akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define REP3(i,x,n) for(int i=x; i>(n); i--)
#define zero_pad(num) setfill('0') << std::right << setw(num)
#define space_pad(num) setfill(' ') << std::right << setw(num)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
int main(){

    ll N,K;
    ll sum = 0;
    bool snuke = false; 
    cin >> N >> K;
    vector<ll> d(K,0);
    ll A[N]={};
    REP(i,N)A[i]=0;
    for(ll i = 0; i< K ; i++){
        ll ak=0;
        cin >> ak;
        for(ll j = 0; j < ak;j++){
            int d_i=0;
            cin >> d_i;
           
            A[d_i-1]++;
            
        }
    }
    
    for(ll j = 0 ;j < N;j ++ ){
        if(A[j]==0){
            sum++;
        }
    }

    cout <<  sum << endl;
    return 0;
}

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

using namespace std;

int arr[1000001];

int main()
{
    int n,i,c;
    vector <int> v;

    cin >> n;

    for(i = 1; i < n; i++){
        cin >> c;
        v.push_back(c);
    }

    for(i = 0; i < n-1; i++){
        arr[v[i]]++;
    }

    for(i = 1; i <= n; i++) cout << arr[i] << '\n';

    return 0;
}

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

int main() {
    int n;
    cin >> n;
    vi a(n);
    rep(i,n) scanf("%d", &a[i]);

    int ggg = a[0];
    rep(i,n-1) ggg = __gcd(ggg, a[i+1]);
    if(ggg != 1){
        puts("not coprime");
        return 0;
    }

    //エラトステネスの篩
    const int P_MAX = 1000005;
    int pmn[P_MAX];     //smallest prime number that can divide i(pmn[i] == i -> i is prime number)
    for(int i = 1; i < P_MAX; i++)
        if(i%2 == 0) pmn[i] = 2;
        else pmn[i] = i;
    for(int i = 3; i*i < P_MAX; i += 2){
        if(pmn[i] == i){
            for(int j = 3*i; j < P_MAX; j += 2*i)
                if(pmn[j] == j) pmn[j] = i; 
        }
    }

    int cnt[P_MAX] = {0};
    rep(i,n){
        while(a[i] != 1){
            int apmn = pmn[a[i]];
            if(cnt[apmn]){
                puts("setwise coprime");
                return 0;
            }
            cnt[apmn]++;
            while(a[i]%apmn == 0) a[i] /= apmn;
        }
    }
    puts("pairwise coprime");
}


Measured memory_bytes: 14864
A,B=[int(x) for x in str(input()).split()]

X=[]
m=len(bin(B)[2:])
temp=bin(A)[2:]
for i in range(m-len(temp)):
  temp="0"+temp
X.append(temp)
X.append(bin(B)[2:])


diff=B-A+1
t=diff%2
ans=""
for j in range(m-1):
  if t==0:
    if A%2==0:
      ans+="0"
    else:
      if X[0][j]==X[-1][j]:
        ans+="0"
      else:
        ans+="1"
  if t==1:
    if A%2==0:
      ans+=X[-1][j]
    else:
      ans+=X[0][j]

if diff%4==0:
  ans+="0"
elif diff%4==1:
  if A%2==0:
    ans+="0"
  else:
    ans+="1"
elif diff%4==2:
  ans+="1"
elif diff%4==3:
  if A%2==0:
    ans+="1"
  else:
    ans+="0"



print(int(ans,2))



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

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { std::cout << #a << " = " << a << "\n"; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }
template<class T, class V> istream& operator>> (istream& ist, pair<T, V>& p) { return ist >> p.first >> p.second; }
template<class T> ostream& operator<< (ostream& ost, pair<T, T>& p) { return ost << p.first << ", " << p.second; }
template<class T> istream& operator>> (istream& ist, vector<T>& vs) { for(auto& e: vs) ist >> e; return ist; }

typedef long long ll;
int const inf = 1<<29;

constexpr int MOD = 1e9+7;

auto prime_factor = [](ll x){map<ll, int> xfact;for(int i=2; (ll)i*i<=x; i++) {while(x % i == 0) {xfact[i]++;x /= i;}}if(x > 1) xfact[x]++;return xfact;};

namespace math {
int64_t extgcd(int64_t a, int64_t b, int64_t& x, int64_t& y) {
  int64_t d = a;
  if(b != 0) {
    d = extgcd(b, a % b, y, x);
    y -= (a / b) * x;
  }
  else {
    x = 1; y = 0;
  }
  return d;
}

int64_t mod_inverse(int64_t a, int64_t m) {
  int64_t x, y;
  extgcd(a, m, x, y);
  return int64_t(m + x % m) % m;
}

int64_t fact[1000000];

int64_t mod_fact(int64_t n, int64_t p, int64_t& e) {
  e = 0;
  if(n == 0) { return 1; }
  int64_t res = mod_fact(n / p, p, e);
  e += n / p;
  if(n / p % 2 != 0) { return res * (p - fact[n % p]) % p; }
  return res * fact[n % p] % p;
}

int64_t mod_comb(int64_t n, int64_t k, int64_t p) {
  if(n < 0 || k < 0 || n < k) { return 0; }
  int64_t e1, e2, e3;
  int64_t a1 = mod_fact(n, p, e1), a2 = mod_fact(k, p, e2), a3 = mod_fact(n-k, p, e3);
  if(e1 > e2 + e3) { return 0; }
  return a1 * mod_inverse(a2 * a3 % p, p) % p;
}
}

int main() {

  math::fact[0] = 1;
  for (int i = 1; i < 1000000; i++) {
    math::fact[i] = math::fact[i - 1] * i;
    math::fact[i] %= MOD;
  }

  int N; int64_t M; cin >> N >> M;
  auto mp = prime_factor(M);
  int64_t ans = 1;
  for (auto e: mp) {
    ans *= math::mod_comb(N + e.second - 1, e.second, MOD);
    ans %= MOD;
  }
  cout << ans << "\n";
}


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

int main() {
  int N;
  string b;
  string a;
  cin >> N;
  for (int i=0;i < 1;i++) {
   
    
   for (int i=0;i < N;i++){
     cin >> a;
     if ( a == "P" ){
       continue;
     } 
     if ( a == "W" ){
       continue;
     }
     if ( a == "G" ){
       continue;
     }
     if ( a == "Y" ){
       cout << "Four" << endl;
      b = "Y";
       break;
     }
    
   }
    if ( b == "Y" ){
      break;
    }
    
    cout << "Three" << endl;
  }
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
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; }

const int mod=1000000007;
const int INF=1001001001;

int N,K;
vector<int>A;
bool f(int x){
  int cnt=0;
  for(int i=0;i<N;i++){
    cnt+=(A[i]-1)/x;
  }
  if(cnt<=K){return true;}
  else{return false;}
}

int main() {
  cin>>N>>K;
  A.resize(N);
  for(int i=0;i<N;i++){
    cin>>A[i];
  }
  int l=0,r=1e9+1;
  while(r-l>1){
    int mid=(l+r)/2;
    if(f(mid)){r=mid;}
    else{l=mid;}
  }
  cout<<r<<endl;
  return 0;  
}

Measured memory_bytes: 4000
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define N 2010
inline int Pow(int x,int zs){
	int ret=1;
	for(;zs;zs>>=1,x=x*1ll*x%mod)
		if(zs&1)ret=ret*1ll*x%mod;
	return ret;
}
int f[N][N],n,k,A[10000010],B[10000010];
inline int C(int n,int m){
	if(m>n||m<0)return 0;
	if(n==m||m==0)return 1;
	return A[n]*1ll*B[m]%mod*B[n-m]%mod;
}
int main(){
	n=1e7;
	for(int i=A[0]=1;i<=n;i++)A[i]=A[i-1]*1ll*i%mod;
	B[n]=Pow(A[n],mod-2);
	for(int i=n-1;~i;i--)B[i]=B[i+1]*(i+1ll)%mod;
	scanf("%d%d",&n,&k);
	if(k==1)return puts("1"),0;
	f[0][0]=1;
	for(int i=0;i<=n;i++)
		for(int j=i;j<=n;j++){
			if(i)f[i][j]=f[i-1][j];
			if(j)f[i][j]=(f[i][j]+f[i][j-1]*1ll*C(i+(j-1)*(k-1)+(k-2),k-2))%mod;
		}
	printf("%lld\n",f[n][n]*1ll*A[n]%mod);
	return 0;
}


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

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

int main() {
  char a[100][101];
  char b[102][102];

  int h,w;
  cin >> h >> w;

  for(int i = 0; i < h; i ++){
    cin >> a[i]; //a[i]で1行文格納
  }
  for(int i = 0; i < h+2; i ++){
    for(int j = 0; j < w+2; j++){
      b[i][j] = '#';
    }
  }

for(int i = 0; i < h; i++){
  for(int j =0; j < w; j++){
    b[i + 1][j + 1] = a[i][j];
  }
}

for(int i = 0; i < h+2; i++){
  for(int j = 0; j<w+2; j++){
    cout << b[i][j];
  }
  cout << endl;
}

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mod 1000000007
#define ll long long int
#define pb push_back
#define mk make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>
#define frr(j,i,n) for(int i=j;i<=n;++i)
using namespace std;
int n;
ll W;
ll w[101],v[101];
ll dp[101][100005];
ll go(int index,ll val)
{
    if(index>n)
    {
        if(val==0)
        return 0;
        return INT_MAX;
    }
    if(dp[index][val]!=-1)
        return dp[index][val];

    if(v[index]>val)
        return dp[index][val] = go(index+1,val);
    else
    {
        ll x=w[index]+go(index+1,val-v[index]);
        ll y=go(index+1,val);

        return dp[index][val] = min(x,y);
    }
    
    

}
ll go1(ll sum)
{
    for(int i=sum;i>=0;i--)
    {
        ll x=go(1,i);
        if(x<=W)
        return i;
    }
}
void solve()
{
    memset(dp,-1,sizeof(dp));
    cin>>n>>W;
    frr(1,i,n)
    {
        cin>>w[i];
        cin>>v[i];
    }
    ll cur=0;
    frr(1,i,n)  cur+=v[i];
	cout<<go1(cur)<<"\n";

}
int main() 
{
	// #ifndef ONLINE_JUDGE
	// 	freopen("input.txt","r",stdin);
	// 	freopen("output.txt","w",stdout);
	// #endif
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	int t=1;
	// cin>>t;
	while(t--)
	solve();
	return 0;
}



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

int main() {
  
    string c;
  cin >> c;
  
  if ( c == "a" || c == "e" || c == "i" || c == "o" || c == "u"){
    cout << "vowel" << endl;
  }


  else{
    cout << "consonant" << endl;
  }

  
 
}



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

int main() {
    int N;
    cin >> N;
    vector<pair<int, int>> A(N);
    for(int i = 0; i < N; i++){
        cin >> A.at(i).first >> A.at(i).second;
    }

    int sum = 0;
    for(int i = 0; i < N; i++){
        sum += - A.at(i).first + A.at(i).second + 1;
    }

    cout << sum << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
long long  N, K;
int main() 
{
    scanf("%lld%lld", &N, &K);
   	long long base = N / K;
   	long long ans = base * base * base, ans2 = 0;
    if(K % 2 == 0) 
	{
        base = (N - K / 2) / K + (N >= K / 2);
        ans2 += base * base * base;        
    }
    printf("%lld", ans+ans2);
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 10;
int n, s, si;
ll ans;
int x[maxn];
ll p[maxn];
int main()
{
	scanf("%d%d", &n, &s);
	for(int i = 1; i <= n; ++i) scanf("%d%lld", &x[i], &p[i]);
	si = lower_bound(x + 1, x + n + 1, s) - x;
	int dir = -1;
	int l = 1, r = n;
	while(l < si && si <= r)
	{
		if(p[l] >= p[r])
		{
			if(dir != 1) ans += x[r] - x[l];
			p[l] += p[r];
			dir = 1;
			--r;
		}
		else
		{
			if(dir != 0) ans += x[r] - x[l];
			p[r] += p[l];
			dir = 0;
			++l;
		}
	}
	if(l >= si) ans += x[r] - s;
	else ans += s - x[l];
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 4992
#include<bits/stdc++.h>
#define INFTY 1<<20
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
const int MOD=1000000007;
int main() {
    int n;cin>>n;
    vector<pair<ll,ll>> pairs(n);
    rep(i,n){
        ll a,b;cin>>a>>b;
        pairs[i] = make_pair(b,a);
    }
    sort(pairs.begin(),pairs.end());
    
    ll time=0;
    bool ok=true;
    rep(i,n){
        time+= pairs[i].second;
        if(time>pairs[i].first){ok=false;break;}
    }
    if(ok)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

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

signed main () {
	int n; 
	cin >> n;
	vector < long long > a(n);
	for (int i = 0; i < n; ++i)
		cin >> a[i];
	long long ans = 0;
	while (*max_element(a.begin(), a.end()) >= n) {
		long long mx = 0;
		int j = -1;
		for (int i = 0; i < n; ++i) {
			if (a[i] > mx) 
				mx = a[i], j = i;
		}
		for (int i = 0; i < n; ++i) {
			if (i != j) 
				a[i] += (mx / n);
		}
		a[j] -= (mx / n) * n;
		ans += mx / n;
	}
	cout << ans << endl;
}


Measured memory_bytes: 3628
#include <iostream>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <cmath>
#include <map>
#define INF 1000000000
using namespace std;
map<int, int> mp;
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int a[3][3];
	for (int i = 0; i < 3; i++) {
		for (int j = 0; j < 3; j++) {
			cin >> a[i][j];
		}
		a[i][1] -= a[i][0];
		a[i][2] -= a[i][0];
		a[i][0] = 0;
	}
	for (int i = 0; i < 3; i++) {
		if (!(a[0][i] == a[1][i] && a[1][i] == a[2][i])) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define SPEED ios_base::sync_with_stdio(false); cin.tie(NULL);
#define FOR(i, a, b) for (ll i = a; i < b; ++i)
#define RFOR(i, b, a) for (ll i = b; i >= a; --i)
#define ALL(x) x.begin(), x.end()
#define DEBUG(args...) { string _s = #args; replace(ALL(_s), ' ', '\0');\
replace(ALL(_s), ',', ' ');\
stringstream _ss(_s); istream_iterator<string> _it(_ss); _debug(_it, args);}
#define endl "\n"
#define F first
#define S second
#define pb(x) push_back(x)
#define mp(x, y) make_pair(x, y)

using namespace std;
using namespace __gnu_pbds;

template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

void _debug(istream_iterator<string>) {}
template<typename T, typename... Args>
void _debug(istream_iterator<string> it, T first, Args... args) {
    cerr << ">> " << *it << " : " << first << endl; _debug(++it, args...);
}
template <typename T1, typename T2>
inline ostream& operator << (ostream& out, const pair<T1, T2>& p) {
    return out << "(" << p.F << ", " << p.S << ")";
}
template<typename T>
inline ostream& operator << (ostream& out, const vector<T>& v) {
    if (v.empty()) return out << "[]";
    else { out << '['; for (auto& e : v) { out << e << ", "; } return out << "\b\b]"; }
}
template<typename T>
inline ostream& operator << (ostream& out, const set<T>& s) {
    if (s.empty()) return out << "{}";
    else { out << '{'; for (auto& e : s) { out << e << ", "; } return out << "\b\b}"; }
}
template<typename T>
inline ostream& operator << (ostream& out, const unordered_set<T>& s) {
    return out << set<T>(ALL(s));
}
template<typename T1, typename T2>
inline ostream& operator << (ostream& out, const map<T1, T2>& m) {
    if (m.empty()) return out << "{}";
    out << '{'; for (auto& p : m) { out << p << ", "; } return out << "\b\b}";
}
template<typename T1, typename T2>
inline ostream& operator << (ostream& out, const unordered_map<T1, T2>& m) {
    return out << map<T1, T2>(ALL(m));
}
template<typename T>
inline ostream& operator << (ostream& out, const ordered_set<T>& s) {
    return out << set<T>(ALL(s));
}

typedef long long ll;
typedef long double ld;
typedef vector<long long> vll;
typedef pair<ll, ll> pll;
typedef vector<pair<ll, ll>> vpll;
typedef unordered_map<ll, ll> STll;
/************************************** MAIN PROGRAM ********************************************/

int main()
{
    //freopen("input.txt", "r", stdin);
    SPEED
    int n;
    cin >> n;
    int k;
    cin >> k;
    vector<ll> h(n);
    for (auto &e : h) {
        cin >> e;
    }
    sort(ALL(h));
    h = vector<ll>(h.begin(), h.begin() + max(n - k, 0));
    cout << accumulate(ALL(h), 0ll);
}
/************************************** END OF PROGRAM ******************************************/
/** Stuff you should look for:
 * int overflow, array bounds, over-counting, graph is not a tree/connected
 * special cases (n=1?), set/unordered_set TLE, multi-set/set error
 * do something instead of nothing and stay organized
 */


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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    ll N, M; cin >> N >> M;
    map<ll, ll> x; rep(i, M){x[i] = 0;}
    rep(i, N){
        ll K; cin >> K;
        rep(j, K){ll n; cin >> n; x[n - 1]++;}
    }
    ll ans = 0;
    rep(i, M){if (x[i] == N){ans++;}}
    cout << ans << endl;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 3644
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>

using namespace std;

template <class T>
T gcd(T a, T b) {
    while (b > 0) {
        a %= b;
        swap(a, b);
    }
    return a;
}

bool solve(int N, vector<int>& A) {
    if (N == 1) return false;

    // 総和の偶奇
    int parity = accumulate(A.begin(), A.end(), 0, [](int init, int a) { return (init + (a & 1)) & 1; });

    // Nが偶数の場合、和の偶奇がそのまま勝敗になる
    if ((N & 1) == 0) return parity != 0;

    // Nが奇数の場合も、和が偶数なら絶対勝てる
    if (parity == 0) return true;

    // 奇数を前に持っていく
    sort(A.begin(), A.end(), [](int a, int b) { return (a & 1) > (b & 1); });
    // 奇数が複数個ある、あるいは唯一の奇数が1(減らせない)なら負け
    if (A[0] == 1 || (A[1] & 1) != 0) return false;
    // そうでなければ、唯一の奇数を減らしてワンチャンに賭ける
    --A[0];
    int g = accumulate(A.begin(), A.end(), 0, gcd<int>);
    for (auto& a : A) a /= g;
    return !solve(N, A);
}

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    for (auto& a : A) cin >> a;
    cout << (solve(N, A) ? "First" : "Second") << endl;
    return 0;
}


Measured memory_bytes: 640
#define _CRT_SECURE_NO_WARNINGS
//#define _USE_MATH_DEFINES
#include<stdio.h>
//#include<stdlib.h>
//#include<math.h>
#include<string.h>
#define P(type,x) fprintf(stdout,"%"#type"\n",x)
char str[5][7] = { {"afkpuz"},
				   {"bglqv."},
				   {"chmrw?"},
				   {"dinsx!"},
				   {"ejoty "} };
int main() {
	char encode[500] = "";
	char decode[500] = "",s[2];
	int i;
	for (; ~fscanf(stdin, "%s", encode);P(s,decode),memset(encode,'\0',sizeof(encode)), memset(decode, '\0', sizeof(decode))) {
		getchar();
		if (strlen(encode) & 1) { strcat(decode, "NA");continue; }
			for (i = 0; i < strlen(encode); i += 2) {
				memset(s, '\0', sizeof(s));
				if (encode[i] < '1' || encode[i] > '6' || encode[i + 1] < '1' || encode[i + 1] > '5') { memset(decode, '\0', sizeof(decode)); strcat(decode, "NA"); break;}
				s[0] = str[(encode[i + 1] - '0') - 1][(encode[i] - '0') - 1];
				strcat(decode,s);
			}
	}
	return 0;
}

Measured memory_bytes: 556
#include <bits/stdc++.h>
using namespace std;
 
//krishrawat
 
 
//----------------------------MACROS-------------------------------------------------
#define pb insert//                                                                 |
#define eb emplace_back//                                                           |
#define ff first//                                                                  |
#define ss second//                                                                 |
typedef long long int ll;//                                                         |
typedef long double ld;//                                                           |
#define all(a) a.begin(), a.end()//                                                 |
#define show(x) cerr << #x << " is " << x << "\n"//                                 |
#define show2(x, y) cerr << #x << " " << #y << " " << x << " " << y << "\n"//       |
typedef vector<ll> vl;//                                                            |
typedef vector<vl> vvl;//                                                           |
typedef pair<ll, ll> pp;//                                                          |
typedef vector<pp> vp;//                                                            |
typedef map<pp, ll> ipi;//                                                          |
typedef map<pp, char> ipc;//                                                        |
typedef map<ll, ll> ii;//                                                           |
typedef set<ll> sl;//                                                               |
typedef multiset<ll> msl;//                                                         |
typedef map<char, ll> ci;//                                                         |
typedef set<pair<ll, ll>> sp;//                                                     |
const ll mod = 1e9 + 7;//                                                           |
const ll N = 5e5 + 1;//                                                             |
//----------------------------------------------------------------------------------



void solve()
{   
    ll n,q;cin>>n>>q;
    ii m,mark;
    int f=0;
    for(int i=0;i<q;i++){
        ll x,y;cin>>x>>y;
        if(mark[x] && m[x]!=y) f=1;
        m[x]=y;
        mark[x]=1;
    }
    if(f) cout<<-1<<"\n";
    else{
        if(n==1) {
            cout<<m[1];
        }
        else{
            if(mark[1] && m[1]==0) cout<<-1<<"\n";
            else{
                for(int i=0;i<n;i++){
                    if(i==0 && !mark[1]) cout<<1;
                    else{
                        if(mark[i+1]){
                            cout<<m[i+1];
                        }
                        else cout<<0;
                    }
                }
            }
        }
    }
}
 
 
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
    
    ll t;
    t=1;
    //cin>>t;
    while(t--){
        solve();
    }
    
	return 0;
}

Measured memory_bytes: 3664
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr int Inf = 1000000000;
constexpr ll INF= 1e18;
constexpr ll MOD = 1000000007;
const double PI = 3.1415926535897;
typedef pair<int,int> P;

int main() {
    ll K,A,B;
    cin >> K >> A >> B;
    if(B - A >= 2) {
        ll ret = 0;
        ret += A;
        K -= (A - 1);
        ret += (K / 2) * (B - A);
        ret += K % 2;
        cout << ret << endl;
    }
    else {
        cout << K + 1 << endl;
    }
}

Measured memory_bytes: 256
#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)
typedef long long ll;
#define MAXN 100005
#define MAXH 10005
ll dp[MAXN] = {};
ll h[MAXN] = {};
int n,k;

void make() {
	dp[1] = abs(h[1]-h[0]);

	for (int i=2; i<n; i++) {
		ll mi = -1;
		for (int j=i-k; j<=i-1; j++) {
			if (j>=0) {
				if (mi==-1) {
					mi = dp[j] + abs(h[i] - h[j]);
				} else {
					mi = min(mi, dp[j] + abs(h[i] - h[j])); 
				}
	}
		}
		dp[i] = mi;
	}
}

int main(){
	cin >> n >>k;
	rep(i,n) {
		cin >> h[i];
	}
	make();
	cout << dp[n-1] << endl;
}


Measured memory_bytes: 1792
n, m, r = map(int, input().split())
R = list(map(int, input().split()))
R = [x-1 for x in R]

def warshal_floyd(d):
  for k in range(n):
    for i in range(n):
      for j in range(n):
        d[i][j] = min(d[i][j], d[i][k]+d[k][j])
  return d

d = [[float('inf') for i in range(n)] for j in range(n)]

for i in range(m):
    a,b,c = map(int, input().split())
    a, b = a-1, b-1
    d[a][b] = c
    d[b][a] = c

for i in range(n):
    d[i][i] = 0

d = warshal_floyd(d)
import itertools
ans = float('inf')
for p in itertools.permutations(R):
    temp = 0
    for i in range(r-1):
        temp += d[p[i]][p[i+1]]
    ans = min(temp, ans)
print(ans)


Measured memory_bytes: 76600
s = input()
q = int(input())

inverse = 1
left = ''
right = ''
for i in range(q):
    query = list(map(str, input().split()))
    if query[0] == '1':
        inverse *= -1
    if query[0] == '2':
        if query[1] == '1' and inverse == 1:
            left += query[2]
        elif query[1] == '2' and inverse == 1:
            right += query[2]
        elif query[1] == '1' and inverse == -1:
            right += query[2]
        elif query[1] == '2' and inverse == -1:
            left += query[2]
s = left[::-1]+s+right
if inverse == 1:
    print(s)
else:
    print(s[::-1])


Measured memory_bytes: 4596
#include<bits/stdc++.h>
#define Mx 1000000000005 
#define ll long long  
#define pi 3.141592653
#define vi vector<ll>
#define Mo 1000000007
#define mp make_pair
#define M map<ll,ll>
#define fr(i,a,b) for(ll i=a;i<b;i++)
#define vii vector<pair<ll,ll> > 
#define fi first
#define se second
#define pb push_back
#define ld long double
#define fill(a,x) memset(a,x,sizeof(a))
using namespace std;
bool comp(const pair<ll,ll> &a, const pair<ll,ll> &b)
{
  return a.second<b.second;
}
/*vi b=v;
   sort(b.begin(), b.end());
  b.resize(unique(b.begin(), b.end()) - b.begin());
  ll t; cin>>t; fr(f,0,t){ 
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
 */
vector<vector<ll>> dp(21,vector<ll>(1<<21,-1));
bool a[21][21];
ll func(ll m,ll n,ll l)
{ 
  ll ans=0;
  if(dp[n-1][m]!=-1) return dp[n-1][m];

  if(n==1)
  {
    fr(j,0,l)
      if(a[0][j] && (m & 1<<j))
        ans+=1;
    return dp[n-1][m]=ans;
  }

  fr(j,0,l)
    if(a[n-1][j] && (m & 1<<j))
    {
      ans+=func(m^(1<<j),n-1,l);
      ans%=Mo;
    }

  return dp[n-1][m]=ans;
}
int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll n; cin>>n;
  fr(i,0,n)
    fr(j,0,n)
      cin>>a[i][j];

  cout<<func((1<<n)-1,n,n);
}


Measured memory_bytes: 363620
#include <iostream>
using namespace std;

// 回分数かどうか 5桁限定
bool isPalindromic(int n) {
    int nums[5];
    for(int i = 0; i < 5; i++) {
        nums[i] = n % 10;
        n /= 10;
    }
    if(nums[0] == nums[4] && nums[1] == nums[3]) return true;
    else return false;
}

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

    int cnt = 0;
    for (int i = a; i <= b; ++i) {
        if (isPalindromic(i)) {
            cnt++;
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
#include <cstdio>
using namespace std;

int main() {
	int i,c=0;
	char S[3];
	scanf("%s",S);
	for(i=0;i<3;i++){
		if(S[i]=='o')c+=1;
	}
	printf("%d",700+c*100);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef long double ld;
 
#define REP(i,a,n) for(int (i)=(a); (i)<(int)(n); (i)++)
#define rep(i,n) REP(i,0,n)
#define vec vector 


int char_to_int(char c){
  switch(c){
    case '0': return 0;
	case '1': return 1;
	case '2': return 2;
	case '3': return 3;
	case '4': return 4;
	case '5': return 5;
	case '6': return 6;
	case '7': return 7;
	case '8': return 8;
	case '9': return 9;
	default: return 0;
  }
}


int main(){
  ll A, B, M;
  cin >> A >> B >> M;
  
  vector<ll> a(A);
  rep(i, A) cin >> a.at(i);
  vector<ll> b(B);
  rep(i, B) cin >> b.at(i);     
  vector<ll> x(M); vector<ll> y(M); vector<ll> c(M);
  rep(i, M) cin >> x.at(i) >> y.at(i) >> c.at(i);
  
  ll A_min = a.at(0); ll A_min_iter = 0;
  ll B_min = a.at(0); ll B_min_iter = 0;
  rep(i, A){
    if(A_min > a.at(i)){
      A_min = a.at(i);
      A_min_iter = i;
    }
  }
  rep(i, B){
    if(B_min > b.at(i)){
      B_min = b.at(i);
      B_min_iter = i;
    }
  }
  
  ll res = A_min + B_min;
  ll tempo;
  rep(i, M){
    tempo = a.at(x.at(i)-1) + b.at(y.at(i)-1) - c.at(i);
    if(tempo < res){
      res = tempo;
    }
  }
  
  cout << res;
    
  
}

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

int main(){
  string s,s1,s2;
  cin >> s1;
  cin >> s;
  s2 = s1+s1;
  //cout << s2.find(s);
  if(s2.find(s) < 100000000){
    cout << "Yes";
  }else{
    cout << "No";
  }
  cout << endl;
}


Measured memory_bytes: 3200
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(int i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(int i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(int i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define uniq(x) (x).erase(unique((x).begin(), (x).end()), (x).end())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int l = 0, r = s.length() - 1;
    int ans = 0;
    while (l < r) {
        if (s[l] == s[r]) {
            l++; r--;
            continue;
        }
        if (s[l] == 'x') {
            l++;
            ans++;
        }
        else if (s[r] == 'x') {
            r--;
            ans++;
        }
        else {
            cout << -1 << endl;
            return 0;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 512
#!/usr/bin/env python3
import sys
import math
INF = float("inf")


def solve(N: int, K: int, A: "List[int]"):
    print(int(math.ceil((N-1)/(K-1))))
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, K, A)


if __name__ == '__main__':
    main()


Measured memory_bytes: 14452
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstring>

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) v.erase(unique(v.begin(), v.end()), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

#define MAX_V 1000000

#define MAX_H 1010
#define MAX_W 1010

int h, w;
char a[MAX_H][MAX_W];

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

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

  cin >> h >> w;
  int cost[h][w];

  queue<pair<int, int> > q;

  rep(i, 0, h) rep(j, 0, w) {
      cin >> a[i][j];
      if(a[i][j] == '#') {
          cost[i][j] = 0;
          q.push(make_pair(j, i));
      } else {
          cost[i][j] = -1;
      }
  }

  while(!q.empty()) {
      pair<int, int> p = q.front(); q.pop();
      rep(i, 0, 4) {
          int nx = p.first + dx[i], ny = p.second + dy[i];
          if(!(0 <= nx && nx < w && 0 <= ny && ny < h)) continue;
          if(cost[ny][nx] != -1) continue;

          cost[ny][nx] = cost[p.second][p.first] + 1;
          q.push(make_pair(nx, ny));
      }
  }

  int rsl = 0;
  rep(i, 0, h) rep(j, 0, w) rsl = max(rsl, cost[i][j]);
  cout << rsl << endl;
}


Measured memory_bytes: 13328
#include <iostream>
#include <cstdio>
#include <map>
#include <set>
#include <queue>
#include <vector>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#define rep(i,a,b) for(int i = a; i <= b; i++)
#define dep(i,a,b) for(int i = a; i >= b; i--) 
#define Rep(i,a) for(int i = 0; i < a; i++)
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define ab(x) ((x) < 0 ? -(x) : (x))
using namespace std;
typedef long long LL;
typedef map<int, int>::iterator mit;
typedef set<int>::iterator sit;
const int N = 100010;
int n, k, a[N];
LL f[N], g[N], s[N];
int main() {
	scanf("%d%d",&n,&k); rep(i,1,n) scanf("%d",&a[i]), s[i] = s[i - 1] + a[i];
	rep(i,1,n) if (a[i] > 0) f[i] = f[i - 1] + a[i]; else f[i] = f[i - 1];
	dep(i,n,1) if (a[i] > 0) g[i] = g[i + 1] + a[i]; else g[i] = g[i + 1];
	LL ans = 0;
	rep(l,1,n - k + 1) {
		int r = l + k - 1;
		ans = max(ans, f[l - 1] + g[r + 1]);
		ans = max(ans, s[r] - s[l - 1] + f[l - 1] + g[r + 1]);
	}
	cout <<ans<<endl;
	return 0;
}

Measured memory_bytes: 3072
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <sstream>

using namespace std;

int a[100000];

int cal(string str){
	int num[6];
	
	num[0] = str[0] - '0';
	num[1] = str[1] - '0';
	num[2] = str[3] - '0';
	num[3] = str[4] - '0';
	num[4] = str[6] - '0';
	num[5] = str[7] - '0';
	return num[0] * 36000 + num[1] * 3600 + num[2] * 600 + num[3] * 60 + num[4] * 10 + num[5];
}

int main(){
	
	int n;
	
	while(true){
		
		cin >> n;
		if(n == 0){
			break;
		}
		
		for(int i = 0; i < 100000; i++){
			a[i] = 0;
		}
		
		
		for(int i = 0; i < n; i++){
			
			string str1, str2;
			cin >> str1 >> str2;
			
			a[cal(str1)]++;
			a[cal(str2)]--;
			
		}
		
		int ans = 0;
		int cur = 0;
		
		for(int i = 0; i < 100000; i++){
			cur += a[i];
			ans = max(ans, cur);
		}
		
		cout << ans << endl;
	}
	
	return 0;
}

Measured memory_bytes: 3496
class Heap
  attr_reader :size
  def initialize(up: false)
    @up = up
    @heap = []
    @size = 0
  end
  def sum
    x = 0
    @size.times do |i|
      x += @heap[i]
    end
    x
  end
  def push(n)
    n = -n if @up
    i = @size
    while i > 0
      pid = (i - 1) / 2
      break if n >= @heap[pid]
      @heap[i] = @heap[pid]
      i = pid
    end
    @heap[i] = n
    @size += 1
  end
  def pop
    return nil if @size == 0
    top = @heap[0]
    @size -= 1
    n = @heap[@size]
    i = 0
    while i * 2 + 1 < @size
      cid1 = i * 2 + 1
      cid2 = cid1 + 1
      if cid2 < @size && @heap[cid2] < @heap[cid1]
        cid1 = cid2
      end
      break if @heap[cid1] >= n
      @heap[i] = @heap[cid1]
      i = cid1
    end
    @heap[i] = n
    if @up
      -top
    else
      top
    end
  end
end

_, m = gets.split.map(&:to_i)
a = gets.split.map(&:to_i)
b = Array.new(m){gets.split.map(&:to_i)}
h = Heap.new(up: false)
a.each do |x|
  h.push(x)
end
f = false
b.sort_by{|x, y| -y}.each do |x, y|
  x.times do
    u = h.pop
    if y > u
      h.push(y)
    else
      h.push(u)
      f = true
    end
    break if f
  end
  break if f
end
puts h.sum

Measured memory_bytes: 20824
#ifdef __APPLE__
#include <iostream>
#include <vector>
#include <utility>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <iomanip>
#include <cmath>
#include <ctgmath>
#include <math.h>
#include <cassert>
#include <chrono>
#else
#include <bits/stdc++.h>
#endif

using namespace std;
#define io ios_base::sync_with_stdio(false), cin.tie(NULL)
#define GFOR(i,a,n) for (i=a;i<n;i++)
#define FOR(i,a,n) for (int i=a;i<n;i++)
#define RFOR(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
#define tc(t) for (int tc=1; tc<=t; tc++)
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<long long int> vll;
typedef vector<pair<int, int> > vpi;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
mt19937 mrand(random_device{}()); 
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll modInverse (ll a) {ll p = mod - 2; return powmod(a, p);}
// head

void solve() {
    int n;
    cin >> n;
    vi a(n), b(n);
    for (int i = 0; i < n; i++)
        cin >> a[i] >> b[i];

    for (int i = 0; i <= n -3; i++) {
        if (a[i] == b[i] && a[i+1] == b[i+1] && a[i+2] == b[i+2])
            goto good;
    }
    cout << "No" << '\n';
    return;
    good:
    cout << "Yes" << '\n';
}

int main() {
    #ifdef LOCAL
    auto t1 = std::chrono::high_resolution_clock::now();
    #endif

    io;
    solve();

    #ifdef LOCAL
    auto t2 = std::chrono::high_resolution_clock::now();
    auto duration = std::chrono::duration_cast<std::chrono::milliseconds>( t2 - t1 ).count();

    std::cout << "Time Taken: " << duration << "\n";
    #endif

}
// check for edge cases in limits
// printing double may print 1.223232e9 like values, beware of that
// carefully observe simulation of test cases
// multiset erase is does not do what it is supposed to


Measured memory_bytes: 3656
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<map>
#include<set>
#include<deque>

using namespace std;

#define sz(x) (int)(x.size())
#define rep(i, a, b) for(int i=a;i<b;++i)
#define per(i, a, b) for(int i=b-1;i>=a;--i)
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;

////////////////

string const F = "First";
string const S = "Second";

int const N = 1e5 + 41;

vector<int> e[N];
int root;
int l[N];
int n;
int cnt[N];
int par[N];
int w[N];

deque<int> q;

void print(string ans){
	cout << ans << endl;
	exit(0);
}

int dfs(int u, int p){
	if(sz(e[u]) == 1) l[u] = 1;
	par[u] = p;
	int cnt = 0;
	rep(i, 0, sz(e[u])){
		int to = e[u][i];
		if(to == p) continue;
		cnt += dfs(to, u);
	}
	if(cnt > 1) print(F);
	return l[u];
}

void solve(){
	cin >> n;
	rep(i, 0, n-1){
		int a, b;
		cin >> a >> b;
		--a;--b;
		e[a].pb(b);
		e[b].pb(a);
	}

	rep(i, 0, n) if(sz(e[i]) > sz(e[root])) root = i;
	++cnt[root];
	dfs(root, -1);
	rep(i, 0, n){
		cnt[i] = sz(e[i]);
		if(l[i]) q.pb(i);
	}
	while(sz(q)){
		int v = q.front();
		q.pop_front();
		if(par[v] == -1){
			continue;
		}
		if(!w[v] && w[par[v]]) print(F);
		--cnt[par[v]];
		if(cnt[par[v]] == 1) q.pb(par[v]);
		if(!w[v]){
			w[par[v]] = 1;
			w[v] = 1;
		}
	}
	rep(i, 0, n) if(!w[i]) print(F);

	print(S);
}

int main(){
#ifdef _DEBUG
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif

	solve();

	return 0;
}

Measured memory_bytes: 7424
#include <cstdio>

int main(){
    int N, Y;
    scanf("%d %d", &N, &Y);
    Y = Y / 1000;

    for(int x = 0; x <= N; x++){
        for(int y = 0; y <= N - x; y++){
            int z = N - x - y;
            if(x * 10 + y * 5 + z == Y){
                printf("%d %d %d", x, y, z);
                return 0;
            }
        }
    }

    printf("-1 -1 -1");
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <utility>
#include <algorithm>
using namespace std;

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

    int *A=new int[200000];
    for(int i=0;i<200000;i++) A[i]=0;
    for(int i=0;i<N;i++){
        int a;
        cin >> a;
        A[a-1]++;
    }

    sort(A,A+200000);

    int cnt=0;
    for(int i=0;i<200000-K;i++){
        cnt+=A[i];
    }

    cout << cnt << endl;

    delete[] A;
    return 0;
}

Measured memory_bytes: 1024
x = int(input())
ma = 0
for i in range(33):
    if x  < i ** 2:
        ma = (i-1) ** 2
        break
for i in range(13):
    if x <  i ** 3:
        max([ma,(i-1) ** 3])
        ma = max([ma,(i-1) ** 3])
        break
for i in range(6):
    if x < i ** 5:
        ma = max([ma, (i-1) ** 5])
        break
print(ma)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define f(i,n) for(int i=0;i<(n);i++)
#define P pair<int,int>
#define LONG LLONG_MAX/3;
#define INT INT_MAX/3;
#define mod 1000000007
#define S second
#define F first
typedef long long ll;
using namespace std;
char c[100][100];
bool b[100][100];
int main(){
	int n,m;
	cin>>n>>m;
	f(i,n){
		bool a=false;
		f(j,m){
			cin>>c[i][j];
			if(c[i][j]=='#'){
				a=true;
			}
		}
		if(!a){
			f(j,m) b[i][j]=true;
		}
	}
	f(j,m){
		bool a=false;
		f(i,n){
			if(c[i][j]=='#') a=true;
		}
		if(!a){
			f(i,n) b[i][j]=true;
		}
	}
	
	f(i,n){
		bool a=false;
		f(j,m){
			if(!b[i][j]){
				cout<<c[i][j];
				a=true;
			}
		}
		if(a) puts("");
	}
	return 0;
}


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

const int Inf = 1000000;
const int Maxn = 50;
const int Maxd = 10;

int dp[Maxn][Maxd], all[Maxn][Maxd];
int k;

int main()
{
    all[1][0] = 1;
    for (int j = 1; j < Maxd; j++)
        all[1][j] = dp[1][j] = 1;
    for (int i = 2; i < Maxn; i++)
        for (int j = 0; j < Maxd; j++)
            for (int d = max(0, j - 1); d <= min(Maxd - 1, j + 1); d++) {
                all[i][j] = min(Inf, all[i][j] + all[i - 1][d]);
                if (j) dp[i][j] = min(Inf, dp[i][j] + all[i - 1][d]);
            }
    cin >> k;
    for (int i = 1; i < Maxn; i++)
        for (int d = 1; d < Maxd; d++)
            if (k <= dp[i][d]) {
                printf("%d", d);
                for (int j = i - 1; j > 0; j--) {
                    for (int nd = max(0, d - 1); nd <= min(Maxd - 1, d + 1); nd++)
                        if (k <= all[j][nd]) { printf("%d", nd); d = nd; break; }
                        else k -= all[j][nd];
                }
                printf("\n");
                return 0;
            } else k -= dp[i][d];
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
#define showall(obj) for(auto x:obj)cout<<x<<endl;
typedef long long ll;
typedef pair<int,int> ip;
typedef pair<ll,ll> lp;
typedef vector<int> vint;
typedef vector<ll> vll;
const int inf = 100100100;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

int main(){
	ll h,w; cin>>h>>w;
	if(h==1||w==1){cout<<1<<endl; return 0;}
	else cout<<(h*w+1)/2<<endl; return 0;
}


Measured memory_bytes: 256
import itertools

if __name__ == '__main__':
    # P and Q are both rearrangements of (1, 2, ..., N)).
    # N! possible permutations of size N
    # among them, let P and Q be the a-th and the b-th
    n = int(input())
    p = list(map(int, input().split(' ')))
    q = list(map(int, input().split(' ')))

    realnums = p.copy()

    realnums.sort()

    perm = list(map(list, itertools.permutations(realnums)))

    print(abs(perm.index(q) - perm.index(p)))

Measured memory_bytes: 10228
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string a, b;
    cin>>a>>b;
    int n=a.length();
    int count=0;
    for(int i=0;i<n;i++)
    {
        if(a[i]!=b[i])
        count++;
    }
    cout<<count<<endl;
}


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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;

#define F first
#define S second
#define PB push_back
#define MK make_pair
#define REP(i, a, b) for (int i=a; i < b; i++)


bool sort_by(pi c, pi d){
	return c.S < d.S;
}

int main() {
	int N, K;
	cin >> N >> K;
	double arr[N], tmp;
	REP(i, 0, N){
		cin >> tmp;
		tmp = (tmp*(tmp+1)/(2*tmp));
		arr[i] = (i==0? tmp: arr[i-1]+tmp);
	}	
	double ans = arr[K-1];
	
	REP(i, K, N)ans = max(ans, arr[i] - arr[i-K]);
	cout << fixed << setprecision(6)<< ans;

}


Measured memory_bytes: 1792
#include <iostream>
#include <cmath>
#include <climits>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
#include <numeric>
using namespace std;
// scanf
#pragma warning(disable: 4996)
// v:vector  type:型  order:greater or less
#define _sort(v,type,order) do { sort(v.begin(),v.end(),order<type>()); } while(0)
// v:vector  default_value:初期値
#define _sum(v,default_value) accumulate(v.begin(),v.end(),default_value )
// 丸め
#define _round(v) round(v)
// 2乗 / 3乗
#define _square(v) pow(v,2)
#define _cube(v)   pow(v,3)
// 大小判定
#define _max(x,y) max(x,y)
#define _min(x,y) min(x,y)
// string ⇒ int
#define _stringtoi(s) stoi(s)
// double 平方根
#define _sqrt(x) sqrt(x)
// double 引数 x 以上で最小の整数値
#define _ceil(x) ceil(x)

int main()
{
	uint32_t n, d, x;
	cin >> n >> d >> x;

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

	for (uint32_t j = 0; j < n; j++) {
		for (uint32_t i = 0; i < d; i++) {
			if ((v[j] * i + 1) > d) { break; }
			x++;
		}
	}

	printf("%d\n", x);
	return 0;
	//	std::cout << "Hello World!\n"; 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
#define int int64
#define rep(i, n) for(int i=0; i<n; i++)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define mk make_pair
#define fi first
#define se second
#define pb push_back
#define ALL(x) x.begin(), x.end()
#define V(T) vector<T>
typedef pair<int, int> P;
typedef pair<P, P> PP;
typedef vector<int> vi;
typedef vector<vi> vvi;
int max(int a, int b) {if(b>a) return b; else return a;}
int min(int a, int b) {if(b<a) return b; else return a;}


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

    vector<int> res(3, -1);
    rep(i, N+1) {
        rep(j, N-i+1) {
            int k = N-(i+j);
            int yen = 10000*i + 5000*j + 1000*k;
            if(yen == Y) {
                res[0] = i; res[1] = j; res[2] = k;
                break;
            }
        }
    }
    
    rep(i, 3) cout << res[i] << " ";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>  
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#define forn(i,a,b)        for( i = a ; i < b  ; i++ )
#define debug(x)           cout << #x << " " << x << " -- "
#define I__O               ios::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define ll                 long long  
#define p(x)               cout << x << "\n" ; 
#define MOD                100000007
#define pi                 pair<int,int>
#define vi                 vector <int>
#define pb                 push_back
#define vp                 vector <pair<ll,ll>>
#define endl               cout << "\n"
#define mi                 map <int,int> 
#define f1                 first 
#define s1                 second    
#define in                 insert
#define all(x)             x.begin(),x.end() 
using namespace std ; 
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set ; 
const int M = 1e9+7;    
const int N = 5e5;  // limit for array size
int tests() {
  int i,j ;
  vector <vector <int>> a(3,vector <int> (3,0));
  forn(i,0,3)
    forn(j,0,3)
      cin >> a[i][j] ;

  vector <vector<bool> > ok(3,vector <bool> (3,false)) ;
   int  x ;     
  int n ; cin >> n ; 
  while(n--){  
    cin >> x ; 
      forn(i,0,3)
        forn(j,0,3)
          if(!ok[i][j] && a[i][j] == x ){ 
            ok[i][j] = true ;
          }      

    }
  vector <int> r(3,0),c(3,0) ;
  forn(i,0,3){ 
    forn(j,0,3)
      r[i] += ok[i][j] ; 
    }    
  forn(i,0,3){ 
    forn(j,0,3)
      c[i] += ok[j][i] ; 
    }  
  int d1 = 0; 
  forn(i,0,3)
    forn(j,0,3)
      if(i == j  )
         d1 += (ok[i][j]) ;

     if(d1 == 3 )
        return cout << "Yes\n",0; 

  d1 = 0 ;         
  forn(i,0,3)
    forn(j,0,3)
      if(i+j == 2 )
         d1 += (ok[i][j]) ;
   if(d1 == 3 )
        return cout << "Yes\n",0; 
           
  forn(i,0,3)
    if(r[i] == 3 )
      return cout << "Yes\n",0; 
  forn(i,0,3)
    if(c[i] == 3 )
      return cout << "Yes\n",0; 
  cout << "No\n" ; 
  return 0; 
}
int main(){
    I__O ;  
    int cases = 1 ;
    // cin >> cases ; 
    while(cases--)
      tests(); 
  return 0 ; 
}

Measured memory_bytes: 256
import java.util.Scanner;							
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[][][] count = new int[4][3][10];
		int b,f,r,v;
		
		for(int i = 0; i < n; i++){
			b = sc.nextInt() - 1;
			f = sc.nextInt() - 1;
			r = sc.nextInt() - 1;
			v = sc.nextInt();
			count[b][f][r] += v;
		}
		
		for(int i = 0; i < 4; i++){
			for(int j = 0; j < 3; j++){
				for(int k = 0; k < 10; k++){
					if(k < 9)System.out.print(" " + count[i][j][k]);
					else System.out.println(" " + count[i][j][k]);
				}
			}
			if(i < 3)System.out.println("####################");
		}
	}
}

Measured memory_bytes: 29608
#include <cstdio>

int main(){
    int p[4][3][10];
    for(int i = 0; i<4; i++){
        for(int j=0; j<3; j++){
            for(int k=0; k<10; k++){
                p[i][j][k] = 0;
            }
        }
    }
    int n, b, f, r, v;
    scanf("%d", &n);
    for(int i = 0; i < n; i++){
        scanf(" %d %d %d %d", &b, &f, &r, &v);
        p[b-1][f-1][r-1] += v;
    }
    for(int i = 0; i<4; i++){
        for(int j=0; j<3; j++){
            for(int k=0; k<10; k++){
                printf(" %d", p[i][j][k]);
            }
            printf("\n");
        }
        if(i<3){
            printf("####################\n");
        }
    }
    return 0;
}


Measured memory_bytes: 2712