akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>

using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main()
{
	int l;
	cin>>l;
  if(l==2){
    cout<<2<<" "<<2<<endl;
    cout<<1<<" "<<2<<" "<<0<<endl;
    cout<<1<<" "<<2<<" "<<1<<endl;
    return 0;
  }
  l--;
	int l0=l;
	int c[20];
	int d=0;
	while(l>0){
		c[d]=l%2;
		d++;
		l/=2;
	}
	vector<P> v[20];
	for(int i=0; i<d-2; i++){
		v[i].push_back(P(i+1, 0));
		v[i].push_back(P(i+1, (1<<i)));
	}
	v[d-2].push_back(P(d-1, l0-(1<<(d-1))+1));
	v[d-2].push_back(P(d-1, l0-(1<<(d-1))+1+(1<<(d-2))));
	l0-=(1<<(d-1));
	for(int i=d-2; i>=0; i--){
		if(c[i]==0) continue;
		l0-=(1<<i);
		v[i].push_back(P(d-1, l0+1));
	}
  v[0].push_back(P(d-1, 0));
	int m=0;
	for(int i=0; i<d; i++){
		m+=(v[i].size());
	}
	cout<<d<<" "<<m<<endl;
	for(int i=0; i<d; i++){
		for(int j=0; j<v[i].size(); j++){
			cout<<i+1<<" "<<v[i][j].first+1<<" "<<v[i][j].second<<endl;
		}
	}
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;

class Program
{
	static int n;
	static int m;
	static int[] cs;
	static int[] minCounts;

	static void Main(string[] args)
	{
		string[] nm = Console.ReadLine().Split();

		n = int.Parse(nm[0]);
		m = int.Parse(nm[1]);

		cs = Console.ReadLine().Split().Select(str => int.Parse(str)).ToArray();

		minCounts = new int[50001];

		// コイン1枚で実現できる金額には枚数1を入れておく
		for (int ci = 0; ci < m; ci++)
		{
			minCounts[cs[ci]] = 1;
		}

		// 1から順番に辿る
		for (int i = 1; i <= n; i++)
		{
			minCounts[i] = GetMinCounts(i);
		}
		System.Console.WriteLine(minCounts[n]);
	}

	// Kを実現する最小コイン枚数を返す
	static int GetMinCounts(int k)
	{
		// 記録済み
		if (minCounts[k] > 0) return minCounts[k];

		// 頭と後ろからの組み合わせで最小値を計算
		int min = k;
		for (int j = 1; j < k; j++)
		{
			if (k - j < j) return min;
			int current = minCounts[k - j] + minCounts[j];
			if (current < min) min = current;
		}
		return min;
	}
}



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

using namespace std;

typedef long long llint;

int main() {
  int n;
  cin >> n;
  vector<llint> a(n + 1), b(n);
  for (int i = 0; i < n + 1; i++) {
    cin >> a[i];
  }

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

  llint ans = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] < b[i]) {
      b[i] -= a[i];
      ans += a[i];
    } else {
      ans += b[i];
      b[i] = 0;
    }

    if (a[i + 1] < b[i]) {
      ans += a[i + 1];
      a[i + 1] = 0;
    } else {
      ans += b[i];
      a[i + 1] -= b[i];
      b[i] = 0;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1792
n=int(input())
lists=list(map(int,input().split()))
a=[0 for i in range(n)]
b=[0 for i in range(n)]
for i in range(n):
    a[i]=(i+1)*(4*10**4)
    b[i]=(n-i)*(4*10**4)
for i in range(n):
    a[lists[i]-1]+=i
    b[lists[i]-1]+=i
print(*a)
print(*b)

Measured memory_bytes: 45828
from itertools import combinations_with_replacement

n,m,q=map(int,input().split())
query=[list(map(int,input().split())) for _ in range(q)]
l=list(range(1,m+1))
ans=0

for x in combinations_with_replacement(l,n):
    ans1=0
    x=sorted(x)
    for Q in query:
        if x[Q[1]-1]-x[Q[0]-1] == Q[2]:
            ans1 += Q[3]
    ans = max(ans,ans1)
        
print(ans)

Measured memory_bytes: 9100
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  int n, k;
  cin >> n >> k;
  vi x, y;
  rep(i, n) {
    int a;
    cin >> a;
    if(a >= 0)
      x.push_back(a);
    else
      y.push_back(abs(a));
  }
  sort(all(x));
  sort(all(y));
  int ans = 1e9;
  rep(i, k + 1) {
    int j = k - i;
    if(i > x.size() || j > y.size()) continue;
    int dx = i == 0 ? 0 : x[i - 1];
    int dy = j == 0 ? 0 : y[j - 1];
    int d = 2 * min(dx, dy) + max(dx, dy);
    ans = min(ans, d);
  }
  cout << ans << endl;
}

Measured memory_bytes: 1020
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = 100010;
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[] h = new int[N];
        int[] ma = new int[N];

        for(int i = 1; i <= n; i++) {
                h[i] = sc.nextInt();
                ma[i] = 0;
        }

        for(int i = 0; i < m; i++) {
            int a = sc.nextInt();
            int b = sc.nextInt();
            ma[a] = Math.max(ma[a], h[b]);
            ma[b] = Math.max(ma[b], h[a]);
        }

        int res = 0;
        for(int i = 1; i <=n; i++) {
             if(h[i]>ma[i]) {
                res++;
            }
        }
        System.out.println(res);
    }
}


Measured memory_bytes: 59652
import sys
input = sys.stdin.readline
n=int(input())

a="MARCH"
cnt=[0]*5
for i in range(n):
    s=input()
    for i in range(5):
        if s[0]==a[i]:
            cnt[i]+=1
ans=0
for i in range(3):
  for j in range(i+1,4):
    for k in range(j+1,5):
      ans+=cnt[i]*cnt[j]*cnt[k]
print(ans)


Measured memory_bytes: 68080
from collections import deque
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import product,permutations,combinations,combinations_with_replacement
from collections import defaultdict,Counter
from bisect import bisect_left,bisect_right
# from math import gcd,ceil,floor,factorial
# from fractions import gcd
from functools import reduce
from pprint import pprint

INF = float("inf")

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

def mylistinput(n):
    return [ list(myinput()) for _ in range(n) ]

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col,reverse_flag):
    data.sort(key=lambda x:x[col],reverse=reverse_flag)
    return data

def mymax(data):
    M = -1*float("inf")
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float("inf")
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

def mycount(ls,x):
    # lsはソート済みであること
    l = bisect_left(ls,x)
    r = bisect_right(ls,x)
    return (r-l)

def myoutput(ls,space=True):
    if space:
        if len(ls)==0:
            print(" ")
        elif type(ls[0])==str:
            print(" ".join(ls))
        elif type(ls[0])==int:
            print(" ".join(map(str,ls)))
        else:
            print("Output Error")
    else:
        if len(ls)==0:
            print("")
        elif type(ls[0])==str:
            print("".join(ls))
        elif type(ls[0])==int:
            print("".join(map(str,ls)))
        else:
            print("Output Error")

h,w = myinput()
a = [ input() for _ in range(h) ]

b = ["#"]*(w+2)
myoutput(b,False)
for i in range(h):
    c = "#" + a[i] + "#"
    myoutput(c,False)
myoutput(b,False)

Measured memory_bytes: 38384
def insertion_sort(a, g, cnt):
  for i in range(g, len(a)):
    v = a[i]
    j = i - g
    while j >= 0 and a[j] > v:
      a[j+g] = a[j]
      j = j - g
      cnt += 1
    a[j+g] = v
  return cnt

n = int(input())
g = [1]
t = 1
cnt = 0
while 1:
  t = 3 * t + 1
  if t < n and len(g) < 100:
    g += [t]
  else:
    g = g[::-1]
    break
a = [int(input()) for _ in range(n)]
for i in range(0, len(g)):
  cnt = insertion_sort(a, g[i], cnt)
print(len(g))
print(*g)
print(cnt)
for i in a: print(i)


Measured memory_bytes: 45668
#include <iostream>

using namespace std;

int a[100][100];
int b[100];

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin>>n>>m;
    for(int i=0; i<n; i++) {
        for(int j=0; j<m; j++) {
            cin>>a[i][j];
        }
    }
    for(int i=0; i<m; i++) {
        cin>>b[i];
    }
    int ans;
    for(int i=0; i<n; i++) {
        ans=0;
        for(int j=0; j<m; j++) {
            ans+=a[i][j]*b[j];
        }
        cout<<ans<<'\n';
    }
    return 0;
}

Measured memory_bytes: 1240
#include <functional>
#include <iostream>
#include <numeric>
#include <set>

using namespace std;
using ll = long long;

int main() {
  ll N, M, x;
  cin >> N >> M;
  multiset<ll, greater<>> s;
  for (int i = 0; i != N; ++i) {
    cin >> x;
    s.insert(x);
  }
  for (int i = 0; i != M; ++i) {
    ll a = *begin(s);
    s.erase(begin(s));
    s.insert(a/2);
  }

  cout << accumulate(begin(s),end(s),0ll) << endl;
}


Measured memory_bytes: 8296
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main(String args[]) throws IOException {

	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	String array[] = br.readLine().split(" ");

	for (int i = 0; i < array.length; i++) {
	    if (Integer.parseInt(array[i]) == 0) {
		System.out.println(i + 1);
		break;
	    }
	}
    }
}


Measured memory_bytes: 32428
# -*- coding: utf-8 -*-

import sys

sys.setrecursionlimit(10 ** 9)
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
INF=float('inf')

N,M=MAP()
nodes=[[] for i in range(N)]
for i in range(M):
    u,v=MAP()
    nodes[u].append(v)
    nodes[v].append(u)

visited=[False]*N
timer=1
prenum=[0]*(N+1)
lowest=[0]*(N+1)
ans=[]
def rec(cur, prev):
    global timer
    # curを訪問した直後の処理
    prenum[cur]=lowest[cur]=timer
    timer+=1

    visited[cur]=True
    for nxt in nodes[cur]:
        # 未訪問なら再帰探索する
        if not visited[nxt]:
            rec(nxt, cur)
            # nxtの探索が終了した直後の処理
            lowest[cur]=min(lowest[cur], lowest[nxt])
            # より近い経路を含まないなら橋とする
            if lowest[nxt]==prenum[nxt]:
                # 番号の小さい方から入れる
                ans.append((min(cur, nxt), max(cur, nxt)))
        # 訪問済の場合、親への経路は無視して、他は近い経路となるか確認を取る
        elif nxt!=prev:
            lowest[cur]=min(lowest[cur], lowest[nxt])

rec(0, -1)

ans.sort()
for edge in ans:
    print(*edge)



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

xyh1 = [] # h > 0
xyh2 = [] # h = 0
for _ in range(N) :
    x, y, h = map(int, input().split())
    if h > 0 :
        xyh1.append((x, y, h))
    else :
        xyh2.append((x, y, h))

def solve() :
    for Cx in range(0, 101) :
        for Cy in range(0, 101) :
            # 特定できるからxyh1は必ず1つは要素を持つ
            x, y, h = xyh1[0]
            H = h + abs(x-Cx) + abs(y-Cy)
            
            flag = False
            for x, y, h in xyh1[1:] :
                if H != h + abs(x-Cx) + abs(y-Cy) :
                    flag = True
                    break
                    
            if flag :
                continue
                
            for x, y, h in xyh2 :
                if H - abs(x-Cx) - abs(y-Cy) > 0 :
                    flag = True
                    break
                    
            if flag :
                continue
                
            return (Cx, Cy, H)
            
print(*solve())

Measured memory_bytes: 41200
inp = input()
a = inp.split()
a[0] = int(a[0])
a[1] = int(a[1])
a[2] = int(a[2])
a[3] = int(a[3])
a[4] = int(a[4])
if (a[4] <= a[2] and a[2] <= a[0]-a[4]) and (a[4] <= a[3] and a[3] <= a[1]-a[4]):
    print("Yes")
else:
    print("No")


Measured memory_bytes: 5596
first=0
second=0
third=0

for i in range(10):
    mountain=int(input())
    if mountain>first:
        third=second
        second=first
        first=mountain
    elif mountain>second:
        third=second
        second=mountain
    elif mountain>third:
        third=mountain

print(first)
print(second)
print(third)

Measured memory_bytes: 7528
#include<bits/stdc++.h>
using namespace std;
 
char sS[100010],sT[100010];
int S[100010] = {0},T[100010] = {0};
int Q;
 
int main()
{
    scanf("%s%s",sS,sT);
    for(int i = 1; i < 100000 + 1; i++)
    {
        if(sS[i - 1] == 'A')
        {
            S[i] += 1;
            S[i + 1] = S[i];
        }
        else
        {
            S[i] += 2;
            S[i + 1] = S[i];
        }
    }
    for(int i = 1; i < 100000 + 1; i++)
    {
        if(sT[i - 1] == 'A')
        {
            T[i] += 1;
            T[i + 1] = T[i];
        }
        else
        {
            T[i] += 2;
            T[i + 1] = T[i];
        }
    }
    scanf("%d",&Q);
    for(int i = 0; i < Q; i++)
    {
        int a,b,c,d;
        scanf("%d%d%d%d",&a,&b,&c,&d);
        if((S[b] - S[a - 1]) % 3 == (T[d] - T[c - 1]) % 3)
        {
            printf("YES\n");
        }
        else
        {
            printf("NO\n");
        }
    }
    return 0;
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n;
    cin>>n;
    int total[100000];
    fill_n(total,100000,0);
    for(int x=1; x<sqrt(n); x++){
        for(int y=1; y<sqrt(n); y++){
            for(int z=1; z<sqrt(n); z++){
                int num=x*x+y*y+z*z+x*y+y*z+z*x;
                total[num]++;
            }
            
        }
    }
    for(int i=1; i<=n; i++){
        cout<<total[i]<<endl;
    }
    return 0;
}

Measured memory_bytes: 3964
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <map>
using namespace std;
typedef long long ll;
ll n,x;
int main(void){
  cin >> n >> x;
  ll sum = 0;
  ll l = n-x;
  ll s = x;
  while(s){
    sum += 3*s*(l/s);
    ll tmp = s;
    s = l%s;
    l = tmp;
  }
  cout << sum  << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <tuple>
#include <iterator>
#include <sstream>
#include <bits/stdc++.h>

using ll = long long;
using namespace std;
#define modmod 1000000007
#define modddd 998244353

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

ll kaizyou[100003]={1};

void kaikai(){
    ll unko = 0;
    for(int i = 1; i < 100003; i++){
        unko = (unko%modddd * 1%modddd)%modddd;
        kaizyou[i] = unko;
    }
}

int main(){
    int N;
    cin >> N;
    ll A[N];
    rep(i,N) cin >> A[i];

    ll count = 0;
    rep(i,N){
        if(A[i]%2 == 1){
            count++;
        }
    }
    if(count%2==0){
        puts("YES");
    }else{
        puts("NO");
    }
    return 0;
}


Measured memory_bytes: 1024
n = gets.to_i
s = gets.chomp

ans = 0
n.times do |i|
    u = s.chars.uniq
    f = s[0..i].chars.uniq
    l = s[i+1..-1].chars.uniq
    # p [f,l,u]
    t = f.size + l.size - u.size
    ans = t if ans < t
end

p ans



Measured memory_bytes: 1788
K = int(input())

def Gcd(x, y): #a>=b>=c
    if x < y:
        x, y = y, x
    a = x
    b = y
    r = a % b
    while r != 0:
        a = b
        b = r
        r = a % b
    return b

sum = 0
for a in range(1, K + 1):
    sum += a

for a in range(1, K + 1):
    for b in range(1, a):
        sum += Gcd(a, b) * 6

for a in range(1, K + 1):
    for b in range(1, a):
        for c in range(1, b):
            sum += Gcd(Gcd(a, b), c) * 6
print(sum)

Measured memory_bytes: 9228
#include<bits/stdc++.h>
using namespace std;
int f[305][305][305],n,K;
char s[305];
inline int max(int x,int y){
	return x>y?x:y;
}
int main(){
  	scanf("%s%d",s+1,&K);
	n=strlen(s+1);
  	for(int i=1;i<=n;i++) for(int k=0;k<=K;k++) f[i][i][k]=1;
  	for(int l=2;l<=n;l++){
      	for(int i=1;i+l-1<=n;i++){
          	int j=i+l-1;
          	for(int k=0;k<=K;k++){
             	f[i][j][k]=max(f[i+1][j][k],f[i][j-1][k]);
                if(k) f[i][j][k]=max(f[i][j][k],f[i+1][j-1][k-1]+2);
                if(s[i]==s[j]) f[i][j][k]=max(f[i][j][k],f[i+1][j-1][k]+2);
          	}
    	}
  	}
  printf("%d\n",f[1][n][K]);
  return 0;
}

Measured memory_bytes: 110464
#include<iostream>
#include<iomanip>
#include<cmath>
void kock(int, std::pair<double,double>, std::pair<double,double>);
int main(){
  int n;
  std::pair<double,double> p1=std::make_pair(0,0), p2=std::make_pair(100,0);
  std::cin >> n;
  std::cout << std::fixed << std::setprecision(10) << p1.first << " " << p1.second << std::endl;
  kock(n,p1,p2);
  std::cout << std::fixed << std::setprecision(10) << p2.first << " " << p2.second << std::endl;
  return 0;
}
void kock(int n, std::pair<double,double> p1, std::pair<double,double> p2){
  std::pair<double,double> s,t,u;
  if(n == 0) return;
  s.first = (2 * p1.first + 1 * p2.first) / 3;
  s.second = (2 * p1.second + 1 * p2.second) / 3;
  t.first = (1 * p1.first + 2 * p2.first) / 3;
  t.second = (1 * p1.second + 2 * p2.second) / 3;
  u.first = (t.first - s.first) * cos(M_PI/3) - (t.second - s.second) * sin(M_PI/3) + s.first;
  u.second = (t.first - s.first) * sin(M_PI/3) + (t.second - s.second) * cos(M_PI/3) + s.second;
  kock(n-1, p1, s);
  std::cout << std::fixed << std::setprecision(10) << s.first << " " << s.second << std::endl;
  kock(n-1, s, u);
  std::cout << std::fixed << std::setprecision(10) << u.first << " " << u.second << std::endl;
  kock(n-1, u, t);
  std::cout << std::fixed << std::setprecision(10) << t.first << " " << t.second << std::endl;
  kock(n-1, t, p2);
}

Measured memory_bytes: 3236
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <map>
#include <math.h>
#include <vector>
using namespace std;
map<int, int> ct;
map<int, int> ct2;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<pair<int, int> > vpii;
typedef pair<int, int> pii;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef vector<ll> vll;
#define INF 0x3f3f3f3f
#define MOD 998244353LL
#define EPS 0.00001
#define f first
#define s second
#define pb push_back
#define mp make_pair

#define FOR(i, a, b) for (int i=(a); i<=(signed)(b); i++)
#define AFOR(i, a) for (int i=0; i<(signed)(a); i++)
#define RFOR(i, a, b) for (int i=(a); i >= b; i--)

#define MN 100005
int n, m, l;
int a, b, c;
string s[MN];
string str;
string ans;

/*
int N;
cin >> N;
vi vect(N);
FOR(i,N) cin >> vec.at(i);*/
//sort(vec.begin(),vec.end());
//vvi data(N,vi(4));

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int K;
	cin >> K;
	cin >> str;
	string str2;

	if (str.size() <= K) cout << str << endl;
	else {
		AFOR(i, K) { str2.push_back(str.at(i)); }
		str2.pb('.');
		str2.pb('.');
		str2.pb('.');
		cout << str2 << endl;
	
	}
	
	return 0;
}

Measured memory_bytes: 6744
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
#include<queue>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int cm = 1 << 15;
char cn[cm], * ci = cn, ct;
inline int getint() {
	int A = 0;
	while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

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

	fread_unlocked(cn, 1, cm, stdin);
	int N = getint(), K = getint(), Q = getint();
	ll A[2002];
	int LR[2002];
	rep1(i, N) A[i] = ((ll)getint() << 16) + i;
	rep(i, N + 2) LR[i] = -1;

	priority_queue<int> q;
	priority_queue<int, vector<int>, greater<int>> q2[2002];
	int q3[2002];
	rep1(i, N) q3[i] = i;
	int kotae = 1e9;
	int saishou = 2e9;
	sort(A + 1, A + N + 1);
	const int m = (1 << 16) - 1;

	for (int i = N; i >= 1; i--) {
		int a = A[i] >> 16;
		int k = A[i] & m;

		int l = (LR[k - 1] == -1) ? k : LR[k - 1];
		int r = (LR[k + 1] == -1) ? k : LR[k + 1];
		LR[l] = r;
		LR[r] = l;

		if (k + k < l + r) swap(q3[l], q3[k + 1]);

		while (q2[q3[k + 1]].size()) {
			int tmp = q2[q3[k + 1]].top();
			q2[q3[l]].push(tmp);
			q2[q3[k + 1]].pop();
		}
		q2[q3[l]].push(a);
		while (q2[q3[l]].size() >= K) {
			int tmp = q2[q3[l]].top();
			q.push(tmp);
			q2[q3[l]].pop();
		}
		while (q.size() >= Q) {
			int tmp = q.top();
			chmin(saishou, tmp);
			q.pop();
		}
		chmin(kotae, saishou - a);
	}

	printf("%d", kotae);

	Would you please return 0;
}

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

namespace ABC098A
{
    class Program
    {
        private static int max, a, b;

        static void Main(string[] args)
        {
            int a, b, x;

            var word = Console.ReadLine().Split(' ');

            a = int.Parse(word[0]);
            b = int.Parse(word[1]);


            x = a + b;

            if (x < a - b) x = a - b;
            if (x < a * b) x = a * b;

            Console.WriteLine(x);
            Console.ReadKey();
        }
    }
}


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

using namespace std;
using ll = long long;

int n, q;
vector<vector<int>> hen;
vector<int> cost;

void dfs(int cur, int prev)
{

    for(auto i : hen[cur])
    {
        if(i == prev)continue;
        cost[i] += cost[cur];
        dfs(i, cur);
    }

}



int main()
{
    cin >> n >> q;
    hen.resize(n);
    cost.resize(n);
    for(int i = 0; i < n - 1; i++){
        int x, y; cin >> x >> y; x--, y--;
        hen[x].push_back(y);
        hen[y].push_back(x);
    }

    for(int i = 0; i < q; i++){
        int v, c; cin >> v >> c;
        v--;
        cost[v] += c;
    }
    dfs(0, -1);

    for(int i = 0; i < n; i++)cout << cost[i] << " ";
}

Measured memory_bytes: 23424
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <algorithm>
#include <cmath>
#include <queue>

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

using namespace std;

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

int s[1<<20];
int size;

// k人目の状態をseg-treeで管理
// ノードは区間内の生存者の合計を保持
void init(int n){
	size = 1;
	while(size < n){
		size *= 2;
	}
	rep(i, size*2){
		s[i] = 0;
	}
}

// k番目にaを加算
void add(int k, int a){
	k += size-1;
	s[k] += a;
	while(k > 0){
		k = (k-1)/2;
		s[k]+=a;
	}
}

// 生存者のn番目の位置を探す
int query(int n, int k, int l, int r){
	if(s[k] < n || s[k] == 0) return -1;
	if(r - l == 1){
		return k-(size-1);
	}
	int chl = k*2+1, chr = k*2+2;
	int ret = query(n, chl, l, (l+r)/2);
	if(ret != -1) return ret;
	return query(n-s[chl], chr, (l+r)/2, r);
}


int main(){
	int q, lim;
	while(cin >> q >> lim, q|lim){
		init(q);
		map<int, int> idmap;
		vector<int> v;
		int idx = 0;
		rep(i, q){
			int type, x;
			cin >> type >> x;
			int pos;
			switch(type){
			case 0:
				v.push_back(x);
				idmap[x] = idx;
				add(idx++, 1);
				// 生存者がlim人を超えたら一番左を殺す
				if(s[0] > lim){
					add(query(1, 0, 0, size), -1);
				}
				break;
			case 1:
				add(query(x, 0, 0, size), -1);
				break;
			case 2:
				pos = query(x, 0, 0, size);
				cout << v[pos] << endl;
				break;
			case 3:
				add(idmap[x], -1);
				break;
			}
		}
		cout << "end" << endl;
    }

	return 0;
}

Measured memory_bytes: 25484
#include "bits/stdc++.h"

using namespace std;

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

#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#ifdef Debug
#define dump(x)  cerr << #x << " = " << (x) << endl
#else
#define dump(x)
#endif

bool cmp(char a[2],char b){
	if(tolower(a[0])==tolower(b))return true;
	else return false;
}


int main(){
	int n,h;
	cin>>n>>h;
	vector<string> s;
	vector<int> t;
	rep(i,n){
		string a;
		int b;
		cin>>a>>b;
		s.pb(a);
		t.pb(b);
	}

	int x=0;
	int times=0;

	rep(i,n){
		int c=0;
		int wrong=0;
		int len=s[i].size();
		while(c<len){
			string str="";
			rep(j,c)str+='_';
			str+=s[i].substr(c,len-c);
			printf("? %s\n", str.c_str() ); fflush(stdout);

			char ch[2];
 			scanf("%s", ch);
			times++;
 			if( cmp(ch,s[i][c]) ){
 				c++;
 				x++;
 			}else {wrong++;}
			if(wrong>t[i]){
 				h--;
 				break;
 			}
		}
		if(h<=0){
			printf("! Game Over\n"); fflush(stdout);
			return 0;
		}
	}
	int ans=x*1000/times;
	printf("! Game Clear %d.%d\n",ans/10,ans%10) ; fflush(stdout);
	return 0;
}

Measured memory_bytes: 1300
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<utility>
#include<cstdio>
#include<set>
#include<string>
#include<map>
#include<queue>
#include<stack>
#include <bitset>
using namespace std;
const int mod=1e9+7;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<n;i++)
#define rep2(i,x,n) for (int i= x;i<n;i++)
#define all(v) v.begin(), v.end()
#define nepe(v) next_permutation(all(v))
#define F first 
#define S second
#define PB push_back 
#define MP make_pair
using ll = long long;
using vi = vector<int>; 
using vvi = vector<vi>;
using vl=vector<long long>;
using vvl = vector<vl>;
using vp =vector<pair<int,int>>;

typedef pair<int,int> P;
string s;
int k;
ll INF = 1000000000000;

int main(){
    int A,B;
    cin >>A>>B;
    cout <<A*B<<endl;
}


Measured memory_bytes: 3632
use proconio::input;

fn main() {
    input! {
        n: usize,
        mut k: usize,
        a: [usize; n],
    }

    let mut s = Vec::new();
    let mut ord: Vec<i64> = vec![-1; n + 1];

    let mut go: usize = 1;
    loop {
        if ord[go] != -1 {
            break;
        }
        ord[go] = s.len() as i64;
        s.push(go);
        go = a[go - 1];
    }
    let loop_size = s.len() - ord[go] as usize;
    let l = ord[go] as usize;

    if k < l {
        println!("{}", s[k]);
    } else {
        k -= l;
        k %= loop_size;
        println!("{}", s[l + k]);
    }
}

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

using namespace std;

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

	int cnt0 = 0, cnt1 = 0, ans = 0;
	for (int i = 0;i < s.length();++i) {
		if (s[i] == '0') {
			cnt0++;

			if (cnt1 > 0) {
				ans++;
				cnt1--;
				cnt0--;
			}
		}
		else {
			cnt1++;

			if (cnt0 > 0) {
				ans++;
				cnt0--;
				cnt1--;
			}
		}
	}

	cout << ans * 2;
		
	return 0;
}

Measured memory_bytes: 512
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner as = new Scanner(System.in);
		int n = Integer.parseInt(as.next());
		int l = n;
		int[] a;
		int b = 0;
		int c = (int)Math.pow(2, n);
		a = new int[c];
		for(int i=0;i<c;i++){
			a[i]  = Integer.parseInt(as.next());
		}
		for(int s=0;s<n;s++){
			for(int i=0;i<(int)(Math.pow(2, l));i+=2){
				if(a[i]<a[i+1]){
					a[i+1]-=a[i];
					a[b]=a[i+1];
					b+=1;
				}else if(a[i]>a[i+1]){
					a[i]-=a[i+1];
					a[b]=a[i];
					b+=1;
				}else{
					a[b]=a[i];
					b+=1;
				}
			}
			l-=1;
			b = 0;
		}
		System.out.println(a[0]);
	}
}


Measured memory_bytes: 51712
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cmath>
using namespace std;
using ll = long long;

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

    ll i0, j0;
    for (ll i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ll j = n / i;
            i0 = i;
            j0 = j;
        }
    }

    cout << i0 + j0 - 2 << endl;

    return 0;
}

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

int main(){
    int x;
    cin >> x;
    int n=x%7;
    if(n==0)cout << "thu";
    else if(n==1)cout << "fri";
    else if(n==2)cout << "sat";
    else if(n==3)cout << "sun";
    else if(n==4)cout << "mon";
    else if(n==5)cout << "tue";
    else if(n==6)cout << "wed";

    cout << endl;

    return 0;
}

Measured memory_bytes: 3112
import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.io.PrintWriter
import java.lang.StringBuilder
import java.util.*

fun PrintWriter.solve(sc: FastScanner) {
    val n = sc.nextInt()
    val a = Array(n) { 0 }
    val b = Array(n) { 0 }
    var sum = 0L
    for (i in 0 until n) {
        a[i] = sc.nextInt()
        b[i] = sc.nextInt()
        sum -= b[i]
    }
    val c = (0 until n).map { a[it] + b[it] }.sortedDescending()
    for (i in 0 until (n + 1) / 2) {
        sum += c[2 * i]
    }
    println(sum)
}

fun main(args: Array<String>) {
    val writer = PrintWriter(System.out, false)
    writer.solve(FastScanner(System.`in`))
    writer.flush()
}

class FastScanner(s: InputStream) {
    private var st = StringTokenizer("")
    private val br = BufferedReader(InputStreamReader(s))

    fun next(): String {
        while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())

        return st.nextToken()
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextLine() = br.readLine()
    fun nextDouble() = next().toDouble()
    fun ready() = br.ready()
}

Measured memory_bytes: 56228
#include <bits/stdc++.h>
 
#define int         long long
#define uint        unsigned int
#define ld          long double
#define showoff     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb          push_back
#define pii         pair<int,int>
#define FOR(i,a,b)  for(int i=a;i<b;++i)
#define RFOR(i,a,b) for(int i=a;i>b;--i)
#define f           first
#define se          second
#define maxn        200005
#define all(v)      v.begin(),v.end()
#define sz(x)       (int)x.size()
#define mod         1000000007
#define pqueue      priority_queue<int>
#define pdqueue     priority_queue< int,vector<int> ,greater< int >>
 
using namespace std;
 
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
 
int power(int a,int n)
{
    a %= mod;
    if(n == 1)return a;
    if(n == 0)return 1;
    if(n%2)return (a*(power((a*a)%mod,n/2)%mod))%mod;
    return power((a*a)%mod,n/2)%mod;
}
const int inf = (int) 1e18;
 
int inverse(int x){
    return power(x,mod-2)%mod;//little fermat....
}
vector<int>v(maxn),adj[maxn],ans(maxn);
vector<stack<int>>len(maxn);
int n;

void dfs(int x,int p){
    int lo = 0,hi = n;
    while(lo < hi){
        int mid = (lo+hi+1)/2;
        if(len[mid].top() >= v[x])hi = mid-1;
        else lo = mid;
    }
    ans[x] = max(lo+1,ans[p]);
    bool fo = 0;
    if(len[lo+1].top() >= v[x])len[lo+1].push(v[x]),fo = 1;
    for(auto &y:adj[x]){
        if(y != p){
            dfs(y,x);
        }
    }
    if(fo)len[lo+1].pop();
}

void solve(){
    cin >> n;
    FOR(i,1,n+1)cin >> v[i];
    FOR(i,0,n+1)len[i].push(inf);
    FOR(i,1,n){
        int u,v;
        cin >> u >> v;
        adj[u].pb(v);
        adj[v].pb(u);
    }
    dfs(1,1);
    FOR(i,1,n+1)cout << ans[i] << "\n";
}

signed main()   
{
    showoff;
    int T = 1;
    //cin >> T;
    FOR(t,1,T+1){
        solve();
    }
    return 0;
}
//*->for large size of matrix take int not long long if possible......
//*->always take maximum as inf for safer side ...


Measured memory_bytes: 167280
#include <stdio.h>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef vector<vector<int>> v2int;
typedef vector<ll> vll;
typedef vector<vector<ll>> v2ll;
typedef list<int> liint;
typedef pair<int, int> pint;
const int INF = int(2e9);
const ll LINF = ll(2e9) * ll(2e9);
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b) { a > b ? : a = b; }
template<class T, class C> void chmin(T& a, C b) { a < b ? : a = b; }

ll gcd(ll a, ll b)
{
    if (a < b) {
        a ^= b;
        b ^= a;
        a ^= b;
    }

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

ll lcm(ll a, ll b)
{
    return (a * b) / gcd(a, b);
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int N;
    ll M;
    cin >> N >> M;
    vll A(N);
    rep(i, N) cin >> A[i];

    
    ll X = A[0]/2;
    rep(i, N - 1) {
        if ((A[i]/2) % 2 != (A[i + 1] /2) % 2) {
            cout << 0 << endl;
            return 0;
        }
    }
    rep(i, N) {
        X = lcm(X, A[i]/2);
        if (X > M) {
            cout << 0 << endl;
            return 0;
        }
    }
    rep(i, N) {
        if ((X - A[i] / 2) % A[i] != 0) {
            cout << 0 << endl;
            return 0;
        }
    }
    ll add = 0;
    if (M % X != 0 && X <= M) add++;
    ll ans = (M / X  + 1)/ 2;
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define EB emplace_back

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef vector<int> vi;

const int INF = 1e9 + 7;

pair<pair<string, int>, int> a[105];

int main()
{
	IO_OP;
	
	int n;
	cin >> n;
	for(int i=0;i<n;i++) {
		string s;
		int p;
		cin >> s >> p;
		a[i] = MP(MP(s, -p), i+1);
	}
	sort(a, a+n);
	for(int i=0;i<n;i++)
		cout << a[i].S << endl;
	
}



Measured memory_bytes: 256
public class Main{
  public void run(java.io.InputStream in, java.io.PrintStream out){
    java.util.Scanner sc = new java.util.Scanner(in);
/*answer*/
    String s;
    int i, n, h, m, sum;
    char[] sch;


    for(;;){
      s = sc.next();
      if("-".equals(s)){
        break;
      }else{
        m = sc.nextInt();
        n = s.length();
        sch = new char[n];
        for(i = 0;i < n;i++){
          sch[i] = s.charAt(i);
        }

        sum = 0;
        for(i = 0;i < m;i++){
          h = sc.nextInt();
          sum += h;
        }

        for(i = 0;i < n;i++){
          System.out.print(sch[(sum + i) % n]);
        }
        System.out.println();
      }
    }

    sc.close();
  }
  public static void main(String[] args){
    (new Main()).run(System.in, System.out);
  }
}

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

using namespace std;
typedef long long ll;
typedef vector<ll> vl ;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;

#define rep(i,N) for(int i=0; i < (int)N; i++)
#define all(v) (v).begin(),(v).end()

const int INF = 100000002;

int main(){
	int n, m; cin >> n >> m;
	vector<pi> ans;
	if (n%2) { 
		for(int l = 1, r=n-1; l < r; l++, r--){
			ans.emplace_back(l,r);
		}
	}else{
		bool flag = false;
		for(int l=1, r=n-1; l < r; l++, r--){
			if(!flag && r-l <= n/2){
				--r;
				flag = true;
			}
			ans.emplace_back(l,r);
		}
	}
	rep(i,m){
		printf("%d %d\n", ans[i].first, ans[i].second);
	}
}

Measured memory_bytes: 4304
#include <iostream>

using namespace std;

int main(void) {

	string C1, C2;

	cin >> C1 >> C2;

	string result = "NO";
	if (C1[1] == C2[1]
		&& C1[0] == C2[2]
		&& C1[2] == C2[0]) {
		result = "YES";
	}

	cout << result << endl;

	return 0;
}



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

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

  vector<pair<int,int>> a(n);
  rep(i,n) cin >> a[i].first >> a[i].second;

  sort(a.begin(),a.end());
  int ans = a.back().first;
  int v = a.back().second;

  ans += v;

  cout << ans << '\n';

}



Measured memory_bytes: 4052
#include <bits/stdc++.h>
using namespace std ;
typedef long long ll;
ll mod=1e9+7;

//RepeatSquare
ll RS(ll N ,ll P, ll M){
    if(P==0) return 1;
    else if(P%2==0){
        ll t=RS(N,P/2,M);
        return t*t%M;
    }
    else return N*RS(N,P-1,M)%mod;   
}
//combination
ll f[10010],inv[10010];

void init(){
    f[0]=inv[0]=1;
    for(int i=1;i<10010;i++){
        f[i]=f[i-1]*i%mod;
        inv[i]=RS(f[i],mod-2,mod);
    } 
}

ll comb(ll a,ll b){
    if(b>a) return 0;
    else return f[a]*inv[b] % mod *inv[a-b]% mod;
}

int main(){
    init();
    ll N,K;cin>>N>>K;
    for(int i=1;i<=K;i++){
        ll t =comb(K-1,i-1)*comb(N-K+1,i)%mod;
        cout << t <<endl;
    } 
    //cout << f[2000] << endl;
}

Measured memory_bytes: 3700
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

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

#include <bits/stdc++.h>
using namespace std;

int main(){
  
  stack<int> sta;
  int a,b;
  string s;
  while(cin>>s){
    if(s[0]=='+'){
      b=sta.top();
      sta.pop();
      a=sta.top();
      sta.pop();
      sta.push(a+b);
    }
    else if(s[0]=='-'){
      b=sta.top();
      sta.pop();
      a=sta.top();
      sta.pop();
      sta.push(a-b);
    }
    else if(s[0]=='*'){
      b=sta.top();
      sta.pop();
      a=sta.top();
      sta.pop();
      sta.push(a*b);
    }
    else{
      sta.push(stoi(s));
    }
  }
  cout << sta.top() << endl;

  return 0;
}


Measured memory_bytes: 3216
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <cmath>
#include <set>
#include <algorithm>
#include <iomanip>

typedef long long ll;
const ll MOD = 1e9 + 7;
const long long INF = 1LL<<60;
const double PI=3.14159265358979323846;
const int NMAX=100005;
using namespace std;

struct BIT {
    int n;
    vector<int> bit;
    
    BIT(int n_) : n(n_ +1), bit(n,0){}

    void add(int i, int x){
        for(int idx = i; idx < n; idx += (idx & -idx)){
            bit[idx] += x;
        }
    }

    int sum(int i){
        int s = 0;
        for(int idx = i; idx > 0; idx -= (idx & -idx)){
            s += bit[idx];
        }
        return s;
    }

};

int main(){
    int n, q;
    cin >> n >> q;
    vector<int> c(n);
    for(int i = 0; i < n; i++){
        cin >> c[i];
    }
    vector<vector<pair<int, int>> > qs(n+1);
    for(int i = 0; i < q; i++){
        int l,r;
        cin >> l >> r;
        qs[l].push_back(make_pair(r,i));
    }

    vector<vector<int> > ps(n+1);
    vector<int> cl(n+1, -1);
    for(int i = 0; i < n; i++){
        int tmp = cl[c[i]];
        if(tmp != -1) ps[tmp+1].push_back(i+1);
        cl[c[i]] = i;
    }

    BIT bit(n);
    vector<int> ans(q, -1);
    for(int i = n; i > 0; i--){
        for(int j = 0; j < ps[i].size(); j++){
            bit.add(ps[i][j], 1);
        }

        for(int j = 0; j < qs[i].size(); j++){
            int dbl = bit.sum(qs[i][j].first);
            ans[qs[i][j].second] = qs[i][j].first-i+1-dbl;
        }
    }

    for(int i = 0; i < q; i++){
        cout << ans[i] << endl;
    }

    return 0;
}

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

int main() {
  string s;
  cin>>s;
  int a=s.size();
  bool ans=true;
  for(int i=0;i<a;i+=2){
    if(s[i]=='L')ans=false;
  }
   for(int i=1;i<a;i+=2){
    if(s[i]=='R')ans=false;
   }
  if(ans)cout<<"Yes"<<endl;
  else  cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  

#pragma warning(disable:4996)  
#pragma comment(linker, "/STACK:336777216")  
using namespace std;

#define mp make_pair  
#define Fi first  
#define Se second  
#define pb(x) push_back(x)  
#define szz(x) ((int)(x).size())  
#define rep(i, n) for(int i=0;i<n;i++)  
#define all(x) (x).begin(), (x).end()  
#define ldb ldouble  

typedef unsigned int uint;
typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

int IT_MAX = 1 << 19;
const ll MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;

const int MX = 1<<19;
const int MM = 998244353;

bool check(vector<int> L){
	int odd = 0, even = 0;
	for(int i = 1; i+2 < L.size(); i += 2) if(L[i] > L[i+2]) odd = 1;
	if(odd) return false;

	vector<pii> X;
	for(int i = 0; i < L.size(); i++) X.emplace_back(L[i], i);
	sort(X.begin(), X.end());
	
	set<pii> P1;
	for(int i = 0; i < X.size(); i++){
		pii c = pii(X[i].second, X[i].first);
		auto it = P1.lower_bound(c);
		if(i%2 == 0 && it != P1.end() && it->first%2 == 0) return false;
		P1.insert(c);
	}

	reverse(X.begin(), X.end());
	P1.clear();

	for(int i = 0; i < X.size(); i++){
		pii c = pii(X[i].second, X[i].first);
		auto it = P1.lower_bound(c);
		if(i%2 == 0 && it != P1.begin() && prev(it)->first%2 == 0) return false;
		P1.insert(c);
	}
	return true;
}

int main()
{
	int N;
	scanf("%d", &N);
	vector<int> L;
	int mx = 0;
	for(int i = 1; i <= N; i++){
		int a;
		scanf("%d", &a);
		if(i%2 != a%2) return !printf("No\n");
		L.push_back(a);
		mx = max(mx, a);
		if(mx == i){
			if(!check(L)) return !printf("No\n");
			L.clear();
		}
	}
	printf("Yes\n");
}



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

int main() {
   int n, a, b, pj = 0, po = 0;
   cin >> n >> a >> b;
   string s;
   cin >> s;
//    int o = count(s.begin(), s.end(), 'b');
   int co = 0;

   for(int i = 0; i < n; i++){
       char c = s[i];
       if(c == 'c'){
           cout << "No" << endl;
       } else if(c == 'a'){
          if(pj + po < a + b){
              cout << "Yes" << endl;
              pj++;
          } else{
              cout << "No" << endl;
          }
       } else {
           if((pj + po) < (a + b) && (co + 1) <= b){
               cout << "Yes" << endl;
               po++;
           } else{
               cout << "No" << endl;
           }
           co++;
       }
   }
   return 0;
}


Measured memory_bytes: 3708
#include<stdio.h>

int main(void)
{
	char mas[8][8];
	int i, j;
	while(scanf( "%s", mas[0]) != EOF ) {

		for( i = 1; i < 8; i++ )
			scanf( "%s", mas[i]);

		for( i = 0; i < 8; i++ ) {
			for( j = 0; j < 8; j++ ) {
				if( mas[i][j] == '1' ){
					if( mas[i + 1][j + 1] == '1' && mas[i + 1][j] == '1' && mas[i][j + 1] == '1' )
						putchar('A');
					if( mas[i + 3][j] == '1' )
						putchar('B');
					if( mas[i][j + 3] == '1' )
						putchar('C');
					if( mas[i + 2][j - 1] == '1' )
						putchar('D');
					if( mas[i + 1][j + 2] == '1' )
						putchar('E');
					if( mas[i + 2][j + 1] == '1' )
						putchar('F');
					if( mas[i + 1][j - 1] == '1' && mas[i][j + 1] == '1')
						putchar('G');
					goto next;
				}
			}
		}

next:
		putchar('\n');
	}

	return 0;
}

Measured memory_bytes: 524
#全探索をA,B,C一度で分けた
# RE 1   ac 19

# 初期入力
import copy
from itertools import combinations
import sys
input = sys.stdin.readline  #文字列では使わない
N,A,B,C = (int(i) for i in input().split())
l =[0]*N
for i in range(N):
    l[i] = int(input())

# A,B,Cどの竹を選ぶかcombination
mp=[]
for na in range(1,N-1):
    for ja in combinations(l,na):

        l_b =copy.copy(l)
        for i2 in ja:
            if i2 in l_b:
                l_b.remove(i2)
        for nb in range(1,N):
            for jb in combinations(l_b ,nb):

                l_c =copy.copy(l_b)
                for i3 in jb:
                    if i3 in l_c:
                        l_c.remove(i3)
                for nc in range(1,N+1):
                    for jc in combinations(l_c ,nc):
                        
                        # MPの消費量＝（求める長さー今回選んだ竹の長さ合計）+10*（合成魔法の回数)
                        AA =abs(A-sum(ja)) +10*(na-1)
                        BB =abs(B-sum(jb)) +10*(nb-1)
                        CC =abs(C-sum(jc)) +10*(nc-1)
                        mp.append(AA +BB +CC)


print(min(mp))

Measured memory_bytes: 11124
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		// 自分の得意な言語で
		// Let's チャレンジ！！

		Scanner sc = new Scanner(System.in);
		String n = sc.next();
		char[] cAr = n.toCharArray();

		System.out.println(++cAr[0]);

	}

}

Measured memory_bytes: 21844
#include <iostream>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    string a;
    cin >> a;
    int n = a.size();
    bool ok = true;
    if (a[0] != 'A')
        ok = false;
    int il = 0;
    for (int i = 2; i <= n - 2; ++i)
        if (a[i] == 'C')
            ++il;
    if (il != 1)
        ok = false;
    for (int i = 0; i < n; ++i)
        if (a[i] != 'A' && a[i] != 'C' && (a[i] >= 'A' && a[i] <= 'Z'))
            ok = false;
    if (ok)
        cout << "AC";
    else
        cout << "WA";
    return 0;
}


Measured memory_bytes: 256
// =========
use std::cmp::{max, min};
use std::collections::{HashMap, HashSet};
use std::process::exit;

const MOD: usize = 1000000007;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    // var... 変数の識別子, $t...型を一つよむ
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        //ここで繰り返し
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    //
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    // 配列の最後のNestではここで型が指定されてparseされる
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
// =========
fn gcd(a: usize, b: usize) -> usize {
    if b == 0 {
        return a;
    } else if a < b {
        return gcd(a, b % a);
    } else {
        return gcd(b, a % b);
    }
}

fn main() {
    input! {
        n: usize,
        a: [usize;n],
    }
    let mut cur = 0;
    for e in a {
        if cur + 1 == e {
            cur = e;
        }
    }
    if cur != 0 {
        println!("{:?}", n - cur);
    } else {
        println!("{:?}", -1);
    }
}


Measured memory_bytes: 8444
using System;

namespace ABC150B
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var S = Console.ReadLine();
            var count = 0;
            for (var i = 0; i < N - 2; i++)
            {
                if (S.Substring(i, 3) == "ABC")
                {
                    ++count;
                }
            }

            System.Console.WriteLine("{0}", count);
            Console.ReadLine();
        }
    }
}


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

// GNU C Compiler
//template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

// type
using ll = int_fast64_t;
using ull = uint_fast64_t;
using LL = long long;
using ULL = unsigned long long;
using PII = pair<int, int>;
//using pair<T1, T2> = p12;

//container
#define PB emplace_back
#define MP make_pair 
#define SZ(a) int((a).size())
#define ALL(v) v.begin(),v.end()

//repetition
#define REP(n) for(ll i=0; i<(n); i++)
#define REPj(n) for(ll j=0; j<(n); j++)
#define REPinit(i,a,n) for(ll i=(a); i<(n); i++)
#define REPinitj(j,a,n) for(ll j=(a); j<(n); j++)

//algorithm
#define SORT(c) sort((c).begin(),(c).end())
#define CONTAINER_ALL(a) a.begin(),a.end()

//constant

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//Optimizer
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")


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

    int A, B;
    cin >> A >> B;

    if (B % A == 0) cout << (A + B) << endl;
    else cout << (B - A) << endl;

    return 0;
}


Measured memory_bytes: 3652