akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,start,end) for(int i=start;i<=end;i++)
const int INF = 1001001001;
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
typedef long long ll;
const ll MOD=1000000007;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T>auto MAX(const T& a) { return *max_element(a.begin(),a.end()); }
template<class T>auto MIN(const T& a) { return *min_element(a.begin(),a.end()); }
template<class T, class U>U SUM(const T& a, const U& v) { return accumulate(a.begin(),a.end(), v); }
template<class T, class U>U COUNT(const T& a, const U& v) { return count(a.begin(),a.end(), v); }
template<class T, class U>int LOWER(const T& a, const U& v) { return lower_bound(a.begin(),a.end(), v) - a.begin(); }
template<class T, class U>int UPPER(const T& a, const U& v) { return upper_bound(a.begin(),a.end(), v) - a.begin(); }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; }
//---------------------------------------------------------------------------------------------------
typedef pair<int,int> P;

int main(void){
    // Your code here!
    int N; cin >> N;
    FOR(h,1,3500) {
        FOR(n,1,3500) {
            if(4*h*n-N*n-N*h <= 0) continue;
            long double w = (double)N*h*n/(4*h*n-N*n-N*h);
            if (w > 0 && floor(w) == ceil(w)) {
                cout << h << " " << n << " " << (ll)w << endl;
                return 0;
            }
        }
    }
}


Measured memory_bytes: 3588
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int r[60][60][110], dp[60][60], n, m, a[3]; vector<int>x[60];
void dfs(int st, int pos, int depth) {
	if (depth >= 102)return;
	if (r[st][pos][depth] == 1)return;
	r[st][pos][depth] = 1;
	for (int i : x[pos])dfs(st, i, depth + 1);
}
int solve(int pos, int depth) {
	if (depth >= 59)return 999999999;
	if (pos == n)return 0;
	if (dp[pos][depth] < (1 << 30))return dp[pos][depth];
	int maxn = 0;
	for (int i = 0; i < 3; i++) {
		int minx = 999999999;
		for (int j = 1; j <= n; j++) {
			if (r[pos][j][a[i]] == 1)minx = min(minx, solve(j, depth + 1) + 1);
		}
		maxn = max(maxn, minx);
	}
	dp[pos][depth] = maxn;
	return maxn;
}
int main() {
	cin >> n >> m >> a[0] >> a[1] >> a[2];
	for (int i = 0; i < 3600; i++)dp[i / 60][i % 60] = 2e9;
	for (int i = 0; i < m; i++) {
		int b, c; cin >> b >> c; x[b].push_back(c);
	}
	for (int i = 1; i <= n; i++)dfs(i, i, 0);
	int ret = solve(1, 0);
	if (ret >= 10000000)cout << "IMPOSSIBLE" << endl;
	else cout << ret << endl;
	return 0;
}

Measured memory_bytes: 4408
#include<bits/stdc++.h>
#define ll long long
#define l long
#define mk make_pair
#define pb push_back
#define in insert
#define se second
#define fi first
#define mod 1000000007
#define watch(x) cout << (#x) << " is " << (x) << "\n"
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);
#define pii pair<int,int>
using namespace std;
int main()
{
    fast;
    
    int n,i,j;
    cin>>n;
    string s1,s2,ans;
    cin>>s1>>s2;
    for(i=0;i<n;i++)
    {
    	ans.pb(s1[i]);
    	ans.pb(s2[i]);
    }
    cout<<ans;
}

Measured memory_bytes: 256
while (str = gets)
  a, b, c, d, e, f = str.split(" ").map(&:to_f)
  if a * b * d * e != 0
    puts [sprintf("%.3f", ((c - f * (b / e)) / (a - d * (b / e))).round(3)), sprintf("%.3f", ((c - f * (a / d)) / (b - e * (a / d))).round(3))].join(" ")
  else
    if a == 0
      puts [sprintf("%.3f", ((f - e * (c / b)) / d).round(3)), sprintf("%.3f", (c / b).round(3))].join(" ")
    elsif b == 0
      puts [sprintf("%.3f", (c / a).round(3)), sprintf("%.3f", ((f - d * (c / a)) / e).round(3))].join(" ")
    elsif d == 0
      puts [sprintf("%.3f", ((c - b * (f / e)) / a).round(3)), sprintf("%.3f", (f / e).round(3))].join(" ")
    else
      puts [sprintf("%.3f", (f / d).round(3)), sprintf("%.3f", ((c - a * (f / d)) / b).round(3))].join(" ")
    end
  end
end

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

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

const int INF = 1000000007;

int main(){
	int n; cin>>n;
	int a[110000]={0};
	for(int i=0;i<n;i++) cin>>a[i];
	int i=0,res=0;

	sort(a, a+n);
	while(i < n){
		int cnt = a[i];
		int f=0;
		while(i<n && a[i]==cnt){
			f++;
			i++;
		}
		res += f % 2;
	}

	cout<< res <<endl;

	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
#define eps 1e-8
#define eq(x,y) (fabs((x)-(y)) < eps)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int>pii;
const ll mod = 1e9+7;
long double PI = acosl(-1);
const ll infl = 1e15;
const int inf = 1e9;
const int nmax = 5e5+5;
const int MAXLG = log2(nmax)+1;
//mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
//typedef tree< int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ost;

const int MAXLOG = 64;
struct basis
{
    int64_t base[MAXLOG];
    void clear()
    {
		for(int i = MAXLOG - 1; i >= 0; i--)
			base[i] = 0;
    }
    void add(int64_t val)
    {
    	for(int i = MAXLOG - 1; i >= 0; i--)
			if((val >> i) & 1)
			{
				if(!base[i]) { base[i] = val; return; }
				else val ^= base[i];
			}
	}
    inline int size()
    {
    	int sz = 0;
    	for(int i = 0; i < MAXLOG; i++)
			sz += (bool)(base[i]);
		return sz;
    }
    int64_t max_xor()
    {
		int64_t res = 0;
		for(int i = MAXLOG - 1; i >= 0; i--)
			if(!((res >> i) & 1) && base[i])
				res ^= base[i];

		return res;
	}
    bool can_create(int64_t val)
    {
		for(int i = MAXLOG - 1; i >= 0; i--)
			if(((val >> i) & 1) && base[i])
				val ^= base[i];

		return (val == 0);
    }
    void fak(){
        for(int i=0; i<MAXLOG; i++){
            cout<<base[i]<<" ";
        }
        cout<<endl;
    }
};

bool sabset(basis a, basis b){
    for(int i=0; i<MAXLOG; i++){
        if(a.base[i]==0 and b.base[i]!=0) return false;
        if(a.base[i] and b.base[i]){
            ll jor = a.base[i] ^ b.base[i];
            while(jor){
                int k=-1;
                ll jor1 = jor;
                while(jor1) jor1/=2, k++;
                if(!a.base[k]) return false;
                jor = jor ^ a.base[k];
            }
        }
    }
    return true;
}

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

    int tc;
    cin>>tc;
    while(tc--){
        basis b0, b1;
        b0.clear(), b1.clear();
        int n;
        cin>>n;
        vector<ll>A(n);
        for(auto &x : A) cin>>x;
        string s;
        cin>>s;
        bool mara = false;
        for(int i=n-1; i>=0; i--){
            if(s[i]=='0'){
                b0.add(A[i]);
            }
            else{
                b1.add(A[i]);
            }
            if(!sabset(b0, b1)){
                mara = true;
                break;
            }
        }
//        b0.fak();
//        cout<<endl;
//        b1.fak();
//        cout<<endl;
        if(mara) cout<<"1\n";
        else cout<<"0\n";
    }

}
/*
*/


Measured memory_bytes: 3624
#include <iostream>

using namespace std;

int main ()
{
        int n, k, x, y;
        cin >> n >> k >> x >> y;
        int sum = 0;

        if ( n - k > 0 )
                sum = (n - k) * y + k * x;
        else
                sum = n * x;

        cout << sum << endl;
}


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

int main(){
    using namespace std;
    string s,t;
    bool check = false;
    cin >> s;
    cin >> t;
    for(int i=0;i<s.length();i++){
        if(s == t){
            cout << "Yes" << endl;
            check = true;
            break;
        }else{
            t = t.back() + t;
            t.pop_back();
        }
    }
    if(!check){
        cout << "No" <<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

ll N = 1e5+10, n, m;
vvll g(N), rev(N);
vll deg(N);

vll topo_sort(vvll &g, vll &deg, ll n){
    queue<ll> que;
    REP(i, n){
        if(!deg[i]) que.push(i);
    }
    vll ans;
    while(!que.empty()){
        ll s = que.front();
        que.pop();
        ans.push_back(s);
        for(auto j : g[s]){
            deg[j]--;
            if(deg[j] == 0) que.push(j);
        }
    }
    return ans;
}

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

    cin >> n >> m;
    ll a, b;
    REP(i, n + m - 1){
        cin >> a >> b;
        a--, b--;
        g[a].push_back(b);
        rev[b].push_back(a);
        deg[b]++;
    }
    vll topo = topo_sort(g, deg, n);
    vll res(n, -1), pri(n);
    REP(i, n) pri[topo[i]] = i;
    res[topo[0]] = 0;
    REP(i, n){
        ll v = topo[i];
        ll ma = -1, idx = -1;
        for (auto u : rev[v]){
            if (pri[u] > ma){
                ma = pri[u];
                idx = u;
            }
        }
        res[v] = idx + 1;
    }
    REP(i, n) cout << res[i] << endl;
    return 0;
}

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

vector<ll> num753;

int calcDigit(ll num){
    if(num < 10) return 1;
    else return calcDigit(num/10) + 1;
}
void appendNum(ll num){
    if(calcDigit(num) < 10){
        num753.push_back(num);
        appendNum(num*10+3);
        appendNum(num*10+5);
        appendNum(num*10+7);
    }
}
int main(){
    int N;  cin >> N;
    appendNum(0);
    sort(num753.begin(), num753.end());
    int n = num753.size();
    int ans = 0;
    for(int i=0; i<n; i++){
        if(num753[i] > N) break;
        string S = to_string(num753[i]);
        if(find(S.begin(), S.end(), '3') != S.end() && find(S.begin(), S.end(), '5') != S.end() && find(S.begin(), S.end(), '7') != S.end()){
            ans++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

int len(int n)
{
	string s;
	stringstream ss;
	ss<<n;
	ss>>s;
	return s.length();
}

string num(int n)
{
	string s;
	stringstream ss;
	ss<<n;
	ss>>s;
	return s;
}

int main()
{	
	int n,m,a,b;
	string z[6]={"","0","00","000","0000","00000"};
	cin>>n>>m;
	vector<pair<int,int>>v[n+1];
	vector<string>ans(m+1);
	for(int i=0;i<m;i++)
	{
		cin>>a>>b;
		v[a].push_back(make_pair(b,i+1));
	}
	for(int i=1;i<=n;i++)
	{
		if(v[i].size()==0)continue;
		sort(v[i].begin(),v[i].end());
		for(int j=0;j<v[i].size();j++)
		{	
			string number="";
			int p=len(i);
			int x=len(j+1);
			number+=z[6-p]+num(i)+z[6-x]+num(j+1);
			ans[v[i][j].second]=number;
		}
	}
	for(int i=1;i<=m;i++)cout<<ans[i]<<endl;
	return 0;
}

Measured memory_bytes: 12416
while True:
    n,x=map(int,input().split())
    if n==0 and x==0:
        break
    else:
        s=0
        for i in range(1,n-1):
            for j in range(i+1,n):
                for k in range(j+1,n+1):
                    if i+j+k==x:
                        s=s+1
        print(s)


Measured memory_bytes: 5596
# C

N, M, X = list(map(int, input().split()))
CAs = [list(map(int, input().split())) for i in range(N)]

import numpy as np
Cs = np.array([ca[0] for ca in CAs])
As = [np.array(ca[1:]) for ca in CAs]

import itertools
states = list(itertools.product([True, False], repeat=N))

def compute(state):
    arr = np.array([0] * M)
    for i in range(N):
        arr += As[i] * state[i]
    price = (Cs * state).sum() if ((arr >= X).sum() == M) else -1
    return price


res = np.array(list(map(compute, states)))
res = res[res > 0]
print(min(res) if len(res) > 0 else -1)

Measured memory_bytes: 27860
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include<algorithm>
#include<sstream>
#include<iomanip>
#include<deque>
#include<list>


using namespace std;

typedef long long ll;

typedef pair<int, int> pii;

const ll MOD_CONST = 1000000007;
const ll BIG_NUM = 1000000000000000000;
const int BIG_INT = 1000000000;




int main() {
	int n, x;
	cin >> n >> x;
	priority_queue<int,vector<int>,greater<int>> pq;
	for (int i = 0; i < n; i++) {
		int a;
		cin >> a;
		pq.push(a);
	}

	int cnt = 0;

	while (x > 0 && !pq.empty()) {
		int a = pq.top();
		pq.pop();
		if (x >=a) {
			cnt++;
			x -= a;
		}
		else {
			x = 0;
		}
	}
	
	if (x > 0) {
		cnt--;
	}

	cout << cnt << endl;

}



Measured memory_bytes: 256
import sys

input = sys.stdin.readline


def main():
    n, m = map(int, input().split())
    arr = list(map(int, input().split()))
    limit = sum(arr) / (4 * m)
    cnt = 0
    for num in arr:
        if num >= limit:
            cnt += 1
        if cnt >= m:
            break

    if cnt >= m:
        print('Yes')
    else:
        print('No')


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <set>
#include <cmath>
using namespace std;

void solve(){
  vector<string> v(3);
  for(int i = 0; i < 3; i++){
    cin >> v[i];
  }
  int id = 0;
  while(1){
    int p = id;
    if(v[id].size() == 0){
      cout << (char)('A' + id) << endl;
      return;
    }
    id = (int)(v[id][0] - 'a');
    v[p].erase(0, 1);
  }
  return;
}

int main(){
  solve();
  return 0;
}


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

int main(){
    int x, ret;
    vector<int> primes;
    primes.push_back(2);
    cin >> x;
    if(x <= 2) ret = x;
    else{
        int kouho = 3;
        while(1){
            bool flag = true;
            for(auto p : primes){
                if(kouho % p == 0){
                    flag = false;
                    break;
                }
            }
            if(flag){
                if(kouho >= x){
                    ret = kouho;
                    break;
                }
                primes.push_back(kouho);
            }
            kouho += 2;
        }
    }
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 384
import java.util.*;

public class Main {
    static Scanner scanner = new Scanner(System.in);

    public static void main(String[]$) {
        int n = scanner.nextInt();
        long[] a = new long[n];
        long[] b = new long[n];
        long ans = 0;
        for (int i = 0; i < n; i++) {
            a[i] = scanner.nextInt();
            b[i] = scanner.nextInt();
        }
        for (int i = n - 1; i >= 0; i--)
            ans += (b[i] - (a[i] + ans) % b[i]) % b[i];
        System.out.println(ans);
    }
}

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

int main()
{
	string A;
	int H, W;

	cin >> H >> W;

	for (int w = 0; w < W+2; w++)
		A += "#";

	for (int h = 0; h < H; h++) {
		string a;
		cin >> a;

		A += "#" + a + "#";
	}

	for (int w = 0; w < W+2; w++)
		A += "#";

	for (int h = 0; h < H+2; h++) {
		for (int w = 0; w < W+2; w++) {
			cout << A[w+((W+2)*h)];
		}
		cout << endl;
	}

	return 0;
}

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

using namespace std;

#define ll long long

int main(){
    vector<ll> aa(4);
    for(int i=0;i<4;i++){
        cin>>aa[i];
    }
    ll ans=-1000000000000000000;
    for(int i=0;i<2;i++){
        for(int j=2;j<4;j++){
            if(aa[i]*aa[j]> ans){
                ans = aa[i]*aa[j];
            }
        }
    }

    cout << ans;
}

Measured memory_bytes: 3620
import sys
input = sys.stdin.readline

"""
X定数だった。両極端な場合が合流する。
[0,L]上定数A、[R,X]上定数B、その間は線形
"""

X = int(input())
K = int(input())
R = [int(x) for x in input().split()]
Q = int(input())
TA = [tuple(int(x) for x in input().split()) for _ in range(Q)]

task = sorted([(r,-1) for r in R] + [(t,a) for t,a in TA])

L = 0
R = X
A = 0
B = X
dx = -1 # 初めは減る方
current = 0
answer = []
for t,a in task:
    # とりあえず上限を突破して落とす
    A += dx * (t-current)
    B += dx * (t-current)
    current = t
    if a != -1:
        # 体積の計算
        if a <= L:
            x = A
        elif a >= R:
            x = B
        else:
            x = A+(B-A)//(R-L)*(a-L)
        if x < 0:
            x = 0
        if x > X:
            x = X
        answer.append(x)
    else:
        dx = -dx
        if A < B:
            if A < 0:
                L += (-A)
                A = 0
            if B > X:
                R -= (B-X)
                B = X
            if A > X:
                A = X
                B = X
                L = 0
                R = 0
            if B < 0:
                A = 0
                B = 0
                L = 0
                R = 0
        elif A >= B:
            if A > X:
                L += (A-X)
                A = X
            if B < 0:
                R -= (-B)
                B = 0
            if A < 0:
                A = 0
                B = 0
                L = 0
                R = 0
            if B > X:
                A = X
                B = X
                L = 0
                R = 0
        if R < L:
            R = L

print(*answer,sep='\n')



Measured memory_bytes: 41084
import fractions
N,X = map(int,input().split())
a1 = input().split()
b = []
for i in range(N):
  b.append(abs(int(a1[i])-X))
z = b[0]
if N == 1:
  print(z)
else:
  for i in range(1,N):
    z = fractions.gcd(z,b[i])
  print(z)

Measured memory_bytes: 16240
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0;i < (int)(n);i++)
using ll = long long;
const ll MOD=1000000007;
const long long INF = 1LL << 60;
const double pi=acos(-1.0);

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

//dfs
vector<ll> vec;

void dfs(ll n,ll S){
  vec.push_back(S);
  if(n>=9) return;
  int edge=S%10;
  
  ll mid=S*10+edge; dfs(n+1,mid);
  if(edge<9) {ll high=S*10+edge+1; dfs(n+1,high);}
  if(edge>0) {ll low=S*10+edge-1; dfs(n+1,low);}
}

int main()
{
  ll K; cin>>K;
  
  //dfs
  vec=vector<ll>(0);
  rep(i,9) dfs(0,i+1);
  
  sort(vec.begin(),vec.end());
  cout<<vec[K-1]<<endl;
  return 0;
}

Measured memory_bytes: 5400
import java.util.Scanner;

public class Main {
  private static int calcX(int A, int P){
    return A * P;
  }

  private static int calcY(int B, int C, int D, int P){
    return (P < C)? B : B + D * (P - C);
  }

  public static void main(String[] args)
  {
    Scanner sc = new Scanner(System.in);

    while(sc.hasNext()){
      int A = Integer.parseInt(sc.next());
      int B = Integer.parseInt(sc.next());
      int C = Integer.parseInt(sc.next());
      int D = Integer.parseInt(sc.next());
      int P = Integer.parseInt(sc.next());

      System.out.println(Math.min(calcX(A, P), calcY(B, C, D, P)));
    }
  };
}

Measured memory_bytes: 26112
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class Main {

	public static void main(String args[]) {
		//コマンドライン引数取得部分
		Scanner scanner = new Scanner(System.in);
		//グループ人数
		Long people = scanner.nextLong();
		//乗客数
		//ArrayList<Long> passengerNumList = new ArrayList<>();
		//for (int i = 0; i < 5; i++) {
		//	passengerNumList.add(scanner.nextLong());
		//}

		//賢いやり方
		long A = scanner.nextLong();
		long B = scanner.nextLong();
		long C = scanner.nextLong();
		long D = scanner.nextLong();
		long E = scanner.nextLong();
		scanner.close();

		//JDK1.8で導入されたStreamを使用する。
		long min = Arrays.asList(A, B, C, D, E).stream().min(Comparator.naturalOrder()).get();
		System.out.println(4L + (long)Math.ceil((double) people/min));

		//Long ZERO = new Long(0);

		//最小移動時間
		//int time = 0;

		//各都市に残っている人数
		//Long[] cityNumList = { people, ZERO, ZERO, ZERO, ZERO, ZERO };

		//while (cityNumList[5].compareTo(people) != 0) {
			//for (int i = 4; 0 <= i; i--) {
				//if (cityNumList[i] > 0) {
					//if (cityNumList[i] > passengerNumList.get(i)) {
						//cityNumList[i + 1] += passengerNumList.get(i);
						//cityNumList[i] -= passengerNumList.get(i);
					//} else {
						//cityNumList[i + 1] += (cityNumList[i]);
						//cityNumList[i] = ZERO;
					//}
				//}
			//}
			//time++;
			//System.out.println(cityNumList[5]);
		//}
		//System.out.println(time);
	}

}


Measured memory_bytes: 28756
using System;

namespace A
{
	internal class Program
	{
		public static void Main(string[] args)
		{
			var n = int.Parse(Console.ReadLine());
			var ainputs = Console.ReadLine().Split();
			var an = new int[n];
			var sum = 0;
			for (var i = 0; i < n; i++) { sum += an[i] = int.Parse(ainputs[i]); }

			var index = 0;
			var diff = 100000;
			for (var i = 0; i < n; i++)
			{
				if (diff > Math.Abs(an[i] * n - sum))
				{
					index = i;
					diff = Math.Abs(an[i] * n - sum);
				}
			}

			Console.WriteLine(index);
		}
	}
}

Measured memory_bytes: 13140
/*
Owner: dxxrk
Problem: Shik and Stone
Date: 21/11/2019
*/
#include <bits/stdc++.h>

using namespace std;

const int N = 2e5 + 3;
const int M = 1e6 + 7;
const long long MOD = 1e9 + 7;
const long long INF = 1e18 + 9;
const int SM = 1e3 + 8;
const int logN = 20, BL = 400;
const double EPS = 3e-16;

int h, w;
char g[SM][SM]; 

bool isPossible(int x, int y){
	return x < h && y < w;
}

int main(){
//	freopen("ex.in", "r", stdin);
//	freopen("ex.out", "w", stdout);
	ios_base::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	cin >> h >> w;
	
	int all = 0;
	for(int i = 0; i < h; i++){
		for(int j = 0; j < w; j++){
			cin >> g[i][j];
			all += (g[i][j] == '#');
		}
	}
	
	int counter = 0;	
	queue<pair<int, int>> q;
	q.push({0, 0});
	while(!q.empty()){
		counter++;
		pair<int, int> v = q.front();
		int x = v.first, y = v.second;
		q.pop();
		
		if(x == h - 1 && y == w - 1) break;
		if(isPossible(x + 1, y)){
			q.push({x + 1, y});
		}
		else {
			q.push({x, y + 1});
		}
	}
	
	if(all == counter){
		cout << "Possible";
	}
	else {
		cout << "Impossible";
	}
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <stack>
#include <queue>
#include <cmath>
#include <string>
#include <iterator>
#include <map>
#include <set>
#include <iomanip>
#include <vector>
#include <fstream>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Graph = vector<vector<int>>;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
#define rep(i, N) for(int i = 0; i < N; i++)
#define rep2(i, l, r) for (ll i = (ll)l; i < (ll)(r); i++)
#define INF 1000000000000000000
#define MAX 200001
#define MOD 1000000007
#define F "test.txt"

template <typename T > inline string toString(const T &a) {ostringstream oss; oss << a; return oss.str();};

int main(){
    ll N, L;
    cin >> N >> L;
    int flag = -1;
    vector<ll> a(N);
    rep(i,N) cin >> a[i];
    rep(i,N-1){
        if(a[i] + a[i+1] >= L) flag = i;
    }
    if(flag != -1){
        cout << "Possible" << endl;
        for(int i = 1; i <= N-1; i++){
            if(i == flag + 1) break;
            cout << i << endl;
        }
        for(int i = N-1; i >= 1; i--){
            if(i == flag + 1) break;
            cout << i << endl;
        }
        cout << flag+1 << endl;
    }
    else cout << "Impossible" << endl;
}

Measured memory_bytes: 4052
#include<bits/stdc++.h>
using namespace std;
string s;
int i,j;
int main(){
	getline(cin,s);
	while(i<s.size()){
		if(s[i]=='C'){
			j=i+1;
			while(j<=s.size()){
				if(s[j]=='F'){
					cout<<"Yes";
					return 0;
				}
				j++;
			}
		}
		i++;
	}
	printf("No");
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int dfs( int );
long long int memo[31]={};
int main(){
  int n ,ans;
  while( true ){
    cin >> n;
    if( n == 0 ) break;
    ans = dfs( n );
    
    ans /= 3650;
    cout << ans+1 << endl;
  }
}

int dfs( int n ){
  if( memo[n] ) return memo[n];
  if( n <= 1 ) return 1;
  if( n == 2 ) return 2;
  return memo[n] = dfs( n-1 ) + dfs( n-2 ) + dfs( n-3 );
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i= (a); i < (b); ++i)
typedef long long ll;
typedef pair<int,int> P;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
char lol[4] = {'A', 'C' , 'G', 'T'};
int main() { string S;
  cin >> S;
  vector<bool> a(S.size(),false);
  REP(i, S.size()) {
    REP(j,4){
      if(S.at(i)==lol[j])a.at(i)=true;
    }
  }
  int ans = 0,now=0;
  REP(i,S.size()){
    if(a.at(i)==true){
      now++;
    }else{
      now = 0;
    }
    ans = max(now, ans);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;

VI a;
bool is_satisfied(int key) {
    return abs(a[key] * 2 - a.back()) - abs(a[key - 1] * 2 - a.back()) >= 0;
}

// TTTTFFFFのときのTの最大indexを求めたいならsearch_max=true
// FFFFTTTTのときのTの最小indexを求めたいならsearch_max=false
int binary_search(int min, int max, bool search_max) {
    min--;
    max++;
    while(max - min > 1) {
        int mid = (max + min) / 2;
        if(is_satisfied(mid) xor not search_max) min = mid;
        else max = mid;
    }
    return search_max ? min : max;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    a.resize(n);
    REP(i, n) cin >> a[i];
    sort(ALL(a));
    cout << a.back() << " " << a[binary_search(1, n - 1, false) - 1] << endl;
      
    return 0;
}


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

int main()
{
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    if (a <= c) {
        if (b < c) {
            cout << 0 << endl;
        } else if (d < b) {
            cout << d-c << endl;
        } else {
            cout << b-c << endl;
        }
    } else {
        if (d < a) {
            cout << 0 << endl;
        } else if (b < d) {
            cout << b-a << endl;
        } else {
            cout << d-a << endl;
        }
    }
}


Measured memory_bytes: 256
#!/usr/bin/python
# -*- coding: utf-8 -*-

def main():
    # 入力
    N = int(raw_input())

    for i in range(N):
        data = {}
        b = Baseball()
        while(b.out < 3):
            event = raw_input()
            b.decisionScore(event)

        print(b.score)

class Baseball():
    def __init__(self):
        self.out = 0
        self.score = 0
        self.que = [0,0,0]  #Third, Second, First

    def decisionScore(self, event):
        if event == "OUT":
            self.out += 1
        elif event == "HIT":
            self.score += self.addRunner()
        elif event == "HOMERUN":
            self.score += self.clearRunnner() + 1
        else:
            print("Wrong data")

    def addRunner(self):
        self.que.append(1)
        point = self.que[0]
        self.que = self.que[1:]
        return point

    def clearRunnner(self):
        point = sum(self.que)
        self.que = [0,0,0]
        return point

if __name__=='__main__':
    main()

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

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

  int n, m;
  cin >> n >> m;

  if(n == m) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  return 0;
}

Measured memory_bytes: 3620
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
typedef long long LL;

const int MaxN = 1e5;
int n;
int a[MaxN + 5];
int b[MaxN + 5];
int c[MaxN + 5];
LL d[MaxN + 5];

int main()
{
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) scanf("%d", &a[i]); sort(a + 1, a + n + 1);
	for (int i = 1; i <= n; i++) scanf("%d", &b[i]); sort(b + 1, b + n + 1);
	for (int i = 1; i <= n; i++) scanf("%d", &c[i]); sort(c + 1, c + n + 1);
	int p = 1;
	for (int i = 1; i <= n; i++) {
		while (p <= n && c[p] <= b[i]) p++;
		d[i] = n - p + 1;
	}
	for (int i = n; i >= 1; i--) d[i] = d[i + 1] + d[i];
	p = 1;
	LL ans = 0;
	for (int i = 1; i <= n; i++) {
		while (p <= n && b[p] <= a[i]) p++;
		ans += d[p];
	}
	printf("%lld\n", ans);
	return 0;
}

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

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<string> vs;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vll = vector<vl>;
using vpll = vector<pll>;
struct Edge {
	ll to;
 	ll cost;
 };
using Graph = vector<vector<Edge>>;

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(a) (a).begin(), (a).end()
/***** define constant start *******/
const ll MOD = 1000000007;
const double PI = 3.1415926535897932;
const ll INF = LLONG_MAX;
string abc = "abcdefghijklmnopqrstuvwxyz";
string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const ll MAX = 10000000;
/****** define constant end ********/
/****** define variable start ******/
ll n, m, x;
vl c;
/******* define variable end *******/
int solve() {
	cin >> n >> m >> x;
	c.resize(n);
	vector<vector<ll>> a(n, vector<ll>(m));
	REP(i, n){
		cin >> c[i];
		REP(j, m){
			cin >> a[i][j];
		}
	}
	ll kane = INF;
	bool flag = false;
	for(ll i = 0; i < 1 << n; ++i){
		ll tmp = i;
		vector<vector<ll>> joutai(1 << n, vector<ll>(n));
		for(ll j = 0; j < n; ++j){
			joutai[i][j] = tmp % 2;
			tmp /= 2;
		}
		vl rikai(m);
		ll kanetmp = 0;
		REP(j, n){
			if(joutai[i][j] == 1){
				kanetmp += c[j];
				REP(k, m){
					rikai[k] += a[j][k];
				}
			}
			ll count = 0;
			REP(k, m){
				if(rikai[k] >= x){
					count++;
				}
			}
			if(count == m){
				flag = true;
				if(kanetmp < kane){
					kane = kanetmp;
				}
			}
		}
	}
	if(flag){
		cout << kane << endl;
	}else{
		cout << -1 << endl;
	}
	return 0;
}

int main() {
	//clock_t start = clock();
	cout << std::fixed << std::setprecision(10);
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int end_solve = solve();
	/*
	clock_t end = clock();
	const double time = static_cast<double>(end - start) / CLOCKS_PER_SEC *
	1000.0; printf("time %lf[ms]\n", time);
	*/

	return end_solve;
}


Measured memory_bytes: 3876
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define FIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
#define vi vector<ll>
#define pb push_back
#define F first
#define S second
#define all(v) (v).begin(),(v).end()
#define pii pair<ll,ll>
#define vii vector<pii>
#define MOD 1000000007LL
#define calc_fact(n) tgamma(n+1)


signed main()
{
    FIO;
    ll n,m,k,a,ans=LONG_LONG_MIN,sum=0,j=0;
    cin>>n>>m>>k;
    vi v1,v2;
    for(ll i=0;i<n;i++)
    {
        cin>>a;
        v1.pb(a);
    }
    for(ll i=0;i<m;i++)
    {
        cin>>a;
        v2.pb(a);
    }
    while(j<n and sum+v1[j]<=k)
    sum+=v1[j++];
    ll p=0;
    while(p<m and sum+v2[p]<=k)
    sum+=v2[p++];
    ans=max(ans,j+p);
    j--;
    while(j>=0)
    {
        sum-=v1[j--];
        while(p<m and sum+v2[p]<=k)sum+=v2[p++];
        ans=max(ans,p+j+1);
    }
    cout<<ans;
}


Measured memory_bytes: 7868
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <numeric>

using namespace std;
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)


typedef long long ll;

long long GCD(long long a, long long b){if(b==0)return a;return GCD(b,a%b);}

int main() {
    long long K; cin >> K;
    long long res = 0;
    int i = 1;
    while(true) {
        if ((K - i) / i <= i) break;
        if ((K - i) % i != 0) {
            ++i;
            continue;
        }
        long long q = (K - i) / i;
        res += q;
        ++i;
    }
    cout << res << endl;
}

Measured memory_bytes: 256
n,k=map(int,input().split())
s=list(input())
check=1
cnt=0
l=[]
for i in range(n):
    if check==1 and s[i]=='0':
        check=-1
        l.append(cnt)
        cnt=0
    elif check==-1 and s[i]=='1':
        check=1
        l.append(cnt)
        cnt=0
    cnt+=1
    if i==n-1:
        l.append(cnt)
if s[0]=='1':
    ans=sum(l[0:k*2+1])
    ansl=[ans]
    i=2*k+1
    while i<len(l):
        ans+=l[i]-l[i-2*k-1]-l[i-2*k]
        if i+1<len(l):
            ans+=l[i+1]
        i+=2
        ansl.append(ans)
if s[0]=='0':
    ans=sum(l[0:2*k+1])
    ansl=[ans]
    i=2*k+1
    while i<len(l):
        ans+=l[i]+-l[i-2*k-1]-l[i-2*k]
        if i+1<len(l):
            ans+=l[i+1]
        i+=2
        ansl.append(ans)
print(max(ansl))

Measured memory_bytes: 6184
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}
 
#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};
 
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
 
    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}
 
#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };
 
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
 
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
 
    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };
 
    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };
 
    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
fn main() {
   input! {
       n: usize,
       d: usize,
       mat: [[i32; d]; n],
   } 

    let mut tmp = 0;
    let mut count = 0;
   for i in 0..n {
       for j in i+1..n {
          // println!("i {} j {}", i, j);
           tmp = 0;
           for (k, l) in mat[i].iter().zip(mat[j].iter()) {
               tmp = tmp + (k-l).pow(2);
           }
           let t2 = tmp as f64;
           //println!("{}", t2);
           if (t2.sqrt().round().powf(2.0) - t2).abs() < 1e-10 {
               count = count + 1;
           }
       }
   }

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

Measured memory_bytes: 4352
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main() {
    ll n,w; cin>>n>>w;
    vector<vector<ll>> dp(n+1,vector<ll>(100001,INF));
    dp[0][0]=0;
    rep(i,n){
        ll s_w,s_v; cin>>s_w>>s_v;
        rep(j,100001){
            if(j<=100000-s_v){
                if(dp[i+1][j+s_v]>dp[i][j]+s_w)
                dp[i+1][j+s_v]=dp[i][j]+s_w;
            }
            if(dp[i+1][j]>dp[i][j])
            dp[i+1][j]=dp[i][j];
        }
    }
    for(int i=100000;i>=0;i--){
        if(dp[n][i]<=w){
            cout<<i<<endl;
            break;
        }
    }
}

Measured memory_bytes: 80256
import heapq
import math

N, M = map(int, input().split())
A = list(map(int, input().split()))

negA = list(map(lambda x: -x, A))

heapq.heapify(negA)

for _ in range(M):
    nedan = -heapq.heappop(negA)
    nedan = nedan // 2
    heapq.heappush(negA, -nedan)

print(-sum(negA))


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

int main(){
  int H,W,i,j;
  cin>>H>>W;
  vector<string> s(H);
  for(i=0;i<H;i++){
    cin>>s[i];
  }
  vector<bool> c(H,false),r(W,false);
  for(i=0;i<H;i++){
    for(j=0;j<W;j++){
      if(s[i][j]=='#') 
      c[i]=r[j]=true;
    }
  }
  for(i=0;i<H;i++){
    if(c[i]==true){
      for(j=0;j<W;j++){
        if(r[j]==true){
          cout<<s[i][j];
        }
      }
      cout<<endl;
    }
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main() {
	string s;
	cin >> s;
	if (s[0] == s[2]) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
	
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<math.h>
using namespace std;
#define mod (1000000000+7)
#define N (10007)
#define INF 1e16
typedef long long ll;
typedef pair<ll,ll> P;

ll tmp1[55];

int main(void){
	int n,r;
	while(true){
		cin>>n>>r;
		if(n==0 && r==0)break;
		vector<int>a(n);
		for(int i=0;i<n;i++)a[i]=n-i;
		for(int i=0;i<r;i++){
			int p,c;
			cin>>p>>c;
			for(int i=p-1;i<p+c-1;i++){
				tmp1[i-p+1]=a[i];
			}
			for(int i=p-2;i>=0;i--){
				a[i+c]=a[i];
			}
			for(int i=0;i<c;i++){
				a[i]=tmp1[i];
			}
		}
		cout<<a[0]<<endl;
	}
    return 0;
}


Measured memory_bytes: 3000
/**
*    author:  boutarou
*    created: 15.08.2020 21:02:30
**/

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

int main() {
    int n;
    cin >> n;
    vector<int>a(n);
    rep(i,n) cin >> a[i];
    sort(a.begin(), a.end());
    int cnt = 0;
    rep(i,n) {
        rep(j, n) {
            rep(k, n) {
                if (i < j && j < k && a[i] != a[j] && a[j] != a[k]) {
                    if (a[i] + a[j] > a[k]) cnt++;
                }
            }
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <complex>
using namespace std;
typedef complex<double> xy_t;
double cross_product(xy_t a, xy_t b) { return (conj(a)*b).imag(); }
const double eps = 1e-11;
double x[4],y[4];
int main() {
    while(true){
        for(int i=0; i<4; ++i){
            cin >> x[i] >> y[i];}
            if(!cin) break;
            xy_t a(x[0],y[0]),b(x[1],y[1]),c(x[2],y[2]),p(x[3],y[3]);
            double pab = cross_product(a-p, b-p);
            double pbc = cross_product(b-p, c-p);
            double pca = cross_product(c-p, a-p);
            bool ok = abs(pab+pbc+pca) == abs(pab)+abs(pbc)+abs(pca);
            cout << (ok ? "YES" : "NO") << endl;
            }
    return 0;
}

Measured memory_bytes: 1220
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n,p;
    while(cin>>n>>p,p){
        int t=0,wan;
        wan=p;
        vector<int> v(n,0);
        while(1){
            if(wan==1&&v[t]==p-1){
                break;
            }
            else if(wan==0){
                wan=v[t];
                v[t]=0;
            }
            else{
                wan--;
                v[t]++;
            }
            t++;
            if(t==n){
                t=0;
            }
        }   
        cout<< t<<endl;
    }
}

Measured memory_bytes: 3012
#include <algorithm>
#include <bitset>
#include <cctype>
#include <complex>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())
#define range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 29;

int main(void){
    int q; cin >> q;
    while(q--){
        int n; cin >> n;
        
        int res = 0;
        map<int, bool> used;
        while(n / 10 != 0){
            if(used[n]){
                res = -1;
                break;
            }
            else{
                used[n] = true;
                res++;
            }
            
            int next = 0;
            rep(i, 6){
                int a = n / (int)pow(10., (double)i);
                int b = n % (int)pow(10., (double)i);

                if(a == 0 || b == 0) continue;

                next = max(next, a * b);
            }
            n = next;
        }

        cout << res << endl;
    }

	return 0;
}

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

using namespace std;

#define INF (1 << 30)
#define EPS 1e-10
#define MOD 1000000007

#define rep(i, n) FOR(i, 0, n)
#define FOR(i, x, n) for (int i = (x); i < (n); ++i)
#define all(v) (v).begin(), (v).end()

using ll = long long;

template<class T> void chmax(T& a, T b){ a>b?:a=b; }
template<class T> void chmin(T& a, T b){ a<b?:a=b; }

int main() {
    int n, m, a, sum = 0;
    cin >> n >> m;
    rep(i, m) {
        cin >> a;
        sum += a;
    }
    if (sum <= n)
        cout << n - sum << endl;
    else
        cout << -1 << endl;

    return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <climits>
#include <string>
#include <vector>
#include <utility>

using namespace std;

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

#define REP(i, n) for (ll i = 0; i < n; i++)
#define REPR(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, m, n) for (ll i = m; i < n; i++)

int main() {
    int n, dp[50];
    cin >> n;
    dp[0] = 1;
    dp[1] = 1;
    FOR(i, 2, n + 1) dp[i] = dp[i - 1] + dp[i - 2];
    cout << dp[n] << endl;
    return 0;
}


Measured memory_bytes: 3080
#include<bits/stdc++.h>
#define ll long long int
#define l(i,a,b) for(ll i=a;i<b;i++)
using namespace std;
int main(){
	int a,b;
	cin>>a>>b;
	if(a<=b){
		l(i,0,b) cout<<a;
		cout<<"\n";
	}
	else{
		l(i,0,a) cout<<b;
		cout<<"\n";
	}
	
	
}

Measured memory_bytes: 3644
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int read()
{
    char ch=getchar();
    int x=0,f=1;
    while(ch<'0' || ch>'9')
    {
        if(ch=='-')
            f=-1;
        ch=getchar();
    }
    while(ch>='0' && ch<='9')
    {
        x=x*10+ch-'0';
        ch=getchar();
    }
    return x*f;
}
int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    swap(a,b);
    swap(a,c);
    printf("%d %d %d\n",a,b,c);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define dl double long
#define rep(i, m, n) for(ll i = (ll)(m); i < (ll)(n); ++i)
#define rrep(i, m, n) for(ll i = (ll)(m); i > (ll)(n); --i)
const ll MOD = 1000000007;
const double pi = 3.14159265358979323846;

int main(void){
    int n, m, h[100000];
    cin >> n >> m;
    bool good[100000];
    rep(i, 0, n) {
        cin >> h[i];
        good[i] = true;
    }
    rep(i, 0, m){
        int a, b;
        cin >> a >> b;
        a -= 1;
        b -= 1;
        if(h[a] >= h[b]) good[b] = false;
        if(h[b] >= h[a]) good[a] = false;
    }
    int count = 0;
    rep(i, 0, n){
        if(good[i] == true)count++;
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 4088
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static String Y = "Yes";
	public static String N = "No";
	public static long MOD = (long) (Math.pow(10, 9) + 7);
	public static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {

		int n = ni();
		int a[] = new int[n];
		int b[] = new int[n];

		for (int i = 0; i < n; i++) {
			int u = ni();
			a[i] = u;
			b[i] = u;
		}

		Arrays.parallelSort(b);

		int max1 = b[n - 1];
		int max2 = b[n - 2];

		for (int i : a) {
			if (i == max1) {
				out(max2);
			} else if (i == max2) {
				out(max1);
			} else {
				out(max1);
			}
		}

	}

	/*
	 * 以下メソッド集
	 */

	public static void permutation(String q, String ans) {
		// Base Case
		if (q.length() <= 1) {
			System.out.println(ans + q);
		}
		// General Case
		else {
			for (int i = 0; i < q.length(); i++) {
				permutation(q.substring(0, i) + q.substring(i + 1),
						ans + q.charAt(i));
			}
		}
	}

	static char[][] same(char[][] c, int h, int w) {

		char[][] a = new char[h][w];
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				a[i][j] = c[i][j];
			}
		}
		return a;

	}

	static int countkuro(char[][] c) {

		int count = 0;
		for (char[] cc : c) {
			for (char ccc : cc) {
				if ('#' == ccc) {
					count++;
				}
			}
		}
		return count;
	}

	static void debug() {

		out("---");
	}

	static void debug(Object a) {

		out("-------");
		out(a);
		out("-------");
	}

	static int ketasuu(int n) {

		String str = "" + n;
		return str.length();
	}

	static int account(String str) {

		String target = "AC";
		int count = 0;
		int len = str.length();
		for (int i = 0; i < len - 1; i++) {
			if (target.equals(str.substring(i, i + target.length()))) {
				count++;
			}
		}
		return count;
	}

	static int ni() {

		return sc.nextInt();
	}

	static long nl() {

		return sc.nextLong();
	}

	static double nd() {

		return sc.nextDouble();
	}

	static String n() {

		return sc.next();
	}

	static char[] nc() {

		return sc.next().toCharArray();
	}

	static int kaijo(int n) {

		if (n == 0 || n == 1) {
			return 1;
		} else {
			return n * kaijo(n - 1);
		}
	}

	static int fib(int n) {

		return (n == 1 || n == 0) ? n : fib(n - 2) + fib(n - 1);
	}

	static long lcm(long m, long n) {

		return m * n / gcd(m, n);
	}

	static int lcm(int m, int n) {

		return m * n / gcd(m, n);
	}

	static long gcd(long a, long b) {

		return (b == 0) ? a : gcd(b, a % b);
	}

	static int gcd(int a, int b) {

		return (b == 0) ? a : gcd(b, a % b);
	}

	static void out(Object obj) {
		System.out.println(obj);
	}

	static void outn(Object obj) {
		System.out.print(obj);
	}

	static double max(double d, double e) {

		return Math.max(d, e);
	}

	static long max(long a, long b) {

		return Math.max(a, b);
	}

	static long min(long d, long e) {

		return Math.min(d, e);
	}

	static int min(int a, int b) {

		return Math.min(a, b);
	}
}

class XY {

	int h;
	int c;

	XY(int h, int c) {
		this.h = h;
		this.c = c;
	}
}


Measured memory_bytes: 63200
#include<iostream>

using namespace std;

char s1[10],s2[10],s3[10],ans[3];
int a;

int main()
{
    cin>>s1;
    cin>>s2;
    cin>>s3;

    ans[0] = s1[0]-32;
    ans[1] = s2[0]-32;
    ans[2] = s3[0]-32;

    cout<<ans;

}


Measured memory_bytes: 256