akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vvvi = vector<vector<vector<int>>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REV(c) reverse(ALL(c))
#define sz(v) (int)v.size()
#define endl '\n'
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;}
template<class T> inline void prn(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << ' ';}
template<class T> inline void printv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << (i == n - 1 ? endl : ' ');}
template<class T> inline void printvv(vector<vector<T>>& v) {for (auto u : v) printv(u);}
template<class T> inline void printlnv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << endl;}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
 
void solve();
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

void solve() {
    int n;
    cin >> n;
    vi a(n * n);
    REP(i, n * n) {
        cin >> a[i];
        a[i]--;
    }
    vvi s(n, vi(n));
    vector<vector<bool>> b(n, vector<bool>(n, false));
    REP(i, n) REP(j, n) {
        s[i][j] = min({i, j, n - 1 - i, n - 1 - j});
    }
    int ans = 0;
    REP(i, n * n) {
        ans += s[a[i] / n][a[i] % n];
        deque<pair<int, int>> q;
        q.emplace_back(a[i] / n, a[i] % n);
        b[a[i] / n][a[i] % n] = true;
        while (!q.empty()) {
            auto p = q.front(); q.pop_front();
            int r = p.first;
            int c = p.second;
            int cur = s[r][c];
            if (r != 0) {
                if (chmin(s[r - 1][c], s[r][c] + (b[r][c] ? 0 : 1))) q.emplace_back(r - 1, c);
            }
            if (r != n - 1) {
                if (chmin(s[r + 1][c], s[r][c] + (b[r][c] ? 0 : 1))) q.emplace_back(r + 1, c);
            }
            if (c != 0) {
                if (chmin(s[r][c - 1], s[r][c] + (b[r][c] ? 0 : 1))) q.emplace_back(r, c - 1);
            }
            if (c != n - 1) {
                if (chmin(s[r][c + 1], s[r][c] + (b[r][c] ? 0 : 1))) q.emplace_back(r, c + 1);
            }
        }
        // printvv(s); cout << endl;
        // printvv(b);
    }
    cout << ans << endl;
}


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

#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define endl "\n"
#define ll long long
#define ld long double
#define l_b lower_bound
#define u_b upper_bound
#define vi vector<int>
#define vll vector<ll>
#define pii pair<int,int>
#define pll pair<ll, ll>
#define vpii vector<pii>
#define vpll vector<pll>
#define heap priority_queue
#define umap unordered_map
#define sz(a) int((a).size())
#define all(c) (c).begin(),(c).end()
#define test() ll t;cin>>t;while(t--)
#define mset(a,x) memset(a,x,sizeof(a))
#define rep(i,a,n) for(ll i = a; i < n; ++i) 
#define fastIO ios_base::sync_with_stdio(0);

const int inf = 1e9;
const int mod = 1e9 + 7;
const int maxn = 1e5 + 5;

ll dp[3][maxn];

int main() {
    // fastIO;
    ll n;
    cin >> n;
    ll a[n], b[n], c[n];
    rep(i, 0, n)
        cin >> a[i] >> b[i] >> c[i]; 
    dp[0][1] = a[0];
    dp[1][1] = b[0];
    dp[2][1] = c[0];
    rep(i, 2, n+1){
        dp[0][i] = a[i-1] + max(dp[1][i-1], dp[2][i-1]);
        dp[1][i] = b[i-1] + max(dp[0][i-1], dp[2][i-1]);
        dp[2][i] = c[i-1] + max(dp[0][i-1], dp[1][i-1]);
    }
    cout << max(dp[0][n],max(dp[1][n], dp[2][n]));
    return 0;
}

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

int main(){
    ll n; cin >> n;
    //vector<ll> a(n); rep(i,n) cin >> a[i];
    map<ll,ll> mp;
    rep(i,n){
        ll tmp; cin >> tmp;
        mp[tmp]++;
    }
    ll q; cin >> q;
    vector<ll> b(q),c(q); rep(i,q) cin >> b[i] >> c[i];

    ll sum = 0;
    for(auto x:mp) sum += x.first * x.second;

    for(long long i = 0; i < q; i++){
        sum = (sum - mp[b[i]] * b[i] + c[i] * mp[b[i]]);
        put(sum);
        mp[c[i]] += mp[b[i]];
        mp[b[i]] = 0;
    }
}

Measured memory_bytes: 10604
# -*- coding: utf-8 -*-
from collections import deque

s = list(input())
q = int(input())

a = deque(s)
reverse = False

for i in range(q):
    query = input()
    if query == "1":
        if reverse:
            reverse = False
        else:
            reverse = True
    else:
        x, q2_1, q2_2 = query.split()
        if q2_1 == "1":
            if reverse:
                a.append(q2_2)
            else:
                a.appendleft(q2_2)
        else:
            if reverse:
                a.appendleft(q2_2)
            else:
                a.append(q2_2)

s = list(a)
if reverse:
    s = s[::-1]
    print("".join(s))
else:
    print("".join(s))


Measured memory_bytes: 72952
import numpy as np
n, m = map(int,input().split())
l = [list(map(int, input().split())) for _ in range(n)]
l1 = [list(map(int,input().split())) for _ in range(m)]
#print(l)
#print(l1)
for i in l:
  l2 = []
  #print(i)
  for j in l1:
    #print(j)
    a = abs(i[0]-j[0]) + abs(i[1]-j[1])
    l2.append(a)
  print(np.argmin(l2)+1)

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

int main(){
  int n, r;
  while(cin >> n >> r && n){
    // cout << "n" << n << "r" << r <<endl;
    // ?±±?????????
    vector<int> fuda(n,0);
    for(size_t i=0; i<fuda.size(); i++) fuda[fuda.size()-1-i] = i+1;
    for(int i=0; i<r ; i++){
      int p, c;
      cin >> p >> c;
      // ?????£???????????????
      rotate(fuda.begin(),fuda.begin()+(p-1),fuda.begin()+(p-1)+c);  
      // for(size_t j=0 ; j<fuda.size(); j++) cout << fuda[j] << " ";
      // cout << endl;
    }
    cout << fuda[0] << endl;
  }
}

Measured memory_bytes: 3092
#include<iostream>
#define MAXN 100005
using namespace std;
struct box
{
	int num=1;
	bool flag;
}box[MAXN];

int main() {
	int N, M,fromNo,toNo,count=0;
	cin >> N >> M;
	box[N];
	box[1].flag = true;
	for (int i = 0; i < M; i++) {
		cin >> fromNo >> toNo;
		if (box[fromNo].flag == true)
			box[toNo].flag = true;
		box[fromNo].num--;
		box[toNo].num++;
		if (box[fromNo].num == 0)
			box[fromNo].flag = false;
	}
	for (int i = 1; i <= N; i++) {
		if (box[i].flag == true)
			count++;
	}
	cout << count << endl;
	//system("pause");
	return 0;
}

Measured memory_bytes: 1024
N = int(input())
A = list(map(int, input().split()))

# 全部+,-は無理だが、それ以外は任意に符号を決められる
plus = []
minus = []
for a in A:
  if a >= 0:
    plus.append(a)
  else:
    minus.append(a)
plus.sort()
plus.reverse()
minus.sort()
if len(plus) == 0:
  plus.append(minus.pop())
if len(minus) == 0:
  minus.append(plus.pop())

print(sum(plus) - sum(minus))

tmp = minus[0]
for p in plus[1:]:
  print(tmp, p)
  tmp = tmp - p
print(plus[0], tmp)
tmp = plus[0] - tmp
for m in minus[1:]:
  print(tmp, m)
  tmp = tmp - m

Measured memory_bytes: 14264
#include <bits/stdc++.h>
using namespace std;
int  i,n,j,k,mx,ans[200001];
string a[200001],b[200001];
int main() {
  cin >> n;
  for (i=1; i<=n; i++)
    cin >> a[i];
    a[n+1]="11111111111";
    j=1; k=1;
    sort(a,a+n+1);

    
    for (i=2; i<=n+1; i++)
        if (a[i]!=a[i-1])
    {
        ans[j]=k;

        j=j+k;
        k=1;
    }
    else
    k++;

    for (i=1; i<=n; i++)
        mx=max(mx,ans[i]);

        j=0;
    for (i=1; i<=n; i++)
        if (ans[i]==mx)
    {
        j++;
        b[j]=a[i];
    }
    sort (b,b+j+1);
    for (i=1; i<=j; i++)
        if (i==j)
        cout<<b[i];
    else
        cout<<b[i]<<endl;

}


Measured memory_bytes: 16872
#include <iostream>

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

using namespace std;

int64_t to_over0(int64_t n) { return n < 0 ? 0 : n; }

int64_t count_up(int64_t n) {
  if (n < 10) {
    return n + 1;
  } else {
    auto first = n % 10;
    auto second = (n / 10) % 10;
    if (second < first || first == 9) {
      auto t = count_up(n / 10);
      return t * 10 + to_over0(t % 10 - 1);
    } else {
      return n + 1;
    }
  }
}

int64_t lunlun(int k) {
  int64_t result = 0;
  rep(_, k) { result = count_up(result); }
  return result;
}

int main() {
  int k;
  cin >> k;
  cout << lunlun(k) << endl;
}


Measured memory_bytes: 256
//Radhe Radhe
#include<bits/stdc++.h>
#define godspeed  ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0);

#define ll long long
#define ld long double
#define fi first
#define se second
#define mp make_pair
#define rep1(i,a,b)    for(ll i=a; i<=b; i++)
#define repVect(i,n)    for(ll i=0; i<sum.size(); i++)
#define fixed cout.setf(ios::fixed);
#define Precise cout.precision(7);
#define yes cout<<"Yes"<<'\n'
#define no cout<<"No"<<'\n'
using namespace std;

int main()
{
    godspeed
    ll  i,j,k,l,n,a,b,ans=0;
    string s;
    cin>>n>>a>>b;
    cout<<min(n*a,b)<<endl;
    return 0;
}





Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;cin >> s;
  int n = s.size(),i,p = 0;
  for(i=0;i<n;i++){
    if(i%2==0) p -= s[i]=='p';
    else p += s[i]=='g';
  }
  cout << p << "\n";
}

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

using namespace std;
typedef long long ll;
#define int ll

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

#define REP(i,n) for(int i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
const int MAX_N = 100010;

int N;
vector<int> C, S, F;

int dfs(int i, int t) {
    //DBG("i: %lld t: %lld\n", i, t);
    if(i >= N - 1) { return 0; }

    int ret = 0;
    //DBG("C: %lld S: %lld F: %lld\n", C[i], S[i], F[i]);
    if(t <= S[i]) {
        int diff = S[i] - t;
        ret += dfs(i + 1, S[i] + C[i]) + diff + C[i];
    }
    else {
        int diff = F[i] - (t % F[i]);
        if(t % F[i] == 0) { diff = 0; }
        ret = dfs(i + 1, t + diff + C[i]) + diff + C[i];
    }
    return ret;
}

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

    cin >> N;
    C.resize(N-1);
    S.resize(N-1);
    F.resize(N-1);
    REP(i, N-1) {
        cin >> C[i] >> S[i] >> F[i];
    }

    REP(i, N) {
        int ans = dfs(i, 0);
        printf("%lld\n", ans);
    }

    return 0;
}

Measured memory_bytes: 256
//author rhythmicankur
                                                                  //god_is_almighty
#pragma GCC optimize("O3")
#pragma GCC target ("sse4")
#include<bits/stdc++.h>
#define f 		first
#define s 		second
#define int     long long
#define ll      int
#define ld 		long double
#define pb 		push_back
#define eb 		emplace_back
#define mk 		make_pair
#define vi 		vector<int>
#define pii 		pair<int,int>
#define pip             pair<int,pii>
#define vpi 		vector<pii>
#define sbcount(x) __builtin_popcountll(x)
#define REP(i,n) for (int i = 1; i <= n; i++)
#define trav(a, x)      for(auto& a : x)
#define all(x)          x.begin(), x.end()
#define fill(a,val)	memset(a,val,sizeof(a))
#define 	PI acos(-1)
#define coud(a,b) cout<<fixed << setprecision((b)) << (a) <<endl
#define M1 	998244353
#define M2 	1000000007
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;

template<typename T> T gcd(T a,T b) { if(a==0) return b; return gcd(b%a,a); } 
#define test4(x,y,z,a) 		    cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<"  |  "<<#a<<": "<<a<<endl;
#define test1(x)                cerr<<#x<<": "<<x<<endl
#define test2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define test3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
ll power(ll a,ll b,ll m=M2){ll answer=1;while(b){if(b&1)answer=(answer*a)%m;b/=2;a=(a*a)%m;}return answer;}
using namespace std;
void ctrl(){cout<<"Control"<<endl;}
int make_num(string p){stringstream geek(p); int x = 0; geek >> x;return x;}
string make_str(int x){ostringstream str1; str1 << x; string geek = str1.str(); return geek;}
int A,B;


signed main()
{	ios::sync_with_stdio(0);
	cin.tie(0); 
	cin.exceptions(cin.failbit);
	
    int x;
    cin>>x;
    int cnt = 3982;
    unordered_map<int,int>mp;
    for(int i=-cnt;i<=cnt;i++)
    {
        int xt = 1LL*i*i*i*i*i;
        mp[xt]=i;
    }
    for(int i=-cnt;i<=cnt;i++)
    {
        int xt = 1LL*i*i*i*i*i;
        if(mp[xt+x])
        {
            A=mp[xt+x];
            B=i;
        }
    }
    if(x==0)
    {
        A=0,B=0;
    }
    else if(mp[x])
    {
        A=mp[x];
        B=0;
    }
    else if(mp[-x])
    {
        A=0;
        B=mp[-x];
    }
    cout<<A<<" "<<B;

return 0;
}

Measured memory_bytes: 4236
package main

import (
	"fmt"
	"math"
)

func main() {
	var n int
	fmt.Scanf("%d", &n)

	xs, ys := []int{}, []int{}

	for i := 0; i < n; i++ {
		var x, y int
		fmt.Scanf("%d %d", &x, &y)
		xs = append(xs, x)
		ys = append(ys, y)
	}

	sum := 0.0
	routes := generateRoutes(n)
	for _, route := range routes {
		sum += distance(route, xs, ys)
	}

	fmt.Printf("%f\n", sum/float64(len(routes)))

}

func distance(route, xs, ys []int) float64 {
	d := 0.0
	for i := 0; i < len(route)-1; i++ {
		from := route[i]
		to := route[i+1]
		xd := float64(xs[to] - xs[from])
		yd := float64(ys[to] - ys[from])
		d += math.Sqrt(xd*xd + yd*yd)
	}
	return d
}

func generateRoutes(n int) [][]int {
	towns := map[int]struct{}{}
	for i := 0; i < n; i++ {
		towns[i] = struct{}{}
	}
	return generatePerm(towns)
}

func generatePerm(unused map[int]struct{}) [][]int {

	if len(unused) <= 1 {
		result := [][]int{}
		for i, _ := range unused {
			result = append(result, []int{i})
		}
		return result
	}

	result := [][]int{}
	for i, _ := range unused {
		recUnused := map[int]struct{}{}
		for j, _ := range unused {
			if j != i {
				recUnused[j] = struct{}{}
			}
		}

		for _, js := range generatePerm(recUnused) {
			result = append(result, append(js, i))
		}
	}

	return result
}


Measured memory_bytes: 11428
w=input()
list=[]
c=0
while True:
    t=input()
    if t=='END_OF_TEXT':
        break
    else:
        t=t.lower()
        
        list=t.split()
        
        for i in range(len(list)):
            if list[i]==w:
                c=c+1
print(c)



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

// iterator
#define REP(i,init, n) for(lli i=init;i<n;i++)
#define REPE(i,init, n) for(lli i=init;i<=n;i++)
#define REPIT(it,container) for(auto it = container.begin(); it != container.end(); it++)
#define REPIT_R(it,container) for(auto it = container.rbegin(); it != container.rend(); it++)

// input
#define cin1(x)             cin >> x
#define cin2(x, y)          cin >> x >> y
#define cin3(x, y, z)       cin >> x >> y >> z
#define ncin1(n, x)         REP(i, 0, n) {cin1(x[i]);}
#define ncin2(n, x, y)      REP(i, 0, n) {cin2(x[i], y[i]);}
#define ncin3(n, x, y, z)   REP(i, 0, n) {cin3(x[i], y[i], z[i]);}

// output
#define cout1(x)            cout << #x << ": " << x << endl;
#define ncout1(n, x)        REP(i, 0, n) {cout << #x << "[" << i << "]: "<< x[i] << endl;}

// sort
#define sort_r(x, y)        sort(x, y, greater<lli>()); // 降順(5,4,3,,,)

#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

typedef long long int lli;
typedef pair<lli, lli> P;

int main() {
    lli n, a, b;
    cin3(n, a, b);
    lli h[n];
    ncin1(n, h);

    lli ans = 0;
    sort_r(h, h+n);

    lli max_num = (h[0] + b - 1) / b;

    lli target = 1;
    lli r_bound = max_num;
    lli l_bound = 0;
    while (true) {
        // target でいけるのかどうかチェック
        bool is_ok = true;
        lli need_cnt = 0;
        REP(i, 0, n) {
            lli rest = h[i] - target * b;
            if (rest <= 0)
                break;
            need_cnt += (rest+a-b-1) / (a-b);
            if (need_cnt > target) {
                is_ok = false;
                break;
            }
        }

        if (is_ok) {
            r_bound = target;
        }
        else {
            l_bound = target;
        }
        lli next = (l_bound + r_bound) / 2;
        if (next == l_bound) {
            if (is_ok)
                ans = target;
            else
                ans = target + 1;
            break;
        }
        target = next;
    }
    //while (true) {
    //    lli top = que.top();
    //    if (top <= x)
    //        break;
    //    que.pop();
    //    que.push(top - a + b);
    //    x += b;
    //    ans++;
    //}
    cout << ans << endl;
}


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

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

    int d;
    for (int i = 0; i < k; i++)
    {
        scanf("%d", &d);
        for (int j = 0; j < d; j++)
        {
            int a;
            scanf("%d", &a);
            data[a - 1]++;
        }
    }

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

    printf("%d", count);
}

Measured memory_bytes: 1732
# https://atcoder.jp/contests/abc073/tasks/abc073_c

import itertools
import collections
import bisect

def main():
    N = int(input())
    A = [int(input()) for _ in range(N)]
    c = collections.Counter(A)

    ans = 0
    for pair in c.items():
        if pair[1] % 2 == 1:
            ans += 1
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 16628
#include<bits/stdc++.h>
using namespace std;
#define ll int64_t
int main()
{
    string s;cin>>s;
ll k=((int)s[0]-48)*10+s[1]-48;
ll l=((int)s[2]-48)*10+s[3]-48;
if(k<=12 && k>=1)
{
    if(l<=12 && l>=1)
        cout<<"AMBIGUOUS";
    else
        cout<<"MMYY";
}
else
{
    if(l<=12 && l>=1)
        cout<<"YYMM";
    else
        cout<<"NA";
}
}



Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
class Program
{
    public static bool f = false, t = true;
    static void Main(string[] args)
    {
        int n = Read.Int();
        int[] a = Read.ints();
        int[] b = Read.ints();
        int max = int.MinValue;
        for (int i = 0; i < n; i++)
        {
            int thisd = 0;
            for (int j1 = 0; j1 <= i; j1++)
            {
                thisd += a[j1];
            }
            for (int j2 = i; j2 < n; j2++)
            {
                thisd += b[j2];
            }
            max = Math.Max(max,thisd);
        }
        Console.WriteLine(max);
        Console.ReadLine();
    }
    public static long gcd(long a, long b)
    {
        while (true)
        {
            if (a == 0) { return b; }
            if (b == 0) { return a; }
            if (a > b) { a -= b; }
            else { b -= a; }
        }
    }
    public static long lcm(long a, long b) { return a / gcd(a, b) * b; }
    public static bool IsPrime(int num)
    {
        if (num < 2) return false;
        else if (num == 2) return true;
        else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

        double sqrtNum = Math.Sqrt(num);
        for (int i = 3; i <= sqrtNum; i += 2)
        {
            if (num % i == 0)
            {
                // 素数ではない
                return false;
            }
        }

        // 素数である
        return true;
    }
}
public static class Read
{
    public static void outl(string n = "") { Console.WriteLine(n); return; }
    public static long Long() { return long.Parse(Console.ReadLine()); }
    public static long[] longs() { return Console.ReadLine().Split().Select(long.Parse).ToArray(); }
    public static int Int() { return int.Parse(Console.ReadLine()); }
    public static int[] ints() { return Console.ReadLine().Split().Select(int.Parse).ToArray(); }
    public static string Str() { return Console.ReadLine(); }
    public static string[] Strs() { return Console.ReadLine().Split(); }
}

Measured memory_bytes: 13396
S, T = input().strip(), input().strip()
ds, dt = {}, {}

for s, t in zip(S, T):
    if s not in ds or ds[s] == t:
        ds[s] = t
    else:
        print('No')
        exit()
    if t not in dt or dt[t] == s:
        dt[t] = s
    else:
        print('No')
        exit()
print('Yes')

Measured memory_bytes: 3632
import sys
from collections import defaultdict
readline = sys.stdin.buffer.readline
# sys.setrecursionlimit(10**5)


def geta(fn=lambda s: s.decode()):
    return map(fn, readline().split())


def gete(fn=lambda s: s.decode()):
    return fn(readline().rstrip())


def main():
    a, b, k = geta(int)

    if a >= k:
        print(a - k, b)
    elif b >= k - a:
        print(0, b - k + a)
    else:
        print(0, 0)


if __name__ == "__main__":
    main()

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

const int inf=1000000005;

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

	int n;cin>>n;
	vector<pair<int ,int> >  lr;
	int mx=-inf,mn=inf;
	for(int i=0;i<n;i++){
		int l,r;cin>>l>>r;
		l--;
		mx=max(mx,l);
		mn=min(mn,r);
		lr.emplace_back(l,r);
	}

	int ans=0;
	for(auto z:lr){
		ans=max(ans,max(int(0),mn-mx)+z.second-z.first);
	}
	vector<pair<int,int> > t;
	for(int i=0;i<n;i++){
		int a=max(int(0),mn-lr[i].first);
		int b=max(int(0),lr[i].second-mx);
		t.emplace_back(b,-a);
	}
	sort(t.begin(),t.end());
	int w=inf;
	for(int i=0;i<n;i++){
		auto z=t[i];
		z.second=-z.second;
		if(i)
			ans=max(ans,w+z.first);
		w=min(w,z.second);
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 2676
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Scan()
	n, _ := strconv.Atoi(sc.Text())
	var t int
	max, min := 0, 1000000001
	for i := 0; i < n; i++ {
		sc.Scan()
		t, _ = strconv.Atoi(sc.Text())
		if t > max {
			max = t
		}
		if t < min {
			min = t
		}
	}
	fmt.Println(max - min)
}


Measured memory_bytes: 640
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
typedef long long LL;
const int MaxN = 1e5;

int n, m;
int vis[MaxN + 5];
int main()
{
	while(scanf("%d %d", &n, &m) != EOF)
	{
		for(int i = 1; i <= m; i++)
		{
			int a, b;
			scanf("%d %d", &a, &b);
			vis[a]++;
			vis[b]++;
		}
		bool f = 1;
		for(int i = 1; i <= n; i++)
		{
			if(vis[i] & 1)
			{
				f = 0;
				break;
			}
		}
		if(f) printf("YES\n");
		else printf("NO\n");
		memset(vis, 0, sizeof(vis));
	}
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,M,K;
    cin >> N >> M >> K;
    vec<ll> A(N),B(M),SA(N+1),SB(M+1);
    for(int i=0;i<N;i++){
        cin >> A[i];
        SA[i+1] = SA[i]+A[i];
    }
    for(int i=0;i<M;i++){
        cin >> B[i];
        SB[i+1] = SB[i]+B[i];
    }
    int ans = 0;
    for(int i=0;i<=N;i++){
        ll n = K-SA[i];
        if(n<0) continue;
        int id = upper_bound(SB.begin(),SB.end(),n)-SB.begin();
        ans = max(ans,i+id-1);
    }
    cout << ans << "\n";
}

Measured memory_bytes: 9512
using System;

namespace ABC076_B
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var k = int.Parse(Console.ReadLine());
            var a = 1;
            for (int i = 0; i < n; i++)
                a = a + k < a * 2 ? a + k : a * 2;
            Console.WriteLine(a);
        }
    }
}


Measured memory_bytes: 13140
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func main() {
	/*/TODO:!!!!!!!テスト用!!!!!!!!!
	sc = bufio.NewScanner(strings.NewReader(`

						`))
	//TODO:!!!!!!!テスト用!!!!!!!!!*/

	buf := make([]byte, 1024*1024)
	sc.Buffer(buf, bufio.MaxScanTokenSize)
	sc.Split(bufio.ScanWords)
	defer out.Flush() // !!!!caution!!!! you must use Fprint(out, ) not Print()
	/* --- code --- */
	//fmt.Fprintln(out, "[DEBUG]", time.Now())

	n := nextInt()
	ans := 1

	b := nextInt()
	f := 0

	for i := 1; i < n; i++ {
		a := nextInt()
		if (f == -1 && b >= a) || (f == 1 && b <= a) {
		} else if f == 0 {
			if b > a {
				f = -1
			} else if b < a {
				f = 1
			}
		} else {
			f = 0
			ans++
		}
		b = a
	}

	//fmt.Fprintln(out, "[DEBUG]]", a)
	fmt.Fprintln(out, ans)
}

//------------------------------------------------------------------------------

// -*-*-*-*-*-*-*-*-
// * I/O utilities *
// -*-*-*-*-*-*-*-*-

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

func nextFloat64() float64 {
	a, _ := strconv.ParseFloat(next(), 64)
	return a
}

func nextInts(n int) []int {
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}
func nextFloats(n int) []float64 {
	ret := make([]float64, n)
	for i := 0; i < n; i++ {
		ret[i] = nextFloat64()
	}
	return ret
}
func nextStrings(n int) []string {
	ret := make([]string, n)
	for i := 0; i < n; i++ {
		ret[i] = next()
	}
	return ret
}

func chars(s string) []string {
	ret := make([]string, len([]rune(s)))
	for i, v := range []rune(s) {
		ret[i] = string(v)
	}
	return ret
}

func absInt(x int) int {
	return int(math.Abs(float64(x)))
}
func minInt(x, y int) int {
	if x < y {
		return x
	}
	return y
}
func maxInt(x, y int) int {
	if x > y {
		return x
	}
	return y
}
func log10(x int) float64 {
	return math.Log10(float64(x))
}


Measured memory_bytes: 3328
#include <stdio.h>

int main(void)
{
    int n;
    char card[4][13] = {0};
    int i, j;
    char *s = "SHCD";

    scanf("%d", &n);
    while (n-- > 0){
        char soot;
        int num;

        scanf(" %c %d", &soot, &num);
        switch (soot){
            case 'S': card[0][num - 1] = 1; break;
            case 'H': card[1][num - 1] = 1; break;
            case 'C': card[2][num - 1] = 1; break;
            case 'D': card[3][num - 1] = 1; break;
        }
    }
    for (i = 0; i < 4; i++){
        for (j = 0; j < 13; j++){
            if (!card[i][j]){
                printf("%c %d\n", s[i], j + 1);
            }
        }
    }

    return 0;
}

Measured memory_bytes: 596
#include <iostream>

int main()
{
  float Distance = 0;
  float Speed = 0;
  float Time = 0;
  
  std::cin >> Distance >> Time >> Speed;
  
  if(Distance <= Time * Speed)
  {
    std::cout << "Yes" << std::endl;
  }
  else 
  {
    std::cout << "No" << std::endl;
  }
  return 0;
}

Measured memory_bytes: 3688
<?php
    $line1 = (trim(fgets(STDIN)));
    $line2 = (trim(fgets(STDIN)));
    
    //プラス1文字かどうか
    if(strlen($line1) != (strlen($line2) - 1)){
        echo "No\n";
        exit;
    }
    
    $line_a = substr($line2,0,strlen($line1));
    
    if($line1 == $line_a){
        echo "Yes\n";
    }else{
        echo "No\n";
    }
    

?>

Measured memory_bytes: 16152
using System;

namespace ABC105
{
    class B
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());

            if (N % 4 == 0 || N % 7 == 0) { Console.WriteLine("Yes"); return; }

            while (6 < N)
            {
                N -= 4;
                if (N % 7 == 0) { Console.WriteLine("Yes"); return; }
            }
            Console.WriteLine("No");
        }
    }
}


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

using namespace std;

int N;
unsigned int PipeTotalLen;
unsigned int JointLength[65000];


bool cmp(const unsigned int j1, const unsigned int j2) {
	return j1 > j2;
}

void solve() {
	unsigned int maxMoney;

	sort(JointLength + 1, JointLength + N, cmp);
	maxMoney = PipeTotalLen*N;
	for (int i = 1; i < N; ++i) {
		JointLength[i] += JointLength[i - 1];
		maxMoney = max(maxMoney, (PipeTotalLen + JointLength[i])*(N - i));
	}

	cout << maxMoney << endl;
}

int main() {
	unsigned int pipeLen;

	while (cin >> N, N) {
		PipeTotalLen = 0;
		for (int i = 0; i < N; ++i) {
			cin >> pipeLen;
			PipeTotalLen += pipeLen;
		}
		JointLength[0] = 0;
		for (int i = 1; i < N; ++i) {
			cin >> JointLength[i];
		}
		solve();
	}
	

}



Measured memory_bytes: 3380
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#pragma warning(disable:4996)
#include <stdio.h>
#include <string>
#include <stdlib.h>
#include <math.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <functional>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <list>
#include <set>
#include <map>
#include <iomanip> 
#include <ctime>
#include <numeric>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

const double PI = 3.14159265358979323846;


int main(int argc, char *args[]) {
	int n; cin >> n;
	rep(i, n) {
		int a; cin >> a;
		if (a % 2 == 0) {
			if (a % 5 != 0 && a % 3 != 0) {
				cout << "DENIED" << endl;
				return 0;
			}
		}
	}
	cout << "APPROVED" << endl;
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<cstring>
#define RG register
using namespace std;
const int N=2e5+10;
int n,x,ans[N];
bool vis[N];
template<typename I> inline void read(I &ot){
	I ch=getchar(), x=0, f=1;
	while(ch<'0' || ch>'9'){if(ch=='-') f=-1; ch=getchar();	}
	while(ch>='0' && ch<='9'){x=x*10+ch-'0'; ch=getchar();	}
	ot=x*f;}
template<typename I, typename... U> inline void read(I &x,U&... y){read(x); read(y...);}
int main()
{ 
//	freopen("Median Pyramid Easy.in","r",stdin);
	//freopen(".out","w",stdout);
	read(n,x); n=2*n-1;
	if(x==1 || x==n) 
	{
		printf("No\n");
		return 0;
	}
	printf("Yes\n");
	ans[n/2]=x; vis[x]=1;
	if(x==n-1) 
	{
		ans[n/2+1]=n; ans[n/2+2]=x-1; ans[n/2-1]=x-2;
		vis[n]=vis[x-1]=vis[x-2]=1;
	}
	else
	{
		ans[n/2+1]=x-1; ans[n/2+2]=x+1; ans[n/2-1]=x+2;
		vis[x-1]=vis[x+1]=vis[x+2]=1;
	}
	for(int i=1,cnt=1;i<=n;i++)
	{
		if(ans[i]) 
		{
			printf("%d\n",ans[i]);
			continue;
		}
		while(vis[cnt]) cnt++;
		ans[i]=cnt++;
		printf("%d\n",ans[i]);
	}
	//fclose(stdin); fclose(stdout);
	return 0;
}


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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n);
  map<int, int> cnt;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    ++cnt[a[i]];
  }
  if (cnt.size() > 3) {
    cout << "No" << '\n';
    return 0;
  }
  for (auto a : cnt) {
    for (auto b : cnt) {
      int x = a.first, y = b.first, z = x ^ y;
      if (!cnt.count(z)) {
        continue;
      }
      map<int, int> cur;
      vector<int> c(n);
      c[0] = x, c[1] = y, c[2] = z;
      ++cur[x], ++cur[y], ++cur[z];
      bool bad = false;
      for (int i = 3; i < n; i++) {
        if (i % 3 == 0) {
          c[i] = x;
          ++cur[x];
          if (cur[x] > cnt[x]) {
            bad = true;
            break;
          }
        } else if (i % 3 == 1) {
          c[i] = y;
          ++cur[y];
          if (cur[y] > cnt[y]) {
            bad = true;
            break;
          }
        } else {
          c[i] = z;
          ++cur[z];
          if (cur[z] > cnt[z]) {
            bad = true;
            break;
          }
        }
      }
      for (int i = 0; i < n; i++) {
        if ((c[(i - 1 + n) % n] ^ c[(i + 1) % n]) != c[i]) {
          bad = true;
          break;
        }
      }
      if (!bad) {
        cout << "Yes" << '\n';
        return 0;
      }
    }
  }
  cout << "No" << '\n';
  return 0;
}


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

int main(){
    int x;
    cin >> x;
    int h, m, s;
    h = x / 3600;
    m = (x % 3600) / 60;
    s = x % 60;
    cout << h << ":" << m << ":" << s << endl;
}



Measured memory_bytes: 3112
h, w = map(int, input().split())
s = [list(input()) for i in range(h)]
for i in range(h - 1):
    for j in range(w - 1):
        if s[i][j] == "#" and s[i - 1][j] != "#" and s[i][j - 1] != "#" and s[i + 1][j] != "#" and s[i][j + 1] != "#":
            print("No")
            exit()
print("Yes")

Measured memory_bytes: 3064
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <cassert>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
const ll mod=1000000007;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
// head

const int N=101000;
int n,e,t;
ll dp[N],x[N];
struct node {
	ll s,fg;
}nd[4*N];
void upd(int p) {
	nd[p].s=min(nd[p+p].s,nd[p+p+1].s);
}
void setf(int p,ll v) {
	nd[p].fg+=v; nd[p].s+=v;
}
void build(int p,int l,int r) {
	nd[p].fg=0;
	if (l==r) {
	} else {
		int md=(l+r)>>1;
		build(p+p,l,md);
		build(p+p+1,md+1,r);
		upd(p);
	}
}
void push(int p) {
	if (nd[p].fg) {
		setf(p+p,nd[p].fg);
		setf(p+p+1,nd[p].fg);
		nd[p].fg=0;
	}
}
ll query(int p,int l,int r,int tl,int tr) {
	if (tl==l&&tr==r) return nd[p].s;
	else {
		push(p);
		int md=(l+r)>>1;
		if (tr<=md) return query(p+p,l,md,tl,tr);
		else if (tl>md) return query(p+p+1,md+1,r,tl,tr);
		else return min(query(p+p,l,md,tl,md),query(p+p+1,md+1,r,md+1,tr));
	}
}
void modify(int p,int l,int r,int tl,int tr,ll v) {
	if (tl>tr) return;
	if (tl==l&&tr==r) return setf(p,v);
	else {
		push(p);
		int md=(l+r)>>1;
		if (tr<=md) modify(p+p,l,md,tl,tr,v);
		else if (tl>md) modify(p+p+1,md+1,r,tl,tr,v);
		else modify(p+p,l,md,tl,md,v),modify(p+p+1,md+1,r,md+1,tr,v);
		upd(p);
	}
}

int main() {
	scanf("%d%d%d",&n,&e,&t);
	rep(i,1,n+1) scanf("%lld",x+i);
	int r=0;
	modify(1,0,n,0,0,t);
	rep(i,1,n+1) {
		dp[i]=1ll<<60;
		modify(1,0,n,0,r-1,3*(x[i]-x[i-1]));
		modify(1,0,n,r,i-1,x[i]-x[i-1]);
		while (2*(x[i]-x[r+1])>t) {
			modify(1,0,n,r,r,(2*(x[i]-x[r+1]))-t);
			r++;
		}
		dp[i]=query(1,0,n,0,i-1);
		modify(1,0,n,i,i,dp[i]+t);
	}
	printf("%lld\n",dp[n]+e-x[n]);
}


Measured memory_bytes: 5888
#include<cstdio>
#include<queue>
#include<iostream>
#include<algorithm>
#include<list>
#include<vector>
using namespace std;
vector<int>a;
int main() {
	int t,n;
	cin >> t;
	n = t;
	while (n--)
	{
		int temp;
		cin >> temp;
		a.push_back(temp);
	}
	cin >> n;
	while (n--)
	{
		int begin, m, end;//开始，e-m位移 结束
		cin >> begin >> m >> end;
		rotate(a.begin()+begin, a.begin()+m, a.begin()+end);
	}
	for (int i = 0; i < t; i++)
	{
		if (i != 0)
		{
			cout << " ";
		}
		cout << a[i];
	}
	cout << endl;
}




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

using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for (ll i = (ll)(n) - 1; i >= 0; i--)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1LL << 62)

#define PI (acos(-1))
#define print(x) cout << x << endl
 
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; }
typedef pair <ll,ll> P;
static const ll dy[4] = {0,1,0,-1}, dx[4] = {1,0,-1,0};

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

int main()
{
    ll H, W, K;
    cin >> H >> W >> K;
    vector<vector<ll>> s(H, vector<ll>(W));
    vector<vector<ll>> a(H, vector<ll>(W, 0));
    rep(i, H) {
        string t;
        cin >> t;
        rep(j, W) {
            s[i][j] = t[j] == '#';
        }
    }
    bool exist = false;
    ll num = 1;
    rep(i, H) {
        exist = false;
        ll pre = 0;
        rep(j, W) {
            if (s[i][j]) {
                exist = true;
                for(ll k = pre; k <= j; k++) {
                    a[i][k] = num;
                }
                pre = j+1;
                num++;
            } else if(exist && j == W-1) {
                for(ll k = pre; k <= j; k++) {
                    a[i][k] = num-1;
                }
            }
        }
    }
    rep(i, H){
        if (i == 0) continue;
        if (a[i][0] == 0) {
            rep(j, W) {
                a[i][j] = a[i-1][j];
            }
        }
    }

    repr(i, H){
        if (i == H-1) continue;
        if (a[i][0] == 0) {
            rep(j, W) {
                a[i][j] = a[i+1][j];
            }
        }
    }
    
    rep(i, H) print(a[i]);
    return 0;
}

Measured memory_bytes: 2176
<?php
while (true) {
    list($a, $operator, $b) = getInputExplodeBySpaces();
    echo calc($a, $operator, $b), PHP_EOL;
}
 
function getInputExplodeBySpaces()
{
    return explode(' ', trim(fgets(STDIN)));
}
 
function calc($a, $operator, $b)
{
    switch ($operator) {
        case '+':
            return addTwoNum($a, $b);
        case '-':
            return subTractTwoNum($a, $b);
        case '*':
            return multiplyTwoNum($a, $b);
        case '/':
            return divideTwoNumByFloorPoint($a, $b);
        case '?':
            exit;
    }
}
 
function addTwoNum($a, $b)
{
    return $a + $b;
}
 
function subTractTwoNum($a, $b)
{
    return $a - $b;
}
   
function multiplyTwoNum($a, $b)
{
    return $a * $b;
}
 
function divideTwoNumByFloorPoint($a, $b)
{
    return floor($a / $b);
}

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

#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define SORT_INV(c) sort((c).begin(), (c).end(), greater<int>())

#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG true
#define LL long long
#define MOD 1000000007

//cout << (c)?"Yay!":":(" << endl;

// sort(a.begin(), a.end(), std::greater<int>());
using namespace std;

int main()
{
    int a, b;
    cin >> a >> b;
    REP(i, 1, 100000)
    {
        int c, d;
        c = int(i * 0.08);
        d = int(i * 0.1);
        if (a == c && b == d)
        {
            cout << i << endl;
            return 0;
        }
    }

    cout << -1 << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define rrep(i,n) for(int i=(int)n-1;i>=0;--i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template<typename T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T& a,T b){if(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::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>::type fill_v(U& u,const V... v){for(auto& e:u)fill_v<T>(e,v...);}

int f(int x) {
    if (x == 0) return 0;
    return f(x % __builtin_popcount(x)) + 1;
}

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

    int n;
    string s;
    cin >> n >> s;
    vector<int> x(n);
    rep(i, n) x[i] = s[i] - '0';
    int pc = 0;
    rep(i, n) pc += x[i];
    
    vector<int> ans(n);
    rep(b, 2) {
        int npc = pc;
        if (b == 0) npc++; else npc--;
        if (npc <= 0) continue;
        int r0 = 0;
        rep(i, n) {
            r0 = (r0 * 2) % npc;
            r0 += x[i];
        }
        int k = 1;
        rrep(i, n) {
            if (x[i] == b) {
                int r = r0;
                if (b == 0) r = (r + k) % npc; else r = (r - k + npc) % npc;
                ans[i] = f(r) + 1;
            }
            k = (k * 2) % npc;
        }
    }
    rep(i, n) cout << ans[i] << endl;
}


Measured memory_bytes: 5168
#include <iostream>
#include <string>
#include <locale>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)

int main()
{
    while (1)
    {
        string x;
        long long ans = 0;
        cin >> x;
        if (x == "0")
            break;
        rep(i, x.length())
        {
            ans += (long long)(x[i] - '0');
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 3208
S = input()
n = len(S)
dp = [[0] * 13 for _ in range(n + 1)]
dp[0][0] = 1
MOD = 10 ** 9 + 7
for i in range(n):
    for j in range(13):
        if S[i] != "?":
            dp[i + 1][(j * 10 + int(S[i])) % 13] += dp[i][j]
        else:
            for k in range(10):
                dp[i + 1][(j * 10 + k) % 13] += dp[i][j]

    for j in range(13):
        dp[i + 1][j] %= MOD

print(dp[-1][5])


Measured memory_bytes: 95780
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long int ll;
static const int MAX_N = 2000;

int N;
ll A[MAX_N];
ll memo[MAX_N][2 * MAX_N];

ll memoize(int i, int j){
	if(memo[i][j] != -1) return memo[i][j];
	int i2 = (i == N - 1 ? 0 : i + 1);
	int j2 = (j == 0 ? N - 1 : j - 1);
	int itv = (i > j ? N + j - i : j - i);
	if((N - itv) % 2 == 1){
		if(i == j) return memo[i][j] = A[i];
		else return memo[i][j] = max(memoize(i2, j) + A[i], memoize(i, j2) + A[j]);
	}else{
		if(i == j) return memo[i][j] = 0LL;
		else if(A[i] > A[j]) return memo[i][j] = memoize(i2, j);
		else return memo[i][j] = memoize(i, j2);
	}
	return 0;
}

int main(){
	scanf("%d", &N);
	for(int i = 0; i < N; i++) scanf("%lld", &A[i]);
	fill(memo[0], memo[N], -1);
	for(int i = 0; i < N; i++){
		for(int j = 0; j < N; j++){
			memo[i][j] = memoize(i, j);
		}
	}
	ll res = 0LL;
	for(int i = 0; i < N; i++){
		for(int j = 0; j < N; j++){
			res = max(res, memo[i][j]);
		}
	}
	printf("%lld\n", res);
	return 0;
}



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

#define rep(i,s,t) for(int i = s; i < t; ++i)
#define per(i,s,t) for(int i = s; i > t; --i)

int const N = 100 * 1000 + 16;
int const M = 1000*1000*1000 + 7;

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

  ll q, h, s, d, n;
  cin >> q >> h >> s >> d >> n;
  ll one = min({4*q, 2*h, s});
  ll two = d;
  ll a = n/2;
  ll b = n&1;
  ll ans = min({n*one, one*b+two*a});
  cout << ans;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef pair<ll, ll> PP;
#define rep(i,n) for(ll i = 0; i < ll(n); i++)
#define all(v) v.begin() , v.end()
#define inputv(v,n) rep(i,n){\
    ll x;\
    cin>>x;\
    v.push_back(x);\
    }
const ll INF = 999999999999999;
const ll MOD = 1000000007;
ll a, b, c, d, e, f, p, t, x, y, z, q, m, n, r, h, k, w, l;
double ans = 0;
vector<PP> P;
void input() {
	cin >> x >> y;
}

ll gyaku(ll a) {
	ll bb = 1;
	ll beki[40];
	beki[0] = a;
	ll kk = MOD - 2;
	rep(i, 35) {
		beki[i + 1] = (beki[i] * beki[i]) % MOD;
	}
	for (ll i = 0; kk > 0; i++) {
		if (kk % 2 == 1)bb = (bb * beki[i]) % MOD;
		kk = kk / 2;
	}

	return bb;
}
ll nck(ll m, ll n) {
	vl kaijo(2000000);
	kaijo[0] = 1;
	rep(i, 1000010) {
		kaijo[i + 1] = (kaijo[i] * (i + 1)) % MOD;
	}
	return (kaijo[m] * gyaku((kaijo[m - n] * kaijo[n])%MOD)) % MOD;
}


void solve() {
	if ((x + y) % 3 != 0) {
		cout << 0 << endl;
		return;
	}

	k = (x + y) / 3;
	a = x - k;
	b = y - k;
	if (a < 0 || b < 0) {
		cout << 0 << endl;
		return;
	}

	cout << nck(a + b , a) << endl;
}

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

Measured memory_bytes: 15872
import java.util.*;
import java.util.stream.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int mod = (int)1e9 + 7;
        String s = sc.next();
        for (int i = 0; i < s.length(); i++) {
            if ((i % 2 == 0 && s.charAt(i) == 'L') || (i % 2 != 0 && s.charAt(i) == 'R')) {
                System.out.println("No");
                return;
            }
        }
        System.out.println("Yes");
    }

}


Measured memory_bytes: 21844
import sys

N = int(input())
A = list(map(int, input().split()))

s = 1
LIM = 10 ** 18
ret = -1
for a in A:
    if a == 0:
        print(0)
        sys.exit(0)
for a in A:
    s *= a
    if s > LIM:
        print(-1)
        sys.exit(0)
print(s)


Measured memory_bytes: 21792
def main():
    MOD = 10 ** 9 + 7

    N = int(input())

    # a:0,9なし
    # b:0あり
    # c:9あり
    # d:0,9あり
    a, b, c, d = 1, 0, 0, 0
    for i in range(N):
        a, b, c, d = (
            (a * 8) % MOD,
            (b * 9 + a) % MOD,
            (c * 9 + a) % MOD,
            (d * 10 + c + b) % MOD
        )

    print(d)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9180
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

const (
	initialBufSize = 100000
	maxBufSize     = 10000000
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wt = bufio.NewWriter(os.Stdout)
)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	i, _ := strconv.Atoi(next())
	return i
}

func nextInts(n int) []int {
	slice := make([]int, n)
	for i := 0; i < n; i++ {
		slice[i] = nextInt()
	}
	return slice
}

func puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}

func max(nums ...int) int {
	ret := nums[0]
	for _, v := range nums {
		if v > ret {
			ret = v
		}
	}
	return ret
}

// nまでの自然数の最小の素因数
func minFactors(n int) []int {
	mf := make([]int, n+1)
	mf[0], mf[1] = -1, -1
	for i := 2; i <= n; i++ {
		for j := 1; i*j <= n; j++ {
			if mf[i*j] == 0 {
				mf[i*j] = i
			}
		}
	}
	return mf
}

// 高速素因数分解
func primeFactors(a []int) []map[int]int {
	// 各数の素因数分解結果を入れるmap配列
	m := make([]map[int]int, len(a))
	for i := range m {
		m[i] = map[int]int{}
	}
	// 最小素因数テーブル
	mf := minFactors(max(a...))
	for i := range a {
		for j := a[i]; j > 1; j /= mf[j] {
			m[i][mf[j]]++
		}
	}
	return m
}

func primeFactor(n int) map[int]int {
	m := map[int]int{}
	for i := 2; i*i <= n; i++ {
		for n%i == 0 {
			m[i]++
			n /= i
		}
	}
	if n != 1 {
		m[n] = 1
	}
	return m
}

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	for a%b != 0 {
		a, b = b, a%b
	}
	return b
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, initialBufSize), maxBufSize)
	defer wt.Flush()

	n := nextInt()
	a := nextInts(n)

	pairwise := true
	pfs := primeFactors(a)
	fac := map[int]int{}
	for i := 0; i < n; i++ {
		for k := range pfs[i] {
			pairwise = pairwise && fac[k] == 0
			fac[k]++
		}
	}
	if pairwise {
		puts("pairwise coprime")
		return
	}

	G := a[0]
	for i := 1; i < n; i++ {
		G = gcd(G, a[i])
	}
	if G == 1 {
		puts("setwise coprime")
		return
	}

	puts("not coprime")
}


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

int main() {
  // ここにプログラムを追記
      string x;
      cin >> x;

      int s=0;
      for (int i=0; i<3 ; i++){
        if (x.at(i) == '1'){
          s++;}
        else {s +=0;
      }
      }
      cout << s << endl;
}


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

typedef long long ll;
const ll MOD = 1e9 + 7;
const ll inf = 1LL<<60;
const double eps = 1e-9;

typedef pair<ll, ll> P;

int main()
{
    int a, b;
    cin >> a >> b;
    int tmp = min(a, b), tmp1 = max(a, b);

    for (int i = 0; i < tmp1; i++) cout << tmp;
    return 0;
}



Measured memory_bytes: 256
x, n = map(int, input().split())
if n == 0:
    print(x)
else:
    p = set(list(map(int, input().split())))
    
    i = 0
    while(True):
        cand1 = x - i
        cand2 = x + i
        if cand1 not in p:
            print(cand1)
            break
        elif cand2 not in p:
            print(cand2)
            break
        i += 1

Measured memory_bytes: 9184