akhauriyash/Code-Regression huggingface dataset:
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <array>
#include <queue>
#include <deque>
#include <set>
#include <list>
#include <map>
#include <stack>
#include <utility>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <climits>
#include <bitset>
#include <random>
#include <functional>
#include <sstream>
#include <iomanip>

using namespace std;

#define rep(i, n) for(int i=0; i<(n); i++)
#define FOR(i, m, n) for(int i=(m);i<(n);i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define REVE(x) reverse((x).begin(),(x).end())
#define mp make_pair
#define pb push_back
#define F first
#define S second


typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
typedef long long LL;

int main() {
	int n; cin >> n;
	VI a(n); rep(i, n)cin >> a[i];

	VI print;
	int q; cin >> q;
	rep(z, q) {
		int b, e, k;
		cin >> b >> e >> k;

		int cnt = 0;
		for (int i = b; i < e; i++)if (a[i] == k)cnt++;
		print.pb(cnt);
	}
	for (auto x : print) {
		cout << x << endl;
	}
}


Measured memory_bytes: 3164
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
void _main()
{
    string S;
    cin >> S;
    int num = 0;
    for (const char c : S)
    {
        if (c == 'o') ++num;
    }
    cout << 700 + 100 * num << endl;
}


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

 

int main() {
    int N;
    int k = 3;
    cin >> N;
    vector<int> L(N);
    rep(i,N) cin >> L.at(i);
    sort(L.begin(), L.end());
    int ans = 0;
    rep(i,N) for (int j = i + 1; j < N; ++j) {
        int idx_distance = distance(L.begin() + j, lower_bound(L.begin(), L.end(), L.at(i)+L.at(j)));
        ans += max(0, idx_distance - 1);
    }
    cout << ans << endl;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
int main(void){
    double N,M;
    cin >> N >> M;
    vector<double> A(N);
    double S = 0;
    for(int i = 0; i < N; i++){
        cin >> A[i];
        S += A[i];
    }
    int ans = 0;
    for(int i = 0; i < N; i++){
        if(A[i] >= S / (4 * M)) ans++;
    }
    
    if(ans >= M) cout << "Yes" << endl;
    else cout << "No" << endl;
}


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

from itertools import permutations
from math import sqrt
def main():
    TMP = permutations(XY)
    sm = 0
    cnt = 0
    for tmp in TMP:
        cnt += 1
        prex,prey = tmp[0]
        for x,y in tmp[1:]:
            sm += sqrt((prex -x)**2 + (prey -y)**2)
    print(sm / cnt)



if __name__ == "__main__":
    main()

Measured memory_bytes: 3188
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
struct Pair{
    int x,y;
}p[100005];
struct edge{
    int s,t,cost;
}e[2][100005];
int s[100005],t[100005],fa[100005];
int Find(int x){return x==fa[x]?x:fa[x]=Find(fa[x]);}
bool Cmpx(int a,int b){
    return p[a].x<p[b].x;
}
bool Cmpy(int a,int b){
    return p[a].y<p[b].y;
}
bool Cmpe(edge a,edge b){
    return a.cost<b.cost;
}
int main(){
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>p[i].x>>p[i].y;
        fa[i]=i;
        s[i]=i;t[i]=i;
    }
    sort(s,s+n,Cmpx);
    sort(t,t+n,Cmpy);
    for(int i=0;i<n-1;i++){
        e[0][i].s=s[i+1];
        e[0][i].t=s[i];
        e[0][i].cost=p[s[i+1]].x-p[s[i]].x;
    }
    for(int i=0;i<n-1;i++){
        e[1][i].s=t[i+1];
        e[1][i].t=t[i];
        e[1][i].cost=p[t[i+1]].y-p[t[i]].y;
    }
    sort(e[0],e[0]+n-1,Cmpe);
    sort(e[1],e[1]+n-1,Cmpe);
    int i=0,j=0,count=0;
    long long cost=0;
    while(count<n-1){
        if(i<=n-1&&e[0][i].cost<=e[1][j].cost){
            int x=Find(e[0][i].s),y=Find(e[0][i].t);
            fa[x]=y;
            cost+=e[0][i].cost;
        }else{
            int x=Find(e[1][j].s),y=Find(e[1][j].t);
            fa[x]=y;
            cost+=e[1][j].cost;
        }
        count++;
        while(i<n-1&&Find(e[0][i].s)==Find(e[0][i].t))i++;
        while(j<n-1&&Find(e[1][j].s)==Find(e[1][j].t))j++;
    }
    cout<<cost<<endl;
    return 0;
}

Measured memory_bytes: 4608
#include <bits/stdc++.h>
#define ll long long int
#define endl "\n"
#define mod 1000000007
#define mem(a,val) memset(a,val,sizeof(a))
#define ps(x,noOfDecimal) fixed<<setprecision(noOfDecimal)<<x

using namespace std;
int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	std::ios::sync_with_stdio(false);
	int t = 1;
	// cin>>t;
	while (t--) {
		int n;
		cin >> n;
		int rem = n % 10;
		if (rem == 2 || rem == 4 || rem == 5 || rem == 7 || rem == 9) {
			cout << "hon";
		}
		else if (rem == 0 || rem == 1 || rem == 6 || rem == 8) {
			cout << "pon";
		}
		else {
			cout << "bon";
		}

	}
	return 0;
}

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


int dp[101][4][4][4];
int mod = 1e9 + 7;

int main() {
    
    int N;
    cin >> N;
    // A - 0, G- 1, C - 2, T - 3
    // dp[文字数][1文字前][2文字前][3文字前]
    // 長さ０の文字列は１
    // ０，１，2に関する制約しかないので，
    // Sは，３３３Sと考えても問題ない．
    dp[0][3][3][3] = 1;
    
    // 文字列の文字数
    for (int len = 0; len < N; len++) {
        // 最後から１文字目のもじ
        for (int c1 = 0; c1 < 4; c1++) {
            // 最後から2文字目のもじ
            for (int c2 = 0; c2 < 4; c2++) {
                // 最後から3文字目のもじ
                for (int c3 = 0; c3 < 4; c3++) {
                    // 条件に当てはまるものがない場合はcontinue;
                    if (dp[len][c1][c2][c3] == 0) continue;

                    // 新しく追加するもじ
                    for (int a = 0; a < 4; a++) {
                        // ダメな5つの条件をカットする
                        // 0 1 2 (AGC)
                        if (a == 2 and c1 == 1 and c2 == 0) continue;
                        // 1 0 2 (GAC)
                        if (a == 2 and c1 == 0 and c2 == 1) continue;
                        // 0 2 1 (ACG)
                        if (a == 1 and c1 == 2 and c2 == 0) continue;
                        // 0 * 1 2 (A*GC)
                        if (a == 2 and c1 == 1 and c3 == 0) continue;
                        // 0 1 * 2 (AG*C)
                        if (a == 2 and c2 == 1 and c3 == 0) continue;

                        // ダメな条件を抜けたら，aを足した文字列が作れる

                        // S = .... c3 c2 c1
                        // NextS = .... c2 c1 a
                        dp[len + 1][a][c1][c2] += dp[len][c1][c2][c3];
                        dp[len + 1][a][c1][c2] %= mod;

                    }
                }
            }
        }
    }
    int ans = 0;
    // 長さNの答えをまとめる
    // 最後から１文字目のもじ
    for (int c1 = 0; c1 < 4; c1++) {
        // 最後から2文字目のもじ
        for (int c2 = 0; c2 < 4; c2++) {
            // 最後から3文字目のもじ
            for (int c3 = 0; c3 < 4; c3++) {
                
                ans += dp[N][c1][c2][c3];
                ans %= mod;

            }
        }
    }
    
    cout << ans << '\n';
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <vector>
#include <set>
#include <cmath>
#include <string>
#include <iostream>
#include <stack>

using namespace std;

int main(){
    string s;
    getline(cin, s);
    int numwin = 0;
    for(char c : s){
        numwin += (c == 'o');
    }
    int rest = 15 - s.size();
    if(rest + numwin >= 8){
        printf("YES\n");
    }else{
        printf("NO\n");
    }
    return 0;
}


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

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
#define dump(val) cerr << __LINE__ << ":\t" << #val << " = " << (val) << endl

using namespace std;

typedef long long int lli;

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...));
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    char ss[25] = "";
    while (cin >> ss, ss[0] != '#') {
        string str = ss;
        vector<string> prevCond(6, string(25, 'z')), aftCond(6, string(1, '0'));
        auto restore = [&](string s) -> bool {
            bool used[26] = {true};
            bool ok = true;
            REP(i, 0, s.size()) {
                if (!used[s[i] - 'a']) {
                    used[s[i] - 'a'] = true;
                    s[i]--;
                }
                ok &= (s[i] == str[i]);
            }
            return ok;
        };
        int ans = 0;
        int msk = 0;
        REP(i, 0, str.size()) {
            if (str[i] == 'z') {
                msk |= (1 << i);
            }
        }
        REP(i, 0, 1 << str.size()) {
            if ((i & msk) != 0) continue;
            string work = str;
            REP(j, 0, work.size()) {
                if (((i >> j) & 1) == 1) work[j]++;
            }
            if (restore(work)) {
                ans++;
                int t;
                for (t = 5; t > 0; t--) {
                    if (work < prevCond[t - 1]) {
                        prevCond[t] = prevCond[t - 1];
                    } else {
                        break;
                    }
                }
                prevCond[t] = work;

                for (t = 5; t > 0; t--) {
                    if (work > aftCond[t - 1]) {
                        aftCond[t] = aftCond[t - 1];
                    } else {
                        break;
                    }
                }
                aftCond[t] = work;
            }
        }
        cout << ans << endl;
        reverse(begin(aftCond), end(aftCond) - 1);
        if (ans <= 5) {
            REP(i, 0, ans) {
                cout << prevCond[i] << endl;
            }
        } else {
            REP(i, 0, 5) {
                cout << prevCond[i] << endl;
            }
            REP(i, max(10 - ans, 0), 5) {
                cout << aftCond[i] << endl;
            }
        }
    }
    return 0;
}



Measured memory_bytes: 3160
N = int(input())
D = [int(i) for i in input().split()]
M = int(input())
T = [int(i) for i in input().split()]

dic_D = {} 
for d in D:
    dic_D[d] = dic_D.get(d,0) + 1
dic_T = {}
for t in T:
    dic_T[t] = dic_T.get(t,0) + 1
    
for k in dic_T:
    if dic_T[k]>dic_D.get(k,0):
        print("NO") 
        break
else:
    print("YES")


Measured memory_bytes: 56788
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.nextLine();
		String t = sc.nextLine();
		int ctr = 0;
		for (int i = 0; i < t.length(); i++) {
			if (s.charAt(i) != t.charAt(i)) {
				ctr++;
			}
		}
		System.out.println(ctr);
		sc.close();
	}
}

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

int main(){
    long double a,b,x;
    cin>>a>>b>>x;
    if(x>=a*a*b/2){
        long double mother,son,son1,son2;
        mother=pow(a,3);
        son1=(double)2*pow(a,2)*b;
        son2=(double)2*x;
        son=son1-son2;
        long double ans=(double)atan(son/mother)/M_PI*180.0;
        cout<<fixed<<setprecision(15)<<ans<<endl;
        return 0;
    }
    else{
        long double c;
        c=(double)x/(a*b/2);
        long double hon;
        hon=(double)sqrt(pow(c,2)+pow(b,2));
        long double ans;
        ans=acos(c/hon)/M_PI*180.0;
        cout<<fixed<<setprecision(15)<<ans<<endl;
       
        return 0;
    }

}

Measured memory_bytes: 512
import copy
def lunlun_check(i,j):
    if abs(i-j) > 1:
        return False
    return True

k = int(input())
ret_list = []
lunlun_list = []
cnt = 0
cnt_pre = 0
digit = 1
while k > (cnt-1):
    cnt_pre = cnt
    tmp_list = []
    ret_list.clear()
    if not lunlun_list:
        for i in range(10):
            tmp_list.append(str(i))
            ret_list.append(i)
    else:
        for i in range(10):
            for data in lunlun_list:
                if lunlun_check(i, int(data[0])):
                    tmp_list.append(str(i)+data)
                    if len(str(int(str(i)+data))) == digit:
                        ret_list.append(int(str(i)+data))
    lunlun_list = tmp_list.copy()
    cnt += len(ret_list)
    digit += 1
print(int( ret_list[k- cnt_pre] ))


Measured memory_bytes: 23240
//コンパイラ最適化用
#pragma GCC optimize("Ofast")

//インクルード(アルファベット順)
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<chrono>//実行時間計測
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm,accumulate
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//順序保持しないmap
#include<unordered_set>//順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;
typedef long long ll;

signed main(){
/*
  cin >> N;
  vector<int> a(N);
  for (int i = 0; i < N; i++)
    cin >> a[i];
*/
  int N;
  cin >> N;

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

  ll money = 1000;
  for (int i = 0; i < N - 1; i++) {
    if (A[i + 1] > A[i]) {
      ll stocks = money / A[i];
      money += (A[i + 1] - A[i]) * stocks;
    }
  }

  cout << money << endl;

  return 0;
}

Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int i,l=0,flag = 0;
    string StrNo;
    cin>>StrNo;
    char last;
   // l = a.size();

   if(StrNo[StrNo.length() - 1] == 's')cout<<StrNo<<"es"<<endl;
   else cout<<StrNo<<"s"<<endl;

}


Measured memory_bytes: 3620
import java.math.BigInteger;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        try {
            final int n = sc.nextInt();
            final int a = sc.nextInt();
            final int b = sc.nextInt();

            long pow = pow(2, n, 1000000007);
            long nca = nCr(n, a, 1000000007);
            long ncb = nCr(n, b, 1000000007);

            long result = pow - 1;
            result = result - nca;
            if (result < 0) {
                result += 1000000007;
            }
            result = result - ncb;
            if (result < 0) {
                result += 1000000007;
            }
            System.out.println(result);

        } finally {
            sc.close();
        }
    }

    public static long nCr(int n, int r, int mod){
        long num = 1;
        for (int i=1; i<=r; i++) {
            num *= n;
            num %= mod;
            n--;
        }

        long invr = pow(factorial(r, mod), mod - 2, mod);

        return num * invr % mod;
    }

    public static long modinv(long a, long mod) {
        return pow(a, mod - 2, mod);
    }

    public static long pow(long a, long x, long mod) {
        return BigInteger.valueOf(a).modPow(BigInteger.valueOf(x),  BigInteger.valueOf(mod)).longValue();
    }

    public static long factorial(long n, long mod) {
        long result = 1;
        for (long i=n; i>0; i--) {
            result *= i;
            result %= mod;
        }
        return result;
    }
}


Measured memory_bytes: 22356
N = int(input())
b = list(map(int,input().split()))
box = [0 for i in range(N)]

for i in range(N-1,-1,-1):
  rest = 0
  for j in range(2 * (i+1),N+1,i+1):
    rest += box[j-1]
  box[i] = (b[i] - rest)%2
print(sum(box))
if sum(box):
  for idx,i in enumerate(box):
    if i == 1:
      print(idx+1)

Measured memory_bytes: 70620
import sys
from functools import reduce
import copy
import math
from pprint import pprint


sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def int_inputs(num_of_input):
    ins = [int(input()) for i in range(num_of_input)]
    return ins


def solve(N, K, answers):
    min_point = K - len(answers)
    points = [min_point for i in range(N)]
    for a in answers:
        points[a-1] += 1
    return ['Yes' if p > 0 else 'No' for p in points]


def string_to_int(string):
    return list(map(int, string.split()))


if __name__ == "__main__":
    [N, K, Q] = string_to_int(input())
    ret = solve(N, K, int_inputs(Q))
    for r in ret:
        print(r)


Measured memory_bytes: 11380
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String s = sc.next();
        int k = sc.nextInt();
        sc.close();
        char p = s.charAt(k - 1);
        for(int i = 0 ; i < n ; i++){
            if(p == s.charAt(i)){
                System.out.print(p);
            }else{
                System.out.print("*");
            }
        }
        System.out.println();
    }
}

Measured memory_bytes: 35564
#include <bits/stdc++.h>
 
#define ll long long
#define X first
#define Y second
#define MP make_pair
 
using namespace std;

const int N = 123;
const ll mod = 1e9 + 7;             

int n;
struct mtx{
	ll a[N][N], len = n;
	mtx(){
		memset(a, 0, sizeof(a));
	}
	void operator *= (mtx b){
		int res[N][N];
		memset(res, 0, sizeof(res));
		for(int i = 1;i <= len;i++){
			for(int j = 1;j <= len;j++){
				for(int k = 1;k <= len;k++){
					res[i][j] = (res[i][j] + a[i][k] * b.a[k][j]) % mod;
				}
			}
		}
		for(int i = 1;i <= len;i++){
			for(int j = 1;j <= len;j++){
				a[i][j] = res[i][j];
			}
		}
	}
};

mtx bin_pow(mtx x, ll y){
	mtx res;
	for(int i = 1;i <= n;i++){
			res.a[i][i] = 1;
	}
    
	while(y){
		if(y & 1LL)
			res *= x;
		
	/*	for(int i = 1;i <= n;i++){	
			for(int j = 1;j <= n;j++){
				cout << res.a[i][j] << " ";
	    	}
			cout << "\n";
		}
	*/	
		x *= x;
		y >>= 1LL;
	}
	return res;
}
   
int main () {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	ll k;
	cin >> n >> k;
	mtx z;
	for(int i = 1;i <= n;i++)
		for(int j = 1;j <= n;j++)
			cin >> z.a[i][j];
	//z *= z;
	z = bin_pow(z, k);
	ll res = 0;
	for(int i = 1;i <= n;i++){	
		for(int j = 1;j <= n;j++){
		//	cout << z.a[i][j] << " ";
			res += z.a[i][j], res %= mod;
	    }
		//cout << "\n";
	}
	cout << res;
}

Measured memory_bytes: 768
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
	Scanner scan = new Scanner(System.in);
	int s = scan.nextInt();
	int h = s/3600;
	s = s%3600;
	int m = s/60;
	s = s%60;
	
	System.out.println("" + h + ":" + m + ":" + s);
	

	
}

}



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

int main(){
    int n, l, total = 0, tmp, answer = 1000000, kotae = 0;
    cin >> n >> l;
    for(int i = 1; i < n + 1; i++){
        total += l + i - 1;
    }
    tmp = total;
    for(int i = 1; i < n + 1; i++){
        tmp -= l + i - 1;
        if(abs(total - tmp) < abs(total - answer)){
            answer = tmp;
            kotae = tmp;
        }
        tmp += l + i - 1;
    }
    cout << kotae << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;
class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in); 
    String S = sc.next();
    String answer;
    if(S.equals("Sunny")){
      answer = "Cloudy";
    }else if(S.equals("Cloudy")){
    answer = "Rainy";
    }else{
      answer = "Sunny";
    }
    System.out.println(answer);
  }
}

Measured memory_bytes: 20564
#include<bits/stdc++.h>
#include<stdio.h>
using namespace std;
typedef int64_t ll;
typedef long double ld;

void solve() {
    ll x;
    cin >> x;
    for(ll i = -1000; i <= 1000; i++) {
        for(ll j = -1000; j <= 1000; j++) {
            if((ll)pow(i, 5) - (ll)pow(j, 5) == x) {
                cout << i << " " << j;
                return;
            }
        }
    }
}    

int main() {
    ios_base :: sync_with_stdio(false); 
    cin.tie(NULL);
    ll t = 1;
    //cin >> t;
    while(t--) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 4068
N = int(input())
p = [0] + list(map(int, input().split()))
count = 0
for i in range(1, N):
    if p[i] == i:
        p[i], p[i + 1] = p[i + 1], p[i]
        count += 1
if p[N] == N:
    print(count + 1)
else:
    print(count)

Measured memory_bytes: 14008
n = gets.to_i
as = gets.split
  .map(&:to_i).sort!
  .each_with_object(Hash.new(0)) { |a, h| h[a] += 1 }
  .select { |k, v| v >= 2 }

ans = 0
length = 0

as.each do |k, v|
  s = length * k
  s = [length * k, k ** 2].max if v >= 4

  ans = s if s >= ans
  length = k
end

puts ans


Measured memory_bytes: 14960
# -*- coding: utf-8 -*-
from sys import stdin

#abcdeefab
#bottom top

A = stdin.readline().rstrip()
m = int(stdin.readline().rstrip())

while True:
  for i in range(m):
    hi = int(stdin.readline().rstrip())
    move_cards = A[:hi]
    not_move_cards = A[hi:]
    A = not_move_cards+move_cards
    #print(A) #TODO delete before submit
  else:
    print(A)
    A = stdin.readline().rstrip()
    if A == '-':
      break
    m = int(stdin.readline().rstrip())


Measured memory_bytes: 5604
I0 = lambda :map(int,input().split())
I1 = lambda :int(input())
I2 = lambda :list(map(int,input().split()))
#####################################################
n ,q = I0()
counter = [0]*n
tree = [[] for i in range(n)]
for i in range(n-1):
    a,b=I0()
    tree[a-1].append(b-1)
    tree[b-1].append(a-1)
 
for i in range(q):
    p,x = I0()
    counter[p-1]+=x

stack = [0]
seen = dict()
seen[0] = 1
while stack:
    yy = stack.pop()
    for i in tree[yy]:
        if seen.get(i,-1) == -1:
            seen[i] = 1
            counter[i]+=counter[yy]
            stack.append(i)
            
print(*counter)

Measured memory_bytes: 66996
/***************************************** START OF TEMPLATE *********************************************/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

#define  SPEED           ios:: sync_with_stdio(0);cin.tie(0);cout.tie(0);cout<<fixed;cout<<setprecision(10);
#define  randomINIT      mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define  foo(i,a,n)      for(ll i = (a); i <= n; i++)
#define  frr(i,a,n)      for(ll i = (a); i >= n; i--)
#define  fo(i,n)         for(ll i = 0; i < n; i++)
#define  newl            cout<<"\n";
#define  f               first
#define  s               second
#define  pb              push_back
#define  mp              make_pair
#define  sym(s)          s="#"+s+"#";
#define  sqr(v)          v*v;
#define  all(x)          (x).begin(),(x).end()
#define  alll(x,n)       x+1, x+n+1
#define  uniq(a)         a.resize(unique(a.begin(), a.end()) - a.begin());
#define  mset(x,val)     memset(x,val,sizeof(x))
#define  mset1d(a,n,v)   foo(i,0,n+5)a[i]=v;
#define  mset2d(a,n,m,v) foo(i,0,n+5)foo(j,0,m+5)a[i][j]=v;
#define  deb1(a)         cout<<a<<"\n";
#define  deb2(a,b)       cout<<a<<" "<<b<<"\n";
#define  deb3(a,b,c)     cout<<a<<" "<<b<<" "<<c<<"\n";
#define  deb4(a,b,c,d)   cout<<a<<" "<<b<<" "<<c<<" "<<d<<"\n";
#define  debp(a)         cout<<a.f<<" "<<a.s<<"\n";
#define  debv(a)         for(auto it: a)cout<<it<<" ";newl;
#define  debm(a)         for(auto it: a)cout<<"{"<<it.f<<","<<it.s<<"}, ";newl;
#define  deb1d(a,n)      foo(i,1,n)cout<<a[i]<<" ";newl;
#define  deb2d(a,n,m)    foo(i,1,n){foo(j,1,m){cout<<a[i][j]<<" ";}newl;}    

template <typename T> 
using  ordered_set =  tree<T, null_type, less<>, rb_tree_tag, tree_order_statistics_node_update>;
using  ll          =  long long;
using  ull         =  unsigned long long;
using  ld          =  long double;
using  pll         =  pair<ll,ll>;
using  vll         =  vector<ll>;
using  vpll        =  vector<pll>;

const ld   PI    =  3.14159265358979323846; 
const ll   MOD   =  1e+9+7;
const ll   INF   =  LLONG_MAX;
const int  INFi  =  INT_MAX;
const ll   N     =  2e+5+8;

vll adj[N]; ll vis[N];
ll dx4[]={0,1,0,-1}, dy4[]={1,0,-1,0};

ll test_cases = 1; randomINIT;

/*********************************************************************************************************/
/***************************************** VARIABLE DECLARATIONS *****************************************/
ll n, a[N];

/***************************************** FUNCTION IMPLEMENTATIONS **************************************/


/***************************************** START OF MAIN FUNCTION ****************************************/
void MAIN(ll tc){
    string s;
    cin>>s;
    n = s.size();
    sym(s);
    ll cnt = 0, res= 0;
    for(int i = 1; i <= n; i++){
        if(s[i] == 'R'){
            cnt += 1;
        }else{
            res= max(res, cnt);
            cnt = 0;
        }
    }
    res = max(res, cnt);
    deb1(res);
}

int main(){
    SPEED;

    //cin>>test_cases;
    foo(i,1,test_cases){
        MAIN(i);
    }
}

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

typedef long long ll;
typedef pair<int,int> ii;

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int n,a,b; cin>>n>>a>>b;
	cout<<min(n*a,b)<<"\n";
	return 0;
}

Measured memory_bytes: 256
class BIT:
    def __init__(self, N):
        self.size = N
        self.tree = [0] * (N + 1)
        self.bisect_K = [1 << k for k in reversed(range(N.bit_length()))]

    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s

    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i

    def bisect(self, w):
        bit, N = self.tree, self.size
        i = 0
        for k in self.bisect_K:
            if i + k <= N and bit[i + k] < w:
                i += k
                w -= bit[i]
        return i + 1

N, *A = map(int, open(0).read().split())

memo = {a: i for i, a in enumerate(sorted(set(A)), 1)}
M = len(memo)

bit = BIT(M)
for b in (memo[a] for a in A):
    s = bit.sum(b - 1)
    if s > 0:
        i = bit.bisect(s)
        bit.add(i, -1)
    bit.add(b, 1)

print(bit.sum(M))


Measured memory_bytes: 25040
# ソースコードの正答を判定する。
n, m, c = map(int, input().split())
b = list(map(int, input().split()))
ans = 0
for _ in range(n):
    a = list(map(int, input().split()))
    t = 0
    for i in range(m):
        t += a[i]*b[i]
    if (t + c) > 0:
        ans += 1
print(ans)


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

using namespace std;

const int N = 2000, MD = 1000000007;

int dp[1 + N];

int main() {
	int n; cin >> n;
	dp[0] = 1;
	for (int a = 0; a <= n; a++)
		for (int b = a + 3; b <= n; b++)
			dp[b] = (dp[b] + dp[a]) % MD;
	cout << dp[n] << '\n';
	return 0;
}


Measured memory_bytes: 3612
#include <iostream>
#include <map>
#include <vector>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <climits>
#include <stack>
#include <queue>
#include <set>
#include <cctype>
#include <bitset>
#include <type_traits>

#include <list>
using namespace std;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define YES(j) cout << (j ? "YES" : "NO") << endl;
#define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
#define yes(j) std::cout << (j ? "yes" : "no") << endl;

int main(void)
{
    int n, k;
    cin >> n >> k;
    int a[200001];
    REP(i, 200001)
    {
        a[i] = 0;
    }
    REP(i, n)
    {
        int t;
        cin >> t;
        a[t]++;
    }
    vector<int> b;
    REP(i, 200001)
    {
        if (a[i] > 0)
        {
            b.push_back(a[i]);
        }
    }
    sort(b.begin(), b.end());
    long long ans = 0;

    if (b.size() <= k)
    {
        cout << "0" << endl;
        return 0;
    }
    k = b.size() - k;

    /* 
    while (k > 0)
    {
        if (b.empty())
        {
            cout << "0" << endl;
            return 0;
        }
        k--;
        ans += b.front();
        b.erase(b.begin());
    }
    */
    for (int i = 0; i < b.size(); i++)
    {
        if (k > 0)
        {
            ans += b[i];
            k--;
        }
        if (k == 0)
        {
            /* code */
            break;
        }
    }

    if (k > 0)
    {
        cout << "0" << endl;
    }
    else
    {
        cout << ans << endl;
    }
}


Measured memory_bytes: 2168
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define UM unordered_map
#define ALL(a) (a).begin(), (a).end()
typedef vector<ll> vi;
typedef vector<vector<ll>> vvi;
typedef pair<ll, ll> pii;
const ll INF = 1LL << 58;
const ll MOD = 1000000007;
typedef vector<pii> vpii;
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;
}

signed main()
{
    int N, K;
    string S;
    cin >> N >> K;
    cin >> S;
    if (S[K - 1] == 'A')
        S[K - 1] = 'a';
    if (S[K - 1] == 'B')
        S[K - 1] = 'b';
    if (S[K - 1] == 'C')
        S[K - 1] = 'c';
    cout << S << endl;

    // system("pause");
}

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

using namespace std;

int main() {

	int n;
	cin >> n;

	vector<double> a(n, 0);
	double summ = 0;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		summ += 1 / a[i];
	}

	cout << fixed << setprecision(9) << 1/ summ << endl;


}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long cur;
vector<int> inv[200005],v[200005];
int stt[200005],ent[200005],sz[200005],ct;
set<pair<int,int> > s;
int dfs(int node,int p)
{
	sz[node]=1;
	stt[node]=++ct;
	for (int u:v[node])
	{
		if (u!=p)
		sz[node]+=dfs(u,node);
	}
	ent[node]=ct;
	return sz[node];
}
void dfs2(int node);
void dfs3(int node)
{
	long long cmp=sz[node];
	while (1)
	{
		auto it=s.lower_bound({stt[node],node});
		if (it==s.end() || it->first>ent[node])
		break;
		cmp-=sz[it->second];
		dfs2(it->second);
	}
	cur-=cmp*(cmp+1)/2;
}
void dfs2(int node)
{
	s.erase({stt[node],node});
	for (int u:v[node])
	{
		if (stt[u]>=stt[node])
		dfs3(u);
	}
}
int main()
{
	int n;
	scanf("%d",&n);
	for (int i=1;i<=n;i++)
	{
		int c;
		scanf("%d",&c);
		inv[c].push_back(i);
	}
	for (int i=1;i<n;i++)
	{
		int a,b;
		scanf("%d%d",&a,&b);
		v[a].push_back(b);
		v[b].push_back(a);
	}
	v[0].push_back(1);
	dfs(0,0);
	for (int i=1;i<=n;i++)
	{
		s.clear();
		s.insert({1,0});
		for (int u:inv[i])
		s.insert({stt[u],u});
		cur=1LL*n*(n+1)/2;
		dfs2(0);
		printf("%lld\n",cur);
	}
}

Measured memory_bytes: 38148
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll INF = 1'010'000'000'000'000'017LL;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()

int main() {
    // AtCoder
    // template
    string s;
    cin >> s;
    bool ans = false;
    string k = "keyence";
    rep(i, 8) {
        // cout << s.substr(0, i) << ' ' << s.substr(s.size() - (7 - i - 1) - 1)
        //      << endl;
        if((s.substr(0, i) == k.substr(0, i) &&
            s.substr(s.size() - (7 - i - 1) - 1) ==
                k.substr(k.size() - (7 - i - 1) - 1)))

            ans = true;
    }

    if(ans)
        cout << "YES";
    else
        cout << "NO";
}


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

//wierd debugging stuff
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << "\n" ; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
//end of weird debugging stuff
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ll> vll;
typedef vector<vector<int>> vvi;
#define all(c) (c).begin(), (c).end()
#define sz(x) (int)(x).size()
 
#define F_OR(i, a, b, s) for (int i = (a); ((s) > 0 ? i < (b) : i > (b)); i += (s))
#define F_OR1(e) F_OR(i, 0, e, 1)
#define F_OR2(i, e) F_OR(i, 0, e, 1)
#define F_OR3(i, b, e) F_OR(i, b, e, 1)
#define F_OR4(i, b, e, s) F_OR(i, b, e, s)
#define GET5(a, b, c, d, e, ...) e
#define F_ORC(...) GET5(__VA_ARGS__, F_OR4, F_OR3, F_OR2, F_OR1)
#define fo(...) F_ORC(__VA_ARGS__)(__VA_ARGS__)
#define foe(i,x) for(auto& i: x)
#define ar array
#define pb push_back
#define vt vector
#define F first
#define S second

template<class T> bool umin(T& a,const T& b){return b<a?a=b,1:0;}
template<class T> bool umax(T& a,const T& b){return b>a?a=b,1:0;}

template<class A> void read(vt<A>& v);
template<class A, size_t S> void read(ar<A, S>& a);
template<class T> void read(T& x) {cin>>x;}
void read(double& d) {string t;read(t);	d=stod(t);}
void read(long double& d) {	string t;read(t);d=stold(t);}
template<class H, class... T> void read(H& h, T&... t) {read(h);read(t...);}
template<class A> void read(vt<A>& x) {	foe(a, x)read(a);}
int nxt(){int a;read(a);return a;}   // iota(all(v),0); genrate(all(v),nxt);

// no change 
const ll MOD = 1e9+7;  
int mx = 1e6+1;
void Titan(){
	string s;
	read(s);
	int n = s.size();
	int i = 0;
	while(s[i]!= 'A')i++;
	int j= n-1;

	while(s[j]!='Z')j--;

	cout << (j - i+1 >0 ? j-i+1 : 0);



	
	
	
	
}

	

int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int T = 1;
	//cin >> T;		//cmt if one test case
    fo(T){
		//cout << "Case #" << i+1 << ": " ;
		Titan();
	}
}
/*///////////////////////////////////////////////////////////
Important Notes : 
* check long long 
* check base cases
* do not loose Hope
* if case fails on 2nd test case maybe some cases are missing check them
* do not sit idle
* try to do it using pen/paper.
*/


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

using namespace std;

int main(){
  string S,T;
  int flg=-1;
  cin >> S >> T;

  for (int i = (int)S.size() - (int)T.size(); i >= 0; i--){
    for (int j = i, k=0; k < (int)T.size(); j++, k++){
      if(S[j]!=T[k]){
        break;
      }
      if(k==((int)T.size()-1)){
        flg=i;
      }
    }
    if(flg != -1){
      break;
    }
  }

  if(flg==-1){
    for (int i = (int)S.size() - (int)T.size(); i >= 0; i--){
      for (int j = i, k=0; k < (int)T.size(); j++, k++){
        if(S[j]!='?' && S[j]!=T[k]){
          break;
        }
        if(k==((int)T.size()-1)){
          flg=i;
        }
      }
      if(flg != -1){
        break;
      }
    }
  }

  if(flg==-1){
    printf("UNRESTORABLE\n");
  }else{
    for (int i = 0; i < (int)S.size(); i++){
      if(S[i]=='?' && (i < flg || i >= (flg + (int)T.size()))){
        printf("a");
      }else if(i >= flg && i < (flg + (int)T.size())){
        printf("%c",T[i-flg]);
      }else{
        printf("%c",S[i]);
      }
    }
    printf("\n");
  }
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> p(n), q(n);
  for (int i = 0; i < n; i++)
    cin >> p[i];
  for (int i = 0; i < n; i++)
    cin >> q[i];
  
  vector<int> m(n);
  for (int i = 0; i < n; i++)
    m[i] = i + 1;
  
  int count = 0, idP = 0, idQ = 0;
  do {
    if (m == p)
      idP = count;
    if (m == q)
      idQ = count;
    count++;
  } while (next_permutation(m.begin(), m.end()));

  cout << abs(idP - idQ) << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <map>
using namespace std;
string s;
map<char,int> a;
int main(void){
  a['I'] = 1;
  a['V'] = 5;
  a['X'] = 10;
  a['L'] = 50;
  a['C'] = 100;
  a['D'] = 500;
  a['M'] = 1000;

  while(cin >> s){
    int ans = 0;

    for(int i = 0; i < (int)s.size(); i++){
      if(a[s[i+1]] > a[s[i]]){
	ans -= a[s[i]];
      }
      else{
	ans += a[s[i]];
      }
    }
    cout << ans  << endl;
  }
}

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

using namespace std;
using ll = long long;
using ld = long double;

//#define int long long
//signed main(){
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int k;
    cin >> k;
    vector<int> a(k);
    a[0]=7%k;
    for(int i = 1; i < k; i++) {
        a[i] = (a[i-1]*10+7)%k;
    }
    bool jud=true;
    for(int i = 0; i < k; i++) {
        if(a[i]==0){
            cout << i+1 << "\n";
            return 0;
            jud=false;
        }
    }
    if(jud) cout << "-1" << "\n";

    return 0;
}

Measured memory_bytes: 7132
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define rep(i,n) for(int i=0;i<n;i++)
#define mod 1000000007 // 10^9+7
#define INF 99999999999 //10^12-1
#define dev 998244353 //tenka1
#define P pair<int,int>
#define F first
#define S second
int q;
int l[200000],r[200000];
int n[200000];
vector<int>p;
void make_prime(){
    for(int i=2;i<=100000;i++){
        if(p.empty())p.push_back(i);
        else{
            int l=p.size();
            bool pr=true;
            rep(j,l){
                if(i%p[j]==0){
                    pr=false;
                    break;
                }
            }
            if(pr)p.push_back(i);
        }
    }
}
bool prime(int n){
    if(n<=1)return false;
    for(int i=0;p[i]<=sqrt(n);i++){
        if(n%p[i]==0)return false;
    }
    return true;
}
signed main(){
    cin>>q;
    rep(i,q)cin>>l[i]>>r[i];
    n[0]=0;
    make_prime();
    if(prime(49))cout<<"Yay!"<<endl;
    for(int i=1;i<=100000;i+=2){
        if(prime(i)&&prime((i+1)/2))n[i]=n[i-2]+1;
        else n[i]=n[i-2];
    }
    rep(i,q){
        int a=max(l[i]-2,(int)(0));
        int x=n[a],y=n[r[i]];
        cout<<y-x<<endl;
    }
    return 0;
}



Measured memory_bytes: 4096
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>

using namespace std;

int read(){
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-48,ch=getchar();}
	return x*f;
}

int main()
{
	int n=read();
	int mx=0,ans=0;
	for(int i=1;i<=n;i++){
		int x=read();
		if(x>=mx) mx=x,ans++;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 384
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		String s = sc.next();
		boolean flag = true;
		Deque<Integer> deq = new ArrayDeque<Integer>();
		int now = n;

		OUT:while(now > 0){
			if(now-m>=0) {
				for (int i = m; i > 0 ; i--) {
					if(s.charAt(now-i) == '0') {
						now -= i;
						deq.addFirst(i);
						break;
					}else if(i == 1) {
						flag = false;
						break OUT;
					}
				}
			}else {
				deq.addFirst(now);
				now = 0;
			}
		}

		if(flag) {
			while(!deq.isEmpty()) {
				System.out.printf("%d ", deq.pollFirst());
			}
		}else{
			System.out.println(-1);
		}

		sc.close();
	}
}

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

int main(){
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	while(true){
		c-=b;
		if(c<=0)
			return cout<<"Yes"<<endl,0;
		a-=d;
		if(a<=0)
			return cout<<"No"<<endl,0;
	}
	return 0;
}


Measured memory_bytes: 3596
#include<iostream>
#include<stdio.h>
#include<cmath>
#include<math.h>
#include <iomanip>
#include<algorithm>
#include<vector>
#include <map>
#define rep(i,N) for(int (i)=0;(i) < (N); ++(i))
typedef long long ll;
using namespace std;

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  string s;
  cin >> s;
  string res = "Good";
  rep(i, s.size() - 1){
    if(s[i] == s[i+1]){
      res = "Bad";
      break;
    }
  }
  cout << res << "\n";
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;

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

int partition(vi &a, int p, int r) {
  int x = a[r], i = p - 1;
  
  for (int j = p; j < r; j++) {
    if (a[j] <= x) {
      i++;
      swap(a[i], a[j]);
    }
  }
  
  i++;
  swap(a[i], a[r]);

  return i;
}

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

  vi a(n);
  rep(i, n) cin >> a[i];

  int q = partition(a, 0, n - 1);

  rep(i, n) {
    if (i == q) printf("[%d]", a[i]);
    else printf("%d", a[i]);

    i != n - 1 ? printf(" ") : printf("\n");
  }
}



Measured memory_bytes: 3232
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
using namespace std;

vector<int> enum_divisors(int N) {
    vector<int> res;
    for (int i = 1; i * i <= N; ++i) {
        if (N % i == 0) {
            res.push_back(i);
            // 重複しないならば i の相方である N/i も push
            if (N / i != i) res.push_back(N / i);
        }
    }
    // 小さい順に並び替える
    sort(res.begin(), res.end());
    return res;
}

int main() {
    int N;
    cin >> N;
    int B;
    const auto& res = enum_divisors(N);
    for (int i = 0; i < res.size(); ++i) {
  //      cout << res[i] << endl;
        for (B = 1; B <= 200; B++) {
            if (((pow(res[i]+B,5)-pow(B,5)) == N)) {
                printf("%d %d\n",res[i]+B, B);
                break;
            }
            else if (((pow(res[i] - B, 5) - pow(-B, 5)) == N)) {
                printf("%d %d\n", res[i] - B, -B);
                break;
            }
        }
    }
}

Measured memory_bytes: 4308
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(os.Stdout)

	n := getNextInt(scanner)
	aa := make([]int, n)

	dp := make([]int, n)
	for i := 0; i < n; i++ {
		aa[i] = getNextInt(scanner)
		dp[i] = 1 << 30
	}

	dp[0] = aa[0]
	for i := 1; i < n; i++ {
		l := 0
		r := i
		for l < r {
			m := (l + r) >> 1
			if dp[m] < aa[i] {
				l = m + 1
				continue
			}
			r = m
		}
		dp[l] = aa[i]
	}

	ans := 0
	for i := 0; i < n && dp[i] < 1<<30; i++ {
		ans = i
	}
	fmt.Fprintln(writer, ans+1)
	writer.Flush()
}



Measured memory_bytes: 4772
#include <bits/stdc++.h>
#define REP(i,a,b) for(int i=(a);i<(b);i++)
#define RREP(i,a,b) for(int i=(a);i>=(b);i--)
#define pq priority_queue
#define P pair<int,int>
#define P2 pair<int,P>
#define P3 pair<int,P2>
typedef long long ll; typedef long double ld;
using namespace std;
const int INF=1e9, MOD=1e9+7, around[]={0,1,1,-1,-1,0,-1,1,0,0};
const ll LINF=1e18;
const ld PI=abs(acos(-1));

int main(){
	ll n,t; cin >> n >> t; ll a[100010];
	REP(i,0,n) cin >> a[i];
	
	ll ma = 0, MA = 0, c = 0;
	RREP(i, n - 1, 0){
		ll pos = t / 2 * ma - t / 2 * a[i];
		
		if(MA < pos) MA = pos, c = 1;
		else if(MA == pos) c++;
		ma = max(ma, a[i]);
	}
	
	cout << c << endl;
	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  vector<string> cards(3);
  for(int i=0;i<3;i++){cin>>cards.at(i);}
  int turn=0;
  for(int i=0;i>=0;i++){
    string card=cards.at(turn);
    if(card.size()==0){
      if(turn==0){cout<<'A'<<endl;}
      if(turn==1){cout<<'B'<<endl;}
      if(turn==2){cout<<'C'<<endl;}
      return 0;
    }
    char top=card.at(0);
    if(card.size()>=2){card=card.substr(1,card.size()-1);}
    else{card="";}
    cards.at(turn)=card;
    if(top=='a'){turn=0;}
    if(top=='b'){turn=1;}
    if(top=='c'){turn=2;}
  }
}

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

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

  long long n, a, b; cin >> n >> a >> b;
  long long ans = n / (a + b) * a;
  long long rem = n % (a+b);
  ans += min(rem, a);

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(){
	int x,a,b,c;
	cin >> a >> b >> c >>x;
	int ans=0;
	for(int i=0;i<=a;i++){
		if(500*i>x)break;
		for(int j=0;j<=b;j++){
			if(500*i+100*j>x)break;
			if(x-500*i-100*j<=50*c)ans++;
		}
	}
	cout << ans <<endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <string>
#include <iostream>
#include <math.h>

using namespace std;



int main(void){

    

    string n;
    cin >>n;
    string ans;

    if(n=="ABC") ans = "ARC";
    else ans = "ABC";

    cout<< ans;


    return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <string>
#include <sstream>
#include <utility>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <cmath>
#include <functional>
#include <chrono>
#include <cstring>
#include <limits.h>

using namespace std;
typedef long long lint;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<lint> vl;
typedef pair<lint,lint> pll;

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

    int ans;
    for (int i = 0; i<5; ++i){
        int x; cin>>x;
        if (x == 0) ans = i+1;
    }
    cout<<ans;

}


Measured memory_bytes: 3648
#include<stdio.h>

#include<stdbool.h>

#define N 8
#define FREE -1
#define NOT_FREE 1

int row[N],col[N],dpos[2*N-1],dneg[2*N-1];

bool X[N][N];

void initialize(){
  int i;
  
  for(i=0;i<N;i++){row[i] = FREE,col[i] = FREE;}
  for(i=0;i<2*N-1;i++){dpos[i] = FREE; dneg[i] = FREE;}
}

void printBoard(){
  int i,j;
  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      if(X[i][j]){
	if(row[i] != j)return;
      }
    }
  }
  
  for(i=0;i<N;i++){
    
    for(j=0;j<N;j++){
      if(row[i] == j)printf("Q");
      else printf(".");
    }
    printf("\n");
    
  }
}

void recursive(int i)
{
  int j;
  if(i == N){
    printBoard();
    return;
  }
  for(j=0;j<N;j++){
    if(NOT_FREE == col[j] ||
       NOT_FREE == dpos[i + j] ||
       NOT_FREE == dneg[i - j + N - 1] )continue;
    row[i] = j;
    col[j] = dpos[i + j] = dneg[i - j + N - 1] = NOT_FREE;
    recursive(i + 1);
    row[i] = col[j] = dpos[i + j] = dneg[i - j + N - 1] = FREE;
  }
}

int main(){
  int i,j,k,r,c;
  initialize();
  for(i=0;i<N;i++)
    for(j=0;j<N;j++) X[i][j] = false;

  scanf("%d",&k);
  for(i=0;i<k;i++)
    {
    scanf("%d%d",&r,&c);
    X[r][c] = true;
  }

  recursive(0);

  return 0;
}



Measured memory_bytes: 2108