akhauriyash/Code-Regression huggingface dataset:
#!/usr/bin/env python3
import sys, math, fractions, itertools

l = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]

def solve(N: int, M: int, A: "List[int]"):
    dp = [-1] * (N+10) # 初期化
    dp[0] = 0 # 初期化
    for i in range(N-1): # 各桁について考える
        for s in A: # 各使える数字をみる
            if dp[i] == -1 and i!=0: # 条件を満たすように作れない場合、continue
                continue
            if dp[i + l[s]] < dp[i]*10+s:
                dp[i + l[s]] = dp[i]*10+s
    print(dp[N])
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    A = [ int(next(tokens)) for _ in range(M) ]  # type: "List[int]"
    solve(N, M, A)

if __name__ == '__main__':
    main()


Measured memory_bytes: 16692
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;

int main() {
    int n;
    cin >> n;
    int minuscounter = 0;
    bool zero = false;
    ll c[n];
    ll sum = 0, ans;

    rep(i, n) {
        ll a;
        cin >> a;
        if(a == 0) {
            zero = true;
        }
        else if(a < 0) {
                minuscounter++;
                minuscounter %= 2;
            }

        sum += abs(a);
        c[i] = abs(a);
    }

    sort(c, c+n);

    if(zero || minuscounter == 0) {
        ans = sum;
    }
    else {
        ans = sum - 2*c[0];
    }

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

Measured memory_bytes: 1024
<?php
define("MOD", 10**9+7);
fscanf(STDIN, "%d%d", $N, $M);

for($j = 2; $j <= $M; $j++){
    if($M%$j == 0){
        @$map[$j]++;
        $M/=$j;
        $j--;
    }
}
$product = 1;
foreach($map as $prime => $count){
    $product *= nCm($count + $N - 1, $count);
    $product %= MOD;
}
echo $product;

//足し算
function addm($a, $b){
    return ($a + $b) % MOD;
}
//引き算
function subm($a, $b){
    return ($a + MOD - $b) % MOD;
}
//掛け算
function mulm($a, $b){
    return ($a * $b) % MOD;
}
//割り算
function divm($a, $b){
    return mulm($a, powerm($b, MOD - 2));
}
//累乗
function powerm($a, $b){
    if($b == 0)return 1;
    if($b & 1)return (powerm($a, $b>>1)**2 % MOD) * $a % MOD;
    return powerm($a, $b>>1)**2 % MOD;
}
//階乗
function factorialm($a){
    if($a == 0)return 1;
    return factorialm($a - 1) * $a % MOD;
}
//順列
function nPm($n, $m){
    if($m == 0)return 1;
    return nPm($n, $m - 1) * ($n - $m + 1) % MOD;
}
//組み合わせ
function nCm($n, $m){
    static $memo;
    if(!isset($memo[$n][$m])){
        $m = min($m, $n-$m);
        $memo[$n][$m] = divm(nPm($n, $m), factorialm($m));
    }
    return $memo[$n][$m];
}

Measured memory_bytes: 4728
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <complex>
#include <ctime>
#include <cstdlib>

using namespace std;

inline int to_int(string s) {int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string to_str(T x) {ostringstream sout; sout << x; return sout.str();}

typedef long long ll;

int main()
{
	int field[10][10], used[10];
	bool judge[10][10];

	int num;
	cin >> num;
	while(num--)
	{
		memset(judge, false, sizeof(judge));

		for(int i = 0; i < 9; i++)
		{
			for(int j = 0; j< 9; j++)
			{
				cin >> field[i][j];
			}
		}
		for(int i = 0; i < 9; i++)
		{
			memset(used, 0, sizeof(used));
			for(int j = 0; j < 9; j++)
			{
				used[field[i][j]]++;
			}
			for(int j = 1; j <=9; j++)
			{
				if(used[j] >= 2)
				{
					for(int k = 0; k < 9; k++)
					{
						if(field[i][k] == j)
						{
							judge[i][k] = true;
						}
					}
				}
			}
			memset(used, 0, sizeof(used));
			for(int j = 0; j < 9; j++)
			{
				used[field[j][i]]++;
			}
			for(int j = 1; j<= 9; j++)
			{
				//printf("%d%s",used[j] ,(j == 9)?"\n":" ");
				if(used[j] >= 2)
				{
					for(int k = 0; k < 9; k++)
					{
						if(field[k][i] == j)
						{
							judge[k][i] = true;
						}
					}
				}
			}
		}

		for(int l = 0; l < 9; l+=3)
		{
			for(int m = 0; m < 9; m+=3)
			{
				memset(used, false, sizeof(used));
				for(int i = 0; i < 3; i++)
				{
					for(int j = 0; j < 3; j++)
					{
						used[field[i+l][j+m]]++;
					}
				}

				for(int n = 1; n <=9; n++)
				{
					if(used[n] >= 2)
					{
						for(int i = 0; i < 3; i++)
						{
							for(int j = 0; j < 3; j++)
							{
								if(field[i+l][j+m] == n)
								{
									judge[i+l][j+m] = true;
								}
							}
						}
					}
				}
			}
		}

		for(int i = 0; i < 9; i++)
		{
			for(int j = 0; j < 9; j++)
			{
				printf("%s%d",(judge[i][j])?"*":" " ,field[i][j]);
			}
			puts("");
		}
		if(num != 0)
		{
			puts("");
		}
	}
}

Measured memory_bytes: 1148
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <map>

using namespace std;

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

	string s;
	vector<int> alpha(26, 0);
	for (int i = 0; i < h; i++) {
		cin >> s;
		for (auto c : s) {
			alpha[c - 'a']++;
		}
	}

	vector<vector<bool>> board(h, vector<bool>(w, false));
	int n4 = (h / 2) * (w / 2);
	int n1 = (h % 2) * (w % 2);
	int n2 = (h * w - n4 * 4 - n1) / 2;

	for (int i = 0; i < alpha.size(); i++) {
		while (alpha[i] >= 4 && n4 > 0) {
			alpha[i] -= 4;
			n4--;
		}
	}
	for (int i = 0; i < alpha.size(); i++) {
		while (alpha[i] >= 2 && n2 > 0) {
			alpha[i] -= 2;
			n2--;
		}
	}
	for (int i = 0; i < alpha.size(); i++) {
		while (alpha[i] >= 1 && n1 > 0) {
			alpha[i]--;
			n1--;
		}
	}

	bool ok = true;
	for (auto e : alpha) {
		if (e > 0) {
			ok = false;
		}
	}

	cout << (ok ? "Yes" : "No") << endl;
	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int n,a[(1<<18)];
P bs[(1<<18)][2];
int ans[(1<<18)];
int main(){
	cin>>n;
	rep(i,1<<n){
		cin>>a[i];
		bs[i][0] = mp(a[i],i);
		bs[i][1] = mp(-INF,-INF);
	}
	for(int i=1;i<(1<<n);i++){
		vector<P>vec;
		vec.pb(bs[i][0]);
		vec.pb(bs[i][1]);
		for(int j=0;j<n;j++){
			if(((i>>j)&1)){
				vec.pb(bs[i-(1<<j)][0]);
				vec.pb(bs[i-(1<<j)][1]);
			}
		}
		SORT(vec);
		ERASE(vec);
		reverse(vec.begin(),vec.end());
		if(vec.size() >= 1){
			bs[i][0] = vec[0];
		}
		else{
			bs[i][0] = mp(-INF,-INF);
		}
		if(vec.size() >= 2){
			bs[i][1] = vec[1];
		}
		else{
			bs[i][1] = mp(-INF,-INF);
		}
		ans[i] = bs[i][0].fi+bs[i][1].fi;
	}
	for(int i=1;i<(1<<n);i++) ans[i] = max(ans[i],ans[i-1]);
	for(int i=1;i<(1<<n);i++) cout<<ans[i]<<endl;
}

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

string s;
int t;
int p=0;

const int INF=1000001;

int read_digit(){
	int res=0;
	while(isdigit(s[p])){
		res*=10;
		res+=s[p++]-'0';
	}
	return res;
}

string calc(){
	string res;
	while(p<s.size()){
		if(isdigit(s[p])){
			int mul=read_digit();
			string get;
			if(s[p]=='('){
				p++;
				get=calc();
			}
			else{
				get=s[p++];
			}
			for(int i=0;i<mul;i++){
				for(int j=0;j<get.size();j++){
					if(res.size()>t) break;
					res+=get[j];
				}
				if(res.size()>t) break;
			}
		}
		else if(isupper(s[p])){
			if(res.size()<=t)
				res+=s[p];
			p++;
		}
		else{
			p++;
			return res;
		}
	}
	return res;
}

int main()
{
	while(cin>>s>>t && s!="0"){
		p=0;
		string get=calc();
		if(get.size()<t+1) cout<<0<<endl;
		else cout<<get[t]<<endl;
	}
}

Measured memory_bytes: 3440
n,m=map(int,input().split())
for i1 in range(1,int(m**0.5)+1):
    if m%i1==0:
        i2=m//i1
        if i1>=n:
            ans=i2
            break
        elif i2==n:
            ans=i1
            break
        elif i2<n:
            ans=pre_i1
            break
        pre_i1=i1
else:
    ans=pre_i1
print(ans)


Measured memory_bytes: 3060
#include <iostream>
using namespace std;
string a;
int main() {
	int i;
	cin>>a;
	for(i=a.size(); i; ) {
		if(i>=5 && a.substr(i-5,5)=="dream") i-=5;
		else if(i>=5 && a.substr(i-5,5)=="erase") i-=5;
		else if(i>=6 && a.substr(i-6,6)=="eraser") i-=6;
		else if(i>=7 && a.substr(i-7,7)=="dreamer") i-=7;
		else break;
	}
	cout<<(i ? "NO":"YES");
	return 0;
}

Measured memory_bytes: 512
S = input()

if S[0] == "A" and S.count("A") == 1 and S.count("C") == 1:
    p = S.find("C")
    b = S.replace("A","").replace("C","")
    if p > 1 and p < len(S) - 1 and b.islower():
        print("AC")
    else:
        print("WA")
else:
    print("WA")


Measured memory_bytes: 3060
#include<stdio.h>
int main(void){
    int n,m;
    int cost[1000],B[1000],C[1000]={0};
    int i,j,k;

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

    for(i=0;i<m;i++){
	for(j=0;j<n;j++){
	    if(cost[j]<=B[i]){
	        C[j]++;
		break;
	    }
	}
    }

    int max=0,ans=0;
    for(j=0;j<n;j++){
	if(C[j]>max){
	    max=C[j];
	    ans=j;
	}
    }

    printf("%d\n",ans+1);

    return 0;
}
   

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

int l,r;
char t[3000];

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

	while(n--){
		string s;
		cin>>s;
		int idx = 1500;
		l = r = 1500;
		for(int i=0;i<s.length();i+=3){
			if(i != 0){
				if(s[i-1] == '>') idx++;
				else idx--;
				l = min(l,idx);
				r = max(r,idx);
			}
			t[idx] = s[i];
		}
		for(int i=l;i<=r;i++){
			cout<<t[i];
		}
		cout<<endl;
	}

	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define FORR(i, n) for(ll i = (ll)n - 1LL; i >= 0LL; i--)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) begin(x), end(x)
using namespace std;
using ll = long long;
constexpr ll Mod = 998244353;
constexpr ll mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;
const double PI = acos(-1);
template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {
    return a < b && (a = b, true);
}
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {
    return a > b && (a = b, true);
}
/*-------------------------------------------*/

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

    int n;
    cin >> n;
    string s;
    int a = 0, b = 0, c = 0, d = 0;

    rep(i, n) {
        cin >> s;
        if(s == "AC") a++;
        if(s == "WA") b++;
        if(s == "TLE") c++;
        if(s == "RE") d++;
    }

    cout << "AC x " << a << endl;
    cout << "WA x " << b << endl;
    cout << "TLE x " << c << endl;
    cout << "RE x " << d << endl;

    return 0;
}

Measured memory_bytes: 3660
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <assert.h>
#include <fstream>

using namespace std;

const long long MOD = 1000000007;

int n;
int cnt[26];

long long ans;

string s;

int main()
{
	cin >> n >> s;
	for (int i = 0;i < n;i++)
		cnt[s[i] - 'a']++;
	ans = 1;
	for (int i = 0;i < 26;i++)
		(ans *= cnt[i] + 1) %= MOD;
	cout << (ans + MOD - 1) % MOD << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <map>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;++i)
#define mod 1000000007

const ll INF=100000;

int main(){
  string s,t;
  cin  >> s >>t;
  string ans="No";
  rep(i,s.size()){
    bool flag=true;
    rep(j,s.size()){
      if(s[(i+j)%s.size()]!=t[j]){
        flag=false;
      }
    }
    if(flag){
      ans="Yes";
      break;
    }
  };
  cout << ans << endl;
}


Measured memory_bytes: 256
import itertools


def count_black(grid):
    num_blacks = 0

    for row in grid:
        for c in row:
            if c == '#':
                num_blacks += 1

    return num_blacks


def deep_copy_grid(grid):
    copy = []

    for row in grid:
        temp = []

        for col in row:
            temp.append(col)

        copy.append(temp)

    return copy


def paint_red(grid, select_rows, select_cols):
    for select_row in select_rows:
        for j in range(len(grid[select_row])):
            grid[select_row][j] = 'r'

    for select_col in select_cols:
        for i in range(len(grid)):
            grid[i][select_col] = 'r'

    return


height, width, k = list(map(int, input().split()))

grid = []

for _ in range(height):
    row = list(input())
    grid.append(row)

num_choices = 0

for i in range(height + 1):
    row_combs = itertools.combinations(range(height), i)

    for row_comb in row_combs:
        for j in range(width + 1):
            col_combs = itertools.combinations(range(width), j)

            for col_comb in col_combs:
                copy = deep_copy_grid(grid)

                paint_red(copy, row_comb, col_comb)

                temp_num_blacks = count_black(copy)

                if temp_num_blacks == k:
                    num_choices += 1

print(num_choices)


Measured memory_bytes: 9128
#include "bits/stdc++.h"
using namespace std;

#define ASC(vec) vec.begin(), vec.end()		// 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend()	// 降順ソート 例:sort(DESC(vec));
#define rep(i, n) for(int i = 0; i < (n); i++)
#define Rep(i, n) for(int i = 1; i < n; i++)

const int mod = 1000000007;
const int inf = (1 << 21);
const long long INF = 1LL << 60;

using ii = pair<int, int>;
using ll = long long;
using vi = vector<int>;
using vd = vector<double>;
using vb = vector<bool>;
using vl = vector<ll>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvb = vector<vector<bool>>;
using vii = vector<pair<int, int>>;

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

ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
ll LCM(ll a, ll b) { return (a * b) / GCD(a, b); }
int round_int(int a, int b) { return (a + (b - 1)) / b; }

constexpr array<int, 9> dx = { 0, 1, 0, -1, -1, 1, 1, -1, 0 };
constexpr array<int, 9> dy = { 1, 0, -1, 0, 1, 1, -1, -1, 0 };

// ──────────────────────────────────────────────────────────────────

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

	vi cad;
	for (int i = 1; i <= c; ++i) {
		if (c % i == 0) cad.push_back(i);
	}

	int ans = 0;
	rep(i, cad.size()) {
		if (a <= cad[i] && cad[i] <= b) ans++;
	}
	cout << ans << endl;
}


Measured memory_bytes: 3148
#0028
import collections
a = list()
for i in range(100):
    try:
        a.append(int(input()))
    except:
        break
x = collections.Counter(a).most_common()[0][1]
z = collections.Counter(a).most_common()[0][0]

l = []

for j in range(len(collections.Counter(a).most_common())):
    y = collections.Counter(a).most_common()[j][1]
    v = collections.Counter(a).most_common()[j][0]
    if x == y:
        l.append(v)
    else:
        break
l.sort()
for k in range(len(l)):
    print(l[k])


Measured memory_bytes: 6004
#include<bits/stdc++.h>
#define two(a) (1<<(a))
#define LINF (1ll<<61)
#define EPS (1e-14)
#define Lshift(a,b) ((a)<<(b))
#define Rshift(a,b) ((a)>>(b))
#define rep(a,b) for(a=0 ; a<b ; a++)
#define xrep(a,b,c) for(a=b ; a<c ; a++)
#define INF (1<<29)
#define sz(a) int(a.size())
#define mset(x) memset(x, 0, sizeof(x))
#define swap(a,b) ( (a^=b) , (b^=a) , (a^=b) )
#define GET(x) (mark[x>>5]>>(x&31)&1)
#define SET(x) (mark[x>>5]|=1<<(x&31))
#define maxL (10000000>>5)+1
#define mod 1000000007
#define vi vector<int>
#define pii pair<int, int>
#define mii map<int, int>
#define si set<int>
#define pb push_back
typedef long long ll;
using namespace std;


int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    int n, k, q;
    cin >> n >> k >> q;
    vector<int> s(n, k - q);
    int i;
    rep(i, q) {
        int v;
        cin >> v;
        s[v-1]++;
    }
    rep(i, n) {
        if (s[i] <= 0) {
            cout << "No" << endl;
        } else {
            cout << "Yes" << endl;
        }
    }
}


Measured memory_bytes: 3668
#include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>
using namespace std;

int main()
{
    int N , fMx = 0 , sMx = 0;
    cin >> N;
    vector<int>V(N);
    vector<int>A(N);

    for (int j = 0; j < N; j++)
    {
        cin >> V[j];
    }
 
    A = V;
    sort(A.begin(), A.end());
    fMx = A[N - 1];
    sMx = A[N - 2];
    for (int j = 0; j < N; j++)
    {
        if (V[j] != fMx) { cout << fMx << endl; }
        else { cout << sMx << endl; }
    }
    return 0;
}



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

int main(){
    int n;
    cin >> n;
    cout << "ABC" << n << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main(){
  string s;
  while(cin >> s){
    int a = 0, b = 0;
    for(int i = 0 ; i < s.size() ; i++ ){
      if(s.substr(i,3) == "JOI") a++;
      else if(s.substr(i,3) == "IOI") b++;
    }
    cout << a << endl << b << endl;
  }
}

Measured memory_bytes: 1212
#include <cmath>
#include <iomanip>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
// #include <bits/stdc++.h>
using namespace std;

void bfs(int i, int color[], vector<int> adj[]) {
  queue<int> que;
  que.push(i);

  while (que.size() > 0) {
    int cur = que.front();
    que.pop();
    for (auto a = adj[cur].begin(); a != adj[cur].end(); a++) {
      if (color[*a] == 0) {
        color[*a] = 1;
        que.push(*a);
      }
    }
  }
}

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

  vector<int> adj[N + 1];

  for (int i = 0; i < M; i++) {
    int x, y, z;
    cin >> x >> y >> z;
    adj[x].push_back(y);
    adj[y].push_back(x);
  }

  int color[N + 1];
  for (int i = 1; i <= N; i++) {
    color[i] = 0;
  }

  int count = 0;
  for (int i = 1; i <= N; i++) {
    if (color[i] == 0) {
      color[i] = 1;
      bfs(i, color, adj);
      count += 1;
    }
  }

  cout << count << endl;

  return 0;
}

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

int main(){
  int v,r,i,j,x;
  scanf("%d",&v);

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

  scanf("%d",&r);
  for(i=0; i<r; i++) {

    scanf("%d",&x);
    int w=v+1,l=-1;

    while(l+1!=w){

      int r=(l+w)/2;
      if(a[r]==x){
	     cnt++;
	     break;
      }
      if(a[r]<x){
      l=r;
      }
      else{
      w=r;
      }
    }
  }
  printf("%d\n",cnt);
  
  return 0;
}



Measured memory_bytes: 2100
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <functional>
#include <array>
#include <map>
#include <queue>
#include <limits.h>
#include <set>
#include <stack>
#include <random>
#include <complex>
#include <unordered_map>
#define rep(i,s,n) for(int i = (s); (n) > i; i++)
#define REP(i,n) rep(i,0,n)
#define RANGE(x,a,b) ((a) <= (x) && (x) <= (b))
#define DUPLE(a,b,c,d) (RANGE(a,c,d) || RANGE(b,c,d) || RANGE(c,a,b) || RANGE(d,a,b))
#define INCLU(a,b,c,d) (RANGE(a,c,d) && (b,c,d))
#define PW(x) ((x)*(x))
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MODU 1000000007
#define bitcheck(a,b)   ((a >> b) & 1)
#define bitset(a,b)      ( a |= (1 << b))
#define bitunset(a,b)    (a &= ~(1 << b))
#define MP(a,b) make_pair((a),(b))
#define Manh(a,b) (abs((a).first-(b).first) + abs((a).second - ((b).second))
#define pritnf printf
#define scnaf scanf
#define itn int
#define PI 3.141592653589
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T &val) {
	std::fill((T*) array, (T*) (array + N), val);
}
pii Dir [] = {
	{ 1,0 },{ 0,1 }
};



signed main() {
	ll a, b,x;

	scanf("%lld %lld %lld", &a, &b, &x);

	
	printf("%lld\n", b/x-a/x + !((bool)(a%x)));
	return 0;
}

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

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

using namespace std;

int main() {
  int a,b,t;
  cin >> a >> b >> t;
  cout << (t/a)*b << endl;
}


Measured memory_bytes: 256
/* ex5_3.c Grid Compression
    dada__              */
#include<stdio.h>
 
int main(void){
    int row, col, i, j;
    scanf("%d %d", &row, &col); //行と列の数の入力
    int judge_row[row], judge_col[col];
    char grid[row][col];
 
    //各マス目の記号の入力
    for(i=0;i<row;i++){
        for(j=0;j<col;j++){
            scanf(" %c", &grid[i][j]);
        }
    }
 
    //各行について，取り除くかの判定
    for(i=0;i<row;i++){
        judge_row[i] = 0;
        for(j=0;j<col;j++){
            if(grid[i][j]=='#'){
                judge_row[i]=1;
                break;
            }
        }
    }
    //各列について，取り除くかの判定
     for(j=0;j<col;j++){
        judge_col[j] = 0;
        for(i=0;i<row;i++){
            if(grid[i][j]=='#'){
                judge_col[j]=1;
                break;
            }
        }
    }
 
    //各判定に基づいた出力
    for(i=0;i<row;i++){
        if(judge_row[i]==1){ //行の判定が1の場合に出力
            for(j=0;j<col;j++){
                if(judge_col[j]==1){//列の判定が1の場合に出力
                    printf("%c", grid[i][j]);
                }
            }
            printf("\n"); //1行出力した段階で改行
        }
    }
    return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<cstdlib>

using namespace std;

int main(){
	int k,s,x,y,z;
	int c = 0;
	
	cin >> k >> s;
	
	for(int i = 0; i <= k; i++){
		for(int j = 0; j <= k; j++){
			if(i + j > s)
				break;
			else if(s-i-j > k)
				continue;
			else
				c ++;
		}
	}
	
	cout << c << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll MOD = 1000000007;
const ld PI = acos(-1);  
const ld EPS = 0.0000000001;

ll gcd(ll a, ll b){
    if(a%b==0) return b;
    return gcd(b, a%b);
}

int main(){
    int n;  cin >> n;
    vector<ll> isPrime(n+1, true);
    isPrime[0]=isPrime[1]=false;
    map<int, int> mp;

    for(int i=2; i<=n; i++){
        if(!isPrime[i]) continue;
        mp[i] += 1;
        for(int j=i+i; j<=n; j+=i)   isPrime[j] = false;
    }

    
    for(int i=2; i<=n; i++){
        if(isPrime[i]) continue;
        int tar = i;
        for(auto x: mp){
            while(tar%x.first==0){
                mp[x.first] += 1; 
                tar /= x.first;
            }
            if(tar==1) break;    
        }
    }
    ll ans=1;
    for(auto x: mp){
        ans *= x.second+1;
        ans %= MOD;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int s, t, n, m;
void chkmax(int &a, int b) {a = a > b ? a : b;}
void chkmin(int &a, int b) {a = a < b ? a : b;}
int read() {
	int x = 0, f = 1; char c = getchar();
	while(!isdigit(c)) {
		if(c == '-') f = -f;
		c = getchar();
	}
	while(isdigit(c)) {
		x = (x << 1) + (x << 3) + c - '0';
		c = getchar();
	}
	return x * f;
}
void write(int x) {
	char c[33] = {0}, tot = 0;
	if(x == 0) {puts("0"); return;}
	while(x) {c[++ tot] = x % 10 + '0'; x /= 10;}
	while(tot) {putchar(c[tot --]);}
	return ;
}
int k, a[10045];
int main() {
	cin >> n >> k;
	for(int i = 1;i <= n;i ++) 
		cin >> a[i];
	sort(a + 1, a + 1 + n);
	n = 0;
	for(int i = 1;i <= k;i ++) 
		n += a[i];
	cout << n;
	return 0;
}


Measured memory_bytes: 3628
'use strict'

function main(s) {

  s = s.split('\n')[0].split(' ').map(n => Number(n));

  const a = s[0];
  const b = s[1];
  const c = s[2];

  const ans = (a <= c && c <= b) ? 'Yes' : 'No';

  console.log(ans);
}

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


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

int main(){
    int n, ans = 0;
    cin >> n;
    if(n % 10 == 0){
        ans = 10;
    }else{
        int dig;
        while(n > 0){
            dig = n % 10;
            ans += dig;
            n /= 10;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
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; }

P c[90005];
ll dp[90005];

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int h, w, d;
    cin >> h >> w >> d;
    vector<vector<int>> a(h, vector<int>(w));
    rep(i,h)rep(j,w){
        cin >> a[i][j];
        c[a[i][j]].first = i;
        c[a[i][j]].second = j;
    }
    for(int i = 1; i <= h*w; ++i){
        if(i+d <= h*w) dp[i+d] = dp[i] + abs(c[i].first - c[i+d].first) + abs(c[i].second - c[i+d].second);
    }
    int q;
    cin >> q;
    rep(i,q){
        int l, r;
        cin >> l >> r;
        ll ans = dp[r] - dp[l];
        cout << ans << endl;
    }
    return 0;
}


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


int main ()
{
   string s,t;cin>>s>>t;
   ll n = s.length();
   ll m = t.length();
   ll dp[n+1][m+1];
   fr(i,n+1)
   {
       fr(j,m+1)
       {
           if(i==0 || j==0){dp[i][j]=0;continue;}
           if(s[i-1]==t[j-1])dp[i][j] = 1 + dp[i-1][j-1];
           else
           {
               dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
           }
           
        }
   }
   string ans = "";
   ll i=n;ll j=m;
   while(i!=0 && j!=0)
   {
       if(dp[i][j] == 1 + dp[i-1][j-1] && s[i-1]==t[j-1]){ans = ans + s[i-1];i--;j--;}
       else
       {
           if(dp[i][j] == dp[i-1][j])i--;
           else j--;
       }
       
   }
   string u="";
   fr(i,ans.length())u=u+ans[ans.length()-1-i];
   cout<<u<<endl;
   return 0;
   
}

Measured memory_bytes: 70656
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    vector <char> m(3);
    for(int i=0;i<3;i++){
        cin >> m[i];
        
    }
    
   if(m[0]==m[1] || m[1]==m[2] || m[0]==m[2]) cout<<"No"<<endl;
   else cout<<"Yes"<<endl;
    
    
 
}


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

int main() {
    int A, B;
    cin >> A >> B;
    for (int i = 1; i <= 10000; i++) {
        int a = i*8/100;
        int b = i*10/100;
        if (a == A && b == B) {
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 256
MOD=10**9+7
N,M=map(int,input().split())
dp=[0]*(N+1)
dp[0]=1
A=set(int(input()) for _ in range(M))
for i in range(1,N+1):
    if i in A:
        continue
    x=dp[i-1]
    if i>1:
        x+=dp[i-2]
    dp[i]=x%MOD
print(dp[N])

Measured memory_bytes: 12652
#include "bits/stdc++.h"
using namespace std;
using ll=long long;
#define print(n) cout<<n<<endl
#define rep(i,a,n) for(ll i=a;i<n;i++)
#define ALL(s) s.begin(),s.end()
#define P pair<ll,ll>
#define vl vector<ll>
#define vi vector<int>
#define vvl vector<vector<ll>>
#define vvi vector<vector<int>>
const int M=200111;
const int inf=1000000007;
const int MOD=1000000007;
const double PI = 3.1415926535897932384626433;
const long long INF=1e18;
int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};
int ddx[8]={1,-1,0,0,1,-1,-1,1},ddy[8]={0,0,1,-1,1,-1,1,-1};


struct UnionFind {
	vector<int> par;
	UnionFind(int n) : par(n, -1) { }

	int root(int x) {
		if (par[x] < 0) return x;
		else return par[x] = root(par[x]);
	}

	bool same(int x, int y) {
		return root(x) == root(y);
	}

	bool merge(int x, int y) {
		x = root(x); y = root(y);
		if (x == y) return false;
		if (par[x] > par[y]) swap(x, y); // merge technique
		par[x] += par[y];
		par[y] = x;
		return true;
	}

	int size(int x) {
		return -par[root(x)];
	}
};

vvl comb(int n) {
	vvl v(n + 1,vl(n + 1, 0));
	for (int i = 0; i < v.size(); i++) {
		v[i][0] = 1;
		v[i][i] = 1;
	}
	for (int j = 1; j < v.size(); j++) {
		for (int k = 1; k < j; k++) {
			v[j][k] = (v[j - 1][k - 1] + v[j - 1][k]);
		}
	}
	return v;
}

void sosu(ll x,bool f[]){
	ll y=x;
	for(ll i=2;i<=sqrt(y);i++){
		if(x%i==0){
			x/=i;
			f[i]=true;
			i--;
		}
	}
}

ll __gcd(ll x,ll y){
	if(x<y)swap(x,y);
	while(1){
		ll tmp=x%y;
		x=y;
		y=tmp;
		if(y==0)break;
	}
	return x;
}

int keta(ll a){
	int ke=1;
	while(a/=10)ke++;
	return ke;
}

vector<long long> enum_divisors(long long N) {
	vector<long long> res;
	for (long long i = 1; i * i <= N; ++i) {
		if (N % i == 0) {
			res.push_back(i);
			// 重複しないならば i の相方である N/i も push
			if (N/i != i) res.push_back(N/i);
		}
	}
	// 小さい順に並び替える
	sort(res.begin(), res.end());
	return res;
}

ll zyou(ll x,ll n){
	ll y=1;
	rep(i,0,n){
		y*=x;
	}
	return y;
}


int main() {
	int n,a[2*M];
	ll k;
	cin>>n>>k;
	rep(i,1,n+1)cin>>a[i];
	int now=1,cnt=0,cnt2=0;
	int y[2*M];
	fill(y,y+2*M,-1);
	y[1]=0;
	if(k<=n){
		rep(i,1,k+1)now=a[now];
	}else{
		rep(i,1,k+1){
			cnt++;
			int next=a[now];
			if(y[next]!=-1){
				int cnt2=y[now]-y[next]+1;
				now=next;
//				print("cnt, cnt2 = "<<cnt<<" , "<<cnt2);
				k=(k-cnt)%cnt2;
				break;
			}
			now=next;
			y[next]=cnt;
		}

//print("k = "<<k);
		rep(i,1,k+1)now=a[now];
	}
	print(now);

}

Measured memory_bytes: 5924
#include <bits/stdc++.h>
#define rep(i,n) for ( int i = 0; i < (n); ++i )
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long int;
const long long int INF = 1001001001001001LL;
const int inf = 1000000007;
long long int MOD = 1000000007LL;
double PI = 3.1415926535897932;


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

    int a, b;
    cin >> a >> b;
    if( a > b ) swap(a, b);
    
    int ans = 0;
    for(int i = 0; i < b; i++ ) ans += a*pow(10, i);

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
    int num,num2,num3,num4=0,i=0,j=0;
    cin >> num >> num2 >> num3;
    while(num4<num3){
        num4+=num;
        i++;
        if(i%7==0){
            num4+=num2;
            i=0;
        }
        j++;
    }
    cout << j << endl;
    return 0;
}


Measured memory_bytes: 3100
/*
 AUTHOR : ANSHU BABU RAJPUT
 
    JAI MAA SARASWATI
    OM NAMAH SHIVAY
    JAI SHRI KRISHNA
    JAI SHRI RAM
    BHARAT MATA KI JAI

    #PKMKB	
    #CKMKB
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define int  long long 
#define endl    ("\n")
#define ff       first
#define ss      second
#define pb   push_back
#define pf  push_front
#define ppb   pop_back
#define ppf  pop_front
#define mp   make_pair
#define mod 1000000007

#define L(x)    x.length()
#define B(x)     x.begin()
#define E(x)       x.end()
#define F(x)     x.front()
#define SZ(x)     x.size()
#define CLR(x)   x.clear()

#define all(x)                      x.begin(),x.end()
#define sortD(x) sort(x.begin(),x.end(),greater<int>)
#define rev(x)             reverse(x.begin(),x.end())

#define intV vector<int>

#define PI          (3.141592653589)
#define PMAX     priority_queue<int>
#define PMIN             priority_queue<int,vi,greater<int>>
#define setbits(x)                   __builtin_popcountll(x)
#define zrobits(x)                        __builtin_ctzll(x)

#define KING(i, n) for (int(i) = 0; (i) < n; (i)++)
#define MAHAKAL(i, n) for (int(i) = n-1; (i) >= 0; (i)--)

#define Anshu        int t; cin>>t; while(t--)
#define SITARAM(n,type) type* input=new type[n]

mt19937                          rng(chrono::steady_clock::now().time_since_epoch().count());
 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;


void ViLiFY_KiNG()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    freopen("error.txt","w",stderr);
#endif
}
 
int32_t main()
{
    ViLiFY_KiNG();
    int n,m;
    cin>>n>>m;

    int n_count = 0;
    int m_count = 0;

    if(n != 0 && n != 1) {
        n_count  = ((n-1)*n)/2;
    }

    if(m != 0 && m != 1) {
        m_count = ((m-1)*m)/2;
    }

    cout<<(m_count+n_count)<<endl;
    return 0;
}

Measured memory_bytes: 3616
#include <iostream>
#include <string>
#include <algorithm>
#include<math.h>
using namespace std;

int main() {
	int N;
	long long int sum=0, a[300000];
	cin >> N;
	for (int i = 0; i < 3 * N; i++)cin >> a[i];
	sort(a, a + 3 * N);
	for (int i = N; i < 3 * N;i = i + 2) {
		sum += a[i];

	}
	cout << sum << endl;
}



Measured memory_bytes: 2560
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <map>
#include <iomanip>
#include <set>
#include <ctime>
#include <tuple>
#include <bitset>
#include <assert.h>
#include <deque>
using namespace std;

/*
using PAIR = pair<string, int>;
sort(sp.begin(), sp.end(), [](PAIR l, PAIR r){
        return l.first<r.first || (l.first==r.first && l.second > r.second);
        });
*/

typedef long long ll;

#define fi first
#define se second
#define rep(i, n) for (ll i = 0; i < n; i++)
#define debugA() cerr << "AAAAA" << endl
#define debug_() cerr << "-------------" << endl
#define debug(x) cerr << #x << ": " << x << endl
#define debug_vec(v)                   \
    for (int i = 0; i < v.size(); i++) \
    {                                  \
        cout << v[i] << " ";           \
    }                                  \
    cout << endl;

using Graph = vector<vector<int>>;
using P = pair<int, int>;

int main()
{
    vector<int>a = {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"

// Begin {{{
using namespace std;

#define all(x) x.begin(), x.end()
#define rep(i, n) for (i64 i = 0; i < (n); ++i)
#define reps(i, s, n) for (i64 i = (s); i <= (n); ++i)
#define var(Type, ...) Type __VA_ARGS__; input(__VA_ARGS__)

#ifdef DEBUG
#define dump(...) dump_(#__VA_ARGS__, __VA_ARGS__);
#else
#define dump(...)
#endif

using i64 = int_fast64_t;
using pii = pair<i64, i64>;

template <class A, class B>
inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }

template <class A, class B>
inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int MOD = int(1e9) + 7;

// input
void input() {}
template <class Head, class... Tail>
void input(Head&& head, Tail&&... tail) {
  cin >> head;
  input(forward<Tail>(tail)...);
}

// ouls
void outs() {}
template <class Head, class... Tail>
void outs(Head&& head, Tail&&... tail) {
  cout << head << " \n"[sizeof...(tail)==0];
  outs(forward<Tail>(tail)...);
}

template <class T>
void outs(vector<T> &vec) { for (auto &e : vec) cout << e << " \n"[&e==&vec.back()]; }

template <class T>
void outs(vector<vector<T>> &df) { for (auto &vec : df) OUTS(vec); }

// outl
void outl() {}
template <class Head, class... Tail>
void outl(Head&& head, Tail&&... tail) {
  cout << head << "\n";
  outl(forward<Tail>(tail)...);
}

template <class T>
void outl(vector<T> &vec) { for (auto &e : vec) cout << e << "\n"; }

// outn
void outn() {}
template <class Head, class... Tail>
void outn(Head&& head, Tail&&... tail) {
  cout << head;
  outn(forward<Tail>(tail)...);
}

template <class T>
void outn(vector<T> &vec) { for (auto &e : vec) cout << e; }

// dump
template <class T>
void dump_(const char *s, T&& x) {
  clog << '{';
  while(*s != '\0') clog << *(s++);
  clog << ": " << x << '}' << "\n";
}

template <class Head, class... Tail>
void dump_(const char *s, Head&& head, Tail&&... tail) {
  clog << '{';
  while(*s != ',') clog << *(s++);
  clog << ": " << head << "}, ";
  for (++s; !isgraph(*s); ++s);
  dump_(s, forward<Tail>(tail)...);
}
// }}} End

signed main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  var(int, N);

  vector<i64> a(N + 10), b(N + 10), c(N + 10);
  reps(i, 1, N) {
    input(a[i]);
  }

  reps(i, 1, N) {
    input(b[i]);
  }

  reps(i, 1, N - 1) {
    input(c[i]);
  }

  i64 res = 0;
  reps(i, 1, N) {
    res += b[a[i]];
    if (a[i] == a[i-1] + 1) res += c[a[i-1]];
  }

  outl(res);
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int long long
using ldb = long double;
using pa = pair < int, int >;
template < typename T > using index_set = tree < T, null_type, less < T >, rb_tree_tag, tree_order_statistics_node_update >;
template < typename T > using MinPriorityQueue = priority_queue < T, vector < T >, greater < T > >;
#define pb push_back
#define all(c) c.begin(),c.end()
#define unique_sort(x) sort(all(x)), x.resize(distance(x.begin(), unique(all(x))))
#define F  first
#define S  second
#define f(i,x,n) for(int i=x;i<n;i++) 
const int MOD = 1e9 + 7, INF = INT_MAX, N = 1e6 + 10;
const double PI = acos(-1);
const int LINF = LLONG_MAX;
int fact[N];
int modpow(int x, int y){
    int ans=1;
    if(y==1){
        return x%MOD;
    }
    x=x % MOD;
    y=y % (MOD-1);
    while(y>0){
        if(y & 1){
            ans = (ans*x) %MOD;
        }
        x *= x;
        x = x % MOD;
        y >>= 1;
    }
    return ans;
}

int modinv(int x){
    return modpow(x,MOD-2);
}
int sub(int x, int y) {
    x -= y;
    if (x < 0) return x + MOD;
    return x;
}
int add(int x, int y) {
    x += y;
    if (x >= MOD) return x - MOD;
    return x;
}
int multiply(int a,int b){
    a %= MOD;
    b %= MOD;
    return (a*b)%MOD;
}
int ncr(int n, int r){ 
    return multiply(fact[n],multiply(modinv(fact[n-r]),modinv(fact[r])));
} 
int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    int a1 = a*c;
    int a2 = a*d;
    int a3 = b*c;
    int a4 = b*d;
    int ans = max({a1,a2,a3,a4});
    cout << ans << "\n";
    return 0;
}



Measured memory_bytes: 3656
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>

using namespace std;

#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ;
#endif

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;

signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    vector<PLL> BA;
    REP(i,N){
        LL A,B; cin >> A >> B;
        BA.eb(B,A);
    }
    sort(BA.begin(),BA.end());
    LL nt = 0;
    bool ng = 0;
    for(auto p : BA){
        nt += p.second;
        if(nt > p.first) ng = 1;
    }
    if(ng) cout << "No" << endl;
    else cout << "Yes" << endl;

}

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

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    
    int N, A, sol = 0, a[100005];
    cin >> N >> A;
    
    for (int i = 1; i <= N; ++i) {
        cin >> a[i];
        sol += min(abs(A - a[i]), a[i]);
    }
    
    cout << sol * 2 << '\n';
    return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <unordered_map> 
#include <unordered_set>
#include <functional>
#include <bitset>

using namespace std;

typedef pair<long long int, long long int> P;
typedef tuple<int, int, int> T;

long long int INF = 1e18;
long long int MOD = 1e9 + 7;

int main(){
	int N;
	cin >> N;
	int a[10];
	for(int i = 0; i < N; i++){
		a[i] = i + 1;
	}
	int P[10], Q[10];
	for(int i = 0; i < N; i++){
		cin >> P[i];
	}
	for(int i = 0; i < N; i++){
		cin >> Q[i];
	}
	int a1, a2;
	int cnt = 0;
	do{
		bool flag = true;
		for(int i = 0; i < N; i++){
			if(P[i] != a[i]){
				flag = false;
			}
		}
		if(flag){
			a1 = cnt;
		}
		flag = true;
		for(int i = 0; i < N; i++){
			if(Q[i] != a[i]){
				flag = false;
			}
		}
		if(flag){
			a2 = cnt;
		}
		cnt += 1;
	}while(next_permutation(a, a + N));
	cout << abs(a1 - a2) << endl;
	return 0;
}

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

int l[1100], r[1100];
int main(){
  int N;
  cin >> N;
  for (int i = 0; i < N; ++i){
    cin >> l[i] >> r[i];
  }
  int sum = 0;
  for (int i = 0; i < N; ++i){
    sum += r[i] - l[i];
  }
  int ans = sum + N;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
input_line_1 = raw_input()
fields = input_line_1.split()
N = int(fields[0])
A = int(fields[1])
B = int(fields[2])
T = A + B
all = raw_input()
for every in all:
	if every == 'c':
		print 'No'
	elif every == 'a':
		if T > 0:
			T = T - 1
			print 'Yes'
		else:
			print 'No'
	else:
		if T > 0 and B > 0:
			T = T - 1
			B = B - 1
			print 'Yes'
		else:
			print 'No'


Measured memory_bytes: 3076
#include<iostream>
#include<stdio.h>
#include<math.h>
#include    <iomanip>
using namespace std;
int main(){
    long long int num;
    while(cin>>num&&num!=0){
        
        char a[100000][2];
        for (long long int i=0; i<num; i++) {
            cin>>a[i][0]>>a[i][1];
            
        }
        long long  num2;
        cin>>num2;
        char k;
        for (long long int i=0; i<num2; i++){
            cin>>k;
            for (long int ii=0; ii<num; ii++) {
                if (a[ii][0]==k) {
                    k=a[ii][1];
                    ii=num;
                }
            }
            cout<<k;
        }
        cout<<endl;
    }
    return 0;
}

Measured memory_bytes: 1156
s = input()[::-1]
for i in range(10 ** 5):
    if s[:5] == "dream"[::-1] or s[:5] == "erase"[::-1]:
        s = s[5:]
    elif s[:7] == "dreamer"[::-1]:
        s = s[7:]
    elif s[:6] == "eraser"[::-1]:
        s = s[6:]
    else:
        if len(s) > 0:
            print("NO")
            break
        else:
            print("YES")
            break


Measured memory_bytes: 3188
nl = lambda: list(map(int, input().split()))
sl = lambda: input().split()
n = lambda: int(input())
s = lambda: input()

H, W = nl()

mas = []
for i in range(H):
    mas.append(s())


res = [[0] * (W+2) for i in range(H+2)]
for i in range(H):
    for j in range(W):
        if mas[i][j] == '#':
            for k in [-1, 0, 1]:
                for l in [-1, 0, 1]:
                    if k == 0 and l == 0:
                        continue
                    res[i+1+k][j+1+l] += 1

for i in range(H):
    row = ''
    for j in range(W):
        if mas[i][j] == '#':
            row += '#'
        else:
            row += str(res[i+1][j+1])
    print(row)


Measured memory_bytes: 3064
#include <stdio.h>

int main(){
  int n;
  int ans=0;
  scanf("%d",&n);
  
  int a[n+1],b[n+1],c[n];
  for(int i=1;i<=n;i++){
    scanf("%d",&a[i]);
  }
  for(int i=1;i<=n;i++){
    scanf("%d",&b[i]);
    ans=ans+b[i];
  }
  for(int i=1;i<n;i++){
    scanf("%d",&c[i]);
  }
  
  for(int i=1;i<n;i++){
    if(a[i+1]-a[i]==1){
      ans=ans+c[a[i]];
    }
  }
  
  printf("%d",ans);
  
  return 0;
}



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

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

ll N;
vector<vector<int>> g;


struct Node {
	ll v;
	ll lazy;
	ll lv, rv;
	Node *left ,*right;
	Node(ll l, ll r){
		v=0; lazy=0;
		lv=l; rv=r;
		left=NULL; right=NULL;
		if(lv>=rv) return;
		ll m=lv + (rv-lv)/2;
		left=new Node(l, m);
		right=new Node(m+1, r);
	}

	void output(){
		cout<<lv<<" "<<rv<<" "<<v<<endl;
		if(left!=NULL) left->output();
		if(right!=NULL) right->output();
	}

	void pushdown(){
		ll mv = lv + (rv - lv)/2;
		if(lazy!=0){
			if(left!=NULL) {
				left->v += (mv - lv + 1) * (N + 1) * lazy - 
				(mv + lv)*(mv-lv+1)/2 * lazy;
				left->lazy += lazy;
			}
			if(right!=NULL) {
				right->v += (rv - mv) * (N + 1) * lazy - 
				(rv + mv + 1)*(rv-mv)/2 * lazy;
				right->lazy += lazy;
			}
			lazy=0;
		}
	}

	void add(ll l, ll r, ll vv){
		//cout<<l<<" "<<r<<" "<<lv<<" "<<rv<<endl;
		if(lv==l && rv==r){
			//v += vv * (rv - lv + 1);
			v += (r - l + 1) * (N + 1) * vv - 
				(r + l)*(r-l+1)/2 * vv;

			lazy += vv;
			return;
		}
		pushdown();
		ll m=lv + (rv - lv)/2;
		if(r<=m){
			left->add(l, r, vv);
		}else if (l>m){
			right->add(l, r, vv);
		}else{
			left->add(l, m, vv);
			right->add(m+1, r, vv);
		}
		v=left->v + right->v;
	}

	ll query(ll l, ll r){
		if(l==lv && r==rv){
			return v;
		}
		pushdown();
		ll m=lv + (rv - lv)/2;
		if(r<=m){
			return left->query(l, r);
		}else if(l>m){
			return right->query(l, r);
		}else{
			return left->query(l,m) + right->query(m+1, r);
		}
		return 0;
	}
};



ll solve(){
	Node seg(1, N);
	for(int u=1; u<=N; u++){
		int c = 0;
		for(int v : g[u]){
			if(v < u){
				c++;
			}
		}
		seg.add(u, u, 1 - c);
	}

	ll res = seg.query(1, N);
	for(int u=1; u<N; u++){
		for(int v : g[u]){
			if(v > u){
				seg.add(v, v, 1);
			}
		}
		res += seg.query(u+1, N);
	}

	return res;
}

int main(){
	cin>>N;
	g = vector<vector<int>>(N+1);
	for(int i=0; i<N-1; i++){
		int u, v;
		cin>>u>>v;
		g[u].push_back(v);
		g[v].push_back(u);
	}

	
	cout<<solve()<<endl;
    return 0;
}






Measured memory_bytes: 39900
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i,m,n) for(ll i = (m); i < (n); i++)
#define all(v) v.begin(), v.end()
#define print(x) cout << (x) << endl

int main() {
    int N,K,d,A;
    vector<bool> sun(N,false);
    cin >> N >> K;
    rep(i,K){
        cin >> d;
        rep(j,d){
            cin >> A;
            sun[A-1] = true;
        }
    }
    int cnt = 0;
    rep(i,N){
        if(sun[i] == false) cnt++;
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 3632