akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INFLL (1LL<<62) // 9223372036854775807
#define EPS 1e-9
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
template<class T>bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; }
using namespace std;

int main(){
    Init();
    ll n, k, ans = INFLL;
    cin >> n >> k;
    vi x(n), y(n);
    rep(i, n) cin >> x[i] >> y[i];

    for(ll sx=0; sx<n; sx++){
        for(ll sy=0; sy<n; sy++){
            for(ll gx=0; gx<n; gx++){
                for(ll gy=0; gy<n; gy++){
                    ll cnt = 0;
                    for(ll i=0; i<n; i++){
                        if(x[sx] <= x[i] && x[i] <= x[gx] && y[sy] <= y[i] && y[i] <= y[gy]) cnt++;
                    }
                    if(cnt >= k) chmin(ans, (x[gx]-x[sx])*(y[gy]-y[sy]));
                }
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3660
import heapq
from collections import defaultdict
import sys
sys.setrecursionlimit(10**9)

def mi(): return map(int,input().split())
def ii(): return int(input())
def isp(): return input().split()
def deb(text): print("-------\n{}\n-------".format(text))

INF=10**20
def main():
    N,M=mi()
    X = defaultdict(lambda: [])
    for i in range(N):
        a,b=mi()
        X[a].append(b)
    
    Y = []
    heapq.heapify(Y)
    ans = 0
    for x in reversed(range(M)):
        ok = M-x
        for x in X[ok]:
            heapq.heappush(Y,-1 * x)
        
        if Y:
            y = heapq.heappop(Y)
            y *= -1
            ans += y

    print(ans)


    


if __name__ == "__main__":
    main()

Measured memory_bytes: 98780
#include<bits/stdc++.h>
using namespace std;
int rd(char c[]){
  int i, sz=0;
  for(;;){
    i = getchar_unlocked();
    if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){
      break;
    }
  }
  c[sz++] = i;
  for(;;){
    i = getchar_unlocked();
    if(i==' '||i=='\n'||i=='\r'||i=='\t'||i==EOF){
      break;
    }
    c[sz++] = i;
  }
  c[sz]='\0';
  return sz;
}
void wt_L(char a){
  putchar_unlocked(a);
}
void wt_L(int x){
  char f[10];
  int m=0, s=0;
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
template<class S, class T> inline S min_L(S a,T b){
  return a<=b?a:b;
}
int N;
char S[100002];
int main(){
  int c0=0, c1=0, i, res;
  N = rd(S);
  for(i=0;i<N;i++){
    if(S[i]=='0'){
      c0++;
    }
    else{
      c1++;
    }
  }
  res = 2*min_L(c0, c1);
  wt_L(res);
  wt_L('\n');
  return 0;
}
// cLay varsion 20190227-1 [beta]

// --- original code ---
// int N;
// char S[100002];
// {
//   int i, c0=0, c1=0, res;
//   rd(S@N);
//   rep(i,N){
//     if(S[i]=='0') c0++; else c1++;
//   }
//   res = 2min(c0,c1);
//   wt(res);
// }


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

int main()
{
    int i, j, ind=0, len;
    char s[150], t[150];
    char swap1, swap2;
    scanf("%s %s", s, t);
    len=strlen(s);
    for(i=0;i<len;i++)
    {
        swap1=s[0];
        s[0]=s[len-1];
        for(j=1;j<len;j++)
        {
            swap2=s[j];
            s[j]=swap1;
            swap1=swap2;
        }
        if(strcmp(s, t)==0)
        {
            ind=1;
            break;
        }
    }
    if(ind==0)
        printf("No\n");
    else
        printf("Yes\n");
    return 0;
}


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

#define REP(i,n) for(int i=0;i<n;++i)
#define RREP(i,n) for(int i=n-1;i>=0;--i)
#define FOR(i,m,n) for(int i=m;i<n;++i)
#define RFOR(i,m,n) for(int i=n-1;i>=m;--i)
#define ALL(v) v.begin(),v.end()
#define PB(a) push_back(a)
#define INF 1000000001
#define MOD 1000000007
#define EPS 1e-9

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

typedef long long ll;
using namespace std;


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, m;
	cin >> n >> m;
	bool g[8][8];
	REP(i, n)REP(j, n)g[i][j] = false;
	REP(i, m) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		g[a][b] = true;
		g[b][a] = true;
	}
	vector<int> v(n);
	REP(i, n) {
		v[i] = i;
	}
	int cnt = 0;
	do {
		if (v[0] != 0)break;
		int flag = 1;
		REP(i, n - 1) {
			if (!g[v[i]][v[i + 1]])flag = 0;
		}
		if (flag)cnt++;
	} while (next_permutation(ALL(v)));
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 256
#include<string>
#include<string.h>
#include<map>
#include<set>
#include<vector>
#include<stdio.h>
#include<math.h>
#include<iostream>
#include<algorithm>
#include<queue>


using namespace std;


int main()
{
    int a,b;
    cin>>a>>b;
    if((a*b)%2==0)
    cout<<"Even";
    else
    cout<<"Odd";
    system("pause");
    return 0;
}     

Measured memory_bytes: 504
import java.io.*;
import java.util.*;
class Main{
	static final long MOD = 1_000_000_007; // 10^9+7
	static final int MAX = 2_147_483_646; // intMax 
	static final int INF = 1_000_000_000; // 10^9  
	public static void main(String[] args) throws Exception{
		hayami saori = new hayami();
		int n = saori.saori_hayami();
		System.out.println(n+n*n+n*n*n);
		saori.close();
	}
}

class hayami implements Closeable {
	private final InputStream in = System.in;
	private final byte[] hayami = new byte[1024];
	private int Hayami = 0;
	private int saori = 0;
	private boolean HayamiSaori() {
		if (Hayami < saori) {
			return true;
		}else{
			Hayami = 0;
			try {
				saori = in.read(hayami);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (saori <= 0) {
				return false;
			}
		}
		return true;
	}
	private int SaoriHayami() { 
		if (HayamiSaori()) {
            return hayami[Hayami++];
         }else{
             return -1;
         }
	}
	private static boolean hayami_saori(int hayami) { 
		return 33 <= hayami && hayami <= 126;
	}
	public boolean hayamisaori() { 
		while(HayamiSaori() && !hayami_saori(hayami[Hayami])) Hayami++; return HayamiSaori();
	}
	public String nextHayami() {
		if (!hayamisaori()) throw new NoSuchElementException();
		StringBuilder hayamin = new StringBuilder();
		int saori = SaoriHayami();
		while(hayami_saori(saori)) {
			hayamin.appendCodePoint(saori);
			saori = SaoriHayami();
		}
		return hayamin.toString();
	}
	public long saorihayami() {//nextLong
		if (!hayamisaori()) throw new NoSuchElementException();
		long hayami = 0;
		boolean misao = false;
		int saori = SaoriHayami();
		if (saori == '-') {
			misao = true;
			saori = SaoriHayami();
		}
		if (saori < '0' || '9' < saori) {
			throw new NumberFormatException();
		}
		while(true){
			if ('0' <= saori && saori <= '9') {
				hayami *= 10;
				hayami += saori - '0';
			}else if(saori == -1 || !hayami_saori(saori)){
				return misao ? -hayami : hayami;
			}else{
				throw new NumberFormatException();
			}
			saori = SaoriHayami();
		}
	}
	public int saori_hayami() {//nextInt
		long hayami = saorihayami();
		if (hayami < Integer.MIN_VALUE || hayami > Integer.MAX_VALUE) throw new NumberFormatException();
		return (int) hayami;
	}
	public double Hayamin() { //nextDouble
		return Double.parseDouble(nextHayami());
	}
	public void close() {
		try {
			in.close();
		} catch (IOException e) {
		}
    }
    
}


Measured memory_bytes: 32400
#include<iostream>
using namespace std;
int main()
{
    int A,B;
    cin>>A>>B;
    if(A>=13)
    {
         cout<<B<<endl;
    }
       else if(A>=6&&A<=12)
       {
           cout<<B/2<<endl;
       }
       else
       {
           cout<<"0"<<endl;
       }
        return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include "math.h"
using namespace std;

vector<pair<long long, long long> > prime_factorize(long long N) {
    vector<pair<long long, long long> > res;
    for (long long a = 2; a * a <= N; ++a) {
        if (N % a != 0) continue;
        long long ex = 0;
        while (N % a == 0) {
            ++ex;
            N /= a;
        }
        res.push_back({a, ex});
    }
    if (N != 1) res.push_back({N, 1});
    return res;
}

int main() {
    int N;
    long long P;
    cin >> N >> P;
    const auto &pf = prime_factorize(P);
    long long res = 1;
    for (auto p : pf) {
        // for (int j = 0; j < p.second/N; ++j) res *= p.first;
        int tmp = int(p.second/N);
        // console.log(tmp)
        res *= pow(p.first,tmp);
    }
    cout << res << endl;
}

Measured memory_bytes: 3876
#include <iostream>
#include <complex>
using namespace std;
int main(void) {
int a, b, c, d, sa, ta, ru;

cin >> a;
cin >> b;
cin >> c;
cin >> d;
sa = std::abs(a-b);
ta = std::abs(b-c);
ru = std::abs(a-c);
if ( sa <= d && ta <= d ) {
    cout << "Yes" << endl;
} else if ( ru <= d) {
    cout << "Yes" << endl;
} else {
    cout << "No" << endl;
}

return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
typedef long long ll;
typedef long  l;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
const ll INF=1000000000000001;
const double PI=3.141592653589;

int waru(int a){
  int c=0;
  while(a%2==0){
    c++;
    a/=2;
  }
  return c;
}

int main(){
  int n; cin>>n;
  int ans=0;

  rep(i,n){
    int a; cin>>a;
    if(a%2==0){
      int g=waru(a);
      // cout<<"a "<<a<<" g "<<g<<endl;
      ans+=g;
    }
  }

  cout<<ans<<endl;


  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(ll i=ll(a);i<ll(b);i++)
#define irep(i,a,b) for(ll i=ll(a);i>=ll(b);i--)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define pb push_back
#define mp make_pair
#define F .first
#define S .second 
#define pll pair<ll,ll>
using ll=long long;
using ld=long double;
const ll INF = 1LL<<60;
const ll mod=1e9+7;
using namespace std;
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
const ll MAX=10000;
long long modpow(ll a, ll b) {
    ll res=1;
    while (b) {
        if (b&1)res=res*a%mod;
        a=a*a%mod;
        b>>=1;
    }
    return res;
}
ll fac[MAX], finv[MAX], inv[MAX];


// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % mod;
        inv[i] = mod - inv[mod%i] * (mod / i) % mod;
        finv[i] = finv[i - 1] * inv[i] % mod;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}

int main(){
    COMinit();

    ll s,ans=0;
    cin>>s;
    ll z=s;
    ll c=1;
    
    while(z>0){
        z=s-c*3;
        ans+=COM(z+c-1,c-1);
        c++;
    }
    cout<<ans%mod;
}



Measured memory_bytes: 3856
W, H, N = map(int, input().split())
xmax = W
xmin = 0
ymax = H
ymin = 0

for i in range(N):
    x, y, a = map(int, input().split())
    if a == 1:
        xmin = max(xmin, x)
    elif a == 2:
        xmax = min(xmax, x)
    elif a == 3:
        ymin = max(ymin, y)
    else:
        ymax = min(ymax, y)

print(max(0, (ymax - ymin)) * max(0, (xmax - xmin)))

Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<cstring>
using namespace std;
typedef long long ll;
#define ip(arr, n) for(int i=0; i<n; i++) cin>>arr[i];
#define op(arr, n) for(int i=0; i<n; i++) cout<<arr[i]<<" ";
#define fstIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define MAX 100005

ll n,capacity;
ll price[100], wt[100];
ll dp[105][MAX];

void bottomUp(){
    memset(dp, 0, sizeof(dp));
    for(int i=0; i<=n; i++){
        for(int j=0; j<=capacity; j++){
            if(i==0||j==0){
                dp[i][j]=0;
            }
            else if(j>=wt[i-1]){
                dp[i][j] = max(dp[i-1][j], price[i-1]+dp[i-1][j-wt[i-1]]);
            }
            else{
                dp[i][j] = dp[i-1][j];
            }
        }
    }
    cout<<dp[n][capacity]<<endl;
}

int main(){
    cin>>n>>capacity;
    for(int i=0; i<n; i++){
        cin>>wt[i]>>price[i];
    }
    bottomUp();
    return 0;
}

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

Measured memory_bytes: 128
def resolve():
    '''
    code here
    '''
    import collections
    import itertools
    N = int(input())
    Ss = [input()[0] for _ in range(N)]

    march_letter = [item for item in Ss if item in ['M', 'A', 'R', 'C', 'H']]
    march_cnt = collections.Counter(march_letter)

    if len(march_cnt) < 3:
        res = 0
    else:
        res_list = itertools.combinations(march_cnt.values(),3)

        res = 0
        for element in res_list:
            res += element[0]*element[1]*element[2]
    print(res)

if __name__ == "__main__":
    resolve()


Measured memory_bytes: 10528
// see https://github.com/LumaKernel/vimfiles/tree/master/snippets/cp-cpp/temp.snip
/// --- .lumrc Template {{{ ///
// #define DEBUG
// #define assert(...)
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using P = tuple<ll, ll>;
using P3 = tuple<ll, ll, ll>;
using VI = vector<int>;
using VL = vector<ll>;
using VVI = vector<VI>;
using VVL = vector<VL>;
using VP = vector<P>;
using VS = vector<string>;

#define omajinai ios::sync_with_stdio(false),cin.tie(0)

#define FOR(i,a,b) for(int i=int(a);i<int(b);++i)
#define FORI(i,a,b) for(int i=int(a);i<=int(b);++i)
#define REP(i,n) FOR(i,0,n)
#define REPI(i,n) FORI(i,0,n)
#define RFOR(i,a,b) for(int i=int(b)-1;i>=int(a);--i)
#define RFORI(i,a,b) for(int i=int(b);i>=int(a);--i)
#define RREP(i,n) RFOR(i,0,n)
#define RREPI(i,n) RFORI(i,0,n)

#define ALL(a) begin(a),end(a)
#define UNIQUE(a) (a).erase(unique(ALL(a)),(a).end())
#define PB push_back
#define EACH(i,c) REP(i,(c).size())
#define REACH(i,c) RREP(i,(c).size())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(ALL(c))

#define BR cout<<"\n";

#ifdef DEBUG
#define dump(...) cerr<<"["<<__LINE__<< "] "<<#__VA_ARGS__<<" = "<<make_tuple(__VA_ARGS__)<<"\n";
#else
#define dump(...)
#endif

#define YES(x) cout<<((x)?"YES":"NO")<<"\n";
#define Yes(x) cout<<((x)?"Yes":"No")<<"\n";
#define yes(x) cout<<((x)?"yes":"no")<<"\n";

int __int_temp; ll __ll_temp; string __string_temp;
#define oini (omajinai, cin>>__int_temp, __int_temp)
#define oinl (omajinai, cin>>__ll_temp, __ll_temp)
#define oins (omajinai, cin>>__string_temp, __string_temp)
#define ini (cin>>__int_temp, __int_temp)
#define inl (cin>>__ll_temp, __ll_temp)
#define ins (cin>>__string_temp, __string_temp)

#define isInside(y,x) (0<=(y)&&(y)<h&&0<=(x)&&(x)<w)

#define fi(x) (get<0>(x))
#define se(x) (get<1>(x))
#define th(x) (get<2>(x))
#define fo(x) (get<3>(x))
#define fif(x) (get<4>(x))

template <typename T> ostream &operator<<(ostream &o, const vector<T> &v) { o << '{'; EACH(i, v) o << v[i] << (i != (int)v.size()-1 ? ", " : ""); o << "}";  return o; }

template<int n, class...T> typename enable_if<(n>=sizeof...(T))>::type _ot(ostream &, tuple<T...> const &){}
template<int n, class...T> typename enable_if<(n< sizeof...(T))>::type _ot(ostream & os, tuple<T...> const & t){ os << (n==0?"":", ") << get<n>(t); _ot<n+1>(os, t); }
template<class...T> ostream & operator<<(ostream & os, tuple<T...> const & t){ _ot<0>(os, t); return os; }

template <typename T> inline void smax(T &a, T b) { a = a > b ? a : b; }
template <typename T> inline void smin(T &a, T b) { a = a < b ? a : b; }

template<typename T> inline int intlog2(T x);
template<> inline int intlog2(int x) { return x == 0 ? 0 : 32 - __builtin_clz(x); }
template<> inline int intlog2(ll x) { return x == 0 ? 0 : 64 - __builtin_clzll(x); }

constexpr double PI = acos(-1);

/// }}}--- ///

constexpr int INF = 1e9+1;
constexpr ll LINF = 1e18+1;
constexpr int MOD = 1e9+7;

int main() {
  cout<<ini/3<<endl;
}


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

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    long h = Long.parseLong(in.readLine());
    
    long multiple = 1;
    for(long i=h; i>0; i/=2) {
      multiple *= 2;
    }
    
    System.out.println(multiple-1);
  }
}

Measured memory_bytes: 32684
#include<bits/stdc++.h>
#define ll long long int 
#define mod 1000000007
#define modulo 998244353
#define endl '\n'
using namespace std;
ll fxp(ll a, ll b)
{
    if(b == 0)return 1;
	if(b%2 == 0){
		ll c = fxp(a,b/2);
		return (c*c)%1000000007;
	}
	return (a*fxp(a,b-1))%1000000007;
}
int lcm(int c,int d)
{
    int a=c;
    int b=d;
    int ans;
    if(a>=b)
    {
        while(b!=0)
        { 
            int x=b;
            b=a%b;
            a=x;
        }
        ans = ( c*d)/a;
    }
    else
    {
        while(a!=0)
        {
            int x=a;
            a=b%a;
            b=x;
        }
        ans = ( c*d)/b;  
    }
    return ans;
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin>>n;
    int happ[n][3];
    for(int i=0;i<n;i++)
        cin>>happ[i][0]>>happ[i][1]>>happ[i][2];
    ll dp[n][3];
    for(int i=0;i<3;i++)
     dp[n-1][i]=happ[n-1][i];
    for(int i=n-2;i>=0;i--)
    {
        dp[i][0]= happ[i][0]+ max(dp[i+1][1],dp[i+1][2]);
        dp[i][1]= happ[i][1]+ max(dp[i+1][0],dp[i+1][2]);
        dp[i][2]= happ[i][2]+ max(dp[i+1][1],dp[i+1][0]);
    }
    ll t = max(dp[0][1],dp[0][2]);
    ll ans = max(t,dp[0][0]);
    cout<<ans<<endl;
    
    return 0;
}

Measured memory_bytes: 7100
#include<stdio.h>

int S[100000];
int N;

int binarySerch(int);

int main(){
int q, T[50000], i, c = 0;

  scanf("%d",&N);
  for(i = 0 ; i < N ; i++)
    scanf("%d",&S[i]);

  scanf("%d",&q);
  for(i = 0 ; i < q ; i++){
    scanf("%d",&T[i]);
    if(1 == binarySerch(T[i])){
      c++;
    }
  }
  printf("%d\n",c);
  return 0;

}

int binarySerch(int key){
  int mid;
  int left = 0;
  int right = N;
  while(left < right){
    mid = (left + right)/2;
    if(S[mid] == key)
      return 1;
    else if(key < S[mid])
      right = mid;
    else 
      left = mid + 1;
  }
  return 0;
}

Measured memory_bytes: 1180
A1 = [int(x) for x in input().split()]
A2 = [int(x) for x in input().split()]
A3 = [int(x) for x in input().split()]
n = int(input())
listA = [int(input()) for _ in range(n)]

list_bingo = [A1,A2,A3]

def check_bingo(list_bingo, N):
    for i in range(3):
        if list_bingo[i][0] == list_bingo[i][1] == list_bingo[i][2] == N or \
         list_bingo[0][i] == list_bingo[1][i] == list_bingo[2][i] == N:
            print('Yes')
            return
    if list_bingo[0][0] == list_bingo[1][1] == list_bingo[2][2] == N or \
    list_bingo[0][2] == list_bingo[1][1] == list_bingo[2][0] == N: 
        print('Yes')
        return
        
    print('No')
    return

listA = list(set(listA))
for i in range(len(listA)):
    for j in range(3):
        if listA[i] in list_bingo[j]:
            list_bingo[j][list_bingo[j].index(listA[i])] = 101
            
check_bingo(list_bingo, 101)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define sz(x) int((x).size())
#define debug(x) cout << #x << ":" << x << ' ';
#define debugg(x) cout << #x << ":" << x << ' ' << "\n";
#define endl '\n'
#define ff first
#define ss second
#define L(X) ((X)<<1)
#define R(X) (((X)<<1)|1)
#define M(X,Y) (((X)+(Y))>>1)

using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int MAXN = 1e5 + 5;
const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const long long int LLINF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-9;
const double PI = acos(-1);

template<typename T>   T add(T x, T y, T m) { return ((x % m)  + (y % m)) % m;}
template<typename T>   T mul(T x, T y, T m) { return ((x % m) * (long long)(y % m)) % m;}
template<typename T>   T sub(T x, T y, T m) { return add(x, -y + m);}
template<typename T>   T gcd(T a, T b) { return b ? gcd(b, a % b) : a;}
template<typename T>   T lcm(T a, T b) { return a / gcd(a, b) * b;}

int lg2(long long x)   {   return 64 - __builtin_clzll(x) - 1;	}
int lg2(int x)   {   return 32 - __builtin_clzll(x) - 1;	}

struct pair_hash{
	template<class T1, class T2>
	size_t operator() (const pair<T1, T2> &p) const {
		auto h1 = hash<T1>{}(p.first);
		auto h2 = hash<T2>{}(p.second);
		return h1 ^ h2;
	}
};

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

	ll h;
	cin >> h;

	int k = floor(log2(h)) + 1;

	ll ans = 0;

	for(ll i = 0 ; i < k ; ++i) {
		ans += (1LL << i);
	}

	cout << ans << endl;

	return 0;
}

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

const int MAXN = 1000;
int n, m;
bool flag[MAXN];

int main() {
  while(cin >> n >> m && (n|m)) {
    fill(flag, flag+MAXN, true);
    for(int i = 0, j = 0; i < n-1; ++i) {
      for(int k = 0; ; j = (j+1)%n) {
        if(flag[j]) {
          if(++k == m) break;
        }
      }
      flag[j] = false;
    }
    for(int i = 0; i < n; ++i) {
      if(flag[i]) {
        cout << i+1 << endl;
        break;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 1160
n, m = map(int, input().split())
lst = [0] * n
ac = 0
wa = 0
for i in range(m):
  p, s = input().split()
  p = int(p)
  s = True if s == 'AC' else False
  if lst[p - 1] >= 0:
    if s:
      ac += 1
      wa += lst[p - 1]
      lst[p - 1] = -1
    else:
      lst[p - 1] += 1
print(ac, wa)

Measured memory_bytes: 3828
N = input()
V = list(input().split())
C = list(input().split())
n = 0
list_P =[]
#V-C = 差額P
while n < len(V):
    Vn = int(V[n])
    Cn = int(C[n])
    Pn = Vn -Cn
    list_P.append(Pn)
    n += 1

MAX = 0
for X in list_P:
    if X > 0:
        MAX += X
    else:
        continue

print(MAX)

Measured memory_bytes: 3064
from sys import stdin


def get_result(data):
    # N = int(data[0][0])
    S = data[1][0]
    r_index = [i for i in range(len(S)) if S[i] == 'R']
    g_index = [i for i in range(len(S)) if S[i] == 'G']
    b_index = set([i for i in range(len(S)) if S[i] == 'B'])
    all_case = len(r_index) * len(g_index) * len(b_index)
    invalid_case = 0
    for i in r_index:
        for j in g_index:
            s_i, s_j = sorted([i, j])
            tmp_max_b = s_j + (s_j-s_i)
            if tmp_max_b in b_index:
                invalid_case += 1
            tmp_min_b = s_i - (s_j-s_i)
            if tmp_min_b in b_index:
                invalid_case += 1
            tmp_mid_b = (s_i + s_j) / 2
            if tmp_mid_b in b_index:
                invalid_case += 1
    return all_case - invalid_case


if __name__ == '__main__':
    raw_data = [val.rstrip() for val in stdin.readlines()]
    data = [list(map(str, val.split(' '))) for val in raw_data]
    result = get_result(data)
    print(result)


Measured memory_bytes: 9196
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <limits.h>
#include <math.h>
#include <functional>
#include <bitset>

#define repeat(i,n) for (long long i = 0; (i) < (n); ++ (i))
#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i] << '\n'
#define debugArrayP(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i].first<< " " << x[i].second << '\n'

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef vector<int> vint;
typedef vector<ll> vll;
const ll INF = INT_MAX;
const ll MOD = 1e9+7;


template <ll mod>
struct ModCombination{
    ll N;
    vector<ll> fact,inv,finv;

    ModCombination(ll n):N(n){
        fact.assign(n+1, 1);
        inv.assign(n+1, 1);
        finv.assign(n+1,1);
        for(int i=1;i<n;i++){
            fact[i+1] = fact[i]*(i+1)%mod;
            inv[i+1] = inv[mod%(i+1)]*(mod-mod/(i+1))%mod;
            finv[i+1] = finv[i]*inv[i+1]%mod;
        }
    }

    ll Comb(ll n,ll k){
        return (fact[n]*finv[k]%mod)*finv[n-k]%mod;
    }
};


ll sum[112345];
int main(){
  int N;cin>>N;
  ModCombination<MOD> C(N);
  sum[1] = C.fact[N-1];
  ll dif = C.fact[N-2];
  repeat(i,N-1){
    sum[i+2] = sum[i+1] + dif;
    dif = dif*(N-i)%MOD*C.inv[N-i-2]%MOD;
  }
  //debugArray(sum,N+1);
  repeat(i,N){
    sum[i+1]=(sum[i+1]+sum[i])%MOD;
  }
  //debugArray(sum,N+1);
  vll A(N);
  repeat(i,N){
    cin>>A[i];
  }
  ll ans = 0;
  repeat(i,N){
    ans = (ans + A[i]*(sum[N]-sum[N-i-1]+sum[N-1]-sum[i+1-1]+MOD)%MOD)%MOD;
    //debug(ans);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4224
#include <stdio.h>
#include <stdlib.h>

int main() {
	int n, m;
	scanf("%d%d", &n, &m);
	int **a = (int**)malloc(sizeof(int*) * n);
	for (int i = 0; i < n; i++) {
		a[i] = (int*)malloc(sizeof(int) * m);
	}
	int* b = (int*)malloc(sizeof(int) * m);
	int* c = (int*)malloc(sizeof(int) * m);

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

	
	for (int i = 0; i < m; i++) {
		scanf("%d", &b[i]);
	}

	for (int i = 0; i < n; i++) {
			c[i] = 0;
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			c[i] = c[i] + a[i][j] * b[j];
		}
	}
	for (int i = 0; i < n; i++) {
		printf("%d\n", c[i]);
	}
	

}



Measured memory_bytes: 2120
#include <iostream>
 
using namespace std;
 
int main(){
    int prime[10001],p = 3,psum[10001],n;
    prime[1] = 2,prime[2] = 3;
    for(int i=5;p < 10001;i++){
        int f = 0;
        for(int j=1;prime[j]*prime[j] <= i;j++) if(i % prime[j] == 0) {f = 1;break;}
        if(!f) prime[p++] = i;
    }
    psum[1] = 2;
    for(int i=2;i < 10001;i++) psum[i] = psum[i-1] + prime[i];
    while(1){
        cin >> n;
        if(!n) break;
        cout << psum[n] << endl;
    }
         
    return 0;
}

Measured memory_bytes: 1236
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int x = sc.nextInt();
		int y = sc.nextInt();
		int money = 0;
		if(2 * c < a + b) {
			int large = Math.max(x, y);
			int min = Math.min(x, y);
			money += min * 2 * c;
			int nokori = Math.abs(x-y);
			if(nokori != 0){
				if(c * 2 < (x < y ? b : a)) money += c * nokori * 2;
				else money += (x < y ? b : a) * nokori;
			}
		}else{
			money += a * x + b * y;
		}
		System.out.println(money);

	}
}

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

using namespace std;

typedef long long ll;
const ll MOD=1000000007;

ll a,b;

ll fact(ll x){
    ll sol=1,i;
    for(i=1;i<=x;i++){
        sol=(ll)sol*i%MOD;
    }
    return sol;
}

int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin>>a>>b;
    if(a>b)
        swap(a,b);
    /// a<=b
    ll dif=b-a;
    if(dif>=2){
        cout<<"0\n";
    }
    if(dif==0){
        cout<<2*fact(a)%MOD*fact(b)%MOD<<"\n";
    }
    if(dif==1){
        cout<<fact(a)*fact(b)%MOD<<"\n";
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
main()
{
    long long int a,b,c,x,y,z;
    cin>>a>>b>>c;
    vector<long long int>v;
    for(int i=0;i<10;i++)
    {
        x=a*c-b;
        c=x;
        v.push_back(x);
    }
    for(int i=0;i<10;i++) cout<<v[i]<<endl;


}


Measured memory_bytes: 256
//Simple Calculator
#include <cstdio>
typedef long long lint;
lint abs(lint x) {return x>0?x:-x;}
int main()
{
	lint x,y;
	scanf("%lld%lld",&x,&y);
	lint dlt=abs(abs(x)-abs(y));
	if(x*y>=0 && x<=y) {printf("%lld",dlt); return 0;}
	if(x*y>0 && x>y) {printf("%lld",dlt+2); return 0;}
	if(x*y==0 && x>y) {printf("%lld",dlt+1); return 0;}
	if(x*y<0) {printf("%lld",dlt+1); return 0;}
}

Measured memory_bytes: 128
import itertools

if __name__ == '__main__':

	n = int(input())

	now = tuple(map(int,input().split()))

	seq = [i+1 for i in range(n)]
	seq2 = list(itertools.permutations(seq))

	ind = 0
	for j,k in enumerate(seq2):
		if k == now:
			ind = j

	if ind == 0:
		print(*seq2[ind])
		if len(seq2) != 1:
			print(*seq2[ind+1])
	elif ind+1 == len(seq2):
		print(*seq2[ind-1])
		print(*seq2[ind])
	else:
		print(*seq2[ind-1])
		print(*seq2[ind])
		print(*seq2[ind+1])



Measured memory_bytes: 52364
#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 DEL(v) decltype(v)().swap(v)
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define NL cerr << 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;
}
template<typename T1, typename T2> ostream& operator << (ostream& s, const P<T1,T2>& p) {
   s << "(" << p.first << "," << p.second << ")";
   return s;
}

int N, A, B;
V<int> h;

bool check(int m) {
   int sum = 0;
   REP(i, h.size()) {
      sum += (max(0LL,h[i] - B*m) + (A-B-1)) / (A-B);
   }
   return sum <= m;
}

int binary_search(int MAX)
{
   int m, l = -1, r = MAX;
   while (r - l > 1) {
      m = (l + r) / 2;
      if (check(m)) {
         r = m;
      } else {
         l = m;
      }
   }
   return r;
}

signed main()
{
   cin >> N >> A >> B;
   h.resize(N);
   int hmax = -1;
   REP(i, N) {
      cin >> h[i];
      hmax = max(hmax, h[i]);
   }
   int ans = binary_search(hmax);
   cout << ans << endl;

   return 0;
}


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

int main() {

    int x;
    char y[105];

    scanf("%d %s", &x, y);

    if(x % 2 == 0 && memcmp(y, y + x / 2, x / 2) == 0) {
        printf("Yes\n");
    } else {
        printf("No\n");
    }

    return 0;
}

Measured memory_bytes: 1656
#include <bits/stdc++.h>
#include <iterator>
#include <string>
#define pan(i,n) for(int i=0;i<n;i++)
#define ll long long int
#define vi vector<int>
#define pb push_back
#define INF 1e9+7
#define PI 3.141592653
#define inf 100007
using namespace std;


int main(){
    string s,t,ans;
    cin>>s>>t;
    int n=s.size(),ts=t.size(),index=0;
    bool found=false;
    for(int i=n-ts;i>=0;i--){
        int fs=0;
        if(s[i]==t[0] || s[i]=='?'){
            for(int j=0;j<ts;j++){
                if((s[i+j]==t[j]) || (s[i+j]=='?')) fs++;
            }
        }
        if(fs==ts){
            index=i;
            found=true;
            break;
        }
    }
    if(!(found)) ans="UNRESTORABLE";
    else{
        int q=0;
        for(int i=0;i<n;i++){
            if(i==index){
                int j=0;
                for(j;j<ts;j++){
                    ans+=t[j];
                }
                i+=j;
                i--;
            }
            else if(s[i]=='?') ans+='a';
            else ans+=s[i];
        }
    }
    cout<<ans;
}   

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

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return b/gcd(a,b)*b;}

int main() {
  ll n;
  cin >> n;
  vector<vector<ll>> a(2, vector<ll>(n));
  rep(i, n) cin >> a[0][i];
  rep(i, n) cin >> a[1][i];
  ll result = 0;
  int row = 0;
  rep(i, n) {
    ll ans = 0;
    row = 0;
    rep(j, n) {
      ans += a[row][j];
      //cout << "row: " << row << ", j: " << j << endl;
      if (i == j) {
        row = 1;
        ans += a[row][j];
      }
    }
    result = max(result, ans);
  }
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
const ll MOD = 1000000007;
const ll INF = 2147483647;
const ll LINF = 9223372036854775807;
#define REP(i, n) for(int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()

int main() {
	ll h, n; cin >> h >> n;
	VI a(n), b(n); REP(i, n)cin >> a[i] >> b[i];
	VVI dp(n + 1, VI(h + 1, INF));
	REP(i, n)dp[i][0] = 0;
	REP(i, n)REP(j, h + 1)dp[i + 1][j] = min(dp[i][j], dp[i + 1][max((ll)0,j - a[i])] + b[i]);
	cout << dp[n][h];
}

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




#define  rep(i, n ) for (int i=0;i<int(n);i++)
//dp ナップサック問題
int main(){
  int H,N;
  cin>>H>>N;
  vector<int> A(N),B(N);
  rep(i,N)
    cin>>A[i]>>B[i];
  int dp[1010][10010];
  //価値= dp[iまで][重さj以下]
  rep(i,N+1){
    rep(j,H+1){
      if(i==0)
        dp[i][j]=100000000;
      if(j==0)
        dp[i][j]=0;
      if(i!=0&&0<j<A[i-1]){
        //cout<<"hi";
        dp[i][j]=min(B[i-1],dp[i-1][j]);
      }
      if(i!=0&&j>=A[i-1]){
        //cout<<"si"<<i<<j;
        dp[i][j]=min(dp[i-1][j],dp[i][j-A[i-1]]+B[i-1]);
      }
    }
  }
  cout<<dp[N][H];
}

Measured memory_bytes: 39680
#include <algorithm> // std::sort(begin,end), std::min, std::max
#include <iostream>
#include <queue>
#include <string>
#include <unordered_map>
#include <utility> // std::swap
#include <vector>

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

template <typename T> // 0<1<2<3<4
using pq_asc = priority_queue<T, vector<T>, greater<T>>;
template <typename T> // 0>1>2>3>4
using pq_dsc = priority_queue<T>;

int main(int argc, char const *argv[]) {

  int n, m, from, to, s, t;
  cin >> n >> m;
  vector<vector<int>> g(n);
  bool visited[n] = {};
  for (int i = 0; i < m; i++) {
    cin >> from >> to;
    g[from - 1].push_back(to - 1);
  }

  cin >> s >> t;
  s--;
  t--;

  visited[s] = true;
  queue<pair<int, int>> q;
  q.push(make_pair(s, 0));

  for (int i = 0; i < n && !q.empty(); i++) {
    pair<int, int> p = q.front();
    // cerr << "(" << p.first << "," << p.second << ")" << endl;
    q.pop();
    for (auto p1 : g[p.first]) {
      for (auto p2 : g[p1]) {
        for (auto p3 : g[p2]) {
          if (!visited[p3]) {
            visited[p3] = true;
            if (p3 == t) {
              cout << p.second + 1 << endl;
              return 0;
            } else {
              q.push(make_pair(p3, p.second + 1));
            }
          }
        }
      }
    }
  }
  cout << -1 << endl;

  return 0;
}


Measured memory_bytes: 5760
program main
implicit none
integer(8) :: l, r, i, j, res

read(*,*) l, r
if( r - l .ge. 2019 ) then 
   write(*,'(i0)') 0
   stop
else
   res = 2018
   do i = l, r-1
      do j = i+1, r
         if( mod( mod(i,2019)*mod(j,2019), 2019 ) .le. res ) then
            res = mod( mod(i,2019)*mod(j,2019), 2019 )
         end if
      end do
   end do
   write(*,'(i0)') res
end if
end program main


Measured memory_bytes: 896
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define D()
#define INF 1000000000000
#define MOD 10000007
#define MAXR 100000
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define INITA(a,i,j,v) for(ll k=i;k<=j;k++){a[k]=v;}

int main() {
    ll n, a, b, c, d, e; cin >> n >> a >> b >> c >> d >> e;
    ll mx = 5;
    mx = max((double) mx, 4 + ceil((double) n / a));
    mx = max((double) mx, 4 + ceil((double) n / b));
    mx = max((double) mx, 4 + ceil((double) n / c));
    mx = max((double) mx, 4 + ceil((double) n / d));
    mx = max((double) mx, 4 + ceil((double) n / e));
    cout << mx << endl;
    return 0;
}

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

int main() {
  int n, m;
  cin >> n >> m;
  vector<P> p(m);
  rep(i,m) cin >> p[i].first >> p[i].second;
  rep(x,1000) {
    int keta = 1;
    int nx = x/10;
    vector<int> d(1,x%10);
    while (nx) {
      keta++;
      d.push_back(nx%10);
      nx /= 10;
    }
    if (keta != n) continue;
    bool ok = true;
    reverse(d.begin(), d.end());
    rep(i,m) {
      if (d[p[i].first-1] != p[i].second) ok = false;
    }
    if (ok) {
      cout << x << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}


Measured memory_bytes: 256
def resolve():
    A_list = list(map(int,input().split()))

    A_sum = 0

    for i in A_list:
        A_sum += i

    if 22 <= A_sum:
        answer = "bust"
    else:
        answer = "win"

    print(answer)

if __name__ == "__main__":
    resolve()

Measured memory_bytes: 2940
import java.util.Scanner;
class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    int a = scan.nextInt();
    int b = scan.nextInt();
    int sum = 0;
    int ans = 0;
    while(sum+1 < b){
      ans++;
      sum += (a-1);
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 21844
#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;

ll dist[110][110];
ll INF = 5E+7 * 100;


int main() {
    int V, E;
    cin >> V >> E;

    rep(i, V) rep(j, V) {
        if (i==j) dist[i][j] = 0;
        else dist[i][j] = INF;
    }

    int si, ti, di;
    rep(i, E) {
        cin >> si >> ti >> di;
        dist[si][ti] = di;
    }

    ll min_dist = INF;
    bool neg_cycle = false;

    rep(i, V) rep(j, V) rep(k, V) {
        if ((dist[i][k] != INF) && (dist[k][j] != INF)) {
            dist[i][j] = min(dist[i][j], dist[i][k]+dist[k][j]);
        }
        min_dist = min(min_dist, dist[i][j]);
    }
    rep(i, V) rep(j, V) rep(k, V) {
        if ((dist[i][k] != INF) && (dist[k][j] != INF)) {
            dist[i][j] = min(dist[i][j], dist[i][k]+dist[k][j]);
        }
        min_dist = min(min_dist, dist[i][j]);
    }


    rep(i, V) rep(j, V) rep(k, V) {
        if ((dist[i][k] != INF) && (dist[k][j] != INF)) {
            dist[i][j] = min(dist[i][j], dist[i][k]+dist[k][j]);
        }
        if (min_dist > dist[i][j]) {
            neg_cycle = true;
            break;
        }
    }

    if (neg_cycle) cout << "NEGATIVE CYCLE" << endl;
    else {
        rep(i, V) {
            rep(j, V) {
                if (dist[i][j] >= INF) cout << "INF";
                else cout << dist[i][j];
                if (j<V-1) cout << " ";
            }
            cout << endl;
        } 
    }

    return 0;
}




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

using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

ll Pow(ll A, ll N){
  if (N == 0) return 1;
  else if (N % 2 == 0) return Pow(A*A%MOD, N/2);
  else return A * Pow(A*A%MOD, N/2)%MOD;
}

int N, a[int(1e5+5)];
int mark = 0, cnt = 0;
bool visited[int(1e5+5)];
ll A, B, C;
ll abc[int(1e5+5)], ac[int(1e5+5)], bc[int(1e5+5)], cc[int(1e5+5)];

int main(){
  cin >> N;
  for (int i = 0; i <= N; i++){
    cin >> a[i];
    if (visited[a[i]]) mark = a[i];
    visited[a[i]] = true;
  }

  for (int i = 0; i <= N; i++){
    if (a[i] == mark){
      cnt++; continue;
    }
    if (cnt == 0) A++;
    if (cnt == 1) B++;
    if (cnt == 2) C++;
  }

  abc[0] = 1; 
  for (ll i = 1; i <= A+B+C; i++){
    abc[i] = abc[i-1] * (A+B+C+1-i) % MOD;
    abc[i] *= Pow(i, MOD-2); abc[i] %= MOD;
  }

  bc[0] = 1;
  for (ll i = 1; i <= A + C; i++){
    bc[i] = bc[i-1] * (A+C+1-i) % MOD;
    bc[i] *= Pow(i, MOD-2); bc[i] %= MOD;
  }

  for (int i = 1; i <= N + 1; i++){
    ll ans = abc[i];
    ans += 2 * abc[i-1] - bc[i-1];
    if (i > 1) ans += abc[i-2];

    ans %= MOD;
    if (ans < 0) ans += MOD;
    cout << ans << endl;
  }

  return 0;
}


Measured memory_bytes: 5516
from collections import deque

S = input()
Q = int(input())
query = [input() for _ in range(Q)]

S = deque(S)

inv = 0
for q in query:
    if q[0] == "1":
        inv += 1
    else:
        _, f, c = q.split()
        if f == "1":
            if inv % 2 == 0:
                S.appendleft(c)
            else:
                S.append(c)
        else:
            if inv % 2 == 0:
                S.append(c)
            else:
                S.appendleft(c)
S = "".join(S)
print(S if inv % 2 == 0 else S[::-1])


Measured memory_bytes: 98392
#include<iostream>

using namespace std;

int main(){
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    if(a+b>c+d)cout << "Left" << endl;
    else if (a+b<c+d)cout << "Right" << endl;
    else cout << "Balanced" << endl;
    return 0;
}

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

int main() {
    //ios_base::sync_with_stdio(false);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    vector <ll> a;
    for (int i = 0; i < 3; i++) {
        int x;
        cin >> x;
        a.push_back(x);
    }
    int cnt = 0;
    while (a[0] % 2 == 0 && a[1] % 2 == 0 && a[2] % 2 == 0) {
        sort(a.begin(), a.end());
        vector <ll> b = a;
        b[0] = (a[1] + a[2]) / 2;
        b[1] = (a[0] + a[2]) / 2;
        b[2] = (a[0] + a[1]) / 2;
        a = b;
        cnt++;
        if (b[0] == b[1] && b[0] == b[2]) {
            cout << -1;
            return 0;
        }
    }
    cout << cnt;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int MAX = 2000000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < MAX; i++) {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k) {
    if(n < k)
        return 0;
    if(n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
int main() {
    int ans = 0;
    int X, Y;
    cin >> X >> Y;
    if((X + Y) % 3 == 0) {
        int n = (2 * X - Y) / 3;
        int m = (2 * Y - X) / 3;
        if(n >= 0 && m >= 0) {
            COMinit();
            ans = COM(n + m, n);
        }
    }
    cout << ans << endl;
}

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


int main()
{
	while (1) {
		int H, W;
		cin >> H >> W;

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

		for (int i = 0; i < H; i++) {
			for (int j = 0; j < W; j++) {
				cout << "#";
			}
			cout << endl;
		}
		cout << endl;
	}
		}

Measured memory_bytes: 3032
#include <iostream>
#include <cstring>
#include <string>    
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
ll n, l;
string str;

int main(){
	cin >> n >> l;
	ll eat = l;
	ll ans = 0;
	for(ll i = 0; i < n; i++){
		if(abs(l+i) < abs(eat)){eat = l+i;}
		ans += l+i;
	}
	cout << ans-eat << endl;
	return 0;
}

Measured memory_bytes: 256
import sys

class Node:
    __slots__ = ["key","left","right"]
    def __init__(self,key):
        self.key = key
        self.left = self.right = None

root = None

def insert(key):
    global root
    x,y = root,None
    while x:
        y = x
        x = x.left if key < x.key else x.right
    if y is None:root = Node(key)
    elif key < y.key:y.left = Node(key)
    else:y.right = Node(key)

def find(target):
    result = root
    while result and target != result.key:
        result = result.left if target < result.key else result.right
    return result is None

def inorder(node):
    return inorder(node.left) + f' {node.key}' + inorder(node.right) if node else ""

def preorder(node):
    return f' {node.key}' + preorder(node.left) + preorder(node.right) if node else ""

input()
for e in sys.stdin:
    if e[0] == "i":insert(int(e[7:]))
    elif e[0] =="f":print(["yes","no"][find(int(e[5:]))])
    else:print(inorder(root));print(preorder(root))



Measured memory_bytes: 53636