akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define reset(X) memset(X, 0, sizeof(X))
#define int long long
typedef long long ll;
#define pb push_back
#define se second
#define fi first
#define endl '\n'
#define all(X) X.begin(),X.end()

const int INF=1e18;
const int mod=1e9+7;
const int mod2=998244353;



#define REDN(a) int a;cin>>a;
#define REDL(a,n) int a[n];for(int i=0;i<n;i++) cin>>a[i];
#define REDA(a,n,m) int a[n][m];for(int i=0;i<n;i++)for(int j=0;j<m;j++) cin>>a[i][j];





int pow(int a, int b)
{
    int prod=1;
    int mult=a;
    while(b!=0)
    {
        if(b%2)
        {
            prod*=mult;
            prod%=mod2;
        }
        mult*=mult;
        mult%=mod2;
        b/=2;
    }
    return prod;
}
int mod_inv(int q, int mod)
{
    return pow(q, mod-2);
}




bool isPrime(int n)
{
    int k=sqrt(n);
    for(int i=2;i<=k;i++)
        if(n%i==0)
            return false;
    return true;
}

const int MAXN=4e5+10;
signed main()
{
    
    
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    #ifndef ONLINE_JUDGE
    if (fopen("INPUT.txt", "r")) {
        freopen ("INPUT.txt" , "r" , stdin);
        // freopen ("OUTPUT.txt" , "w" , stdout);
    }
    #endif
//---------------------------------------------------------------------------------------------------
    int x;
    cin>>x;
    while(!isPrime(x))
        x++;
    cout<<x;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

    char[] s = scanner.next().toCharArray();
    if (palindrome(s, 0, s.length) && palindrome(s, 0, s.length / 2) && palindrome(s, s.length / 2 + 1, s.length)) {
      System.out.println("Yes");
    } else {
      System.out.println("No");
    }
  }

  private static boolean palindrome(char[] s, int left, int right) {
    right--;
    while (left < right) {
      if (s[left] != s[right]) return false;
      left++;
      right--;
    }
    return true;
  }
}


Measured memory_bytes: 22996
# include <iostream>
# include <string>
using namespace std;
int main() {
    char x;
    cin>>x;
    if(x=='a'){
        cout<<"vowel";
    }
    else if(x=='e'){
        cout<<"vowel";
    }
    else if (x=='o'){
        cout<<"vowel";
    }
    else if(x=='u'){
        cout<<"vowel";
    }
    else if(x=='i'){
        cout<<"vowel";
    }
    else{
        cout<<"consonant";
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define BIG 1000000010
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
typedef long long int ll;


int main(){
  int n,a;
  cin>>n>>a;
  cout<<n*n-a<<endl;

  return 0;
}




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

int main(){

    int N, K;
    cin >> N >> K;
    vector<ll> A(N);
    for(int i=0; i<N; i++) cin >> A.at(i);

    vector<string> ans(N);

    int pos;
    bool flg = true;
    for(pos = K; pos<N; pos++){
        if(A.at(pos-K)>=A.at(pos)) ans.at(pos) = "No";
        else ans.at(pos) = "Yes";
    }

    for(int i=K; i<N; i++) cout << ans.at(i) << endl;
    return 0;
}

Measured memory_bytes: 11172
#include<cstdio>
using namespace std;
int n,m,q,a[501][501];
int main() {
	scanf("%d%d%d",&n,&m,&q);int l,r;
	for(int i=1;i<=m;++i) {scanf("%d%d",&l,&r);++a[l][r];}
	for(int i=1;i<=n;++i) for(int j=i;j<=n;++j) a[i][j]=a[i][j]+a[i][j-1];
	for(int i=1;i<=q;++i) {
		scanf("%d%d",&l,&r);int ans=0;
		for(int j=l;j<=r;++j) ans+=a[j][r];
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 1792
/*
　　　　　　 ＿＿
　　　　　／＞　　 フ
　　　　　| 　_　 _ l
　 　　　／` ミ＿xノ
　　 　 /　　　 　 |　見ちゃダメ〜
　　　 /　 ヽ　　 ﾉ　　
　 　 │　　|　|　|　　
　／￣|　　 |　|　|
　| (￣ヽ＿_ヽ_)__)
　＼二つ
*/

#include <bits/stdc++.h>
using namespace std;
#define SORT(a) sort((a).begin(), (a).end())
#define RSORT(a) reverse((a).begin(), (a).end())
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;
const long long INF = 1LL << 60;

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(200010);
  rep(i, n) {
    int k;
    cin >> k;
    a[k]++;
  }
  SORT(a);
  RSORT(a);
  int total = 0;
  rep(i, 200010) {
    if (a[i] > 0) k--;
    total += a[i];
    if (k == 0) break;
  }
  cout << n - total << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main() {
  while (true) {
    int n, m, t;
    cin >> n >> m >> t;
    if (n == 0)
      break;
    vector<int> a(n);
    for (int i = 0; i < n; i++)
      cin >> a[i];
    a.push_back(-m);
    a.push_back(t + m);
    sort(a.begin(), a.end());
    long long ans = 0;
    int bef = a[0];
    for (int i = 1; i <= a.size(); i++) {
      ans += max(0, a[i] - bef - 2 * m);
      bef = a[i];
    }
    cout << ans << endl;
    break;
  }
  return 0;
}



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

int main(){
  int A,B,C,K;
  cin >> A >> B >> C >> K;
  while(K > 0){
    if(A >= B){
      B *= 2;
    }else if(B >= C){
      C *= 2;
    }
    K--;
  }
  if(A < B && B < C){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3632
n = int(input())
ac,wa,tle,re = 0,0,0,0
for _ in range(n):
    s = input()
    if s=="AC":
        ac+=1
    elif s=="WA":
        wa+=1
    elif s=="TLE":
        tle+=1
    else:
        re+=1
print("AC x",ac)
print("WA x",wa)
print("TLE x",tle)
print("RE x",re)

Measured memory_bytes: 74700
#include<stdio.h>

int A[20], n;

bool Search(int sum, int i, int m) {
    bool ans1, ans2;
    if (i==n-1) {
        if (sum==m) return true;
        else return false;
    }
    i++;
    ans1 = Search(sum, i, m);
    sum += A[i];
    ans2 = Search(sum, i, m);
    
    return ans1 || ans2;
}

int main() {
    int i, m, q;
    bool ans;

    scanf("%d", &n);
    for (i=0; i<n; i++) scanf("%d", &A[i]);
    scanf("%d", &q);
    for (i=0; i<q; i++) {
        scanf("%d", &m);
        ans = Search(0, -1, m);
        if (ans) printf("yes\n");
        else printf("no\n");
    }
}


Measured memory_bytes: 2676
#include <iostream>
#include <algorithm>
#include <climits>
#include <numeric>
#include <iomanip>
#include <cmath>
#include <vector>
#include <set>
#include <unordered_set>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <unordered_map>
 
#define barsik ios::sync_with_stdio(false)
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
typedef long long ll;
typedef std::vector<int> vi;
typedef std::pair <int, int> pii;
typedef std::unordered_set <int> u_si;
const double PI = acos(-1);
const long double EPS = 1e-9;
using namespace std;

 
void solve(){
    int n, m;
    cin >> n >> m;
    vi a(m, 0);
    for(int i = 0; i < n; i++){
        int k;
        cin >> k;
        for(int j = 0; j < k; j++){
            int idx;
            cin >> idx;
            a[idx - 1] += 1;
        }
    }
    int cnt = 0;
    for(int i = 0; i < m; i++){
        if(a[i] == n) cnt++;
    }
    cout << cnt;
}

 
int main() {
    barsik;
    int q = 1;
    //cin >> q;
    while(q--) solve();
}


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

int main() {
	int N;

	cin >> N;
	vector<pair<int, int>> AB( N );
	for( int i = 0; i < N; i++ ) {
		int a, b;
		cin >> a >> b;
		AB[i] = make_pair( b, a );
	}

	sort( AB.begin(), AB.end() );
	string ans = "Yes";
	int t = 0;
	for( int i = 0; i < N; i++ ) {
		t += AB[i].second;
		if( t > AB[i].first ) {
			ans = "No";
			break;
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1792
N,W = map(int,input().split())
w = [None] * N
v = [None] * N

for i in range(N):
  w[i],v[i] = map(int,input().split())

dp = [[-1] * (W + 1) for i in range(N + 1)]
dp[0][0] = 0

for i in range(N):
  for j in range(len(dp[i]) - 2, -1, -1):
    if dp[i][j] == -1:
      continue
    dp[i + 1][j] = max(dp[i + 1][j], dp[i][j])
    if j + w[i] >= len(dp[i]):
      continue
    dp[i + 1][j + w[i]] = max(dp[i + 1][j + w[i]], dp[i][j] + v[i])

print(max(dp[N]))

Measured memory_bytes: 147832
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.1,sse4.2,popcnt,abm,mmx,avx")
// #pragma comment(linker, "/stack:200000000"]
 
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <bitset>
#include <stack>
#include <random>
#include <fstream>
#include <sstream>
#include <chrono>

#define fi first
#define se second
#define pb push_back
#define ll long long
#define ld long double
#define hm unordered_map 
#define pii pair<int, int>
#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()
#define cinv(v) for (auto& x: v) cin >> x
#define fr(i, n) for (int i = 0; i < n; ++i)
#define fl(i, l, n) for (int i = l; i < n; ++i)

#define int ll

using namespace std;

#ifdef __LOCAL
	#define dbg(x) cerr << #x << " : " << x << '\n'
	const int maxn = 20;
#else 
	#define dbg(x)
	const int maxn = 2e5 + 20;
#endif

//tg: @galebickosikasa
 
const ll inf = (ll) 2e9;
const ld pi = asin (1) * 2;
const ld eps = 1e-8;
const ll mod = (ll)1e9 + 7;
const ll ns = 97;

mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

int BS (int x) {
	int l = -5300, r = 5300;
	while (r - l > 1) {
		int m = (r + l) / 2;
		if (m * m * m * m * m >= x) r = m;
		else l = m;
	}
	return r;
}

signed main () {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	int x;
	cin >> x;
	for (int i = -5300; i <= 5300; ++i) {
		int a = i * i * i * i * i;
		int b = a - x;
		int t = BS (b);
		if (t * t * t * t * t == b) {
			cout << i << ' ' << t;
			exit (0);
		}
	}
	exit (1);







}

Measured memory_bytes: 3640
/* Bismillahirrahmanirrahim
   Semoga Dapet AC ya Allah
   Amin.................. :)
   Ps. SelfRemainder #1: Variabel gak otomatis nilainya 0
					 #2: Output harus sama persis formatnya sama di contoh
					 #3: Jangan lama2 mikirin 1 soal. Kalo dah gabisa, stop
					 #4: Kalau for bersarang, variabelnya jangan sama
*/
#include<bits/stdc++.h>
#define forA for(int i=0; i<a; i++)
#define Fora for(int i=1; i<=a; i++)
#define ll long long
#define F first
#define S second
using namespace std;

int main(){
	int a, b, c, sum;
	cin >> a >> b >> c;
	sum=b+c-a;
	if(sum<0) cout << 0;
	else cout << sum;
}


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

def matmul(a, b, mod):
    m = len(a)
    l = len(a[0])
    n = len(b[0])
    ret = [[0] * n for _ in range(m)]
    for i in range(m):
        for j in range(n):
            e = 0
            for k in range(l):
                e = (e + a[i][k] * b[k][j]) % 2
            ret[i][j] = e
    return ret

def calc(X, v, r):
    rr = 0
    for i in range(r, D):
        if v[i][0] == 1:
            rr = i
            break
    v[rr], v[r] = v[r], v[rr]
    X[rr], X[r] = X[r], X[rr]
    for i in range(D):
        if i == r or v[i][0] == 0:
            continue
        for c in range(D):
            X[i][c] = (X[i][c] + X[r][c]) % 2

T = int(input())
D = 64
for _ in range(T):
    N = int(input())
    A = list(map(int, input().split()))
    S = input().rstrip()
    X = [[int(i == j) for j in range(D)] for i in range(D)]
    r = 0
    for i in range(N)[::-1]:
        v = [[A[i] >> j & 1] for j in range(D)]
        if S[i] == '0':
            v = matmul(X, v, 2)
            if any(v[j][0] == 1 for j in range(r, D)):
                calc(X, v, r)
                r += 1
        else:
            v = matmul(X, v, 2)
            if any(v[j][0] == 1 for j in range(r, D)):
                print(1)
                break
    else:
        print(0)

Measured memory_bytes: 73008
#include<cstdio>
#include<iostream>
using std::string;
string s;

int SearchMatch(string t,char lower){
    int n = s.size(), m = t.size();
    int res = -1;
    for(int i = 0; i < n-m+1; i++){
        int eq = 1;
        for(int j = 0; j < m; j++) if(s[i+j]!=t[j]){
            eq = 0;
            break;
        }
        if(eq && i+m<n && s[i+m]>=lower){
            int u = s[i+m]-'a';
            if(res==-1 || u<res) res = u;
        }
    }
    return res;
}

int main(){
    int k;
    std::cin>>s>>k;
    string base = "";
    for(int i = 0; i < k; i++){
        int res = SearchMatch(base,'a');
        if(res!=-1){
            base.push_back(res+'a');
        }
        else{
            char last = base[base.size()-1]+1;
            base.pop_back();
            int res = SearchMatch(base,last);
            while(res==-1){
                last = base[base.size()-1]+1;
                base.pop_back();
                res = SearchMatch(base,last);
            }
            base.push_back(res+'a');
        }
        //printf("i = %d: ",i);
        //std::cout<<base<<"\n";
    }
    std::cout<<base<<"\n";
    return 0;
}


Measured memory_bytes: 3640
// #pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
 
#define ll long long
#define pb push_back
#define N 1000000007
#define N2 998244353
#define Nmax 100001
#define INF (ll)1e18
#define pll pair<ll,ll>
#define pii pair<ll,ll>
#define mp make_pair
#define fi first
#define se1 second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(ll i=m;i<(n);i++)
#define get(n) ll (n); scanf("%lld",&(n));
#define get2(n,k) ll (n),(k); scanf("%lld%lld",&(n),&(k));
#define get3(n,m,k) ll (n),(m),(k); scanf("%lld%lld%lld",&(n),&(m),&(k));
#define gets(s) string (s); cin >> (s);
#define ALL(c) (c).begin(),(c).end()
#define fill_nums(A,n) vector<ll> A((n)); for(ll i=0;i<n;i++) scanf("%lld",&A[i]);
#define fill_edges(adj,m) for(ll i=0;i<m;i++) {ll a, b; scanf("%lld %lld",&a,&b); adj[a-1].pb(b-1); adj[b-1].pb(a-1);}
#define fill_direct(adj,m) for(ll i=0;i<m;i++) {ll a, b; scanf("%lld %lld",&a,&b); adj[a-1].pb(b-1);}
#define pi 3.1415926535897

int main() {
    
    get2(n,m);

    vector<pair<ll,pll>> vec;
    rep(i,n) {
        get3(a,b,c);
        vec.pb({c,{a,b}});
    }

    sort(ALL(vec));

    set<ll> se;
    rep(i,m) {
        get(a);
        se.insert(a);
    }

    map<ll,ll> ma;
    for(auto i:vec) {
        ll pos = i.fi;
        ll l = max((ll)0,i.se1.fi-pos);
        ll r = max((ll)0,i.se1.se1-1-pos);

        set<ll>::iterator it1 = se.lower_bound(l);
        set<ll>::iterator it2 = se.upper_bound(r);
        if(it1==it2) continue;
        it2--;

        vector<ll> temp;
        while(it1!=it2) {
            temp.pb(*it1);
            it1++;
        }
        temp.pb(*it2);
        for(auto i:temp) {
            se.erase(i);
            ma[i] = pos;
        }
    }

    for(auto i:se)
        ma[i] = -1;

    for(auto i:ma) {
        printf("%lld\n",i.se1);
    }

    return 0;  
}

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

signed main() {
  while (1) {
    int n;
    cin >> n;
    if (n == 0) break;
    vector<vector<pii>> g(n);
    vector<int> P(n - 1), D(n - 1);
    REP(i, n - 1) cin >> P[i];
    REP(i, n - 1) cin >> D[i];
    REP(i, n - 1) {
      g[P[i] - 1].push_back({i + 1, D[i]});
      g[i + 1].push_back({P[i] - 1, D[i]});
    }
    
    int ans = 0;
    auto dfs = [&](auto f, int v, int par) -> bool {
      if (g[v].size() == 1) {
        return true;
      }
      for (pii e : g[v]) {
        int w = e.first;
        if (par == w) continue;
        if (f(f, w, v)) {
          ans += e.second;
        } else {
          ans += e.second * 3;
        }
      }
      return false;
    };
    int root = 0;
    while (g[root].size() == 1) root++;
    dfs(dfs, root, -1);
    
    vector<int> dist(n);
    auto dfs2 = [&](auto f, int v, int par, int d) -> void {
      if (g[v].size() == 1) return;
      dist[v] = d;
      for (pii e : g[v]) {
        if (e.first == par) continue;
        f(f, e.first, v, d + e.second);
      }
    };
    dist[root] = 0;
    dfs2(dfs2, root, -1, 0);
    int mxi = max_element(dist.begin(), dist.end()) - dist.begin();
    fill(dist.begin(), dist.end(), 0);
    dfs2(dfs2, mxi, -1, 0);
    int diam = *max_element(dist.begin(), dist.end());
    
    cout << ans - diam << endl;
  }
}


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

using namespace std;

#define YES cout << "YES" << endl;
#define NO  cout << "NO"  << endl;
#define Yes cout << "Yes" << endl;
#define No  cout << "No"  << endl;
 
#define INF INT_MAX
#define MOD 1000000007
#define PI  acos(-1)

using ll  = long long;
using ull = unsigned long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

ll fact(ll n) {
    if (n == 1) {
        return 1;
    } else {
        return (n * fact(n - 1)) % MOD;
    }
}

int main(int argc, char *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    ll N, M;
    cin >> N >> M;

    ll ans = 0;
    if (abs(N-M) == 0) {
        ans = fact(N)*fact(M);
        ans *= 2;
        ans %= MOD;
    } else if (abs(N-M) == 1) {
        ans = fact(N)*fact(M) % MOD;
    }

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

Measured memory_bytes: 1792
Program ABC065_B;
const   MaxN=100005;
var n,i,cnt:longint;
    a,d:array[0..MaxN] of longint;

begin
    read(n);
    for i:=1 to n do read(a[i]);
    i:=1;
    cnt:=0;
    repeat
        d[i]:=1;
        i:=a[i];
        inc(cnt);
    until (d[2]=1)or(d[i]=1);
    if d[2]=1 then write(cnt-1)
    else write(-1);
end.

Measured memory_bytes: 896
str = input()
n = int(input())

for i in range(n):
	line = input().split()
	com = line[0]
	x = int(line[1])
	y = int(line[2])
	
	if com == 'replace':
		str = str[:x]+line[3]+str[y+1:]
	elif com == 'reverse':
		str = str[:x]+str[x:y+1][::-1]+str[y+1:]
	elif com == 'print':
		print(str[x:y+1])



Measured memory_bytes: 5616
#include <stdio.h>
int main(void){
    int N = 0; int K = 0;
    scanf("%d", &N);
    scanf("%d", &K);

    char line[N];

    for(int i = 0; i <= N; i++){
        scanf("%c", &line[i]);
    }

    line[K] = line[K] + 32;

    for(int i = 0; i <= N; i++){
        printf("%c", line[i]);
    }
    printf("\n");
    return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <tuple>
#include <iomanip>
#include <climits>
#include <fstream>
#include <random>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define revrep(i, n) for(int i = (n)-1; i >= 0; i--)
#define pb push_back
#define f first
#define s second
#define chmin(x, y) x = min(x, y);
#define chmax(x, y) x = max(x, y);
#define sz(x) ((int)(x).size())

//const ll INFL = LLONG_MAX;//10^18 = 2^60
const ll INFL = 1LL<<60;
//const int INF = INT_MAX;
const int INF = 1 << 30;//10^9
ll MOD = 1000000007;
//const ll MOD = 998244353;
double EPS = 1e-10;

vector<ll> dy = {0, 1, 0, -1, 1, 1, -1, -1, 0};
vector<ll> dx = {1, 0, -1, 0, 1, -1, 1, -1, 0};

void pres(double A){printf("%.12lf\n", A);}
void BinarySay(ll x, ll y = 60){rep(i, y) cout << (x>>(y-1-i) & 1); cout << endl;}
ll cnt_bit(ll x){return __builtin_popcountll(x);}

ll pow_long(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2) res *= x;
    x *= x; k /= 2;
  }
  return res;
}

ll pow_mod(ll x, ll k){
  x %= MOD;
  ll res = 1;
  while(k > 0){
    if(k % 2){
      res *= x; res %= MOD;
    }
    x *= x; x %= MOD;
    k /= 2;
  }
  return res;
}

ll gcd(ll a, ll b){
    if(b == 0) return a;
    return gcd(b, a % b);
}

ll lcm(ll x, ll y){
  ll res = x / gcd(x, y);
  res *= y;
  return res;
};

int p, q, Ma, n;

int saiki(int last, int a, int b, int N){
  if(N > n) return 0;
  if(b > Ma) return 0;
  if(a * q == b * p) return 1;
  if(a * q > b * p) return 0;
  //last以上を追加する
  int res = 0;
  for(int i = last; i * b <= Ma; i++){
    int a_ = a * i + b;
    int b_ = b * i;
    res += saiki(i, a_, b_, N+1);
  }
  return res;
}

void solve(){
  while(true){

    cin >> p >> q >> Ma >> n;
    if(p+q+Ma+n == 0) return;
    cout << saiki(1, 0, 1, 0) << endl;
  }
}

int main(){
  ios_base::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  solve();
}



Measured memory_bytes: 3140
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n;
ll a[1<<22];
ll sum[1<<22];
ll twop[1<<22];
ll zero[1<<22];
ll dp[1<<22];
ll dp2[1<<22];

int main(void){
	scanf("%d",&n);
	twop[0]=1;
	for(int i=0;i<=n;i++){
		twop[i+1]=twop[i]*2LL%MOD;
	}
	for(int i=0;i<n;i++){
		scanf("%lld",&a[i]);
	}
	for(int i=0;i<n;i++){
		sum[i+1]+=sum[i];
		sum[i+1]^=a[i];
	}
	for(int i=n-1;i>=0;i--){
		zero[i]=zero[i+1];
		if(sum[i+1]==0)zero[i]++;
	}
	ll ans=0;
	if(sum[n]==0){
		ans+=twop[zero[0]-1];
	}
	for(int i=0;i<n;i++){
		if(sum[i+1]>0){
			ll val=dp[sum[i+1]];
			val-=dp2[sum[i+1]]*zero[i]%MOD;
			val+=MOD;
			val++;
			val%=MOD;
			if((i+1)==n)ans+=val;
			else if(sum[n]==0)ans+=val;
			dp2[sum[i+1]]+=val;
			dp2[sum[i+1]]%=MOD;
			val=val*zero[i]%MOD;
			dp[sum[i+1]]+=val;
			dp[sum[i+1]]%=MOD;
			//printf("%lld %lld %lld %lld %lld\n",sum[i+1],ans,val,dp[sum[i+1]],dp2[sum[i+1]]);
			ans%=MOD;
		}
	}
	printf("%lld\n",(ans)%MOD);
	return 0;
}


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

typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
#define int ll

const ll MOD = 1000000007;
const ll INF_LL = (ll)1000000007 * 1000000007;
const int INF_INT = (int)1000000007;
const double PI = 3.14159265358979323846;

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

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define irep(itr, st) for (auto itr = (st).begin(); itr != (st).end(); ++itr)
#define irrep(itr, st) for (auto itr = (st).rbegin(); itr != (st).rend(); ++itr)

#define m0(x) memset((x), 0, sizeof((x)))
#define m1(x) memset((x), -1, sizeof((x)))

// xにはvectorなどのコンテナ
#define ALL(x) (x).begin(), (x).end()  // sortなどの引数を省略したい
#define RALL(x) (x).rbegin(), (x).rend()  // sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size())     // sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))  //最大値を求める
#define MIN(x) *min_element(ALL(x))  //最小値を求める
#define all(x) (x).begin(), (x).end()

//略記
#define pb emplace_back  // vectorヘの挿入
#define mp make_pair     // pairのコンストラクタ
#define F first          // pairの一つ目の要素
#define S second         // pairの二つ目の要素

#define BITCOUNT __builtin_popcount
#define BITCOUNT_LL(x) __builtin_popcountll(x)

#define perm(c)             \
  sort(all(c));             \
  for (bool c##p = 1; c##p; \
       c##p = next_permutation(all(c)))  //順列 123 132 213 231 312 321

#define BIT(n) (1LL << (n))

#ifdef DEBUG
#define PRINT(A) std::cout << (#A) << ": " << (A) << std::endl;
#else
#define PRINT(A)
#endif

//入力高速化
struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  }
} iosetup;

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

signed main() {
  int A, V, B, W, T;
  cin >> A >> V >> B >> W >> T;
  if (abs(A - B) <= T * (V - W)) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}

Measured memory_bytes: 3648
using namespace std;
#include <bits/stdc++.h>
#define rep(i, s) for (int i = 0; i < s; ++i)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define all(v) (v.begin(), v.end())
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define VEC(a, n) vector<int>a(n)
#define VECV(a,n,m) vector<vector<int>> a(n, vector<int>(m));
#define PQ(a) priority_queue<int>a
#define PQmin(a) priority_queue< int, :vector<int>, greater<int> >a
#define PAIR pair<int, int>
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
#define EPS (1e-7)
#define INF (1e10)
#define PI (acos(-1))
const ll mod = 1000000007;
bool f(string s){
  bool ans=true;
  rep(i,s.size()/2){
    if(s[i]!=s[s.size()/2+i]){
      ans=false;
      break;
    }
  }
  return ans;
}

int gcd(int a, int b) {
  int v0 = a, v1 = b, v2 = a % b;
  while (v2 != 0) {
    v0 = v1;
    v1 = v2;
    v2 = v0 % v1;
  };
  return v1;
}

int gcd3(int a, int b,int c){
  return gcd(gcd(a,b),c);
}

int mid(int a, int b, int c){
  if(max(max(a,b),c)==a && min(min(a,b),c)==b)
    return c;
  if(max(max(a,b),c)==a && min(min(a,b),c)==c)
    return b;
  if(max(max(a,b),c)==b && min(min(a,b),c)==a)
    return c;
  if(max(max(a,b),c)==b && min(min(a,b),c)==c)
    return a;
  if(max(max(a,b),c)==c && min(min(a,b),c)==a)
    return b;
  if(max(max(a,b),c)==c && min(min(a,b),c)==b)
    return a;
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int K,A,B;
  cin>>K>>A>>B;
  if(B%K==0||A%K==0)
    cout<<"OK"<<endl;
  else if(B/K-A/K>0)
    cout<<"OK"<<endl;
  else
    cout<<"NG"<<endl;
    

}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
using vi = vector<i64>;
using vvi = vector<vi>;

int main() {
    int n, q;
    cin >> n >> q;
    vi as(n), bs(n + 1);
    for (int i = 0; i < n; i++) {
        cin >> as[i];
        if (i % 2 == 0) {
            bs[i + 1] = as[i];
        }
    }

    vi sum(as);
    sum.insert(sum.begin(), 0);
    for (int i = 1; i <= n; i++) {
        sum[i] += sum[i - 1];
        bs[i] += bs[i - 1];
    }

    // [a, b)
    auto get_sum = [&](int a, int b) {
        return sum[b] - sum[a];
    };
    
    while (q--) {
        int x;
        cin >> x;
        int l = 0, r = n / 2 + 1;
        while (l < r - 1) {
            int m = (l + r) / 2;
            int tak = as[n - m];
            int aok = as[n - 2 * m];
            if (abs(aok - x) <= abs(x - tak)) {
                l = m;
            } else {
                r = m;
            }
        }
        if (2 * l == n) {
            cout << get_sum(l, n) << '\n';
            continue;
        }
        i64 s = get_sum(n - l, n);
        if (abs(as[n - 2 * l - 1] - x) <= abs(as[n - l - 1] - x)) {
            i64 ans = as[n - l - 1];
            i64 tmp = 0;
            // for (int j = n - 2 * l - 3; j >= 0; j -= 2) {
            //     tmp += as[j];
            // }
            if (n - 2 * l - 3 < 0) {
                tmp = 0;
            } else if ((n - 2 * l - 3) % 2 == 0) {
                tmp = bs[n - 2 * l - 3 + 1];
            } else {
                tmp = get_sum(0, n - 2 * l - 3 + 1) - bs[n - 2 * l - 3];
            }
            cout << s + ans + tmp << '\n';
        } else {
            i64 tmp = 0;
            // for (int j = n - 2 * l - 1; j >= 0; j -= 2) {
            //     tmp += as[j];
            // }
            if (n - 2 * l - 1 < 0) {
                tmp = 0;
            } else if ((n - 2 * l - 1) % 2 == 0) {
                tmp = bs[n - 2 * l - 1 + 1];
            } else {
                tmp = get_sum(0, n - 2 * l - 1 + 1) - bs[n - 2 * l - 1];
            }
            cout << s + tmp << '\n';
        }
    }
}

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

struct data{
  int ac,pe,id;
  bool operator == (const data& p) const{
    return ac==p.ac && pe==p.pe;
  }
  bool operator < (const data& p) const{
    if(ac!=p.ac)return ac>p.ac;
    if(pe!=p.pe)return pe<p.pe;
    return id>p.id;
  }
};

int wa_cnt[51][11];

data team[51];

void init();

int main(){
  int M,T,P,R;
  while(1){
    cin>>M>>T>>P>>R;
    if(M==0&&T==0&&P==0&&R==0)break;
    init();
    for(int i=0;i<R;i++){
      int m,t,p,j;
      cin>>m>>t>>p>>j;t--;
      if(m>M)continue;
      if(j==0){
	team[t].ac++;
	team[t].pe+=(wa_cnt[t][p]*20);	
	team[t].pe+=m;
      }else wa_cnt[t][p]++;
    }

    sort(team,team+T);
    for(int i=0;i<T;i++){
      if(i>0)cout<<(team[i-1]==team[i]?'=':',');
      cout<<team[i].id;
    }
    cout<<endl;
  }
  return 0;
}

void init(){
  for(int i=0;i<51;i++)for(int j=0;j<11;j++)wa_cnt[i][j]=0;
  for(int i=0;i<51;i++){
    team[i].id=i+1;
    team[i].pe=team[i].ac=0;
  }
}

Measured memory_bytes: 1188
#include<iostream>
using namespace std;
int main(){
  long long int N,M;
  long long int result;
  long long int tmp_result;
  cin >> N >> M;
  result = (N < M/2)? N:M/2;
  M = M - 2 * result;
  if(M > 0) result = result +  M / 4; 
  cout << result << endl;
}


Measured memory_bytes: 256
# coding: utf-8
# Your code here!
while True:
    n=int(input())
    
    if n==0:
        break
    s=1
    for i in range(n):
        s*=(i+1)
    
    ans=0
    
    while True:
        if s%10!=0:
            break
        else:
            s=s//10
            ans+=1
    print(ans)


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

int main(){
    int n, i, j, k;
    scanf("%d",&n);
    int a[n+5], b[n+5], c[n+5];
    for(i=1;i<=n;i++){
        scanf("%d %d %d",&a[i], &b[i], &c[i]);
    }
    int dp[n+5][3];
    memset(dp, 0, sizeof(dp));
    for(i=1;i<=n;i++){
        dp[i][0] = max(dp[i-1][1], dp[i-1][2]) + a[i];
        dp[i][1] = max(dp[i-1][0], dp[i-1][2]) + b[i];
        dp[i][2] = max(dp[i-1][0], dp[i-1][1]) + c[i];
    }
    int ans  = 0;
    ans = max(dp[n][0], dp[n][1]);
    ans = max(ans, dp[n][2]);
    cout << ans << "\n";

    return 0;
}


Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> V;
#define rep(cnt,e) for(ll cnt=0;cnt<e;cnt++ )
typedef pair<ll,ll> P;
const ll mod = 1e9+7;
const ll INF = INT64_MAX;






ll i,j,k;


int main(){
    ll N;
    cin>>N;
    ll kijun=1e18;
    V A(N);
    rep(i,N)cin>>A[i];
    ll ans=1;
    rep(i,N){
        if(A[i]==0){
            cout<<0<<endl;
            return 0;
        }
    }
    rep(i,N){
        double handan=kijun/A[i];
        
        if(handan<ans){
            cout<<-1<<endl;
            return 0;
        }
        else{
            ans*=A[i];
        }

    }
    if(ans>kijun){
        cout<<-1<<endl;
        return 0;

    }
    cout<<ans<<endl;
}

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

char s[51], t[51];

int solve() {
  scanf("%s %s", s, t);
  int n = strlen(s);
  int r1 = n - 1;
  int r2 = n - 1;
  while (s[r1] == '0') r1--;
  while (t[r2] == '0') r2--;
  int ans = 0;
  while (r1 > r2) {
    s[r1 - 1] = '1';
    s[r1] = '0';
    r1--;
    ans++;
  }
  int l = 0;
  while (l < r1 && s[l] == t[l]) l++;
  return ans + (r1 - l) + (r2 - l);
}

int main() {
  int q;
  scanf("%d", &q);
  while (q--) {
    printf("%d\n", solve());
  }
}


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

namespace AtCoder
{
    class Program
    {
        static void Main()
        {
            var tmp = ReadLine();
            var a = tmp[0];
            var b = tmp[1];

            while (a != b)
            {
                if (a < b)
                {
                    a += tmp[0];
                }
                else if (b < a)
                {
                    b += tmp[1];
                }
            }

            Console.WriteLine(a);
        }

        static List<long> ReadLine()
        {
            var line = Console.ReadLine();
            var array = line.Split(' ');

            return array.Select(x => long.Parse(x)).ToList();
        }
    }
}

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

int main() {
ll X,Y,A,B,C;
cin>>X>>Y>>A>>B>>C;
ll a[A]={};
ll b[B]={};
ll c[C]={};
ll counter=0;
for(int i=0;i<A;i++){
cin>>a[i];}
for(int i=0;i<B;i++){
cin>>b[i];}
for(int i=0;i<C;i++){
cin>>c[i];}
sort(a,a+A);
sort(b,b+B);
sort(c,c+C);
ll k=0;
ll w=0;
priority_queue<ll,vector<ll>,greater<ll>>q;
for(int j=0;j<X;j++){
counter+=a[A-1-w];
q.push(a[A-1-w]);
w++;}
w=0;
for(int j=0;j<Y;j++){
counter+=b[B-1-w];
q.push(b[B-1-w]);
w++;}
for(int j=C-1;j>=0;j--){
k=q.top();
if(c[j]>=k){
counter=counter-k+c[j];
q.pop();}
else
break;}
cout<<counter<<endl;}

Measured memory_bytes: 4724
#include<iostream>
using namespace std;
char ans[2][10]={
    "No\n",
    "Yes\n"
};
int main(){
    int a,b,c;
    cin>>a>>b>>c;
    bool flag=0;
    if(a<b)if(b<c)flag=1;
    cout<<ans[flag];
}

Measured memory_bytes: 1124
#include <algorithm>
#include <cstdlib>
#include<iostream>
#include<vector>
#include<map>
#include<cmath>
using namespace std;
int N,A;
int main(int argc, char const *argv[])
{
cin>>N>>A;
if(N%500<=A){
    cout<<"Yes"<<endl;
}else{
    cout<<"No"<<endl;
}
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>

int main(){
    char a[101],b[101];
    scanf("%s\n%s",a,b);

    int count_d_a = 0;
    int count_d_b = 0;
    for(int i = 0; a[i] != '\0'; i++){
        count_d_a++;
    }
    for(int i = 0; b[i] != '\0'; i++){
        count_d_b++;
    }

    if(count_d_a > count_d_b){
        printf("GREATER\n");
    }else if(count_d_a < count_d_b){
        printf("LESS\n");
    }else{
        for(int i = 0; i < count_d_a; i++){
            if(a[i] > b[i]){
                printf("GREATER\n");

                return 0;
            }else if(a[i] < b[i]){
                printf("LESS\n");

                return 0;
            }
        }
        printf("EQUAL\n");
    }

    return 0;
}

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

using ll = long long;
using ld = long double;

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

    int n, k;
    cin>>n>>k;

   vector<int>a(n);

    for(auto& x: a)cin>>x;

    vector<bool>dp(k+1);

    for(int stones = 0; stones <= k; stones++){
        for(int x : a){
            if(stones >= x && !dp[stones-x])
                dp[stones] = true;
        }
    }

    cout<<  (dp[k] ? "First" : "Second");
}

Measured memory_bytes: 256
import bisect,collections,copy,heapq,itertools,math,string
import numpy as np
import sys
sys.setrecursionlimit(10**7)

def _S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())

N,K = LI()
H = LI()

Hs = np.array(sorted(H, reverse=True))

ans = np.sum(Hs[K:])

print(ans)

Measured memory_bytes: 49772
#include<stdio.h>
int main(void)
{
	int a[20000],b[20000],i=0,n[20000],m;
	char op[20000];
	while(1){
	scanf("%d %c %d\n",&a[i],&op[i],&b[i]);
		if(op[i]=='?'){
		break;
		}else if(op[i]=='+'){
			n[i]=a[i]+b[i];
		}else if(op[i]=='-'){
			n[i]=a[i]-b[i];
		}else if(op[i]=='*'){
			n[i]=a[i]*b[i];
		}else if(op[i]=='/'){
			n[i]=a[i]/b[i];
		}
		i++;
	}
	for(m=0;m<i;m++)
	printf("%d\n",n[m]);
}

Measured memory_bytes: 1816
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;


public class Main {

	/**
	 * @param args
	 * @throws IOException 
	 */
	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		while(true){
			String str = br.readLine();
			if(str == null){
				break;
			}
			String[] tmpArray = str.split(" ");
			int n = Integer.parseInt(tmpArray[0]);
			int ans = Integer.parseInt(tmpArray[1]);
			
			System.out.println(combinationOfSeq(n, ans, null));
		}
	}
	
	static int combinationOfSeq(int n , int ans, boolean[] used){
		
		if(used == null){
			used = new boolean[10];
			Arrays.fill(used, false);
		}
		
		//System.out.println("n = "+n+" ans = "+ans);
		if(ans < 0){
			return 0;
		}

		if(n == 0){
			if(ans == 0){
			//	System.out.println("OK");
				return 1;
			}
			else {
				return 0;
			}
		}
//		if(n == 1){
//			if(ans >= 0 && ans <= 9){
//				System.out.println("OK");
//				return 1;
//			}
//			else {
//				return 0;
//			}
//		}
		
		int result = 0;
		for(int i = 9; i >= 0 ; i--){
			if(used[i]){
				continue;
			}
			used[i] = true;
			result += combinationOfSeq(n - 1, ans - n*i, used);
			used[i] = false;
		}
		
		return result;
	}

}

Measured memory_bytes: 24764
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;

const int MAX = 105;
const ll INF = 10000000005;

int n;
ll d[MAX][MAX];

void floyd() {
  rep(k, n) {
    rep(i, n) {
      if (d[i][k] == INF) continue;
      rep(j, n) {
        if (d[k][j] == INF) continue;
        d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
      }
    }
  }
}

int main() {
  int e, u, v, c;
  cin >> n >> e;
  rep(i, n) {
    rep(j, n) {
      d[i][j] = INF;
      if (i == j) d[i][i] = 0;
    }
  }
  rep(i, e) {
    cin >> u >> v >> c;
    d[u][v] = c;
  }
  floyd();
  rep(i, n) {
    if (d[i][i] < 0) {
      cout << "NEGATIVE CYCLE" << endl;
      return 0;
    }
  }
  rep(i, n) {
    rep(j, n) {
      if (j) cout << " ";
      if (d[i][j] == INF) cout << "INF";
      else cout << d[i][j];
    }
    cout << endl;
  }
  
  return 0;
}


Measured memory_bytes: 3188
#include <iostream>
#include <stdio.h>
#include<string>
using namespace std;

int main()
{
 int  i;
char c[100];

 cin >> c;
 i = 0;
 while (c[i] != '\0') {
	 c[i] = 'x';
	 i++;
 }

 cout << c;

}

Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <cctype>
#include <stdio.h>
#include <map>
using namespace std;

void bfs(string worm);
char jump(char c1, char c2);
int main(int argc, char const* argv[])
{
    string worm;
    while ( cin >> worm ) {
        if( worm == "0" ) { break; }
        else
        {
            bfs(worm);
        }
    }
    return 0;
}


void bfs(string worm){
    //puts("enter bfs");
    queue<string> q;
    string str;
    map<string, int> dis;
    q.push(worm); 
    dis[worm] = 0;

    while ( q.size() != 0 ) 
    {
        //puts("enter while");
        //一つ取り出す
        str = q.front(); q.pop();

        //終了判定
        bool is_same = true;
        for( int i=0; i<str.length()-1; i++)
        {
            //cout << 
            if( str[i] != str[i+1]) { is_same = false; continue; }
        }
        if ( is_same == true ) 
        {
            cout << dis[str] << endl;
            return;
        }
        //cout<<"worm:" << worm<< endl;
        //cout<<"str:" << str << endl;
        //cout<<"time:" << time << endl;

        //色が違ったらpush
        for(int i=0; i<str.size()-1; i++){
            //隣が色違い
            //puts("enter while");
            if( str[i] != str[i+1])
            {
                string next_str = str;
                next_str[i] = next_str[i+1] = jump(str[i], str[i+1]);
                //まだ通ってない
                if ( dis.find(next_str) == dis.end() )
                {
                    q.push(next_str);
                    dis[next_str] = dis[str] + 1;
                }
                else { continue; }
            }
        }
    }
    cout << "NA" << endl;
}

char jump(char c1, char c2){
    if(c1 != 'r' && c2 != 'r')
    {
        return 'r';
    }
    else if(c1 != 'g' && c2 != 'g')
    {
        return 'g';
    }
    else if(c1 != 'b' && c2 != 'b')
    {
        return 'b';
    }
}

Measured memory_bytes: 2888
s = input()
k = int(input())
import math
if len(set(list(s))) == 1:
    print(len(s) * k // 2)
    exit()
last=s[0]
length=1
change=0
for i in range(1,len(s)):
    if s[i] == last:
        length+=1
    else:
        change += math.floor(length/2)
        length=1
    last=s[i]

change += math.floor(length/2)
ans=change*k
if s[0] != s[-1]:
    print(ans)
    exit()

l_length=1
last=s[0]
for i in range(1,len(s)):
    if s[i] == last:
        l_length+=1
    else:
        break
r_length=1
last=s[-1]
for i in range(len(s)-2,-1,-1):
    if s[i] == last:
        r_length+=1
    else:
        break

if l_length%2==1 and r_length%2==1:
    print(ans+k-1)
    exit()
print(ans)

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

int gcd(int x, int y) {
  int a = x % y;

  for (int i = a; i > 0; i--) {
    if (y % i == 0 && a % i == 0) {
      return i;
    }
  }
}

int main() {
  int x, y;

  cin >> x >> y;

  if (x == y) {
    cout << x << endl;
  } else if (x > y) {
    cout << gcd(x, y) << endl;
  } else {
    cout << gcd(y, x) << endl;
  }
}



Measured memory_bytes: 3096
#include <bits/stdc++.h>
using namespace std;
int main(void){

    long long H, ans=1, i = 1;
    cin >> H;
    while(H){
        if(H==1) break;
        else{
            H=H/2;
            if(H!=1) ans=ans + pow(2,i);

            else {
                ans=ans + pow(2,i);
                break;
            }
        }
        i++;
    }
    cout << ans << endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(a) (a).begin(),(a).end()
#define upper_index(array,a) (int)distance(array.begin(), upper_bound((array).begin(),(array).end(),a))

using namespace std;
typedef long long ll;

int main() {
  int N;
  cin >> N;
  vector<int> ls(N);
  rep(i,N) cin>>ls[i];
  sort(ALL(ls));
  int cnt=0;
  rep(i,N)rep(j,i) cnt+=max(0,j-upper_index(ls,ls[i]-ls[j]));
  cout << cnt << endl;
}


Measured memory_bytes: 256
def main():
    a, b = map(int, input().split())
    A = ""
    B = ""
    for _ in range(b):
        A += str(a)

    for _ in range(a):
        B += str(b)

    if int(A) >= int(B):
        print(A)
    else:
        print(B)

main()

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


int main() {
    int N;
    cin >> N;
    int a[N];
    for (int i=0;i<N;i++){
        cin >> a[i];
    }
    for (int i=0;i<N;i++){
        a[i]--;
    }
    int s=a[0],i=1;
    while (i<N+1){
        if (s!=1){
            s=a[s];
            i++;
        }
        if (s==1) {
            cout << i << endl;
            break;
        }
    }
    if (s!=1) cout << -1 << endl;
}


Measured memory_bytes: 640
parseInt(x::String) = parse(Int, x)
parseInt(x::SubString{String}) = parse(Int, x)
parseInt(x::Char) = parse(Int, x)
parseInt(x::Float64) = trunc(Int, x)
parseFloat(x::String) = parse(Float64, x)
parseFloat(x::Int) = trunc(Float64, x)
parseFloat(x::SubString{String}) = parse(Float64, x)
parseFloat(x::Char) = parse(Float64, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
    w,h,n=parseMap(split(readline()))
    hma,hmi,wma,wmi=h,0,w,0
    for i in 1:n
        x,y,a=parseMap(split(readline()))
        if a==1
            wmi=max(wmi,x)
        elseif a==2
            wma=min(wma,x)
        elseif a==3
            hmi=max(hmi,y)
        else
            hma=min(hma,y)
        end
    end
    println(max(max(hma-hmi,0)*max(wma-wmi,0),0))
end
main()

Measured memory_bytes: 112560
#include <iostream>
#include <cstdio>
#define PR pair<int,int>
#define F first
#define S second
#define F first
#define S second
using namespace std;

int k, x, y;
PR ans[200005];

PR f(int p, int q) {
	PR re;
	if(p>q) {
		re = f(q, p);
		return {re.S, re.F};
	}
	if(p<0) {
		re = f(-p, q);
		return {-re.F, re.S};
	}
	if(p+q >= 2*k) return {p, q-k};
	if(p+q == k) return {0,0};
	int t = (p+q)/2 - k;
	return {t, p+q-k-t};
}

int main() {
	int i;
	cin >> k >> x >> y;
	if(!(k&1) && (x+y)&1) return puts("-1")*0;
	ans[0] = {x, y};
	for(i=0; ans[i].F || ans[i].S; i++) {
		ans[i+1] = f(ans[i].F, ans[i].S);
	}
	printf("%d\n", i);
	for(; i--; ) printf("%d %d\n", ans[i].F, ans[i].S);
	return 0;
}

Measured memory_bytes: 4096
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

import static java.lang.Integer.parseInt;

/**
 * Kakezan
 */
public class Main {

	public static int MAX = 7;

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;


		while ((line = br.readLine()) != null && !line.isEmpty()) {

			int Q = parseInt(line);

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

				int N = parseInt(br.readLine());
				int c = 0;

				while (N >= 10) {
					// split
					int _N = 0;
					for (int j = 1; j <= MAX; j++) {
						if (Math.pow(10, j) > N) continue;
						int l = (int) (N / Math.pow(10, j));
						int r = (int) (N % Math.pow(10, j));
						_N = Math.max(_N, l * r);
					}
					//
					if (N == _N) {
						c = -1;
						break;
					}
					c++;
					N = _N;
				}
				System.out.println(c);
			}
		} //end while
	} //end main
}

Measured memory_bytes: 24304
package main

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

type intQueue []int

func (queue *intQueue) enqueue(i int) {
	*queue = append(*queue, i)
}

func (queue *intQueue) dequeue() int {
	result := (*queue)[0]
	*queue = (*queue)[1:]
	return result
}

func createGroups(n int, links [][]int) []int {
	groups := make([]int, n)
	for i := 0; i < n; i++ {
		groups[i] = i
	}
	var queue intQueue = make([]int, 0)
	for i := 0; i < n; i++ {
		if groups[i] != i {
			continue
		}
		queue.enqueue(i)
		for len(queue) != 0 {
			j := queue.dequeue()
			for _, k := range links[j] {
				if groups[k] != i {
					groups[k] = i
					queue.enqueue(k)
				}
			}
		}
	}
	return groups
}

func readLinks(n, k int) [][]int {
	links := make([][]int, n)
	for i := 0; i < k; i++ {
		p := readInt()
		q := readInt()
		links[p-1] = append(links[p-1], q-1)
		links[q-1] = append(links[q-1], p-1)
	}
	return links
}

func main() {
	n := readInt()
	k := readInt()
	l := readInt()

	roadLinks := readLinks(n, k)
	railLinks := readLinks(n, l)

	roadGroups := createGroups(n, roadLinks)
	railGroups := createGroups(n, railLinks)

	d := map[int]int{}
	result := make([]int, n)
	for i := 0; i < n; i++ {
		t := 2000001*roadGroups[i] + railGroups[i]
		if _, ok := d[t]; ok {
			d[t] += 1
		} else {
			d[t] = 1
		}
	}

	for i := 0; i < n; i++ {
		result[i] = d[2000001*roadGroups[i]+railGroups[i]]
	}

	printIntln(result...)
}

const (
	ioBufferSize = 1 * 1024 * 1024 // 1 MB
)

var stdinScanner = func() *bufio.Scanner {
	result := bufio.NewScanner(os.Stdin)
	result.Buffer(make([]byte, ioBufferSize), ioBufferSize)
	result.Split(bufio.ScanWords)
	return result
}()

func readString() string {
	stdinScanner.Scan()
	return stdinScanner.Text()
}

func readInt() int {
	result, err := strconv.Atoi(readString())
	if err != nil {
		panic(err)
	}
	return result
}

func printIntln(v ...int) {
	b := make([]byte, 0, 4096)
	for i := 0; i < len(v)-1; i++ {
		b = append(b, strconv.Itoa(v[i])...)
		b = append(b, " "...)
	}
	b = append(b, strconv.Itoa(v[len(v)-1])...)
	fmt.Println(string(b))
}


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

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

using namespace std;

int main(){
  int a,b,c,d;cin>>a>>b>>c>>d;

  cout<<max(0,min(b,d)-max(a,c));

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define maxn 200005
#define inf 1e17
#define eps 1e-6
#define ll long long
#define ull unsigned long long
#define main() int main()
#define pii pair<int, ll>
#define pb push_back
#define mp make_pair
#define fir first
#define sec second
#define sa(x) scanf("%d",&x)
#define sab(x,y) scanf("%d%d",&x,&y)
#define pa(x) printf("%d",&x)
#define pab(x,y) printf("%d%d",x,y) 
#define ms(a,x) memset(a,x,sizeof(a))
#define IO ios::sync_with_stdio(0);cin.tie(0)
#define endl '\n'
#define ff0(i,n) for(int i=0;i<n;++i)
#define ff1(i,n) for(int i=1;i<=n;++i)
main()
{
    IO;
    int x,y;
    cin>>x>>y;
    if(x>=10)cout<<y<<endl;
    else cout<<y+100*(10-x)<<endl;
}

Measured memory_bytes: 256
import sys
from bisect import bisect_left

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def is_prime(n):
    if n == 1:
        return False
    for i in range(2, int(n ** 0.5) + 1):
        if n % i == 0:
            return False
    return True


def main():
    X = int(readline())

    while not is_prime(X):
        X += 1

    print(X)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 63280
import sys
input=sys.stdin.readline
sys.setrecursionlimit(1000000)

n,q=map(int,input().split())
g=[[] for _ in range(n+1)]

for _ in range(n-1):
    a,b=map(int,input().split())
    g[a].append(b)
    g[b].append(a)
c=[0]*(n+1)
que=[1]
done=[0]*(n+1)
done[1]=1
for _ in range(q):
    p,x=map(int,input().split())
    c[p]+=x
while que:
    d=que.pop()
    for node in g[d]:
        if not done[node]:
            c[node]+=c[d]
            que.append(node)
            done[node]+=1
print(*c[1:])


Measured memory_bytes: 93004