akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>

using namespace std;

int main() {
    int n;
    cin >> n;
    int a[2][n];
    for (int i = 0; i < 2; i++) {
        for (int j = 0; j < n; j++) {
            cin >> a[i][j];
        }
    }
    int max = 0;
    for (int i = 0; i < n; i++) {
        int t = 0;
        for (int j = 0; j <= i; j++) {
            t += a[0][j];
        }
        for (int j = i; j < n; j++) {
            t += a[1][j];
        }
        if (t > max) {
            max = t;
        }
    }
    cout << max << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fo(i,a,b) for(i=a;i<=b;i++)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define min(a,b) (a<b?a:b)
using namespace std;
typedef long long ll;
typedef vector<int> vt;
int i,j,T,d[55],fa[55],n,x,y,ans,cost;
vt a[55],b[55];
bool bz[55],w[55][55];
void dfs(int x,int y){
	fa[x]=y;
	if (bz[y]&&w[x][y]) bz[x]=1;
	for(int i=0;i<b[x].size();i++){
		int g=b[x][i];
		if (g!=y) dfs(g,x);
	}
}
void work(){
	memset(w,0,sizeof(w));
	scanf("%d",&n);
	fo(i,1,n) a[i].clear(),b[i].clear();
	fo(i,1,n-1){
		scanf("%d%d",&x,&y);
		w[x][y]=w[y][x]=1;
		a[x].push_back(y),a[y].push_back(x);
	}
	fo(i,1,n-1){
		scanf("%d%d",&x,&y);
		b[x].push_back(y),b[y].push_back(x);
	}
	ans=n+1;
	fo(i,1,n){
		memset(bz,0,sizeof(bz));
		bz[i]=1;
		dfs(i,0);
		fo(x,1,n) d[x]=a[x].size();
		cost=0;
		for(;;){
			fo(x,1,n) if (!bz[x]&&d[x]==1&&bz[fa[x]]) break;
			if (x>n) break;
			bz[x]=1,cost++;
			for(j=0;j<a[x].size();j++) d[a[x][j]]--;
 		}
		fo(x,1,n) if (!bz[x]) break;
		if (x>n) ans=min(ans,cost);
		if (a[i].size()>1||x>n||ans<=n) continue;
		memset(bz,0,sizeof(bz));
		bz[0]=1;
		fo(x,1,n) d[x]=a[x].size();
		for(;;){
			fo(x,1,n) if (!bz[x]&&d[x]<=1&&bz[fa[x]]) break;
			if (x>n) break;
			bz[x]=1;
			for(j=0;j<a[x].size();j++) d[a[x][j]]--;
 		}
 		fo(x,1,n) if (!bz[x]) break;
		if (x>n) ans=n;
	}
	printf("%d\n",ans>n?-1:ans);
}
int main(){
	for(scanf("%d",&T);T--;) work();
}


Measured memory_bytes: 256
/*
https://atcoder.jp/contests/dp/tasks/dp_b */
#include<bits/stdc++.h>
using namespace std;
int dp[100005];

int main()
{
	int n,k;
	cin >> n >>k;
	int a[n+1];
	for(int i=1;i<=n;i++)cin >> a[i];
	dp[0]=1e6,dp[1]=0;
    for(int i=2;i<=n;i++)dp[i]=INT_MAX;
    for(int i=2;i<=n;i++)
    {
    	for(int j=1;j<=k&&i-j>=0;j++)
    	dp[i]=min(dp[i-j]+abs(a[i]-a[i-j]),dp[i]);
    }
    cout << dp[n] << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
 
using namespace std;
 
#define rep(i, n) for(int i=0; i<(n); i++)
#define FOR(i, m, n) for(int i=(m);i<(n);i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define RSORT(x) sort((x).rbegin(),(x).rend())
#define REVE(x) reverse((x).begin(),(x).end())
#define mp make_pair
#define pb push_back
#define chmax(x,y) x = max(x,y)

 
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<vector<int> > VVI;
typedef pair<int, int> PII;
typedef long long LL;
typedef vector<bool> VB;
typedef vector<LL> VL;
typedef vector<vector<long long>> VVLL;
typedef vector<set<int>> VSI;
const int MOD = 1e9+7;
const int INF = 1e9;
const LL LINF = 1e18;
int gcd(int a, int b)
{
   if (a%b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a%b));
   }
}

int lcm(int a, int b)
{
   return a * b / gcd(a, b);
}
struct UnionFind {
    VI d;
    UnionFind(int n = 0): d(n,-1) {}
    int find(int x) {
        if(d[x] < 0) return x;
        return d[x] = find(d[x]);
    }
    bool unite(int x,int y) {
        x = find(x); y = find(y);
        if(x == y) return false;
        if(d[x] > d[y]) swap(x,y);
        d[x] += d[y];
        d[y] = x;
        return true;
    }
    bool same(int x,int y) { return find(x) == find(y); }
    int size(int x) { return -d[find(x)]; }
};
int deg[100005];
VI to[100005];

struct mint {
  LL x; // typedef long long ll;
  mint(LL x=0):x((x%MOD+MOD)%MOD){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += MOD-a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= MOD;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(LL t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
 
  // for prime mod
  mint inv() const {
    return pow(MOD-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

mint f(int n) {
    if(n == 0) return 1;
    mint x = f(n/2);
    x *= x;
    if(n%2 == 1) x *= 2;
    return x;
}

mint choose(int n,int a) {
    mint x = 1, y = 1;
    rep(i,a) {
        x *= n-i;
        y *= i+1;
    }
    return x/y;
}

int main() {
    int n,k;
    cin >> n >> k;
    LL ans = 0;
    for(LL i = k;i <= n+1 ;i++) {
      LL min = ((i)*(i-1))/2;
      LL max = ((i)*(n+(n-i+1)))/2;
      ans += max - min + 1;
    }
    cout << ans%MOD << endl;
}


Measured memory_bytes: 5988
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <functional>
#include <math.h>
#include <stdlib.h>
#include <map>
#include <deque>
#include <sys/timeb.h>
#include <fstream>

using namespace std;

#define repr(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repr(i,0,n)
#define reprrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) reprrev(i,0,n)
#define repi(itr,ds) for(auto itr=ds.begin();itr!=ds.end();itr++)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define mp make_pair
#define mt make_tuple
#define INF 1050000000
#define INFL 1100000000000000000LL
#define EPS (1e-10)
#define MOD 1000000007
#define PI 3.1415926536
#define RMAX 4294967295

typedef long long ll;
typedef pair<int, int> Pi;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<Pi> vPi;
typedef vector<vector<int> > vvi;
typedef vector<vector<bool> > vvb;
typedef vector<vector<ll> > vvll;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<double> > vvd;
typedef vector<vector<Pi> > vvPi;
typedef priority_queue<int, vector<int>, greater<int> > pqli;
typedef priority_queue<ll, vector<ll>, greater<ll> > pqlll;
typedef priority_queue<Pi, vector<Pi>, greater<Pi> > pqlP;
struct Edge {
	int from, to, cost;
	bool operator<(Edge e) {
		return cost < e.cost;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
template <class T>
using vec = vector<T>;
template<class T>
using pql = priority_queue<T, vector<T>, greater<T>>;
string debug_show(Pi a) {
	return "(" + to_string(a.first) + "," + to_string(a.second) + ")";
}

template<class T>
struct augEdge {
	T from, to;
	int cost;
	bool operator<(augEdge e) { return cost < e.cost; }
	bool operator>(augEdge e) { return cost > e.cost; }
};
template<class T>
using augGraph = vector<augEdge<T>>;



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

	char a, b;
	cin >> a >> b;
	if (a == b) {
		cout << 'H' << endl;
	}
	else {
		cout << 'D' << endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define pi 3.14159265358979323846
int read(){
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}

long long num[2000000];
long long n;

int main(){
    n=read();
    for (int i=1;i<=n;i++)  num[i]=read();
    int cnt=0;
    for (int i=1;i<=n;i++){
        if (num[i]==i)  cnt++;
    }
    int boolean=0;
    for (int i=1;i<=n&&cnt;i++){
        if (num[i]==i){
            boolean++;
        }
        else{
            cnt-=(boolean)/2;
            boolean=0;
        }
    }
    if (boolean>=2)  cnt-=(boolean)/2;
    cout<<cnt<<endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define all(vec) vec.begin(),vec.end()
#define mp make_pair
using namespace std;
using ll=long long;
using P=pair<int,int>;
const ll INF=1LL<<30;
const ll LINF=1LL<<61;
const double eps=1e-5;
const ll MOD=1e9+7;
char c[1010][1010];
ll dp[1010][1010];
int main(){
    int h,w;cin>>h>>w;
    for(int i=0;i<h;i++){
        cin>>c[i];
    }
    dp[0][0]=1;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if(i<h-1&&c[i+1][j]!='#'){
                dp[i+1][j]+=dp[i][j];dp[i+1][j]%=MOD;
            }
            if(j<w-1&&c[i][j+1]!='#'){
                dp[i][j+1]+=dp[i][j];dp[i][j+1]%=MOD;
            }
        }
    }
    cout<<dp[h-1][w-1]<<endl;
}   


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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back
#define pii pair<int, int>
#define pll pair<ll, ll>

using namespace std;

typedef long long ll;

/* --- INFやMODの値が適切か確認する --- */
// const int INF = 1 << 30;
// const ll INF = 1LL << 60;
// const ll MOD = 1000000007;

int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> d(n, vector<int>());
  rep(i, m) {
    int s, c;
    cin >> s >> c;
    d[s - 1].eb(c);
  }

  int ans = 0;
  if (n == 1) {
    rep(i, n) {
      vector<int> a = d[i];
      uniq(a);
      if (a.size() > 1) {
        ans = -1;
        break;
      }

      if (a.size() != 0) ans = a[i];
    }
  } else {
    rep(i, n) {
      vector<int> a = d[i];
      uniq(a);
      if (a.size() > 1) {
        ans = -1;
        break;
      }

      if (a.size() == 0) {
        if (ans == 0)
          ans = 1;
        else
          ans *= 10;
      } else {
        if (ans == 0 && a[0] == 0) {
          ans = -1;
          break;
        }
        ans = 10 * ans + a[0];
      }
    }
  }

  cout << ans << endl;
}


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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

template<typename H> bool chmin(H& v1, const H v2) { if (v1 > v2) { v1 = v2; return true; } return false; }
template<typename H> bool chmax(H& v1, const H v2) { if (v1 < v2) { v1 = v2; return true; } return false; }
template<typename H> void read(H& head) { cin >> head; }
template<typename H, typename ...T> void read(H& head, T& ...tail) { cin >> head; read(tail...); }
template<typename H> void write(H head) { cout << head << '\n'; }
template<typename H, typename ...T> void write(H head, T ...tail) { cout << head << " "; write(tail...); }
template<typename ...T> void die(T ...tok) { write(tok...); exit(0); }

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

	const ll mx = 1'000'000'000;
	ll x1, y1, x2, y2, x3, y3, s;
	read(s);
	x1 = 0;
	y1 = 0;
	x2 = mx;
	y2 = 1;
	x3 = (mx - s % mx) % mx;
	y3 = (s + x3) / mx;

	write(x1, y1, x2, y2, x3, y3);
}


Measured memory_bytes: 256
N,K = map(int,input().split())
pls = list(map(int,input().split()))
ans = sum(pls[:K])/2 + 0.5*K
sum1 = ans
for i in range(1,N-K+1):
    sum1 += -pls[i-1]/2+pls[i+K-1]/2
    ans = max(ans,sum1) 
print(ans)

Measured memory_bytes: 98704
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0; i<n; i++)
typedef long long ll;
typedef long long unsigned int llu;
ll MOD = 1000000007;
ll INF = 1000000009;

void solve(){

    int n;
    cin >> n;
    string s,t;
    cin >> s >> t;
    rep(i,n){
        cout << s[i] << t[i];
    }
    cout << endl;

}

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


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

cnt = 0

last = [A, B, C]

while A % 2 == 0 and B % 2 == 0 and C % 2 == 0:
    a = A // 2
    b = B // 2
    c = C // 2
    cnt += 1
    A = b + c
    B = a + c
    C = a + b
    if A in last and B in last and C in last:
        print(-1)
        exit()

    last = [A, B, C]

print(cnt)



Measured memory_bytes: 9128
#![allow(unused_imports)]
use std::cmp::*;
use std::collections::*;
use itertools::Itertools;
use proconio::{input, marker::*};
use superslice::*;
fn main() {
    input! {
        s: usize, w: usize,
    }

    if w>=s {
        println!("unsafe");

    } else {
        println!("safe");
    }
}


Measured memory_bytes: 2152
#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    vector<vector <int >> a(n,vector<int> (3));
    for(int i=0;i<n;i++)
    {
      for(int k=0;k<3 ;k++)
      cin>>a[i][k];
    }
  vector<vector<int >> dp(n+1,vector<int >(3));
  for(int i=1;i<=n;i++)
  {
    for(int j=0;j<3;j++)
      for(int k=0;k<3;k++)
      if(j!=k) dp[i][j]=max(dp[i][j],dp[i-1][k]+a[i-1][j]);
  }
  cout<<max(dp[n][0],max(dp[n][1],dp[n][2]));
    return 0;
}

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

int main()
{
	long long int n,m,sum=0;
	cin>>n>>m;
	
	for(long long int i=0;i<m;i++)
	{
		long long int a;
		cin>>a;
		sum+=a;
	}
	if(sum <= n)
	{
		cout<<(n-sum);
	}
	else{
		cout<<-1;
	}
	return 0;
}

Measured memory_bytes: 3636
# define _CRT_SECURE_NO_WARNINGS 1
# define _USE_MATH_DEFINES
# include <iostream>
# include <numeric>
# include <string>
# include <bitset>
# include <vector>
# include <algorithm>
# include <cstdlib>
# include <cstdio>
# include <cstring>
# include <cstdlib>
# include <iomanip>
# include <queue>
# include <sstream>
# include <climits>
# include <complex>
# include <cmath>
# include <list>
# include <functional>
# include <string>
# include <ctime>
# include <set>
# include <forward_list>
# include <map>
# include <stack>
using namespace std;
# define INF ((int)(1<<25))
# define REP(i,n) for(int i=0;i<(int)n;i++)
# define FOR(i,n) REP(i,n)
# define FORI(i,k,n) for(int i=k;i<(int)n;i++)
# define TORAD 2.0*M_PI/360.0
# define INT(x) int x;cin>>x;
# define ALL(x) begin(x),end(x)
# define RALL(x) (x).rbegin(),(x).rend()
# define DEBUG(x) cout<<#x<<":"<<x<<endl;
# define EPS 1e-12
#ifdef _MSC_VER
#include <intrin.h>
#define __builtin_popcount __popcnt
#endif
typedef long long lint;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
const int dx[4] = { 0,1,0,-1 }, dy[4] = { -1,0,1,0 };
template<class T> void debug(T a) { for (auto i : a)cout << i << endl; }

int main()
{
	while (1)
	{
		int n, x, y;
		cin >> n >> x >> y;
		if (n + x + y == 0)break;
		vector<pii> a(1, pii(0, 0));
		a.push_back(pii(y, x));
		FOR(i, n)
		{
			int p, s;
			cin >> p >> s;
			pii now = a[p];
			a.erase(a.begin() + p);
			s %= (now.first + now.second) * 2;
			pii A, B;
			A = B = now;
			if (s <= now.second)
			{
				A.second = s;
				B.second = now.second - s;

			}
			else if (s <= now.first + now.second)
			{
				A.first = s - now.second;
				B.first = now.first - A.first;
			}
			else if (s <=  now.first +2* now.second)
			{
				B.second = s - now.first - now.second;
				A.second = now.second - B.second;
			}
			else
			{
				B.first = s - now.second * 2 - now.first;
				A.first = now.first - B.first;
			}
			if (A.first*A.second >= B.first*B.second)
			{
				a.push_back(B);
				a.push_back(A);
			}
			else
			{
				a.push_back(A);
				a.push_back(B);
			}
		}
		vector<int> ans;
		FORI(i, 1, a.size())
		{
			int area = a[i].first*a[i].second;
			ans.push_back(area);
		}
		sort(ALL(ans));
		FOR(i, ans.size())
		{
			if (i)cout << " ";
			cout << ans[i];
		}
		cout << endl;
	}
}

Measured memory_bytes: 3140
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time
 
sys.setrecursionlimit(10**7)
inf = 10**20
MOD = 998244353
#########################
N = int(input())
a = list(map(int,input().split()))
sumOfAbsValues = 0
minimumValueAbs = 10**10
minusSignParity = 0
zeroExists = False
for value in a:
    if value == 0:
        zeroExists = True
    absValue = abs(value)
    sumOfAbsValues += absValue
    minimumValueAbs = min(minimumValueAbs,absValue)
    if value < 0:
        minusSignParity += 1
if zeroExists:
    ans = sumOfAbsValues
elif minusSignParity%2 == 0:
    ans = sumOfAbsValues
else:
    ans = sumOfAbsValues - 2*minimumValueAbs
print(ans)

Measured memory_bytes: 17264
# coding: utf-8
N=int(input())
A1=list(map(int,input().split()))
A2=list(map(int,input().split()))

sA1=[A1[0]]
sA2=[A2[-1]]

for i in range(N-1):
    sA1.append(sA1[-1]+A1[i+1])
    sA2.insert(0,sA2[0]+A2[-(i+2)])

candies=[]

for i in range(N):
    candies.append(sA1[i]+sA2[i])

print(max(candies))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long double PI = 3.14159265358979323846;

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

    int n, m, x;
    cin >> n >> m >> x;
    vector<vector<int>> a(n, vector<int>(m));
    vector<int> c(n);
    for (int i = 0; i < n; ++i) {
        cin >> c[i];
        for (int j = 0; j < m; ++j) {
            cin >> a[i][j];
        }
    }
    int ans = 1e9;
    int combs = 1 << n;
    for (int mask = 0; mask < combs; ++mask) {
        int cost = 0;
        vector<int> algos(m, 0);
        for (int i = 0; i < n; ++i) {
            if ((mask >> i) & 1) {
                cost += c[i];
                for (int j = 0; j < m; ++j) {
                    algos[j] += a[i][j];
                }
            }
        }
        bool possible = true;
        for (int i = 0; i < m; ++i) {
            if (algos[i] < x) { possible = false; };
        }
        if (possible) {
            ans = min(ans, cost);
        }
    }
    if (ans == 1e9) {
        cout << -1 << '\n';
    } else {
        cout << ans << '\n';
    }

    return 0;
}

Measured memory_bytes: 3624
/*	
*  Sachin Mittal
*/
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define M 998244353
#define mod 1000000007
#define all(v) v.begin(),v.end()
#define rep(i,j,n) for(int i=j;i<n;i++)
#define F first
#define S second
#define lb lower_bound
#define mem0(dp) memset(dp,0,sizeof(dp))
#define mem1(dp) memset(dp,-1,sizeof(dp))
#define pb push_back
#define sz(s) (int)(s.size())
#define debug(x) cout << #x << " = " << x << '\n';

void solve()
{
    int n;
    cin >> n;
    vector<int> a(n);
    vector<int> has_come(1000005, 0), uncheck(1000005, 1);
    rep(i, 0, n){
    	cin >> a[i];
    }
    int ans = 0;
    rep(i, 0, n){
    	if(!has_come[a[i]]){
    		for(int j = 2 * a[i]; j < 1000005; j += a[i]){
    			uncheck[j] = 0;
    		}
    	}
    	has_come[a[i]]++;
    }
    rep(i, 0, n){
    	if(uncheck[a[i]] and has_come[a[i]] == 1){
    		ans++;
    	}
    }
    cout << ans << '\n';
}

int32_t main(){
ios_base::sync_with_stdio(false); 
cin.tie(0); cout.tie(0);
int tst = 1;
//cin >> tst;
while(tst--)
{
	solve();
}
}

Measured memory_bytes: 20340
n = int(input())
t, x, y = 0,0,0
for _ in range(n):
    next_t, next_x, next_y = map(int, input().split())
    diff = abs(next_x - x) + abs(next_y - y)
    if ((next_t - t) < diff) or (diff - (next_t - t)) % 2 ==1:
        print('No')
        exit()
print('Yes')

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pld pair<long double, int>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define ff first
#define ss second
#define SZ(x) ((int)(x).size())
#define ld long double
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int MAXN = 3e5+100;
int N, K, a[MAXN];

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

int dp[MAXN+1], st[4*(MAXN+10)];
int get(int i, int l, int r, int ql, int qr){
    if(ql <= l && r <= qr){
        return st[i];
    }
    if(qr < l || ql > r)
        return 0;
    int m = (l + r) / 2;
    int r1 = get(2*i+1, l, m, ql, qr);
    int r2 = get(2*i+2, m+1, r, ql, qr);
    return (max(r1, r2));
}

void add(int i, int l, int r, int p, int k){
    if(p <= l && r <= p){
        st[i] = k;
        return;
    }
    int m = (l + r) / 2;
    if(p <= m)
        add(2*i+1, l, m, p, k);
    else
        add(2*i+2, m+1, r, p, k);
    st[i] = max(st[2*i+1], st[2*i+2]);
}

void solve(){
    read();
    for(int i = 0; i < N; i++){
        int l = max(a[i] - K, 0);
        int r = min(a[i] + K, MAXN);
        dp[a[i]] = max(dp[a[i]], get(0, 0, MAXN, l, r) + 1);
        add(0, 0, MAXN, a[i], dp[a[i]]);
    }
    cout << *max_element(dp, dp+MAXN+1);
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    solve();
    return 0;
}


Measured memory_bytes: 10096
// I/O
#include <iostream>
#include <iomanip>

// data structures
#include <set>
#include <queue>

// manipulations
#include <algorithm>

#define rep(i,n) for(int (i)=0;(i)< (n);++(i))
#define REP(i,n) for(int (i)=1;(i)<=(n);++(i))
#define for_lowercase(c) for(char (c)='a';(c)<='z';++(c))
#define for_uppercase(c) for(char (c)='A';(c)<='Z';++(c))
#define ALL(a) (a).begin(),(a).end()
using LLI = long long int;
LLI GCD(LLI a,LLI b){ if(a<b) return GCD(b,a); else if(a%b==0) return b; else return GCD(b,a%b); }
LLI LCM(LLI a,LLI b){ return (a/GCD(a,b))*b; }
using VI  = std::vector<LLI>;
using PI  = std::pair<LLI,LLI>;
using VVI = std::vector<VI>;
using VPI = std::vector<PI>;
template<class T> bool is_odd (T x){ return   x%2 ; }
template<class T> bool is_even(T x){ return !(x%2); }
LLI combination(LLI n,LLI k,bool reset=false){
    static VVI C; static LLI n_hashed = -1;
    if(n<0){ std::cerr << "[ERROR] n must be non-negative in combination()" << std::endl; exit(1); }
    if(!(0<=k&&k<=n)){ std::cerr << "[WARNING] k should be in range [0,n] in combination()" << std::endl; return 0; }
    if(n_hashed<n || reset){
        C.resize(n+1);
        for(int i=0;i<=n;++i) C[i].resize(i+1,1); // filled with 1
        for(int i=1;i<=n;++i)for(int j=1;j<i;++j) C[i][j] = C[i-1][j-1] + C[i-1][j];
        n_hashed = n;
    }
    return C[n][k];
}
namespace compProg{
    template<class T> std::ostream& ostream_iterable_impl(std::ostream &os,
                                                          const T &t,
                                                          const std::string &LEFT,
                                                          const std::string &RIGHT,
                                                          const std::string &DELIMITER){
        bool first = true;
        os << LEFT;
        for(const auto &x:t){
            if(first) first = false;
            else os << DELIMITER;
            os << x;
        }
        os << RIGHT;
    }
    void please_never_call_this_function_to_eliminate_warning(){
        is_odd(0); is_even(0); combination(0,0); LCM(0,0);
        rep(i,0)REP(j,0)for_lowercase(c)for_uppercase(c);
        std::sort(ALL(std::string("")));
    }
}
template<class T> std::ostream& operator<<(std::ostream &os,const std::vector<T> &t){
    return compProg::ostream_iterable_impl(os,t,"[","]",", ");
}
template<class T> std::ostream& operator<<(std::ostream &os,const std::set<T> &t){
    return compProg::ostream_iterable_impl(os,t,"{","}",", ");
}
template<class T> std::ostream& operator<<(std::ostream &os,const std::multiset<T> &t){
    return compProg::ostream_iterable_impl(os,t,"{","}",", ");
}

int main() {
    std::ios::sync_with_stdio(false);
    LLI N;
    std::cin >> N;
    VI a(N);
    rep(i,N) std::cin >> a[i];

    LLI max = 100000;
    VI count(max,0);
    rep(i,N) {
        count[a[i]]++;
        if( 0 <= a[i]-1 )
            count[a[i]-1]++;
        if( a[i]+1 < max)
            count[a[i]+1]++;
    }
    std::cout << *std::max_element(count.begin(),count.end()) << std::endl;
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
long long a,b,c,d; 
long long cc,dd,cd;
long long num(long long nw){
	long long x=a/nw;
	long long y=b/nw;
	if(nw*x!=a)x++;
	return y-x+1;
}
long long gcd(long long x,long long y){
	if(y==0)return x;
	return gcd(y,x%y);
}
int main() { 
    //freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	cin>>a>>b>>c>>d;
	cc=num(c);
	dd=num(d);
	if(c<d)swap(c,d);
	cd=c*d/gcd(c,d);
	cd=num(cd);
	cout<<b-a+1-cc-dd+cd<<endl;
    return 0; 
}

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

int main() {
	string s;
	cin >> s;
	for (int i = 0; i < s.length(); i += 2) {
		if (s.substr(i, 2) != "hi") {
			cout << "No";
			return 0;
		}
	}
	cout << "Yes";

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
map<int,int> m;vector<int> v;
int main(){
    int n,ans;cin>>n;
    for(register int i=1;i<=n;++i){
        int x;cin>>x;
        if(m[x]==0) v.push_back(x);++m[x];
    }
    for (register int i=0;i<v.size();++i) 
        if(m[v[i]]>=v[i]) ans+=m[v[i]]-v[i]; else ans+=m[v[i]];
    cout<<ans;
    return 0;
}

Measured memory_bytes: 6264
N = int(input())
ans = []


def get_range(s):
    start = ord("a")
    end = ord(max(s))
    return [chr(c) for c in range(start, end + 2)]


def pana(s):
    if len(s) == N:
        ans.append(s)
        return
    for t in get_range(s):
        pana(s + t)
    return


pana("a")
ans.sort()
print(*ans, sep="\n")

Measured memory_bytes: 14464
/*
      author  : nishi5451
      created : 14.08.2020 12:53:27
*/

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


int main(){
    int n,m;
    cin >> n >> m;
    vector<int> v(n+1);
    rep(i,m){
        int a,b;
        cin >> a >> b;
        v[a]++;
        v[b]++;
    }
    for(int i=1; i<=n; i++)
        cout << v[i] << endl;
    return 0;
}

Measured memory_bytes: 3616
#include <set>
#include <array>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <queue>
#include <vector>
#include <tuple>
#include <string>
#include <math.h>
#include <time.h>
#include <bitset>
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <limits>
#include <climits>
#include <numeric>
#include <functional>

#define lnd '\n'
// #define reverse(i, n) for(ll i = n-1; i >= 0; --i)
#define from(i, n) for (ll i = 0; i < n; ++i)
#define loop(i, n) for(ll i = 0; i < n; i++)
#define REPN(i, n) for (ll i = 1; i <= n; ++i)
#define ALL(s) (s).begin(), (s).end()
#define rALL(s) (s).rbegin(), (s).rend()
#define sz(s) (int)(s).size()
#define mk make_pair
#define pb push_back
#define sqr(s) ((s) * (s))

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef unsigned int ui;

template <class T>
T GCD (T a, T b) {
  if(a == 0) return b;
  return GCD(b%a, a);
}

template <class T>
T LCM(T a, T b){
  return a*b/GCM(a,b);
}

template <class T>
T modpow(T x, T p){
    T res = 1;
    while(p > 0){
        if(p&1) res *= x;
        x *= x;
        p /= 2;
    }
    return res;
}

template <class T>
T modpow(T x, T p, ll mod){
    T res = 1;
    while(p > 0){
        if(p&1) res = (res*x)%mod;
        x = (x*x)%mod;
        p /= 2;
    }
    return res%mod;
}

template <class T>
void print(T a[], ll n){
    for (ll i = 0; i < n; i++) std::cout << a[i] << ' ';
    cout << endl;
}

template<class T>
void printc(T c){
    for(auto const& v: c) std::cout << v << ' ';
    cout << endl;
}

struct HASH{
  size_t operator()(const pair<long,long>&x)const{
    return hash<long long>()(((long long)x.first)^(((long long)x.second)<<32));
  }
};

bool pair_sort(const pair<int, int> &p1, const pair<int,int> &p2){
    if(p1.first != p2.first) return p1.first < p2.first;
    else return p1.second < p2.second;
}

const int INF = std::numeric_limits<int>::max();
const ll M_INF = std::numeric_limits<ll>::min();
const ll LL_INF = std::numeric_limits<ll>::max();

void solution();
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    solution();
    return 0;
}

void solution(){
  ll a, b, c;
  cin >> a >> b >> c;
  cout << c << " " << a << " " << b << endl;
}     



Measured memory_bytes: 256
import std.stdio;

void show(int[][] square) {
  for(int i = 0; i < square.length; i++)
    for(int j = 0; j < square[i].length; j++)
      writef("%4d%s", square[i][j], j == square.length - 1 ? "\n" : "");
}

int[][] magic_square(int[][] square, int n) {
  int x = (n - 1) / 2;
  int y = (n - 1) / 2 - 1;
  int len = 0;
  while(len <= n * n) {
    if (x < 0)  {x += n;}
    if (y < 0)  {y += n;}
    if (x >= n) {x -= n;}
    if (y >= n) {y -= n;}
    if (square[x][y] == 0) {
      square[x][y] = len;
      x = x + 1;
      y = y + 1;
      len++;
    }
    else {
      x = x + 1;
      y = y - 1;
    }
  }
  return square;
}

void main() {
  for(int n; readf("%d\n", &n), n != 0;) {
    magic_square(new int[][](n, n), n).show;
  }
}

Measured memory_bytes: 1100
def main():
    a, b = input().split()

    liar = False
    if  a == "H" and b == "H" :
        liar = False
    elif a == "H" and b == "D" :
        liar = True
    elif a == "D" and b == "H" :
        liar = True
    elif a == "D" and b == "D" :
        liar = False
    
    if liar:
        print("D")
    else:
        print("H")

main()

Measured memory_bytes: 2940
A, B = map(int, input().split())
ans = -1
i = 0
while True:
    A8 = i*0.08//1
    B10 = i*0.1//1
    if A == A8 and B == B10:
        ans = i
        break
    elif A < A8 and B < B10:
        break
    i += 1
print(ans)

Measured memory_bytes: 38384
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define REVERSE(a) reverse(a.begin(), a.end())
#define int long long
#define INF 1000000000000000
using namespace std;

typedef vector<int> vec;
typedef vector<vec> mat;
typedef pair<int, int> Pii;

template<typename T>
void readvec(vector<T> &a);
void readindex(vector<int> &a);



signed main(){

    int N, M;
    cin >> N >> M;
    vec count(N, 0);
    int a, b;
    REP(i, M){
        cin >> a >> b;
        count[a - 1]++;
        count[b - 1]++;
    }

    string ans = "YES";
    REP(i, N) if(count[i] % 2 == 1) ans = "NO";

    cout << ans;
    
    return 0;
}


template<typename T>
void readvec(vector<T> &a){
    REP(i, a.size()){
        cin >> a[i];
    }
}
void readindex(vector<int> &a){
    REP(i, a.size()){
        cin >> a[i];
        a[i]--;
    }
}

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

int main() {
  long A,B,K;
  cin >> A >> B >> K;

  if (K < A) {
    cout << A - K << " " << B << endl;
  } else if (K < (A + B)) {
    cout << 0 << " " << (A + B) - K << endl;
  } else {
    cout << 0 << " " << 0 << endl;
  }
}


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





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

	vector<int>a(M+1);

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

	vector<long>dp(N+1);
	vector<int>tf(N+1);
	for(int i=0;i<N+1;i++)tf[i]=0;
	for(int i=0;i<M;i++)tf[a[i]]=1;

	dp[0]=1;
	if(tf[1]==1){
		dp[1]=0;
	}
	else{
		dp[1]=1;
	}
	
	for(int i =2;i<N+1;i++){
		if(tf[i]==1){
			dp[i]=0;
		}
		else{
			dp[i]=dp[i-1]+dp[i-2];
			dp[i]%=1000000007;
		}
	}
	cout<<dp[N];

	
}


Measured memory_bytes: 1792
from collections import deque


def main():
    n = int(input())
    Q = deque()

    for _ in range(n):
        cmd = input().split()

        if cmd[0] == "deleteFirst":
            Q.popleft()
        elif cmd[0] == "deleteLast":
            Q.pop()
        elif cmd[0] == "insert":
            Q.appendleft(int(cmd[1]))
        elif cmd[0] == "delete" and int(cmd[1]) in Q:
            Q.remove(int(cmd[1]))

    print(*Q)


if __name__ == "__main__":
    main()



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

string a[11];

int main() {
  int n,m,k;
  cin >> n >> m >> k;
  for(int i=0;i<n;i++)
    cin>>a[i];
  int ans=1e9;
  for(int mask=0;mask<(1<<(n-1));mask++){
    vector<int> p;
    p.push_back(0);
    for(int i=1;i<n;i++)
      if(mask>>(i-1)&1)
        p.push_back(i);
    p.push_back(n);
    int cur=p.size()-2;
    int l=0;
    int r=0;
    while(l<m){
      vector<int> c(p.size()-1);
      while(r<m){
        for(int t=0;t<p.size()-1;t++)
          for(int i=p[t];i<p[t+1];i++)
            c[t]+=(a[i][r]=='1');
        if(*max_element(c.begin(),c.end())>k)
          break;
        r++;
      }
      if(l==r){
        cur=1e9;
        break;
      }
      l=r;
      cur+=l<m;
    }
    ans=min(cur,ans);
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 3612
check=[list(input()) for i in range(3)]
cur=0
flag=True
while flag:
  if (len(check[0])==0 and cur==0) or (len(check[1])==0 and cur==1) or (len(check[2])==0 and cur==2):
    flag=False
    break
  temp=check[cur].pop(0)
  if temp=="a":
    cur=0
  elif temp=="b":
    cur=1
  else:
    cur=2
if cur==0:
  print("A")
elif cur==1:
  print("B")
else:
  print("C")


Measured memory_bytes: 3188
#include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <utility>
#include <map>
#include <list>
#include <climits>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>

// #define cerr if(false)cerr
#define watch(x) cerr << "> " << #x << ": " << x << "\n";

using namespace std;

template <typename T>
std::ostream &operator <<(std::ostream &out, vector<T> &v) {
	for (typename vector<T>::size_type i = 0; i < v.size(); ++i)
		out << v[i] << " ";
	out << "\n";
    return out;
}
template <typename T, typename N>
std::ostream &operator <<(std::ostream &out, vector<pair<T, N> > &v) {
	for (size_t i = 0; i < v.size(); ++i)
		out << "(" << v[i].first << ", " << v[i].second << ") ";
	out << "\n";
    return out;
}
template <typename T>
std::ostream &operator <<(std::ostream &out, vector<vector<T> > &v) {
	for (size_t i = 0; i < v.size(); ++i) {
		for (size_t j = 0; j < v[i].size(); ++j) {
			out << v[i][j] << " ";
		}
		out << "\n";
	}
   	return out;
}

int main() {

	std::ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	int n;
	cin >> n;

	vector<int> b(n + 1), c(2e5 + 1);
	int a;
	for (int i = 1; i <= n; ++i) {
		cin >> a;
		b[i] = a + i;
		if (i - a >= 0) {	
			++c[i - a];
		}
	}

	long long ans = 0;
	for (int i = 1; i <= n; ++i) {
		if (b[i] <= 2e5) {
			ans += c[b[i]];
		}
	}

	cout << ans << "\n";

	return 0;

}

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

#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ALL(a) (a).begin(),(a).end()
#define Yes(hoge) cout<<((hoge)?"Yes":"No")<<endl;
#define YES(hoge) cout<<((hoge)?"YES":"NO")<<endl;
typedef struct aaaaa{
  int x,y,t;
}Grid;
using namespace std;
int main(){
  int h,w,n;cin>>h>>w>>n;
  vector<pair<int,int> > pii;
  int hge[500][500]={};
  for(int i=0;i<n;i++){
    int a,b;cin>>a>>b;
    if(a>=b)
      pii.pb(mp(a,b));
     hge[--a][--b]=1;
    //if(a>b)
    //pii.pb(a);
  }
  /*for(int i=0;i<h;i++){
    for(int j=0;j<w;j++)
      cout<<hge[i][j];
    cout<<endl;
    }*/
  sort(ALL(pii));
  int po=0;
  for(int i=0;i<pii.size();i++){
    if(pii[i].S<pii[i].F-po){
      cout<<pii[i].F-1<<endl;
      return 0;
    }else if(pii[i].S==pii[i].F-po){
      po++;
    }
    //cout<<po<<endl;
  }
  cout<<h<<endl;
  return 0;
}

Measured memory_bytes: 2420
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**8)
input = sys.stdin.readline

n = int(input())
a = [int(item) for item in input().split()]

minima = a[0]
ans = 0
for item in a:
    if item <= minima:
        ans += 1
        minima = item
print(ans)

Measured memory_bytes: 25748
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  string S;
  cin>>S;
  int N=S.size();
  vector<int> A(N+1),B(N+1);
  A[0]=0,B[N]=0;
  for(int i=0;i<N;i++){
    if(S[i]=='<')
      A[i+1]=A[i]+1;
    else
      A[i+1]=0;
  }
  for(int i=N;i>0;i--){
    B[i-1]=B[i];
    if(S[i-1]=='>')
      B[i-1]=B[i]+1;
    else
      B[i-1]=0;
  }
  int k=0;
  for(int i=0;i<=N;i++)
    k+=max(A[i],B[i]);
  cout<<k<<endl;
}

Measured memory_bytes: 11636
import java.util.*; import java.io.*; import java.math.*;
public class Main{
	//Don't have to see. start------------------------------------------
	static class InputIterator{
		ArrayList<String> inputLine = new ArrayList<String>(1024);
		int index = 0; int max; String read;
		InputIterator(){
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			try{
				while((read = br.readLine()) != null){
					inputLine.add(read);
				}
			}catch(IOException e){}
			max = inputLine.size();
		}
		boolean hasNext(){return (index < max);}
		String next(){
			if(hasNext()){
				return inputLine.get(index++);
			}else{
				throw new IndexOutOfBoundsException("There is no more input");
			}
		}
	}
	static HashMap<Integer, String> CONVSTR = new HashMap<Integer, String>();
	static InputIterator ii = new InputIterator();//This class cannot be used in reactive problem.
	static PrintWriter out = new PrintWriter(System.out);
	static void flush(){out.flush();}
	static void myout(Object t){out.println(t);}
	static void myerr(Object t){System.err.print("debug:");System.err.println(t);}
	static String next(){return ii.next();}
	static boolean hasNext(){return ii.hasNext();}
	static int nextInt(){return Integer.parseInt(next());}
	static long nextLong(){return Long.parseLong(next());}
	static double nextDouble(){return Double.parseDouble(next());}
	static ArrayList<String> nextStrArray(){return myconv(next(), 8);}
	static ArrayList<String> nextCharArray(){return myconv(next(), 0);}
	static ArrayList<Integer> nextIntArray(){
		ArrayList<String> input = nextStrArray(); ArrayList<Integer> ret = new ArrayList<Integer>(input.size());
		for(int i = 0; i < input.size(); i++){
			ret.add(Integer.parseInt(input.get(i)));
		}
		return ret;
	}
	static ArrayList<Long> nextLongArray(){
		ArrayList<String> input = nextStrArray(); ArrayList<Long> ret = new ArrayList<Long>(input.size());
		for(int i = 0; i < input.size(); i++){
			ret.add(Long.parseLong(input.get(i)));
		}
		return ret;
	}
	static String myconv(Object list, int no){//only join
		String joinString = CONVSTR.get(no);
		if(list instanceof String[]){
			return String.join(joinString, (String[])list);
		}else if(list instanceof ArrayList){
			return String.join(joinString, (ArrayList)list);
		}else{
			throw new ClassCastException("Don't join");
		}
	}
	static ArrayList<String> myconv(String str, int no){//only split
		String splitString = CONVSTR.get(no);
		return new ArrayList<String>(Arrays.asList(str.split(splitString)));
	}
	public static void main(String[] args){
		CONVSTR.put(8, " "); CONVSTR.put(9, "\n"); CONVSTR.put(0, "");
		solve();flush();
	}
	//Don't have to see. end------------------------------------------
	static void solve(){//Here is the main function
		int N = nextInt();
		ArrayList<Integer> list = nextIntArray();
		HashSet<Integer> set = new HashSet<Integer>();
		for(int i = 0; i < N; i++){
			if(set.contains(list.get(i))){
				myout("NO");
				return;
			}
			set.add(list.get(i));
		}
		myout("YES");
	}
	//Method addition frame start



	//Method addition frame end
}


Measured memory_bytes: 75008
n = int(input())
ans = [0] * (n + 1)

for x in range(1, 101):
    for y in range(1, 101):
        for z in range(1, 101):
            val = x ** 2 + y ** 2 + z ** 2 + x * y + y * z + z * x
            if val <= n:
                ans[val] += 1

print(*ans[1:], sep="\n")


Measured memory_bytes: 9312
#include <iostream>

using namespace std;
int main() {
  long  n, amount;
  cin >> n >> amount;
  const int TEN_THOUSAND = 10000;
  const int FIVE_THOUSAND = 5000;
  const int ONE_THOUSAND = 1000;
  // Find the number of 10000 yen bills
  /*int numTenThousand = y/TEN_THOUSAND;
  int numFiveThousand = (y - (numTenThousand*TEN_THOUSAND))/FIVE_THOUSAND;
  int numOneThousand = (y - (numTenThousand*TEN_THOUSAND + numFiveThousand*FIVE_THOUSAND))/ONE_THOUSAND;
  int diff = 0;
  if (numTenThousand + numFiveThousand + numOneThousand == n) {
    // We are done
     cout << numTenThousand << " " << numFiveThousand << " " << numOneThousand << "\n";
  } else {
    // need to loop onto smaller denominations
    // have to do some division stuff, maybe.
    // have to think if theres a way to tell if no soln
    // can convert one ten thousand to:
    // - 2 x 5000
    //
    // can convert one five thousand to:
    // - 5 x 1000
    //
    // if diff == 5, or a multiple 5 and we have remaining notes, then we can
    // diff has to be a multiple of 2, 5, or 10
    diff = n - (numTenThousand + numFiveThousand + numOneThousand);
    while (diff >= 0 ) {
      cout << "diff: " << diff << endl;
      cout << "x:" << numTenThousand << ", y:" << numFiveThousand << ", z:" << numOneThousand << "\n";
      if (numFiveThousand > 0) {
        numFiveThousand = numFiveThousand - 1;
        numOneThousand = numOneThousand + 5;
        
        diff = n - (numTenThousand + numFiveThousand + numOneThousand);
      } else if (diff % 5 == 0 && numFiveThousand <= 0) {
        cout << "B-1 -1 -1 " << endl;
        diff = -1;
      }

      // convert 10 thousand to 5 thousand
      if (diff != 0 && numTenThousand > 0) {
        numTenThousand = numTenThousand - 1;
        numFiveThousand = numFiveThousand + 2;
        diff = n - (numTenThousand + numFiveThousand + numOneThousand);
      } else if (diff % 2 == 0 && numTenThousand <= 0) {
        diff = -1; 
        cout << "C -1 -1 -1 " << endl;
      }
    }
  }
  if (diff < 0) {
    cout << "-1 -1 -1" << endl;
  } else {
    cout << "x:" << numTenThousand << ", y:" << numFiveThousand << ", z:" << numOneThousand << "\n";
  }*/
  for (int x = 0; x <= n; ++x) {
    for (int y = 0; y <= n; ++y) {
      int z = n - x - y;
      //cout << x << " " << y << " " << z << endl;
      if ((x + y + z == n) && ((10000 * x) + (5000 * y) + (1000 * z) == amount)
          && (x >= 0) && (y >= 0) && (z >= 0)) {
        // solution found
        //cout << 10000*x + 5000*y + 1000*z << endl;
        cout << x << " " << y << " " << z << endl;
        return 0;
      }
    }
  }
  cout << "-1 -1 -1" << endl;
  return 0;
}




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

int main(){
    int n, k;
    cin >> n >> k;
    int i, j, man, p=0;
    int kashi[k];
    int flag[n];
    int hako[10000];
    int sum=0;
    for(i=0;i<n;i++){
        flag[i] = 0;
    }
    for(i=0;i<k;i++){
        cin >> kashi[i];
        for(j=0;j<kashi[i];j++){
            cin >> hako[p];
            flag[hako[p]-1] = 1;
            p++;
        }
    }

    for(i=0;i<n;i++){
        if(flag[i] == 0){
            sum++;
        }
    }

    cout << sum << endl;

    return 0;
}


Measured memory_bytes: 3604
#include <iostream>
#include <stdio.h>
#include <string>
#include <math.h>
#include <algorithm>
using namespace std;
int main(){
	int W[31], w, n, a, b;
	int i, j, temp;
	char x;

	cin >> w >> n;
	for(i = 1;i < w+1;i++){
		W[i] = i;
	}
	while(n != 0){
		if(n == 0) break;
		cin >> a >> x >>  b;
		temp = W[a];
		W[a] = W[b];
		W[b] = temp;
 		n--;
	}
	for(i = 1;i < w+1;i++){
		cout << W[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
int n,a[100010];
int vi[100010][2],max1=0,max2=0,m1,m2,num1,num2,maxx1,maxx2;
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
		if(i%2)vi[a[i]][0]++;
		else vi[a[i]][1]++;	
	}
	for(int i=1;i<=100000;i++){
		if(max1<vi[i][0]){
			max1=vi[i][0];
			num1=i;
		}
		if(max2<vi[i][1]){
			max2=vi[i][1];
			num2=i;
		}	
	}
	if(num1!=num2){
		m1=n/2+(n%2);
		m2=n-m1;
		cout<<m1-max1+m2-max2<<endl;	
	}
	else {
		for(int i=1;i<=100000;i++){
			if(maxx1<vi[i][0]&&i!=num1){
			maxx1=vi[i][0];
			}
			if(maxx2<vi[i][1]&&i!=num2){
				maxx2=vi[i][1];
			}	
		}
		m1=n/2+(n%2);
		m2=n-m1;
		cout<<min(m1-max1+m2-maxx2,m2-max2+m1-maxx1)<<endl;
	}
	return 0;
}

Measured memory_bytes: 1408
fun main() {
    val (n, m, x) = readLine()!!.split(" ").map { it.toInt() }
    val a = Array(n) { IntArray(m + 1) }
    for (i in 0 until n) {
        readLine()!!.split(" ").map { it.toInt() }.let {
            a[i] = it.toIntArray()
        }
    }

    var min = Int.MAX_VALUE / 10
    for (i in 0..(1 shl n)) {
        val b = IntArray(m+1)
        for (j in 0 until n) {
            if (i.shr(j).and(1) == 1) {
                for (k in 0..m) {
                    b[k] += a[j][k]
                }
            }
        }
        if((1..m).map { b[it] >= x }.all { it }){
            min = Math.min(min, b[0])
        }
    }
    if(min == Int.MAX_VALUE / 10) println(-1) else println(min)
}

Measured memory_bytes: 40212
#include <bits/stdc++.h>
using namespace std;
int N, A[3][3], b[10];
bool appear[3][3];
int main() {
  for(int i = 0; i < 3; i++){
    for(int j = 0; j < 3; j++){
      cin >> A[i][j];
    }
  }
  cin >> N;
  for(int i = 0; i < N; i++) cin >> b[i];
  for(int i = 0; i < 3; i++){
    for(int j = 0; j < 3; j++){
      appear[i][j] = false;
      for(int k = 0; k < N; k++){
        if(A[i][j] == b[k])appear[i][j] = true;
      }
    }
  }
  string ANS = "No";
  for(int i = 0; i < 3; i++){
    if(appear[i][0] and appear[i][1] and appear[i][2]) ANS = "Yes";
  }
  for(int i = 0; i < 3; i++){
    if(appear[0][i] and appear[1][i] and appear[2][i]) ANS = "Yes";
  }
  if(appear[0][0] and appear[1][1] and appear[2][2]) ANS = "Yes";
  if(appear[0][2] and appear[1][1] and appear[2][0]) ANS = "Yes";
  cout << ANS << endl;
  return 0;
}

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

using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  int n;
  cin >> n;

  int min = INT_MAX;
  int max = -INT_MIN;
  for (int i = 0; i < n; ++i) {
    int a;
    cin >> a;
    max = std::max(a, max);
    min = std::min(a, min);
  }
  cout << (max - min) << "\n";
}


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

int main() {
  int N,M;
  cin >> N >> M;
  vector<int> vec(M);
  for (int i = 0; i<N; i++) {
    int k;
    cin >> k;
    for (int j = 0; j < k; j++) {
      int a;
      cin >> a;
      vec.at(a-1)++;
    }
  }
  
  int ans = 0;
  for (int i = 0; i < M; i++) {
    if (vec.at(i) == N) ans++;
  }
  cout << ans << endl;
  
  
  
}

Measured memory_bytes: 256