akhauriyash/Code-Regression huggingface dataset:
#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;

ll N;
using CVDR = const vector<double>&;
double C(double W,CVDR vw,CVDR pf,CVDR vf,CVDR th,double pw){
    double ret = W*pw;
    for(int i = 0; i < N;i++){
        double F = (th[i] - W*vw[i])/vf[i];
        F = max(F,0.);
        ret += (F*pf[i]);
    }
    return ret;
}
double solve(){
    double res = 0;
    double pw; cin >> pw;
    vector<double> vw(N),pf(N),vf(N),th(N);
    for(int i = 0; i < N;i++) cin >> vw[i] >> pf[i] >> vf[i] >> th[i];
    double l = 0,r = 1e5;
    for(int kassa = 0; kassa < 100; kassa++){
        double xl = l + (r-l)/3.;
        double xr = l + (r-l)*2/3.;
        double lret = C(xl,vw,pf,vf,th,pw);
        double rret = C(xr,vw,pf,vf,th,pw);
        if(lret < rret){
            r = xr;
        }else{
            l = xl;
        }
    }
    res = C(l,vw,pf,vf,th,pw);
    return res;
}
int main(void){
    cin.tie(0); ios_base::sync_with_stdio(false);
    while(cin >> N,N){
        cout << fixed << setprecision(12) <<  solve() << endl;
    }
    return 0;
}



Measured memory_bytes: 6152
N, Ma, Mb = map(int, input().split())
r = Ma/Mb
a = 0
b = 0
costlist = [500000]
data = [list(map(int, input().split())) for i in range(N)]
for i in range(N):
    a += data[i][0]
    b += data[i][1]


dp = [[[500000 for i in range(N+1)] for i in range(b+10)] for i in range(a+10)]
dp[0][0][0] = 0

#Aがiグラム、Bがjグラム、k番目までの薬を用いたときの最小コスト
for k in range(N):
    for j in range(b):
        for i in range(a):
            ai = data[k][0]
            bj = data[k][1]
            dp[i+ai][j+bj][k+1] = min(dp[i+ai][j+bj][k+1], dp[i][j][k] + data[k][2])
            dp[i][j][k+1] = min(dp[i][j][k], dp[i][j][k+1])

for i in range(1, a):
    for j in range(1, b):
        if i/j == r:
            costlist.append(dp[i][j][N])
if N == 1:
    if data[0][0]/data[0][1] == r:
        print(data[0][2])
    else:
        print(-1)

elif min(costlist) == 500000:
    print(-1)
else:
    print(min(costlist))


Measured memory_bytes: 73436
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rem(i, m, n) for (int i = m; i < (n); i++)
#define eps (1e-7)
#define inf (1e9)
#define pi (acos(-1))
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<double> vd;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

    int n;
    cin >> n;
    vi a(n);
    rep(i, n) cin >> a[i];
    ll sum = 0;
    rep(i, n) sum += a[i] - 1;
    cout << sum << "\n";
    // int mina = a[0];
    // int maxa = a[0];
    // rep(i, n)
    // {
    //     mina = min(mina, a[i]);
    //     maxa = max(maxa, a[i]);
    // }
    // int index = 0;
    // ll maxsum = 0;
    // rem(i, maxa, 1e5 + 1)
    // {
    //     ll sum = 0;
    //     for (const auto &e : a)
    //     {
    //         sum += (i % e);
    //     }
    //     cout << "i : " << i << "\n";
    //     cout << "sum : " << sum << "\n";
    //     if (sum > maxsum)
    //         index = i;
    //     maxsum = max(sum, maxsum);
    // }
    // cout << maxsum << "\n";
    // cout << index << "\n";
    return 0;
}

Measured memory_bytes: 256
#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++)
using namespace std;
using P = pair<int, int>; 
using ll = long long;
 
int main()
{
  int a, b;
  cin >> a >> b;
  cout << (a+b) % 24 << endl;
  return 0;
}


Measured memory_bytes: 3548
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		String s = sc.next();
		int a = Integer.parseInt(s.substring(0, 2));
		int b = Integer.parseInt(s.substring(2, 4));
		if (a <= 12 && b <= 12 && a > 0 && b > 0) {
			sb.append("AMBIGUOUS");
		} else if (a <= 12 && a > 0) {
			sb.append("MMYY");
		} else if (b <= 12 && b > 0) {
			sb.append("YYMM");
		} else {
			sb.append("NA");
		}
		System.out.println(sb);
	}
}


Measured memory_bytes: 22100
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <math.h>
#include <limits.h>

int main(void){
    int n,i;
    scanf("%d%d",&n,&i);
    printf("%d\n",n-i+1);
	return 0 ;
}

Measured memory_bytes: 128
#include <stdio.h>

int main()
{
    int n;
    scanf("%d", &n);
    char s[n+1];
    scanf("%s", s);
    int i, j, k;
    int max = 0;
    for(i=0;i<n-1;i++){
        int count = 0;
        for(j='a';j<='z';j++){
            int judge_a = 0;
            int judge_b = 0;
            for(k=0;k<=i;k++) if((int)s[k]==j) judge_a = 1;
            for(k=i+1;k<n;k++) if((int)s[k]==j) judge_b = 1;
            if(judge_a==1&&judge_b==1) count += 1;
        }
        if(max<count) max = count;
    }
    printf("%d", max);
    
    return 0;
}

Measured memory_bytes: 128
A, B = map(int, input().split())

count = 0

for i in range(A, B+1):
    check = 0
    str_i = str(i)
    for j in range(0, (len(str_i)//2)+1):
        if int(str_i[j]) != int(str_i[-1-j]):
            check += 1
    if check == 0:
        count += 1

print("{}".format(count))

Measured memory_bytes: 9124
from collections import Counter
n = int(input())
s = list(map(int,input().split()))
c = Counter(s)
ls = c.most_common()
di = [0]*(max(s))
dis = [0]*(max(s))
def combinations_count(n, r): #組み合わせ(nCr)
    import math
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

for i in range(len(ls)):
    if ls[i][1] > 2:
        di[ls[i][0]-1] = combinations_count(ls[i][1], 2)
        dis[ls[i][0]-1] = combinations_count(ls[i][1]-1, 2)
    elif ls[i][1] == 2:
        di[ls[i][0]-1] = combinations_count(ls[i][1], 2)
mx = sum(di)
for j in range(n):
    a = s[j]
    if di[a-1] != 0:
        print(mx-di[a-1]+dis[a-1])
    else:
        print(mx)


Measured memory_bytes: 122956
#include<stdio.h>

int main(void)
{
	int x1, x2, x3, x4, x5;
	scanf("%d %d %d %d %d", &x1, &x2, &x3, &x4, &x5);
	printf("%d\n", 15 - x1 - x2 - x3 - x4 - x5);

	return 0;
}

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

using namespace std;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t,ac=0,wa=0,tle=0,re=0;
    cin >> t;
    while(t--){
        string s;
        cin >> s;
        if(s=="AC")
            ac+=1;
        if(s=="WA")
            wa+=1;
        if(s=="TLE")
            tle+=1;
        if(s=="RE")
            re+=1;
    }

    cout << "AC x " << ac << endl;
    cout << "WA x " << wa << endl;
    cout << "TLE x " << tle << endl;
    cout << "RE x " << re << endl;
    return 0;
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
int main(){
  int w,h,n,x,y,z,j,x1=0,x2,y1=0,y2;
  cin>>w>>h>>n;
  x2=w;
  y2=h;
  for(j=0;j<n;j++){
    cin>>x>>y>>z;
    if(z==1) x1=max(x1,x);
    else if(z==2) x2=min(x2,x);
    else if(z==3) y1=max(y1,y);
    else if(z==4) y2=min(y2,y);
  }
  if(x1<x2&&y1<y2) cout<<(x2-x1)*(y2-y1)<<endl;
  else cout<<0<<endl;
}

Measured memory_bytes: 3612
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <utility>
#include <iomanip>

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

using namespace std;

typedef pair<int, int> P;

const int INF = 1e15;
const int MOD = 1e9+7;

void solve(int h){
    vector<vector<int>> a(h, vector<int>(5));
    for(int i = h-1; i >= 0; i--){
        rep(j, 5){
            cin >> a[i][j];
        }
    }

    bool able = true;

    int ans = 0;
    while(able){
        able = false;

        vector<vector<bool>> del(h, vector<bool>(5, false));

        rep(i, h){
            rep(j, 3){
                if(a[i][j] == 0){
                    continue;
                }

                if(a[i][j] == a[i][j+1] && a[i][j] == a[i][j+2]){
                    able = true;
                    del[i][j] = true;
                    del[i][j+1] = true;
                    del[i][j+2] = true;
                }
            }
        }

        rep(i, h){
            rep(j, 5){
                if(del[i][j]){
                    ans += a[i][j];
                    a[i][j] = 0;
                }
            }
        }

        for(int i = 1; i < h; i++){
            rep(j, 5){
                int ni = i-1;
                while(ni >= 0 && a[ni][j] == 0){
                    a[ni][j] = a[ni+1][j];
                    a[ni+1][j] = 0;
                    ni--;
                }
            }
        }
    }
    cout << ans << endl;
}

signed main(){
    while(true){
        int h;
        cin >> h;

        if(h == 0){
            break;
        }

        solve(h);
    }

    return 0;
}



Measured memory_bytes: 3120
from functools import reduce


n = int(input())
A = list(map(int, input().split()))
if n == 1:
    print(A[0])
else:
    numerator = reduce(lambda a, b: a * b, A)
    denominator = 0
    for i in range(n):
        denominator += reduce(lambda a, b: a * b, A[:i] + A[i+1:])
    print(1.0 * numerator / denominator)


Measured memory_bytes: 3572
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    n,K=map(int,input().split())
    dp=[[[0]*2700 for _ in range(55)] for _ in range(55)]
    dp[0][0][0]=1
    for i in range(n):
        for j in range(i+1):
            for k in range(K+1):
                dp[i+1][j][k+2*j]+=(2*j+1)*dp[i][j][k]
                dp[i+1][j][k+2*j]%=MOD
                dp[i+1][j+1][k+2*(j+1)]+=dp[i][j][k]
                dp[i+1][j+1][k+2*(j+1)]%=MOD
                if(j):
                    dp[i+1][j-1][k+2*(j-1)]+=j*j*dp[i][j][k]
                    dp[i+1][j-1][k+2*(j-1)]%=MOD
    print(dp[n][0][K])
resolve()

Measured memory_bytes: 104668
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
    int n,k;
    cin>>n>>k;
    string s;
    cin>>s;
    if(s[k-1]=='A')
    s[k-1]='a';
    else if(s[k-1]=='B')
    s[k-1]='b';
    else
    s[k-1]='c';
    cout<<s;
    return 0;
}


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

int main() {

    int k, n;

    cin >> k >> n;

    vector<int> house(n);

    int maxDistance = -1;
    int index = -1;

    for(int i = 0; i < n; ++i) {
        cin >> house[i];

        if(i == 0)
            continue;

        if(house[i] - house[i - 1] > maxDistance) {
            index = i;
            maxDistance = house[i] - house[i - 1];
        }

    }

    if(house[0] + (k - house[n - 1]) > maxDistance) {
        index = 0;
        maxDistance = house[0] + (k - house[n - 1]);
    }

    cout << k - maxDistance << endl;

    return 0;


}

Measured memory_bytes: 1024
#include <cstdio>
#include <cmath>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <cstdlib>
using namespace std;
typedef long long LL;
 
int main() {
	int a, b;
	scanf("%d %d", &a, &b);
	int c = (a + b) / 2;
	if(a % 2 == 0 && b % 2 == 0) printf("%d\n", c);
	else if(a % 2 != 0 && b % 2 != 0) printf("%d\n", c);
	else printf("%d\n", c + 1);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<ll> vll;
typedef vector<vector<int>> vvi;
typedef vector<vector<string>> vvs;
typedef vector<vector<char>> vvc;
typedef vector<vector<bool>> vvb;
typedef pair<int,int> P;
typedef pair<ll, ll> Pll;
#define vrep(v,n) for(int i=0;i<n;i++){cin >> v.at(i);} 
#define rep(i, l, n) for (int i = l; i < (int)(n); i++)
#define repn(i, l, n) for (int i = l; i <= (int)(n); i++)
#define pb push_back 
void chmin(int &a, int b) {if(a > b) a = b;}
void chmax(int &a, int b) {if(a < b) a = b;}

const int mod = 1000000007;
const int inf = 1e9;
#define PI 3.14159265369;
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};


int main(){
    int q;
    cin >> q;
    int prime[100004];
    prime[0] = 0;
    for(int i = 1 ; i <= 100000 ; i++){
        if(i == 1){
            prime[i] = 0;
        }else if(i == 2){
            prime[i] = 1;
        }else if(i % 2 == 0){
            prime[i] = prime[i-1];
        }else{
            bool flag = false;
            for(int j = 3 ; j*j<=i ; j++){
                if(i%j == 0){
                    prime[i] = prime[i-1];
                    flag = true;
                    break;
                }
            }
            if(flag) continue;
            prime[i] = prime[i - 1] + 1;
        }
    }
    int like[100005];
    for(int i = 1 ; i <= 100000 ; i++){
        if(i%2==0){like[i] = like[i-1];}
        else if(prime[i]-prime[i-1] == 1 && prime[(i+1)/2]-prime[(i-1)/2] == 1){
            like[i] = like[i-1] + 1;
        }else{like[i] = like[i-1];}
    }
    rep(i,0,q){
        int a,b;
        cin >> a >> b;
        cout << like[b] - like[a-1] << endl;;
    }
}

Measured memory_bytes: 1408
#include<stdio.h>
int MIN(int a,int b){return a<b?a:b;}
int ta[100010],to[100010],co[100010],nt[100010],it[100010],l[100010];
void mklsb(int v,int e,int *a,int *b,int *c){
  int i;
  for(i=0;i<v;i++)ta[i]=-1;
  for(i=0;i<e;i++){
    nt[i  ]=ta[to[i+e]=a[i]];
    nt[i+e]=ta[to[i  ]=b[i]];
    co[ta[a[i]]=i  ]=c[i];      
    co[ta[b[i]]=i+e]=0;
  }
}
int MF(int e,int s,int t,int min){
  if(s==t)return min;
  int i,r;
  for(;it[s]+1;it[s]=nt[it[s]]){
    if(co[it[s]]==0||l[s]>=l[to[it[s]]])continue;
    r=MF(e,to[it[s]],t,MIN(min,co[it[s]]));
    co[it[s]]-=r;
    co[(it[s]+e)%(2*e)]+=r;
    if(r)return r;
  }
  return 0;
}
int maxf(int v,int e,int s,int g){
  int i,a=0,q[100010],t,r,c=3;
  while(1){
    q[0]=s;
    for(i=t=0;i<v;i++)l[i]=-1;
    l[q[0]]=0;
    for(r=1;r-t;t++){
      for(i=ta[q[t]];i+1;i=nt[i]){
	if(co[i]==0||l[to[i]]+1)continue;
	l[to[i]]=l[q[t]]+1;
	q[r++]=to[i];
      }
    }
    if(l[g]<0)return a;
    for(i=0;i<v;i++)it[i]=ta[i];
    while(r=MF(e,s,g,1e9))a+=r;
  }
  return a;
}
int main(){
  int n,m,i,a[100010],b[100010],c[1000010],m1,m2;
  scanf("%d %d",&n,&m);
  for(i=0;i<m;i++)scanf("%d %d %d",&a[i],&b[i],&c[i]);
  mklsb(n,m,a,b,c);//prls(n);
  m1=maxf (n,m,0,n-1);
  printf("%d\n",m1);
  return 0;
}

Measured memory_bytes: 2700
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <deque>
#include <list>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>

using namespace std;


#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int (i)=(n); (i)>=(0); (i)--)
#define SIZE(x) ((int)(x).size())
#define GCD(a, b) int gcd(int a,int b){return b?gcd(b,a%b):a;}
#define QP(a, b) int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define all(v) (v).begin(),(v).end()


template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
template<typename A, size_t N, typename T>
void FILL(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

typedef vector<int, int> vint;
typedef pair<int,int> pint;
typedef vector<pint>vpint;
typedef long long ll;

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1LL << 60;
const ll MOD = 1000000007LL;


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a[3];
    rep(i, 3) cin >> a[i];
    sort(a, a+3);
    cout << a[2] - a[0];
    cout << endl;
    return 0;
}




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

#define debug(x) cout << #x << " = " << x << endl
#define fori(i, ini, lim) for(int i = int(ini); i < int(lim); i++)
#define ford(i, ini, lim) for(int i = int(ini); i >= int(lim); i--)

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;

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

	int cnt[2] = {0};
	int n;
	cin >> n;
	fori(i, 1, n + 1) {
		int cur;
		cin >> cur;
		cnt[cur & 1]++;
	}

	while(cnt[0] >= 2 || cnt[1] >= 2) {
		if(cnt[0] >= 2) {
			cnt[0]--;
		}
		else {
			cnt[1] -= 2;
			cnt[0]++;
		}
	}

	if(cnt[0] + cnt[1] == 1) {
		cout << "YES" << '\n';
	}
	else {
		cout << "NO" << '\n';
	}

	return 0;
}



Measured memory_bytes: 256
from operator import mul
from functools import reduce

n, m, c = list(map(int, input().split(" ")))
bs = list(map(int, input().split(" ")))
a_nm = []
for _ in range(n):
    a_m = list(map(int, input().split(" ")))
    a_nm.append(a_m)

ans = 0
tested = [sum([a * b for a, b in zip(a_nm[i], bs)]) + c for i in range(n)]
passed = list(filter(lambda x: x > 0, tested))
print(len(passed))


Measured memory_bytes: 3700
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

const int mod = 1000000007, mod2 = 998244353, inf = 0x3f3f3f3f;
const int maxn = 1e6 + 5;
int cnt[1005], a[10005];
int main()
{
//    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) cin >> a[i];
    int ans = 0;
    for (int i = 0, j; i < n; ++i){
        for (j = i; j >= 0; --j){
            if (a[j] > a[i]) break;
            if (j == 0) ++ans;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;

public class Main {
	final int _intMax = Integer.MAX_VALUE; //=2147483647>10^9
	final int _intMin = Integer.MIN_VALUE;
	final long _longMax = Long.MAX_VALUE; //=9223372036854775807L>10^18
	final long _longMin = Long.MIN_VALUE;
	static boolean bElapsed = false;

	void solve() {
		int[] ia = readNums();
		long x = ia[0];
		long y = ia[1];
		if (x == y) {
			pln("0");
			return;
		}
		if (x == 0) {
			if (y > 0) {
				pln(y);
				return;
			} else {
				pln(-y+1);
				return;
			}
		}
		if (y == 0) {
			if (x > 0) {
				pln(x+1);
				return;
			} else {
				pln(-x);
				return;
			}
		}
		long sx = x >= 0 ? 1 : -1;
		long sy = y >= 0 ? 1 : -1;
		if (sx == sy) {
			if (y == 0) {
				pln(x+1);
			} else if (x <= y) {
				pln(y-x);
			} else {
				pln(x-y+2);
			}
		} else if (sx < 0) {
			x = -x;
			if (x == y) {
				pln("1");
			} else if (y == 0) {
				pln(x);
			} else if (x < y) {
				pln(y-x+1);
			} else {
				pln(x-y+1);
			}
		} else if (sy < 0) {
			y = -y;
			if (x == y) {
				pln("1");
			} else if (x == 0) {
				pln(y);
			} else if (x < y) {
				pln(y-x+1);
			} else {
				pln(x-y+1);
			}
		}
	}

	long ceil2pow(long n) {
		if (n == 0) return 1;
		n--;
		n |= (n >>> 1);
		n |= (n >>> 2);
		n |= (n >>> 4);
		n |= (n >>> 8);
		n |= (n >>> 16);
		n++;
		return n;
		/*
		long pow = 1;
		while (pow < n) pow <<= 1;
		return pow;
		*/
	}
	int gcd(int a, int b) {
		if (a < b) return gcd(b, a);
		if (b == 0) return a;
		return gcd(b, a % b);
	}
	long sqrt(long n) {
		return (long)Math.sqrt(n);
	}
	long pow(long n, long p) {
		return (long)Math.pow(n, p);
	}
	long pow_mod(long n, long p, long m) {
		if (p == 0) return 1;
		else if (p % 2 == 1) return pow_mod(n, p-1, m) * n % m;
		long sum = pow_mod(n, p/2, m);
		return sum * sum % m;
	}
	int pint(String s) {
		return Integer.parseInt(s);
	}
	long plong(String s) {
		return Long.parseLong(s);
	}
	String readLine() {
		try {
			return _in.readLine();
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
	}
	int readNum() {
		String line = readLine();
		return pint(line);
	}
	String[] readFlds() {
		String line = readLine();
		return line.split(" ");
	}
	int[] readNums() {
		String[] flds = readFlds();
		int[] nums = new int[flds.length];
		for (int i=0; i<flds.length; i++) {
			nums[i] = pint(flds[i]);
		}
		return nums;
	}
	void p(char c) {
		_out.print(c);
	}
	void pln(char c) {
		_out.println(c);
	}
	void p(double d) {
		_out.print(d);
	}
	void pln(double d) {
		_out.println(d);
	}
	void p(long l) {
		_out.print(l);
	}
	void pln(long l) {
		_out.println(l);
	}
	void p(String s) {
		_out.print(s);
	}
	void pln(String s) {
		_out.println(s);
	}
	static BufferedReader _in;
	static PrintWriter _out;
	public static void main(String[] args) {
		long start = System.currentTimeMillis();
		_in = new BufferedReader(new InputStreamReader(System.in));
		_out = new PrintWriter(System.out);
		new Main().solve();
		_out.flush();
		long end = System.currentTimeMillis();
		if (bElapsed) {
			System.err.println((end-start) + "ms");
		}
	}
}


Measured memory_bytes: 8276
#include <bits/stdc++.h>
using namespace std; 
int main(){
	int A, B, C; 
	cin >> A >> B >> C; 
	if(A == B && B == C && A % 2 == 0) cout << -1 << endl; 
	else{
		int count = 0; 
	for(int q = 0; q < 114514; q++){
		if(A % 2 || B % 2 || C % 2){
			cout << count << endl; 
			break; 
		}
		else{
			int d = (B+C)/2; int e = (C+A)/2; int f = (A+B)/2; 
			A = d; B = e; C = f; count ++; 
		}
	}
    }
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int a,b,x;
    scanf("%d %d %d",&x,&a,&b);
    if(b - a <= 0)
    {
        printf("delicious");
    }
    else if(b - a <= x)
    {
        printf("safe");
    }
    else
    {
        printf("dangerous");
    }
}


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

int main() {
  string ss,t,ans = "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz";
  cin >> ss >> t;
  if(ss.size() < t.size()){
    cout << "UNRESTORABLE" << endl;
    return 0;
  }
  for(int i = 0;i < ss.size()-t.size()+1;i++){
    string s = ss;
    for(int j = 0;j < t.size();j++){
      if(s[i+j] != '?' && s[i+j] != t[j]){
        break;
      }
      if(j == t.size()-1){
        s.replace(i,t.size(),t);
        for(int k = 0;k < s.size();k++){
          if(s[k] == '?') s[k] = 'a';
        }
        if(s < ans) ans = s;
      }
    }
  }
  if(ans != "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz"){
    cout << ans << endl;
    return 0;
  }
  cout << "UNRESTORABLE" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <climits>
#include <queue>

using namespace std;
int N, M, K, x0, x1, y0, y1;
vector<set<int>> rows, cols;
vector<set<int>> lotusR, lotusC;

pair<int,int> getRange(set<int> &st, int y, int Bound) {
        set<int>::iterator sec = st.upper_bound(y);
        int lo = y - K - 1, hi = y + K + 1;
        if (sec != st.end()) {
            hi = min((*(sec)), hi);
        }
        if (sec != st.begin()) {
            --sec;
            lo = max((*(sec)), lo);
        }
        return {lo, hi};
}


int bfs(vector<set<int>> &rows, vector<set<int>> &cols, vector<set<int>> &lotusR, vector<set<int>> &lotusC) {
    vector<vector<int>> D(N, vector<int>(M, INT_MAX));
    queue<pair<int, int>> Q;
    Q.push({x0, y0});
    D[x0][y0] = 0;
    rows[x0].erase(y0);
    cols[y0].erase(x0);
    while (!Q.empty()) {
        auto firstEle = Q.front();
        Q.pop();
        vector<int> toBeRem;
        auto row = getRange(lotusR[firstEle.first], firstEle.second, M);
        for (auto it = rows[firstEle.first].upper_bound(row.first);
                        it != rows[firstEle.first].end() && (*it) < row.second;
                        ++it) {
            D[firstEle.first][(*it)] = D[firstEle.first][firstEle.second] + 1;
            Q.push({firstEle.first, (*it)});
            toBeRem.push_back(*it);
        }
        for (int ele: toBeRem) {
            rows[firstEle.first].erase(ele);
            cols[ele].erase(firstEle.first);
        }
        toBeRem.clear();

        auto col = getRange(lotusC[firstEle.second], firstEle.first, N);
        for (auto it = cols[firstEle.second].upper_bound(col.first);
                        it != cols[firstEle.second].end() && (*it) < col.second;
                        ++it) {

            D[(*it)][firstEle.second] = D[firstEle.first][firstEle.second] + 1;
            Q.push({(*it), firstEle.second});
            toBeRem.push_back(*it);
        }
        for (int ele: toBeRem) {
            rows[ele].erase(firstEle.second);
            cols[firstEle.second].erase(ele);
        }
    }
    return D[x1][y1] == INT_MAX ? -1 : D[x1][y1];
}

int main() {
    ios::sync_with_stdio(false);cin.tie(0);
    cin >> N >> M >> K >> x0 >> y0 >> x1 >> y1;
    --x0;--y0;--x1;--y1;
    rows.resize(N);
    cols.resize(M);
    lotusR.resize(N);
    lotusC.resize(M);
    for (int i = 0; i < N; ++i) {
        string A;
        cin >> A;
        for (int j = 0; j < M; ++j) {
            if (A[j] == '.') {
                rows[i].insert(j);
                cols[j].insert(i);
            } else {
                lotusR[i].insert(j);
                lotusC[j].insert(i);
            }
        }
    }
    cout << bfs(rows, cols, lotusR, lotusC);

    return 0;
}


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

int main() 
{
  char c;
  cin >> c;
  
  if(c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o')
  {
    cout << "vowel" << endl;
  }
  else
  {
    cout << "consonant" << endl;
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using V = vector<int>;
using VV = vector<vector<int>>;
using VVV = vector<vector<vector<int>>>;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using VVVL = vector<vector<vector<ll>>>;
using pq = priority_queue<int>;
template<class T>
using P = pair<T, T>;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define REP(i,k,n) for(int i=(k);i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define output(x,y) cout << fixed << setprecision(y) << x << endl;
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 gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
int under = (1 << 31);
int upper = under - 1;
ll UNDER = (1LL << 63);
ll UPPER = UNDER - 1;
const int MOD = 1e9 + 7;
const long double pi = 3.141592653589793;
int main() {
	int n, h;
	cin >> n >> h;
	V a(n);
	V b(n);
	rep(i, n) {
		cin >> a[i] >> b[i];
	}
	int ans = 0;
	int s = *max_element(all(a));
	sort(all(b), greater<int>());
	rep(i, n) {
		if (s < b[i] && h > 0) ans++, h -= b[i];
	}
	if (h > 0) ans += (h + s - 1) / s;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
 
using ll = long long;
using pll = pair<ll, ll>;
#define all(x) (x).begin(), (x).end()
#define call(x) (x).cbegin(), (x).cend()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define sz(x) ((x).size())
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define rep(i, a, b) for(ll i = ll(a); i < ll(b); i++)
const double PI = acos(-1);
const int mod = 1e9+7;
const long long INF = (1LL << 60);
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a / gcd(a,b) * b;}
ll stringcount(string s, char c){return count(s.cbegin(), s.cend(), c);}
bool isInteger(double x){return floor(x) == x;}
ll ceil(ll a, ll b){return ((a)+(b)-1)/b;}
template<class T> inline bool chmax(T &a, const T &b){ if(a < b){ a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b){ if(a > b){ a=b; return 1; } return 0; }



int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  
  ll n, m;
  cin >> n >> m;
  vector<pll> ab(n);
  rep(i, 0, n){
    cin >> ab[i].first >> ab[i].second;
  }
  sort(all(ab));

  ll ans = 0;
  rep(i, 0, n){
    if(m <= ab[i].second){
      ans += ab[i].first * m;
      break;
    }else{
      ans += ab[i].first * ab[i].second;
      m -= ab[i].second;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 4688
#include <algorithm>
#include <iostream>
#include <map>
#include <set>
#include <vector>
using namespace std;

int main() {
    long long  N, A, B;
    cin >> N >> A >> B;
    long long ring = A + B;
    long long  num = N / ring;
    long long diff = N - ring * num;
    if (diff > A)
        diff = A;
    long long ans = A * num + diff;
    cout << ans << "\n";
    return 0;
}


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

int main(){

    int s, n, ans = 0;

    cin >> s >> n;
    long long w[s + 5], v[s + 5];
    for(int i = 1; i <= s; i++) cin >> w[i] >> v[i];
    long long dp[s + 5][n + 5];
    memset(dp, 0, sizeof(dp));
    for(int i = 1; i <= s; i++){
        for(int j = 0; j <= n; j++){
            dp[i][j] = dp[i - 1][j];
            if(w[i] <= j) dp[i][j] = max(dp[i][j], v[i] + dp[i - 1][j - w[i]]);
        }
    }
    cout << dp[s][n] << endl;

    return 0;
}


Measured memory_bytes: 82304
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, a, b) for(int i = a; i <= b; i++)
#define all(x) x.begin(), x.end()
#define fi first
#define se second
#define debug(...) cerr<<__LINE__<<" ["<<#__VA_ARGS__<<"]:",debug_out(__VA_ARGS__)
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec)
    { for (auto v : vec) os << v << ' '; os << '\n'; return os; }
template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa)
    { os << '(' << pa.first << ',' << pa.second << ')'; return os; }
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T)
    { cerr << " " << H; debug_out(T...); }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

int dp[3030][6060];

void solve() {
    int n, T;
    cin >> n >> T;
    vector<pii> A(n);
    rep(i, n) {
        int a, b;
        cin >> a >> b;
        A[i] = {a, b};
    }
    sort(all(A));
    rep(i, n) rep(t, T) {
        chmax(dp[i + 1][A[i].fi + t], dp[i][t] + A[i].se);
        chmax(dp[i + 1][t], dp[i][t]);
    }
    int ans = 0;
    rep(i, n + 1) chmax(ans, *max_element(dp[i], dp[i] + 6060));
    cout << ans << endl;
}

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


Measured memory_bytes: 65256
while True:
    H,W = map(int,input().split())
    if H == 0 and W == 0:
        break
    for i in range(H):
        for j in range(W):
            if (i + j) % 2 == 0:
                print("#", end = "")
            else:
                print(".", end = "")
        print()
    print()


Measured memory_bytes: 7004
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> V;
const long long MOD=1000000007LL;
const long long INFL=1LL << 60;
const int INF=1<<29;


int main() {
    int R,G,B,N;
    cin >>R>>G>>B>>N;
    int cnt=0;
    for(int i=0;i<=N/R;i++){
        for(int j=0;j<=(N-i*R)/G;j++){
            if((N-i*R-j*G)%B==0) cnt++;
        }
    }
    cout<<cnt<<endl;

    return 0;
}

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

int H, W;
vector<vector<char>> A;

int Bfs() {
  vector<vector<bool>> flag(H, vector<bool>(W));
  queue<pair<int, int>> q;
  for (int i = 0; i < H; ++i) {
    for (int j = 0; j < W; ++j) {
      if (A[i][j] == '#') {
        q.push({i, j});
        flag[i][j] = true;
      }
    }
  }

  if (q.size() == H * W)
    return 0;

  int res = -1;
  queue<pair<int, int>> nq;
  while (!q.empty()) {
    int i = q.front().first, j = q.front().second;
    q.pop();

    int di[4] = {1, 0, -1, 0}, dj[4] = {0, 1, 0, -1};
    for (int n = 0; n < 4; ++n) {
      int ni = i + di[n], nj = j + dj[n];

      if (ni < 0 || ni >= H || nj < 0 || nj >= W)
        continue;
      if (flag[ni][nj])
        continue;

      nq.push({ni, nj});
      A[ni][nj] = '#';
      flag[ni][nj] = true;
    }

    if (q.empty()) {
      ++res;
      q = nq;
      while (!nq.empty())
        nq.pop();
    }
  }

  return res;
}

int main() {
  cin >> H >> W;
  A.resize(H, vector<char>(W));
  for (int i = 0; i < H; ++i)
    for (int j = 0; j < W; ++j)
      cin >> A[i][j];

  int ans = Bfs();

  cout << ans << endl;
}

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

int N;
vector<int> A;
vector<int> G;

// 昇順ソート
void insertionSort(vector<int>& A, int n, int g, int& cnt) {
	for (int i = g; i < n; i++) {
		int v = A[i]; // iの示す値を取り出す
		int j = i - g; // とっかえ対象はgだけ離れる

		while (j >= 0 && A[j] > v) { // jの示す値A[j]がiの示す値よりも大きい
			A[j + g] = A[j]; // 押出し
			j = j - g; // またg間隔移動する
			cnt++;
		}

		A[j + g] = v; // 取り出していた値を現在のi位置に戻す
	}
}

int shellSort(vector<int>& A, int n) {
	int cnt = 0;

	// シェルソート間隔数列Gの生成
	for (int h = 1; ;) {
		if (h > n) break;// 要素数分より一段階多く確保する
		G.push_back(h);
		h = 3 * h + 1;
	}

	// 大きい順に使う
	for (int i = G.size() - 1; i >= 0; i--) {
		insertionSort(A, n, G[i], cnt);
	}

	return cnt;
}

int main() {
	int cnt;
	cin >> N;
	A.resize(N);
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}


	cnt = shellSort(A, N);

	cout << G.size() << endl;
	for (int i = G.size() - 1; i >= 0; i--) {
		cout << G[i];
		if (i != 0) cout << " ";
	}
	cout << endl;
	cout << cnt << endl;

	for (int i = 0; i < N; i++) {
		cout << A[i] << endl;
	}

	return 0;
}


Measured memory_bytes: 6772
#include <bits/stdc++.h>
typedef long long lint;
using namespace std;

struct loop {
    lint loop_len;
    lint prefix_len;
};

lint n, k;
vector<int> a;

int f(int p) {
    return a[p];
}

int simple_solve(int start, int m) {
    int now = start;
    for (int i = 0; i < m; i++) {
        now = f(now);
    }
    return now;
}

loop get_loop() {
    int now = 0;
    int time = 0;
    vector<int> appear_time(n, -1);
    while (true) {
        if (appear_time[now] == -1) {
            appear_time[now] = time;
            time++;
            now = f(now);
        } else {
            loop res;
            res.prefix_len = appear_time[now];
            res.loop_len = time - res.prefix_len;
            return res;
        }
    }
}

int main() {
    cin >> n >> k;
    a.resize(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        a[i]--;
    }
    auto lp = get_loop();
    if (k < lp.prefix_len) {
        cout << simple_solve(0, k) + 1 << endl;
    } else {
        lint loop_num = (k - lp.prefix_len) / lp.loop_len;
        lint essential = k - loop_num * lp.loop_len;
        cout << simple_solve(0, essential) + 1 << endl;
    }
}

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

#define int long long

#define rep(i, n) for (int i = 0; i < (n); i++)
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(), (v).end()
#define fi first
#define se second

using vint = vector<int>;
using pint = pair<int, int>;
using vpint = vector<pint>;

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

template <class A, class B>
ostream& operator<<(ostream& ost, const pair<A, B>& p) {
    ost << "{" << p.first << "," << p.second << "}";
    return ost;
}

template <class T>
ostream& operator<<(ostream& ost, const vector<T>& v) {
    ost << "{";
    for (int i = 0; i < v.size(); i++) {
        if (i) ost << ",";
        ost << v[i];
    }
    ost << "}";
    return ost;
}

inline int topbit(unsigned long long x) {
    return x ? 63 - __builtin_clzll(x) : -1;
}

inline int popcount(unsigned long long x) {
    return __builtin_popcountll(x);
}

inline int parity(unsigned long long x) {
    return __builtin_parity(x);
}

signed main() {
    string S;
    cin >> S;
    int sum = 0;
    for (auto c : S) sum += c - '0';
    if (sum % 9)
        cout << "No" << endl;
    else
        cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 3756
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#define LL long long
using namespace std;
const int N = 5010;
LL sum[N], a[N];
int p[N];
int main()
{
	int n;
	LL k;
	cin>>n>>k;
	for(int i = 1; i <= n; i++)
		scanf("%d", &p[i]);
	for(int i = 1; i <= n; i++)
		cin>>a[i];
	LL ans = -1e18 - 1;
	for(int i = 1;i <= n; i++)
	{
		int x = p[i];
		LL cnt = 1;
		int flag = 0;
		while(x != i)
		{
			sum[cnt] = sum[cnt - 1] + a[x];
			x = p[x];
			cnt++;
		}
		sum[cnt] = sum[cnt - 1] + a[i];
		//for(int j = 1; j <= cnt; j++)
		//	cout<< sum[j] << " ";
		//cout<<endl; 
		for(int j = 1; j <= min(k, cnt); j++)
		{
			LL nk = k - j;
			if(sum[cnt] >= 0)
				ans = max(ans, sum[cnt] * (nk / cnt) + sum[j]);
			else
				ans = max(ans, sum[j]);
		}
	}
	cout<<ans<<endl;
	return 0;
 } 

Measured memory_bytes: 3864
/*
AuThOr Gwj
*/
#include<bits/stdc++.h>
#define rb(a,b,c) for(int a=b;a<=c;++a)
#define rl(a,b,c) for(int a=b;a>=c;--a)
#define LL unsigned long long
#define IT iterator
#define PB push_back
#define II(a,b) make_pair(a,b)
#define FIR first
#define SEC second
#define FREO freopen("check.out","w",stdout)
#define rep(a,b) for(int a=0;a<b;++a)
#define KEEP while(1)
#define SRAND mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define random(a) rng()%a
#define ALL(a) a.begin(),a.end()
#define POB pop_back
#define ff fflush(stdout)
#define fastio ios::sync_with_stdio(false)
#define debug_pair(A) cerr<<A.FIR<<" "<<A.SEC<<endl;
using namespace std;
const int INF=0x3f3f3f3f;
typedef pair<int,int> mp;
typedef pair<mp,mp> superpair;
int t;
LL N,A,B,C,D;
map<LL,LL> M;
LL calc(LL now){
	if(M[now]) return M[now];
	if(now==0) return 0;
	if(now==1) return D;
	LL res=now*D;
	LL tmp=now,tmp2=0;
	while(tmp%2!=0){
		tmp++;
		tmp2+=D;
	}
	res=min(res,calc(tmp/2)+A+tmp2);
	tmp2=0;
	tmp=now;
	while(tmp%2!=0){
		tmp--;
		tmp2+=D;
	}
	res=min(res,calc(tmp/2)+A+tmp2);
	tmp=now;
	tmp2=0;
	while(tmp%3!=0){
		tmp--;
		tmp2+=D;
	}
	res=min(res,calc(tmp/3)+B+tmp2);
	tmp=now;
	tmp2=0;
	while(tmp%3!=0){
		tmp++;
		tmp2+=D;
	}
	res=min(res,calc(tmp/3)+B+tmp2);
	tmp=now;
	tmp2=0;
	while(tmp%5!=0){
		tmp--;
		tmp2+=D;
	}
	res=min(res,calc(tmp/5)+C+tmp2);
	tmp=now;
	tmp2=0;
	while(tmp%5!=0){
		tmp++;
		tmp2+=D;
	}
	res=min(res,calc(tmp/5)+C+tmp2);
	M[now]=res;
	return res;
}
int main(){
	fastio;
	cin>>t;
	while(t--){
		cin>>N>>A>>B>>C>>D;
//		cout<<calc(10)<<endl;
		M.clear(); 
		cout<<calc(N)<<endl;
	}	
	return 0;
}


Measured memory_bytes: 4464
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n; cin >> n;
  vector<int> T(n), A(n);
  rep(i, n) cin >> T[i] >> A[i];
  ll prevT = T[0], prevA = A[0];
  rep(i, n) {
    ll mx = max({(prevT+T[i]-1)/T[i], (prevA+A[i]-1)/A[i]});
    prevT = mx * T[i];
    prevA = mx * A[i];
  }
  cout << prevT+prevA << "\n";
  return 0;
}


Measured memory_bytes: 3660
#include<iostream>
using namespace std;
int main(void){

    string q,a;
    while(cin>>q>>a){
        if(q==a&&q=="0")break;
        int hit=0,blow=0;

        for(int i=0;i<4;i++){
            if(q[i]!=-1&&q[i]==a[i]){
                hit++;
                q[i]=a[i]=-1;
            }
        }
        for(int i=0;i<4;i++){
            for(int j=0;j<4;j++){
                if(q[i]!=-1&&a[j]!=-1&&q[i]==a[j]){
                    blow++;
                    q[i]=a[j]=-1;
                }
            }
        }
        cout<<hit<<" "<<blow<<endl;
    }

    return 0;
}

Measured memory_bytes: 1192
A,B,C = (int(i) for i in input().split())

num = [A,B,C]
num.sort()

ans = 0
difference = (num[2]-num[1]) + (num[2]-num[0])
if difference%2 == 0:
    ans = difference/2
else:
    ans += 1
    difference += 1
    ans += difference/2

print(int(ans))

Measured memory_bytes: 3060
A = [list(map(int, input().split())) for i in range(3)]
N = int(input())
b = set([int(input()) for i in range(N)])
flag = False
for i in range(3):
  if A[i][0] in b and A[i][1] in b and A[i][2] in b:
    flag = True
  if A[0][i] in b and A[1][i] in b and A[2][i] in b:
    flag = True
if A[0][0] in b and A[1][1] in b and A[2][2] in b:
  flag = True
if A[0][2] in b and A[1][1] in b and A[2][0] in b:
  flag = True
print(['No','Yes'][flag])

Measured memory_bytes: 3064
from math import log2
from math import ceil
n,k=map(int,input().split())
p=0


for i in range(1,n+1):
    if i>=k:
        p+=1/n
    else:
        cnt=ceil(log2(k)-log2(i))
        p+=(1/n)*((1/2)**cnt)
    

print(p)


Measured memory_bytes: 3064
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <math.h>
typedef long long ll;
using namespace std;

int main()
{
	int n, k; cin >> n >> k;
	vector<int> h(n);
	int cnt = 0;
	for (int i = 0; i < n; i++)
	{
		cin >> h[i];
		if (h[i] >= k) cnt++;
	}
	cout << cnt << endl;
}

Measured memory_bytes: 640
#define _GIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;


int main(void) {
  string s[2];
  cin >> s[0] >> s[1];

  string s2[2];
  s2[0] = s[1];
  s2[1] = s[0];
  reverse(s2[0].begin(), s2[0].end());
  reverse(s2[1].begin(), s2[1].end());

  if (s2[0] == s[0] && s2[1] == s[1]) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
  
  return 0;
}

Measured memory_bytes: 3632
S=[int(x) for x in list(input())]
K=int(input())
count=0
if len(S)==1:
    print(S[0])
else:
    for i, box in enumerate(S):
        if box==1:
            count+=1
            if count==K:
                print(1)
                break
        else:
            print(S[i])
            break


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

int main(){
    int N;
    string march = "MARCH";
    string s;
    vector<long long> count(5);

    cin >> N;
    for(int i = 0; i < N; i++){
        cin >> s;
        for(int j = 0; j < 5; j++){
            if(march[j] == s[0]){
                count[j]++;
                break;
            }
        }
    }

    long long ans = 0;
    for(int i = 0; i < 5; i++){
        for(int j = i+1; j < 5; j++){
            for(int k = j+1; k < 5; k++){
                ans += count[i] * count[j] * count[k];
            }
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3604
#include<stdio.h>
int main(void){
    int W = 0,H = 0,r = 0, x = -101,y = -101;
    while(W <= 0 || 100 < W || H <= 0 || 100 < H || r <= 0 || 100 < r || x < -100 || 100 < x || y < -100 || 100 < y){
        scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);
    }
    if(x - r < 0 || y - r < 0 || x + r > W || y + r > H){
        printf("No\n");
    }
    else printf("Yes\n");
    return 0;
}


Measured memory_bytes: 2112
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
  ll X, K, D;
  cin >> X >> K >> D;
  ll ans;
  if (abs(X/D) >= K) {
    ans = abs(abs(X) - D*K);
  }
  else {
    if (X < 0) {
      while (X < 0) {
        X += D;
        K--;
      }
      if (K % 2 == 0) ans = X;
      else ans = abs(X-D);
    }
    else if (X > 0) {
      while (X > 0) {
        X -= D;
        K--;
      }
      if (K % 2 == 0) ans = -X;
      else ans = abs(X+D);
    }
    else {
      if (K % 2 == 0) ans = 0;
      else ans = D;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

const ll mod = 1e9 + 7;

int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  ll tot = 0;
  for (ll &i : a) {
    cin >> i;
    tot += i;
  }
  ll rs = a[0];
  ll ans = abs(rs - tot + rs);
  for (int i = 1; i < n-1; i++) {
    rs += a[i];
    ans = min(ans, abs(rs - tot + rs));
  }
  cout << ans << endl;
  return 0;
}


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

#define INF_LL (int64)1e18
#define INF (int64)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

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

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
  for(auto &e:u) fill_v<T>(e,v...);
}

template<typename T,T MOD,T B>
struct RollingHash{
  using ll = long long;
  vector<T> hash,po;
  RollingHash(){}
  RollingHash(vector<T> vs){init(vs);}
  RollingHash(string &s){
    vector<T> vs;
    for(char c:s) vs.emplace_back(c);
    init(vs);
  }
  void init(vector<T> vs){
    int n=vs.size();
    hash.assign(n+1,0);
    po.assign(n+1,1);
    for(int i=0;i<n;i++){
      hash[i+1]=((ll)hash[i]*B+vs[i])%MOD;
      po[i+1]=(ll)po[i]*B%MOD;
    }
  }
  //S[l, r)
  T find(int l,int r){
    T res=(ll)hash[r]+MOD-(ll)hash[l]*po[r-l]%MOD;
    return res>=MOD?res-MOD:res;
  }
};

int64 N, u, v;
vector<int64> G[112345];
vector<int64> d, md;

void dfs(int64 v, int64 p, int64 dep = 0) {
  d[v] = dep;
  for (auto& u : G[v]) {
    if (u == p) continue;
    dfs(u, v, dep+1);
    chmax(md[v], md[u]+1);
  }
}

int main(void) {
  cin >> N >> u >> v; u--; v--;
  REP(i, N-1) {
    int64 a, b;
    cin >> a >> b; a--; b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  d.resize(N, 0); md.resize(N, 0);
  dfs(v, -1);
  int64 turn = 0;
  while (1) {
    int64 pu = u;
    REP(i, G[u].size()) {
      if (d[G[u][i]] == d[u] - 1) {
        u = G[u][i];
        break;
      }
    }
    if (d[v] + turn >= d[u]) {
      cout << turn + md[pu] << endl;
      return 0;
    }
    if (d[v] + turn + 1 >= d[u]) {
      cout << turn + md[u] << endl;
      return 0;
    }
    turn++;
  }
}


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

int main() {
  int N,K;
  int L = 0;
  vector<int> x(N);
  
  cin >> N >> K;
  
  for(int i=0;i<N;i++){
    cin >> x.at(i);
    if(K-x.at(i) < x.at(i)){
      L += (K - x.at(i))*2;
    }else{
      L += x.at(i)*2;
    }
  }
  cout << L << endl;
}


Measured memory_bytes: 16640
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int[] count = new int[26];
        int num = 'a';
        while(sc.hasNext()){
            String str = sc.nextLine();
            char[] cha = str.toCharArray();
            for(char alp:cha){
                if(!Character.isAlphabetic(alp)){
                    continue;
                }
                alp = Character.toLowerCase(alp);
                count[alp-num]++;
            }
        }
        for(int i = 0; i < count.length; i++){
            System.out.print(Character.toChars(num+i));
            System.out.println(" : "+count[i]);
        }
    }
}

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

int main() {
  int N, K;
  cin >> N >> K;
  double ans = 0;

  for (int i = 1; i <= N; i++) {
    double p = 1;
    int q = i;

    while (q < K) {
      p *= 0.5;
      q *= 2;
    }
    ans += p / N;
  }
  printf("%.10f\n", ans);

  return 0;
}


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

int main()
{
    long long a, b, n, x, max = 0;
    scanf("%lld %lld %lld", &a, &b, &n);

    x = (n / b * b) - 1;

    long long ret = (a * x) / b - a * (x / b);
    max = max > ret ? max : ret;
    x += b;

    max = max > ((a * n) / b - a * (n / b)) ? max : ((a * n) / b - a * (n / b));

    printf("%d", max);

    return 0;
}

Measured memory_bytes: 1684