akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define PI 3.141592653589
#define ll long long int
#define ld long double
#define vi vector<int>
#define vl vector<ll>
#define ii pair<int,int>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define pll pair<ll,ll>
#define vv vector
#define all(v) (v).begin(),(v).end()
int MOD=1e9+7;
ll power(ll a, ll b){//a^b
    ll res=1;
    a=a%MOD;
    while(b>0){
        if(b&1){res=(res*a)%MOD;b--;}
        a=(a*a)%MOD;
        b>>=1;
    }
    return res;
}
ll fermat_inv(ll y){return power(y,MOD-2);}
ll gcd(ll a, ll b){return (b==0)?a:gcd(b,a%b);}
ll min(ll a,ll b){return (a>b)?b:a;}
ll max(ll a,ll b){return (a>b)?a:b;}
bool prime[1000001];
vi primes;
void SieveOfEratosthenes(int n) 
{ 
    memset(prime, true, sizeof(prime)); 
    for (int p=2; p*p<=n; p++) 
    { 
        if (prime[p] == true) 
        { 
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
    for(int p=2;p<1000001;p++)
        if(prime[p])
            primes.pb(p);
}
ll fact[100010];
ll finv[100010];
void factorial(int n){
    fact[0]=1;
    finv[0]=1;
    for(int i=1;i<=n;i++)
        fact[i]=fact[i-1]*i,fact[i]%=MOD,finv[i]=fermat_inv(fact[i]);
}
ll ncr(ll n,ll r)
{
    if(n<r)
        return 0;
    else{
        ll x=finv[r]*finv[n-r]%MOD;
        return fact[n]*x%MOD;
    }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif

    int te=1;
    //cin>>te;
    //SieveOfEratosthenes(1000000);
    //factorial(100005);
    while(te--){
        ll n,x,m;
        cin>>n>>x>>m;
        ll vis[m+1]={0};
        ll mv=0;
        vis[x]=++mv;
        n--;
        ll ans=x;
        //cout<<x<<' '<<ans<<'\n';
        x=x*x%m;

        while(n&&!vis[x]){
            n--;
            ans+=x;
            //cout<<x<<' '<<ans<<'\n';
            vis[x]=++mv;
            x=x*x%m;
        }
        //cout<<ans<<' '<<x<<' '<<vis[x]<<'\n';
        ll cycsum=0,cyclength=mv-vis[x]+1;
        for(int i=0;i<cyclength;i++)
            cycsum+=x,x=x*x%m;
        ans+=cycsum*(n/cyclength);
        n%=cyclength;
        while(n--){
            ans+=x;
            x=x*x%m;
        }
        cout<<ans<<'\n';
    }
}

Measured memory_bytes: 4340
import java.util.Scanner;

public class Main{

	public static void main (String [] args) {

		Scanner sc = new Scanner (System.in);

		int A = sc.nextInt();
		int B = sc.nextInt();

		boolean flag = true;
		int tap = 0;
		int count = 0;
		
		while (flag) {
			if (B==1) {
				break;
			}
			tap += A;
			count++;
			if (tap>=B) {
				flag = false;
			} else {
				tap -= 1;
			}
		}

		System.out.println(count++);
	}
}

Measured memory_bytes: 21716
import Data.Char (digitToInt)
import qualified Data.Set as S

toDigits :: (Integral a, Show a) => a -> S.Set Int
toDigits = S.fromList . fmap digitToInt . show

compute :: (Integral a, Show a) => a -> S.Set Int -> a
compute n ds
    | S.null $ S.intersection (toDigits n) ds = n
    | otherwise = compute (n + 1) ds

main :: IO ()
main = do
    [n, _] <- fmap read . words <$> getLine :: IO [Int]
    ds <- S.fromList . fmap read . words <$> getLine :: IO (S.Set Int)
    print $ compute n ds


Measured memory_bytes: 1020
#include <stdio.h>
int main(void)
{
	int i, x;
	for(i = 1; i>=0; i++){
		scanf("%d", &x);
		
		if(x==0){
			break;
		}
	printf("Case %d: %d\n", i, x);
	}
	return 0;
}



Measured memory_bytes: 2044
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

ll a[100000];
ll b[100000];

void die() {
  cout << "No\n";
  exit(0);
}

void solve() {
  int n;
  cin >> n;
  for(int i = 0; i < n; i++) cin >> a[i];
  for(int i = 0; i < n; i++) cin >> b[i];
  multiset<ll> dp;
  for(int i = 0; i < n; i++) dp.insert(a[i] - b[i]);
  while(dp.size()) {
    if(*dp.rbegin() <= 0) break;
    if(*dp.begin() >= -1) die();
    auto lhs = dp.begin();
    auto rhs = dp.find(*dp.rbegin());
    ll lhslhs = *lhs;
    ll rhsrhs = *rhs;
    dp.erase(lhs);
    dp.erase(rhs);
    ll delta = min(-lhslhs/2, rhsrhs);
    lhslhs += 2 * delta;
    rhsrhs -= delta;
    if(lhslhs) dp.insert(lhslhs);
    if(rhsrhs) dp.insert(rhsrhs);
  }
  cout << "Yes\n";
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  /*
  int t;
  cin >> t;
  for(int i = 1; i <= t; i++) {
    cout << "Case #" << i << ": ";
    solve();
  }
  */
  solve();
}


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

int main() {
  int N, T;
  cin >> N >> T;
  int t[N];
  for (int i=0 ; i<N ; i++) {
    cin >> t[i];
  }
  long long ans = T;
  for (int i=1 ; i<N ; i++) {
    if (t[i] < t[i-1] + T) {
      ans += t[i] - t[i-1];
    } else {
      ans += T;
    }
  }
  cout << ans << endl;
}


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

c, s, f = [], [], []
for _ in range(n - 1):
    temp = [int(_) for _ in input().split()]
    c.append(temp[0])
    s.append(temp[1])
    f.append(temp[2])

for i in range(n):
    answer = 0
    for j in range(i, n - 1):
        if answer < s[j]:
            answer = s[j] + c[j]
        else:
            answer = ((answer - 1) // f[j] + 1) * f[j] + c[j]
    print(answer)


Measured memory_bytes: 3064
while 0 != ( n = gets.to_i )
	s = gets.split( " ").map { |val| val.to_f }
	t = 0
	s.each { |val| t += val }
	m = t / n
	t = 0
	s.each { |val| t += ( val - m )**2 }
	puts( Math.sqrt( t/n ) )
end

Measured memory_bytes: 6168
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

vector<ll>X[101010], Y[101010];

int main(){

    ll N;
    cin >> N;
    vector<ll>x(N), y(N), flg(N, 0);
    ll ans = 0;
    for(ll i = 0; i < N; i++){
        cin >> x[i] >> y[i];
        X[x[i]].push_back(i);
        Y[y[i]].push_back(i);
    }    
    for(ll i = 0; i < N; i++){
        if(flg[i])continue;
        ll cnt = 1;
        flg[i] = 1;
        set<ll>XS;
        set<ll>YS;
        XS.insert(x[i]);
        YS.insert(y[i]);
        queue<ll>Q;
        Q.push(i);
        while(!Q.empty()){
            ll xx = x[Q.front()];
            ll yy = y[Q.front()];
            Q.pop();
            for(ll j = 0; j < X[xx].size(); j++){
                ll k = X[xx][j];
                if(flg[k])continue;
                cnt++;
                flg[k] = 1;
                YS.insert(y[k]);
                Q.push(k);
            }
            for(ll j = 0; j < Y[yy].size(); j++){
                ll k = Y[yy][j];
                if(flg[k])continue;
                cnt++;
                flg[k] = 1;
                XS.insert(x[k]);
                Q.push(k);
            }
        }
        ans += XS.size() * YS.size() - cnt;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 15616
#B-Path
a1,b1=map(int,input().split( ))
a2,b2=map(int,input().split( ))
a3,b3=map(int,input().split( ))
x=[a1,b1,a2,b2,a3,b3]
y=[x.count(i) for i in range(1,5)]
if max(y)==3 or min(y)==0:
    print("NO")

else:
    print("YES")

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

int main(){
	int x,y,z,i=1;
  	cin >> x >> y >> z;
  	for(;;i++){
  		if(z*(i+1)+y*i>x){
      		break;
    	}
    }
    cout << i-1 << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
    public static void main(String[] args){

        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();

        String judge[] = {"AC","WA","TLE","RE"};
        int count[] = {0,0,0,0};

        for(int loop = 0; loop<N; loop++){
            String result = scanner.next();
            switch(result){
                case "AC":
                    count[0]++;
                    break;
                case "WA":
                    count[1]++;
                    break;
                case "TLE":
                    count[2]++;
                    break;
                case "RE":
                    count[3]++;
                    break;
                default:
                    break;
            }
        }

        for(int loop = 0; loop < 4; loop++){
            System.out.println( judge[loop] + " x " + count[loop] );
        }
    }
}

Measured memory_bytes: 58272
#include <stdio.h>

int main() {
  int n,q,i,j,C;
  scanf("%d", &n);
  long S[n];
  for(i = 0; i < n; i++) scanf("%ld", S+i);
  scanf("%d", &q);
  long T;C = 0;
  for(i = 0; i < q; i++) {
    scanf("%ld",&T);
    for(j = 0; j < n; j++) if(T == S[j]) { C++;break;}
  }

  printf("%d\n",C);
  
  return 0;
}

Measured memory_bytes: 676
import sys
import itertools
# import numpy as np
import time
import math
 
sys.setrecursionlimit(10 ** 7)
 
from collections import defaultdict
 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

X, Y = map(int, readline().split())

for i in range(0, 101):
    for j in range(0, 101):
        if i + j == X:
            if i * 2 + j * 4 == Y:
                print("Yes")
                exit()
print("No")

Measured memory_bytes: 9540
#include<bits/stdc++.h>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;
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 long long INF = 1LL << 60;

using namespace std;
using Edge = pair<int, long long>;
int N, M;
vector<vector<Edge>> G;

int main() {
    cin >> N >> M;
    G.clear(); G.resize(N);
    for (int i = 0; i < M; ++i) {
        int a, b; ll w;
        cin >> a >> b >> w; --a; --b;
        G[a].push_back(Edge(b, -w));
    }

    vector<ll> dist(N, INF);
    bool negative = false;
    dist[0] = 0;
    for (int iter = 0; iter <= N*2; ++iter) {
        for (int v = 0; v < N; ++v) {
//            if (dist[v] >= INF / 2) continue;
            for (auto e: G[v]) {
                if (chmin(dist[e.first], dist[v] + e.second)) {
                    if (e.first == N - 1 && iter == N * 2) negative = true;
                }
            }
        }
    }

    if(!negative) cout << -dist[N-1] << endl;
    else cout << "inf" << endl;

}

Measured memory_bytes: 384
a,b,k=map(int,input().split())

ansl=[]

for i in range(a,min(b+1,a+k)):
    ansl.append(i)
for i in range(b,max(b-k,a-1),-1):
    ansl.append(i)

ansl=list(set(ansl))
ansl.sort()
for ans in ansl:
    print(ans)

Measured memory_bytes: 9188
#include <iostream>
#include <stdio.h>
#include <string>
#include <math.h>
using namespace std;

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

	if(a.at(a.length()-1) == b.at(0) && b.at(b.length()-1) == c.at(0)) cout << "YES" << endl;
	else cout << "NO" << endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	Scanner sc = new Scanner(System.in);
	
	void doIt() {
		sB();
	}
	
	void sB(){
		int N = sc.nextInt();
		int L;
		int max = 0;
		int sum = 0;
		for(int i = 0; i < N; i++) {
			L = sc.nextInt();
			sum += L;
			if(L > max) max = L;
		}
		if(sum - max <= max) System.out.println("No");
		else System.out.println("Yes");
	}
	
	public static void main(String[] args) {
		new Main().doIt();
	}
}


Measured memory_bytes: 23124
#include <algorithm>
#include <iostream> //入出力
#include <stdio.h>
#include <map>
#include <string>
#include <math.h>
#include <vector>
#include <cstdlib>
#include <queue>
#include <stack>
#include <list>
#include <iomanip> //小数点以下を表示させる(setprecision())
//#include <bits/stdc++.h>
using namespace std;
typedef long long ll; //64bit型

#define debug(x) cerr << x << " " \
                      << "(L:" << __LINE__ << ")" << '\n'
#define PRINT(V)                                   \
        {                                          \
                for (int i = 0; i < V.size(); i++) \
                {                                  \
                        cout << V[i] << " ";       \
                }                                  \
                cout << endl;                      \
        }

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

int main()
{
        //input->compute->output//
        int A, B, C;
        cin >> A>>B>>C;
        cout << A * B / 2 << endl;
        return 0;
}


Measured memory_bytes: 256
n,a,b = map(int, input().split())

num = map(int, str(n))

nums = []

def digitSum(n):
    s = str(n)
    array = list(map(int, list(s)))
    return sum(array)

for i in range(n+1):
    if a <= digitSum(i) <= b:
        nums.append(i)

print(sum(nums))

Measured memory_bytes: 3428
S = input()
K = int(input())

P = []
len_s = len(S)
for k in range(1, K+1):
    for i in range(len_s-k+1):
        P.append(S[i:i+k])
P.sort()

ans = P[0]
cnt = 1
i = 1
while cnt < K:
    if ans != P[i]:
        ans = P[i]
        cnt += 1
    i += 1

print(ans)

Measured memory_bytes: 4340
import collections
import numpy as np
import sys
import copy
from functools import lru_cache


sys.setrecursionlimit(10**8)
#N,K=map(int,input().split())
N=int(input())
#h=np.array(list(map(int,input().split())))
#ans=0
num2alpha = lambda c: chr(c+96)


def dfs(K,b,s):
    if len(s)==N:
        return b.append(s)
        s=""
    elif len(s)>N:
        return
    elif len(s)<N:
        x = copy.deepcopy(s)
        for i in range(N):
            if i+1-len(set(x))< 2:
                s=x+num2alpha(i+1)
                dfs(N-1, b, s)
B=list()
m=""
dfs(N-1,B,m)
for i in B:
    print(i)


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

using namespace std;

int solve(int N, vector<int> &cnt)
{
    if (cnt[0] == N) return 1;

    int res = 0, p = (cnt[1] > cnt[2] ? 1 : 2);
    cnt[p]--;
        
    while (1) {
        res++;
        if (p == 0) {
            break;
        } else if (p == 1) {
            if (cnt[1] > 0) {
                cnt[1]--;
                p = 2;
            } else if (cnt[0] > 0) {
                cnt[0]--;
                p = 1;
            } else {
                p = 0;
                if (cnt[2] == 0) {
                    break;
                }
            }                
        } else {
            if (cnt[2] > 0) {
                cnt[2]--;
                p = 1;
            } else if (cnt[0] > 0) {
                cnt[0]--;
                p = 2;
            } else {
                p = 0;
                if (cnt[1] == 0) {
                    break;
                }
            }
        }
    }
    return res;
}

int main()
{
    int N;
    cin >> N;
    int a;
    vector<int> cnt(3, 0);
    for (int i = 0; i < N; i++) {
        cin >> a;
        cnt[a%3]++;
    }

    cout << solve(N, cnt) << endl;
    return 0;
}

Measured memory_bytes: 3096
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <map>
#include <cstdlib>
#include <math.h>

using namespace std;

typedef long long ll;
#define rep(i, n) for(long (i) = 0; (i) < (long) (n); (i)++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,a,b) for(long i=(a);i<(b);i++)
#define rrep1(i,a,b) for(long i=(a);i<=(b);i++)
#define rrrep(i,a,b) for(long i=(a);i>=(b);i--)
#define define pb push_back
#define ALL(obj) (obj).begin(), (obj).end()
#define X first
#define Y second
#define vi vector<int>
#define vl vector<ll>
#define vvi vector<vector<int> >
#define vpl vector<pair<long, long> >
#define vppl vector<pair<long, pair<long, long> > >

const int INF = 100100100;
const long LONG_INF = 2147483647;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
const ll LINF = 1e18;


int pow(int x) {
	if (x == 0) {
		return 1;
	}
	else {
		return pow(x - 1) * 2;
	}
}

int main(int argc, char const *argv[])
{
	cin.tie(0);
	ios::sync_with_stdio(false);
    int k,x;
    cin >> k >> x;
    for(int i= -k+1; i < k;i++) {
        cout << i + x << " ";
    }
    return 0;
}


Measured memory_bytes: 256
S = input()

if S == "MON":
    print(6)
elif S == "TUE":
    print(5)
elif S == "WED":
    print(4)
elif S == "THU":
    print(3)
elif S == "FRI":
    print(2)
elif S == "SAT":
    print(1)
elif S == "SUN":
    print(7)

Measured memory_bytes: 3060
#include <iostream>
    #include <algorithm>
    #include <string>
    #include <cmath>
    #include <ctype.h>
    #include <map>
    #include <vector>
    #define REP(i,n) for(int i=0;i<(int)n;i++)
    #define REP1(j,n) for(int j=0;j<(int)n;j++)
    #define REPD(i,n) for(int i=n;i>=0;i--)
    #define REPD1(j,n) for(int j=n;j=>0;j--)
    #define REPS(i,n) for(int i=1;i<=(int)n;i++)
    #define REPS1(j,n) for(int j=1;j<=(int)n;j++)
    #define rep(i,a,n) for(int i=a;i<=(int)n;i++)
    #define SZ(x) ((int)(x).size())	//size() unsigned -> int
    #define DescSort(a) sort(a.begin(),a.end(),std::greater<int>())
     
    using namespace std;
    typedef long long ll;
     
    int main(void) {
    	int a,b;
    	cin >> a>>b;
    	if (b%a == 0) cout << a + b << endl;
    	else cout << b - a << endl;
    	return 0;
    }

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll MOD = 1000000007;
const ll INF = 1061109567;
const ll MAX = 1e18;
const double EPS = 1e-10;
int main(){
    int N;
  cin>>N;
  	ll a[N];
    ll buf=1;
  for(ll i=0;i<N;i++){
    cin>>a[i];
    if(a[i]==0){
      cout<<a[i]<<endl;
      return 0;
    }
  }
  for(ll i=0;i<N;i++){
    if(buf<=MAX/a[i]){buf*=a[i];}
    else{cout<<"-1"<<endl;return 0;}
  }
  cout<<buf<<endl;
        return 0;
}

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

const int MAX = 100000;
const long long _INFINITY = 1LL << 60;
long long dp[MAX];
long long h[MAX];

int main(int argc, const char * argv[]) {
    int N;
    
    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> h[i];
    }
    
    for (int i = 0; i < MAX; i++) {
        dp[i] = _INFINITY;
    }
    
    dp[0] = 0;
    
    for (int i = 0; i < N; i++) {
        long long min = dp[i] + abs(h[i] - h[i + 1]);
        if (dp[i + 1] > min) {
            dp[i + 1] = min;
        }
        min = dp[i] + abs(h[i] - h[i + 2]);
        if (dp[i + 2] > min) {
            dp[i + 2] = min;
        }
    }
    
    cout << dp[N - 1] << endl;
 
    return 0;
}

Measured memory_bytes: 1792
using System;
using System.Linq;
using System.Collections.Generic;
using System.Numerics;

namespace ABC174
{
    class Program
    {
        static void Main(string[] args)
        {
            //var NK = Console.ReadLine().Split().Select(long.Parse).ToArray();
            //var p = Console.ReadLine().Split().Select(long.Parse).OrderBy(x => x).ToArray();
            // var CA = Enumerable.Repeat(0, (int)N).Select(_ => Console.ReadLine().Split().Select(long.Parse).ToArray()).ToArray();
            var K = long.Parse(Console.ReadLine());
            var x = 7L;
            for (long i = 0; i <= 10000000; i++)
            {
                if (x % K == 0) { Console.WriteLine(i + 1); return; }
                x = (10 * x + 7) % K;
            }
            Console.WriteLine(-1);
        }
    }
}


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

#define ll long long
#define mod 1000000007
#define pb push_back
#define pi pair<int,int>
#define vi vector<int>
#define vpi vector< pi > 

int a[27]={0};
int main()
{
	int n,m;
	cin>>n>>m;
	for(int i=0;i<n;i++)
		for(int j=0;j<m;j++)
		{
			char c;
			cin>>c;
			a[c-'a']++;
		}
		int x1=0,x2=0,x3=0;
		for(int i=0;i<26;i++)
		{
			if(a[i]%4==1)
				x1++;
			if(a[i]%4==2)
				x2++;
			if(a[i]%4==3)
				x3++;
		}
		if(n<m)
			swap(n,m);
		if(x1>1||(x1>0&&x3>0))
		{
			cout<<"No";
			return 0;
		}
		if(n%2==1&&m%2==1)
		{
			if(x3>1||(x1==0&&x3==0))
				{
					cout<<"No";
					return 0;
				}
				if(n+m-1<(x1+x2*2+x3*3)||((n+m-1)-(x1+x2*2+x3*3))%4!=0)
				{
					cout<<"No\n";
					return 0;
				}
				cout<<"Yes";
				return 0;
		}
		else if(m==1)
		{
			if(x1>0||x3>0)
			{
				cout<<"No";
				return 0;
			}
			cout<<"Yes";
			return 0;

		}
		else if(n%2==1||m%2==1)
		{
			if(n%2!=0)
				swap(n,m);
			if((x2>0&&(x2*2>n||(n-x2*2)%4!=0))||x3>0||x1>0)
			{
				cout<<"No";
				return 0;
			}
			cout<<"Yes";
			return 0;
		}
		else
		{
			if(x1>0||x2>0||x3>0)
				cout<<"No";
			else
				cout<<"Yes";
		}


	return 0;
}

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

int main()
{  
    int n;
    cin>>n;
    set<int>s;
    REP(i,n)
    {
        int x,y;
        cin>>x>>y;
        if(x==0){s.insert(y);cout<<s.size()<<endl;}
        if(x==1)cout<<s.count(y)<<endl;
        if(x==2)
        {
            if(s.find(y)!=s.end())s.erase(y);
        }
        if(x==3)
        {
            int z;
            cin>>z;
            decltype(s)::iterator it=s.lower_bound(y);
            decltype(s)::iterator end=s.upper_bound(z);
            while(it!=end)
            {
                cout<<*it<<endl;
                ++it;
            }
        }
    }
}



Measured memory_bytes: 12444
from sys import *
from math import *
from collections import deque
input = stdin.readline
lmi = lambda: list(map(float, input().split()))
mi = lambda: map(int, input().split())
si = lambda: input().strip('\n')
ssi = lambda: input().strip('\n').split()

n, m = mi()
print(n*(n-1)//2 + m*(m-1)//2)

Measured memory_bytes: 27884
#include<iostream>

using namespace std;

int main(){
  char s;
  cin>>s;
  
  if(s=='A')
    cout<<"T"<<endl;
  else if(s=='T')
    cout<<"A"<<endl;
  else if(s=='C')
    cout<<"G"<<endl;
  else
    cout<<"C"<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i)
#define rrepLRE(i, l, r) for (ll i = (l); i >= (r); --i)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

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

/* Macros reg. ends here */

const ll INF = 1LL << 50;

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);

  ll a, b;
  cin >> a >> b;
  cout << max(a - b, 0LL) << endl;

  return 0;
}


Measured memory_bytes: 256
using System;
 
public class NextAlphabet {
    public static void Main(){
        char C = Console.ReadLine().ToCharArray()[0];
        string alphstr = "abcdefghijklmnopqrstuvwxyz";
        char[] alph = alphstr.ToCharArray();
        for (int i = 0 ; i < alph.Length ; i++)
        {
            if (C == alph[i])
            {
                Console.WriteLine(alph[i+1]);
                break;
            }
        }
    }
}

Measured memory_bytes: 11092
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <string>

using namespace std;

char s[110];

int main()
{
    scanf("%s", s);
    int l = strlen(s);
    bool flag = true;
    for(int i = 0; i < l; i ++){
        if(i % 2 == 0){
            if(s[i] == 'R' || s[i] == 'U' || s[i] == 'D') continue;
            else {flag = false;break;}
        }
        else {
            if(s[i] == 'L' || s[i] == 'U' || s[i] == 'D') continue;
            else {flag = false;break;}
        }
    }
    if(flag) printf("Yes\n");
    else printf("No");
    return 0;
}


Measured memory_bytes: 256
package main

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

var sc *bufio.Scanner

func init() {
	// 100MB
	bufsize := 100 * 1024 * 1024
	sc = bufio.NewScanner(os.Stdin)
	sc.Buffer(make([]byte, bufio.MaxScanTokenSize), bufsize)
	sc.Split(bufio.ScanWords)
}
func readInt() int              { return readIntArray(1)[0] }
func readInt2() (int, int)      { a := readIntArray(2); return a[0], a[1] }
func readInt3() (int, int, int) { a := readIntArray(3); return a[0], a[1], a[2] }
func readIntArray(n int) []int {
	s := readStringArray(n)
	a := make([]int, n)
	for i := range a {
		a[i], _ = strconv.Atoi(s[i])
	}
	return a
}
func readString() string            { return readStringArray(1)[0] }
func readString2() (string, string) { a := readStringArray(2); return a[0], a[1] }
func readStringArray(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		sc.Scan()
		a[i] = sc.Text()
	}
	return a
}
func max(ns ...int) int {
	max := ns[0]
	for _, n := range ns {
		if n > max {
			max = n
		}
	}
	return max
}
func min(ns ...int) int {
	min := ns[0]
	for _, n := range ns {
		if n < min {
			min = n
		}
	}
	return min
}
func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

func main() {
	X, Y, Z := readInt3()
	fmt.Printf("%d %d %d\n", Z, X, Y)
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

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

	string input;
	input.reserve(100000);
	cin >> input;

	int32_t count_p{ count(input.cbegin(), input.cend(), 'p') };

	cout << input.size() / 2 - count_p << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define ll long long

using namespace std;

const int N = 1e6 + 100;

string s;
ll Dp[N][2];

ll Solve(int idx, bool carry)
{
    if (idx == 0) return carry;

    ll &ret = Dp[idx][carry];
    if (ret + 1) return ret;

    int x = (s[idx] - '0') + carry;

    ll C1 = Solve(idx - 1, 0) + x;
    ll C2 = Solve(idx - 1, 1) + (10 - x);

    return ret = min(C1, C2);
}

int main()
{
    cin >> s;   s = "00" + s;

    memset(Dp, -1, sizeof Dp);

    cout << Solve(s.size() - 1, 0) << '\n';

    return 0;
}

Measured memory_bytes: 63792
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)

using namespace std;

int main() {
   int a,b;
   cin >> a >> b; 
   cout << (a<=8 && b<=8 ? "Yay!" : ":(") << endl;
}

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

#define mod 1000000007

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

using namespace std;
typedef long long ll;
const long long INF = 1LL << 60;

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

int W, H;
vector<vector<int> > c;
void dfs(int h, int w){
    c[h][w] = 0;
    rep(dir, 8){
        int nh = h + dx[dir];
        int nw = w + dy[dir];

        if(nh < 0 || nh >= H || nw < 0 || nw >= W || c[nh][nw] == 0)
            continue;
        dfs(nh, nw);
    }
}
 
int main(void){
    while(1){
        cin >> W >> H;
        if(W == 0 && H == 0)
            break;
        c.resize(H);
        rep(i, H){
            c[i].resize(W);
            rep(j, W)
                cin >> c[i][j];
        }
        int count = 0;
        rep(i, H){
            rep(j, W){
                if(c[i][j] == 0)
                    continue;
                dfs(i, j);
                count++;  
            }
        }
        cout << count << endl;
    }
	
	return 0;
}


Measured memory_bytes: 3204
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stdio.h>

using namespace std;

int main()
{
    string s, t;
    cin >> s;
    t = s;
    int n = s.length() / 2;
    reverse(s.begin(), s.end());
    int count = 0;
    for (int i = 0; i < n; i++)
    {
        if (s[i] != t[i])
        {
            count++;
        }
    }
    cout << count << endl;

    return 0;
}

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

typedef long long LL;

const int N=5000,mod=1000000007;

int add(int a,int b,int p=mod){return a+b>=p?a+b-p:a+b;}
int sub(int a,int b,int p=mod){return a-b<0?a-b+p:a-b;}
int mul(int a,int b,int p=mod){return (LL)a*b%p;}
void sadd(int &a,int b,int p=mod){a=add(a,b,p);}
void ssub(int &a,int b,int p=mod){a=sub(a,b,p);}
void smul(int &a,int b,int p=mod){a=mul(a,b,p);}
int Power(int a,int k,int p=mod){int res=1;for (;k;k>>=1,smul(a,a,p)) if (k&1) smul(res,a,p);return res;}

int n,a[N+9];

void into(){
  scanf("%d",&n);
  for (int i=1;i<=n;++i)
	scanf("%d",&a[i]);
}

int pw[N+9];

void Get_pw(){
  pw[0]=1;
  for (int i=1;i<=n;++i) pw[i]=mul(pw[i-1],n-1);
}

int uni[N+9],siz[N+9];

int Query_uni(int k){return k==uni[k]?k:uni[k]=Query_uni(uni[k]);}

int ans;

void Get_a(){
  int cnt=0;
  for (int i=1;i<=n;++i) cnt+=a[i]==-1,uni[i]=i,siz[i]=1;
  ans=mul(n,pw[cnt]);
  for (int i=1;i<=n;++i){
	if (a[i]==-1) continue;
	int fx=Query_uni(i),fy=Query_uni(a[i]);
	if (fx==fy){
	  siz[fx]=0;
	  ssub(ans,pw[cnt]);
	}else{
	  uni[fx]=fy;
	  siz[fy]=siz[fx]&&siz[fy]?siz[fx]+siz[fy]:0;
	}
  }
  int ca=0;
  for (int i=1;i<=n;++i)
	if (siz[i]&&Query_uni(i)==i){
	  a[++ca]=siz[i];
	  if (siz[i]>1) ssub(ans,mul(siz[i]-1,pw[max(cnt-1,0)]));
    }
  n=ca;
}

int dp[N+9][N+9];

void Get_dp(){
  for (int i=1;i<=n;++i){
	dp[i][1]=add(dp[i-1][1],a[i]);
	for (int j=2;j<=i;++j) dp[i][j]=add(dp[i-1][j],mul(dp[i-1][j-1],mul(a[i],j-1)));
  }
  for (int i=2;i<=n;++i) ssub(ans,mul(dp[n][i],pw[n-i]));
}

void work(){
  Get_pw();
  Get_a();
  Get_dp();
}

void outo(){
  printf("%d\n",ans);
}

int main(){
  into();
  work();
  outo();
  return 0;
}

Measured memory_bytes: 70476
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL //デバッグ出力系
#define dout(s) cout<<s<<"\n";
#define debug() if(true)
#else
#define dout(s)
#define debug() if(false)
#endif//
#define next asdnext
#define prev asdprev
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define vout(v) for(auto &i:v){cout<<i<<" ";}cout<<"\n"; //配列出力
#define vin(v) for(auto &i:v)cin>>i; //配列入力
#define vec(v,n) vector<int> v(n);
typedef long long ll;
typedef unsigned long long ull;

void Main() {
	int N, M;
	cin >> N >> M;
	vec(L, M);
	vec(R,M);

	rep(i,M) {
		cin >> L[i] >> R[i];
	}
	int _max=-1, _min=1e6;
	rep(i,M) {
		_max = max(_max,L[i]);
		_min = min(_min, R[i]);
	}

	dout("Max"+to_string(_max) + "\tMin"+ to_string(_min));

	if (_min+1-_max > 0) {
		cout << _min + 1 - _max <<"\n";
	}
	else {
		cout << 0<<"\n";
	}
}

int main() {
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << std::fixed << std::setprecision(15);
	Main();
	return 0;
}


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

using namespace std;
typedef long long ll;

#define INF (long long)(1e9+7)
#define REP(i,n) for(ll i = 0; i < n; i++)
#define REP1(i,n) for(ll i = 1; i <= n; i++)

int main(void)
{
    int n;
    cin >> n;
    cout << (n / 2 + n % 2) << endl;

}


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

using namespace std;

const long long MOD = 1000000007LL;
long long GCD(long long a, long long b){return b == 0 ? a : GCD(b, a % b);}
long long fast_exp(long long base, long long exp, long long mod = MOD) {
    long long tot = 1;
    for(;exp > 0;exp >>= 1) {
       if((exp & 1) == 1) tot = tot * base % mod;
       base = base * base % mod;
    }
    return tot;
}

int arr[2003], dp[2003][2003][2];

int helper(int pos, int p1, int p2, int turn = 0){

    if(pos <= 0) return abs(arr[p1] - arr[p2]);

    if(dp[p1][p2][turn] != -1)
        return dp[p1][p2][turn];

    if(turn == 0){
        int best = max(helper(pos - 1, pos - 1, p2, 0), helper(pos - 1, p1, pos - 1, 1));
        dp[p1][p2][turn] = best;
        return best;
    } else {
        int best = min(helper(pos - 1, pos - 1, p2, 0), helper(pos - 1, p1, pos - 1, 1));
        dp[p1][p2][turn] = best;
        return best;
    }

}

int main(){

    cin.sync_with_stdio(0); cin.tie(0); cout.tie(0);

    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    //

    int n, z, w; cin >> n >> z >> w;

    for(int i = 0; i < n; ++i)
        cin >> arr[n - i - 1];

    for(int i = 0; i < 2003; ++i)
        for(int j = 0; j < 2003; ++j)
            dp[i][j][0] = dp[i][j][1] = -1;

    arr[n] = w;
    arr[n + 1] = z;


    cout << helper(n + 1, n + 1, n) << "\n";

    return 0;

}


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

bool isPossible(int N, int M, int K)
{
    int i, j;
    int black;
    for(i = 0; i <= N; ++i){
        for(j = 0; j <= M; ++j){
            black = i * (M - j) + j * (N - i);
            if(black == K) return true;
        }
    }
    return false;
}

int main()
{
    int N, M, K;
    int i, j;
    cin >> N >> M >> K;

    if(isPossible(N, M, K)) {
        cout << "Yes";
    } else {
        cout << "No";
    }
    return 0;
}

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

int main(void)
{
    int a, b;
    int ans;
    scanf("%d%d", &a, &b);

    if (a % 2 != b % 2)
    {
        puts("IMPOSSIBLE");
        return 0;
    }

    for (ans = 0; ans < a + b; ans++)
        if (abs(a - ans) == abs(b - ans))
            break;

    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 128
//Think simple yet elegant.
#include <bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll  unsigned long long
#define all(v) v.begin(),v.end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define pi pair<int,int>
const ll maxn=105;
const ll mod=1e9+7;

int main(){
	fast;
	ll n,i,j,k,ans=0;
	cin>>n;
	vector<ll> a(n+1),p(n+1);
	for(i=1;i<=n;++i){
		cin>>a[i];
		if(i>1){
			p[i]=p[i-1]+a[i];
		}
		else
		p[1]=a[1];
	}
	ll term;
	p[n]%=mod;
	for(i=1;i<=n;i++){
		p[i]%=mod;
		term=((a[i]*p[n])%mod-(a[i]*p[i])%mod+mod)%mod;
		ans=(ans%mod+term%mod+mod)%mod;
	}
	cout<<ans;
}

Measured memory_bytes: 6368
#include <stdio.h>

int memo[3000][3001];

int tanosisa[3000];
int zikan[3000];

int tansaku(int yomisemax,int hanabi,int timemax,int nextyomise,int ctime);

int main(void) {
	int yomisenum;
	int hanabitime,endtime;
	int i;
	int result;
	scanf("%d%d%d",&yomisenum,&endtime,&hanabitime);
	for(i=0;i<yomisenum;i++) {
		scanf("%d%d",&tanosisa[i],&zikan[i]);
	}
	result=tansaku(yomisenum,hanabitime,endtime,0,0);
	printf("%d\n",result);
	return 0;
}

int tansaku(int yomisemax,int hanabi,int timemax,int nextyomise,int ctime) {
	int result;
	int nowresult;
	int nexttime;
	if(nextyomise>=yomisemax)return 0;
	if(memo[nextyomise][ctime]>0)return memo[nextyomise][ctime]-1;
	/*don't play*/
	result=tansaku(yomisemax,hanabi,timemax,nextyomise+1,ctime);
	/*play*/
	nexttime=ctime;
	if(nexttime<hanabi && nexttime+zikan[nextyomise]>hanabi)nexttime=hanabi;
	nexttime+=zikan[nextyomise];
	if(nexttime<=timemax) {
		nowresult=tansaku(yomisemax,hanabi,timemax,nextyomise+1,nexttime);
		nowresult+=tanosisa[nextyomise];
		if(nowresult>result)result=nowresult;
	}
	memo[nextyomise][ctime]=result+1;
	return result;
}

Measured memory_bytes: 0
#include <iostream>
#include <map>
#include <vector>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;

int main(){
    int n, m;
    cin >> n >> m;
    map<int, int> num;
    rep(i, n) num[i] = -1;

    vector<int> s(m);
    vector<int> c(m);
    rep(i, m) {
        cin >> s.at(i) >> c.at(i);
        s[i]--;
    }

    rep(i, m) {
        if (num[s[i]] != -1 && num[s[i]] != c[i]) {
            cout << -1 << endl;
            return 0;
        }
        num[s[i]] = c[i];
    }

    if (n > 1) {
        if (num[0] == 0) {
            cout << -1 << endl;
            return 0;
        } else if (num[0] == -1) {
            num[0] = 1;
        }
        rep(i, n) {
            if (num[i] == -1) cout << 0;
            else cout << num[i];
        }
        cout << endl;
        return 0;
    } else { // N == 1
        if (num[0] == -1) num[0] = 0;
        cout << num[0] << endl;
        return 0; 
    }
}


Measured memory_bytes: 256
n,k=map(int,input().split())
arr=[]
for _ in range(k):
	arr.append(list(map(int,input().split())))
pref=[0]*(n+1)
dp=[0]*(n+1)
dp[0]=1
pref[0]=1
for i in range(1,n):
	for j in range(k):
		if(arr[j][1]<=i):
			dp[i]=(dp[i]+pref[i-arr[j][0]]-pref[i-arr[j][1]-1])%998244353
		elif(arr[j][0]<=i):
			dp[i]=(dp[i]+pref[i-arr[j][0]])%998244353
	pref[i]=(pref[i-1]+dp[i])%998244353
print(dp[n-1])

Measured memory_bytes: 71116
require 'set'; require 'prime'
INF=Float::INFINITY; MOD=10**9+7
n,q = gets.chomp.split.map(&:to_i)
s = gets.chomp

dp = Array.new(n)
dp[0] = 0
1.upto(n-1).each do |i|
  dp[i] = dp[i-1]
  if s[i-1] == 'A' && s[i] == 'C'
    dp[i] += 1
  end
end

q.times do
  l,r = gets.chomp.split.map(&:to_i)
  puts dp[r-1] - dp[l-1]
end




Measured memory_bytes: 5884
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define pb push_back
#define MOD 1000000007
int f[26];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n=0,k=0,sum=0,flag=0,x=0;string s;
    cin>>n>>k;
    for(int i=0;i<n;++i)
    {
        cin>>s;
        f[s[0]-'A']++;
    }
    while(!flag)
    {
        sum=0;
        for(int i=0;i<26;++i)
            sum+=f[i];
        x=sum/k;
        flag=1;
        for(int i=0;i<26;++i)
        {
            if(f[i]>x)
            {
                f[i]=x;
                flag=0;
            }
        }
    }
    cout<<x<<endl;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
main(){
	int n,m;
	while(cin>>n,n){
		char a,b,l[62] = {0};
		while(n--)
			cin >> a >> b,l[a > 96?a - 97:a > 64?a - 39:a > 47?a + 4:0] = b;
		cin >> m;
		string s = "";
		while(m--){
			cin >> a;b = l[a > 96?a - 97:a > 64?a - 39:a > 47?a + 4:0];if(b==0)b = a;s+=b;}
		cout << s << endl;
	}
}

Measured memory_bytes: 1120
// C++ program to find Excel 
// column name from a given 
// column number 
#include <bits/stdc++.h> 
#define MAX 50 
using namespace std; 
#define ll long long
// Function to print Excel column name for a given column number 
void printString(ll n) 
{ 
	char str[MAX]; // To store result (Excel column name) 
	ll i = 0; // To store current index in str which is result 

	while (n > 0) { 
		// Find remainder 
		int rem = n % 26; 

		// If remainder is 0, then a 'Z' must be there in output 
		if (rem == 0) { 
			str[i++] = 'z'; 
			n = (n / 26) - 1; 
		} 
		else // If remainder is non-zero 
		{ 
			str[i++] = (rem - 1) + 'a'; 
			n = n / 26; 
		} 
	} 
	str[i] = '\0'; 

	// Reverse the string and print result 
	reverse(str, str + strlen(str)); 
	cout << str << endl; 

	return; 
} 

// Driver program to test above function 
int main() 
{ 
	ll x;cin>>x;
	printString(x);
	return 0; 
} 


Measured memory_bytes: 3632
n, k = map(int, input().split())
td = [list(map(int, input().split())) for _ in range(n)]

td = sorted(td, key = lambda x: x[1], reverse = True)
eat_types = set()
sushi_dup = []
value = 0
for t, d in td[:k]:
    if not t in eat_types:
        eat_types.add(t)
    else:
        sushi_dup.append(d)
    value += d

ans = value + len(eat_types)**2
for t, d in td[k:]:
    if len(sushi_dup) == 0:
        break
    
    if t in eat_types:
        continue
    else:
        eat_types.add(t)
        r = sushi_dup.pop()
        value += d - r
        ans = max(ans, value + len(eat_types)**2)
print(ans)


Measured memory_bytes: 30776
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

class Main {

    public static void main(String[] args) throws Exception {

        try {

            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

            List<String> firstRow = Arrays.asList(br.readLine().split(""));
            List<String> secondRow = Arrays.asList(br.readLine().split(""));
            swap(secondRow, 0, 2);

            if (firstRow.equals(secondRow)) {
                System.out.println("YES");
            } else {
                System.out.println("NO");
            }

        } catch (IOException | NumberFormatException e) {
            e.printStackTrace();
            System.exit(0);
        } catch (final Exception e) {
            e.printStackTrace();
            System.exit(0);
        }
    }

    static void swap(List<String> list, int index1, int index2) {
        String tmp = list.get(index1);
        list.set(index1, list.get(index2));
        list.set(index2, tmp);
    }
}

Measured memory_bytes: 21332
#include <float.h>
#include <inttypes.h>
#include <limits.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <math.h>
#ifdef __cplusplus
#include <bits/stdc++.h>
#endif

#define P 1000000007

uint32_t nextpint(void){ char c=getchar_unlocked(); while(c<'0'||'9'<c) c=getchar_unlocked(); uint32_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar_unlocked(); } return x; }
uint64_t nextplong(void){ char c=getchar_unlocked(); while(c<'0'||'9'<c) c=getchar_unlocked(); uint64_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar_unlocked(); } return x; }

int a1, a2, a3, a5;
std::map<long, long> cost;

long func(long n){
	if(n==0) return 0;
	if(cost.count(n)>0) return cost[n];
	long min=LONG_MAX;
	{long t=n/2; long now=func(t)+a2+(n-t*2)*a1; if(now<min) min=now;}
	{long t=n/3; long now=func(t)+a3+(n-t*3)*a1; if(now<min) min=now;}
	{long t=n/5; long now=func(t)+a5+(n-t*5)*a1; if(now<min) min=now;}
	if(n>=2){long t=(n+1)/2; long now=func(t)+a2+(t*2-n)*a1; if(now<min) min=now;}
	if(n>=3){long t=(n+2)/3; long now=func(t)+a3+(t*3-n)*a1; if(now<min) min=now;}
	if(n>=5){long t=(n+4)/5; long now=func(t)+a5+(t*5-n)*a1; if(now<min) min=now;}
	if(min/n>a1-1 && min>n*a1) min=n*a1;
	cost[n]=min;
	return min;
}

int main(void){
	int t=nextpint();
	while(t-->0){
		long n=nextplong();
		a2=nextpint();
		a3=nextpint();
		a5=nextpint();
		a1=nextpint();
		cost.clear();
		long ans=func(n);
		printf("%ld\n", ans);
	}
}


Measured memory_bytes: 4456
#define _USE_MATH_DEFINES 
#include<iomanip> 
#include<cmath>  
#include<iostream>
#include<fstream>
#include<vector>
#include<algorithm>
#include<numeric>
#include<bitset>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<queue>
#include<deque>
#include<stack>
using namespace std;
typedef long long ll;
#define repi(i,a,b) for(ll i = (ll)(a) ; i < (ll)(b) ; i++)
#define repd(i,a,b) for(ll i = (ll)(a) ; i > (ll)(b) ; i--)
#define rd(x) cin >> x
#define wr(x)  cout << x
#define wrln(x) cout << x << endl
#define wl() cout << endl
const ll MAX_10p5 = 100010;
const ll MAX_10p9 = 1000000010;
const ll MAX_10p18 = 1000000000000000010;
const ll MOD = 1000000007;
const ll m4x[4] = { 1,0,-1,0 };
const ll m4y[4] = { 0,1,0,-1 };
const ll m8x[8] = { 1,1,0,-1,-1,-1,0,1 };
const ll m8y[8] = { 0,1,1,1,0,-1,-1,-1 };
const ll m9x[9] = { 1,1,0,-1,-1,-1,0,1,0 };
const ll m9y[9] = { 0,1,1,1,0,-1,-1,-1,0 };

struct edge {
	ll from, to, cost;
	bool operator<(const edge& right) const {
		return cost < right.cost;
	}
};
struct point {
	ll x, y;
	bool operator<(const point& right) const {
		return x == right.x ? y < right.y : x < right.x;
	}
};

///////////////////////////////////////////////////////////////////////////////////////

int main() {
	while (1) {
		ll e;
		rd(e);
		if (e == 0) break;
		ll ans = MAX_10p18;
		for (ll z = 0; z*z*z <= e; z++) {
			for (ll y = 0; z*z*z + y*y <= e; y++) {
				ll x = e - z*z*z - y*y;
				ans = min(ans, x + y + z);
			}
		}
		wrln(ans);
	}
	return 0;
}



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

int main() {
	int n;
	cin >> n;
	int ans=0;
	for(int i=0;i<n;i++)
	{
		int a;
		cin >> a;
		while(a>0)
		{
			if(a % 2 == 0)
			{
				ans++;
				a /= 2;
			}
			else
			{
				a = 0;
			}
		}
	}
    cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
import sys
import itertools
# import numpy as np
import time
import math
import heapq
from collections import defaultdict
from collections import Counter
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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

N, M, K = map(int, input().split())
MAX = 2 * 10 ** 5 + 5
MOD = 10 ** 9 + 7

fac = [0 for i in range(MAX)]
finv = [0 for i in range(MAX)]
inv = [0 for i in range(MAX)]

def comInit(mod):
    fac[0], fac[1] = 1, 1
    finv[0], finv[1] = 1, 1
    inv[1] = 1
    for i in range(2, MAX):
        fac[i] = fac[i - 1] * i % mod
        inv[i] = mod - inv[mod % i] * (mod // i) % mod
        finv[i] = finv[i - 1] * inv[i] % mod


def com(n, r, mod):
    if n < r:
        return 0
    if n < 0 or r < 0:
        return 0
    return fac[n] * (finv[r] * finv[n - r] % mod) % mod

def p(n, r, mod):
    return fac[n] * finv[n - r] % mod
comInit(MOD)

xs = 0
for i in range(M):
    xs += i * (M - i)
    xs %= MOD
xs *= N ** 2
ys = 0
for i in range(N):
    ys += i * (N - i)
    ys %= MOD
ys *= M ** 2
ys %= MOD
print(((xs + ys) % MOD) * com(N * M - 2, K - 2, MOD) % MOD)

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

#define rep2(x,fr,to) for(int x=(fr);x<(to);x++)
#define rep(x,to) for(int x=0;x<(to);x++)
#define repr(x,fr,to) for(int x=(fr);x>=(to);x--)
#define all(c) c.begin(),c.end()
#define sz(v) (int)v.size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
typedef vector<ll> VL; const int MD = 1e9 + 7;
void dbg(){ cerr << "\n"; } template <typename T,typename ...T2> void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }



int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n;
	cin >>n;
	VI h(n);
	rep(i, n) cin >>h[i];
	int mx = 0, cr = 0;
	rep2(i, 1, n){
		if(h[i-1] >= h[i]) cr++;
		else cr=0;
		mx = max(mx, cr);
	}
	cout << mx <<"\n";
	return 0;
	
}


Measured memory_bytes: 640
#include<stdio.h>
 
#define MAX 100
#define INF 1000000
#define white 0
#define gray 1
#define black 2
 
int n, u;
int M[MAX][MAX];


void MST(void);



int main(){
  
  int i,j,k;
  int v,c;
 
  scanf("%d",&n);
 
  for(i = 0 ;i < n;i++){
    for(j = 0;j < n;j++){
      M[i][j] = INF;
    }
  }
 
  for(i = 0;i < n;i++){
    scanf("%d %d",&u,&k);
    for(j = 0;j < k;j++){
      scanf("%d %d",&v,&c);
      M[u][v] = c;
    }
  }
 
  MST();
 
  return 0;
}
 
void MST(){
  
  int i;
  int min;
  int d[MAX];
  int color[MAX] = {white};
 
  for(i = 0;i < n;i++){
    d[i] = INF;
  }
 
  d[0] = 0;
  color[0] = gray;
 
  while(1){

    min = INF;
    u = -1;

    for(i = 0;i < n;i++)
      if(min > d[i] && color[i] != black){
	u = i;
	min = d[i];
      }
    if(u == -1)break;
    color[u] = black;
    for(i = 0;i < n;i++)
      if(color[i] != black && M[u][i] != INF){
    if(d[i] > d[u] + M[u][i]){
      d[i] = d[u] + M[u][i];
      color[i] = gray;
    }
      }
  }
  
  for(i = 0;i < n;i++){
    if(d[i] == INF)printf("%d -1\n",i);
    else printf("%d %d\n",i,d[i]);
  }
 
}

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

int main()
{
    int n;
    cin>>n;
    int arr[n];
    for(int i = 0; i < n; i++){
        cin>>arr[i];
    }
    int dp[n];
    for(int i = 0; i < n; i++){
        dp[i] = 0;
    }
    
    dp[0] = 0;
    dp[1] = abs(arr[1] - arr[0]);
    
    for(int i = 2; i < n; i++){
        dp[i] += min(dp[i - 1] + abs(arr[i] - arr[i - 1]),dp[i - 2] + abs(arr[i] -  arr[i - 2]));
    }
    cout<<dp[n - 1];
    return 0;
}


Measured memory_bytes: 4188