akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include <cstdio>
using namespace std;
#define ll  long long
#define PB push_back
#define ld long double
#define ff first
#define ss second
# define st(v) (v).begin(),(v).end()
#define   pr pair<int,int>
using namespace std::chrono;
const int N = 1e5+5 , M=N,inf=(int)1e9;
const int mod=1e9+7;
int fastAbs(int n) { return (n ^ (n >> 31)) - (n >> 31); }
ll multiply(ll a, ll b){ return ((a % mod) * (b % mod)) % mod; }
ll add(ll a, ll b) {     return ((a % mod) + (b % mod)) % mod; }
ll sub(ll a, ll b) { return ((a%mod) - (b % mod)+ mod) % mod ; }
int ans ;
map< pair<int,int> , int > mp;
const int dx[4] = {1,0,0,-1};
const int dy[4] = {0,-1,1,0};
string cal ( int p , int k){
    string  ans = "000000000000";
    int i = 5 ;
    int r;
    while(p!=0){
        r = p%10 ;
        ans[i] = r + 48 ;
        i--;
        p/=10;
    }
    i = 11 ;
    while(k!=0){
        r = k%10 ;
        ans[i] = r + 48 ;
        i--;
        k/=10;
    }
    return ans ;
}
void solve(){
  int n , m ;
  cin >> n >> m ;
  vector < pair< int, pair < int , int > > > a( m ) ;
  for ( int i = 0 ; i < m ; i++){
        int x , y ;
        cin >> x >> y ;
        a[i] = {x,{y,i}} ;
  }
   sort(st(a)) ;
   vector < string > answer(m);
    int k = 1 ;
    //for( int i = 0 ; i < m ; i)
    answer[a[0].ss.ss] = cal(a[0].ff,k) ;
    for( int i = 1 ; i < m ; i++){
        if( a[i-1].ff == a[i].ff){
            k++;
            answer[a[i].ss.ss] = cal(a[i].ff,k);
        }
        else{
            k = 1 ;
           answer[a[i].ss.ss] = cal(a[i].ff,k);
        }
    }
    for ( int i = 0 ; i < m ; i++ ) cout << answer[i] << '\n';
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int q=1;
    //cin >> q;
    while(q--)
        solve();
}



Measured memory_bytes: 8192
from fractions import gcd
N = int(input())
A = list(map(int, input().split()))
gcd_b = {}
gcd_a = {}
gcd_b[-1] = 0
for i in range(N):
    gcd_b[i] = gcd(gcd_b[i-1], A[i])
gcd_a[N] = 0
for i in range(N):
    gcd_a[N-1-i] = gcd(gcd_a[N-i], A[N-1-i])
ans = 0
for i in range (N):
    ans = max(ans, gcd(gcd_b[i-1], gcd_a[i+1]))
print(ans)

Measured memory_bytes: 33808
#include<bits/stdc++.h>
#define all(x) x.begin(), x.end()
using namespace std;
const int inf = 1<<30, maxn = 1<<19;

int main() {
	cin.tie(0)->sync_with_stdio(0);
	int a = 0;
	string s, t;
	cin>>s >> t;
	for(int i = 0; i < s.size(); i++) a += s[i] != t[i];
	cout << a;
	return 0;
}


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

#define rep(i,n) for (int i = 0; i< (n); ++i)
#define vvec(m,n) vector<vector<int>> (int(m), vector<int>(n))
#define ALL(a) (a).begin(), (a).end()

using ll = long long;

int main(){
    int a, b, c;
    cin >> a >> b >> c;
    if((a-b)<=0){
        cout << c << endl;
        return 0;
    }
    if(c - (a-b) <=0) cout << 0 << endl;
    else cout << c - (a-b)  << endl;
    
}

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

#define endl '\n'
#define rep(i,n)       for(int i=0; i<n; i++)
#define clr(arr)       memset(arr, 0, sizeof arr)
#define all(x)         x.begin(), x.end()
const int MOD = 1e9 + 7;

#ifdef SMIT
template<class F, class S> ostream& operator<<(ostream &out, const pair<F, S> &p)
{
	return out << '(' << p.first << ", " << p.second << ')';
}
template<class T> auto operator<<(ostream &out, T &&x) -> decltype(x.begin(), out)
{
	out << '{';
	for (auto i = x.begin(); i != x.end(); i++)
		out << *i << (i == prev(x.end()) ? "" : ", ");
	return out << '}';
}
void dmp() {}
template<class T, class... Args> void dmp(T &&x, Args... args)
{
	cerr << x << ";  "; dmp(args...);
}
struct Nl {~Nl() {cerr << '\n';}};
#define debug(x...) cerr << (strcmp(#x, "") ? #x ":  " : ""), dmp(x), Nl(), cerr << ""
#else
#define debug(...) {}
#endif
// Yes you CAN



void solve()
{
// #define TEST
	string s; cin >> s;
	if (s.back() == 's') cout << s + "es" << endl;
	else cout << s + "s" << endl;
}

int32_t main()
{
#ifdef SMIT
	// freopen("/home/smit/Desktop/in.txt", "r", stdin);
#endif
	ios_base::sync_with_stdio(false); cin.tie(nullptr);

	int t = 1;
#ifdef TEST
	cin >> t;
#endif
	while (t--)
		solve();
}

Measured memory_bytes: 3656
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    vector<int>a(101,0);
    cin>>n;
    for(int i=0;i<n;i++)cin>> a[i];
    int ans=INT_MAX;
    for(int i=-100;i<=100;i++)
    {
        int cost=0;
        for(int j=0;j<n;j++)
        {
            cost+=(a[j]-i)*(a[j]-i);
        }
        ans=min(ans,cost);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
cnt = 1
output = []
while True:
	data = input().split()
	if data[0] == '0' and data[1] == '0':
		break
	elif int(data[0]) > int(data[1]):
		output += [data[1] + " " + data[0]]
	else:
		output += [data[0] + " " + data[1]]
for line in output:
	print(line)


Measured memory_bytes: 5868
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll a[2000005];
map<ll,ll>mp;
int main()
{
    /*char ch;
    cin >> ch;
    if(ch>='A'&&ch<='Z')
        cout << 'A' << endl;
    else
        cout << 'a' << endl;
    int a[10000];
    int n,k;
    cin >> n>> k;
    for(int i=0;i<n;i++)
        cin >> a[i];
    sort(a,a+n);
    int ans=0;
    for(int i=0;i<k;i++)
        ans+=a[i];
    cout << ans << endl;*/
    /*ll c;
    cin >> c;
    vector<ll>v;

            while(c>0)
            {
                if(c%26==0)
                v.push_back(26);
                else
                v.push_back(c%26);
                //cout << c << endl;
                if(c%26==0)
                    c= c/26-1;
                else
                    c= c/26;

            }

            for(ll i=v.size()-1;i>=0;i--)
            {
                //cout << v[i] << endl;
                printf("%c",v[i]+96);
            }*/
    ll n,sum=0;
    cin >> n;
    for(ll i=0;i<n;i++){
        cin >> a[i];
        mp[a[i]]++;
        sum+=a[i];
    }

    ll q;
    cin >> q;
    while(q--)
    {
        ll b,c;
        cin >> b >> c;
        if(mp.find(b)==mp.end())
        {
            cout << sum << "\n";
            continue;
        }
            sum-=mp[b]*b;
            sum+=mp[b]*c;
            mp[c]+= mp[b];
            mp[b]=0;
            //sum+=mp[c]*c;
            cout << sum << "\n";

    }

}


Measured memory_bytes: 9452
w, h, n = map(int, input().split())

x0, y0, x1, y1 = 0, 0, w, h
for _ in range(n):
    x, y, a = map(int, input().split())
    if a == 1 and x0 <= x:
        x0 = x
    elif a == 2 and x <= x1:
        x1 = x
    elif a == 3 and y0 <= y:
        y0 = y
    elif a == 4 and y <= y1:
        y1 = y

if x1 - x0 <= 0 or y1 - y0 <= 0:
    print(0)
else:
    print((x1 - x0) * (y1 - y0))


Measured memory_bytes: 3064
#include<iostream>
using namespace std;
int main(){
  string s;
  cin>>s;
  char str[s.length()];
  int ii=-1;
  for(int i=0;i<s.length();i++)
  {
     if(s[i]=='B')
    { if(ii!=-1)
      ii--;
    }
    if(s[i]=='0')
    {
      ii++;
      str[ii]='0';
    }
    if(s[i]=='1')
    {
      ii++;
      str[ii]='1';
    }
   
  }
  string strin;
  strin="";
  for(int i=0;i<ii+1;i++)
    strin+=str[i];
  cout<<strin;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <cstdio>

using namespace std;

int main()
{
    if (fopen("Test.INP", "r"))
        freopen("Test.INP", "r", stdin);

    int n;
    cin >> n;

    int dp[n];
    dp[0] = 0;

    int far, pre, now;
    cin >> pre;

    for (int i = 1; i < n; ++i)
    {
        cin >> now;

        dp[i] = dp[i - 1] + abs(now - pre);
        if (i > 1)
            dp[i] = min(dp[i], dp[i - 2] + abs(now - far));

        far = pre; pre = now;
    }

    cout << dp[n - 1];
    return 0;
}


Measured memory_bytes: 640
#include <stdio.h>
                                                                                                
  
int main(void){
                                                                                                
   
    int n, i, j, h, t;
   
    int a[101];
   
      
    scanf("%d", &n);

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

        }

   
    for( j = 0 ; j < n ; j = j + 1 ){

        for( h = j + 1 ; h < n ; h = h + 1 ){

            if( a[j] < a[h] ){

                t = a[j];

                a[j] = a[h];

                a[h] = t;

                }

             }

         }
   

    printf("%d\n", a[0] - a[n - 1] );


    return 0;
                                                          
}

Measured memory_bytes: 128
#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 1e9
#define ALL(v) v.begin(), v.end()

using namespace std;
typedef long long ll;

int main(){
    string keyence = "keyence";
    string s;
    cin >> s;

    int start = 0;
    int end = 0;

    REP(start, s.size()-1){
        FOR(end, start, s.size()){
           if (s.substr(0, start) + s.substr(end, s.size()) == keyence){
               cout << "YES" << endl;
               return 0;
           } 
        }
    }
    cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int maxN = 1e3+7;
const int maxV = 90010;
//const int INF = 1e9+9;
//const ll INF = (1ll)<<60;
const int INF = 2e9+9;
const int MOD = 1e9+7;

int a[maxN];
int p[maxN];
vector<int> c[maxN];
int costs[maxN], cur[maxN];

int main()
{
	string S;
	cin>>S;
	int n = S.size();
	int cnt = 0;
	for(int i=0;i<n;i++)
	{
		if(S[i] == 'o')
		{
			cnt++;
		}	
	} 
	if(cnt + 15 - n >=8)
	{
		puts("YES");
	}
	else
	{
		puts("NO");
	}
	return 0;
}

Measured memory_bytes: 256
def differ(i,ss):
  tos = ["W","B","R"]
  count = 0
  for j in ss:
    if (j != tos[i]):
      count += 1
  return count
[n,m] = list(map(int,input().split()))
ls = []
for i in range(n):
  ls.append(input())
dp = [[0 for i in range(50)] for i in range(3)]
dp[0][0] = differ(0,ls[0])
for i in range(3):
  for j in range(n):
    if j == 0:
      if i == 0:
        dp[i][j] = differ(0,ls[0])
      else:
        dp[i][j] = 100000
    elif i == 0:
      dp[i][j] = dp[i][j-1] + differ(i,ls[j])
    else:
      dp[i][j] = min(dp[i-1][j-1] + differ(i,ls[j]),dp[i][j-1] + differ(i,ls[j]))
print(dp[2][n-1])

Measured memory_bytes: 7784
from collections import deque
[H,W] = list(map(int,input().split()))

S = []
for i in range(H):
    S.append(list(input()))
# print('S:',*S,sep='\n')

out=0
dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]
#スタート・ゴール全探索
for i_s in range(H):
    for j_s in range(W):
        if S[i_s][j_s]!='#':
            # print('S,G:',i_s,j_s,i_g,j_g)
            #BFS
            init = 10**9
            d = [[init] * W for i in range(H)]  #これを更新していく
            # print('d:',*d, sep='\n')
            que = deque([])
            que.append((i_s,j_s))
            d[i_s][j_s] = 0
            while que:
                p = que.popleft()
                for i in range(4):  #四方をチェック
                    nx = p[0] + dx[i]
                    ny = p[1] + dy[i]
                    # print('p,nx,ny,S[nx][ny]:',p,nx,ny,S[nx][ny])
                    if (0<=nx<H)and(0<=ny<W)and(S[nx][ny]!="#")and(d[nx][ny]==init):
                        # print('yahhoooo')
                        que.append((nx, ny))  #後で(nx,ny)の四方みていくよ
                        # print(d[p[0]][p[1]])
                        d[nx][ny] = d[p[0]][p[1]] + 1  #d更新しておくよ
                        out=max(out,d[p[0]][p[1]] + 1)
            # print('d:',*d, sep='\n')
            # print('ゴール',d[i_g][j_g])
# print(out)
print(out)


Measured memory_bytes: 74852
/*  -*- coding: utf-8 -*-
 *
 * a.cc: A - On the Way
 */

#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 */

/* typedef */

/* global variables */

/* subroutines */

/* main */

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

  if ((a < c && c < b) || (b < c && c < a)) puts("Yes");
  else puts("No");
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<string>
using namespace std;
int main()
{
     int x,t=0;
     string n;
    cin>>n;
    long long int i=0;
    while(i<n.length())
    {
       t+=int(n[i])-48;
       i++;
    }
    if(t%9==0)
    cout<<"Yes";
    else
    {
        cout<<"No";
    }
    
}

Measured memory_bytes: 3708
s = {}
s['a'], s['b'], s['c'] = [input() for i in range(3)]

player = 'a'
while True:
    if len(s[player]) == 0:
        break
    first_c = str(s[player])[0]
    s[player] = str(s[player])[1:]
    player = first_c

print(player.upper())

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

#define nax 100009
#define FOR(i,n,m) for(int i =(n);i<(m);i++)
#define REP(i,n) FOR(i,0,n)
#define pb push_back

typedef long long ll; 
typedef vector<ll> vi;

int main(){
	ll n,k, dp[nax]; cin>>n>>k;
	vi v(n);

	REP(i,n) cin>>v[i];
	REP(i,n) dp[i] = 1000000000000LL;
	dp[0] = 0;

	REP(i,n){
		FOR(j,1,k+1){
			if(i+j>=n) break;
			dp[i+j] = min(dp[i]+abs(v[i]-v[i+j]),
						dp[i+j]);
		}
	}

	cout<<dp[n-1];

	return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <set> 
#include <map>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstring>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
typedef long long ll;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
const int MAX_V = 210;

struct edge {int to, cap, rev; };

vector<edge> G[MAX_V];
bool used[MAX_V];

void add_edge(int from, int to, int cap) {
    G[from].push_back((edge){to, cap, (int)G[to].size()});
    G[to].push_back((edge){from, 0, (int)G[from].size()-1});
}

int dfs(int v, int t, int f) {
    if (v==t) return f;
    used[v] = true;
    for (int i = 0; i < G[v].size(); i++) {
        edge &e =  G[v][i];
        if(!used[e.to] && e.cap > 0) {
            int d = dfs(e.to, t, min(f, e.cap));
            if(d > 0) {
                e.cap -= d;
                G[e.to][e.rev].cap += d;
                return d;
            } 
        }  
    }
    return 0;
}

int max_flow(int s, int t) {
    int flow = 0;
    for (;;) {
        memset(used, 0, (int)sizeof(used));
        int f = dfs(s, t, INF);
        if (f==0) return flow;
        flow += f;
    }
}

int main () {

    int n; cin >> n;
    vector<int> a(n), b(n), c(n), d(n);

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

    int s = 2*n, t = s + 1;

    for (int i = 0; i < n; i++) {
        add_edge(s, i, 1);
    }

    for (int i = 0; i < n; i++) {
        add_edge(n+i, t, 1);
    }

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            if(a[i] < c[j] && b[i] < d[j]) {
                add_edge(i, n+j, 1);
            }
        }
    }

    cout << max_flow(s, t) << endl;

    return 0;
}



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

int main()
{

    int n, min_a = 0x7FFFFFFF, max_a = 0;

    int a;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> a;
        min_a = min(min_a, a);
        max_a = max(max_a, a);
    }

    cout << max_a - min_a << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
input=sys.stdin.readline
n=int(input())
a_list=list(map(int,input().split()))
D={}
for i in a_list:
    if not i in D:
        D[i]=1
    else:
        D[i]+=1
count=0
for i in D:
    count+=1
r=n-count
if r%2==0:
    print(count)
else:
    print(count-1)


Measured memory_bytes: 62108
while (input=gets) != nil
    a,b,c,d,e,f = input.split(" ").map{|num| num.to_f}
    d = (a*e-b*d)*1.00
    x = (e*c-f*b)/d
    y = (c-a*x)/b
    puts(sprintf("%.3f %.3f",x+0.0,y+0.0))
end

Measured memory_bytes: 6132
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define MOD 1000000007
ll dp[1001][1001];
ll ans(ll m,ll n){
	if(dp[0][0]==-1){
		return 0;
	}
	for(ll i=0;i<m;i++){
		if(dp[i][0]==-1){
			break;
		}
		dp[i][0] = 1;
	}
	for(ll i=0;i<n;i++){
		if(dp[0][i]==-1){
			break;
		}
		dp[0][i] = 1;
	}
	for(ll i=1;i<m;i++){
		for(ll j=0;j<n;j++){
			if(dp[i][j]==-1){
				continue;
			}
			dp[i][j] = 0;
			if(dp[i-1][j]!=-1){
				dp[i][j] = dp[i-1][j]%MOD;
			}
			if(dp[i][j-1]!=-1){
				dp[i][j] = (dp[i][j] + dp[i][j-1])%MOD;
			}
		}
	}
	if(dp[m-1][n-1]==-1){
		return 0;
	}
	return dp[m-1][n-1];
}
int main(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
	ll m,n;
	cin>>m>>n;
	for(ll i=0;i<m;i++){
		for(ll j=0;j<n;j++){
			char a;
			cin>>a;
			if(a=='.'){
				dp[i][j] = 0;
			}else{
				dp[i][j] = -1;
			}
		}
	}
	cout<<ans(m,n)<<endl;
	return 0;

}

Measured memory_bytes: 11372
#include <bits/stdc++.h>
#define FOR(i,a,b)  for(int (i)=(a);(i)<(b);(i)++)
#define REP(i,n)    FOR(i,0,n)
#define RER(i,n)    FOR(i,0,(n+1))
#define pb          push_back
#define mp(a,b)     make_pair((a),(b))
#define mset(m,v)   memset(m,v,sizeof(m))
using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pair<int, int> > vpii;
typedef long long ll;
typedef vector<ll> vl;
typedef pair<ll,ll> pll;
typedef vector<pair<ll, ll> > vpll;
typedef vector<string> vs;
typedef long double ld;
const double EPS    = 1e-10;
const int INF       = 1e+9;
const double PI     = acos(-1);


auto main() -> int
{
    string a, b;
    cin >> a >> b;

    int res = stoi(a + b);
    REP(i, 10001) {
        if ( res == i * i ) {
            cout << "Yes" << endl;
            return 0;
        }
    }

    cout << "No" << endl;

    return 0;
}



Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <algorithm>

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

using namespace std;

typedef pair<int, int> P;

int area(const P& p){
	int a = p.first;
	int b = p.second;
	return a * b;
}

void split(const P& p, int k, P& s, P& t){
	int a = p.first;
	int b = p.second;
	k %= (a + b) * 2;
	if(k <= a){
		s = P(k, b);
		t = P(a - k, b);
	}
	else if(k <= a + b){
		k -= a;
		s = P(a, k);
		t = P(a, b - k);
	}
	else if(k <= a * 2 + b){
		k -= (a + b);
		s = P(k, b);
		t = P(a - k, b);
	}
	else{
		k -= (a * 2 + b);
		s = P(a, k);
		t = P(a, b - k);
	}
}

int n, w, h;
vector<P> x;

int main(){
	while(scanf("%d%d%d", &n, &w, &h), w){
		x.push_back(P(w, h));
		rep(i, n){
			int a, k;
			scanf("%d%d", &a, &k);
			P p = x[--a];
			x.erase(x.begin() + a);
			P s, t;
			split(p, k, s, t);
			if(area(s) > area(t)){
				swap(s, t);
			}
			x.push_back(s);
			x.push_back(t);
		}

		vector<int> v;
		rep(i, n + 1){
			v.push_back(area(x[i]));
		}
		sort(v.begin(), v.end());
		rep(i, n + 1){
			if(i != 0){
				putchar(' ');
			}
			printf("%d", v[i]);
		}
		putchar('\n');

		x.clear();
	}
	return 0;
}

Measured memory_bytes: 1060
S = list(input())
N = len(S)
if N%4 == 3 or N%4 == 1:
    if S[0:int((N-1)/2)] == S[int((N+1)/2):N]:
        flag = True
        s = S[0:int((N-1)/2)]
        for i in range(N//4):
            if s[i] != s[-i-1]:
                flag=False
        if flag:
            print('Yes')
        else:
            print('No')
    else:
        print('No')    
else:
    print('No')

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

int main() {
  string s;
  cin >> s;
  vector<string> w;
  w.push_back("dreamer");
  w.push_back("dream");
  w.push_back("eraser");
  w.push_back("erase");
  int i = s.size();
  while (i > 0) {
    bool found = false;
    for (int j = 0; j < w.size(); j++) {
      int wl = w[j].length();
      if (wl > i) continue;
      if (s.substr(i - wl, wl) == w[j]) {
        i -= wl;
        found = true;
      }
    }
    if (found) continue;
    cout << "NO" << endl;
    exit(0);
  }
  cout << "YES" << endl;
  return 0;
}


Measured memory_bytes: 512
import java.util.*;

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

        int n = sc.nextInt();
        int[] a = new int[n];
        for(int i = 0;i < n;i++){
            a[i] = sc.nextInt();
        }

        for(int i = 1;i < n;i++){
            if(a[i - 1] != a[i])    System.out.print(a[i - 1]+" ");
        }
        System.out.println(a[a.length - 1]);
    }
}


Measured memory_bytes: 71160
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
#define allr(x) (x).rbegin(),(x).rend()
#define rp(i,s,e) for(int i=(s);i<(e);++i)
#define rpz(i,e) rp(i,0,e)

int main(){
	int N,H; cin>>N>>H;
	vi AB;
	int maxA = 0;
	rpz(i, N){
		int a,b; cin>>a>>b;
		AB.push_back(a);
		AB.push_back(b);
		maxA = max(maxA, a);
	}
	sort(allr(AB));
	int count = 0;
	for(ll i=0; i<AB.size() && H>0 && AB[i]>maxA; ++i){
		H -= AB[i];
		count++;
	}
	if(H > 0) count += (H+maxA-1)/maxA;//round up
	cout<< count <<endl;
}

Measured memory_bytes: 1400
//Bismillahir Rahmanir Rahim
#include<bits/stdc++.h>
using namespace std;
#define ios ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define ll long long
#define endl '\n'
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
bool sortbysec(const pair<ll,ll>&a,const pair<ll,ll>&b)
{
    return (a.second<b.second);
}
const int m=2e5+7;
vector<ll>adj[m];
vector<bool>vis;
vector<ll>ans;
void dfs(ll v)
{
   vis[v]=true;
   for(ll i=0;i<adj[v].size();i++)
   {
       ll k=adj[v][i];
       if(!vis[k])
       {
           ans[k]+=ans[v];
           dfs(k);
       }
   }
}

int main()
{
  ios;
     int n,q;
    cin>>n>>q;
    ans.assign(n,0);
    vis.assign(n,false);
    for(int i=0;i<n-1;i++)
    {
        ll a,b;
        cin>>a>>b;
        a--,b--;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    for(int i=0;i<q;i++)
    {
        ll a,b;
        cin>>a>>b;
        a--;
        ans[a]+=b;
    }
    for(int i=0;i<n;i++)
    {
        if(vis[i])
            continue;
        dfs(i);
    }
    for(int i=0;i<n;i++)
        cout<<ans[i]<<" ";
    cout<<endl;






}
//Alhamdulillah













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

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

ll n,m,x,k,d,i,j,index,flag=0,mini,count=0,result=0,odd,even,sum=0,temp;
//cin>>n;
string s;
cin>>s;
//ll a[200005];
//ll b[200005];
for(i=0;i<3;i++)
{
    if(s[i]=='R')   result++;
}
if(result==0 || result ==1 || result==3)  cout<<result<<endl;
else
{
    if((s[0]=='R' && s[1]=='R') || (s[1]=='R' && s[2]=='R') ) cout<<result<<endl;
    else cout<<1<<endl;
}
    return 0;
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
#define ll long long
#define loop(n) for(ll i = 0; i<n; i++)
#define sort(a) sort(a.begin(), a.end())
using namespace std;

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

    ll n; cin>>n;
    vector<int> dp(3);
    loop(n){
        vector<int> cost(3);
        cin>>cost[0]>>cost[1]>>cost[2];

        vector<int> temp(3,0);
        for(int k = 0; k<3; k++){
            for(int j = 0; j<3; j++){
                if(k!=j) temp[j] = max(temp[j], dp[k]+cost[j]);
            }
        }
        dp = temp;
    }
    cout<<max({dp[0], dp[1], dp[2]})<<"\n";
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#define pb push_back
#define fi first
#define se second
#define mp make_pair
using namespace std;
map<int, int> H[2];
set<int> S[2];
typedef pair<int, int> PII;
typedef long long LL;
vector<PII> V;



inline void Insert(int x, int v){
    H[x][v]++;
    S[x].insert(v);
}
inline void Erase(int x, int v){
    if(H[x][v] == 1) S[x].erase(v);
    H[x][v]--;
}
int N, x, y;
int Rmax, Rmin, Bmax, Bmin, tRmax, tRmin, tBmax, tBmin;
int main()
{
    cin>>N;
    for(int i = 0; i < N; i++){
        scanf("%d %d", &x, &y);
        if(x < y) swap(x, y);
        V.pb(mp(x, y));
    }
    sort(V.begin(), V.end());
    reverse(V.begin(), V.end());
    LL ans = 2e18;
    for(auto x : V){
        Insert(0, x.fi);
        Insert(1, x.se);
    }
    Rmax = Rmin = V[0].fi;
    Bmax = Bmin = V[0].se;
    Erase(0, V[0].fi); Erase(1, V[0].se);
    for(int i = 1; i < V.size(); i++){
        tRmax = Rmax;
        tRmin = Rmin;
        tBmax = Bmax;
        tBmin = Bmin;
        tRmin = min(tRmin, V[i].se);
        tBmax = max(tBmax, V[i].fi); tBmin = min(tBmin, V[i].fi);
        Erase(0, V[i].fi); Erase(1, V[i].se);
        if(S[0].size() > 0){
            tRmin = min(tRmin, *S[1].begin());
            tBmin = min(tBmin, *S[0].begin());
        }
        ans = min(ans, (LL)(tRmax - tRmin)*(tBmax - tBmin));
        Rmin = min(Rmin, V[i].fi);
        Bmax = max(Bmax, V[i].se); Bmin = min(Bmin, V[i].se);
    }
    ans = min(ans, (LL)(Rmax - Rmin)*(Bmax - Bmin));
    cout<<ans<<endl;
}


Measured memory_bytes: 39280
#include<bits/stdc++.h>
#define rep(i,a,n) for (int i = a;i < n;i++)
#define per(i,n,a) for (int i = n-1;i >= a;i--)
using namespace std;

int main() {
    long long x, ans;
    cin >> x;
    ans = (x / 11) * 2;
    if (x % 11 >= 7) {
        ans += 2;
    } else if (x % 11 > 0) {
        ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
n = int(input())
l = [int(input()) for _ in range(n)]

x = sum(l)
y = [i for i in l if i % 10 != 0]

if x % 10 != 0:
    print(x)
else:
    if y ==[]:
        print(0)
    else:
        print(x - min(y))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif
#define int long long
const int INF = 1LL << 60;

signed main(){

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

  int ans = 0;
  for(int i = 0; i < n; i++){
    int right1 = i, right2 = i;
    while(right1+1 < n && a[right1] <= a[right1+1]) right1++;
    while(right2+1 < n && a[right2] >= a[right2+1]) right2++;
    i = max(right1, right2);
    ans++;
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  char X,Y;
  cin >> X >> Y;
  if (X>Y){
    cout << '>' << endl;
  }
  else if (X<Y){
    cout << '<' << endl;
  }
  else {
    cout << '=' << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
 
#define rep(i,z) for(int i = 0; i<(int)(z); i++)
#define rep1(i,z) for(int i = 1; i<=(int)(z); i++)
 
using namespace std;
 
typedef long long ll;
const ll mod=1e9+7;
 
using pear = pair<int,int>;
 
int main(){
    int n; cin >>n;
    vector<int> d(n);
    rep(i,n) cin >>d[i];
    int ans = 0;
    rep(i,n-1)     for(int j = i+1;j < n;j++)   ans += d[i]*d[j];
    cout << ans << endl;
}

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

using namespace std;

int main () {
  int H, A;
  
  cin >> H;
  cin >> A;
  
  int  i = 0;
  while(1) {
    H -= A;
    i++;
    
    if(H <= 0) {
      break;
    }
  }
  
  cout << i << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<string>
#include<math.h>
#include<vector>
#include<iomanip>
using namespace std;

long long int gcd(long long int x, long long int y)
{
	if (y == 0) { return x; }
	return gcd(y, x % y);
}

int main(void)
{
	char a;
	cin >> a;
	cout << char(a + 1) << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template<class T> ostream& operator<<(ostream &os, vector<T> V) {
os << "[ "; for(auto v : V) os << v << " "; return os << "]";}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {
    return os << "(" << P.first << "," << P.second << ")";}

// #define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cout << name << " : " << arg1 << std::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...);
}
#else
#define trace(...) 1
#endif
typedef long long ll;
typedef double ld;
#define pll pair<ll,ll>
#define pii pair<int, int>
#define pb push_back
#define mp(x, y) make_pair((x), (y))
#define F first
#define S second
#define I insert
#define vi vector<int>
#define vll vector<ll>
#define vpll vector<pll>
#define all(x) (x).begin(), (x).end()
#define sz(x) (ll)(x).size()
   
const ll Mod = 1e9 + 7;
const int N = 2007;
ll dp[N][N] , n , m , A[N] , B[N];

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); 
    
    for(int i = 0 ;i < N ; i++){
        dp[0][i] = 1;
        dp[i][0] = 1;
    }

    cin >> n >> m;
    for(int i = 1;i <= n; i++)
        cin >> A[i];
    for(int j = 1 ; j <= m ; j++)
        cin >> B[j];

    for(int i = 1 ;i <= n; i++){
        for(int j =1 ; j <= m ; j++){
            if(A[i] == B[j])
                dp[i][j] = (dp[i-1][j] + dp[i][j-1])%Mod;
            else
                dp[i][j] = (dp[i-1][j] + dp[i][j-1] - dp[i-1][j-1] + Mod)%Mod;
        }       
    }
    cout << dp[n][m] << endl;
    return 0;
}

Measured memory_bytes: 31744
import java.util.Scanner;

class Main {
	public static void main(String args[]) {
		Scanner scanner = new Scanner(System.in);
		long numbef = scanner.nextInt();//要素数
		long numaft = scanner.nextInt();//要素数
		
		gcd_euclid(numbef, numaft);
		
		scanner.close();
	}
	
	public static void gcd_euclid(long numbef, long numaft) {
		  long sub;
		  while (0 != numaft) {
		  	//ユークリッドの互除法
		    sub = numbef % numaft; 
		  	numbef = numaft; 
		  	numaft = sub;
		  }
		  System.out.println(numbef);
		}
}




Measured memory_bytes: 26248
def main():
    n = int(input())
    a = list(map(int, input().split()))
    if n % 2 == 0:
        dp = [[[-10**18]*2, [-10**18]*2] for _ in [0]*(n+1)]
        dp[0][0][0] = 0
        for i in range(n):
            # 使う場合
            dp[i+1][1][0] = max(dp[i+1][1][0], dp[i][0][0]+a[i])
            dp[i+1][1][1] = max(dp[i+1][1][1], dp[i][0][1]+a[i])
            # 使わない場合
            dp[i+1][0][1] = max(dp[i+1][0][1], dp[i][0][0])
            # 更新
            dp[i+1][0][0] = max(dp[i+1][0][0], dp[i][1][0])
            dp[i+1][0][1] = max(dp[i+1][0][1], dp[i][1][1])
        print(max(dp[n][1][1], dp[n][0][0]))
        return
    dp = [[[-10**18]*3, [-10**18]*3] for _ in [0]*(n+1)]
    dp[0][0][0] = 0
    for i in range(n):
        # 使う場合
        dp[i+1][1][0] = max(dp[i+1][1][0], dp[i][0][0]+a[i])
        dp[i+1][1][1] = max(dp[i+1][1][1], dp[i][0][1]+a[i])
        dp[i+1][1][2] = max(dp[i+1][1][2], dp[i][0][2]+a[i])
        # 使わない場合
        dp[i+1][0][1] = max(dp[i+1][0][1], dp[i][0][0])
        dp[i+1][0][2] = max(dp[i+1][0][2], dp[i][0][1])
        # 更新
        dp[i+1][0][0] = max(dp[i+1][0][0], dp[i][1][0])
        dp[i+1][0][1] = max(dp[i+1][0][1], dp[i][1][1])
        dp[i+1][0][2] = max(dp[i+1][0][2], dp[i][1][2])
    print(max(dp[n][1][2], dp[n][0][1]))


main()


Measured memory_bytes: 145900
import functools
N = int(input())
A = [int(x) for x in input().split()]
Ai = sorted([A[i] - i - 1 for i in range(N)])
if N % 2:
  med = N // 2
  ans = functools.reduce(lambda x, y: x + y, [abs(a - Ai[med]) for a in Ai])
else:
  med = N // 2
  ans1 = functools.reduce(lambda x, y: x + y, [abs(a - Ai[med]) for a in Ai])
  ans2 = functools.reduce(lambda x, y: x + y, [abs(a - Ai[med - 1]) for a in Ai])
  ans = min(ans1, ans2)
print(ans)

Measured memory_bytes: 28124
#include<stdio.h>
#define size 100
int main( )
{
    int n , i , num[size] , j , temp , a[size];
    scanf("%d" , &n);
    
    for( i = 1 ; i <= n ; i++)
    {
         scanf("%d" , &num[i]);
         a[i] = num[i] ;
    }
       
    
    for( i = 1 ; i <= n ; i++)
    {
        for( j = 1 ; j < n ; j++)
        {
            if( num[j] > num[j+1])
            {
                 temp = num[j] ;
                 num[j] = num[j+1] ;
                 num[j+1] = temp ;
            }
        }
    }
    
    int count = 0 ;
    for( i = 1 ; i <= n ; i++)
    {
        if( a[i] != num[i] )
            count++ ;
    }
    
    if( count == 0 || count == 2)
        printf("YES\n");
    else 
        printf("NO\n");
    
    return 0;
}


Measured memory_bytes: 2060
import java.util.Scanner;

public class Main {
    public static void main(String [] args) {
        Scanner scanner = new Scanner(System.in);
        String s = scanner.next();
        int win = 0;
        for (int i = 0; i < s.length(); ++i) {
            if (s.charAt(i) == 'o') {
                ++win;
            }
        }
        win += (15 - s.length());
        if (win >= 8) {
            System.out.print("YES");
        } else {
            System.out.print("NO");
        }
    }
}


Measured memory_bytes: 22996
l=input().split()
L,R=int(l[0]),int(l[1])
a=0
if R-L<2019:
    a=2018
    for i in range(L,R):
        n=i%2019
        m=(i+1)%2019
        s=(n*m)%2019
        if s<a:
            a=s
        for j in range(R-i-1):
            s+=n
            s=s%2019
            if s<a:
                a=s
        if a==0:
            break
print(a)

Measured memory_bytes: 3064
import java.util.Scanner;
 
public class Main{
 
    public static void main(String args[]){
 
        Scanner scan = new Scanner(System.in);
        String s = scan.next();
 
        if(s.charAt(0)==s.charAt(1)){
            if(s.charAt(0) != s.charAt(2) && s.charAt(0) != s.charAt(3) && s.charAt(2) == s.charAt(3)){
                System.out.println("Yes");   
            }else{
                System.out.println("No");   
            }
        }else{
            if(s.charAt(0) == s.charAt(2)){
                if(s.charAt(1) == s.charAt(3)){
                    System.out.println("Yes");
                }else{
                    System.out.println("No");
                }
            }else if(s.charAt(0) == s.charAt(3)){
                if(s.charAt(1) == s.charAt(2)){
                    System.out.println("Yes");
                }else{
                    System.out.println("No");
                }
            }else{
                System.out.println("No");
            }
        }
    }
}

Measured memory_bytes: 22996
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		while(sc.hasNext()) {
			int N=sc.nextInt();
			if(N==0) {
				break;
			}
			if(N%1111==0) {
				pl("NA");
			}
			else if(N==6174) {
				pl(0);
			}
			else {
				int counter=0;
				while(N!=6174) {
					counter++;
					N=calc(N);
				}
				pl(counter);
			}
		}
	}
	public static int calc(int a) {
		int[] num=new int[10];
		int[] num2=new int[10];
		for(int i=0; i<4; i++) {
			num[a%10]++;
			num2[a%10]++;
			a/=10;
		}
		int L=0;
		int S=0;
		int tmp=9;
		while(true) {
			if(tmp==-1) {
				break;
			}
			else {
				if(num[tmp]==0) {
					tmp--;
				}
				else {
					num[tmp]--;
					L+=tmp;
					L*=10;
				}
			}
		}
		tmp=0;
		while(true) {
			if(tmp==10) {
				break;
			}
			else {
				if(num2[tmp]==0) {
					tmp++;
				}
				else {
					num2[tmp]--;
					S+=tmp;
					S*=10;
				}
			}
		}
		return L/10-S/10;
	}
	public static void pl(Object o) {
		System.out.println(o);
	}
	public static void pl() {
		System.out.println();
	}
	public static void p(Object o) {
		System.out.print(o);
	}
}


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

int main(){
    double a,b;
    cin>> a >> b;
    cout << round((a+b)/2.0) << endl;
}

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

int n, x = 0, ans = 0;
char s[101];

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

	for (int i = 0; i < n; i++){
		if (s[i] == 'I'){
			x++;
		}
		else{
			x--;
		}

		if (x > ans){
			ans++;
		}
	}

	cout << ans;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int h = scan.nextInt();
		int n = scan.nextInt();
		int[] a = new int[n];

		int sum = 0;
		for(int i = 0; i < n ; i++) {
			a[i] = scan.nextInt();
			sum += a[i];
			if(sum >= 1_000_000_000) {
				break;
			}
		}


		String ans = "Yes";
		if(sum < h) {
			ans = "No";
		}


		System.out.println(ans);

	}

}

Measured memory_bytes: 50168
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <cstring>
#include <string>
#include <sstream>
#include <vector>
#include <deque>
#include <set>
#include <map>
using namespace std;
typedef long long int lli;
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define INF 1000000000
#define IOS ios_base::sync_with_stdio(0); cin.tie(0) //making cin faster
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FOR_R(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define REP(i,n)   FOR(i,0,n)
#define REP_R(i,n)   FOR_R(i,0,n)
#define ALL(x) (x).begin(),(x).end()
#define SIZ(x) ((int)(x).size())

int IsPrime(int);

int main(void)
{
  int n;
  int m;

  int cnt = 0;
  
  scanf("%d\n",&n);

  REP(i,n)
    {
      scanf("%d\n",&m);
      cnt += IsPrime(m);
      
    }

  cout << cnt << "\n";
  
   
  
  
}

int IsPrime(int Nvrbl){int i;if(Nvrbl<2){return 0;}else if(Nvrbl==2){return 1;}else if(Nvrbl%2 ==0){return 0;}for(i=3;i<=sqrt(Nvrbl);i+=2){if(Nvrbl%i==0){return 0;}}return 1;}



Measured memory_bytes: 3148
import java.util.*;
import java.lang.*;
import java.math.*;

public class Main {
	Scanner sc = new Scanner(System.in);

	class p implements Comparable<p>{
		int pos;
		int v;
		
		public int compareTo(p t){
			return t.v - v;
		}
	}

	void run() {
		for (;;) {
			int n = sc.nextInt();
			int w = sc.nextInt();

			if ((n | w) == 0) {
				break;
			}

			p data[] = new p[100/w+ 1];

			for (int i = 0; i < 100 / w + 1; i++) {
				data[i] = new p();
				data[i].pos = i;
			}

			int maxv = 0;
			int maxp = 0;
			for (int i = 0; i < n; i++) {
				int v = sc.nextInt() / w;
				
				data[v].v++;
				maxv = Math.max(data[v].v, maxv);
				maxp = Math.max(v, maxp);
			}
			data = Arrays.copyOf(data, maxp);
			Arrays.sort(data);
			double ans = 0;
			for (int i = 0; i < maxp ; i++) {
				ans += ((double)maxp  - data[i].pos) / (maxp ) * data[i].v / (double)maxv;
			}
			System.out.println(ans+0.01);
		}

	}

	public static void main(String[] args) {
		Main m = new Main();
		m.run();
	}
}

Measured memory_bytes: 12000
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007 

int main() {
	ll n,m;
	cin>>n>>m;
	map<ll,ll>a;
	for(ll i=0;i<n;i++){
		ll x;
		cin>>x;
		x=-x;
		a[x]++;
	}
	for(ll i=0;i<m;i++){
		ll b,c;
		cin>>b>>c;
		a[-c]+=b;
	}
	ll ans=0;
	ll cnt=0;
	for(auto itr=a.begin();itr!=a.end();itr++){
		ll num=itr->first;
		ll val=itr->second;
		cnt+=val;
		ans+=num*val;
		if(cnt>=n){
			ans-=(cnt-n)*num;
			break;
		}
	}
	cout << abs(ans);
	// your code goes here
	return 0;
}

Measured memory_bytes: 16108
program abc057
    use,intrinsic :: iso_fortran_env
    implicit none
    integer(int64):: n,i

    read*, n
    do i=ceiling(sqrt(dble(n))),1,-1
        if (mod(n,i) == 0) then
            print'(i0)', int(log10(dble(max(i,n/i))))+1
            stop
        end if
    end do
end program abc057

Measured memory_bytes: 256
n, q = map(int, input().split())
tree =[[] for i in range(n)]
ans = [0 for i in range(n)]
visited = [0 for i in range(n)]
for i in range(n-1):
  a, b = map(int, input().split())
  a, b = a-1, b-1
  tree[a].append(b)
  tree[b].append(a)
  
for i in range(q):
  a, b = map(int, input().split())
  ans[a-1] += b

visited[0] = 1
stack = [0]
while stack:
  v = stack.pop()
  for c in tree[v]:
    if visited[c]:
      continue
    visited[c] = 1
    ans[c] += ans[v]
    stack.append(c)
    
print(" ".join(str(i) for i in ans))


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

#define REP(i,m,n) for(int i=(m); i<(int)(n); i++)
#define RREP(i,m,n) for(int i=(int)(n-1); i>=m; i--)
#define rep(i,n) REP(i,0,n)
#define rrep(i,n) RREP(i,0,n)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aut(r,v) __typeof(v) r = (v)
#define each(it,o) for(aut(it,(o).begin()); it!=(o).end(); ++it)
#define reach(it,o) for(aut(it,(o).rbegin()); it!=(o).rend(); ++it)
#define fi first
#define se second
#define debug(...) {cerr<<"[L"<<__LINE__<<"] "; _debug(__VA_ARGS__);}

template<typename T1, typename T2> ostream& operator<<(ostream& o, const pair<T1, T2>& p)
{return o<<"("<<p.first<<", "<<p.second<<")";}
template<typename T>string join(const vector<T>&v, string del=", ")
{stringstream s;rep(i,v.size())s<<del<<v[i];return s.str().substr(del.size());}
template<typename T>ostream& operator<<(ostream& o, const vector<T>&v)
{if(v.size())o<<"["<<join(v)<<"]";return o;}
template<typename T>ostream& operator<<(ostream& o, const vector<vector<T> >&vv)
{int l=vv.size();if(l){o<<endl;rep(i,l){o<<(i==0?"[ ":",\n  ")<<vv[i]<<(i==l-1?" ]":"");}}return o;}
template<typename T>ostream& operator<<(ostream& o, const set<T>& st)
{vector<T> v(st.begin(),st.end());o<<"{ "<<join(v)<<" }";return o;}
template<typename T1, typename T2>ostream& operator<<(ostream& o, const map<T1, T2>& m)
{each(p,m){o<<(p==m.begin()?"{ ":",\n  ")<<*p<<(p==--m.end()?" }":"");}return o;}
inline void _debug(){cerr<<endl;}
template<class First, class... Rest>
void _debug(const First& first, const Rest&... rest){cerr<<first<<" ";_debug(rest...);}

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;

const double PI = (1*acos(0.0));
const double EPS = 1e-9;
const ll INF = 0x3f3f3f3f;
const ll INFL = 0x3f3f3f3f3f3f3f3fLL;
const ll mod = 1e9 + 7;

inline void finput(string filename) {
    freopen(filename.c_str(), "r", stdin);
}

int main(){
    ios_base::sync_with_stdio(0);
    // finput("./input");

    int n, k;
    cin >> n >> k;
    vi A(n), dp(k+1, 0);
    rep(i,n) cin >> A[i];

    rep(i,k+1){
        int cnt = 0, lose = 0;
        rep(j,n){
            if(i < A[j]) continue;
            if(!dp[i-A[j]]){
                cnt++;
                lose++;
            } else {
                cnt++;
            }
        }
        if(cnt == 0) dp[i] = 0;
        else if(lose == 0) dp[i] = 0;
        else dp[i] = 1;
    }
    cout << (dp[k] ? "First" : "Second") << endl;
    return 0;
}

Measured memory_bytes: 640
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let k = read::<i64>();
    let s = read::<i64>();

    let mut cnt = 0;
    for i in 0..k+1 {
        for j in 0..k+1 {
            if 0 <= s - i as i64 - j as i64 && s - i as i64 - j as i64 <= k {
                cnt+=1;
            }
        }
    }
    
    println!("{}", cnt);
}


Measured memory_bytes: 4352
import sys

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


def main():
    N, K, *AF = map(int, read().split())
    A = AF[:N]
    F = AF[N:]

    A.sort()
    F.sort(reverse=True)
    C = [a * f for a, f in zip(A, F)]

    def is_ok(cost):
        k = 0
        for i in range(N):
            if C[i] > cost:
                k += (C[i] - cost + F[i] - 1) // F[i]
        return k <= K

    ok = max(C)
    ng = -1
    while ok - ng > 1:
        mid = (ok + ng) // 2
        if is_ok(mid):
            ok = mid
        else:
            ng = mid

    print(ok)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 138776
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define rep2(i,n) for(int i=0;i<=n;i++)
#define repr(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define P pair<long long,long long>
#define uni(e) e.erase(unique(e.begin(),e.end()),e.end())
#define double long double
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; }
int INF=1e10;
int MOD=1e9+7;
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void yesno(T b){if(b)out("yes");else out("no");}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
template<class T> void YESNO(T b){if(b)out("YES");else out("NO");}
template<class T> void noyes(T b){if(b)out("no");else out("yes");}
template<class T> void NoYes(T b){if(b)out("No");else out("Yes");}
template<class T> void NOYES(T b){if(b)out("NO");else out("YES");}
int keta(int a){
  double b=a;
  b=log10(b);
  int c=b;
  return c+1;
}
int gcd(int a,int b){
  if(a%b==0)
    return b;
  return gcd(b,a%b);
}
int lcm(int a,int b){
    return a/gcd(a,b)*b;
}
bool sosuu(int a){
  bool b=1;
  if(a<=1)
    return 0;
  else{
  rep1(i,sqrt(a)-1){
  if(a%(i+1)==0)
  b=0;
  }
  return b;
  }
}
int modpow(int a,int b,int m=MOD){
	if(!b)return 1;	if(b&1)return modpow(a,b-1,m)*a%m;
	int memo = modpow(a,b>>1,m);
	return memo*memo%m;
}
int fact_mod(int n) {
    int f=1; 
for(int i=2;i<n+1;i++) f=f*(i%MOD)% MOD;
    return f;
}
int mod_pow(int x,int n) {
    int res=1;
    while(n>0){
        if(n&1) res=(res*x)%MOD; 
        x=(x*x)%MOD;        
n>>=1; 
    }
    return res;
}
int c_mod(int n, int r) {
    if(r>n-r) r=n-r;
    if(r==0) return 1;
    int a=1;
    rep(i,r) 
a=a*((n-i)%MOD)%MOD;
    int b=mod_pow(fact_mod(r), MOD-2);
    return (a%MOD)*(b%MOD)%MOD;
}
signed main(){
  int a;
  cin>>a;
  vector<int> b(a);
  rep(i,a)
    cin>>b[i];
  int c=0;
  rep(i,a)
    c+=b[i];
  YESNO(c%2==0);
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <string>
#include <set>
#include <iomanip>
#include <unordered_map>
#include <cmath>
#define int long long
#define pii pair<int, int>
typedef long long ll;
using namespace std;

void fast() {
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
}

signed main() {
	fast();
	int n;
	cin >> n;
	vector<int> a(n), c(n);
	for (int i = 0; i < n; i++) cin >> a[i];
	for (int i = 0; i < n; i++) cin >> c[i];
	vector<int> b(n);
	for (int i = 0; i < n; i++) b[i] = a[i] - c[i];
	int cnt = 0;
	int s = 0;
	sort(b.begin(), b.end());
	for (int i = 0; i < n; i++) {
		if (b[i] < 0) {
			cnt++;
			s += b[i];
		}
	}
	for (int i = n - 1; i >= 0 && s < 0; i--) {
		if (b[i] <= 0) break;
		s += b[i];
		cnt++;
	}
	if (s < 0) cout << -1;
	else cout << cnt;
	return 0;
}

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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;

#define INF (1LL << 60)
#define MOD 1000000007

#define REP(i,m,n) for(ll (i)=(m),i_len=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define pb push_back
#define mp make_pair

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

int main()
{
    ll K;
    cin >> K;

    ll sum = 0;
    REP(i,1,K+1) {
        REP(j,1,K+1) {
            REP(k,1,K+1) sum += gcd(gcd(i, j), k);
        }
    }
    PR(sum);

    return 0;
}

/*



*/

Measured memory_bytes: 3584
N, K = [int(x) for x in input().split()]
arr = [0] * (10**5+1)
for _ in range(N):
    a, b = [int(x) for x in input().split()]
    arr[a] += b

remain = K
for i in range(1, 10**5+1):
    if arr[i] != 0:
        remain -= arr[i]
    if remain <= 0:
        print(i)
        exit()

Measured memory_bytes: 5848