akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class MainClass
{
	public const long Giri = 1000000007;
	public const long DpInf = 99999999999999;
	
	
	public static void Main(string[] args)
	{
 		var n = Console.ReadLine().ToInt();
		var ai = Input();
		var a = new long[n];
		for(int i = 0; i < n; i++)
		{
			a[i] = ai[i].ToLong()-1;
		}
		var map = new long[n];
		long max = 0;
		for(int i = 0; i < n; i++)
		{
			map[a[i]]++;
			max = Math.Max(max, a[i]);
		}
		max++;
		
		var cs = new long[max];
		long all = 0;
		for(int i = 0; i < max; i++)
		{
			if(map[i] > 1)
			{
				cs[i] = Combination(map[i], 2);
				all += cs[i];
			}
		}
		
		for(int i = 0; i < n; i++)
		{
			long c = 0;
			
			if(cs[a[i]] > 1)
			{
				c = Combination(map[a[i]]-1, 2);
			}
			Console.WriteLine(all - cs[a[i]] + c);
			
		}
		
	}
	
	static long ModPow(long a, long n, long mod)
	{
	    long res = 1;
	    while (n > 0)
	    {
	        if ((n & 1) == 1) res = res * a % mod;
	        a = a * a % mod;
	        n >>= 1;
	    }
	    return res;
	}
	
	//コンビネーション 繰り返し二乗法使うやつ nCk
	static long Combination(long n, long k)
	{
		if(n <= 1)
			return 0;
			
		return n * (n-1) / 2;
	}
	
	static long GCD(long a, long b)
	{
		var v = new[] { a, b };
		while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; }
		return v[0];
	}
	public static string[] Input() { return Console.ReadLine().Split(); }
}

public static class Smarter
{
	public static int ToInt(this string str) { return int.Parse(str); }
	public static long ToLong(this string str) { return long.Parse(str); }
	public static int[] ToInt(this string[] str, int offset = 0)
	{
		var r = new int[str.Length];
		for(int i = 0; i < str.Length; i++) r[i] = str[i].ToInt() + offset;
		return r;
	}
}

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

int main() {
  int a,b,c,d,e,k;
  cin >>a >>b >>c >>d >>e >>k;
  if((e-a)>k){
    cout <<":(" <<endl;
    return 0;
  }
  cout <<"Yay!" <<endl;
  return 0;
}  

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define RREP(i,n) for(int i=n;i>=0;i--)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
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; }
//const ll INF = 1LL << 60;
//const int INF = 1001001001;

int main(void){
    int s,w;
    cin >> s >> w;
    if(s<=w)
        cout << "unsafe";
    else cout << "safe";
    return 0;
}

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

#define rep(i,n) for(ll i=0;i<(n);++i)
using ll = long long;
using pll = pair<ll,ll>;
constexpr ll INF = (1LL<<60);
constexpr ll MOD = (1e9+7);
//constexpr ll MOD = (998244353);
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;}
#if loc||debg||local||debug
void dump(){cerr<<endl;}
template<class T,class... Ts> void dump(T&& h, Ts&&... t){cerr<<h<<", ";dump(forward<Ts>(t)...);}
#else
template<class T,class... Ts> void dump(T&& h, Ts&&... t){}
#endif
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T> ostream &operator<<(ostream& os,vector<T>const& v){for(auto const& vi:v)os<<vi<<" ";return os;}
template<class T>vector<T> vec(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto vec(size_t a, Ts... ts){return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...));}
template<class T>vector<T> _vec(size_t a,T v){return vector<T>(a,v);}
template<class T, class... Ts>auto _vec(size_t a, Ts... ts){return vector<decltype(_vec<T>(ts...))>(a, _vec<T>(ts...));}

int main(){

  int n;
  cin>>n;
  vector<string>s(n);
  vector<ll>t(n);
  rep(i,n){
    cin>>s[i]>>t[i];
  }
  string x;
  cin>>x;
  ll res = 0;
  bool f=false;
  rep(i,n){
    if(f)res+=t[i];
    if(s[i]==x)f=true;
  }
  cout<<(res)<<endl;

}

Measured memory_bytes: 256
//↓template↓

#include "bits/stdc++.h"
using namespace std;
#define Would
#define you
#define all(n)  n.begin(),n.end()
const long long INF = 1e18;
const long long MOD = 1e9 + 7;
const double pi = acos(-1);
const int SIZE = 1 << 17;
int dx[] = { 1,0,-1,0 }, dy[] = { 0,1,0,-1 }, alp[30];
long long fac[200005], finv[200005], inv[200005];
vector<long long>dij;
struct edge { long long to, cost; };
vector<vector<edge> >G;

long long mod_pow(long long a, long long b) {
	long long res = 1, mul = a;
	for (int i = 0; i < 31; ++i) {
		if (b >> i & 1) {
			res *= mul;
			res %= MOD;
		}
		mul = (mul * mul) % MOD;
	}

	return res;
}

void addedge(int from, int to, int cost) {
	G[from].push_back({ to,cost });
	G[to].push_back({ from,cost });
}

//↑template↑


long long n, k[100005], sum;
int main() {
	cin >> n;
	for (int i = 0; i < n; ++i) {
		cin >> k[i]; sum += k[i];
	}
	cout << sum / n << endl;
}


Measured memory_bytes: 3096
#include<stdio.h>

void QSort(long long int x[ ], int left, int right)
{
    int i, j;
    int pivot;

    i = left;                      /* ソートする配列の一番小さい要素の添字 */
    j = right;                     /* ソートする配列の一番大きい要素の添字 */

    pivot = x[(left + right) / 2]; /* 基準値を配列の中央付近にとる */

    while (1) {                    /* 無限ループ */

        while (x[i] < pivot)       /* pivot より大きい値が */
            i++;                   /* 出るまで i を増加させる */

        while (pivot < x[j])       /* pivot より小さい値が */
            j--;                   /*  出るまで j を減少させる */
        if (i >= j)                /* i >= j なら */
            break;                 /* 無限ループから抜ける */

        Swap(x, i, j);             /* x[i] と x[j]を交換 */
        i++;                       /* 次のデータ */
        j--;
    }

    if (left < i - 1)              /* 基準値の左に 2 以上要素があれば */
        QSort(x, left, i - 1);     /* 左の配列を Q ソートする */
    if (j + 1 <  right)            /* 基準値の右に 2 以上要素があれば */
        QSort(x, j + 1, right);    /* 右の配列を Q ソートする */
}

  /* 配列の要素を交換する */
void Swap(long long int x[ ], int i, int j)
{
    long long int temp;

    temp = x[i];
    x[i] = x[j];
    x[j] = temp;
}

int main(){
  int n,i,num,flag=0;
  long long int x[100000],s=1;
  scanf("%d",&n);
  for(i=0;i<n;i++)
    scanf("%lld",&x[i]);
  QSort(x, 0, n - 1);
  for(i=n-1;i>0;i--){
    if(x[i]==x[i-1]){
      flag++;
      i--;
      s*=x[i];
    }
    if(flag==2) break;
  }
  if(flag==2) printf("%lld\n",s);
  else printf("0\n");
}

Measured memory_bytes: 896
#include<stdio.h>
int main(void){
	char s[101] = {'\0'};
	char t[101] = {'\0'};
	scanf("%s", s);
	scanf("%s", t);
	int i = 0;
	int j = 0;
	while(t[j] != '\0'){
		printf("%c", t[j]);
		j++;
	}
	while(s[i] != '\0'){
		printf("%c", s[i]);
		i++;
	}
	printf("\n");
	return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define T top()
#define E end()
#define PS push
#define Q queue
#define PP pop()
#define L0 (LL)0
#define V vector
#define ST stack
#define FI first
#define MAX 4e18
#define MIN -MAX
#define DQ deque
#define RE rend()
#define SZ size()
#define C clear()
#define B begin()
#define F front()
#define SE second
#define DL double
#define G getline
#define IN insert
#define endl "\n"
#define EM empty()
#define EE emplace
#define RB rbegin()
#define MD 1000000007
#define PSB push_back
#define PI acos(-1.00)
#define PPB pop_back()
#define PSF push_front
#define ub upper_bound
#define lb lower_bound
#define PPF pop_front()
#define EB emplace_back
#define LL long long int
#define PQ priority_queue
#define N cout<<"NO"<<endl
#define Y cout<<"YES"<<endl
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define file freopen("input.txt","r",stdin);freopen("output.txt","w",stdout)
#define UOSMOY v.C;w.C;ww.C;uu.C;uo.C;vo.C;vu.C;ab.C;bc.C;cc.C;uuu.C;a.C;b.C;c.C
V<LL>v;
V<LL>w,ab,bc;
set<LL>uo;
map<LL,LL>ww,cc,u;
V<pair<LL,LL> >uu;
map<LL,V<LL> >uuu;
map<pair<LL,LL>,LL> vo;
map<pair<LL,LL>,LL> vu;
LL ar[100];
LL dxx[]= {-1,0,1,0};
LL dyy[]= {0,1,0,-1};
LL dx[]= {2,1,-1,-2,-2,-1,1,2};
LL dy[]= {1,2,2,1,-1,-2,-2,-1};
int main()
{
//  BRR;
//  file;
    FAST;
    char ch;
    string a,b,c;
    DL x,y,d,e,f,g,h;
    LL n,m,i,j,k,p,q,o,l,s,tt=1,t,z,aa,r=0;
//    cin>>tt;
    while(tt--)
    {
        UOSMOY;
        cin>>n>>d;
        k=0;
        for(i=0; i<n; i++)
        {
             cin>>x>>y;
             e=sqrt((x*x)+(y*y));
             if(e<=d)
             {
                 k++;
             }
        }
        cout<<k<<endl;

    }
    return 0;
    //IN
    //AL
}


Measured memory_bytes: 3780
#include <bits/stdc++.h>
using namespace std;
    
int main() {
  long long N;
  cin >> N;
  long long ans = 0;
  if (N%2 == 1)
    cout << 0 << endl;
  
  else {
    long long A = 10;
    while (A <= N) {
      ans += N/A;
      A *= 5;
    }
    cout << ans << endl;
  }
}


Measured memory_bytes: 256
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n,m = LI()
    v = [[] for i in range(n)]
    v_ = [[] for i in range(n)]
    for i in range(m):
        a,b = LI()
        a -= 1
        b -= 1
        v[a].append(b)
        v_[b].append(a)
    dp = [0]*n
    for y in range(1,n)[::-1]:
        v_[y].sort()
        d = dp[y]
        for x in v_[y]:
            dp[x] += (d+1)/len(v[x])
    ans = dp[0]
    lx = []
    for a in range(n-1):
        lx.append(len(v[a])-1)
        if len(v[a]) == 1:
            lx[-1] += 1
            continue
        m = max([dp[b] for b in v[a]])
        for b in v[a]:
            if dp[b] == m:
                break
        for i in range(a+1):
            dp[i] = 0
        for y in range(1,n)[::-1]:
            d = dp[y]
            for x in v_[y]:
                if x > a:
                    break
                if (x,y) == (a,b):
                    continue
                dp[x] += (d+1)/lx[x]
        if 0 < dp[0] < ans:
            ans = dp[0]
        lx[-1] += 1
    print(ans)
    return

#Solve
if __name__ == "__main__":
    solve()


Measured memory_bytes: 69596
#-*-coding:utf-8-*-
from collections import Counter

def main():
    n = int(input())
    a_list = list(map(int, input().split()))
    s = [0]
    ans = 0
    for i in range(n):
        s.append(a_list[i] + s[-1])
    counter = Counter(s)
    for i in set(s):
        ans += counter[i] * (counter[i] - 1) // 2
    print(ans)
    

if __name__ == '__main__':
    main()

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

int n;
int a[5][5];
int s[5];
int dy[] = {-1,0,1,0}, dx[] = {0,1,0,-1};

int check(void){
  int res = 0;
  for(int d=1;;d++){
    bool dis[5][5],f = false;
    rep(i,5)rep(j,5)dis[i][j] = false;
    
    rep(i,5)rep(j,5){
      if(a[i][j] == 0)continue;
      
      rep(k,2){
	int sy = i, sx = j;
	int c = 0;
	while(sy>=0 && sx>=0 && sy<=4 && sx<=4 && a[sy][sx] == a[i][j]){
	  c++; sy += dy[k]; sx += dx[k];
	}
	if(c<3)continue;
	
	f = true;
	sy = i; sx = j;
	while(sy>=0 && sx>=0 && sy<=4 && sx<=4 && a[sy][sx] == a[i][j]){
	  dis[sy][sx] = true;
	  sy += dy[k]; sx += dx[k];
	}
      }
    }
    if(!f)return res;

    rep(i,5)rep(j,5){
      if(dis[i][j]){
	res += d*s[a[i][j]-1];
	a[i][j] = 0;
      }
    }
    
    rep(i,5){
      for(int j=4;j>=0;j--){
	if(a[j][i] != 0){
	  for(int k=1;k<=4-j;k++){
	    if(a[j+k][i]==0)swap(a[j+k][i],a[j+k-1][i]);
	  }
	}
      }
    }
  }
}

int move(int y,int x,int d){
  int tmp[5][5];
  rep(i,5)rep(j,5)tmp[i][j] = a[i][j];
  int res = check();
  rep(i,5)rep(j,5)a[i][j] = tmp[i][j];
  if(d==n)return res;

  rep(k,4){
    int sy = y+dy[k], sx = x+dx[k];
    if(sy<0 || sy>4 || sx<0 || sx>4)continue;
    swap(a[y][x],a[sy][sx]);
    res = max(res,move(sy,sx,d+1));
    swap(a[y][x],a[sy][sx]);
  }
  return res;
}     

int solve(){
  int res = 0;
  rep(i,5)rep(j,5)res = max(res,move(i,j,0));
  return res;
}

int main(){
  while(cin >> n,n>=0){
    rep(i,5)rep(j,5)cin >> a[i][j];
    rep(i,5)cin >> s[i];
    cout << solve() << endl;
  }
}

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

int main()
{
  int N;
  cin>>N;
  ll A, ans=0, sumA=0;
  while(N-->0){
    cin>>A;
    ans=(ans + A*sumA)%(ll)(1e9+7);
    sumA=(sumA+A)%(ll)(1e9+7);
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3632
# seishin.py
N = int(input())
*A, = map(int, input().split())
*B, = map(int, input().split())

M = 32
MOD = [(2 << i) for i in range(M+1)]

from bisect import bisect
def make(B):
    S = [None]*M
    s = {}; get = s.get
    for b in B:
        s[b] = get(b, 0) ^ 1
    S[M-1] = sorted(b for b in s if s[b])

    for i in range(M-2, -1, -1):
        t = S[i+1]; l = len(t)
        m = MOD[i]
        mid = bisect(t, m-1)
        def gen(p, q):
            while p < mid and q < l:
                u = t[p]; v = t[q]
                if u+m == v:
                    p += 1; q += 1
                elif u+m < v:
                    yield t[p]; p += 1
                else:
                    yield t[q]-m; q += 1
            while p < mid:
                yield t[p]; p += 1
            while q < l:
                yield t[q]-m; q += 1
        *S[i], = gen(0, mid)
    return S
S = make(A)
T = make(B)

ans = 0
if 0 in S[0]:
    ans ^= 1 in T[0]
if 1 in S[0]:
    ans ^= 0 in T[0]

for i in range(1, M):
    s = S[i]; ls = len(S)
    t = T[i]; lt = len(t)
    m = MOD[i]; p = MOD[i-1]
    P = p+m; Q = 2*m

    if lt:
        c = 0
        f = lt
        while P <= t[f-1]:
            f -= 1

        u = f; v = lt
        for a in s:
            while u > -lt and P <= a + t[u-1] + (u > 0)*m:
                u -= 1
            while v > -lt and Q <= a + t[v-1] + (v > 0)*m:
                v -= 1
            c += (v - u)
        if c & 1:
            ans ^= 1 << i
print(ans)

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

int main(){
  int n,l;
  cin >> n >> l;
  int syoku = 0;
  if(l<0){
    syoku = min(0,l+n-1);
  }else syoku = l;
  int pie = 0;
  for(int i=0; i<n; i++){
    pie += l+i;
  }
  cout << pie - syoku << endl;
}

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

using namespace std;

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPI(i,a,b) for(int i=int(a);i<int(b);++i)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define ALL(x) (x).begin(),(x).end()


int main () {
  long long r;
  cin >> r;
  cout << ((r*2) * acos(-1)) << endl;
  return 0;
}


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

int main() {
    int a, b;
    cin >> a >> b;
    int ans = 0, cnt = 1;
    while (cnt < b) {
        cnt += a - 1;
        ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	long long x, y;
	cin>>x>>y;
	if((y%2==0)&&(y>=(2*x))&&(y<=(4*x))){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}
	return 0;
}

Measured memory_bytes: 3632
#include <iostream>
    #include <cstdio>
    #include <algorithm>
    #include <vector>
    #include <string>
     
    typedef long long ll;
    using namespace std;
    const ll INF = 1000000000000000000ll;
    const ll MOD = 1000000007ll;
     
    const double EPS = 1e-8;
     
    int main()
    {
		ll N,MIN,MAX=-1000000000;

		cin >> N;

		vector<ll> R(N,0);

		for(int i=0;i<N;i++){
			cin >> R[i];
		}

		MIN=R[0];
		MAX=R[1]-R[0];

		for(int i=1;i<N;i++){
			MAX = max(MAX,R[i]-MIN);
			MIN = min(MIN,R[i]);
		}

		cout << MAX << endl;
				
		return 0;
    }

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

#define REP(i, start, count) for(int i=(start); i<(int)(count); ++i)
#define rep(i, count) REP(i, 0, count)
#define ALLOF(c) (c).begin(), (c).end()

typedef long long ll;
typedef unsigned long long ull;

int K;
int k[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

int
main(void)
{
    cin >> K;

    cout << k[K - 1] << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
using namespace std;
int n,Mod;
int f[3010][3010];
int C[3010][3010];
int main()
{
	scanf("%d %d",&n,&Mod);
	C[0][0]=1;
	for(int i=1;i<=n;i++)
	{
		C[i][0]=1;
		for(int j=1;j<=i;j++)
			C[i][j]=(C[i-1][j-1]+C[i-1][j])%Mod;
	}
	f[0][0]=1;
	for(int i=1;i<=n;i++)
		for(int j=0;j<i;j++)
		{
			f[i][j+1]=(f[i][j+1]+f[i-1][j])%Mod;
			f[i][j]=(f[i][j]+(long long)f[i-1][j]*(j+1))%Mod;
		}
	int ans=0;
	for(int i=0;i<=n;i++)
	{
		int sum=0,val=1;
		for(int j=1;j<=n-i;j++)
			val=(val+val)%Mod;
		int cur=1;
		for(int j=0;j<=i;j++)
		{
			sum=(sum+(long long)cur*f[i][j])%Mod;
			cur=(long long)cur*val%Mod;
		}
		cur=2;
		for(int j=1;j<=n-i;j++)
			cur=(long long)cur*cur%Mod;
		if(i&1)
			ans=(ans-(long long)C[n][i]*cur%Mod*sum%Mod+Mod)%Mod;
		else ans=(ans+(long long)C[n][i]*cur%Mod*sum)%Mod;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 69632
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#define ll long long int
using namespace std;

int main() {
	int N;
	ll X, ans;

	cin >> N;
	vector<ll> a(N);
	
	for (int i = 0; i < N; i++){
		cin >> a[i];
	}

	X = a[0];
	for (int i = 1; i < N; i++){
		X = X^a[i];
	}
	
	for (int i = 0; i < N; i++){
		ans = X^a[i];
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 4780
//入出力等基本
#include <iostream>
#include <vector>
#include <map>

#define 中心() main()
#define 返 return
#define 入力(a) cin >> a
#define 出力(a) cout << a << endl
#define 再帰(s,t) for(整数 s = 0; s < 整数(t); s += 1)
#define 如果(a) if(a)
#define 場合(a) while(a)
#define 先(a) a.first
#define 後(a) a.second
#define 自動 auto

using namespace std;

typedef int 整;
typedef void 無;
typedef long long 整数;
typedef vector<整数> 整数配列;
typedef map<整数,整数> 整辞書;

整数 高,幅,距離;

無 解(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    入力(高);
    入力(幅);
    入力(距離);
    再帰(a,高){
        再帰(b,幅){
            整数 s=(a+b)%(2*距離),t=(a-b + 1000*(2*距離))%(2*距離);
            如果(s>=距離&&t>=距離) cout << 'R';
            如果(s>=距離&&t<距離) cout << 'Y';
            如果(s<距離&&t>=距離) cout << 'G';
            如果(s<距離&&t<距離) cout << 'B';
        }
        cout<<endl;
    }
}   

整 中心(){
    解();
    返 0;
}

Measured memory_bytes: 888
N = int(input())

def num_withdraw_l(N):
    dp = [N] * (N + 1)
    dp[0] = 0
    for n in range(1, N+1):
        dp[n] = min(dp[n], dp[n - 1] + 1)
        coin = 6
        while coin <= N:
            dp[n] = min(dp[n], dp[n - coin] + 1)
            coin *= 6
        coin = 9
        while coin <= N:
            dp[n] = min(dp[n], dp[n - coin] + 1)
            coin *= 9
    return dp[N]

print(num_withdraw_l(N))

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

typedef struct proc_t {
    int x1, y1, x2, y2;
} proc;

int main()
{
    int w, h;
    int a[1<<9][1<<9];
    int n = 0;
    std::cin >> h >> w;
    proc p[w*h];
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            std::cin >> a[i][j];
        }
    }
    for (int i = 0; i < h; i++) {
        if (i%2==0) {
            for (int j = 0; j < w; j++) {
                if (i == h-1 && j == w-1) break;
                if (j != w-1) {
                    if (a[i][j]%2==1) {
                        a[i][j]--;
                        a[i][j+1]++;
                        p[n].x1 = i;
                        p[n].y1 = j;
                        p[n].x2 = i;
                        p[n].y2 = j+1;
                        n++;
                    }
                } else {
                    if (a[i][j]%2==1) {
                        a[i][j]--;
                        a[i+1][j]++;
                        p[n].x1 = i;
                        p[n].y1 = j;
                        p[n].x2 = i+1;
                        p[n].y2 = j;
                        n++;
                    }
                }
            }
        } else {
            for (int j = w-1; j >= 0; j--) {
                if (i == h-1 && j == 0) break;
                if (j != 0) {
                    if (a[i][j]%2==1) {
                        a[i][j]--;
                        a[i][j-1]++;
                        p[n].x1 = i;
                        p[n].y1 = j;
                        p[n].x2 = i;
                        p[n].y2 = j-1;
                        n++;
                    }
                } else {
                    if (a[i][j]%2==1) {
                        a[i][j]--;
                        a[i+1][j]++;
                        p[n].x1 = i;
                        p[n].y1 = j;
                        p[n].x2 = i+1;
                        p[n].y2 = j;
                        n++;
                    }
                }
            }
        }
    }
    std::cout << n << std::endl;
    for (int i = 0; i < n; i++) {
        printf("%d %d %d %d\n", p[i].x1+1, p[i].y1+1, p[i].x2+1, p[i].y2+1);
    }
    return 0;
}


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

const int N = 1e3L + 11;
const int mod = 1e4L + 7;

int dp[N][8];
int a[N];

int main() {
	ios :: sync_with_stdio(false);
	int n; cin >> n;
	string s; cin >> s; s = '0' + s;
	for(int i = 1; i <= n; i ++)
		a[i] = (s[i] == 'J') ? 1 : (s[i] == 'O') ? 2 : 4;
	for(int i = 0; i < 8; i ++)
		dp[1][i] = (i & a[1]) && (i & 1);
	for(int i = 2; i <= n; i ++)
		for(int j = 0; j < 8; j ++)
			for(int k = 0; k < 8; k ++) if(j & k)
				if(k & a[i]) {
					dp[i][k] += dp[i - 1][j];
					dp[i][k] %= mod;
				}
	cout << accumulate(dp[n], dp[n] + 8, 0) % mod << '\n';
}

Measured memory_bytes: 3216
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <string>
using namespace std;

int main(){
  int H, W;
  cin >> H >> W;

  int h, w;
  cin >> h >> w;

  cout << (H-h) * (W-w) << "\n";
  return 0;
}


Measured memory_bytes: 256
"""
task statement
==============

明日から太郎君の夏休みが始まります。
太郎君は夏休みの計画を立てることにしました。
夏休みは N 日からなります。
各 i (1 \leq i \leq N) について、i 日目には太郎君は次の活動のうちひとつを選んで行います。

A: 海で泳ぐ。 幸福度 a_i を得る。
B: 山で虫取りをする。 幸福度 b_i を得る。
C: 家で宿題をする。 幸福度 c_i を得る。

太郎君は飽き性なので、2 日以上連続で同じ活動を行うことはできません。
太郎君が得る幸福度の総和の最大値を求めてください。

io_style
-------
N
a_1 b_1 c_1
a_2 b_2 c_2
:
a_N b_N c_N
"""
#-*-coding:utf-8-*-

import sys

def main2():
    n = int(input())
    dp=[[0,0,0] for _ in range(n+1)]
    for i in range(n):
        a,b,c=map(int,input().split())
        dp[i+1][0]=max(dp[i][1],dp[i][2])+a
        dp[i+1][1]=max(dp[i][0],dp[i][2])+b
        dp[i+1][2]=max(dp[i][0],dp[i][1])+c
    print(max(dp[-1]))

if __name__ == "__main__":
    main2()


Measured memory_bytes: 22764
#include<stdio.h>

int main(){
    int N,K,a,count=0;
    scanf("%d %d ",&N,&K);
    int p[N];
    for(int i=0;i<N;i++){
        p[i]=0;
    }
    for(int i=0;i<K;i++){
        scanf("%d ",&a);
        int b[a];
        for(int j=0;j<a;j++){
            scanf("%d ",&b[j]);
            p[b[j]-1]=b[j];
        }
    }
    for(int i=0;i<N;i++){
        if(p[i]==0){
            count+=1;
        }
    }
    printf("%d",count);
    
    
    
    return 0;
}

Measured memory_bytes: 1732
import java.util.Scanner;

class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = Integer.parseInt(sc.next());
    int[] a = new int[n];
    for(int i=0;i<n;i++)a[i] = Integer.parseInt(sc.next());
    
    int val = 1;
    for(int i=0;i<n;i++){
      if(a[i]==val)val++;
    }
    if(val>1){
      System.out.println(a.length-(val-1));
    }else{
      System.out.println(-1);
    }
  }
}

Measured memory_bytes: 51576
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define isYES(x) printf("%s\n",(x) ? "YES" : "NO")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define isYes(x) printf("%s\n",(x) ? "Yes" : "No")
#define isIn(x,y,h,w) (x >= 0 && x < h && y >= 0 && y < w)

#define int long long
//using ll = long long;
using P = pair<int,int>;

ostream &operator<<(ostream &os,const P &p){ return os << "(" << p.first << "," << p.second << ")"; }
template<class T>
ostream &operator<<(ostream &os,const vector<T> &v){
	for(int i = 0;i < v.size();i++) os << (i ? "," : "[") << v[i];
	os << "]";
	return os;
}

template<class T> T &chmin(T &a,const T &b){ return a = min(a,b); }
template<class T> T &chmax(T &a,const T &b){ return a = max(a,b); }

const int INF=1e+18;
const double EPS=1e-9;
const int MOD=1000000007;

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

signed main(){
	const double PI = 3.141592653589793;
	double n;
	cin >> n;
	printf("%.15lf\n",n * 2 * PI);
}

Measured memory_bytes: 3784
#include<stdio.h>
int main()
{
    int i=0,j,n=0,a[1000],b[1000],k;
    while(1){
        scanf("%d %d",&a[i],&b[i]);
        if(a[i]==0 && b[i]==0){
            break;
        }
        i++;
        n++;
    }
    for(k=0;k<n;k++){
        for(i=1;i<=a[k];i++){
            for(j=1;j<=b[k];j++){
                printf("#");
            }
            printf("\n");
        }
        printf("\n");
    }
    return 0;
}



Measured memory_bytes: 2056
#include <bits/stdc++.h>
using namespace std;
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using f32 = float;
using f64 = double;
using ll = long long;
constexpr i64 INF = 1010000000000000017LL;
constexpr i64 MOD = 1000000007LL;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))
template<typename T, typename U, typename Comp=less<>>
bool chmax(T& xmax, const U& x, Comp comp={}) {
    if(comp(xmax, x)) xmax = x; return true;
    return false;
}
template<typename T, typename U, typename Comp=less<>>
bool chmin(T& xmin, const U& x, Comp comp={}) {
    if(comp(x, xmin)) xmin = x; return true;
    return false;
}
template<typename Val>
bool bitcheck(Val bit, size_t idx) {
    return bit & (1 << idx);
}
struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;
    ProconInit() {
        cin.tie(nullptr); ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH) cout << unitbuf;
    }
} PROCON_INIT;

void solve() {
    ll n; cin >> n;
    vector<ll> d(n); FOR(i, 0, n) cin >> d[i];
    sort(d.begin(), d.end());
    ll s = d[n/2-1];
    ll e = d[n/2];
    cout << e - s << endl;
}

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

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

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

using namespace std;

using  ll = long long;

template<class T,class U>
using umap = unordered_map<T,U>;

template<class T>
using uset = unordered_set<T>;

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

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


int main(){
  string s,t;cin >> s >> t;
  umap<char, vector<int>> dic;
  const int ssize = static_cast<int>(s.size());
  const int tsize = static_cast<int>(t.size());
  for(int i = 0; i < ssize; ++i){
    dic[s[i]].push_back(i);
  }
  ll ans = 0;
  ll pre = -1;
  for(int i = 0; i < tsize; ++i){
    if(dic.count(t[i]) == 0){
      cout << -1 << endl;
      return 0;
    }
    auto it = upper_bound(dic[t[i]].begin(), dic[t[i]].end(), pre);
    if(it == dic[t[i]].end()){
      ans += ssize;
      pre = -1;
      it = upper_bound(dic[t[i]].begin(), dic[t[i]].end(), pre);
    }
    int now = *it;
    pre = now;
  }
  cout << ans + pre + 1 << endl;
  return 0;
}


Measured memory_bytes: 1216
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod=1e9+7;

int main(){
    int H, W;
    cin >> H >> W;
    vector<vector<char>> a(H, vector<char>(W));
    for(int y=0; y<H; y++){
        for(int x=0; x<W; x++){
            cin >> a[y][x];
        }
    }
    vector<bool> row(H, false);
    vector<bool> col(W, false);
    for (int y=0; y<H; y++){
        for(int x=0; x<W; x++){
            if(a[y][x]=='#'){
                row[y] = true;
                col[x] = true;
            }
        }
    }

    for (int y=0; y<H; y++){
        if(row[y]){
            for(int x=0; x<W; x++){
                if(col[x]){
                    cout << a[y][x];
                }
            }
            cout << endl;
        }
    }
}

Measured memory_bytes: 256
import java.util.*;

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

    String s[] = sc.nextLine().split(" ");
    System.out.println(s[0].substring(0, 1) + s[1].substring(0, 1) + s[2].substring(0, 1));
  }
}

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

using namespace std;

using ll = long long;
using P = pair<ll,ll>;

#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define rrep(i,x) for(ll i = ((ll)(x) - 1); i >= 0; i--)

#define _upgrade ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define all(x) (x).begin(), (x).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

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

//ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
//ll lcm(ll x, ll y) {return x / gcd(x, y) * y;}

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

const ll mod = 1e9 + 7;
const ll INF = 1LL << 60;
const double PI = 3.14159265358979323846;


// ****************************************CODE***************************************//









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

        //隣接リスト
        //グラフ構造を持つ
        vector<vector<int>> to(n), co(n);
        for(int i = 0; i < n-1; i++)
        {
                int a, b, w;
                cin >> a >> b >> w;
                a--;
                b--;
                to[a].push_back(b);
                co[a].push_back(w);
                to[b].push_back(a);
                co[b].push_back(w);
        }

        //BFS
        vector<int> ans(n,-1);
        queue<int> q;
        ans[0] = 0;
        q.push(0);
        while(!q.empty())
        {
                int v = q.front();
                q.pop();
                for(int i = 0; i < to[v].size(); i++){
                        //並んでる順番が一緒だから
                        //構造体を作って実装するのも良い
                        int u = to[v][i];
                        int w = co[v][i];
                        if(ans[u] != -1) continue;
                        ans[u] = (ans[v] + w) % 2;
                        q.push(u);
                }
        }

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
















Measured memory_bytes: 11904
#include<bits/stdc++.h>
#define N (100000+1000)
using namespace std;
 
int n,a[N],b[N],ans;
map<int,int>pos;
 
int main()
{
	scanf("%d",&n);
	for (int i=1; i<=n; ++i)
		scanf("%d",&a[i]),b[i]=a[i];
	sort(b+1,b+n+1);
	for (int i=1; i<=n; ++i) pos[b[i]]=i;
	for (int i=1; i<=n; ++i) 
		if (abs(i-pos[a[i]])%2)
			ans++;
	printf("%d",ans>>1);
}

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

using namespace std;

typedef long long ll;

ll gcd(ll a, ll b){

  while(a){
    b %= a;
    swap(a, b);
  }
  return b;
}

ll lcm(ll a, ll b){
  return a * b / gcd(a, b);
}

int main(void){

  int n,d[10],v[10];
  while( cin >> n , n ){

    for( int i = 0 ; i < n ; i++ ){
      cin >> d[i] >> v[i];
      int dg = gcd(d[i], v[i]);
      d[i] /= dg;
      v[i] /= dg;
    }
    ll gd = v[0], lm = d[0];
    for( int i = 1 ; i < n ; i++ ){
      lm = lcm(lm, d[i]);
      gd = gcd(gd, v[i]);
    }
    for( int i = 0 ; i < n ; i++ )
      cout << lm * v[i] / gd / d[i] << endl;

  }
  return 0;
}

Measured memory_bytes: 1156
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int main(){
	ll n;
	cin>>n;
	ll cnt2=0,cnt5=0;
	if(n%2)//奇数
		cout<<0<<endl;
	else
	{
		for(ll i=2;i<=n;i*=2){
			cnt2+=n/i;
		}
		for(ll i=10;i<=n;i*=5){
			cnt5+=n/i;	
		}
		cout<<min(cnt2,cnt5)<<endl;
	} 
	return 0;
} 

Measured memory_bytes: 256
macro_rules! get {
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
            get!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
            get!($($t),*)
        ).collect::<Vec<_>>()
    };
}

struct UnionFind {
    tree: Vec<usize>,
    rank: Vec<usize>,
}

impl UnionFind {
    fn new(n: usize) -> UnionFind {
        UnionFind {
            tree : (0..n).collect::<Vec<_>>(),
            rank : vec![0;n],
        }
    }

    fn parent(&mut self, x: usize) -> usize {
        if x == self.tree[x] {
            x
        } else {
            let p = self.tree[x];
            let q = self.parent(p);
            self.tree[x] = q;
            q
        }
    }

    fn is_same(&mut self, a: usize, b: usize) -> bool {
        self.parent(a) == self.parent(b)
    }

    fn unite(&mut self, a: usize, b: usize) -> bool {
        let a = self.parent(a);
        let b = self.parent(b);
        if a == b {
            return false;
        }

        if self.rank[a] > self.rank[b] {
            self.tree[b] = a;
        } else {
            self.tree[a] = b;
            if self.rank[a] == self.rank[b] {
                self.rank[b] += 1;
            }
        }
        true
    }
}

use std::cmp::Ordering;
use std::collections::BinaryHeap;

#[derive(Copy, Clone, Eq, PartialEq)]
struct Road {
    a: usize,
    b: usize,
    c: i64
}

impl Ord for Road {
    fn cmp(&self, other: &Road) -> Ordering {
        other.c.cmp(&self.c)
    }
}

impl PartialOrd for Road {
    fn partial_cmp(&self, other: &Road) -> Option<Ordering> {
        Some(self.cmp(other))
    }
}

fn main() {
    let n = get!(usize);
    let mut xx = Vec::new();
    let mut yy = Vec::new();
    for i in 0..n {
        let (x, y) = get!(usize, usize);
        xx.push((i, x));
        yy.push((i, y));
    }
    xx.sort_by(|&(_, a), &(_, b)| a.cmp(&b));
    yy.sort_by(|&(_, a), &(_, b)| a.cmp(&b));

    let mut pq = BinaryHeap::new();

    for i in 1..n {
        let (x1, j) = xx[i-1];
        let (x2, k) = xx[i];
        pq.push(Road { a: x1, b: x2, c: (k-j) as i64 });
        let (y1, j) = yy[i-1];
        let (y2, k) = yy[i];
        pq.push(Road { a: y1, b: y2, c: (k-j) as i64 });
    }

    let mut uft = UnionFind::new(n);
    let mut cost = 0;
    while let Some(Road { a, b, c }) = pq.pop() {
        if !uft.is_same(a, b) {
            cost += c;
            uft.unite(a, b);
        }
    }
    println!("{}", cost);
}

Measured memory_bytes: 18228
using System;
					
public class Program
{
	public static void Main()
	{
		string[] str = Console.ReadLine().Split(' ');
		int A = int.Parse(str[0]);
		int B = int.Parse(str[1]);
		int C = int.Parse(str[2]);
		
		int tmpA, tmpB, tmpC;
		int orgA=A, orgB=B, orgC=C;
		int cnt=0;
				
		while(true){
			
		if((A%2==1)||(B%2==1)||(C%2==1)){
			break;
		}else{
			tmpA=A/2;
			tmpB=B/2;
			tmpC=C/2;
			
			A=tmpB+tmpC;
			B=tmpC+tmpA;
			C=tmpB+tmpA;
			
			if((A==orgA)&&(B==orgB)&&(C==orgC)){
				cnt=-1;
				break;
			}
			cnt++;
		}
			
		}
		
		Console.WriteLine(cnt);
	}
}

Measured memory_bytes: 11092
#include<cstdio>
#include<cstring>
#include<algorithm>
#define MAXN 200000
using namespace std;
int p[MAXN+5],q[MAXN+5];
int f[MAXN+5],T[MAXN+5];
bool Check(int a,int b,int c)
{
	return (a<b&&b<c)||(b<c&&c<a)||(c<a&&a<b);
}
int main()
{
	int N;
	scanf("%d",&N);
	for(int i=1;i<=N;i++)
		scanf("%d",&p[i]),q[p[i]]=i;
	for(int i=N-1;i>=1;i--)
	{
		if(T[i+1]==0)
		{
			if(q[i]>q[i+1])
				T[i]=1,f[i]=i+1;
		}
		else
		{
			if(Check(q[f[i+1]],q[i],q[i+1])==true)
				T[i]=T[i+1],f[i]=f[i+1];
			else
				T[i]=T[i+1]+1,f[i]=i+1;
		}
	}
	printf("%d\n",T[1]);
	return 0;
}

Measured memory_bytes: 3328
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		long ans = 0;
		if (N == 1) {
			System.out.println(K);
		}else {
			ans = K * (long)Math.pow(K-1,N-1);
			System.out.println(ans);
		}

	}

}


Measured memory_bytes: 35772
#include <cstdio>
#include <map>
#include <algorithm>
using namespace std;
int h,w,m,tr[300003],tc[300003];
pair<int,int> r[300003],c[300003];
map<pair<int,int>,int> mp;
bool cmp(pair<int,int> x,pair<int,int> y){return x.second>y.second;}
int main(){
    scanf("%d%d%d",&h,&w,&m);
    for(int i=1;i<=m;i++){
        int x,y;scanf("%d%d",&x,&y);
        mp[make_pair(x,y)]=1,++tr[x],++tc[y];
    }
    for(int i=1;i<=h;i++) r[i]=make_pair(i,tr[i]);for(int i=1;i<=w;i++) c[i]=make_pair(i,tc[i]);
    std::sort(r+1,r+1+h,cmp),std::sort(c+1,c+1+w,cmp);
    int maxr=r[1].second,maxc=c[1].second;
    for(int i=1;r[i].second==maxr;i++){
        for(int j=1;c[j].second==maxc;j++){
            if(!mp[make_pair(r[i].first,c[j].first)]) return printf("%d\n",maxr+maxc),0;
        }
    }
    printf("%d\n",maxr+maxc-1);
    return 0;
}

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

arr = []
for it in range(n):
    arr.append(str(input()))

count_arr = [0] * 4

for i in arr:
    if i == 'AC':
        count_arr[0] += 1
    elif i == 'WA':
        count_arr[1] += 1
    elif i == 'TLE':
        count_arr[2] += 1
    elif i == 'RE':
        count_arr[3] += 1

# output
print('AC x', count_arr[0])
print('WA x', count_arr[1])
print('TLE x', count_arr[2])
print('RE x', count_arr[3])

Measured memory_bytes: 83332
n,m=map(int,input().split())
ab=[list(map(int,input().split())) for i in range(n)]#学生の位置
cd=[list(map(int,input().split())) for i in range(m)]#ゴール
l=[0]*n
for i in range(n):
    ans=10**18
    
    for j in range(m):
        a=abs(ab[i][0]-cd[j][0])+abs(ab[i][1]-cd[j][1])
        
        if ans>a:
            ans=a
            l[i]=j+1
        if ans==0:
            break
            
print(*l,sep='\n')

Measured memory_bytes: 3064
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
S = sum(A)
count = [0]*(10**5+1)
for i in range(len(A)):
  count[A[i]] += 1

A = list(set(A))
for i in range(Q):
  B, C = map(int, input().split())
  S = S - B*count[B] + C*count[B]
  count[C] += count[B]
  count[B] = 0
  print(S)
  

Measured memory_bytes: 20740
#include<iostream>
#include<cstring> 
using namespace std;
int main()
{
	int a[4][4],b[4][4];
	for(int i=1;i<=3;i++)
		for(int j=1;j<=3;j++)
		cin>>a[i][j];
		 memset(b,0,sizeof(b));
		 int n,m;
		 cin>>n;
		 for(int i=0;i<n;i++)
		 {
		 	cin>>m;
		 	for(int j=1;j<=3;j++)
		 		for(int x=1;x<=3;x++)
		 		{
		 			if(m==a[j][x])
		 			b[j][x]=1;
				}
		 }
		 int panduan=0;
		 for(int i=1;i<=3;i++)
		 {
		 	if(b[i][1]+b[i][2]+b[i][3]==3)
			 panduan=1; 
		 }
		 for(int j=1;j<=3;j++)
		 {
		 	if(b[1][j]+b[2][j]+b[3][j]==3)
		 	panduan=1;
		 }
		 if(b[1][1]+b[2][2]+b[3][3]==3)
		 panduan=1;
		 if(b[1][3]+b[2][2]+b[3][1]==3)
		 panduan=1;
		 
		 if(panduan==1)
		 cout<<"Yes";
		 else
		 cout<<"No";
 } 

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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) for(i64 i = 1; i <= n; ++i)
#define RREP(i, n) for(i64 i = n - 1; i >= 0 ; --i)
#define RREPS(i, n) for(i64 i = n; i >= 1; --i)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define pb push_back
#define mp make_pair
#define F first
#define S second

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }


struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;

#define INF 2'000'000'000

int main() {
    i64 N, K; cin >> N >> K;
    vector<i64> h(N);
    REP(i, N) cin >> h[i];
    sort(h.begin(), h.end());

    i64 minv = INF;
    REP(i, N - K + 1) {
        chmin(minv, h[i + K - 1] - h[i]);
    }
    cout << minv << endl;

    return 0;
}

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

using ll = long long;
const ll mod = (1E9) + 7;
using vl = vector<ll>;
using vll = vector<vl>;
vll comb;

void init(int h)
{
    int size = h + 5;
    comb = vll(size, vl(size, 0));

    comb[0][0] = 1;

    for (int i = 0; i <= h; i++) {
        for (int j = 0; j <= h; j++) {
            comb[i + 1][j] += comb[i][j];
            comb[i + 1][j] %= mod;

            comb[i + 1][j + 1] += comb[i][j];
            comb[i + 1][j + 1] %= mod;
        }
    }
}

ll f(ll ball, ll group)
{
    if (ball < 0)
        return 0;

    ll partition = group - 1;
    return comb[ball + partition][partition];
}

int main(void)
{
    int N, K;
    cin >> N >> K;

    init(2 * N);

    const int blue = K;
    const int red = N - K;
    for (int i = 1; i <= K; i++) {
        ll b = f(blue - i, i);
        ll r = f(red - (i - 1), i + 1);

        cout << b * r % mod << endl;
    }

    return 0;
}


Measured memory_bytes: 125696
#if 1
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>
#include <bitset>
#include <list>

auto& in = std::cin;
auto& out = std::cout;
#define all_range(C) std::begin(C), std::end(C)
const double PI = 3.141592653589793238462643383279502884197169399375105820974944;

int32_t N;
int32_t A[200010];

int main()
{
	using std::endl;
	in.sync_with_stdio(false);
	out.sync_with_stdio(false);
	in.tie(nullptr);
	out.tie(nullptr);

	in >> N;// N = 200000;
	for (int32_t i = 0; i < N; ++i)
	{
		in >> A[i];
		//A[i] = N - i;
	}
	{
		bool ok = true;
		for (int32_t i = 1; i < N; ++i)
		{
			if (A[i - 1] < A[i]) {

			}
			else {
				ok = false;
				break;
			}
		}
		if (ok) {
			out << 1 << endl;
			return 0;
		}
	}
	//{
	//	bool ok = true;
	//	std::unordered_set<int32_t> map;
	//	for (int32_t i = 0; i < N; ++i)
	//	{

	//		if (map.count(A[i])) {
	//			ok = false;
	//			break;
	//		}
	//		map.insert(A[i]);
	//	}
	//	if (ok) {
	//		out << 2 << endl;
	//		return 0;
	//	}
	//}

	//for (int32_t i = 0; i < N; ++i)
	//{
	//	A[i] = std::min(40, A[i]);
	//}


	using BS_INT = int32_t;
	BS_INT ok_range = N, ng_range = 1;
	while (std::abs(ok_range - ng_range) > 1) {
		BS_INT mid = (ok_range + ng_range) / 2;
		bool is_ok = true;

		//ここに書く
		{
			//std::vector<int> now(A[0], 0);
			std::map<int, int> table;
			table[A[0]] = 0;
			for (int32_t i = 1; i < N; ++i)
			{
				if (table.rbegin()->first < A[i])
				{
					table[A[i]] = 0;
					continue;
				}
				if (table.rbegin()->first > A[i]) {
					table.erase(table.upper_bound(A[i]), table.end());
				}
				//add
				bool ok = false;
				for (int j = A[i]; j >= 1; j--)
				{
					if (table[j] == mid - 1) {
						table[j] = 0;
						continue;
					}
					ok = true;
					++table[j];
					break;
				}
				if (ok) {
					continue;
				}

				is_ok = false;
				break;
			}
		}

		if (is_ok) {
			ok_range = mid;
		}
		else {
			ng_range = mid;
		}
	}
	out << ok_range << endl;

	return 0;
}
#endif


Measured memory_bytes: 3840
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Main main = new Main();
		main.run();
	}

	public void run() {
		Scanner sc = new Scanner(System.in);
		long n=sc.nextLong();
		long ans=keta(n);
		for(long i=2; i*i<=n; i++) {
			if(n%i!=0) continue;
			long k = Math.max(keta(i), keta(n/i));
			if(ans>k) {
				ans = k;
			}
		}
		System.out.println(ans);
		sc.close();
	}

	private long keta(long x) {
		if((x/10)==0) {
			return 1;
		}
		return keta(x/10)+1;
	}


}




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

using namespace std;
ll mod=1000000007;

ll pre[3004];
ll suff[3004];

int main(){
	ll n;
	cin>>n;
	ll dp[n+1][n+1];
	string s;
	cin>>s;
	memset(dp,0,sizeof(dp));
	
	dp[1][1]=1;
	for(ll i=2;i<=n;i++){
		memset(pre,0,sizeof(pre));
	//	memset(suff,0,sizeof(suff));
		for(ll j=1;j<i;j++){
			pre[j]=dp[i-1][j];
			if(j>=2){
				pre[j]=(pre[j]+pre[j-1])%mod;
			}
			
			}
		
		for(ll j=1;j<=i;j++){
			ll l,r;
			if(s[i-2]=='<'){
				l=1;r=j-1;
			}
			else{
				l=j;r=i-1;
			}
			if(l<=r){
				
				dp[i][j]=(dp[i][j]+(pre[r]-pre[l-1]+mod))%mod;
			}
			
			}
			
			
			
		
		
	}
	ll ans=0;
	for(ll i=1;i<=n;i++){
		ans=(ans+dp[n][i])%mod;
	}
	cout<<ans;
}

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

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;

using namespace std;


int inputValue(){
    int a;
    cin >> a;
    return a;
};

void inputArray(int * p, int a){
    rep(i, a){
        cin >> p[i];
    }
};

void inputVector(vector<int> * p, int a){
    rep(i, a){
        int input;
        cin >> input;
        p -> push_back(input);
    }
}

template <typename T>
void output(T a, int precision) {
    if(precision > 0){
        cout << setprecision(precision)  << a << "\n";
    }
    else{
        cout << a << "\n";
    }
}

int main(int argc, const char * argv[]) {
    
    // source code
  int n;
  int k;
  cin >> n;
  cin >> k;
  int h[n];
  int count = 0;
  inputArray(h,n);
  rep(i,n)
  {
    if(h[i] >= k)
    {
      count++;
    }
  }
  
  cout << count << endl;
}

Measured memory_bytes: 640
import math
n = int(input())
a = list(map(int,input().split()))

b = [0]*n 
c = 0
s = [0]*(n+1)

for i in reversed(range(1,n+1)):
	for k in range(1,math.floor(n/i)+1):
		j = int(k*i)
		s[i] += b[j-1]
	if s[i]%2 != a[i-1]:
		b[i-1] += 1
		c += 1
print(c)
L = [i+1 for i in range(n) if b[i] == 1]
print(*L)

Measured memory_bytes: 19708