akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <algorithm>

void c_Poll(const std::vector<std::string>& S_list)
{
    std::map<std::string, int> counter;
    int max = 0;
    for (const auto& s : S_list)
    {
        if (counter.count(s) == 0)
            counter[s] = 1;
        else
            ++counter[s];

        if (max < counter[s])
            max = counter[s];
    }

    std::vector<std::string> out;
    for (const auto& c : counter)
    {
        if (c.second == max)
            out.push_back(c.first);
    }

    std::sort(out.begin(), out.end());

    for (const auto& s : out)
        std::cout << s << "\n";
}


int main(int, char* [])
{
    int N;
    std::cin >> N;

    std::vector<std::string> S_list(N);
    for (int i = 0; i < N; ++i)
        std::cin >> S_list[i];

    c_Poll(S_list);

    return 0;
}


Measured memory_bytes: 28404
class UnionFind():
    def __init__(self, n):
        self.n = n
        #親の添字、親自身は木の要素数*-1をもつ
        self.root = [-1]*(n)
        #枝の最大長さ
        self.rank = [0]*(n)

    def find_root(self, x):
        if(self.root[x] < 0):
            return x
        else:
            self.root[x] = self.find_root(self.root[x])
            return self.root[x]
    #高さによる合併    
    def unite(self, x, y):
        x = self.find_root(x)
        y = self.find_root(y)
        if x == y:
            return 
        elif self.rank[x] > self.rank[y]:
            self.root[x] += self.root[y]
            self.root[y] = x

        else:
            self.root[y] += self.root[x]
            self.root[x] = y
            if(self.rank[x] == self.rank[y]):
                self.rank[y] += 1
    def same(self, x, y):
        return self.find_root(x) == self.find_root(y)
    
    def count(self, x):
        return -self.root[self.find_root(x)]    
    
    def members(self, x):
        root = self.find_root(x)
        return [i for i in range(self.n) if self.find_root(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.root) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

N, M, K = map(int,input().rstrip().split())
AB=[list(map(int,input().rstrip().split()))for _ in range(M)]
CD=[list(map(int,input().rstrip().split()))for _ in range(K)]

u = UnionFind(N)
for a,b in AB:
    u.unite(a-1,b-1)

ans=[u.count(i)-1 for i in range(N)] #木の要素数から自分を引く
ans

for a,b in AB:
    if u.same(a-1,b-1):
        ans[a-1]-=1
        ans[b-1]-=1

for c,d in CD:
    if u.same(c-1,d-1):
        ans[c-1]-=1
        ans[d-1]-=1
print(*ans)

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

#define FOR(i,a,b) for(long long int i=(a);i<(b);i++)
#define REP(i,n) for(long long int i=0;i<(n);i++)
#define ALL(s) (s).begin(),(s).end()

#define PI 3.14159265358479

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

int main(){
	ll n,m=100000;
	cin >> n;
	REP(i, n){
		m *= 105;
		m /= 100;
		if (m % 1000 != 0){
			m -= m % 1000;
			m += 1000;
		}
	}
	cout << m << "\n";
}

Measured memory_bytes: 1156
#include<stdio.h>
  int main()
  {
    int n, i;
    int min=1000000,max=-1000000;
    long long int sum=0ll;
      scanf("%d",&n);
      for(i = 0;i < n;i++)
      {
          int a;
          scanf("%d",&a);
          if(min>a)
          {
            min = a;
          }
          if(max<a)
          {
            max = a;
          }
          sum= sum + a;
      }
      printf("%d %d %lld\n",min,max,sum);

      return 0;
   }

Measured memory_bytes: 600
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define Repr(i, n, a) for (int i = (n); i >= (a); i--)
#define rep(i, n) Rep(i, 0, n)
#define repr(i, n) Repr(i, n, 0)
#define all(a) a.begin(), a.end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;

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

    int n;
    while (1)
    {
        cin >> n;
        if (n == 0)
            break;
        vector<int> v(n);
        rep(i, n) cin >> v[i];
        sort(all(v));
        int sum = 0;
        for (int i = 1; i < n - 1; i++)
            sum += v[i];
        cout << sum / (n - 2) << endl;
    }
}


Measured memory_bytes: 3112
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
void read(int &x){
	char ch=getchar();x=0;
	int res=1;
	for (;ch==' '||ch=='\n';ch=getchar());
	if (ch=='-') res=-1,ch=getchar();
	for (;ch!=' '&&ch!='\n';x=x*10+ch-'0',ch=getchar());
	x*=res;
}
void write(ll x){
	if (x<0){
		putchar('-'),write(-x);
		return;
	}
	if (x>9) write(x/10);
	putchar(x%10+'0');
}
int n,a[18][18];
ll num[65540];
ll dp[65540];
int main(){
	read(n);
	for (int i=0;i<n;i++)
		for (int j=0;j<n;j++)
			read(a[i][j]);
	for (int i=1;i<(1<<n);i++)
		for (int j=0;j<n;j++) if ((1<<j)&i)
			for (int k=j+1;k<n;k++) if ((1<<k)&i)
				num[i]+=a[j][k];
	for (int i=1;i<(1<<n);i++){
		dp[i]=num[i];
		for (int j=i&(i-1);j;j=(j-1)&i){
			dp[i]=max(dp[i],dp[i^j]+num[j]);
		}
	}
	write(dp[(1<<n)-1]);
}

Measured memory_bytes: 1280
#include <iostream>
#include <algorithm>

using namespace std;

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

    int d[30][30] = {}, t[3][30] = {};

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

    int x;

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            cin >> x;
            t[(i+j)%3][x-1]++;
        }
    }

    int tmp, ans = 1e9;

    for (int i = 0; i < c; i++) {
        for (int j = 0; j < c; j++) {
            for (int k = 0; k < c; k++) {
                if (i == j || j == k || k == i) continue;

                tmp = 0;
                for (int l = 0; l < c; l++) {
                    tmp += d[l][i] * t[0][l];
                    tmp += d[l][j] * t[1][l];
                    tmp += d[l][k] * t[2][l];
                }
                ans = min(ans, tmp);
            }
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;

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

    vector<int64_t> a(n), b(n);
    for (auto&& aa : a) {
        cin >> aa;
    }

    for (auto&& bb : b) {
        cin >> bb;
    }

    vector<int64_t> diff(n);
    int64_t sum_diff = 0;
    for (auto i : irange(0L, n)) {
        diff[i] = a[i] - b[i];
        sum_diff += diff[i];
    }

    if (sum_diff < 0) {
        cout << "-1" << endl;
        return 0;
    }

    sort(diff.begin(), diff.end());
    int64_t neg = 0;
    int64_t ans = 0;
    for (auto d : diff) {
        if (d >= 0) {
            break;
        }
        neg += -d;
        ++ans;
    }

    for (auto i : irange(n-1, -1L, -1L)) {
        if (neg <= 0) {
            break;
        }
        auto d = diff[i];
        neg -= d;
        ++ans;
    }

    cout << ans << endl;
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define pb push_back
const int maxn = 10000;
const int INF32 = 1'050'000'000;
const long long INF64 = 4'000'000'000'000'000'000;
const int MOD7 = 1'000'000'007;
const int MOD9 = 1'000'000'009;

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
string s;

int main()
{
	cin >> s;
	int n = s.size();
	vector<int> ans(n);
	rep(ri, 2)
	{
		int cnt = 0;
		rep(i, n)
		{
			if(s[i] == 'R') cnt++;
			else
			{
				ans[i] += cnt/2;
				ans[i-1] += (cnt+1)/2;
				cnt = 0;
	 		}
		}

		reverse(ans.begin(), ans.end());
		reverse(s.begin(), s.end());
		rep(i, n)
		{
			if(s[i] == 'R') s[i] = 'L';
			else s[i] = 'R';
		}
	}

	rep(i, n)
	{
		cout << ans[i] << " ";
	}
	cout << endl;
}

Measured memory_bytes: 1024
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def II(): return int(input())
def LS(): return input().split()
def S(): return input()



def main():
    a,b = LS()
    if a == b:
        return 'H'
    return 'D'

print(main())


Measured memory_bytes: 5408
import sys
read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
inputs= sys.stdin.buffer.readlines
#rstrip().decode('utf-8')

import math
#import numpy as np
#import operator
#import bisect
#from heapq import heapify,heappop,heappush
#from math import gcd
#from fractions import gcd
#from collections import deque
#from collections import defaultdict
#from collections import Counter
#from itertools import accumulate
#from itertools import groupby
#from itertools import permutations
#from itertools import combinations
#from scipy.sparse import csr_matrix
#from scipy.sparse.csgraph import floyd_warshall
#from scipy.sparse.csgraph import csgraph_from_dense
#from scipy.sparse.csgraph import dijkstra
#sys.setrecursionlimit(10**7)

#map(int,input().split())

def main():
	n=int(input())
	D=list(map(int,input().split()))
	
	
	if D[0]!=0:
		print(0)
		exit(0)
	
	if len(D)==1:
		print(1)
		exit(0)
		
		
	D.sort()
	
	if D[1]!=1:
		print(0)
		exit(0)
	
	ans=1
	
	li=[0]*n
	
	for i in range(n):
		li[D[i]]+=1
	
	for i in range(1,n):
		ans*=li[D[i]-1]
		ans%=998244353
	
	print(ans)

if __name__ == '__main__':
	main()

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

#define endl '\n'
#define lfs cout<<fixed<<setprecision(10)
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define fi first
#define se second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = (n); i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = (m) - 1; i >= (ll)(n); i--)
using ll = long long;
using ld = long double;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T>
bool chmin(T &a,T b){if(a>b){a=b;return true;}else return false;}
template<typename T>
bool chmax(T &a,T b){if(a<b){a=b;return true;}else return false;}
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;}
template<typename T1,typename T2>
void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T>
void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>&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;}};
template<typename T>
void debug(vector<T>&v,ll n){if(n!=0)cout<<v[0];
for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>
vector<vector<T>>vec(ll x, ll y, T w){
  vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
vector<ll>dx={1,0,-1,0,1,1,-1,-1};
vector<ll>dy={0,1,0,-1,1,-1,1,-1};
template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}
ostream &operator<<(ostream &os, pair<ll, ll>&p){
  return os << p.first << " " << p.second;
}  
struct UnionFind {
  vector<ll> data;
  ll num;
  UnionFind(ll size) : data(size, -1) ,num(size){ }
  bool unite(ll x, ll y) {
    x = root(x); y = root(y);
    if (x != y) {
      if (data[y] < data[x]) swap(x, y);
      data[x] += data[y]; data[y] = x;
	  num--;
    }
    return x != y;
  }
  bool find(ll x, ll y) {
    return root(x) == root(y);
  }
  ll root(ll x) {
    return data[x] < 0 ? x : data[x] = root(data[x]);
  }
  ll size(ll x) {
    return -data[root(x)];
  }
};
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  ll res=0,buf=0;
  bool judge = true;
  ll n,m,k;cin>>n>>m>>k;
  UnionFind uf1(n);
  vector<ll>cnt(n);
  rep(i,0,m){
    ll a,b;cin>>a>>b;a--;b--;
    uf1.unite(a,b);
    cnt[a]++;
    cnt[b]++;
  }
  rep(i,0,k){
    ll a,b;cin>>a>>b;a--;b--;
    if(uf1.find(a,b)){
      cnt[a]++;
      cnt[b]++;
    }
  }
  vector<ll>ret(n);
  rep(i,0,n){
    ret[i]=uf1.size(i)-cnt[i]-1;
  }
  debug(ret,n);
  return 0;
}

Measured memory_bytes: 3200
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define umap unordered_map
#define RESET   "\033[0m"
#define RED     "\033[31m"
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
const ll lINF = 1e18+7;
const int INF = 1e9+7;

template <class T> ostream& operator<<(ostream& s, const vector<T>& v) {
    for (size_t i = 0; i < v.size(); i++) s << v[i] << ' ';
    return s;
}

template <class T> istream& operator>>(istream& s, vector<T>& v) {
    for (size_t i = 0; i < v.size(); i++) s >> v[i];
    return s;
}


//########################################################################################





void solve(int CASE=0) {
	int n;
	cin >> n;
	vi v(n);
	map<int, queue<int>> m;
	cin >> v;

	sort(rall(v));
	m[v[1]].push(v[0]);
	ll sum = v[0];

	for (int i = 2; i < n; i++) {
		int l = prev(m.end())->F;
		int r = m[l].front();
		sum += l;
		m[min(v[i], l)].push(max(v[i], l));
		m[min(v[i], r)].push(max(v[i], r));
		if (i > 2) {
			m[l].pop();
			if (m[l].empty()) m.erase(l);
		}
	}
	cout << sum;
}


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

    int TEST = 1;
    //cin >> q;
    for (int i = 1; i <= TEST; i++) 
		solve(i);
}


Measured memory_bytes: 75788
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < n; i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
typedef long long ll;

int main() {
    int N, K; cin >> N >> K;
    vector<int> H(N);
    REP(i, 0, N) cin >> H[i];

    vector<ll> dp(N, 1LL << 60);
    dp[0] = 0;
    REP(i, 0, N) {
        REP(j, i + 1, min(N, i + 1 + K)) {
            dp[j] = min(dp[j], dp[i] + abs(H[i] - H[j]));
        }
    }
    cout << dp[N - 1] << endl;
    return 0;
}

Measured memory_bytes: 1408
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <iostream>
#include <algorithm>

typedef char                SINT8;
typedef unsigned char       UINT8;
typedef short               SINT16;
typedef unsigned short      UINT16;
typedef int                 SINT32;
typedef unsigned int        UINT32;
typedef long long           SINT64;
typedef unsigned long long  UINT64;
typedef double              DOUBLE;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))
#define rep(i,a,b) for(int (i)=int(a);(i)<int(b);(i)++)

#define INF = 1e9;
#define MOD = 1e9+7;
#define INF64 = 1e18;


using namespace std;

int main() {

	SINT32 N = 0;
	cin >> N;
	vector<SINT32> AR(55556);
	vector<SINT32> AR2(55556);
	vector<SINT32> AR3(55556);

	rep(i,2,55556) {
		AR[i] = i;
	}


	for(int i = 2; i < sqrt(55556); i++){
		if(AR[i] != 0) {
			for(int j = 2; i * j < 55556; j++) {
				AR[i * j] = 0;
			}
		}
	}
	AR2 = AR;

	sort(AR2.begin(),AR2.end());
	AR2.erase(std::unique(AR2.begin(), AR2.end()), AR2.end());




	AR3 = AR2;
	rep(i,0,AR3.size()) {
		AR3[i] %= 5;
	}

	
	SINT32 cnt = 0;
	while (N != 0) {
		if (AR3[cnt] == 1) {
			N--;
			cout << AR2[cnt] << " ";
		}
		cnt++;
	}

	return 0;
}

//	sort(DATA.begin(),DATA.end());
//	sort(DATA.begin(),DATA.end(),std::greater<SINT32>());
//	__gcd(ANS,DATA[i]);

//	// DATA.emplace_back(BUF);	//後ろに追加

//  DATA.erase(std::unique(DATA.begin(), DATA.end()), DATA.end());	//ソートしてから

//	DATA.insert(DATA.begin() + X, 0);	//X番目の要素に0を挿入


//	vector<vector<SINT32>> DP(N,vector<SINT32>(3));　//2次元配列

/*
	SINT32 M = 3;
	vector<pair<SINT32,SINT32>> DATA2(M);
	for (SINT32 i = 0; i < M; i++) {
		cin >> DATA2[i].first;
		cin >> DATA2[i].second;
	}
	sort(DATA2.begin(),DATA2.end());
	cout << DATA2[0].first << endl;
	cout << DATA2[0].second << endl;
*/

// 	vector<pair<int,pair<int,int>>> DATA(M);
//	cin >> DATA[i].first;
//	cin >> DATA[i].second.first;
//	cin >> DATA[i].second.second;


//		APOSI = lower_bound(ADATA.begin(),ADATA.end(),QDATA[i]) - ADATA.begin();
//		BPOSI = lower_bound(BDATA.begin(),BDATA.end(),QDATA[i]) - BDATA.begin();


/* 文字列回転
	string N;
	cin >> N;
	N = N[N.length()-1] + N.substr(0,N.length()-1);
*/

/* SET コンテナ
	set<SINT32> DATA;
	for (SINT32 i = 0; i < N; i++) {
		SINT32 buf;
		cin >> buf;
		DATA.insert(buf);
	}

	//全表示
    set<string>::iterator it; //  イテレータを用意
    for(it = DATA.begin(); it != DATA.end(); it++) {
        cout << *it << endl;
    }

	//N番目を一部表示
	set<string>::iterator it; //  イテレータを用意
	it = DATA.begin();
	rep (i,0,N) {
		it++;
	}
	cout << *it << endl;
*/

/* map
	map<string,SINT32> mp;
	SINT32 N = 0;
	SINT32 mx = 0;

	cin >> N;
	for (SINT32 i = 0; i < N; i++) {
		string s;
		cin >> s;
		mp[s]++;
	}
	for(auto it=mp.begin();it!=mp.end();it++) {
		mx=max(mx,it->second);
	}

*/

Measured memory_bytes: 896
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.Stack;

public class Main
{
	public static void main(String[] arg) throws IOException
	{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		int n = Integer.parseInt(br.readLine());
		for(int i=0; i<n; i++)
		{
		    String s1 = br.readLine();
		    String s2 = br.readLine();
		    if(s1.length() > 80 || s2.length() > 80)
			System.out.println("overflow");
		    else if ((s1.length() < 10) && (s2.length() < 10)) {
			System.out.println(Integer.parseInt(s1.toString()) + 
					   Integer.parseInt(s2.toString()));
		    } else {	
			Stack budget = cal(s1,s2);
			int m = budget.size();
			if( m > 80 ) System.out.println("overflow");
			else {
			    for(int j=0; j<m; j++)
			    System.out.print(budget.pop());
			    System.out.println();
			}
		    }
		 }
	}

	private static Stack cal(String s1, String s2)
	{
		Stack<Integer> a = new Stack<Integer>();
		Stack<Integer> b = new Stack<Integer>();
		Stack<Integer> c = new Stack<Integer>();
		char[] char1 = s1.toCharArray();
		char[] char2 = s2.toCharArray();
		int lenA = char1.length, lenB = char2.length, max = Math.max(lenA, lenB);
		for(int i=0; i<	lenA; i++) 
			a.push(Integer.parseInt(char1[i]+""));
		for(int i=0; i< lenB; i++)
			b.push(Integer.parseInt(char2[i]+""));

		int temp=0, roundup=0; //determine whether round up is needed
		for(int i=0; i<max; i++)
		{
		    if( !a.isEmpty() && !b.isEmpty() ) {
		        temp = a.pop() + b.pop() + roundup;
		    } else if( a.isEmpty() ) {
			temp = b.pop() + roundup;
		    } else {
			temp = a.pop() + roundup;
		    }

		    if(temp>9) {roundup = 1; temp-=10;}
		    else       roundup = 0;
		    c.push(temp);
		    if(i==max-1 && roundup == 1)
			c.push(1);
		}
		return c;
	}
}

Measured memory_bytes: 9636
import java.util.*;
import java.math.*;

class Main{
  public static void main(String args[]){
    Scanner scan=new Scanner(System.in);
    while(scan.hasNext()){
      int n = scan.nextInt();
      int k = scan.nextInt();
      if(n*k==0) return;

      //0th~k-1st, make sum of them is 0
      //then look k-th num, record 0 - 0th + kth, compare 0 and new value
      //then look (k+1)th num, record (old value - 1st + (k+1)th), compare maxium value and new value
      int table[]=new int [n];
      for(int i=0;i<n;i++){
        table[i]=scan.nextInt();
      }
      
      int res=0;
      int max=0;
      int imax=0;
      for(int i=k;i<n;i++){
        res=res+table[i]-table[i-k];
        if(res>max){
          //System.out.printf("max changed,imax=%d,imaxEnd=%d\n",i-k+1,i);
          max=res;
          imax=i-k+1;
        }
      }
      
      long out=0;
      for(int i=imax;i<imax+k;i++){
        out+=table[i];
      }
      //System.out.printf("imax:%d\n",imax);
      System.out.println(out);

    }
  }//main
}


Measured memory_bytes: 67700
H,W=map(int,input().split())
h,w=map(int,input().split())

buff = []
for w1 in range(W):
    buff.append([0 for h1 in range(H)])

for w2 in range(w):
    for x in range(H):
        buff[w2][x] = 1
    for h2 in range(h):
        for x in range(W):
            buff[x][h2] = 1
c = 0
for b in buff:
    for a in b:
        if a == 0:
            c+=1
print(c)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
int n,m,dp[305][305][305];
vector<pair<int,int> > v[305];
int solve(int a,int b,int c)
{
	if (dp[a][b][c]!=-1)
	return dp[a][b][c];
	int idx=max(a,max(b,c));
	for (auto p:v[idx])
	{
		if ((a>=p.first)+(b>=p.first)+(c>=p.first)!=p.second)
		return dp[a][b][c]=0;
	}
	if (idx==n)
	return dp[a][b][c]=1;
	return dp[a][b][c]=((solve(idx+1,b,c)+solve(a,idx+1,c))%mod+solve(a,b,idx+1))%mod;
}
int main()
{
	scanf("%d%d",&n,&m);
	while (m--)
	{
		int l,r,x;
		scanf("%d%d%d",&l,&r,&x);
		v[r].push_back({l,x});
	}
	memset(dp,-1,sizeof(dp));
	printf("%d",solve(0,0,0));
}

Measured memory_bytes: 114708
class Dice
  def initialize(t, s, e, w, n, b)
    $north = n
    $south = s
    $east = e
    $west = w
    $top = t
    $bottom = b
  end

  def execute_orders(orders)
    length = orders.length
    for i in 0...length
      if orders[i] == "N"
        move_north
      elsif orders[i] == "S"
        move_south
      elsif orders[i] == "E"
        move_east
      elsif orders[i] == "W"
        move_west
      else
        puts "error!"
      end
    end
  end

  def check_dices_same(order_t, order_s, order_e, order_w, order_n, order_b)
      100.times do
        execute_orders(["N", "W"].sample)
        return true if $top == order_t && $south == order_s && $east == order_e && $west == order_w && $north == order_n && $bottom == order_b
      end
    return false
  end


  private
  def move_north
    north = $north
    south = $south
    top = $top
    bottom = $bottom
    $north = top
    $top = south
    $bottom = north
    $south = bottom
  end

  def move_south
    north = $north
    south = $south
    top = $top
    bottom = $bottom
    $south = top
    $bottom = south
    $north = bottom
    $top = north
  end

  def move_east
    top = $top
    bottom = $bottom
    east = $east
    west = $west
    $east = top
    $bottom = east
    $west = bottom
    $top = west
  end

  def move_west
    top = $top
    bottom = $bottom
    east = $east
    west = $west
    $west = top
    $bottom = west
    $east = bottom
    $top = east
  end
end

n = gets.chomp.to_i
dices = []
n.times do
  dice = gets.chomp.split.map(&:to_i)
  dices << dice
end
flag = 0
for i in 0...n-1
  dice = Dice.new(dices[i][0], dices[i][1], dices[i][2], dices[i][3], dices[i][4], dices[i][5])
  for j in i+1...n
    if dice.check_dices_same(dices[j][0], dices[j][1], dices[j][2], dices[j][3], dices[j][4], dices[j][5])
      puts "No"
      flag += 1
      break
    end
  end
  if flag == 1
    break
  end
  if dice.check_dices_same(dices[n-1][0], dices[n-1][1], dices[n-1][2], dices[n-1][3], dices[n-1][4], dices[n-1][5])
    puts "No"
    flag += 1
    break
  end
end
if flag == 0
  puts "Yes"
end

Measured memory_bytes: 8828
#include<iostream>
#include<vector>
#include<algorithm>//necessary
using namespace std;

int main(){
  long long n, k, a, b;
  cin >> n >> k;
  long long ans = 0;
  long long arr[100000] = {0};
  for(long long i = 0 ; i < n; i++){
    cin >> a >> b;
    arr[a-1] += b;
  }
  for(long long i = 0; i < 100000; i++){
    if(ans + arr[i] >= k){
      cout << i+1 << endl;
      break;
    }
    else ans += arr[i];
  }
}


Measured memory_bytes: 1024
N,K,*A = $<.read.split.map(&:to_i)
A.unshift 1
B = [-1]+[nil]*N
at,k = 0,K
while 0
	break if B[at] == k

	to = A[at]

	if B[to] # B[to] <= B[at]
		l = B[at]-B[to]+1
		k -= (K-B[at])/l*l
		break
	end

	B[to], at = B[at]+1, to
end
p (k-B[at]).times.inject(at){|at| A[at] }


Measured memory_bytes: 32760
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

const ll INF = 1e17;
ll dp[52][52];
VI a, b;

bool check(VL x, int m){
    int n = x.size();
    FORR(r,m,1){
        REP(i,n){
            REP(j,51){
                if ((x[i] >> j) & 1){
                    x[i] |= 1LL << (j % r);
                }
            }
        }
    }
    bool ok = true;
    REP(i,n){
        if (((x[i] >> b[i]) & 1) == 0) ok = false;
    }
    return ok;
}

int main() {
    int n;
    cin >> n;
    a.resize(n);
    b.resize(n);
    REP(i,n) cin >> a[i];
    REP(i,n) cin >> b[i];

    REP(i,n){
        if (b[i] > a[i] || (a[i] != b[i] && 2 * b[i] >= a[i])){
            cout << -1 << endl;
            return 0;
        }
    }

    VL x(n);
    REP(i,n) x[i] = 1LL << a[i];

    ll ans = 0;
    FORR(r,50,0){
        if (!check(x, r)){
            // cout << r << endl;
            ans += 1LL << (r + 1);
            REP(i,n){
                REP(j,51){
                    if ((x[i] >> j) & 1){
                        x[i] |= 1LL << (j % (r+1));
                    }
                }
            }
        }
    }

    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;
int n1,n2,n4,n,x;
int main()
{
    cin>>n;
    for(int i=1;i<=n;++i)
    {
        cin>>x;
        if(x%4==0) {++n4;continue;}
        if(x%2==0) {++n2;continue;}
        ++n1;
    }
    n2=n2%2;
    n1+=n2;
    if(n1-n4>1) cout<<"No";
    else cout<<"Yes";
    return 0;
}


Measured memory_bytes: 384
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: i64,
        k: i64,
    }

    let ans = n - k + 1;

    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
 
#define fio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define int long long
// #define double long double
// #define mp make_pair
// #define pb push_back
// Upper case English alphabet to lower case ch |= ' ';
// Lower case English alphabet to upper case ch &= '_’ ;
//__builtin_popcount(x)

int INF=(int)1e18+1,t=-1,till=0;
int gcd(int a, int b) { return b!=0 ? gcd(b, a % b) : a; }
// int digits(int n){return floor(log10(n))+1 ;}
// bool ispoweroftwo (int x) { return x && (!(x&(x-1))); }
//vector<int> vis,parent,ti,tout,dis;
// vector<vector<int> > adj;
// map<pair<int,int>,int> vis;
// vector<int> row={-1,1,0,0};
// vector<int> col={0,0,-1,1};
// //map<pair<int,int>,int> dp;
// int n=1;
// int th=0;

// int dfs(int r,int c,vector<vector<int> > board,vector<vector<int> > &dp){
//     vis[{r,c}]=1;
//     if(dp[r][c]!=-1){
//         return dp[r][c];
//     }
//     int t=1;
//     for(int i=0;i<4;i++){
//         int r1=r+row[i],c1=c+col[i];
//         if(r1>=0 && r1<n && c1>=0 && c1<n && 
//           !vis[{r1,c1}] && board[r][c]<board[r1][c1]){
//           t=max(t,1LL + dfs(r1,c1,board,dp));
//         }
//     }
//     vis[{r,c}]=0;
//     return dp[r][c]=max(t,dp[r][c]);
    
    
// }




signed main(){
    fio;
    string s,t;
    cin>>s>>t;
    int l1=s.length(),l2=t.length();
    string prev[l2+1];
    for(int i=0;i<=l2;i++) prev[i]="";
    string tmp="";
    for(int i=0;i<=l1;i++){
        string dp[l2+1];
        for(int j=0;j<=l2;j++){
            dp[j]="";
            if(i==0 || j==0){
                tmp=prev[j];
                prev[j]=dp[j];
                continue;
            }
            prev[j].length()>dp[j-1].length() 
            ? dp[j]=prev[j]:dp[j]=dp[j-1];
            if(s[i-1]==t[j-1]){
                string k=tmp+s[i-1];
                if(k.length()>dp[j].length()) dp[j]=k;
            }
            tmp=prev[j];
            prev[j]=dp[j];
        }
        
    }
    cout<<prev[l2]<<endl;

    


    
    


    

        
}


Measured memory_bytes: 8576
module Main where

import qualified Data.ByteString.Char8 as BS
import Data.Maybe
import Control.Monad

readInt = fst . fromJust . BS.readInt
getInt = readInt <$> BS.getLine

main :: IO ()
main = do
  h <- getInt
  w <- getInt
  n <- getInt
  print $ check (if h > w then h else w) n 1

check :: Int -> Int -> Int -> Int
check x n m = if x*m < n then check x n (m+1) else m


Measured memory_bytes: 380
from collections import Counter
n, m = map(int, input().split())
a = list(map(int, input().split()))
s = [0] * (n+1)
for i in range(n): s[i+1] = s[i] + a[i]
s = [x % m for x in s]
ans = 0
for x in Counter(s).values():
    ans += x * (x-1) // 2
print(ans)

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


using namespace std;


int main(){
  int N, M=0;
  cin >> N;
  vector<int> a(N), ans(N);
  for (int i=0; i<N; ++i) cin >> a[i];
  for (int i=1; i<N; ++i) {
    M ^= a[i];
  }
  ans[0] = M;
  M = M ^ a[0];
  for (int i = 1; i<N; ++i) {
    ans[i] = M ^ a[i];
  }
  for (int i = 0; i<N-1; ++i) cout << ans[i] << ' ';
  cout << ans[N-1] << endl;
  return 0;
}


Measured memory_bytes: 4680
data = {
        'S': [int(x) for x in range(1,14)],
        'H': [int(x) for x in range(1,14)],
        'C': [int(x) for x in range(1,14)],
        'D': [int(x) for x in range(1,14)],
        }
 
count = int(input())
 
for c in range(count):
    (s, r) = input().split()
    r = int(r)
    del data[s][data[s].index(r)]
 
for i in ('S', 'H', 'C', 'D'):
    for v in data[i]:
        print(i, v)

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

int main () {
  int n,m,c;
  cin >> n >> m >> c;
  int a[n][m],b[m];

  for(int j=0;j<m;j++) {
    cin >> b[j];
  }

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

  int sum[n] = {0};
  for(int i=0;i<n;i++) {
    for(int j=0;j<m;j++) {
      sum[i] += a[i][j] * b[j];
    }
  }

  int count = 0;
  for (int i=0;i<n;i++) {
    if(sum[i] + c > 0) count++;
  }

  cout << count << endl;
}


Measured memory_bytes: 256
use std::io;

fn main() {
	let mut buf = String::new();
	io::stdin().read_line(&mut buf).expect("");
	let mut iter = buf.split_whitespace();
	let a:i32 = match iter.next().unwrap().parse() {
		Ok(n) => n,
		_ => panic!(""),
	};
	let b:i32 = match iter.next().unwrap().parse() {
		Ok(n) => n,
		_ => panic!(""),
	};
	
	if a <= b*2 {
		println!("0");
	}else{
		println!("{}", a - 2*b);
	}
}

Measured memory_bytes: 4352
#include <iostream>
#include <string>
#define ll long long int

using namespace std;

ll calc(int *x, int n){
		ll res = 0;
		for(int i = 0; i < (1 << (n - 1)); i++){
				ll tmp = x[0];
				for(int j = 0; j < n - 1; j++){
						if((i >> j) % 2 == 0){
								tmp = tmp * 10 + x[j + 1];
						}else{
								res += tmp;
								tmp = x[j + 1];
						}
				}
				res += tmp;
		}
		return res;
}

int main(int argc, char const* argv[])
{
	string s;
	cin >> s;
	int *x = new int[s.size()];
	for(int i = 0; i < s.size(); i++){
			x[i] = s[i] - '0';
	}
	cout << calc(x, s.size()) << endl;
	return 0;
}


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

int main(){
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  int k;
  cin>>k;
  int e=60*a+b;
  int f=60*c+d;
  cout<<f-e-k<<endl;

}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std ; 
bool solve(int n,int k,int arr[]){
    bool dp[k+1] ; 
    dp[0] =false ; //if there is nothing to pick then taro loses . 
    
    for(int i = 1 ; i<=k ; i++){
        for(int j = 1; j<=n ; j++){
            if(i-arr[j]>=0){
            if(!dp[i-arr[j]]){
                dp[i] = true ; 
                break ; 
              }
            }
            if(j==n){
                dp[i] = false ; 
            }
        }
    }
    return dp[k] ; 
}
int main(){
        int n,k ; cin>>n>>k ; 
        int arr[n] ; 
        for(int i = 1 ; i<=n ; i++){
            cin>>arr[i] ; 
        }
       if(solve(n,k,arr)){
           cout<<"First" ; 
       }else{
           cout<<"Second" ;
       } 
       cout<<"\n" ;  
    

}

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

constexpr int MaxN = 100000;

int main()
{
	int N, M;
	cin >> N >> M;

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

	vector<int64_t> B(N);
	B[0] = A[0];
	for (int i = 1; i < N; ++i)
	{
		B[i] = A[i] + B[i-1];
	}

	map<int64_t, int64_t> num;
	for (int i = 0; i < N; ++i)
	{
		++num[B[i] % M];
	}

	int64_t sum = 0;
	for (auto n : num)
	{
		if (n.first == 0)
		{
			sum += n.second;
		}
		sum += n.second * (n.second - 1) / 2;
	}

	cout << sum << endl;

	return 0;
}

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

int main(int argc, char const *argv[])
{
	int n;
	cin>>n;
	int a,ans[n];
	for (int i = 0; i < n; ++i)
	{
		cin>>a;--a;
		ans[a]=i+1;
	}
	cout<<ans[0];
	for (int i = 1; i < n; ++i)
	{
		cout<<" "<<ans[i];
	}
	cout<<endl;
	return 0;
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define showmap(is, js, x) {rep(i, is){rep(j, js){cout << x[i][j] << " ";}cout << endl;}}
#define show(x) {for(auto i: x){cout << i << " ";} cout<<endl;}
#define showm(m) {for(auto i: m){cout << m.x << " ";} cout<<endl;}
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> llP;
ll gcd(int x, int y){ return y?gcd(y, x%y):x;}
ll lcm(ll x, ll y){ return (x*y)/gcd(x,y);}



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

    int lmax = 0;
    int len = 0;
    rep(i, s.size()){
        if (s[i] == 'R'){
            len++;
            lmax = max(lmax, len);
        } else {
            len=0;
        }
    }    
    cout << lmax << endl;
}


Measured memory_bytes: 3564
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for(ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF (1ll << 60)
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
using vl = vector<ll>;
using vvl = vector<vl>;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int MOD = 1000000007;
using ll = long long;
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;
}

void print(const std::vector<int> &v) {
    std::for_each(v.begin(), v.end(), [](int x) { std::cout << x << " "; });
    std::cout << std::endl;
}

int main() {
    ll N;
    cin >> N;
    // 4/N = 1/h + 1/n + 1/w;
    // Nhnwかけて
    // 4hnw = Nnw + Nhw + Nhn = N(nw + hw + hn)
    // w(4hn-Nn-Nh) == Nhn
    for(ll h = 1; h <= 3500; h++) {
        for(ll n = 1; n <= 3500; n++) {
            ll hoge = N * h * n;
            ll huga = 4 * h * n - N * n - N * h;
            if(huga <= 0LL) {
                continue;
            }
            if(hoge % huga == 0) {
                ll w = hoge / huga;
                if(w <= 0) {
                    continue;
                }
                cout << h << " " << n << " " << w << endl;
                return 0;
            }
        }
    }
}

Measured memory_bytes: 384
#!/usr/bin/env python3

n = int(input())

# TLE
# def fib(n):
#     if n == 0:
#         return 1
#     elif n == 1:
#         return 1
#     else:
#         return fib(n - 1) + fib(n - 2)
# print(fib(n))

dp = {}
dp[0] = 1
dp[1] = 1

for i in range(2, n + 1):
    dp[i] = dp[i - 1] + dp[i - 2]

print(dp[n])



Measured memory_bytes: 5600
n,b = input().split()
n = int(n)
b = int(b)

def base10to(n, b):
  if (int(n/b)):
    return base10to(int(n/b), b) + str(n%b)
  return str(n%b)

a = len(base10to(n,b))
print(a)

Measured memory_bytes: 2940
#include <iostream>
#include<stack>
using namespace std;
static const int N = 100;
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n, M[N][N];
int color[N], d[N], f[N], tt;
int nt[N];

int next(int u) {
	for (int v = nt[u]; v < n; v++) {
		nt[u] = v + 1;
		if (M[u][v])
			return v;
	}
	return -1;
}

void dfs_visit(int r) {
	for (int i = 0; i < n; i++)
		nt[i] = 0;
	stack<int> S;
	S.push(r);
	color[r] = GRAY;
	d[r] = ++tt;
	while (!S.empty()) {
		int u = S.top();
		int v = next(u);
		if (v != -1) {
			if (color[v] == WHITE) {
				color[v] = GRAY;
				d[v] = ++tt;
				S.push(v);
			}
		} else {
			S.pop();
			color[u] = BLACK;
			f[u] = ++tt;
		}
	}
}

void dfs() {
	for (int i = 0; i < n; i++) {
		color[i] = WHITE;
		nt[i] = 0;
	}
	tt = 0;

	for (int u = 0; u < n; u++) {
		if (color[u] == WHITE)
			dfs_visit(u);
	}
	for (int i = 0; i < n; i++) {
		cout << i + 1 << " " << d[i] << " " << f[i] << endl;
	}
}

int main() {
	int u, k, v;
	cin >> n;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++)
			M[i][j] = 0;
	}

	for (int i = 0; i < n; i++) {
		cin >> u >> k;
		u--;
		for (int j = 0; j < k; j++) {
			cin >> v;
			v--;
			M[u][v] = 1;
		}
	}

	dfs();

	return 0;
}


Measured memory_bytes: 3124
#include <bits/stdc++.h>
#include <vector>
#define rep(i,n) for(int i = 0; i < n; i++)
using ll = long long;
using namespace std;
int main(){
  int n,k;
  cin >> n >> k;
  int current = 1;
  rep(i, n){
    current += min(current, k);
  }
  cout << current << endl;
  return 0;
}

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

typedef long long ll;

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

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

  ll ans = 0;
  for(int i = 0; i < n; i++){
    ans += a[i] / 2;
    if(i < n-1)
      if(a[i] % 2 == 1 && a[i+1] > 0){
        a[i+1]--;
        ans++;
      }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#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()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(unique(all(x)), x.end());
typedef long long ll;
typedef complex<double> Complex;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

int main() {
    int n;
    ll k;
    cin >> n >> k;
    vector<int> g(n);
    rep(i, n) {
        int b;
        cin >> b;
        b--;
        g[i] = b;
    }

    if (k <= 1001001) {
        int now = 0;
        while (k--) {
            now = g[now];
        }
        cout << now + 1 << endl;
        return 0;
    }

    ll r;
    int v;
    vector<ll> d(n, -1);
    d[0] = 0;
    int now = 0;
    while (true) {
        if (d[g[now]] != -1) {
            r = d[now] - d[g[now]] + 1;
            v = g[now];
            break;
        }
        d[g[now]] = d[now] + 1;
        now = g[now];
    }

    k %= r;
    while (k < d[v]) k += r;

    now = 0;
    while (k--) {
        now = g[now];
    }
    cout << now + 1 << endl;
}


Measured memory_bytes: 5632
#include <iostream>
#include <string>
#include <cstdlib>//こいつを注意しろ！！！！

using namespace std;





int main(){

  int N;
  int t[1000000],x[1000000],y[1000000];
  cin>>N;
  t[0]=0;x[0]=0;y[0]=0;

  for(int i=1;i<=N;i++){
    cin>>t[i]>>x[i]>>y[i];

    int a=x[i]-x[i-1];
    a=abs(a);
    int b=y[i]-y[i-1];
    b=abs(b);
    //    int a=abs(x[i]-x[i-1]);
    //    int b=abs(y[i]-y[i-1]);
    int T=t[i]-t[i-1];
    if(((a+b)%2)==(T%2)&&(a+b)<=T)continue;
    else{
      cout<<"No"<<endl;
      return 0;
    }
  }
  cout<<"Yes"<<endl;

  return 0;
}


Measured memory_bytes: 8832
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>

using namespace std;

int main(void) {
	int A, B;
	cin >> A >> B;
	if (A + B >= A - B) {
		if (A + B >= A * B) {
			cout << A + B;
		}
		else {
			cout << A * B;
		}
	}
	else {
		if (A - B >= A * B) {
			cout << A - B;
		}
		else {
			cout << A * B;
		}
	}
}

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

int main() {
    int p[30];
    int n, cnt = 0;
    cin >> n;
    rep(i, n) { cin >> p[i]; }
    for (int i = 1; i < n - 1; ++i) {
        if ((p[i - 1] < p[i]) && (p[i] < p[i + 1])) {
            cnt++;
        } else if ((p[i - 1] > p[i]) && (p[i] > p[i + 1])) {
            cnt++;
        }
    }
    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 3584
#include <iostream>
#include <iomanip>
#include <cmath>
#include <vector>
#include <queue>
#include <limits>
#include <algorithm>
#include <string>
#include <set>
using namespace std;

int main()
{
	int32_t N;
	cin >> N;

	string res = "";

	int32_t sign = 1;
	while (N != 0) {
		if (N % 2 == 0) {
			res = "0" + res;
		} else {
			res = "1" + res;
			N -= sign;
		}
		N /= 2;
		sign *= -1;
	}

	if (res == "")
		res = "0";

	cout << res << endl;

	return 0;
}


Measured memory_bytes: 256
N, Q = map(int, input().split())
l = [list(map(int, input().split())) for i in range(Q)]

s_ids = []
m_ids = []

for i in range(Q):
    s_ids.append(l[i][0])
    m_ids.append(l[i][1])

max_s_id = max(s_ids)
min_m_id = min(m_ids)

# diff = abs(max_s_id - min_m_id)
# print(diff+1)

if max_s_id <= min_m_id:
    print(abs(max_s_id - min_m_id) +1)
else:
    print(0)


Measured memory_bytes: 29100
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;

#define rep(i, e) for (int i = 0; i < e; i++)
#define repp(i, s, e) for (int i = s; i < e; i++)
#define N_Max 100
#define Card_Max 36
#define ll long long

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

int main()
{
    string n;
    int sum=0;
    cin>>n;
    rep(i,n.size()){
        int num = n[i] - '0';
        sum += num%10;
        num/=10;
    }
    if(stoi(n)%sum==0){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
}

Measured memory_bytes: 256
#include<cstdio>
int main(){
	int n,ans=0;
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		int x;
		scanf("%d",&x);
		while(x%2==0){
			ans++;
			x/=2;
		}
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 128
def solve(W):
    set_W = set(W)
    if len(W) != len(set_W):
        return False

    for i in range(len(W) - 1):
        if W[i][-1] != W[i + 1][0]:
            return False

    return True


N = int(input())
W = [input() for _ in range(N)]

if solve(W):
    print("Yes")
else:
    print("No")


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

using namespace std;
 
#define  fastio         ios:: sync_with_stdio(0);cin.tie(0);cout.tie(0);cout<<fixed;cout<<setprecision(10);
#define  f              first                 
#define  s              second
#define  endl           "\n"
#define  pb             push_back  
#define  mset(a,x)      memset(a,x,sizeof(a))
#define  debv(a)        for(auto it: a)cout<<it<<" ";cout<<endl;
#define  deb1(a)        cout<<a<<endl;
#define  deb2(a,b)      cout<<a<<" "<<b<<endl;
#define  deb3(a,b,c)    cout<<a<<" "<<b<<" "<<c<<endl;
#define  deb4(a,b,c,d)  cout<<a<<" "<<b<<" "<<c<<" "<<d<<endl;            
          
 
typedef  long long             ll;
typedef  long double           ld;
typedef  pair<ll,ll>           pll;
typedef  vector<ll>            vll;
typedef  unordered_map<ll,ll>  um;
typedef  vector<pll>           vpll;
 
const ll   N     =  5e5+5;
const ll   mod   =  998244353;
const ll   INF   =  1e18;
const int  INFi  =  0x7f7f7f7f;

ll test = 1, n, q, a[N], s = 0;
map <ll,ll> m;

void solve(){
    cin>>n;
    for(int i = 0; i < n; i++) cin>>a[i], m[a[i]]++, s += a[i];
    cin>>q;
    while(q--){
        int b,c;
        cin>>b>>c;
        s -= m[b]*b;
        s += m[b]*c;
        m[c] += m[b];
        m[b] = 0;
        deb1(s)
    }
}

int main(){
    fastio;
    //cin>>test;
    for(int i = 1; i <= test; i++){
        solve();
    }
}

Measured memory_bytes: 10352
N,X,Y = gets.chomp.split.map(&:to_i)
line = [0] * N

(1..N).each do |i|
  (i+1..N).each do |j|
    cnt = j - i
    count = (X - i).abs + 1 + (j - Y).abs
    if count < cnt
      cnt = count
    end
    line[cnt-1] += 1
  end
end

puts line[0..N-2]

Measured memory_bytes: 1788
#include <iostream>
#include <string>
#include <map>
using namespace std;

string to[] = {"100101","10011010","0101","0001","110","01001","10011011","010000","0111","10011000","0110","00100","10011001","10011110","00101","111","10011111","1000","00110","00111","10011100","10011101","000010","10010010","10010011","10010000","101","000000","000011","10010001","010001","000001"};

int main(){
	string s;
	map<char,string> tm;
	map<string,char> fm;
	for(int i = 0;i < 26;i++){
		tm[i + 'A'] = to[i];
		string tmp = "";
		for(int j = 4;j >= 0;j--) tmp += to_string((i >> j) & 1);
		fm[tmp] = i + 'A';
	}
	tm[' '] = to[26];
	tm['\''] = to[27];
	tm[','] = to[28];
	tm['-'] = to[29];
	tm['.'] = to[30];
	tm['?'] = to[31];
	fm["11010"] = ' ';
	fm["11011"] = '.';
	fm["11100"] = ',';
	fm["11101"] = '-';
	fm["11110"] = '\'';
	fm["11111"] = '?';
	while(getline(cin,s)){
		string t = "";
		for(int i = 0;i < s.length();i++) t += tm[s[i]];
		for(int i = (t.length() + 4) % 5 + 1;i < 5;i++) t += "0";
		for(int i = 0;i < t.length() / 5;i++) cout << fm[t.substr(i * 5,5)];
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 3228