akhauriyash/Code-Regression huggingface dataset:
n,Y = map(int,(input().split()))
x = 0
y = 0
z = 0
f = True
for i in range(n+1):
    for j in range(n+1):
        k=Y-i*10000-j*5000
        if k==(n-i-j)*1000 and k>=0:
            x=i
            y=j
            z=int(k/1000)
            f=False
if f :
    x = -1
    y = -1
    z = -1
print(x,y,z)



Measured memory_bytes: 3188
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <list>
#include <ctime>
#include <sstream>
#include <queue>
#include <stack>
#include <random>
#include <bitset>
#include <numeric>
#include <cassert>
using namespace std;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;
#define rep(x, b, e) for(int x=(b); x<(e); ++x)
#define ford(x, b, e) for(int x=((int)(b))-1; x>=(e); --x)
#define all(c) c.begin(),c.end()
#define sz(x) ((int)((x).size()))
#define pb push_back
#define st first
#define nd second
#define mp(x,y) make_pair(x,y)
typedef short int sint;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it) {
	*this << ((it != d.b) ? ", " : "") << *it;
  }
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

const int mod= 1e9+7;
const int nax=2* 1e5 + 5;
int c[nax];
ll dwa[nax];
int n;

int main() {
	ios_base::sync_with_stdio(false);
	cin >> n;
	rep(i,0,n) cin >> c[i];
	sort(c, c+n);
	dwa[0] = 1;
	rep(i,1,nax) {
		dwa[i] = (dwa[i-1] * 2) % mod;
	}
	ll res = 0;
	rep(i,0,n) {
		ll pom = (dwa[i]*c[i]) % mod;
		ll pom2 = ((n-i-1) * dwa[n - i - 2]) % mod;
		res = (res + pom * (pom2 + dwa[n-i-1])) % mod;
	}
	cout << (dwa[n] * res) % mod << endl;
}

Measured memory_bytes: 2560
#include <algorithm>
#include <deque>
#include <iostream>
#include <map>
#include <math.h>
#include <string.h>
#include <vector>

using namespace std;
int main() {
    int X,Y;
    string ans;
    cin >> X >> Y;

    cout << X+Y/2 << endl;
    return 0;
}

Measured memory_bytes: 256
AV = input().split()
BW = input().split()
T = int(input())

if(int(AV[0]) > int(BW[0])):
  T *= -1

a = int(AV[0]) + int(AV[1]) * T
b = int(BW[0]) + int(BW[1]) * T

if(T >=0 and a >= b):
  print('YES')
elif(T <= 0 and a <= b):
  print('YES')
else:
  print('NO')


Measured memory_bytes: 9216
#include<iostream>
#include<vector>
#include<cmath>
#include<numeric>
using namespace std;
int sum(int n);

int main(){
  int N;
  cin >> N;
  vector<int> B(N-1,0);
  for(int i=0;i<N-1;i++)cin >> B.at(i);
  int count=0;
  for(int i=0;i<N-2;i++){
    if(B.at(i)>B.at(i+1))count+=B.at(i+1);
    else count+=B.at(i);
  }
  cout << count+B.at(0)+B.at(N-2) << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sstream>
#include <iostream>
#include <math.h>
#include <time.h>
#include <unistd.h>
#include <algorithm>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <string>
 
#ifndef ONLINE_JUDGE
	#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#else
	#define DEBUG(x) do {} while(0);
#endif
 
#define pb push_back
#define mp make_pair
#define ALL(x) (x).begin(), (x).end()
#define PER(i, N) for(int (i) = (N)-1; (i) >= 0; (i)--)
#define REP(i, N) for(int (i) = 0; (i) < (int)(N); (i)++)
 
using namespace std;
typedef long long ll;
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }

template <typename T, typename U> std::istream&operator>>(std::istream&i, pair<T,U>&p) {i >> p.x >> p.y; return i;}
template<typename T>std::istream&operator>>(std::istream&i,vector<T>&t) {for(auto&v:t){i>>v;}return i;}
template <typename T, typename U> std::ostream&operator<<(std::ostream&o, const pair<T,U>&p) {o << p.x << ' ' << p.y; return o;}
template<typename T>std::ostream&operator<<(std::ostream&o,const vector<T>&t) {if(t.empty())o<<'\n';for(size_t i=0;i<t.size();++i){o<<t[i]<<" \n"[i == t.size()-1];}return o;}
template<typename T> using minheap = priority_queue<T, vector<T>, greater<T>>;
template<typename T> using maxheap = priority_queue<T, vector<T>, less<T>>;
template<typename T> T gcd(T a,T b) { if (a<b) swap(a,b); return b?gcd(b,a%b):a; }

ll n,k;
int sub[222222];
void solve(istream& cin, ostream& cout) {
	cin >> n;
	vector<string> S(n);
	cin >> S;
	sort(ALL(S));
	cout << unique(ALL(S))-S.begin() << endl;
}


int main() {
    ios_base::sync_with_stdio(false);
	cin.tie(nullptr); cout.tie(nullptr);
	solve(cin, cout);
	/*
	{
		istringstream instr("2\n2\n14");
		solve(instr, cout);
	}
 */
	return 0;
}


Measured memory_bytes: 7584
#include<bits/stdc++.h>
using namespace std;
#define fastIO std::ios_base::sync_with_stdio(false); std::cin.tie(0); std::cout.tie(0)
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
typedef double db;
//mt19937 mrand(random_device{}()); 
const ll mod=1000000007;
const int INF = 0x3f3f3f3f;
//int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}

const int maxn = 2e5 + 10; 

int h,w,k;
int mat[11][1005];
vector<int>p;

int get_sum(int x1, int y1, int x2, int y2)
{
	return mat[x2][y2] - mat[x1][y2] - mat[x2][y1] + mat[x1][y1];
}

bool check(int x, int y){
	for(int i = 1; i < (int)p.size(); ++i) {
		//cout << p[i - 1] << " " << x << " " << p[i] << " " << y << " " << get_sum(p[i - 1],x,p[i],y) << endl;
		if(get_sum(p[i - 1],x,p[i],y) > k) return true;
	}

	return false;
}

int main()
{
	//fastIO;
	cin >> h >> w >> k;
	rep(i,1,h + 1) {
		rep(j,1,w + 1){
			scanf("%1d",&mat[i][j]);
		}
	}		
	rep(i,1,h + 1) {
		rep(j,1,w + 1){
			mat[i][j] += mat[i- 1][j] + mat[i][j - 1] - mat[i - 1][j - 1];
		}
	}
	int ans = INT_MAX;
	for(int i = 0; i < (1 << (h - 1)); ++i){
		p.clear(); p.pb(0);
		int now = 0;
		for(int j = 1; j <= h - 1; ++j){
			if(( 1 << (j - 1)) & i) p.pb(j), now++;
		}
		p.pb(h);
		//cout << i << " ";
		//rep(i,0,SZ(p)) cout << p[i] << " ";
		//cout << endl;
		int pre = 0;
		for(int j = 1; j <= w; ++j) {
			if(check(pre,j)) pre = j - 1, now++;
		}
		if(check(pre,w)) now = INT_MAX;
		ans = min(ans,now);
	}
	cout << ans << endl;
	return 0;
}

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

long long n,t,v1,tmp,ans;
long long a[110],b[110],c[110],d[110];
long long lena,lenb,lenc,lend;

inline bool cmp(long long a,long long b)
{
	return a>b;
}

int main()
{
	cin>>n>>t;
	cin>>v1>>a[++lena];
	for(int i=2;i<=n;i++)
	{
		cin>>tmp;
		if(tmp-v1==0)cin>>a[++lena];
		if(tmp-v1==1)cin>>b[++lenb];
		if(tmp-v1==2)cin>>c[++lenc];
		if(tmp-v1==3)cin>>d[++lend];
	}
	sort(a+1,a+lena+1,cmp);
	sort(b+1,b+lenb+1,cmp);
	sort(c+1,c+lenc+1,cmp);
	sort(d+1,d+lend+1,cmp);
	for(int i=1;i<=100;i++)
	{
		a[i]=a[i-1]+a[i];
		b[i]=b[i-1]+b[i];
		c[i]=c[i-1]+c[i];
		d[i]=d[i-1]+d[i];
	}
	for(int i=0;i<=lena;i++)
	for(int j=0;j<=lenb;j++)
	for(int k=0;k<=lenc;k++)
	for(int l=0;l<=lend;l++)
	if(v1*(i+j+k+l)+j+k*2+l*3<=t)
	{
		ans=max(ans,a[i]+b[j]+c[k]+d[l]);
	}
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 256
#!usr/bin/env python3
from collections import defaultdict, deque, Counter, OrderedDict
from functools import reduce, lru_cache
import collections, heapq, itertools, bisect
import math, fractions
import sys, copy

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI1(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline().rstrip())
def LS(): return [list(x) for x in sys.stdin.readline().split()]
def S(): return list(sys.stdin.readline().rstrip())
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def LIR1(n): return [LI1() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]

sys.setrecursionlimit(1000000)
dire = [[1, 0], [0, 1], [-1, 0], [0, -1]]
dire8 = [[1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0], [-1, -1], [0, -1], [1, -1]]
MOD = 1000000007

def main():
    s = S()

    dp = [[0] * 13 for _ in range(len(s) + 1)]
    dp[0][0] = 1

    for i in range(len(s)):
        if s[i] == "?":
            for ch in range(10):
                for j in range(13):
                    dp[i+1][(j * 10 + ch) % 13] += dp[i][j]
        else:
            ch = int(s[i])
            for j in range(13):
                dp[i+1][(j * 10 + ch) % 13] += dp[i][j]

        for j in range(13):
            dp[i+1][j] %= MOD

    print(dp[len(s)][5])

if __name__ == '__main__':
    main()

Measured memory_bytes: 105992
#include<bits/stdc++.h>
// Useful constants
#define INF  (int)1e9
#define EPS   1e-9
#define MOD 1000000007ll
#define PI 3.14159
// for input-output
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
// iteration macros: have advantage of auto-casting and not recomputing arguments
#define REP(i, a, b) \
for (int i = int(a); i <= int(b); i++) // a to b, and variable i is local!
#define TRvi(c, it) \
for (vi::iterator it = (c).begin(); it != (c).end(); it++)
#define TRvii(c, it) \
for (vii::iterator it = (c).begin(); it != (c).end(); it++)
#define TRmsi(c, it) \
for (msi::iterator it = (c).begin(); it != (c).end(); it++)
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define setBit(S, j) (S |= (1 << j))
#define clearBit(S, j) (S &= ~(1 << j))
#define toggleBit(S, j) (S ^= (1 << j))
// input macro
#define in(x,n)   for(int e=0;e<n;e++){ll y;cin>>y;x.pb(y);}
//output macro
#define print(x)    for(auto it:x) cout<<it<<' '; cout<<endl;
#define printii(x)  for(auto it:x) cout<<it.F<<' '<<it.S<<'\t';  cout<<endl;
// shortcut for data type
#define ll long long
#define vi vector<ll>
#define vvi vector<vi>
#define ii pair<ll,ll>
#define pll pair<ll,ll>
#define vii vector<ii>
#define vvii vector<vii>
#define viii vector<pair<ii,ll>>
#define pb push_back
#define ppb pop_back
#define eb emplace_back
#define mp make_pair
#define F first
#define S second
#define uset unordered_set
#define umap unordered_map
//--namespace
using namespace std;
//--useful function
ll gcd(ll a, ll b){ll temp;while (b > 0){temp = a%b;a = b;b = temp;} return a;}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
ll fpow(ll  b, ll exp, ll mod){if(exp == 0) return 1;ll t = fpow(b,exp/2,mod);if(exp&1) return t*t%mod*b%mod;return t*t%mod;}
ll divmod(ll i, ll j, ll mod){i%=mod,j%=mod;return i*fpow(j,mod-2,mod)%mod;}
// --clock funtion
clock_t time_p=clock();
void TimeTaken()
{
    time_p=clock()-time_p;
    cerr<<"Completion time : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
}
// --solve function
void solve() {

}
//--main function
int main(){
	int n,m;
	cin>>n>>m;
	vector <string> s(n);
	REP(i,0,n-1)cin>>s[i];
	REP(i,0,n-1){
		REP(j,1,2)cout<<s[i]<<"\n";
	}
	return 0;

//   TimeTaken();
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int i=0,j=0,d,x[3000],y[3000];
	while(1){
		scanf("%d %d",&x[i],&y[i]);
		if(x[i]==0&&y[i]==0){
			break;
		}
		i++;
	}
	while(1){
		if(x[j]==0&&y[j]==0){
			break;
		}
		if(x[j]>y[j]){
			d=x[j];
			x[j]=y[j];
			y[j]=d;
		}
		printf("%d %d\n",x[j],y[j]);
		j++;
	}
	return 0;
}

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

int main(){
  int e,x;
  while(1){
    cin>>e;
    if(e==0)break;
    int m1=0,m=1000;
    for(int y=0;y*y<=e;y++)
      for(int z=0;z*z*z<=e-y*y;z++){
	x=e-z*z*z-y*y;
	m1=x+y+z;
	if(m>m1)m=m1;
      }
    cout<<m<<endl;
  }
  return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
#define endl '\n'
#define mp make_pair
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp> 
// using namespace __gnu_pbds; 
// #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
typedef long long int ll;


int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n;
   string s;
   cin>>s;
   set<char> st;
   for(int i=0;i<s.size();i++){
      st.insert(s[i]);
   }
   if(st.size()==2) cout<<"Yes";
  else  cout<<"No";
    
    
}


Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
using namespace std;
char s[4010];
int a[3][4010], b[4010];
int main() {
    int n, i, j, k;
    long long ans = 0;
    scanf("%d%s", &n, s);
    for (i = n - 1; i >= 0; i--) {
        if (s[i] == 'R') b[i] = 0;
        if (s[i] == 'G') b[i] = 1;
        if (s[i] == 'B') b[i] = 2;
        for (j = 0; j < 3; j++) a[j][i] = a[j][i + 1];
        a[b[i]][i]++;
    }
    for (i = 0; i < n; i++) {
        for (j = i + 1; j < n; j++) {
            if (b[i] == b[j]) continue;
            int x = 3 - b[i] - b[j];
            ans += a[x][j+1];
            if (j+j-i < n && b[j+j-i]==x) ans--;
        }
    }
    printf("%lld\n", ans);
    return 0;
}


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

int main(){
    ll n;
    cin >> n;
    if(n % 2 == 1){
        cout << 0 << endl;
    } else {
        ll total = 0;
        ll original = 10;
        while(original <= n){
            total += n / original;
            original *= 5;
        }
        cout << total << endl;
    }
}

Measured memory_bytes: 256
use std::io;

fn procon_read<T: std::str::FromStr>() ->  Vec<T> {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).expect("");
    let iter = buf.split_whitespace();
    let mut v: Vec<T> = Vec::new();
    for i in iter {
        v.push(i.parse().ok().unwrap());
    }
    v
}

fn main() {
    println!("{}", (procon_read::<u64>()[0]+1)%2);
}

Measured memory_bytes: 2144
from collections import Counter
import bisect

S = input()
T = input()

ls = len(S)
lt = len(T)

cons = Counter(S)
cont = Counter(T)
dics = {}
dicc = {}

for i in range(ls):
  if S[i] not in dics:
    dics[S[i]] = [i+1]
    dicc[S[i]] = 1
  else:
    dics[S[i]].append(i+1)
    dicc[S[i]] += 1
idx = 0
cic = 0
for t in T:
  if t not in dics:
    print(-1)
    exit()
  i = bisect.bisect_left(dics[t], idx)
  if i == dicc[t]:
    idx = dics[t][0] + 1
    cic += 1
  else:
    idx = dics[t][i] + 1
    
print(cic*ls+idx-1)

Measured memory_bytes: 80224
#include<iostream>
#include<algorithm>
#include<vector>
#include <iomanip>
#include <math.h>
 
using namespace std;
 
int main(){
 
  int n;
  cin >> n;
  
  
  for(int i=1; i<=n; i++){
	int x = i;
    if(x%3==0){
    	cout << " " << i;
    	continue;
    }
    
    while(x>0){
    	if(x%10==3){
      		cout << " " << i;
        	break;
        }
      	x /= 10;
    }
    }
  cout << endl;
  return 0;
}


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

using namespace std;

int main(){
    int n;
    cin >> n;
    vector<bool> a(n), b(n);
    int x;
    cin >> x;
    for(int i = 0; i < x; i++){
        int num;
        cin >> num;
        a[num - 1] = true;
    }
    int y;
    cin >> y;
    for(int i = 0; i < y; i++){
        int num;
        cin >> num;
        b[num - 1] = true;
    }
    int ans = 0, z;
    cin >> z;
    for(int i = 0; i < z; i++){
        int num;
        cin >> num;
        ans += !a[num - 1] || b[num - 1];
    }
    cout << ans << "\n";
}


Measured memory_bytes: 3084
n,*t=map(int,open(0).read().split())
*z,=zip(t[::2],t[1::2])
s=set((a+b)%2for a,b in z)
if len(s)>1:
    print(-1)
    exit()
s,*_=s
d=[2**(38-i)for i in range(39)]+[1]*(s<1)
print(len(d))
print(*d)
for a,b in z:
    x=y=0
    for i in d:
        if abs(a-x)>abs(b-y):
            if a-x>0:
                print('R',end='')
                x+=i
            else:
                print('L',end='')
                x-=i
        else:
            if b-y>0:
                print('U',end='')
                y+=i
            else:
                print('D',end='')
                y-=i
    print()

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

#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define MP make_pair
#define test cout<<"test"<<endl;
#define fi first
#define se second
typedef long long ll;
typedef long double ld;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
void chmin(ll &a,ll b){if(a>b)a=b;}
void chmax(ll &a,ll b){if(a<b)a=b;}
void pmod(ll &a,ll b){a=(a+b)%MOD;}
void pmod(ll &a,ll b,ll c){a=(b+c)%MOD;}
void qmod(ll &a,ll b){a=(a*b)%MOD;}
void qmod(ll &a,ll b,ll c){a=(b*c)%MOD;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
void ans(bool x,ll y,ll z){if(x)cout<<y<<endl;else cout<<z<<endl;}
void ans(bool x,string y,string z){if(x)cout<<y<<endl;else cout<<z<<endl;}   
void debug(vector<vector<ll>>v,ll h,ll w){for(ll i=0;i<h;i++)
{for(ll j=0;j<w;j++)cout<<v[i][j]<<" ";cout<<endl;}};
ll gcd(ll x,ll y){ll r;while((r=x%y)!=0){x=y;y=r;}return y;}
//m.emplace(x,0).fi->second++;

int main(){
  ll i,j,o;
  ll res=0,res1=INF,res2=-INF,buf=0;
  bool judge = true;
  ll n,d;cin>>n>>d;
  cout<<(n+2*d)/(2*d+1)<<endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N, T, total_time=0, extra_time=0;
    cin >> N >> T;
    
    vector<int> t(N);
    for(int i=0; i < N; i++) cin >> t[i];
    
    for(int i=1; i < N; i++) {
        if (0 < T - (t[i]-t[i-1])) extra_time += T - (t[i]-t[i-1]);
    }

    total_time = N * T;
    
    cout << total_time - extra_time << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    istream& in(cin);
    ostream& out(cout);
    int h,w,k;
    in>>h>>w>>k;
    vector<string> s(h);
    for(auto&c:s) in>>c;
    int ANS=INT_MAX;
    fr(b,1<<(h-1)){
        vector<vector<int>> v;
        vector<int> t(1,0);
        int ans{};
        fr(i,h-1){
            if((b>>i)&1){
                ++ans;
                v.emplace_back(move(t));
                t.assign(1,i+1);
            }
            else{
                t.emplace_back(i+1);
            }
        }
        v.emplace_back(move(t));
        int n=v.size();
        vector<int> cnt(n);
        bool F{};
        fr(j,w){
            bool f=false;
            vector<int> tmp(n);
            fr(l,n){
                for(auto i:v[l]) if(s[i][j]=='1') ++tmp[l];
                if(tmp[l]>k){
                    F=true;
                    break;
                }
                if(cnt[l]+tmp[l]>k) f=true;
            }
            if(F) break;
            if(f) ++ans,cnt.swap(tmp);
            else fr(l,n) cnt[l]+=tmp[l];
        }
        if(F) continue;
        ANS=min(ans,ANS);
    }
    cout<<ANS<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " \n"[i == n-1];}
#define INF (1e18)

int main(){   
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll a[8];
    rep(i,0,7) cin >> a[i];
    ll ans = 0;
    ans += a[1];
    // print2(v1,v4);
    ll tt = 0;
    if(a[0] >= 1 && a[3] >= 1 && a[4] >= 1){
        tt += 3;
        tt += 2 * ((a[0]-1)/2) + 2 * ((a[3]-1)/2) + 2 * ((a[4]-1)/2);
    }
    ll tt2 = 2 * (a[0]/2) + 2 * (a[3]/2) + 2 * (a[4]/2);
    ans += max(tt, tt2);
    print(ans);
}


Measured memory_bytes: 256
/* _________________________________________________________________________________________________
  |                                                                                                 |
  |                             Author      : Aditya Ahuja                                          |
  |                             Date        : Sun, 19th Jan 2020                                    |
  |_________________________________________________________________________________________________|
*/
 
#include<bits/stdc++.h>
using namespace std;

#define int long long

#define pb          push_back
#define F           first
#define S           second
#define endl        "\n"
#define rep(i,a,b)  for(int i = a; i < (int)b; i++)
#define req(i,a,b)  for(int i = (int)b - 1; i >= a; i--)
#define all(a)      (a).begin(),(a).end()
#define ret(x)      {cout << x << endl; return;}
#define sz(x)       (int)x.size()
#define type(x)     typeid(x).name()

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<vector<int>> vii;

int gcd(int a, int b) {return b?gcd(b,a%b):a;}

#ifdef LOCAL
	#define wa(x)       cerr << (#x) << " --- " << (x) << endl
	#define pvi(v)      {for(auto it:v) cerr << it << " "; cerr << endl;}
	#define line1	    cerr << "---------------------------" << endl;
#else
	#define wa //
	#define line1 //
	#define pvi //
	#define printf //
#endif

void solve();
signed main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	cout << fixed << setprecision(10);

	int t=1; 
	// cin>>t;
	while(t--) solve();
	return 0;
}

//___________________________________________________________________________________________________

void solve() {

	int n;
	cin >> n;

	vii m(10, vi(10,0));

	rep(i,1,n+1){
		int a = i%10;
		int b = i;
		while(b >= 10) b /= 10;
		// int b = to_string(i)[0] - '0';
		m[a][b]++;
	}

	ll tot = 0;
	rep(i,0,10) rep(j,0,10) tot += m[i][j] * m[j][i];
	ret(tot);
}


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

int n;
char a[110],b[110];

main()
{
	scanf("%d %s %s",&n,&a,&b);
	for(int i=0;i<n;i++)
	{
		int ok=1;
		for(int j=0;i+j<n;j++)
		{
			if(a[i+j]!=b[j])
			{
				ok=0;
				break;
			}
		}
		if(ok==1)
		{
			printf("%d",2*n-(n-i));
			return 0;
		}
	}
	printf("%d",2*n);
}


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

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

    int val;
    std::vector<int> a = {9};   // <- it enables to use unified calculation to derive a distance.
    for(int i = 0; i < n; ++i){
        std::cin >> val;
        a.push_back(val);
    }

    int i = 1, ans = 0;
    std::vector<int>::iterator preItr = a.begin(), currItr = preItr;
    while(a.end() != currItr){
        currItr = std::find(preItr, a.end(), i++);
        ans += std::distance(preItr, currItr) - 1;  // <- this calculation
        preItr = currItr;
    }

/*     int i = 1, ans = 0;
    std::vector<int>::iterator preItr = a.begin(), currItr = std::find(preItr, a.end(), i++);
    while(a.end() != currItr){
        ans += std::distance(preItr, currItr) - 1;  // <- this calculation
        preItr = currItr;
        currItr = std::find(preItr, a.end(), i++);
    }

    ans += std::distance(preItr, currItr) - 1;  // <- this calculation
 */
    if(2 == i && ans == a.size() - 1){
        ans = -1;
    }

    std::cout << ans << std::endl;

    return 0;
}

Measured memory_bytes: 1528
#include<iostream>
#include<cmath>
#include<vector>

using namespace std;

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

  int min_hp = 10000100;
  for(int p=1; p <= 100; p++) {
    int hp = 0;
    for(int i=0; i < n; i++) {
      hp += pow(v[i]-p, 2);
    }
    min_hp = min(min_hp, hp);
  }
  cout << min_hp << endl;
}


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

string s;
int id = 0;
int memo[3] = {0};

int recall();
int solve();

int main() {
  while(1) {
    cin >> s;
    if(s == ".") break;
    cout << solve() << endl;
  }
  return 0;
}

int solve() {
  int ans = 0;
  for(int i = 0; i < 3; ++i)
    for(int j = 0; j < 3; ++j)
      for(int k = 0; k < 3; ++k) {
        id = -1;
        memo[0] = i;
        memo[1] = j;
        memo[2] = k;
        if(recall() == 2) ++ans;
      }
  return ans;
}

int recall() {
  int now = 0, nextn = 0;
  bool option = 0;
  ++id;
  if(s[id] >= '0' && s[id] <= '2') return s[id] - '0';
  if(s[id] >= 'P' && s[id] <= 'R') return memo[s[id] - 'P'];
  if(s[id] == '-') return 2 - recall();
  now = recall();
  if(s[++id] == '+') option = 1;
  nextn = recall();
  ++id;
  if(option) {
    if(now == 2 || nextn == 2) return 2;
    return now + nextn > 0;
  }
  if(now == 0 || nextn == 0) return 0;
  return 1 + (now * nextn == 4);
}


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

#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <stack>
#include <complex>
#include <string>
#include <bitset>
#include <stdio.h>
#include <string.h>
#include <fstream>
#include <iomanip>
#include <assert.h>

using namespace std;
#define el  '\n'
#define ll long long
#define clr(a, b)memset(a,b,sizeof(a))
#define sz(a) (int)(a).size()
const long long N = 102, OO = 0x3f3f3f3f, MOD = (int) 1e9 + 7;

pair<int, int> a[N];
ll dp[N][(int) 1e5 + 2];

class DKnapsack1 {
public:
    void init() {

    }

    void solve(istream &cin, ostream &cout) {
        init();
        int n, totW;
        cin >> n >> totW;
        for (int i = 0; i < n; i++)
            cin >> a[i].first >> a[i].second;

        for (int i = 0; i < n; i++) {
            for (int j = 0; j <= totW; j++) {
                if (i - 1 < 0) {
                    dp[i][j] = (j - a[i].first >= 0) ? a[i].second : 0;
                    continue;
                }
                if (j - a[i].first >= 0)
                    dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - a[i].first] + a[i].second);
                else
                    dp[i][j] = dp[i - 1][j];
            }
        }
        cout << dp[n - 1][totW] << el;
    }
};
int main() {
	ios::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr);
	DKnapsack1 solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


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

struct piece{
  int w,d,S;
  bool operator<(const piece &a)const{
    return this->S<a.S;
  }
};

void renewPiece(int w,int d,piece* p){
  p->w=w;
  p->d=d;
  p->S=w*d;
}

int main(){
  int n,w,d;
  while(cin>>n>>w>>d){
    if(w==0)return 0;
    vector<piece> P;
    piece tmp;
    renewPiece(w,d,&tmp);
    P.push_back(tmp);
    int p,s;
    piece a,b;
    for(int i=0;i<n;i++){
      cin>>p>>s;
      p--;
      s = s % (P[p].w+P[p].d);
      if(s>P[p].w){
	s-=P[p].w;
	renewPiece(P[p].w,P[p].d-s,&a);
	renewPiece(P[p].w,s,&b);
      }else{
	renewPiece(P[p].w-s,P[p].d,&a);
	renewPiece(s,P[p].d,&b);
      }

      if(a.S<b.S){
	tmp = b;
	b = a;
	a = tmp;
      }

      P.erase(P.begin() + p);
      P.push_back(b);
      P.push_back(a);
    }
    sort(P.begin(), P.end());
    for(int i=0;i<P.size()-1;i++){
      cout << P[i].S << " ";
    }
    cout << P[P.size()-1].S<< endl;
  }
}

Measured memory_bytes: 1224
N=int(input())
w=[None]*N
for i in range(N):
  a,b=map(int,input().split())
  w[i]=a,b
w=sorted(w,key=lambda x:x[1])
time=0
for i in range(len(w)):
  if w[i][1]>=time+w[i][0]:
    time+=w[i][0]
  else:
    print("No")
    break
else:
  print("Yes")

Measured memory_bytes: 33352
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a),i##formax=(b);i<i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formax=(b);i>=i##formax;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)
#define show(x) cout<<#x<<" = "<<x<<endl;
#define all(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define perm(c) sort(all(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c)))
#define bitComb(a,n,k) for(int a##x,a##y,a=(1<<k)-1;a<(1<<n);a##x=a&-a,a##y=a+a##x,a=(((a&~a##y)/a##x)>>1)|a##y)
#define uniq(v) sort(all(v));v.erase(unique(all(v)), v.end())
#define bit(n) (1LL<<(n))
#define randInt(l,r) (uniform_int_distribution<ll>(l,r)(rnd))
#define randDouble(l,r) (uniform_real_distribution<double>(l,r)(rnd))
#define dout(d) printf("%.12f\n",d)

typedef long long ll;
typedef __int128_t lll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>ostream& operator<<(ostream& o,const pair<T,Y>& p){return o<<"("<<p.fi<<", "<<p.se<<")";}
template<typename A,size_t N,typename T>void Fill(A (&array)[N],const T&v){fill((T*)array,(T*)(array+N),v);}
lll gcd(lll a,lll b,lll &x,lll &y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll gcd(ll a,ll b){lll x=0,y=0;return gcd(a,b,x,y);}
ll modInv(ll a,ll m){lll x,y;gcd(a,m,x,y);return (x%m+m)%m;}
ll modPow(lll a,lll n,ll m){if(!a)return a;lll p=1;for(;n>0;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return(ll)p;}
bool isPrime(ll n){if(n<2||n%2==0)return n==2;lll t=n-1,d=t/(t&-t);for(lll a:{2,325,9375,28178,450775,9780504,1795265022})if(a%n){for(t=d,a=modPow(a,t,n);t!=n-1&&a!=1&&a!=n-1;a=a*a%n,t=t*2%n);if(a!=n-1&&t%2==0)return 0;}return 1;}
const int IINF = 1e9+6;
const ll LINF = 1e18;
const int MOD = 1e9+7;
const double PI = acos(-1);
const double EPS = 1e-10;
static random_device rd;
static mt19937 rnd(rd());

const int N = 1e5;
string s;
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> s;
  s[5] = ' ';
  s[13] = ' ';
  cout << s << endl;
}

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

constexpr long long mod = 1000000007;
constexpr int sz = 22;

using Mat = array<array<long long, sz>, sz>;
using Vec = array<long long, sz>;
Vec denom;

void init() {
    // (1-x^2)^5 (1-x)^(2*5+1)
    denom.fill(0); denom[0] = 1;
    for (int _ = 0; _ < 5; _++) {
        for (int i = sz-1; i >= 2; i--) {
            denom[i] += mod - denom[i-2];
            denom[i] %= mod;
        }
    }
    for (int _ = 0; _ < 2*5+1; _++) {
        for (int i = 22; i >= 1; i--) {
            denom[i] += mod - denom[i-1];
            denom[i] %= mod;
        }
    }
}

Vec mul(const Mat &m, const Vec &v) {
    Vec res;
    for (int i = 0; i < sz; i++) {
        res[i] = 0;
        for (int j = 0; j < sz; j++) {
            res[i] += m[i][j] * v[j] % mod;
        }
        res[i] %= mod;
    }
    return res;
};

Mat mul(const Mat &a, const Mat &b) {
    Mat res;
    for (int i = 0; i < sz; i++) {
        for (int j = 0; j < sz; j++) {
            res[i][j] = 0;
            for (int k = 0; k < sz; k++) {
                res[i][j] += a[i][k] * b[k][j] % mod;
            }
            res[i][j] %= mod;
        }
    }
    return res;
};

long long solve() {
    long long N; cin >> N;
    N -= 5;
    if (N < 0) return 0;
    Mat m; Vec v;
    v.fill(0); m.fill(v);
    v[0] = 1;
    for (int i = 0; i < sz-1; i++) {
        m[i][0] = (mod - denom[i+1]) % mod;
        if (i+1 < sz) m[i][i+1] = 1;
    }
    while (N) {
        if (N & 1) v = mul(m, v);
        m = mul(m, m);
        N >>= 1;
    }
    return v[0];
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int T; cin >> T;
    init();
    while (T--) cout << solve() << "\n";
    return 0;
}

Measured memory_bytes: 3596
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    //int N;
    string s;
    cin >> s;
    int ans;
    int count1 =0;
    int count2 =0;
    int N;
    N = s.length();
    int i;
    for(i=0;i<N;i++)
    {
        if(s[i] == 'o')
        {
            count1++;
        }
    }
    if(count1 + 15-N>= 8)
    {
        cout << "YES" << endl;
    }
    else
    {
        cout << "NO" << endl;
    }
    //cout <<count1 ;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
using namespace std;
typedef  long long int lint;
typedef pair<int, int> P;
typedef pair<lint, lint> LLP;
typedef pair<char, char>CP;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define llower(v,hoge) *lower_bound(v.begin(), v.end(), hoge)
#define lupper(v,hoge) *upper_bound(v.begin(), v.end(), hoge)
/*
vector<char>al(26);
al = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
vector<char>AL(26);
AL = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
vector<char>NUM(10);
	NUM = { '0','1','2' ,'3' ,'4' ,'5' ,'6' ,'7' ,'8' ,'9' };
*/



int main() {
	string S;
	cin >> S;
	int cnt = 0;
	rep(i, 3) {
		if (S[i] == '1') {
			cnt++;
		}
	}
	cout << cnt << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a),i##formax=(b);i<i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formax=(b);i>=i##formax;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)
#define show(x) cout<<#x<<" = "<<x<<endl;
#define all(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define perm(c) sort(all(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c)))
#define bitComb(a,n,k) for(int a##x,a##y,a=(1<<k)-1;a<(1<<n);a##x=a&-a,a##y=a+a##x,a=(((a&~a##y)/a##x)>>1)|a##y)
#define uniq(v) sort(all(v));v.erase(unique(all(v)), v.end())
#define bit(n) (1LL<<(n))
#define randInt(l,r) (uniform_int_distribution<ll>(l,r)(rnd))
#define randDouble(l,r) (uniform_real_distribution<double>(l,r)(rnd))
#define dout(d) printf("%.12f\n",d)

typedef long long ll;
typedef __int128_t lll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>ostream& operator<<(ostream& o,const pair<T,Y>& p){return o<<"("<<p.fi<<", "<<p.se<<")";}
template<typename A,size_t N,typename T>void Fill(A (&array)[N],const T&v){fill((T*)array,(T*)(array+N),v);}
lll gcd(lll a,lll b,lll &x,lll &y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll gcd(ll a,ll b){lll x=0,y=0;return gcd(a,b,x,y);}
ll modInv(ll a,ll m){lll x,y;gcd(a,m,x,y);return (x%m+m)%m;}
ll modPow(lll a,lll n,ll m){if(!a)return a;lll p=1;for(;n>0;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return(ll)p;}
bool isPrime(ll n){if(n<2||n%2==0)return n==2;lll t=n-1,d=t/(t&-t);for(lll a:{2,325,9375,28178,450775,9780504,1795265022})if(a%n){for(t=d,a=modPow(a,t,n);t!=n-1&&a!=1&&a!=n-1;a=a*a%n,t=t*2%n);if(a!=n-1&&t%2==0)return 0;}return 1;}
const int IINF = 1e9+6;
const ll LINF = 1e18;
const int MOD = 1e9+7;
const double PI = acos(-1);
const double EPS = 1e-10;
static random_device rd;
static mt19937 rnd(rd());

const int N = 1e5;
ll n, m, d[N], c[2];
V<int> e[N];
bool z;
void dfs(int a, int f){
  d[a] = f;
  for(int b:e[a]){
    if(d[b]){
      if((f-d[b])%2 == 0) z = true;
    }else{
      dfs(b, f+1);
    }
  }
}
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n >> m;
  FOR(_, 0, m){
    int a, b;
    cin >> a >> b;
    a--; b--;
    e[a].pb(b);
    e[b].pb(a);
  }
  dfs(0, 1);
  if(z){
    cout << n*(n-1)/2-m << endl;
    return 0;
  }
  FOR(i, 0, n) c[d[i]%2]++;
  cout << c[0]*c[1] - m << endl;
}

Measured memory_bytes: 7296
import sys
input=sys.stdin.readline
from collections import deque
#グラフの連結成分を調べる
def Graph(ab):
    G=[[] for i in range(n)]
    for a,b in ab:
        G[a-1].append(b)
        G[b-1].append(a)
    return G

n, q = map(int,input().split())
ab = [list(map(int,input().split())) for i in range(n - 1)]
px = [list(map(int,input().split())) for i in range(q)]

G = Graph(ab)
ki = [0] * n

for i in range(q):
    root, score = px[i]
    ki[root - 1] += score

q = deque()
q.append((1, -1))

while q:
    v, p = q.popleft()
    for next in G[v - 1]:
        if next == p:continue
        ki[next - 1] += ki[v - 1]
        q.append((next, v))
print(*ki)

Measured memory_bytes: 134640
#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL); 

#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define in insert
#define ld long double


#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...) 1
#endif
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 << ")";}
template <typename T,typename U>pair<T,U> operator+(const pair<T,U> & l,const std::pair<T,U> & r) { return {l.first+r.first,l.second+r.second};}
typedef long long int ll;
#define int ll
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
const ll mod =1e18;
const ll MAX_NODES =200001;
const ll MAX_LOG =50;
const ll maxn = 100000+1;

int32_t main()
{ 

  IOS 
    int n,k;
    cin>>n>>k;
    int a[n+1][65];
    for(int i = 1;i<=n;i++){
      cin>>a[i][0];
    }
    for(int j = 1;j<=60;j++){
      for(int  i = 1;i<=n;i++)
        a[i][j] = a[a[i][j-1]][j-1];
    }
    int cur = 1;
    for(int i = 0;i<=60;i++){
      if((k>>i)&1){
        cur = a[cur][i];
      }
    }
    cout<<cur<<endl;


  

  




}


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

using namespace std;

typedef pair<double,double> P;

int main(){
    int n;cin>>n;
    vector<P> v(n);
    for(int i=0;i<n;i++){
        double x,y;cin>>x>>y;
        v[i]=P(x,y);
    }
    double cx,cy,ma=-1;
    for(int i=0;i<n;i++){
        for(int j=i;j<n;j++){
            double x1=v[i].first,y1=v[i].second,x2=v[j].first,y2=v[j].second;
            double tmp=(x2-x1)*(x2-x1)+(y2-y1)*(y2-y1);
            if(tmp>ma){
                ma=tmp;
                cx=(x1+x2)/2;cy=(y1+y2)/2;
            }
        }
    }
    bool flag=true;
    for(int i=0;i<n;i++){
        double x1=v[i].first,y1=v[i].second;
        bool ftmp=false;
        for(int j=0;j<n;j++){
            double x2=v[j].first,y2=v[j].second;
            if(cx==(x1+x2)/2 && cy==(y1+y2)/2) ftmp=true;
        }
        flag&=ftmp;
    }
    if(flag)cout<<fixed<<setprecision(10)<<cx<<" "<<cy<<endl;
    else cout<<"NA"<<endl;
}

Measured memory_bytes: 3256
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(begin, i, end) for (int i = begin; i < (int)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

int main()
{
    ll N;
    cin >> N;
    if (N % 1000 == 0)
    {
        cout << 0 << endl;
    }
    else
    {
        cout << (N / 1000 + 1) * 1000 - N << endl;
    }
}

Measured memory_bytes: 3644
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
using namespace std;

int main(){
  long a, b;
  string result = "";

  cin >> a >> b;

  if((a * b) % 2 == 1)
    result = "Yes";
  else
    result = "No";
    

  cout << result << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i,l,r) for(ll i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define RFOR(i,l,r) for(ll i=(l);i>=(r);--i)
#define RREP(i,n) RFOR(i,n-1,0)
#define RREPS(i,n) RFOR(i,n,1)
#define pb push_back
#define eb emplace_back
#define SZ(x) ((ll)(x).size())
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
template<class T = ll> using V = vector<T>;
template<class T = ll> using VV = V<V<T>>;
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true; }return false; }
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true; }return false; }
inline void Yes(bool b = true) {cout << (b ? "Yes" : "No") << '\n';}
inline void YES(bool b = true) {cout << (b ? "YES" : "NO") << '\n';}
inline void err(bool b = true) {if(b) {cout << -1 << '\n'; exit(0);}}
template<class T> inline void fin(bool b = true, T e = 0) {if(b) {cout << e << '\n'; exit(0);}}
template<class T> T Roundup_div(T x, T y) {return (x+(y-1))/y;}
const ll INF = 1e18;
template <typename T>
T pow(T a, long long n, T e = 1) {
    T ret = e;
    while (n) {
        if (n & 1) ret *= a;
        a *= a;
        n >>= 1;
    }
    return ret;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n; cin >> n;
    V<> a(n);
    REP(i,n) cin >> a[i];
    sort(all(a));
    if(a[n-1] - a[0] > 1){
        cout << "No" << endl;
        return 0;
    }
    if(a[0] == a[n-1]){
        Yes(a[0] == n - 1 or a[0] * 2 <= n);
    
    }
    else{
        int m = lower_bound(all(a), a[n-1]) - a.begin();
        Yes(m < a[n-1] and 2 * a[n-1] - n - m <= 0);
    }
}

Measured memory_bytes: 3928
# E - Logs
import sys
sys.setrecursionlimit(1000000)

N,K = map(int,input().split())
A = list(map(int,input().split()))

def rec(l,r):
    global N,K,A
    if l==r:
        return l
    tmp = (l+r)//2
    ans = 0
    for i in range(N):
        ans += (A[i]-0.001)//tmp
    if ans<=K:
        return rec(l,tmp)
    else:
        return rec(tmp+1,r)
    
print(rec(1,max(A)))

Measured memory_bytes: 104568
#include <bits/stdc++.h>
using namespace std;
int main(){
	string s,t;int q,i,k,f;char c;
	cin>>s>>q;
	for(i=0;i<q;i++){
		cin>>k;
		if(k==1)swap(s,t);
		else{
			cin>>f>>c;
			if(f==1)t+=c;else s+=c;
		}
	}
	reverse(t.begin(),t.end());
	t+=s;
	cout<<t;
}

Measured memory_bytes: 1128
N=int(input())
A=[int(x) for x in input().split()]
ans=abs(A[-1])
A=[0]+A+[0]
diff=[0 for x in range(N)]
for i in range(1,N+1):
  dif=abs(A[i]-A[i-1])+abs(A[i]-A[i+1])-abs(A[i-1]-A[i+1])
  ans+=abs(A[i]-A[i-1])
  diff[i-1]=dif

for i in range(N):
  print(ans-diff[i])


Measured memory_bytes: 14176
n, m, x = [int(e) for e in input().split()]

import numpy as np

all = np.zeros(n*(m+1)).reshape(n,m+1)

for i in range(n):
    all[i] += [int(e) for e in input().split()]

bool_list = np.array([])
a = []
b = []
def make(n):
    if len(a) == n:
        b.append([0 for _ in range(n)])
        for i,v in enumerate(a) :
            if v == True:
                b[-1][i] = True
            else:
                b[-1][i] = False
    else:
        for i in [True,False]:
            a.append(i)
            make(n)
            a.pop()

make(n)
c=np.array(b)

dp=10**10

for i in c:
    if (all[i][:,1:].sum(axis = 0) >=x).all() :
        dp = min(dp,all[i][:,0].sum(axis = 0))

if dp ==10**10:
    dp = -1
print(int(dp))

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

struct Work {
  int take;
  ll limit;

  bool operator<(const Work& rhs) const { return limit < rhs.limit; }
};

int main() {
  int n;
  cin >> n;
  vector<Work> w(n);
  for (int i = 0; i < n; i++) cin >> w[i].take >> w[i].limit;

  sort(w.begin(), w.end());

  int t = 0;
  for (int i = 0; i < n; i++) {
    t += w[i].take;
    if (t > w[i].limit) {
      cout << "No" << endl;
      return 0;
    }
  }

  cout << "Yes" << endl;
}


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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = ((int)(n)-1); i >= 0; i--)
#define all(x) (x).begin(),(x).end()
 
using namespace std;
using ll = long long;
 
struct edge { int to, cost; };
 
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> P;
 
const int INF = ~(1<<31);
const int MOD = 1e9+7;
const double EPS = 1.0e-10;
const double PI = acos(-1.0);
 
const int mx4[] = {0,1,0,-1};
const int my4[] = {1,0,-1,0};
const int mx8[] = {0,1,1,1,0,-1,-1,-1};
const int my8[] = {1,1,0,-1,-1,-1,0,1};

int main()
{
	string s;
	cin >> s;
	int cnt = 0;
	for (int i = 0; i < s.size()/2; i++) {
		if (s[i] != s[s.size()-i-1]) cnt++;
	}
	cout << cnt << endl;
	return 0;
}


Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))+[0]
b=[0]*(n+1)
b[0]=1-a[0]
r=sum(a)-a[0]-a[1]
for i in range(1,n+1):
    b[i]=min(r,b[i-1]*2-a[i])
    r-=a[i+1]
if any(i<0 for i in b):print(-1)
else:print(sum(a)+sum(b))

Measured memory_bytes: 666724
a, b, c = (int(x) for x in input().split())
if a == b:
    if c != a:
        print('Yes')
    else:
        print('No')
elif a == c:
    if b != a:
        print('Yes')
    else:
        print('No')
elif b == c:
    if a != b:
        print('Yes')
    else:
        print('No')
else:
    print('No')

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

int N;
bool ada = false;

int main (){
    cin >> N;
    for(int i=1; i<=9; i++) {
        for(int j=1; j<=9; j++) {
            if(i*j ==N) {
                ada = true;
            }
        }
    }
    if(ada) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

//pi

Measured memory_bytes: 3616
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
#define FOR(i,a,b) for(int (i)=(a);(i)<=(b);(i)++)
#define rep(i,n) FOR(i,0,n-1)
#define int long long


signed main(){
	
	int n;cin >> n;
	string s;cin >> s;
	int ans = 0;
	rep(i,n)
	{
		int m[30];
		rep(j,28) m[j]=0;
		int cnt=0;
		rep(l,i)m[s[l]-'a']=1;
		
		FOR(r,i,n-1) if(m[s[r]-'a'])
		{
			m[s[r]-'a']--;
			cnt++;			
		}
		ans = max(ans,cnt);
	}
	cout << ans << endl;
}

//cout << ans << endl;

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define N 500005
using namespace std;
int n,D,Q,x;
int sum[N],d[N],low[N];
int main()
{
    scanf("%d%d",&n,&sum[0]); int x=0;	
    for (int i=1;i<=n;i++){
    	scanf("%d",&d[i]);
    	sum[i]=min(sum[i-1],abs(sum[i-1]-d[i]));
    }
    low[n+1]=1; for (int i=n;i>0;i--){low[i]=low[i+1];if (d[i]<low[i]*2) low[i]+=d[i];} 
    scanf("%d",&Q); while (Q--){
    	scanf("%d",&x);
    	if (low[x+1]<=sum[x-1]) puts("YES");
    	else puts("NO");
    }
    return 0;
}

Measured memory_bytes: 7808