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

// {U}{INT,LONG,LLONG}_{MAX,MIN}
#define INF         INT_MAX/3
#define LLINF       LLONG_MAX/3
#define MOD         (1000000007LL)
#define MODA(a, b)  a=((a)+(b))%MOD
#define MODP(a, b)  a=((a)*(b))%MOD
#define inc(i, l, r)   for(int i=(l);i<(r);i++)
#define dec(i, l, r)   for(int i=(r)-1;i>=(l);i--)
#define pb          push_back
#define se          second
#define fi          first
#define mset(a, b)  memset(a, b, sizeof(a))

using LL  = long long;
using G   = vector<vector<int>>;

int di[] = {0, -1, 0, 1};
int dj[] = {1, 0, -1, 0};
// }}}

int main() {
    cin.tie(0);ios::sync_with_stdio(false);
    LL k, a, b;cin >> k >> a >> b;
    LL ans = 1;
    if(b-a > 1){
        ans = a + (k-(a-1))/2*(b-a);
        if((k-(a-1))%2 != 0){
            ans++;
        }
    }else{
        ans += k;
    }
    printf("%lld\n", ans);
    return 0;
}


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

int main(){
  int n;
  cin>>n;
  if(n>=1800){
    cout<<1;
  }else if(n>=1600){
    cout<<2;
  }else if(n>=1400){
    cout<<3;
  }else if(n>=1200){
    cout<<4;
  }else if(n>=1000){
    cout<<5;
  }else if(n>=800){
    cout<<6;
  }else if(n>=600){
    cout<<7;
  }else if(n>=400){
    cout<<8;
  }
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
int main(){
  int n,x,y;
  cin>>n;
  vector<int>p(n);
  vector<int>q(n);
  vector<int>r(n);
  rep(i,n){
    r.at(i)=i+1;
  }
  rep(i,n){
    int P;
    cin>>P;
    p.at(i)=P;
  }
  rep(i,n){
    int Q;
    cin>>Q;
    q.at(i)=Q;
  }
  int i=0;
  do {
    if (p==r) {
      x=i;
    }
    if (q==r) {
      y=i;
    }
    i+=1;
  } while(next_permutation(r.begin(),r.end()));
  cout<<abs(x-y)<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <numeric>
#include <set>
#include <list>
#include <bitset>
#include <cstdlib>
#include <map>
using ll = long long int;
using namespace std;

int main()
{
    int N;
    ll x;
    cin >> N >> x;
    vector<ll> A(N);
    for (int i = 0; i < N; i++)
    {
        cin >> A[i];
    }
    sort(A.begin(), A.end());
    int ans = 0;
    for (int i = 0; i < N; i++)
    {
        if (A[i] <= x)
        {
            x -= A[i];
            ans++;
        }
        else if (x < A[i])
        {
            x = 0;
            break;
        }
    }
    if (x == 0)
    {
        cout << ans << endl;
    }
    else
    {
        cout << ans - 1 << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int x,y;
	int s1,s2,s3,s4;
	int sum;
	
	scanf("%d %d %d %d",&s1,&s2,&s3,&s4);
	sum=s1+s2+s3+s4;
	x=sum/60;
	y=sum%60;
	printf("%d\n%d\n",x,y);
	return 0;
}

Measured memory_bytes: 1020
using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

    class Program
    {
        static void Main()
        {
            var S = Console.ReadLine();
            var T = Console.ReadLine();

            var lS = new List<AlphaDic>();
            var lT = new List<AlphaDic>();



            for (int i = 0; i < S.Length; i++)
            {
                var rS = new AlphaDic();
                rS.key = S[i];
                var targetS = lS.FirstOrDefault(x => x.key == S[i]);
                if (targetS == null)
                {
                    rS.idx = i;
                    rS.cnt = 1;
                }
                else
                {
                    rS.idx = targetS.idx;
                    rS.cnt++;
                }
                lS.Add(rS);

                var rT = new AlphaDic();
                rT.key = T[i];
                var targetT = lT.FirstOrDefault(x => x.key == T[i]);
                if (targetT == null)
                {
                    rT.idx = i;
                    rT.cnt = 1;
                }
                else
                {
                    rT.idx = targetT.idx;
                    rT.cnt++;
                }
                lT.Add(rT);

                if (lS[i].idx != lT[i].idx || lS[i].cnt != lT[i].cnt)
                {
                    Console.WriteLine("No");
                    return;
                }
            }

            Console.WriteLine("Yes");
        }
        class AlphaDic
        {
            public char key;
            public int    idx;
            public int    cnt;
        }
    }

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

int main() {
	vector<int> K(5);
	for(int i = 0 ; i < 5 ; i++){
		cin >> K[i];
	}
	vector<double> k(5);
	for(int i = 0 ; i < 5 ; i++){
		k[i] = K[i];
	}
	for(int i = 0 ; i < 5 ; i++){
		k[i] = ceil(k[i]/10)*10;
	}
	int n=20;
	for(int i = 0 ; i < 5 ; i++){
		if(K[i]%10 != 0){
		n = min(n,K[i]%10);
		}
	}
	int ans = 0;
	for(int i = 0 ; i < 5 ; i++){
		ans += k[i];
	}
	if(n == 20){
	cout << ans << endl;
	return 0;
}
	cout << ans + n -10 << endl; 
}


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

using namespace std;
const int INF = 1e9;


int main(){
  int N, M;
  vector<int> as(3);
  cin >> N >> M >> as[0] >> as[1] >> as[2];
  vector<vector<int>> G(N);
  for(int i=0;i<M;++i){
	int u, v; cin >> u >> v;
	--u, --v;
	G[u].push_back(v);
  }

  vector<set<int>> memo[3];
  for(int k=0;k<3;++k)
	for(int i=0;i<N;++i){
	  set<int> buf[2];
	  int crt = 0, nxt = 1;
	  buf[crt].insert(i);
	  for(int n=0;n<as[k];++n){
		buf[nxt].clear();
		for(int x: buf[crt])
		  for(int to: G[x])
			buf[nxt].insert(to);
		swap(crt, nxt);
	  }
	  memo[k].push_back(buf[crt]);
	}

  vector<int> dist(N, INF);
  dist[N-1] = 0;
  for(int i=0;i<N;++i){
	for(int j=0;j<N;++j){
	  int prv = dist[j];
	  dist[j] = 0;
	  for(int k=0;k<3;++k){
		int tmp = INF;
		for(int x: memo[k][j])
		  if(x != j)
			tmp = min(tmp, dist[x]+1);
		dist[j] = max(dist[j], tmp);
	  }
	  dist[j] = min(dist[j], prv);
	}
  }

  //for(int i=0;i<N;++i) cout << i << " " << dist[i] << endl;
  if(dist[0] >= INF || dist[0] < 0)
	cout << "IMPOSSIBLE" << endl;
  else
	cout << dist[0] << endl;

  return 0;
}

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


#define f(i,a,b) for(int i=(int)(a);i<=(int)(b);i++)
#define char_f(i,a) for(int i=(int)(a);(char)s[i]!='\0';i++)
#define rf(i,a,b) for(int i=(int)(a);i>=(int)(b);i--)
#define llf(i,a,b) for(long long int i=(long long int)(a);i<=(long long int)(b);i++)
#define llrf(i,a,b) for(long long int i=(long long int)(a);i>=(long long int)(b);i--)



#define ll long long
#define fi first
#define se second
#define pb push_back
#define pob pop_back
#define mem(ara) memset((ara),0,sizeof(ara))
#define memn(ara) memset((ara),-1,sizeof(ara))
#define bb begin()
#define ee end()
#define em emplace
#define eb emplace_back





#define si set<int>
#define sd set<double>
#define sll set<long long int>
#define ss set<string>
#define sc set<char>

#define pii pair<int,int>
#define pli pair<long long int,int>
#define pil pair<int,long long int>
#define pll pair<long long int,long long int>
#define pci pair<char,int>
#define pic pair<int,char>
#define pcl pair<char,long long int>
#define plc pair<long long int,char>

#define pss pair<string,string>
#define pcc pair<char,char>

#define pis pair<int,string>
#define psi pair<string,int>
#define pls pair<long long int,string>
#define psl pair<string,long long int>
#define pdd pair<double,double>
#define pcs pair<char,string>
#define psc pair<string,char>



#define vi  vector<int>
#define vll vector<long long int>
#define vd vector<double>
#define vs vector<string>
#define vc vector<char>
#define vii vector<pii>



#define mod 1000000007
#define mx (1<<30)-1
#define llmx (1ll<<62)
#define n_size 100005
#define g_size 10000005
double PI=acos(-1);
#define eps 1e-9



///unsigned int uMAX=4294967295;
///unsigned ll int ullMAX=18446744073709551615;





int arr[g_size];



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

	int n,m,T,res;

	int maxi=-mx,mini=mx,count=0;

	int i,j,k;

	bool flag;

	string s1,s2;

	char s[100000];

	int ara[n_size],ara2[n_size];

	cin>>m>>n;
    
    if(n==100){
        n++;
    }
	if(m==0) cout<<n<<endl;
	else if(m==1) cout<<n*100<<endl;
	else if(m==2)cout<<n*10000<<endl;



}


Measured memory_bytes: 3592
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <queue>
#include <deque>

using namespace std;
//using std::cin, std::cout, std::endl, std::string;
using ll = long long;

#define rep(countName, left, right, up) for (auto countName = left; countName < right; countName += up)
#define REP(countName, end) for (auto countName = 0; countName < end; countName++)
#define rev(countName, right, left, down) for (auto countName = right; countName >= left; countName -= down)
#define REV(countName, end) for (auto countName = end; countName >= 0; countName--)

auto solve1(int n, std::vector<int> &&a)
{
    int ans;
    std::vector<int> v(n);
    REP(i, n)
    {
        if (a[i] % 2 == 0)
        {
            while (a[i] % 2 == 0)
            {
                v[i]++;
                a[i] /= 2;
                //cout << a[i] << " ";
            }
            //cout << endl;
        }
        else
        {
            v[i] = 0;
        }
    }
    ans = *std::min_element(v.begin(), v.end());
    return ans;
}

int main(void)
{
    int n;
    cin >> n;
    std::vector<int> a(n);
    REP(i, n) { cin >> a[i]; }
    cout << solve1(n, std::move(a)) << endl;
    return 0;
}

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

int main() {
    int N;
    pair < int , int > A[100005];
    int cnt = 0;
    cin >> N;
    for ( int i = 0; i < N; i++ ) { cin >> A[i].first; A[i].second = i; }
    sort(A, A + N);
    for ( int i = 0; i < N; i++ ) cnt += ((A[i].second + i) & 1);
    cout << cnt / 2 << endl;
    return ( 0 );
}


Measured memory_bytes: 1024
import java.util.*;
public class Main {
  	static int mod = 1000000007;
  static int size = 200001;
	static long[] fac = new long[size];
	static long[] finv = new long[size];
	static long[] inv = new long[size];
	static int INF = Integer.MAX_VALUE;
public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
	// 整数の入力
	int N = sc.nextInt();

    System.out.println((int)Math.pow(N,3));



} 

 //fac, inv, finvテーブルの初期化、これ使う場合はinitComb()で初期化必要
	public static  void initComb(){
		fac[0] = finv[0] = inv[0] = fac[1] = finv[1] = inv[1] = 1;
		for (int i = 2; i < size; ++i) {
			fac[i] = fac[i - 1] * i % mod;
			inv[i] = mod - (mod / i) * inv[(int) (mod % i)] % mod;
			finv[i] = finv[i - 1] * inv[i] % mod;
		}
	}
 
	//nCk % mod
	public static long comb(int n, int k){
        if (n < k) return 0;
        if (n < 0 || k < 0) return 0;
		return fac[n] * finv[k] % mod * finv[n - k] % mod;
	}
 
	//n! % mod
	public static long fact(int n){
		return fac[n];
	}
 
	//(n!)^-1 with % mod
	public static long finv(int n){
		return finv[n];
	}
  
}

Measured memory_bytes: 25940
using System;
using System.Linq;

namespace AtCoder
{
    class Program
    {
        static void Main()
        {
            var Nline = Console.ReadLine();
            var Xline = Console.ReadLine().Split(' ');

            var N = int.Parse(Nline);
            var X = Xline.Select(s => int.Parse(s)).ToArray();

            var max = X.Max();

            var count = 1;
            var result = new double[max];

            while (count <= max)
            {
                var i = 0;
                while (i < N)
                {
                    result[count - 1] = result[count - 1] + Math.Pow(X[i] - count, 2);
                    i += 1;
                }

                count += 1;
            }

            Console.WriteLine(result.Min());
        }
    }
}


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

using namespace std;

using ll = long long;
using ull = unsigned long long;

int main(int argc, char const *argv[]) {
	int a,b;
	std::cin >> a >> b;
	if ((a * b) % 2 == 0) {
		std::cout << "No" << '\n';
	}
	else {
		std::cout << "Yes" << '\n';
	}
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(void)
{
  double n, m;
  cin >> n >> m;
  vector<double> data(n);
  int sum = 0;
  for(int i = 0; i < n ; i++)
  {
    cin >> data[i];
    sum += data[i];
  }
  sort(data.begin(), data.end(), greater<int>());
  if(data[m - 1] < sum / (4 * m))
  {
    cout << "No" << endl;
  }else{
    cout << "Yes" << endl;
  }
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <vector>


using namespace std;

int main(){
  long long int A, B, C;
  cin >> A >> B >> C;
  if ((A % 2) == 0){
    cout << 0 << endl;
  }else if ((B % 2) == 0){
    cout << 0 << endl;
  }else if ((C % 2) == 0){
    cout << 0 << endl;
  }else{
    if ((A >= B) && (A >= C)){
      cout << (B*C) << endl;
    }else if ((B >= A) && (B >= C)){
      cout << (A*C) << endl;
    }else{
      cout << (A*B) << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
int main() {
    std::string s;
    for (std::cin >> s; s != "-"; std::cin >> s) {
        int m;
        std::cin >> m;
        while (m-- > 0) {
            int h;
            std::cin >> h;
            std::reverse(s.begin(), s.begin() + h);
            std::reverse(s.begin() + h, s.end());
            std::reverse(s.begin(), s.end());
        }
        std::cout << s << std::endl;
    }
}



Measured memory_bytes: 3148
#include<iostream>
using namespace std;
int main(){
  long long n,k;cin >> n >> k;
  long long a[2];
  a[0] = n/k;
  if(k%2==0 && n>=k/2) a[1] = 1+(n-k/2)/k;
  else a[1] = 0;
  cout << a[0]*a[0]*a[0]+a[1]*a[1]*a[1] << endl;
}
  

Measured memory_bytes: 256
N,M=map(int,input().split())
A=[int(x) for x in input().split()]

if N>=M:
  answer=0
else:
  A.sort()
  B=[]
  for i in range(1,M):
    B +=[A[i]-A[i-1]]
  B=sorted(B)
  answer=sum(B[:M-N])
print(answer)

Measured memory_bytes: 13840
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
const int mod=1000000007;

int main(){
	int a,b,c;
	cin>>a>>b>>c;
	if(a==b&&b==c){
		cout<<"Yes";
	}else{
		cout<<"No";
	}
    return 0;
}


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

using namespace std;

int main(){
    ios::sync_with_stdio(false);
    int n;
    cin >>n;
    vector<int> a(n);
    vector<int> b(n-1);
    for(int ib = 0;ib<n-1;ib++){
        cin >> b[ib];
    }
    for(int ia=1;ia<n-1;ia++){
        a[ia]=min(b[ia-1],b[ia]);
    }
    a[n-1]=b[n-2];
    a[0] = b[0];

    int ans;
    ans = accumulate(a.begin(),a.end(),0);
    cout << ans <<"\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define LL long long
#define PII pair<int,int>
using namespace std;
const int MAXN = 1005;
const int MAXX = 5005;
const int INF = (LL)1e9 + 5;

int X[MAXN], minv[MAXN], dp[MAXX], N;
vector<int> ch[MAXN];

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	cin >> N;
	for (int i = 2; i <= N; i++) {
		int p;
		cin >> p;
		ch[p].push_back(i);
	}
	
	bool ok = true;
	for (int i = 1; i <= N; i++) cin >> X[i];
	for (int v = N; v >= 1; v--) {
		fill(dp, dp + 5001, INF);
		dp[0] = 0;
		
		for (int to : ch[v]) {
			int c1 = X[to], c2 = minv[to];
			for (int j = 5000; j >= 0; j--) {
				int a = INF, b = INF;
				if (j >= c1) a = dp[j - c1] + c2;
				if (j >= c2) b = dp[j - c2] + c1;
				dp[j] = min(a, b);
			}
		}
		
		minv[v] = *min_element(dp, dp + X[v] + 1);
		if (minv[v] == INF) {
			ok = false;
			break;
		}
	}
	
	if (!ok) cout << "IM";
	cout << "POSSIBLE\n";
	
	return 0;
	
	/**** Note MAXN ****/
}


Measured memory_bytes: 384
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt(), cnt = 0;
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}

		LOOP1 : while (true) {
			for (int i = 0; i < a.length; i++) {
				if (a[i] % 2 == 1) {
					break LOOP1;
				}
				a[i] = a[i] / 2;
			}
			cnt++;
		}

		System.out.println(cnt);
	}

}

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

int main(){
    vector <ll> v(3);
    for(int i=0;i<3;++i)cin >> v[i];
    sort(v.begin(),v.end());
    ll ans=0;
    for(int i=1;i<3;++i)ans+=abs(v[i]-v[i-1]);
    cout << ans << endl;
}

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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define PI 3.14159265358979
#define MOD 1000000007 // = 10^9 + 7

using namespace std;
using ll = long long;


void solve()
{
	int n, m;
	cin >> n >> m;

	vector<int> a(n);
	int all_sum = 0;
	for(int i = 0; i < n; ++i)
	{
		cin >> a[i];
		all_sum += a[i];
	}
	
	sort(a.begin(), a.end(), greater<int>());
	cout << ((all_sum / (4.0 * m) <= a[m - 1]) ? "Yes" : "No") << endl;
}

int main()
{
	fastio;
	solve();

	return 0;
}




Measured memory_bytes: 256
n = int(input())
s = list(map(int, input().split()))
q = int(input())
t = list(map(int, input().split()))

count = 0
for i in range(q):
    left = 0
    right = n
    mid = (left + right) // 2
    while left < right:
        if t[i] == s[mid]:
            count += 1
            break
        elif t[i] < s[mid]:
            right = mid
            mid = (left + right) // 2
        elif t[i] > s[mid]:
            left = mid + 1
            mid = (left + right) // 2

print(count)






Measured memory_bytes: 16708
#include <iostream>

using namespace std;

int main() {
    int n, y;
    cin >> n >> y;
    int res_x = -1;
    int res_y = -1;
    int res_z = -1;
    bool finished = false;
    for (int tmp_x = 0; tmp_x <= n; ++tmp_x) {
        for (int tmp_y = 0; tmp_y <= n - tmp_x; ++tmp_y) {
            int tmp_z = n - tmp_x - tmp_y;
            if (10000 * tmp_x + 5000 * tmp_y + 1000 * tmp_z == y) {
                res_x = tmp_x;
                res_y = tmp_y;
                res_z = tmp_z;
                finished = true;
                break;
            }
        }
        if (finished) break;
    }
    cout << res_x << " " << res_y << " " << res_z << endl;
    return EXIT_SUCCESS;
}

Measured memory_bytes: 256
-- Try AtCoder
-- author: Leonardone @ NEETSDKASU

main = interact $ maybe "Yes" id . (`lookup` [(True, "No")]) . all null . map (foldl1 (((maybe "" id . (`lookup` [(True, "@")])) .) . all . (==) . head) . replicate 2 . take 3) . zipWith drop [0 .. 3] . replicate 4 . cycle


Measured memory_bytes: 380
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define pb push_back
#define eb emplace_back
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
const ll INF = numeric_limits<ll>::max()/4;
const int n_max = 1e5+10;

// xの桁数を返す関数
int digit_max(ll x){
    int dig = 0;
    while(x/pow(10,dig) >= 1)dig++;
    return dig;
}

// xのdigit桁目を返す関数
// 下から順にone-based（感覚に即しているはず）
int digit_num(ll x, int digit){
    assert(digit_max(x) >= digit);
    ll t1 = x/pow(10,digit-1);
    ll t2 = (x/pow(10,digit));
    // print(t1,t2);
    return t1 - t2 * 10;
}

int main(){
    ll n; cin >> n;
    ll ans = 0;
    for(int i = 1; i <= n; i++){
        ll ed = i%10;
        ll st = digit_num(i,digit_max(i));
        if(ed == 0)continue;
        ll temp = 0;
        rep(i,10){
            if(i+2 > digit_max(n))break;
            if(i+2 < digit_max(n))temp += pow(10,i);
            else{
                if(digit_num(n,digit_max(n)) > ed)temp += pow(10,i);
                else if(digit_num(n,digit_max(n)) == ed){
                    // debug("test");
                    temp += (n-ed*pow(10,i+1)-st)/10 + 1;
                }
            }
        }
        if(st == ed)temp++;
        // debug(i);debug(st);debug(ed);
        // debug(temp);
        ans += temp;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
class Node:
    def __init__(self):
        self.name=-1
        self.parent=-1
        self.children=[]
        self.degree=0
        self.depth=-1
        self.state="leaf"
        self.sibling=-1
        self.height=-1




def get_depth(Tree,node,depth):
    for child in node.children:
        Tree[child].depth=depth+1
        get_depth(Tree,Tree[child],depth+1)


def get_height(Tree):
    for node in Tree:
        if(len(node.children)==0):
                node.height=0
                tmp_node=node
                while(tmp_node.parent!=-1):
                        Tree[tmp_node.parent].height=max([tmp_node.height+1, Tree[tmp_node.parent].height])
                        tmp_node=Tree[tmp_node.parent]
                     




Tree=[]
n=int(input())
for i in range(n):
    Tree.append(Node())
for loop in range(n):
    info=list(map(int,input().split()))
    i=info[0]
    Tree[i].name=i
    for j in range(1,len(info)):
        if(info[j]!=-1):
                (Tree[i].children).append(info[j])
                if(info[1]!=-1 and info[2]!=-1):
                        Tree[info[2]].sibling=info[1]
                        Tree[info[1]].sibling=info[2]
                Tree[i].state="internal node"
                Tree[info[j]].parent=i




for node in Tree:
    if(node.parent==-1):
        node.state="root"
        node.depth=0
        get_depth(Tree,node,0)


get_height(Tree)
        


for node in Tree:
    print(f"node {node.name}: parent = {node.parent}, sibling = {node.sibling}, degree = {len(node.children)}, depth = {node.depth}, height = {node.height}, {node.state}")



Measured memory_bytes: 5632
#include <bits/stdc++.h>
using namespace std;
char str[10000];

int main(){
	int n;
	cin >> n;
	scanf("%s",str);
	int ptr=0,front=0;
	bool not_bal=false;
	for(int i=0;i<n;i++){
		if(not_bal){
			if(str[i]==')'){
				ptr--;
				if(ptr==0)
					not_bal=false;
			}
			else{
				ptr++;
			}

		}
		else{
			if(str[i]==')'){
				front++;
			}
			else{
				not_bal=true;
				ptr++;
			}
		}
	}
	for(int i=0;i<front;i++)
		printf("(");
	printf("%s",str);
	for(int i=0;i<ptr;i++)
		printf(")");
	cout << endl;

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
	long n,index;
	long max, min;
	long total = 0;
	scanf("%d",&n);
	for (int i = 0; i < n; i++)
	{
		scanf("%ld", &index);
		if (i == 0)
		{
			max = min = index;
		}
		else
		{
			if (max < index)
			{
				max = index;
			}
			else if(min > index)
			{
				min = index;
			}
		}
		total = total + index;
	}
	printf("%ld %ld %ld\n",min,max,total);
	return 0;
}


Measured memory_bytes: 2744
N,A,B,C = map(int, input().split())
l = list(int(input()) for _ in range(N))
inf = 10 ** 9
def dfs(cur,a,b,c):
    if cur == N:
        return abs(a-A) + abs(b-B) + abs(c-C) -30 if min(a,b,c) > 0 else inf
    re0 = dfs(cur+1, a, b, c)
    re1 = dfs(cur+1, a+l[cur], b, c)+10
    re2 = dfs(cur+1, a, b+l[cur], c) + 10
    re3 = dfs(cur+1, a, b, c+l[cur]) + 10
    return min (re0, re1, re2, re3)
print(dfs(0,0,0,0))


Measured memory_bytes: 73972
import java.util.*;

public class Main {

    static final int MOD = 1000000007;

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt(),b=sc.nextInt(),c=sc.nextInt();
        System.out.println(a+b>=c?"Yes":"No");
    }
}


Measured memory_bytes: 21716
#include<stdio.h>

int main(void){
 int i, height;
 int top[3] = {0};
 
 for(i = 0; i < 10; i++){
  scanf("%d", &height);
  if(height > top[0]){
   top[2] = top[1];
   top[1] = top[0];
   top[0] = height;
  }else if(height > top[1]){
   top[2] = top[1];
   top[1] = height;
  }else if(height > top[2]){
   top[2] = height;
  }
 }
 for(i = 0; i < 3; i++){
  printf("%d\n", top[i]);
 }
 return 0;
}

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

using namespace std;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;

#define LOOP(N) for(int i=(int)(N); i--;)
#define REP(i, N) for(int i=0; i<(N); ++i)
#define FOR(i, start, end) for(int i=(int)(start); i<(end); ++i)
#define ALL(a) (a).begin(),(a).end()

class FastIO {
public:
    FastIO() {
        cin.tie(0);
        ios::sync_with_stdio(false);
    }
    ~FastIO() {}

    template <class T>
    void scan(T &v) {
        cin >> v;
    }
    template <class T, class... Rest>
    void scan(T &v, Rest&... rest) {
        scan(v);
        scan(rest...);
    }

    template <class T>
    void print(T v) {
        cout << v;
    }
    template <class T, class... Rest>
    void print(T v, Rest... rest) {
        print(v);
        print(" ");
        print(rest...);
    }
    template <class T>
    void print(vector<T> v) {
        for (T t: v) {
            print(t);
            print(" ");
        }
        print("\b\n");
    }
    template <class T>
    void prints(T v) {
        print(v);
        cout << "\n";
    }
};

void _main(FastIO&);
int main() {
    FastIO io;
    _main(io);
}



void _main(FastIO &io) {
    int A, B; io.scan(A, B);
    
    int tap_c = 1;
    int c = 0;
    while (tap_c < B) {
        tap_c += A - 1;
        c++;
    }
    cout << c;
}

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

typedef long long ll;
#define ar array
#define vi vector<int>
#define vvi vector<vector<int>>
#define vll vector<long long>
#define all(x) (x).begin(), (x).end()
#define en '\n'
#define FILL(x, v) memset(x, v, sizeof(x))
#define pb push_back
#define fast                     \
	ios::sync_with_stdio(false); \
	cin.tie(NULL);               \
	cout.tie(NULL);
#define F_OR(i, a, b, s) for (int i = (a); ((s) > 0 ? i < (b) : i > (b)); i += (s))
#define F_OR1(e) F_OR(i, 0, e, 1)
#define F_OR2(i, e) F_OR(i, 0, e, 1)
#define F_OR3(i, b, e) F_OR(i, b, e, 1)
#define F_OR4(i, b, e, s) F_OR(i, b, e, s)
#define GET5(a, b, c, d, e, ...) e
#define F_ORC(...) GET5(__VA_ARGS__, F_OR4, F_OR3, F_OR2, F_OR1)
#define FOR(...)       \
	F_ORC(__VA_ARGS__) \
	(__VA_ARGS__)

#define E_ACH2(x, a) for (auto &x : a)
#define E_ACH3(x, y, a) for (auto &[x, y] : a)
#define E_ACH4(x, y, z, a) for (auto &[x, y, z] : a)
#define E_ACHC(...) GET5(__VA_ARGS__, E_ACH4, E_ACH3, E_ACH2)
#define EACH(...)       \
	E_ACHC(__VA_ARGS__) \
	(__VA_ARGS__)

template <typename A, typename B>
inline void chmin(A &a, B b)
{
	if (a > b)
		a = b;
}
template <typename A, typename B>
inline void chmax(A &a, B b)
{
	if (a < b)
		a = b;
}

const int mxn = 2e5 + 1;
vvi grid(mxn);
vi vis(mxn);
struct UnionFind
{
	vector<int> d;
	UnionFind(int n = 0) : d(n, -1) {}

	int find(int x)
	{
		// not visited or parent
		if (d[x] < 0)
			return x;
		return d[x] = find(d[x]); // dont really need to assign again
	}

	bool unite(int x, int y)
	{
		x = find(x);
		y = find(y);
		if (x == y)
			return false;
		if (x > y)
			swap(x, y);
		if (d[x] > d[y])
			swap(x, y);
		d[x] += d[y];
		d[y] = x;

		return true;
	}

	bool same(int x, int y) { return find(x) == find(y); }

	int size(int x) { return -d[find(x)]; }
};

int main()
{
	fast;
	int n, m;
	cin >> n >> m;
	UnionFind uf(n);
	FOR(m)
	{
		int x, y;
		cin >> x >> y;
		x--;
		y--;
		grid[x].pb(y);
		grid[y].pb(x);
		uf.unite(x, y);
	}
	int ans = 0;
	FOR(n)
	{
		chmax(ans, uf.size(i));
	}
	cout << ans;
}

Measured memory_bytes: 16328
N = gets.to_i
# a = N / 1.08
# if (a * 1.08).to_i == N
#   puts a.round.to_i
# else
#   puts ':('
# end

(1..N).each do |n|
  if (n * 1.08).to_i == N
    puts n
    exit 0
  end
end
puts ':('


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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;

#define F first
#define S second
#define PB push_back
#define MK make_pair
#define REP(i, a, b) for (int i=a; i < b; i++)


bool sort_by(pi c, pi d){
	return c.S < d.S;
}

int main() {
	int n, a, b, c, d;
	string s;
	cin >> n >> a >> b >> c >> d >> s;
	string ans = "Yes";
	s = "#" +s;
	char p;
	REP(i, a, c+1){
		if(i != a && p == '#' && s[i] == '#'){
			cout << "No";
			exit(0);
		}
		p = s[i];
	}
	REP(i, b, d+1){
		if(i != b && p == '#' && s[i] == '#'){
			cout << "No";
			exit(0);
		}
		p = s[i];
	}
	int m_c = 0;
	if( d < c){
		int t = 0;
		REP(i, b-1, d+2){
			if(s[i] == '.') ++t;
			else{ 
				m_c = max(m_c, t);
				t = 0;
			}
			m_c = max(m_c, t);
		}
		if(m_c < 3) ans = "No";
	}
	cout << ans;
		
	

}


Measured memory_bytes: 772
#include<stdio.h>
int main(void){
    char num[1001];
    int sum,i;
    while(1){
        sum=0;
        scanf("%s",num);
        sum=0;
        if(num[0]=='0')break;
        for(i=0;num[i]!='\0';i++){
            sum+=num[i]-'0';
        }
        printf("%d\n",sum);
    }
    return 0;
}


Measured memory_bytes: 2104
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int H, W, D;
    cin >> H >> W >> D;
    int A[H][W] = {};
    map<int,pair<int, int> > ma;
    rep(i, H) {
        rep(j, W) {
            cin >> A[i][j];
            ma[A[i][j]] = make_pair(i, j);
        }
    }
    //rep(i, H*W+1) cout << ma[i].first << " " << ma[i].second << endl;
    int sum[D][(H*W+1)/D+2] = {};
    for(int j = 0; j < D; j++) {
        for(int i = 1; i*D <= H*W; i++) {
            sum[j][i] = sum[j][i-1] + abs(ma[i*D+j].first - ma[(i-1)*D+j].first) + abs(ma[i*D+j].second - ma[(i-1)*D+j].second);
        }
    }
    int Q; cin >> Q;
    //rep(i, 5) dump(sum[2][i]);
    rep(i, Q) {
        int L, R; cin >> L >> R;
        //dump(sum[L%D][R/D]);
        cout << sum[L%D][R/D] - sum[L%D][L/D] << endl; 
    }



    return 0;
}


Measured memory_bytes: 13056
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long n,a,b;
	cin>>n;
	long long x=INT_MAX;
	for(int i=0;i<n;i++)
	{
		cin>>a>>b;
		x=min(x,a+b);
	}
	cout<<x<<endl;
return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  int M;
  int x = 0;//総投票数
  int k = 0;//人気商品になりえる個数
  
  cin >> N;
  cin >> M;
  
  vector<int> vec(N); //配列定義
  
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
    x = x + vec.at(i);
  } //配列入力と総投票数確定
  
  for (int j = 0; j < N; j++) {
    if (vec.at(j) *4*M >= x){
    k = k + 1 ;
    }  
  }

  if (k >= M){
    cout << "Yes" ;
  }
  else{
    cout << "No" ;
  }
}

Measured memory_bytes: 256
import java.util.Scanner;

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

	private static void solve() {
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int[] nums = new int[n];
		for (int i = 0; i < n; i++) {
			nums[i] = sc.nextInt();
		}
		sc.close();
		int tmpMax = Integer.MIN_VALUE;
		int tmpMin = nums[0];

		for (int i = 1; i < n; i++) {
			tmpMax = Math.max(tmpMax, nums[i] - tmpMin);
			tmpMin = Math.min(tmpMin, nums[i]);
		}

		System.out.println(tmpMax);
	}
}

Measured memory_bytes: 100980
#include <bits/stdc++.h> 
using namespace std;
const long long mod=1e9+7;
int main(){
    int N,M;
    cin >> N >> M;
    //create a vector that judges floor is clash or safe 
    vector<int> oks(N+1,true);
    for(int i=0;i<M;i++){
        //clash floors are false
        int a;
        cin >> a;
        oks[a]=false;

    }

    vector<long long int >dp(N+1);
    dp[0]=1;
    for(int now = 0;now < N;now++){
        for(int next = now+1;next<=min(N,now+2);next++){
            if(oks[next]){
                dp[next] +=dp[now];
                dp[next] %=mod;
            }
        }

    }
    cout << dp[N]<<endl;


}

Measured memory_bytes: 1408
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long int ll;
typedef vector<pair<ll,ll> > Q;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<(int)(n);i++)

ll n,k,ans=0;

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

  //kが奇数の時，a,b,cをkで割った余りは0
  if(k%2==1)
  {
    ans=pow((int)(n/k),3);
  }
  //kが偶数の時，a,b,c,をkで割った余りはすべて0 or すべてk/2;
  else
  {
    ans=pow((int)(n/k),3); //余り0
    if(n%k>=k/2) ans+=pow((int)((n/k)+1),3);
    else ans+=pow((int)(n/k),3);
  }

  cout<<ans<<endl;
}

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

int main() {
	int N;
	cin >> N;
	vector<long long> A(N);
	for (int i = 0; i < N; i++) cin >> A[i];
	long long NOW = 1000;
	for (int i = 0; i < N - 1; i++) {
		if (A[i] < A[i + 1]) {
			NOW = NOW % A[i] + (NOW / A[i]) * A[i + 1];
		}
	}
	cout << NOW << endl;
}

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

#define INF 100100100
#define MOD 1000000007

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

using namespace std;
using ll = long long;
using ull = unsigned long long ;

struct edge{ll to,cost;};

int main(int argc, char const* argv[]){
   ios::sync_with_stdio(false);
   cin.tie(0);
   string S;
   cin >> S;
   char a = S[0];
   ll ans = 0;
   for(int i=1;i<S.size();i++){
      if(S[i] != a){
         ans++;
         a = S[i];
      }
   }
   cout << ans << endl;
   return 0;
}


Measured memory_bytes: 512
/********************/
/* K B G D E L T A */
/*     DA-IICT      */
/********************/
 
#include<bits/stdc++.h>
using namespace std;
using   ll=long long;
using   ld=long double;
#define fast           ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define endl           "\n"
#define F(i,n)         for(ll i=0;i<n;i++)
#define rep(i,a,b)     for(ll i=a;i<b;i++)
#define repp(i,a,b)    for(ll i=a;i>=b;i--)
#define pb             push_back
#define mp             make_pair
#define vll            vector<ll>
#define f              first
#define s              second
#define pll            pair<ll,ll>
#define ALL(v)         v.begin(),v.end()
#define ALLR(v)        v.rbegin(),v.rend()
#define pii            3.14159265358979323
#define mod            1000000007

void solve()
{
    ll n,ans=0;

    cin>>n;

    vll a(n);

    F(i,n)
    {
        cin>>a[i];
    }

    sort(ALL(a));

    for(int i=n-1;i>=2;i--)
    {
        for(int j=i-1;j>=1;j--)
        {
            ll it=lower_bound(ALL(a),a[i]-a[j]+1)-a.begin();

            if(it>=j)   break;

            ans+=j-it;
        }
    }

    cout<<ans;
}
 
signed main(){
 
    fast;
 
    ll t=1;
 
    //cin>>t;
 
    while(t--)
    {
        solve();
    }
 
    return 0;
}


Measured memory_bytes: 256
N = int(input())
a_list = list(map(int, input().split()))

for i in range(N, 0, -1):

    j = i
    sum_num = 0
    while j <= N:
        a = a_list[j-1]
        if j != i:
            sum_num += a
        if i == 1:
            j += 1
        else:
            j += i
    if sum_num % 2 == 0:
        if a_list[i-1] == 0:
            continue
        else:
            a_list[i-1] = 1
    else:
        if a_list[i-1] == 1:
            a_list[i-1] = 0
        else:
            a_list[i-1] = 1

ans = sum(a_list)
print(ans)

for i in range(1, N+1):
    if a_list[i-1] != 0:
        print(i)


Measured memory_bytes: 62812
data = gets.split(" ")
a = data[0].to_i
b = data[1].to_i
c = data[2].to_i
tmp = a

if (b < a)
  a = b
  b = tmp
end

if (c < b)
  tmp = b
  b = c
  c = tmp
end

if (b < a)
  tmp = a
  a = b
  b = tmp
end

puts "#{a} #{b} #{c}"

Measured memory_bytes: 8604
#include <iostream>

int main(void){
  char c;
  std::cin >> c;
  switch(c){
    case 'a':case 'i':case 'u':case 'e': case 'o':
      std::cout << "vowel" << std::endl; break;
    default:
      std::cout << "consonant" << std::endl;
  }
  return 0;
}

Measured memory_bytes: 3568
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<bitset>
#include<queue>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) FOR(i,0,n)
typedef long long ll;
//全ての数の最小公倍数を求める問題

ll gcd(ll a, ll b){
	//a>bに揃えたい
	if (a<b) swap(a,b);
	if (b%a==0) return a;
	else return gcd(b,a%b);
}
int main(){
	int n;
	cin >> n;
	ll ans,sub;
	cin >> ans;

	rep(i,n-1){
		cin >> sub;
		ans = (sub/gcd(ans,sub))*ans;
	}
	cout << ans << endl;
	return 0;
}
	


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cstdlib>  
#include <algorithm>
#include <string>

using namespace std;
 
int main() {
    int n;cin>>n;
    int a[n];
    long g = 0;
    for(int i= 0;i<n;i++)cin>>a[i];
    for(int i = 1;i<n;i++){
    	if(a[i-1] > a[i]){
        	g+= a[i-1] -a[i];
            a[i] = a[i-1];
        }  
    }
    cout<<g;
    return 0;
}

Measured memory_bytes: 3904
//============================================================================
// Name        : AOJ.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <cstdio>
#include <string>
#include <cctype>
using namespace std;

int main() {
	int n,m,e,j;
	while(1){
		cin>>n;
		if(n==0) break;
		for(int i=0;i<n;i++){
			cin>>m>>e>>j;
			if(m==100 || e==100 || j==100)cout<<"A"<<endl;
			else if((m+e)/2>=90)cout<<"A"<<endl;
			else if((m+e+j)/3>=80)cout<<"A"<<endl;
			else if((m+e+j)/3>=70)cout<<"B"<<endl;
			else if(((m+e+j)/3>=50&&m>=80)||((m+e+j)/3>=50&&e>=80))cout<<"B"<<endl;
			else cout<<"C"<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 2968
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define int ll
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a) (a).begin(),(a).end()
#define pb emplace_back


signed main(){
    int n;
    cin>>n;
    vector<int> c(n);
    rep(i,n)cin>>c[i];

    vector<int> v(n,0);
    int q;
    cin>>q;
    vector<int> t(q),x(q),d(q);
    rep(i,q)cin>>t[i]>>x[i]>>d[i];
    rep(i,q){
        x[i]--;
        if(t[i]==1){   //input
            v[x[i]] += d[i];
            if(v[x[i]]>c[x[i]]){
                cout<<x[i]+1<<endl;
                return 0;
            }
        }else{  //output
            v[x[i]] -= d[i];
            if(v[x[i]]<0){
                cout<<x[i]+1<<endl;
                return 0;
            }
        }
    }
    cout<<0<<endl;
}



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

int main() {
	long long int k, a, b;
	cin >> k >> a >> b;

	long long int ans = 0;
	if (b - a <= 2) {
		ans = k + 1;
	}
	else {
		ans = a + ((k - (a - 1))) / 2 * (b - a) + (k - (a - 1)) % 2;
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
from fractions import gcd
N, M = map(int, input().split())
A = list(map(int, input().split()))
lcm = 1

def f(n):
  res = 0
  while n%2 == 0:
    res += 1
    n //= 2
  return res

t = f(A[0])
for a in A:
  if t != f(a):
    print(0)
    exit()
  a //= 2
  lcm *= a // gcd(lcm, a)

print(M//lcm - M//(lcm*2))

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

int main() {
  int N;
  int Y = 0;
  string C;
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> C;
    if (C == "Y") {
      Y += 1;
      cout << "Four" << endl;
      break;
    }
    else {
      continue;
    }
  }
  if (Y == 0) {
	cout << "Three" << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9;

int n;
int solve(int m){
	if((long long)m*m <= (long long)n)return 1;
	else return 0;
}

int main(){
	scanf("%d", &n);
	int lb = 0, ub = n+1;
	while(ub-lb > 1){
		int mid = (ub+lb)/2;
		int res = solve(mid);
		if(res)lb = mid;
		else ub = mid;
	}
	printf("%d\n", lb*lb);
	return 0;
}

Measured memory_bytes: 256
// -*- coding: utf-8 -*-
// Last-Updated : <2014/06/19 06:27:15 by samui>

#include <algorithm>
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <climits>
#include <set>
#include <bitset>

#define MP(a, b) make_pair(a, b)
#define X first
#define Y second
#define rep(i,n) for(int (i) = 0; (i) < (int)(n); ++(i))
#define rer(i,l,n) for(int (i) = l; (i) <= (int)(n); ++(i))
#define reu(i,l,n) for(int (i) = l; (i) < (int)(n); ++(i))
template<typename T,typename U> inline void amin(T &x,U y){ if(y<x) x = y;}
template<typename T,typename U> inline void amax(T &x,U y){ if(x<y) x = y;}
template<typename TYPE,std::size_t SIZE>
std::size_t len(const TYPE (&array)[SIZE]){return SIZE;}

int main(int argc, char *argv[])
{
  std::string inp;
  int s;
  std::string op;
  std::vector<int> t;
  int s1,s2;
  //std::cin >> op;
  getline(std::cin,op);
  for(auto it = op.begin(); it!=op.end();++it){
    inp = *it;
    
    if(inp == " ")
      continue;
    if(t.size()>=2){
      s1 = t[t.size()-1];
      s2 = t[t.size()-2];
    }
    if(inp == "+" )
      {
	t.pop_back();
	t.pop_back();
	t.push_back(s1+s2);
      }
    else if(inp == "-")
      {
	t.pop_back();
	t.pop_back();
	t.push_back(s2-s1);

      }
    else if(inp == "*")
      {
	t.pop_back();
	t.pop_back();
	t.push_back(s1*s2);
      }
    else
      {
	std::string q = "";
	while(it != op.end()){
	  inp = *it;
	  if(inp == " ")
	    break;
	  q+=inp;
	  ++it;
	}
	t.push_back(std::stoi(q));
      }
    
  }
  std::cout<<t[t.size()-1]<<std::endl;

  return 0;
}

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

vector<int> g[100001];
bool vis[100001];

void dfs(int src)
{
  vis[src] = true;
  for(auto child:g[src]){
    if(!vis[child]){
      dfs(child);
    }
  }
}

int main()
{
  int n,m;
  cin>>n>>m;
  for(int i=0;i<m;i++){
    int a,b;
    cin>>a>>b;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  
  for(int i=1;i<=n;i++){
    vis[i]=false;
  }
  
  int cc=0;
  for(int i=1;i<=n;i++){
    if(!vis[i]){
      dfs(i);
      cc++;
    }
  }
  cout<<cc-1<<endl;
}

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

int H, W;
char M[2005][2005];

bool vis[4][2005][2005];

int D[4][2005][2005];

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

inline bool val(int i, int j){
	return 0 <= i && i < H && 0 <= j && j < W;
}

int dfs(int k, int i, int j){
	if (vis[k][i][j]) return D[k][i][j];
	if (M[i][j] == '#') return 0;
	if (!val(i, j)) return 0;
	vis[k][i][j] = true;
	int x = i + dx[k], y = j + dy[k];
	return D[k][i][j] = dfs(k, x, y)+1;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cin >> H >> W;
	for (int i=0; i<H; i++){
		cin >> M[i];
	}
	for (int k=0; k<4; k++){
		for (int i=0; i<H; i++){
			for (int j=0; j<W; j++){
				if (vis[k][i][j]) continue;
				dfs(k, i, j);
			}
		}
	}
	int ans = 0;
	for (int i=0; i<H; i++){
		for (int j=0; j<W; j++){
			ans = max(ans, D[0][i][j]+D[1][i][j]+D[2][i][j]+D[3][i][j]-3);
		}
	}
	cout << ans << endl;
}



Measured memory_bytes: 82816
def main():
    from itertools import product
    n,m,x = map(int,input().split())
    A = []
    for i in range(n):
        a = list(map(int,input().split()))
        A.append(a)
    P = product([0,1], repeat=n)
    ans = float('inf')
    for p in P:
        a = [0 for i in range(m)]
        M = 0
        for i in range(len(p)):
            if p[i]==1:
                M += A[i][0]
                for j in range(1,len(A[i])):
                    a[j-1]+=A[i][j]
        flg = 0
        for i in range(len(a)):
            if a[i]<x:
                flg = 1
                break
        if M<ans and flg==0:
            ans = M
    if ans == float('inf'):
        print(-1)
    else:
        print(ans)
        

if __name__ == "__main__":
    main()


Measured memory_bytes: 9276
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
    static void Main(string[] args)
    {
            // 入力
            string[] sS = System.Console.ReadLine().Trim().Split(' ');
            int iN = int.Parse(sS[0]);
            int iK = int.Parse(sS[1]);
            sS = System.Console.ReadLine().Trim().Split(' ');
            List<int> lstInp = new List<int>();
            for (int i = 0; i < sS.Length; i++) { lstInp.Add(int.Parse(sS[i])); }

            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();

            // 解析
            lstInp.Sort();
            long iOut = 0L;
            for (int i = 0; i < lstInp.Count - iK; i++) { iOut += (long)lstInp[i]; }

            // 出力
            System.Console.WriteLine("{0}", iOut.ToString().Trim());

            sw.Stop();
#if DEBUG
            Console.WriteLine();
            Console.WriteLine("{0}", sw.Elapsed.ToString());
            Console.WriteLine("続行するには何かキーを押してください．．．");
            Console.ReadKey();
#endif
    }

}


Measured memory_bytes: 33792
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef long long int ll;
typedef vector<int> vi;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define Sort(a) sort(a.begin(), a.end())
const int INF = 1 << 30;
const ll MOD = 1000000007;
int N;
vector<int> values;
vector<int> one;
vector<int> two;
int main(void) {
  cin >> N;
  values.resize(N);
  one.resize(N);
  two.resize(N);
  for (int i = 0; i < N; i++) values[i] = (i + 1);
  for (int i = 0; i < N; i++) {
    cin >> one[i];
  }
  for (int i = 0; i < N; i++) {
    cin >> two[i];
  }

  Sort(values);
  int oneIndex = 0;
  int twoIndex = 0;
  int position = 0;
  do {
    if (values == one) oneIndex = position;
    if (values == two) twoIndex = position;
    position++;
  } while (next_permutation(values.begin(), values.end()));

  cout << abs(oneIndex - twoIndex) << 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 a;
  string s;
  cin >> a >> s;
  if (a >= 3200)
    cout << s << endl;
  else
    cout << "red" << endl;
  return 0;
}

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

typedef unsigned long long int uint64;
typedef long long int          int64;

char S[(10*10*10*10)+1];
char T[(10*10*10*10)+1];

int main()
{
  int cnt;
  int N;
  int i;
  int result = 0;
  int len;

  cnt = scanf("%d", &N);
  cnt = scanf("%s", S);

  len = strlen(S);

  for (i=0; i<len; i++) {
    T[i] = S[i] + N;
    if (T[i] > 'Z') {
      T[i] = T[i] - ('Z' - 'A') - 1;
    }
    printf("%c", T[i]);
  }

  return 0;
}


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

res = 0
for i in range(n):
    if a[i] <= b[i]:
        res += min(a[i]+a[i+1], b[i])
        a[i+1] -= min(a[i+1], b[i]-a[i])
    else:
        res += b[i]
print(res)

Measured memory_bytes: 18624