akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

class EdgeTable : public map<uint64_t, set<uint64_t>> {};

inline uint64_t match_node(uint64_t x, uint64_t y)
{
  return (min(x, y) << 10) + max(x, y);
}

static array<bool, 2000000> visited;
static array<bool, 2000000> finished;
static array<uint64_t, 2000000> cache;

const uint64_t NotFound = -1;

uint64_t search_dfs(uint64_t src, const EdgeTable &edges)
{
  if (visited[src]) {
    if (!finished[src]) {
      return NotFound;
    } else {
      return cache[src];
    }
  }
  
  cache[src] = 1;
  visited[src] = true;
  
  if (edges.find(src) == edges.end()) {
    finished[src] = true;
    
    return cache[src];
  }
  
  for (auto &dst : edges.at(src)) {
    uint64_t ret = search_dfs(dst, edges);
    
    if (ret == NotFound) {
      return NotFound;
    }
    
    if (ret + 1 > cache[src]) {
      cache[src] = ret + 1;
    }
  }
  
  finished[src] = true;
  
  return cache[src];
}

int main()
{
  uint64_t N;
  cin >> N;
  
  vector< vector<uint64_t> > A(N);
  for (uint64_t n = 0; n < N; ++n) {
    A[n] = vector<uint64_t>(N - 1);
    for (uint64_t m = 0; m < N - 1; ++m) {
      cin >> A[n][m];
      --A[n][m];
    }
  }
  
  EdgeTable edges;
  for (uint64_t n = 0; n < N; ++n) {
    for (uint64_t m = 0; m < N - 2; ++m) {
      edges[match_node(n, A[n][m])].insert(match_node(n, A[n][m + 1]));
    }
  }
  
  set<uint64_t> match_set;
  for (uint64_t n = 0; n < N; ++n) {
    for (uint64_t m = 0; m < n; ++m) {
      match_set.insert(match_node(n, m));
      cache[match_node(n, m)] = NotFound;
    }
  }
  
  uint64_t max_depth = 0;
  for (uint64_t start : match_set) {
    uint64_t depth = search_dfs(start, edges);
    
    if (depth == NotFound) {
      cout << -1 << endl;
      return 0;
    }
    
    if (max_depth < depth) { max_depth = depth; }
  }
  
  cout << max_depth << endl;
  
  return 0;
}

Measured memory_bytes: 137600
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
using ll = long long;
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;};

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

  Int n;
  cin>>n;
  vector<Int> ss(n),ls(n),ps(n);
  for(Int i=0;i<n;i++) cin>>ss[i]>>ls[i]>>ps[i];

  const Int MAX = 500;
  const Int INF = 1e15;
  vector<Int> dp(MAX,-INF);
  dp[0]=0;
  for(Int i=0;i<n;i++)
    for(Int j=0;j<MAX;j++)
      for(Int k=ss[i];k<=ls[i];k++)
        if(j+k<MAX) chmax(dp[j+k],dp[j]+ps[i]);

  Int m;
  cin>>m;
  vector<Int> ws(m);
  for(Int i=0;i<m;i++) cin>>ws[i];

  auto NG=[](){cout<<-1<<endl;exit(0);};
  for(Int i=0;i<m;i++)
    if(dp[ws[i]]<0) NG();

  for(Int i=0;i<m;i++) cout<<dp[ws[i]]<<endl;
  return 0;
}



Measured memory_bytes: 3228
// In the Name of God

#include <bits/stdc++.h>

using namespace std;

#define	ll long long
#define ull unsigned long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define sz(a) int(a.size())
#define all(v) v.begin(), v.end()
#define bpc(v) __builtin_popcountll(v)
#define itr iterator
#define rep(i, a, b) for (int i = a; i <= b; ++i)
#define per(i, a, b) for (int i = a; i >= b; --i)
#define ub upper_bound
#define lb lower_bound

const int N = 1e5 + 5;
const ll mod = 1e9 + 7;
const int inf = 1e9 + 1;
const double eps = 1e-15;
const int pw = 257;

int n;
ll a[N], f[N], res, t[N * 4];

void upd(int v, int l, int r, int L, int R, ll val) {
	if (r < L || R < l)
		return;
	if (L <= l && r <= R) {
		t[v] = (t[v] + val) % mod;
		return;
	}
	int mid = (l + r) >> 1;
	upd(v + v, l, mid, L, R, val);
	upd(v + v + 1, mid + 1, r, L, R, val);
}

ll get(int v, int l, int r, int pos) {
	if (l == r) 
		return t[v];
	int mid = (l + r) >> 1;
	if (pos <= mid)
		return (t[v] + get(v + v, l, mid, pos)) % mod;
	else
		return (t[v] + get(v + v + 1, mid + 1, r, pos)) % mod;
}

/*
inline ll calc(int l, int r) {
	ll res = 1;
	rep(i, l, r)
		res = (res * i) % mod;
	return res;
}
*/

ll binpow(ll a, ll b) {
	ll res = 1;
	while (b) {
		if (b % 2 == 1)
			res = (res * a) % mod;
		a = (a * a) % mod;
		b /= 2;
	} 
	return res;
}

int main() {
	#ifdef Madi
	freopen(".in", "r", stdin);
	freopen(".out", "w", stdout);
	#endif

	cin >> n;
	rep(i, 1, n)
		cin >> a[i];

	f[0] = 1;
    rep(i, 1, n)
    	f[i] = (f[i - 1] * i) % mod;	

    rep(i, 1, n) {
    	upd(1, 1, n, 1, n - i + 1, f[n] * binpow(i, mod - 2));
    	if (i > 1)
    		upd(1, 1, n, i, n, f[n] * binpow(i, mod - 2));
    }
	/*upd(1, 1, n, 1, n, f[n]);
	rep(d, 1, n - 1) {
		ll ans = 0;
		ll p = 1, q = 0;
		rep(k, 1, d)
			p = (p * k) % mod;
		q = (q + p) % mod;

		rep(k, 1, n - d - 1) {
			p = ((p * binpow(k, mod - 2)) % mod * (k + d)) % mod;
			q = (q + p) % mod;
		}
		ans = (ans + (f[n - d - 1] * q) % mod) % mod;
		cerr << ans << ' ';
		upd(1, 1, n, 1, n - d, ans);
		upd(1, 1, n, d + 1, n, ans);
	}
	*/
	rep(i, 1, n)  {
//		cout << get(1, 1, n, i) << ' ';
		res = (res + (get(1, 1, n, i) * a[i]) % mod) % mod;
	}
//	cout << "\n";

	cout << res;

	#ifdef Madi
    cerr << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
    #endif
	return 0;
}

Measured memory_bytes: 4992
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;

const int N=5e5+1e3+7;

int n,a[N],f[N];

int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	for(int i=1;i<=n;i++)
		f[a[i]]=f[a[i]-1]+1;
	int mx=0;
	for(int i=1;i<=n;i++)
		mx=max(mx,f[i]);
	printf("%d",n-mx);
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define MAXN 100000

int h[MAXN];
int dp[MAXN];
int n;

int main() {
	int i;
	scanf("%d",&n);
	for (i=0; i<n;i++) {
		scanf("%d",&h[i]);
	}
	dp[n-1]=0;
	dp[n-2]=abs(h[n-1]-h[n-2]);
	for (i=n-3; i>=0; i--) {
		dp		[i]=min(abs(h[i]-h[i+1])+dp[i+1], abs(h[i]-h[i+2])+dp[i+2]);
	}
	
	printf("%d\n",dp[0]);
	return 0;
}

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

using namespace std;

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

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

    int cnt = 0;
    for (int i = 0; i < n - 1; i++)
        if (inp[i] == i + 1) {
            swap(inp[i], inp[i + 1]);
            cnt++;
        }
    if (inp[n - 1] == n)
        cnt++;

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

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

int main() {
  int N;
  cin >> N;
  vector<long long> A(N), B(N);
  for (int i = 0; i < N; ++i) cin >> A[i] >> B[i];

  long long res = 0;
  for (int i = N-1; i >= 0; --i) {
	A[i] += res;
	long long r = A[i] % B[i];
	if (r != 0) r = B[i] - r;
	res += r;
  }
  cout << res << endl;
}


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

int findSumOfDigits(int n) {
  int sum = 0;
  while (n > 0) {
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

int main() {
  int n,a,b;
  cin >> n >> a >> b;
  int ans=0;
  for(int i=1; i<=n; i++){
    int sum = findSumOfDigits(i);
    if(a <= sum && sum <= b) ans += i;
  }
  cout << ans << endl;
}

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

using namespace std;

const long double pi = acosl(-1);

int main() {
  int x1, y1, x2, y2;
  cin >> x1 >> y1 >> x2 >> y2;

  if (x1 > x2) {
    swap(x1, x2);
    swap(y1, y2);
  }
  int s = y1 <= y2 ? 1 : -1;
  y1 *= s;
  y2 *= s;

  int n;
  cin >> n;

  map<int, int> mp;

  for (int i = 0; i < n; i++) {
    int x, y;
    cin >> x >> y;
    y *= s;

    if (x1 <= x && x <= x2 && y1 <= y && y <= y2) {
      mp[x] = y;
    }
  }

  vector<int> lis(mp.size(), 1e9);

  for (auto kv : mp) {
    *upper_bound(lis.begin(), lis.end(), kv.second) = kv.second;
  }

  int l = lower_bound(lis.begin(), lis.end(), 1e9) - lis.begin();

  long double ans = ((x2 - x1) + (y2 - y1)) * 100LL;
  if (x2 - x1 + 1 == l || y2 - y1 + 1 == l) {
    l--;
    ans += (180 + 10 * pi - 200);
  }

  ans -= (200 - 180 - 5 * pi) * l;

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

Measured memory_bytes: 10368
import java.util.*;

class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int[] a = new int[3];
		for(int i = 0; i < 3; i++){
			a[i] = sc.nextInt();
		}
		Arrays.sort(a);
		System.out.print(a[2]*10+a[1]+a[0]);
	}
}


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

#ifdef LOCAL
#include "../../dump.hpp"
#else
#define dump(...)
#endif

#define int ll
#define rep(i,n) for(int i=0,i##_cond=(n);i<i##_cond;++i)
#define FOR(i,a,b) for(int i=(a),i##_cond=(b);i<i##_cond;++i)
#define ROF(i,a,b) for(int i=(a)-1,i##_cond=(b);i>=i##_cond;--i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend() //sortで大きい順
#define sz(x) ((int)(x).size())
#define pb push_back
#define fst first
#define snd second
#define mp make_pair
using ll  = long long;
using vi  = vector<int>;
using vvi = vector<vi>;
using vs  = vector<string>;
using pii = pair<int,int>;
constexpr ll inf = 1ll<<61;
constexpr ll mod = 1e9+7;
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T>void add(T &a, const T &b){a += b; a %= mod;}

vvi g;
vi d;
vi ans;
stack<int> st;
priority_queue<int,vi,greater<int>> c;

void dfs(){ // sを根としてbfs  
  while(!st.empty()){
    int next = st.top();
    st.pop();
    d[next]--;
    ans[next] = c.top();
    c.pop();
    
    rep(i, g[next].size()){
      int n = g[next][i];
      if(d[n] > 0) d[n]--;
      if(d[n] <= 0) continue;
      
      if(d[n] == 1){
	st.push(n);
      }
    }
  }
}

signed main(){
  int n; cin >> n;
  g.resize(n);
  d.resize(n);
  ans.resize(n,-1);
  rep(i,n-1){
    int a, b; cin >> a >> b;
    a--; b--;
    d[a]++; d[b]++;
    g[a].pb(b);
    g[b].pb(a);
  }
  
  rep(i,n){
    int tmp; cin >> tmp;
    c.push(tmp);
  }
  rep(i,n){
    if(d[i] == 1){
      st.push(i);
    }
  }
  dfs();
  int ansc = accumulate(all(ans),0ll) - *max_element(all(ans));
  cout << ansc << endl;
  rep(i,n-1) cout << ans[i] << " ";
  cout << ans[n-1] << endl;
}


Measured memory_bytes: 1280
#include <iostream>
using namespace std;
int main() {
int i;
int n;
cin>>n;
string s;
cin>>s;
if(n%2!=0)
{
  cout<<"No";
  
}
else
{
    int t=n/2;
    
for( i=0;i<n/2;i++)
{
    if(s[i]!=s[t+i])
    {
        cout<<"No";
        break;
    }
}
if(i==n/2)
cout<<"Yes";
}
return 0;
}

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

int main() {
	int n;
	cin >> n;
	string k = "Yes";
	if(n < 18)
	{
		int nd = n;
		for(int i = 0;i < 4;i++)
		{
			nd -= i * 7;
			if(nd < 0)
			{
				k = "No";
			}
			else
			{
				if(nd % 4 == 0)
				{
					break;
				}
			}
			
		}
	}
    cout << k << endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<iomanip>
using namespace std;

int main() {
    int N, K; cin >> N >> K;
    string S; cin >> S;

    int ans = 0;
    bool is_reverse = false;
    int cnt = 0;
    for (int i = 0; i < N - 1; i++) {
        if (!is_reverse && S[i] == S[i + 1]) {
            ans++;
            continue;
        }
        if (cnt < K && !is_reverse && S[i] != S[i + 1]) {
            is_reverse = true;
            ans++;
            cnt++;
            continue;
        }
        if (is_reverse && S[i] == S[i + 1]) {
            ans++; 
            continue;
        }
        if (is_reverse && S[i] != S[i + 1]) {
            is_reverse = false;
            ans++;
            continue;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

#define REP(i, n) for(int i = 0;i < n;i++)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define ALL(a) (a).begin(), (a).end()

using namespace std;

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

    unsigned long long sum = 0;

    sum = ((unsigned long long)1 << M) * (1900 * M + (N - M) * 100);

    cout << sum << endl;

    return 0;
}


Measured memory_bytes: 256
while True:
    a, b, c = input().split()
    d = int(a)
    e = int(c)
    if b == '+':print(d + e)
    if b == '-':print(d - e)
    if b == '*':print(d * e)
    if b == '/':print(d // e)
    if b == '?':break



Measured memory_bytes: 5596
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)

const ll MOD = (ll)1e9 + 7;
const ll HIGHINF = (ll)1e18;

int main() {
  ll n; cin >> n;
  vll v(n);
  ll ans = 0;
  REP(i, n) cin >> v.at(i);
  REP(i, n) {
    for (ll j=n-1; j>i; j--) {
      if (v.at(j) < v.at(j-1)) {
        swap(v.at(j), v.at(j-1));
        ans++;
      }
    }
  }
  cout << v.at(0);
  rep(i, 1, n) cout << ' ' << v.at(i);
  cout << endl;
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 3108
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <queue>

#define INF (1e+9)
#define LLINF (1e+18)
#define LL long long

using namespace std;

int num;
int array[128];
LL dp[128][32] = {0};


int main (void){

	for(int i=0;i<128;i++){
		for(int j=0;j<32;j++){
			dp[i][j] = 0;
		}
	}
	dp[0][0] = 1;

	scanf("%d",&num);
	for(int i=0;i<num;i++){
		scanf("%d",array+i);
	}
	

	for(int i=0;i<num-1;i++){
		for(int j=0;j<21;j++){
			if(dp[i][j] != 0){
				if(j + array[i] <= 20){
					dp[i+1][j + array[i]] += dp[i][j];
				}
				if(j - array[i] >= 0){
					if(i != 0)dp[i+1][j - array[i]] += dp[i][j];
				}
			}
		}
	}
	/*for(int i=0;i<=20;i++){
		for(int j=0;j<4;j++){
			printf("%lld\t",dp[j][i]);
		}
		printf("\n");
	}
	printf("###%lld\n",dp[0][0]);*/

	printf("%lld\n",dp[num-1][array[num - 1]]);



	return 0;
}

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

int main() {
  int n, m;
  cin >> n;
  int sqn = sqrt(n);
  vector<int> v(n + 1, 0);
  for(int i = 1;i <= sqn;i++) {
    for(int j = 1;j <= sqn;j++) {
      for(int k = 1;k <= sqn;k++) {
        m = i*i+j*j+k*k+i*j+j*k+k*i;
        if(m <= n) v[m]++;
      }
    }
  }
  for(int i = 1;i < n+1;i++) cout << v[i] << endl;
}

Measured memory_bytes: 3660
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define SZ(x) ((int)x.size())
#define ALL(x) x.begin(),x.end()
#define L(i,u) for (register int i=head[u]; i; i=nxt[i])
#define rep(i,a,b) for (register int i=(a); i<=(b); i++)
#define per(i,a,b) for (register int i=(a); i>=(b); i--)
using namespace std;
typedef long double ld;
typedef long long ll;
typedef unsigned int ui;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
typedef vector<int> Vi;
template<class T> inline void read(T &x){
	x=0; char c=getchar(); int f=1;
	while (!isdigit(c)) {if (c=='-') f=-1; c=getchar();}
	while (isdigit(c)) {x=x*10+c-'0'; c=getchar();} x*=f;
}
template<class T> T gcd(T a, T b){return !b?a:gcd(b,a%b);}
template<class T> inline void umin(T &x, T y){x=x<y?x:y;}
template<class T> inline void umax(T &x, T y){x=x>y?x:y;}
mt19937 R(chrono::system_clock().now().time_since_epoch().count());

ll a,b,c,d,t;
ll Abs(ll x){return x>0?x:-x;}
int main() {
	read(a);read(b);
	read(c);read(d);
	read(t);
	if(Abs(a-c)<=(b-d)*t)cout<<"YES";else cout<<"NO";
	return 0;
}


Measured memory_bytes: 3636
#! env python
# -*- coding: utf-8 -*-

import os
import sys


# ac_py.main
# Date: 2020/06/14
# Filename: main 
# Author: acto_mini

def main():
    N, K = map(int, input().split())
    # all = K ** N
    # out_single, out_multi = 0, 0
    # for i in range(2, N + 1):
    #     out_multi += (N - i + 1) * K
    print(K * ((K - 1) ** (N - 1)))
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 38256
#include<bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int l[N], r[N], n , m;
map <int, int> mp;
int cnt[N];
inline int read () {
    int tot = 0, f = 1; char c = getchar ();
    while (c < '0' || c > '9') { if (c == '-') f = -1; c = getchar (); }
    while (c >= '0' && c <= '9') { tot = tot * 10 + c - '0'; c = getchar (); }
    return tot * f;
}
signed main () {
    n = read (); m = read ();
    for (int i = 1; i <= n; i++) {
        l[i] = read (); r[i] = read ();
    }
    for (int i = 0; i < m; i++) mp[i] = i;
    cnt[0] = m;
    int ans = 0;
    for (int i = 1; i <= n; i++) {
        l[i]--; r[i]--;
        auto it = mp.lower_bound (l[i]);
        int pos = -1;
        while (it != mp.end () && it->first <= r[i] + 1) {
            pos = max (pos, it->second);
            cnt[it->first - it->second] --;
            it = mp.erase (it);
        }
        if (pos >= 0 && r[i] + 1 < m) {
            mp[r[i] + 1] = pos;
            cnt[r[i] + 1 - pos]++;
        }
        while (!cnt[ans] && ans < m) ans++;
        if (ans == m) printf ("-1\n");
        else printf ("%d\n", i + ans);
    }
    return 0;
}


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

ll inf=1ll<<60;

int main()
{
	//freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
	ios_base::sync_with_stdio(false); cin.tie(0);
	ll n,k,i,t1,t2,a[100001]={0};
	cin>>n>>k;
	for (i=0;i<n;i++){
		cin>>t1>>t2;
		a[t1]+=t2;
	}
	for (i=1;i<100001;i++){
		if (a[i]>0){
			if (k<=a[i]){
				cout<<i;
				break;
			}
			else {
				k-=a[i];
			}
		}
	}
	return 0;
}

Measured memory_bytes: 1152
n,k = map(int,input().split())

a = [-1 for _ in range(n)]
for i in range(k):
	d = int(input())
	A = list(map(int,input().split()))
	for j in range(d):
		a[A[j]-1] += 1

ans = 0
for i in range(n):
	if a[i] == -1:
		ans += 1

print(ans)


Measured memory_bytes: 9192
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>

using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
signed main(){
  string s;cin>>s;
  int n=(int)s.length();
  int mae=(n+1)/2;
  int ato=n/2;
  int sum=0;
  rep(i,n){
    if(s[i]=='p'&&i<mae)sum--;
    else if(s[i]=='g'&&i>=mae)sum++;
  }
  cout<<sum<<endl;
  return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define RREP(i, n) for (int i = n - 1; 0 <= i; i--)
#define FOR(i, start, end) for (int i = start; i < end; i++)
#define RFOR(i, start, end) for (int i = start - 1; 0 <= i; i--)
#define ALL(a) a.begin(), a.end()
using ll = long long;
using namespace std;
const int INF32       = 1'050'000'000;
const long long INF64 = 4'000'000'000'000'000'000;
const int MOD7        = 1'000'000'007;
const int MOD9        = 1'000'000'009;
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;
}
void print() { std::cout << '\n'; }
template <class H, class... T> void print(H &&head, T &&... args) {
    std::cout << head;
    sizeof...(args) == 0 ? std::cout << "" : std::cout << ' ';
    print(std::forward<T>(args)...);
}
template <class T> void print(std::vector<T> &v) {
    for (int i = 0; i < v.size(); i++) {
        std::cout << v[i];
        i == v.size() - 1 ? std::cout << '\n' : std::cout << ' ';
    }
}
template <class T> void print(std::vector<std::vector<T>> &v) {
    for (int i = 0; i < v.size(); i++) {
        for (int j = 0; j < v[i].size(); j++) {
            std::cout << v[i][j];
            j == v[i].size() - 1 ? std::cout << '\n' : std::cout << ' ';
        }
    }
}

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

    int N, M;
    cin >> N >> M;
    vector<string> a(N), b(M);
    for (auto &&i : a) {
        cin >> i;
    }
    for (auto &&i : b) {
        cin >> i;
    }
    REP(i, N - M + 1) {
        REP(j, N - M + 1) {
            bool f = true;
            REP(y, M) {
                REP(x, M) {
                    if (a[y + i][x + j] != b[y][x]) {
                        f = false;
                        break;
                    }
                }
            }
            if (f) {
                print("Yes");
                return 0;
            }
        }
    }
    print("No");

    return 0;
}

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

typedef long long ll;
typedef pair <ll, ll> pii;
const int N = 1e5 + 10, inf = 1e9;

ll deg[N], n, dp[N];
vector <int> adj[N];

void dfs(int v, int p = -1) {
	ll ans = 0;
	int cnt = 0;
	for (auto u : adj[v]) {
		if(u == p) 	continue;
		dfs(u, v);
		dp[v] += dp[u];
		if(dp[u] == 0)
			cnt++;
	}
	if(cnt)
		dp[v] += cnt - 1;
}

int main() {
	// task
	ios_base::sync_with_stdio(0), cin.tie(0);
	cin >> n;
	for (int i = 0; i < n - 1; i++) {
		int v, u;
		cin >> v >> u;
		adj[v].push_back(u), adj[u].push_back(v);
		deg[v]++, deg[u]++;
	}
	ll root = inf;
	for (int i = 0; i < n; i++) {
		if(deg[i] > 2)
			root = min(root, i * 1LL);
	}
	if(root == inf) {
		cout << 1 << "\n";
	}
	else {
		dfs(root);
		cout << dp[root] << "\n";
	}
}

Measured memory_bytes: 11520
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda:sys.stdin.readline().rstrip()
from heapq import heappop,heappush
def resolve():
    n,m,s,t=map(int,input().split())
    s-=1; t-=1
    E=[[] for _ in range(n)]
    R=[[] for _ in range(n)]
    for _ in range(m):
        u,v,a,b=map(int,input().split())
        u-=1; v-=1
        E[u].append((v,a))
        E[v].append((u,a))
        R[u].append((v,b))
        R[v].append((u,b))

    # Dijkstra with heapq
    dist1=[INF]*n
    dist1[s]=0
    Q=[(0,s)]
    while(Q):
        d,v=heappop(Q)
        if(dist1[v]<d): continue
        for nv,w in E[v]:
            if(dist1[nv]>dist1[v]+w):
                dist1[nv]=dist1[v]+w
                heappush(Q,(dist1[nv],nv))

    dist2=[INF]*n
    dist2[t]=0
    Q=[(0,t)]
    while(Q):
        d,v=heappop(Q)
        if(dist2[v]<d): continue
        for nv,w in R[v]:
            if(dist2[nv]>dist2[v]+w):
                dist2[nv]=dist2[v]+w
                heappush(Q,(dist2[nv],nv))

    # s -> v -> t の最短を計測する
    dist=[dist1[v]+dist2[v] for v in range(n)]
    # 後ろから min をとる
    for i in range(n-1,0,-1):
        dist[i-1]=min(dist[i-1],dist[i])

    M=10**15
    for v in range(n):
        print(M-dist[v])
resolve()

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

#define pb push_back
#define F first
#define S second
#define y1 dasdasfasfas
#define x1 wqdadfasfasfas
#define All(c) c.begin(), c.end()
#define SZ(A) (int((A).size()))
#define umap unordered_map
#define __ fflush(stdout)
#define FILENAME ""

typedef long long ll;
typedef long double ld;    

using namespace std;

void FREOPEN() {
	#ifdef LOCAL
		freopen(".in", "r", stdin);
		freopen("1.out", "w", stdout);
	#else
		//freopen(FILENAME".in", "r", stdin);
		//freopen(FILENAME".out", "w", stdout);
	#endif
}

inline double Time() {return (clock() * 1.0) / CLOCKS_PER_SEC; }             

const int N = 200500, inf = 1e9 * 2;

const ll MOD = 1e9 + 7ll, INF = 1e18;

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

bool was[N];

int mex[N], a[N]; 

int n;

int dfs(int k) {
	if (was[k]) return mex[k];
	was[k] = 1;
	vector<bool> step(101, 0);
	for (int i = 1; i <= n; i++) {
		if (k >= a[i]) step[dfs(k - a[i])] = 1;
	}
	mex[k] = 0;
	while (step[mex[k]]) mex[k]++;
	return mex[k];
}

int main() {
	FREOPEN();
	int k;
	cin >> n >> k;
	for (int i = 1; i <= n; i++) scanf("%d ", &a[i]);
	if (dfs(k)) puts("First");
	else puts("Second");
	return 0;
}


Measured memory_bytes: 13312
S = input()

mod = 10 ** 9 + 7
N = len(S)
dp = [[0 for _ in range(13)] for _ in range(10 ** 5 + 5)]
dp[0][0] = 1

for i in range(N):
    c = 0
    if S[i] == "?":
        c = -1
    else:
        c = int(S[i])
    for j in range(10):
        if c != -1 and c != j:
            continue
        for k in range(13):
            dp[i+1][(k * 10 + j) % 13] += dp[i][k]
    for j in range(13):
        dp[i+1][j] %= mod

print(dp[N][5])


Measured memory_bytes: 66780
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl '\n'
int n, a, b, c, d;
string field;
void fail() {
	cout << "No";
	exit(EXIT_SUCCESS);
}
void case1() {
	int inc = 0;
	for (int i = b; i <= d; i++) {
		char& ch = field[i];
		if (ch == '#') inc++;
		else inc = 0;
		if (inc >= 2) {
			fail();
		}
	}
	inc = 0;
	for (int i = a; i <= c; i++) {
		char& ch = field[i];
		if (ch == '#' || i == d) inc++;
		else inc = 0;
		if (inc >= 2) {
			fail();
		}
	}
}
void case2() {
	int inc = 0;
	for (int i = a; i <= c; i++) {
		char& ch = field[i];
		if (ch == '#') inc++;
		else inc = 0;
		if (inc >= 2) fail();
	}
	bool ok = false;
	inc = 0;
	for (int i = b - 1; i <= d+1; i++) {
		char& ch = field[i];
		if (ch == '.') inc++;
		else inc = 0;
		if (inc >= 3) {
			ok = true;
			break;
		}
	}
	if (!ok) fail();
}
int main() {
	
	cin >> n >> a >> b >> c >> d;
	a--;
	b--;
	c--;
	d--;
	cin >> field;
	if (c < d) case1();
	else case2();


	cout << "Yes";
	return 0;
}

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

int main() {
  int N, X;
  cin >> N >> X;
  vector<int> x(N);
  for (int i = 0; i < N; i++) cin >> x.at(i);
  x.push_back(X);
  int ans = 0;
  sort(x.begin(), x.end());
  for (int i = 0; i + 1 < x.size(); i++) {
    ans = __gcd(ans, x.at(i + 1) - x.at(i));
  }
  cout << ans << "\n";
}

Measured memory_bytes: 1024
import java.util.*;
import java.io.*;
import java.math.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int r = sc.nextInt();
        int s = sc.nextInt();
        int p = sc.nextInt();
        String t = sc.next();
        char[] c = t.toCharArray();
        int now = 0;
        long ans = 0;
        while(true){
            int tmp = t.indexOf("r",now);
            if(tmp == -1){
                break;
            }else if(tmp-k >= 0 && c[tmp-k] == 'r'){
                c[tmp] = 'd';
            }else{
                ans += p;
            }
            now = tmp+1;
        }
        now = 0;
        while(true){
            int tmp = t.indexOf("p",now);
            if(tmp == -1){
                break;
            }else if(tmp-k >= 0 && c[tmp-k] == 'p'){
                c[tmp] = 'd';
            }else{
                ans += s;
            }
            now = tmp+1;
        }
        now = 0;
        while(true){
            int tmp = t.indexOf("s",now);
            if(tmp == -1){
                break;
            }else if(tmp-k >= 0 && c[tmp-k] == 's'){
                c[tmp] = 'd';
            }else{
                ans += r;
            }
            now = tmp+1;
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 27040
n = int(input())
a = [0]*120
for i in range(n):
    b, f, r, v = map(int, input().split())
    t = (b - 1) * 30 + (f - 1) * 10 + r - 1
    a[t] += v
for i in range(120):
    print(' %d'  % a[i], end="")
    if i % 10 == 9:
        print("")
    if i % 30 == 29 and i < 100:
        for c in range(20):
            print("#", end="")
        print("")


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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,M;
    cin >> N >> M;
    cout << ((N*(N-1)) + (M*(M-1)))/2 << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef pair<int,int> pint;
typedef pair<long long, long long> pll;

#define MP make_pair
#define PB push_back
#define ALL(s) (s).begin(),(s).end()
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P) 
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P) 
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P) 
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P) 
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s; }

int n;
ll a[10100];

int main() {
    while (cin >> n) {
        if (n == 0) break;
        for (int i = 0; i < n; ++i) cin >> a[i];
        sort(a, a+n);
        ll res = 0;
        ll sum[10100] = {0};
        for (int i = 0; i < n; ++i) {
            sum[i+1] = sum[i] + a[i];
            res += sum[i];
        }
        cout << res << endl;
    }
    return 0;
}


Measured memory_bytes: 1344
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
    static int[] w = new int[100010];
    static int[] v = new int[100010];
    static int[][] dp = new int[110][100010];
    static int k;

    static int chmin(int a, int b) {
        if (a > b) {
            a = b;
            return a;
        }
        return a;
    }

    static int chmax(int a, int b) {
        if (a < b) {
            a = b;
            return a;
        }
        return a;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int train = sc.nextInt();
        int fTrain = sc.nextInt();
        int bus = sc.nextInt();
        int fBus = sc.nextInt();
        System.out.println(Math.min(train, fTrain) + Math.min(bus, fBus));

    }
}


Measured memory_bytes: 79956
// abc153_d
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF ((1 << 29)-1)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
#define print_line(vec, n) {for(int i=0;i<(n-1);i++) cout << (vec)[i] << " "; cout << (vec)[(n)-1] << endl;}
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;

int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif

    ll H;
    cin >> H;

    ll cnt = 1;
    ll ans = 0;
    ll cur = H;

    if (H == 1){
        print(1);
        return 0;
    }
    
    while (true){

        ans += cnt;
        cur /= 2;
        cnt *= 2;

        if (cur == 1){
            ans += cnt;
            break;
        }
    }

    print(ans);


    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a, b;
  cin >> a >> b;
  int x = (a * b) % 2;

  if (x == 1) {
    cout << "Odd" << endl;
  }
  else
  {
    cout << "Even" << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
  int n;
  int X, Y, W, H;
  int num_of_cats;
  int m;
  int x, y;
  
  cin >> n;

  while (n--) {
    cin >> X >> Y >> W >> H;
    cin >> m;
    num_of_cats = 0;
    while (m--) {
      cin >> x >> y;
      if (x >= X && x <= X + W
          && y >= Y && y <= Y + H) {
        num_of_cats++;
      }
    }
    cout << num_of_cats << endl;
  }
}
      



Measured memory_bytes: 3024
#include <iostream>
#include <cstdio>
#include <vector>

using namespace std;

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

	vector<int> foods(m + 1, 0);
	for (int i = 0; i < n; i++) {
		cin >> k;
		for (int j = 0; j < k; j++) {
			cin >> a;
			foods[a]++;
		}
	}

	int ans = 0;
	for (int x: foods) {
		if (x == n) {
			ans++;
		}
	}

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


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

int MOD(int a){
	return (a %= p) >= 0 ? a : a + p;
}

int power(int a, int N){
	if(N == 0){
		return 1;
	}
	else if(N % 2 == 0){
		return power(MOD(a * a), N / 2);
	}
	else{
		return MOD(a * power(a, N - 1));
	}
}

int inverse(int a){
	return power(a, p - 2);
}

vector<int> fact, fact_inv;

int comb(int N, int k){
	return MOD(fact[N] * MOD(fact_inv[k] * fact_inv[N - k]));
}

int solve(int T, int N){
//	printf("solve(%lld, %lld)\n", T, N);
	int i, j;
	vector<int> A(N + 1, 0);
	A[0] = T + 1;
	for(i = 1; i <= N; i++){
		A[i] = power(T + 1, i + 1);
//		printf("A1[%lld] = %lld\n", i, A[i]);
		for(j = 2; j <= i + 1; j++){
			A[i] = MOD(A[i] - comb(i + 1, j) * A[i - j + 1]);
//			printf("A%lld[%lld] = %lld\n", j, i, A[i]);
		}
		A[i] = MOD(A[i] * inverse(i + 1));
	}
	for(i = 0; i <= N; i++){
//		printf("A[%lld] = %lld\n", i, A[i]);
	}
//	printf("A[N] = %lld\n", A[N]);
	return A[N];
}

signed main(){
	int N, S, i;
	scanf("%lld%lld", &N, &S);
	fact.assign(N + 1, 1);
	for(i = 1; i <= N; i++){
		fact[i] = MOD(i * fact[i - 1]);
	}
	fact_inv.assign(N + 1, 1);
	for(i = 0; i <= N; i++){
		fact_inv[i] = inverse(fact[i]);
	}
	int ans = MOD(MOD(power(S + 1, N) - power(S + 1, N - 1)) * inverse(2));
//	printf("ans0 = %lld\n", ans);
	if(S % 2 == 0){
		ans = MOD(ans + power(2, N - 1 + 1) * solve(S / 2, N - 1) - solve(S, N - 1));
	}
	else{
		ans = MOD(ans + solve(S, N - 1) - power(2, N - 1 + 1) * solve(S / 2, N - 1));
	}
	printf("%lld\n", ans);
/*	for(i = 0; i < 3; i++){
		printf("solve(%lld) = %lld\n", i, solve(i, 10));
	}
*/	return 0;
}


Measured memory_bytes: 3224
#include<iostream>
#include<cstdio>
using namespace std;
typedef long long LL;
int main() {
	LL taka, aoki, k;
	bool turn = true;
	//true=taka
	cin >> taka >> aoki >> k;
	while (k--) {
		//taka
		if (turn) {
			if (taka & 1)taka--;
			aoki += taka / 2;
			taka /= 2;
			turn = false;
		}
		//aoi
		else{
			if (aoki & 1)aoki--;
			taka += aoki / 2;
			aoki /= 2;
			turn = true;
		}
	}
	cout << taka << " " << aoki;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>

typedef struct tree_{
    int parent;
    int left;
    int right;
}tree;

void postorder(tree *node, int id){
    if(node[id].left!=-1){
        postorder(node, node[id].left);
        printf(" ");
    }
    if(node[id].right!=-1){
        postorder(node, node[id].right);
        printf(" ");
    }
    printf("%d",id);
}

int reconstruct(int *pre, int *in, tree *node, int n){
    if(n==0)return -1;
    int root = pre[0];
    int n1, n2;
    for(n1=0;n1<n;n1++){
        if(in[n1]==root)break;
    }
    n2 = n - n1 - 1;
    node[root].left = reconstruct(pre+1, in, node, n1);
    node[root].right = reconstruct(pre+1+n1, in+1+n1, node, n2);
    return root;
}

int main(){
    int i, n;
    scanf("%d",&n);
    int pre[n];
    int in[n];
    tree node[n];
    for(i=0;i<n;i++)scanf("%d",pre+i);
    for(i=0;i<n;i++)scanf("%d",in+i);
    int root = reconstruct(pre, in, node, n);
    postorder(node, root);
    printf("\n");
    return 0;
}



Measured memory_bytes: 2740
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
ll mm=1000000000;ll MM=mm+7;
#define rep(i, n) for(int i=0;i<n;i++)
 


int main(){
  int n;
  cin >> n;
  vector<ll> a(n);
  ll sum=0;
  rep(i,n){
    cin >> a.at(i);
    sum+=a.at(i);
  }
  int k;
  ll suma=0;
  rep(i,n){
    suma+=a.at(i);
    if(2*suma>=sum){
     k=i;
      break;
    }
  }
  ll sumb=suma-a.at(k);
  ll difa=2*suma-sum;
  ll difb=sum-2*sumb;
  ll ans=min(difa,difb);
  cout << ans << endl;
  
}

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


int ASC(const void *a, const void *b) {
	return *(int *)b - *(int *)a;//降順
}
int GCD(int a, int b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}
long long a[200000];
int main(void)
{
	long long n, syain;
	scanf("%lld",&n);
	for (long long i = 0; i < n; i++) {
		a[i] == 0;
	}
	for (long long i = 2; i <= n; i++) {
		scanf("%lld", &syain);
		a[syain]++;
	}
	for (long long i = 1; i <= n; i++) {
		printf("%lld\n",a[i]);
	}
	return 0;
}

Measured memory_bytes: 3268
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<int64_t> A(N+1);
  vector<int64_t> B(N+1);
  for(int i=1;i<N+1;i++){
    cin >> A.at(i);
  }
  
  for(int i=1;i<N+1;i++){
     B.at(A.at(i))++;
  }
  int64_t x=0;
  for(int j=1;j<N+1;j++){  
     x=x+((B.at(j))*(B.at(j)-1))/2;
  }
  for(int k=1;k<N+1;k++){
    int64_t z=A.at(k);
    int64_t y=x-(B.at(z)*(B.at(z)-1)/2)+((B.at(z)-1)*(B.at(z)-2)/2);
    cout << y << endl;
  }
    
}
  
  

Measured memory_bytes: 5760
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
using namespace std;
#define MOD 1000000007
#define INF (1<<29)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;

vector<Int> a, b;
Int n, k;

Int shugyo(Int x){
    Int need = 0;
    for(int i = 0;i < n;i++){
        need += max(0LL, a[i] - (x / b[i]));
    }
    return need;
}

int main(){
    cin >> n >> k;
    a.resize(n);
    b.resize(n);
    for(int i = 0;i < n;i++)cin >> a[i];
    for(int i = 0;i < n;i++)cin >> b[i];

    sort(a.begin(), a.end());
    sort(b.rbegin(), b.rend());
    
    Int bottom = 0, top = 1100000000000;
    while(top - bottom > 1){
        Int mid = (top + bottom) / 2;
        if(shugyo(mid) <= k)top = mid;
        else bottom = mid;
    }
    if(shugyo(0) <= k)top = 0;
    cout << top << endl;
    return 0;
}

Measured memory_bytes: 3328
import java.io.*;

class Main{
	public static void main(String args[]) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		final int
			TOTAL_CARDS = 52;					//カード総数
			
		final String[]
			MARK		= {"S","H","C","D"};	//絵柄
			
		//全種類のどのカードを所持しているかのフラグ
		boolean[] flagArray	= new boolean[TOTAL_CARDS];
		
		//所持カード枚数(入力レコード数)を記録
		int cardCount = Integer.parseInt(br.readLine());
		
		for(int i = 0;i < cardCount;i++){
			int arrayNum = 0;	//1~52の何番目か
			//所持カードの絵柄,数字の入力
			String[] input = br.readLine().split("[\\s]+");
			
			//絵柄と番号を1~52に対応させる
			for(int x = 0;x < MARK.length;x++){
				
				if(input[0].equals(MARK[x])){
					
					arrayNum = Integer.parseInt(input[1]) + (x * 13) - 1;
				}
			}
			//所持フラグの変更
			flagArray[arrayNum] = true;
		}
		
		//所持していなかったカードを表示させる
		for(int i = 0;i < flagArray.length;i++){
			
			if(flagArray[i] == false){
				
				//1~13までの数字に変換する
				int cardNum = i % 13 + 1;
				
				//出力
				System.out.println(MARK[i / 13] + " " + String.valueOf(cardNum));
			}
		}
	}
}



Measured memory_bytes: 24476
program atcoder
    implicit none
    integer(8),allocatable,dimension(:) :: a,b,c
    integer(8) N,K,i,j,l,m,num
    read*,N,K
    allocate( a(N) )
    allocate( b(N*(N+1)/2) )
    allocate( c(N*(N+1)/2) )
    read(*,*)(a(i),i=1,N)
    l = 1
    do i=1,N
        m = 0
        do j=i,N
            m = m + a(j)
            b(l) = m
            l = l + 1
        enddo
    enddo
    !write(*,'(I0)')lshift(1_8,36_8)
    num = N*(N+1)/2
    do i=63,1,-1
        l = 0
        do j=1,num
            if(iand(b(j),lshift(1_8,i))==lshift(1_8,i))then
                l = l+1
                c(l) = b(j)
            endif
        enddo
        if(l>=K)then
            b = c
            num = l
        endif
    enddo
    j = b(1)
    do i=1,num
        j = iand(j,b(i))
    end do
    write(*,'(I0)')j
!----------------------functions--------------------------
contains



end program atcoder

Measured memory_bytes: 6912
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector> 
#include <cstring>
#include <queue>
#include <ctime>
#include <set>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
const ll INF = 10e16;
const int maxN = 200010;
const int maxM = 100010;
const int N = 5000; 
const int MOD = 1000000007;

int a[maxN];
int b[maxN];
int n;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
	}
	for(int i=1;i<=n;i++)
	{
		b[a[i]] = i;
	}
	int mxlen = 0; 
	int len = 0;
	for(int i=1;i<=n;i+=len)
	{
		int j = i;
		len = 1;
		while(1)
		{
			if(b[j+1] > b[j])
			{
				len++;
			}
			else
				break;
			j++;
		} 
		if(len > mxlen)
			mxlen = len;
	}
	printf("%d\n",n-mxlen);
	return 0;
}  

Measured memory_bytes: 1792
n,k,c=gets.split.map(&:to_i)
str=gets.chomp.split('')
maruarray=[]

i=0
n.times{
 if str[i]=="o"
     maruarray.push(i+1)
 end
 i+=1   
}

hissuarray=[maruarray[0]]
hissuarray2=[maruarray[-1]]
count=1
index=1
last=maruarray[0]

loop{
    if count==k
        break
    end
    
    if maruarray[index]>last+c
        hissuarray.push(maruarray[index])
        last=maruarray[index]
        count+=1
    end
    index+=1
}

if maruarray[-1]-hissuarray[-1]>c
    exit
end


count=1
index=-1
last=maruarray[-1]

loop{
    if count==k
        break
    end
    
    if maruarray[index]<last-c
        hissuarray2.push(maruarray[index])
        last=maruarray[index]
        count+=1
    end
    index-=1
   
}

hissuarray2=hissuarray2.reverse

ans=[]

index2=0
count.times{
    if hissuarray[index2]==hissuarray2[index2]
        ans.push(hissuarray[index2])
    end
    index2+=1
}

ans.map{|value|
    puts value
}

Measured memory_bytes: 29560
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		ScannerModule sm = new ScannerModule();
		String input_a = String.valueOf(sm.scanInt());
		String input_b = String.valueOf(sm.scanInt());
		int result_num = Integer.parseInt(input_a + input_b);
		int flag = 0;
		for(int i = 1; i <= result_num; i++) {
			if(result_num % i == 0) {
				if(result_num / i == i) {
					flag = 1;
				}
			}
		}
		if(flag == 1) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
	}
}
class ScannerModule {
	Scanner scanner = new Scanner(System.in);
	int scanInt() {
		return Integer.parseInt(scanner.next());
	}
	String scanString() {
		return scanner.next();
	}
}

Measured memory_bytes: 21844
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub


import sys
# sys.setrecursionlimit(10**6)
# buff_readline = sys.stdin.buffer.readline
buff_readline = sys.stdin.readline
readline = sys.stdin.readline

INF = 2**62-1


def read_int():
    return int(buff_readline())


def read_int_n():
    return list(map(int, buff_readline().split()))


def read_float():
    return float(buff_readline())


def read_float_n():
    return list(map(float, buff_readline().split()))


def read_str():
    return readline().strip()


def read_str_n():
    return readline().strip().split()

def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N):
    fc = Counter()
    for x in range(1, 100+1):
        x2 = x**2
        for y in range(1, 100+1):
            y2 = y**2
            for z in range(1, 100+1):
                z2 = z**2
                f = x2 + y2 + z2 + x*y + y*z + z*x
                if f <= N:
                    fc[f] += 1

    for i in range(1, N+1):
        print(fc[i])


def main():
    N = read_int()
    (slv(N))


if __name__ == '__main__':
    main()


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

int N,i,j,k;
int64_t A,B,sm,ans,mx=0;
int64_t h[100010];
bool check(int64_t t){
  sm = 0;
  for(i = 0;i < N;i++){
    if(h[i] - B*t > 0){
      sm += (h[i] - B*t + A - B - 1)/(A - B);
    }
  }
  if(sm <= t){
    return false;
  }else{
    return true;
  }
}

int64_t BinarySearch(int64_t low, int64_t high, function< bool(int64_t) > check){
  while(1){
    if(high-low == 1){
      return high;
      break;
    }
    int64_t mid = low+(high-low)/2;
    if(check(mid)){
      low = mid;
    }else{
      high = mid;
    }
  }
}
int main(){
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  // ifstream in("input.txt");
  // cin.rdbuf(in.rdbuf());

  cin >> N >> A >> B;
  for(i = 0;i < N;i++){
    cin >> h[i];
    mx = max(mx, h[i]);
  }

  ans = BinarySearch(0LL, mx+1, check);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define loop2(i, s, n, a) for (int i = int(s); i < int(n); i += a)
#define loop(i, s, n) loop2(i, s, n, 1)
#define rep(i, n) loop(i, 0, n)

#define pb push_back
#define all(in) in.begin(),in.end()

using ll = long long;
using ull = unsigned long long;
using namespace std;

int main(){
    ll n; cin >> n;
    vector<ll> data(n); rep(i,n) cin >> data[i];
    vector<ll> ans(n); 
    ll base = 0;
    rep(i,n) base = base ^ data[i];
    rep(i,n) ans[i] = base ^ data[i];
  rep(i,n) cout << ans[i] << " ";
  
}



Measured memory_bytes: 6348
#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)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> pip;
const ll INF = 1ll<<29;
const ll MOD = 1000000007;
const double EPS = 1e-9;
const bool debug = 0;
//---------------------------------//
 
int main() {
	int a, b; cin >> a >> b;
	
	if (a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0)
		puts("Possible");
	else
		puts("Impossible");
	return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline

n = int(input())
a = list(map(int, input().split()))
g = [[] for _ in range(n)]

for i in range(n - 1):
    g[a[i] - 1].append(i)

for i in range(n):
    print(len(g[i]))


Measured memory_bytes: 43980
#include <iostream>
using namespace std;
int main()
{
    int n;
    cin>>n;
    bool temp=false;
    while(n!=0)
    {
        int x=n%10;
        if(x==7){temp=true;break;}
        n=n/10;
    }
    if(temp){cout<<"Yes";}
    else{cout<<"No";}
}


Measured memory_bytes: 3636