akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

int A, B, C;

int main()
{
    scanf("%d%d%d", &A, &B, &C);
    int ans = 0;

    int maxV = max({A, B, C});
    while (A + 2 <= maxV)
    {
        A += 2;
        ans += 1;
    }
    while (B + 2 <= maxV)
    {
        B += 2;
        ans += 1;
    }
    while (C + 2 <= maxV)
    {
        C += 2;
        ans += 1;
    }

    int cnt = 0;
    if (A < maxV) cnt += 1;
    if (B < maxV) cnt += 1;
    if (C < maxV) cnt += 1;

    if (cnt == 2)
        ans += 1;
    else if (cnt == 1)
        ans += 2;

    printf("%d", ans);
    return 0;
}

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

#define f(i,a,b) for( ll i = a; i < b ; i++ )
#define af(i,a,b) for( ll i = a; i >= b ; i--)
#define rep(i,a,b,k) for(ll i = a; i < b ; i+= k )
#define arep(i,a,b,k) for( ll i = a; i >= b ; i-= k)
#define ones(x) (ll) __builtin_popcount(x)
#define fs first
#define sc second
#define pb push_back
#define po pop_back
#define mp make_pair  
#define sz(a) (ll) a.size()
#define all(a) a.begin(), a.end()
#define sor(a) sort( a.begin(), a.end() )
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ller ios::sync_with_stdio(false);cin.tsie(nullptr);cout.tie(nullptr)
#define watch(x) cout << (#x) << " is " << (x) <<"#" <<endl
#define PI 3.1415926535
using namespace std;
typedef long long ll;
typedef long double ld; 
typedef pair<ll,ll> ii ;
typedef vector<ll>  vi ;
typedef vector<ii> vii ;
const ll mod = 1e9+7;
const ll MAX = 2e5+23;
const ll inf = 1e18+7;
ll parent[MAX];

ll finds(ll v){
    if(parent[v]==v) return v;
    return parent[v] = finds(parent[v]);
}
void uni(ll a,ll b){
    a = finds(a);
    b = finds(b);
    if(a!=b){
        parent[a] = b;
    }
}
ll tam[MAX];

int main(){
  fastio;
  ll n,m;
  cin>>n>>m;
  f(i,1,n+1) parent[i]=i;
  f(i,0,m){
    ll x,y;
    cin>>x>>y;
    uni(x,y);
  }
  ll cnt=0;
  f(i,1,n+1){
    tam[finds(i)]++;
  }
  f(i,1,n+1){
    cnt = max(cnt,tam[i]);
  }
  cout<<cnt<<"\n";
  return 0; 
}

Measured memory_bytes: 11436
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner scanner=new Scanner(System.in);
		int[] height=new int[10];
		int temp;
		for(int a=0;a<height.length;a++){
			height[a]=scanner.nextInt();
		}
		for(int i=0;i<height.length;i++){
			for(int j=0;j<height.length-1;j++){
				if(height[j]<height[j+1]){
					temp=height[j];
					height[j]=height[j+1];
					height[j+1]=temp;
				}
			}
		}
		for(int i=0;i<3;i++){
			System.out.println(height[i]);
		}
	}
}

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

using namespace std;

#ifdef DGC
#include "debug.h"
#else
#define debug(...) 9715
#endif
typedef long long ll;
typedef long double ld;
typedef complex<ll> point;
#define F first
#define S second



int main()
{
	#ifdef DGC
		//freopen("a.in", "r", stdin);
		//freopen("b.out", "w", stdout);
	#endif

	ios_base::sync_with_stdio(0), cin.tie(0);

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

	int ans = 0;
	for (int i = 0; i+3 <= n; ++i)
		ans += s.substr(i, 3) == "ABC";
	cout << ans << "\n";

	return 0;
}



Measured memory_bytes: 256
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner in=new Scanner(System.in);
		
		int n=in.nextInt();
		BTNode[] tree=new BTNode[n];
		for(int i=0;i<n;i++)tree[i]=new BTNode();
		
		for(int i=0;i<n;i++) {
			int id=Integer.parseInt(in.next()),
					l=Integer.parseInt(in.next()),
					r=Integer.parseInt(in.next());
			
			if(l!=-1) {
				tree[id].lc=l;
				tree[l].p=id;
			}
			if(r!=-1) {
				tree[id].rc=r;
				tree[r].p=id;
			}
		}
		in.close();
		
		int root=findRoot(tree);
		
		System.out.println("Preorder");
		preWalk(tree,root);
		System.out.println("\nInorder");
		inWalk(tree,root);
		System.out.println("\nPostorder");
		postWalk(tree,root);
		System.out.println();
	}
	
	static int findRoot(BTNode[] tree) {
		for(int i=0;i<tree.length;i++) {
			if(tree[i].p==-1)return i;
		}
		
		return -1;
	}
	
	static void preWalk(BTNode[] tree,int pos){
		System.out.print(" "+pos);
		if(tree[pos].lc!=-1)preWalk(tree,tree[pos].lc);
		if(tree[pos].rc!=-1)preWalk(tree,tree[pos].rc);
	}
	
	static void inWalk(BTNode[] tree,int pos){
		if(tree[pos].lc!=-1)inWalk(tree,tree[pos].lc);
		System.out.print(" "+pos);
		if(tree[pos].rc!=-1)inWalk(tree,tree[pos].rc);
	}
	
	static void postWalk(BTNode[] tree,int pos){
		if(tree[pos].lc!=-1)postWalk(tree,tree[pos].lc);
		if(tree[pos].rc!=-1)postWalk(tree,tree[pos].rc);
		System.out.print(" "+pos);
	}

}

class BTNode{
	int p=-1,lc=-1,rc=-1;
}


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

void solve(long long N, long long M, std::vector<long long> A)
{
    sort(begin(A), end(A));

    while (M > 0)
    {
        while (M > 0 && (A.size() == 1 || A.back() / A[A.size() - 2] >= 2))
        {
            A.back() /= 2;
            M--;
        }

        auto it = upper_bound(begin(A), end(A), A.back() / 2);
        it += max(distance(it, end(A)) - M, 0LL);
        if (it != end(A))
        {
            transform(it, end(A), it, [](int n) { return n / 2; });
            M -= distance(it, end(A));
            sort(begin(A), end(A));
        }
    }

    long long ans = accumulate(begin(A), end(A), 0LL);
    cout << ans << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);

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


Measured memory_bytes: 1024
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main(void)
{
    int n;
    int x[100] = {0};
    int y[100] = {0};
    double d1 = 0.0;
    double d2 = 0.0;
    double d3 = 0.0;
    double dinf = 0.0;

    scanf("%d", &n);

    for ( int i = 0; i < n; i++ ) {
        scanf("%d", &x[i]);
    }

    for ( int i = 0; i < n; i++ ) {
        scanf("%d", &y[i]);
    }

    //  p = 1
    for ( int i = 0; i < n; i++ ) {
        d1 += (double)abs(x[i] - y[i]);
    }

    //  p = 2
    for ( int i = 0; i < n; i++ ) {
        d2 += pow(abs(x[i] - y[i]), 2.0);
    }
    d2 = sqrt(d2);

    //  p = 3
    for ( int i = 0; i < n; i++ ) {
        d3 += pow(abs(x[i] - y[i]), 3.0);
    }
    d3 = cbrt(d3);

    //  p = ∞
    for ( int i = 0; i < n; i++ ) {
        if ( abs(x[i] - y[i]) >= dinf ) {
            dinf = abs(x[i] - y[i]);
        }
    }

    printf("%lf\n", d1);
    printf("%lf\n", d2);
    printf("%lf\n", d3);
    printf("%lf\n", dinf);
    
    return 0;
}


Measured memory_bytes: 2108
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <map>
#include <cstdlib>
#include <math.h>

using namespace std;

typedef long long ll;
#define rep(i, n) for(long (i) = 0; (i) < (long) (n); (i)++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,a,b) for(long i=(a);i<(b);i++)
#define rrep1(i,a,b) for(long i=(a);i<=(b);i++)
#define rrrep(i,a,b) for(long i=(a);i>=(b);i--)
#define define pb push_back
#define ALL(obj) (obj).begin(), (obj).end()
#define X first
#define Y second
#define vi vector<int>
#define vl vector<ll>
#define vvi vector<vector<int> >
#define vpl vector<pair<long, long> >
#define vppl vector<pair<long, pair<long, long> > >

const int INF = 100100100;
const long LONG_INF = 2147483647;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
const ll LINF = 1e18;


int pow(int x) {
	if (x == 0) {
		return 1;
	}
	else {
		return pow(x - 1) * 2;
	}
}

int main(int argc, char const *argv[])
{
	cin.tie(0);
	ios::sync_with_stdio(false);
    string a;
    cin >> a;
    if (a == "A") {
        a = "T";
    } else if (a == "T")
    {
        a = "A";
    } else if (a == "C")
    {
        a = "G";
    } else
    {
        a = "C";
    }
    cout << a << endl;
    
    
    
    
    return 0;
}


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

const int MAXN = 2e5 + 5;

int n;
vector<int> adj[MAXN];

void input(){
	scanf("%d", &n);
	for(int i = 0; i < n-1; ++i){
		int u, v;
		scanf("%d %d", &u, &v);
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
}

int getDiameter(){
	int dist[MAXN], farthestNode = 1;

	memset(dist, -1, sizeof dist);
	queue<int> bfs;
	bfs.push(1);
	dist[1] = 0;
	while(!bfs.empty()){
		int top = bfs.front(); bfs.pop();
		if(dist[farthestNode] < dist[top])
			farthestNode = top;
		for(int i : adj[top]){
			if(dist[i] != -1)
				continue;
			dist[i] = dist[top]+1;
			bfs.push(i);
		}
	}

	fprintf(stderr, "Farthest node = %d\n", farthestNode);

	memset(dist, -1, sizeof dist);
	bfs.push(farthestNode);
	dist[farthestNode] = 0;
	while(!bfs.empty()){
		int top = bfs.front(); bfs.pop();
		if(dist[farthestNode] < dist[top])
			farthestNode = top;
		for(int i : adj[top]){
			if(dist[i] != -1)
				continue;
			dist[i] = dist[top]+1;
			bfs.push(i);
		}
	}

	fprintf(stderr, "Diameter = %d\n", dist[farthestNode]);

	return dist[farthestNode];
}

/*
Let D be the set of nodes along the diameter of the tree
If the current player choose a leaf node from D, he will shrink the diameter by 1
Otherwise, he will shrink the diameter by 2

Diameter
-1 0 1 2 3 4 5 6 7
 L W L W W L W W L
*/

void work(){
	// Find diameter of the tree
	int d = getDiameter();

	if(d == 1 || (d >= 4 && d%3 == 1)){
		printf("Second\n");
	}else{
		printf("First\n");
	}
}

int main(){
	input();
	work();
}

Measured memory_bytes: 13556
a, b, c, d = map(int, input().split())
if a <= c and c <= b and b <= d:
    print(b-c)
elif a <= c and c <= b and d <= b:
    print(d-c)
elif c <= a and b <= d:
    print(b-a)
elif c <= a and a <= d and d <= b:
    print(d-a)
else:
    print(0)

Measured memory_bytes: 3060
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <list>

using namespace std;

typedef long long ll;

#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(d) string(1,d)
#define print(x) cout<<#x<<" = "<<x<<endl;

#define MOD 1000000007

ll n,k;
ll ans;
vector<vector<ll> > v;
ll d[200005];
ll dd[200005];

int f(int p){
  d[p] = 1;
  int ret = 100000000;
  rep(i,0,v[p].sz){
    if(d[v[p][i]]!=1){
      ret = min(ret,f(v[p][i]));
    }
  }
  if(ret == 100000000)return k;
  if(ret-1 == 1){
    if(p!=0&&dd[p]!=0){
      ans++;
    }
    return k+1;
  }
  else{
    return ret-1;
  }
}

int main() {
  cin>>n>>k;
  ans = 0;
  vector<vector<ll> > v_(n,vector<ll>());
  v = v_;
  rep(i,0,n){
    ll a;
    cin>>a;
    a--;
    dd[i] = a;
    if(i==0&&a!=0)ans++;
    if(i!=0){
      v[a].pb(i);
      v[i].pb(a);
    }
  }
  if(k==1){
    rep(i,1,n){
      if(dd[i]!=0)ans++;
    }
    cout << ans << endl;
    return 0;
  }
  clr(d,0);
  f(0);
  cout << ans << endl;
  return 0;
}




Measured memory_bytes: 15104
#include<bits/stdc++.h>
using namespace std;
const int maxn=500;
char c[maxn][maxn];
char ans[maxn][maxn];
int main(){
	int h,w;
	cin>>h>>w;
	for(int i=1;i<=h;i++){
		for(int j=1;j<=w;j++){
			cin>>c[i][j];
		}
	}
	for(int i=1;i<=h*2;i++){
		for(int j=1;j<=w;j++){
			ans[i][j]=c[(i+1)/2][j];
		}
	}
	for(int i=1;i<=h*2;i++){
		for(int j=1;j<=w;j++){
			cout<<ans[i][j];
		}
		cout<<endl;
	}
	return 0;
}


Measured memory_bytes: 384
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;

/*
<url:https://cf16-exhibition-final-open.contest.atcoder.jp/tasks/cf16_exhibition_final_a>
問題文============================================================
 一次元の世界に N 個のパソコンと N 個の電源があります。
 i 番目のパソコンの座標は ai であり、 i 番目の電源の座標は bi です。
 これらの 2N 個の座標は相異なることが保証されています。
 
 すぬけ君は、それぞれのパソコンをケーブルで電源につなぎたいです。
 それぞれの電源は一つのパソコンにのみつなぐことができます。
 
 何通りの方法で、ケーブルの長さの合計を最小化できるでしょうか？ 答えを modulo 10^9+7 で求めてください。
=================================================================

解説=============================================================
PC の座標を oo_a , 電源の座標を oo_b とする
 
 0_a 10_a 15_a 20_b 25_b 30_b
 
 と並んでいたとすると、 最初の3つのPC座標 0 , 10 ,15 は後半の電源のどの座標を選んでも
 全体の長さは変わらない (一つのPCが一つの電源を選択することによって変化する増(減)分は他方で回収されるから）
 
 よって、 20_b は 0 10 15 の中から自由に選ぶことができ
        25_b は 20_bが使用していない二つから
        30_b は 20_b 25_bが使用していない一つ
 を選ぶことができる
 これは PC を 電源の座標が入れ替わっても同様の考えができる
 
 ex.
 0_b 10_b 15_b 20_a 25_a 30_a
 
 よって、座標を左から順番に見ていって、それぞれ PC と　電源がいくつ選択巣rことができるのかを
 シミュレーションしていけば良い
 
================================================================
*/
const ll MOD = 1e9+7;
ll solve(){
    ll N; cin >> N;
    vector<ll> a(N),b(N);
    for(auto &in:a) cin >> in;
    for(auto &in:b) cin >> in;
    sort(a.begin(),a.end()); sort(b.begin(),b.end());
    
    vector<pll> event(2*N);
    for(int i = 0; i < N;i++){ event[i] = {a[i],0}; }
    for(int i = 0; i < N;i++){ event[i+N] = {b[i],1}; }
    
    sort(event.begin(),event.end());

    ll ret = 1;
    
    ll cnt1 = 0, cnt2 = 0;
    for(int i = 0; i < 2*N;i++){
        if(event[i].second == 0){
            if(cnt2 != 0){
                (ret *= cnt2)%=MOD;
                cnt2--;
            }else{ cnt1++; }
        }else{
            if(cnt1 != 0){
                (ret *= cnt1)%=MOD;
                cnt1--;
            }else{ cnt2++; }
        }
    }
    return ret;
}
int main(void) {
	cin.tie(0); ios::sync_with_stdio(false);
    cout << solve() << endl;
	return 0;
}


Measured memory_bytes: 4992
#include <iostream>
#include <string>
#include <deque>

int main() {
	std::string str1, str2;
	std::cin >> str1 >> str2;
	str1 += str1;
	
	if (str1.find(str2) != std::string::npos)
		std::cout << "Yes" << std::endl;
	else
		std::cout << "No" << std::endl;

	return 0;
}

Measured memory_bytes: 3168
N = int(input())
X = list(map(int,input().split()))
X_sort = sorted(X)
median_large = X_sort[N//2]
median_small = X_sort[N//2-1]
if median_large == median_small:
    for _ in range(N):
        print(median_large)
else:
    for i in range(N):
        if X[i] <= median_small:
            print(median_large)
        elif X[i] >= median_large:
            print(median_small)



Measured memory_bytes: 26772
#include <bits/stdc++.h>
using namespace std;
int INF = 1000000;
int main(){
  int N;
  cin >> N;
  vector<int> dp(N + 1, INF);
  dp[0] = 0;
  for (int i = 1; i <= N; i++){
    int j = 1;
    while (j <= i){
      dp[i] = min(dp[i], dp[i - j] + 1);
      j *= 6;
    }
    j = 9;
    while (j <= i){
      dp[i] = min(dp[i], dp[i - j] + 1);
      j *= 9;
    }
//    cout << i << ": " << dp[i] << endl;
  }
  cout << dp[N];
}

Measured memory_bytes: 640
#include <cstdio>
#define ref(i,x,y)for(int i=x;i<=y;++i)
typedef long long LL;
const int N=3001;
int n,w[N],a[N][N];
bool solve(int f,int x){
	ref(i,1,a[x][0])if(a[x][i]!=f&&w[a[x][i]]<w[x])
		if(!solve(x,a[x][i]))return 1;
	return 0;
}
int main(){
	scanf("%d",&n);
	ref(i,1,n)scanf("%d",&w[i]);
	ref(i,2,n){
		int x,y;scanf("%d%d",&x,&y);
		a[x][++a[x][0]]=y;a[y][++a[y][0]]=x;
	}
	ref(i,1,n)if(solve(0,i))printf("%d ",i);
}

Measured memory_bytes: 33792
#include <bits/stdc++.h>
#include<iostream>
using namespace std;
 
int main() {
   string s;
	int a(0),b(0);
   cin >> s;

   for(int i = 0; i < 3;i++){
      if(s.at(i) == 'A'){
         a = 1;
        //cout <<s.at(i);;
      }
      if(s.at(i) == 'B'){
         b = 1;
      }
   }

   if(a == 1 && b == 1){
      cout << "Yes";
   }else{
      cout << "No";
   }

   
}


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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#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--)
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

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

// 約数列挙
vector<ll> divisor(ll N) {
    vector<ll> res;
    for (ll i = 1L; i * i <= N; ++i) {
        if (N % i == 0) {
            res.push_back(i);
            ll j = N / i;
            if (j != i)  {
                res.push_back(j);
            }
        }
    }
    sort(res.begin(), res.end());
    return res;
}

void Main() {
    ll N, M; cin >> N >> M;
    vector<ll> X = divisor(M);
    sort(X.begin(), X.end(), greater<int>()); // 大きい方から取り出す
    for(auto v: X){
        if (v * N > M){
            continue;
        } else {
            cout << v << endl;
            break;
        }
    }
}

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define REP(i,b,e) for(ll i=(ll)b;i<(ll)e;i++)
#define rep0(i,n) REP(i,0ll,n)
#define rep1(i,n) REP(i,1ll,n+1)
const ll longinf=1ll<<60;
const int inf=(1<<30)-1;


//II→factorialを計算するrange
const ll MOD = 1e9+7;
const ll II = 2e5+3;
 
ll addMod(ll a,ll b){
      return ((a%MOD)+(b%MOD))%MOD;
}
 
ll mulMod(ll a,ll b){
      return ((a%MOD)*(b%MOD))%MOD;
}
 
ll powMod(ll a,ll b){
      if(b==0) return 1;
      else if(b%2==0){
            ll ret=powMod(a,b/2);
            return ((ret%MOD)*(ret%MOD))%MOD;
      }
      else return ((powMod(a,b-1)%MOD)*(a%MOD))%MOD;
}
ll divMod(ll a,ll b){
      return ((a%MOD)*(powMod(b,MOD-2)%MOD))%MOD;
}
 
ll fact[II+1];
ll invfact[II+1];

void calc(){ //main関数内にcalc();を入れること(前計算)
      fact[0]=1;
      invfact[0]=1;
      rep0(i,II){
            fact[i+1]=mulMod(fact[i],i+1);
            invfact[i+1]=divMod(1,fact[i+1]);
      }
}


int main(){
      ll n,a,b,c;
      cin>>n>>a>>b>>c;
      calc();
      ll p=divMod(a,a+b);
      ll q=divMod(b,a+b);
      ll ans=0;
      for(int m=n;m<2*n;m++){
            ll comb=mulMod(fact[m-1],invfact[n-1]);
            comb=mulMod(comb,invfact[m-n]);
            ll A=mulMod(powMod(p,n),powMod(q,m-n));
            ll B=mulMod(powMod(p,m-n),powMod(q,n));
            ll C=mulMod(addMod(A,B),m);
            ans=addMod(ans,mulMod(comb,C));
      }
      ll d=divMod(100ll,addMod(a,b));
      cout<<mulMod(ans,d)<<endl;
    return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define lsb(x) (x & (-x))

using namespace std;

#define a first
#define b second

const ll INF = 1e18;

int main() {
#ifdef HOME
	ifstream cin("C.in");
	ofstream cout("C.out");
#endif
	int i, n, t;
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);

	cin >> n >> t;
	vector <pair <int, int>> arr(n + 1);
	for(i = 1; i <= n; i++) {
		cin >> arr[i].a >> arr[i].b;
		arr[i].a++;
	}
	sort(next(arr.begin()), arr.end(), [&](const pair <int, int> &x, const pair <int, int> &y) {
		if(x.a == 1 && y.a == 1) {
			return x.b < y.b;
		}
		return 1LL * x.b * y.a + y.a + y.b > 1LL * y.b * x.a + x.a + x.b;
	});

	vector <ll> best(41, INF);
	best[0] = 0;

	while(arr.size() && arr.back().a >= 2) {
		vector <ll> cur(41, INF);
		for(int j = 0; j < 40; j++) {
			if(best[j] <= t) {
				cur[j + 1] = 1LL * (best[j] + 1) * arr.back().a + arr.back().b;
			}
		}
		for(int j = 0; j <= 40; j++) {
			best[j] = min(best[j], cur[j]);
		}
		arr.pop_back();
	}
	int ans = 0;
	for(int j = 0; j <= 40; j++) {
		if(best[j] >= t + 1) continue;

		ll cur = best[j];
		i = 1;
		while(i < (int)arr.size() && cur + arr[i].b + 1 <= t) {
			cur += arr[i].b + 1;
			i++;
		}
		ans = max(ans, j + i - 1);
	}

	cout << ans;

	return 0;
}


Measured memory_bytes: 1792
n = int(input())
P = list(map(int, input().split()))

check = 0
ans = 0
for i in range(n):
    if P[i] == i+1:
        ans += 1
        if check == 1:
            ans -= 1
            check = 0
        else:
            check += 1
    else:
        check = 0
print(ans)
        

Measured memory_bytes: 14008
#include<cstdio>
#include<queue>
#include<utility>
#include<cstring>
#include<stack>
#include<algorithm>
#include<cmath>
#include<iostream>
#include<map>
#define MAX_N 100001
#define INF_INT 2147483647
#define INF_LL 9223372036854775807
#define REP(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
void init(int n);
int find(int n);
void unite(int x,int y);
bool same(int x, int y);
ll bpow(ll,ll,ll);
typedef vector<int> vec;
typedef vector<vec> mat;
mat mul(mat &A,mat &B);
mat pow(mat A,ll n);
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};


bool cmp_P(const P &a,const P &b){
  return a.second < b.second;
}
int main()
{
  ll N,A,B;
  cin >> N >> A >> B;
  ll res = (((N-1)*B+A) - (((N-1)*A+B)) + 1);
  cout << (res >= 0 ? res : 0 )<< endl;
  
  return 0;
}

int par[MAX_N];
int ranks[MAX_N];

//n要素で初期化
void init(int n){
  REP(i,n){
    par[i] = i;
    ranks[i] = 0;
  }

}

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

void unite(int x,int y){
  x = find(x);
  y = find(y);
  if(x == y) return ;
  if(ranks[x] < ranks[y]){
    par[x] = y;
  }else{
    par[y] = x;
    if(ranks[x] == ranks[y]) ranks[x]++;
  }
}

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

ll bpow(ll a, ll n,ll mod){
  int i = 0;
  ll res=1;
  while(n){
    if(n & 1)
      res = (res*a) % mod;
    a = (a*a) % mod;
    n >>= 1;
  }
  return res;
}
const int MOD = 1000000007;
mat mul(mat &A, mat &B){
  mat C(A.size(),vec(B[0].size()));
    REP(i,A.size())REP(k,B.size())REP(j,B[0].size()){
    C[i][j] = (C[i][j] + A[i][k] * B[k][j]) % MOD;
  }
  return C;
}

mat pow(mat A,ll n)
{
  mat B(A.size(),vec(A.size()));
  REP(i,A.size()){
    B[i][i] = 1;
  }
  while(n > 0){
    if ( n & 1) B = mul(B,A);
    A = mul(A,A);
    n >>= 1;
  }
  return B;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cstring>
using namespace std;
char s[2100];
int len, first, last;
int main()
{
	scanf("%s",s+1);
	len = strlen(s+1);
	first = 1000000000, last = 0;
	for(int i=1;i<=len;i++)
	{
		if(s[i] == 'C') first = min(i, first);
		if(s[i] == 'F') last = max(i, last);
	}
	if(first < last) printf("Yes\n");
	else printf("No\n");
	
	return 0;
}

Measured memory_bytes: 256
//ABC138-D
#include <iostream>
#include <vector>
#include <queue>
#include <stack>

using namespace std;

using Edge = pair<int, int>; //エッジ(本問題では使わない))
using Graph = vector<vector<int>>;	//グラフ

int N, Q;
Graph G;

// res は答え
vector<int> res;

// v:現在のノード p:親ノード
void dfs_recursive(int v, int p) {
	for (auto e : G[v]) {
		if (e == p) continue;	//親ノードにさかのぼらない
		res[e] += res[v];		//親の答えを子に足し合わせる
		dfs_recursive(e, v);	//vから下流に進む，このときvが親ノードになる
	}
}

void dfs(int start) {
	vector<int> visited(N, -1); //訪問フラグ
	stack<int> vstack; //待ち配列
	vstack.push(start);
	while (!vstack.empty()) {
		int v = vstack.top(); // スタックから先頭頂点を取り出す
		vstack.pop();
		visited[v] = 0; //訪問フラグを立てる

		// v から辿れる頂点をすべて調べる
		for (auto nv : G[v]) {
			if (visited[nv] != -1) continue; // すでに発見済みの頂点は探索しない
			res[nv] += res[v];
			vstack.push(nv);
		}
	}
}

void bfs(int start) {
	vector<int> visited(N, -1); //訪問フラグ
	queue<int> que; //待ち配列
	que.push(start);
	while (!que.empty()) {
		int v = que.front(); // キューから先頭頂点を取り出す
		que.pop();
		visited[v] = 0; //訪問フラグを立てる

						// v から辿れる頂点をすべて調べる
		for (auto nv : G[v]) {
			if (visited[nv] != -1) continue; // すでに発見済みの頂点は探索しない
			res[nv] += res[v];
			que.push(nv);
		}
	}
}

int main(void) {
	cin >> N >> Q;
	G.assign(N, vector<int>());
	for (int i = 0; i < N - 1; i++) {
		int u, v; cin >> u >> v;
		u--, v--;
		G[u].push_back(v);
		G[v].push_back(u);
	}
	res.assign(N, 0);
	for (int i = 0; i < Q; i++) {
		int x, value; cin >> x >> value;
		x--;
		res[x] += value;
	}
	bfs(0);
	for (auto v : res) cout << v << ' ';
	cout << endl;
	return 0;
}

Measured memory_bytes: 15588
import fractions

def f(x, c, d):
    lcm_num = c*d // fractions.gcd(c, d)
    return x - x//c - x//d + x//lcm_num

a, b, c, d = map(int, input().split())
print(int(f(b, c, d) - f(a-1, c, d)))

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

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

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> tiii;

const int INF=1<<30;
const ll LINF = 1e18+5;

int main() {
    int T1, T2;
    ll A1, A2, B1, B2;
    cin >> T1 >> T2 >> A1 >> A2 >> B1 >> B2;
    ll Ac = T1 * (A1 - B1);
    ll Bc = T2 * (A2 - B2);
    if (Ac == -1 * Bc) {
        cout << "infinity" << endl;
        return 0;
    } else if (Ac>0&&Bc>0 || Ac<0&&Bc<0) {
        cout << 0 << endl;
        return 0;
    }
    Bc = Bc * -1;
    if (Ac<0) Ac*=-1;
    if (Bc<0) Bc*=-1;
    if (Ac > Bc) {
        cout << 0 << endl;
        return 0;
    }else {
        ll n = Ac / (Bc - Ac);
        n *= 2;
        if (n != 0 && Ac % (Bc - Ac) == 0) n--;
        cout << n + 1 << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string>
#include <vector>
#include <iostream>
#include <cstring>
#include <cstdio>


#define ll long long
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define pii pair<int,int>
#define f(n) for (ll i = 0; i < n; i++)

using namespace std;

int main()
{
	ios_base::sync_with_stdio(0);
	int n, d;
	cin >> n >> d;
	int c = 0;
	vector<vi > points;
	f(n)
	{
		vi nums(d);
		f(d) cin >> nums[i];
		points.push_back(nums);
	}
	f(n)
	{
		for (int j = 0; j < i; j++)
		{
			double dis = 0;
			for (int k = 0; k < d; k++) dis += abs(points[i][k] - points[j][k]) * abs(points[i][k] - points[j][k]);
			dis = sqrt(dis);
			if (dis == floor(dis)) c++;
		}
	}
	cout << c << '\n';
}


Measured memory_bytes: 256
#include <vector>
#include <map>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long int ll;

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

int main(int argc, const char * argv[]) {
    
    int A, B, C;
    cin >> A >> B >> C;
    
    C -= ( A - B );
    
    if (C < 0) {
        C = 0;
    }
    
    cout << C;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
using namespace std;
int n,m;
vector<int> fri[501];
int ff[501];
main(){
  while(1){
    scanf("%d",&n);
    scanf("%d",&m);
    if(n==0 && m==0) break;
    memset(ff,0,sizeof(ff));
    for(int i=0;i<=501;i++)
      fri[i].clear();
    for(int i=0;i<m;i++){
      int a,b;
      scanf("%d %d",&a,&b);
      fri[a].push_back(b);
      fri[b].push_back(a);
    }
    int M=fri[1].size();
    for(int i=0;i<M;i++){
      int N=fri[fri[1][i]].size();
      for(int j=0;j<N;j++){
	ff[fri[fri[1][i]][j]]=1;
      }
      ff[fri[1][i]]=1;
    }
    int res=0;
    for(int i=2;i<=n;i++){
      if(ff[i]==1)res++;
      //    printf("%d ",ff[i]);
    }
    printf("%d\n",res);
  }
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
 
int main (){
  int count = 0;
  string a;
  cin >> a;
  
  if(a[0] == '1') ++count;
  if(a[1] == '1') ++count;
  if(a[2] == '1') ++count;

  cout << count << endl;
}
    


Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    }
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[derive(Debug)]
struct Shop {
    price: i64,
    num: i64,
}

fn main() {
    input! {
        n: i64,
        m: i64,
        inp: [[i64; 2]; n]
    }
    let mut shops: Vec<Shop> = Vec::new();
    for val in inp.into_iter() {
        shops.push(Shop {
            price: val[0],
            num: val[1],
        });
    }
    shops.sort_by_key(|shop| shop.price);
    let mut ans = 0;
    let mut cnt = 0;
    for shop in shops {
        for _ in 0..shop.num {
            ans += shop.price;
            cnt += 1;
            if cnt == m {
                println!("{}", ans);
                return;
            }
        }
    }
}


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

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    int n, m;
    cin >> n >> m;
    pair<int, int> kek = {1, n};
    for (int i = 0; i != n; ++i)
    {
        int l, r;
        cin >> l >> r;
        kek.first = max(kek.first, l);
        kek.second = min(kek.second, r);
    }
    cout << max(0, kek.second - kek.first + 1) << '\n';
    return 0;
}

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

int main() {

  int H , W;

  while(1) {

    cin >> H >> W;

    if ( H == 0 && W == 0) break;

    for (int i = 0; i < H ; i++) {

      for (int j = 0; j < W ; j++) {

	if (i % 2 == 0) {

	  if(j % 2 == 0) {

	    cout << "#";

	  } else {

	    cout << ".";

	  } 

	} else { 

	  if (j % 2 == 0) {

	    cout << ".";

	  } else { 

	    cout << "#";

	  }

	}

      }

      cout << "\n";

    }

    cout << "\n" ;
  
  }

  return 0;

}

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

typedef long long ll;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll LINF = 1e18;
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define MP make_pair
#define MT make_tuple
#define F first
#define S second
#define PB push_back
#define dump(x)  cout << #x << " = " << (x) << endl;	//debug
#define SZ(x) ((ll)(x).size())
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define RFOR(i, a, b) for (ll i = (a); i >= (b); i--)
#define ps(s) cout << #s << endl;
#define pv(v) cout << (v) << endl;
#define pvd(v) cout << setprecision(16) << (v) << endl;
#define ALL(a)  (a).begin(),(a).end()
#define RANGE(a, start_index, num)  (a).begin()+(start_index),(a).begin()+(num)

int main() {
	ll n;
	cin >> n;
	vector<ll> a(n + 1);
	FOR(i, 1, n) {
		cin >> a[i];
	}
	ll money = 1000, kabu = 0;
	FOR(i, 1, n) {
		if (i != n && a[i + 1] >= a[i]) {
			ll tmp = money / a[i];
			kabu += tmp;
			money -= tmp * a[i];
		}
		else {
			money += kabu * a[i];
			kabu = 0;
		}
	}
	pv(money)
	return 0;
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
vector<ll> prime;
ll size = 1010101;
int main() {
  vector<bool> used(size);
  for (int i = 2; i < size; i++) {
    if (!used[i]) {
      prime.push_back(i);
      for (int j = 1; i * j < size; j++)
        used[i * j] = true;
    }
  }
  while (true) {
    int n, p;
    cin >> n >> p;
    if (n == -1)
      break;
    auto it = upper_bound(prime.begin(), prime.end(), n);
    vector<ll> ps;
    for (int i = 0; i < p; i++)
      for (int j = i; j < p; j++)
        ps.push_back((*(it + i)) + (*(it + j)));
    sort(ps.begin(), ps.end());
    cout << ps[p - 1] << endl;
  }
  return 0;
}


Measured memory_bytes: 3776
#include <algorithm>
    #include <string.h>
    #include <iostream>
    using namespace std;
     
    int main( )
    {
        int a,b;
        cin>>a>>b;
        char s[100];
        cin>>s;
        if(strlen(s)!=a+b+1||s[a]!='-'||a>5||a<1||b>5||b<1)
        {
            cout<<"No";return 0;
        }
        for(int i=0;i<=a+b;i++)
        {
            if(i==a) continue;
            if(s[i]<'0'||s[i]>'9')
            {
                cout<<"No";
                return 0;
            }
        }
     
        cout<<"Yes";
     
     
        return 0;
    }

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

#define ll long long
#define ull unsigned long long 
#define endl '\n'
#define pii pair<int, int>
#define all(a) a.begin(),a.end()

template <typename T>
inline T gcd(T a, T b) { while (b != 0) swap(b, a %= b); return a; }

int main(){
    int d, n;
    cin >> d >> n;
    if(n==100)
        cout << 101 << string((d>0)?2*d:0,'0');
    else
        cout << n << string((d>0)?2*d:0,'0');
}


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

int main() {
    int n, m; cin >> n >> m;
    int A[n]; for (int i=0; i<n; i++) cin >> A[i];
    int B[m]; for (int j=0; j<m; j++) cin >> B[j];

    int vote[n]; for (int i=0; i<n; i++) vote[i] = 0;
    for (int j=0; j<m; j++)
        for (int i=0; i<n; i++)
            if (A[i] <= B[j]) {
                vote[i]++;
                break;
            }

    int vote_max = 0, best = 0;
    for (int i=0; i<n; i++)
        if (vote[i] > vote_max) {
            vote_max = vote[i];
            best = i;
        }

    cout << best + 1 << endl;
}


Measured memory_bytes: 3100
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <string.h>
#include <math.h>
#include <time.h>
#include <stdlib.h>
using namespace std;



int main(){
	int n,dig,ans;
	char max[10],min[10],g;
	cin >> n;
	for(int i=0;i<n;i++){
		scanf("%s",max);
		for(int t=0;t<8;t++){
			min[t] = max[t];
		}
		ans=0;
		dig=1;
		for(int x=1;x<8;x++){
			for(int y=0;y+x<8;y++){
				if(min[y]<min[y+1]){
					g = min[y];
					min[y] = min[y+1];
					min[y+1] = g;
				}
				if(max[y]>max[y+1]){
					g = max[y];
					max[y] = max[y+1];
					max[y+1] = g;
				}
			}
		}
		for(int t=0;t<8;t++){
			ans += (max[t]-min[t])*dig;
			dig*=10;
		}
		printf("%d\n",ans);
				
	}
	return 0;
}


Measured memory_bytes: 3080
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ln '\n';
int lim=1e6;
int inf=1e9+7;
vector<vector<long double> > dp;

long double solve(int i,int j,long double* p,int n)
{
    if(i==n)
    {
        if(j==0)
            return 1;
        else
            return 0;
        
    }
    
    if(dp[i][j]!=-1)
        return dp[i][j];

    long double ans1=(1-p[i])*solve(i+1,j,p,n);

    long double ans2=0;
    
    if(j>0)
        ans2=(p[i])*(solve(i+1,j-1,p,n));
        
    dp[i][j]=ans1+ans2;
    return dp[i][j];
}

int main()
{    
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int n;cin>>n;
    long double p[n];

    for(int i=0;i<n;i++)
        cin>>p[i];
    
    dp.resize(n,vector<long double>(n+1,-1));
    long double ans=0;

    for(int j=(n/2+1);j<=n;j++)
        ans+=solve(0,j,p,n);
    
    cout<<setprecision(10)<<ans<<ln;
}


Measured memory_bytes: 141440
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 n = Integer.parseInt(br.readLine());
		String[] strs = br.readLine().split(" ");
		
		int[] v1 = new int[100001];
		int[] v2 = new int[100001];
		
		for(int i = 0 ; i < v1.length ; i++){
			v1[i] = 0;
			v2[i] = 0;
		}
		
		for(int i = 0 ; i < n ; i++){
			if(i%2 == 0){
				v1[Integer.parseInt(strs[i])]++;
			}else{
				v2[Integer.parseInt(strs[i])]++;
			}
		}
		int max11 = 0;
		int max12 = 0;
		int max11id = 0;
		int max12id = 0;
		int max21 = 0;
		int max22 = 0;
		int max21id = 0;
		int max22id = 0;
		
		for(int i = 0 ; i < v1.length ; i++){
			if(v1[i] > max11){
				max12 = max11;
				max12id = max11id;
				max11 = v1[i];
				max11id = i;
			}else if(v1[i] > max12){
				max12 = v1[i];
				max12id = i;
			}
		}
		for(int i = 0 ; i < v2.length ; i++){
			if(v2[i] > max21){
				max22 = max21;
				max22id = max21id;
				max21 = v2[i];
				max21id = i;
			}else if(v2[i] > max22){
				max22 = v2[i];
				max22id = i;
			}
		}
		
		if(max11id != max21id){
			System.out.println((n - max11 - max21));
		}else{
			if((n - max11 - max22) < (n - max12 - max21)){
				System.out.println((n - max11 - max22));
			}else{
				System.out.println((n - max12 - max21));
			}
		}
	}
}


Measured memory_bytes: 37724
#include<iostream>
    using namespace std;
    int main()
    {
        int X,A;
        cin>>X;
        cin>>A;
        if(X<A)
        {
            cout<<0;
        }
     
        else
        {
            cout<<10;
        }
     
     
     
     
        return 0;
    }

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <array>
#include <queue>
#include <stack>
#include <set>
#include <utility>
using namespace std;

int main() {
  int N, C; cin >> N >> C;
  int D[30][30];
  for (int i = 0; i < C; i++) {
    for (int j = 0; j < C; j++) {
      cin >> D[i][j];
    }
  }
  int c[500][500];
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      cin >> c[i][j];
    }
  }
  int score[3][30];
  for (int i = 1; i <= C; i++) {
    for (int l = 0; l < N; l++) {
      for (int m = 0; m < N; m++) {
        if ((l + m) % 3 == 0) {
          score[0][i-1] += D[c[l][m]-1][i-1];
        } else if ((l+m) % 3 == 1) {
          score[1][i-1] += D[c[l][m]-1][i-1];
        } else {
          score[2][i-1] += D[c[l][m]-1][i-1];
        }
      }
    }
  }
  int sc = N * N * 1000;
  for (int i = 1; i <= C; i++) {
    for (int j = 1; j <= C; j++) {
      for (int k = 1; k <= C; k++) {
        if (i != j && j != k && k != i) {
          int s = score[0][i-1] + score[1][j-1] + score[2][k-1];
          if (s < sc)
            sc = s;
        }
      }
    }
  }
  cout << sc << endl;
}


Measured memory_bytes: 1280
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;

int main() {
	double sum=0,sum2=0,temp;
	int n;
	while(1) {
		cin >> n;
		if(n==0) break;
		sum=0.0;
		sum2=0.0;
		for(int i=0;i<n;++i) {
			cin >> temp;
			sum+=temp;
			sum2+=temp*temp;
		}
		cout << fixed << setprecision(8);
		cout << pow(sum2/(double)n - (sum/(double)n)*(sum/(double)n),0.5) << endl;
	}
	return 0;
}

Measured memory_bytes: 3388
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <cstdlib>
#include <queue>
#include <stack>
using namespace std;


int main(){
	map<int,int> mp;
	for(int i=0;i<4;i++){
		int x;
		cin>>x;
		mp[x]++;
	}
	if(mp[1]==1&&mp[9]==1&&mp[4]==1&&mp[7]==1){
		cout<<"YES"<<endl;
	}
	else{
		cout<<"NO"<<endl;
	}
	
	
	
	return 0;
}


Measured memory_bytes: 256
<?php
fscanf(STDIN, "%d%d%d", $N, $K, $C);
$S = (trim(fgets(STDIN)));
$rest = 10**10;
$c = 1;
for($i = 0; $i < $N; ++$i){
    if($S[$i] == "o" && $rest > $C){
        $work[$i] = $c++;
        $rest = 0;
    }else{
        $work[$i] = 0;
    }
    $rest++;
}
$rest = 10**10;
$c = $K;
for($i = $N-1; $i >= 0; --$i){
    if($S[$i] == "o" && $rest > $C){
        $work2[$i] = $c--;
        $rest = 0;
    }else{
        $work2[$i] = 0;
    }
    $rest++;
}
for($i = 0; $i < $N; ++$i){
    if($work[$i] > 0 && $work[$i] == $work2[$i])$ret[] = $i+1;
}
echo implode("\n", $ret);


Measured memory_bytes: 34416
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtTest.ABC_110
{
    class B
    {
        static void Main(string[] args)
        {
            Method(args);
        }

        static void Method(string[] args)
        {
            int[] nmxy = ReadInts();
            int n = nmxy[0];
            int m = nmxy[1];
            int x = nmxy[2];
            int y = nmxy[3];
            int[] xs = ReadInts();
            int[] ys = ReadInts();
            Array.Sort(xs);
            Array.Sort(ys);
            if (xs[n - 1] >= ys[0])
            {
                WriteLine("War");
                return;
            }

            for(int i = xs[n - 1] + 1; i <= ys[0]; i++)
            {
                if (x < i && i <= y)
                {
                    WriteLine("No War");
                    return;
                }
                else continue;
            }
            WriteLine("War");
        }

        private static string Read() { return ReadLine(); }
        private static char[] ReadChars() { return Array.ConvertAll(Read().Split(), a => a[0]); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 11220
#include<iostream>
#include<map>
#include<cmath>
//S 
using namespace std;
typedef pair<int,int> P;
int cx[30],cy[30],n,hx,hy,dx,dy;
map<P,double> mp;
bool func(int S,int now,double time){
	if(S==(1<<n)-1)
		return 1;
	for(int i=0;i<n;i++){
		if(!(S&(1<<i))){
			if(mp[P(now,i)]+time>=mp[P(i,n+1)])
			return 0;
		}
	}
	for(int i=0;i<n;i++){
		if(!(S&(1<<i))){
			double pre=mp[P(now,i)];
			double dis=mp[P(i,n+1)];
			if(pre+time<dis&&func(S|(1<<i),i,time+pre))
				return 1;
		}
	}
	return 0;
}
int main(){
	while(cin>>n>>hx>>hy>>dx>>dy,n||hx||hy||dx||dy){
		for(int i=0;i<n;i++)
			cin>>cx[i]>>cy[i];
		cx[n]=hx;
		cy[n]=hy;
		cx[n+1]=dx;
		cy[n+1]=dy;
		for(int i=0;i<=n+1;i++)
		for(int j=0;j<=n+1;j++)
		mp[P(i,j)]=sqrt((cx[i]-cx[j])*(cx[i]-cx[j])+(cy[i]-cy[j])*(cy[i]-cy[j]));
		if(func(0,n,0.0))
			cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
		mp.clear();
	}
	return 0;
}

Measured memory_bytes: 932
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	while(a>0&&c>0){
		c=c-b;
		if(c<=0){
		cout<<"Yes";
		break;
	}
		a=a-d;
		if(a<=0){
		cout<<"No";
        break;
	}
	}
	return 0;
}


Measured memory_bytes: 3636
R,G,B,N = map(int, input().split())

sum = 0
for i in range(N // R + 1):
  for j in range(N // G + 1):
    b = N - (i * R) - (j * G)
    if (b >= 0 and b % B == 0):
      sum += 1
print(sum)

Measured memory_bytes: 40812
using System;
using System.Linq;
using System.Collections.Generic;

namespace atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            ABC137.plus();
        }
    }

    class ABC137
    {
        public static void plus()
        {
            var i = Input.getIntArray();
            int[] a = {i[0] + i[1], i[0] - i[1], i[0] * i[1]};
            Console.WriteLine(a.Max());
        }
    }

  
    class Input
    {
        public static int getInt()
        {
            int i = int.Parse(Console.ReadLine());
            return i;
        }

        public static string getString()
        {
            string s = Console.ReadLine();
            return s;
        }
        public static int[] getIntArray()
        {
            string[] s = Console.ReadLine().Split(' ');
            int[] num = s.Select(x=>int.Parse(x)).ToArray();
            return num;
        }
        public static long[] getLongArray()
        {
            string[] s = Console.ReadLine().Split(' ');
            long[] num = s.Select(x=>long.Parse(x)).ToArray();
            return num;
        }
    }

    class Calc
    {
        //Greatest common divisor
        public static int Gcd(int a, int b)
        { 
            if(a<b)
            {
                return Gcd(b,a);
            }
            else
            {
                while(b != 0)
                {
                    int tmp = a%b;
                    a = b;
                    b = tmp;
                }
                return a;                
            }

        }

        //Least common multiple
        public static long Lcm(int a, int b)
        {
            return (long)(a*b/Gcd(a,b));
        }
    }
}


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

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  
  int n;
  cin >> n;
  vector<string> g(n);
  for (int i = 0; i < n; i++) {
    cin >> g[i];
  }

  vector<int> rows(n), cols(n);
  int sum = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      rows[i] += (g[i][j] == '#');
      cols[j] += (g[i][j] == '#');
      sum += (g[i][j] == '#');
    }
  }
  if (sum == 0) {
    cout << -1 << '\n';
    return 0;
  }

  int all_black_col = 0;
  for (int i = 0; i < n; i++) {
    if (cols[i] == n) all_black_col++;
  }

  int ans = 2 * n;
  for (int i = 0; i < n; i++) {
    int res = (cols[i] == 0);
    res += (n - rows[i]) + (n - all_black_col);
    ans = min(ans, res);
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 512
function Main(input) {
  "use strict";
	const lines = input.split("\n");
  const n = parseInt(lines[0], 10);
  let nums = lines[1].split(" ").map(s => parseInt(s, 10));

  let ans = 0;
  let highest = 0;
  nums.forEach( x => {
    if ( x >= highest) { ans++; highest = x;}
  })
  console.log(ans)
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 11468
#include<stdio.h>
int main()
{
	int N, rep;
	int res = 0;
	int a[N];
	scanf("%d", &N);
	
	for (rep=0; rep < N; rep++)
	{
		scanf("%d", &a[rep]);
		res = res + a[rep] - 1;
	}
	
	printf("%d", res);
	
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
//#include<string>
#include<algorithm>
using namespace std;
static const int N = 1000;

int lcs(string X,string Y){
  int c[N+1][N+1];
  int m=X.size();
  int n=Y.size();
  int maxl=0;
  X=' '+X;
  Y=' '+Y;
  for(int i=0;i<=m;i++)c[i][0]=0;
  for(int j=1;j<=n;j++)c[0][j]=0;

  for(int i=1;i<=m;i++){
    for(int j=1;j<=n;j++){
      if(X[i]==Y[j]){
        c[i][j]=c[i-1][j-1]+1;
      }else{
        c[i][j]=max(c[i-1][j],c[i][j-1]);
      }
      maxl=max(maxl,c[i][j]);
    }
  }
  return maxl;
}

int main(){
  string s1,s2;
  int n;cin>>n;
  for(int i=0;i<n;i++){
    cin>>s1>>s2;
    cout<<lcs(s1,s2)<<endl;
  }
  return 0;
}



Measured memory_bytes: 7080
// prakhsri_
#include<iostream>
#include<bits/stdc++.h>
#include<string>
#include<time.h>
using namespace std;
#define ll int
#define pb push_back
#define mp make_pair
#define fi first    
#define se second
#define mod 1000000 
void solve()
{
    ll a,b,m;
    cin>>a>>b>>m;
    vector<ll> A(a);
    vector<ll> B(b);
    ll i,j,k;
    for(i=0;i<a;i++)
        cin>>A[i];
    for(i=0;i<b;i++)
        cin>>B[i];
    ll x[m],y[m],c[m];
    for(i=0;i<m;i++)
        cin>>x[i]>>y[i]>>c[i];
    ll ans = INT_MAX;
    for(i=0;i<m;i++)
        ans = min(ans,A[x[i]-1]+B[y[i]-1]-c[i]);
    sort(A.begin(),A.end());
    sort(B.begin(),B.end());
    ans = min(ans,A[0]+B[0]);
    cout<<ans;
}
int main(){ 
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
  
    clock_t tStart = clock();
    // int t;
    // cin>>t;
    // while(t--)
       solve();
    // printf("\nTime taken: %.2fs\n", (double)(clock() - tStart)/CLOCKS_PER_SEC);
    return 0;
}       

Measured memory_bytes: 2176