akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>
#include <cmath>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
//ll mod = 998244353;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main() {
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    ll ans = 1e18;
    rep(ri, 2) {
        ll sum = 0;
        ll tmp_ans = 0;
        rep(i, n) {
            //cout << sum << " " << a[i] << " " << tmp_ans << endl;
            if (i % 2 == ri) {
                if (sum + a[i] > 0) {
                    sum += a[i];
                }
                else {
                    tmp_ans += (1LL - sum - a[i]);
                    sum = 1LL;
                }
            }
            else {
                if (sum + a[i] < 0) {
                    sum += a[i];
                }
                else {
                    tmp_ans += abs((-1LL - sum - a[i]));
                    sum = -1LL;
                }
            }
        }
        //cout << tmp_ans << endl;
        ans = min(ans, tmp_ans);
    }
    cout << ans << endl;
    return 0;
}


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

int number_of_digits(int n) {
	int result = 0;
	while (n != 0) {
		result++;
		n /= 10;
	}
	return result;
}

int main() {
	int a, b;
	
	while (cin >> a >> b)
		cout << number_of_digits(a+b)
		     << endl;
	return 0;
}

Measured memory_bytes: 3092
N = int(input())

E = [[] for _ in range(N)]
Color = [None] * N

for i in range(N - 1):
	u, v, w = map(int, input().split())
	u, v = u - 1, v - 1
	E[u].append((v, w & 1))
	E[v].append((u, w & 1))


for i in range(N):
	if Color[i] is not None:
		continue
	stack = [(i, 0)]
	
	while stack:
		u, color = stack.pop()
		Color[u] = color
		for v, w in E[u]:
			if Color[v] is not None:
				continue
			stack.append((v, color if w == 0 else 1 - color))

for i in range(N):
	print(Color[i])



Measured memory_bytes: 35628
def korat(x):
    i = 0
    while x > 1:
        if x % 2:
            x = x * 3 + 1
            i += 1
        while x % 2 == 0:
            x = x // 2
            i += 1
    return i

while True:
    n = int(input())
    if n == 0:
        break
    print(korat(n))


Measured memory_bytes: 5592
W,H,N = map(int,raw_input().split())
ans = 0
X,Y = map(int,raw_input().split())
for i in range(N-1):
	X1,Y1 = map(int,raw_input().split())
	dX,dY = X1-X,Y1-Y
	if dX*dY > 0:
		ans += max(abs(dY),abs(dX))
	else:
		ans += abs(dY) + abs(dX)
	X,Y = X1,Y1
print ans

Measured memory_bytes: 4240
#include <stdio.h>

int main(){
  int n, a[100], i;

  scanf("%d",&n);

  for (i=0;i<n;i++) scanf("%d",&a[i]);
  for(i=n-1;i>=0;i--) {
    if(i==0) printf("%d\n",a[i]);
    else printf("%d ",a[i]);
  }

  return 0;
}



Measured memory_bytes: 2112
#                         author:  kagemeka 
#                         created: 2019-11-07 12:33:44(JST)
import sys
# import collections
# import math
# import string
# import bisect
# import re
# import itertools
# import statistics
# import functools
# import operator

def main():
    s = sys.stdin.readline().rstrip()
    ans = 700 + 100 * s.count('o')
    print(ans)



if __name__ == "__main__":
    # execute only if run as a script
    main()


Measured memory_bytes: 3060
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
#include <random>
#include <cassert>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define MEM(a,b) memset((a),(b),sizeof(a))
const LL INF = 1e9 + 7;
const int N = 1e6 + 10;

int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int n;
	cin >> n;
	string str;
	cin >> str;
	if (str.substr(0, n / 2) == str.substr(n / 2)) puts("Yes");
	else puts("No");
	return 0;
}

Measured memory_bytes: 256
def c_next_prime():
    from bisect import bisect_left
    X = int(input())

    def prime_table(n):
        """n以下の素数のリスト(エラトステネスの篩)"""
        is_prime = [True] * (n + 1)
        is_prime[0] = is_prime[1] = False  # 0と1は素数でない
        for j in range(2, int(n**0.5) + 1):
            if not is_prime[j]:
                continue
            for k in range(j * 2, n + 1, j):
                is_prime[k] = False  # jの倍数は素数でない
        return [i for i in range(n + 1) if is_prime[i]]

    primes = prime_table(min(2 * X, 10**5 + 3))
    return primes[bisect_left(primes, X)]

print(c_next_prime())

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

using namespace std;

int main()
{
  int N, A[200000], B[200000];
  int sum[100000] = {};

  vector< int > add[100000], del[100000];
  int ans[200000] = {};

  scanf("%d", &N);
  for(int i = 0; i < N; i++) {
    scanf("%d %d", &A[i], &B[i]);
    --A[i], --B[i];
    ++sum[A[i]];
    --sum[B[i]];
    add[A[i]].emplace_back(i);
    del[B[i]].emplace_back(i);
  }

  int ret = 0, cur = 0;
  for(int i = 0; i < 100000; i++) {
    cur += sum[i];
    ret = max(ret, cur);
  }

  cur = 0;
  int open = 0;
  for(int i = 0; i < 100000; i++) {
    for(auto &idx : del[i]) ans[idx] += open;
    cur -= del[i].size();
    for(auto &idx : add[i]) ans[idx] -= open - cur;
    open += add[i].size();
    cur += add[i].size();
  }
  cout << *max_element(ans, ans + N) << " " << ret << endl;
}

Measured memory_bytes: 16208
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i < (int)(n); i++)
#define Sort(a) sort(a.begin(), a.end())
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return true;} return false;}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return true;} return false;}

int main(){
    long double a, b;
    cin >> a >> b;
    ll ans = a*b;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3728
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations
import sys
import bisect
import string
import math
import time
from fractions import gcd
#import random


def I(): return int(input())


def MI(): return map(int, input().split())


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


def input(): return sys.stdin.readline().rstrip()


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


YN = ['Yes', 'No']
MOD = 10**9+7
inf = float('inf')
IINF = 10**19
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)


show_flg = False
# show_flg = True

A = 0
B = 0
C = 0
N = 0


def dfs(cur, L, a, b, c):
    # print(A, B, C)
    if cur == N:
        return abs(A - a) + abs(B - b) + abs(C - c) if min(a, b, c) > 0 else IINF

    ret0 = dfs(cur + 1, L, a, b, c)
    ret1 = dfs(cur + 1, L, a + L[cur], b, c) + (0 if a == 0 else 10)
    ret2 = dfs(cur + 1, L, a, b + L[cur], c) + (0 if b == 0 else 10)
    ret3 = dfs(cur + 1, L, a, b, c + L[cur]) + (0 if c == 0 else 10)

    return min(ret0, ret1, ret2, ret3)


def main():
    global A
    global B
    global C
    global N
    N, A, B, C = MI()
    L = [0] * N

    for i in range(N):
        L[i] = int(input())

    # itertools.combinations(L, 2)
    print(dfs(0, L, 0, 0, 0))


if __name__ == '__main__':
    main()


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

int main(){
    int r, c, i, j;
    int a[101][101] = {0};
    
    cin >> r >> c;
    
    for(i = 0; i <= r; i++){
        for(j = 0; j <= c; j++){
            if(j == c){
                cout << a[i][j] << endl;
                a[r][c] += a[i][c];
                continue;
            }
            else if(i == r){
                cout << a[i][j] << " ";
                continue;
            }
            
            cin >> a[i][j];
            a[i][c] += a[i][j];
            a[r][j] += a[i][j];
            
            cout << a[i][j] << " ";
        }
    }
}


Measured memory_bytes: 3136
#include <iostream>
#include <string>
using namespace std;
int main(void){
    // Your code here!
    int A,B,C;
    scanf("%d%d%d",&A,&B,&C);
    for(int i=1;i<=B;i++){
        if((A*i)%B==C){cout<<"YES"<<endl;return 0;}
    }
    cout<<"NO"<<endl;
    return 0;
}


Measured memory_bytes: 256
import java.math.BigInteger;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner reader = new Scanner(System.in);
		int N = reader.nextInt();
		BigInteger[] A = new BigInteger[N];
		BigInteger[] gcd = new BigInteger[N];
		BigInteger[] reverse = new BigInteger[N];
		for (int i = 0; i < N;i++) {
			A[i] = new BigInteger(reader.next());
			if (i > 0) {
				gcd[i] = A[i].gcd(gcd[i-1]);
			} else {
				gcd[i] = A[i];
			}
		}
		for (int i = N-1; i >=0 ;i--) {
			if (i < N-1) {
				reverse[i] = A[i].gcd(reverse[i+1]);
			} else {
				reverse[i] = A[i];
			}
		}
		long ans = Math.max(gcd[N-2].longValue(), reverse[1].longValue());
		for (int i = 1; i < N-1;i++) {
			BigInteger a = gcd[i-1].gcd(reverse[i+1]);
			ans = Math.max(a.longValue(), ans);
		}





		System.out.println(ans);
		reader.close();

	}
}





Measured memory_bytes: 83100
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <cstring>
#include <map>

#define rep(i, N) for (int i = 0; i < (int)N; i++)
using namespace std;
typedef long long ll;
const ll LLINF = 9223372036854775807;
const int MOD = 1000000007;

int main() {
  int N; cin >> N;
  int result = N * (N+1) / 2;
  cout << result << endl;
  return 0;
}

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

int gcd(int a,int b){
  if(a%b==0||b%a==0){
    return min(a,b);
  }else{
    if(a>b){
      return gcd(a-b,b);
    }else{
      return gcd(a,b-a);
    }
  }
}

int main(){
  int N;
  cin>>N;
  vector<int> A(N);
  for(int i=0;i<N;i++){
    cin>>A.at(i);
  }
  int a;
  for(int i=0;i<N;i++){
    if(i==0){
      a=gcd(A.at(i),A.at(i+1));
    }else{
      a=gcd(A.at(i),a);
    }
  }
  cout<<a<<endl;
  
  
}

Measured memory_bytes: 640
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<string>
using namespace std;
#define MAX_N 200000
long n,k;
long double a[MAX_N+1];
long double b[MAX_N+1];
long double c[MAX_N+1];

int main(){
    cin>>n>>k;
    for(int i=0;i<n;i++){
        cin>>a[i];
        b[i]=(a[i]+1)/2;
        }
    for(int i=0;i<n;i++){
        if(i==0){
        c[i]=b[i];
        continue;
        }
        c[i]=c[i-1]+b[i];
    }
    long double max=0,z;
    for(int i=k-1;i<n;i++){
        if(i==k-1){
            z=c[i];
            if(z>max)max=z;
            continue;
        }
        z=c[i]-c[i-k];
        if(z>max)max=z;
    }
    printf("%.15Lf\n",max);
}

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


namespace tes
{
	class contest
	{
		static void Main(string[] args)
		{
			
            var input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            string s = Console.ReadLine();
            int N = input[0];
            int A = input[1];
            int B = input[2];

            
            int rank = 0;
            int foreRnc = 0;

            for(int i =0; i<s.Length ; i++)
            {
                if(s[i]=='a' && rank < A + B)
                {
                    Console.WriteLine("Yes");
                    rank++;
                }
                else if(s[i]== 'b' && rank < A + B && foreRnc<B)
                {
                    Console.WriteLine("Yes");
                    rank++;
                    foreRnc++;
                }
                else
                {
                    Console.WriteLine("No");

                }

                
            }

            
            
		}	
		
	}
}

Measured memory_bytes: 7512
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string str1,str2;
  cin >> str1;
  cin >> str2;
  int count = 0;
  for(int i = 0; i < 3; i++) {
    if(str1.at(i) == str2.at(i))
      count++;
  }
  cout << count << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int A[1000000], n;

int binarySearch(int key) {
  int left = 0;
  int right = n;
  int mid;
  while(left < right) {
    mid = (left + right) / 2;
    if(key == A[mid]) return 1; 
    if(key > A[mid]) left = mid + 1; 
    else if(key < A[mid]) right = mid;
  }
  return 0;
}

int main(void) {
  int i, q, k, sum = 0;
  scanf("%d",&n);
  for(i=0; i<n; i++) {
    scanf("%d",&A[i]);
  }
  scanf("%d",&q);
  for(i=0;i<q;i++) {
    scanf("%d",&k);
    if(binarySearch(k))
      sum++;
  }
  printf("%d\n",sum);
  return 0;
}


Measured memory_bytes: 2228
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int main() {
    int n;
    cin >> n;

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

    int res = 1000000000;
    for (int i = -100, r = 0; i <= 100; i++, r = 0) {
        for (int j = 0; j < n; j++) {
            r += (i - a[j]) * (i - a[j]);
        }

        res = min(res, r);
    }

    cout << res << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
int main(){
  int n,total=0,i,j,temp,num[10000],fi,flag=0;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&num[i]);
    double cmp=sqrt(num[i]);
    fi=cmp+1;
    flag=0;
    for(j=2;j<=fi;j++){
      if(num[i]%j==0 && num[i]!=2){
	flag=1;
	break;
      }
    }
    if(flag==0)total++;
  }
  printf("%d\n",total);
  return(0);
}

Measured memory_bytes: 628
package main

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

func pow(a, n int) int {
	ret := 1
	for n > 0 {
		if n&1 == 1 {
			ret *= a
		}
		a *= a
		n >>= 1
	}
	return ret
}

// nの上位d桁目の数
func digitNum(n, d int) int {
	s := strconv.Itoa(n)
	return int(s[d-1] - '0')
}

func main() {
	sc.Split(bufio.ScanWords)
	n, m := nextInt(), nextInt()
	s, c := make([]int, m), make([]int, m)
	for i := 0; i < m; i++ {
		s[i], c[i] = nextInt(), nextInt()
	}

	ans := -1
	iMax := pow(10, n)
	iBegin := pow(10, n-1)
	if iBegin == 1 {
		iBegin = 0
	}
	for i := iBegin; i < iMax; i++ {
		ok := true
		for j := 0; j < m; j++ {
			if digitNum(i, s[j]) != c[j] {
				ok = false
				break
			}
		}
		if ok {
			ans = i
			break
		}
	}
	puts(ans)
	wt.Flush()
}

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

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

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

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


Measured memory_bytes: 640
import java.util.*;
public class Main{
 public static void main(String[] args){
   Scanner sc = new Scanner(System.in);
   int N = sc.nextInt();
   int[] Ai = new int[N];
   for(int i=0;i<N;i++) Ai[i] = sc.nextInt();
   
   int gcdmem = Ai[0];
   
   for(int i=1;i<N;i++)
   {
     gcdmem = gcd(gcdmem,Ai[i]);     
   }
    System.out.print(gcdmem);   
 }
  static int gcd (int a, int b) {return b>0?gcd(b,a%b):a;}
}

Measured memory_bytes: 50392
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define nthElement(x) find_by_order(x)
#define lessThan(x) order_of_key(x)
#define dd double
#define pb push_back
#define pf push_front
#define ll long long
#define ull unsigned long long
#define ld long double
#define mx 200
#define mod 1000000007
#define fr first
#define se second
#define End cout<<"\n"
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define memo(Array,val) memset(Array, val, sizeof Array)
#define PI acos(-1)
#define per(i) cout<<fixed<<setprecision(i)
#define con continue
#define all(ele) (ele).begin(),(ele).end()
#define Ones(x) __builtin_popcount(x)
#define trailingZero(x) __builtin_ctz(x)
#define len(ele) (ele).size()

template<typename... T> void get(T&... args) { ((cin >> args), ...); }

template<typename... T> void Get(T&... args){ ((getline(cin,args)), ...); }

template<typename... T> void print(T&&... args) { ((cout << args << ""), ...); }

bool check(int n, int pos){ return (n&(1<<pos)); }
bool Set(int n, int pos) {  return (n | (1<<pos)); }
ld LOG(ld b, ld e){ return log(b)/log(e); }
ld rad(ld x) {  return ((ld)PI*x)/180.0; }

/// Code Starts From Here.............................................///

int tc=1,r,c,k;
string s1[10], s2[11];

void cpy()
{
    for(int i=0; i<r; i++)
        s2[i]=s1[i];
}

void go(int row, int col)
{
    for(int i=0; i<r; i++){
        if(check(row,i)){
            for(int j=0; j<c; j++)
                s2[i][j]='B';
        }
    }

    for(int i=0; i<c; i++){
        if(check(col,i)){
            for(int j=0; j<r; j++)
                s2[j][i]='B';
        }
    }
}

bool func()
{
    int sum=0;
    for(int i=0; i<r; i++){
        for(int j=0; j<c; j++)
            sum+=(s2[i][j] == '#');
    }
    return sum == k;
}

void solve(int kk)
{
    int sum=0;
    cin >> r >> c >> k;
    for(int i=0; i<r; i++)
        cin >> s1[i];
    /// All possible combinations
    for(int i=0; i<(1<<r); i++){
        for(int j=0; j<(1<<c); j++){
            cpy();
            go(i,j);
            sum+=func();
        }
    }
    print(sum, "\n");


}

int main()
{
   //freopen("text.txt", "r", stdin);
   //freopen("text2.txt", "w", stdout);
   fast;
   int kk=0;
   //cin >> tc;
   //scanf("%d", &tc);
   while(++kk<=tc) solve(kk);

   return 0;
}


Measured memory_bytes: 3704
#include <stdio.h>
int main(void)
{
	int n,a[10001],i,c=0;
	scanf("%d",&n);
	for(i=0; i<n; i++){
		scanf("%d",&a[i]);
		while(a[i]%2==0){
			a[i]=a[i]/2;
			c=c+1;
		}
	}
	printf("%d\n",c);
	return 0;
}

Measured memory_bytes: 256
//include,namespace
 #include<bits/stdc++.h>
 #include<iostream> 
 #include <queue>
 #include <vector>
 #include <string>
 using namespace std;
//REPmacro
 #define all(x) (x).begin(),(x).end()             //ソート
 #define FOR(i,x,n)for(int i=(x);i<(n);i++)
 #define FOR_R(i,x,n) for(int i=(n-1);i>=(x);i--)
 #define REP(i, n) FOR(i, 0, n)
 #define REP_R(i, n) FOR_R(i, 0, n)
//long long(define)
 using ll = long long;
 typedef long long ll;
 typedef long long int64;
 typedef long long lint;
 typedef long long lli;

////////////////いろいろあるよ//////////////////////////////////
int main(){
	char piyo;
  	cin >> piyo;
  	cin >> piyo;
  
  if(piyo=='B'){cout << "ARC" << endl;}
  else{ cout << "ABC" << endl;}
   //cout << piyo;
  
}


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


using namespace std;

// RL 前のR数と後ろのL数
struct RLP{
  int p; // R最後尾の配列インデックス
  int r; // pを含めた、pまでの連続したR数
  int l; // pを含まない、p+1から次の境目までのL数
  int np; // pに集まる人間の数
  int npp; // p+1に集まる人間の数
};
  

void printarray(int* a, int n){
  for(int i = 0; i < n; i++){
    cout << a[i] << " " << flush;
  }
  cout << endl;
}

int main(){
  string s;
  cin >> s;
  cin.ignore();

  int n = s.length();

  vector <RLP> rlp;
  RLP tmp_rlp;
  tmp_rlp.r = 0;
  tmp_rlp.l = 0;
  tmp_rlp.p = 0;
  tmp_rlp.np = 0;
  tmp_rlp.npp = 0;
  bool prev_r = true;
  for (int i = 0; i < n; i++){
    if(s[i] == 'R'){
      if(prev_r == false){
        rlp.push_back(tmp_rlp);
        tmp_rlp.l = 0;
        tmp_rlp.r = 0;
      }
      ++tmp_rlp.r;
      prev_r = true;
    }else if(s[i] == 'L'){
      if(prev_r == true){
        tmp_rlp.p = i - 1; // i==0ではありえない
      }
      ++tmp_rlp.l;
      prev_r = false;
    }
  }

  // 最後のtmp_rlpを入れる(最後はLだからfor中の条件に引っかからない)
  rlp.push_back(tmp_rlp);

  // 10の100乗は偶数
  // しかも収束するには十分
  // ということは
  // pには、pから偶数の距離を持つ人が集まる。
  // p+1には、pから奇数の距離を持つ人が集まる。
  for (int i =0; i < rlp.size(); i++){
    //cout << "RLP [" << i << "] : p = " << rlp[i].p << ", r = " << rlp[i].r << ", l = " << rlp[i].l << endl;
    rlp[i].np = rlp[i].r / 2 + rlp[i].l / 2;
    if(rlp[i].r % 2 == 0){
      rlp[i].np = rlp[i].r / 2;
      rlp[i].npp = rlp[i].r / 2;
    } else {
      rlp[i].np = rlp[i].r / 2 + 1;
      rlp[i].npp = rlp[i].r / 2;
    }
    if(rlp[i].l % 2 == 0){
      rlp[i].np += rlp[i].l / 2;
      rlp[i].npp += rlp[i].l / 2;
    } else {
      rlp[i].np += rlp[i].l / 2 ;
      rlp[i].npp += rlp[i].l / 2 + 1;
    }
  }

  // 表示
  for(int i = 0, ptr = 0; i < n; i++){
    if(ptr >= rlp.size()) {
      cout << 0 << " " << flush;
      continue;
    }
    if(rlp[ptr].p == i){
      cout << rlp[ptr].np << " " << rlp[ptr].npp << " " << flush;
      ++i;
      ++ptr;
    } else {
      cout << 0 << " " << flush;
    }
  }

  
  return 0;
}
  


Measured memory_bytes: 1816
#include"bits/stdc++.h"
#define ll long long
#define inf 100005
using namespace  std;

vector<vector<ll>>g(inf);
vector<ll>indgree(inf);
vector<ll>dist(inf);
bool visted[inf];

void dfs(ll v){
	visted[v]=true;
	vector<ll>::iterator it;

	for(it=g[v].begin();it<g[v].end();it++){
		dist[*it]=max(dist[*it],dist[v]+1);
		indgree[*it]--;

		if(indgree[*it]==0){
			dfs(*it);
		}
	}
}

int main(){

	ll n,m,i,j,a,b;
	cin>>n>>m;

	for(i=0;i<m;i++){
		cin>>a>>b;
		g[a].push_back(b);
		indgree[b]++;
	}

	for(i=1;i<=n;i++){
		if(!visted[i] && indgree[i]==0){
			dfs(i);
		}
	}


	ll d=-1;

	for(i=1;i<=n;i++){
		if(d<dist[i]){
			d=dist[i];
		}
	}

	cout<<d<<endl;

	return 0;
}

Measured memory_bytes: 16408
MODE = "stdio"

line = Array.new

if(defined? MODE)
  line = STDIN.read.split("\n")
else
  tmp = "\
  3
  1 1 3 8
  3 2 2 7
  4 3 8 1
  ".split("\n")
  tmp.each{|s|
    line << s.strip
  }
end
n =  line[0].to_i

ary = Array.new(4){Array.new(3){Array.new(10,0)}}

(1..n).each do |num|
b,f,r,v = line[num].split(" ").map(&:to_i)
ary[b-1][f-1][r-1] += v
end
idx=0
ary.each do |s|
  s.each do |ss|
    puts " " + ss.join(" ")
  end
  idx += 1
  puts '#'*20 if idx<=3
end

Measured memory_bytes: 8724
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using lpair = pair<ll, ll>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i=(m);i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i>=(n);i--)
#define printa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
void print() {}
template <class H,class... T>
void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    ll A[200010];
    rep(i,0,N) cin >> A[i];
    map<ll,ll> mp;
    rep(i,0,N) mp[A[i]]++;
    ll ans = 0;
    for(auto &e: mp){
        if(e.second >= 2){
            ans += e.second * (e.second-1) / 2;
        }
    }
    rep(i,0,N){
        ll res = ans;
        ll v = mp[A[i]];
        if(v >= 2){
            res -= v * (v-1) / 2;
            res += (v-1) * (v-2) / 2;
        }
        print(res);
    }
    



}

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

#define SUBTASK 1

using ll = long long;

const ll XMAX = 1.1e17;

const int MAXN = 1.1e5;
int N;
pair<ll, ll> P[MAXN];

bool checkPt(ll Y) {
	bool res = 0;
	for (int i = 0; i < N; i++) {
		res ^= (((Y - P[i].second) | P[i].first) == P[i].first);
	}
	return res;
}

pair<ll, ll> ptToBounds(ll Y) {
	assert(checkPt(Y));
	ll lo = Y, hi = Y;
	for (int l = 59; l >= 0; l--) {
		if (checkPt(hi + (1ll << l))) {
			hi += (1ll << l);
		}
		if (checkPt(lo - (1ll << l))) {
			lo -= (1ll << l);
		}
	}
	return {hi - lo, lo};
}

pair<ll, ll> go() {
#if SUBTASK == 1
	return ptToBounds(XMAX);
#else
#endif
}

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> P[i].first >> P[i].second;
		P[i].first += XMAX;
		P[i].second += XMAX;
		assert(P[i].first >= 0);
		assert(P[i].second >= 0);
	}

	auto ans = go();
	ans.first -= XMAX;
	ans.second -= XMAX;

#if SUBTASK == 1
	cout << ans.first << '\n';
#else
	cout << ans.first << ' ' << ans.second << '\n';
#endif

	return 0;
}


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

int a,b,c;
int main()
{
    cin>>a>>b>>c;
    int maxi=max(max(a,b),c);
    int ans=0;
    ans=3*maxi-a-b-c;
    if(ans%2==0)
        cout<<ans/2<<endl;
    else
        cout<<(ans+1)/2+1<<endl;
}


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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

#define lf double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
    int n; cin>>n;
    map<int, int> Map;
    rep(i, n){
        int a; cin>>a;
        Map[a] = i+1;
    }
    for(auto e:Map){
        cout << e.se << " ";
    }
    cout << "\n";
    return 0;
}


Measured memory_bytes: 5504
#include<bits/stdc++.h>
using namespace std;
#define F(i,s,e) for(int i=s;i<e;++i)

int main()
{
    long n;
    cin >> n;
    if(n%2==1){
        cout << 0 << endl;
        return 0;
    }
    long ans=0,cnt=1,x=10;
    while(x<=n){
        ans+=n/x;
        ++cnt;
        x*=5;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<int>;
using VL = vector<ll>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);--(i))
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; }return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; }return 0; }
template<class T> inline istream& operator>>(istream& input, vector<T>& v) { for (auto& elemnt : v)input >> elemnt; return input; }
inline void init() { /*cin.tie(nullptr);*/ cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }

int main() {
    init();

    int n; cin >> n;

    vector<string> s(n);
    cout << "0\n" << flush;
    cin >> s[0];
    if (s[0] == "Vacant")return 0;

    int l = 1, r = n;
    while (1) {
        int mid = (l + r) / 2;
        cout << mid << "\n" << flush;
        fflush(stdout);
        cin >> s[mid];
        if (s[mid] == "Vacant")return 0;

        if ((mid % 2 == 0 && s[0] == s[mid]) || (mid % 2 == 1 && s[0] != s[mid]))l = mid + 1;
        else r = mid;
    }
}


Measured memory_bytes: 1620
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ll long long int
const int INF = 2147483647;
const ll MOD = 1000000007;

using namespace std;

int main() {
  int n;
  cin >> n;
  set<int> s;
  REP(i, n) {
    int d;
    cin >> d;
    s.insert(d);
  }
  cout << s.size() << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int64_t i=0;i < (int64_t)(n);i++)
#define invrep(i,n) for(int64_t i=n-1;i >= 0L;i--)
#define prep(i,n) for(int64_t i=1;i <= (int64_t)(n);i++)
using namespace std;

//////全探索したいときに開けよ////////
vector<vector<int>> fspattern;
vector<int> fspattern_draft;
int fspcnt = 0;

void setfspattern_core(int floor,int number,int degree){
  if(floor==degree){
    fspattern.at(fspcnt) = fspattern_draft;
    fspcnt++;
  }else{
    rep(i,number){
      fspattern_draft.at(floor) = i;
      setfspattern_core(floor+1,number,degree);
    }
  }
}

void setfspattern(int number,int degree){
  int64_t array_num = 1;
  fspcnt = 0;
  rep(i,degree){
    array_num *= number;
  }
  fspattern = vector<vector<int>>(array_num,vector<int>(degree));
  fspattern_draft = vector<int>(degree);
  setfspattern_core(0,number,degree);
}

//////nCrのmodを求めたいときに開けよ/////////
//int64_t univMod = 1000000007;
//int64_t factnum = 100000
//vector<int64_t> modfact(factnum);
//vector<int64_t> modinvfact(factnum);

/*void setmodfact(){
  for(int i=0;i<factnum;i++){
    if(i == 0){
      modfact.at(i) = 1;
    }else{
      modfact.at(i) = (modfact.at(i-1)*i)%univMod;
    }
  }
}

int64_t calcmodpower(int64_t a,int64_t n){
  int64_t res = 1;
  while(n != 0){
    if(n & 1){
      res = (res * a) % univMod;
    }
    a = (a*a) % univMod;
    n = n >> 1;
  }
  return res;
}

int64_t calcinverse(int64_t n){
	return calcmodpower(n,univMod-2);
}

void setmodinvfact(){
  for(int i=0;i<factnum;i++){
    if(i==0){
      modinvfact.at(i) = 1;
    }else{
      modinvfact.at(i) = calcmodpower(modfact.at(i),univMod-2);
    }
  }
}

int64_t calcmodcomb(int64_t n,int64_t r){
  return (((modfact.at(n)*modinvfact.at(r))%univMod)*modinvfact.at(n-r))%univMod;
}

int64_t calcmodpositive(int64_t n){
  return (n + ((abs(n)+univMod-1)/univMod)*univMod)%univMod;
}
  
    */


/*
int64_t calcGCD(int64_t a,int64_t b){
	int64_t p = a;
	int64_t q = b;
	int64_t c = a%b;
	while(c != 0){
		p = q;
		q = c;
		c = p%q;
	}
	return q;
}
*/

int main(){
  int H,W,h,w;
  cin >> H >> W >> h >> w;
  cout << (H-h)*(W-w);
}

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

int main()
{
    stack<char> st;
    long int N;
    cin>>N;
    if(N<=26)
        cout<<(char)(97+N-1);
    else{
    int p = (int) log(N)/log(26);
    /*for(int i=0;i<a;i++)
    {
        int a = N%26;
        if(a==0)
            st.push('z');
        else
            st.push((char)(97+a-1));
        N = (long int) N/26;
    }*/
    while(N)
    {
        int a = N%26;
        if(a==0)
            {st.push('z');N = (long int) N/26;N--;}
        else
            {st.push((char)(97+a-1));
        N = (long int) N/26;}
    }    //if(() && (N <= (()) )
    while(!st.empty())
    {
        cout<<st.top();st.pop();
    }}
    return 0;
}


Measured memory_bytes: 3704
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define reps(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; --i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define repc2(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define inf 2e9
#define linf 9000000000000000000ll
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

#define N 200009
int n;
vector<ll> vx, vy;

int main() {
    cin >> n;
    vx.resize(n);
    vy.resize(n);
    rep(i, n) {
        ll x, y;
        scanf("%lld%lld", &x, &y);
        vx[i] = x - y;
        vy[i] = x + y;
    }
    cout << max(*max_element(all(vy)) - *min_element(all(vy)), *max_element(all(vx)) - *min_element(all(vx))) << endl;
    return 0;
}

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

int i;

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    vector<int> count(100001);
    for (i = 0; i < n; i++)
    {
        cin >> a[i];
        count[a[i]]++;
        count[a[i] + 1]++;
        count[a[i] + 2]++;
    }

    int ans = *max_element(count.begin(), count.end());

    cout << ans;
}

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

template <typename T>
T gcd(T a, T b) {
  if (a % b == 0) {
    return b;
  } else {
    return gcd(b, a % b);
  }
}

template <typename T>
T lcm(T a, T b) {
  if (a <= b)
    return b / gcd(a, b) * a;
  else
    return a / gcd(a, b) * b;
}

int main() {
  int n;
  cin >> n;
  vector<ll> t(n);
  for (int i = 0; i < n; i++) cin >> t[i];

  ll ans = 1;
  for (int i = 0; i < n; i++) {
    ans = max(ans, lcm(t[i], ans));
  }
  cout << ans << endl;
}


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

ll mod = 1000000009;
ll base = 12345678;

int main() {
    int N;
    string s;
    cin >> N;
    cin >> s;
    vector<ll> rh_sum(N+1);
    rh_sum[0] = 0;
    for (int i = 1; i <= N; i++) {
        rh_sum[i] = (rh_sum[i-1] * base + s[i-1]) % mod;
    }
    vector<ll> basepower(N, 1);
    for (int i = 1; i < N; i++) {
        basepower[i] = (basepower[i-1] * base) % mod;
    }
    int ans = 0;
    for (int i = 1; i <= N-1; i++) {
        for (int j = i+1; j <= N; j++) {
            if (s[i] != s[j]) continue;
            int a = max(1, ans);
            int b = min(j-i, N-j+1) + 1;
            while (b-a > 1) {
                int c = (a*3+b+2)/4;
                ll rhi = rh_sum[i+c-1] - rh_sum[i-1] * basepower[c];
                ll rhj = rh_sum[j+c-1] - rh_sum[j-1] * basepower[c];
                if ((rhj-rhi) % mod == 0) a = c;
                else b = c;
            }
            if (a > ans) ans = a;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int dp[5010][5010];

int main()
{
  int N, ans = 0;
  string S;
  cin >> N >> S;
  for (int i = N - 1; i >= 0; i--)
  {
    for (int j = N - 1; j >= 0; j--)
    {
      if (S[i] == S[j])
      {
        dp[i][j] = dp[i + 1][j + 1] + 1;
      }
    }
  }
  for (int i = 0; i < N - 1; i++)
  {
    for (int j = i + 1; j < N; j++)
    {
      ans = max(ans, min(dp[i][j], j - i));
    }
  }
  cout << ans << endl;
}

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

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define Eback(s) s.erase(s.end()-1,s.end())
#define pb push_back
#define pf push_front
#define mod 1000000007
#define m_p make_pair
#define DOUBLE fixed << setprecision(15)
#define OK puts("OK")
#define OK1 puts("OK1")
#define OK2 puts("OK2")
#define SIZE(s) (int)s.size()
#define INF ((1LL<<62)-(1LL<<31))

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
typedef vector<pair<ll,ll>> vpll;
typedef vector<string> vs;
const double pi = acos(-1.0);

template<class A, class B>
ostream& operator<<(ostream& ost, const pair<A, B>&p) {
	ost << "{" << p.first << ", " << p.second << "} ";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost, const vector<T>&v) {
	ost << "{";
	for (int i = 0; i<(int)v.size(); i++) {
		if (i)ost << " ";
		ost << v[i];
	}
	ost << "} \n";
	return ost;
}

template<class A, class B>
ostream& operator<<(ostream& ost, const map<A, B>&v) {
	ost << "{";
	for (auto p:v) {
		ost << "{" << p.first << ", " << p.second << "} ";
	}
	ost << "} ";
	return ost;
}

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

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

ll gcd(ll x, ll y) { return (y == 0) ? x : gcd(y, x % y); }
ll lcm(ll x, ll y) { return x * y / gcd(x, y); }

int main()
{
	bool b=true;
	ll n,a;
	cin >> n;
	rep(i,n){
		cin >> a;
		if(a%2==0 && a%3!=0 && a%5!=0) b=false;
	}
	cout << (b?"APPROVED\n":"DENIED\n");
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <climits>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <string>
#include <cstdio>
#include <climits>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <utility>
#include <queue>
#include <cstring>
#include <set>
#include <map>
#include <complex>
#define rep(i, n) for (int i = 0; i < int(n); i++)
using namespace std;
long long MOD = 998244353;
long long INF = 1000000000000000; //10^15
typedef long long ll;
typedef unsigned long long ull;


ll powMod(ll x, ll n, ll mod) {
  if (n == 0) return 1;
  ll t = powMod(x, n/2, mod);
  t = t * t % mod;
  if (n & 1) return t * x % mod;
  return t;
}



int main(void) {

  ll x, k;
  cin >> x >> k;

  x %= k;
  if (x < k - x) cout << x << endl;
  else cout << -x + k << endl;




}


Measured memory_bytes: 256
#include <bits/stdc++.h>
// #include <iostream>
using namespace std;
#define FALSE 0
#define TRUE 1

int main(){
    int N;
    vector<int64_t>     vP(100010);
    map<int64_t, int>   mP;
    string res;

    // 嘘じゃない解法
    cin >> N;
    for (int i=0; i<N; i++){
        cin >> vP.at(i);
        mP[vP.at(i)]++;
    }

    res = "No";
    
    int len_mP = mP.size();
    if (len_mP == 1) {
        // 入力が1種類のとき
        // 全部 0 ならOK、 0 以外はNG
        res = (mP.count(0))? "Yes": "No";
    }
    if (len_mP == 2) {
        // 2種類のとき
        // 0 が N/3、 x が 2N/3 ならOK
        if (mP.count(0) && N%3==0)
            res = (mP[0] == N/3)? "Yes": "No";
    }
    if (len_mP == 3) {
        // 3種類のとき
        // N/3 ずつの入力が (x^y)==z ならOK
        if (N%3==0) {
            int64_t x[3];
            int isN3 = TRUE;
            int i=0;
            map<int64_t, int>::iterator iter;
            for (iter = mP.begin(); iter != mP.end(); iter++) {
                x[i] = iter->first;
                if (iter->second != N/3) {isN3 = FALSE;}
                i++;
            }
            if (isN3)
                res = ((x[0]^x[1])==x[2])? "Yes": "No";
        }
    }

    cout << res << endl;
    return 0;
}


Measured memory_bytes: 5888
#include<stdio.h>

int main(void)
{
        int x,a,b;

        scanf("%d%d%d",&x,&a,&b);

        if(a>=b)
                printf("delicious\n");
        else{
                if(b-a<=x)
                        printf("safe\n");
                else
                        printf("dangerous\n");
        }

        return 0;
}


Measured memory_bytes: 128
import sys,os
from collections import defaultdict, deque
from math import ceil, floor
if sys.version_info[1] >= 5:
    from math import gcd
else:
    from fractions import gcd
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in os.environ else lambda *x: 0
def main(given=sys.stdin.readline):
    input = lambda: given().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    MOD = 10**9+7

    S = input()
    T = input()
    if S == T[:-1] and len(S) + 1 == len(T):
        print('Yes')
    else:
        print('No')

    

if __name__ == '__main__':
    main()

Measured memory_bytes: 65152
#include <algorithm>
#include <cmath>
#include <vector>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <ctype.h>
#include <climits>
#include <queue>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i = 0; i < (ll)(n); ++i)
template<class T> inline bool chmax(T& a, T b) { if(a < b){ a=b; return 1; } return 0;}
template<class T> inline bool chmin(T& a, T b) { if(a > b){ a=b; return 1; } return 0;}

int main(){
	string s;
	ll k;
	cin >> s >> k;
	
	ll index=1;
	while(s[index-1]=='1' && k>index){
		index++;
	}
	cout << s[index-1] << endl;
	
	return 0;
}

Measured memory_bytes: 3600
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define INF 100000000000000
int main(){
	string sd,t,ins;cin>>sd>>t;
	ins=sd;

	int tsize=t.size(),sdsize=sd.size();
	bool changed=false;

	for(int i=sdsize-1;i>=tsize-1;i--){
		bool ok=true;
		for(int j=i;j>i-tsize;j--){
			if(sd[j]=='?' || sd[j]==t[tsize-1-(i-j)]) continue;
			ok=false;break;
		}
		
		if(ok){
			for(int j=i;j>i-tsize;j--){
				sd[j]=t[tsize-1-(i-j)];
				changed=true;
			}
			break;
		}
	}

	
	if(sd==ins && !changed){cout<<"UNRESTORABLE"<<endl;return 0;}

	for(int i=0;i<sdsize;i++){
		if(sd[i]=='?'){sd[i]='a';}
	}

	cout<<sd<<endl;
	return 0;
}

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

#define INF 1e9
#define llINF 1e18
#define MOD 1e9+7
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
using namespace std;
int main(){
  ll n;cin>>n;
  vector<ll>num(n);
  ll rui[n+10]={};
  for(int i=0;i<n;i++){cin>>num[i];rui[i+1]=rui[i]+num[i];}

  vector<pair<ll,ll> >left(n+10);
  vector<pair<ll,ll> >right(n+10);

  ll lpo=1;
  for(int i=2;i<n-1;i++){
    while(i>lpo-1&&(((rui[i]-rui[lpo])-rui[lpo])>0))
      lpo++;
    if((lpo!=0)&&abs((rui[i]-rui[lpo])-rui[lpo])>abs((((rui[i]-rui[lpo-1])-rui[lpo-1])))){
      lpo--;
    }
    left[i-2]=mp(abs(rui[i]-rui[lpo]),rui[lpo]);
  }

  ll rpo=3;
  for(int i=2;i<n-1;i++){
    while(n>rpo-1&&((rui[n]-rui[rpo])-(rui[rpo]-rui[i]))>0)
      rpo++;
    if((rpo-i!=1)&&abs(((rui[n]-rui[rpo])-(rui[rpo]-rui[i])))>abs(((rui[n]-rui[rpo-1])-(rui[rpo-1]-rui[i])))){
	rpo--;
      }
      right[i-2]=mp(abs(rui[n]-rui[rpo]),abs(rui[rpo]-rui[i]));
  }

  ll ans=llINF;
  for(int i=0;i<n-3;i++){
    ll ma=max(max(left[i].F,left[i].S),max(right[i].F,right[i].S));
    ll mi=min(min(left[i].F,left[i].S),min(right[i].F,right[i].S));
    ans=min(ans,ma-mi);
  }

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


Measured memory_bytes: 9600
#include<stdio.h>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
ll dp[1 << 15];
vector<int>pat[15];
int cnt[15][1 << 15];
int main()
{
	int num, way;
	scanf("%d%d", &num, &way);
	for (int i = 0; i < way; i++)
	{
		int za, zb;
		scanf("%d%d", &za, &zb);
		za--, zb--;
		pat[za].push_back(zb);
	}
	for (int p = 0; p < (1 << num); p++)
	{
		for (int i = 0; i < num; i++)
		{
			for (int j = 0; j < pat[i].size(); j++)
			{
				if (p&(1 << pat[i][j]))cnt[i][p]++;
			}
		}
	}
	dp[0] = 1;
	for (int p = 0; p < (1 << num); p++)
	{
		if (((p & 1) == 0) != ((p & 2) == 0))
		{
			dp[p] = 0;
			continue;
		}
		//printf("%d %lld\n", p, dp[p]);
		int v[15];
		int pt = 0;
		for (int i = 0; i < num; i++)if ((p&(1 << i)) == 0)v[pt++] = i;
		for (int q = 0; q < (1 << pt); q++)
		{
			int x = 0;
			for (int i = 0; i < pt; i++)if (q&(1 << i))x += 1 << v[i];
			if (x == 0)continue;
			ll tim = 1;
			for (int i = 0; i < pt; i++)if ((q&(1 << i)) == 0)tim = (tim*((1 << cnt[v[i]][x]) - 1)) % mod;
			for (int i = 0; i < num; i++)if (p&(1 << i))tim = (tim*(1 << cnt[i][x])) % mod;
			dp[p + x] = (dp[p + x] + tim*dp[p]) % mod;
		}
	}
	ll ans = 1;
	for (int i = 0; i < way; i++)ans = ans * 2 % mod;
	printf("%lld\n", (ans + mod - dp[(1 << num) - 1]) % mod);
}

Measured memory_bytes: 2176
#include<cstdio>
#include<algorithm>

using namespace std;

long long n,m,k;
long long a[200010];

int main () {
	scanf("%lld%lld",&n,&k);
	for (long long i=0;i<n;i++) {
		scanf("%lld",&a[i]);
	}
	sort(a,a+n); reverse(a,a+n);
	m=0;
	for (long long i=k;i<n;i++) {
		m+=a[i];
	}
	printf("%lld\n",m);
	return 0;
}

Measured memory_bytes: 1664
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<string>
#include<math.h>
#include<vector>
#include<iomanip>
using namespace std;

long long int gcd(long long int x, long long int y)
{
	if (y == 0) { return x; }
	return gcd(y, x % y);
}

int main(void)
{
	int n;
	double a[110],ans = 0;
	cin >> n;
	for (int i = 0; i < n; i++) { cin >> a[i]; ans += 1 / a[i]; }
	cout << fixed << setprecision(8) <<  1 / ans << endl;
	return 0;
}


Measured memory_bytes: 256
import collections

N,K,Q=map(int,input().split())
A=[]
for i in range(Q):
    a=int(input())
    A.append(a)

#print(A)

p=[(K-Q)]*N
for a in A:
    p[a-1]+=1

for pp in p:
    if pp > 0:
        print('Yes')
    else:
        print('No')



Measured memory_bytes: 55896
#include<bits/stdc++.h>
#define ll long long 
using namespace std;
bool check(ll r,ll n)
{	if (r>n)return false;
	int  t=0,f=0,s=0;
	while(r>0){
		ll x = r%10;
		r=r/10;
		if (x==3)t=1;
		if (x==5)f=1;
		if (x==7)s=1;
	}
	if (t+f+s==3)return true;
    return false;
}
ll bfs(ll s,ll n)
{	
    ll ans=0;
	int arr[3]={3,5,7};
	queue<int> q;
	q.push(s);
	while(!q.empty())
	{	ll u = q.front();
		q.pop();
		for (int i=0;i<3;i++)
		{	ll num=u*10+arr[i];
			if (num<=n)
				q.push(num); 	
		}
		if (check(u,n))ans++;
	}
	return ans;
}
ll solve(ll n)
{
	return( bfs(3,n)+bfs(5,n)+bfs(7,n) );
}
int  main()
{
	ll n;
	cin>>n;
	cout<<solve(n);
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <stack>
#include <cstdio>
#include <cmath>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using P1 = pair<int, P>;
#define FOR(t, a, b) for (int t = (a); t < (b); ++t)
#define REP(t, n) FOR(t, 0, n)

int main()
{
    int n, k;
    cin >> n >> k;
    REP(i, n)
    {
        int temp;
        cin >> temp;
    }
    if (n == k)
    {
        cout << 1 << endl;
    }
    else if (k == 2)
    {
        cout << n - 1 << endl;
    }
    else if (n % (k - 1) == 0 || n % (k - 1) == 1)
    {
        cout << n / (k - 1) << endl;
    }
    else
    {
        cout << n / (k - 1) + 1 << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<cctype>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
#define reps(i,n) for (int i=1;i<=(n);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rreps(i,n) for (int i=(n);i>0;i--)
#define all(v) (v).begin(),(v).end()
#define pi 3.1415926535897932384
#define E9 1000000000
#define eps 1e-4
#define pii pair<int,int>
template<class T> inline bool chmin(T &a, T b) {if (a>b) {a = b; return 1;} return 0;};
template<class T> inline bool chmax(T &a, T b) {if (a<b) {a = b; return 1;} return 0;};
typedef long long int ll;
const long long INF = 1LL << 60;

int main(){
  int N, M; cin >> N >> M;
  int cnt[N] = {};
  rep(i,M){
    int a, b; cin >> a >> b;
    --a, --b;
    cnt[a]++, cnt[b]++;
  }
  bool ans = true;
  rep(i,N){
    if (cnt[i]&1) ans = false;
  }
  if (ans) cout << "YES" << endl;
  else cout << "NO" << endl;
  
  
  // cout << fixed << setprecision(10);
  
  return 0;
}


Measured memory_bytes: 3952
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define P pair<int,int>
using ll=int64_t;
using namespace std;
#define ketasuu(n) fixed<<setprecision(n)
#define btoe(p) p.begin(),p.end()
#define etob(p) p.rbegin(),p.rend()


int gcd(int a, int b){ return (b? gcd(b,a%b): a);}


int main(){
    int a,b,k,cnt=0,ans=0;
    vector<int> p;
    cin>>a>>b>>k;
    while(ans<=gcd(a,b)){
        ans++;
        if(a%ans==0 && b%ans==0){
            cnt++;
            p.push_back(ans);
        }
    }
    sort(etob(p));
    cout<<p[k-1]<<endl;
    return 0;
}

Measured memory_bytes: 256
def dfs(s,n,adj):
    adj = 'abcdefghij'
    if len(s) == n:
        print(s)
    else:
        for child in adj[:len(set(s))+1]:
            dfs(s+child,n,adj)
    return -1

def main():
    import sys
    def input(): return sys.stdin.readline().rstrip()
    n = int(input())
    adj = 'abcdefghij'
    dfs('a',n,adj)


if __name__ == '__main__':
    main()

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

int main()
{
	long long X, Y; cin >> X >> Y;
	if (X%Y == 0)cout << -1 << endl;
	else {
		for (int i = 1; i < 10000; i++) {
			if ((X*i) % Y != 0) {
				cout << X*i << endl;
				break;
			}
		}
	}


    return 0;
}



Measured memory_bytes: 256