akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
#define MOD = 1000000007;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define ALL(a) begin(a),end(a)
#define COUNTOF(a) (sizeof(a)/sizeof(a[0]))
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}
template<class T> inline bool chmin(T& a, T b) {return a>b?a=b,true:false;}
template<class T> inline bool chmax(T& a, T b) {return a<b?a=b,true:false;}
template<class T> inline bool is_overlap(const T& as, const T& ae, const T& bs, const T& be)
{ return bs <=ae && as <= be; }
#define SP << " " <<
#define FMT(a) #a<<":"<<a 
#define FMT2(a,b) #a<<":"<<a<<", "<<#b<<":"<<b 
#define FMT3(a,b,c) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c 
#define FMT4(a,b,c,d) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c<<", "<<#d<<":"<<d 
#define ANS(a) cout<<a<<endl
void yes(bool f){cout<<(f?"yes":"no")<<endl;}
void Yes(bool f){cout<<(f?"Yes":"No")<<endl;}
void YES(bool f){cout<<(f?"YES":"NO")<<endl;}

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

    int N; cin >>N;
    vector<int> d(N); cin >> d;
  
    sort(ALL(d));
    d.erase(unique(ALL(d)),d.end());
    
    cout << d.size() << endl;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
    int arr[5];
    for(int i=0 ; i<5 ; i++){
        cin>>arr[i];
    }
    int k;
    cin>>k;
    int count=0;
    for(int i=0 ; i<5 ; i++){
        int q = i+1;
        for(int j=i+1 ; j<5 ; j++){
            int q2 = arr[j]-arr[i];
            if(q2 > k){
                count++;
            }
            q2 = 0;
        }
        if(count > 0){
            cout<<":("<<endl;
            return 0;
        }
    }
    cout<<"Yay!"<<endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
typedef long long int ll;

int main(){
	int a, b;
	cin >> a >> b;
	if(a + b == 15) cout << '+' << endl;
	else if(a * b == 15) cout << '*' << endl;
	else cout << 'x' << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>

int main() {
  int k, a, b;
  std::cin >> k >> a >> b;
  for (int i = a; i <= b; ++i) {
    if(i%k==0){
      std::cout << "OK" << std::endl;
      return 0;
    }
  }
  std::cout << "NG" << std::endl;
}


Measured memory_bytes: 3128
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS
#include <vector>
#include <iostream>
#include <iomanip>
#include <string.h>
#include <set>
#include <algorithm>
#include <cmath>
#include <map>
#include <string>
#include <time.h>
using namespace std;

typedef double LD;
typedef long long LL;
typedef pair<int, int> PII;
#define MP make_pair
#define PB push_back
#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 REP(i, t) FOR(i,0,t)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)((a).size())

const LL MOD = 1000000007;
const int INF = 1000000007;
const LL LINF = 1LL * INF * INF;
const int MAXN = 100007;
const LD EPS = 1e-7;

int A[MAXN], C[16], DP[1 << 16];

int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	//freopen("In.txt", "r", stdin);
	//freopen("sparse.in", "r", stdin);
	//freopen("sparse.out", "w", stdout);
	int n, ans = 0;
	cin >> n;
	REP(i, n - 1)
	{
		int u, v, a;
		cin >> u >> v >> a;
		A[u] ^= a;
		A[v] ^= a;
	}
	REP(i, n)
		++C[A[i]];
	FOR(i, 1, 16)
	{
		ans += C[i] >> 1;
		C[i] &= 1;
	}
	FOR(i, 1, 1 << 16)
		DP[i] = INF;
	DP[0] = DP[1] = 0;
	FOR(mask, 1, 1 << 16)
	{
		RFOR(pos, 16, 1)
		{
			if (mask & (1 << pos))
				FOR(submask, 1, pos)
			{
				int cur = bool(mask & (1 << submask));
				cur += bool(mask & (1 << (pos ^ submask)));
				DP[mask] = min(DP[mask],
					cur + DP[mask ^ (1 << pos) ^ (1 << submask) ^ (1 << (pos ^ submask))]);
			}
		}
	}
	int mask = 0;
	REP(i, 16)
		if (C[i] & 1)
			mask |= (1 << i);
	cout << ans + DP[mask];
	//cout << endl; system("pause");
	return 0;
}

Measured memory_bytes: 896
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string>
#include <sstream>
#include <numeric>
#include <set>
#include <map>
//#include <bits/stdc++.h>

#define rep(i, j) for(int i = 0; i < j; i++)
#define all(i) i.begin(), i.end()
#define ll long long
#define bl bool
#define nn printf("\n");
#define mod 1000000007

using namespace std;

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, M; while (cin >> N >> M && N != 0 && M != 0)
	{
		int r; cin >> r;
		vector<vector<int>> dat(M + 2, vector<int>(722, 0));
		vector<vector<int>> ttmp(M + 2, vector<int>(N + 2, 0));
		rep(i, r)
		{
			int t, n, m, s; cin >> t >> n >> m >> s;
			if (s == 1){ ttmp[m][n] = t - 540; }
			else if (s == 0) { fill(dat[m].begin() + ttmp[m][n], dat[m].begin() + (t - 540), 1); }
		}
		int q; cin >> q;
		rep(i, q)
		{
			int ts, te, m; cin >> ts >> te >> m;
			printf("%d\n", accumulate(dat[m].begin() + (ts - 540), dat[m].begin() + (te - 540), 0));
		}
	}
	return 0;
}

Measured memory_bytes: 60668
#include<map>
#include<cstdio>
#include<vector>
#include<algorithm>

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

using namespace std;

const int INF=1<<29;

int h,w;
char B[11][12];

vector<int> reconnect(const vector<int> &C,int x,bool b){
	vector<int> C2=C;

	if(b){
		if(x>0 && C[x-1]>0 && C[x]>0){
			rep(j,w) if(C2[j]==C[x-1]) C2[j]=C[x];
		}
		else if(x>0 && C[x-1]>0) C2[x]=C[x-1];
		else if(!(x>0 && C[x-1]>0) && C[x]==0) C2[x]=20;
	}
	else C2[x]=0;

	int f[21],id=1;
	rep(i,21) f[i]=-1;
	f[0]=0;
	rep(j,w) if(f[C2[j]]==-1) f[C2[j]]=id++;
	rep(j,w) C2[j]=f[C2[j]];

	return C2;
}

map< vector<int>,int > dp[11][11];
int dfs(int x,int y,vector<int> C){
	if(x==w) return dfs(0,y+1,C);
	if(y==h) return count(C.begin(),C.end(),2)==0?0:-INF;

	if(dp[y][x].count(C)) return dp[y][x][C];

	int res=-INF;
	if(B[y][x]=='#' || B[y][x]=='?'){
		if(!(x>0 && y>0 && C[x]>0 && C[x-1]==C[x])){
			res=max(res,dfs(x+1,y,reconnect(C,x,true))+1);
		}
	}

	if(B[y][x]=='.' || B[y][x]=='?'){
		if(!(x>0 && C[x-1]==0) && !(y>0 && C[x]==0)
		&& !(y>0 && C[x]>0 && count(C.begin(),C.end(),C[x])==1)){
			res=max(res,dfs(x+1,y,reconnect(C,x,false)));
		}
	}

	return dp[y][x][C]=res;
}

int main(){
	scanf("%d%d",&h,&w);
	rep(i,h) scanf("%s",B[i]);

	if(w==1 && h==1){
		puts(B[0][0]=='.'?"0":"1");
		return 0;
	}

	if(w==1){
		bool ok=true;
		rep(i,h-1) if(B[i][0]=='.' && B[i+1][0]=='.') ok=false;

		int i1,i2;
		for(i1= 0 ;i1< h&&B[i1][0]=='.';i1++);
		for(i2=h-1;i2>=0&&B[i2][0]=='.';i2--);
		for(int i=i1;i<=i2;i++) if(B[i][0]=='.') ok=false;

		printf("%d\n",ok?i2-i1+1:-1);
		return 0;
	}

	printf("%d\n",max(dfs(0,0,vector<int>(w,0)),-1));

	return 0;
}

Measured memory_bytes: 24000
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
const int N = 1e3+10;

struct point {
    double x,y;
}p[N];

bool cmp(point a,point b){
	return atan2(a.y,a.x)>atan2(b.y,b.x);
}

int main(){
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;++i){
        scanf("%lf%lf",&p[i].x,&p[i].y);
    }
    sort(p,p+n,cmp);
    double ans = 0;
    for(int i=0;i<n;++i){
        double x = 0,y = 0;
        int j = i;
        do{
            x += p[j].x, y += p[j].y;
            ans = max(ans,x*x+y*y);
            j = (j+1)%n;
        }while(i!=j);
    }
    printf("%.15lf\n",sqrt(ans));
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
//C++14 (GCC 5.4.1)
int main() {
    int N,A,B;
    cin >>N >> A>>B;
    //-----------------------------------
    int Ans=0,ketawa;
    for (int i = 1; i <=N; ++i){
        ketawa=i%10+(i/10)%10+(i/100)%10+(i/1000)%10+(i/10000)%10;
        if(A<=ketawa && ketawa<=B){
            Ans+=i;
        }
    }

    cout << Ans <<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#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 INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main()
{
    int a,b;
    cin >>a;
    cin >>b;
    printf("%d %d\n",(a*b),2*(a+b));
}


Measured memory_bytes: 3152
/*
 * d.cc: 
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>

using namespace std;

/* constant */

const int MAX_N = 200000;
const int INF = 1 << 30;

/* typedef */

/* global variables */

int rs[MAX_N];

/* subroutines */

/* main */

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

  for (int i = 0; i < n; i++) cin >> rs[i];

  int maxd = -INF, minr = rs[0];
  for (int i = 1; i < n; i++) {
    int d = rs[i] - minr;
    if (maxd < d) maxd = d;
    if (minr > rs[i]) minr = rs[i];
  }

  printf("%d\n", maxd);
  return 0;
}

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

int main() {
    int n;
    int dp[101000] = {INT_MAX};
    
    cin >> n;
    dp[0] = 0;
    
    for (int i = 1; i <= n; i++) {
        dp[i] = i;
        
        for (int ii = 6; ii <= i; ii *= 6) {
            dp[i] = min(dp[i], dp[i - ii] + 1);
        }
        
        for (int ii = 9; ii <= i; ii *= 9) {
            dp[i] = min(dp[i], dp[i - ii] + 1);
        }
    }
    
    cout << dp[n] << endl;
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <math.h>
#define REP(i,n) for(int (i) = 0; i <= n; ++i)
#define N 1000000
using namespace std;

vector<int>prime;

void Eratosthenes(){
    bool f[N];
    for(int i = 0; i < N; i++){
        f[i] = true;
    }
    f[0]=f[1]=false;
    
    for(int i = 2; i < sqrt(N); i++){
        if(f[i]){
            for(int j = 0; i * (j + 2) < N; j++){
                f[i *(j + 2)] = false;
            }
        }
    }
    
    for(int i = 2; i < N; i++){
        if(f[i]){
            prime.push_back(i);
        }
    }
}

int main() {
    int n;
    Eratosthenes();
    while(cin>>n){
        int ret = 0;
        for (int j = 0; j < prime.size(); j++) {
            if (prime[j] > n)break;
            ret++;
        }
        cout<<ret<<endl;
    }
    return 0;
}

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

int x[600000];
int d[600000];
int main(){
	string s;cin>>s;
	int n=s.size()+1;
	int Max=0;
	rep(i,s.size()){
		if(s[i]=='<'){
			Max++;
			d[i+1]=Max;
		}
		else Max=0;
	}
	Max=0;
	for(int i=s.size()-1;i>=0;i--){
		if(s[i]=='>'){
			Max++;
			Max=max(Max,d[i]);
			d[i]=Max;
		}
		else Max=d[i];
	}
	ll sum=0;
	/*
	rep(i,n)cerr<<d[i]<<' ';
	cerr<<endl;
	*/
	rep(i,n){
		sum+=d[i];
	}
	cout<<sum<<endl;
}

Measured memory_bytes: 2820
n = int(input())
i=0
T_point=H_point=0
while i < n:
    Taro_card, Hana_card = list(input().split())
    if Taro_card>Hana_card:
        T_point+=3
    elif Taro_card==Hana_card:
        T_point+=1
        H_point+=1
    else:
        H_point+=3
    i+=1

print(T_point, H_point)



Measured memory_bytes: 5592
import numpy as np
from collections import Counter
 
N = int(input())
S = [input() for _ in range(N)]
c = Counter(S)
d = c.most_common()
t = 1

for i in range(1, len(d)):
  if d[0][1] == d[i][1]:
    t += 1
  else:
    pass

L = [[]]*t
for j in range(t):
  L[j] = d[j][0]
  
L = sorted(L)
for i in range(len(L)):
  print(L[i])

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

class ABC130B{
    public static void Main(){
        var NX = Console.ReadLine().Split(' ').Select(int.Parse);
        var Ln = Console.ReadLine().Split(' ').Select(int.Parse);
        var count = 1;
        var sum = 0;
        foreach(var l in Ln){
            sum += l;
            if(sum>NX.ElementAt(1)){
                break;
            }
            count++;
        }
        Console.WriteLine(count);
    }
}

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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (int i = (int)a; i < (int)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define MOD 1000000007
#define INF 1000000000
#define PI 3.14159265359
#define EPS 1e-12

int main(void)
{
  int n, m;
  string s[55], t[55];
  cin >> n >> m;
  REP(i, n) cin >> s[i];
  REP(i, m) cin >> t[i];

  REP(i, n-m+1) REP(j, n-m+1){
    bool flag = true;
    REP(k, m) REP(l, m){
      if(s[i+k][j+l] != t[k][l]) flag = false;
    }
    if(flag) {
      cout << "Yes" << endl;
      return 0;
    }
  }

  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
from collections import defaultdict, deque
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    return g1[n] * g2[r] % mod

mod = 10**9+7 #出力の制限
N = 10**6
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

N, K = map(int, input().split())
dic = defaultdict(list)
for i in range(N-1):
  a, b = map(int, input().split())
  dic[a-1] += [b-1]
  dic[b-1] += [a-1]

log = [float('inf')]*N
log[0] = 0
q = deque([0])
ans = K
while q:
  p = q.popleft()
  if log[p]<1:
    ans *= cmb(K-1,K-1-len(dic[p]),mod)
  else:
    ans *= cmb(K-2,K-1-len(dic[p]),mod)
  ans %= mod
  for e in dic[p]:
    if log[e]>log[p]+1:
      q += [e]
      log[e] = log[p]+1
print(ans)


Measured memory_bytes: 127688
#include<iostream>
using namespace std;
int main(void){
int a,b,c,d;
cin  >> a>>b>>c>>d;
if(b<=c){
cout << 0<<endl;
}
else if(d<=a){
cout <<0<<endl;
}
else if(a <=c&&d<=b){
int x = d-c;
cout <<x<<endl;
}
else if(c <=a&& b<= d){
int x = b-a;
cout << x<<endl;
}
else if(a<=c){
int x = b -c;
cout <<x<<endl;
}
else{
int x = d-a;
cout <<x <<endl;
}
return 0;
}

Measured memory_bytes: 256
N = int(input())
T = [0 for i in range(N)]
A = [0 for i in range(N)]
for i in range(N):
    T[i], A[i] = map(int, input().split())
    
vote_num = A[0] + T[0]
a_num = A[0]
t_num = T[0]
for i in range(1, N):
    #print("nums: ", t_num, a_num, vote_num)
    mult_a = a_num // A[i] if a_num % A[i] == 0 else a_num // A[i] + 1
    mult_t = t_num // T[i] if t_num % T[i] == 0 else t_num // T[i] + 1
    mult_vote = vote_num // (A[i] + T[i]) if vote_num % (A[i] + T[i]) == 0 else vote_num // (A[i] + T[i]) + 1
    #print("mults: ", mult_t, mult_a, mult_vote)
    mult = max(mult_a, mult_t, mult_vote)
    a_num = A[i] * mult
    t_num = T[i] * mult
    vote_num = mult * (A[i] + T[i])

print(vote_num)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
     
     
//#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define ll long long
#define sd(x) scanf("%d",&x)
#define sld(x) scanf("%lld",&x)
#define pld(x) printf("%lld\n",x)
#define pd(x) printf("%d\n",x)
     
     
int main(){
            
    int n , k;
    sd(n); sd(k);

    string s;
    cin >> s;

    s[k-1] = s[k-1] + 32 ;        
     
     cout << s  << endl;
        
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <cmath>
#include <ctime>
#include <cassert>
#include <cstdio>
#include <queue>
#include <set>
#include <map>
#include <fstream>
#include <cstdlib>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>
using namespace std;

#define mp make_pair
#define fi first
#define se second
#define gcd(a, b) __gcd((a), (b))
#define lcm(a, b) (((a) * (b)) / (__gcd((a), (b))))
#define in_range(x, y, r, c) (x < r && y < c && x >= 0 && y >= 0)
#define setbits(x) __builtin_popcountll(x)
#define unsetend(x) __builtin_ctzll(x)
#define unsetfront(x) __builtin_clzll(x)
#define f first
#define s second
#define pb push_back
#define pf push_front
#define ll long long
#define endl "\n"
#define Endl "\n"

// long long expo(long long a, long long b, long long mod)
// {
//     ll ret = 1;
//     while (b > 0)
//     {
//         if (b % 2 == 1)
//             ret = (((ret)%mod) * ((a)%mod))%mod;
//
//         a = ((a)%mod) * ((a)%mod)%mod;
//         b = b / 2;
//     }
//     return (ret%mod);
// }

// vector<long long> seive()
// {
//    long long i,j;
//    vector<long long> hash(1000001,1);
//    vector<long long> primes;
//
//    for(i=2;i*i<=1000000;i++)
//    {
//        if(hash[i])
//        {
//            for(j=i*i;j<=1000000;j+=i)
//            hash[j]=0;
//        }
//    }
//    for(i=2;i<1000001;i++)
//    {
//        if(hash[i])
//        primes.pb(i);
//    }
//    return primes;
// }

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

    int n, i;
    cin >> n;
    int h[n + 1];
    for (i = 1; i <= n; i++)
        cin >> h[i];

    int dp[n + 1];
    dp[1] = 0;
    dp[2] = abs(h[2] - h[1]);

    for (i = 3; i <= n; i++)
    {
        dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2]));
    }
    cout << dp[n];
}

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

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define ALL(x) x.begin(),x.end()
#define EPS (1e-8)
#define equals(a,b) (fabs((a)-(b))<EPS)

using namespace std;

typedef long long ll;
const int IINF = INT_MAX;
const ll LLINF = LLONG_MAX;

inline bool LT(double a,double b) { return !equals(a,b) && a < b; }
inline bool LTE(double a,double b) { return equals(a,b) || a < b; }
vector<ll> C, S, F;
ll compute(int sp,int n) {
  ll cur = 0;
  int ptr = sp;
  while( ptr < n-1 ) {
    if( cur < S[ptr] ) {
      cur = S[ptr];
    }
    ll coef = 0;
    while( ( S[ptr] + F[ptr] * coef < cur ) ) ++coef;
    cur = S[ptr] + F[ptr] * coef;
    cur += C[ptr];
    ++ptr;
  }
  return cur;
}

int main() {
  int n;
  cin >> n;
  C.resize(n), S.resize(n), F.resize(n);
  rep(i,n-1) cin >> C[i] >> S[i] >> F[i];
  rep(i,n) {
    cout << compute(i,n) << endl;
  }
  return 0;
}


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

using namespace std;

int main (void) {
  long long A;
  double B;
  cin >> A >> B;
  int B_ = B * 100 + 0.5;
  long long ans = (A * B_) / 100;
  cout << ans << endl;
  return 0;
}


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

#define F first
#define S second
#define PB push_back

using namespace std;

typedef long long ll;

int state[112345];
ll n, k;
ll a[112345];

int findState(int pos){
	if(pos == 0)	return 0;
	if(state[pos] != -1)	return state[pos];
	int curstate = 0;
	for(int i = 0; i < n; i++){
		if(pos - a[i] < 0)	continue;
		if(findState(pos-a[i]) == 0)	curstate = 1;
	}
	return state[pos] = curstate;
}

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

	memset(state, -1, sizeof(state));
	cin >> n >> k;

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

	if(findState(k))	cout << "First\n";
	else cout << "Second\n";

	return 0;
}

Measured memory_bytes: 5376
import math
deg = 90
x = 0.0
y = 0.0
while True:
    di,ai = map(int, input().split(','))
    if di==0 and ai==0:
        break
    x += di*math.cos(deg*math.pi/180.0)
    y += di*math.sin(deg*math.pi/180.0)
    deg -= ai

print("%d\n%d" % (x,y))

Measured memory_bytes: 7704
#include <stdio.h>
 
int main(){
    int m,n,i,j,k;
        long int K;
        int a,b,c,d;
        char tmp;
        int J[1002][1002]={0},O[1002][1002]={0};//I[1002][1002]={0};
        int tmp1,tmp2,tmp3;
        
        
        scanf("%d %d\n%ld\n",&m,&n,&K);
        //for(i=0;i<m;i++){
        //      gets(map[i]);
                //printf("%s\n",&map[i]);
        //}
        //printf("%c\n",map[0][3]);
        for(i=1;i<=m;i++){
                for(j=1;j<=n;j++){
            scanf("%c",&tmp);
            if(tmp=='\n') scanf("%c",&tmp);
            if(i==1&&j==1){
                
            }
            else if(i==1){
                J[i][j]=J[i][j-1];
                O[i][j]=O[i][j-1];
                //I[i][j]=I[i][j-1];
            }
            else if(j==1){
                J[i][j]=J[i-1][j];
                O[i][j]=O[i-1][1];
                //I[i][j]=I[i-1][1];
            }
            else{
                                J[i][j]=J[i-1][j]+J[i][j-1]-J[i-1][j-1];
                                O[i][j]=O[i-1][j]+O[i][j-1]-O[i-1][j-1];
                                //I[i][j]=I[i-1][j]+I[i][j-1]-I[i-1][j-1];
            }
                                if(tmp=='J'){
                                        //printf("j\n");
                                        J[i][j]+=1;
                    //printf("%d:%d J%d\n",i,j,J[i][j]);
                                }
                                else if(tmp=='O'){
                                        O[i][j]+=1;
                    //printf("%d:%d O%d\n",i,j,O[i][j]);
                                }
                                else if(tmp=='I'){
                                        //I[i][j]+=1;
                    //printf("%d:%d I%d\n",i,j,I[i][j]);
                                }
                }
        }
    scanf("%c",&tmp);
        for(i=0;i<K;i++){
                scanf("%d %d %d %d\n",&a,&b,&c,&d);
                tmp1 = J[c][d]-J[c][b-1]-J[a-1][d]+J[a-1][b-1];
                printf("%d ",tmp1);
                tmp2 = O[c][d]-O[c][b-1]-O[a-1][d]+O[a-1][b-1];
                printf("%d ",tmp2);
                tmp3 = (c-a+1)*(d-b+1)-tmp1-tmp2;
                printf("%d\n",tmp3);
        }
        return 0;
}

Measured memory_bytes: 8880
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <climits>
#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <vector>
#include <sstream>
#include <typeinfo>
#include <fstream>

#define DIV 1000000007

using namespace std;

long long N, M;
bool box[100005];
int num[100005];
int main(){
	cin >> N >> M;
	box[0] = true;
	for(int i = 0; i < N; i++){
		num[i] = 1;
	}

	for(int i = 0; i < M; i++){
		long long x, y;
		cin  >> x >> y;
		x--;y--;
		if(num[x] == 1 && box[x] == true){
			box[x] = false;
			num[x]--;
			num[y]++;
			box[y] = true;
		}else{
			num[x]--;
			num[y]++;
			box[y] |= box[x];
		}
	}
	long long ret = 0;
	for(int i = 0; i < N; i++){
		if(box[i]){
			ret++;
		}
	}
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 768
#include <stdio.h>
#define N 8
#define TRUE 3
#define FALSE 2
#define FREE -1
#define NOT_FREE 1
 
int X[N][N];
int row[N],col[N],dpos[2*N-1],dneg[2*N-1];
 void syokika(){
  int i;
  for(i=0;i<N;i++){
      row[i]=FREE;
      col[i]=FREE;
    }
  
  for(i=0;i<2*N-1;i++){
      dpos[i]=FREE;
      dneg[i]=FREE;
    }
}
void printboard(){
  int i,j;
  
  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      if(X[i][j]==TRUE){
	if(row[i]!=j) return;
      }
    }
  }
  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      if(row[i]==j)printf("Q");
      else printf(".");
    }
    printf("\n");
  }
}

void putQueen(int a){
  int j;
  if(a==N){
    printboard();
    return;
  }
  for(j=0;j<N;j++){
    if(col[j]==NOT_FREE || dpos[a+j]==NOT_FREE || dneg[a-j+N-1]==NOT_FREE) continue;
    
    row[a]=j;
    col[j]=dpos[a+j]=dneg[a-j+N-1]=NOT_FREE;
    putQueen(a+1);
    col[j]=dpos[a+j]=dneg[a-j+N-1]=FREE;
  }
}
     
int main(){
  int i,j,k,r,c;
  syokika();
  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      X[i][j]=FALSE;
    }
  }
  scanf("%d",&k);
  for(i=0;i<k;i++){
    scanf("%d%d",&r,&c);
    X[r][c]=TRUE;
  }
  putQueen(0);
  return 0;
}
 

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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(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) long long(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>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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 = 1e9;
const ll MOD = 1e9+7;
const ll LINF = 1e18;



signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  string s; cin>>s;
  if(s=="ABC") cout<<"ARC"<<endl;
  else cout<<"ABC"<<endl;
}

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


int main(int argc, char *argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  string s; cin >> s;
  char z = s.at(0) + 1;
  cout << z << endl;

  return 0;
}



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

int main() {
    string s, t, u;
    int a, b;
    cin >> s >> t >> a >> b >> u;
    
    if (s == u) cout << a-1 << " " << b << endl;
    else cout << a << " " << b-1 <<  endl;
    return 0;
}

Measured memory_bytes: 256
/*

  "With age, comes wisdom. With travel, comes understanding.
   Remember that happiness is a way of travel – not a destination"

*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define int            long long int
#define ld             long double
#define F              first
#define S              second
#define pb             push_back
#define si             set <int>
#define vi             vector <int>
#define pii            pair <int, int>
#define vpi            vector <pii>
#define vpp            vector <pair<int, pii>>
#define mii            map <int, int>
#define mpi            map <pii, int>
#define spi            set <pii>
#define endl           "\n"
#define sz(x)          ((int) x.size())
#define all(p)         p.begin(), p.end()
#define que_max        priority_queue <int>
#define que_min        priority_queue <int, vi, greater<int>>
#define bug(...)       __f (#__VA_ARGS__, __VA_ARGS__)
#define print(a)       for(auto x : a) cout << x << " "; cout << endl
#define print1(a)      for(auto x : a) cout << x.F << " " << x.S << endl
#define print2(a,x,y)  for(int i = x; i < y; i++) cout<< a[i]<< " "; cout << endl

inline int power(int a, int b)
{
     int x = 1;
     while (b)
     {
          if (b & 1) x *= a;
          a *= a;
          b >>= 1;
     }
     return x;
}

typedef tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update> Set;

template <typename Arg1>
void __f (const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << endl; }
template <typename Arg1, typename... Args>
void __f (const char* names, Arg1&& arg1, Args&&... args)
{
     const char* comma = strchr (names + 1, ',');
     cout.write (names, comma - names) << " : " << arg1 << " | "; __f (comma + 1, args...);
}

const int N = 200005;
int a[N], n, m, k;

void solve()
{
     int i, j;
     string s; cin >> s;
     n = sz(s);
     i = 0, j = n - 1;
     int cnt = 0;
     while (i < j)
     {
          if (s[i] != s[j])
               cnt++;
          i++;
          j--;
     }
     cout << cnt;

}

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

     cout << setprecision(9) << fixed;
     clock_t z = clock();
     solve();
     cerr << "Run Time : " << ((double)(clock() - z) / CLOCKS_PER_SEC);

     return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<string>
#include<vector>
#include<sstream>
#include<deque>
#include<algorithm>

using namespace std;

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

deque<int> ans;

void saiki(int maxi,int amari){
	if(amari==0){
		rep(i,ans.size()){
			printf("%d",ans[i]);
			if(i+1>=ans.size()){
				break;
			}
			printf(" ");
		}puts("");
	}
	for(int i=min(maxi,amari);i>0;i--){
		ans.push_back(i);
		saiki(i,amari-i);
		ans.pop_back();
	}
}

int main(){
	while(1){
		int n;
		scanf("%d",&n);
		if(n==0)break;
		ans.clear();
		saiki(n,n);
	}
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
 
int main(){
	 int n;
	 string word[100];
	 cin>>n;

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

	 for (int i = 0; i < n-1; i++){
	 	if(word[i].back()!=word[i+1][0]){
	 		cout<<"No"<<endl;
	 		return 0;
	 	}
	 }

	 for (int i = 0; i < n; i++){
	 	for (int j = i+1; j < n; j++){
	 		if(word[i]==word[j]){
	 			cout<<"No"<<endl;
	 			return 0;
	 		}
	 	}
	 }

	 cout<<"Yes"<<endl;
}



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

#define mod 1000000007

using namespace std;
typedef long long ll; 
 
int main(void){
	
	string S;
	
	cin >> S;
	
	int N = S.length();
	
	int ans[N] = {};
	
	char now = 'R';
	int count_R = 1, count_L = 0;
	for(int i=1; i<N; i++){
		if(S[i] == 'L' && S[i-1] == 'R'){
			if(count_R % 2 == 0){
				ans[i] += count_R / 2;
				ans[i - 1] += count_R / 2;
			}else{
				ans[i] += (count_R / 2);
				ans[i - 1] += count_R / 2 + 1;
			}
			count_R = 0;
			count_L = 0;
		}else if(S[i] == 'R' && S[i-1] == 'L'){
			if(count_L % 2 == 0){
				ans[i - count_L - 1] += count_L / 2;
				ans[i - count_L] += count_L / 2;
			}else{
				ans[i- count_L - 1] += (count_L / 2);
				ans[i - count_L] += count_L / 2 + 1;
			}
			count_R = 0;
			count_L = 0;
		}
		if(S[i] == 'R')
			count_R++;
		if(S[i] == 'L')
			count_L++;
		if(i == N - 1 && S[i] == 'L' && S[i-1] == 'L'){
			if(count_L % 2 == 0){
				ans[i - count_L] += count_L / 2;
				ans[i - count_L + 1] += count_L / 2;
			}else{
				ans[i- count_L + 1] += (count_L / 2) + 1;
				ans[i - count_L] += count_L / 2;
			}
		}
	}
	
	if((S[N-1] == 'R' && S[N-2] == 'L') || (S[N-1] == 'L' && S[N-2] == 'R'))
		ans[N-1]++;
		
	
	for(int i=0; i<N; i++)
		cout << ans[i] << " ";
	
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
using i64 = int_fast64_t;
#define rep(i, N) for(int (i) = 0; (i) < (N); (i)++)
#define all(v) (v).begin(), (v).end()
#define eb emplace_back

int main(){
    string S;
    int Q;
    cin >> S >> Q;
    deque<char> dq;
    for(auto& c : S) dq.emplace_back(c);

    bool r = false;
    while(Q--){
        int q; 
        cin >> q;
        if(q == 1) r ^= 1;
        if(q == 2){
            int f; char c;
            cin >> f >> c; f--;
            if((f ^ r) == 0) dq.emplace_front(c);
            if((f ^ r) == 1) dq.emplace_back(c);
        }
    }

    string ans = "";
    for(auto& c : dq) ans += c;
    if(r) reverse(all(ans));

    cout << ans << endl;
}


Measured memory_bytes: 1412
min_  = 1000000000
difmax=-1000000000
cnt=0
n = STDIN.gets.split[0].to_i
0.upto(n-1) {|i| 
  n = STDIN.gets.split[0].to_i

  dif = n - min_   if(i>0)

  if n < min_
    min_ = n
  end
 
  difmax = dif if dif > difmax   if(i>0)
}
puts difmax

Measured memory_bytes: 8780
#include <iostream>
#define ll long long
using namespace std;


int main(){
  ll a[100002];
  ll N;
  ll count=0;
  cin>>N;
  for(ll in=1;in<=N;in++){
    cin>>a[in];
  }
  for(ll i=1;i<=N;i++){
    for(ll j=1;;j++){
      if(a[i]%2==0){
        a[i]=a[i]/2;
        count++;
      }
      else break;
      
      
    }
    
  }
  cout<<count<<endl;
  return 0;
}


Measured memory_bytes: 384
/* half & half */

#include <iostream>
#include <cmath>

using namespace std;

int main(){
  int A, B, C, X, Y;
  cin >> A >> B >> C;
  cin >> X >> Y;

  int i, j, k;
  int min_sum = A * X + B * Y;
  for(k = 0; k <= max(X, Y); k++){
    i = max(0, X - k);
    j = max(0, Y - k);
    int sum = A*i + B*j + 2*C*k;
    //cout << sum << " " << i << " " << j << " " << k << endl;
    if(min_sum > sum) min_sum = sum;
  }
  
  /*
  int D = A + B -2*C;

  if(D > 0){ k = min(X,Y);}
  else{ k = 0; }
  i = X - k; j = Y - k;
  
  int sum = A * i + B * j + 2*C*k;
  */
  
  cout << min_sum << endl;
  
  //cout << i << " " << j << " " << 2*k << endl;
  return 0;
}
  


Measured memory_bytes: 256
import sys 
input = lambda:sys.stdin.readline().strip()
import bisect
n,m,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
ans = 0
for i in range(1,n):
    a[i]+=a[i-1]
for i in range(1,m):
    b[i]+=b[i-1]
for i in range(n):
    rem = k-a[i]
    if rem<0:
        break 
    ind = bisect.bisect_right(b,rem)
    ans = max(ans,i+1+ind)
    # print(ans,ind,rem)
for i in range(m):
    rem = k-b[i]
    if rem<0:
        break 
    ind = bisect.bisect_right(a,rem)
    ans = max(ans,i+1+ind)
print(ans)
            
    

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

#ifdef LOCAL
#include "../debug.h"
#else
#define debug(x...) 141
#endif
#define forn(i,x,n) for(int i = x; i < n; ++i)
#define forit(it, m) for(auto it = m.begin(); it!=m.end(); ++it)
typedef long long ll;

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll n,i=1;
    string s="";

    cin>>n;
    n--;
    while(n>=0)
    	n-=pow(26,i++);
    n+=pow(26,--i);

    while(i--){
    	s=(char)('a'+n%26)+s;
    	n/=26;
    }

    cout<<s;
    
    return 0;
}

Measured memory_bytes: 4060
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int N,T,A;
  cin>>N>>T>>A;
  int H[N];
  for(int i=0;i<N;i++){
    cin>>H[i];
  }
  vector<double> t(N);
  for(int i=0;i<N;i++){
    t[i]=T-0.006*H[i];
    t[i]=abs(t[i]-A);
  }
  
  auto ans= min_element(t.begin(),t.end());
  cout<<(int)(ans-t.begin())+1;
}

Measured memory_bytes: 256
#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<deque>
#include<chrono>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
const ll E=1e17+7;
#define F first
#define S second
#define MK make_pair


bool s[100000];

int main(){
    fill(&s[2],&s[100000],1);
    vector<int> S;
    for(int i=2;i<55556;i++){
        if(s[i]){
            S.push_back(i);
            for(ll t=i;i*t<55556;t++){
                s[i*t]=false;
            }
        }
    }
    vector<int> ans[5];
    for(int i=0;i<S.size();i++){
        ans[S[i]%5].push_back(S[i]);
    }
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        cout<<ans[1][i];
        if(i!=n-1){cout<<" ";}
    }
    cout<<endl;
    
    return 0;
}

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

long long cnt;
int l;
int A[1000000];
int n;
vector<int> G;

void insertionSort(int A[], int n, int g) {
    for ( int i = g; i < n; i++ ) {
        int v = A[i];
        int j = i - g;
        while ( j >= 0 && A[j] > v) {
            A[j+g] = A[j];
            j -= g;
            cnt++;
        }
        A[j + g] = v;
    }
}

void shellSort(int A[], int n) {
    for ( int h = 1; ; ) {
        if ( h > n ) break;
        G.push_back(h);
        h = 3*h + 1;
    }

    for ( int i = G.size()-1; i >= 0; i--) {
        insertionSort(A, n, G[i]);
    }
}

int main() {
    cin >> n;
    for ( int i = 0; i < n; i++ ) scanf("%d", &A[i]);
    cnt = 0;

    shellSort(A, n);

    cout << G.size() << endl;
    for ( int i = G.size()-1; i >= 0; i-- ) {
        printf("%d", G[i]);
        if ( i ) printf(" ");
    }
    printf("\n");
    printf("%d\n", cnt);
    for ( int i = 0; i < n; i++) {
        printf("%d\n", A[i]);
    }
    return 0;
}
/*
int cnt = 0;
void insertionSort(int A[], int N, int g) {
    for ( int i = g; i < N; i++ ) {
        int v = A[i];
        int j = i - g;
        while ( j >= 0 && A[j] > v) {
            A[j+g] = A[j];
            j = j - g;
            cnt++;
        }
        A[j+g] = v;
    }
}

void shellSort(int A[], int N) {
    int cnt = 0;
    int m = 2;
    int G[] = {4, 1};
    cout << m << endl;
    for ( int i = 0; i < m; i++) {
        if (i != 0) cout << " ";
        cout << G[i];
    }
    cout << endl;

    for ( int i = 0; i < m; i++) {
        insertionSort(A, N, G[i]);
    }
}

int main() {
    int N, A[100000];

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

    shellSort(A, N);


    cout << cnt << endl;
    for ( int i = 0; i < N; i++ ) {
        cout << A[i] << endl;
    }

}
*/

Measured memory_bytes: 7108
S = input()
N = len(S)
A = S[:int((N-1)/2)]
B = S[int((N+3)/2)-1:]
out = 0

for i in range(N):
    if S[i]!=S[N-i-1]:
        out = 1
for i in range(len(A)):
    if A[i]!=A[len(A)-i-1]:
        out = 1
for i in range(len(B)):
    if B[i]!=B[len(B)-i-1]:
        out = 1

if out==0:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 38392
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
using namespace std;
const int MAXN = 100005,INF=0x3f3f3f3f;
struct Edge{
    int to,next;
}e[MAXN<<1];
int val[MAXN],n,cnt,k,head[MAXN];
inline void insert(int u,int v)
{
    e[++cnt].to=v,e[cnt].next=head[u],head[u]=cnt;
    e[++cnt].to=u,e[cnt].next=head[v],head[v]=cnt;
}
bool flag=true;
int l[MAXN],r[MAXN],sta[MAXN];
#define EXIT {puts("No");exit(0);}
void dfs_up(int x,int fa)
{
    if(val[x]<INF)sta[x]=(val[x]&1);
    for(int i=head[x];i;i=e[i].next){
        int v=e[i].to;
        if(v==fa)continue;
        dfs_up(v,x);
        if(sta[x]<INF){
            if(sta[v]<INF && sta[x]^(sta[v]^1))EXIT;
        }else{
            if(sta[v]<INF)sta[x]=(sta[v]^1);
        }
        l[x]=max(l[x],l[v]-1),r[x]=min(r[x],r[v]+1);
    }
    if(l[x]>r[x])EXIT;
}
void dfs_down(int x,int fa)
{
    if(fa){
        l[x]=max(l[x],l[fa]-1),r[x]=min(r[x],r[fa]+1);
        if(sta[x]<INF){
            if(sta[x]^(sta[fa]^1))EXIT;
        }
    }
    if(l[x]>r[x])EXIT;
    if(l[x]==r[x] && (sta[x])^(l[x]&1))EXIT;
    for(int i=head[x];i;i=e[i].next){
        int v=e[i].to;
        if(v==fa)continue;
        dfs_down(v,x);
    }
}
int ans[MAXN];
void getans(int x,int fa)
{
    if(!fa){
        if((l[x]&1)^sta[x])ans[x]=l[x]+1;
        else ans[x]=l[x];
    }else ans[x]=ans[fa]-1,ans[x]+=(ans[x]<l[x])*2;
    for(int i=head[x];i;i=e[i].next){
        int v=e[i].to;
        if(v==fa)continue;
        getans(v,x);
    }
}
int main()
{
    scanf("%d",&n);
    for(int i=1;i<n;++i){
        int u,v;
        scanf("%d%d",&u,&v);
        insert(u,v);
    }
    memset(val,0x3f,sizeof(val));
    memset(l,128,sizeof(l));
    memset(r,127,sizeof(r));
    memset(sta,0x3f,sizeof(sta));
    scanf("%d",&k);
    int x,y,root=1;
    while(k--){
        scanf("%d%d",&x,&y);
        val[x]=y;
        l[x]=r[x]=y;
        root=x;
    }
    dfs_up(root,0);
    dfs_down(root,0);
    puts("Yes");
    getans(root,0);
    for(int i=1;i<=n;++i)
        printf("%d\n",ans[i]);
    return 0;
}

Measured memory_bytes: 9472
#include <bits/stdc++.h>
#include <string>
using namespace std;
#define ll long long int
#define ld long double
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define mod 1000000007
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define fr(i,a,n) for(i=a;i<n;i++)
#define frn(i,a,n) for(i=a;i<=n;i++)
#define vll vector<ll>
#define pll pair<ll,ll>
#define vp vector<pll>
#define ub upper_bound
#define lb lower_bound
//#define map map<ll,ll>
#define mem(x,y) memset(x,y,sizeof(x))
#define all(v) v.begin(),v.end()
#define bs binary_search
#define qll queue<ll>
#define sll set<ll>
#define ma 500000
ll power(ll x,ll n)
{
    if(n==0)
        return 1;
    else if(n%2 == 0)        //n is even
        return power(x*x,n/2);
    else                             //n is odd
        return x*power(x*x,(n-1)/2);
}
int highestPowerof2(int n)
{
   int p = (int)log2(n);
   return (int)pow(2, p);  
}
ll powermod(ll x, ll y, ll p)  
{  
    ll res = 1;
    x = x % p;
    if (x == 0) return 0;  
  
    while (y > 0)  
    {  
        if (y & 1)  
            res = (res*x) % p;  
        y = y>>1; 
        x = (x*x) % p;  
    }  
    return res;  
}
 
int main()
{
    ll n;
    cin>>n;
    if(n%1000==0)
    cout<<0<<endl;
    else
    {
        ll ans=n/1000;
        ans++;
        ans=ans*1000;
        cout<<ans-n<<endl;
    }
return 0;
}


Measured memory_bytes: 3676
import Data.List
main :: IO ()
main = do
    _ <- getLine
    h1:h <- map read . words <$> getLine :: IO [Int]
    let (a,_,_) = foldl' f (0,0,h1) h
    print a
  where
    f (m,c,i) j =
        let c' = if i >= j then c+1 else 0
         in (max m c', c', j)


Measured memory_bytes: 91516
#include <iostream>
#include <iomanip>
#include <cmath>
#include <vector>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <queue>
#include <stack>
#include <map>
#include <unordered_map>
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;
using namespace std;
const int N = 2e5 + 5;

int main()
{
    int n;
    cin >> n;
    vector<int> t(n + 1);
    vector<int> h(n);
    ll s = 0;
    rep(i, n + 1)
    {
        cin >> t[i];
        s += t[i];
    }
    rep(i, n)
    {
        cin >> h[i];
    }
    ll tt = s;
    rep(i, n)
    {
        if (h[i] > t[i])
        {
            s -= t[i];
            h[i] -= t[i];
            t[i] = 0;
            if (h[i] > t[i + 1])
            {
                s -= t[i + 1];
                t[i + 1] = 0;
            }
            else
            {
                t[i + 1] -= h[i];
                s -= h[i];
            }
        }
        else
        {
            s -= h[i];
            t[i] -= h[i];
        }
    }
    cout << (tt - s) << endl;
}

Measured memory_bytes: 3988
line = readlines.map(&:to_i)

N = line[0]

a = []
for i in 1..N do
  a.push(line[i])
end
b = a.sort.reverse

for i in 1..N do
  if a[i-1] == b[0] then
    puts b[1]
  else
    puts b[0]
  end
end

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

using namespace std;

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define MOD 1000000007
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)

signed main(){

	string s,t;
	cin>>s>>t;

	sort(s.begin(),s.end());
	sort(t.rbegin(),t.rend());

	if(s<t)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
void fastIO(){
  ios_base::sync_with_stdio(0); cin.tie(0);
}


int main(){
  fastIO();
  int n;
  cin>>n;
  vector<ll>cities(n+1);
  vector<ll>heroes(n);
  for(int i=0;i<=n;i++){
  	cin>>cities[i];
  }
  for(int i=0;i<n;i++){
  	cin>>heroes[i];
  }
  ll tot = 0;
  for(int i=0;i<n;i++){
  	if(heroes[i]<=cities[i]){
  		cities[i]-=heroes[i];
  		tot+=heroes[i];
  		heroes[i]=0;
  	}else{
  		tot+=cities[i];
  		heroes[i]-=cities[i];
  		cities[i]=0;
  		if(heroes[i]<=cities[i+1]){
  			tot+=heroes[i];
  			cities[i+1]-=heroes[i];
  			heroes[i]=0;
  		}else{
  			tot+=cities[i+1];
  			heroes[i]-=cities[i+1];
  			cities[i+1]=0;
  		}
  	}
  }
  cout<<tot<<endl;
}

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

#include <utility>

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;

#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

template<class Monoid>
class SegmentTree {

public:
    /**
     * @param N size
     * @param e identity element
     * @param operation operation to merge `data`
     * @param updater operation to update `data`
     */
    SegmentTree(size_t N, Monoid e, function<Monoid(Monoid, Monoid)> operation,
                function<Monoid(Monoid, Monoid)> updater)
            : e(e), operation(operation), updater(move(updater)) {
        n = 1;
        while (n < N) {
            n *= 2;
        }
        data = vector<Monoid>(2 * n - 1, e);
        for (int i = n - 2; i >= 0; i--) {
            data[i] = operation(data[2 * i + 1], data[2 * i + 2]);
        }
    }

    /**
     * iの値をxに更新 ( 0-indexed )
     */
    void update(int i, Monoid x) {
        i += n - 1;
        data[i] = updater(data[i], x);
        while (i > 0) {
            i = (i - 1) / 2;
            data[i] = operation(data[i * 2 + 1], data[i * 2 + 2]);
        }
    }

    /**
     * [a, b)の区間でクエリを実行
     */
    Monoid query(int a, int b) {
        return query(a, b, 0, 0, n);
    }

    /**
     * 添字でアクセス( 0-indexed )
     */
    Monoid operator[](int i) {
        return data[i + n - 1];
    }

private:
    int n;
    vector<Monoid> data;
    Monoid e;
    function<Monoid(Monoid, Monoid)> operation;
    function<Monoid(Monoid, Monoid)> updater;

    Monoid query(int a, int b, int k, int l, int r) {
        // 交差しない
        if (r <= a || b <= l) return e;
        // 区間 [a, b) に l, r が含まれる
        if (a <= l && r <= b) return data[k];
        // 左の子
        Monoid c1 = query(a, b, 2 * k + 1, l, (l + r) / 2);
        // 右の子
        Monoid c2 = query(a, b, 2 * k + 2, (l + r) / 2, r);
        return operation(c1, c2);
    }
};

void Main() {
    int N;
    cin >> N;
    vector<ll> H(N), A(N);
    rep(i, N) cin >> H[i];
    rep(i, N) cin >> A[i];
    SegmentTree<ll> segmentTree(N + 1, 0, [](ll a, ll b) { return max(a, b); }, [](ll a, ll b) { return b; });
    rep(i, N) {
        ll h = H[i];
        ll a = A[i];
        ll tmp = segmentTree.query(0, h);
        segmentTree.update(h, tmp + a);
    }
    cout << segmentTree.query(0, N + 1) << '\n';
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 7552
#include"bits/stdc++.h"
using ll=long long; 
using ld=long double; 
#define rep(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
const int mod=1e9+7; 
int main()
{
  #ifndef ONLINE_JUDGE
  freopen("input.txt","r",stdin);
  freopen("output.txt","w",stdout); 
  #endif
  int n; cin>>n; vector<int>a(n); for(int i=0;i<=n-1;i++) cin>>a[i]; 
  vector<ll>p(n); p[n-1]=(a[n-1])%mod; for(int i=n-2;i>=0;i--) p[i]=(p[i+1]+a[i])%mod;  
  ll ans=0; 
  for(int i=0;i<=n-2;i++)
  { 
    ans=(ans+a[i]*1ll*p[i+1])%mod; 
  }
  cout<<ans<<"\n"; 
  return 0; 
}

Measured memory_bytes: 5580
read N H
sort -nr|awk 'NR==1{a=$1;print a}a<$2{print $2}'|sort -nr|awk -v H=$H 'function c(x){return (int(x)==x)?x:int(x)+1}{H-=$0;if(H<=0){print NR;exit}}END{print NR+c(H/$0)}'|head -1

Measured memory_bytes: 13536