akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>

int main() {
	int n, k, i;
	char s[50];

	scanf("%d %d", &n, &k);
	scanf("%s", s);

	k -= 1;

	if (s[k] == 'A')
		s[k] = 'a';
	if (s[k] == 'B')
		s[k] = 'b';
	if (s[k] == 'C')
		s[k] = 'c';

	i = 0;
	while (s[i] != '\0') {
		printf("%c", s[i]);
		i++;
	}

	printf("\n");
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
template<typename T> istream& operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T> ostream& operator<<(ostream &os, const vector<T> &vec){ os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream& operator<<(ostream &os, const set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream& operator<<(ostream &os, const unordered_set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream& operator<<(ostream &os, const multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream& operator<<(ostream &os, const unordered_multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T1, typename T2> ostream& operator<<(ostream &os, const pair<T1, T2> &pa){ os << "(" << pa.first << "," << pa.second << ")"; return os; }
template<typename TK, typename TV> ostream& operator<<(ostream &os, const map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename TK, typename TV> ostream& operator<<(ostream &os, const unordered_map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename T> void ndarray(vector<T> &vec, int len) { vec.resize(len); }
template<typename T, typename... Args> void ndarray(vector<T> &vec, int len, Args... args) { vec.resize(len); for (auto &v : vec) ndarray(v, args...); }
template<typename T> void Max(T &m, const T q) { if (m < q) m = q; }
template<typename T> void Min(T &m, const T q) { if (m > q) m = q; }
template<typename T1, typename T2> pair<T1, T2> operator+(pair<T1, T2> &l, pair<T1, T2> &r) { return make_pair(l.first + r.first, l.second + r.second); }
template<typename T1, typename T2> pair<T1, T2> operator-(pair<T1, T2> &l, pair<T1, T2> &r) { return make_pair(l.first - r.first, l.second - r.second); }
#define dbg(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ") " << __FILE__ << endl;

int H, W, N;
map<int, set<int>> D;

int main()
{
    cin >> H >> W >> N;
    REP(_, N)
    {
        int x, y;
        cin >> x >> y;
        D[x - 1].insert(y - 1);
    }

    int r = 0;
    REP(t, H)
    {
        if (D[t + 1].size() == 0)
        {
            r++;
            continue;
        }
        if (*D[t + 1].begin() <= r)
        {
            cout << t + 1 << endl;
            return 0;
        }
        if (*D[t + 1].begin() > r + 1) r++;
    }
    cout << H << endl;
}


Measured memory_bytes: 28416
mod = 10**9+7
s = input()
n = len(s)
dp = [[0]*13 for _ in range(n+1)]
dp[0][0] = 1

for i in range(n):
    for j in range(10):
        if s[i] != "?" and int(s[i]) != j: continue
        for k in range(13):
            dp[i+1][(k*10+j)%13] += dp[i][k]
    for j in range(13):
        dp[i+1][j] %= mod
        
# for i in range(n+1): print(dp[i])
print(dp[n][5])

Measured memory_bytes: 61788
H = int(input())

last_index = H + 1

keys = [None] + input().split()

for i in range(1, last_index):
    print('node {0}: '.format(i), end = '')
    print('key = {0}, '.format(keys[i]), end = '')
    if i != 1:
        print('parent key = {0}, '.format(keys[i // 2]), end = '')
    left_index = i * 2
    if left_index < last_index:
        print('left key = {0}, '.format(keys[left_index]), end = '')
    right_index = left_index + 1
    if right_index < last_index:
        print('right key = {0}, '.format(keys[right_index]), end = '')
    print('')

Measured memory_bytes: 7688
#include <iostream>
#include <iomanip> //! for setprecision(10)
#include <math.h>
#include <algorithm>
#include <functional> 
#include <string>
#include <vector>

#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <utility>

using namespace std;

typedef long long LL;

#define dump(c) { for (auto it = c.begin(); it != c.end(); ++it) if (it == c.begin()) cout << *it; else cout << ' ' << *it; cout << endl; } 
#define rep(i,n) for (int i = 0; i < (n); ++i)

const int MOD = 1000000007;

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

    LL T1, T2, A1, A2, B1, B2;
    cin >> T1 >> T2 >> A1 >> A2 >> B1 >> B2;

    LL a1 = T1 * A1;
    LL a2 = a1 + T2 * A2;

    LL b1 = T1 * B1;
    LL b2 = b1 + T2 * B2;

    if (a2 == b2) {
        cout << "infinity" << endl;
        return 0;
    }

    if (a2 < b2) {
        swap(a1, b1);
        swap(a2, b2);
    }

    LL ans = 0;
    if (a1 < b1) {
        ans = 2 * ((b1 - a1) / (a2 - b2)) + 1;
        if ((b1 - a1) % (a2 - b2) == 0) {
            --ans;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
"""
challenge case

in:
3
1 3
2 3

out:
1
1
1
"""

from collections import deque

def main():
	N, *AB = map(int, open(0).read().split())
	B = AB[1::2]

	E = [[] for _ in range(N + 1)]
	for a, b in zip(*[iter(AB)] * 2):
		E[a] += b,

	Q = deque([1])
	C = [0] * (N + 1)
	while Q:
		v = Q.popleft()
		c = 0
		for u in E[v]:
			c += 1 + (c + 1 == C[v])
			C[u] = c
			Q += u,

	print(max(C))
	for b in B:
		print(C[b])

main()

Measured memory_bytes: 25900
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  loop(i,0,n)
#define all(c) c.begin(),c.end()
#define vi vector<int>
#define vl vector<ll>
#define pll pair<ll,ll>
#define vpll vector<pll>

int main(){
    int A[5];
    int k;
    cin>>A[0]>>A[1]>>A[2]>>A[3]>>A[4];
    cin>>k;
    if(A[4]-A[0]>k)cout<<":("<<endl;
    else cout<<"Yay!"<<endl;
}

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

int main() {
    int64_t A, B, C, D;
    string ans;
    cin >> A >> B >> C >> D;
    while (1) {
        C -= B;
        if (C <= 0){
            ans = "Yes";
            break;
        }
        A -= D;
        if (A <= 0){
            ans = "No";
            break;
        }
    }
    cout << ans << endl;   
    return 0;
}


Measured memory_bytes: 3624
import java.io.*;
import java.util.*;

public class Main {

	static ArrayList<ArrayList<Integer> >ve ; 
	static int dp[] ; 
	static void dfs(int i)
	{
		ArrayList<Integer> u = ve.get(i) ; 
		if(u.size()!=0)
		{
			int y = 0 ;
			for(int ele : u)
			{
				if(dp[ele]==0)
				{
					dfs(ele) ; 	
				}
				int va = dp[ele] ; 
				y = Integer.max(y, va) ; 
				
			}
	        dp[i]= y+1 ; 
		}
				
	}
	public static void main(String[] args) throws Exception{
		BufferedReader  jk =  new BufferedReader(new InputStreamReader( System.in))  ; 
		PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out)) ; 
		StringTokenizer ana = new StringTokenizer(jk.readLine()) ;
		int n =Integer.parseInt(ana.nextToken()) ; 
		int m = Integer.parseInt(ana.nextToken()) ;
		dp = new int[n] ;  
		ve = new ArrayList<>() ; 
		boolean v[] = new boolean[n] ; 
		for(int i=0 ; i<n ;i++) ve.add(new ArrayList<>()) ; 
		for(int i=0 ; i<m ;i++)
		{
			ana = new StringTokenizer(jk.readLine()) ;
			int x= Integer.parseInt(ana.nextToken())-1 ; int y= Integer.parseInt(ana.nextToken())-1 ; 
			ve.get(x).add(y) ; 
			v[y]=true ;

		}
		for(int i=0 ; i<n ;i++)
		{
			if(!v[i]) 	dfs(i) ; 
		}



		int y = 0 ;
		for(int i=0 ; i<n ;i++)
		{
			if(dp[i]>y) y=dp[i] ; 
		}

		out.println(y);



		out.flush();
	}
}



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


int main() {
	int N;
	cin >> N;
	int num = 0;
	while (true) {
		if (num * 1000 >= N)break;
		num++;
	}
	cout << 1000 * num - N << endl;
	return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <cmath>

#define lint long long int
using namespace std;

lint Solve(lint N, lint X) {
    if (!N || !X)
        return 0;
    
    //cout << "Solve(" << N << ", " << X << ") - Type ";
    if (2 * X <= N) {
        //cout << "1" << endl;
        return 3 * X       + Solve(N - X, N - 2 * X);
    }
    else {
        //cout << "2" << endl;
        lint C = X / (N - X);
        return X + (N - X) * (3 * C + 1) - N + Solve(N - (N - X) * C, N - (N - X) * (C + 1));
    }
}

void Stress() {
    static const lint NMAX = 1000000000000LL;
    static const double MAGIC = (3 - sqrt(5)) * 0.5;

    lint N = NMAX;
    lint X = N * MAGIC;

    cout << Solve(N, X) << '\n';
}

void Submit() {
    lint N, X;
    cin >> N >> X;

    cout << Solve(N, X) << '\n';
}

int main() {
    //Stress();
    Submit();

    return 0;
}

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

using namespace std;

using LL = long long;

template<typename T>
ostream& operator << (ostream& out, const vector<T>& v) {
    out << "[";
    for(const auto& x : v) {
        out << x << ", ";
    }
    return out << "]";
}

template<typename S, typename T>
ostream& operator << (ostream& out, const pair<S, T>& p) {
    return out << "{" << p.first << ", " << p.second << "}";
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
    string a, b;
    cin >> a >> b;
    int ans = 0;
    for(int i = 0; i < int(a.length()); ++i) {
        ans += (a[i] != b[i]);
    }
    cout << ans << "\n";
    
    
    return 0;
}


Measured memory_bytes: 3776
/*
    Mbak Sana Dong
    Mbak Chaeyoung Dong
*/
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
struct angka
{
    int bal, mini, o;
    string s;
};
struct angka nodeL[1000010], nodeR[1000010];
int chaeng;
bool desc(struct angka a, struct angka b)
{
    return a.mini > b.mini;
}
bool asc(struct angka a, struct angka b)
{
    return a.o > b.o;
}
int main()
{
	int n,i,j,k,x,y,ans,curr,temp,m;
	int tc;
	cin >> n;
    string s;
    chaeng = 0;
    int pos = 0, neg = 0;
    for(i=1;i<=n;i++) {
        cin >> s;
        int bal = 0;
        int mini = 0;
        int o = 0;
        for(auto x : s) {
            if(x == '(') {
                bal++;
                o++;
            }
            else {
                bal--;
                if(o) o--;
            }
            mini = min(mini, bal);
        }
        chaeng += bal;
        if(bal >= 0) {
            nodeL[pos].bal = bal;
            nodeL[pos].mini = mini;
            nodeL[pos].o = o;
            nodeL[pos].s = s;
            pos++;
        } else {
            nodeR[neg].bal = bal;
            nodeR[neg].mini = mini;
            nodeR[neg].o = o;
            nodeR[neg].s = s;
            neg++;
        }
    }
    if(chaeng != 0) {
        cout << "No" << endl;
        return 0;
    }
    sort(nodeL, nodeL + pos, desc);
    sort(nodeR, nodeR + neg, asc);
    for(i=0;i<pos;i++) {
        s = nodeL[i].s;
        for(auto x : s) {
            if(x == '(') chaeng++;
            else chaeng--;
            if(chaeng < 0) {
                cout << "No" << endl;
                return 0;
            }
        }
    }
    for(i=0;i<neg;i++) {
        s = nodeR[i].s;
        for(auto x : s) {
            if(x == '(') chaeng++;
            else chaeng--;
            if(chaeng < 0) {
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout << "Yes" << endl;
	return 0;
}


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


using namespace std;

using ll   = long long;
using ii   = pair   < int , int >;
using i3   = pair   < int , ii  >;
using li   = pair   < ll  , int >;
using lii  = pair   < ll  , ii  >;
using pll  = pair   < ll  , ll  >;
using vi   = vector < int       >;
using vl   = vector < ll        >;
using vii  = vector < ii        >;
using vpll = vector < pll       >;
using vi3  = vector < i3        >;
using vlii = vector < lii       >;


const int N = 1;
const ll INF = 1e17 + 7;
const double eps = 1e-9 , PI = acos(-1);



int n , m;


void solve(int testCase){

    scanf("%d" , &n);

    string s;
    cin >> s;

    for(int i = 0 ; s[i] ; i ++){
            s[i] = char((int(s[i] - 'A') + n) % 26) + 'A';
    }

    cout << s << endl;


}

main(){

    int t = 1;
    //scanf("%d" , &t);

    for(int testCase = 1 ; testCase <= t ; testCase ++){
            solve(testCase);
    }

    return 0;
}


Measured memory_bytes: 384
# from math import factorial,sqrt
# from itertools import permutations as permus
# from fractions import gcd
# from collections import deque,Counter

# import numpy as np
# import scipy as scp

# 入力の受け取り
k = int(input())

arr = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]

ans = arr[k-1]

print(ans)
# print("{:.10f}".format(ans))


Measured memory_bytes: 2940
s = input()

a = 1
ans = 1

for i in s:
    if a%2 == 0:
        if i == "R":
            print("No")
            ans = 0
            break
    if a%2 == 1:
        if i == "L":
            print("No")
            ans = 0
            break
    a += 1
    
if ans == 1:
    print("Yes")

Measured memory_bytes: 3060
n = gets.chomp.to_i
infos = n.times.map do
  gets.chomp.split.map(&:to_i)
end

height_non_zero_info = infos.find{|info| !info.last.zero?}
# 総当りで計算を行っても101 * 101 * 100で間に合うので。

101.times do |x|
  101.times do |y|
    vertex_height = height_non_zero_info[2] + (x - height_non_zero_info[0]).abs + (y - height_non_zero_info[1]).abs
    flg = true

    infos.each do |info|
      manhattan_distance = (x - info[0]).abs + (y - info[1]).abs
      height = vertex_height - manhattan_distance <= 0 ? 0 : vertex_height - manhattan_distance
      if height != info[2]
        flg = false
        break
      end
    end

    if flg
      puts "#{x} #{y} #{vertex_height}"
      exit
    end
  end
end

Measured memory_bytes: 14328
#include<stdio.h>

int main(void)
{
    int n , pm, pe , pj , i ;

    while(scanf("%d",&n)&&n!=0)
    for(i=0;i<n;i++){
        scanf("%d%d%d",&pm,&pe,&pj);
        if((pm==100)||(pe==100)||(pj==100)||((pm+pe)/2>=90)||((pm+pe+pj)/3>=80)){
            printf("A\n");
        } else if(((pm+pe+pj)/3>=70)||((((pm+pe+pj)/3)>=50)&&((pm>=80)||(pe>=80)))){
            printf("B\n");
        } else {
            printf("C\n");
        }
    }
    return 0 ;
}

Measured memory_bytes: 584
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
int main()
{
    int n;
    cin>>n;
    int ans=0;
    int a[55];
    for(int i=0;i<n;i++)
        cin>>a[i];
    for(int i=0;i<n;i++)
        ans+=a[i];
    ans=ans*ans;
    for(int i=0;i<n;i++)
        ans-=a[i]*a[i];
    ans/=2;
    cout<<ans<<'\n';
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (ll i = 0; i < (ll)n; i++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
using namespace std;
typedef long long int ll;
typedef vector<int > vecint;
typedef vector<ll > vecll;
typedef vector<vector<int > > vec2int;
typedef vector<bool > vecbool;
typedef vector<string > vecstr;
////////////////////////////////////////////////
int main()
{
  ll h, w;
  cin >> h >> w;
  ll ans = 0;
  if(h%3 ==0 ||w%3 ==0){
    cout << 0 << endl;
    return 0;
  }
  if(h == 2&&w == 2){
    cout << 1 << endl;
    return 0;
  }
  ans = min(h,w);
  ll tmp1 = 0;
  ll tmp2 = 0;
  ll tmp3 = 0;
  ll tmp = 0;
  for(int i = 1; i <= w - 1; i++){
    tmp1 = i*h;
    tmp2 = (w - i)*(h/2);
    tmp3 = (w - i)*(h - h/2);
    tmp = max(tmp1, tmp3) - min(tmp1,tmp2);
    ans = min(ans, tmp);
  }
  for(int i = 1; i <= h - 1; i++){
    tmp1 = i*w;
    tmp2 = (h - i)*(w/2);
    tmp3 = (h - i)*(w - w/2);
    tmp = max(tmp1, tmp3) - min(tmp1, tmp2);
    ans = min(ans, tmp);
    // if(ans == tmp){
    //   cout << i << " "<<tmp1 <<" " << tmp2 << " " << tmp3 << endl;
    // }
  }
  cout << ans << endl;


}


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

int main() {
    ll N;
    cin >> N;
    vector<vector<pair<ll, ll>>> nodes(N);
    ll u, v, w;
    rep(i, N - 1) {
        cin >> u >> v >> w;
        nodes[u - 1].push_back(make_pair(v - 1, w));
        nodes[v - 1].push_back(make_pair(u - 1, w));
    }

    vector<bool> ans(N, 0);
    queue<ll> vis;
    unordered_set<ll> visited;
    vis.push(0);
    visited.insert(0);
    while (vis.size() > 0) {
        ll now = vis.front();
        vis.pop();
        for (auto to : nodes[now]) {
            if (visited.count(to.first) > 0) continue;
            if (to.second % 2 == 1)
                ans[to.first] = !ans[now];
            else
                ans[to.first] = ans[now];
            vis.push(to.first);
            visited.insert(to.first);
        }
    }
    for (int a : ans) cout << a << "\n";
    cout << flush;
    return 0;
}


Measured memory_bytes: 12068
#include <bits/stdc++.h>
using namespace std;
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long
#define ld long double
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
const int mod = 1e9 + 7;
int main()
{
	SPEED
	string s, t;
	cin >> s;
	for (int i = 0; i < s.length(); ++i)
	{
		s[i]='x';
	}
	cout << s;
	return 0;
}

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

using namespace std;

int main(){
  int N,gendo,nino=0,saigo=0,fg=0;
  long long int num;
  cin>>N;
  vector<long long int> a;

  for(int i=0;i<N;i++){
    cin>>num;
    a.push_back(num);
  }

  gendo=N/2;
  if(N%2!=0){
    gendo++;
  }
  num=0;

  for(int i=0;i<N;i++){
    if(a[i]%4!=0){
      if(a[i]%2==0){
        nino++;
        if(nino==2){
          num--;
        }
        if(nino>=2){
          num--;
          gendo=(N-nino)/2;
          if((N-nino)%2!=0){
            gendo++;
          }
        }
      }
      num++;
      if(gendo<num){
          break;
      }
    }else{
      fg=1;
    }
  }
  saigo=N-nino;
  if(saigo%2!=0 && nino>=2){
    if(gendo==num){
      gendo=0;
    }
  }

  //cout<<gendo<<"aaa"<<num<<endl;


  if(gendo<num){
    cout<<"No"<<endl;
  }else{
    if(fg==0 && nino!=N){
      cout<<"No"<<endl;
    }else{
      cout<<"Yes"<<endl;
    }
  }

  return 0;
}


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

#define FOR0(i,n) for (int i = 0; i < n; i++)
#define FOR(i,j, n) for (int i = j; i < n; i++)
// bool isEven(ll n) {return (n%2!=0)?false:true;};
#define INF 1000000000 // 1 billion, safer than 2B for Floyd Warshall’s

#define f(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define vi vector< int >
#define vl vector< ll >
#define ss second
#define ff first
#define ll long long
#define pii pair< int,int >
#define pll pair< ll,ll >
#define sz(a) a.size()
#define inf (1000*1000*1000+5)
#define all(a) a.begin(),a.end()
#define tri pair<int,pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod (1000*1000*1000+7)
#define pqueue priority_queue< int >
#define pdqueue priority_queue< int,vi ,greater< int > >
// #define int ll


using namespace std;
typedef pair<int, pair<int, int> > ppp;

//leetcode

int main()
{
  int a, b;
  cin>>a>>b;

  int c = max(a, b);
  int d = min(a, b);
  
  string s = "";
  for(int i =0; i<c; i++)
    s+=to_string(d);
  cout<<s<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
  using namespace std;
  #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  #define endl "\n"
  #define int long long
  #define all(v) v.begin(),v.end()
  #define f first
  #define s second
  #define PB push_back
  #define MP make_pair
  #define double long double
  #define trace1(x)                cerr<<#x<<": "<<x<<endl
  #define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
  #define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
  #define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
  #define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
  #define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
  #define cases int testcases;cin>>testcases; while(testcases--)
  #define MOD 998244353
  #define N 1000001
  #define INF 1000000000000
  #define eps 1e-6



int32_t main()
{


  int n;
  cin >> n;
  map<string,int> mp;

  for(int i = 1; i <= n; i++)
  {
    string s;
    cin >> s;
    mp[s]++;
  }


  int a = 1;

  for(auto i :mp)
  {
    a = max(a,i.second);
  }

  for(auto i:mp)
  {
    if(i.s == a)
    {
      cout << i.f << endl;
    }
  }

    return 0;
}

Measured memory_bytes: 25216
import functools

import math

@functools.lru_cache()
def combinations(n, r):
    return math.factorial(n) / math.factorial(r) / math.factorial(n - r)


def main():
    n, p = map(int, input().split())
    a = tuple(map(lambda x: int(x) % 2, input().split()))

    if n == 1 and a[0] % 2 != p:
        print(0)
        return 0

    t = len(tuple(filter(lambda x: x == 1, a)))
    f = n - t

    count = 0

    if p == 0:
        for i in range(t + 1):
            if i % 2 == 0:
                c = 0
                for j in range(f + 1):
                    c += combinations(f, j)
                count += combinations(t, i) * c
    else:
        for i in range(t + 1):
            if i % 2 == 1:
                c = 0
                for j in range(f + 1):
                    c += combinations(f, j)
                count += combinations(t, i) * c

    print(int(count))

    return 0

if __name__ == '__main__':
    main()


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

long long f(long long);

int main()
{
	long long A, B;
	scanf("%lld%lld", &A, &B);
	printf("%lld\n", f(A - 1) ^ f(B));

	return 0;
}

long long f(long long max)
{
	if (max == 0 || max == -1) return 0;
	long long sum{};
	if ((max - 1) % 4 < 2) sum = 1;
	for (int i{1}; i < 50; i++)
	{
		long long one{1LL << i};
		if (max % (2 * one) < one) continue;
		if (~max & 1) sum |= one;
	}
	return sum;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll     = long long;
using pii    = pair<int, int>;
using pll    = pair<ll, ll>;
using vi     = vector<int>;
using vl     = vector<ll>;
using vvi    = vector<vi>;
using vvl    = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}
template <class C>
void print(const C &c, std::ostream &os = std::cout) {
    std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, " "));
    os << std::endl;
}

int main() {
    int l;
    cin >> l;
    ll twoes = 1;
    ll nt    = 0;
    while (1 << (nt + 1) <= l) {
        nt++;
    }
    nt--;
    vi a, b, c;
    // 0 to 1 << (i+1) - 1
    for (int i = 0; i <= nt; ++i) {
        a.push_back(i);
        b.push_back(i + 1);
        c.push_back(0);
        a.push_back(i);
        b.push_back(i + 1);
        c.push_back(1 << i);
    }
    // 1 << (i+1) to l - 1
    for (int i = nt; i >= 0; --i) {
        if (l - (1 << (nt + 1)) >= 1 << (i)) {
            a.push_back(i);
            b.push_back(nt + 1);
            c.push_back(l - (1 << (i)));
            l -= (1 << (i));
        }
    }
    cout << nt + 2 << " " << a.size() << "\n";
    for (int i = 0; i < a.size(); ++i) {
        cout << a[i] + 1 << " " << b[i] + 1 << " " << c[i] << "\n";
    }
    return 0;
}

Measured memory_bytes: 256
import Control.Applicative ((<$>), (<*>))
import Control.Monad
import Data.List

main :: IO ()
main = do
  [n,a,b] <- getl $ map read . words
  solve n a b <$> getl (map read . words) >>= print

solve :: Int -> Int -> Int -> [Int] -> Int
solve n a b xs = foldl f 0 ds
  where
    ds = zipWith (-) (tail xs) xs
    f s x = if x * a > b then s + b else s + x * a

getl :: (String -> a) -> IO a
getl f = f <$> getLine


Measured memory_bytes: 36220
from sys import stdin

n = int(stdin.readline().rstrip())
s = stdin.readline().rstrip()
t = stdin.readline().rstrip()
# A, B, C = [int(x) for x in stdin.readline().rstrip().split()]
# data = [stdin.readline().rstrip().split() for _ in range(n)]

ans = 2 * n
for i in range(n, 0, -1):
    if s[n-i:] == t[:i]:
        ans -= i
        break
print(ans, '\n')
# print(*data, sep='\n')


Measured memory_bytes: 38256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pint = pair<int,  int>;
using pll = pair<ll, ll>;
using edge = pair<int, ll>;
using Graph = vector<vector<int>>; 
using WeightedGraph = vector<vector<edge>>;
const ll INF = 1LL << 60;
const int INF32 = 1 << 29;
const ll MOD = 1000000007;

int main(){
  ll n,k;cin >> n >> k;
  vector<ll> a(n), sum(n+1);
  for(int i = 0; i < n; ++i){
    cin >> a[i];
    --a[i];
    a[i]%=k;
    sum[i+1]=sum[i]+a[i];
    sum[i+1]%=k;
  }
  
  ll ans = 0;
  map<int, int> mp;
  for(int i = 0; i <= n; ++i){
    if(i>=k)--mp[sum[i-k]];
    ans += mp[sum[i]];
    ++mp[sum[i]];
  }
  cout << ans << endl;
}


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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


int nextInt() { int x; scanf("%d", &x); return x;}

int main2() {
  int N = nextInt();
  for (int i = 111; ; i += 111) {
    if (i >= N) {
      cout << i << endl;
      return 0;
    }
  }
  return 0;
}

int main() {
  for (;!cin.eof();cin>>ws)
    main2();
  return 0;
}


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

int main()
{
    int n;
    cin>>n;
    vector<double> dp(n+1);
    dp[0] = 1;
    for(int coins=0;coins<n;coins++){
        double p_heads;
        cin>>p_heads;
        for(int i=coins+1;i>=0;i--){
            dp[i] = ((i==0)?0:dp[i-1]*p_heads) + dp[i]*(1-p_heads);
        }
    }
    double answer = 0;
    for(int heads= 0;heads<=n;heads++){
        int tails = n-heads;
        if(heads>tails)
            answer += dp[heads];
    }
    cout<<std::setprecision(10);
    cout<<answer;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <deque>
using namespace std;

#define next '\n'
#define sp " "
#define print(x) cout << (x)
#define println(x) cout << (x) << next
#define stop return(0)
#define rep(i, n) for(int (i) = (0); (i) < (n); (++i))
#define FOR(i, start, end) for(int (i) = (start); (i) < (end); (++i))
#define foreach(e, elem) for(auto& (e) : (elem))
#define FAST ios::sync_with_stdio(false); cin.tie(nullptr)
#define size(s) (s).size()
#define all(vec) (vec).begin(), (vec).end()
#define pb(e) push_back(e);
#define INF 1e+8
#define PI acos(-1)
#define MOD 100000009
using ll = long long;
using ull = unsigned long long;

int dp[100010];

int main(){
    int n;
    cin >> n;
    vector<int> h(n);
    rep(i, n){
        cin >> h[i];
    }

    rep(i, n + 1){
        dp[i] = INF;
    }

    dp[0] = 0;
    for(int i = 1; i < n + 1; ++i){
        if(i == 1){
            dp[i] = abs(h[i] - h[i - 1]);
            continue;
        }

        dp[i] = min(
                dp[i - 1] + abs(h[i] - h[i - 1]),
                dp[i - 2] + abs(h[i] - h[i - 2]));
    }

    println(dp[n - 1]);
}

Measured memory_bytes: 1024
n,x = map(int,input().split())
li=map(int,input().split())
num = 0
cnt = 0
for i in li:
  num += i
  cnt += 1
  if num > x:
    print(cnt)
    break
  elif cnt == n:
    print(n+1)
    break
  else:
    pass

Measured memory_bytes: 2940
#include <iostream>
#include <stdio.h>

using namespace std;

int main() {
  char x[1000000];
  int stack[100];
  int temp;
  int top_index = 0;

  while (cin >> x) {
    // for (int i = 0; i < top_index; i ++)
    //   cout << stack[i] << " ";
    // cout << top_index << " " << x << endl;
    switch (x[0]) {
      case '+':
        top_index--;
        stack[top_index - 1] += stack[top_index];
        break;
      case '-':
        top_index--;
        stack[top_index - 1] -= stack[top_index];
        break;
      case '*':
        top_index--;
        stack[top_index - 1] *= stack[top_index];
        break;
      default:
        // cout << (int)x << endl;
        sscanf(x, "%d", &stack[top_index]);
        top_index ++;
    }
  }
  cout << stack[0] << endl;
  return 0;
}



Measured memory_bytes: 3228
#define _GLIBCXX_DEBUG
#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 = 1; i < (int)(n); i++) 
#define dunk(n) cout << n << endl
#define all(a) (a).begin(),(a).end()
typedef pair<int,int> P;
typedef long long ll;

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    int m = a[0];
    int ans = 1;
    rrep(i,n){
        if(a[i] <= m){
            ans++;
            m = a[i];
        }
    }
    dunk(ans);
    return 0;
}

Measured memory_bytes: 3980
import java.util.*;

public class Main {


    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        int K = sc.nextInt();

        int deved =0;

        for(int i=100;i>0;i--){
            if(A % i == 0 && B % i == 0){
                deved++;
            }
            if(deved == K){
                System.out.println(i);
                System.exit(0);
            }

        }


    }


}


Measured memory_bytes: 22868
#include<bits/stdc++.h>
#define int long long
using namespace std;
template<class T> inline bool chmax(T& a, T b){ if(a<b){ a=b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b){ if(a>b){ a=b; return 1; } return 0; }


signed main()
{
    int N,K; cin>>N>>K;
    cout<<N-K+1<<endl;
}


Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <stdio.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second
#define mp make_pair
 
const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int main(){
  int X, Y; cin >> X >> Y;

  for (int i = 0; i <= X; i++){
    int now = i * 2 + (X - i) * 4;
    if (now == Y){
      Yes(); return 0;
    }
  }
  No();

  return 0;
}


Measured memory_bytes: 3624
#include <iostream>
#include <queue>
#include <vector>

using namespace std;

struct edge{
    long long int to,cost;
};


vector<edge> G[100010];
long long int d[100010];

int main(void){
    int n;
    cin>>n;
    for(int i=0;i<n-1;i++){
        long long int a,b,c;
        cin>>a>>b>>c;
        G[a].push_back(edge{b,c});
        G[b].push_back(edge{a,c});
    }
    long long int Q,k;
    cin>>Q>>k;
    fill(d,d+n+1,3e18);
    d[k]=0;
    priority_queue<pair<long long int,long long int>,vector<pair<long long int,long long int>>,greater<pair<long long int,long long int>>> q;
    q.push(pair<long long int,long long int>(d[k],k));
    while(!q.empty()){
        pair<long long int,long long int> p=q.top();q.pop();
        long long int from=p.second;
        long long int cost=p.first;
        if(d[from]<cost)continue;
        for(long long int i=0;i<G[from].size();i++){
            edge e=G[from][i];
            long long int next=e.to;
            long long int newCost=e.cost+cost;
            if(d[next]>newCost){
                d[next]=newCost;
                q.push(pair<long long int,long long int>(newCost,next));
            }
        }
    }
    
    //for(int i=0;i<n;i++)cout<<d[i]<<endl;
    
    for(int i=0;i<Q;i++){
        int x,y;
        cin>>x>>y;
        
        cout<<d[x]+d[y]<<endl;
    }
    return 0;
}


Measured memory_bytes: 11392
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int prime[200000];
bool is_prime[200000];
int sieve(int n);
vector<int> prime_prime;
int main(){
  sieve(200000);
  int i,j;
  int n,p;
  int count=0;
  while(cin>>n>>p){
    count=0;
    prime_prime.clear();
    if(n==-1 && p==-1)break;
    while(prime[count]<=n)count++;
    for(i=count;i<p+count;i++)
      for(j=i;j<p+count;j++)
	prime_prime.push_back(prime[i]+prime[j]);
    sort(prime_prime.begin(),prime_prime.end());
    //for(int i=0;i<num;i++)cout<<prime_prime[i]<<endl;    
    cout<<prime_prime[p-1]<<endl;
  }
  return 0;
}

int sieve(int n){
  int p = 0;
  int i,j;
  for(i = 0;i<=n;i++)is_prime[i] = true;
  is_prime[0] = is_prime[1] = false;
  for(i = 2;i<=n;i++){
    if(is_prime[i]){
      prime[p++]=i;
      for(j=2*i;j<=n;j+=i)is_prime[j]=false;
    }
  }
  return p;
}

Measured memory_bytes: 1540
#include <iostream>

int main(int argc, char** argv){
	int a, b;
    std::string str1;
  	std::cin>>a;
    std::cin>>str1;
    std::cin>>b;
 	if(str1=="+"){
  		std::cout<<a+b;
    }else if(str1=="-"){
        std::cout<<a-b;
    }
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int x = sc.nextInt();
        int[] a = new int[n + 1];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }
        a[n] = x;
        Arrays.sort(a);
        for (int i = 0; i <= n; i++) {
            a[i] -= x;
        }
        for (int i = 1; i <= n; i++) {
            a[i] -= a[0];
        }
        a[0] = 0;
        int ans = a[1] - a[0];
        for (int i = 2; i <= n; i++) {
            ans = gcd(ans, a[i] - a[i - 1]);
        }
        System.out.println(ans);

    }

    public static int gcd(int a, int b) {
        if (b == 0)
            return a;
        return gcd(b, a % b);
    }

}


Measured memory_bytes: 49960
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(n) for (ll i = 0; i < n; ++i)
#define rep2(i, n) for (ll i = 0; i < n; ++i)
#define rep3(i, a, b) for (ll i = a; i < b; ++i)
#define rep4(i, a, b, c) for (ll i = a; i < b; i += c)
#define erep(n) for (ll i = 0; i <= n; ++i)
#define erep2(i, n) for (ll i = 0; i <= n; ++i)
#define erep3(i, a, b) for (ll i = a; i <= b; ++i)
#define erep4(i, a, b, c) for (ll i = a; i <= b; i += c)
#define rrep(i, a, b) for (ll i = a; i > b; --i)
#define rrep2(i, a, b, c) for (ll i = a; i > b; i -= c)
#define errep(i, a, b) for (ll i = a; i >= b; --i)
#define errep2(i, a, b, c) for (ll i = a; i >= b; i -= c)
#define print(a) cout << a << endl;
#define printVec(v) printf("{"); for (const auto& i : v) { std::cout << i << ", "; } printf("}\n");
#define cin(x) cin >> x;
const ll MOD = 1000000007;
const double PI = 3.14159265358979323846264338327950;
inline int newline() { putchar('\n'); return 0; }

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

    string s;
    cin(s);

    ll w = 0, r = 0;
    rep2(i, n) {
        char c = s[i];
        if (c == 'W') ++w;
        else ++r;
    }

    ll result = 0;

    rep3(i, r, n) {
        char c = s[i];
        if (c == 'R') ++result;
    }

    print(result);
    return 0;
}

Measured memory_bytes: 3748
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.util.stream.Collectors;

public class Main {

	public static void main(String args[]) {
		FastScanner cin = new FastScanner();
		PrintWriter cout = new PrintWriter(System.out);
		solve(cin, cout);
		cout.flush();
	}

	private static void solve(FastScanner cin, PrintWriter cout) {
		int n = cin.nextInt();
		int m = cin.nextInt();
		int[][] abs = new int[m][];
		for (int i = 0; i < m; i++)
			abs[i] = new int[] { cin.nextInt(), cin.nextInt() };
		int[] ans = solve(m, n, abs);
		String ansstr = Arrays.stream(ans).mapToObj(Integer::toString)
				.collect(Collectors.joining(System.lineSeparator()));
		cout.println(ansstr);
	}

	private static int[] solve(int m, int n, int[][] abs) {
		int[] ans = new int[n];
		for (int[] ab : abs) {
			ans[ab[0] - 1] += 1;
			ans[ab[1] - 1] += 1;
		}
		return ans;
	}

	/**
	 * How to read input in Java — tutorial <br />
	 * By Flatfoot<br />
	 * http://codeforces.com/blog/entry/7018
	 */
	static class FastScanner {
		private BufferedReader br;
		private StringTokenizer st;

		FastScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements())
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					throw new IllegalStateException(e);
				}
			return st.nextToken();
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				throw new IllegalStateException(e);
			}
			return str;
		}

		long nextLong() {
			return Long.parseLong(next());
		}
	}

}


Measured memory_bytes: 28500
#include<iostream>
#include<stdio.h>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#define ll long long
using namespace std;
int pos(int n)
{
    if(n<0)
        return 0;
    else
        return n;
}
bool pali(ll n)
{
    char a[10000]= {0};
    int num=0,tn=n;
    for(int i=0; i<tn; i++)
    {
        a[i]=n%10;
        n/=10;
        num=i;
        if(n<=0)
            break;

    }
    for(int i=0; i<num/2; i++)
    {
        if(a[i]!=a[num-i])
        {
            return false;
        }
    }
    return true;
}
int main()
{
    ll n,m;
    cin>>n>>m;
    if(n>=3)
        n-=2;
    else if(n==2)
        n=0;
    if(m>=3)
        m-=2;
    else if(m==2)
        m=0;
    cout<<n*m;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

#include <limits.h>

using namespace std;

typedef long long ll;

template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

const int INF = INT_MAX / 2;

vector<int> vs;

// 21:38
int main(void) {
    int N, K;
    cin >> N >> K;

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

    int ans = -INF;

    // get n jewel
    for (int n = min(N, K); n >= 0; n--) {
        // nl is jewels from left
        // nr is jewels from right
        for (int nl = n; nl >= 0; nl--) {
            int nr = n - nl;

            priority_queue<int, vector<int>, greater<int>> q;
            for (int i = 0; i < nl; i++) {
                q.push(vs[i]);
            }
            for (int i = 0; i < nr; i++) {
                q.push(vs[N - 1 - i]);
            }

            for (int i = 0; i < K - n && !q.empty(); i++) {
                const int v = q.top();
                if (v >= 0) {
                    break;
                }
                q.pop();
            }

            int cand = 0;
            while (!q.empty()) {
                const int v = q.top();
                // printf("v: %d\n", v);
                q.pop();
                cand += v;
            }
            // printf("cand: %d\n", cand);
            chmax(ans, cand);
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3572
def main():
    a, b, c, d, e, f = map(int, input().split())

    ws = set()
    for w_a in range(0, f + 1, 100 * a):
        for w_b in range(0, f + 1 - w_a, 100 * b):
            ws.add(w_a + w_b)
    ws.remove(0)

    ss = set()
    for s_c in range(0, f + 1, c):
        for s_d in range(0, f + 1 - s_c, d):
            ss.add(s_c + s_d)
    ss.remove(0)

    ws = sorted(iter(ws))
    ss = sorted(iter(ss))

    res = (100 * a, 0)
    density_max = 0

    for w in ws:
        for s in ss:
            if w + s > f:
                break
            if w * e < s * 100:
                break
            density = s / (w + s)
            if density > density_max:
                density_max = density
                res = (w + s, s)

    print(res[0], res[1])


if __name__ == '__main__':
    main()


Measured memory_bytes: 3188
#define _[2<<17]
n,i,j;B _,T _,F _;long M,D _,P _,R _;s(u,i,p,I){R[i]=i?s(u,T[i],p),(I=B[i])-p?s(I,F[I],u),D[u]=D[u]*-~D[I]%M:D[u]:++D[u];}S(u,x,p,i,I){for(i=F[u];I=B[i];I-p?S(I,R[i]*x%M+1,u),x=x*-~D[I]%M:0)i=T[i];P[u]=x%M;}main(u,v){for(;~scanf("%d%d",&u,&v);)i++?T[i-1]=F[u],T[i]=F[v],B[F[u]=i-1]=v,B[F[v]=i++]=u:(n=u,M=v);s(1,F[1]);for(S(1,1);j++<n;)printf("%d ",P[j]);}

Measured memory_bytes: 13056
import java.util.ArrayList;
import java.util.Scanner;

//So when I die (the [first] I will see in (heaven) is a score list).
//0123456789012345678901234567890123456789012345678901234567890123456
class Main {
    public static void main(String args[]) {
        Scanner scan = new Scanner(System.in);
        String[] strings = {"([", ")]"};
        while (true) {
            String input = scan.nextLine();
            ArrayList<Integer> list = new ArrayList<Integer>();
            if (input.equals(".")) {
                break;
            }
            boolean flag = true;
            for (int i = 0; i < input.length(); i++) {
                for (int j = 0; j < strings[0].length(); j++) {
                    if (input.charAt(i) == strings[0].charAt(j)) {
                        list.add(j);
                        // System.out.println("[add]i="+i+":j="+j+":size="+list.size());
                    } else if (input.charAt(i) == strings[1].charAt(j)) {
                        // System.out.println("[deleat]i="+i+":j="+j+":size="+list.size());
                        try {
                            if (list.get(list.size() - 1) == j) {
                                list.remove(list.size() - 1);
                            } else {
                                i = input.length();
                                flag = false;
                                break;
                            }
                        } catch (Exception e) {
                            flag = false;
                            break;
                        }

                    }
                }
            }
            if (list.size() != 0) {
                flag = false;
            }
            if (flag) {
                System.out.println("yes");
            } else {
                System.out.println("no");
            }
        }
    }
}


Measured memory_bytes: 46340
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
#include <array>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define loop(i, a, n) for (int i = a; i < (n); i++)
#define all(in) in.begin(), in.end()
const int INF = 1e9;
const int MOD = 1e9 + 7;
int main() {
    int n, b, c;
    cin >> n >> b >> c;
    cout << min(c, b) << " " << max(b + c - n, 0) << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int main() {
	int n,a[105],cnt1=0,cnt2=0;
	scanf("%d",&n);
	for (register int i=1;i<=n;++i) {
		scanf("%d",a+i);
	}
	sort(a+1,a+n+1);
	for (register int i=1;i<=n;++i) {
		if (i&1) {
			cnt1+=a[i];
		}
		else {
			cnt2+=a[i];
		}
	}
	printf("%d\n",abs(cnt1-cnt2));
	return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
inf = 10**17
mod = 10**9 + 7
#s=input().rstrip()
k=I()
a,b=MI()
for i in range(a,b+1):
    if i%k==0:
        print("OK")
        sys.exit()
print("NG")

Measured memory_bytes: 9428