akhauriyash/Code-Regression huggingface dataset:
//52行目から編集
#include <iostream>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <cassert>

using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define eb emplace_back

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<int> > vvi;
typedef vector<vector<ll> > vvl;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;

template<class T> bool chmin(T& a,T b){if(a > b){a = b;return true;}else return false;}
template<class T> bool chmax(T& a,T b){if(a < b){a = b;return true;}else return false;}
///////////////////////////////////////////////////////////

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    //cout << fixed << setprecision(20);
    int a,b,c;cin >> a >>b >> c;
    cout << c << ' ' << a << ' ' << b << '\n';
    return 0;
}
/*
 *!!CHECK!! 
 * 制約をよく読め：まず最も愚直な解法を考えろ
 * intの掛け算をしてる場合：overflowは大丈夫？
 * 制約の下限・上限は大丈夫？
 * 木構造は一直線にした時TLEしない？
 * */


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import _collections
import string
from functools import lru_cache
import heapq

class cin():
    def int():
        return int(sys.stdin.readline().rstrip())
    def string():
        return sys.stdin.readline().rstrip()
    def mapInt():
        return [int(x) for x in cin.string().split()]
    def stringList(n):
        return [input() for i in range(n)]
    def intListList(n):
        return [cin.mapInt() for i in range(n)]
    def intColsList(n):
        return [int(input()) for i in range(n)]
        
class Math():
    def gcd(a,b):
        if b == 0:
            return a
        return Math.gcd(b,a % b)
    def lcm(a,b):
        return (a * b) // Math.gcd(a,b)
    def roundUp(a,b):
        return -(-a // b)
    def toUpperMultiple(a,x):
        return Math.roundUp(a,x) * x
    def toLowerMultiple(a,x):
        return (a // x) * x
    def nearPow2(n):
        if n <= 0:
            return 0
        if n & (n - 1) == 0:
            return n
        ret = 1
        while(n > 0):
            ret <<= 1
            n >>= 1
        return ret

MOD = int(1e09) + 7

def main():
    N,K,Q = cin.mapInt()
    A = [0] * N
    for i in range(Q):
        a = cin.int()
        A[a - 1] += 1
    for i in A:
        print("NYoe s"[K - (Q - i) > 0 ::2])
    return

if __name__ == "__main__":
    main()


Measured memory_bytes: 47836
#include <algorithm>
#include <cmath>
#include <ctype.h>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

#define ENDL '\n'
#define FOR(i, n) for (int i = 0; i < n; ++i)
#define FOR_EACH(i, v) for (auto&& i : v)

int N;

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

	cin >> N;
	set<int> d;

	FOR(i, N) {
		int tD;
		cin >> tD;
		d.insert(tD);
	}

	cout << d.size() << ENDL;

	return 0;
}

Measured memory_bytes: 3608
#include <iostream>

using std::cin;
using std::cout;
using std::endl;

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

    for(int n = 1; n <= 9; ++ n) {
        if(num % n == 0 && num / n < 10){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
deque<int>deq;
int n,k;
string s;
int main(){
	cin>>n>>k>>s;
	rep(i,n){
		deq.pb(s[i]-'A');
	}
	int rev = 0;
	rep(i,min(10000000,k)){
		if((rev^deq[0]) == 0){
			deq[0] ^= 1;
		}
		else{
			deq.pop_front();
			rev^=1;
			deq.pb(rev);
		}
	}
	if(10000000>=k){
		rep(i,n){
			printf("%c",('A'+(rev^deq[i])));
		}
	}
	else{
		for(int i=1;i<n;i++){
			//assert(deq[i]!=deq[i-1]);
		}
		int zan = k-10000000;
		zan %= 2;
		rep(i,zan){
			if((rev^deq[0]) == 0){
				deq[0] ^= 1;
			}
			else{
				deq.pop_front();
				rev^=1;
				deq.pb(rev);
			}
		}
		rep(i,n){
			printf("%c",('A'+(rev^deq[i])));
		}
	}
}

Measured memory_bytes: 1540
n, m = map(int, input().split())
to = [[] for _ in range(n)]
for _ in range(m):
    u, v = map(int, input().split())
    to[u - 1].append(v - 1)

s, t = map(int, input().split())
s -= 1
t -= 1

cnt = 0
phase = 0
q = [s]
visited = [[False] * 3 for _ in range(n)]
while q:
    nextq = []
    for v in q:
        if visited[v][phase]:
            continue
        visited[v][phase] = True
        if v == t and phase == 0:
            print(cnt)
            exit()
        nextq += to[v]
    if phase == 0:
        cnt += 1
    phase = (phase + 1) % 3
    q = nextq
print(-1)


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

int main(){
  int A,B;
  long long int ans;
  cin>>A>>B;
  ans=max(A,B);
  while(1){
    if(ans%A==0&&ans%B==0){
      break;
    }
    ans+=max(A,B);
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
<?php
  
  fscanf(STDIN,"%s",$n);
$p=trim(fgets(STDIN));
$q=trim(fgets(STDIN));
$p =  str_replace(" ",'',$p);
$q =  str_replace(" ",'',$q);
function dfs(&$jyun,$array,$n){
  if($n==count($array)){
    $jyun[]=$array;
    return;
  }
  for($i=1;$i<=$n;$i++){
    if(in_array($i,$array)){
      continue;
    }
    $array[]=$i;
    dfs($jyun,$array,$n);
    array_pop($array);
  }
}
$jyu=array();
dfs($jyu,[],$n);

//print_r($jyu);
$p_c=0;



$q_c=0;
  $s='';
foreach($jyu as $k=>$val){
  foreach($val as $v){
    $s.=$v;
  }
  if($s==$p){
    $p_c=$k;
  }
  if($s==$q){
    $q_c=$k;
  }
  $s='';
}

echo abs($p_c-$q_c);

Measured memory_bytes: 21368
from collections import deque
from collections import Counter
from itertools import product, permutations,combinations
from operator import itemgetter
from heapq import heappop, heappush
from bisect import bisect_left, bisect_right, bisect
#pypyではscipy, numpyは使えない
#from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson, minimum_spanning_tree
#from scipy.sparse import csr_matrix, coo_matrix, lil_matrix
#import numpy as np
from fractions import gcd
from math import ceil,floor, sqrt, cos, sin, pi, factorial
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**8)
INF = float('inf')
MOD = 10**9+7

def main():
  l, r = map(int, readline().split())
  if r-l>=2018:
    print(0)
  else:
    mod = []
    for i in range(l, r):
      for j in range(i+1, r+1):
        mod.append(i*j%2019)
    print(min(mod))
  
  
  
if __name__ == '__main__':
  main()

Measured memory_bytes: 77576
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, islice
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
import numpy as np
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()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')

N, W = MAP()
w, v = ZIP(N)

max_v = 0
dp = np.full(1000*N+1, 10**18, dtype=np.int64)
dp[0] = 0
for w, v in zip(w, v):
	np.minimum(dp[v:max_v+v+1], dp[:max_v+1]+w, out=dp[v:max_v+v+1])
	max_v += v
print(np.where(dp <= W)[0].max())


Measured memory_bytes: 15344
text=input()
n=int(input())
for i in range(n):
    order=input().split()
    a,b=map(int,order[1:3])
    if order[0]=="print":
        print(text[a:b+1])
    elif order[0]=="reverse":
        re_text=text[a:b+1]
        text=text[:a]+re_text[::-1]+text[b+1:]
    else :
        text=text[:a]+order[3]+text[b+1:]


Measured memory_bytes: 5608
import java.util.Scanner;

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

		while(true) {
			String a=sc.next();
			if(a.equals("#")) {
				break;
			}
			int y=sc.nextInt();
			int m=sc.nextInt();
			int d=sc.nextInt();

			if(y<=30) {
				System.out.println(a+" "+y+" "+m+" "+d);
			}

			else if(y==31 && m<=4) {
				System.out.println(a+" "+y+" "+m+" "+d);
			}
			else {
				System.out.println("? "+(y-30)+" "+m+" "+d);
			}
		}
	}
}


Measured memory_bytes: 26696
import java.util.*

fun main(args: Array<String>) {
    val (N, M) = readLine()!!.split(' ').map(String::toInt)
    val egs = Array(N){
        //ArrayList<Int>(0)
        HashSet<Int>()
    }
    repeat(M) {
        var (a, b) = readLine()!!.split(' ').map(String::toInt)
        a--; b--
        egs[a].add(b)
        egs[b].add(a)
    }

    var cnt = 0
    var ans = 0
    var vis = Array(N) {false}

    fun dfs(x:Int, px:Int=-1) {
        if (vis[x]) return
        vis[x] = true
        cnt++

        if (cnt == N) ans++

        for(nx in egs[x]) {
            if (nx == px) continue
            dfs(nx, x)
        }

        vis[x] = false
        cnt--
    }

    dfs(0)

    println(ans)
}


Measured memory_bytes: 38252
#include <bits/stdc++.h>
#define rep(i,n)    for(long long i = 0; i < (n) ; ++i)
#define orep(i,n)   for(long long i = 1; i <= (n); ++i)   // one rep
#define drep(i,n)   for(long long i = (n)-1; i >= 0; --i) // down rep
#define srep(i,s,t) for(long long i = (s); i < (t); ++i)  // set rep
#define rng(x)  (x).begin(),(x).end()

  // range
#define rrng(a) (a).rbegin(),(a).rend() // reverse range
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define ru(x,y) (((x)+(y)-1)/(y)) // round up
#define fi first
#define se second
#define eb emplace_back
#define fcout cout << fixed << setprecision(15)


using namespace std;
using ll  = long long;
using P   = pair<int,int>;
using vi  = vector<int>;
using vvi = vector<vi>;
using vp  = vector<P>;
using vl  = vector<ll>;

template<typename T> void Yes(T flag) {
  cout << (flag ? "Yes" : "No") << endl;
}

template<typename T> void pv(vector<T> vec) {
  cout << "[";
  for(auto& v : vec) { cout << v << ","; }
  cout << "]" << endl;
}

template<>
void pv(vector<P> vec) {
  cout << "[";
  for(auto& v : vec) {
    cout << "<" << v.fi << ","<< v.se << ">" << ",";
  }
  cout << "]" << endl;
}

int main() {
  int n;
  cin >> n;
  set<string> s;
  rep(i,n) {
    string t;
    cin >> t;
    s.insert(t);
  }

  cout << s.size() << endl;

  return 0;
}


Measured memory_bytes: 19224
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<ll>;
using vii = vector<vi>;
using Pll = pair<ll, ll>;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
const int MOD = 1000000007;
template<class T> void print(const T& t){ cout << t << endl; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
  ll n;
  cin >> n;
  vi x(n);
  ll total;
  rep(i, n){
    cin >> x[i];
    total += x[i];
  }
  ll ans = MOD;
  for (ll i = 1; i < 101; i++){
    ll sum = 0;
    rep(j, n){
      sum += (x[j] - i) * (x[j] - i);
    }
    chmin(ans, sum);
  }
  print(ans);
}

Measured memory_bytes: 256
#include <iostream>
#include<string>
#include<time.h>
#include<math.h>
#include<stdlib.h>
#include<map>
using namespace std;


int main() {
	string S, T, U;
	cin >> S >> T ;
	int A, B;
	cin >> A >> B;
	cin >> U;
	if (S == U) {
		A--;
	}
	else if (T == U) {
		B--;
	}
	cout << A << " " << B << endl;

	


	return 0;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;

public class Main {
    public static void main(final String[] args) {
        final Scanner scanner = new Scanner(System.in);
        final int n = scanner.nextInt();
        final int h = scanner.nextInt();

        int maxA = 0;
        final List<Integer> bList = new ArrayList<>();
        int index = 0;
        for (int i = 0; i < n; i++) {
            final int a = scanner.nextInt();
            if (a > maxA) {
                maxA = a;
                index = a;
            }
            bList.add(scanner.nextInt());
        }

        int fixed = maxA;
        final List<Integer> list = bList.stream()
                .filter(b -> b >= fixed)
                .sorted(Comparator.reverseOrder())
                .collect(Collectors.toList());

        int sum = 0;
        int counter = 0;
        for (final int b : list) {
            counter++;
            sum += b;
            if (sum >= h) {
                System.out.println(counter);
                return;
            }
        }

        System.out.println((h - sum + maxA - 1) / maxA + counter);
    }
}


Measured memory_bytes: 86556
N = gets.to_i
x = Array.new(N).map{Array.new()}
N.times do |i|
    x[i] = gets.split.map(&:to_i)
end
t = 0
x = x.sort {|a,b| a[1] <=> b[1]}
flag = true
x.each do |c|
    t += c[0]
    if c[1] >= t then
    else
        flag = false
        break

    end
end
puts flag ? "Yes" : "No"

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

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> vec(N,0);
  for(int i = 0; i<M;i++){
    int a,b;
    cin >> a >> b;
    vec.at(a-1) += 1;
    vec.at(b-1) += 1;
  }
  for(int i = 0; i<N;i++){
    cout << vec.at(i) << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using Graph = vector<vector<int>>;
const int INF = 1e9 + 1;
const ll LLINF = 1e18;
const int MOD = 1e9 + 7;

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

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

    ll ans = 1;
    bool zero = false;
    if (N % 2)
        zero = (cnt[0] != 1);
    for (int i = (N % 2 ? 2 : 1); i < N; i += 2) {
        zero |= (cnt[i] != 2);
        (ans *= 2) %= MOD;
    }
    cout << (zero ? 0 : ans) << endl;
    return 0;
}


Measured memory_bytes: 640
n, y = gets.chomp.split(' ').map(&:to_i)
0.upto(n) do |i|
  0.upto(n) do |j|
    x = n - (i + j)
    if x >= 0 && y == i * 1000 + j * 5000 + x * 10000
      puts "#{x} #{j} #{i}"
      exit
    end
  end
end
puts "-1 -1 -1"


Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
	int a,b=0;
	cin>>a;
	b=a%10;
	if(b==2||b==4||b==5||b==7||b==9)
		cout<<"hon";
	if(b==0||b==1||b==6||b==8)
		cout<<"pon";
	if(b==3)
		cout<<"bon";
return 0;
}


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

class Main {
	public static void main(String[] $) {
		Scanner sc = new Scanner(System.in);
		int[] a=new int[3];
		a[0]=sc.nextInt();
		a[1]=sc.nextInt();
		a[2]=sc.nextInt();
		Arrays.sort(a);
		if((a[2]-a[0])%2==0 && (a[2]-a[1])%2==0) {
			System.out.println((a[2]-a[0])/2+(a[2]-a[1])/2);
		}else if((a[2]-a[0])%2!=0 && (a[2]-a[1])%2!=0) {
			System.out.println((a[2]-a[0]-1)/2+(a[2]-a[1]-1)/2+1);
		}else {
			a[0]++;
			a[2]++;
			if((a[2]-a[0])%2==0 && (a[2]-a[1])%2==0) {
				System.out.println((a[2]-a[0])/2+(a[2]-a[1])/2+1);
			}else{
				System.out.println((a[2]-a[0]-1)/2+(a[2]-a[1]-1)/2+2);
			}
		}
	}
}



Measured memory_bytes: 23764
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int) n; i++)
using ll = long long;
template <class T>
using vt = vector<T>;
using vvi = vector<vt<int>>;

int main(){

  string s;
  cin >> s;
  int n=0;

  rep(i,3){
    if(s[i]=='R'){
      if(n==0)  n++;
      else if(s[i-1]=='R'&&s[i]=='R')
      n++;
    }

  }

  cout << n << endl;
  return 0;
}


Measured memory_bytes: 3624
"""
in1 = '7 4 4'
in2 = ['1 2', '2 3', '2 5', '6 7', '3 5', '4 5', '3 4', '6 7']
N, K, L = map(int, in1.split())
pqrs = []
for idx1 in range(K + L):
    temp0, temp1 = map(int, in2[idx1].split())
    pqrs.append([temp0, temp1])
"""

def makeTree(a):
    aT = list(range(N + 1))
    for p, q in a:
        rootp     = getRoot(aT, p)
        rootq     = getRoot(aT, q)
        thisRoot  = max(rootp, rootq, q)
        aT[p]     = thisRoot
        aT[q]     = thisRoot
        aT[rootp] = thisRoot
        aT[rootq] = thisRoot
    return aT

def getRoot(a,i):
    if a[i] == i:
        return i
    else:
        a[i] = getRoot(a, a[i])
        return a[i]

N, K, L = map(int, input().split())
pqrs = []
for idx1 in range(K + L):
    temp0, temp1 = map(int, input().split())
    pqrs.append([temp0, temp1])

MTree = makeTree(pqrs[0:K])
TTree = makeTree(pqrs[K:])

aRet = []
dRet = {}
for idx1 in range(1, N + 1):
    Comb = (getRoot(MTree, idx1), getRoot(TTree, idx1))
    aRet.append(Comb)
    if Comb in dRet:
        dRet[Comb] += 1
    else:
        dRet[Comb] = 1

print(" ".join([str(dRet[_]) for _ in aRet]))


Measured memory_bytes: 92112
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>

using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype

template <class T>
int __builtin_popcount(T n) { return n ? 1 + __builtin_popcount(n & (n - 1)) : 0; }
#endif

#define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define popcount __builtin_popcount

const double EPS = 1e-10;
typedef long long ll;
typedef pair<int, int> pint;


int main()
{
	int n, k;
	while (scanf("%d%d", &n, &k), n|k)
	{
		int c[100000];
		int b = 0;
		for (int i = 0; i < k; ++i)
		{
			scanf("%d", c + i);
			if (c[i] == 0)
			{
				b = 1;
				--i; --k;
			}
		}
		sort(c, c+k);

		int res = 0, s = 1, from = 0;
		vector<pint> succ;
		for (int i = 1; i < k; ++i)
		{
			if (c[i-1]+1 == c[i])
				++s;

			if (c[i-1]+1 != c[i] || i == k-1)
			{
				succ.push_back(pint(s, from));
				res = max(res, s + b);
				s = 1;
				from = i;
			}
		}
		if (b)
		{
			for (int i = 1; i < succ.size(); ++i)
			{
				int t = succ[i].second;
				if (c[t-1]+2 == c[t])
					res = max(res, succ[i-1].first+succ[i].first+1);
			}
		}
		printf("%d\n", res);
	}
}

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

    typedef long long int ll;
    #define pb         push_back
    #define mp         make_pair
    #define F          first
    #define S          second
    #define fl(i,a,b)  for(ll i=a;i<b;i++)
    #define pll        pair<ll,ll>
    #define pii        pair<int,int>
    #define all(v)     v.begin(),v.end()
    #define M 1000000007
    #define tr(v, it) for(auto it = v.begin(); it != v.end(); it++)
    using namespace std;

    int solve(vector<vector<int> >& arr, int i, int n, vector<vector<int> >& dp, int activity )
    {
        if(i>n)
            return 0;

         if(dp[i][activity]!=-1)
            return dp[i][activity];


        int result = INT_MIN;

        if(activity!=0)
        result= max(result, arr[i][0]+solve(arr, i+1,n, dp, 0));
        if(activity!=1)
        result= max(result, arr[i][1]+solve(arr, i+1,n, dp, 1));
        if(activity!=2)
        result= max(result, arr[i][2]+solve(arr, i+1,n, dp, 2));
       // cout<<result<<" " <<i
        return dp[i][activity]=result;
    }

    int main()
    {

    ios_base::sync_with_stdio(false);
	cin.tie(NULL);

       int n;
       cin>>n;
       vector<vector<int> > arr(n+1, vector<int>(3,0));
       for(int i=1; i<=n; i++)
       {
           cin>>arr[i][0]>>arr[i][1]>>arr[i][2];
       }
       vector<vector<int> > dp(n+1,vector<int>(3,-1));
       int result = max(solve(arr, 1,n, dp,0),solve(arr, 1,n, dp,1));
       result = max(result, solve(arr, 1,n, dp,2));
       cout<<result;
        return 0;

    }



Measured memory_bytes: 23492
#include<iostream>
#include<string>

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

    size_t cnt = 0;

    for(size_t i = 0; i < s.size() / 2; i++){
        if(s.at(i) != s.at(s.size() - i - 1)) cnt++;
    }

    std::cout << cnt << std::endl;
    
    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define EPS (1e-10)    //誤差
typedef complex<double> P;

//実数同士の比較
bool EQ(double a, double b){
    return (abs(a - b) < EPS);
}

//内積
double dot(P a, P b){
    return (a.real() * b.real() + a.imag() * b.imag());
}

//外積
double cross(P a, P b){
    return (a.real() * b.imag() - a.imag() * b.real());
}

//図を思い出す
int ccw(P a, P b, P c) {
    b -= a; c -= a;
    if( cross(b,c) > EPS ) return +1;
    if( cross(b,c) < -EPS ) return -1;
    if( dot(b,c) < 0 ) return +2;
    if( norm(b) < norm(c) ) return -2;
    return 0;
}

// a1,a2を端点とする線分とb1,b2を端点とする線分の交差判定
int is_intersected_ls(P a1, P a2, P b1, P b2) {
  return ( ccw(a1,a2,b1) * ccw(a1,a2,b2) <= 0 ) &&
           ( ccw(b1,b2,a1) * ccw(b1,b2,a2) <= 0 );
}

int main(){

    int q; cin >> q;
    for(int i = 0; i < q; i++){
        P p0, p1, p2, p3; cin >> p0.real() >> p0.imag() >> p1.real() >> p1.imag() >> p2.real() >> p2.imag() >> p3.real() >> p3.imag();
        if(is_intersected_ls(p0, p1, p2, p3)) cout << 1 << endl;
        else cout << 0 << endl;
    }
    return 0;
}


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

int32_t main(){
    ios::sync_with_stdio(0),cin.tie(0);
    int n;
    cin >> n;
    int a[n],b[n];
    for(int i=0;i<n;i++)
        cin >> a[i] >> b[i];
    sort(a,a+n);sort(b,b+n);
    if(n%2){
        cout << b[n/2]-a[n/2]+1;
    }
    else{
        cout << b[n/2]+b[n/2-1]-a[n/2]-a[n/2-1]+1;
    }
}


Measured memory_bytes: 6728
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")

#include <bits/stdc++.h>
using namespace std;
using LL = long long int;
#define incID(i, l, r) for(int i = (l)    ; i <  (r); ++i)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); --i)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); ++i)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define dec(i, n)  decID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec1(i, n) decII(i, 1, n)
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define FI first
#define SE second
#define FR front()
#define BA back()
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
auto setmin   = [](auto & a, auto b) { return (b <  a ? a = b, true : false); };
auto setmax   = [](auto & a, auto b) { return (b >  a ? a = b, true : false); };
auto setmineq = [](auto & a, auto b) { return (b <= a ? a = b, true : false); };
auto setmaxeq = [](auto & a, auto b) { return (b >= a ? a = b, true : false); };
#define SI(v) static_cast<int>(v.size())
#define RF(e, v) for(auto & e: v)
#define until(e) while(! (e))
#define if_not(e) if(! (e))
#define ef else if
#define UR assert(false)
#define IN(T, ...) T __VA_ARGS__; IN_(__VA_ARGS__);
void IN_() { };
template<typename T, typename ... U> void IN_(T &  a, U &  ... b) { cin >> a; IN_(b ...); };
template<typename T                > void OUT(T && a            ) { cout << a << endl; }
template<typename T, typename ... U> void OUT(T && a, U && ... b) { cout << a << " "; OUT(b ...); }

// ---- ----

const int M = 1'000'000;
int A[M / 2 + 1], B[M / 2 + 1], aa, bb, mi, sum;
int main() {
	until(getchar_unlocked() == '\n') { }
	while(true) {
		char c = getchar_unlocked();
		if(c == '(' || c == ')') {
			sum += (c == '(' ? +1 : -1);
			setmin(mi, sum);
		} else {
			int a = -mi, b = sum - mi;
			if(a <= b) { A[a] += sum; setmax(aa, a); }
			else       { B[b] += sum; setmax(bb, b); }
			mi = 0, sum = 0;
			if(c == EOF) { break; }
		}
	}
	
	incII(i, 0, aa) {
		setmin(mi, sum - i);
		sum += A[i];
	}
	decII(i, 0, bb) {
		sum += B[i];
		setmin(mi, sum - i);
	}
	puts(mi >= 0 && sum == 0 ? "Yes" : "No");
}


Measured memory_bytes: 3628
#include <iostream>

int main()
{
	int a, b, k;
	std::cin >> a >> b >> k;
	int c = 0;

	int n = (a <= b) ? a : b;
	for (int i = n; i >= 1; i--) {
		if ((a%i == 0) && (b%i == 0))c++;
		if (c == k) {
			c = i;
			break;
		}
	}

	std::cout << c;
    return 0;
}

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

int main() {
    int n;
    cin >> n;
    if (n % 2 == 0) {
        cout << n / 2 << endl;
    }else {
        cout << n / 2 + 1 << endl;
    }
}



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

const ll INF = pow(10, 9) + 7;

int main() {
	int N;
	cin >> N;
	vector<ll> A(N);

	bool a = true;
	rep(i, N) cin >> A[i];
	sort(A.begin(), A.end());
	rep(i, N-1) {
		if (A[i + 1] - A[i] == 0) a = false;
	}
	if (a)cout << "YES";
	else cout << "NO";
}



// プログラムの実行: Ctrl + F5 または [デバッグ] > [デバッグなしで開始] メニュー
// プログラムのデバッグ: F5 または [デバッグ] > [デバッグの開始] メニュー

// 作業を開始するためのヒント: 
//    1. ソリューション エクスプローラー ウィンドウを使用してファイルを追加/管理します 
//   2. チーム エクスプローラー ウィンドウを使用してソース管理に接続します
//   3. 出力ウィンドウを使用して、ビルド出力とその他のメッセージを表示します
//   4. エラー一覧ウィンドウを使用してエラーを表示します
//   5. [プロジェクト] > [新しい項目の追加] と移動して新しいコード ファイルを作成するか、[プロジェクト] > [既存の項目の追加] と移動して既存のコード ファイルをプロジェクトに追加します
//   6. 後ほどこのプロジェクトを再び開く場合、[ファイル] > [開く] > [プロジェクト] と移動して .sln ファイルを選択します


Measured memory_bytes: 1792
#include<iostream>
#include <algorithm>
#include <string>
#include<math.h>
#define rep(i,n)for(i=0;i<n;i++)
using namespace std;
int main() {
    string a, b, c;
    cin >> a >> b >> c;
    if (a.substr(a.size()-1, 1) == b.substr(0, 1) && b.substr(b.size()-1, 1) == c.substr(0, 1)) {
        cout << "YES" << endl;
    }
    else {
        cout << "NO" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long A,B,C,D,H,K,L,M,N,T,W,X;
  string S;
  cin >> N >> M;
  vector<long long> vec(N,0);
  C=1;
  D=N;
  for (int i=0;i<M;i++) {
    cin >> A >> B;
    if (A>=C && A<=D) {C=A;}
    if (B<=D && B>=C) {D=B;}
    if (A>D || B<C) {C=1;D=0;}
  } 
  
  cout << D-C+1 << endl;
}


Measured memory_bytes: 1024
//*
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <time.h>
#include <stdlib.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <numeric>
#include <functional>
#define MOD 1000000007
#define MAX 0x3f3f3f3f
#define MAX2 0x3f3f3f3f3f3f3f3fll
#define ERR 1e-10
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#pragma warning(disable:4996)
using namespace std;

typedef long long ll;
typedef long double ldb;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;

int n;
int a[200000];

int main()
{
	int i, j, k, l;
	cin>>n;
	for(i=0;i<n;i++) scanf("%d", &a[i]), a[i]--;
	int ans=0;
	for(i=0;i<n;i++) if(a[a[i]] == i) ans++;
	cout<<ans/2<<endl;
	return 0;
}
//*/

Measured memory_bytes: 640
#ifndef BZ
#pragma GCC optimize "-O3"
#endif
#include <bits/stdc++.h>

#define FASTIO

#ifdef FASTIO
#define scanf abacaba
#define printf abacaba
#endif

typedef long long ll;
typedef long long llong;
typedef long double ld;
typedef unsigned long long ull;

using namespace std;

const ll MOD = 998244353;

ll pw(ll a, ll b) {
	ll ans = 1; while (b) {
		while (!(b & 1)) b >>= 1, a = (a * a) % MOD;
		ans = (ans * a) % MOD, --b;
	} return ans;
}
const int MAXN = 2000000;

ll fc[MAXN];
ll bfc[MAXN];

ll cnk(int n, int k) {
	if (k > n)
		return 0;
	return fc[n] * bfc[k] % MOD * bfc[n - k] % MOD;
}

ll go(int n, int a, int b) {
	int x = (n + (b - a)) / 2;
	int y = n - x;
	if (x - y != b - a || x > n)
		return 0;
	ll ans = cnk(n, x);
	int nx = (n + (a + b)) / 2;
	int ny = n - nx;
	if (nx <= n && nx - ny == (a + b))
		ans = (ans - cnk(n, nx) + MOD) % MOD;
	return ans;
}

int n, k;

int main() {
#ifdef FASTIO
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#endif
	cin >> n >> k;
	fc[0] = 1;
	for (int i = 1; i < MAXN; ++i)
		fc[i] = (fc[i - 1] * i) % MOD;
	bfc[MAXN - 1] = pw(fc[MAXN - 1], MOD - 2);
	for (int i = MAXN - 2; i >= 0; --i) {
		bfc[i] = (bfc[i + 1] * (i + 1)) % MOD;
	}
	ll ans = 0;
	for (int r = 0; r <= k; ++r) {
		int b = (k - r);
		if (r < b)
			continue;
		if (r < n)
			continue;
		if (r >= b + n) {
			ans = (ans + cnk(k, r)) % MOD;
			continue;
		}
		if (r > b) {
			int bd = n - (r - b);
			if (b < bd)
				continue;
			ans = (ans + go(k, 1 + (b - bd), 1 + (b - bd) + (r - b))) % MOD;
		}
		else {
			ans = (ans + go(k - 1, 1 + (b - n) + 1, 1 + (b - n))) % MOD;
		}
	}
	cout << ans % MOD << "\n";
	return 0;
}




Measured memory_bytes: 31488
import javax.swing.text.MutableAttributeSet;
import java.util.*;

public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        int[] b = new int[n];
        int[] c = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
            b[i] = sc.nextInt();
            c[i] = sc.nextInt();
        }

        int[][] dp = new int[n+1][3];
        for (int i = 1; i <= n; i++) {
            dp[i][0] = Math.max(dp[i-1][1], dp[i-1][2]) + a[i-1];
            dp[i][1] = Math.max(dp[i-1][2], dp[i-1][0]) + b[i-1];
            dp[i][2] = Math.max(dp[i-1][1], dp[i-1][0]) + c[i-1];
        }

        System.out.println(Math.max(dp[n][0], Math.max(dp[n][1], dp[n][2])));
    }
}


Measured memory_bytes: 61268
import java.lang.Math.max
import java.lang.Math.min
import java.util.*

val sc = Scanner(System.`in`)
val A = sc.nextInt()
val B = sc.nextInt()
val C = sc.nextInt()
val D = sc.nextInt()

fun main(args: Array<String>) {
    println(max(0, min(B, D) - max(A, C)))
}


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

using namespace std;

struct node {
	long long key;
	int left;
	int right;
};

int nind,root;
vector<node> tree;

void preorder_walk(int ind) {
	if (ind < 0) {
		return;
	}
	cout << " " << tree[ind].key;
	preorder_walk(tree[ind].left);
	preorder_walk(tree[ind].right);
	return;
}

void inorder_walk(int ind) {
	if (ind < 0) {
		return;
	}
	inorder_walk(tree[ind].left);
	cout << " " << tree[ind].key;
	inorder_walk(tree[ind].right);
	return;
}

void insert(int ind) {
	if (ind == 0) {
		return;
	}
	bool find = false;
	int now = 0;
	while (!find) {
		if (tree[now].key < tree[ind].key) {
			if (tree[now].right == -1) {
				tree[now].right = ind;
				find = true;
			}
			else {
				now = tree[now].right;
			}
		}
		else {
			if (tree[now].left == -1) {
				tree[now].left = ind;
				find = true;
			}
			else {
				now = tree[now].left;
			}
		}
	}
	return;
}

bool find_key(int num) {
	int now = 0;
	while (now >= 0) {
		if (tree[now].key == num) {
			return true;
		}
		else if (tree[now].key < num) {
			now = tree[now].right;
		}
		else {
			now = tree[now].left;
		}
	}
	return false;
}

void delete_key(long long num) {
	int prev,now = 0;
	bool find = false;
	while (!find) {
		if (tree[now].key == num) {
			find = true;
		}
		else {
			prev = now;
			if (tree[now].key < num) {
				now = tree[now].right;
			}
			else {
				now = tree[now].left;
			}
		}
	}

	if (tree[now].left < 0 && tree[now].right < 0) {
		if (now == 0) {
			root = nind;
		}
		else {
			if (tree[prev].key < num) {
				tree[prev].right = -1;
			}
			else {
				tree[prev].left = -1;
			}
		}
	}
	else if (tree[now].left < 0 || tree[now].right < 0) {
		int next = max(tree[now].left,tree[now].right);
		if (now == 0) {
			root = next;
		}
		else {
			if (tree[prev].key < num) {
				tree[prev].right = next;
			}
			else {
				tree[prev].left = next;
			}
		}
	}
	else {
		int next = tree[now].right;
		prev = now;
		while (tree[next].left >= 0) {
			prev = next;
			next = tree[next].left;
		}
		tree[now].key = tree[next].key;
		if (prev != now) {
			tree[prev].left = tree[next].right;
		}
		else {
			tree[prev].right = tree[next].right;
		}
	}

	return;
}

int main(void) {
	int nop;
	cin >> nop;

	string ope;
	root = nind = 0;
	long long num;
	tree = vector<node>(nop+1,{-1,-1,-1});
	for (int q = 0; q < nop; ++q) {
		cin >> ope;
		if (ope == "print") {
			inorder_walk(root);
			cout << endl;
			preorder_walk(root);
			cout << endl;
		}
		else {
			if (ope == "insert") {
				cin >> tree[nind].key;
				insert(nind);
				++nind;
			}
			else {
				cin >> num;
				if (ope == "find") {
					if (find_key(num)) {
						cout << "yes" << endl;
					}
					else {
						cout << "no" << endl;
					}
				}
				else {
					delete_key(num);
				}
			}
		}
	}
	return 0;
}



Measured memory_bytes: 18332
S = input()
N = len(S)

flag = True
for i in range(len(S)//2):
    if S[i] != S[-i-1]:
        flag = False
        
left = S[0:(N-1)//2]
for i in range(len(left)//2):
    if left[i] != left[-i-1]:
        flag = False
        
right = S[(N+2)//2:N]
for i in range(len(left)//2):
    if right[i] != right[-i-1]:
        flag = False
        
if flag:
    print("Yes")
else:
    print("No")

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

using namespace std;

int64_t solve(const std::array<int, 4>& prices, int n) {
  int64_t ret = n * INT64_C(4) * prices[0];
  ret = std::min(n * INT64_C(2) * prices[1], ret);
  ret = std::min(n * INT64_C(1) * prices[2], ret);
  int64_t const dCount = n / 2;
  if (n % 2) {
    ret = std::min(dCount * prices[3] + INT64_C(4) * prices[0], ret);
    ret = std::min(dCount * prices[3] + INT64_C(2) * prices[1], ret);
    ret = std::min(dCount * prices[3] + INT64_C(1) * prices[2], ret);
  } else {
    ret = std::min(dCount * prices[3], ret);
  }
  return ret;
}

int main() {
  int n;
  std::array<int, 4> prices;
  for (auto& price : prices) {
    std::cin >> price;
  }
  std::cin >> n;
  std::cout << solve(prices, n) << std::endl;
  return 0;
}


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

static const int MAX_N = 100;

int N;
int A[2][MAX_N];

int main(){
  cin >> N;
  for(int i = 0; i < 2; i++){
    int tmp;
    cin >> A[i][0];
    for(int j = 1; j < N; j++){
      cin >> tmp;
      A[i][j] = A[i][j-1]+tmp;
    }
  }
  int ans = A[0][0]+A[1][N-1];
  for(int i = 1; i < N; i++)
    ans = max(ans, A[0][i]+A[1][N-1]-A[1][i-1]);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
# coding: utf-8
# Your code here!
import sys
read = sys.stdin.read
readline = sys.stdin.readline 
readlines = sys.stdin.readlines

#n = int(input())
#h,w = [int(i) for i in readline().split()]

s = input()

n = len(s)
ans = 0
for i in range(n):
    #print(s[i],s[-i-1])
    if s[i] != s[-i-1]:
        ans += 1
    #print(ans)

print(ans//2)
    

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

# define F first    
# define S second
# define mp make_pair
// everything go according to my plan      
# define pb push_back
# define sz(a) (int)(a.size())
# define vec vector
// shimkenttin kyzdary, dzyn, dzyn, dzyn...
# define y1    Y_U_NO_y1
# define left  Y_U_NO_left
# define right Y_U_NO_right  

using namespace std;

typedef pair <int, int> pii; 
typedef long long ll;
typedef long double ld;

const int Mod = (int)1e9 + 7;
const int MX = 1073741822;
const ll MXLL = 4e18;
const int Sz = 1110111;
// a pinch of soul
inline void Read_rap () {
  ios_base :: sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
}
inline void randomizer3000 () {
  unsigned int seed;
  asm ("rdtsc" : "=A"(seed));
  srand (seed);
}
void files (string problem) {   
  if (fopen ((problem + ".in").c_str(),"r")) {
    freopen ((problem + ".in").c_str(),"r",stdin);
    freopen ((problem + ".out").c_str(),"w",stdout);
  }
}
void localInput(const char in[] = "s") { 
  if (fopen (in, "r")) {
    freopen (in, "r", stdin);
  }
  else
    cerr << "Warning: Input file not found" << endl;
}
const int K = 201;
const int N = 5000 + 1;

int n, k;

ll ans;

ll dist[N];

int b[K][N];
            
struct maxQueue {
  deque <int> q;
  int l, r;
  int prev = -1;
  int *a;
  maxQueue (int *a) : a(a) {}
  maxQueue(){}

  void set (int lvl) {     
    if (prev < lvl) {
      q.clear();    
      l = 1, r = 0;
    }        
    prev = lvl;
  }    
  void add (int p) {
    while (!q.empty() && a[p] > a[q.back()])
      q.pop_back();
    q.push_back (p);
  }
  void move (int L, int R) {
    while (r < R)
      add (++r);
    l = L;            
    while (q.front() < l)
      q.pop_front();
  }     
  int getmax() {   
    assert (!q.empty());  
    return a[q.front()];
  }       
} T[K + 1];

struct node {
  int l, r;
  int tl, tr;
  int lvl;
} t[4*N];

queue <int> q;
void solve (int v) { 
  node &a = t[v];
  int m = (a.l + a.r) >> 1;
  for (int i = 1; i <= k; i++)
    T[i].set (a.lvl);
          
  ll mx = -1;
  int opt = 0;   
  for (int j = a.tl; j <= min (a.tr, m); j++) {
    ll cost = -(dist[m] - dist[j]);  
    for (int i = 1; i <= k; i++) {
      T[i].move (j, m);    
      cost += T[i].getmax ();
    }                 
    if (mx < cost) {
      mx = cost;
      opt = j;
    }
  }                   
  ans = max (ans, mx);
  if (a.l != a.r) {
    t[v<<1] = {a.l, m, a.tl, opt, a.lvl + 1};
    t[v<<1|1] = {m + 1, a.r, opt, a.tr, a.lvl + 1};
  }      
}    

int main()
{
  # ifdef Local
    //localInput();
  # endif
  scanf ("%d %d", &n, &k);
  for (int i = 2; i <= n; i++) {
    static int d; 
    scanf ("%d", &d);
    dist[i] = dist[i - 1] + d;
  }
      
  for (int i = 1; i <= n; i++)  
    for (int j = 1; j <= k; j++)
      scanf ("%d", b[j] + i);

  for (int i = 1; i <= k; i++)
    T[i] = maxQueue (b[i]);
  
  t[1] = {1, n, 1, n, 0};        
  for (int i = 1; i <= 4*n; i++) {
    if (!t[i].l)
      break;
    solve (i);
  }    
  cout << ans;
          
  return 0;
}






// Coded by Z..


Measured memory_bytes: 4736
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <string>
#include <cmath>
#include <iostream>
#include <stack>
#include <queue>

#define ll long long int
#define all(x) x.begin(), x.end()
#define MOD 998244353

using namespace std;


void solve()
{
    ll X;
    cin >> X;

    ll A = 0, B = -100;
    while (true)
    {
        while (B < A)
        {
            if (pow(A, 5) - pow(B, 5) == X)
            {
                cout << A << " " << B << endl;
                return;
            }
            B++;
        }
        A++;
        B = -100;
    }
}


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

    int T = 1;
    //cin >> T;
    while (T--)
    {
        solve();
    }
    return 0;
}



Measured memory_bytes: 4140
n,x=list(map(int,input().split()))

def rec(lev,x):
    bottom=1
    center=2**(lev+1)-1
    top=2**(lev+2)-3


    if x>center:
        if top==x:
            return 2**(lev+1)-1
        return 2**lev+rec(lev-1,x-center)
    elif x==center:
        return 2**lev
    else:
        if bottom==x:
            return 0
        
        return rec(lev-1,x-1)

print(rec(n,x))

Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN=100010;
int a[MAXN],n,cnt;
int read(){
    int f=1,x=0;
    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 f*x;
}
int main(){
    int d;
    cin>>d;
    if(d==25) cout<<"Christmas";
    else if(d==24) cout<<"Christmas Eve";
    else if(d==23) cout<<"Christmas Eve Eve";
    else if(d==22) cout<<"Christmas Eve Eve Eve"; 
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define show(x) cout << #x << " = " << (x) << endl;
using namespace std;
using ll = long long;
using pii = pair<int,int>;
class UnionFind {
private:
    int sz;
    vector<int> par, nrank;
public:
    UnionFind(){}
    UnionFind(int node_size) : sz(node_size), par(sz), nrank(sz, 0){
        iota(par.begin(), par.end(), 0);
    }
    int find(int x){
        if(par[x] == x) return x;
        else return par[x] = find(par[x]);
    }
    void unite(int x,int y){
        x = find(x), y = find(y);
        if(x == y) return;
        if(nrank[x] < nrank[y]) swap(x,y);
        par[y] = x;
        if(nrank[x] == nrank[y]) nrank[x]++;
    }
    bool same(int x,int y){
        return find(x) == find(y);
    }
};
struct edge{
    int from,to;
    ll cost;
    bool operator<(const edge&b) const{
        return cost < b.cost;
    }
};
vector<pair<int,ll>>g[4000];
ll dp[4000][4000];
void dfs(const int t, int s, int p){
    for(auto &x:g[s]){
        if(x.first==p)continue;
        int v = x.first;
        dp[t][v] = max(dp[t][s], x.second);
        dfs(t,v,s);
    }
}
int main(){
    int n, m;
    cin >> n >> m;
    vector<edge>vec;
    while(m--){
        int a,b;
        ll c;
        cin >> a >> b >> c;
        a--,b--;
        vec.push_back({a,b,c});
    }
    sort(vec.begin(),vec.end());
    UnionFind uf(n);
    ll sum = 0;
    for(auto &e:vec){
        if(!uf.same(e.from,e.to)){
            sum += e.cost;
            uf.unite(e.from,e.to);
            g[e.from].emplace_back(e.to,e.cost);
            g[e.to].emplace_back(e.from,e.cost);
        }
    }
    rep(i,n){
        dfs(i,i,-1);
    }
    int q;
    cin >> q;
    while(q--){
        int s,t;
        cin >> s >> t;
        s--,t--;
        cout << sum - dp[s][t] << "\n";
    }
}

Measured memory_bytes: 134376
#include <stdio.h>

int main()
{   int n;
    scanf("%d",&n);
    char s[n+1];
    scanf("%s",s);
    int l=0,r=0;
    for(int i=0;i<n;i++){
        if(s[i]=='('){
            l++;
        }else if(l>0){
            l--;
        }else{
            r++;
        }
    }
    for(int i=0;i<r;i++){
        printf("(");
    }
    printf("%s",s);
    for(int i=0;i<l;i++){
        printf(")");
    }
    
    return 0;
}


Measured memory_bytes: 128
n = int(input())

a = [int(input()) for _ in range(n)]

ans = 0
ind = 0
flag = 0
for i in range(n):
    t = a[ind]
    if t == 2:
        flag = 1
        ans += 1
        break
    else:
        ind = t-1
        ans += 1

if flag:
    print(ans)
else:
    print(-1)

Measured memory_bytes: 13060
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <utility>
#include <functional>

using namespace std;

int main() {
	int h, w;
	cin >> h >> w;
	string s(w + 2, '#'), t;
	cout << s << endl;
	while (h--) {
		cin >> t;
		cout << "#" << t << "#\n";
	}
	cout << s << endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int h = sc.nextInt();
      	int n = sc.nextInt();
        int a[] = new int[n];
        int i;
		// 出力
      for(i = 0; i < n; i++){
        h -= sc.nextInt();
      }
	  if(h <= 0){
            System.out.println("Yes");
      }else {
            System.out.println("No");  
      }
	}
}

Measured memory_bytes: 59400
def main():
    import sys
    from fractions import gcd
    sys.setrecursionlimit(10 ** 6)
    input = sys.stdin.readline
    K = int(input())
    GCD = {}
    for a in range(1, K+1):
        for b in range(1, K+1):
            GCD[(a, b)] = gcd(a, b)
    ans = 0
    for a in range(1, K+1):
        for b in range(1, K+1):
            gcd_ = GCD[(a, b)]
            for c in range(1, K+1):
                ans += GCD[(gcd_, c)]
                
    print(ans)
    

if __name__ == '__main__':
    main()

Measured memory_bytes: 14048
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <functional>
using namespace std;

typedef long long ll;

class maxflow { // Dinic O(E*V^2)
public:
	static const int MAX_V = 1003;
	static const int INF = 2e9;
private:
	struct edge { int to, cap, rev; };
	vector<edge> edg[MAX_V];
	int level[MAX_V], iter[MAX_V];
public:
	void add_edge(int  from, int to, int cap) {
		edg[from].push_back({ to, cap, (int)edg[to].size() });
		edg[to].push_back({ from, 0, (int)edg[from].size() - 1 });
	}

	ll calc_maxflow(int s, int t) {
		ll flow = 0;
		while (true) {
			bfs(s);
			if (level[t] < 0) return flow;
			for (int i = 0; i < MAX_V; i++) iter[i] = 0;
			int f;
			while ((f = dfs(s, t, INF)) > 0) {
				flow += (ll)f;
			}
		}
	}

	void show_edge(int bi, int en) {
		for (int i = bi; i < en; i++) {
			cerr << i << ": ";
			for (int j = 0; j < (int)edg[i].size(); j++) {
				cout << "(" << edg[i][j].to << "," << edg[i][j].cap << "," << edg[i][j].rev << ") ";
			}
			cout << endl;
		}
	}
private:
	void bfs(int s) {
		for (int i = 0; i < MAX_V; i++) level[i] = -1;
		deque<int> que;
		level[s] = 0;
		que.push_back(s);
		while (!que.empty()) {
			int v = que.front(); que.pop_front();
			for (int i = 0; i < (int)edg[v].size(); i++) {
				edge &e = edg[v][i];
				if (e.cap > 0 && level[e.to] < 0) {
					level[e.to] = level[v] + 1;
					que.push_back(e.to);
				}
			}
		}
	}

	int dfs(int v, int t, int f) {
		if (v == t) return f;
		for (int &i = iter[v]; i < (int)edg[v].size(); i++) {
			edge &e = edg[v][i];
			if (e.cap <= 0 || level[v] >= level[e.to]) continue;
			int d = dfs(e.to, t, min(f, e.cap));
			if (d > 0) {
				e.cap -= d;
				edg[e.to][e.rev].cap += d;
				return d;
			}
		}
		return 0;
	}
};

int main() {
	int n; cin >> n;
	pair<int, int> r[102], b[102];
	for (int i = 0; i < n; i++) cin >> r[i].first >> r[i].second;
	for (int i = 0; i < n; i++) cin >> b[i].first >> b[i].second;
	maxflow mf;
	for (int i = 0; i < n; i++) {
		mf.add_edge(999, i, 1);
		mf.add_edge(n + i, 1000, 1);
		for (int j = 0; j < n; j++) {
			if (r[i].first < b[j].first && r[i].second < b[j].second) {
				mf.add_edge(i, n + j, 1);
			}
		}
	}
	cout << mf.calc_maxflow(999, 1000) << endl;
	return 0;
}



Measured memory_bytes: 384
import math

if __name__ == '__main__':

	n,x = map(int,input().split())

	A = []
	for i in range(n):
		A.append(int(input()))

	cnt = 0
	sm = sum(A)
	x = x - sm
	cnt += len(A)
	
	if x != 0:
		mi = min(A)
		cnt += math.ceil(x // mi)

	print(cnt)

Measured memory_bytes: 9052
#!/usr/bin/env python3
import sys
from itertools import takewhile, count


def solve(N: int, K: int):
    return max(takewhile(lambda i: N >= (K ** i), count(0))) + 1

# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    print(solve(N, K))

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060