akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<deque>
#include<cmath>
#include<map>
#include<cstring>

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LLINF = 1LL<<60;
#define P pair<int, int>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define print(x) cout << (x) << endl

/*-- template --*/
const int MAX_N = 1e5 + 1;

vector<vector<int>>G(MAX_N);
int main() {
    int N, M; cin >> N >> M;
    rep(i, M) {
        int u, v; cin >> u >> v;
        --u, --v;
        G[u].pb(v);
    }
    int S, T; cin >> S >> T;
    --S, --T;
    vector<vector<int>> dis(MAX_N, vector<int>(3, INF));
    queue<P>Q;
    Q.push(mp(S, 0));
    dis[S][0] = 0;
    while(!Q.empty()) {
        P q = Q.front();Q.pop();
        for(int next : G[q.first]) {
            if(dis[next][(q.second + 1)%3] == INF) {
                Q.push(mp(next, (q.second + 1)%3));
            }
            dis[next][(q.second + 1)%3] = min(dis[q.first][q.second] + 1, dis[next][(q.second + 1)%3]);
        }
    }
    if(dis[T][0] == INF)cout << -1 << endl;
    else cout << dis[T][0] / 3 << endl;
}


Measured memory_bytes: 11136
//Trying to code! @skylags
//Codeforces Round #650 (Div. 3)
#include <bits/stdc++.h>
#define pb push_back
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define F first
#define S second
#define ALL(a) (a).begin(),(a).end()
#define SKY ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define lp(i,start,end) for(int i=start;i<end;i++)
#define MAX 100005
using namespace std;
typedef long long int int64;
const int N=1e5+5;

int32_t main()
{
    SKY;
    int64 a,b,c,d,e;
    cin>>a>>b>>c>>d>>e;
    cout<<15-(a+b+c+d+e)<<"\n";
    return 0;
}


Measured memory_bytes: 3640
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    vint n(3);
    REP(i,3) cin >> n[i];
    sort(ALL(n));
    if(n[0]==5&&n[1]==5&&n[2]==7){
        puts("YES");
    }else{
        puts("NO");
    }

    return 0;
}

Measured memory_bytes: 256
from collections import Counter
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


INF = float('inf')


n = I()
a = LI()
a = sorted(a)[::-1]
counter = Counter(a).items()
hen4 = [elem[0] for elem in counter if elem[1] >= 4]
hen2 = [elem[0] for elem in counter if elem[1] >= 2]
if len(hen4) == 0 and len(hen2) == 0:
    print(0)
    sys.exit()

if len(hen4) > 0:
    seihoukei = hen4[0] ** 2
    if len(hen2) >= 2:
        chouhoukei = hen2[0] * hen2[1]
        ans = max(seihoukei, chouhoukei)
    else:
        ans = seihoukei
    print(ans)

else:
    print(hen2[0] * hen2[1])


Measured memory_bytes: 22640
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner as = new Scanner(System.in);
		int n = Integer.parseInt(as.next());
		long x = Integer.parseInt(as.next());
		long a[] = new long[n];
		for(int i=0;i<n;i++){
			a[i] = Integer.parseInt(as.next());
		}
		long l=0;
		long c;
		for(int i=0;i<n-1;i++){
			c=a[i]+a[i+1];
			if(c>x){
				a[i+1]-=c-x;
				l+=c-x;
				if(a[i+1]<0){
					a[i]+=a[i+1];
					a[i+1]=0;
				}
			}
		}
		System.out.println(l);
	}
}

Measured memory_bytes: 32564
x,y=input().split()
lis=["A","B","C","D","E","F"]
for i in range(6):
    if x==lis[i]:x=i+10
    if y==lis[i]:y=i+10
if x<y:print("<")
elif x>y:print(">")
elif x==y:print("=")

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define mod 1000000007
//A 1
//G 2
//C 3
//T 4
int n,ans;
map<pair<pair<int,int>,pair<int,int> >,int> mem;
int dfs(int x,int a,int b,int c)
{
	if(x>=n)
		return 1;
	if(mem[make_pair(make_pair(x,a),make_pair(b,c))])
		return mem[make_pair(make_pair(x,a),make_pair(b,c))];
	int res=0;
	for(int l=1;l<=4;l++)
	{
		if(l==3&&(b==1&&c==2||a==1&&b==2||a==1&&c==2||b==2&&c==1)) continue;
		if(l==2&&b==1&&c==3) continue;
		res+=dfs(x+1,b,c,l);
		res%=mod;
	}
	mem[make_pair(make_pair(x,a),make_pair(b,c))]=res;
	return res;
}
signed main()
{
	cin>>n;
	if(n==3)
	{
		cout<<61<<endl;
		return 0;
	}
	for(int i=1;i<=4;i++)
		for(int j=1;j<=4;j++)
			for(int k=1;k<=4;k++)
			{
				if(i==1&&j==2&&k==3||i==2&&j==1&&k==3||i==1&&j==3&&k==2) continue;
				ans+=dfs(3,i,j,k);
				ans%=mod;
			}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 768
import math
import copy
from operator import mul
from functools import reduce
from collections import defaultdict
from collections import Counter
from collections import deque
# 直積 A={a, b, c}, B={d, e}:のとき，A×B={(a,d),(a,e),(b,d),(b,e),(c,d),(c,e)}: product(A, B)
from itertools import product
# 階乗 P!: permutations(seq), 順列 {}_len(seq) P_n: permutations(seq, n)
from itertools import permutations
# 組み合わせ {}_len(seq) C_n: combinations(seq, n)
from itertools import combinations
# 一次元累積和
from itertools import accumulate
from bisect import bisect_left, bisect_right

import re
# import numpy as np
# from scipy.misc import comb

# 再帰がやばいとき
# import sys
# sys.setrecursionlimit(10**9)

def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W

# 四方向: 右, 下, 左, 上
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]
 
def i_inpl(): return int(input())
def l_inpl(): return list(map(int, input().split()))
def line_inpl(x): return [i_inpl() for _ in range(x)]

INF = int(1e50)
MOD = int(1e9)+7 # 10^9 + 7

# field[H][W]
def create_grid(H, W, value = 0):
    return [[ value for _ in range(W)] for _ in range(H)]

########

def main():
    # A, B, C =l_inpl()
    # print(max(C-(A-B), 0))
    N = i_inpl()
    ans = 0
    for i in range(1, N+1):
        if len(str(i)) % 2 == 1:
            ans += 1
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 39920
#include <iostream>
#include <vector>
#include <queue>
#define ERA_MAX 1000000
#define ROO_MAX 316
using namespace std;

bool Eratos[ERA_MAX];

int M(int N, int P)
{
	priority_queue<int> pq;
	vector<int> vec(P);
	for (int i = 0, n = N + 1; i < P; n++) {
		if (Eratos[n]) {
			vec[i] = n;
			i++;
		}
	}
	for (int i = 0; i < P; i++) {
		for (int j = i; j < P; j++) {
			pq.push(-(vec[i] + vec[j]));
		}
	}
	for (int i = 0; i < P - 1; i++)
		pq.pop();
	return -pq.top();
}

int main()
{
	int N, P;
	Eratos[0] = Eratos[1] = false;
	for (int i = 2; i < ERA_MAX; i++) {
		Eratos[i] = true;
	}
	for (int i = 2; i < ROO_MAX; i++) {
		for (int j = i * 2; j < ERA_MAX; j += i) {
			Eratos[j] = false;
		}
	}
	while (cin >> N >> P, N != -1 || P != -1) {
		cout << M(N, P) << endl;
	}
	return 0;
}

Measured memory_bytes: 2252
#include <bits/stdc++.h>
#define mod 1000000007
using namespace std;
const int N=305;
int n,m,mn[N][4],mx[N][4],f[N][N][N],ans;
int check(int a, int b, int c)
{
    if(mn[a][1]<=mx[a][1]) if(mn[a][1]<b+1) return 0;
    if(mn[a][2]<=mx[a][2]) if(mn[a][2]<c+1||b<mx[a][2]) return 0;
    if(mn[a][3]<=mx[a][3]) if(c<mx[a][3]) return 0;
    return 1;
}
int main()
{
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++) for(int j=1;j<=3;j++) mn[i][j]=n+1;
    for(int i=1;i<=m;i++)
    {
        int l,r,x; scanf("%d%d%d",&l,&r,&x);
        mn[r][x]=min(mn[r][x],l);
        mx[r][x]=max(mx[r][x],l);
    }
    f[0][0][0]=1;
    for(int i=0;i<n;i++) for(int j=0;j<=i;j++) for(int k=0;k<=j;k++)
    {
        if(check(i+1,j,k)) (f[i+1][j][k]+=f[i][j][k])%=mod;
        if(check(i+1,i,k)) (f[i+1][i][k]+=f[i][j][k])%=mod;
        if(check(i+1,i,j)) (f[i+1][i][j]+=f[i][j][k])%=mod;
    }
    for (int j=0;j<=n;j++)
        for (int k=0;k<=j;k++)
            (ans+=f[n][j][k])%=mod;
    cout << ans;
}

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


#define ll long long
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(arr) arr.begin(),arr.end()
#define INF 2000000000
#define MOD 1000000007
#define vi vector<int>
#define ii pair<int,int>
#define pb push_back
#define mp make_pair
#define um unordered_map
#define us unordered_set
#define ff first
#define ss second
#define FOR(i,n,m) for(int i = (n); i < (m); i++)
#define REP(i,n) FOR(i,0,n)



using namespace std; 
void solve(); 
int main() 
{ 
	ios_base::sync_with_stdio(false); 
	cin.tie(NULL); 
/*
#ifndef ONLINE_JUDGE 
	freopen("input.txt", "r", stdin); 
	freopen("error.txt", "w", stderr); 
	freopen("output.txt", "w", stdout); 
#endif 
*/

	int n;
	cin>>n;
	ll ans = 0l;
	for(int i=1;i<=n;i++){
		if(i%3 != 0 && i%5!= 0){
			ans = ans + i;
			}
		}
	cout<<ans<<"\n";

	cerr << "time taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << endl; 
	return 0; 
} 
void solve() 
{ 
} 


Measured memory_bytes: 3784
#include<bits/stdc++.h>
typedef long long ll;
#define REP(i,n) for(int i = 0;i < (n);i++)
#define rep(i,m,n) for(int i = (m);i < (n);i++)
#define P pair<int,int>
#define pb push_back
#define mk make_pair
using namespace std;
#define Vec(a) vector <int> a
#define F first
#define S second
const int INF = 1 << 20;
const int MOD = 1e9+7;


struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};


int main(){
    int h,w;
    cin >> h >> w;
    ll x[h+10][w+10];
    string s[h];
    REP(i,h){
        s[i] = "";
        cin >> s[i];
        REP(j,w){
            x[i][j] = 0;
        }
    }
    UnionFind tree(161100);
    REP(i,h){
        REP(j,w-1){
            if(s[i][j] == '#'){
                if(s[i][j+1] == '.' && !tree.same((i*w+j), ((i)*w+j+1))){
                    tree.unite((i*w+j), ((i)*w+j+1));
                }
            }else{
                if(s[i][j+1] == '#' && !tree.same((i*w+j), ((i)*w+j+1))){
                    tree.unite((i*w+j), ((i)*w+j+1));
                }
            }
        }
    }
    REP(i,h-1){
        REP(j,w){
            if(s[i][j] == '#'){
                if(s[i+1][j] == '.' && !tree.same((i*w+j), ((i+1)*w+j))){
                    tree.unite((i*w+j), ((i+1)*w+j) );
                }
            }else{
                if(s[i+1][j] == '#' && !tree.same((i*w+j), ((i+1)*w+j) )){
                    tree.unite((i*w+j), ((i+1)*w+j) );
                }
            }
        }
    }
    
    REP(i,h*w){
        tree.root(i);
    }
    ll res = 0;
    ll y[161100] = {},z[161100] = {};
    REP(i,h){
        REP(j,w){
            if(s[i][j] == '#'){
                y[tree.root(i*w+j)]++;
            }else{
                z[tree.root(i*w+j)]++;
            }
        }
    }
    REP(i,161100){
        res+= y[i]*z[i];
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 4864
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int d = sc.nextInt();
        int s = Math.max(a, c);
        int e = Math.min(b, d);
        if (e - s >= 0)
            System.out.println(e - s);
        else
            System.out.println(0);
    }
}


Measured memory_bytes: 22740
import sys
from collections import defaultdict
readline = sys.stdin.buffer.readline
geta = lambda fn: map(fn, readline().split())
gete = lambda fn: fn(readline())

# sys.setrecursionlimit(10**5)

def main():
    N = gete(int) 
    p = list(geta(int))
    q = sorted(p)

    cnt = 0
    for pi, qi in zip(p,q):
        if pi != qi:
            cnt += 1
    
    if cnt <= 2:
        print('YES')
    else:
        print('NO')
	
if __name__ == "__main__":
    main()

Measured memory_bytes: 38256
#include <bits/stdc++.h>
using namespace std;
const double EPS=1e-10;
typedef complex<double> P;
namespace std {
  bool operator < (const P& a, const P& b) {
    return real(a)!=real(b)?real(a)<real(b):imag(a)<imag(b);
  }
}
double cross(const P& a, const P& b) {return imag(conj(a)*b);}
double dot(const P& a, const P& b) {return real(conj(a)*b);}

int ccw(P a, P b, P c) {
  b-=a;c-=a;
  if(cross(b,c)>EPS)return +1;
  if(cross(b,c)<-EPS)return -1;
  if(dot(b,c)<-EPS)return +2;
  if(norm(b)<norm(c))return -2;
  return 0;
}

vector<P> convex_hull(vector<P> p) {
  int n=p.size(),k=0;
  sort(p.begin(),p.end());
  vector<P> q(2*n);
  for(int i=0;i<n;q[k++]=p[i++])
    while(k>=2&&ccw(q[k-2],q[k-1],p[i])<=0) --k;
  for(int i=n-2,t=k+1;i>=0;q[k++]=p[i--])
    while(k>=t&&ccw(q[k-2],q[k-1],p[i])<=0) --k;
  q.resize(k-1);
  return q;
}

double area(vector<P> p) {
  double a=0;
  for(int i=0; i<(int)p.size(); i++) a+=cross(p[i],p[(i+1)%p.size()]);
  return fabs(a)/2;
}

vector<P> v;
int n;
bool ck() {
  vector<P> a;
  double d[n];
  for(int i=0; i<n; i++) {
    a.push_back(v[i]);
    d[i]=0;
    if(a.size()<3) continue;
    vector<P> b=convex_hull(a);
    d[i]=area(b);
    if(d[i]-d[i-1]<EPS) return 0;
  }
  return 1;
}

int main() {
  cin >> n;
  for(int i=0; i<n; i++) {
    double x,y;
    cin >> x >> y;
    v.push_back(P(x,y));
  }
  for(int t=0; t<2; t++) {
    if(!ck()) {
      cout << "Impossible" << endl;
      return 0;
    }
    reverse(v.begin(),v.end());
  }
  cout << "Possible" << endl;
  return 0;
}

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

const int MAXN = 100000 + 10;
int cnt[MAXN];

int main() {
//    freopen("test.txt", "r", stdin);
    int n, tmp;
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%d", &tmp);
        cnt[tmp]++;
    }
    int ret = 0;
    for (int i = 0;i < MAXN; i++) {
        tmp = cnt[i];
        if (i+1 < MAXN) tmp += cnt[i+1];
        if (i-1 >= 0) tmp += cnt[i-1];
        ret = max(ret, tmp);
    }
    cout << ret << endl;
    return 0;
}

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

int main() {
    int N;
    cin >> N;
    int T[N];
    for(int i = 0; i < N; i++) {
        cin >> T[i];
    }

    int M;
    cin >> M;
    int P[M];
    int X[M];
    for(int i = 0; i < M; i++) {
        cin >> P[i] >> X[i];
    }

    int a[M];
    for(int i = 0; i < M; i++) {
        a[i] = 0;
    }

    int t;
    for(int i = 0; i < M; i++) {
        t = T[P[i]-1];
        T[P[i]-1] = X[i];

        for(int j = 0; j < N; j++) {
            a[i] += T[j];
        }

        T[P[i]-1] = t;
    }

    for(int i = 0; i < M; i++) {
        cout << a[i] << "\n";
    }
    
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        int k = scanner.nextInt();
        String s = scanner.next();

        if(s.length() <= k){
            System.out.println(s);
        }else{
            String part = s.substring(0, k) + "...";
            System.out.println(part);
        }
    }
}


Measured memory_bytes: 38640
#include<stdio.h>
 
int abs(int a){
    return (a<0) ? -a : a;
}

int main(){
    int a, b, c, d;
    scanf("%d %d %d %d", &a, &b, &c, &d);
    if((d>=abs(a-b) && d>=abs(b-c)) || d>=abs(a-c))
        printf("Yes\n");
    else printf("No\n");


}

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

const long long int MOD = 1e9+7;
#define pb push_back
typedef long long ll;
const long long int N = 1e5;



int main(){
    int n,k;
    cin>>n>>k;
    int a[n+5];
    vector<bool> dp(k+5,false);
    // vector<vector<bool>> dp(k+5,vector<bool>(n+5,false));
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    dp[0]=false;
    for(int i=1;i<=k;i++){
        for(int j=1;j<=n;j++){
            if(a[j]<=i){
                dp[i]= dp[i] || !dp[i-a[j]];
            }
        }
    }
    if(dp[k]) cout<<"First";
    else cout<<"Second";

    return 0;
}

Measured memory_bytes: 3596
s=input()
t=input()

sl = list(s)
sl.sort()
s = ''.join(sl)
tl = list(t)
tl.sort(reverse=True)
t = ''.join(tl)

if(len(s) < len(t) and s == t[:len(s):] ):
    print('Yes')
elif(s == t ):
    print('No')
elif(len(s) > len(t) and s[:len(t):] == t ):
    print('No')
else:
    for i in range(min(len(s),len(t))):
        if(s[i] == t[i]):
            if(i == len(s)-1):
                print('Yes')
            continue
        elif(s[i] < t[i]):
            print('Yes')
            break
        else:
            print('No')
            break

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順

int main() {
    string S; cin >> S;
    int N = S.size();
    if (N == 1) {
        cout << 0 << endl;
        return 0;
    }

    string T;
    rep(i,N) if (S[i] != 'x') T += S[i];
    int NT = T.size();
    if (NT == 0) {
        cout << 0 << endl;
        return 0;
    }
    for (int i = 0; i <= NT/2; i++) {
        if (T[i] != T[NT-1-i]) {
            cout << -1 << endl;
            return 0;
        }
    }

    int L = NT / 2 + (NT % 2 == 1);
    int i = 0, j = 0;
    while (1) {
        if (S[i] == T[j]) {
            j++;
            if (j == L) break;
        }
        i++;
    }

    int l, r = i + 1;
    if (NT % 2 == 0) {
        l = i;
        while (S[r] == 'x') r++;
        assert(S[l] == S[r]);
    } else {
        l = i - 1;
    }
    int cnt = 0;
    if (NT % 2 == 1) l = i - 1; else l = i;
    while (l >= 0 && r < N) {
        if (S[l] != S[r]) {
            assert(S[l] == 'x' || S[r] == 'x');
            cnt++;
            if (S[l] == 'x') l--;
            else r++;
        } else l--, r++;
    }
    if (l < 0 && r < N) cnt += N - r;
    else if (l >= 0 && r == N) cnt += l + 1;
    cout << cnt << endl;
}


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

int main() {
    string s;
    cin >> s;
    int n=s.size();
    int count0=0;
    int count1=0;
    for(int i=0;i<n;i++){
        if(s[i]=='0') count0++;
        else count1++;
    }
    cout << min(count0,count1)*2 << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define fi first
#define se second
#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>;
template<typename T> inline bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T &a,T b){if(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U &u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U &u,const V... v){for(auto &e:u)fill_v<T>(e,v...);}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    string s;
    cin >> s;
    int q;
    cin >> q;
    deque<char> dq;
    int n = sz(s);
    rep(i, n) dq.push_back(s[i]);
    bool rev = false;
    while (q--) {
        int t;
        cin >> t;
        if (t == 1) {
            rev ^= true;
        } else {
            int f; char c;
            cin >> f >> c;
            f--;
            bool flag = rev^f;
            if (!flag) dq.push_front(c);
            else dq.push_back(c);
        }
    }
    if (!rev) rep(i, sz(dq)) cout << dq[i];
    else rrep(i, sz(dq)) cout << dq[i];
    cout << endl;
}


Measured memory_bytes: 4032
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using vll = vector<ll> ;
#define all(v) v.begin(),v.end()

int main(){
  char c;cin>>c;
    if(c>='a' && c<='z')cout<<'a'<<endl;
    else cout<<'A'<<endl;
}

Measured memory_bytes: 3620
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		long x = sc.nextLong();
		long y = sc.nextLong();
		sc.close();

		long a = x;
		int ans = 1;
		while (true) {
			a *= 2;
			if (a <= y) {
				ans++;
			} else {
				break;
			}
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
#define llu unsigned long long
#define ll long long
#define INF 0x3f3f3f3f
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define to_lower(s) transform(s.begin(), s.end(), s.begin(), ::tolower);
#define to_upper(s) transform(s.begin(), s.end(), s.begin(), ::toupper);

using namespace std;

// scan vector
template <typename T> 
inline istream &operator>>(istream &in, vector<T> &a) {
    for(auto &x : a) in >> x;
    return in;
}
// print vector
template <typename T> 
inline ostream &operator<<(ostream &out, vector<T> &a) {
    for(auto &x : a) out << x <<" ";
    return out;
}
// scan pair
template <typename T, typename U> 
inline istream &operator>>(istream &in, pair<T,U> &a) {
    in >> a.first >> a.second; 
    return in;
}
int n,k;
vector<ll> a;
vector<vector<ll> > dp;
vector<vector<bool> > visited;
ll solve(int first, int last)
{
    if(first>last)
        return 0;

    if(visited[first][last])
        return dp[first][last];
    
    visited[first][last]=true;

    if(first==last)
        return dp[first][last]=a[first];
    ll case1=min(a[first]+solve(first+2,last),a[first]+solve(first+1,last-1));
    ll case2=min(a[last]+solve(first,last-2),a[last]+solve(first+1,last-1));
    dp[first][last]=max(case1,case2);
    
    return dp[first][last];
}

int main()    
{
    #ifdef SANS
        freopen("ongoingin.txt","r",stdin);
        freopen("ongoingout.txt","w",stdout);
    #endif
    fast
    int t=1;
    // cin>>t;
    while(t--)
    {
        cin>>n;
        dp.resize(n,vector<ll>(n,-1));
        a.resize(n);
        cin>>a;
        visited.resize(n,vector<bool>(n,0));
        ll total=0;
        for(auto& i:a)
        {
            // cin>>i;
            total+=i;
        }
        ll X=solve(0,n-1);
        // cout<<X<<" "<<total<<endl;
        cout<<(X-(total-X));
    }
    #ifdef SANS
        cout<<"\nTime Elapsed:"<<1.0*clock()/CLOCKS_PER_SEC <<"sec\n";
    #endif
}

Measured memory_bytes: 74992
#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;}

int main() {
    // Write Your Code Below
    int n, sum;cin >> n;
    vector<int> w(n);
    for(int i=0;i<n;i++){
        cin >> w[i];
        sum += w[i];
    }
    int r=1, l=n-2, ans;
    int right=w[0], left=w[n-1];
    for(int i=0;i<n-2;i++){
        if(right<=left){
            right += w[r];
            r++;
        }else{
            left += w[l];
            l--;
        }
    }
    int a = right-left;
    ans = abs(a);
    cout << ans << endl;

}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <tuple>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <numeric>
#include <string.h>
#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define repn(i, x) for (int i = 1; i <= (int)(x); i++)
#define repr(i, x) for (int i = ((int)(x) - 1); i >= 0; i--)
#define reprn(i, x) for (int i = ((int)(x)); i > 0; i--)
#define all(x) (x).begin, (x).end()
using namespace std;
typedef long long int64;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const long long  INFL = 1e18;
const int MOD = 1000000007;
const int MAX = 210000;
const int MAX_NUM = 999999999;
//逆元を求める関数
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
	  fac[i] = fac[i-1] * i % MOD;
	  inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
	  finv[i] = finv[i-1] * inv[i] % MOD;
	}
}
//組み合わせ
long long COM (int n, int k) {
	if(n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD;
}
int N, M, Q;
vector<int> a, b, c, d;
int64 ans = 0;

void dfs(vector<int> num) {
	if (num.size() == N + 1) {
		int64 now = 0;
		for (int i = 0; i < Q; ++i) {
			if (num[b[i]] - num[a[i]] == c[i]) {
				now += d[i];
			}
		}
		ans = max(ans, now);
		return;
	}
	num.push_back(num.back());
	while (num.back() <= M) {
		dfs(num);
		num.back()++;
	}
	return;
}

void solve() {
	cin >> N >> M >> Q;
	a = b = c = d = vector<int>(Q);
	for (int i = 0; i < Q; ++i) {
		cin >> a[i] >> b[i] >> c[i] >> d[i];
	}
	dfs(vector<int>(1, 1));
	cout << ans << endl;
	return;
}
int main() {
	solve();
	return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (int i = j; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
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 (a > b) { a = b; return 1; } return 0; }
//name[i][j]-> vvl name(i,vl(j))
//map<int,int>mp
//余りを切り上げる =>  (a + b - 1) / b 

signed main(){
	ll n,x; cin>>n>>x;
	vl vec(n);
	rep(i,0,n){
		cin>>vec[i];
	}
	sort(all(vec));
	ll ans=0;
	rep(i,0,n){
		if(x<=vec[i]){
			if(x==vec[i]) ++ans;
			break;
		}
		else if(i==n-1){
			if(x==vec[i]) ++ans;
			break;
		}
		else {
			x-=vec[i];
			++ans;
		}
	}
	cout<<ans;
	
	
	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);
		long A = sc.nextInt();
		long B = sc.nextInt();
		System.out.println(lcm(A,B));
	}
	
	static long gcd(long a,long b) {
		if(a<b) {
			return gcd(b,a);
		}else if(b==0) {
			return a;
		}else {
			return gcd(b,a%b);
		}
	}
	
	static long lcm(long a,long b) {
		return a*b/gcd(a,b);
	}

}


Measured memory_bytes: 21716
#include <stdio.h>
#include <math.h>
#include <string.h>
#define rep(i,n) for(i=0;i<n;i++)
int in(void){
	int i;
	scanf("%d",&i);
	return i;
}
int main(void){
	int n,m,a[50],b[50],c[50],d[50],i,j,min,ans;
	n=in();
	m=in();
	rep(i,n){
		a[i]=in();
		b[i]=in();
	}
	rep(i,m){
		c[i]=in();
		d[i]=in();
	}
	rep(i,n){
		min=300000000;
		rep(j,m){
			int tmp=fabs(a[i]-c[j])+fabs(b[i]-d[j]);
			if(tmp<min){
				ans=j+1;
				min=tmp;
			}
		}
		printf("%d\n",ans);
	}
	return 0;
}

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

using namespace std;

#define INPUT_OUTPUT { \
    freopen("input.txt", "r", stdin); \
    freopen("output.txt", "w", stdout); \
}

int main()
{
    // INPUT_OUTPUT;
    int r, x200, d, i, a = 0;
    scanf("%d %d %d", &r, &d, &x200);
    a = x200;
    for(i = 1; i <= 10; i++) {
        a = (a*r)-d;
        printf("%d\n", a);
    }
    return 0;
}


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

import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline #文字列入力のときは注意

#n = int(input())
l,r = [int(i) for i in readline().split()]

def make_dp(init, size):
    res = "[{}]*{}".format(init,size[-1])
    for i in reversed(size[:-1]):
        res = "[{} for _ in [0]*{}]".format(res,i)
    return eval(res)


MOD = 10**9 + 7

R = bin(r)[2:]
L = bin(l)[2:]
L = "0"*(len(R)-len(L)) + L

dp = make_dp(0,(len(R)+1,2,2,2))
dp[0][0][0][0] = 1
for i, (r,l) in enumerate(zip(R,L)): #i桁目からi+1桁目に遷移
    ri = int(r)
    li = int(l)
    for is_less in range(2):
        for is_more in range(2):
            for is_nonzero in range(2):
                for dl in range(0 if is_more else li,2):
                    for dr in range(dl, 2 if is_less else ri+1): # d: i+1桁目の数字
                        dp[i+1][is_nonzero or dr != 0][is_more or li < dl][is_less or dr < ri] += dp[i][is_nonzero][is_more][is_less]*(dr==dl or is_nonzero)
                        dp[i+1][is_nonzero or dr != 0][is_more or li < dl][is_less or dr < ri] %= MOD

#print(dp[-1])
ans = 0
for i in range(2):
    for j in range(2):
        for k in range(2):
            ans += dp[-1][i][j][k]

print(ans%MOD)



Measured memory_bytes: 3064
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
using namespace std;
int main(){
    int n,sum=0;
    string s;
    cin >> n >> s;
    for(int i=0; i<n-2; ++i){
        if(s.at(i)=='A'){
            if(s.at(i+1)=='B' && s.at(i+2)=='C'){
                sum++;
                i+=2;
            }
        }
    }
    cout << sum << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define all(vec) vec.begin(), vec.end()
#define END return 0
typedef int64_t ll;
const int mod7 = 1e9 + 7;
const int mod9 = 1e9 + 9;
const int inf = 1 << 30;
const ll INF = 1LL << 60;
template<typename T> T gcd(T a, T b) {return b ? gcd(b, a % b) : abs(a);}
template<typename T> T lcm(T a, T b) {return a / gcd(a, b) * b;}
template<typename T> bool chmax(T &a, T b) {if (a < b) {a = b; return true;} return false;}
template<typename T> bool chmin(T &a, T b) {if (a > b) {a = b; return true;} return false;}
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) {fill((T*)array, (T*)(array+N), val);}

int main() {
    int R, G, B, N;
    int ans = 0;
    cin >> R >> G >> B >> N;
    for(int r = 0; r <= 3000; r++)
        for(int g = 0; g <= 3000; g++)
                if((R * r + G * g - N) <= 0 && (R * r + G * g - N) % B == 0) ans++;
    cout << ans << endl;
}

Measured memory_bytes: 384
#include <stdio.h>

int main(void)
{
  char a;
  scanf("%s", &a);
  if(a=='A')
    printf("T");
  if(a=='T')
    printf("A");
  if(a=='C')
    printf("G");
  if(a=='G')
    printf("C");
   
 
  return 0;
}

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

int main() {
  string S, T;
  int i;
  cin >> S >> T;
  for (i = 0; i < T.size(); i++)
    cout << T[i];
  for (i = 0; i < S.size(); i++)
    cout << S[i];
  cout << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int n;
	int p[20];
	int num=0;
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		scanf("%d",&p[i]);
	}
	for(int i=1;i<=n-2;i++)
	{
		if((p[i]<p[i+1]&&p[i]>p[i-1])||
		   (p[i]>p[i+1]&&p[i]<p[i-1]))
		{
			num++;
		}
	}
	printf("%d\n",num);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <cstring>
using namespace std;
int main(){
	string str;int count=0;
	getline(cin,str);
	if(count++) cout << ' ' ;
	for(int i=0;i<str.size();i++)
	if(str[i]-'a'>=0 && str[i]-'z'<=0) str[i]=toupper(str[i]);
	cout << str ;
	cout << '\n' ;
}

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

// #define int long long
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;

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 (a > b) { a = b; return 1; } return 0; }

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

ll n,m;
vpll G[100005];
ll dist[100005];

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  cin>>n>>m;
  rep(i,m){
    ll l,r,c; cin>>l>>r>>c; l--,r--;
    G[r].emplace_back(l,c);
    G[l].emplace_back(r,c);
  }
  rep(i,n){
    G[i+1].emplace_back(i,0);
  }
  rep(i,n) dist[i]=LINF;
  dist[0]=0;
  priority_queue<pll, vector<pll>, greater<pll>> q;
  q.emplace(0,0);
  while(!q.empty()){
    auto p=q.top(); q.pop();
    ll v=p.second, c=p.first;
    if(dist[v]<c) continue;
    for(auto np: G[v]){
      ll nv=np.first, nc=np.second;
      if(chmin(dist[nv],dist[v]+nc)){
        q.emplace(dist[nv],nv);
      }
    }
  }
  ll ans=dist[n-1];
  if(ans==LINF) ans=-1;
  cout<<ans<<endl;
}

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

signed main(){
    int N,K;
    cin>>N>>K;
    vpint vec;
    rep(i,N){
        int a,b;
        cin>>a>>b;
        vec.pb({a,b});
    }
    sort(all(vec));

    rep(i,vec.size()){
        if(vec[i].se<K){
            K-=vec[i].se;
            continue;
        }
        cout<<vec[i].fi<<endl;
        return 0;
    }
    return 0;
}


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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;A++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////

ll A, B;

ll i, j, k;
int main(){
    scanf("%lld%lld",&A,&B);
    if(B==1)
        printf("0");
    else
    printf("%lld", (B - 2) / (A-1)+1);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int a,b,c;
    cin >> a >> b >> c;
    int s = a+b+c;
    string ans;
    if(s>=22){
        ans = "bust";
    }else{
        ans = "win";
    }
    cout << ans << "\n";

    return 0;
}

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

#define all(x) x.begin(), x.end()
using namespace std;
using ll = long long;
using pii = pair<int, int>;
const int MN = 1e5 + 5, LN = 17, MOD = 1e9 + 7, INF = 0x3f3f3f3f, BSZ = 320;
int N, p[MN], ind[MN];

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0);
    cin >> N;
    set<int> s;
    for (int i = 1; i <= N; i++) {
        cin >> p[i];
        ind[p[i]] = i;
    }
    ll ret = 0;
    s.insert(ind[N]);
    for (int i = N - 1; i >= 1; i--) {
        int l, r, ll, rr;
        auto it = s.lower_bound(ind[i]);
        if (it == s.end()) r = N + 1, rr = N + 1;
        else {
            r = *it;
            it++;
            if (it == s.end()) rr = N + 1;
            else rr = *it;
        }
        it = s.lower_bound(ind[i]);
        if (it == s.begin()) l = 0, ll = 0;
        else {
            it--;
            l = *it;
            if (it == s.begin()) ll = 0;
            else it--, ll = *it;
        }
        s.insert(ind[i]);
        long long cnt = 0;
        cnt += 1LL * (rr - r) * (ind[i] - l);
        cnt += 1LL * (l - ll) * (r - ind[i]);
        ret += cnt * i;
    }
    cout << ret << '\n';
    return 0;
}


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

int main(void)
{
  int d[20];
  int i;
  int count = 0;

  while((scanf("%d", &d[i])) != EOF)
    {
      if(600%d[i] == 0)
	i++;
      if(i > 20) 
	break;
    }
  count = i;

  for(i = 0; i < count; i++){
    int num, j, s, width, height;
    s = 0;
    num = 600/d[i];
    width = d[i];
    for(j = 1; j <= num; j++){
      height = pow((d[i]*j-d[i]),2);
      s += width * height;
    }
    printf("%d\n", s);
  }

  return 0;
}

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

vector<string> res;
int n;

string tmp;
void gen(int m, char c) {
    if (m == (1 << n) - 1) {
        res.push_back(tmp);
        return;
    }
    int fp = 0;
    for (fp = 0; fp < n; fp++) if (!(m >> fp & 1)) break;

    tmp[fp] = c;
    m |= 1 << fp;
    for (int nm = 0; (nm | n) < 1 << n; nm = (nm | m) + 1 & (~m)) { 
        for (int ib = 0; ib < n; ib++)
            if (nm >> ib & 1)
                tmp[ib] = c;
        gen(nm | m, c + 1);   
    }
}

int main () {
    while (scanf("%d", &n) == 1) {
        tmp.assign(n, '0');
        gen(0, 'a');
        sort(res.begin(), res.end());
        for (auto &s : res) printf("%s\n", s.c_str());
    }
}



Measured memory_bytes: 7796
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>

using namespace std;

#define int long long
#define endl "\n"

const long long INF = (long long)1e18;
const long long MOD = (long long)1e9 + 7; 

string yn(bool f){return f?"Yes":"No";}
string YN(bool f){return f?"YES":"NO";}

int K;
const int MAX = 1100000;

int check(vector<int> &A, int x){
	vector<int> div, sum1, sum2;
	int res = INF;
	
	for(int i = 0; i < A.size(); i++){
		if(A[i]%x) div.push_back(A[i]%x);
	}
	
	if(!div.size()) return true;
	
	sort(div.begin(), div.end());
	
	sum1.resize(div.size()+2,0);
	sum2.resize(div.size()+2,0);
	
	for(int i = 0; i < div.size(); i++){
		sum1[i+1] += div[i];
		sum1[i+1] += sum1[i];
	}
	for(int i = div.size(); i >= 1; i--){
		sum2 [i-1] += x-div[i-1];
		sum2[i-1] += sum2[i];
	}
	// cout<<"x = "<<x<<" ------- "<<endl;
	// for(int i = 0; i < div.size(); i++) cout<<div[i]<<" ";cout<<endl;
	// for(int i = 0; i <= div.size(); i++) cout<<sum1[i]<<" ";cout<<endl;
	// for(int i = 0; i <= div.size(); i++) cout<<sum2[i]<<" ";cout<<endl;
	
	for(int i = 0; i <= div.size(); i++){
		res = min(res, max(sum1[i],sum2[i]));
		
	}
	
	return res <= K;
}

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	int ans = 1;
	int sum = 0;
	
	int N;
	vector<int> A;
	
	cin>>N>>K;
	
	A.resize(N);
	
	for(int i = 0; i < N; i++){
		cin>>A[i];
		sum += A[i];
	}
	
	for(int i = 1; i*i <= MAX*N; i++){
		if(sum%i) continue;
		if(check(A,i)) ans = max(i, ans);
		if(check(A,sum/i)) ans = max(sum/i, ans);
	}
	
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
using VI = vector<int>;
using VL = vector<LL>;
using PII = pair<int, int>;
using PLL = pair<LL, LL>;

#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define F first
#define S second
#define FOR(i, a, b) for (int i = (a); i<(b); ++i)
#define RFOR(i, b, a) for (int i = (b)-1; i>=(a); --i)
#define FILL(a, b) memset(a, b, sizeof(a))

void dout() { cerr << endl; }

template <typename Head, typename... Tail>
void dout(Head H, Tail... T) {
    cerr << H << ' ';
    dout(T...);
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, t;
    cin >> n >> t;
    VI a(n);
    FOR(i, 0, n)
        cin >> a[i];
    VI prof(n);
    int mn = a[0];
    FOR(i, 1, n)
    {
        prof[i] = a[i] - mn;
        mn = min(mn, a[i]);
    }
    int mx = *max_element(ALL(prof));
    cout << count(ALL(prof), mx);
    return 0;
}

Measured memory_bytes: 1024
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("03")
#pragma GCC optimization("unroll-loops")
#include<bits/stdc++.h>
#define ll long long 
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    int i,n,d,c=0; cin>>n>>d;
	for(i=0;i<n;i++)
    {
      ll a,b; double res;
      cin>>a>>b;
      res=sqrt(a*a +b*b);
      if(res<=d)
        c++;
    }
  cout<<c;
}

Measured memory_bytes: 3656
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(
            new InputStreamReader(System.in));
        String data = br.readLine();
        double r = Double.parseDouble(data);
        double circle1 = Math.PI * Math.pow(r, 2);
        double circle2 = 2 * Math.PI * r;

        System.out
            .println(String.format("%1$.5f %2$.5f", circle1, circle2));
    }
}

Measured memory_bytes: 24560
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n1 = sc.nextInt();
		int n2 = sc.nextInt();
		System.out.println(n1*n2 + " " + 2*(n1+n2));
	}
}



Measured memory_bytes: 26084
import java.util.*;
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 [] k = new int [n];
	int a = 0;
	int cnt = 0;
	for(int i = 0;i < n;i++) {
		k[i] = sc.nextInt();
	}
out:	for(int i = 0;;i++){
		for(int j = 0;j < n;j++) {
			if(k[j] % 2 == 1) {
				break out;
			}
			k[j] = k[j] / 2;
		}
		cnt ++;
	}
	System.out.println(cnt);
	}
}



Measured memory_bytes: 21972
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;   
#define ll long long
#define ull unsigned long long
// #define ordered_set tree<pair<ll, ll>, null_type, less<pair<ll, ll>>, rb_tree_tag, tree_order_statistics_node_update> 
ll mod=1e9+7;
#define PI 3.1415926535897932385
#define inf 9e18
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
typedef pair<long long, long long> ii;
#define S second
#define F first
ll max(ll a,ll b){if(a>b){return a;}return b;}
ll min(ll a,ll b){if(a<b){return a;}return b;}
#define MAXN 200005
// Comment this out for interactice problem
// #define endl '\n'
// string to integer stoi() Remember: it takes string not character
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
 
// To compile--> g++ -std=c++0x -o output one.cpp
// To run--> ./output
vector<ll> Divisors(ll n){ 

    vector<ll> v; 
    for (ll i=1; i*i<=n; i++) 
    { 
        if (n%i==0){ 
            if (n/i == i){
                v.push_back(i); 
            }
            else{ 
                v.push_back(i); 
                v.push_back(n/i); 
            } 
        } 
    }
    return v;
} 

int main() 
{ 
    fastio;
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
    ll n;
    cin>>n;
    map<ll, ll> m1;
    for (int i = 0; i < n; ++i)
    {
        ll a;
        cin>>a;
        m1[a]++;
    }

    ll ans=0;
    set<ll> s1;
    for (auto i = m1.begin(); i != m1.end(); ++i)
    {
        if(i->S==1){
            vector<ll> div=Divisors(i->F); 
            ll fg=0;   
            for (auto it = div.begin(); it != div.end(); ++it)
            {
                if(s1.find(*it)!=s1.end()){
                    fg=1;
                    break;
                }
            }
            if(fg==0){
                ans++;
            }
        }
        s1.insert(i->F);
    }

    cout<<ans;

    return 0;
}

Measured memory_bytes: 25504
// review
#include <iostream>
#include <vector>

using namespace std;
typedef long long ll;
const ll INF = 1e15;

ll n;
vector<ll> a;
vector<ll> sum;

ll calc(ll left, ll right, bool isLeft) {
  ll low = left, high = right;
  while (high - low > 1) {
    ll mid = (high + low) / 2;
    if (sum[mid] - (isLeft ? 0 : sum[left-1]) >= sum[right] - sum[mid-1]) {
      high = mid;
    } else {
      low = mid;
    }
  }
  return low;
}

void solve() {
  sum.push_back(a[0]);
  for (ll i=1;i<n;i++) {
    sum.push_back(a[i] + sum[i-1]);
  }
  ll minDiff = INF;
  for (ll i=1;i<n-2;i++) {
    ll leftMid = calc(0, i, true);
    ll rightMid = calc(i+1, n-1, false);
    ll maxSum = max(sum[leftMid], max(sum[i] - sum[leftMid], max(sum[rightMid] - sum[i], sum[n-1] - sum[rightMid])));
    ll minSum = min(sum[leftMid], min(sum[i] - sum[leftMid], min(sum[rightMid] - sum[i], sum[n-1] - sum[rightMid])));
    minDiff = min(minDiff, maxSum - minSum);
  }
  cout << minDiff << endl;
}

int main() {
  cin >> n;
  ll tmp;
  for (ll i=0;i<n;i++) {
    cin >> tmp;
    a.push_back(tmp);
  }
  solve();
}


Measured memory_bytes: 4848
#include <bits/stdc++.h>
#define watch(x) std::cout << (#x) << " is " << (x) << std::endl
#define print(x) std::cout << (x) << std::endl
using LL = long long;

int main() {
	//freopen("in","r",stdin);
	std::ios::sync_with_stdio(false);
	std::cin.tie(nullptr);
	int n, x, t;
	std::cin >> n >> x >> t;
	std::cout << (n + x - 1) / x * t << std::endl;
	return 0;
}

Measured memory_bytes: 3600
#include<stdio.h>
#include<string.h>
int main(void){
  int a, z;
  int flag=1;
  int i=0, l;
  char s[200000];
  scanf("%s", s);
  //printf("%s\n", s);
  l=strlen(s);
  while(flag){
    if(s[i]=='A'){
      flag=0;
      a=i;
    }
    i++;
  }
  i=strlen(s);
  flag=1;
  while(flag){
    if(s[i]=='Z'){
      flag=0;
      z=i;
    }
    i--;
  }
  /*
  printf("%d %d\n", a, z);
  for( i=a; i<=z; i++){
    printf("%c", s[i]);
  }
  */
  printf("%d\n", z-a+1);
  return 0;
}

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

int main(){

    int N, K;
    cin >> N >> K;

    int ans = 0;
    for(int i = 1; i <= N; i += 2) ans++;

    if(ans >= K) cout << "YES" << endl;
    else cout << "NO" << endl;

    return 0;
}

Measured memory_bytes: 256
# coding: utf-8

NM = list(map(int, input().split()))
M = NM[1]
Okane = 0

AB = [[0 for i in range(2)] for j in range(NM[0])]

for i in range(NM[0]):
    AB[i] = list(map(int, input().split()))

AB.sort()

for i in range(NM[0]):
  if M >= AB[i][1]:
    Okane = Okane + AB[i][0] * AB[i][1]
    M = M - AB[i][1]
  elif M < AB[i][1]:
    Okane = Okane + AB[i][0] * M
    M = 0
    
  if M == 0:
    break
      
print(Okane)

Measured memory_bytes: 27436