akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define uint ungigned
#define db double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pli pair<ll,int>
#define vi vector<int>
#define vpi vector<pii >
#define IT iterator

#define PB push_back
#define MK make_pair
#define LB lower_bound
#define UB upper_bound
#define BG begin
#define ED end

#define For(i,j,k) for (int i=(j);i<=(int)k;i++)
#define Rep(i,j,k) for (int i=(j);i>=(int)k;i++)
#define CLR(a,v) memset(a,v,sizeof(a));
#define CPY(a,b) memcpy(a,b,sizeof(a));

#define LS3 k*2,l,mid
#define RS3 k*2+1,mid+1,r
#define LS5 k*2,l,mid,x,y
#define RS5 k*2+1,mid+1,r,x,y
#define GET pushdown(k);int mid=(l+r)/2
using namespace std;

int S(ll i){
	int s=0;
	for (;i;s+=i%10,i/=10);
	return s;
}
const int N=100005;
ll q[N];
double v[N];
int main(){
	ll val1=1;
	int top=0;
	for (int i=1;i<=15;i++,val1*=10)
		for (int j=1;j<=999;j++)
			q[++top]=j*val1+val1-1;
	sort(q+1,q+top+1);
	top=unique(q+1,q+top+1)-q-1;
	v[top+1]=1e18;
	for (int i=top;i;i--){
		v[i]=1.0*q[i]/S(q[i]);
		if (v[i]>v[i+1]) q[i]=0;
		v[i]=min(v[i],v[i+1]);
	}
	int k;
	scanf("%d",&k);
	for (int i=1;k;i++)
		if (q[i]) printf("%lld\n",q[i]),k--; 
}

Measured memory_bytes: 512
/*  ex6_3
    potter0723sw  */

#include <stdio.h>
#include <stdlib.h>
#define  error fprintf(stderr, "memory allocation error.\n")//エラー出力を定義

int main(void){
    int row,column,i,j,*rowblack,*colblack;
    char **matrix;
    scanf("%d %d",&row,&column);
//matrixを確保
    matrix = (char**)calloc(row, sizeof(char*));
    if(matrix == NULL){
        error;
        exit(1);
    }
    for(i=0; i < row; i++){
        matrix[i] = (char*)calloc(column, sizeof(char));
        if(matrix[i] == NULL){
            error;
            exit(1);
        }
    }
//rowblackとcolblackも確保
    rowblack = (int*)calloc(row, sizeof(int));
    if(rowblack == NULL){
        error;
        exit(1);
    }
    colblack = (int*)calloc(column, sizeof(int));
    if(colblack == NULL){
        error;
        exit(1);
    }
//黒マスのある行と列を記憶
    for(i=0; i < row; i++){
        for(j=0; j<column;j++){
            scanf(" %c", &matrix[i][j]);
            if(matrix[i][j] == '#'){
                rowblack[i] += 1;
                colblack[j] += 1;
            }
        }
    }
//同じ行にも同じ列にも黒マスのあるマスのみ出力
    for(i=0; i < row; i++){
        for(j=0; j < column; j++){
            if(rowblack[i] != 0 && colblack[j] != 0){
                printf("%c", matrix[i][j]);
            }
        }
        if(rowblack[i] != 0){
            printf("\n");
        }
    }
//メモリ解放
    for(i=0; i < row; i++){
        free(matrix[i]);
    }
    free(matrix);
    free(rowblack);
    free(colblack);
    return 0;
}


Measured memory_bytes: 1632
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		
		int[] a = new int[5];
		
		a[0] = s.nextInt();
		a[1] = s.nextInt();
		a[2] = s.nextInt();
		a[3] = s.nextInt();
		a[4] = s.nextInt();
		
		int c = 0;
		int n = 0;
		int total = 0;
		
		int loss = 0;
		
		for(int i = 0 ; i < 5 ; i++) {
			
			n = a[i] % 10;
			if (n == 0 ) {
				loss = 0;
			} else {
				loss = 10 - n;
			}
			total = total + a[i];
			if(loss > c) {
				total = total + c;
				c = loss;
			} else {
				total = total + loss;
			}
		}
		
		
		System.out.println(total);
		s.close();
		
	}

}


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

int main(void){
    int a[4];
    int b[4];
    
    while((scanf("%d", &a[0])) != EOF){
        int hitcount = 0;
        int bcount   = 0;
        
        for(int i = 1; i < 4; i++){
            scanf("%d", &a[i]);
        }
        
        for(int i = 0; i < 4; i++)
            cin >> b[i];
        
        //a???????????????????????????????´????b????????¢??¢?´¢
        for(int i = 0; i < 4; i++){
            int x = a[i];
            for(int j = 0; j < 4; j++){
                if(x == b[j]){
                    if(i == j) hitcount++;
                    else bcount++;
                }
            }
        }
        
        cout << hitcount << " " << bcount << endl;
    }
    
    return 0;
}

Measured memory_bytes: 1244
n,k=map(int,input().split())
a=list(map(int,input().split()))
i=0
s=set()
s.add(1)
order=[1]
while 1:
    if a[i] in s:
        order.append(a[i])
        break
    else:
        order.append(a[i])
        s.add(a[i])
    i=a[i]-1
for i in range(len(order)):
    if order[-1]==order[i]:
        idx=i
        break
#print(order)
cnt=len(order)-(idx+1)
if len(order)>k:
    print(order[k])
else:
    k-=len(order)
    order=order[idx+1:]
    #print(cnt)
    #print(order)
    k%=cnt
    #print(k)
    print(order[k])
#print(order)

Measured memory_bytes: 32684
n,d=map(int,input().split())
x=[list(map(int,input().split())) for i in range(n)]
cnt=0
import itertools
import math
com=itertools.combinations([i for i in range(n)],2)
for p,q in com:
    s=0
    for k in range(d):
        s+=(x[p][k]-x[q][k])**2
    if math.ceil(s**0.5)==s**0.5:
        cnt+=1
print(cnt)



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

int main(void){
  int N;
  int max = 0,p = 0;
  char ch,str[100];
  
  scanf("%d",&N);	getchar();
  while((ch = getchar()) != EOF){
    if(ch == 'I')	++p;
    else --p;
    
    if(max < p)	max = p;
  }
  printf("%d\n",max);
}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvl;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  string a, b, c;
  cin >> n >> a >> b >> c;
  int ans = 0;
  for (int i = 0; i < n; i++) {
    set<char> s;
    s.insert(a[i]);
    s.insert(b[i]);
    s.insert(c[i]);
    if (s.size() == 2)
      ans++;
    else if (s.size() == 3)
      ans += 2;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

long long at[51]={1};
long long pat[51]={1};
long long ans=0;

int am(long long x,int level){
		//printf("%lld,%d\n",x,level);
		if(x==-1)return 0;
		if(level==-1)return 0;
		if(x==at[level])ans+=pat[level];
		else if(x<=at[level-1]+1)am(x-1,level-1);
		else if(x==at[level-1]+2)ans+=pat[level-1]+1;
		else {
				ans+=pat[level-1]+1;
				am(x-(at[level-1]+2),level-1);
		}
		return 0;
}

int main(){
		int n,i;
		long long x;
		scanf("%d%lld",&n,&x);
		for(i=1;i<=50;i++)at[i]=at[i-1]*2+3;
		for(i=1;i<=50;i++)pat[i]=pat[i-1]*2+1;
		am(x,n);
		printf("%lld\n",ans);
		return 0;
}


Measured memory_bytes: 128
#include<stdio.h>
main()
{
  int h,w;
  int i,j;
  while(1)
    {
      scanf("%d %d",&h,&w);
      if(h==0 && w==0)break;
      for(i=0 ; i<h ; i++)
	{
	  if(i%2==0)
	    {
	      for(j=0 ; j<w ; j++)
		{
		  if(j%2==0)
		    {
		      printf("#");
		    }
		  else
		    {
		      printf(".");
		    }
		}
	    }
	  else
	    {
	      for(j=0 ; j<w ; j++)
		{
		  if(j%2==0)
		    {
		      printf(".");
		    }
		  else
		    {
		      printf("#");
		    }
		}
	    }
	  printf("\n");
	}
      printf("\n");
    }
  return 0;
}

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

using namespace std;

int main()
{
  int a,b;
  float t;
  cin>>a>>b>>t;
  int ans=0;
  for(int i=a;i<(t+0.5);i+=a)
  {
      ans+=b;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <vector>
#include <math.h>
#include <iostream>
using namespace std;
int main() {
	vector<double> vv;
	int n;
	cin >> n;
	while(n--) {
		int x;
		cin >> x;
		vv.push_back(x);
	}

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

	int i = 0;
	for (; ; ++i) {
		vv[i+1] = (vv[i] + vv[i+1]) /2; 
		if (i == vv.size() - 2) break;
	}
	cout << vv[i+1] << endl;
}

Measured memory_bytes: 888
#include<bits/stdc++.h>
using namespace std;
#define intt long long int
#define intu unsigned long long int
#define vi vector<int>
#define ii pair<int,int>
#define pb push_back
//#define mp make_pair
#define ff first
#define ss second
#define fast_io ios::sync_with_stdio(0);cin.tie(NULL);std::cout.tie(NULL);
# define PI           3.14159265358979323846 
#define all(a) a.begin(),a.end()
#define for0(i, n) for (int i = 0; i < n; i++)
#define for1(i, n) for (int i = 1; i <= n; i++)
#define loop(i,a,b) for (int i = a; i < b; i++)
#define bloop(i,a,b) for (int i = a ; i>=b;i--)
#define tc(t) int t; cin >> t; while (t--)
int mod = 1000000007;
intt gcd(intt a, intt b) {return b ? gcd(b, a % b) : a;}
intt lcm(intt a, intt b) {return a * b / gcd(a, b); }
intt bpow(intt a,intt b) 
{
  intt res = 1;
  while (b > 0) {
    if (b & 1)res = ((res%mod) * (a%mod))%mod;
      a = ((a%mod) * (a%mod))%mod;
      b >>= 1;
  }
  return res;
}
intt fact(intt n) { 
   if ((n==0)||(n==1))
      return 1; 
   else
      return n*fact(n-1);
}
void go()
{
#ifndef ONLINE_JUDGE
  freopen("inn.txt","r",stdin);
  freopen("o.txt","w",stdout);
  #endif
}
///////////U L R D
int dx[4]={0,-1,1,0};
int dy[4]={1,0,0,-1};

template <typename T1, typename T2>
struct less_second {
    typedef pair<T1, T2> type;
    bool operator ()(type const& a, type const& b) const {
        return a.second > b.second;
    }
};

int main() 
{ 
    fast_io
    go();
    int r,g,b;cin>>r>>g>>b;
    int k;cin>>k;

    if(g>r && b>g)
    {
      cout << "Yes" <<"\n";
    }
    else
    {
      bool f=0;
      while(k--)
      {
        if(g<=r)
        {
          g*=2;
          continue;
        }
        if(b<=g)
        {
          b*=2;
        }
      }
      if(g>r && b>g)
      {
        cout << "Yes" <<"\n";
      }
      else
        cout <<"No" <<"\n";
    }


} 





/*
From 
400
 through 
599
: 
8
-kyu
From 
600
 through 
799
: 
7
-kyu
From 
800
 through 
999
: 
6
-kyu
From 
1000
 through 
1199
: 
5
-kyu
From 
1200
 through 
1399
: 
4
-kyu
From 
1400
 through 
1599
: 
3
-kyu
From 
1600
 through 
1799
: 
2
-kyu
From 
1800
 through 
1999
: 
1
-kyu

*/






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

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

    int n;
    cin >> n;
    string s;
    cin >> s;

    int ec, wc = 0, ans = 1e9;
    ec = count(s.begin(), s.end(), 'E');
    
    REP(i, n){
        if(s[i] == 'E') ec--;
        ans = min(ans, wc + ec);
        if(s[i] == 'W') wc++;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 848
import java.util.Scanner;
import java.util.Arrays;
public class Main{
    static int dp[][]=new int[2000][2000];
	public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int num = sc.nextInt();
        int ans[]=new int[num];
        for(int i=0;i<num;i++){
            String str1=sc.next();
            String str2=sc.next();
            for(int x=1;x<=str2.length();x++){
                for(int y=1;y<=str1.length();y++){
                    String temp1=String.valueOf(str1.charAt(y-1));
                    String temp2=String.valueOf(str2.charAt(x-1));
                    if(temp1.equals(temp2)){
                        dp[x][y]=dp[x-1][y-1]+1;
                    }
                    else{
                        if(dp[x-1][y]>dp[x][y-1]){
                            dp[x][y]=dp[x-1][y];
                        }
                        else{
                            dp[x][y]=dp[x][y-1];
                        }
                    }
                }
            }
            ans[i]=dp[str2.length()][str1.length()];
        }
        for(int i=0;i<num;i++){
            System.out.println(ans[i]);
        }
    }
}

Measured memory_bytes: 303328
#include <bits/stdc++.h>
using namespace std;
#define int long long int
mt19937 rng(chrono::duration_cast<chrono::nanoseconds>(chrono::high_resolution_clock::now().time_since_epoch()).count());
#define mp make_pair
#define pb push_back
#define F first
#define S second
const int N=200005;
#define M 1000000007
#define double long double
#define BINF 10000000000001
#define init(arr,val) memset(arr,val,sizeof(arr))
#define MAXN 5000004
#define deb(x) cout << #x << " " << x << "\n";
const int LG = 22;



#undef int 
int main() {
#define int long long int
ios_base::sync_with_stdio(false); 
cin.tie(0); 
cout.tie(0);
 

 


    string s;
    cin >> s;
    if(s[2] == s[3] and s[4] == s[5])
        cout << "Yes";
    else
        cout << "No";
    
    





return 0;  
}

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

typedef long long ll;

using namespace std;

#define swap(a, b)    do { typeof(a) __tmp = (a); (a) = (b); (b) = __tmp; } while(0)
#define repd(i, a, b) for(typeof(b) i = a; i < (b); ++i)
#define rep(i, n)     repd(i, 0, n)
#define dump(x)       cerr << #x << " = " << (x) << endl
#define debug(x)      cerr << "L" << __LINE__ << ": " << #x << " = " << (x) << endl
#define YesNo(x)      cout << ((x) ? "Yes" : "No") << endl
#define YESNO(x)      cout << ((x) ? "YES" : "NO") << endl
#define absi(x)       ( ((x) >= 0) ? (x) : (-(x)) )

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

	ll ret = 0;
	for(ll i = 1; i * i <= n; ++i) {
		if( (n - i) % i == 0 ) {
			if((n - i) / i > i) { // n = 10^12, i = 10^6 の場合に必要になるが、
				                  // ループ範囲を変えて対応すると hand_02.txt と rand_18.txt が WA になる
				                  // 理由は分かっていません
				ret += (n - i) / i;
			}
		}
	}
	cout << ret << endl;

	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int n,t,e,i,m,a;
  scanf("%d %d %d",&n,&t,&e);
  for(i=0;i<n;i++){
    scanf("%d",&a);
    m=t%a;
    if(m<=e||a-m<=e)break;
  }
  printf("%d\n",i-n?i+1:-1);
  return 0;
}

Measured memory_bytes: 596
while i = gets do
  a, b, c, d, e, f = i.split.map(&:to_f)
  x = (c * e - b * f) / (a * e - b * d) + 0.000
  y = (f * a - c * d) / (a * e - d * b) + 0.000
  printf("%.3f %.3f\n", x, y)
end

Measured memory_bytes: 8604
/**
 * Dont raise your voice, improve your argument.
 * --Desmond Tutu
 */

#include <bits/stdc++.h>
using namespace std;

const bool ready = []() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(12);
    return true;
}();

const double PI = acos(-1);
using ll= long long;
#define int ll
#define all(v) (v).begin(), (v).end()
#define fori(n) for(int i=0; i<int(n); i++)

#define cini(i) int i; cin>>i;
#define cins(s) string s; cin>>s;
#define cind(d) double d; cin>>d;
#define cinai(a,n) vi a(n); fori(n) { cin>>a[i]; }
#define cinas(s,n) vs s(n); fori(n) { cin>>s[i]; }
#define cinad(a,n) vd a(n); fori(n) { cin>>a[i]; }

using pii= pair<int, int>;
using pdd= pair<double, double>;
using vd= vector<double>;
using vb= vector<bool>;
using vi= vector<int>;
using vvi= vector<vi>;
using vs= vector<string>;

/* fix x and y, find numbers z
 */
const int N=10000;
void solve() {
    cini(n);

    for(int nn=1; nn<=n; nn++) {
        int ans=0;
        for(int x=1; x*x+x<nn; x++) {
            for(int y=x; x*x+y*y<nn; y++) {
                int nnn=x*x+y*y+x*y;

                nnn=nn-nnn;
                for(int z=y; z*z<nnn; z++) {
                    if(z*z+z*x+z*y==nnn) {
                        if(x==y && y==z) {
                            ans++;
                        } else if(x==y || y==z || x==z) {
                            ans+=3;
                        } else {
                            ans+=6;
                        }
                    }
                }
            }
        }
        cout<<ans<<endl;
    }
}

signed main() {
    solve();
}

// FIRST THINK, THEN CODE
// DO NOT JUMP BETWEEN PROBLEMS


Measured memory_bytes: 3592
size = 10 ** 5
is_prime = [True] * size
is_prime[0] = False
for i in range(1, int(size ** 0.5)):
  if not is_prime[i]:
    continue
  for j in range(2 * i + 1, size, i + 1):
    is_prime[j] = False
counts = [0] * size
for i in range(size):
  if is_prime[i] and is_prime[(i + 1) // 2]:
    counts[i] = counts[i - 1] + 1
  else:
    counts[i] = counts[i - 1]

q = int(input())
for _ in range(q):
  l, r = map(int, input().split())
  print(counts[r - 1] - (counts[l - 2] if l >= 2 else 1))

Measured memory_bytes: 5108
# F

N = int(input())

list_plus = []
list_minus = []
for i in range(N):
    S = input()
    state = 0
    min_state = 0
    for s in S:
        if s == '(':
            state += 1
        else:
            state -= 1
        min_state = min(min_state, state)
    
    if state > 0:
        list_plus.append((min_state, state))
    else:
        list_minus.append((min_state - state, -state))

def compute(arr):
    total_state = 0
    for min_state, state in arr[::-1]:
        if total_state + min_state < 0:
            print('No')
            exit()
        total_state += state
    return total_state

list_plus.sort()
total_state_plus = compute(list_plus)
list_minus.sort()
total_state_minus = compute(list_minus)

print('Yes' if total_state_plus == total_state_minus else 'No')

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

int main(){
  int64_t H;
  cin>>H;
  
  int s=1;
  while(H>=2){
    H=H/2;
    s++;
  }
  int64_t t=pow(2,s)-1;
  
  cout<<t<<endl;
  
  
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
using namespace std;

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

	int *a;
	a=(int *)malloc(n);

	int i;
	for (i=0;i<n;i++){
		cin >>  a[n-i-1];
	}
	for (i=0;i<n-1;i++){
		cout <<  a[i] << " ";
	}
	cout << a[n-1] << endl;

//	free(a);

	return 0;
}


Measured memory_bytes: 3112
#include <bits/stdc++.h>
     
using namespace std;
typedef long long ll;
const int nmax=200001; 
vector<int> V[nmax];
ll count1[nmax];
int N,Q;
ll ans[nmax];
void print_vector_int(vector<int> & S){
    int i,n;
    n = S.size();
    for(i=0;i<n;i++){
        if (i != 0) {
            cout << " ";
        }
        cout << S[i];
    }
    cout << endl;
}

void DFS(int start,int p){
    int i,n;
    // cout << "I am " << start << endl;
    if (p>=0){
        count1[start] += count1[p];
    }
    for(int c:V[start]){
        if (c != p){
            DFS(c,start);
        }
    }
    if (p<0){
        for(i=1;i<=N;i++){
            if(i!=1){
                cout << " ";
            }
            cout << count1[i];
        }
        cout << endl;
    }
}

void solve(){
    DFS(1,-1);
}

int main() {
    int i,j; 
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> N >> Q; 
    // cout << N << " " << Q << endl;
    i=0; 
    for(i=1; i<= N-1; i++){
        int x,y;
        cin >> x >> y;
        V[x].push_back(y);
        V[y].push_back(x);
    }
    //for(i=1; i<= N; i++){
    //    cout << i << " ";
    //    print_vector_int(V[i]);
    //}
    for(i=1;i<=N;i++){
        count1[i] = 0;
    }
    for(i=1;i<=Q;i++){
        int p,q;
        cin >> p >> q;
        count1[p] = count1[p] + q;
    }
    solve();
}


Measured memory_bytes: 24320
/*

*/
#include <bits/stdc++.h>
using namespace std;
#define pi acos(-1.0)
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define rep(i,a,n) for (ll i=a;i<n;i++)
#define per(i,a,n) for (ll i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((ll)(x).size())
#define cin1(x) cin >> x
#define cin2(x, y) cin >> x >> y
#define cin3(x, y, z) cin >> x >> y >> z
#define cou(x) cout << x
#define cous(x) cout << x << " "
#define coul(x) cout << x << "\n"
#define ret(x) return x
#define MAX 5000001
#define start int main() {   fastio
#define finish ret(0); }
#define Test ll _t; cin1(_t); while( _t-- )
typedef long long ll;
typedef vector<ll> VI;
typedef pair<ll,ll> PII;
typedef double db;
//mt19937 mrand(random_device{}());
const ll mod=1000000007;
//ll rnd(ll x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}ret(res);}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll fact[13];
void factorial() {   fact[0]=1;  rep(i, 1, 12) fact[i]=(fact[i-1]*i);  }
vector <ll> sie; //for sieve function
ll spf[MAX+7];  //for sieve function
void sieve() {    rep(i, 2, MAX)  {  if (spf[i] == 0) {  spf[i] = i;   sie.pb(i);  }    for (ll j=0; j<SZ(sie) && i*sie[j] <= MAX && sie[j] <= spf[i]; j++)   spf[i * sie[j]] = sie[j]; }   }
// head collected

string str;
ll k, m, tot, ans , te, u;
queue <ll> Q;

start;

    cin1(k);

    if ( k <= 9 ) {
        coul(k);
        ret(0);
    }
    rep(i, 1, 10) Q.push(i);

    for (ll i = 9; ; ) {
        if ( i == k ) break;
        te = Q.front();
        Q.pop();
        tot = te % 10;
        if( tot != 0){
            i++;
            ans = te*10+tot-1;
            Q.push(ans);
        }
        if ( i == k ) break;
        i++;
        ans = te*10+tot;
        Q.push(ans);
        if ( i == k ) break;
        if( tot != 9){
            i++;
            ans = te*10+tot+1;
            Q.push(ans);
        }
    }

    coul(ans);

finish



Measured memory_bytes: 768
#include <stdio.h>

int main(){
  char line[100];
  int r, c;
  fgets(line, sizeof(line), stdin);
  sscanf(line, "%d %d", &r, &c);
  int matrix[r+1][c+1];
  int i, j;
  int sum;
  int allsum=0;
  for(i=0; i<r; ++i){
	sum=0;
	for(j=0; j<c; ++j){
	  scanf("%d", &matrix[i][j]);
	  sum+=matrix[i][j];
	}
	matrix[i][c]=sum;
	allsum+=sum;
  }
  matrix[r][c]=allsum;
  for(j=0; j<c; ++j){
	sum=0;
	for(i=0; i<r; ++i){
	  sum+=matrix[i][j];
	}
	matrix[r][j]=sum;
  }
  for(i=0; i<=r; ++i){
	for(j=0; j<c; ++j)
	  printf("%d ", matrix[i][j]);
	printf("%d\n", matrix[i][c]);
  }
  return 0;
}



Measured memory_bytes: 2044
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define ll long long
#define P pair<int,int>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define pb push_back
#define eb emplace_back
template<class T>void chmax(T &a,T b){if(a<b)a=b;}
template<class T>void chmin(T &a,T b){if(a>b)a=b;}
constexpr int INF=1000000000000000000;
constexpr int mod=1000000007;
constexpr double eps=1e-8;
const double pi=acos(-1);
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int Random(int mi,int ma){
    random_device rnd;
    mt19937 mt(rnd());//32bit
    //[mi,ma]
    uniform_int_distribution<int>engine(mi,ma);
    return engine(mt);
}
int gcd(int a,int b){
    if(b==0)return a;
    return gcd(b,a%b);
}
int lcm(int a,int b){
    return a/gcd(a,b)*b;
}
bool prime(int a){
    if(a==1)return false;
    for(int i=2;i*i<=a;i++){
        if(a%i==0)return false;
    }
    return true;
}
int modpow(int a,int b){
    if(b==0)return 1;
    if(b%2)return modpow(a,b-1)*a%mod;
    int memo=modpow(a,b/2);
    return memo*memo%mod;
}
vector<int>kaijo,invkaijo;
void init_fact(int n){
    kaijo.resize(n+1);
    invkaijo.resize(n+1);
    kaijo[0]=1;
    for(int i=1;i<=n;i++){
        kaijo[i]=kaijo[i-1]*i;
        kaijo[i]%=mod;
    }
    rep(i,n+1)invkaijo[i]=modpow(kaijo[i],mod-2);
}
int comb(int a,int b){
    if(a<b)return 0;
    if(a<0||b<0)return 0;
    return kaijo[a]*invkaijo[a-b]%mod*invkaijo[b]%mod;
}
int inv(int x){
    x=modpow(x,mod-2);
    return x;
}
struct Segtree{
    int siz=1;
    vector<int>dat,laz;
    Segtree(int n){
        while(siz<n)siz*=2;
        dat.resize(siz*2-1,0);
        laz.resize(siz*2-1,0);
    }
    void eval(int k,int l,int r){
        if(laz[k]!=0){
            dat[k]+=laz[k];
            if(r-l>1){
                laz[2*k+1]+=laz[k];
                laz[2*k+2]+=laz[k];
            }
            laz[k]=0;
        }
    }
    void update(int a,int b,int x,int k=0,int l=0,int r=-1){
        if(r==-1)r=siz;
        eval(k,l,r);
        if(b<=l||r<=a)return;
        if(a<=l&&r<=b){
            laz[k]+=x;
            eval(k,l,r);
            return;
        }
        update(a,b,x,2*k+1,l,(l+r)/2);
        update(a,b,x,2*k+2,(l+r)/2,r);
        dat[k]=max(dat[2*k+1],dat[2*k+2]);
    }
    int query(int a,int b,int k=0,int l=0,int r=-1){
        if(r==-1)r=siz;
        if(b<=l||r<=a)return -INF;
        eval(k,l,r);
        if(a<=l&&r<=b)return dat[k];
        int vl=query(a,b,2*k+1,l,(l+r)/2);
        int vr=query(a,b,2*k+2,(l+r)/2,r);
        return max(vl,vr);
    }
};
int n,m;
vector<P>q[200010];
signed main(){
    cin.tie(0);ios::sync_with_stdio(false);
    cin>>n>>m;
    rep(i,m){
        int l,r,a;
        cin>>l>>r>>a;
        q[r].pb({l,a});
    }
    Segtree seg(n+1);
    for(int i=1;i<=n;i++){
        seg.update(i,i+1,seg.query(0,i));
        for(P p:q[i]){
            seg.update(p.fi,i+1,p.se);
        }
    }
    cout<<seg.query(0,n+1)<<endl;
    return 0;
}

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

using namespace std;

const int MAX_N = 55;
int n, m, depth[MAX_N], parent[MAX_N];
vector<int> tree[MAX_N];
long long status[25];

void dfs(int p, int u, int d)
{
    if (depth[u] != 0) return;
    depth[u] = d;
    parent[u] = p;
    for (int v: tree[u]) dfs(u, v, d+1);
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    for (int i = 0; i < n-1; ++i) {
        int u, v;
        cin >> u >> v;
        --u, --v;
        tree[u].push_back(v);
        tree[v].push_back(u);
    }
    dfs(-1, 0, 1);

    cin >> m;
    for (int i = 0; i < m; ++i) {
        int u, v;
        cin >> u >> v;
        --u, --v;
        if (depth[u] < depth[v]) swap(u, v);
        while (depth[u] > depth[v]) {
            status[i] |= 1ll<<u;
            u = parent[u];
        }
        while (u != v) {
            status[i] |= 1ll<<u;
            status[i] |= 1ll<<v;
            u = parent[u];
            v = parent[v];
        }
    }

    long long an = 0;
    for (int i = 0; i < 1<<m; ++i) {
        long long all_status = 0;
        int cnt = 0;
        for (int j = 0; j < m; ++j) if ((i>>j) & 1) {
            all_status |= status[j];
            ++cnt;
        }
        int edges = 0;
        for (int j = 0; j < n; ++j) if ((all_status>>j) & 1) {
            edges++;
        }
        long long val = 1ll<<(n-edges-1);
        if (cnt % 2) an -= val;
        else an += val;
    }
    cout << an << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
class status {
public:
    int miss[11], solve, time, id;
    bool operator<(const status & rhs) const{
        if(solve > rhs.solve) return true;
        else if(solve==rhs.solve && time < rhs.time) return true;
        else if(solve==rhs.solve && time == rhs.time && id < rhs.id) return true;
        return false;
    }
};

status a[51];

int main(void){
    int T, P, R;
    int team, prob, time;
    string msg;
    while(cin >> T >> P >> R && T) {
        rep(i, 52) {
            a[i].solve = a[i].time = 0;
            a[i].id = i+1;
            rep(j, 11) a[i].miss[j] = 0;
        }
        rep(i, R) {
            cin >> team >> prob >> time >> msg;
            team--;
            if(msg == "CORRECT") {
                a[team].solve++;
                a[team].time += a[team].miss[prob]*1200+time;
            } else {
                a[team].miss[prob]++;
            }
        }
        sort(a, a+T);
        rep(i, T) cout << a[i].id << " "<<  a[i].solve << " " << a[i].time << endl;
    }
}

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

int main()
{
	int N, M;
	cin >> N >> M;
	vector<int> factors;
	for (int d = 1; d <= (int)sqrt(M); ++d)
	{
		if (M % d == 0)
		{
			factors.push_back(d);
			factors.push_back(M / d);
		}
	}
	sort(factors.rbegin(), factors.rend());
	
	for (int i = 0; i < factors.size(); ++i)
	{
		if (M / factors[i] >= N)
		{
			cout << factors[i] << '\n';
			return 0;
		}
	}
}


Measured memory_bytes: 256
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::*;
#[allow(dead_code)]
fn getline() -> String {
    let mut ret = String::new();
    std::io::stdin().read_line(&mut ret).ok();
    return ret;
}
fn get_word() -> String {
    let mut stdin = std::io::stdin();
    let mut u8b: [u8; 1] = [0];
    loop {
        let mut buf: Vec<u8> = Vec::with_capacity(16);
        loop {
            let res = stdin.read(&mut u8b);
            if res.unwrap_or(0) == 0 || u8b[0] <= b' ' {
                break;
            } else {
                buf.push(u8b[0]);
            }
        }
        if buf.len() >= 1 {
            let ret = std::string::String::from_utf8(buf).unwrap();
            return ret;
        }
    }
}
fn parse<T: std::str::FromStr>(s: &str) -> T { s.parse::<T>().ok().unwrap() }

#[allow(dead_code)]
fn get<T: std::str::FromStr>() -> T { parse(&get_word()) }

fn main() {
    let n = get();
    let ma: i32 = get();
    let mb: i32 = get();
    let mut tbl = Vec::new();
    for _ in 0 .. n {
        let a: i32 = get();
        let b: i32 = get();
        let c: usize = get();
        tbl.push((a * mb - b * ma, c))
    }
    const W: usize = 100000;
    const BIAS: usize = 50000;
    const INF: usize = 12345678;
    let mut dp = vec![vec![INF; W]; n + 1];
    for i in 0 .. n {
        let (delta, c) = tbl[i];
        for j in 0 .. W {
            if j as i32 + delta >= 0 && W as i32 > j as i32 + delta {
                let nj = (j as i32 + delta) as usize;
                dp[i + 1][nj] = min(dp[i + 1][nj], dp[i][j] + c);
                if j == BIAS {
                    dp[i + 1][nj] = min(dp[i + 1][nj], c);
                }
            }
            dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
        }
    }
    if dp[n][BIAS] >= INF {
        println!("-1");
    } else {
        println!("{}", dp[n][BIAS]);
    }
}


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

int main() {
	int n,c,k;
	scanf("%d%d%d", &n, &c, &k);
	int prevT=-1, cu=0, ans=0;
	int t[n];
	for (int i=0; i<n; i++) {
		scanf("%d", &t[i]);
	}
	sort(t,t+n);
	for (int i=0; i<n; i++) {
		if (cu==c || (prevT!=-1 && prevT+k<t[i])) {
			prevT=-1;
			cu=0;
			ans++;
		}
		if (prevT==-1) prevT=t[i];
		cu++;
	}
	if (cu) ans++;
	printf("%d\n", ans);
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100000;
int n, a[maxn + 10];
bool vis[maxn + 10], f[maxn + 10];
vector<int> g[maxn + 10];

bool dfs(int p) {
	if (vis[p]) return f[p];
	vis[p] = 1;
	for (int i = 0; i < (int)g[p].size(); ++i) {
		int e = g[p][i];
		if (a[e] < a[p] && !dfs(e)) return f[p] = 1;
	}
	return f[p] = 0;
}

int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
	for (int i = 1; i < n; ++i) {
		int l, r; scanf("%d%d", &l, &r);
		g[l].push_back(r); g[r].push_back(l);
	}
	for (int i = 1; i <= n; ++i)
		if (dfs(i)) printf("%d ", i);
}


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

int gcd(int a, int b);
int gcd(const std::vector<int>& arr);

int main() {

        int age = 0;
        int cost = 0;
        std::cin >> age >> cost;

        if (age >= 13) {
                std::cout << cost << std::endl;
        }
        else if (12 >= age && age >= 6) {
                std::cout << cost / 2 << std::endl;
        }
        else {
                std::cout << 0 << std::endl;
        }

        return 0;
}

int gcd(int a, int b) {
        if (a > b) {
                std::swap(a, b);
        }

        for (int r = b % a; r != 0; b = a, a = r, r = b % a)
                ;

        return a;
}

int gcd(const std::vector<int>& arr) {
        const int size = arr.size();
        if (size == 0) {
                return 0;
        }
        else if (size == 1) {
                return arr[0];
        }

        int ret = gcd(arr[0], arr[1]);

        for (std::size_t i = 2; i < size && ret != 1; ++i) {
                ret = gcd(arr[i], ret);
        }

        return ret;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
using namespace std;
typedef long long ll;

int main()
{
	int n,x,t;
	cin>>n>>x>>t;
	if(n%x!=0)
		cout<<(n/x+1)*t;
	else
		cout<<n/x*t;
	
	return 0;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mk make_pair
#define rint register int
#define int ll
using namespace std;
const int mod = 1e9+7;
inline int read(){int w=1,s=0;char ch=getchar();while(!isdigit(ch)){if(ch=='-')w=-1;ch=getchar();}while(isdigit(ch)){s=s*10+ch-'0';ch=getchar();}return w*s;}
int n;
int A[1000010];
int fac[1000010],Sum[1000010],Ifac[1000010],S[1000010];
inline ll ksm(ll x,ll y){ll res=1;while(y){if(y&1) res=res*x%mod;x=x*x%mod;y>>=1;} return res;}
inline int C(int a,int b){return 1ll*fac[a]*Ifac[b]%mod*Ifac[a-b]%mod;}
inline void Init()
{	fac[0]=1;
	for(rint i=1;i<=5e5;++i) fac[i]=1ll*fac[i-1]*i%mod;
	Ifac[500000]=ksm(fac[500000],mod-2);Ifac[0]=1;
	for(rint i=499999;i;--i) Ifac[i]=1ll*(i+1)*Ifac[i+1]%mod;
}
signed main()
{
	n=read();
	for(rint i=1;i<=n;++i) A[i]=read();
	Init();
	for(rint i=1;i<=n;++i)
	{
		Sum[i]=Sum[i-1];
		Sum[i]+=1ll*fac[n]*ksm(i+1,mod-2)%mod;
		Sum[i]%=mod; 
	}ll res=0;
	for(rint i=1;i<=n;++i)
	{
		res+=1ll*(Sum[i-1]+Sum[n-i]+fac[n])%mod*A[i]%mod;
		res%=mod;
	}
	res%=mod;cout<<res;
	return 0;
}

Measured memory_bytes: 18688
import sys
import math
import collections
import itertools
import array
import inspect

# Set max recursion limit
sys.setrecursionlimit(10000)


# Debug output
def chkprint(*args):
    names = {
        id(v): k
        for k, v in inspect.currentframe().f_back.f_locals.items()
    }
    print(', '.join(
        names.get(id(arg), '???') + ' = ' + repr(arg) for arg in args))


# Binary converter
def to_bin(x):
    return bin(x)[2:]


def li_input():
    return [int(_) for _ in input().split()]


# --------------------------------------------

dp = None


def main():
    N = int(input())
    S = [input() for _ in range(2)]
    is_cols = []

    i = 0
    while i < N:
        if S[0][i] == S[1][i]:
            is_cols.append(True)
            i += 1
        else:
            is_cols.append(False)
            i += 2

    if is_cols[0]:
        ans = 3
    else:
        ans = 6

    i = 1
    while i < len(is_cols):
        if is_cols[i] and is_cols[i - 1]:
            ans *= 2
        elif not is_cols[i] and not is_cols[i - 1]:
            ans *= 3
        elif not is_cols[i] and is_cols[i - 1]:
            ans *= 2

        i += 1

    print(ans % 1000000007)


main()


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

#define for_(i,a,b) for(int i=(a);i<(b);++i)

int main() {
	int n, cnt[6] = {0};
	double mn = 160;
	
	cin >> n;
	
	for_(i,0,n) {
		double c;
		cin >> c;
		int p = min(5, int((c - mn) / 5.));
		++cnt[p];
	}
	
	for_(i,0,6) {
		cout << i + 1 << ":";
		for_(j,0,cnt[i]) cout << "*";
		cout << endl;
	}
}

Measured memory_bytes: 1232
#include<bits/stdc++.h>
using namespace std;
const int M=2e5+5;
int A[M],Q[M],r,B[M];

int main(){
	int n;
	scanf("%d",&n);
	for(int i=1,res; i<=n; i++){
		scanf("%d",&A[i]);
		A[i]&=1;
	}
	for(int i=n; i>=1; i--){
		int res=0;
		for(int j=i+i; j<=n; j+=i) res^=B[j];
		if(A[i]^res) Q[++r]=i, B[i]=1;
	}
	printf("%d\n",r);
	for(int i=r; i>=1; i--) printf("%d ",Q[i]);
	return 0;
}

Measured memory_bytes: 2816
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
X = Counter(a)
q = int(input())
b = [0 for _ in range(q)]
c = [0 for _ in range(q)]
for i in range(q):
    b[i], c[i] = map(int, input().split())

ans = sum(a)
for num, rep in zip(b, c):
    ans += (rep * X[num] - num * X[num])
    X[rep] += X[num]
    del(X[num])
    print(ans)

Measured memory_bytes: 29188
#include<stdio.h>
int main(void){
  double n;
  scanf("%lf",&n);
  if((int)n%2==0){
    int odd=n/2;
    printf("%lf",odd/n);
  }else{
    int odd=n/2+1;
    printf("%lf",odd/n);
  }
  return 0;
}

Measured memory_bytes: 128
#include<iostream>
using namespace std;
int main(){
  int n,m;
  while(cin >>n>>m,n||m){
    int f[101]={0},x=0;
    for(int i=0;;i++){
      if(i!=0) cin >>n>>m;
      if(n == 0 && m == 0) break;
      f[n]++;
      f[m]++;
    }
    for(int i=1; i<101; i++) x+=f[i]%2;
    if(x == 2) cout <<"OK"<<endl;
    else cout <<"NG"<<endl;
  }
  return 0;
}

Measured memory_bytes: 1152
#include<cstdio>
#include<cstring>
#include<stack>
#include<vector>
using namespace std;

const int MAXN = 123456;
int N, L[MAXN], R[MAXN], is_child[MAXN], root;

void preorder_traverse(int root) {
	stack<int> st;
	for(int i=root; ; ) {
		if(i != -1) {
			printf(" %d", i);
			st.push(i);
			i = L[i];
		} else {
			if(st.empty()) break;
			i = R[st.top()];
			st.pop();
		}
	}
}

void inorder_traverse(int root) {
	stack<int> st;
	for(int i=root; ; ) {
		if(i != -1) {
			st.push(i);
			i = L[i];
		} else {
			if(st.empty()) break;
			printf(" %d", st.top());
			i = R[st.top()];
			st.pop();
		}
	}
}

void postorder_traverse(int root) {
	vector<int> list;
	stack<int> st;
	for(int i=root; ; ) {
		if(i != -1) {
			list.push_back(i);
			st.push(i);
			i = R[i];
		} else {
			if(st.empty()) break;
			i = L[st.top()];
			st.pop();
		}
	}
	
	for(int i=list.size()-1; i>=0; i--) {
		printf(" %d", list[i]);
	}
}

struct Node {
	int id;
	bool left;
	Node(int id, bool left) : id(id), left(left) {}
};
void postorder_traverse_2(int root) {
	stack<Node> st;
	for(int i=root; ; ) {
		if(i != -1) {
			st.push(Node(i, true));
			i = L[i];
		} else {
			if(st.empty()) break;
			Node node = st.top();
			st.pop();
			if(node.left) {
				st.push(Node(node.id, false));
				i = R[node.id]; 
			} else {
				printf(" %d", node.id);
				i = -1;
			}
		}
	}
}

void postorder_traverse_3(int root) {
	stack<int> st;
	int prev = -1;
	for(int i=root; ; ) {
		if(i != -1) {
			st.push(i);
			i = L[i];
		} else {
			if(st.empty()) break;
			i = st.top();
			st.pop();
			if(R[i] == -1 || R[i] == prev) {
				printf(" %d", i);
				prev = i;
				i = -1;
			} else {
				st.push(i);
				i = R[i];
			}
		}
	}
}
 
int main() {
	#ifdef LOCAL
		freopen("in.txt", "r", stdin);
		freopen("out.txt", "w", stdout);
	#endif
	
	scanf("%d", &N);
	memset(is_child, 0, sizeof(is_child));
	for(int i=0; i<N; ++i) {
		int j;
		scanf("%d", &j);
		scanf("%d%d", &L[j], &R[j]);
		if(L[j] != -1) is_child[L[j]] = 1;
		if(R[j] != -1) is_child[R[j]] = 1;
	}
	
	for(int i=0; i<N; ++i) {
		if(!is_child[i]) {
			root = i;
			break;
		}
	}
	
	puts("Preorder");
	preorder_traverse(root);
	puts("");
	
	puts("Inorder");
	inorder_traverse(root);
	puts("");
	
	puts("Postorder");
	postorder_traverse_2(root);
	puts("");
	
	return 0;
}

Measured memory_bytes: 3256
import java.util.*;

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

    public static void main(String[]$) {
        int x = scanner.nextInt();
        int max = 1;
        for (int i = 2; i <= x; i++) {
            int j = i;
            while (true) {
                j *= i;
                if (j > x) {
                    break;
                }
                max = Math.max(max, j);
            }
        }
        System.out.println(max);
    }
}

Measured memory_bytes: 21716
#include <iostream>
#include <vector>
#include <array>
#include <set>
#include <cmath>
#include <string>
#include <sstream>
#include <queue> 
#include <list>
#include <stack>
#include <unordered_map>
#include <algorithm> 
#include <numeric>  
#include <functional>
#include <cassert>
#include <bitset>
#include <cctype>  
#include <iomanip> 
#include <limits>  
#include <regex>
// std::numeric_limits<int>::max(), min()
// std::setprecision(X)
// std::islower(), std::isupper(), std::tolower, std::toupper
// std::accumulate(m.begin(), m.end(), 0LL);
// std::sort(begin(),end()) // 0, 1, 2, 3 ,4 (default, less);
// std::priority_queue<int, vector<int>, less<int>> que; // 4, 3, 2, 1 (defualt, less) : 
// if ( std::regex_match(S, std::regex("(dream|dreamer|erase|eraser)*")) ) std::cout << "YES" << std::endl;
 
#define rep(i, n) for(int i = 0; i < (int)(n);    i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()

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; }
typedef long long ll;
typedef std::vector<int> vi;
typedef std::vector<std::vector<int>> vvi;

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

#define N_MAX 2000001
#define last(x) (*(x.end()-1))


int main (void) {
  std::cin.tie(0);  std::ios::sync_with_stdio(false);
  int N; std::cin >> N;
  std::vector<int> a(N); rep(i,N) std::cin >> a[i];
  
  int b = 1;
  for(int i=0; i<N; i++) {
    if ( a[i] == b ) b++;
  }
  b--;
  if ( N - b <= N-1 ) std::cout << N - b << std::endl;
  else std::cout << -1 << std::endl;
  return 0;
}


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

// types
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;
typedef vector<pll> vpl;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};


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

  string s;
  cin >> s;
  ll k;
  cin >> k;

  ll n = s.size();
  REP(i, n){
    ll need = 'z'-s[i]+1;
    need %= 26;
    if(need<=k){
      s[i] = 'a';
      k -= need;
    }
  }
  s[n-1] = 'a'+(s[n-1]-'a'+k)%26;

  cout << s << endl;
}


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

template<typename T>
class CumulativeSum{
public:
  int n;
  vector<T> sum;
  vector<T> A;
  int added;
  CumulativeSum():n(-1),added(0){}
  CumulativeSum(int n):n(n), sum(n+1), A(n+1),added(0){}
  CumulativeSum(const vector<T> &B):n(B.size()), sum(n+1), A(n+1),added(0){
    for(int i=1;i<=n;i++) sum[i] = sum[i-1] + B[i-1];
  }

  void apply(){
    for(int i=1;i<=n;i++) A[i] = A[i] + A[i-1];
    for(int i=1;i<=n;i++) A[i] = A[i] + A[i-1];
    for(int i=1;i<=n;i++) sum[i] = sum[i] + A[i-1];
    added = 0; A.clear(); A.resize(n+1);
  }

  //[l, r)にxを加算
  void add(int l, int r, T x){
    added = 1;
    assert(l <= r && 0 <= l && r <= n);
    A[l] = A[l] + x;
    A[r] = A[r] - x;
  }

  //[l, r)の和を得る
  T get(int l,int r){
    assert(l<=r && 0<=l && r<=n);
    if(added) apply();
    return sum[r] - sum[l];
  }
};

CumulativeSum<int> cum_cnt;
CumulativeSum<int> cum_sum;
const int N = 100005;
int n, m, A[N];

int Cnt(int x){
  int sum = 0;
  for(int i=0;i<n;i++){
    int k = x - A[i];
    if( k < 0 ) k = 0;
    if( N <= k ) continue;
    sum += cum_cnt.get( k, N );
  }
  return sum;
}

int Sum(int x){
  int sum = 0;
  for(int i=0;i<n;i++){
    int k = x - A[i];
    if( k < 0 ) k = 0;
    if( N <= k ) continue;
    sum += A[i] * cum_cnt.get( k, N );
    sum += cum_sum.get( k, N );
  }
  return sum;
}

bool check(int x){
  return Cnt( x ) >= m;
}

signed main(){
  
  cin>>n>>m;
  
  cum_cnt = CumulativeSum<int>( N );
  cum_sum = CumulativeSum<int>( N );
  
  for(int i=0;i<n;i++) cin>>A[i];
  
  for(int i=0;i<n;i++){
    cum_cnt.add( A[i], A[i] + 1, 1 );
    cum_sum.add( A[i], A[i] + 1, A[i] );
  }
  
  cum_cnt.apply();
  
  int L = 0, R = 200005;
  
  while( L + 1 < R ){
    
    int M = ( L + R ) / 2;
    
    if( check( M ) ) L = M;
    else R = M;
    
  }
  
  int ans = Sum( R );
  
  ans += L * ( m - Cnt( R ) );
  
  cout<<ans<<endl;
  
  return 0;
}


Measured memory_bytes: 4224
N = int(input())
A = list(map(int,input().split()))
t = [0 for k in range(8)]
s = 0

for x in A:
    if x < 400:
        t[0] = 1
    elif x < 800:
        t[1] = 1
    elif x < 1200:
        t[2] = 1
    elif x < 1600:
        t[3] = 1
    elif x < 2000:
        t[4] = 1
    elif x < 2400:
        t[5] = 1
    elif x < 2800:
        t[6] = 1
    elif x < 3200:
        t[7] = 1
    else:
        s += 1

print(max(1,t.count(1)),t.count(1)+s)

Measured memory_bytes: 3064
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		
		int num = scan.nextInt();
		
		ArrayList<String>  str = new ArrayList<String>();
		for(int i = 0 ; i < num ; i++) {
			str.add(scan.next());
		}
		
		for(int j = 1 ; j < str.size() ; j++) {
			if(str.get(j - 1).charAt(str.get(j - 1).length() - 1) != str.get(j).charAt(0)) {
				System.out.print("No");
				return;
			}
			
			String target = str.get(j);
			for(int k = 0 ; k < str.size() ; k++) {
				if(j != k) {
					if(target.equals(str.get(k))) {
						System.out.print("No");
						return;
					}
				}
			}
		}
		
		scan.close();
		
		System.out.print("Yes");
	}
}


Measured memory_bytes: 22612
// Sky's the limit :)
#include <bits/stdc++.h>
using namespace std;
#define int long long

signed main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    
    int T = 1; 
    // cin >> T; 
    while (T--) {
        int n;
        cin >> n;
        int a[n + 5], tot = 0;
        for(int i = 1; i <= n; i++) {
            cin >> a[i];
            tot ^= a[i];
        }

        for(int i = 1; i <= n; i++)
            cout << (tot ^ a[i]) << ' ';
        cout << '\n';
        
    }
    
    return 0;
}



Measured memory_bytes: 5256
#include <iostream>

using namespace std;

int main() {
    while (true) {
        int a, b;
        cin >> a >> b;
        if (a == 0 & b == 0) {
            return 0;
        }
        if (a > b) {
            cout << b << " " << a << endl;
        } else {
            cout << a << " " << b << endl;
        }
    }
}


Measured memory_bytes: 3072
#include<stdio.h>
    #include<stdlib.h>
    #include<string.h>
    #include<math.h>
    #include<iostream>
    #include<algorithm>
    #include<stack>
    #include<queue>
    #include<vector>
    #include<set>
    #include<map>
    #include<string>
    using namespace std;
    typedef long long ll;
    typedef pair<int,int>P;
    const int INF=0x3f3f3f3f;
    const double pi=acos(-1.0);
    const double eps=1e-9;
    const ll mod=1e9+7;
    map<ll,ll>m;
    ll solve(ll n)
    {
        if(m[n])return m[n];
        return m[n]=(solve(n/2)+solve((n-1)/2)+solve((n-2)/2))%mod;
    }
    int main()
    {
        ll n;scanf("%lld",&n);
        m[0]=1,m[1]=2;
        printf("%lld\n",solve(n));
        return 0;
    }

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<stack>
#include<vector>
#include<algorithm>
#include<cstring>
#pragma warning(disable:4996)
using namespace std;

int main(){
	stack<int> S1;
	stack<pair<int,int> >S2;
	char ch;
	int sum = 0;
	for(int i=0; cin >> ch; i++){
		if( ch=='\\' ) S1.push(i);
		else if( ch=='/' && S1.size()>0 ){
			int j = S1.top();
			S1.pop();
			sum += i - j;
			int a = i-j;
			while( S2.size()>0 && S2.top().first > j ){
				a += S2.top().second;
				S2.pop();
			}
			S2.push(make_pair(j,a));
		}
	}

	vector<int>ans;
	while(S2.size()>0){
		ans.push_back( S2.top().second);
		S2.pop();
	}
	reverse( ans.begin(), ans.end() );
	cout << sum << "\n";
	cout << ans.size();
	for(int i=0; i<ans.size(); i++){
		cout << " ";
		cout << ans[i];
	}
	cout << "\n";
	return 0;
}

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

using namespace std;

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

using i64 = long long;
using pii = pair<i64, i64>;

template<class A, class B>inline bool chmax(A &a, const B &b){return b > a ? a = b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b < a ? a = b,1 : 0;}

constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int MOD = int(1e9) + 7;

signed main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  string a, s, c;
  cin >> a >> s >> c;
  cout << 'A' << s[0] << 'C' << "\n";
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>

using namespace std;
int main(){
	int N, M;
	cin >> N >> M;
	if(N >= M){
		cout << 0 << endl;
	}
	else{
		int X[M];
		for(int i=0;i<M;i++){
			cin >> X[i];
		}
		sort(X,X+M);
		int L[M];
		L[0] = 0;
		for (int i=1;i<M;i++){
			L[i] = X[i] - X[i-1];
		}
		sort(L,L+M);
		int sum = 0;
		for (int i = 0;i <N-1;i++){
			sum = sum + L[M-i-1];
		}
		cout << X[M-1] - X[0] - sum << endl;
	}
}


Measured memory_bytes: 1024