akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <utility>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
using namespace std;
#define INF 1000000007
#define LINF 1000000000000000007
#define MOD 1000000007
#define int long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define repb(i, n) for (int i = n - 1; i >= 0; i--)
#define MODE 1
#ifdef MODE
#define DEB(X) cout << #X << ": " << X << " ";
#define ARDEB(i, X) cout << #X << "[" << i << "]: " << X[i] << " ";
#define END cout << endl;
#else
#define DEB(X) \
    {          \
    }
#define ARDEB(i, X) \
    {               \
    }
#define END \
    {       \
    }
#endif
typedef pair<int, int> P;
struct edge{int to,cost;};
typedef long long ll;

int n;
vector<edge> G[111111];
int d[111111];
void dijkstra(int s){
    priority_queue<P,vector<P>,greater<P>> que;
    fill(d,d+n,LINF);
    d[s]=0;
    que.push(P(0,s));
    while(!que.empty()){
        P p=que.top();
        que.pop();
        int i=p.second;
        if(d[i]<p.first)continue;
        for(int j=0;j<(signed)G[i].size();j++){
            edge e=G[i][j];
            if(d[e.to]>d[i]+e.cost){
                d[e.to]=d[i]+e.cost;
                que.push(P(d[e.to],e.to));
            }
        }
    }
}

signed main()
{
    cin>>n;
    int a,b,c;
    rep(i,n-1){
        cin>>a>>b>>c;
        edge e;
        e.to=b-1,e.cost=c;
        G[a-1].push_back(e);
        e.to=a-1;
        G[b-1].push_back(e);
    }
    dijkstra(0);
    for(int i=0;i<n;i++){
        if(d[i]%2==0)cout<<0<<endl;
        else cout<<1<<endl;
    }
}


Measured memory_bytes: 8960
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false);cin.tie(NULL)
using namespace std;
#define int long long
#define MOD 1000000007
typedef vector<int> vi;
typedef pair<int,int> pi;
#define inf 1e18
#define For(i,a,b) for (int i = a; i < b; i++)
#define Rep(i,a,b) for (int i = a; i <= b; i++)
#define ps(x,y) fixed << setprecision(y) << x 
#define pb push_back 
#define mp make_pair 

int a[1005], b[1005], c[1005];
vi ans;
 
int32_t main()
{
    fast;
    int x, y, z, k; cin >> x >> y >> z >> k;
    For(i, 0, x) cin >> a[i];
    For(i, 0, y) cin >> b[i];
    For(i, 0, z) cin >> c[i];

    sort(a, a+x, greater<int>());
    sort(b, b+y, greater<int>());
    sort(c, c+z, greater<int>());

    For(i, 0, x) {
        For(j, 0, y) {
            For(m, 0, z) {
                if((i+1) * (j+1) * (m+1) <= k) ans.pb(a[i] + b[j] + c[m]);
                else break;
            }
        }
    }

    sort(ans.begin(), ans.end(), greater<int> ());
    For(i, 0, k) cout << ans[i] << "\n";
    
    return 0;
}

Measured memory_bytes: 4272
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

P pointRotate(P p) {
    int nx = p.first * 0 + p.second * (-1);
    int ny = p.first * 1 + p.second * 0;

    return mp(nx,ny);
}

P pointShift(P p,int x,int y) {
    return mp(p.first + x,p.second + y);
}

bool pointSame(vector<P> s,vector<P> t) {
    if(s.size() != t.size()) return false;

    bool flag = true;
    rep(i,s.size()) {
        if(s[i].first != t[i].first || s[i].second != t[i].second) {
            flag = false;
        }
    }

    return flag;
}

bool same(vector<P> s,vector<P> t) {
    if(s.size() != t.size()) return false;

    bool flag = false;
    rep(i,4) {
        vector<P> v,v2;

        rep(j,s.size()) {
            P temp = s[j];
            rep(k,i) {
                temp = pointRotate(temp);
            }

            v.push_back(temp);
            v2.push_back(temp);
        }

        int nx = t[0].first - v[0].first;
        int ny = t[0].second - v[0].second;

        rep(j,v.size()) {
            v[j] = pointShift(v[j],nx,ny);
        }

        if(pointSame(v,t)) {
            flag = true;
        }

        reverse(v2.begin(),v2.end());

        nx = t[0].first - v2[0].first;
        ny = t[0].second - v2[0].second;

        rep(j,v2.size()) {
            v2[j] = pointShift(v2[j],nx,ny);
        }

        if(pointSame(v2,t)) {
            flag = true;
        }
    }

    return flag;
}

int main()
{
    int n;
    while(cin >> n && n) {
        
        vector<P> v;
        int m;
        cin >> m;

        rep(i,m) {
            int x,y;
            cin >> x >> y;

            v.push_back(mp(x,y));
        }

        vector< vector<P> > p(n);
        rep(i,n) {
            cin >> m;

            rep(j,m) {
                int x,y;
                cin >> x >> y;

                p[i].push_back(mp(x,y));
            }
        }

        bool flag = true;
        vector<int> ans;
        rep(i,n) {
            if(same(v,p[i])) {
                flag = false;
                ans.push_back(i);
            }
        }

        if(!flag) rep(i,ans.size()) cout << ans[i]+1 << endl;
        cout << "+++++" << endl;
    }

    return 0;
}

Measured memory_bytes: 1232
#include <bits/stdc++.h>
using namespace std;
int main(){
    string S;
    //string = vector<cahr> 
    cin >> S;
    reverse(S.begin(),S.end());
    int N = S.size();
    string t[4];
    t[0] = "maerd";
    t[1] = "re" + t[0];
    t[2] = "esare";
    t[3] = "r" + t[2];
    bool judge = true;
    for(int i = 0;i < N;){
        if(S[i] == 'm'){
            if(S.substr(i,5) == t[0]){
                i += 5;
            }
            else{
                judge = false;
                break;
            }
        }else if(S[i] == 'e'){
            if(S.substr(i,5) == t[2]){
                i += 5;
            }
            else {
                judge = false;
                break;
            }
        }else if(S.substr(i,3) == "res"){
            if(S.substr(i,6) == t[3]){
                i += 6;
            }
            else {
                judge = false;
                break;
            }
        }else if(S.substr(i,3) == "rem"){
            if(S.substr(i,7) == t[1]){
                i += 7;
            }
            else {
                judge = false;
                break;
            }
        }else{
            judge = false;
            break;
        }
    }
    if(judge)cout << "YES" << endl;
    else cout << "NO" << endl;
    //cin >> S;
}

Measured memory_bytes: 512
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn=100,inf=0x3f3f3f3f;
int n,a[maxn],b[maxn],c[maxn],ok=0;
bool dfs(int x,int y,int t){
	if(t==11) {
		ok=1;
	}
	if(a[t]>b[x-1]){
		b[x]=a[t];
		dfs(x+1,y,t+1);
	}
	if(a[t]>c[y-1]){
		c[y]=a[t];
		dfs(x,y+1,t+1);
	}

}
int main()
{
	//freopen("read.txt", "r", stdin);
	cin>>n;
	while(n--){
		for(int i=1;i<=10;i++)cin>>a[i];
		ok=0;
		dfs(1,1,1);
		if(ok==1)cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}
	//fclose(stdin);
	return 0;
}

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

typedef pair<int, int> P;
typedef pair<P, int> Q;

int main() {

	int n, c;

	cin >> n >> c;

	vector<Q> dd(n);

	for (int i = 0; i < n; i++) {
		int s, t, cc;
		cin >> s >> t >> cc;
		dd[i] = Q(P(s, t), cc);
	}

	sort(dd.begin(), dd.end());

	vector<P> v;
	v.push_back(P(0, 0));
	for (int i = 0; i < n; i++) {
		bool h = true;
		for (int j = 0; j < v.size(); j++) {
			if (v[j].second == dd[i].second) {
				if (v[j].first <= (dd[i].first).first) {
					v[j].first = (dd[i].first).second;
					h = false;
					break;
				}
			}
			else {
				if (v[j].first <= (dd[i].first).first - 1) {
					v[j].first = (dd[i].first).second;
					v[j].second = dd[i].second;
					h = false;
					break;
				}
			}
		}
		if (h) {
			v.push_back(P((dd[i].first).second, dd[i].second));
		}
		sort(v.begin(), v.end());
	}

	cout << v.size() << endl;

	return 0;
}

Measured memory_bytes: 1408
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<random>
#include<set>
#include<map>
#include<functional>
using namespace std;
#define int long long
#define inf 1145141919
#define mod 1000000007
#define rep(i,n) for(int i=0;i<n;i++)
typedef pair<int, int>P;
typedef pair<int, P> PP;
struct edge { int to, cost; };

signed main() {
	int n; cin >> n;
	if (n == 3) {
		puts("2 5 63");
	}
	else if (n == 4) {
		puts("2 5 20 63");
	}
	else {
		int a = 1, b = 2, c = 1, d = 0;
		for (int i = 5; i <= n; i++) {
			if (i % 8 == 5)d++;
			else if (i % 8 == 6)d++;
			else if (i % 8 == 7) {
				a++; c++; d--;
			}
			else if (i % 8 == 0)d++;
			else if (i % 8 == 1)d++;
			else if (i % 8 == 2) {
				a++; c++; d--;
			}
			else if (i % 8 == 3)d++;
			else {
				b += 2;
				d--;
			}
		}
		rep(i, a) {
			if (i)cout << ' ';
			cout << 6 * i + 2;
		}
		rep(i, b)cout << ' ' << 6 * i + 3;
		rep(i, c)cout << ' ' << 6 * i + 4;
		rep(i, d)cout << ' ' << 6 * i + 6;
		cout << endl;
	}
}

Measured memory_bytes: 384
#include <stdio.h>
#include <string.h>

int main () {
  unsigned int size = 0, counter = 1;
  scanf("%d", &size);

  char str[size];
  scanf("%s", str);

  int length = strlen(str);

  for (int i = 0; i < length-1; i++) {
    if (str[i] != str[i+1]) {
      counter++;
    }
  }

  printf("%d", counter);
}


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

int main() {
	lli a, b, c, ans=0;
  cin >> a;
  for(lli i=1; i<=a; i++)
  {
    cin >> b;
    if(i%2==1 and b%2==1) ans++;
  }
  cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3540
def chess(H,W):
  if(H+W) % 2 == 0:
    return '#'
  return '.'

while True:
  H , W = map(int, input().split())
  if H == 0 and W == 0:
    break
  for i in range(H):
    for j in range(W):
      print(chess(i,j), end='')
    print()
  print()


Measured memory_bytes: 7008
#pragma GCC optimize("Ofast",3,"inline")
#include<bits/stdc++.h>
using namespace std;
#define fir first
#define sec second
#define m_p make_pair
#define y1 ygftgfgcdtfgxffgx
#define y2 yfdsesgvtyghftfvv
#define x1 xvyr6cf6fgcfgf676
#define x2 xcr6rfc5r66y6r6fr
#define up_bound upper_bound
#define low_bound lower_bound
#define next_per next_permutation
#define pb push_back
#define i_to_s to_string
typedef priority_queue<int> p_queue;
typedef priority_queue<int, vector<int>, greater<int> > min_p_queue;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
int mon[20]={31,28,31,30,31,30,31,31,30,31,30,31};
ll gcd(ll x,ll y){return ((y==0)?x:gcd(y,x%y));}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	char c;
	cin>>c;
	if(c>='a')cout<<'a';
	else cout<<'A';
	return 0;
}



Measured memory_bytes: 3608
#include<bits/stdc++.h>
#define int long long int
#define pll pair<ll,ll>
#define un unsigned
#define dbl long double
#define ff first
#define ss second
#define endl "\n"
#define mod 1000000009
#define eps 0.0000000001
#define inf 10000000000001
#define all(x) (x).begin(),(x).end()
#define size(x) (int)(x).size()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define vv(dt) vector<vector<dt>>
#define fastio(x) ios_base::sync_with_stdio(x); cin.tie(NULL)
#define debug(x) cerr<<"LINE: "<<__LINE__<<" || "<<#x<<" = "<<x<<endl
#define loop(i,s,n) for(auto i=s;i<n;i++)
#define rloop(i,n,b) for(auto i=n-1;i>=b;i--)
using namespace std;

int a[3001],dp[3001][3001];

int f(int l,int r)
{
	if(l==r) return a[l];
	if(dp[l][r]!=-1) return dp[l][r];
	dp[l][r] = max(a[l] - f(l+1,r), a[r] - f(l,r-1));
	return dp[l][r];
}

signed main()
{
	fastio(0);
	int n;
	cin>>n;
	loop(i,0,n) cin>>a[i];
	memset(dp,-1,sizeof(dp));
	cout<<f(0,n-1)<<endl;
	return 0;
}

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

int main() {
  int n, a = 0;
  cin >> n;

  for (int i = 1; i < n + 1; i++) {
    a = i;
    if (a % 3 == 0) {
      cout << " " << i;
    } else {
      while (a) {
        if (a % 10 == 3) {
          cout << " " << i;
          break;
        }
        a /= 10;
      }
    }
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 3080
#include<bits/stdc++.h>
#define REP(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
const ll MOD = 1000000007;

int main() {
  int a, b, c, d, s = 0;
  cin >> a >> b >> c >> d;
  REP(i, 101) {
    if (a <= i && i < b && c <= i && i < d) s++;
  }
  cout << s << endl;
  return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = 0
for i in range(n):
  c += min(a[i]+a[i+1],b[i])
  a[i+1] -= min(max(b[i]-a[i],0),a[i+1])
print(c)

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


int main() {
  double W, H, x, y;
  cin >> W >> H >> x >> y;
  int mult = ((W/2==x) && (H/2==y) ? 1 : 0);
  cout << W*H/2 << " " << mult << endl;
  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define inc(i,a,b) for(register int i=a;i<=b;i++)
using namespace std;
int head[10010],cnt;
class littlestar{
	public:
	int to,nxt;
	void add(int u,int v){
		to=v; nxt=head[u];
		head[u]=cnt;
	}
}star[200010];
const int p=1e9+7;
long long n,siz[20010],f[5010][5010],g[5010],tmp[10010];
void dp(int u,int fa){
	siz[u]=1; f[u][1]=1;
	for(int i=head[u];i;i=star[i].nxt){
		int v=star[i].to;
		if(v==fa) continue;
		dp(v,u);
		inc(j,1,siz[u]+siz[v]) tmp[j]=0;
		inc(j,1,siz[u]){
			inc(k,0,siz[v]){
				tmp[j+k]=(tmp[j+k]+f[u][j]*f[v][k]%p)%p;
			}
		}
		siz[u]+=siz[v];
		inc(j,1,siz[u]) f[u][j]=tmp[j];
	}
	for(int i=2;i<=siz[u];i+=2){
		f[u][0]=(f[u][0]-f[u][i]*g[i]%p%p+p)%p;
	}
}
int main(){
	cin>>n;
	inc(i,1,n-1){
		int x,y;
		scanf("%d%d",&x,&y);
		star[++cnt].add(x,y);
		star[++cnt].add(y,x);
	}
	g[0]=1;
	for(long long i=2;i<=n;i+=2) g[i]=g[i-2]*(i-1)%p;
	dp(1,0);
	cout<<p-f[1][0];
}

Measured memory_bytes: 92380
import scala.io.StdIn._
import scala.annotation.tailrec

object Main {

  final case class Rotation(run: Dice => Dice){
    final def apply(d: Dice): Dice = run(d)
    final def compose(other: Rotation): Rotation = Rotation(run compose other.run)
    final def andThen(other: Rotation): Rotation = other compose this
  }

  object Rotation {
    final def id = Rotation(d => d)
    final def north = Rotation(d => Dice(List(1,5,2,3,0,4).map(d.pip)))
    final def east = Rotation(d => Dice(List(3,1,0,5,4,2).map(d.pip)))
    final def ccw = Rotation(d => Dice(List(0,3,1,4,2,5).map(d.pip)))

    final def axial(rotation: Rotation): Seq[Rotation] =
      for(i <- 0 to 3) yield List.fill(i)(rotation).fold(id)(_ compose _)

    def enumerateTop(): Seq[Rotation] =
      for(i <- 1 to 6) yield ((0 to i).map(j => if(j % 2 == 0) north else east)).fold(id)(_ compose _)

    def enumerate: Seq[Rotation] = enumerateTop().flatMap(e => axial(ccw).map(e compose _))
  }

  case class Dice(pip: List[Int]){
    lazy val all: Seq[Dice] = Rotation.enumerate.map(_.run(Dice(pip)))
    def ===(that: Dice): Boolean = pip.corresponds(that.pip)(_ == _)
    def ==(that: Dice): Boolean = all.exists(_ === that)
  }

  def main(args: Array[String]): Unit = {
    val pip = readLine.split(" ").map(_.toInt).toList
    val all: Seq[Dice] = Rotation.enumerate.map(_.run(Dice(pip)))
    val Array(n,_*) = readLine.split(" ").map(_.toInt)

    for(i <- 1 to n){
      val Array(a,b,_*) = readLine.split(" ").map(_.toInt)
      println(all.filter(d => d.pip(0)==a && d.pip(1)==b)(0).pip(2))
    }
  }

}

Measured memory_bytes: 44520
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define LLINF 9223372036854775807
#define MOD ll(1e9+7)

int main(){
    ll a,b,c;
    cin >> a >> b >> c;
    if(a+b>=c-1){
        cout << b+c<<endl;
    }else{
        cout << a+b+1+b << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define N 100009
int a[N], b[N], c[N], dp[N][4];

int main()
{
    int n;
    cin >> n;
    for(int i = 1; i <= n; i++)
    {
        cin >> a[i] >> b[i] >> c[i];
        dp[i][1] = max(dp[i - 1][2], dp[i - 1][3]) + a[i];
        dp[i][2] = max(dp[i - 1][1], dp[i - 1][3]) + b[i];
        dp[i][3] = max(dp[i - 1][2], dp[i - 1][1]) + c[i];
    }
    cout << max({dp[n][1], dp[n][2], dp[n][3]}) << endl;
}




Measured memory_bytes: 2944
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define deb(x) cout << #x << " = "<< x << "\n";

signed main() {
	//freopen("in.txt", "r",stdin);
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	
	int n; cin >> n;
	map<string, int> m;
	while(n--) {
	    string s; cin >> s;
	    m[s]++;
	}
	cout << "AC x "<<m["AC"] << "\n";
	cout << "WA x "<<m["WA"] << "\n";
	cout << "TLE x "<<m["TLE"] << "\n";
	cout << "RE x "<<m["RE"] << "\n";
}


Measured memory_bytes: 3652
N = int(input())
if N <= 9:
    A = N
elif N <= 99:
    A = 9
elif N <= 999:
    A = N - 90
elif N <= 9999:
    A = 909
elif N <= 99999:
    A = N - 9090
else:
    A = 90909
print(A)

Measured memory_bytes: 2940
#include<stdio.h>
int ta[100010],nt[200010],to[200010],co[200010];
void mkls(int v,int e,int *a,int *b){
  int i;
  for(i=0;i<v;i++)ta[i]=-1;
  for(i=0;i<e;i++){
    nt[i  ]=ta[to[i+e]=a[i]];
    nt[i+e]=ta[to[i  ]=b[i]];
    ta[b[i]]=i+e;
    ta[a[i]]=i;
  }
}
void f(int v,int *c,int s){
  int i,q[100010],t=0,r;
  for(i=0;i<v;i++)c[i]=0;
  c[q[t=0]=s]=1;
  for(r=1;r-t;t++){
    for(i=ta[q[t]];i+1;i=nt[i]){
      if(c[to[i]]>0)continue;
      c[q[r++]=to[i]]=c[q[t]]+1;
    }
  }
}
int main(){
  int n,s,t,m=0,i,c[100010],d[100010],a[100010],b[100010];
  scanf("%d %d %d",&n,&s,&t);
  for(i=0;i<n-1;i++){
    scanf("%d %d",&a[i],&b[i]);
    a[i]--;
    b[i]--;
  }
  mkls(n,n-1,a,b);
  f(n,c,s-1);
  f(n,d,t-1);
  //for(i=0;i<n;i++)printf("%d %d %d\n",i+1,c[i],d[i]);
  for(i=0;i<n;i++){
    if(c[i]>d[i])continue;
    if(m<d[i])m=d[i];
  }
  printf("%d\n",m-2);
  return 0;
}


Measured memory_bytes: 4096
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
#include<set>
#include<algorithm>
#include<utility>
#include<map>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
const int INF = 1001001001;

ll pow_mod(ll p, ll n, ll m) {
	if (n == 0) return 1;
	else if (n == 1) return p % m;
	else if (n % 2 == 1) return p * pow_mod(p, n - 1, m) % m;
	else {
		ll tmp = pow_mod(p, n / 2, m);
		return (tmp * tmp) % m;
	}
}

ll gcd(ll x, ll y) {
	if (y == 0) {
		return x;
	}
	return gcd(y, x % y);
}

ll com_mod(ll n, ll k, ll m) {
	if (k == 0) return 1;
	else {
		ll x = 1;
		ll y = 1;
		for (ll i = 0; i < k; i++) {
			x = (x * (n - i)) % m;
			y = (y * (i + 1)) % m;
		}
		ll res = (x * pow_mod(y, m - 2, m)) % m;
		return res;
	}
}

int main() {
	int a, b, c; cin >> a >> b >> c;
	if (a + b >= c)cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main()
{
	int n, k;
	string s = "afjawe";
	cin >> n >> k >> s;

	int ans = 0;
	for (int i = 1; i < n; i++) {
		if (s[i] == s[i - 1]) {
			ans++;
		}
	}
	cout << min(ans + 2 * k, n - 1) << endl;

	return 0;
}

Measured memory_bytes: 512
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

// c++11
#include <array>
#include <tuple>
#include <unordered_map>
#include <unordered_set>

#define mp make_pair
#define mt make_tuple
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;

using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
template <class T>
using max_priority_queue = priority_queue<T>;
template <class T>
using min_priority_queue = priority_queue<T, std::vector<T>, std::greater<T>>;

const int INF = 1 << 29;
const ll LL_INF = 1LL << 60;
const double EPS = 1e-9;
const ll MOD = 1000000007;

const int dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1};
ll L;
const int MAX_N = 20;
vector<pii> edges[MAX_N];
int pow2[MAX_N + 10];
int get_pow2_idx(int L)
{
  if (L == 1)
  {
    return 0;
  }
  int idx = 0;
  int p = 1;
  while (p <= L)
  {
    idx++;
    p *= 2;
  }
  return idx - 1;
}
void init()
{
  pow2[0] = 1;
  for (int i = 1; i < MAX_N + 5; i++)
  {
    pow2[i] = 2 * pow2[i - 1];
  }
}

int main()
{
  init();
  cin >> L;
  for (int i = 0; i < MAX_N - 1; i++)
  {
    edges[i].push_back(mp(i + 1, 0));
  }
  int p = 1;
  ll tmp_L = L - 1;
  int base = 0;
  for (int i = MAX_N - 1; i >= 1; i--)
  {
    if (tmp_L - p < 0)
    {
      break;
    }
    tmp_L -= p;
    edges[i - 1].push_back(mp(i, p));
    base += p;
    p *= 2;
  }
  while (tmp_L > 0)
  {

    int sum = 1;
    int idx = 0;
    for (int i = 1; i < MAX_N; i++)
    {
      if (2 * sum > tmp_L)
      {
        break;
      }
      sum *= 2;
      idx = i;
    }
    cerr << "tmp_L = " << tmp_L << " base = " << base << " idx = " << idx << " sum = " << sum << endl;
    edges[0].push_back(mp(MAX_N - 1 - idx, base + 1));
    tmp_L -= sum;
    base += sum;
  }
  int M = 0;
  for (int i = 0; i < MAX_N; i++)
  {
    M += edges[i].size();
  }
  cout << MAX_N << " " << M << endl;
  for (int i = 0; i < MAX_N; i++)
  {
    for (int j = 0; j < edges[i].size(); j++)
    {
      cout << i + 1 << " " << edges[i][j].first + 1 << " " << edges[i][j].second << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 256
class Unionfind
  attr_accessor(:par, :size)

  def initialize(n)
    @par = Array.new(n+1)
    (n+1).times do |i|
      @par[i] = i
    end
    @size = Array.new(n+1,1)
  end

  def root(x)
    while @par[x] != x
      x = @par[@par[x]]
      @par[x] = @par[@par[x]]
    end
    x
  end

  def unite(x,y)
    rx = root(x)
    ry = root(y)
    if rx != ry
      @size[ry] += size(rx)
      @par[rx] = ry
    end
  end

  def same(x,y)
    return root(x)==root(y)
  end

  def size(x)
    if @par[x] == x
      @size[x]
    else
      size(root(par[x]))
    end
  end

end

n,m,k=gets.chomp.split(" ").map(&:to_i)
tree = Unionfind.new(n)
a = []
b = []
m.times do |i|
  a[i],b[i] = gets.chomp.split(" ").map(&:to_i)
  tree.unite(a[i],b[i])
end
c = []
d = []
k.times do |i|
  c[i],d[i] = gets.chomp.split(" ").map(&:to_i)
end

ans = Array.new(n)
n.times do |i|
  ans[i] = tree.size(i+1)
end

m.times do |i|
  ans[a[i]-1] -= 1
  ans[b[i]-1] -= 1
end

k.times do |i|
  if tree.same(c[i],d[i])
    ans[c[i]-1] -= 1
    ans[d[i]-1] -= 1
  end
end

n.times do |i|
  print "#{ans[i] - 1} "
end


Measured memory_bytes: 8156
#include <cstdio>
#include <algorithm>
 
using namespace std;
 
#define MAX_N 101
#define INF (1<<28)
 
int n, m, s, g1, g2;
int graph[MAX_N][MAX_N];
int main() {
    while (scanf("%d %d %d %d %d", &n, &m, &s, &g1, &g2), n || m || s || g1 || g2) {
        for (int i = 0; i <= n; i++) 
            for (int j = 0; j <= n; j++) {
                if (i == j) graph[i][j] = 0;
                else graph[i][j] = INF;
            }
        for (int i = 0; i < m; i++) {
            int b1, b2, c;
            scanf("%d %d %d", &b1, &b2, &c);
            graph[b1][b2] = c;
        }
        for (int k = 1; k <= n; k++) {
            for (int i = 1; i <= n; i++) {
                for (int j = 1; j <= n; j++) {
                    graph[i][j] = min(graph[i][j], graph[i][k] + graph[k][j]);
                }
            }
        }
 
        int min_cost = graph[s][g1] + graph[s][g2];
        for (int i = 1; i <= n; i++) { // 分岐する点
            min_cost = min(min_cost, graph[s][i] + graph[i][g1] + graph[i][g2]);
        }
        printf("%d\n", min_cost);
    }
    return 0;
}

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

int main(void)
{
  std::string s;
  std::cin >> s;

  std::vector<int> cnt(26);
  for (size_t i = 0; i < s.size(); i++) {
    cnt[s[i] - 'a']++;
  }

  bool flag = true;
  for (int i : cnt) {
    if (i & 0x01) {
      flag = false;
      break;
    }
  }

  if (flag) {
    std::cout << "Yes" << std::endl;
  }
  else {
    std::cout << "No" << std::endl;
  }
  
  return 0;
}

Measured memory_bytes: 3620
a=input()
p = int(input())
k = []
for i in range(len(a)):
    for j in range(i+1,min(i+6,len(a)+1)):
        k.append(a[i:j])
#(k)
k = set(k)
k = list(k)
k.sort()
#(k)
print(k[p-1])

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

int main() {
	int D, N ;
	cin >> N >> D;
	if (N % (D * 2 + 1) > 0) {
		cout << N / (D * 2 + 1)+1 << '\n';
	}
	else
	{
		cout << N / (D * 2 + 1) << '\n';
	}
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

int main() {
	int n;
	scanf("%d", &n);
	ll a[n], b[n];
	
	for (int i  = 0; i < n; i++) {
		scanf("%lld %lld", &a[i], &b[i]);
	}
	
	ll ans = 0;
	for (int i = n - 1; i >= 0; i--) {
		if ((a[i] + ans) % b[i] != 0) {
			ll add = (b[i] - ((a[i] + ans) % b[i]));
			ans += add;
		}
	}
	
	
	cout << ans << endl;

	
	return 0;
}

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




int main(){
  int n,i,a,b,j;
  char str[1000],str1[1000],**order;
  scanf("%s",str);
  scanf("%d",&n);
  order=malloc(n*sizeof(char *));
  for(i=0;i<n;i++){
    order[i]=malloc(7*sizeof(char));
    scanf(" %s",order[i]);
    if(order[i][0]=='r' && order[i][2]=='p'){
      scanf("%d %d",&a,&b);
      for(j=a;j<=b;j++) scanf(" %c",&str[j]);
    }
    if(order[i][0]=='r'  && order[i][2]=='v'){
      scanf("%d %d",&a,&b);
      for(j=a;j<=b;j++) str1[j]=str[j];
      for(j=a;j<=b;j++) str[j]=str1[a+b-j];
    }
    if(order[i][0]=='p'){
      scanf("%d %d",&a,&b);
      for(j=a;j<=b;j++) printf("%c",str[j]);
      printf("\n");
    }
    free(order[i]);
  }
  return 0;
}

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


int d[100001];

int main()
{
	

	int N;

	cin >> N;

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

	sort(d, d + N);

	int K = N / 2;

	cout << d[K] - d[K - 1] << endl;


}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define int long long
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using P=pair<long long,long long>;
#define rep(i,n) for(long long i=0; i<(long long)n; i++)
#define FOR(i,a,b) for(long long i=a; i<b; i++)
#define ll long long
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((long long)(x).size())
#define COUT(x) cout << x << endl
#define PB(x) push_back(x)
#define MP make_pair
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstr vector<string>
#define SUM(x) accumulate(x.begin(),x.end(),0)
#define MAX(x) *max_element(x.begin(),x.end())
#define MIN(x) *min_element(x.begin(),x.end())
#define couty cout<<'Y'<<'e'<<'s'<<endl
#define coutn cout<<'N'<<'o'<<endl
#define coutY cout<<'Y'<<'E'<<'S'<<endl
#define coutN cout<<'N'<<'O'<<endl
#define yn(x) cout<<(x?"Yes":"No")<<endl
#define YN(x) cout<<(x?"YES":"NO")<<endl
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
const long long dx[4]={1,0,-1,0};
const long long dy[4]={0,1,0,-1};
const long long INF = 1e12;
const long long MOD = 1e9+7;
//cout<<fixed<<setprecision(15)<<

signed main(){
    int n,k; cin >> n >> k;
    vector<P> p;
    rep(i,n){
        int a,b; cin >> a >> b;
        p.PB(P(a,b));
    }
    sort(all(p));
    int sum=0,res=0;
    rep(i,n){
        sum+=p[i].second;
        if(sum>=k){
            res=p[i].first;
            break;
        }
    }
    cout<<res<<endl;
}

Measured memory_bytes: 2420
#include <bits/stdc++.h>
#define REP(i, m, n) for(int (i) = (m); (i) < (n); ++i)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
using namespace std;
using Graph = vector<vector<int>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
typedef long long ll;
typedef pair<ll, ll> P;
const int INF = 1e9+7;
const ll LINF = 1LL<<60;

const int MAX_N = 200000;

int n, m;
vector<vector<P>> G;
int dist[MAX_N];

bool dfs(int v) {
    for (auto p : G[v]) {
        int nv = p.first;
        int nd = p.second;
        if (dist[nv] != INF) {
            if (dist[nv] != dist[v] + nd) return false;
        }
        else {
            dist[nv] = dist[v] + nd;
            if (!dfs(nv)) return false;
        }
    }
    return true;
}

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

    cin >> n >> m;
    G.resize(n);
    rep(i, m) {
        int l, r, d;
        cin >> l >> r >> d;
        --l, --r;
        G[l].push_back(make_pair(r, d));
        G[r].push_back(make_pair(l, -d));
    }

    rep(i, MAX_N) dist[i] = INF;

    bool ok = true;
    rep(i, n) {
        if (dist[i] != INF) continue;
        dist[i] = 0;
        if (!dfs(i)) ok = false;
    }

    if (ok) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 15616
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner scn=new Scanner(System.in);
		int n=scn.nextInt();
		int m =scn.nextInt();
		ArrayList<ArrayList<Integer>> al=new ArrayList<>();
		for(int i=0;i<n;i++){
			ArrayList<Integer>al1=new ArrayList<>();
			al.add(al1);
		}
		HashSet<String> hs =new HashSet<>();
		for(int i=0;i<m;i++){
			int val1= scn.nextInt();
			int val2 =scn.nextInt();
		     String s1=val1+"#"+val2;
		     String s2=val2+"#"+val1;
		     if(hs.contains(s1)|| hs.contains(s2)){
		    	 continue;
		     }
		     hs.add(s1);
		     al.get(val1-1).add(val2-1);
		     al.get(val2-1).add(val1-1);
		     
		}
		int max=0;
		HashSet<Integer>hs1=new HashSet<>();
		for(int i=0;i<n;i++){
			cnt=0;
		     dfs(i,al,hs1);
		     max=Math.max(cnt, max);
		}
		 System.out.println(max);

	}
	static int cnt=0;
	public static void dfs(int s, ArrayList<ArrayList<Integer>>al , HashSet<Integer> hs){
		if(hs.contains(s)){
			return ;
		}
		hs.add(s);
		cnt++;
		
		for(int val : al.get(s)){
			dfs(val,al,hs);
		}
	}

}

Measured memory_bytes: 185160
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
const ll INF=mod;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(x) (x).begin(),(x).end()
ll min(ll a,ll b){
  if(a>b){
    return b;
    }
      else{
        return a;
      }
  }
  
  ll max(ll a,ll b){
    if(a>b){
      return a;
    }
    else{
      return b;
    }
  }

ll power(ll a,ll b){
 ll ans=1;
 for(ll i=1;i<=b;i++){
ans*=a;
  }
  return ans;
}

 ll gcd(ll m,ll n){
 	if(n==0){
       return m;
     }
   return gcd(n,m%n);
 }
ll lcm(ll a,ll b){
  ll g=gcd(a,b);
  return a/gcd(a,b)*b;
		

}
vector<ll> x[1000];
vector<ll> y[1000];
int main(){
  
  ll N;
  cin>>N;
  
  vector<ll>A(N);
 
  ll ans=0;
  rep(i,N){
    cin>>A[i];
    rep(j,A[i]){
      ll a,b;
     cin>>a>>b;
      x[i].push_back(a);
      y[i].push_back(b);
      
    }
  }

  rep(i,power(2,N)){
    ll sum=0;
    bitset<15>b(i);
  string S=b.to_string();
    reverse(all(S));
   
    rep(k,N){
      ll sum2=0;
      if(S[k]=='1'){
    rep(j,A[k]){
      if(y[k][j]==S[x[k][j]-1]-'0'){
        sum2++;
      
      }
    }
if(sum2==A[k]){
  sum++;
}
   else{
sum-=INF;
   }

    }
    }
    ans=max(sum,ans);
  }

  cout<<ans<<endl;
  
}
    


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstring>
#include<map>
#include<queue>
#include<vector>
#include<set>
#include<sstream>
using namespace std;
typedef unsigned long long ll;
const ll maxn=1e6+10;
const ll inf=0x3f3f3f3f3f3f3f3f;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	ll n,m;
	cin>>n>>m;
	if(n==1||m==1)
	{
		cout<<1<<endl;
		return 0;
	}
	if((n*m)%2==0)
		cout<<(m*n)/2<<endl;
	else
		cout<<(m*n)/2+1<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A,B,C,D,Left,Right;
  cin >> A >> B >> C >> D;
  Left = A + B;
  Right = C + D;
 
  if (Left > Right) {
    cout << "Left" << endl;
	} else if (Left < Right) {
    cout << "Right" << endl;
	} else {
    cout << "Balanced" << endl;
  	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long 
#define inf 0x3f3f3f3f
#define infll 0x3f3f3f3f3f3f3f3f
#define all(x) (x).begin(),(x).end()
#define forn(i, a, b) for (int i=a; i<(signed)(b); ++i)
#define pb push_back
 
 
// debug templates 
#define debug(x)       cerr<< #x <<" : "<< x << endl;
#define debuga(A,N)    cerr<< #A <<" : [";for(int i = 0; i<N;i++) cerr<<A[i]<<" "; cerr<<"]\n";
#define debuga2(A,N,M) cerr<< #A << " : \n"; for(int i=0;i<N;i++){cerr<<"[";for(int j=0;j<M;++j) cerr<<A[i][j]<<" ";cerr<<"]\n";}
#define debugp(p)      cerr<< #p <<" : "<<"("<<(p).first<<","<<(p).second<<")\n";
#define debugv(v)      cerr<< #v <<" : "<<"[";for(int i = 0; i< (v).size(); i++) cerr<<v[i]<<" "; cerr<<"]\n";
#define debugv2(v)     cerr<< #v << " : \n"; for(int i=0;i<v.size();i++){cerr<<"[";for(int j=0;j<(v[0].size());++j) cerr<<v[i][j]<<" ";cerr<<"]\n";}
#define debugs(m)      cerr<< #m <<" : [ "; for(auto itr = m.begin(); itr!=m.end();itr++) cerr<<*itr<<" "; cerr<<"]\n";
#define debugm(m)      cerr<< #m <<" : [ "; for(auto itr = m.begin();itr!=m.end(); itr++) cerr<<"("<<itr->first<<","<<itr->second<<") ";cerr<<"]\n";
 

// 2b=y-2x, 2a+4b = y

void solve(){
	int x,y; cin >> x >> y;
	int b = y-2*x;
	bool can = 1;
	if(b&1) can = 0;
	else{
		b /= 2;
		int a = x - b;
		if(2*a + 4*b != y) can = 0;
		if(a<0 || b <0) can = 0;
	}
	cout << (can ? "Yes" : "No");
}
 
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	solve();
	return 0;
}
 


Measured memory_bytes: 3612
// Jump, and you will find out how to unfold your wings as you fall.

#include<bits/stdc++.h>

#define F first
#define S second
#define PB push_back
#define sz(s) int((s).size())
#define bit(n,k) (((n)>>(k))&1)

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const int maxn=1e5+10,mod=1e9+7;
const ll inf=1e18;

ll a[maxn],W[maxn],cnt[maxn];
vector<int>v[maxn];

void dfs1(int u,int par=-1){
    if(sz(v[u])==1) {W[u]=a[u]; return;}
    W[u]=2*a[u];
    for(int y:v[u]){
	if(y!=par){
	    dfs1(y,u);
	    W[u]-=W[y];
	}
    }
}
ll dfs2(int u,int par=-1){
    if(sz(v[u])==1) return -W[u];
    ll sm=0;
    for(int y:v[u]){
	if(y!=par){
	    sm+=dfs2(y,u);
	}
    }
    ll num=W[u]+sm;
    if(num>0 || num&1) cout<<"NO"<<endl,exit(0);
    cnt[u]=(-num)/2;
    return -W[u];
}
ll dfs3(int u,int par=-1){
    if(sz(v[u])==1) return W[u];
    ll check=cnt[u]*2,sum=0;
    for(int y:v[u]){
	if(y!=par){
	    ll num=dfs3(y,u);
	    sum+=num;
	    check-=min(num,cnt[u]);
	}
    }
    if(check>0) cout<<"NO"<<endl,exit(0);
    return sum-cnt[u]*2;
}

int main(){
    ios_base::sync_with_stdio(false);cin.tie(0);
    int n;cin>>n;
    for(int i=1;i<=n;i++){
	cin>>a[i];
    }
    for(int i=1;i<=n-1;i++){
	int a,b;cin>>a>>b;
	v[a].PB(b);
	v[b].PB(a);
    }
    if(n==2){
	return cout<<(a[1]==a[2]?"YES":"NO")<<endl,0;
    }
    int r=1;
    for(int i=1;i<=n;i++){
	if(sz(v[i])>1) r=i;
    }
    dfs1(r);
    if(W[r]!=0) return cout<<"NO"<<endl,0;
    dfs2(r);
    if(dfs3(r)!=0) return cout<<"NO"<<endl,0;
    return cout<<"YES"<<endl,0;
}
// Deathly mistakes:
//  * Read the problem curfully.
//  * Check maxn.
//  * Overflows.


Measured memory_bytes: 15232
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

using u128 = __uint128_t;

#define int long long
#define idxSet tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
#define atIdx find_by_order
#define idxOf order_of_key
#define MOD 1000000007
#define MAX 200005
#define endl '\n'

typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

int dp[MAX];

void solve() {
    int n ;
    cin>>n;
    int a[n] , b[n];
    for(int i = 0 ;i< n; i++)
        cin>>a[i]>>b[i];
    int f = 0 ;
    int sum = 0;
    for(int i = n-1 ; i>= 0 ; i--){
        if((a[i] + f) % b[i] != 0){
            int k = ( ((a[i] + f) / b[i]) + 1) * b[i] ;
            sum += k - (a[i] + f);
            f += k - (a[i] + f);
        }
    }
    cout<<sum<<endl;
}

int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t = 1;
    //cin>>t;
    while (t--)
        solve();
    return 0;
}

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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(ll i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
#define MAX_N 110

int N, M;
pair<int, int> students[MAX_N];
pair<int, int> points[MAX_N];

static inline int get_dist(pair<int, int> student, pair<int, int> point) {
    return abs(student.first - point.first) + abs(student.second - point.second);
}

signed main()
{
    cin >> N >> M;
    REP(i, N) {
        int a, b;
        cin >> a >> b;
        students[i] = make_pair(a, b);
    }
    REP(i, M) {
        int c, d;
        cin >> c >> d;
        points[i] = make_pair(c, d);
    }
    REP(i, N) {
        int cand_dist = get_dist(students[i], points[0]);
        int cand_ind = 1;
        REP(j, M) {
            int tmp = get_dist(students[i], points[j]);
            if(cand_dist > tmp) {
                cand_dist = tmp;
                cand_ind = j+1;
            }
        }
        printf("%lld\n", cand_ind);
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL_
void debug_out() {cerr << endl;}
template<typename Head,typename... Tail> void debug_out(Head H,Tail... T){cerr << ' ' << H; debug_out(T...);}
#define debug(...) cerr << 'L' << __LINE__ << " [" << #__VA_ARGS__ << "]:",debug_out(__VA_ARGS__)
#define dump(x) cerr << 'L' << __LINE__ << " " << #x << " = " << (x) << endl;
#else
#define debug(...) (void(0))
#define dump(x) (void(0))
#endif
#define rep(i,n) for (int i = 0; i < (int)(n); i ++)
#define irep(i,n) for (int i = (int)(n) - 1;i >= 0;--i)
using ll = long long;
using PL = pair<ll,ll>;
using P = pair<int,int>;
constexpr int INF = 1000000000;
constexpr long long HINF = 1000000000000000;
constexpr long long MOD = 1000000007;// = 998244353;
constexpr double EPS = 1e-4;
constexpr double PI = 3.14159265358979;

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

    string N; cin >> N;
    int cnt = 0;
    rep(i,4) cnt += (N[i] == '2');
    cout << cnt << '\n';
    return 0;
}

Measured memory_bytes: 3612
#include<cstdio>
int diff[200005];
int a[200005];

int min(int a,int b){ return a>b?b:a; }

int max(int a,int b){ return a>b?a:b; }

int main(){
	int n,k;
	scanf("%d%d",&n,&k);
	int minn = n+1;
	for(int i = 1; i <= n; i++){
		scanf("%d",&a[i]);
		minn = min(minn,a[i]);
	}
	for(int t = 0; t < k; t++){
		if(minn==n) break;
		else{
			for(int i = 1; i <= n+1; i++) diff[i] = 0;
			for(int i = 1; i <= n; i++){
				int l = max(1,i-a[i]), r = min(n,i+a[i]);
				diff[l]++, diff[r+1]--;
			}
			minn = n+1;
			int sum = 0;
			for(int i = 1; i <= n; i++){
				sum += diff[i];
				a[i] = sum;
				minn = min(minn,a[i]);
			}
		}
	}
	for(int i = 1; i <= n; i++) printf("%d ",a[i]);
	printf("\n");
	return 0;
}


Measured memory_bytes: 3260
#include <bits/stdc++.h>
#define err(args...) {}
#ifdef DEBUG
#include "_debug.cpp"
#endif
using namespace std;
using ll = long long;
using ld = long double;
template <typename T> using lim = numeric_limits<T>;
template <typename T> istream& operator>>(istream& is, vector<T>& a) { for(T& x : a) { is >> x; } return is; }
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    set<int> psquares;
    for(int i = 0; i <= 1000; i++) {
        psquares.insert(i * i);
    }
    int n, d;
    cin >> n >> d;
    vector<vector<int>> x(n, vector<int>(d));
    for(int i = 0; i < n; i++) {
        cin >> x[i];
    }
    int ans = 0;
    for(int i = 0; i < n; i++) {
        for(int j = i + 1; j < n; j++) {
            int sqdist = 0;
            for(int y = 0; y < d; y++) {
                int dy = x[i][y] - x[j][y];
                sqdist += dy * dy;
            }
            ans += psquares.count(sqdist);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int X, Y, prize = 0;
    cin >> X >> Y;
    if(X <= 3)
        prize += 100000*(3-X+1);
    if(Y <= 3)
        prize += 100000*(3-Y+1);
    if(X == 1 && Y ==1)
        prize += 400000;
        
    cout << prize << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[]) {
   int x,y;
   cin>>x>>y;
   if(x%3==0 || y%3==0 || (x+y)%3==0 )cout<<"Possible"<<endl;
   else cout<<"Impossible"<<endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static class restVal implements Comparable<restVal> {

		private String name;


		public String getName() {
			return name;
		}

		public void setName(String name) {
			this.name = name;
		}

		public int getTensu() {
			return tensu;
		}

		public void setTensu(int tensu) {
			this.tensu = tensu;
		}

		private int tensu;

		@Override
		public int compareTo(restVal rV) {

			int result = this.name.compareTo(rV.name);
			if (result == 0) {
				result = -Integer.valueOf(this.tensu).compareTo(Integer.valueOf(rV.tensu));
			}
			return result;

		}

	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();

		String s[] = new String[n];
		int p[] = new int[n];
		
		List<restVal> restVal = new ArrayList<>();
		for (int i = 0; i < n; i++) {
			s[i] = sc.next();
			p[i] = sc.nextInt();
			restVal a = new restVal();
			a.setName(s[i]);
			a.setTensu(p[i]);
			restVal.add(a);

		}
		Collections.sort(restVal);

		int anc[] = new int[n];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				if ((restVal.get(i).getName()+restVal.get(i).getTensu()).equals(s[j] + p[j])) {
					anc[i] = j+1;
					break;
				}
			}
		}
		for (int i = 0; i < n; i++) {
			System.out.println(anc[i]);
		}
	}

}


Measured memory_bytes: 21844
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N,num):
    if N<=0:
        return [[] for _ in range(num)]
    elif num==1:
        return [I() for _ in range(N)]
    else:
        read_all = [tuple(II()) for _ in range(N)]
        return map(list, zip(*read_all))

#################

from itertools import permutations

N = I()
P = tuple(III())
Q = tuple(III())

A = list(permutations(range(1,N+1)))

for i in range(len(A)):
    if A[i]==P:
        p = i
    if A[i]==Q:
        q = i

print(abs(p-q))

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

int main() {
  int N, M;
  cin >> N >> M;
  vector<long long> x(N), y(N), z(N);
  for (int i = 0; i < N; i++) {
    cin >> x[i] >> y[i] >> z[i];
  }

  int a[] = {1, -1, 1, -1, 1, -1, 1, -1};
  int b[] = {1, 1, -1, -1, 1, 1, -1, -1};
  int c[] = {1, 1, 1, 1, -1, -1, -1, -1};

  long long ans = LONG_LONG_MIN;
  for (int i = 0; i < 8; i++) {
    vector<long long> v(N);
    long long tmp = 0;
    for (int j = 0; j < N; j++) {
      v[j] = a[i] * x[j] + b[i] * y[j] + c[i] * z[j];
    }
    sort(v.begin(), v.end());
    reverse(v.begin(), v.end());
    tmp = 0;
    for (int j = 0; j < M; j++) {
      tmp += v[j];
    }
    if (ans < tmp)
      ans = tmp;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>

int main(void){
    
    int start, end, K;
    int i;
    scanf("%d %d %d",&start , &end, &K);

    if(end - start + 1 > 2*K){
        for(i = start; i < start + K; i++){
            printf("%d\n",i);
        }
        for(i = end - K + 1; i <= end; i++){
            printf("%d\n",i);
        }
    }else{
        for(i = start; i<end+1; i++) {
            printf("%d\n",i);
        }
    }

}

Measured memory_bytes: 128
#include<iostream>
#include<string>
using namespace std;
int main(){
  int y,m,d;
  char a,b;
  cin>>y>>a>>m>>b>>d;
  
  if(y>2019) cout<<"TBD"<<endl;
  else if(y==2019 && m>4)cout<<"TBD"<<endl;
  else cout<<"Heisei"<<endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
struct data{
    int ac,all_time,n;
    data(int a,int b,int c):ac(a),all_time(b),n(c){}
    data(){}
    bool operator<(const data &d)const{
        return ac<d.ac||(ac==d.ac&&(all_time>d.all_time||all_time==d.all_time&&n<d.n));
    }
};
int main(){
    int M,T,P,R;
    while(scanf("%d%d%d%d",&M,&T,&P,&R),M||T||P||R){
        int wa[50][10];
        vector<data>V(T);
        for(int i=0;i<T;i++)V[i]=data(0,0,i+1);
        fill_n(*wa,500,0);
        while(R--){
            int m,t,p,j;
            scanf("%d%d%d%d",&m,&t,&p,&j);
            if(j){
                t--;p--;
                wa[t][p]++;
            }
            else{
                t--;p--;
                V[t].ac++;
                V[t].all_time+=m+wa[t][p]*20;
            }
        }
        sort(V.begin(),V.end());
        reverse(V.begin(),V.end());
        printf("%d",V[0].n);
        for(int i=1;i<T;i++){
            if(V[i].ac==V[i-1].ac&&V[i].all_time==V[i-1].all_time){
                printf("=");
            }
            else{
                printf(",");
            }
            printf("%d",V[i].n);
        }
        puts("");
    }
}

Measured memory_bytes: 1056
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)

int main()
{
    int r, D, x;
    cin >> r >> D >> x;
    for (int i = 0; i < 10; i++)
    {
        x = r * x - D;
        cout << x << endl;
    }
}

Measured memory_bytes: 256