akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;

int n;
int c[500], s[500], f[500], a[500]={};

int main(){
  cin >> n;
  for(int i=0;i<n-1;i++){
    int C, S, F;
    cin >> C >> S >> F;
    c[i]=C, s[i]=S, f[i]=F;
  }
  a[n-2] = s[n-2]+c[n-2];
  for(int i=n-3;i>=0;i--){
    int x = s[i] + c[i];
    if (x <= s[i+1]){
      a[i] = a[i+1];
    }else{
      int total=x, flag=0;
      for(int j=i;j<n-2;j++){
        if (x <= s[j+1]){
          a[i] = a[j+1];
          flag=1;
          break;
        }
        int ind=1;
        while(ind*f[j+1] < x-s[j+1]){
          ind++;
        }
        x = s[j+1] + ind * f[j+1] + c[j+1];
        total=x;
      }
      if (flag == 0){
        a[i] = total;
      }
    }
  }
  for(int i=0;i<n-1;i++){
    cout<< a[i] << endl;
  }
  cout << 0 << endl;
  return 0;
}

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

cnt = 0
for i in range(N + 1):
    for j in range(N + 1 - i * R):
        if i * R + j * G <= N and (N - i * R - j * G) % B == 0:
            cnt += 1
            
print(cnt)

Measured memory_bytes: 40428
import static java.lang.Integer.parseInt;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

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

		while (!(line = br.readLine().trim()).equals("0") && !line.isEmpty()) {

			int n = parseInt(line);
			int[][] cs = new int[n][5];
			for (int i = 0; i < n; i++) {
				StringTokenizer st = new StringTokenizer(br.readLine());
				cs[i][0] = parseInt(st.nextToken());
				cs[i][1] = parseInt(st.nextToken());
				cs[i][2] = parseInt(st.nextToken());
				cs[i][3] = parseInt(st.nextToken());
				cs[i][4] = cs[i][1] * 4 + cs[i][2] * 9 + cs[i][3] * 4;
			}

			int[] lim = new int[5];
			StringTokenizer st = new StringTokenizer(br.readLine());
			lim[1] = parseInt(st.nextToken());
			lim[2] = parseInt(st.nextToken());
			lim[3] = parseInt(st.nextToken());
			lim[4] = parseInt(st.nextToken());

			int sum = 0;
			outer: for (int i = 0; i < n; i++) {
				for (int j = 1; j < 5; j++) {
					if (cs[i][j] > lim[j])
						continue outer;
				}
				System.out.println(cs[i][0]);
				sum++;
			}
			if (sum == 0)
				System.out.println("NA");

		}

	}
}

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

          using namespace std;
          typedef long long ll;
          int a, b, c, d, i = 1;
int dfd[3232];
          int main()
          {
            cin >> a >> b >> c >> d;
            while(a > 0 && c > 0)  
            {
              if(i & 1)
                c -= b;
              else a -= d;
              i++;  
            }
            if(a <= 0)
              cout << "No";
            else cout << "Yes";  
          }

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

int main() {
	// your code goes here
	int n;
	cin >> n;
	long long int l[n+1];
	l[0]=2;
	l[1]=1;
	for(int i=0;i<n-1;i++){
		l[i+2]=l[i+1]+l[i];
	}
	cout << l[n] << endl;
	
	
	
	return 0;
}

Measured memory_bytes: 256
x=input()
n=len(x)
ans=[]
for i in range(2**(n-1)):
    s=format(i,"b").zfill(n-1)
    sprt=[0]
    for i in range(n-1):
        if s[i]=="1":
            sprt.append(i+1)
    sprt.append(n)
    for i in range(len(sprt)-1):
        ans.append(int(x[sprt[i]:sprt[i+1]]))
print(sum(ans))

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

int main() {
  int c[3][3];

  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      std::cin >> c[i][j];
    }
  }

  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      for (int k = 0; k < 3; k++) {
        for (int l = 0; l < 3; l++) {
          if (c[i][j] + c[k][l] != c[i][l] + c[k][j]) {
            std::cout << "No" << std::endl;
            return 0;
          }
        }
      }
    }
  }

  std::cout << "Yes" << std::endl;
  return 0;
}


Measured memory_bytes: 256
#define wi first
#define bl second
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> PII;
const int N = 100010;
const int M = 2*N;
int h[N], e[M], ne[M], idx;
const int mod = 1000000007;
ll black[N];
ll white[N];
int n;

PII dfs(int u, int pre) {
    ll res_w = 1;//白色
    ll res_b = 1;//黑色
    for(int i = h[u]; i != -1; i = ne[i]) {
        int j = e[i];
        if (j == pre) continue;
        PII res = dfs(j, u);
        res_w *= ((res.bl + res.wi) % mod);
        res_w %= mod;
        res_b *= res.wi;
        res_b %= mod;
    }
    return {res_w, res_b};
}

void add(int a, int b) {
    e[idx] = b;
    ne[idx] = h[a];
    h[a] = idx ++;
}
int main() {
    cin >> n;
    memset(h, -1, sizeof h);
    for(int i = 1; i < n; i ++) {
        int a, b;
        cin >> a >> b;
        add(a, b);
        add(b, a);
    }
    PII get = dfs(1, -1);
    cout << (get.wi + get.bl) % mod << endl;
    return 0; 
}

Measured memory_bytes: 7808
#include <iostream>
#include <string>
#include <vector>

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

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

int main() {
  int A, B, C;
  cin >> A >> B >> C;
  
  int m = A % B;
  if (m == C) {cout << "YES" << endl; return 0;}
  else {
    for (int i = 2; m != i * A % B; i++) {
      if (C == i * A % B) {
        cout << "YES" << endl;
        return 0;
      }
    }

    cout << "NO" << endl;
  }

  return 0;
}


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

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    if(a == 5 && b == 5 && c == 7){
        cout << "YES" << endl;
    } else if(a == 5 && b == 7 && c == 5){
        cout << "YES" << endl;
    } else if(a == 7 && b == 5 && c == 5){
        cout << "YES" << endl;
    } else { 
        cout << "NO" << endl;
    }
}


Measured memory_bytes: 256
n = int(input())
l = list(range(n+1))
l3=l[::3]
l5=l[::5]
l15=l[::15]
# print(l)
# print(l3)
# print(l5)
# print(l15)
sum_all = sum(l) - sum(l3) - sum(l5) + sum(l15)
print(sum_all)

Measured memory_bytes: 52916
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.Scanner;
class Main{


	static final int MOD = 1000000007;


	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);			//文字の入力
		int n = sc.nextInt();
		int[] d = new int[n];
		for(int i = 0;i < n;i++){
			d[i] = sc.nextInt();
		}
		int ans = 0;
		for(int i = 0;i < n;i++){
			for(int j = i + 1;j < n;j++){
				ans += d[i]*d[j];
			}
		}
		
		
		System.out.println(ans);

		
	}


	static long dijkstra(Edge[] edge,int n){

		long[] d = new long[n];		//始点からの最短距離
		Arrays.fill(d, 1l << 60);
		d[0] = 0;
		PriorityQueue<P> q = new PriorityQueue<>(Comparator.comparingLong(p-> p.cost));			//costをソート
		q.add(new P(0,0));

		while(!q.isEmpty()){
			P current = q.remove();
			if(current.to == n-1){
				return current.cost;
			}
			if(current.cost != d[current.to]){
				continue;
			}
			for(P next: edge[current.to]){
				if(d[next.to] > current.cost + next.cost){
					d[next.to] = current.cost + next.cost;
					q.add(new P(next.to, current.cost+next.cost));
				}
			}


		}
		return -1;



	}



	static int upperbond(int k,int currentindex, ArrayList<Pair> a,ArrayList<Pair> b,int[] aa,int[] bb){		//kより小さい最大の値をdataの中から探し、返す二分探索
		int min = -1;
		int max = a.size();

		while(max-min > 1){
			int mid = (max+min)/2;
			if(a.get(mid).from > k){
				max = mid;
			}else{
				min = mid;
			}
		}

		if(max == a.size()){
			max--;
		}
		for(int i = max; i>=0;i--){
			if(a.get(i).from <= bb[currentindex] && aa[currentindex] <= bb[a.get(i).end]){
				int tmp = a.get(i).end;
				a.get(i).end = a.get(currentindex).end;
				a.get(currentindex).end = tmp;

				return tmp;
			}
		}

		return -1;
	}

	static int lowerbond(int k, ArrayList<Integer> data){		//kより小さい最小の値をdataの中から探し、返す二分探索
		int min = -1;
		int max = data.size();

		while(max-min > 1){
			int mid = (max+min)/2;
			if(data.get(mid) >= k){
				max = mid;
			}else{
				min = mid;
			}
		}
		return data.get(min);
	}



	static int gcd(int a,int b){				//最大公約数を返す
		if(b == 0){
			return a;
		}else{
			return gcd(b, a%b);
		}
	}
	static long gcd(long a,long b){
		if(b == 0){
			return a;
		}else{
			return gcd(b, a%b);
		}
	}



	static long lcm (long a, long b) {
		long g = gcd(a,b);
		return a/g*b;
	}




}


class Edge extends ArrayList<P>{

}

class P{
	int to;
	long cost;
	P(int to,long cost){
		this.to = to;
		this.cost = cost;
	}
}


class Pair implements Comparable{
	int from;
	int end;
	@Override
	public int compareTo(Object other) {
		Pair otherpair = (Pair)other;

		return   from- otherpair.from;
	}








}






Measured memory_bytes: 24916
# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

K, N = MAP()
A = LIST()

A += [K+A[0]]
mx = 0
for i in range(N):
    mx = max(mx, A[i+1] - A[i])
ans = K - mx
print(ans)


Measured memory_bytes: 26444
/* Press F to pay respects */
#define _CRT_SECURE_NO_DEPRECATE
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds; 
using namespace std;
#define int long long int
#define SYNC std::ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
#define FRE freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
typedef long double ld;
typedef pair<int,int> ii;
typedef pair<int,ii> iii;
typedef vector<int> vi;
typedef vector<ii>   vii;
//typedef tree<int, null_type, less<int>, rb_tree_tag, 
//             tree_order_statistics_node_update> 
//    data_set;
#define rep(i,l,r)   for(int i=(l);i<(r);i++)
#define deb(x)     cout << (#x) << " is " << (x) << endl
#define dbg(x)     cout << x << ' '
#define here cout << " Hey baitch!!\n";
#define  pb push_back
#define  F  first
#define  S  second
#define all(v) (v).begin(),(v).end()
#define sz(a) (int)((a).size())
#define sq(x) ((x)*(x))
const int MOD = 1e9+7;
const int MOD1 = 998244353;
const int N = 2e5+5;
const int INF = 1000111000111000111LL;
const ld PI = 3.1415926535898;
int dp[10000][100][2];
int32_t main()
{
	SYNC
	string s;
	int d;
	cin >> s >> d;
	int n = sz(s);
	memset(dp,0,sizeof dp);
	for(int i = 0; i < (s[0]-'0'); i++)
		dp[0][i%d][0] += 1;
	dp[0][(s[0]-'0')%d][1] = 1;
	for(int i = 1; i < n; i++) {
		int cur_lim = s[i]-'0';
		for(int j = 0; j < d; j++) {
			for(int k = 0; k < 10; k++) {
				dp[i][(k+j)%d][0] += dp[i-1][j][0];
				dp[i][(k+j)%d][0] %= MOD;
				if(k < cur_lim) {
					dp[i][(k+j)%d][0] += dp[i-1][j][1];
					dp[i][(k+j)%d][0] %= MOD;
				}
			}
			if(dp[i-1][j][1]) {
				dp[i][(j+cur_lim)%d][1] += dp[i-1][j][1];
				dp[i][(j+cur_lim)%d][1] %= MOD;
			}	
		}
	}
	int ans = (dp[n-1][0][1]+dp[n-1][0][0] + MOD-1)%MOD;
	ans = max(ans,0LL);
	cout << ans;
    return 0;
}

Measured memory_bytes: 15872
hp_t, attack_t, hp_a, attack_a = map(int, input().split())
def battle(hp_t, attack_t, hp_a, attack_a, p):
    
    if p == 't':
        hp_a -= attack_t
    else:
        hp_t -= attack_a
        
    if hp_t <= 0:
        return 'No'
    elif hp_a <= 0:
        return 'Yes'
    
    return battle(hp_t, attack_t, hp_a, attack_a, 't' if p == 'a' else 'a')
print(battle(hp_t, attack_t, hp_a, attack_a, 't'))

Measured memory_bytes: 9192
import java.io.*;
import java.util.Arrays;
import java.util.stream.IntStream;

public class Main {
  public static void main(String[] args) {
    new Main().run();
  }

  private void run() {
    try(BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(System.out)) {

      final int MAX = 100000;
      int n = Integer.parseInt(in.readLine());

      int[] table = new int[MAX+1];
      in.lines()
        .limit(n)
        .map(s -> s.split(" "))
        .map(a -> Arrays.stream(a).mapToInt(Integer::parseInt).toArray())
        .forEach(a -> IntStream.rangeClosed(a[0],a[1])
          .forEach(i -> table[i] = 1)
        );

      final int ans = Arrays.stream(table).sum();
      System.out.println(ans);
    }
    catch(IOException e) {
      System.err.println(e);
    }
  }
}

Measured memory_bytes: 26836
#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n,w;
    cin >> n >> w;
    int val[n],wt[n];
    for(int i=0;i<n;i++)
        cin >> wt[i] >> val[i];
    
    int ma=1e5+1;
    int dp[ma];
    for(int i=0;i<ma;i++)
        dp[i]=INT_MAX;
    dp[0]=0;
    for(int i=0;i<n;i++){
        for(int j=ma;j>0;j--){
            if(j>=val[i]){
                dp[j]=min(dp[j],dp[j-val[i]]+wt[i]);
            }
        }
    }
    int nas=0;
    for(int i=0;i<ma;i++)
        if(dp[i]<=w)
            nas=i;
    cout << nas;
}

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

int main(){
    ll n,a,b,c,d,e;
    cin >> n >> a >> b >> c >> d >> e;
    ll neck = min(min(min(min(a,b),c),d),e);
    ll res = (n-1)/neck + 5;
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
const int INF = 1e9 + 7;

const int N = (int)1e5;
int dp[N];
int hs[N];

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

	int n, k;
	cin >> n >> k;
	for (int i = 0; i < n; ++i) {
		cin >> hs[i];
	}
	for (int i = 1; i < n; ++i) {
		dp[i] = INF;
		for (int j = i-1; j >= max(0, i-k); --j) {
			dp[i] = min(dp[i], dp[j] + abs(hs[j] - hs[i]));
		}
	}
	cout << dp[n-1] << '\n';
}


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

int main(){
    int N,L;
    cin >> N >> L;
    vector<int> LL(N);
    int mintaste=1000;
    int ans=0;
    int Ntaste=0;
    for(int i=0; i<N; i++){
        LL.at(i) = L+i; //味を配列にいれた。
        Ntaste += LL.at(i);
        if(abs(mintaste) > abs(LL.at(i)) ){
            mintaste = LL.at(i);
        }
    }
    cout << Ntaste - mintaste;   
}


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

int main() {
	int A, B, C, D,T;
	cin >> A >> B >> C >> D;
	if (C <= B) {
		if (D >= B&&C>=A) T = B - C;
               if(D>=B&&C<=A) T=B-A;
		if (D<=B&&C>=A) T = D - C;
		if (D <=B&&C <=A) T = D - A;
		if (D <= A) T = 0;
		}
	else T = 0;
	cout << T;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <functional>
#include <iomanip>
#include <bitset>
#include <numeric>
#include <queue>
#include <map>
#include <cstdint>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
const long long mod = 1000000007;
typedef long long int ll;
typedef pair<int, int> P;
const vector<int> di = { -1, 0, 1, 0 };
const vector<int> dj = { 0, 1, 0, -1 };


int main() {

	int n;
	cin >> n;

	vector<int> pn;
	vector<int> cnt;

	for (int i = 2; i < n + 1; ++i) {
		int num = i;
		bool check = true;
		while (check) {
			for (int j = 2; j < num + 1; j++) {
				if (j == num) check = false;
				if (num % j == 0) {
					num = num / j;
					if (num == 1) {
						check = false;
					}
					if (pn.size() == 0) {
						pn.push_back(j);
						cnt.push_back(1);
						break;
					}
					rep(k, pn.size()) {
						if (j == pn.at(k)) {
							cnt.at(k)++;
							break;
						}
						else if (k == pn.size() - 1) {
							pn.push_back(j);
							cnt.push_back(1);
							break;
						}
					}
					break;
				}
			}
		}
	}

	
	ll ans = 1;
	rep(i, cnt.size()) {
		ans = ans * (cnt.at(i) + 1) % mod;
	}

	cout << ans << endl;


	
	return 0;
}

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

int main() {
	int a, b;
	while (cin >> a >> b) {
		if (a + b < 10)
			cout << "1" << endl;
		else if (a + b < 100)
			cout << "2" << endl;
		else if (a + b < 1000)
			cout << "3" << endl;
		else if (a + b < 10000)
			cout << "4" << endl;
		else if (a + b < 100000)
			cout << "5" << endl;
		else if (a + b < 1000000)
			cout << "6" << endl;
		else if (a + b < 10000000)
			cout << "7" << endl;
		else if (a + b < 100000000)
			cout << "8" << endl;
		else if (a + b < 10000000000)
			cout << "9" << endl;
	}
	return 0;
}

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

int main(){
 int a,b,d,r;
cin >>a>>b;
d=a/b;
r=a%b;
double f=1.00000*a/b;
cout<<d<<" "<<r<<" ";
cout <<fixed<< setprecision(5)<<f<<endl;
    return 0;
}

Measured memory_bytes: 1244
#include<bits/stdc++.h>
#define f(n) ((n+1LL)*(n)/2)
using namespace std;
const int mod = 1e9 + 7;
int main() {
    int n, k; cin >> n >> k;
    long long ans = 1;
    for (int i = k; i <= n; i++) 
        ans = (ans + f(n) - f(n - i) - f(i - 1) + 1) % mod;
    cout << ans;
}

Measured memory_bytes: 3592
import sys
from operator import itemgetter

sys.setrecursionlimit(10 ** 7)
rl = sys.stdin.readline


class SegmentTree:
    def __init__(self, init_value: list, segfunc, ide_ele):
        n = len(init_value)
        self.N0 = 1 << (n - 1).bit_length()
        self.ide_ele = ide_ele
        self.data = [ide_ele] * (2 * self.N0)
        self.segfunc = segfunc
        
        for i, x in enumerate(init_value):
            self.data[i + self.N0 - 1] = x
        for i in range(self.N0 - 2, -1, -1):
            self.data[i] = self.segfunc(self.data[2 * i + 1], self.data[2 * i + 2])
    
    def update(self, k: int, x):
        k += self.N0 - 1
        ################################################################
        self.data[k] = x
        ################################################################
        while k:
            k = (k - 1) // 2
            self.data[k] = self.segfunc(self.data[k * 2 + 1], self.data[k * 2 + 2])
    
    def query(self, left: int, right: int):
        L = left + self.N0
        R = right + self.N0
        res = self.ide_ele
        ################################################################
        
        while L < R:
            if L & 1:
                res = self.segfunc(res, self.data[L - 1])
                L += 1
            if R & 1:
                R -= 1
                res = self.segfunc(res, self.data[R - 1])
            L >>= 1
            R >>= 1
        
        ################################################################
        return res


def solve():
    N, Q = map(int, rl().split())
    events = []
    xs = set()
    for _ in range(N):
        s, t, x = map(int, rl().split())
        events.append((t - x, 0, x))
        events.append((s - x, 1, x))
        xs.add(x)
    for _ in range(Q):
        d = int(rl())
        events.append((d, 2, -1))
    events.sort(key=itemgetter(0, 1))
    
    x_to_idx = {x: idx for idx, x in enumerate(sorted(xs))}
    M = len(xs)
    ide_ele = 10 ** 10
    seg_tree = SegmentTree([ide_ele] * M, min, ide_ele)
    
    ans = []
    for _, com, pos in events:
        if com == 0:
            seg_tree.update(x_to_idx[pos], ide_ele)
        elif com == 1:
            seg_tree.update(x_to_idx[pos], pos)
        else:
            tmp = seg_tree.data[0]
            ans.append(tmp if tmp != ide_ele else -1)
    print(*ans, sep='\n')


if __name__ == '__main__':
    solve()


Measured memory_bytes: 241192
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>

using lint = long long;

void solve() {
    int x, y, a, b, c;
    std::cin >> x >> y >> a >> b >> c;

    std::vector<lint> ps(a), qs(b), rs(c);
    for (auto& p : ps) std::cin >> p;
    for (auto& q : qs) std::cin >> q;
    for (auto& r : rs) std::cin >> r;

    std::sort(ps.rbegin(), ps.rend());
    std::sort(qs.rbegin(), qs.rend());
    std::sort(rs.rbegin(), rs.rend());

    lint rsum = std::accumulate(ps.begin(), ps.begin() + x, 0LL);

    lint gsum = 0;
    int qi = 0, ri = 0;
    while (qi + ri < y) {
        if (ri == c || (qi < b && qs[qi] > rs[ri])) {
            gsum += qs[qi++];
        } else {
            gsum += rs[ri++];
        }
    }

    lint ans = rsum + gsum;
    int fri = 0;
    for (int pi = x - 1; pi >= 0; --pi) {
        rsum -= ps[pi];

        if (fri >= c) break;
        fri++;

        if (fri <= ri &&
            (ri == c || (qi < b && qs[qi] > rs[ri]))) {
            gsum += qs[qi++];
        } else {
            gsum += rs[ri++];
        }

        ans = std::max(ans, rsum + gsum);
    }

    std::cout << ans << std::endl;
}

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

    solve();

    return 0;
}


Measured memory_bytes: 2560
void main(){
	int[] x = _scanln!()();
	foreach(i, elm; x){
		if(elm == 0){
			writeln(i+1);
			return;
		}	
	}
}

import std.stdio, std.conv, std.algorithm, std.numeric, std.string;

// 1要素のみの入力
T _scan(T= int)(){
	return to!(T)( readln().chomp() );
}

// 1行に同一型の複数入力
T[] _scanln(T = int)(){
	T[] ln;
	foreach(string elm; readln().chomp().split()){
		ln ~= elm.to!T();
	}
	return ln;
}


Measured memory_bytes: 2676
#include<stdio.h>

int main(){
  int a,b,c,i,count=0;
  scanf("%d %d %d",&a,&b,&c);
  
  for(i=a;i<=b;i++){
    if(c%i==0){
      count++;
    }
  }

  printf("%d\n",count);
  
  return 0;
}

Measured memory_bytes: 596
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder.AtCoder_Begginer_Contest_158
{
    class B
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            long N = long.Parse(input[0]);
            long A = long.Parse(input[1]);
            long B = long.Parse(input[2]);

            long quotient = N / (A + B);
            long remainder = N % (A + B);
            long answer = quotient * A + (A < remainder ? A : remainder);
            Console.WriteLine(answer);
        }
    }
}


Measured memory_bytes: 13140
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ALDS1_3_A
{
    public class Program

    {
        public static void Main(string[] args)
        {
            string[] line = ReadStAr();
            Stack<int> numbers = new Stack<int>();

            for (int i = 0 ; i < line.Length ; i++)
            {

                int a, b;
                switch (line[i])
                {
                    case "+":
                        a = numbers.Pop();
                        b = numbers.Pop();
                        numbers.Push(b + a);
                        break;
                    case "-":
                        a = numbers.Pop();
                        b = numbers.Pop();
                        numbers.Push(b - a);
                        break;
                    case "*":
                        a = numbers.Pop();
                        b = numbers.Pop();
                        numbers.Push(b * a);
                        break;
                    default:
                        numbers.Push(int.Parse(line[i]));
                        break;
                }
            }

            Console.WriteLine(numbers.Pop());
        }

        static string ReadSt() { return Console.ReadLine(); }
        static int ReadInt() { return int.Parse(Console.ReadLine()); }
        static long ReadLong() { return long.Parse(Console.ReadLine()); }
        static double ReadDouble() { return double.Parse(Console.ReadLine()); }
        static string[] ReadStAr(char sep = ' ') { return Console.ReadLine().Split(sep); }
        static int[] ReadIntAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => int.Parse(e)); }
        static long[] ReadLongAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => long.Parse(e)); }
        static double[] ReadDoubleAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => double.Parse(e)); }

    }

}



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

int main() {
  string S;
  cin >> S;
  int a;

  for (int x = 0; x < S.size(); x++){
  	if (S.at(x) == '7')
  		break;
    a = x +1 ;
  }
  if ( a  == S.size())
  	cout << "No";
  else
  	cout << "Yes";

}


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

#define pb push_back
#define all(c) c.begin(),c.end()
#define allr(c) c.rbegin(),c.rend()
#define MOD 1000000007
#define PI 3.14159265
#define endl '\n'
#define MAX 501
using namespace std;

void quick () {
    cin.tie(0);
    cout.tie(0);
    ios_base::sync_with_stdio(0);
}

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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
     int a , b ;
    cin >> a >> b ;
    bool state = false ;
    for (int i = 1 ; i <= 3 ; i++){
        if (a*b*i%2!=0)state=true;
    }
    if (state){
        cout << "Yes";
    }else {
        cout << "No";
    }
    return 0;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h> 
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <iomanip>
#include <assert.h>
using namespace std;
typedef long long ll;
vector<ll> g[200005];
#define pi 3.14159265358979
ll ok[200005]={0};
ll n,m; 
int main()
{
	double a,b,h,m;
	scanf("%lf%lf%lf%lf",&a,&b,&h,&m);
	double y=2*pi*(h/12.0+m/60.0/12.0-m/60.0);
	
	y=fabs(y);
	double ans=b*b+a*a-2*a*b*cos(y);
	printf("%.12lf",sqrt(ans));
}

Measured memory_bytes: 8880
while(True):
    H, W = map(int, input().split())
    if(H == W == 0):
        break
    str = "#." * (W // 2 + 1)
    for i in range(H):
        if(i % 2 == 0):
            print(str[:W:])
        else:
            print(str[1:W + 1:])
    print()


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

int main() {
  
  int a;
  int S1;
  int S2;
  int S3;
  
  cin >> a;
  S1 = a/100;
  S2 = (a-S1*100)/10;
  S3 = a-S1*100-S2*10;
  cout << S1+S2+S3 << endl;
  
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;

public class Main {
	static FastReader in = new FastReader();

	public static void main(String[] args) {
		solve();
	}

	static void solve() {
		char[] s = in.nextLine().toCharArray();
		char[] t = in.nextLine().toCharArray();
		
		
		int n = s.length;
		int n2 = t.length;
		
		int min = n2;
		for(int i = 0; i < n - n2 + 1; i++)
		{
			int curr = 0;
			int count = 0;
			for(int j = i; j < i + n2; j++)
			{
				if(s[j] != t[count]) curr++;
				count++;
			}
			min = Math.min(curr, min);
		}
		
		System.out.println(min);
	}

	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}

		int[] readarr(int abc) {
			int[] a = new int[abc];
			for (int i = 0; i < abc; i++)
				a[i] = nextInt();
			return a;
		}
	}
}





Measured memory_bytes: 32584
A=[list(map(int,input().split())) for _ in range(3)]
N=int(input())
b=[int(input()) for _ in range(N)]
G=[['*']*3,['*']*3,['*']*3]
for i in range(3):
  for j in range(3):
    if A[i][j] not in b:
      G[i][j]=A[i][j]

if G[0][0]==G[1][1]==G[2][2]=='*':
  print('Yes')
  exit()
elif G[0][2]==G[1][1]==G[2][0]=='*':
  print('Yes')
  exit()
else:
  for i in range(3):
    if G[i][0]==G[i][1]==G[i][2]=='*':
      print('Yes')
      exit()
    elif G[0][i]==G[1][i]==G[2][i]=='*':
      print('Yes')
      exit()

print('No')

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

int main(void) {
    string s,t;
    cin >> s >> t;
    string tmp = s;
    for(int i=0;i<s.size();i++) {
        tmp = tmp[s.size()-1] + tmp.substr(0,s.size()-1);
        if(tmp == t) {
            cout << "Yes\n";
            return 0;
        }
    }
    cout << "No\n";
    
    return 0;
}


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

int f(int t)
{
    if(t < 0)
    {
        t += N;
    }
    return t;
}

int main()
{
    
    cin >> N;
    cin >> x;
    
    vector<vector<long>> data(N,vector<long>(N));
    
    
    for(int i=0;i<N;i++)
    {
        cin >> data[i][0];
    }
    
    for(int j = 1;j<N;j++)
    {
        data[0][j] = data[N-1][j-1] + x;
        for(int i=1;i<N;i++)
        {
            data[i][j] = data[i-1][j-1] + x;
        }
    }
    
    vector<long> ans(N,0);
    vector<long> mini(N);
    mini = data[0];

    for(int k = 0;k<N;k++) //魔法回数
    {
        long temp = 0;
        for(int i = 0;i<N;i++)
        {
            mini[i] = min(mini[i],data[f(i-k)][0]);
            temp += mini[i];
        }
        ans[k] = temp + k * x;
    }
    
    
    sort(ans.begin(),ans.end());
    
    cout << ans[0] << endl;
    
    return 0;
    
}

Measured memory_bytes: 31616
object Main {
  def main(args: Array[String]): Unit = {
    val s = new Main()
    s.solve()
    s.out.flush()
  }
}

class Main {
  import java.io._
  import java.util.StringTokenizer

  import scala.collection.mutable
  import scala.util.Sorting
  import math.{abs, max, min}
  import mutable.{ArrayBuffer, ListBuffer}
  import scala.reflect.ClassTag

  val MOD = 1000000007
  val out = new PrintWriter(System.out)

  def solve(): Unit = {
    val N, S = nl()

    def f(b: Long, n: Long): Long = {
      if (n < b) n
      else {
        n % b + f(b, n / b)
      }
    }

    var ans = Long.MaxValue
    // b <= sqrt(N)
    REP(math.ceil(math.sqrt(N)).toInt, 2) { b =>
      if (f(b, N) == S) ans = min(b, ans)
    }

    // b > sqrt(N)
    REP(math.sqrt(N).toInt, 1) { c1 =>
      if ((N - S) % c1 == 0) {
        val b = (N - S) / c1 + 1
        if (b >= 2 && f(b, N) == S) ans = min(b, ans)
      }
    }

    // c1 = 0, c0 = N
    if (N == S) ans = N + 1

    if (ans == Long.MaxValue) ans = -1
    out.println(ans)
  }

  class InputReader(val stream: InputStream) {
    private val reader = new BufferedReader(new InputStreamReader(stream), 32768)
    private var tokenizer: StringTokenizer = _

    def next(): String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new StringTokenizer(reader.readLine)
      tokenizer.nextToken
    }

    def nextInt(): Int = next().toInt
    def nextLong(): Long = next().toLong
    def nextChar(): Char = next().charAt(0)
  }
  val sc = new InputReader(System.in)
  def ni(): Int = sc.nextInt()
  def nl(): Long = sc.nextLong()
  def nc(): Char = sc.nextChar()
  def ns(): String = sc.next()
  def ns(n: Int): Array[Char] = ns().toCharArray
  def na(n: Int, offset: Int = 0): Array[Int] = map(n)(_ => ni() + offset)
  def na2(n: Int, offset: Int = 0): (Array[Int], Array[Int]) = {
    val A1, A2 = Array.ofDim[Int](n)
    REP(n) { i =>
      A1(i) = ni() + offset
      A2(i) = ni() + offset
    }
    (A1, A2)
  }
  def nm(n: Int, m: Int): Array[Array[Int]] = {
    val A = Array.ofDim[Int](n, m)
    REP(n) { i =>
      REP(m) { j =>
        A(i)(j) = ni()
      }
    }
    A
  }
  def nal(n: Int): Array[Long] = map(n)(_ => nl())
  def nm_c(n: Int, m: Int): Array[Array[Char]] = map(n) (_ => ns(m))
  def REP(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = offset
    val N = n + offset
    while(i < N) { f(i); i += 1 }
  }
  def REP_r(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = n - 1 + offset
    while(i >= offset) { f(i); i -= 1 }
  }

  def map[@specialized A: ClassTag](n: Int, offset: Int = 0)(f: Int => A): Array[A] = {
    val res = Array.ofDim[A](n)
    REP(n)(i => res(i) = f(i + offset))
    res
  }


  def sumL(as: Array[Int]): Long = {
    var s = 0L
    REP(as.length)(i => s += as(i))
    s
  }

  def cumSum(as: Array[Int]) = {
    val cum = Array.ofDim[Long](as.length + 1)
    REP(as.length) { i =>
      cum(i + 1) = cum(i) + as(i)
    }
    cum
  }
}

Measured memory_bytes: 27444
#include <stdio.h>
  int main(){
    int a,b,c;
    int emp;
    scanf("%d %d %d\n",&a,&b,&c);

    if(a>b){
      emp = b;
      b = a;
      a = emp;
    }
    if(b>c){
      emp = c;
      c = b;
      b= emp;
    }
    if(a>b){
      emp = b;
      b = a;
      a = emp;
    }
    printf("%d %d %d\n",a,b,c);
    return 0;
    
  }


Measured memory_bytes: 2100
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <unordered_map>
#include <set>
#include <map>
#define INCANT cin.tie(0), cout.tie(0), ios::sync_with_stdio(0), cout << fixed << setprecision(20);
#define rep(i,n) for (int i=0; i<n;++i)
#define ALL(a)  (a).begin(),(a).end()
#define PI 3.14159265358979
typedef long long ll;
using namespace std;
const ll MOD = 1e9+7LL;
const int INF = 2e9;
int N;
int x,y,z;
int main() {
  INCANT;
  cin >> N;
  int a;
  
  rep(i, N) {
    cin >> a;
    if (a%4==0) x++;
    else if (a%2==0) y++;
    else z++;
  }
  string ans = (x>=z || (z==x+1 && y==0))?"Yes":"No";
  cout << ans << "\n";
  
  return 0;
}

Measured memory_bytes: 384
#define D(x) cout << #x " = " << x << endl
#define DD(x, y) cout << "(" #x ", " #y ") = (" << x << ", " << y << ")" << endl
#define DDD(x, y, z) cout << "(" #x ", " #y ", " #z ") = (" << x << ", " << y << ", " << z << ")" << endl
#define DV(v) for (auto __macro_vi : v){ cout << __macro_vi << " ";} cout << endl;
#define DA(a, n) for (int __macro_i = 0; __macro_i < n; ++__macro_i) { cout << a[__macro_i] << " "; } cout << endl;
#define REP(i, n) for (int i = 0; i < n; ++i)
#define ALL(v) (v).begin(), (v).end()
#include<iostream>
#include<vector>
#include<cassert>
#include<cmath>

using namespace std;
using ll = long long;

ll cost[1 << 16];
ll dp[1 << 16];
int n;
int a[16][16];
int main()
{
    cin >> n;
    REP(i, n) REP(j, n) cin >> a[i][j];
    
    REP(mask, 1 << n) {
        ll tmp = 0;
        REP(i, n) {
            for (int j = i + 1; j < n; ++j) {
                if (((mask >> i) & 1) == 0) continue;
                if (((mask >> j) & 1) == 0) continue;
                tmp += a[i][j];
            }
        }
        cost[mask] = tmp;
    }

    for (int mask = 0; mask < (1 << n); ++mask) {
        dp[mask] = 0;
        for (int mask2 = mask; mask2 > 0; mask2 = (mask2 - 1) & mask) {
            dp[mask] = max(dp[mask], dp[mask ^ mask2] + cost[mask2]);
        }
        // DD(mask, dp[mask]);
    }
    cout << dp[(1 << n) - 1] << endl;
}


Measured memory_bytes: 1280
import sys

sys.setrecursionlimit(500005)
stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n = ni() - 1
l = 1

nus = [1]
for i in range(20):
    nus.append(nus[-1] * 26)

while True:
    if n < nus[l]:
        s = ""
        for i in range(l):
            s += chr(n%26+97)
            n //= 26
        print(s[::-1])
        break
    n -= nus[l]
    l += 1


Measured memory_bytes: 61788
#![allow(unused_imports)]

use proconio::{input, fastout};
use proconio::marker::*;
use nalgebra::min;

#[fastout]
fn main() {
    input! {
    n: usize,
    m: usize,
    ac: [(usize, [Usize1]);m]
    }
    let mut dp = vec![std::usize::MAX; 1 << n];
    dp[0] = 0;
    for i in 0..m {
        let t = ac[i].1.iter().map(|&x| 1 << x).fold(0, |acc, x| acc | x);
        for j in 0..1 << n {
            dp[j | t] = min(dp[j | t], dp[j].saturating_add(ac[i].0))
        }
    }
    let ans = dp[(1 << n) - 1];
    if ans == std::usize::MAX { println!("-1") } else {
        println!("{}", ans);
    }
}


Measured memory_bytes: 2248
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cstring>
#include<math.h>
#include<bitset>
#include<queue>
#include<set>
#include<iomanip>
#include<math.h>
#include<assert.h>
#include<string>
#include<cstdlib>
//#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long INF = 1LL << 40;
const double INFD = 1e100;
const ll mod = 1000000007;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
// ----------------------------------------------------------------------------

int main(){
  ll N,x;
  cin >> N >> x;
  vector<ll> a(N+1);
  for(int i=1; i<=N; i++){
    cin >> a[i];
  }
  ll ans=0;
  for(int i=1; i<N; i++){
    ll sum;
    sum = a[i] + a[i+1];
    if(sum <= x) continue;
    ans += sum-x;
    a[i+1] -= min(a[i+1],sum-x);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1024
n, m = map(int, input().split())
dct = {}
exist = True
for _ in range(m):
    s, c = map(int, input().split())
    if n != 1 and s == 1 and c == 0:
        exist = False

    if s in dct.keys():
        if dct[s] != c:
            exist = False
    else:
        dct[s] = c

if (not(1 in dct.keys())) and n != 1:
    dct[1] = 1

if exist:
    ans = 0
    for s, c in dct.items():
        ans += c*10**(n-s)
    print(ans)
else:
    print(-1)

Measured memory_bytes: 3064
using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using static System.Math;
using System.Numerics;
static class Program{
	const int mod=(int)1e9+7;
	const double eps=1e-11;
	static void Main(){
		Sc sc=new Sc();
		var s=sc.Ia;
		var h=sc.Arr(s[0],()=>sc.Ia);
		int m=1<<s[0];
		var dp=new int[m];
		int ans=mod;
		for(int i = 0;i<m;i++) {
			var c=new int[s[1]+1];
			c[0]=s[2];
			int p=0;
			for(int j = 0;1<<j<=i;j++) {
				if(((1<<j)&i)!=0){
					p+=h[j][0];
					for(int k = 1;k<=s[1];k++) {
						c[k]+=h[j][k];
					}
				}
			}
			if(c.Min()>=s[2]){ans=Min(ans,p);}
		}
		Console.WriteLine("{0}",ans==mod?-1:ans);
	}
}
public class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
	public object[] Oa{get{return Console.ReadLine().Split();}}
	public int[] Ia2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),int.Parse);}}
	public int[] Ia3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),int.Parse);}
	public int[] Ia3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),int.Parse);}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),long.Parse);}}
	public long[] La3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),long.Parse);}
	public long[] La3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),long.Parse);}
	public double[] Da2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),double.Parse);}}
	public double[] Da3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),double.Parse);}
	public double[] Da3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),double.Parse);}
	public T[] Arr<T>(int n,Func<T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f();}return a;}
	public T[] Arr<T>(int n,Func<int,T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i);}return a;}
	public T[] Arr<T>(int n,Func<string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(Console.ReadLine().Split());}return a;}
	public T[] Arr<T>(int n,Func<int,string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i,Console.ReadLine().Split());}return a;}
}

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

int main(void){
    char s[200020],t[200020];
    scanf("%s%s",s,t);
    int x[27],y[27];
    for (int i=0; i<27; i++){
        x[i]=-1;
        y[i]=-1;
    }
    for (int i=0; i<strlen(s); i++){
        if (x[s[i]-'a']==-1){
            x[s[i]-'a']=t[i]-'a';
        } else {
            if (x[s[i]-'a']!=t[i]-'a'){
                printf("No\n");
                return 0;
            }
        }
    }
    for (int i=0; i<strlen(t); i++){
        if (y[t[i]-'a']==-1){
            y[t[i]-'a']=s[i]-'a';
        } else {
            if (y[t[i]-'a']!=s[i]-'a'){
                printf("No\n");
                return 0;
            }
        }
    }
    printf("Yes\n");
    return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin>>n;
  string s,t,a;
  cin>>s>>t;
  for(int i=0;i<n;i++)
  {
    a +=s[i];
    a+=t[i];
  }
  cout<<a<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < (b); i++)
#define rrep(i, a, b) for (int i = a; i >= (b); i--)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
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;
}
void hr() {
   cerr << "--------------" << endl;
}
const int INF = 1001001001;
const int MOD = 1000000007;

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

   int n, k;
   cin >> n >> k;
   vector<int> a(n);
   rep(i, 0, n) cin >> a[i];
   sort(a.rbegin(), a.rend());

   int l = 0, r = 1e9;
   while (r - l > 1) {
      int mid = (l + r) / 2;
      auto f = [&](int mid) {
         int cnt = 0;
         rep(i, 0, n) {
            cnt += a[i] / mid;
            if (a[i] % mid) cnt++;
            cnt--;
         }
         return cnt <= k;
      };
      if (f(mid))
         r = mid;
      else
         l = mid;
   }
   cout << r << endl;
   return 0;
}

Measured memory_bytes: 3972
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;


public class Main {
    int[] x;
    private void solve() {
        x = nextIntArray(5);
        for(int i = 0;i < 5;i++) {
            if (x[i] == 0) {
                out.println(i + 1);
            }
        }
    }

    public static void main(String[] args) {
        out.flush();
        new Main().solve();
        out.close();
    }

    /* Input */
    private static final InputStream in = System.in;
    private static final PrintWriter out = new PrintWriter(System.out);
    private final byte[] buffer = new byte[4096];
    private int p = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (p < buflen)
            return true;
        p = 0;
        try {
            buflen = in.read(buffer);
        } catch (IOException e) {
            e.printStackTrace();
        }
        if (buflen <= 0)
            return false;
        return true;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrint(buffer[p])) {
            p++;
        }
        return hasNextByte();
    }

    private boolean isPrint(int ch) {
        if (ch >= '!' && ch <= '~')
            return true;
        return false;
    }

    private int nextByte() {
        if (!hasNextByte())
            return -1;
        return buffer[p++];
    }

    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = -1;
        while (isPrint((b = nextByte()))) {
            sb.appendCodePoint(b);
        }
        return sb.toString();
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }

    public int[] nextIntArray(int n) {
        int[] x = new int[n];
        for(int i = 0;i < n;i++) {
            x[i] = nextInt();
        }
        return x;
    }

    public long[] nextLongArray(int n) {
        long[] x = new long[n];
        for(int i = 0;i < n;i++) {
            x[i] = nextLong();
        }
        return x;
    }

    public double[] nextDoubleArray(int n) {
        double[] x = new double[n];
        for(int i = 0;i < n;i++) {
            x[i] = nextDouble();
        }
        return x;
    }
}

Measured memory_bytes: 32432
// cout << "Case #" << k << ": ";
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
typedef long long ll;
#define MOD 1000000007
using namespace std;
int main() {
    ll n, k;
    cin >> n >> k;
    ll res = n % k;
    cout << min(res, k - res) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,j,k) for(int i = (int)j;i <= (int)k;i ++)
#define debug(x) cerr<<#x<<":"<<x<<endl
const int maxn=(int)1e6+5;
int dp[maxn],h[maxn];
int main(){
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int n;
    cin>>n;
    rep(i,1,n)cin>>h[i];
    dp[1]=0;dp[2]=abs(h[1]-h[2]);
    rep(i,3,n){
        dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));
    }
    cout<<dp[n]<<endl;
}
/* 
i->i+1 or i+2, with cost |hi-hj|
dp[i]:走到i的花费
dp[i]=min(dp[i-1]+cost1,dp[i-2]+cost2)
 */

Measured memory_bytes: 4736
#include<bits/stdc++.h>
using namespace std;
#define int long long

struct edge{ int to,cost; };
const int N = 2e5+10;
vector< edge > G[N];

signed main(){

  int n; cin >> n;
  for(int i = 0; i < n-1; i++){
    int u,v,w; cin >> u >> v >> w;
    u--,v--;
    G[u].push_back({v,w});
    G[v].push_back({u,w});
  }

  vector<int> table(n,-1);
  table[0] = 1;
  queue<int> q;
  q.push(0);
  while(!q.empty()){
    int p = q.front(); q.pop();
    for(edge e : G[p]){
      if(table[e.to] != -1) continue;
      if(e.cost%2 == 0){
        table[e.to] = table[p];
      }
      else {
        table[e.to] = 1 - table[p];
      }
      q.push(e.to);
    }
  }

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

  return 0;
}


Measured memory_bytes: 11008
def gcd(a,b):
    if b % a == 0:
        return a
    return gcd(b % a, a)

A,B,C,D = list(map(int, input().split()))

c_num = B//C - (A-1)//C
d_num = B//D - (A-1)//D

g = gcd(C,D)
cd = C*D//g
cd_num = B//cd - (A-1)//cd

res = (B-A + 1) - (c_num + d_num - cd_num)

print(res)

Measured memory_bytes: 3060