akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define pb push_back
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
#define FORR(I,A,B) for(ll I = (B-1);I >= (A); --I)
const ll INF=1e18+13;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll n;
	cin>>n;
	vector<ll> a(n),wa(n),cut1(n),cut2(n);
	FOR(i,0,n)cin>>a[i];
	wa[0]=a[0];
	FOR(i,1,n)wa[i]=wa[i-1]+a[i];
	ll r = 0;cut1[1]=0;
	FOR(i,2,n-1){
		while(1){
			ll p1,p2,q1,q2;
			p1 = wa[r];
			p2 = wa[r+1];
			q1 = wa[i] - p1;
			q2 = wa[i] - p2;
			if(abs(p1-q1)>abs(p2-q2)){
				r++;
			}else{
				break;
			}
		}
		cut1[i]=r;
	}
	r = 1;cut2[n-2] = n-2;
	FORR(i,1,n-2){
		while(1){
			ll r1,r2,s1,s2;
			r1 = wa[n-1] - wa[n-1-r];
			r2 = wa[n-1] - wa[n-2-r];
			s1 = wa[n-1] - wa[i] - r1;
			s2 = wa[n-1] - wa[i] - r2;
			if(abs(r1-s1)>abs(r2-s2)){
				r++;
			}else{
				break;
			}
		}
		cut2[i] = n-1-r;
	}
	ll ans = INF;
	FOR(i,1,n-1){
		ll p1,q1,r1,s1;
		p1 = wa[cut1[i]];
		q1 = wa[i] - p1;
		s1 = wa[n-1] - wa[cut2[i]];
		r1 = wa[cut2[i]] - wa[i];
		ll ansi = max({p1,q1,s1,r1})-min({p1,q1,s1,r1});
		ans = min(ans,ansi);
	}
	cout<<ans<<endl;

}

Measured memory_bytes: 6528
<?php
    /*
        Problem URL : http://agc008.contest.atcoder.jp/tasks/agc008_a
        Score  :
        Result :
        Time   : ms
        Memory : KB
     */
 
    ini_set('error_reporting', E_ALL & ~E_NOTICE);
    // define('DEBUG', true);
    define('DEBUG', false);

    $arr = array();

    fscanf(STDIN, "%d %d", $N, $K);
    $a = explode(" ", trim(fgets(STDIN)));
    $arrL = array();
    $arrR = array();

    $arrL[0] = $a[0] > 0 ? $a[0] : 0;
    for ($i = 1; $i < $N; $i++) {
        $arrL[$i] = $arrL[$i-1] + ($a[$i] > 0 ? $a[$i] : 0);
    }

    $arrR[$N-1] = $a[$N-1] > 0 ? $a[$N-1] : 0;
    for ($i = $N-2; $i >= 0; $i--) {
        $arrR[$i] = $arrR[$i+1] + ($a[$i] > 0 ? $a[$i] : 0);
    }
    ksort($arrR);

    $tmp = 0;
    for ($i = 0; $i < $N - $K + 1; $i++) {
        if ($i == 0) {
            for ($j = 0; $j < $K; $j++) {
                $tmp += $a[$j];
            }
        } else {
            $tmp += $a[$i + $K - 1] - $a[$i - 1];
        }
        $arrM[$i] = $arrL[$i - 1] + max(0, $tmp) + $arrR[$i + $K];
    }

    // var_dump($arrL);
    // var_dump($arrR);
    // var_dump($arrM);
    echo max($arrM) . PHP_EOL;


Measured memory_bytes: 22508
#include <bits/stdc++.h>
#define IO ios::sync_with_stdio(0);cin.tie(0)
#define endl '\n'
#define MAXN 100005

using namespace std;

int N, M;
int cnt;
vector<int> E[MAXN];
bool vis[MAXN];

void dfs(int cur) {
	vis[cur] = true;
	for (auto &i: E[cur]) {
		if (!vis[i]) {
			dfs(i);
		}
	}
}

signed main()
{
	IO;
	cin >> N >> M;
	for (int i = 0; i < M; i++) {
		int s, t;
		cin >> s >> t;
		s--, t--;
		E[s].emplace_back(t);
		E[t].emplace_back(s);
	}

	for (int i = 0; i < N; i++) {
		if (!vis[i]) {
			cnt++;
			dfs(i);
		}
	}

	cout << cnt - 1 << endl;

	return 0;
}


Measured memory_bytes: 9708
H, W = map(int, input().split())
N = int(input())
a = [int(x) for x in input().split()]
temp = []
for i in range(N):
    for _ in range(a[i]):
        temp.append(i+1)
ans = []
for i in range(H):
    ans = temp[i*W:(i+1)*W]
    if i&1:
        ans.reverse()
    print(*ans)


Measured memory_bytes: 9632
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#define _USE_MATH_DEFINES
#include <cmath>

#define rep(i, n)     for (int (i) = 0; (i) < (n); (i)++)
#define rep1(i, n)    for (int i = 1; i <= (int)(n); i++)

using namespace std;
typedef long long ll;

struct Card {
   char suit;
   int  num;
};

const int MAX = 100100;
const int INF = 2e9;
Card A[MAX], B[MAX];

int partition(int p, int q) {
   int i = p - 1;
   int r = A[q].num;

   for (int j = p; j < q; j++) {
      if (A[j].num <= r) {
         i++;
         swap(A[i], A[j]);
      }
   }
   swap(A[i + 1], A[q]);
   return(i + 1);
}

void quickSort(int p, int q) {
   if (p < q) {
      int ans = partition(p, q);
      quickSort(p, ans - 1);
      quickSort(ans + 1, q);
   }
}

void merge(int head, int mid, int tail) {
   int  n1 = mid - head;
   int  n2 = tail - mid;
   Card L[n1 + 1], R[n2 + 1];

   rep(i, n1) L[i] = B[head + i];
   rep(i, n2) R[i] = B[mid + i];
   L[n1].num = R[n2].num = INF;

   int l = 0, r = 0;
   for (int i = 0; i < tail - head; i++) {
      if (L[l].num <= R[r].num) {
         B[head + i] = L[l];
         l++;
      }
      else{
         B[head + i] = R[r];
         r++;
      }
   }
}

void mergeSort(int head, int tail) {
   int mid = (head + tail) / 2;

   if (head + 1 < tail) {
      mergeSort(head, mid);
      mergeSort(mid, tail);
      merge(head, mid, tail);
   }
}

int main() {
   int  n, cur_num;
   char cur_suit[10];
   bool or_stable = true;

   cin >> n;
   rep(i, n) {
      scanf("%s %d", cur_suit, &cur_num);
      A[i].num  = B[i].num = cur_num;
      A[i].suit = B[i].suit = cur_suit[0];
   }
   quickSort(0, n - 1);
   mergeSort(0, n);
   rep(i, n) {
      if (A[i].suit != B[i].suit) or_stable = false;
   }
   cout << (or_stable ? "Stable" : "Not stable") << endl;
   rep(i, n) {
      printf("%c %d\n", A[i].suit, A[i].num);
   }
   return(0);
}



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

int main()
{
    int n,cnt=0,i;
    string s;
    cin>>n>>s;
    for(i=0; i<n;)
    {
        if(s[i]=='A' && s[i+1]=='B' && s[i+2]=='C')
        {
            cnt++;
            i=i+3;
        }
        else
            i++;
    }
    cout<<cnt<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<deque>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

int main()
{
	string S;
	cin >> S;
	int ans = 700;
	for (int i = 0; i < 3; i++) {
		if (S[i] == 'o') ans += 100;
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
//agc030_a.cpp
//Sat Jan  5 12:05:44 2019

#include <iostream>
#include <string>
#include <queue>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#define INTINF 2147483647
#define LLINF 9223372036854775807
using namespace std;
using ll=long long;
typedef pair<int,int> P;

int main(){
	ll a,b,c;
	cin >> a >> b >> c;

	ll ans = 0;
	if (a+b >= c-1){
		ans += c;
	}else {
		ans += a+b+1;
	}

	cout << ans+b << endl;
//	printf("%.4f\n",ans);
}

Measured memory_bytes: 256
N, M = gets.split.map(&:to_i)
as = gets.split.map(&:to_i)
bcs = []
M.times do |i|
  bcs << gets.split.map(&:to_i)
end
bcs.sort! { |(b1,c1),(b2,c2)| c2<=>c1}
n = N
bcs2 = []
bcs.each do |bc|
  t = [bc[0], n].min
  n -= t
  bcs2 << [bc[1]] * t
  break if n == 0
end
bcs2.flatten!
puts (as + bcs2).sort.reverse[0..N-1].inject(:+)


Measured memory_bytes: 26744
import sys

def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり

N = I()
a = LI()

ans = 0
for i in range(0,N,2):
    if a[i] % 2 == 1:
        ans += 1

print(ans)

Measured memory_bytes: 61296
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MAX 510000
#define MOD 1000000007
#define rep(i, a, n) for (ll i = a; i < n; ++i)
#define all(x) x.begin(), x.end()
int main(void)
{
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    int h, w, k;
    cin >> h >> w >> k;
    vector<string> c(h);
    vector<int> tate(w), yoko(h);
    rep(i, 0, h) cin >> c[i];
    ll cta = 0, ans = 0;
    rep(i, 0, h) rep(j, 0, w) if (c[i][j] == '#') cta++, yoko[i]++, tate[j]++;
    // rep(i, 0, h) if (yoko[i] == k) ans++;
    // rep(i, 0, w) if (tate[i] == k) ans++;
    rep(i, 0, 1 << h)
    {
        rep(j, 0, 1 << w)
        {
            vector<int> x, y;
            rep(a, 0, h) if (i >> a & 1) y.push_back(a);
            rep(a, 0, w) if (j >> a & 1) x.push_back(a);
            int res = 0;

            for (auto a : y)
                res += yoko[a];
            for (auto a : x)
                res += tate[a];
            for (auto a : y)
            {
                for (auto b : x)
                {
                    if (c[a][b] == '#')
                        res--;
                }
            }
            if (cta - res == k)
                ans++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3652
import scala.collection.mutable._
import io.StdIn.readInt
import io.StdIn.readLine

object Main extends App {
  val out = new java.io.PrintWriter(System.out)

  def calculate(q:Array[Int],d:Array[Array[Int]]):Int = {
    val ts = q(0)
    val te = q(1)
    val st = q(2)

    val a = d.filter(_(2) == st)
    val map = new HashMap[Int,Array[Int]]
    val log = new ListBuffer[Tuple2[Int,Int]]
    a.foreach(l => {
      if(l(3) == 1) map.put(l(1),l)
      else {
        val e = map(l(1))
        log += {( e(0), l(0) )}
        }
    })
    // println(log.mkString)

    val time = Array.ofDim[Boolean](721)
    log.foreach(t => {
      val s = math.max(ts, t._1) -540
      val e = math.min(te, t._2) -540
      (s until e).foreach(time(_) = true)
    })
    time.count(_ == true)
  }

  def solve(s:String):Unit = {
    val Array(n, m) = s.split(" ").map(_.toInt)
    val r = readInt
    val d = Iterator.continually(readLine)
      .take(r)
      .map(_.split(" ").map(_.toInt))
      .toArray
    val q = readInt
    Iterator.continually(readLine)
      .take(q)
      .map(_.split(" ").map(_.toInt))
      .foreach(qd => out.println(calculate(qd,d)))
  }

  Iterator.continually(readLine)
    .takeWhile(_ != "0 0")
    .foreach(solve(_))
  
  out.flush
}


Measured memory_bytes: 59620
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<time.h>
using namespace std;
#define int long long
#define inf 1e9+7
typedef pair<int, int> P;
int d[114],s[114];

signed main() {
	string s;
	cin >> s;
	s[3] = '8';
	cout << s << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(v) v.begin(),v.end()
#define len(x) (ll)(x).length()
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int INF=1e9;
const ll INFS=1e18;
const int MOD=INF+7;
const int di[] = {-1,0,1,0};
const int dj[] = {0,-1,0,1};

ll choose2(ll n){
  return n*(n-1)/2;
}
 
int main(){
  int n;
  cin>>n;
  vector<int> a(n);
  vector<int> cnt(n);
  rep(i,n) cin>>a[i];
  rep(i,n) a[i]--;
  ll tot=0;
  rep(i,n) cnt[a[i]]++;
  rep(i,n) tot+=choose2(cnt[i]);
  rep(i,n){
    ll ans=tot;
    ans-=choose2(cnt[a[i]]);
    cnt[a[i]]--;
    ans+=choose2(cnt[a[i]]);
    cnt[a[i]]++;
    cout<<ans<<endl;
  }
}

Measured memory_bytes: 4852
using System;

class Program
{
    public static void Main()
    {
        int mondaiN = int.Parse(Console.ReadLine());
        string[] str = Console.ReadLine().Split(' ');
        int[] time = new int[str.Length];
        int syuruiM = int.Parse(Console.ReadLine());
        int[,] drink = new int[syuruiM, 2]; 
        for(int i=0; i < syuruiM; i++){
            string[] tmp = Console.ReadLine().Split(' ');
            drink[i,0] = int.Parse(tmp[0]);
            drink[i,1] = int.Parse(tmp[1]);
        }
        for(int i=0; i<str.Length; i++){
            time[i] = int.Parse(str[i]);
        }

        int[] ans = new int[syuruiM];
        for(int i=0; i < syuruiM; i++){
            for(int j=1; j <= mondaiN; j++){
                if(drink[i,0] == j){
                    ans[i] += drink[i,1];
                }else{
                    ans[i] += time[j-1];
                }
            }
        }

        // 出力
        for(int i=0; i < ans.Length; i++){
            Console.WriteLine(ans[i]);
        }
    }
}

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

int main()
{
  string s;
  cin >> s;
  
  int n = s.size();
  int64_t ans = 0;
  for(int bit = 0; bit < (1 << (n-1)); bit++){
    int64_t tmp = 0;
    int i = 0;
    for(i = 0; i < n-1; i++){
      tmp *= 10;
      tmp += s[i] - '0';
      if(bit & (1 << i)){
        ans += tmp;
        tmp = 0;
      }//if
    }//for
    
    tmp *= 10;
    tmp += s[i] - '0';
    ans += tmp;
  }//for
  
  cout << ans << endl;
}

Measured memory_bytes: 3628
S = input()
mod = 2019

cs_mods = {0:1}
cumsum = 0
count = 0
for i, s in enumerate(S[::-1]):
    cumsum = (cumsum + int(s) * pow(10, i, mod)) % mod
    cs_mods.setdefault(cumsum, 0)
    # count += cs_mods[cumsum]
    cs_mods[cumsum] += 1

# count = 0
for k, v in cs_mods.items():
    count += v*(v-1)//2

print(count)

Measured memory_bytes: 9388
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef set<int> si;
typedef map<string, int> msi;
#define REP(i,a,b) \
for(int i=int(a);i<=int(b);i++)
#define DEP(i,a,b) \
for(int i=int(a);i>=int(b);i--)
#define TR(c, it) \
for (auto it = (c).begin(); it != (c).end(); it++)

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll n,m,i,j,k,l;
	cin>>n>>m;
	ll h[n];REP(i,0,n-1)cin>>h[i];
	ll adj[n]={0};
	REP(i,0,m-1){
		cin>>k>>l;
		adj[k-1]=max(adj[k-1],h[l-1]);
		adj[l-1]=max(adj[l-1],h[k-1]);
	}
	ll ans=0;
	REP(i,0,n-1){
		if(adj[i]<h[i])
			ans++;
	}
	cout<<ans;
	return 0;
}


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

typedef long long ll;

const ll sz = 1e6+5;
ll dat[sz];
ll depth[sz];
bool visited[sz];
deque<ll> asu;

ll dfs(ll curr) {
  visited[curr] = 1;
  if (!visited[dat[curr]]) {
    asu.push_back(curr);
    return 1 + dfs(dat[curr]);
  }
  asu.push_back(curr);
  return 1;
}

int main() {
  ll N, K;
  cin >> N >> K;
  for (ll i = 0; i < N; ++i) {
    cin >> dat[i];
    --dat[i];
  }
  ll dalam = dfs(0);
  while (K > 0 && !asu.empty() && asu.front() != dat[asu.back()]) {
    --K;
    asu.pop_front();
  }
  K %= asu.size();
  printf("%lld\n", asu[K]+1);
  return 0;
}


Measured memory_bytes: 12680
A, B, C = map(int, input().split())

List = []
List.append(A)
List.append(B)
List.append(C)

big_digit = str(max(List))
del List[List.index(max(List))]

small_digit = str(List[0])

num = big_digit + small_digit
num = int(num)

print(num + List[1])


Measured memory_bytes: 3060
function Main(input) {
  var K = parseInt(input.split(" ")[0]);
  var X = parseInt(input.split(" ")[1]);
  
  var Kmin = X -(K - 1);
  var Kmax = X +(K - 1);
  //console.log("Kminは" + Kmin + "です。Kmaxは" + Kmax + "です");
  var output = "";
  for(var i = Kmin; i <= Kmax; i++){
   	 if(output == ""){
        output = i.toString();
        }else{
         output += " " +  i.toString();
        }
  }
  console.log(output);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


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

#ifdef LOCAL
#include "../dump.hpp"
#else
#define dump(...)
#define showvv(v)
#endif

using namespace std;

#define rep(i,n) for(int i=0,i##_len=(n);i<i##_len;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ROF(i,a,b) for(int i=(a)-1;i>=(b);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend() //sortで大きい順
#define UNIQUE(v) v.erase(unique(all(v)),v.end())
#define SUM(a) accumulate(all(a),0)
#define sz(x) ((int)(x).size())
#define pb push_back
#define fst first
#define snd second

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

int main(){
  int a,b; cin >> a >> b; a--; b--;
  
  char ans[100][100];
  rep(i,50) rep(j,100) ans[i][j] = '#';
  FOR(i,50,100) rep(j,100) ans[i][j] = '.';
  
  int x = 0,y = 0;
  while(a > 0){
    a--;
    ans[x][y] = '.';
    y += 2;
    if(y >= 100){
      y = 0;
      x += 2;
    }
  }

  x = 99; y = 0;
  while(b > 0){
    b--;
    ans[x][y] = '#';
    y += 2;
    if(y >= 100){
      y = 0;
      x -= 2;
    }
  }

  cout << "100 100\n";
  rep(i,100){
    rep(j,100) cout << ans[i][j];
    cout << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
using namespace std;
char strs[110][110];
int main(){
	int N,cn,cnt;
	bool ok;
	char teho[30];
	cin>>N;
	cin>>teho;
	for(int i=0;i<N;i++){
		cin>>strs[i];
	}
	cnt=0;
	for(int i=0;i<N;i++){
		for(int j=0;j<(int)strlen(strs[i]);j++){
			for(int k=1;j+k<(int)strlen(strs[i]);k++){
				cn=0;
				for(int l=j;l<(int)strlen(strs[i]);l+=k){
					if(teho[cn]!=strs[i][l]){
						break;
					}
					cn++;
				}
				//cout<<i<<" "<<j<<" "<<k<<"  "<<cn<<endl;//
				if(cn==strlen(teho)){
					cnt++;
					goto hog;
				}
			}
		}
hog:;

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

Measured memory_bytes: 1176
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <math.h>
typedef long long ll;
char lowcmp[26]="abcdefghijklmnopqrstuvwxyz";
char upcmp[26]="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
long long mod=1000000007;

long long max(long long A,long long B){
    return A>B?A:B;
}

long long min(long long A,long long B){
    return A<B?A:B;
}

void swap(long long *A,long long *B){
    long long T;
    T=*A;
    *A=*B;
    *B=T;
}

int main(void){
    int a,b,c;
    scanf("%d%d%d",&a,&b,&c);
    if(a==b &&b==c){
        printf("Yes\n");
    } else {
        printf("No\n");
    }
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define si size()
#define bk back()
#define popb pop_back()
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define endl "\n"
#define lb lower_bound
#define ub upper_bound
#define emp empty()
#define beg begin()
#define en end()
#define ump unordered_map
#define forl(i,a,n) for(int i=a;i<n;i++)
#define rfor(i,n,a) for(int i=n;i>=a;i--)
#define fore(i,a,n) for(int i=a;i<=n;i++)
#define len length()
#define ld long double
const int mod=1e9+7;
int main()
{
    int n,k;
    cin>>n>>k;
    ll arr[n];
    forl(i,0,n) cin>>arr[i];
    bool dp[k+1];
    forl(i,0,k+1) dp[i]=false;
    dp[0]=false;
    forl(i,1,k+1)
    {
        forl(j,0,n)
        {
            if(i-arr[j]>=0)dp[i]=(dp[i] || (!dp[i-arr[j]]));
        }
    }
    if(dp[k]) cout<<"First"<<endl;
    else cout<<"Second"<<endl;


}

Measured memory_bytes: 384
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;
 
const ll nmax = 1e9 + 7;
const ll Mod = 998244353;
const double PI = 2 * asin(1);


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

  Pil AB[N];
  for (int i = 0; i < N; i++){
    cin >> AB[i].first >> AB[i].second;
  }
  sort(AB, AB + N);

  ll now = 0;
  for (int i = 0; i < N; i++){
    if (now + AB[i].second >= K){
      cout << AB[i].first << endl;
      return 0;
    }
    now += AB[i].second;
  }
  cout << AB[N - 1].first << endl;

  return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;cin>>s;
  int sum = 0;
  for(int i=0;i<s.size();i++){
    sum = (sum+(s[i]-48))%9;
  }
  if(sum %9==0){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
  return 0;
}
    


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

#define fst first
#define snd second
#define ll long long
#define ld long double
#define pb push_back
#define emp emplace_back
#define pii pair<int, int>
#define usg unsigned
#define sg signed
#define mp make_pair

using namespace std;

void setIO(){
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
}

const ld PI = 4*atan((ld)1);
const int INF = 1e9+7;
const int mxn = 3007;

ll dp[mxn][mxn][4], a[mxn][mxn];
int r, c, k;

int main(){
	setIO();
	cin >> r >> c >> k;
	for (int i = 0; i < k; i++){
		int x, y, v; cin >> x >> y >> v;
		a[x-1][y-1] = v;
	}
	dp[0][0][1] = a[0][0];
	for (int i = 0; i < r; i++){
		for (int j = 0; j < c; j++){
			for (int k = 0; k < 4; k++){
				if (i+1 < r){
					dp[i+1][j][0] = max(dp[i+1][j][0], dp[i][j][k]);
					dp[i+1][j][1] = max(dp[i+1][j][1], dp[i][j][k]+a[i+1][j]);
				}
				if (j+1 < c){
					dp[i][j+1][k] = max(dp[i][j+1][k], dp[i][j][k]);
					if (k+1 < 4)
						dp[i][j+1][k+1] = max(dp[i][j+1][k+1], dp[i][j][k]+a[i][j+1]);
				}
			}
		}
	}
	ll ans = 0;
	for (int i = 0; i < 4; i++)
		ans = max(ans, dp[r-1][c-1][i]);
	cout << ans << endl;
}

Measured memory_bytes: 355876
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
#define Priq priority_queue<int,vi,greater<int>>
#define pb push_back
#define mp make_pair
#define INF (1ll<<60)
signed main(){
  int N; cin>>N;
  string S; cin>>S;
  int count1=0,count2=0,sum1=0,sum2=0;
  rep(i,0,N){
    if(S[i]=='(') count1--;
    else count1++;
    sum1=max(sum1,count1);
  }
  rep(i,0,N){
    if(S[N-1-i]==')') count2--;
    else count2++;
    sum2=max(sum2,count2);
  }
  rep(i,0,sum1) cout<<'(';
  cout<<S;
  rep(i,0,sum2) cout<<')';
  }


Measured memory_bytes: 256
"use strict";
const input = require("fs").readFileSync("/dev/stdin", "utf8");
const inputs = input.trim().split("\n");

const get = (inputs) => {
  const As = inputs.slice(1);
  
  let max = 1;
  let max2 = 1;
  for (const A of As) {
    const a = +A;
    if (max < a) {
      max = a;
    } else if (max2 < a) {
      max2 = a;
    }
  }
  
  return As.map(A => +A === max ? max2 : max).join("\n")
}

console.log( get(inputs) );

Measured memory_bytes: 46412
#include<bits/stdc++.h>
#include<queue>
using namespace std;
int main () {
  int H, W;
  cin >> H >> W;
  int si, sj, gi, gj;
  cin >> si >> sj >> gi >> gj;
  priority_queue<tuple<int, int, int>, vector<tuple<int, int, int>>, 
  greater<tuple<int, int, int>>> que;
  int dist[1003][1003];
  char maze[1004][1004];
  for (int i = 1; i <= H; i ++) {
    for (int j = 1; j <= W; j ++) {
      cin >> maze[i][j];
    }
  }
  for (int i = 0; i <= H; i ++) maze[i][0] = maze[i][W + 1] = '#';
  for (int j = 0; j <= W; j ++) maze[0][j] = maze[H + 1][j] = '#';
  que.push(make_tuple(0, si, sj));
  for (int i = 0; i <= H; i ++) {
    for (int j = 0; j <= W; j ++) {
      dist[i][j] = 10000003;
    }
  }
  dist[si][sj] = 0;
  int omi[] = {0, 1, 0, -1};
  int omj[] = {1, 0, -1, 0};
  int tmi[] = {-2, -2, -2, -2, -2, -1, 0, 1, 2, 2, 2, 2, 2, 1, 0, -1, -1, 1, -1, 1};
  int tmj[] = {-2, -1, 0, 1, 2, 2, 2, 2, 2, 1, 0, -1, -2, -2, -2, -2, -1, -1, 1, 1};
  while (!que.empty()) {
    int ui, uj, dis;
    tie(dis, ui, uj) = que.top();
    que.pop();
    while (dis != dist[ui][uj] && !que.empty()) {
      tie(dis, ui, uj) = que.top();
      que.pop();
    }
    for (int i = 0; i < 4; i ++) {
      int vi = ui + omi[i];
      int vj = uj + omj[i];
      if (maze[vi][vj] != '#') {
        if (dist[vi][vj] > dis) {
          dist[vi][vj] = dis;
          que.push(make_tuple(dis, vi, vj));
        }
      }
    }
    for (int i = 0; i < 20; i ++) {
      int vi = ui + tmi[i];
      int vj = uj + tmj[i];
      //if (ui == 3 && uj == 3) cout << vi << ' ' << vj << ' ' << endl;
      if (vi >= 0 && vi <= H && vj >= 0 && vj <= W && maze[vi][vj] != '#') {
        if (dist[vi][vj] > dis + 1) {
          dist[vi][vj] = dis + 1;
          que.push(make_tuple(dis + 1, vi, vj));
        }
      }
    }
    //cout << ui << ' ' << uj << ' ' << dis << endl;
  }
  cout << (dist[gi][gj] != 10000003 ? dist[gi][gj] : -1) << endl;
}

Measured memory_bytes: 8608
#include <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <tuple>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#include <complex>
#include <iterator>
#include <array>
#include <memory>
#include <stack>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<double,double>pdd;
typedef pair<ll,ll>pll;
int main(){
    int n;
    while(cin>>n,n){
    vi v(n);
    string s; cin>>s;
    int field=0;
    int now=0;
    rep(i,s.size()){
        if(s[i]=='M')v[i%n]++;
        else if(s[i]=='S'){field+=v[i%n]+1;v[i%n]=0;}
        else if(s[i]=='L'){v[i%n]+=field+1;field=0;}
    }
    int temp=0;
        sort(all(v));
    rep(i,n){
        if(!i)cout<<v[i];
        else cout<<" "<<v[i];
    }
    cout<<" "<<field<<endl;
    }
}

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

int main() {
  string s;
  cin >> s;
  for (int i = 0; i < s.size(); ++i) {
    if (s[i] == '?') cout << 'D';
    else cout << s[i];
  }
  cout << '\n';
  return 0;
}

Measured memory_bytes: 3760
#include <bits/stdc++.h>
#define IOS                                                                    \
  ios::sync_with_stdio(0);                                                     \
  cin.tie(0);                                                                  \
  cout.tie(0)
#define pb push_back
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
using namespace std;
using ll = long long;
using vi = vector<int>;
using pii = pair<ll, ll>;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
ll bpow(ll b, ll p, ll m = 1000000007LL) {
  ll rt = 1;
  for (; p; p >>= 1, b = b * b % m)
    if (p & 1)
      rt = rt * b % m;
  return rt;
}
vector<int> g[55];
int st[55], ft[55], low[55];
int vis[55];
int counter = 1;
int ans = 0;
void dfs(int u, int p = -1) {
  vis[u] = 1;
  st[u] = low[u] = counter++;
  st[u] = counter++;
  for (int v : g[u]) {
    if (v == p)
      continue;
    if (!vis[v]) {
      dfs(v, u);
      low[u] = min(low[u], low[v]);
      if (low[v] > st[u]) {
        ans++;
      }
    } else {
      low[u] = min(low[u], st[v]);
    }
  }
  ft[u] = counter++;
}
int main() {
  IOS;
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    g[u].pb(v);
    g[v].pb(u);
  }
  dfs(1);
  cout << ans << endl;
}


Measured memory_bytes: 3628
// JAI SHREE RAM
typedef long long int ll;
typedef unsigned long long int ull;
#define fast  ios_base::sync_with_stdio(false); cin.tie(NULL);
#define FOR(i,n) for(int i=0;i<n;i++)
#define MOD 1000000007
#define sz(a) int((a).size())
#define forn(i, n) for (int i = 0; i < (n); ++i)
#define fore(i, l, r) for (int i = int(l); i < int(r); ++i)
#define loop for(int i=0;i<n;i++)
#define max3(a,b,c) max(a,max(b,c))
#define max4(a,b,c,d) max3(a,max(b,c),d)
#define max5(a,b,c,d,e) max4(a,max(b,c),d,e)
#define min3(a,b,c) min(a,min(b,c))
#define min4(a,b,c,d) min3(a,min(b,c),d)
#define min5(a,b,c,d,e) min4(a,min(b,c),d,e)
#define sec second
#define fir first
// #define all(a) (a).begin(),(a).end()
#define vec vector<int>
#define M_PI           3.14159265358979323846  /* pi */
#define pb push_back
#define pii pair<int,int>
#include<bits/stdc++.h>
#include<cmath>
using namespace std;
struct three
{
	ll x,y,z;
};
struct three ans[100005];
ll n;
int memo[100005][3];
ll dp(ll i,ll m)
{

	if(i==n)
		return 0;
	else 
		{	
			if(memo[i][m]==-1)
			{
			if(m==1)
		 		return (memo[i][m]=max(ans[i].x+dp(i+1,2),ans[i].x+dp(i+1,3)));
		 	else if(m==2)
		 		return (memo[i][m]=max(ans[i].y+dp(i+1,1),ans[i].y+dp(i+1,3)));
		 	else
		 		return (memo[i][m]=max(ans[i].z+dp(i+1,2),ans[i].z+dp(i+1,1)));
		 	}
		 	else
		 		return memo[i][m];
		}
}
int main()
{


	cin >> n;
	memset(memo,-1,sizeof(memo));
	ll a,b,c;
	FOR(i,n)
	{
		cin>>a>>b>>c;
		ans[i].x=a;
		ans[i].y=b;
		ans[i].z=c;
	}
	cout<<max3(dp(0,1),dp(0,2),dp(0,3));


}

Measured memory_bytes: 8448
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0;i < (n);i++)
using namespace std;
  
int main () {
  int n , k;
  cin >> n >> k;
  double ans = 0.0;
  for(int i=1;i<=n;i++) {
    int p = i;
    double q = 1.0;
    while(p < k) {
      q *= 0.5;
      p *= 2;
    }
    ans += q;
  }
  cout << fixed << setprecision(10);
  cout << ans / n;
}


Measured memory_bytes: 256
require 'prime'
 
prime = Prime.each(2*10**5)
c = Array.new(2*10**5, 0)
l=[], r=[]
Q = gets.to_i
Q.times do |i|
	l[i], r[i] = gets.split.map(&:to_i)
end
 
isPrime = Array.new(2*10**5, false)
prime.each do |i|
	isPrime[i] = true
end
 
j = 1
while j < 100000
	c[j] += 1 if isPrime[j] && isPrime[(j+1)/2]
	j +=2
end
 
1.upto(100000) do |i|
	c[i] += c[i-1]
end
 
Q.times do |i|
	puts c[r[i]]-c[l[i]-1]
end

Measured memory_bytes: 7900
import numpy as np
n,k,q=map(int,input().split())	
listA=[] #appendのために宣言が必要
while True:
    try:
        listA.append(int(input()))
    except:
        break;
a=np.repeat(k-q,n)
for word in listA:
    a[word-1]+=1
result=[]
for i in range(len(a)):
    if a[i]<=0:
        print('No')
    else:
        print('Yes')

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

public class Main {
    private static boolean debug = false;
    private static boolean elapsed = false;

    private static PrintWriter _out = new PrintWriter(System.out);
    private static PrintWriter _err = new PrintWriter(System.err);

    private void solve(Scanner sc) {
        int N = sc.nextInt();
        int[] A = new int[N];
        long sum = 0;
        for (int i = 0; i < N; ++i) {
            A[i] = sc.nextInt() - (i + 1);
            sum += A[i];
        }
        Arrays.sort(A);
        long ans = 0;
        for (int i = 0; i < N; ++i) {
            ans += Math.abs(A[i] - A[N / 2]);
        }
        _out.println(ans);
    }
    private static BigInteger C(long n, long r) {
        BigInteger res = BigInteger.ONE;
        for (long i = n; i > n - r; --i) {
            res = res.multiply(BigInteger.valueOf(i));
        }
        for (long i = r; i > 1; --i) {
            res = res.divide(BigInteger.valueOf(i));
        }
        return res;
    }
    private static BigInteger P(long n, long r) {
        BigInteger res = BigInteger.ONE;
        for (long i = n; i > n - r; --i) {
            res = res.multiply(BigInteger.valueOf(i));
        }
        return res;
    }
    /*
     * 10^10 > Integer.MAX_VALUE = 2147483647 > 10^9
     * 10^19 > Long.MAX_VALUE = 9223372036854775807L > 10^18
     */
    public static void main(String[] args) {
        long S = System.currentTimeMillis();

        Scanner sc = new Scanner(System.in);
        new Main().solve(sc);
        _out.flush();

        long G = System.currentTimeMillis();
        if (elapsed) {
            _err.println((G - S) + "ms");
        }
        _err.flush();
    }
}

Measured memory_bytes: 64496
#include<stdio.h>
int main(){
    int i;
    int num[10001];
    for (i=1;i<10001;i++){
        scanf("%d",&num[i]);
        if(num[i]!=0){
            printf("Case %d: %d\n",i,num[i]);
        }else{
            i=10001;
        }
    }
    return 0;
}


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

struct SCC {
    int sz;
    vector<vector<int>> g, rg, dag, group;
    vector<int> cmp, ord, used;

    SCC (int n) : g(n), rg(n), cmp(n, -1), used(n, false) {}
    SCC (vector<vector<int>> &g) : g(g), rg(g.size()), cmp(g.size(), -1), used(g.size(), false) {
        for (int v = 0; v < (int)g.size(); ++v) for (int u : g[v]) rg[u].push_back(v);
        build();
    }

    void add_edge(int s, int t) {
        g[s].push_back(t);
        rg[t].push_back(s);
    }

    void dfs(int v) {
        if (used[v]) return;
        used[v] = true;
        for (auto &u : g[v]) dfs(u);
        ord.push_back(v);
    }

    void rdfs(int v) {
        if (~cmp[v]) return;
        cmp[v] = sz;
        for (auto &u : rg[v]) rdfs(u);
    }

    void build() {
        for (int i = 0; i < (int)g.size(); ++i) dfs(i);
        reverse(ord.begin(), ord.end());
        sz = 0;
        for (int i : ord) if (!~cmp[i]) rdfs(i), ++sz;
        dag.resize(sz);
        group.resize(sz);
        for (int i = 0; i < (int)g.size(); ++i) {
            for (int j : g[i]) {
                int x = cmp[i], y = cmp[j];
                if (x == y) continue;
                dag[x].emplace_back(y);
            }
            group[cmp[i]].push_back(i);
        }
    }

    // number of connected components
    int size() { return sz; }

    // the number of the component to which element x belongs
    int operator[](int x) { return cmp[x]; }

    bool same(int x, int y) { return cmp[x] == cmp[y]; }
};

int main() {
    int V, E;
    cin >> V >> E;
    vector<vector<int>> g(V);
    for (int i = 0; i < E; ++i) {
        int s, t;
        cin >> s >> t;
        g[s].push_back(t);
    }
    SCC scc(g);
    int Q;
    cin >> Q;
    for (int i = 0; i < Q; ++i) {
        int u, v;
        cin >> u >> v;
        cout << scc.same(u, v) << endl;
    }
}


Measured memory_bytes: 5092
A,B,C = map(int,input().split())
ans = 0
while A%2+B%2+C%2==0:
    if A==B==C:
        ans = -1
        break
    A,B,C = (B+C)//2,(C+A)//2,(A+B)//2
    ans += 1
print(ans)

Measured memory_bytes: 3060
#include <iostream>

using namespace std;

int main(){
    long N, A, B;
    cin >> N >> A >> B;

    long ans = (N/(A+B))*A;

    if(N%(A+B) >= A) ans += A;
    else ans += N%(A+B);

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

#define NIL -2000000001

typedef struct{
  int id;
  int l;
  int r;
} Node;

int L,R,n,m,i,largest;
Node node[500001];

void maxHeapify(Node A, int a){
  if(2*a <= n && node[A.l].id > node[a].id){
    largest = A.l;
  } else {
    largest = a;
  }
  if(2*a+1 <= n && node[A.r].id > node[largest].id){
    largest = A.r;
  }
  if(largest != a){
    m = node[a].id;
    node[a].id = node[largest].id;
    if(node[a].l == largest){
      node[2*a].id = m;
      maxHeapify(node[2*a],2*a);
    } else {
      node[2*a+1].id = m;
      maxHeapify(node[2*a+1],2*a+1);
    }
  }
}

void buildMaxHeap(void){
  for(i=n/2; i >= 1; i--){
    maxHeapify(node[i],i);
  }
}

int main(){

  scanf("%d",&n);

  for(i=1; i <= n; i++){
    node[i].l = node[i].r = NIL;
    scanf("%d",&node[i].id);
  }

  for(i=1; i <= n; i++){
    if(2*i <= n){
      node[i].l = 2*i;
    }
    if(2*i+1 <= n){
      node[i].r = 2*i+1;
    }
  }
  
  buildMaxHeap();
  
  for(i=1; i <= n; i++){
    printf(" %d",node[i].id);
  }
  printf("\n");

  return 0;

}



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

public class Main {
    public static void main(String[] args) {
        try (BufferedReader in = new BufferedReader(new InputStreamReader(System.in))){
            int taro = 0;
            int hanako = 0;

            int n = Integer.parseInt(in.readLine());
            for (int i = 0; i < n; i++) {
                String[] arr = in.readLine().split(" ");
                int cmp = arr[0].compareTo(arr[1]);
                if (cmp > 0) {
                    taro += 3;
                } else if (cmp == 0) {
                    taro++;
                    hanako++;
                } else {
                    hanako += 3;
                }
            }

            System.out.println(taro + " " + hanako);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}



Measured memory_bytes: 25240
#include<iostream>
#include<vector>
using namespace std;
int main()
{
    int n,m;
    cin>>n>>m;
    int M=1e9+7;
    vector<vector<char>> v;
    for (int i=0;i<n;i++)
    {
        vector<char> ch;
        for(int j=0;j<m;j++)
        {
            char a;
            cin>>a;
            ch.push_back(a);
        }
        v.push_back(ch);
    }
    vector<vector<long long>> dp(n+1,vector<long long>(m+1));
    dp[1][1]=1;
    for (int i=1;i<n+1;i++)
    {
        for(int j=1;j<m+1;j++)
        {
            if (v[i-1][j-1]!='#' and (i!=1 or j!=1))
            {
                dp[i][j]=dp[i-1][j]+dp[i][j-1];
                dp[i][j]%=M;
            }
        }
    }
    
    cout<<dp[n][m]%M;
}

Measured memory_bytes: 12036
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.*;
import java.util.Stack;

public class Main {
	
	public static class FastReader {
		BufferedReader br;
		StringTokenizer st;
	

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (Exception r) {
					r.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());//converts string to integer
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (Exception r) {
				r.printStackTrace();
			}
			return str;
		}
	}
	
	public static PrintWriter out = new PrintWriter (new BufferedOutputStream(System.out));
   
  // static Scanner sc = new Scanner(System.in);
  
    private final static int mod = (int) (1e9 + 7);
    private final static int N = (int) (1e6);
	public static void main(String[] args) {
	   
	 FastReader sc = new FastReader();
	 int n = sc.nextInt();
	 long[][] tab = new long[n][3];
	 for(int i=0;i<n;++i) {
		 for(int j=0;j<3;++j) {
			 tab[i][j] = sc.nextLong();
		 }
	 }
	 
	 for(int i=n-2;i>=0;--i) {
		 tab[i][0] +=Math.max(tab[i+1][1], tab[i+1][2]);
		 tab[i][1] +=Math.max(tab[i+1][0], tab[i+1][2]);
		 tab[i][2] +=Math.max(tab[i+1][0], tab[i+1][1]);
	 }
	 
	 out.print(Math.max(tab[0][0], Math.max(tab[0][1], tab[0][2])));
	 out.close();
    
	}

	private static long pow(long a, int b) {
		if(b == 0) return 1;
		long temp = pow(a,b/2);
		temp = (temp*temp)%mod;
		if((b&1) == 1) temp = (a*temp)%mod;
		return temp;
	}
}

Measured memory_bytes: 48708
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <queue>
#include <map>
using namespace std;
typedef long long ll;
const int INF = 1<<30; 
const int MOD = 1e9 + 7;
const int dy[] = {1, 0, -1, 0};
const int dx[] = {0, 1, 0, -1};
using namespace std;
 
long long p[55], sz[55];
 
long long dfs(long long n, long long x) {
    if (n == 0) return x <= 0 ? 0 : 1;
    if (x <= sz[n - 1] + 1) return dfs(n - 1, x - 1);
    return p[n - 1] + 1 + dfs(n - 1, x - sz[n - 1] - 2);
}
 
int main() {
    p[0] = 1, sz[0] = 1;
    for (int i = 1; i <= 50; i++) {
        p[i] = 2 * p[i - 1] + 1;
        sz[i] = 2 * sz[i - 1] + 3;
    }
    long long n, x;
    cin >> n >> x;
    cout << dfs(n, x) << endl;
    return 0;
}

Measured memory_bytes: 256
// ?????¬???????????¬??????

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define int long long int

template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}

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

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
constexpr ll INF = 1001001001001001LL;
constexpr ll MOD = 1000000007LL;

int N, a[110], b[110];
int l[110], r[110];
vector<int> v;

// ?????? a ??§?????? [s, t)????????? b ??§?????? [x, y) ????????? (??¨?????¨)
void solve(int s, int t, int x, int y) {
    if(t - s <= 1) return;
    int root = a[s];
    int idx = find(b, b+N, root) - b; // b ?????????????????????????????????

    bool exist[110] = {};
    rep(i,idx+1,y) exist[ b[i] ] = true;
    int mi = INF; // a ?????????????????¨?????¨????§???????????????????
    rep(i,s,t) if(exist[ a[i] ]) chmin(mi, i);

    // printf("s = %lld, t = %lld, x = %lld, y = %lld\n", s, t, x, y);
    // printf("root = %lld, idx = %lld, mi = %lld\n", root, idx, mi);

    if(idx != x && idx != y-1) l[root] = a[s+1], r[root] = a[mi];
    else if(idx == x) r[root] = a[mi];
    else if(idx == y-1) l[root] = a[s+1];

    // printf("l = %lld, r = %lld\n", l[root], r[root]);

    chmin(mi, t);
    solve(s+1, mi, x, idx);
    solve(mi, t, idx+1, y);
}

void pushans(int p) {
    if(l[p] != -1) pushans(l[p]);
    if(r[p] != -1) pushans(r[p]);
    v.push_back(p);
}

signed main() {
    cin >> N;
    rep(i,0,N) cin >> a[i];
    rep(i,0,N) cin >> b[i];

    memset(l, -1, sizeof(l));
    memset(r, -1, sizeof(r));
    solve(0, N, 0, N);
    pushans(a[0]);

    rep(i,0,N) cout << (i == 0 ? "" : " ") << v[i];
    cout << endl;
    return 0;
}

Measured memory_bytes: 3148
function main(input) {
  const inputs = input.split('\n')
  const ss = inputs.slice(1)
  const r = {}
  ss.forEach(e => {
    r[e] = 1
  })
  // console.log(Object.keys(r))
  console.log(Object.keys(r).length)
}

main(require('fs').readFileSync('/dev/stdin', 'utf8').trim())


Measured memory_bytes: 85052
char s[]="RYGB";main(){int h,w,d,i,j;scanf("%d%d%d",&h,&w,&d);for(i=0;i<h;++i,puts(""))for(j=0;j<w;++j)putchar(s[(i+j)/d%2*2+(i-j+w)/d%2]);}

Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <cassert>
using namespace std;
typedef long long ll;
const int INF = 1<<30;
const ll MOD = 1e9+7;
const double EPS = 1e-9;


int main(int argc, const char * argv[]) {
  int n, d; cin >> n >> d;
  cout << (n + 2*d)/(2*d + 1) << endl;
  return 0;
}

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

int main(){
    ll ans = 0; 
    int n, tt; cin >> n >> tt;
    vector<int> t(n);
    rep(i,n) cin >> t[i];

    for(int i = 0; i < n-1; i++){
        ans += min(tt,abs(t[i+1] - t[i]));
    }
    ans += tt;

    put(ans);
}

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

int main()
{
    int out = 0;
    string s;
    cin >> s;


    if (s[0] == 'R' && s[1] == 'R' && s[2] == 'R') cout << 3 << endl;
    else if (s[0] == 'R' && s[1] == 'R' || s[1] == 'R' && s[2] == 'R') cout << 2 << endl;
    else if (s[0] == 'S' && s[1] == 'S' && s[2] == 'S') cout << 0 << endl;
    else cout << 1 << endl;

    return 0;
}

Measured memory_bytes: 3624
#pragma GCC optimize ("O3")
#pragma GCC target ("tune=native")
#pragma GCC target ("avx")

#include <bits/stdc++.h>

// 汎用マクロ
#define ALL_OF(x) (x).begin(), (x).end()
#define REP(i,n) for (long long i=0, i##_len=(n); i<i##_len; i++)
#define RANGE(i,is,ie) for (long long i=(is), i##_end=(ie); i<=i##_end; i++)
#define DSRNG(i,is,ie) for (long long i=(is), i##_end=(ie); i>=i##_end; i--)
#define UNIQUE(v) { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); }
template<class T> bool chmax(T &a, const T &b) {if (a < b) {a = b; return 1;} return 0; }
template<class T> bool chmin(T &a, const T &b) {if (a > b) {a = b; return 1;} return 0; }
#define INF 0x7FFFFFFF
#define LINF 0x7FFFFFFFFFFFFFFFLL
#define Yes(q) (q ? "Yes" : "No")
#define YES(q) (q ? "YES" : "NO")
#define DUMP(q) cerr << "[DEBUG] " #q ": " << (q) << " at " __FILE__ ":" << __LINE__ << endl
#define DUMPALL(q) cerr << "[DEBUG] " #q ": ["; REP(dumpall_i, (q).size()) { cerr << q[dumpall_i] << (dumpall_i == (q).size() - 1 ? "" : ", "); } cerr << "] at " __FILE__ ":" << __LINE__ << endl

// gcc拡張マクロ
#define gcd __gcd
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll

// エイリアス
using  ll = long long;
using ull = unsigned long long;
using  ld = long double;
using namespace std;

// モジュール


// 処理内容
int main() {

    while (true) {
    
        ll n; cin >> n;
        if (!n) break;
        vector<ll> a(n); REP(i, n) cin >> a[i];

        sort(ALL_OF(a));

        ll mind = LINF;
        REP(i, n-1) {
            chmin(mind, a[i+1] - a[i]);
        }
        cout << mind << endl;

    }
    
}


Measured memory_bytes: 3152
#include <bits/stdc++.h>
#define SIZE 10
#define PI 3.141592653589793

using namespace std;
typedef long long ll;
typedef unsigned long long ull;

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

	int i,j;
	int answer=0;
	ll N;
	ll money=100;
	ll counter=0;
	vector<int> given;

	cin >> N;

	while(money<N){
		//cout << std::fixed << std::setprecision(15) << money << endl;
		money=(ll)(money*1.01);

		counter++;
	}
	
	cout << counter << endl;

	return 0;
}



Measured memory_bytes: 3632
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <math.h>
#include <sstream>
#include <iterator>

using namespace std;

#define endl ("\n")
#define pi (3.141592653589)
#define mod 1000000007
#define int int64_t
#define float double
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(c) c.begin(), c.end()
#define min3(a, b, c) min(c, min(a, b))
#define min4(a, b, c, d) min(d, min(c, min(a, b)))
#define rrep(i, n) for(int i=n-1;i>=0;i--)
#define rep(i,n) for(int i=0;i<n;i++)
#define fast ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)

struct debugger
{
    template<typename T> debugger& operator , (const T& v)
    {    
        cerr<<v<<" ";    
        return *this;    
    }
} dbg;

int32_t main() 
{
    fast;
	int t;
	cin >> t;
	vector<double> x;
	while(t--){
       double n;
		cin >> n;	   
		x.push_back(n);
	}
	sort(x.begin(), x.end());
	double res = 0;
	for(int i=0; i < x.size()-1; i++){
		res+=x[i];
	}
	res+=x[x.size()-1]/2;
	cout << res;
}





Measured memory_bytes: 3812
#include<iostream>
#include<cstdint>
#include<vector>
#include<cstdlib>
template<typename T>
void fin(T const& t){ std::cout << t << std::endl; exit(0); }

int main() {
  std::cin.tie(0); std::ios::sync_with_stdio(false);
  int N; std::cin >> N;
  std::vector<int64_t> A(N);
  for(int i = 0; i < N; ++i) std::cin >> A[i];
  for(int i = 0; i < N; ++i) if(A[i] == 0) fin(0);
  int64_t ans = 1, ma = 1e18;
  for(int i = 0; i < N; ++i) {
    if(ans > (ma+A[i]-1)/A[i]) fin(-1);
    ans *= A[i];
    if(ans > ma) fin(-1);
  }
  fin(ans);
  return 0;
}


Measured memory_bytes: 4440