akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
 
typedef long long int ll;
typedef vector<long long>lve;
typedef vector<pair<ll,ll> > lvp;
typedef vector<vector<int> > ivve;
 
#define sp         ' '
#define endl       '\n'
#define F          first
#define S          second
#define pp         pop_back`
#define pb         push_back
#define mp         make_pair 
#define GCD(x,y)   __gcd(x,y)
#define lb         lower_bound
#define up         upper_bound
#define setp       setprecision
#define bs         binary_search
#define all(x)     x.begin(),x.end()
#define LCM(x,y)   ((x*y)/__gcd(x,y))
#define spc(x)     cout<<fixed<<setp(x)
 
const   long long  inf = 1e18;
const   long long  cs =  200005;
const   long long  mod = 1000000007;
const   double     PI =  2 * acos(0.0);
void solve()
{
    ll t,n,m,a,b,c,d,e,i,j,k,x,y,z,cnt=0,cnt1=0;
    bool flag = false;  
 
    cin>>n;
    if(n==1LL) cout<<0<<endl;
    else cout<<1<<endl;
}
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);    cout.tie(NULL);
 
    // freopen ("input.txt","r",stdin);
    // freopen ("output.txt","w",stdout);
 
    // int32_t tc;
    // cin>>tc;
    // while(tc--)
    solve();
 
    return 0;
}

Measured memory_bytes: 3644
#include<iostream>
#include<vector>
#include<numeric>

int main()
{	unsigned long long n;
	std::cin >> n ;
	std::vector<unsigned long long> vec;

	for(unsigned int i = 0; i < n ; ++i)
	{
		unsigned long long q;
		std::cin >> q ;
		vec.push_back(q);
	}
	unsigned long long local_sum = 0;	
	unsigned long long sum=0;
	for(unsigned int i = 0 ; i < vec.size(); ++i)
	{
		sum += local_sum*vec[i];
		sum %= 1000000007;
		local_sum += vec[i];
		local_sum%= 1000000007;		
	}
	std::cout << sum%1000000007 << std::endl;
	
}


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

int main(){
	int A,B,C;
	cin >> A >> B >> C;
	if(A-B>C){
		cout << 0 << endl;
	}else{
		cout << C - (A-B) << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#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)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template<typename T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T& a,T b){if(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U& u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U& u,const V... v){for(auto& e:u)fill_v<T>(e,v...);}

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

    int n;
    cin >> n;
    int k = 0;
    for (int i = 1; i * (i-1) <= 2 * n; ++i) {
        if (i * (i-1) == 2 * n) k = i;
    }
    if (k == 0) {
        puts("No");
        return 0;
    }
    auto ans = make_vec<int>(k, 0);
    int num = 1;
    rep(i, k) {
        for (int j = i+1; j < k; ++j) {
            ans[i].push_back(num);
            ans[j].push_back(num);
            num++;
        }
    }
    cout << "Yes" << endl;
    cout << k << endl;
    rep(i, k) {
        cout << k-1 << " ";
        rep(j, k-1) cout << ans[i][j] << (j == k-2 ? '\n' : ' ');
    }
}


Measured memory_bytes: 4184
#include<bits/stdc++.h>
#define maxn 3005
#define LL long long
using namespace std;
typedef long long ll;
const int N=2e5;
map<string,ll> mmap;
string a;
int main()
{
    int n;
    ll sum=0;

    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a;
        sort(a.begin(),a.end());
        if(mmap[a]){
            sum+=mmap[a];
            mmap[a]=mmap[a]+1;
        }
        else mmap[a]=1;
        //cout<<a[i]<<endl;
    }

    cout<<sum;
}


Measured memory_bytes: 11136
#include<bits/stdc++.h>
#define rep(i,start,lim) for(lld i=start;i<lim;i++)
#define repd(i,start,lim) for(lld i=start;i>=lim;i--)
#define scan(x) scanf("%lld",&x)
#define print(x) printf("%lld ",x)
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define br printf("\n")
#define sz(a) lld((a).size())
#define YES printf("YES\n")
#define NO printf("NO\n")
#define all(c) (c).begin(),(c).end()
#define INF         1011111111
#define LLINF       1000111000111000111LL
#define EPS         (double)1e-10
#define MOD         1000000007
#define PI          3.14159265358979323
using namespace std;
typedef long double ldb;
typedef long long lld;
lld powm(lld base,lld exp,lld mod=MOD) {lld ans=1;while(exp){if(exp&1) ans=(ans*base)%mod;exp>>=1,base=(base*base)%mod;}return ans;}
lld ctl(char x,char an='a') {return (lld)(x-an);}
char ltc(lld x,char an='a') {return (char)(x+an);}
#define bit(x,j) ((x>>j)&1)
typedef vector<lld> vlld;
typedef pair<lld,lld> plld;
typedef map<lld,lld> mlld;
typedef set<lld> slld;
#define sync ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define mxm(a,b) a = max(a,b)
#define mnm(a,b) a = min(a,b)
#define endl '\n'
#define fre freopen("1.in","r",stdin); freopen("1.out","w",stdout);
#define N 1000005
int main()
{
    //sync;
    lld a,b;
    cin>>a>>b;
    rep(i,1,999) {
        lld tmp1 = (i*(i+1))/2;
        lld tmp2 = ((i+2)*(i+1))/2;
        if(tmp1-a==tmp2-b) {
            cout<<(tmp1-a);
            return 0;
        }
    }
    return 0;
}

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

#define rep(i,n) for(ll i = 0; i < n; i++)
#define per(i,n) for(ll i = n-1; i >= 0; i--)
#define REP(i,n) for(ll i = 1; i < n; i++)
#define PER(i,n) for(ll i = n; i >= 1; i--)
#define sz(x) int(x.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define endl '\n'
#define fi first
#define se second
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vii = vector<vi>;
using vl = vector<ll>;
using vll = vector<vl>;
using vs = vector<string>;
using vb = vector<bool>;
using vc = vector<char>;
using vcc = vector<vc>;
using vP = vector<P>;
using vPP = vector<vP>;
using vPl = vector<Pl>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll &a, const ll &b){return ((a)+(b)-1)/b;}
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; }



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

  string s;
  int k;
  cin >> s >> k;
  set<string> st;
  int n = sz(s);
  rep(i,n) {
    for(int j = 1; j <= 5 && i+j <= n; j++) {
      st.insert(s.substr(i,j));
    }
  }
  for(string t : st) {
    if(k == 1) {
      cout << t << endl;
      return 0;
    }
    k--;
  }
}

Measured memory_bytes: 1664
class Combination:
    def __init__(self, n_max, mod=998244353):
        self.mod = mod
        self.modinv = self.make_modinv_list(n_max)
        self.fac, self.facinv = self.make_factorial_list(n_max)

    def __call__(self, n, r):
        return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod

    def make_factorial_list(self, n):
        fac = [1]
        facinv = [1]
        for i in range(1, n+1):
            fac.append(fac[i-1] * i % self.mod)
            facinv.append(facinv[i-1] * self.modinv[i] % self.mod)
        return fac, facinv

    def make_modinv_list(self, n):
        modinv = [0] * (n+1)
        modinv[1] = 1
        for i in range(2, n+1):
            modinv[i] = self.mod - self.mod//i * modinv[self.mod%i] % self.mod
        return modinv

def main():
    n,m,k=map(int,input().split())
    mod=998244353
    modPow=[1]
    mPow=1
    ans=0
    if n==1:
        print(m)
    elif m==1:
        if k==n-1:
            print(1)
        else:
            print(0)
    else:
        comb=Combination(n-1)
        for i in range(n-1):
            mPow=(mPow*(m-1))%mod
            modPow.append(mPow)
        for i in range(n-1-k,n):
            ans+=(((m*modPow[i])%mod)*comb(n-1,i))%mod
        print(ans%mod)
if __name__=="__main__":
    main()

Measured memory_bytes: 40676
#include<stdio.h>
#include<string.h>
struct pp{
  char name[100];
  int t;
};

int main(void){

  int q,head,tail,n;
  int st=0;
  int i=0;
  
  scanf("%d %d", &n, &q);
  
  int c=n;
  
  struct pp P[n+1];
  
  while(c--)
  {
  	scanf("%s %d",&P[i].name,&P[i].t);
  	i++;
  }

  for ( head=0,tail=n;head!=tail;head=(head+1)%(n+1))
  {
 	i=head;
 	
 	if(P[i].t>q)
 	{
 		st+=q;
 		
 		P[tail].t=P[i].t-q;
 		strcpy(P[tail].name,P[i].name);
 		
 		tail=(tail+1)%(n+1);
 	}
 	else
 	{
 		st+=P[i].t;
 		printf("%s %d\n",P[i].name,st);
 		
 		P[i].t=0;
 	}

  }
  return 0;
}


Measured memory_bytes: 6772
#include <bits/stdc++.h>
//----***やべーやつら***----
using namespace std;
#define int long long

//----***型定義***----
using ll = long long;
using pll = pair<ll, ll>;
using pdd = pair<double, double>;
typedef long double lb;
typedef long double ld;
typedef pair<int,int> P;

//----***Like a Pythonista***----
#define REP(ii,jj,nn) for (ll ii=jj;ii<(nn);ii++)
#define RREP(ii,nn,jj) for (ll ii = nn; jj<ii;ii--)
#define each(i,...) for (auto&& i:__VA_ARGS__)
#define ALL(vec) (vec).begin(),(vec).end()
#define sum(...) accumulate(ALL(__VA_ARGS__),0LL)
#define dsum(...) accumulate(ALL(__VA_ARGS__),0.0L)
#define vec(type,name,...) vector<type> name(__VA_ARGS__)
template<class T> inline auto max(const T& a){ return *max_element(ALL(a)); }
template<class T> inline auto min(const T& a){ return *min_element(ALL(a)); }
inline ll gcd(ll a,ll b){if(b == 0) return a;return  gcd(b,a%b);}
inline ll lcm(ll a,ll b){ll g = gcd(a,b);return a / g * b;}

//----***定数***----
#define MOD 1e9+7;
#define INF 1e9;
#define EPS 1e-9;

//----***入出力***---
#define print(out) cout<< out  << "\n";
#define debug(var)  do{std::cerr << #var << " ↓ "<<"\n";view(var);}while(0);
#define dbg cerr<<"🥺🥺🥺🥺🥺🥺"<<endl;
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }

//----***初期時読み込み***----
struct initial{initial(){cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);};}initial_;


signed main(){
  int N,M,a,b;cin>>N>>M;
  vector<vector<int> > G(N);
  REP(i,0,M){
    cin>>a>>b;
    a--;b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  bool flg=false;
  each(e1,G[0])each(e2,G[e1]){
    if(e2==N-1)flg=true;
  }
  if(flg)print("POSSIBLE")
  else print("IMPOSSIBLE")
}


Measured memory_bytes: 12776
#!usr/bin/env python3
from collections import defaultdict
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A

#B

#C

#D
def root(x):
    if x == par[x]:
        return x
    par[x] = root(par[x])
    return par[x]

def same(x,y):
    return root(x) == root(y)

def unite(x,y):
    x = root(x)
    y = root(y)
    if rank[x] < rank[y]:
        par[x] = y
    else:
        par[y] = x
        if rank[x] == rank[y]:
            rank[x] += 1
n = I()
v = LIR(n)
l = [None for i in range(2*n-2)]
for i in range(n):
    v[i].append(i)
par = [i for i in range(n)]
rank = [0 for i in range(n)]
v.sort(key = lambda x:x[0])
for i in range(n-1):
    l[i] = [v[i][2],v[i+1][2],v[i+1][0]-v[i][0]]
v.sort(key = lambda x:x[1])
for i in range(n-1):
    l[i+n-1] = [v[i][2],v[i+1][2],v[i+1][1]-v[i][1]]
l.sort(key = lambda x:x[2])
k = 0
ans = 0
for i in range(2*n-2):
    x,y,c = l[i]
    if not same(x,y):
        k += 1
        ans += c
        unite(x,y)
    if k == n-1:break
print(ans)
#E

#F

#G

#H

#I

#J

#K

#L

#M

#N

#O

#P

#Q

#R

#S

#T


Measured memory_bytes: 61520
#include <stdio.h>
#include <stdlib.h>

int main()
{
    char a,b;
    scanf("%c %c",&a,&b);
    if(a == 'H' && b == 'H')
        printf("H");
    else if(a == 'H' && b == 'D')
        printf("D");
    else if(a == 'D' && b == 'D')
        printf("H");
    else if(a == 'D' && b == 'H')
        printf("D");
    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
#define pii pair<int,int> 
#define pb push_back
#define INF INT_MAX 
#define mod 1000000007ll
#define fi first
#define se second
#define f(i,p,q) for(int i=p;i<q;i++)
#define si(a) scanf("%d",&a)
#define sii(a,b) scanf("%d %d",&a,&b)
#define siii(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define pi(a) printf("%d\n",a)
#define psi(a) printf(" %d",a)
#define poi(a) printf("%d",a)
#define sl(a) scanf("%lld",&a)
#define pl(a) printf("%lld\n",a)
#define Nline() printf("\n")
#define sstr(str) scanf("%s",str)
#define pstr(str) printf("%s\n",str)
#define SET(a) memset(a,-1,sizeof(a))
#define CLR(a) memset(a,0,sizeof(a))
#define vi vector<int>
#define vvi vector<vi>
#define all(v) (v).begin(),(v).end()
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())
#define ios ios::sync_with_stdio(false); cin.tie(0);cout.tie(NULL);
ll solve(ll n)
{
      if(n==2)return 3;
      if(n==1)return 1;
      else
         return 1+2*solve(n/2);
}
int main() {
    ios;
 
	ll n;cin>>n;
cout<<	solve(n)<<"\n";
	
 
    
}

Measured memory_bytes: 256
#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);
    
    //good luck kittu!
    string s, t;
    cin>>s>>t;
    if(t.size() != s.size()+1) return cout<<"No\n", 0;
    t.erase(s.size());
    if(t==s) cout<<"Yes\n";
    else cout<<"No\n";
    return 0;
}


Measured memory_bytes: 3644
n = int(input())

a = [i**5 for i in range(120)]
for i in range(120):
   for j in range(i+1,120):
       if a[j]-a[i] == n:
           print(j,i)
           break
       if a[j]+a[i] == n:
           print(j,-i)
           break
   else: continue
   break


Measured memory_bytes: 9072
#include<bits/stdc++.h>
#define U [1<<17]={}
#define G(a)((c=A[a]+A[P[a]]+C[a])%k?c:0)
typedef long long L;using namespace std;map<L,L>T U;L P U,E U,Z U,H U,C U,A U,O U,X U,B U,k,n,a,b,c,p;char s U;
L D(L a){L d;Z[a]=1;for(map<L,L>::iterator I=T[a].begin();I!=T[a].end();I++)
    d=I->first,d-P[a]?P[d]=a,E[d]=E[a]+1,C[d]=I->second,D(d),Z[a]+=Z[d],!H[a]|Z[H[a]]<Z[d]?H[a]=d:0:0;}
L M(L i){return i?B[i]+M(i^i&-i):0;}
L S(L x,L i){for(x=G(x)+M(i++)-M(i);i<1e5;i+=i&-i)B[i]+=x;}
L K(L a){p=X[a];n=X[b];return p-n?E[p]<E[n]?swap(a,b),p=n:0,M(O[a])-M(O[p])+G(p)+K(P[p]):abs(M(O[a])-M(O[b]));}
main(){for(cin>>n>>k;++p<n;T[a][b]=T[b][a]=c)cin>>a>>b>>c;
       for(D(b=p=0);p<n;p++)if(!p|H[P[p]]-p)for(a=p;!b|a;S(a=H[a],O[a]=b++))X[a]=p;
       for(cin>>a;cin>>s>>a>>b;*s&2?cout<<K(a)<<endl,0:A[a]+=b,S(H[a],O[a]),a&&S(a,O[a]-1));}

Measured memory_bytes: 33392
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<string.h>
#include<vector>
#include<math.h>
#include<queue>
#include <algorithm>
#include<functional>
#include<cstdlib>
#include<cmath>


#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 FORR(i, m, n) for(int i = m;i >= n;i--)
#define CI cin >>
#define CO cout <<
#define E << endl;

using namespace std;

typedef pair<int, int> P;
typedef pair<long, long> LP;
typedef pair<int, P> PP;
typedef pair<long, LP> LPP;



int dy[] = { 0, 0, 1, -1, 0 };
int dx[] = { 1, -1, 0, 0, 0 };


double X = 0;
double H = 0;

void input(void) {
	CI X;
	CI H;

	return;
}


int main(void) {
	while (1) {
		input();
		if (X == 0 && H == 0) {
			return 0;
		}
		printf("%.7f\n", (X * X) + (2 * X * sqrt((H * H) + (X * X) / 4.0)));
	}

	return 0;
}

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

using namespace std;

int main(){
    int N, K;
    cin >> N >> K;
    if(N == 1){
        if(!K){
            cout << "0 0 1 1" << endl;
        }
        else{
            cout << -1 << endl;
        }
    }
    else{
        if((1<<N) <= K){
            cout << -1 << endl;
        }
        else{
            for(int i = 0; i<(1<<N); i++){
                if(i != K){
                    cout << i << " ";
                }
            }
            cout << K << " ";
            for(int i = (1<<N)-1; i>=0; i--){
                if(i != K){
                    cout << i << " ";
                }
            }
            cout << K << endl;
        }
    }
}


Measured memory_bytes: 1792
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<tuple>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define Per(i,sta,n) for(int i=n-1;i>=sta;i--)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};

int k;
vector<ll> lu;

void dfs(ll k,int d){
  lu.push_back(k);
  if(d>=10) return;
  int l=k%10;
  if(l>=1) dfs(k*10+l-1,d+1);
  dfs(k*10+l,d+1);
  if(l<=8) dfs(k*10+l+1,d+1);
}

void solve(){
  cin >> k;
  rep(i,9){
    dfs(i+1,0);
  }
  sort(lu.begin(),lu.end());
  // rep(i,50){
  //   cout << lu[i] << endl; 
  // }
  cout << lu[k-1] << endl;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(50);
    solve();
}

Measured memory_bytes: 10604
n = int(input())

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

b ={i:0 for i in range(min(min(a),-1),max(a)+10)}
for i in a:
    b[i] += 1


c = 0
for i in range(len(b)-3):
    c = max(c,b[i]+b[i+1]+b[i+2])
print(c)

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

const int mod = 1000000007;
const int maxn = 200013;

int n;
int c[maxn], dp[maxn], seen[maxn];

signed main () {
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i)
        scanf("%d", &c[i]);
    dp[0] = 1;
    for (int i = 1; i <= n; ++i) {
        dp[i] = dp[i - 1];
        if (c[i] != c[i + 1]) {
            if (seen[c[i]])
                (dp[i] += dp[seen[c[i]]]) %= mod;
            seen[c[i]] = i;
        }
    }
    printf("%d\n", dp[n]);
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,n) for(ll i=0;i<n;++i)
#define FOR(i,j,n) for(ll i=j;i<n;++i)
#define MOD (1e9 + 7)

int main(void){
    ll N, K;
    cin >> N >> K;
    ll A[N], memory[N], path[N];
    REP(i,N){
        cin >> A[i];
        memory[i] = -1;
        path[i] = 0;
    }
    ll current = 0;
    memory[0] = 0;
    ll loop_start=0, loop_size=1;
    for(ll i=1;i<N+1;i++){
        ll next = A[current] - 1;
        if(memory[next]==-1){
            memory[next] = i;
            path[i] = next;
            current = next;
        }
        else{
            loop_start = memory[next];
            loop_size = i - loop_start;
            break;
        }
    }
    ll res;
    if(K<loop_start){
        res = K;
    }
    else{
        res = loop_start + ((K-loop_start) % loop_size);
    }
    cout << path[res]+1 << endl;
}


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

using namespace std;
#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define ll long long
#define ll1 1ll
#define ONE 1ll
#define DBG 1
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define loop(n) rep(loop, (0), (n))
#define all(c) begin(c), end(c)
const int INF =
sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
using pii = pair<int, int>;
// template<class T> ostream &operator<<(ostream &os,T &t){dump(t);return os;}
template <typename T, typename S>
istream &operator>>(istream &is, pair<T, S> &p) {
	is >> p.first >> p.second;
	return is;
}
template <typename T, typename S>
ostream &operator<<(ostream &os, pair<T, S> &p) {
	os << p.first << " " << p.second;
	return os;
}

template <typename T> void printvv(const vector<vector<T>> &v) {
	cerr << endl;
	rep(i, 0, v.size()) rep(j, 0, v[i].size()) {
		if (typeid(v[i][j]).name() == typeid(INF).name() and v[i][j] == INF) {
			cerr << "INF";
		}
		else
			cerr << v[i][j];
		cerr << (j == v[i].size() - 1 ? '\n' : ' ');
	}
	cerr << endl;
}
/*
typedef __int128_t Int;
std::ostream &operator<<(std::ostream &dest, __int128_t value) {
std::ostream::sentry s(dest);
  if (s) {
	__uint128_t tmp = value < 0 ? -value : value;
	char buffer[128];
	char *d = std::end(buffer);
	do {
	  --d;
	  *d = "0123456789"[tmp % 10];
	  tmp /= 10;
	} while (tmp != 0);
	if (value < 0) {
	  --d;
	  *d = '-';
	}
	int len = std::end(buffer) - d;
	if (dest.rdbuf()->sputn(d, len) != len) {
	  dest.setstate(std::ios_base::badbit);
	}
  }
  return dest;
}

__int128 parse(string &s) {
  __int128 ret = 0;
  for (int i = 0; i < s.length(); i++)
	if ('0' <= s[i] && s[i] <= '9')
	  ret = 10 * ret + s[i] - '0';
  return ret;
}
*/

#ifndef _DEBUG
#define printvv(...)
#endif
void YES(bool f) { cout << (f ? "YES" : "NO") << endl; }
void Yes(bool f) { cout << (f ? "Yes" : "No") << endl; }
template <class T> bool chmax(T &a, const T &b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
template <class T> bool chmin(T &a, const T &b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}

signed main(signed argc, char *argv[]) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(12);

	int N, M; cin >> N >> M;
	vector<vector<int>>A(N, vector<int>(M));
	rep(i, 0, N)rep(j, 0, M) { cin >> A[i][j]; A[i][j]--; }
	vector<int>idx(N);
	set<int>d;
	int ans = INF;
	rep(i, 0, M) {
		rep(i, 0, N) {
			while (idx[i] < M and d.count(A[i][idx[i]]))idx[i]++;
		}
		vector<int>cnt(M);
		rep(i, 0, N)cnt[A[i][idx[i]]]++;
		int m = max_element(all(cnt)) - cnt.begin();
		chmin(ans, cnt[m]);
		d.insert(m);
	}
	cout << ans << endl;

	return 0;
}


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

void solve(long long N, long long M, long long K, std::vector<long long> A, std::vector<long long> B) {
    vector<ll> sumA(N + 1);
    vector<ll> sumB(M + 1);
    sumA[0] = 0;
    for (ll i = 1; i <= N; i++) {
        sumA[i] = A[i - 1] + sumA[i - 1];
    }
    sumB[0] = 0;
    for (ll i = 1; i <= M; i++) {
        sumB[i] = B[i - 1] + sumB[i - 1];
    }

    ll ans = 0;
    ll j = M;
    rep(i, N + 1) {
        if (sumA[i] > K) {
            break;
        }
        while (sumB[j] > K - sumA[i]) {
            j--;
        }
        ans = max(ans, i + j);
    }
    cout << ans << endl;
}

int main() {
    long long N;
    scanf("%lld", &N);
    long long M;
    scanf("%lld", &M);
    long long K;
    scanf("%lld", &K);
    std::vector<long long> A(N);
    for (int i = 0; i < N; i++) {
        scanf("%lld", &A[i]);
    }
    std::vector<long long> B(M);
    for (int i = 0; i < M; i++) {
        scanf("%lld", &B[i]);
    }
    solve(N, M, K, std::move(A), std::move(B));
    return 0;
}


Measured memory_bytes: 9540
import sys
from fractions import gcd
from functools import reduce
from itertools import combinations

import numpy as np

sys.setrecursionlimit(200000)


def input():
    return sys.stdin.readline()[:-1]


def ii(t: type = int):
    return t(input())


def il(t: type = int):
    return list(map(t, input().split()))


def imi(N: int, t: type = int):
    return [ii(t) for _ in range(N)]


def iml(N: int, t: type = int):
    return [il(t) for _ in range(N)]


def is_MM(s):
    num = int(s)
    return 0 < num <= 12


def solve():
    N, M = il()
    L = []
    R = []
    for m in range(M):
        lr = il()
        L.append(lr[0])
        R.append(lr[1])
    return max(0, min(R) - max(L) + 1)


if __name__ == "__main__":
    print(solve())

Measured memory_bytes: 21612
#include <stdio.h>
#define N 500000
#define INFTY 10000000000

long int L[N/2+2],R[N/2+2];
int count;


void merge(int S[],int left,int mid,int right){
  int n1,n2,i,j,k;
  n1=mid-left;
  n2=right-mid;

  for(i=0;i<n1;i++){
    L[i]=S[left+i];
  }
  for(i=0;i<n2;i++){
    R[i]=S[mid+i];
  }
  L[n1]=INFTY;
  R[n2]=INFTY;
  i=0;
  j=0;

  for(k=left;k<right;k++){
    if(L[i]<=R[j]){
      S[k]=L[i];
      i=i+1;
    }
    else{
      S[k]=R[j];
      j=j+1;
    }
    count++;
  }
}

void mergesort(int S[],int left,int right){
    if(left+1<right){
      int mid=(left+right)/2;
      mergesort(S,left,mid);
      mergesort(S,mid,right);
      merge(S,left,mid,right);
    }
}


int main(){
  int S[N],n,i;
  count=0;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&S[i]);
  }
  
  mergesort(S,0,n);

  for(i=0;i<n;i++){
    printf("%d",S[i]);
    if(i!=n-1){
      printf(" ");
    }
  }
 
  printf("\n%d\n",count);

  return 0;
}
   

  





Measured memory_bytes: 7560
#include<iostream>

using namespace std;

int main()
{
	long long a,b;
	cin >> a >> b;
	if(((a > 0) and (a < 10)) and ((b > 0) and (b < 10)))
	{
		cout << a * b << endl;
	}
	else
	{
		cout << "-1" << endl;
	}
}


Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <cmath>
#include <csignal>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>

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

int main() {
  int n = 0;
  cin >> n;
  vector<int> a(n);
  for (int i=0; i<n; i++) {
    cin >> a.at(i);
  }
  int cnt = 0;
  for (int i=0; i<n; i++) {
    if (i+1 == a.at(i)) {
      cnt++;
      i++;
    }
  }
  cout << cnt << endl;
  return 0;
}
 

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

int two(int a){
	int k=0;
	while(a>0){
		if(a%2==0) k++;
		else break;
		a /= 2;
	}
	return k;
}

int main(void){
	int n, a, ans=0;
	cin >> n ;
	for(int i=0; i<n; i++){
		cin >> a;
		ans += two(a);
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> pi;
int h,w;
int arr[1005][1005];
int dy[4]={0,0,1,-1};
int dx[4]={1,-1,0,0};
bool visited[1005][1005];
int main(){
	int sx,sy;
	int des_x,des_y;
	cin>>h>>w>>sy>>sx>>des_y>>des_x;
	for(int i=1; i<=h; i++){
		string s;
		cin>>s;
		for(int j=0; s[j]; j++){
			if(s[j]=='#') arr[i][j+1] = 1;
		}
	}
	deque<pair<pi,int> >deq;
	deq.push_back(make_pair(pi(sy,sx),0));
	while(!deq.empty()){
		
		int y = deq.front().first.first;
		int x = deq.front().first.second;
		int d = deq.front().second;
		//cout<<y<<" "<<x<<" "<<d<<'\n';
		deq.pop_front();
		if(visited[y][x]) continue;
		visited[y][x] = true;
		if(y==des_y && x==des_x){
			cout<<d;
			return 0;
		}
		for(int i=-2; i<=2; i++){
			for(int j=-2; j<=2; j++){
				int yy = y+j;
				int xx =x+i;
				if(yy<1 || yy>h || xx<1 || xx>w) continue;
				if(visited[yy][xx] || arr[yy][xx]) continue;
				if(abs(yy-y)+abs(xx-x)<=1){
					deq.push_front(make_pair(pi(yy,xx),d));
				}
				else deq.push_back(make_pair(pi(yy,xx),d+1));
			}
		}
	}
	cout<<-1;
}

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

typedef long long ll;
typedef pair <int , int> pii;
typedef long double ld;

const int N = 2e5+10 , mod = 1e9+7;

int32_t main(){
   ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
   ll x , k , d;
   cin >> x >> k >> d;
   ll need = min(abs(x) / d , k);
   if(x > 0)
      x -= need * d;
   else
      x += need * d;
   k -= need;
   if(!k)
      return cout << abs(x) , 0;
   if(x < 0){
      k--;
      x += d;
   }
   if(k & 1)
      cout << abs(x - d);
   else
      cout << x;
   return 0;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e5+13; 
int main()
{
	char s[4];
	scanf("%s",s+1);
	int cnt=0;
	for(int i=1;i<=3;i++)
	{
		if(s[i]=='R') cnt++;
	 } 
	if(cnt==0)
	{
		printf("0");
	}
	else if(cnt==1)
	{
		printf("1");
	}
	else if(cnt==3)
	{
		printf("3");
	}
	else
	{
		if(s[1]=='S'||s[3]=='S')
		{
			printf("2");
		 } 
		 else printf("1");
	}
 } 

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

using namespace std;

int main()
{
    int n, k;  cin >> n >> k;
    vector <int> v(n), dp(n, 1e9 + 10);

    for (auto &x : v)
        cin >> x;

    dp[0] = 0;
    for (int i = 0; i < n; i++)
        for (int j = i + 1; j <= i + k; j++)
            if (j < n)
                dp[j] = min(dp[j], dp[i] + abs(v[i] - v[j]));
    cout << dp[n-1] << "\n";
    
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>

using namespace std;

int main(){
  string s;
  std::cin >> s;

  if(s[2] == s[3] && s[4] == s[5]){
    std::cout << "Yes" << '\n';
  }else{
    std::cout << "No" << '\n';
  }
  return 0;
}


Measured memory_bytes: 888
N,T=(int(i) for i in input().split())
ans=99999999999999
for i in range(N):
	c,t=(int(i) for i in input().split())
	if t <= T:
		if c <= ans:
			ans=c
if ans ==99999999999999:
	print("TLE")
else:
	print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

#define int long long
int prime[1000000];
int divide[1000000];
signed main(){
    int n, p;
    cin >> n >> p;
    int index = 0;
    int tmp = p;
    for(int i=2; i * i <= tmp; ++i){
        if(p % i) continue;
        prime[index] = i;
        while(p % i == 0){
           divide[index]++; 
           p /= i;
        }
        index++;
    }
    //for(int i=0; i<index; ++i) cout << prime[i] << endl;
    //for(int i=0; i<index; ++i) cout << divide[i] << endl;
    prime[index] = p;
    divide[index] = 1;
    index++;

    int res=1;
    for(int i=0; i<index; ++i){
        //cout << divide[i] << " " << n << " " << divide[i]/n << endl;
    
        while(divide[i]>=n){
            res *= prime[i];
            divide[i] -= n;
        }
    }
    cout << res << endl;
    return 0;
}

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

using namespace std;

typedef pair<int, bool> Link;
typedef vector<vector<Link> > Graph;

int main () {
    int V, E, r;
    cin >> V >> E >> r;

    vector<pair<bool, int> > distances(V);
    vector<pair<pair<int, int>, int> > edges;

    // Init source to a distance of 0
    distances[r] = make_pair(true, 0);

    // Set known edges
    for(int i=0; i<E; i++) {
        int s, t, d;
        cin >> s >> t >> d;
        edges.push_back(make_pair(make_pair(s, t), d));
    }

    // Run Ford-Bellman
    for(int _=0; _<V; _++)
        for(int i=0; i<E; i++){
            int v1 = edges[i].first.first;
            int v2 = edges[i].first.second;
            int d = edges[i].second;

            if (distances[v1].first) {
                // If distance to v1 is Inf, ignore
                if (distances[v2].first) {
                    // If distance is defined, then check
                    if (distances[v2].second > distances[v1].second + d)
                        distances[v2] = make_pair(true, distances[v1].second + d);
                } else {
                    // If distance to v2 is Inf, force set
                    distances[v2] = make_pair(true, distances[v1].second + d);
                }
            }
        }

    // Detect loop
    for(int i=0; i<E; i++){
        int v1 = edges[i].first.first;
        int v2 = edges[i].first.second;
        int d = edges[i].second;

        if (distances[v1].first)
            if (distances[v2].first)
                if (distances[v2].second > distances[v1].second + d) {
                    cout << "NEGATIVE CYCLE" << endl;
                    return 0;
                }
    }

    // Log
    for(int i=0; i<V; i++) {
        bool isDefined = distances[i].first;
        int d = distances[i].second;

        if (isDefined)
            cout << d << endl;
        else
            cout << "INF" << endl;
    }
}


Measured memory_bytes: 3140
#include<stdio.h>
int main(){
  int n,a[100],b[100],i;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
   }
  for(i=0;i<n;i++){
     b[i]=a[n-1-i];
     if(i>0){
       printf(" ");
     }
     printf("%d",b[i]);
      }
  printf("\n");
  return 0;
}
    
    
    

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

// #define int long long // intで書いたけど心配なときにlong longに変換する
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;

/* short */
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) begin(v), end(v)
#define RALL(v) rbegin(v), rend(v)
#define X real()
#define Y imag()

/* REPmacro */
#define REPS(i, a, n) for (ll i = (a); i < (ll)(n); ++i)
#define REP(i, n) REPS(i, 0, n)
#define RREP(i, n) REPS(i, 1, n + 1)
#define DEPS(i, a, n) for (ll i = (a); i >= (ll)(n); --i)
#define DEP(i, n) DEPS(i, n, 0)
#define EACH(i, n) for (auto&& i : n)

/* debug */
#define debug(x) cerr << x << " " << "(L:" << __LINE__ << ")" << '\n';

/* alias */
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;
using D = double;
using P = complex<D>;
using vs = vector<string>;
template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* const */
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;
const D EPS = 1e-9;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

/* func */
inline bool inside(int y, int x, int H, int W) {return y >= 0 && x >= 0 && y < H && x < W;}
inline int in() {int x; cin >> x; return x;}
inline ll IN() {ll x; cin >> x; return x;}
inline vs split(const string& t, char c) {vs v; stringstream s(t); string b; while(getline(s, b, c)) v.eb(b); return v;}
template <typename T> inline bool chmin(T& a, const T& b) {if (a > b) a = b; return a > b;}
template <typename T> inline bool chmax(T& a, const T& b) {if (a < b) a = b; return a < b;}
template <typename T, typename S> inline void print(const pair<T, S>& p) {cout << p.first << " " << p.second << endl;}
template <typename T> inline void print(const T& x) {cout << x << endl;}
template <typename T, typename S> inline void print(const vector<pair<T, S>>& v) {for (auto&& p : v) print(p);}
template <typename T> inline void print(const vector<T>& v, string s = " ") {REP(i, v.size()) cout << v[i] << (i != (ll)v.size() - 1 ? s : "\n");}
inline void yesno(bool ok, string yes = "Yes", string no = "No") {cout << (ok?yes:no) << endl;}


signed main() {
    //my-code
    string S; cin >> S;
    cout << S[0] << S[1] << S[2] << endl;

    return 0;
}

// https://github.com/kurokoji/.cpp-Template/wiki テンプレートについて
// http://www.creativ.xyz/dump-cpp-652 dump()について
// https://gist.github.com/rigibun/7905920 色々

Measured memory_bytes: 3652
# include<bits/stdc++.h>
# include<unordered_map>
# include<unordered_set>
// # include<prettyprint.hpp>
using namespace std;
# define ll long long
int n, m, x;
int ans = INT_MAX;
vector<int> c;
vector<vector<int> > book;
string bits(int i){
    string res;
    while (i){
        res+='0'+(i&1);
        i>>=1;
    }
    while (res.size() < n) res+='0';
    return res;
}
int calc(int i){
    string bit = bits(i);
    reverse(bit.begin(), bit.end());
    vector<int>a(m);
    int cost = 0;
    for(int i = 0; i < n; i++){
        if (bit[i] == '0') continue;
        cost += book[i][0];
        for(int j = 0; j < m; j++) a[j]+=book[i][j+1];
    }
    int flag = 0;
    for(auto i:a) if (i < x) flag = 1;
    if (!flag) return cost;
    return -1;
}
int main(){
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    cin >> n >> m >> x;
    c.resize(n);
    book.resize(n, vector<int>(m+1));
    for(int i = 0; i < n; i++){
        for(int j = 0; j <= m; j++) cin >> book[i][j];
    }
    int ans = INT_MAX;
    for(int i = 0; i < (1<<n); i++){
        int cal = calc(i);
        if (cal!=-1) ans = min(ans, calc(i));
    }
    if (ans == INT_MAX) cout << -1;
    else cout << ans;
    return 0;
}

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

using namespace std;

struct card {
	char suit;
	int value;
};

void BubbleSort(struct card Card1[], int N) {
	
	int i, flag = 1;

	while(flag){
		flag = 0;
		for (i = N - 1; i >= 1;i--) {
			if (Card1[i].value < Card1[i - 1].value) {
				swap(Card1[i], Card1[i - 1]);
				flag = 1;
			}
		}
	}

}

void SelectionSort(struct card Card2[],int N) {

	int i, j, minj;

	for (i = 0; i < N-1; i++) {
		minj = i;
		for (j = i + 1; j < N; j++) {
			if (Card2[j].value < Card2[minj].value) {
				minj = j;
			}
		}
		swap(Card2[i] , Card2[minj]);
		
	}

}

bool compare(struct card Card1[], struct card Card2[],int N) {

	for (int i = 0; i < N; i++) {
		if (Card1[i].suit != Card2[i].suit)
			return false;
	}
	return true;
}

int main() {

	card Card1[36], Card2[36];
	int i,N;

	cin >> N;
	for (i = 0; i < N; i++) {
		cin >> Card1[i].suit >> Card1[i].value;
	}

	for (i = 0; i < N; i++) {
		Card2[i] = Card1[i];
	}

	BubbleSort(Card1, N);
	SelectionSort(Card2, N);

	for (i = 0; i < N; i++) {
		if (i != 0) cout << " ";
		cout << Card1[i].suit << Card1[i].value;
	}
	cout << endl << "Stable" << endl;
	

	for (i = 0; i < N; i++) {
		if (i != 0) cout << " ";
		cout << Card2[i].suit << Card2[i].value;
	}

	if (compare(Card1, Card2, N))
		cout << endl << "Stable" << endl;
	else cout << endl << "Not stable" << endl;

	return 0;

}

Measured memory_bytes: 1164
// #pragma comment(linker, "/stack:200000000")
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,avx,avx2")

#include <bits/stdc++.h>  
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define pl pair<ll,ll>
#define fastIO ios_base::sync_with_stdio(false);cin.tie(NULL);
#define vl vector<ll>
#define N 100005
#define mod 1000000007

ll lcm(ll a,ll b)
{
    return a/__gcd(a,b)*b;
}

int main()
{   
    ll n;cin>>n;
    ll a[n];
    ll sol=1;
    for(ll i=0;i<n;i++)
    cin>>a[i];
    for(ll i=0;i<n;i++)
    {
        sol=lcm(sol,a[i]);
    }
    cout<<sol<<"\n";
    return 0;
}

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

int n;
long long int k;
long long int sum;
int cnt[40];

long long int dfs(int i, int f, long long int d){
	if(i<0){
		return sum+d;
	}
	if(f){
		return dfs(i-1, 1, d+max(0LL, (1LL << i)*(n-cnt[i]-cnt[i])));
	}else{
		if(k >> i & 1){
			return max(dfs(i-1, 1, d), dfs(i-1, 0, d+(1LL << i)*(n-cnt[i]-cnt[i])));
		}else{
			return dfs(i-1, 0, d);
		}
	}
	return 0LL;
}

int main() {
	cin >> n >> k;
	for(int i=0;i<n;i++){
		long long int a; cin >> a;
		sum += a;
		for(int j=0;j<40;j++){
			cnt[j] += a >> j & 1;
		}
	}
	cout << dfs(41, 0, 0) << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<climits>
#include<vector>
#include<list>
#include<functional>
#include<algorithm>
#include<string>
#include<cmath>
#include<complex>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<tuple>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

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

	int y, m, d;
	scanf("%d%*c%d*c%d", &y, &m, &d);
	string res = "Heisei";
	if (y > 2019) res = "TBD";
	else if (y == 2019) {
		if (m > 4) res = "TBD";
	}
	cout << res << "\n";

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<stdlib.h>
#include<queue>
#include<map>
#include<math.h>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>
#include<deque>
#include<set>
using namespace std;
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
typedef long long LL;
typedef vector<int> vi;
typedef vector<pair<int,int> > vii;
typedef pair<int, int> pii;
#define FF first
#define SS second
#define MP make_pair
#define mxN (int)2e5 + 2
#define sz(n) (int)(n).size()
#define fasterIO ios::sync_with_stdio(0); cin.tie(0);
LL gcd(LL a, LL b)
{
    if(b == 0LL) return a;
    return gcd(b, a % b);
}
LL bigmod(LL a, LL b, LL mod)
{
    if(b == 0LL) return 1LL;
    LL sq = bigmod(a, b/2LL, mod);
    sq = (sq * sq) % mod;
    if(b&1LL) return (sq * (a%mod)) % mod;
    return sq;
}
 
 
int main()
{
    fasterIO
    LL n, x, t;
    cin >> n >> x >> t;
    cout << ((n + (x - 1) )/ x) * t << endl;
 
    return 0;
}

Measured memory_bytes: 3192
macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; input_inner ! { iter , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let s = { use std :: io :: Read ; let mut s = String :: new ( ) ; std :: io :: stdin ( ) . read_to_string ( & mut s ) . unwrap ( ) ; s } ; let mut iter = s . split_whitespace ( ) ; input_inner ! { iter , $ ( $ r ) * } } ; }
macro_rules ! input_inner { ( $ iter : expr ) => { } ; ( $ iter : expr , ) => { } ; ( $ iter : expr , mut $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let mut $ var = read_value ! ( $ iter , $ t ) ; input_inner ! { $ iter $ ( $ r ) * } } ; ( $ iter : expr , mut $ var : ident $ ( $ r : tt ) * ) => { let mut $ var = $ iter . next ( ) . unwrap ( ) . parse ::< usize > ( ) . unwrap ( ) ; input_inner ! { $ iter $ ( $ r ) * } } ; ( $ iter : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ iter , $ t ) ; input_inner ! { $ iter $ ( $ r ) * } } ; ( $ iter : expr , $ var : ident $ ( $ r : tt ) * ) => { let $ var = $ iter . next ( ) . unwrap ( ) . parse ::< usize > ( ) . unwrap ( ) ; input_inner ! { $ iter $ ( $ r ) * } } ; }
macro_rules ! read_value { ( $ iter : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ iter , $ t ) ) ,* ) } ; ( $ iter : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ iter , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ iter : expr , chars ) => { read_value ! ( $ iter , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ iter : expr , usize1 ) => { read_value ! ( $ iter , usize ) - 1 } ; ( $ iter : expr , $ t : ty ) => { $ iter . next ( ) . unwrap ( ) . parse ::<$ t > ( ) . unwrap ( ) } ; }
use std::cmp::max;
fn rec(n: usize, i: usize, j: usize, a: &Vec<isize>, memo: &mut Vec<Vec<Option<isize>>>) -> isize {
    if let Some(p) = memo[i][j] {
        p
    } else if i + j == n {
        0
    } else {
        let l = a[i] - rec(n, i + 1, j, a, memo);
        let r = a[n - j - 1] - rec(n, i, j + 1, a, memo);
        let d = max(l, r);
        memo[i][j] = Some(d);
        d
    }
}
fn main() {
    input! { n, a: [isize; n] };
    let mut memo = vec![vec![None; n + 1]; n + 1];
    println!("{}", rec(n, 0, 0, &a, &mut memo));
}


Measured memory_bytes: 166268
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
ll pow(ll x,ll y){
if(y==0){return 1;}
else if(y%2){return x*pow(x,y-1);}
ll temp=pow(x,y/2);
return temp*temp;
}
vector<ll>graph[200005];
ll ans[200005]={0};
ll x[200005]={0};
void bfs(ll cur,ll par,ll cnt){

ans[cur]+=x[cur]+cnt;
for(int i=0;i<graph[cur].size();i++){
    if(graph[cur][i]!=par){
        bfs(graph[cur][i],cur,cnt+x[cur]);
    }
}
}
int main(){
 ll t=1;
 //cin>>t;
 while(t--){
ll n,q;
cin>>n>>q;
for(int i=0;i<n-1;i++){
    ll x,y;
    cin>>x>>y;
    graph[x].pb(y);
    graph[y].pb(x);
}
for(int i=0;i<q;i++){
    ll x1,y;
    cin>>x1>>y;
    x[x1]+=y;
}
bfs(1,-1,0);
for(int i=1;i<=n;i++){
    cout<<ans[i]<<" ";
}
 }
}


Measured memory_bytes: 28800
using System;
using System.IO;

namespace AGC006B{
    public class Program{
        public static void Main(string[] args){
            var sr = new StreamReader();
            var sw = new StreamWriter(Console.OpenStandardOutput()){AutoFlush = false};
            //---------------------------------
            var N = sr.Next<int>();
            var X = sr.Next<int>();
            var size = 2 * N - 1;

            if(X == 1 || X == size){
                Console.WriteLine("No");
                return;
            }

            Console.WriteLine("Yes");
            if(X < N){
                for(var i = X + N; i <= size; i++){
                    sw.WriteLine(i);
                }
                for(var i = 1; i < X + N; i++){
                    sw.WriteLine(i);
                }
            }
            if(X == N){
                for(var i = 1; i <= size; i++){
                    sw.WriteLine(i);
                }
            }
            if(X > N){
                for(var i = X - N + 1; i <= size; i++){
                    sw.WriteLine(i);
                }
                for(var i = 1; i < X - N + 1; i++){
                    sw.WriteLine(i);
                }
            }
            //---------------------------------
            sw.Flush();
        }
    }

    public class StreamReader{
        private readonly char[] _c = {' '};
        private int _index = -1;
        private string[] _input = new string[0];
        private readonly System.IO.StreamReader _sr = new System.IO.StreamReader(Console.OpenStandardInput());

        public T Next<T>(){
            if(_index == _input.Length - 1){
                _index = -1;
                while(true){
                    string rl = _sr.ReadLine();
                    if(rl == null){
                        if(typeof(T).IsClass) return default(T);
                        return (T)typeof(T).GetField("MinValue").GetValue(null);
                    }
                    if(rl != ""){
                        _input = rl.Split(_c, StringSplitOptions.RemoveEmptyEntries);
                        break;
                    }
                }
            }
            return (T)Convert.ChangeType(_input[++_index], typeof(T), System.Globalization.CultureInfo.InvariantCulture);
        }

        public T[] Next<T>(int x){
            var ret = new T[x];
            for(var i = 0; i < x; ++i) ret[i] = Next<T>();
            return ret;
        }

        public T[][] Next<T>(int y, int x){
            var ret = new T[y][];
            for(var i = 0; i < y; ++i) ret[i] = Next<T>(x);
            return ret;
        }
    }
}

Measured memory_bytes: 8144
#include <bits/stdc++.h>
using namespace std;
 
int main() {
bool f= true;
string s,t;
cin>>s>>t;
int n=s.size();
int m=t.size();
if(m!=n+1){
    cout<<"No";
        return 0;
    }
for(int i=0;i<n;i++){
    if(s[i]!=t[i])
        f=false;
}
if(f== true )
    cout<<"Yes";
else
    cout<<"No";

   return 0;
}

Measured memory_bytes: 3616