akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
ll gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }    //最大公約数
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }     //最小公倍数
using Graph = vector<vector<int>>;
ll inf=300000000000000000;
const double PI = 3.14159265358979323846;
int main(){
  int r,c,k;
  cin >> r >> c >> k;
  ll o[r][c];
  rep(i,r)rep(j,c)o[i][j]=0;
  rep(i,k){
    ll a,b,c;
    cin >> a >> b >> c;
    a--;
    b--;
    o[a][b]=c;
  }
  vector<vector<vector<ll>>> dp(r, vector<vector<ll>>(c, vector<ll>(4,0)));
  rep(i,r)rep(j,c)rep(l,4)dp[i][j][l]=0;
  if(o[0][0]>0){
    dp[0][0][1]=o[0][0];
  }
  rep(i,r){
    rep(j,c){
      if(i+j==0)continue;
      if(o[i][j]==0){
        rep(l,4){
          if(j!=0){
            dp[i][j][l]=max(dp[i][j][l],dp[i][j-1][l]);
          }
          if(i!=0){
            dp[i][j][0]=max(dp[i][j][0],dp[i-1][j][l]);
          }
        }
      }
      else{
        if(j!=0){
          rep(l,4){
            dp[i][j][l]=max(dp[i][j][l],dp[i][j-1][l]);
            if(l!=3)dp[i][j][l+1]=max(dp[i][j][l+1],o[i][j]+dp[i][j-1][l]);
          }
        }
        if(i!=0){
          rep(l,4){
            dp[i][j][0]=max(dp[i][j][0],dp[i-1][j][l]);
            dp[i][j][1]=max(dp[i][j][1],o[i][j]+dp[i-1][j][l]);
          }
        }
      }
    }
  }
  ll ans=0;
  rep(i,4)ans=max(ans,dp[r-1][c-1][i]);
  cout << ans << endl;
}


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

using namespace std;

#define rep(i, n) for (int i = 0; i < n; ++i)
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define stl_repr(itr, x) for (auto itr = x.rbegin(); itr != x.rend(); ++itr)
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()

using llong = long long int;

const static int MOD = 1000000007;
const static int IINF = INT_MAX;
const static llong LINF = LLONG_MAX;
const static int dx[4] = {1, 0, -1, 0};
const static int dy[4] = {0, 1, 0, -1};

template<typename T> T my_gcd(T a, T b) {
    return (a ? my_gcd(b % a, a) : b);
}
template<typename T> T my_lcm(T a, T b){
    return a * b / my_gcd(a, b);    
}

const int MAX = 9999999;

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

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main (int argc, char *argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int x, y;
    cin >> x >> y;
    if ((2 * y - x) % 3 != 0 || (2 * x - y) % 3 != 0) {
    	cout << 0 << endl;
    	return 0;
    }

    COMinit();
    int n = (2 * y - x) / 3, m = (2 * x - y) / 3;
    cout << COM(n + m, n) << endl;

    return 0;
}

Measured memory_bytes: 234624
#include<iostream>

using namespace std;

string str,in;

int solve(int num){
  for(int i = 0; i < in.length(); i++){
    if(in[i] != str[num+i]) return 0;
  }
  return 1;
}
int main(){
  cin >> in;
  int num,sum = 0;
  cin >> num;
  for(int i = 0; i < num; i++){
    cin >> str;
    str += str;
    for(int i = 0; i < str.length()-in.length(); i++){
      if(solve(i)) {
	sum++;
	break;
      }
    }
  }
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 0
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		Scanner sc = new Scanner(System.in);

		String[] line = sc.nextLine().split(" ");

		int[] label = new int[line.length];
		for (int i=0; i < label.length; i++) {
			label[i] = Integer.parseInt(line[i]);
		}

		char[] order = sc.nextLine().toCharArray();

		Dice d = new Dice(label);

		for (int i=0; i < order.length; i++) {
			d.koroOrKaiten(order[i]);
		}

		System.out.println(d.ue);
	}

}

class Dice {
	int ue,mae,migi,hidari,ushiro,shita;

	int[] label = {
			this.ue, this.mae,
			this.migi, this.hidari,
			this.ushiro, this.shita,
	};

	Dice(int[] label) {
		ue = label[0];
		mae = label[1];
		migi = label[2];
		hidari = label[3];
		ushiro = label[4];
		shita = label[5];
	}

	Dice koroOrKaiten(char newsrl) {
		int temp = 0;

		switch (newsrl) {
		case 'N':
			temp = ue;
			ue = mae;
			mae = shita;
			shita =ushiro;
			ushiro = temp;
			break;
		case 'S':
			temp = ue;
			ue = ushiro;
			ushiro = shita;
			shita = mae;
			mae = temp;
			break;
		case 'E':
			temp = ue;
			ue = hidari;
			hidari = shita;
			shita = migi;
			migi = temp;
			break;
		case 'W':
			temp = ue;
			ue = migi;
			migi = shita;
			shita = hidari;
			hidari = temp;
			break;
		case 'R':
			temp = mae;
			mae = migi;
			migi = ushiro;
			ushiro = hidari;
			hidari = temp;
			break;
		case 'L':
			temp = mae;
			mae = hidari;
			hidari = ushiro;
			ushiro = migi;
			migi = temp;
			break;
		}

		return this;
	}

	boolean check(Dice d) {
		if (this.ue == d.ue && this.mae == d.mae &&
				this.migi == d.migi && this.hidari == d.hidari &&
				this.ushiro == d.ushiro && this.shita == d.shita) {
			return true;
		} else return false;
	}

}

Measured memory_bytes: 26076
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
void io(){ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);}
int main()
{
    io();
    ll s,w;
    cin>>s>>w;
    if(w>=s)
        cout<<"unsafe";
    else
        cout<<"safe";
}


Measured memory_bytes: 3652
#include<bits/stdc++.h>
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int mod = 1000000007;

int main() {
  string s, t;
  cin >> s >> t;
  bool ok = true;
  rep(i, s.length()) {
    if(s[i] != t[i]) ok = false;
  }
  if(ok) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 3628
#include <stdio.h>

int H;

void maxHeapify(int h[],int i){
  int left,right,largest,ex;
  
  left = 2*i;
  right = 2*i+1;

  if(left <= H && h[left] > h[i])largest = left;
  else largest = i;

  if(right <= H && h[right] > h[largest])largest = right;
  
  if(largest != i){
    ex = h[i];
    h[i] = h[largest];
    h[largest] = ex;
    maxHeapify(h,largest);
  }
}

void buildMaxHeap(int h[]){
  int i;

  for(i = H/2; i > 0; i--){
    maxHeapify(h,i);
  }
}

int main(){
  int i;
  int heap[500001];
  
  scanf("%d",&H);

  for(i = 1;i <= H; i++){
    scanf("%d",&heap[i]);
  }
  
  buildMaxHeap(heap);
	       
  for(i = 1;i <= H; i++){
    printf(" %d",heap[i]);
  }
   printf("\n");
  return 0;
}



Measured memory_bytes: 3724
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1e9;
using namespace std;
using ll = long long;
int N(int x) {
	return (x + 9) / 10 * 10;
}
int T(int x) {
	return N(x) - x;
}
int main() {
	int A, B, C, D, E;
	cin >> A >> B >> C >> D >> E;
	int sum = N(A) + N(B) + N(C) + N(D) + N(E);
	sum -= max({T(A) , T(B) , T(C) , T(D) , T(E)});
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 3580
n,x = map( int,input().split() )

ans = [-1,-1,-1]
ck = 0
for i in range(n+1):
  if i * 10000 > x :
    break

  for j in range(n+1-i):

    if i * 10000 + j * 5000 > x :
      break

    k = n - i - j
    if i * 10000 + j * 5000 + k * 1000 == x:
      ans = [i,j,k]
      ck = 1
      break

  if ck :
    break

print(' '.join(map(str,ans)))


Measured memory_bytes: 3060
import math

n = int(input())
ps = [tuple(map(int, input().split())) for _ in range(n)]
mp = {tuple(p): i for i, p in enumerate(ps)}

# ベクトルp0p1に対する点p2の位置（反時計回り, もしくは直線上ならTrue, 時計回りならFalse）を返す。
def ccw(p0, p1, p2):
    return (p1[0] - p0[0]) * (p2[1] - p0[1]) - (p1[1] - p0[1]) * (p2[0] - p0[0]) >= 0   # (ベクトルp0p1とベクトルp0p2の外積) >= 0

# 凸包を求める。psは点(x, y)の集合。
def convex_hull(ps):
    upper = []
    lower = []
    ps.sort()
    for p in ps:
        while len(lower) > 1 and ccw(lower[-2], lower[-1], p):
            lower.pop()
        lower.append(p)

    for p in ps[::-1]:
        while len(upper) > 1 and ccw(upper[-2], upper[-1], p):
            upper.pop()
        upper.append(p)
    return lower[:-1] + upper[:-1]

ans = [0] * n
ch = convex_hull(ps)
ch += [ch[0]]
ch += [ch[1]]

for pre, now, next in zip(ch, ch[1:], ch[2:]):
    x0 = now[0] - pre[0]
    y0 = now[1] - pre[1]
    x1 = next[0] - now[0]
    y1 = next[1] - now[1]
    ans[mp[tuple(now)]] = math.atan2(x1*y0 - x0*y1, x0*x1 + y0*y1) / (2 * math.pi)  # atan2(外積, 内積), 外積: |u||v|sinθ, 内積: |u||v|cosθ

for a in ans:
    print(a)

Measured memory_bytes: 3316
import math
A, B = map(int, input().split())
result = 'No'
for i in range(1, 1500):
    eight = math.floor(i * 0.08)
    ten = math.floor(i * 0.10)
    if eight == A and ten == B:
        print(i)
        result = 'Yes'
        break
if result == 'No':
    print(-1)

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

using namespace std;
typedef long long ll;
#define rep(i,j,n) for (ll i = j; i < (n); i++)
#define CLR(mat,f) memset(mat, f, sizeof(mat))
#define IN(a, b, x) (a<=x&&x<b)
#define out(ans) cout << ans << endl
typedef pair<ll,ll>P;
const ll mod=1e9+7;
const int INF = 1000000;
const double PI=3.14159265359;

int main(){

  ll n;cin>>n;
  ll l[2*n];rep(i,0,2*n)cin>>l[i];
  sort(l,l+2*n);
  // reverse(l,l+2*n);
  ll ans=0;
  rep(i,0,n)ans+=l[2*i];

  out(ans);




  return 0;
}


Measured memory_bytes: 256
<?php

define('MOD', 1000000007);

class Com
{
    protected $fact;
    protected $fact_inv;

    public function __construct()
    {
    }

    public function com_init($n)
    {
        $fact[0] = $fact[1] = 1;
        for ($i = 2; $i <= $n; $i++) {
            $fact[$i] = $fact[$i - 1] * $i % MOD;
        }
        $fact_inv[$n] = $this->power_mod($fact[$n], MOD - 2);
        for ($i = $n - 1; $i >= 0; $i--) {
            $fact_inv[$i] = $fact_inv[$i + 1] * ($i + 1) % MOD;
        }
        $this->fact = $fact;
        $this->fact_inv = $fact_inv;
    }

    public function com($n, $k)
    {
        if ($n < $k) {
            return 0;
        }
        if ($n < 0 || $k < 0) {
            return 0;
        }
        return ($this->fact[$n] * $this->fact_inv[$k]) % MOD * $this->fact_inv[$n - $k] % MOD;
    }

    public function power_mod($a, $b)
    {
        $res = 1;
        while ($b > 0) {
            if ($b & 1) {
                $res = $res * $a % MOD;
            }
            $a = $a * $a % MOD;
            $b >>= 1;
        }
        return $res;
    }
}

fscanf(STDIN, "%d %d %d %d", $h, $w, $a, $b);

$c = new Com();
$c->com_init($h + $w);

$loop = $h - $a;
$w_vec = $w - $b - 1;
$total = 0;
for ($i = 0; $i < $loop; $i++) {
    $total += $c->com($b - 1 + $i, $b - 1) * $c->com($w_vec + ($h - $i - 1), $w_vec) % MOD;
}
echo $total % MOD;

Measured memory_bytes: 61684
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0;i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef vector<int> V;
typedef pair<int,int> P;
typedef vector<vector<int>> Graph;

int main() {
    int n,k;
    cin >> n >> k;
    vector<int> p(n);
    rep(i,n){
        cin >> p[i];
    }
    sort(ALL(p));
    ll ans = 0;
    rep(i,k){
        ans += p[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 3632
#include<iostream>

using namespace std;

int main(void){
  int N;
  cin >> N;
  
  if(N % 10 == 3){
    cout << "bon" << endl;
  }else if(N % 10 == 0 || N % 10 == 1 || N % 10 == 6 || N % 10 == 8){
    cout << "pon" << endl;
  }else{
    cout << "hon" << endl;
  }
  return 0;
}

Measured memory_bytes: 3584
#include <cmath>
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
const int inf = 1012345678;
int main() {
	int N;
	cin >> N;
	vector<int> A(N);
	for (int i = 0; i < N; ++i) {
		cin >> A[i];
		A[i] -= i;
	}
	sort(A.begin(), A.end());
	int mid = A[N / 2];
	long long ans = 0;
	for (int i = 0; i < N; ++i) {
		ans += abs(A[i] - mid);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
#define FORR(I,A,B) for(ll I = ((B)-1); I >= (A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;else return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=1e18+7;
const ll MOD=1e9+7;
#define pri(a) cout << (a) << endl

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll a;
	cin >> a;
	cout << 48 - a << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep_inv(i, n, m) for(int i = (int)(n); i > (int)(m); i--)
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vl>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;

int main(){
  string S, T;
  cin >> S >> T;

  ll N = S.size();
  ll ans = 0;

  rep(i, N)
    ans += (S[i] != T[i]) ? 1 : 0;

  cout << ans << "\n";
  
  return 0;
}


Measured memory_bytes: 3820
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <cstdlib> 
#include <string.h>
#include <vector>
#include <cstdio>
#include <iomanip>
#include <stack>
#include <set>
#include <map>
#include <list>
#include <ctime>
#include <algorithm>
#include <cmath>
#define PI 3.1415926535897932384626433832795l
#define IOS ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define deci(n) cout<<fixed<<setprecision(n);
#define F first
#define S second
#define mk make_pair
#define pb push_back
#define ALPHA 27
#define ll long long int
#define ld long double
#define mmset(arr, n) memset(arr, n, sizeof arr)
#define debug(x) cerr << '#' << ' ' << x << '\n'
#define len(s) s.length()
#define ForA(i,a,b) for(int i = a; i < b; i++)
#define ForA1(i,a,b) for(int i = b - 1; i >= a; i--)
#define ForB1(i,a,b) for(int i = b; i > a; i--)
#define ForB(i,a,b) for(int i = a; i <= b; i++)
#define INT_SIZE 18 
#define maxn 200010

using namespace std;

const ll INF = (ll)(8e18);
const ll MOD = 1000000007;
const ll Maxn = 1000000000000;

ll h[maxn], a[maxn], dp[maxn], segment[maxn + maxn + maxn], A[maxn];

void build(ll node, ll l, ll r)
{
    if(l == r){
        segment[node] = a[l];
        return;
    }
    
    ll mid = (l + r) >> 1;
    build(2*node, l, mid);
    build(2*node+1, mid + 1, r);
    segment[node] = max(segment[2*node], segment[2*node + 1]);
}

void update(ll node, ll l, ll r, ll idx, ll val)
{
    if(l == r){
        a[idx] = val;
        segment[node] = val;
        return;
    }

    ll mid = (l + r) / 2;
    if(l <= idx and idx <= mid)
        update(2*node, l, mid, idx, val);
    else 
        update(2*node+1, mid + 1, r, idx, val);
    segment[node] = max(segment[2*node] , segment[2*node + 1]);
}

ll query(ll node, ll start, ll end, ll l, ll r)
{
    if(r < start || end < l) return 0;
    
    if(l <= start && end <= r){
        return segment[node];
    }
    
    ll mid = (start + end) >> 1;
    ll left = query(2*node, start, mid, l, r);
    ll right = query(2*node + 1, mid + 1, end, l, r);
    return max(left, right);
}

int main()
{
    IOS;   
    ll n; cin >> n;
    ForB(i,1,n) cin >> h[i];
    ForB(i,1,n) cin >> A[i];
    build(1, 1, n);
    ForB(i,1,n){
        ll ans = query(1, 1, n, 1, h[i]);
        dp[i] = ans + A[i];
        update(1, 1, n, h[i], dp[i]);
    }
    ll ans = 0;
    ForB(i,1,n) ans = max(ans, dp[i]);
    cout << ans << '\n';
    #ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
    #endif
    return 0 ;
}

Measured memory_bytes: 11264
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define is(a, b) a == b
#define len(v) ll(v.size())

const ll mod=1e9+7;

//vector書き出し
template <class T>
void cout_vec(const vector<T> &vec1){
  rep(i,len(vec1)){
    cout<<vec1[i]<<' ';
  }
  cout<<'\n';
}

typedef pair<int,int> P;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin>>s;
    rep(i,len(s)){
      if(i%2==0){
        cout<<s[i];
      }
    }
    cout<<endl;
}

Measured memory_bytes: 592
#include<iostream>
#include<string.h>

using namespace std;

int n,m,p;
int dx[] = {0,1, 1, 0,-1,-1,-1, 0, 1};
int dy[] = {0,0,-1,-1,-1, 0, 1, 1, 1};
int dz[] = {0,1,-1};
int field[7][7][7];

bool check(int x,int y,int z);

int main(){
	while(1){
		cin >> n >> m >> p;
		if(n == 0) break;
		memset(field,-1,sizeof(field));
		
		bool player = 0;
		int winner = -1;
		int turn = 0;
		for(int i = 0;i < p;i++){
			int tx,ty,tz;
			cin >> tx >> ty;
			tx--;
			ty--;
			for(int j = 0;j < n;j++){
				if(field[tx][ty][j] == -1){
					field[tx][ty][j] = player;
					tz = j;
					break;
				}
			}
			if(winner == -1){
				for(int a = 0;a < n;a++){
					for(int b = 0;b < n;b++){
						for(int c = 0;c < n;c++){
							if(field[a][b][c] != -1 && check(a,b,c) && winner == -1){
								winner = player;
								turn = i + 1;
							}
						}
					}
				}
			}
			player = !player;
		}
		if(winner == -1){
			cout << "Draw" << endl;
		}else if(winner == 0){
			cout << "Black " << turn << endl;
		}else{
			cout << "White " << turn << endl;
		}
	}

	return 0;
}

bool check(int x,int y,int z){
	bool ps = field[x][y][z];
	for(int i = 0;i < 3;i++){
		for(int j = 0;j < 9;j++){
			if(i == 0 && j == 0){
				
			}else{
				int nx = x;
				int ny = y;
				int nz = z;
				for(int k = 1;k < m;k++){
					nx += dx[j];
					ny += dy[j];
					nz += dz[i];
					if(0 <= nx && nx < n && 0 <= ny && ny < n && 0 <= nz && nz < n){
						if(ps != field[nx][ny][nz]){
							break;
						}
					}else{
						break;
					}
					if(k == m-1){
						return true;
					}
				}
			}
		}
	}
	return false;
}


Measured memory_bytes: 3068
import java.util.*;
public class Main{
    public static void main(String[] args){
	new Main().run();
    }
    Scanner sc = new Scanner(System.in);

    int[][] points;
    int[] sum, unique;

    void run(){
	int n = sc.nextInt();
	points = new int[n][3];
	sum = new int[n];
	unique = new int[201];
	int i=0;
	int p=0;
	for(p=0; p<n; p++){
	    for(i=0; i<3; i++){
		points[p][i] = sc.nextInt();
		//System.out.print(points[p][i]+" ");	    
	    }
	    //System.out.println();
	}
	  
	i=0;
	while(i<3){
	    for(p=0; p<n; p++){
		unique[points[p][i]]++;
	    }
	    for(p=0; p<n; p++){
		if(unique[points[p][i]]==1)
		    sum[p] += points[p][i];
		//System.out.println("*"+sum[i]);
		unique[points[p][i]] = 0;
	    }
	    i++;
	}
	for(i=0; i<sum.length; i++){
	    System.out.println(sum[i]);
	}	
    }
}

Measured memory_bytes: 20672
#include <bits/stdc++.h>
using namespace std;
int main() {
	string str, str1 = "CODEFESTIVAL2016";
	int ans = 0;
	cin >> str;
	for(int i = 0; i < str.length(); i++) {
		if(str[i] != str1[i]) ans++;
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep1(i,n) for(int i=1; i<=(n); ++i)
#define repi(i,a,b) for(int i=a; i<=(b); ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define pb push_back
#define mp make_pair
#define sz(v) (int)v.size()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
using ll = long long;
using namespace std;
struct aaa{aaa(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);};}aaaaaaa;
int MOD = 1e9 + 7;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return (a*b)/gcd(a,b);}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

ll X,Y;
int main(){
    cin >> X >> Y;
    ll ct = 0;
    while(X <= Y){
        ct++;
        X = X*2;
    }
    cout << ct << endl;
    
}

Measured memory_bytes: 256
N = [int(c) for c in input()]
dp = 0,1
for i in range(len(N)):
  a = min(dp[0]+N[i], dp[1]+10-N[i])
  b = min(dp[0]+N[i]+1, dp[1]+10-N[i]-1)
  dp = a,b
print(dp[0])


Measured memory_bytes: 13636
n = int(input())
lis = list(map(int,input().split()))
now = []
key = 0
cat = [0 for i in range(101)]
for i in range(n):
  if lis[i] > 0:
    now.append(lis[i])
    cat[lis[i]] += 1
    if cat[lis[i]] > 1:
      print(i+1)
      key = 1
      break
  else:
    try:
      num = now.pop(-1)
      cat[num] -= 1
      if lis[i]*(-1) != num:
        print(i+1)
        key = 1
        break
    except:
      print(i+1)
      key = 1
      break
if key == 0:print("OK")


Measured memory_bytes: 5620
import sys
input = sys.stdin.readline
import re
def print_ans(S):
    """Test Case
    >>> print_ans("0011")
    4
    >>> print_ans("11011010001011")
    12
    >>> print_ans("0")
    0
    """
    flg = True
    ans = 0
    # while flg:
    #     tmp = re.sub(r"01|10", "", S)
    #     if len(tmp) == len(S):
    #         flg = False
    #         break
    #     else:
    #         ans += len(S) - len(tmp)
    #         S = tmp
    # print(ans)
    list_0 = []
    list_1 = []
    for s in S:
        if s =="0":
            list_0.append(s)
        else:
            list_1.append(s)
    print(min(len(list_0), len(list_1)) * 2)
        


if __name__ == '__main__':
    S = input().rstrip()
    print_ans(S)


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

#define M 1000003
#define L 14
#define NIL -1

char H[M][L]; /* Hash Table */

int getChar(char);
/* convert a string into an integer value */
long long getKey(char []);
int h1(int);
int h2(int);
int find(char []);
int insert(char []);

int main(){
    int i, n, h;
    char str[L], com[9];

    for ( i = 0; i < M; i++ ) 
    H[i][0] = '\0';
    
    scanf("%d", &n);
    
    for ( i = 0; i < n; i++ ){
	scanf("%s %s", com, str);
	
	if ( com[0] == 'i' ){
	    insert(str);
	} 
    
    else {
	    if (find(str) != NIL){
		printf("yes\n");
	    }

        else {
		printf("no\n");
	    }
	}

    }

    return 0;
}

int getChar(char ch){
  if ( ch == 'A') return 1;
  else if ( ch == 'C') return 2;
  else if ( ch == 'G') return 3;
  else if ( ch == 'T') return 4;
}

/* convert a string into an integer value */
long long getKey(char str[]){
  long long sum = 0, p = 1, i;
  for ( i = 0; i < strlen(str); i++ ){
    sum += p*(getChar(str[i]));
    p *= 5;
  }
  return sum;
}

int h1(int key){
     return key % M; }

int h2(int key){
     return 1 + (key % (M - 1)); }

int find(char str[]){
int i,j;
long long key;

key = getKey(str);
i = 0;

while (1){
    j = (h1(key) + i * h2(key)) % M;

    if(strcmp(H[j],str) == 0)
    return 1;

    else if (strlen(H[j]) == 0)
    return NIL;

    else
        i = i + 1;
}

}

int insert(char str[]){
int i,j;
long long key;

key = getKey(str);

i = 0;
while (1){
    j = (h1(key) + i * h2(key)) % M;

    if (strcmp(H[j],str) == 0){
        return 1;
    }

else if (strlen(H[j]) == 0){
    strcpy(H[j],str);
    return 0;
}
    else
         i = i + 1;
}

}



Measured memory_bytes: 15420
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const int64_t LINF=8931145141919364364,LMOD=998244353;
// const int dy[]={0,-1,0,1,1,-1,-1,1};
// const int dx[]={1,0,-1,0,1,1,-1,-1};

int main() {
	int64_t n; cin >> n;
	int64_t ans = LINF;
	for(int64_t i = 1; i * i <= n; ++i) {
		int64_t j = n / i;
		if(i * j == n) {
			ans = min(ans, i + j - 2);
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); i++)
#define print(n) cout << n << endl
using namespace std;
using ll = long long;
 
int main()
{
    ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    
    int A, B;
    cin >> A >> B;

    print(((B % A) ? B - A : A + B));

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

#define White 0
#define Gray 1
#define Black 2
#define Max 100
#define Inf 1000000000

int G[Max + 1][Max + 1], n;

void dia() {
  int min, i, j, u;
  int color[Max + 1], dist[Max + 1];

  for (i = 0; i < n; i++) {
    color[i] = White;
    dist[i] = Inf;
  }

  color[0] = Gray;
  dist[0] = 0;

  while (1) {
    min = Inf;
    u = -1;
    for (i = 0; i < n; i++) {
      if (color[i] != Black && min > dist[i]) {
        u = i;
        min = dist[i];
      }
    }

    if (u == -1) break;
    color[u] = Black;

    for (j = 0; j < n; j++) {
      if (color[j] != Black && G[u][j] != Inf) {
        if (dist[j] > dist[u] + G[u][j]) {
          dist[j] = dist[u] + G[u][j];
          color[j] = Gray;
        }
      }
    }
  }
  for (i = 0; i < n; i++) {
    if (dist[i] != Inf) {
      printf("%d %d\n", i, dist[i]);
    } else {
      printf("%d -1\n", i);
    }
  }
}

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

  for (i = 0; i < n; i++) {
    for (j = 0; j < n; j++) {
      G[i][j] = Inf;
    }
  }

  int k, c, u, v;
  for (i = 0; i < n; i++) {
    scanf("%d %d", &u, &k);
    for (j = 0; j < k; j++) {
      scanf("%d %d", &v, &c);
      G[u][v] = c;
    }
  }
  dia();

  return 0;

}



Measured memory_bytes: 2144
//YukiOtake-2018/03/04
//time:12:11
import java.util.Scanner;
class Main{
	public static void main(String args[]){
		Scanner scan = new Scanner(System.in);
		while(true){
      int n=scan.nextInt();
      int p=scan.nextInt();
      // int n=3,p=2;
      if(n==0 && p==0){
        break;
      }
      int[] data=new int[n];
      int i=0,temp=p;
      while(true){
        if(i==n){
          i=0;
        }
        if(temp>0){
          temp--;
          data[i]++;
        }
        else{
          temp=data[i];
          data[i]=0;
        }
        if(data[i]==p){
          break;
        }
        i++;        
      }
      System.out.println(i);
		}
	}
}



Measured memory_bytes: 26640
#include <bits/stdc++.h>
#define REP(a, b) for(int a = 0; a < b; a++)
#define FOR(i, a, b) for(int i = a; i <= b; i++)
#define mp make_pair
#define f first
#define s second
#define pb push_back
using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef pair<ll, ll> LL;
typedef vector<int> vi;

const ll INF = 1e9;
const ll MOD = 1e9 + 7;
const int MAXN = 1e5 + 100;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//shuffle(permutation.begin(), permutation.end(), rng);
//uniform_int_distribution<int>(l, r)(rng);
int n, m;
ii A[MAXN];
int ambil[MAXN];

int main() {
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	ios::sync_with_stdio(0); cin.tie(0);
	cin >> n >> m;
	A[0].f = 1;
	FOR(i, 1, n - 1) A[i].s = 1;
	REP(i, m) {
		int x, y;
		cin >> x >> y;
		x--, y--;
		int red = 1;
		if (A[x].f == 0) red = 0;
		if (red) {
			A[y].f += 1;
		}
		else {
			A[y].s += 1;
		}
		ambil[x]++;
		if (ambil[x] == (A[x].f + A[x].s)) {
			ambil[x] = 0;
			A[x].f = A[x].s = 0;
		}
	}
	int nyak = 0;
	REP(i, n) {
		if (A[i].f) nyak++;
	}
	cout << nyak << '\n';
}

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

using namespace std;
//FILE *fi=freopen("1.txt","r",stdin);
int n;
long long sum;
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        if(i%3!=0&&i%5!=0)
            sum+=i;
    }
    cout<<sum;
    return 0;
}


Measured memory_bytes: 3636
def combination_list(data, r):
    if r == 0 or r > len(data):
        return []

    result = []
    _combination_list(data, r, 0, [], result)
    return result


def _combination_list(data, r, start, progress, result):
    if r == 0:
        result.append(progress)
        return

    for i in range(start, len(data)):
        _combination_list(data, r - 1, i + 1, progress + [data[i]], result)


n = int(input())

names = {"M": 0, "A": 0, "R": 0, "C": 0, "H": 0}
for _ in range(n):
    name = str(input())[0]
    if name in names.keys():
        names[name] += 1

# print(names)

l = list(names.values())
# print(l)

combis = combination_list(l, 3)

count = 0
for combi in combis:
    val = 1
    for i in combi:
        val *= i

    count += val

print(count)


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

char area[100][100];
using P=pair<char,bool>;

int main(){
  int h,w;
  std::cin >> h>>w;

  std::vector<std::vector<P> > area(h,std::vector<P>(w));

  std::vector<bool> iseh(h,true);
  std::vector<bool> isew(w,true);

  rep(i,h)rep(j,w){
    char temp;
    std::cin >> temp;
    area[i][j]=P(temp,1);
  }


  while (1) {
    int nh=h-1,bh=h-1;
    int nw=w-1,bw=w-1;


    rep(i,w){
        if(iseh[i]==false)continue;
        char start='a';
        bool flag=true;
        rep(j,h) {
          if(start!='a' && start!='.')flag=false;;
          if(area[j][i].second==false)continue;
          if(start=='a')start=area[j][i].first;
          else if(start!=area[j][i].first)flag=false;
        }

        if(flag && start=='.'){
          iseh[i]=false;
          rep(j,h)area[j][i].second=false;
          nh-=1;
        }


    }

    rep(i,h){
      if(isew[i]==false)continue;
      char start='a';
      bool flag=true;
      rep(j,w) {
        if(start!='a' && start!='.')flag=false;
        if(area[i][j].second==false){
          continue;
        }
        if(start=='a')start=area[i][j].first;
        else if(start!=area[i][j].first)flag=false;
      }

      if(flag && start=='.'){
        isew[i]=false;
        rep(j,h)area[i][j].second=false;
        nw-=1;
      }

    }



    if(nh==bh && nw==bw)break;

  }



      rep(i,h){
        if(isew[i]){
          rep(j,w){
            if(area[i][j].second==true)std::cout << area[i][j].first;
          }
          std::cout  << '\n';
        }
      }





  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  set<int> s;
  for(int i = 0; i < n; ++i) {
    int a;
    cin >> a;
    s.insert(a);
  }
  cout << ((s.size() == n) ? "YES" : "NO") << endl;
  return 0;
}

Measured memory_bytes: 9600
#include<bits/stdc++.h>
#define int long long

using namespace std;

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

    int a[3];
    cin >> a[0] >> a[1] >> a[2];
    sort(a, a + 3);
    if (a[0] == a[1] && a[1] == 5 && a[2] == 7)
        cout << "YES\n";
    else
        cout << "NO\n";

    return 0;
}


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

public class Main {
	public static void solve() throws IOException {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		for (int i = 0; i < a.length; i++) {
			a[i] = sc.nextInt();
		}
		sc.close();

		ArrayDeque<String> b = new ArrayDeque<String>(n);
		b.add(a[0] + " ");
		if (n % 2 == 0) {
			for (int i = 1; i < (n - 2) / 2 + 1; i++) {
				b.addFirst(a[2 * i - 1] + " ");
				b.addLast(a[2 * i] + " ");
			}
			b.addFirst(a[n - 1] + " ");
		} else {
			for (int i = 1; i < (n - 1) / 2 + 1; i++) {
				b.addFirst(a[2 * i] + " ");
				b.addLast(a[2 * i - 1] + " ");
			}
		}

		for (int i = 0; i < n; i++) {
			System.out.print(b.poll());
		}
		System.out.println();
	}

	public static void main(String[] args) {
		try {
			solve();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}

Measured memory_bytes: 97816
#include <bits/stdc++.h>
 
using namespace std;
 
#define rep(i, n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define pb push_back
#define int long long
 
 
signed main(){

 	int n;
 	cin>>n;

 	bool flag[n+1]={false};

	vector<int> v;

 	for(int i=0;i<n;i++){
 		int tmp;
 		cin>>tmp;
 		v.push_back(tmp);
 	}

 	sort(v.begin(),v.end());

 	// for(int i=0;i<n;i++){
 	// 	cout<<v[i]<<" ";
 	// }cout<<endl;

 	int tmp1=0;
 	int tmp2=0;

 	for(int i=v.size()-1;i>0;i--){
 		if(v[i]==v[i-1]){
 			tmp1=v[i];
 			flag[i]=flag[i-1]=true;
 			break;
 		}
 	}

 	// for(int i=0;i<n;i++){
 	// 	cout<<flag[i]<<" ";
 	// }cout<<endl;

 	for(int i=v.size()-1;i>0;i--){

 		// cout<<v[i]<<" "<<v[i-1]<<endl;

 		if(v[i]==v[i-1]&&flag[i]==0&&flag[i-1]==0){
 			tmp2=v[i];
 			break;
 		}
 	}

 	// cout<<tmp1<<endl;
 	// cout<<tmp2<<endl;

 	cout<<tmp1*tmp2<<endl;

 // 	for(int i=0;i<n;i++){
 // 		count[a[i]]++;
 // 	}

	// int tmp1=0;
 // 	int tmp2=0;

 // 	// for(int i=0;i<n+1;i++){
 // 	// 	cout<<count[i]<<" ";
 // 	// }cout<<endl;

 // 	for(int i=100000;i>=0;i--){
 // 		if(count[i]>=2){
 // 			count[i]-=2;
 // 			tmp1=i;
 // 			break;
 // 		}
 // 	}

 // 	for(int i=tmp1;i>=0;i--){
 // 		if(count[i]>=2){
 // 			tmp2=i;
 // 			break;
 // 		}
 // 	}

 // 	cout<<tmp1<<endl;
 // 	cout<<tmp2<<endl;

 // 	int ans=tmp1*tmp2;

 // 	cout<<tmp1*tmp2<<endl;

}

Measured memory_bytes: 1528
#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;++i)
#include<string>
using namespace std;
typedef long long ll;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

int main() {
	int a;
	cin >> a;
	if (a == 3 || a == 5 || a == 7)puts("YES");
	else puts("NO");
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iostream>
#include <numeric>
#include <utility>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

int main() {
    string s;
    long k;
    cin >> s >> k;
    size_t first = s.find_first_not_of("1");
    if (first == string::npos) {
        cout << s[0] << endl;
    } else if (k > first) {
        cout << s[first] << endl;
    } else {
        cout << "1" << endl;
    }
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"container/list"
	"fmt"
	"os"
	"strconv"
	"strings"
)

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

func main() {
	var N int
	fmt.Scan(&N)
	l := list.New()
	for i := 0; i < N; i++ {
		sc.Scan()
		s := sc.Text()
		if s == "deleteFirst" {
			e := l.Front()
			l.Remove(e)
		} else if s == "deleteLast" {
			e := l.Back()
			l.Remove(e)
		} else {
			str := strings.Split(s, " ")
			com := str[0]
			key, _ := strconv.Atoi(str[1])
			if com == "insert" {
				l.PushFront(key)
			} else if com == "delete" {
				for e := l.Front(); e != nil; e = e.Next() {
					if e.Value == key {
						l.Remove(e)
					}
				}
			}
		}
	}
	for e := l.Front(); e != nil; e = e.Next() {
		if e.Prev() != nil {
			fmt.Fprint(wtr, " ")
		}
		fmt.Fprint(wtr, e.Value)
	}
	fmt.Fprintln(wtr)
	wtr.Flush()
}



Measured memory_bytes: 89564
#include <bits/stdc++.h>
#define FOR(I,X,Y) for(int (I)=(X);(I)<(Y);(I)++)
#define REP(I,X,Y) for(int (I)=(Y)-1;(I)>=(X);(I)--)
#define ALL(X) (X).begin(),(X).end()
#define INF 1000000007
#define LINF 1000000000000000007
typedef long long ll;
using namespace std;

int main(){
  ll X,Y;
  cin >> X >> Y;
  if(X%Y == 0)cout << -1 << endl;
  else cout << X << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll; 

using namespace std;

int main() {
	int N, K;
	cin >> N >> K;
	vector<int> r;
	vector<int> l;
	int cnt = 0;
	r.push_back(0);
	l.push_back(0);
	for (int i = 0; i < N; i++) {
		int x;
		cin >> x;
		if (x > 0) r.push_back(x);
		else if (x < 0) l.push_back(-1 * x);
		else cnt++;
	}
	sort(l.begin(), l.end());

	if (cnt >= K) {
		cout << 0 << endl;
		return 0;
	}

	K -= cnt;

	ll res = 1e18;
	for (int i = 1; i < r.size(); i++) {
		int li = K - i;
		if ((i > K) || (li >= l.size()) || (li < 0)) {
			continue;
		}

		ll tmp = r[i] + l[li] + min(r[i], l[li]);

		res = min(res, tmp);
	}
	for (int i = 1; i < l.size(); i++) {
		int ri = K - i;
		if ((i > K) || (ri >= r.size()) || (ri < 0)) {
			continue;
		}

		ll tmp = l[i] + r[ri] + min(r[ri], l[i]);
		res = min(res, tmp);
	}

	cout << res << endl;
	return 0;
}


Measured memory_bytes: 1020
//=================================
// Created on: 2018/07/02 20:16:19
//=================================
#pragma GCC optimize("O3")
#pragma GCC target("tune=native")
#pragma GCC target("avx")
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int N;
    cin >> N;
    using P = pair<int, int>;
    vector<P> s(N);
    for (int i = 0, H, W; i < N; i++) { cin >> H >> W, s[i] = {H, W}; }
    vector<vector<int>> f(4, vector<int>(4, 0));
    map<char, int> mp;
    mp['R'] = 1, mp['G'] = 2, mp['B'] = 3;
    for (int i = 0; i < 4; i++) {
        string s;
        cin >> s;
        for (int j = 0; j < 4; j++) { f[i][j] = mp[s[j]]; }
    }
    vector<int> memo(1 << 16, -1);
    auto dfs = [&](auto&& self, const int hash) -> int {
        if (hash == 0) { return 0; }
        if (memo[hash] != -1) { return memo[hash]; }
        int ans = 30;
        for (int i = 0; i < N; i++) {
            const int H = s[i].first, W = s[i].second;
            for (int h = 1 - H; h < 4; h++) {
                for (int w = 1 - W; w < 4; w++) {
                    const int hinf = max(h, 0), winf = max(w, 0);
                    const int hsup = min(h + H, 4), wsup = min(w + W, 4);
                    int ch = -1;
                    bool ok = true;
                    for (int i = hinf; i < hsup; i++) {
                        for (int j = winf; j < wsup; j++) {
                            if (hash & (1 << (4 * i + j))) {
                                if (ch != -1 and ch != f[i][j]) { ok = false; }
                                ch = f[i][j];
                            }
                        }
                    }
                    if (not ok or ch == -1) { continue; }
                    int h = hash;
                    for (int i = hinf; i < hsup; i++) {
                        for (int j = winf; j < wsup; j++) { h &= ~(1 << (4 * i + j)); }
                    }
                    const int sub = self(self, h) + 1;
                    ans = min(ans, sub);
                }
            }
        }
        return memo[hash] = ans;
    };
    const int ans = dfs(dfs, (1 << 16) - 1);
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3200
import sys
sys.setrecursionlimit(10**6)
def f(x):
    if flg[x]:
        flg[x] = 0
        p = 0
        for y in glaph[x]:
            p = max(p,f(y)+1)
        dp[x] = p
    return dp[x]
n,m = map(int,input().split())
flg = [1]*(n+1)
dp = [0]*(n+1)
glaph = [[] for i in range(n+1)]
for _ in range(m):
    x,y = map(int,input().split())
    glaph[x].append(y)
ans = 0
for i in range(1,n+1):
    ans = max(ans,f(i))
print(ans)


Measured memory_bytes: 61948
import java.util.Scanner;

public class Main {

	static int N=0;
	static int a=0;
	static int b=0;
	static int c = 0;
	static String P;
	static String Q;
	public static void main(String[] args) {
	    Scanner scanner = new Scanner(System.in);

	    N = Integer.parseInt(scanner.next());
	    StringBuilder p = new StringBuilder();
	    StringBuilder q = new StringBuilder();
	    
	    for (int i=0; i<N; i++) {
	    	p.append(Integer.parseInt(scanner.next()));
	    }
	    P=p.toString();
	    for (int i=0; i<N; i++) {
	    	q.append(Integer.parseInt(scanner.next()));
	    }
	    Q=q.toString();
        f("");
        System.out.print(Math.abs(a - b));
	}
	
	public static void f(String s) {
		if (s.length() == N) {
			c++;
		    if (s.equals(P)) {
			    a = c;
		    }
		    if (s.equals(Q)) {
			    b = c;
	    	}
		    return;
		}
		for (int i = 1; i <= N; i++) {
		    if (!s.contains(String.valueOf(i))) {
		        f(s + String.valueOf(i));
		    }
		}
	}
}


Measured memory_bytes: 57780
#include <stdio.h>
#define MIN(x,y) ((x) < (y) ? (x) : (y))
#define INF 1000000000
int A[1001];
int C[1001];
unsigned long long dp[5000];

int main() {
    int N, M, Nc;
    scanf(" %d %d", &N, &M);
    Nc = 1<<N;
    for (int i = 1; i <= M; ++i) {
        int b;
        scanf(" %d %d", A+i, &b);
        for (int j = 1; j <= b; ++j) {
            int c;
            scanf(" %d", &c);
            C[i] |= 1 << (c - 1);
        }
    }
    for (int j = 0; j < Nc; ++j) {
        dp[j] = INF;
    }
    dp[0] = 0;
    for (int i = 1; i <= M; ++i) {
        for (int j = 0; j < Nc; ++j) {
            dp[j|C[i]] = MIN(dp[j|C[i]], A[i]+dp[j]);
        }
    }
    if (dp[Nc-1] >= INF) {
        dp[Nc-1] = -1;
    }
    printf("%d\n", dp[Nc-1]);
    return 0;
}

Measured memory_bytes: 256
n = int(input())
s = list(input().rstrip())

left_cur = 0
right_cur = n - 1
ans = 0
flag = False
while(left_cur < right_cur and left_cur < n - 1 and right_cur > 0):
    while(s[left_cur] == 'R'):
        left_cur += 1
        if (left_cur == n - 1):
            flag = True
            break
    while(s[right_cur] == 'W'):
        right_cur -= 1
        if (right_cur == 0):
            flag = True
            break
    if(left_cur > right_cur):
        flag = True
    if(flag):
        break
    ans += 1
    left_cur += 1
    right_cur -= 1

print(ans)


Measured memory_bytes: 10800
def main():
    N, M = map(int, input().split())
    Lmax  = 0
    Rmin  = N+1
    for i in range(M):
        L, R = map(int, input().split())
        if L > Lmax:
            Lmax = L
        if R < Rmin:
            Rmin = R
    if Rmin < Lmax:
        print(0)
    else:
        print(Rmin - Lmax + 1)
main()

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

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

#define pb push_back
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)
#define mod 1e9+7

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

int main() {
  int n, f;
  cin >> n >> f;
  map<string, map<string, int> > mp;
  int c = 0;
  for(int i = 0; i < n; i++) {
    int m;
    cin >> m;
    string item[m];
    for(int j = 0; j < m; j++) cin >> item[j];
    sort(item, item + m);
    for(int j = 0; j < m; j++) {
      for(int k = j + 1; k < m; k++) {
        mp[item[j]][item[k]]++;
        if(mp[item[j]][item[k]] == f) c++;
      }
    }
  }
  cout << c << endl;
  for(map<string, map<string, int> >::iterator it = mp.begin(); it != mp.end(); it++) {
    map<string, int> smp = it->second;
    for(map<string, int>::iterator i = smp.begin(); i != smp.end(); i++) {
      if(i->second >= f) {
        cout << it->first << " " << i->first << endl;
      }
    }
  }
}

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


int main() {
    string S;
    cin>>S;
    int a;
    int mn =1000;
    rep(i,S.size()-2){
        a=(S[i]-'0')*100+(S[i+1]-'0')*10+(S[i+2]-'0');
        mn=min(mn,abs(a-753));
    }
    cout<<mn <<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int sum = 0;
		for (int i = a; i <= b; i++)
			if (c % i == 0)
				sum++;
			System.out.println(sum);
			sc.close();
	}
}


Measured memory_bytes: 26400
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.StringTokenizer;

public class Main {
    static PrintWriter out;
    static CF_Reader in;

    public static void main(String[] args) throws IOException {
        out = new PrintWriter(new OutputStreamWriter(System.out));
        in = new CF_Reader();

        HashMap<Integer, String> cache = new HashMap<>();
        for (int n: new int[]{2,4,5,7,9}) cache.put(n, "hon");
        for (int n: new int[]{0,1,6,8}) cache.put(n, "pon");
        cache.put(3, "bon");
        out.println(cache.get(in.intNext() % 10));

        out.close();
    }

    static class CF_Reader {
        BufferedReader br;
        StringTokenizer st;

        public CF_Reader() throws IOException {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() throws IOException {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine().trim());
            return st.nextToken();
        }

        long longNext() throws IOException {
            return Long.parseLong(next());
        }

        int intNext() throws IOException {
            return Integer.parseInt(next());
        }

        double doubleNext() throws IOException {
            return Double.parseDouble(next());
        }

        char charNext() throws IOException {
            return next().charAt(0);
        }

        public int[] nextIntArray(final int n) throws IOException {
            final int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = intNext();
            return a;
        }

        public long[] nextLongArray(final int n) throws IOException {
            final long[] a = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = longNext();
            return a;
        }

        String line() throws IOException {
            return br.readLine().trim();
        }
    }
}


Measured memory_bytes: 32776
/*
csc -debug C.cs && mono --debug C.exe <<< "3
5 6 3 8
5 100 8"
*/

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Reflection;

public class HelloWorld {
    public static void SolveCodeForces() {
        var N = cin.NextInt();
        var A = cin.LongArray();
        var B = cin.LongArray();

        var total = 0L;
        var prev = 0L;
        for (var i = 0; i < B.Length; i++) {
            var a = A[i] - prev;
            var b = B[i];
            var c = Math.Min(a, b);
            total += c;
            b -= c;
            var d = Math.Min(A[i + 1], b);
            total += d;
            prev = d;
        }

        System.Console.WriteLine(total);
    }

    static Scanner cin = new Scanner();
    static StringBuilder cout = new StringBuilder();

    static public void Main () {
        SolveCodeForces();
        // IncreaseStack(SolveCodeForces);
        // System.Console.Write(cout.ToString());
    }

    public static void IncreaseStack(ThreadStart action, int stackSize = 128000000)
    {
        var thread = new Thread(action, stackSize);
        thread.Start();
        thread.Join();
    }
}

public static class Helpers {
    public static string Join<T>(this IEnumerable<T> arr, string sep = " ") {
        return string.Join(sep, arr);
    }

    public static void Swap<T>(ref T a, ref T b) {
        var tmp = a;
        a = b;
        b = tmp;
    }

    public static T[] CreateArray<T>(int length, Func<int, T> itemCreate) {
        var result = new T[length];
        for (var i = 0; i < result.Length; i++)
            result[i] = itemCreate(i);
        return result;
    }
}

public class Scanner
{
    private string[] line = new string[0];
    private int index = 0;

    public string Next() {
        if (line.Length <= index) {
            line = Console.ReadLine().Split(' ');
            index = 0;
        }
        var res = line[index];
        index++;
        return res;
    }

    public int NextInt() {
        return int.Parse(Next());
    }

    public long NextLong() {
        return long.Parse(Next());
    }

    public ulong NextUlong() {
        return ulong.Parse(Next());
    }

    public string[] Array() {
        line = Console.ReadLine().Split(' ');
        index = line.Length;
        return line;
    }

    public int[] IntArray(int emptyPrefixLen = 0) {
        var array = Array();
        var result = new int[emptyPrefixLen + array.Length];
        for (int i = 0; i < array.Length; i++)
            result[emptyPrefixLen + i] = int.Parse(array[i]);
        return result;
    }

    public long[] LongArray() {
        var array = Array();
        var result = new long[array.Length];
        for (int i = 0; i < array.Length; i++)
            result[i] = long.Parse(array[i]);
        return result;
    }

    public ulong[] UlongArray() {
        var array = Array();
        var result = new ulong[array.Length];
        for (int i = 0; i < array.Length; i++)
            result[i] = ulong.Parse(array[i]);
        return result;
    }
}

Measured memory_bytes: 36452