akhauriyash/Code-Regression huggingface dataset:
import numpy as np
NABCD = list(map(int,input().split()))
N = NABCD[0]
A = NABCD[1]
B = NABCD[2]
C = NABCD[3]
D = NABCD[4]
S = input()

output = "No"

cous = 0
maxs = 0
cour = 0
maxr = 0
maxi = np.array([])
maxir = np.array([])

for i in range(N):
    p = S[i]
    if p == "#":
        cour += 1
        cous = 0
    elif p == ".":
        cous += 1
        cour = 0
    if cour > maxr:
        maxr = cour
    if cous > maxs:
        maxs = cous
    if cous > 2:
        maxi = np.append(maxi,i+1)
    if cour >= 2:
        maxir = np.append(maxir,i+1)

keysum = sum((maxi-1>=B)*(maxi-1<=D))
outsumA = sum((A<maxir)*(maxir<C))
outsumB = sum((B<maxir)*(maxir<D))
outsum = outsumA + outsumB
if C > D:
    if (maxr < 2)and(maxs >2)and(keysum>0):
        output = "Yes"
    elif (maxr >= 2)and(outsum==0)and(maxs >2)and(keysum>0):
        output = "Yes"
elif D > C:
    if maxr < 2:
        output = "Yes"
    elif (maxr >= 2)and(outsum==0):
        output = "Yes"

print(output)

Measured memory_bytes: 21012
from collections import Counter

n = int(input())
a = list(map(int,input().split()))
q = int(input())
count_map = Counter(a)
res = sum(a)
ans = []
for _ in range(q):
    b, c = map(int, input().split())
    if b not in count_map or count_map[b] == 0:
        ans.append(res)
    else:
        diff = (c-b)*count_map[b]
        count_map[c] += count_map[b]
        count_map[b] = 0
        res += diff
        ans.append(res)
print(*ans, sep='\n')

Measured memory_bytes: 21424
#include<bits/stdc++.h>
using namespace std;
#define sync ios_base::sync_with_stdio(false), cin.tie(NULL)
#define F first
#define S second
#define pb emplace_back
#define mt make_tuple
#define gcd __gcd
#define PI 3.141592653589
// Input
#define in(a) scanf("%d",&a)
#define in2(a,b) scanf("%d%d",&a,&b)
#define in3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define llin(a) cin >> a
#define inl(a) scanf("%lld",&a)
#define read(v,i,n) for(i=0;i<n;i++)in(v[i])
#define twod(mat,i,j,n,m) rep(i,n){rep(j,m)in(mat[i][j]);}
#define sc(ch) scanf("%c",&ch)
#define sstr(str) scanf("%s",str)
// Output
#define pr(a) printf("%d ",a)
#define pr2(a,b) printf("%d %d\n",a,b)
#define pr3(a,b,c) printf("%d %d %d\n",a,b,c)
#define out(a) printf("%d\n",a)
#define outl(a) printf("%lld\n",a)
#define llpr(a) cout << a << " "
#define llout(a) cout << a << "\n"
#define yes printf("YES\n")
#define no printf("NO\n")
#define lin printf("\n")
// Iterator
#define lp(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) for(i=0;i<n;i++)
#define all(vec) vec.begin(),vec.end()
#define lower(v,k) lower_bound(v.begin(),v.end(),k)-v.begin()
#define upper(v,k) upper_bound(v.begin(),v.end(),k)-v.begin()
#define tf(mytuple) get<0>(mytuple)
#define ts(mytuple) get<1>(mytuple)
#define tt(mytuple) get<2>(mytuple)
// Debug
#define dbg(v,i,n) for(i=0;i<n;i++)pr(v[i]); lin
#define what(x) cerr << #x << " : " << x << "\n"
#define ck printf("continue\n")
#define debug(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args)
{
	cerr << *it << " = " << a << "\n";
	err(++it, args...);
}
// Data Type
#define ll long long int
#define ii pair<int,int>
#define pli pair<ll,int>
#define triple tuple<int,int,int>
#define vi vector<int>
#define vii vector<pair<int,int> >
#define vvi vector<vector<int> >
#define viii vector<pair<pair<int,int>,int> >
#define vvii vector<vector<pair<int,int> > >
#define M 998244353
#define N 200005  //check the limits, man
int main()
{
    string str;
    cin >> str;
    if(str[0]=='S')
    {
        if(str[1]=='U')
            out(7);
        else
            out(1);
    }
    else if(str[0]=='T')
    {
        if(str[1]=='U')
            out(5);
        else
            out(3);
    }
    else if(str[0]=='W')
        out(4);
    else if(str[0]=='M')
        out(6);
    else if(str[0]=='F')
        out(2);
}



Measured memory_bytes: 256
#pragma GCC optimize ("Ofast")
#pragma GCC target ("avx2")

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

#define NMAX 200001

int a[NMAX], up[NMAX], bt[NMAX];
int imos[NMAX];

void reset(int n) {
    for(int i = 0; i < n; i++) imos[i] = 0;
}

int get_int() {
    int res = 0;
    char c = getchar();
    while(c != EOF && c != ' ' && c != '\n') {
        res *= 10;
        res += c - '0';
        c = getchar();
    }
    return res;
}

void put_int(int n) {
    char c[30];
    int sz = 0;
    c[sz++] = (n % 10) + '0';
    n /= 10;
    while(n > 0) {
        c[sz++] = (n % 10) + '0';
        n /= 10;
    }
    for(int i = sz-1; i >= 0; i--) {
        putchar(c[i]);
    }
    putchar('\n');
}

int max(int a, int b) { 
    if(a > b) return a;
    else return b;
}

int min(int a, int b) { 
    if(a < b) return a;
    else return b;
}

int main(){

    int n, k;
    n = get_int();
    k = get_int();
    for(int i = 0; i < n; i++) a[i] = get_int();

    for(int itr = 0; itr < k; itr++) {
        reset(n+1);
        for(int i = 0; i < n; i++) {
            bt[i] = max(0, i - a[i]);
            up[i] = min(n, i + a[i] + 1);
        }
        for(int i = 0; i < n; i++){
            imos[bt[i]]++;
            imos[up[i]]--;
        }
        int acc = 0;
        for(int i = 0; i < n; i++){
            acc += imos[i];
            a[i] = acc;
        }
        int sum = 0;
        for(int i = 0; i < n; i++) sum += a[i];
        if(sum == n * n) break;
    }

    for(int i = 0; i < n; i++) put_int(a[i]);
    return 0;
}


Measured memory_bytes: 4836
import java.util.*;

class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n;
		StringBuilder str;
		char c;
		int start, end, len;
		while((n = sc.nextInt()) != 0){
			str = new StringBuilder(256);
			str = str.append(sc.next());
			for(int i = 0; i < n; i++){
				len = str.length();
				c = str.charAt(0);
				start = 0;
				for(int j = 1; j < len; j++){
					if(str.charAt(j) != c){
						str.replace(start, j, Integer.toString(j - start) + c);
						j += str.length() - len;
						len = str.length();
						start = j;
						c = str.charAt(j);
					}
				}
				str.replace(start, len, Integer.toString(len - start) + c);
			}
			System.out.println(str);
		}
	}
}

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

using namespace std;

#define sz(x) (int) x.size()
#define all(a) a.begin(), a.end()

int convert(int h, int m) {
    return h * 60 + m;
}

int main() {

    int h1, m1, h2, m2, need;
    cin >> h1 >> m1 >> h2 >> m2 >> need;

    int tm1 = convert(h1, m1);
    int tm2 = convert(h2, m2);

    cout << (tm2 - tm1 + 1) - need - 1 << endl;

    return 0;
}


Measured memory_bytes: 3636
#include "bits/stdc++.h"
#include <unordered_set>

#define REP(i, n) for(decltype(n) i = 0; i < (n); i++)
#define REP2(i, x, n) for(decltype(x) i = (x); i < (n); i++)
#define REP3(i, x, n) for(decltype(x) i = (x); i <= (n); i++)
#define RREP(i, n) for (decltype(n) i = (n) - 1;i >= 0; i--)

#define ALL(a) (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define DESCSORT(c) sort(c.begin(), c.end(), greater<int>())

#define LL long long int
#define LD long double

#define INF 1000000000
#define PI 3.14159265358979

#define _CRT_SECURE_NO_WARNINGS

using namespace std;

// N, E, S, W
const int dx[4] = { -1, 0,  1,  0 };
const int dy[4] = { 0, 1,  0, -1 };

typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<LL> vll;
//==============================================
int n, q;
vi A;

bool solve(int i, int m) {
	if (m == 0) return true;
	if (i >= n) return false;

	return (solve(i + 1, m) || solve(i + 1, m - A[i]));
}

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

	cin >> n; A.resize(n);
	REP(i, n) cin >> A[i];

	cin >> q;
	int m;
	REP(i, q) {
		cin >> m;
		cout << (solve(0, m) ? "yes" : "no") << "\n";
	}
	return 0;
}

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

string s, t;

int main(void) {
    bool flag = false;
    cin >> s >> t;
    for (int i = s.size() - t.size(); i >= 0; i--) {
        bool pp = false;
        string tmp = s.substr(i, t.size());
        for (int j = 0; j < t.size(); j++) {
            if (tmp[j] == '?') continue;
            else if (tmp[j] != t[j]) {
                pp = true;
                break;
            }
        }
        if (!pp) {
            s = s.erase(i, t.size());
            s.insert(i, t);
            flag = true;
            break;
        }
    }
    for (int i = 0 ; i < s.size(); i++) {
        if (s[i] == '?') s[i] = 'a';
    }

    if (flag) cout << s << endl;
    else cout << "UNRESTORABLE" << endl;
    return 0;
}

Measured memory_bytes: 256
# 全方位DP
import sys
input = lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**6)
from collections import defaultdict, deque
from math import factorial

MOD = 10**9+7
class Facts():
    def __init__(self, max_num=10**5, p=10**9 + 7):
        self.p = p
        self.max_num = max_num
        self.fact = [1] * (self.max_num + 1)
        for i in range(1, self.max_num + 1):
            self.fact[i] = self.fact[i-1] * i
            self.fact[i] %= self.p

    def power_func(self, a, b):
        ans = 1
        while b > 0:
            if b & 1:
                ans = ans * a % self.p
            a = a * a % self.p
            b >>= 1
        return ans

    def fact_inv(self, a):
        return self.power_func(a, self.p-2) % self.p

n = int(input())
fact = Facts(max_num=200000)
edges = defaultdict(lambda: [])

for _ in range(n-1):
    a, b = map(int, input().split())
    edges[a].append(b)
    edges[b].append(a)

# step1 吸い上げ
size = [1 for _ in range(n+1)]
def dfs1(num, par=-1):
    res = 1
    for node in edges[num]:
        if node == par:
            continue
        else:
            res += dfs1(node, num)
    res %= MOD
    size[num] = res
    return res
dfs1(1)
# print(size)
dp = [0 for _ in range(n+1)]
def dfs2(n, par=-1):
    res = fact.fact[size[n] - 1]
    for node in edges[n]:
        if node == par:
            continue
        else:
            res *= dfs2(node, n) * fact.fact_inv(fact.fact[size[node]])
    res %= MOD
    dp[n] = res
    return res
dfs2(1)
# print(dp)

# step2 還元
ans = [0 for _ in range(n+1)]
inv_1 = fact.fact_inv(fact.fact[n-1])
def dfs3(num, par=-1):
    if par != -1:
        res = dp[num] * fact.fact_inv(fact.fact[size[num] - 1]) * \
            fact.fact[n-1] * ans[par] * inv_1 * \
            fact.fact[n-size[num]-1] * fact.fact[size[num]] * \
            fact.fact_inv(dp[num]) * \
            fact.fact_inv(fact.fact[n-size[num]]) % MOD
        ans[num] = res
    else:
        ans[num] = dp[num]
    for node in edges[num]:
        if node == par:
            continue
        dfs3(node, num)
dfs3(1)
print("\n".join(list(map(str, ans[1:]))))


Measured memory_bytes: 160840
#include <stdio.h>

int main (void) {
  int a,b;
  scanf("%d %d", &a, &b);

  int x, y, z;
  x = a % 3;
  y = b % 3;
  z = (a + b) %3;

  if (x == 0 || y == 0 || z == 0) {
        puts("Possible");
  } else {
        puts("Impossible");
  }

  return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
const int N=100010;
struct node{
	int to;
}sq[2*N];
int n,m,all=0,nxt[2*N],head[N],d[N];
vector<int> four;

int read()
{
	int x=0,f=1;char ch=getchar();
	while ((ch<'0') || (ch>'9')) {if (ch=='-') f=-1;ch=getchar();}
	while ((ch>='0') && (ch<='9')) {x=x*10+(ch-'0');ch=getchar();}
	return x*f;
}

void add(int u,int v)
{
	all++;sq[all].to=v;nxt[all]=head[u];head[u]=all;
}

bool dfs(int u,int fa,int from,int to)
{
	if (u==from) return 0;
	if (u==to) return 1;
	int i;
	for (i=head[u];i;i=nxt[i])
	{
		int v=sq[i].to;
		if (fa==v) continue;
		return dfs(v,u,from,to);
	}
	return 0;
}

int main()
{
	n=read();m=read();
	int i;
	for (i=1;i<=m;i++)
	{
		int u=read(),v=read();
		add(u,v);add(v,u);
		d[u]++;d[v]++;
	}
	bool six=0;
	for (i=1;i<=n;i++)
	{
		if (d[i]&1) {printf("No");return 0;}
		else if (d[i]>=6) six=1;
		else if (d[i]==4) four.push_back(i);
	}
	if ((six) || (four.size()>=3)) {printf("Yes");return 0;}
	if (four.size()<2) {printf("No");return 0;}
	int from=four[0],to=four[1],cnt=0;
	for (i=head[from];i;i=nxt[i])
		if (dfs(sq[i].to,from,from,to)) cnt++;
	if (cnt==2) printf("Yes");else printf("No");
	return 0;
}


/*#include<bits/stdc++.h>
using namespace std;
#define N 100010
typedef long long ll;
int cnt;
struct node
{
    int to;
}p[2*N];
int nxt[2*N],head[N],d[N];
vector<int>d4;
void add(int u,int v)
{
    cnt++;
    p[cnt].to=v;
    nxt[cnt]=head[u];
    head[u]=cnt;
}
int dfs(int x,int fa,int st,int ed)
{
    if(x==st)return 0;
    if(x==ed)return 1;
    for(int i=head[x];i;i=nxt[i])
    {
        if(p[i].to==fa )continue;
        dfs(p[i].to,x,st,ed);
    }
    return 0;
}
int main()
{
    int n,m,x,y;
    scanf("%d%d",&n,&m);
    for(int i=1;i<=m;i++)
    {
        scanf("%d%d",&x,&y);
        add(x,y),add(y,x);
        d[x]++,d[y]++;
    }
    int flag=0;
    for(int i=1;i<=n;i++)
    {
        if(d[i]&1){printf("No\n");return 0;}
        if(d[i]>=6)flag=1;
        if(d[i]==4)d4.push_back(i);
    }
    if(flag || d4.size()>=3)
        {printf("Yes\n");return 0;}
    if(d4.size()<2)
    { printf("No\n");return 0;}

    int num=0,st=d4[0],ed=d4[1];
    for(int i=head[st];i;i=nxt[i])
        if(dfs(p[i].to,st,st,ed))
                num++;
    if(num==2)
        printf("Yes\n");
    else
        printf("No\n");
}
*/


Measured memory_bytes: 2560
#define _CRT_SECURE_NO_WARNINGS
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<functional>
#include<iomanip>
#include<iostream>
#include<list>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<utility>
#include<vector>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define FORR(i,a,b) for(int i=(a);i>=(b);--i)
#define REPR(i,n)   FORR(i,n,0)

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

int main() {
	int N, M, p[100000], x, y, comp[100000] = { 0 };
	

	cin >> N >> M;
	vector<vector<int>> edge(N);
	REP(i, N) {
		cin >> p[i];
	}REP(i, M) {
		cin >> x >> y;
		edge[x - 1].push_back(y - 1);
		edge[y - 1].push_back(x - 1);
	}


	int k = 1;
	REP(i, N) {
		if (comp[i] == 0) {
			stack<int> s;
			s.push(i);
			comp[i] = k;
			while (!s.empty()) {
				int u = s.top();
				s.pop();
				for (auto itr = edge[u].begin();itr < edge[u].end();++itr) {
					if (comp[*itr] == 0) {
						s.push(*itr);
						comp[*itr] = k;
					}
				}
			}
			k++;
		}
	}

	int ans = 0;
	REP(i, N) {
		if (comp[i] == comp[p[i] - 1]) {
			ans++;
		}
	}
	
	cout << ans << endl;



	return 0;
}

Measured memory_bytes: 6528
// ------------------------------------
// Date:2018/ 3/ 7
// Problem:ABC 078 HSI c.cpp
//
// ------------------------------------

#include <bits/stdc++.h>

using namespace std;

#define EACH(i,a) for (auto&& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define debug(x) cerr << #x << ":" << x << endl

typedef long long ll;

static const int MOD = 1000000007;

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

  int N, M;
  cin >> N >> M;
  
  ll tmp1 = 1900 * M + (N - M) * 100;

  ll tmp2 = 1;
  ll n = 2;
  while (M > 0) {
    if (M & 1) {
      tmp2 = tmp2 * n;
    }
    n *= n;
    M >>= 1;
  }
  ll ans = tmp1 * tmp2;
  cout << ans << endl;
  
  return 0;
}



Measured memory_bytes: 256
#include<vector>
#include<algorithm>
#include<set>
#include<iostream>

using namespace std;

const int MX = 100005;

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

int D[MX];
int N, M;

int main()
{
	scanf("%d%d", &N, &M);
	if( N == 1 ) return !printf("1\n1\n1\n");
	if( M == 1 ) return !printf("%d\n2\n%d 1\n", N, N-1);
	if( N == 2 ) return !printf("1 1\n1\n2\n", N);
	
	int tot = N/2;
	for(int i = 1; i <= M; i++) scanf("%d", D+i), tot += D[i]/2;
	if( tot < N-1 ) return !printf("Impossible\n");
	else{
		int a = -1, b = -1;
		for(int i = 1; i <= M; i++){
			if( D[i]%2 == 1 && a == -1 ) a = i;
			else if( D[i]%2 == 1 ) b = i;
		}
		if( a != -1 ) swap(D[1], D[a]);
		if( b != -1 ) swap(D[M], D[b]);
		for(int i = 1; i <= M; i++) printf("%d ", D[i]);
		printf("\n");
		if( D[M] == 1 ){
			printf("%d\n", M-1);
			printf("%d ", D[1]+1);
			for(int i = 2; i <= M-2; i++) printf("%d ", D[i]);
			printf("%d\n", D[M-1]);
		}
		else{
			printf("%d\n", M);
			printf("%d ", D[1]+1);
			for(int i = 2; i <= M-1; i++) printf("%d ", D[i]);
			printf("%d\n", D[M]-1);
		}
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using msi = map<string, int>;
using mii = map<int, int>;
using psi = pair<string, int>;
using pii = pair<int, int>;
using vlai = valarray<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF (ll)1E9
#define EPS 1E-9
#define MOD 1000000007
#define PI 3.1415926535897932384

template <class T>ostream &operator<<(std::ostream &o, const vector<T> &v)
{
	rep(i, v.size()) {
		o << (i > 0 ? " " : "") << v[i];
	}
	return o;
}

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

//constexpr ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }


int main(void) {
	int n, m;
	ll ans = 0, in;
	cin >> n >> m;
	vector<ll> a(n), b(n), c(n);
	rep(i, n) {
		cin >> a[i] >> b[i] >> c[i];
	}
	rep(i, 8) {
		ll tmpans = 0;
		int x, y, z;
		vector<ll> tmp(n);
		x = (i & 4 ? 1 : -1);
		y = (i & 2 ? 1 : -1);
		z = (i & 1 ? 1 : -1);
		rep(j, n) {
			tmp[j] = a[j] * x + b[j] * y + c[j] * z;
		}
		sort(all(tmp), greater<ll>());
		rep(j, m) {
			tmpans += tmp[j];
		}
		ans = max(ans, tmpans);
	}
	cout << ans << endl;
}



Measured memory_bytes: 256
from math import ceil
N, H = map(int, input().split())
Throw = []
A_max = 0
for i in range(N):
    a, b = map(int, input().split())
    A_max = max(A_max, a)
    Throw.append(b)


Throw = sorted([t for t in Throw if t > A_max])


ans = 0
while H > 0 and Throw:
    H -= Throw.pop()
    ans += 1

if H <= 0:
    print(ans)
else:
    print(ans + ceil(H / A_max))


Measured memory_bytes: 9056
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pi M_PI
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1000000007,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

void Main() {
  int n;
  R n;
  P a[n];
  rep(i,n) cin >> a[i].F >> a[i].S;
  string s[4];
  rep(i,4) R s[i];
  int dp[1<<16];
  rep(i,1<<16) dp[i]=MAX;
  dp[0]=0;
  rep(t,1<<16) {
    if(dp[t]==MAX) continue;
    rep(k,n)REP(l,-a[k].F+1,4)REP(r,-a[k].S+1,4) {
      int z=0,e=0;
      REP(x,max(0,l),min(4,l+a[k].F)) {
        REP(y,max(0,r),min(4,r+a[k].S)) {
          z|=1<<(x*4+y);
          if(!(t&(1<<x*4+y))) {
            if(s[x][y]=='R') e|=1<<0;
            if(s[x][y]=='G') e|=1<<1;
            if(s[x][y]=='B') e|=1<<2;
          }
          if(!(e==0||e==1||e==2||e==4)) goto next;
        }
      }
      if(e==1||e==2||e==4) dp[t|z]=min(dp[t|z],dp[t]+1);
    next:;
    }
  }
  pr(dp[(1<<16)-1]);
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


Measured memory_bytes: 3488
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
    vector<string> s(2);
    for(int i = 0; i < 2; i++){
        cin >> s[i];
    }
    if(s[0][0] != s[1][2] || s[0][1] != s[1][1] || s[0][2] != s[1][0]){
        cout << "NO\n";
    }
    else        cout << "YES\n";
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>

using namespace std;
using llong = long long;
using ullong = unsigned long long;

int main() {
  int A,B;
  std::cin >> A >> B;
  if( A <= 5 ) {
    std::cout << 0 << std::endl;
  } else if( A >= 13 ) {
    std::cout << B << std::endl;
  } else {
    std::cout << B / 2 << std::endl;
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define MAXN 100005
#define INF 1000000000
#define MOD 1000000007
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int N,L,a[MAXN];
int main()
{
    scanf("%d%d",&N,&L);
    for(int i=1;i<=N;i++) scanf("%d",&a[i]);
    int id=-1;
    for(int i=1;i<=N-1;i++)
    {
        if(a[i]+a[i+1]>=L)
        {
            id=i;
            break;
        }
    }
    if(id==-1) {puts("Impossible"); return 0;}
    puts("Possible");
    for(int i=1;i<id;i++) printf("%d\n",i);
    for(int i=N-1;i>=id+1;i--) printf("%d\n",i);
    printf("%d\n",id);
    return 0;
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MOD = 1000000007;

signed main() {
int n;
cin>>n;
pair<int,int> p[n],q[n];
int l,r;
pair<int,pair<int,int>> t[n];
for(int i=0;i<n;i++){
  cin>>l>>r;
  p[i]=make_pair(r,l);
  q[i]=make_pair(l,r);
  t[i]=make_pair(r-l,make_pair(l,r));
}
sort(p,p+n);sort(q,q+n);sort(t,t+n);
int mxl=q[n-1].first,mxr=q[n-1].second,mil=p[0].second;int ans1=p[1].first-mil;
for(int i=0;p[i].first<mxr;i++){
  mil=max(mil,p[i].second);
  ans1=max(ans1,p[i+1].first-mil);
  cerr<<ans1<<endl;
}
int ans2,x=0,y=0;
vector<int> tt;
for(int i=0;i<n;i++){
  if(x==0&&mxl==t[i].second.first){
    x=1;
    continue;
  }
  if(y==0&&p[0].first==t[i].second.second){
    y=1;
    continue;
  }
  tt.push_back(t[i].first);
}
//cerr<<ans1<<' '<<ans1+1-q[n-1].first+p[0].first+1<<' '<<tt[tt.size()-1]+1+max(0LL,p[0].first-mxl+1)<<' '<<t[n-1].first+1<<endl;
if(tt.size()==0){
  cout<<max(ans1+1-q[n-1].first+p[0].first+1,t[n-1].first+1);
  return 0;
}
cout<<max(ans1+1-q[n-1].first+p[0].first+1,max(tt[tt.size()-1]+1+max(0LL,p[0].first-mxl+1),t[n-1].first+1));






return 0;
}


Measured memory_bytes: 7808
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define setbits(x) __builtin_popcount(x)
#define setbitsll(x) __builtin_popcountll(x)
#define endl '\n'
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define se second
#define fi first
#define pai acos(-1)
#define fn(i,x) for(i=0;i<x;i++)
#define fs(i,s,x) for(i=s;i<x;i++)
#define fr(i,x,s) for(i=x;i>=s;i--)
#define fit(itr,s) for(itr=s.begin();itr!=s.end();itr++)
#define W while
#define pp pair<ll,ll>
#define ppi pair<int,int>
#define vl vector<ll>
#define vll vector<pp >
#define vi vector<int>
#define vii vector<ppi>
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define debug(x) cerr<<#x<<" :: "<<x<<endl;
#define debug2(x,y) cerr<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<endl;
#define debug3(x,y,z) cerr<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<endl;
#define debug4(x,y,z,w) cerr<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\t"<<#w<<" :: "<<w<<endl;
#define boost  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
const ll MAX=1e16;
const ll MM=1e18;
const ll mod=1e9+7;
int dx[]={-1,0,1,0};
int dy[]={0,1,0,-1};
ll expo(ll x,ll n,ll M=mod)
{
    ll ans=1;
    while(n>0)
    {
        if(n&1){ans=(ans*x)%M;}
                x=(x*x)%M;
                n>>=1;
    }
    return ans;
}

vl adj[200001];
void solve()
{
   /*ll n,m,x;
   cin>>n>>m>>x;
   ll a[n][m];
   ll c[n];
   fn(i,n)
   {
       cin>>c[i]
       fn(j,m)
       cin>>a[i][j];
   }*/
   ll n,k,i;
   cin>>n>>k;
   vl a(n);
   fn(i,n){cin>>a[i];a[i]--;}
   ll in=0;
   set<ll> st;
   st.insert(0);
   W(k)
   {
       //debug2(in,k);
       in=a[in];
       if(st.count(in) || in==a[i])
        break;
        k--;
       st.insert(in);
   }
   if(k==0)
    cout<<in+1<<endl;
   else{
   ll start=in;
   in=a[in];
   //debug2(start,in);
   vl temp;
   temp.pb(start);
   W(in!=start)
   {
       temp.pb(in);
       in=a[in];
   }
   ll len=temp.size();
   //debug(len);
   k=k%len;
   //debug(k);
   if(k==0)k=len;
   cout<<temp[k-1]+1<<endl;
   }

}


int main()
{
  boost;
  int t=1;
  //cin>>t;
  while(t--)
  {
      solve();
  }
}


Measured memory_bytes: 19044
#include <iostream>
#include <vector>
#include <iomanip>
#include <algorithm>
using namespace std;
using ll = long long;

const int MOD = 1e9 + 7;

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

    vector<int> digit;

    while(true) {
        digit.push_back(n % 26);
        n = (n - 1) / 26;
        if(n == 0) break;
    }

    reverse(digit.begin(), digit.end());
    
    /*
    for(int x : digit) {
        cout << x << ' ';
    }
    cout << endl;
    */

    for(int x : digit) {
        if(x == 0) cout << 'z';
        else cout << (char) ('a' + x - 1);
    }
    cout << endl;


    return 0;
}

Measured memory_bytes: 3572
import java.util.*;

public class Main{
    public static void main(String[]args){
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int total=0;
        for(int i=0;i<n;i++){
            total+=Math.abs(sc.nextInt()-sc.nextInt())+1;
        }
        System.out.println(total);

    }
}

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

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

  if (a % 2 == 0 || b % 2 == 0) {
    cout << "Even" << endl;
  }
  else{
    cout << "Odd" << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define VIEW(x) do {cerr << #x << ": "; for(auto i : x) cerr << i << " "; cerr << endl;} while(0)
#define ALL(x) (x).begin(),(x).end()

signed main() {
  int n,k; cin >> n >>k;
  vector<int> a(n);
  rep(i,n) cin >> a[i];

  auto ok = [&](int x) {
    int kk = k;
    rep(i,n) kk -= (a[i] + x-1) / x - 1;
    return kk >= 0;
  };

  int l = 1, r = *max_element(ALL(a));
  while(r-l>1) {
    int m = l + (r-l) / 2;
    if(ok(m)) r = m;
    else l = m;
  }
  if(ok(l)) r = l;
  cout << r << endl;
}


Measured memory_bytes: 3852
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define all(x) (x).begin(),(x).end()

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

typedef long long ll;

using namespace std;

int n,m;
vector<vector<int>> edge;
int cnt1=0,cnt2=0;
vector<int>memo;
bool flag=0;
void dfs(int par,int node,bool oe)
{
  if(flag)return;
  if(memo[node]!=-1)
  {
    if(oe!=memo[node]){flag=1;return ;}
    else return ;
  }
  if(oe)cnt1++;
  else cnt2++;
  memo[node]=(int)oe;
  for(int nn:edge[node])
  {
    if(nn!=par)
    {
      dfs(node,nn,!oe);
    }
  }
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin>>n>>m;
  edge.resize(n+1);
  memo=vector<int>(n+1,-1);
  rep(i,m)
  {
    int a,b;
    cin>>a>>b;
    edge[a].push_back(b);
    edge[b].push_back(a);
  }
  dfs(-1,1,0);
  if(flag==0)
  {
    ll res=(ll)cnt1*cnt2;
    res-=m;
    cout<<res<<endl;
  }
  else
  {
    ll res=((ll)n*(n-1))/2;
    res-=m;
    cout<<res<<endl;
  }
  return 0;

}


Measured memory_bytes: 6528
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define inf 1e9
#define mod 1000000007
#define ff first
#define ss second

int arr[200010];

bool valid(int mid, int n, int k)
{
	int cnt = 0;
	for (int i = 0; i < n; i++)
	{
		cnt += (arr[i] + mid - 1) / mid - 1;
	}
	return (cnt <= k);
}

void solve()
{
	int n, k;
	cin >> n >> k;
	for (int i = 0; i < n; i++)
	{
		cin >> arr[i];
	}
	int low = 1, high = *max_element(arr, arr + n);
	int ans = high;
	while (low <= high)
	{
		int mid = (high + low) / 2;
		if (valid(mid, n, k))
		{
			ans = mid;
			high = mid - 1;
		}
		else
		{
			low = mid + 1;
		}
	}
	cout << ans << "\n";
}

signed main()
{
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	solve();
	return 0;
}


Measured memory_bytes: 5096
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static string InputPattern = "InputX";

    static List<string> GetInputList()
    {
        var WillReturn = new List<string>();

        string wkStr;
        while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
        return WillReturn;
    }

    static void Main()
    {
        List<string> InputList = GetInputList();

        int[] wkArr = { };
        Action<string> SplitAct = pStr =>
            wkArr = pStr.Split(' ').Select(X => int.Parse(X)).ToArray();

        SplitAct(InputList[1]);
        int[] AArr = wkArr;
        int UB = AArr.GetUpperBound(0);

        SplitAct(InputList[2]);
        int[] BArr = wkArr;

        SplitAct(InputList[3]);
        int[] CArr = wkArr;

        Array.Sort(AArr);
        Array.Sort(BArr);
        Array.Sort(CArr);

        //尺取法で、自分未満な配列Aの要素数[配列Bの添字]を求める
        int[] LowerCntArrA = new int[UB + 1];
        int J = 0;
        for (int I = 0; I <= UB; I++) {
            while (J <= UB && BArr[I] > AArr[J]) J++;
            LowerCntArrA[I] = J;
        }

        //尺取法で、自分以下な配列Cの要素数[配列Bの添字]を求める
        int[] LowerCntArrC = new int[UB + 1];
        J = 0;
        for (int I = 0; I <= UB; I++) {
            while (J <= UB && BArr[I] >= CArr[J]) J++;
            LowerCntArrC[I] = J;
        }

        long Answer = 0;
        for (int I = 0; I <= UB; I++) {
            Answer += (long)LowerCntArrA[I] * (CArr.Length - LowerCntArrC[I]);
        }
        Console.WriteLine(Answer);
    }
}


Measured memory_bytes: 45340
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define mod 1000000007
#define MAX 1000000000000000
#define all(v) v.begin(),v.end()
#define rep(i,a,b) for(i=(ll)a;i<(ll)b;i++)
#define revrep(i,a,b) for(i=(ll)a;i>=(ll)b;i--)
#define ii pair<ll,ll>
#define MP make_pair
#define pb push_back
#define f first
#define se second
#define ll long long int
#define vi vector<ii>
ll modexp(ll a,ll b){ ll res = 1; while(b > 0){  if(b & 1) res = (res * a)%mod;  a = (a * a)%mod;  b/=2;  }  return res; }
#define rs resize
typedef tree< ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update > OST;
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << endl;
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define trace(...)
#endif

const ll N = 1e5 + 2;
ll i,n,k,j,ans;
vi v;
string s;
ll en[N], st[N];
int main()
{
    std::ios_base::sync_with_stdio(false); cin.tie(NULL);
    cin>>n>>k>>s;
    s = "$" + s;
    
    rep(i,1,n + 1) if(s[i] == '1'){
        en[i] = en[i - 1] + 1;
        ans = max(ans, en[i]);
    }
    
    revrep(i,n,1) if(s[i] == '1')
        st[i] = st[i + 1] + 1;
    
    v.emplace_back(-1, -1);
    rep(i,1,n + 1){
        j = i;
        while(j <= n && s[i] == s[j]) j += 1;
        if(s[i] == '0')
            v.emplace_back(i, j - 1);
        i = j - 1;
    }
    
    rep(i,1,v.size()){
        j = max(1LL,i - k + 1);
        ans = max(ans, en[v[j].f - 1] + v[i].se - v[j].f + 1 + st[v[i].se + 1]);
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 3064
def digitSum(n):
    # 数値を文字列に変換
    s = str(n)
    # １文字ずつ数値化し配列にする。
    array = list(map(int, s))
    # 合計値を返す
    return sum(array)

n, a, b = map(int, input().split())
r = 0
for i in range(n + 1):
    if a <= digitSum(str(i)) <= b:
        r += i
print(r)

Measured memory_bytes: 3060
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
using namespace std;
 
//#define int ll
 
typedef int64_t ll;
//static const int MOD = 1000000007;
static const int INF = 2147483647;
//static const long long INF = 9223372000000000000;
//static const long long INF = 9223372000000000000/2;
//static const int INF = 1000010000;
//int dx4[4] = {0,0,1,-1}, dy4[4] = {1,-1,0,0};
//int dx5[5] = {-1,0,0,0,1}, dy5[5] = {0,-1,0,1,0};
//int dx8[8] = {-1,0,1,1,1,0,-1,-1}, dy8[8] = {1,1,1,0,-1,-1,-1,0};
//int dx9[9] = {-1,0,1,1,1,0,-1,-1,0}, dy9[9] = {1,1,1,0,-1,-1,-1,0,0};
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define FI first
#define SE second
#define NP next_permutation
#define PQ priority_queue
#define UB upper_bound
#define LB lower_bound
#define SZ(a) signed((a).size())
#define LEN(a) signed((a).length())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).begin(),(c).end());reverse((c).begin(),(c).end());
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REP1(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREP1(i,x) for(int i=((int)(x));i>0;i--)
#define ALL(x) (x).begin(),(x).end()
#define YESNO(x) puts((x)?"YES":"NO")
#define YesNo(x) puts((x)?"Yes":"No")

signed main(){
    int a[3]={};
    string s;
    cin >> s;
    REP(i,3) a[s[i]-'a']++;
    YesNo(a[0]==1&&a[1]==1&&a[2]==1);
}















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

#define REP(i, n) for ( int i = 0; i < (n); i++ )

int main() {

    int h, w;

    for ( ;; ) {

        std::cin >> h >> w;

        if ( h == 0 && w == 0 ) break;

        REP(i, h) {

            REP(j, w) {

                i == 0 || i == h - 1 || j == 0 || j == w - 1
                ? std::cout << "#"
                : std::cout << "." ;
            }

            std::cout << std::endl;
        }

        std::cout << std::endl;

    }

    return 0;

}



Measured memory_bytes: 3056
#include<iostream>
#include<math.h>

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i, x, n) for (int i = x; i < (n); ++i)
using namespace std;

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

    int T, A;
    cin >> T >> A;

    int H[1100];
    rep(i, N) cin >> H[i];

    // 標高ごとの平均気温
    int mt[1100];
    rep(i, N) mt[i] = 1000 * T - H[i] * 6;

    int min_diff = 10000000; // 最小の差
    int min_diff_index = 0; // 差が最小となる地点のインデックス
    rep(i, N) {
        int diff = abs(1000 * A - mt[i]);
        if (diff < min_diff) {
            min_diff = diff;
            min_diff_index = i + 1;
        }
    }

    cout << min_diff_index << endl;
    return 0;
}


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

int main() {
  int n,m,sm = 0,mx = 0;

  cin >> n >> m;
  vector<int> a;

  for ( int i=0 ; i < n ; ++i ) {
    int x;
    cin >> x;
    a.push_back(x);
    sm += a[i];
  }
  sort(a.begin(),a.end(),greater<int>());
  if (a[m-1]*4*m < sm){
    cout << "No" << endl;  
  } else{
    cout << "Yes" << endl;  
  }
}

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

namespace abc070_b
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
            Console.WriteLine(Math.Max(0, Math.Min(x[1], x[3]) - Math.Max(x[0], x[2])));
        }
    }
}

Measured memory_bytes: 13268
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
using namespace std;
int main() {
  string s,t;
  cin >> s >> t;
  int N = s.size();
  bool flag = false;
  for (int i=0; i<N; i++) {
    string nexts = s.substr(i,N-i) + s.substr(0,i);
    if (nexts == t) {
      flag = true;
      break;
    }
  }
  if (flag) cout << "Yes" << endl;
  else cout << "No" << endl;
}
  

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <limits.h>
#include <math.h>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>

using namespace std;

int main(int argc, char* argv[]){
  int N;
  long long x;
  cin >> N >> x;
  
  long long *a = new long long[N];

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

  long long count = 0;
  for(int i=0; i<N-1; i++){
    if(a[i]+a[i+1] > x){
      long long tmp = a[i] + a[i+1] - x;
      count += tmp;
      if(a[i+1] >= tmp){
	a[i+1] -= tmp;
      }
      else{
	a[i+1] = 0;
      }
    }
  }

  cout << count << endl;
  delete[] a;
  return 0;
}



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

#define fi first
#define se second
const int N = 100100;
using namespace std;
int n;int x[N];int y[N];int r[N];bool used[N];
long double d[N];
long double dist(int i, int j){
        long double e = 1ll * (x[i] - x[j]) * (x[i] - x[j]) + 1ll * (y[i] - y[j]) * (y[i] - y[j]);
        return max((long double)0, sqrt(e) - r[i] - r[j]);
}

int main(){
        ios_base::sync_with_stdio(0);

        //freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);

        cin >> x[1] >> y[1] >> x[2] >> y[2];
        cin >> n;
        n += 2;
        for(int i = 3; i <= n; i++){
                cin >> x[i] >> y[i] >> r[i];
        }
        long double inf = (long double)(1e18);
        for(int i = 2; i <= n; i++){
                d[i] = inf;
        }
        for(int i = 1; i <= n; i++){
                int h = -1;
                for(int j = 1; j <= n; j++){
                        if(used[j]){
                                continue;
                        } else if(h == -1 || d[j] < d[h]){
                                h = j;
                        }
                }
                used[h] = 1;
                for(int j = 1; j <= n; j++){
                        d[j] = min(d[j], d[h] + dist(h, j));
                }
        }
        cout << fixed << setprecision(9) << d[2] << "\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <random>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repp(i,n,m) for (int i = m; i < (n); ++i)
#define repl(i,n) for (long long i = 0; i < (n); ++i)
#define reppl(i,n,m) for (long long i = m; i < (n); ++i)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PL = pair<long long, long long>;
using Pxy = pair<double, double>;
using T = tuple<int, int, bool>;
const int INF = 1001001007;
const int mod = 1000000007;
const int MOD = 998244353;
const ll inf = 1e18;
template <typename AT>
void printvec(vector<AT> &ar){
    rep(i,ar.size()-1) cout << ar[i] << " ";
    cout << ar[ar.size()-1] << endl;
}
template <typename Q>
void printvvec(vector<vector<Q>> &ar){
    rep(i,ar.size()){
        rep(j,ar[0].size()-1) cout << ar[i][j] << " ";
        cout << ar[i][ar[0].size()-1] << endl;
    }
}
template <typename S>
bool range(S a, S b, S x){
    return (a <= x && x < b);
}

void yes(){
    cout << "Yes" << endl;
}

void no (){
    cout << "No" << endl;
}

ll cel (ll a, ll b){
    if (a % b == 0) return a / b;
    else return a / b + 1;
}

ll gcds(ll a, ll b){
    ll c = a % b;
    while (c != 0){
        a = b;
        b = c;
        c = a % b;
    }
    return b;
}

int main() {
    string s; cin >> s;
    string m = s.substr(5,2);
    string d = s.substr(8,2);
    int a = stoi(m);
    int b = stoi(d);
    if (P(a,b) <= P(4,30)) cout << "Heisei" << endl;
    else cout << "TBD" << endl;
}

Measured memory_bytes: 3612
import java.util.*;
import java.math.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int[] A = new int[N];
    for (int i = 0; i < N; i++) A[i] = sc.nextInt();
    sc.close();

    Set<Integer> set = new HashSet<>(N);
    for (int i = 0; i < N; i++) set.add(A[i]);

    String ans = set.size() == N ? "YES" : "NO";
    System.out.println(ans);
  }
}


Measured memory_bytes: 70896
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#define all(a) a.begin(),a.end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef long double ld;
typedef complex<ld> com;
constexpr int inf = 1000000000;
constexpr ll INF = 1000000000000000000;
constexpr ld EPS = 1e-12;
constexpr ld PI = 3.141592653589793238;
template<class T, class U> inline bool chmax(T &a, const U &b) { if (a < b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if (a > b) { a = b; return true; } return false; }


signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(20);

	int n;
	cin >> n;
	vector<P> a(n);
	rep(i, n) {
		cin >> a[i].first;
		a[i].second = i;
	}
	vector<ll> ans(n);
	sort(all(a));
	reverse(all(a));
	a.pb(P(0, -1));
	set<int> st;
	rep(i, n) {
		st.insert(a[i].second);
		int fr = *st.begin();
		ans[fr] += (a[i].first - a[i + 1].first)*(i + 1);
	}
	for (ll i : ans) cout << i << '\n';
}

Measured memory_bytes: 9188
#include<stdio.h>
#include<cmath>
using namespace std;
int main(){
    int n=0;
    int x[100]={},y[100]={};
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d",&x[i]);
    }
    for(int i=0;i<n;i++){
        scanf("%d",&y[i]);
    }
    double dif[100]={},sum1=0,sum2=0,sum3=0,max=0;
    for(int i=0;i<n;i++){
        dif[i]=abs(x[i]-y[i]);
        sum1+=dif[i];
        sum2+=dif[i]*dif[i];
        sum3+=dif[i]*dif[i]*dif[i];
        if(max<dif[i]){
            max=dif[i];
        }
    }
    double p1=sum1,p2=sqrt(sum2),p3=cbrt(sum3),pifn=max;
    printf("%.5f\n%.5f\n%.5f\n%.5f\n",p1,p2,p3,pifn);
}


Measured memory_bytes: 2936
#include<iostream>
#define Number 1299710
using namespace std;

int table[Number]={0,0};

int main(){
  int n;
  for(int i=2;i<Number;i++)
    table[i]=1;
  for(int i=2;i<Number;i++){
    if(table[i]){
      for(int j=i+i;j<Number;j+=i){
	table[j]=0;
      }
    }
  }
  while(cin>>n,n){
    if(table[n]){
      cout<<0<<endl;
    }else{
      int lower=n;
      int higher=n;
      while(!table[--lower])
	;
      while(!table[++higher])
	;
      cout<<higher-lower<<endl;

    }

  }
  return 0;
}

Measured memory_bytes: 6236
#include<stdio.h>
int main()
{
  int A,B,C;
  scanf("%d %d %d",&A,&B,&C);
  if(C-A+B>0){
  printf("%d",C-A+B);
  }
  else
  {
    printf("%d",0);
  }
    return 0;
}

Measured memory_bytes: 1736
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    long MOD = (long)Math.pow(10, 9) + 7;
    int[] a = new int[n];
    for(int i = 0; i < n; i++) {
      a[sc.nextInt()]++;
    }
    int p = 0;
    if((n % 2) == 0) {
      for(int i = 1; i < n; i += 2) {
        if(a[i] != 2) p++;
      }
    } else {
      if(a[0] != 1) p++;
      for(int i = 2; i < n; i += 2) {
        if(a[i] != 2) p++;
      }
    }
    long ans = 0;
    if(p == 0) {
      ans = 1;
      for(int i = 0; i < (n / 2); i++) {
        ans = (ans * 2) % MOD;
      }
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 59464
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <string.h>
#include <algorithm>
#include <cmath>
#include <limits>
#include <sstream>
#include <iomanip>

using namespace std;

int main (void)
{
	int a,b;

	cin >> a >> b;

	double p = a * b;

	cout << fixed << setprecision(10) << p / 3.305785 << endl;
}


Measured memory_bytes: 3280
#include<iostream>
#include<iomanip>
#include<math.h>
#include<algorithm>
#include<utility>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<unordered_map>
#include<functional>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF=2e18;
const ll MOD=1e9+7;

string N;
ll K;
ll dp[110][2][5];
int main(){
    cin>>N>>K;
    for(ll i=0;i<N.length();i++){
        for(ll j=0;j<2;j++){
            for(ll k=0;k<4;k++){
                dp[i][j][k]=0;
            }
        }
    }
    dp[0][0][0]=1;
    for(ll i=0;i<N.length();i++){
        for(ll j=0;j<2;j++){
            for(ll k=0;k<=K;k++){
                for(ll d=0;d<10;d++){
                    ll nextI=i+1;
                    ll nextJ=j;
                    if(j==0){
                        if(N[i]-'0'<d)continue;
                        if(N[i]-'0'>d){
                            nextJ=1;
                        }
                    }
                    ll nextK=k+(d>0);
                    if(nextK>K)continue;
                    dp[nextI][nextJ][nextK]+=dp[i][j][k];
                }
            }
        }        
    }
    cout<<dp[N.length()][0][K]+dp[N.length()][1][K]<<endl;
    return 0;
}

Measured memory_bytes: 256
n=int(input())
t,a=map(int,input().split())
h=list(map(int,input().split()))
comp=t-a
ans=0
for i in range(1,n):
  if abs(h[ans]*0.006-comp) > abs(h[i]*0.006-comp):
    ans = i
print(ans+1)

Measured memory_bytes: 9028
#include <iostream>
using namespace std;
int main(){
	char s;
	int i,j,k=0,n,a,b;
	cin>>a>>b;
	for(i=1;i<=a+b+1;i++){
		cin>>s;
		if(k==0){
			if(i!=a+1){
				if(s<'0'||s>'9')k=1;
			}
			else{
				if(s!='-')k=1;
			}
		}
	}
	if(k==1)cout<<"No"<<endl;
	else cout<<"Yes"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <climits>
#include <vector>
#include <stack>
#include <cmath>
#include <queue>
#include <set>
#include <map>
using namespace std;
bool isprime(int a) {
    for (int i = 2; i <= sqrt(a) ; ++i) {
        if (a % i == 0) return false;

    }
    return true;
}

bool like(int x) {
    return x > 1 && ( x %2 == 1) && isprime(x) && isprime((x+1)/2);
}
int main() {
    int q;
    cin >> q;

    vector<int> z(1000001, 0);
    for (int j = 1; j <=100000 ; ++j) {
        if(like(j))
            z[j] = 1;
    }

    for (int k = 1; k <= 100000; ++k) {
        z[k] += z[k-1];
    }

    for (int i = 0; i < q; ++i) {
        int l,r;
        cin >> l >>r;
        cout << z[r] - z[l-1] << endl;
    }

    return 0;
}


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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N;
int A[202020],B[202020];
int NA[202020],NB[202020];
void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	FOR(i,N) {
		cin>>A[i];
		NA[A[i]]++;
	}
	FOR(i,N) {
		cin>>B[i];
		NB[B[i]]++;
	}
	
	int ma=0;
	for(i=1;i<=N;i++) {
		if(NA[i]+NB[i]>N) return _P("No\n");
		NA[i]+=NA[i-1];
		NB[i]+=NB[i-1];
		ma=max(ma,NA[i]-NB[i-1]);
	}
	
	cout<<"Yes"<<endl;
	FOR(i,N) cout<<B[(i+N-ma)%N]<<" ";
	cout<<endl;
	
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 6752