akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i, a, b) for(ll i = (ll)a; i <= (ll)b; i++)
#define DEC(i, a, b) for(ll i = (ll)a; i >= (ll)b; i--)
typedef pair<ll, ll> pi;
#define f first
#define s second
#define pb push_back
#define fastio ios_base::sync_with_stdio(0); cin.tie(0)

ll n, k, f[4010], t[1050], mi[4010], m = 998244353;

ll qexp(ll a, ll b) {
    a %= m;
    ll res = 1, base = a;
    while (b) {
        if (b & 1) {
            res *= base;
            res %= m;
        }
        base *= base;
        base %= m;
        b >>= 1;
    }
    return res % m;
}

inline ll choose(ll n, ll k) {
	if (n < k or k < 0 or n < 0) return 0;
	return (((f[n] * mi[k]) % m) * mi[n-k])%m;
}

ll add(ll a, ll b) {
	b %= m;
	a += b;
	a %= m;
	return a;
}

int main() {
	fastio;
	cin >> k >> n;
	f[0] = 1; FOR(i, 1, 4005) f[i] = (i * f[i-1]) % m;
	FOR(i, 0, 4005) mi[i] = qexp(f[i], m-2);
	t[0] = 1; FOR(i, 1, 1040) t[i] = (2 * t[i-1]) % m;
	FOR(i, 2, 2*k) {
		ll p = (i-1)/2 - max(0LL, i-k-1), ans = 0;
		if (i&1) {
			FOR(q, 0, p) {
				ans = add(ans, ((choose(n+k-2*p-1, q+k-2*p-1) * choose(p, q)) % m) * t[q]);
			}
		} else {
			FOR(q, 0, p) {
				ans = add(ans, ((t[q]*choose(p, q))%m) * add(choose(n+k-2*p-2, q+k-2*p-2), choose(n+k-2*p-3, q+k-2*p-2)));
			}
		}
		cout << ans << "\n";
	}
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main(){
  double av;
  int x[200000]={},m[200000]={},min,n,idx,a,b;
  cin>>n;
  for(int i=0;i<n;i++){cin>>x[i];}
  for(int i=0;i<n;i++)m[i]=x[i];
  sort(m,m+n);
  a=m[n/2];
  b=m[n/2-1];
  av=(a+b)/2;
  for(int i=0;i<n;i++)
    if(av>=x[i])cout<<a<<endl;
    else cout<<b<<endl;
  return 0;
}

Measured memory_bytes: 3712
import sys
input = sys.stdin.readline

N = int(input())
prob_table = list(map(float, input().split()))

dp = [[0 for _ in range(N+1)] for _ in range(N+1)]
dp[0][0] = 1
for i in range(0,N):
	for j in range(i+1):
		dp[i+1][j+1] += dp[i][j]*prob_table[i]
		dp[i+1][j] += dp[i][j]*(1-prob_table[i])

print(sum(dp[N][N//2+1:]))

Measured memory_bytes: 256776
N=int(input())
A=list(map(int, input().split()))
t=0
i=0
while i < N:
    if A[i] % 2 == 0:
        A[i] = A[i]//2
        if i == N - 1:
            t += 1
            i = -1
        i += 1
    else:
        break
print(t)


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


using namespace std;


using ll = long long;


int main(void) {
    ll A, B, N;
    cin >> A >> B >> N;
    ll x;
    if (B - 1 > N) {
        x = N;
    } else {
        x = B - 1;
    }
    ll ans = ((A * x) / B) - A * (x / B);
    cout << ans << endl;
}


Measured memory_bytes: 3640
#include "bits/stdc++.h"

using namespace std;
using ll = long long int;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pdi = pair<double, int>;

int N;
ll X;
vector<ll> b, l, u;
vector<pli> diff;
vector<ll> sumX;
vector<ll> sum0;

bool is_win(ll A) {
	const int q = (int)(A / X);
	const ll r = A % X;

	for (int i = 0; i < N; i++)
	{
		ll ans = 0;

		ans += r > b[i] ? u[i] * (r - b[i]) : -l[i] * (b[i] - r);

		if (i < q) {
			ans += sumX[q + 1];
			ans += sum0[q + 1];
			ans -= (ll)u[i] * (X - b[i]);
		}
		else {
			ans += sumX[q];
			ans += sum0[q];
			ans -= -(ll)l[i] * b[i];
		}

		if (ans >= 0)
			return true;
	}

	return false;
}

int main() {
	cin >> N >> X;
	b.assign(N, 0), l.assign(N, 0), u.assign(N, 0);
	for (int i = 0; i < N; i++)
		cin >> b[i] >> l[i] >> u[i];


	for (int i = 0; i < N; i++)
		diff.push_back(pli(u[i] * (X - b[i]) + l[i] * b[i], i));
	sort(diff.rbegin(), diff.rend());

	{
		vector<ll> dummyb, dummyl, dummyu;
		for (int i = 0; i < N; i++)
		{
			int ni = diff[i].second;
			dummyb.push_back(b[ni]);
			dummyl.push_back(l[ni]);
			dummyu.push_back(u[ni]);
		}
		b = dummyb;
		l = dummyl;
		u = dummyu;
	}

	sumX.push_back(0);
	sum0.push_back(0);
	for (int i = 0; i < N; i++) {
		sumX.push_back(sumX[i] + u[i] * (X - b[i]));
		sum0.push_back(sum0[i] - l[N - 1 - i] * b[N - 1 - i]);
	}
	reverse(sum0.begin(), sum0.end());

	ll lb = -1, rb = N * X; // (lb, rb]
	while (rb - lb > 1) {
		ll mid = (lb + rb) / 2;
		if (is_win(mid))
			rb = mid;
		else
			lb = mid;
	}

	cout << rb << endl;
	return 0;
}

Measured memory_bytes: 7792
/**
*　　　　　　　　┏┓　　 　┏┓
* 　　　　　　　┏┛┗━━━━━━━┛┗━━━┓
* 　　　　　　　┃　　　　　　　┃ 　
* 　　　　　　　┃　　　━　　 　┃
* 　　　　　　　┃　＞　　　＜　┃
* 　　　　　　　┃　　　　　　　┃
* 　　　　　　　┃...　⌒　... 　┃
* 　　　　　　　┃　　　　　　　┃
* 　　　　　　　┗━┓　　　┏━┛
* 　　　　　　　　　┃　　　┃　　　　　　　　　　
* 　　　　　　　　　┃　　　┃
* 　　　　　　　　　┃　　　┃　　　　　　　　　　　
* 　　　　　　　　　┃　　　┃  　　　　　　
* 　　　　　　　　　┃　　　┃
* 　　　　　　　　　┃　　　┃　　　　　　　　　　　
* 　　　　　　　　　┃　　　┗━━━┓
* 　　　　　　　　　┃　　　　　　　┣┓
* 　　　　　　　　　┃　　　　　　　┏┛
* 　　　　　　　　　┗┓┓┏━┳┓┏┛
* 　　　　　　　　　　┃┫┫　┃┫┫
* 　　　　　　　　　　┗┻┛　┗┻┛
*/
#include<iostream>  
#include<cstdio>  
#include<fstream>  
#include<iomanip>
#include<algorithm>  
#include<cmath>  
#include<deque>  
#include<vector>
#include<bitset>
#include<queue>  
#include<string>  
#include<cstring>  
#include<map>  
#include<stack>  
#include<set>
#include<cassert>
#include<functional>

#define pii pair<int, int>
#define mod 1000000007
#define mp make_pair
#define pi acos(-1)
#define eps 0.000000001
#define mst(a,i) memset(a,i,sizeof(a))
#define all(n) n.begin(),n.end()
#define lson(x) ((x<<1))  
#define rson(x) ((x<<1)|1) 
#define inf 0x3f3f3f3f
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
const int maxn = 1005;
int	c[maxn], s[maxn], f[maxn];

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
#ifdef DEBUG
	freopen("old_data.json", "r", stdin);
	freopen("1.out", "w", stdout);
#endif // DEBUG clang++ checker.cpp --target=i686-pc-mingw32 -o checker.exe
	int n;
	cin >> n;
	for (int i = 1; i < n; ++i) {
		cin >> c[i] >> s[i] >> f[i];
	}
	for (int i = 1; i <= n; ++i) {
		int now = 0;
		for (int j = i; j < n; ++j) {
			if (now < s[j])now = s[j];
			if (now%f[j] != 0) {
				now = ((now / f[j]) + 1) * f[j];
			}
			now += c[j];
		}
		cout << now << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<map>
#include<set>

using namespace std;

int main(){
	int n;
	while(cin>>n && n){
	
	vector<int> v;
	
	for(int i=0;i<n;i++){
		int x;
		cin>>x;
		v.push_back(x);
	}
	int co=0;
	while(co<=10001){
		for(int i=0;i<v.size();i++){
			if(i+1!=v[i])break;
			else if(i+1==v.size()){
				cout<<co<<endl;
				goto suc;
			}
		}
		int s=v.size();
		co++;
		for(vector<int>::iterator ite=v.begin();ite!=v.end();++ite){
			(*ite)--;
			if(*ite==0){
				ite=v.erase(ite);
				--ite;
				}
			}
			v.push_back(s);
		}
		cout<<-1<<endl;
		suc:;
	}
}

Measured memory_bytes: 1236
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
ll mod = 1000000007;

int n;
string s;
ll dp[100005][13];

void solve() {
    ll ans = 0;
    n = s.size();

    dp[0][0] = 1;
    rep(i, n) {
        int c;
        if(s[i] == '?') {
            c = -1;
        }
        else {
            c = s[i] - '0';
        }

        rep(j, 10) {
            if(c != -1 && c != j) {
                continue;
            }
            rep(ki, 13) {
                dp[i+1][(10*ki + j)%13] += dp[i][ki];
            }
        }
        rep(j, 13) {
            dp[i+1][j] %= mod;
        }
    }
    ans = dp[n][5];

    cout << ans;
}

int main() {
    cin >> s;
    
    solve();
    
    cout << endl;
    return 0;
}

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

const int N = 1e5 + 10;

int a[N];
long long sum[N], sum1[N], sum2[N];

int main(){
	int n, q, x, l, r, mid, d;
	long long ans;
	scanf("%d %d",&n,&q);
	for (int i = 1; i <= n; i++) scanf("%d",&a[i]);
	sum[0] = sum1[0] = sum2[0] = 0;
	for (int i = 1; i <= n; i++){
		sum[i] = sum[i - 1] + a[i];
		if (i & 1) sum1[(i + 1) / 2] = sum1[(i - 1) / 2] + a[i];
		else sum2[i / 2] = sum2[i / 2 - 1] + a[i];
	}
	for (int i = 1; i <= q; i++){
		scanf("%d",&x);
		d = lower_bound(a + 1, a + n + 1, x) - a;
		l = d - 1; r = n;
		while (r - l > 1){
			mid = (l + r) / 2;
			d = lower_bound(a + 1, a + n + 1, x * 2 - a[mid]) - a;
			if (mid - d + 1 > n - mid) r = mid;
			else l = mid;
		}
		ans = sum[n] - sum[l];
		if (l * 2 - n >= 1){
			if ((l * 2 - n) & 1) ans += sum1[(l * 2 - n + 1) / 2];
			else ans += sum2[(l * 2 - n) / 2];
		}
		printf("%lld\n", ans);
	}
	return 0;
}

Measured memory_bytes: 3712
a, b = map(int, input().split())
count = 0
ans = 0
for i in range(1, 1001):
    if int(i*0.08) == a and int(i*0.1) == b:
        count = 1
        ans = i
        break
    else:
        pass
print(ans if count == 1 else "-1")

Measured memory_bytes: 2940
import java.util.Scanner;

public class Main {
	public static void main(String arg[]) {

		Scanner sc = new Scanner(System.in);

		// 年齢
		int r = sc.nextInt();

		// 通常の値段
		int D = sc.nextInt();

		// x(2000)～x(2011)の配列(11個)
		int x[] = new int[11];

		for (int i = 0; i < 11; i++) {
			// x(2000)のみ入力
			if (i == 0) {
				x[i] = sc.nextInt();
				continue;
			}

			// 指定された式
			x[i] = r * x[i - 1] - D;
			System.out.println(x[i]);

		}

	}
}


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


int main()
{
	ll n;
	cin>>n;
	ll a[n+1],b[n+1],c[n+1];

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

    }
    ll ans=max(dp[n][0],max(dp[n][1],dp[n][2]));
    cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 8280
a = input()
b = a[::-1]
s ,t ,r= 0,0,0

while s+t<len(a):
    if a[s] == b[t]:
        s+=1
        t+=1
    elif a[s] =="x":
        r+=1
        s+=1
    elif b[t] =="x":
        r+=1
        t+=1
    else:
        print(-1)
        exit()
print(r)


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

int main(){

int s;
cin>>s;

int a = s%10;

if(a == 2 || a == 4 || a == 5 || a == 7 || a == 9) cout<<"hon"<<endl;

else if(a == 0 || a == 1 || a == 6 || a == 8) cout<<"pon"<<endl;

else cout<<"bon"<<endl;


}


Measured memory_bytes: 3636
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")

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

#define pb push_back
#define F first
#define S second
#define f(i,a,b)  for(int i = a; i < b; i++)
// #define endl '\n'

using ll = long long;
using db = long double;
using ii = pair<int, int>;

const int N = 1e5+5, LG = 17, MOD = 998244353;
const int SQ = 450;
const long double EPS = 1e-7;
int cnt[N];
int32_t main(){
#ifdef ONLINE_JUDGE
    ios_base::sync_with_stdio(0);
    cin.tie(0);
#endif
  int n,x;
  cin>>n;
  f(i,0,n){
    cin>>x;
    cnt[x]++;
  }
  n/=2;
  int cur = 0,ans;
  f(i,1,N){
    cur+=cnt[i];
    if(cur==n)ans++;
  }
  cout<<ans<<'\n';

  return 0;
}


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

int main() {
  char a,b;cin>>a>>b;
  string ans = a=='9'||b=='9'?"Yes":"No";
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#include <vector>
#include <string>
#include <cstdio>
#include <cmath>

using namespace std;

int main(void)
{
    ios::sync_with_stdio(false);
    int n, m, k;
    cin >> n >> m;
    int a[2*n], b[2*n];
    for(int i=0; i<2*n; i++) a[i] = i+1;
    for(int i=0; i<m; i++) {
        cin >> k;
        if(k == 0) {
            for(int j=0; j<n; j++) {
                b[2*j] = a[j];
                b[2*j+1] = a[n+j];
            }
        } else {
            for(int j=0; j<2*n; j++) b[j] = j+1;
            for(int j=0; j<2*n-k; j++) b[j] = a[j+k];
            for(int j=0; j<k; j++) b[j+2*n-k] = a[j];
        }
        for(int j=0; j<2*n; j++) a[j] = b[j];
    }
    for(int i=0; i<2*n; i++)
        cout << a[i] << endl;

    return 0;
}

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

int main() {
  int N, K;
  cin >> N >> K;
  double ans = 0;
  for (int i = 1; i <= N; i++) {
    int a = i;
    int n = 0;
    while (a < K) {
      n++;
      a *= 2;
    }
    ans += pow(0.5, n);
  }
  printf("%.10lf\n", ans / (double) N);
}

Measured memory_bytes: 256
#include <stdio.h>
 
#define PRIME_MAX 1000000
int getprimes(int list[], int top){
    int i, j;
    int index = 0;
    char tmp[PRIME_MAX];
 
    for(i=0;i<top;i++) {
        tmp[i] = 1;
    }
    
    tmp[0] = tmp[1] = 0;
    for(i=2;i<top;i++) {
        if(tmp[i] == 1) {
            /* 素数 */
            list[index] = i;
            index ++;
            for(j=2;j*i<top;j++) {
                tmp[j*i] = 0;
            }
        }
    }
 
    list[index] = -1;
    return index;
}
 
int gcd(int a, int b) {
	if (a < 0 || b < 0) {
		return 0;
	}

	while (b > 0) {
		int c = a % b;
		a = b;
		b = c;
	}

  return a;
}

inline int numofbits5(long bits) {
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
    return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}

int main(void) {
    int i;
    int n, base;
    int size;
    int *primes;
    int div[1000];
    int d;
    int j;
    int old_prime = -1;
	unsigned char* memo;
	double c;
    primes = (int*)malloc(100001*4);
    size = getprimes(primes, PRIME_MAX);
    
    scanf("%d\n", &base);
    i = d = 0;
    n = base;
    while(n > 1) {
        if((n % primes[i]) == 0) {
        	if(old_prime != primes[i]) {
	            div[d] = primes[i];
	            d++;
        	}
            n /= primes[i];
            old_prime = primes[i];
        } else {
            i++;
        }
         
        if(i >= size) {
            div[d] = n;
            d++;
            break;
        }
    }
    free(primes);

	c = base;
	for(j=0;j<d;j++) {
		c = c * (1 - 1.0/div[j]);
	}
/*
    memo = (unsigned char*)malloc(base/8+1);
    for(i=0;i<base/8+1;i++) memo[i] = 0;
	c = 0;
    for(j=0;j<d;j++) {
        for(i=div[j];i<base;i+=div[j]) {
        	memo[i/8] |= 1<<(i%8);
        }
    }
    
    for(i=1;i<base;i++) {
    	if(!(memo[i/8]&(1<<(i%8)))) c++;
    }
*/
    printf("%d\n", (int)c);
    
    return 0;
}

Measured memory_bytes: 1684
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <cmath>
#define rep(i,cc,n) for(int i=cc;i<=n;++i)
#define drep(i,cc,n) for(int i=cc;i>=n;--i)
typedef long long ll;
using namespace std;

int main(){
    ll n,m;
    cin>>n>>m;
    vector<ll> a(m);
    ll ans = 0;
    rep(i,0,m-1){
        cin>>a[i];
        ans += a[i];
    }
    if(n>=ans) cout<<n-ans<<endl;
    else cout<<"-1"<<endl;
    return 0;
}

Measured memory_bytes: 3704
n = int(input())
lst = []

for i in range(n):
  lst.append(input())
  
print('AC x ' + str(lst.count('AC')))
print('WA x ' + str(lst.count('WA')))
print('TLE x ' + str(lst.count('TLE')))
print('RE x ' + str(lst.count('RE')))

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

using namespace std;

typedef long long ll;
const int mod = (int) 1e9 + 7;

int add(int a, int b) {
  a += b;
  if (a >= mod) {
    return a - mod;
  }
  if (a < 0) {
    return a + mod;
  }
  return a;
}

int mul(int a, int b) {
  return a * (ll) b % mod;
}

int pw(int a, int b) {
  int r = 1;
  while (b) {
    if (b & 1) {
      r = mul(r, a);
    }
    a = mul(a, a);
    b /= 2;
  }
  return r;
}

int dv(int a, int b) {
  return mul(a, pw(b, mod - 2));
}

const int N = 2000 * 2000 + 7;
const int L = 2000 + 7;
int fact[N], inv[N];
int n, k, dp[L][L];

int comb(int n, int k) {
  int x = fact[n];
  int y = mul(inv[k], inv[n - k]);
  return mul(x, y);
}

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

  fact[0] = 1;
  for (int i = 1; i < N; i++) {
    fact[i] = mul(fact[i - 1], i);
  }
  inv[N - 1] = dv(1, fact[N - 1]);
  for (int i = N - 2; i >= 0; i--) {
    inv[i] = mul(i + 1, inv[i + 1]);
  }
  cin >> n >> k;
  if (k == 1) {
    cout << "1\n";
    return 0;
  }
  dp[0][0]=1;
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j <= i; j++) {
      dp[i][j] = dp[i - 1][j];
      if (j) {
        dp[i][j] = add(dp[i][j], mul(dp[i][j - 1], comb(n - i + (n - j + 1) * (k - 1) - 1, k - 2)));
      }
    }
  }
  int ans = dp[n][n];
  ans = mul(ans, fact[n]);
  cout << ans << "\n";
}


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

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

int main() {
  long long n,k,sum=0,a=0,b=0,c=0,d=0,ans=0;
  long long MOD = 1000000007;
  long long INF = 1LL << 60;
  string S="";
  cin >> a >> b >> c;
  if(c%gcd(a,b)==0) S = "YES";
  else S = "NO";
  
  cout << S << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
    int n,k;
    scanf("%d %d", &n, &k);
    int ai[n];
    for(int i = 0; i < n; i++){
        scanf("%d", &ai[i]);
    }
    for(int i = 0; i < n-k; i++){
        if(ai[i] < ai[i + k]){
            printf("Yes\n");
        }   
        else{
            printf("No\n");
        }
    }
  
    return 0;
}


Measured memory_bytes: 3944
import heapq

INF = 10**20
A = 50  # max A


def inpl():
    return list(map(int, input().split()))


def main():
    N, M, S = inpl()
    S = min(S, M * A)

    lines = [[] for _ in range(N * (M * A + 1))]
    for _ in range(M):
        in_s, in_t, cost, time = inpl()
        in_s -= 1
        in_t -= 1

        for n in range(cost, M * A + 1):
            s = in_s + n * N
            t = in_t + (n - cost) * N
            lines[s].append((t, time))

            s = in_s + (n - cost) * N
            t = in_t + n * N
            lines[t].append((s, time))

    for i in range(N):
        cost, time = inpl()
        for n in range(0, M * A + 1):
            s = i + n * N
            if n + cost > M * A:
                t = i + (M * A) * N
            else:
                t = i + (n + cost) * N
            lines[s].append((t, time))

    def dijkstra(N, S):
        weight = [INF] * N
        weight[S] = 0
        q = [[0, S]]
        heapq.heapify(q)
        while q:
            w0, s = heapq.heappop(q)
            for t, w in lines[s]:
                w += w0
                if weight[t] > w:
                    heapq.heappush(q, [w, t])
                    weight[t] = w

        return weight

    weight = dijkstra(N * (M * A + 1), 0 + S * N)

    ansl = [INF] * N
    for i, w in enumerate(weight):
        n = i % N
        if n == 0:
            continue
        else:
            ansl[n] = min(w, ansl[n])

    print("\n".join(map(str, ansl[1:])))


if __name__ == "__main__":
    main()


Measured memory_bytes: 183716
#include <stdio.h>
 
int main(){
int a,b,c,k,i;
int max = 0;
int late;
scanf("%d %d %d",&a,&b,&c);
scanf("%d",&k);
if(max < a)
	max = a;
if(max < b)
	max = b;
if(max < c)
	max = c;
 
late = max;
for(i = 0;i < k;i++){
late = late * 2;
}
 
 
printf("%d",late + a + b + c - max);
return 0;
}

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

using namespace std;
#define ll long long
#define ld long double
#define mk make_pair
#define pb push_back
#define sz(a) (int)(a).size()
#define rep(i, a, b) for (int i = (a), _b = (b); i < _b; ++i)

typedef complex<ld> cplex;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef vector<ii> vii;
typedef vector<iii> viii;

const int multipleTest = 0;
const int N = 300000 + 7;
const int inf = 1000000007;


string s[2];
int dp[N][3][3];
int n;

void solve() {
    cin >> n;
    cin >> s[0] >> s[1];
    for (int i = 0; i < n; ++i) {
        for (int u = 0; u < 3; ++u) for (int v = 0; v < 3; ++v) {
            if (s[0][i] == s[1][i]) {
                if (u != v) continue;
                if (i == 0) dp[i][u][v] = 1;
                else {
                    rep(lu, 0, 3) rep(lv, 0, 3) if (u != lu && v != lv) {
                        dp[i][u][v] = (dp[i][u][v] + dp[i - 1][lu][lv]) % inf;
                    }
                }
            } else {
                if (u == v) continue;
                if (i == 0) dp[i][u][v] = 1;
                else {
                    rep(lu, 0, 3) rep(lv, 0, 3) {
                        if (s[0][i] == s[0][i - 1] && u != lu) continue;
                        if (s[1][i] == s[1][i - 1] && v != lv) continue;
                        if (s[0][i] != s[0][i - 1] && u == lu) continue;
                        if (s[1][i] != s[1][i - 1] && v == lv) continue;
                        dp[i][u][v] = (dp[i][u][v] + dp[i - 1][lu][lv]) % inf;
                    }
                }
            }
        }
    }
    int res = 0;
    rep(u, 0, 3) rep(v, 0, 3) {
        res = (res + dp[n - 1][u][v]) % inf;
//        cout << u << ' ' << v << ' ' << dp[n - 1][u][v] << '\n';
    }
    cout << res;
}

int main() {
#ifdef _LOCAL_
    freopen("in.txt", "r", stdin);
    //    freopen("out.txt", "w", stdout);
#endif
    
    int Test = 1;
    if (multipleTest) {
        cin >> Test;
    }
    for(int i = 0; i < Test; ++i) {
        solve();
    }
    
#ifdef _LOCAL_
    cout<<"\n" << 1.0 * clock() / CLOCKS_PER_SEC <<endl;
#endif
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        
    
 Scanner input = new Scanner (System.in); 
   int a = input.nextInt();
    int b = input.nextInt();
    if(((a + b) % 2) == 0) {
      System.out.println((a + b) / 2);
    }
    else {
      System.out.println("IMPOSSIBLE");
    }
 }
}

Measured memory_bytes: 21844
#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <stack>
#include <math.h>
#include <map>
#define Z class
#define ln cout<<'\n'
#define ll long long
#define rep(i, n) for(int i = 0; i < (n); ++i)
//ASCII a=97, A=65
// int H[N]; rep(i,N) scanf("%d", &H[i]);
// int max_x = *std::max_element(x.begin(), x.end());
// int min_y = *std::min_element(y.begin(), y.end());
// sort(vec.begin(), vec.end()); std::greater<>()
// reverse(vec.begin(), vec.end());
using namespace std;
template<class T> inline bool chmax(T& a, T b){ if(a < b) { a=b; return 1; }return 0;}
template<class T> inline bool chmin(T& a, T b){ if(a > b) { a=b; return 1; }return 0;}
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}

int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
const long long INF = 1LL << 60;

int main(){
    string s; cin >> s;
    vector<int> a(200000); rep(i,200000) a[i] = 200000;
    vector<int> z(200000);
    
    rep(i,s.length()){
        if(s[i]=='A') a[i] = i;
        if(s[i]=='Z') z[i] = i;
    }
    sort(a.begin(), a.end());
    sort(z.begin(), z.end(),std::greater<>());
    pr(z[0] - a[0]+1);
}


Measured memory_bytes: 2180
#include<bits/stdc++.h>
using namespace std;
int main()
{
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);cout.tie(NULL);
        int n;
        cin>>n;
        if(n>=30){
                cout<<"Yes";
        }
        else{
        cout<<"No";
        }
                return 0;
}
/*

        creation time:  13.09.2020 09:23:27

*/                      



Measured memory_bytes: 3604
def solve(N, X):
    thickness = [1]
    pate = [1]
    for L in range(1, N + 1):
        thickness.append(thickness[-1] * 2 + 3)
        pate.append(pate[-1] * 2 + 1)

    def sub(t, X):
        middle = (thickness[t] - 1) // 2
        if t == 0:
            return 1
        if X <= 0:
            return 0
        if X < middle:
            return sub(t - 1, X - 1)
        if X == middle:
            return pate[t - 1] + 1
        return pate[t - 1] + 1 + sub(t - 1, X - middle - 1)

    return sub(N, X - 1)

def test():
    def f(N, X, expect):
        print('N={}, X={}'.format(N, X))
        print(solve(N, X), 'expect={}'.format(expect))
    f(2, 7, 4)
    f(2, 8, 4)
    f(2, 9, 5)
    f(50, 4321098765432109, 2160549382716056)

    print('-'*5)
    for i in range(1, 14): f(2, i, '')

    print('-'*5)
    for i in range(1, 6): f(1, i, '')


if __name__ == '__main__':
    N, X = map(int, input().split())
    print(solve(N, X))

Measured memory_bytes: 3064
from itertools import product

n = int(input())
xy = []
for _ in range(n):
    a = int(input())
    tmp = [list(map(int, input().split())) for _ in range(a)]
    xy.append(tmp)

ans = 0
for bit in product([0, 1], repeat=n):
    for i, liar in enumerate(bit):
        if liar and any(bit[x - 1] != y for x, y in xy[i]):
            break
    else:
        ans = max(ans, sum(bit))
print(ans)


Measured memory_bytes: 75064
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)*}
    };
}

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)*}
    };
}

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, usize1) => {
        read_value!($next, usize) - 1
    };

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

use std::cmp::max;

fn main() {
    input!{
        n: usize,
        v: [i64; n]
    }
    let mut tab: Vec<Vec<i64>> = vec![vec![0; n]; n];
    for i in 0..n {
        tab[i][i] = v[i];
    }
    for d in 1..n {
        for i in 0..n - d {
            tab[i][i + d] = max(v[i] - tab[i + 1][i + d], v[i + d] - tab[i][i + d - 1]);
        }
    }
    println!("{}", tab[0][n - 1]);
}


Measured memory_bytes: 90364
#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int n;
  cin >> n;
  long long ans = 0;
  for(long long a = 1; a < n; a++) {
    for(long long b = a; a * b < n; b++) {
      if (a == b) ans++;
      else ans += 2;
    }
  }
  cout << ans;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define inf 1000000000000000001
#define mod 1000000007
#define all(c) c.begin(),c.end()
#define mp(x,y) make_pair(x,y)
#define mem(a,val) memset(a,val,sizeof(a))
#define eb emplace_back
#define pb push_back
#define f first
#define s second
#define fast_cin ios_base::sync_with_stdio(false);cin.tie(NULL);
#define precise fixed(cout);cout<<setprecision(16);
#define Set(N,p) N=((N)|((1LL)<<(p)))
#define Reset(N,p) N=((N)&(~((1LL)<<(p))))
#define Check(N,p) (!(((N)&((1LL)<<(p)))==(0)))
#define POPCOUNT __builtin_popcountll
#define RIGHTMOST __builtin_ctzll
#define LEFTMOST(x) (63-__builtin_clzll((x)))
#define NUMDIGIT(x,y) (((vlong)(log10((x))/log10((y))))+1)
#define OUT(x) for(auto a:x) cout << a << " "; cout << endl;
#define OK cout << "@===================ok===================@" <<endl;
#define WTF cout <<"< "<<lo<<" | "<< hi <<" >" << endl;

using namespace std;

int main()
{
    int n;
	cin >> n;
	string s,t;
	cin >> s >> t;
	string res="";
	for(int i=0,j=0;i<n&&j<n;){
		res+=s[i++];
		res+=t[j++];
	}
	cout << res << endl;
}


Measured memory_bytes: 256
x, y, z, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
a.sort(reverse = True)
b.sort(reverse = True)
c.sort(reverse = True)
ans = []
for s in range(x):
    for t in range(y):
        if (s + 1) * (t + 1) > k:
            break
        for u in range(z):
            if (s + 1) * (t + 1) * (u + 1) > k:
                break
            ans.append(a[s] + b[t] + c[u])
ans.sort(reverse = True)
for i in range(k):
    print(ans[i])

Measured memory_bytes: 8708
N = int(input())
XYH = [list(map(int,input().split())) for i in range(N)]
XYH.sort(key = lambda x:x[2], reverse = 1)
for Cx in range(101):
    for Cy in range(101):
        H = XYH[0][2]+abs(XYH[0][0]-Cx)+abs(XYH[0][1]-Cy)
        cnt = 0
        for X,Y,h in XYH:
            if h == max(H-abs(X-Cx)-abs(Y-Cy),0):
                    cnt += 1
        if cnt == N:
            print(Cx,Cy,H)
            break

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main() {
    long long X, Y, A, B, C; cin >> X >> Y >>A >> B >> C;
    long long red[A], green[B], colorless[C];
    for (int i = 0; i < A; i++) cin >> red[i];
    for (int i = 0; i < B; i++) cin >> green[i];
    for (int i = 0; i < C; i++) cin >> colorless[i];

    sort(red, red + A);
    sort(green, green + B);
    sort(colorless, colorless + C);

    long long eat[X+Y];
    for (int i = 0; i < X; i++)
    {
        eat[i] = red[A-1-i];
    }
    for (int i = 0; i < Y; i++)
    {
        eat[X+i] = green[B-1-i];
    }
    sort(eat, eat + X + Y);
    for (int i = 0; i < min(X+Y, C); i++)
    {
        if(colorless[C-1-i] <= eat[i]) break;
        eat[i] = colorless[C-1-i];
    }

    long long ans = 0;
    for (int i = 0; i < X+Y; i++)
    {
        ans += eat[i];
    }

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

Measured memory_bytes: 3968
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<map>
#include<list>
#include<stack>
#include<queue>
#include<climits> //INT_MIN/MAX


using namespace std;

#define FOR(i,s,e) for(int (i)=(s);(i)<(e);(i)++)
#define FORR(i,s,e) for(int (i)=(s);(i)>(e);(i)--)
#define MOD 1000000007
#define llong long long
#define debug(x) cout<<#x<<": "<<x<<endl

llong n;


int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    int flag1 = 0;
    int flag2 = 0;
    char c[101];
    cin >> c;
    FOR(i, 0, 100) {
        if (c[i] == 'C')
            flag1 = 1;
        if (flag1==1&&c[i] == 'F')
            flag2 = 1;
    }
    if(flag1==1&&flag2==1)
    cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
 
public class Main {
	public static void main(String[] args) {
		// practice contest
 
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		// char[] array = new char[4];
		// for (int i = 0; i < array.length; i++) {
		// array[i] = S.charAt(i);
		// }
		char[] array = S.toCharArray();
		Arrays.sort(array);
 
		if ((array[0] == array[1]) && (array[2] == array[3]) && (array[0] != array[2])) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
 
		Arrays.sort(array);
		// for()
		// if(array[i])
 
	}
}

Measured memory_bytes: 21328
#include <iostream>
int main() {
    int r, c, a[100] = { 0 }, s = 0;
    std::cin >> r >> c;
    for (int i = 0; i < r; ++i, s = 0) {
        for (int j = 0, n; j < c; ++j) {
            std::cin >> n;
            std::cout << n << ' ';
            a[j] += n;
            s += n;
        }
        std::cout << s << std::endl;
    }
    for (int i = 0; i < c; ++i) {
        s += a[i];
        std::cout << a[i] << ' ';
    }
    std::cout << s << std::endl;
}



Measured memory_bytes: 3080
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")

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

#define pb push_back
#define F first
#define S second
#define f(i,a,b)  for(int i = a; i < b; i++)
#define endl '\n'

using ll = long long;
using db = long double;
using ii = pair<int, int>;
const int N = 300 * 4, MX = 2e6, LG = 19, MOD = 1e9 + 7;
const int SQ =225;
const long double EPS = 1e-7;
vector<int> solve(ll n){
  if(n == 1)
    return vector<int>({});
  if(n&1){
    vector<int> x = solve(n-1);
    int val = 0;
    if(!x.empty())
    val = *max_element(x.begin(),x.end());
    x.insert(x.begin(), val + 1);
    return x;
  } else {
    vector<int> x = solve(n>>1);
    int val = 0;
    if(!x.empty())
    val = *max_element(x.begin(),x.end());
    x.pb(val + 1);
    return x;
  }
}
int32_t main(){
#ifdef ONLINE_JUDGE
    ios_base::sync_with_stdio(0);
    cin.tie(0);
#endif
  ll n;
  cin >> n;
  auto out = solve(n+1);
  cout<<out.size()*2<<'\n';
  for(auto x : out)cout << x << " ";
  f(i,0,out.size())cout << i + 1 << " ";

  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		//コンソールに入力した値を取得
		String a = sc.next();

		if (Character.isUpperCase(a.charAt(0))) {
			System.out.println("A");
		} else {
			System.out.println("a");
		}

		sc.close();
	}
}


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

int main(){
  int N;
  cin >> N;
  vector<int> boss(N+1);
  vector<int> sub(N+1);
  vector<int> n(N+1);
  
  int i=0;
  for(i=2; i < N+1; i++){
    cin >> boss[i];
    sub[boss[i]]++;
  }
  
  for(i=1; i < N+1; i++){
    cout << sub[i] << endl;
  }

}

Measured memory_bytes: 5596
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define si(X) scanf("%d", &(X))
#define sll(X) scanf("%lld",&(X))
const ll mod = 1e9+7;
#define INFL 0x3f3f3f3f3f3f3f3fLL
 
//-------------------------<MATH>-------------------------------------------------------//
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll expo(ll base,ll pow){ll ans = 1;
   while(pow!=0){if(pow&1==1){ans = ans*base;ans = ans%mod;}
   base *= base;base%=mod;pow/=2;}return ans;}
ll inv(ll x){return expo(x,mod-2);}
ll mult_mod(ll a , ll b){a = a%mod; b = b%mod;
ll c = (a * b)%mod;
//cout << a << " " << b << endl;
return c;}
ll add_mod(ll a , ll b){a = (a + mod)%mod;b = (b + mod)%mod;ll c = (a + b)%mod;return c;}
ll fac[(int)(5e5 + 5)] , inv_fac[(int)(5e5 + 5)];
void precomp_factorial(int M){fac[0] = 1;for(int i = 1 ; i <= M ; i++) fac[i] = mult_mod(i , fac[i - 1]);
    inv_fac[M] = inv(fac[M]);for(int i = M - 1 ; i >= 0 ; i--) inv_fac[i] = mult_mod(i + 1 , inv_fac[i + 1]);}
ll nCk(ll n , ll k){ll ans = fac[n];ans = mult_mod(ans , inv_fac[n - k]);ans = mult_mod(ans , inv_fac[k]);return ans;}
int lo[(int)(1e3 + 6)];
void sieve(int M){for(int i = 2 ; i < M ; i++){ if(lo[i]) continue; for(int j = i ; j < M ; j += i)lo[j] = i;}}
int max_expo_prime_n_fac(ll N , int prime){int ress = 0;while(N){ress += (N/prime);N /= prime;}return ress;}
//-------------------------</MATH>-------------------------------------------------------//
 
//-------------------------<STRING>-------------------------------------------------------//
string get_prefix(string x , int MAX){return x.substr(0 , min((int)x.size() , MAX));}
string get_suffix(string x,int MAX){int dn=1;for(int i=x.size()-1;i>=0;i--){if(dn==MAX)return x.substr(i);dn++;}return x;}
string convert_to_binary(int x,int len) {string ans=""; while(x){if(x&1){ans='1'+ans;}
    else{ans ='0'+ans;}x/=2;}int k = ans.size();while(k < len){ans = '0' + ans;k++;}return ans;}
//-------------------------</STRING>-------------------------------------------------------//
 
ull llrand() {ull r = 0;for(int i = 0; i < 5; ++i){r = (r << 15)|(rand() & 0x7FFF);}return r & 0xFFFFFFFFFFFFFFFFULL;}
int dx[8] = {1 , 0 , -1 , 0 , 1 , -1 , -1 , 1};    // last 4 diagonal
int dy[8] = {0 , 1 , 0 , -1 , 1 , 1 , -1 , -1};
 
ll dp[213456][9]; 
 
int valid(vector <char> vec){
    if(vec[0] == 'L' && vec[2] == 'R') return 1;
    if(vec[0] == 'R' && vec[2] == 'L') return 1;
    if(vec[0] == 'R' && vec[1] == 'L') return 1;
    if(vec[1] == 'R' && vec[2] == 'L') return 1;
    return 0;
}
 
char change(char c, int val){
    if(val)
    return c == 'L'? 'R': 'L';
    return c;
}
 
int main(){

   ll n;
   cin >> n;
    vector <ll> vec(n);
    ll sum = 0;
    for(int i = 0; i < n; i++){
        cin >> vec[i];
        //cout << sum << " " << i << endl;
        if(i){
            //cout << vec[i] << " " << vec[i-1] << endl;
            sum += max(vec[i-1] - vec[i], 0LL);
            vec[i] = max(vec[i], vec[i-1]);
        }
    }
    cout << sum;
   
}

Measured memory_bytes: 4780
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e3+100;
int a[maxn];

int main(){
    int n,k,i,ans=0;
    scanf("%d%d",&n,&k);

    for(i=1;i<=n;i++)
        scanf("%d",&a[i]);
    sort(a+1,a+1+n);
    for(i=1;i<=k;i++)ans+=a[i];
    printf("%d\n",ans);
    return 0;
}

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

int k;
char s[123456];

int main(){

  cin >> s >> k;

  for (int i = 0; i < (int)strlen(s) - 1 && k > 0; i++) {
    if (s[i] - 'a' != 0) {
      int foo = 'z' - s[i] + 1;
      if (foo <= k) {
        k -= foo;
        s[i] = 'a';
      }
    }
  }

  int len = (int)strlen(s);
  int mo = (s[len - 1] - 'a' + k) % 26;
  s[len - 1] = (char)(mo + 'a');
  puts(s);

  return 0;
}


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

int main(void){
    ll n,m,k;cin >> n >> m >> k;
    ll a[n],b[m];
    rep(i,n)cin >> a[i];
    rep(i,m)cin >> b[i];
    
    ll N[n],M[m];
    int alina = 0;
    N[0] = a[0],M[0] = b[0];
    for(int i = 1;i < n;i++){
        N[i] = N[i-1] + a[i];
        if(N[i] <= k)alina = max(alina,i+1);
    }
    for(int i = 1;i < m;i++){
        M[i] = M[i-1] + b[i];
        if(M[i] <= k)alina = max(alina,i+1);
    }
    
    for(int i = 0;i < n;i++){
        if(N[i] > k)break;
        
        int ng = -1,ok = m;
        while(abs(ok-ng) > 1){
            int mid = (ok+ng)/2;
            if(M[mid]+N[i] > k)ok = mid;
            else ng = mid;
        }
        alina = max(alina,ok+i+1);
    }
    cout << alina;
}

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

using namespace std;

int main() {
   ios::sync_with_stdio(false);
   cin.tie(0);
   int n;
   cin >> n;
   int cnt = 0;
   for(int i = 0; i < n; i++) {
       int foo, bar;
       cin >> foo >> bar;
       if(foo == bar) {
           cnt++;
       } else {
           if(cnt >= 3) {
               cout << "Yes" << endl;
               return 0;
           } else {
               cnt = 0;
           }
       }
   }
   if(cnt >= 3) {
       cout << "Yes" << endl;
       return 0;
   }
   cout << "No" << endl;
}

Measured memory_bytes: 3644
a = int(input())
b = int(input())
c = int(input())
x = int(input())
ans = 0
for i in range(a + 1):
  for j in range(b + 1):
    ts = i * 500 + j * 100
    if x - ts >= 0 and (x - ts) % 50 == 0 and (x - ts) // 50 <= c:
      ans += 1
print(ans)

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

// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0257

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	int i = (a << 2) + (b << 1) + c;
	if (i == 1 || i == 6) cout << "Open";
	else cout << "Close";
	cout << endl;
	return 0;
}

Measured memory_bytes: 1156
S = input()[::-1]

for i in range(len(S)):
    # print(len(S))
    # print(S[0:len(S)])
    if (i == 0):
        S = S[1:]
        continue
    if (len(S) % 2 == 0):
        if (S[0:len(S) // 2] == S[len(S) // 2:]):
            print(len(S))
            break
        else:
            S = S[1:]
    else:
        S = S[1:]


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

#include <math.h>
#include <stdlib.h>


#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

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

//INT_MAX	2,147,483,647 = 2*1.0e9

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int N; cin >> N;

    vector<int> B(N-1);
    for(int i = 0; i < N-1; i++) cin >> B[i];

    vector<int> A(N);
    A[0] = B[0];
    A[N-1] = B[N-2];
    for(int i = 1; i < N-1; i++){
        A[i] = min(B[i], B[i-1]);
    }
    int ans = 0;
    for(int i = 0; i < N; i++) ans += A[i];

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <algorithm>
#include <queue>
using namespace std;
int main(){
	int A, B, C, D, E, F; 
	cin >> A >> B >> C >> D >> E >> F; 
	int total = 100 * A; int sugar = 0; 
	for(int a = 0; a <= 30; a++){
		for(int b = 0; b <= 15; b++){
			int water = a * A + b * B; 
			if(100 * water > F) break; 
			for(int c = 0; c <= 3000; c++){
				for(int d = 0; d <= 1500; d++){
					int sato = c * C + d * D; 
					if(100 * water + sato > F) break; 
					if(sato <= water * E && sugar * (sato + 100 * water) < total * sato){
						sugar = sato; total = sato + 100 * water;
					}
				}
			}
		}
	}
	cout << total << " " << sugar << endl; 
}

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

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (int64_t)(n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

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

  using P = pair<int, int>;
  vector<P> students(N), checkpoints(M);
  rep(i, N) { cin >> students[i].first >> students[i].second; }
  rep(i, M) { cin >> checkpoints[i].first >> checkpoints[i].second; }

  rep(i, N) {
    int x, y;
    tie(x, y) = students[i];
    P result = P(1'000'000'000, 0);
    rep(j, M) {
      int z, w;
      tie(z, w) = checkpoints[j];
      result = min(result, P(abs(x - z) + abs(y - w), j));
    }
    cout << result.second + 1 << "\n";
  }
  return 0;
}

Measured memory_bytes: 3624
def main(argv)
  n = gets.chomp.to_i
  
  c = 0
  
  (1..n).each do |i|
    if (i.to_s.size % 2) == 1 then
      c += 1
    end
  end
  
  puts c.to_s
end

if self.to_s == 'main' then
  main(ARGV)
end

Measured memory_bytes: 1788
N,M = map(int,input().split())
ans = 0
if N == 3:
  ans += 100000
if M == 3:
  ans += 100000
if N == 2:
  ans += 200000
if M == 2:
  ans += 200000
if N == 1:
  ans += 300000
if M == 1:
  ans += 300000
if N == 1 and M == 1:
  ans += 400000
print(ans)

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

int main(void){
  char c;
  scanf("%c", &c);
  if(c=='S'){
    printf("Cloudy");
  }else if(c=='C'){
    printf("Rainy");
  }else if(c=='R'){
    printf("Sunny");
  }
  return 0;
}
  

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <functional>
#include <stack>
#include <numeric>
typedef long long ll;
using namespace std;
const int MOD = (int)1e9 + 7;
const ll INF = (ll)1e18 + 7;
#define int long long
#define vint vector<int>
#define pint pair<int,int>
#define pb(a) push_back(a)
#define all(v) v.begin(),v.end()
#define dbg(x) cerr << #x << " = " << (x) << endl
#define yn(b) cout << ((b) ? "Yes" : "No") << endl
#define YN(b) cout << ((b) ? "YES" : "NO") << endl

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

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

	int N, M;
	cin >> N >> M;
	vector<pint> D(N);

	for(int i = 0; i < N; i++)
	{
		cin >> D[i].first >> D[i].second;
	}
	

	sort(all(D));

	int i = 0;
	int now = 0;
	int ans = 0;
	while(1){
		if(now+D[i].second<M){
			ans += (D[i].first * D[i].second);
			now += D[i].second;
		}else{
			ans += (M - now) * D[i].first;
			break;
		}
		i++;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1792
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<vector>
#define ll long long
#define inf 0x3f3f3f3f
#define mod 1000000007
#define maxn 200010
inline ll read()
{
	ll x=0; char c=getchar(),f=1;
	for(;c<'0'||'9'<c;c=getchar())if(c=='-')f=-1;
	for(;'0'<=c&&c<='9';c=getchar())x=x*10+c-'0';
	return x*f;
}
inline void write(ll x)
{
	static char buf[20];
	int len=0;
	if(x<0)putchar('-'),x=-x;
	for(;x;x/=10)buf[len++]=x%10+'0';
	if(!len)putchar('0');
	else while(len)putchar(buf[--len]);
}
inline void writesp(ll x){write(x); putchar(' ');}
inline void writeln(ll x){write(x); putchar('\n');}
int p[maxn],vis[maxn],col[maxn],mark[maxn],dep[maxn],rt[maxn],deg[maxn];
int len[maxn],dis[maxn];
int cnt[maxn],f[maxn];
std::vector<int>a;
int n,tot;
int main()
{
	// freopen("agc008E.in","r",stdin);
	// freopen("agc008E.out","w",stdout);
	n=read();
	for(int i=1;i<=n;i++)
		p[i]=read();
	for(int i=1;i<=n;i++)
		if(!vis[i]){
			int now=i;
			while(!vis[now]){
				a.push_back(now); vis[now]=1;
				now=p[now];
			}
			if(col[now]){
				int sz=a.size();
				for(int j=sz-1;j>=0;j--)
					col[a[j]]=col[now],rt[a[j]]=rt[now],dep[a[j]]=dep[now]+(sz-j);
			}
			else{
				int sz=a.size(),flag=0;
				++tot;
				for(int j=sz-1;j>=0;j--){
					col[a[j]]=tot;
					if(!flag)mark[a[j]]=1,rt[a[j]]=a[j],dep[a[j]]=0;
					else rt[a[j]]=now,dep[a[j]]=dep[a[j+1]]+1;
					flag|=(a[j]==now);
				}
			}
			a.clear();
		}
	for(int i=1;i<=n;i++)
		if(!mark[i])++deg[p[i]];
	for(int i=1;i<=n;i++)
		if(deg[i]>=2){
			puts("0"); return 0;
		}
	for(int i=1;i<=n;i++)
		len[rt[i]]=std::max(len[rt[i]],dep[i]);
	memset(vis,0,sizeof(vis));
	ll ans=1;
	for(int i=1;i<=n;i++)
		if(mark[i]&&!vis[i]){
			a.push_back(i); vis[i]=1;
			int now=p[i];
			while(now!=i){
				a.push_back(now); vis[now]=1;
				now=p[now];
			}
			int flag=0,sz=a.size();
			for(int j=0;j<sz;j++)
				if(len[a[j]]){
					flag=1; break;
				}
			if(flag){
				int last=-1,first=-1;
				for(int j=0;j<sz;j++)
					if(len[a[j]]){
						if(~first)dis[a[j]]=j-last;
						else first=j;
						last=j;
					}
				dis[a[first]]=first+sz-last;
				for(int j=0;j<sz;j++)
					if(len[a[j]]){
						if(len[a[j]]<dis[a[j]])ans=ans*2%mod;
						else if(len[a[j]]>dis[a[j]]){
							puts("0"); return 0;
						}
					}
			}
			else ++cnt[sz];
			a.clear();
		}
	for(int i=1;i<=n;i++){
		int w=((i&1)&&(i>1))?2:1;
		f[0]=1; f[1]=w;
		for(int j=2;j<=cnt[i];j++)
			f[j]=(f[j-1]*w+(ll)(j-1)*f[j-2]%mod*i)%mod;
		ans=ans*f[cnt[i]]%mod;
	}
	writeln(ans);
	return 0;
}

Measured memory_bytes: 7164
n = int(input())
def dfs(s):
        if int(s) > n:
                return 0
        ret = 0
        if s.count('7')>0 and s.count('5')>0 and s.count('3')>0:
            ret = 1
        for c in '753':
                ret += dfs(s + c)
        return ret
print(dfs('0'))


Measured memory_bytes: 50396
#include<iostream>


#define MAX 100005
#define ll long long 
using namespace std;

int a[MAX],b[MAX];
int main( )
{
	int n;
	while(cin >> n){
		for(int i = 0; i < n; cin >> a[i++]);
		for(int i = 0; i < n; cin >> b[i++]);
		ll time = 0;
		for(int i = 0; i < n; i++){
			if(a[i] < b[i]){
				time += (b[i] - a[i])/2;
			}
			if(a[i] > b[i]){
				time -= a[i] - b[i];
			}
		}
		if(time >= 0)
			cout << "Yes" << endl;
		else
			cout << "No" << endl;
	}
}




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

class Program
{
    static void Main(string[] args)
    {
        int[] NK = ReadLineParseIntArray();
        int N = NK[0];
        int K = NK[1];

        long ans = 0;
        long a = N / K;
        ans = a * a * a;
        if(K % 2 == 0)
        {
            a = 2 * N / K - a;
            ans += a * a * a;
        }
        WriteLine(ans);
    }
    static int ReadLineParseInt() => int.Parse(ReadLine());
    static int[] ReadLineParseIntArray() => ReadLine().Split(' ').Select(int.Parse).ToArray();
}

Measured memory_bytes: 11348