akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = 0;
		ArrayList<Integer> c = sosu(200);
		for(int i = 1; i < a+1; i++) {
			for(int j = 1; j < a+1; j++) {
				for(int k = 1; k < a+1;k++) {
					b += gcd(i,j,k,c);
				}
			}
		}
		System.out.println(b);
	}
	static int gcd(int a,int b,int c,ArrayList s) {
		int d = 1;
		for(int i = 1; i < s.size(); i++) {
			int ss = (int)s.get(i);
			if(ss != 0) {
				if(a%ss == 0 && b%ss == 0 && c%ss == 0) {
					while(true) {
						d *= ss;
						a /= ss;
						b /= ss;
						c /= ss;
						if(!(a%ss == 0 && b%ss == 0 && c%ss == 0)) break;
					}
				}
			}
		}
		return d;
	}
	static ArrayList sosu(int a) {
		int[] b = new int[a];
		for(int i = 0; i < a; i++) {
			b[i] = i+1;
		}
		for(int i = 1; i < a; i++) {
			if(b[i] != 0) {
				for(int j = 0;j < a; j++) {
					if(i != j && b[j] % b[i] == 0)b[j] =0;
				}
			}
		}
		ArrayList<Integer> al = new ArrayList<Integer>();
		for(int i = 0; i < a; i++) {
			if(b[i] != 0) {
				al.add(b[i]);
			}
		}
		return al;
	}
}


Measured memory_bytes: 36720
#include "bits/stdc++.h"

using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
	REP(i, v.size()) { if (i)os << " "; os << v[i]; }return os;
}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
	REP(i, v.size()) { if (i)os << endl; os << v[i]; }return os;
}

const ll INF = 1LL << 60;

int main() {
	vector<ll> v;
	vector<ll> a(3, 0);
	vector<ll> b(3, 0);

	REP(i, 9) {
		ll c;
		cin >> c;
		v.push_back(c);
	}

	REP(i, 3) {
		b[i] = v[i];
	}

	a[1] = v[3] - b[0];
	a[2] = v[6] - b[0];

	REP(i, 3) {
		REP(j, 3) {
			if (a[i] + b[j] != v[i * 3 + j]) {
				cout << "No" << endl;
				return 0;
			}
		}
	}

	cout << "Yes" << endl;
}

Measured memory_bytes: 256
import numpy as np

H, W = list(map(int, input().split()))
a = [[] for w in range(W)]

for h in range(H):
    i = input()
    if not '#' in i:
        continue

    for n in range(len(i)):
        a[n].append(i[n])

b = []
for x in a:
    if not '#' in x:
        continue
    b.append(x)

[print(''.join(x)) for x in np.array(b).T.tolist()]


Measured memory_bytes: 12500
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
using namespace std;
int main(){
  string s;
  cin>>s;
  s=s+s;
  string out;
  cin>>out;
  if(s.find(out)!=string::npos)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

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

int main(){
  ll n;
  cin>>n;
  ll a;
  for(ll i = 1;i * i <= n; i++){
    if(n % i == 0) a = i;
  }
  ll ans = a + n/a - 2;
  cout << ans << endl;
}


Measured memory_bytes: 384
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=500000004;
const double EPS=1e-6;
const double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
long long X[110000];
long long Y[110000];
long long Z[110000];
long long x[110000];
long long y[110000];
long long z[110000];
pair<long long,int>p[110000];
long long L[110000];
long long R[110000];
int main(){
	int a,b,c;
	scanf("%d%d%d",&a,&b,&c);
	int n=a+b+c;
	for(int i=0;i<n;i++)scanf("%lld%lld%lld",X+i,Y+i,Z+i);
	for(int i=0;i<n;i++)p[i]=make_pair(Y[i]-X[i],i);
	std::sort(p,p+n);
	for(int i=0;i<n;i++){
		x[i]=X[p[i].second];
		y[i]=Y[p[i].second];
		z[i]=Z[p[i].second];
	}
	long long ret=0;
	priority_queue<long long>in;
	long long cur=0;
	for(int i=0;i<n;i++){
		in.push(z[i]-x[i]);
		cur+=x[i];
		if(in.size()>a){
			long long tmp=in.top();
			in.pop();
			cur+=tmp;
		}
		L[i]=cur;
	}
	while(in.size())in.pop();
	cur=0;
	for(int i=n-1;i>=0;i--){
		in.push(z[i]-y[i]);
		cur+=y[i];
		if(in.size()>b){
			long long tmp=in.top();
			in.pop();
			cur+=tmp;
		}
		R[i]=cur;
	}
	for(int i=a;i<=n-b;i++){
		//printf("%lld %lld\n",L[i-1],R[i]);
		ret=max(ret,L[i-1]+R[i]);
	}
	printf("%lld\n",ret);
}

Measured memory_bytes: 9464
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <time.h>
#include <math.h>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <sstream>
#include <string>
#include <bitset>
using namespace std;
#define FOR(I,F,N) for(int I = F; I < (int)(N); I++)
#define T 3.305785
#define rep(i, n) FOR(i, 0, n)
#define FIN(V) cout<<V<<endl
#define pb push_back
#define INF (1 << 30)
typedef pair<int, int> P;
typedef long long ll;
typedef priority_queue<int> pq;
int StrToInt(string);
string IntToStr(int);
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};




int main(void){
    int a, b;
    cin >> a >> b;
    printf("%6lf\n", a*b/T);
   return 0;
}

Measured memory_bytes: 1192
# coding: utf-8
# Your code here!

n = int(input())

numList = []

for i in range(n):
    a = int(input())
    numList.append(a)


min = numList[0]
max = numList[1]
profit = max - min

for i in range(1,len(numList)):
    if min > numList[i]:
        min = numList[i]
        max = numList[i]
        continue
    if max <= numList[i]:
        max = numList[i]
        if profit < max- min:
            profit = max - min
    
print(profit)


Measured memory_bytes: 13588
# Treap
class Node():
    def __init__(self, k, p):
        self.k = k
        self.p = p
        self.left = None
        self.right = None

def rightRotate(t):
    s = t.left
    t.left = s.right
    s.right = t
    return s

def leftRotate(t):
    s = t.right
    t.right = s.left
    s.left = t
    return s

def insert(t, key, pri):
    if t == None:
        return Node(key, pri)
    if key == t.k:
        return t

    if key < t.k:
        t.left = insert(t.left, key, pri)
        if t.p < t.left.p:
            t = rightRotate(t)
    else:
        t.right = insert(t.right, key, pri)
        if t.p < t.right.p:
            t = leftRotate(t)
    return t

def erase(t, key):
    if t == None:
        return None

    if key == t.k:
        if t.left == None and t.right == None:
            return None
        elif t.left == None:
            t = leftRotate(t)
        elif t.right == None:
            t = rightRotate(t)
        else:
            if t.left.p > t.right.p:
                t = rightRotate(t)
            else:
                t = leftRotate(t)
        return erase(t, key)

    if key < t.k:
        t.left = erase(t.left, key)
    else:
        t.right = erase(t.right, key)
    return t

def inorder(t):
    if t == None:
        return 
    inorder(t.left)
    print(" " + str(t.k), end="")
    inorder(t.right)

def preorder(t):
    if t == None:
        return
    print(" " + str(t.k), end="")
    preorder(t.left)
    preorder(t.right)

def output(t):
    inorder(t)
    print()
    preorder(t)
    print()


t = None
data = []
dict = {}
m = int(input())
for i in range(m):
    data.append(list(input().split()))

for i in range(m):
    if data[i][0] == "insert":
        if (data[i][1] in dict) == False:
            t = insert(t, int(data[i][1]), int(data[i][2]))
            dict[data[i][1]] = True
    elif data[i][0] == "print":
        output(t)
    elif data[i][0] == "find":
        if (data[i][1] in dict) == True:
            print("yes")
        else:
            print("no")
    else:
        t = erase(t, int(data[i][1]))
        if (data[i][1] in dict) == True:
            del dict[data[i][1]]


Measured memory_bytes: 122280
#include <bits/stdc++.h>
#define SIZE(x) ((x).size())
#define PB push_back

using namespace std;

const int N = 100;

int n, m;

bool read() {
    if (!(cin >> n >> m)) {
        return false;
    }
    return true;
}

void solve() {
    if (n == 2 || m == 2) {
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
    }
}

int main(void) {
    while (read())
        solve();
    return 0;
}




Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String[] line = sc.nextLine().split("");
		sc.close();
		int cnt = 0;

		for(int i = 0; i< line.length; i++) {
			if(line[i].equals("1")) {
				cnt++;
			}
		}

		System.out.println(cnt);

	}

}


Measured memory_bytes: 23508
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_set>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<complex>
#include<tuple>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef long double D;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;


int main(){
    ll n,q;
    cin>>n>>q;
    vector<pair<pll,pll>> A(2*n);
    for(int i=0;i<n;i++){
        pair<pll,pll> I;
        cin>>I.F.F>>I.F.S>>I.S.F;
        I.S.S=i;
        I.F.F-=I.S.F;
        I.F.S-=I.S.F;
        A[i]={{I.F.F,1},{I.S.F,i}};
        A[i+n]={{I.F.S,-1},{I.S.F,i}};
    }
    sort(A.begin(),A.end());
    ll idx=0;
    priority_queue<pll,vector<pll>,greater<pll>> Q;
    vector<ll> D(q);
    for(auto &I:D){cin>>I;}
    vector<bool> used(n,false);
    for(int i=0;i<q;i++){
        while(idx<2*n && A[idx].F.F<=D[i]){
            if(A[idx].F.S==-1){
                used[A[idx].S.S]=true;
            }
            else{
                Q.push({A[idx].S});
            }
            idx++;
        }
        while(!Q.empty() && used[Q.top().S]){Q.pop();}
        if(Q.empty()){cout<<-1<<endl;}
        else{cout<<Q.top().F<<endl;}
    }
    
    
    
    return 0;
}


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

using namespace std;

long long inf=1000000007;

int main(){
	long long n;
	cin>>n;
	vector<long long> num(n+1,0);

	for(long long i=1;i+i<=n;i++){
		for(long long j=1;j*j<=n;j++){
			long long hoge=i*i+j*j+i*j;
			long long l=1,r=n;

			while(r-l>1){
				long long mid=(l+r)/2;
				if(hoge+i*mid+j*mid+mid*mid<=n){
					l=mid;
				}else{
					r=mid;
				}
			}

			if(l==1 && hoge+1+i+j>n) continue;

			for(long long k=1;k<=l;k++){
				num.at(hoge+i*k+j*k+k*k)++;
			}
		}
	}

	for(long long i=1;i<=n;i++) cout<<num.at(i)<<endl;

	return 0;
}


Measured memory_bytes: 3548
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>

#define INF 1e09

using std::cin;
using std::cout;
using std::endl;
using std::setprecision;
using std::fixed;
using std::pair;
using std::make_pair;
using std::min;
using std::max;
using std::string;
using std::vector;
using std::list;
using std::map;
using std::set; // insert erase find count
using std::queue;
using std::priority_queue;
using std::stack;

typedef vector<int> VI;
typedef vector<vector<int> > VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, pair<int, int> > PIII;

int main(void) {
    while (1) {
        int n;
        int m;
        cin >> n >> m;
        if (n == 0 && m == 0) {
            break;
        }
        VI vn(n);
        VI vm(m);
        for (int i = 0; i < n; i++) {
            cin >> vn[i];
        }
        for (int i = 0; i < m; i++) {
            cin >> vm[i];
        }

        VI listn;
        for (int i = 0; i < n; i++) {
            int temp = vn[i];
            listn.push_back(temp);
            for (int j = i + 1; j < n; j++) {
                temp += vn[j];
                listn.push_back(temp);
            }
        }
        VI listm;
        for (int i = 0; i < m; i++) {
            int temp = vm[i];
            listm.push_back(temp);
            for (int j = i + 1; j < m; j++) {
                temp += vm[j];
                listm.push_back(temp);
            }
        }

        sort(listn.begin(), listn.end());
        sort(listm.begin(), listm.end());

        int count = 0;
        int now_i = 0;
        int now_j = 0;
        int size_i = (int)listn.size();
        int size_j = (int)listm.size();

        while (1) {
            if (now_i == size_i || now_j == size_j) {
                break;
            }
            if (listn[now_i] < listm[now_j]) {
                while (listn[now_i] < listm[now_j] && now_i != size_i) {
                    now_i++;
                }
                continue;
            } else if (listn[now_i] > listm[now_j]) {
                while (listn[now_i] > listm[now_j] && now_j != size_j) {
                    now_j++;
                }
                continue;
            } else {
                int count_i = 0;
                int count_j = 0;
                int temp_i = listn[now_i];
                int temp_j = listm[now_j];
                while (listn[now_i] == temp_i && now_i != size_i) {
                    now_i++;
                    count_i++;
                }
                while (listm[now_j] == temp_j && now_j != size_j) {
                    now_j++;
                    count_j++;
                }
                count += (count_i * count_j);
            }
        }
        cout << count << endl;
    }

    return 0;
}

Measured memory_bytes: 19792
#include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
#define int long long
using namespace std;
typedef pair<int,int>P;
#define F first
#define S second

string s;
int  n;
int sum1[200009];
int sum2[200009];

signed main(){
    cin>>n>>s;
    r(i,n){
        if(s[i]=='#')sum1[i]=1;
        if(s[i]=='.')sum2[i]=1;
    }
    r(i,n-1)sum1[i+1]+=sum1[i];
    r(i,n-1)sum2[i+1]+=sum2[i];
    int ans=1e9;
    for(int i=0;i<n;i++){
        int sa=0;
        sa+=sum2[n-1]-sum2[i];

        if(i)sa+=sum1[i-1];
        ans=min(ans,sa);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3716
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//priority_queue<int,vector<int>, greater<int> > q2;



signed main(){
cin.tie(0);
ios::sync_with_stdio(false);

	int N;
	cin >> N;
	VI D(N), sum(N + 1, 0);;
	REP(i, N) {
		cin >> D[i];
		sum[i + 1] = sum[i] + D[i];
	}
	map<int, int>mp;
	int ans = 0;

	FOR(i,1, N + 1) {
		//cout << mp[sum[i]] << endl;
		if (sum[i] == 0) {
			ans = max(i, ans);
		}
		else if (mp[sum[i]] == 0) {
			mp[sum[i]] = i;
		}
		else {
			ans = max(ans, i - mp[sum[i]]);
		}
	}

	cout << ans << endl;


	return 0;
}




Measured memory_bytes: 18188
import java.util.*;
import java.io.*;
import java.lang.*;
public class Main{
public static long help(int[] arr,long[][] dp,int i, int j){
	if(i>j||j<=0||i>arr.length-1){return 0;}
	if(dp[i][j]!=0){return dp[i][j];}
	long x=arr[i]+Math.min(help(arr,dp,i+2,j),help(arr,dp,i+1,j-1));
	long y=arr[j]+Math.min(help(arr,dp,i+1,j-1),help(arr,dp,i,j-2));
	return dp[i][j]=Math.max(x,y);
}
public static void main(String[] args) throws FileNotFoundException, IOException{
       Scanner s=new Scanner(System.in);
       BufferedWriter out=new BufferedWriter(new OutputStreamWriter(System.out));
       int n=s.nextInt();
       long[][] dp=new long[n+1][n+1];
       int[] arr=new int[n+1];
       long sum=0;
       for(int i=1;i<=n;i++){arr[i]=s.nextInt();sum+=arr[i];}       
         out.write((2*help(arr,dp,1,n)-sum)+"\n");       
        out.flush();
  }
}


Measured memory_bytes: 129904
function main()
    n = parse(Int, readline())
    a = parse.(Int, split(readline()))
    if 0 in a
        println(0)
        return
    end
    ans = 1;
    pre = 1
    for i in a
        ans *= i
        if ans > 10^18 || ans < pre
            ans = -1
            break
        end
        pre = ans
    end

    println(ans)
end

main()


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

int main(){
  int a,b,c;
  cin >> a >> b >> c;
  if( a==b && a!=c)cout << "Yes" << endl;
  else if( b==c && b!=a)cout << "Yes" << endl;
  else if( a==c && a!=b)cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main(void){
	int n;
	int i;
	int cnt=0;
	int sum;
	cin>>n;
	for(i=1;i<=n;i+=2){
		sum=0;
		for(int j=1;j<=i;j++){
			if(i%j==0){
				sum++;
			}
		}
		if(sum==8){
			cnt++;
		}
	}
	cout<<cnt<<endl;
	return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"sort"
)

func main() {
	var n, m int
	fmt.Scan(&n, &m)

	x := make([]int, m)
	for i := 0; i < m; i++ {
		fmt.Scan(&x[i])
	}
	sort.Ints(x)

	diff := make([]int, m)
	for i := 1; i < m; i++ {
		diff[i] = x[i]-x[i-1]
	}
	sort.Ints(diff)

	var result int
	for i := 0; i < m - n +1; i++ {
		result += diff[i]
	}
	fmt.Println(result)
}

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

#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0, a1, a2, a3, a4, x, ...) x
#define dump_1(x1) cerr << #x1 << ": " << x1 << endl
#define dump_2(x1, x2) \
  cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << endl
#define dump_3(x1, x2, x3)                                                \
  cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
       << x3 << endl
#define dump_4(x1, x2, x3, x4)                                            \
  cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
       << x3 << ", " #x4 << ": " << x4 << endl
#define dump_5(x1, x2, x3, x4, x5)                                        \
  cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
       << x3 << ", " #x4 << ": " << x4 << ", " #x5 << ": " << x5 << endl
#define dump(...) \
  CHOOSE((__VA_ARGS__, dump_5, dump_4, dump_3, dump_2, dump_1, ~))(__VA_ARGS__)
#define check(s) cerr << s << endl

#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define unique(v) v.erase(unique(v.begin(), v.end()), v.end());
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

using namespace std;

using ll = long long;

vector<int> dx = {0, 1, 0, -1};
vector<int> dy = {1, 0, -1, 0};

const ll LINF = 2e18;
const int INF = 1e9;

void solve(ll N) {
  ll sum = 0;
  int c = 1;
  while (sum < N) {
    sum += c;
    c++;
  }

  FOR(i, 1, c) {
    if (sum - N == i) continue;
    cout << i << endl;
  }
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  ll N;
  scanf("%lld", &N);
  solve(N);
  return 0;
}


Measured memory_bytes: 3712
#include <stdio.h>

int main(){
  int n, i, num[2], result[2] ={0,0};

  while(scanf("%d", &n)){
    if(n == 0) break;

    result[0] = 0;
    result[1] =	0;
    for(i = 0; i < n;i++){
      scanf("%d %d", &num[0], &num[1]);
      if(num[0] > num[1]) result[0] += num[0] + num[1];
      else if(num[0] < num[1]) result[1] += num[0] + num[1];
      else result[0] += num[0], result[1] += num[1];
    }
    printf("%d %d\n", result[0], result[1]);
  }

  return 0;
}

Measured memory_bytes: 600
from itertools import groupby
from numpy import cumsum


N, K = map(int, input().split())
S = input().strip()

if len(set(S)) == 1:
    print(N)
    exit()

G = []
for k, v in groupby(S):
    G.append(len(list(v)))
if S[0] == '0':
    G.insert(0, 0)
if S[-1] == '0':
    G.append(0)

cum = [0]
cum.extend(list(cumsum(G)))
cum.append(0)

ans = 0
gc = len(G)
w = min(gc, 3+(K-1)*2)
for i in range(0, gc-w+2, 2):
    ans = max(ans, cum[i+w]-cum[i])
print(ans)


Measured memory_bytes: 17876
#include <iostream>
#include <stdio.h>
#define _USE_MATH_DEFINES
#include <math.h>

using namespace std;

void solve()
{
	int d, t;
	double x = 0, y = 0;
	double angle = 90;
	while(true)
	{
		scanf("%d,%d", &d, &t);
		if(d == 0 && t == 0)
		{
			break;
		}
		x += d * cos(angle / 180 * M_PI);
		y += d * sin(angle / 180 * M_PI);
		angle -= t;
	}
	cout << (int)x << endl;	
	cout << (int)y << endl;
}

int main()
{
	solve();
	return(0);
}

Measured memory_bytes: 1212
#include <bits/stdc++.h>
typedef long long int lli;
using namespace std;
#define MOD 1000000007
#define MAX 5000005
#define endl "\n"
lli arr[MAX];
lli n;
map <tuple <lli,lli,lli>, bool> visited;
map <lli, pair<lli,lli> >  dp;
lli ans = LONG_LONG_MIN;
long long binpow(long long a, long long b) {
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}
void f(lli x, lli money, lli stock){
    if(x == n){
        ans = max(ans,money);
        return;
    }
    dp[x].first = max(dp[x].first,money);
    dp[x].second = max(dp[x].second,stock);
    visited[{x,money,stock}] = true;
    if(!visited[{x+1,money,stock}]){
        if(dp[x+1].first <= money || dp[x+1].second <=stock)
            f(x+1, money, stock);
    }
    lli purchasem = money%arr[x];
    lli purchasestock = stock + money/arr[x];
    if(!visited[{x+1,purchasem,purchasestock}]){
        if(dp[x+1].second <=purchasestock)
            f(x+1, purchasem, purchasestock);
    }
    lli sellm = money + stock*arr[x];
   // cout<<sellm<<endl;
    if(!visited[{x+1,sellm,0}]){
        if(dp[x+1].first < sellm)
            f(x+1, sellm,0);
    }
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);    
 /*   freopen("biginput.txt", "r", stdin);
    freopen("output.txt", "w", stdout);*/
    lli t;
    t = 1;
    lli pa = 0;
    while(t--){
       dp[0] = {1000,0};
       cin>>n;
       for(lli i = 0; i<n; i++){
           cin>>arr[i];
       }
       f(0,1000,0);
       cout<<ans<<endl;
    }
}


Measured memory_bytes: 7436
#include<stdio.h>
int main()
{
    int num,i,j,k,big=-1,avg,max,total=0,count[50];
    scanf("%d",&max);
     for(i=1;i<=max;i++)
    {
        if(i<=9)
            total++;
        else if(i>=100 && i<=999)
            total++;

        else if(i>=10000 && i<=99999)
            total++;
    }
    printf("%d",total);
    return 0;
}


Measured memory_bytes: 1724
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N = int(readline())
m = map(int,read().split())
UV = zip(m,m)

if N == 1:
    print(0)
    exit()

graph = [[] for _ in range(N+1)]
for u,v in UV:
    graph[u].append(v)
    graph[v].append(u)

deg = [len(x) for x in graph]

root = 1
parent = [0] * (N+1)
order = []
stack = [root]
while stack:
    x = stack.pop()
    order.append(x)
    for y in graph[x]:
        if y == parent[x]:
            continue
        parent[y] = x
        stack.append(y)

parent,order

# dp1：その頂点に上から辿り着いてきたとする。残り回数期待値
dp1 = [0.0]*(N+1)
for v in order[::-1]:
    d = deg[v]
    if v != root and d == 1:
        continue
    x = sum(dp1[c] for c in graph[v])
    if v == root:
        dp1[v] = x/deg[v] + 1
    else:
        dp1[v] = x/(deg[v]-1) + 1

# dp2：その頂点から上に進んだとする。残り回数期待値。上移動を含まない。
dp2 = [0.0] * (N+1)
for v in order:
    d = deg[v]
    n_child = d if v == root else d-1
    S = dp1[v] * n_child # 子に進んだ場合の値の総和
    if v != root:
        S += dp2[v]+1# あらゆる移動の値の総和
    for c in graph[v]:
        if c == parent[v]:
            continue
        if d == 1:
            dp2[c] = 0
        else:
            dp2[c] = (S-dp1[c]-1) / (d-1)

answer = []
for v in range(1,N+1):
    d = deg[v]
    n_child = d if v == root else d-1
    S = dp1[v] * n_child
    if v != root:
        S += dp2[v]+1# あらゆる移動の値の総和
    answer.append(S/d)

print('\n'.join(map(str,answer)))


Measured memory_bytes: 126812
import java.util.*;
import java.util.stream.Collectors;

public class Main {
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int minuscount = 0;
		List<Integer> values = new ArrayList<Integer>();
		for(int tmp = 0; tmp < n; tmp++) {
			int v = sc.nextInt();
			if(v < 0) {
				minuscount++;
			}
			values.add(Math.abs(v));
		}
		long result = 0;
		if((n % 2 == 1) && (minuscount % 2 == 0)) {
			for(Integer value : values) {
				result += value;
			}
		}else if((n % 2 == 1) && (minuscount % 2 == 1)) {
			int min = values.stream().min(Comparator.comparing(Integer::valueOf)).orElse(0);
			values.remove(values.indexOf(min));
			for(Integer value : values) {
				result += value;
			}
			result -= min;
		}else if((n % 2 == 0) && (minuscount % 2 == 0)) {
			for(Integer value : values) {
				result += value;
			}
		}else {
			int min = values.stream().min(Comparator.comparing(Integer::valueOf)).orElse(0);
			values.remove(values.indexOf(min));
			for(Integer value : values) {
				result += value;
			}
			result -= min;
		}
		System.out.println(result);	
	}
}

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

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

	int n,m; cin >> n >> m;
	int a[m];
	for(int i =0; i<m;i++) cin >> a[i];
	int sum = accumulate(a,a+m,0);
	cout << max(n-sum,-1);	
	
	

}


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

#define all(c) ((c).begin()), ((c).end())
#define dump(c) cerr << "> " << #c << " = " << (c) << endl;
#define iter(c) __typeof((c).begin())
#define tr(i, c) for (iter(c) i = (c).begin(); i != (c).end(); i++)
#define REP(i, a, b) for (int i = a; i < (int)(b); i++)
#define rep(i, n) REP(i, 0, n)
#define mp make_pair
#define fst first
#define snd second
#define pb push_back
#define debug( fmt, ... ) \
        fprintf( stderr, \
                  fmt "\n", \
                  ##__VA_ARGS__ \
        )

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 1 << 29;
const double EPS = 1e-10;

double zero(double d) {
    return d < EPS ? 0.0 : d;
}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
    return os << '(' << p.first << ',' << p.second << ')';
}

template<typename T>
ostream &operator<<(ostream &os, const vector<T> &a) {
    os << '[';
    rep(i, a.size()) os << (i ? " " : "") << a[i];
    return os << ']';
}

string toString(int i) {
    stringstream ss;
    ss << i;
    return ss.str();
}

const int MOD = 1000000007;
// a^k
ll fpow(ll a, ll k, int M) {
    ll res = 1ll;
    ll x = a;
    while (k != 0) {
        if ((k & 1) == 1)
            res = (res * x) % M;
        x = (x * x) % M;
        k >>= 1;
    }
    return res;
}

struct prepare {
	prepare() {
	    cout.setf(ios::fixed, ios::floatfield);
	    cout.precision(8);
	    ios_base::sync_with_stdio(false);
	}
} _prepare;

int main() {
	ll N, X;
	cin >> N >> X;

    ll f1 = X;
    ll f2 = N - f1;

    ll ans = 0;

    while(true) {
        if(f2 == 0)
            break;

        ll s = f1 / f2;
        ll rem = f1 % f2;
        ans += f2 * s * 3;

        f1 = f2;
        f2 = rem;
    }

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

Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author toshibablack
 */

#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <fstream>
#include <functional>
#include <iostream>
#include <iomanip>
#include <iterator>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

#define ll long long int
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define REP(i, n) for(int i=0;i<n;++i)
#define FOREACH(x, a) for(auto& (x) : (a))
#define ALL(a) (a).begin(),(a).end()
#define COUT(x) out << (x) << endl;

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

using namespace std;


class DGatheringChildren {
public:
    string S;
    vector<int> rl;
    int ans[100000]{0};

    void solve(std::istream& in, std::ostream& out) {
        in >> S;
        int N = S.length();
        FOR(i, 0, N-1) {
            if (S[i] == 'R' && S[i+1] == 'L') rl.push_back(i);
        }
        FOREACH(b, rl) {
            int left = 0; int right = N-1;
            for (int i = b; i >= 0; --i) if (S[i] == 'L') { left = i+1; break; }
            for (int i = b+1; i < N; ++i) if (S[i] == 'R') { right = i-1; break; }
            ans[b] += (b - left + 2) / 2;
            ans[b+1] += (b - left + 1) / 2;
            ans[b] += (right- b) / 2;
            ans[b+1] += (right - b + 1) / 2;
        }
        REP(i, N) {
            if (i != N-1) out << ans[i] << " ";
            else out << ans[i] << endl;
        }
    }
};


int main() {
    DGatheringChildren solver;
    std::istream& in(std::cin);
    std::ostream& out(std::cout);
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 1280
#include<iostream>
#include<vector>
#include<algorithm>
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N,min=999,ans;
  cin>>N;
  vector<int> Min(N);
  for(int i=0;i<N;i++){
    cin>>Min[i];
  }
  for(int j=0;j<N;j++){
    int A=0,B=0;
    for(int i=0;i<=j;i++){
      A+=Min[i];
    }
    for(int l=j+1;l<N;l++){
      B+=Min[l];
    }
    if(A<=B){
      ans=B-A;
      if(ans<min){
        min=ans;
    }
    }
    if(B<=A){
      ans=A-B;
      if(ans<min){
        min=ans;
    }
    }
  }
  cout<<min<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<tuple>
#include<iomanip>
#include<map>
#define int long long
using namespace std;

signed main() {
	int N;
	cin >> N;
	vector<int> vec(N);
	for(int i = 0;i < N;i++) {
		cin >> vec.at(i);
	}
	int answer = vec.at(0);
	for(int i = 1;i < N;i++) {
		answer = __gcd(answer,vec.at(i));
	}
	cout << answer << endl;
}

Measured memory_bytes: 1024
s = int(input())

if s < 3:
    print(0)
    exit()
if s < 6:
    print(1)
    exit()

l = [0]*(s+1)
l[3] = 1
l[4] = 1
l[5] = 1
i = 6
sum = 1
while i <= s:
    sum += l[i-3]
    l[i] = sum
    i += 1

print(l[s]%1000000007)

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

int main()
{
  vector<int> N(3);
  for (int i = 0; i < 3; i++)
  {
    cin >> N[i];
  }
  sort(N.begin(), N.end());
  int r = 2 * N[2] - (N[1] + N[0]);
  if (r % 2 == 0)
  {
    cout << r / 2 << endl;
  }
  else
  {
    cout << (r + 3) / 2 << endl;
  }
}


Measured memory_bytes: 3612
from collections import deque

def solve():
    S = list(input())
    M = int(input())
    Q = [list(input().split()) for _ in range(M)]
    
    bef = deque([])
    s = deque(S)
    aft = deque([])
    c = 0
    
    for q in Q:
        if q[0] == '1':
            c += 1
        else:
            ad = q[2]
            if q[1] == '1':
                # 先頭
                if c % 2 == 0:
                    bef.appendleft(ad)
                else:
                    aft.append(ad)
            else:
                # 末尾
                if c % 2 == 0:
                    aft.append(ad)
                else:
                    bef.appendleft(ad)

    ans = ''.join(bef) + ''.join(s) + ''.join(aft)
    if c % 2 == 1:
        ans = ans[::-1]

    return ans

print(solve())

Measured memory_bytes: 119416
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <cassert>
#include <ctime>
#include <map>
#include <set>
using namespace std;
#define lowbit(x) (x&(-x))
#define max(x,y) (x>y?x:y)
#define min(x,y) (x<=y?x:y)
#define MAX 100000000000000000
#define MOD 1000000007
#define pi acos(-1.0)
#define ei exp(1)
#define PI 3.141592653589793238462
#define ios() ios::sync_with_stdio(false)
#define INF 1044266558
#define mem(a) (memset(a,0,sizeof(a)))
typedef long long ll;
int n,m;
int main()
{
	while(scanf("%d%d",&n,&m)!=EOF)
	{
		printf("%d\n",(n-1)*(m-1));
	}
	return 0;
}

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

const int INF = pow(2, 31) - 1;
#define ll long long
#define DEBUG(x) cout << "DEBUG>" << #x << ":" << x << endl;
#define REP(i,n) for(ll i=0;i<(n);i++)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}

int main() {
  int N;
  cin >> N;
  if(N == 0) {
    cout << "0" << endl;
    return 0;
  }
  string ans;
  while(N != 0) {
    if(N & 1) {
      ans += "1";
      N--;
      N /= -2;
    } else {
      ans += "0";
      N /= -2;
    }
  }
  reverse(ans.begin(), ans.end());
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
def calcs(x,y,ax,ay,bx,by) ((ax-x)*(by-y)-(bx-x)*(ay-y))/2.0 end
def inpf() a=gets.chomp.split(" ").map(&:to_f)end
def inps() a=gets.chomp.split(" ")end  
def copy(a) Marshal.load(Marshal.dump(a)) end
def kaizyo(n)(n < 2)? 1 : (2..n).inject(:*) end
def scount(a) b=na(a.max+1);a.each{|n|b[n]+=1};return b end
def na(n,d=0) Array.new(n,d)end
def na2(n,m,d=0) Array.new(n){Array.new(m,d)}end
def na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end
def bit(n) n.to_s(2).split("").map(&:to_i) end
def inp() a=gets.chomp.split(" ").map(&:to_i)end
def saiki(a,x,y)
  return if(x < 0)
  return if(y < 0)
  return if(y >= @h)
  return if(x >= @w)
  return if(a[y][x] == @bad)
  a[y][x] = @bad
  saiki(a,x+1,y)
  saiki(a,x,y+1)
  saiki(a,x-1,y)
  saiki(a,x,y-1)
  
  saiki(a,x+1,y+1)
  saiki(a,x-1,y+1)
  saiki(a,x-1,y-1)
  saiki(a,x+1,y-1)
end
while true
  n = inp[0]

  nt = []
  dr = []  
  break if n == 0
  n.times do |i|
    d = inps
    dn = d[0]
    dd = d[1..9].map(&:to_i)
    vi = dd[6]*dd[7]
    so = (vi*dd[8]-dd[0])/(dd[1..5].inject(:+)+dd[4..5].inject(:+)*(dd[8]-1)).to_f 
    nt.push([dn,so])
  end
  nt.sort! do |a,b|
    (b[1]<=>a[1]).nonzero? ||
      (a[0] <=> b[0])
  end
  n.times do |i|
    puts nt[i][0]
  end
  puts "#"
end
=begin

=end

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

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

	int cnt = 0;
	sort(c, c+n);
	for (int i = 0; i < n; i++) {
		if (c[i] != p[i]) {
			cnt++;
		}
	}

	string ans = "NO";
	if (cnt == 0 || cnt == 2) {
		ans = "YES";
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 256
def main():
    n, m = map(int,input().split())
    s = []
    k = []
    for i in range(m):
        tmp = list(map(int,input().split()))
        k.append(tmp.pop(0))
        s.append(tmp)
    p = list(map(int,input().split()))
    ans = 0

    f = True
    for i in range(2**n):
        tmp = [0] * n
        b = i
        keta = 0
        while b > 0:
            # print(b,bin(b))
            # print(bin(1&b))
            if bin(b & 1)==bin(1):
                tmp[keta] = 1
            b >>= 1
            keta += 1
        # print(tmp)
        for j, ss in enumerate(s):
            tmp_sum=0
            for l, sss in enumerate(ss):
                 if tmp[sss-1] == 1:
                    tmp_sum += 1
            if tmp_sum % 2 == p[j]:
                continue
            else:
                f = False
                break
        if f == True:
            ans += 1
        f = True
    print(ans)
if __name__ == '__main__':
    main()


Measured memory_bytes: 3188
N=int(input())
list1=[]
list2=[]
for i in range(N):
    s=int(input())
    list1.append(s)
    if s%10!=0:
        list2.append(s)
list1.sort()
list2.sort()

ans=sum(list1)
for j in range(len(list2)):
    if ans%10!=0:
        print(ans)
        exit()
    else:
        ans-=list2[j]
print(0)

Measured memory_bytes: 3060
from collections import deque
n = int(input())
graph = [[] for _ in range(n+1)]
for _ in range(n-1):
    u,v,w = map(int,input().split())
    graph[u].append((v,w))
    graph[v].append((u,w))
q = deque([1])
ans = [0] * (n+1)
parent = [0]*(n+1)
while q:
    x = q.popleft()
    for y,w in graph[x]:
        if y == parent[x]:
            continue
        parent[y] = x
        ans[y] = ans[x]^(w&1)
        q.append(y)
for i in range(1,n+1):
    print(ans[i])

Measured memory_bytes: 39912
import heapq as hp

n, m = map(int, input().split())
a = list(map(int, input().split()))

for i in range(n):
    a[i] = a[i] * (-1)
hp.heapify(a)

for _ in range(m):
    max_price = (-1) * hp.heappop(a)
    hp.heappush(a, (-1) * (max_price // 2))

print(-sum(a))

Measured memory_bytes: 20364
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;

string s;
int main()
{
    cin>>s;
    for(int i=0; i<s.size()-1; ++i)
        if(s[i]==s[i+1])
        {
            cout<<i+1<<" "<<i+2<<"\n";
            return 0;
        }
        else if(s[i]==s[i+2])
        {
            cout<<i+1<<" "<<i+3<<"\n";
            return 0;
        }
    cout<<"-1 -1\n";
    return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<math.h>
#include<set>
#include<algorithm>
#include<vector>
#include<iomanip>
using namespace std;

static long parseans(long j, long l)
{
    string k = "";
    long cur = 0;
    for (long long i = (long long) j; i <= l; ++i)
    {
        cur *= 10;
        cur += k[i] - '0';
    }
    return cur;
}

static long gcd(long a, long b)
{
    if (b == 0)
    {
        return a;
    } else
    {
        return gcd(b, a % b);
    }
}

static bool pri(long long k)
{
    if (k == 1) return false;
    for (long long i = 2; i * i <= k; i++)
    {
        
        if (k % i == 0) return false;
    }
    return true;
}



int main()
{
    int n;
    cin >> n;
    vector<int> s;
    s.resize(n);
    int sum = 0;
    for(int i = 0;i < n; i++)
    {
        cin >> s[i];
        sum += s[i];
    }
    sort(s.begin(), s.end());
    if(sum % 10)
    {
        cout << sum << "\n";
        return 0;
    }
    else
    {
        for(int i = 0; i < n; i++)
        {
            if( s[i] % 10)
            {
                cout << sum - s[i] << "\n";
                return 0;

            }
        }
     }
    cout << "0" << "\n";
    return 0;
    }

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;

typedef long long ll;
typedef vector <bool> v_bool;
typedef vector <ll> v_ll;
typedef vector <vector <ll> > vv_ll;
typedef vector < pair <ll,ll> > vp_ll;
typedef pair <ll,ll> p_ll;

bool TEST=false;
ll MOD = 1000000007;

void show(){if (TEST){cout << endl;}}
void show(string x){if (TEST){cout << x;}}
void show(string x,bool enter){
  if (TEST){if (enter) cout << "<#> " << x << endl;else cout << x;}
}
void show(ll x){if (TEST){cout << x;}}
void show(ll x,bool enter){
  if (TEST){if (enter) cout << "<#> " << x << endl;else cout << x;}
}
void show(p_ll p){
  if (TEST){cout << "{ ";show(p.first);cout << " ";show(p.second);cout << " }";}
}
void show(v_ll v){
  if (TEST){
    cout << "<begin> ";
    for (ll i=0;i<v.size();i++){show(v[i]); cout << " ";}cout <<"<end>"<< endl;
}}
void show(vv_ll v){
  if (TEST){
    cout << "//////////" << endl;
    for (ll i=0;i<v.size();i++){
      show(v[i]); cout << endl;
}}}
void show(vp_ll v){
  if (TEST){
    cout << "//////////" << endl;
    for (ll i=0;i<v.size();i++){
      show(v[i]); cout << endl;
}}}

ll mod(ll x){
  ll n=MOD;
  ll ret=x%n;
  if (ret<0)ret+=n;
  return ret;
}
void mod_self(ll &x){
  x=mod(x);
}
ll mod_inv(ll x){
  ll n=MOD;
  ll y = x,z = n-2, ret=1;
  y=mod(y);
  while (z>0){
    if(z%2==1) ret=mod(ret*y);
    y=mod(y*y);
    z/=2;
  }
  return ret;
}
ll mod_pow(ll x,ll a){
  ll y = x,z = a,ret=1;
  y=mod(y);
  if (z<0)z=-z;
  while (z>0){
    if(z%2==1) ret=mod(ret*y);
    y=mod(y*y);
    z/=2;
  }
  if (a<0) ret=mod_inv(ret);
  return ret;
}
v_ll mod_nck(ll n){
  v_ll nck(n+1,0);
  nck[0]=1;
  for (ll i=1;i<=n;i++){
    nck[i]=mod(nck[i-1]*(n+1-i));
    nck[i]=mod(nck[i]*mod_inv(i));
  }
  return nck;
}
v_ll mod_factorial(ll n){
  v_ll fct(n+1,0);
  fct[0]=1;
  for (ll i=1;i<=n;i++){
    fct[i]=mod(fct[i-1]*i);
  }
  return fct;
}

ll N;
v_ll A;
int main(){
  cin >> N;
  A.assign(N+10,0);
  for (ll i=1;i<=N;i++){
    cin >> A[i];
  }
  for (ll i=N-1;i>=1;i--){
    if (A[i]>A[i+1])A[i]--;
    if (A[i]>A[i+1]){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 1152
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static int def = 10000;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		int x = sc.nextInt();
		int y = sc.nextInt();
		List<Integer> listx = new ArrayList<>();
		List<Integer> listy = new ArrayList<>();
		boolean turn = false;
		int step = 0;
		for(int i = 0; i < s.length(); i++) {
			if(s.charAt(i) == 'F') {
				step++;
			} else {
				if(turn) {
					listy.add(step);
				} else {
					listx.add(step);
				}
				step = 0;
				turn = !turn;
			}
		}
		if(turn) {
			listy.add(step);
		} else {
			listx.add(step);
		}
		boolean[] ansx = new boolean[2 * def];
		boolean[] ansy = new boolean[2 * def];
		for(int i = 0; i < 2 * def; i++) {
			ansx[i] = false;
			ansy[i] = false;
		}
		ansx[listx.get(0) + def] = true;
		listx.remove(0);
		ansy[def] = true;
		for(int i = 0; i < listx.size(); i++) {
			int value = listx.get(i);
			boolean[] tmp = new boolean[2 * def];
			for(int j = 0; j < 2 * def; j++) {
				tmp[j] = false;
			}
			for(int j = 0; j < 2 * def; j++) {
				if(ansx[j]) {
					tmp[j + value] = true;
					tmp[j - value] = true;
				}
			}
			for(int j = 0; j < 2 * def; j++) {
				ansx[j] = tmp[j];
			}
		}
		for(int i = 0; i < listy.size(); i++) {
			int value = listy.get(i);
			boolean[] tmp = new boolean[2 * def];
			for(int j = 0; j < 2 * def; j++) {
				tmp[j] = false;
			}
			for(int j = 0; j < 2 * def; j++) {
				if(ansy[j]) {
					tmp[j + value] = true;
					tmp[j - value] = true;
				}
			}
			for(int j = 0; j < 2 * def; j++) {
				ansy[j] = tmp[j];
			}
		}
		if(ansx[x + def] && ansy[y + def]) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}

}


Measured memory_bytes: 61736
def divisors(n):
    i = 1
    table = set()
    while i * i <= n:
        if not n % i:
            table.add(i)
            table.add(n//i)
        i += 1
    return table
A, B, K = map(int, input().split())
res = divisors(A) & divisors(B)
res = list(res)
res.sort()
print(res[-K])

Measured memory_bytes: 61776
#include<iostream>
#include<algorithm>
#include<string>
#include<sstream>
using namespace std;
int main() {
  int n;
  stringstream ss;
  cin >> n;
  for(int i=0;i<=n/4;i++){
    if((n-4*i)%7==0) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		Integer length = s.nextInt();
		Integer[] seq = new Integer[length];
		for(int i = 0; i < length; i++){
			seq[i] = s.nextInt();
		}
		Integer count = 0;
		for(int i = 0; i < length; i++){
			for(int j = length - 1; j > 0; j--){
				if(seq[j] < seq[j-1]){
					Integer bkp = seq[j-1];
					seq[j-1] = seq[j];
					seq[j] = bkp;
					count++;
				}
			}
		}
		
		for(int i = 0; i < length; i++){
			if(i == length - 1){
				System.out.print(seq[i] + "\n");
			}
			else{
				System.out.print(seq[i] + " ");
			}
		}
		System.out.println(count);
	}

}

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

using namespace std;
using ll = long long;
using Edge = pair<int, int>;
using Graph = vector<vector<Edge>>;

const int limit = 100010;

Graph G(limit);
vector<ll> H(limit);

void dfs(int v, int p, ll d) {
  H[v] = d;
  for (auto e : G[v]) {
    if (e.first == p) continue;
    dfs(e.first, v, d + e.second);
  }
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  cin >> N;
  for (int i = 0; i < N - 1; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    a--, b--;
    G[a].push_back(Edge(b, c));
    G[b].push_back(Edge(a, c));
  }
  int Q, K;
  cin >> Q >> K;
  dfs(K - 1, -1, 0);
  for (int i = 0; i < Q; i++) {
    int x, y;
    cin >> x >> y;
    x--, y--;
    cout << H[x] + H[y] << '\n';
  }
  return 0;
}


Measured memory_bytes: 12800