akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B,L,R;
string S,T;
const ll MOD = (1e+9) + 7;
const ll INF = 1LL << 60;
typedef pair<ll,ll> P;

typedef vector<P> vp;
typedef vector<vp> matP;

int main(){
    cin>>N>>M;
    mat p(8,vec(N,0));
    rep(i,N){
        cin>>A>>B>>L;
        rep(j,8){
            ll temp = 0;
            temp += (j&1) ? A : -A;
            temp += ((j>>1)&1) ? B : -B;
            temp += ((j>>2)&1) ? L : -L;
            p[j][i] = temp;
        }
    }
    rep(i,8) sort(p[i].begin(), p[i].end());
    rep(i,8) reverse(p[i].begin(), p[i].end());
    ll ans = -1;
    rep(i,8){
        ll temp = 0;
        rep(j,M){
            temp += p[i][j];
        }
        ans = max(ans,temp);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<string>
#include<iostream>

using namespace std;

struct Era{
	string name;
	int l,r;
};

int main(){
	for(int n,q;cin>>n>>q,n;){
		Era era[1000];
		for(int i=0;i<n;i++){
			int erabased,western;
			cin>>era[i].name>>erabased>>western;
			era[i].l=western-erabased+1;
			era[i].r=western;
		}

		while(q--){
			int y;	cin>>y;
			bool found=false;
			for(int i=0;i<n;i++){
				if(era[i].l<=y && y<=era[i].r){
					cout<<era[i].name<<' '<<y-era[i].l+1<<endl;
					found=true;
					break;
				}
			}
			if(!found)	cout<<"Unknown"<<endl;
		}
	}

	return 0;
}

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

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int N,M,C;
cin>>N>>M>>C;

vector<int>B(M);
rep(i,M)cin>>B[i];

int ok=0;
rep(i,N){
    int score=0;
    int A;
    rep(j,M){
        cin>>A;
        score+=A*B[j];
    }
    if(score+C>0)ok++;
}
cout<<ok<<endl;
//system("pause");
return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll  = long long;
using vvl = vector<vector<ll>>;
using vl  = vector<ll>;
#define _GLIBCXX_DEBUG
#define acc_io cin.tie(0);ios::sync_with_stdio(false)
#define all(x) x.begin(),x.end()
#define rep(i,sta,end) for(ll i=sta;i<end;i++)
#define lcm(a,b) (a)/__gcd((a),(b))*(b)
#define pb push_back
const ll MOD = 1000000007;
const double PI = acos(-1);  
//name[i]   -> vl  name(i)
//name[i][j]-> vvl name(i,vl(j))
//or-> ||
//map<int,int>mp

//ll n;
//ll ans;
string s,t;
signed main(){
	acc_io;
//	ans=0;
	cin>>s>>t;
	t.pop_back();
	if(s==t) 	cout<<"Yes"<<endl;
	else		cout<<"No"<<endl;
	return 0;
}


Measured memory_bytes: 3652
N=int(input())
a=[int(i) for i in input().split()]
c=list(range(len(a)))
d=0
for j in range(len(a)):
    while a[j]%2==0:
        d=d+1
        a[j]=a[j]/2
        c[j]=d
    d=0
print(min(c))

Measured memory_bytes: 3060
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define mfill(x,y) memset(x,y,sizeof(x))
#define all(v) v.begin(), v.end()
#define in(x,y,h,w) if(0<=x&&x<h&&0<=y&&y<w)
#define y0 y12345
#define y1 y54321

#ifdef LOCAL
#define debug(...) fprintf(stderr,__VA_ARGS__)
#else
#define debug(...) 42
#endif

using ul = unsigned long;
using ll = long long;
using P = pair<int, int>;
using vint = vector<int>;using vvint = vector<vector<int>>;
using vll = vector<ll>;using vvll = vector<vector<ll>>;
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a, const T &b){if(a>b){a=b;return 1;}return 0;}
template <class T>void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
	v.assign(a, vector<T>(b, t));
}
template <class T>T gcd(T &a, T &b){if(a<b){swap(a,b);} T r = a%b; while(r!=0){a=b;b=r;r=a%b;} return b;}

vint dx = {-1, 0, 1, 0}, dy = {0, -1, 0, 1};
vint dx8 = {-1, -1, -1, 0, 1, 1, 1, 0}, dy8 = {-1, 0, 1, 1, 1, 0, -1, -1};

int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
	debug("debug test\n");
   	int n,m;cin>>n;int k;cin>>k;
	vint h(n);
	rep(i, n){
		cin>>h[i];
	}
	sort(all(h));
	ll ans = 0;
	rep(i, n-k){
		ans += h[i];
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1024
import java.util.*;
 
public class Main {
 	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		ArrayList<Pair> sp = new ArrayList<Pair>();
		ArrayList<Integer> ans = new ArrayList<Integer>();

		for(int i=0; i<N; i++){
			String S = sc.next();
			int P = sc.nextInt();
			Pair pair = new Pair(S, P, i);

			//System.out.println(pair.s);
			//System.out.println(pair.p);

			sp.add(pair);
			ans.add(i);

		}

		Collections.sort(sp, new ScoreComparator());
		//Collections.sort(sp);

		for(int i=0; i<N; i++){
			//System.out.println(sp.get(i).s);
			//System.out.println(sp.get(i).p);
			System.out.println(sp.get(i).n+1);
		}


	}

}

class Pair {
	public String s;
	public int p;
	public int n;

	Pair(String S, int P, int n){
		this.s = S;
		this.p = P;
		this.n = n;
	}
}

class ScoreComparator implements Comparator<Pair> {

	@Override
	public int compare(Pair p1, Pair p2) {
		if(p1.s.equals(p2.s)==true){
			return p1.p > p2.p ? -1 : 1;
		}else{
			if(p1.s.compareTo(p2.s)<0){
				return -1;
			}else{
				return 1;
			}
		}
		//return p1.p < p2.p ? -1 : 1;
		//return p1.s.equals(p2.s) ? -1 : 1;
	}
}



Measured memory_bytes: 36024
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
#define MOD @
#define ADD(X,Y) ((X) = ((X) + (Y)%MOD) % MOD)
typedef long long i64; typedef vector<int> ivec; typedef vector<string> svec;

int main(){
  long long int n, a[5], x=1000000000000005, t;
  cin >> n;
  for(int i=0;i<5;i++){
    cin >> a[i];
    x=min(a[i],x);
  }
  if(n%x==0)t=n/x;
  else t=n/x+1;
  if(n<=x)t=1;
  cout << t+4 << endl;
  return 0;
}


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

public class Main {
  public static void main(String[] args) throws IOException {
    Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
    int n = in.nextInt();
    int[] a = new int[n + 1];
    int[] b = new int[n + 1];
    int[] c = new int[n + 1];
    for (int i = 1; i <= n; i++) {
      a[i] = in.nextInt();
      b[i] = in.nextInt();
      c[i] = in.nextInt();
    }
    final Solver solve = new Solver();
    System.out.println(solve.solve(a, b, c));
  }
}

class Solver {
  public int solve(int[] a, int[] b, int[] c) {
    int n = a.length;
    int[][] dp = new int[n][3];

    dp[1][0] = a[1];
    dp[1][1] = b[1];
    dp[1][2] = c[1];

    for (int i = 2; i < n; i++) {
      for (int j = 0; j < 3; j++)  {
        if (j == 0) {
          dp[i][j] = Math.max(dp[i-1][1], dp[i-1][2]) + a[i];
        } else if (j == 1) {
          dp[i][j] = Math.max(dp[i-1][0], dp[i-1][2]) + b[i];
        } else {
          dp[i][j] = Math.max(dp[i-1][1], dp[i-1][0]) + c[i];
        }
      }
    }

    int ans = Math.max(dp[n - 1][0], Math.max(dp[n - 1][1], dp[n - 1][2]));
    return ans;
  }
}


Measured memory_bytes: 93256
#include<bits/stdc++.h>
using namespace std;
int dx[4] = {1, 0 ,-1, 0};
int dy[4] = {0 ,-1, 0, 1};
int h, w, c;
bool used[10][10];
int dfs(vector<vector<int> > &grid, int x, int y, int p, int d) {
  int res = 1;
  for (int i = 0; i < 4; i++) {
    int nx = x + dx[i], ny = y + dy[i];
    if(0 <= nx && nx < w &&
       0 <= ny && ny < h &&
       used[ny][nx] == false && 
       grid[ny][nx] == p){
      grid[ny][nx] = d;
      used[ny][nx] = true;
      res += dfs(grid, nx, ny, p, d);
    }
  }
  return res;
}

int solve(vector<vector<int> > &grid, vector<int> &change, int depth){
  int res = 0;
  if(depth == 4){
    vector<vector<int> > tmp = grid;
    for (int i = 0; i < 5; i++) {
      memset(used, 0, sizeof(used));
      int a = grid[0][0];
      grid[0][0] = change[i];
      if(a == change[i])continue;
      res = max(res, dfs(grid, 0, 0, a, change[i]));
    }
    memset(used, 0, sizeof(used));
    used[0][0] = true;
    res = max(res, dfs(grid, 0, 0, change[4], change[4]));
    memset(used, 0, sizeof(used));
    grid = tmp;
    return res;
  }
  for (int i = 1; i <= 6; i++) {
    change[depth] = i;
    res = max(res, solve(grid, change, depth + 1));
  }
  return res;
}


int main(int argc, char *argv[]){
  while(cin >> h >> w >> c, c){
    vector<vector<int> >grid(h, vector<int>(w, 0));
    for (int i = 0; i < h; i++) {
      for (int j = 0; j < w; j++) {
        cin >> grid[i][j];
      }
    }
    vector<int> change(5, 0);
    change[4] = c;
    std::cout << solve(grid, change, 0) << std::endl;
  }
  
  return 0;
}

Measured memory_bytes: 1224
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())

struct mint {
    const int mod = 1e9 + 7;
    long long x;
    
    mint (long long x = 0) : x((x % mod + mod) % mod) {
        
    }
    
    mint& operator=(const long long a) {
        x = a % mod;
        return *this;
    }
    
    mint& operator=(const mint a) {
        x = a.x % mod;
        return *this;
    }
    
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    
    mint operator+(const mint a) const {
        mint res(*this);
        return res += a;
    }
    
    mint& operator-=(const mint a) {
        if ((x += (mod - a.x)) >= mod) x -= mod;
        return *this;
    }
    
    mint operator-(const mint a) const {
        mint res(*this);
        return res -= a;
    }
    
    mint& operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }
    
    mint operator*(const mint a) const {
        mint res(*this);
        return res *= a;
    }
    
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }
    
    mint inv() const {
        return pow(mod - 2);
    }
    
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    
    mint operator/(const mint a) const {
        mint res(*this);
        return res /= a;
    }
};


vector<pair<ll, ll>> factorize(ll n) {
    vector<pair<ll, ll>> res;
    for (ll i = 2; (i * i) <= n; i++) {
        if (n % i) continue;
        res.emplace_back(i, 0);
        while((n % i) == 0) {
            n /= i;
            res.back().second++;
        }
    }
    if (n != 1) res.emplace_back(n, 1);
    return res;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // std::ifstream in("input.txt");
    // std::cin.rdbuf(in.rdbuf());
    const ll mod = 1e9 + 7;
    ll n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    map<ll, ll> lcm;
    rep(i, n) {
        vector<pair<ll, ll>> fac = factorize(a[i]);
        rep(ii, sz(fac)) {
            lcm[fac[ii].first] = max(lcm[fac[ii].first], fac[ii].second);
        }
    }
    mint total = 1;
    for(auto x : lcm) {
        rep(i, x.second) total *= x.first;
    }
    mint ans = 0;
    rep(i, n) {
        ans += total / a[i];
    }
    cout << ans.x << endl;
    return 0;
}


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

int main(){
  int N,K;
  cin >> N >> K;
  vector<int64_t> h(N);
  priority_queue<int64_t,vector<int64_t>,greater<int64_t> > pq;
  for(int i=0;i<N;i++){
    cin >> h.at(i);
  }
  sort(h.begin(),h.end());
  for(int i=0;i<N;i++){
    if(i+K-1>=N){
      break;
    }
    pq.push(h.at(i+K-1)-h.at(i));
  }
  cout << pq.top() << endl;
  return 0;
}


Measured memory_bytes: 2168
import Data.Char

main = do
  s <- getLine
  let a = ((read . take 2) s) `elem` [1..12]
  let b = ((read . drop 2) s) `elem` [1..12]
  putStrLn $ if a && b then "AMBIGUOUS" else if a then "MMYY" else if b then "YYMM" else "NA"

Measured memory_bytes: 508
#include <bits/stdc++.h>
#define pb push_back
typedef long long int ll;
#define loop(a,b) for(int i=a;i<b;i++)
#define say(a) cout<<a<<endl
#define say2(a,b) cout<<a<<" "<<b<<endl;
ll mod =1e9+7;
using namespace std;

int main()
{
   int a;char s[10];
   scanf("%d %s",&a,s);
   if(a<3200) say("red");
   else say(s);
}


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

int main() {
  int n, d;
  cin >> n >> d;
  int a = 2*d+1;

  if(n % a == 0){
     cout << n/a << "\n";
  }
  else{
      cout << n/a+1 << "\n";
  }
}

Measured memory_bytes: 256
#[allow(unused_imports)]
use proconio::marker::{Bytes, Chars, Usize1};
use proconio::{fastout, input};
#[fastout]
fn main() {
    input! {
        n: usize,
        l: [usize; n],
    }
    let mut ans = 0;
    if n <= 2 {
        println!("{}", ans);
        return;
    }
    for i in 0..n - 2 {
        for j in i + 1..n - 1 {
            if l[i] == l[j] {
                continue;
            }
            for k in j + 1..n {
                if l[i] == l[k] || l[j] == l[k] {
                    continue;
                }
                if l[i] + l[j] > l[k] && l[j] + l[k] > l[i] && l[i] + l[k] > l[j] {
                    ans += 1;
                }
            }
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 2212
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <vector>

using namespace std;

int main() {
  int n;
  scanf("%d", &n);

  vector<int> l(n);
  for (int i = 0; i < n; i++) {
    int x;
    scanf("%d", &x);
    l[i] = x;
  }

  sort(l.begin(), l.end(), greater<int>());

  int sum = 0;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      int a = l[i], b = l[j];
      for (int k = j + 1; k < n; k++) {
        int c = l[k];
        if (c >= (a + b)) {
          continue;
        }
        
        if (a < (b + c) && b < (c + a)) {
          sum++;
        }
      }
    }
  }

  cout << sum << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <sstream>
#include <cassert>
using namespace std;
static const double EPS = 1e-5;
typedef long long ll;
typedef pair<int,int> PI;
typedef vector<int> vi;
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define mp make_pair
#define pb push_back
#define f first
#define s second

main(){
  string str;
  while(getline(cin,str)){
    if(str[0]=='0')break;

    int ans=0,n1=0;
    stringstream ss(str);
    int t;
    while(ss>>t){
      if(t==1)n1++;
      if(t>10)t=10;
      ans+=t;
    }
    while(n1 && ans<12){
      n1--;
      ans+=10;
    }
    if(ans>21)ans=0;
    cout<<ans<<endl;
  }
}

Measured memory_bytes: 0
n,l=map(int, input().split())
arry=[]
ans=[]
ans2=[]
for i in range(n):
  arry.append(l+i)
for i in range(n):
  ans.append(sum(arry)-arry[i])
  ans2.append(abs(sum(arry)-(sum(arry)-arry[i])))
print(ans[ans2.index(min(ans2))])


Measured memory_bytes: 3060
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>
using namespace std;

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

template<class T> vector<T> make_vec(size_t a) { return vector<T>(a); }
template<class T, class... Ts> auto make_vec(size_t a, Ts... ts) {
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template<class T, class V>
typename enable_if<is_class<T>::value == 0>::type fill(T &t, const V &v) {
    t = v;
}
template<class T, class V>
typename enable_if<is_class<T>::value != 0>::type fill(T &t, const V &v){
    for (auto &e : t) fill(e, v);
}

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }

#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }


long long a, b, c;
int main() {
    cin >> a >> b >> c;
    cout << min(a*b, c) << endl;
}
                                                                         


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


int main() {

	int n, m;

	scanf("%d %d", &n, &m);

	int tmp[3] = {10, 10, 10};
	int s[5];
	int c[5];

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



	for(int i = 0; i < m; i++) {
		if( (tmp[s[i] -1]) == 10) {
			tmp[s[i] -1] = c[i];
		}
		else if( (tmp[s[i] -1]) == c[i]){
			continue;
		}
		else{
			printf("-1\n");
			return 0;
		}
	}

	if(tmp[0] == 10 && n != 1) {
		tmp[0] = 1;
	}

	for(int i = 0; i < n; i++) {
		if(tmp[i] == 10) {
			tmp[i] = 0;
		}
	}

	int ans = 0;
	if(n == 3) {
		if( tmp[0] == 0 ){
			printf("-1\n");
			return 0;
		}
		ans = tmp[0] * 100 + tmp[1] * 10 + tmp[2];
	} else if( n == 2) {
		if( tmp[0] == 0 ){
			printf("-1\n");
			return 0;
		}
		ans = tmp[0] * 10 + tmp[1];
	} else if( n == 1) {

		ans = tmp[0];
	}

	printf("%d", ans);

	return 0;

}

Measured memory_bytes: 128
//

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

int main(){
	int A[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
	int K;
	cin >> K;

	cout << A[K - 1] << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define sws ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define INFINITO 1000000000
#define ll long long
#define vi vector<int>
#define pb push_back
#define pii pair<int, int>
#define mp make_pair
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define fo(i, n) for( int i = 0; i < n; i++ )


int main() {

    string s;
    cin >> s;

    cout << (s[1] == 'B' ? "ARC\n" : "ABC\n");

    return 0;
}

Measured memory_bytes: 3592
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    
    int H = sc.nextInt();
    int W = sc.nextInt();
    int A = sc.nextInt();
    int B = sc.nextInt();
    sc.close();
    
    for(int tate=1;tate<=H;tate++){
      for(int yoko=1;yoko<=W;yoko++){
        if (tate<=B){
          if(yoko<=A){
            System.out.print("0");
          }else{
            System.out.print("1");
          }
        }else{
          if(yoko<=A){
            System.out.print("1");
          }else{
            System.out.print("0");
          }
        }
      }
      System.out.println("");
    }

  }  
}

Measured memory_bytes: 46140
#include<iostream>  
#include<cmath>
#include<string>
using namespace std;
int main(){ 
	int n,r;
	cin>>n>>r;
	int count=1;
	int r_=r;
	while(1){
		if(r>n)
			break;
		else
			r*=r_;
		count++;
	}
	cout<<count;
}




 




Measured memory_bytes: 256
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))

AX=[A[i%N]^A[(i-1)%N] for i in range(N,0,-1)]
BX=[B[i%N]^B[(i-1)%N] for i in range(N,0,-1)]
BX2=BX+BX
#print(BX2)
#print(AX)

shift=[0]*(N+1)
k=1
l=0
while k<N:
    if AX[k]==AX[l]:
        k+=1
        l+=1
        shift[k]=l
    elif l>0:
        l=shift[l]
    else:
        k+=1
        shift[k]=0
#print(shift)

ans=[]
ai=bi=0
Z=0
while bi<N:
    #print(bi,ai)
    if BX2[bi+ai]==AX[ai]:
        ai+=1
        if ai==N-1:
            print(bi,A[bi]^B[0])
            ans.append((bi+1)%N)
            bi+=ai-shift[ai]
            ai=shift[ai]
    else:
        bi+=1 if ai==0 else ai-shift[ai]
        ai=shift[ai]


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

int main(){
    string S;
    cin >> S;
    size_t N = S.length();
    for(int i=0;i<N;i++){
        if( i%2 == 0 && S[i] == 'L'){
            cout << "No" << endl;
            return 0;
        }
        else if( i%2 == 1 && S[i] == 'R'){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <set>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <limits>
#include <bitset>
#include <stack>
#include <queue>
#include <ctype.h>

typedef long long int lli;
#define rep(i,s,N) for(int i=s;i<N;i++)
#define MOD 1000000007
#define more(a,b) (((a)>(b))?(a):(b))
#define less(a,b) (((a)<(b))?(a):(b))
using namespace std;


int main(void)
{
	int N; cin >> N;
	vector<int> X(N); rep(i, 0, N)cin >> X[i];
	int ans = 10000000;
	rep(x, 0, 101) {
		int tmp = 0;
		rep(i, 0, N) {
			tmp += pow(X[i] - x, 2);
		}
		ans = min(ans, tmp);
	}
	cout << ans << endl;

	return 0;
}


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

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}

int main() {
	int n = ri(), t = ri();
	t--;
	int a[n], b[n];
	for (int i = 0; i < n; i++) a[i] = ri(), b[i] = ri();
	int dp[t + 1][2];
	memset(dp, 0, sizeof(dp));
	for (int i = 0; i < n; i++) {
		int next[t + 1][2];
		memcpy(next, dp, sizeof(next));
		for (int j = t - a[i]; j >= 0; j--) {
			next[j + a[i]][0] = std::max(next[j + a[i]][0], dp[j][0] + b[i]);
			next[j + a[i]][1] = std::max(next[j + a[i]][1], dp[j][1] + b[i]);
		}
		for (int j = 0; j <= t; j++) next[j][1] = std::max(next[j][1], dp[j][0] + b[i]);
		memcpy(dp, next, sizeof(next));
	}
	int res = 0;
	for (int i = 0; i <= t; i++)
		for (int j = 0; j < 2; j++) res = std::max(res, dp[i][j]);
	std::cout << res << std::endl;
	return 0;
}


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

using namespace std;
using ll = long long;

int main() {
#ifdef LOCAL
    freopen("in1.txt", "r", stdin);
    freopen("out1.txt", "w", stdout);
#endif


    int n;
    cin>>n;
    if(n%2==0 or n%5==0) puts("-1");
    else{
        int a = 7;
        int num = 1;
        while(1){
            if(a%n==0) break;
            a = a * 10 + 7 ;
            a %= n;
            num++;
        }
        cout<<num;
    }

    return 0;
}

Measured memory_bytes: 3604
//#include <bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
using namespace std;
typedef long long ll;//int64
typedef unsigned long long ull;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
//----------program from here----------




int main(){
    int a,b,c;
	cin>>a>>b>>c;

	if(c<=a+b){
		cout<<"Yes";
    }else{
		cout<<"No";
    }






    return 0;
}

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

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

int H,W;
char A[1005][1005];

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

struct dat{int y,x,d;};

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

    cin >> H >> W;

    queue<dat> que;
    int dist[1005][1005];
    int cnt = 0;
    int ans = 0;

    for (int i = 1;i <= H;i++){
        for (int j = 1;j <= W;j++){
            dist[i][j] = -1;
            cin >> A[i][j];
            if(A[i][j] == '#'){
                que.push({i,j,0});
                cnt++;
                dist[i][j] = 0;
            }
        }
    }

    while(que.size()){
        dat from = que.front(); que.pop();
        //cout << from.y << " " << from.x << endl;
        for (int i = 0;i < 4;i++){
            int ty = from.y+dy[i];
            int tx = from.x+dx[i];
            if(dist[ty][tx] == -1 && (tx > 0 && ty > 0 && tx <= W && ty <= H)){
                dist[ty][tx] = from.d+1;
                que.push({ty,tx,from.d+1});
                ans = max(ans,dist[ty][tx]);
            }
        }
    }

    cout << ans << endl;

    return 0;

}


Measured memory_bytes: 17296
#include <bits/stdc++.h>
#define MOD 100000007LL
using namespace std;

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

ll labs(ll x){
	if(x<0LL)return -x;
	return x;
}

ll n;
ll a,b,c,d;

int main(void){
	scanf("%lld%lld%lld%lld%lld",&n,&a,&b,&c,&d);
	bool flag=false;
	for(ll i=0;i<=n-1;i++){
		ll lo=-d*(n-1LL-i)+c*i;
		ll up=d*i-c*(n-1LL-i);
		if(lo<=b-a && b-a<=up)flag=true;
	}
	printf("%s\n",flag?"YES":"NO");
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <functional>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <tuple>
#include <cassert>
#include <exception>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<P> vp;
#define rep(i,a,n) for(ll i = (a);i < (n);i++)
#define per(i,a,n) for(ll i = (a);i > (n);i--)
#define lep(i,a,n) for(ll i = (a);i <= (n);i++)
#define pel(i,a,n) for(ll i = (a);i >= (n);i--)
#define clr(a,b) memset((a),(b),sizeof(a))
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define sz size()
#define print(X) cout << (X) << endl
#define fprint(NUM,X) cout << fixed << setprecision(NUM) << (X) << endl
#define fprints(NUM,X,Y) cout << fixed << setprecision(NUM) << (X) << " " << (Y) << endl
const ll INF = 1e+9+7;
ll n,m,l;
// string s,t;
ll d[200010],dp[1010][1010];
double w[1000],v[1000];
double box[200010];

static const int MAX = 100000;
struct edge{int to,cap,rev;};
vector<edge> graph[MAX];
int level[MAX];
int iter[MAX];


void add_edge(int from,int to,int cap){
  graph[from].push_back((edge){ to , cap , (int)graph[to].size() });
  graph[to].push_back((edge){ from , 0 , (int)graph[from].size() - 1});
}

void bfs(int s){
  memset(level,-1,sizeof(level));
  queue<int> que;
  level[s] = 0;
  que.push(s);

  while(!que.empty()){
    int v = que.front();que.pop();
    for(int i = 0;i < graph[v].size();i++){
      edge &e = graph[v][i];
      if(e.cap > 0 && level[e.to] < 0){
        level[e.to] = level[v] + 1;
        que.push(e.to);
      }
    }
  }
}

int dfs(int v,int t,int f){
  if(v == t)return f;
  for(int &i = iter[v];i < graph[v].size();i++){
    edge &e = graph[v][i];
    if(e.cap > 0 && level[v] < level[e.to]){
      int d = dfs(e.to ,t ,min(f,e.cap));
      if(d > 0){
        e.cap -= d;
        graph[e.to][e.rev].cap += d;
        return d;
      }
    }
  }
  return 0;
}

int max_flow(int s,int t){
  int flow = 0;
  for(;;){
    bfs(s);
    if(level[t] < 0)return flow;
    memset(iter,0,sizeof(iter));
    int f;
    while((f = dfs(s,t,INF)) > 0){
      flow += f;
    }
  }
}

int main(){
  cin >> n >> m;
  rep(i,0,m){
    int a,b,c;
    cin >> a >> b >> c;
    add_edge(a,b,c);
  }
  print(max_flow(0,n-1));
  return 0;
}


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

#define rep(i,m,n) for(int (i)=(int)(m);i<(int)(n);i++)
#define rep2(i,m,n) for(int (i)=(int)(n)-1;i>=(int)(m);i--)
#define REP(i,n) rep(i,0,n)
#define REP2(i,n) rep2(i,0,n)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define all(hoge) (hoge).begin(),(hoge).end()
#define en '\n'
using ll = long long;
using ull = unsigned long long;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
typedef pair<ll, ll> P;
constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;
//constexpr long long MOD = (ll) 1e9 + 7;
constexpr long long MOD = 998244353LL;
typedef vector<ll> Array;
typedef vector<Array> Matrix;


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

struct Edge {
	ll to, cap, rev;
	Edge(ll _to, ll _cap, ll _rev) {
	to = _to; cap = _cap; rev = _rev;
	}
};
using Edges = vector<Edge>;
using Graph = vector<Edges>;

void add_edge(Graph& G, ll from, ll to, ll cap, bool revFlag, ll revCap) {
	G[from].push_back(Edge(to, cap, (ll)G[to].size()));
	if (revFlag)G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}

void solve(){
    ll n;
    cin>>n;
    string s;
    cin>>s;

    Array sum(n+1,0);
    REP(i,n) sum[i+1]=sum[i]+(s[i]=='E'?1:0);

    ll ans=n;
    REP(i,n){
        chmin(ans,(i-sum[i])+sum[n]-sum[i+1]);
    }
    cout<<ans<<en;

}

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

    solve();
    //ll t;cin>>t;REP(i,t) solve();

    return 0;
}

Measured memory_bytes: 2964
#include<bits/stdc++.h>
using namespace std;
char s[110];
int main(){
	cin>>s;
	int l=strlen(s);
	int vc=0,vf=0;
	for(int i=0;i<l;i++){
		if(s[i]=='C') vc=1;
		else if(s[i]=='F' && vc) vf=1; 
	}
	if(vf) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
from operator import attrgetter
class City:
    def __init__(self, city, pref, year):
        self.city = city
        self.pref = pref
        self.year = year
        self.number = 0

def main():
    N, M = map(int, input().split())
    prefcount = [0] * (N + 1)
    PY = [City(0, 0, 0)]
    for i in range(M):
        P, Y = map(int, input().split())
        PY.append(City(i + 1, P, Y))
    PY.sort(key=attrgetter("year"))
    for i in PY:
        i.number = str(i.pref * 1000000 + (prefcount[i.pref] + 1)).zfill(12)
        prefcount[i.pref] += 1
    PY.sort(key=attrgetter("city"))
    for i in range(1, M + 1):
        print(PY[i].number)
main()

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

int n;
cin >> n;
vector<char> s(n);
for(int i = 0;i < n;i++){
    cin >> s.at(i);
}

int count = 1;

for(int i = 0;i<n-1;i++){
    if(n==0){
        break;
    }else if(s.at(i) != s.at(i+1)){
        count++;
    }
}
cout << count << endl;
return 0;
}

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

int main() {
	int N, cnt = 0, a;
	cin >> N;
	for (int i = 0;i < N;i++) {
		cin >> a;
		if (a != i + 1) cnt++;
	}
	if (cnt < 3)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
}

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

using namespace std;
typedef long long ll;

ll H;
unordered_map<ll,ll> um;


ll C(ll t){
    if(um.count(t) > 0) return um[t];
    if(t == 1) return um[1] = 1;
    return um[t] = C(t/2) * 2 + 1;
}

int main(){
    cin >> H;
    cout << C(H) << endl;
    return 0;
}

Measured memory_bytes: 256
n = gets.to_i
s = gets.chomp
e = (s[0] == 'E' ? [1] : [0])
w = (s[0] == 'W' ? [1] : [0])

1.upto(n - 1) do |i|
  if (s[i] == 'E')
    e[i] = e[i - 1] + 1
    w[i] = w[i - 1]
  else
    e[i] = e[i - 1]
    w[i] = w[i - 1] + 1
  end
end
w.unshift(0)
min = Float::INFINITY
0.upto(n - 1) do |i|
  min = e[-1] - e[i] + w[i] - w[0] if min > e[-1] - e[i] + w[i] - w[0]
end
puts min

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

int main(){
    int H,W;
    cin >>H>>W;
    vector<vector<char>>vec(H,vector<char>(W));
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            cin >>vec.at(i).at(j);
           
        }
    }
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            cout <<vec.at(i).at(j);
        }
         cout <<endl;
         for(int j=0;j<W;j++){
            cout <<vec.at(i).at(j);
        }
         cout <<endl;

    }
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define ull unsigned long long
#define pb(a) push_back(a)
#define INF 100000000001
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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


int main()
{
    int n, m, s=0;
    cin >> n >> m;
    REP(i, m){
        int a;
        cin >> a;
        s += a;
    }
    if(s > n) cout << -1 << endl;
    else cout << n - s << endl;
}


Measured memory_bytes: 3644
n = int(input())
d = list(map(int,input().split()))
m = 998244353
import collections
c = collections.Counter(d)
if c[0] == 1 and d[0] == 0:
    ans = 1
else:
    ans = 0
d = sorted(d)
for i in range(1,n):
    ans *= c[d[i]-1]
    ans %= m
print(ans)

Measured memory_bytes: 23752
#include <bits/stdc++.h>
using namespace std;
constexpr int Mbit= 49;
using path= bitset<Mbit>;
using edge= pair<int, int>;
using Graph= vector<vector<edge>>;

void dfs(const Graph& gph, int g, int parent, int child, path* path_dfs, vector<path>* paths){
  if(g==child){
    paths->emplace_back(*path_dfs);
    return;
  }
  else{
    for(auto e:gph.at(child)){
      int neighbor, id_e;
      tie(neighbor, id_e)= e;
      if(neighbor != parent){
        path_dfs->set(id_e);
        dfs(gph, g, child, neighbor, path_dfs, paths);
        path_dfs->reset(id_e);
      }
    }
  }
}

int main(){
  constexpr int Cmax= 20;

  int N;
  cin >> N;
  const int M= N-1;
  Graph gph(N);

  int v1,v2;
  for(int j=0; j<M; j++){
    cin >> v1 >> v2;
    v1--; v2--; // 1-indexed -> 0-indexed
    gph.at(v1).emplace_back(v2, j);
    gph.at(v2).emplace_back(v1, j);
  }

  int C;
  cin >> C;
  vector<path> paths;
  for(int c=0; c<C; c++){
    cin >> v1 >> v2;
    v1--; v2--; // 1-indexed -> 0-indexed

    path path_empty;
    dfs(gph, v2, -1, v1, &path_empty, &paths);
  }

  int64_t ng= 0;
  for(int tmp=1; tmp<(1<<C); tmp++){
    bitset<Cmax> activesets(tmp);

    path activeedges;
    for(int c=0; c<C; c++){
      if(activesets.test(c)){
        activeedges |= paths.at(c);
      }
    }
    int Mfree= M- activeedges.count();

    if(activesets.count()% 2== 1){ ng+= 1LL<< Mfree; }
    else                         { ng-= 1LL<< Mfree; }
  }
  int64_t ans= (1LL<< M)- ng;
  
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
// type alias
typedef long long LL;
typedef pair<int,int> II;
typedef tuple<int,int,int> III;
typedef vector<int> VI;
typedef vector<string> VS;
typedef unordered_map<int,int> MAPII;
typedef unordered_set<int> SETI;
template<class T> using VV=vector<vector<T>>;
// minmax
template<class T> inline T SMIN(T& a, const T b) { return a=(a>b)?b:a; }
template<class T> inline T SMAX(T& a, const T b) { return a=(a<b)?b:a; }
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// collection
#define ALL(c) (c).begin(),(c).end()
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// stdout
#define println(args...) fprintf(stdout, ##args),putchar('\n');
// debug cerr
template<class Iter> void __kumaerrc(Iter begin, Iter end) { for(; begin!=end; ++begin) { cerr<<*begin<<','; } cerr<<endl; }
void __kumaerr(istream_iterator<string> it) { (void)it; cerr<<endl; }
template<typename T, typename... Args> void __kumaerr(istream_iterator<string> it, T a, Args... args) { cerr<<*it<<"="<<a<<", ",__kumaerr(++it, args...); }
template<typename S, typename T> std::ostream& operator<<(std::ostream& _os, const std::pair<S,T>& _p) { return _os<<"{"<<_p.first<<','<<_p.second<<"}"; }
#define __KUMATRACE__ true
#ifdef __KUMATRACE__
#define dump(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); __kumaerr(_it, args); }
#define dumpc(ar) { cerr<<#ar<<": "; FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }
#define dumpC(beg,end) { cerr<<"~"<<#end<<": "; __kumaerrc(beg,end); }
#else
#define dump(args...)
#define dumpc(ar)
#define dumpC(beg,end)
#endif

// $ cp-batch Test | diff Test.out -
// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG -fsanitize=address Test.cpp && ./a.out

/*
 
 5/3/2020
 
 18:44-
 
 */

const int MAX_N=100+1;
int D[MAX_N];
int N;

int solve() {
  VI cnt(13,0);
  REP(i,N+1) cnt[D[i]]++;
//  dumpc(cnt);
  REP(i,13) if(cnt[i]>2) return 0;
  if(cnt[0]==2||cnt[12]==2) return 0;
  VI B(24,0);
  bool lr=0;
  REP(i,13) {
    if(cnt[i]==2) B[i]=B[i==0?0:(24-i)]=1;
    else if(cnt[i]==1) {
      B[((i==0||lr)?i:(24-i))]=1;
      lr^=1;
    } else if(cnt[i]==0) continue;
    else assert(false);
  }
//  dumpc(B);
  int res=24;
  REP(i,24) if(B[i]) {
    int mind=24;
    REP(j,24) if(i!=j&&B[j]) SMIN(mind,min(abs(i-j),abs(j+24-i)));
    SMIN(res,mind);
  }
  return res;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout<<setprecision(12)<<fixed;
  
  cin>>N;
  REP(i,N) cin>>D[i+1];
  cout<<solve()<<endl;
  
  return 0;
}


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

#define rep(i, N) for (int i = 0; i < N; i++)
#define pb push_back

typedef long long ll;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef vector<int> vi;

const int MOD = 1e9 + 7;
const int INF = INT_MAX / 2;

bool check(int N, vector<vector<int> > G, vector<int> a) {
	rep(u, N) {
		set<int> st;
		for (int v : G[u]) st.insert(a[v]);
		int x;
		for (x = 0; st.count(x); x++);
		if (x != a[u]) return false;
	}
	return true;
}

int main() {
	int N; cin >> N;
	vector<vector<int> > G(N), _G(N);
	rep(u, N) {
		int v; scanf("%d", &v);
		v--;
		G[v].pb(u);
		_G[u].pb(v);
	}
	rep(z, 2) {
		vector<int> d(N);
		rep(u, N) d[u] = G[u].size();
		vector<int> a(N, -1);
		priority_queue<i_i, vector<i_i>, greater<i_i> > q;
		rep(u, N) q.push(i_i(d[u], u));
		while (q.size()) {
			i_i du = q.top(); q.pop();
			int u = du.second;
			if (du.first > d[u]) continue;
			set<int> st;
			for (int v: G[u]) st.insert(a[v]);
			int x;
			bool hoge = true;
			for (x = 0; ; x++) {
				if (st.count(x)) continue;
				if (d[u] && z && hoge) {
					hoge = false;
					continue;
				}
				break;
			}
			a[u] = x;
			for (int v: _G[u]) {
				d[v]--;
				if (a[v] == -1) q.push(i_i(d[v], v));
			}
		}
		if (check(N, G, a)) {
			cout << "POSSIBLE" << endl;
			return 0;
		}
	}
	cout << "IMPOSSIBLE" << endl;
}


Measured memory_bytes: 34544
#include<iostream>
#include<math.h>
#include<stdlib.h>
using namespace std;
int main(){
    int n,i,j,k,kk,f,ff;
    int a[110],b[110],c[110];
    cin >> n;
    for(i=0;i<n;i++)
        cin >> a[i] >> b[i] >> c[i];
    for(i=100;i>=0;i--)
    {
        for(j=100;j>=0;j--)
        {
            f=0;ff=0;
            kk=c[0]+abs(a[0]-i)+abs(b[0]-j);
            if(c[0]==0)
                ff=1;
            for(k=1;k<n;k++)
            {
                if(c[k]==0)
                {
                    if(kk>abs(a[k]-i)+abs(b[k]-j))
                    {
                        if(ff)
                            kk=abs(a[k]-i)+abs(b[k]-j);
                        else
                        {
                            f=1;
                            break;
                        }
                    }
                    continue;
                }
                if(ff)
                {
                    kk=c[k]+abs(a[k]-i)+abs(b[k]-j);
                    ff=0;
                }
                else if(kk!=c[k]+abs(a[k]-i)+abs(b[k]-j))
                {
                    f=1;
                    break;
                }
            }
            if(f==0)
            {
                cout << i << " " << j << " " << kk << endl;
                return 0;
            }
        }
    }
}


Measured memory_bytes: 256
m,e,j,s;main(n){for(;--n||scanf("%d",&n)*n;puts(m>99|e>99|j>99|m+e>179|s>239?"A":s>209||s>149&&m>79|e>79?"B":"C"))scanf("%d%d%d",&m,&e,&j),s=m+e+j;}

Measured memory_bytes: 0
# https://atcoder.jp/contests/cf16-final/tasks/codefestival_2016_final_b

n = gets.to_i
MAX = 10**8
# dp = Array.new(n + 1, MAX)
# dp[1] = [1]
# dp[2] = [2]
# dp[3] = [1, 2]
# dp[4] = [1, 3]
# dp[5] = [2, 3]
# dp[7] = [4, 3]
# dp[8] = [4,3,1]
# dp[9] = [4,3,2]
# dp[19] = [6,5,4,3,1]
# dp[20] = [6,5,4,3,2]
res = []
current_sum = 0
1.upto(n) do |i|
  res << i
  current_sum += i
  break if current_sum >= n
end
res.delete(current_sum - n)
puts res

Measured memory_bytes: 1788
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
using namespace std;

  int main(){
int a,b;
cin>> a >>b;
cout << (a+b+1)/2 << endl;
return 0;}

Measured memory_bytes: 384
#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 argc, char const *argv[])
{
	int x; cin >> x;
	for (int i = 0; i <= 1000; ++i) {
		if (100 * i <= x and x <= 105 * i) {
			cout << 1 << endl;
			return 0;
		}
	}
	cout << 0 << endl;
	return 0;
}


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

class Program {
    static void Main() {
        for (string line; !string.IsNullOrEmpty(line = Console.ReadLine());)
        {
            Console.WriteLine(ConvertString(line));
        }
    }

    static string ConvertString(string line) {
        var length = line.Length;

        if (length % 2 != 0) {
            return "NA";
        }

        var result = new StringBuilder(length / 2);

        for (int i = 0; i < length; i += 2) {
            var ch = ConvertChar(line[i], line[i + 1]);

            if (ch == char.MinValue) {
                return "NA";
            }

            result.Append(ch);
        }

        return result.ToString();
    }

    static char[,] charTable = {
        { 'a', 'b', 'c', 'd', 'e' },
        { 'f', 'g', 'h', 'i', 'j' },
        { 'k', 'l', 'm', 'n', 'o' },
        { 'p', 'q', 'r', 's', 't' },
        { 'u', 'v', 'w', 'x', 'y' },
        { 'z', '.', '?', '!', ' ' },
    };

    static char ConvertChar(char v1, char v2) {
        int i, j;
        if (!int.TryParse(v1.ToString(), out i) || !int.TryParse(v2.ToString(), out j) ||
            i < 1 || i > 6 || j < 1 || j > 5
        ) {
            return char.MinValue;
        }

        return charTable[i - 1, j - 1];
    }
}

Measured memory_bytes: 8804
n = int(input())
a = [int(input()) for _ in range(n)]

if n == 2:
	print(abs(a[0] - a[1]))
elif n == 3:
	print(max(abs(a[0] - a[1]) + abs(a[0] - a[2]), abs(a[1] - a[2]) + abs(a[1] - a[0]), abs(a[2] - a[1]) + abs(a[2] - a[0])))
else:
	b = sorted(a)
	ans = [0] * n
	if n % 2 == 0:
		for i in range(2, n-1, 2):
			ans[i] =  b[(i // 2) - 1]
			#print(i, ans[i])
		for i in range(1, n-1, 2):
			ans[i] = b[-1 - ((i - 1) // 2)]
			#print(i, ans[i])
		ans[0] = b[n // 2 - 1]
		ans[n-1] = b[n // 2]
	else:
		ans[0] = b[n // 2]
		if b[n // 2 + 1] + b[n // 2 - 1] >= 2 * b[n // 2]:
			for i in range(2, n-1, 2):
				ans[i] =  b[(i // 2) - 1]
			for i in range(1, n-1, 2):
				ans[i] = b[-1 - ((i - 1) // 2)]

			ans[n-1] = b[n // 2 - 1]
			#ans[n-2] = b[n // 2 + 1]
		else:
			for i in range(1, n-1, 2):
				ans[i] =  b[((i - 1) // 2)]
			for i in range(2, n-1, 2):
				ans[i] = b[-1 - ((i - 2) // 2)]

			ans[n-1] = b[n // 2 + 1]
			#ans[n-2] = b[n // 2 - 1]

	#print(ans)
	print(sum([abs(ans[i] - ans[i+1]) for i in range(n-1)]))

Measured memory_bytes: 12784
import sys,math,copy

def main():
    # import numpy as np
    input = sys.stdin.readline
    S = ''.join(reversed(input().strip()))

    # dp = np.zeros((13), dtype=int)
    # dp_ = np.zeros((13), dtype=int)
    dp = [0] * 13
    dp_ = [0] * 13
    mod13_tuple = tuple([i % 13 for i in range(12 ** 2 + 1)])
    tuple10 = tuple(range(10))
    tuple13 = tuple(range(13))
    divisor = 10 ** 9 + 7
    dp_[0] = 1
    mul = 1
    for i in range(len(S)):
        s = S[i]
        if s == '?':
            for d in tuple10:
                m = mod13_tuple[(d * mul)]
                for pm in tuple13:
                    dp[mod13_tuple[(pm+m)]] += dp_[pm]

        else:
            si = int(s)
            m = mod13_tuple[(si * mul)]
            for pm in tuple13:
                dp[mod13_tuple[(pm+m)]] = dp_[pm]

        # dp_ = dp % divisor
        # dp = dp * 0 # np.zeros((13), dtype=int)
        for j in tuple13:
            dp_[j] = dp[j] % divisor
            dp[j] = 0
        mul = mod13_tuple[(mul * 10)]
    print(dp_[5])

main()

Measured memory_bytes: 4468
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <functional>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cassert>
#define InfL 1000000000
#define InfLL 1000000000000000000LL
#define mod 1000000007
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rrep(i,n) for(int (i)=(n-1);(i)>=(0);(i)--)
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<db> vd;

int main() {
	ll K;
	cin >> K;
	string ans = "0";
	rep(k, K) {
		int n = ans.length();
		if (n == 1) {
			if (ans == "9")
				ans = "10";
			else
				ans[0]++;
			continue;
		}
		for(int i = n-2;i>=-1;i--){
			if (i == -1 && ans[0]=='9') {
				ans = "1";
				rep(i, n) {
					ans.push_back('0');
				}
				break;
			}
			else if (i == -1) {
				ans[0]++;
				for (int j = 0; j < n - 1; j++) {
					ans[j + 1] = ans[j] - 1;
					if (ans[j] == '0')
						ans[j + 1] = '0';
				}
			}
			if (ans[i] - ans[i + 1] >= 0 && ans[i+1]!='9') {
				ans[i + 1]++;
				for (int j = i + 1; j < n-1; j++) {
					ans[j + 1] = ans[j] - 1;
					if (ans[j] == '0')
						ans[j + 1] = '0';
				}
				break;
			}
		}
	}
	cout << ans << endl;
	return 0;
}

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

typedef long int lint;
typedef long long int llint;
typedef pair<int, int> pii;
typedef pair<int, string> pis;
typedef pair<long, long> pll;

#define EACH(t, c) for (auto&& t : c)
#define ALL(c) begin(c), end(c)
#define FOR(i, s, e) for (int i = (s); i < (int)(e); ++i)
#define REP(i, n) FOR(i, 0, n)
#define endl '\n'
#define fk first
#define sv second

const int dx[] = {1, 0, -1, 0, 1, 1, -1, -1}, dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
const int MOD = (int)1e9 + 7;
const int INF = 999999999;

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

  cin >> a >> b >> c >> x >> y;

  if (x > y) {
    swap(x, y);
    swap(a, b);
  }
  int cost = 0;
  if (a + b > c * 2) {
    cost = x * c * 2;
    y -= x;
    if (b * y < c * y * 2) {
      cost += b * y;
    } else {
      cost += c * y * 2;
    }
  } else {
    cost = a * x + b * y;
  }

  cout << cost << endl;
}

Measured memory_bytes: 256