akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>

#define N1 10000
#define N2 500

int main(){
  int S[N1+1];
  int T[N2+1];
  int n,q,i,j,key;
  int count=0;
  
  scanf("%d", &n);
  for( i = 0; i < n; i++ ) scanf("%d", &S[i]);
  scanf("%d", &q);
  for( i = 0; i < q; i++ ) scanf("%d", &T[i]);

  for(i=0;i<q;i++){
    key=T[i];
    j=0;
    S[n]=key;
    while(S[j]!=key){
      j++;
      
    }
    if(j!=n){
      count++;
    }
  }

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

Measured memory_bytes: 640
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;


template <typename TYPE>
void print_vec(const vector<TYPE>& v){
	for(int i=0; i<v.size(); i++){
		cout << v[i] << " ";
	}
	cout << endl;
}

template <typename TYPE>
void print_vec2(const vector<vector<TYPE>>& v){
  cout << endl; cout << "       ";
  for(int i=0; i<v[0].size(); i++) cout << i << "   "; 
  cout << endl;
	for(int i=0; i<v.size(); i++){
		cout << "i=" << i << ":   ";
		for(int j=0; j<v[i].size(); j++){
			if(v[i][j] == 0) cout << "\x1B[0m" << v[i][j] << "   ";
      else cout << "\x1B[31m" << v[i][j] << "   ";//https://stackoverrun.com/ja/q/12618775
		}
		cout << "\x1B[0m" << endl;
	}
}


// UnionFind
// coding: https://youtu.be/TdR816rqc3s?t=726
// comment: https://youtu.be/TdR816rqc3s?t=6822
struct UnionFind {
  vector<int> d;
  UnionFind(int n=0): d(n,-1) {}
  int find(int x) {
    if (d[x] < 0) return x;
    return d[x] = find(d[x]);
  }
  bool unite(int x, int y) {
    x = find(x); y = find(y);
    if (x == y) return false;
    if (d[x] > d[y]) swap(x,y);
    d[x] += d[y];
    d[y] = x;
    return true;
  }
  bool same(int x, int y) { return find(x) == find(y);}
  int size(int x) { return -d[find(x)];}
};


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

	for(int i=0; i<M; i++){
		int x, y, z;
		cin >> x >> y >> z;
		x--; y--;
		uf.unite(x, y);
	}

	int ans = N;
	map<int, int> mp;
	for(int i=0; i<N; i++){
		int root = uf.find(i);
		// cout << "  i: " << i << " root: " << root << " uf.size(root): " << uf.size(root) << endl;
		if(mp[root] != 0) continue;
		mp[root]++;
		int size = uf.size(root);
		ans -= size-1;
	}

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


Measured memory_bytes: 8248
H, W, K = map(int, input().split())
L = [list(input()) for _ in range(H)]
ans = 0

for h_p in range(2 ** H):
    for w_p in range(2 ** W):
        count = 0
        for h in range(H):
            for w in range(W):
                if (h_p >> h) & 1 == 0 and (w_p >> w) & 1 == 0:
                    if (L[h][w] == '#'):
                        count += 1
        if count == K:
            ans += 1

print(ans)


Measured memory_bytes: 9052
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <cmath>
#include <map>
#include <climits>
#include <cassert>
#include <algorithm>
#include <utility>

using namespace std;
using Int = long long int;
using UInt = unsigned long long int;
using VI = vector<long long int>;
using VVI = vector<vector<long long int> >;

// 二つの値の最小値を求める関数
Int Min(const Int a, const Int b) {
    if (a <= b) {
        return a;
    } else {
        return b;
    }
}

int main(void) {
    Int l, r;
    cin >> l >> r;
    /*
    l = (l % 2019);
    r = (r % 2019);
    if (l >= r) {
        r += 2019;
    }
    */

    Int result = 2019;
    for (Int i = l; i <= r; ++i) {
        for (Int j = i + 1; j <= r; ++j) {
            result = Min(result, (i * j) % 2019);
            if (result == 0) {
                cout << 0 << endl;
                return 0;
            }
        }
    }
    cout << result << endl;
    return 0;
}


Measured memory_bytes: 3556
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <functional>
#include <utility>
#include <vector>
using ll = long long;
const ll ha = 924844033;
const ll bs = 5;
ll pow_mod(ll a, ll b) {
  ll ans = 1, res = a;
  while(b) {
    if(1LL & b) ans = ans * res % ha;
    res = res * res % ha; b >>= 1;
  }
  return ans;
}
ll inv(ll x) {
  return pow_mod(x, ha - 2LL);
}

ll fac[200005], ifac[200005];
void process() {
  int n = 200000;
  fac[0] = 1;
  for(int i = 1; i <= n; i ++) fac[i] = (ll)i * fac[i - 1] % ha;
  ifac[n] = inv(fac[n]);
  for(int i = n - 1; i >= 0; i --) ifac[i] = (ll(i + 1)) * ifac[i + 1] % ha;
}
ll C(int n, int m) {
  if(n < m) return 0;
  ll ret = fac[n] * ifac[n - m] % ha;
  ret = ret * ifac[m] % ha;
  return ret;
}

int flip(int bi, int x) {
  int ans = 0;
  for(int i = 0; i < bi; i ++) {
    if((1 << i) & x) {
      ans |= (1 << (bi - i - 1));
    }
  }
  return ans;
}
void NTT(ll *A, int bi, bool flag = false) {
  int n = 1 << bi;
  for(int i = 0; i < n; i ++) {
    int f = flip(bi, i);
    if(f < i) std::swap(A[f], A[i]);
  }
  for(int L = 1; L < n; L <<= 1) {
    ll xi_n = pow_mod(bs, (ha - 1LL) / (ll(L << 1)));
    if(flag) xi_n = inv(xi_n);
    for(int i = 0; i < n; i += (L << 1)) {
      ll xi = 1LL;
      for(int j = i; j < i + L; j ++) {
        ll x = A[j], y = A[j + L];
        A[j] = (x + (y * xi) % ha) % ha;
        A[j + L] = (x - (y * xi) % ha + ha) % ha;
        xi = xi * xi_n % ha;
      }
    }
  }
  if(flag) {
    ll inv_n = inv(n);
    for(int i = 0; i < n; i ++) A[i] = A[i] * inv_n % ha;
  }
}

std::vector<int> G[200005];
void add_edge(int u, int v) {
  G[u].push_back(v);
}
void ins_edge(int u, int v) {
  add_edge(u, v); add_edge(v, u);
}

ll a[800005], b[800005]; int siz[200005], n;
void dfs(int x, int fa = -1) {
  siz[x] = 1;
  for(int v : G[x]) {
    if(v != fa) {
      dfs(v, x);
      b[siz[v]] ++; b[n - siz[v]] ++;
      siz[x] += siz[v];
    }
  }
}

int main() {
  process();
  scanf("%d", &n);
  for(int i = 1; i <= n - 1; i ++) {
    int u, v; scanf("%d%d", &u, &v);
    ins_edge(u, v);
  }
  dfs(1);
  for(int i = 0; i <= n; i ++) {
    b[i] = b[i] * fac[i] % ha;
    a[i] = ifac[n - i];
  }
  int bi = 0, len = 1;
  while(len <= 2 * n) {
    bi ++; len <<= 1;
  }
  NTT(a, bi); NTT(b, bi);
  for(int i = 0; i < len; i ++) a[i] = a[i] * b[i] % ha;
  NTT(a, bi, true);
  for(int i = 1; i <= n; i ++) {
    ll ret = (ll)n * C(n, i) % ha;
    ret = (ret - a[n + i] * ifac[i] % ha + ha) % ha;
    printf("%lld\n", ret);
  }
  return 0;
}

Measured memory_bytes: 40064
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <cmath>
#include <cstdlib>

using namespace std;

int main(){
  int n,k;
  cin >> n >> k;

  vector<int> v;
  
  for(int i = 0; i < k; ++i){
    int s;
    cin >> s;
    v.push_back(s);
  }

  while(true){
    int d = n;
    int flag = 0;
    while(d > 0){
      for(int i = 0; i < v.size(); ++i){
        if(d%10 == v[i])
          flag++;
      }
      d /= 10;
    }
    if(flag == 0)
      break;
    ++n;
  }

  cout << n << endl;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(vecto) vecto.begin(),vecto.end()
typedef long long ll;

int main(){
    string s;
    cin >> s;
    sort(all(s));
    if(s=="abc"){
        cout << "Yes" << endl;
    }
    else
        cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, n) for (int i = 1; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;
int main()
{
    int n;
    cin >> n;
    vector<int> v(n);
    rep(i, n) cin >> v[i];

    // 奇数

    typedef std::pair<int, int> pair;
    vector<vector<pair> > change(2, vector<pair>());

    rep (_n, 2) {
        unordered_map<int, int> c;
        int total = 0;
        for (int i = _n; i < n; i += 2) {
            c[v[i]] = 0;
            total++;
        }
        for (int i = _n; i < n; i += 2) c[v[i]]++;

        for (auto kv: c) {
            change[_n].push_back(pair(kv.first, total - kv.second));
        }
        change[_n].push_back(pair(-1, total));
    }

    rep (i, 2) {
        sort(all(change[i]), [](const pair& lhs, const pair& rhs) {
            return lhs.second < rhs.second;
        });
    }

    int sum = change[0][0].second + change[1][0].second;
    if (change[0][0].first == change[1][0].first) {
        sum = min(
            change[0][0].second + change[1][1].second,
            change[0][1].second + change[1][0].second
        );
    }

    put(sum);

    return 0;
}

Measured memory_bytes: 6980
import math
A,B = map(int,input().split())
x1 = math.ceil(A / 0.08)
x2 = (A+1) / 0.08
y1 = math.ceil(B / 0.10)
y2 = (B+1) / 0.10

while x1 < x2:
    if y1 <= x1 < y2:
        print(x1)
        exit(0)
    x1 += 1
print(-1)

Measured memory_bytes: 9188
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<ll, ll>;
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
template<typename T> void chmin(T &a, const T &b) { a = min(a, b); }
template<typename T> void chmax(T &a, const T &b) { a = max(a, b); }
struct FastIO {FastIO() { cin.tie(0); ios::sync_with_stdio(0); }}fastiofastio;
#ifdef DEBUG_ 
#include "../program_contest_library/memo/dump.hpp"
#else
#define dump(...)
#endif
const ll INF = 1LL<<60;

int main(void) {
    ll n;
    cin >> n;
    vector<vector<ll>> g(n);
    REP(i, n-1) {
        ll p;
        cin >> p;
        p--;
        g[p].push_back(i+1);
        g[i+1].push_back(p);
    }
    dump(g);
    vector<ll> x(n);
    REP(i, n) cin >> x[i];

    dump(x);

    function<ll(ll,ll)> dfs = [&](ll v, ll p) {
        dump(v, p);
        vector<ll> ch, val;
        for(auto to: g[v]) {
            if(to == p) continue;
            ll tmp = dfs(to, v);
            if(tmp == INF) {
                cout << "IMPOSSIBLE" << endl;
                exit(0);
            }
            ch.push_back(to);
            val.push_back(tmp);
        }
        if(ch.size() == 0) return 0LL;
        vector<vector<ll>> dp(ch.size(), vector<ll>(x[v]+1, INF));
        {
            ll mi = min(x[ch[0]], val[0]), ma = max(x[ch[0]], val[0]);
            REP(i, min(x[v]+1, mi)) dp[0][i] = INF;
            FOR(i, mi, min(x[v]+1, ma)) dp[0][i] = ma;
            FOR(i, ma, x[v]+1) dp[0][i] = mi; 
        }
        FOR(i, 1, ch.size()) REP(j, x[v]+1) {
            if(j>=x[ch[i]]) chmin(dp[i][j], dp[i-1][j-x[ch[i]]] + val[i]);
            if(j>=val[i]) chmin(dp[i][j], dp[i-1][j-val[i]] + x[ch[i]]);
        }
        ll mi = INF;
        REP(i, x[v]+1) chmin(mi, dp[ch.size()-1][i]);
        return mi;
    };

    if(dfs(0, -1) < INF) cout << "POSSIBLE" << endl;
    else cout << "IMPOSSIBLE" << endl;

    return 0;
}

Measured memory_bytes: 2396
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cassert>
#include <vector>
#include <string>
#include <cmath>
#include <map> 
using namespace std;
 
const int MAX= 10000100;

#define loop(i,a,b) for(int i = a ; i < b ; i ++)
#define rep(i,a) loop(i,0,a)
#define all(a) (a).begin(),(a).end()
#define ll long long int
#define gcd(a,b) __gcd(a,b)

int GCD(int a, int b) {if(!b) return a; return gcd(b, a%b);}
int lcm(int a, int b) {return a*b / gcd(a, b);}

int main(void){
  string str;
  while(cin>>str){
    vector<int> card;
    vector<int> cnt(13,0);
    for(int i = 0 ; i < str.size() ; i ++){
      if('1' <= str[i] && str[1] <= '9'){
	if('0' <= str[i + 1] && str[i + 1] <= '9'){
	  int num = 10 + str[i + 1] - '0';
	  card.push_back(num);
	  cnt[--num] ++;
	  i ++;
	}else{
	  int num = str[i] - '0';
	  card.push_back(num);
	  cnt[--num] ++;
	}
      } 
    }
    sort(card.begin(),card.end());
    int ans[2][2] = {0,0,0,0};
    int c1,c2;
    c1 = c2 = 0;
    bool straight = false;
    rep(i,cnt.size()){
      if(cnt[i] == 1 && 
	 cnt[i + 1] == 1 && 
	 cnt[i + 2] == 1 && 
	 cnt[i + 3] == 1 && 
	 cnt[i + 4] == 1){
	straight = true;
	break;
      }
      if(cnt[i] > 1 && c1 == 0)
	c1 = cnt[i];
      else if(cnt[i] > 1)
	c2 = cnt[i];
    }
    if(straight)
      cout<<"straight";
    else if(c1 == 5)
      cout<<"five card";
    else if(c1 == 4 || c2 == 4)
      cout<<"four card";
    else if((c1 == 3 && c2 == 2) || 
	    (c1 == 2 && c2 == 3)) 
      cout<<"full house";
    else if(c1 == 3)
      cout<<"three card";
    else if(c1 == 2 && c2 == 2)
      cout<<"two pair";
    else if(c1 == 2)
      cout<<"one pair";
    else if(cnt[ 9] == 1 && 
	    cnt[10] == 1 && 
	    cnt[11] == 1 && 
	    cnt[12] == 1 && 
	    cnt[ 0] == 1)
      cout<<"straight";
    else 
      cout<<"null";
    cout<<endl;
    
    }
}

Measured memory_bytes: 1200
<?php

$n = trim(fgets(STDIN));
$s = trim(fgets(STDIN));

$s = str_split($s);

$array = [
    'R' => [],
    'G' => [],
    'B' => [],
];

$count = 0;
foreach ($s as $offset => $char) {
    $array[$char][] = $offset;
    if ($char === 'R') {
        $o1 = 'G';
        $o2 = 'B';
    } else if ($char === 'G') {
        $o1 = 'R';
        $o2 = 'B';
    } else if ($char === 'B') {
        $o1 = 'R';
        $o2 = 'G';
    }

    $limit = $offset / 2;
    for ($i=1;$i<=$limit;++$i) {
        if (
            $s[$offset - $i] === $o1 &&
            $s[$offset - $i - $i] === $o2 || 
            $s[$offset - $i] === $o2 &&
            $s[$offset - $i - $i] === $o1
        ) {
            ++$count;
        }
    }
}
$ans = count($array['R']) * count($array['G']) * count($array['B']) - $count;

echo $ans . PHP_EOL;



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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define debug(x) cout << #x << ": " << x << endl
#define out(x) cout << x << endl
//#define int long long int
const int MOD = 1000000007;
const ll LINF = (ll)1e18 - 1;
const int INF = 1e9 - 1;
const double EPS = 0.000000001;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

auto print = [](auto &v) {
  for(auto x : v) {
    cout << x << " ";
  }
  cout << endl;
};

ll pm(ll x, ll n, int mod) {
  ll powed = 1;
  while (n > 0)
  {
    if(n & 1) {
      powed *= x;
      powed %= mod;
    }
    x *= x;
    x %= mod;
    n >>= 1;
  }
  return powed;
}


signed main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n, a, b;
  cin >> n >> a >> b;
  ll ans = ((pm(2, n, MOD) - 1) + MOD) % MOD;
  ll c, d;
  c = d = 1;
  rep(i, a) {
    c *= (n-i);
    c %= MOD;
    d *= (a-i);
    d %= MOD;
  }
  d = pm(d, MOD-2, MOD);
  ll red1 = c * d % MOD;

  c = d = 1;
  rep(i, b) {
    c *= (n-i);
    c %= MOD;
    d *= (b-i);
    d %= MOD;
  }
  d = pm(d, MOD-2, MOD);
  ll red2 = c * d % MOD;

  out((ans - red1 - red2 + 3ll * MOD) % MOD);
  return 0;
}


Measured memory_bytes: 256
w,h,n= map(int,input().split())
kuro = [[0,w],[0,h]]
for i in range(n):
    x,y,a=map(int,input().split())
    if a==1:
        if kuro[0][0]<x:
            kuro[0][0]=x
    if a==2:
        if kuro[0][1]>x:
            kuro[0][1]=x
    if a==3:
        if kuro[1][0]<y:
            kuro[1][0]=y
    if a==4:
        if kuro[1][1]>y:
            kuro[1][1]=y
            
yoko = max(kuro[0][1]-kuro[0][0] , 0)
tate = max(kuro[1][1]-kuro[1][0] , 0)
print(yoko*tate)

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)
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; }
const ll MOD = 1e9+7;

int main(){
    int N;
    cin >> N;
    vector<ll> A;
    vector<ll> B;
    REP(i,N){
        ll a, b;
        cin >> a >> b;
        A.push_back(a);
        B.push_back(b);
    }

    ll ans = 0;
    for(int i = N-1; i >= 0; i--){
        ll a = A[i];
        ll b = B[i];
        a += ans;
        ll num;
        if(a == 0){
            num = 0;
        }
        else if(b > a)
            num = b - a;
        else
            num = (a/b + (a%b != 0))*b - a;

        //chmax(ans, num);
        ans += num;
        //cout << ans << endl;
    }

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


Measured memory_bytes: 2036
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;

const int N = 21;
ll dp[N+1][1<<N];
int comp[N][N];

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

	int n;
	cin >> n;
	for (int y = 0; y < n; ++y) {
		for (int x = 0; x < n; ++x) {
			cin >> comp[y][x];
		}
	}
	dp[0][0] = 1;
	for (int i = 0; i <= n; ++i) {
		for (int mask = 0; mask < (1<<n); ++mask) {
			if (dp[i][mask] == 0) continue;
			dp[i][mask] %= MOD;

			for (int j = 0; j < n; ++j) {
				if (! comp[i][j]) continue;
				if (mask & (1<<j)) continue;
				dp[i+1][mask | (1<<j)] += dp[i][mask];
			}
		}
	}
	int fullmask = (1<<n) - 1;
	cout << dp[n][fullmask] % MOD << '\n';
}


Measured memory_bytes: 309504
program main
	integer N, Y
	read(*, *) N, Y
	do i = 0, N
		do j = 0, N-i
			if(Y == 1000*i + 5000*j + 10000*(N-i-j)) then
				write(*, *) N-i-j, j, i
				goto 1
			end if
		end do
	end do
1 continue
	if(Y /= 1000*i + 5000*j + 10000*(N-i-j)) then
		write(*, *) -1, -1, -1
	end if
end program main

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define dofloat cout<<fixed<<setprecision(8)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define bitcount __builtin_popcount
#define all(vec) vec.begin(),vec.end()
#define rall(vec) vec.rbegin(),vec.rend()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<long long> vl;
typedef pair<long long,long long> pll;
typedef vector<pair<long long,long long> > vll;
typedef vector<pair<int,int> > vii;
typedef vector<int> vi;
typedef pair<int,int> ii;
const long long MOD=1000000007;
const long long MAX=100005;
const long double PI=3.14159265359;
const long double G=9.807;
const long long INF=1e18;
const long double EPS=1e-6;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
bool isprime(ll a){
  if(a==2)return 1;
  if(!(a&1))return 0;
  for(ll i=3;i*i<=a;i+=2)
    if(a%i==0)return 0;
  return 1;
}
ll mpow(ll base,ll exponent,ll modulus){
  if(modulus==1)return 0;
  long long result = 1;
  base=base%modulus;
  while(exponent){
    if(exponent%2 == 1)
    result=(result*base)%modulus;
    exponent=exponent>>1;
    base=(base*base)%modulus;
  }
  return result;
}
ll minv(ll a,ll mod){
  ll _gcd=gcd(a,mod);
  assert(_gcd==1);
  return mpow(a,mod-2,mod);
}


/*
ll ncr(ll N,ll K){
  if(N<K)return 0;
  if(K==0)return 1;
  if(N==0)return 0;

  ll den=1;
  for(ll i=1;i<=K;i++)den*=i;
  ll num=1;
  while(K--){
    num*=N;
    if(num%den==0){
      num/=den;
      den=1;
    }
    N--;
  }

  return num;
}
*/
ll n;
ll a[2005];
vll v;
ll dp[2005][2005],done[2005][2005];
ll solve(ll i,ll j){
  ll pos = i+n-1-j;
  if(pos == n) return 0;
  if(done[i][j])return dp[i][j];
  ll cost1 = v[pos].first*abs(v[pos].second-i);
  ll cost2 = v[pos].first*abs(v[pos].second-j);
  ll ans = max(solve(i+1,j)+cost1,solve(i,j-1)+cost2);
  done[i][j] = 1;
  return dp[i][j] = ans;
} 
int main(){FAST;
cin>>n;
ll curx = 1;
ll cury = n;
for(ll i=0;i<n;++i){
  cin>>a[i];
  v.push_back({a[i],i});
}
sort(rall(v));
cout<<solve(0,n-1);
return 0;
}

/*
 WA? check edge cases, N=1,M=1 etc. Read code fully once and check all variables.
 Read the question again and see what you might have missed.
 Consider changing your solution or find more cases.
 */


Measured memory_bytes: 49100
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.Arrays;
public class Main {
	static int N ;
	static int X ;
	static int Y ;

	public static void main(String[] args) throws Exception {
		// TODO 自動生成されたメソッド・スタブ

		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String W = in.readLine();
		String[] Ws = W.split(" ");

		int N = Integer.parseInt(Ws[0]);
		 X = Integer.parseInt(Ws[1]);
		 Y = Integer.parseInt(Ws[2]);

		 ArrayDeque<Integer> q = new ArrayDeque<>();
		 long[] dist = new long[N+1];
		 long[] C = new long[N+2];
		 Arrays.fill(dist,0);

		 for(int i=1;i<=N;i++){
			 Arrays.fill(C, Long.MAX_VALUE);
			 C[0]=0;
			 C[N+1]=0;
			 C[i]=0;
			 q.add(i);
			 while(!q.isEmpty()){
				 int num = q.remove();
				 if(C[num-1]==Long.MAX_VALUE){
					 q.add(num-1);
					 C[num-1]=C[num]+1;
				 }
				 if(C[num+1]==Long.MAX_VALUE){
					 q.add(num+1);
					 C[num+1]=C[num]+1;
				 }
				 if(num == X && C[Y]==Long.MAX_VALUE){
					 q.add(Y);
					 C[Y]=C[num]+1;
				 }
				 if(num == Y && C[X]==Long.MAX_VALUE){
					 q.add(X);
					 C[X]=C[num]+1;
				 }
			 }
			 for(int x=1;x<=N;x++){
				 dist[(int)C[x]]++;
			 }
		 }
		 for(int k=1;k<N;k++){
			 System.out.println(dist[k]/2);
		 }
	}
}

Measured memory_bytes: 43788
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> P;
const LL mod=1e9+7;
const LL LINF=1LL<<62;
const int INF=1<<17;



int main(){
    int N;
    cin >> N;
    vector<P> r,b;
    for(int i=0;i<N;i++){
        int a,b;
        cin >> a >> b;
        r.push_back(P(a,b));
    }
    sort(r.rbegin(),r.rend());
    for(int i=0;i<N;i++){
        int c,d;
        cin >> c >> d;
        b.push_back(P(c,d));
    }
    sort(b.begin(),b.end());
    int cnt=0;
    for(auto p:r){
        int t=INF;
        auto k=b.begin();
        for(auto q=b.begin();q!=b.end();q++){
            if(p.first<q->first&&p.second<q->second){
                if(q->second-p.second<t){
                    t=q->second-p.second;
                    k=q;
                }
            }
        }
        if(t==INF) continue;
        b.erase(k);
        cnt++;
    }
    cout << cnt << endl;
    return 0;
}

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

namespace _0500
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                int n = int.Parse(Console.ReadLine());
                if (n == 0) { break; }
                int a = 0;
                int b = a;
                for (int i = 0; i < n; i++)
                {
                    int[] s = Console.ReadLine().Split().Select(int.Parse).ToArray();
                    if (s[0] == s[1]) { a += s[0]; b += s[1]; }
                    else if (s[0] > s[1]) { a += s[0] + s[1]; }
                    else { b += s[0] + s[1]; }

                }
                Console.WriteLine(a + " " + b);
            }
        }
    }
}

Measured memory_bytes: 9712
#include <stdio.h>

int main(void) {
	int L;
	int c[1024];
	int i;
	int hayamisaori = 0;
	int hanazawakana[1024];
	char tamurayukari[128] = {0};
	if (scanf("%d", &L) != 1) return 1;
	for (i = 0; i < L; i++) {
		if (scanf("%d", &c[i]) != 1) return 1;
	}
	for (i = 0; i < L; i++) {
		if (c[i] > 0) {
			if (tamurayukari[c[i]]) {
				printf("%d\n", i + 1);
				return 0;
			}
			tamurayukari[c[i]] = 1;
			hanazawakana[hayamisaori++] = c[i];
		} else {
			if (hayamisaori <= 0 || hanazawakana[hayamisaori - 1] != -c[i]) {
				printf("%d\n", i + 1);
				return 0;
			}
			hayamisaori--;
			tamurayukari[-c[i]] = 0;
		}
	}
	puts("OK");
	return 0;
}



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

using namespace std;

int main(){
  long long input_data;
  long long tmp=5;
  long long ans=0;
  int i;

  cin >> input_data;

  if(input_data%2==0){
    while(tmp<input_data){
      ans = ans + input_data/(tmp*2);
      tmp*=5;
    }
    cout << ans << endl;
  }else{
    cout << 0 << endl;
  }

  return 0;
}


Measured memory_bytes: 256
package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	sc.Scan()
	n, _ := strconv.Atoi(sc.Text())

	d := make([]int, n - 1, n - 1)

	sc.Scan()
	h, _ := strconv.Atoi(sc.Text())
	for i := 0; i < n - 1; i++ {
		sc.Scan()
		tmp, _ := strconv.Atoi(sc.Text())
		d[i] = tmp - h
		h = tmp
	}

	answer := 0
	m := 0
	for i := 0; i < n - 1; i++ {
		if d[i] <= 0 {
			m++
		} else {
			m = 0
		}
		if m > answer {
			answer = m
		}
	}

	fmt.Println(answer)
}

Measured memory_bytes: 3072
import java.util.*;

public class Main {
     public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        PriorityQueue<Integer> queue = new PriorityQueue(new Comparator<Integer>() {
            public int compare(Integer i1, Integer i2) {
                return i2.intValue() - i1.intValue();
            }
        });
        for (int i = 0; i < n; i++) {
            queue.add(sc.nextInt());
        }
        for (int i = 0; i < m; i++) {
            queue.add(queue.poll() / 2);
        }
        long total = 0;
        while (queue.size() > 0) {
            total += queue.poll();
        }
        System.out.println(total);
    }
}


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

int main(){
	// sengen
	int n;
	// nyuryoku
	cin >> n;
	int a[n];
	for(int i=0;i<n;i++){
		cin >> a[i];
	}
	int count = 0;
	int num = 1;
	// keisan
	for(int i=0;i<n;i++){
		if(a[i] != num){
			count++;
		}else{
			num++;
		}
	}
	// syutsuryoku
	if(n == count){
		cout << "-1";
	}else{
		cout << count;
	}
}

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

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

    int n;
    cin>>n;
    char a[n+1],b[n+1],c[2*n+1];
    cin>>a>>b;
    for(int i=0; i<n; i++)
    {
        c[2*i]=a[i];
        c[2*i+1]=b[i];
    }
    c[2*n]=0;
    cout<<c<<'\n';
    return 0;
}

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

int main() {
  int A;
  cin >> A;
  int C;

  vector<int> B(A);
  for(int i = 0; i < A; i++){
    cin >> C;
    B.at(i) = C;
  }

  sort(B.begin(), B.end());
  reverse(B.begin(), B.end());

  int D = 1;

  for(int i = 0; i < A-1; i++){
    if(B.at(i) > B.at(i+1)){
      D++;
    }
  }

  cout << D << endl;
}



Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
using namespace std;
typedef long long ll;

char buf[10];

int main(void) {
  scanf("%s", buf);
  int res = 0;
  for(int i = 0; buf[i]; ++i) {
    if(buf[i] == '1') {
      ++res;
    }
  }
  printf("%d\n", res);
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int i = (int)(n); i >= 0; i--)
#define all(v) v.begin(),v.end()
typedef long long ll;

int main(){
    int N,X,T;
    cin >> N >> X >> T;
    if (N % X == 0) cout << (N / X) * T << endl;
    else cout << (N / X + 1) * T << endl;
}

Measured memory_bytes: 3616
S=input()
n=len(S)
l=[0]*13
l[0]=1
pr=10**9+7
for i in range(n):
    a=[0]*13
    p=pow(10,i,13)
    s=S[-i-1]
    if s=="?":
        for j in range(10):
            for k in range(13):
                a[(k+p*j)%13]+=l[k]%pr
    else:
        for k in range(13):
            a[(k+p*int(s))%13]+=l[k]%pr
    l=a
print(l[5]%pr)

Measured memory_bytes: 43244
package main
 
import (
	"fmt"
)
 
func main() {
	var n, k, x, y int
	fmt.Scan(&n, &k, &x, &y)
	if n <= k {
		fmt.Println(n * x)
		return
	}
	fmt.Println(k*x + (n-k)*y)
}

Measured memory_bytes: 512
#include <iostream>
#include <set>
#include <algorithm>
using namespace std;

#define V(a) a.begin(), a.end()
typedef set<int> s;

int main()
{
	s a[2], C;

	for (auto &i : a) {
		int n, x;
		cin >> n;
		while (n--) {
			cin >> x;
			i.insert(x);
		}
	}

	set_intersection(V(a[0]), V(a[1]), inserter(C, C.end()));

	cout << C.size() << endl;
}


Measured memory_bytes: 3112
#include <iostream>
#include <string>
#include<algorithm>
#include<functional>
using namespace std;

int main()
{ 
	string s, t;
	cin >> s;
	cin >> t;
	sort(s.begin(), s.end());
	sort(t.begin(), t.end(),greater<int>());
	
	if (s < t) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
		return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
 
long long gcd(long long a,long long b){
  if(b == 0) return a;
  return gcd(b,a%b);
}

long long lcm(long long a,long long b){
  long long g = gcd(a,b);
  return a/g*b;
}

int main(){
  
  long long int a,b[100010],c,d;
  cin >>a;
  
  for(int i=0;i<a;i++)
  cin >> b[i];

  sort(b,b+a);
  
  cout << b[a/2]-b[a/2-1] << endl;
  
}
  

Measured memory_bytes: 1024
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define N 2*10e5
#define precise cout<<fixed<<setprecision(10)
#pragma GCC optimize("O0")
#pragma GCC optimize ("Ofast")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize ("-ffloat-store")
#define rep(i,a,b) for(int i=a;i<b;i++)
#define min3(a,b,c) min(a,min(b,c))
#define nl cout<<"\n";
#define all(v) v.begin(),v.end()
#define F first
#define S second
typedef long long ll;
typedef vector<long long> vl;
typedef vector<pair<long,long>> vp;
void get(ll arr[],ll n){for(ll i=0;i<n;i++) cin>>arr[i];}
ll gcd(ll a,ll b);
ll binpow(ll a,ll b);
ll n,m,k;
ll a[200001],b[200001];
ll ar[200001],br[200001];
bool poss(ll mid)
{
	if(mid>n)
	{
		for(ll i=n,j=mid-n;i>=mid-m && j<=m;i--,j++)
		{
			ll t=0;
			if(i!=0) t+= ar[i-1];
			if(j!=0) t+= br[j-1];
			if(t<=k) return true;
		}
		return false;
	}
	else
	{
		for(ll i=mid,j=0;i>=mid-j && j<=m;i--,j++)
		{
			ll t=0;
			if(i!=0) t+= ar[i-1];
			if(j!=0) t+= br[j-1];
			if(t<=k) return true;
		}
		return false;
	}
}
ll bs(ll l,ll r)
{
	ll ans;
	while(l<=r)
	{
		ll mid= (l+r)/2 ;
		if(poss(mid)) ans=mid,l=mid+1;
		else r=mid-1;
		//cout<<mid;
	}
	return ans;
}
void solve()
{
    cin>>n>>m>>k;
    //if(n<m) swap(n,m);
    get(a,n),get(b,m);
    ar[0]=a[0],br[0]=b[0];
    rep(i,1,n) ar[i]=ar[i-1]+a[i];
    rep(i,1,m) br[i]=br[i-1]+b[i];
	cout<<bs(0,m+n);
}
int main()
{
 	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll t;
	t=1;
	//cin>>t;
	while(t--)
	{
	 	solve();
	}
	//cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}
ll binpow(ll a, ll b) {
   ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}
ll gcd(ll a,ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}


Measured memory_bytes: 9884
#include <iostream>
#include <fstream>
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>
#include <iomanip>
#include <set>
using namespace std;

int n;
string S[50];

int solve() {
	for(int k = 1; k <= 50; k++) {
		set<string> set;
		for(int i = 0; i < n; i++) {
			string s = S[i];
			string t;
			t += s[0];
			for(int j = 0; j < s.size() - 1; j++) {
				if(s[j] == 'a' || s[j] == 'i' || s[j] == 'u' || s[j] == 'e' || s[j] == 'o') {
					t += s[j + 1];
				}
			}
			t = t.substr(0, min(k, int(t.size())));
			set.insert(t);
		}
		if(set.size() == n) {
			return k;
		}
	}
	return -1;
}

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

	while(cin >> n, n) {
		for(int i = 0; i < n; i++) {
			cin >> S[i];
		}
		cout << solve() << endl;

	}
}

Measured memory_bytes: 3192
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] x = new int[n];
        int[] y = new int[n];
        int[] h = new int[n];
        int hc = 0;
        for (int i = 0 ; i < n ; i++) {
            x[i] = sc.nextInt();
            y[i] = sc.nextInt();
            h[i] = sc.nextInt();
            if (h[i] != 0) {
                hc = i;
            }
        }
        for (int cx = 0 ; cx <= 100; cx++) {
            for (int cy = 0; cy <= 100; cy++) {
                boolean isCenter = true;
                int H = Math.abs(x[hc] - cx) + Math.abs(y[hc] - cy) + h[hc];
                for (int i = 0 ; i < n ; i++) {
                    int div = Math.abs(x[i] - cx) + Math.abs(y[i] - cy);
                    if (h[i] != Math.max(H - div , 0)) {
                        isCenter = false;
                    }
                }
                if (isCenter) {
                    System.out.println(cx+ " " + cy + " " + H);
                    return;
                }
            }
        }

    }

}

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

int main() {
//    freopen("in.txt", "r", stdin);
//    freopen("out.txt", "w", stdout);
  int n;
  cin >> n;
  int a[n], b[n];

  ll sum, res;
  sum = 0;
  res = 1e10;
  for(int i = 0;i < n;i++){
    cin >> a[i] >> b[i];
    sum += a[i];
    if(a[i] > b[i]){
      res = min(1LL * b[i], res);
    }
  }
  if(res == 1e10)
    cout << 0;
  else
    cout << sum - res;
  return 0;
}


Measured memory_bytes: 512
class Dice(object):
    def __init__(self, faces):
        self.top = faces[0]
        self.front = faces[1]
        self.right = faces[2]
        self.left = faces[3]
        self.back = faces[4]
        self.bottom = faces[5]

    def rotate(self, command):
        pre_top = self.top
        if command == "N":
            self.top = self.front
            self.front = self.bottom
            self.bottom = self.back
            self.back = pre_top
        elif command == "E":
            self.top = self.left
            self.left = self.bottom
            self.bottom = self.right
            self.right = pre_top
        elif command == "W":
            self.top = self.right
            self.right = self.bottom
            self.bottom = self.left
            self.left = pre_top
        elif command == "S":
            self.top = self.back
            self.back = self.bottom
            self.bottom = self.front
            self.front = pre_top
        elif command == "R":
            pre_front = self.front
            self.front = self.left
            self.left = self.back
            self.back = self.right
            self.right = pre_front


def main() -> None:
    dice_values = list(map(int, input().split()))
    dice_x = Dice(dice_values)

    q = int(input())
    for i in range(q):
        top, front = map(int, input().split())
        for j in range(6):
            if top == dice_x.top:
                break
            dice_x.rotate("N")
        for j in range(6):
            if top == dice_x.top:
                break
            dice_x.rotate("E")
        while front != dice_x.front:
            dice_x.rotate("R")
        print(dice_x.right)


if __name__ == "__main__":
    main()


Measured memory_bytes: 5604
a1,a2,b1,b2=gets.split.map &:to_i
c1 = b1-(b2-a2)
c2 = b2+(b1-a1)
d1 = c1-(c2-b2)
d2 = c2+(c1-b1)
p c1,c2,d1,d2

Measured memory_bytes: 1788
n,a,b=map(int,input().split())
if a==0 and b!=0:
    print(0)
elif a!=0 and b==0:
    print(n)
elif a==0 and b==0:
    print(0)
else:
    x=(n//(a+b))*a 
    y=min(n%(a+b),a)
    print(x+y)

Measured memory_bytes: 3060
#include <stdio.h>
#include <string.h>
#define MAX 100
int main(void) {
    int N, i, j, ans=0;
    
    char S[MAX];
    
    scanf("%d", &N);
    scanf("%s", S);
    
    int len = strlen(S);
    for(i=0; i<len; i++) {
        int history[2][26]={0};
        for(j=0; j<=i; j++)
            history[0][S[j]-'a']++;
        
        for(j=i+1; j<len; j++)
            history[1][S[j]-'a']++;
        
        int cnt = 0;
        for(j=0; j<26; j++) {
            if(history[0][j]>0 && history[1][j]>0)
                cnt++;
        }
        
        if(ans<cnt)
            ans = cnt;
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define repr(i,n) for(ll i=(n-1);i>=0;i--)
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define br cout << endl;
using namespace std;
const int INF = 1e9;
const int MOD = 1e9+7;
using Graph = vector<vector<ll>>;
template<class T> inline bool chmin(T &a, T b) { if(a > b){ a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b) { if(a < b){ a = b; return true;} return false;}

// 0 false, 1 true 
// stringの数字をint型にしてアスキーコードになったら -48する
// 切り上げ　ceil(a)
// コンパイル　g++ -std=c++17 a.cpp

vector<ll> unit_label;
vector<ll> union_size;
ll current_size;
void dfs(const Graph &G, ll v, const ll &label){
    unit_label[v] = label;
    current_size++;
    for(ll next_node : G[v]){
        if(unit_label[next_node] != -1){
            continue;
        }else{
            dfs(G, next_node, label);
        }
    }

}

int main() {
    ll n, m, k;
    cin >> n >> m >> k;

    vector<ll> friend_num(n, 0);
    Graph G(n);
    for (ll i = 0; i < m; i++) {
        ll a, b;
        cin >> a >> b;
        a--;
        b--;

        //無向グラフ
        G[a].push_back(b); G[b].push_back(a);
        friend_num.at(a)++;
        friend_num.at(b)++;
    }

    unit_label.assign(n,-1);
    ll label = 0;
    rep(i,n){
        if(unit_label[i] == -1){
            current_size = 0;
            dfs(G, i, label);
            union_size.push_back(current_size);
            label++;
        } 
    }

    vector<ll> block_num(n, 0);
    for (ll i = 0; i < k; ++i) {
        ll a, b;
        cin >> a >> b;
        a--;
        b--;
        if(unit_label.at(a) == unit_label.at(b)){
            block_num.at(a)++;
            block_num.at(b)++;
        }
    }

    /*
    rep(i,n){
        cout << unit_label.at(i) << " ";
    }
    cout << endl;
    
    rep(i,label){
        cout << union_size.at(i) << " ";
    }
    cout << endl;
    */

    rep(i,n){
        cout << union_size.at(unit_label.at(i)) - 1 - friend_num.at(i) - block_num.at(i) << " ";
    }
    cout << endl;


}

Measured memory_bytes: 10496
N=int(input())
p=[float(x) for x in input().split()]
dp=[[0 for j in range(N+5)] for i in range(N+5)]
dp[0][0]=1
for i in range(N):
    for j in range(i+1):
        dp[i+1][j+1] += dp[i][j]*p[i]
        dp[i+1][j] += dp[i][j]*(1-p[i])
M =(N+1)//2
result = 0
for i in range(M,N+1):
    result += dp[N][i]
print(result)

Measured memory_bytes: 257544
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <vector>
#include <cstdio>
#include <string>
#include <cstring>
#include <iostream>
#include <algorithm>

#define x first
#define y second

#define INF 0x3f3f3f3f

using namespace std;

typedef long long LL;
typedef pair<int,int>PII; 

int a[5][5];
int cnt[5][5];

int main(void) {
	for(int i = 1; i <= 3; i ++) {
		for(int j = 1; j <= 3; j ++) {
			cin >> a[i][j];
		}
	}
	int n,value;
	cin >> n;
	while(n --) {
		cin >> value;
		bool vis = false;
		for(int i = 1; i <= 3; i ++) {
			for(int j = 1; j <= 3; j ++) {
				if(a[i][j] == value) {
					vis = true;
					cnt[i][j] = 1;
					break;
				}
			}
			if(vis) break;
		}
	}
	if((cnt[1][1] == 1 && cnt[1][2] == 1 && cnt[1][3] == 1) || (cnt[2][1] == 1 && cnt[2][2] == 1 && cnt[2][3] == 1) ||
		(cnt[3][1] == 1 && cnt[3][2] == 1 && cnt[3][3] == 1) || (cnt[1][1] == 1 && cnt[2][1] == 1 && cnt[3][1] == 1) ||
		(cnt[1][2] == 1 && cnt[2][2] == 1 && cnt[3][2] == 1) || (cnt[1][3] == 1 && cnt[2][3] == 1 && cnt[3][3] == 1) ||
		(cnt[1][1] == 1 && cnt[2][2] == 1 && cnt[3][3] == 1) || (cnt[1][3] == 1 && cnt[2][2] == 1 && cnt[1][3] == 1)
	) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  int a,b,c,d,e = 0;
  for (int i =0;i<N;i++){
    string s;
    cin >> s;
    //桃色を P、白色を W、緑色を G、黄色を Y と
    if(s =="P"){
      a++;
    }else if(s == "W"){
      b++;
    }else if(s =="G"){
      c++;
    }else if(s =="Y"){
     d++;
    }
  }
  if(a!= 0)e++;
  if(b!=0)e++;
  if(c!=0)e++;
  if(d!=0)e++;
 // cout << e<<endl;
  if(e==3){
    cout << "Three" << endl;
  }else {
    cout << "Four"<<endl;
  }   
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main() {
	//min(a,b)...a,bの小さいほう
	//max(a,b)...     大きいほう
	int a;
	int b;
	int c;
	int d;
	int e;
	std::cin >> a >> b;
	if (b % a == 0) {
		cout << a + b << "\n";
	}
	else {
		cout << b - a << "\n";
	}
	
	std::cin >> e;
}

Measured memory_bytes: 256
//Robs Code

/***********HEADER***************/
#include <iostream>
#include <bitset>
#include <deque>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <algorithm>
#include <list>
#include <vector>
#include <unordered_set>
#include <unordered_map>
#include <stack>
#include <set>
#include <queue>
#include <map>
#include <iomanip>

/***********MACROS***************/
#define int long long int
#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()
#define endl "\n"
#define pb push_back
#define _1 first
#define _2 second
#define pii pair<int,int>

using namespace std;

const int N = 1e5 + 1;
int n,m,i,j,k,l,x,y,z,cnt[3],sum[3];

/***********MAIN**************/
const int M = 998244353;
int power(int x, int y){
    x %= M;
    int ans = 1;
    while(y){
        if(y & 1)
            ans = (ans * x) % M;
        y >>= 1LL;
        x = (x * x) % M;
    }
    return ans;
}
int add(int a, int b){
    return((a % M + b % M) % M);
}
int sub(int a, int b){
    return((a % M - b % M + M) % M);
}
int mul(int a, int b){
    return(((a % M) * (b % M)) % M);
}
int divi(int a, int b){
    return(mul(a, power(b, M - 2)) % M);
}
int a[3001];
int dp[3001][3001];
int brute(int i,int s){
	if(s < 0){
		return 0;
	}
	if(s == 0){
		return power(2,n - i);
	}
	if(i == n){
		return 0;
	}
	if(dp[i][s] != -1){
		return dp[i][s];
	}
	dp[i][s] = (2 * brute(i + 1,s) + brute(i + 1,s - a[i])) % M;
	return dp[i][s];
}
signed main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	cin >> n >> m;
	for(int i = 0;i < n;i++){
		cin >> a[i];
	}
	memset(dp,-1,sizeof dp);
	cout << (brute(0,m));
}
//.........

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

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
  
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
 
#define FS              ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll              long long int
#define ld              long double
#define pb              push_back
#define bp              __builtin_popcount
#define sz              size()
#define ff              first
#define ss              second
#define vll             vector<ll>
#define vbool           vector<bool>
#define vpll            vector<pair<ll,ll>>
#define pll             pair<ll,ll>
#define vllv            vector<vector<ll>>
#define setpri(x)       cout<<setprecision(x)<<fixed;
#define all(v)          v.begin(),v.end()
#define allr(v)         v.rbegin(),v.rend()
#define yesr {cout<<"YES"<<endl;return;}
#define nor {cout<<"NO"<<endl;return;}
// getline (std::cin,name);
ll MOD=1e9+7;
ll ceil1(ll n,ll x){return (n-1)/x+(n>0);}

ll gcd(ll a,ll b){return __gcd(a,b);}
ll lcm(ll a,ll b){return (max(a,b)/gcd(a,b))*min(a,b);}

ll pow1(ll n,ll m ,ll mod=MOD );
ll pow2(ll n,ll k);

ll modinv(ll n,ll mod=MOD){  return pow1(n,mod-2,mod);}

bool func(pair<ll,ll> &a,pair<ll,ll> &b ){
        if(a.ff != b.ff)return a.ff < b.ff;
        return a.ss > b.ss;
}

ll const N=(ll)2e5+11;
ll const LG=(ll)log2(N)+1;


void solve(){
        ll i,j,k,l,n,m,x,y,z,r;
      
      vll a(5);
      for(i=0;i<5;i++){
              cin>>a[i];
      }
      cin>>k;
      n=5;
      for(i=0;i<n;i++){
              for(j=i+1;j<n;j++){
                      if(a[j]-a[i]>k){
                              cout<<":(";
                              return;;
                      }
              }
      }
        
        cout<<"Yay!\n";
        
        
}       
int main(){
        FS;
        
        ll i,j,k,n,m,x,y,z,q;
        q=1;
        // cin>>q;
        for(ll tc=1;tc<=q;tc++){
                // cout<<"Case #"<<tc<<": ";
                solve();
        }
        return 0;
}


ll pow1(ll n,ll m,ll mod){
        if(m==0)return 1;
        
        if(m%2==0)return pow1((n*n)%mod,m/2,mod);
    	
    	return (pow1((n*n)%mod,m/2,mod)*n)%mod;
}

ll pow2(ll n,ll k){
        ll ans=1;
            while(k>0){
                if(k%2==1)ans=ans*n;
                n=n*n;
                k/=2;
            }
            return ans;
}


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

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

  ll n;
  cin >> n;

  vector<char> v;
  vector<char> vc = {
    'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'
  };

  ll r = n / 26;
  ll q = n % 26;

  if(q == 0){
    r = r-1;
    q = 26;
  } 

  v.push_back(vc.at(q-1));

  while (r > 0)
  {
    q = r % 26;
    r = r / 26;
    if(q == 0)
    {
      r = r-1;
      q = 26;
    } 
    v.push_back(vc.at(q-1));
  }
  reverse(v.begin(), v.end());

  for (int i = 0; i < v.size(); i++)
  {
    cout << v.at(i);
  }
  cout << endl;
  

  return 0;
}

Measured memory_bytes: 3640
N, K = map(int, input().split())
S = list(map(int, input()))

cnt = 0
now = 1
Nums = []

for i in range(N):
    if S[i] == now:
        cnt += 1
    else:
        Nums.append(cnt)
        now = 1 - now
        cnt = 1

if cnt != 0:
    Nums.append(cnt)
if len(Nums) % 2 == 0:
    Nums.append(0)

add = 2*K+1
ans = 0
left = right = 0
tmp = 0

for i in range(0, len(Nums), 2):
    Nextleft = i
    Nextright = min(i+add, len(Nums))
    
    while Nextleft > left:
        tmp -= Nums[left]
        left += 1
    
    while Nextright > right:
        tmp += Nums[right]
        right += 1
    
    ans = max(tmp, ans)

print(ans)

Measured memory_bytes: 4768
import itertools

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

k = []
for _ in range(M):
    k.append(list(map(int, input().split()))[1:])

p = list(map(int, input().split()))

ans = 0
for i, s in enumerate(itertools.product([0,1],repeat=N)):
    if all([sum([s[j-1] for j in v])%2==t  for v,t in zip(k, p)]):
        ans += 1
print(ans)

            




Measured memory_bytes: 3064
#include <stdio.h>
int main()
{
	char input[101];
	int a, b;
	scanf("%d %d", &a, &b);
	scanf("%s", input);
	int flag = 0;
	int ctr = 0;
	for(int i = 0; i < a+b+1; i++)
	{
		if(input[a+1-1] != '-')
		{
			flag = 1;
			break;
		}
		if(input[i] >= '0' && input[i] <= '9')
		{
			ctr++;
		}
	}
	if(flag == 0 && ctr == a+b)
	{
		puts("Yes");
	} else
	{
		puts("No");
	}
	
	
	return 0;
	
}

Measured memory_bytes: 1664
N = int(input())
Fs = [list(map(int, input().split())) for i in range(N)]
Ps = [list(map(int, input().split())) for i in range(N)]

cnts = [0] * 10
for F in Fs:
    for i,f in enumerate(F):
        cnts[i] += f

ans = -10**10
for i in range(1,2**10):
    bs = list(bin(i)[2:].zfill(10))
    cnt_all = 0
    for fs,ps in zip(Fs, Ps):
        cnt = 0
        for i in range(10):
            if int(bs[i]) * int(fs[i]) == 1:
                cnt += 1
        cnt_all += ps[cnt]
    ans = max(cnt_all,ans)
    # print(bs,cnt)
print(ans)

Measured memory_bytes: 3064
//#define NDEBUG

#include <bits/stdc++.h>

#define StarBurstStream ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define iter(a) a.begin(), a.end()
#define riter(a) a.rbegin(), a.rend()
#define lsort(a) sort(iter(a))
#define gsort(a) sort(riter(a))
#define mp(a, b) make_pair(a, b)
#define pb(a) push_back(a)
#define pf(a) push_front(a)
#define pob pop_back()
#define pof pop_front()
#define F first
#define S second
#define printv(a, b) {bool pvaspace=false; \
for(auto pva : a){ \
    if(pvaspace) b << " "; pvaspace=true;\
    b << pva;\
}\
b << "\n";}
#define pii pair<int, int>
#define pll pair<ll, ll>
#define modadd(a, b) (((a % MOD) + (b % MOD)) % MOD)
#define modtimes(a, b) (((a % MOD) * (b % MOD)) % MOD)

//#define TEST

typedef long long ll;
typedef unsigned long long ull;

using namespace std;

const ll MOD = 1000000007;
const ll MAX = 2147483647;

int main(){
    StarBurstStream

    int n, k;
    cin >> n >> k;

    string s;
    cin >> s;

    int cnt = 0;
    int ans = 0;

    for(int i = 0; i < n; i++){
        if(i == 0 || s[i] != s[i - 1]) cnt++;
        if(s[i] == 'L' && i != 0 && s[i - 1] == s[i])
            ans++;
        if(s[i] == 'R' && i != n - 1 && s[i + 1] == s[i])
            ans++;
    }

    cout << min(n - 1, ans + 2 * k) << "\n";

    return 0;
}

Measured memory_bytes: 512