akhauriyash/Code-Regression huggingface dataset:
package main

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

////////////////////////////////////////
///        templates                 ///
////////////////////////////////////////

var sc = bufio.NewScanner(os.Stdin)

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

var rdr = bufio.NewReaderSize(os.Stdin, 1000000)

func readBigLine() string {
        buf := make([]byte, 0, 1000000)
        for {
                l, p, e := rdr.ReadLine()
                if e != nil {
                        panic(e)
                }
                buf = append(buf, l...)
                if !p {
                        break
                }
        }
        return string(buf)
}

func strSprit(str string) []string {
        cols := strings.Split(str, " ")
        return cols
}

func parseInt(str string) int {
        n, _ := strconv.Atoi(str)
        return n
}

func intSprit(str string) []int {
        strs := strSprit(str)
        cols := make([]int, len(strs))
        for i, v := range strs {
                cols[i] = parseInt(v)
        }
        return cols
}

type SortSlice []int

func (s SortSlice) Len() int {
        return len(s)
}

func (s SortSlice) Swap(i, j int) {
        s[i], s[j] = s[j], s[i]
}

func (s SortSlice) Less(i, j int) bool {
        return s[i] < s[j]
}

func reverseString(str string) string {
        buf := []rune(str)
        for i, j := 0, len(buf)-1; i < j; i, j = i+1, j-1 {
                buf[i], buf[j] = buf[j], buf[i]
        }
        return string(buf)
}

////////////////////////////////////////
///        end templates             ///
////////////////////////////////////////

func main() {
        line := readBigLine()
        num := parseInt(line)

        sum := 0
        n := num
        for {
                sum += n % 10
                n /= 10
                if n <= 0 {
                        break
                }
        }

        if num%sum == 0 {
                fmt.Println("Yes")
        } else {
                fmt.Println("No")
        }

}


Measured memory_bytes: 640
#include <bits/stdc++.h>
typedef long long lint;
using namespace std;

template <class T>
bool chmin(T &a, const T &b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}

int a, b, q;
vector<lint> s, t;

int main() {
    cin >> a >> b >> q;
    s.resize(a + 2), t.resize(b + 2);
    s.front() = t.front() = LLONG_MIN / 5;
    s.back() = t.back() = LLONG_MAX / 5;
    for (int i = 0; i < a; i++) {
        cin >> s[i + 1];
    }
    for (int i = 0; i < b; i++) {
        cin >> t[i + 1];
    }
    for (int i = 0; i < q; i++) {
        lint x;
        cin >> x;
        int near_shrine = lower_bound(s.begin(), s.end(), x) - s.begin();
        int near_temple = lower_bound(t.begin(), t.end(), x) - t.begin();
        lint ans = LLONG_MAX;
        for (int j = near_shrine - 1; j <= near_shrine; j++) {
            for (int k = near_temple - 1; k <= near_temple; k++) {
                chmin(ans, abs(x - s[j]) + abs(s[j] - t[k]));
                chmin(ans, abs(x - t[k]) + abs(t[k] - s[j]));
            }
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 2944
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]

from collections import defaultdict, deque
from sys import exit
import math
import copy
from bisect import bisect_left

import sys
# sys.setrecursionlimit(1000000)
# list(map(int, input().split()))
mod = 10 ** 9 + 7

N = getN()
A = getList()
# Aの各数字の（２進数における）各桁ごとに分解して排他的論理和を求める
# 例
# 3
# 1 2 3 →
# 1, 10, 11
# 2 ** 0の桁について(1 ^ 2) 1 ^ 0 = 1,(1 ^ 3) 1 ^ 1 = 0,(2 ^ 3) 0 ^ 1 = 1
# 2 ** 1の桁について 0(1の2 ** 1の桁は0) ^ 1 = 1, 0 ^ 1 = 1, 1 ^ 1 = 0
# 各桁について2 ** iの桁が1の数字の選び方 * 2 ** iの桁が0の数字の選び方 * 2 ** iを
# 足し合わせる
lista = [[0, 0] for i in range(61)]
# bitの各桁が１か０かをlistaに収納
def splitbit(n):
    for i in range(61):
        if n & (1 << i):
            lista[i][1] += 1
        else:
            lista[i][0] += 1
for i in A:
    splitbit(i)
ans = 0
for i in range(61):
    ans += ((lista[i][0] * lista[i][1]) * (2 ** i)) % mod
print(ans % mod)

Measured memory_bytes: 128880
#include<iostream>
#include<cmath>

int main(){
    int x, a, b;
    std::cin >> x >> a >> b;
    if(std::abs(x - a) > std::abs(x - b)){
        std::cout << "B" << std::endl;
    }else{
        std::cout << "A" << std::endl;
    }
    return 0;
}


Measured memory_bytes: 256
// In the name of GOD
#include<bits/stdc++.h>
using namespace std;

#define debug(x) cout<<#x<<" :: "<<x<<"\n";
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n";
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\n";

#define     IOS         ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define 	setprecn(x) cout<<fixed<<setprecision(x);
#define 	ll          long long int
#define 	pb          push_back
#define 	pll         pair<ll,ll>
#define 	vll         vector<ll>
#define 	ff          first
#define 	ss          second
#define 	all(a)      (a).begin(),(a).end()
#define 	sz(x)       (ll)x.size()
#define 	mod         1000000007
#define 	inf         10000000000000007
#define 	rep(i,n)    for(ll i=0;i<n;i++)
#define 	repe(i,a,b) for(ll i=a;i<b;i++)
#define 	lbnd        lower_bound
#define 	ubnd        upper_bound
#define 	bs          binary_search

ll power(ll a,ll b,ll m=mod)
{
	if(b==0)
		return 1;
	if(b==1)
		return a;
	ll c=power(a,b/2,m);
	if(b%2==0)
		return((c%m)*(c%m))%m;
	return ((((c%m)*(c%m))%m)*(a%m))%m;
}

/********************************************************/
//	d.erase(unique(all(d)), d.end());




int main()
{
	IOS;
	ll n,k,m,i,j,c=0,cs=0,t;
	t=1;

	// cin>>t;
	string s;
	while(t--)
	{
		// reverse(a.begin(),a.end());
		cin>>n;
		// n=s.length();
		ll a[n];
		rep(i,n)
		{
			cin>>a[i];
		}
		repe(i,1,n-1)
		{
			if((a[i]<a[i-1] && a[i]>a[i+1]) || (a[i]>a[i-1] && a[i]<a[i+1]))
				c++;
		}
		
		cout<<c;
		
		if(t!=0)
	   		cout<<"\n";
	}
	return 0;
}

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

#define B 1
#define W 2

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

    vector<int> map[100001];
    for(int i=0;i<N-1;i++){
        int a,b;
        cin >> a >> b;
        map[a].push_back(b);
        map[b].push_back(a);
    }

    int col[100001];
    for(int i=1;i<=100000;i++) col[i]=0;
    col[1]=B;
    col[N]=W;

    int black=1,white=1;
    queue<int> bq,wq;
    bq.push(1);
    wq.push(N);

    while(!bq.empty() || !wq.empty()){
        queue<int> bn,wn;
        while(!bq.empty()){
            int t=bq.front();
            bq.pop();

            for(int x:map[t]){
                if(col[x]==0){
                    bn.push(x);
                    col[x]=B;
                    black++;
                }
            }
        }
        bq=bn;

        while(!wq.empty()){
            int t=wq.front();
            wq.pop();

            for(int x:map[t]){
                if(col[x]==0){
                    wn.push(x);
                    col[x]=W;
                    white++;
                }
            }
        }
        wq=wn;
    } 

    if(black>white) cout << "Fennec" << endl;
    else cout << "Snuke" << endl;

    return 0;
}

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

int main(){
  int i,j,b,n,k,*blood,canMake;
  while(1){
    scanf("%d %d",&n,&k);
    if(!n&&!k) break;
    canMake=1;
    blood=malloc(sizeof(int)*k);
    scanf("%d",blood);
    for(i=1;i<k;i++) scanf(" %d",blood+i);
    for(i=0;i<n;i++){
      scanf("%d",&b);
      blood[0]-=b;
      if(blood[0]<0) canMake=0;
      for(j=1;j<k;j++){
	scanf(" %d",&b);
	blood[j]-=b;
	if(blood[j]<0) canMake=0;
      }
    }
    printf("%s\n",canMake?"Yes":"No");
  }
  return 0;
}

Measured memory_bytes: 444
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long int LL;
typedef LL ll;
typedef string str;
typedef pair<ll,ll> pll;
typedef vector<ll> vll;
typedef stringstream strs;
 
#define X first
#define Y second
#define PB push_back
#define For(i,a,b) for (int i=a;i<b;i++)
#define Ford(i,a,b) for (int i=a;i>=b;i--)
#define smax(a,b) a=max(a,b)
#define smin(a,b) a=min(a,b)
#define SZ(a) ((ll)a.size())
#define ER(a) cout << #a << ' ' << a << endl
#define LB(a,n,x) (lower_bound(a,(a)+(n),x)-(a))
#define RET(x) { cout << x; exit(0); } 
const ll M=2e5+5,LG=19,SM=4000+5,inf=1e18+1;
ll mod=1e9+7;

ll n;
ll p[M],pv[M];
ll res=0;

int main()
{
	ios::sync_with_stdio(0);
    cin >> n;
    set<ll> se;
    se.insert(-1);
    se.insert(n);      
    For(i,0,n)
    {
        cin >> p[i];
        p[i]--;
        pv[p[i]]=i;
    }
    For(i,0,n)
    {
        auto ite=se.upper_bound(pv[i]);
        ll y=*ite;
        ll x=*(--ite);
        res+=(y-pv[i])*(pv[i]-x)*(i+1);
        se.insert(pv[i]);
    }
    RET(res);
}

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


int main() {

    int a, b;
    cin >> a >> b;
    int  ans = 0;
    for (int i = a; i <= b; ++i) {
        string s = to_string(i);
        if (s[0] == s[4] && s[1] == s[3]) {
            ++ans;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#import numpy as np
import sys
#from collections import deque
#import copy


def xnxn(n=0, flag="v"):
    """
    args:
        int n: a number of lows to read
    example:
        input   1
        retrun  1

        input   1 2 3
        return  [1,2,3]
        input   1 2 3
                4 
        return  [[1,2,3],
                [4]]
    """
    if n == 0:
        temp = list(map(int, input().split()))
        if len(temp) == 1:
            if flag == "l":
                return temp
            else:
                return temp[0]
        elif len(temp) > 1:
            return temp
    else:
        temp = [list(map(int, input().split())) for _ in range(n)]
        return temp


x, n = xnxn()

if n == 0:
    print(x)
    sys.exit()

p = xnxn(flag="l")


i = 0
while True:
    if (x - i in p) == False:
        print(x - i)
        sys.exit()
    elif (x + i in p) == False:
        print(x + i)
        sys.exit()
    i += 1


Measured memory_bytes: 9224
import java.util.*;
class Main{
  static Scanner sc = new Scanner(System.in);
  public static void main(String[] args){
    int X=sc.nextInt(),N=sc.nextInt(),ans=0;
    if(N!=0){
      List<Integer> p = new ArrayList<Integer>();
      for(int i=0;i<N;i++){
        p.add(sc.nextInt());
      }
      for(int i=0;true;i++){
        if(!p.contains(X-i)){
          System.out.println(X-i);
          break;
        }
        else if(!p.contains(X+i)){
          System.out.println(X+i);
            break;
        }
      }
    }
    else{
      System.out.println(X);
    }
  }
}

Measured memory_bytes: 35660
#include <cstdlib>
#include <climits>
#include <iostream>
#include <cstdint>
#include <vector>
#include <string>
#include <complex>
#include <bitset>
#include <queue>
#include <deque>
#include <stack>
#include <utility>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <regex>

#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/multi_array.hpp>

using namespace std;

int main()
{
    size_t N;
    std::cin >> N;

    size_t chars[26];
    for (auto& c: chars) {
        c = 50;
    }

    for (size_t i = 0; i < N; ++i) {
        std::string s;

        std::cin >> s;
        size_t thisChars[26] = {};

        for (auto itr = s.begin(); itr != s.end(); ++itr) {
            thisChars[*itr - 'a']++;
        }

        for (size_t j = 0; j < 26; ++j) {
            chars[j] = std::min(chars[j], thisChars[j]);
        }
    }

    for (size_t i = 0; i < 26; ++i) {
        for (size_t j = 0; j < chars[i]; ++j) {
            std::cout << char(i+'a');
        }
    }

    std::cout << std::endl;

    return 0;
}


Measured memory_bytes: 256
import sys

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

n = int(input())

if n == 1:
    print(0)
    sys.exit()

ans = factorization(n)

def f(v):
    i = 1
    s = 0
    while s < v:
        i += 1
        s += i
    return i - 1

print(sum([ f(v) for k,v in ans]))

Measured memory_bytes: 9496
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); ++i)
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
using namespace std;
using ll = long long;
using P = pair<int, int>;
using Pl = pair<long long, long long>;
using veci = vector<int>;
using vecl = vector<long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;

int main()
{
    int N; cin >> N;
    vector<bool> seen(N,false);
    string S; cin >> S;
    string ans = S;
    REP(i,N) {
        if(seen[i]) continue;
        bool ok = false;
        if(S[i] == '(') {
            for(int j = i+1; j < N; j++) if(S[j] == ')' && !seen[j]) {
                ok = true;
                seen[i] = true;
                seen[j] = true;
                break;
            }
            if(!ok) ans = ans + ')';
        } else {
            for (int j = i - 1; j >= 0; j--)
                if (S[j] == '(' && !seen[j])
                {
                    ok = true;
                    seen[i] = true;
                    seen[j] = true;
                    break;
                }
            if(!ok) ans = '(' + ans;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        // TODO 自動生成されたメソッド・スタブ

        Scanner sc = new Scanner(System.in);

        int a = sc.nextInt();
        int b = sc.nextInt();

        if(a + b == 3) {
            System.out.println(3);
        }
        else if(a + b == 4) {
            System.out.println(2);
        }
        else {
            System.out.println(1);
        }
        sc.close();

    }

}


Measured memory_bytes: 35368
#include<bits/stdc++.h>
using namespace std;
#define str string
int main(){
    int a,b,c;
    cin>>a>>b>>c;
    if(a==5||a==7){
        if(b==5||b==7){
            if(c==5||c==7){
                if(a+b+c==17){
                    cout<<"YES"<<endl;
                }
                else cout<<"NO"<<endl;
            }
        }
    }
    else cout<<"NO"<<endl;
}


Measured memory_bytes: 256
a=int(input())
b=int(input())
c=int(input())
x=int(input())
ans=0
for i in range(a+1):
  for j in range(b+1):
    for k in range(c+1):
      if k*50 + j*100 + i*500 == x:
        ans += 1
print(ans)


Measured memory_bytes: 3060
#include <iostream>
using namespace std;
int main(){
	int n;
	int a;
	int b[100000];
	int ans = 0;
	for(int i = 0;i < 100000;i++){
		b[i] = 0;
	}
	cin >> n;
	for(int i = 0;i < n;i++){
		cin >> a;
		if(a <= n){
			b[a - 1]++;
		}else{
			ans++;
		}
	}
	for(int i = 0;i < n;i++){
		if(b[i] >= i + 1){
			ans += b[i] - (i + 1);
		}else{
			ans += b[i];
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 640
import java.io.PrintWriter
val pw = PrintWriter(System.out)

fun main(args : Array<String>) {
    func()
    pw.flush()
}

fun func() {
    val n = nextInt()
    val a = listOfLong()
    val b = listOfLong()

    var killedMobs: Long = 0
    var killedInAdvance: Long = 0
    for (i in 0..n-1) {
        val numOfMobs: Long = a[i] - killedInAdvance
        if (numOfMobs >= b[i]) {
            killedMobs += b[i]
            killedInAdvance = 0
        } else {
            killedMobs += numOfMobs
            killedInAdvance = b[i] - numOfMobs
            if (killedInAdvance > a[i+1]) {
                killedInAdvance = a[i+1]
            }
            killedMobs += killedInAdvance
        }
    }

    println(killedMobs)
}

fun next() = readLine()!!
fun nextInt() = next().toInt()
fun listOfString() = next().split(" ")
fun listOfLong() = listOfString().map { it.toLong() }

fun println(value : Any) {
    pw.println(value)
}

Measured memory_bytes: 79596
#include <cstdio>
#include <algorithm>
#include <vector>
#define file(x) freopen(#x".in", "r", stdin), freopen(#x".out", "w", stdout)

const int N(1e5 + 10);
struct edge { int x, y; } e[N];
struct node { long long d; int id; } a[N];
inline int operator < (const node &l, const node &r)
	{ return l.d < r.d; }
int n, size[N], cnt;

int main()
{
	scanf("%d", &n);
	for (int i = 1; i <= n; i++)
		scanf("%lld", &a[i].d), a[i].id = i, size[i] = 1;
	std::sort(a + 1, a + n + 1);
	long long dis = 0, d;
	for (int i = n, p; i > 1; i--)
	{
		d = a[i].d - n + (size[i] << 1), p = std::lower_bound(a + 1, a + n + 1, (node) {d, 0}) - a;
		if (a[p].d != d) return puts("-1"), 0;
		e[++cnt] = (edge) {a[i].id, a[p].id}, size[p] += size[i], dis += size[i];
	}
	if (dis != a[1].d) puts("-1");
	else for (int i = 1; i < n; i++) printf("%d %d\n", e[i].x, e[i].y);
	return 0;
}


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

using namespace std;

typedef long long int LL;

#define st first
#define nd second
#define PLL pair <LL, LL>
#define PII pair <int, int>

const int N = 2007;

int n, mod;
int newt[3 * N][3 * N];
int dp1[3 * N][2 * N];
int dp2[3 * N][2 * N];

void add(int &a, int b){
	a += b;
	if(a >= mod)
		a -= mod;
}

int main(){
	scanf("%d %d", &n, &mod);
	for(int i = 0; i <= 3 * n; ++i){
		newt[i][0] = newt[i][i] = 1;
		for(int j = 1; j < i; ++j)
			newt[i][j] = (newt[i - 1][j] + newt[i - 1][j - 1]) % mod;
	}

	dp1[0][0] = 1;
	for(int i = 1; i <= 3 * n; ++i)
		for(int j = 0; j <= 2 * n; ++j){
			add(dp1[i][j], 1LL * dp1[i - 1][j + 1] * (j + 1) % mod);
			if(j > 1)	add(dp1[i][j], dp1[i - 1][j - 2]);
		}
	
	dp2[0][0] = 1;
	for(int i = 1; i <= 3 * n; ++i)
		for(int j = 0; j <= 2 * n; ++j){
			add(dp2[i][j], 1LL * dp2[i - 1][j + 1] * (j + 1) % mod);
			if(j > 0)	add(dp2[i][j], dp2[i - 1][j - 1]);
		}
	
	int ans = 0;
	for(int a = 0; a <= n; ++a)
		for(int b = 0; b <= n; ++b)
			if(a + b <= n){
				LL tmp = 1LL * newt[3 * n][3 * a] * dp1[3 * a][0] % mod;
				tmp = tmp * newt[3 * n - 3 * a][2 * b] % mod * dp2[2 * b][0] % mod;
//				printf("%d %d -> %d\n", a, b, tmp);
				add(ans, tmp);
			}
	
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 330240
#include<stdio.h>
int main(void){
  long a,b,c,k;
  scanf("%ld%ld%ld%ld",&a,&b,&c,&k);
  if(k<=a)printf("%ld",k);
  else if(k<=a+b)printf("%ld",a);
  else if(k<=a+b+c)printf("%ld",2*a-k+b);
  else printf("%ld",a-c);
  return 0;
}

Measured memory_bytes: 1732
#include <bits/stdc++.h>
#include <unordered_map>
#include <queue>
#define MOD 1000000007
#define REP(i,st,num)for(int i=(st);i<(num);++i)
#define ll long long
const ll linf = 1LL << 60;
using namespace std;

struct Edge {
    int to, value;
};

int main() {
    ios::sync_with_stdio(false);
    int N,M,P,A,B,C;
    vector<pair<int, int> > mp[2501];
    cin>>N>>M>>P;
    REP(i,0,M){
        cin>>A>>B>>C;
        mp[A-1].push_back(make_pair(B-1, -(C-P)));
    }
    vector<ll> upper(2501, linf);
    int s = 0;
    bool updated;
    upper[0] = 0;

    REP(i,0,N) {
        REP(here,0,N) {
            if(upper[here]==linf)continue;
            REP(j,0,mp[here].size()){
                int there = mp[here][j].first;
                int cost = mp[here][j].second;
                upper[there]=min(upper[there],upper[here]+cost);
            }
        }
    }
    ll last = upper[N-1];
    REP(i,0,N){
        REP(here,0,N) {
            if(upper[here]==linf)continue;
            REP(j,0,mp[here].size()){
                int there = mp[here][j].first;
                int cost = mp[here][j].second;
                if(upper[there]>upper[here]+cost){
                    upper[there]=-linf;
                }
            }
        }
    }
    if (upper[N-1]==-linf)cout<<"-1";
    else cout << max(0LL,-upper[N-1]);

    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <queue>
#include <set>
#include <string>

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

using namespace std;
typedef long long ll;

int main() {
    int n; cin >> n;
    vector<ll> a(n);
    ll min = 1 << 30;
    int minus = 0;
    ll sum = 0;
    rep(i, n) {
        cin >> a[i];
        if(a[i] < 0)
            minus++;
        if(min > abs(a[i]))
            min = abs(a[i]);
        sum += abs(a[i]);
    }
    if(minus%2 == 0) {
        cout << sum << endl;
    } else {
        cout << sum - 2*min << endl;
    }
}


Measured memory_bytes: 1024
s = input()
l = len(s)
ans = 0
for i in range(2**(l-1)):
    e = ""
    for j in range(l):
        if ((i >> j) & 1):
            e += s[j] + "+"
        else:
            e += s[j]
    ans += eval(e)
print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}

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

  ll K ; cin >> K;
  vector<ll> A;

  ll l = 0, r = 0;
  ll a , b;
  rep(i,K){
    ll inp; cin >> inp;
    r+=inp;
    A.pb(inp);
  }
  r += 2;
  a = l; b = r;
  while(b-a>1){
    ll t = (a+b)/2;

    rep(i,K) {
      ll sub = t%A[i];
      t-=sub;
    }
    if(t<=2)a=((a+b)/2);
    else b=(a+b)/2;
  }
  ll M = a;

  a = l; b = r;
  while(b-a>1){
    ll t = (a+b)/2;

    rep(i,K) {
      ll sub = t%A[i];
      t-=sub;
    }
    if(t>=2)b=((a+b)/2);
    else a=(a+b)/2;  
  }
  ll m = b;

  if(m>M) cout <<"-1" << endl;
  else cout << m << " " << M << endl;
  //cout << fixed << setprecision(16) << ans << endl;
  return 0;
}


Measured memory_bytes: 1528
import collections
N = int(input())
A = list(map(int, input().split()))
A_count = collections.Counter(A)
# print(A_count)
ans = 0
even = []
# odd = []
for v in A_count.values():
    if v == 1 or v % 2 != 0:
        ans += 1
    else:
        even.append(v)
# even.sort()
m = len(even)
if m % 2 == 0:
    ans += m
else:
    ans += m-1

print(ans)
# odd.sort()


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

/* #include<cstdio>*/
int main(){
	int S, h, m, s;
	cin >> S;
	h = S / 3600;
	m = (S - h * 3600) / 60;
	s = S - h * 3600 - m * 60;

	cout << h << ":" << m << ":" << s << endl;

	return 0; 
}



Measured memory_bytes: 3096
# -*- coding: utf-8 -*-
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
write = sys.stdout.write
# template


def resolve():
    ofs = 6400
    h, w = map(int, readline().split())
    A = [list(map(int, readline().split())) for i in range(h)]
    B = [list(map(int, readline().split())) for i in range(h)]
    dp = [[0]*w for _ in range(h)]
    x = abs(A[0][0]-B[0][0])
    dp[0][0] |= ((1 << (ofs+x)) | (1 << (ofs-x)))

    from itertools import product
    for i, j in product(range(h), range(w)):
        x = abs(A[i][j]-B[i][j])
        t = 0
        if(i-1 >= 0):
            t |= dp[i-1][j]
        if(j-1 >= 0):
            t |= dp[i][j-1]
        dp[i][j] |= ((t << x) | (t >> x))

    for i, s in enumerate(bin(dp[-1][-1])[-ofs-1:]):
        if(s == '1'):
            write("%d\n" % i)
            return


if __name__ == "__main__":
    INF = float("inf")
    MOD = 10**9+7
    resolve()


Measured memory_bytes: 51548
#include <bits/stdc++.h>
using namespace std;
#define int long long
int n,mod=1e9+7;
vector<vector<int>> v,dp;

void dfs(int node,int par)
{
     int f=1;
     int x=1,y=1;
     for(auto i:v[node])
     {
          if(i!=par){
          f=0;
          dfs(i,node);
          x=(x*(dp[i][0]+dp[i][1]))%mod;
          y=(y*(dp[node][1]+dp[i][0]))%mod;
          }
     }
     if(f==0){
     dp[node][0]=x;
     dp[node][1]=y;
     }
     if(f){              //If the node is leaf node
     dp[node][0]++;
     dp[node][1]++;
     }
     //cout<<node<<" "<<dp[node][0]<<" "<<dp[node][1]<<endl;
}

signed main() {
 ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 cin>>n;
 int x,y;
 v=vector<vector<int>>(n+1);
 dp=vector<vector<int>>(n+1,vector<int>(2));
 for(int i=1;i<n;i++)
 {
      cin>>x>>y;
      v[x].push_back(y);
      v[y].push_back(x);
 }
 dfs(1,-1);
 cout<<(dp[1][0]+dp[1][1])%mod;

}

Measured memory_bytes: 18176
#!/usr/bin/env python3
import sys
import collections

sys.setrecursionlimit(10 ** 8)
ni = lambda: int(sys.stdin.readline())
nm = lambda: map(int, sys.stdin.readline().split())
nl = lambda: list(nm())
ns = lambda: sys.stdin.readline().rstrip()

N, M = nm()
adj = [[] for _ in range(N)]
for i in range(M):
    a, b = nm()
    a -= 1
    b -= 1
    adj[a].append(b)
    adj[b].append(a)


def solve():
    q = collections.deque([(0, 0, -1)])
    visited = [False] * N
    prev = [None] * N
    while q:
        l, node, pnode = q.popleft()
        if visited[node]:
            continue
        visited[node] = True
        prev[node] = pnode
        for nxt in adj[node]:
            if not visited[nxt]:
                q.append((l + 1, nxt, node))
    print("Yes")
    for i in range(1, N):
        print(prev[i] + 1)


if __name__ == "__main__":
    solve()


Measured memory_bytes: 106980
#include <iostream>
#include <vector>
#include <unordered_map>
#include <map>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <deque>
#include <cmath>
#include <stack>
#include <queue>
#include <string>
#include <iomanip>
#include <cstring>
#include <climits>
#include <cstdio> 

#define nl '\n'

using namespace std;

long long k, n, a, d;

int main(){

    cin >> k >> n;
    vector<long long> v;

    vector<long long> g;

    for(long long i = 0; i < n; i++){
        cin >> a;
        v.push_back(a);
    }

    for(long long i = 0; i < v.size()-1; i++){
        g.push_back(v[i+1]-v[i]);
    }

    g.push_back((k -v[v.size()-1]) + v[0]);

    sort(g.begin(), g.end());

    for(long long i = 0; i < n-1; i++){
        d += g[i];
    }

    cout << d;


}
 
//g++ -std=c++14 comp.cpp -o c && c.exe
//g++ -std=c++14 comp.cpp -o c; ./c.exe
//g++ -std=c++14 comp.cpp && ./a.out


//Surely this is going to AC

Measured memory_bytes: 4848
#include <bits/stdc++.h>
#define all(a) (a).begin(),(a).end()
#define rep(i,n) for(ll (i)=0,(i##_len)=(n);(i)<(i##_len);(i)++)
#define rep2(i,a,b) for(ll (i)=(a),(i##_len)=(b);(i)<=(i##_len);(i++))
#define rrep(i,n) ll(i)=(n);ll now=-1;while((i)--&&(now++||1))
#define Yes(n) cout<<((n)?Yes:No)<<"\n"
#define vll vector<ll>
#define pb push_back

using namespace std;
using ll = long long;

static inline void ignore_ret(int x) {}
template<class T> bool chmax(T&a,const T&b){if(a<b){a=b;return true;}return false;}
template<class T> bool chmin(T&a,const T&b){if(a>b){a=b;return true;}return false;}
template<class T> T gcd_vec(vector<T>v){T r=v.at(0);for(T i=1;i<v.size();i++)r=gcd(r,v.at(i));return r;}
template<class T> T lcm_vec(vector<T>v){T r=v.at(0);for(T i=1;i<v.size();i++)r=lcm(r,v.at(i));return r;}
template<class T> T factorial(T n){if(n==0)return 1;T r=1;for(T i=2;i<=n;i++)r*=i;return r;}
template<class T> T nCr(T n,T k){return factorial<T>(n)/(factorial<T>(k)*factorial<T>(n-k));}
template<class T> T dot_product(vector<T>u,vector<T>v){T r=0;for(T i=0;i<u.size();i++)r+=u.at(i)*v.at(i);return r;}
template<class T> T sum(vector<T>v){return reduce(all(v),0LL);}

// Template ends here
void solve(ll N, vector<ll> A){
    vll B = A;
    sort(all(B));
    rep(i, N) {
        if (A.at(i) == B.at(N - 1)) cout << B.at(N - 2) << "\n";
        else cout  << B.at(N - 1) << "\n";
    }
}

int main() {
    ll N;
    ignore_ret(scanf("%lld",&N));
    vector<ll> A(N);
    for(int i = 0 ; i < N ; i++){
        ignore_ret(scanf("%lld",&A[i]));
    }
    solve(N, move(A));
    return 0;
}

Measured memory_bytes: 4736
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  Int n;
  cin>>n;
  vector<Int> a(n);
  for(Int i=0;i<n;i++) cin>>a[i];

  const Int INF = 1e17;
  Int ans=INF;
  
  for(Int uku=0;uku<2;uku++){
    vector<Int> s(n+1,0);
    for(Int i=0;i<n;i++) s[i+1]=s[i]+a[i];
    
    vector<Int> dp1(n+1,INF),dp2(n+1,INF),dp3(n+1,INF);
    for(Int i=0;i<n;i++){
      chmin(dp1[i+1],s[i]+(a[i]&1));
      chmin(dp1[i+1],dp1[i]+(a[i]?(a[i]&1):2));
      
      chmin(dp2[i],s[i]);
      chmin(dp2[i+1],dp1[i]+(~a[i]&1));
      chmin(dp2[i+1],dp2[i]+(~a[i]&1));
      
      chmin(dp3[i+1],dp2[i]+(a[i]?(a[i]&1):2));
      chmin(dp3[i+1],dp3[i]+(a[i]?(a[i]&1):2));
      
      chmin(ans,dp1[i]+(s[n]-s[i]));
      chmin(ans,dp2[i]+(s[n]-s[i]));
      chmin(ans,dp3[i]+(s[n]-s[i]));
    }
    //cout<<dp2[1]<<endl;
    chmin(ans,s[n]);
    chmin(ans,dp1[n]);
    chmin(ans,dp2[n]);
    chmin(ans,dp3[n]);
    
    reverse(a.begin(),a.end());
  }
  cout<<ans<<endl;
  return 0;
}


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

using namespace std;

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

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;
const ll MAX = 30000;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    if (N == 3) {
        cout << "2 5 63" << endl;
        return 0;
    }
    vector<ll> v;
    v.push_back(2);
    v.push_back(4);
    {
        ll x = 3;
        while (v.size() + 2 <= N && x + 6 <= MAX) {
            v.push_back(x);
            v.push_back(x + 6);
            x += 12;
        }
    }
    {
        ll x = 8;
        while (v.size() + 2 <= N && x + 2 <= MAX) {
            v.push_back(x);
            v.push_back(x + 2);
            x += 6;
        }
    }
    {
        ll x = 6;
        while (v.size() < N) {
            v.push_back(x);
            x += 6;
        }
    }
    sort(v.begin(), v.end());
    REP(i, v.size()) {
        cout << v[i] << " ";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define fastIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;

int const N = 3005;
int n ;
double P[N] , DP[N][N];

double calc(int idx , int heads){
    if(heads == (n+1)/2)return 1;
    if(idx > n)return 0;
    if(DP[idx][heads] > -0.9)return DP[idx][heads];
    double hPath = P[idx] * calc(idx+1,heads+1);
    double tPath = (1-P[idx]) * calc(idx+1,heads);
    return DP[idx][heads] = hPath + tPath;

}

int main(){
    fastIO;
    cin>>n;
    memset(DP,-1,sizeof DP);
    for(int i = 1 ; i<=n ; i++){
        cin>>P[i];
    }
    cout<<fixed<<setprecision(10)<<calc(1,0);
}


Measured memory_bytes: 74548
#include<stdio.h>
#define MAX 100000
#define INF 1000000000
 
typedef struct card{
  char s;
  int v;
}Card;

void M(Card A[],int l,int m,int r);
void Ms(Card A[],int l,int r);
int P(Card A[],int p,int r);
void Qs(Card A[],int p,int r);
 
 
int main(){
  int i,j,n,v,stable = 0;
  Card A[MAX],B[MAX];
  char s;
 
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf(" %c%d",&s,&v);
    A[i].s = B[i].s = s;
    A[i].v = B[i].v = v;
  }
 
  Ms(A,0,n);
  Qs(B,0,n-1);
 
  for(i=0;i<n;i++){
    if(A[i].s != B[i].s) stable = 1;
  }
 
  if(stable == 0)printf("Stable\n");
  else printf("Not stable\n");
 
  for(i=0;i<n;i++){
    printf("%c %d\n",B[i].s,B[i].v);
  }
  return 0;
}


void M(Card A[],int l,int m,int r){
  Card R[MAX/2+2],L[MAX/2+2];
  int i,j,k;
  int n1,n2;
  n1 = m - l;
  n2 = r - m;
 
  for(i=0;i<n1;i++){
    L[i] = A[l+i];
  }
  for(i=0;i<n2;i++){
    R[i] = A[m+i];
  }
  L[n1].v = INF;
  R[n2].v = INF;
  i = 0;
  j = 0;
 
  for(k=l;k<r;k++){
    if(L[i].v <= R[j].v){
      A[k] = L[i++];
    }else{
      A[k] = R[j++];
    }
  }
}



void Ms(Card A[],int l,int r){
  int m;
  if(l + 1 < r){
    m = (l+r)/2;
    Ms(A,l,m);
    Ms(A,m,r);
    M(A,l,m,r);
  }
}


int P(Card A[],int p,int r){
  Card tmp,x;
  int i,j;
 
  x = A[r];
  i = p - 1;
  for(j=p;j<r;j++){
    if(A[j].v <= x.v){
      i++;
      tmp = A[i];
      A[i] = A[j];
      A[j] = tmp;
    }
  }
  tmp = A[i+1];
  A[i+1] = A[r];
  A[r] = tmp;
 
  return i + 1;
}

void Qs(Card A[],int p,int r){
  int q;
  if(p<r){
    q = P(A,p,r);
    Qs(A,p,q-1);
    Qs(A,q+1,r);
  }
}



Measured memory_bytes: 4076
#!/usr/bin/env python3
import sys


def solve(N: int, K: int, A: "List[int]"):
    ret = 0
    for i in range(1, N):
        if K * i - (i - 1) >= N:
            ret = i
            break
    print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    A = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, K, A)

if __name__ == '__main__':
    main()


Measured memory_bytes: 14452
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int main(){
  ll i,j,n,l[2010];
  cin >> n;
  for(i=0;i<n;i++){
    cin >> l[i];
  }
  sort(l,l+n);
  ll ans=0;
  for(i=0;i<n;i++){
    for(j=i+1;j<n;j++){
      ll x=abs(l[i]-l[j]),min=-1,max=n;
      while(abs(min-max)>1){
        ll mid=(min+max)/2;
        if(l[mid]>x){
          max=mid;
        }
        else{
          min=mid;
        }
      }
      if(max==n){
        continue;
      }
      ll y=max;
      x=l[i]+l[j],min=-1,max=n;
      while(abs(min-max)>1){
        ll mid=(min+max)/2;
        if(l[mid]<x){
          min=mid;
        }
        else{
          max=mid;
        }
      }
      ll z=min,res=0;
      if(z==-1){
        continue;
      }
      if(i>=y && i<=z){
        res++;
      }
      if(j>=y && j<=z){
        res++;
      }
      if(z-y-res+1>0){
        ans+=(z-y-res+1);
      }
    }
  }
  cout << ans/3 << endl;
}

Measured memory_bytes: 3664
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<iomanip>
#include<sstream>
#include<map>
#include<set>
#include<cmath>
using namespace std;
#define rep(i,n) for(int i = 0;i < n;i++)
#define req(i,n) for(int i = 1;i <=n;i++)
#define rrep(i,n) for(int i = n -1;i >= 0;i--)
#define ALL(a) a.begin(),a.end()
typedef long long ll;
typedef long double ld;
const ll MOD =  1000000007;
const ll INF =  1LL << 60;
int n, m, x, y;ll z = 0, w, h, sum = 0, ans = 0;
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T & val) {
    std::fill((T*)array, (T*)(array + N), val);
}
int main(void) {
	cin >> n >> m; vector<int> a(100010, 0);
	rep(i, n) {
		cin >> x >> y >> z;
		a[x - 1]++; a[y]--;
	}
	rep(i, 100009) {
		a[i + 1] += a[i];
	}x = 0;
	rep(i, 100010) {
		x = max(x, a[i]);
	}cout << min(x,m) << endl;
}

Measured memory_bytes: 640
#include <algorithm>
#include <bitset>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define MOD (1000000007l)
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)

using namespace std;

ll foo[100] = { 0 };
ll bar[100] = { 0 };


ll b[100] = { 0 };

void input(ll num, ll keta) {
  if (keta == 100) return;
  if (num & 1) foo[keta] ++ ;
  else bar[keta] ++;
  input(num / 2, keta + 1);
}

void calc(ll num, ll keta) {
  if (keta == 100) return;
  if (num & 1) b[keta] += bar[keta];
  else b[keta] += foo[keta];
  calc(num / 2, keta + 1);
}

ll make_ans(ll keta) {
  if (keta == 100) return 0;
  ll tmp = make_ans(keta + 1);
  tmp *= 2;
  tmp += b[keta];
  tmp %= MOD;
  return tmp;
}

void solve() {
  ll N;
  cin >> N;
  vector<ll> A(N);
  rep (i, N) cin >> A[i];
  for (ll i = N - 1; i >= 0; i--) {
    calc(A[i], 0);
    input(A[i], 0);
  }
  cout << make_ans(0) << endl;
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.precision(12);
  cout << fixed;
  solve();
  return 0;
}


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

#define fastio 			ios::sync_with_stdio(0);	cin.tie(0); cout.tie(0);  cout<<fixed;  cout<<setprecision(12);
#define randomINT 		mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define	newl 			cout<<"\n"
#define DISP(as)		for(auto it : as) cout<<it<<" ";newl;
#define all(x)         	(x).begin(),(x).end()
#define mset(x,val)    	memset(x,val,sizeof(x))
#define newl           	cout<<"\n"
#define pb             	push_back
#define mp             	make_pair
#define f 				first
#define s 				second
#define dline          cerr<<"///REACHED///\n";
#define deb1(x)        cerr<<#x<<" = "<<x<<'\n';
#define deb2(x,y)      cerr<<'['<<#x<<','<<#y<<"] = "<<'['<<x<<','<<y<<']'<<'\n';
#define deb3(x,y,z)    cerr<<'['<<#x<<','<<#y<<','<<#z<<"] = "<<'['<<x<<','<<y<<','<<z<<']'<<'\n';

typedef long long 				ll;
typedef long double 			ld;
typedef vector<ll> 				vll;
typedef pair<ll , ll> 			pll;
typedef pair<ld, ld> 			pld;
typedef unordered_map<ll, ll> 	um;
typedef vector<pll> 			vpll;

const ll 	MAX5 	= 	1e+5 + 7;
const ll 	MAX7 	= 	1e+7 + 7;
const ll 	MAXN 	= 	MAX7;
const ll   	INF   	=  	0x7f7f7f7f7f7f7f7f;
const int  	INFi 	=  	0x7f7f7f7f;
const ll 	MOD		=  	1000000007;

int dx4[] = {0, 1, 0, -1}, dy4[] = {1, 0, -1, 0};

// <------------- Declare Variables Here ------------> //

ll T = 1;
ll n, q, x, k;
string s, t;
// <------------- Implement Functions Here ----------> //

string base() {
	string f;
	while(n ) {
		ll rem = n%26;
		if(rem) {
			f += (rem - 1) + 'a';
			n/=26;
		}
		else {
			f += 'z';
			n/=26;
			n-=1;
		}
	}
	reverse(all(f));
	return f;
}

// <------------- Start of main() -------------------> //

void MAIN() {
	cin>>n;
	string f = base();
	cout<<f;
}	


int main() {
	fastio; randomINT;
	//cin >> T;
	while (T--) {
		MAIN();
	}
	return 0;
}


Measured memory_bytes: 3652
use std::cmp;
use std::collections::HashMap;
use std::collections::VecDeque;
use std::io::Read;
use std::usize::MAX;

macro_rules! input {(source = $s:expr, $($r:tt)*) => {let mut iter = $s.split_whitespace();let mut next = || { iter.next().unwrap() };input_inner!{next, $($r)*}};($($r:tt)*) => {let stdin = std::io::stdin();let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));let mut next = move || -> String{bytes.by_ref().map(|r|r.unwrap() as char).skip_while(|c|c.is_whitespace()).take_while(|c|!c.is_whitespace()).collect()};input_inner!{next, $($r)*}};}
macro_rules! input_inner {($next:expr) => {};($next:expr, ) => {};($next:expr, $var:ident : $t:tt $($r:tt)*) => {let $var = read_value!($next, $t);input_inner!{$next $($r)*}};}
macro_rules! read_value {($next:expr, ( $($t:tt),* )) => {( $(read_value!($next, $t)),* )};($next:expr, [ $t:tt ; $len:expr ]) => {(0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()};($next:expr, chars) => {read_value!($next, String).chars().collect::<Vec<char>>()};($next:expr, usize1) => {read_value!($next, usize) - 1};($next:expr, [ $t:tt ]) => {{let len = read_value!($next, usize);(0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()}};($next:expr, $t:ty) => {$next().parse::<$t>().expect("Parse error")};}

fn solve() {
    input! {
        n: u64,
        m: u64
    }

    let mut ans = 0;

    println!("{}", (n * (n - 1) + m * (m - 1)) / 2);
}

fn main() {
    let thd = std::thread::Builder::new().stack_size(104_857_600);
    thd.spawn(|| solve()).unwrap().join().unwrap();

    /*
    // 入力を一括で読み込む場合
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut input = buf.split_whitespace();

    // inputに対しnext()で読み込んでいく
    let q: usize = input.next().unwrap().parse().unwrap();
    */
}

const LARGE_PRIME: u64 = 1_000_000_007;

// @〜でsnippet


Measured memory_bytes: 8572
N = int(input())
H = list(map(int, input().split()))
I = [0] * N

count = 0
updated = True

while updated:
  tmp = -9999
  updated = False
  
  for i in range(N):
    if I[i] != H[i]:
      if tmp + 1 != i:
        count += 1
      I[i] += 1
      updated = True
      tmp = i

print(count)

Measured memory_bytes: 3064
require'rational'
a, b, c, d  = gets.split(" ").map(&:to_i)
# 全部
sum = b - (a - 1)
# cで割れるものの数
c_sum = b/c - (a - 1)/c
# dで割れるものの数
d_sum = b/d - (a - 1)/d
# cとdで割れるものの数（ダブり）
cd_sum = b/c.lcm(d) - (a - 1)/c.lcm(d)

puts sum - (c_sum + d_sum) + cd_sum

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

int main() {
  int N;
  string S;
  cin >> N >> S;
  int max = 0;
  for (int i=0; i<N; i++) { //i番目までXに入っている
	int cnt = 0;
	for (char z='a'; z<='z'; z++) {
	  bool x=false;
	  bool y=false;
	  for (int j=0; j<i; j++) { 
			if(S.at(j) == z) x = true;
		}
	  for (int j=i; j<N; j++) {
			if(S.at(j) == z) y = true;
		}	  
	  if (x && y) cnt++;
	}
	if (cnt > max) max = cnt;
  }
  cout << max;
}

Measured memory_bytes: 256
#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 (x + a +1 <= b){
printf("dangerous\n");
}else if(a < b && b - a <= x) { 
printf("safe\n");
}
    return 0;

}


Measured memory_bytes: 128
#include<iostream>
int main() {
	int n,a,num,max,min;
	long total=0;
	a=1;
	max=-1000001;
	min=1000001;
	std::cin >> n;
	while (a<=n){
		std::cin >> num;
		if(max<num){
			max=num;
		}
		if(min>num){
			min=num;
		}
		total=total+num;
		a++;
	}
	if (a>n){
		std::cout << min << " " << max << " " << total << std::endl;
	}
	return 0;
}

Measured memory_bytes: 3100
X = int(input())


def isPrime(x):
    i = 1
    while i ** 2 < x:
        i += 1
    i -= 1
    for j in range(2, i + 1):
        if x % j == 0:
            return False
    return True


while True:
    if isPrime(X):
        print(X)
        break
    X += 1


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

int main(){
  int N;
  cin >> N;
  vector<int> a(N);
  for(int i=0;i<N;i++){
    cin >> a.at(i);
  }
  int tmp=a.at(0);
  int count=1;
  if(tmp==2){
    cout << count << endl;
    return 0;
  }
  while(1){
    if(a.at(tmp-1)==2){
      count++;
      cout << count << endl;
      break;
    }
    if(a.at(tmp-1)==1){
      cout << -1 << endl;
      break;
    }
    tmp=a.at(tmp-1);
    count++;
    if(count>10*10*10*10*10){
      cout << -1 << endl;
      break;
    }
  }
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for(int i = (n) - 1; (i) >= 0; --i)
#define SZ(n) (int)(n).size()
#define ALL(n) (n).begin(), (n).end()
#define MOD LL(1e9 + 7)
#define INF 1000000
using namespace std;
using LL = long long;


int main() {
	string x;
	while (cin >> x) {
		if (x[0] == '0') break;
		int sum = 0;
		for (auto & e : x) {
			sum += e - '0';
		}
		cout << sum << endl;
	}
	return 0;
}



Measured memory_bytes: 3136
#!/usr/bin/env python
# coding: utf-8

# In[43]:


mylist = list(map(int, input().split()))


# In[45]:


if abs(mylist[0]-mylist[1]) > 10**18:
    print("Unfair")
else:
    if mylist[-1]%2 == 0:
        print(mylist[0]-mylist[1])
    else:
        print(-mylist[0]+mylist[1])


# In[ ]:






Measured memory_bytes: 3316
import java.util.*;
import java.math.BigInteger;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    BigInteger moder = new BigInteger("1000000007");
    BigInteger all = BigInteger.TEN;
    all = all.pow(n);
    BigInteger toNine = new BigInteger("9");
    toNine = toNine.pow(n);
    BigInteger toEight = new BigInteger("8");
    toEight = toEight.pow(n);
    BigInteger ans = new BigInteger("0");
    ans = ans.add(all);
    ans = ans.subtract(toNine);
    ans = ans.subtract(toNine);
    ans = ans.add(toEight);
    ans = ans.mod(moder);
    System.out.println(ans);

  }
}


Measured memory_bytes: 89132
#include <iostream>
using std::cout;
using std::endl;
using std::cin;

int selection_sort(int a[],int n){
  int mini,c=0;
  for(int i=0;i<n;i++){
    mini = i;
    for(int j=i;j<n;j++){
      if(a[j]<a[mini]){
        mini = j;
      }
    }
    if(mini!=i)c++,std::swap(a[i],a[mini]);
  }
  return c;
}

int main(){
  int n,a[100];
  cin >> n;
  for(int i=0;i<n;i++){
    cin >> a[i];
  }
  int change = selection_sort(a,n);
  for(int i=0;i<n-1;i++){
    cout << a[i] << ' ';
  }
  cout << a[n-1] << endl;
  cout << change << endl;
}

Measured memory_bytes: 1160
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <functional>
#include "math.h"
#include <set>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define VI vector<int>
#define debug(x) cout<<#x<<": "<<x<<endl
#define DEBUG(x) cout<<#x<<": "<<x<<endl
int N;
vector <int > t,x,y;





int main()
{

	cin >> N;

	t.resize(N+1);
	x.resize(N+1);
	y.resize(N+1);

	FOR(i,1,N+1){
		cin >> t[i];
		cin >> x[i];
		cin >> y[i];
	}

	t[0] = 0;
	x[0] = 0;
	y[0] = 0;

	FOR(i,1,N+1){
		int l = abs(x[i]-x[i-1])+abs(y[i]-y[i-1]);
		if(t[i]-t[i-1]<l){
			cout << "No" << endl;
			return 0;
		}else{
			if((t[i]-t[i-1]-l)%2==1){
				cout << "No" << endl;
				return 0;
			}
		}
	}

	cout << "Yes" << endl;

}







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

using namespace std;

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

    int XOR = 0;
    vector<int> v(n);
    for (int i = 0; i < n; i++)cin >> v[i], XOR ^= v[i];
    sort(v.begin(), v.end());

    if (n % 3 == 0) {
        cout << (v[n / 3 * 0] == v[n / 3 * 1 - 1] &&
                 v[n / 3 * 1] == v[n / 3 * 2 - 1] &&
                 v[n / 3 * 2] == v[n / 3 * 3 - 1] &&
                 XOR == 0 ? "Yes" : "No") << endl;
    } else {
        cout << (v[0] == v[n - 1] ? "Yes" : "No") << endl;
    }
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>

using namespace std;

bool IsPrime[10010];
void PrimeCalc()
{
	for(int i = 0; i < 10010; ++i)
	{
		IsPrime[i] = true;
	}
	IsPrime[0] = IsPrime[1] = false;
	for(int i = 2; i < 10010; ++i)
	{
		if(IsPrime[i])
		{
			for(int j = 2 * i; j < 10010; j += i)
			{
				IsPrime[j] = false;
			}
		}
	}
}

void solve()
{
	PrimeCalc();
	int N;
	while(cin >> N)
	{
		int count = 0;
		for(int i = 1; i <= N; ++i)
		{
			if(IsPrime[i] == true && IsPrime[N - i + 1] == true)
			{
				++count;
			}
		}
		cout << count << endl;
	}
}

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

Measured memory_bytes: 0
#include <stdio.h>

int main(){
    int book[30] = {0};
    char ch;
    while((ch = getchar()) != '\n'){
        book[ch - 'a']++;
    }
    int flag = 1;
    for(int i=0; i<26; i++){
        if(book[i] >= 2){
            printf("no");
            flag = 0;
            break;
        }
    }
    if(flag) printf("yes");
    return 0;
}

Measured memory_bytes: 128
# B - Ordinary Number

n = int(input())
p = list(int(x) for x in input().split())

ans = 0
for i in range(1, n-1):
    if (p[i-1]<p[i] and p[i]<p[i+1]) or (p[i+1]<p[i] and p[i]<p[i-1]):
        ans += 1

print(ans)

Measured memory_bytes: 3060