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

#define max(a, b) ((a > b) ? a : b)
#define min(a, b) ((a < b) ? a : b)

#define forn(n) for(int i = 0; i < n; i++)
#define fork(k, n) for(int i = k; i < n; i++)

#define pb(n) push_back(n);

typedef long long ll;
typedef double dbl;

const int MX = 1e6;
const int MOD = 1e9 + 7;
const string ALPHA = "abcdefghijklmnopqrstuvwxyz";
const double PI = 3.1415926535;


int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
	//Code here bby
  double n, x, t;
  cin>>n>>x>>t;
  cout<<(int)(ceil(n / x) * t)<<endl;
}


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

int main() {
	int a, b ,c, k;
	scanf("%d %d %d\n%d", &a, &b, &c, &k);
	int max = a;
	int maxi = 0;
	if (max < b) {
		maxi = 1;
		max = b;
	}
	if (max < c) {
		maxi = 2;
		max = c;
	}
	switch (maxi) {
	case 0:
		printf("%d\n", a * (int)pow(2, k) + b + c);
		break;
	case 1:
		printf("%d\n", a + b * (int)pow(2, k) + c);
		break;
	case 2:
		printf("%d\n", a + b + c * (int)pow(2, k));
	}
	
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a[1000],b[1000];
  a[1000]=0;
  b[1000]=0;
  int n;
  int sum=0;
  cin >> n;
  for(int i=1;i<=n-1;i++){
    cin >> b[i];
  }
  for(int i=1;i<=n-2;i++){
    sum+=std::min(b[i],b[i+1]);
  }
  sum=sum+b[1]+b[n-1];
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
#define sp(n) cout << fixed << setprecision(n)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long ll;
using namespace std;
ll gcd(ll x,ll y){
    if (y == 0) return x;
    return gcd(y, x%y);
}
int main(void){
    ll n,k;cin>>n>>k;
    vector<ll> a(n);
    rep(i,n) cin>>a[i];
    ll g=a[0];
    rep(i,n) g=gcd(g,a[i]);
    sort(a.rbegin(),a.rend());
    rep(i,n){
        if(a[i]<k)break;
        if((a[i]-k)%g==0){
            cout<<"POSSIBLE"<<endl;
            return 0;
        }
    }
    cout<<"IMPOSSIBLE"<<endl;
}

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

int main() {
  int n;
  string s;
  cin>>n>>s;
  int cur=0;
  int ans=0;
  rep(i,n){
    if(s[i]=='I') cur++;
    else cur--;
    ans=max(ans,cur);
  }
  
  cout<<ans<<endl;
}


Measured memory_bytes: 512
ref={"A":"BD","B":"ACE","C":"BF","D":"AEG","E":"BDFH","F":"CEI","G":"DH","H":"EGI","I":"HF"}
for i in range(1000):
	p=raw_input()
	for i in range(len(p)-1):
		if p[i+1] not in ref[p[i]]:
			break
	else:
		print p

Measured memory_bytes: 4232
# -*- coding: utf 8 -*-
# Selection Sort
# 2019. 4/22

def selectionSort(A, N):
    sw = 0
    for i in range(0, int(N) - 1):
        minj = i
        for j in range(i, int(N)):
            if A[j] < A[minj]:
                minj = j
        A[i], A[minj] = A[minj], A[i]
        if minj != i:
            sw = sw + 1

    return A, sw

if __name__ == "__main__":
    N = int(input())
    A = list(map(int, input().split()))

    A_sorted, sw = selectionSort(A, N)

    for i in range(0, N - 1):
        print(A[i], end=" ")
    print(A[N - 1])
    print(sw)



Measured memory_bytes: 5624
#include<bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define rrep(i, n) for (int (i) = 1; (i) <= (n); (i++))
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define yn {puts("Yes");}else {puts("No");}
#define printd(x) printf("%.12f\n", ans);
template<class T> bool chmin(T& a, const T& b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> bool chmax(T& a, const T& b) {if (a < b) {a = b; return 1;} return 0;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

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

    sort(rng(s));

    string ans = "";
    rep (i, n) ans += s[i];
    
    cout << ans << endl;
    return 0;
}

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

int main() {
    int n;
    cin >> n;
    ll allxor = 0;
    vector<ll> a(n);
    rep(i, n) {
        cin >> a[i];
        allxor ^= a[i];
    }
    rep(i, n) {
        cout << ll(allxor ^ a[i]) << " ";
    }
    cout << endl;
}


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

using namespace std;

int main(int argc, char const *argv[]) {
	int n;
	std::cin >> n;
	char x;
	std::vector<bool> v(4,true);
	int count = 0;
	string str = "PWGY";
	for (size_t i = 0; i < n; i++) {
		std::cin >> x;
		for (size_t j = 0; j < str.size(); j++) {
			if (str[j] == x && v[j]) {
				v[j] = false;
				count++;
			}
		}
	}

	if (count == 3) {
		std::cout << "Three" << '\n';
	}
	else {
		std::cout << "Four" << '\n';
	}
	return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
      	int[] num = new int[5];
		for(int i=0;i<5;i++){
			num[i] = sc.nextInt();
          	if( num[i] != (i+1) ){
              System.out.println( (i+1) );
            }
		}
		//System.out.println(ans);    	
	}
}

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

int main() {
  int A, B, C, X, Y;
  cin >> A >> B >> C >> X >> Y;
  int price;
  if (A + B <= C * 2){
    price = A * X + B * Y;
  }
  else if (X >= Y){
    if (A <= C * 2){
      price = C * 2 * Y + A * (X - Y);
    }
    else{
      price = C * 2 * X;
    }
  }
  else{
    if (B <= C * 2){
      price = C * 2 * X + B * (Y - X);
    }
    else{
      price = C * 2 * Y;
    }
  }
  
  cout << price << endl;
}

Measured memory_bytes: 3632
n,k = map(int,input().split())
X = [0]*n
Y = [0]*n
for i in range(n):
    X[i],Y[i] = map(int,input().split())

Xs = sorted(X)
Ys = sorted(Y)
XY = sorted(list(zip(X,Y)))
ans = 1e100
for i in range(n-k+1):
    for j in range(i+k-1,n):
        w = Xs[j] - Xs[i]
        XYs = sorted(XY[i:j+1],key = lambda x:x[1])
        h = 1e100
        for l in range(len(XYs) - k + 1):
            h = min(h, XYs[l + k - 1][1] - XYs[l][1])
        ans = min(ans , h*w)
print(ans)


Measured memory_bytes: 40044
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for( int i = 0 ; i < n ; i++ )
 
int main() {
  int a , b, c, d, e, k ;
  cin >> a >> b >> c >> d >> e >> k ;
  if( e - a > k ) cout << ":(" << endl;
  else cout << "Yay!" << endl ;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
S = input()
N = len(S)

def kaibun(s):
  for i in range(len(s)):
    if s[i]!=s[-i-1]:
      return False
  return True

A = kaibun(S[:(N-1)//2])
B = kaibun(S[(N+1)//2:])
C = kaibun(S)

if A and B and C:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 3064
'use strict';

function answer(bool) {
  if (bool) console.log('Yes');
  else console.log('No');
}

function main(stdin) {
  const input = stdin.split(' ').map(v => parseInt(v, 10));
  const N = input[0];

  let ans = false;

  for (let i = 1; i <= 9; i++) {
    for (let j = 1; j <= 9; j++) {
      if (i * j == N) ans = true;
    }
  }

  answer(ans);
}

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

Measured memory_bytes: 21064
#include <bits/stdc++.h>
using namespace std;
#define  rep(i, n) for(int i = 0; i < n; i++) 
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  INF 1LL << 60
typedef long long int LL;
const int MOD = 1000000007;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }
//sort(all(x))とするとソートできるよ
// 10^x は pow(10,(x)) 
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

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

    int lim = log(N) / log(6);
    lim /= 1;

    vector<LL> DP(N+pow(9,lim)+1,INF);
    DP[0] = 0;


    rep(i,N){
        if(lim == 0){
            chmin(DP[i+1],DP[i] + 1);   // 1 select
        }
        else{
            for(int j = 1;j <= lim;j++){
                chmin(DP[i+1],DP[i] + 1);   // 1 select
                chmin(DP[i+pow(6,j)],DP[i] + 1); // 6^j select
                chmin(DP[i+pow(9,j)],DP[i] + 1); // 9^j select
            }
        }
    }

    cout << DP[N] << endl;
}

Measured memory_bytes: 5120
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Globalization;
using System.Diagnostics;
using static System.Console;
using Pair = System.Collections.Generic.KeyValuePair<int, int>;

class Program
{
    static void Main()
    {
        //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
        new Program().Solve();
        Out.Flush();
    }
    Scanner cin = new Scanner();
    Random rnd = new Random();
    Stopwatch sw = new Stopwatch();
    readonly int[] dd = { 0, 1, 0, -1, 0 };
    readonly int mod = 1000000007;
    readonly string alfa = "abcdefghijklmnopqrstuvwxyz";


    void Solve()
    {
        int N = cin.Nextint;
        int M = cin.Nextint;
        var A = new int[N];
        var B = new int[N];
        var C = new int[M];
        var D = new int[M];

        for (int i = 0; i < N; i++)
        {
            A[i] = cin.Nextint;
            B[i] = cin.Nextint;
        }

        for (int i = 0; i < M; i++)
        {
            C[i] = cin.Nextint;
            D[i] = cin.Nextint;
        }

        for (int i = 0; i < N; i++)
        {
            int min = int.MaxValue;
            int ans = -1;
            for (int j = 0; j < M; j++)
            {
                if (Math.Abs(A[i] - C[j]) + Math.Abs(B[i] - D[j]) < min)
                {
                    ans = j + 1;
                    min = Math.Abs(A[i] - C[j]) + Math.Abs(B[i] - D[j]);
                }
            }
            WriteLine(ans);
        }

    }

}

class Scanner
{
    string[] s; int i;
    char[] cs = new char[] { ' ' };
    public Scanner() { s = new string[0]; i = 0; }
    public string[] Scan { get { return ReadLine().Split(); } }
    public int[] Scanint { get { return Array.ConvertAll(Scan, int.Parse); } }
    public long[] Scanlong { get { return Array.ConvertAll(Scan, long.Parse); } }
    public double[] Scandouble { get { return Array.ConvertAll(Scan, double.Parse); } }
    public string Next
    {
        get
        {
            if (i < s.Length) return s[i++];
            string st = ReadLine();
            while (st == "") st = ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return Next;
        }
    }
    public int Nextint { get { return int.Parse(Next); } }
    public long Nextlong { get { return long.Parse(Next); } }
    public double Nextdouble { get { return double.Parse(Next); } }
}


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

using namespace std;

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

  string s[n];
  for (int i = 0; i < n; ++i) {
    cin >> s[i];
  }

  sort(s, s + n);

  for (int i = 0; i < n; ++i) cout << s[i];
  cout << endl;
}


Measured memory_bytes: 256
import java.util.*;
public class Main
{
    public static void main(String args[])
    {
        Scanner sc=new Scanner(System.in);
       int ar[]=new int[4];
       for(int i=0;i<3;i++)
       {
           int a=sc.nextInt();
           int b=sc.nextInt();
           a-=1;
           b-=1;
           ar[a]+=1;
           ar[b]+=1;
       }
       for(int i:ar)
       {
           if(i>2)
           {
               System.out.println("NO");
               System.exit(0);
           }
       }
       System.out.println("YES");
    }
}

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

int main(){
  int i,j;
  char s[20];
  char tmp[20];

  cin >> s;
  for(i=0;s[i] != NULL; i++);
  for(j=i-1;j>=0;j--){
    printf("%c",s[j]);
  }
  cout << endl;

return 0;
}

Measured memory_bytes: 1128
#include<bits/stdc++.h>
#define ll long long 
#define mp make_pair 
#define f(i,n) for(int i=0;i<n;i++) 
#define F first 
#define S second 
#define pb push_back 

using namespace std;

ll R,C,K;

ll cache[3030][3030][4];

ll val[3030][3030];

ll dp(ll i,ll j,ll k){
	if(i==R or j==C or k==4)
		return 0;
	else if(cache[i][j][k]!=-1)
		return cache[i][j][k];
	else{
		ll ans = max(dp(i+1,j,0),dp(i,j+1,k));
		if(val[i][j]!=0 and k<3)
		{
			ans = max(ans,val[i][j] + max(dp(i+1,j,0),dp(i,j+1,k+1)));
			
		}
		cache[i][j][k] = ans;
		return cache[i][j][k];
	}
}

void test(){
	cin>>R>>C>>K;
	memset(cache,-1,sizeof(cache));
	f(i,K){
		ll r,c,k;
		cin>>r>>c>>k;
		val[r-1][c-1] = k;
	}
	
	cout<<dp(0,0,0)<<"\n";
}

int main(){
	std::ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int tests=1;
	// cin>>tests;
	while(tests--){
		test();
	}
}


Measured memory_bytes: 361872
#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"

using namespace std;

using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
using i8 = int8_t;
using i32 = int32_t;
using i64 = int64_t;
constexpr char newl = '\n';

template<typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define F0R(i,b) FOR(i,0,b)
#define RFO(i,a,b) for (int i = ((b)-1); i >=(a); i--)
#define RF0(i,b) RFO(i,0,b)
//#define F first
//#define S second
#define debug(x) cout << #x << ": " << x << '\n';
template<class T> void Print(vector<T> v) {
  F0R(i, v.size()) {
    cout << v[i] << ' ';
  }
  cout << newl;
}

#if 1


// INSERT ABOVE HERE
signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int N, M;
  cin >> N >> M;

  string cand(N, '?');

  bool result = true;
  F0R(i, M) {
    int s;
    char c;
    cin >> s >> c;
    s--;

    if (cand[s] == '?' || cand[s] == c) {
      cand[s] = c;
    }
    else {
      result = false;
      break;
    }
  }

  if (cand.size() > 1 && cand[0] == '0') result = false;
  F0R(i, cand.size()) {
    if (cand[i] == '?') cand[i] = '0';
  }
  if (cand.size() > 1 && cand[0] == '0') cand[0] = '1';

  cout << (result ? cand : "-1");
}
#endif


Measured memory_bytes: 256
#include <bits/stdc++.h>
//---------------------------
using namespace std;
//---------------------------
#define REP(i,n) for(int i = 0; i < (n); i++)
#define P(x) cout << (x) << "\n"

#define MOD 1000000007 // 1e9+7
#define PI acos(-1.0)
#define ll long long int // 10^18
#define INF 1000000001 // 1e9+1

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

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

  // ifstream in("input.txt");
  // cin.rdbuf(in.rdbuf());

  int a,b,c;cin>>a>>b>>c;
  int count=0;
  if(a>b)swap(a,b);
  if(b>c)swap(b,c);
  while(a<c){
    a+=2;
    count++;
  }
  while(b<c){
    b+=2;
    count++;
  }
  if(a==c+1 && b==c+1){
    count-=2;
    count++;
    P(count);
  }else if(a==c && b==c){
    P(count);
  }else{
    count++;
    P(count);
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <sstream>
#include <utility>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <cmath>
#include <functional>
#include <chrono>
#include <cstring>
#include <bits/stdc++.h>

using namespace std;
typedef long long lint;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<lint> vl;
typedef pair<lint,lint> pll;
#define mpr make_pair

int res(int t1, int t2, int t3){
    int l = (t1 + t2 +t3)/2;
    int x1 = l - t3;
    int x2 = l - t2;
    int x3 = l - t1;
    if (x1==x2 || x2==x3){
        if (x1==x2 && x2==x3) return 1;
        else return 3;
    } else {
        return 6;
    }
}

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

    int n; cin>>n;

    for (int k = 1; k<=n; ++k){

        int cnt = 0;
        for (int t1 =1; t1*t1*3 <= 2*k; ++t1){
            for (int t2 = t1; t1*t1 + 2*t2*t2 <= 2*k; ++t2){
                for (int t3 = t2; t3 < t1 + t2; ++t3){
                    if (t1*t1 + t2*t2 + t3*t3 == 2*k) cnt += res(t1, t2, t3);
                    if (t1*t1 + t2*t2 + t3*t3 >= 2*k) break;
                }
            }
        }
        cout<<cnt<<"\n";
    }

}


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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int n; cin>>n;
	unordered_map<int,int>m;
	for(int i=2;i<=n;++i){
		int num=i;
		for(int j=2;j<=n;++j){
			while(num%j==0){
				num/=j;
				++m[j];
			}
		}
	}
	int ans=1,mod=1e9+7;
	for(auto&i:m)ans=(int64_t)ans*(i.second+1)%mod;
	cout<<ans<<"\n"s;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <limits.h>
#include <map>
#include <set>
#include <vector>
#include <functional>
#include <algorithm>
#include <stack>
#include <list>
#include <queue>
#include <bitset>
//#include <iostream>
//#include <sstream>
using namespace std;
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define pf printf
#define sf scanf
#define test_ fprintf(stderr, ">>>>>>>>>>>>>>>>>>>> in <<<<<<<<<<<<<<<<<<<<")
#define deb(x) cerr << ">>>>>>>>>>>>>>>>>>>> " << #x << " = " << x << " <<<<<<<<<<<<<<<<<<<<\n"
#define debd(x) fprintf(stderr, ">>>>>>>>>>>>>>>>>>>> %s = %d <<<<<<<<<<<<<<<<<<<<\n", #x, x)
#define debs(x) fprintf(stderr, ">>>>>>>>>>>>>>>>>>>> %s = %s <<<<<<<<<<<<<<<<<<<<\n", #x, x)
#define debll(x) fprintf(stderr, ">>>>>>>>>>>>>>>>>>>> %s = %lld <<<<<<<<<<<<<<<<<<<<\n", #x, x)
#define deblf(x) fprintf(stderr, ">>>>>>>>>>>>>>>>>>>> %s = %lf <<<<<<<<<<<<<<<<<<<<\n", #x, x)
#define fr(i, a, b) for(int i = a ; i < b ; i++)
#define frr(i, a, b) for(int i = a ; i >= b ; i--)
#define tr(it, var) for(__typeof(var.begin()) it = var.begin(); it != var.end(); it++)
#define trr(rit, var) for(__typeof(var.rbegin()) rit = var.rbegin(); rit != var.rend(); rit++)
#define its(x) static_cast< ostringstream & >( ( ostringstream() << dec << x ) ).str()
#define boost ios_base::sync_with_stdio(false); cin.tie(NULL)
#define ln puts("")
#define mems(a) memset(a, 0, sizeof(a))
#define has(cont, x) ((cont).find((x)) != (cont).end())
#define sz(x) ((int)(x).size())
//typedef
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<ll> vll;
//bitmask
int onbit(int x, int pos) {x |= (1 << pos); return x;}
int offbit(int x, int pos) {x &= ~(1 << pos); return x;}
int test(int x, int pos) {return x & (1 << pos);}
int flip(int x, int pos) {x ^= (1 << pos); return x;}
int lsb(int x) {return x & (-x);}
int onbitall(int x, int pos) {x = (1 << pos)-1; return x;}
//constants
const double EPS = 1e-9;
const double PI = 2*acos(0.0);
const int INF = 0x3f3f3f3f;
const int MOD = 1e9+7;
//moves
const int dx1[] = {0, 1, 0, -1};
const int dy1[] = {1, 0, -1, 0};
const int dx2[] = {-1, -1, -1, 0, 0, 1, 1, 1};
const int dy2[] = {-1, 0, 1, -1, 1, -1, 0, 1};

int main() {
//  freopen("input.in", "r", stdin);
	int n, a, b;
  sf("%d %d %d", &n, &a, &b);
  pf("%d\n", min(n*a, b));
	return 0;
}


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

#define null               ""
#define endl               '\n'
#define all(dat)           dat.begin(), dat.end()
#define loop(i, to)        for (int i = 0; i < to; ++i)
#define cont(i, to)        for (int i = 1; i <= to; ++i)
#define circ(i, fr, to)    for (int i = fr; i <= to; ++i)
#define foreach(i, dat)    for (__typeof(dat.begin()) i = dat.begin(); i != dat.end(); ++i)

typedef long long          num;

using namespace std;

const int nsz = 1e5;
int n, ans[nsz + 5];
vector<pair<int, int>> g[nsz + 5];

void dfs(int u = 1, int p = 1, int c = 0) {
    ans[u] = c;
    loop (i, g[u].size()) {
        int v = g[u][i].first, w = g[u][i].second;
        if (v == p)  continue;
        dfs(v, u, c ^ (w & 1));
    }
}

int inline read() {
    int res = 0;
    char c = getchar();
    for (; !isdigit(c); c = getchar());
    for (; isdigit(c); res *= 10, res += c ^ 48, c = getchar());
    return res;
}

int main() {
    ios_base::sync_with_stdio(0);
    n = read();
    cont (i, n - 1) {
        int u = read(), v = read(), w = read();
        g[u].push_back({v, w});
        g[v].push_back({u, w});
    }
    dfs();
    cont (i, n) {
        cout << ans[i] << endl;
    }
}


Measured memory_bytes: 9216
#include <bits/stdc++.h>
 
using namespace std;
 
#define FOR(i, n) for(int i = 0; i < (int) n; i++)
#define all(v) v.begin(), v.end()
#define PB push_back
#define F first
#define S second
 
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
 
const ll MOD = 1e9+7;
 
int cont[3][4007];

int dif(char a, char b){
	string s = "RGB";
	for(int i = 0; i < 3; i++)
		if(s[i] != a && s[i] != b)
			return i;
	return 0;
}

int main(){
	ios::sync_with_stdio(false); cin.tie(0);
 
	int n; cin >> n;
	string s; cin >> s;

	string aux = "RGB";
	
	for(int i = 1; i <= n; i++){
		for(int j = 0; j < 3; j++)
			cont[j][i] = cont[j][i-1];
		if(s[i-1] == 'R')
			cont[0][i]++;
		else if(s[i-1] == 'G')
			cont[1][i]++;
		else
			cont[2][i]++;
	}
	

	ll ans = 0;
	for(int i = 0; i < n-2; i++){
		for(int k = i+2; k < n; k++){
			if(s[i] != s[k]){
				int d = dif(s[i], s[k]);
				ans += cont[d][k+1]-cont[d][i];
				if((i+k)%2 == 0 && s[(i+k)/2] == aux[d]){
					ans--;
				}
			}
		}
	}

 	cout << ans << '\n';

	return 0;
}

Measured memory_bytes: 3668
function main(arg) {
    arg = arg.split("\n")
    arg = parseInt(arg[0], 10)
    var ans = ""

    while (arg != 0) {
        if (arg % 2 !== 0) {
            arg--;
            ans = "1" + ans
        } else {
            ans = "0" + ans
        }
        arg /= -2
    }
    if (ans === "") {
        ans = "0"
    }
    console.log(ans)
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

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

#define INF INT_MAX
#define MOD 1000000007
#define REP(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()

typedef long long ll;
typedef std::pair<int,int> pii;

using namespace std;

vector<int> graph[200005];
int c[200005];
int ans[200005];

void dfs(int sum,int to){
    ans[to] = c[to]+sum;
    if(graph[to].size() == 0)return;

    REP(i,graph[to].size()){
        dfs(ans[to],graph[to][i]);
    }
}

int main() {

    int n,q;
    cin >> n >> q;
    REP(i,n-1){
        int a,b;
        cin >> a >> b;
        a--,b--;
        graph[a].push_back(b);
    }
    REP(i,q){
        int p,x;
        cin >> p >> x;
        p--;
        c[p] += x;
    }
    dfs(0,0);
    for(int i = 0;i < n;i++){
        cout << ans[i];
        if(i != n-1)cout << " ";
        else cout << endl;
    }

    return 0;
}

Measured memory_bytes: 24064
#include <stdio.h>
int main(){
    int a[3];
    scanf("%d%d%d",&a[0],&a[1],&a[2]);
    for(int i = 0; i < 3; i++){
        for(int j = i + 1; j < 3; j++){
            if(a[i] > a[j]){
                int tmp = a[i];
                a[i] = a[j];
                a[j] = tmp;
            }
        }
    }
    printf("%d %d %d", a[0], a[1], a[2]);
    printf("\n");
    return 0;
}

Measured memory_bytes: 2596
using System;
using System.Text;

namespace Aizu
{
    class OnlineJudge
    {
        public static void Main()
        {
            var output = new StringBuilder();
            string input;
            int count = 0;
            while((input = Console.ReadLine()) != "0") {
                output.AppendLine("Case " + ++count + ": " + input);
            }
            Console.Write(output.ToString());
        }
    }
}

Measured memory_bytes: 6900
#include<stdio.h>
int main(){
int a,b,x,i,t=1;
  scanf("%d  %d",&a,&b);
  for(i=0;t<=b;i++){
  t*=10;
  }
  x=a*t+b;
  for(i=1;i<=350;i++){
    if(i*i==x)break;
    }
  if(i==351)printf("No");
  else printf("Yes");
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define MOD 1000000007
#define INF 1e9
#define All(x) (x).begin(), (x).end()
typedef long long ll;
using namespace std;

int main() {
  ll N;
  cin >> N;
  N++;
  ll ans = 1;
  vector<ll> a(N), sum(N);
  REP(i, N) cin >> a[i];
  sum[N - 1] = a[N - 1];
  for (int i = N - 2; i >= 0; i--) {
    sum[i] = sum[i + 1] + a[i];
  }
  ll bef = 1 - a[0];
  if(bef<0){
    cout << -1 << endl;
    return 0;
  }
  for (ll i = 1; i < N; i++) {
    ll con = bef * 2 - a[i];
    if((con<=0&&i!=N-1)||con<0){
      cout << -1 << endl;
      return 0;
    }
    ans += (min(sum[i] - a[i], con) + a[i]);
    bef = min(sum[i] - a[i], con);
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 4840
x=int(input()) #　a1
a=list(map(int, input().split()))

rate=[0]*8
cl_all=0
for cl in a:
  if cl >=3200:
    cl_all+=1
    continue
  
  rate[cl//400]=1

if sum(rate)==0:
  print(1,cl_all)
else:
  print(sum(rate),sum(rate)+cl_all)
  

Measured memory_bytes: 2940
r,d,x=map(int,input().split())
a=r*x-d
b=r*a-d
c=r*b-d
e=r*c-d
f=r*e-d
g=r*f-d
h=g*r-d
i=h*r-d
j=r*i-d
k=r*j-d
print(int(a))
print(int(b))
print(int(c))
print(int(e))
print(int(f))
print(int(g))
print(int(h))
print(int(i))
print(int(j))
print(int(k))


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <typeinfo>
#include <cxxabi.h>
#ifdef LOCAL
#include "dbgtoki.hpp"
#define DUMP(i) dump((string)TOSTRING(i), demangle(typeid(i).name()), __LINE__ , i) 
#else
#define DUMP(i)
#endif

using namespace std;
#define TOSTRING(x) #x
#define SZ(x) (int)(x).size()
#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(s) (s).begin(), (s).end()
#define dis distance
#define so(V) sort(ALL(V))
#define rev(V) reverse(ALL(V))
#define uni(v) v.erase( unique(ALL(v)) , v.end());
#define pub push_back
#define sec second
#define fir first

typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector <int> > vvi;
const int EPS = 1e-9;
const int MOD = 1e9+7;
const int INF = (1 << 30);
const double PI = acos(-1);

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string x;
	cin >> x;
	stack<char> S;
	REP(i,SZ(x)){
		char c = x[i];
		if(c == 'T'&&(!S.empty())&&S.top()=='S'){
			S.pop();
		}else{
			S.push(c);
		}
	}
	cout << SZ(S) << endl;
	return 0;
}

Measured memory_bytes: 720
N = int(input())
h = list(map(int,input().split()))

INF = 10 ** 9 + 1
dp = [INF] * N
dp[0] = 0
for i in range(len(dp) - 1):
  dp[i + 1] = min(dp[i] + abs(h[i + 1] - h[i]), dp[i + 1])
  if i + 2 < len(dp):
    dp[i + 2] = min(dp[i] + abs(h[i + 2] - h[i]), dp[i + 2])
  
print(dp[N - 1])


Measured memory_bytes: 20460
#include<bits/stdc++.h>
using namespace std;
int n;
double m,x,ans,nn,m1,x1; 
int main()
{
	scanf("%d%lf%lf",&n,&m,&x);
	nn=n+n;
	for(register int i=n;i>=1;i--)
	{
		ans+=m+(nn-1)/2*x;
        m1=m+(2*m+5*x)/nn;
        x1=x+4*x/nn;
        x=x1,m=m1,nn-=2;
	}
	printf("%.10lf\n",ans);
	return 0;
}

Measured memory_bytes: 256
import sys

n = int(input())
a_list = list(map(int, input().split()))
result = sys.maxsize
for i in range(n):
    divided = a_list[i]
    count = 0
    while divided % 2 == 0:
        divided /= 2
        count += 1
    if count < result:
        result = count
print(result)


Measured memory_bytes: 3060
from collections import defaultdict
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
AtoZ = [chr(i) for i in range(65,65+26)]
atoz = [chr(i) for i in range(97,97+26)]

def inpl(): return list(map(int, input().split()))
def inpl_str(): return list(input().split())

N,M = inpl()
print((N-1)*(M-1))

Measured memory_bytes: 4456
#[warn(unused_imports)]
use proconio::{
   fastout, input,
   marker::{Bytes, Chars, Isize1, Usize1}
};

#[fastout]
fn main() {
   input! {
      a:i64,
      b:i64,
      c:i64,
      mut k:i64,
   }
   let mut ans: i64;
   if a >= k {
      ans = k;
   } else {
      ans = a;
      k -= a;
      if b < k {
         ans -= k - b;
      }
   }
   println!("{}", ans);
}


Measured memory_bytes: 2164
<?php
	
function gcb( $x, $y )
{
	while( 0 != $y ) {
		$t = $y;
		$y = $x%$y;
		$x = $t;
	}
	return $x;
}

	$nums = explode( " ", trim( fgets( STDIN ) ) );
	$x = max( $nums );
	$y = min( $nums );
	print gcb( $x, $y );
?>

Measured memory_bytes: 15336
#include <stdio.h>

int main(void) {
  int N, t;
  int i = 0;
  char str[10000];

  scanf("%d", &N);
  scanf("%s", str);
  
  while ('A' <= str[i] && str[i] <= 'Z') {
    t = str[i] + N;
    if (t > 'Z') {
      t -= 26;
    }
    str[i] = t;
    i++;
  }
  i = 0;
  while ('A' <= str[i] && str[i] <= 'Z') {
    printf("%c", str[i]);
    i++;
  }
  putchar('\n');

  return 0;
}


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

using namespace std;

using ll = long long;



int main()
{
    int N, M;
    cin >> N >> M;
    pair<int, int> p[50];
    bool d[51];
    for(int i = 0; i < M; ++i) cin >> p[i].first >> p[i].second;
    for(int i = 0; i < N+1; ++i) d[i] = false;

    int cnt = 0;
    for(int i = 0; i < M; ++i){
        queue<pair<int, int>> q;
        q.push(p[i]);
        while(q.empty() == false){
            auto node = q.front();
            q.pop();
            for(int j = 0; j < M; ++j){
                if(j == (i+1)%M) continue;
                if(node == p[j]) continue;
                if(node.second == p[j].first){
                    if(d[p[j].first] == true) continue;
                    q.push(p[j]);
                }
                if(node.first == p[j].second){
                    if(d[p[j].second] == true) continue;
                    q.push(p[j]);
                }
                if(node.second == p[j].second){
                    if(d[p[j].second] == true) continue;
                    q.push(p[j]);
                }
                if(node.first == p[j].first){
                    if(d[p[j].first] == true) continue;
                    q.push(p[j]);
                }
            }
            d[node.first] = true;
            d[node.second] = true;
        }
        bool isBridge = false;
        for(int j = 1; j <= N; ++j){
            if(d[j] == false){
                isBridge = true;
            }else{
                d[j] = false;
            }
        }
        if(isBridge) cnt++;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"sort"
	"strconv"
	"strings"
)

var sc = bufio.NewScanner(os.Stdin)

func oneInt() int {
	var a int
	fmt.Scan(&a)
	return a
}
func oneStr() string {
	var a string
	fmt.Scan(&a)
	return a
}

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

func scanNums() (nums []int) {
	s := nextLine()
	numStr := strings.Split(s, " ")

	for _, n := range numStr {
		i, _ := strconv.Atoi(n)
		nums = append(nums, i)
	}
	return nums
}

func scanStrings() (strs []string) {
	s := nextLine()
	list := strings.Split(s, " ")
	strs = append(strs, list...)
	return strs
}

func abs(a int) int {
	return int(math.Abs(float64(a)))
}

func pow(p, q int) int {
	return int(math.Pow(float64(p), float64(q)))
}

func min(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton min() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Min(float64(res), float64(nums[i])))
	}
	return res
}

func max(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton max() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Max(float64(res), float64(nums[i])))
	}
	return res
}

func strSearch(a []string, b string) bool {
	for i := 0; i < len(a); i++ {
		if a[i] == b {
			return true
		}
	}
	return false
}

func sortAsc(a []int) []int {
	sort.Ints(a)
	return a
}

func sortDesc(a []int) []int {
	sort.Sort(sort.Reverse(sort.IntSlice(a)))
	return a
}

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

func lcm(a, b int) int {
	if a == 0 && b == 0 {
		return 0
	}
	return a * b / gcd(a, b)
}


func main() {
	S := oneStr()
	S = strings.Replace(S, "BC", "D", -1)
	cntA := 0
	ans := 0
	for _, r := range S {
		switch {
		case r == 'A':
			cntA++
		case r == 'D':
			ans += cntA
		default:
			cntA = 0
		}
	}
	fmt.Print(ans)
}


Measured memory_bytes: 2432
#include <iostream>
#include <stack>
#include <queue>
#include <map>
#include <vector>
#include <cstdio>
#include <string>
#include <climits>
#include <cmath>
#include <cstring>
#include <iomanip>

using namespace std;

int main(){
    int n,x;
    cin>>n;
    int a[4] = {0};
    for(int i = 0; i < n; i++){
        cin>>x;
        a[x%4]++;
    }
    if(a[2] == 0 && a[0]+1 >= a[1]+a[3]){
        cout<<"Yes"<<endl;
    }else if(a[2] == 0){
        cout<<"No"<<endl;
    }else if(a[0] >= a[1] + a[3]){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
}


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

struct Edge {
	int to;
};
using EdgeVec = std::vector<Edge>;
using EdgeLists = std::vector<EdgeVec>;

///////////////////
// 強連結成分分解 //
///////////////////

// コンストラクタに隣接リストを渡すと強連結成分分解する
// Edgeは{to}
class SCC {
private:
	using vi = std::vector<int>;
	using vvi = std::vector<vi>;
	using vb = std::vector<bool>;

	const EdgeLists& edge_;
	vvi componentElements_, revEdge_;
	vi belongTo_;

	void backTrack(const int index, vi& revOrder, vb& visited)
	{
		if (visited[index]) return;
		visited[index] = true;
		for (const auto& next: edge_[index])
			backTrack(next.to, revOrder, visited);
		revOrder.push_back(index);
	}
	void assignComponent(const int index)
	{
		if (belongTo_[index] >= 0) return;
		belongTo_[index] = componentElements_.size() - 1;
		componentElements_.back().push_back(index);
		for (const auto& next: revEdge_[index])
			assignComponent(next);
	}

public:
	// belongTo[i]は元のグラフの要素iが属している強連結成分のindex
	const vi& belongTo;
	// belongToの逆像、compoenentElements.size()は強連結成分の個数
	const vvi& componentElements;

	SCC(const EdgeLists& adjacentList)
		: edge_(adjacentList), belongTo(belongTo_), componentElements(componentElements_)
	{
		revEdge_.resize(edge_.size());
		for (int i{}; i < (int)edge_.size(); i++)
			for (const auto& vertex: edge_[i])
				revEdge_[vertex.to].push_back(i);

		vb visited(edge_.size());
		vi revOrder;
		revOrder.reserve(edge_.size());
		for (int i{}; i < (int)edge_.size(); i++)
			backTrack(i, revOrder, visited);

		belongTo_.resize(edge_.size(), -1);
		for (int i{(int)revOrder.size() - 1}; i >= 0; i--)
		{
			const int index{revOrder[i]};
			if (belongTo_[index] >= 0) continue;
			componentElements_.push_back({});
			assignComponent(index);
		}
		for (auto& e: componentElements_)
			std::sort(e.begin(), e.end());
	}

	// 強連結成分を押しつぶした時のDAGを隣接リストで返す
	vvi makeDAG() const
	{
		vvi dagList(edge_.size());
		for (int from_i{}; from_i < (int)edge_.size(); from_i++)
			for (const auto& to_e: edge_[from_i])
			{
				const int dag_from{belongTo[from_i]}, dag_to{belongTo[to_e.to]};
				if (dag_from == dag_to) continue;
				dagList[dag_from].push_back(dag_to);
			}
		for (auto& e: dagList)
		{
			std::sort(e.begin(), e.end());
			e.erase(std::unique(e.begin(), e.end()), e.end());
		}
		return std::move(dagList);
	}
};

int main()
{
	int N, M;
	scanf("%d%d", &N, &M);
	EdgeLists edges(N);
	for (int i{}; i < M; i++)
	{
		int a, b;
		scanf("%d%d", &a, &b);
		a--; b--;
		edges[a].push_back({b});
	}
	SCC scc(edges);
	for (int i{}; i < N; i++)
	{
		auto& list{scc.componentElements[scc.belongTo[i]]};
		for (int j{}; j < (int)list.size(); j++)
			printf("%d%c", list[j] + 1, j + 1 == (int)list.size()? '\n': ' ');
	}

	return 0;
}


Measured memory_bytes: 4112
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
	int arr[3], sum = 0;
	cin >> arr[0] >> arr[1] >> arr[2];
	
	sort(arr,arr+3);
	sum += arr[2] - (arr[1]+arr[0]+1)/2;
	
	if( arr[0]%2 != arr[1]%2 )
		sum += 2;

	cout << sum;
}

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

int main(void){
    int i,n;
    cin >> n;
    long int R[n], tmp[2];
    cin >> R[0];
    cin >> R[1];
    tmp[0]=min(R[0],R[1]);
    tmp[1]=R[1]-R[0];
    for(i=2; i<n; i++){
        cin >> R[i];
        if((R[i]-tmp[0]) > tmp[1]){
            tmp[1] = R[i]-tmp[0];
        }
        if(R[i] < tmp[0]){
            tmp[0] = R[i];
        }
    }
    cout << tmp[1] << endl;
    return 0;
}

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

using namespace std;

int main(){
    vector<char> a(4);
    cin>>a[0]>>a[1]>>a[2]>>a[3];
    sort(a.begin(),a.end());
    if(a[0]!=a[1])cout<<"No";
    else if(a[2]!=a[3])cout<<"No";
    else if(a[1]==a[2])cout<<"No";
    else cout<<"Yes";
    cout<<endl;


    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repd(i,a,b) for (int i = (a); i < (b); i++)
typedef long long ll;
int Y_company(int B, int C, int D, int P)
{
	if(P<=C) return B;
	else return B+(P-C)*D;
}
int main(void)
{
	int A, B, C, D, P;
	cin >> A >> B >> C >> D >> P;
	ll ans = min(P*A, Y_company(B, C, D, P));
	cout << ans << endl;
}



Measured memory_bytes: 3100
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define sz(v) (int)(v).size()
#define pb push_back
#define sc second
#define fr first
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
using namespace std;
typedef long long int ll;
typedef pair <int, int> P;
ll mod_pow(ll x, ll n, ll mod){
    if (n==0) return 1;
    ll res=mod_pow(x*x%mod, n/2, mod);
    if (n%2==1) res=res*x%mod;
    return res;
}
ll euler_phi(ll n){
    ll res=n;
    for(ll i=2;i*i<=n;i++){
        if(n%i==0){
            res=res/i*(i-1);
            for(;n%i==0;n/=i);
        }
    }
    if(n!=1) res=res/n*(n-1);
    return res;
}
ll extgcd(ll a, ll b, ll& x, ll&y){
    ll d=a;
    if(b!=0){
        d=extgcd(b, a%b, y, x);
        y-=(a/b)*x;
    }
    else {
        x=1; y=0;
    }
    return d;
}
ll mod_inverse(ll a, ll m){
    ll x,y;
    extgcd(a,m,x,y);
    return (m+x%m)%m;
}
ll fact[3010];
ll mod_fact(ll n, ll p, ll& e){
    e=0;
    if(n==0) return 1;
    ll res=mod_fact(n/p,p,e);
    e+=n/p;
    if(n/p%2!=0) return res*(p-fact[n%p])%p;
    return res*fact[n%p]%p;
}
ll mod_comb(ll n, ll k, ll p){
    if(n<0||k<0||n<k) return 0;
    ll e1, e2, e3;
    ll a1=mod_fact(n,p,e1), a2=mod_fact(k,p,e2), a3=mod_fact(n-k,p,e3);
    if(e1>e2+e3) return 0;
    return a1*mod_inverse(a2*a3%p,p)%p;
}
ll dp[3010][3010];
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll N,M;
    cin>>N>>M;
    dp[0][0]=1;
    rep(i,1,N+1){
        rep(j,0,i+1){
            if(j>0) dp[i][j]+=dp[i-1][j-1];
            dp[i][j]+=dp[i-1][j]*(j+1)%M;
            dp[i][j]%=M;
        }
    }
    ll a[3010]={};
    rep(i,1,N+1){
        ll s=0;
        rep(j,0,i+1){
            s+=dp[i][j]*mod_pow(2,(N-i)*j,M)%M;
            s%=M;
        }
        s*=mod_pow(2, mod_pow(2,N-i,M-1), M);
        s%=M;
        a[i]=s;
    }
    fact[1]=1;
    rep(i,2,3010){
        fact[i]=fact[i-1]*i;
        fact[i]%=M;
    }
    ll ans=0;
    rep(i,1,N+1){
        ans+=mod_comb(N, i, M)*a[i]*(i%2?1:-1);
        ans%=M;
    }
    ans=((mod_pow(2,mod_pow(2,N,M-1),M)-ans)%M+M)%M;
    cout <<ans<<"\n";
}

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

int main() {
    int r, c;
    cin >> r >> c;

    vector<vector<int>> vec(r+1, vector<int>(c+1, 0));

    for(int i=0; i<r; ++i) {
        for(int j=0; j<c; ++j) {
            cin >> vec[i][j];
        }
    }

    int vec_r_c = 0;
    for(int i=0; i<r; ++i) {
        int row_sum = 0;
        for(int j=0; j<c; ++j) {
            row_sum += vec[i][j];
        }
        vec[i][c] = row_sum;
        vec_r_c += row_sum;
    }

    vec[r][c] = vec_r_c;

    for(int j=0; j<c; ++j) {
        int col_sum = 0;
        for(int i=0; i<r; ++i) {
            col_sum += vec[i][j];
        }
        vec[r][j] = col_sum;
    }

    for(int i=0; i<r+1; ++i) {
        for(int j=0; j<c+1; ++j) {
            cout << vec[i][j];
            if (j != c) cout << " ";
        }
        cout << endl;
    }

    return 0;
}


Measured memory_bytes: 3168
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <climits>
#include <utility>

using namespace std;

#define int long long
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define rep1(i,n) for(int i=1;i<=(int)n;++i)
#define all(a) begin(a),end(a)
#define chmin(a,b) a=min(a,b)
#define chmax(a,b) a=max(a,b)

int X,Y,A,B,C;
vector<int> p,q,r;

using pii=pair<int,int>;

signed main()
{
	cin>>X>>Y>>A>>B>>C;
	p.resize(A);
	q.resize(B);
	r.resize(C);

	rep(i, A) scanf("%lld",&p[i]);
	rep(i, B) scanf("%lld",&q[i]);
	rep(i, C) scanf("%lld",&r[i]);

	sort(all(p), greater<int>());
	sort(all(q), greater<int>());
	sort(all(r), greater<int>());

	priority_queue<int, vector<int>, greater<int>> pq1;
	priority_queue<int, vector<int>, greater<int>> pq2;

	int sum = 0;

	rep(i, X) {
		sum+=p[i];
		pq1.push(p[i]);
	}
	rep(i, Y) {
		sum+=q[i];
		pq2.push(q[i]);
	}

	int ans = sum, x = 0, y = 0;
	rep(i, min(X+Y,C)){
		int v1(1e10), v2(1e10);
		if (not pq1.empty()) {
			v1 = pq1.top();
		}
		if (not pq2.empty()) {
			v2 = pq2.top();
		}
		if (x == X) {
			pq2.pop();
			sum -= v2;
			y++;
		} else if (y == Y) {
			pq1.pop();
			sum -= v1;
			x++;
		} else if (v1 > v2) {
			pq2.pop();
			sum -= v2;
			y++;
		} else {
			pq1.pop();
			sum -= v1;
			x++;
		}
		sum += r[i];
		ans = max(ans, sum);
	}

	cout << ans << endl;
}


Measured memory_bytes: 4852
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stdlib.h>
#include <map>

using namespace std;

int main()
{
	int n, d; long long x, y;
	int count = 0;
	double distance;
	cin >> n >> d;

	for(int i = 0; i<n; i++){
		cin >> x >> y;
		distance = sqrt(pow(x, 2) + pow(y, 2));
		if(distance <= d)
			count++;
	}

	cout << count ;
}

Measured memory_bytes: 3676
#include <bits/stdc++.h>
using namespace std;
const int BASE = 998244353;

int update(int &r, int &g, int &b)
{
  return g && b ? min(g--, b--) : max(g + b - (r++), 1);
}

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

  int n;
  string s;
  cin >> n >> s;

  int r = 0, g = 0, b = 0;
  long long ans = 1;
  for (int i = 0; i < n * 3; i++)
    if (s[i] == 'R') ans = ans * update(r, g, b) % BASE;
    else if (s[i] == 'G') ans = ans * update(g, r, b) % BASE;
    else ans = ans * update(b, r, g) % BASE;

  for (int i = 2; i <= n; i++)
    ans = ans * i % BASE;

  cout << ans << endl;
}


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


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

  int ans = 0;
  for (int i = 1; i <= N; i += 2) {
    int count = 0;
    for (int j = 1; j <= i; ++j) {
      if (i % j == 0) {
        count++;
      }
    }
    if (count == 8) {
      ans++;
    }
  }

  cout << ans << endl;

  return 0;
}


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

int main() {
    ll N; cin >> N;
    string S; cin >> S;
    if (N % 2 == 1) {
        cout << "No" << endl;
        return 0;
    }
    bool isDuplicate = true;
    for (int i = 0; i < N/2; i++) {
        if (S[i] != S[i + N/2]) {
            isDuplicate = false;
        }
    }

    if (isDuplicate) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
N, M = map(int, input().split())
mod = 10**9 + 7


def factorize(n):
    b = 2
    fct = {}
    while b * b <= n:
        while n % b == 0:
            n //= b
            if b in fct.keys():
                fct[b] += 1
            else:
                fct[b] = 1
        b = b + 1
    if n > 1:
        fct[n] = 1
    return fct


from operator import mul
from functools import reduce


def cmb(n, r):
    r = min(n-r, r)
    if r == 0:
        return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1, r + 1))
    return over // under


fac_list = factorize(M)
ans = 1
for k, v in fac_list.items():
    ans *= cmb(v+N-1, v)
    if ans >= mod:
        ans %= mod

print(int(ans))

Measured memory_bytes: 3572
#[allow(unused_macros)]
macro_rules! input {
    ( $($t:ty),* ) => {{
        let mut s = String::new();
        std::io::stdin().read_line(&mut s);
        let mut splits = s.trim().split_whitespace();
        ($( { splits.next().unwrap().parse::<$t>().unwrap() },)*)
    }}
}

#[allow(unused_must_use)]
#[allow(unused_variables)]
fn solve() {
    let (h,) = input!(u64);

    let mut n = h;
    let mut count = 0;
    while n != 1 {
        n /= 2;
        count += 1;
    }

    println!("{}", 2_u64.pow(count + 1) - 1);
}

fn main() {
    solve();
}


Measured memory_bytes: 4352
#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>;
const int INF = 1 << 29;
 
int main() {
	int x;
	cin >> x;
	if (x==1) {
		cout << 1 << endl;
		return 0;
	}
	//vector<int> beki;
	int b, p;
	int ans = 0;
	for (int i = 2; i < 32; i++)
	{
		int j = 2;
		while(pow(i, j) <= x) {
			ans = max(ans, int(pow(i, j)+0.5));
			j++;
		}
	}
	cout << ans << endl;
	//sort(beki.begin(), beki.end(), greater<int>());
	//cout << beki[0] << endl;
	return 0;
}

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

using namespace std;
long long int n;
long long int arr[100005][3];
long long int dp[100005][3];
long long int FindMax(long long int row,long long int index){
  if(row==n-1){
    return dp[row][index]; 
  }
  if(index==0){
    if(dp[row][index]==-1){
      dp[row][index] = arr[row][index] + max(FindMax(row+1,1),FindMax(row+1,2));
    }
    return dp[row][index];
  }
  else if(index==1){
    if(dp[row][index]==-1){
      dp[row][index] = arr[row][index] + max(FindMax(row+1,0),FindMax(row+1,2));
    }
    return dp[row][index];
  }
  else{
    if(dp[row][index]==-1){
      dp[row][index] = arr[row][index] + max(FindMax(row+1,0),FindMax(row+1,1));
    }
    return dp[row][index];
  }
}

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin>>n;
  long long int i,j;
  for(i=0;i<n;i++){
    for(j=0;j<3;j++){
      cin>>arr[i][j];
      dp[i][j] = -1;
    }
  }
  dp[n-1][0] = arr[n-1][0];
  dp[n-1][1] = arr[n-1][1];
  dp[n-1][2] = arr[n-1][2];
  FindMax(0,0);
  FindMax(0,1);
  FindMax(0,2);
  cout<<max(dp[0][0],max(dp[0][1],dp[0][2]))<<endl;
  return 0;
}


Measured memory_bytes: 9600