akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define rep(i,m,n) for(int (i)=(m);(i)<(n);++(i))
#define rREP(i,m,n) for(int (i)=(n)-1;(i)>=(m);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 1000000001;
constexpr ll mod = 1000000007;
constexpr double PI = 3.1415926535897932;
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;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

int main() {
	init();
	
	int N; cin >> N;
	vector<int>a(N), b(N);
	rep(i, 0, N) {
		cin >> a[i] >> b[i];
	}
	sort(all(a));
	sort(all(b));
	int ans = 0;
	if (N % 2 == 0) {
		ans = (b[N / 2] + b[N / 2 - 1]) - (a[N / 2] + a[N / 2 - 1]) + 1;
	}
	else {
		ans = b[N / 2] - a[N / 2] + 1;
	}
	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 4724
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>

using namespace std;


int main() {
	map<int, int> mp;
	long long int n,w, a[100007], b[100007], c[100007], dp[105][100005] = {},tmp=0;
	string str, str2[5000];
	cin >> n>>w;

	
	for (int i = 1; i <= n; i++) {
		cin >> a[i]>>b[i];
		tmp += b[i];
	}
	for (int i = 0; i <= tmp-1; i++) {
		dp[1][tmp]=w;
		dp[1][i] = -1;
	}
	for (int i = 1; i <= n; i++) {
		for (int j = b[i]; j <=tmp; j++) {
			
			dp[i + 1][j - b[i]] = max(dp[i][j] - a[i], dp[i][j - b[i]]);
			
		}
		for (int j = tmp-b[i]+1; j <= tmp; j++) {

			dp[i + 1][j ] = max(dp[i][j],dp[i+1][j]) ;

		}
		for (int j = 0; j <= tmp; j++) {

		}
	}


	for (int i = 0; i <=tmp; i++) {
		if (dp[n + 1][i] >= 0) { cout << tmp - i; return 0; }

	}
	
}

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

#define INF 1e9
#define LLINF 1e18
#define pi 3.14159265358979323
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;

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


int main() {
    int a, b, c;
    cin >> a >> b >> c;
    int k;
    cin >> k;
    int n = 0;
    while(true) {
        if (b > a) break;
        else {
            b *= 2;
            n++;
        }
    }
    while (true) {
        if (c > b) break;
        else {
            c *= 2;
            n++;
        }
    }
    if (n <= k) {
        cout << "Yes" << endl;
    }
    else cout << "No" << endl;
}

Measured memory_bytes: 3628
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))
h,w = mi()
a = [list(input()) for _ in range(h)]

dp = [[0]*w for i in range(h)]
dp[0][0] = 1
for i in range(1,w):
    if a[0][i] == '#':break
    dp[0][i] = 1
for i in range(1,h):
    if a[i][0] == '#':break
    dp[i][0] = 1

for i in range(1,h):
    for j in range(1,w):
        if a[i][j] == '#':continue
        dp[i][j] = dp[i-1][j] + dp[i][j-1]
mod = 10**9+7
print(dp[h-1][w-1]%mod)

Measured memory_bytes: 165292
#include <bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
#define eps 1e-9

typedef long long ll;

using namespace std;

const ll inf = 1e18;
const ll mod = 1e9+7;
const int N = 1e5+5;
//int a[N];

int main()

{
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

    int ans = 0, cnt = 0;
    string s;

    cin >> s;

    for (int i = 0; i < s.size(); i++) {

        for (int j = i;  j < s.size(); j++) {

            if (s[j] == 'A' || s[j] == 'C' || s[j] == 'G' || s[j] == 'T') cnt++;
            else {

                ans = max(ans, cnt);
                break;
            }

            ans = max(ans, cnt);
        }

        cnt = 0;
    }


	cout << ans;

    return 0;
}


Measured memory_bytes: 256
s = input()
flg = 0
if s[0]!="A":
    print("WA")
elif s[2:-1].count("C") !=1:
    print("WA")
else:
    index = s.find("C")
    all_ind = [i for i in range(1,len(s))]
    all_ind.remove(index)
    for i in all_ind:
        if s[i].isupper():
            flg = 1
            print("WA")
            break
    if flg==0:
        print("AC")

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,0,n+1)
#define int long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
const int MOD=1e9+7;
const int INF=1e18;
const int MAX=3000;

int powMOD(int x,int r){
    if(r==0)return 1;
    if(r%2==0)return powMOD(x,r/2)*powMOD(x,r/2)%MOD;
    if(r%2==1)return powMOD(x,r-1)*x%MOD;
}

signed main(){
    int N;cin>>N;
    map<int,int>memo;
    REP(i,N){
        int a;cin>>a;
        memo[a]++;
    }
    bool ok=true;
    int i=(N%2==0?1:0);
    for(auto v:memo){
        if(N%2==0){
            if(v.first!=i||v.second!=2){
                ok=false;
                break;
            }
            i+=2;
        }
        else{
            if(i==0){
                if(v.first!=0||v.second!=1){
                ok=false;
                break;
                }
                i+=2;
            }
            else{
                if(v.first!=i||v.second!=2){
                ok=false;
                break;
                }
                i+=2;
            }
        }
    }
    if(ok)cout<<powMOD(2,N/2)<<endl;
    else cout<<0<<endl;
}

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

int main() {
  string S;
  int a = 0, b, c = 0;
  cin >> S;
  if (S.at(0) != 'A') cout << "WA" << endl;
  else {
    for (int i = 2; i < S.size() - 1; i++) {
      if (S.at(i) == 'C') a++;
    }
    if (a != 1) cout << "WA" << endl;
    else {
      for (int i = 2; i < S.size() - 1; i++) {
        if (S.at(i) == 'C') b = i;
      }
      for (int i = 1; i < b; i++) {
        c += isupper(S.at(i));
      }
      for (int i = b + 1; i < S.size(); i++) {
        c += isupper(S.at(i));
      }
      if (c != 0) cout << "WA" << endl;
      else cout << "AC" << endl;
    }
  }
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int n;
    cin >> n;
    int p[n];
    int cnt = 0;
    
    for(int i = 0; i<n; i++){
        cin >> p[i];
    }
    
    for(int i=1; i<n-1; i++){
        if((p[i-1] < p[i]) && (p[i] < p[i+1])){
            cnt++;
        } else if((p[i+1] < p[i]) && (p[i] < p[i-1])){
            cnt++;
        }
    }
    
    cout << cnt << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <queue>

#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <functional>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define INF 1<<29
#define ALEN(ARR) (sizeof(ARR) / sizeof((ARR)[0]))
#define MP make_pair
#define mp make_pair
#define pb push_back
#define PB push_back
#define _DEBUG(x) cout<<#x<<": "<<x<<endl
#define _DDEBUG(x,y) cout<<#x<<": "<<x<<", "<<#y<<": "<<y<<endl
#define ll long long
#define ull unsigned long long
#define MOD 1000000007

const int max_v = 100010;
const ll infinite = 1000'0000'0000'0000;

struct edge { int to, cost; };
using P = pair<int, int>;

int V; // vertex
vector<edge> G[max_v + 5]; // cost(if not exist, this value is INF)
ll d[max_v]; // distance

void dijkstra(int s) {
    // we can get small order first due to point greater
    priority_queue<P, vector<P>, greater<P> > que;
    fill(d, d + V, infinite);
    d[s] = 0;
    que.push(P(0, s));

    while(!que.empty()) {
        P p = que.top(); que.pop();
        
        int v = p.second;
        if (d[v] < p.first) {
            continue;
        }

        for(int i = 0; i < G[v].size(); i++) {
            edge e = G[v][i];
            if(d[e.to] > d[v] + e.cost) {
                d[e.to] = d[v] + e.cost;
                que.push(P(d[e.to], e.to));
            }
        }
    }
}

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

    int n;
    cin >> n;

    int a, b, c;
    for(int i = 0; i < n - 1; i++) {
        cin >> a >> b >> c;
        edge e1 = {b, c};
        edge e2 = {a, c};
        G[a].push_back(e1);
        G[b].push_back(e2);
    }

    int q, k;
    cin >> q >> k;
    V = n + 1;
    dijkstra(k);

    int x, y;
    for(int i = 0; i < q; i++) {
        cin >> x >> y;
#if DEBUG
        cout << "** RESULT **" << endl; // debug
        _DDEBUG(x, y);
        _DDEBUG(d[x], d[y]);
#endif
        cout << d[x] + d[y] << endl;
   }	
	return 0;
}

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

using namespace std;
int N;
long long GCD(long long a, long long b)
{
  return b ? GCD(b, a % b) : a;
}

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

    long long res = A[0];
    for (int i = 0; i < N; ++i) {
        res = GCD(res, A[i]);
    }
    cout << res << endl;
  return 0;
}

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

int main() {
	int a[5];
	int size = sizeof a / sizeof * a;
	int result;
  
	for (int i = 0; i < size; i++) {
		cin >> a[i];
	}

	for (int i = 0; i < size; i++) {
		if (a[i] == 0) {
			result = i + 1;
		}
	}

	cout << result << endl;

}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
struct D
{
	int year;
	int ken;
	int no;
};
using PD = shared_ptr<D>;
int func(const void*a, const void*b)
{
	if ((*(PD*)a)->year < (*(PD*)b)->year) return -1;
	if ((*(PD*)a)->year > (*(PD*)b)->year) return 1;
	return 0;
}
int main()
{
	int n, m;
	cin >> n >> m;
	vector<vector<PD>> ken(n);
	vector<PD> shi;
	for (int i = 0; i < m; i++)
	{
		int p, y;
		cin >> p >> y;
		PD tmp = make_shared<D>();
		tmp->ken = p;
		tmp->year = y;
		ken[p - 1].push_back(tmp);
		shi.push_back(tmp);
	}
	for (auto v : ken)
	{
		qsort(v.data(), v.size(), sizeof(PD), func);
		for (int i = 0, j = v.size(); i < j; i++)
			v[i]->no = i + 1;
	}
	for (auto s : shi)
	{
		cout << setw(6) << setfill('0') << s->ken << setw(6) << setfill('0') << s->no << endl;
	}
	return 0;
}

Measured memory_bytes: 13532
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long int
#define pb push_back
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define mem(x,y) memset(x,y,sizeof(x))//memset only use to initialize 0 or -1 no other number.
#define pii pair<int,int>
#define pll pair<ll,ll>
#define INF 1e9
#define INFL 1e18
#define mod 1000000007
//#define mod 998244353
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
using namespace __gnu_pbds; 
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> os;
typedef tree<pii,null_type,less<pii>,rb_tree_tag,tree_order_statistics_node_update> os_pair;
 
ll power(ll x,ll n){ll res =1;while(n>0){if(n%2==1){res=res*x;}x=x*x;n=n/2;}return res;}
ll powm(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
 
//cout<< fixed << setprecision(10)
multiset<int>f[200005];
int main(){
 
    fast;
    int T;
    T=1;
   // cin>>T;
    while(T--){
    string s,t;
    cin>>s>>t;
    int c=0;
    for(int i=0;i<s.size();i++){
    	if(s[i]!=t[i])
    	c++;
	}
 cout<<c<<"\n";
    }
	return 0;
}

Measured memory_bytes: 13188
#include <iostream>

using namespace std;

main(){

 int s;
 int time_h,time_m,time_s;

 cin >> s;
 //calculate for hours

 time_h = s / 3600;
 s %= 3600;

 time_m = s /60;
 s %= 60;

 time_s = s;

 cout << time_h << ':' << time_m << ':' << time_s  << endl;


}


Measured memory_bytes: 3080
#include <iostream>
#include <vector>
#include <cstddef>
#include <cstdint>
#include <map>
#include <utility>

using usize = int;
using u64 = long long;
using point = std::pair<usize, usize>;

template<class T>
inline void chmax (T &a, const T &b) {
	if (a < b) a = b;
}

u64 dp[3003][3003][4];

int main() {
	usize r, c, k;
	std::cin >> r >> c >> k;
	std::map<point, u64> items;
	for (usize i = 0; i < k; i++) {
		usize x, y;
		u64 value;
		std::cin >> x >> y >> value;
		items[point(x - 1, y - 1)] = value;
	}
	
	for (usize i = 0; i <= r; i++) for (usize j = 0; j <= c; j++) {
		for (usize s = 0; s < 4; s++) {
			if (i < r) chmax(dp[i + 1][j][0], dp[i][j][s]);
			if (j < c) chmax(dp[i][j + 1][s], dp[i][j][s]);
		}
		if (items.count(point(i, j))) {
			const u64 item = items[point(i, j)];
			for (usize s = 0; s < 3; s++) {
				if (i < r) chmax(dp[i + 1][j][0], dp[i][j][s] + item);
				if (j < c) chmax(dp[i][j + 1][s + 1], dp[i][j][s] + item);
			}
		}
	}

	u64 ans = 0;
	for (usize s = 0; s < 4; s++) chmax(ans, dp[r][c][s]);
	
	std::cout << ans << '\n';

	return 0;
}

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

int main() {
  int n;
  cin >> n;
  ll cnt = 0;
  rep(i, n) {
    int x;
    cin >> x;
    cnt += x;
  }
  if (cnt % 2 == 0)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}

Measured memory_bytes: 384
#include<stdio.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<string.h>
#include<functional>
#include<limits.h>
#include<stdlib.h>
#include<cmath>
#include<cstring>
#include<set>
#include<climits>
#include<bitset>
using namespace std;

#define intmax INT_MAX
#define lmax LONG_MAX
#define uintmax UINT_MAX
#define ulmax ULONG_MAX
#define llmax LLONG_MAX
#define ll long long
#define rep(i,a,N) for((i)=(a);(i)<(N);(i)++)
#define rrp(i,N,a) for((i)=(N)-1;(i)>=(a);(i)--)
#define llfor ll i,j
#define sc(a) cin>>a
#define pr(a) cout<<a<<endl
#define pY puts("YES")
#define pN puts("NO")
#define py puts("Yes")
#define pn puts("No")
#define pnn printf("\n")
#define pb push_back
#define all(a) a.begin(),a.end()
#define llvec vector<vector<ll>>
#define charvec vector<vector<char>>
#define llpvec vector<pair<ll,ll>>
#define size_(a,b) (a,vector<ll>(b))
#define S 3
int main(){
 string s;
 cin>>s;
 ll n=s.length();
  
 //010101......
 ll cnt1=0;
 for(int i=0;i<n;++i){
  if(i%2!=(s[i]-'0'))cnt1++;
 }
 cout<<min(cnt1,n-cnt1)<<endl;
 return 0;}

Measured memory_bytes: 3716
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    long s = sc.nextLong();
    long y = ((long)Math.pow(10,18)-s)%1000000000;
    long x = (s+y)/1000000000;
    System.out.println(0+" "+0+" "+x+" "+y+" "+1+" "+1000000000);
  }
}

Measured memory_bytes: 21844
#include <stdio.h>
int main()
{
  int H, W;
  scanf("%d %d", &H, &W);

  int a, b;

  while(H!=0 && W!=0){
    for(a=0; a<H; a++){
      for(b=0; b<W; b++){
	printf("#");
      }
      printf("\n");
    }

    printf("\n");
    scanf("%d %d", &H, &W);
  }
  return 0;
}

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

int main()
{
	int x[2];

	while (1){
		cin >> x[0] >> x[1];
		if (x[0] == 0 && x[1] == 0) break;
		sort (x, x + 2);
		cout << x[0] << " " << x[1] << endl;
	}
	return(0);
}

Measured memory_bytes: 1176
N = int(input())
red = [tuple(map(int, input().split())) for i in range(N)]
blue = [tuple(map(int, input().split())) for i in range(N)]

blue.sort()
red.sort(key=lambda x: x[1], reverse=True)

used = [0]*N

ans = 0
for bx, by in blue:
    for ri in range(N):
        if used[ri] == 1:
            continue
        rx, ry = red[ri]
        if rx < bx and ry < by:
            used[ri] = 1
            ans += 1
            break

print(ans)

Measured memory_bytes: 38896
#include <cstdio>
#include <algorithm>
using std::max;
int main(void)
{
    int dp[2][3],a[3],i,N;
    i=0; 
    dp[0][0]=0;
    dp[0][1]=0;
    dp[0][2]=0;
 
    scanf("%d",&N);
    while(N--)
    {
        scanf("%d%d%d",a,a+1,a+2);
        dp[1-i][0]=a[0]+max(dp[i][1],dp[i][2]);
        dp[1-i][1]=a[1]+max(dp[i][0],dp[i][2]);
        dp[1-i][2]=a[2]+max(dp[i][1],dp[i][0]);
        //printf("%d\t%d\t%d\n",dp[1-i][0],dp[1-i][1],dp[1-i][2]);
        i=1-i;
    }
    printf("%d\n",max(max(dp[i][0],dp[i][1]),dp[i][2]));
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#include <map>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
typedef long long ll;

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

vector<vector<bool>> checked(10,vector<bool>(10,false));



int main() {
    int x, y, z;
    cin >> x >> y >> z;
    cout << z << ' ' << x << ' ' << y << endl;
}

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

int main()
{
    int a;
    std::string s;
    std::cin >> a >> s;
    if (a >= 3200) { std::cout << s << std::endl; }
    else
    {
        std::cout << "red" << std::endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

fn main() {
    let n = read::<i32>();
    let a = read_vec::<i32>();

    let mut cur = 1;
    for x in a {
        if x == cur {
            cur += 1;
        }
    }

    println!("{}", if cur != 1 { n - cur + 1 } else { -1 });
}


Measured memory_bytes: 8444
input_line = input()
Line = input_line.split()
Line = [int(s) for s in Line]
#mondaisuu
N = Line[0]
#teisyutu
M = Line[1]
 
AC_Lists = [""]*N
# print(AC_Lists)
 
for i in range(M):
    input_line = input()
    Line = input_line.split()
    # print(AC_Lists[int(Line[0])-1])
    AC_Lists[int(Line[0])-1] += Line[1][0]
 
AC_count = 0
WA_count = 0
 
for s in AC_Lists:
    # print(s)
    if 'A' in s:
        AC_count += 1
        my_str = s.split("A")
        # print(my_str)
        # print(len(my_str[0]))
        WA_count += len(my_str[0])
    # else:
    #     print(len(s))
    #     WA_count += len(s)
# print(AC_Lists)
 
print(AC_count,WA_count)

Measured memory_bytes: 5312
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_map>
#include<climits>
#include<cstdlib>
#include<cmath>
#include<string>
#include<iomanip>
#include<bitset>

using namespace std;

#define ll long long int

ll const MOD = 1000000007;
ll const INF = (long long int)1 << 61;

ll mypow(ll x,ll n){
    ll ret = 1;
    while(n > 0){
        if(n&1){
            ret = (ret*x)%MOD;
        }
        x = (x*x)%MOD;
        n >>= 1;
    }
    return ret;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
 
    ll x,y,z,k;
    cin >> x >> y >> z >> k;

    vector<ll> a(x),b(y),c(z);

    for(int i = 0; i < x; i++){
        cin >> a[i];
    }
    for(int i = 0; i < y; i++){
        cin >> b[i];
    }
    for(int i = 0; i < z; i++){
        cin >> c[i];
    }

    map<ll,ll> mp;

    for(int i = 0; i < y; i++){
        for(int j = 0; j < z; j++){
            if(mp.find(-(b[i] + c[j])) == mp.end()){
                mp.insert(make_pair(-(b[i] + c[j]),1));
            }else{
                mp[-(b[i] + c[j])]++;
            }
        }
    }

    /*for(auto itr = mp.begin(); itr != mp.end(); itr++){
        cerr << (*itr).first << " ";
        cerr << (*itr).second << endl;
    }*/

    sort(a.begin(),a.end());

    ll smin = INF;
    vector<ll> ans;

    vector<pair<ll,ll>> pa;

    a.push_back(-1);

    for(int i = 0; i < x; i++){
        ll count = 0;
        while(a[i] == a[i+1]){
            count++;
            i++;
        }
        pa.push_back(make_pair(a[i],count+1));
    }


    auto getNext = [&](ll prev)->pair<ll,ll>{
        ll retv = 0;
        ll retc = 0;
        for(int i = 0; i < pa.size(); i++){
            auto itr = mp.upper_bound(-(prev - pa[i].first));
            if(itr != mp.end()){
                if(retv < pa[i].first + (-(*itr).first)){
                    retv = (pa[i].first + (-(*itr).first));
                    retc = pa[i].second*(*itr).second;
                }else if(retv == pa[i].first + (-(*itr).first)){
                    retc += pa[i].second*(*itr).second;
                }
            }
        }
        return make_pair(retv,retc);
    };

    while(true){
        auto ret = getNext(smin);
        for(int i = 0; i < ret.second && ans.size() < k; i++){
            ans.push_back(ret.first);
            //cerr << ans.size() << endl;
        }
        //cerr << ans.size() << endl;
        if(ans.size() == k){
            break;
        }
        smin = ret.first;
    }

    for(int i = 0; i < k; i++){
        cout << ans[i] << endl;
    }

    return 0;
}

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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) std::cout << x << '\n'
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define sz(x) ((int)(x).size())
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; }
const int dx[4] = { 1, 0, -1,  0 };
const int dy[4] = { 0, 1,  0, -1 };
const int INF = (int)1e9;
const ll  inf = (ll)1e18;
const int mod = 1000000007;
const int MAX_N = 100010;
const double PI = acos(-1);

ll n;
ll ans = 0;
char num[3] = { '3', '5', '7' };

void dfs(string &A) {
	if (0 < sz(A) && stoll(A) > n) return;

	ll cnt[3] = {};
	for (int i = 0; i < sz(A); i++) {
		for (int j = 0; j < 3; j++) {
			if (A[i] == num[j]) cnt[j]++;
		}
	}

	if (cnt[0] && cnt[1] && cnt[2]) {
		ans++;
	}

	for (int j = 0; j < 3; j++) {
		A.push_back(num[j]);
		dfs(A);
		A.pop_back();
	}
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(10);
	/*------------------------------*/

	cin >> n;

	string A = "";
	dfs(A);

	out(ans);

	return 0;
}

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

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { cout << #a << " = " << a << endl; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }
template<class T> void operator>> (istream& ist, vector<T>& vs) { for(auto& e: vs) cin >> e; }

typedef long long ll;
int const inf = 1<<29;

int main() {
  int N; cin >> N;
  vector<int> vs(N);
  rep(i, N) {
    cin >> vs[i];
  }
  auto copied = vs;
  sort(copied.begin(), copied.end());
  int m1 = copied[N / 2 - 1], m2 = copied[N / 2];
  rep(i, N) {
    if (vs[i] < m2) {
      cout << m2 << "\n";
    } else {
      cout << m1 << "\n";
    }
  }
}


Measured memory_bytes: 3712
#include<iostream>
#include<cstdio>
#include<algorithm>//sort头文件
using namespace std;
int a[10001],ans=0,bns=0,n;//乱入了1个打酱油的变量。
int main()
{
    scanf("%d",&n);//读入数据
    for(int i=1;i<=2*n;i++)//题目说的是2n，别一顺手就打错了。
    {
        scanf("%d",&a[i]);//循环读入
    }
    sort(a+1,a+1+2*n);    //所有数据排序
    for(int i=1;i<=2*n;i+=2)
    {
        bns+=a[i];//根据题意分析，我们只需要逐个跳着加和即为所求。
    } 
    printf("%d\n",bns);//AT通性，换行
    return 0;//结束
}

Measured memory_bytes: 256
import java.util.*;
 
public class Main {
	static int count = 0;
 
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
 
		int N = sc.nextInt();
		int M = sc.nextInt();
		int[] K = new int[N];
		int[][] A = new int[N][100];
		for (int i=0; i<N; i++) {
			K[i] = sc.nextInt();
			for (int j=0; j<K[i]; j++) {
				A[i][j] = sc.nextInt();
			}
		}
 
		int[][] matrix = new int[N][M];
		for (int i=0; i<N; i++) {
			for (int j=0; j<K[i]; j++) {
				matrix[i][A[i][j]-1] = 1;
			}
		}
		
		int[] check = new int[M];
		for (int i=0; i<M; i++) {
			for (int j=0; j<N; j++) {
				check[i] += matrix[j][i];
			}
			
			if(check[i]==N) {
				count++;
			}
		}
		
		System.out.println(count);
 
	}
 
}

Measured memory_bytes: 22996
#include <stdio.h>

int width,height;
char map[52][52];
int result[51][51];

int main(void) {
	int i,j;
	scanf("%d%d",&height,&width);
	for(i=1;i<=height;i++)scanf("%s",&map[i][1]);
	for(i=0;i<51;i++)result[i][0]=result[0][i]=0x10000000;
	result[1][0]=0;
	for(i=1;i<=height;i++) {
		for(j=1;j<=width;j++) {
			result[i][j]=
				((result[i][j-1]<result[i-1][j])?
					result[i][j-1]:result[i-1][j])
				+map[i][j]-'0';
		}
	}
	printf("%d\n",result[height][width]);
	return 0;
}

Measured memory_bytes: 0
a=input().strip()
if len(a)<26:
  for i in range(97, 97+26):
    if chr(i) not in list(a):
      print(a+chr(i))
      break
else:
  f=False
  for i in range(26):
    t0=a[25-i:]
    ts=list(t0)
    ts.sort(reverse=True)
    t1="".join(ts)
    
    if t0 != t1 :
      for j in range(len(ts)):
        if ts[len(ts)-1-j]==t0[0]:
          print(a[:25-i]+ts[len(ts)-1-j-1])
          f=True
          break
    if f == True:
      break
  else:
    print(-1)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

const int mod = 1000000007;
struct mint {
  ll x;  // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint& operator+=(const mint a) {
    if((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if((x += mod - a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const { return mint(*this) += a; }
  mint operator-(const mint a) const { return mint(*this) -= a; }
  mint operator*(const mint a) const { return mint(*this) *= a; }
  mint pow(ll t) const {
    if(!t) return 1;
    mint a = pow(t >> 1);
    a *= a;
    if(t & 1) a *= *this;
    return a;
  }
  // for prime mod
  mint inv() const { return pow(mod - 2); }
  mint& operator/=(const mint a) { return *this *= a.inv(); }
  mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }
mint fact(int n) {
  if(n == 1 || n == 0) return 1;
  mint res = n;
  return res * fact(n - 1);
}

map<ll, ll> primeFactor(ll n) {
  map<ll, ll> res;
  for(ll i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      res[i]++;
      n /= i;
    }
  }
  if(n != 1) res[n] = 1;
  return res;
}

int main() {
  ll n;
  cin >> n;
  map<ll, ll> mp;
  rep2(i, 2, n + 1) {
    auto pf = primeFactor(i);
    for(auto v : pf) mp[v.first] += v.second;
  }
  mint ans = 1;
  for(auto v : mp) ans *= (v.second + 1);
  cout << ans << endl;
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N,M;
ll A[5050];
int B[5050][202];
ll ret;

int more[5050][202];
ll add[5050];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	scanf("%d%d",&N,&M);
	FOR(i,N-1) {
		scanf("%d",&x);
		A[i+1]=A[i]+x;
	}
	
	FOR(y,N) FOR(x,M) scanf("%d",&B[y][x]);
	FOR(x,M) {
		stack<pair<int,int>> S;
		B[N][x]=1<<30;
		S.push({1<<30,N});
		more[N][x]=N;
		for(y=N-1;y>=0;y--) {
			while(S.top().first<B[y][x]) S.pop();
			more[y][x]=S.top().second;
			S.push({B[y][x],y});
		}
		
		y=0;
		while(y<N) {
			add[more[y][x]]+=B[more[y][x]][x]-B[y][x];
			y=more[y][x];
		}
	}
	
	FOR(y,N) {
		ll cur=0;
		FOR(x,M) cur+=B[y][x];
		ret=max(ret,cur);
		for(int z=y+1;z<N;z++) {
			cur+=add[z];
			ret=max(ret,cur-(A[z]-A[y]));
		}
		
		FOR(x,M) {
			j=more[y][x];
			add[j]-=B[j][x]-B[y][x];
			i=y+1;
			while(i<j) {
				add[more[i][x]]+=B[more[i][x]][x]-B[i][x];
				i=more[i][x];
			}
		}
		
	}
	
	cout<<ret<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}


Measured memory_bytes: 8192
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define forn(i,a,b) for(int i =a;i<b;i++)
#define fi first
#define se second
#define fast ios_base::sync_with_stdio(false);
using namespace std;


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


void solve(){
	int k;
	string s;
	cin >> k >> s;
	int n = s.length();
	if(n<=k){
		cout << s << endl;
	}
	else{
		string a = s.substr(0,k);
		cout << a << "..." << endl;
	}
}

int main(){
	fast;
	#ifndef ONLINE_JUDGE
		freopen("in","r",stdin);
		freopen("out","w",stdout);
	#endif

	// int t;cin >> t;while(t--)
		solve();
}


Measured memory_bytes: 3616
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        C solver = new C();
        solver.solve(1, in, out);
        out.close();
    }

    static class C {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            long x = Long.parseLong(in.next());
            long y = Long.parseLong(in.next());
            long ans = 0;
            for (long i = x; i <= y; i = i * 2) {
                ans++;
            }

            // 出力
            out.println(ans);

        }

    }
}



Measured memory_bytes: 22868
fn main() {
    let n = read::<usize>();
    let k = read::<i32>();
    let xs = read_vec::<i32>();

    let mut sum = 0;
    for i in 0..n {
        let p = std::cmp::min(xs[i], k - xs[i]);

        sum += p * 2;
    }
    println!("{}", sum);
}

#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
#[allow(dead_code)]
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
#[allow(dead_code)]
fn yn(result: bool) {
    if result {
        println!("Yes");
    } else {
        println!("No");
    }
}


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

int main(){
	int n;
	long long cnt=0;
	cin >> n;
	vector<int> a(n+1);
	vector<int> b(n);
	
	for(int i=0;i<n+1;i++){
		cin >> a[i];
	}
	for(int i=0;i<n;i++){
		cin >> b[i];
	}
	
	for(int i=0;i<n;++i){
		int c = min(a[i],b[i]);
		cnt += c;
		a[i] -= c;
		b[i] -= c;

		int d = min(a[i+1],b[i]);
		cnt += d;
		a[i+1] -= d;
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 4048
#include <stdio.h>
int main(){
    int w,h,x,y,r;
    scanf("%d %d %d %d %d",&w,&h,&x,&y,&r);
    if((y<r)||(x<r)){
        printf("No\n");
    } else if ((h<y+r)||(w<x+r)){
        printf("No\n");
    } else {
        printf("Yes\n");
    }
}


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

int main() {
vector<int> h(10000);
vector<int> w(10000);
for(int i=0;i<10002;i++){
    cin >> h.at(i) >> w.at(i);
    if(h.at(i)==0&&w.at(i)==0) break;
}
for (int l=0;l<10005;l++){
    if(h.at(l)==0&&w.at(l)==0) return 0;
    
for(int i=0;i<w.at(l);i++){
    cout << "#";
}
cout << endl;
for(int i=0;i<h.at(l)-2;i++){
    cout << "#";
    for(int j=0;j<w.at(l)-2;j++){
        cout << ".";
    }
    cout << "#" <<endl;
}
for(int i=0;i<w.at(l);i++){
    cout << "#";
}
cout << endl<<endl;
}}



Measured memory_bytes: 3192
//                   ********** YATIN KWATRA **********

// AC BAKSHI RABBA

#include <bits/stdc++.h>
#define ll                      long long 
#define ld                      long double
#define ull                     unsigned long long 
#define FIO                     ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl                    "\n"
#define fo(i,a,b)               for(int i = a; i<=b ; i++)
#define rfo(i,a,b)              for(int i = a; i>=b ; i--)
#define vii                     vector<int>
#define vll                     vector<ll>
#define pq                      priority_queue
#define uom                     unordered_map                
#define all(v)                  v.begin(),v.end()
#define mp                      make_pair
#define pb                      push_back
#define pob                     pop_back
#define ff                      first
#define ss                      second
#define pii                     pair<int,int> 
#define pll                     pair<long,long>
#define mll                     map<ll,ll>
#define mii                     map<int,int>
#define vvii                    vector<vii>
#define vvll                    vector<vll>
#define mod                     1000000007
#define MIN                     -1e9
#define pi                      3.1415926535897932384626433832795

using namespace std;

void INPUT() 
{  
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
}

/*
    
   -> Check For Overflows
   -> Out of Bounds
   -> Initialisations of global arrays and variables
   -> Read the Question and the sample test cases carefully
   -> Its not Always Complex, Try to simplify
   -> write it down and try to solve
   -> Have Faith in urself and in ur approach
   -> If it seems totally out of reach, switch to next :)
   -> And Come Back later, if possible ..
*/



const int N = 60005;


int f( int x, int y, int z)
{
  return (x*x + y*y + z*z + x*y + y*z + z*x);
}

void solve()
{ 
        int n;
        cin >> n;
        
        vii v(N,0);

        int cur;

        fo(i,1,100)
        {
          fo(j,1,100)
          {
            fo(k,1,100)
            {
              cur = f(i,j,k);
              v[cur]++;
            }
          }
        }

        fo(i,1,n) cout << v[i] << endl;

       
}
int main() {
    
    FIO
    INPUT();
    
    int t;
    t = 1;
    //cin >> t;
    
    while(t--)
    {
       solve();
    }
    return 0;
}


Measured memory_bytes: 3600
#include<bits/stdc++.h>
#include<math.h>
#include<queue>
#include<cstdio>
#include<set>
#include<map>
using namespace std;
using ll = long long;

int main(){
    ll N,M,K;
    cin >> N >> M >> K;
    vector<ll> A(N),B(M);
    vector<ll> sumA(N+1),sumB(M+1);
    sumA.at(0)=0;
    sumB.at(0)=0;
    for(ll i=0; i<N; i++){
        cin >> A.at(i);
        sumA.at(i+1)=sumA.at(i)+A.at(i);
    }
    for(ll i=0; i<M; i++){
        cin >> B.at(i);
        sumB.at(i+1)=sumB.at(i)+B.at(i);
    }
    ll max=0;
    for(ll i=0; i<=N; i++){
        ll target=K-sumA.at(i);
        ll a=0;
        ll b=M;
        ll here;
        if(sumB.at(b)<=target){
			 here=b;
        }else if(sumB.at(a)>target){
			break;
        }else{
          	while(b-a>1){
            ll c=(a+b)/2;
            if(target==sumB.at(c)){
                here = c;
                break;
            }else if(target<sumB.at(c)){
                b=c;
            }else{
                a=c;
            }
        }
        if(target==sumB.at(b)) here=b;
        else here = a;
        }
        if(max<i+here) max=i+here;
    }
    cout << max << endl;
    return 0;
}

Measured memory_bytes: 9592
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <cstdlib>
#include <cmath>
#include <functional>
#include <queue>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <stack>
#include <deque>
#include <map>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define fst first
#define snd second
const ll mod = 1000000007;
const ll INF = (1LL << 59);
const int iINF = (1 << 31) - 1;
const double dINF = 1000000000000000000.0;
const int MAX_N = 1 << 17;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;

//#define _DEB 0

int main(){
	int n; cin >> n;
	bool flg = false;
	for (int i = 0; i < n; i++) {
		char c; cin >> c;
		if (c == 'Y')flg = true;
	}
	cout << (flg ? "Four" : "Three") << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); 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 equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
//const ll mod = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }



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

  int n = s.length();
  rep(i, s.length() - 1) {
    if (s[i] == 'a') continue;
    if (k >= 'a' + 26 - s[i]) {
      k -= 'a' + 26 - s[i];
      s[i] = 'a';
    }
  }
  s[n - 1] = 'a' + (s[n - 1] - 'a' + k) % 26;
  cout << s << endl;


  
  return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
#define int ll
using namespace std;
signed main()
{
	fastio;
	int n;
	cin>>n;
	int a[n]={};
	int sum=0;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		if(i%2==0)
		{
			if(a[i]%2==1)
			{
				sum++;
			}
		}
	}
	cout<<sum;
	
	
		
return 0;
}


Measured memory_bytes: 3648
#include <iostream>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <sstream>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <complex>
#include <vector>
#include <bitset>
#include <cstdio>
#include <cmath>
#include <time.h>
#include <tuple>
#define all(c) ((c).begin(),(c).end())
#define rall(c) ((c).rbegin(),(c).rend())
//#define sort(v,n) sort(v,v+n)
#define ll long long
#define fi first
#define se second
#define inf 999999999
using namespace std;
const ll MOD = 1e9 + 7;
const double PI = acos(-1.0);
//---------------------------------------------------------------------------------------------//
int q;

inline int digit(ll a) {
	int now = 0;
	while (a > 0) {
		a /= 10;
		now++;
	}
	return now;
}

inline int buunnkatsu(ll a) {
	ll res=-inf;
	int b[7];
	for (int i = 0; i < 7; i++)b[i] = 0;
	int n = digit(a);
	for (int i = n-1; i >=0; i--) {
		b[i] = (a % 10);
		a /= 10;
	}
	ll c=0, d=0;
	for (int i = 0; i < n; i++) {
		c = 0;
		d = 0;
		for (int j = 0; j <= i; j++) {
			c *= 10;
			c += b[j];
		}
		for (int j = i + 1; j < n; j++) {
			d *= 10;
			d += b[j];
		}
		//cout <<"i="<<i<< "c=" << c << "d=" << d << endl;
		res = max(res, c*d);
	}
	//cout <<"res="<< res << endl;
	return res;
}

int main() {
	cin >> q;
	for (int i = 0; i < q; i++) {
		ll a; int cont = 0;
		cin >> a;
		while (1) {
			if (cont > 100000) {
				break;
			}
			if (digit(a) > 1) {
				a = buunnkatsu(a);
			}
			else {
				break;
			}
			cont++;
		}
		if (cont > 100000)cout << -1 << endl;
		else
		cout << cont << endl;
	}
}

Measured memory_bytes: 3064
program main
   implicit none
   integer,allocatable,dimension(:)::a
   integer::n,i,ma,counter=0
   read(*,*)n
   allocate(a(n))
   read(*,*)a
   ma=a(1)
   do i=1,n
     if(ma<=a(i))then
       counter=counter+1
       ma=a(i)
     endif
   enddo
   write(*,*)counter
end program main


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

#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <algorithm>

#include <bits/stdc++.h>
#include <cmath>
#include <limits>

using namespace std;
using Graph = vector<vector<int>>;

long long N;
map<int, map<int, int>> mp; //頂点、色種、0
map<pair<int, int>, int> eorder; //辺、入力番号
map<pair<int, int>, int> ecolor; //辺、色番号

void dfs(Graph &G, int v, vector<int> &done, int K){
	if(done[v] == 1) return;

	map<int, int> used;
	//隣の頂点が処理済の場合、隣の頂点の辺の色をusedに追加
	for(auto next_v : G[v]){
		if(done[next_v] == 0){
			continue;
		}
		int a = min(v, next_v);
		int b = max(v, next_v);
		if(ecolor.count({a, b}) != 0){
			used[ecolor[{a, b}]] = 1;
			continue;
		}
		for(auto nn_v : G[next_v]){
			if(nn_v != v){
				used[ecolor[{min(next_v, nn_v), max(next_v, nn_v)}]] = 1;
			}
		}
	}

	//used以外の色を順番に色付け
	map<int, int> color;
	int c = 1;
	for(auto next_v : G[v]){
		int a = min(v, next_v);
		int b = max(v, next_v);
		if(ecolor.count({a, b}) != 0){
			continue;
		}
		int i;
		for(i = c; i <= K; i++){
			if(used.count(i) == 0){
				color[i] = 1;
				used[i] = 1;
				ecolor[{a, b}] = i;
				break;
			}
		}
		c = i + 1;
	}
	mp[v] = color;
	done[v] = 1;

	//次の頂点の処理
	for(auto next_v : G[v]){
		if(done[next_v] == 0){
			dfs(G, next_v, done, K);
		}
	}
}

int main(int argc, char* argv[]){
	cin.tie(0);
	ios::sync_with_stdio(false);

	cin >> N;
	Graph G(N);
	vector<pair<int, int>> edge;
	for(int i=0; i<N-1; i++){
		int a, b;
		cin >> a >> b;
		G[a - 1].push_back(b - 1);
		G[b - 1].push_back(a - 1);
		edge.push_back(make_pair(a - 1, b - 1));
		eorder[make_pair(a - 1, b - 1)] = i;
	}

	int K = 0;
	int v = 0;
	for(int i=0; i<N; i++){
		int w = G[i].size();
		if(w > K){
			K = w;
			v = i;
		}
	}
	printf("%d\n", K);

	//vを起点に辺に色付けしていく
	vector<int> done;
	done.assign(N, 0);
	dfs(G, v, done, K);

	for(int i=0; i<edge.size(); i++){
		int a = edge[i].first;
		int b = edge[i].second;
		int c = ecolor[{a, b}];
		printf("%d\n", c);
	}
	return 0;
}

Measured memory_bytes: 48116
# coding: utf-8
w=int(input())
L=[i for i in range(1,w+1)]
n=int(input())
for i in range(n):
    a,b=[int(j)-1 for j in input().split(",")]
    s=L[a]
    L[a]=L[b]
    L[b]=s
[print(i) for i in L]

Measured memory_bytes: 7676
//#pragma warning disable
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System;
using System.Numerics;
using System.Threading.Tasks;
using static System.Math;
using static System.Console;
class Z { static void Main() => new K(); }
class K
{
	int F() => int.Parse(ReadLine());
	long FL() => int.Parse(ReadLine());
	int[] G() => ReadLine().Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();
	long[] GL() => ReadLine().Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries).Select(long.Parse).ToArray();
	public const int MOD = 1000000007;
	public K()
	{
		SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
		Solve();
		Out.Flush();
	}
	void Solve()
	{
		var I = G();
		int V = I[0], E = I[1];
		var a = new bool[V];
		var b = new bool[V];
		for (var i = 0; i < E; i++)
		{
			I = G();
			if (I[0] == 1) a[I[1] - 1] = true;
			if (I[1] == V) b[I[0] - 1] = true;
		}
		var flag = false;
		for (var i = 0; i < V; i++) flag |= a[i] & b[i];
		Console.WriteLine(flag ? "POSSIBLE" : "IMPOSSIBLE");
	}
}


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

using namespace std;

#define F first
#define S second
#define modulo ll (1e9 + 7)
const long double PI = 3.141592653589793238L;

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

void init(){
    cin.tie(0);
    cin.sync_with_stdio(0);
}

const int N = 4e5 + 9, M = 5e3 + 9, OO = 0x3f3f3f3f;
const ll llOO = 0x3f3f3f3f3f3f3f3f;



int main(){
    init();

    int R;  cin >> R;
    cout << fixed << setprecision(10) << 2 * PI * R;

}







Measured memory_bytes: 3800
# import sys
# sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
def II(): return int(input())

def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())

def LI(): return list(map(int, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

from collections import deque

def solve():
    n = II()
    H = LI()
    d = deque([])

    flag = True
    for i in range(0, n):
        hi = H[i]
        if i == 0:
            d.append(hi - 1)
            continue

        hp = d.popleft()
        if hp < hi:
            d.append(hi - 1)
        elif hp == hi:
            d.append(hi)
        else:   # hp > hi
            flag = False
            break

    print('Yes' if flag else 'No')







if __name__ == '__main__':
    solve()


Measured memory_bytes: 14780
#include<stdio.h>

int p_tax, a_tax, price, max, search_cnt;

int MAX(int a, int b)
{
    return (a > b) ? a : b;
}

int tax_calcurate(int tax, int left, int right)
{
    return left * (100 + tax) / 100 + right * (100 + tax) / 100;
}

void Max_Search(int left, int right)
{
    int tmp = 0, p_price;
    if( left <= right ){
        p_price = tax_calcurate(p_tax, left, right);
        if(  p_price == price ) tmp = tax_calcurate( a_tax, left, right );
        max = MAX( max, tmp);

        if(( p_price == price && search_cnt <= price / 2) ||( p_price < price && search_cnt <= price / 2)) Max_Search( search_cnt++, price );
        else Max_Search( left, right - 1);
    }
}

int main()
{
    while(1){
        scanf("%d %d %d", &p_tax, &a_tax, &price);
        max = search_cnt = 1;

        if( p_tax == 0 && a_tax == 0 && price == 0 ) break;
        Max_Search(search_cnt, price);
        printf("%d\n", max);

    }
    return 0;
}

Measured memory_bytes: 1760
#include <stdio.h>
#include <vector>
#include <utility>
#include <queue>
using namespace std;
typedef long long ll;

int main(void) {
  ll i, j, n, u, v, w, now;
  scanf("%lld", &n);
  vector< pair<ll, bool> > vec[n];
  bool ans[n], flg[n];
  for(i = 1; i < n; ++i) {
    scanf("%lld%lld%lld", &u, &v, &w);
    vec[--u].push_back(make_pair(--v, w & 1));
    vec[v].push_back(make_pair(u, w & 1));
  }
  for(i = 0; i < n; ++i) flg[i] = true;
  flg[0] = false;
  ans[0] = true;
  queue<ll> q;
  q.push(0);
  while(q.size()) {
    now = q.front(), q.pop();
    for(i = 0; i < vec[now].size(); ++i) if(flg[vec[now][i].first]) {
      ans[vec[now][i].first] = ans[now] ^ vec[now][i].second;
      flg[vec[now][i].first] = false;
      q.push(vec[now][i].first);
    }
  }
  for(i = 0; i < n; ++i) printf("%d\n", ans[i]);
  return 0;
}

Measured memory_bytes: 8064
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int top , S[1000] ;

void push(int t){
    S[++top] = t ;
}
int pop(){
    top-- ;
    return S[top + 1] ;
}

int main(void){
    int m , b ;
    top = 0 ;
    char a[100] ;
    while(scanf("%s" , a) != EOF){
        if(a[0] == '+'){
            m = pop() ;
            b = pop() ;
            push(m + b) ;
        }
        else if(a[0] == '-'){
            m = pop() ;
            b = pop() ;
            push(b - m) ;
        }
        else if(a[0] == '*'){
            m = pop() ;
            b = pop() ;
            push(m * b) ;
        }
        else push(atoi(a)) ;
    }
    printf("%d\n" , pop()) ;
    return 0 ;
}



Measured memory_bytes: 2140