akhauriyash/Code-Regression huggingface dataset:
package main

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

func main() {
	sc = initScanner(os.Stdin)
	s := scanString(sc)
	fmt.Println(resolve(s))
}

func resolve(s string) int {
	s1 := strings.Split(s, "")
	s2 := strings.Split(s, "")

	var prev string

	cnt0, cnt1 := 0, 0
	// 010101...
	for i:=0;i< len(s);i++ {
		if i==0 && s1[0] != "0" {
			cnt0++
			s1[0] = "0"
		}

		if i !=0 && prev == s1[i] {
			cnt0++

			if prev == "0" {
				s1[i] = "1"
			} else {
				s1[i] = "0"
			}
		}

		prev = s1[i]
	}

	for i:=0;i< len(s);i++ {
		if i==0 && s2[0] != "1" {
			cnt1++
			s2[0] = "1"
		}

		if i !=0 && prev == s2[i] {
			cnt1++

			if prev == "0" {
				s2[i] = "1"
			} else {
				s2[i] = "0"
			}
		}

		prev = s2[i]
	}

	if cnt0 < cnt1 {
		return cnt0
	} else {
		return cnt1
	}
}

// --------------- BASE DEFINITIONS ---------------

const (
	initialBufSize = 100000
	maxBufSize     = 1000000
)

var sc *bufio.Scanner

func initScanner(r io.Reader) *bufio.Scanner {
	buf := make([]byte, initialBufSize)

	sc := bufio.NewScanner(r)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords)
	return sc
}

func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}

func scanIntSlice(sc *bufio.Scanner, n int) []int {
	is := make([]int, n)
	for i := 0; i < n; i++ {
		is[i] = scanInt(sc)
	}

	return is
}

func scanString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

func scanStringSlice(sc *bufio.Scanner, n int) []string {
	ss := make([]string, n)
	for i := 0; i < n; i++ {
		sc.Scan()
		ss[i] = sc.Text()
	}

	return ss
}


Measured memory_bytes: 5324
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
typedef long long ll;
typedef unsigned long long ull;
typedef double db;


int main()
{
string s,t;
cin >> s >> t;
int a,b;
cin >>a >> b;
string now;
cin >> now;
if (now==s) cout << a-1 <<" " << b; else
    cout << a << " " << b-1;



}


Measured memory_bytes: 256
n,wmax = map(int,input().split())
w = [0]*n
v = [0]*n
for i in range(n):
    w[i],v[i] = map(int,input().split())

dp = [0]*(wmax+1)
for weight,value in zip(w,v):
    for i in reversed(range(weight,wmax+1)):
        dp[i] = max(dp[i],dp[i-weight]+value)

print(max(dp))

Measured memory_bytes: 41708
from collections import defaultdict,deque
import sys
finput=lambda: sys.stdin.readline().strip()

def main():
  n=int(finput())
  edges=[tuple(map(int,finput().split())) for _ in range(n-1)]
  q,k=map(int,finput().split())
  xy=[tuple(map(int,finput().split())) for _ in range(q)]
  
  stack=[-1]*(n+1)
  stack[k]=0
  ed=defaultdict(list)
  wt=defaultdict(int)
  for e in edges:
    ed[e[0]].append(e[1])
    ed[e[1]].append(e[0])
    wt[(e[0],e[1])]=e[2]
    wt[(e[1],e[0])]=e[2]
  ce=deque([(k,x) for x in ed[k]])
  ne=deque()
  while True:
    while ce:
      e=ce.pop()
      stack[e[1]]=stack[e[0]]+wt[e]
      for v in ed[e[1]]:
        if stack[v]<0:
          ne.append((e[1],v))
    if not ne:
      break
    ce.extend(ne)
    ne.clear()
  
  for que in xy:
    print(stack[que[0]]+stack[que[1]])

if __name__=='__main__':
    main()


Measured memory_bytes: 83260
#pragma GCC optimize("Ofast")  
#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
using namespace std;
#define IO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define int long long 
#define endl "\n"
#define all(x) (x).begin(),(x).end()
const int MOD = 1e9+7;
const int mxN = 2e5+3;

void solve(){
	int a, b, c;
	cin >> a >> b >> c;
	int k;
	cin >> k;
	int cnt = 0;
	while(b <= a){
		b *= 2;
		cnt++;
	}
	while(c <= b){
		c *= 2;
		cnt++;
	}
	if(cnt > k)cout << "No" << endl;
	else cout << "Yes" << endl;
}

int32_t main(){
	IO;
	
	int nT = 1;
	//cin >> nT;
	for(int i = 1; i <= nT; ++i)
		solve();
	return 0;
}


Measured memory_bytes: 3636
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-15
typedef long long ll;
using namespace std;
typedef pair<int,int> pint;
typedef vector<int> vint;
int INF=2e+9+1;
int main(){
	char S[300001];
	int N;
	int miginum[300001]={0};
	scan(N);
	scan(S);
	rep1(i,N){
		miginum[i]=miginum[i-1]+((S[i-1]=='E')? 1:0);
	}
	int changemin=INF;
	rep1(i,N){
		changemin=min(changemin,(i-1)-miginum[i-1]+(miginum[N]-miginum[i]));
	}
	prin(changemin);
	return 0;
}


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

int main() {
  int a;
  cin >> a;
  if(a<1000){
    cout << 1000-a << endl;
  }
  else if(a%1000==0){
    cout << 0 << endl;
  }
  else{
  	cout << 1000-(a%1000) << endl;
  }
}


Measured memory_bytes: 3592
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <deque>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <tuple>
#include <numeric>
#include <string>
#include <bitset>
#include <functional>

using ld = long double;
using vld = std::vector<ld>;
using vvld = std::vector<vld>;
using vvvld = std::vector<vvld>;
using ll = long long;
using vll = std::vector<ll>;
using vvll = std::vector<vll>;
using vvvll = std::vector<vvll>;
using pll = std::pair<ll, ll>;
using vpll = std::vector<pll>;
using str = std::string;
using vstr = std::vector<str>;

template<typename T> bool chmin(T a, T &b) { return a < b ? b = a, true : false; }
template<typename T> bool chmax(T a, T &b) { return a > b ? b = a, true : false; }

constexpr ld PI = 3.141592653589793L;
constexpr ld EPS = std::numeric_limits<ld>::epsilon();

ll gcd(ll n, ll m) { return m ? gcd(m, n % m) : n; }
ll lcm(ll n, ll m) { return n / gcd(n, m) * m; }
bool is_prime(ll n) {
    if (n == 1) return false;
    for (ll i = 2; i * i <= n; i++)
        if (n % i == 0) return false;
    return true;
}
ll rpow(ll x, ll n) {
    if (n == 0) return 1;
    ll k = 1;
    for (; n > 1; n /= 2) {
        if (n & 1) k *= x;
        x *= x;
    }
    return k * x;
}
ll modpow(ll x, ll n, ll mod) {
    if (n == 0) return 1;
    ll k = 1;
    for (; n > 1; n /= 2) {
        if (n & 1) (k *= x) %= mod;
        (x *= x) %= mod;
    }
    return k * x % mod;
}
ll modcomb(ll n, ll r, ll mod) {
    if (r < 0 || n < r) return 0;
    chmin(n - r, r);
    ll mul = 1, div = 1;
    for (ll i = 0; i < r; i++) {
        (mul *= n - i) %= mod;
        (div *= i + 1) %= mod;
    }
    return mul * modpow(div, mod - 2, mod) % mod;
}

/*------------------------------------------------------------------------*/

void solve();

int main() {
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    std::cout << std::setprecision(15);

    solve();
}
void solve() {
    ll n; str s;
    std::cin >> n >> s;

    std::map<char, std::set<ll>> map;
    for (ll i = 0; i < n; i++)
        map[s[i]].insert(i);

    ll ans = 0;
    for (ll i = 0; i < 1000; i++) {
        str t = std::to_string(i);
        t = str(3 - t.length(), '0') + t;

        ll p = -1;
        for (ll j = 0; j < 3; j++) {
            auto k = map[t[j]].upper_bound(p);
            if (k != map[t[j]].end()) p = *k;
            else { p = -1; break; }
        }

        ans += p != -1;
    }

    std::cout << ans << '\n';
}


Measured memory_bytes: 5100
import sys
sys.setrecursionlimit(10**9)

def mi(): return map(int,input().split())
def ii(): return int(input())
def isp(): return input().split()
def deb(text): print("-------\n{}\n-------".format(text))

INF=10**20
def main():
    N=ii()
    if N == 0:
        print(0)
        exit()

    ans = []
    while N != 1:
        # print(N)
        if N % 2 == 0:
            ans.append("0")
            q = N // (-2)
            N = q

        else:
            ans.append("1")
            q = (N-1) // (-2)
            N = q
        

    ans.append("1")
    print("".join(ans[::-1]))





if __name__ == "__main__":
    main()

Measured memory_bytes: 61940
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan=new Scanner(System.in);
        String str=scan.nextLine();
            int p=scan.nextInt();
            for(int i=0;i<p;i++) {
                String str1=scan.next();
                int a=scan.nextInt();
                int b=scan.nextInt();
                int c=str.length();
                String str3=str.substring(a,b+1);
                String str4="";
                if(str1.equals("replace")) {
                    String str2=scan.next();
                    String sa=str.substring(0, a);
                    String sb=str.substring(b+1,c);
                    str=sa+str2+sb;
                }else if(str1.equals("reverse")) {
                    for(int i1=str3.length()-1;i1>=0;i1--) {
                    str4=str4+str3.charAt(i1);
                    }
                    str=str.replaceAll(str3,str4);
                }else if(str1.equals("print")) {
                    System.out.println(str3);
                }
            }
            scan.close();
        }

}


Measured memory_bytes: 47796
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()
typedef long long ll;
#define downque(que)  priority_queue<ll> que;
#define upque(que) priority_queue<ll, vector<int>, greater<int>> que;


int main(){
   int q; cin>>q;
   
   bool b[100000+1];
   int kyo[100001]; //kyo[i]=i－１までの2017に似てる数を保存
   

   REP(i,100001){
      b[i]=true;
      kyo[i]=0;
   }
   b[0]=false;
   b[1]=false;

   for(int i=2;i<=317;i++){
      for(int j=2*i;j<=100001;j+=i){
         b[j]=false;

      }
    }//ふるいにかける

   REP(j,100000){
   int a=(j+1)/2;
   if(j%2==1&&b[j]&&b[a])kyo[j+1]=kyo[j]+1;
   else{kyo[j+1]=kyo[j];}
	
  }
  //累積わ

   for(int i=0;i<q;i++){
      int l,r; cin>>l>>r;
      cout<<kyo[r+1]-kyo[l]<<endl;
    
   }
  
}

Measured memory_bytes: 1152
#include <string>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//typedef pair<long long,long long> P;
//typedef pair<long long,P> P1;
//typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define se second
#define rep(i,x) for(long long i=0;i<x;i++)
#define repn(i,x) for(long long i=1;i<=x;i++)
#define rrep(i,x) for(long long i=x-1;i>=0;i--)
#define rrepn(i,x) for(long long i=x;i>1;i--)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())


#define ALL(v)  (v).begin(),(v).end()
//#define MAX(a,b) if(a>b)
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))




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

#define pr printf
#define re return
#define CASET int ___T, case_n = 1; scanf("%d ", &___T); while (___T-- > 0)



ll N,M;
ll sum;

int main(){

	ll wk;

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	std::cin >> N >> M;

	std::vector<long long> v(N);
	
	priority_queue<ll> que;
	
	for(long long i=0; i<N; i++){
		std::cin >> wk;
		que.push(wk);
	}
	
	
	for(long long i=0; i<M; i++){
		wk=que.top();
		que.pop();
		//pr("%lld\n",que.top());
		wk/=2;
		que.push(wk);
	}
	sum=0;
	while(!que.empty()){
		sum+=que.top();
		que.pop();
	}
	
	
	pr("%lld",sum);
	re 0;
}


Measured memory_bytes: 2168
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int a = s.nextInt();
		int b = s.nextInt();
		int c = s.nextInt();

		if(a < b && a < c){
			if(b < c){
				System.out.println(a + " " + b + " " + c);
			} else {
				System.out.println(a + " " + c + " " + b);
			}
		} else if(b < a && b < c){
			if(a < c){
				System.out.println(b + " " + a + " " + c);
			} else {
				System.out.println(b + " " + c + " " + a);
			}
		} else {
			if(a < b){
				System.out.println(c + " " + a + " " + b);
			} else {
				System.out.println(c + " " + b + " " + a);
			}
		}
	}

}

Measured memory_bytes: 26340
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<cmath>
#include<math.h>
#include<algorithm>
#include<string.h>
#include <iomanip>
#include <sstream>
using namespace std;

int main() {
  int N;
  int a,b,c;

  cin >> N;
  c = N%10;
  b = (N/10)%10;
  a = (N/100)%10;

  if(a < b){
    a++;
  }else if(a == b){
    if(a < c){
      a++;  
    }else{
    }
  }else if(a > b){
  }else{
  }
  
  cout << a*100 + a*10 + a << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
       
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main() {
  int H, W, N;
  cin >> H >> W >> N;

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

  vector<ll> ans(10, 0);

  vector<int> di = {0, -1, -2, 0, -1, -2, 0, -1, -2},
              dj = {0, 0, 0, -1, -1, -1, -2, -2, -2};

  auto count = [&](int i, int j, vector<ll> &ans) {
    for (int k = 0; k < (int)9; ++k) {
      int cnt = 0;
      for (int ii = 0; ii < (int)3; ++ii) for (int jj = 0; jj < (int)3; ++jj) {
        int r = i + di[k] + ii, c = j + dj[k] + jj;
        if (r < 0 || H <= r || c < 0 || W <= c) goto HOGE;
        if (B.find(r) != B.end() && B[r].find(c) != B[r].end()) cnt += B[r][c];
      }
      ans[cnt] += 1;
    HOGE:;
    }
  };

  for (auto &p : B) {
    int i = p.first;
    for (auto &q : p.second) {
      int j = q.first;
      count(i, j, ans);
    }
  }

  for (int i = 0; i < (int)10; ++i) if (i) ans[i] /= i;
  ans[0] = (H - 2LL) * (W - 2LL) - accumulate(ans.begin() + 1, ans.end(), 0LL);
  for (int i = 0; i < (int)10; ++i) cout << ans[i] << endl;

  return 0;
}


Measured memory_bytes: 14336
import java.util.HashSet;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        char[] s = sc.next().toCharArray();
        HashSet<Character> ss = new HashSet<>();
        for (int i = 0; i < s.length; i++) {
            ss.add(s[i]);
        }
        if(s.length == ss.size()) System.out.println("yes");
        else System.out.println("no");
    }
}

Measured memory_bytes: 35536
n=int(input())
a=list(map(int,input().split()))
d={}
for i in range(n):
    if a[i] not in d:d[a[i]]=1
    else: d[a[i]]+=1
ans=0
for x in d:
    if x<d[x]:ans+=d[x]-x
    elif x>d[x]:ans+=d[x]
print(ans)

Measured memory_bytes: 17780
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;


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

    int n, k, q;
    cin >> n >> k >> q;
    vector<int> A(n, -q);
    for (int i = 0; i < q; ++i) {
        int x;
        cin >> x;
        A[x - 1] += 1;
    }

    for (int i = 0; i < n; ++i) {
        A[i] += k;
        if (A[i] <= 0) {
            cout << "No\n";
        } else {
            cout << "Yes\n";
        }
    }

    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int b[105];
int main()
{
	for(int i=1;i<=4;i++)
	{
		char ch;
		scanf("%c",&ch);
		b[ch-'A']++;
	}
	for(int i=0;i<26;i++)
		if(b[i]!=0&&b[i]!=2)
		{
			puts("No");
			return 0;
		}
	puts("Yes");
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;

// 2013/03/16
public class Main{
	Scanner sc=new Scanner(System.in);

	int INF=1<<28;

	int n;

	void run(){
		n=sc.nextInt();
		solve();
	}

	void solve(){
		for(int i=0;; i++){
			String s=(n-i)+"";
			if(n-i>=0&&new StringBuilder(s).reverse().toString().equals(s)){
				println(s);
				return;
			}
			s=(n+i)+"";
			if(new StringBuilder(s).reverse().toString().equals(s)){
				println(s);
				return;
			}
		}
	}

	void println(String s){
		System.out.println(s);
	}

	void debug(Object... os){
		System.err.println(deepToString(os));
	}

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

}

Measured memory_bytes: 17384
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<set>
#include<bitset>
#include<map>

#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)

using namespace std;

typedef long long LL;
typedef double db;

int get(){
	char ch;
	while(ch=getchar(),(ch<'0'||ch>'9')&&ch!='-');
	if (ch=='-'){
		int s=0;
		while(ch=getchar(),ch>='0'&&ch<='9')s=s*10+ch-'0';
		return -s;
	}
	int s=ch-'0';
	while(ch=getchar(),ch>='0'&&ch<='9')s=s*10+ch-'0';
	return s;
}

const int N = 2005;

int a[N][N];
int n,m,q;
int p[3][N][N];

int getv(int t,int x1,int y1,int x2,int y2){
	return p[t][x2][y2]-p[t][x2][y1-1]-p[t][x1-1][y2]+p[t][x1-1][y1-1];
}

int main(){
	n=get();m=get();q=get();
	fo(i,1,n){
		char s[N];
		scanf("%s",s+1);
		fo(j,1,m)a[i][j]=s[j]-'0';
	}
	fo(i,1,n)
		fo(j,1,m){
			p[0][i][j]=a[i][j];
			p[1][i][j]=a[i][j]&a[i][j-1];
			p[2][i][j]=a[i][j]&a[i-1][j];
		}
	fo(t,0,2)
		fo(i,1,n)
			fo(j,1,m)p[t][i][j]=p[t][i][j]+p[t][i-1][j]+p[t][i][j-1]-p[t][i-1][j-1];
	fo(i,1,q){
		int x1=get(),y1=get(),x2=get(),y2=get();
		printf("%d\n",getv(0,x1,y1,x2,y2)-getv(1,x1,y1+1,x2,y2)-getv(2,x1+1,y1,x2,y2));
	}
	return 0;
}

Measured memory_bytes: 64640
// Copyright 2020 yaito3014
#include <bits/stdc++.h>

int main() {
  using namespace std;
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int N, M;
  cin >> N >> M;
  vector<int> A(N), B(M);
  for (auto& e : A) cin >> e, --e;
  for (auto& e : B) cin >> e, --e;
  sort(begin(A), end(A));
  sort(begin(B), end(B));
  if (unique(begin(A), end(A)) != end(A) ||
        unique(begin(B), end(B)) != end(B)) {
    cout << "0\n";
    return 0;
  }
  vector<int> count_A(N * M + 1, 0), count_B(N * M + 1, 0);
  for (const auto& e : A) ++count_A[e];
  for (const auto& e : B) ++count_B[e];
  partial_sum(crbegin(count_A), crend(count_A), rbegin(count_A));
  partial_sum(crbegin(count_B), crend(count_B), rbegin(count_B));
  constexpr int kMod = 1000000007;
  long long ans = 1;
  for (int i = N * M; i > 0;) {
  	--i;
  	int a = count_A[i] - count_A[i + 1];
  	int b = count_B[i] - count_B[i + 1];
  	if (a && !b) ans = ans * count_B[i] % kMod;
  	else if (!a && b) ans = ans * count_A[i] % kMod;
  	else if (!a && !b) {
  		int p = count_A[i] * count_B[i] - (N * M - i - 1);
  		ans = ans * p % kMod;
  	}
  }
  cout << ans << endl;
}


Measured memory_bytes: 8064
#include<iostream>
#include<map>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
#define MAX_N 101

string name[MAX_N];
int page[MAX_N];
map<string, int> m;
vector<int> vec;

int main(){
    int i = 0;
    while(cin >>name[i] >>page[i]){
        if(m.find(name[i]) == m.end()) m[name[i]] = 1;
        i++;
    }
    for(map<string, int>::iterator it = m.begin(); it != m.end(); it++){
        string searchName = (*it).first;
        cout <<searchName <<endl;
        for(int j = 0; j < i; j++){
            if(name[j] == searchName) vec.push_back(page[j]);
        }
        sort( vec.begin(), vec.end() );
        for(int i = 0; i < vec.size() - 1; i++){
            cout <<vec[i] <<" ";
        }
        cout <<vec[vec.size() - 1] <<endl;
        vec.clear();
    }
    return 0;
}

Measured memory_bytes: 0
# include<bits/stdc++.h>
using namespace std;
# define lowbit(x) ((x)&(-x))
# define pi acos(-1.0)
# define eps 1e-8
# define MOD 19260817
# define INF 1000000000
# define mem(a,b) memset(a,b,sizeof(a))
# define FOR(i,a,n) for(register int i=a; i<=n; ++i)
# define FDR(i,a,n) for(register int i=a; i>=n; --i)
# define AU(i,x)    for(auto i=x.begin(); i!=x.end(); ++i)
# define ALL(A) A.begin(),A.end()
# define bug puts("H");
# define lch p<<1,l,mid
# define rch p<<1|1,mid+1,r
# define mp make_pair
# define pb push_back
typedef pair<int,int> PII;
typedef vector<int> VI;
# pragma comment(linker, "/STACK:1024000000,1024000000")
typedef long long LL;
inline char nc(){
    static char buf[1000000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,1000000,stdin),p1==p2)?EOF:*p1++;
}
inline LL Scan(){
    long long res = 0;
    char ch = 0;
    while (ch < '0' || ch > '9')
        ch = getchar();
    while (ch >= '0' && ch <= '9')
    {
        res = res * 10 + ch - '0';
        ch = getchar();
    }
    return res;
}
int ps4[4][2]={0,1,0,-1,1,0,-1,0};
int ps8[8][2]={0,1,0,-1,1,0,-1,0,1,1,1,-1,-1,-1,-1,1};
inline int min(int a,int b,int c) {return min(a,min(b,c));}
inline int max(int a,int b,int c) {return max(a,max(b,c));}
inline int min(int a,int b,int c,int d){return min(min(a,b,c),d);}
inline int max(int a,int b,int c,int d){return max(max(a,b,c),d);}
//struct Edge{int p, next, w;}edge[maxn];
//inline add_edge(int u, int v, int w){edge[cnt]=Edge{v,head[u],w}; head[u]=cnt++;}
const int N=100005;
///Code begin..................................................................

int w[15][15];

int main ()
{
    int H, W, x;
    scanf("%d%d",&H,&W);
    FOR(i,0,9) FOR(j,0,9) scanf("%d",&w[i][j]);
    FOR(k,0,9) FOR(i,0,9) FOR(j,0,9) if (w[i][k]+w[k][j]<w[i][j]) w[i][j]=w[i][k]+w[k][j];
    int ans=0;
    FOR(i,1,H) FOR(j,1,W) {
        scanf("%d",&x);
        if (x==-1) continue;
        ans+=w[x][1];
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 256
k,n = map(int,input().split())
a = list(map(int,input().split()))

b = []
for i in range(n-1):
    kyori = a[i+1] - a[i]
    b.append(kyori)
b.append(abs(a[0]+(k-a[-1])))

print(sum(b)-max(b))


Measured memory_bytes: 32276
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
using namespace std;
typedef long long int ll;
typedef vector< int > vi;
typedef pair< int, int > ii;
typedef vector< ii > vii;
typedef vector< ll > vll;
// #define DEBUG_MODE
#ifdef DEBUG_MODE
	#define errp(...) fprintf(stderr, __VA_ARGS__)
	#define dbg(x) fprintf(stderr, "[%s = %d]\n", #x, x)
#else
	#define errp(...)
	#define dbg(x) 
#endif

const int N = 100010;
int n, color[N];
vector<vii> adj;

void dfs (int u, int p) {
	for (int i = 0; i < adj[u].size(); i++) {
		ii v = adj[u][i];
		if (v.first == p) continue;
		if (v.second & 1) color[v.first] = 1 - color[u];
		else color[v.first] = color[u];
		dfs(v.first, u);
	}
}

int main () { 
#ifdef DEBUG_MODE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	scanf("%d", &n);
	adj.assign(n, vii(0));
	int u, v, w;
	for (int i = 0; i < n - 1; i++) {
		scanf("%d%d%d", &u, &v, &w);
		u--; v--;
		adj[u].emplace_back(v, w);
		adj[v].emplace_back(u, w);
	}
	memset(color, -1, sizeof color);
	color[0] = 0;
	dfs(0, -1);
	for (int i = 0; i < n; i++) printf("%d\n", color[i]);
}

Measured memory_bytes: 8960
import java.util.*;

public class Main {
    static Scanner scanner = new Scanner(System.in);

    public static void main(String[]$) {
        int a = scanner.nextInt();
        int b = scanner.nextInt();
        int c = scanner.nextInt();
        System.out.println(a == b ? c : a == c ? b : a);
    }
}

Measured memory_bytes: 21204
// practice with Dukkha
#include <algorithm>
#include <iostream>

using namespace std;

int main() {
	string s; cin >> s;
	int n = s.length();
	int ans = 0;
	for (int i = n - 1; i >= 0; i--) {
		int d = s[i] - '0';
		if (d != 5) {
			if (d > 5) {
				ans += 10 - d;
				if (i)
					s[i - 1]++;
				else
					ans++;
			} else if (d < 5)
				ans += d;
		} else {
			ans += 5;
			if (i && s[i - 1] >= '5')
				s[i - 1]++;
		}
	}
	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 5344
n,k = map(int,input().split())

p = []
#min = 10**9+1
for i in range(n) :
    t = int(input())
    p.append(t)
    #if t < min :
    #   min = t

p.sort()

ans = 10**9+1
for i in range(n-k+1) :
    max = p[i+k-1]
    min = p[i]
    t = max - min
    if ans > t :
        ans = t
print(ans)

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

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

int n, m, d[N][N], r;
char b[N][N];
queue<tuple<int, int>> q;

int main(){
	scanf("%d%d", &n, &m);
	memset(d, 0x7f, sizeof(d));
	for(int i = 1; i <= n; i++){
		scanf("%s", b[i] + 1);
		for(int j = 1; j <= m; j++){
			if(b[i][j] == '#'){
				d[i][j] = 0;
				q.emplace(i, j);
			}
		}
	}
	while(!q.empty()){
		int x, y; tie(x, y) = q.front(); q.pop();
		r = max(r, d[x][y]);
		for(int i = 0; i < 4; i++){
			int nx = x + dx[i], ny = y + dy[i];
			if(!b[nx][ny]) continue;
			if(d[nx][ny] > d[x][y] + 1){
				d[nx][ny] = d[x][y] + 1;
				q.emplace(nx, ny);
			}
		}
	}
	printf("%d\n", r);
}

Measured memory_bytes: 13328
#include<bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); i++)
#define ALL(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
const int MAX = 300002;
const int mod = 1e9 + 7;

int main(){
	ll N; cin >> N;
	ll C[N];
	for(int i=0; i<N; i++) cin >> C[i];
	sort(C, C+N);
	ll t[2*N];
	t[0] = 1;
	for(int i=1; i<2*N; i++) t[i] = t[i-1]*2%mod;
	ll ans = 0;
	for(int i=0; i<N; i++){
		if(i != N-1)
		ans = (ans + ((t[2*N-2]*(N-i+1))%mod)*C[i])%mod;
		else
		ans = (ans+C[i]*t[2*i+1]%mod)%mod;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 4992
#include <iostream>
#include <stdio.h>
#include <math.h>
using namespace std;


int main() {
	long long int q;
	double x;
	while(1){
		cin >> q;
		if(q==-1) break;
		double x = (double)q/2.0;
		while(fabs(x*x*x-q)>0.00001*(double)q){
			x = x-(x*x*x-q)/(3*x*x);
		}
		printf("%.6f\n",x);
	}
	return 0;
}


Measured memory_bytes: 3208
#include <bits/stdc++.h>
#define f first
#define s second
#define MOD 1000000007
#define PMOD 998244353
#define pb(x) push_back(x)
using namespace std;

typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> plii;
typedef pair<int, pii> piii;
const int INF = 1e9+10;
const ll LINF = 1LL*INF*INF;
const int MAXN = 2e5+10;
const int MAXM = 5e3+10;

priority_queue<int> pq;
vector<vector<int> > graph;
queue<int> que;

int A[MAXN];
char S[MAXN];

int main()
{
    int n,m,k,a,b,x,y,q;
    int cnt = 0;
    int mx = 0;
    int mn = INF;

    cin>>n;

    long double sum = 0;
    long double cur;

    for(int i=0;i<n;i++){
        cin>>cur;
        cur = 1.0/cur;
        sum+=cur;
    }

    sum = 1.0/sum;
    cout<<fixed;
    cout.precision(9);
    cout<<sum<<"\n";

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/numeric>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#define oo 0x3f3f3f3f
#define OO 0x3f3f3f3f3f3f3f3f
#define popcount(n) __builtin_popcount(n)
#define popcountll(n) __builtin_popcountll(n)
#define long long long

using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;
template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef pair<int, int> ii;
typedef pair<int, long> ill;
typedef pair<long, int> lli;
typedef vector<int> vi;
typedef vector<long> vl;
typedef vector<pair<long, long>> vll;
typedef vector<ii> vii;
typedef vector<pair<ii, int>> viii;

const double PI = acos(-1.0), EPS = 1e-9;
const int MAXN = 100005, MAXM = 102, Mod = 998244353, MAXLog = 20;


int main() {
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0), cout.precision(10), cout
            << fixed;

//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);

    int n;
    cin >> n;
    vector<int> arr(n);
    for (int i = 0; i < n; ++i) {
        cin >> arr[i];
    }
    long ans = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = i + 1; j < n; ++j) {
            ans += arr[i] * arr[j];
        }
    }
    cout << ans << '\n';

    return 0;
}

Measured memory_bytes: 256
// https://atcoder.jp/contests/diverta2019-2/tasks/diverta2019_2_b
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define FOR(i, a, b) for (int i = (a); i < (int)(b); ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N;
    cin >> N;
    vector<pii> v(N);
    REP(i, N) cin >> v[i].first >> v[i].second;
    sort(ALL(v));

    map<pii, int> dist;
    int ans = N;
    REP(i, N) FOR(j, i + 1, N) {
        dist[{v[i].first - v[j].first, v[i].second - v[j].second}]++;
    }
    for (auto &x : dist) {
        ans = min(ans, N - x.second);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include <algorithm>
#include <string>
using namespace std;
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(int)(n); i++)
typedef long long ll;
const int INF = numeric_limits<int>::max();
const int MOD = (1e9 + 7);

int main(){
  int N,i=1, cnt=0;
  bool can=false;
  cin >> N;
  int a[N];
  rep(i, N){
    cin >> a[i];
  }
  rep(j, N){
    i = a[i-1];
    cnt ++;
    if(i==2) {
      can=true; 
      break;
    }
   
  }
  if(can) cout << cnt << endl;
  else cout << -1 << endl;
    
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
const ll INF = 1e9+100;
const ll INFL = 1e18+100;
const ll MOD = 1e9+7;
const bool debug = 0;
//-----------------------------------------------//

int main() {
	int a, b;
	cin >> a >> b;
	int p = b - a - 1;
	cout << (1 + p) * p / 2 - a << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    int k, a, b;
    cin >> k >> a >> b;
    int t = ((a / k) + (a % k != 0)) * k;
    cout << (t <= b ? "OK" : "NG") << '\n';
    return 0;
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
using LL = long long;
const LL LINF = 1e18;
using namespace std;
#define COUT(v) cout<<(v)<<endl
#define CIN(n)  int(n);cin >> (n)
#define SCIN(n) string(n);cin >> (n)
#define YES(n) cout<<((n)? "YES" : "NO")<<endl
#define Yes(n) cout<<((n)? "Yes" : "No")<<endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) <<endl

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)

#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(obj) (obj).begin(),(obj).end()

#define P pair<int,int>
#define I vector<int>
#define S set<int>
#define pb(v) push_back(v)
#define V vector
#define rt return
#define rmsame(a) sort(ALL(a)),a.erase(unique(ALL(a)), a.end())
class Edge{
public:
    int from,to,value;
    Edge(int a,int b,int c){
        from = a;
        to = b;
        value = c;
    }
    Edge(int a,int b){
        from = a;
        to = b;
    }
};
int main(){
    CIN(A);CIN(B);
    COUT(max({A+B,A-B,A*B}));
    return 0;
}


Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
int main(){
int t;cin>>t;
int ac=0,wa=0,tle=0,re=0;
while(t--){
    string s;cin>>s;
    if(s=="AC")
        ac++;
    else if(s=="WA")
        wa++;
    else if(s=="TLE")
        tle++;
    else
        re++;
}
cout<<"AC x "<<ac<<"\n";
cout<<"WA x "<<wa<<"\n";
cout<<"TLE x "<<tle<<"\n";
cout<<"RE x "<<re;

}


Measured memory_bytes: 3624
/**
 *      purpose : 
 *      author  : kyomukyomupurin
 *      created : 
**/

#include <bits/stdc++.h>
using namespace std;
using int64 = int64_t;
using pii = pair<int, int>;
using pll = pair<int64_t, int64_t>;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define print(x) cout << (x) << '\n'
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define fi first
#define se second

const int64 INF = 1e15;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int n, k; cin >> n >> k;
    int64 h[n];
    rep(i, n) cin >> h[i];

    int64 dp[100000 + 100]; // dp[i] : minimum const to reach 'i'
    rep(i, 100000 + 100) dp[i] = INF;

    dp[0] = 0; dp[1] = abs(h[0] - h[1]);

    for (int i = 0; i < n; ++i){
        for (int j = 1; j <= k; ++j) dp[i + j] = min(dp[i + j], dp[i] + abs(h[i] - h[i + j]));
    }
    print(dp[n - 1]);

    return 0;
}

Measured memory_bytes: 1792
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using static System.Math;
using System.Text;
using System.Threading;
using System.Globalization;
using System.Runtime.CompilerServices;
using Library;

namespace Program
{
    public static class ABC153B
    {
        static public int numberOfRandomCases = 0;
        static public void MakeTestCase(List<string> _input, List<string> _output, ref Func<string[], bool> _outputChecker)
        {
        }
        static public void Solve()
        {
            var H = NN;
            var N = NN;
            var AList = NNList(N);
            foreach (var item in AList)
            {
                H -= item;
            }
            if (H <= 0) Console.WriteLine("Yes");
            else Console.WriteLine("No");
        }
        static class Console_
        {
            static Queue<string> param = new Queue<string>();
            public static string NextString() { if (param.Count == 0) foreach (var item in Console.ReadLine().Split(' ')) param.Enqueue(item); return param.Dequeue(); }
        }
        class Printer : StreamWriter
        {
            public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } }
            public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) { base.AutoFlush = false; }
            public Printer(Stream stream, Encoding encoding) : base(stream, encoding) { base.AutoFlush = false; }
        }
        static public void Main(string[] args) { if (args.Length == 0) { Console.SetOut(new Printer(Console.OpenStandardOutput())); } var t = new Thread(Solve, 134217728); t.Start(); t.Join(); Console.Out.Flush(); }
        static long NN => long.Parse(Console_.NextString());
        static double ND => double.Parse(Console_.NextString());
        static string NS => Console_.NextString();
        static long[] NNList(long N) => Repeat(0, N).Select(_ => NN).ToArray();
        static double[] NDList(long N) => Repeat(0, N).Select(_ => ND).ToArray();
        static string[] NSList(long N) => Repeat(0, N).Select(_ => NS).ToArray();
        static IEnumerable<T> OrderByRand<T>(this IEnumerable<T> x) => x.OrderBy(_ => xorshift);
        static long Count<T>(this IEnumerable<T> x, Func<T, bool> pred) => Enumerable.Count(x, pred);
        static IEnumerable<T> Repeat<T>(T v, long n) => Enumerable.Repeat<T>(v, (int)n);
        static IEnumerable<int> Range(long s, long c) => Enumerable.Range((int)s, (int)c);
        static uint xorshift { get { _xsi.MoveNext(); return _xsi.Current; } }
        static IEnumerator<uint> _xsi = _xsc();
        static IEnumerator<uint> _xsc() { uint x = 123456789, y = 362436069, z = 521288629, w = (uint)(DateTime.Now.Ticks & 0xffffffff); while (true) { var t = x ^ (x << 11); x = y; y = z; z = w; w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)); yield return w; } }
    }
}
namespace Library {
}


Measured memory_bytes: 23008
#include<stdio.h>

int main()
{
	int a,b,c;
	scanf("%d %d %d",&a,&b,&c);
	int ctr=0;
	for(int i=a;i<=b;i++)
	{
		if(i%c==0)
		{
			ctr++;
		}
	}
	printf("%d\n",ctr);
	return 0;
}

Measured memory_bytes: 1700
n=int(input())
a=list(map(int,input().split()))
a=[0]+a+[0]
x=[abs(a[i]-a[i-1]) for i in range(1,n+2)]
s=sum(x)
for i in range(n):
  print(s if (a[i+2]-a[i+1])*(a[i+1]-a[i])>0 else s-x[i]-x[i+1]+abs(a[i+2]-a[i]))

Measured memory_bytes: 13920
#include <iostream>
#include <string>
#include <algorithm>
#include <iterator>
#include <functional>
#include <vector>
#include <math.h>
#include <typeinfo>
#include <numeric>
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
using namespace std;

int main()
{
	int A, B, C;

	cin >> A >> B >> C;

	int ans = C - (A - B);

	if (ans < 0)
	{
		ans = 0;
	}

	cout << ans << endl;

	return 0;
 
}

Measured memory_bytes: 256
# coding=utf-8

if __name__ == "__main__":
    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))

    ctr = 0

    for i in range(len(B)):
        if B[i] <= A[i]:
            ctr += B[i]
        else:
            ctr += A[i]
            rest = B[i] - A[i]

            ctr += min(A[i+1], rest)

            A[i+1] = max(0, (A[i]+A[i+1]-B[i]))

    print(ctr)


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

using ll = long long;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  ll x, k, d;
  cin >> x >> k >> d;
  
  x = abs(x);
  
  ll keep = min(x / d, k);
  x -= keep * d;
  k -= keep;
  //cout << x << endl;
  if (k > 0) {
    k %= 2;
    if (k == 1) x = abs(x - d);
  }
  
  cout << abs(x) << '\n';
}

Measured memory_bytes: 3592
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <random>
#include <queue>

using namespace std;


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

	vector<int> Vs(N, 0);
	vector<int> Cs(N, 0);


	int ans = 0;

	for(int ni = 0; ni < N; ni++){
		cin >> Vs[ni];
	} 
	for (int ni = 0; ni < N; ni++) {
		cin >> Cs[ni];
	}

	for (int ni = 0; ni < N; ni++) {
		if (Vs[ni] > Cs[ni]) {
			ans += Vs[ni] - Cs[ni];
		}
	}

	printf("%d", ans);

	return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>

using namespace std;

#define int long long
#define endl "\n"

const long long INF = (long long)1e18;
const long long MOD = 1'000'000'007; 

string yn(bool f){return f?"Yes":"No";}
string YN(bool f){return f?"YES":"NO";}



signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	int n;
	int sum = 0, sum2 = 0, sum3 = 0, sum4 = 0;
	int ans = 0, ans2 = 0, ans3 = 0, ans4 = 0;
	vector<int> a;
	
	cin>>n;
	
	a.assign(n, 0);
	
	for(int i = 0; i < n; i++){
		cin>>a[i];
		
		if(i){
			if(sum > 0){
				sum += a[i];
				if(sum >= 0){
					// cout<<"Y"<<endl;
					ans += sum+1;
					sum = -1;
				}
			} else {
				sum += a[i];
				if(sum <= 0){
					// cout<<"Z"<<endl;
					ans += 1-sum;
					sum = 1;
				}
			}
		} else {
			sum = a[i];
			if(sum == 0){
				sum = 1;
				ans = 1;
			}
		}
		// cout<<ans<<" "<<sum<<endl;
	}
	
	for(int i = 0; i < n; i++){
		
		if(i){
			if(sum2 > 0){
				sum2 += a[i];
				if(sum2 >= 0){
					ans2 += sum2+1;
					sum2 = -1;
				}
			} else {
				sum2 += a[i];
				if(sum2 <= 0){
					ans2 += 1-sum2;
					sum2 = 1;
				}
			}
		} else {
			sum2 = a[i];
			if(sum2 == 0){
				sum2 = -1;
				ans2 = 1;
			}
		}
	}
	
	for(int i = 0; i < n; i++){
		if(i){
			if(sum3 > 0){
				sum3 += a[i];
				if(sum3 >= 0){
					// cout<<"Y"<<endl;
					ans3 += sum3+1;
					sum3 = -1;
				}
			} else {
				sum3 += a[i];
				if(sum3 <= 0){
					// cout<<"Z"<<endl;
					ans3 += 1-sum3;
					sum3 = 1;
				}
			}
		} else {
			sum3 = 1;
			ans3 = abs(sum3-a[i]);
		}
		// cout<<ans<<" "<<sum<<endl;
	}
	
	
	for(int i = 0; i < n; i++){
		if(i){
			if(sum4 > 0){
				sum4 += a[i];
				if(sum4 >= 0){
					// cout<<"Y"<<endl;
					ans4 += sum4+1;
					sum4 = -1;
				}
			} else {
				sum4 += a[i];
				if(sum4 <= 0){
					// cout<<"Z"<<endl;
					ans4 += 1-sum4;
					sum4 = 1;
				}
			}
		} else {
			sum4 = -1;
			ans4 = abs(sum4-a[i]);
		}
		// cout<<ans<<" "<<sum<<endl;
	}
	
	cout<<min(min(ans,ans2),min(ans3,ans4))<<endl;
	
	return 0;
}

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

int main(){
  int A,B;
  cin >> A >> B;
  if(A<=5){
    cout << 0 << endl;
  }else if(A<=12){
    cout << B/2 << endl;
  }else{
    cout << B << endl;
  }
  return 0;
}


Measured memory_bytes: 256
import heapq
N = int(input())
V = [int(x) for x in input().split()]
heapq.heapify(V)

nabe = 0
for n in range(N-1):
    a = heapq.heappop(V)
    a += heapq.heappop(V)
    nabe += a
    heapq.heappush(V, a / 2)

print(V[0])


Measured memory_bytes: 3188
use std::io::prelude::*;
fn main() {
    let mut s = String::new();
    let stdin = std::io::stdin();
    stdin.lock().read_line(&mut s).expect("line");
    let stones: Vec<Stone> = (&s)
        .trim()
        .chars()
        .map(|c| Stone::from_char(c).expect("fromchar error"))
        .collect();
    let len = stones.len();
    let mut ans = 0;
    let mut blacks = 0;
    for (i, &s) in stones.iter().enumerate() {
        if s == Stone::B {
            blacks += 1;
            ans += len;
            ans -= i + blacks;
        }
    }
    println!("{}", ans);
}

#[derive(Debug, Clone, Copy, Eq, PartialEq)]
enum Stone {
    B,
    W,
}

impl Stone {
    fn from_char(c: char) -> Option<Self> {
        match c {
            'B' => Some(Stone::B),
            'W' => Some(Stone::W),
            _ => None,
        }
    }
}


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

int main(){
    long long N;
    std::cin >> N;
    N--;
    
    std::string ans; 
    while(1){
        int b = N % 26;
        char c = 'a' + b;
        ans = c + ans;
        N /= 26;
        N--;
        if(N < 0){
            break;
        }
    }
    
    std::cout << ans << std::endl;
    
    return 0;
}



Measured memory_bytes: 3628
#include <bits/stdc++.h>
#include <boost/range/adaptors.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;
using namespace boost::adaptors;

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

    vector<int64_t> a(n, -1);
    vector<vector<int64_t>> losers(n);
    for (auto i : irange(1L, n)) {
        cin >> a[i];
        --a[i];
        losers[a[i]].push_back(i);
    }

    vector<int64_t> remains(n);
    for (auto i : irange(0L, n)) {
        remains[i] += losers[i].size();
        if (losers[i].empty()) {
            --remains[a[i]];
        }
    }

    queue<int64_t> q;
    for (auto i : irange(0L, n)) {
        if (remains[i] == 0 && !losers[i].empty()) {
            q.push(i);
        }
    }

    vector<int64_t> d(n, 0);
    while (!q.empty()) {
        auto winner = q.front();
        q.pop();

        vector<pair<int64_t, int64_t>> orders;
        for (auto loser : losers[winner]) {
            orders.emplace_back(d[loser], loser);
        }

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

        d[winner] += orders.size();
        for (auto o : orders | indexed()) {
            d[winner] =
                    max(d[winner], d[o.value().second] +
                                           static_cast<int64_t>(orders.size()) -
                                           o.index());
        }

        if (winner == 0) {
            break;
        }

        --remains[a[winner]];
        if (remains[a[winner]] == 0) {
            q.push(a[winner]);
        }
    }

    cout << d[0] << endl;
}

Measured memory_bytes: 8064
# -*- coding: utf-8 -*-
from heapq import heapify, heappop, heappush
from random import randint
from collections import defaultdict
from itertools import accumulate
from fractions import gcd
from collections import defaultdict
import sys
#input = sys.stdin.readline
def inpl(): return list(map(int, input().split()))
MOD = 10**9 + 7
N, A, B = inpl()

MOD = 10**9 + 7
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod
 
size = 10**6
g1, g2, inverse = [0]*size, [0]*size, [0]*size
 
g1[:2] = [1, 1] # 元テーブル
g2[:2] = [1, 1] #逆元テーブル
inverse[:2] = [0, 1] #逆元テーブル計算用テーブル
 
for i in range(2, size):
    g1[i] =  ( g1[i-1] * i ) % MOD 
    inverse[i] = (-inverse[MOD % i] * (MOD//i) ) % MOD 
    g2[i] =  (g2[i-1] * inverse[i]) % MOD

ans = pow(2, N, MOD) - 1

g = 1
for x in range(N, N-A, -1):
    g = (g*x)%MOD
ans = (ans - g * g2[A])%MOD

g = 1
for x in range(N, N-B, -1):
    g = (g*x)%MOD
ans = (ans - g * g2[B])%MOD

print(ans)

Measured memory_bytes: 92264
#include <stdio.h>

int main(void){

	int h, w, a, b;
	while(1){
		scanf("%d %d", &h, &w);
		if(h == 0 && w == 0){
			break;
		}
		
		for(a = 0; a < h; a++){
					printf("#");
			for(b = 2; b < w; b++){
				if(a==0 || a==h-1){
					printf("#");
				}
				else{
				printf(".");	
				}
			}
			printf("#");
			printf("\n");
		}
		printf("\n");
	}
	return 0;
}

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

int main(){
  int n;
  cin >> n;
  vector<int> p;
  for(int i=0;i<n;i++){
    int tmp_p;
    cin >> tmp_p;
    p.push_back(tmp_p);
  }
  int count=0;
  for(int j=1;j<n-1;j++){
    if(((p.at(j)<p.at(j-1))&&(p.at(j)>p.at(j+1))||(p.at(j)>p.at(j-1))&&(p.at(j)<p.at(j+1)))){
      count++;
    }
  }
  cout << count <<endl;
}

Measured memory_bytes: 384
#ダイクストラ
#単一始点最短経路(正の辺のみ)
#s=始点 n=頂点数 edgeは隣接リスト(edge=[[[1,2],[2,4]],[[2,1]],[]])
#0-indexed
from heapq import heappop,heappush
def dijkstra(s,n,edge):
  inf=10**20
  ans=[inf]*n
  ans[s]=0
  h=[[0,s]]
  while h:
    c,v=heappop(h)
    if ans[v]<c:continue
    for u,t in edge[v]:
      if c+t<ans[u]:
        ans[u]=c+t
        heappush(h,[c+t,u])
  return ans
n,m=map(int,input().split())
edge=[[]for _ in range(n*3)]
for _ in range(m):
	u,v=map(int,input().split())
	u-=1
	v-=1
	edge[u*3].append([v*3+1,1])
	edge[u*3+1].append([v*3+2,1])
	edge[u*3+2].append([v*3,1])
s,t=map(int,input().split())
s-=1
t-=1
dij=dijkstra(s*3,n*3,edge)
if dij[t*3]==10**20:print(-1)
else:print(dij[t*3]//3)


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

int R,C,K,r,c,v;
int board[3001][3001];
long long int dp[3001][3001][4];

int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	cin >> R >> C >> K;
	for(int i=0;i<K;i++)
	{
		cin >> r >> c >> v;
		board[r][c] = v;
	}

	memset(dp,-1,sizeof(dp));
	dp[1][1][1] = board[1][1];
	dp[1][1][0] = 0;
	for(int i=1;i<=R;i++)
	{
		for(int j=1;j<=C;j++)
		{
			for(int k=0;k<4;k++)
			{
				if(k==3)
				{
					if(j+1<=C)
					{
						dp[i][j+1][k] = max(dp[i][j+1][k],dp[i][j][k]);
					}
					if(i+1<=R)
					{
						dp[i+1][j][0] = max(dp[i+1][j][0],dp[i][j][k]);
						dp[i+1][j][1] = max(dp[i+1][j][1],dp[i][j][k] + board[i+1][j]);
					}
				}
				else
				{
					if(j+1<=C)
					{
						dp[i][j+1][k] = max(dp[i][j+1][k],dp[i][j][k]);
						dp[i][j+1][k+1] = max(dp[i][j+1][k+1],dp[i][j][k] + board[i][j+1]);
					}
					if(i+1<=R)
					{
						dp[i+1][j][0] = max(dp[i+1][j][0],dp[i][j][k]);
						dp[i+1][j][1] = max(dp[i+1][j][1],dp[i][j][k] + board[i+1][j]);
					}
				}
			}
		}
	}

	long long int res = 0;

	for(int i=1;i<=R;i++)
	{
		for(int j=1;j<=C;j++)
		{
			for(int k=0;k<4;k++)
			{
				res = max(res,dp[i][j][k]);
			}
		}
	}

	cout << res  << '\n';

	return 0;
}


Measured memory_bytes: 320132
#include<bits/stdc++.h>
using namespace std;
int main(){
  string o,e,f;cin>>o;cin>>e;
  for(int i=0;i<o.size();i++){
    f[2*i]=o[i];
  }
  for(int i=0;i<e.size();i++){
    f[2*i+1]=e[i];
  }
  for(int i=0;i<o.size()+e.size();i++) cout<<f[i];
}

Measured memory_bytes: 256