akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>
#include<complex>

using namespace std;

#define ll long long
#define ld long double
#define EPS 1e-9
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef pair<int,pii> pip;
typedef vector<pii> vp;
typedef vector<vi> vvi;

int gcd(int a, int b){if(b==0) return a;return gcd(b,a%b);}
int lcm(int a, int b){return a/gcd(a,b)*b;}


signed main(void) {
    int n,m,l;
    cin >> n >> m >> l;
    int d[305][305] = {};
    rep(i,n)rep(j,n)if(i!=j)d[i][j] = LINF;
    rep(i,m){
        int a,b,c;
        cin >> a >> b >> c;
        a--;b--;
        if(c > l)continue;
        d[a][b] = d[b][a] = c;
    }
    rep(k,n)rep(j,n)rep(i,n){
        d[i][j] = min(d[i][j],d[i][k]+d[k][j]);
    }
    int g[305][305];
    rep(i,n)rep(j,n){
        if(i == j)g[i][j] = 0;
        else if(d[i][j] <= l)g[i][j] = 1;
        else g[i][j] = LINF;
    }
    rep(k,n)rep(j,n)rep(i,n){
        g[i][j] = min(g[i][j],g[i][k]+g[k][j]);
    }
    int q;
    cin >> q;
    while(q--){
        int s,t;
        cin >> s >> t;
        s--,t--;
        if(g[s][t] == LINF){
            cout << -1 << endl;
        }else{
            cout << g[s][t]-1 << endl;
        }
    }
}


Measured memory_bytes: 1920
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
bitset<2000000 + 5> d;
int main () {
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  d[0] = 1;
  int sum = 0;
  for(int i = 0; i < N; ++i) {
    int a;
    cin >> a;
    d |= d << a;
    sum += a;
  }

  for(int i = (sum + 1) / 2; ; i++) {
    if (d[i]) {
      cout << i;
      return 0;
    }
  }

}

Measured memory_bytes: 1152
fn main(){
    proconio::input!{
        mut x: u64
    }
    let mut yokin = 100;
    let mut cnt = 0;
    loop{
        yokin = (yokin as f64 * 1.01) as u64;
        cnt += 1;
        if x <= yokin{
            break;
        }
    }
    println!("{}", cnt);
}

Measured memory_bytes: 2156
import math
import bisect
import heapq
from collections import deque

n = int(input())

h = list(map(int, input().split()))

d = [float('inf')] * n
d[0] = 0
d[1] = abs(h[0] - h[1])

for i in range(2,n):
    d[i] = min(d[i-1] + abs(h[i-1]-h[i]), d[i-2] + abs(h[i-2]-h[i]))

print(d[n-1])


Measured memory_bytes: 14620
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int l = scan.nextInt();
		List<String> list = new ArrayList<String>();
		for (int i = 0; i < n; i++) {
			list.add(scan.next());
		}
		Collections.sort(list);
		for (String s : list) {
			System.out.print(s);
		}
		System.out.println();
	}
}

Measured memory_bytes: 22100
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(n);i++)
int main(){
	ll n,x; cin>>n;
	ll cnt[n+1]={0};
	for(int i=0;i<n-1;i++) cin>>x,cnt[x]++;
	for(int i=1;i<=n;i++) cout<<cnt[i]<<endl;
}


Measured memory_bytes: 5108
#include <bits/stdc++.h>
using namespace std;
int main(){
  int A,B,C,X,Y,Z;
  cin>>A>>B>>C>>X>>Y;
  if(X>Y){
    int Z=X-Y;
    cout<<min((A*X)+(B*Y),min(C*X*2,(C*Y*2)+(A*Z)))<<endl;
  }else if(Y>X){
    int Z=Y-X;
    cout<<min((A*X)+(B*Y),min(C*Y*2,(C*X*2)+(B*Z)))<<endl;
  }else{
    cout<<min((A*X)+(B*Y),C*Y*2)<<endl;
  }
  return 0;
}



Measured memory_bytes: 256
N=int(input())
h=list(map(int,input().split()))

dp=[0]*N
dp[1]=abs(h[1]-h[0])

for i in range(2,N):
    dp[i]=min(abs(h[i]-h[i-1])+dp[i-1],abs(h[i]-h[i-2])+dp[i-2])

print(dp[N-1])

Measured memory_bytes: 52208
//#include <bits/stdc++.h>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define fast_io()                \
    ios::sync_with_stdio(false); \
    std::cin.tie(0);
#define mod 998244353
typedef long long ll;
typedef long double ld;
using namespace std;

int main()
{
    fast_io();
    int n;
    cin >> n;
    int tmp = max(1, (int)ceil(sqrt(n - 2)) + 1);
    map<int, int> f;
    int  x = 0, y = 0, z = 0;
    for (x = 1; x <= tmp; x++)
    {
        for (y = 1; y <= tmp; y++)
        {
            for (z = 1; z <= tmp; z++)
            {
                int ans = x * x + y * y + z * z + x * y + y * z + z * x;
                f[ans]++;
            }
        }
    }
    for (int i = 1; i <= n; i++)
        cout << f[i] << "\n";

    return 0;
}

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

using namespace std;

int main(){
  
  int N;
  cin >> N;
  double sum = 0, tmp = 0, reverse_sum = 0;
  //int *a = new int[N];
  
  for(int i = 0; i < N; i++){
    cin >> tmp;
    sum += 1 / tmp;
  }
  
  reverse_sum = 1 / sum;
  cout << reverse_sum;
  
  return 0;
}


Measured memory_bytes: 256
import java.util.*;
class Main{
  public static void main(String args[]){
    int tmp;
    int count = 0;
    int minj;
    Scanner sc = new Scanner(System.in);

    int n = sc.nextInt();
    int [] Array = new int[n];
    
    for(int i = 0; i<n; i++){
      Array[i] = sc.nextInt();
    }

    for(int i = 0; i<n; i++){
      minj = i;
      for(int j = i; j<n;j++){
        if(Array[j]<Array[minj]){
          minj = j;
        }
      }
      if(i != minj){
        tmp = Array[i];
        Array[i] = Array[minj];
        Array[minj] = tmp;
        count++;
      }
    }
    for(int i = 0; i<n-1; i++){
      System.out.printf("%d ",Array[i]);
    }
    System.out.println(Array[n-1]);
    System.out.println(count);
  }
}


Measured memory_bytes: 26548
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (long long i = 0; i < (long long)(n); i++)
#define FOR(i, m, n) for (long long i = m; i < n; i++)
#define SORT(x) sort(x.begin(), x.end())
#define RS(x) rsort(x.begin(),x,end()))
#define REVE(x) reverse(x.begin(), x.end())
#define ALL(x) (x).begin(), (x).end()
#define pb push_back
#define pob pop_back
int INF = 1e9 + 1;
int MOD = 1e9+7;
int main(){
   long long n,k,c=0;
   cin >> n >> k;
  if(k>=n)k=n;
   vector<long long> h(n);
 REP(i,n){
   cin >>h[i];
 }
  SORT(h);
  REP(i,k){
   h[n-i-1]=0;
  }
   REP(i,n){
     c+=h[i];
         }
  cout << c;
}

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

typedef long long ll;


#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
#define LINF 1e18

struct Edge{
    int from,to,cost;
};

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

    int p = 20;
    while(L<(1<<p)){
        p--;
    }

    int N = p+1;

    vector<Edge> ans;
    FOR(i,1,p+1){
        ans.push_back({i, i+1,0});
        ans.push_back({i, i+1, (1<<(i-1))});
    }

    L -= 1<<(N-1);

    while(p>0){
        if(L >= (1<<(p-1))){
            L -= (1<<(p-1));
            ans.push_back({p, N, L+(1<<(N-1)) });
        }
        p--;

    }

    cout << N << " " << ans.size() << endl;



    for(auto x: ans){
        cout << x.from << " " << x.to << " " << x.cost << endl;
    }
    return 0;
}

Measured memory_bytes: 3528
n = int(input())
t, a = [int(i) for i in input().split(' ')]
h = [int(i) for i in input().split(' ')]

temp = []
for i in h:
    temp.append(t - i * 0.006)

near = 10001
ans = 0
for i, v in enumerate(temp):
    sub = a - v
    if abs(near) > abs(sub):
        near = sub
        ans = i+1

print(ans)


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

int main(){
    int h, w;
    cin >> h >> w;
    string s[h][w];
    string sub;
    string ans[h][w];
    for (int i = 0; i < h; i++)
    {
        cin >> sub;
        for (int j = 0; j < w; j++)
        {
            s[i][j] = sub[j];
        }
    }

    const int dx[4]={0,-1,1,0};
    const int dy[4]={-1,0,0,1};
    int count=0;
    int koritu=0;

    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if(s[i][j]=="#"){
                for(int k=0;k<4;k++){
                    if(i+dy[k]<0||i+dy[k]>=h||j+dx[k]<0||j+dx[k]>=w) continue;
                    if(s[i+dy[k]][j+dx[k]]=="#"){
                        count++;
                    }
                }
                if(count==0){
                        koritu++;
                    }
                    count=0;
            }
        }
    }
    if(koritu==0){
        cout << "Yes"<<endl;;
    }else{
        cout << "No"<<endl;;
    }
}

Measured memory_bytes: 384
open System
open System.Collections.Generic
open System.Linq
open System

// Following contents are my library. The Main processes are on the bottom of this code.

let puts = Console.WriteLine : 'a -> unit
let put = Console.Write : 'a -> unit
let read() = Console.ReadLine()
let reads () = Console.ReadLine().Split()
let read2 () = reads() |> (fun x -> x.[0], x.[1])
let read3 () = reads() |> (fun x -> x.[0], x.[1], x.[2])
let read4 () = reads() |> (fun x -> x.[0], x.[1], x.[2], x.[3])
let tmap2 f1 f2 (t1, t2) = (f1 t1, f2 t2)
let tmap3 f1 f2 f3 (t1, t2, t3) = (f1 t1, f2 t2, f3 t3)
let tmap4 f1 f2 f3 f4 (t1, t2, t3, t4) = (f1 t1, f2 t2, f3 t3, f4 t4)
let readAs f = read() |> f
let readAs2 f1 f2 = read2 () |> tmap2 f1 f2
let readAs3 f1 f2  f3 = read3 () |> tmap3 f1 f2 f3
let readAs4 f1 f2 f3 f4 = read4 () |> tmap4 f1 f2 f3 f4
let readInt () = readAs int
let readInt2 () = readAs2 int int
let readInt3 () = readAs3 int int int
let readInt4 () = readAs4 int int int int
let ensmallen l = l % 1000000007L
let manhattan x y = abs (fst x - fst y) + abs (snd x - snd y)
let sayYESNO b = if b then puts "YES" else puts "NO"
let sayYesNo b = if b then puts "Yes" else puts "No"

let toIntArray (s:string) = s.ToCharArray() |> Array.map (fun c -> int c - int '0')


// The main contents of this submission are below this line.
let n = read()
let fn = toIntArray n |> Array.sum
int n % fn = 0 |> sayYesNo


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

int main() {
  int n;
  cin >> n;
  int r = n % 100;
  int l = n / 100;
  bool yymm = ((0 <= l && l <= 99) && (1 <= r && r <= 12));
  bool mmyy = ((0 <= r && r <= 99) && (1 <= l && l <= 12));
  string ans;
  if (yymm && !mmyy) ans = "YYMM";
  else if (!yymm && mmyy) ans = "MMYY";
  else if (yymm && mmyy) ans = "AMBIGUOUS";
  else ans = "NA";
  cout << ans << endl;
  return 0;
}


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

int main(){
    long double a,b;
    cin >> a >> b;
    cout << (ll)(a*b+0.001) << endl;
}

Measured memory_bytes: 3716
import java.util.*;

public class Main {
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		double r = sc.nextDouble();
		double S = r*r*Math.PI;
		double L = 2*r*Math.PI;
		System.out.printf("%.6f %.6f\n", S,L);
	}
}

Measured memory_bytes: 28112
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <queue>
#include <iomanip>


using namespace std;
 

int main() {

      int k;
      cin >> k;
      long sum;
      sum = 0;
      for(int a = 1; a <= k ; a++){
            for(int b = 1 ; b <= k ; b++){
                  for(int c = 1; c <= k ; c++){
                        sum += __gcd(a, __gcd(b,c)  );
                  }
            }
      }
      cout << sum;
      return 0;
}

Measured memory_bytes: 3636
//* AuThOr GaRyMr *//
#include<bits/stdc++.h>
#define rb(a,b,c) for(int a=b;a<=c;++a)
#define rl(a,b,c) for(int a=b;a>=c;--a)
#define niv vector<int>
#define LL long long
#define IT iterator
#define PB push_back
#define II(a,b) make_pair(a,b)
#define FIR first
#define SEC second
#define FREO freopen("check.out","w",stdout)
#define rep(a,b) for(int a=0;a<b;++a)
#define KEEP while(1)
#define SRAND mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define random(a) rng()%a
#define ALL(a) a.begin(),a.end()
#define ff fflush(stdout)
using namespace std;
const int INF=0x3f3f3f3f;
typedef pair<int,int> mp;
typedef pair<mp,mp> superpair;
int main(){
	string s;
	cin>>s;
	if(s.length()<26)
	{
		int cnt[27]={0};
		rep(i,s.length()) cnt[s[i]-'a'+1]++;
		rb(i,1,26){
			if(!cnt[i]){
				cout<<s<<char('a'-1+i);
				break;
			}
		} 
	 } 
	else{
		int cnt[27]={0};
		rl(j,s.length()-1,0){
			rb(i,1,26){
				if(cnt[i]&&i>s[j]-'a'+1){
					rb(i,0,j-1){
						cout<<s[i];	
					}
					cout<<char('a'+i-1);
					return 0;
				}
			}
			cnt[s[j]-'a'+1]++;
		}
		cout<<-1<<endl;
	} 
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<cstdio>
#include<cmath>
#include<utility>
#include<algorithm>
#include<bitset>
using namespace std;

int a,b,c;
int main(){
  cin>>a>>b;
  if(b/10>0){
    if(b/100>0){
      c=a*1000+b;
    }else c=a*100+b;
  }else c=a*10+b;
  for(int i=1;i<=1000;i++){
    if(i*i==c){cout<<"Yes"<<endl;return 0;}
    else if(i*i>c){cout<<"No"<<endl;return 0;}
  }
  return 0;
}



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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;
const ll mod = 1e9+7;


int main(){
	
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    // cout<<0<<endl;
    ll n;cin>>n;
    string s; cin>>s;
    ll r=0,b=0,g=0;
    ll sub=0;
    // cout<<0<<endl;
    REP(i,n){
        if(s[i]=='R') r++;
        if(s[i]=='G') g++;
        if(s[i]=='B') b++;
    }
    // cout<<r<<endl;
    for(ll i=1; 2*i+1<=n; i++){ //kankaku
        ll j=0;
        while(j+2*i < n){
            if(s[j] != s[j+i] && s[j+i]!=s[j+2*i] && s[j]!=s[j+2*i]){
                sub++;
            }
            j++;
            // cout<<j<<endl;
        }
    }

    cout<< r*g*b-sub<<endl;
    return 0;
}

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

#define boost ios::sync_with_stdio(); cin.tie(); cout.tie();
#define ll long long
#define ld long double
#define pii pair <int, int>
#define pll pair <ll, ll>
#define st first
#define nd second
#define pb push_back
#define mp make_pair
#define vt vector 
#define all(c) (c).begin(), (c).end()
#define sz(x) (int)(x).size()

template<class T> bool umin(T& a, const T& b) {
	return b<a?a=b, 1:0;
}
template<class T> bool umax(T& a, const T& b) { 
	return a<b?a=b, 1:0;
} 

const int INF = 1e9 + 10;
const int mod = 1e9 + 7;
const ll LLINF = 1e18 + 10;

void solve() 
{
	int ans, curr;
	for(int i =0;i < 5; i++){
		cin >> curr;
		if(curr ==0){
			ans = i+1;
		}
	}
	cout << ans;
	return;
}
int main()
{
    boost
    //int t; read(t); while(t--)
    solve();
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
long long fun(int W, long long wt[], long long val[], int n) 
{ 
    long long i, w; 
    long long K[n + 1][W + 1]; 
  
    // Build table K[][] in bottom up manner 
    for (i = 0; i <= n; i++) { 
        for (w = 0; w <= W; w++) { 
            if (i == 0 || w == 0) 
                K[i][w] = 0; 
            else if (wt[i - 1] <= w) 
                K[i][w] = max( 
                    val[i - 1] + K[i - 1][w - wt[i - 1]], 
                    K[i - 1][w]); 
            else
                K[i][w] = K[i - 1][w]; 
        } 
    } 
  
    return K[n][W]; 
}
int main()
{
  int n,w;
  cin>>n>>w;
  long long ww[n],vv[n];
  for (int i=0;i<n;i++)
    cin>>ww[i]>>vv[i];
  cout<<fun(w,ww,vv,n);
  return 0;
}

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

int main() {
    int N, K;
    string S;
    cin >> N >> S >> K;
    char ch = S[K-1];
    rep(i, S.size()) {
        if (S[i] != ch) cout << "*";
        else cout << S[i];
    }
    cout << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#define ll long long
#define rep(i,l,r) for(ll i=(l);i<(r);i++)
#define max(p,q) ((p)>(q)?(p):(q))
#define min(p,q) ((p)<(q)?(p):(q))
#define abs(p) ((p)>=(0)?(p):(-(p)))
int main(void){
    ll A, B, X;
    scanf("%lld %lld %lld", &A, &B, &X);
    if(A<=X && X<=(A+B)) printf("YES\n");
    else printf("NO\n");
    return 0;
}


Measured memory_bytes: 128
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<stdbool.h>
#include<math.h>
#include<limits.h>
#define MAX 15
int min(int a,int b){
    if(a<b) return a;
    else return b;
}

int main(){
    int N,M,X;
    int C[MAX];
    int A[MAX][MAX];
    int ans = 1000000000;
    scanf("%d %d %d",&N,&M,&X);
    for(int i=1;i<=N;i++){
        scanf("%d",C+i);
        for(int j=1;j<=M;j++)
            scanf("%d",&A[i][j]);
   }
   for(int bit=1;bit<(1<<N);bit++){
       int state[MAX] = {0};
       int money = 0;
       for(int i=1;i<=N;i++){
           if(bit & 1<<(i-1)){
               money += C[i];
               for(int j=1;j<=M;j++)
                    state[j] += A[i][j];
           }
       }
       bool f = true;
       for(int j=1;j<=M;j++){
            if(state[j] < X){
                f = false;
                break;
            }
       }
       if(f) ans = min(ans,money);
   }
   if(ans == 1000000000) printf("-1");
   else printf("%d",ans);
}


Measured memory_bytes: 1736
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

var (
	readString func() string
	stdout     *bufio.Writer
)

func init() {
	readString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = readInt()
	}
	return b
}

func readLengthAndSlice() (int, []int) {
	n := readInt()
	return n, readIntSlice(n)
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}

func eprintln(args ...interface{}) (int, error) {
	return fmt.Fprintln(os.Stderr, args...)
}

func eprintf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(os.Stderr, f, args...)
}

// readString() string
// readInt() int
// readIntSlice(n int) []int
// readLengthAndSlice() []int

// -----------------------------------------------------------------------------

func main() {
	defer stdout.Flush()
	k := readInt64()
	a := readInt64()
	b := readInt64()
	if b-a < 3 || k < a+1 {
		println(k + 1)
		return
	}

	x := k - (a - 1)
	ans := a + (b-a)*(x/2)
	if x%2 != 0 {
		ans++
	}
	println(ans)

	// 5 8
	//
	// 0 1
	// 1 2
	// 2 3
	// 3 4
	// 4 5
	// 5 0
	// 6 8
	// 7 3
	// 8 11
	// 8 6
	// 8 14
}

// -----------------------------------------------------------------------------


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

int main(){
	while(1){
		double x,h,s;
		cin>>x>>h;
		if(x==0&&h==0)break;
		s=x*x+2*x*pow((x*x/4+h*h),0.5);
		cout<<fixed<<setprecision(6)<<s<<endl;
	}
}

Measured memory_bytes: 1328
import java.util.*;
import java.lang.Math;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int[] x = {0,0,0,0,0,0};
        //         a,b,c,d,e
        for(int i = 0; i < x.length ; i++){
            x[i] = sc.nextInt();
        }
        int judge = 0;
        for(int i = 0;i < x.length-1;i++){
            for(int j = 1; j < x.length;j++){
                if(Math.abs(x[i] - x[j]) > x[5]){
                    judge = 1;
                }
            }
        }
        if(judge == 1){
            System.out.println(":(");
        }else{
            System.out.println("Yay!");
        }

    }
}

Measured memory_bytes: 21716
use std::collections::{HashMap, VecDeque};
use std::io::{Write, BufWriter};

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

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

fn main() {
    let n = read::<usize>();
    let mut map = HashMap::new();
    for _ in 0..n-1 {
        let input = read_vec::<usize>();
        let (u, v, w) = (input[0], input[1], input[2]);
        map.entry(u).or_insert_with(|| vec![]).push((v, w));
        map.entry(v).or_insert_with(|| vec![]).push((u, w));
    }
    let mut queue = VecDeque::new();
    queue.push_back(1);

    let mut used = vec![false; n];
    let mut colors = vec![0usize; n];

    dfs(1, 0, &map, &mut used, &mut colors);

    let stdout = std::io::stdout();
    let mut stdout = BufWriter::new(stdout.lock());
    for color in colors.into_iter() {
        writeln!(stdout, "{}", color).unwrap();
    }
}

fn dfs(key: usize, current_color: usize, map: &HashMap<usize, Vec<(usize, usize)>>, used: &mut Vec<bool>, colors: &mut Vec<usize>) {
    if used[key-1] {
        return;
    }
    used[key-1] = true;
    if let Some(val) = map.get(&key) {
        for x in val {
            let next_color = (current_color + x.1) % 2;
            colors[x.0-1] = next_color;
            dfs(x.0, next_color, map, used, colors);
        }
    }
}

Measured memory_bytes: 20676
import itertools
N, M, Q = map(int,input().split())
ABCD = [tuple(map(int, input().split())) for _ in range(Q)]
ans = 0
for s in itertools.combinations_with_replacement(range(1,M+1),N):
    temp = 0
    for i in range(Q):
        if s[ABCD[i][1]-1] - s[ABCD[i][0]-1] == ABCD[i][2]:
            temp += ABCD[i][3]
    ans = max(ans,temp)
print(ans)

Measured memory_bytes: 9212
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep2(i, m, n) for(int i=int(m); i<int(n); ++i)
#define drep2(i, m, n) for(int i=int(m-1); i>=int(n); --i)
#define rep(i, n) rep2(i, 0, n)
#define drep(i, n) drep2(i, n, 0)
#define all(a) a.begin(), a.end()
#define fst first
#define snd second
using ll = long long;
using ld = long double;
using V = vector<int>;
using Vll = vector<ll>;
using Vld = vector<ld>;
using Vbo = vector<bool>;
using VV = vector<V>;
using VVll = vector<Vll>;
using VVld = vector<Vld>;
using VVbo = vector<Vbo>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using Pld = pair<ld, ld>;
template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<typename T> istream &operator>>(istream &is, vector<T> &v) { for (auto &e : v) is >> e; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << " "; return os; }
template<typename T> inline int count_between(vector<T> &a, T l, T r) { return lower_bound(all(a), r) - lower_bound(all(a), l); } // [l, r)
inline int Log2(ll x) { int k; for (k = 0; x > 0; ++k) x >>= 1; return k; } // number of binary digits
const int INF  = 1<<30;
const ll INFll = 1ll<<62;
const ld EPS   = 1e-10;
const int MOD  = int(1e9)+7;


int main() {
  ll w, h; cin >> w >> h;
  vector<P> pq(w+h);
  rep(i, w) {
    int x; cin >> x;
    pq[i] = P(x, 0);
  }
  rep(i, h) {
    int x; cin >> x;
    pq[w+i] = P(x, 1);
  }
  sort(all(pq));

  ll ans = 0;
  Vll rest(2);
  rest[0] = w+1;
  rest[1] = h+1;
  int cnt = 0;
  for (auto &p : pq) {
    int x, i;
    tie(x, i) = p;
    cnt += rest[i^1];
    ans += rest[i^1] * x;
    --rest[i];
  }

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


Measured memory_bytes: 1920
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> VI;
typedef vector<VI> VVI;
typedef pair<ll, ll> P;
#define FOR(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define PRINT(V) for (auto v : (V)) cout << v << " "
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const ll INF = numeric_limits<ll>::max();
int main()
{
    string s; cin >> s;
    int c = 0;
    int ans = 0;
    rep(i, s.size()){
        if (s[i] == 'R') ++c;
        else c = 0;
        ans = max(ans, c);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3620
#include <iostream>
#include <algorithm>  
#include <vector>
using namespace std;


int main() 
{ 
	int r, g,b,n; 
	long long int contador=0;
	cin>>r;
	cin>>g;
	cin>>b;
	cin>>n;
	
	for (int i=0;i<=n;i++)
	{
		for (int j=0; j<=n;j++)
		{
			if ((n-i*g-j*b)>=0 && (n-i*g-j*b)%r==0)
			contador++;
		}
	}
	
	cout<<contador;
	
	
}



Measured memory_bytes: 256
#include <algorithm>
#include <functional>
#include <iostream>
#include <vector>
#define all(x) (x).begin(), (x).end()
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;

int main() {
  int N;
  cin >> N;
  vector<int> p;
  vector<int> p2;
  REP(i, N) {
    int P;
    cin >> P;
    p.push_back(P);
    p2.push_back(P);
  }

  sort(all(p2));

  int ans = 0;
  REP(i, N) {
    if (p[i] == p2[i]) {
      ans++;
      if (!p[i + 1]) continue;
      if (p[i + 1] == p2[i + 1]) i += 1;
    }
  }

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

Measured memory_bytes: 1276
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


def make_divisors(n):
    # 約数のリストを返す
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    return divisors


n = int(readline())
l = []
for i in range(n+1):
    if len(make_divisors(i)) == 8 and i % 2 == 1:
        l.append(i)
print(len(l))


Measured memory_bytes: 9508
#include <bits/stdc++.h>
  
using namespace std;
  
template<class T> void ckmin(T &a, T b) { a = min(a, b); }
template<class T> void ckmax(T &a, T b) { a = max(a, b); }
  
#define pb push_back
#define mp make_pair
#define cotu cout
#define itn int
#define Red ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define F first
#define S second
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int i = 0; i < n; ++i)
#define repr(i,n) for(int i = n - 1; i >= 0; --i)
#define Rep(i, a, n) for(int i = (a); i <=(n); ++i)
#define repst(i, n) for(auto it = n.begin(); it != n.end(); ++it)
#define Repr(i, a, n) for(int i = (n); i >= (a); --i)
  
#define ordered_set tree<int , null_type,less<int >, rb_tree_tag,tree_order_statistics_node_update> 
  
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
  
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
  
const int inf = int(1e9);
const int mod = inf + 7;
const int N = 1e6 + 555; // TL MB
const double PI = acos(-1.0);
 
void mul(ll &x, ll y){
	x *= y;
	if(x >= mod) x %= mod;
}
 
void add(ll &x, ll y){
	x += y;
	if(x >= mod) x -= mod;
	if(x < 0) x += mod;
}
ll bp(ll a, ll n){
	ll r = 1;
	while(n){
		if(n & 1) mul(r, a);
		mul(a, a);
		n >>= 1;
	}
	return r;
}

void solve()
{
	map<int, int> mp;
	int n;
	cin >> n;
	int a[n];
	rep(i, n){
		cin >> a[i];
		mp[a[i]]++;
	}
	for(auto it : mp){
		if(it.S != 1){
			cout << "NO";
			return;
		}
	}
	cout << "YES";
}


 
 
int main()
{
    Red;
  	// int T; cin >> T; while(T--)
    solve();
    return 0;
}

Measured memory_bytes: 10368
#include<bits/stdc++.h>
using namespace std;
const int maxn=2010;
char s[maxn][maxn];
int l[maxn][maxn],r[maxn][maxn],u[maxn][maxn],d[maxn][maxn];
int a[maxn][maxn],ll[maxn],rr[maxn],uu[maxn],dd[maxn],b[maxn][maxn];
int main()
{
	int h,w;
	scanf("%d%d",&h,&w);
	for(int i=1;i<=h;i++)
	{
		l[i][ll[i]++]=-w-1;
		r[i][rr[i]++]=0;
	}
	for(int i=1;i<=w;i++)
	{
		u[i][uu[i]++]=-h-1;
		d[i][dd[i]++]=0;
	}
	for(int i=1;i<=h;i++)
	{
		scanf("%s",s[i]+1);
		for(int j=1;j<=w;j++)
		{
			if(s[i][j]=='#')
			{
				l[i][ll[i]++]=-j;
				r[i][rr[i]++]=j;
			}
		}
	}
	for(int i=1;i<=w;i++)
	{
		for(int j=1;j<=h;j++)
		{
			if(s[j][i]=='#')
			{
				u[i][uu[i]++]=-j;
				d[i][dd[i]++]=j;
			}
		}
	}
	for(int i=1;i<=h;i++)
	{
		l[i][ll[i]++]=0;
		r[i][rr[i]++]=w+1;
	}
	for(int i=1;i<=w;i++)
	{
		u[i][uu[i]++]=0;
		d[i][dd[i]++]=h+1;
	}
	for(int i=1;i<=h;i++)sort(l[i],l[i]+ll[i]);
	for(int i=1;i<=w;i++)sort(u[i],u[i]+uu[i]);
	int ans=0;
	for(int i=1;i<=h;i++)
	{
		for(int j=1;j<=w;j++)
		{
			if(s[i][j]=='#')continue;
			a[i][j]+=*lower_bound(r[i],r[i]+rr[i],j)+*lower_bound(l[i],l[i]+ll[i],-j)-1; 
			
		}
	}
	for(int i=1;i<=w;i++)
	{
		for(int j=1;j<=h;j++)
		{
			if(s[j][i]=='#')continue;
			b[i][j]+=*lower_bound(d[i],d[i]+dd[i],j)+*lower_bound(u[i],u[i]+uu[i],-j)-1; 
		}
	}
	for(int i=1;i<=h;i++)
	{
		for(int j=1;j<=w;j++)
		{
			ans=max(a[i][j]+b[j][i],ans);
		}
	}
	cout<<ans-1;
	return 0;
}

Measured memory_bytes: 98944
using System;

public class Test
{
	public static void Main( )
	{
		double[] nums = Array.ConvertAll( Console.ReadLine().Split( ' ' ), double.Parse );
		var x1 = nums[0];
		var y1 = nums[1];
		var x2 = nums[2];
		var y2 = nums[3];
		var d = Math.Sqrt( Math.Pow( x1-x2, 2 )+Math.Pow( y1-y2, 2 ) );
		Console.WriteLine( d );
	}
}

Measured memory_bytes: 9436
#include <cmath>
#include <vector>
#include <iostream>
#include <algorithm>
#include <set>
#include <iomanip>
#include <queue>
#include <string>
#include <map>
#include <fstream>
#include <cassert>
#include <stack>
#include <climits>
#include <array>
#include <unordered_set>
#include <unordered_map>
#include <memory>
#include <functional>
#include <cfloat>
#include <numeric>
#include <atcoder/math>
std::vector<int> prime(const int upper) {
	std::vector<bool> is_prime(upper + 1, true);
	for (auto i = 2; i * i <= upper; ++i) {
		if (is_prime[i]) {
			for (auto j = i * i; j <= upper; j += i) {
				is_prime[j] = false;
			}
		}
	}
	std::vector<int> result;
	for (auto i = 2; i <= upper; ++i) {
		if (is_prime[i]) result.push_back(i);
	}
	return result;
}
std::vector<long long int> coprime_factors(long long int n) {
	const auto primes = prime(std::sqrt(n));
	std::vector<long long int> result;
	for (const auto prime : primes) {
		if ((long long int)prime * (long long int)prime > n) continue;
		if (n % prime == 0) {
			long long int p = 1;
			while (n % prime == 0) {
				p *= prime;
				n /= prime;
			}
			result.push_back(p);
		}
	}
	if (n > 1) result.push_back(n);
	return result;
}
int brute(const long long int n) {
	long long int sum{ 1 };
	auto i = 2;
	for (; sum % n != 0; ++i) {
		sum += i;
	}
	return i - 1;
}
long long int gcd(const long long int a, const long long int b) {
	return b == 0 ? a : gcd(b, a % b);
}
long long int solve(long long int n) {
	if (n == 1) {
		return 1;
	}
	const auto factor = coprime_factors(n);
	long long int min_k = n & 1 ? n - 1 : 2 * n - 1;
	for (auto i = 0; i < (1 << factor.size()); ++i) {
		long long int a{ 1 }, b{ 1 };
		for (auto j = 0; j < factor.size(); ++j) {
			if ((i >> j) & 1) {
				a *= factor[j];
			}
			else {
				b *= factor[j];
			}
		}
		const auto x = atcoder::inv_mod(a, b);
		const auto k = a * x - 1;
		if (k <= 0) continue;
		const auto rest = 2 * n / gcd(2 * n, k);
		const auto r = rest / gcd(rest, k + 1);
		if (r == 1) min_k = std::min(min_k, k);
	}
	return min_k;
}
int main() {
	long long int n; std::cin >> n;
	std::cout << solve(n) << '\n';
}


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

int main()
{
	double a, b, C, pi = acos(-1);
	cin >> a >> b >> C;
	
	double area = a * b * sin(C * pi / 180);
	
	cout << fixed << setprecision(8) << area / 2 << endl;
	cout << fixed << setprecision(8) << a + b + sqrt(a * a + b * b - 2 * a * b *cos(C * pi / 180)) << endl;
	cout << fixed << setprecision(8) << area / a << endl;
	

    return 0;
}



Measured memory_bytes: 3468
#include <stdio.h>
int main(){
    int N,K,Q;
    scanf("%d %d %d" ,&N, &K, &Q);
    int A[Q];
    int B[N];//正解数
    for(int i=0; i<N; i++){
        B[i]=0;
    }
    for(int i=0; i<Q; i++){
        scanf("%d" ,&A[i]);
    }
    for(int i=0; i<Q; i++){
        B[A[i]-1]++;
    }
    for(int j=0; j<N; j++){
        if(K-Q+B[j]>0){
            printf("Yes\n");
        }
        else{
            printf("No\n");
        }
    }
    return 0;
}

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

int main()
{
    long long  n, k;
    while(scanf("%lld %lld", &n, &k) !=EOF){
        long long res=1;
        while(n){
            n/=k;
            res++;
        }
        printf("%lld\n", res - 1);
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
using ll = long long;

int F(ll A, ll B){
    ll maxVal = std::max(A, B);
    int keta = 0;
    while(maxVal > 0){
        keta++;
        maxVal /= 10;
    }

    return keta;
}

int main(){
    ll N;
    std::cin >> N;

    // 常にA <= Bとして全探索
    int Fmin = 10;
    ll A;
    if(N % 2 == 0){
        A = 2;
    }else{
        A = 1;
    }

    int threshold = std::sqrt(N);
    for(; A <= threshold; A += 2){
        if(N % A == 0){
            ll B = N / A;
            Fmin = std::min(F(A, B), Fmin);
        }
    }

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

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

int main(){
	/*input*/
	int n; cin >> n;
	int* h = new int[n]; 
	for(int i = 0; i < n; i++){
		cin >> h[i];
	}
	/*calculation*/
	int o = 0;			//旅館の数
	int heighest = 0;	//iの時点で最も高い山 
	for(int i = 0; i < n; i++){
		if(h[i] >= heighest){
			heighest = h[i];
			o++;
		}
	}

	/*output*/
	cout << o << endl;
	delete[] h;
}


Measured memory_bytes: 256
using System;
using System.Linq;
using static System.Console;

class program{
	static void Main(){
		var input=ReadLine().Split(' ')
          .Select(s=>int.Parse(s)).ToList();
        
      
       input.Sort();
      var sorted=input;
      
       if(sorted[0]+sorted[1]==sorted[2]){
         WriteLine("Yes");
       }else{
         WriteLine("No");
       }
	}
}

Measured memory_bytes: 11348
from collections import deque

H, W = map(int, input().split())
seen = [[False]*W for _ in range(H)]
dx,dy = [1, 0, -1, 0], [0, 1, 0, -1]
c,S = 0,[]
for _ in range(H):
	S.append(input())

for i in range(H):
	for j in range(W):
		if (S[i][j]=='#') and (not seen[i][j]):
			d = deque()
			d.append((i, j))
			seen[i][j],b,w = True,1,0
			while d:
				px,py = d.popleft()
				for x,y in zip(dx,dy):
					nx, ny = px+x, py+y
					if nx < 0 or ny < 0 or nx >= H or ny >= W or seen[nx][ny]:
						continue
					if (S[px][py]=='#' and S[nx][ny] == '.') or (S[px][py]=='.' and S[nx][ny] == '#'):
						d.append((nx, ny))
						seen[nx][ny] = 1
						if S[px][py] == '#':
							w += 1
						else:
							b += 1
			c += b*w

print(c)

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

#ifdef LOCAL
#define debug(var) cerr << #var << " = " << var << endl;
#else
#define debug(var)
#endif

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

const int N = 1e5+23;

int t[N];
pair<int, int> p[N];

inline int dist(int i, int px, int py) {
	return abs(px-p[i].first)+abs(py-p[i].second);
}

void solve() {
	int n; scanf("%d", &n);
	for (int i = 0; i < n; ++i) {
		scanf("%d%d%d", &t[i], &p[i].first, &p[i].second);
	}
	int px = 0, py = 0, tt = 0;
	for (int i = 0; i < n; ++i) {
		int d = dist(i, px, py);
		if (t[i]-tt < d || (t[i]-tt)%2 != d%2) {
			debug(t[i]); debug(tt);
			debug(dist(i, px, py));
			printf("No");
			return;
		}
		tt = t[i];
		px = p[i].first;
		py = p[i].second;
	}
	puts("Yes");
}

int main() {
	init();
	int t = 1; //scanf("%d", &t);
	while (t--) {
		solve();
	}
	return 0;
}


Measured memory_bytes: 1408
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#define _USE_MATH_DEFINES
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const ll dx[4] = { 0,1,0,-1 };
const ll dy[4] = { -1, 0, 1,0 };
const int INF = 1e9 + 7;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}
void mul(ll a, ll b) {
	a = a * b % INF;
}
double mysqrt(double x) {
	double l = 0, r = x;
	for (int i = 0; i < 64; ++i) {
		double m = (l + r) / 2.0;
		if (m*m < x)l = m;
		else r = m;
	}
	return l;
}
///////////////////////////////////////


int main() {
	int N, K; cin >> N >> K;
	int a[1010];
	REP(i, N)cin >> a[i];
	vector<ll>sum;
	sum.push_back(0);
	REP(i, N) {
		sum.push_back(sum[i] + a[i]);
	}
	vector<ll>V;
	for (int i = 0; i < N; ++i) {
		for (int j = i+1; j <= N; ++j) {
			V.push_back(sum[j] - sum[i]);
		}
	}
	sort(V.begin(), V.end(),greater<ll>());
	int n = V.size();
	vector<int>ok(n, 1);
	ll ans = 0;
	for (int i = 60; i >= 0; --i) {
		ll msk = 1LL << i;
		int cnt = 0;
		REP(j, n)if ((V[j] & msk) && ok[j])cnt++;
		if (K <= cnt) {
			ans += msk;
			REP(j, n)if (!(V[j] & msk) && ok[j])ok[j] = 0;
		}
	}
	cout << ans << endl;
	return 0;
}


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

using namespace std;
typedef long long ll;
typedef long double ld;
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }

const int q = 1e9+9;
int a[1007],b[1007];


int main()
{
    int ma[3],ans=0;
    cin>>ma[0]>>ma[1]>>ma[2];
    sort(ma,ma+3);
    ans+=ma[2]-ma[1];
    ma[0]+=ans;

    if(ma[2]-ma[0]==1){
        ans+=2;
        ma[0]++;
    }
    while(ma[0]!=ma[2]){
        if(ma[2]-ma[0]>1){
            ans++;
            ma[0]+=2;
        }
        else if(ma[2]-ma[0]==1){
            ans+=2;
            break;
            }
            else break;
    }

    cout<<ans<<endl;


    return 0;
}
// gotcha;


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
//INSERT ABOVE HERE
Int n;
using P = pair<Int, Int>;
using V = vector<P>;
vector<V> G;
V add(V a,Int b){
  for(auto &p:a){
    p.first+=b;
    p.second+=b;
  }
  return a;
}

V dfs(Int v,Int x){
  if(G[v].empty()) return V(1,P(0,0));
  V a=add(dfs(G[v][0].first,x),G[v][0].second);
  V b=add(dfs(G[v][1].first,x),G[v][1].second);
  if(a.size()>b.size()) swap(a,b);

  Int s=b.size();
  V r;
  {
    Int j=s-1,k=0;
    for(auto p:a){
      while(j>0&&p.first+b[j].first>x) j--;
      if(p.first +b[j].first <=x) r.emplace_back(p.second,b[j].second);
      
      while(k+1<s&&p.first+b[k].second>x) k++;
      if(p.first +b[k].second<=x) r.emplace_back(p.second,b[k].first);
    }
  }
  
  {
    Int j=s-1,k=0;
    for(auto p:a){
      while(j>0&&p.second+b[j].first>x) j--;
      if(p.second+b[j].first <=x) r.emplace_back(p.first ,b[j].second);
      
      while(k+1<s&&p.second+b[k].second>x) k++;
      if(p.second+b[k].second<=x) r.emplace_back(p.first ,b[k].first);
    }
  }
  
  for(auto &p:r)
    if(p.first>p.second)
      swap(p.first,p.second);
  sort(r.begin(),r.end());
  
  V w;
  for(auto p:r){
    if(w.empty()){
      w.emplace_back(p);
      continue;
    }
    if(w.back().second<=p.second) continue;    
    w.emplace_back(p);
  }
  return w;
}

signed main(){
  cin>>n;
  G.resize(n);
  for(Int i=1;i<n;i++){
    Int a,v;
    cin>>a>>v;
    a--;
    G[a].emplace_back(i,v);
  }
  
  Int l=-1,r=1e9;
  while(l+1<r){
    Int m=(l+r)>>1;
    if(!dfs(0,m).empty()) r=m;
    else l=m;
  }
  cout<<r<<endl;
  return 0;
}


Measured memory_bytes: 21760
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define ALL(x) (x).begin(), (x).end()
#define REP(i ,n) for(int i = 0; i < (int)(n); i++)
#define pb push_back
typedef vector<int>vint;
typedef vector<ll>vll;
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int main(){
    string s;
    cin >> s;
    vint ans((int)s.size(),0);
    int cnt = 0;
    REP(i,s.size()){
        if('R' != s[i]){
            int even = cnt/2;
            ans[i] += even;
            ans[i-1] += cnt-even;
            cnt = 0;
        }else{
            cnt++;
        }
    }
    reverse(s.begin(),s.end());
    reverse(ans.begin(),ans.end());
    REP(i,s.size()){
        if('L' != s[i]){
            int even = cnt/2;
            ans[i] += even;
            ans[i-1] += cnt-even;
            cnt = 0;
        }else{
            cnt++;
        }
    }
    reverse(ans.begin(),ans.end());
    for(auto a : ans){
        cout << a << " ";
    }
    cout << endl;
}

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

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define rep(i, n) repd(i, 0, n)

using namespace std;

using ll = long long;
using ul = unsigned long long;
ll mod = 1000000007;

int main() {
source:
    ll n;
    cin >> n;
    ll a[3 * n];
    rep(i, 3 * n) { cin >> a[i]; }
    sort(a, a + 3 * n);
    ll ans = 0;
    ll index = 3 * n - 2;
    rep(i, n) {
        ans += a[index];
        index -= 2;
    }
    cout << ans << endl;
    return 0;
}



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

#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define abs(x) ((x)<(0)?-(x):(x))

using namespace std;
using ll = long long;

const int N = 22;
int a[N], b[N], c[N];
signed main(){
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);

	int n;
	cin >> n;
	for(int i = 1; i <= n; i++) cin >> a[i];
	for(int i = 1; i <= n; i++) cin >> b[i];
	for(int i = 1; i < n; i++) cin >> c[i];
	int ans = 0;
	for(int i = 1; i <= n; i++) {
		ans += b[a[i]];
		if(i == 1 ) continue;
		if(a[i] - 1 == a[i - 1]) ans += c[a[i - 1]];
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    long long n, a, b;
    cin >> n >> a >> b;
    if(a > b){
        cout << 0 <<endl;
        return 0;
    }
    if(n==1){
        if(a==b) cout << 1 << endl;
        else cout << 0 << endl;
    }
    if(n > 1){
        cout << (n-2)*(b-a) + 1 <<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <vector>
using namespace std;
#define MAX 1000001
#define pb( a ) push_back( a )
/*
vとkv(奇数用)を用意して
ガンガンまわす
*/
int t[MAX],kt[MAX];
int main(){
	
	memset(t,MAX,sizeof(t));
	memset(kt,MAX,sizeof(kt));
	t[0]=kt[0]=0;
	vector<int>v,kv;
	for(int i=1;1;i++){
		int tmp= i*(i+1)*(i+2)/6;
		if(tmp>MAX)break;
		v.pb(tmp);
		if(tmp%2)kv.pb(tmp);
	}
	
	for(int i=0;i<MAX;i++){
		for(int j=0;j<v.size();j++){
			int tmp=i+v[j];
			if(tmp>=MAX)break;
			t[tmp]=min(t[i]+1,t[tmp]);
		}
		for(int j=0;j<kv.size();j++){
			int tmp=i+kv[j];
			if(tmp>=MAX)break;
			kt[tmp]=min(kt[i]+1,kt[tmp]);
		}
	}
	
	for(int n;cin>>n,n;)cout<<t[n]<<" "<<kt[n]<<endl;;
	
}


Measured memory_bytes: 9036
#include <iostream>

using namespace std;
int l,r,i,n,m,s[100005];
char a[100005];
int main()
{
    cin>>n>>m;
    for(i=1;i<=n;i++)
        cin>>a[i];
    for(i=2;i<=n;i++)
    {
        if(a[i]=='C' && a[i-1]=='A')
            s[i]=s[i-1]+1;
        else
            s[i]=s[i-1];
    }
    for(i=1;i<=m;i++)
    {
        cin>>l>>r;
        cout<<s[r]-s[l]<<'\n';
    }
    return 0;
}


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


#define mod                1000000000000000007
#define pi                 3.1415926535897932384626433832795
#define ll                 long long
#define pb                 push_back
#define pii                pair < int , int >
#define vecsort(v)         sort(v.begin(),v.end())
#define lcm(x,y)           (x/__gcd(x,y))*y
#define forn(i,n)          for(i = 0 ; i < n ; i++)
#define deb(x)             cout << #x << " " << x << endl;
#define vecsum(v)          accumulate(v.begin(), v.end(), 0)
#define T(t)               cout << "Case " << t <<": ";
#define fast_cin           ios_base::sync_with_stdio(false);cin.tie(NULL)





int a[105];

int main() {

    ll ans = 0 ;
    ll mn = 1e9;
    int n , x;
    cin >> x >> n;

    set < int > s;
    for( int i = 0 ; i < n ; i++ ){
        cin >> a[i];
        s.insert(a[i]);
    }

    for( int i = -101 ; i <= 101 ; i++ ){
        if( abs( x - i ) < mn  && !s.count(i)){
            mn = abs( x - i );
            ans = i;
        }
    }

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

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

int main() {
    vector<char> S(4);
    cin >> S[0] >> S[1] >> S[2] >> S[3];
    sort(S.begin(), S.end());
    if (S[0] == S[1] && S[1] != S[2] && S[2] == S[3]) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<memory.h>
using namespace std;
int square[50][50]={0},base[50][50]={0},n,m,a,b,c,t,s[50];
void sqr(int t){//cout<<t<<endl;
	if(t==1){
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				square[i][j]=base[i][j];
			}
		}
		return;
	}
	sqr(t/2);	
	
	int tmp[50][50];
	memset(tmp,0,sizeof(int)*2500);
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			for(int k=0;k<n;k++){
				tmp[i][j]+=square[i][k]*square[k][j];
				tmp[i][j]%=m;
			}
		}
	}
	if(t%2){
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				square[i][j]=0;
				for(int k=0;k<n;k++){
					square[i][j]+=tmp[i][k]*base[k][j];
					square[i][j]%=m; 
				}
			}
		}
	}else{
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				square[i][j]=tmp[i][j];
			}
		}
	}
//	for(int i=0;i<n;i++){
//		for(int j=0;j<n;j++){
//			cout<<square[i][j]<<' ';
//		}cout<<endl;
//	}cout<<endl;
}
int main(){
	scanf("%d%d%d%d%d%d",&n,&m,&a,&b,&c,&t);
    while(n){
    	memset(square,0,sizeof(int)*2500);
    	base[0][0]=b;
    	base[0][1]=c;
    	base[n-1][n-2]=a;
    	base[n-1][n-1]=b;
    	for(int i=1;i<n-1;i++){
    		base[i][i-1]=a;
    		base[i][i]=b;
    		base[i][i+1]=c;
    	}
    	for(int i=0;i<n;i++){
    		scanf("%d",&s[i]);
    	}
    	if(t==0){
    		for(int i=0;i<n-1;i++){
    			printf("%d ",s[i]);
    		}
    		printf("%d\n",s[n-1]);
    		scanf("%d%d%d%d%d%d",&n,&m,&a,&b,&c,&t);
    		continue;
    	}
    	sqr(t);
//    	for(int i=0;i<n;i++){
  //  		for(int j=0;j<n;j++){
    //			cout<<square[i][j]<<' ';
    //		}cout<<endl;
    //	}cout<<endl;
    	for(int i=0;i<n-1;i++){
    		int ret=0;
    		for(int j=0;j<n;j++){
    			ret+=s[j]*square[i][j];
    			ret%=m;
    		}
    		printf("%d ",ret);
    	}
		int ret=0;
		for(int j=0;j<n;j++){
			ret+=s[j]*square[n-1][j];
			ret%=m;
		}
		printf("%d\n",ret);
    	scanf("%d%d%d%d%d%d",&n,&m,&a,&b,&c,&t);
    }
}   
/*
5 4 1 3 2 0
0 1 2 0 1

5 7 1 3 2 1
0 1 2 0 1

5 13 1 3 2 11
0 1 2 0 1

6 6 0 2 3 1000
0 1 2 0 1 4

20 1000 0 2 3 1000000000
0 1 2 0 1 0 1 2 0 1 0 1 2 0 1 0 1 2 0 1

30 2 1 0 1 1000000000
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0
*/

Measured memory_bytes: 3496