akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
typedef pair<double, string> P;
bool comp(P a, P b) {
  if(fabs(a.first - b.first) <= 0.00000001) {
    return a.second <= b.second;
  }
  return a.first >= b.first;
}
int main()
{
  int n;
  while(cin>>n,n) {
    vector<P> v(n);
    FOR(i,0,n) {
      string L; cin >> L;
      ll p,a,b,c,d,e,f,s,m;
      cin>>p>>a>>b>>c>>d>>e>>f>>s>>m;
      ll t = a + b + c + (d + e) * m;
      double buy = (double)(m * f * s - p) / t;
      v[i] = P(buy, L);
    }
    sort(v.begin(), v.end(), comp);
    FOR(i,0,n) cout << v[i].second << endl;
    puts("#");
  }
  return 0;
}

Measured memory_bytes: 3140
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <functional>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

const int INF = 1e9;

int main() {
    int h, w;
    cin >> h >> w;
    vector<string> s(h);
    REP(i,h) cin >> s[i];
    int n = h * w;
    VVI d(n, VI(n, INF));
    REP(i,n) d[i][i] = 0;
    REP(i,h) REP(j,w){
        if (s[i][j] == '#') continue;
        int p = i * w + j;
        if (i < h - 1 && s[i + 1][j] != '#'){
            int q = (i + 1) * w + j;
            d[p][q] = d[q][p] = 1;
        }
        if (j < w - 1 && s[i][j + 1] != '#'){
            int q = i * w + j + 1;
            d[p][q] = d[q][p] = 1;
        }
    }
    REP(k,n) REP(i,n) REP(j,n) chmin(d[i][j], d[i][k] + d[k][j]);
    int ans = 0;
    REP(i,n) REP(j,n) if (d[i][j] != INF) chmax(ans, d[i][j]);
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
 
int main() {

int a,b;

  cin >> a >> b;

  int n;

  if((a+b)%2==0){
    n=(a+b)/2;
  }else
  {
    n=(a+b)/2+1;
  }
  
  
  
  cout << n << endl;

}

Measured memory_bytes: 256
#pragma GCC optimization_level 3
#include <iostream>
#include <cstdio>
#include <unordered_map>
#include <chrono>
using namespace std;
typedef long long ll;

ll i, j, k;
ll a, b;
double sec;

ll n;
ll arr[100005];
unordered_map<ll, ll> x;
unordered_map<ll, bool> mp;

int main()
{
    
    scanf("%lld %lld", &n, &arr[0]);
    for (i = 1; i < n; i++) {
        scanf("%lld", &arr[i]);
        x[arr[i]]++;
    }

    auto s = chrono::system_clock::now();
    auto t = s;
    for (i = 1; i < n ; i++) {
        t = chrono::system_clock::now();
        if (chrono::duration_cast<chrono::milliseconds>(t - s).count() >= 1900) {
            puts("No");
            return 0;
        }
        
        if (mp[arr[i]]) continue;
        
        unordered_map<ll, ll> tmp = x;

        a = arr[0];
        b = arr[i];
        tmp[b]--;

        for (j = 2; j < n; j++) {
            ll f = a ^ b;

            if (tmp[f]) {
                tmp[f]--;
                a = b;
                b = f;
            }
            else {
                mp[arr[i]] = true;
                break;
            }
        }

        if (!(j ^ n)) {
            if (arr[0] == (a ^ b) &&
                arr[i] == (b ^ arr[0])) {
                puts("Yes");
                return 0;
            }
            else {
                mp[arr[i]] = true;
            }
        }
    }

    puts("No");

    return 0;
}   


Measured memory_bytes: 7716
#include<stdio.h>

int main(void)
{
	int X, Y;
	scanf("%d %d", &X, &Y);

	int num = X % Y;
	if (num != 0)
	{
		printf("%d", X);
	}
	if (X == Y || Y==1 || num == 0)
	{
		printf("-1");
	}
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 10000000000000000

int dfs(vector<vector<int>> &E,int now,int p){
	bool f = true;
	int ret = 0;
	for(int i=0;i<E[now].size();i++){
		int to = E[now][i];
		if(to==p)continue;
		int t = dfs(E,to,now);
		
		ret += t;
		if(t==0){
			if(f)f=false;
			else ret++;
		}
	}
	return ret;
}

template <typename T,typename F0,typename F1>
struct rerooting{
	F0 func0;
	F1 func1;
	T init_value;
	
	vector<T> v;
	vector<T> ans;
	vector<bool> visited;
	
	rerooting(vector<vector<int>> &E,F0 f0,F1 f1,T iv):func0(f0),func1(f1){
		init_value = iv;
		v.resize(E.size());
		ans.resize(E.size());
		visited.resize(E.size(),false);
		for(int i=0;i<E.size();i++){
			if(visited[i])continue;
			dfs(E,i,-1);
			redfs(E,i,-1,init_value);
		}
	}
	
	void dfs(vector<vector<int>> &E,int now,int p){
		v[now] = init_value;
		for(int i=0;i<E[now].size();i++){
			int to = E[now][i];
			if(to==p)continue;
			dfs(E,to,now);
			v[now] = func0(v[now],v[to]);
		}
		v[now] = func1(v[now],now,p);
		visited[now]=true;
	}
	
	void redfs(vector<vector<int>> &E,int now,int p,T pv){
		vector<T> S(E[now].size(),init_value);
		if(S.size()>1){
			for(int i=S.size()-2;i>=0;i--){
				int to = E[now][i+1];
				T x = v[to];
				if(to==p)x = pv;
				S[i] = func0(x,S[i+1]);
			}
		}
		
		T temp = init_value;
		for(int i=0;i<E[now].size();i++){
			int to = E[now][i];
			if(to!=p){
				redfs(E,to,now,func1(func0(temp,S[i]),now,to));
				temp = func0(temp,v[to]);
			}
			else{
				temp = func0(temp,pv);
			}
		}
		ans[now] = func1(temp,now,p);
	}
	
};
	
		
int main(){
	
	int N;
	cin>>N;
	
	vector<vector<int>> E(N,vector<int>());
	vector<int> cnt(N,0);
	
	for(int i=0;i<N-1;i++){
		int a,b;
		cin>>a>>b;
		E[a].push_back(b);
		E[b].push_back(a);
		cnt[a]++;
		cnt[b]++;
	}
	
	auto f0 = [](pair<int,int> a,pair<int,int> b){
		pair<int,int> ret(a.first+b.first,a.second+b.second);
		
		return ret;
	};
	
	auto f1 = [](pair<int,int> a,int ind,int p){
		a.first += max(0,a.second-1);
		if(a.first==0)a.second = 1;
		else a.second = 0;
		return a;
	};
	
	rerooting<pair<int,int>,decltype(f0),decltype(f1)> rr(E,f0,f1,{0,0});
	
	int ans = 1000000;
	
	for(int i=0;i<N;i++){
		if(cnt[i]==1){
			ans = min(ans,rr.ans[i].first+1);
		}
	}
	
	cout<<ans<<endl;
	
	
	return 0;
}

Measured memory_bytes: 18560
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {
	private static final FastIn in = new FastIn();
	private static final PrintWriter out = new PrintWriter(System.out);
	
	public static void main(String[] args) {
		Solver sol = new Solver();
		sol.solve();
		out.close();
	}
	private static final class Solver {
		public void solve() {
			long[] a = new long[2];
			long[] b = new long[2];
			for (int i = 0; i < 2; ++i) a[i] = in.nextInt();
			for (int i = 0; i < 2; ++i) b[i] = in.nextInt();
			long ans = Long.MIN_VALUE;
			for (int i = 0; i < 2; ++i)
				for (int j = 0; j < 2; ++j) {
					ans = Math.max(ans, a[i] * b[j]);
				}
			out.println(ans);
		}
	}
	private static final class FastIn {
		private BufferedReader br;
		private StringTokenizer st;
		public FastIn() {
			br = new BufferedReader(new InputStreamReader(System.in), 1 << 20);
			st = null;
		}
		public String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return st.nextToken();
		}
		public int nextInt() {
			return Integer.parseInt(next());
		}
	}
}

Measured memory_bytes: 34844
n,X = map(int, input().split())
x = list(map(int, input().split()))
if n == 1:
    print(abs(X-x[0]))
    exit()

def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a%b)

x = x + [X]
x.sort()
ans = x[1] - x[0]

for i in range(1,n):
    ans = gcd(ans, x[i+1] - x[i])
print(ans)

Measured memory_bytes: 14252
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
A = LIST()
B = [i for i in range(1, N + 1)]
C = [0] * N

r = 0
ans = 0
while r < N:
    if A[r] == r + 1:
        ans += 1
        r += 1
    r += 1
print(ans)


exit()
for i in range(N):
    if A[i] == B[i]:
        C[i] = 1

# for i in range(N-1):
r = 0
pre_is_one = False

# 1の連続数を数える
conti_one = []
# print(C)
while r < N:
    conti = 0
    while C[r] == 1:
        conti += 1
        r += 1
        # print(r)
        if r >= N:
            break

    conti_one.append(conti)
    # if C[r] == 1:
    #     ans += 1
    #     while C[r]
    #     r += 1
    #     if pre_is_one == True:
    #         ans -= 1
    #     pre_is_one = True
    if r < N and C[r] == 0:
        r += 1
    
# print(ans)
# print(conti_one)
ans = 0
for c in conti_one:
    # print(c)
    if c == 1:
        ans += 1
    elif c > 1:
        ans += c - 1
print(ans)

    

Measured memory_bytes: 15956
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int window = Integer.parseInt(sc.next());
    int curtain = Integer.parseInt(sc.next());
    if(window - 2 * curtain > 0) {
      System.out.println(window - 2 * curtain);
    } else {
      System.out.println(0);
    }
  }
}


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

int main() {
    int N;
    while (cin >> N, N) {
        vector<int> v(N);
        for (auto& i : v) cin >> i;
        int med = N / 2;
        sort(v.begin(), v.end());
        int ans = -1;
        for (int i = 0; i < N; i++) {
            if (i + med < N && v[i] == v[i+med]) {
                ans = v[i];
                break;
            }
        }
        if (ans < 0) cout << "NO COLOR" << endl;
        else cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 8260
/*我是菜鸡
╭╮＿＿╭╭╭╭╭＿＿╭╮
│　　　　　　　　　　　│　
│　　　　　　　　　　　│　
│　●　╭———╮　●　│　
│≡　　│●　●│　　≡│
│　　  ╰———╯　　　│
╰——┬○————┬—○╯
*/
#include<bits/stdc++.h>
#define _for(i,a,b) for(int i = (a);i<(b);++i)
#define cci ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const int maxn = 1000 + 5;
int ans[maxn][maxn];
int main() {
	cci;
	//ifstream cin("E:\\acm dream\\in.txt");
	//ofstream cout("E:\\acm dream\\out.txt");
	int n, m;
	while (cin >> n >> m) {
		if (n == m)cout << "Yes\n";
		else cout << "No\n";
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define range(a) (a).begin(),(a).end()
#define print(A,n) rep(i,0,n){cout<<(i ? " ":"")<<A[i];}cout<<endl;
#define pprint(A,m,n) rep(j,0,m){print(A[j],n);}
const long mod=1e9+7;
const int size=1e5;
const int inf=1e9;
long fact[size];
long inv(long x){// p is prime
	if(x==0) return 0;
	int i=0;long res=1;
	while((mod-2)>=(1<<i)){
		if((mod-2)&(1<<i)) (res*=x)%=mod;
		i++; x=x*x%mod;
	}return res;
}
void calc(int n){
    fact[0]=1;
    rep(i,1,n+1){
        fact[i]=(fact[i-1]*i)%mod;
    }return;
}
long modcomb(long n,long r){//nCr mod p
	if(n<r) return 0;
    long res=(fact[n]*inv(fact[n-r]))%mod;
    return (res*inv(fact[r]))%mod;
}
int main(){
	long N,K;cin>>N>>K;
	long A[N];
	rep(i,0,N) cin>>A[i];
	sort(A,A+N);
    rep(i,0,N) (A[i]+=mod)%=mod;
	long ans=0,res;
    calc(N);
	rep(i,0,N){
		res=(modcomb(i,K-1)-modcomb(N-1-i,K-1)+mod)%mod;
		(res*=A[i])%=mod;
		(ans+=res)%=mod;
	}cout<<ans<<endl;
}

Measured memory_bytes: 1792
g=gets.split
x=[0,2,5,3]
y=[0,4,5,1]
n=gets.split
m=->r,d{r.map{|i|n[i]}.rotate(d).map.with_index{|v,i|n[r[i]]=v}}
m[rand(2)>0?x:y,rand(2)>0?1:-1]until g[0..1]==n[0..1]
puts g[2]==n[2]?:Yes: :No

Measured memory_bytes: 6136
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
  int n,m,num,sum=0,dec=0;
  vector<int> x;
  cin >> n >> m;
  for(int i=0;i<m;i++){
    cin >> num;
    x.push_back(num);
  }
  if(n>=m){
    cout << 0 << endl;
  }else{
  sort(x.begin(),x.end());
  for(int i=0;i<m-1;i++){
    x[i]=x[i+1]-x[i];
    sum+=x[i];
  }
  x[m-1]=-1000000;
  sort(x.begin(),x.end());
  for(int i=0;i<n-1;i++){
    dec+=x[m-1-i];
  }
  cout<<sum-dec<<endl;
  }
  }


Measured memory_bytes: 892
#define _DEBUG
#include "bits/stdc++.h"
#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0,a1,a2,a3,a4,x,...) x
#define debug_1(x1) cout<<#x1<<": "<<x1<<endl
#define debug_2(x1,x2) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<endl
#define debug_3(x1,x2,x3) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<endl
#define debug_4(x1,x2,x3,x4) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<endl
#define debug_5(x1,x2,x3,x4,x5) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<", "#x5<<": "<<x5<<endl
#ifdef _DEBUG
#define debug(...) CHOOSE((__VA_ARGS__,debug_5,debug_4,debug_3,debug_2,debug_1,~))(__VA_ARGS__)
#else
#define debug(...)
#endif
#define rep(index,num) for(int index=0;index<(int)num;index++)
#define rep1(index,num) for(int index=1;index<=(int)num;index++)
#define brep(index,num) for(int index=(int)num-1;index>=0;index--)
#define brep1(index,num) for(int index=(int)num;index>0;index--)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=(ll)1e+18+1;
int INF=1e+9+1;
struct UnionFind{
  vector<int> par;
  vector<int> sizes;
  UnionFind(int n) : par(n), sizes(n, 1) {
    rep(i,n) par[i] = i;
  }
  int root(int x) {
    if (x == par[x]) return x;
    return par[x] = root(par[x]);
  }
  void unite(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y) return;
    if (sizes[x] < sizes[y]) swap(x, y);
    par[y] = x;
    sizes[x] += sizes[y];
  }
  bool same(int x, int y) {
    return root(x) == root(y);
  }
  int size(int x) {
    return sizes[root(x)];
  }
};
int main(){
	int N,M;
	bool exist[701][701]={};
	scan(N>>M);
	rep(i,M){
		int a,b;
		scan(a>>b);
		a--; b--;
		exist[a][b]=exist[b][a]=1;
	}
	UnionFind uf(N*2);
	UnionFind adj(N);
	rep(i,N){
		for(int j=i+1;j<N;j++){
			if(exist[i][j]==0){
				uf.unite(i,j+N);
				uf.unite(i+N,j);
				adj.unite(i,j);
			}
		}
	}
	bool bipartite = true;
	rep(i,N){
		if(uf.same(i,N+i)) bipartite = false;
	}
	if(bipartite){
		int B[700]={},W[700]={};
		rep(i,N){
			int rt=adj.root(i);
			if(uf.same(rt,i)) B[rt]++;
			else W[rt]++;
		}
		bitset<2000> dp;
		dp.set(1000);
		rep(i,N){
			int sa=abs(B[i]-W[i]);
			if(sa){
				dp=(dp<<sa)|(dp>>sa);
			}
		}
		for(int k=1000;k<2000;k++){
			if(dp[k]){
				int K=(N-(k-1000))/2;
				int ans=K*(K-1)/2+(N-K)*(N-K-1)/2;
				prin(ans);
				return 0;
			}
		}
	}
	else{
		prin(-1);
	}
	return 0;
}


Measured memory_bytes: 4084
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <numeric>
using namespace std;
typedef long long ll;

int main(){
   int n;cin>>n;
   vector<ll> a(n+1),b(n);
   for(int i=0;i<n+1;i++)cin>>a[i];
   for(int i=0;i<n;i++)cin>>b[i];
  ll ans=0;
   for(int i=0;i<n;i++){
       if(b[i]>=a[i]){ans+=a[i];b[i]-=a[i];a[i]=0;}
       else {ans+=b[i];a[i]-=b[i];b[i]=0;}
       if(b[i]>=a[i+1]){ans+=a[i+1];b[i]-=a[i+1];a[i+1]=0;}
       else {ans+=b[i];a[i+1]-=b[i];b[i]=0;}
   }
   cout<<ans;
}


Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <iomanip>
#include <string>
#include <sstream>
#include <algorithm>
#include <map>
#include <bits/stdc++.h>

using namespace std;
#define REP(i,n) FOR(i,0,n)
#define FOR(i,a,b) for(long long i=(a),i##Len_=(b);i<i##Len_;i++)
typedef long long ll;
static const ll MOD = 1000000007;
static const ll INF = 1000000000000000000LL;

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

    if(A+B >= 10)
    {
        cout << "error" << endl;
    }
    else
    {
        cout << A+B << endl;
    }


    return 0;
}

Measured memory_bytes: 256
n,m,c = map(int, input().split())
B = list(map(int, input().split()))
A = []
for i in range(n):
    a = list(map(int, input().split()))
    A.append(a)
ans = 0
for i in range(n):
    f = 0
    for j in range(m):
        f += B[j] * A[i][j]
    f += c
    if f>0:
        ans += 1
print(ans)

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

int main(){
  int K,A,B;
  cin >> K >> A >>B;
  int i=1;
  int check = K;
  while(K*i<=1000){
    if(check>=A && check <= B) break;
    i++;
    check = K*i;
  }
  if(check>=A && check <= B) cout << "OK" << endl;
  else cout << "NG" << endl;
  
}

Measured memory_bytes: 3688
datas = $stdin.read.split("\n")
n = datas[0].to_i
a = datas[1].split(" ")
count1 = 0
for i in 0..a.count - 1 do
  while true
    if a[i].to_i % 2 == 0
      a[i] = a[i].to_i / 2
       count1 += 1
    else
      break
    end
  end
end
puts count1

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

public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String w = br.readLine();
        int sum = 0;
        while (true) {
            String line = br.readLine();
            if (line.equals("END_OF_TEXT")) {
                break;
            }
            line = line.toLowerCase();
            String[] lines=line.split(" ");
            for(String s:lines){
                if(s.contains(w)&&s.length()==w.length()){
                    sum++;
                }
            }
        }
        System.out.println(sum);
    }
}

Measured memory_bytes: 24236
import heapq
from collections import deque
import copy

def main():
    n, k = map(int, input().split())
    v = deque([int(x) for x in input().split()])

    left_plus = 0
    left_minus_count = 0
    left_minus_list = []
    
    ans = 0
    sub = 0
    minus_list = []
    minus_count = 0
    heapq.heapify(minus_list)
    for i in range(n-1, max([-1, n-k-1]), -1):
        if v[i] >= 0:
            sub += v[i]
        else:
            heapq.heappush(minus_list, -v[i])
            minus_count += 1
        while n-i+minus_count > k and minus_list:
            sub -= heapq.heappop(minus_list)
            minus_count -= 1
        if n-i+minus_count > k:
            break
        if ans < sub:
            ans = sub
    
    for i in range(min([n, k])):
        if v[i] >= 0:
            left_plus += v[i]
        else:
            left_minus_list.append(-v[i])
            left_minus_count += 1
        
        sub = left_plus
        minus_count = left_minus_count
        minus_list = copy.deepcopy(left_minus_list)
        heapq.heapify(minus_list)
        while i+minus_count+1 > k and minus_list:
            minus_count -= 1
            sub -= heapq.heappop(minus_list)
        if i+minus_count+1 <= k and ans < sub:
            ans = sub
        sub = left_plus
        minus_count = left_minus_count
        minus_list = copy.deepcopy(left_minus_list)
        heapq.heapify(minus_list)
        for j in range(n-1, max([i, n-k+i+1]), -1):
            if v[j] >= 0:
                sub += v[j]
            else:
                minus_count += 1
                heapq.heappush(minus_list, -v[j])
            while minus_count+i+n-j+1 > k and minus_list:
                minus_count -= 1
                sub -= heapq.heappop(minus_list)
            
            if i+(n-j)+minus_count+1 > k:
                break
            if ans < sub:
                ans = sub
        
        
    print(ans)

if __name__ == "__main__":
    main()

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

int main() {
	string s, t;
	cin >> s >> t;
	cout << t + s;
}



Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

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

		long N = sc.nextLong();
		long D = sc.nextLong();


		long ans = 0;
		for (long i=0; i < N; i++) {
			long x = sc.nextLong();
			long y = sc.nextLong();

			if (Math.sqrt((x * x) + (y * y)) <= D) {
				ans++;
			}
		}

		System.out.println(ans);

	}

	private static class FastScanner {
		private BufferedReader reader = null;
		private StringTokenizer tokenizer = null;

		public FastScanner(InputStream in) {
			reader = new BufferedReader(new InputStreamReader(in));
			tokenizer = null;
		}

		public String next() {
			if (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}

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

	}
}


Measured memory_bytes: 54732
#include<bits/stdc++.h>
#define int long long
#define mod 1000000007
#define trace(x) cerr<<#x<<": "<<x<<" "<<endl
#define tarce(x) cerr<<#x<<": "<<x<<" "<<endl
#define trace2(x, y) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z) cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define sa(a,n) for(int i =0 ; i<n ; i++) cin>>a[i]
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define pb push_back
#define inf 2e18
#define scan() int n; cin>>n ; int a[n]; for(int i = 0 ; i<n ; i++) cin>>a[i]
#define print(a,n) for(int i = 0 ; i < n ; i++) cout<<a[i]<<' '
#define mem(a,v) memset(a,v,sizeof(a))
#define pii pair<int,int>
#define mkp make_pair
using namespace std;
#define N 200005
int find(int n) 
{ 
    // Initialize result 
    int count = 0; 
  
    // Keep dividing n by powers of  
    // 5 and update count 
    for (int i = 5; n / i >= 1; i *= 5) 
        count += n / i; 
  
    return count; 
} 


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

      int n;
      cin >> n;
      if(n<2){
          cout << 0;
          return 0;
      }
      if(n%2==1){
          //int ans=find(n/2);
          cout << 0 << '\n';
      }
      else{
         int m=find(n/2);
         cout << m;      
        }

}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
//#define _USE_MATH_DEFINES
#include<stdio.h>
//#include<stdlib.h>
#include<math.h>
//#include<string.h>
#define P(type,x) fprintf(stdout,"%"#type"\n",x)
int main() {
	int h, m, n;
	double s, l,t,d;
	fscanf(stdin, "%d", &n);
	s = l = 0.0;
	while (n--) {
		fscanf(stdin, "%d%*c%d", &h, &m);
		l = m*6.0;
		s = h*30.0 + 30.0*m/60.0;
		if (l < s) t = l, l = s, s = t;
		d = (l - s)>180?360-l+s:l-s;
		if (d < 30.0) puts("alert");
		else if (d < 90.0) puts("warning");
		else puts("safe");
	}
	return 0;
}

Measured memory_bytes: 588
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <functional>
#include <numeric>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <limits>
#include <iomanip>
#include <bitset>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <stdio.h>

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

#define rep(i, n) for(int i = 0;i < n;i++)
const int INF = 1LL << 30;
const int MOD = 1000000007;

int main(){
    std::ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    int n; cin >> n;
    std::map<int,int> num;
    ll ans = 0;

    rep(i,n){
        int a; cin >> a;
        num[a]++;
        ans += a;
    }

    int q; cin >> q;

    rep(i,q){
        int b,c; cin >> b >> c;
        if(num[b]){
            ans += (c-b)*num[b];
            num[c] += num[b];
            num[b] = 0;
        }
        cout << ans << endl;
    }

    return 0;
}

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

const int MAX_N = 100;

int main(){
    int A, B; cin >> A >> B;
    cout << MAX_N << " " << MAX_N << endl;

    vector<vector<char> > ans(MAX_N, vector<char>(MAX_N));
    rep(i, 0, 100){
        rep(j, 0, 100){
            if(i < 50) ans[i][j] = '.';
            else ans[i][j] = '#';
        }
    }

    int cnt = 1;
    int idx_i = 0, idx_j = 0;
    while(cnt < B){
        ans[idx_i][idx_j] = '#';
        cnt++;
        if(idx_j == 98){
            idx_j = 0;
            idx_i += 2;
        }else{
            idx_j += 2;
        }
    }
    cnt = 1;
    idx_i = 99, idx_j = 0;
    while(cnt < A){
        ans[idx_i][idx_j] = '.';
        cnt++;
        if(idx_j == 98){
            idx_j = 0;
            idx_i -= 2;
        }else{
            idx_j += 2;
        }
    }
    rep(i, 0, MAX_N){
        rep(j, 0, MAX_N){
            cout << ans[i][j];
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    int n = scan.nextInt();
    int a = scan.nextInt();
    int b = scan.nextInt();
    for(int i=a;i<=b;i++){
      if (i%n == 0){
        System.out.println("OK");
        return;
      }
    }
    System.out.println("NG");

  }
}


Measured memory_bytes: 35556
#include <iostream>
#include <cmath>

using namespace std;

int main(){
  int n;
  cin >> n;
  int ans;
  if(n >= 64) ans = 64;
  else if(n >= 32) ans = 32;
  else if(n >= 16) ans = 16;
  else if(n >= 8) ans = 8;
  else if(n >= 4) ans = 4;
  else if(n >= 2) ans = 2;
  else ans = 1;
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = n-1; i >= 0; i--)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define sz(x) ((int)(x).size())
typedef long long ll;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<vector<int>>;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using VP = vector<P>;
template<typename T> void view(T e){std::cout << e << std::endl;}
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

const int inf = 1 << 30;
const ll INF = 1LL << 60;

int main(){
    int n;
    cin >> n;
    VI d(100000);
    for(int i = 1; i <= 100000; i++){
        for(int j = i; j <= 100000; j += i) d[j]++;
    }

    VI ans;
    rep(i,100000){
        if (d[i] == 2 && i % 5 == 1) ans.push_back(i);
    }

    rep(i,n) printf("%d%c", ans[i], i==n-1?'\n':' ');
    return 0;
}

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

#define fi first
#define se second
#define fin(s) freopen( s, "r", stdin );
#define fout(s) freopen( s, "w", stdout );

const long long N = 100100;
const long long Q = 100000001;
const long long mod = 1e9 + 7;
const long long MAGIC = 30;

using namespace std;

int n;
int m;
int C;
int a[N];
int f[N];
int d[N];
vector < int > v[N];

void dfs(int x)
{
        if(d[x]){
                return;
        }
        d[x] = f[a[x]] = C;
        for(int y: v[x]){
                dfs(y);
        }
}

void solve()
{
        cin >> n >> m;
        for(int i = 1; i <= n; i++){
                cin >> a[i];
        }
        for(int i = 1; i <= m; i++){
                int x, y;
                cin >> x >> y;
                v[x].push_back(y);
                v[y].push_back(x);
        }
        for(int i = 1; i <= n; i++){
                if(d[i] == 0){
                        ++C;
                        dfs(i);
                }
        }
        int ans = 0;
        for(int i = 1; i <= n; i++){
                ans += (f[i] == d[i]);
        }
        cout << ans << "\n";
}

bool mtest = false; int main()
{
        //fin("input.txt");
        //fout("output.txt");
        //fin("maze.in");
        //fout("maze.out");
        ios_base::sync_with_stdio(0);
        int TE = 1;
        if(mtest)
                cin >> TE;
        while(TE--)
                solve();
        return 0;
}


Measured memory_bytes: 8960
#include<iostream>
#include<algorithm>
#include<string>
#include<math.h>
using namespace std;

int main(void)
{
    int n;
    cin >> n;
    if(n % 10 == 9 || n / 10 == 9){cout << "Yes" << endl;}
    else{cout << "No" << endl;}
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int dp[1002][1002];
const int MOD = (int)1e9 + 7;
int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    string s;
    cin >> s;
    int sum = 0;
    for (int i = 0; i < s.size(); i++)
        sum += int(s[i] - '0');
    if(sum % 9 == 0)
        cout << "Yes\n";
    else
        cout << "No\n";
}

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

s = []
p = []
num = []
for i in range(n):
  tmp = input().split()
  s.append(tmp[0])
  p.append(tmp[1])
  num.append(i)
sp = []
st = []
sn = []
spnum = zip(s,p,num)
spnum_s = sorted(spnum)
#print(spnum_s)
for i in range(0,len(spnum_s)):
  st.append(spnum_s[i][0])
  sp.append(int(spnum_s[i][1]))
  sn.append(spnum_s[i][2])
  #print(st)
  if(i == len(spnum_s)-1 or st[-1] != spnum_s[i+1][0]):
    tmp = zip(sp,sn)
    tmp2 = sorted(tmp, reverse=True)
    #print(tmp2)
    for j in range(0,len(tmp2)):
      print(tmp2[j][1]+1)
    st = []
    sp = []
    sn = []
  

Measured memory_bytes: 38256
# include <iostream>
using namespace std;
int main(){
  int n,i,a,b;
  cin>>n; 
  int ar[n];
  for(i=0;i<n;i++){
    cin>>ar[i];
  }
  int dp[n+1];
  dp[0]=0;
  dp[1]=0;
  a=0;
  b=0;
  dp[2]=abs(ar[1]-ar[0]);
  for(i=3;i<=n; i++){
    a=abs(ar[i-1]-ar[i-2]);
   // cout<<a; 
    b=abs(ar[i-1]-ar[i-3]);
    //cout<<b; 
    dp[i]=min((dp[i-1]+a),(dp[i-2]+b));
    //cout<<dp[i]<<" ";
  }
  cout<<dp[n];
  return 0;
}

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

#define pb push_back
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define ll long long
#define ii pair<int,int>
#define vi vector<int>
#define vll vector<ll>
#define vii vector<ii>

using namespace std;

const int maxn = 1e6+10;

bool sieve[maxn];
unordered_map<int,int> hist;
vi vs;

void fill_sieve(int lim){
	for(auto &x:vs){
		if(!sieve[x]){
			for(int k=2*x;k<=lim;k+=x){
				sieve[k]=1;
			}
		}
	}
	for(auto &x:hist)
		if(x.ss>1)
			sieve[x.ff]=1;
}

int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n,lim=1;
	cin>>n;
	vs = vi(n);
	for(int &x:vs){
		cin>>x;
		hist[x]++;
		lim = max(x,lim);
	}
	if(hist[1]==1){
		cout<<1<<endl;
		exit(0);
	}
	if(hist[1]>1){
		cout<<0<<endl;
		exit(0);
	}
	sort(all(vs));
	fill_sieve(lim);
	int ans=0;
	for(auto x:vs){
		if(!sieve[x]){
			++ans;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 12552
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <cmath>
using namespace std;
#define EPS (1e-10)
#define EQ(a,b) (abs((a)-(b))<EPS)
double dp[21][150001];
const double INF=(1LL<<50);
int a[21];
int n;
double dfs(int idx,int lastNum){
    if(idx==-1)
        return 0.0;
    if(!EQ(INF,dp[idx][lastNum]))
        return dp[idx][lastNum];
    double minCost=INF;
    if(idx==n-1)
        for(int i = 1; i <= 150000; i++){
            if(minCost<(double)abs(a[idx]-i)/a[idx])
                continue;
            minCost=min(minCost,max(dfs(idx-1,i),(double)abs(a[idx]-i)/a[idx]));
        }
    else{
        // lastNumðèØéÅJÚ
        for(int i = 1; i*i <= lastNum; i++){
            if(lastNum%i==0){
                minCost=min(minCost,max(dfs(idx-1,i),(double)abs(a[idx]-i)/a[idx]));
                minCost=min(minCost,max(dfs(idx-1,(lastNum/i)),(double)abs(a[idx]-(lastNum/i))/a[idx]));
            }
        }
    }
    return dp[idx][lastNum]=minCost;
}

int main(){
    for(int i = 0; i < 21; i++)
        for(int j = 0; j < 150001; j++)
            dp[i][j]=INF;
    cin>>n;
    for(int i = 0; i < n; i++) cin>>a[i];
    double res=dfs(n-1,0);
    printf("%.9f\n",res);
    return 0;
}

Measured memory_bytes: 24000
#include <iostream>
#include <vector>
#include <functional>
#include <algorithm>

#define INF 100000000

using namespace std;

int match[] = {2, 5, 5, 4, 5, 6, 3, 7, 6};


int main(){
    int N, M;
    cin>>N>>M;
    vector<int> A(M);
    for(int i=0; i<M; ++i){
        cin>>A[i];
    }
    sort(A.begin(), A.end());

    vector<int> dp(N+1, -INF);
    dp[0] = 0;
    for(int i=2; i<=N; ++i){
        for(int j=0; j<M; ++j){
            if(i - match[A[j]-1] >= 0){
                dp[i] = max(dp[i], dp[i - match[A[j]-1]] + 1);
            }
        }
    }
    
    for(int j=M-1; j>=0; --j){
        while(N - match[A[j]-1] >= 0 && dp[N - match[A[j]-1]] == dp[N] - 1){
            cout<<A[j];
            N -= match[A[j]-1];
        }
    }
    cout<<endl;
    
    return 0;
}

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

int main(){

    int H, W = -1;

    queue<int> que_h;
    queue<int> que_w;

    while(1){
        if((H == 0) && (W == 0)){
            break;
        }
        cin >> H >> W;
        que_h.push(H);
        que_w.push(W);
    }

    while(1){
        
        H = que_h.front();
        W = que_w.front();

        if((H == 0) && (W == 0)){
            break;
        }

        for(int i=0; i<W; i++){
            cout << "#";
        }
        cout << endl;
        // contents
        for(int i=0; i<H-2; i++){
            for(int j=0; j<W; j++){
                if((j == 0) || (j == W-1)){
                    cout << "#";
                }else{
                    cout << ".";
                }
            }
            cout << endl;
        }
        
        for(int i=0; i<W; i++){
            cout << "#";
        }
        cout << endl;
        cout << endl;

        que_h.pop();
        que_w.pop();
    }


    return  0;
}

Measured memory_bytes: 3092
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {

	static int dp[][] = new int[(1 << 21) + 1][21];
	static int dist[][] = new int[21][21];

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int a = Integer.parseInt(br.readLine());

		System.out.println((int) (a + Math.pow(a, 2) + Math.pow(a, 3)));
	}
}


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

int x[2000][5], H;

int solve() {
	int score = 0;
	for (int i = 0; i < 500; i++)
	{
		for (int j = 0; j < H; j++)
		{
			if (x[j][0] == x[j][1] && x[j][1] == x[j][2] && x[j][2] == x[j][3] && x[j][3] == x[j][4] && x[j][0] >= 1) {
				score += x[j][0] * 5;
				x[j][0] = 0;
				x[j][1] = 0;
				x[j][2] = 0;
				x[j][3] = 0;
				x[j][4] = 0;
			}
		}
		for (int j = 0; j < H; j++)
		{
			for (int k = 0; k < 2; k++)
			{
				if (x[j][k + 0] == x[j][k + 1] && x[j][k + 1] == x[j][k + 2] && x[j][k + 2] == x[j][k + 3] && x[j][k + 0] >= 1) {
					score += x[j][k + 0] * 4;
					x[j][k + 0] = 0;
					x[j][k + 1] = 0;
					x[j][k + 2] = 0;
					x[j][k + 3] = 0;
				}
			}
		}
		for (int j = 0; j < H; j++)
		{
			for (int k = 0; k < 3; k++)
			{
				if (x[j][k + 0] == x[j][k + 1] && x[j][k + 1] == x[j][k + 2] && x[j][k + 0] >= 1) {
					score += x[j][k + 0] * 3;
					x[j][k + 0] = 0;
					x[j][k + 1] = 0;
					x[j][k + 2] = 0;
				}
			}
		}
		for (int j = 0; j < 500; j++) {
			for (int j = 1; j < H; j++) {
				for (int k = 0; k < 5; k++) {
					if (x[j][k] == 0) {
						x[j][k] = x[j - 1][k];
						x[j - 1][k] = 0;
					}
				}
			}
		}
	}
	return score;
}

int main() {
	while (true) {
		cin >> H;
		if (H == 0) { break; }
		for (int i = 0; i < H; i++) {
			for (int j = 0; j < 5; j++) {
				cin >> x[i][j];
			}
		}
		cout << solve() << endl;
	}
	return 0;
}

Measured memory_bytes: 1164
li = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
k = int(input())
print(li[k-1])

Measured memory_bytes: 3316
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rep2(i,n) for (int i = 1; i < (n); ++i)
using namespace std;
typedef long long ll;
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, r;
    cin >> n >> r;
    int ans;
    if(n < 10) ans = 100 * (10-n) + r;
    else ans = r;
    cout << ans << endl;
    return 0;
}

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

int main() {
	double N, ans;
	scanf("%lf", &N);
	ans = ceil(N / 1.08);
	if ((int)(ans * 1.08) == (int)N) printf("%d\n", (int)ans);
	else printf(":(\n");
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <stdio.h>
#define ff(i,x,y)for(int i=x;i<y+1;i++)
#define fs(i,x,y)for(int i=x;i>y-1;i--)
#define all(x) x.begin(),x.end()
#define Ins(x) inserter(x,x.begin())
//set<int>::iterator it
using namespace std;
typedef long long ll;
int n,m,k;
int main()
{
    scanf("%d%d%d",&n,&m,&k);
    int pan=0;
    ff(i,0,n)
    {
        ff(j,0,m)
        {
            if(k==i*m+j*n-2*i*j)
            {
                pan=1;
                break;
            }
        }
    }
    if(pan)
        printf("Yes\n");
    else
    printf("No\n");
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string>
#include<map>
#include<algorithm>
#include<vector>
#include<iostream>
using namespace std;
int main(){
  vector<string> a,t;
  string s[200010];
  map<string,int> store;
  int n,i,max=0;
  scanf("%d\n",&n);
  for(i=0;i<n;i++){
    cin >> s[i];
    store[s[i]]++;
    if(store[s[i]]==1){
      t.push_back(s[i]);
    }
  }
  for(i=0;i<n;i++){
    if(store[s[i]]>max){
      max=store[s[i]];
    }
  }
  for(i=0;i<t.size();i++){
    if(store[t[i]]==max){
      a.push_back(t[i]);
    }
  }
  sort(a.begin(),a.end());
  for(i=0;i<a.size();i++){
    cout << a[i] << endl;
  }
  return 0;
}

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

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

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

/**
 * @brief 多次元 vector の作成
 * @author えびちゃん
 */
namespace detail {
    template<typename T, int N>
    auto make_vec(vector<int>& sizes, T const& x) {
        if constexpr (N == 1) {
            return vector(sizes[0], x);
        } else {
            int size = sizes[N-1];
            sizes.pop_back();
            return vector(size, make_vec<T, N-1>(sizes, x));
        }
    }
}
template<typename T, int N>
auto make_vec(int const(&sizes)[N], T const& x = T()) {
    vector<int> s(N);
    for (int i = 0; i < N; ++i) s[i] = sizes[N-i-1];
    return detail::make_vec<T, N>(s, x);
}

__attribute__((constructor))
void fast_io() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
}

int main() {
    int n, m;
    cin >> n >> m;
    auto a = make_vec<int>({n, m});
    rep(i, n) rep(j, m) cin >> a[i][j], a[i][j]--;

    auto check = [&](int x) {
        vector<bool> hold(m, true);
        while (true) {
            vector<int> cnt(m);
            rep(i, n) {
                rep(j, m) {
                    if (hold[a[i][j]]) {
                        cnt[a[i][j]]++;
                        break;
                    }
                    if (j == m-1) {
                        return false;
                    }
                }
            }
            bool flag = true;
            rep(i, m) {
                if (cnt[i] > x) {
                    hold[i] = false;
                    flag = false;
                }
            }
            if (flag) break;
        }
        return true;
    };

    int ng = 0, ok = n;
    while (ok - ng > 1) {
        int mid = (ok + ng) >> 1;
        (check(mid) ? ok : ng) = mid;
    }
    cout << ok << '\n';
}


Measured memory_bytes: 3784
def solve():
    L,R = map(int, input().split())
    if R-L >= 2019:
        multiple = [0]
    else:
        L,R = L%2019, R%2019
        L,R = min(L,R),max(L,R)
        multiple = [i*j%2019 for i in range(L,R) for j in range(i+1,R+1)]
        
    print(min(multiple))

solve()

Measured memory_bytes: 75416
#include <bits/stdc++.h>
#include <unordered_map>
typedef long long ll;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " \n"[i == n-1];}
#define printp(x,n) for(ll i = 0; i < n; i++){ cout << "(" << x[i].first << ", " << x[i].second << ") "; } cout << endl;
#define INF (1e18)
using namespace std;
const ll MOD = 1e9 + 7;
typedef pair<ll, ll> lpair;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N,M;
    ll a[100010], b[100010];
    cin >> N >> M;
    rep(i,0,M){
        cin >> a[i] >> b[i];
        a[i]--; b[i]--;
        if(a[i] > b[i]) swap(a[i], b[i]);
    }
    ll v[100010] = {};
    rep(i,0,M){
        v[a[i]]++;
        v[b[i]]--;
    }
    rep(i,0,N+2){
        v[i+1] += v[i];
    }
    bool ok = true;
    rep(i,0,N-1){
        if(v[i] % 2 != 0) ok = false;
    }
    // printa(v,N);
    if(ok){
        print("YES");
    }else{
        print("NO");
    }
}


Measured memory_bytes: 2560
package main

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

type Pair struct {
	a, b int
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)

	scanner.Scan()
	N, _ := strconv.Atoi(scanner.Text())
	scanner.Scan()
	Ma, _ := strconv.Atoi(scanner.Text())
	scanner.Scan()
	Mb, _ := strconv.Atoi(scanner.Text())

	memo := map[Pair]int{}
	memo[Pair{0, 0}] = 0
	for i := 0; i < N; i++ {
		scanner.Scan()
		a, _ := strconv.Atoi(scanner.Text())
		scanner.Scan()
		b, _ := strconv.Atoi(scanner.Text())
		scanner.Scan()
		c, _ := strconv.Atoi(scanner.Text())

		new_memo := map[Pair]int{}
		for k, v := range memo {
			new_memo[Pair{k.a + a, k.b + b}] = v + c
		}
		for k, v := range new_memo {
			x, ok := memo[k]
			if ok {
				if x > v {
					memo[k] = v
				}
			} else {
				memo[k] = v
			}
		}
	}

	ret := -1
	for k, v := range memo {
		if k.a == 0 && k.b == 0 {
			continue
		}
		if k.a*Mb == k.b*Ma {
			if ret == -1 || ret > v {
				ret = v
			}
		}
	}
	fmt.Println(ret)
}


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

int64_t intpow(int64_t n, int64_t k, int64_t INF=int64_t(1e18)){
    int64_t ret = 1;
    while(k--){
        if(ret > INF/n) return INF;
        ret *= n;
    }
    return ret;
}

int64_t nroot(int64_t n, int64_t k){
    int64_t ret = pow((long double)n, 1.0L/k);
    while(true){
        if(intpow(ret, k, n+1) > n){
            ret--;
        }else{
            break;
        }
    }
    while(true){
        if(intpow(ret+1, k, n+1) <= n){
            ret++;
        }else{
            break;
        }
    }
    return ret;
}

int main(){
    int64_t N, A;
    cin >> N >> A;

    int64_t ans = N;
    for(int k=2; k<=40; k++){
        int64_t low = nroot(N, k);
        int64_t now = intpow(low, k, N);
        int64_t res = A*(k-1) + low*k;
        for(int i=0; now < N; i++){
            now /= low;
            now *= low+1;
            res++;
        }
        ans = min(ans, res);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline

mod = 10**9+7
n, m = map(int, input().split())
broken = set(int(input()) for i in range(m))

pattern = [0]*(n+1)
pattern[0] = 1
if 1 in broken:
    pattern[1] = 0
else:
    pattern[1] = 1

for i in range(2, n+1):
    if i in broken:
        continue
    else:
        pattern[i] = (pattern[i-1] + pattern[i-2]) % mod

print(pattern[n])


Measured memory_bytes: 11884
import sys

N,K=map(int,input().split())
A=sorted(list(map(int,input().split())))[::-1]
mod=10**9+7
score=1

if K%2==1:  #これでKは偶数として扱えるようになった
    score*=A[0]
    A.pop(0)
    K-=1

#print(A)

P,M=[],[]
for i in A:
    if i>0:
        P.append(i)
    else:
        M.append(i)

M=M[::-1]
t=0
p,m=0,0
while t<=K:
    if score<0:  #負であることが確定しているなら小さくなるようにする
        P=P[::-1]
        M=M[::-1]
        if 0 in M:
            print(0)
            sys.exit()
    if t+2<=K:
        if 2*p+1<len(P) and 2*m+1<len(M):
            if P[2*p]*P[2*p+1] >= M[2*m]*M[2*m+1]:
                score*=P[2*p]*P[2*p+1]
                p+=1
                t+=2
            else:
                score*=M[2*m]*M[2*m+1]
                m+=1
                t+=2
        elif 2*p+1<len(P):
            score*=P[2*p]*P[2*p+1]
            p+=1
            t+=2
        elif 2*m+1<len(M):
            score*=M[2*m]*M[2*m+1]
            m+=1
            t+=2
        else:  #?
            score*=P[-1]*M[-1]
            break
    elif t+1<=K:
        if 2*p<len(P):
            score*=P[2*p]
        else:
            score*=M[2*m]
        break
    else:
        break
    score%=mod

print(score%mod)

Measured memory_bytes: 31640
#include<stdio.h>
int main()
{
	int a,b,c,d,x,y;
	while(scanf("%d %d %d %d",&a,&b,&c,&d)!=EOF)
	{
		x=a+b;
		y=c+d;
		if(x==y)
		printf("Balanced\n");
		if(x>y)
		printf("Left\n");
		if(x<y)
		printf("Right\n");
	}
	return 0;
}

Measured memory_bytes: 128
// AtCoder ABC127: A - Ferris Wheel
// 2019.9.8 bal4u

#include <stdio.h>

int main()
{
	int A, B, ans;
	
	scanf("%d%d", &A, &B);
	if (A >= 13) ans = B;
	else if (A >= 6) ans = B/2;
	else ans = 0;
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
/***********************************************/
/* Dear online judge:
 * I've read the problem, and tried to solve it.
 * Even if you don't accept my solution, you should respect my effort.
 * I hope my code compiles and gets accepted.
 *  ___  __     _______    _______      
 * |\  \|\  \  |\  ___ \  |\  ___ \     
 * \ \  \/  /|_\ \   __/| \ \   __/|    
 *  \ \   ___  \\ \  \_|/__\ \  \_|/__  
 *   \ \  \\ \  \\ \  \_|\ \\ \  \_|\ \ 
 *    \ \__\\ \__\\ \_______\\ \_______\
 *     \|__| \|__| \|_______| \|_______|
 */
const long long mod = 1000000007;

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

	long long X,res;
	cin>>X;
	res = (X + 10) / 11;
	res *= 2;
	if(X%11 && X%11 <= 6) {
		res--;
	}
	cout<<res<<'\n';	
	return 0;
}
/**/


Measured memory_bytes: 256