akhauriyash/Code-Regression huggingface dataset:
from math import *

def pal(x):
    for i in range(len(x)//2):
        if x[i] != x[len(x) - i - 1]:
            return False
    return True

s = input()
n = len(s)
if pal(s) and pal(s[:(n-1)//2]) and pal(s[(n+2)//2:]):
    print("Yes")
else:
    print("No")



Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
constexpr int MX = 200005;
int n, c[MX], a, b, mu[MX*2];
vector<int> G[MX];
stack<int> par[MX];
ll ans[MX];
int count(int u, int p){
	int ret = 1, t, premu = 0;
	par[c[u]].push(u);
	for(int nx: G[u]) if(nx != p){
		t = count(nx, u);
		ret += t;
		t += mu[u] - premu;
		ans[c[u]] -= (ll)t * (t+1) / 2;
		premu = mu[u];
	}
	par[c[u]].pop();
	mu[par[c[u]].top()] -= ret;
	return ret;
}
int main(){
	scanf("%d", &n);
	rep(i,n){
		scanf("%d", c+i);
		c[i]--;
	}
	rep(i,n-1){
		scanf("%d%d", &a, &b);
		a--; b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	rep(i,n) par[i].push(n+i);
	fill(ans, ans+n, (ll)n * (n+1) / 2);
	fill(mu+n, mu+n*2, n);
	count(0,n);
	rep(i,n) printf("%lld\n", ans[i] - (ll)mu[i+n] * (mu[i+n]+1) / 2);
}

Measured memory_bytes: 169252
#include <iostream>
#include <math.h>
using namespace std;
int main() {
    int k,x;
    cin>>k>>x;
    if(k==1) {
        cout << x<<endl;
    }
    else{
        for(int i=1;i<=2*k-1;i++){
            cout<<-1*(k-i)+x<<" ";
        }
    }
    system("pause");
}


Measured memory_bytes: 504
#include <bits/stdc++.h>
  using namespace std;
#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) cin>>aa;(p).push_back(aa);
#define vecpl2(p) long long a	b;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define set0(k,n) for(int nn=0;nn<(n);nn++){ (k).push_back(0); }
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define vecsize(b,size) vector<int> (b)((size));
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsl(s) vector<pair<ll,ll>> (s);
#define pairss(s) vector<pair<string,string>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairspl(s) ll aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsps(s) string aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsREV(s) (s).push_back(make_pair(bb,aa));
#define pairslREV(s) (s).push_back(make_pair(bb,aa));
#define pairssREV(s) (s).push_back(make_pair(bb,aa));
#define MOD 1000000007


int main() {
	
	ll K;
	cin>>K;
	
	ll k=K/50;
	ll j=K%50;
	ce(50)
	fx(j){
		cout<<k*50+49+50-k*49-(j-1)<<' ';
	}
	fx(50-j){
		cout<<k*50+49-k*49-j<<' ';
		if(x==50-j-1){
			cout<<endl;
		}else{
			cout<<' ';
		}
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define M 1000000007
#define INF ((1LL<<62LL) - 1)

const int N = 2e5 + 5;
set<int> g[N];
bool vis[N];
vector<int> connect[N];
int cur = 0;

void dfs(int x){
    vis[x] = true;
    connect[cur].push_back(x);

    for(int y:g[x]){
        if(!vis[y]){
            dfs(y);
        }
    }
}

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

    int n; cin >> n;
    int m; cin >> m;
    for(int i=1;i<=m;i++){
        int u,v; cin >> u >> v;
        g[u].insert(v);
        g[v].insert(u);
    }

    for(int i=1;i<=n;i++){
        if(!vis[i]){
            cur++;
            dfs(i);
        }
    }

    int ans = 1;
    for(int i=1;i<=cur;i++){
        ans = max(ans, (int)connect[i].size());
    }

    cout << ans << "\n";



}


Measured memory_bytes: 47232
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <math.h>
#include <deque>
#include <queue>
#include <map>
#include <iterator>
#include <set>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e) { std::cout << e << std::endl; }
template<typename T> void view(const std::vector<T>& v) { for (const auto& e : v) { std::cout << e << " "; } std::cout << std::endl; }
template<typename T> void view(const std::vector<std::vector<T> >& vv) { for (const auto& v : vv) { view(v); } }
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; }

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

	while (1) {
		int n, x;
		cin >> n >> x;
		int ans = 0;
		if (n == 0 && x == 0) break;
		for (int i = 1; i <= n; i++) {
			for (int j = i + 1; j <= n; j++) {
				for (int k = j+1; k <= n; k++) {
					if (i + j + k == x) ans++;
				}
			}
		}
		cout << ans << endl;
	}
}


Measured memory_bytes: 3112
#include<stdio.h>

int getBenefit(int*, int);

int main()
{
  int i,n,R[200000];
  
  scanf("%d", &n);
  for(i=0;i<n;i++)
    {
      scanf("%d", &R[i]);
    }

  printf("%d\n", getBenefit(R,n));
  return 0;
}

int getBenefit(int *R, int n)
{
  int j, maxv = R[1] - R[0], minv = R[0];
  for(j=1;j<=n-1;j++)
    {
      /*条件演算子*/
      maxv = maxv > R[j] - minv ? maxv : R[j] - minv;
      minv = minv < R[j] ? minv : R[j];
    }
  return maxv;
}



Measured memory_bytes: 2564
#include<bits/stdc++.h>
#define ll long long
using namespace std;
signed main() {
  ll n, k, a[1000000];
  cin >> n >> k;

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

  for (int i = 1; i <= n - k; i++) {
    if (a[i] < a[i + k]) {
      cout << "Yes\n";
    }else {
      cout << "No\n";
    }
  }
  return 0;
}

Measured memory_bytes: 5084
#dp[i][sum_v]:= i-1以下の品物の中から、価値をsum_v以上になる時の重さの最小値

N,W=map(int,input().split())

w,v=[0],[0]

for _ in range(N):
    wi,vi=map(int,input().split())
    w.append(wi)
    v.append(vi)

dp=[[10**12 for _ in range(N*max(v)+1)] for _ in range(N+1)]
dp[0][0]=0

for i in range(N):
    for sum_v in range(N*max(v)+1):
        if sum_v-v[i+1]>=0:
            dp[i+1][sum_v]=min(dp[i][sum_v-v[i+1]]+w[i+1],dp[i][sum_v])
        else:
            dp[i+1][sum_v]=dp[i][sum_v]

ans=0

for sum_v in range(N*max(v)+1):
    if dp[N][sum_v]<=W:
        ans=max(ans,sum_v)
print(ans)


Measured memory_bytes: 171912
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
  int A, B;
  cin >> A >> B;
  int r = A - 2 * B;
  cout << (r > 0 ? r : 0) << endl;
}


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

// region template
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define trav(a, x) for (auto &a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;

ll gcd(ll a, ll b) { return __gcd(a, b); }

ll euclid(ll a, ll b, ll &x, ll &y) {
    if (b) { ll d = euclid(b, a % b, y, x);
        return y -= a/b * x, d; }
    return x = 1, y = 0, a;
}

typedef unsigned long long ull;
typedef long double ld;
ull mod_mul(ull a, ull b, ull M) {
    ll ret = a * b - M * ull(ld(a) * ld(b) / ld(M));
    return ret + M * (ret < 0) - M * (ret >= (ll)M);
}
ull mod_pow(ull b, ull e, ull mod) {
    ull ans = 1;
    for (; e; b = mod_mul(b, b, mod), e /= 2)
        if (e & 1) ans = mod_mul(ans, b, mod);
    return ans;
}

const ll mod = 1000000007;
struct Mod {
    ll x;
    Mod(ll xx) : x(xx) {}
    Mod operator+(Mod b) { return Mod((x + b.x) % mod); }
    Mod operator-(Mod b) { return Mod((x - b.x) % mod); }
    Mod operator*(Mod b) { return Mod((x * b.x) % mod); }
    Mod operator/(Mod b) { return *this * invert(b); }
    Mod invert(Mod a) {
        ll x, y, g = euclid(a.x, mod, x, y);
        assert(g == 1); return Mod((x + mod) % mod);
    }
    Mod operator^(ll e) {
        if (!e) return Mod(1);
        Mod r = *this ^ (e / 2); r = r * r;
        return e & 1 ? *this * r : r;
    }
};
// endregion

const int mx = 300000;
int prime[mx], ps[mx];

int main() {
    cin.sync_with_stdio(0); cin.tie(0); cin.exceptions(cin.failbit);

    prime[0] = 0, prime[1] = 0;
    rep(i, 2, mx) prime[i] = true;
    rep(i, 2, mx) for (ll j = 1ll * i * i; j < mx; j += i) prime[j] = false;
    rep(i, 1, mx) ps[i] = ps[i - 1] + prime[i];

    while (1) {
        int n; cin >> n;
        if (!n) break;
        cout << ps[2 * n] - ps[n] << endl;
    }
}


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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod= int(1e9)+7;
using P = pair<ll,ll>;
using ld=long double;

int main(){
    ll n;cin >>n;
    vector<ll>t(n);
    ll lcm;
    ll g;
    for (int i = 0; i < n; ++i) {
        cin >>t[i];
        if(!i)lcm=t[i];
        g=__gcd(lcm,t[i]);
        lcm=lcm*(t[i]/g);
    }
    cout <<lcm<<endl;
    return 0;
}

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

int main() {
	int n; cin >> n;
	vector<int>a(n); for (auto&& x : a)cin >> x;
	sort(a.begin(), a.end());
	int aN = a[n - 1], aR = a[0];
	long long dis = 1e9;
	for (int i = 1; i < n - 1; i++) {
		if (dis > abs(a[i] * 2 - aN)) {
			dis = abs(a[i] * 2 - aN);
			aR = a[i];
		}
	}
	cout << aN << ' ' << aR << endl;

	return 0;
}

Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<int> edge[100005];
int n,m,s,t,vis[100005][3];
void bfs(){
	queue<pair<int,int>> q;
	q.push({s,0});
	while(!q.empty()){
		int u=q.front().first;
		int x=q.front().second;
		q.pop();
		if(u==t&&x%3==0){
			cout<<x/3<<endl;
			exit(0);
		}
		for(int i=0;i<edge[u].size();i++){
			int v=edge[u][i],val=x+1;
			if(vis[v][val%3]==1) continue;
			q.push({v,val});
			vis[v][val%3]=1;
		}
	}

}
int main(){
	cin>>n>>m;
	for(int i=1;i<=m;i++){
		int u,v;
		cin>>u>>v;
		edge[u].push_back(v);
	}
	cin>>s>>t;
	bfs();
	cout<<-1<<endl;
}

Measured memory_bytes: 6912
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
int N;
int ans = 0;
vector<int> A;
int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);

	cin >> N;
	int cnt = 0;
	A.push_back(N);
	while(1){
		int tmp;
		N = A[cnt++];
		if(N % 2){
			tmp = 3 * N + 1;
		}else{
			tmp = N / 2;
		}
		
		REP(i,A.size()){
			if(A[i] == tmp){
				ans = cnt;
			}
		}
		A.push_back(tmp);
		if(ans) break;
	}
	cout << ans + 1<< endl;

}

Measured memory_bytes: 256
/*#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("fast-math")*/
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
using namespace std;

#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define Str(x) to_string(x)
#define len(s) (int)s.size()
#define int long long
typedef long long ll;
typedef long double lld;
typedef string str;
typedef unsigned long long ull;

const int maxn = 1e5 + 228;

int first[maxn], second[maxn], arr[maxn], firstfirst[maxn], secondsecond[maxn];

int ind[maxn];


main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int n;
    cin >> n;
    for (int i = 0; i < maxn; i++)
    {
        second[i] = n + 1;
        secondsecond[i] = n + 1;
    }
    for (int i = 1; i <= n; i++)
    {
        cin >> arr[i];
        ind[arr[i]] = i;
    }
    int ans = 0;
    set <int> mx, mn;
    for (int i = n; i >= 1; i--)
    {
        if (!mx.empty() && *mx.rbegin() > ind[i])
        {
            int val = *mx.lower_bound(ind[i]);
            second[ind[i]] = val;
            if (*mx.rbegin() != val)
            {
                val = *mx.lower_bound(val + 1);
                secondsecond[ind[i]] = val;
            }
        }
        if (!mn.empty() && *mn.rbegin() > -ind[i])
        {
            int val = *mn.lower_bound(-ind[i]);
            first[ind[i]] = -val;
            if (*mn.rbegin() != val)
            {
                val = *mn.lower_bound(val + 1);
                firstfirst[ind[i]] = -val;
            }
        }
        mx.insert(ind[i]);
        mn.insert(-ind[i]);
    }
    for (int i = 1; i <= n; i++)
    {
        if (arr[i] == n)
        {
            continue;
        }

        int flexxx = 0;
        if (second[i] != n + 1)
        {
            flexxx += (secondsecond[i] - second[i]) * (i - first[i]);
        }
        if (first[i] != 0)
        {
            flexxx += (first[i] - firstfirst[i]) * (second[i] - i);
        }
        ans += flexxx * arr[i];
    }
    cout << ans;
    return 0;
}

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

using ll = long long;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << "(" << p.first << "," << p.second << ")";
    return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
    os << "{";
    rep(i, (int)v.size()) {
        if (i)
            os << ",";
        os << v[i];
    }
    os << "}";
    return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
    for (auto val : array)
        std::cout << val << ", ";
    std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << std::setprecision(10);

    int n, m, x; std::cin >> n >> m >> x;
    vi c(n);
    vvi a(n, vi(m));
    rep(i, n) {
        std::cin >> c[i];
        rep(j, m) {
            std::cin >> a[i][j];
        }
    }

    int ans = inf;
    rep(i, 1 << n) {
        int tmp = 0;
        vi sum(m);
        rep(j, n) {
            if ((i >> j) & 1) continue;
            rep(k, m) {
                sum[k] += a[j][k];
            }
            tmp += c[j];
        }
        bool ok = true;
        rep(j, m) if (sum[j] < x) ok = false;
        if (ok) chmin(ans, tmp);
    }
    std::cout << (ans != inf ? ans : -1) << "\n";
}


Measured memory_bytes: 3592
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class Main {

    public static void main(String[] args) throws IOException {

        InputStreamReader is = new InputStreamReader(System.in);
        BufferedReader reader = new BufferedReader(is);

        List<String> mylist = new ArrayList<>();

        // 標準入力からの値を変数strinputに代入
        String strinput = reader.readLine();

        while (strinput != null) {

            mylist.add(strinput);
            strinput = reader.readLine();

        }
        String arr01[] = mylist.get(0).split(" ");
        Integer r = Integer.valueOf(arr01[0]);

        System.out.println(r * r);

    }

}

Measured memory_bytes: 22484
// https://atcoder.jp/contests/agc032/tasks/agc032_a

#include <algorithm>
#include <array>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <tuple>
#include <vector>
using namespace std;

typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

#define EPS (1e-7)
#define INF (1e9)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOREACH(x, a) for (auto &(x) : (a))
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()

// long gcd(long a, long b) { return b ? gcd(b, a % b) : a; }
// long lcm(long a, long b) { return a * b / gcd(a, b); }

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> v(n), w;

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

    for (auto &x : v) {
        if (x - 1 > w.size()) {
            cout << "-1\n";
            return 0;
        }
        w.insert(w.begin() + (x - 1), x);
    }
    for (auto &x : w) {
        cout << x << '\n';
    }

    return 0;
}


Measured memory_bytes: 256
A, B, C, X, Y = map(int, input().split())

totalA1 = A * X
totalA2 = C * X * 2
totalB1 = B * Y
totalB2 = C * Y * 2

totalAB = A * X + B * Y

totalAC = C * Y * 2
if X > Y:
    totalAC += (X - Y) * A

totalCB = C * X * 2
if Y > X:
    totalCB += (Y - X) * B

totalCC = max(X, Y) * C * 2

print(min(totalAB, totalAC, totalCB, totalCC))



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

using namespace std;

const int nax=1e5+5;
long long int dp[111][nax];




int main()
{
    int n,w; cin>>n>>w;
    long long int waga[111];
    long long int wartosc[111];
    for(int i=1;i<=n;i++)
    {
        cin>>waga[i]>>wartosc[i];
    }
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=w;j++)
        {
            dp[i][j]=dp[i-1][j];
            if(j>=waga[i])
            {
                dp[i][j]=max(dp[i][j],dp[i-1][j-waga[i]]+wartosc[i]);
            }
        }
    }
    cout<<dp[n][w];
    return 0;
}


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

using namespace std;
 
#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

typedef int64_t ll; typedef vector<int> VI; typedef pair<int,int> pii;
const ll mod = 1e9+7;

void dbg(){ cerr << "\n"; }  
template <typename T,typename ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }


int main()
{
	
	//cin.tie(0); ios_base::sync_with_stdio(false);
	int n=3;

	vector<VI> c(3, VI(3));
	
	rep(i,3) rep(j,3) cin >>c[i][j];
	
	rep(a0,101) rep(a1,101) rep(a2,101){
		
		int b0 = c[0][0] - a0;
		int b1 = c[0][1] - a0;
		int b2 = c[0][2] - a0;
		if(b0<0 ||b1<0 ||  b2<0) continue;
		//dbg(a0,a1,a2,b0,b1,b2);
		
		if(c[1][0] != a1 +b0 || c[1][1] != a1 +b1 || c[1][2] != a1 +b2) continue;
		if(c[2][0] != a2 +b0 || c[2][1] != a2 +b1 || c[2][2] != a2 +b2) continue;				puts("Yes"); return 0;
	}
	
	puts("No");
	return 0;
	
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <string>
#include <queue>
#include <numeric>
#include <ctype.h>
#include <limits>
#include <iomanip>

#define rep(i,n) for (int i = 0; i < n; i++)
#define all(x) (x).begin(),(x).end()
using namespace std;

typedef long long ll;

int main() {
	int A, B;
	cin >> A >> B;
	if ((A + B) % 2 == 0)cout << (A + B) / 2;
	else cout << "IMPOSSIBLE";
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;

class Main{
  public static StringBuilder bl = new StringBuilder();
  public static final int WHITE = 0;
  public static final int BLACK = 2;
  public static final int GRAY = 1;
  static int color[];
  static int time;
  static int M[][];
  static int nt[];
  static  int d[]; // 行きの時間 discover;
  static  int f[]; // 帰りの時間 finishing;
  static int n;
  // static Deque<Integer> stack = new ArrayDeque<Integer>();

  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    n = sc.nextInt();
    M = new int[n][n];
    color = new int[n];
    d = new int[n];
    f = new int[n];
    nt = new int[n];
    int u, k, v;

    for(int i = 0; i<n; i++){
      for(int j = 0; j<n; j++){
        M[i][j] = 0;
      }
    }

    for(int i = 0; i<n; i++){
      u = sc.nextInt();
      k = sc.nextInt();
      for(int j = 0; j<k; j++){
        v =sc.nextInt();
        M[u-1][v-1] = 1;
      }
    }
    dfs_init();
    System.out.print(bl);
  }

  static void dfs_init(){
    for(int i =0; i<n; i++){
      color[i] = WHITE;
      nt[i] = 0;
    }
    time = 0;
    //  //dfs(0);

    for(int u = 0; u<n; u++){
      if(color[u] == WHITE)dfs(u);
    }

    for(int i = 0; i<n; i++){
      bl.append(i+1).append(" ").append(d[i]).append(" ").append(f[i]).append("\n");
      // System.out.println((i+1)+" "+d[i]+" "+f[i]);
    }

  }

  static void dfs(int r){

    for(int i =0; i<n; i++){
      nt[i] = 0;
    }
    Deque<Integer> stack = new ArrayDeque<Integer>();
    stack.offerFirst(r);
    color[r] = GRAY;
    d[r] = ++time;

    while(stack.peek()!=null){
      int u = stack.getFirst();
      int v = next(u);
      if(v != -1){
        if(color[v] == WHITE){
          color[v] = GRAY;
          d[v] = ++time;
          stack.offerFirst(v);
        }
      }else{
        stack.removeFirst();
        color[u] = BLACK;
        f[u] = ++time;
      }
    }

  }

  //ノードuに隣接しているノードを返す 隣接行列で表現されているのでuの行を探索して1があればその列の添字を返す。
  static int next(int u){
    for(int v = nt[u]; v <n; v++){
      nt[u] = v+1;
      if(M[u][v] == 1) return v;
    }
    return -1;
  }

}


Measured memory_bytes: 28140
// Depth_First_Search.cs

using System;

class V {

	public int edge;
	public int[] adj;
	public int d;
	public int f;
	
	public V(int k) {
		edge = k;
		adj = new int[edge];
	}
}

class Depth_First_Search {
	public static void Main() {

		int n = int.Parse(Console.ReadLine());
		int time = 0;

		V[] ver = new V[n + 1];

		for(int i = 0; i < n; i++) {

			string[] num = Console.ReadLine().Split();
			int u = int.Parse(num[0]);
			int k = int.Parse(num[1]);
			ver[u] = new V(k);

			for(int j = 0; j < k; j++) {
				ver[u].adj[j] = int .Parse(num[2 + j]);
			}
		}

		for(int i = 1; i <= n; i++) {
			if(ver[i].d == 0) {
				DFS(ver, i, ref time);
			}
		}

		for(int i = 1; i <= n; i++) {
			Console.WriteLine(i + " " + ver[i].d + " " + ver[i].f);
		}

	}

	static void DFS(V[] ver, int u, ref int time) {

		if(ver[u].d == 0) {

			ver[u].d = ++time;

			if(ver[u].edge != 0) {

				for(int i = 0; i < ver[u].edge; i++) {
					if(ver[ver[u].adj[i]].d == 0) {
						DFS(ver, ver[u].adj[i], ref time);
					}
				}

			}
		}

		if(ver[u].f == 0) {
			ver[u].f = ++time;
		}

	}

}

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

int main() {
  string S;
  cin >> S;
  
  int N = S.size();
  
  stack<char> s;
  s.push('2'); // 空にならないように0,1以外の何かを最初に入れておく．
  
  int ans = 0;
  for (int i = 0; i < N; i++) {
    if ((s.top() == '0' && S.at(i) == '1') || (s.top() == '1' && S.at(i) == '0')) {
      ans += 2;
      s.pop();
    } else {
      s.push(S.at(i));
    }
    
  }
   
  cout << ans << endl;
  
  
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
	int flag=1;
	int n;cin>>n;
	int a[110];
	for(int i=0;i<n;i++)
	cin>>a[i];
	for(int i=0;i<n;i++)
	{
		if(a[i]%2==0)
		{
			if(a[i]%3!=0&&a[i]%5!=0)
			flag=0;
		}
	}
	if(flag)
	cout<<"APPROVED"<<endl;
	else
	cout<<"DENIED"<<endl;
}

Measured memory_bytes: 256
N, M = map(int, input().split())

par = [i for i in range(N)]

def find(x):
  if par[x] == x:
    return x
  else:
    par[x] = find(par[x])
    return par[x]
    

def unite(x, y):
  x = find(x)
  y = find(y)
  if x > y:
    par[x] = y
    find(x)
  else:
    par[y] = x
    find(y)
if M > 0:  
  for i in range(M):
    a, b = map(int, input().split())
    unite(a - 1, b - 1)
  
  ans = [0] * N
  Max = 0
  for i in range(N):
    find(i)
  for i in par:
    ans[i] += 1
  for i in ans:
    if i > Max:
      Max = i
  
  print(Max)
else:
  print(1)

Measured memory_bytes: 18536
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

// Input. ----------

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
}

func nextInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}

	return i
}

// ---------- Input.

func main() {
	N := nextInt()
	if N == 1 {
		fmt.Println("YES")
		return
	}

	sum := 0
	for i := 0; i < N; i++ {
		sum += nextInt()
	}

	ans := ""
	if sum%2 == 0 {
		ans = "YES"
	} else {
		ans = "NO"
	}

	fmt.Println(ans)
}

Measured memory_bytes: 2176
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <climits>
#include <map>
#include <cmath>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iterator>
#include <deque>
#include <bitset>
#include <list>
#include <queue>
#include <set>
#include <stack>
#include <functional>
#include <iterator>
#include <locale>
#include <memory>
#include <stdexcept>
#include <utility>
#include <fstream>
#include <ios>
#include <iosfwd>
#include <iomanip>
#include <istream>
#include <sstream>
#include <streambuf>
#include <complex>
#include <numeric>
#include <valarray>
#include <exception>
#include <limits>
#include <new>
#include <typeinfo>
#include <bitset>
#include <queue>

using namespace std;

int main() {
	string a;
	cin >> a;
	if (a[a.size() - 1] == 's') {
		cout << a + "es";
	}
	else
		cout << a + "s";
}



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

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

typedef long long ll;
const ll MOD = 1e9 + 7;

int main() {
  std::string S;
  ll K;
  std::cin >> S >> K;

  bool all_same = true;
  for(char c : S) {
    if(c != S[0]) {
      all_same = false;
      break;
    }
  }

  if(all_same) {
    std::cout << (K * S.size()) / 2 << '\n';
    return 0;
  }

  std::vector<int> cnt_count;
  char head = S[0];
  int cnt = 0;
  for(size_t i = 0; i < S.size(); ++i) {
    if(S[i] == head) {
      ++cnt;
    } else {
      cnt_count.push_back(cnt);
      head = S[i];
      cnt = 1;
    }
  } cnt_count.push_back(cnt);

  int ans_S = 0;
  for(int v : cnt_count) {
    ans_S += v / 2;
  }


  if(S.front() != S.back()) {
    std::cout << K * ans_S << '\n';
    return 0;
  } else {
    int a = cnt_count.front();
    int b = cnt_count.back();

    std::cout << K * ans_S - (K - 1) * (a / 2 + b / 2 - (a + b) / 2) << '\n';
    return 0;
  }
}


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

int main() {

	int n; cin >> n;
	vector<int> p(n), min_p(n);
	for (int i = 0; i < n; i++) {
		cin >> p[i];		
	}
	min_p[0] = p[0];
	for (int i = 1; i < n; i++) {
		min_p[i] = min(min_p[i - 1], p[i]);
	}
	int ans = 0;
	for (int i = 0; i < n; i++) {
		if (p[i] <= min_p[i]) ans++;
	}
	cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4840
N = int(input())
a = list(map(int,input().split()))
a.sort(reverse=True)
st_n = a[0]
st_r = a[1]
m = st_r*(st_n-st_r)
for r in range(2,N):
    cn = a[r]*(st_n-a[r])
    if m < cn:
        st_r = a[r]
        m = cn
print(st_n,st_r)

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

int main()
{
    int l, r, d;
    cin >> l >> r >> d;
    int ans = 0;
    for (int i = l; i <= r; ++i)
        if (i % d == 0)
            ans++;
    cout << ans << endl;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define N 2000010
int a[N], n;
int sta[N], top;
int l[N], r[N];
int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
    for (int i = 1; i <= n; i++) {
        while (top && a[i] <= a[sta[top]]) r[sta[top--]] = i - 1;
        sta[++top] = i;
    }
    while (top) r[sta[top--]] = n;
    for (int i = n; i; i--) {
        while (top && a[i] <= a[sta[top]]) l[sta[top--]] = i + 1;
        sta[++top] = i;
    }
    while (top) l[sta[top--]] = 1;
    ll ans = 0;
    for (int i = 1; i <= n; i++)
        ans += (ll)(r[i] - i + 1) * (i - l[i] + 1) * a[i];
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 11264
#include <bits/stdc++.h>
using namespace std;
int solve(string s1,string s2,int m,int n)
{
	if(m==0||n==0)
		return 0;
	if(s1[m-1]==s2[n-1])
		return 1+solve(s1,s2,m-1,n-1);
	else
		return max(solve(s1,s2,m-1,n),solve(s1,s2,m,n-1));
}
string solution(string s1,string s2,int m,int n)
{
	int dp[m+1][n+1];
	for(int i=0 ; i<=m ; i++)
	{
		for(int j=0 ; j<=n ; j++)
		{
			if(i==0||j==0)
				dp[i][j]=0;
			else if(s1[i-1]==s2[j-1])
				dp[i][j]=1+dp[i-1][j-1];
			else
				dp[i][j]=max(dp[i][j-1],dp[i-1][j]);
		}
	}
	int i=m,j=n;
	string str="";
	while(i>0 && j>0)
	{
		if(s1[i-1]==s2[j-1])
		{
			str+=s1[i-1];
			i--;
			j--;
		}
		else
		{
			if(dp[i][j-1]>dp[i-1][j])
				j--;
			else
				i--;
		}
	}
	return str;
//	return dp[m][n];
}
int main() {
	string x,y;
	cin>>x>>y;
	string ans=solution(x,y,x.size(),y.size());
	reverse(ans.begin(),ans.end());
	cout<<ans;
	return 0;
}

Measured memory_bytes: 38796
n,m=map(int,input().split())
K=[]
S=[]
for i in range(m):
  tmp=list(map(int,input().split()))
  K.append(tmp[0])
  S.append(tmp[1:])
P=list(map(int,input().split()))
ans=0
for i in range(2**n):
  bit=format(i,'0'+str(n)+'b')
  bit=list(map(int,bit))
  on_den=0
  for den in range(m):
    on_swi=0
    for s in S[den]:
      on_swi+=bit[s-1]
    if on_swi%2==P[den]:
      on_den+=1
  if on_den==m:
    ans+=1
print(ans)

Measured memory_bytes: 9080
#include <iostream>
#include <queue>
#include <cstring>
#include <tuple>
using namespace std;

int dr[4] = {1, 0, -1, 0},
    dc[4] = {0, 1, 0, -1};
int H, W;

bool inside(int r, int c) {
    return 0 <= r and r < H and 0 <= c and c < W;
}

int main() {
    cin >> H >> W;

    int white = 0;

    string s[50];
    for (int r = 0; r < H; r++) {
        cin >> s[r];

        for (char ch : s[r]) {
            if (ch == '.') white++;
        }
    }

    int cost[50][50];
    memset(cost, -1, sizeof(cost));

    queue<tuple<int, int, int>> Q;  // (r, c, 距離)

    cost[0][0] = 1;
    Q.push(make_tuple(0, 0, 1));
    while (!Q.empty()) {
        int r, c, d;
        tie(r, c, d) = Q.front(); Q.pop();

        if (r == H - 1 and c == W - 1) {
            cout << white - d << endl;
            return 0;
        }

        for (int i = 0; i < 4; i++) {
            int nr = r + dr[i];
            int nc = c + dc[i];
            if (inside(nr, nc) and cost[nr][nc] < 0 and s[nr][nc] == '.') {
                cost[nr][nc] = d + 1;
                Q.push(make_tuple(nr, nc, d + 1));
            }
        }
    }
    cout << -1 << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int N;
long long A[300010], AA[300010][100];
long long mod = 1000000007;
int main () {
    cin >> N;
    for (int i = 1; i <= N; i++) {
        cin >> A[i];
        auto a = A[i];
        for (int j = 0; a; j++) {
            if (a & 1) {
                AA[i][j] = 1;
            }
            a /= 2;
        }
    }
    for (int j = 0; j < 60; j++) {
        for (int i = 1; i <= N; i++) {
            AA[i][j] += AA[i-1][j];
        }
    }
    long long ans = 0;
    for (int i = 1; i < N; i++) {
        for (long long j = 0, p = 1; j < 60; j++, p += p) {
            int k1 = AA[N][j] - AA[i][j];
            int k0 = N-i-k1;
            long long g = p % mod;
            if (A[i] & p) {
                ans += g * k0;
            }
            else {
                ans += g * k1;
            }
            ans %= mod;
        }
    }
    cout << ans << endl;   
}

Measured memory_bytes: 236928
#include <iostream>
int main(int argc, char *argv[]) {
  char c;
  int start = -1, end = -1, idx = 1;
  while (std::cin >> c) {
    if (start < 0 && c == 'A')
      start = idx;
    if (start >= 0 && c == 'Z')
      end = idx;
    ++idx;
  }

  std::cout << end - start + 1 << std::endl;
}


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

int main(){
  int A,B,ans=1;
  cin >> A >> B;
  for(int i=1;i<4;i++){
    if(i!=A && i!=B) ans=i;
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 3604
#include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <cassert>
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
const double EPS = 1e-10;
const double PI  = acos(-1.0);

int dfs(int p,int q,int a,int n,int bunbo,int bunsi,int cnt,int prev){
	if(cnt==n){
		return(q*bunsi==p*bunbo);
	}
	int ret=(q*bunsi==p*bunbo);
	FOR(i,prev,a+1){
		int new_bunbo=bunbo*i;
		int new_bunsi=bunsi*i+bunbo;
		if(new_bunbo>a)break;
		ret+=dfs(p,q,a,n,new_bunbo,new_bunsi,cnt+1,i);
	}
	return ret;
}
int main(){
	int p,q,a,n;
	while(cin>>p>>q>>a>>n,p|q|a|n){
		cout<<dfs(p,q,a,n,1,0,0,1)<<endl;
	}
}

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

int main(){
    int N, L;
    vector<string> S;
    string tmp;
    cin >> N >> L;
    for(int i=0; i<N; i++){
        cin >> tmp;
        S.push_back(tmp);
    }
    string tmp2;
    for(int i=0; i<S.size(); i++){
        for(int j=i+1; j<S.size(); j++){
            if(S[i] > S[j]){
                tmp2 = S[i];
                S[i] = S[j];
                S[j] = tmp2;
            }
        }
    }
    for(int i=0; i<S.size(); i++){
        cout << S[i];
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 3640
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define NUM 1000000007 //10^9+7
#define ll long long int

int main(void){
	ll n,i,ans=1;
	char s[100001];
	scanf("%lld %s",&n,s);
	int alph[26]={0};
	for(i=0;i<n;i++)alph[s[i]-'a']++;
	for(i=0;i<26;i++){
		ans *= (alph[i]+1);
		ans = ans%NUM;
	}
	ans = (ans-1)%NUM;
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 256
X = int(input())

count_500 = 0
count_5 = 0
if X >= 500:
    count_500 += int(X/500)
    X = X%500
    if X >= 5:
        count_5 += int(X/5)
        X = X%5
else:
    count_5 += int(X/5)
    X = X%5

print(count_500*1000 + count_5*5)

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

#define NEW(p,n){p=malloc((n)*sizeof(p[0]));if(p==NULL){printf("not enough memory\n");exit(1);};}
//pの型の変数n個の要素分のメモリを確保し、そのアドレスをpに代入するマクロ

#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define SWAP(type, x, y) do { type tmp = x; x = y; y = tmp; } while (0)

#define MOD 1000000007 

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

    int M[2][N];
    for(int i=0;i<2;i++){
        for(int j=0;j<N;j++) scanf("%d",&M[i][j]);
    }
    
    //累積和をとる
    for(int i=1;i<N;i++) M[0][i]+=M[0][i-1];
    for(int i=N-2;i>=0;i--) M[1][i]+=M[1][i+1];
    
    int ans=0;
    for(int i=0;i<N;i++) ans=MAX(ans, M[0][i]+M[1][i]);
    printf("%d\n",ans);
    
    return 0;
}

Measured memory_bytes: 128
package main

import (
	"fmt"
	"strconv"
	"strings"
)

func stringArrayToIntArray(stringArray []string) []int {
	intArray := make([]int, len(stringArray))
	for n := range stringArray {
		intArray[n], _ = strconv.Atoi(stringArray[n])
	}
	return intArray
}

func sumDigits(nums []int) int {
	var sum int
	for _, num := range nums {
		sum += num
	}
	return sum
}

func canDigitSumDevideOriginalNumber(digitSum int, originalNumber int) string {
	if originalNumber%digitSum == 0 {
		return "Yes"
	}
	return "No"

}

func main() {
	var s string
	fmt.Scan(&s)

	originalNumber, _ := strconv.Atoi(s)
	digits := stringArrayToIntArray(strings.Split(s, ""))
	digitSum := sumDigits(digits)
	fmt.Println(canDigitSumDevideOriginalNumber(digitSum, originalNumber))
}


Measured memory_bytes: 640
a_list = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
a = int(input())
print(a_list[a-1])

Measured memory_bytes: 3060
n=int(input())
s=[input() for _ in [0]*n]
march=[0]*5
for x in s:
  if x[0] in 'MARCH':
    march['MARCH'.index(x[0])]+=1
ans=0
for i in range(5):
  for j in range(i+1,5):
    for k in range(j+1,5):
      ans+=march[i]*march[j]*march[k]
print(ans)

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

int main(){
	int n,v[60],c[60],a;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>v[i];
	}
	for(int i=0;i<n;i++){
		cin>>c[i];
	}
	a=0;
	for(int i=0;i<n;i++){
		if(v[i]>c[i]){
			a+=v[i]-c[i];
		}
	}
	cout<<a<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#define M 1000010

using namespace std;

int H[M];

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

int getKey(string str) {
  int sum = 0;
  int p = 1;
  for (int i = 0; i < str.size(); i++) {
    int char2int = char2Int(str[i]);
    int add = p * char2int;
    sum += add;
    p *= 5;
  }
  return sum;
}

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

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

void insert(string str) {
  int key = getKey(str);
  for (int i = 0; ; i++) {
    int h = (h1(key) + i * h2(key)) % M;

    if (H[h] == key) {
      // cout << "[aready] i:" << i <<", h:" << h << endl;
      break;
    } else if (H[h] != 0) {
      // cout << "[collision] i:" << i <<", h:" << h << endl;
    } else {
      H[h] = key;
      // cout << "[insert!] i:" << i <<", h:" << h << endl;
      break;
    }
    if (i >= M) {
      cout << "hash full" << endl;
      break;
    }
  }
}

int find(string str) {
  int key = getKey(str);
  for (int i = 0; ; i++) {
    int h = (h1(key) + i * h2(key)) % M;
    if (H[h] == key) {
      // cout << "[aready] i:" << i <<", h:" << h << endl;
      return h;
    } else if (H[h] != 0) {
      // cout << "[collision] i:" << i <<", h:" << h << endl;
    } else {
      return -1;
    }
  }
}

int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    string command;
    string str;
    cin >> command >> str;
    // cout << command << endl;
    if (command == "insert") {
      // cout << "insert" << endl;
      insert(str);
    } else if (command == "find") {
      if (find(str) != -1) {
        cout << "yes" << endl;
      } else {
        cout << "no" << endl;
      }
    }
  }
}



Measured memory_bytes: 7052
a = [[0] * 3] * 3
for i in range(3):
    a[i] = list(map(int, input().split()))

n = int(input())

for i in range(n):
    b = int(input())
    for x in range(3):
        for y in range(3):
            if a[x][y] == b:
                a[x][y] = -1
                break

is_bingo = False
# | line check
for i in range(3):
    if a[i][0] == a[i][1] == a[i][2] == -1 or a[0][i] == a[1][i] == a[2][i] == -1:
        is_bingo = True

if not is_bingo:
    if a[0][0] == a[1][1] == a[2][2] == -1 or a[2][0] == a[1][1] == a[0][2] == -1:
        is_bingo = True

if is_bingo:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
 
using namespace std;
 
int m,f,r;//中間試験の点数、期末テストの点数、再試験の点数、試験を受けてない場合は-1
 
int main()
{
  while(scanf("%d %d %d",&m,&f,&r)){
    if(m == -1&& f == -1 && r== -1){
      break;
    }
    if(m == -1||f== -1){
      cout <<"F"<<endl;
    }
    else if(m+f >=80)
      cout <<"A"<<endl;
    else  if(m+f>=65 &&m+f<80)
      cout <<"B"<<endl;
    else if(m+f >=50&&m+f<65)
      cout <<"C"<<endl;
    else if(m+f >=30&&m+f<50){
      if(r>=50){
    cout <<"C"<<endl;
      }else
    cout <<"D"<<endl;
    }
    else if(m +f <30){
      cout <<"F"<<endl;
    }
  }
  return 0;
}



Measured memory_bytes: 3148
#include <bits/stdc++.h>
 
#define forn(i, n) for (llong i = 0ll; i < (llong) n; ++i)
#define fornn(i, l, r) for (llong i = (llong) l; i < (llong) r; ++i)
#define size(x) ((int) (x.size()))
 
using namespace std;
 
typedef long long llong;
const llong inf = (llong) 1e+9 + 7ll;
const llong linf = (llong) 1e+18 + 7ll;
const long double eps = (long double) 1e-9;
const long double pi = acosl((long double) -1.0);
const int alph = 26;

mt19937 mrand(random_device{} ()); 

template<typename T, typename U> inline llong umin(const T& a, const U& b) { return a < b ? a : b; }
template<typename T, typename U> inline llong umax(const T& a, const U& b) { return a > b ? a : b; }
 
static char buff[(int) 2e6 + 17]; // reads std::string
const int maxn = (int) 3e6 + 17;

struct pt
{
	int x, y;
	pt() { }
};

struct fenwick
{
	int n;
	unordered_map<int, int> F;

	fenwick()
	{
		n = inf;
		F.rehash(1000000);
		F.max_load_factor(0.5);
	}

	void upd(int i, int x)
	{
		for (; i < n; i |= i + 1)
			F[i] = max(F[i], x);
	}

	int get(int i)
	{
		int res = 0;

		for (; i >= 0; i &= i + 1, --i)
			res = max(res, F[i]);

		return res;
	}
};

int n;
pt s, f;
pt p[maxn];

bool read()
{
	if (scanf("%d %d %d %d %d", &s.x, &s.y, &f.x, &f.y, &n) != 5)
		return false;

	forn (i, n)
		scanf("%d %d", &p[i].x, &p[i].y);

	return true;
}

bool cmp(pt a, pt b) { return make_pair(a.x, a.y) < make_pair(b.x, b.y); }

void solve()
{
	if (s.x > f.x)
		swap(s, f);

	if (s.y > f.y)
	{
		f.y = 2 * s.y - f.y;

		forn (i, n)
			p[i].y = 2 * s.y - p[i].y;
	}

	vector<pt> pp;

	forn (i, n)
		if (s.x <= p[i].x && p[i].x <= f.x && s.y <= p[i].y && p[i].y <= f.y)
			pp.push_back(p[i]);

	sort(pp.begin(), pp.end(), cmp);
	fenwick dp;

	forn (i, size(pp))
		dp.upd(pp[i].y, dp.get(pp[i].y) + 1);

	int lis = dp.get(inf);
	long double ans = 0;

	if (lis != min(f.y - s.y, f.x - s.x) + 1)
		ans = 100.0 * (f.y - s.y + f.x - s.x) - 20.0 * lis + 5 * M_PI * lis;
	else
		ans = 100.0 * (f.y - s.y + f.x - s.x) - 20.0 * lis + 5 * M_PI * (lis - 1) + 10 * M_PI;

	printf("%.15f\n", (double) ans);
}

int main()
{
#if SEREZHKA
	freopen("file.in", "r", stdin);
#endif

	while (read())
		solve();

	return 0;
}


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

bool f() {
  string s; cin >> s;
  string a = "keyence";
  int l = s.size();
  if (l < 7) return false;
  for (int i = 0; i < 8; i++) {
    if (s.substr(0, i) != a.substr(0, i)) return false;
    int j = 7-i;
    if (s.substr(l-j, j) == a.substr(7-j, j)) return true;
  }
  return false;
}

int main() {
  if (f()) cout << "YES" << endl;
  else cout << "NO" << endl;
}


Measured memory_bytes: 256
#include <cstdint>

using namespace std;

#define MEMO_SIZE 44
int64_t memo[MEMO_SIZE];

void fib_init()
{
  for (uint32_t i = 0; i < MEMO_SIZE; i++) {
    memo[i] = -1;
  }
}

uint32_t fib(uint32_t i)
{
  if (i == 0) {
    return memo[0] = 1;
  } else if (i == 1) {
    return memo[1] = 1;
  } else {
    int64_t val1 = memo[i - 1], val2 = memo[i - 2];
    if (val1 == -1) {
      val1 = memo[i - 1] = fib(i - 1);
    }

    if (val2 == -1) {
      val2 = memo[i - 2] = fib(i - 2);
    }

    return val1 + val2;
  }
}

#include <iostream>

int32_t main()
{
  fib_init();
  uint32_t i;
  cin >> i;
  cout << fib(i) << endl;
  return 0;
}

Measured memory_bytes: 3108
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {

		Scanner s = new Scanner(System.in);
		while (true) {
			int n = s.nextInt();
			int p = s.nextInt();

			if (n == 0 && p == 0)
				break;

			int[] candidates = new int[n];
			int cup = p;
			int count = 0;
			int winner = 0;

			while (true) {
				count %= n;
				if (cup != 0) {
					candidates[count]++;
					cup--;
				} else if (cup == 0 && candidates[count] != 0) {
					cup = candidates[count];
					candidates[count] = 0;
				}

				if (candidates[count] == p) {
					winner = count;
					break;
				}
				count++;

			}

			System.out.println(winner);

		}
	}
}

Measured memory_bytes: 20292
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = (int)(a); i <= (int)(n); ++i)
#define rrep(i, a, n) for (int i = (int)(a); i >= (int)(n); --i)
#define debug(x) cerr << #x << " = " << x << "\n"
#define debugv(x) \
  rep(f, 0, (x.size() - 1)) cerr << x[f] << (f == (x.size() - 1) ? "\n" : " ")
#define all(x) x.begin(), x.end()
#define int long long
using namespace std;
typedef pair<int, int> pii;
const int INF = ((1LL << 30) + (1LL << 29));
const int MOD = 1000000007;
template <typename T1, typename T2>
inline void chmin(T1 &a, T2 b) {
  if (a > b) a = b;
}
template <typename T1, typename T2>
inline void chmax(T1 &a, T2 b) {
  if (a < b) a = b;
}

int N, M, K;
string S, T;
vector<int> V;
void input() {
  cin>>N;
}
void solve() {
  // N=2 -> 1. N=13 -> 78, N=1 -> 0;

  cout<<N*(N-1)/2<<endl;
}
signed main() {
  input();
  solve();
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int lli;
#include <algorithm>

int main() {
  int n, k;
  cin >> n >> k;
  
  vector<lli> h(n);
  for(int i = 0; i < n; i++)
    cin >> h[i];
  sort(h.begin(), h.end());
  
  vector<lli> section(n-1);
  for(int i = 0; i < n-1; i++)
    section[i] = h[i+1] - h[i];
  
  //shakutori low
  lli shakutori = 0;
  lli min_shaku = 1145141919810;
  
  for(int i = 0; i < n-1; i++){
    //section is num(k-1) - 1
    //cout << shakutori << endl;
    shakutori += section[i];

    if(i >= k-1-1){
      if(min_shaku > shakutori)
        min_shaku = shakutori;
      shakutori -= section[i-(k-1-1)];
    }
  }
  
  cout << min_shaku << endl;
}


Measured memory_bytes: 1792
from math import ceil, log

log_2 = log(2)

def max2(x, y): return x if x >= y else y

def getNums(As, N):
    dp = list(range(16))
    nums = [0] * N
    for i in reversed(range(N - 1)):
        dx = ceil( log( As[i] / As[i+1] ) / log_2 / 2 )
        dp2 = [0] * 16
        for x in range(16):
            nx = x + dx
            if nx <= 15:
                dp2[x] = dp[max2(0, nx)] + x
            else:
                dp2[x] = dp[15] + x + (N - 1 - i) * (nx - 15)
        dp = dp2
        nums[i] = dp[0]
    return nums

N = int(input())
As = list(map(int, input().split()))

numPstvs = getNums(As, N)
numNgtvs = getNums(As[::-1], N)[::-1]

ans = float('inf')
for i, (p, m) in enumerate(zip(numPstvs + [0], [0] + numNgtvs)):
    ans = min(ans, 2 * p + 2 * m + i)
print(ans)


Measured memory_bytes: 128308
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
  input = input.split("\n")
  tmp0 = input[0].split(" ")
  S = tmp0[0].split("/")
  yyyy = Number(S[0])
  mm = Number(S[1])
  dd = Number(S[2])

  if(yyyy <= 2019 && mm <= 4 && dd <= 30){
    console.log("Heisei")
  }else{
    console.log("TBD")
  }
  
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
// Main("2019/11/01\n")

Measured memory_bytes: 21064