akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

#define foreach(i,v) for(auto&& i: v)
#define all(x) (x).begin(), (x).end()

typedef std::vector< std::string > VS;
typedef std::vector<int> VI;
typedef long long ll;

template <class C> C& mini(C& a, C b) { if (b < a) a = b; return a; }
template <class C> C& maxi(C& a, C b) { if (a < b) a = b; return a; }

using namespace std;

template <typename T> void read(T& x) { x.read(); }
template <typename T> void read(vector<T>& v) { for (T& x: v) read(x); }
template <typename X, typename Y> void read(pair<X, Y>& p) { read(p.first); read(p.second); }
template <> void read(int& x) { scanf("%d", &x); }
template <> void read(unsigned int& x) { scanf("%u", &x); }
template <> void read(long long& x) { scanf("%lld", &x); }
template <> void read(unsigned long long& x) { scanf("%llu", &x); }
template <typename T> void readv(vector<T>& v) { int N; read(N); v.resize(N); read(v); }
template <typename T, typename ...Ts> void read(T& x, Ts&... args) { read(x); read(args...); }

int K;

#define MOD 1000000007

template <typename T>
void imfix(T& r) {
    if (r >= MOD)
        r -= MOD;
}

template <typename T>
T mfix(T r) {
    return r >= MOD ? r - MOD : r;
}

class Node {
public:
    vector<Node*> edges; /* should be filled by user */
    Node *parent;
    int h;

    void addEdge(Node *node) {
        edges.push_back(node);
    }

    void mkroot() {
        this->parent = nullptr;
        this->h = 0;
        stack<Node*> st;
        st.push(this);
        while (!st.empty()) {
            Node *c = st.top();
            int pi = -1;
            st.pop();
            for (int i = 0; i < c->edges.size(); i++) {
                Node *ch = c->edges[i];
                if (ch != c->parent) {
                    ch->parent = c;
                    ch->h = c->h + 1;
                    st.push(ch);
                } else {
                    pi = i;
                }
            }
            if (pi >= 0) {
                c->edges[pi] = c->edges.back();
                c->edges.pop_back();
            }
        }
    }

    int solve(int used) {
        if (used >= K)
            return 0;
        ll ret = K - used;
        int us = used ? 2 : 1;
        foreach (c, edges) {
            ret = ret * c->solve(us) % MOD;
            us++;
        }
        return ret;
    }

};

int main(int argc, const char* argv[]) {
    int N;
    read(N, K);
    vector<Node> nodes(N);
    for (int i = 0; i < N-1; i++) {
        int a, b;
        read(a, b);
        a--; b--;
        nodes[a].addEdge(&nodes[b]);
        nodes[b].addEdge(&nodes[a]);
    }
    nodes[0].mkroot();
    printf("%d\n", nodes[0].solve(0));
    return 0;
}


Measured memory_bytes: 9600
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 1000000007LL;
ll ten[19];
ll dfs(int k, int L, ll x) {
	if (k == L / 2) {
		if (x) return 0;
		if (L % 2) return 10;
		return 1;
	}
	ll d[2];
	if (x >= 0) {
		d[0] = x % 10;
		d[1] = d[0] - 10;
	}
	else {
		d[0] = -((-x) % 10);
		d[1] = d[0] + 10;
	}
	ll ret = 0;
	for (int i = 0; i < 2; i++) {
		if (i == 1 && abs(x) % 10 == 0) break;
		ll y = x - d[i] * (1 - ten[L - 1 - 2 * k]);
		if (y % 10) continue;
		y /= 10;
		ll add = dfs(k + 1, L, y);
		if (k == 0) add *= 9 - abs(d[i]);
		else add *= 10 - abs(d[i]);
		ret += add;
	}
	return ret;
}
int main() {
	int D;
	cin >> D;
	ten[0] = 1;
	for (int i = 1; i <= 18; i++) ten[i] = ten[i - 1] * 10;
	ll ans = 0;
	for (int L = 1; L <= 18; L++) {
		ans += dfs(0, L, D);
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
package main

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

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

func scanString() string   { sc.Scan(); return sc.Text() }
func scanRunes() []rune    { return []rune(scanString()) }
func scanInt() int         { a, _ := strconv.Atoi(scanString()); return a }
func scanInt64() int64     { a, _ := strconv.ParseInt(scanString(), 10, 64); return a }
func scanFloat64() float64 { a, _ := strconv.ParseFloat(scanString(), 64); return a }

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = scanInt()
	}
	return res
}

func debug(a ...interface{}) { fmt.Fprintln(os.Stderr, a...) }

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

//•*¨*•.¸¸♪main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)
func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1001001)

	n, m, a, b := scanInt(), scanInt(), scanInt(), scanInt()
	x := scanInts(n)
	y := scanInts(m)
	x = append(x, a)
	y = append(y, b)
	sort.Ints(x)
	sort.Ints(y)
	if x[n] < y[0] {
		fmt.Fprintln(wr, "No War")
	} else {
		fmt.Fprintln(wr, "War")
	}
}


Measured memory_bytes: 1792
import math
x, k, d = map(int, input().split())
i = math.floor((d*k - x)/(2*d))
if 0<= i <=k:
  print(min([abs(x-d*k+2*d*j) for j in range(i-1, i+2)]))
else:
  print(abs(abs(x)-abs(d*k)))


Measured memory_bytes: 9184
#include <iostream>

using namespace std;

int main(void) {
    int N;
    cin >> N;
    string S;
    cin >> S;

    int minimum = 0;
    for (int i = 1; i < N; ++i) {
        if (S[i] == 'E') minimum++;
    }
//    cout << minimum << endl;
    int cnt = minimum;
    for (int i = 1; i < N; ++i) {
        if (S[i - 1] == 'W') cnt++;
//        if (S[i] == 'W') cnt--;
        if (S[i] == 'E') cnt--;
        minimum = min(minimum, cnt);
    }

    cout << minimum << endl;
    return 0;
}

Measured memory_bytes: 900
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc =new Scanner(System.in);
		int N = sc.nextInt();
		int A = sc.nextInt();
		int B = sc.nextInt();
		int c =A*N;
		if(B>c) {
			System.out.println(c);
		}else {
			System.out.println(B);
		}
	}

}

Measured memory_bytes: 21844
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T>& V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> >& Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T>& mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }
template<typename T>vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>auto make_v(size_t a,Ts... ts){return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type fill_v(T &t,const V &v){t=v;}
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type fill_v(T &t,const V &v){for(auto &e:t) fill_v(e,v);}
/*
 <url:>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

template<class Type>
Type solve(Type res = Type()){
    ll A,B; cin >> A >> B;
    if((A+B)%2 == 1) {
        cout << "IMPOSSIBLE" << endl;
        return res;
    }
    cout << (A+B)/2 << endl;
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    solve(0);
    // cout << fixed << setprecision(15) << solve<ll>() << endl;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
    int p=0,q;
    long long a,b,k;
    cin>>a>>b>>k;
    q=k;
    if((b-a)/k>=2){
            for(int i = 0; i < k; i++){
                cout<<a+p<<endl;
                p++;
            }
            for(int i = 0; i < k; i++){
                cout<<b-q+1<<endl;
                q--;
            }
 
    }
    else{
        for(int i = 0;i <= b-a; i++){
            cout<<a+i<<endl;
        }
    }
  return 0;
}

Measured memory_bytes: 256
M=2019
S=input()+'0'
t = 1
p=0
mcnt = [0] * 2019
ans = 0
for x in S[::-1]:
    dm = int(x) * t % M
    am = (dm+p) % M
    ans += mcnt[am]
    mcnt[am]+=1
    t=t*10%M
    p=am
print(ans)


Measured memory_bytes: 68672
#include<bits/stdc++.h>
 using namespace std;
 inline int read(){
    int x=0,f=1; char ch=getchar();
    while(ch<'0' || ch>'9') {if(ch=='-') f=-1; ch=getchar();}
    while(ch>='0' && ch<='9') {x=x*10+ch-'0'; ch=getchar();}
    return x*f;
 }
 int N,Q,a[100010],b,c,cnt[100010];
 #define LL long long
 int main(){
 	N=read();
 	LL sum = 0;
 	for (int i=1; i<=N; i++) a[i]=read(),cnt[a[i]]++,sum+=a[i];
 	Q=read();
 	while (Q--){
 		b=read(),c=read();
 		sum -= 1LL*cnt[b]*b;
 		sum += 1LL*cnt[b]*c;
 		cnt[c] += cnt[b];
 		cnt[b] = 0;
 		printf("%lld\n",sum);
 	}
 	return 0;
 }
 
 
 /*
4
1 2 3 4
3
1 2
3 4
2 4
 */

Measured memory_bytes: 4428
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <set>
#include <iomanip>
#include <fstream>
#include <stdint.h>
#include <cmath>
#include <algorithm>
#include <utility>
#include <numeric>
using namespace std;

constexpr int INF       = 1000000000;/* 1e+9a */
constexpr int MODULO    = 1000000007;

constexpr int evx[4] = { 1, 0, -1, 0 };
constexpr int evy[4] = { 0, 1, 0, -1 };

//----------------------------------
//----------------------------------

signed main()
{
    ios::sync_with_stdio(false);
	string s;
	cin >> s;
	int num = s.size();
	int s_num = 0;
	for(size_t i = 0; i < s.size(); ++i)
	{
		switch(s[i]){
			case 'S': s_num++;
					  break;
			case 'T': 
					  if(s_num > 0)
					  {
						  num -= 2;
						  s_num--;
					  }
					  break;
		}
	}
	cout << num << '\n';

						 



			
}


Measured memory_bytes: 720
#include <stdio.h>

int main(void) {
	int N;
	char s[128] = "";
	int kitaeri = 0;
	int i;
	if (scanf("%d", &N) != 1) return 1;
	if (scanf("%127s", s) != 1) return 1;
	for (i = 0; i < N; i++) {
		if (s[i] == 'R') kitaeri++; else kitaeri--;
	}
	puts(kitaeri > 0 ? "Yes" : "No");
	return 0;
}


Measured memory_bytes: 1616
#include<bits/stdc++.h>
#define ll long long
#define int ll
#define mp make_pair
#define pii pair<int,int>
#define pb push_back
#define r1 rt<<1
#define r2 rt<<1|1
#define fi first
#define se second
#define db double
#define ld long db
#define ri register int
#define rep(i,a,b) for(ri i=(a);i<=(b);++i)
#define rep2(i,a,b,c) for(ri i=(a);i<=(b);i+=(c))
#define REP(i,a,b) for(ri i=(a);i>=(b);--i)
#define REP2(i,a,b,c) for(ri i=(a);i>=(b);i-=(c))
using namespace std;

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

const int N=6e5+5;
int n,m,a[N],lim;
const double PI = acos(-1.0);
struct Complex {
  double x, y;
  Complex(double _x = 0.0, double _y = 0.0) {
    x = _x;
    y = _y;
  }
  Complex operator-(const Complex &b) const {
    return Complex(x - b.x, y - b.y);
  }
  Complex operator+(const Complex &b) const {
    return Complex(x + b.x, y + b.y);
  }
  Complex operator*(const Complex &b) const {
    return Complex(x * b.x - y * b.y, x * b.y + y * b.x);
  }
}A[N],B[N];
/*
 * 进行 FFT 和 IFFT 前的反置变换
 * 位置 i 和 i 的二进制反转后的位置互换
 *len 必须为 2 的幂
 */
void change(Complex y[], int len) {
  int i, j, k;
  for (int i = 1, j = len / 2; i < len - 1; i++) {
    if (i < j) swap(y[i], y[j]);
    // 交换互为小标反转的元素，i<j 保证交换一次
    // i 做正常的 + 1，j 做反转类型的 + 1，始终保持 i 和 j 是反转的
    k = len / 2;
    while (j >= k) {
      j = j - k;
      k = k / 2;
    }
    if (j < k) j += k;
  }
}
/*
 * 做 FFT
 *len 必须是 2^k 形式
 *on == 1 时是 DFT，on == -1 时是 IDFT
 */
void fft(Complex y[], int len, int on) {
  change(y, len);
  for (int h = 2; h <= len; h <<= 1) {
    Complex wn(cos(2 * PI / h), sin(on * 2 * PI / h));
    for (int j = 0; j < len; j += h) {
      Complex w(1, 0);
      for (int k = j; k < j + h / 2; k++) {
        Complex u = y[k];
        Complex t = w * y[k + h / 2];
        y[k] = u + t;
        y[k + h / 2] = u - t;
        w = w * wn;
      }
    }
  }
  if (on == -1) {
    for (int i = 0; i < len; i++) {
      y[i].x /= len;
    }
  }
}
signed main()
{
	n=read();m=read();
	rep(i,1,n)a[i]=read(),++A[a[i]].x,++B[a[i]].x;
	lim=1;while(lim<=400004)lim<<=1;
	fft(A,lim,1);fft(B,lim,1);
	rep(i,0,lim)A[i]=A[i]*B[i];
	fft(A,lim,-1);
	ri ans=0;
	REP(i,2e5,0){
		ri cur=(int)(A[i].x+0.5);
		if(cur>=m){ans+=i*m;break;}
		m-=cur;ans+=i*cur;
	}
	cout<<ans;
	return 0; 
}

Measured memory_bytes: 21120
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> Pl;
typedef pair<int, int> P;

int n, c[3*100000+30], mem, ans, pos;
string s;

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

    for(int i = 0; i < s.length(); i++){
        if(s[i] == 'W') c[i+1]++;
        c[i+1] += c[i];
    }
    ans = 3*100000+30;
    for(int i = 0; i < n; i++){
        mem = c[i] + (n-i-1)-(c[n]-c[i+1]);
        ans = min(ans, mem);
    }
    cout << ans << endl;
}

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


#define li          long long int
#define rep(i,to)   for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)    for(li i=(li)(start);i<((li)(to));i++)
#define pb          push_back
#define sz(v)       ((li)(v).size())
#define bgn(v)      ((v).begin())
#define eend(v)     ((v).end())
#define allof(v)    (v).begin(), (v).end()
#define dodp(v,n)       memset(v,(li)n,sizeof(v))
#define bit(n)      (1ll<<(li)(n))
#define mp(a,b)     make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)     idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)       idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)        idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)   for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)      idp p2((x).F, (x).S)
#define dump(x,n)   idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)  idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)    idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)   idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)   rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)   rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;

li h, n;
li a[1010];
li b[1010];

li dp[20200];

int main() {
    li maa = 0;
    cin >> h >> n;
    rin{
        cin >> a[i] >> b[i];
        maa = max(maa, a[i]);
    }

    rep(i, h + 1 + 10000) {
        dp[i] = INF;
    }
    dp[0] = 0;

    rep(i, h) {
        rep(j, n) {
            dp[i + a[j]] = min(dp[i + a[j]], dp[i] + b[j]);
        }
    }

    li res = INF;
    repp(i, h, h + maa + 1) {
        res = min(res, dp[i]);
    }

    cout << res << endl;


    return 0;
}

Measured memory_bytes: 3800
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;

int n;
int a[105];
bool cnt[10];
int main()
{
	while(scanf("%d", &n) != EOF)
	{
		for(int i = 1; i <= n; i++)
			scanf("%d", &a[i]);
		sort(a + 1, a + n + 1);
		int x = 0;
		for(int i = 1; i <= n; i++)
		{
			if(a[i] >= 1 && a[i] <= 399) cnt[1] = 1;
			else if(a[i] >= 400 && a[i] <= 799) cnt[2] = 1;
			else if(a[i] >= 800 && a[i] <= 1199) cnt[3] = 1;
			else if(a[i] >= 1200 && a[i] <= 1599) cnt[4] = 1;
			else if(a[i] >= 1600 && a[i] <= 1999)  cnt[5] = 1;
			else if(a[i] >= 2000 && a[i] <= 2399) cnt[6] = 1;
			else if(a[i] >= 2400 && a[i] <= 2799) cnt[7] = 1;
			else if(a[i] >= 2800 && a[i] <= 3199) cnt[8] = 1;
			else if(a[i] >= 3200) x++;
		}
		int num = 0;
		for(int i = 1; i <= 8; i++)
			if(cnt[i] == 1)
				num++;
		if(x > 0 && num == 0) printf("1 %d\n", x);
		else 
			printf("%d %d\n", num, num + x);
		memset(a, 0, sizeof(a));
		memset(cnt, 0, sizeof(cnt));
	}
	return 0;
}

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

#define ll long long
#define vvi vector< vector<int> >
#define vi vector<int>
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
#define pi 3.14159265359
#define shosu(X) fixed << setprecision(X)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
	string a,b;
	cin >> a >> b;
	if(a.size() < b.size()){
		cout << "LESS" << endl;
		return 0;
	}
	if(a.size() > b.size()){
		cout << "GREATER" << endl;
		return 0;
	}
	REP(i,a.size()){
		if(a[i] < b[i]){
			cout << "LESS" << endl;
			return 0;
		}
		if(a[i] > b[i]){
			cout << "GREATER" << endl;
			return 0;
		}
	}
	cout << "EQUAL" << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
    
    int n, m, i, j, x;
    int b[1000], a[1000][1000];
    
    scanf("%d %d", &n, &m);
    
    for(i=0; i<n; i++){
        for(j=0; j<m; j++){
            scanf("%d", &a[i][j]);
        }
    }
    
    for(i=0; i<m; i++){
        scanf("%d", &b[i]);
    }
    
    for (i = 0; i < n; i++) {
        x=0;
        for(j = 0; j < m; j++){
            x += a[i][j] * b[j];
        }
        printf("%d\n", x);
    }
    
return 0;
}

Measured memory_bytes: 992
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n, a, plan2, plan1;
  cin >> n >> a >> plan2;
  
  plan1 = a * n;
  
  if (plan1 < plan2) {
    cout << plan1 << endl;
  } else {
    cout << plan2 << endl;
  }
}

Measured memory_bytes: 256
n = int(input())
s = list(input())
ans = 0
for i in range(1, n):
    count = 0
    x = sorted(set(s[:i]))
    y = sorted(set(s[i:]))
    for j in x:
        if j in y:
            count += 1
    ans = max(ans, count)
print(ans)

Measured memory_bytes: 9188
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author cherrypi59
 */

#pragma GCC optimize ("O2")
#pragma GCC optimize ("tree-vectorize")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define FFOR(i, a, b) FOR(i, a, b+1)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) FOR(i, 1, n+1)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define LEN(x) (int)(x).size()
#define DUMP(x) cerr<<__LINE__<<' '<<#x<<"="<<(x)<<endl;
#define pb push_back
#define eb emplace_back
#define mp make_pair

using namespace std;
using lint = long long;
using pii =  pair<int, int>;
using pll =  pair<lint, lint>;
template <typename T> using vc = vector<T>;
template <typename T> using vvc = vector<vector<T>>;
template <typename T> inline bool chmax(T &a, T b){if(a<b){a = b; return true;} return false;}
template <typename T> inline bool chmin(T &a, T b){if(a>b){a = b; return true;} return false;}

constexpr lint ten(int n) {return n==0 ? 1 : ten(n-1)*10;}

class CMaximalValue {
public:
    void solve(std::istream& in, std::ostream& out){
        ios_base::sync_with_stdio(false);
        in.tie(nullptr), out.tie(nullptr);
        int N;
        in>>N;
        vc<int> B(N-1);
        REP(i, N-1) in>>B[i];
        int ans = B[0] + B[N-2];
        RREP(i, N-2) ans += min(B[i], B[i-1]);
        out<<ans<<'\n';
    }
};


int main() {
	CMaximalValue solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


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

int main() {
	int a, b;
	int c;
	cin >> a >> b;
	if ((a + b) % 2 == 0) cout << (a + b) / 2 << endl;
	else cout << (a + b)/2 + 1 << endl;


}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;++i)


int main(){
  string s;
  cin >> s;
  string ans="NO";
  string str=s,key="keyence",keyr=key;
  reverse(str.begin(),str.end());
  reverse(keyr.begin(),keyr.end());
  int a=key.size();
  if(s.substr(0,a-1)==key||str.substr(0,a-1)==keyr){
    ans="YES";
  }
  rep(i,a+1){
    if(s.substr(0,i)==key.substr(0,i)){
      if(str.substr(0,a-i)==keyr.substr(0,a-i)){
        ans="YES";
        break;
      }
    }
  }
  cout << ans << endl;
}


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

typedef long long ll;
typedef pair<ll, ll> P;


#define rep(i,n) for(ll (i)=0; (i)<(ll)(n); (i)++)
#define frep(i,m,n) for(ll (i)=(m); (i)<=(ll)(n); (i)++)
#define rrep(i,n) for(ll (i)=(n)-1; (i)>-1; (i)--)
#define frrep(i,m,n) for(ll (i)=(n); (i)>(ll)(m); (i)--)
#define ALL(x) (x).begin(), (x).end()

const ll INF = 100100100100100100;
const ll MOD = 1000000007;

// get abs
ll my_abs(ll a);
// a^n
ll a_n(ll a, ll n);
// get gcd
ll my_gcd(ll a, ll b);
// a^(-1) % MOD 
ll inv(ll a);
// (a+b+c)%MOD
ll madd(ll a, ll b, ll c);
// (a-b)%MOD
ll msub(ll a, ll b);
// (a*b*c)%MOD
ll mtime(ll a, ll b, ll c);


// list of prime (is_prime.size() = n + 1, primes.size() = 0)
// primes: list of prime numbers
// is_prime: is_prime[i] == "if i is a prime number"
void prime_list(ll n, vector<ll> &primes, vector<bool> &is_prime) {
    ll p = 0;
    rep(i, n + 1) is_prime[i] = true;
    is_prime[0] = false;
    is_prime[1] = false;
    for(ll i = 2; i <= n; i++) {
        if(is_prime[i]) {
            primes.push_back(i);
            for(ll j = 2*i; j <= n; j += i) is_prime[j] = false;
        }
    }
}

int main() {
    ll n; cin >> n;
    vector<ll> primes;
    vector<bool> is_prime(56001);
    prime_list(56000, primes, is_prime);
    
    ll num = 0;
    rep(i, primes.size()) {
        if((primes[i]%5) == 1) {
            cout << primes[i];
            num++;
            if(num == n) {
                cout << endl;
                break;
            }
            else {
                cout << " ";
            }
        }
    }

    return 0;
}

ll my_abs(ll a) {
    if(a >= 0) return a;
    else return -1 *a;
}

ll a_n(ll a, ll n) { 
    if(n == 0) return 1;
    
    ll ret = a, count = 1;
    while(count * 2 < n) {
        ret *= ret;
        count *= 2;
    }
    if(count == n) return ret;
    else return (ret * a_n(a, n-count));
}

ll my_gcd(ll a, ll b) {
    if(b == 0) return a;
    return my_gcd(b, a%b);
}

ll inv(ll a) {
    return a_n(a, MOD-2);
}

ll madd(ll a, ll b, ll c) {
    ll ret = (a+b) % MOD;
    return (ret+c) % MOD;
}

ll msub(ll a, ll b) {
    if(a < b) return (a-b+MOD) % MOD;
    else return (a-b) % MOD;
}

ll mtime(ll a, ll b, ll c) {
    ll ret = (a*b) % MOD;
    return (ret*c) % MOD;
}


Measured memory_bytes: 3712
# coding: utf-8
N=int(input())
A=list(map(int,input().split()))
A.sort()

MOD=10**9+7
flg=True
k=1

if N%2==1:
    k=2
    a=A.pop(0)
    if a!=0:
        flg=False
        
for i in range(N//2):
    if A[i*2]!=k or A[i*2+1]!=k:
        flg=False
    k+=2
    
if flg:
    ans=1
    for i in range(N//2):
        ans*=2
        ans=ans%MOD
else:
    ans=0

print(ans)



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

namespace AtCorder
{
	public class Program
	{
		static void Main(string[] args)
		{
			A();
		}

		public static void A()
		{
			Scanner cin = new Scanner();
			int a = cin.NextInt();
			int b = cin.NextInt();
			int c = cin.NextInt();

			int temp = b / a;

			Console.WriteLine(Math.Min(temp, c));

		}
	}

	public class Scanner
	{
		string[] s;
		int i;

		char[] cs = new char[] { ' ' };

		public Scanner()
		{
			s = new string[0];
			i = 0;
		}

		public string Next()
		{
			if (i < s.Length) return s[i++];
			string st = Console.ReadLine();
			while (st == "") st = Console.ReadLine();
			s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
			if (s.Length == 0) return Next();
			i = 0;
			return s[i++];
		}

		public int NextInt()
		{
			return int.Parse(Next());
		}
		public int[] ArrayInt(int N, int add = 0)
		{
			int[] Array = new int[N];
			for (int i = 0; i < N; i++) {
				Array[i] = NextInt() + add;
			}
			return Array;
		}

		public long NextLong()
		{
			return long.Parse(Next());
		}

		public long[] ArrayLong(int N, long add = 0)
		{
			long[] Array = new long[N];
			for (int i = 0; i < N; i++) {
				Array[i] = NextLong() + add;
			}
			return Array;
		}

		public double NextDouble()
		{
			return double.Parse(Next());
		}


		public double[] ArrayDouble(int N, double add = 0)
		{
			double[] Array = new double[N];
			for (int i = 0; i < N; i++) {
				Array[i] = NextDouble() + add;
			}
			return Array;
		}
	}
}


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

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

const ll mod =  1000000007;  //ansを出力する時は (ans % mod + mod) % mod とする(負の剰余を正にする)
const int inf = 1e9;
const long long INF = 1LL << 60;   // INFの値は1152921504606846976


int main()
{
    int n,l; cin >> n >> l;
    int sum = 0;
    int e = inf;
    rep(i,n){
        int a; cin >> a;
        sum += (l+i);
        if(abs(l+i) < abs(e)) e = l+i;
    }
    cout << sum - e;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
        int d;
        scanf("%d",&d);
        if(d==25)printf("Christmas\n");
        else if(d==24)printf("Christmas Eve\n");
        else if(d==23)printf("Christmas Eve Eve\n");
        else printf("Christmas Eve Eve Eve\n");
        return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <string>
#include <set>

using namespace std;

int main(){
    int N, Q;
    string S;
    cin >> N ;
    cin >> S;
    cin >> Q;
    set<int> alp_loc[26];
    for (int i=0; i<N; i++){
        alp_loc[S[i] - 'a'].insert(i);
    }
    int t[Q], r1[Q], r2[Q];
    for(int i=0; i<Q; i++){
        cin >> t[i];
        if(t[i] == 1){
            char c;
            cin >> r1[i] >> c;
            r2[i] = int (c - 'a');
            r1[i]--;
        }
        else{
            cin >> r1[i] >> r2[i];
            r1[i] --; r2[i] --;
        }
    }
    for(int i=0; i<Q; i++){
        if(t[i] == 1){
            for(int j=0; j<26; j++){
                if(alp_loc[j].find(r1[i]) != alp_loc[j].end()) {
                    alp_loc[j].erase(r1[i]);
                    break;
                }
            }
            alp_loc[r2[i]].insert(r1[i]);
        }
        else{
            int ans = 0;
            for(int j=0; j<26; j++){
                if (*alp_loc[j].lower_bound(r1[i]) <= r2[i] && alp_loc[j].lower_bound(r1[i]) != alp_loc[j].end()) ans ++;
            }
            cout << ans << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 24452
object Main extends App{
    val s = scala.io.StdIn.readLine.toList
    val t = scala.io.StdIn.readLong

    var i = 0

    while(i < s.size && s(i) == '1'){
    	i += 1
    }

    if(t <= i){
    	println(1)
    }else{
    	println(s(i))
    }
}


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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define show(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define show(x)
#endif

typedef long long int ll;
typedef pair<int,int> pii;
template<typename T> using vec=std::vector<T>;

const int inf=1<<30;
const long long int infll=1LL<<62;
const double eps=1e-9;
const int dx[]={1,0,-1,0},dy[]={0,1,0,-1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
    	os << v << ",";
    }
    os << "]";
    return os;
}

void solve(int m,int n){
    vector<string> objs(n);
    for(auto &obj:objs) cin >> obj;

    vector<vector<int>> memo(1<<m,vector<int>(1<<m,inf));
    vector<vector<bool>> done(1<<m,vector<bool>(1<<m));
    function<int(bitset<11>&,bitset<11>&)> dfs=[&](bitset<11> &question,bitset<11> &answer){
        int &res=memo[question.to_ulong()][answer.to_ulong()];
        if(done[question.to_ulong()][answer.to_ulong()]) return res;
        done[question.to_ulong()][answer.to_ulong()]=true;

        int count_match=0;
        rep(i,0,n){
            bool match=true;
            rep(j,0,m){
                if(!question[j]) continue;
                if((objs[i][j]=='0' and  answer[j]) or (objs[i][j]=='1' and  !answer[j])){
                    match=false;
                    break;
                }
            }
            if(match) ++count_match;
        }
        if(count_match==0) return res=-inf;
        if(count_match==1) return res=question.count();

        rep(i,0,m){
            if(question[i]) continue;
            question[i]=1;
            answer[i]=1;
            int tmp=dfs(question,answer);
            answer[i]=0;
            res=min(res,max(dfs(question,answer),tmp));
            question[i]=0;
        }
        return res;
    };
    bitset<11> question,answer;
    cout << dfs(question,answer) << endl;
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(10);
    while(true){
        int m,n;
        cin >> m >> n;
        if(m==0 and n==0) break;
        solve(m,n);
    }
    return 0;
}

Measured memory_bytes: 20080
#include <bits/stdc++.h>
using namespace std;
struct UnionFind {
    vector<int> r;
    UnionFind(int N) {
        r = vector<int>(N, -1);
    }
    int root(int x) {
        if (r[x] < 0) return x;
        return r[x] = root(r[x]);
    }
    bool unite(int x, int y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (r[x] > r[y]) swap(x, y);
        r[x] += r[y];
        r[y] = x;
        return true;
    }
    int size(int x) {
        return -r[root(x)];
    }
};

int main(){
  int n, m;
  cin >> n >> m;
  UnionFind uf(n);
  for(int i = 0; i < m; ++i){
  	int a, b;
    cin >> a >> b;
    --a; --b;
	uf.unite(a, b);
  }
  int maxsize = 0;
  for(int i = 0; i < n; ++i){
  	maxsize = max(maxsize, uf.size(i)); 
  }
  cout << maxsize << '\n';
  return 0;
}




Measured memory_bytes: 3968
#include <bits/stdc++.h>
using namespace std;
#define int long long
int mod = 2019;
int INF = (int)2e18;

signed main() {
    int A, B, C;
    cin >> A >> B >> C;
    int ans = C - (A - B);
    if (ans < 0) ans = 0;
    cout << ans << endl;
}

Measured memory_bytes: 256
n,m,q = map(int, input().split())
lr=[list(map(int,input().split())) for i in range(m)]
pq=[list(map(int,input().split())) for i in range(q)]
arr = [[0 for _ in range(n+1)] for _ in range(n+1)]
for l,r in lr:
    arr[l][r]+=1
rui = [[0 for _ in range(n+1)] for _ in range(n+1)]

for i in range(1,n+1):
    for j in range(1,n+1):
        rui[i][j] = rui[i-1][j] + rui[i][j-1] - rui[i-1][j-1] + arr[i][j]

for p,q in pq:
    cnt = rui[q][q] - rui[p-1][q] - rui[q][p-1] + rui[p-1][p-1]
    print(cnt)

Measured memory_bytes: 127808
n = int(input())
cnt = [[[0 for _ in range(10)] for _ in range(3)] for _ in range(4)]
 
for _ in range(n):
  b, f, r, v = map(int, input().split())
  cnt[b-1][f-1][r-1] += v
 
for i in range(4):
  for j in range(3):
    print(' '+' '.join(map(str, cnt[i][j])))
 
  if i != 3:
    print('#'*20)


Measured memory_bytes: 5604
#include<stdio.h>

int main(){
   int crane=2;
   int turtle=4;
   int X,Y;
   scanf("%d %d",&X,&Y);
   if(Y<2*X||X*4<Y){
      printf("No");
   }else if(Y%2==1){
      printf("No");
   }else{
      printf("Yes");
   }
   return 0;
}


Measured memory_bytes: 1736
# C - Bugged
def main():
    n = int(input())
    s = [int(input()) for _ in range(n)]
    s.sort()
  
    if sum(s) % 10 != 0:
        print(sum(s))
    else:
        for i in range(n):
            if s[i] % 10 != 0:
                print(sum(s)-s[i])
                exit()
        else:
            print(0)


if __name__ ==  "__main__":
    main()

Measured memory_bytes: 9028
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
#include<bitset>
using namespace std;

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

typedef int i32;
typedef long long int i64;
typedef unsigned long long int ui64;
typedef float f32;
typedef double f64;
typedef long double f128;


int main(){
    int N;
    cin >> N;
    int a[N];
    REP(i,N){
        cin >> a[i];
    }
    int ans=0;
    REP(i,N){
        REP(k,100){
            if(a[i]%2==0){
                ans++;
                a[i] /= 2;
            }else{
                break;
            }
        }
    }
    cout << ans;
}

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

void Main(){
    int n, k, wel = 0, cre = 0;
    cin >> n >> k;
    vector<char> s(n+1);
    rep(i, n){
        cin >> s[i];
    }
    rep(i,n-1){
        if(s[i] == s[i+1]){
            wel++;
        }else{
            cre++;
        }
    }
    int ans = 0;
    if(k * 2 > cre){
        ans += cre + wel;
    }else{
        ans += k * 2 + wel;
    }
    
    cout << ans << endl;
}

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

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

set<long long> S;
int id;
void f(long long n) {
  id++;
  if( S.count(n) ){
    cout << id << endl;
    exit(0);
  }else{
    S.insert(n);
  }
  if (n % 2 == 0) {
    f(n / 2);
  } else {
    f( n * 3 + 1);
  }
}
void solve(long long s) {
  f(s);
}

int main() {
  long long s;
  scanf("%lld", &s);
  solve(s);
  return 0;
}


Measured memory_bytes: 256
#include <functional>
#include <algorithm>
#include <set>
using namespace std;

using line_t = double;
const line_t is_query = -1e18;
struct Line {
	line_t m, b;
	mutable function<const Line*()> succ;
	bool operator<(const Line& rhs) const {
		if (rhs.b != is_query) return m < rhs.m;
		const Line* s = succ();
		if (!s) return 0;
		line_t x = rhs.m;
		return b - s->b < (s->m - m) * x;
	}
};
struct HullDynamic : public multiset<Line> { // will maintain upper hull for maximum
	bool bad(iterator y) {
		auto z = next(y);
		if (y == begin()) {
			if (z == end()) return 0;
			return y->m == z->m && y->b <= z->b;
		}
		auto x = prev(y);
		if (z == end()) return y->m == x->m && y->b <= x->b;
		return (x->b - y->b)*(z->m - y->m) >= (y->b - z->b)*(y->m - x->m);
	}
	void insert_line(line_t m, line_t b) {
		auto y = insert({ m, b });
		y->succ = [=] { return next(y) == end() ? 0 : &*next(y); };
		if (bad(y)) { erase(y); return; }
		while (next(y) != end() && bad(next(y))) erase(next(y));
		while (y != begin() && bad(prev(y))) erase(prev(y));
	}
	line_t query(line_t x) {
		Line tptp = { x, is_query };
		auto l = *lower_bound(tptp);
		return l.m * x + l.b;
	}
}H;

int n, w[201000];
long long K, D[201000];

int main() {
	int i;
	scanf("%d%lld", &n,&K);
	for (i = 1; i <= n; i++) {
		scanf("%d", &w[i]);
		if(i!=1)D[i] = -H.query(w[i]) + 1ll*w[i]*w[i] + K;
		else D[i] = 0;
		H.insert_line(2 * w[i], -(D[i] + 1ll * w[i] * w[i]));
	}
	printf("%lld\n", D[n]);
}

Measured memory_bytes: 21376
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    T = list(map(int, input().split()))
    A = list(map(int, input().split()))

    check = [False] * n
    check[0] = check[-1] = True
    res = [f_inf] * n
    res[0] = T[0]
    res[-1] = A[-1]
    for i in range(1, n):
        if T[i - 1] != T[i] or T[i] == 1:
            check[i] = True
        res[i] = min(res[i], T[i])

    for j in reversed(range(n - 1)):
        if A[j + 1] != A[j] or A[j] == 1:
            check[j] = True
        res[j] = min(res[j], A[j])

    ma = 0
    for i in range(n):
        if check[i]:
            if res[i] > ma:
                ma = res[i]
        if T[i] > ma:
            print(0)
            exit()

    ma = 0
    for i in reversed(range(n)):
        if check[i]:
            if res[i] > ma:
                ma = res[i]
        if A[i] > ma:
            print(0)
            exit()

    ans = 1
    for k in range(n):
        if not check[k]:
            ans *= res[k]
            ans %= mod
    print(ans)


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 25096
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 4000000000000000000LL
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


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

  std::cout << std::fixed << std::setprecision(6);
  std::cerr << std::fixed << std::setprecision(6);

  int P, Q, R;

  std::cin >> P >> Q >> R;

  std::cout << std::min({P + Q, Q + R, R + P}) << std::endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define FOR(i,a,b) for(long long i = (long long)(a); i < (long long)(b); i++)
#define RFOR(i,a,b) for(long long i = (long long)(a); i >= (long long)(b); i--)
#define MIN3(a,b,c) (a)<(b)?((a)<(c)?(a):(c)):((b)<(c)?(b):(c))
#define MAX(a,b) (a)>(b)?(a):(b)
#define MIN2(a,b) (a)<(b)?(a):(b)
using namespace std;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef long long ll;
#define ull unsigned long long
typedef long double ld;
typedef vector<ll> vll;
typedef pair<ll,ll> lll;
#define deb(x )     cerr << #x << " here "<< x << endl;
#define endl    "\n"
#define printCase() "Case #" << caseNum << ": "
inline bool is_palindrome(const string& s){ return std::equal(s.begin(), s.end(), s.rbegin()); }
const ll MOD = 1000000007;
const ll INF = 1e9+5;
const double eps = 1e-7;
const double PI = acos(-1.0);
#define coud(a,d) cout << fixed << showpoint << setprecision(d) << a;
inline void debug_vi(vi a) {FOR(i, 0, a.size()) cout<<a[i]<<" ";}
inline void debug_vll(vll a) {FOR(i, 0, a.size()) cout<<a[i]<<" ";}
#define ff first
#define ss second
/*----------------------------------------------------------------------*/

set<int> pos[26];

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

    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    string s,t; cin>>s>>t; int n =s.size();
    FOR(i, 0, s.size()) {
    	pos[s[i]-'a'].insert(i);
    }
    ll ans = 0, tot = 0, idx = -1;
    FOR(i, 0, t.size()) {
    	int v = t[i] - 'a';
    	auto itr = pos[v].upper_bound(idx);
    	if(itr != pos[v].end()) {
    		ans = tot * n + (*itr);
    		idx = *itr;
    	} else {
    		idx = -1;
    		tot++;

    		auto itr2 = pos[v].upper_bound(idx);
    		if(itr2 != pos[v].end()) {
    			ans = tot * n + (*itr2);
    			idx = *itr2;
    		} else {
    			cout<<-1;
    			return 0;
    		}
    	}
    }
    cout<<ans + 1;
    return 0;
}

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

int main()
{
	string s;
	while( cin >> s ){
		int a[10][10];
		for( int i = 0; i < 10; i++ )
			a[0][i] = s[i] - '0';
		
		for( int i = 1; i < 10; i++ ){
			for( int j = 0; j < 10 - i; j++ ){
				a[i][j] = a[i-1][j] + a[i-1][j+1];
				a[i][j] %= 10;
			}
		}
		cout << a[9][0] << endl;
	}
	return 0;
}

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

int main() {
    ll n, cnt[26]{}, ans;
    string s;
    cin >> s;
    n = s.size();
    for(auto c : s){
        cnt[c-'a']++;
    }
    ans = n*(n-1)/2;  // 長さ2以上の部分文字列の反転の総数
    REP(i,26) ans -= cnt[i]*(cnt[i]-1)/2;  // 部分列の両端が同じ文字のものを除く
    ans++;  // 初期状態の分
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 640
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {

	public static void main(String[] args) {
		//		new Main().solveA();
		new Main().solveB();
		// new Main().solveC();
		// new Main().solveD();
	}

	private void solveA() {
		Scanner scanner = null;
		int numA = 0;
		int numB = 0;

		try {
			scanner = new Scanner(System.in);
			numA = scanner.nextInt();
			numB = scanner.nextInt();

			System.out.println(Math.max(numA + numB, Math.max(numA - numB, numA * numB)));

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}

	private void solveB() {
		Scanner scanner = null;
		int numN = 0;
		String numS = "";

		try {
			scanner = new Scanner(System.in);
			numN = scanner.nextInt();
			numS = scanner.next();

			int res = 0;
			for (int num = 0; num < 2; num++) {

				String numWk = "";
				if (num == 0) {
					numWk = numS;
				} else {
					numWk = new StringBuilder(numS).reverse().toString();
				}

				for (int i = numN / 2; i >= 0; i--) {
					char[] val1 = numWk.substring(0, i).toCharArray();
					char[] val2 = numWk.substring(i, numN).toCharArray();

					Set<Character> wkSet1 = new HashSet<Character>();
					for (int j = 0; j < val1.length; j++) {
						wkSet1.add(val1[j]);
					}

					Set<Character> wkSet2 = new HashSet<Character>();
					for (int j = 0; j < val2.length; j++) {
						wkSet2.add(val2[j]);
					}

					Set<Character> chkSet = null;
					Set<Character> resSet = null;
					if (wkSet1.size() > wkSet2.size()) {
						chkSet = wkSet1;
						resSet = wkSet2;
					} else {
						chkSet = wkSet2;
						resSet = wkSet1;
					}

					int cnt = 0;
					for (Character character : chkSet) {
						if (resSet.contains(character)) {
							cnt++;
						}
					}

					res = Math.max(res, cnt);
				}
			}

			System.out.println(res);

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}

	private void solveC() {
		Scanner scanner = null;
		int numN = 0;
		int numK = 0;
		int numS = 0;

		try {
			scanner = new Scanner(System.in);
			numN = scanner.nextInt();

			System.out.println("");

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}

	private void solveD() {
		Scanner scanner = null;
		int numN = 0;
		int numK = 0;
		int numS = 0;

		try {
			scanner = new Scanner(System.in);
			numN = scanner.nextInt();

			System.out.println("");

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}
}

Measured memory_bytes: 23892
N = gets.chomp.to_i
PN = gets.chomp.split(' ').map(&:to_i)[0..N]

puts (0.upto(N-3).reduce(0) do |count, i|
  count += 1 if ( PN[i] < PN[i+1] && PN[i+1] < PN[i+2] ) || ( PN[i] > PN[i+1] && PN[i+1] > PN[i+2] )
  count
end)


Measured memory_bytes: 1788
#include<iostream>
#include<stdio.h>
#include<cmath>
#define INF 9999999
using namespace std;
int n,t[10][10],a,b,c,d,flg[10],sum,mini,miniNo;
int main(){
	while(1){
		for(int i=0;i<10;i++){
			for(int j=0;j<10;j++){
				t[i][j]=INF*(j!=i);
			}
			flg[i]=0;
		}
		cin>>n;
		if(n==0)break;
		for(int i=0;i<n;i++){
			cin>>a>>b>>c;
			t[a][b]=t[b][a]=c;
			flg[a]=flg[b]=1;
		}
		for(int k=0;k<10;k++){
			for(int i=0;i<10;i++){
				for(int j=0;j<10;j++){
					t[i][j]=min(t[i][j],t[i][k]+t[k][j]);
				}
			}
		}
		mini=INF;
		for(int i=0;i<10;i++){
			if(flg[i]){
				sum=0;
				for(int j=0;j<10;j++){
					if(t[i][j]!=INF){
						sum+=t[i][j];
					}
				}
				if(mini>sum){
					mini=sum;
					miniNo=i;
				}
			}
		}
		cout<<miniNo<<" "<<mini<<endl;

	}
			return 0;
}

Measured memory_bytes: 1160
import sys
N=int(input())
for h in range(1,3501):
    for n in range(1,h):
        a = h*n*N
        b = -(n+h)*N + 4*h*n
        if b !=0:
            if a % b ==0 and a*b>0:
                print(h,n,a//b)
                sys.exit()

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

int main() {
  int N,K;

  cin >> N;
  cin >> K;

  int x[N];
  int sum=0;

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

  for (int i=0; i<N; i++) {
      if (2*x[i] <= K) {
          sum += 2*x[i];
      } else {
          sum += 2*(K-x[i]);
      }
  }   
  cout << sum << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IO ios::sync_with_stdio(false), cin.tie(0)
typedef long long ll;

int main()
{
    string s;
    cin >> s;
    int len = s.length();
    while (len--)
    {
        cout << "x";
    }
    cout << endl;
}

Measured memory_bytes: 256
using System;

class Program
{
    static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        string[] s = Console.ReadLine().Split(' ');
        int[] a = new int[n];
        for(int i = 0;i < a.Length; i++)
        {
            a[i] = int.Parse(s[i]);
        }

        Sort sort = new Sort();
        sort.insertionsort(a);
    }
}

class Sort
{
    public void insertionsort(int[] a)
    {
        foreach (int x in a)
        {
            if (x != a[a.Length - 1])
                Console.Write("{0} ", x);
            else
                Console.WriteLine("{0}", x);
        }
        for (int i = 1; i < a.Length; i++)
        {
            int v = a[i];
            int j = i - 1;
            while (j >= 0 && a[j] > v)
            {
                a[j + 1] = a[j];
                j--;
            }
            a[j + 1] = v;
            foreach (int x in a)
            {
                if (x != a[a.Length - 1])
                    Console.Write("{0} ", x);
                else
                    Console.WriteLine("{0}", x);
            }
        }
    }
}

Measured memory_bytes: 9176
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
typedef long long int ll;
ll s[100010];
ll t[100010];
int main(){
	int n,k; cin >>n>>k;
	vector<ll> a(n);
	for(int i=0;i<n;i++){
		cin >>a[i];
	}
	for(int i=0;i<n;i++){
		s[i+1]=s[i]+a[i];
		t[i+1]=t[i]+max((ll)0,a[i]);
	}
	ll ans=s[n];
	for(int i=0;i<=n-k;i++){
		ans=max(t[i]+(t[n]-t[i+k])+s[i+k]-s[i],ans);
		ans=max(t[i]+(t[n]-t[i+k]),ans);
	}
	cout << ans << endl;
}

Measured memory_bytes: 2688
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  int k=0;
  cin>>s;
  for(int i=0;i<6;i++){
    (s.at(i)=='1'?k+=1:k+=0);
  }
  cout<<k;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdlib>
#define rep(i,N) for(ll i=0;i<N;i++)
typedef long long int ll;
using namespace std;
using vl=vector<ll>;

ll N,H,ans_x,ans_y,ans_h;

ll get_h(ll x,ll y,ll c_x,ll c_y,ll H){
    return max(H-abs(x-c_x)-abs(y-c_y),(ll)0);
}

void calc(vl x,vl y,vl h){
   ll c;
   rep(i,N){
        if(h[i]!=0){
            c=i;
            break;
        }
    }
    rep(c_x,101){
        rep(c_y,101){
            int flag=1;
            H=h[c]+abs(x[c]-c_x)+abs(y[c]-c_y);
            rep(i,N){
                if(h[i]!=get_h(x[i],y[i],c_x,c_y,H)){
                    flag=0;
                    break;
                }
            }
            if(flag==1){
                ans_x=c_x;
                ans_y=c_y;
                ans_h=H;
                return;
            }
        }
    }
}

int main(){
    cin>>N;
    vl x(N),y(N),h(N);
    rep(i,N){
        cin>>x[i]>>y[i]>>h[i];
    }
    calc(x,y,h);
    cout<<ans_x<<" "<<ans_y<<" "<<ans_h<<endl;             
    
    return 0;
}

Measured memory_bytes: 256