akhauriyash/Code-Regression huggingface dataset:
/**
*    author:  yuya1234
*    created: 26.06.2020 16:26:38
**/

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)

#define SORT(s) sort((s).begin(),(s).end())
#define SORTD(s) sort((s).rbegin(),(s).rend())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define SZ(x) ((int)(x).size())
#define MEMSET(v, h) memset((v), h, sizeof(v))

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

    int a,b,c;
    cin>>a>>b>>c;

    string ans="NO";
    for (size_t i = 1; i < 100; i++)
    {
        if((i*a)%b==c)
        {
            ans="YES";
            break;
        }
    }
    
    cout<<ans<<endl;

    return 0;
}

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

int main() {
	// your code goes here
string  m,n;
int l;
    cin>>l;
    cin>>m>>n;
    for(int i=0;i<l;i++)
    {
        cout<<m[i]<<n[i];
    }

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ull unsigned long long
#define ll long long
#define il inline
#define db double
#define ls rt << 1
#define rs rt << 1 | 1
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define pll pair<ll, ll>
#define X first
#define Y second
#define pcc pair<char, char>
#define vi vector<int>
#define vl vector<ll>
#define rep(i, x, y) for(int i = x; i <= y; i ++)
#define rrep(i, x, y) for(int i = x; i >= y; i --)
#define rep0(i, n) for(int i = 0; i < (n); i ++)
#define per0(i, n) for(int i = (n) - 1; i >= 0; i --)
#define ept 1e-9
#define INF 0x3f3f3f3f
#define sz(x) (x).size()
#define All(x) (x).begin(), (x).end()
#define lowbit(x) ((x) & -(x))
using namespace std;
inline int read()
{
	int x = 0, f = 1; char ch = getchar();
	while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); }
	while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); }
	return x * f;
}
inline ll read1()
{
	ll x = 0, f = 1; char ch = getchar();
	while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); }
	while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); }
	return x * f;
}
const ll mod = 1e9 + 7;
const int N = 4e6 + 10;
const db pi = acos(-1);
int a[N];
int main()
{
	int n = read();
	rep(i, 1, n)
		a[i] = read();
	int q = read();
	while(q --)
	{
		int l = read();
		int r = read();
		int p = read(); 
		l ++;
		int ans = 0;
		rep(i, l, r) if(a[i] == p) ans ++;
		cout << ans << endl;
	}
	return 0;
}



Measured memory_bytes: 3112
from collections import deque
mod = 1000000007

n,k = map(int, input().split())
path = [[] for i in range(n)]
for i in range(n-1):
    a, b = map(int, input().split())
    path[a-1].append(b-1)
    path[b-1].append(a-1)

que = deque()
que.append(0)

used = [False] * n #既に見たかの判定リスト
used[0] = True # 最初の頂点は見たことになる
ans = k

while que:
    i = que.popleft()
    if i == 0: #最初の頂点では、色の選択肢は自分以外
        c = k-1
    else:
        c = k-2 # それ以降は親と自分以外

    for e in path[i]:
        if used[e]: continue
        used[e] = True
        ans = (ans * c) % mod # DFSで木の色を埋めていく
        c -= 1
        que.append(e)

print(ans)


Measured memory_bytes: 23832
import java.util.*;
class Main{
	public static void main(String[] args){
		Scanner in = new Scanner(System.in);
		long N = Long.parseLong(in.next());
		boolean breakFlag = false;
long h,n,w;
		h=1;
		n=1;
		w=1;
//		for (h = 1; h <= 3500; h++){
			for (n = 1; n <= 3500; n++){
				for (w = 1; w <= 3500; w++){
					if(4*n*w>N*(n+w))h=N*n*w/(4*n*w-N*(n+w));
					if(4*h*n*w==N*(h*n+n*w+w*h)){
						breakFlag = true;
					}
					if(breakFlag)break;
				}if(breakFlag)break;
			}/*if(breakFlag)break;
		}*/
		System.out.println(h+" "+n+" "+w);
	}
}

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

using namespace std;

const int maxn = 100010;

int n,ans,c[maxn],dp[3][maxn],num[maxn],root,MA;
vector<int> g[maxn];

void dfs1(int u,int pa) {
    num[u] = c[u];
    for (auto v : g[u])
        if (v!=pa) {
            dfs1(v,u);
            num[u]+=num[v];
        }
}

void dfs2(int u,int pa) {
    int tmp = (c[u] ? 2:0);
    for (auto v : g[u])
        if (v!=pa && num[v]>0) {
            ans+=2;
            dfs2(v,u);
            if (dp[0][u] < dp[0][v] + tmp) {
                dp[1][u] = dp[0][u];
                dp[0][u] = dp[0][v] + tmp;
            } else if (dp[1][u] < dp[0][v] + tmp) {
                dp[1][u] = dp[0][v] + tmp;
            }
        }
    MA = max(MA,dp[0][u] + dp[1][u] - tmp);
}

int main() {
    //freopen("in.txt","r",stdin);
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin>>n;
    for (int i=1;i<n;i++) {
        int x,y;
        cin>>x>>y;
        g[x].push_back(y);
        g[y].push_back(x);
    }
    string ts;
    cin>>ts;
    for (int i=0;i<ts.length();i++) c[i+1] = (ts[i]=='W');
    for (int i=1;i<=n;i++)
        if (c[i]) {
            root = i;
            break;
        }
    dfs1(root,-1);
    for (int u=1;u<=n;u++)
        if (num[u]>0) {
            for (auto v : g[u])
                if (num[v]>0) c[u] ^= 1;
            ans += c[u];
        }
    dfs2(root,-1);
    cout<<ans - MA;
}


Measured memory_bytes: 15696
import sys
from collections import deque

input = sys.stdin.readline


def main():
    S = input().rstrip()

    stack = deque()
    ans = 0
    for s in S:
        if len(stack) == 0:
            stack.append(s)
        else:
            if stack[-1] != s:
                stack.pop()
                ans += 2
            else:
                stack.append(s)

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 4212
#include<bits/stdc++.h>
// Begin Header {{{
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i,n) for(ll i=0; i<n; i++)
#define loop(i, j, n) for(ll i=j; i<n; i++)
#define all(x) (x).begin(), (x).end()
constexpr int INF  = 0x3f3f3f3f;
const long long mod=1e9+7;
const long double PI = acos(-1);
// }}} End Header

int main() {
	int n;
	double ans=0;
	cin >> n;
	rep(i,n){
		double x; string s;
		cin >> x >> s;
		if(s == "JPY") ans+=x;
		else ans+=380000*x;
	}
	printf("%.15f", ans);
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
    int n,w,i,j,a,b;cin >> n >> w;
    int dp[n+1][w+1] = {};
    for(i=1;i<=n;i++){
        cin >> a >> b;
        for(j=0;j<b;j++) dp[i][j] = dp[i-1][j];
        for(j=b;j<=w;j++) dp[i][j] = max(dp[i-1][j],dp[i-1][j-b]+a);
    }
    cout << dp[n][w] << endl;
}


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

int main() {
    int a,b; cin >> a >> b;
    int res = 0;
    int plug = 1;
    while (true) {
        if (plug >= b) break;
        plug--;
        plug += a;
        res++;
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 256
MOD = int(1e9)+7
def main():
    H, W = map(int, input().split())
    mat = []
    for i in range(H):
        mat.append(input())

    ways = [[0]*(W+1) for i in range(H+1)]
    ways[0][1] = 1
    for i in range(1, H+1):
        for j in range(1, W+1):
            if mat[i-1][j-1] != '#':
                ways[i][j] = (ways[i-1][j]+ways[i][j-1])%MOD
    print(ways[H][W])


if __name__ == "__main__":
    main()


Measured memory_bytes: 51440
#include<iostream>
#include<sstream>
#include<map>
#include<vector>
#include<algorithm>
using namespace std;

struct SGreater{
  bool operator() (pair<int, string> a,pair<int, string> b)
  {
    if(a.first!=b.first)
      return a.first>b.first;
    else
      return a.second<b.second;
  }
};

int main()
{
  int n;
  for(;cin>>n,n;)
    {
      vector<pair<int, string> >data;
      map<string,int> hash;
      string aa;
      getline(cin,aa);
      for(int i=0;i<n;i++)
	{
	  string str;
	  getline(cin,str);
	  //	  cout<<str<<endl;
	  istringstream os(str);
	  string buf;
	  for(;os>>buf;)
	    {
	      if(hash.find(buf)==hash.end())
		{
		  hash[buf]=data.size();
		  data.push_back(make_pair(1,buf));
		  //		  cout<<"not Hit"<<endl;
		}
	      else
		{
		  
		  data[hash[buf]].first++;
		  //		  cout<<"Hit"<<endl;
		}
	    }	 
	}
      sort(data.begin(),data.end(),SGreater());
      char top;
      //      int max=-1;
      int cnt=0;
      cin>>top;
      for(int i=0;i<data.size();i++)
	{
	  if(cnt>=5)
	    break;
	  if(data[i].second[0]==top)
	    {
	      if(cnt!=0)
		cout<<" ";
	      cout<<data[i].second;
	      // max=data[i].first;
	      cnt++;
	    }
	  
	}
      if(cnt==0)
	cout<<"NA";
      cout<<endl;
    }
}

Measured memory_bytes: 1252
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String str = sc.next();
        int n = str.length();
        char st = str.charAt(0);
        char go = str.charAt(n - 1);
        int m = n - 2;
        System.out.print(st);
        System.out.print(m);
        System.out.println(go);


    }
}

Measured memory_bytes: 21844
import sys

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

tin=lambda : map(int, input().split())
lin=lambda : list(tin())
mod=1000000007

#+++++

def main():
	n = int(input())
	#b , c = tin()
	#s = input()
	al = lin()
	aax=0
	for v in al:
		aax = aax^v
	ret = [v^aax for v in al]
	print(*ret)
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Measured memory_bytes: 115172
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;

namespace MyProject
{
    class Program
    {
        static void Main(string[] args)
        {
#if Local
            var sw = new Stopwatch();
            sw.Start();
            Console.SetIn(new StreamReader("input.in"));
#endif

            var solver = new Solver();
            solver.Solve();
#if Local
            Console.WriteLine($"{sw.ElapsedMilliseconds}ms");
#endif
        }
    }

    class Solver
    {
        public void Solve()
        {
            var item = Console.ReadLine().Split().Select(elem => int.Parse(elem)).ToArray();
            var N = item[0];
            var M = item[1];
            var answer = (N * (N - 1)) / 2;
            answer += (M * (M - 1)) / 2;
            Console.WriteLine(answer);
        }
    }
}


Measured memory_bytes: 13396
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl
#define doublecout(a) cout<<fixed<<setprecision(15)<<a<<endl;
#define Cerr(x) cerr<<(x)<<endl
#define fi first
#define se second
#define P pair<ll,ll> 
#define m_p make_pair
#define V vector<ll> 

ll n,cnt,ans,a,b,c,tmp,tmpp,m,h,w,x,y,sum,pos,k;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz");
char s[2005][2005];
bool fl;
struct edge{int to,cost;};
ll l[2005][2005],r[2005][2005],u[2005][2005],d[2005][2005];

//-------------------------↓↓↓↓↓↓------------------------

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

    cin>>h>>w;
    rep(i,h)rep(j,w)cin>>s[i][j];
    rep(i,h){
        rep(j,w){
            if(s[i][j]=='.'){
                l[i][j]++;
                r[i][j]++;
                u[i][j]++;
                d[i][j]++;
            }
        }
    }
    rep(i,h){
        rrep(j,1,w){
            if(s[i][j]=='#')continue;
            l[i][j]+=l[i][j-1];
        }
    }
    rep(i,h){
        rrrep(j,w-2,0){
            if(s[i][j]=='#')continue;
            r[i][j]+=r[i][j+1];
        }
    }
    rep(j,w){
        rrep(i,1,h){
            if(s[i][j]=='#')continue;
            u[i][j]+=u[i-1][j];
        }
    }
    rep(j,w){
        rrrep(i,h-2,0){
            if(s[i][j]=='#')continue;
            d[i][j]+=d[i+1][j];
        }
    }
    rep(i,h){
        rep(j,w){
            if(s[i][j]=='.'){
                cnt=l[i][j]+r[i][j]+u[i][j]+d[i][j]-3;
                ans=max(ans,cnt);
            }
        }
    }
    Cout(ans);
    return 0;
}


Measured memory_bytes: 129792
#include<bits/stdc++.h>
using namespace std;
int main(){
	long long x,y,N,h,n,w;
	scanf("%lld",&N);
	for(h=1;h<=3500;++h)
		for(n=1;n<=3500;++n){
			x=(4*h*n-(h+n)*N),y=N*h*n;
			if(x>0&&y%x==0)
				return printf("%lld %lld %lld\n",h,n,y/x),0;
		}
}

Measured memory_bytes: 256
import sys

input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n,d = list(map(int, input().split()))
xy = [tuple(map(int, input().split())) for _ in range(n)]
class SAT2:
    def __init__(self, n):
        self.n = n
        self.ns = [[] for _ in range(2*n)]
    def add_clause(self, i, f, j, g):
        """(xi==f) and (xj==g)
        """
        n = self.n
        u0,u1 = (i,i+n) if f else (i+n,i)
        v0,v1 = (j,j+n) if g else (j+n,j)
        self.ns[u1].append(v0)
        self.ns[v1].append(u0)
    def solve(self):
        """強連結成分分解
        トポロジカルソート順の逆順に返す
        """
        preorder = {}
        lowlink = {}
        seen = [False]*(2*self.n)
        scc_queue = []
        i = 0  # Preorder counter
        # ans = [None]*(2*self.n)
        count = 1
        for source in range(2*self.n):
            if seen[source]:
                continue
            queue = [source]
            while queue:
                v = queue[-1]
                if v not in preorder:
                    i = i + 1
                    preorder[v] = i
                done = True
                for w in self.ns[v]:
                    if w not in preorder:
                        queue.append(w)
                        done = False
                        break
                if done:
                    lowlink[v] = preorder[v]
                    for w in self.ns[v]:
                        if seen[w]:
                            continue
                        if preorder[w] > preorder[v]:
                            lowlink[v] = min([lowlink[v], lowlink[w]])
                        else:
                            lowlink[v] = min([lowlink[v], preorder[w]])
                    queue.pop()
                    if lowlink[v] == preorder[v]:
                        scc = {v}
                        while scc_queue and preorder[scc_queue[-1]] > preorder[v]:
                            k = scc_queue.pop()
                            scc.add(k)
                        for v in scc:
                            seen[v] = count
                        count += 1
                    else:
                        scc_queue.append(v)
        ans = [None]*self.n
        for i in range(self.n):
            if seen[i]==seen[i+self.n]:
                return None
            elif seen[i]>seen[i+self.n]:
                # 上流にxがある: x-> not x : x==False
                ans[i] = False
            else:
                ans[i] = True
        return ans

solver = SAT2(n)
for i in range(n):
    for j in range(i+1,n):
        if abs(xy[i][0]-xy[j][0])<d:
            solver.add_clause(i,False,j,False)
        if abs(xy[i][0]-xy[j][1])<d:
            solver.add_clause(i,False,j,True)
        if abs(xy[i][1]-xy[j][0])<d:
            solver.add_clause(i,True,j,False)
        if abs(xy[i][1]-xy[j][1])<d:
            solver.add_clause(i,True,j,True)
ans = solver.solve()
if ans is not None:
    print("Yes")
    write("\n".join(map(str, [xy[i][0 if ans[i] else 1] for i in range(n)])))
else:
    print("No")

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

using namespace std;

int main(){
  int A,B,C,tmp;
  cin >> A >> B >> C;
  if(A<B){
    tmp=A;
    A=B;
    B=tmp;
  }
  if(B<C){
    tmp=B;
    B=C;
    C=tmp;
  }
  if(A<B){
    tmp=A;
    A=B;
    B=tmp;
  }
  cout << A*10+B+C << endl;
  return 0;
}
  
  
    

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
#include <cstdio>
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>

using namespace std;

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

int tx[] = {1,-1};

static const double EPS = 1e-8;

int main(){
	string buf;
	string lhs = "qwertasdfgzxcvb";
	string rhs = "yuiophjklnm";
	sort(lhs.begin(),lhs.end());
	sort(rhs.begin(),rhs.end());

	while(cin >> buf){
		if(buf == "#") break;
		int res = 0;
		bool flag = (lhs.find(buf[0]) != string::npos ? true : false);
		for(int i=1;i<buf.size();i++){
			bool old_flag = flag;
			flag = (lhs.find(buf[i]) != string::npos ? true : false);
			if(old_flag != flag) res++;
		}

		printf("%d\n",res);
	}
}

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

signed main() {
  int N;
  cin >> N;
  
  vector<vector<int>> hito(N, vector<int>(N));
  for( int i = 0; i < N; i++ ){
    for( int j = 0; j < N; j++ ){
      hito.at(i).at(j) = -1;
    }
  }
  
  int A, X, Y;
  for( int i = 0; i < N; i++ ){
    cin >> A;
    for( int j = 0; j < A; j++ ){
      cin >> X >> Y;
      hito.at(i).at(X-1) = Y;
    }
  }
  
  int ans = 0;
  for (int bit = 0; bit < (1<<N); ++bit){
    int cnt = 0;
    bool fg = true;
    for (int i = 0; i < N; ++i) {
      if (bit & (1<<i)) { // i が bit に入るかどうか
        for( int j  = 0; j < N; j++ ){
          //if( hito.at(i).at(j) == 1 && hito.at(j).at(i) == 0 ) fg = false;
          if(hito.at(i).at(j) == -1) continue;
          if (bit & (1<<j)){
            if( hito.at(i).at(j) == 0 ) fg = false;
            //if( hito.at(j).at(i) == 0 ) fg = false;
          }
          else{
            if( hito.at(i).at(j) == 1 ) fg = false;
            //if( hito.at(j).at(i) == 1 ) fg = false;
          }
        }
        if( fg == true ) cnt++;
      }
    }
    if(fg == true) ans = max( ans, cnt );
  }
  cout << ans << endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int  N, M;

  cin >> N >> M;

  vector<vector<int>> gate(M, vector<int>(2));

  for(int i = 0; i < M; i++){
      cin >> gate.at(i).at(0);
      cin >> gate.at(i).at(1);
  }

  int correct = 0;

  //上限ゲートの最小値を求める
  //下限ゲートの最大値を求める
  //上限-下限が0以下の場合は0を出力
  //その間にあるかどうか検証
  int maximum, minimum; 
  maximum = gate.at(0).at(0); //下限ゲートの細大値
  minimum = gate.at(0).at(1); //上限ゲートの最小値

  for(int i = 1; i < M; i++){
    maximum = max(maximum, gate.at(i).at(0));
    minimum = min(minimum, gate.at(i).at(1));
  }

  if(maximum <= minimum){
    for(int j = 1; j < N + 1; j++){
      if(maximum <= j && minimum >= j){
        correct++;
      }
    }
  }else{
    correct = 0;
  }

  cout << correct << endl;
}

Measured memory_bytes: 5760
import sys
S = list(sys.stdin.readline().rstrip())
chars = [chr(ord("a") + i) for i in range(26)]
ans = 10**5
for c in chars:
    if c not in S:
        continue
    cnt = 0
    S_copy = S.copy()
    while len(set(S_copy)) > 1:
        S_tmp = []
        for i in range(len(S_copy) - 1):
            if S_copy[i] == c or S_copy[i + 1] == c:
                S_tmp.append(c)
            else:
                S_tmp.append(S[i])
        S_copy = S_tmp.copy()
        cnt += 1
    ans = min(ans, cnt)
print(ans) 

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
int main()
{
    int N; cin >> N;
    vector<Int> A(N); for (auto &a : A) cin >> a;
    vector<Int> dp(N);
    for (int i = 0; i < N; i++) {
        if (i-2 >= 0) {
            dp[i] = max({dp[i-2], dp[i-2] + A[i], A[i]});
        } else {
            dp[i] = A[i];
        }
    }
    int k = max_element(begin(dp), end(dp)) - begin(dp);
    vector<bool> used(N);
    for (; k >= 0; k -= 2) {
        if (dp[k] == A[k]) { used[k] = true; break; }
        else if (k >= 2 && dp[k] == A[k] + dp[k-2]) used[k] = true;
    }
    int curr = 0;
    vector<int> ans;
    while (used[curr] == 0) curr++, ans.push_back(1);
    while (curr < N) {
        assert(used[curr] == 1);
        int n = 0;
        while (curr+n+1 < N && used[curr+n+1] == 0) n++;
        curr += n + 1;
        while (n >= 3) n -= 2, ans.push_back(3);
        if (n == 2) ans.push_back(3), ans.push_back(2);
        if (n == 1) ans.push_back(2);
    }
    cout << *max_element(begin(dp), end(dp)) << '\n';
    cout << ans.size() << '\n';
    for (auto a : ans) cout << a << '\n';
    return 0;
}


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

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

  int sum = 0, l, r;
  for (int i = 0; i < N; i++) {
    cin >> l >> r;
    sum += r - l + 1;
  }
  cout << sum << endl;
}


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

int main(){

  int n, r, p, c, i, k;

  while(cin >> n >> r, n+r){
    int a[n+1];
    int down[n+1];
    for(i = 1; i <= n; i++){
      a[i] = n - i + 1;
      //cout << a[i] << endl;
    }
    for(k = 0; k < r; k++){
      cin >> p >> c;
      int j = 0;
      for(i = 1; i < p; i++){
        down[i] = a[i];
      }
      for(i = 1; i <= c; i++){
        a[i] = a[p - 1 + i];
      }
      for(i = 1; i < p; i++){
        a[c+i] = down[i];
      }
    }
    cout << a[1] << endl;
  }
  return 0;
}


Measured memory_bytes: 3072
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#define rep(i,n) for(int i=0; i<(n) ; i++)
using namespace std;

int main(){
	int h,w,k;
	cin>>h>>w>>k;
	vector<string> s(h);//要素数のベクトルを作成
	int ans=0;

	for(int i=0;i<h;i++) cin >> s[i]; //i行であるs[i]に文字列を入力

 //isを0から、1をhだけ左にシフトした値(h=6なら64)までループする
 //js を0から最大64までループする
	rep(is, 1<<h)rep(js,1<<w){
		int cnt=0;
		rep(i,h)rep(j,w){
			if((is>>i)&1)continue;//isにiのフラグが立っている(つまりi=is行目について)場合全てを無視
			if((js>>j)&1)continue;//
			if(s[i][j]=='#')cnt++;
		}
		if(cnt==k)ans++;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3600
#include <iostream>

using namespace std;

int main()
{int a,b,c,d,e,f,g,h,S,T;
cin>>a>>b>>c>>d>>e>>f>>g>>h;
 S=a+b+c+d;
 T=e+f+g+h;
 if(S>=T){
    cout<<S<<endl;
 }
 else{
    cout<<T<<endl;
 }
    return 0;
}



Measured memory_bytes: 3108
#include<iostream>
#include<vector>
#include<algorithm>
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;

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

    vector<vector<char> > table(H,vector<char>(W));
    
    rep(i,H){
        rep(j,W){
            cin >> table.at(i).at(j);
        }
    }

    bool flag;
    // row
    rep(i,H){

        flag = true;
        rep(j,W){
            if(table.at(i).at(j) == '#') flag = false;
        }
        if(flag) {
            // delete row i
            // table.erase(table.at(i).begin());
            table.erase(table.begin()+i);
            i--;
            H--;
        }
    }

    //column
    rep(j,W){
        flag = true;
        rep(i,H){
            if(table.at(i).at(j) == '#') flag = false;
        }
        if(flag) {
            // delete column j
            rep(i,H){
                table.at(i).erase(table.at(i).begin()+j);
            }
            j--;
            W--;
        }
    }

    //output
    rep(i,H){
        rep(j,W){
            cout << table.at(i).at(j);
        }
        cout << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a, b, c;
  cin >> a >> b >> c;
  int d = 100 * a + 10 * b + c;
    if(d % 4 == 0) cout << "YES" << endl;
  else cout << "NO" << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int n[4],e,f,i,a,b;
	for(i=0;i<4;i++)	{
	scanf("%d",&n[i]);
	}
	scanf("%d %d",&e,&f);
	a=100;
	b=0;
	for(i=0;i<4;i++)	{
		b=b+n[i];
		if(n[i]<a)	{
		a=n[i];
		}
	}
	b=b-a;
	if(e>f)	{
	b=b+e;
	}
	else	{
	b=b+f;
	}
	printf("%d\n",b);
	return 0;
}


Measured memory_bytes: 2756
//#include <tourist>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF =1e9;
const ll LINF=1e18;
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl; 
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; }
//setprecision(15)有効数字15桁
//-std=c++14
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b){return a / gcd(a, b)*b;}
int n, m;
vector<int> a;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int t;
    cin >> n>>t;
    priority_queue<int> que;
    for (int i = 0; i < t; i++)
    {
        int temp;
        cin >> temp;
        que.push(temp);
    }
    int prev=que.top();
    prev--;
    que.pop();
    while(!que.empty()){
        int temp=que.top();
        que.pop();
        if(prev!=0)
        que.push(prev);
        prev=temp;
        prev--;
    }
    cout << prev << "\n";
}



Measured memory_bytes: 256
//# define FLAG
///delet....................................
# include <iostream>
# include <cstring>
# include <cstdlib>
# include <cstdio>
# include <string>
# include <cmath>
# include <ctime>
# include <set>
# include <map>
# include <queue>
# include <stack>
# include <bitset>
# include <vector>
# include <fstream>
# include <algorithm>
using namespace std;
# define eps 1e-8
# define pb push_back
# define pi acos(-1.0)
# define bug puts("H");
# define mem(a,b) memset(a,b,sizeof(a))
# define IOS ios::sync_with_stdio(false);
# define FO(i,n,a) for(int i=n; i>=a; --i)
# define FOR(i,a,n) for(int i=a; i<=n; ++i)
# define INF 0x3f3f3f3f
# define MOD 1000000007
///           123456789
//# pragma comment(linker, "/STACK:1024000000,1024000000")
typedef unsigned long long ULL;
typedef long long LL;
inline int Scan(){
    int x=0,f=1; char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-') f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
///coding...................................

int main()
{
    IOS;
#ifdef FLAG
    freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
#endif /// FLAG
    string a;
    cin>>a;
    FOR(i,0,a.size()-1)if(a[i]!=a[a.size()-1-i]){cout<<"No"<<endl;return 0;}

    cout<<"Yes"<<endl;
    return 0;
}








Measured memory_bytes: 256
s = list(input())
t = list(input())

s = sorted(s)
t = sorted(t, reverse=True)

#print(s,t)
flag = [0,0]

if len(s) < len(t):
    for i in range(len(s)):
        if s[i]<t[i]:
            print('Yes')
            break
        elif s[i] > t[i]:
            print('No')
            break
        elif i == len(s)-1:
            print('Yes')
elif len(s) > len(t):
    for i in range(len(t)):
        if s[i]<t[i]:
            print('Yes')
            break
        elif s[i] > t[i]:
            print('No')
            break
        elif i == len(t)-1:
            print('No')
elif len(s) == len(t):
    for i in range(len(s)):
        if s[i]<t[i]:
            print('Yes')
            break
        elif s[i] > t[i]:
            print('No')
            break
        elif i == len(s)-1:
            print('No')


Measured memory_bytes: 9116
//by azidoazideazide(c2n14)
//C
#include<iostream>
#include<iomanip>
#include<vector>
#include<algorithm>
#include<queue>
using namespace std;
using ll=long long;

priority_queue<double, vector<double>, greater<double>> q;

int main(){
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	int n;
	cin>>n;
	for(int i=0,tt;i<n;i++){
		cin>>tt;
		q.emplace(tt); 
	}
	while(q.size()>1){
		double a=q.top();
		q.pop();
		double b=q.top();
		q.pop();
		double tt=(a+b)/2;
		q.emplace(tt);
	}
	cout<<fixed<<setprecision(6)<<q.top()<<endl;
}


Measured memory_bytes: 256
fn main() {
    let v = read_vec::<usize>();
    println!("{}", (v[0] - 1) * (v[1] - 1));
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 4352
<?php
$n=trim(fgets(STDIN));
$a=explode(" ",trim(fgets(STDIN)));
if($n==2){
  if($a[0]-$a[1]>$a[1]-$a[0]){
    echo $a[0]-$a[1].PHP_EOL;
    echo $a[0]." ".$a[1];
  }else{
    echo $a[1]-$a[0].PHP_EOL;
    echo $a[1]." ".$a[0];
  }
}else{
sort($a);

if($a[$n-1]<=0){
  $r=$a[$n-1];
  $sum=array_sum($a)-$r;
  echo $r-$sum.PHP_EOL;
  $i=2;
  while($i<=$n){
    echo $r." ".$a[$n-$i].PHP_EOL;
    $r-=$a[$n-$i];
    ++$i;
  }
}elseif($a[0]>=0){
  $r=$a[0];
  $sum=array_sum($a)-$r;
  echo $sum-$r.PHP_EOL;
  $i=2;
  while($i<$n){
    echo $r." ".$a[$n-$i].PHP_EOL;
    $r-=$a[$n-$i];
    ++$i;
  }
  echo $a[$n-1]." ".$r.PHP_EOL;
}else{
  $sum=0;
  $i=0;
  while($a[$i]<0){
    $sum-=$a[$i];
    ++$i;
  }
  echo array_sum($a)+2*$sum.PHP_EOL;
  $r=$a[0];
  $j=$i;
  while($i<$n-1){
    echo $r." ".$a[$i].PHP_EOL;
    $r-=$a[$i];
    ++$i;
  }
  $i=1;
  $s=$a[$n-1];
  while($i<$j){
    echo $s." ".$a[$i].PHP_EOL;
    $s-=$a[$i];
    ++$i;
  }
  echo $s." ".$r.PHP_EOL;
}
}

Measured memory_bytes: 14452
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
ll max(ll a, ll b)
{
    if(a>=b) return a; else return b;
}
ll min(ll a, ll b)
{
    if(a<=b) return a; else return b;
}
ll ans[100000][4];
ll f(ll a[][3],ll n,ll k)
{
    if(n==-1) return 0;
    if(n==0) { ans[0][0]=a[0][0]; ans[0][1]=a[0][1]; ans[0][2]=a[0][2]; ans[n][3]=max(max(ans[n][0],ans[n][1]),ans[n][2]); return ans[0][k];}
    if(ans[n][k]!=-1) return ans[n][k];
    
    ans[n][0]=max(a[n][0]+ f(a,n-1,1),a[n][0]+f(a,n-1,2));
    ans[n][1]=max(a[n][1]+ f(a,n-1,0),a[n][1]+f(a,n-1,2));
    ans[n][2]=max(a[n][2]+ f(a,n-1,0),a[n][2]+f(a,n-1,1));
    ans[n][3]=max(max(ans[n][0],ans[n][1]),ans[n][2]);
    return ans[n][k];
    
}
int main() {
    for(ll i=0;i<100000;i++) {ans[i][0]=-1; ans[i][1]=-1; ans[i][2]=-1; ans[i][3]=-1;}
    ll n;
    cin>>n;
    ll a[n][3];
    for(ll i=0;i<n;i++)
    {
        cin>>a[i][0]>>a[i][1]>>a[i][2];
    }
    cout<<f(a,n-1,3);
	return 0;
}


Measured memory_bytes: 13568
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <string>
#include <utility>
#include <vector>
#define REP(i, n) for(int i = 0; i < (n); ++i)
typedef long long ll;
const ll MOD = 1000000007;
using namespace std;

int main(){
    int n, ans = 0; cin >> n;
    string s; cin >> s;
    for(int i = 1; i < n; ++i){
        int cnt = 0;
        for(char c = 'a'; c <= 'z'; c++){
            bool lt = false, rt = false;
            REP(j, i) if(s[j] == c) lt = true;
            for(int j = i; j < n; ++j) if(s[j] == c) rt = true;
            if(lt && rt) ++cnt;
        }
        ans = max(ans, cnt);
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;

typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = (ll)1e9 + 7;

bool is_ok(int price, vector<int>& D)
{
  while (price > 0) {
    if (D[price % 10]) { return false; }
    price /= 10;
  }
  return true;
}

int main()
{
  int N, K; scanf("%d %d", &N, &K);
  vector<int> D(10, 0);
  int d;
  for (int i = 0; i < K; ++i) {
    scanf("%d", &d);
    D[d] = 1;
  }

  int ans = INF;
  for (int p = N; true; ++p) {
    if (is_ok(p, D)) {
      ans = p;
      break;
    }
  }
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(a) (a).begin(), (a).end()
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1; (i)>=0; (i)--)
#define ios() cin.tie(0), ios::sync_with_stdio(false)
typedef long long ll;
typedef unsigned long long ull;
ll const MOD = 1e9+7;
ll const INF = 1e18;
using namespace std;

int main(){
    string s;
    cin >> s;
    int n = (s[5] - '0')*10 + (s[6] - '0');
    if(n <= 4){
        cout << "Heisei" << endl;
    }else{
        cout << "TBD" << endl;
    }
    return 0;
}

Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(k,i,n) for(ll i=k;i<n;++i)
int main(void){
    ll a,b;
    cin>>a>>b;
    if(b%a==0){
        cout<<a+b<<endl;
    }else{
        cout<<b-a<<endl;
    }
}

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

using namespace std;

const int mo = 1e9 + 7;
const int Maxn = 200001;

long long f[2][Maxn], m[Maxn];
vector<int> v;
int n, k, siz, nx;

int main() {
    cin >> n >> k;
    for(int i = 1; i * i <= n; ++i) 
        v.push_back(i), v.push_back(n / i);
    stable_sort(v.begin(), v.end());
    v.erase(unique(v.begin(), v.end()), v.end());
    siz = v.size();
    m[0] = 1;
    f[0][0] = 1;
    for(int i = 1; i < siz; ++i)
        m[i] = v[i] - v[i - 1], f[0][i] = m[i];
    for(int i = 1; i < k; ++i) {
        nx = (i & 1);
        long long sum = 0;
        memset(f[nx], 0, sizeof(f[nx]));
        for(int j = 0; j < siz; ++j) {
            sum += f[nx ^ 1][j];
            sum %= mo;
            f[nx][siz - j - 1] += sum * m[siz - j - 1] % mo;
            f[nx][siz - j - 1] %= mo;
        }
    }
    long long ans = 0;
    for(int i = 0; i < siz; ++i)
        ans += f[nx][i];
    cout << ans % mo << endl;
    return 0;
}

Measured memory_bytes: 4228
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n;
int a[105];
int na[105];
int b[105];

int main(void){
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d",&b[i]);
    }
    for(int i=0;i<n;i++){
        if(b[i]>i+1){
            printf("-1\n");
            return 0;
        }
        for(int j=0;j<b[i]-1;j++){
            na[j]=a[j];
        }
        na[b[i]-1]=b[i];
        for(int j=b[i]-1;j<i;j++){
            na[j+1]=a[j];
        }
        for(int j=0;j<i+1;j++){
            a[j]=na[j];
        }
    }
    for(int i=0;i<n;i++){
        printf("%d\n",a[i]);
    }
    return 0;
}




Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <algorithm>
#include <cstdio>
#include <string>

#define rep(x,to) for(int x=0;x<to;x++)
#define rep2(x,from,to) for(int x=from;x<to;x++)

using namespace std;


int main(void){

int cnt=0;
int sc[7] ={1000,500,100,50,10,5,1};
string ss[7] ={"M","D","C","L","X","V","I"}, wk, wwk;
map<string, int> rtb;

//	rep(i,7) rtb.insert(pair<string, int>(ss[i],sc[i]));
	rep(i,7) rtb[ss[i]] = sc[i];
	while(!cin.eof()){
		cin >> wk;
		if(cin.eof()) break;
		int su=0;
		string w1,w2;
		rep(i,wk.size()){
			bool mn = false;
			w1 = wk[i];
			rep2(j,i+1,wk.size()){
				w2 = wk[j];
				if(rtb[w1] < rtb[w2 ]) mn = true;
			}
			if(mn) su -= rtb[w1];
			else   su += rtb[w1];
//			cout << rtb[wwk] << "-";
		}
		cout << su << endl;
		cnt++; if(cnt>50) break;
	}	
	
	return 0;
	
	
}

Measured memory_bytes: 1192
#include<bits/stdc++.h>
using namespace std;
#define REP(i,N) for(int (i)=0;(i)<(N);(i)++)
#define REPR(i,N) for(int (i)=(N);i>=0;i--)
#define FOR (i,m,n) for(int (i)=m;(i)<(n);(i)++)

int main(){
  int N, total=0, temp_N=0;
  cin >> N;

  REP(i,8){
    temp_N=N/pow(10,i);
    total+=temp_N%10;
  }

  if(N%total)cout << "No" << endl;
  else cout << "Yes" << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int ketanowa(int n)
{
    int a=0;
    while(n>0){
        a+=n%10;
        n/=10;
    }
    return a;
}
int main(void)
{
    int n,i,min=114514;
    cin>>n;
    for(i=1;i<n;i++){
        if(ketanowa(i)+ketanowa(n-i)<min){
            min=ketanowa(i)+ketanowa(n-i);
        }
    }
    cout<<min;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>
int main()
{
    long long int N,L;
    scanf("%lld %lld",&N,&L);
    long long int sum=0,flag=0,flag1=0,i,ara[10000];
    for(i=1;i<=N;i++)
    {
        ara[i]=L+i-1;
        if(ara[i]==0)
        {
            flag=1;
        }
        if(ara[1]<0)
        {
            flag1=1;
        }
        else if(ara[1]>0)
        {
            flag1=-1;
        }
        sum+=ara[i];
    }
    if(flag)
    {
        printf("%lld\n",sum);
    }
    else if(flag1==1)
    {
        printf("%lld\n",sum-ara[N]);
    }
    else if(flag1==-1)
    {
        printf("%lld\n",sum-ara[1]);
    }
    return 0;
}

Measured memory_bytes: 128
using System;

namespace DefaultNamespace
{
	
	public class Stuck
	{
		public static int sPointer=0;
		public static int[] stuck=new int[101] ;
		public  static void Main(string[] args)
		{
			string read=Console.ReadLine();
			string[] dataArray=read.Split();
			Console.WriteLine(answer(dataArray));
			
		}
		public static int answer(string[] s)
		{
		   // ?????????????????????push ???????????????pop ?????????????????????????????\
		   //string?????????s[]????????????????????????????????????????????????????????????????????????????????????????????????
		   for(int i=0;i<s.Length;i++){
		   int number=0;
		   if(int.TryParse(s[i],out number))
		      {
		   	push(number);
		      }
		   else{//???????????????????????????????????????
		   	calc(s[i]);
		   }
		   }
		   return stuck[1];
		}
		public static  void push(int num)
		{
			sPointer++;
			stuck[sPointer]=num;
			
		}
		
		public  static void calc(string ope)
		{//???????????????????????§switch
			int temp=0;
			switch(ope){
					case "+": temp =stuck[sPointer-1]+stuck[sPointer];
					break;
					case "-": temp =stuck[sPointer-1]-stuck[sPointer];
					break;
					case "*": temp =stuck[sPointer-1]*stuck[sPointer];
					break;
					case "/": temp=stuck[sPointer-1]/stuck[sPointer];
					break;
			}
			sPointer-=2;
			push(temp);
			
		}
		
	}
}

Measured memory_bytes: 9132
#include <stdio.h>

int main(void){
	int a,b,c,d,p,ryx,ryy;
	scanf("%d%d%d%d%d",&a,&b,&c,&d,&p);
	ryx=a*p;
	if(p>c){
	ryy=b+d*(p-c);
	}
	else{ryy=b;}
	if(ryx<ryy){printf("%d\n",ryx);}
	else{printf("%d\n",ryy);}
	return 0;
}

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

int main() {
  string s, t;
  cin >> s >> t;
  int n = s.size();
  int m = t.size();

  int ans = 1e9;
  for (int i = 0; i <= n - m; i++) {
    int tmp = 0;
    for (int j = 0; j < m; j++) {
      if (s.at(i + j) != t.at(j)) tmp++;
    }
    ans = min(ans, tmp);
  }

  cout << ans << endl;
  return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> d(n);
  rep(i, n) cin >> d[i];
  sort(d.begin(), d.end());
  d.erase(unique(d.begin(), d.end()), d.end());
  cout << d.size() << endl;
  return 0;
}

Measured memory_bytes: 3620
#include <iostream>
#include <array>
#include <algorithm>

int main() {
  unsigned int K, A, B;
  std::cin >> K >> A >> B;

  const int trade = B - A;
  if (trade <= 2) {
    std::cout << 1 + K << std::endl;
    return 0;
  }

  const size_t trade_preparation_num = A - 1;
  const size_t trade_num = (K - trade_preparation_num) / 2;
  std::cout << 1 + trade_preparation_num + trade_num * trade + (K - trade_preparation_num - trade_num * 2) << std::endl;

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
 
int main(){
  int a, b, c;
  while(scanf("%d%d%d", &a, &b, &c) && (a != -1 || b != -1 || c != -1)){
    if(a < 0 || b < 0) puts("F");
    else if(a + b >= 80) puts("A");
    else if(a + b >= 65) puts("B");
    else if(a + b >= 50 || c >= 50) puts("C");
    else if(a + b >= 30) puts("D");
    else puts("F");
  }
  return 0;
}


Measured memory_bytes: 2036
// Problem : 
// 			C - Walking Takahashi
// 			Editorial
// 		
// Contest : AtCoder - AtCoder Beginner Contest 175
// URL : https://atcoder.jp/contests/abc175/tasks/abc175_c
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

// #pragma GCC optimize("Ofast")
// #pragma GCC target("avx,avx2,fma")
// #pragma GCC optimization ("unroll-loops")

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define fo(i,n)         for(int i=0;i<n;i++)
#define Fo(i,k,n)       for(int i=k;i<n;i++) 
#define endl            "\n"
#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define vec(x)          vector<x>
#define matrix(x)       vector<vector<x>>
#define sz(x)           (int)x.size()
#define mem(a,b)        memset(a, b, sizeof a)
#define vii             vector<pair<int,int>>
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define gcd(a,b)        __gcd(a,b)
#define lcm(a,b)        (a*(b/gcd(a,b)))
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define MOD             998244353
#define deb(x)          cerr <<#x<<" = "<<x<<"\n"
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define all(v)          v.begin(),v.end()
#define rep(i,a,b)      for (int i = a; i<b; ++i)
#define len(s)          s.length()
#define watch(x)        cout << #x << " = " << x << endl
#define trace(x)        cerr << #x << " = " << x << endl
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());
 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
 
 
int power(int a,int b,int m=mod)
{int ans=1;while(b>0){if(b&1)ans=(ans*a)%m;a=(a*a)%m;b>>=1;}
return ans;}

void babuBhaiya()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
}

const int N = 1e5+1;
const double pi = acos(-1);

void solve(){
    
	int x,k,d; cin>>x>>k>>d;
	x = abs(x);
	if(x/d>=k){
		x -= k*d;
		cout<<x;
	}
	else{
		int y = x/d;
		x -= y*d;
		k -= y;
		if(k&1) cout<<min(abs(x-d),abs(x+d));
		else cout<<abs(x);
	}
	
}

 
int32_t main()
{
    babuBhaiya();

    int t;

    t = 1;
    //cin>>t;

    while(t--){
        solve();
    }
    
    return 0;
}

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

using namespace std;

int main(void) {
	int num, a, b, i, t = 0;
	bool ok = true;
	cin >> num;
	vector<pair<int, int>> d(num);
	for (i = 0; i < num; i++) {
		scanf("%d%d", &a, &b);
		d[i] = make_pair(b, a);
	}
	sort(d.begin(), d.end());
	for (i = 0; i < num; i++) {
		t += d[i].second;
		if (t > d[i].first) {
			ok = false;
			break;
		}
	}
	if (ok)
		printf("Yes\n");
	else
		printf("No\n");
	return 0;
}

Measured memory_bytes: 1792
import heapq

n = int(input())
a = []

for i in range(1, n+1):
  av = -int(input())
  heapq.heappush(a, (av, i))

fst = heapq.heappop(a)
sec = heapq.heappop(a)

for i in range(1,n+1):
  if i == fst[1]:
    print (-sec[0])
  else:
    print (-fst[0])

Measured memory_bytes: 31624
#include <iostream>
using namespace std;
 
int main()
{
    int N,a,b,c,i,j;
    cin>>N;
    int A[3*N];
    for(i=0;i<N;i++)
    {
        int a,b,c;
        cin>>a>>b>>c;
        j=3*i;
        A[j] = a;
        A[j+1] = b;
        A[j+2] = c;
        
    }
    for (i=0;i<3*N;i=i+3)
    {
        if (A[i]*A[i]==A[i+1]*A[i+1]+A[i+2]*A[i+2] || A[i+1]*A[i+1]==A[i]*A[i]+A[i+2]*A[i+2] || A[i+2]*A[i+2]==A[i]*A[i]+A[i+1]*A[i+1])
        cout<<"YES"<<"\n";
        else
        cout<<"NO"<<"\n";
    }
}

Measured memory_bytes: 1128
#include <cstdio>
#include <vector>
#include <string>
#include <iostream>
using namespace std;
 
int main() {
    int H, W;
    scanf(" %d %d", &H, &W);

    vector<vector<char> > a(H+2, vector<char>(W+2, '#'));

    for (int i = 0; i < H; i++) {
        string str;
        cin >> str;
        for (int j = 0; j < W; j++) {
            a[i+1][j+1] = str[j];
        }
    }

    for (int i = 0; i < H+2; i++) {
        for (int j = 0; j < W+2; j++) {
            cout << a[i][j];
        }
        cout << endl;
    }
}

Measured memory_bytes: 256
LI = lambda: list(map(int, input().split()))

W, H, x, y = LI()


def main():
    s = W * H / 2
    if 2 * x == W and 2 * y == H:
        t = 1
    else:
        t = 0
    print(s, t)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9084
N,K=map(int,input().split())
A=list(map(int,input().split()))
B=[1]
C=["#"]*N
roop=False
for i in range(K):
    if C[B[i]-1]=="#":
        C[B[i]-1]="$"
    else:
        roop=True
        break
    B.append(A[B[i]-1])
if roop==True:
    f=B.index(B[i])
    T=i-f
    if T==0:
        print(B[f])
    else:
        r=(K-f)%T
        print(B[f+r])
else:
    print(B[K])


Measured memory_bytes: 32296
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<vector>
#include<cstdlib>
#include<map>
#include<queue>
#include<stack>
#include<deque>
#include<fstream>
#include<string>
#include<sstream>
#include<iomanip>
#include<numeric>
#include<cctype>
#include<random>

using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long int I;

int keta(int a){
    int count=0;
    while(a!=0){
        a/=10;
        count++;
    }
    return count;
}


int main(){
    long long int n,m,cnt=0,sum=0;
    cin>>n>>m;
    vector<int> a(n);
    for(int i=0;i<n;i++){
        cin>>a.at(i);
    }
    sort(a.begin(),a.end(),greater<int>());
    for(int i=m;i<n;i++){
        sum+=a.at(i);
    }
    cout<<sum<<endl;
 


    return 0;
} //カモンAC

Measured memory_bytes: 1024
S = input()
S1 = int(S[0] + S[1])
S2 = int(S[2] + S[3])

if 1 <= S1 <= 12 and 1 <= S2 <= 12:
    print('AMBIGUOUS')
elif 1 <= S1 <= 12:
    print('MMYY')
elif 1 <= S2 <= 12:
    print('YYMM')
else:
    print('NA')

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;
#define FOR(i,a,n) for(ll i=(ll)a;i<(ll)n;i++)
#define RFOR(i,a,n) for(ll i=(ll)n-1;i >= (ll)a;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,0,n)
#define ALL(v) v.begin(), v.end()
#define bra(first,second) '(' << first << ',' << second << ')'
ll MOD = 1000000007;
//ll INF = 21474836470000000;
ll INF = 1001001001001001001;
long double EPS = 1e-11;
long double PI = 3.141592653589793238;
template<typename T>
void remove(std::vector<T>& vector, unsigned int index){
    vector.erase(vector.begin() + index);
}

using Graph = vector<vector<ll>>;

int main(){
    ll N;
    cin >> N;
    vector<pair<string,ll>> A(N);
    rep(i,N) cin >> A[i].first >> A[i].second;
    string X;
    cin >> X;
    ll ans = 0;
    bool flag = 0;
    rep(i,N){
        if(flag) ans += A[i].second;
        if(X == A[i].first) flag = 1;
    }
    cout << ans << endl;
}


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

signed main() {
	int n;
	cin >> n;
	int t[n], a[n];
	for (int i = 0; i < n; i++) {
		cin >> t[i] >> a[i];
	}

	int t1, t2;
	t1 = t[0];
	t2 = a[0];
	for (int i = 1; i < n; i++) {
		int resa, resb;
		resa = (t1 % t[i]) ? (t1 / t[i] + 1) : (t1 / t[i]);
		resb = (t2 % a[i]) ? (t2 / a[i] + 1) : (t2 / a[i]);
		int res = max(resa, resb);
		t1 = res * t[i];
		t2 = res * a[i];
	}
	cout << t1 + t2 << endl;

	return 0;
}


Measured memory_bytes: 256