akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<functional>
#define M 2100000
using namespace std;	
int main(void)
{
	int i,j,n,k,m,a[3001],b[3001],cost[3001],time[3001],kk,pp,bre;
	int p,q,r;
	int kin[101][101],zi[101][101];
	int flg[10001],leng[10001],min;
	int kaku,skin,szi;
	
	while(1) {
		scanf("%d %d",&n,&m);
		if(n==0 && m==0) break;
		for(i=1;i<=n;i++) scanf("%d %d %d %d",&a[i],&b[i],&cost[i],&time[i]);
		//??£??\????????????  ??????
		for(i=1;i<=m;i++) {
			for(j=1;j<=m;j++) {
				kin[i][j]=M;
			}
		}
		for(i=1;i<=m;i++) kin[i][i]=0;
		for(i=1;i<=n;i++)	kin[a[i]][b[i]]=cost[i];
		for(i=1;i<=n;i++)	kin[b[i]][a[i]]=cost[i];
		//??£??\???????????????
		for(i=1;i<=m;i++) {
			for(j=1;j<=m;j++) {
				zi[i][j]=M;
			}
		}
		for(i=1;i<=m;i++) zi[i][i]=0;
		for(i=1;i<=n;i++) zi[a[i]][b[i]]=time[i];
		for(i=1;i<=n;i++) zi[b[i]][a[i]]=time[i];
		scanf("%d",&k);
		for(i=1;i<=k;i++) {
			scanf("%d %d ",&p,&q);
			scanf("%d",&r);
			for(j=1;j<=m;j++) {
				leng[j]=M;
				flg[j]=0;
			}
			leng[p]=0;
			if(r==0) {
				for(j=1;j<=m;j++) {
					min=M;
					for(kk=1;kk<=m;kk++) {
						if(flg[kk]==0 && leng[kk]<min) {
							kaku=kk;
							min=leng[kk];
						}
					}
					flg[kaku]=1;
					for(kk=1;kk<=m;kk++) {
						if((leng[kaku]+kin[kaku][kk])<leng[kk]) leng[kk]=leng[kaku]+kin[kaku][kk];
					}
				}
				printf("%d\n",leng[q]);
			}
			else {
				for(j=1;j<=m;j++) {
					min=M;
					for(kk=1;kk<=m;kk++) {
						if(flg[kk]==0 && leng[kk]<min) {
							kaku=kk;
							min=leng[kk];
						}
					}
					flg[kaku]=1;
					for(kk=1;kk<=m;kk++) {
						if((leng[kaku]+zi[kaku][kk])<leng[kk]) leng[kk]=leng[kaku]+zi[kaku][kk];
					}
				}
				printf("%d\n",leng[q]);
			}
		}
		/*
			//cost
		printf("??????\n");
		printf("      ");
		for(i=1;i<=m;i++) printf("%7d ",i);
		printf("\n");
		printf("\n");
		for(i=1;i<=m;i++) {
			printf("%7d  ",i);
			for(j=1;j<=m;j++) {
				printf("%7d ",kin[i][j]);
			}
			printf("\n");
		}
		printf("\n");
		printf("\n");
		//time
		printf("??????\n");
		printf("      ");
		for(i=1;i<=m;i++) printf("%7d ",i);
		printf("\n");
		printf("\n");
		for(i=1;i<=m;i++) {
			printf("%7d  ",i);
			for(j=1;j<=m;j++) {
				printf("%7d ",zi[i][j]);
			}
			printf("\n");
		}
		printf("\n");*/
	}
		return 0;
}
	

Measured memory_bytes: 1168
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <cassert>
#include <cstdarg>
#include <sys/time.h>
#include <fstream>
//#include "cout.h"

using namespace std;

#define SZ(x) ((int)x.size())
#define MSET(x,a) memset(x, a, (int)sizeof(x))
#define PB push_back
#define VI vector < int >
#define PII pair < int, int >
#define LL long long
#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(), (v).end()
#define FIT(it,v) for (__typeof((v).begin()) it = (v).begin(); it != (v).end(); it++)
#define OUT(A) cout << #A << " = "<< (A) << endl
#define OUT2(A, B) cout << "(" << #A << ", " << #B << ") = (" << (A) << ", "<< (B) << ")" << endl
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }

#define present(c, e) ((c).find((e)) != (c).end())
#define cpresent(c, e) (find(ALL(c), (e)) != (c).end())

int n, k;
LL V[55];

void solve() {
  cin >> n >> k;
  REP(i, n) cin >> V[i];
  LL res = 0;

  FOR(l, -1, n) for(int r = n; r > l; r--) {
    vector<LL> v;
    REP(i, l+1) v.PB(V[i]);
    for(int i = n-1; i >= r; i--) v.PB(V[i]);
    if (SZ(v) > k) continue;
    int remain = k - SZ(v);
    LL sum = 0;
    sort(ALL(v));
    REP(i, SZ(v)) {
      if (v[i] < 0 && remain > 0) {
        remain--;
        continue;
      }
      sum += v[i];
    }
    chmax(res, sum);
  }
  cout << res << endl;
}

int main() {
	solve();
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
#include <iomanip>
#define MAX_L 100
using namespace std;

int n;
long double x[MAX_L], y[MAX_L];

int factorial(int n)
{
    if (n > 0)
    {
        return n * factorial(n - 1);
    }
    else
    {
        return 1;
    }
}

void solve()
{
    long double ans = 0;
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < n; j++)
        {
            ans += sqrt((x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]));
        }
    }

    ans /= double(n);

    cout << fixed << setprecision(10) << ans;
}

int main()
{
    cin >> n;

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

    solve();
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<list>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<set>
#include<map>
#include<queue>
#include<cstring>
#include<sstream>
using namespace std;

typedef long long ll;

int main() {
  int N; cin >> N;
  int x; cin >> x;
  int a[100010];
  for ( int i = 0; i < N; i++ ) cin >> a[i];
  ll ans = 0;
  for ( int i = 0; i < N-1; i++ ) {
    ll sum = a[i]+a[i+1];
    if ( sum > x ) {
      int res = sum - x;
      if ( res <= a[i+1] ) {
	ans += res;
	a[i+1] -= res;
      } else {
	ans += a[i+1];
	int tmp = a[i+1];
	a[i+1] = 0;
	ans += res-tmp;
      }
    }
  }
  cout << ans << endl;
  return 0;
}


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

#define REP(i,n) for (int i=0;i<(n);++i)
#define MOD 1000000007

using namespace std;

using ll = long long;

template <class T, T M>
class modulo {
public:
    T data;

    modulo(T data = 0) : data(data % M) {
    }

    modulo operator+(const modulo &x) const {
        return modulo(data + x.data);
    }

    modulo operator-(const modulo &x) const {
        return modulo(data + (M - x.data));
    }

    modulo operator*(const modulo &x) const {
        return modulo(data * x.data);
    }

    modulo operator/(const modulo &x) const {
        return modulo(data * x.inv().data);
    }

    modulo operator+=(const modulo &x) {
        data = (data + x.data) % M;
    }

    modulo operator-=(const modulo &x) {
        data = (data + (M - x.data)) % M;
    }

    modulo operator*=(const modulo &x) {
        data = (data * x.data) % M;
    }

    modulo operator/=(const modulo &x) {
        data = (data * x.inv().data) % M;
    }

    modulo inv() const {
        return _pow(M - 2);
    }

    template <class Integer>
    modulo operator^(Integer n) const {
        if (n >= 0) {
            return _pow(n);
        } else {
            return _pow(M - 1 - (-n) % (M - 1));
        }
    }

    friend std::ostream& operator<<(std::ostream &os, const modulo &x) {
        os << x.data;
        return os;
    }

private:
    template <class NonNegativeInteger>
    modulo _pow(NonNegativeInteger n) const {
        modulo result(1);
        modulo x(*this);
        while (n) {
            if (n & 1) {
                result *= x;
            }
            x *= x;
            n >>= 1;
        }
        return result;
    }
};

using mod = modulo<ll, MOD>;

int main() {
    int N;
    cin >> N;
    vector<ll> A(N);
    REP(i, N) {
        cin >> A[i];
    }

    mod x = 0;
    REP(k, 60) {
        ll cnt = 0;
        REP(i, N) {
            if (A[i] & (1ll << k)) {
                ++cnt;
            }
        }
        x += mod(cnt) * (cnt - 1) * (1ll << k);
    }
    mod y = 0, z = 0;
    REP(i, N) {
        y += A[i];
    }
    mod result = y * (N - 1) - x;
    cout << result << endl;

    return 0;
}

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


int main() {
  set<char> S;
  rep(i,3){
    char a;
    cin >> a;
    S.insert(a);
  }
  string ans = "No";
  if(S.size() == 3) ans = "Yes";
  cout << ans << endl;
  return 0;
  
}

Measured memory_bytes: 256
import sys

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

IN=lambda : map(int, input().split())
LIN=lambda : list(IN())
mod=1000000007

#+++++

def main():
	n = int(input())
	#b , c = IN()
	#s = input()
	al = LIN()
	c = 0
	nc = mod
	nnc = mod
	for cv, nv, nnv in zip(al, al[1:], al[2:]):
		nc = min(c + abs(cv - nv), nc)
		nnc = min(nnc, c+ abs(cv - nnv))
		c, nc, nnc = nc, nnc, mod
	nc = min(c + abs(al[-2] - al[-1]), nc)
	c = nc
	
	print(c)
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Measured memory_bytes: 13908
N = int(input())
s = []
l_cnt = []
for i in range(N):
  s.append(''.join(sorted(input())))

dic = {}
for x in s:
  if dic.get(x) == None:
    dic[x] = 1
  else:
    dic[x] += 1

print(sum(map(lambda n: n*(n-1)//2,list(dic.values()))))

Measured memory_bytes: 19400
#include <bits/stdc++.h>
#include <fstream>
using namespace std;
typedef long long lint;
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define repp(i,m,n) for(lint (i)=(m);(i)<(n);(i)++)
#define repm(i,n) for(lint (i)=(n-1);(i)>=0;(i)--)
#define INF (1ll<<60)
#define all(x) (x).begin(),(x).end()
const lint MOD =1000000007;
const lint MAX = 1000000;
using Graph =vector<vector<lint>>;
typedef pair<lint,lint> P;
typedef map<lint,lint> M;
 
lint fac[MAX], finv[MAX], inv[MAX];
 
void COMinit() 
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (lint i = 2; i < MAX; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
long long COM(lint n, lint k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
 
lint primary(lint num)
{
    if (num < 2) return 0;
    else if (num == 2) return 1;
    else if (num % 2 == 0) return 0;
 
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return 0;
        }
    }
 
    return 1;
}
   long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
    lint lcm(lint a,lint b){
        return a/__gcd(a,b)*b;
    }
     lint gcd(lint a,lint b){
        return __gcd(a,b);
    } 
 
 
  int main(){
     lint n,q,d;
     string s;
     cin>>n>>q>>d;
     lint ans=0;
     repp(i,n,q+1){
         if(i%d==0)ans++;
     }

     cout<<ans;
     }
     
 

Measured memory_bytes: 3556
#include<stdio.h>
	int main(void)
	{
	int a,b;
	scanf("%d %d",&a,&b);
	if(a<b)
		{
			printf("a < b\n");
		}
		else if(a>b)
		{
			printf("a > b\n");
		}
		else
		{
			printf("a == b\n");
		}
	return 0;
	}

Measured memory_bytes: 1008
#include <bits/stdc++.h>
#ifdef DEMETRIO
#define deb(...) fprintf(stderr,__VA_ARGS__)
#define deb1(x) cerr << #x << " = " << x << endl
#else
#define deb(...) 0
#define deb1(x) 0
#endif
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define fore(i,a,b) for(int i=a,ThxDem=b;i<ThxDem;++i)
#define SZ(x) ((int)x.size())
using namespace std;
typedef long long ll;

int n;
int a[2048];
bitset<(1<<21)> b;

int main(){
	scanf("%d",&n);
	b[0]=1;
	int r=0;
	fore(i,0,n){
		scanf("%d",a+i);
		r+=a[i];
		b|=b<<a[i];
	}
	r=(r+1)/2;
	while(!b[r])r++;
	printf("%d\n",r);
	return 0;
}

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N, a, b;
    vector<int> A, B;

    cin >> N;
    for (int i = 1; i <= N+1; i++) {
        cin >> a;
        A.push_back(a);
    }
    long long cnt = 0;
    int b2 = 0;
    for (int i = 0; i < N+1; i++) {
        if (i < N) {
            cin >> b;
        } else {
            b = 0;
        }
        cnt += min(A[i], b + b2);
        // cout << cnt << endl;
        if (b + b2 > A[i]) {
            b2 = min(b, b + b2 - A[i]);
        } else {
            b2 = 0;
        }
    }

    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 892
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		int[] okasiInfo = new int[n +1];
		for(int i = 0; i < k;i++) {
			int d = sc.nextInt();
			for(int j = 0; j < d;j++) {
				okasiInfo[sc.nextInt()]++;
			}
		}
		int answer = 0;
		for(int i = 1;i <= n;i++) {
			if(okasiInfo[i] ==0) {
				answer++;
			}
		}
		System.out.println(answer);
	}
}

Measured memory_bytes: 37496
n, k = map(int, input().split())
r, s, p = map(int, input().split())
t = list(input())

l = []
res = 0

for i in range(n):

    if t[i] == 'r':
        l.append('p')
    if t[i] == 's':
        l.append('r')
    if t[i] == 'p':
        l.append('s')
        
    if i >= k:
        if l[i] == l[i - k]:
            l[i] = 'x'
        
    if l[i] == 'r':
        res += r
    if l[i] == 's':
        res += s
    if l[i] == 'p':
        res += p
        
# print(l)
print(res)

Measured memory_bytes: 4792
fun main(args: Array<String>) {
    val S = readLine()!!
    val T = readLine()!!

    // LCS を記録するメモ配列を初期化
    val dp = Array(3001) { IntArray(3001) { 0 } }

    // 二重ループで メモを埋めていく
    for (i in 1..S.length) {
        for (j in 1..T.length) {
            // 条件に従って メモ配列を更新 (文字列のインデックスと配列のインデックスは１つ違う）
            if (S[i - 1] == T[j - 1]) {
                dp[i][j] = dp[i - 1][j - 1] + 1
            } else
                dp[i][j] = Math.max(dp[i - 1][j], dp[i][j - 1])
        }
    }

    // LCS の再構成, d[S.length][T.length] から逆にたどって，斜め遷移をしてきてる部分を出力すれば良い？？
    // ある地点までで，同じ値になるたどり着き方(max の操作で選択されないことがないパス）がすなわち，LCSのパターン数になる
    // そのうち１つを逆にたどっていった結果を出力すればよい

    // 1. 斜め上を見て現在の値 -1 かどうか判定 ( -1 であればそちらへ遷移，文字列キューにプッシュ・そうでないなら２の処理へ),
    // 2. 左か上を見て，現在の値と同じかどうか判定, 同じ方へ遷移（文字列には加えない

    var indexI = S.length
    var indexJ = T.length
    var ans = ""

    // どちらかのインデックスが 0 になるまで遷移していく
    while (indexI != 0 && indexJ != 0) {

        // まず一致していかった場合を確認
        if (dp[indexI - 1][indexJ] == dp[indexI][indexJ]) {
            indexI -= 1
            continue
        }
        if (dp[indexI][indexJ - 1] == dp[indexI][indexJ]) {
            indexJ -= 1
            continue
        }

        // 文字列が一致していたとして答えに追加
        ans = S[indexI - 1] + ans
        indexI -= 1
        indexJ -= 1
    }
    println(ans)
}

Measured memory_bytes: 94892
r,g,b,n = map(int,input().split())
ans = 0
L = [r,g,b]
L.sort()
for i in range(n//L[2]+1):
  t = n-i*L[2]
  if t >= 0:
    for j in range(t//L[1]+1):
      q = t-j*L[1]
      if q >= 0:
        if q%L[0] == 0:
          ans += 1
print(ans)

Measured memory_bytes: 3316
# -*- coding: utf-8 -*-
"""
Created on Fri May 15 12:46:40 2020

@author: shinba
"""
from collections import deque

A = deque(input())
B = deque(input())
C = deque(input())

start = "a"

while True:
    if start == "a":
        if len(A) == 0:
            print("A")
            break
        else:
            start = A.popleft()
    elif start == "b":
        if len(B) == 0:
            print("B")
            break
        else:
            start = B.popleft()
    else:
        if len(C) == 0:
            print("C")
            break
        else:
            start = C.popleft()
        

Measured memory_bytes: 3316
#include <bits/stdc++.h>
#define MODNum 1000000007
#define REP(type, i, a, b) for( type i = a; i < b; i++ )
typedef long long ll;

using namespace std;

int main (void) {
    ll N, a;
    map<ll,ll> mp;
    cin >> N;
    REP(int,i,0,N){
        cin >> a;
        mp[a]++;
        if (mp[a] == 2){
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
    return 0;
}

Measured memory_bytes: 12800
#include <iostream>
#include <sstream>
#include <string>
using namespace std;

int main(void)
{
  int n;
  int a[20], b[20], c[20];
  cin >> n;
  cin.ignore();
  string line;
  getline(cin, line);
  istringstream issA(line);
  for (int i = 0; i < n; ++i)
  {
    issA >> a[i];
  }
  getline(cin, line);
  istringstream issB(line);
  for (int i = 0; i < n; ++i)
  {
    issB >> b[i];
  }
  getline(cin, line);
  istringstream issC(line);
  for (int i = 0; i < n - 1; ++i)
  {
    issC >> c[i];
  }
  int prev = -10, cur, score = 0;
  for (int i = 0; i < n; ++i)
  {
    cur = a[i] - 1;
    score += b[cur];
    if (prev == cur - 1)
    {
      score += c[prev];
    }
    prev = cur;
  }
  cout << score << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
const double PI=3.14159265358979323846;
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "

int main(void){
    int n;cin>>n;
    int a[n],b[n],c[n];
    rep(i,n)cin>>a[i];
    rep(i,n)cin>>b[i];
    rep(i,n-1)cin>>c[i];
    int total=0;
    int before;
    for(int i=0;i<n;i++){
        if(i==0){before=a[i];total+=b[a[i]-1];continue;}
        if(before+1==a[i]){total+=(b[a[i]-1]+c[a[i]-2]);}
        else {total+=b[a[i]-1];}
        before=a[i];
    }
    co(total);
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
score = 0
for a, b in zip(A, B):
    diff = b - a
    if diff > 0:
        score += diff // 2
    else:
        score += diff
print("Yes") if score >= 0 else print("No")


Measured memory_bytes: 10540
#include<bits/stdc++.h>
#define FAST std::ios::sync_with_stdio(false);
#define endl '\n'
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define MAX_N 4010
#define Mem(a,b) memset(a,b,sizeof(a))
#define FREI freopen("in.txt","r",stdin)
#define FREO freopen("out.txt","w",stdout)
using namespace std;
const ll mod=1e9+7;

char str[100];
int main() {
#ifdef ONLINE_JUDGE
#else
    //FREI;
    // FREO;
#endif
    //FAST;
    char s[5]="YAKI";
    scanf("%s",str);
    int len=strlen(str);
    bool flag=1;
    for(int i=0;i<min(len,4);i++){
        if(str[i]!=s[i])
            flag=0;
    }
    if(len<4)
        flag=0;
    if(flag)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
long long a, b, st, dr, mid, poz, i, k, t, a2, b2, c, d, x, p;
char sol[105];
int main(){
    cin>> t;
    for(; t; t--){
        cin>> a >> b >> c >> d;
        if(a > b){
            k = a / (b + 1);
            if(a % (b + 1) != 0){
                k++;
            }
        }
        else{
            k = b / (a + 1);
            if(b % (a + 1) != 0){
                k++;
            }
        }
        st = 0;
        dr = a + b;
        while(st <= dr){
            mid = (st + dr) / 2;
            b2 = b - mid / (k + 1);
            a2 = a - mid / (k + 1) * k - mid % (k + 1);
            if(a2 < 0 || a2 * k < b2){
                dr = mid - 1;
            }
            else{
                st = mid + 1;
            }
        }
        poz = st;
        if(poz % (k + 1) == 0 && poz != 0){
            poz--;
        }
        sol[d - c + 1] = 0;
        if(c <= poz){
            x = c % (k + 1);
            if(x == 0){
                x = k + 1;
            }
            p = 0;
            for(i = c; i <= min(d, poz); i++){
                if(x == k + 1){
                    sol[i - c] = 'B';
                    x = 1;
                }
                else{
                    sol[i - c] = 'A';
                    x++;
                }
            }
            p = d - c;
            d = a + b - d + 1;
            x = d % (k + 1);
            if(x == 0){
                x = k + 1;
            }
            for(i = d; i <= a + b - poz; i++){
                if(x == k + 1){
                    sol[p--] = 'A';
                    x = 1;
                }
                else{
                    sol[p--] = 'B';
                    x++;
                }
            }
        }
        else{
            c -= poz;
            d -= poz;
            swap(c, d);
            c = a + b - poz - c + 1;
            d = a + b - poz - d + 1;
            x = c % (k + 1);
            if(x == 0){
                x = k + 1;
            }
            p = d - c;
            for(i = c; i <= d; i++){
                if(x == k + 1){
                    sol[p--] = 'A';
                    x = 1;
                }
                else{
                    sol[p--] = 'B';
                    x++;
                }
            }
        }
        cout<< sol <<"\n";
    }
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
void ABC90(void);
void ABC91(void);
void ABC92(void);
void ABC93(void);
void ABC94(void);
void ABC95(void);
void ABC96(void);
void ABC97(void);
void ABC98(void);
void ABC99(void);

int main(void){
    ABC90();
}

void ABC90(){
    int a,b,i,count=0;
    cin>>a>>b;
    for(i=a;i<=b;i++){
        if(((i/10000)%10==i%10)&&((i/10)%10==(i/1000)%10))count++;
    }
    cout<<count<<endl;
}

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

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

  /* */
  int n, x;
  cin >> n >> x;

  vi v(n + 1);
  v[0] = 0;
  for (int i = 1; i <= n; ++i) {
    cin >> v[i];
  }

  ll ans = 0;
  for (int i = 0; i < n; ++i) {
    if (v[i] + v[i + 1] > x) {
      ans += v[i] + v[i + 1] - x;
      v[i + 1] = x - v[i];
    }
  }
  cout << ans << endl;
  /* */

  return EXIT_SUCCESS;
}


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

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    return divisors

import math

def is_prime(n):
    if n == 1: return False

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False

    return True

common_divisor = set(make_divisors(A))&set(make_divisors(B))

ans = 0
for d in common_divisor:
    if is_prime(d):
        ans+=1
    
print(ans+1)

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

// a^n mod m を計算する(二分累乗法:O(logn))
ll modpow(ll a, ll n, ll m) {
	ll x = 1;
	while(n){
		if(n & 1) x = x * a % m;
		a = a * a % m;
		n >>= 1;
	}
	return x;
}

// nCr mod m
ll nCr(ll n, ll r, ll m){
	ll a = 1, b = 1;
	for(ll i=1; i<=r; ++i){
		a *= n - i + 1;
		b *= i;
		a %=m;
		b %=m;
	}
	return a * modpow(b, m-2, m) % m;
}

int main(){
	ll MOD = 1000000007, N,A,B;
	cin>>N>>A>>B;
	ll ans = modpow(2, N, MOD) - 1;
	ans -= nCr(N, A, MOD);
	ans -= nCr(N, B, MOD);
	ans %= MOD;
	if(ans < 0L) ans += MOD;
	cout<< ans <<endl;
}

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


#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int MD = (int)1e9 + 7; typedef vector<ll> VL;
void dbg(){ cerr << "\n"; }  template <class T, class ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }
template <class T, class T2> void amax(T& a,T2 b){ if(a < b) a = b;}

struct UF{
	vector<int> p;
	UF() {}
	UF(int n) : p(n, -1) {}
	int find(int a){ return p[a] < 0 ? a : p[a] = find(p[a]); }
	bool unite(int a, int b) {
		a = find(a); b = find(b);
		if(a == b) return false;
		if(-p[a] < -p[b]) swap(a, b);
		p[a] += p[b]; p[b] = a;
		return true;
	}
	bool root(int a){ return p[a] < 0; }
	bool same(int a, int b){ return find(a) == find(b); }
	int size(int a){ return -p[find(a)]; }
};

int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n, k, l;
	cin >>n >>k >>l;
	
	UF dr(n), td(n);
	rep(i, k){
		int p, q;
		cin >>p >>q;
		if(!dr.same(p-1, q-1)) dr.unite(p-1, q-1);
	}
	rep(i, l){
		int p, q;
		cin >>p >>q;
		if(!td.same(p-1, q-1)) td.unite(p-1, q-1);
	}
	
	map<pii, int> mp;
	rep(i, n) mp[pii(dr.find(i), td.find(i))]++;
	rep(i, n){
		cout <<(i? " ":"")<< mp[pii(dr.find(i), td.find(i))] ;
	}
	cout <<"\n";
	return 0;
}


Measured memory_bytes: 13568
#include<cstdio>

int c[8];
int m[8]={1,4,1,4,1,2,1,2};
int mm[8][8];
int main(void){
	for(int i=0;i<8;i++){
		for(int j=0;j<8;j++)mm[i][j]=m[(j+i)%8];
	}
	while(~scanf("%d%d%d%d%d%d%d%d",&c[0],&c[1],&c[2],&c[3],&c[4],&c[5],&c[6],&c[7])){
		int res=114514,num=0,id=0;
		for(int i=0;i<8;i++){
			int cnt=0;
			for(int j=0;j<8;j++)if(c[j]>mm[i][j])cnt+=c[j]-mm[i][j];
			if(cnt<res){
				res=cnt;
				id=i;
				num=0;
				for(int j=0;j<8;j++){
					num*=10;
					num+=mm[i][j];
				}
			}else if(cnt==res){
				int nnum=0;
				for(int j=0;j<8;j++){
					nnum*=10;
					nnum+=mm[i][j];
				}
				if(nnum<num){
					id=i;
					num=nnum;
				}
			}
		}
		for(int i=0;i<8;i++)printf("%d%c",mm[id][i],i==7?'\n':' ');
	}
	return 0;
}

Measured memory_bytes: 1028
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define OP ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define F first
#define S second
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int i = 0; i < n; ++i)
#define repr(i,n) for(int i = n - 1; i >= 0; --i)
#define Rep(i, a, n) for(int i = (a); i <=(n); ++i)
#define repst(i, n) for(auto it = n.begin(); it != n.end(); ++it)
#define Repr(i, a, n) for(int i = (n); i >= (a); --i)
typedef long long ll;
typedef std::vector<int> vi;
typedef std::pair<int, int> pii;
const int inf = int(1e9);
const int mod = inf + 7;
const double PI = acos(-1.0);
using namespace std;
const int N = 1e5 + 155;
template<typename T>
inline void read(T&x){
    x=0;int f=1;char ch = getchar();
    while(ch<'0' ||ch>'9'){ if(ch=='-')f=-1;ch=getchar(); }
    while(ch>='0' && ch<='9'){ x=x*10+ch-'0'; ch=getchar(); }
    x*=f;
}
 
 
ll bp(ll a, ll n){
	ll r = 1;
	while(n){
		if(n & 1) r = (r * a) % mod;
		a = (a * a) % mod;
		n >>= 1;
	}
	return r;
}

 
void solve(){
	string s;
	cin >> s;
	unordered_map<char, vector<int>> m;
	rep(i, sz(s)) {
		m[s[i]].pb(i + 1);
	}
	for(auto it: m) {
		vector<int> v = it.second;
		for(int i = 0; i < v.size() - 1; i++) {
			if (v[i + 1] - v[i] <= 2) {
				cout << v[i] << ' ' << v[i + 1];
				return;
			}
		}
	}
	cout << "-1 -1";
}

int main(){
    OP
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int t = 1;
	//cin >> t;
    for(int i = 1; i <= t; i++) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 1228
#include<algorithm>
#include<cstdio>
#include<cstring>

const int Maxv = 705, INF = 0x6ffffff; 
int col[Maxv << 1], n, m, Sum1, Sum2; 
bool g[Maxv][Maxv], vis[Maxv], k[Maxv << 1], dp[Maxv << 1]; 

inline int read(){
    int x = 0, f = 1; 
    char ch = getchar(); 
    while (ch < '0' || ch > '9') {
        if (ch == '-') {
            f = -1; 
        }
        ch = getchar(); 
    }
    while (ch >= '0' && ch <= '9') {
        x = x * 10 + ch - '0'; 
        ch = getchar(); 
    }
    return x * f; 
}

bool dfs(int u, int c){
    if (vis[u]) {
        if (col[u] != c) {
            return false; 
        }
        return true; 
    }
    vis[u] = true; 
    col[u] = c; 
    if (c) {
        Sum1++; 
    }
    else {
        Sum2++; 
    }
    for (int i = 1; i <= n; i++) {
        if (u != i && !g[u][i]) {
            if (!dfs(i, c ^ 1)) {
                return false; 
            }
        }
    }
    return true; 
}

int main(){
    n = read(); 
    m = read(); 
    for (int i = 1; i <= m; i++) {
        int u = read(); 
        int v = read(); 
        g[u][v] = true; 
        g[v][u] = true; 
    }
    dp[0] = true; 
    for (int i = 1; i <= n; i++) {
        if (!vis[i]) {
            Sum1 = 0; 
            Sum2 = 0; 
            if (!dfs(i, 0)) {
                printf("-1\n"); 
                return 0; 
            }
            for (int j = 0; j <= n; j++) {
                k[j + Sum1] |= dp[j]; 
                k[j + Sum2] |= dp[j]; 
            }
            for (int j = 0; j <= n; j++) {
                dp[j] = k[j]; 
                k[j] = false; 
            }
        }
    }
    int min = INF; 
    for (int i = 0; i <= n; i++) {
        if (dp[i]) {
            min = std::min(min, i * (i - 1) / 2 + (n - i) * (n - i - 1) / 2); 
        }
    }
    printf("%d\n", min); 
    return 0; 
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll mod = 1e9 + 7;
#define pival 3.14159265358979323846264338327950L
#define pll pair<ll,ll>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pqq priority_queue
#define all(a) a.begin(), a.end()
#define sz(a) (ll)(a.size())
#define endl '\n'
#define DEBUG
#ifdef DEBUG
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1)
    {
        cerr << name << " = " << arg1 << endl;
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args)
    {
        const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " = " << arg1 << " || ";
        __f(comma+1, args...);
    }
#else
#define debug(...)
#endif
template <class Ch, class Tr, class Container>
basic_ostream <Ch, Tr> & operator << (basic_ostream <Ch, Tr> & os, Container const& x) {
    os << "{ ";
    for(auto& y : x) os << y << " ; ";
    return os << "}";
}
template <class X, class Y>
ostream & operator << (ostream & os, pair <X, Y> const& p) {
    return os << "[ " << p.first << ", " << p.second << "]" ;
}
ll power(ll x, ll y, ll p)
{ 
    ll res = 1;  
    x = x % p;
    while (y > 0) { 
        if (y & 1) res = (res * x) % p; 
        y = y >> 1;
        x = (x * x) % p;   
    } 
    return res; 
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    string s;
    cin >> s;
    for (ll i = 0; i < sz(s); i++) {
    	if (s[i] == '?') cout << 'D';
    	else cout << s[i];
    }
	cout << endl;
	return 0;
}

Measured memory_bytes: 3744
n = int(input())
s,t = input().split()
s = str(s.lower())
t = str(t.lower())
if len(s) == n and len(t) == n:
    new_list = []
    for item in range(len(s)):
        new_list.append(s[item])
        new_list.append(t[item])

    print(''.join(new_list))
else:
    pass


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

typedef long long ll;

const int N = 550;

int n, K, P;

template <typename T1, typename T2>
inline void add(T1 &x, T2 y) {
  x += y;
  if (x >= P)
    x -= P;
}

namespace Sub1 {

  ll f[N][N], ans1, ans2;

  inline ll solve() {
    K /= 2; f[0][0] = 1;
    for (int i = 1; i <= n; ++i) {
      for (int j = 0; j <= K; ++j)
        add(f[i][0], f[i - 1][j]);
      for (int j = 1; j <= K; ++j)
        add(f[i][j], f[i - 1][j - 1]);
    }
    for (int i = 0; i <= K; ++i)
      add(ans1, f[n / 2][i]);
    for (int i = 0; i <= K; ++i)
      add(ans2, f[(n + 1) / 2][i]);
    return ans1 * ans2 % P;
  }
}

namespace Sub2 {

  ll f[N][N][N], ans;

  inline ll solve() {
    if (K > n - 2) {
      ll ret = 1;
      for (int i = 1; i <= n; ++i)
        ret = ret * 2 % P;
      return ret;
    }
    f[0][0][0] = 1;
    for (int i = 2; i <= n + K; i += 2) {
      for (int j = 0; j <= n; ++j)
        for (int k = 0; k <= K + 1; ++k)
          add(f[i][0][0], f[i - 2][j][k]);
      if (i <= n) {
        for (int j = 0; j <= n; ++j)
          for (int k = 0; k <= K + 1; ++k)
            add(f[i][j + 1][0], f[i - 2][j][k]);
      }
      if (i >= K + 1) {
        for (int j = 0; j <= n; ++j) {
          for (int k = 1; k <= K; ++k)
            add(f[i][0][k + 1], f[i - 2][j][k]);
          add(f[i][0][0], f[i - 2][j][0]);
        }
      }
      if (i <= n && i >= K + 1) {
        for (int j = 0; j <= n; ++j)
          for (int k = 0; std::max(j + 1, k) <= K; ++k)
            add(f[i][j + 1][std::max(j + 2, k + 1)], f[i - 2][j][k]);
      }
    }
    for (int j = 0, qwq = ((n + K) & 1 ? n + K - 1 : n + K); j <= n; ++j)
      for (int k = 0; k <= K + 1; ++k)
        add(ans, f[qwq][j][k]);
    return ans;
  }
}

int main() {
  // freopen("data", "r", stdin);
  std::cin >> n >> K >> P;
  if (!(K & 1)) std::cout << Sub1::solve() << std::endl;
  else std::cout << Sub2::solve() << std::endl;
  return 0;
}


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

int main()
{
	long long a, b, c;
	scanf("%lld%lld%lld", &a, &b, &c);
	if (a + b >= c - 1)
		printf("%lld\n", b + c);
	else
		printf("%lld\n", a + 2 * b + 1);

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
int main(void){
	int a,b,c;
	int rect = 0;
	int rhom = 0;
	
	while(scanf("%d,%d,%d",&a,&b,&c) != EOF){
		if(pow(a,2)+pow(b,2) == pow(c,2))rect++;
		if(a == b)rhom++;
	}
	
	printf("%d\n%d\n",rect,rhom);
	return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
#define nl ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll long long
#define all(v) (v).begin(), (v).end()
#define allr(v) (v).rbegin(), (v).rend()
#define pi acos(-1)

using namespace std;

int main() {
    nl // Bazzi - Paradise

    int a, b;
    cin >> a >> b;
    int add = a+b;
    int prod = a*b;
    int sub = a-b;
    cout << max({add,prod,sub});

    return 0;
}

Measured memory_bytes: 3644
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <unordered_map>
#include <string>
#include <cmath>
#include <set>
#include <cmath>
using namespace std;



vector<vector<int>> g;
vector<long long> dp;

const long long mod = 1e+9 + 7;

int bitcount(int mask)
{
	int cnt = 0;
	while (mask > 0)
	{
		if (mask & 1)
		{
			cnt++;
		}
		mask >>= 1;
	}
	return cnt;
}

void solve()
{
	int n;
	cin >> n;

	g.assign(n, vector<int>(n, 0));

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

	dp.assign((1 << n), 0);


	dp[0] = 1;
	for (int mask = 0; mask < (1 << n); mask++)
	{
		int j = bitcount(mask);

		for (int i = 0; i < n; i++)
		{
			if (!(mask & (1 << i)) && g[j][i])
			{
				int newmask = mask + (1 << i);
				dp[newmask] += dp[mask];
				dp[newmask] %= mod;
			}
		}
	}

	cout << dp[(1 << n) - 1];
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	//freopen("file.in", "r", stdin);//freopen("file.out", "w", stdout);

	int t = 1;
	//cin >> t;
	while (t--)
	{
		solve();
	}
	return 0;
}

Measured memory_bytes: 16640
#include <iostream>
#include <string>


using namespace std; 

int main(){
	int a[] = { 0,1,3,1,2,1,2,1,1,2,1,2,1};
	int x, y;
	cin >> x >> y;
	if (a[x] == a[y]){
		cout << "Yes" << endl;
	}
	else{
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<array>
using namespace std;
using UL = unsigned;
using LL = long long;
using ULL = unsigned long long;
#define rep(i, n) for(UL i = 0; i < (n); i++)
void Solve() {
	UL m1, d1, m2, d2; cin >> m1 >> d1 >> m2 >> d2;
	if (m1 != m2) cout << 1 << endl;
	else cout << 0 << endl;
}
int main() { Solve(); return 0; }


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
int main() {
long long int N, A; 
long long int X[60] = {};
cin >> N >> A;
for(int i = 0; i < N; i++){
long long int n; 
cin >> n; 
X[i] = n - A; 
}
long long int B[6000][60] = {}; 
B[3000][0] ++; 
B[3000 + X[0]][0] ++; 
for(int i = 1; i < N; i++){
 for(int j = 3000 - 50 * i; j <= 3000 + 50 * i; j++){
B[j][i] = B[j][i-1] + B[j - X[i]][i-1]; 
}
}
cout << B[3000][N-1] - 1<< endl; 
}

Measured memory_bytes: 3072
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    N=I()
    S=input()
    bk=S.count("#")
    ans=N-bk
    w=0
    for i in range(N):#i番目まで白，i+1以降黒
        if S[i]=="#":
            bk-=1
        else:
            w+=1
        temp=(i+1-w)+(N-i-1-bk)
        ans=min(ans,temp)
    print(ans)
        

main()


Measured memory_bytes: 70256
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef long long ll;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    string s;
    cin >> s;
    if(s[1] == 'B'){
        cout << "ARC" << endl;
    }else{
        cout << "ABC" << endl;
    }
}

Measured memory_bytes: 3612
#include<iostream>

int wrong_count(char a1[],char a2[]){
    //std::cout << a1 << ' ' << a2 << '\n';
    int i=0;
    if(a1[i] == '\0' && a2[i] == '\0') return 0;
    do{
        if(a1[i] == a2[i]){
            i++;
            if(a1[i] == '\0' && a2[i] == '\0') return 0;
        }else{
            //std::cout << "return\n";
            return 1;
        }
    }while(a1[i] != '\0' || a2[i] != '\0');
    return 1;
}

void cut_str(char s[],char a[],int& i){
    int ap=0;
    i++;
    while(s[i] != '"'){
        a[ap++] = s[i++];
    }
    i++;
    a[ap] = '\0';
    //std::cout << a << '\n';
}

int compare_str(char s1[],char s2[]){
    int i=0,j=0;
    int count = 0;
    while(s1[i] != '\0' || s2[j] != '\0'){
        if(s1[i] != s2[j]){ return -1; }
        else if(s1[i] == '"' && s2[j] =='"'){
            char a1[200] = {},a2[200] = {};
            cut_str(s1,a1,i);
            cut_str(s2,a2,j);
            count += wrong_count(a1,a2);
            if(count > 1) return -1;
            if(s1[i] == '\0' && s2[j] == '\0') return count;
        }else{
            i++;
            j++;
            if(s1[i] == '\0' && s2[j] == '\0') return count;
        }
    }
    return count;
}


int main(){
  char s1[200]= {},s2[200] = {} ;
  for(int i=0;i<100;i++){
      std::cin >> s1 ;
      if(s1[0] == '.') break;
      std::cin >> s2;
      int count = compare_str(s1,s2);
    if(count == 0){
      std::cout << "IDENTICAL\n";
    }else if(count == 1){
      std::cout << "CLOSE\n";
    }else{
      std::cout << "DIFFERENT\n";
    }
  }
  return 0;
}


Measured memory_bytes: 3000
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <queue>
#include <cstdlib>

using namespace std;

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

const ll mod = 1000000007;

template <class T>
struct swag {
  vector<T> data_front;
  vector<T> data_back;
  vector<T> func_front;
  vector<T> func_back;

  void clear() {
    data_front.clear();
    data_back.clear();
    func_front.clear();
    func_back.clear();
  }

  int size() {
    return data_front.size() + data_back.size();
  }

  void push(T x) {
    if (data_front.size() == 0) {
      data_front.push_back(x);
      func_front.push_back(x);
    }
    else {
      T f;
      if (func_back.size() == 0) f = x;
      else f = min(func_back[func_back.size()-1], x);
      data_back.push_back(x);
      func_back.push_back(f);
    }
  }

  void pop() {
    if (data_front.size() > 0) {
      data_front.pop_back();
      func_front.pop_back();
    }
    if (data_front.size() == 0) {
      int s = data_back.size();
      for (int i = 0; i < s; i++) {
        T x = data_back[data_back.size()-1];
        T f;
        if (func_front.size() == 0) f = x;
        else f = min(func_front[func_front.size()-1], x);
        data_front.push_back(x);
        func_front.push_back(f);
        data_back.pop_back();
        func_back.pop_back();
      }
    }
  }

  T fold_all() {
    if (func_front.size() == 0) return 0;
    else if (func_back.size() == 0) return func_front[func_front.size()-1];
    else return min(func_front[func_front.size()-1], func_back[func_back.size()-1]);
  }
};

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

  int n, l;
  cin >> n >> l;
  vector<int> a(n);
  for (auto &x: a) cin >> x;

  swag<int> sw;
  vector<int> ans;
  for (int i = 0; i < n; i++) {
    sw.push(a[i]);
    if (sw.size() >= l) {
      ans.push_back(sw.fold_all());
      sw.pop();
    }
  }

  for (int i = 0; i < (int)ans.size(); i++) {
    cout << ans[i];
    if (i < (int)ans.size() - 1) cout << " ";
    else cout << endl;
  }
}



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


int main(){

int N, L;
cin >> N >> L;
  
vector<string> S(N);
 
for(int i = 0; i < N; i++){
  cin >> S.at(i);
}
  
 sort(S.begin(),S.end());
  for(int i = 0; i < N; i++){
    cout << S.at(i);
  }
cout << endl;
}
 

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip> 
#include <complex> 
#include <string>
#include <vector> 
#include <list>
#include <deque> 
#include <stack> 
#include <queue> 
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <utility>
#include <algorithm> 
#include <numeric> 
#include <typeinfo> 
#include <cstdio>
#include <cstdlib> 
#include <cstring>
#include <cmath>
#include <climits> 
#include <ctime>

using namespace std;

const int INF=1000000;
int n,m;
int cost[101][101];
int mincost[101];
bool used[101];

int prim(){
	int a;
	for(a=0;a<n;++a){
		mincost[a]=INF;
		used[a]=false;
	}
	mincost[0]=0;
	int res=0;
	while(1){
		int v=-1;
		for(a=0;a<n;a++){
			if(!used[a] && (v==-1 || mincost[a] < mincost[v]))v=a;
		}
		if(v==-1)break;
		used[v]=true;
		res+=mincost[v];
		for(a=0;a<n;a++){
			mincost[a]=min(mincost[a],cost[v][a]);
		}
	}
	return res;
}

int main(void){
	int a,b;
	while(1){
		for(a=0;a<=100;a++){
			for(b=0;b<=100;b++){
				cost[a][b]=INF;
				if(a==b)cost[a][b]=0;
			}
		}
		cin >> n >> m;
		if(n==0 && m==0)break;
		for(a=0;a<m;a++){
			int b,c,d;
			cin >> b >> c >> d;
			if(cost[b][c]>d){
				cost[b][c]=d;
				cost[c][b]=d;
			}
		}
		int ans=prim();
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 0
<?php
  $n = trim(fgets(STDIN));
  $a = explode(" ", trim(fgets(STDIN)));
  $h = $a[0];
  $ans = 0;
  for($i=1; $i<$n; $i++){
      if($h > $a[$i]){
          $ans += $h-$a[$i];
      }else{
          $h = $a[$i];
      }
  }
  echo $ans;

Measured memory_bytes: 31868
#include<stdio.h>

#define H 250
#define NIL -1

int A[H],n;

int main(){
  int i;
  scanf("%d",&n);
  for(i=1;i<=n;i++){
    scanf("%d",&A[i]);
  }

  for(i=1;i<=n;i++){
    printf("node %d: key = %d, ",i,A[i]);
    if(i/2>=1){
      printf("parent key = %d, ",A[i/2]);
    }
    if(2*i<=n){
      printf("left key = %d, ",A[2*i]);
    }
    if(2*i+1<=n){
      printf("right key = %d, ",A[2*i+1]);
    }
    printf("\n");
  }
  return 0;
}



Measured memory_bytes: 2028
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define endl "\n"
#define se second
#define ls( s) (s&(-s))
#define ll long long
#define inf 0x3f3f3f3f
#define fast    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const ll N = 200030;
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
const ll mod =    998244353;
ll n;
ll arr[100];

int main()
{  fast
priority_queue<ll> pq;
cin>>n;
ll ans=0;
ll cnt=0;
for(ll i=0;i<n;i++)
{
	ll x;
	cin>>x;
	pq.push(x);
}
while(1)
{
	ll x=pq.top();
	pq.pop();
	if(x+cnt<n)
	break;
	ll y=((x+cnt)/n);
	ans+=y;
	pq.push(x-y*n-y);
	cnt+=y;
}
cout<<ans;
}




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

using namespace std;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define fin(ans) cout << (ans) << endl;
#define blank(ans) cout << (ans) << " ";
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()

typedef long long ll;
typedef long long lli;
typedef unsigned long long ull;
typedef long double ld;
typedef string str;

typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<ld> vd;
typedef vector<str> vs;
typedef vector<ll> vll;
typedef vector<pair<ll, ll>> vpll;
typedef vector<pair<ll, str>> vpls;
typedef vector<tuple<str, ll, ll>> vtsl;
typedef vector<vector<ll>> vvll;
typedef vector<vector<char>> vvc;
typedef vector<vector<str>> vvs;

const ld PI = acos(-1.0);
const ll MAX = 9000000000000000000;
const ll MIN = -9000000000000000000;
const ld DMAX = 4500;
const ld DMIN = -4500;
const ll MOD = 1000000007;

//実行部
void Main()
{
  ll a, b, c, d; cin >> a >> b >> c >> d;
  ll A = c - a, B = d - b;
  blank(c - B) blank(d + A) blank(a - B) fin(b + A)
}

//前処理
int main()
{
  //ios::sync_with_stdio(false);
  //cin.tie(0);
  cout << fixed << setprecision(20); //高精度少数表示
  Main();
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <vector>
#include <cmath>
#include <ctime>
#include <cassert>
#include <ctype.h>
#include <iomanip>
#include <cstdio>
#include <float.h>
#include <queue>
#include <set>
#include <map>
#include <fstream>
#include <cstdlib>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <stack>
#include <functional>
// #include <pair> 
       
using namespace std;
       
#define endl '\n'
#define MOD 1000000007
#define INF 1ll<<30
 
// #define MAX 100010
 
#define eps 1e-11
#define bit_max 1ll<<32
#define _USE_MATH_DEFINES
 
// long long binpow(long long a,long long b)
// {
//     if (b == 1) return a;
//     long long res = binpow(a, b/2)%MOD;
//     if (b % 2) return (res*((res*a)%MOD))%MOD;
//     else return (res * res)%MOD;
// }
 
// long long int fact(long long int a)
// {
//     if(a==0||a==1)
//         return 1;
//     long long int ans = 1;
//     for(int i=a;i>=1;i--)
//         ans = (ans * i);
//     return ans;
// }
 
// long long int ivmod(long long int a)
// {
//     return binpow(a,MOD-2);
// }
 
// long long int ncr(long long int a,long long int b)
// {
//     long long int pans=1;
//     for(int i =a;i>max(b,a-b);i--)
//         pans=pans*i;
//     long long int div = fact(min(b,a-b));
//     // cout<<ans<<"            "<<div<<endl;
//     pans = pans/div;
//     return pans;
// }

int main()
{
    // ios_base::sync_with_stdio(false);
    // cin.tie(NULL);
    // cout.tie(NULL);
    // #ifndef ONLINE_JUDGE
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
    // #endif   
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    int arr[1000]={0};
    for(int i=a;i<=b;i++)
    {
        arr[i]+=1;
    }
    for(int i=c;i<=d;i++)
    {
        arr[i]+=1;

    }
    int ans = 0;
    for(int i=0;i<=100;i++)
    {
        if(arr[i]>1)
            ans++;
    }
    if(ans!=0)
        ans--;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

int cmp(const void *l, const void *r)
{
  return *(int*)l - *(int*)r;
}

int main()
{
  int abc[3];
  scanf("%d %d %d", &abc[0], &abc[1], &abc[2]);
  qsort(abc, 3, sizeof(int), cmp);

  if (abc[0] == 5 && abc[1] == 5 && abc[2] == 7) {
    puts("YES");
  }
  else {
    puts("NO");
  }

  return 0;
}

Measured memory_bytes: 128
def main():
	
	from collections import deque
	n,m = map(int, input().split())
	graph = [[] for _ in range(n+1)]

	for i in range(m):
		a, b = map(int, input().split())
		graph[a].append(b)
		graph[b].append(a)
	d = deque()
	dist = [-1] * (n+1)
	dist[0] = 0
	dist[1] = 0
	d.append(1)

	while d:
		v = d.popleft()
		for i in graph[v]:
			if dist[i] != -1:
				continue
			dist[i] = dist[v] + 1
			d.append(i)

	if graph[1] == "":
		print("No")
	else:
		print("Yes")
		for i in range(2,n+1):
			for g in graph[i]:
				if dist[g] == dist[i]-1:
					print(g)
					break


if __name__ == '__main__':
	main()

Measured memory_bytes: 94844
from collections import deque


k = int(input())
if k<=9:
    print(k)
    exit()

run = deque([int(i) for i in range(1,10)])
rli = [int(i) for i in range(1,10)]
i=0
while len(rli)<=k:
    
    p = run.popleft()
    j=p%10
    if p%10 == 9:
        for h in range(-1,1):
            n = p*10+j+h
            rli.append(n)
            run.append(n)
    elif p%10 == 0:
        for h in range(0,2):
            n = p*10+j+h
            rli.append(n)
            run.append(n)
    else:
        
        for h in range(-1,2):
            n = p*10+j+h
            rli.append(n)
            run.append(n)
    
print(rli[k-1])
    
        



Measured memory_bytes: 14056