akhauriyash/Code-Regression huggingface dataset:
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]

n,m,x=n1()
ca=n3(n)
ans=9999999999

import itertools
book=list(itertools.product([0,1], repeat=n))
price=[]
for line in book:
    p=0
    for i in range(n):
        if line[i]==1:
            p+=ca[i][0]
            
    price.append(p)
for i in range(len(book)):
    t=book[i]
    s=[0]*m
    for j in range(n):
        if t[j]==1:
            s=[s[k]+ca[j][k+1] for k in range(m)]
    if len([y for y in s if y>=x])==m:
        ans=min(ans,price[i])
if ans==9999999999:
    print(-1)
else:
    print(ans)

Measured memory_bytes: 9804
import java.util.Scanner;
class Main{
 public static void main(String args[]){
  int m,f,r,g;
  Scanner sc = new Scanner(System.in);
  while(true){
   m=sc.nextInt();
   f=sc.nextInt();
   r=sc.nextInt();
   g=m+f;
   if(m==-1 && f==-1 && r==-1)
    break;
   if(m==-1 || f==-1 || g<30)
    System.out.println("F");
   else if(g>=80)
    System.out.println("A");
   else if(g>=65)
    System.out.println("B");
   else if(g>=50)
    System.out.println("C");
   else if(g>=30){
    if(r>=50)
     System.out.println("C");
    else
     System.out.println("D");}
   }
 }
}


Measured memory_bytes: 26464
// 東京海上日動 プログラミングコンテスト2020-A
#include <bits/stdc++.h>
#define endl "\n"
#define rep(i,n) for(int i=0;i<int(n);i++)
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> ipair;
typedef pair<ll,ll> lpair;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v) //vectorの中身を見る
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(12);

    string s;
    cin>>s;
    cout<<s[0]<<s[1]<<s[2]<<endl;
    return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <string>

typedef long long int ll;

using namespace std;
ll a,b,c,n,m,q,aa[100000],bb[10000][10000];
bool ra,rb,rc[100000];
vector<ll> va,vb;
string st;

#define CE cout<<endl
#define C cout<<
#define E <<endl

int main(){
    cin>>n>>m;
    for(int i=0;i<n;i++){
        cin>>aa[i];
        rc[i]=true;
    }
    for(int i=0;i<m;i++){
        cin>>a>>b;
        if(aa[a-1]==aa[b-1]){
            rc[b-1]=false;
            rc[a-1]=false;
        }
        else if(aa[a-1]>aa[b-1]) rc[b-1]=false;
        else if(aa[a-1]<aa[b-1]) rc[a-1]=false;
    }
    q=0;
    for(int i=0;i<n;i++){
        if(rc[i]){
            q++;
        }
    }
    C q E;

}


Measured memory_bytes: 4492
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i=0;i < (int)(n);i++)

vector<int> v;
vector<bool> seen;
vector<int> dis;

void dfs(int s,int dist){
    if (seen[s] == true) return;
    seen[s] = true;
    dis[s] = dist;
    if (v[s] == 1){
        seen[1] = true;
        dis[1] = dist+1;
        return;
    }
    //if (s == v[s]) return;
    //cout << s << " " <<  v[s] << endl;
    dfs(v[s],dist+1);
}

int main(){
    int n;
    cin >> n;
    v.resize(n);
    seen.resize(n,false);
    dis.resize(n,1000000007);

    rep(i,n) {
        cin >> v[i];
        v[i]--;
    }
    dfs(0,0);
    if (seen[1]) cout << dis[1] << endl;
    else cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;

#define each(i, c) for (auto& i : c)
#define mkp(a, b) make_pair(a, b)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> Pll;
const ll MOD = 1e9+7;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << ": " << p.second << ")"; return os; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ", "; os << ")"; return os; }
template<typename K, typename V> ostream& operator << (ostream& os, map<K, V> m) { os << "{"; each (i, m) os << i << ", "; os << "}"; return os; }

int main() {
  ll k, n;
  cin >> k >> n;

  vector<ll> a(n);
  for (ll i = 0; i < n; ++i) {
    cin >> a[i];
  }

  ll ans = a[a.size()-1] - a[0];
  for (ll i = 1; i < n; ++i) {
    ans = min(ans, a[i-1]+k - a[i]);
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
  int n;
  cin >> n;
  vector<pair<ll,ll>> v (n);
  for(int i=0; i<n; i++){
    ll a,b;
    cin >> a >> b;
    v.at(i) = make_pair(b,a);
  }
  sort(v.begin(),v.end());
  string ans = "Yes";
  ll time = 0;
  for(int i=0; i<n; i++){
    time += v.at(i).second;
    if(time > v.at(i).first){
      ans = "No";
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3328
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc=new Scanner(System.in);
        int num=sc.nextInt();
        int num2=sc.nextInt();
        int kazu=(num-1)*(num2-1);
        System.out.println(kazu);
    }
}


Measured memory_bytes: 21204
#include<iostream>

using namespace std;

int main()
{
	int n1,n2;
	int ans;
	int sum;
	
	for(;cin >> n1;)
	{
		cin >> n2;
		
		ans=1;
		sum=n1+n2;
		
		for(;sum/10>0;sum/=10)
			ans++;
		
		cout << ans << endl;
	}
}

Measured memory_bytes: 0
/*
ID: learnin7
TASK: test
LANG: C++                 
*/
/* LANG can be C++11 or C++14 for those more recent releases */
#include<bits/stdc++.h>

/*  Macros from Endagorion */
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;


int main(){
        
    ios_base::sync_with_stdio(0);
    
    //ofstream fout ("test.out");
    //ifstream fin ("test.in");
    //fin >> a >> b;
    //fout << a+b << endl;
    string a,b;
    cin>>a>>b;
    string r = a+b;
    int num=0;
    int prod=1;
    //cout<<r<<endl;
    ford(i,r.length()){
        int x = r[i]-'0';
        num += (x*prod);
        prod *=10;
    }
    //cout<<num<<endl;
    for(int i=1;i<=sqrt(num);i++){
        if(i*i==num){
            //cout<<i<<" "<<num/i<<endl;
            cout<<"Yes\n";
            return 0;
        }
    }
    cout<<"No\n";
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b!=0?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}

int main(){
    ll n,m;
    cin>>n>>m;
    vector<ll> a(n),b(n),c(m),d(m),ans(n,-1);
    rep(i,n) cin>>a[i]>>b[i];
    rep(i,m) cin>>c[i]>>d[i];
    rep(i,n){
        ll mn=1e9;
        rep(j,m){
            ll manh=abs(a[i]-c[j])+abs(b[i]-d[j]);
            if(mn>manh){
                mn=manh;
                ans[i]=j+1;
            }
        }
    }
    rep(i,n) cout<<ans[i]<<endl;
    return 0;
}

Measured memory_bytes: 256
# include <bits/stdc++.h>
# define INF 1e9
using namespace std;

int main(){

  int H, W;
  cin >> H >> W;

  vector<string> a;
  for(int i=0; i<H; i++){
    string s;
    cin >> s;
    if(s.find('#') != string::npos){
      a.push_back(s);
    }
  }

  set<int> todelete;
  for(int j=0; j < W; j++){
    int count = 0;
    for(int i=0; i < a.size(); i++){
      if(a[i][j] == '.') count++;
    }
    if(count == a.size()) todelete.insert(j);
  }

  // for(auto j: todelete){
  //   cout << j << endl;
  // }

  vector<string> ans;
  for(int i=0; i < a.size(); i++){
    string t = "";
    for(int j=0; j< W; j++){
      if(todelete.find(j) == todelete.end()){
        t += a[i][j];
      }
    }
    cout << t << endl;
  }

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll  long long
#define pp pair<int,int>
#define ppn pair<pp,int>
#define F first
#define S second
#define N 200005
#define mod 1000000007
#define pi 3.14159265358979323846

using namespace std;


int main()
{


    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int n, k=1000,x=0;
    map<string,int>m;
    cin>>n;
    string s;
    for(int i=0; i<n; i++){
        cin>>s;
        m[s]++;
    }
    string t[]={"AC","WA","TLE","RE"};
    for(int i=0; i<4; i++){
        cout<<t[i]<<" x "<<m[t[i]]<<endl;
    }


}


Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;

#define debug(x) cout <<"DEBUG"<<" "<< #x << ":" << x << '\n'

// n回繰り返し
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順
#define rep1(i,n) for(int i = 1; i <= ((int)(n)); i++) // 1-indexed昇順
#define rrep(i,n) for(int i = ((int)(n)-1); i >= 0; i--)  // 0-indexed降順
#define rrep1(i,n) for(int i = ((int)(n)); i >= 1; i--)   // 1-indexed降順
#define all(x) (x).begin(),(x).end()

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vii;  // 2次元配列
typedef vector<ll> vll;
typedef vector<double> vd;
typedef pair<int, int> PII;

template<typename T>
using vec = vector<T>;
template<class T>
using maxheap = std::priority_queue<T>;
template<class T>
using minheap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template<class T,class U> inline bool chmax(T &a, const U &b){if(a<b){a=b;return 1;}return 0;}
template<class T,class U> inline bool chmin(T &a, const U &b){if(a>b){a=b;return 1;}return 0;}

const ld Pi = std::acos(-1.0L);
const ll infll = (1LL<<62)-1;
const int inf = (1<<30)-1;
const int mod = 1000000007;
// const int mod = 998244353;


/*FUNCs=================================================*/


/*MAIN==================================================*/
signed main(){
    int _StartTime_ = clock();
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化
    cout << fixed << setprecision(15);

    int n; cin >> n;
    vec<PII> xy(n); rep(i,n) cin >> xy[i].first >> xy[i].second;
    sort(all(xy));  // 重要！

    double ans = 0;
    double c = 0;
    do {
        for(int k = 0; k < n-1; ++k) {
            ans += sqrt(((xy[k].first-xy[k+1].first)*(xy[k].first-xy[k+1].first)
                        + (xy[k].second-xy[k+1].second)*(xy[k].second-xy[k+1].second)));
        }
        ++c;
    }while (next_permutation(all(xy)));

    cout << ans/c << '\n';

    // printf("ExcutionTime: %d /ms\n",1000*(int)((clock()-_StartTime_)/CLOCKS_PER_SEC));
}

Measured memory_bytes: 256
def cubeRoot(q):
    x = q / 2
    while abs(x ** 3 - q) >= (0.00001 * q):
        x = (2 * x ** 3 + q) / (3 * x ** 2)
    return x
    
while True:
  q = int(input())
  if q == -1:
    break
  print(cubeRoot(q))


Measured memory_bytes: 5668
#pragma region Header
#ifdef DEBUG
#include "debug.hpp"
#else
#define debug(...)
#define IFD(...)
#ifndef NDEBUG
#define NDEBUG
#endif
#endif
#include <utility>
#include <cstdint>
#include <cmath>
#include <cassert>
#include <vector>
#include <array>
#include <deque>
#include <queue>
#include <stack>
#include <tuple>
#include <set>
#include <map>
#include <unordered_map>
#include <bitset>
#include <string>
#include <functional>
#include <algorithm>
#include <numeric>
#include <stdexcept>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <boost/hana/functional/fix.hpp>
using boost::hana::fix;
using namespace std;
using i32 = int32_t;
using i64 = int64_t;
using u32 = uint32_t;
using u64 = uint64_t;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repd(i, n) for (int i = (n)-1; i >= 0; --i)
#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define FORD(i, b, a) for (int i = (b); i >= (a); --i)
template <typename T>
int SZ(T const &x)
{
    return static_cast<int>(x.size());
}
template <class T>
bool chmax(T &a, T const &b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
bool chmin(T &a, T const &b)
{
    if (b < a)
    {
        a = b;
        return true;
    }
    return false;
}
#pragma endregion

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);

    i64 a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << max({a * c, a * d, b * c, b * d}) << '\n';

    return 0;
}


Measured memory_bytes: 3644
N,M=map(int,input().split())
lst = [0] * M
for i in range(N):
  s = input().rstrip().split(' ')
  num = int(s[0])
  for j in range(1, num+1):
    lst[int(s[j])-1] += 1
length = len(lst)
count = 0
for k in range(length):
  if lst[k] == N:
    count += 1
print(count)
  

Measured memory_bytes: 3064
#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

int main(){
	int n; scanf("%d",&n);
	vector<int> a(n);
	rep(i,n) scanf("%d",&a[i]);

	vector<int> P,M;
	rep(i,n) (a[i]>=0?P:M).emplace_back(a[i]);

	if(P.empty()){
		int x=*max_element(a.begin(),a.end());
		P={x};
		M.erase(find(M.begin(),M.end(),x));
	}
	if(M.empty()){
		int x=*min_element(a.begin(),a.end());
		M={x};
		P.erase(find(P.begin(),P.end(),x));
	}

	int np=P.size(),nm=M.size();
	vector<pair<int,int>> ans;
	for(int i=1;i<nm;i++){
		ans.emplace_back(P[0],M[i]);
		P[0]-=M[i];
	}
	for(int i=1;i<np;i++){
		ans.emplace_back(M[0],P[i]);
		M[0]-=P[i];
	}
	ans.emplace_back(P[0],M[0]);

	printf("%d\n",P[0]-M[0]);
	for(auto p:ans) printf("%d %d\n",p.first,p.second);

	return 0;
}


Measured memory_bytes: 3828
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<queue>
#include<stack>
#include<cmath>	

using namespace std;

int main() {
	int A, B;
	cin >> A >> B;
	int ans = max(A + B, A - B);
	ans = max(ans, A * B);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
n=int(input())
s=list(map(int,input().split()))
cost=[0]*n
cost[1]=abs(s[1]-s[0])
if n==2:
  
  print(abs(s[1]-s[0]))
  
else:
  for i in range(2,len(s)):
  	cost[i]=min(abs(s[i]-s[i-1])+cost[i-1],abs(s[i]-s[i-2])+cost[i-2])
  print(cost[n-1])
    
  
  


Measured memory_bytes: 13928
N, K, Q = map(int, input().split())
a_list = [int(input()) for _ in range(Q)]

point = [0] * N
for a in a_list:
    point[a-1] += 1

for i in point:
    if K - (Q - i) <= 0:
        print('No')
    else:
        print('Yes')
    

Measured memory_bytes: 13684
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <tuple>
#include <cmath>
#include <map>
#include <climits>
using namespace std;
using Int = long long;
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n,m) for(int i=n;i<m;i++)
int main()
{
    int N; cin >> N;
    for (;;) {
        int sq = (int)sqrt(N);
        if (sq * sq == N) {
            cout << N << endl;
            break;
        }
        N--;
    }
    return 0;
}

Measured memory_bytes: 256
from collections import defaultdict
from collections import deque
from collections import OrderedDict
import itertools
from sys import stdin
input = stdin.readline


class Eratos:
  def __init__(self, n):
    import math

    self.all = []
    self.is_prime = [True]*(n+1)
    self.is_prime[0] = False
    self.is_prime[1] = False

    for i in range(2, int(math.sqrt(n))+1):
      if self.is_prime[i]:
        self.all.append(i)
        j = i + i
        while j <= n:
          self.is_prime[j] = False
          j += i


def main():
  X = int(input())

  e = Eratos(X)

  # print(len(e.all))
  for x in range(X, 2*X+1):
    for prime in e.all:
      if x % prime == 0:
        break
    else:
      print(x)
      return


if(__name__ == '__main__'):
  main()


Measured memory_bytes: 66944
def c_tak_and_cards():
    from collections import defaultdict
    N, A = [int(i) for i in input().split()]
    X = [int(i) for i in input().split()]

    average = [x - A for x in X]
    dp = defaultdict(int)  # dp[s]: y から 1 枚以上選んで整数の和を s にする方法
    dp[0] = 1  # 「選ばない」 1 通り
    for y in average:
        for k, v in list(dp.items()):  # for 文中で要素数が変わってはいけないため
            dp[k + y] += v
    return dp[0] - 1

print(c_tak_and_cards())

Measured memory_bytes: 3572
h, w = map(int, input().split())

s = []

for _ in range(h):
    temp = []
    for i in input():
        if i == '#':
            temp.append(-100)
        else:
            temp.append(0)
    temp = [0] + temp + [0]
    s.append(temp)

s = [[0] * (w+2)] + s + [[0] * (w+2)]

for i in range(h+2):
    for j in range(w+2):
        if s[i][j] < 0:
            s[i-1][j-1] += 1
            s[i][j-1] += 1
            s[i+1][j-1] += 1
            s[i-1][j] += 1
            s[i+1][j] += 1
            s[i-1][j+1] += 1
            s[i][j+1] += 1
            s[i+1][j+1] += 1

s = s[1:-1]

ans = []

for i in s:
    temp = ''
    for j in i[1:-1]:
        if j < 0:
            temp += "#"
        else:
            temp += str(j)
    ans.append([temp])

for i in ans:
    print(*i)

Measured memory_bytes: 3064
using System;
using System.Linq;
using static System.Math;

class D
{
	static void Main() => Console.WriteLine(string.Join("\n", new int[int.Parse(Console.ReadLine())].Select(_ => Console.ReadLine().Split().Select(int.Parse).ToArray()).Select(x => Find(x[0], x[1]))));

	static double Find(long a, long b)
	{
		// l: x + y = c
		for (long r = 0, t, c = 2 * (long)Floor(Sqrt(a * b)); ; r = t, c++)
		{
			t = c % 2 == 0 ?
				c * c / 4 <= a * b ? c - 2 - (a != b && c * c / 4 == a * b ? 1 : 0) : -1 :
				c / 2 * (c / 2 + 1) < a * b ? c - 2 : -1;
			if (t < r) return r;
		}
	}
}


Measured memory_bytes: 11348
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

///#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,avx,sse4.1,sse4.2,mmx")
///#pragma GCC optimize ("unroll-loops")
///#pragma GCC optimize ("Ofast")
///#pragma GCC optimize ("O3")

using namespace std;
using namespace __gnu_pbds;

#define int long long
#define ff first
#define ss second
#define db double
#define ld long double
#define pb push_back
#define what(x) cerr << #x << " = " << x << '\n'

const int N = 1e6 + 5, M = 3e3 + 5;
const int inf = 1e18 + 100, mod = 1e9 + 7;
const ld eps = 1e-9, Pi = atan2(0, -1);

template < class T >
using ordered_set = tree < T, null_type, less < T >, rb_tree_tag, tree_order_statistics_node_update >;

template < class T >
using ordered_multiset = tree < T, null_type, less_equal < T >, rb_tree_tag, tree_order_statistics_node_update >;

mt19937_64 mt_rnd_64(chrono::steady_clock::now().time_since_epoch().count());
int rnd(int l, int r){
    return mt_rnd_64() % (r - l + 1) + l;
}

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ld R;
    cin >> R;
    cout << fixed << setprecision(2) << 2.0 * R * Pi;
    return 0;
}
/// hto ya? zvychayna domohospodarka chy president Ykrainy?


Measured memory_bytes: 3792
//Bartek Kostka
//  You are not prepared!

#include "bits/stdc++.h"

using namespace std;

#define x first
#define y second
#define SZ(x) int(x.size())
#define ll long long
#define pii pair <int, int>
#define vi vector <int>
#define ALL(x) x.begin(), x.end()

#ifdef LOCAL
template<class TH> void _dbg(const char *sdbg, TH h){ cerr<<sdbg<<" = "<<h<<endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')cerr<<*sdbg++;
  cerr<<" = "<<h<<", "; _dbg(sdbg+1, a...);
}
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define dbg(...)
#define cerr if(false) cout
#endif

int main() {
  vi A(5);
  for(int i=0; i<5; i++) cin >> A[i];
  vi I = {0, 1, 2, 3, 4};
  int res = 1e9;
  do {
    int t = 0;
    for(int j=0; j<5; j++) {
      t += A[I[j]];
      int r = (t % 10);
      if(j!=4 and r) t += 10 - r;
    }
    res = min(res, t);
  } while(next_permutation(ALL(I)));
  cout << res << "\n";
}


Measured memory_bytes: 256
import math

a, b, h, m = map(int, input().split())

rad_h = (2 * math.pi / 12) * (h + m / 60)
rad_m = (2 * math.pi / 60) * m
# print(rad_h)
# print(rad_h * 360 / 2 / math.pi)
# print(rad_m)
# print(rad_m * 360 / 2 / math.pi)

theta = abs(rad_h - rad_m)
# print(theta)
# print(math.cos(theta))
# print(theta * 360 / 2 / math.pi)

x = math.sqrt(a ** 2 + b ** 2 - 2 * a * b * math.cos(theta))
print(x)

Measured memory_bytes: 9308
import sys
from collections import Counter

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def prime_factorize(n):
    a = Counter()
    while n % 2 == 0:
        a[2] += 1
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a[f] += 1
            n //= f
        else:
            f += 2
    if n != 1:
        a[n] += 1
    return a


def main():
    N = int(readline())

    prime = Counter()
    for n in range(1, N + 1):
        prime.update(prime_factorize(n))

    C = [0] * 101
    for v in prime.values():
        C[v] += 1

    for i in range(99, -1, -1):
        C[i] += C[i + 1]

    ans = 0
    ans += (C[2] - 2) * (C[4] * (C[4] - 1) // 2)
    ans += (C[2] - 1) * C[24]
    ans += (C[4] - 1) * C[14]
    ans += C[74]

    print(ans)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 9428
using System;
using System.Linq;
using System.Collections.Generic;

public static class Program {
    public static void Main() {
        int n=int.Parse(Console.ReadLine());
        int[]a=Console.ReadLine().Split().Select(int.Parse).ToArray();
        int[]dp=new int[n];
        dp[1]=a[1]-a[0];
        if(dp[1]<0)dp[1]=-dp[1];
        for(int i=2;i<n;i++) {
            dp[i]=int.MaxValue;
            for(int j=i-2;j<i;j++){
                int x=a[i]-a[j];
                if(x<0)x=-x;
                dp[i]=Math.Min(dp[i],dp[j]+x);
            }
        }
        Console.WriteLine(dp[n-1]);
    }
}



Measured memory_bytes: 18016
n, k = map(int,input().split())
ps = [tuple(map(int,input().split())) for i in range(n)]

sx = sorted(ps,key = lambda x: x[0]) # x座標でソート
nx = list(enumerate(sx)) # 頂点番号を付加
ans = 5e18

for f, (x1,y1) in nx[:n-k+1]: # 左辺の頂点
    for e, (x2,y2) in nx[f+k-1:]: # 右辺の頂点
        dx = x2 - x1 # 横
        sy = sorted(y for x,y in sx[f:e+1]) # 含まれる頂点をy座標でソート
        for y3,y4 in zip(sy,sy[k-1:]): # y3=下辺の頂点，y4=上辺の頂点
            if y3 <= y1 and y4 >= y2: # 左右辺の頂点を含むこと
                ans = min(ans, dx * (y4 - y3))

print(ans)

Measured memory_bytes: 3064
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
#include <deque>

using namespace std;

#define mod 1000000007

int main()
{
	int n;
	cin >> n;
	int h[100001];
	for(int i = 0; i < n; i++){
		cin >> h[i];
	}

	int result[100001];
	result[n - 1] = 0;
	result[n - 2] = abs(h[n - 1] - h[n - 2]);
	for(int i = n - 3; i >= 0; i--){
		result[i] = min(result[i + 1] + abs(h[i + 1] - h[i]), result[i + 2] + abs(h[i + 2] - h[i]));
	}
	cout << result[0] << endl;
}

Measured memory_bytes: 1024
#include<stdio.h>
int main(void)
{
    int n,a,b,c;
    int cal[10000]={0};
    int i,j;
    int x,z;
    int rui=0,masa = 0;
 
    scanf("%d%d%d%d",&n,&a,&b,&c);
    for(i = 0;i < n; i++) {
scanf("%d",&cal[i]);
		}
 
    for(i = 0;i < n; i++){
        for(j = 0;j < n; j++){
            if(cal[i] > cal[j]){
                x = cal[i];
                cal[i] = cal[j];
                cal[j] = x;
            }
        }
    }
    z = c;
    rui = c/a;
    for(i = 1;i <= n; i++){
        z += cal[i-1];
        masa = z / ((b*i)+a);
        if(rui <=masa){
        rui = masa;
        }
        else{
        break;
        }
    }
    printf("%d\n",rui);
    return 0;
}

Measured memory_bytes: 644
//高知能系Vtuberの高井茅乃です。
//Twitter: https://twitter.com/takaichino
//YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

#define INF 1999999999
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define MODA 1000000007 

int main() {
	int ans = 0;
	int tmp;
	int n, r;
	cin >> n >> r;
	
	cout << r+100*(10-min(10,n)) << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
    public static void main(String[] args) {
      Scanner sc = new Scanner(System.in);

      String s=sc.next();

      s = s + 'R';

      int lng =s.length();

      char r = 'R';
      char l = 'L';

      char[] c = new char[lng];
      for(int i=0;i<lng;i++){
        c[i] = s.charAt(i);
      }

      int[] num = new int[lng];
      for(int i=0;i<lng;i++){
        num[i] = 0;
      }

      int cnt=0;
      int numR;
      int numL;
      int flag=0;

      for(int i=0;i<lng-1;i++){
        cnt++;
        if(c[i]==l && c[i+1]==r){//if LR finds
        //////////////////////////////////////////////////////
          for(int j=flag;j<=i;j++){//find RL
            if(c[j]==r && c[j+1]==l){//if RL finds
              numL = i-j-1;
              numR = cnt - numL - 2;
              num[j] = calcL(cnt,numR,numL);
              num[j+1] = calcR(cnt,numR,numL);
              flag = i+1;
              cnt=0;
              break;
            }
          }
        /////////////////////////////////////////////////////
        }
      }

////////////////////////////////////////////////
      for(int i=0;i<lng-1;i++){
        System.out.print(num[i]+" ");
      }
////////////////////////////////////////////////
    }

    public static int calcL(int cn,int rr,int ll){
      int ans=0;
      if(cn%2==0){
        ans = cn/2;
      }
      else if(rr%2==0){
        ans = (cn+1)/2;
      }
      else if(rr%2==1){
        ans = (cn-1)/2;
      }
      return ans;
    }
    public static int calcR(int cn,int rr,int ll){
      int ans=0;
      if(cn%2==0){
        ans = cn/2;
      }
      else if(rr%2==0){
        ans = (cn-1)/2;
      }
      else if(rr%2==1){
        ans = (cn+1)/2;
      }
      return ans;
    }

}


Measured memory_bytes: 44508
import collections
N = int(input())
A = list(map(int,input().split()))
counter = collections.Counter(A)
ans = sum(A)
Q = int(input())
R = []
for _ in range(Q):
    b,c = map(int,input().split())
    ans += (c-b)*counter[b]
    counter[c] +=counter[b]
    del counter[b]
    R.append(ans)
for r in R:
    print(r)

Measured memory_bytes: 95676
#include <bits/stdc++.h>
// iostream is too mainstream
#include <cstdio>
// bitch please
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <cmath>
#include <iomanip>
#include <time.h>
#define dibs reserve
#define OVER9000 1234567890
#define ALL_THE(CAKE,LIE) for(auto LIE =CAKE.begin(); LIE != CAKE.end(); LIE++)
#define tisic 47
#define soclose 1e-8
#define chocolate win
// so much chocolate
#define patkan 9
#define ff first
#define ss second
#define abs(x) ((x < 0)?-(x):x)
#define uint unsigned int
#define dbl long double
#define pi 3.14159265358979323846
using namespace std;
// mylittledoge

typedef long long cat;

#ifdef DONLINE_JUDGE
	// palindromic tree is better than splay tree!
	#define lld I64d
#endif

int main() {
	cin.sync_with_stdio(0);
	cin.tie(0);
	cout << fixed << setprecision(10);
	int N;
	cin >> N;
	vector<int> A(2*N);
	vector<char> C(2*N);
	for(int i = 0; i < 2*N; i++) cin >> C[i] >> A[i];
	vector< vector<int> > pos(2, vector<int>(N));
	for(int i = 0; i < 2*N; i++) pos[C[i] == 'B'][A[i]-1] = i;

	vector< vector<int> > cnt[2];
	for(int k = 0; k < 2; k++) {
		cnt[k].resize(N+1, vector<int>(2*N+1, 0));
		for(int i = 0; i < 2*N; i++) if((C[i] == 'B') == k)
			for(int j = 0; j <= A[i]-1; j++) cnt[k][j][i+1] = 1;
		for(int j = 0; j < N; j++)
			for(int i = 0; i < 2*N; i++) cnt[k][j][i+1] += cnt[k][j][i];
	}

	vector< vector<int> > mincost(N+1, vector<int>(N+1, OVER9000));
	mincost[0][0] = 0;
	for(int i = 0; i <= N; i++) for(int j = 0; j <= N; j++) {
		if(i < N) {
			int p = pos[0][i];
			mincost[i+1][j] = min(mincost[i+1][j], mincost[i][j] + cnt[0][i][p] + cnt[1][j][p]);
		}
		if(j < N) {
			int p = pos[1][j];
			mincost[i][j+1] = min(mincost[i][j+1], mincost[i][j] + cnt[0][i][p] + cnt[1][j][p]);
		}
	}
	cout << mincost[N][N] << "\n";
	return 0;}

// look at my code
// my code is amazing


Measured memory_bytes: 78720
#include<bits/stdc++.h>
#include<algorithm>
#include<cmath>
#include<climits>
using namespace std;
typedef long long int lli;
typedef vector<int> vi;
typedef vector<long long int> vlli;
typedef pair<int,int> pii;
typedef pair<long long int,long long int> plli;
typedef vector< vi > vvi ;
typedef vector< vlli > vvlli  ;
#define fi(i,a,b) for(int i=a;i<=b;i++)
#define flli(i,a,b) for(long long int i=a;i<=b;i++)
#define bi(i,a,b) for(int i=a;i>=b;i--)
#define blli(i,a,b) for(long long int i=a;i>=b;i--)
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define all(x) x.begin(),x.end()
#define sz(x) x.size()
#define pi 2*acos(0.0)
#define pb push_back
#define tr(v,it) for(decltype(v.begin()) it=v.begin();it!=v.end();it++)
#define present(v,num) (v.find(num)!=v.end())
#define cpresent(v,num) (find(v.begin(),v.end(),num)!=v.end())
#define pq priority_queue
#define mp make_pair
const int inf=INT_MAX;
const lli INF =LLONG_MAX;
const lli mod = 1e9+7;
int main() {
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    fast;
    lli n;cin>>n;
    vlli a(n);flli(i,0,n-1)cin>>a[i];
    vlli sum(n);sum[n-1]=a[n-1];
    blli(i,n-2,0)
    	sum[i]=(sum[i+1]+a[i])%mod;
    lli ans=0;
    flli(i,0,n-2)
    {
    	ans=(ans+(a[i]*sum[i+1])%mod)%mod;
    }
    cout<<ans;
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
    return 0;
}

Measured memory_bytes: 6364
N = int(input())
if N%4 == 0 or N%7 ==0:
    print("Yes")
else:
    while N >= 7:
        N = N - 4
        if N%7 ==0:
            print("Yes")
            break
            
if N%7!=0 and N%4!=0:
    print("No")

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;

int64_t n;
string s;

void solve() {
    int64_t r = 0;
    int64_t g = 0;
    int64_t b = 0;
    
    for (int i = 0; i < n; i++) {
        if (s.at(i) == 'R') {
            r++;
        } else if (s.at(i) == 'G') {
            g++;
        } else if (s.at(i) == 'B') {
            b++;
        }
    }

    int64_t ans = r * g * b;

    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            int k = 2 * j - i;
            if (k < n) {
                if (s.at(i) != s.at(j) && s.at(j) != s.at(k) && s.at(k) != s.at(i)) {
                    ans--;
                }
            }
        }
    }

    cout << ans << endl;
}

int main() {
    cin >> n >> s;
    solve();
}

Measured memory_bytes: 3604
#include <stdio.h>

#define max(a,b) (((a)>(b))?(a):(b))
int main(void)
{
	int p, q, r;
	scanf("%d %d %d", &p, &q, &r);
	printf("%d\n",p+q+r-max(max(p,q),max(q,r)));
	return(0);
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define fi first
#define se second
#define pb push_back
#define mk make_pair
using namespace std;
typedef long long ll;
typedef long double lld;
const ll INF = 1e18;
const ll mod = 1e9+7;
 
ll fastpowMOD(ll a, ll p,ll MOD);
ll fastpowMOD(ll a, ll p,ll MOD){ if(p==0) return 1; a %= MOD; ll z = fastpowMOD(a,p/2,MOD); z = (z*z)%MOD; if(p%2) z = (z*a)%MOD; return z; }
 
ll lcm(ll a,ll b){
	return (a*b)/__gcd(a,b);
}

void solve(){
	ll n;
	cin>>n;
	ll cnt = n-2;
	vector<ll> a(n,0);
	for(ll i=0;i<n;i++){
		cin>>a[i];
	}
	sort(a.begin(),a.end());
	reverse(a.begin(),a.end());
	ll sum = 0;
	sum += a[0];
	
	for(ll i=1;i<n;i++){
		if(cnt>=2){
			sum += a[i]*2;
			cnt -= 2;
		}
		else{
			if(cnt==1){
				sum += a[i];
			}
			
			break;
		}
	}
	cout<<sum<<"\n";
}

int main(){
    fastio;
	solve();
	
}




Measured memory_bytes: 4740
#include<bits/stdc++.h>
 
using namespace std;
 
// Competetive Template:
typedef long long int lli;
typedef unsigned long long int ulli;
typedef long double ldb;
 
// Debugging :
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
 
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
 
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define ba  back
#define si size()
#define be begin()
#define en end()
#define le length()
#define mp make_pair 
#define mt make_tuple
#define fi first
#define se second
#define gcd __gcd
#define maxe *max_element
#define mine *min_element
#define deb debug
 
#define forz(i,n) for(long long int i=0;i<n;i++)
#define rep(i,k,n) for (lli i = k; i <= n; i++)
#define deci(n)  fixed<<setprecision(n)
#define high(n) __builtin_popcount(n)
#define parity(n) __builtin_parity(n)
#define ctz(n)  __builtin_ctz(n)
#define mod 1000000007
#define mod2 998244353
#define kira ios::sync_with_stdio(0), cin.tie(0),cout.tie(0)
 
typedef pair <lli,lli> pll;
 
 
lli countGreater(lli arr[], lli n, lli k) 
{ 
    lli l = 0; 
    lli r = n - 1; 
  
    lli leftGreater = n; 
  
    while (l <= r) { 
        lli m = l + (r - l) / 2; 
  

        if (arr[m] > k) { 
            leftGreater = m; 
            r = m - 1; 
        } 

        else
            l = m + 1; 
    } 
  
    return (n - leftGreater); 
}
 
bool is_palin(string input)
{
    if (input == string(input.rbegin(), input.rend())) 
        return true;
    return false;
}
void solve()
{
    lli n,k;
    cin>>k>>n;
    lli arr[n];
    lli sum =0;
    lli diff = -1e17;
    forz(i,n) 
    {
        cin>>arr[i];
    }
    forz(i,n-1)
    {
        sum+=arr[i+1]-arr[i];
        if(diff<(arr[i+1]-arr[i]))
            diff = arr[i+1]-arr[i];
    }
    if(diff<(k-sum))
            diff = k-sum;
    sum = sum+(k-sum);
    // deb(sum,diff);
    cout<<sum-diff<<endl;
}
 
int main()
{
    kira; 
 
    lli t=1; //cin>>t;
    while(t--)
    {
        solve();
    }
    
    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
using namespace std;
int main(void){
    int m,f,b;
    cin >> m >> f >> b;
    if(m >= b){
        cout << 0 << endl;
    }
    else if(m+f >= b){
        cout << b-m << endl;
    }
    else{
        cout << "NA" << endl;
    }
}


Measured memory_bytes: 3092
#include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<string.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
long long int mod=1e9+7;
bool debug=false;
typedef long long ll;
int main(){
	int n;
	cin>>n;
	vector<int>d(n);
	rep(i,n)cin>>d[i];
	int sum = 0;
	rep(i,n-1){
		for(int j=i+1;j<n;j++){
			sum+=d[i]*d[j];
		}
	}
	cout<<sum<<endl;

	return 0;
}

Measured memory_bytes: 256
import math
n=int(input())
k=2
a=[int(i) for i in input().split()]
b=[0]*n
b[n-2]=abs(a[n-1]-a[n-2])
for i in range(n-3,-1,-1):
    c=[]
    for j in range(i+1,min(n,i+k+1)):
        c.append(abs(a[j]-a[i])+b[j])
    b[i]=min(c)
print(b[0])

Measured memory_bytes: 52208
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

// https://atcoder.jp/contests/abc138/submissions/7075855 を参考

#define mod 1000000007

// y と x は2進数で同じ桁数である必要がある
// このとき, y % x = y - x
// 繰り下がりが無いことが必要十分

ll L, R;
int dp[61][2][2][2];

// 現在の桁, Lの制約の有無, Rの制約の有無, 桁数が合ってるかどうか
int solve(int i, bool L_Free, bool R_Free, bool flag){
    if(i == -1) return 1;
    int &res = dp[i][L_Free][R_Free][flag];
    if(res != -1) return res;
    res = 0;

    int lX = 0, rX = 1, lY = 0, rY = 1;
    if (! L_Free) lX = (L >> i) & 1;
    if (! R_Free) rY = (R >> i) & 1;

    for (int x = lX; x <= rX; ++x) {
        for (int y = lY; y <= rY; ++y) {
            if (x <= y && (flag || x == y) ) {
              res += solve(i-1, L_Free | (x > lX), R_Free | (y < rY), flag | (x == 1));
              res %= mod;
            }
        }
    }
    return res;
}

int main() {
    cin >> L >> R;
    memset(dp, -1, sizeof dp);
    cout << solve(60, 0, 0, 0);
    return 0;
}

Measured memory_bytes: 256
import scala.io.{StdIn => in}

object Main extends App {
  val n = in.readInt
  val a = in.readLine.split(" ").map(_.toInt)

  val tableL = Array.ofDim[Int](n)
  val tableR = Array.ofDim[Int](n)

  var f = a.head
  var l = a.last
  for(i <- 0 until n-1) {
    val j = n-1 - i
    f = gcd(f, a(i))
    tableL(i+1) = f
    l = gcd(l, a(j))
    tableR(j-1) = l
  }

  val init = tableR(0) max tableL(n-1)
  val ans = (1 until n-1)./:(init)((acc,i) => acc max gcd(tableL(i),tableR(i)))
  println(ans)

  def gcd(a:Int, b:Int):Int = {
    if(b== 0) a
    else gcd(b, a%b)
  }
}

Measured memory_bytes: 46332
# -*- coding: utf-8 -*-
A, B = map(int, input().split(' '))
# A, B = 2, 4

if A % 2 == 0:
    n = (B - A) // 2
    b = 2 * n + A

    ans = 0 if n % 2 == 0 else 1
    for i in range(b, B+1):
        ans ^= i

    # print(b)
    # print(n)
    print(ans)
else:
    a = A
    A += 1

    n = (B - A) // 2
    b = 2 * n + A

    ans = 0 if n % 2 == 0 else 1
    ans ^= a
    for i in range(b, B+1):
        ans ^= i

    # print(b)
    # print(n)
    print(ans)




Measured memory_bytes: 38256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main()
{
    int n;
    string s;
    cin >> n >> s;
    vector<ll> cnt(3, 0);
    rep(i, n)
    {
        if (s[i] == 'R')
            cnt[0]++;
        if (s[i] == 'G')
            cnt[1]++;
        if (s[i] == 'B')
            cnt[2]++;
    }
    ll ans = cnt[0] * cnt[1] * cnt[2];
    rep(j, n)
        rep(i, j)
    {
        int k = 2 * j - i;
        if (k >= n)
            continue;
        if (s[i] == s[j])
            continue;
        if (s[j] == s[k])
            continue;
        if (s[k] == s[i])
            continue;
        ans--;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3592
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const long long mod = 1e9+7;
int main()
{
    int n;
    long long ans = 1;
    scanf("%d",&n);
    for(int i=1; i<=n; i++)
    {
        ans = (ans % mod * i % mod) % mod;
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 256
def main():
    n,k = map(int,input().split())
    r,s,p = map(int,input().split())
    t = list(input())
    res = 0
    dic = {'r':p,'s':r,'p':s}

    for i in range(n):
        if i < k or t[i-k] != t[i]:
            res += dic[t[i]]
        else:
            t[i] = ' '
    print(res)

if __name__ == '__main__':
    main()



Measured memory_bytes: 49392
#include <bits/stdc++.h>

using namespace std;
using llong = long long;
using P = pair<llong, llong>;

#define BE(x) x.begin(), x.end()

const llong inf = llong(1e18)+7;
const llong mod = 1e9+7;

int main(){
	llong N;
	string s;
	cin >> N >> s;
	llong plus = 0;
	string ans;
	for(auto x : s){
		if(x == ')')
			if(plus == 0)
				ans = '(' + ans + x;
			else
				ans += x, plus--;
		else
			ans += x, plus++;
	}
	if(plus > 0)
		ans += string(plus, ')');

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){
	int a,b;
	scanf("%d%d",&a,&b);
	if(a == 1){a = 14;}
	if(b == 1){b = 14;}
	if(a > b){printf("Alice\n");}
	if(a < b){printf("Bob\n");}
	if(a == b){printf("Draw\n");}
	return 0;
}

Measured memory_bytes: 128
#define _USE_MATH_DEFINES
#include <iostream>
#include <cstdio>
#include <cmath>

using namespace std;

int main() {

	int a, b, ans;
	char op;

	while (true) {
		cin >> a >> op >> b;
		if (op == '?')
			return 0;
		switch (op) {
		case '+':
			ans = a + b;
			break;
		case '-':
			ans = a - b;
			break;
		case '*':
			ans = a * b;
			break;
		case '/':
			ans = a / b;
		}
		cout << ans << endl;
	}

	return 0;

}

Measured memory_bytes: 3040
using System;
using System.Linq;
using System.Collections.Generic;

namespace program{
  class Program{
    static void Main(){
      int N = Input.ScanInt();
      double[] p = Input.ScanDoubleArray();
      
      double[] p_tmp = new double[N+1];
      p_tmp[0]=1.0;
      for(int i=1;i<=N;i++){
        for(int k=i;k>0;k--){
          p_tmp[k] = p_tmp[k-1] * p[i-1] + p_tmp[k] * (1.0 - p[i-1]);
        }
        p_tmp[0] *= (1.0 - p[i-1]);
      }
      double sum = 0;
      for(int i=N;2*i>=N;i--) sum += p_tmp[i];
	  Console.Write($"{sum}");
    }
  }

    static class Input
    {
      static public double[] ScanDoubleArray() { return Console.ReadLine().Split(' ').Select(x => double.Parse(x)).ToArray(); }
        static public int ScanInt() { return int.Parse(Console.ReadLine()); }
        static public uint ScanUint() { return uint.Parse(Console.ReadLine()); }
        static public long ScanLong() { return long.Parse(Console.ReadLine()); }
        static public ulong ScanUlong() { return ulong.Parse(Console.ReadLine()); }
        static public int[] ScanIntArray() { return Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); }
        static public uint[] ScanUintArray() { return Console.ReadLine().Split(' ').Select(x => uint.Parse(x)).ToArray(); }
        static public long[] ScanLongArray() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray(); }
        static public ulong[] ScanUlongArray() { return Console.ReadLine().Split(' ').Select(x => ulong.Parse(x)).ToArray(); }

        static public string ScanStr() { return Console.ReadLine(); }
        static public string[] ScanStrArray() { return ScanStr().Split(' '); }
    }
}


Measured memory_bytes: 13408
#include <stdio.h>
#include <string.h>
#include <queue>
#include <utility>
#define INF 0x3FFFFFFF

using namespace std;


int main(void){
	int n, h, w, i, j, k, dx[4] = {0,1,0,-1}, dy[4] = {-1,0,1,0}, s[11][20][20], d[11][11], a, b, dp[11][1 << 10], min;
	pair<int,int> l[11];
	queue<pair<int,int> > que;
	char field[20][21];
	while(1){
		scanf("%d%d%*c",&w,&h);
		if(w == 0 && h == 0) break;
		n = 1;
		for(i = 0;i < h;i++){
			for(j = 0;j < w;j++){
				field[i][j] = getchar();
				if(field[i][j] == '*') l[n].first = j,l[n++].second = i, field[i][j] = '.';
				else if(field[i][j] == 'o') l[0].first = j, l[0].second = i, field[i][j] = '.';
			}
			getchar();
		}
		memset(s,-1,sizeof(s));
		for(i = 0;i < n;i++){
			que.push(l[i]);
			s[i][que.front().second][que.front().first] = 0;
			while(que.size()){
				a = que.front().first, b = que.front().second;
				for(j = 0;j < 4;j++){
					if(a + dx[j] >= 0 && a + dx[j] < w && b + dy[j] >= 0 && b + dy[j] < h && field[b + dy[j]][a + dx[j]] == '.' && s[i][b + dy[j]][a + dx[j]] == -1){
						que.push(pair<int,int>(a + dx[j],b + dy[j]));
						s[i][b + dy[j]][a + dx[j]] = s[i][b][a] + 1;
					}
				}
				que.pop();
			}
		}
		for(i = 0;i < n;i++){
			for(j = 1;j < n;j++){
				d[i][j] = s[i][l[j].second][l[j].first];
				if(i != 0){
					d[j][i] = s[i][l[j].second][l[j].first];
				}
			}
		}
		for(i = 0;i < n;i++){
			for(j = 1;j < n;j++) if(d[i][j] == -1) break;
			if(j != n) break;
		}
		if(i != n){ // もし汚れを取ることのできないタイルがあるのなら
			printf("-1\n");
			continue;
		}
		for(i = 0;i < 1 << (n - 1);i++)
			for(j = 0;j < n;j++) dp[j][i] = INF;
		dp[0][0] = 0;
		for(i = 0;i < 1 << (n - 1);i++){
			for(j = 0;j < n;j++){
				for(k = 1;k < n;k++){
					if(~i & (1 << (k - 1)) && dp[k][i | (1 << (k - 1))] > dp[j][i] + d[j][k])
						dp[k][i | (1 << (k - 1))] = dp[j][i] + d[j][k];
				}
			}
		}
		min = INF;
		for(i = 0;i < n;i++)
			if(min > dp[i][(1 << (n - 1)) - 1]) min = dp[i][(1 << (n - 1)) - 1];
		printf("%d\n",min >= INF ? -1 : min);
	}
	return 0;
}

Measured memory_bytes: 1132
// AC - B - Go to Jail

#include <bits/stdc++.h>
using namespace std;

int main(){
    int n,i,x,y,s = 0; cin >> n;
    vector<int>v[n];

    for(i = 0; i < n; i++){
        cin >> x >> y;
        v[i].push_back(x); v[i].push_back(y);
    }

     for(i = 0; i < n; i++){
        if(v[i][0] == v[i][1]){
            s = s + 1;
            if(s == 3){
                cout <<"Yes\n"; return 0;
            }
        } else s = 0;
     }
     cout <<"No\n";

     return 0;
}

Measured memory_bytes: 3636
n,m = map(int, input().split())
d = {i+1:0 for i in range(m)}
a = [list(map(int, input().split()))[1:] for _ in range(n)]
for i in a:
  for j in i:
    d[j] += 1

print(sum([i==n for i in d.values()]))


Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
#include <random>
using namespace std;

#define REP(i,n) for(int (i)=0; (i)<(n); (i)++)
#define For(i,a,b) for(int (i)=(a); (i)<(b); (i)++)

class Dice {
    vector<int> v;
public:
    Dice(int a, int b, int c, int d, int e, int f);
    int getTop();
    int getFront();
    void east();
    void south();
    void north();
    void west();
    vector<int> getContents();
    void random();
};

Dice::Dice(int a, int b, int c, int d, int e, int f) {
    v.push_back(a);
    v.push_back(b);
    v.push_back(c);
    v.push_back(d);
    v.push_back(e);
    v.push_back(f);
}

int Dice::getTop() {
    return v[0];
}

int Dice::getFront() {
    return v[1];
}

void Dice::east() {
    vector<int> e;
    e.push_back(v[3]);
    e.push_back(v[1]);
    e.push_back(v[0]);
    e.push_back(v[5]);
    e.push_back(v[4]);
    e.push_back(v[2]);
    REP(i,6) v[i] = e[i];
}

void Dice::south() {
    vector<int> e;
    e.push_back(v[4]);
    e.push_back(v[0]);
    e.push_back(v[2]);
    e.push_back(v[3]);
    e.push_back(v[5]);
    e.push_back(v[1]);
    REP(i,6) v[i] = e[i];
}

void Dice::north() {
    vector<int> e;
    e.push_back(v[1]);
    e.push_back(v[5]);
    e.push_back(v[2]);
    e.push_back(v[3]);
    e.push_back(v[0]);
    e.push_back(v[4]);
    REP(i,6) v[i] = e[i];
}

void Dice::west() {
    vector<int> e;
    e.push_back(v[2]);
    e.push_back(v[1]);
    e.push_back(v[5]);
    e.push_back(v[0]);
    e.push_back(v[4]);
    e.push_back(v[3]);
    REP(i,6) v[i] = e[i];
}

void Dice::random() {
    random_device rnd;
    switch (rnd() % 4) {
        case 0:
            west();
            break;
            
        case 1:
            north();
            break;
            
        case 2:
            south();
            break;
            
        case 3:
            east();
            break;
            
        default:
            break;
    }
}

vector<int> Dice::getContents() {
    return v;
}

bool sameDice(Dice dice, Dice dice2) {
    vector<int> v,w;
    v = dice.getContents();
    w = dice2.getContents();
    sort(v.begin(), v.end());
    sort(w.begin(), w.end());
    REP(i,6) {
        if (v[i] != w[i]) return false;
    }
    REP(i,1000) {
        dice.random();
        bool okay = true;
        REP(j,6) {
            okay *= dice.getContents()[j] == dice2.getContents()[j];
        }
        if (okay) return true;
    }
    return false;
}

bool allDifferentDice(vector<Dice> v) {
    int n = v.size();
    for (int i = 0; i < n-1; i++) {
        for (int j = i+1; j < n; j++) {
            if (sameDice(v[i], v[j])) {
                return false;
            }
        }
    }
    return true;
}

int main() {
    int n;
    cin >> n;
    vector<Dice> v;
    REP(i,n) {
        int a,b,c,d,e,f;
        cin >> a >> b >> c >> d >> e >> f;
        Dice dice(a,b,c,d,e,f);
        v.push_back(dice);
    }
    if (allDifferentDice(v)) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3240