akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
import java.io.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		String s = sc.next();
		int[] count = new int[26];
		for(int i = 0; i < s.length(); i++) {
			count[s.charAt(i) - 65]++;
		}
		
		int c = 0;
		for(int i = 0; i < 26; i++) {
			if(count[i] > 0) {
				c++;
				if(c > 2 || count[i] != 2) {
					System.out.println("No");
					return;
				}
			}
		}
		if(c < 2) {
			System.out.println("No");
			return;
		} else {
			System.out.println("Yes");
			return;
		}
			
	}

}


Measured memory_bytes: 21716
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <cstdio>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<ll, int> P;
#define rep(i,n) for(int i=0;i<(n);i++)
const int INF = 1e9;


int main(void){
	int n, a, b; cin >> n >> a >> b;
	b--;
	vector<int> t(n);
	rep(i, n) cin >> t[i];
	sort(t.begin(), t.end());
	int ans = 0;
	rep(i, n){
		if(a <= t[i] && t[i] <= b) ans++;
	}
	printf("%d\n", n - ans);
	return 0;
}

Measured memory_bytes: 256
#include<string.h>
main(){
	int N,M,i,x,y,d,l,v[4]={0,1,0,-1},w[4]={1,0,-1,0};
	char D[2],*S="NESW";
	for(;scanf("%d",&N),N;){
		int g[21][21]={0};
		for(i=0;i<N;i++){
			scanf("%d%d",&x,&y);
			g[x][y]=1;
		}
		x=y=10;
		scanf("%d",&M);
		for(i=0;i<M;i++){
			scanf("%s%d",D,&l);
			d=strchr(S,*D)-S;
			for(;l--;){
				x+=v[d];
				y+=w[d];
				if(g[x][y]){
					N--;
					g[x][y]=0;
				}
			}
		}
		puts(N?"No":"Yes");
	}
	exit(0);
}

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


int main (){
    int H,W;
    cin >> H >>W;
        string S[H];
    for(int i=0;i<H;i++){
        cin >> S[i];
    }
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            if(S[i].at(j)=='.'){
                int count=0;
                for(int I=i-1;I<i+2;I++){
                    for(int J=j-1;J<j+2;J++){
                        if(I>=0 && I<H && J>=0 && J<W){
                            if(S[I].at(J)=='#'){
                                count++;
                            }
                        } 
                        }
                    }
                    cout << count;
                }
                else{
                    cout << '#';
                }
            }
            cout << endl;
        }
}

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

int main()
{
ll n ;
cin >> n ;
vector<ll> a(n+1);
vector<ll> ans(n+1);
rep(i, n){
  ll aa;
  cin >> aa;
  a[aa]++;
}
vector<ll> v;
for(auto b:a){
  if(b!=0)v.push_back(b);
}
sort(v.begin(),v.end());
ans[v.size()]=v[0];
vector<ll> s;
s.push_back(0);
rep(i,v.size()){
  s.push_back(v[i]+s[i]);
}
ll sum=0;
rep(i,v.size()-1){
  sum+=v[i];
  ll lower = i+1; //上限のindex
  ll upper = v.size();     //上限のindex
  ll seenow;
  bool ok;
  ll su;
  ll anss;
  while (true)
  {
    seenow = (lower + upper) / 2;

    su=s[seenow]-s[i+1];
    if (sum>=v[seenow]*(seenow-i-1)-su)
      ok = true;
    else
      ok = false;
    //処理ここまで
    if (!ok)
    {
      upper = seenow;
      if (upper == lower + 1)
      {
        anss = seenow-1;
        break;
      }
    }
    else
    {
      lower = seenow;
      if (upper == lower + 1)
      {
        anss = seenow;
        break;
      }
    }
  }
  ans[v.size()-i-1]=v[anss]+(sum-(v[anss]*(anss-i)-(s[anss+1]-s[i+1])))/(anss-i);
}

rep(i,n)cout << ans[i+1] << endl;
return 0;
}

Measured memory_bytes: 16364
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
using namespace std;
using ll = long long;
const ll mod =  1000000007;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REP_FROM(i, j, n) for (int i = (j); i < (n); ++i)
#define all(x) (x).begin(),(x).end()

ll power(ll base, ll exponent, ll module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ ll root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
ll inverse(ll x){ return power(x, mod - 2, mod);}
struct combination{ vector<ll> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2, mod); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } ll C(int p, int q) const{ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };

string ng[] = {"AGC", "ACG", "GAC", "AGTC", "ATGC", "AGGC", "AGAC"};

char c[] = {'A', 'G', 'C', 'T'};
map<char, int> c_idx {
  {'A', 0},
  {'G', 1},
  {'C', 2},
  {'T', 3}
};

ll dp[4*4*4*4][101] = {};

ll solve(int n, int i, char p[]) {
  REP(j, 7) {
    int length = ng[j].size();
    bool invalid = true;
    REP(k, length) {
      if(ng[j][length - 1 - k] != p[k]) {
        invalid = false;
        break;
      }
    }
    if(invalid) {
      return 0;
    }
  }
  if(n==i) {
    return 1;
  }
  int history = 0;
  REP(j, min(4, i)) {
    history += power(4,j, mod) * c_idx[p[j]];
  }
  if(dp[history][i] != 0) {
    return dp[history][i] ;
  }

  ll ans = 0;
  REP(j, 4) {
    p[-1] = c[j];
    ans += solve(n, i+1, p-1);
    ans %= mod;
  }
  dp[history][i] = ans;
  return ans;
}

signed main() {
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  char tmp[1001] = {};
  char *p = tmp + 500;
  ll ans = solve(n, 0, p);
  cout << ans << endl;
}


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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using edge = pair<ll, P>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
using Graph = vector<vector<ll>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    int N;
    cin >> N;
    priority_queue<double, vector<double>, greater<>> queue;
    rep(i, N) {
        double v;
        cin >> v;
        queue.push(v);
    };
    while (queue.size() != 1){
        double a = queue.top(); queue.pop();
        double b = queue.top(); queue.pop();
        queue.push((a+b)/2);
    }
    cout << queue.top() << endl;


}

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


Measured memory_bytes: 256
s,f=input()[::-1],-1
while f<0:
    if s:
        if s[:5]=='maerd':
            s=s[5:]
        elif s[:5]=='esare':
            s=s[5:]
        elif s[:6]=='resare':
            s=s[6:]
        elif s[:7]=='remaerd':
            s=s[7:]
        else:
            f=0
    else:
        f=1
print(['NO','YES'][f])

Measured memory_bytes: 9248
def solve():
    n = int(input())
    w = list(map(int, input().split()))
    dif = 1000
    for i in range(len(w)):
        dif = min(dif, abs(sum(w[:i]) - sum(w[i:])))
    print(dif)





if __name__ == '__main__':
    solve()


Measured memory_bytes: 2940
#include <stdio.h>
#define MAX_LENGTH 100000
int main() {
    int s[MAX_LENGTH]={0};
    int t[MAX_LENGTH]={0};
    int n, m, counter=0;
    scanf("%d", &n);
    for(int i=0;i<n;i++){scanf("%d", &s[i]);}
    scanf("%d", &m);
    for(int i=0;i<m;i++){scanf("%d", &t[i]);}
    for(int i=0;i<m;i++)
    {
        for(int j=0;j<n;j++)
        {
            if(s[j]==t[i])
            {
                counter++;
                break;
            }
        }
    }
    printf("%d\n", counter);
    return 0;
}



Measured memory_bytes: 2628
// Created by sz
#include <bits/stdc++.h>
using namespace std;

const int N = 1e5 + 5;
int n,m, p[N];

class dsu {
public:
    vector<int> p;
    int n;
    
    dsu(int _n) : n(_n) {
        p.resize(n);//n nodes, 0 ~ n-1
        iota(p.begin(), p.end(), 0);
    }
    
    inline void re_init(){
        iota(p.begin(), p.end(), 0);
    }
    
    inline int findset(int x) {
        return (x == p[x] ? x : (p[x] = findset(p[x])));
    }
    
    inline bool unite(int x, int y) {
        x = findset(x);
        y = findset(y);
        if (x != y) {
            p[x] = y;
            return true;
        }
        return false;
    }
    int num_of_component(){
        int ans = 0;
        for (int i = 0; i < n; i++){
            if(i == findset(i)) ans++;
        }
        return ans;
    }
    
    void every_component_size(){
        map<int, int> cnt;
        for (int i = 0; i < n; i++){
            cnt[findset(i)] ++;
        }
        
        int num_comp = cnt.size();
        for (int i = 0; i < n; i++){
            cout<<cnt[findset(i)]<<' ';//每个节点所属连通分量的节点数量
        }
    }
};


int main(){
#ifdef LOCAL
    freopen("./input.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    cin>>n>>m;
    
    for (int i = 0; i < n; i++){
        cin>>p[i];
        p[i] --;
    }
    
    dsu d(n);
    
    int u,v;
    for (int i = 0; i < m; i++){
        cin>>u>>v;
        u--, v--;
        d.unite(u, v);
    }
    
    set<int> root;
    map<int, set<int>> root_pos, root_val;
    
    for (int i = 0; i < n; i++){
        root.insert(d.findset(i));
        root_pos[d.findset(i)].insert(i);
        root_val[d.findset(i)].insert(p[i]);
    }
    
    int ans = 0;
    for (auto i : root) {
        set<int> intersect;
        set_intersection(root_pos[i].begin(),root_pos[i].end(),root_val[i].begin(),root_val[i].end(),
                         inserter(intersect,intersect.begin()));
        ans += intersect.size();
    }
    
    cout<<ans<<endl;
    
    
    
    return 0;
}



Measured memory_bytes: 33792
n = int(input())
a = list(map(int,input().split()))
b = sum(map(int,input().split()))
c = list(map(int,input().split()))
for i in range(0,n-1):
  if a[i] == a[i+1] - 1:
    b += c[a[i]-1]
print(b)

Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i=0; i<(n); i++)
const int MX = 105, INF = 1e15;
struct edge{int t; ll c; int r;};
vector<edge> G[MX];
int lev[MX], n;
ll ans, a;
void add_edge(int f, int t, ll c){
	G[f].push_back(edge{t, c, (int)G[t].size()});
	G[t].push_back(edge{f, 0, (int)G[f].size()-1});
}
bool bfs(int s, int t){
	fill(lev, lev+n+2, -1);
	lev[s] = 0;
	queue<int> qu;
	qu.push(s);
	while(!qu.empty()){
		int v = qu.front(); qu.pop();
		for(edge& e: G[v]) if(e.c && lev[e.t] == -1){
			lev[e.t] = lev[v] + 1;
			qu.push(e.t);
		}
	}
	return lev[t] != -1;
}
ll dfs(int v, int t, ll f){
	if(v == t) return f;
	ll ret = 0;
	for(edge& e: G[v]){
		if(lev[v] < lev[e.t] && e.c){
			ll d = dfs(e.t, t, min(f - ret, e.c));
			if(d){
				e.c -= d; G[e.t][e.r].c += d;
				ret += d;
			}
		}
		if(f == ret) break;
	}
	return ret;
}
ll dinic(int s, int t){
	ll ret = 0;
	while(bfs(s,t)) ret += dfs(s, t, INF);
	return ret;
}

int main(){
	scanf("%d", &n);
	for(int i=1; i<=n; i++){
		scanf("%lld", &a);
		if(a < 0) add_edge(i,n+1,-a);
		else{
			ans += a;
			add_edge(0,i,a);
		}
		for(int j=i*2; j<=n; j+=i) add_edge(j,i,INF);
	}
	printf("%lld\n", ans-dinic(0,n+1));
}

Measured memory_bytes: 256
from copy import deepcopy

N,M  = [int(i) for i in input().split()]
ab   = [[int(i)-1 for i in input().split()] for j in range(M)]
edge = [[] for i in range(N)]
ans  = 0

for i in range(M):
        edge[ab[i][0]].append(ab[i][1])
        edge[ab[i][1]].append(ab[i][0])

def paint(tmpEdge):
        used=[False for i in range(N)]
        stack=[0]
        used[0]=True
        while len(stack)>0:
                now=stack[-1]
                stack.pop(-1)
                for nextP in tmpEdge[now]:
                        if used[nextP]==False:
                                used[nextP]=True
                                stack.append(nextP)

        #print(used)
        if False in used:
                return True
        else:
                return False

for i in range(M):
        tmpEdge=deepcopy(edge)
        tmpEdge[ab[i][0]].remove(ab[i][1])
        tmpEdge[ab[i][1]].remove(ab[i][0])
        if paint(tmpEdge):
                ans+=1
print(ans)

Measured memory_bytes: 3496
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
typedef long long ll;

int main() {
    int N, tmp, pre_height;
    vector<int> H;

    cin >> N;

    for (int i = 0; i < N; i++) {
        cin >> tmp;
        H.push_back(tmp);
    }

    for (int i = N - 2; i >= 0; i--) {
        // 何もしなくても後ろのマスが前のマスより高い場合
        if (H[i+1] >= H[i]) {
            ;
        }
        // 後ろのマスが前のマスの高さ-1以上の場合
        else if (H[i+1] >= H[i] - 1){
            H[i]--;
        }
        else {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

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

using namespace std;

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

    // freopen("input.txt", "r" , stdin);
    // freopen("output.txt", "w", stdout);

    int x,y,z;
    cin>>x>>y>>z;

    cout<<z<<" "<<x<<" "<<y;

    return 0;
}


Measured memory_bytes: 256
import sys
import heapq
import math
import fractions
import bisect
import itertools
from collections import Counter
from collections import deque
from operator import itemgetter
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

n=int(input())
s,t=map(str,input().split())
ans=[]
for i in range(n):
    ans.append(s[i])
    ans.append(t[i])
print(*ans,sep="")

Measured memory_bytes: 72804
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll MOD = 1000000007LL;
bool used[26];
int main() {
	string s;
	cin >> s;
	for (int i = 0; i < s.size(); i++) used[s[i] - 'a'] = 1;
	if (s.size() < 26) {
		for (int i = 0; i < 26; i++) {
			if (!used[i]) {
				s.push_back('a' + i);
				break;
			}
		}
		cout << s << endl;
		return 0;
	}
	for (int i = s.size() - 1; i >= 0; i--) {
		bool ok = 0;
		for (int j = s[i] - 'a' + 1; j < 26; j++) {
			if (!used[j]) {
				s[i] = 'a' + j;
				ok = 1;
				break;
			}
		}
		if (ok) {
			s.erase(i + 1);
			cout << s << endl;
			return 0;
		}
		used[s[i] - 'a'] = 0;
	}
	cout << -1 << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>

using namespace std;

int n, k, x, p, a[200001];
double rez, s;

int main()
{
    cin >> n >> k;
    for (int i = 1; i <= n; ++i) cin >> a[i];
    for (int i = 1; i <= n; ++i)
    {
        p = a[i] * (a[i] + 1) / 2;
        s = s + (p * 1.0 / a[i]);
        if (i >= k)
        {
            p = a[i - k] * (a[i - k] + 1) / 2;
            if (i - k > 0) s -= p * 1.0 / a[i - k];
            if (s > rez) rez = s;
        }
    }
    cout << fixed << setprecision(10) << rez;
	return 0;
}


Measured memory_bytes: 1152
A = ['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']
C = input()
for i in range(len(A)):
  if C == A[i]:
    break
print(A[i+1])

Measured memory_bytes: 3060
#include <cmath>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <list>
#include <time.h>
#include <math.h>
#include <random>
#include <deque>
#include <queue>
#include <cassert>
#include <unordered_map>
#include <iomanip>

using namespace std;

typedef long long ll;

mt19937 rnd(228);

int main()
{
#ifdef ONPC
    freopen("a.in", "r", stdin);
#endif
    int n;
    cin >> n;
    int cnt_4 = 0, cnt_2 = 0, cnt_1 = 0;
    for (int i = 0; i < n; i++)
    {
        int x;
        cin >> x;
        if (x % 4 == 0)
        {
            cnt_4++;
        }
        else if (x % 2 == 0)
        {
            cnt_2++;
        }
        else
        {
            cnt_1++;
        }
    }
    while (cnt_1)
    {
        if (!cnt_4)
        {
            if (n != 1)
            {
                cout << "No\n";
                return 0;
            }
            else
            {
                break;
            }
        }
        cnt_1--, cnt_4--;
        n -= 2;
    }
    cout << "Yes\n";
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
long long a[55];
bool Find;
int main()
{
	long long n,i,j,cnt,ans=0;
	cin>>n;
	for(i=1;i<=n;i++)cin>>a[i];
	Find=true;
	while(Find)
	{
		Find=false;
		for(i=1;i<=n;i++)
		{
			if(a[i]>=n)
			{
				Find=true;
				cnt=a[i]/n;
				a[i]=a[i]%n;
				ans+=cnt;
				for(j=1;j<=n;j++)
				{
					if(j!=i)a[j]=a[j]+cnt;
				}
			}
		}
	}
	cout<<ans;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
#define Priq priority_queue<int,vi,greater<int>>
#define pb push_back
#define mp make_pair
#define INF (1ll<<60)
int N;
int A[200000],F[200000];
int func(int X){
  int ret=0;
  rep(i,0,N)
    ret+=max(0ll,A[i]-X/F[i]);
  return ret;
}
signed main(){
  int K; cin>>N>>K;
  rep(i,0,N) cin>>A[i];
  rep(i,0,N) cin>>F[i];
  sort(A,A+N);
  sort(F,F+N,greater<int>());
  int left=0,right=1000000000000;
  while(left+1<right){
    int mid=(left+right)/2;
    if(func(mid)>K)
      left=mid;
    else
      right=mid;
  }
  int ans=right;
  if(func(left)<=K)
    ans=left;
  cout<<ans<<endl;
  }




Measured memory_bytes: 3328
import sys
from collections import deque
import copy
import math
def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline



def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [A, B, T] = [int(input_raw[0]), int(input_raw[1]), int(input_raw[2])]
    print (T/A) * B

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
int main()
{
	int n,m,c,b[25],a[25][25];
	cin >> n >>m>>c;
	for(int  i=0;i<m;i++) cin >> b[i] ;
	for(int i=0;i<n;i++) 
		for(int j=0;j<m;j++) 
			cin >>a[i][j] ;
	int f=0;
	for(int i=0;i<n;i++){
		int s=0;
		for(int j=0;j<m;j++){
			s+=a[i][j]*b[j] ;
		}
		if(s>-c) f++;
 	} 
 	cout <<f;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define PB push_back
#define ZERO (1e-10)
#define INF int(1e9+1)
#define CL(A,I) (memset(A,I,sizeof(A)))
#define DEB printf("DEB!\n");
#define D(X) cout<<"  "<<#X": "<<X<<endl;
#define EQ(A,B) (A+ZERO>B&&A-ZERO<B)
typedef long long ll;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
#define IN(n) int n;scanf("%d",&n);
#define FOR(i, m, n) for (int i(m); i < n; i++)
#define F(n) FOR(i,0,n)
#define FF(n) FOR(j,0,n)
#define FT(m, n) FOR(k, m, n)
#define aa first
#define bb second
void ga(int N,int *A){F(N)scanf("%d",A+i);}
#define MX (1<<20)
#define IS(A) ((cn[A>>6]>>(A&63))&1)
#define ST(A) (cn[A>>6]|=1ULL<<((A&63)))
ll P[MX>>1]={2},L(1),cn[1+(MX>>6)];
void gen(){
    ST(0),ST(1);
    int Q(1+sqrt(MX));
    for(ll i(4);i<MX;i+=2)ST(i);
    for(int k(3);k<=Q;k+=2)if(!IS(k))
        for(ll h(k<<1),j(k*k);j<MX;j+=h)ST(j);
    for(int i(3);i<MX;i+=2)if(!IS(i))P[L++]=i;
}
int fc(int N,int*f,int*c){
    int L(0);
    for(int i(0),h(0);N>=P[i]*P[i];++i,h=0){
        while(!(N%P[i]))++h,N/=P[i];
        if(h)f[L]=P[i],c[L++]=h;
    }
    if(N>1)f[L]=N,c[L++]=1;
    return L;
}
void rec(int*f,int*c,int p,int L,vi&o,int S){
    if(p==L)o.PB(S);
    else F(c[p]+1)rec(f,c,p+1,L,o,S),S*=f[p];
}
void dsr(int N,vi&o){
    o.clear();
    static int f[64],c[64];
    int L(fc(N,f,c));
    rec(f,c,0,L,o,1);
    sort(o.begin(),o.end(),greater<int>());
}
int N,A[MX],K,T,V[MX];
bool ok(int M){
    int I=0,J=N-1,q=0;
    F(N)V[i]=A[i]%M;
    sort(V,V+N);
    while(I<J){
        int m=min(V[I],M-V[J]);
        q+=m,V[I]-=m,V[J]+=m,V[J]%=M;
        if(q>K)return 0;
        I+=!V[I];
        J-=!V[J];
    }
    return 1;
}
vi o;
int main(void){
    gen(),scanf("%d%d",&N,&K),ga(N,A),T=accumulate(A,A+N,0);
    dsr(T,o);
    for(auto&h:o)if(ok(h))return printf("%d\n",h),0;
    assert(0);
    return 0;
}


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

long long mod = 1000000000 + 7;

long long modplus(long long a, long long b){
	long long ans = a + b;
	ans %= mod;
	return ans;
}
long long modminus(long long a, long long b){
	long long ans = a - b;
	ans %= mod;
	if(ans < 0) ans += mod;
	return ans;
}
long long modmul(long long a, long long b){
	long long ans = a * b;
	ans %= mod;
	return ans;
}

long long modpow(long long A, long long P){
	long long a = A, p = P;
	if(p == 0) return 1;
	if(p == 1) return a;
	long long adash = modmul(a,a);
	if(p % 2) return modmul(modpow(adash, p / 2), a);
	else return modpow(adash, p / 2);
}
long long moddiv(long long a, long long b){
	long long divisor = modpow(b, mod - 2);
	return modmul(a,divisor);
}

long long popcount(long long x){
	long long popc = 0;
	while(x > 0){
		if(x % 2 == 1) popc++;
		x /= 2;
	}
	return popc;
}

int func(char a, long long i, long long N, long long Xpp, long long Xpm, long long popc){
	int ans = 0;
	long long tmp = 0;
	if(a == '0'){
		mod = popc + 1;
		tmp = modplus(Xpp, modpow(2, N - i - 1));
		ans++;
	}
	else{
		if(popc == 1) return ans;
		mod = popc - 1;
		tmp = modminus(Xpm, modpow(2, N - i - 1));
		ans++;
	}
	while(tmp > 0){
		tmp %= popcount(tmp);
		ans++;
	}
	return ans;
}

int main(){
	long long N;
	string X;
	cin >> N >> X;
	long long popc = 0;
	for(long long i=0;i<N;i++){
		if(X[i] == '1')popc++;
	}
	long long Xpp = 0;
	mod = popc + 1;
	for(long long i=0;i<N;i++){
		if(X[i] == '1'){
			Xpp = modplus(Xpp, modpow(2, N - i - 1));
		}
	}
	long long Xpm = 0;
	mod = popc - 1;
	if(mod > 0){
		for(long long i=0;i<N;i++){
			if(X[i] == '1'){	
				Xpm = modplus(Xpm, modpow(2, N - i - 1));
			}
		}
	}
	for(long long i=0;i<N;i++){
		cout << func(X[i], i, N, Xpp, Xpm, popc) << endl;
	}
}


Measured memory_bytes: 3736
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <iomanip>
#include <cassert>
#include <random>
#include <tuple>
#include <cstdint>
#include <complex>
#include <bitset>

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

using namespace std;
typedef long long ll;
typedef pair<int, int> P;

const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

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


int main() {
    int n, k; cin >> n >> k;
    vector<int> a(n); rep(i, n) cin >> a[i];
    sort(a.begin(), a.end());

    // 単調性が成り立つことを示す。
    // k - a[i] <= S < k となるSが存在するとすると、
    // a[j] > a[i] を満たす任意のa[j]について、k - a[j] <= S' < k が成り立つようなS'が存在することが示せる。
    // (Sに a[j]が含まれる場合と、a[j]が含まれない場合に分けると示せた。)

    int left = -1;
    int right = n;
    int mid;
    while (right - left > 1) {
        mid = (left + right) / 2;
        bitset<5010> dp;
        dp[0] = 1;

        rep(i, n) {
            if (i != mid) {
                dp = dp | (dp << a[i]);
            }
        }

        bool flag = 0;
        for (int j = max(0, k - a[mid]); j < k; j++) {
            flag |= dp[j];
        }
        if (flag) right = mid;
        else left = mid;
    }

    cout << left + 1 << endl;

    return 0;
}


    

Measured memory_bytes: 256
# coding:utf-8

import sys
import math
import time
#import numpy as np
import collections
from collections import deque
from collections import Counter
import queue
import copy
import bisect
import heapq
import itertools


sys.setrecursionlimit(10**7)
#N, Q = map(int, input().split())
#G = [list(input()) for i in range(H)]
#INF = V * 10001
#A = [int(i) for i in input().split()]
#AB = [list(map(int, input().split())) for _ in range(K)]

N, X, T = map(int, input().split())
ans = 0
count = 0

while True:
    ans += T
    count += X
    if(N<=count):
        break

print(ans)


Measured memory_bytes: 68684
def extgcd(a, b):
    if b == 0:
        return a, 1, 0
    else:
        g, x, y = extgcd(b, a % b)
        return g, y, x - (a // b) * y

a, b = map(int, input().split())
_, x, y = extgcd(a, b)
print(x, y)


Measured memory_bytes: 5600
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <memory.h>
#include <queue>

using namespace std;
typedef long long LL;
typedef pair<int,int> mp;
const int maxn = 805;
const int inf = 1<<30;
int dx[]={0,0,1,-1};
int dy[]={1,-1,0,0};

char s[maxn][maxn];
int g[maxn][maxn],h,w,k,cx,cy,ans=inf;
queue<mp> q;
bool inG(int x,int y) {
	return x>=1&&y>=1&&x<=h&&y<=w&&s[x][y]!='#';
}

int main()
{
	#ifdef Amberframe
		freopen("agc014c.in","r",stdin);
		freopen("agc014c.out","w",stdout);
	#endif
	scanf("%d %d %d",&h,&w,&k);
	for (int i=1;i<=h;i++) scanf("%s",s[i]+1);
	for (int i=1;i<=h;i++)
	for (int j=1;j<=w;j++) g[i][j]=inf;
	for (int i=1;i<=h;i++)
	for (int j=1;j<=w;j++)
		if (s[i][j]=='S') cx=i,cy=j;
	
	g[cx][cy]=0;q.push(mp(cx,cy));
	while (!q.empty()) {
		int x=q.front().first;
		int y=q.front().second;
		q.pop();
		if (g[x][y]>=k) break;
		for (int nx,ny,d=0;d<4;d++)
		if (inG(nx=x+dx[d],ny=y+dy[d])&&g[nx][ny]==inf)
			g[nx][ny]=g[x][y]+1,q.push(mp(nx,ny));
	}
	for (int i=1;i<=h;i++)
	for (int j=1;j<=w;j++)
		if (g[i][j]<=k) ans=min(ans,min(min(i-1,h-i),min(j-1,w-j)));
	printf("%d",ans?(ans-1)/k+2:1);
	return 0;
}

Measured memory_bytes: 3456
#include<bits/stdc++.h>
#define ll long long 
using namespace std;
int main(){
	ios::sync_with_stdio(false);
	char c;
	cin>>c;
	if(isupper(c)){
		cout<<'A'<<'\n';
	}
	else{
		cout<<'a'<<'\n';
	}
	return 0;
}

Measured memory_bytes: 3640
#include<stdio.h>
#define MAX 100000

struct Card{
  char s;
  int v;
};

struct Card L[MAX], R[MAX];

void merge(struct Card A[], int n, int left, int mid, int right){
  int i, j, k;
  int n1 = mid - left;
  int n2 = right - mid;
  //左部分のマージ
  for( i = 0 ; i < n1 ; i++ ){
    L[i] = A[left + i];
  }
  // 右部分のマージ
  for( i = 0 ; i < n2 ; i++ ){
    R[i] = A[mid + i];
  }
  L[n1].v = R[n2].v = 2000000000;
  i = j = 0;
  for( k = left ; k < right ; k++){
    //　L側とR側に振り分け
    if( L[i].v <= R[j].v ){
      A[k] = L[i++];
    }else{
      A[k] = R[j++];
    }
  }
}

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

// 要素を分割し、要素の標準（ピボット）となる要素の番号を返す。
int partition(struct Card A[], int n, int p, int r){
  int i, j;
  struct Card t, x;
  // t 一時避難用、x元カード保持
  x = A[r];
  i = p - 1;
  for( j = p ; j < r ; j++ ){
    if( A[j].v <= x.v ){
      i++;
      t = A[i];
      A[i] = A[j];
      A[j] = t;
    }
  }
  t = A[i+1];
  A[i+1] = A[r];
  A[r] = t;
  return i + 1;
}

void quickSort(struct Card A[], int n ,int p, int r){
  int q;
  if( p < r ){
    // 要素の分割化
    q = partition(A, n, p, r);
    // 分割した左部分
    quickSort(A, n, p, q-1);
    // 分割した右部分
    quickSort(A, n, q+1, r);
  }
}

int main(){
  int i, n, v;
  //クイックソートとマージソートを比べるために二つ配列を用意する
  struct Card A[MAX], B[MAX];
  char S[10];
  int stable = 1;

  scanf("%d", &n);
  for( i = 0 ; i < n ; i++){
    scanf("%s %d", S, &v);
    A[i].s = B[i].s = S[0];
    A[i].v = B[i].v = v;
  }
  //マージソート
  m_sort(A, n, 0, n);
  //クイックソート
  quickSort(B, n, 0, n-1);

  for( i = 0 ; i < n ; i++){
    //クイックソートとマージソートを比べる
    if( A[i].s != B[i].s ) stable = 0;
  }

  if( stable == 1 ) printf("Stable\n");
  else printf("Not stable\n");
  for(i = 0 ; i < n ; i++){
    printf("%c %d\n", B[i].s, B[i].v);
  }
  return 0;
}



Measured memory_bytes: 4052
import sys

def solve(n):
    a = 0
    for s in str(n):
        a += int(s)
    if n%a == 0:
        return("Yes")
    else:
        return("No")

def readQuestion():
    line = sys.stdin.readline().rstrip()
    [str_a] = line.split(' ')
    return (int(str_a))

def main():
    a = readQuestion()
    answer = solve(a)
    print(answer)
    
if __name__ == '__main__':
    main()

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

int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  for (int i = 0; i < N; i++) {
    cin >> a.at(i);
  }
  sort(a.begin(), a.end());
  reverse(a.begin(), a.end());
  int result = 0;
  for (int i = 0; i < N; i++) {
    if (i % 2 == 0) {
      result += a.at(i);
    }
    else {
      result -= a.at(i);
    }
  }
  cout << result << endl;
}

Measured memory_bytes: 384
#include<stdio.h>

int max(int a,int b){if(a>b){return a;}return b;}

int tax(int x,int p){
  return (x*(100+p))/100;
}

int main(){
  int x,y,s,i,j,r,w;
  while(scanf("%d%d%d",&x,&y,&s),s!=0){
    r=0;
    i=1;j=s-1;
    while(i<=j){
      w=tax(i,x)+tax(j,x);
      if(w==s){r=max(tax(i,y)+tax(j,y),r);}
      if(w<=s){i++;}
      else{j--;}
    }
    printf("%d\n",r);
  }
}



Measured memory_bytes: 2096
#n:switch m:light
n,m=map(int,input().split())

#rule light switch
k=[]
for _ in range(m):
  temp = list(map(int,input().split()))[1:]
  inp=0
  for i in temp:
    inp+=2**(i-1)
  k.append(inp)

#number of on/off 
p=list(map(int,input().split()))

#print(k)

#binStr is status of switch
#swStr is target of switch 
#p is odd or even
def checkMod(binStr,swStr,p):
  #print(bin(binStr),bin(swStr))
  #print(">>",bin(binStr & swStr))
  if bin(binStr & swStr).count("1")%2==p:
    return 1
  else:
    return 0
  

  
result=0

for i in range(2**n):
  count=1
  for j in range(m):
    count=count*checkMod(i,k[j],p[j])
    if count==0:
      break
  if count==1:
    result+=1

print(result)




Measured memory_bytes: 3064
n = "keyence"
s = input()

for i in s:
    if n[0] == i:
        n = n[1:]
    else:
        break

for i in s[::-1]:
    if n == "":
        print("YES")
        exit()
    elif n[-1] == i:
        n = n[:-1]
    else:
        break

print("NO")

Measured memory_bytes: 9052
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Queue;
import java.util.StringTokenizer;

import static java.lang.Integer.parseInt;

/**
 * Cheese
 * JOI 10th, Pre.5
 */
public class Main {

	static final int[][] HV = {
			{1, 0},
			{-1, 0},
			{0, 1},
			{0, -1},
	};

	static char[][] map;
	static int H, W, N;

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;
		String[] words;

		StringTokenizer st = new StringTokenizer(br.readLine());

		H = parseInt(st.nextToken());
		W = parseInt(st.nextToken());
		N = parseInt(st.nextToken());

		map = new char[H + 2][W + 2];
		for (int i = 0; i < map.length; i++) {
			Arrays.fill(map[i], 'X');
		}

		//start pos
		int sy = 0, sx = 0;

		for (int i = 0; i < H; i++) {
			line = br.readLine();
			for (int j = 0; j < W; j++) {
				map[i + 1][j + 1] = line.charAt(j);
				if (map[i + 1][j + 1] == 'S') {
					sy = i + 1;
					sx = j + 1;
				}
			}
		}

		System.out.println(solve(sy, sx, 1));

	}

	static int solve(int y, int x, int target) {

		if (target > N) return 0;

		int res = 0;
		int sy = 0, sx = 0;

		char[][] _map = new char[map.length][];
		for (int i = 0; i < map.length; i++) {
			_map[i] = Arrays.copyOf(map[i], map[i].length);
		}
		Queue<int[]> q = new ArrayDeque<>();
		q.offer(new int[]{y, x, 0});
		_map[y][x] = 'X';

		outer:
		while (!q.isEmpty()) {
			int cy, cx, cd;
			cy = q.peek()[0];
			cx = q.peek()[1];
			cd = q.peek()[2];
			q.poll();

			for (int i = 0; i < HV.length; i++) {
				int ny, nx;
				ny = cy + HV[i][0];
				nx = cx + HV[i][1];
				if (_map[ny][nx] != 'X') {
					if (_map[ny][nx] - '0' == target) {
						sy = ny;
						sx = nx;
						res = cd + 1;
						break outer;
					} else {
						q.offer(new int[]{ny, nx, cd + 1});
						_map[ny][nx] = 'X';
					}
				}
			}
		}
		return res + solve(sy, sx, target + 1);
	}
}

Measured memory_bytes: 72548
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define veci vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define vec2(a,b) vector<vec>(a,vec(b))
#define vec2ll(a,b) vector<vec>(a,vecll(b))
#define vec3(a,b,c) vector<vector<vec>>(a,vec2(b,c))
#define vec3ll(a,b,c) vector<vector<vecll>>(a,vec2ll(b,c))
#define fi first
#define se second
#define all(c) begin(c),end(c)
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))


using namespace std;
int in() {int x;cin>>x;return x;}
ll lin() {ll x;cin>>x;return x;}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T> inline void print(pair<T,T> p){cout<<"("<<p.first<<","<<p.second<<") ";}
template<class T> inline void print(vector<pair<T,T>> v){for(auto e:v)print(e); cout<<endl;}
template<class T> inline void print(T v){for(auto e:v)cout<<e<<" ";cout<<endl;}
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
    for(T& x:vec) is >> x;
    return is;
}
const ll INF=1e9+100;


int main()
{
    ll n,r;
    cin >> n >> r;
    if(n>=10) cout << r << endl;
    else{
        cout << 100*(10-n)+r << endl;
    }
    return 0;
} 

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

int main() {
	int n, a, b;
	cin >> n >> a >> b;
	int ans = 0;
	for(int i = 1; i <= n; i++) {
		int c = 0;
		for(auto j : to_string(i)) {
			c += j - '0';
		}
		if(a <= c && c <= b) {
			ans += i;
		}
	}
	cout << ans << endl;
}

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

#define int long long
#define double long double
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n) for (int i = 1; i <= (n); i++)
#define all(x) (x).begin(), (x).end()
#define uniq(x) (x).erase(unique(all(x)), (x).end())
#define bit(n) (1LL << (n))
#define dump(x) cerr << #x " = " << (x) << endl
using vint=vector<int>;
using vvint=vector<vint>;
using pint=pair<int, int>;
using vpint=vector<pint>;
template<typename T> using priority_queue_rev=priority_queue<T, vector<T>, greater<T>>;
constexpr double pi = 3.1415926535897932384626433832795028L;
constexpr int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int gcd(int a, int b) {
    while (b) { swap(a %= b, b); }
    return a;
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
template<typename T> void fin(T mes) {
    cout << mes << endl;
    exit(0);
}
template<typename T1, typename T2> bool chmax(T1 &a, const T2 &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T1, typename T2> bool chmin(T1 &a, const T2 &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &rhs) {
    os << "(" << rhs.first << ", " << rhs.second << ")";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const vector<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
struct setup {
    static constexpr int PREC = 20;
    setup() {
        cout << fixed << setprecision(PREC);
        cerr << fixed << setprecision(PREC);
    };
} setup;

int H, W;
string S[2200];
bool flat[2200][2200];
int L[2200][2200], R[2200][2200], U[2200][2200], D[2200][2200];
signed main() {
    cin >> H >> W;
    rep(i, H) {
        cin >> S[i];
        rep(j, W) { flat[i][j] = S[i][j] == '.'; }
    }
    rep(i, H) {
        for (int j = 1; j < W; j++) { if (flat[i][j]) { L[i][j] = L[i][j - 1] + flat[i][j - 1]; }}
        for (int j = W - 2; j >= 0; j--) { if (flat[i][j]) { R[i][j] = R[i][j + 1] + flat[i][j + 1]; }}
    }
    rep(i, W) {
        for (int j = 1; j < H; j++) { if (flat[j][i]) { D[j][i] = D[j - 1][i] + flat[j - 1][i]; }}
        for (int j = H - 2; j >= 0; j--) { if (flat[j][i]) { U[j][i] = U[j + 1][i] + flat[j + 1][i]; }}
    }
    int ans = 0;
    rep(i, H)rep(j, W) { chmax(ans, L[i][j] + R[i][j] + U[i][j] + D[i][j] + 1); }
    cout << ans << endl;
}


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

#define INF_LL (ll)1e18
#define INF (int)1e9
#define REP(i, n) for(int i = 0;i < (n);i++)
#define FOR(i, a, b) for(int i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second
using ll = long long;
using PII = pair<int, int>;
using PLL = pair<ll, ll>;

const double eps = 1e-10;

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

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	vector<int> a(N);
	REP(i, N)
		cin >> a[i];
	sort(all(a), greater<int>());
	int res[2] = {};
	REP(i, a.size()){
		res[i%2] += a[i];
	}
	cout << res[0]-res[1] << endl;
}


Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let mut done: bool = false;

    while !done {
        let h = read();
        let w = read();
        if h == 0 && w == 0 {
            done = true;
        } else {
            for _ in 0..h {
                for _ in 0..w {
                    print!("#");
                }
                println!();
            }
            println!();
        }
    }
}



Measured memory_bytes: 5028
#include <stdio.h>
#include <string.h>

int main()
{
    while(1){
        int count = 1, n, tmp, top = 1, south = 2, east = 3;
        char str[6] = "";
        scanf("%d", &n);
        if(n == 0)return 0;
        for(int i=0;i<n;i++){
            scanf("%s",str);
            switch(str[0]){
            case 'N':
                tmp = top;
                top = south;
                south = 7 - tmp;
                break;
            case 'E':
                tmp = east;
                east = top;
                top = 7 - tmp;
                break;
            case 'W':
                tmp = top;
                top = east;
                east = 7 - tmp;
                break;
            case 'S':
                tmp = south;
                south = top;
                top = 7 - tmp;
                break;
            case 'R':
                tmp = south;
                south = east;
                east = 7 - tmp;
                break;
            case 'L':
                tmp = east;
                east = south;
                south = 7 - tmp;
                break;
            }
            count += top;
        }
        printf("%d\n",count);
    }
}

Measured memory_bytes: 1032
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define ll long long
#define vi vector<int>
#define pii pair<int,int>
#define F first
#define S second
#define pb push_back
#define forn(b) for(int i = 0; i < b; i++)
#define rforn(b) for(int i = b - 1 ;i >= 0; i--)
#define It(m) for(auto it = m.begin(); it != m.end(); it++)
#define N 500500
#define PI 3.14159265358979323846264338327950L
#define speed ios_base :: sync_with_stdio(0);cin.tie(0);cout.tie(0);
    
const ll mod = (ll)1e9 + 7;
    
int main(){
    speed;
    int n; cin >> n;
    int cnt = 0;
    for(int i = 1; i <= n; i++) {
        int k = i;
        int s = 0;
        while(k != 0) {
            k /= 10;
            s++;
        }
        if(s % 2 == 1) {cnt++;}
    }
    cout << cnt;

    return 0;
}

Measured memory_bytes: 256
import sys
import copy
import math
import bisect
import pprint
import bisect
from functools import reduce
from copy import deepcopy
from collections import deque

def lcm(x, y):
    return (x * y) // math.gcd(x, y)

if __name__ == '__main__':
    a = [int(i) for i in input().split()]
    count =0

    if a[0] ==1:
        count+=300000
    if a[1] ==1:
        count+=300000
    if a[0] ==2:
        count+=200000
    if a[1] ==2:
        count+=200000
    if a[0] ==3:
        count+=100000
    if a[1] ==3:
        count+=100000
    if a[0] == a[1]==1 :
        count+=400000
    print(count)


Measured memory_bytes: 3828
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int x = Integer.parseInt(br.readLine());
		if (x < 1200) {
			System.out.println("ABC");
		} else {
			System.out.println("ARC");
		}

	}

}


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

using ll = long long;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  if (fopen("input.in", "r")) {
    freopen("input.in", "r", stdin);
    freopen("output.out", "w", stdout);
  }

  /*
  dp[i][j] = max polls for doing option j on day i
  */

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

  vector<vector<ll>> dp(N, vector<ll>(3, 0));
  dp[0][0] = a[0];
  dp[0][1] = b[0];
  dp[0][2] = c[0];

  for (ll i = 1; i < N; i++) {
    dp[i][0] = max(dp[i-1][1], dp[i-1][2])+a[i];
    dp[i][1] = max(dp[i-1][0], dp[i-1][2])+b[i];
    dp[i][2] = max(dp[i-1][0], dp[i-1][1])+c[i];
  }

  cout << max(dp[N-1][0], max(dp[N-1][1], dp[N-1][2])) << endl;

  return 0;
}

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

#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i < (n); i++)

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

    string X; cin >>X;

    int len = X.size();
    int rm = 0;
    int s_count = 0;
    rep(i, len) {
        if (X[i] == 'S') {
            s_count++;
        } else {
            if (s_count) {
                rm++;
                s_count--;
            }
        }
    }

    cout << len - rm * 2 << endl;
}


Measured memory_bytes: 720
#include <bits/stdc++.h>
using namespace std;
int main(void)
{
	int n, k;
	cin >> n >> k;
	long double ans = 0.0;
	for (long long i = 1; i <= n; i++) {
		long long tmp = i;
		for (int m = 0; tmp < k; m++) {
			tmp *= 2;
		}
		ans += (long double)1.0 / (long double)(tmp/i);
	}
	printf("%.12Lf\n", ans/(long double)n);
	return 0;
}

Measured memory_bytes: 3688
#include <stdio.h>
int main() {
	long n,i,a,b,ans[100001]={};
	long k,count=0;
	scanf("%lld%lld",&n,&k);
	for (i=0;i<n;i++) {
		scanf("%lld%lld",&a,&b);
		ans[a]+=b;
	}
 
	for (i=1;i<=100000;i++) {
		count+=ans[i];
		if(k<=count)break;
	}
	printf("%lld\n",i);
	return 0;
}

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

int main() {
  int n,l;
  cin >> n >> l;
  int total = 0;
  int L = l;
  int R = l+n-1;
  
  int eat;
  if(R<=0) eat=R;
  else if(L>=0) eat=L;
  else eat=0;
  
  int ans = (R+L)*(R-L+1)/2 - eat;
  rep(i,n) total += (l+i);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
ll GCD(ll a, ll b){ return a ? GCD(b % a, a) : b; }
int main(){
    char a;
    cin>>a;
    if(a-'A' < 26){
        cout<<"A";
    }else{
        cout<<"a";
    }
    cout<<endl;
}

Measured memory_bytes: 3604
from bisect import bisect_left
N = int(input())
L = sorted(list(map(int,input().split())))
cnt = 0
for i in range(N-2):
    for j in range(i+1,N-1):
        ind = bisect_left(L,L[i]+L[j])
        cnt += ind-j-1
print(cnt)

Measured memory_bytes: 9368
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;

class Program
{
    static void Main(string[] args)
    {
        var NK = ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
        var (N, K) = (NK[0], NK[1]);
        var V = ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();

        var ans = long.MinValue;
        for (int take = 0; take <= N; take++)
        {
            var remK = K - take;
            if (remK < 0)
                continue;

            for (int leftTake = 0; leftTake <= take; leftTake++)
            {
                var rigthTake = take - leftTake;

                var leftV = V[..leftTake];
                var rightV = V[^rigthTake..];
                var takeV = leftV.Concat(rightV).OrderBy(x => x).ToArray();

                for (int ret = 0; ret <= remK; ret++)
                {
                    var sum = takeV.Skip(ret).Sum();
                    ans = Math.Max(ans, sum);
                }
            }
        }

        WriteLine(ans);
    }
}


Measured memory_bytes: 34032
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll,ll> P;
#define Mod 2929000007
using VP = vector<P>; using VVP = vector<VP>;
using VI = vector<ll>; using VVI = vector<VI>; using VVVI = vector<VVI>;
#define INF 1234567890


int main(){
    ll i,j;
    string s;
    cin>>s;
    ll n=s.size();
    if(s[0]==s[n-1]) n++;
    if(n%2==0){
        cout<<"Second"<<endl;
    }
    else cout<<"First"<<endl;
    return 0;
}

Measured memory_bytes: 512
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <sstream>
#include <random>
#include <utility>
#include <map>
#include <vector>
#define REP(i,x) for(int i=0; i<(x); i++)

using namespace std;

int main(int argc, const char * argv[]) {
    int a,b;
    b = 0;
    cin >> a;
    while (a>0) {
        b += a%10;
        a /= 10;
    }
    cout << b << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int lint
typedef long long lint;
typedef pair<int,int> P;
const int    INF=(int)1e9;
const int    MOD=(int)1e9+7;
const double EPS=(double)1e-10;
struct Accelerate_Cin{
    Accelerate_Cin(){
        cin.tie(0); ios::sync_with_stdio(0);cout<<fixed<<setprecision(20);
    };
};



signed main(){
  string o,e;cin>>o>>e;
  for(int t=0;t<o.size()+e.size();t++){
    if(t%2==0)cout<<o[t/2];
    if(t%2==1)cout<<e[t/2];
  }
  cout<<"\n";
  return 0;
}


Measured memory_bytes: 256
program Project1;

{$APPTYPE CONSOLE}

uses
  SysUtils,Classes;
var
  a,b,h:Integer;
begin
  try
    { TODO -oUser -cConsole Main : ここにコードを記述してください }
    Readln(a);
    Readln(b);
    Readln(h);

    Writeln((a+b)*h div 2);
    Readln;
  except
    on E: Exception do
      Writeln(E.ClassName, ': ', E.Message);
  end;
end.


Measured memory_bytes: 256