akhauriyash/Code-Regression huggingface dataset:
#include <algorithm> //STLͨ���㷨
#include <cmath> //������ѧ����
#include <cstdio> //��������/�������
#include <iostream> //����������/���
#include <cstring> //�ַ�������
#include <string> //�ַ�����
#include <ctime> //�������ʱ��ĺ���
#define itn int
#define fro for
#define ll long long
#define reg register
#define inf 1234567890
#define rep(i,a,b,c) for (int i=a;i<=b;i+=c)
/*#include <bitset> //STLλ������
#include <cstype> //�ַ�����
#include <cerrno> //���������
#include <complex> //������
#include <clocale> //���屾�ػ�����
#include <cstdlib> //������������ڴ���亯��
#include <deque> //STL˫�˶�������
#include <exception> //�쳣������
#include <fstream> //�ļ�����/���
#include <functional> //STL�������㺯��(���������)
#include <limits> //�����������������ֵ����
#include <list> //STL�����б�����
#include <map> //STLӳ������
#include <iomanip> //����������/���
#include <ios> //��������/���֧��
#include <iosfwd> //����/���ϵͳʹ�õ�ǰ������
#include <istream> //����������
#include <ostream> //���������
#include <queue> //STL��������
#include <set> //STL��������
#include <sstream> //�����ַ�������
#include <stack> //STL��ջ����
#include <stdexcept> //��׼�쳣��
#include <streambuf> //�ײ�����/���֧��
#include <utility> //STLͨ��ģ����
#include <vector> //STL��̬��������
#include <cwchar.h>//���ַ�����������/���
#include <cwctype.h> //���ַ�����*/

using namespace std;

int ans;

int max(int x,int y){return x>y?x:y;}

int min(int x,int y){return x<y?x:y;}

int abs(int x){return x>0?x:-x;}

int gcd(int x,int y){return (!y)?x:gcd(y,x%y);}

void exgcd(int a,int b,int &d,int &x,int &y){if (!b){d=a,x=1,y=0;}else{exgcd(b,a%b,d,y,x);y-=x*(a/b);}}

int quick_power(ll a,int b){ll r=1;for (;b;b>>=1,a=a*a)if (b&1) r=r*a;return r;}

inline char read() {
	static const int IN_LEN = 1000000;
	static char buf[IN_LEN], *s, *t;
	return (s == t ? t = (s = buf) + fread(buf, 1, IN_LEN, stdin), (s == t ? -1 : *s++) : *s++);
}
template<class T>
inline void read(T &x) {
	static bool iosig;
	static char c;
	for (iosig = false, c = read(); !isdigit(c); c = read()) {
		if (c == '-') iosig = true;
		if (c == -1) return;
	}
	for (x = 0; isdigit(c); c = read()) x = x * 10 + (c ^ '0');
	if (iosig) x = -x;
}

char sr[10000000],z[20];int C=-1,Z=0;
void Ot(){fwrite(sr,1,C+1,stdout),C=-1;}
void print(int x){
	if (x<0) sr[++C]='-',x=-x;
	while(z[++Z]=x%10+48,x/=10);
	while(sr[++C]=z[Z],--Z);sr[++C]='\n';
}
//int find(int x){return fa[x]=fa[x]==x?x:find(fa[x]);}

//void add(int x,int y,int z){to[++cnt]=y;v[cnt]=z;Next[cnt]=head[x];head[x]=cnt;}
const int N=100100;
int n;
ll a[N],p[62];

void insert(ll x)
{
	for (int i=60;i>=0;i--)
		if (x>>i&1)
		{
			if (!p[i])
			{
				p[i]=x;
				break;
			}
			x^=p[i];
		}
}

int main()
{
	read(n);
	ll all=0;
	for (int i=1;i<=n;i++) read(a[i]),all^=a[i];
	for (int i=0;i<=60;i++)
		if (all>>i&1)
			for (int j=1;j<=n;j++)
				if (a[j]>>i&1) a[j]-=(1ll<<i);
	for (int i=1;i<=n;i++) insert(a[i]);
	ll ans=0;
	for (int i=60;i>=0;i--)
		if ((p[i]^ans)>ans) ans=p[i]^ans;
	cout<<ans+(ans^all);
	return 0;
}








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

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i)
#define rrepLRE(i, l, r) for (ll i = (l); i >= (r); --i)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

ll dx[9] = {-1, 1, 0, 0, -1, -1, 1, 1, 0};
ll dy[9] = {0, 0, -1, 1, -1, 1, -1, 1, 0};

/* Macros reg. ends here */

const ll INF = 1LL << 50;

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

  ll n, a, b;
  cin >> n >> a >> b;

  if (a > b) {
    cout << 0 << endl;
    return 0;
  }
  if (n == 1) {
    if (a == b)
      cout << 1;
    else
      cout << 0;
    return 0;
  }
  if(n == 2) {
    cout << 1 << endl;
    return 0;
  }

  ll ma = b * (n - 1) + a;
  ll mi = a * (n - 1) + b;

  ll ans = ma - mi + 1;
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>

using namespace std;
#define repeat(i, n) for(int i=0;i<(n);i++)
vector<int> g[100005];
int dep[100005];
int sz[100005]; // subtree
int par[100005];

void dfs(int j, int i=-1){
   par[j]=i;
   sz[j]=1;
   for(int k: g[j])if(i!=k){
      dep[k]=dep[j]+1;
      dfs(k, j);
      sz[j]+=sz[k];
   }
}

int main(){
   
   int N;
   cin>> N;
   repeat(i, N-1){
      int a, b;
      cin>> a>> b;
      g[a-1].push_back(b-1);
      g[b-1].push_back(a-1);
   }

   dfs(0);
   int d=dep[N-1];
   int n=N-1;
   repeat(i, (d-1)/2) n=par[n];
   int snu=sz[n];
   int fen=N-sz[n];

   cout<< (fen>snu? "Fennec": "Snuke")<< endl;

   return 0;
}


Measured memory_bytes: 13184
//AOJ Problem0030

#include<iostream>
#include<vector>

using namespace std;

int ans;

void solve(int n,int s,int m,int sum,int max){//n:何個か s:目的値 m:何回目か sum:現在の合計 max:最大の足した数
	
	if(m>n || sum>s){
		return;
	}

	else if(n==m && sum==s){
		ans++;
		return;
	}

	else{
		for(int i=max+1;i<=9;i++){
		
			solve(n,s,m+1,sum+i,i);
		}
	}
}

int main(){

	int n,s;

	vector<int> dataN;
	vector<int> dataS;

	for(;;){
		cin>>n;
		cin>>s;
		if(n==0&&s==0){
			break;
		}
		dataN.push_back(n);
		dataS.push_back(s);
	}
	for(int j=0;j<dataN.size();j++){

		ans=0;

		for(int i=0;i<=9;i++){
			solve(dataN[j],dataS[j],1,i,i);
		}

		cout<<ans<<endl;
	}

	return 0;
}

Measured memory_bytes: 1216
#!/usr/bin/env python3
#ABC60 D

import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7

n,W = map(int,input().split())
wv = [list(map(int,input().split())) for _ in range(n)]
mw = wv[0][0]
w = [[] for _ in range(4)]
for i,j in wv:
    w[i-mw].append(j)
for i in range(4):
    w[i].sort(reverse = True)
    w[i] = list(accumulate(w[i]))
w = [[0] + w[i] for i in range(4)]
a,b,c,d = len(w[0]),len(w[1]),len(w[2]),len(w[3])
ans = 0
for i in range(a):
    for j in range(b):
        for k in range(c):
            for l in range(d):
                if i*mw + j*(mw+1) + k*(mw+2) + l*(mw+3) <= W:
                    ans = max(ans,w[0][i]+w[1][j]+w[2][k]+w[3][l])
print(ans)


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

int main() {
	int S;
	cin>>S;
	cout<<S/3600<<":"<<(S-3600*(S/3600))/60<<":"<<S-(3600*(S/3600))-(((S-3600*(S/3600))/60)*60)<<endl;
	return 0;
}

Measured memory_bytes: 3108
#include <stdio.h>


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

Measured memory_bytes: 1712
#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<ll, ll>;

void solve(long long K) {
    string S = "ACL";
    string ans = "";
    rep(i, K) {
        ans += S;
    }
    cout << ans << endl;
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main() {
    long long K;
    scanf("%lld", &K);
    solve(K);
    return 0;
}


Measured memory_bytes: 3684
N, X = map(int, input(). split())
a, p = [1], [1]

for n in range(N):
    a.append(a[n]*2 + 3)
    p.append(p[n]*2 + 1)

def xmas(N, X):
    if N == 0:
        return 0 if X <= 0 else 1
    elif X <= 1 + a[N-1]:
        return xmas(N-1, X-1)
    else :
        return p[N-1] + 1 + xmas(N-1, X-(a[N-1]+2))

print(xmas(N, X))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vll = vector<long long>;
using vp = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
template<class T> inline bool chmax(T &a, T b) { if (a<b) {a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, T b) { if (b<a) {a=b; return 1;} return 0;}

template <typename T>
vector<int> zalgo(T s) {
    int n = (int)s.size();
    vector<int> res(n, 0);
    res[0] = n;
    int i = 1, j = 0;
    while (i < n) {
        while (i+j < n && s[i+j] == s[j]) j++;
        res[i] = j;
        if (j == 0) { i++; continue;}
        int k = 1;
        while (i+k < n && k + res[k] < j) res[i+k] = res[k], ++k;
        i += k; j -= k;
    }
    return res;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int n;
    string s;
    cin >> n >> s;
    int ans = 0;
    rep(i, n-1) {
        auto res = zalgo(s.substr(i, n-i));
        for (int j = 1; j < sz(res); ++j) chmax(ans, min(j, res[j]));
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
 int isprime(int x){
    if(x==2) return true;
    if(x<2||x%2==0) return false;
    else{
        int i=3;
        while(i<=sqrt(x)){
            if(x%i==0) return false;
            i = i+2;
        }
        return true;
    }
}

int main() {
    int n;
    cin >> n;
    int a[n],b;
    b=0;
    for(int i=0;i<n;i++){
        cin >> a[i];
        if(isprime(a[i])!=0){
            b++;
        }
    }
    cout << b << endl;
}



Measured memory_bytes: 3084
#include <stdio.h>
#include <string.h>


int main(void)
{
    int i,j,top,dice[10],dice2[10];

    for(i=0;i<6;i++){
        scanf("%d",&dice[i]);
    }
    for(i=0;i<6;i++){
        scanf("%d",&dice2[i]);
    }
    
    for(i=0;i<8;i++){
        if(memcmp(dice,dice2,sizeof(dice))==0)break;
        if(dice[0]==dice2[0]){
            for(j=0;j<4;j++){
                top=dice2[1];
                dice2[1]=dice2[2];
                dice2[2]=dice2[4];
                dice2[4]=dice2[3];
                dice2[3]=top;
                if(memcmp(dice,dice2,sizeof(dice))==0) goto OUT;
            }
        }
        if(i<4){
                top=dice2[0];
                dice2[0]=dice2[1];
                dice2[1]=dice2[5];
                dice2[5]=dice2[4];
                dice2[4]=top;
        }else{
                top=dice2[0];
                dice2[0]=dice2[2];
                dice2[2]=dice2[5];
                dice2[5]=dice2[3];
                dice2[3]=top;
        }
    }
    OUT:

    if(memcmp(dice,dice2,sizeof(dice))==0){
        printf("Yes\n");
    }else{
        printf("No\n");
    }
    return 0;
}




Measured memory_bytes: 2048
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<list>
#include<cmath>

using namespace std;
typedef long long ll;
/*
D G
p1 c1
...
pD cD

D <= 10
pi num of problems <= 100
ci complete bonus <= 1000000
score: 100i
G goal score

output total num of problems
*/
ll pow(int x, int n){
  if(n == 0)
    return 1;
  else
    return x * pow(x, n - 1);
}

bool bit(int b, int i){
  return (b >> i) % 2 == 1;
}

int D;
ll G;

int* p;
ll* c;
int p_num;

ll positive(ll x){
  return max(x, (ll)0);
}

ll calc_score(int b){
  // total score of completed
  ll cscore = 0;
  for(int i = 0; i < D; i++)
    if(bit(b, i)) cscore += 100 * (i + 1) * p[i] + c[i];

  cerr << "cscore = " << cscore << endl;
  // total score of not completed
  ll G1 = G - cscore;
  ll score = 0;
  p_num = 0;
  for(int i = D - 1; i >= 0; i--){
    cerr << "i = " << i << " (" << 100 * (i + 1) << ") : ";

    int num;
    if(bit(b, i)){
      num = p[i];
    } else {
      num = min( (ll)ceill( (long double)( positive(G1) / (100 * (i + 1) ) )) , (ll)p[i] - 1);      
      G1 -= 100 * (i + 1) * num;
    }
    score += 100 * (i + 1) * num + (num == p[i] ? c[i] : 0);
    p_num += num;
    cerr << "num = " << num << ", G1 = " << G1 << endl;
  }
  cerr << "p_num = " << p_num << endl;

  return score;
}


int main(){
  scanf("%d %lld", &D, &G);

  p = (int*)malloc(sizeof(int) * D);
  c = (ll*)malloc(sizeof(ll) * D);

  for(int i = 0; i < D; i++){
    scanf("%d %lld", &p[i], &c[i]);
    cerr << "p_{" << i + 1 << "} = " << p[i] << ", ci = " << c[i] << endl; 
  }

  int ans = 0;
  for(int i = 0; i < D; i++)
    ans += p[i];
  
  for(int b = 0; b < pow(2, D); b++){
    cerr << "--- b = " << b << endl;

    ll score = calc_score(b);
    cerr << "score = " << score << endl;
    
    if(score >= (ll)G && p_num < ans)
      ans = p_num;
  }

  cout << ans << endl;

  free(p);
  free(c);
  
  return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
    using namespace std;
    #pragma GCC optimize("Ofast")
    #pragma GCC optimize("unroll-loops")
    #pragma GCC optimize ("-ffloat-store")  
    #pragma GCC optimize ("-fno-defer-pop") 
    #define ll long long int
    #define ps push_back
    #define fs first
    #define sc second
    #define mkp make_pair
    #define mod 1000000007
    ll an[101][100001];
    ll maxwt(ll W,ll n,ll w[],ll v[]){
    	if(n==0||W==0){
    		return 0;
    	}
    	if(an[n][W]>-1) return an[n][W];
    	if(w[n]>W){
    		an[n][W]=maxwt(W,n-1,w,v);
    	}
    	else {
    		an[n][W]=max(maxwt(W,n-1,w,v),v[n]+maxwt(W-w[n],n-1,w,v));
    	}
    	return an[n][W];
    }
    int main(){
    	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    	
    	ll n,W,i,j,k,l;
    	cin>>n>>W;
    	for(i=0;i<101;i++){
    		for(j=0;j<100001;j++){
    			an[i][j]=-1;
    		}
    	}
    	ll w[n+1],v[n+1];
    	for(i=1;i<=n;i++){
    		cin>>w[i]>>v[i];
    	}
     
    	k=maxwt(W,n,w,v);
    	cout<<k;
    	return 0;
    }

Measured memory_bytes: 79360
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pi 3.141592653589793238
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define mod 1000000007
void solve()
{
	ll x,a,b;
	cin>>x>>a>>b;
	if(abs(x-a)<=abs(x-b))
		cout<<"A";
	else
		cout<<"B";
	return;
}


int main()
{
	fast;
	ll q;
	q=1;
	// cin>>q;
	while(q--)
	{
		solve();
	}
	return 0;
}


Measured memory_bytes: 3620
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
#include <set>
#include <map>
using namespace std;

const int MAX_N = 8;
int N;
int G[MAX_N][MAX_N];
priority_queue<pair<int,int> > que;
set<int> vis;
int f[10];
int ten[10];

int make() {
  f[0] = f[1] = 1;
  for(int i = 2; i < 10; ++i) f[i] = f[i-1]*i;
  ten[0] = 1;
  for(int i = 1; i < 10; ++i) ten[i] = ten[i-1]*10;
}

int getDigit(int s, int n) { return s/ten[n]%10; }

int my_swap(int s, int a, int b) {
  int A = getDigit(s,a);
  int B = getDigit(s,b);
  return s - A*ten[a] - B*ten[b] + A*ten[b] + B*ten[a];
}

int solve() {
  int v = 0;
  for(int i = 0; i < N; ++i) v += i*ten[i];
  que.push(make_pair(0,v));

  int ans = 0;
  while(!que.empty() && vis.size() < f[N]) {
    int cost = que.top().first;
    v = que.top().second;
    que.pop();
    if(vis.find(v) != vis.end()) continue;
    vis.insert(v);
    ans = min(ans,cost);

    for(int i = 0; i < N; ++i) {
      for(int j = i+1; j < N; ++j) {
	int nv = my_swap(v,i,j);
	if(vis.find(nv) == vis.end()) {
	  que.push(make_pair(cost-G[i][j],nv));
	}
      }
    }
  }
  return -ans;
}

int main() {
  make();
  cin >> N;
  for(int i = 0; i < N; ++i) {
    for(int j = 0; j < N; ++j) {
      cin >> G[i][j];
    }
  }
  cout << solve() << endl;
  return 0;
}

Measured memory_bytes: 5196
#include<bits/stdc++.h>
using namespace std;
int n;
int a[100005],ans;
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    scanf("%d",&a[i]);
    sort(a+1,a+n+1);
    for(int i=1;i<=n;i++)
    {
        for(int j=i+1;j<=n;j++)
        {
            int lef=j+1;
            int l=0,r=n+1;
            while(l<r)
            {
                int mid=(l+r)/2;
                if(a[mid]>=a[i]+a[j])
                r=mid;
                else l=mid+1;
            }
            ans+=l-lef;
        }
    }
    cout<<ans;
}

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

#define endl '\n'

using namespace std;

int main(){

  cin.tie(0);     // cout と cin の同期を切る
  ios::sync_with_stdio(false);  /* cの stdioストリーム (printfとか)と*/

  int N;

  int a,b;
  
  cin>>N;

  if(N==1){

    cout<<"Hello World"<<endl;

  }
  else{

    cin>>a>>b;

    cout<<a+b<<endl;

  }
    
  
  return 0;

}


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

using namespace std;
typedef long long ll;

int main() {
    int n, x, t;
    cin >> n >> x >> t;
    if (n % x != 0) {
        cout << (n / x + 1) * t << endl;
    } else {
        cout << (n / x) * t << endl;
    }
    return 0;
}


Measured memory_bytes: 3592
trip = int(input())
sumiit = [int(i) for i in input().split()]
count = 1
for i in range(1, trip):
    jug = []
    for n in range(0, i):
        if sumiit[n] <= sumiit[i]:
            jug.append(True)
        else:
            jug.append(False)
    if all(jug):
        count += 1
print(count)



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

int main() {
    ll n, x, m;
    cin >> n >> x >> m;
    set<ll> s;
    vector<ll> v;
    v.push_back(x);
    s.insert(x);
    ll lsz;
    vector<ll>::iterator it;
    while (true) {
        ll a = (v.back() * v.back()) % m;
        ll sz = s.size();
        s.insert(a);
        if (sz == s.size()) {
            it = find(v.begin(), v.end(), a);
            lsz = s.size() - distance(v.begin(), it);
            break;
        }
        v.push_back(a);
    }
    ll idx = distance(v.begin(), it);
    ll bsum = 0;
    if (it != v.begin()) {
        bsum = accumulate(v.begin(), it, 0ll);
    }
    ll lsum = accumulate(it, v.end(), 0ll);
    ll ans = 0;
    if (v.size() >= n) {
        cout << accumulate(v.begin(), v.begin() + n, 0ll) << endl;
    }
    else {
        ans += bsum;
        n -= distance(v.begin(), it);
        ans += (n / lsz) * lsum;
        ans += accumulate(it, it + (n % lsz), 0ll);
        cout << ans << endl;
    }
}

Measured memory_bytes: 5984
N, T = map(int, input().split())

carr = []
carr2 = []
tarr = []

for i in range(N):
    c, t = map(int, input().split())
    carr.append(c)
    tarr.append(t)

for y in range(N):
    if tarr[y] <= T:
        carr2.append(carr[y])

if carr2 ==[]:
    print('TLE')
else:
    print(min(carr2))
    


Measured memory_bytes: 3060
#include <cstdio>
#include <iostream>

using namespace std;

typedef long long ll;
const int MAXN = 16;

int n, a[MAXN][MAXN], b[MAXN+1];
ll f[1<<MAXN], g[1<<MAXN];

inline int count(int x)
{
	int res = 0;
	for(int i=0;i<n;++i)
		if(x&(1<<i)) ++res;
	return res;
}

int main()
{
	scanf("%d",&n);
	for(int i=0;i<n;i++)
		for(int j=0;j<n;j++)
			scanf("%d",&a[i][j]);
	const int MAXS = 1<<n;
	for(int s=1;s<MAXS;s++)
	{
		int num = 0; g[s] = 0;
		for(int i=0;i<n;i++)
			if(s & (1<<i)) b[++num] = i;
		for(int i=1;i<num;i++)
			for(int j=i+1;j<=num;j++)
				g[s] += a[b[i]][b[j]];
	}
	for(int s=1;s<MAXS;s++){
		for(int t=s;t;t=(t-1)&s){
			f[s] = max(f[s], f[t] + g[s^t]);
		}
		f[s] = max(f[s], g[s]);
	}
	printf("%lld\n",f[MAXS-1]);
	return 0; 
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
 
using namespace std;
 
#define MAX 100000
 
int N, M;
int par[MAX], rank[MAX];
typedef pair<double,double> P;
void init(){
    for(int i = 0 ; i < N ; i++){
	par[i] = i;
	rank[i] = 0;
    }
}
 
int find(int x){
    if(par[x] == x){
	return x;
    }else{
	return par[x] = find(par[x]);
    }
}
 
void unite(int x,int y){
    x = find(x);
    y = find(y);
 
    if(x == y) return;
 
    if(rank[x] < rank[y]){
	par[x] = y;
    }else{
	par[y] = x;
 
	if(rank[x] == rank[y]){
	    rank[x]++;
	}
    }
}
 
bool same(int x,int y){
    return find(x) == find(y);
}
 
struct edge{
    int u,v;
    double cost;
};
 
bool comp(const edge &e1,const edge &e2){
    return e1.cost > e2.cost;
}
 
edge es[MAX];
 
double kruskal(){
    init(); sort(es , es + M, comp);
    double res = 0;
    for(int i = 0 ; i < M ; i++){
	edge e = es[i];
	if(!same(e.u , e.v)){
	    unite(e.u , e.v);
	    res += e.cost;
	}
    }
    return res;
}
 
double dist(P p1, P p2){
    return sqrt(pow(p1.first-p2.first,2)+pow(p1.second-p2.second,2));
}
 
int main(){
    int a,b;
    P p[MAX];
 
    scanf("%d %d" ,&N ,&M);
    for(int i = 0 ; i < N ; i++){
	scanf("%lf%lf",&p[i].first, &p[i].second);
    }
    double total = 0;
    for(int i = 0 ; i < M ; i++){
	scanf("%d %d" ,&a ,&b);  
	a--, b--;
	double d = dist(p[a], p[b]);
	es[i].u = a; es[i].v = b; es[i].cost = d;
	total += d;
    }
    printf("%.5f\n",total-kruskal());
    return 0;
}

Measured memory_bytes: 3360
#include <iostream>
#include <vector>

using namespace std;

int main(int argc, char const *argv[])
{
    int a, b;
    cin >> a >> b;
    if ((b - 1) % (a - 1) == 0)
    {
        cout << (b - 1) / (a - 1);    
    } else
    {
        cout << (b - 1) / (a - 1) + 1;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb push_back
#define fr first
#define sc second
#define all(x) x.begin(), x.end()
#define skip continue
#define NAME "code"
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
 
void faster(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
 
const ll INF = 1e9;
const ll MOD = 1e9 + 7;
const ll MAXN = 2e3 + 123;
const ld EPS = 1e-12;
const int dx[4] = {-1, 0, 0, 1};
const int dy[4] = {0, -1, 1, 0};

int n, m;
vector<int> q[2], ans;

void solve(){
	cin >> n >> m;

	for(int i = 0, x; i < m; ++i){
		cin >> x;
		q[x & 1].pb(x);
		if(m == 1){
			if(x > 1){
				cout << x << '\n';
				cout << 2 << '\n';
				cout << x - 1 << ' ' << 1 << '\n';
			}
			else{
				cout << x << '\n';
				cout << 1 << '\n';
				cout << x << '\n';
			}
			return;
		}
	}

	if(q[1].size() > 2){
		cout << "Impossible";
		return;
	}

	if(!q[1].empty()){
		ans.pb(q[1].back());
		q[1].pop_back();
	}

	for(int x : q[0])
		ans.pb(x);

	if(!q[1].empty()){
		ans.pb(q[1].back());
		q[1].pop_back();
	}

	for(int x : ans){
		cout << x << ' ';
	}

	ans.front()--;
	ans.back()++;
	if(!ans.front())
		ans.erase(ans.begin());

	cout << '\n' << ans.size() << '\n';
	
	for(int x : ans){
		cout << x << ' ';
	}
}

int main(){

	faster();
 
	int T = 1;
	// cin >> T;
	
	while(T--){
		solve();
	}
 
	return 0;
}

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

#define rep(i, n) for(int i=0; i<n; ++i)
#define repit(it, li) for(auto it=li.begin(); it!=li.end(); it++)
#define ll long long int

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

   int ans=1000*(x/500)+5*(x%500/5);

   cout << ans << endl;
   return 0;
}


Measured memory_bytes: 3596
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cmath>
#include <iomanip>
#include <cassert>
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) (int)(x).size()
using namespace std;
using ll = long long;
constexpr ll INF = 3000000000000000000;

int main() {
    string A;
    cin >> A;
    
    vector<vector<int>> S(26);
    REP(i, SZ(A)) S[A[i] - 'a'].push_back(i);
    REP(i, 26) S[i].push_back(SZ(A));
    vector<int> T(SZ(A) + 2, 1001001001);
    T[SZ(A) + 1] = 0;
    T[SZ(A)] = 1;
    for (int i = SZ(A) - 1; i >= 0; --i) {
        REP(j, 26) {
            T[i] = min(T[i], T[*lower_bound(ALL(S[j]), i) + 1] + 1);
        }
    }
    
    string ans;
    int now = 0;
    while (now < SZ(A) + 1) {
        REP(i, 26) {
            if (T[*lower_bound(ALL(S[i]), now) + 1] == T[now] - 1) {
                now = *lower_bound(ALL(S[i]), now) + 1;
                ans.push_back('a' + i);
                break;
            }
        }
    }
    
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 5172
#include <iostream>
#include<vector>
#include<algorithm>
#include<cstring>
#include<string>
#include <set>
#include <cassert>
#include<cmath>
using namespace std;
#define MOD 1000000007
class UnionFind {
	vector<int> data;
public:
	UnionFind(int size) : data(size, -1) { }
	bool unionSet(int x, int y) {
		x = root(x); y = root(y);
		if (x != y) {
			if (data[y] < data[x]) swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
		return x != y;
	}
	bool findSet(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};

int find(vector<long long> &arr, long long obj) {
	if (arr[arr.size() - 1] < obj)return arr.size()-1;
	if (arr[0] > obj)return -1;

	int min = 0; int max = arr.size() - 1;
	for (int i = 0; i < arr.size(); i++) {
		if (arr[min+(max-min) / 2] > obj) {
			max = min + (max - min) / 2;
		}
		else {
			min = min + (max - min) / 2;
		}
		if (max - min == 1) {
			return min;
		}
	}


}


int main() {
	long long a, b, c, k;
	cin >> a >> b >> c >> k;
	if (k % 2 == 0) {
		cout << a - b;
	}
	else {
		cout << b - a;
	}


	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string.h>

using namespace std;

int main(void)
{
    long long hist[100][21];
    int n;
    int form[100];
    
    scanf("%d", &n);
    for (int i = 0; i < n; i++){
        scanf("%d", &form[i]);
    }
    
    memset(hist, 0, sizeof(hist));
    
    hist[0][form[0]] = 1;
    for (int i = 1; i < n - 1; i++){
        for (int j = 0; j < 21; j++){
            if (hist[i - 1][j] > 0){
                if (j - form[i] >= 0 && j - form[i] <= 20) 
                    hist[i][j - form[i]] += hist[i - 1][j];
                if (j + form[i] >= 0 && j + form[i] <= 20)
                    hist[i][j + form[i]] += hist[i - 1][j];
            }
        }
    }
    
    cout << hist[n - 2][form[n - 1]] << endl;
    
    return (0);
}

Measured memory_bytes: 0
n, m = map(int, input().split())
l_list = []
r_list = []
for i in range(m):
    l, r = map(int, input().split())
    l_list.append(l)
    r_list.append(r)
if min(r_list) - max(l_list) < 0:
    print(0)
    exit()
else:
    print(min(r_list) - max(l_list) + 1)


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

#define ll long long int
ll mod=1e9+7;

int main()
{
    /* Faster input ouput */
    // ios_base::sync_with_stdio(false);
    // cin.tie(NULL);
    // cout.tie(NULL);

    /* To read input from a file and output to a file */
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
    
    ll t = 1;
    // cin >> t;
    while(t--)
    {        
        ll n,i,j,k;
        cin >> n >> k;
        ll arr[n];
        ll max_len = INT_MIN;
        for(i=0;i<n;i++)
        {
            cin >> arr[i];
            max_len = max(max_len,arr[i]);
        }

        sort(arr,arr+n,greater<ll> ());

        if(k == 0)
        {
            cout << max_len << '\n';
        }
        else
        {
            // do bs on what lengths can be obtained

            ll start = 1;
            ll end = max_len;

            while(start < end)
            {
                ll mid = (start + end)/2;
                // cout << start << " " << mid << " " << end << '\n';
                // compute k, repeatedly divide by 2 to get a value less than or equal to mid
                ll ops = 0;
                for(i=0;i<n;i++)
                {
                    ll logl = arr[i];
                    // ll count = 0;
                    // while(logl > mid)
                    // {
                    //     // logl /= 2;
                    //     double num = ceil((double(logl)/2.0));
                    //     logl = num;
                    //     ops = ops + (ll)(pow(2,count));
                    //     count++;
                    // }
                    // double num = ceil((double(logl)/(double) mid));
                    if(logl > mid)
                    {
                        ops += (logl/mid);
                    }
                }   

                // cout << ops << '\n';

                if(ops <= k)
                {
                    end = mid;
                }
                else
                {
                    start = mid + 1;
                }
            }

            cout << (start) << '\n';
        }
        


    }
    
    return 0;
}

Measured memory_bytes: 5208
#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,x,y;
cin>>a>>b>>c>>x>>y;
if(a+b<2*c){cout<<a*x+b*y;}
else{
  int k=0;
  if(x>=y){k=c*y*2+a*(x-y);}
  else k=c*x*2+b*(y-x);
  cout<<min(k,c*max(x,y)*2);
}
}


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

int main()
{
	int n;
	cin>>n;
	double a[n],s=0;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		s+=1.0/a[i];
	}
	cout<<1.0/s<<endl;
}

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

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

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

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

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

  int N;
  cin >> N;
  VVI xs(3, VI(N));
  REP(k,3){
	REP(i,N) cin >> xs[k][i];
	SORT(xs[k]);
  }

  LL ans = 0;
  REP(i,N){
	LL l1 = lower_bound(ALL(xs[0]), xs[1][i]) - begin(xs[0]);
	LL l2 = N - (upper_bound(ALL(xs[2]), xs[1][i]) - begin(xs[2]));
	ans += l1 * l2;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1792
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define F first
#define S second
#define int long long
#define ll long long
//#define int  unsigned long long
#define pb push_back
#define double long double

using namespace std;
using namespace __gnu_pbds;
typedef  tree< int , null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
const int N = 610000;
const int K = 19;
const int mod = 1e9 + 7;
int f[N], invf[N], inv2, inv3, a[N], b[N], pr[N], len[N], dp[2][N], n;
int nxt(int x){
    if (x == pr[x]) return x;
    return pr[x] = nxt(pr[x]);
}
void solve(int k){
    for (int i = 1; i <= n; i++){
        pr[i] = i;
        len[i] = 0;
        b[i] = 0;
    }
    dp[k][n] = 0;
    b[n] = 1e9;
 //   cout << "K = " << k << endl;
    for (int i = n - 1; i >= 1; i--){
        int x = a[i];
        vector < int > ev;
        ev.clear();
        if (x <= a[i + 1]){
            int c = 0;
            while(x + x + x + x <= a[i + 1]){
                c++;
                x += 3 * x;
            }
            if (c == 0){
                pr[i] = nxt(i + 1);
                len[pr[i]]++;
            } else b[i] = c;
            dp[k][i] = dp[k][i + 1];
           // cout << "! i = " << i << " " << dp[k][i] << endl;
        } else{
            int p = i + 1;
            int c = 0;
            int y = a[i + 1];
            while(y < x){
                y += 3 * y;
                c++;
            }
            int res = 0;
           // cout << "c = " << c << endl;
            while(c != 0){
                p = nxt(p);
                res += c * len[p];
         //   cout << nxt(6) << " yyy " << nxt(7) << endl;
           //   cout << p << " -- " << nxt(p) << " " << nxt[4] << endl;
                if (p == 0) exit(0);
                if (b[p] > c){
                    res += c;
                    b[p] = b[p] - c;
                    c = 0;
                    break;
                } else
                if (b[p] <= c){
                    res += c;
                    c -= b[p];
                    b[p] = 0;
                   // cout << p << " qq " << " " << b[5] << " " << nxt(p) << " " << nxt(p + 1) << endl;
                    ev.pb(p);
                }
                p++;
               // cout << i << " " << p << endl;
            }

            pr[i] = nxt(i + 1);
            len[nxt(i)]++;
            dp[k][i] = dp[k][i + 1] + res;
            reverse(ev.begin(), ev.end());
            for (auto j: ev){
                int z = len[nxt(j)];
                pr[j] = nxt(j + 1);
                len[nxt(j)] += z + 1;
            }
          //  cout << "i = " << i << " " << dp[k][i] << endl;
        }
    }
}
main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen("input.txt", "r", stdin);
    cin >> n;
    for (int i = 1; i <= n; i++){
        cin >> a[i];
    }
    solve(0);
    reverse(a + 1, a + n + 1);
    solve(1);
    int ans = 1e15;
    for (int i = 0; i < n; i++){
        ans = min(ans, i + 2 * dp[1][n - i] + 2 * dp[0][i + 1]);
    }
    cout << ans;
}


Measured memory_bytes: 22272
#include <iostream>
#include <iomanip> //! for setprecision(10)
#include <math.h>
#include <algorithm>
#include <functional> 
#include <string>
#include <vector>

#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <utility>
#include <limits.h>

using namespace std;

typedef long long LL;

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define dump(c) { for (auto it = c.begin(); it != c.end(); ++it) if (it == c.begin()) cout << *it; else cout << ' ' << *it; cout << endl; } 
#define dumpMap(m) { for (auto it: m) cout << it.first << "=>" << it.second << ' '; }

const int MOD = 1000000007;

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(0);
    
    int A, B;
    cin >> A >> B;

    cout << (A*B) << endl;

    return 0;
}


Measured memory_bytes: 3648
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <utility>
#include <cmath>
#define REP(i, n) for(int i = 0; i < n; i++)
#define SORT(x) sort(x.begin(), x.end())
#define RSORT(x) sort(x.begin(), x.end(), std::greater<int>())
#define swap(a, b) \
  do { typeof(a) __tmp = (a); (a) = (b); (b) = __tmp; } while (0)
using namespace std;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
long long m, a, r, c, h;
int N;

int main() {

  cin >> N;
  
  REP(i, N) {
    
    string s;
    cin >> s;
    switch(s[0]) {
    case 'M': ++m; break;
    case 'A': ++a; break;
    case 'R': ++r; break;
    case 'C': ++c; break;
    case 'H': ++h; break;
    default:
      continue;
    }
  }
  
  long long sum = 0;
  sum += (m * a * r);
  sum += (m * a * c);
  sum += (m * a * h);
  sum += (m * r * c);
  sum += (m * r * h);
  sum += (m * c * h);
  sum += (a * r * c);
  sum += (a * r * h);
  sum += (a * c * h);
  sum += (r * c * h);
  cout << sum << endl;
  
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define E "\n"

using namespace std;
const long long MOD = (long long)1e9 + 7;

int n;

int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n;
    int ans = n % 1000;
    ans = 1000 - ans;
    ans %= 1000;
    cout << ans << E;
    //system("pause");
    return 0;
}

Measured memory_bytes: 3648
def wa(x):
    return ((x+1)*x)/2


s = input()

d = '<'
r = '>'

prev = r
count = 0
array = []

for i in s:
    if i == prev:
        count += 1
    else:
        array.append([prev, count])
        count = 1
        prev = i

array.append([prev, count])

for i in range(len(array)-1):
    if array[i][0] == d and array[i+1][0] == r:
        if array[i][1] <  array[i+1][1]:
            array[i][1] -= 1
        else:
            array[i+1][1] -= 1

ans = 0
for i in array:
    ans += wa(i[1])

print(int(ans))

Measured memory_bytes: 89928
import sys
sys.setrecursionlimit(2**20)  


class Node:
    def __init__(self,key,left=None,right=None,parent=None):
        self.key = key
        self.left = left
        self.right = right
        self.parent = parent

ROOT = None

def pre_parse(u, pre_ls):
    if u == None:
        return
    pre_ls.append(u.key)
    pre_parse(u.left, pre_ls) 
    pre_parse(u.right, pre_ls)


def in_parse(u, in_ls):
    if u == None:
        return
    in_parse(u.left, in_ls)
    in_ls.append(u.key)
    in_parse(u.right, in_ls)


def insert(value):
    global ROOT
    y = None
    x = ROOT
    z = Node(value)  
    while x != None:
        y = x  
        if z.key < x.key:
            x = x.left
        else:
            x = x.right
            
    z.parent = y

    if y == None:
        ROOT = z
    else:
        if z.key < y.key:
            y.left = z
        else:
            y.right = z


def find(u, value):
    while u != None and u.key != value:
        if value < u.key:
            u = u.left
        else:
            u = u.right
    return u


def deleteNode(z):
    
    if (z.left == None or z.right == None):
        y = z
    else:
        y = getSucessor(z)

    if y.left is not None:
        x = y.left
    else:
        x = y.right

    if x is not None:
        x.parent = y.parent

    if y.parent is None:
        ROOT = x
    elif y == y.parent.left:
        y.parent.left = x
    else:
        y.parent.right = x

    if y != z:
        z.key = y.key

def getSucessor(x):
    if x.right is not None:
        return getMinimum(x.right)

    y = x.parent
    
    while y and x == y.right:
        x = y
        y = y.parent
    return y


def getMinimum(x):
    while x.left != None:
        x = x.left
    return x
    
    
def print_result():
    pre_ls, in_ls = [], []
    in_parse(ROOT, in_ls)
    pre_parse(ROOT, pre_ls)
    print('', *in_ls)
    print('', *pre_ls)

n = int(input())

for i in range(n):
    tmp = input()
    if tmp[0] == "p":
        print_result()
    elif tmp[0] == "f":
        if find(ROOT, int(tmp[5:])):
            print("yes")
        else:
            print("no")
    elif tmp[0] == "i":
        insert(int(tmp[7:]))
    else:
        deleteNode(find(ROOT, int(tmp[7:])))



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

char str[200005];
int cnt[200005][2];
bool ok[200005];
vector<int> g[200005];
set< pair<int, int> > already;
queue<int> q;

int main(){
    int n, m;
    scanf("%d%d", &n, &m);
    scanf("%s", str);
    for(int i=0;i<m;i++){
        int aa, bb;
        scanf("%d%d", &aa, &bb);
        aa--; bb--;
        if(already.find({aa, bb}) != already.end()) continue;
        if(already.find({bb, aa}) != already.end()) continue;
        g[aa].push_back(bb);
        g[bb].push_back(aa);
        cnt[aa][str[bb]-'A']++;
        cnt[bb][str[aa]-'A']++;
        already.insert({aa, bb});
        already.insert({bb, aa});
    }
    for(int i=0;i<n;i++){
        if(cnt[i][0] == 0 || cnt[i][1] == 0){
            ok[i] = false;
            q.push(i);
        }else{
            ok[i] = true;
        }
    }
    int lft = n;
    while(!q.empty()){
        int me = q.front(); q.pop();
        lft--;
        for(auto &nxt: g[me]){
            if(!ok[nxt]) continue;
            cnt[nxt][str[me]-'A']--;
            if(cnt[nxt][0] == 0 || cnt[nxt][1] == 0){
                ok[nxt] = false;
                q.push(nxt);
            }
        }
    }
    if(lft) printf("Yes\n");
    else printf("No\n");
}


Measured memory_bytes: 30336
import math
import itertools
def gcd(lst):
  return math.gcd(math.gcd(lst[0],lst[1]), lst[2])

k = int(input())
lst = [i for i in range(1,k+1)]
itr = itertools.combinations_with_replacement(lst, 3)
ans = 0

for i in itr:
  st = set(i)
  num = len(st)
  if num == 1:
    ans += i[0]
  elif num == 2:
    a,b = st
    ans += math.gcd(a,b) * 3
  else:
    ans += math.gcd(math.gcd(i[0],i[1]), i[2]) * 6

print(ans)

Measured memory_bytes: 9200
using System;

public class Test
{
	static public void Main( )
	{
		int[] nm = Array.ConvertAll( Console.ReadLine().Split( ' ' ), int.Parse );
		int n = nm[0];
		int m = nm[1];
		int[,] a = new int[ n, m ];
		int[] b = new int[ m ];
		int[] c = new int[ n ];		
		for( int i=0; i<n; i++ ) {
			int[] row = Array.ConvertAll( Console.ReadLine().Split( ' ' ), int.Parse );
			for( int j=0; j<m; j++ ) {
				a[ i, j ] = row[j];
			}
		}
		for( int i=0; i<m; i++ ) {
			b[i] = int.Parse( Console.ReadLine() );
		}
		for( int i=0; i<n; i++ ) {
			for( int j=0; j<m; j++ ) {
				c[i] += ( a[ i, j ] * b[j] );
			}
			Console.WriteLine( c[i] );
		}		

	}
}

Measured memory_bytes: 19956
N=int(input())
A=list(map(int,input().split()))

def selectionSort(A,N):
    count = 0
    for i in range(N):
        mini=i
        for j in range(i,N):
            if A[j]<A[mini]:
                mini=j
        if i!=mini:
            tmp = A[i]
            A[i]=A[mini]
            A[mini] = tmp
            count += 1


    print(' '.join(list(map(str, A))))
    print(count)

selectionSort(A,N)


Measured memory_bytes: 5604
colors = [int(i) for i in list(input())]

def func(colors):
  count = 0
  prev_color = colors[0]
  for i in range(1, len(colors)):
    if colors[i] == prev_color:
      colors[i] = 1 if prev_color == 0 else 0
      count += 1
    prev_color = colors[i]
  return count

print(max(func(colors), func(list(reversed(colors)))))

Measured memory_bytes: 4652
#include<iostream>
#include<queue>
#define int long long
using namespace std;
priority_queue<pair<int,int> > lis;
const int N=2e5+2;
int ar[N],ar1[N];
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n,i,j,k,l,z,val,mod,num=0;
	cin>>n;
	for(i=1;i<=n;i++){
		cin>>ar[i];
	}	
	for(i=1;i<=n;i++){
		cin>>ar1[i];
		if(ar1[i]<ar[i]){
			cout<<-1;
			return 0;
		}
		if(ar1[i]!=ar[i]){
			lis.push({ar1[i],i});
		}
	}
	while(lis.size()){
		j=lis.top().first;
		k=lis.top().second;
		lis.pop();
		if(k==1){
			l=n;
		}
		else{
			l=k-1;
		}
		z=k%n+1;
		mod=ar1[z]+ar1[l];
		val=max(ar[k],j%mod);
		i=(j-val)/mod;
		if(i==0){
			cout<<-1;
			return 0;
		}
		j-=i*mod;
		num+=i;
		ar1[k]=j;
		if(j!=ar[k]){
			lis.push({j,k});
		}
	}
	cout<<num;
}

Measured memory_bytes: 9072
n=int(input())
# n=26*26+26+1
basis=[26**i for i in range(12)]
l=[]
s=0
for b in basis:
    s+=b
    l.append(s)    

i=0
f=12
while(f-i>1):
#     print(f-i)
    x=(i+f)//2
    if l[x]>n:
        f=x
    else:
        i=x

length=i+1
k=n-(l[length-1]-1)
x=k-1
res=[]
for i in range(length):
    q=x//26
    r=x%26
    x=q
    res.append(r)

ans=list(map(lambda x: chr(ord("a")+x),list(reversed(res))))
print("".join(ans))

Measured memory_bytes: 9152
#include<stdio.h>
#define PRIME 1
#define COMPO 0
int is_prime( int x ){

  if ( x == 2 ) return PRIME;

  int i;
  for ( i = 2 ; i < x ; i++ ){

    if ( i * i > x ) return PRIME;

    if ( x % i == 0 ) return COMPO;

  }

  return 0;

}

int main(){

  int i,j,n,a[10001],count;

  scanf("%d", &n );

  count = 0;
  
  for ( i = 0 ; i < n ; i++ ){
    scanf("%d", &a[i] );
    if ( is_prime( a[i] ) == PRIME ) count += 1;
  }

  printf("%d\n", count );

  return 0;

}

Measured memory_bytes: 628
import java.util.Scanner;

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

		int a = scan.nextInt();
		if(a == 1){
			a = 100;
		}
		int b = scan.nextInt();
		if(b == 1){
			b = 100;
		}

		if(a > b){
			System.out.println("Alice");
		}
		else if(a < b){
			System.out.println("Bob");
		}
		else{
			System.out.println("Draw");
		}
	}
}


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

using namespace std;

int main () {

	int n, d;
	scanf("%d %d", &n, &d);
	
	int ans = n / (2 * d + 1);
	int add =!!( n % (2 * d + 1) );

	printf("%d\n", ans + add);

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, e) for (int i = (int)(s); i <= (int)(e); i++)
#define printYesNo(is_ok) puts(is_ok ? "Yes" : "No");
#define SORT(v) sort(v.begin(), v.end());
#define RSORT(v) sort(v.rbegin(), v.rend());
#define REVERSE(v) reverse(v.begin(), v.end());

int main()
{
    int N;
    cin >> N;
    vector<int> colors(N, 1);
    map<int, vector<pair<int, int>>> edges;
    rep(i, N - 1)
    {
        int u, v, w;
        cin >> u >> v >> w;
        u--;
        v--;
        w %= 2;
        edges[u].emplace_back(v, w);
        edges[v].emplace_back(u, w);
    }
    vector<int> cost(N, -1);
    queue<int> que;
    que.push(0);
    cost[0] = 0;
    while (que.size())
    {
        int d = cost[que.front()];
        vector<pair<int, int>> edge = edges[que.front()];
        que.pop();
        rep(i, edge.size())
        {
            int n_node = edge[i].first;
            int n_cost = edge[i].second;
            if (cost[n_node] == -1)
            {
                cost[n_node] = d + n_cost;
                cost[n_node] %= 2;
                que.push(n_node);
            }
        }
    }
    rep(i, N)
    {
        cout << cost[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 12672
#include <iostream>
#include <algorithm>

using namespace std;

int main(void){
  int n,m;

  while(cin >> n >> m){
    if((n|m) == 0) break;
    int l[n],r[m],a[n+m+1],ret,s=0,t=0;
    for(int i=0;i<n;i++) cin >> l[i];
    for(int i=0;i<m;i++) cin >> r[i];
    for(int i=0;i<n+m;i++){
      if(s == n){
	a[i] = r[t++];
      }else if(t == m){
	a[i] = l[s++];
      }else{
	if(l[s] > r[t]){
	  a[i] = r[t++];
	}else{
	  a[i] = l[s++];
	}
      }
    }
    ret = a[0];
    for(int i=1;i<n+m;i++){
      ret = max(ret, a[i]-a[i-1]);
    }
    cout << ret << endl;
  }
}

Measured memory_bytes: 0
#include <iostream>
#include <string>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <vector>
#include <set>
#include <bitset>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using lint = long long;
using namespace std;

const int MOD = 1000000007;

int main() {
    int N;
    cin >> N;
    cout << N * N * N << endl;
    return 0;
}


Measured memory_bytes: 256