akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define INF 1e9
using namespace std;

#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a)  (a).begin(),(a).end()
#define endl "\n"

template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
typedef long long ll;

int N,M,Q;
vector<vector<int>> box;

void dfs(const vector<int> &v) {
    int sz = v.size();
    int l = v[sz-1];

    if (sz==N) {
        box.push_back(v);
        return;
    }
    FOR(i,l,M+1) {
        auto v2 = v;
        v2.push_back(i);
        dfs(v2);
    }
}

void solve() {
    cin >> N >> M >> Q;
    vector<int> v(1,1);
    dfs(v);
    vector<int> a(Q);
    vector<int> b(Q);
    vector<int> c(Q);
    vector<int> d(Q);
    REP(i,Q) cin >> a[i] >> b[i] >> c[i] >> d[i];

    ll mx = 0;
    for(const auto &itv: box) {
        ll now = 0;
        REP(i,Q) {
            if ((itv[b[i]-1] - itv[a[i]-1] )== c[i]) now+=d[i];
        }
        chmax(mx,now);
    }
    cout << mx << endl;
}

int main() {
    solve();
    return 0;
}


Measured memory_bytes: 6772
mod = 1000000007
eps = 10**-9


def main():
    import sys
    input = sys.stdin.readline

    S = input().rstrip('\n')
    a = S.find("C")
    b = S.rfind("F")
    if 0 <= a < b:
        print("Yes")
    else:
        print("No")


if __name__ == '__main__':
    main()


Measured memory_bytes: 62380
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	String str = sc.next();
    	StringBuffer sb = new StringBuffer(str);
		String dst = sb.reverse().toString();
		if(str.equals(dst)){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}
		
    }
}


Measured memory_bytes: 21716
import numpy as np
from scipy.sparse.csgraph import dijkstra
from collections import Counter

H, W = map(int, input().split())
C = np.array([tuple(map(int, input().split())) for _ in range(10)])
A = Counter()
for _ in range(H):
    A.update(map(int, input().split()))
try:
    del A[-1]
except:
    pass

way = dijkstra(C.T, indices=1).astype(int)
print(sum(way[k] * v for k, v in A.items()))


Measured memory_bytes: 16948
#include <iostream>
using namespace std;
int d;
int f(int x){
    return x*x;
}
int solve(){
    int r=0;
    for(int i=0; i*d<600; i++){
        r += f(i*d)*d;
    }
    return r;
}
signed main(){
    while(cin >> d){
        cout << solve() << endl;
    }
}


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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
  
    int k;
    cin >> k;
    int sum = 0;
    for (int i = 1; i <= k; i++) {
        for (int j = 1; j <= k; j++) {
            int gcd1 = __gcd(i, j);
            for (int y = 1; y <= k; y++) {
                sum += __gcd(gcd1, y);
            }
        }
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 3640
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;
 
 
public class Main {
    int H,W,h,w;
    private void solve() {
        H = nextInt();
        W = nextInt();
        h = nextInt();
        w = nextInt();
 
        out.println((H - h) * (W - w));
    }
 
    public static void main(String[] args) {
        out.flush();
        new Main().solve();
        out.close();
    }
 
    /* Input */
    private static final InputStream in = System.in;
    private static final PrintWriter out = new PrintWriter(System.out);
    private final byte[] buffer = new byte[4096];
    private int p = 0;
    private int buflen = 0;
 
    private boolean hasNextByte() {
        if (p < buflen)
            return true;
        p = 0;
        try {
            buflen = in.read(buffer);
        } catch (IOException e) {
            e.printStackTrace();
        }
        if (buflen <= 0)
            return false;
        return true;
    }
 
    public boolean hasNext() {
        while (hasNextByte() && !isPrint(buffer[p])) {
            p++;
        }
        return hasNextByte();
    }
 
    private boolean isPrint(int ch) {
        if (ch >= '!' && ch <= '~')
            return true;
        return false;
    }
 
    private int nextByte() {
        if (!hasNextByte())
            return -1;
        return buffer[p++];
    }
 
    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = -1;
        while (isPrint((b = nextByte()))) {
            sb.appendCodePoint(b);
        }
        return sb.toString();
    }
 
    public int nextInt() {
        return Integer.parseInt(next());
    }
 
    public long nextLong() {
        return Long.parseLong(next());
    }
 
    public double nextDouble() {
        return Double.parseDouble(next());
    }
}

Measured memory_bytes: 20948
#include <stdio.h>
#define MAX(x,y) ((x) < (y) ? (y) : (x))
#define MIN(x,y) ((x) > (y) ? (y) : (x))
char S[2010][2010];
int R[2010][2010];
int C[2010][2010];

int main() {
    int H, W, ans = 1, s;
    scanf("%d %d", &H, &W);
    for (int i = 0; i < H; i++)
        scanf("%s", S[i]);
    for (int i = 0; i < H; i++) {
        s = 0;
        for (int j = 0; j < W; j++) {
            if (S[i][j] == '#') {
                for (int k = s; k < j; k++)
                    R[i][k] = j - s;
                s = j + 1;
            }
        }
        for (int k = s; k < W; k++)
            R[i][k] = W - s;
    }
    for (int j = 0; j < W; j++) {
        s = 0;
        for (int i = 0; i < H; i++) {
            if (S[i][j] == '#') {
                for (int k = s; k < i; k++)
                    C[k][j] = i - s;
                s = i + 1;
            }
        }
        for (int k = s; k < H; k++)
            C[k][j] = H - s;
    }
    for (int i = 0; i < H; i++)
        for (int j = 0; j < W; j++)
            ans = MAX(ans, R[i][j] + C[i][j] - 1);
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 35712
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;

ll L,N;
vector<ll> X;

int main(){
  cin>>L>>N;
  X.resize(N);
  rep(i,N) cin>>X[i];

  ll ans=0;
  for(int q=0;q<2;q++){
      vector<ll> sum(N+1,0),rsum(N+1,0);
      for(int i=0;i<N;i++){
          sum[i+1]=sum[i]+X[i];
      }
      for(int i=N-1;i>=0;i--){
          rsum[i]=rsum[i+1]+(L-X[i]);
      }

      ans=max(ans,X[N-1]);
      for(int k=0;k<N-1;k++){
          int rest=N-k-1;
          int last=k+rest/2;

          ll res=2*X[k]+2*(sum[last+1]-sum[k+1])+2*rsum[last+1];
          if(rest%2) res-=(L-X[last+1]);
          else res-=X[last];
          ans=max(ans,res);
      }

      for(int i=0;i<N;i++) X[i]=L-X[i];
      reverse(X.begin(),X.end());
  }

  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned int uint;
typedef unsigned char uchar;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;

#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();i++)
#define ALL(container) (container).begin(), (container).end()
#define RALL(container) (container).rbegin(), (container).rend()
#define SZ(container) ((int)container.size())
#define mp(a,b) make_pair(a, b)
#define pb push_back
#define eb emplace_back
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define __builtin_popcount __builtin_popcountll

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; }
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
    os<<"["; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"]"; return os;
}
template<class T> ostream& operator<<(ostream &os, const set<T> &t) {
    os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const map<S, T> &t) {
    os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
template<class S, class T> pair<S,T> operator+(const pair<S,T> &s, const pair<S,T> &t){ return pair<S,T>(s.first+t.first, s.second+t.second);}
template<class S, class T> pair<S,T> operator-(const pair<S,T> &s, const pair<S,T> &t){ return pair<S,T>(s.first-t.first, s.second-t.second);}

const int INF = 1<<28;
const double EPS = 1e-8;
const int MOD = 1000000007;


int T, n, m;

int main(int argc, char *argv[]){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    while(cin >> n >> m){
        vi d(n);
        REP(i, n) cin >> d[i];
        sort(RALL(d));
        vector<ll> dp(m + 1);
        dp[m] = 1;
        REP(j, n) {
            vector<ll> nxt(m + 1);
            int x = d[j];
            REP(i, m + 1) {
                ll t = dp[i];
                (nxt[i] = (nxt[i] + dp[i] * (n - 1 - j))) %= MOD;
                (nxt[i % x] += dp[i]) %= MOD;
            }
            swap(dp, nxt);
        }
        ll ans = 0;
        REP(i, m + 1) {
            ans = (ans + dp[i] * i) % MOD;
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 1888
#include <bits/stdc++.h>
using namespace std;
const int N = 1005;
int n;
long long dp[100005];

struct Block {
	int w = 0;
	int s = 0;
	long long v = 0;
	
	void read() {
		cin >> w >> s >> v;
	}

	bool operator <(const Block &b) const {
		return w + s < b.w + b.s;
	}
};

Block blocks[N];

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

	cin >> n;

	for (int i = 0; i < n; i++) {
		blocks[i].read();
	}

	sort(blocks, blocks + n);

	for (int i = 0; i < n; i++) {
		Block b = blocks[i];
		for (int w = b.s; w >= 0; w--) {
			dp[w + b.w] = max(dp[w + b.w], dp[w] + b.v);
		}
	}

	cout << *max_element(dp, dp + 100000) << '\n';

	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
unordered_set<string> s;
int main(int argc, char const *argv[])
{
	int n;
	cin >> n;
	int count = 0;
	while (n--) {
		string str;
		cin >> str;

		if (s.find(str) == s.end()) {
			s.insert(str);
			count++;
		}

	}
	cout << count << endl;
	return 0;
}

Measured memory_bytes: 17732
#include <iostream>
#include <cassert>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
int main(int argc, char const *argv[])
{
    int n, m, input;
    long long answer = 0;
    cin >> n >> m;
    map<long long, int> a;
    for (int i = 0; i < n; i++)
    {
        cin >> input;
        a[input] += 1;
    }
    for (int i = 0; i < m; i++)
    {
        auto amax = a.end();
        amax--;
        a[(*amax).first / 2] += 1;
        (*amax).second -= 1;
        if ((*amax).second == 0)
        {
            a.erase(amax);
        }
    }
    for (auto box : a)
    {
        answer += (box.first * box.second);
    }
    cout << answer;
    return 0;
}

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

namespace ConsoleApp17
{
    class Program
    {
        static void Main(string[] args)
        {
            var s = Console.ReadLine();

            var ans = 0;
            for (int i = 0; i < s.Length / 2; i++)
            {
                if (s[i] != s[s.Length - i - 1]) ans++;
            }

            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

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

  ll N; cin >> N;
  vector<ll> A(N); for (ll i = 0; i < N; i++) cin >> A[i];

  ll ans = 0;
  for (ll i = 0; i < N; i++) {
    if (i % 2 == 0 && A[i] % 2 == 1) ans++;
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 3652
function Main(input){
  inputs=input.split("\n");
  numbers=inputs.filter((x,i)=>i!==0&&x!="").map(x=>parseInt(x));

  count=parseInt(inputs[0]);
  countArray=[...Array(count)];

  // max1=numbers.reduce((a,b,i)=>(b>a&&i<count)?b:a);
  // max2=numbers.reduce((a,b,i)=>(b>a&&i<count&&(b<max1||b==a))?b:a);

  max1=0;
  max2=0;
  countArray.map((_,i)=>{
    max2=(numbers[i]>max2?numbers[i]:max2);
    if(max2>max1){
      tmp=max1;
      max1=max2;
      max2=tmp;
      // [max2,max1]=[max1,max2];
    }
  });

  countArray.map((_,i)=>{
    console.log(numbers[i]!=max1?max1:max2);
  });


  // countArray.map((_,index)=>{
  //   max=numbers.filter((_,i)=>i!=index).reduce((a,b)=>a>b?a:b);
  //   console.log(max);
  // });
}
Main(require('fs').readFileSync('/dev/stdin','utf8'));


Measured memory_bytes: 48644
#include<stdio.h>
#include<math.h>
int main(void){
    int N;
    float T,A;
    //int H[1001];
    int H;
    int i,num;
    float diff,diffabs,mindiff;
    float temp;
    scanf("%d",&N);
    scanf("%f %f",&T,&A);
    mindiff = 100000.0;
    num = 0;
    /*for(i=0;i<1001;i++){
        H[i]=0;
    }*/ 
    for(i=1;i<=N;i++){
        scanf("%d",&H);
        temp = T - 0.006 * H;
        diff = A - temp;
        diffabs = fabsf(diff);
        if(diffabs<mindiff){
            num = i;
            mindiff = diffabs; 
        }
        temp=0;
    }
    //printf("%f\n",mindiff);
    printf("%d\n",num);
}

Measured memory_bytes: 128
#include <stdio.h>

#define DICE 6
#define CMD 128

typedef struct {
  int side[DICE];
} dice_t;

dice_t rotate(dice_t d, int dir);
/* dice_t rotateS(dice_t d); */
/* dice_t rotateW(dice_t d); */
/* dice_t rotateE(dice_t d); */
/* dice_t rotateR(dice_t d); */
/* dice_t rotateL(dice_t d); */

enum direction {N, S, W, E, R, L};

int main(void){
  int i, j, isEqual;
  dice_t d1, d2, d2copy;

  for (i = 0; i < DICE; i++)
    scanf("%d", &d1.side[i]);
  for (i = 0; i < DICE; i++)
    scanf("%d", &d2.side[i]);
  d2copy = d2;

  // search for top side and fix
  for (j = 0; j < DICE; j++) {
    isEqual = 1;
    d2 = d2copy;
    if (d1.side[0] == d2.side[j]) {
      switch (j) {
      case 0:
	break;
      case 1:
	d2 = rotate(d2, N);
	break;
      case 2:
	d2 = rotate(d2, W);
	break;
      case 3:
	d2 = rotate(d2, E);
	break;
      case 4:
	d2 = rotate(d2, S);
	break;
      default: // case 5:
	d2 = rotate(d2, N);
	d2 = rotate(d2, N);
	break;
      }
    }

    // search for front side
    for (i = 0; i < 3; i++) {
      if (d1.side[1] == d2.side[1])
	break;
      d2 = rotate(d2, R);
    }

    // compare dice1 with dice2
    for (i = 0; i < DICE; i++) {
      if (d1.side[i] != d2.side[i]) {
	isEqual = 0;
	break;
      }
    }
    if (isEqual)
      break;
  }

  if (isEqual)
    printf("Yes\n");
  else
    printf("No\n");
  return 0;
}

dice_t rotate(dice_t d, int dir){
  int tmp;
  switch (dir) {
  case N:
    tmp = d.side[0];
    d.side[0] = d.side[1];
    d.side[1] = d.side[5];
    d.side[5] = d.side[4];
    d.side[4] = tmp;
    return d;
    break;
  case S:
    tmp = d.side[0];
    d.side[0] = d.side[4];
    d.side[4] = d.side[5];
    d.side[5] = d.side[1];
    d.side[1] = tmp;
    return d;
    break;
  case W:
    tmp = d.side[0];
    d.side[0] = d.side[2];
    d.side[2] = d.side[5];
    d.side[5] = d.side[3];
    d.side[3] = tmp;
    return d;
    break;
  case E:
    tmp = d.side[0];
    d.side[0] = d.side[3];
    d.side[3] = d.side[5];
    d.side[5] = d.side[2];
    d.side[2] = tmp;
    return d;
    break;
  case R:
    tmp = d.side[1];
    d.side[1] = d.side[2];
    d.side[2] = d.side[4];
    d.side[4] = d.side[3];
    d.side[3] = tmp;
    return d;
    break;
  case L:
    tmp = d.side[1];
    d.side[1] = d.side[3];
    d.side[3] = d.side[4];
    d.side[4] = d.side[2];
    d.side[2] = tmp;
    return d;
    break;
  dafault:
    printf("This direction is not available\n");
    break;
  }
}

Measured memory_bytes: 580
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define INF 1e9
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(void){
    int n;
    cin>>n;
    int d[n];
    for(int i=0;i<n;i++) cin>>d[i];
    sort(d,d+n);
    if(d[n/2]==d[n/2-1]){
        cout<<0<<endl;
        return 0;
    }
    cout<<d[n/2]-d[n/2-1]<<endl;
}

Measured memory_bytes: 640
import Data.List (foldl')

main = do
    [n,a,b] <- getInts
    xs <- getInts
    print $ solve a b xs

getInts :: IO [Int]
getInts = map read . words <$> getLine

solve :: Int -> Int -> [Int] -> Int
solve a b xs = foldl' (\s (l,r)-> s + min (a*(r-l)) b) 0 $ zip xs (tail xs)


Measured memory_bytes: 36220
#include <stdio.h>
int main(){
int n;
scanf("%d",&n);
switch(n){
case 1: printf("1"); break;
case 2: printf("3"); break;
case 3: printf("4"); break;
case 4: printf("7"); break;
case 5: printf("11"); break;
case 6: printf("18"); break;
case 7: printf("29"); break;
case 8: printf("47"); break;
case 9: printf("76"); break;
    
case 15: printf("1364"); break;
case 16: printf("2207"); break;
case 17: printf("3571"); break;
    
case 20: printf("15127"); break;
case 21: printf("24476"); break;
    
case 35: printf("20633239"); break;
case 42: printf("599074578"); break;
case 51: printf("45537549124"); break;
case 62: printf("9062201101803"); break;
case 79: printf("32361122672259149"); break;
case 85: printf("580696784543856761"); break;
case 86: printf("939587134549734843"); break;
default: break;
}
return 0;
}


Measured memory_bytes: 128
import java.util.Scanner;

public class Main {

     static Scanner scanner;

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

         int N=gi();
         long[] A=new long[N];

         long ans=0;
         for (int i=0; i<N;i++) {
        	 A[i]=gi();
         }
         long max=A[0];
         for (int i=1; i<N;i++) {
        	 if (max>A[i]) {
        		 ans+=max-A[i];

        	 }
        	 max=Math.max(A[i], max);
         }


        	 System.out.println(ans);




     }

     public static long f(int n, int s, int e) {
    	 if(s<=e) {
    		 return e-s;
    	 } else {
    		 return n-s+e;
    	 }
     }

     // 文字列として入力を取得
     public static String gs() {
          return scanner.next();
     }

     // intとして入力を取得
     public static int gi() {
          return Integer.parseInt(scanner.next());
     }

     // longとして入力を取得
     public static long gl() {
          return Long.parseLong(scanner.next());
     }

     // doubleとして入力を取得
     public static double gd() {
          return Double.parseDouble(scanner.next());
     }
}

Measured memory_bytes: 61156
#include "bits/stdc++.h"
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);  
typedef long long ll;
const ll mod =1e9 + 7;
const ll inf =1e16 + 7;
const int nax = 2e6 + 7;
ll vis[nax];
int main(){
	fast;
	int n ;
	ll k;
	cin >> n >> k;
	int a[n + 1];
	for(int i = 1; i <= n ; i++)
		cin >> a[i];
	//ll cycle = 0;
	ll i = 1;
	ll cnt = 0;
	while(vis[i] == 0 && cnt != k){
		vis[i] = cnt + 1;
		i = a[i];
		//cout << i << " " << cnt << endl;
		cnt++;
	}
	if(cnt == k)
		cout << i << endl;
	else{
		k -= (cnt);
		//cout << cnt << " " << vis[i] << endl;
		k %= (cnt - vis[i] + 1);
		//cout << k << "----0000" << endl;
	int ans = i;
	for(int i = 1 ; i <= k ; i++){
			ans = a[ans];
	}
	cout << ans << endl;
}
	return 0;
}


Measured memory_bytes: 5976
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <map>
#include <deque>
using namespace std;

#define REP(i,n) for(int i = 0; i < n; i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;
typedef pair<string,string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pi> vpi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

double EPS = 1e-9;
int INFi = 1000000005;
long long INFll = 1000000000000000005ll;
double PI = acos(-1);
int dirx[8] = {-1,0,0,1,-1,-1,1,1};
int diry[8] = {0,1,-1,0,-1,1,-1,1};
ll MOD = 1000000007;


int main(){
  ll x, y;
  cin >> x >> y;

  if(abs(x-y)<=1)cout << "Brown" << endl;
  else cout << "Alice" << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define N 41
typedef long long ll;
const int inf=0x3f3f3f3f;
ll adj[N];
int a[N],que[N];
vector<int> g[N];
int n,m,ans,cnt=0,kk=0;
unordered_set<ll> se;
bool bfs(int beg,ll s)
{
    int l=0,r=0,x,y;
    que[0]=beg;
    while(l<=r)
    {
        x=que[l++];
        if(x==n-1) return true;
        for(int y:g[x])
        {
            if((s>>y)&1) continue;
            s|=1LL<<y;que[++r]=y;
        }
    }
    return false;
}
int calc(int x,ll s1,ll s2)
{
    // if(!bfs(x,s1)) return inf;
    s2|=adj[n-1];
    int tot=0;
    for(int i=0;i<n;++i)
        if((s2>>i)&1) tot+=a[i];
    return tot;
}
void dfs(int x,ll s1,ll s2)
{
    if(cnt>=10000000) return;
    ++cnt;
    if(x==n-1)
    {
        // printf("%d %d ?\n",x,calc(x,s1,s2));
        ans=min(ans,calc(x,s1,s2));
        return;
    }
    ll h=s1*100+x;
    if(se.count(h)) return;
    se.insert(h);
    // printf("%d %d %d !!\n",x,calc(x,s1,s2),ans);
    if(calc(x,s1,s2)>=ans) return;
    
    for(int y:g[x])
    {
        if((s1>>y)&1) continue;
        dfs(y,s1|(1LL<<y),s2|adj[y]);
    }
}
int main()
{
    scanf("%d%d",&n,&m);
    for(int i=0;i<n;++i) 
    {
        scanf("%d",&a[i]);
        adj[i]=1LL<<i;
    }
    int x,y;
    for(int i=1;i<=m;++i)
    {
        scanf("%d%d",&x,&y);
        --x;--y;
        g[x].push_back(y);g[y].push_back(x);
        adj[x]|=1LL<<y;adj[y]|=1LL<<x;
    }
    for(int i=0;i<n;++i) 
        shuffle(g[i].begin(),g[i].end(),default_random_engine(0));
    ans=inf;
    dfs(0,1,adj[0]);
    printf("%d\n",ans);
    return 0;
}



Measured memory_bytes: 242172
#include <iostream>
#include <algorithm>
#include <utility>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <math.h>
#include <string.h>
#include <iomanip>
#include <numeric>
#include <cstdlib>
#include <cstdint>
#include <cmath>
#include <functional>
#include <limits>
#include <cassert>

using namespace std;

using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vll = vector<vl>;
using vpll = vector<pll>;

void debug_out() { std::cout << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cout << "debug: "; debug_out(__VA_ARGS__)
#else
#define debug(...) 
#endif

#define rep(i, a, n) for (int i = (int)(a); i < (int)(n); i++)
#define rrep(i, a, n) for (int i = ((int)(n)-1); i >= (int)(a); i--)
#define Rep(i, a, n) for (long long i = (long long)(a); i< (long long)(n); i++)
#define RRep(i, a, n) for (long long i = ((long long)(n)-1); i>=(long long)(a); i--)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()

struct Edge{
    int to;
    int weight;
    Edge(int t, int w) : to(t), weight(w){ }
};

struct edge{
    int from;
    int to;
    int weight;
    edge(int f,int t,int w) : from(f), to(t), weight(w){ }
};


using Graph = vector<vector<Edge>>;
using graph = vector<vector<int>>;
using edges = vector<edge>;

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

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

template <class T>
T lcm(T a, T b){
    return (a*b)/gcd(a,b);
}

bool isPalindrome(string s){
    string t = s;
    reverse(all(t));
    return s==t;
}

constexpr ll INF = 1e9+7;

vector<int> dx = {-1,0,1,0};
vector<int> dy = {0,-1,0,1};

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll n,k; cin >> n >> k;
    vector<ll> a(n);
    vector<ll> f(n);
    rep(i,0,n) cin >> a[i];
    rep(i,0,n) cin >> f[i];
    sort(all(a));
    sort(rall(f));
    ll left = -1;
    ll right = (ll)1e13;
    while(right-left>1){
        ll mid = left + (right-left)/2;
        ll cnt = 0;
        rep(i,0,n){
            if(a[i]*f[i]>mid){
                cnt += a[i] - mid/f[i];
            }
        }
        if(cnt<=k){
            right = mid;
        }
        else{
            left = mid;
        }
    }
    cout << right << endl;
}

Measured memory_bytes: 3456
N = int(input())
A = []
for i in range(N):
  A.append(int(input()))
A_max = max(A)
i = A.index(A_max)
del A[i]
B_max = max(A)
for j in range(N):
  if j == i:
    print(B_max)
  else:
    print(A_max)

Measured memory_bytes: 12520
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigInteger;

class Main {
	public static void main(String[] args) {
		InputStreamReader isr = new InputStreamReader(System.in);
		BufferedReader br = new BufferedReader(isr);
		try {
			String n = br.readLine();
			String[] a = br.readLine().split(" ");
			int i, num, min = 1000000;
			int max = -1000000;
			BigInteger sum = BigInteger.ZERO;
			for (i = 0; i < a.length; i++) {
				num = Integer.parseInt(a[i]);
				if (num > max) {
					max = num;
				}
				if (num < min) {
					min = num;
				}
				sum = sum.add(BigInteger.valueOf(num));
			}
			System.out.println(min + " " + max + " " + sum);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}

Measured memory_bytes: 25628
#include<bits/stdc++.h>
#define sz(a) int((a).size()) 
#define pb push_back 
#define all(c) (c).begin(),(c).end() 
#define tr(c,i) for(auto i = (c).begin(); i != (c).end(); i++) 
#define present(c,x) ((c).find(x) != (c).end()) 
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define F(i,n) for(int i=0;i<n;i++)
#define MOD 1000000007
#define VE(i,v) for(int i = 0;i < (v).size();i++)

using namespace std;
#define trace(...) cerr<<__FUNCTION__<<":"<<__LINE__<<" "; __f(#__VA_ARGS__, __VA_ARGS__)
template<typename Arg1>
void __f(const char *name, Arg1 &&arg1) {
	cerr<<name<<" : "<<arg1<<endl;
}
template<typename Arg1, typename ... Args>
void __f(const char *names, Arg1 &&arg1, Args &&... args) {
	const char *comma=strchr(names+1,',');
	cerr.write(names,comma-names)<<" : "<<arg1<<" | ";
	__f(comma+1,args...);
}
typedef vector<int> vi; 
typedef vector<vi> vvi; 
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef long long ll;
typedef unsigned int ui;
typedef vector<ll> vl; 
typedef vector<vl> vvl; 
typedef pair<ll,ll> pll;
typedef vector<pll> vpll; 
 
vector<int> id;
vector<int> od;
vi adj[100001];

ll dp[3001][3001][2];
int N;
ll helper(int p, int i, int j, vector<ll> &arr)
{
	if((i>=N) || (j<0) || (i>j))
		return 0;
	if(dp[i][j][p]==-1e18)
	{
		if(p==0)
			dp[i][j][0] = max(arr[i]-helper(1,i+1, j, arr), arr[j]-helper(1,i,j-1, arr));
		else
			dp[i][j][1] = max(arr[i]-helper(0,i+1, j, arr), arr[j]-helper(0,i,j-1, arr));
	}
	return dp[i][j][p];
}


int main()

{
	std::ios::sync_with_stdio(false);
	cin.tie(NULL);
	int T;
	T=1;

	for(int tc=1; tc<=T;tc++)
	{
		cin >> N; 
		for(int i=0; i <=N; i++)
			for(int j=0; j<=N; j++)
				for(int k=0; k<2; k++)
					dp[i][j][k] = -1e18;

		vector<ll> arr(N+1);
		for(int i=0; i <N; i++)
		{
			cin>>arr[i];
			dp[i][i][0] = arr[i];
			dp[i][i][1] = arr[i];
		}
		ll ans = helper(0,0, N-1, arr);

		


			
		
		cout<<ans<<"\n";
	}
 
 
 
	return 0;
}
 
 



Measured memory_bytes: 143616
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        ArrayList<ArrayList<Integer>> mass = new ArrayList<ArrayList<Integer>>();
        if (N%2==0) {
            for (int i=0;i<N/2;i++) {
                ArrayList<Integer> add = new ArrayList<Integer>();
                add.add(i+1);
                add.add(N-i);
                mass.add(add);
            }
        } else { // N%2==1
            int N_tmp = N-1;
            for (int i=0;i<N_tmp/2;i++) {
                ArrayList<Integer> add = new ArrayList<Integer>();
                add.add(i+1);
                add.add(N_tmp-i);
                mass.add(add);
            }
            ArrayList<Integer> add_tmp = new ArrayList<Integer>();
            add_tmp.add(N);
            mass.add(add_tmp);
        }

        if (N%2==0) {
            System.out.println(4*(N/2)*(N/2-1)/2);
        } else { // N%2==1
            System.out.println(4*((N-1)/2)*((N-1)/2-1)/2+(N-1));
        }
        for (int i=0;i<mass.size();i++) {
            ArrayList<Integer> tmp = mass.get(i);
            for (int j=0;j<tmp.size();j++) {
                for (int k=i+1;k<mass.size();k++) {
                    if (i==k) continue;
                    ArrayList<Integer> tmp_2 = mass.get(k);
                    for (int l=0;l<tmp_2.size();l++) {
                        System.out.println(tmp.get(j)+" "+tmp_2.get(l));
                    }
                }
            }
        }
    }
}

Measured memory_bytes: 24532
//
//  main.cpp
//  atCoder
//
//  Created by 佐々木勇星 on 2019/07/23.
//  Copyright © 2019 佐々木勇星. All rights reserved.
//

#include <iostream>
#include <regex>


int main(void) {
    
    using namespace std;
    
    int N;
    int value = 0;
    cin >> N;
    
    int A[N], B[N];
    
    for(int i=0; i<N-1; i++){
        cin >> B[i];
        //cout << "A[i] = " << A[i] << endl;
    }
    
    for(int i=0; i<N-1; i++){
        A[i] = B[i];
        A[i+1] = B[i];
        
        if(i>0 && B[i] > B[i-1]) A[i] = B[i-1];
    }
    
    for(int i=0; i<N; i++){
        //cout << "A:" << A[i] << endl;
        value += A[i];
    }
    
    cout << value << endl;
    
    return 0;
}


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

public class Solution
{
    public static void Main()
    {
        var n = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();

        if(n.Contains(1) && n.Contains(9) && n.Contains(7) && n.Contains(4))
        {
            Console.WriteLine("YES");
        }
        else
        {
            Console.WriteLine("NO");
        }
    }
}

Measured memory_bytes: 13396
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;

int n;
vector<bitset<8> > graph;

int solve(int curr, bitset<8> used)
{
	if(used.count() == n)
		return 1;

	int ans = 0;
	for(int i=0; i<n; ++i){
		if(graph[curr][i] && !used[i])
			ans += solve(i, used | bitset<8>(1 << i));
	}
	return ans;
}

int main()
{
	int m;
	cin >> n >> m;
	graph.assign(n, 0);
	for(int i=0; i<m; ++i){
		int a, b;
		cin >> a >> b;
		-- a;
		-- b;
		graph[a][b] = graph[b][a] = true;
	}

	int ans = solve(0, 1);
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#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 n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a.at(i);

    int free = 0;
    set<int> st;
    rep(i, n) {
        if(a.at(i)/400 >= 8) free++;
        else {
            st.insert(a.at(i)/400);
        }
    }

    if(st.size() == 0) cout << 1;
    else cout << st.size();

    cout << ' ' << st.size() + free << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <functional>

using namespace std;

int main()
{
	while ( true )
	{
		int n;
		cin >> n;
		
		if ( n == 0 )
		{
			break;
		}

		vector< vector<int> > board;
		
		for ( int i = 0; i < n; i++ )
		{
			board.push_back( vector<int>() );
			board[i].resize( n );
		}

		
		int i = n / 2 + 1, j = n / 2;
		board[i][j] = 1;

		for ( int ni = 2; ni <= n * n; ni++ )
		{
			i++;
			i %= n;

			j++;
			j %= n;

			if ( board[i][j] == 0 )
			{
				board[i][j] = ni;
			}
			else
			{
				i++;
				i %= n;

				j--;
				if ( j < 0 )
				{
					j += n;
				}

				board[i][j] = ni;
			}
		}

		for ( unsigned int i = 0; i < board.size(); i++ )
		{
			for ( unsigned int j = 0; j < board[i].size(); j++ )
			{
				printf("%4d", board[i][j] );
			}
			cout << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rrep(i,n) for(int i=1; i<=(int)(n); i++)
#define pb push_back
#define all(v) v.begin(),v.end()
#define fi first
#define se second
#define bigger (char)toupper
#define smaller(char)tolower
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<string> vs;
typedef vector<char> vc;
typedef long long ll;
typedef unsigned long long ull;

int main() {
    int A,B,C;
    cin>>A>>B>>C;
    bool ok=false;
    int N=A*B;
    for(int i=A; i<=N; i+=A) {
        if(i%B==C) {
            ok=true;
            break;
        }
    }
    if(ok) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
struct dsu{
    int p[200002], sz[200002];
    void init(int n){
        for(int i=1;i<=n;i++) p[i] = i, sz[i] = 1;
    }
    int root(int a){
        return p[a] == a?a:(p[a]=root(p[a]));
    }
    void merge(int a, int b){
        a = root(a), b = root(b);
        if(a != b){
            sz[b] += sz[a];
            p[a] = b;
        }
    }
}d1, d2;
map<pii, int> dp;

int main(){
    int n, k, l;
    scanf("%d%d%d", &n, &k, &l);
    d1.init(n), d2.init(n);
    for(int i=1;i<=k;i++){
        int a, b;
        scanf("%d%d", &a, &b);
        d1.merge(a, b);
    }
    for(int i=1;i<=l;i++){
        int a, b;
        scanf("%d%d", &a, &b);
        d2.merge(a, b);
    }
    for(int i=1;i<=n;i++) dp[make_pair(d1.root(i), d2.root(i))]++;
    for(int i=1;i<=n;i++) printf("%d ", dp[make_pair(d1.root(i), d2.root(i))]);
}

Measured memory_bytes: 15104
import sys
sys.setrecursionlimit(100000)

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

MOD = 10 ** 9 + 7

if x > y:
    x, y = y, x

z = y - x

if x - z < 0 or (x - z) % 3 != 0:
    print(0)
    exit()

a = (x - z) // 3
b = a + z

def cmb(n, r):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % MOD

mod = 10**9+7 #出力の制限
N = 10**6
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

print(cmb(a+b, a))

Measured memory_bytes: 121836
import numpy as np
n,m = map(int,input().split())
left = 1
right = n

for i in range(m):
    l,r = map(int,input().split())
    if l > left:
        left = l
    if r < right:
        right = r

# print(left,right)
if right >= left:
    print(right-left+1)
else:
    print(0)

Measured memory_bytes: 12420
from collections import deque
def main():
    s = deque(input())
    q = int(input())
    appendleft=s.appendleft
    append=s.append
    flag = False
    for i in range(q):
        temp = input().split()
        if temp[0] == "1":
            flag = not flag
        else:
            if temp[1] == "1":
                if flag:
                    append(temp[2])
                else:
                    appendleft(temp[2])
            else:
                if flag:
                    appendleft(temp[2])
                else:
                    append(temp[2])
    if flag:
        s.reverse()
    print("".join(list(s)))
if __name__=="__main__":
    main()

Measured memory_bytes: 8436
import itertools


n, m = [int(i) for i in input().split()]
light = []
light_append = light.append
for _ in range(m):
    light_append([int(i) - 1 for i in input().split()][1:])
p = [int(i) for i in input().split()]

ans = 0
for bit in itertools.product((0, 1), repeat=n):
    for i, l in enumerate(light):
        if sum([bit[j] for j in l]) % 2 != p[i]:
            break
    else:
        ans += 1

print(ans)


Measured memory_bytes: 40816
#include <iostream>
#include <vector>
#define T 1001
#define M 1000000007
#define E e[x][i]
#define S e[x].size()
using namespace std;
typedef long long ll;
int N,s,t,j;
string n[T];
vector<int> e[T];

ll func(int x){
  ll r=0,i;
  if(!S){
    if(n[x]=="E") return 1;
    return 2;
  }
  else if(n[x][0]=='E'){
    r++;
    for(i=0;i<S;i++) r*=func(E);
    if(n[x]=="E?") r++;
  }
  else if(n[x][0]=='A'){
    for(i=0;i<S;i++) r+=func(E);
    if(n[x]=="A?") r++;
  }else{
    r++;
    for(i=0;i<S;i++) r*=(1+func(E));
    if(n[x]=="R") r--;
  }
  return r%M;
}
 
main(){
  cin>>N;
  for(j=0;j<N;j++) cin>>n[j];
  while(--N) cin>>s>>t,e[s-1].push_back(t-1);
  cout<<func(0)%M<<endl;
}

Measured memory_bytes: 1356
n,M,K=map(int,input().split())

def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 998244353 #出力の制限
N = (10**5)*2+5
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )
    
ans=0
for i in range(K+1):
    ans+=(M*pow(M-1,n-1-i,mod)*cmb(n-1,i,mod))%mod
print(ans%mod)

Measured memory_bytes: 112588
#include <iostream>
using namespace std;
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#define MOD1 1000000007
#define MOD2 998244353
#define LIMIT1 200002
#define LIMIT2 500002
typedef long long ll;
typedef long double ld;
typedef const void cv;
#define rep(i,n) for((i)=0;(i)<(n);(i)++)
#define per(i,n) for((i)=(n)-1;(i)>=0;(i)--)
#define max(a,b) ((a)>(b) ? (a) : (b))
#define min(a,b) ((a)<(b) ? (a) : (b))
#define zt(a,b) (max((a),(b))-min((a),(b)))
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll nPr(int n,int r){ll i,result=1;rep(i,r){result*=(ll)(n-i);}return result;}
ll nCr(int n,int r){ll i,result=1;if(n<r) return 0;rep(i,min(r,n-r)){result*=(ll)(n-i);result/=(ll)(i+1);}return result;}
#define nHr(n,r) nCr((int)((n)+(r)+1),(int)(r))
#define sankaku(x) (((x)*((x)+1))/2)
int dx[8]={1,0,-1,0,1,-1,-1,1},dy[8]={0,1,0,-1,1,1,-1,-1};
int upint(cv *a, cv *b) { return *(int *)a < *(int *)b ? -1 : *(int *)a > *(int *)b ? 1 : 0; }
int downint(cv *a, cv *b) { return *(int *)a < *(int *)b ? 1 : *(int *)a > *(int *)b ? -1 : 0; }
int upchar(cv *left, cv *right) {return strcmp((char *)left,(char *)right);}
int downchar(cv *left, cv *right) {return strcmp((char *)right,(char *)left);}
void tmpInit(int *c,ll m) {ll i;rep(i,m) c[i]=i;}
ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1){
      res *= a; if(mod>=1) res %= mod;
    }
    a *= a; if(mod>=1) a %= mod;
    n >>= 1;
  }
  return res;
}
void initialize(){
  
}
int main(void){
  initialize();
  ll n,m,i,j,k,result=0;
  int a[LIMIT2]={0};
  char s[LIMIT1];
  
  cin >> s;
  if(s[0] >= 'A' && s[0] <= 'Z') cout << "A" << endl;
  else cout << "a" << endl;
  
  return 0;
}

Measured memory_bytes: 3636
import sys
n = int(input())
D = {}
for i in [0,n-1]:
    print(i,flush=True)
    s = input()
    if s == "Vacant":
        sys.exit()
    D[i] = s
inf = 0
sup = n
while True:
    mid = (sup+inf)//2
    print(mid,flush=True)
    s = input()
    if s == "Vacant":
        sys.exit()
    else:
        D[mid] = s
        if ((mid%2==inf%2) != (D[mid] == D[inf])):
            sup = mid
        else:
            inf = mid

Measured memory_bytes: 9224
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

alias L = Tuple!(int, "level", long, "size", long, "patty");

L[51] LS;

void main()
{
    LS[0] = L(0, 1, 1);
    foreach (i; 0..50) {
        auto l = LS[i];
        LS[i+1] = L(i+1, l.size*2 + 3, l.patty*2 + 1);
    }

    long solve(long l, long i) {
        if (i <= l) return 0;
        if (l == 0) return 1;

        if (i <= LS[l-1].size + 1) {
            return solve(l-1, i-1);
        } else if (i == LS[l-1].size + 2) {
            return LS[l-1].patty + 1;
        } else {
            return solve(l-1, i-2-LS[l-1].size) + 1 + LS[l-1].patty;
        }
    }

    auto nx = readln.split.to!(long[]);
    auto N = nx[0];
    auto X = nx[1];

    writeln(solve(N, X));
}

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

using namespace std;

int main() {
  int N;
  cin >> N;
  for (int i = 0; i < N; i++) {
    int A;
    cin >> A;
    if (A % 2 == 0) {
      if (A % 3 == 0 || A % 5 == 0) {
      } else {
	cout << "DENIED" << endl;
	return 0;
      }
    }
  }

  cout << "APPROVED" << endl;

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int a,b,c;
  int sum=0;
  scanf("%d %d %d",&a,&b,&c);
  
  sum = a + b + c;
  
  if(sum>21){
    printf("bust");
  }else{
    printf("win");
  }
  
  return 0;
}

Measured memory_bytes: 128
import Control.Monad
import Data.List

main :: IO ()
main = do
  [n, k] <- map read . words <$> getLine
  hs <- replicateM n readLn
  print $ solve k hs

solve :: Int -> [Int] -> Int
solve k hs = minimum $ zipWith (-) hs2 hs1
  where
    hs1 = sort hs
    hs2 = drop (k - 1) hs1

Measured memory_bytes: 65916
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
#define repitr(itr,a) for(auto itr=a.begin();itr!=a.end();++itr)
#define P pair<int,ll>
const ll MOD=998244353;
const int INF=1e9;
const double PI=acos(-1);


int main() {
    ios_base::sync_with_stdio(false);

    int a,b,c;
    cin >> a >> b >> c;
    if ((b*10+c)%4==0) cout << "YES" << endl;
    else cout << "NO" << endl;

    return 0;

}


Measured memory_bytes: 3588
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

//struct edge {int from, to, cost;};

constexpr double EPS = 1e-10;
//constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;
constexpr int MOD = 1'000'000'007;
//inline void modAdd(LL &l, LL &r) {l = (l + r) % MOD;}

template<class T> inline T sqr(T x) {return x*x;}

bool solve(LL t, VLL &h, int &a, int &b) {
    int diff = a - b;
    LL rest = t;
    for (auto v: h) {
        v -= t * b;
        if (v <= 0) continue;
        rest -= max(0LL, (v + diff - 1) / diff);
        if (rest < 0) return false;
    }
    //dump(t);
    return true;
}

long long meguru_bin(VLL &h, int &a, int &b) {
    long long ok = 1'000'000'000 + 1;
    long long ng = -1;

    while (abs(ok - ng) > 1) {
        long long mid = ng + (ok - ng) / 2;
        //dump(ok);
        //dump(ng);
        //dump(mid);
        if (solve(mid, h, a, b)) ok = mid;
        else ng = mid;
        //break;
    }

    return ok;
}

void solve() {
    int n,a,b;
    cin >> n >> a >> b;
    VLL h(n);
    REP(i,0,n) cin >> h[i];
    cout << meguru_bin(h, a, b) << endl;
}

int main() {
    solve();
    
    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
static const int N=1000;

int lcs(string X, string Y){
    int c[N+1][N+1];
    int m=X.length();
    int n=Y.length();
    int maxlcs=0;
    X=' '+X;
    Y=' '+Y;
    for(int i=0;i<=m;i++) c[i][0]=0;
    for(int j=1;j<=n;j++) c[0][j]=0;
    
    for(int i=1;i<=m;i++){
        for(int j=1;j<=n;j++){
            if(X[i]==Y[j]){
                c[i][j]=c[i-1][j-1]+1;
            }else{
                c[i][j]=max(c[i-1][j],c[i][j-1]);
            }
            maxlcs=max(maxlcs,c[i][j]);
        }
    }
    return maxlcs;
}

int main(){
    string a1,a2;
    int n;
    cin >> n;
    for(int i=1;i<=n;i++){
        cin >> a1 >> a2;
        cout << lcs(a1,a2) << endl;
    }
    return 0;
}


Measured memory_bytes: 7064
N = int(input())
K = int(input())
memo = {}

def F(N, K):
    """
    F(N, K) = (1以上N以下で0でない桁がちょうどK個なものの個数)
    Nを一の桁から見ていくことで再帰で求める
    （例）F(314,3) = F(31,2)*4 + F(30,2)*5 + F(31,3)
                      = {F(3,1) + F(2,1)*8 + F(3,2)} * 4
                            + {F(2,1)*9 + F(3,2)} * 5
                            + {F(3,2) + F(2,2)*8 + F(3,3)}
                      = ...
    """
    r = int(str(N)[-1])
    M = (N - r) // 10
    if K == 0 and N >= 0:
        return 1
    elif K == 0 and N <= -1:
        return 0
    elif N <= 0:
        return 0
    else:
        return F(M, K-1) * r + F(M-1, K-1) * (9-r) + F(M, K)

print(F(N, K))


Measured memory_bytes: 49880
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define show(x) {for(auto i: x){cout << i << " ";} cout<<endl;}
#define showm(m) {for(auto i: m){cout << m.x << " ";} cout<<endl;}
typedef long long ll;
typedef pair<int, int> P;
ll gcd(int x, int y){ return y?gcd(y, x%y):x;}
ll lcm(ll x, ll y){ return (x*y)/gcd(x,y);}


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

    int score = 0;
    int score_min = 0;
    rep(i, n){
        if (s[i] == '('){
            score++;
        } else {
            score--;
        }
        score_min = min(score, score_min);
    }
    int l = -score_min;
    int r = score - score_min;
    string ans = "";
    rep(i, l) ans += "(";
    ans += s;
    rep(i, r) ans += ")";
    
    cout << ans << endl;
}



Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    
    long prevT = 0;
    long prevA = 0;
    long ans = 0;
    for (int i = 0; i < N; i++) {
      int T = sc.nextInt();
      int A = sc.nextInt();
      long f = 1;
      if (T < prevT) {
        f = prevT/T + (prevT%T == 0 ? 0 : 1);
      }
      if (A < prevA) {
        long fa = prevA/A + (prevA%A == 0 ? 0 : 1);
        f = Math.max(f,fa);
      }
      
      ans += f*T - prevT + f*A - prevA;
      prevT = f*T;
      prevA = f*A;
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 23892