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

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

typedef long long lint;

lint n, ans, lb[10], ub[10], ten[10], k;

bool isok(int cans) {
	int k = 0, nn = 0;
	
	while (cans > 0) {
		int x = cans % 10;
		nn += x * ten[k];
		cans /= 10;
		++k;
	}
	
	return n == nn;
}

bool rec(int x, int cans, int i) {
	if (i > k) {
		if (isok(cans)) {
			ans = cans;
			return 1;
		} else {
			return 0;
		}
	}
	
	int xx = x < 0 ? -x : x, ii = i;
	while (ii--) xx /= 10;
	int p = xx % 10;
	
	if (rec(x - ten[i] * p, cans + p * (i % 2 ? -ten[i] : ten[i]), i + 1)) return 1;
	if (rec(x - ten[i] * (10 - p), cans + (10 - p)  * (i % 2 ? -ten[i] : ten[i]), i + 1)) return 1;
	return 0;
}

int main() {
	lb[0] = 0; ub[0] = 9;
	lint mn = 0, mx = 9, add = -90;
	
	for_(i,1,10) {
		if (i % 2) {
			lb[i] = mn + add;
			ub[i] = mn - 1;
			mn = lb[i];
		} else {
			lb[i] = mx + 1;
			ub[i] = mx + add;
			mx = ub[i];
		}
		add *= -10;
	}
	
	ten[0] = 1;
	for_(i,1,10) ten[i] = ten[i-1] * -10;
	
	while (cin >> n, n) {
		k = 0;
		while (n < lb[k] || n > ub[k]) ++k;
		rec(n, 0, 0);
		cout << ans << endl;
	}
}

Measured memory_bytes: 1156
import string
import sys

number = []

all = list(string.ascii_lowercase)

for i in range(26):
    number.append(0)

moji = sys.stdin.read()
T = list(moji.lower())

for i in range(26):
    for j in range(len(moji)):
        if T[j] == all[i]:
            number[i] += 1

for i in range(26):
    print(all[i], ":", number[i])


Measured memory_bytes: 6676
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <bitset>

using namespace std;
typedef long long ll;

int main() {
	int x, y; cin >> x >> y;
	int s = 0;
	if (x < 4) { s += 100000 * (4 - x); }
	if (y < 4) { s += 100000 * (4 - y); }
	if (x == 1 && y == 1) {
		s += 400000;
	}

	cout << s << endl;
	return 0;
}

Measured memory_bytes: 256
/**
 *    author        : Sudipta Banik Trisha 
 *    created       : August 15, 2020 6:00 PM
 *    Problem Name  : A - Rainy Season
 *    Problem Limit : 2000 ms , 1024 MB
 *    Problem Url   : https://atcoder.jp/contests/abc175/tasks/abc175_a
 *    @genarated by : ai-virtual-assistant
**/

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

int main(){
    ios_base::sync_with_stdio(false);

    string s;
    cin >> s;
    int cnt=0,maxx=0;
    
    for(int i=0; i<s.length(); i++){
        if(s[i] == 'R'){
            cnt++;
            maxx = max(maxx,cnt);
        }
        else cnt=0;
    }
    cout << maxx << endl;
    return 0 ;
}


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

typedef long long ll;
using namespace std;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        int tax = i * 1.08;
        if (tax == n) {
            cout << i << endl;
            return 0;
        } else if (tax > n) {
            cout << ":(" << endl;
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int N,K;
  cin >> N >> K;
  int ans = 1;
  for (int i = 0; i < N; i++) {
    ans = min(ans * 2,ans + K);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>
 
using namespace std;

#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define REP(i,n) FOR(i,0,n)

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

long lcm(long a, long b){
	return (a*b) / gcd(a,b);
}
 
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a < b) { a = b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a > b) { a = b; return 1; } return 0; }

typedef long long ll;
 
const ll INF = 1ll<<29;
const ll MOD = 1000000007;
const double EPS = 1e-10;

int main(){
	int a, b, c;
	
	cin >> a >> b >> c;
	
	if (a > b){
		int tmp = a;
		a = b;
		b = tmp;
	}
	
	if (b > c){
		int tmp = b;
		b = c;
		c = tmp;
	}
	
	cout << a+b << endl;
	
	return 0;
}

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

typedef struct Node{
  int value;
  Node *parent, *left, *right;
} Node;

Node *NIL, *root;

void insert(int k){
  Node *y = NIL, *x = root, *z;

  //create new node
  z = (Node *)malloc(sizeof(Node));
  z->value = k;
  z->left = z->right = NIL;

  //search the position that insert new node into
  while(x != NIL){
    y = x;
    if(z->value < x->value) x = x->left;
    else x = x->right;
  }
  z->parent = y;

  if(y == NIL) root = z;
  else if(z->value < y->value) y->left = z;
  else y->right = z;
}

void preParse(Node *node){
  if(node == NIL) return ;

  cout << " " << node->value;
  if(node->left != NIL) preParse(node->left);
  if(node->right != NIL) preParse(node->right);
}

void inParse(Node *node){
  if(node == NIL) return ;

  if(node->left != NIL) inParse(node->left);
  cout << " " << node->value;
  if(node->right != NIL) inParse(node->right);
}

int main(){

  int n, key;
  string command;

  //input
  cin >> n;
  for(int i = 0;i < n;i++){
    cin >> command;
    if(command == "insert"){
      cin >> key;
      insert(key);
    }else if(command == "print"){
      inParse(root);
      cout << endl;
      preParse(root);
      cout << endl;
    }
  }

  return 0;
}




Measured memory_bytes: 26488
#include <stdio.h>
#include <iostream>
#include <vector>
#include <assert.h>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <stack>
#include <bitset>
#include <string>
#include <sstream>
#include <memory.h>
#include <time.h>
#include <string.h>
#include <stdlib.h>
#include <functional>
#include <algorithm>
using namespace std;
typedef long long ll;
int main()
{
	int n, k;
	scanf("%d%d", &n, &k);
	vector<int> v(n);
	for (int i = 0; i < n; ++i)
		scanf("%d", &v[i]);
	const int M = 1000000007;
	vector<vector<int> > dp(n + 1, vector<int>(k + 1));
	fill(dp[n].begin(), dp[n].end(), 1);
	for (int i = n - 1; i >= 0; --i) {
		for (int j = 0; j <= k; ++j) {
			int l = max(0, j - v[i]);
			int r = j;
			dp[i][j] = dp[i + 1][r];
			if (l) {
				dp[i][j] += M - dp[i + 1][l - 1];
				if (dp[i][j] >= M)
					dp[i][j] -= M;
			}
			if (j) {
				dp[i][j] += dp[i][j - 1];
				if (dp[i][j] >= M)
					dp[i][j] -= M;
			}
		}
	}
	printf("%d\n", (dp[0][k] - (k ? dp[0][k - 1] : 0) + M) % M);
	return 0;
}

Measured memory_bytes: 40192
#include <iostream>
#include <cmath>
#include <iomanip>
#include <limits>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <list>
#include <cctype>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0;i<(n);i++)

int main(){
    int R,G,B,n;
    cin >> R >> G >> B >> n;
    int ans=0;
    for(int r=0;r<=n;r++){
        for(int g=0;g<=n;g++){
            if(n-r*R-g*G>=0 && (n-r*R-g*G)%B==0) ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
#include<stdio.h>
#include <cstdint>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;


int n, m, ans, tmp;
int c[1001];
int a[1001];
int b[1001];

int main() {

	cin >> n >> m;
	rep(i, n)cin >> a[i];
	rep(i, m)cin >> b[i];

	rep(i, m) {
		rep(j, n) {
			if (b[i] >= a[j]) {
				c[j]++;
				break;
			}
		}
	}
	rep(i, n) {
		if (tmp < c[i]) {
			ans = i + 1;
			tmp = c[i];
		}
	}
	
	cout << ans << endl;

	return 0;
}


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

list2=[]

for i in range(n):
    list=[j for j in input().split()]
    list[1]=int(list[1])
    list2.append(list)

#print(list2)

list3=sorted(list2, key=lambda x:(x[0],-x[1]))

#print(list3)

for i in list3:
    print(list2.index(i)+1)


Measured memory_bytes: 3060
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include<math.h>
#include<iomanip>
#include<functional>
using namespace std;

#define ll long long
using vt = ll; //ここで数値の型を変えられる
#define rep(i, n) for (vt i = 0; i < (vt)(n); i++)
#define reps(i, s, n) for(vt i = (vt) (s); i < (vt) (n); i++) 
#define all(v) v.begin(), v.end()
#define P pair<int, int>
const ll  MOD = 1000000007;

int main() {
	ll n;
	cin >> n;
	vector<ll> d(n);
	rep(i, n) cin >> d.at(i);
	sort(all(d));
	cout << d.at(n / 2) - d.at(n / 2 - 1);
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,b) for (int i = (a); i <= (b); ++i)
#define REPD(i,a,b) for (int i = (a); i >= (b); --i)
#define FORI(i,n) REP(i,1,n)
#define FOR(i,n) REP(i,0,int(n)-1)
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define vi vector<int>
#define ll long long
#define SZ(x) int((x).size())
#define DBG(v) cerr << #v << " = " << (v) << endl;
#define FOREACH(i,t) for (typeof(t.begin()) i=t.begin(); i!=t.end(); i++)
#define fi first
#define se second

const int N = 4020;

char s[N][N];
int t[N][N];
int lo[N][N], x[N];
int st[N], q;
int le[N], ri[N];

int main() {
	int n,m;
	scanf("%d%d", &n, &m);
	FOR(i,n) scanf("%s", s[i]);
	FOR(i,n) FOR(j,m) t[i][j] = s[i][j] == '#';
	FOR(j,m-1) lo[n-1][j] = 1;
	for (int i = n-2; i >= 0; i--) {
		FOR(j,m-1) {
			if (t[i][j]^t[i+1][j]^t[i][j+1]^t[i+1][j+1]^1) lo[i][j] = lo[i+1][j] + 1;
			else lo[i][j] = 1;
		}
	}
	/*FOR(i,n) {
		FOR(j,m-1) printf("%d ", lo[i][j]);
		printf("\n");
	}*/
	int res = n;
	FOR(i,n) {
		FORI(j,m-1) x[j] = lo[i][j-1];
		FOR(j,m+1) {
			le[j]=0;
			ri[j]=m;
		}
		q = 1;
		st[0] = 0;
		x[0] = 0;
		x[m] = 0;
		FORI(j,m) {
			while (x[st[q-1]] > x[j]) {
				q--;
				ri[st[q]] = j;
			}
			st[q++] = j;
		}
		q = 1;
		st[0] = m;
		x[m] = 0;
		x[0] = 0;
		for (int j = m-1; j >= 0; j--) {
			while (x[st[q-1]] > x[j]) {
				q--;
				le[st[q]] = j;
			}
			st[q++] = j;
		}
		FORI(j,m-1) {
			//printf("j=%d, h=%d, seg= %d %d\n", j, x[j], le[j], ri[j]);
			res = max(res, x[j] * (ri[j]-le[j]));
		}
	}
	printf("%d\n", res);
	return 0;
}


Measured memory_bytes: 77568
k=int(input())
n=min(k+2,50)
a=list(range(n))
for i in range(n):
  a[i]+=k//n
for i in range(k%n):
  a[i]+=n
  for j in range(n):
    if i==j:continue
    a[j]-=1
print(n)
print(*a)

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

int main() {
    int N;
    cin >> N;
    
    vector<int> vec(N);
    for (int i = 0; i < N; i++){
        int a;
        cin >> a;
        vec.at(i) = a;
    }
    
    int alice = 0;
    int bob = 0;
    
    for (int i = 0; i < N; i++){
        int M = 0;
        
        for (int j = 0; j < vec.size(); j++){
            if (vec.at(j) > M){
                M = vec.at(j);
            }
        }
        
        if (i % 2 == 0){
          alice += M;
        }
        
        else {
            bob += M;
        }
        
        vector<int> vec2(vec.size()-1);
        bool flag = true;
        
        for (int k = 0; k < vec.size()-1; k++){
            if (vec.at(k) != M || flag == false){
                vec2.at(k) = vec.at(k);
            }
            else if (vec.at(k) == M){
                flag = false;
            }
        }
        
        for (int k = 0; k < vec.size()-1; k++){
            if (vec2.at(k) == 0){
                vec2.at(k) = vec.at(vec.size()-1);
            }
        }
        
        vec = vec2;
    }
    
    cout << alice - bob << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <functional>
#include <vector>
#include <map>
#include <set>
#include <tuple>

using namespace std;

#define D(x) x
#define REP(i,a,b) for (int i = (a); i < (b); ++i)

int main() {
    ios_base::sync_with_stdio(false);
    cout << setprecision(12) << fixed;

    string s; int K;
    cin >> s >> K;

    REP(pos,0,s.length() - 1) {
        if (s[pos] == 'a' || 'z' - s[pos] + 1 > K)
            cout << s[pos];
        else {
            cout << 'a';
            K -= ('z' - s[pos] + 1) % 26;
        }
    }
    int c = s[s.length() - 1];
    c += K % 26;
    if (c > (int)'z')
        c -= 26;
    cout << (char)c << endl;
	return 0;
}


Measured memory_bytes: 720
#include <bits/stdc++.h>
using namespace std;
int main () {
  long A, B, C;
  cin >> A >> B >> C;
  if(C - A - B >= 0 && 4 * A * B < (C - A - B) * (C - A - B)){
    cout << "Yes" << endl;
  } else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>

int main() {
  // 入力
  int a_weight, b_weight, c_weight, d_weight;
  std::cin >> a_weight >> b_weight >> c_weight >> d_weight;

  // 傾き判定
  int left_weight = a_weight + b_weight;
  int right_weight = c_weight + d_weight;
  std::string ans;
  if (left_weight > right_weight) {
    ans = "Left";
  } else if (left_weight < right_weight) {
    ans = "Right";
  } else {
    ans = "Balanced";
  }

  // 出力
  std::cout << ans << std::endl;

  return 0;
}


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


int main() {
   
   int n; 
   cin >> n;
   
   for (int i=1; i<=9; i++) {
       for (int j=1; j<=9; j++) {
           if (i*j == n) {
               cout << "Yes" << endl;
               return 0;
           }
       }
   } 
   cout << "No" << endl;
}

Measured memory_bytes: 3652
s=int(input())

chk = set([s])
def f(a):
  if a%2 == 0:
    return a/2
  else:
    return 3*a+1

for i in range(2,1000000):
  s = f(s)
  if s in chk:
    print(i)
    break
  chk.add(s)


Measured memory_bytes: 2940
def main():
    d = int(input())
    c = [int(i) for i in input().split()]
    s = [[int(i) for i in input().split()] for _ in range(d)]
    last = [0] * 26
    for i in range(d):
        t = 0
        score = 0
        for j in range(26):
            sj = s[i][j] + c[j] * last[j]
            if sj > score:
                t = j
                score = sj
        last[t] = 0
        print(t + 1)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9500
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> pi;
int main(){
	int n,m;
	cin>>n>>m;
	vector<pi>edge;
	while(m--){
		int a,b;
		cin>>a>>b;
		edge.push_back(pi(a,b));
	}
	sort(edge.begin(),edge.end());
	int fin = edge[0].second;
	int ret = 0;
	for(int i=0; i<edge.size(); i++){
		if(edge[i].first<fin){
			fin = min(fin,edge[i].second);
		}
		else{
			ret++;
			fin = edge[i].second;
		}
	}
	cout<<ret+1;
}

Measured memory_bytes: 4320
#include<stdio.h>
#include<math.h>
long long int gcd(long long int x,long long int y)
{
    return x%y==0?y:gcd(y,x%y);
}
long long int LCM(long long int i,long long int j)
{
    return i%j==0?i:i/gcd(i,j)*j;
}
long long int t[1005];
int main()
{
    int n;
    int i;
    long long int p,j=1;
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        scanf("%lld",&t[i]);
        p=gcd(j,t[i]);
        j=t[i]/p*j;
    }
    if(t[n-1]>1000000000000000000)
    {
        return 0;
    }
    else
    {
        printf("%lld\n",j);
    }
}


Measured memory_bytes: 128
#abc164d
s=input()[::-1]
n=len(s)
cnt=[0]*2020
res=0
t=0
p=1
for c in s:
 c=int(c)
 t=(t+c*p)%2019
 p=(p*10)%2019
 cnt[t]+=1
res+=(cnt[0]+1)*cnt[0]//2
for i in cnt[1:]:
 res+=i*(i-1)//2
print(res)


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

int N, W;
int w[110], v[110];

long long dp[110][100010];

// i 番目の品物を見ている
// 残り使える重さが j
long long solve(int i, int j) {
    if(i > N) return 0;
    if(dp[i][j] != -1) return dp[i][j];
    long long ret = solve(i + 1, j); // i 番目を使わない遷移
    if(j - w[i] >= 0) ret = max(ret, solve(i + 1, j - w[i]) + v[i]);
    return dp[i][j] = ret;
}

int main() {
    cin >> N >> W;
    for(int i = 1; i <= N; i++)
        cin >> w[i] >> v[i];

    // 初期化
    for(int i = 0; i < 110; i++)
        for(int j = 0; j < 100010; j++)
            dp[i][j] = -1;

    cout << solve(1, W) << endl;
}

Measured memory_bytes: 86272
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1e9;
const int MOD = INF+7;
const ll LINF = 1e18;
#define rep(i,N) for(int (i)=0;(i)<(N);++(i))
#define rrep(i,N) for(int (i)=(N-1);(i)>0;--i)
#define FOR(i,j,N) for(int (i)=(j);(i)<(N);++(i))
#define all(v) v.begin(),v.end()
#define MP make_pair
#define pb(n) push_back(n)
#define int long long 

int POW(int x,int n){
    int res = 1;
    while(n){
        if(n%2) res *= x;
        x *= x;
        n >>= 1;
    }
    return res;
}

signed main(){
    int N,P;
    cin >> N >> P;
    bool all_even = true;
    rep(i,N){
        int a; cin >> a;
        if(a%2) all_even = false; 
    }

    int ans = 0;
    if(all_even) ans = P?0:POW(2,N);
    else ans = POW(2,N-1);

    cout << ans << endl;    
}

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

int main(){
  int n,a,b,i,f=0;
  cin>>n>>a;
    
  for(i=0;i<n-1;i++){
    cin>>b;
    if(a<b) f=0;
    else if(a-1==b && !f) f=1;
    else if(a!=b){
      cout<<"No";
      return 0;
    }
    a=b;
  }
  cout<<"Yes";
}

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

long long X;

int main(){
	cin >> X;

	long long cur = 100;

	for(long long i = 1; i >= 0; i++) {
		//cur = (long long)(cur * 1.01);
		cur += cur/100;
		if(cur >= X) {
			cout << i << endl;
			return 0;
		}
	}

}



Measured memory_bytes: 3628
#coding : UTF-8

N = int(input())
T,A = map(int,input().split())
H = list(input().split())
 

flag = 1
num = 0
for i,h in enumerate(H):
    t = float(T)-(float(h)*0.006)
    a = abs(A-t) 
    if flag == 1 :
        ans = a
        num = i
        flag = 0
    elif ans > a:
        ans = a
        num = i
print (num+1)

Measured memory_bytes: 3064
#include <iostream>
using namespace std;
int main(void){
  int N,t,B,C,i,j;
  cin >> N;
  for(i = 0 ; i < N ; i++){
    bool is = true;
    for( B = 0, C = 0, j = 0; j < 10; j++){
      cin >> t;
      if(B >= t && C >= t) is = false;
      if(is){
	if(B < t && C < t){
	  if(B < C) C = t;
	  else B = t;
	}
	else if(B < t) B = t;
	else if(C < t) C = t;
      }
    }
    if(is) cout << "YES" << endl;
    else cout << "NO" << endl;
  }
  return 0;
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<P1,ll> P2;
const ll INF=1000000000000000001;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};

int main() {

	string s;
	cin>>s;
	ll total=0;
	int f=0;
	for(int i=1; i<s.size(); i++){
		if(s[i]!='9'){
			f=1;
			break;
		}
	}
	if(s[0]=='2')total++;
	if(s[0]=='3')total=2;
	if(s[0]=='4')total=3;
	if(s[0]=='5')total=4;
	if(s[0]=='6')total=5;
	if(s[0]=='7')total=6;
	if(s[0]=='8')total=7;
	if(s[0]=='9')total=8;
	total+=(s.size()-1)*9;
	if(f==0)total++;
	cout<<total<<endl;

	return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
const int INF = 1<<29;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin() , v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)


int main(){
    int a, b, c, d, e, f; cin >> a >> b >> c >> d >> e >> f;
    int anso = 0, anst = 0;
    for(int i = 0; i <= f; i += 100 * a){
        for(int j = 0; i + j <= f; j += 100 * b){
            for(int k = 0; (i + j) / 100 * e >= k; k += c){
                for(int l = 0; (i + j) / 100 * e >= k + l && i + j + k + l <= f; l += d){
                    if(anso == 0) anso = k + l, anst = i + j + k + l;
                    else if((double) anso / anst < (double)(k + l) / (i + j + k + l)) anso = k + l, anst = i + j + k + l;
                }
            }
        }
    }
    cout << anst << " " << anso << endl;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	a := []string{"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"}
	var c string
	fmt.Scan(&c)
	for i := 0; i < len(a); i++ {
		if c == a[i] {
			fmt.Println(a[i+1])
		}
	}
}


Measured memory_bytes: 512
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
using namespace std;
using ll = int64_t;
#define rep(i, j, n) for (int i = j; i < (int)n; ++i)

template <typename T, class F = std::function<T(const T&, const T&)>>
class segment_tree {
public:
  segment_tree(size_t n, T i, F f) : identity(i), operation(f) {
    for (size = 1; size < n; size <<= 1) {}
    data.assign(size * 2, identity);
  }

  void update(size_t i, T value) {
    for (data[i += size] = value; i >>= 1;)
      data[i] = operation(data[i << 1], data[i << 1 | 1]);
  }
  // [a,b)
  T query(size_t l, size_t r) {
    T resL = identity;
    T resR = identity;
    for (l += size, r += size; l < r; l >>= 1, r >>= 1) {
      if (l & 1) resL = operation(resL, data[l++]);
      if (r & 1) resR = operation(data[--r], resR);
    }
    return operation(resL, resR);
  }

private:
  size_t size;         // num of leaves
  std::vector<T> data; // root index is 1
  T identity;
  F operation;
};

int main() {
  int n, q, t;
  string s;
  cin >> n >> s >> q;

  segment_tree st(n, 0, [](int a, int b) { return a | b; });
  rep(i, 0, n) {
    int c = s[i] - 'a';
    st.update(i, 1 << c);
  }

  rep(i, 0, q) {
    cin >> t;
    if (t == 1) {
      int j;
      char c;
      cin >> j >> c;
      --j;
      st.update(j, 1 << (c - 'a'));
    } else {
      int l, r;
      cin >> l >> r;
      --l;
      int res = st.query(l, r);
      cout << __builtin_popcount(res) << '\n';
    }
  }

  return 0;
}

Measured memory_bytes: 7980
//============================================================================
// Name        : abc132_d.cpp
// Author      : abb
// Version     :
// Copyright   : [My copyright notice]
// Description : Hello World in C++, Ansi-style
//============================================================================

/*
 D - Blue and Red Balls

 実行時間制限: 2 sec / メモリ制限: 1024 MB

 配点 : 400 点

 問題文
 K 個の青いボールと N-K 個の赤いボールがあります。同じ色のボールは区別が不可能です。すぬけ君と高橋君はこれらのボールで遊んでいます。
 まず、すぬけ君が、N 個のボールを左から右に一列に並べます。
 次に、高橋君は、これらのうち K 個の青いボールのみを回収します。高橋君は、1 回の操作で連続して並ぶ青いボールを何個でも回収することができます。高橋君は、常に K 個の青いボールを回収するのにかかる操作の回数が最小になるように行動します。
 K 個の青いボールを回収するために高橋君がちょうど i 回操作をする必要があるボールの並べ方は何通りあるでしょうか。 1 ≤ i ≤ K をみたす i それぞれについて答えを計算し、 10^9+7 で割った余りを答えてください。

 制約

 ・1 ≤ K ≤ N ≤ 2000
 */
#pragma GCC optimize ("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;

#define rep(i, m, n) for (int i = m; i < n; ++i)

// -----------------------------------------------------------------------------------------------

/** 法．10^9+7. */
const ll MOD = 1000000007;
/** 階乗テーブルのインデックス数．10^5 より少し大きいくらい． */
const ll TABLELEN = 101010;

/** 階乗．f[i] = i! mod MOD. */
ll f[TABLELEN];
/** 階乗の逆元．finv[i] = f[i]^(-1) = (i!)^(-1). */
ll finv[TABLELEN];
/** 整数の逆元．inv[i] = i^(-1). */
ll inv[TABLELEN];

/**
 * 階乗とその逆元のテーブルを初期化する．
 */
void init_fact_table() {
	f[0] = f[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	rep(i, 2, TABLELEN)
	{
		f[i] = (f[i - 1] * i) % MOD;
		// MOD を法として， i^(-1) ≡ -(MOD % i)^(-1) * (MOD / i).
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

/**
 * 組み合わせ数を計算する．
 * @param n
 * @param k
 * @return nCk を表す整数．
 */
ll combination(int n, int k) {
	if (n < k)
		return 0;
	if (n < 0 || k < 0)
		return 0;
	// n!/(k!(n-k)!) mod MOD
	return f[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

// -----------------------------------------------------------------------------------------------

/**
 * エントリポイント．
 * @return 0.
 */
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	int n, k;
	cin >> n >> k;

	init_fact_table();
	for (int i = 1; i <= k; ++i) {
		// i 回の操作が必要 => 取りたい球(合計 K 個)が i 箇所に挿入されている
		// => (n-k+1箇所のうち) i 箇所の選び方 × (k個の球の) i 箇所への分け方
		// => (n-k+1箇所のうち) i 箇所の選び方 × (k-1箇所のうちの) i-1 箇所の選び方
		cout << combination(n - k + 1, i) * combination(k - 1, i - 1)  % MOD << endl;
	}
	return 0;
}


Measured memory_bytes: 2688
import copy
h,w=map(int,input().split())
s=[]
for i in range(h):
	s.append(list(input()))

copyS=copy.deepcopy(s)


def check(y,x,s):
	ans=0
	for i in range(3):
		for j in range(3):
			X=x+i-1
			Y=y+j-1
			if 0<=X<w and 0<=Y<h:
				if s[Y][X]=="#":
					ans+=1
	return ans

for i in range(h):
	for j in range(w):
		if s[i][j]==".":
			copyS[i][j]=str(check(i,j,s))

for i in copyS:
	print("".join(i))


Measured memory_bytes: 3700
#if !defined(ONLINE_JUDGE)
    #include "prettyprint.hpp" 
#else
    #include <bits/stdc++.h>
    using namespace std;
    #define d(...) 1729
    #define cer(x) 13
#endif
const bool testcase=0;
typedef long long int ll;
#define INF LONG_MAX
#define MINF LONG_MIN 
#define MAXR 111111
const ll mod1 = 1000000007;
const ll mod2 = 998244353;



//loop 
#define loop(i,L,R) for (int i = L; i < R; i++) //next four are for "for loops"
#define loope(i,L,R) for (int i = L; i <= R; i++)
#define rloop(i,L,R) for (int i = L; i > R; i--)
#define rloope(i,L,R) for (int i = L; i >= R; i--)
#define nl cout<<'\n'



//misc
#define sz(x) ((int)((x).size()))
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL) 
#define checkbit(n,b) ( (n >> b) & 1)
#define test int _T_=1;if(testcase){cin>>_T_;}while(_T_--)



//vector
#define lastEle(vec) vec[vec.size()-1]
#define all(ve) ve.begin(),ve.end()
#define rall(x) x.rbegin(),x.rend()
#define fi first
#define se second



template<typename T>inline T mmod(T a,T b,T mod){return ((a%mod)*(b%mod))%mod;}
template<typename T>inline T smod(T a,T b,T mod){return ((a%mod)+(b%mod))%mod;}
template<typename T>bool isPrime(T n){for(T i=2;i*i<=n;i++)if(n%i==0)return 0;return 1;}
template<typename TAIL>inline void inp(TAIL& T){cin>>T;}
template<typename HEAD,typename... TAIL>inline void inp(HEAD &H,TAIL&... T){cin>>H;inp(T...);}
template<typename T>inline bool in_range(T a,T l,T r){return (a>=l&&a<=r);}
template<typename T,typename U>inline istream& operator >>(istream& in,pair<T,U> &a){in>>a.fi>>a.se;return in;}
template<typename T>inline istream& operator >>(istream& in,vector<T> &a){for(auto &x : a)in>>x;return in;}

ll lcm(ll a,ll b){return (max(a,b)/__gcd(a,b))*min(a,b);} 

// MAIN
void solve();
int main(){
    std::chrono::time_point<std::chrono::high_resolution_clock> start, end;
    start = std::chrono::high_resolution_clock::now();
    fast;
    #ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
        // for debug in error.txt
        freopen("error.txt", "w", stderr);
    #endif
    test {
        solve();
    }
    end = std::chrono::high_resolution_clock::now();
    ll elapsed_time = std::chrono::duration_cast<std::chrono::milliseconds>(end-start).count();
    cerr << "\nElapsed Time: " << elapsed_time << "ms\n";
    return 0;
}


// SOLVE 

void solve() {
    ll n,cnt = 0;
    cin >> n;
    string s;
    cin >> s;
    for(int i = 0 ; i < n; i++) {
        if(s[i] == 'W') {
            cnt++;
        }
    }
    ll ans = 0;
    for(int i = 0; i < n-cnt; i++) {
        if(s[i] == 'W') {
            ans++;
        }
    }
    cout << ans << '\n';
}



Measured memory_bytes: 3772
function Main(input) {
	function compareFunc(a, b) {
		return a - b;
	}
	input = input.trim().split("\n").map(function(x) { return x.split(" ")});
	var L1 = input[0].map(e => parseInt(e, 10));
	var A = L1[0] * 100;
	var B = L1[1] * 100;
	var C = L1[2];
	var D = L1[3];
	var E = L1[4];
	var F = L1[5];
	var ABList = [];
	var tmp;
	for (var i = 0; i < (F / A); i++){
		tmp = A * i;
		for (var j = 0; j < ((F - tmp) / B); j++){
			ABList.push(tmp + B * j);
		}
	}
	ABList.sort(compareFunc);
	ABList = ABList.filter(function (x, i, self) {
		return self.indexOf(x) === i;
	});
	var x = Math.floor(F * E / (100 + E));
	var CDList = [];
	for (var i = 0; i < (x / C); i++){
		tmp = C * i;
		for (var j = 0; j < ((x - tmp) / D); j++){
			CDList.push(tmp + D * j);
		}
	}
	CDList.sort(compareFunc);
	CDList = CDList.filter(function (x, i, self) {
		return self.indexOf(x) === i;
	});

	var CDbitmap = [];
	for (var i = 0; i <= x; i++){
		CDbitmap.push(0);
	}
	for (var i of CDList){
		CDbitmap[i] = 1;
	}
	// console.log(ABList,CDList,CDbitmap);

	var tmpDens, tmpCDLL, tmpCDHL;
	tmpDens = 0;
	ans = [0, 0];
	
	tmpCDHL = x;
	for (var i of ABList){
		tmpCDLL = Math.round(i * tmpDens);
		tmpCDHL = Math.min(Math.floor(i * E / 100), F - i);
		for (var j = tmpCDLL; j <= tmpCDHL; j++){
			if (CDbitmap[j] === 1){
				if ((j / i) >= tmpDens){
					ans[0] = i + j;
					ans[1] = j;
					tmpDens = j / i;
				}
				CDbitmap[j] = 0;
			}
		}
	}
	if (ans[1] === 0) ans[0] = A;
	console.log("%d %d", Math.round(ans[0]), Math.round(ans[1]));
}

Main(require("fs").readFileSync("/dev/stdin", "utf8")); 

Measured memory_bytes: 35100
#include<iostream>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    string s;
    cin>>s;
    int i,ct=0,maxR=0;
    for(i=0;i<=2;i++)
    {
        if(s[i]=='R')
        {
            ct++;
            if(i==2)
                maxR = max(maxR,ct);
        }
        else
        {
            maxR = max(maxR,ct);
            ct = 0;
        }
    }
    cout<<maxR<<"\n";
    return 0;
}


Measured memory_bytes: 3600
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

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

    static class EKnapsack2 {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.ni();
            int W = in.ni();
            long[] w = new long[n];
            int[] v = new int[n];
            for (int i = 0; i < n; ++i) {
                w[i] = in.nl();
                v[i] = in.ni();
            }
            long[] val = new long[100001];
            Arrays.fill(val, Long.MAX_VALUE);
            val[0] = 0;
            for (int i = 0; i < n; ++i) {
                for (int j = 100000; j >= 0; --j) {
                    if (j - v[i] >= 0 && val[j - v[i]] != Long.MAX_VALUE)
                        val[j] = Math.min(val[j], val[j - v[i]] + w[i]);
                }
            }
            for (int i = 100000; i >= 0; --i) {
                if (val[i] <= W) {
                    out.println(i);
                    break;
                }
            }
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int ni() {
            return Integer.parseInt(next());
        }

        public long nl() {
            return Long.parseLong(next());
        }

    }
}



Measured memory_bytes: 23380
#include <iostream>

using namespace std;

int main() {
  int a, b, c, x;
  cin >> a >> b >> c >> x;

  int y = 0, count = 0;
  for (int i=0; i <= a; i++){
    for (int j=0; j <= b; j++){
      for (int k=0; k <= c; k++){
        y = 500*i + 100*j + 50*k;

        if (x == y) count+=1;
      }
    }
  }
  cout << count << "\n";
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#define FOR(i,k,n)  for(int i = (k);i < (n);++i)
#define REP(i,n)    FOR(i,0,n)

using namespace std;
using ll = int64_t;
using vecint = vector<int>;
using vecll = vector<ll>;

struct BipartiteMatching {
  int V;
  vector<vector<int>> g;
  vector<int> match;
  vector<bool> used;
  bool dfs(int v) {
    used[v] = true;
    for (int u: g[v]) {
      int w = match[u];
      if (w < 0 || (!used[w] && dfs(w))) {
        match[v] = u; match[u] = v;
        return true;
      }
    }
    return false;
  }
public:
  BipartiteMatching (int v) : V(v), g(v), match(v), used(v) {}
  void add_edge(int u, int v) {
    g[u].push_back(v);
    g[v].push_back(u);
  }
  int maximum_matching(void) {
    int res = 0;
    boost::fill(match, -1);
    REP(v, V) {
      if (match[v] < 0) {
        boost::fill(used, 0);
        if (dfs(v)) res++;
      }
    }
    return res;
  }
};

int main()
{
  int n,m;
  cin>>n>>m;
  vector<vecint> a(n, vecint(m));
  REP(i,n)REP(j,m)cin>>a[i][j];
  vector<vector<bool>> used(n, vector<bool>(m, false));
  vector<vecint> b(m, vecint(n));
  REP(i,m){
    BipartiteMatching bm(n+n);
    REP(j,n) REP(k,m) {
      int r = (a[j][k]-1)/m;
      if (!used[j][k]) {
        bm.add_edge(j, r+n);
      }
    }
    bm.maximum_matching();
    REP(j,n) {
      int s = bm.match[j]-n;
      REP(k,m) {
        if (used[j][k]) continue;
        int r = (a[j][k]-1)/m;
        if (r == s) {
          b[i][j] = a[j][k];
          used[j][k] = true;
          break;
        }
      }
    }
  }
  REP(i,n) {
    REP(j,m) {
      if(j) cout<<' ';
      cout<<b[j][i];
    }
    cout<<endl;
  }
  REP(i,m) {
    boost::sort(b[i]);
  }
  REP(i,n) {
    REP(j,m) {
      if(j) cout<<' ';
      cout<<b[j][i];
    }
    cout<<endl;
  }
  return 0;
}


Measured memory_bytes: 512
use proconio::input;

fn main() {
    input! {
        s: String,
        t: String,
    }

    let mut ans = 0;

    let x = s.chars().collect::<Vec<char>>();
    let y = t.chars().collect::<Vec<char>>();

    for i in 0..s.len() {
        if x[i] != y[i] {
            ans += 1;
        }
    }

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


Measured memory_bytes: 4360
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;

int main() {
	int a, b, c, d, e, k;
	int m[5];
	int m_last[5];

	//cin >> a >> b >> c >> d >> e >> k;
	int small = 10;
	int s_i = 0;
	for (int i = 0; i < 5; i++) {
		cin >> m[i];
		a = m[i];

		a = a % 10;

		//cout << a << endl;
		if (a == 0) {
			a = 10;
		}
		if (a < small) {
			s_i = i;
			small = a;
		}
		m_last[i] = a;
	}

	int sum = 0;

	for (int i = 0; i < 5; i++) {
		//cout << i <<  "  " << s_i << endl;
		if (i != s_i) {
			sum += m[i] + 10 - m_last[i];
			//cout << m[i] << endl;
		}
	}
	sum += m[s_i];
	cout << sum << endl;
	return 0;

}

Measured memory_bytes: 256
using System;
using System.Text;

public class Test
{
	static public void Main( )
	{
		StringBuilder output = new StringBuilder();
		int[] rc = Array.ConvertAll( Console.ReadLine().Split( ' ' ), int.Parse );
		int r = rc[0];
		int c = rc[1];
		
		int[] total = new int[ c+1 ];
		int t = 0;
		for( var i=0; i<r; i++ ) {
			int[] nums = Array.ConvertAll( Console.ReadLine().Split( ' ' ), int.Parse );
			int sum = 0;
			for( var j=0; j<c; j++ ) {
				sum += nums[j];
				t += nums[j];
				total[j] += nums[j];
			}
			output.AppendLine( string.Join( " ", Array.ConvertAll( nums, Convert.ToString ) )+" "+sum.ToString() );
		}
		total[c]= t;
		output.AppendLine( string.Join( " ", Array.ConvertAll( total, Convert.ToString ) ) );
		
		Console.Write( output );
	}
}

Measured memory_bytes: 6068
#include <bits/stdc++.h>
#define REP(i, n) for (int i=0, i##_len=(n); i<i##_len; ++i)
#define FOR(i, a, b) for (int i=(a); i<(b); ++i)
using ll = long long;
using namespace std;

int main()
{
    ll A, B, C;
    cin >> A >> B >> C;

    ll ret = 0;
    ret += min(C, A+B+1);
    ret += B;

    cout << ret << endl;

    return 0;
}


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

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	string a;
	cin >> a;
	for (int i = 0; i < a.length(); i++)
	{
		if( a[i] == '?' ) cout << "D";
		else cout << a[i];
	}
	return 0;
}


Measured memory_bytes: 3376
import math
array=input().split(" ")
A=float(array[0])
B=float(array[1])
H=float(array[2])
M=float(array[3])
D1=float(H/12*360+(M/60*30))
D2=float(M/60*360)

D=float(abs(D1-D2))
if D>180:
  D=360-D
B2=float(pow(B,2))
A2=float(pow(A,2))

ans2=B2+A2-2*B*A*(math.cos(math.radians(D)))
ans=float(pow(ans2,0.5))
print('{:.20f}'.format(ans))

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

unsigned gcd(unsigned a, unsigned b) {
  if(a < b) gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,x;cin >> n >> x;
	vector<int> a(n);
	rep(i,n) cin >> a.at(i);
	rep(i,n) a.at(i)=abs(a.at(i)-x);
	if(n==1) cout << a.at(0) << endl;
	else{
		int r=gcd(a.at(0),a.at(1));
		for(int i=2;i<n;++i){
			if(r==1) break;
			r=gcd(r,a.at(i));
		}
		cout << r << endl;
	}
}

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

using namespace std;

int const N = 123456;

int ac = 0;
int ans[N], p[N], where[N], a[N], blocked[N];

vector<int> edges[N];

void shift(int start) {
	int v = start;
	int tmp = a[v];
	while (v != 0) {
		v = p[v];
		int ntmp = a[v];
		a[v] = tmp;
		where[a[v]] = v;
		tmp = ntmp;
	}
	a[start] = tmp;
	where[a[start]] = start;
	ans[ac++] = start;
}

int getdown(int v, int value) {
	int mx = -1;
	for (int to : edges[v]) {
		if (blocked[to]) continue;
		int got = getdown(to, value);
		if (got < 0) continue;
		if (mx < 0 || a[mx] < a[got]) {
			mx = got;
		}
	}
	if (mx < 0 && a[v] > value) {
		mx = v;
	}
	return mx;
	// while (true) {
	// 	int mx = -1;
	// 	for (int to : edges[v]) {
	// 		if (blocked[to]) continue;
	// 		if (a[to] < value) continue;
	// 		if (mx < 0 || a[mx] < a[to]) mx = to;
	// 	}
	// 	if (mx < 0) {
	// 		return v;
	// 	}
	// 	v = mx;
	// }
}

int main() {
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	for (int i = 1; i < n; i++) {
		cin >> p[i];
		edges[p[i]].push_back(i);
	}
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		where[a[i]] = i;
	}
	for (int i = 0; i < n; i++) blocked[i] = false;
	int cur = n - 1;
	while (cur >= 0) {
		while (a[0] != cur) {
			int v = where[cur];
			int u = getdown(v, a[0]);
			shift(u);
		}
		shift(cur);
		blocked[cur] = true;
		--cur;
	}
	cout << ac << '\n';
	for (int i = 0; i < ac; i++) {
		cout << ans[i] << '\n';
	}
}


Measured memory_bytes: 4608
/**
 *    author:  Baibhav Kumar
 *    created: 24.07.2020 19:00:00      
**/

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

int main() {
	string s;
	cin >> s;
	cout << (s=="ABC"?"ARC":"ABC") << endl; 
}


Measured memory_bytes: 3572
import Control.Applicative

import Control.Monad
    (when)

type Problem = Int

type Result = [Int]

solve :: Problem -> Result

solve n
    = [x | x <- [1..n], (mod x 3 == 0) || (elem '3' $ show x)]

input :: IO Problem

input
    = do
        [n] <- map read.words <$> getLine
        return n

output :: Result -> IO ()

output xs
    = putStrLn $ concat [" " ++ show x | x <- xs]
    
main :: IO ()

main = output =<< solve <$> input

Measured memory_bytes: 4184
s = input()
n = int(input())
for i in range(n):
	t = input().split()
	a = int(t[1])
	b = int(t[2])
	if t[0] == "print":
		print(s[a:b + 1])
	elif t[0] == "replace":
		s = s[0 : a] + t[3] + s[b + 1 : len(s)]
	elif t[0] == "reverse":
		u = s[a : b + 1]
		s = s[0 : a] + u[ : : -1] + s[b + 1 : len(s)]



Measured memory_bytes: 5608
#include<iostream>
using namespace std;
int main(){
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    if(a <= b && c <= d){
       cout << a+c << endl;
}
   else if(a <= b && c >= d){
       cout << a+d << endl;
}
else if(a >= b && c <= d){
       cout << b+c << endl;
}
else if(a >= b && c >= d){
       cout << b+d << endl;
}

}


Measured memory_bytes: 256
from random import randint
import sys
input = sys.stdin.readline
INF = 9223372036854775808


def calc_score(D, C, S, T):
    """
    開催日程Tを受け取ってそこまでのスコアを返す
    コンテストi 0-indexed
    d 0-indexed
    """
    score = 0
    last = [0]*26  # コンテストiを前回開催した日
    for d, t in enumerate(T):
        last[t] = d + 1
        for i in range(26):
            score -= (d + 1 - last[i]) * C[i]
        score += S[d][t]
    return score


def update_score(D, C, S, T, score, ct, ci):
    """
    ct日目のコンテストをコンテストciに変更する
    スコアを差分更新する

    ct: change t 変更日 0-indexed
    ci: change i 変更コンテスト 0-indexed
    """
    new_score = score
    last = [0]*26  # コンテストiを前回開催した日
    prei = T[ct]  # 変更前に開催する予定だったコンテストi
    for d, t in enumerate(T, start=1):
        last[t] = d
        new_score += (d - last[prei])*C[prei]
        new_score += (d - last[ci])*C[ci]
    last = [0]*26
    for d, t in enumerate(T, start=1):
        if d-1 == ct:
            last[ci] = d
        else:
            last[t] = d
        new_score -= (d - last[prei])*C[prei]
        new_score -= (d - last[ci])*C[ci]
    new_score -= S[ct][prei]
    new_score += S[ct][ci]
    return new_score


def local_search():
    pass


def main(D, C, S):
    T = []
    for d in range(D):
        # d日目終了時点で満足度が一番高くなるようなコンテストiを開催する
        max_score = -INF
        best_i = 1
        for i in range(26):
            T.append(i)
            score = calc_score(D, C, S, T)
            if max_score < score:
                max_score = score
                best_i = i
            T.pop()
        T.append(best_i)
    return T


if __name__ == '__main__':
    D = int(input())
    C = [int(i) for i in input().split()]
    S = [[int(i) for i in input().split()] for j in range(D)]
    T = [int(input())-1 for i in range(D)]
    M = int(input())
    DQ = [[int(i)-1 for i in input().split()] for j in range(M)]
    score = calc_score(D, C, S, T)
    for d, q in DQ:
        score = update_score(D, C, S, T, score, d, q)
        T[d] = q
        print(score)


Measured memory_bytes: 97420
n,m=map(int,input().split())
r=[[] for x in range(n)]
for c in range(m):
    a,b=map(int,input().split())
    r[a-1].append(b-1)
    r[b-1].append(a-1)
s=[-1]*n
u=[0]
v=[]
k=1
for c in range(10**5):
    for d in u:
        for e in r[d]:
            if s[e]==-1:
                s[e]=d
                k+=1
                v.append(e)
    if k>n-1:
        break
    u=v
print('Yes')
for c in range(n-1):
    print(s[c+1]+1)

Measured memory_bytes: 34652
n=int(input())
ans=0
l=map(int,input().split())
li=sorted(l)
for i in range(n):
    for j in range(i+1,n):
        for k in range(j+1,n):
            if li[i]!=li[j]!=li[k] and li[i]+li[j]>li[k]:
                ans+=1
print(ans)

Measured memory_bytes: 73456
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
using pil = pair<int, ll>;
using uint = unsigned int;
template <typename T>
using Graph = vector<vector<T>>;
const int MOD = 10007;
const ld PI = acosl(-1);

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

    int K;
    cin >> K;
    ll n = 0;
    int cnt = 0;
    bool isng = false;
    vector<bool> seen(K);
    do {
        n = (10 * n + 7) % K;
        if (seen[n]) {
            isng = true;
            break;
        }
        cnt++;
        seen[n] = true;
    } while (n);

    cout << (isng ? -1 : cnt) << endl;

    return 0;
}


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

long long int  nChoosek( int n, int k )
{
    if (k > n) return 0;
    if (k * 2 > n) k = n-k;
    if (k == 0) return 1;

    int result = n;
    for( int i = 2; i <= k; ++i ) {
        result *= (n-i+1);
        result /= i;
    }
    return result;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int N, M;
    cin >> N >> M;
    long long int  sum = 0;
    sum+= nChoosek(N, 2);
    sum+= nChoosek(M, 2);

    cout << sum <<endl;
    return 0;
}

Measured memory_bytes: 256
struct Rin{}
impl Rin{
    fn input(&self)->String{
        let mut x=String::new();
        std::io::stdin().read_line(&mut x).ok();
        x
    }
    fn inputs(&self)->String{
        let s=self.input().trim().to_string();
        s
    }
    fn inputn(&self)->i32{
        let n:i32=self.input().trim().parse().unwrap();
        n
    }
    fn inputvs(&self)->Vec<String>{
        let vs=self.input().trim().split(' ').map(|x|x.to_string()).collect();
        vs
    }
    fn inputvn(&self)->Vec<i32>{
        let vn=self.input().trim().split(' ').map(|x|x.to_string().parse().unwrap()).collect();
        vn
    }
}

fn main(){
    let r=Rin{};
    let k=r.inputn();
    let v=r.inputvn();
    let a=v[0];
    let b=v[1];
    if a<=b/k*k{
        println!("OK");
    }else{
        println!("NG");
    }
}

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

int main() {
    int N, L;
    cin >> N >> L;
    vector<int> A(N);
    int full = 0; 
    for (int i = 0; i < N; ++i){
        A[i] = i + L;
        full += A[i];
    }
    int ans = 1e9;

    for (int i = 0; i < N; ++i){
        int temp = full - A[i];
        if (abs(full - ans) > abs(full - temp)) ans = temp; 
    }

    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define sayyes cout<<"Yes"<<endl;
#define sayno cout<<"No"<<endl;
using namespace std;
typedef long long ll;
const double PI=acos(-1);
typedef pair<int,int>P;
const int mod =1e9+7;

int main()
{
    int h,w,k;
    cin>>h>>w>>k;
    vector< vector<char> > cake(h,vector<char>(w));
    vector< vector<int>> ans(h,vector<int>(w,0));
    int bb=0;
    rep(i,h)
    {
        int bc=0;
        rep(j,w)
        {
            cin>>cake[i][j];
            if(j==0)
            {
                bb++;
                ans[i][j]=bb;
                if(cake[i][j]=='#')bc++;
            }
            else
            {
                if(cake[i][j]=='#')
                {
                    if(bc!=0)
                    {
                        bb++;
                    }
                    ans[i][j]=bb;
                    bc++;
                }
                else ans[i][j]=bb;
                
            }
            
            
        }
        if(bc==0)
        {
            if(i>0)
            {
                rep(j,w)ans[i][j]=ans[i-1][j];

            }
            else
            {
                rep(j,w)ans[i][j]=0;
            }
            
            bb--;
        }

    }

    for(int i=h-1;i>=0;i--)
    {
        rep(j,w)
        {
            if(ans[i][j]==0)
            {
                ans[i][j]=ans[i+1][j];
            }
        }
    }
    
    rep(i,h)
    {
        rep(j,w)
        {
            cout<<ans[i][j]<<" ";
        }
        cout<<endl;
    }
}


Measured memory_bytes: 1280