akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) sort((c).rbegin(),(c).rend())
#define UNIQUE(c) SORT(c); (c).erase(unique((c).begin(), (c).end()), (c).end());
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
const double INF = 1e7;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
#define CLR(a) memset((a), 0 ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;


const int MOD = 1e9 + 7;


void solve(LL H, LL W, LL K){
	int dp[H + 1][W];
	CLR(dp);
	dp[0][0] = 1;
	FOR(i, 1, H + 1) {
		REP(j, 1 << (W - 1)) {
			if (j & (j << 1)) {
				continue;
			}
			REP(k, W) {
				if (k < (W - 1) && j & (1 << k)) {
					dp[i][k + 1] += dp[i - 1][k];
					dp[i][k + 1] %= MOD;
				} else if (k > 0 && j & (1 << (k - 1))) {
					dp[i][k - 1] += dp[i - 1][k];
					dp[i][k - 1] %= MOD;
				} else {
					dp[i][k] += dp[i - 1][k];
					dp[i][k] %= MOD;
				}
			}
		}
	}
	cout << dp[H][K - 1] << endl;
}


int main(){	
	LL W;
	LL H;
	LL K;
	scanf("%lld",&H);
	scanf("%lld",&W);
	scanf("%lld",&K);
	solve(H, W, K);
	return 0;
}



Measured memory_bytes: 256
s = input()
q = int(input())
ansList = [""] * (2 * 10 ** 5 * 2 + 1)
last = 2 * 10 ** 5
first = 2 * 10 ** 5 - 1
for x in range(len(s)):
    ansList[last] = s[x]
    last += 1
isReverce = False
for x in range(q):
    query = list(map(str, input().split()))
    if query[0] == "1": isReverce = not isReverce
    else:
        if (query[1] == "1" and isReverce == False) or (query[1] == "2" and isReverce == True):
            ansList[first] = query[2]
            first -= 1
        else:
            ansList[last] = query[2]
            last += 1
ans = "".join(ansList)
if isReverce == False: print(ans)
else: print(ans[::-1])


Measured memory_bytes: 7412
package main

import (
	"fmt"
)

func main() {
	var S, T, U string
	var A, B int
	fmt.Scan(&S, &T)
	fmt.Scan(&A, &B)
	fmt.Scan(&U)

	if S == U {
		A = A - 1
	}
	if T == U {
		B = B - 1
	}
	fmt.Println(A, B)
}


Measured memory_bytes: 512
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

    public static void main(String[] args) throws Exception {
        int N = Integer.parseInt(br.readLine().trim());
        int total = 0;
        int[] lr;
        for(int i=0; i<N; i++){
            lr = inputval();
            total += lr[1]-lr[0]+1;
        }
        System.out.println(total);
    }


    static int[] inputval() throws Exception {
        String[] strarray = br.readLine().trim().split(" ");
        int[] intarray = new int[strarray.length];
        for (int i = 0; i < intarray.length; i++) {
            intarray[i] = Integer.parseInt(strarray[i]);
        }
        return intarray;
    }

    static void array_sout(int[][] array) {
        for (int i = 0; i < array.length; i++) {
            for (int j = 0; j < array[0].length; j++) {
                System.out.print(array[i][j] + " ");
            }
            System.out.println();
        }
    }

    static void array_sout(int[] array) {
        for (int i = 0; i < array.length; i++) {
            System.out.print(array[i] + " ");
        }
        System.out.println();
    }
}

Measured memory_bytes: 22356
#include <iostream>
#include <set>
using namespace std;
typedef long long ll;

int main() {
	ll n, x; int m; cin >> n >> x >> m;
	set<ll> s; ll res = 0;
	ll cur = x; while (!s.count(cur)) {
		s.insert(cur); res += cur;
		cur = (cur * cur) % m;
	}
	set<ll> t; ll cycle = 0;
	while (!t.count(cur)) {
		t.insert(cur); cycle += cur;
		cur = (cur * cur) % m;
	}

	if (n <= (int)s.size()) {
		res = 0; while (n--) { res += x; x = (x * x) % m; }
		cout << res << '\n'; return 0;
	}
	n -= (int)s.size(); res += (n / t.size())*cycle;
	x = cur; n %= t.size();
	while (n--) { res += x; x = (x * x) % m; }
	cout << res << '\n';
	cin.ignore(2); return 0;
}

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

void solve(long long N, long long K, long long h[]){
	sort(h, h+N);
	long long res = 1000000000;
	for (int i = 0; i < N-K+1; i++) {
		if(res > h[i+K-1] - h[i]) res = h[i+K-1] - h[i];
	}
	printf("%lld\n", res);
}

int main(){
	long long K;
	long long N;
	scanf("%lld",&N);
	long long h[N-1+1];
	scanf("%lld",&K);
	for(int i = 0 ; i <= N-1 ; i++){
		scanf("%lld",&h[i]);
	}
	solve(N, K, h);
	return 0;
}


Measured memory_bytes: 1152
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(false);cin.tie(0);
using namespace std;
typedef long long ll;
const ll mod=(1e9+7);
int main(){IOS;
	int n;
	cin>>n;
	vector<ll>a(n);
	ll sol=0;
	for(int i=0;i<n;i++){
		cin>>a[i];
		sol+=a[i];
   if(sol>mod)
   sol%=mod;}
		ll sum=0;
		for(int i=0;i<n;i++){
		    sol-=a[i];
             if(sol<0)
             sol+=mod;
				  sum+=ll(a[i]*(sol))%mod;}
	
				  cout<<sum%mod<<endl;}

Measured memory_bytes: 4748
N,A,B,C = list(map(int, input().split()))
s = [input() for i in range(N)]

u = ["A","B","C"]
ss = ["BC","AC","AB"]
t = [A,B,C]
trace = []
ans = "Yes"
for i in range(N):
  idx = ss.index(s[i])
  if t[(idx+1)%3] == 0 and t[(idx+2)%3] == 0:
    ans = "No"
    break
  elif t[(idx+2)%3] == 0:
    t[(idx+1)%3] -= 1
    t[(idx+2)%3] += 1
    trace.append(u[(idx+2)%3])
  elif t[(idx+1)%3] == 0:
    t[(idx+1)%3] += 1
    t[(idx+2)%3] -= 1
    trace.append(u[(idx+1)%3])
  elif i+1<N and s[i+1] == ss[(idx+1)%3]:
    t[(idx+1)%3] -= 1
    t[(idx+2)%3] += 1
    trace.append(u[(idx+2)%3])
  else:
    t[(idx+1)%3] += 1
    t[(idx+2)%3] -= 1
    trace.append(u[(idx+1)%3])
print(ans)
if ans == "Yes":
  for v in trace:
    print(v)

Measured memory_bytes: 17088
n = int(input())
primes = []
isprime = [0] * 2 + [1] * 60000
for i in range(2,60000):
    if isprime[i] == 1:
        primes.append(i)
        for j in range(2,60000//i):
            isprime[i*j] = 0
prime2 = []
for p in primes:
    if len(prime2) > 60:
        break
    if p % 5 == 2:
        prime2.append(p)
for i in range(n):
    print(prime2[i], end = ' ')
print()


Measured memory_bytes: 3956
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;
#define int long long int

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

Measured memory_bytes: 256
#include<stdio.h>

int main(void){
	int a,b;
	scanf("%d %d",&a,&b);
	
	if(a<b){
		printf("a < b\n");
	}
	if(a>b){
		printf("a > b\n");
	}
	if(a==b){
		printf("a == b\n");
	}
	return 0;
}




Measured memory_bytes: 2040
#pragma gcc optimize("Ofast")

#include "bits/stdc++.h"
using namespace std;
typedef int64_t lld;
typedef pair<int,int> pii;
typedef pair<lld,lld> pll;
typedef pair<int,pll> pip;
typedef pair<pll,int> ppi;
typedef pair<lld,pll> plp;
typedef pair<pll,lld> ppl;
typedef pair<pll,pll> ppp;
template<typename T>
using maxHeap = priority_queue<T,vector<T>,less<T>>;
template<typename T>
using minHeap = priority_queue<T,vector<T>,greater<T>>;
#define ff first
#define ss second
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define endl '\n'
#define jizz cin.tie(0);cout.tie(0);ios::sync_with_stdio(0);
inline void input(int &_x) {
    _x = 0;
    int _tmp = 1; char _tc = getchar();
    while((_tc < '0' || _tc > '9') && _tc != '-') _tc = getchar();
    if(_tc == '-') _tc = getchar(), _tmp = -1;
    while(_tc >= '0' && _tc <= '9') _x = _x*10+(_tc-48), _tc = getchar();
    _x *= _tmp;
}
inline void output(int _x) {
    char _buff[20]; int _f = 0;
    if(_x == 0)putchar('0');
    while(_x > 0)
    {
        _buff[_f++] = _x%10+'0';
        _x /= 10;
    }
    for(_f-=1; _f >= 0; _f--)
        putchar(_buff[_f]);
    putchar('\n');
}
template<typename Iter>
ostream& _out(ostream &s, Iter b, Iter e) {
    s<<"[";
    for ( auto it=b; it!=e; it++ ) s<<(it==b?"":" ")<<*it;
    s<<"]";
    return s;
}
template<class T1,class T2>
ostream& operator<<(ostream& out, pair<T1,T2> p) {
    return out << '(' << p.first << ", " << p.second << ')';
}
template<typename T>
ostream& operator <<( ostream &s, const vector<T> &c ) {
     return _out(s,c.begin(),c.end());
 }
#ifdef erd1
    #define pprint(x) cerr<<__PRETTY_FUNCTION__<<":"<<__LINE__<<" - "<<(#x)<<"="<<(x)<<endl
#else
    #define pprint(x)
#endif

const int mod = 1000000007;
// code starts here
int invmod(int a, int b = mod, int s0 = 1, int s1 = 0){
    return b? invmod(b, a%b, s1, (s0-(lld)(a/b)*s1%mod+mod)%mod) : s0;
}

int fpow(int a, int b){
    int ans = 1;
    do if(b&1) ans = (lld)ans * a %mod;
    while(a = (lld)a*a%mod, b>>=1);
    return ans;
}

vector<int> fact, ifact, dp;
inline void MOD(int& x){if(x > mod)x-=mod;}
signed main(){
    int n, a, b, c, d;
    cin >> n >> a >> b >> c >> d;
    fact.resize(n+1); ifact.resize(n+1); fact[0] = ifact[0] = 1;
    for(int i = 1; i <= n; i++)ifact[i] = invmod(fact[i] = (lld)fact[i-1]*i%mod);
    dp.resize(n+1);
    dp[0] = 1;
    for(int j = a; j <= b; j++)
        for(int i = n; i >= 1; i--)
            for(int k = c; k <= d && j*k <= i; k++)
                MOD(dp[i] += (lld)dp[i-j*k]*fact[i]%mod*ifact[i-j*k]%mod*invmod(fpow(fact[j], k))%mod*ifact[k]%mod);
    cout << dp[n] <<endl;
}


Measured memory_bytes: 256
import sys
import itertools


input = sys.stdin.readline


def fact(n):
    res = 1
    for i in range(n):
        res *= n - i
    return res


def main():
    dst_sum = 0
    for p in itertools.permutations(T):
        for i in range(1, N):
            px, py = p[i-1]
            cx, cy = p[i]
            dst_sum += ((cx-px)**2 + (cy-py)**2)**0.5
    print(dst_sum/fact(N))


if __name__ == "__main__":
    N = int(input())
    T = [tuple(map(int, input().split())) for _ in range(N)]
    main()


Measured memory_bytes: 3188
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<utility>
#include<stack>
#include<queue>
#include<map>

#define se second

using namespace std;

map<int,int> mp;

int main()
{
    //    freopen("input.in", "r", stdin);
    
    int n; cin >> n;
    int hit = 0;
    while(n--)
    {
        int a;
        cin >> a;
        mp[a]++;
    }
    
    
    for(auto x : mp)
        if(x.se&1)
            hit++;
    
    cout << hit << "\n";
}


Measured memory_bytes: 4992
/*
 Author: LargeDumpling
 Email: LargeDumpling@qq.com
 Edit History:
	2017-08-06	File created.
*/

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
int H,W,n;
int a[10050],koloro[105][105];
int main()
{
	//freopen("code.in","r",stdin);
	//freopen("code.out","w",stdout);
	int now=1;
	scanf("%d%d%d",&H,&W,&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	for(int i=1;i<=H;i++)
		if(i&1) for(int j=1;j<=W;j++)
		{
			koloro[i][j]=now;
			a[now]--;
			if(!a[now]) now++;
		}
		else for(int j=W;j;j--)
		{
			koloro[i][j]=now;
			a[now]--;
			if(!a[now]) now++;
		}
	for(int i=1;i<=H;i++)
	{
		for(int j=1;j<=W;j++)
			printf("%d ",koloro[i][j]);
		putchar('\n');
	}
	fclose(stdin);
	fclose(stdout);
	return 0;
}


Measured memory_bytes: 384
N,K = map(int,input().split())
A =[0]*K
for k in range(K):
    d = int(input())
    A[k] = list(map(int, input().split()))

import itertools


judge_list = set(list(itertools.chain.from_iterable(A)))
count=0
for i in range(N):
    if (i+1) in judge_list:
        continue
    else:
        count+=1

print(count)


Measured memory_bytes: 9192
#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define ii pair<int,int>
#define F first
#define S second
#define pb push_back
#define pf push_front
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define fore(i,a,b) for(int i = a;i < b; i+= 1)
#define forr(i,a) for(int i = a; i >= 0; i--)
#define fori(i,m) for(auto i = m.begin(); i != m.end(); i++) 
#define sz(s) int(s.size())
#define cls(a,car) memset(a,car,sizeof (a))
using namespace std;
typedef long long ll;
const int N = 2 * 1e5 + 5;
const ll mod = 1e9 + 7;
const int INF = INT_MAX;
const ll INFCAD  = ll(INT_MAX) * 2 + 1;
//freopen("","r",stdin);
//freopen("","w",stdout);
int main(){
    int n;
    ll mn = (1LL << 62);
    cin >> n;
    vector<ll> v(n);
    for(auto  &i : v)
        cin >> i;
    fore(i,1,100000){
        ll aux = 0;
        fore(j,0,n)
            aux += (v[j] - i) * (v[j] - i);
        mn = min(aux,mn);
    }
    cout << mn << '\n';
    return 0;
}

Measured memory_bytes: 256
alias Edge = Tuple!(long, "to", long, "cost");
long[] dijkstra(in Edge[][] tree, long start) {
	alias PriorityQueue = BinaryHeap;

	auto V = tree.length;
	auto dist = new long[V];
	fill(dist, 1L<<60);

	auto queue = new PriorityQueue!(Array!Edge, "a.cost >= b.cost")();
	dist[start] = 0;
	queue.insert(Edge(start, 0));
	while(!queue.empty) {
		auto p = queue.front();
		long v = p.to, cost = p.cost;
		queue.popFront();
		if(dist[v] < cost) continue;
		foreach(const ref Edge e; tree[v]) {
			if(dist[v] + e.cost < dist[e.to]) {
				dist[e.to] = dist[v] + e.cost;
				queue.insert(Edge(e.to, dist[e.to]));
			}
		}
	}
	return dist;
}

void main() {
	auto N = ri;
	auto tree = new Edge[][](N, 0);
	foreach(i; 0..N-1) {
		auto ip = readAs!(int[]), a = ip[0], b = ip[1], c = ip[2];
		a--; b--;
		tree[a] ~= Edge(b, c);
		tree[b] ~= Edge(a, c);
	}
	auto ip2 = readAs!(int[]), Q = ip2[0], K = ip2[1];
	K--;
	auto dist = dijkstra(tree, K);
	foreach(i; 0..Q) {
		auto ip3 = readAs!(int[]), x = ip3[0], y = ip3[1];
		x--; y--;
		writeln(dist[x] + dist[y]);
	}
}

// ===================================

import std.stdio;
import std.string;
import std.functional;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}

Measured memory_bytes: 31996
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;

v(bool) visited;

vi d;
vi* dijkstra(v(vp) &G,int V,int s) {
// G[f][i] = P(t,c) means that from `f` to `t` 's cost is `c` 
  d = vi(V,INF);
  priority_queue<P,vp, greater<P>> que;
  d[s] = 0;
  que.push(P(0,s));
  while(!que.empty()) {
    P p = que.top();
    que.pop();
    int tar = p.second;
    if(d[tar] < p.first) continue;
    rep(i,sz(G[tar])) {
      P e = G[tar][i];
      if(d[e.first] == INF) {
        visited[e.first] = true; 
        d[e.first] = d[tar] + e.second;
        que.push(P(d[e.first],e.first));
        continue;
      }
      if(d[e.first] == d[tar] + e.second) {
        continue;
      }
      return NULL;
    }
  }
  return &d;
}
  
int main() {
  int N,M;
  cin >> N >> M;
  vv(P) G(N);
  set<int> s;
  rep(i,M) {
    int l,r,d;
    cin >> l >> r >> d;
    l--;
    r--;
    s.insert(l);
    s.insert(r);
    G[l].push_back(P(r,d));
    G[r].push_back(P(l,-d));
  }
  visited = v(bool)(N,false);
  vi* res;
  rep(i,N) {
    if(!visited[i] && s.count(i) > 0) {
      visited[i] = true;
      res = dijkstra(G,N,i);
      if(res == NULL) {
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;
  return 0;
}

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

ll k, ans, a, b;

int main(){
    cin >> k >> a >> b;
    if (a + 1 >= b || a > k - 1) ans = k + 1; 
    else k -= a + 1, ans = b + (b - a) * (k / 2) + k % 2;
    cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

class Solver {
    void solve(Scanner sc) {
        int N = sc.nextInt();
        int[] difficulty = new int[N];
        for (int i = 0; i < N; i++) {
            difficulty[i] = sc.nextInt();
        }
        Arrays.sort(difficulty);
        int a = difficulty[(difficulty.length - 1) / 2];
        int b = difficulty[(difficulty.length - 1) / 2 + 1];
        System.out.println(b - a);
    }
}

class Main {
    public static void main(String... args) {
        Scanner in = new Scanner(System.in);

        new Solver().solve(in);

        in.close();
    }
}

Measured memory_bytes: 52480
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <map>
#include <set>
using namespace std;
#define F first
#define S second

constexpr int kN = int(2E5 + 10), kInf = int(1E9 + 10);

int A[kN], B[kN], ans[kN];

int main() {
	int h, w;
	map<int, pair<int, int>> ma; // start, (end, start val)
	map<int, pair<int, int>> :: iterator u;
	set<pair<int, int>> distance;
	pair<int, pair<int, int>> st, nxt;
	scanf("%d%d", &h, &w);
	for (int i = 1; i <= h; i++) scanf("%d%d", &A[i], &B[i]);
	for (int i = 1; i <= w; i++) ma.insert({i, {i, 0}});
	for (int i = 1; i <= w; i++) distance.insert({0, i});
	
	for (int i = 1; i <= h; i++) {
		//printf("i = %d\n", i);
		//printf("ma : ");
		//for (pair<int, pair<int, int>> j : ma) printf(" (%d, (%d, %d))", j.F, j.S.F, j.S.S);
		//printf("\n");
		u = ma.lower_bound(A[i]);
		if (u == ma.begin()) st = {0, {0, kInf}};
		else {
			u = prev(u);
			st = *u;
			ma.erase(u);
		}
		//printf("st = (%d, (%d, %d))\n", st.F, st.S.F, st.S.S);
		u = ma.lower_bound(A[i]);
		while (u != ma.end() && u -> F <= B[i]) {
			//printf("u = (%d, (%d, %d))\n", u -> F, u -> S.F, u -> S.S);
			if (u -> S.F > B[i]) {
				nxt = {B[i] + 1, {u -> S.F, B[i] + 1 - u -> F + u -> S.S}};
				distance.erase({u -> S.S, u -> F});
				ma.erase(u);
				distance.insert({nxt.S.S, nxt.F});
				ma.insert(nxt);
			}
			else {
				distance.erase({u -> S.S, u -> F});
				ma.erase(u);
			}
			u = ma.lower_bound(A[i]);
		}
		if (st.F) ma.insert({st.F, {max(st.S.F, B[i]), st.S.S}});
		if (!distance.empty()) ans[i] = distance.begin() -> F + i;
		else ans[i] = -1;
	}
	for (int i = 1; i <= h; i++) printf("%d\n", ans[i]);
}


Measured memory_bytes: 27500
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {
	static long num = 0;
	static long patty = 0;
	static long n = 0;
	static long x = 0;
	static Map<Long,Long> numMap = new HashMap<Long,Long>();
	static Map<Long,Long> pattyMap = new HashMap<Long,Long>();
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		n = sc.nextLong();
		x = sc.nextLong();

		numMap.put(0L,1L);
		pattyMap.put(0L,1L);
		for (long i = 1 ; i <= 50 ; i++) {
			numMap.put(i, numMap.get(i-1)*2+3);
			pattyMap.put(i, pattyMap.get(i-1)*2+1);
		}

		level(n);
		// 出力
		System.out.println(patty);
		sc.close();
	}

	private static boolean level(long lev) {
		if ( (x - num) > numMap.get(lev)) {
			num += numMap.get(lev);
			patty += pattyMap.get(lev);
			return true;
		}

		if (lev == 0) {
			num++;
			patty++;
			if (num == x) return false;
			return true;
		} else {
			num++;
			if (num == x) return false;

			boolean b = level(lev - 1);
			if (b == false) return false;

			num++;
			patty++;
			if (num == x) return false;

			b = level(lev - 1);
			if (b == false) return false;

			num++;
			if (num == x) return false;

			return true;
		}
	}
}


Measured memory_bytes: 21716
import java.util.Scanner;

public class Main{
  public static void main(String[] args){
    int ans = 0;
    Scanner sc = new Scanner(System.in);
    char[] s = sc.nextLine().toCharArray();
    for(int cnt = 0; cnt < s.length ; cnt++){
      if(s[cnt] == '1'){
        ans++;
      }
    }
    System.out.println(ans);
    sc.close();
  }
}

Measured memory_bytes: 35536
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int[][][] dormitory = new int[4][3][10];
    int n = sc.nextInt();
    for (int i = 0; i < n; i++) {
      int b = sc.nextInt();
      int f = sc.nextInt();
      int r = sc.nextInt();
      int v = sc.nextInt();
      dormitory[b - 1][f - 1][r - 1] += v;
    }
    sc.close();
    for (int i = 0; i < dormitory.length; i++) {
      for (int j = 0; j < dormitory[i].length; j++) {
        for (int k = 0; k < dormitory[i][j].length; k++) {
          System.out.printf(" %d", dormitory[i][j][k]);
        }
        System.out.println();
      }
      if (i != 3)
        System.out.println("####################");
    }
  }
}


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

int main() {
  unsigned long long K,A,B,rest;
  cin >> K >> A >> B;
  
  if(B>(A+1)){
  	if(((K+1)/(A+2))>0){
  		rest=(K+1)-(A+2);
  		cout << B+(rest/2)*(B-A)+(rest%2) << endl;
	}else{
  	cout << K+1 << endl;		
	}
  }else{
  	cout << K+1 << endl;
  }
  return 0;
}


Measured memory_bytes: 256
N = gets.chomp.to_i
X = gets.chomp.split.map(&:to_i)
# S = gets.chomp.chars

# Calculate in greedy way.
minX = X.min
maxX = X.max

minCost = 10000000
(minX.upto(maxX)).each do |p|
  cost = 0
  0.upto(N-1).each do |i|
    cost += (X[i] - p) * (X[i] - p) 
  end
  if (cost < minCost)
    minCost = cost
  end
end

p minCost
    

Measured memory_bytes: 1788
#include<bits/stdc++.h>
#define MOD 1000000007
#define MOD2 1000000006
#define TEMPMOD1 998244353
#define TEMPMOD2 998244352
#define INF 1000000000000000007
#define NEGINF -1000000000000000007
#define vll vector<ll> 
#define vvll vector<vector<ll>>
#define pll pair<ll,ll>
#define plll pair<pll,ll>
#define vpll vector<pll>
using namespace std;
typedef long long int ll;


int main()
{
    
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
    ll w,h,x,y;
    cin>>w>>h>>x>>y;
    ll ans=w*h;
    double res=(double)ans/2.000000;
    if(w==(2*x) && h==(2*y))
    {
        cout<<fixed<<setprecision(8)<<res<<" 1";
    }
    else
    {
        cout<<fixed<<setprecision(8)<<res<<" 0";
    }
    return 0;
}

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

int main() {
	std::ios_base::sync_with_stdio(false);
	std::cin.tie(NULL);
	long long int a, b;
	long long int c, d;
	cin >> a >> b;
	c=a%b;
	d=abs(c-b);
	if(c>=d){
		cout << d;
	}else{
		cout << c;
	}
	return 0;
}

Measured memory_bytes: 256
x, y, a, b, c = [0] * 5
p, q, r = [[]] * 3

def format_input(filename = None):
	global x, y, a, b, c
	global p, q, r
	if filename == None:
		x, y, a, b, c = list(map(int, input().split()))
		p, q, r = [list(map(int, input().split())) for i in range(3)]

	elif filename == '__random__':
		from random import randint as rng
		x = rng(1, 10**5)
		y = rng(1, 10**5)
		a = rng(x, 10**5)
		b = rng(y, 10**5)
		c = rng(1, 10**5)
		p = [rng(1, 10**9) for i in range(a)]
		q = [rng(1, 10**9) for i in range(b)]
		r = [rng(1, 10**9) for i in range(c)]
		print(x, y, a, b, c)
		[print(' '.join(list(map(str, i)))) for i in [p, q, r]]

def get_answer():
	red = sorted(p)[-x:]
	green = sorted(q)[-y:]
	delicious_apples = sorted(red + green + r)[-(x+y):]
	return sum(delicious_apples)

if __name__ == '__main__':
	format_input()

	ans = get_answer()
	print(ans)


Measured memory_bytes: 23328
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

import static java.lang.Integer.parseInt;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = "";

		int[] ts = new int[3];

		while ((line = br.readLine()) != null && !line.isEmpty()) {
			StringTokenizer st = new StringTokenizer(line);
			int[] es = new int[3];
			for (int i = 0; i < 3; i++) {
				es[i] = parseInt(st.nextToken());
			}
			Arrays.sort(es);
			if (es[2] >= es[0] + es[1]) break;
			ts[typeIs(es)]++;
		}
		System.out.printf("%d %d %d %d\n", ts[0] + ts[1] + ts[2], ts[0], ts[1], ts[2]);
	}

	static int typeIs(int[] es) {
		int t = es[2] * es[2] - es[0] * es[0] - es[1] * es[1];
		return t == 0 ? 0 : t < 0 ? 1 : 2;
	}
}

Measured memory_bytes: 16924
#include<string>
#include<algorithm>
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
//	int a;
for(int i=1;i<10;i++)
{
for(int k=1;k<10;k++)
{cout<<i<<"x"<<k<<"="<<i*k<<endl;}
}
	return 0;
}

Measured memory_bytes: 3064
import java.util.*;
import java.io.*;
import java.math.*;

class Main {
	static String[][] map = new String[][] {{"a","i","u","e","o"},{"ka","ki","ku","ke","ko"},{"sa","si","su","se","so"},{"ta","ti","tu","te","to"},{"na","ni","nu","ne","no"},
		{"ha","hi","hu","he","ho"},{"ma","mi","mu","me","mo"},{"ya","","yu","","yo"},{"ra","ri","ru","re","ro"},{"wa","","nn","","wo"}};
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		char[] in = sc.next().toCharArray();
		for(int i = 0; i < in.length; i += 2) {
			int c = 0;
			switch(in[i+1]) {
			case 'T':c = 0; break;
			case 'L':c = 1; break;
			case 'U':c = 2; break;
			case 'R':c = 3; break;
			case 'D':c = 4; break;
			}
			if(in[i] == '0') {
				System.out.print(map[9][c]);
			}
			else {
				System.out.print(map[(in[i] - '0') - 1][c]);
			}
		}
		System.out.println();
		
	}
}

Measured memory_bytes: 17344
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
#define REP(i,n) for(i=0;i<n;i++)
struct branch{
	int n1, n2, w;
};
bool f(branch i, branch j){
	return (i.w > j.w);
}
int main(){
	while (1){
		int n,i;
		char c;
		cin >> n;
		if (n == 0) break;
		vector <int> T(n);
		REP(i,n) T[i] = i;

		int m;
		cin >> m;
		vector <branch> S(m);
		REP(i,m) cin >> S[i].n1 >> c>>S[i].n2 >> c>>S[i].w;

		sort(S.begin(), S.end(),f);

		int a = 0;
		while (S.size()){
			branch tmp = S.back();
			S.pop_back();
			int b = T[tmp.n1], c = T[tmp.n2];
			if (b != c){
				REP(i,n)
					if (T[i] == c) T[i] = b;
				a += tmp.w / 100 - 1;
			}
		}
		cout << a << endl;
	}
}

Measured memory_bytes: 1272
import sys
sys.setrecursionlimit(10**6)


def main(input, print):
    n, k = map(int, input().split())
    p = list(map(int, input().split()))
    p.sort()
    ans = 0
    for i in range(k):
        ans += p[i]
    print(ans)


if __name__ == '__main__':
    main(sys.stdin.readline, print)


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

#define rep(i,n) for(ll i = 0; i < n; i++)
#define per(i,n) for(ll i = n-1; i >= 0; i--)
#define REP(i,n) for(ll i = 1; i < n; i++)
#define PER(i,n) for(ll i = n; i >= 1; i--)
#define sz(x) int(x.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define endl '\n'
#define fi first
#define se second
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vii = vector<vi>;
using vl = vector<ll>;
using vll = vector<vl>;
using vs = vector<string>;
using vb = vector<bool>;
using vc = vector<char>;
using vcc = vector<vc>;
using vP = vector<P>;
using vPP = vector<vP>;
using vPl = vector<Pl>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll &a, const ll &b){return ((a)+(b)-1)/b;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }



int main(){
  string s;
  cin >> s;
  vector<bool> seen(26);
  rep(i,sz(s)) {
    int c = s[i]-'a';
    if(seen[c]) {
      cout << "no" << endl;
      return 0;
    }
    seen[c] = true;
  }
  cout << "yes" << endl;
}

Measured memory_bytes: 3572
#include <stdio.h>

int main(void)
{
    int num[5] = {100,100,100,100,100}, empty, i;
    scanf("%d%d%d", &num[0], &num[1], &num[2]);
    for (i = 0; i < 3; i++)
    {
        if (num[i] > num[i + 1])
        {
            empty = num[i];
            num[i] = num[i + 1];
            num[i + 1] = empty;
        }
        printf ("%d", num[0] * num[1] / 2);
        return (0);
    }
}


Measured memory_bytes: 128
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Linq;

namespace tmplete
{
    class InsertionSort
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[] str = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();//2つ以上のスペース区切り入力の取得
            Print(str);
            for(int i = 1; i < n; i++)
            {
                int key = str[i];
                int j = i - 1;
                while(j >= 0 && str[j] > key)
                {
                    str[j+1] = str[j];
                    j--;
                }
                str[j+1] = key;
                Print(str);
            }
        }

        public static void Print(IEnumerable<int> collection)
        {
            Console.WriteLine(string.Join(" ", collection.Select(i => i.ToString()).ToArray()));
        }
    }
}


Measured memory_bytes: 9764
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007

int main() {

  int N,M;
  cin >> N >> M;

  int x = 1900 * M + 100 * (N - M);
  for(int i = 0;i < M;i++) {
    x *= 2;
  }

  cout << x << endl;


}




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

int main(void){
    int N=5,U=1,W=4,E=3,D=6,S=2,sub=0;
    int n,i;
    int count=1;
    for(;;){
        N=5,U=1,W=4,E=3,D=6,S=2,sub=0,count=1;
        scanf("%d",&n);
        if(n==0)break;
        char a[10];//[10000]={0};
        for(i=0;i<n;i++){
            scanf("%s",a);
            if(strcmp(a,"North")==0)sub=N,N=U,U=S,S=D,D=sub,count+=U;
            else if(strcmp(a,"South")==0)sub=D,D=S,S=U,U=N,N=sub,count+=U;
            else if(strcmp(a,"East")==0)sub=E,E=U,U=W,W=D,D=sub,count+=U;
            else if(strcmp(a,"West")==0)sub=D,D=W,W=U,U=E,E=sub,count+=U;
            else if(strcmp(a,"Right")==0)sub=E,E=N,N=W,W=S,S=sub,count+=U;
            else if(strcmp(a,"Left")==0)sub=S,S=W,W=N,N=E,E=sub,count+=U;
            }
        printf("%d\n",count);
    }



	return 0;
}

Measured memory_bytes: 1032
import scala.io.StdIn.readInt

object Main {

  def find(y:Int):String = {
    var x = y
    while(x>0 && x%10!=3) {
        x = x/10
    }
    if(x%10 == 3) " "+y else ""
  }

  def call(i:Int, n:Int):Unit = {
    var str = ""
    for(i <- 1 to n) {
      if(i%3 == 0){
        print(" "+i)
      } else {
        print(find(i))
      }
    }
    println()
}

  def main(args: Array[String]) = {
    var n = readInt
    call(1,n)
  }

}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

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

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

ll t;
int n;
ll x[125252],y[125252];
ll sum[125252];

int main(){
  scanf("%lld%d",&t,&n);
  REP(i,n)scanf("%lld%lld",x+i,y+i);
  REP(i,n)sum[i+1]=sum[i]+(y[i]-x[i]);
  ll ans = 0;
  {
    int ed = 0;
    REP(i,n){
      ll st = x[i];
      while(ed<n && st+t >= y[ed])ed++;
      CHMAX(ans,sum[ed]-sum[i]+(ed<n?max(0ll,st+t-x[ed]):0));
    }
  }
  // swap(x,y);
  // REP(i,n)x[i]=-x[i],y[i]=-y[i];
  // reverse(x,x+n);
  // reverse(y,y+n);
  // REP(i,n)sum[i+1]=sum[i]+(y[i]-x[i]);
  // {
  //   int ed = 0;
  //   REP(i,n){
  //     ll st = x[i];
  //     while(ed<n && st+t >= y[ed])ed++;
  //     CHMAX(ans,sum[ed]-sum[i]+(ed<n?max(0ll,st+t-x[ed]):0));
  //   }
  // }
  printf("%lld\n",ans);
  return 0;
}

Measured memory_bytes: 3544
#include <iostream>
#include <map>
using namespace std;
map <int,bool> l;
int main(){

  int n,a,r=0;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>a;
    if(l[a]==false){
      l[a]=true;
      r++;
    } else {
      l[a]=false;
      r--;
    }
  }
  cout<<r<<endl;
  return 0;


}



Measured memory_bytes: 4864
fun main() {
    readLn().toInt()
    val a = readInts().map { it.toLong() }.sorted().reversed()
    var entrants = 0
    var currBest = 0
    var total = 0L
    while (entrants < a.size) {
        if (entrants > 0) {
            total += a[currBest]
            if (entrants % 2 == 1) currBest++
        }
        entrants++
    }

    println(total)
}

// Input Reader
private fun readLn() = readLine()!!

private fun readStrings() = readLn().trim().split(" ")
private fun readInts() = readStrings().map { it.toInt() }

Measured memory_bytes: 76444
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,s,t) for(int i = s ; i < t ; ++i)
#define ALL(a) a.begin(),a.end()
#define SORT(a) sort(ALL(a))
#define UNIQ(a) a.erase(unique(ALL(a)),a.end())
#define debug(a) cerr<<#a":="<<a<<endl
using LL = long long; template<class T> using V = vector<T>; template<class T> using VV = V<V<T>>;


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

	int H, W;
	cin >> H >> W;
	VV<int>a(H + 1, V<int>(W + 1, 0));
	FOR(i, 0, H) {
		FOR(j, 0, W) {
			cin >> a[i + 1][j + 1];
		}
	}
	LL ans = 0;
	VV<int>dp(H + 1, V<int>(W + 1, 0));
	FOR(i, 1, H + 1) {
		FOR(j, 1, W + 1) {
			if (a[i][j] == 1)dp[i][j] = 0;
			else dp[i][j] = min(dp[i - 1][j - 1], min(dp[i - 1][j], dp[i][j - 1])) + 1;
			ans = max(ans, (LL)dp[i][j]);
		}
	}

	cout << ans * ans << endl;

	return 0;
}


Measured memory_bytes: 18364
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define fi first
#define se second
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define pf push_front
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define SZ(x) (int)(x).size()
#define endl '\n'
#define FOR(a, b, c) for (auto(a) = (b); (a) < (c); ++(a))
#define ROF(a, b, c) for (auto(a) = (b); (a) > (c); --(a))
#define F0R(a, b) FOR ((a), 0, (b))
#define R0F(a, b) ROF ((a), (b), -1)
#define CEIL(a, b) ((a) + (b)-1) / (b)
#define SET(a, b) memset((a), (b), sizeof(a))
template <class t>
bool ckmin(t& a, const t& b) {
    return a > b ? a = b, true : false;
}
template <class t>
bool ckmax(t& a, const t& b) {
    return a < b ? a = b, true : false;
}
#ifndef DEBUG
#define DEBUG 0
#endif
#define dout \
    if (DEBUG) std::cerr
#define dvar(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
template <class a, class b>
ostream& operator<<(ostream& o, const pair<a, b>& p);
template <class T>
struct IsC {
    template <class C>
    static char test(typename C::const_iterator*);
    template <class C>
    static int test(...);
    static const bool value = sizeof(test<T>(0)) == sizeof(char);
};
template <>
struct IsC<string> {
    static const bool value = false;
};
template <class C>
typename enable_if<IsC<C>::value, ostream&>::type operator<<(ostream& o,
                                                             const C& c) {
    o << '[';
    for (auto it = c.begin(); it != c.end();)
        o << *it << (++it != c.end() ? ", " : "");
    return o << ']';
}
template <class a, class b>
ostream& operator<<(ostream& o, const pair<a, b>& p) {
    return o << '(' << p.fi << ", " << p.se << ')';
}

void solve() {
    string in;
    cin >> in;
    for (char c : in) {
	if (c == '?') cout << 'D';
	else cout << c;
    }
    cout << endl;
}

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

    int tt = 1;
    FOR (t, 1, tt + 1) {
	// cout << "Case #" << t << ": ";
	solve();
    }

    return 0;
}


Measured memory_bytes: 3776
#include <iostream>
#include <ios>
#include <vector>
#include <algorithm>
using namespace std;
long n, A[21] = {}, DP[21][2000] = {};

void createDP(){
	int MaxV = 0;
	for (int i = 1; i <= n; ++i){
		MaxV += A[i];
		DP[i][0] = DP[i][A[i]] = 1;
		for (int j = 1; j < 2000; ++j){
			if (DP[i - 1][j] == 1) DP[i][j] = 1;
			if (A[i] < j && DP[i - 1][j - A[i]] == 1) DP[i][j] = 1;
			if (MaxV < j)
				break;
		}
	}
}

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	long m, i, j, k;
	cin >> n;
	for (i = 1; i <= n; ++i)
		cin >> A[i];
	sort(A, A + n + 1);
	createDP();
	cin >> m;
	for (i = 0; i < m; ++i){
		cin >> k;
		cout << ((DP[n][k] == 1) ? "yes\n" : "no\n");
	}

	return 0;
}

Measured memory_bytes: 1296
#include<iostream>
#include<vector>
#include<string>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= (int)end; --i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return 0;}
template<typename T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return 0;}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, M;
    cin >> N >> M;
    vector<int> L(M), R(M);
    rep(i, 0, M) {
        cin >> L[i] >> R[i];
    }
    int l = 0, r = 1 << 30;
    rep(i, 0, M) {
        chmax(l, L[i]);
        chmin(r, R[i]);
    }
    cout << max(0, r - l + 1) << endl;
    return 0;
}

Measured memory_bytes: 1152
#include<stdio.h>

int eray[4]={1868,1912,1926,1989};
int eram[4]={9,7,12,1};
int erad[4]={8,30,25,8};
char *era[5]={"pre-meiji","meiji","taisho","showa","heisei"};

void prans(int i,int y,int m,int d){
  printf("%s",era[i]);
  if(i!=0){
    printf(" %d %d %d",y-eray[i-1]+1,m,d);
  }
  printf("\n");
}

void doit(int y,int m,int d){
  int i=0;
  int f=0;
  while((i<4)&&(f==0)){
    if(y<eray[i]){
      prans(i,y,m,d);
      f=1;
    }
    else if(y==eray[i]){
      if(m<eram[i]){
	prans(i,y,m,d);
	f=1;
      }
      else if(m==eram[i]){
	if(d<erad[i]){
	  prans(i,y,m,d);
	  f=1;
	}
      }
    }
    i++;
  }
  if(f==0){
    prans(4,y,m,d);
  }
}

int main(){
  int y,m,d;
  while(scanf("%d %d %d",&y,&m,&d)!=EOF){
    doit(y,m,d);
  }
  return 0;
}

Measured memory_bytes: 600
A = []
A.append(input().split())
A.append(input().split())
A.append(input().split())
N = int(input())
b = [input() for _ in range(N)]
 
# 2次元配列として処理
for i in range(N):
  for j in range(3):
    if b[i] in A[j]: A[j][A[j].index(b[i])] = True

if (A[0][0]==True and A[1][0]==True and A[2][0]==True) or (A[0][1]==True and A[1][1]==True and A[2][1]==True) or (A[0][2]==True and A[1][2]==True and A[2][2]==True) or (A[0][0]==True and A[0][1]==True and A[0][2]==True) or (A[1][0]==True and A[1][1]==True and A[1][2]==True) or (A[2][0]==True and A[2][1]==True and A[2][2]==True) or (A[0][0]==True and A[1][1]==True and A[2][2]==True) or (A[0][2]==True and A[1][1]==True and A[2][0]==True): print('Yes')
else: print('No')

Measured memory_bytes: 9144
#include<cstdio>
#include<iostream>
using namespace std;
typedef long long ll;
const int N=4e2+10;
const ll INF_ll=4611686018427387903;
int n,a[N];ll dp[N][N],pre[N];
int main(){
	scanf("%d",&n);
	for(register int i=1;i<=n;i++)scanf("%d",&a[i]);
	for(register int i=1;i<=n;i++)pre[i]=pre[i-1]+a[i];
	for(register int i=n;i;i--)
		for(register int j=i+1;j<=n;j++){
			dp[i][j]=INF_ll;
			for(register int p=i;p<j;p++)
				dp[i][j]=min(dp[i][j],dp[i][p]+dp[p+1][j]+pre[j]-pre[i-1]);
		}
	printf("%lld\n",dp[1][n]);
	return 0;
}

Measured memory_bytes: 1536
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
	#define eprintf(...) 42
#endif

#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define repp(i, m, n) for(int i = m, i##_len = (n); i < i##_len; ++i)
#define reprev(i, n) for(ll i = (n-1LL); i >= 0; --i)
#define all(x) (x).begin(), (x).end()
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; }
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <ll,ll> P;
typedef long double ld;

int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	string a, b;
	cin >> a >> b;
	rep (i, n) {
		cout << a[i] << b[i];
	}
	cout << "\n";
	return 0;
}

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

int main(){
	int n;
	cin>>n;
	
	vector<int> a(1e5,0);
	for(int i=0;i<n;i++){
		int b;
		cin>>b;
		a[b]++;
	}
	
	int ans=0;
	
	for(int i=0;i<1e5-2;i++){
		int sum=a[i]+a[i+1]+a[i+2];
		ans=max(ans,sum);
	}
	
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#include<string>
using namespace std;
#define int long long int


int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout<<setprecision(30)<<fixed;

	int n;
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++)
		cin>>a[i];
	int b[n];
	b[n-1]=a[n-1];
	int M=1e9+7;
	for(int i=n-2;i>=0;i--)
		b[i]=(b[i+1]+a[i])%M;
	int c=0;
	for(int i=0;i<n-1;i++)
	{
		c=(c+(b[i+1]*a[i])%M)%M;
	}
	cout<<c<<endl;
	return 0;
}


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

#define LLI long long int
LLI Xstar[1000005],Ystar[1000005],Xline[1000005],Yline[1000005],xx[1000005],yy[1000005];
LLI x,y,n,xans,yans,m,sum,j;

int main(){

    while(1){
        Xline[1000005]={0};
        Yline[1000005]={0};
    cin >> n;
    if(n==0)break;

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

    cin >> m;

    for(int i=0;i<m;i++){
        cin >> x >> y;
        xx[i]=x;
        yy[i]=y;
        Xline[x]=1;
        Yline[y]=1;
    }

    for(int i=0;i<m;i++){
            while(1){
            j++;
            if(j==n){
            xans=Xstar[0]-xx[i];
            yans=Ystar[0]-yy[i];
            break;
            }

            x=Xstar[0]-Xstar[j];
            y=Ystar[0]-Ystar[j];

            if(Xline[xx[i]-x]==1&&Yline[yy[i]-y]==1);
            else break;
        }
        if(j==n)break;
        else j=0;
    }

    cout << -xans << " " << -yans << endl;
    }

return 0;
}

Measured memory_bytes: 25740
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    N, A, B = map(int, readline().split())

    print(min(A, B), max(0, N - (N - A + N - B)))


if __name__ == '__main__':
    main()


Measured memory_bytes: 61604
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
k = int(input())

ABCDE = [a, b, c, d, e]
distance = max(ABCDE) - min(ABCDE)

if distance > k:
    ans = ':('
else:
    ans = 'Yay!'
    
print(ans)

Measured memory_bytes: 3064
package main
 
import (
    "bufio"
    "fmt"
    "os"
    "strconv"
)

func main(){
    
    var ans string
    s := nextString()
	for i := 0; i < len(s); i++ {
		c := string(s[i])
		switch c {
		case "0", "1":
			ans += c
		case "B":
			if ans != "" {
				ans = ans[0 : len(ans) - 1]
			}
		}
	}
	fmt.Println(ans)

}
 
/* templates */
 
func Max(a []int) int {
    r := a[0]
    for i := 0; i < len(a); i++ {
        if r < a[i] {
            r = a[i]
        }
    }
    return r
}
 
func Min(a []int) int {
    r := a[0]
    for i := 0; i < len(a); i++ {
        if r > a[i] {
            r = a[i]
        }
    }
    return r
}
 
func Sum(a []int) (r int) {
    for i := range a {
        r += a[i]
    }
    return r
}
 
func Abs(a float64) float64 {
    if a < 0 {
        return -a
    }
    return a
}
 
type Pair struct {
    a, b int
}
 
type Pairs []Pair
 
func (p Pairs) Len() int {
    return len(p)
}
 
func (p Pairs) Swap(i, j int) {
    p[i], p[j] = p[j], p[i]
}
 
func (p Pairs) Less(i, j int) bool {
    return p[i].b < p[j].b
}
 
var nextReader func() string
 
func init() {
    nextReader = NewScanner()
}
 
func NewScanner() func() string {
    r := bufio.NewScanner(os.Stdin)
    r.Buffer(make([]byte, 1024), int(1e+11))
    r.Split(bufio.ScanWords)
    return func() string {
        r.Scan()
        return r.Text()
    }
}

func nextString() string {
    return nextReader()
}
 
func nextInt64() int64 {
    v, _ := strconv.ParseInt(nextReader(), 10, 64)
    return v
}
 
func nextInt() int {
    v, _ := strconv.Atoi(nextReader())
    return v
}
 
func nextInts(n int) []int {
    r := make([]int, n)
    for i := 0; i < n; i++ {
        r[i] = nextInt()
    }
    return r
}

func nextStrings(n int) []string {
    r := make([]string, n)
    for i := 0; i < n; i++ {
        r[i] = nextString()
    }
    return r
}

func nextFloat64() float64 {
    f, _ := strconv.ParseFloat(nextReader(), 64)
    return f
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define pb push_back
#define Int long long
using namespace std;

const int MAXN=50005;
const int NAX=1005;
const long MOD=(long)(1e9+7);

Int N,M,K;
Int X,Y,Z;
Int perform(Int x){
    return (x*(x+1))/2LL;
}
vector<Int> A;


int main()
{
    cin>>N>>M>>K>>X;
    cout<<max((N*M),(X*K));
     
}


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

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

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

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

int main()
{
    int N, K;
    string S;
    cin >> N >> S >> K;
    REP(i, N)
    {
        if (S[i] == S[K - 1])
            continue;
        S[i] = '*';
    }
    cout << S << endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
a = [list(map(int, input().split())) for _ in range(2)]

sum_cur = a[0][0] + sum(a[1])
ans = sum_cur
for i in range(1, n):
    sum_cur = sum_cur+a[0][i]-a[1][i-1]
    ans = max(ans, sum_cur)
print(ans)


Measured memory_bytes: 3060