akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>
int main(void){
	int n,i,t,x,y,_t=0,_x=0,_y=0,absT,absX,absY,sum;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d%d%d",&t,&x,&y);
		absT=abs(t-_t); _t=t;
		absX=abs(x-_x); _x=x;
		absY=abs(y-_y); _y=y;
		sum=absX+absY;
		if(absT<sum){printf("No\n");return 0;}
		if(absT%2!=sum%2){printf("No\n");return 0;}
	}
	printf("Yes\n");
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define INT INT_MAX
#define LONG LLONG_MAX
#define f(i,n) for(int i=0;i<(n);i++)
#define P pair<int,int>
typedef long long ll;
using namespace std;

ll GCD(ll a, ll b) {
	if (b == 0)return a;
	return GCD(b, a%b);
}

ll LCM(ll a, ll b) {
	return a / GCD(a, b)*b;
}

ll mypow(ll a, ll b, ll c) {
	if (b == 0)return 1;
	if (b % 2)return mypow(a, b - 1, c)*a%c;
	else return mypow(a, b / 2, c)*mypow(a, b / 2, c) % c;
}

ll longmax(ll a,ll b){
	if(a>b) return a;
	else return b;
}

ll longmin(ll a,ll b){
	if(a<b) return a;
	else return b;
}

signed main(){
	string s;
	map<char,int> m;
	cin>>s;
	int ans=INT;
	for(int j=0;j<26;j++){
		int b[s.size()],d=0,e=0;
		f(i,s.size()){
			if(s[i]=='a'+j){
				b[d]=i;
				d++;
			}
		}
		b[d]=s.size();
		for(int i=d;i>=0;i--){
			if(i) b[i]-=b[i-1]+1;
			e=max(e,b[i]);
		}
		ans=min(ans,e);
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from collections import defaultdict 
def main():
    s = readline().rstrip().decode()
    n = len(s)
    T = [0]
    P = 2019
    dd = defaultdict(int)
    dd[0] += 1
    for i in range(1, n+1):
        v = ((ord(s[-i])-ord('0'))*pow(10, i-1, P) + T[i-1])%P
        dd[v] += 1
        T.append(v)
    ans = 0
    for v in dd.values():
        ans += v*(v-1)//2
    print(ans)
if __name__ == '__main__':
    main()


Measured memory_bytes: 82456
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define ll long long
#define mod 998244353

int n;
int s;
int a[4000];
int knap[3001][3001]={};

int compare_int(const void *a, const void *b){
    return *(int*)a - *(int*)b;
}

int main(){
  scanf("%d%d",&n,&s);
  for(int i=0;i<n;i++){
    scanf("%d",&a[i]);}

  for(int j=0;j<=n;j++){
    knap[0][j]=0;}
  knap[0][0] = 1;

  for(int i=1;i<=n;i++){ //A_i made
    for(int j=0;j<=s;j++){ //S=j
      knap[i][j] = knap[i-1][j]*2%mod;
      if(j-a[i-1]>=0){
	knap[i][j] += knap[i-1][j-a[i-1]];
    knap[i][j] %= mod;}
      //printf("%d\n",knap[i][j]);
    }}

  ll ans =0;
  printf("%d\n",knap[n][s]);
  
  return 0;
}


Measured memory_bytes: 36916
import java.util.*;
public class Main {
	public static class City{
		private long pref;
		private int year;
		private int num;
		private String No;
		
		public City(int p, int y, int n) {
			this.pref = p;
			this.year = y;
			this.num = n;
		}
		
		public long getPref() {
			return pref;
		}
		public int getYear() {
			return year;
		}
		public int getNum() {
			return num;
		}
		public String getNo() {
			return No;
		}
		public void setNo(String No) {
			this.No = No;
		}
	}
	
	public static class Comp1 implements Comparator<City> {
	    public int compare(City x1, City x2) {
	        if(x1.getPref() < x2.getPref()) {
	            return -1;
	        } 
	        else if(x1.getPref() > x2.getPref()){
	            return 1;
	        } 
	        else{
	        	if(x1.getYear() < x2.getYear()) {
	        		return -1;
	        	}
	        	else if(x1.getYear() > x2.getYear()) {
	        		return 1;
	        	}
	        	else {
	        		return 0;
	        	}
	        }
	    }
	}
	
	public static class Comp2 implements Comparator<City> {
	    public int compare(City x1, City x2) {
	        if(x1.getNum() < x2.getNum()) {
	            return -1;
	        } 
	        else{
	            return 1;
	        }
	    }
	}

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int N = stdIn.nextInt();
		int M = stdIn.nextInt();
		ArrayList <City> cities = new ArrayList<City>();
		for(int i = 0; i < M; i++) {
			int P = stdIn.nextInt();
			int Y = stdIn.nextInt();
			City city = new City(P, Y, i);
			cities.add(city);
		}
		Collections.sort(cities, new Comp1());
		String str = String.format("%012d", cities.get(0).getPref()*1000000+1);
		cities.get(0).setNo(str);
		int index = 2;
		for(int i = 1; i < M; i++) {
			if(cities.get(i-1).getPref() != cities.get(i).getPref()) {
				index = 1;
			}
			str = String.format("%012d", cities.get(i).getPref()*1000000+index);
			cities.get(i).setNo(str);
			index++;
		}
		Collections.sort(cities, new Comp2());
		for(City c:cities) {
			System.out.println(c.getNo());
		}

	}

}

Measured memory_bytes: 113864
OPERATORS = {
    "+": lambda x, y: x + y,
    "-": lambda x, y: x - y,
    "*": lambda x, y: x * y,
    "/": lambda x, y: x // y
}


# OP_PL = "+"
# OP_MN = "-"
# OP_MP = "*"
# OP_DV = "/"

while True:
    a, b, c  = input().split()
    a = int(a)
    c = int(c)
    if b == "?":
        break
    print(OPERATORS.get(b)(a, c))


Measured memory_bytes: 5596
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n,x) for(int i=n;i<x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define pb push_back
using ll = long long;

int main() {
	ll n;
	cin >> n;
	vector<string> s(n);
	rep(i, 0, n) cin >> s[i];

	ll ans = 0;
	unordered_map<string, int> mp;
	rep(i, 0, n) {
		SORT(s[i]);
		if (mp.count(s[i])) {
			mp[s[i]]++;
			ans += mp[s[i]];
		}
		mp[s[i]];
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 17700
#include<iostream>
#include<cmath>
#include<vector>
#include<map>
#include<string>
#include<algorithm>
using namespace std;
int main(){
  int A, B, K;
  cin >> A >> B >> K;
  vector<int> l;
  for(int i=1; i<=100; i++) if(A%i==0 && B%i==0) l.push_back(i);
  sort(l.rbegin(), l.rend());
  cout << l[K-1] << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define REP(i,n) for(int i=0;i<(int)(n);i++)

using namespace std;
using ll=long long;
ll mod=1e+9+7;
char a[1010][1010];
ll dp[1010][1010];

int main(){ _;
  int h,w;cin>>h>>w;
  REP(i,h)REP(j,w)cin>>a[i][j];

  REP(i,h){
    if(a[i][0]=='#')break;
    dp[i][0]=1;
  }
  REP(j,w){
    if(a[0][j]=='#')break;
    dp[0][j]=1;
  }
  for(int i=1;i<h;i++){
    for(int j=1;j<w;j++){
      if(a[i][j]=='#')continue;
      dp[i][j]=dp[i-1][j]+dp[i][j-1];
      if(dp[i][j]>=mod)
	dp[i][j]-=mod;
    }
  }
  cout<<dp[h-1][w-1]<<endl;
}


Measured memory_bytes: 9216
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<vector>
#include <algorithm>
#include<deque>
#include<queue>
#include<set>
#include <functional>
#include <cmath>


//マクロ
#define REP(i,n) for(int i=0; i<(int)(n); ++i)
#define REPS(i,n) for(int i=1; i<=(int)(n); ++i)
#define RREP(i,n) for(int i=(int)(n)-1; i>=0; --i)
#define RREPS(i,n) for(int i=(int)(n); i>0; --i)
#define FOR(i,s,e) for(int i=(int)(s); i<(int)(e); ++i)
#define RFOR(i,s,e) for(int i=(int)(e)-1; i>=(int)(s); --i)

#define All(a) (a).begin(),(a).end()

//定数
#define INF 1e9
#define MOD (int)(1e9+7)

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

//とりあえず書いておく変数
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };

//今回の変数
vector<int> l;

//使用する関数
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;
}


int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	double a,b,x;
	cin >> a >> b >> x;

	double t;
	if (a*a*b/2 == x) {
		cout << "45" << endl;
		return 0;
	}
	else if (a*a*b / 2 > x) {
		t = a*b*b / x /2;
	}
	else {
		t = (2 * b - 2 * x / (a*a))/a;
	}

	//cout << t << endl;
	//cout << atan(t)<< endl;
	//cout << atan(t) * 180 / M_PI << endl;
	printf("%.10f\n", atan(t) * 180 / M_PI);
}

Measured memory_bytes: 384
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define reps(i,a,b) for(int i=a;i<b;++i)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template<typename T> inline bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T &a,T b){if(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U &u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U &u,const V... v){for(auto &e:u)fill_v<T>(e,v...);}

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

    int x, n;
    cin >> x >> n;
    vector<int> p(n);
    rep(i, n) cin >> p[i];
    int now = 1000;
    int ans = 0;
    for (int i = -100; i <= 105; ++i) {
        bool flag = false;
        rep(j, n) if (p[j] == i) flag = true;
        if (!flag && chmin(now, abs(x-i))) ans = i;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
int n,m,head[100100],cnt,dsu[100100],pos[100100];
bool sta[100100],vis[100100];
pair<int,bool>p[100100];
struct edge{
	int to,next,id;
}edge[1001000];
void ae(int u,int v,int w){
	edge[cnt].id=w,edge[cnt].next=head[u],edge[cnt].to=v,head[u]=cnt++;
	edge[cnt].id=w,edge[cnt].next=head[v],edge[cnt].to=u,head[v]=cnt++;
}
vector<int>v;
int fd(int x){return dsu[x]==x?x:dsu[x]=fd(dsu[x]);}
bool mg(int x,int y){
	x=fd(x),y=fd(y);
	if(x==y)return false;
	dsu[x]=y;
	return true;
}
bool dfs(int x){
	bool res=sta[x];
	vis[x]=true;
	for(int i=head[x];i!=-1;i=edge[i].next){
		if(vis[edge[i].to])continue;
		bool now=dfs(edge[i].to);
		if(now)v.push_back(edge[i].id);
		res^=now;
	}
	return res;
}
int main(){
	scanf("%d%d",&n,&m),memset(head,-1,sizeof(head));
	for(int i=1;i<=n+1;i++)dsu[i]=i;
	for(int i=1;i<=n;i++)scanf("%d%d",&p[i].first,&p[i].second);
	sort(p+1,p+n+1);
	for(int i=1;i<=n;i++)pos[i]=p[i].first,sta[i]=p[i].second;
	for(int i=n;i;i--)sta[i]^=sta[i-1];
	for(int i=1,l,r;i<=m;i++){
		scanf("%d%d",&l,&r),l=lower_bound(pos+1,pos+n+1,l)-pos,r=upper_bound(pos+1,pos+n+1,r)-pos;
		if(mg(l,r))ae(l,r,i);
	}
	dfs(n+1);
	for(int i=1;i<=n;i++){
		if(vis[i])continue;
		if(dfs(i)){puts("-1");return 0;}
	}
	sort(v.begin(),v.end());
	printf("%d\n",v.size());
	for(int i=0;i<v.size();i++)printf("%d ",v[i]);
	return 0;
}

Measured memory_bytes: 8396
#include <cstdio>
#include <cassert>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>

std::pair<int, int> fulfill_A(std::vector<std::string> &S, int &A) {
  size_t N=S.size(), M=S[0].length();
  size_t i, j;
  for (i=0; i+1<N; i+=2) {
    for (j=0; j+1<M; j+=2) {
      if (A < 2) return {i, j};

      S[i][j] = '<';
      S[i][j+1] = '>';
      S[i+1][j] = '<';
      S[i+1][j+1] = '>';
      A -= 2;
    }
  }
  return {i, j};
}

std::pair<int, int> fulfill_B(std::vector<std::string> &S, int &B,
                              const std::pair<int, int> &a) {
  size_t N=S.size(), M=S[0].length();
  size_t i=a.first, j;
  if (i+1 < N) {
    for (j=a.second; j+1<M; j+=2) {
      if (B < 2) return {i, j};

      S[i][j] = '^';
      S[i+1][j] = 'v';
      S[i][j+1] = '^';
      S[i+1][j+1] = 'v';
      B -= 2;
    }
  }

  for (i+=2; i+1<N; i+=2) {
    for (j=0; j+1<M; j+=2) {
      if (B < 2) return {i, j};

      S[i][j] = '^';
      S[i+1][j] = 'v';
      S[i][j+1] = '^';
      S[i+1][j+1] = 'v';
      B -= 2;
    }
  }
  return {i, j};
}

int main() {
  int N, M, A, B;
  scanf("%d %d %d %d", &N, &M, &A, &B);

  if (N == 3 && M == 3 && A == 2 && B == 2) {
    printf("YES\n");
    printf("<>^\n");
    printf("^.v\n");
    printf("v<>\n");
    return 0;
  }

  if (N*M < 2*(A+B))
    return !printf("NO\n");

  if (N == 1 && B) return !printf("NO\n");
  if (M == 1 && A) return !printf("NO\n");

  if ((M/2*2)*N < A*2) return !printf("NO\n");
  if ((N/2*2)*M < B*2) return !printf("NO\n"); 

  // A: <>
  // B: ^v
  std::vector<std::string> S(N, std::string(M, '.'));

  if (N % 2) {
    for (int j=0; j+1<M && A; j+=2) {
      S[N-1][j] = '<';
      S[N-1][j+1] = '>';
      --A;
    }
  }

  if (M % 2) {
    for (int i=0; i+1<N && B; i+=2) {
      S[i][M-1] = '^';
      S[i+1][M-1] = 'v';
      --B;
    }
  }

  std::pair<int, int> a=fulfill_A(S, A);
  std::pair<int, int> b=fulfill_B(S, B, a);

  assert(A <= 1 && B <= 1);

  if (A) {
    for (int i=0; i<N; ++i) {
      for (int j=0; j+1<M; ++j) {
        if (S[i][j] == '.' && S[i][j+1] == '.') {
          S[i][j] = '<';
          S[i][j+1] = '>';
          --A;
          goto noA;
        }
      }
    }
  noA:;
  }

  if (B) {
    for (int i=0; i+1<N; ++i) {
      for (int j=0; j<M; ++j) {
        if (S[i][j] == '.' && S[i+1][j] == '.') {
          S[i][j] = '^';
          S[i+1][j] = 'v';
          --B;
          goto noB1;
        }
      }
    }
  noB1:;
  }

  if (M >= 3) {
    if (S[N-1][M-3] == '<' && S[N-1][M-2] == '>' && S[N-1][M-1] == '.') {
      S[N-1][M-3] = '.';
      S[N-1][M-2] = '<';
      S[N-1][M-1] = '>';
    }
  }

  if (B) {
    for (int i=0; i+1<N; ++i) {
      for (int j=0; j<M; ++j) {
        if (S[i][j] == '.' && S[i+1][j] == '.') {
          S[i][j] = '^';
          S[i+1][j] = 'v';
          --B;
          goto noB2;
        }
      }
    }
  noB2:;
  }

  if (A || B) {
    return !printf("NO\n");
  }

  printf("YES\n");
  for (int i=0; i<N; ++i)
    for (int j=0; j<M; ++j)
      printf("%c%s", S[i][j], j+1<M? "":"\n");
}


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

bool pos[10001];
int N,a;

int main()
{
	cin >> N;
	pos[0] = 1;
	for(int i=0;i<N;i++)
	{
		cin >> a;
		for(int j=10000-a;j>=0;j--)
			if(pos[j])
				pos[j+a] = 1;
	}
	int mx = 0;
	for(int i=0;i<=10000;i++)
		if(i%10 && pos[i])
			mx = i;
	cout<< mx << '\n';
}

Measured memory_bytes: 256
import bisect
import heapq
import itertools
import math
import operator
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

S = np.array(list(sys.stdin.readline().rstrip()))
T = np.array(list(sys.stdin.readline().rstrip()))

print((S == T).sum())


Measured memory_bytes: 23196
#include <algorithm>
#include <array>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>

using namespace std;

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

  for (int i = 1; i <= n; i++) {
    int cnt = 0;

    for (int j = 1; j * j <= i; j++) {
      for (int k = 1; k <= j; k++) {
        for (int l = 1; l <= k; l++) {
          if (j * j + k * k + l * l + j * k + k * l + j * l == i) {
            if (j == k && k == l) {
              cnt++;
            } else if (j == k) {
              cnt += 3;
            } else if (k == l) {
              cnt += 3;
            } else {
              cnt += 6;
            }
          }
        }
      }
    }

    cout << cnt << endl;
  }

  return 0;
}


Measured memory_bytes: 3044
n = gets.to_i
as = gets.chomp.split.map(&:to_i)
ans = 0

def solve n,cnt
	if n % 2 != 0
		cnt
	else
		solve(n/2, cnt+1)
	end
end

as.each do |a|
	if a % 2 == 0
		ans += solve(a,0)
	end
end

puts ans.to_i

Measured memory_bytes: 2428
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<algorithm>
#include<map>
#include<cstdlib>
#include<cmath>
#include<numeric>
#include<iomanip>
using namespace std;
using ll =long long;
const int MOD = 1000000007;
int main() {
	string S, T;
	cin >> S >> T;
	cout << T + S;


}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for (int i=0;i<(n);i++)
using namespace std;
using P = pair<int,int>;
using ll = long long;
int main() {
    int h, w, k; cin >> h >> w >> k;
    vector<string> c(h);
    rep(i, h) cin >> c[i];
    int ans = 0;
    rep(i0, 1 << h){
        rep(j0, 1 << w){
            int count = 0;
            rep(i1, h){
                rep(j1, w){
                    if(i0 & 1<<i1) continue;
                    if(j0 & 1<<j1) continue;
                    if(c[i1][j1] == '#') ++count;
                }
            }if(count == k){++ans;}
        }
    }
    cout << ans << endl;
}



Measured memory_bytes: 3624
import java.util.Scanner;

public class Main {

	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		int n = sc.nextInt();

		int ans = sc.nextInt();
		for(int i = 1; i < n; i++) {
			ans = gcd(ans, sc.nextInt());
		}

		System.out.println(ans);
	}

	static int gcd(int a, int b) {
		if(b == 0) return a;
		return gcd(b, a % b);
	}
}


Measured memory_bytes: 48116
import java.util.*;
import java.util.stream.*;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int r = in.nextInt(), d = in.nextInt(), x = in.nextInt();
        for (int i = 0; i < 10; i++) {
            int next = r * x - d;
            System.out.println(next);
            x = next;
        }
    }
}


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

using namespace std;

int main(){
    int x1,y1,x2,y2,x3,y3,x4,y4;
    cin >> x1 >> y1 >> x2 >> y2 ;
    int x = x2 - x1;
    int y = y2 - y1;
    cout << x2 - y << " " << y2 + x << " " <<  x1 - y << " "<< y1 + x << endl;
}

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

using namespace std;

#define ALL(x) (x).begin(), (x).end()
#define AND(x,y,z) 
#define DUMP(xs) for (auto x:xs) cout<<x<<' ';cout<<endl
#define DUMPP(xs) for (auto x:xs) cout<<'('<<x.first<<','<<x.second<<')';cout<<endl
#define FOR(i,a,b) for (ll i=(ll)(a);i<(ll)(b);++i)
#define OUT(x) cout<<x<<endl
#define REP(i,n) FOR(i,0,n)
#define YES(cond) cond ? OUT("YES") : OUT("NO")
#define Yes(cond) cond ? OUT("Yes") : OUT("No")

template<class T> T gcd(const T x,const T y){if(!y){return x;}return gcd(y,x%y);}
template<class T> T lcm(const T x,const T y){return x/gcd(x,y)*y;};
template<class T> T modpow(const T x,const T n,const T mod) {
  T res=1;while(n>0){if(n%2)res=res*x%mod;x=x*x%mod;n/=2;};return res;
}
template<class T> bool alltrue(const T &a){return all_of(ALL(a),[](bool x){return x;});}
template<class T> bool anytrue(const T &a){return any_of(ALL(a),[](bool x){return x;});}
template<class T> bool contain(const T &a,const T &b){for(auto x:b){if (a.find(x)==a.end()){return false;}}return true;}
template<class T> bool mmax(T &m,const T q){ if (m < q) {m = q; return true;} else return false; }
template<class T> bool mmin(T &m,const T q){ if (m > q) {m = q; return true;} else return false; }
template<class T> int siz(const T &a) {return (int)a.size();}
template<class T> set<T> devisers(T n) {
  set<T> res;for(T i=1;i<(T)sqrt(n)+1;i++){if(n%i==0){res.insert(i);res.insert(n/i);}}return res;
}
template<class T> void concat(T &a, const T &b){a.insert(a.end(),b.begin(),b.end());}
template<class T> void getand(const T &a,const T &b,T &c) {
  set_intersection(a.begin(),a.end(),b.begin(),b.end(),inserter(c,c.end()));
}
template<class T> void getor(const T &a,const T &b,T &c) {
  set_union(a.begin(),a.end(),b.begin(),b.end(),inserter(c,c.end()));
}

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

const int MOD=1e9+7;
const int MAX=1e5+100;

int main() {
  ll H,W;cin>>H>>W;
  vector<vector<int>> gap(H,vector<int>(W,0));
  REP(h,H)REP(w,W) cin>>gap[h][w];
  REP(h,H)REP(w,W) {
    int B;cin>>B;
    gap[h][w] = abs(gap[h][w]-B);
  }

  int max_gap = 160*80;
  vector<vector<bitset<160*80*2+10>>> dp(H,vector<bitset<160*80*2+10>>(W));
  dp[0][0].set(gap[0][0]+max_gap);

  FOR(w,1,W) {
    dp[0][w] |= (dp[0][w-1]<<gap[0][w]);
    dp[0][w] |= (dp[0][w-1]>>gap[0][w]);
  }
  FOR(h,1,H) {
    dp[h][0] |= (dp[h-1][0]<<gap[h][0]);
    dp[h][0] |= (dp[h-1][0]>>gap[h][0]);
  }
  FOR(h,1,H)FOR(w,1,W) {
    dp[h][w] |= (dp[h-1][w]<<gap[h][w]);
    dp[h][w] |= (dp[h-1][w]>>gap[h][w]);
    dp[h][w] |= (dp[h][w-1]<<gap[h][w]);
    dp[h][w] |= (dp[h][w-1]>>gap[h][w]);
  }

  FOR(i,max_gap,max_gap*2+5) {
    if (dp[H-1][W-1][i]) {
      OUT(i-max_gap);
      break;
    }
  }

  return 0;
}

Measured memory_bytes: 20736
#include<stdio.h>
#include<string.h>

int N;
int S;
int D[50];
int ans = 0;

int main()
{
	scanf("%d", &N);
	for (int i = 0; i < N; i++) {
		scanf("%d", &D[i]);
	}
	
	for (int i = 0; i < N; i++) {
		for (int j = i + 1; j < N; j++) {
			S = D[i] * D[j];
			ans = ans + S;
		}
	}

	printf("%d", ans);

	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <random>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include <fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;

using ll = long long;
using vll = vector<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using vb = vector<bool>;
using mll = map<ll, ll>;
using sll = stack<ll>;
#define REP(i,n) for(ll i(0);(i)<(n);(i)++)
#define rep(i,n) for(ll i(0);(i)<(n);(i)++)
#define ALL(a) a.begin(), a.end()
#define enld endl //* missspell check
const ll INF = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }

void solve(long long X){
    cout << 8 - (X-400)/200 <<endl;
}
int main(){
    long long X;
    scanf("%lld",&X);
    solve(X);
    return 0;
}


Measured memory_bytes: 3224
#include <bits/stdc++.h>
#define mk make_pair
#define ll long long
using namespace std;
const int N = 2e3 + 5;
const ll inf = 1e15;
int a[N];
ll ans;
vector<int> Eid[N];
int n, m, cnt, S, T, in[N], out[N], cur[N], d[N];
struct Edge {
	ll c;
	int v;
} E[N];
void AddEdge(int x, int y, ll c) {
	E[cnt].v = y, E[cnt].c = c;
	Eid[x].push_back(cnt++);
	E[cnt].v = x, E[cnt].c = 0;
	Eid[y].push_back(cnt++);
}
bool BFS() {
	static int Q[N];
	int x, ql, qr;
	for (int i = 0; i <= T; i++) d[i] = -1;
	Q[ql = qr = 0] = S; d[S] = 0;
	while (ql <= qr) {
		x = Q[ql++];
		for (int i = 0; i < Eid[x].size(); i++) {
			const Edge &e = E[Eid[x][i]];
			if (e.c && d[e.v] == -1) {
				Q[++qr] = e.v;
				d[e.v] = d[x] + 1;
				if (e.v == T) return 1;
			}
		}
	}
	return 0;
}
ll Aug(int x, ll a) {
	if (x == T) return a;
	ll aug = 0, delta;
	for (int &i = cur[x]; i < Eid[x].size(); i++) {
		Edge &e = E[Eid[x][i]];
		if (e.c && d[e.v] == d[x] + 1) {
			delta = Aug(e.v, min(a, (ll)e.c));
			if (delta) {
				e.c -= delta;
				E[Eid[x][i] ^ 1].c += delta;
				aug += delta;
				if (!(a -= delta)) break;
			}
		}
	}
	if (!aug) d[x] = -1;
	return aug;
}
ll MaxFlow() {
	ll flow = 0;
	while(BFS()) {
		for (int i = 0; i <= T; i++) cur[i] = 0;
		flow += Aug(S, inf);	
	}
	return flow;
}
int main() {
	cin >> n;
	S = 0; T = n + 1;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		if (a[i] > 0) {
			ans += a[i];
			AddEdge(i, T, a[i]);
		} else {
			AddEdge(S, i, -a[i]);
		}
	}
	for (int i = 1; i <= n; i++) {
		if (a[i] < 0) {
			for (int j = i + 1; j <= n; j++) {
				if (j % i == 0 && a[j] > 0) {
					AddEdge(i, j, inf);
				}
			}
		}
	}
//	cout << ans << endl;
	cout << max(0ll, ans - MaxFlow()) << endl;
} 


Measured memory_bytes: 384
#include "bits/stdc++.h"

using namespace std;
typedef long long int ll;
typedef pair<ll, ll > pi;  
typedef pair<pair<ll, ll >, ll > pii;  
vector<ll > vec;
vector<vector<ll > > vec2;
ll MOD = 1000000007;
ll INF = 1145141919454519;


int main() {
    ll a, b;
    cin >> a >> b;
    if(a <= b){
        cout << a << endl;
    }else{
        cout << a - 1 << endl;
    }
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <memory.h>

using namespace std;
typedef long long LL;
const int maxn = 200005;

int ehead[maxn],ecnt;
struct edge {
	int u,v,next;
}edg[maxn];
void add(int u,int v) {
	edg[++ecnt]=(edge){u,v,ehead[u]};
	ehead[u]=ecnt;
}
bool vis[maxn],ins[maxn],onring[maxn],flag;
int n,a[maxn],fa[maxn],stk[maxn],top,bac[maxn];
void dfs(int u)
{
	vis[u]=ins[u]=true;
	for (int v,j=ehead[u];j&&!flag;j=edg[j].next) 
	if (ins[v=edg[j].v]) {
		onring[v]=flag=true;stk[++top]=v;
		for (int j=u;j!=v;j=fa[j])
			onring[j]=true,stk[++top]=j;
	}
	else if (!vis[v]) fa[v]=u,dfs(v);
	ins[u]=false;
}
int calc1(int u)
{
	for (int v,j=ehead[u];j;j=edg[j].next)
	if (!onring[v=edg[j].v]) bac[a[v]]++;
	int w=0;while (bac[w]) ++w;
	for (int v,j=ehead[u];j;j=edg[j].next)
	if (!onring[v=edg[j].v]) bac[a[v]]--;
	return w;
}
int calc2(int u)
{
	for (int j=ehead[u];j;j=edg[j].next)
		bac[a[edg[j].v]]++;
	int w=0;while (bac[w]) ++w;
	for (int j=ehead[u];j;j=edg[j].next)
		bac[a[edg[j].v]]--;
	return w;
}
void dfs2(int u)
{
	for (int v,j=ehead[u];j;j=edg[j].next)
	if (!onring[v=edg[j].v]) dfs2(v);
	a[u]=calc1(u);
}
int main()
{
	#ifdef Amberframe
		freopen("arc079f.in","r",stdin);
		freopen("arc079f.out","w",stdout);
	#endif
	scanf("%d",&n);
	for (int x,i=1;i<=n;i++) scanf("%d",&x),add(x,i);
	for (int i=1;i<=n;i++) if (!vis[i]) dfs(i);
	for (int i=1;i<=n;i++) if (onring[i]) dfs2(i);
	
	int o=a[stk[1]];
	for (int i=2;i<=top;i++) a[stk[i]]=calc2(stk[i]);
	if (a[stk[top]]!=o) {puts("POSSIBLE");return 0;}
	bac[o]++;a[stk[1]]=calc1(stk[1]);bac[o]--;
	for (int i=2;i<=top;i++) a[stk[i]]=calc2(stk[i]);
	if (a[stk[top]]==o) {puts("POSSIBLE");return 0;}
	puts("IMPOSSIBLE");
	return 0;
}

Measured memory_bytes: 11392
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef long double ld;
 
int main(){
    ll x; 
    cin >> x;
    ll a=100; 
    ll k=0;
    while(x>a){
        
        a += a/100;
        k++;
    }
    cout << k << endl;
}

Measured memory_bytes: 3636
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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; }

const int INF = 100000;

int h, w;
char field[105][105];
int dp[105][105][2];

int dfs(int y, int x, int seq){
    if(y == h-1 && x == w-1) return 0;
    if (dp[y][x][seq] != -1) return dp[y][x][seq];
    int res = INF;
    if(x+1 < w){
        if(field[y][x+1] == '#'){
            if(seq) chmin(res, dfs(y, x+1, 1));
            else chmin(res, dfs(y, x+1, 1) + 1);
        }
        else{
            chmin(res, dfs(y, x+1, 0));
        }
    }
    if(y+1 < h){
        if(field[y+1][x] == '#'){
            if(seq) chmin(res, dfs(y+1, x, 1));
            else chmin(res, dfs(y+1, x, 1) + 1);
        }
        else{
            chmin(res, dfs(y+1, x, 0));
        }
    }
    return dp[y][x][seq] = res;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
    cin >> h >> w;
    rep(i,h)rep(j,w) cin >> field[i][j];
    memset(dp, -1, sizeof(dp));
    int ans;
    if(field[0][0] == '#') ans = dfs(0, 0, 1)+1;
    else ans = dfs(0, 0, 0);
    cout << ans << endl;
	return 0;
}

Measured memory_bytes: 384
"use strict";
function I(t, i) {
  (this._s = t.split("\n")), (this._c = 0), (this._l = 0), (this._f = i || Number);
}
(I.prototype.a = function(t) {
  var i = this._s[this._l];
  if (i) {
    var s = i.trim().split(" "),
      h = s[this._c];
    return this._c++, s.length === this._c && ((this._c = 0), this._l++), t ? t(h) : this._f(h);
  }
}),
  (I.prototype.l = function(t) {
    var i = this._s[this._l];
    if (i) return (this._c = 0), this._l++, i.split(" ").map(t || this._f);
  }),
  (module.exports = I);

function main(input) {
  var o = new I(input);

  const A = o.a();
  const B = o.a();
  const C = o.a();

  const container1Remaining = A - B;
  const container2Total = C;

  const container2Left = container2Total > container1Remaining ? container2Total - container1Remaining : 0;

  console.log(container2Left);
}

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


Measured memory_bytes: 11468
#include<stdio.h>
#include<math.h>
#include<stdlib.h>


#define N 3
#define M 9
#define MAX 10000000


 struct Puzzle{
  int f[M];
  int path;
  int space;
};

typedef struct Puzzle puzzle;

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

puzzle Q[MAX];
int head,tail,ori[MAX];

int empty(void);
void enqueue(puzzle );
puzzle dequeue(void);
int cheak(puzzle );
int isTarget(puzzle );
int bfs(puzzle p);

int main()
{
  int i,x;
  puzzle p;

  for(i=0;i<M;i++){
    scanf("%d",&p.f[i]);
    if(p.f[i]==0){
      p.f[i]=M;
      p.space=i;
    }
  }

  x=bfs(p);

  printf("%d\n",x);

  return 0;

}

int empty()
{
  return head==tail;
}

void enqueue(puzzle x)
{
  Q[tail]=x;
  tail=(tail+1)%MAX;
}

puzzle dequeue()
{
  puzzle x;

  x=Q[head];
  head=(head+1)%MAX;

  return x;

}

int cheak(puzzle p)
{
  int i,j,fac,count,num=0;

  for(i=0,fac=1;i<M;fac*=++i){
    for(j=0,count=0;j<i;j++)
      if(p.f[j]<p.f[i]) count++;
      num+=count*fac;
}

  return num;

}

int isTarget(puzzle p)
{
  int i;

  for(i=0;i<M;i++)
    if(p.f[i]!=(i+1)) return 0;
    return 1;
}

int bfs(puzzle p)
{
  int x,y,tx,ty,r,temp;
  puzzle u, v;

  p.path=0;
  enqueue(p);
  ori[cheak(p)]=1;

  while(!empty()){
    u=dequeue();
    if(isTarget(u)) return u.path;
    x=u.space/N;
    y=u.space%N;

    for(r=0;r<4;r++){
      tx=x+dx[r];
      ty=y+dy[r];
      if(tx<0 || tx>=N || ty<0 || ty >= N) continue;
      v=u;
      temp=v.f[u.space];
      v.f[u.space]=v.f[tx*N+ty];
      v.f[tx*N+ty]=temp;
      v.space=tx*N+ty;
      if(!ori[cheak(v)]){
	       ori[cheak(v)]=1;
	       v.path++;
	       enqueue(v);
      }
    }
  }

  return -1;

}



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

#define debug(x) cerr << x << " = "(x) << endl;
#define ll long long
#define rep(i,x,y) for(ll i=x;i<y;i++)
#define rel(i,x,y) for(int i=x-1;i>=y;i--)
#define all(x) x.begin(),x.end()

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll n,k; cin >> n >> k;
    vector<pair<int,int>> a(n); //prev,next
    rep(i,0,n){
        a[i].first = -1;
        cin >> a[i].second;
        a[i].second--;
    }
    int locate=0;
    int next;
    while(a[a[locate].second].first==-1){
        next = a[locate].second;
        a[next].first = locate;
        locate = next;
    }
    int tmp = a[locate].second;
    int cnt=1;
    while(locate!=tmp){
        cnt++;
        tmp = a[tmp].second;
    }
    int cocomade=0;
    tmp = 0;
    while(tmp != locate){
        cocomade++;
        tmp = a[tmp].second;
    }
    //cout << cnt << endl;
    //cout << locate << endl;
    //cout << cocomade << endl;
    if(k>=cocomade)k -= cocomade; //locateまで移動
    else{
        tmp = 0;
        rep(i,0,k){
            tmp = a[tmp].second;
        }
        cout << tmp+1 << endl;
        return 0;
    }
    k %= cnt;
    tmp = locate;
    rep(i,0,k){
        tmp = a[tmp].second;
    }
    cout << tmp+1 << endl;
}

Measured memory_bytes: 4784
#include <bits/stdc++.h>
using namespace std;
//#define cerr if (false) cerr
#define db(x) cerr << #x << "=" << x << endl
#define db2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define db3(x, y, z) cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl
#define dbv(v) cerr << #v << "="; for (auto _x : v) cerr << _x << ", "; cerr << endl
#define dba(a, n) cerr << #a << "="; for (int _i = 0; _i < (n); ++_i) cerr << a[_i] << ", "; cerr << endl
template <typename A, typename B>
ostream& operator<<(ostream& os, const pair<A, B>& x) {
	return os << "(" << x.first << "," << x.second << ")";
}
typedef long long ll;
typedef long double ld;
int main() {
	int x;
	scanf("%d", &x);
	vector<int> can(x + 1);
	can[0] = 1;
	for (int i = 0; i < 6; ++i) {
		for (int j = 100 + i; j <= x; ++j) {
			can[j] |= can[j - 100 - i];
		}
	}
	printf("%d\n", can[x]);
}


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

//typedef
//------------------------------------------
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int MOD = 1000000007;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//main code

int main(int argc, char const* argv[])
{
	int n,m;
	cin >> n >> m;
	VL a(n), b(m);
	set<LL> an,o;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		o.insert(a[i]);
	}
	for (int i = 0; i < m; i++) {
		cin >> b[i];
		o.insert(b[i]);
	}
	b.push_back(MOD);
	for (int i = 0; i < n; i++) {
		if (*lower_bound(ALL(b),a[i]) == a[i]) {
			an.insert(a[i]);
		};
	}

	cout << an.size() << " " << o.size() << endl;
	for (auto&& var : an) {
		cout << var << endl;
	}
	for (auto&& var : o) {
		cout << var << endl;
	}
	return 0;
}



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


int main() {
    long long a, b, k;
    cin >> a >> b >> k;
    if (a >= k) {
        cout << a - k << " " << b << endl;
    } else {
        cout << 0 << " " << max((long long int)0, b - k + a) << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	int n, cnt = 0;
	cin >> n;

	vector<int> p(n);
	for(int i=0;i<n;i++){
		cin >> p.at(i);
		if(i!=p.at(i)-1) cnt++;
	}

	if(cnt==0 || cnt==2) cout << "YES" << endl;
	else cout << "NO" << endl;
}

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

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

    int h, w, items;
    cin >> h >> w >> items;
    vector<vector<int>> grid(h, vector<int>(w));

    while (items--){
    	int r, c, val;
    	cin >> r >> c >> val;
    	--r, --c;
    	grid[r][c] = val;
    }

    vector<vector<vector<long long>>> dp(h, vector<vector<long long>>(w, vector<long long>(4, -1)));
    for (int row = 0; row < h; ++row){
    	for (int col = 0; col < w; ++col){
    		if (row == 0 && col == 0){
    			dp[row][col][0] = 0;
    			dp[row][col][1] = grid[row][col];
    		}
    		else{
    			if (row){
    				dp[row][col][0] = *max_element(dp[row - 1][col].begin(), dp[row - 1][col].end());
    				dp[row][col][1] = dp[row][col][0] + grid[row][col];
    			}
    			for (int k = 0; k <= 3; ++k){
    				if (col){
    					dp[row][col][k] = max(dp[row][col][k], dp[row][col - 1][k]);
    					if (k){
    						dp[row][col][k] = max(dp[row][col][k],
    							dp[row][col - 1][k -1] + grid[row][col]);
    					}
    				}
    			}
    		}
    	}
    }

    cout << *max_element(dp[h - 1][w - 1].begin(), dp[h - 1][w - 1].end()) << '\n';
    return 0;
}

Measured memory_bytes: 671596
w,h,n=map(int,input().split())
t=[[int(i) for i in input().split()]for i in range(n)]
x_1,x_2,y_1,y_2=0,w,0,h
for i in range(n):
    if t[i][2]==1:
        ans=t[i][0]
        x_1=max(ans,x_1)
    elif t[i][2]==2:
        ans_2=t[i][0]
        x_2=min(ans_2,x_2)
    elif t[i][2]==3:
        ans_3=t[i][1]
        y_1=max(ans_3,y_1)
    elif t[i][2]==4:
        ans_4=t[i][1]
        y_2=min(ans_4,y_2)
if x_1<x_2 and y_1<y_2:
    print(abs(x_2-x_1)*abs(y_2-y_1))
else:
    print(0)


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

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		Main me = new Main();
		System.out.println(me.fact(Integer.parseInt(in.readLine())));
	}
	private long fact(long n){
		return (n==0)?1:n*fact(n-1);
	}
}

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

int main(){
    int n; cin >> n;
    int MIN = 200010;
    int cnt = 0;
    rep(i, n){
        int tmp;
        cin >> tmp;
        MIN = min(MIN, tmp);
        if(MIN >= tmp){
            cnt++;
        }

    }
    cout << cnt << endl;
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
typedef long long ll;
long long mod = 1e9 + 7;
const int iINF = 0x3f3f3f3f;
const long long INF = 1LL << 60;
using namespace std;
using pint = pair<int, int>;

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;
}

int main()
{
  int n, k;
  cin >> n >> k;
  vector<ll> left, right;

  rep(i, n)
  {
    int x;
    cin >> x;
    if (x <= 0)
      left.push_back(-x);
    else
      right.push_back(x);
  }

  reverse(left.begin(), left.end());

  ll ans;

  if (right.size() >= k)
  {
    ans = right[k - 1];
  }
  else
  {
    ans = iINF;
  }

  rep(i, left.size())
  {
    if (k - i - 1 > right.size())
      continue;

    if (i > k - 1)
      continue;

    if (i == k - 1)
    {
      chmin(ans, left[i]);
      continue;
    }

    chmin(ans, left[i] + right[k - i - 2] + min(left[i], right[k - i - 2]));
  }

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


Measured memory_bytes: 4584
pattys_of_level = 50.times.inject([1]){|acc, it| acc.push(acc.last * 2 + 1)}
height_of_level = 50.times.inject([1]){|acc, it| acc.push(acc.last * 2 + 3)}

define_method(:pattys_of_height_and_level){|lv, h|
    if h == 0 
        return 0
    end

    if h == height_of_level[lv]
        return pattys_of_level[lv]
    end

    mid_patty = height_of_level[lv - 1] + 2

    if h < mid_patty
        return pattys_of_height_and_level(lv - 1, h - 1)
    elsif h == mid_patty
        return pattys_of_level[lv - 1] + 1
    else
        return pattys_of_level[lv - 1] + 1 + pattys_of_height_and_level(lv - 1, h - mid_patty)
    end
}

n, x = gets.split.map(&:to_i)
puts pattys_of_height_and_level(n, x)



Measured memory_bytes: 3836
package main

import (
	"fmt"
	"sort"
)

func main() {
	var N, x int
	fmt.Scan(&N, &x)
	a := make([]int, N)
	for i := range a {
		fmt.Scan(&a[i])
	}
	sort.Ints(a)
	cnt := 0
	for i, v := range a {
		if v > x {
			continue
		} else if i == N-1 && v != x {
			break
		} else {
			cnt++
			x -= v
		}
	}
	fmt.Println(cnt)
}


Measured memory_bytes: 512
#include <stdio.h>
#include <math.h>

//#define getchar_unlocked()  getchar()
int in()
{
	int n = 0, c = getchar_unlocked();
	do n = 10*n + (c & 0xf), c = getchar_unlocked(); while (c >= '0');
	return n;
}

int main()
{
	int N, i, a, r, ans;

	N = in();
	ans = 0;
	while (N--) {
		a = in();
		if (a == 2) ans++;
		else if (a&1) {
			r = (int)sqrt(a);
			for (i = 3; ; i+=2) {
				if (i > r) { ans++; break; }
				if (a%i == 0) break;
			}
		}
	}
	printf("%d\n", ans);
	return 0;
}



Measured memory_bytes: 2060
#include <bits/stdc++.h>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i,a,b) for (ll i=(a);i<(ll)b; i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define INF 1000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll,ll> p;
const int MOD = 1000000007;

// vector<p> cut(M);
// cut[i].second
// cut[i].first;
// REP(i,M){
//     int a,b;cin>>a>>b;
//     cut[i] = make_pair(b,a);//last first の順番
// }
// for(int i=0; i<N;i++){
// }
// sort(cut.begin(),cut.end()); //sort
// char '' str ""
int main(void)
{
    double a, b;
    cin>>a>>b;
    a /= INF;
    b /= INF;
    if(a-b>0){
      cout<<"GREATER"<<endl;
      return 0;
    }else if(a-b<0){
      cout<<"LESS"<<endl;
      return 0;
    }

      cout<<"EQUAL"<<endl;



    return 0;
}


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

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

    int N;
    cin >> N;

    vector<pair<int, int> > X(N);

    for(int i = 0; i < N; i++) {
        int x;
        cin >> x;
        X[i] = make_pair(x, i);
    }

    sort(X.begin(), X.end());

    int front = X[N / 2 - 1].first;
    int back = X[N / 2].first;

    vector<int> ans(N);

    for(int i = 0; i < N; i++) {
        if(i < N / 2) {
            ans[X[i].second] = back;
        } else {
            ans[X[i].second] = front;
        }
    }

    for(int i = 0; i < N; i++) {
        cout << ans[i] << endl;
    }
}

Measured memory_bytes: 4608
#include <bits/stdc++.h>
using namespace std;
int n,m,x,y,sum;
int is[100005],a[100005];
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++) a[i]=1;
	is[1]=1;
	for(;m--;)
	{
		scanf("%d%d",&x,&y);
		if(is[x]&&a[x]==1) is[y]=1,is[x]=0;
		else if(is[x]) is[y]=1;
		a[x]--,a[y]++;
	}
	for(int i=1;i<=n;i++)
		if(a[i]&&is[i])
			sum++;
	printf("%d",sum);
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <cstdlib>  
#include <algorithm>
#include <string>

using namespace std;
 
int main() {
    int x,y;
    cin>>x>>y;
    for(int i = 0;i<=x;i++){
      int j = x-i;
      if(i*2+j*4 == y){
        cout<<"Yes";
        return 0;
      }
    }
    cout<<"No";
    return 0;
}

Measured memory_bytes: 3044
// 未解決

#include <bits/stdc++.h>

#include <iostream>
using namespace std;

#define EACH(i, a) for (auto &&i : a)
#define FOR(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define RFOR(i, a, b) for (int i = (int)b - 1; i >= (int)a; --i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) FOR(i, 1, int(n) + 1)
#define RREP(i, n) RFOR(i, 0, n)
#define RREPS(i, n) RFOR(i, 1, int(n) + 1)
#define ALL(x) (x).begin(), (x).end()
#define MEMSET(v, h) memset((v), h, sizeof(v))
#define debug(x) cout << #x << ": " << x << endl

#define pb push_back
#define mp make_pair
#define F first
#define S second

#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define INF (1L << 30)
#define MOD (1000000007)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

template <class T>
void pv(T a, T b) {
  for (T i = a; i != b; ++i) cout << *i << " ";
  cout << endl;
}
template <class T>
void pvp(T a, T b) {
  for (T i = a; i != b; ++i)
    cout << "(" << i->first << ", " << i->second << ") ";
  cout << endl;
}
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
int in() {
  int x;
  scanf("%d", &x);
  return x;
}

using ll = long long;
#define int ll

//**********

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

  int n, k;
  cin >> n >> k;
  int d[100];
  int a[100][100];
  int ans[100];
  MEMSET(ans, 0);
  REP(i, n) {
    cin >> d[i];
    REP(j, d[i]) {
      cin >> a[i][j];
      ans[a[i][j] - 1] = 1;
    };
  }
  int anss = 0;
  REP(i, n) {
    if (ans[i] == 0) {
      anss += 1;
    }
  }

  cout << anss << endl;

  return 0;
};


Measured memory_bytes: 3684
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0;i<ll(n);i++)
int main() {
    string s;
    cin >> s;
    vector<int>v(s.size(), 0);
    s = s+"R";
    int r, l;
    r = l = 0;
    int pr, pl;
    rep(i, s.size() - 1) {
        if (s[i] == 'R'){
            r++;
            if (s[i+1] == 'L') {
                pr = i;
                pl = i+1;
            }
        }else if (s[i] == 'L'){
            l++;
            if (s[i + 1] == 'R') {
                v[pl] = r/2 + l - l/2;
                v[pr] = l/2 + r - r/2;
                r = l = 0;
            }
        }
        
    }
    rep(i, s.size() - 2) cout << v[i] << ' ';
    cout << v[s.size() - 2] << endl;
    return 0;
}


Measured memory_bytes: 3980
#include<iostream>
#include <fstream>
#include <stdio.h>
#include <stdlib.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include<string>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#include<sstream>
#include<algorithm>
#include<map>
#include<complex>
using namespace std;


#define li			long long int
#define rep(i,to)	for(int i=0;i<((int)(to));i++)
#define repp(i,start,to)	for(int i=(int)(start);i<((int)(to));i++)
#define pb			push_back
#define sz(v)		((li)(v).size())
#define bgn(v)		((v).begin())
#define eend(v)		((v).end())
#define allof(v)	(v).begin(), (v).end()
#define dodp(v,n)		memset(v,(li)n,sizeof(v))
#define bit(n)		(1ll<<(li)(n))
#define mp(a,b)		make_pair(a,b)
#define rin	rep(i,n)
#define EPS 1e-10
#define ETOL 1e-8
#define MOD 1000000007
#define p2(a,b)		cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)		cout<<a<<"\t"<<b<<"\t"<<c<<endl


string sum(string a, string b){
	string res="";
	if(sz(a)<sz(b))swap(a,b);
	li n=sz(a);
	li nb=sz(b);
	rep(i,n-nb)b="0"+b;
	li c=0;
	//p2(a,b);
	for(li i=n-1; i>=0; i--){
		li now=c+(a[i]-'0')+(b[i]-'0');
		res=(char)(now%10+'0')+res;
		c=now/10;
	}
	if(c>0)res=(char)(c+'0')+res;
	if(sz(res)>80)return "overflow";
	return res;
}

int main(){
	li n;
	cin>>n;
	rin{
		string a,b;
		cin>>a>>b;
		cout<<sum(a,b)<<endl;
	}
	
	return 0;
}

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

using namespace std;
typedef long long ll;
ll dp[520][100001];
ll n, q, v[300001], w[300001];

ll dfs(ll x, ll y, ll vv, ll ww) {
  if (ww > y) {
    return 0LL;
  }
  if (x < (1 << 8)) {
    return dp[x][y - ww] + vv;
  }
  return max(dfs(x / 2, y, vv + v[x], ww + w[x]), dfs(x / 2, y, vv, ww));
}

int main() {
  ll vv, l;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> v[i + 1] >> w[i + 1];
  }
  for (ll i = 1LL; i <= min(n, (1LL << 8)); i++) {
    for (ll j = 100000LL; j >= 0; j--) {
      dp[i][j] = dp[i / 2LL][j];
      if (j - w[i] >= 0) {
        dp[i][j] = max(dp[i][j], dp[i / 2][j - w[i]] + v[i]);
      }
    }
    for (ll j = 1; j <= 100000; j++) {
      dp[i][j] = max(dp[i][j], dp[i][j - 1]);
    }
  }
  cin >> q;
  for (int i = 0; i < q; i++) {
    cin >> vv >> l;
    cout << dfs(vv, l, 0, 0) << endl;
  }
}

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

int main(){
  int h,w;
  cin >> h >> w;
  vector<vector<char>>probe(h,vector<char>(w));
  for (int i = 0; i < h ; i++){
    for (int j = 0; j < w; j++){
      cin >> probe.at(i).at(j);
    }
  } 
  vector<bool>row(h, false);
  vector<bool>line(w, false);
    for (int i = 0; i < h ; i++){
    for (int j = 0; j < w; j++){
      if (probe.at(i).at(j) == '#'){
        row.at(i) = true;
        line.at(j) = true;
      }
    }
  }
    for (int i = 0; i < h ; i++){
      if(row.at(i)){
        for (int j = 0; j < w; j++){
          if (line.at(j)){
            cout << probe.at(i).at(j) ;
          }
        }
        cout << endl;
      }
    
            
    }
    
}
      
                          

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

int main(){
    string s, t, u;
    cin >> s >> t;
    int a, b;
    cin >> a >> b;
    cin >> u;
    if(s == u){
        cout << a-1 << ' ' << b << endl;
    }
    else{
        cout << a << ' ' << b-1 << endl;
    }
}

Measured memory_bytes: 256