akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<vector>
#include<set>

using namespace std;

#define int long long

void solve(string &s, vector<vector<pair<bool,set<int>>>>& ans, int b, int e){
	
	if(e - b <= 0) return;
	

	if(ans[b][e].first){
		return;
	}
		
	ans[b][e].first = true;
	

	bool flag = true;
	int num = 0, con = 0;
	
	for(int i = b, depth = 0, index = 0; i < e; i++){
		if(s[i] == '(') {
			if(!depth) con++;
			depth++;
			flag = false;
		} else if(s[i] == ')') {
			depth--;
			flag = false;
		} else if(s[i] == '+' || s[i] == '-' || s[i] == '*' || s[i] == '/') {
			if(depth) continue;
			
			solve(s, ans, b, i);
			
			solve(s, ans, i+1, e);
			
			if(s[i] == '+') {
				for(int y : ans[b][i].second){
					for(int z : ans[i+1][e].second){
						ans[b][e].second.insert(y + z);
					}
				}
			} else if(s[i] == '-') {
				for(int y : ans[b][i].second){
					for(int z : ans[i+1][e].second){
						ans[b][e].second.insert(y - z);
					}
				}
			} else if(s[i] == '*') {
				for(int y : ans[b][i].second){
					for(int z : ans[i+1][e].second){
						ans[b][e].second.insert(y * z);
					}
				}
			} else if(s[i] == '/') {
				for(int y : ans[b][i].second){
					for(int z : ans[i+1][e].second){
						if(z) ans[b][e].second.insert(y / z);
					}
				}
			}
			
			flag = false;
		} else {
			num = num * 10 + s[i] - '0';
		}
	}
	
	if(flag) {
		ans[b][e].second.insert(num);
	}
	
	if(s[b] == '(' && s[e-1] == ')' && con == 1) {
		solve(s, ans, b+1, e-1);
		
		ans[b][e] = ans[b+1][e-1];
		
		return ;
	}

}

signed main(){
	
	while(true){
		vector<vector<pair<bool,set<int>>>> ans;
		
		int n;
		string s;
		
		cin>>s;
		
		if(s == "#") break;
		
		n = s.size();
		
		ans.resize(n, vector<pair<bool,set<int>>>(n+1));

		solve(s, ans, 0, s.size());
		
		cout<<ans[0][s.size()].second.size()<<endl;
	}
}


Measured memory_bytes: 3344
import sys

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


def main():
    N, K, *L = map(int, read().split())

    L.sort(reverse=True)

    print(sum(L[:K]))

    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 61736
import itertools

N, M, Q = map(int, input().split())
A, B, C, D = [[] for _ in range(4)]

for _ in range(Q):
    a, b, c, d = map(int, input().split())
    A.append(a - 1)
    B.append(b - 1)
    C.append(c)
    D.append(d)

res = 0
for lst in itertools.combinations_with_replacement(range(0, M), N):
    res = max(res, sum([D[i] for i in range(Q) if lst[B[i]] - lst[A[i]] == C[i]]))

print(res)


Measured memory_bytes: 9164
import java.util.*;
public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		int M = Integer.parseInt(sc.next());
		int A[] = new int[M];
		int B[] = new int[M];
		UnionFind.init(N);
		for(int i = 0; i < M; i++) {
			A[i] = Integer.parseInt(sc.next()) - 1;
			B[i] = Integer.parseInt(sc.next()) - 1;
		}
		
		long ans[] = new long[M];
		ans[M - 1] = (long)N * (long)(N - 1) / 2;
		for(int i = M - 2; i >= 0; i--) {
			if(UnionFind.same(A[i + 1], B[i + 1])) {
				ans[i] = ans[i + 1];
			} else {
				ans[i] = ans[i + 1] - ((long)UnionFind.getSize(A[i + 1]) * (long)UnionFind.getSize(B[i + 1]));
			}
			UnionFind.unite(A[i + 1], B[i + 1]);
		}
		for(int i = 0; i < M; i++) {
			System.out.println(ans[i]);
		}
	}
}

class UnionFind {
	static int N;
	static int par[];
	static int rank[];
	static int size[];
	public static void init(int n) {
		N = n;
		par = new int[N];
		rank = new int[N];
		size = new int[N];
		for(int i = 0; i < N; i++) {
			par[i] = i;
			rank[i] = 0;
			size[i] = 1;
		}
	}

	public static int find(int x) {
		if(par[x] == x) {
			return x;
		} else {
			return par[x] = find(par[x]);
		}
	}
	
	public static void unite(int x, int y) {
		x = find(x);
		y = find(y);
		if(x == y) return;
		
		if(rank[x] < rank[y]) {
			par[x] = y;
			size[y] += size[x];
		} else {
			par[y] = x;
			size[x] += size[y];
			if(rank[x] == rank[y]) rank[x]++;
		}
	}
	
	public static int getSize(int x) {
		int rootX = find(x);
		return size[rootX];
	}
	
	public static boolean same(int x, int y) {
		return find(x) == find(y);
	}
}


Measured memory_bytes: 63584
#include <bits/stdc++.h>
using namespace std;
typedef long long lli;
#define mod 1000000007
#define mod2 998244353
#define fori(n) for (int i = 0; i < n; i++)
#define forj(n) for (int j = 0; j < n; j++)
#define forr(c, n) for (int i = c; i < n; i++)
#define forli(n) for (lli i = 0; i < n; i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define fast ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define endl "\n"
#define sortvec(a) sort(a.begin(), a.end())

//FUNCTONS
lli llipower(lli x, lli y)
{
    lli res = 1;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x);
        y = y >> 1;
        x = (x * x);
    }
    return res;
}
lli llipowerp(lli x, lli y, lli p)
{
    lli res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}
lli gcd(lli a, lli b)
{
    if (!a)
        return b;
    return gcd(b % a, a);
}
lli binarySearch(vector<int> arr, int l, int r, int x)
{
    if (r >= l)
    {
        lli mid = l + (r - l) / 2;
        if (arr[mid] == x)
            return mid;
        if (arr[mid] > x)
            return binarySearch(arr, l, mid - 1, x);
        return binarySearch(arr, mid + 1, r, x);
    }
    return -1;
}
template <typename T>
void printvec(vector<T> inp)
{
    for (int i = 0; i < inp.size(); i++)
    {
        cout << inp[i] << " ";
    }
    cout << endl;
}
template <typename T>
T ceildiv(T x, T y) { return 1 + ((x - 1) / y); }
lli modInverse(lli a, lli m)
{
    lli g = gcd(a, m);
    if (g != 1)
        return -1;
    else
        return llipowerp(a, m - 2, m);
}


int main()
{
    int n;
    cin>>n;
    lli sum=0;
    for(int i=1;i<=n;i++){
        if(i%3!=0 && i%5!=0) sum+=i;
    }
    cout<<sum<<endl;
    
}


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


using namespace std;

#define M 1000000007
#define pb push_back
#define f first
#define s second
#define rep(i, st, ed) for(int i=st; i<ed; i++)
#define repn(i, st, ed) for(int i=st; i<=ed; i++)
#define repb(i, ed, st) for(int i=ed; i>=st; i--)
#define all(v) v.begin(),v.end()
typedef long long ll;
typedef unsigned long long int llt;
typedef long double ld;

const long double PI  =3.141592653589793238463;
const int N = 1e5 + 10;
const ll INF = 1LL << 60;

template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}



// Main Code
int main()
{
	ll n, m;
	cin>>n>>m;
	vector<pair<ll, ll>> vp;
	rep(i, 0, n)
	{
		ll x, y;
		cin>>x>>y;
		vp.pb({x, y});
	}
	sort(all(vp));
	ll ans = 0;
	int i = 0;
	while(m != 0)
	{
		ll cnt = vp[i].s;
		chmin(cnt, m);
		//cout<<cnt<<endl;
		m = m - cnt;
		ans += cnt*vp[i].f;
		i++;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 2420
N,K = map(int,input().split())

calc = (N*(N-3))//2 + 1

if calc < K :
    print(-1)
else :
    cnt = calc - K

    ans = []
    for i in range(2,N+1) :
        ans.append([1,i])

    for i in range(2,N) :
        if not cnt > 0 :
            break

        for j in range(i+1,N+1) :
            if not cnt > 0 :
                break

            ans.append([i,j])
            cnt -= 1

    M = len(ans)

    print(M)
    for res in ans :
        print(*res)


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

using namespace std;

int main(){
    int a,b,c;
    cin>>a>>b>>c;
    for(int i=0;i<70;++i){
        if(c%(a+b)<=a)break;
        c+=60;
        if(i==69)c=-1;
    }
    cout<<c<<endl;
}

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

#define For(x,y,z) for(int x=y;x<=z;++x)

const int N = 101;
int pw[N][N*N], fac[N], inv[N];
int f[N][N], g[N][N], coe[N][N];
int n, m, K, p;

inline int qpow(int A, int B) {
	int r = 1; while(B) {
		if(B&1) r = (ll)r * A%p;
		A = (ll)A * A%p, B >>= 1;
	} return r;
}

int main() {
	scanf("%d%d%d%d", &n, &m, &K, &p);
	
	for(int i = 0; i <= K; ++ i) {
		pw[i][0] = 1;
		for(int j = 1; j <= n * m; ++ j)
			pw[i][j] = (ll)pw[i][j-1] * i%p;
	}
	
	int t = n;
	if(n < m) t = m;
	fac[0] = 1;
	for(int i = 1; i <= t; ++ i) fac[i] = (ll)fac[i-1] * i%p;
	inv[t] = qpow(fac[t], p-2);
	for(int i = t; i; -- i) inv[i-1] = (ll)inv[i] * i%p;
	
	g[0][0] = 1;
	For(t, 1, K) {
		swap(f, g);
		For(i, 0, n) For(j, 0, m)
			coe[i][j] = (ll)pw[t][i*(m-j)] * pw[K-t+1][i*j]%p * inv[i]%p;
		For(i, 0, n) For(j, 0, m) {
			int&v = g[i][j]; v = 0;
			For(k, 0, i)
				v = (v + (ll)f[i-k][j] * coe[k][j])%p;
		}
		/* definited row*/
		
		swap(f, g);
		For(i, 0, n) For(j, 0, m)
			coe[i][j] = (ll)pw[t][j*(n-i)] * pw[K-t+1][i*j]%p * inv[j]%p;
		For(i, 0, n) For(j, 0, m) {
			int&v = g[i][j]; v = 0;
			For(k, 0, j)
				v = (v + (ll)f[i][j-k] * coe[i][k])%p;
		}
		/* definited column */
		
		swap(f, g);
		For(i, 0, n) For(j, 0, m) {
			coe[i][j] = (ll)pw[t][i*(m-j)] * pw[K-t][i*j]%p * inv[i]%p;
			if(i&1) coe[i][j] = (ll)coe[i][j] * (p-1)%p;
		}
		For(i, 0, n) For(j, 0, m) {
			int&v = g[i][j]; v = 0;
			For(k, 0, i)
				v = (v + (ll)f[i-k][j] * coe[k][j])%p;
		}
		
		swap(f, g);
		For(i, 0, n) For(j, 0, m) {
			coe[i][j] = (ll)pw[t][j*(n-i)] * pw[K-t][i*j]%p * inv[j]%p;
			if(j&1) coe[i][j] = (ll)coe[i][j] * (p-1)%p;
		}
		For(i, 0, n) For(j, 0, m) {
			int&v = g[i][j]; v = 0;
			For(k, 0, j)
				v = (v + (ll)f[i][j-k] * coe[i][k])%p;
		}
	}
	
	printf("%lld\n", (ll)f[n][m] * fac[n]%p * fac[m]%p);
	return 0;
}

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

#define int long long

using namespace std;

int s[100001];
int a[100001];
int suff[100001];
int pref[100001];

 main () {
	int n, k;
	cin >> n >> k;
	for (int i = 1;i <= n;i ++) {
		cin >> a[i];
	}
	for (int i = 1;i <= n;i ++) pref[i] = pref[i - 1] + max (0ll, a[i]);
	for (int i = n;i >= 1;i --) suff[i] = suff[i + 1] + max (0ll, a[i]);
	for (int i = 1;i <= n;i ++) s[i] = s[i - 1] + a[i];
	int ans = 0;
	for (int i = 1;i + k - 1 <= n;i ++) {
		int l = i;
		int r = i + k - 1;
		int asd = pref[i - 1] + suff[i + k] + max (0ll, s[r] - s[l - 1]);
		ans = max (ans, asd);
	}
	cout << ans;
	return 0;
}

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

const int N = 3005;

int n, posa[N], posb[N], cnta = 0, cntb = 0;
string str, f[N];
bool choose[N << 1];

int main () {
	cin >> n >> str;
	for (int i = 0; i < (n << 1); i++) {
		if (str[i] == 'a') posa[cnta++] = i;
		else posb[cntb++] = i;
	}

	for (int i = n - 1; i >= 0; i--) {
		if (posa[i] < posb[i]) {
			int j = i;
			while (j < n && min(posa[j], posb[j]) <= posb[i]) j++;
			f[i] = max(f[i + 1], "ab" + f[j]);
		}
		else {
			int k = i;
			for (int j = 0; j < (n << 1); j++) choose[j] = false;
			for (int j = i; k < n && posb[k] <= posa[j]; k++) {
				if (posb[k] < posa[k]) {
					choose[posa[k]] = choose[posb[k]] = true;
					j = k;
				}
			}
			f[i] = f[k];
			for (int j = (n << 1) - 1; j >= 0; j--) {
				if (choose[j]) f[i] = str[j] + f[i];
			}
			f[i] = max(f[i], f[i + 1]);
		}
	}

	cout << f[0] << endl;
	return 0;
}

Measured memory_bytes: 10880
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
import java.lang.Math;
import java.util.Map;
import java.util.ArrayList;
import java.util.Collections;

public class Main {

    public static void main(String[] args) {
        FastScanner fs = new FastScanner();
        long x = Math.abs(fs.nextLong());
        long k = fs.nextLong();
        long d = fs.nextLong();
        long xd = x/d;

        if ( xd> k) {
            System.out.println(x-k*d);
        } else {
            k-=xd;
            if (k%2 == 0) {
                System.out.println(Math.abs(x-d*xd));
            } else {
                System.out.println(Math.abs(x-d*xd-d));

            }
        }
    }



    static class FastScanner {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st=new StringTokenizer("");
        String next() {
            while (!st.hasMoreTokens())
                try {
                    st=new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }
        int[] readArray(int n) {
            int[] a=new int[n];
            for (int i=0; i<n; i++) a[i]=nextInt();
            return a;
        }
        long nextLong() {
            return Long.parseLong(next());
        }
    }

}


Measured memory_bytes: 32732
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>


int str_cmp(const void *a,const void *b){
  return strcmp((char *)a,(char *)b);
}

int cmp(const long long int *a,const long long int *b){
  if(*a>*b){
    return -1;
  }
  else if(*a<*b)
  return 1;
  else return 0;
}




 int  main(void){
   int x=100000;
   int n;
   int i,j;
   int hanteiki;
   //printf("input the number\n");

   scanf("%d",&n);
   //printf("ok,the program is gonna list the odd number existing between 2 to %d\n",n);
   for(i=n;i<=x;i++){
     hanteiki=1;//1のまま最後まで通ったら素数ってこと。
     for(j=2;j<n;j++){
       if(i%j==0)
       hanteiki=0;
     }
     if(hanteiki==1){
       printf("%d\n",i);
       return 0;
     }

   }
   
   printf("100003");
  return 0;
}


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

int main() {
  int x , y ;
  cin >> x >> y ;

  vector<vector<char>> data(x,vector<char>(y));
  
  for(int i = 0 ; i<x ; i++){
    for(int j = 0 ; j<y; j++){
      cin >> data.at(i).at(j);
    }
  }
  
  for(int j = 0 ; j<y ; j++){
    bool tate = true ;
    for(int i = 0 ; i<x; i++){
      if(data.at(i).at(j)=='#'){
        tate = false;
        break;
      }
    }
    
    if(tate){
      for(int k = 0 ; k<x; k++){
        data.at(k).at(j)='|';
      }
    }
  }
  
  for(int i = 0 ; i<x ; i++){
    bool yoko = true ;
    for(int j = 0 ; j<y; j++){
      if(data.at(i).at(j)=='#'){
        yoko = false;
        break;
      }
    }
    
    if(yoko){
      for(int k = 0 ; k<y; k++){
        data.at(i).at(k)='-';
      }
    }
  }
  
  for(int i = 0 ; i < x ; i++){
    for(int j = 0 ; j < y ; j++){
      if(data.at(i).at(j)=='|'){
        if(j!=y-1){
          continue;
        }
        else{
          cout << endl;
          continue;
        }
      }
      if(data.at(i).at(j)=='-'){
          continue;
        
      }
      
      cout << data.at(i).at(j) ;
      if(j==y-1){
        cout << endl;
      }
    }
  }
      

}



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

string show_ans(int bit, string S){
    string ans = "";
    ans.push_back(S.at(0));
    for (int i = 0; i < 3; i++){
            if (bit & (1 << i)){
                //左からi-1番目の符号が+
                ans.push_back('+');
                ans.push_back(S.at(i + 1));                
            }else
            {
                ans.push_back('-');
                ans.push_back(S.at(i + 1));
            }
    }
  ans += "=7";
  return ans;
}
int main(){
    string S; cin >> S;
    
    int sum = S.at(0) - '0';
    //フラグが立ってたら+, なかったら-
    for (int bit = 0; bit < (1 << 3); bit++){
        for (int i = 0; i < 3; i++){
            if (bit & (1 << i)){
                //左からi-1番目の符号が+
                sum += S.at(i + 1) - '0';
            }else
            {
                sum -= S.at(i + 1) - '0';
            }
        }
        if (sum == 7){
            cout << show_ans(bit, S) << endl;
            return 0;
        }
      sum = S.at(0) - '0';
    }
    
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
 
using namespace std;
 
int main() {
  int n, t, a;
  cin >> n >> t >> a;
  int h;
  double best = 10000;
  int best_idx = 0;
  for (int i = 0; i < n; i++) {
    cin >> h;
    if(abs((t - h * 0.006) - a) <= best) {
      best = abs((t - h * 0.006) - a);
      best_idx = i;
    }
  }
  cout << best_idx + 1 << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main() {
	int n, i, j, k;
	int count;
	int l[100000];
	
	while (scanf("%d", &n) != EOF) {
		count = 0;
		if (n >= 2) l[count++] = 2;
		if (n >= 3) {
			l[count++] = 3;
			for (i = 5; i <= n; i+=2) {
				k = 0;
				for (j = 1; l[j]*l[j] <= i; j++) {
					if (i % l[j] == 0) {
						k = 1;
						break;
					}
				}
				if (k == 0) l[count++] = i;
			}
		}
		printf("%d\n", count);
	}
    return 0;
}

Measured memory_bytes: 908
#include <stdio.h>
#include <math.h>

int main() {
	int N, K, i, ten;
	double ritu = 0.0, j;

	scanf("%d %d", &N, &K);
	
	for (i = 1; i <= N; i++) {
		ten = i;
		j = 0.0;
		while (ten < K) {
			ten = ten * 2;
			j++;
		}
		ritu = ritu + 1.0 / ((double)N * pow(2.0, j));
	}

	printf("%.12f\n", ritu);

	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <vector>

using namespace std;

int main()
{
    int n,cnt=0,c=0;
    cin>>n;
    int a[n];
    bool ex[8];
    memset(ex, false, sizeof(ex));
    for (int i=0; i<n; i++) cin>>a[i];
    sort(a,a+n);
    for (int i=0; i<n; i++)
    {
        if (a[i]<3200) ex[a[i]/400]=true;
        else cnt++;
    }
    for (int i=0; i<8; i++)
    {
        if (ex[i]) c++;
    }
    if (c==0) cout<<1<<" "<<cnt<<endl;
    else cout<<c<<" "<<c+cnt<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
 int a,b,c,d;

 scanf("%d %d %d",&a,&b,&c);

 if(a>b){
  d=a;
  a=b;
  b=d;
 }

 if(b>c){
  d=b;
  b=c;
  c=d;
 }

 if(a>b){
  d=a;
  a=b;
  b=d;
 }

 printf("%d %d %d\n",a,b,c);

 return 0;

} 
   

Measured memory_bytes: 1780
#include <bits/stdc++.h>
#include<algorithm>
#define int long long
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1000000000000

signed main()
 {
   int a,b,c,k;
   cin>>a>>b>>c>>k;
   if(k>a){
     if(k>a+b){cout<<a-(k-a-b);}
     else cout<<a;
   }
   else cout<<k;
}

Measured memory_bytes: 3624
fun main(args: Array<String>) {
    var (a,b) = readLine()!!.split(" ").map(String::toInt)
    if(a==1) a = 14
    if (b==1) b = 14
    
    if(a > b) println("Alice")
    else if(a==b) println("Draw")
    else println("Bob")
}


Measured memory_bytes: 36056
import sys, random
mod = 1000000007
def get_array(): return list(map(int, sys.stdin.readline().split()))
def get_ints(): return map(int, sys.stdin.readline().split())
def input(): return sys.stdin.readline()
def print_array(a): print(" ".join(map(str, a)))
def main():
        n, k, q = get_ints()
        A = [k for _ in range(n)]
        for _ in range(q):
                A[int(input()) - 1] += 1
        for e in A:
                print("Yes" if e - q > 0 else "No")
if __name__ == "__main__":
        main()

Measured memory_bytes: 7016
pub mod contest {
    pub mod input {
        use std::io;
        use std::str::FromStr;
        use std::fmt::Debug;

        pub fn read_line<F>() -> F
        where F: FromStr, <F as FromStr>::Err: Debug {
            let mut input = String::new();
            io::stdin().read_line(&mut input).unwrap();
            input.trim().parse().unwrap()
        }

        pub fn read_words<F>() -> Vec<F>
        where F: FromStr, <F as FromStr>::Err: Debug {
            let mut input = String::new();
            io::stdin().read_line(&mut input).unwrap();
            input
                .split_whitespace()
                .map(|i| i.parse().unwrap())
                .collect()
        }

        pub fn read_matrix<F>(num_lines: usize) -> Vec<Vec<F>>
        where F: FromStr, <F as FromStr>::Err: Debug {
            (0..num_lines).map(|_| read_words()).collect()
        }

        // 所有権的な問題で SplitWhitespace を直接持てないので妥協
        // まあ、一行のデータの数なんてそんなに多くないだろうし
        pub struct WordsReader {
            words: Vec<String>,
            cur: usize,
        }

        impl WordsReader {
            pub fn new() -> Self {
                let mut input = String::new();
                io::stdin().read_line(&mut input).unwrap();
                WordsReader {
                    words: input.split_whitespace().map(|i| i.to_owned()).collect(),
                    cur: 0,
                }
            }

            pub fn next<F>(&mut self) -> F
            where F: FromStr, <F as FromStr>::Err: Debug {
                let v: F = self.words[self.cur].parse().unwrap();
                self.cur += 1;
                v
            }
        }
    }
}

use std::collections::HashSet;

fn step(abc: (i64, i64, i64)) -> Option<(i64, i64, i64)> {
    let (a, b, c) = abc;
    if a % 2 == 1 || b % 2 == 1 || c % 2 == 1 {
        None
    } else {
        Some(((b + c) / 2, (c + a) / 2, (a + b) / 2))
    }
}

fn solve(a: i64, b: i64, c: i64) -> i64 {
    let mut visited = HashSet::new();
    let mut pos = (a, b, c);
    let mut n_loop = 0;
    loop {
        match step(pos) {
            None => {
                return n_loop;
            },
            Some(new_pos) => {
                if visited.contains(&new_pos) {
                    return -1
                } else {
                    visited.insert(new_pos);
                    pos = new_pos;
                    n_loop += 1;
                }
            },
        }
    }
}

#[test]
fn test_solve() {
    assert_eq!(solve(4, 12, 20), 3);
    assert_eq!(solve(14, 14, 14), -1);
    assert_eq!(solve(454, 414, 444), 1);
}

fn main() {
    let mut wr = contest::input::WordsReader::new();
    let a: i64 = wr.next();
    let b: i64 = wr.next();
    let c: i64 = wr.next();
    println!("{}", solve(a, b, c));
}


Measured memory_bytes: 4352
//
//  main.cpp
//  multiplication 4
//
//  Created by Bryan on 05/07/20.
//  Copyright © 2020 mac. All rights reserved.
//

#include <iostream>
#include <stdio.h>
#include <algorithm>
using namespace std;
long long mod = 1000000007;

int main()
{
    long long N,K;
    scanf ("%lld %lld", &N, &K);
    long long arr[N+2];
    for (long long f = 0; f<N;f++)
        scanf ("%lld", &arr[f]);
    sort (arr,arr+N);
    long long max = arr[N-1];
    long long ans = 1;
    if (K%2==0)
    {
        long long atas = N-1;
        long long bawah = 0;
        while (K>0)
        {
            long long a = arr[atas]*arr[atas-1];
            long long b = arr[bawah]*arr[bawah+1];
            if (a>=b)
            {
                ans = ans * ((a+mod)%mod);
                ans +=mod;
                ans %=mod;
                atas-=2;
            }
            else
            {
                ans = ans * ((b+mod)%mod);
                ans += mod;
                ans %=mod;
                bawah+=2;
            }
            K-=2;
        }
    }
    else if (max == 0)
        ans = 0;
    else if (max<0)
    {
        for (long long f = N-1; f>=N-K;f--)
        {
            ans = ans*((arr[f]+mod)%mod);
            ans += mod;
            ans %= mod;
        }
            
    }
    else
    {
        ans = ans *((arr[N-1]+mod)%mod);
        ans += mod;
        ans %= mod;
        long long atas = N-2;
        long long bawah = 0;
        K--;
        while (K>0)
        {
            long long a = arr[atas]*arr[atas-1];
            long long b = arr[bawah]*arr[bawah+1];
            if (a>=b)
            {
                ans = ans * ((a+mod)%mod);
                ans +=mod;
                ans %=mod;
                atas-=2;
            }
            else
            {
                ans = ans * ((b+mod)%mod);
                ans += mod;
                ans %=mod;
                bawah+=2;
            }
            K-=2;
        }
        
    }
    ans += mod;
    ans = ans %mod;
    printf ("%lld\n",ans);
}


Measured memory_bytes: 5384
#include<stdio.h>
#include<stdlib.h>

typedef long long int int64;

#define MAX(a,b) ((a)>(b)?(a):(b))

int64 calc(const int *x,const int n,const int l){
  int64 *front=(int64 *)calloc(n+1,sizeof(int64));
  int64 *back=(int64 *)calloc(n+1,sizeof(int64));
  int i,j;
  for(i=1;i<n;i++) front[i]=front[i-1]+x[i-1]+x[i];
  for(i=n-1;i>=0;i--) back[i]=back[i+1]+2*(l-x[i]);
  int64 ans=0;
  for(i=0;i<n;i++){
    int64 local=x[i];
    j=(n-2-i)/2;
    if(i+j+1>=n-1-j) j--;
    local+=front[i+j+1]-front[i]+back[n-1-j];
    j++;
    /*
    for(j=0;i+j+1<n-1-j;j++){
      local+=x[i+j]+l-x[n-1-j];
      local+=l-x[n-1-j]+x[i+j+1];
    }
    */
    if(i+j<n-1-j) local+=x[i+j]+l-x[n-1-j];
    ans=MAX(ans,local);
  }
  free(front);
  free(back);
  return ans;
}

void run(void){
  int l,n;
  scanf("%d%d",&l,&n);
  int *x=(int *)calloc(n,sizeof(int));
  int i;
  for(i=0;i<n;i++) scanf("%d",x+i);
  int64 a=calc(x,n,l);
  for(i=0;i<n;i++) x[i]=l-x[i];
  for(i=0;i<n-1-i;i++){
    int t=x[i];
    x[i]=x[n-1-i];
    x[n-1-i]=t;
  }
  int64 b=calc(x,n,l);
  printf("%lld\n",MAX(a,b));
}

int main(void){
  run();
  return 0;
}


Measured memory_bytes: 4096
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <vector>
#include <cstdio>
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <stdio.h>
#include <stack>
#include <queue>
#include <deque>
#include <numeric>
#include<bits/stdc++.h>
#include <utility>

#define ALL(obj) (obj).begin(), (obj).end()
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define RFOR(i,a,b) for(int i = (a); (b) <= i; i--)
#define REP(i,n) for(int i = 0; i < (n); i++)
#define RREP(i,n) for(int i = n; n <= i; i--)
#define ABS(a) ((a < 0) ? ((-1)*(a)) : (a))
#define elif else if
#define MOD 1000000007
#define INF (1<<29)

using namespace std;
using ll = long long;
map <int ,int> mpa,mpb;
typedef pair<ll, ll> P;
priority_queue<P, vector<P>, greater<P>> pque;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int A[3];
  cin >> A[0] >> A[1] >> A[2];
  sort(A,A+3);
  ll ans;
  ans=A[2]*10+A[1]+A[0];
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.HashMap;
import java.util.Scanner;
import java.util.Set;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long n = sc.nextLong();
    int answer = 0;
    HashMap<Long, Long> primeMap = new HashMap<>();

    long divide = 2;
    while(n % divide == 0){
      if(primeMap.get(divide) == null){
        primeMap.put(divide, 1l);
      } else {
        long v = primeMap.get(divide);
        primeMap.put(divide, v + 1l);
      }
      n /= divide;
    }
    divide = 3;
    double l2 = Math.sqrt(n);
    while(n != 1 && (long)(l2 + 1) > divide){
      if(n % divide == 0){
        if(primeMap.get(divide) == null){
          primeMap.put(divide, 1l);
        } else {
          long v = primeMap.get(divide);
          primeMap.put(divide, v + 1l);
        }
        n /= divide;
        l2 = Math.sqrt(n);
        continue;
      } else {
        divide += 2;
      }
    }
    if(n != 1){
      if(primeMap.get(n) == null){
        primeMap.put(n, 1l);
      } else {
        long v = primeMap.get(n);
        primeMap.put(n, v + 1l);
      }
    }


    Set<Long> key = primeMap.keySet();
    for(Long val : key){
      long cnt = primeMap.get(val);
      long wk = 1l;
      long cnt2 = 0;
      while(cnt >= wk){
        cnt = cnt - wk;
        wk++;
        cnt2++;
      }
      answer += cnt2;
    }
    System.out.print(answer);
  }
}

Measured memory_bytes: 36488
#include<iostream>
using namespace std;
string x;int f,l;
int main()
{
	cin>>x;
	for(int i=0;i<x.size();i++)if(x[i]=='A'){f=i;break;}
	for(int i=x.size()-1;i>=0;i--)if(x[i]=='Z'){l=i;break;}
	cout<<l-f+1;
}

Measured memory_bytes: 644
from sys import stdin

def getval():
    n,c = map(int,stdin.readline().split())
    s = [list(map(int,stdin.readline().split())) for i in range(n)]
    return n,c,s

def main(n,c,s):
    arr = [[0 for i in range(c)] for i in range(10**5)]
    for i in s:
        ch = i[2]-1
        for j in range(i[0]-1,i[1]):
            arr[j][ch] = 1
    ans = 0
    for i in range(10**5):
        loc = arr[i]
        temp = 0
        for j in range(c):
            temp += loc[j]
        ans = max(temp,ans)
    print(ans)

if __name__=="__main__":
    n,c,s = getval()
    main(n,c,s)

Measured memory_bytes: 122336
n = int(input())
A = list(map(int, input().split()))
M = max(A)
m = min(A)
M_idx = A.index(M) + 1
m_idx = A.index(m) + 1
print(2*n-1)
if abs(M) >= abs(m):
  for i in range(1, n+1):
    print(M_idx, i)
  for i in range(1, n):
    print(i, i+1)
else:
  for i in range(1, n+1):
    print(m_idx, i)
  for i in range(n-1, 0, -1):
    print(i+1, i)

Measured memory_bytes: 3064
// D - I hate Factorization
#include <bits/stdc++.h>

using namespace std;

int main(int argc, char *argv[])
{
	long long x;
	cin >> x;

	vector<long long> a;
	for (long long i = 0; ; i++) {
		long long t = i * i * i * i * i;
		if (t > 1e16) break;
		a.push_back(t);
	}

	for (long long i = 0; i < a.size(); i++) {
		for (long long j = 0; j < i; j++)
			if (a[i] - a[j] == x) {
				cout << i << ' ' << j << endl;
				return 0;
			}
		for (long long j = 0; j < a.size(); j++) {
			if (a[i] + a[j] == x) {
				cout << i << ' ' << -j << endl;
				return 0;
			} else if (a[i] + a[j] > x)
				break;
		}
	}

	return 0;
}


Measured memory_bytes: 3656
#pragma gcc optimize ("O3")
char S[12];
char out[2<<20],*p=out;
int Slen;
main()
{
	int N,K;
	scanf("%d%d ",&N,&K);
	gets(S);
	Slen=strlen(S);
	S[Slen++]='\n';
	for(int i=0;i<K;i++)
	{
		memcpy(p,S,Slen);
		p+=Slen;
	}
	for(int i=K;i<N;i++)
	{
		*p++='7';
		*p++='\n';
	}
	write(1,out,p-out);
}

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

int main() {
    string N;
    cin >> N;
    ll sum = 0;
    for (int i = 0; i < N.size(); ++i) {
        sum += N[i]-'0';
    }
    if (sum % 9 == 0) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3752
#include<iostream>
#include<algorithm>
using namespace std;

int main(){
  int N,X,a=0;
  cin>>N>>X;
  int l[N];
  for(int i=0;i<N;++i)cin>>l[i];
  
  sort(l,l+N);
  	for(int i=0;i<N;++i){
      X-=l[i];
      	if(X>=0)a++;
      	else break;
    }
  if(X>0)cout<<a-1;
  else cout<<a;
  
  
  
  
}


Measured memory_bytes: 3164
#include<stdio.h>

int depth(int);
int n,count=0;
typedef struct{
  int k;
  int parent;
  int right;
  int left;
} node;

node A[100000];

int main()
{
  int i,j,k,x,c,l,child,id;

  scanf("%d",&n);

  for(i=0;i<n;i++)
    {
            A[i].parent=-1;
      A[i].right=-1;
      A[i].left=-1;
    }
  
  for(i=0;i<n;i++)
    {
      scanf("%d",&id);
      scanf("%d",&A[id].k);
      for(j=0;j<A[id].k;j++)
	{
	  scanf("%d",&child);
	  if(j==0)
	    {
	      A[id].left=child;
	      A[child].parent=id;
	      c=child;
	    }

	  else
	    {
	      A[c].right=child;
	      A[child].parent=id;
	      c=child;
	    }
	}
    }

  for(i=0;i<n;i++)
    {
      count=0;
      printf("node %d: parent = %d, depth = %d, ",i,A[i].parent,depth(i));
      if(A[i].parent==-1) printf("root, [");
      else if(A[i].left==-1) printf("leaf, [");
      else if(A[i].left!=-1) printf("internal node, [");

      if(A[i].left!=-1)
	{
	  printf("%d",A[i].left);
	  l=A[i].left;
	
	  for(j=0;j<A[i].k-1;j++)
	    {	    
	      printf(", %d",A[l].right);

	      l=A[l].right;
	    }
	}
      printf("]\n");
    }

  return 0;
}


  
int depth(int m)
{
  int l;
  l=A[m].parent;
  if(l==-1) return count;
  count++;
  depth(l);
}

Measured memory_bytes: 2172
#gcdは3.4.3だとfractionsにある
from fractions import gcd

from math import factorial as f

from math import ceil,floor,sqrt

from sys import exit

from copy import deepcopy
import numpy as np

import bisect
import re


ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))



def main():
    n = ii()

    a = li()
    b = li()
    c = li()

    ans = 0

    for i in range(n):
        ans+=b[i]

    for i in range(n-1):
        if a[i+1] == a[i]+1:
            ans+=c[a[i]-1]

    print(ans)


main()


Measured memory_bytes: 22820
if __file__.startswith('/tmp'):
	import sys; sys.stdin = open('input.txt')

n, x = map(int, raw_input().split())

def foo(a, b):
	if a == b: return a
	if a > b: return foo(b, a)
	if a == 0: return -b
	return 2 * a * (b / a) + foo(b % a, a)

print n + foo(x, n - x)

Measured memory_bytes: 2952
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int n, d; cin >> n >> d;
  int x[n][d];
  for (int i = 0; i < n; i++){
    for (int j = 0; j < d; j++) {
      cin >> x[i][j];
    }
  }

  int ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      long double dist = 0;
      for (int k = 0; k < d; k++) {
        dist += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
      }
      dist = sqrt(dist);
      if (ceil(dist) == floor(dist)) ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
ll INFL = 1000000000000000010;//10^18 = 2^60
int INF = 2147483600;//10^9
ll MOD  = 1000000007;
ll N,M;
ll A[100010], B[100010];
ll par[100010];
ll Rank[100010];
ll Size[100010];

void init(ll n){
    for(ll i = 0; i < n; i++){
        par[i] = -1;
        Rank[i] = 0;
        Size[i] = 1;
    }
}

//木の根を調べる
ll find(ll x){
    if(par[x] == -1){
        return x;
    }
    else{
        return par[x] = find(par[x]);
    }
}

void unite(ll x, ll y){
    x = find(x);
    y = find(y);
    if(x == y) return;
    
    if(Rank[x] < Rank[y]){
        par[x] = y;
        Size[y] += Size[x];
    }else{
        par[y] = x;
        Size[x] += Size[y];
    }
    if(Rank[x] == Rank[y]) Rank[x]++;
}

bool same(ll x, ll y){
    return find(x) == find(y);
}


int main(void){
    // Your code here!
    cin >> N >> M;
    for(ll i = 0; i < M; i++){
        cin >> A[i] >> B[i];
        A[i]--;
        B[i]--;
    }
    
    init(N);
    
    ll Ans[M];
    ll ans;
    
    ans = N * (N-1) / 2;
    for(ll i = M-1; i >= 0; i--){
        Ans[i] = ans;
        ll x = A[i],y = B[i];
        if(!same(x, y)){
            ans -= Size[find(x)] * Size[find(y)];
            unite(x, y);
        }
    }
    for(ll i = 0; i < M; i++){
        cout << Ans[i] << endl;
    }
    
}


Measured memory_bytes: 6016
parseInt(x::String) = parse(Int, x)
parseInt(x::SubString{String}) = parse(Int, x)
parseInt(x::Char) = parse(Int, x)
parseInt(x::Float64) = trunc(Int, x)
parseFloat(x::String) = parse(Float64, x)
parseFloat(x::Int) = trunc(Float64, x)
parseFloat(x::SubString{String}) = parse(Float64, x)
parseFloat(x::Char) = parse(Float64, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
    h,w=parseMap(split(readline()))
    println("#"^(w+2))
    for i in 1:h
        println(join(['#',chomp(readline()),'#']))
    end
    println("#"^(w+2))
end
main()

Measured memory_bytes: 186388
import std.algorithm;
import std.array;
import std.container;
import std.conv;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

const MOD = 10^^9 + 7;

long calc(long[] a) {
    long[61] zero, one;
    foreach (e; a) {
        for (int i = 0; i <= 60; i++) {
            if (e & (1L << i)) one[i]++;
            else zero[i]++;
        }
    }

    long ans = 0;
    for (int i = 0; i <= 60; i++) {
        // 0 と 1 のペア数
        long cnt = zero[i] * one[i] % MOD;
        ans += ((1L << i) % MOD) * cnt % MOD;
        ans %= MOD;
    }
    return ans;
}

void main() {
    read;
    auto a = reads!long;
    writeln(calc(a));
}

void scan(T...)(ref T a) {
    string[] ss = readln.split;
    foreach (i, t; T) a[i] = ss[i].to!t;
}
T read(T=string)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readints = reads!int;


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

using namespace std;

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

    char b;
    cin >> b;

    if(b == 'A')
        cout << "T";
    else if(b == 'C')
        cout << "G";
    else if(b == 'G')
        cout << "C";
    else
        cout << "A";

    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
const int mod=924844033;
long long dp[4010][2010][2],g[4010],f[4010];
bool vis[2010][2],End[4010];
int n,K;
int ADD(int x)
{
	return (x>=mod)?x-mod:x;
}
int main()
{
	scanf("%d%d",&n,&K);
	int sum=0;
	for (int i=1;i<=n;i++)
		for (int j=0;j<=1;j++)
		{
			if (vis[i][j]) continue;
			int len=0;
			for (int x=i,y=j;x<=n;x+=K,y^=1)
			{
				vis[x][y]=true;
				len++;
			}
			sum+=len;
			End[sum]=true;
		}
	dp[0][0][0]=1;
	for (int i=1;i<=(n<<1);i++)
		for (int j=0;j<=n;j++)
		{
			dp[i][j][0]=ADD(dp[i-1][j][0]+dp[i-1][j][1]);
			if (j>0&&!End[i]) dp[i][j][1]=dp[i-1][j-1][0];
		}
	f[0]=1;
	for (int i=1;i<=n;i++) f[i]=f[i-1]*i%mod;
	for (int i=0;i<=n;i++) g[i]=ADD(dp[(n<<1)][i][0]+dp[(n<<1)][i][1]);
	int j=1;
	long long ans=0;
	for (int i=0;i<=n;i++)
		ans=(ans+g[i]*f[n-i]%mod*j%mod+mod)%mod,j=-j;
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 125824
#pragma GCC optimize("O3")
#include <stdio.h>
#include <functional>
#include <algorithm>
#include <vector>
#include <utility>
using namespace std;
#define PB push_back
#define F first
#define S second
constexpr int kN = int(5E5 + 10), kBlk = 710;

int c[kN], cnt[kN], ans[kN];
pair<int, int> p[kN];
vector<int> v[kBlk];

int main() {
	int n, q, now = 0, lpos = 0, rpos = -1;
	bool f = true;
	scanf("%d%d", &n, &q);
	for (int i = 1; i <= n; i++) scanf("%d", &c[i]);
	for (int i = 1; i <= q; i++) scanf("%d%d", &p[i].F, &p[i].S);
	for (int i = 1; i <= q; i++) v[p[i].F / kBlk].PB(i);

	for (int i = 0; i < kBlk; i++) {
		if (f) sort(v[i].begin(), v[i].end(), [&](int a, int b) {return p[a].S == p[b].S ? p[a].F < p[b].F : p[a].S < p[b].S;});
		else sort(v[i].begin(), v[i].end(), [&](int a, int b) {return p[a].S == p[b].S ? p[a].F < p[b].F : p[a].S > p[b].S;});
		for (int j : v[i]) {
			while (rpos < p[j].S) if (cnt[c[++rpos]]++ == 0) now++;
			while (lpos > p[j].F) if (cnt[c[--lpos]]++ == 0) now++;
			while (lpos < p[j].F) if (--cnt[c[lpos++]] == 0) now--;
			while (rpos > p[j].S) if (--cnt[c[rpos--]] == 0) now--;
			ans[j] = now;
		}
		f = !f;
	}
	for (int i = 1; i <= q; i++) printf("%d\n", ans[i]);
}


Measured memory_bytes: 16868
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
#define MOD                 1000000007LL
#define EPS                 1e-9
#define io                  ios_base::sync_with_stdio(false);cin.tie(NULL);

const int MAXN = 1e5+5;

int isPrime[MAXN];	//isPrime[i] = 0 indicates i is prime. 
void sieve(){
	//if even check itself while calling. This function will only tells wether a number is prime or not(not for even numbers).
	isPrime[0] = isPrime[1] = 1;
	for(int i = 2; i*i <= MAXN; i++){
		if(isPrime[i] == 0){
			if(i*(ll)1*i <= MAXN){
				for(int j = i*i; j <= MAXN; j += (i)){
					isPrime[j] = 1;
				}
			}
		}
	}
}

int similar[MAXN];
int pre[MAXN];

int main(){
	io;
	sieve();
	for(int i = 1;i <= 100000; i += 2){
		if(isPrime[i] == 0 && isPrime[(i+1)/2] == 0)
			similar[i]++;
	}
	// cout << similar[3] << " " << similar[5] << " " << similar[7] << endl;
	for(int i = 1;i <= 100000; i++)
		pre[i] = pre[i - 1] + similar[i];
	int q;
	cin >> q;
	while(q--){
		int l, r;
		cin >> l >> r;
		cout << pre[r] - pre[l-1] << endl;
	}
	return 0;
}

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


int main(){
  ll N, K;
  cin >> N >> K;
  ll H[N];
  REP(i, N) cin >> H[i];
  sort(H, H+N);
  ll ans = 0;
  REP(i,N-K) ans += H[i];
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
bool a[10000001],b[100000001];
int main()
{
	int n,m;cin>>n>>m;
	for(int i=1;i<=m;i++){
		int ax,bx;cin>>ax>>bx;
		if(ax==1)a[bx]=1;
		if(bx==n)b[ax]=1;
	}
	for(int i=1;i<=m;i++){
		if(a[i]&&b[i]){
			cout<<"POSSIBLE";return 0;
		}
	}
	cout<<"IMPOSSIBLE";
	return 0;
}


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

#define REP(i,n) for(int i=0;i<(n);++i)
#define FORR(it,cont) for(auto it=rbegin(cont);it!=rend(cont);++it)
#define FOR(it,cont) for(auto it=begin(cont);it!=end(cont);++it)
#define ALL(cont) begin(cont), end(cont)
#define LB(b,e,v) lower_bound(b,e,v)
#define UB(b,e,v) upper_bound(b,e,v)
#define AS_MOD(a,b) ((((a) % (b) ) + (b)) % (b))
#define MODDING(a,b) (a) = AS_MOD(a,b)
#define MAXIMIZE(a, b) (a) = max((a),(b))
#define MINIMIZE(a, b) (a) = min((a),(b))

using namespace std;
typedef long long ll;
int N;
string P,Q;
string S2;
ll dptable[20][20];
ll doDP(int p, int q) {
  if (dptable[p][q]!=-1) {
    return dptable[p][q];
  }
  if (p == P.length() && q == Q.length()) {
    return dptable[p][q] = 1;
  }
  int i=p+q;
  ll val = 0;
  if (p < P.length() && S2[i] == P[p]) {
    val += doDP(p+1, q);
  }
  if (q < Q.length() && S2[i] == Q[q]) {
    val += doDP(p, q+1);
  }
  return dptable[p][q] = val;
}
int main(int argc, char **argv, char **envp) {
  string S;
  cin >> N >> S;
  S2 = S;
  reverse(S2.begin(), S2.end());
  S2.resize(N);
  //cout << S2 << endl;
  ll ans=0;
  for(int comb=0;comb< (1<<N);++comb) {
    P=Q="";
    for(int i=0;i<N;++i) {
      if((comb >> i) & 1 == 1) {
        P+=S[i];
      } else {
        Q+=S[i];
      }
    }
    memset(dptable,-1,sizeof(dptable));
    ans += doDP(0,0);
    //cout << P << " " << Q << endl;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ULL;

int main(){
string A, chars="abcdefghijklmnopqrstuvwxyz"; cin >> A;
ULL l=A.size(), ans=l*(l-1)/2+1; map<char, ULL> freq;
for(ULL i=0; i<l; i++){ freq[A[i]]++; }
for(ULL i=0, q=0; i<26; i++){ q=freq[chars[i]]; ans-=q*(q-1)/2; }
cout << ans << "\n";
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 
  string s,t;
  cin >> s;
  
  for(int i=0;i<s.size();i++){
    if(s.at(i)=='B'){
      if(t!=""){
        t.pop_back();
      }
    }else{
      t+=s.at(i);
    }
  }
  cout << t << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{ int N,M;
int sum=0;
 cin>>N>>M;
  vector<int>V(M);
 for(int i=0;i<M;i++)
  { cin>>V[i];
   sum+=V[i];
}
   if(sum>N)  
	{ cout<<-1;
}
  else
 cout<<N-sum;
return 0;
}


Measured memory_bytes: 3612
#include <iostream>
#include <list>
using namespace std;

int main()
{
	string S;
	int Q;

	cin >> S;
	cin >> Q;

	list<char> l;
	for (int i = 0; i < (int)S.length(); ++i)
	{
		l.push_back(S[i]);
	}

	bool reversed = false;
	for (int i = 0; i < Q; ++i)
	{
		int mode, f;
		char c;

		cin >> mode;
		if (mode == 1)
		{
			reversed = !reversed;
		}
		else if (mode == 2)
		{
			cin >> f >> c;
			if (f == 1)
			{
				if (reversed) 
				{
					l.push_back(c);
				}
				else 
				{
					l.push_front(c);
				}

			}
			else if (f == 2)
			{
				if (reversed) 
				{
					l.push_front(c);
				}
				else 
				{
					l.push_back(c);
				}
			}
		}
	}
	if (reversed)
	{
		for (auto itr = l.rbegin(); itr != l.rend(); ++itr)
		{
			cout << (*itr);
		}
	}
	else
	{
		for (auto itr = l.begin(); itr != l.end(); ++itr)
		{
			cout << (*itr);
		}
	}

	return 0;
}


Measured memory_bytes: 9984
#include <iostream>
using namespace std;

int main(){
    int a,b,c;
    int cnt=0;
    
    cin >> a >> b >> c;
    
    for(int i=a;i<=b;i++){
        if(c%i==0) cnt++;        
    }
    
    cout << cnt << endl;
    
    return 0;
}


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

typedef long long ll;
typedef pair<int, int> pii;
#define FOR(i, n) for(int (i)=0; (i)<(n); (i)++)
#define FOR1(i, n) for(int (i)=1; (i)<=(n); (i)++)
#define FORI(i, n) for(int (i)=n-1; (i)>=0; (i)--)

int main(int argc, char** argv) {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout << setprecision(15);
    if (argc == 2 && atoi(argv[1]) == 123456789) {
        freopen("d:\\code\\cpp\\contests\\stdin", "r", stdin);
        //freopen("d:\\code\\cpp\\contests\\stdout", "w", stdout);
    }

    int r;
    cin >> r;
    cout << r*r << endl;


    if (argc == 2 && atoi(argv[1]) == 123456789)        cerr << clock()*1.0/CLOCKS_PER_SEC << " sec\n";
    return 0;
}

Measured memory_bytes: 256
import copy

def main():

    N = int(input())
    A = [int(input()) for _ in range(N)]

    srtdA = copy.copy(A)
    srtdA.sort(reverse=True)
    atmax = srtdA[0]
    atsecond = srtdA[1]


    for  a in A:
        if a==atmax:
            print(atsecond)
        else:
            print(atmax)

if __name__== "__main__":
    main() 


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

using namespace std;

const int maxn=1e5+500;
struct node{
    int x,y,t;
}s[maxn];
 
int main()
{
    int n;
    cin>>n;
    s[0].t=0,s[0].x=0,s[0].y=0;
    for(int i=1;i<=n;i++){
       cin>>s[i].t>>s[i].x>>s[i].y;
    }
    int i;
    for(i=1;i<=n;i++){
        int a=abs(s[i].x-s[i-1].x)+abs(s[i].y-s[i-1].y);
        int b=s[i].t-s[i-1].t;
        if(a%2!=b%2||b<a)
            break;
    }
    if(i>n)
        printf("Yes\n");
    else
        printf("No\n");
    return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
//---------------------------------//

int N;
int A[212345];
map<int, ll> dp[212345][2];

ll dfs(int i, bool used, int sum) {
	if (i == N) {
		if (sum == N / 2) return 0;
		else return -longINF;
	}
	if (sum > N / 2) return -longINF;
	
	int res = N - i - used;
	if (res < 0 || res == 0 && sum != N / 2) return -longINF;
	
	int can = (res + 1) / 2;
	if (sum + can < N / 2) return -longINF;
	
	if (used) return dfs(i + 1, false, sum);
	
	if (dp[i][used].find(sum) != dp[i][used].end()) return dp[i][used][sum];
	
	ll mx = dfs(i + 1, true, sum + 1) + A[i];
	chmax(mx, dfs(i + 1, false, sum));
	return dp[i][used][sum] = mx;
}

int main() {
	cin >> N;
	REP(i, N) scanf("%d", A + i);
	cout << dfs(0, 0, 0);
	return 0;
}


Measured memory_bytes: 61824
N = int(input())
L = list(map(float, input().split()))

L.sort()

while True:
    a = L.pop(0)
    b = L.pop(0)
    tmp = (a + b) / 2
    L.append(tmp)
    L.sort()
    if len(L) == 1:
        print(tmp)
        break



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

namespace ConsoleTest
{
    class Program
    {
        static int[] CalcRange(int zei, int rate)
        {
            bool minJust = ((zei ) * 100) % rate == 0;
            int min = (zei * 100) / rate + (minJust ? 0 : 1);
            bool maxJust = ((zei + 1) * 100) % rate == 0;
            int max = ((zei + 1) * 100) / rate - (maxJust?1:0);
            return new int[] { min, max };
        }

        static void TaxTest(int rate)
        {
            for(int i = 1; i <=100; ++i)
            {
                int[] r = CalcRange(i, rate);
                if ((r[0] * rate) / 100 != i) throw new InvalidOperationException(string.Format("cond 1 ({0}, {1}) {2}", i, rate, r[0]));
                if (((r[0]-1) * rate) / 100 == i) throw new InvalidOperationException(string.Format("cond 2 ({0}, {1}) {2}", i, rate, r[0]));
            }
        }

        static void Main(string[] args)
        {
            //TaxTest(8);
            //TaxTest(10);




            int[] ps = Console.ReadLine().Split(' ')
                .Select(s => int.Parse(s))
                .ToArray();

            var r8 = CalcRange(ps[0], 8);
            var r10 = CalcRange(ps[1], 10);
            //Console.WriteLine(string.Format("zei {0} : ({1} {2})", ps[0], r8[0], r8[1]));
            //Console.WriteLine(string.Format("zei {0} : ({1} {2})", ps[1], r10[0], r10[1]));
            var merge = new int[] { Math.Max(r8[0], r10[0]), Math.Min(r8[1], r10[1]) };
            if (merge[0] <= merge[1])
            {
                Console.WriteLine(merge[0]);
            }
            else
            {
                Console.WriteLine("-1");
            }


        }
    }
}


Measured memory_bytes: 13396