akhauriyash/Code-Regression huggingface dataset:
N, K = map(int, input().split())
A = list(map(int, input().split()))
for i in range(N):
    A[i] -= 1
L = [0]
t = 0
F = [-1 for _ in range(N)]
F[0] = 0
c = 1
while F[A[t]] == -1:
    t = A[t]
    F[t] = c
    c += 1
    L.append(t)
loop = c - F[A[t]]
buffer = c - loop
if K < buffer:
    print(L[K] + 1)
else:
    NL = L[buffer:]
    amari = (K - buffer) % loop
    print(NL[amari] + 1)


Measured memory_bytes: 107272
X ,N = [int(i) for i in input().split()]
N_list = [int(n) for n in input().split()]
count = 0
while(True):
    if not X-count in N_list:
        min_abs = X - count
        break
    elif not X+count in N_list:
        min_abs = X + count
        break
    count += 1
print(min_abs)

Measured memory_bytes: 9124
#include <stdio.h>
#include <string>
#include <iostream>
#include <iomanip>
#include <map>
#include <algorithm>
#include <vector>
#include <math.h>
using namespace std;

int main(void) {
	int n;
	char clo;
	cin >> n;
	for(int i=0; i<n; i++){
		cin >> clo;
		if(clo=='Y'){
			cout << "Four" << endl;
			return 0;
		}
	}
	cout << "Three" << endl;
	return 0;
}

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

const int N=200008;
int a[N], b[N], ta, tb;
int main()
{
	cin.sync_with_stdio(0);
	long long A,B;
	cin >> A >> B;
	if (A == B) {cout << 1 << endl; return 0;}
	if (A > B) swap(A, B);
	ta = tb = 0;
	while (A)
	{
		a[ta++] = A % 2;
		A >>= 1;
	}
	while (B)
	{
		b[tb++] = B % 2;
		B >>= 1;
	}
	int r = 0;
	for (int i = 0; i < max(ta, tb); i++)
		if (a[i] != b[i]) r = i;
	for (int i = r; i >= 0; i--)
		A = A * 2 + a[i], B = B * 2 + b[i];
	int pos = -1;
	for (int i = 0; i < r; i++) if (b[i] == 1) pos = i;
	long long R = (1ll << r) + (1ll << pos + 1) - 1;
	long long T = 1ll << r;
	long long L = A + T;
	long long ans = T - A;
	if (R < L) ans += R - T + 1, ans += T * 2 - A - T; else ans += T;
	cout << ans << endl;	
}


Measured memory_bytes: 256
/* ex9_2
    sachiyan*/

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define SIZE 100001

//リストのノード（スタック内の各データ）の定義
typedef struct node{
    char elem;
    struct node *next;
} node;

//スタックにデータを追加
void push(node  **first, char elem){
    //追加する分の領域を確保
    node *new = calloc(1, sizeof(node));
    if(new == NULL) exit(1);
    new->elem = elem;
    new->next = *first;
    *first = new;
}

//スタックからデータを取り出す
char pop(node **first){
    char elem;
    node *tmp = *first;
    if(tmp == NULL) exit(1);
    elem = tmp->elem;
    *first = tmp->next;
    //取り出したノードのメモリを解放
    free(tmp);
    return elem;
}

int main(void){
    //最初のノードの指す先
    node *first = NULL;
    char string[SIZE],last;
    int i;
    int count=0;
    //与えられた文字列の入力
    scanf("%s",string);

    //１つずつのキューブについて考える
    for(i=0;i<strlen(string);i++){
        //机の上にキューブがなければ、新たな要素をスタックに追加
        if(first==NULL){
            push(&first,string[i]);
        }
        else{
            last=pop(&first);
            //先頭と異なる色であれば何も入らず、消えたブロック２つをカウント
            if(last!=string[i]){
                count+=2;
            }
            //先頭と同じ色であれば、前と後のどちらもスタックに入る
            else{
                push(&first,last);
                push(&first,string[i]);
            }
        }
    }
    
    //答えの出力
    printf("%d\n",count);

    return 0;
}

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

#define rep(i,N) for(int i=0;i<N;i++)
#define rep2(i,N) for(int i=1;i<=N;i++)
using namespace std;
long long  INF=1e18;
long long mod=1e9+7;



int main(){

    int n;
    cin>>n;
    int A[n+1];

    rep2(i,n)cin>>A[i];
    
    bitset<4000010>bs;
    int cnt[4000010]={};
    bs[0]=1;
    long long sum=0;
    rep2(i,n){
        bs|=(bs << A[i]);
        sum+=A[i];
    }

    for(int i=++sum/2;;i++){
        if(bs[i]){
            cout<<i<<endl;
            return 0;
        }
    }

    /*
    long long ans;
    long long median=1;

    rep(i,n-1)median*=2;

    cout<<median<<endl;
    rep2(i,4000010){
        if(bs[i]==1){
            cout<<i;
        }
    }
    cout<<endl;
    */

    

    return 0;

}
/*


*/


Measured memory_bytes: 1664
N = int(input())
A = list(map(int,input().split(" ")))
S = []
for a in A:
    if a % 2 == 0:
        S.append(a)
    else:
        pass
flag = True
for s in S:
    if s % 3==0 or s% 5==0:
        pass
    else:
        flag = False
if flag==True:
    print("APPROVED")
if flag == False:
    print("DENIED")

Measured memory_bytes: 3064
//g++ -std=c++14 test.cpp -o test.out
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <map> 
#include <utility>
#include <limits.h>
#include <bitset>
#include <set>
using namespace std;
 
#define LL long long int
const LL INF = (LL)(1e18)+1;
const int INF_INT = 2147483647-1e6;
const LL mod = 1000000007ll;

LL N,K;
LL A[500];

LL ans = 1;

void solve(){
	LL A_sum = 0;
	for(int i=0;i<N;i++){
		A_sum += A[i];
	}

	//A_sumの約数について一つづつ見ていく
	//約数は高々√(N*max(A)個しかない
	set<LL> divisor;
	for(LL i=1;i*i<=A_sum;i++){
		if(A_sum%i==0){
			divisor.insert(i);
			divisor.insert(A_sum/i);
		}
	}
	for(LL x:divisor){
		LL need;
		{
			//calc need
			vector<LL> r(N);
			for(int i=0;i<N;i++) r[i] = A[i]%x;
			sort(r.begin(),r.end());

			LL B = 0;
			for(int i=0;i<N;i++) B+=(x-r[i]);

			LL A = 0;
			need = 1e18;
			for(int i=0;i<N;i++){
				A += r[i];
				B -= (x-r[i]);
				need = min(need,max(A,B));
			}
		}
		if(need<=K) ans = max(ans,x);
	}
}
 
int main(){
	cin >> N >> K;
	for(int i=0;i<N;i++) cin >> A[i];
 
	solve();
 
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		try(Scanner sc = new Scanner(System.in)) {
			int a = sc.nextInt();
			int b = sc.nextInt();
			int c = sc.nextInt();
			int x = sc.nextInt();
			int ans = 0;
			for(int i = 0 ; i <= a ; i++) {
				for(int j = 0 ; j <= b ; j++) {
					for(int k = 0 ; k <= c ; k++) {
						if(i * 500 + j * 100 + k * 50 == x) {
							ans++;
						}
					}
				}
			}

			System.out.println(ans);
		}

	}

}


Measured memory_bytes: 21844
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>

using namespace std;

int read()
{
    char c=getchar();
    int d=0;
    while(c<'0' || c>'9')c=getchar();
    while(c>='0' && c<='9'){d=(d<<3)+(d<<1)+(c^48);c=getchar();}
    return d;
}

#define MAXN 50
#define INF 10086

int n;
string s;
int a[27];
int minn[MAXN+1];

int main()
{
    n=read();
	for(int i=1;i<=26;i++)minn[i]=INF;
    for(int i=1;i<=n;i++)
    {
		for(int j=1;j<=26;j++)a[j]=0;
        getline(cin,s);
        //for(auto j:s)a[j-'a'+1]++;
        for(char j:s)a[j-'a'+1]++;
		for(int j=1;j<=26;j++)minn[j]=min(minn[j],a[j]);
    }
    for(int i=1;i<=26;i++)
		for(int j=1;j<=minn[i];j++)putchar('a'+i-1);
}

Measured memory_bytes: 256
/* include file */
#include <set>
#include <queue>
#include <vector>
#include <functional>
using namespace std;

struct Graph
{
    struct edge
    {
        int to;
        long long cost;
    };

    int n;
    vector<vector<edge>> edges;

    Graph(int N)
    {
        n = N;
        edges.resize(n, vector<edge>());
    }

    int size() const
    {
        return n;
    }

    vector<edge> &operator[](int v)
    {
        return edges[v];
    }
};

template <class Type>
struct Dijkstra
{
    using Update = function<bool(Type &, Graph::edge &, Type &)>;
    using P = pair<Type, int>;
    Graph &G;

    Update update;

    vector<Type> ver;
    int n;
    Type init;

    Dijkstra(Graph &g, Type init_v, Update func) : G(g), n(g.size()), init(init_v), update(func)
    {
    }

    Type &operator[](int i)
    {
        return ver[i];
    }

    vector<Type> &cal(int s, Type first)
    {
        ver.assign(n, init);
        ver[s] = first;
        priority_queue<P, vector<P>, greater<P>> que;
        que.push({ver[s], s});

        while (!que.empty())
        {
            Type t = que.top().first;
            int v = que.top().second;
            que.pop();

            if (ver[v] < t)
                continue;

            for (auto &e : G[v])
            {
                if (update(ver[v], e, ver[e.to]))
                {
                    que.push({ver[e.to], e.to});
                }
            }
        }
        return ver;
    }
};

#include <iostream>

int main()
{
    typedef long long i64;
    int v, e, r;
    cin >> v >> e >> r;
    Graph G(v);
    for (int i = 0; i < e; i++)
    {
        int s, t;
        i64 d;
        cin >> s >> t >> d;
        G[s].push_back({t, d});
    }

    Dijkstra<i64> dijk(G, (1LL << 60),
                       [](i64 &from, Graph::edge &e, i64 &to) {
                           if (to > from + e.cost)
                           {
                               to = from + e.cost;
                               return true;
                           }
                           return false;
                       });
    dijk.cal(r, 0LL);

    for (int i = 0; i < v; i++)
    {
        if(dijk[i] == (1LL << 60)) cout << "INF" << endl;
        else cout << dijk[i] << endl;
    }
    return 0;
}



Measured memory_bytes: 19532
import sys
input = lambda: sys.stdin.readline().rstrip("\r\n")

n = int(input())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()][::-1]

ng = []
for i in range(n):
    if a[i] == b[i]:
        ng.append(i)

if len(ng) == 0:
    print('Yes')
    print(*b)
    sys.exit()

min_ng = min(ng)
max_ng = max(ng)

left = 0
right = n - 1

for i in ng:
    if b[i] != b[left] and a[left] != b[i]:
        b[i], b[left] = b[left], b[i]
        left += 1
        continue
    if b[i] != b[right] and a[right] != b[i]:
        b[i], b[right] = b[right], b[i]
        right -= 1

flag = 1

for i in range(n):
    if a[i] == b[i]:
        flag = 0

if flag:
    print('Yes')
    print(*b)
else:
    print('No') 



Measured memory_bytes: 124324
use std::io::*;

fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let k: usize = itr.next().unwrap().parse().unwrap();
    let n: usize = itr.next().unwrap().parse().unwrap();
    let a: Vec<usize> = (0..n)
        .map(|_| itr.next().unwrap().parse().unwrap())
        .collect();

    let mut ans = 1usize << 60;
    for i in 0..n - 1 {
        ans = std::cmp::min(ans, k - (a[i + 1] - a[i]));
    }
    ans = std::cmp::min(ans, k - ((k - a[n - 1]) + a[0]));
    println!("{}", ans);
}


Measured memory_bytes: 8444
#include <bits/stdc++.h>
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define int long long
using namespace std;

const int N = 2e5 + 5;

int kol[N];

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int x;
    cin >> x;
    //for (int x = 1; x <= 179; x++) {
    kol[0]++;
    int ans = 1;
    int sum = 1;
    int cur = 0;
    double cx = 0, cy = 0;
    cx = 1;
    while (abs(cx) > 1e-10 || abs(cy) > 1e-10) {
        cur += x;
        cur %= 360;
        ans++;
        /*if (cur >= 180) {
            kol[cur - 180]--;
            if (kol[cur - 180] == 0)
                sum--;
            else
                if (kol[cur - 180] == -1)
                    sum++;
            cout << kol[cur - 180] << endl;
        } else {
            kol[cur]++;
            if (kol[cur] == 0)
                sum--;
            else if (kol[cur] == 1)
                sum++;
        }
        cout << cur << ' ' << sum << endl;
        */
        cy += sin(cur * 1.0 / 180 * acos(-1));
        cx += cos(cur * 1.0 / 180 * acos(-1));
        //cout << cx << ' ' << cy << endl;
    }
    cout << ans;
    //cout << x << endl;
    //}
    return 0;
}


Measured memory_bytes: 4012
n=int(input())
l=sorted([''.join(sorted(input())) for _ in range(n)])
c=1
ans=[]
for i in range(n-1):
  if l[i] == l[i+1]:
    c += 1
  else:
    ans.append((c*(c-1))/2)
    c=1
ans.append((c*(c-1))/2)
print(int(sum(ans)))
  

Measured memory_bytes: 13432
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <stdio.h>
#include <string>
#include <vector>

#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const double PI = 3.1415926535897932;

/* a と b の最大公約数を返す関数 */
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

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

	int c[3] = {};
	int total;
	int ans[3] = { -1, -1, -1 };
	bool find = false;
	for (int i = 0; i <= N; ++i)
	{
		for (int j = 0; j <= (N - i); ++j)
		{
			total = 10000 * i + 5000 * j + 1000 * (N - i - j);
			if (total == Y)
			{
				ans[0] = i;
				ans[1] = j;
				ans[2] = N - i - j;
				find = true;
				break;
			}
		}
		
		if (find) break;
	}

	cout << ans[0] << " " << ans[1] << " " << ans[2] << endl;
	return 0;
}

Measured memory_bytes: 3584
#include<bits/stdc++.h>
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define ri(x) scanf("%d",&(x))
#define ri2(x,y) scanf("%d %d",&(x),&(y))
#define ri3(x,y,z) scanf("%d %d %d",&(x),&(y),&(z))
#define rll(x) scanf("%lld",&(x))
#define rll2(x,y) scanf("%lld %lld",&(x),&(y))
#define rll3(x,y,z) scanf("%lld %lld %lld",&(x),&(y),&(z))
#define gc(x) ((x) = getchar())
using namespace::std;

const long double PI = acos(-1);
const long long MOD = 1000000000 +7;

typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<ll,pll> tll;
typedef pair<int,int> ii;
typedef pair<int,ii> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<ll> vll;
typedef vector<pll> vpll;
typedef vector<tll> vtll;
typedef vector<string> vs;
typedef set<int> si;
typedef set<ii> sii;
typedef set<iii> siii;

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

ll add(ll a, ll b, ll m = MOD){ return (a%m + b%m+2*m)%m;}

ll mul(ll a, ll b, ll m = MOD){ return ((a%m+m)*(b%m+m))%m;}

ll pow_mod(ll a, ll b, ll m = MOD){
	ll res = 1LL;
	a = a%m;
	while(b){
		if(b&1) res = mul(res,a,m);
		b >>= 1;
		a = mul(a,a,m);
	}
	return res;
}

ll fastexp(ll a, ll b){
	ll res = 1LL;
	while(b){
		if(b&1) res = res*a;
		b >>= 1;
		a *= a;
	}
	return res;
}

int gcdExtendido(int a, int b, int *x, int *y){
	if(a == 0){
		*x = 0;
		*y = 1;
		return b;
	}
	int x1, y1;
	int gcd = gcdExtendido(b%a,a,&x1,&y1);
	
	*x = y1-(b/a)*x1;
	*y = x1;
	return gcd;
}

int modInverso(int a, int m){
	int x, y;
	int g = gcdExtendido(a,m,&x,&y);
	if(g!=1) return -1;
	else return (x%m + m)%m;
}

/****************************************
*************P*L*A*N*T*I*L*L*A************
*****************************************/

const int N = 5000+5;
const int M = 200+5;
const int LOG = 18;

int n,m;
ll a[N];
ll ans;
int bestL, bestR;
int b[N][M];
int ST[M][N][LOG];

void startSparseTable(){
	for(int k=0; k<m; k++){
		for(int i=0; i<n; i++){
			ST[k][i][0] = b[i][k];
		}
		for(int d=1; 1<<d <= n; d++){
			int dis = 1<<(d-1);
			for(int i=0; i+2*dis-1 < n; i++){
				ST[k][i][d] = max(ST[k][i][d-1],ST[k][i+dis][d-1]);
			}
		}
	}
}

int getMax(int k, int x, int y){
	if(x == y) return b[x][k];
	int d = y-x+1;
	int bit = 31 - __builtin_clz(d);
	int dis = 1<<bit;
	return max(ST[k][x][bit],ST[k][y-dis+1][bit]);
}

ll compute(int L, int R){
	ll act = 0LL;
	for(int i=0; i<m; i++){
		act += getMax(i,L,R);
	}
	act -= a[R] - a[L];
	return act;
}

void solve(int L, int R, int optL, int optR){
	if(L > R) return;
	int mi = (L+R)/2;
	ll midAns = 0LL;
	int midBest = optL;
	for(int i=max(mi,optL); i<=optR; i++){
		ll cand = compute(mi,i);
		if(midAns < cand){
			midBest = i;
			midAns = cand; 
		}
	}
	if(ans < midAns){
		ans = midAns;
		bestL = mi;
		bestR = midBest;
	}
	if(L < R){
		solve(L,mi-1,optL,midBest);
		solve(mi+1,R,midBest,optR);
	}
}

int main(){
	ri2(n,m);
	for(int i=1; i<n; i++) rll(a[i]);
	for(int i=1; i<n; i++) a[i] += a[i-1];
	for(int i=0; i<n; i++){
		for(int j=0; j<m; j++){
			ri(b[i][j]);
		}
	}
	startSparseTable();
	ans = 0LL;
	solve(0,n-1,0,n-1);
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 76416
#include<bits/stdc++.h>
#include <assert.h>
using namespace std;
#define rep(a,b,c) for(ll a=b;a<=c;a++)
#define repn(a,b,c) for(ll a=b;a>=c;a--)
#define ll long long 
#define sum(a,b) a=a+b
#define mem(a, b) memset(a, (b), sizeof(a))
#define ctz(x) __builtin_ctz(x)
#define clz(x) __builtin_clz(x)
#define popcount(x) __builtin_popcount(x)
#define parity(x) __builtin_parity(x)


int main(){

	double n,k;
	cin>>n>>k;

	rep(i,1,(int)n){
      int x;
      cin>>x;
      
	}
n--;
k--;
double ans=n/k;
ans=ceil(ans);

cout<<ans<<endl;

return 0;
}

Measured memory_bytes: 256
h,w = map(int,input().split())
aa = [list(input()) for _ in range(h)]

use_cols = []
use_rows = []

for hi in range(h):
  flag = False
  for wi in range(w):
    if aa[hi][wi] == '#':
      flag = True
      break
  if flag:
    use_rows.append(hi)

for wi in range(w):
  flag = False
  for hi in range(h):
    if aa[hi][wi] == '#':
      flag = True
      break
  if flag:
    use_cols.append(wi)
    
ans = [[' ']*(w-len(use_cols)) for _ in range(h-len(use_rows))]

ans =[]
for hi in use_rows:
  row = ''
  for wi in use_cols:
    row+=aa[hi][wi]
  ans.append(row)
  
for a in ans:
  print(a)  

Measured memory_bytes: 3188
#include <iostream>
#include <ios>
#include <iomanip>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <cstdlib>
#include <cstring>
#include <cmath>
using namespace std;

#define MOD 1e9+7
#define rep(i, n) for(int i=0; i<n; ++i)
typedef long long ll;

#define MAX_N 100000
#define MAX_V 100
#define MAX_E 100

//--------------------------

//void dfs(string, int);

int N, K;
int d[10];
bool flag = true;

int main() {

  cin >> N >> K;
  rep(i, K) cin >> d[i];

  for(int i=N; i<=100000; ++i) {
    flag = true;
    string s = to_string(i);
    rep(j, K) {
      if(s.find(to_string(d[j]))!=string::npos) {
        flag = false;
      }
    }

    if(flag) {
      cout << s << endl;
      break;
    }
  }

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(obj) begin(obj), end(obj)
using namespace std;

using ll = long long;
using ull = unsigned long long;
const ll INF = 1e18;

int N;
vector<vector<ll>> dp;
vector<ll> a;

ll rec(int l = 0, int r = N) {
    if (r == l) return 0;
    ll &ret = dp[l][r];
    if (ret != INF) return ret;

    if ((N - (r - l)) % 2 == 0) {  // 先手
        ret = max(a[l] + rec(l + 1, r), rec(l, r - 1) + a[r - 1]);
    } else {  // 後手
        ret = min(-a[l] + rec(l + 1, r), rec(l, r - 1) - a[r - 1]);
    }

    return ret;
}

int main() {
    cin >> N;
    a.assign(N, 0);
    dp.assign(N + 5, vector<ll>(N + 5, INF));
    for (int i = 0; i < N; i++) {
        cin >> a.at(i);
    }

    cout << rec() << endl;

    return 0;
}


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

int main(){
    int n,m;
    cin>>n>>m;
    vector<int>x(m),y(m-1);
    rep(i,m)cin>>x[i];
    sort(x.begin(),x.end());
    rep(i,m-1)y[i]=abs(x[i]-x[i+1]);
    sort(y.begin(),y.end());
    ll ans=0;
    rep(i,m-n){
        ans+=y[i];
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1024
#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <numeric>
#include <queue>
#include <sstream>
#include <string>
#include <string.h>
#include <tuple>
#include <vector>

#define REP(i,x) for(int i{ 0 }; i < (int)(x); i++)
#define REPC(i,x) for(int i{ 0 }; i <= (int)(x); i++)
#define RREP(i,x) for(int i{ (int)(x) - 1 }; i >= 0 ;i--)
#define RREPC(i,x) for(int i{ (int)(x)}; i >= 0; i--)
#define REP1O(i,x) for(int i{ 1 }; i < (int)(x); i++)
#define REP1C(i,x) for(int i{ 1 }; i <= (int)(x); i++)

#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()

using namespace std;

typedef int64_t ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
typedef pair<int, int> pii;
typedef tuple<int, int, int> tupiii;
typedef tuple<ll, ll, ll> tuplll;

const int INTMAX = 2147483647;
const ll LLMAX = 9223372036854775807;
const int MOD = 1000000007;

template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
inline void swap(ll& a, ll& b) { a ^= b; b ^= a; a ^= b; }
inline void swap(int& a, int& b) { a ^= b; b ^= a; a ^= b; }



int main()
{
	string s;
	cin >> s;

	vector<string> items{ "dream" ,"dreamer", "erase", "eraser" };
	REP(i, 4)
		reverse(ALL(items[i]));

	string tmp ("");

	while (SZ(tmp) < 7 && !s.empty())
	{
		tmp.PB(s.back());
		s.pop_back();

		REP(i, 4)
		{
			if (items[i] == tmp)
				tmp.clear();
		}
	}

	if (!tmp.empty())
		cout << "NO" << endl;
	else
		cout << "YES" << endl;

}


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

typedef long long ll;

int main(){
	ll N, T, c, t, min=10000;
	cin >> N >> T;
	
	for(int i=0; i<N; i++){
		cin >> c >> t;
		if(t <= T  &&  c < min) min = c;
	}
	
	if(min == 10000){
		cout << "TLE" <<endl;
		return 0;
	}
	
	cout << min << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
void print() {
    cout << endl;
}
template <class Head, class... Tail>
void print(Head &&head, Tail &&... tail) {
    cout << head;
    if (sizeof...(tail) != 0)
        cout << " ";
    print(forward<Tail>(tail)...);
}
template <class T>
void print(vector<T> &vec) {
    for (auto &a : vec) {
        cout << a;
        if (&a != &vec.back())
            cout << " ";
    }
    cout << endl;
}
template <class T>
void print(vector<vector<T>> &df) {
    for (auto &vec : df) {
        print(vec);
    }
}
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define xrep(i, a, b) for (int i = int(a); i < int(b); ++i)
using ll = long long;
const int INF = 100100100;


int main() {
    int N, K ,Q;
    cin >> N >> K >> Q;
    vector<int> A(Q);
    rep(i, Q) {
        int a;
        cin >> a;
        a--;
        A[i] = a;
    }

    vector<int> B(N, K-Q);
    
    for(auto a: A) {
        B[a]++;
    }

    for(auto b: B) {
        if(b<=0) {
            print("No");
        }
        else {
            print("Yes");
        }
    }
    return 0;
}

Measured memory_bytes: 3980
S = list(input())
l = len(S)
ans = 0
for i in range(2**(l-1)):
    start = 0
    c = 0
    for j in range(l-1):
        if (i>>j)&1:
            end = j+1
            ans += int("".join(S[start:end]))
            start = j+1
    ans += int("".join(S[start:]))
print(ans)


Measured memory_bytes: 39920
import collections

def getls():
    return [ipt for ipt in input().split()]
def getlsi():
    return [int(ipt) for ipt in input().split()]

[n,k] = getlsi()
a = getlsi()

dic = collections.defaultdict(int)

now = 1

cnt = 1
while dic[now] == 0:
    dic[now] = cnt
    now = a[now-1]
    cnt += 1
lp = cnt - dic[now]
if k <= dic[now]:
    next = 1
    for i in range(k):
        next = a[next-1]
    print(next)
else:
    next = 1
    tmp = (k+1 - dic[now]) % lp
    #print(tmp)
    for i in range(dic[now]+ tmp-1):
        #print(next)
        next = a[next-1]
    print(next)
#else:


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

#define rep(i,s,n) for (int i = (int)s; i < (int)n; i++)
#define ll long long
#define pb push_back
#define eb emplace_back
#define All(x) x.begin(), x.end()
#define Range(x, i, j) x.begin() + i, x.begin() + j
#define lbidx(x, y) lower_bound(x.begin(), x.end(), y) - x.begin()
#define ubidx(x, y) upper_bound(x.begin(), x.end(), y) - x.begin()
#define llbidx(x, y, z) lower_bound(x.begin(), x.end(), z) - lower_bound(x.begin(), x.end(), y) // 二要素間の距離
#define deg2rad(deg) ((((double)deg)/((double)360)*2*M_PI))
#define rad2deg(rad) ((((double)rad)/(double)2/M_PI)*(double)360)
#define Find(set, element) set.find(element) != set.end()
#define Decimal(x) printf("%.10f\n", x) // 小数点を10桁まで表示
// debug用
#define PrintVec(x) for (auto elementPrintVec: x) { cout << elementPrintVec << " "; } cout << endl;

typedef pair<int, int> PI;
typedef pair<ll, ll> PLL;

int POWINT(int x, int n) {
  int ret = 1;
  rep(i, 0, n) ret *= x;
  return ret;
};

ll POWLL(int x, int n) {
  ll ret = 1;
  rep(i, 0, n) ret *= x;
  return ret;
};

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

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

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

  int N;
  cin >> N;
  vector<string> v(N);
  rep(i, 0, N) {
    cin >> v[i];
  }

  set<string> s;
  s.insert(v[0]);
  bool flag = true;
  rep(i, 1, N) {
    string cur = v[i];
    string prv = v[i-1];
    if (prv[prv.size()-1] != cur[0] || Find(s, cur)) {
      flag = false;
      break;
    }
    s.insert(cur);
  }

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

  return 0;
};


Measured memory_bytes: 256
s = input()

uis_noty = False
lis_noty = False

if int(s[0]) > 1 or (int(s[0]) == 1 and int(s[1]) > 2) or (int(s[0]) == 0 and int(s[1]) == 0):
  uis_noty = True
if int(s[2]) > 1 or (int(s[2]) == 1 and int(s[3]) > 2) or (int(s[2]) == 0 and int(s[3]) == 0):
  lis_noty = True

if uis_noty == True and lis_noty == True:
  print('NA')
elif uis_noty == False and lis_noty == True:
  print('MMYY')
elif uis_noty == True and lis_noty == False:
  print('YYMM')
else:
  print('AMBIGUOUS')

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

const int MAX = 1e5 + 10 ;

int dp[ MAX ] ;
vector< int > v[ MAX ] ;

int dfs( int x ){
	if( dp[ x ] != -1 )
		return dp[ x ] ;
	int &ans = dp[ x ] ;
	ans = 0 ;
	for( int i : v[ x ] ){
		ans = max( ans, dfs( i ) ) ;
	}
	ans += 1 ;
	return ans ;
}

int main( ){
	int n, m, x, y ;
	cin >> n >> m ;
	for( int i = 0 ; i < m ; i++ ){
		cin >> x >> y ;
		v[ y ].push_back( x ) ;
	}
	memset( dp, -1, sizeof dp ) ;
	int ans = 0 ;
	for( int i = 1 ; i <= n ; i++ ){
		ans = max( ans, dfs( i ) ) ;
	}
	cout << ans - 1 ;
}

Measured memory_bytes: 9088
import os
import sys
import numpy as np


def dump(x):
    print >> sys.stderr, "{0}".format(x)

l = map(int, raw_input().split())
S = raw_input()
AB = l[1]+l[2]
B = l[2]
N = l[0]

count_array = [0]*2
pass_list = [0]*N
for i, s in enumerate(S):
    if count_array[0] >= AB:
        break

    if s == "a":
        count_array[0] += 1
        pass_list[i] = 1
    elif s == "b" and count_array[1] < B:
        count_array[0] += 1
        count_array[1] += 1
        pass_list[i] = 1

for pass_ in pass_list:
    if pass_ == 1:
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 11692
#include<bits/stdc++.h>
#define rep(i,a,n) for (int i = a;i < n;i++)
#define per(i,n,a) for (int i = n-1;i >= a;i--)
using namespace std;

int main() {
    string a, b; cin >> a >> b;
    rep(i, 0, a.size()) {
        cout << a[i];
        if (i < b.size()) {
            cout << b[i];
        }
    }
    cout << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <numeric>
#include <ctime>
#include <complex>
#include <bitset>
#include <random>
#include <climits>

using namespace std;

typedef long long ll;
typedef long double ld;

#define int ll
#define double ld
#define loop(i, n) for(int i = 0; i < (int)n; ++i)
#define loop1(i, n) for(int i = 1; i <= (int)n; ++i)
#define F first
#define S second
#define pb push_back
#define pi pair <int, int>
#define all(x) begin(x), end(x)
#define ti tuple <int, int, int>
#define Point Vect
#define no {cout << "Impossible"; return;}
#define mkp make_pair
#define mkt make_tuple
#define cerr if(0) cerr

const int N = 2e6 + 7, MOD = 1e9 + 7;

int deg25[N] = { 1 }, deg26[N] = { 1 }, f[N] = { 1 }, rf[N] = { 1 };

int binpow(int x, int deg) {
    int ans = 1;
    while (deg) {
        if (deg & 1)
            ans = ans * x % MOD;
        x = x * x % MOD;
        deg >>= 1;
    }
    return ans;
}

int binom(int n, int k) {
    return f[n] * rf[k] % MOD * rf[n - k] % MOD;
}

void solve() {
    loop1(i, N - 1) {
        deg25[i] = deg25[i - 1] * 25 % MOD;
        deg26[i] = deg26[i - 1] * 26 % MOD;
        f[i] = f[i - 1] * i % MOD;
        rf[i] = binpow(f[i], MOD - 2);
    }
    int k, n, ans = 0;
    string s;
    cin >> k >> s;
    n = s.size();
    loop(i, k + 1)
        ans = (ans + deg25[i] * deg26[k - i] % MOD * binom(i + n - 1, n - 1)) % MOD;
    cout << ans;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //int t; cin >> t; loop(i, t)
    solve();
    return 0;
}

Measured memory_bytes: 66768
#!/usr/bin/env python3

def getComb(n, k, MOD):
    if n < k:
        return 0
    if n-k < k:
        k = n-k
    # n!/(n-k)!
    comb = 1
    for x in range(n-k+1, n+1):
        comb = (comb * x) % MOD
    # k!
    d = 1
    for x in range(1, k+1):
        d = (d * x) % MOD
    # n!/((n-k)!*k!)
    comb *= pow(d, MOD-2, MOD)
    return comb % MOD

n,a,b = map(int,input().split())

MOD = 10**9 +7

# nCk (k = 1,...,a-1,a+1,...,b-1,b+1,...,n)

ans = pow(2,n,MOD)
ans -= 1 + getComb(n,a,MOD) + getComb(n,b,MOD)
print(ans % MOD)

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <string>
#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>

using namespace std;

// ---------------------
// repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

// debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

// ---------------------
#define INF 922337203685477580
typedef long long ll;

#define NIL -1

typedef struct {
  int parent, left, right;
} Node;


Node T[100100];
int D[100100];


void depth(int key, int d) {
  if (key == NIL) return;
  for (int right = key; right != NIL; right = T[right].right) {
    D[right] = d;

    depth(T[right].left, d + 1);
  }
}

int main() {
  int n;
  cin >> n;
  // Node T[n + 10];

  REP(i, n + 10) {
    T[i].parent = NIL;
    T[i].left = NIL;
    T[i].right = NIL;
  }

  REP(i, n) {
    int key, num_child;
    cin >> key;
    cin >> num_child;

    int child[num_child];

    FOR(j, 0, num_child) {
      cin >> child[j];
      T[key].left = child[0];
    }

    FOR(j, 0, num_child) {
      T[child[j]].parent = key;

      if (j < num_child - 1) {
        T[child[j]].right = child[j + 1];
      }
    }
  }

  // calc depth
  REP(i, n) {
    if (T[i].parent == NIL) {
      depth(i, 0);
      break;
    }
  }


  REP(i, n) {
    string role;
    if (T[i].parent == NIL) {
      role = "root";
    } else if (T[i].left != NIL) {
      role = "internal node";
    } else {
      role = "leaf";
    }
    cout << "node " << i << ": parent = " << T[i].parent << ", depth = " << D[i] << ", " << role << ", ";

    int j = 0;
    cout << "[";
    for (int child = T[i].left; child != NIL; child = T[child].right) {
      if (j++) cout << ", ";
      cout << child;
    }
    cout << "]" << endl;
  }

  return 0;
}

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

int main()
{
    ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
    cout.setf(ios::fixed); cout.precision(20);
    map<int, int> wrong;
    map<int, int> accepted;

    int N, M; cin >> N >> M; int penalty = 0;
    for (int i = 0; i < M; ++i) {
        int p; string s;
        cin >> p >> s;
        if (accepted.find(p) != accepted.end()) continue;
        if (s == "WA") {
            wrong[p]++;
        } else {
            if (wrong.find(p) != wrong.end()) {
                accepted[p] += wrong[p];
            } else {
                accepted[p] = 0;
            }
            penalty += accepted[p];
        }
    }
    cout << accepted.size() << " " << penalty << endl;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=2e9+7;
const ll longinf=1LL<<62;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=100010;
const ll mod=1e9+7;

int main(){
  int n,k; cin >> n >> k;
  vector<ll> x(n),y(n);
  vector<ll> xx,yy;
  rep(i,n){
    cin >> x[i] >> y[i];
    xx.push_back(x[i]);
    yy.push_back(y[i]);
  }
  sort(xx.begin(),xx.end());
  sort(yy.begin(),yy.end());

  ll ans=longinf;
  rep(i,n)REP(j,i+1,n)rep(l,n)REP(m,l+1,n){
    int cnt=0;
    rep(t,n){
      if(xx[i]<=x[t]&&x[t]<=xx[j]&&yy[l]<=y[t]&&y[t]<=yy[m]){ cnt++; }
    }
    if(cnt>=k)ans=min(ans,(xx[j]-xx[i])*(yy[m]-yy[l]));  
  }
  
  cout << ans << endl;
  return 0;                                                 
}

Measured memory_bytes: 384
X, N = map(int,input().split())
if N == 0:
    print(X)
    exit()
a = list(map(int,input().split()))
cnt = 0
while 1:
  b,c = X-cnt,X+cnt
  if b not in a:
    print(b)
    break
  elif c not in a:
    print(c)
    break
  else:
    cnt += 1
  

Measured memory_bytes: 9204
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
constexpr long double EPS = 1e-15;
const long double PI = acos(-1);
constexpr int inf = 2e9;
constexpr ll INF = 2e18;
constexpr ll MOD = 1e9+7;
constexpr ll MOD1 = 998244353;
typedef pair<ll,ll> P;
//#define all(v) (v).begin(), (v).end()
#define rep(i,a,b) for (int i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)
#define sz(s) (s).size()
#define pb push_back
#define fi first
#define se second
//#define mp make_pair

void solve() {
    int n;
    cin >> n;
    int ans[n];
    for (int i = 0; i < n; i++) {
        int k;
        cin >> k;
        ans[k-1] = i+1;
    }
    REP(i,n) cout << ans[i] << " \n"[i == n - 1];
}

int main(int argc, char *argv[]){
    // /* Regular */
    // int case_num = 1;
    // if (argc > 1 && stoi(argv[1])) cin >> case_num;
    // REP(case_no, case_num) {
    //   cerr << endl << "case " << case_no + 1 << endl;
    //   solve();
    // }
    /* AOJ */
    solve();
    return 0;
}

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

int main() {
  int N,K,t;
  cin >> N >> K;
  for (int i = 0; i < N; i++) {
    int x;
    cin >> x;
    if (x * 2 <= (K - x) * 2) {
      t += x * 2;
    } else if  (x * 2 > (K - x) * 2) {
      t += (K - x) * 2;
    }
  }
  cout << t << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
#include<cstdio>
#include<vector>
#include<queue>
#include<stack>

using namespace std;
typedef long long ll;
#define inf 0x3f3f3f3f
string a, b;
//std::ios::sync_with_stdio(0); std::cin.tie(0);
int main() {
	int i;
	cin >> a;
	cin >> b;
	int n = a.size(), ans = 0;
	for (i = 0; i < n; ++i) {
		if (a[i] != b[i])++ans;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3888
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
 
int main(int argc,char** argv)
{
 
	int A,N,x;
	scanf("%d%d",&N,&A);
	x = N * N - A;
	printf("%d\n", x);
	return(0);
 
}

Measured memory_bytes: 128
/*
[agc027] B - Garbage Collector
*/

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;

const int MAX_N = 200000;
const ll INF = 1e17;

ll N;
ll X;
ll x[MAX_N];
ll s[MAX_N + 1];

ll solve() {
    s[0] = 0;
    for (int i = 1; i <= N; i++) {
        s[i] = s[i - 1] + x[N - i];
    }

    ll ans = INF;
    for (ll m = 1; m <= N; m++) {
        ll sum_e = X * (N + m);
        for (ll d = 0; d <= N / m; d++) {
            ll e = (d == 0) ? 5 : (2 * d + 3);
            sum_e += e * (s[min(N, (d + 1) * m)] - s[d * m]);
            if (sum_e >= ans) {
                break;
            }
        }
        ans = min(ans, sum_e);
    }

    return ans;
}

int main() {
    cin >> N >> X;
    for (int i = 0; i < N; i++) {
        cin >> x[i];
    }

    cout << solve() << endl;

    return 0;
}


Measured memory_bytes: 3328
N,D = map(int,input().split())
li =[]
import math
def dist(a,b):
    li2 = []
    for k in range(D):
        li2.append((a[k]-b[k])**2)
    return math.sqrt(sum(li2))
for _ in range(N):
    X = list(map(int,input().split()))
    li.append(X)
cnt = 0
for i in range(N):
    for j in range(N):
        x = li[i]
        y = li[j]
        dis = dist(x,y)
        if dis == 0:
            pass
        else:
            if dis.is_integer():
                cnt +=1
print(int(cnt/2))

Measured memory_bytes: 3064
import sys
sys.setrecursionlimit(10**8)
input = sys.stdin.readline
N = int(input())

def num2alpha(n):
    ret = chr(n+ord('a')-1)
    if n==0:
        ret = 'z'
    return ret

ans = ['']
while N>0:
    t = N%26
    ans.append(num2alpha(t))
    N //= 26
    if t==0:
        N -= 1
ans.reverse()
ans = ''.join(ans)
print(ans)

Measured memory_bytes: 9192
#include<iostream>
#include <algorithm>

using namespace std;

int n, W, v[110], w[110], dp[110][10010];
int calc() {
	for (int i = n - 1; i >= 0; i--) {
		for (int j = 0; j <= W; j++) {
			if (j < w[i])dp[i][j] = dp[i + 1][j];
			else dp[i][j] = max(dp[i + 1][j], dp[i + 1][j - w[i]] + v[i]);
		}
	}
	return dp[0][W];
}
int main() {
	int ans;
	cin >> n >> W;
	for (int i = 0; i < n; i++) {
		cin >> v[i] >> w[i];
	}
	ans = calc();
	cout << ans << endl;
	return 0;

}

Measured memory_bytes: 6864
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pl;
#define all(a) (a).begin(),(a).end()
#define overload4(_1, _2, _3, _4, name, ...) name
#define rep1(n) for(ll i = 0;i < (n);i++)
#define rep2(i,n) for(ll i = 0;i < (n);i++)
#define rep3(i,a,b) for(ll i = (a);i < (b);i++)
#define rep4(i,a,b,c) for(ll i = (a);i < (b);i += (c))
#define rep(...) overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rrep1(n) for(ll i = (n)-1;i >= 0;i--)
#define rrep2(i,n) for(ll i = (n)-1;i >= 0;i--)
#define rrep3(i,a,b) for(ll i = (a)-1;i >= (b);i--)
#define rrep4(i,a,b,c) for(ll i = (a)-1;i >= (b);i -= (c))
#define rrep(...) overload4(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__)
#define SHOW(x) cout << #x << ": " << x << endl;
template<class T> ll sumArr(const T& a){ return accumulate(all(a), 0LL);}
template<class T> auto minArr(const T& a){ return *min_element(all(a));}
template<class T> auto maxArr(const T& a){ return *max_element(all(a));}
template<class T> void DEBUG_PRINT(T tmp){cout<<tmp<<endl;}
template<class T1,class... T2> void DEBUG_PRINT(T1 tmp,T2... tmp2){cout<<tmp<<" ";DEBUG_PRINT(tmp2...);}
ll gcd(ll a, ll b){ while(b){ ll c = b; b = a % b; a = c; } return a; }
ll lcm(ll a, ll b){ if(!a || !b) return 0; return a / gcd(a, b) * b; }
const ll INF=1e18,MOD = 1e9+7;
const int iINF = 1e9;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    ll ans = INF,x,y;
    cin>>x>>y;
    rep(i,1LL<<2){
        ll cx = x,cy = y,tmp = 0;
        if(i & (1LL << 0)){
            cx *= -1;
            tmp++;
        }
        if(i & (1LL << 1)){
            cy *= -1;
            tmp++;
        }
        if(cy < cx)continue;
        tmp += cy - cx;
        ans = min(ans,tmp);

    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <string>
#include <cstdlib>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cctype>
#include <map>
#include <cstring>
#include <typeinfo>
#include <utility>
#define REP(i,n) for(int i = 0;i < n ;i++)
#define FOR(i,m,n) for(int i= m ;i<n;i++)
using namespace std;

int main(void){
  int w,h,n;
  cin >> w >> h >> n;
  int xr=w,xl=0,yd=0,yu=h;
  vector<int> x(n+1),y(n+1),a(n+1);
  int i;
  for(i=1;i<n+1;i++){
    cin >> x[i] >> y[i] >> a[i];
    if(a[i]==1 && xl<=x[i])xl=x[i];
    else if(a[i]==2 && xr>=x[i])xr=x[i];
    else if(a[i]==3 && yd<=y[i])yd=y[i];
    else if(a[i]==4 && yu>=y[i])yu=y[i];
  }
  int men = (xr-xl)*(yu-yd);
  if((xr-xl)<0 || (yu-yd)<0)cout << 0 <<endl;
  else cout << men << endl;
  return 0;
}


Measured memory_bytes: 256
//Author : Sukarna Paul

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>
#include<ext/pb_ds/detail/standard_policies.hpp>
#define pi acos(-1)
#define pb push_back
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define MAX 300005
#define INF 0x3f3f3f3f
template <class T> inline T bigmod(T p,T e,T M){ll ret = 1LL;for(; e > 0LL; e >>= 1LL){if(e & 1LL) ret = (ret * p) % M;p = (p * p) % M;}return (T)ret;}
template <class T> inline T modinverse(T a,T M){return bigmod(a,M-2,M);}   // M is prime}

using namespace std;
using namespace __gnu_pbds;

typedef trie<string,null_type,trie_string_access_traits<>,pat_trie_tag,trie_prefix_search_node_update>pref_trie;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef tree<pair<int, int>,null_type,less<pair<int, int>>,rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;




int main(){
    IOS
    //freopen("output.txt","w",stdout);
    ll k;
    cin>>k;
    ll L,R;
    cin>>L>>R;
    if(L/k!=R/k || R%k==0 || L%k==0){
        cout<<"OK\n";
    }
    else{
        cout<<"NG\n";
    }
}


Measured memory_bytes: 3652
#include <iostream>

using namespace std;

int main(int argc, char* argv[])
{
    string S; cin >> S;

    int cur = 0, max_length = 0;
    for (int i = 0; i < S.size(); i++) {
        if (S[i] == 'A' || S[i] == 'C' || S[i] == 'G' || S[i] == 'T') {
            cur++;
        } else {
            max_length = max(max_length, cur);
            cur = 0;
        }
    }    

    max_length = max(max_length, cur);
    cout << max_length << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <set>
#include <stdio.h> 
using namespace std;
	typedef long long int lli;
	const int MaxN=200005;
	#define fst first
	#define snd second
	#define mp make_pair
	int mcd(int a,int b){	
		if(a==0)return b;
		return mcd(b%a,a);
	}		
	int mat[4][4];
	int vis[200][200];
	int exist[200];
	pair <int,int> val[200];
	pair <int,int> aux;
int main(){
	lli N,K,i,j,s=0,p,q;
	for(i=1;i<=3;i++){
		for(j=1;j<=3;j++){
			cin>>mat[i][j];
			exist[mat[i][j]]=1;
			val[mat[i][j]]=mp(i,j);
		}
	}	
	cin>>N;	
	while(N--){
		cin>>K;	
		if(!exist[K])continue;
		aux=val[K];
		p=aux.fst,q=aux.snd;
		vis[p][q]=1;
	}
	for(i=1;i<=3;i++){
		s=0;
		for(j=1;j<=3;j++){
			s+=vis[i][j];
		}
		if(s==3){
			cout<<"Yes";
			return 0;
		}
	}
	for(j=1;j<=3;j++){
		s=0;		
		for(i=1;i<=3;i++){
			s+=vis[i][j];
		}		
		if(s==3){
			cout<<"Yes";
			return 0;
		}
	}
	if(vis[1][1]+vis[2][2]+vis[3][3]==3){
		cout<<"Yes";
		return 0;
	}
	if(vis[1][3]+vis[2][2]+vis[3][1]==3){
		cout<<"Yes";
		return 0;
	}
	cout<<"No";
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,k,x,y;
  cin >> n >> k >> x >> y;
  int i,j,sum=0;
  for(i=0;i<min(k,n);i++){
    sum+=x;
  }
  for(j=k;j<n;j++){
    sum+=y;
  }
  cout << sum;
}

Measured memory_bytes: 256
n = int(input())
S = [input() for _ in range(n)]


from collections import Counter
Alphabet = 'abcdefghijklmnopqrstuvwxyz'

A = [51 for _ in range(26)]
C = [[] for _ in range(n)]
for i, s in enumerate(S):
    C[i] = Counter(s)
    for j, a in enumerate(Alphabet):
#        print(A[j])
        A[j] = min([A[j], C[i][a]])
ans = ''
for a, c in zip(Alphabet, A):
    ans += a*c
#    print(a, c, ans)
print(ans)

Measured memory_bytes: 39536
#include<bits/stdc++.h>
using namespace std;
int main(void)
{
  int d;
  cin>>d;
  if(d == 25)
    cout<<"Christmas ";
  if(d == 24)
    cout<<"Christmas Eve ";
  if(d == 23)
    cout<<"Christmas Eve Eve ";
  if(d == 22)
    cout<<"Christmas Eve Eve Eve ";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const ll N=1e7+7;
ll A[N];
vector<ll> v;
void sieve()
{
    for(ll i=3; i<=2000; i+=2)
    {
        for(ll j=i*i; j<=4000000; j+=i)
            A[j]=1;
    }
    v.push_back(2);
    for(ll i=3; i<=4000000; i+=2)
        if(A[i]==0)
            v.push_back(i);
}

int main()
{
    sieve();
   ll a,b,cnt=0;
   cin>>a>>b;
   ll d=__gcd(max(a,b),min(a,b));
   for(ll i=0;v[i]<=sqrt(d);i++)
   {
       if(d%v[i]==0)
       {
           while(d%v[i]==0)
             {
                 d/=v[i];
             }
           cnt++;
       }
   }
   if(d!=1)
   {
       cnt++;
   }
   cout<<cnt+1<<endl;
return 0;
}


//bool is_prime(ll n){
//    if(n==1) return 1;
//for(ll i=2;i*i<=n;i++)
//    if(n%i==0) return 0;
//    return 1;
//}
//
//int main(){
//   ios::sync_with_stdio(0);
//        cin.tie(0);
//        cout.tie(0);
////        map<ll,ll> ma;
//        vector<ll>v1;
//ll a,b;
//cin>>a>>b;
//ll mx=max(a,b);
//for(ll i=1;i*i<=mx;i++){
//    if(a%i==0&&b%i==0)
//        v1.push_back(i);
//}
//ll cnt=0;
//for(ll i=0;i<v1.size();i++){
//if(is_prime(v1[i]))
//    cnt++;
////cout<<v1[i]<<" ";
//}
//
//cout<<cnt;
//
//}









Measured memory_bytes: 38544
#line 2 "/home/toof/working/library/template.hpp"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pl = pair<ll, ll>;
using vl = vector<ll>;
#define rep(i, n) for(ll i = 0; i < (ll)n; i++)
#define rep3(i, l, r) for(ll i = l; i < (ll)r; i++)
#define per(i, n) for(ll i = (ll)n-1; i >= 0; i--)
#define per3(i, l, r) for(ll i = (ll)r-1; i >= (ll)l; i--)
#define all(v) begin(v), end(v)
template<class T, class U> inline void cmax(T &a, U b) { if (a < b) a = b; }
template<class T, class U> inline void cmin(T &a, U b) { if (a > b) a = b; }
constexpr char el = '\n';
template<class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p) { os << p.first << " " << p.second; return os; }
template<class T, class U> istream &operator>>(istream &is, pair<T, U> &p) { is >> p.first >> p.second; return is; }
template<class T> ostream &operator<<(ostream &os, const vector<T> &v) { rep(i, v.size()) os << v[i] << (i+1 != v.size() ? " " : ""); return os; }
template<class T> istream &operator>>(istream &is, vector<T> &v) { for(T &i : v) is >> i; return is; }
struct IoSetup {
  IoSetup() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); cerr << fixed << setprecision(15); }
} io_setup;
#line 2 "a.cpp"

int main() {
  ll d, t, s;
  cin >> d >> t >> s;
  cout << (d <= t*s ? "Yes" : "No") << el;
}


Measured memory_bytes: 3584