akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>

int main(){
  int flag = 0;
  int i,j;
  int tmp,cnt = 0;
  int N;
  int A[100];

  if(scanf("%d",&N) > 100)
    exit(1);
  for(i = 0; i < N; i++){
    scanf("%d",&A[i]);
    if(A[i] < 0 || A[i] > 100)
      exit(2);
  }

  do{
    flag = 0;
    for(j = N-1; j > 0; j--){
      if(A[j] < A[j-1]){ 
	flag = 1;
	tmp = A[j-1];
	A[j-1] = A[j];
	A[j] = tmp;
	cnt++;
      }
    }       
  } while(flag==1);

  for(i = 0; i < N; i++){
    printf("%d",A[i]);
    if(i != N-1)
      printf(" ");
  }
  printf("\n%d\n",cnt);
  return 0;
}




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

int main(void){
    vector<pair<int,int>> shop;
    int n, m, count = 0, a, b;
    long long result = 0;
    cin >> n >> m;
    for(int i = 0; i < n; ++i){
        cin >> a >> b;
        shop.push_back(make_pair(a, b));
    }
    sort(shop.begin(), shop.end());
    for(int i = 0; i < n; ++i){
        if((count + shop[i].second) >= m){
            result += (long long)shop[i].first * (m - count);
            break;
        }
        result += (long long)shop[i].first * shop[i].second;
        count += shop[i].second;
    }
    cout << result << endl;
    return 0;
    
}

Measured memory_bytes: 1400
#include <iostream>
#include <string>
using namespace std;
int main()
{
	int n; cin >> n ; cin.ignore();
	for(int i=0;i<n;i++){
		string full_str; getline(cin,full_str);
		string::iterator p;
		for(p=full_str.begin(); p!=full_str.end();p++)
		{
			int m=p - full_str.begin();
			string pre_str=full_str.substr(m,7);
			if(pre_str=="Hoshino") full_str.replace(p,p+7,"Hoshina");
		};
		cout << full_str << endl;
	};
}

Measured memory_bytes: 1220
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <bitset>
#include <queue>
using namespace std;
using ll = long long int;
using P = pair<int, int>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
const ll INF = 1LL << 60;
ll mod = 1000000007;

int main() {
    char a;
    cin >> a;
    if('a' <= a && 'z' >= a) cout << 'a' << endl;
    else cout << 'A' << endl;
}


Measured memory_bytes: 3564
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;

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

    while(1) {
        int n, r; cin >> n >> r;
        if(n==0 && r==0) break;

        vector<int> vec(n);
        rep(i, n) vec[i] = n-i;
        rep(i, r) {
            int p, c; cin >> p >> c;
            p--;
            int loc = 0;
            rep(j, c) {
                int num = vec[p];
                vec.erase(vec.begin()+p);
                vec.insert(vec.begin()+loc, num);
                p++;
                loc++;
            }
        }
        cout << vec.front() << endl;
    }
}


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

#define ll long long
#define ar array



int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	string s,e,a,b;
	cin >> s;
	e=s;
	int size=s.size();
	a=s.substr(0, (size-1)/2);
	b=s.substr(((size-1)+3)/2, size-1);
	string d=a;
	string f=b;
	reverse(a.begin(), a.end());
	reverse(b.begin(),b.end());
	reverse(s.begin(), s.end());
	if(e==s && d==a && f==b) {
		cout << "Yes";
	}else{
		cout << "No";
	}
}


Measured memory_bytes: 256
# coding: utf-8
import math

N = int(raw_input())
CSF = [map(float, raw_input().split()) for _ in range(N-1)]

for i in range(N-1):
    ans = CSF[i][0] + CSF[i][1]
    for j in range(i+1, N-1):
        s, t, u = CSF[j][0], CSF[j][1], CSF[j][2]
        if t < ans:
            n = int(math.ceil((ans - t) / u))
            ans = int(s + t + u * n)
        else:
            ans = s + t

    print int(ans)

print 0

Measured memory_bytes: 2692
N = int(input())
A = list(map(int, input().split()))
cnt = 0
for i in A:
    if i % 2 == 0:
        if (i % 3 != 0 and i % 5 != 0):
            cnt += 1

if cnt == 0:
    print("APPROVED")
else:
    print("DENIED")

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

int st[200];
char in[1000010];

int main(){
  int sp = 0;
  while( cin >> in ){
    if( '0' <= in[0] && in[0] <= '9' ){
      st[sp++] = atoi( in );
    }else{
      int a = st[--sp];
      int b = st[--sp];
      if( in[0] == '+' ){
	st[sp++] = b + a;
      }else if( in[0] == '-' ){
	st[sp++] = b - a;
      }else{
	st[sp++] = b * a;
      }
    }
  }

  assert( sp == 1 );
  cout << st[sp - 1] << endl;
}



Measured memory_bytes: 3116
n = int(input())
l = []
for i in range(1,n+1):
    s,p = input().split()
    p = int(p)
    l.append([s,p,i])
l = sorted(l,key=lambda x:(x[0],-x[1]))
for i in range(n):
    print(l[i][2])

Measured memory_bytes: 38256
n = input()
k = int(input())
#nより小さいことが確定しているdp
#dp_0[i][j] := i桁目まで決めて、0でない数字をj個使った時の数字の個数
dp_0 = [[0 for i in range(k+1)] for j in range(len(n))]
#nより小さいことが確定していないdp
#dp_1[i][j] := i桁目まで決めて、0でない数字をj個使った時の数字の個数。
dp_1 = [[0 for i in range(k+1)] for j in range(len(n))]
dp_0[0][0] = 1
dp_0[0][1] = int(n[0]) - 1
dp_1[0][1] = 1
for i in range(1,len(n)):
    dp_0[i][0] = 1
    for j in range(1,k+1):
    #今回の桁が0でないことを想定
        if n[i] != '0':
            #0を使う場合と使わない場合両方考える
            #まずは使わない場合
            dp_0[i][j] += dp_0[i-1][j-1] * 9 + dp_1[i-1][j-1] * (int(n[i]) - 1)
            dp_1[i][j] += dp_1[i-1][j-1]
            #0を使う場合。この時はjが変化しない。なぜなら0を使うか
            #dp_1の更新は無し。
            #なぜなら、今回の桁が0でないことを想定しているため、もうnを超えることはないから
            dp_0[i][j] += dp_0[i-1][j] + dp_1[i-1][j]
        else:
            #今回の桁が0の場合 
            #dp_1を遷移式に入れない理由は、今回の桁が0だった時は、どんな数字の選び方をしても
            #さっきの桁まででnより小さいことが確定しないものが
            #今回の桁の決め方で確定することはないから。
            dp_0[i][j] = dp_0[i-1][j-1] * 9 + dp_0[i-1][j]
            dp_1[i][j] = dp_1[i-1][j]
print(dp_0[-1][k] + dp_1[-1][k])



Measured memory_bytes: 38384
class UnionFind:
    def __init__(self,n):
        self.n=n
        self.parents=[-1]*n
        self.rank=[0]*n

    def find(self,x):
        if self.parents[x]<0:
            return x
        else:
            self.parents[x]=self.find(self.parents[x])
            return self.parents[x]

    def union(self,x,y):
        x=self.find(x)
        y=self.find(y)

        if x==y:
            return 

        if self.rank[x]<self.rank[y]:
            self.parents[y]+=self.parents[x]
            self.parents[x]=y
        else:
            self.parents[x]+=self.parents[y]
            self.parents[y]=x

            if self.rank[x]==self.rank[y]:
                self.rank[x]+=1

    def are_same(self,x,y):
        return self.find(x)==self.find(y)

    def element_count(self,x):
        x=self.find(x)
        return -self.parents[x]

    def group_count(self):
        count=0
        for e in self.parents:
            if e<0: count+=1
        return count


from sys import stdin
def main():
    #入力
    readline=stdin.readline
    n,m=map(int,readline().split())
    a=list(map(int,readline().split()))
    uf=UnionFind(n+1)
    for i in range(m):
        x,y=map(int,readline().split())
        uf.union(x,y)

    i=1
    while i<n+1:
        x=a[i-1]
        if x==i:
            i+=1
        elif uf.are_same(i,x):
            a[i-1],a[x-1]=a[x-1],a[i-1]
        else:
            i+=1

    print(len([a[i] for i in range(n) if a[i]-1==i]))

if __name__=="__main__":
    main()

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

int main(){
	int n,a,b;
	int answer=0;
	cin >> n >> a>>b;
	for (int i=1;i<=n;i++) {
	int tmp = i;
	int keta_sum = tmp%10;	//まずひとけた目
	while (tmp >= 10) {
	tmp /= 10;
	keta_sum += tmp%10;
	}
	if (a <= keta_sum && keta_sum <= b) {
	answer += i;
	}
	}

	cout << answer << endl;
	return 0;
}


Measured memory_bytes: 256
# AOJ 1587: Plants
# Python3 2018.7.13 bal4u

hi = [[0 for j in range(51)] for i in range(51)]
W, H, T = map(int, input().split())
P = int(input())
for i in range(P):
	x, y, t = map(int, input().split())
	hi[x][y] += 1
ans = 0;
for y in range(H):
	v = list(map(int, input().split()))
	for x in range(W):
		if v[x]: ans += hi[x][y]
print(ans)


Measured memory_bytes: 5608
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)  for(int i = 0; i < n; i++)
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.rbegin(), cont.rend()
#define unique(a)        (a).erase(unique((a).begin(), (a).end()),(a).end())
#define fastio          ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define PB push_back
#define endl "\n"
#define mod 1000000007 
typedef long long LL;
typedef long double LD;
typedef vector<int> VI;
inline LL moduloMultiplication(LL x, LL y) { return (x%mod * 1LL * y%mod) % mod; }
inline LL power(LL a, LL b) {
	LL x = 1 % mod;
	while (b) {
		if (b & 1) x = moduloMultiplication(x, a);
		a = moduloMultiplication(a, a);
		b >>= 1;
	}
	return x % mod;
}

LL gcd(LL a, LL b)
{
	if (!a)
		return b;
	return gcd(b%a, a);
}
inline LL add(LL x, LL y) { x += y; if (x >= mod) x -= mod; return x; }
int main()
{
	int a, b;
	
	cin >> a >> b;
	if (a < b) 
		rep(i, b)cout << a ;
	else
		rep(i, a)cout << b  ;
	
}


Measured memory_bytes: 256
s = str(input())

if s == 'zyxwvutsrqponmlkjihgfedcba':
    print(-1)
elif len(s) == 26:
    tmp = ord(s[-1])
    for i in range(len(s))[::-1]:
        if ord(s[i]) < tmp:
            ans = sorted(s[i:])
            for j in ans:
                if ord(j) > ord(s[i]):
                    print(s[:i] + j)
                    exit()
        tmp = ord(s[i])
else:
    alpha = [chr(i) for i in range(97, 97 + 26)]
    for i in alpha:
        if i not in s:
            print(s + i)
            break


Measured memory_bytes: 3064
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
//dp[何文字目か][直前の数字][上下][自由に選べるか][余り]
//上:0 下:1
int m;
string s;
char z[555];
int dp[501][10][3][2][500];
int solve(int n,int be,int ud,int ok,int md){
  if(n == (int)s.size()){
    //if(!md)cout << z << endl;
    return md?0:1;
  }
  if(dp[n][be][ud][ok][md] >= 0) return dp[n][be][ud][ok][md];

  int ret = 0;
  for(int i = 0; i <= ((ok)?9:(int)(s[n]-'0')); i++){
    if(ud == 0 && be <= i) continue;
    if(ud == 1 && be >= i) continue;
    if(ud == 2 && be != 0 && be == i) continue;
    int u;
    if(ud == 2){
      if(be == 0) u = 2;
      else if(be > i) u = 1;
      else u = 0;
    }else{
      u = (ud+1)%2;
    }
    //z[n] = i + '0';
    ret += solve(n+1,i,u,(ok || i != (int)(s[n]-'0'))?1:0,(md*10+i)%m);
    //z[m] = '\0';
  }
  return dp[n][be][ud][ok][md] = ret%10000;
}

int main(void){
  string c,d;
  cin >> c >> d >> m;
  for(int i = (int)c.size()-1; i >= 0; i--){
    if(c[i] == '0'){
      c[i] = '9';
    }else{
      c[i]--;
      break;
    }
  }
  s = c;
  memset(dp,-1,sizeof(dp));
  int a = solve(0,0,2,0,0);
  //cout << "A" << endl;
  s = d;
  memset(dp,-1,sizeof(dp));
  int b = solve(0,0,2,0,0);
  //cout << "B" << endl;
  //cout << a << endl;
  //cout << b << endl;
  cout << (b + 10000 - a)%10000 << endl;
}

Measured memory_bytes: 59996
#include <bits/stdc++.h>
using namespace std;
 
#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 1
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define TO_STRING(VariableName) # VariableName
#define LOG(x) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<endl;
#define LOG2(x,y) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<endl;
#define LOG3(x,y,z) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;
#define LOG4(w,x,y,z) if(DEBUG)cout<<TO_STRING(w)<<"="<<w<<" "<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;
 
template<class T>bool chmax(T & a, const T & b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
 
void solve(){
 
    lli ans = 0;
    priority_queue<pair<lli,lli>> q;
    priority_queue<pair<lli,lli>,vector<pair<lli,lli>>,greater<pair<lli,lli>>> qq;
 
    lli n;
    cin>>n;
    REP(i,0,n){
        lli k,l,r;
        cin>>k>>l>>r;
        if(l-r>0){
            q.push({k,l-r});
            ans += r;
        }
        else{
            qq.push({k,r-l});
            ans += l;
        }
    }
 
    lli now = 0;
 
    priority_queue<lli> s;
    lli cnt = 0;
    for(lli i=n;i>=1;i--){
        while(q.size() && q.top().first >= i){
            s.push(q.top().second);
            q.pop();
        }
        if(s.size()==0)continue;
        ans += s.top();
        s.pop();
    }
 
    while(s.size())s.pop();
    for(lli i=cnt+1;i<=n;i++){
        while(qq.size() && qq.top().first < i){
            s.push(qq.top().second);
            qq.pop();
        }
        if(s.size()==0)continue;
        ans += s.top();
        s.pop();
    }
    cout<<ans<<endl;
 
}
 
 
int main(){
 
    lli t;
    cin>>t;
    while(t--)solve();
 
    return 0;
}

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



int main()
{
  ll n,m,r;
  cin >> n >> m >> r;

  // weight, end point
  vector<vector<pair<ll,ll>> > G(n);

  for (ll i = 0; i < m; i++)
  {
    ll s,t,d;
    cin >> s >> t >> d;
    G[s].emplace_back(make_pair(d,t));
  }

  vector<ll> dist(n,1e+10);

  priority_queue<P,vector<P>,greater<P> > que;
  dist[r] = 0;
  que.push(make_pair(0,r));
  
  while(!que.empty())
  {
    /*
    cout << "-----------------------" << endl;
    //debugging
    cout << "dist:" << endl;
    for(auto x:dist)
    {
      if(x!=1e+10) cout << x << " ";
      else cout << "INF" << " ";
    }
    cout << endl;
    cout << "que:" << endl;
    priority_queue<P,vector<P>,greater<P> > tmpque = que;
    while(!tmpque.empty())
    {
      P p = tmpque.top();
      cout << p.first << " " << p.second << endl;
      tmpque.pop();
    }
    */

    // main part
    P p = que.top();
    que.pop();
    ll v = p.second;
    if(dist[v] < p.first) continue;

    /*
    cout << "edges: ";
    cout << v << " " << G[v].size() << endl;
    */
    for(auto q:G[v])
    {
      //cout << "from " << v << " to " << q.second;
      if(dist[q.second] > dist[v] + q.first)
      {
        dist[q.second] = dist[v] + q.first;
        que.push(make_pair(dist[q.second],q.second));
        //cout << ": updated" << endl;
      } else {
        //cout << ": skipped" << endl;
      }
    }
  }

  //cout << "-----------------------" << endl;


  for(auto x:dist)
  {
    if(x!=1e+10) cout << x << endl;
    else cout << "INF" << endl;
  }

  return 0;
}


Measured memory_bytes: 19368
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = 1; i < (int)(n); i++) 
#define dunk(n) cout << n << endl
#define all(a) (a).begin(),(a).end()
typedef pair<int,int> P;
typedef long long ll;

int n,m,q;
vector<int> a(51),b(51),c(51),d(51);
int ans = 0;
vector<int> A;

void dfs(int s){
    if(A.size() == n){
        int res = 0;
        rep(i,q){
            if(A[b[i]]-A[a[i]] == c[i]) res += d[i];
        }
        ans = max(ans,res);
        return;
    }
    for(int i = s; i <= m; i++){
        A.push_back(i);
        dfs(i);
        A.pop_back();
    }
   
}

int main() {
    cin >> n >> m >> q;
    rep(i,q){
        cin >> a[i] >> b[i] >> c[i] >> d[i];
        a[i]--; b[i]--;
    }
    dfs(1);
    dunk(ans);
    
    return 0;
}

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

int main(void)
{
    int i=0,ans;
    char s[4];
    char youbi[7][4]={"SUN","MON","TUE","WED","THU","FRI","SAT"};

    scanf("%s",s);

    while (1)
    {
        if(strcmp(s,youbi[i])==0)
        {
            ans=7-i;
            break;
        }
        i++;
    }

    printf("%d",ans);

    return 0;
}

Measured memory_bytes: 128
mod = 10 ** 9 + 7
n, m = map(int, input().split())
a = [True] * (n + 1)
for _ in range(m):
    a[int(input())] = False
dp = [0]*(n+1)
dp[0] = 1
if a[1]: dp[1] = 1
for i in range(2, n+1):
    if a[i-2]: dp[i] += dp[i-2]
    if a[i-1]: dp[i] += dp[i-1]
    dp[i] %= mod
print(dp[-1])

Measured memory_bytes: 7768
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int N,i;
	cin>>N;  double c = 0;
	for(i=1;i<=N;i++)
	{
		double a; 
		cin>>a;
		c+=(1/a);
		//cout<<(1/c);
	}
    double d = 1 / c;
    cout<<fixed<<setprecision(6);
    cout << d << endl;
}

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

using namespace std;

int a[510][510],c[250250][4];
int h,w;


int main()
{
    ios::sync_with_stdio(false);cin.tie(0);
    cin>>h>>w;
    for(int i=0;i<h;i++)
    {
        for(int j=0;j<w;j++)
        {
            cin>>a[i][j];
        }
    }
    int ans=0;
    for(int i=0;i<h-1;i++)
    {
        for(int j=0;j<w;j++)
        {
            if(a[i][j]%2==1)
            {
                c[ans][0]=i;
                c[ans][1]=j;
                c[ans][2]=i+1;
                c[ans][3]=j;
                ans++;
                a[i+1][j]++;
            }
        }
    }
    for(int i=0;i<w-1;i++)
    {
        if(a[h-1][i]%2==1)
        {
            c[ans][0]=h-1;
            c[ans][1]=i;
            c[ans][2]=h-1;
            c[ans][3]=i+1;
            ans++;
            a[h-1][i+1]++;
        }
    }
    cout<<ans<<endl;
    for(int i=0;i<ans;i++)
    {
        cout << c[i][0] + 1 << " " << c[i][1] + 1 << " " << c[i][2] + 1 << " " << c[i][3] + 1 << endl;
    }
    return 0;
}


Measured memory_bytes: 6912
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define reps(i,n) for(int i=1;i<(int)(n);i++)

typedef long long ll;
using namespace std;

ll gcd(ll a, ll b) { //最大公約数
  if (b==0) return a;
  else return gcd(b, a%b);
}

ll lcm(ll a, ll b) { //最小公倍数
  return a * b / gcd(a, b);
}

ll digit_sum(ll a){ //10進桁和
  ll ans=0;
  while(a>0){
    ans+=a%10;
    a/=10;
  }
  return ans;
}



int main()
{
  ll n,a[10010];
  cin>>n;
  ll ans=0;;
  rep(i,n){
    cin>>a[i];
    while(a[i]%2==0){
      ans++;
      a[i]/=2;
    }
  }
  cout<<ans<<endl;;
  return 0;
}


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

using namespace std;
#define ll long long

bool isVisited[501][501];

void update(vector<vector<int>> &dp, int r, int c, int val)
{
    if(r < 0 || r >= dp.size() || c <0 || c >= dp.size() || dp[r][c] <= val)
        return;
    
    dp[r][c] = val;
    if( isVisited[r][c])
    {
        update(dp,r-1,c,val);
        update(dp,r,c-1,val);
        update(dp,r+1,c,val);
        update(dp,r,c+1,val); 
    }
    else
    {
        update(dp,r-1,c,val+1);
        update(dp,r,c-1,val+1);
        update(dp,r+1,c,val+1);
        update(dp,r,c+1,val+1);
    }
}


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

    vector<vector<int>> dp(n, vector<int>(n));
    for(int i = 0; i<n;i++)
        for(int j = 0 ;j<n;j++)
        {
            int min1 = min(i,n-1-i);
            int min2 = min(j, n-1-j);
            dp[i][j] = min(min1,min2);
            isVisited[i][j] = false;
        }
    
    ll ans= 0;

    for(int i=0;i<n*n;i++)
    {
        int q;
        cin >> q;
        int row ,col;
        col = (q-1)%n;
        row = (q-1)/n;
        ans += dp[row][col];
        isVisited[row][col] = true;

        //cout<<q<<"  "<<row<<" "<<col<<"  "<<ans<<endl;

        update(dp,row-1,col, dp[row][col]);
        update(dp,row,col-1, dp[row][col]);
        update(dp,row+1,col, dp[row][col]);
        update(dp,row,col+1, dp[row][col]);
    }

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


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

#define For(i, j, k) for(int i = j; i < k; i++)
#define Forr(i, j, k) for(int i = int(j) - 1; i >= k; i--)
#define pb push_back

using namespace std;

const int N = 2010;

int A[N], B[N << 1];
int pre[N], nxt[N << 1];
bool vis[N];
int n, ans;

bool cmp(int x, int y){
	return pre[x] < pre[y];
}

void work(){
	For(i, n, 2 * n) B[i] = B[i - n];
	For(i, 0, n) vis[i] = false;

	int lst = -1;
	For(i, 0, n) if(B[i]) lst = i;
	For(i, n, 2 * n){
		if(B[i]) lst = i;
		pre[i - n] = i - lst;
	}

	lst = n;
	Forr(i, 2 * n, n) if(B[i]) lst = i;
	Forr(i, n, 0){
		if(B[i]) lst = i;
		nxt[i] = lst - i;
	}

	For(i, 0, n){
		int ret = i;
		vector<int> pos;

		For(j, 0, n){
			if(B[j + i]) vis[j] = true;
			if(A[j] ^ B[j + i]){
				++ret;
				if(!vis[j]) pos.pb(j);
			}
		}

		if(pos.size() && lst == n) continue;
		sort(pos.begin(), pos.end(), cmp);

		int Max = 0;
		Forr(j, pos.size(), 0){
			ans = min(ans, ret + Max * 2 + pre[pos[j]] * 2);
			Max = max(Max, nxt[(i + pos[j]) % n]);
		}
		ans = min(ans, ret + Max * 2);

	}
}

char S[N];

int main(){
	scanf("%s", S);
	n = strlen(S);
	For(i, 0, n) A[i] = S[i] - '0';
	For(i, 0, n) scanf("%1d", &B[i]);

	ans = 1e9;
	work();
	reverse(A, A + n);
	reverse(B, B + n);
	work();

	printf("%d\n", ans == 1e9 ? -1 : ans);
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <queue>
#include <vector>
typedef long long LL;
using namespace std;
 
int main() {
    int n, m;
    LL ans = 0;
    LL tmp;
    cin >> n >> m;
    priority_queue<LL> a;
    for (int i=0; i<n; i++) {
        cin >> tmp;
        a.push(tmp);
    }
 
    for (int i=0; i<m; i++) {
        tmp = a.top();
        a.pop();
        tmp = tmp/2;
        a.push(tmp);
    }
 
    for (int i=0; i<n; i++) {
        ans += a.top();
        a.pop();
    }
 
    cout << ans << endl;
}

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

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

    int X = N / 1.08;
    while (X * 1.08 < N)
    {
        X++;
    }

    if ((int)(X * 1.08) == N)
    {
        cout << X << endl;
    }
    else
    {
        cout << ":(" << endl;
    }

    return 0;
}

Measured memory_bytes: 3592
import queue

"""
N = int(input())
#S = input()
# (N,M) = (int(i) for i in input().split(" "))
# A = [int(i) for i in input().split()]
A = []
for i in range(N):
	A.append(int(input()))

print(A)

"""
ch = True
S=input()
for i,s in enumerate(S):
	if i%2==0 and s=="L":
		ch = False
		break
	if i%2==1 and s=="R":
		ch = False
		break
if ch:
	print("Yes")
else:
	print("No")


Measured memory_bytes: 4208
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(void){
    // Your code here!
    int n,in,sum=0;
    cin>>n;
    n*=2;
    vector<int> v;
    for(int i=0;i<n;i++){
        cin>>in;
        v.push_back(in);
    }
    sort(v.begin(),v.end());
    for(int i=0;i<n;i+=2){
        sum+=v[i];
    }
    cout<<sum<<endl;
}


Measured memory_bytes: 256
import std.stdio, std.string, std.conv, std.algorithm;
import std.range, std.array, std.math, std.typecons, std.container, core.bitop;


void main() {
    int N, A;
    scan(N);
    scan(A);

    writeln(N^^2 - A);
}



void scan(T...)(ref T args) {
    string[] line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}



void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

Measured memory_bytes: 256
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#ifdef __GXX_EXPERIMENTAL_CXX0X__
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#ifdef __GXX_EXPERIMENTAL_CXX0X__
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif


using namespace std;

void saiki(int N, vector<int>data,int max)
{
	if (N == 0)
	{
		for (size_t i = 0; i < data.size() - 1; i++)
		{
			cout << data[i] << " ";
		}
		cout << data[data.size() - 1] << endl;
	} else if (N < 0)
	{
		return;
	}

	for (int i = max; i > 0; i--)
	{
		data.push_back(i);
		saiki(N - i, data,i);
		data.pop_back();
	}
}

int main()
{
	int N;
	while (1)
	{
		cin >> N;
		if (!N)break;
		vector<int>data;
		data.clear();
		saiki(N, data, N);
	}
}

Measured memory_bytes: 1216
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a, b, c, d;
	cin >> a >> b >> c >>d;
	bool turn = true;
	while(a > 0 && c > 0)
	{
		if(turn)
			c -= b;
		else
			a -= d;
		turn = !turn;
	}
	if(a > 0)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define pi 3.14159265359
using namespace std;
const long long INF=1e9+7;
const string alp="abcdefghijklmnopqrstuvwxyz"; //26
const string ALP="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
//const ll MOD=998244353LL;
//const ll MOD=1777777777LL;


int main() {
  ll N;
  cin>>N;
  string s[N];
  rep(i,N) cin>>s[i];
  vl ans(4,0);
  rep(i,N){
    if(s[i]=="AC") ans[0]++;
    else if(s[i]=="WA") ans[1]++;
    else if(s[i]=="TLE") ans[2]++;
    else ans[3]++;
  }
  cout<<"AC"<<" "<<'x'<<" "<<ans[0]<<endl;
  cout<<"WA"<<" "<<'x'<<" "<<ans[1]<<endl;
  cout<<"TLE"<<" "<<'x'<<" "<<ans[2]<<endl;
  cout<<"RE"<<" "<<'x'<<" "<<ans[3]<<endl;
}

Measured memory_bytes: 6752
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>

using namespace std;

#define ll long long
#define pii pair<int,int>
#define N 500500
#define dracarys ios_base :: sync_with_stdio(0);cin.tie(0);cout.tie(0);

const ll mod = 998244353;


int x;

int get_kyu(int x) {
    if (400 <= x && x <= 599) return 8;
    if (600 <= x && x <= 799) return 7;
    if (800 <= x && x <= 999) return 6;
    if (1000 <= x && x <= 1199) return 5;
    if (1200 <= x && x <= 1399) return 4;
    if (1400 <= x && x <= 1599) return 3;
    if (1600 <= x && x <= 1799) return 2;
    if (1800 <= x && x <= 1999) return 1;
}


void solve() {
    cin >> x;
    cout << get_kyu(x) << "\n";
}


int main() {
//    freopen("sample.in", "r", stdin);
    dracarys
    int t = 1;
//    cin >> t;
    for (int i = 1; i <= t; ++i) {
//        cout << "Case #" << i << ": ";
        solve();
    }
    return 0;
}


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

int main() {
    while(1){
        int n, k; cin >> n >> k;
        if(n==0) break;
        vector<int> a(n);
        for(int i=0; i<n; i++) cin >> a[i];
        int ans=0;
        for(int i=0; i<k; i++) ans += a[i];
        int mx=ans;
        for(int i=1; i<n-k+1; i++){
            mx=mx+a[k-1+i]-a[i-1];
            ans=max(ans, mx);
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 3012
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

from itertools import combinations

n,x,y=map(int,readline().split())
dis=[0]*n
lst=list(range(1,n+1))
for a,b in combinations(lst,2):
  if b<=x or a>=y:
    dist=b-a
  else:
    dist=min(b-a, abs(x-a)+abs(y-b)+1)
  dis[dist]+=1
print(*dis[1:],sep='\n')

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

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

const ll INF64 = 1LL << 60;
const int INF32 = 1 << 29;
const int MOD = 1000000007;

const int CASES = 3;

void solve(){
    int N;
    cin >> N;
    vector<P> A(N);
    for(int i = 0; i < N; ++i){
        int a; cin >> a;
        A[i] = {a, i+1};

    }
    sort(A.begin(), A.end());


    for(int i = 0; i < N-1; ++i){
        cout << A[i].second << " ";
    }
    cout << A[N-1].second << "\n";
    return;
}

int main() {
    #ifdef MYLOCAL
    vector<string> filenames {"input1.txt", "input2.txt", "input3.txt", "input4.txt"};
    cout << "------------\n";
    for(int i = 0; i < CASES; ++i){
        ifstream in(filenames[i]);
        cin.rdbuf(in.rdbuf());
        solve();
        cout << "------------\n";
    }
    #else

    solve();

    #endif
    return 0;
}



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

int dp[11][46] = {0};

int main()
{
	dp[0][0]=1;
	for(int k=0; k<10; k++)
	{
		for(int i=k; i>=0; i--)
		for(int j=0; j<46-k; j++)
		{
			dp[i+1][j+k] += dp[i][j];
		}
	}

	int N,S;
	while(cin>>N>>S, N||S)
	{
		if(0<=N && N<11 && 0<=S && S<46)
		{
			cout << dp[N][S] << endl;
		}
		else
		{
			cout << 0 << endl;
		}
	}
}

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

#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define intll int long long
const int INF = 1e9;
const int MOD = 1e9 + 7;

int main() {
  string s ;
  cin >> s ;
  int ans = 0 ;
  
  if(s.at(0) =='R' || s.at(1) =='R' || s.at(2) == 'R') ans ++ ;
  if(s.at(0) == 'R' && s.at(1) =='R') ans ++ ;
  if(s.at(1) == 'R' && s.at(2) =='R') ans ++ ;
  
  cout <<ans ;
  
}


Measured memory_bytes: 3624
#include<iostream>
using namespace std;
bool isPrime(int n) {
	for (int i = 2; i * i <= n; i++) if (n % i == 0) return false;
	return true;
}

int main() {
	int d[10005] = {};
	int i = 2, k = 1;
	while (k < 10005) {
		while (!isPrime(i)) i++;
		d[k] = d[k - 1] + i;
		i++; k++;
	}
	while (cin >> k, k) cout << d[k] << endl;
	return 0;
}


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

using namespace std;

const double EPS = 1e-8;
const double INF = 1e12;
const double PI = acos(-1);

using Point = complex<double>;
using Polygon = vector<Point>;

inline int sgn(const double &a) { return (a < -EPS ? -1 : (a > EPS ? 1 : 0)); }

inline bool eq(const Point &a, const Point &b) { return abs(a - b) < EPS; }

namespace std {
inline bool operator<(const Point &a, const Point &b) {
    if (sgn(a.real() - b.real()))
        return sgn(a.real() - b.real()) < 0;
    return sgn(a.imag() - b.imag()) < 0;
}
} // namespace std

double dot(const Point &a, const Point &b) { return real(conj(a) * b); }

double det(const Point &a, const Point &b) { return imag(conj(a) * b); }

struct Line {
    Point p1, p2;

    Line(Point p1 = Point(), Point p2 = Point()) : p1(p1), p2(p2) {}

    bool operator<(const Line &rhs) const {
        if (eq(p2, rhs.p2))
            return p1 < rhs.p1;
        return p2 < rhs.p2;
    }
    bool operator==(const Line &rhs) const {
        return (eq(p1, rhs.p1) && eq(p2, rhs.p2)) ||
               (eq(p1, rhs.p2) && eq(p2, rhs.p1));
    }
};

enum CCW {
    ONLINE_FRONT = -2,
    CLOCKWISE,
    ON_SEGMENT,
    COUNTER_CLOCKWISE,
    ONLINE_BACK
};

int ccw(Point p0, Point p1, Point p2) {
    Point a = p1 - p0;
    Point b = p2 - p0;
    if (sgn(det(a, b)) == 1)
        return COUNTER_CLOCKWISE;
    if (sgn(det(a, b)) == -1)
        return CLOCKWISE;
    if (sgn(dot(a, b)) == -1)
        return ONLINE_BACK;
    if (sgn(norm(b) - norm(a)) == 1)
        return ONLINE_FRONT;
    return ON_SEGMENT;
}

bool is_intersected(Line a, Line b, bool segflag){
    if(segflag)return (ccw(a.p1, a.p2, b.p1) * ccw(a.p1, a.p2, b.p2) <= 0) &&
            (ccw(b.p1, b.p2, a.p1) * ccw(b.p1, b.p2, a.p2) <= 0);
    else return (sgn(det(a.p2-a.p1, b.p1-a.p1) * det(a.p2-a.p1, b.p2-a.p1)) <= 0) &&
            (sgn(det(b.p2-b.p1, a.p1-b.p1) * det(b.p2-b.p1, a.p2-b.p1)) <= 0);
}

int main(){
    int q;
    cin >> q;
    for(int i=0;i<q;++i){
        double x0, y0, x1, y1, x2, y2, x3, y3;
        cin >> x0 >> y0 >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
        Point p0 = Point(x0, y0), p1 = Point(x1, y1), p2 = Point(x2, y2), p3 = Point(x3, y3);
        Line s1 = Line(p0, p1), s2 = Line(p2, p3);
        cout << (is_intersected(s1, s2, true) ? 1 : 0) << endl;
    }

    return 0;
}



Measured memory_bytes: 3276
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define INF 1LL << 60;
#define LLINF 1e12
#define PI 3.14159265359
#define ALL(a) (a).begin(), (a).end()
int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
int dy8[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dx8[] = {0, 1, 0, -1, 1, 1, -1, -1};
int ny, nx;
typedef long long ll;
using namespace std;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

ll lcm(ll m, ll n)
{
    if ((0 == m) || (0 == n))
        return 0;
    return ((m / gcd(m, n)) * n);
}

ll llpow(ll x, ll y)
{
    ll ans = 1;
    REP(i, y)
    ans *= x;
    return ans;
}

ll llmin(ll x, ll y) { return x < y ? x : y; }
ll llmax(ll x, ll y) { return x > y ? x : y; }

unsigned GetDigit(unsigned num) { return to_string(num).length(); }

template <typename Container>
bool exist_in(const Container &c, const typename Container::value_type &v)
{
    return (c.end() != std::find(c.begin(), c.end(), v));
}

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

ll nCr(int n, int r)
{
    if (n == r or n == 0)
        return 1;
    if (n < r)
        return 0;
    if (r == 1)
        return n;
    return nCr(n - 1, r - 1) + nCr(n - 1, r);
}

//素因数分解
vector<ll> decom;

void decompositPrime(ll n)
{
    ll a = 2;
    while (n >= a * a)
    {
        if (n % a == 0)
        {
            decom.push_back(a);
            n /= a;
        }
        else
        {
            a++;
        }
    }
    decom.push_back(n);
}

//std::cout << std::defaultfloat << std::setprecision(10);
////////////////////////////////////////
int main()
{

    int N; cin >> N;
    vector<int> x(N+1);
    REP(i,N+1) cin >> x[i];

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

    vector<int> res(N);
    REP(i,N) res[i] = x[i+1]-x[i];

    int ans = res[0];

    REP(i,N){
        ans = gcd(ans, res[i]);
    }

    cout << ans << endl;

    return 0;
}


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

trains = []
for i in range(1, N):
    trains.append(list(map(int, input().split())))

for i in range(1, N+1):
    if i == N:
        print(0)
        continue
    result_time = 0
    for j, train in enumerate(trains):
        if j + 1 < i:
            continue
        c, s, f = train
        if result_time < s:
            result_time = s
        else:
            while result_time % f != 0:
                result_time += 1
        result_time += c

    print(result_time)


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

int main() {
    int a, b, c, d, T, A;
    cin >> a >> b >> c >> d;
    //高橋君のモンスターが殴られる回数
    if (a % d != 0) {
        T = a / d + 1;
    } else {
        T = a / d;
    }
    //青木君のモンスターが殴られる回数
    if (c % b != 0) {
        A = c / b + 1;
    } else {
        A = c / b;
    }
    if (T >= A) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 3596
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <numeric>
#include <mutex>
#include <cmath>
#define lli long long int
#define ll long long
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;

int main(){
  int a, b, c, N, K, ans;
  cin >> N >> K;
  ans = N - K + 1;
  cout << ans;
  return 0;
}


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

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define TO_STRING(VariableName) # VariableName
#define LOG(x) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" ";
#define LOGE if(DEBUG)cout<<endl;

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



void func(long long M, std::vector<long long> d, std::vector<long long> c){

    lli ans = 0;

    lli sum = 0;
    REP(i,0,M){
        ans += c[i];
        sum += c[i]*d[i];
    }

    cout<<(ans-1)+(sum-1)/9<<endl;

}

int main(){
    // cout << fixed << setprecision(5);

    long long M;
    scanf("%lld",&M);
    std::vector<long long> d(M);
    std::vector<long long> c(M);
    for(int i = 0 ; i < M ; i++){
        scanf("%lld",&d[i]);
        scanf("%lld",&c[i]);
    }
    func(M, std::move(d), std::move(c));
    return 0;
}


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

int main() 
{
    double a,b,x;
    cin >> a >> b >> x;
    double para;
    double theta;
    if(a*a*b/2 >= x)
    {
        para = 2*x/(a*b*b);
        theta = 3.14159265/2-atanf(para);
    }
    else
    {
        para = (a*a*b-x)/(a*a*a/2);
        theta = atanf(para);
    }
    

    cout.precision(12);
    cout << 180*theta/3.14159265 << endl;
    return 0;
}


Measured memory_bytes: 256
open Batteries
open Printf

let ($) g f x = g (f x)

module MyList = struct
  include List
  let foldl = fold_left
  let foldli = fold_lefti
  let foldr = fold_right
  let foldri = fold_righti
  
  let flatmap = concat_map

  let zipf = map2
  let zipfi = map2i
end

module L = MyList

let swap = Tuple2.swap

let atoi = int_of_string
let itoa = string_of_int
let atof = float_of_string
let ftoa = string_of_float
let ctoi = int_of_char
let itoc = char_of_int

let stocl = String.to_list
let cltos = String.of_list
let spsp s = String.split_on_char ' ' s

module MyString = struct
  include String

  let map' f s = L.map f (stocl s)
  let mapi' f s = L.map f (stocl s)

  let zipf f a b = L.zipf f (stocl a) (stocl b)
  let zipfi f a b = L.zipfi f (stocl a) (stocl b)

  let mkstr f sep ls =
    L.foldl (fun acc x -> acc ^ sep ^ (f x)) (f @@ L.hd ls) (List.tl ls)
end

module S = MyString

module MySet = struct
  include Set

  let fold' f s z = fold f z s
end

module St = MySet

module MyMap = struct
  include Map

  let apply = find
  let apply_or = find_default
end

module Mp = MyMap


let rds () = read_line ()

let rdi () = atoi @@ rds ()

let rdhs () = spsp @@ rds ()
let rdhi () = rdhs () |> L.map atoi

let rdi2 () = match rdhi () with
  | a::b::_ -> (a, b)
  | _ -> (0, 0)

let rdi3 () = match rdhi () with
| a::b::c::_ -> (a, b, c)
| _ -> (0, 0, 0)

let rdi4 () = match rdhi () with
| a::b::c::d::_ -> (a, b, c, d)
| _ -> (0, 0, 0, 0)

let rdi5 () = match rdhi () with
| a::b::c::d::e::_ -> (a, b, c, d, e)
| _ -> (0, 0, 0, 0, 0)

let rdv n rdf =
  let rec rdv' n =
    if n <= 0 then []
    else (
      let s = rdf () in
      s::(rdv' (n - 1))
    )
  in rdv' n

let rdvi n = rdv n rdi
let rdvi2 n = rdv n rdi2
let rdvi3 n = rdv n rdi3
let rdvi4 n = rdv n rdi4

let puts s = print_endline s
let putyn b = puts (if b then "Yes" else "No")
let puti i = puts @@ itoa i

let set_power ls =
  let rec set_power' ls pls =
    match ls with
    | [] -> pls
    | hd::tl -> set_power' tl (L.flatmap (fun p -> [p; hd::p]) pls)
  in set_power' ls [[]]


let rdhf () = rdhs () |> L.map atof
let rdf4 () = match rdhf () with
| a::b::c::d::_ -> (a, b, c, d)
| _ -> (0., 0., 0., 0.)


module Graph = struct

  type 'a t = { nb : (int, int St.t) Mp.t; vdt : (int, 'a) Mp.t }

  let nothing = { nb = Mp.empty; vdt = Mp.empty }

  let add_edge (e : int * int) g =
    let (v1, v2) = e in
    let nbvs = g.nb |> Mp.apply_or St.empty v1 in
    let nb1 = g.nb |> Mp.add v1 (nbvs |> St.add v2) in
    { g with nb = nb1 }

  let add_uedge e g =
    add_edge e (add_edge (swap e) g)

  let from_edges es =
    es |> L.foldl (fun g e -> add_edge e g) nothing

  let from_uedges es =
    es |> L.foldl (fun g e -> add_uedge e g) nothing


end

module G = Graph


let _ =
  let (h1, m1, h2, m2, k) = rdi5 () in
  let dif = (h2 * 60 + m2) - (h1 * 60 + m1) in
  puti @@ max 0 (dif - k)
;;


Measured memory_bytes: 5452
#include <bits/stdc++.h>
#define REP(i, n) for (int i=0, i##_limit=(n); i<i##_limit; ++i)
#define FOR(i, a, b) for (int i=(a), i##_limit=(b); i<i##_limit; ++i)
#define pb push_back
#define mp make_pair
using namespace std;
using ll = long long;
using pi = pair<int, int>;

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

    cout << max(C-(A-B), 0) << endl;
    return 0;
}

Measured memory_bytes: 256
n,m = map(int,input().split())
wa = [0] * 10**6
ac = [0] * 10**6
ans = 0
for i in range(m):
    str_p,str_m = map(str,input().split())
    p = int(str_p)
    if str_m =='WA':
        if ac[p] == 0:
            wa[p] += 1
    else:
        if ac[p] == 0:
            ac[p] = 1
            ans += wa[p]
print(sum(ac),ans)

Measured memory_bytes: 24708
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int count;
  string ans;
  cin >> count;
  bool y = false;
  for (int i = 0; i < count; i++) {
    string s;
    cin >> s;
    if (s == "Y") {
      y = true;
    }
  }
  if (y) {
    cout << "Four" << endl;
  } else {
    cout << "Three" << endl;
  }
}

Measured memory_bytes: 256
def judge(x)
  if x < 400
    0
  elsif x < 800
    1
  elsif x < 1200
    2
  elsif x < 1600
    3
  elsif x < 2000
    4
  elsif x < 2400
    5
  elsif x < 2800
    6
  elsif x < 3200
    7
  else
    8
  end
end
n = gets.to_i
a = gets.chomp.split(" ").map(&:to_i)
backet = Array.new(9,0)
n.times do |i|
  backet[judge(a[i])] += 1
end
cnt = backet[0..7].count{|x| x >= 1}
if cnt != 0
  puts "#{cnt} #{cnt+backet[8]}"
else
  puts "#{1} #{backet[8]}"
end

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

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define BIL ((ll)1e9)
#define MOD ((ll)1e9+7)
#define INF (1LL<<60)           //1LL<<63でオーバーフロー
#define inf (1<<29)             //1<<29でオーバーフロー

int main(int argc,char* argv[]){
    string s;
    cin >> s;

    string prevstr="",nextstr="";
    prevstr+=s[0];
    int count = 1;
    for(int i=1;i<s.size();i++){
        nextstr+=s[i];
        if(prevstr!=nextstr){
            prevstr=nextstr;
            nextstr="";
            count++;
        }
    }

    cout << count << endl;

    return 0;
}


Measured memory_bytes: 3728
#include <iostream>

using namespace std;

int main()
{
	int X, A, B;

	cin >> X >> A >> B;

	if (A - B >= 0)
	{
		cout << "delicious" << endl;
	}
	else if (A - B + X >= 0)
	{
		cout << "safe" << endl;
	}
	else
		cout << "dangerous" << endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int N,A,B,C;
vector<int> l(8);
int dfs(int cur,int a,int b,int c);
int main(){
    cin>>N>>A>>B>>C;
    for(int i=0;i<N;i++)cin>>l[i];
    cout<<dfs(0,0,0,0)<<endl;
    return  0;
}
int dfs(int cur,int a,int b,int c){
    if(cur==N){
        if(min(a,min(b,c))>0){
            return abs(a-A)+abs(b-B)+abs(c-C)-30;
        }
        else{
            return 1e9;
        }
    }
    int ret0,ret1,ret2,ret3;
    ret0=dfs(cur+1,a,b,c);
    ret1=dfs(cur+1,a+l[cur],b,c)+10;
    ret2=dfs(cur+1,a,b+l[cur],c)+10;
    ret3=dfs(cur+1,a,b,c+l[cur])+10;
    return min(min(ret0,ret1),min(ret2,ret3));
}


Measured memory_bytes: 256
import sys
S = str(input())
if len(S) < 2 or len(S) > 27:
    sys.exit()
if not S.islower():
    sys.exit()

result = 'yes'
for I in range(len(S)):
    if S.count(S[I]) > 1:
        result = 'no'
print(result)

Measured memory_bytes: 9024
n = int(input())
list = list(map(int,input().split()))
count = 0
flag = False
while True:
    for i in range(n):
        if list[i]%2 == 0:
            list[i] = list[i]/2
        else:
            flag = True
    if flag==True:
        break
    else:
        count += 1
print(count)

Measured memory_bytes: 3060
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<deque>
#include<map>
#include<queue>
using namespace std;
#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
static const ll maxLL = (ll)1 << 62;
const int mod=1000000007;
int dy[]={-1,0,1,0};
int dx[]={0,1,0,-1};

int par[100010];
int rank1[100010];

//n要素で初期化
void init(int n){
  for(int i=0;i<n;i++){
    par[i]=i;
    rank1[i]=0;
  }
}

//木の根を求める
int find(int x){
  if(par[x]==x){
    return x;
  } else {
    return par[x]=find(par[x]);
  }
}

//xとyの属する集合を併合
void unite(int x,int y){
  x=find(x);
  y=find(y);
  if(x==y) return;

  if(rank1[x]<rank1[y]){
    par[x]=y;
  }else{
    par[y]=x;
    if(rank1[x]==rank1[y])rank1[x]++;
  }
}

//xとyが同じ集合に属するか否か
bool same(int x,int y){
return find(x)==find(y);
}


//#define int ll
signed main(){
    int n,m;
    cin>>n>>m;
    init(n+1);
    int p[100010],x[100010],y[100010];
    repe(i,1,n)cin>>p[i];
    rep(i,0,m){
        cin>>x[i]>>y[i];
        unite(x[i],y[i]);
    }
    int ans=0;
    repe(i,1,n)if(find(p[i])==find(i))ans++;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 2176
s=input()
q=int(input())
for _ in range(q):
  d=input().split()
  d[1]=int(d[1])
  d[2]=int(d[2])
  if d[0]=="print":
    print(s[d[1]:d[2]+1])
  if d[0]=="reverse":
    s=s[:d[1]]+s[d[1]:d[2]+1][::-1]+s[d[2]+1:]
  if d[0]=="replace":
    s=s[:d[1]]+d[3]+s[d[2]+1:]


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

// {
#define debug(var)  do{ std::cout << #var << " : "; view(var); }while(0)
using ll = long long;
using ld = long double;
inline int num (const std::string& S, int idx) noexcept { return S.at(idx) - '0'; }
inline int ctoi(char c) noexcept { return c - '0'; }
inline bool isNumber(char c) noexcept { return ('0'<c && c<'9'? true : false); }
inline int safeCtoi(char c) { if(isNumber(c)) { return ctoi(c); } else { throw 1; } }
inline char itoc(int i) noexcept { return i + '0'; }
inline unsigned int bitMask(int i) noexcept { return (1 << i); }
inline bool isTrue(unsigned int bit, int i) noexcept { return bit & bitMask(i); }
inline bool isEven(int num) noexcept { return !num%2; }
inline bool isOdd(int num) noexcept { return num%2; }
template<typename T> inline short sgn(T num) noexcept { return (num==0? 0 : (num>0? 1 : -1) ); }
template<typename T> inline bool isZero(T num) noexcept { return (num==0? true : false); }
template<typename T> inline bool isPositive(T num) noexcept { return (num>0? true : false); }
template<typename T> inline bool isNegative(T num) noexcept { return (num<0? true : false); }
template<typename T> void view(T e) noexcept { cout << e; }
template<typename T> void view(std::vector<T> v) noexcept { for(const auto& e : v) cout << e << " "; }
template<typename T> void view(std::vector<std::vector<T>> vv) noexcept { for(const auto& v : vv) view(v); }
//}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	vector<int> x(5);
	for(auto& e : x) cin >> e;
	for(int i=0; i<5; ++i){
		if(!x[i]){
			cout << i+1 << endl;
			return 0;
		}
	}
	return 0;
}


Measured memory_bytes: 3604