akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <fstream>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long

int main () {
  int n;
  cin >> n;
  vector<int> L(n);
  rep(i, n) {
    cin >> L.at(i);
  }
  int ans = 0;
  for(int i = 0; i < n; i++) {
    for(int j = i + 1; j < n; j++) {
      for (int k = j + 1; k < n; k++) {
        if (L.at(i) == L.at(j) || L.at(i) == L.at(k) || L.at(j) == L.at(k)) continue;
        int length = L.at(i) + L.at(j) + L.at(k);
        int maxlen = max(L.at(i), max(L.at(j), L.at(k)));
        int rest = length - maxlen;
        if (rest > maxlen) ans++;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3628
#include <stdio.h>
int main(){
	int data[10]={};
	int n, i=0;
	while(scanf("%d", &n) != EOF){
		if(n!=0){
			data[i] = n;
			i++;
		} else {
			i--;
			printf("%d\n", data[i]);
			data[i] = 0;
		}
	}
	return 0;
}

Measured memory_bytes: 1804
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
using namespace std;
typedef long long ll;
const ll MOD = 998244353;
const ll INF = (ll)1000000007 * 1000000007;
const double EPS = 1e-9;
typedef pair<int, int> P;
typedef unsigned int ui;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-11;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
int main() {
	vector<int> G[100];
	P need[100][100];
	int m, n; cin >> m >> n;
	rep(i, m) {
		rep(j, n) {
			need[i][j] = { -1,101 };
		}
	}
	int s; string o; int c; int K;
	rep(i, m) {
		cin >> K;
		rep(j, K) {
			cin >> s >> o >> c; s--;
			if (o == ">=") {
				need[i][s].first = max(need[i][s].first, c);
			}
			else {
				need[i][s].second = min(need[i][s].second, c);
			}
		}
	}
	int used[100][100] = {};
	rep(i, m) {
		Rep(j,i, m) {
			rep(k, n) {
				if (need[i][k].second < need[j][k].first&&!used[i][j]) {
					G[i].push_back(j); used[i][j] = 1;
				}
				if (need[j][k].second < need[i][k].first && !used[j][i]) {
					G[j].push_back(i); used[j][i] = 1;
				}
			}
		}
	}
	bool f = false;
	rep(i, m) {
		int cyc[100] = {};
		queue<int> q; q.push(i); cyc[i] = 1;
		while (!q.empty()) {
			int now = q.front(); q.pop();
			int len = G[now].size();
			rep(j, len) {
				int v = G[now][j];
				if (v == i)f = true;
				if (!cyc[v]) {
					cyc[v] = 1; q.push(v);
				}
			}
		}
	}
	if (f)cout << "No" << endl;
	else cout << "Yes" << endl;
	return 0;
}


Measured memory_bytes: 3392
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
#include <cstdlib>
#include <typeinfo>
#include <list>
#include <stdio.h>
#include <math.h>

using namespace std;

const int MAX_R = 10;
const int MAX_C = 10000;

int main() {
  int gril[MAX_R][MAX_C];
  int r, c;

  while(1){
    scanf("%d %d", &r, &c);
    if(r == 0 && c == 0) return 0;
    for (int i = 0; i < r; i++) for (int j = 0; j < c; j++) scanf("%d", &gril[i][j]);

    int ans = 0;
    for (int mask = 0; mask < (1 << r); mask++) {
      vector<int> sum_of_0(c, 0);

      for (int r_pos = 0; r_pos < r; r_pos++) {
        if (mask & (1 << r_pos)){
          for (int i = 0; i < c; i++) if(gril[r_pos][i] == 1) sum_of_0[i]++;
        }else{
          for (int i = 0; i < c; i++) if(gril[r_pos][i] == 0) sum_of_0[i]++;
        }
      }

      int tmp = 0;
      for (int i = 0; i < c; i++) tmp += max(sum_of_0[i], r - sum_of_0[i]);
      ans = max(ans, tmp);
    }
    printf("%d\n", ans);
  }
  return 0;
}

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

int main() {
  int a1,a2,a3;
  cin >> a1 >> a2 >> a3;
  cout << min(abs(a1-a2)+abs(a2-a3),min(abs(a1-a3)+abs(a3-a2),min(abs(a1-a2)+abs(a1-a3),min(abs(a2-a3)+abs(a3-a1),min(abs(a3-a2)+abs(a2-a1),abs(a3-a1)+abs(a1-a2)))))) << endl;

}


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

using namespace std;

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

    vector<int64_t> C(3);

    for (const auto &s: S)
        C[s % 3]++;

    int64_t ans = C[0] * C[1] * C[2];
    for (int i = 0; i < n; i++){
        for (int j = i + 1; j < n; j++){
            if (S[i] == S[j])
                continue;
            if (j + j - i < n and S[j + j - i] % 3 == 3 - (S[i] % 3) - (S[j] % 3))
                ans--;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 3636
#include<cstdio>
const int N=100010;
int v[N],maxv;
int main(){
	int n; scanf("%d",&n);
	for(int i=1;i<=n;++i){
		int x; scanf("%d",&x);
		++v[x]; ++v[x+1]; ++v[x+2];
	}
	for(int j=0;j<=N-1;++j) if(v[j]>maxv) maxv=v[j];
	printf("%d",maxv); return 0;
}

Measured memory_bytes: 512
/**
 *    author:  tourist
 *    created: 17.12.2019 17:38:40       
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> h(n);
  for (int i = 0; i < n; i++) {
    cin >> h[i];
  }
  vector<int> dp(n);
  dp[0] = 0;
  for (int i = 1; i < n; i++) {
    dp[i] = dp[i - 1] + abs(h[i] - h[i - 1]);
    if (i >= 2) {
      dp[i] = min(dp[i], dp[i - 2] + abs(h[i] - h[i - 2]));
    }
  }
  cout << dp.back() << '\n';
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using ll = long long;

#define rep(i, n) for (ll i = 0; i < (n); i++)
using namespace std;
long long MX = 1.0e18;

int main() {
    ll a[200000];
    ll n;
    ll ans = 1;
    bool zero = false;
    cin >> n;
    rep(i, n) {
        cin >> a[i];
        if (a[i] == 0) zero = true;
    }
    // ゼロかどうかの判定
    if (zero) {
        cout << 0 << endl;
        return 0;
    }
    rep(i, n) {
        // 最大かどうかの判定
        // if (MX / ans < a[i]) {
        if (ans > 1000000000000000000 / a[i]) {
            cout << -1 << endl;
            return 0;
        }
        ans *= a[i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4376
package main

import "fmt"

func main() {
	var s string
	fmt.Scan(&s)
	a := f(s)
	fmt.Printf("%s%d%s\n", s[:1], a-2, s[a-1:])
}

func f(s string) (n int) {
	for range s {
		n++
	}
	return
}


Measured memory_bytes: 512
n,k=map(int, input().split())  
MOD=10**9+7
uplimit=2*10**5+1
fac = [0 for i in range(uplimit)] # 階乗
inv = [0 for i in range(uplimit)] # iの逆元 
finv = [0 for i in range(uplimit)] # i!の逆元

def fac_and_inv() :
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    inv[1] = 1
    for i in range(2, uplimit) :
        fac[i] = fac[i-1] * i % MOD
        inv[i] = MOD - inv[MOD%i] * int(MOD / i) % MOD
        finv[i] = finv[i-1] * inv[i] % MOD
    return fac, finv, inv

temp = fac_and_inv()
ans = 0

#  x : 0人部屋の数
for x in range(0, k+1) : # k回動ける=最大kまで0人部屋になりうる
    if(x >= n) : # kがn以上の場合を想定。これ以降は計算する意味なし。
        break
    y = n - x # y : 人がいる部屋の数
    ans += (fac[n]*finv[x]*finv[n-x]) * (fac[n-1] * finv[x] * finv[y-1]) % MOD
    # 要はnCx * n-xHx 通り
    # nCxは0人部屋の選び方
    # n-xHxは n-xから重複を許してx選ぶ組み合わせ
    # n-xHx = n-1Cn-x-1 = n-1Cy-1
    # よって(n-1)! / x! / (y-1)!が欲しい

print(ans % MOD)



Measured memory_bytes: 26904
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int ans=1000000;
int f(int x)
{
	int cnt=0;
	while(x!=0)
	{
		cnt+=x%10;
		x/=10;
	}
	return cnt;
}
int n;
int main()
{
	cin>>n;
	for(int i=1;i<=n-1;i++) ans=min(ans,f(i)+f(n-i));
	cout<<ans;	
} 

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) ; 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 All(x) (x).begin(),(x).end()

typedef long long ll;
typedef unsigned long long ull;

const int INF = 1e9;

int main(){
   int n,m;
   cin >> n >> m;
   vector<int> a(n);
   vector<int> b(n);
   vector<int> c(m);
   vector<int> d(m);
   rep(i,n){
      cin >> a[i];
      cin >> b[i];
   }
   rep(i,m){
      cin >> c[i];
      cin >> d[i];
   }
   vector<int> ans(n);
   int minEle = INF;
   for(int i=0;i<n;i++){
      for(int j=0;j<m;j++){
         int tmp = abs(a[i] - c[j]) + abs(b[i] - d[j]);
         if(minEle > tmp){
            minEle = tmp;
            ans[i] = j+1;
         }
      }
      minEle = INF;
   }
   rep(i,n)cout << ans[i] << endl;
   return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<deque>
#include<iomanip>
#include<tuple>
using namespace std;
typedef long long int LL;
typedef pair<int,int> P;
typedef pair<LL,int> LP;
const int INF=1<<30;
const LL MAX=1e9+7;

void array_show(int *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%d%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(LL *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%lld%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(vector<int> &vec_s,int vec_n=-1,char middle=' '){
	if(vec_n==-1)vec_n=vec_s.size();
	for(int i=0;i<vec_n;i++)printf("%d%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}
void array_show(vector<LL> &vec_s,int vec_n=-1,char middle=' '){
	if(vec_n==-1)vec_n=vec_s.size();
	for(int i=0;i<vec_n;i++)printf("%lld%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}

string sa;

int main(){
	int n,m;
	int i,j,k;
	int a,b,c;
	cin>>sa;
	if(sa=="SUN")a=7;
	if(sa=="MON")a=6;
	if(sa=="TUE")a=5;
	if(sa=="WED")a=4;
	if(sa=="THU")a=3;
	if(sa=="FRI")a=2;
	if(sa=="SAT")a=1;
	cout<<a<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mod 1000000007
#define pb emplace_back
#define dbg(x) cout << x << endl
#define check(k, i, j) ((k>=i) && (k<=j))
#define FAST_IO ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
typedef long long ll;
using namespace std;
int dx[] = {0, -1, 0, 1};
int dy[] = {1, 0, -1, 0};

template<typename T>
void printV(vector<T> v){
    for(int i=0; i<v.size(); i++){
        cout << v[i]%mod << " ";
    }
    cout << endl;
}

template<typename T>
void printA(T arr[], ll n){
    for(int i=0; i<n; i++){
        cout << arr[i] << " ";
    }
    cout << endl;
}

template<typename T>
void printPA(T* arr, ll n){
    for(int i=0; i<n; i++){
        cout << arr[i] << " ";
    }
    cout << endl;
}

// ===================================== //

int main(){

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

    FAST_IO;
    int n;
    cin >> n;
    if(n%1000){
    cout << 1000 - (n%1000) << endl;

    }
    else{
        cout << 0 << endl;
    }
    return 0;
}


Measured memory_bytes: 3644
import sys
import numba
import numpy as np
S = sys.stdin.buffer.readline().decode('utf-8').rstrip()
S = np.array([int(d) for d in S[::-1]], dtype=np.int32)

@numba.njit(numba.i8(numba.typeof(S)), cache=True)
def solve(S):
	M = 2019
	t = 1
	ans = 0
	c = np.zeros(M, dtype=np.int64)
	c[0] = 1
	r = 0
	for d in S:
		r = (d * t + r) % M
		ans += c[r]
		c[r] += 1
		t = t * 10 % M
	return ans

print(solve(S))

Measured memory_bytes: 107108
#include<cstdio>
#include<cstring>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> PP;
#define F first
#define S second
PP K[11111];
int L;
int n;
int dp[11111];
int next(int l){
  int st=0,ed=n;
  int ret = -1;
  if( l > L ) return -1;
  while( st<=ed ){
    int h = (st+ed)/2;
    if( K[h].F > l ){
      ed=h-1;
      ret = h;
    }
    else if(K[h].F < l )
      st = h+1;
    else
      return h;
  }
  if( ret == -1 ){
    return n;
  }
  return ret;
}
int solve(int id){
  if( dp[id] != -1 ) return dp[id];
  if( id == n ) return 0;
  int nel = K[id].F+K[id].S.F;
  int nex = next(nel);
  int res;
  if( nex == -1 || nex == id){
    res = solve(id+1)+(K[id+1].F - K[id].F);
  } else {
    res = min( solve(id+1)+(K[id+1].F - K[id].F),
	       solve(nex)+(K[nex].F - nel) +  K[id].S.S);
  }
  // printf("%d - %d = %d\n",K[nex].F,nel,K[nex].F-nel);
  // printf("%d %d  %d\n",id,K[id].F,res);
  return dp[id] = res;
}

int main(){
  cin >> L >> n;
  memset(dp,-1,sizeof(dp));
  for(int i=0;i<n;i++){
    int p,d,t;
    cin >> K[i].F >> K[i].S.F >> K[i].S.S;
  }
  sort(K,K+n);
  K[n].F = L;
  cout << solve(0)+K[0].F << endl;

}


Measured memory_bytes: 1404
w,h,n=map(int,input().split())
wl,wr,hu,hl=0,w,h,0
for i in range(n):
  x,y,a=map(int,input().split())
  if a==1:
    wl=max(x,wl)
  elif a==2:
    wr=min(x,wr)
  elif a==3:
    hl=max(y,hl)
  else:
    hu=min(y,hu)
print(0 if wr<=wl or hu<=hl else (wr-wl)*(hu-hl))

Measured memory_bytes: 3064
imports System.Collections.Generic
module ABC085B
	sub Main(ByVal args() as String)
		dim n,i as integer
		dim m as new Dictionary(of integer,integer)
		'HashSetは.Net3.5以降のため使えません
		n=Console.ReadLine()
		for i=1 to n
			m(Console.ReadLine())=1
		next
		Console.WriteLine(m.Count)
	end sub
end module


Measured memory_bytes: 13268
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std;
int n, a, b, c[100005];
int sum, s;
int main()
{
	while(~scanf("%d %d %d", &n, &a, &b))
	{
		if(a > b) swap(a,b);
		int t = 0;
		s = 0;
			for(int i = 1;i <= n;i++){
				sum = 0;
				int k = i;
				while(k)
				{
					int h = k % 10;
			//		printf("%d %d\n",i, h);
					k = k / 10;
			//		printf("%d %d\n",i, k);
					sum = sum + h;
				}
				 if(sum <= b && sum >= a)
				{
				t = t + 1;
					c[t] = i;
				//	printf("%d %d\n",c[t],i);
					s = s + i;
				}
			}
			printf("%d\n",s);
	}
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var (
		n   int
		num int
	)
	fmt.Scan(&n)
	h := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&h[i])
	}

	num = 1
	for i := 1; i < n; i++ {
		result := true
		for j := 0; j < i; j++ {
			if h[i] < h[j] {
				result = false
			}
		}
		if result {
			num++
		}
	}
	fmt.Println(num)
}


Measured memory_bytes: 512
#include<stdio.h>
main(){
  int n,m,i,j;
  int a[100][100],b[100],c[100]={};
  scanf("%d%d",&n,&m);
  for(i=0;i<n;i++){
    for(j=0;j<m;j++){
      scanf("%d",&a[i][j]);
    }
  }
  for(i=0;i<m;i++){
    scanf("%d",&b[i]);
  }
  for(i=0;i<n;i++){
    for(j=0;j<m;j++){
      c[i]+=a[i][j]*b[j];
    }
    printf("%d\n",c[i]);
  }
  return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define ll long long
#define ulli unsigned long long int
#define ld long double  
#define endl "\n"
using namespace std; 

void solve() {
    int n;
    cin >> n;
    vector<int> nums(n);

    for (int &x: nums) {
        cin >> x;
    }

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

    double temp = nums[0];
    for (int i = 1; i < n; i++) {
        temp = (nums[i] + temp) / 2; 
    }

    cout << temp << endl;
}

int main() 
{ 
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL); 
  
    int t = 1; 
    //cin >> t; 
    while (t--) { 
        solve(); 
    } 
  
    cerr << "time taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << endl; 
    return 0; 
} 


Measured memory_bytes: 256
import heapq
N,K = map(int, input().split())
L = [[] for _ in range(N)]
h = []
for _ in range(N):
    t,d = map(int, input().split())
    L[t-1].append(d)
    heapq.heappush(h, (-d, t-1))

cnt = 0
for l in L:
    if len(l) > 0:
        cnt += 1

used = [0]*N
h1 = []
h2 = []
num = 0
if K <= cnt:
    while len(h2) < K:
        temp = heapq.heappop(h)
        if used[temp[1]] > 0:
            heapq.heappush(h1, temp)
            continue
        used[temp[1]] += 1
        heapq.heappush(h2, (-temp[0], temp[1]))
        num -= temp[0]
else:
    c2 = 0
    while len(h2) < K:
        temp = heapq.heappop(h)
        if used[temp[1]] > 0:
            if c2 < K-cnt:
                c2 += 1
            else:
                heapq.heappush(h1, temp)
                continue
        used[temp[1]] += 1
        heapq.heappush(h2, (-temp[0], temp[1]))
        num -= temp[0]

cnt = min(K, cnt)
ans = num + cnt**2
while len(h1) > 0 and h2[0][0] < -h1[0][0]:
    t1 = heapq.heappop(h1)
    t2 = heapq.heappop(h2)
    used[t2[1]] -= 1
    used[t1[1]] += 1
    if used[t2[1]] == 0:
        cnt -= 1
    if used[t1[1]] == 1:
        cnt += 1
    num += -t1[0]-t2[0]
    ans = max(ans, num+cnt**2)
    heapq.heappush(h2, (-t1[0], t1[1]))

print(ans)

Measured memory_bytes: 87712
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using ll = long long;
using P = pair<int, int>;
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 {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res*=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 {
        mint res(*this);
        return res/=a;
    }
};

mint da[200005];

int main(){
    int n, k;
    cin >> n >> k;
    mint ans(0);

    for (int i=k; i>=1; i--) {
        int num = k/i;
        mint now;
        now = mint(num).pow(n);
        
        for (int j=2*i; j<=k; j+=i) {
            now -= da[j];
        }
        da[i] = now;
        now *= i;
        ans += now;
    }
    
    
    
    cout << ans.x << endl;
    return 0;
}


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

int main(void) {
    int c1, c5, c10, c50, c100, c500;
    cin >> c1 >> c5 >> c10 >> c50 >> c100 >> c500;
    if (((c1*1) + (c5*5) + (c10*10) + (c50*50) + (c100*100) + (c500*500)) < 1000) {
        cout << "0" << endl;
    }
    else {
        cout << "1" << endl;
    }
}


Measured memory_bytes: 3104
#include<iostream>
#include<string>
#define REP(i,n) for(int i=0;i<(n);++i)
using namespace std;

int main(){
	string s[3];
	REP(i,3) cin>>s[i];
	
	int turn=0;
	int num[3]={};
	while(1){
		if(num[turn]<s[turn].size()){
			turn=s[turn][num[turn]++]-'a';//Point.
		}else{
			cout<<char('A'+turn)<<endl;
			return 0;
		}
	}
}//解答解説参考.

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 2e9;
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> h(n);
  rep(i, n) cin >> h[i];
  vector<int> dp(n, INF);
  dp[0] = 0;
  rep(i, n) {
    for (int j = 1; j <= k; j++)
      dp[i + j] = min(dp[i + j], abs(h[i + j] - h[i]) + dp[i]);
  }
  cout << dp[n - 1] << endl;
  return 0;
}

Measured memory_bytes: 1024
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//ここから編集する
class Solve {
public:
    void input() {

    }

    void solve() {
        input();
        int N;
        cin >> N;
        ll K;
        cin >> K;

        vector<ll> A(N);
        rep(i, 0, N) cin >> A[i];

        ll X = 0ll;
        for (int bit = 60; bit >= 0; bit--) {
            ll mask = 1ll << bit;
            ll kouho = X | mask;
            if (kouho > K) continue;

            ll tapi = 0;
            ll tapu = 0;

            for (int i = 0; i < N; ++i) {
                if (A[i] >> bit & 1) {
                    tapu++;
                } else {
                    tapi++;
                }
            }

            if (tapi > tapu) {
                X = kouho;
            }
        }

        ll ans = 0ll;
        for (int i = 0; i < N; ++i) {
            ll tmp = A[i] ^X;
            ans += tmp;
        }
        cout << ans << endl;

    }
};


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

    Solve().solve();


    return 0;
}


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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

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

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

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v)is >> e;
  return is;
}

inline void YN(const bool f, string y = "Yes", string n = "No"){
  if(f) cout << y << endl;
  else cout << n << endl;
}

int main(){
  int h,n; cin >> h >> n;
  ll s=0,x=0;
  for(int i = 0; i < n; ++i)cin >> x, s += x;
  YN(s >= h);
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<queue>
#include<cmath>
#include <numeric>
#include<iomanip>
#include <cstdint>
#include<deque>
#include<stdio.h>
typedef long long ll;

using namespace std;

int main() {
	int n;
	string s, t;
	cin >> n >> s >> t;
	string ans="";
	for (int i = 0; i < n; i++) {
		ans += s[i];
		ans += t[i];
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <numeric>
using namespace std;
using ll = long long;

int main() {
    vector<int> A(3);
    for (auto& a : A) cin >> a;
    cout << min(min(A[0] + A[1], A[1] + A[2]), A[2] + A[0]) << endl;
}


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

#define ll long long
#define ull unsigned long long

using namespace std;

int main() {
	ll X, Y, Z, K;
	cin >> X >> Y >> Z >> K;

	vector <ll> th(3);
	th[0] = X; 	th[1] = Y; 	th[2] = Z;

	vector <ll> A(X);
	for (int ii = 0; ii < X; ++ii) cin >> A[ii];
	vector <ll> B(Y);
	for (int ii = 0; ii < Y; ++ii) cin >> B[ii];
	vector <ll> C(Z);
	for (int ii = 0; ii < Z; ++ii) cin >> C[ii];
	sort(A.rbegin(), A.rend());
	sort(B.rbegin(), B.rend());
	sort(C.rbegin(), C.rend());

	vector < pair<ll, ll> > v;
	ll cA = 1000000;
	ll cB = 1000;
	ll cC = 1;
	ll pval = A[0] + B[0] + C[0];
	ll pidx = cA*0 + cB*0 + cC*0;
	v.push_back(make_pair(pval, pidx));

	map<ll, ll> m;
	map<ll, ll> mm;
	mm[pidx] = 1;

	for (int cnt = 0; cnt < K; ++cnt){
		pair<ll, ll> tmp = v.back();
		v.pop_back();

		ll val = tmp.first;
		ll idx = tmp.second;
		if (m[idx] == 0) cout << val << "\n";

		m[idx] = 1;

		vector <ll> tidx(3);
		tidx[0] = idx / cA;
		tidx[1] = (idx - cA*tidx[0]) / cB;
		tidx[2] = idx - cA*tidx[0] - cB*tidx[1];
		for (int ii = 0; ii < 3; ++ii){
			if (tidx[ii] + 1 == th[ii]) continue;
			tidx[ii]++;
			ll val = A[tidx[0]] + B[tidx[1]] + C[tidx[2]];
			ll idx = cA*tidx[0] + cB*tidx[1] + cC*tidx[2];
			if (mm[idx] == 0){
				v.push_back(make_pair(val, idx));
				mm[idx] = 1;
			}
			tidx[ii]--;
		}

		sort(v.begin(), v.end());
	}

	return 0;
}


Measured memory_bytes: 4228
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repI(i, d, n) for (int i = (d); i < (n); ++i)
#define reps1(i, n) for (int i = 1; i < (n); ++i)
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; }

using ll = long long;
using P = pair<int, int>;
using Pl = pair<ll, ll>;
using M = map<int, int>;
ll const INF = 1ll<<61;
double pi = 3.141592653589793238;
ll n, m, x;
vector<vector<ll>> a;
vector<ll> cost;
ll ans = INF;

int main() {

  cin >> n >> m >> x;
  a.assign(n, vector<ll>(m));
  cost.resize(n);

  rep(i, n) {
    cin >> cost[i];
    rep(j, m) cin >> a[i][j];
  }

  rep(i, 1<<n) {
    vector<int> d(n);
    rep(j, n) if (i>>j&1) {
      d[j] = 1;
    }
    vector<ll> score(m, 0);
    ll money = 0;

    rep(i, n) {
      if (d[i] == 1) {
        rep(j, m) score[j] += a[i][j];
        money += cost[i];
      }
    }

    bool flg = true;
    rep(i, m) {
      if (score[i] < x) flg = false;
    }
    if (flg) chmin(ans, money);
  }

  if (ans == INF) cout << -1 << endl;
  else cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3640
using System;
 
class TempMatch
{
	static public void Main(string[] args)
	{
		string[] vals = Console.ReadLine().Split(' ');
		int N = int.Parse(vals[0]);
		int M = int.Parse(vals[1]);
		string[] A = new string[N];
		string[] B = new string[M];
 
		for(int i=0; i<N; i++)
			A[i] = Console.ReadLine();
		for(int i=0; i<M; i++)
			B[i] = Console.ReadLine();
		for(int y=0; y<=N-M; y++)
		{
			for(int x=0; x<=N-M; x++)
			{
				bool match = true;
				for(int j=0; j<M; j++)
				{
					for(int i=0; i<M; i++)
					{
						if(A[y+j][x+i] != B[j][i])
						{
							match = false;
							break;
						}
					}
				}
				if(match)
				{
					Console.WriteLine("Yes");
					return;
				}
			}
		}
		Console.WriteLine("No");
 
	}
}

Measured memory_bytes: 2648
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int[][] A = new int[3][3];
		boolean[][] R = new boolean[3][3];
		for(int i = 0; i < 3; i++) {
			for(int j = 0; j < 3; j++) {
				A[i][j] = sc.nextInt();
				R[i][j] = false;
			}
		}
		int N = sc.nextInt();
		boolean r = false;
		for(int b = 0; b < N; b++) {
			int B = sc.nextInt();
			for(int i = 0; i < 3; i++) {
				for(int j = 0; j < 3; j++) {
					if(B == A[i][j]) R[i][j] = true;
				}
				if(R[i][0] && R[i][1] && R[i][2]) {
					r = true;
					break;
				}
			}
		}
		sc.close();
		for(int j = 0; j < 3; j++) {
			if(R[0][j] && R[1][j] && R[2][j]) {
				r = true;
				break;
			}
		}
		if(R[0][0] && R[1][1] && R[2][2]) r = true;
		if(R[0][2] && R[1][1] && R[2][0]) r = true;
		
		System.out.println(r?"Yes":"No");
	}
}


Measured memory_bytes: 21844
#include <stdio.h>
 
int main(void){
 int x,sum=0,a;
 scanf("%d",&x);
  a=x;
 while(a){
  sum+=a%10;
  a=a/10;
}
if(x%sum==0){
	printf("Yes");
}else{
	printf("No");
}
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
typedef long long LL;
const int N = 1005;
const int M = 301;
int n,m;
char s[N];
int main()
{
    while (cin>>s)
    {
        int l=strlen(s);
        int f=0;
        for (int i=0;i<l/2;i++)
        {
            if (s[i]!=s[l-1-i])
            {
                f=1;
                break;
            }
        }
        if (f)
            printf("No\n");
        else
            printf("Yes\n");
    }
    return 0;
}

/*

*/

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int N,X;cin>>N>>X;int u=0;
  vector<int> v(N);for(int i=0;i<N;i++)cin>>v[i];
  for(int j=0;j<N;j++){if(X<v[j]){v[j]=v[j]-X;}else{v[j]=X-v[j];}}
  if(N==1){cout<<v[0]<<endl;}
  else{
  for(int j=0;j<N;j++){u=__gcd(u,v[j]);}
  cout<<u<<endl;}}

Measured memory_bytes: 640
hutamoji_list=[[None]*11 for i in range(3)]#35,37,57の順
def hutamoji(keta,one,two):
    global hutamoji_list
    if one*two==15:
        index=0
    elif one*two==21:
        index=1
    else:
        index=2
    if hutamoji_list[index][keta]!=None:
        return hutamoji_list[index][keta]
    ans=[]
    if keta==1:
        return ans
    for each in hutamoji(keta-1,one,two):
        ans.append(one*(10**(keta-1))+each)
        ans.append(two * (10 ** (keta - 1)) + each)
    for i in [one,two]:
        for j in [one,two]:
            if i!=j:
                ans.append(i*(10**(keta-1))+int(str(j)*(keta-1)))
    ans.sort()
    hutamoji_list[index][keta]=ans

    return ans


def sannmoji(keta):
    hitigosan=[3,5,7]
    ans=[]
    if keta<=2:
        return ans
    for each in sannmoji(keta-1):
        for i in [3,5,7]:
            ans.append(i*(10**(keta-1))+each)
    for one,two,three in [[3,5,7],[5,3,7],[7,3,5]]:
        hutas=hutamoji(keta-1,two,three)
        for huta in hutas:
            ans.append(one*(10**(keta-1))+huta)
    ans.sort()
    return ans


sannmoji(10)
n=input()
keta=len(n)
n=int(n)
ans=0
for i in range(1,keta):
    ans+=len(sannmoji(i))

for i in sannmoji(keta):
    if i <=n:
        ans+=1
    else:
        break
print(ans)

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

using namespace std;

int main(int argc, char const *argv[])
{
    int n;
    cin >> n;

    if (n % 10 == 3)
    {
        cout << "bon" << endl;
    }
    else if (n % 10 == 2 || n % 10 == 4 || n % 10 == 5 || n % 10 == 7 || n % 10 == 9)
    {
        cout << "hon" << endl;
    }
    else if (n % 10 == 0 || n % 10 == 1 || n % 10 == 6 || n % 10 == 8)
    {
        cout << "pon" << endl;
    }
    return 0;
}


Measured memory_bytes: 3132
use std::vec::Vec;
use std::cmp::min;

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 read_touple<T: std::str::FromStr + Copy>() -> (T, T) {
  let v: Vec<T> = read_vec();
  assert_eq!(v.len(), 2);
  (v[0], v[1])
}

fn main() {
    let n: usize = read();
    let mut x: Vec<i64> = read_vec();
    x.sort();

    let mn = x[0];
    let mx = x[n-1];
    let mut ans = 1_000_000_000;

    for p in mn..mx+1 {
      let mut sum = 0;
      for e in &x {
        sum += (e - p) * (e - p);
      }

      ans = min(ans, sum);
    }

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


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

#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
using ll = long long;

const int maxn=3005;
double dp[maxn][maxn];

signed main() {
  int n; cin>>n;
  vector<double> ps(n+1);
  reps(i,n) cin>>ps[i];
  dp[0][0]=1;
  reps(i,n){
    dp[i][0]=dp[i-1][0]*(1-ps[i]);
    reps(j,i){
      dp[i][j]=dp[i-1][j-1]*ps[i]+dp[i-1][j]*(1-ps[i]);
    }
  }
  double ans=0;
  int half=(n+1)/2;
  for(int i=half; i<=n; i++){
    ans+=dp[n][i];
  }
  
  cout<<std::setprecision(10)<<ans<<endl;
}


Measured memory_bytes: 68992
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
string s;
long long k;
int main()
{
	cin>>s>>k;
	if(k==1)
		printf("%c",s[0]);
	else{
		int i=0;
		while(s[i]=='1'){
			i++;	k--;
			if(k==0){
				i--;break;
			}
			  	
		}
		if(i==s.size())
			i=s.size()-1;
			printf("%c",s[i]);
	}
	
	
	return 0;
}

Measured memory_bytes: 256
/**
 * @author: pr4shan7 (प्रशांत)
 */
// #define _DEBUG

#ifndef _DEBUG
#define NDEBUG
#endif

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

// #define int long long
// #define double long double

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pb_set;
typedef long long ll;
typedef long double ld;
#define pb push_back
#define endl '\n'
#define x first
#define y second
#define cai static_cast<int>
#define cal static_cast<long long>
#define cad static_cast<long double>
#define deb(z) cout << "// " << #z << " = " << z << endl;
const int N = 1e5 + 5;
const int INF = 1e9;
const int MV = 1e9 + 7;



int32_t main() {
	ios_base::sync_with_stdio(false);
	// cin.tie(NULL);

#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	string s; cin >> s;
	for (int i = 0; i < s.length(); ++i)
	{
		cout << 'x';
	}
	cout  << endl;

	return 0;
}


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

int main(){
    int n;
    cin >> n;
    string s;
    cin >> s;
    int ans=1;
    for (int i = 0; i < n-1; i++){
        if(s[i] != s[i+1]) ++ans;
    }
    cout << ans <<endl;
    return 0;
}

Measured memory_bytes: 512
#include "bits/stdc++.h"

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ld,int> P;
constexpr ld pi = acos(-1.0);

// gcd(a, b)
ll gcd(ll a, ll b) {
    if (b == 0) return a;
    return gcd(b, a%b);
}

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

    int t;cin>>t;
    while(t--){
      // 始め, 消費, 閾値, 供給
      ll a,b,c,d;cin>>a>>b>>c>>d;
      if(b>a){
        cout<<"No"<<endl;
        continue;
      }
      if(b>d){
        cout<<"No"<<endl;
        continue;
      }
      if(c>=b){
        cout<<"Yes"<<endl;
        continue;
      }
      // b<=a, b<=d, c<b
      ll g=gcd(b,d);
      if(b-g+(a%g)>c) cout<<"No"<<endl;
      else cout<<"Yes"<<endl;
    }
}


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

int main(){
  string s, t; cin >> s >> t;
  map<char, set<int>> mp;
  vector<vector<int>> v(26);
  rep(i,s.size()){
    v[s[i] - 'a'].push_back(i);
  }
  int id = -1;
  ll ans = 0;
  rep(i,t.size()){
    int x = t[i] - 'a';
    if(v[x].size() == 0){
      cout << -1 << endl;
      return 0;
    }
    auto it = upper_bound(v[x].begin(), v[x].end(), id);
    if(it == v[x].end()){
      ans += s.size();
      id = *(v[x].begin());
    }
    else{
      id = *it;
    }
  }
  ans += id + 1;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4204
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,m;
	cin>>n>>m;
	int a[n+1],b[n+1] ;
	vector<vector<int> > v(4);
	for(int i=1;i<=m;i++)
	{
		cin>>a[i]>>b[i] ;
		if(a[i]==1 && b[i]==0 && n!=1) 
		{
			cout<<"-1\n";return 0;
		}
		v[a[i]].push_back(b[i]);
	}
	for(int i=1;i<=3;i++)
	{
		if(v[i].size())
		{
			int x=v[i][0],count=1;
			for(int j=0;j<v[i].size();j++)
			{
				if(v[i][j]!=x) 
				{
					cout<<"-1\n"; return 0;
				}
			}
		}
	}
	if(m==0 && n==1)
	{
		cout<<"0\n"; 
	}
	else if(v[1].size()==0 ) cout<<1;
	else cout<<v[1][0];
	for(int i=2;i<=n;i++)
	{
		if(v[i].size()==0) cout<<0;
		else cout<<v[i][0];
	}
	cout<<"\n";
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#define int long long
using namespace std;

int n, m;
int c[16];
int x[20000];
int dp[20001][256];

signed main() {
	int i, j, k;
	
	while (cin >> n >> m) {
		if (!n) break;
		for (i = 0; i < m; i++) cin >> c[i];
		for (i = 0; i < n; i++) cin >> x[i];
		for (i = 0; i <= n; i++) for (j = 0; j < 256; j++) dp[i][j] = 1145141919810;
		
		dp[0][128] = 0;
		for (i = 0; i < n; i++) {
			for (j = 0; j < 256; j++) {
				for (k = 0; k < m; k++) {
					int ny = max(0LL, min(255LL, j + c[k]));
					dp[i + 1][ny] = min(dp[i + 1][ny], dp[i][j] + (x[i] - ny) * (x[i] - ny));
				}
			}
		}
		
		int ans = 1145141919810;
		for (i = 0; i < 256; i++) ans = min(ans, dp[n][i]);
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 43240
s = input()
t = input()
n, m = len(s), len(t)

for i in range(n - m, -1, -1):
    match = True
    for j in range(m):
        if s[i + j] == '?' or s[i + j] == t[j]:
            continue
        else:
            match = False
            break

    if match:
        ans = ""
        for j in range(i):
            if s[j] == '?':
                ans += 'a'
            else:
                ans += s[j]
        ans += t
        for j in range(i + m, n):
            if s[j] == '?':
                ans += 'a'
            else:
                ans += s[j]
        print(ans)
        exit()
print("UNRESTORABLE")


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

int main(){

    int N, Q; cin >> N >> Q;
    char str[N+10]; cin >> str;

    int l[Q], r[Q];
    for(int i = 0; i < Q; i+=1){cin >> l[i] >> r[i];}

    int cnt[N+1];
    cnt[0] = 0;
    cnt[1] = 0;
    for(int i = 2; i < N+1; i+=1){
        if(str[i-2] == 'A' && str[i-1] == 'C'){
            cnt[i] = cnt[i-1] + 1;
        }else{
            cnt[i] = cnt[i-1];
        }

        //cout << "cnt[" <<  i  << "] = " << cnt[i] << endl;
    }

    for(int i = 0; i < Q; i += 1){
        cout << cnt[r[i]] - cnt[l[i]] << endl;
    }
}

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

int main() {
  int n;
  cin >> n;
  map<int, int> mp;
  rep(i,n){
    int a;
    cin >> a;
    mp[a]++;
  }
  int m;
  cin >> m;
  rep(i,m){
    int b;
    cin >> b;
    if (mp[b] <= 0){
      cout << "NO" << endl;
      return 0;
    }
    mp[b]--;
  }
  cout << "YES" << endl;
}

Measured memory_bytes: 9600
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        long n = in.nextLong();

        int min = Integer.MAX_VALUE;
        for (int p = 1; p < Math.sqrt(n) + 1; p++) {
            if (n % p == 0) {
                long q = n / p;

                int f = Math.max(digits(p), digits(q));
                min = Math.min(min, f);
            }
        }

        System.out.println(min);
    }

    static int digits(long n) {
        int count = 0;
        while (n > 0) {
            count++;
            n /= 10;
        }
        return count;
    }
}


Measured memory_bytes: 21972
N = int(input())
A = list(map(int, input().split()))
mod = 10 ** 9 + 7

# 重複している要素Xを探す
X_search_set = set()
for a in A:
    if a in X_search_set:
        X = a
        break
    else:
        X_search_set.add(a)

# 重複している要素のindexを取得
x_left, x_right = [i for i, a in enumerate(A) if a == X]

# 重複している要素の左側・右側にそれぞれ何個あるか
Left, Right = x_left, N - x_right

# 階乗 & 逆元計算
factorial = [1]
inverse = [1]
for i in range(1, N+2):
    factorial.append(factorial[-1] * i % mod)
    inverse.append(pow(factorial[-1], mod-2, mod))


# 組み合わせ計算
def nCr(n, r):
    if n < r or r < 0:
        return 0
    elif r == 0:
        return 1
    return factorial[n] * inverse[r] * inverse[n - r] % mod


# 計算・出力
for k in range(1, len(A) + 1):
    ans = nCr(len(A), k)

    # 重複部分を引く
    if k - 1 <= Left + Right:
        ans -= nCr(Left + Right, k - 1)

    print(ans % mod)


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

int main(){
	int n,a,b,c,d,count;
	while(scanf("%d",&n)==1){
	count = 0;
	for(a=0;a<10;a++){
		for(b=0;b<10;b++){
			for(c=0;c<10;c++){
				for(d=0;d<10;d++){
					if(a+b+c+d == n) count = count + 1;
				}
			}
		}
	}
	printf("%d\n",count);
	}
	return 0;
}

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

int main(){

    int N;
    cin >> N;
    string ans = "No";
    for (int i = 1; i < 10; i++) {
        bool flg = false;
        for(int j=i;j<10;j++){
            if(N == i*j){
                ans = "Yes";
                flg = true;
                break;
            }
        }
        if(flg){
            break;
        }
    }

    cout << ans << endl;

}


Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
int main(){
  int n,i,s;
  double a,m,heikin,heikin2,heikin22,s2,total=0,total2=0,result;
  while(1){
    scanf("%d",&n);
    if(n==0) break;
    else{
      for(i=1;i<=n;i++){
	scanf("%d",&s);
	total+=s;
	s2=s*s;
	total2+=s2;
      }
      heikin=total/n;
      
      heikin2=heikin*heikin;
      
      heikin22=total2/n;
     
      a=heikin22-heikin2;
     
      result=sqrt(a);
      printf("%f\n",result);
      total=0;
      total2=0;
    }
  }
  return 0;
}

Measured memory_bytes: 1060
#define  _USE_MATH_DEFINES

#define  rep(i, n) for(int i = 0; i < n; i++)
#define  repx(i, a, n) for(int i = a; i < n; i++)
#define  loop while(1)
#define  lli long long int
 
#include <iostream>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <utility>
#include <set>

using namespace std;

int main() {

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

  vector<int> cnt(n + 1, 0);
  int l, r;
  rep (i, m) {
    cin >> l >> r;
    repx(j, l, r) cnt[j] += 1;
  }
  
  int ans = 0;
  rep (i, n + 1) {
    if (cnt[i] > 0) ans += 3;
    else ans += 1;
  }
  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 3112
#include <iostream>
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <iomanip>
#include <string>
#include <queue>
#include <numeric>
#include <functional>
#include <array>
#include <map>
#include <set>

#define INF 1000000007 //1000000000000000003
#define MOD 1000000007
#define MAX 2000005

#define ll long long

//printf("%.10f", );
//cout << fixed << setprecision(10) << heikin << endl;
//vector<vector<int>> data(3, vector<int>(4, -1));
//left + 1 < top

using namespace std;
using P = pair<int, int>;
using Pc = pair<double, int>;
using T = tuple<int, int, int>;
using edge = struct { int to; long long dist; };
const double PI = 3.141592653589793;
long long fact[MAX], inv[MAX];
int dx[] = { -1,0,1,0 };
int dy[] = { 0,-1,0,1 };

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

vector<vector<int>> tree(100005);
int color[100005];
map<P, int>colorMap;
int m = 0;

struct BridgeInfo {
	int town1;
	int town2;
	int year;
	BridgeInfo(int t1, int t2, int y) {
		town1 = t1;
		town2 = t2;
		year = y;
	}
};

struct People {
	int index;
	int town;
	int year;
	People(int i, int t, int y) {
		index = i;
		town = t;
		year = y;
	}
};

bool compare_by_second(pair<int, int> a, pair<int, int> b) {
	if (a.second != b.second) {
		return a.second < b.second;
	}
	else {
		return a.first < b.first;
	}
}

struct UnionFind {
	vector<int>uf;
	
	UnionFind(int size) :uf(size, -1) {};

	int root(int target) {
		if (uf[target] < 0)return target;
		else return uf[target] = root(uf[target]);
	}

	void merge(int a, int b) {
		a = root(a);
		b = root(b);
		if (a == b)return;
		if (uf[b] < uf[a])swap(a, b);
		uf[a] += uf[b];
		uf[b] = a;
	}
};

ll CalcPow(ll num, ll power) {
	if (power == 0)return 1;
	if (power % 2 == 0) {
		ll half = CalcPow(num, power / 2);
		return (half * half) % MOD;
	}
	else return (num * CalcPow(num, power - 1)) % MOD;
}

ll combination(ll all, ll select) {
	if (all < select) return 0;
	if (all < 0 || select < 0) return 0;
	return fact[all] * (inv[select] * inv[all - select] % MOD) % MOD;
}

void initCombination(int max) {
	fact[0] = fact[1] = 1;
	for (int i = 2; i <= max; ++i) {
		fact[i] = fact[i-1] * i % MOD;
	}

	inv[max] = CalcPow(fact[max], MOD - 2);
	for (int i = max - 1; 0 <= i; --i) {
		inv[i] = (inv[i + 1] * (i + 1)) % MOD;
	}
}

void dfs(int from) {
	int c = 1;
	for (auto t : tree[from]) {
		c = c != color[from] ? c : c + 1;
		color[t] = c;
		colorMap[make_pair(from, t)] = c;
		m = max(c, m);
		dfs(t);
		c++;
	}
}

int dp[105][4][2];

int main() {
	vector<int>abc(3);
	for (int i = 0; i < 3;++i) {
		cin >> abc[i];
	}
	sort(abc.begin(),abc.end());
	int before = abc[0];
	int sameCount = 1;
	for (int i= 1; i < 3;++i) {
		if (before == abc[i])sameCount++;
		before = abc[i];
	}
	string ans = sameCount == 2 ? "Yes" : "No";
	cout  << ans << endl;
}



Measured memory_bytes: 2560
#include<stdio.h>

#define MAX 500000
#define INFTY 2000000000

int g_count;

void merge(int [], int, int, int);
void mergeSort(int [], int, int);

int main(){
  int A[MAX], n, i;
  
  scanf("%d",&n);
  for(i = 0; i < n; i++) scanf("%d",&A[i]);

  mergeSort(A,0,n);

  for(i = 0; i < n; i++){
    if(i != 0) printf(" ");
    printf("%d",A[i]);
  }

  printf("\n");

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

void merge(int A[], int left, int mid, int right){
  int n1, n2,i,j,k;
  int L[MAX/2+2],R[MAX/2+2];

  n1 = mid - left;
  n2 = right - mid;
  for(i = 0; i < n1; i++) L[i] = A[left + i];
  for(i = 0; i < n2; i++) R[i] = A[mid+i];
  L[n1] = R[n2] = INFTY;

  i = 0;
  j = 0;
  for(k = left; k < right; k++){
    g_count++;
    if(L[i] <= R[j]) A[k] = L[i++];
    else A[k] = R[j++];
  }
}

void mergeSort(int A[], int left, int right){
  if(left+1 < right){
    int mid = (left + right) / 2;
    mergeSort(A, left, mid);
    mergeSort(A, mid, right);
    merge(A ,left, mid, right);
  }
}




Measured memory_bytes: 5644
//url:
//problem name: 

#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); ++i)
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;}
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<long long,long long>;
using veci = vector<int>;
using vecl = vector<long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;

int main() {
    int N;
    cin >> N;
    veci V(N);
    set<int> odd;
    set<int> even;
    map<int,int> mp_odd;
    map<int,int> mp_even;
    REP(i,N) {
        cin >> V[i];
        if(i%2 == 0) {
            even.insert(V[i]);
            if(mp_even.count(V[i])) mp_even[V[i]]++;
            else mp_even[V[i]] = 1;
        }
        else {
            odd.insert(V[i]);
            if(mp_odd.count(V[i])) mp_odd[V[i]]++;
            else mp_odd[V[i]] = 1;
        }
    }

    vector<P> vec_even;
    vector<P> vec_odd;

    for(auto ret:mp_even) vec_even.push_back(P(ret.second,ret.first));
    for(auto ret:mp_odd) vec_odd.push_back(P(ret.second,ret.first));

    sort(vec_even.begin(),vec_even.end(),greater<P>());
    sort(vec_odd.begin(),vec_odd.end(),greater<P>());

    ll ans = 0;
    //cout << even.size() << " " << odd.size()<<endl;
    if(even.size() == 1 && odd.size() == 1) {
        for(int v: even) for(int w:odd) if(v == w) ans = N/2; else ans = 0;
    }
    if(even.size() == 1 && odd.size() > 1) {
        int v = vec_even[0].second;
        int w = vec_odd[0].second;
        if(v != w) ans = N/2-vec_odd[0].first;
        else ans = N/2 - vec_odd[1].first;
    } else if(even.size() > 1 && odd.size() == 1) {
        int v = vec_even[0].second;
        int w = vec_odd[0].second;
        if(v != w) ans = N/2-vec_even[0].first;
        else ans = N/2 - vec_even[1].first;
    } else if(even.size() > 1 && odd.size() > 1){
        int v = vec_even[0].second;
        int w = vec_odd[0].second;
        if(v != w) ans = N/2-vec_even[0].first + N/2-vec_odd[0].first;
        else ans = min(N-vec_even[0].first-vec_odd[1].first,N-vec_even[1].first-vec_odd[0].first);
    }

    cout << ans << endl;
}


Measured memory_bytes: 11132
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	int a,b,c;
	cin>>a>>b>>c;

        int i=min(a,b);
        for(;;i--)
        {
            if(a%i==0&&b%i==0)
            {
                if(c==1)
                {
                    cout<<i<<endl;
                    break;
                }
                c--;
            }
        }

	return 0;
}


Measured memory_bytes: 256