akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define REP(i,n) for(int i=(0);i<(n);i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;

const int N=200005;
int f[N],n,a,b,len;
vi e[N];

int dfs(int u,int fa){
	int mx=0,mx2=0,now;
	for(auto v:e[u])
		if(v!=fa){
			now=dfs(v,u)+1;
			if(now>mx)mx2=mx,mx=now;
			else if(now>mx2)mx2=now;
		}
	len=max(len,mx+mx2);
	return mx;
}

int main(){
	scanf("%d",&n);
	rep(i,1,n-1){
		scanf("%d%d",&a,&b);
		e[a].pb(b),e[b].pb(a);
	}
	len=max(len,dfs(1,0));
	++len,f[1]=1,f[2]=0;
	rep(i,3,len)
		if(!f[i-2]||!f[i-1])f[i]=1;
		else f[i]=0;
	if(f[len])puts("First");
	else puts("Second");
	return 0;
}

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

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

    ll N, C, K;
    ll T[100000 + 7] = {};
    cin >> N >> C >> K;
    for (ll i = 0; i < N; i++) {
        cin >> T[i];
    }
    sort(T, T + N);

    ll ans = 1;
    ll num = 1;
    ll depature_time = T[0] + K;

    for (ll i = 1; i < N; i++) {
        if (T[i] <= depature_time && num < C) {
            num++;
        } else {
            ans++;
            num = 1;
            depature_time = T[i] + K;
        }
    }

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


Measured memory_bytes: 1024
#include <bits/stdc++.h>
	using namespace std;
	#define IOS ios::sync_with_stdio(false), cin.tie(0)
	#define REP(i, n) for (int i = 0; i < n; i++)
	#define FOR(i, a, b) for (int i = a; i < b; i++)
	#define ALL(x) (x).begin(), (x).end()
	#define dump(x) cout << (x) << endl
	#define LMAX 9223372036854775807LL
	#define LMIN -9223372036854775807LL

	using ll = long long;
	template<typename T>
	using vec = vector<T>;
	using P = pair<ll, ll>;

	template <typename A, size_t N, typename T>
	void Fill(A (&array)[N], const T &val){
		fill((T *)array, (T *)(array + N), val);
	}
	
	const ll INF = 1e18;
	const ll mod = 1e9 + 7;

	//int dx[4] = {1,0,-1,0};
	//int dy[4] = {0,1,0,-1};
	//ll pas[51][52];
	
	ll powm(ll a, ll b, ll c) {
		if (b == 0)return 1;
		else if (b % 2 == 0) {
			ll d = powm(a, b / 2, c);
			return (d * d) % c;
		}
		else return (a * powm(a, b - 1, c)) % c;
	}

	signed main(){
		IOS;
		ll n, t;
		cin >> n >> t;
		vec<ll> a(n);
		REP(i,n)cin >> a[i];
		map<ll,ll> mp;//最大の差とその個数
		ll d = a[0],u = a[0];
		REP(i,n){
			if(d > a[i])d = a[i];
			mp[d - a[i]]++;
		}
		ll kosuu = mp.begin()->second;
		dump(kosuu);
	}

Measured memory_bytes: 7296
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int x = 0;
		int max = 0;
		int N = sc.nextInt();
		String S = sc.next();
		for(int i=0;i<N;i++){
			if(S.charAt(i)=='I')x++;
			if(S.charAt(i)=='D')x--;
			if(x>max)max = x;
		}
		System.out.println(max);
	}
}

Measured memory_bytes: 21972
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
const int MAX = 1000000000;

int main()
{
    int n, k;
    cin >> n >> k;
    int d[100];
    int a[100][100];
    bool have[101];
    for (int i = 0; i < 100;i++){
        have[i] = false;
    }
        for (int i = 0; i < k; i++)
        {
            cin >> d[i];
            for (int j = 0; j < d[i]; j++)
            {
                int t;
                cin >> t;
                have[t] = true;
            }
        }
        int ans = 0;
        for (int i = 1; i <= n;i++){
            if(have[i] == true){
                ans++;
                
            }
        }
        cout << n-ans;
} 


Measured memory_bytes: 3592
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<deque>
#include <chrono>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
const ll E=1e17+7;
#define F first
#define S second
#define MK make_pair
typedef pair<ll,ll> sushi;

ll dp[110000][2][2]={};

int main(){
    ll n,c;
    cin>>n>>c;
    vector<sushi> s;
    for(int i=0;i<n;i++){
        ll x,v;
        cin>>x>>v;
        s.push_back({x,v});
    }
    ll sum=0;
    for(int i=0;i<n;i++){
        sum+=s[i].S;
        dp[i][0][0]=sum-s[i].F;
        dp[i][0][1]=dp[i][0][0]-s[i].F;
    }
    ll mx[2]={};
    for(int i=0;i<n;i++){
        mx[0]=max(mx[0],dp[i][0][0]);
        mx[1]=max(mx[1],dp[i][0][1]);
        dp[i][0][0]=mx[0];
        dp[i][0][1]=mx[1];
    }
    sum=0;
    for(ll i=n-1;i>=0;i--){
        sum+=s[i].S;
        dp[i][1][0]=sum-(c-s[i].F);
        dp[i][1][1]=dp[i][1][0]-(c-s[i].F);
    }
    mx[0]=0;
    mx[1]=0;
    for(ll i=n-1;i>=0;i--){
        mx[0]=max(mx[0],dp[i][1][0]);
        mx[1]=max(mx[1],dp[i][1][1]);
        dp[i][1][0]=mx[0];
        dp[i][1][1]=mx[1];
    }
    ll ans=0;
    for(ll i=0;i<n-1;i++){
        ans=max(ans,dp[i][0][0]+dp[i+1][1][1]);
        ans=max(ans,dp[i][0][1]+dp[i+1][1][0]);
    }
    ans=max(ans,dp[n-1][0][0]);
    ans=max(ans,dp[0][1][0]);
    cout<<ans<<endl;
    
    return 0;
}

Measured memory_bytes: 5104
import java.util.Scanner;

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

        String S = sc.next();
        String T = sc.next();
        int A = sc.nextInt();
        int B = sc.nextInt();

        if (S.equals(sc.next())) {
            A--;
        } else {
            B--;
        }

        System.out.println(A + " " + B);
    }
}


Measured memory_bytes: 23124
# -*- coding: utf-8 -*-
import sys
from collections import defaultdict
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    N=int(input())
    A=list(map(int,input().split()))
    d=defaultdict(int)
    t=[0]
    f=[0]
    for x in A:
        d[x]+=1
        if d[x]==2:
            t.append(x)
        elif d[x]==4:
            f.append(x)
    t.sort()
    f.sort()
    if len(t)>=2:
        print(max(f[-1]**2,t[-1]*t[-2]))
    else:
        print(0)

if __name__ == '__main__':
    main()


Measured memory_bytes: 64512
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>

using namespace std;
typedef long long ll;

int main(){
  int N;
  cin >> N;
  int h[N];
  for(int i=0;i<N;i++){
    cin >> h[i];
  }
  int ans = 0;
  for(int i=0;i<N-1;i++){
    if(h[i]>=h[i+1]){
      ans += h[i];
      ans -= h[i+1];
    }
  }
  ans += h[N-1];
  cout << ans << endl;
}


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

using namespace std;

#define sp(x) cout<<setprecision(x);
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define all(a) (a).begin(), (a).end()
#define inf 10000000
#define linf INT64_MAX*0.99
#define print(s) cout<<(s)<<endl
#define lint long long
#define yes "Yes"
#define no "No"

typedef pair<int, int> P;
 
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n; cin>>n;
    int sum=inf;
    int now=0;
    vector<int> x(n);
    REP(i,n) cin>>x[i];
    sort(all(x));
    
    FOR(j,1,x[n-1]+1){
        REP(i,n){
            now+=(x[i]-j)*(x[i]-j);
        }
        if(now<sum) sum = now;
        now = 0;
    }
    print(sum);
    return 0;
}

Measured memory_bytes: 256
# AtCoder Beginner Contest 165: A (2020/05/02)
K = int(input())
A, B = map(int, input().split())
X = A // K
Y = B // K
if A % K != 0:
    X = X + 1
if Y >= X :
    print("OK")
else:
    print('NG')

Measured memory_bytes: 9176
// This amazing code is by Eric Sunli Chen.
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace std;
template<typename T> bool get_int(T &x)
{
	char t=getchar();
	bool neg=false;
	x=0;
	for(; (t>'9'||t<'0')&&t!='-'&&t!=EOF; t=getchar());
	if(t=='-')neg=true,t=getchar();if(t==EOF)return false;
	for(; t<='9'&&t>='0'; t=getchar())x=x*10+t-'0';
	if(neg)x=-x;return true;
}
template<typename T> void print_int(T x)
{
	if(x<0)putchar('-'),x=-x;
	short a[20]= {},sz=0;
	while(x>0)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1; i>=0; i--)putchar('0'+a[i]);
}
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define get1(a) get_int(a)
#define get2(a,b) (get1(a)&&get1(b))
#define get3(a,b,c) (get1(a)&&get2(b,c))
#define printendl(a) print_int(a),puts("")
typedef long long LL;
typedef unsigned long long uLL;
typedef pair<int,int> pii;
const int inf=0x3f3f3f3f;
const LL Linf=1ll<<61;
const double pi=acos(-1.0);

const int mod=1e9+7;
int power(int x,int y)
{
	int ret=1;
	while(y)
	{
		if(y&1)ret=1ll*ret*x%mod;
		x=1ll*x*x%mod;
		y>>=1;
	}
	return ret;
}
int s,p10[12000111],f[23000111];
int main()
{
	p10[0]=1;for(int i=1;i<12000111;i++)p10[i]=10ll*p10[i-1]%mod;
	get1(s);
	for(int i=1;i<=23000000;i++)f[i]=f[i/10]+1;
	for(int i=1;i<=23000000;i++)f[i]+=f[i-1];
	int r=1,ans=s/8;
	for(int l=1;l<10000000;l++)
	{
		while(r<23000111&&f[r]-f[l-1]<s)r++;
		if(f[r]==f[l-1]+s)ans++;
	}
	for(int i=1;i<=s/8;i++)if(s%i==0)
		ans=(ans+9ll*power(10,s/i-1)-i+mod)%mod;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 136960
#include<stdio.h>

int selectionSort(int A[],int N){
 int i,j,t,sw=0,minj;
	for(i=0;i<N-1;i++){
	 minj=i;
		for(j=i;j<N;j++){
			if(A[j]<A[minj])minj=j;
			}
		t=A[i];A[i]=A[minj];A[minj]=t;
		if(i!=minj)sw++;
		}
	return sw;
	
	}

int main(){
 int A[100],N,i,sw;
	
	scanf("%d",&N);
	for(i=0;i<N;i++)scanf("%d",&A[i]);
	
	sw=selectionSort(A,N);
	
	for(i=0;i<N;i++){
		if(i>0)printf(" ");
		printf("%d",A[i]);
	 }

	printf("\n");
	printf("%d\n",sw);
	
return 0;
}



Measured memory_bytes: 2104
#include <cstdio>
#include <cstdlib>
#include <cstring>

struct Node{
	int key;
	Node *next,*prev;
}; 

Node *nil;

Node* listSearch(int key){
	Node *cur = nil->next;
	while(cur != nil && cur->key != key){
		cur = cur->next;
	}
	
	return cur;
}

void init(){
	nil = (Node *)malloc(sizeof(Node));
	nil->next = nil;
	nil->prev = nil;
}

void printList(){
	Node *cur = nil ->next;
	int isf = 0;
	while(1){
		if(cur == nil) break;
		if(isf++ > 0) printf(" ");
		printf("%d",cur->key);
		cur = cur->next;
	}
	printf("\n"); 
}

void deleteNode(Node *t){
	if(t == nil) return;
	t->prev->next = t->next;
	t->next->prev = t->prev;
	free(t);
}

void deleteFirst(){
	deleteNode(nil->next);
}

void deleteLast(){
	deleteNode(nil->prev);
}

void deleteKey(int key){
	deleteNode(listSearch(key));
} 

void insert(int key){
	Node *x = (Node *)malloc(sizeof(Node));
	x->key = key;
	x->next = nil->next;
	nil->next->prev = x;
	nil->next = x;
	x->prev = nil;
}

int main(){
	int key,n,i;
	int size = 0;
	char com[20];
	int np = 0,nd = 0;
	scanf("%d",&n);
	init();
	for(i = 0; i<n;i++){
		scanf("%s%d",com,&key);
		if(com[0] == 'i'){
			insert(key);
			np++;
			size++;
		}
		else if(com[0] == 'd'){
			if(strlen(com) > 6){
				if(com[6] == 'F') deleteFirst();
				else if(com[6] == 'L') deleteLast(); 
			}
			else{
				deleteKey(key);
				nd++;
			}
			size--;
		}
	}
	
	printList();
	
	return 0;
}


Measured memory_bytes: 33836
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
#define int int64
#define rep(i, n) for(int i=0; i<n; i++)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define mk make_pair
#define fi first
#define se second
#define pb push_back
#define ALL(x) x.begin(), x.end()
#define V(T) vector<T>
typedef pair<int, int> P;
typedef pair<P, P> PP;
typedef vector<int> vi;
typedef vector<vi> vvi;
int max(int a, int b) {if(b>a) return b; else return a;}
int min(int a, int b) {if(b<a) return b; else return a;}
const int INF = 1e18;

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

    for(int i=A; i<=B; i++) {
        if(i%K==0) {
            cout << "OK" <<endl;
            return 0;
        }
    }

    cout << "NG" << endl;

    return 0;
}

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

int main() {
  int N , M , K ;
  cin >> N >> M >> K ; 
  vector<int> A(N) , B(M) ;  
  
  for(int i = 0 ; i < N ; i++){
    cin >> A.at(i) ; 
  }
  for(int i = 0 ; i < M ; i++){
    cin >> B.at(i) ; 
  }
  
  int64_t T = 0 ; 
  for(int i = 0 ; i < M ; i++) T += B.at(i) ; //Bの机から全部読んだ時の時間
  int j = M ; //B机から全部読んだ札数
  int ans = 0 ; //最終的な答え
  
  for(int i = 0 ; i <= N ; i++){
    while ( j > 0 && T > K ){
      --j ; //机Bのj冊目の時間は配列Bのj-1個目(ゼロインデックスだから)
      T -= B.at(j) ; //M個目を読まないことにするのでその時間を減らす
    }
    if(T > K) break ; //机Bからj番目の本を読まなかった時、Kを超えたら何もせず終わり
    
    ans = max(ans , i+j) ; //一番多く読めた札数を残す
    
    if(i == N) break ;// 机AにはN冊までしかないので範囲外参照することになる
    
    T += A.at(i) ;// 机Aからi番目の本を読むのにかかる時間を足す
  }
  
  cout << ans << endl ; 
  
  
}

Measured memory_bytes: 4836
#include <iostream>
#include <vector>
#include <queue>
using namespace std;

int main() {
    int N;
    cin >> N;
    priority_queue<double , vector<double >, greater<double >> que;
    for (int i = 0; i < N; i++) {
        double v;
        cin >> v;
        que.push(v);
    }

    while (que.size() > 1) {
        double a = que.top(); que.pop();
        double b = que.top(); que.pop();
        que.push((a + b) / 2);
    }

    printf("%.6f\n", que.top());
    return 0;
}


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

using namespace std;

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

const int INF = 1000000000;
const ll LINF = (ll) 4000000000000000000;
const ll MOD = (ll) 1000000007;
const double PI = acos(1.0);
const int limit = 100010;

#define REP(i,m,n) for(ll i = m; i < (ll)(n); i++)
#define rep(i,n) REP(i, 0, n)
#define MP make_pair
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define NP(v) next_permutation(v.begin(),v.end())
#define smaller_queue  priority_queue <ll, vector<ll>, greater<ll> >
//------------------------------------------------------

int main() {

    REP(i, 1, 10) REP(j, 1, 10) {
        printf("%dx%d=%d\n", i, j, i * j);
    }

    return 0;
}



Measured memory_bytes: 3148
n,l = map(int,input().split())
al = list(map(int,input().split()))

target = -1
for i in range(n-1):
    if al[i] + al[i+1] >= l:
        target = i

if target == -1:
    print("Impossible")
    exit()
else:
    print("Possible")
    for i in range(target):
        print(i+1)
    for i in range(n-1, target+1, -1):
        print(i)
    print(target+1)



Measured memory_bytes: 63984
#include <bits/stdc++.h>
#define int long long int
#define mod(x) ((x % MOD) + MOD) % MOD
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define RFORE(i,a,b) for(int i=(b);i>=(a);--i)
#define REP(i,n) FOR(i,0,n)
#define ALL(c) (c).begin(),(c).end()
#define RALL(c) (c).rbegin(),(c).rend()
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define SZ(c) (int)((c).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define LB(c,x) (int)(lower_bound(ALL(c),x)-(c).begin())
#define UB(c,x) (int)(upper_bound(ALL(c),x)-(c).begin())
#define COUNT(c,x) (UB(c,x)-LB(c,x))
#define UNIQUE(c) SORT(c); (c).erase(unique(ALL(c)),(c).end());
#define COPY(c1,c2) copy(ALL(c1),(c2).begin())
#define EXIST(s,e) (bool)((s).find(e)!=(s).end())
#define PB push_back
#define MP make_pair
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
using namespace std;
template<typename T1, typename T2> using P = pair<T1,T2>;
template<typename T> using V = vector<T>;
struct edge { int from, to; int cost; };
bool operator< (const edge &edge1, const edge &edge2) { return edge1.cost < edge2.cost; };
const int INF = 1e18;
const int MOD = 1e9+7;

template<typename T> ostream& operator << (ostream& s, const V<T>& v) {
   s << "[";
   for (int i = 0; i < v.size(); i++) { s << v[i]; if (i < v.size() - 1) s << " "; }
   s << "]";
   return s;
}

signed main()
{
   int N; cin >> N;
   V<int> A(N), B(N);
   REP(i, N) {
      cin >> A[i] >> B[i];
   }

   int sumA = 0;
   REP(i, N) sumA += A[i];

   int minB = sumA;
   REP(i, N) if (A[i] > B[i]) minB = min(minB, B[i]);

   int ans = sumA - minB;
   cout << ans << endl;

   return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using i64 = long long;

bool used[101010];
int dp[101010];
std::deque<int> g[101010];

int dfs(int v) {
    if (used[v]) return dp[v];

    used[v] = true;

    int ret = 0;
    for (auto c : g[v]) {
        ret = std::max(ret, dfs(c) + 1);
    }

    return dp[v] = ret;
}

int main() {
    int n, m;
    std::cin >> n >> m;
    for (int i = 0; i < m; i++) {
        int x, y;
        std::cin >> x >> y;
        x--; y--;
        g[x].push_back(y);
    }

    int ret = 0;
    for (int v = 0; v < n; v++) ret = std::max(ret, dfs(v));
    std::cout << ret << std::endl;

    return 0;
}

Measured memory_bytes: 71296
K,A,B=$<.read.split.map(&:to_i)

# 交換しても増えないなら叩きまくる
if B-A < 2 || K <= A-1
  p(1+K)
  exit 0
end

# 初回の交換までの回数
ret = A
i = K-A+1

ret += i/2 * (B-A)
ret += 1 if i.odd?

p ret


Measured memory_bytes: 3836
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<deque>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<iterator>
#include<complex>
#include<stack>
#include "stdio.h"
using namespace std;

#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)

using ll = long long;
using Pii = pair<int, int>;

const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const long long mod_const = 1e9+7;

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

using MIte = multimap<ll, ll, greater<ll> >::iterator;

//2051
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	// long long?
	long long A,B;
	cin >> A >> B;

	if (A == B) {
		cout << A << endl;
		return 0;
	}

	const int limdigit = 50;
	ll div = 1;
	ll ans = 0;
	for (int i = 0; i != limdigit; ++i) {
		div *= 2;
		ll A_sho = A / div;
		ll A_ama = A % div;
		ll B_sho = B / div;
		ll B_ama = B % div;
		if (div == 2) {
			ll tmp = B_sho - A_sho;
			tmp = (B_ama == 1) ? tmp + 1 : tmp;
			ans = (tmp % 2 == 0) ? ans : ans + 1;
		}
		else {
			if (A_sho != B_sho) {
				A_ama = (A_ama <= (div / 2)) ? div / 2 : div / 2 - A_ama;
				B_ama = (B_ama < (div / 2)) ? 0 : B_ama - div / 2 + 1;

				ll tmp = A_ama + B_ama;
				ll add = (tmp % 2 == 0) ? 0 : 1;
				ans += (add * div / 2);
			}
			else {
				ll tmp = (B_ama + 1 - div / 2 > 0) ? B_ama + 1 - div / 2 : 0;
				tmp -= (A_ama + 1 - div / 2 > 0) ? A_ama - div / 2 : 0;
				ll add = (tmp % 2 == 0) ? 0 : 1;
				ans += (add * div / 2);
			}
		}
		if (A_sho == 0 && B_sho == 0) {
			break;
		}
	}

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

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <atcoder/modint>

#include <atcoder/math>
#include <atcoder/fenwicktree>
#include <atcoder/convolution>
#include <atcoder/scc>
#include <atcoder/twosat>
#include <atcoder/string>

#include <string>
#include <cstdio>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)

using namespace std;
typedef long long ll;

using namespace atcoder;

ll mod2 = 998244353;

int main()
{
    static char buf[500'001];
    scanf("%s", buf);
    string s = buf;
    vector<int> sa = suffix_array(s);
    long long answer = 1LL * s.size() * (s.size() + 1) / 2;
    for (auto x : lcp_array(s, sa)) {
        answer -= x;
    }
    printf("%lld\n", answer);
    return 0;
}

Measured memory_bytes: 16196
#include <iostream>

using namespace std;

int main(){
  string s;
  cin>>s;
  char a='a';
  bool flag = true;
  for(int i=0;i<s.size();i++){
    if(s[i]==a){
      flag=false;
    }
    a=s[i];
  }
  if(flag)cout<<"Good"<<endl;
  else cout<<"Bad"<<endl;
  
}


Measured memory_bytes: 3568
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

//Sheets
public class Main{

	class R{
		int x1, x2, type;
		public R(int x1, int x2, int type) {
			this.x1 = x1;
			this.x2 = x2;
			this.type = type;
		}
	}
	
	int n, r, area, len, INF = 1<<28;
	int[][] a;
	List<R>[] list;
	
	@SuppressWarnings("unchecked")
	void run(){
		Scanner sc = new Scanner(System.in);
		a = new int[2][10000];
		list = new List[10001];
		for(;;){
			n = sc.nextInt(); r = sc.nextInt();
			if((n|r)==0)break;
			int minx = INF, maxx = -1, miny = INF, maxy = -1;
			area = len = 0;
			for(int i=0;i<=10000;i++)list[i] = new ArrayList<R>();
			for(int i=0;i<n;i++){
				int x1 = sc.nextInt(), y1 = sc.nextInt(), x2 = sc.nextInt(), y2 = sc.nextInt();
				minx = Math.min(minx, x1);
				maxx = Math.max(maxx, x2);
				miny = Math.min(miny, y1);
				maxy = Math.max(maxy, y2);
				list[y1].add(new R(x1, x2, 1));
				list[y2].add(new R(x1, x2, -1));
			}
			Arrays.fill(a[0], 0);
			int X = 1;
			for(int y=miny;y<=maxy+1;y++,X=1-X){
				for(int x=minx;x<maxx;x++)a[X][x]=a[1-X][x];
				for(R r:list[y]){
					for(int x=r.x1;x<r.x2;x++)a[X][x]+=r.type;
				}
				for(int x=minx;x<maxx;x++){
					if(0 < a[X][x]){
						area++;
						if(x==0 || a[X][x-1]==0)len++;
						if(x==9999 || a[X][x+1]==0)len++;
					}
					if(a[X][x]==0&&0<a[1-X][x] || 0<a[X][x]&&a[1-X][x]==0)len++;
				}
			}
			System.out.println(area);
			if(r==2)System.out.println(len);
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 16000
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
#include <iostream>
#include <sstream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <bitset>
#include <complex>
#include <array>
#include <list>
#include <stack>
#include <valarray>

using namespace std;

typedef unsigned uint;
typedef long long Int;
typedef unsigned long long UInt;

const int INF = 1001001001;
const Int INFLL = 1001001001001001001LL;

template<typename T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
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; }
double fin() { double x; scanf("%lf", &x); return x; }
Int lin() { Int x; scanf("%lld", &x); return x; }

int main() {
  int H = in();
  int W = in();
  int N = in();
  set<pair<int, int>> X;
  for (int i = 0; i < N; ++i) {
    int r = in() - 1;
    int c = in() - 1;
    X.insert(make_pair(r, c));
  }

  vector<int> top(W, INF);
  int ar = 0, ac = 0;
  while (true) {
    chmin(top[ac], ar);
    ++ar;
    if (ar >= H) {
      break;
    }
    if (X.count(make_pair(ar, ac + 1)) == 0 && ac + 1 < W) {
      ++ac;
    }
  }

  int res = H;
  for (const auto& p : X) {
    if (top[p.second] < p.first) {
      chmin(res, p.first);
    }
  }
  printf("%d\n", res);
  return 0;
}


Measured memory_bytes: 10368
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <iomanip>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 998244353

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

ll ans = LLINF;
void dfs(ll now, ll cou, ll a, ll b, ll sum){
	if(a <= 0)return;
	if(ans < now)return;
	if(cou == 41){
		ans = min(ans, now);
		return;
	}
	ll A = (a >> cou) & 1;
	ll B = (b >> cou) & 1;
	ll C = (sum >> cou) & 1;

	if((A + B + C) % 2){
		return;
	}

	ll tmp = (1LL << cou);
	dfs(now, cou+1, a, b, sum);
	dfs(now + tmp, cou+1, a - tmp, b + tmp, sum);
}

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

	ll n;cin >> n;
	vector<ll> v(n);REP(i, n)cin >> v[i];
	ll sum = 0;
	for(ll i = 2;i < n;i++)sum ^= v[i];

	dfs(0, 0, v[0], v[1], sum);
	if(ans < v[0]){
		cout << ans << endl;
	}
	else{
		cout << -1 << endl;
	}

	return 0;
}


Measured memory_bytes: 3640
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
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; }
typedef long long ll;
int main()
{
  ll n; cin >> n;
  vector<ll> f(n+1, 1);
  for (ll i = 2; i <= n; ++i) {
    ll j = i;
    while(j <= n) {
      f[j]++;
      j += i;
    }
  }

  ll res = 0;
  for (ll i = 1; i <= n; ++i) {
    res += i*f[i];
  }
  cout << res << "\n";

  return 0;
}


Measured memory_bytes: 81400
#include<bits/stdc++.h>
using namespace std;
signed main(){
string s;
  int a=0,b,c;
  cin>>s;
  c=s.size();
  b=c;
  for(int i=0;i<c/2;i++){
	if(s[i]!=s[b-1]){
  	a++;
    }
    b--;
  }
  cout<<a<<"\n";
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int N;
long K;
long A[2<<17];
main()
{
	cin>>N>>K;
	for(int i=0;i<N;i++)cin>>A[i];
	sort(A,A+N);
	long L=-2e18,R=2e18;
	while(R-L>1)
	{
		long M=(L+R)/2;
		long now=2*K;
		for(int i=0;i<N;i++)
		{
			if(A[i]*A[i]<=M)now++;
			if(A[i]==0)
			{
				if(M>=0)now-=N;
			}
			else if(A[i]>0)
			{
				if(M>=0)now-=upper_bound(A,A+N,M/A[i])-A;
				else
				{
					now-=upper_bound(A,A+N,-((-M+A[i]-1)/A[i]))-A;
				}
			}
			else
			{
				if(M>=0)now-=A+N-lower_bound(A,A+N,-(M/-A[i]));
				else now-=A+N-lower_bound(A,A+N,(-M-A[i]-1)/-A[i]);
			}
		}
		if(now<=0)R=M;
		else L=M;
	}
	cout<<R<<endl;
}


Measured memory_bytes: 1792
#pragma GCC optimize(2)
#include <bits/stdc++.h>
using namespace std;
template <typename T> void read(T &t) {
	t=0; char ch=getchar(); int f=1;
	while (ch<'0'||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
	do { (t*=10)+=ch-'0'; ch=getchar(); } while ('0'<=ch&&ch<='9'); t*=f;
}
const int INF=0x7f7f7f7f;
const int maxn=(2e5)+10;
int n,m;
int to[maxn],from[maxn],S;
bool mk[1010][1010],dis[1010][1010],vis[1010];
vector<int> g[1010];
void dfs(int u) {
	vis[u]=1;
	mk[S][u]=1;
	for (int i=0,v;i<g[u].size();i++) {
		v=g[u][i];
		if (!vis[v]) dfs(v);
	}
}
int main() {
	//freopen("1.txt","r",stdin);
	read(n); read(m);
	for (int i=1;i<=m;i++) {
		read(from[i]); read(to[i]);
		g[from[i]].push_back(to[i]);
	}
	int x,y;
	for (S=1;S<=n;S++) {
		memset(vis,0,sizeof(vis));
		vis[S]=1;
		for (int i=0,v;i<g[S].size();i++) {
			v=g[S][i];
			if (!vis[v]) dfs(v);
			else dis[S][v]=1;
		}
		memset(vis,0,sizeof(vis));
		vis[S]=1;
		for (int i=g[S].size()-1,v;i>=0;i--) {
			v=g[S][i];
			if (!vis[v]) dfs(v);
			else dis[S][v]=1;
		}
	}
	for (int i=1;i<=m;i++) {
		x=from[i],y=to[i];
		if (dis[x][y]==mk[y][x]) printf("same\n");
		else printf("diff\n");
	}
	return 0;
}
/*
  0. Enough array size? Enough array size? Enough array size? Interger overflow?
  
  1. Think TWICE, Code ONCE!
  Are there any counterexamples to your algo?
    
  2. Be careful about the BOUNDARIES!
  N=1? P=1? Something about 0?
    
  3. Do not make STUPID MISTAKES!
  Time complexity? Memory usage? Precision error?
*/

Measured memory_bytes: 6272
import heapq

N, C = map(int,input().split())

sushi = []
for i in range(N):
    cur_sushi = list(map(int,input().split()))
    sushi.append(cur_sushi)

sum_V, sum_right = [0], [0]
for i in range(N):
    sum_V.append(sum_V[i]+sushi[i][1])
    sum_right.append(sum_V[i+1] - sushi[i][0])

sum_V, sum_left = [0], [0]
for i in range(N):
    sum_V.append(sum_V[i]+sushi[N-1-i][1])
    sum_left.append(sum_V[i+1] - (C-sushi[N-1-i][0]))

ans = max(max(sum_left), max(sum_right))

left = [0]
heapq.heapify(left)

for l in range(N):
    now = sum_right[N-l] - sushi[N-1-l][0]
    heapq.heappush(left, -sum_left[l])
    now -= left[0]
    ans = max(ans,now)

right = [0]
heapq.heapify(right)

for r in range(N):
    now = sum_left[N-r] - (C - sushi[r][0])
    heapq.heappush(right, -sum_right[r])
    now -= right[0]
    ans = max(ans,now)

print(ans)

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

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);  
	
	int n, k;
	cin >> n >> k;
	vector<int> num(10);
	for(int i = 0; i < k; i++) {
		int x;
		cin >> x;
		num[x]++;
	}
	while(true) {
		int m = n;
		bool ok = true;
		while(m > 0) {
			if(num[m % 10]) ok = false;
			m /= 10;
		}
		if(ok) {
			cout << n << endl;
			return 0;
		}
		n++;
	}
	return 0;	
}

Measured memory_bytes: 256
S=input()
N=len(S)
A=[0]*N
B=[]
C=[-1]
for i in range(N-1):
  if S[i]=='R' and S[i+1]=='L':
    B.append(i)
  elif S[i]=='L' and S[i+1]=='R':
    C.append(i)
C.append(N-1)
d=len(B)
for i in range(d):
  e=C[i+1]-C[i]
  if e%2==0:
    A[B[i]]=e//2
    A[B[i]+1]=e//2
  else:
    if (B[i]-C[i])%2==0:
      A[B[i]]=e//2
      A[B[i]+1]=e//2+1
    else:
      A[B[i]]=e//2+1
      A[B[i]+1]=e//2
      
print(*A)

Measured memory_bytes: 10292
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define SPEED ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
signed main()
{
    SPEED;
    int n;
    cin>>n;
    if(n%10==3)
    {
        cout<<"bon";
    }
    else if(n%10==0 || n%10==1 || n%10==6 || n%10==8)
    {
        cout<<"pon";
    }
    else
    {
        cout<<"hon";
    }
}

Measured memory_bytes: 3616
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

#include <bits/stdc++.h>
using namespace std;

ll floor_sum(ll n,ll m,ll a,ll b){
  ll ans=0;
  if(a>=m){
    ans+=(n-1)*n*(a/m)/2;
    a%=m;
  }
  if(b>=m){
    ans+=n*(b/m);
    b%=m;
  }

  ll y_max=(a*n+b)/m;
  if(y_max==0) return ans;
  ans+=floor_sum(y_max,a,m,a*n-y_max*m+b);
  return ans;
}

int main(){
  int t;
  cin>>t;
  
  rep(i,t){
    int n,m,a,b;
    cin>>n>>m>>a>>b;
  
    cout<<floor_sum(n,m,a,b)<<'\n';
  }
  
  return 0;
}

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

typedef long long ll;
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define REP(i,n) for (int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
 
using namespace std;


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

    vector<ll> a(8),b(7);
    a[0] = 1;
    b[0] = 1;
    for(int i = 1;i <= 7;i++) a[i] = 6*a[i-1];
    for(int i = 1;i <= 6;i++) b[i] = 9*b[i-1];

    set<ll> s;
    set<ll> z;
    s.insert(n);

    int cnt = 0;
    while(1){
        cnt++;
        for(auto x : s){
          	
          	cerr << x << endl;
            
            auto itr1 = upper_bound(a.begin(),a.end(),x);
            auto itr2 = upper_bound(b.begin(),b.end(),x);

            itr1--;
            itr2--;
          	cerr << "*itr1" << *itr1 << " " << "*itr2" << *itr2 << endl; 

            ll A = x - *itr1;
            ll B = x - *itr2;
            
            if(A == 0 || B == 0){
                cout << cnt << endl;
                return 0;
            }else{
                z.insert(A);
                z.insert(B);
            }
        }
        s = z;
        z.clear();
    }


    return 0;
}


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

int main(){
    int a;
    int b;
    int area;
    int length;
    
    cin >> a;
    cin >> b;
    
    area = a * b;
    length = 2 * (a + b);
    
    printf("%d %d\n", area, length);
    
    return 0;
}


Measured memory_bytes: 3212
# D - Dice in Line
from itertools import accumulate #累積和
n,k,*p = map(int,open(0).read().split())
ac = [0] + list(accumulate(p))
a = 0
for i in range(n-k+1): a = max(a, ac[i+k] - ac[i])
print((a+k)/2)

Measured memory_bytes: 25420
#include<bits/stdc++.h>
constexpr long long INFL = 1LL << 60;
constexpr int INF = 1e9;

using namespace std;

int main()
{
    int N,M,X;
    cin >> N >> M >> X;
    int A[110];
    for(int i = 0; i < M; ++i) cin >> A[i];
    int prise_left = 0;
    int prise_right = 0;
    sort(A, A+M);
    for(int i = 0; i < M; ++i){
        if(A[i] < X)
            prise_left++;
        else
            prise_right++;
    }

    cout << min(prise_left, prise_right) << endl;
    return 0;
}

Measured memory_bytes: 256
console.log((args=>{
  const [[K],A] = args.trim().split`\n`.map(r=>r.split` `.map(v=>v|0));
  if ( A[K-1] > 2 ) return '-1';
  let min = 2, max = 3;
  for ( let i = K-2; i >= 0; i-- ) {
    min = Math.ceil(min/A[i])*A[i];
    max = Math.floor(max/A[i])*A[i] + A[i] - 1;
    if ( max < A[i] || min > max ) return '-1';
  }
  return `${min} ${max}`;
})(require('fs').readFileSync('/dev/stdin', 'utf8')));


Measured memory_bytes: 40748
#include <iostream>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string.h>
#include <set>
#include <unordered_map>

using namespace std;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int a, b, c;
	cin >> a >> b >> c;
	cout << max(c-(a-b), 0) << '\n';
	return 0;
}

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

using i64 = int64_t;

int main(){
    int n, l, r;
    while(cin >> n >> l >> r, n != 0){
        vector<int> v;
        for(int i=0;i<n;++i){
            int tmp;
            cin >> tmp;
            v.push_back(tmp);
        }
        int ans = 0;
        for(int i=l;i<=r;++i){
            bool is_leap = false, exist = false;
            for(int j=0;j<v.size();++j){
                if(i%v[j] != 0)continue;
                if((j+1)%2 != 0)is_leap = true;
                else is_leap = false;
                exist = true;
                break;
            }
            if(!exist){
                if(n%2)is_leap = false;
                else is_leap = true;
            }
            if(is_leap)ans++;
        }
        cout << ans << endl;
    }

    return 0;
}



Measured memory_bytes: 3128
// eddy1021
#include <bits/stdc++.h>
using namespace std;
typedef double D;
typedef long double LD;
typedef long long ll;
typedef long long LL;
typedef pair<int,int> PII;
typedef pair<LL,LL> PLL;
typedef pair<LD,LD> Pt;
typedef tuple<int,int,int> tiii;
typedef tuple<LL,LL,LL> tlll;
#define mod9 1000000009ll
#define mod7 1000000007ll
#define INF  1023456789ll
#define INF16 10000000000000000ll
#define FI first
#define SE second
#define X FI
#define Y SE
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define eps 1e-9
#define SZ(x) (int)(x).size()
#define ALL(x) (x).begin(), (x).end()
#ifndef ONLINE_JUDGE
#define debug(...) printf(__VA_ARGS__)
#else 
#define debug(...)
#endif
inline ll getint(){
  ll _x=0,_tmp=1; char _tc=getchar();    
  while( (_tc<'0'||_tc>'9')&&_tc!='-' ) _tc=getchar();
  if( _tc == '-' ) _tc=getchar() , _tmp = -1;
  while(_tc>='0'&&_tc<='9') _x*=10,_x+=(_tc-'0'),_tc=getchar();
  return _x*_tmp;
}
inline ll add( ll _x , ll _y , ll _mod = mod7 ){
  ll _ = _x + _y;
  if( _ >= _mod ) _ -= _mod;
  return _;
}
inline ll sub( ll _x , ll _y , ll _mod = mod7 ){
  ll _ = _x - _y;
  if( _ < 0 ) _ += _mod;
  return _;
}
inline ll mul( ll _x , ll _y , ll _mod = mod7 ){
  ll _ = _x * _y;
  if( _ >= _mod ) _ %= _mod;
  return _;
}
ll mypow( ll _a , ll _x , ll _mod ){
  if( _x == 0 ) return 1ll;
  ll _tmp = mypow( _a , _x / 2 , _mod );
  _tmp = mul( _tmp , _tmp , _mod );
  if( _x & 1 ) _tmp = mul( _tmp , _a , _mod );
  return _tmp;
}
ll mymul( ll _a , ll _x , ll _mod ){
  if( _x == 0 ) return 0ll;
  ll _tmp = mymul( _a , _x / 2 , _mod );
  _tmp = add( _tmp , _tmp , _mod );
  if( _x & 1 ) _tmp = add( _tmp , _a , _mod );
  return _tmp;
}
inline bool equal( D _x ,  D _y ){
  return _x > _y - eps && _x < _y + eps;
}
int __ = 1 , _cs;
/*********default*********/
#define N 111
void build(){

}
int n;
vector<int> v;
void init(){
  n = getint();
  for( int i = 0 ; i < n + n ; i ++ )
    v.push_back( getint() );
  sort( ALL( v ) );
}
void solve(){
  int ans = 0;
  for( int i = 0 ; i < n + n ; i += 2 )
    ans += v[ i ];
  cout << ans << endl;
}
int main(){
  build();
  //__ = getint();
  while( __ -- ){
    init();
    solve();
  }
}


Measured memory_bytes: 256
def main():
    a=tuple(map(int,input().split()))
    e=set()
    while a not in e:
        for x in a:
            if x % 2 != 0:
                print(len(e))
                return
        e.add(a)
        a=((a[1]+a[2])//2,(a[0]+a[2])//2,(a[0]+a[1])//2)
    else:
        print(-1)
    
if __name__ == "__main__":
    main()

Measured memory_bytes: 9028
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
#include <vector>
#include <functional>
#include <queue>
#include <unordered_set>
#include <climits>

using namespace std;
typedef long long ll;

int main()
{
	ll N, M, X;
	ll C[20];
	ll A[20][20];
	ll ans = LONG_MAX;
	cin >> N >> M >> X;
	for(int i = 0; i < N; i++){
		cin >> C[i];
		for(int j = 0; j < M; j++){
			cin >> A[i][j];
		}
	}
	
	for(int bit = 0; bit < (1 << N); bit++){
		ll understand[20];
		ll money = 0;
		for(int i = 0; i < M; i++){
			understand[i] = 0;
		}
		for(int i = 0; i < N; i++){
			if((bit >> i) & 1){
				money += C[i];
				for(int j = 0; j < M; j++){
					understand[j] += A[i][j];
				}
			}
		}
		
		bool isOK = true;
		for(int i = 0; i < M; i++){
			if(understand[i] < X){
				isOK = false;
			}
		}
		
		if(isOK){
			ans = min(ans, money);
		}
	}
	if(ans == LONG_MAX){
		cout << -1 << endl;
	}else{
		cout << ans << endl;
	}
	
	return 0;
}

Measured memory_bytes: 3636
package main

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

var sc = bufio.NewScanner(os.Stdin)

func readInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func readString() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	sc.Split(bufio.ScanWords)
	n := readInt()
	s := readString()

	codeList := make(map[int]int, 0)
	for i := 0; i <= 999; i++ {
		str := strconv.Itoa(i)
		num := make([]int, 3)
		switch len(str) {
		case 1:
			num[0] = 0
			num[1] = 0
			num[2] = int(str[0] - '0')
		case 2:
			num[0] = 0
			num[1] = int(str[0] - '0')
			num[2] = int(str[1] - '0')
		case 3:
			num[0] = int(str[0] - '0')
			num[1] = int(str[1] - '0')
			num[2] = int(str[2] - '0')
		}

		k := 0
		for j := 0; j < n; j++ {
			if int(s[j]-'0') == num[k] {
				k++
				if k == 3 {
					codeList[i]++
					break
				}
			}
		}

	}
	fmt.Println(len(codeList))
}


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

vector<int> S;
int H;

void MaxHeapi(int i) {
  int l = 2 * i, r = 2 * i + 1, largest;
  if (l <= H && S[l] > S[i])
    largest = l;
  else
    largest = i;
  if (r <= H && S[r] > S[largest])
    largest = r;

  if (largest != i) {
    swap(S[i], S[largest]);
    MaxHeapi(largest);
  }
}

int ExtractMax() {
  if (H < 1)
    return -1;
  int max_k = S[1];
  S[1] = S[H];
  S.pop_back();
  --H;
  MaxHeapi(1);
  return max_k;
}

void HeapIncreaseKey(int i, int k) {
  if (k < S[i])
    return;
  S[i] = k;
  while (i > 1 && S[i / 2] < S[i]) {
    swap(S[i], S[i / 2]);
    i = i / 2;
  }
}

void Insert(int k) {
  ++H;
  S.push_back(-1);
  HeapIncreaseKey(H, k);
}

int main() {
  S.resize(1);
  while (true) {
    char O[8];
    scanf("%s", O);
    if (strcmp(O, "insert") == 0) {
      int k;
      scanf("%d", &k);
      Insert(k);
    } else if (strcmp(O, "extract") == 0) {
      printf("%d\n", ExtractMax());
    } else {
      break;
    }
  }
}


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

#define x first
#define y second
#define y1 Y1
#define y2 Y2
#define mp make_pair
#define pb push_back
#define DEBUG(x) cout << #x << " = " << x << endl;

using namespace std;

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

template <typename T> inline int Chkmax (T &a, T b) { return a < b ? a = b, 1 : 0; }
template <typename T> inline int Chkmin (T &a, T b) { return a > b ? a = b, 1 : 0; }
template <typename T> inline T read ()
{
	T sum = 0, fl = 1; char ch = getchar();
	for (; !isdigit(ch); ch = getchar()) if (ch == '-') fl = -1;
	for (; isdigit(ch); ch = getchar()) sum = (sum << 3) + (sum << 1) + ch - '0';
	return sum * fl;
}

inline void proc_status ()
{
	ifstream t ("/proc/self/status");
	cerr << string (istreambuf_iterator <char> (t), istreambuf_iterator <char> ()) << endl;
}

const int Maxn = 3e5 + 100;

int N, A, B;
int p, rest;

inline void process (int num)
{
	--rest;
	for (int i = p - num + 1; i <= p; ++i) printf("%d ", i);
	p -= num;
}

inline void Solve ()
{
	if (A + B > N + 1) { puts("-1"); exit(0); }
	if ((LL) A * B < N) { puts("-1"); exit(0); }
	p = N, rest = B;
	process (A);
	if (B == 1) return ;
	for (int i = 1; i <= B - 1; ++i)
	{
		int ave = p / rest;
		if (rest == 1) process (p);
		else process (ave);
	}
	puts("");
}

inline void Input ()
{
	N = read<int>(), A = read<int>(), B = read<int>();
}

int main()
{

#ifdef hk_cnyali
	freopen("E.in", "r", stdin);
	freopen("E.out", "w", stdout);
#endif

	Input ();
	Solve ();

	return 0;
}


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

int main(){
    ll a,b,c,d;
    cin >> a >> b >> c >> d;
    ll ans;
    ans = max(a*c,a*d);
    ans = max(ans,b*c);
    ans = max(ans,b*d);
    cout << ans << endl;
}

Measured memory_bytes: 3632
#include <iostream>
using  namespace std;
#define ll      long long int
#define pai     pair<int,int>
#define vi      vector<int>
#define vd      vector<double>
#define vs      vector<string>
#define vp      vector< pair <string,int> >
#define mpi     map<int,int>
#define mps     map<char,int>
#define sti     stack<int>
#define stc     stack<char>
#define sei     set<int>
#define ses     set<string>
#define multii  multiset<int>
#define forn(i,n)    for (int i = 0; i < n; i++)
#define fork(i,k,n)  for (int i = k; i <= n; i++)
#define forkr(i,k,n) for (int i = k; i >= n; i--)

 int main()
{
 ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
string s,t;
cin>>s;
cin>>t;
ll c=0;
forn(i,s.size()){
if(s[i]!=t[i]){
    c++;
}

}
cout<<c<<endl;

}






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

const int INF = 1000010;

int MCMP(int N, int R[], int C[]) {
    int dp[N][N];
    rep(i, N) rep(j, N) {
        if (i==j) dp[i][j] = 0;
        else dp[i][j] = INF;
    }
    for (int len=0; len<=N; len++) {
        for (int s=0; s+len<N; s++) {
            int left = s, right = s+len;
            for (int mid=left; mid<right; mid++) {
                int lmr_num;
                lmr_num = dp[left][mid] + dp[mid+1][right] + R[left] * C[mid] * C[right];
                dp[left][right] = min(dp[left][right], lmr_num);
                // cout << " " << left << " " << right << " " << mid << " " << dp[left][right] << endl;
            }
        }
    }
    return dp[0][N-1];
}


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

    int R[N], C[N];
    rep(i, N) cin >> R[i] >> C[i];

    cout << MCMP(N, R, C) << endl;

    return 0;
}




Measured memory_bytes: 3124
package main

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

const (
	initialBufSize = 100000
	maxBufSize     = 10000000
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wt = bufio.NewWriter(os.Stdout)
)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	i, _ := strconv.Atoi(next())
	return i
}

func puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, initialBufSize), maxBufSize)
	defer wt.Flush()

	a, b, c := nextInt(), nextInt(), nextInt()
	k := nextInt()

	for i := 0; i < k; i++ {
		if a >= b {
			b *= 2
		} else if b >= c {
			c *= 2
		}
	}

	if a < b && b < c {
		puts("Yes")
	} else {
		puts("No")
	}
}


Measured memory_bytes: 1780
#include <string>
#include <iostream>
#include <list>
int main () {
  std::list<char> buffer;
  int reverse = 0;
  std::string s;
  std::cin>>s;
  for (int i = 0 ; i < s.length() ; ++i ) {
    buffer.push_back(s[i]);
  }
  int Q;
  std::cin>>Q;

  for (int i = 0 ; i < Q ; ++i ) {
    int T;
    std::cin>>T;
    if (T == 1 ) {
      reverse = 1 - reverse;
    }
    else {
      int F;
      char C;
      std::cin>>F>>C;
      if (F == reverse +1) {
        buffer.push_front(C);
      }
      else {
        buffer.push_back(C);
      }
    }
  }
  if (reverse == 1 ) {
    buffer.reverse();
  }
  for (auto iter = buffer.begin() ; iter != buffer.end() ; ++iter ) {
    std::cout<<*iter;
  }

  return 0;
}


Measured memory_bytes: 9984
#include <bits/stdc++.h>
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define INF 999999999999999999
#define rep(i,m,n) for(lli i = m;i < n;i++)
#define rrep(i,m,n) for(lli i=m-1;i>=n;i--)
#define pb(n) push_back(n)
#define UE(N) N.erase(unique(N.begin(),N.end()),N.end());
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(),n.end())
#define Out(S) cout << S << endl
#define NeOut(S) cout << S
#define HpOut(S) cout << setprecision(25) << S << endl
#define Vec(K,L,N,S) vector<L> K(N,S)
#define DV(K,L,N,M,S) vector<vector<L>> K(N,vector<L>(M,S))
#define TV(K,L,N,M,R,S) vector<vector<vector<L>>> K(N,vector<vector<L>>(M,vector<L>(R,S)))
#define pint pair<lli,lli>
#define paf(L,R) pair<L,R>
#define mod 998244353
#define MAX 10000000
#define ALL(a)  a.begin(),a.end()
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
map<lli,lli>mp;
map<string,lli>mps;
map<char,lli>mpc;
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  lli A,B,C,D,E,F,N,M,K,L,X,Y,Z,H,W,sum=0,num=0,flag=0;string S,T;
  cin >> X;
  N=100;
  while(X>N){
    N+=N/100;
    sum++;
  }
  Out(sum);
}

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

int main(){
  int i,j,plen,slen,k;
  char s[200]={NULL},p[100]={NULL},pc[100]={NULL};
  
  scanf("%s",s);
  scanf("%s",p);
  
  slen = strlen(s);
  plen = strlen(p);
  for(i=0;i<slen;i++){
    s[slen+i]=s[i];
  }
  
  
  for(i=0;i<slen;i++){
    for(j=i,k=0;j<i+plen;j++,k++){
      pc[k]=s[j];
    }
    if(strcmp(p,pc)==0){
      puts("Yes");
      break;
    }
  }
  
  if(strcmp(p,pc)!=0) puts("No");

  return 0;
}

Measured memory_bytes: 524
def dfs(a, b, c, k, h)
  
  if k == N
    
    return nil if h[0] == 0 or h[1] == 0 or h[2] == 0
    ret = 0
    ret += 10 * (h[0] - 1)
    ret += 10 * (h[1] - 1)
    ret += 10 * (h[2] - 1)
  
    return ret + a.abs + b.abs + c.abs
  end
  
  h[0] += 1
  x = dfs(a-L[k], b, c, k+1, h)
  h[0] -= 1
  h[1] += 1
  y = dfs(a, b-L[k], c, k+1, h)
  h[1] -= 1
  h[2] += 1
  z = dfs(a, b, c-L[k], k+1, h)
  h[2] -= 1
  w = dfs(a, b, c, k+1, h)
  
  [x, y, z, w].compact.min
end

N, A, B, C = gets.split.map(&:to_i)

L = Array.new(N)
N.times{ |i| L[i] = gets.to_i }

p dfs(A, B, C, 0, [0,0,0])


Measured memory_bytes: 1916