akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<algorithm>
using namespace std;
inline int read()
{
	int x;char c;
	while((c=getchar())<'0'||c>'9');
	for(x=c-'0';(c=getchar())>='0'&&c<='9';)x=x*10+c-'0';
	return x;
}
#define MN 100000
struct edge{int nx,t;}e[MN*2+5];
int h[MN+5],en,s[MN+5],d[MN+5],z[MN+5],q[MN+5],qn;
long long ans;
inline void ins(int x,int y)
{
	e[++en]=(edge){h[x],y};h[x]=en;
	e[++en]=(edge){h[y],x};h[y]=en;
}
void get(int x,int fa)
{
	z[d[x]=d[fa]+1]=x;
	for(int i=h[x];i;i=e[i].nx)if(e[i].t!=fa)
		if(d[e[i].t]){if(!qn)for(int j=d[e[i].t];j<=d[x];++j)q[++qn]=z[j];}
		else get(e[i].t,x);
}
inline int Z(int x){return x<0?-x:x;}
void dfs(int x,int fa)
{
	for(int i=h[x];i;i=e[i].nx)if(d[e[i].t]>=0&&e[i].t!=fa)s[e[i].t]=-s[x];
	for(int i=h[x];i;i=e[i].nx)if(d[e[i].t]>=0&&e[i].t!=fa)dfs(e[i].t,x),s[x]+=s[e[i].t];
	if(d[x]>=0)ans+=Z(s[x]);
}
int main()
{
	int n,m,i,x;
	n=read();m=read();
	for(i=1;i<=m;++i)ins(read(),read());
	if(m<n){dfs(s[1]=1,0);return 0*printf("%d",s[1]?-1:ans);}
	get(1,0);
	for(i=1;i<=qn;++i)d[q[i]]=-1;
	for(i=1;i<=qn;++i)s[q[i]]=i&1?1:-1,dfs(q[i],0);
	for(i=1;i<=qn;++i)d[i]=d[i-1]+s[q[i]];
	if(qn&1?d[qn]&1:d[qn])return 0*puts("-1");
	if(qn&1)x=d[qn]/2;else nth_element(d+1,d+qn/2,d+qn+1),x=d[qn/2];
	for(i=1;i<=qn;++i)ans+=Z(d[i]-x);
	printf("%lld",ans);
}

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

#define si(v) int(v.size())
#define all(v) v.begin(), v.end()
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep2(i, n, m) for (ll i = n; i <= (m); ++i)
#define rep3(i, n, m) for (ll i = n; i >= (m); --i)

template<class T, class U> void chmax(T &a, U b) { if (a < b) a = b; }
template<class T, class U> void chmin(T &a, U b) { if (b < a) a = b; }

using ll = long long;
using ld = long double;
using namespace std;

signed main()
{
  cout << fixed << setprecision(20);
  ios::sync_with_stdio(false);
  cin.tie(0);
  
  string s; cin >> s;
  set<char> se;

  rep(i, 3) se.emplace(s[i]);
  if (si(se) == 3) cout << "Yes\n";
  else cout << "No\n";
  
  return (0);
}

Measured memory_bytes: 3632
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main (void)
{
	long long X, K, D;
	cin >> X >> K >> D;

	if (X < 0)
		X *= -1;
		
	long long quotient = (long long) (X / D); //ガウス記号
	if (K <= quotient)
	{
		cout << (X - D*K) << endl;
		return 0;
	}
	
	long long candidate [2];
	
	candidate [0] = X % D;
	candidate [1] = D - candidate [0];
	
	if ((K - quotient) % 2 == 0)
	{
		cout << candidate [0] << endl;
		return 0;
	}

	cout << candidate [1] << endl;


	return 0;
}

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

int main(){
	int n,taro=0,hanako=0;
	string str1,str2;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>str1>>str2;
		if(str1>str2)taro+=3;
		else if(str1==str2){
			taro+=1;
			hanako+=1;
		}
		else hanako+=3;
	}
	cout<<taro<<" "<<hanako<<endl;
	
}



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

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

	if (abs(x - a) <= abs(x - b))
	{
		cout << "A" << endl;
	}
	else
	{
		cout << "B" << endl;
	}
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define SZ(x) ((int)x.size())
#define L(i,u) for (register int i=head[u]; i; i=nxt[i])
#define rep(i,a,b) for (register int i=(a); i<=(b); i++)
#define per(i,a,b) for (register int i=(a); i>=(b); i--)
using namespace std;
typedef long long ll;
typedef unsigned int ui;
typedef pair<int,int> Pii;
typedef vector<int> Vi;
inline void read(int &x) {
	x=0; char c=getchar(); int f=1;
	while (!isdigit(c)) {if (c=='-') f=-1; c=getchar();}
	while (isdigit(c)) {x=x*10+c-'0'; c=getchar();} x*=f;
}
inline ui R() {
	static ui seed=416;
	return seed^=seed>>5,seed^=seed<<17,seed^=seed>>13;
}
const int N = 333333;
int n,l,x[N],t[N];
ll res;bool a[N],b[N],vis[N];
int solve(){
	int q=0,l=0,r=0;
	rep(i,1,n-1)if(a[i]||b[i]){
		if(a[i]&&!b[i])l++,r++,q++;
		else if(!a[i]&&b[i]){
			if(!l&&r)l++,r--,q++;
			else if(l)l--,r--,q++;
		}
		else{
			if(!l)l++,r++,q++;
			else l--,r++,q++;
		}
	}
	q-=l;
	//rep(i,1,n-1)printf("%d:%d %d\n",i,a[i],b[i]);
	//printf("ans = %d\n",q);
	return q/2;
}
bool ck(int mid){
	Vi p,q;
	rep(i,1,n-1)if(a[i]&&SZ(p)<mid)p.pb(i);
	per(i,n-1,1)if(b[i]&&SZ(q)<mid)q.pb(i);reverse(q.begin(),q.end());
	if(SZ(p)<mid||SZ(q)<mid)return 0;
	rep(i,0,SZ(p)-1)if(p[i]>q[i])return 0;
	return 1;
}
void umax(int &x, int y){x=max(x,y);}
int main() {
	read(n);read(l);rep(i,1,n)read(x[i]);
	rep(i,1,n){
		read(t[i]),res+=t[i]/(l*2),t[i]%=l*2;
		if(!t[i])t[i]+=l*2,res--;
	}
	rep(i,1,n)a[i]=t[i]<=2*x[i];
	rep(i,1,n)b[i]=t[i]<=2*(l-x[i]);
	
	//1..n-1
	int q=solve();
	
	res-=q;
	res+=n+(!b[n]);
//	rep(i,1,n)printf("%d:%d %d\n",i,a[i],b[i]);
//	printf("%lld %d\n",res,q);
	
	cout<<2LL*l*res;
	return 0;
}


Measured memory_bytes: 3200
N = int(input())

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

vis = [False] * N
inf = 1e9
d = [inf] * N
d[0] = 0
cost = 0
for _ in range(N):
    nv, ni = inf, -1
    for i in range(N):
        if not vis[i] and d[i] < nv:
            nv, ni = d[i], i
    vis[ni] = True
    cost += nv
    for i in range(N):
        c = a[ni][i]
        if c > -1:
            d[i] = min(d[i], c)
print(cost)


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

// begin fast read template by CYJian (source: https://www.luogu.com.cn/paste/i11c3ppx)

namespace io {
	const int __SIZE = (1 << 21) + 1;
	char ibuf[__SIZE], *iS, *iT, obuf[__SIZE], *oS = obuf, *oT = oS + __SIZE - 1, __c, qu[55]; int __f, qr, _eof;
	#define Gc() (iS == iT ? (iT = (iS = ibuf) + fread (ibuf, 1, __SIZE, stdin), (iS == iT ? EOF : *iS ++)) : *iS ++)
	inline void flush () { fwrite (obuf, 1, oS - obuf, stdout), oS = obuf; }
	inline void gc (char &x) { x = Gc(); }
	inline void pc (char x) { *oS ++ = x; if (oS == oT) flush (); }
	inline void pstr (const char *s) { int __len = strlen(s); for (__f = 0; __f < __len; ++__f) pc (s[__f]); }
	inline void gstr (char *s) { for(__c = Gc(); __c < 32 || __c > 126 || __c == ' ';)  __c = Gc();
		for(; __c > 31 && __c < 127 && __c != ' '; ++s, __c = Gc()) *s = __c; *s = 0; }
	template <class I> inline bool gi (I &x) { _eof = 0;
		for (__f = 1, __c = Gc(); (__c < '0' || __c > '9') && !_eof; __c = Gc()) { if (__c == '-') __f = -1; _eof |= __c == EOF; }
		for (x = 0; __c <= '9' && __c >= '0' && !_eof; __c = Gc()) x = x * 10 + (__c & 15), _eof |= __c == EOF; x *= __f; return !_eof; }
	template <class I> inline void print (I x) { if (!x) pc ('0'); if (x < 0) pc ('-'), x = -x;
		while (x) qu[++ qr] = x % 10 + '0',  x /= 10; while (qr) pc (qu[qr --]); }
	struct Flusher_ {~Flusher_(){flush();}}io_flusher_;
} using io::pc; using io::gc; using io::pstr; using io::gstr; using io::gi; using io::print;

// end fast read template by CYJian

#define iter(i, a, b) for(int i=(a); i<(b); i++)
#define rep(i, a) iter(i, 0, a)
#define rep1(i, a) iter(i, 1, (a)+1)
#define log(a) cerr<<"\033[32m[DEBUG] "<<#a<<'='<<(a)<<" @ line "<<__LINE__<<"\033[0m"<<endl
#define all(a) a.begin(), a.end()
#define fi first
#define se second
#define pb push_back
#define mp make_pair
 
using ll=long long;
using pii=pair<int, int>;
//#define int ll
const int MOD = 1000000007;

bool st[100005];

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    int n, m; gi(n), gi(m);
	int l = 1, r = n;
	while(m--) {
		print(l); pc(' '); 
		if(n%2 == 0 && ((r - l) == n/2 || (r - l) == n/2-1)) r--;
		print(r);
		pc('\n');
		l++; r--;
	}
}


Measured memory_bytes: 4700
import scala.io.StdIn.readLine

object Main {

  def sum(n:Int, s:Int, x:Int):Int = {
    if(n*9<s|| (n-1)*n/2>s) 0
    else if(n==1) { if(s >= 0 && s<=9 && s > x ) 1 else 0 }
    else { for(i <- 0 to 9 if s>=i && i>x) yield sum(n-1,s-i,if(i>x) i else x) }.sum
  }

  def getSum(sb:StringBuilder):Unit = {
    val r = readLine.split(" ").map(_.toInt)

    if(r(0)==0 && r(1)==0)  print(sb.result)
    else {
      println(sum(r(0),r(1),-1))
      getSum(sb)
    }
  }

  def main(args:Array[String]) = getSum(new StringBuilder)
}

Measured memory_bytes: 45088
N = int(input())
S = input()
dp = [[0] * (N + 1) for _ in range(N + 1)]
for i in range(N - 1, -1, -1):
    for j in range(N - 1, -1, -1):
        if S[i] == S[j]:
            dp[i][j] = dp[i + 1][j + 1] + 1
result = 0
for i in range(N):
    for j in range(i + 1, N):
        t = dp[i][j]
        if t > j - i:
            t = j - i
        if t > result:
            result = t
print(result)


Measured memory_bytes: 229896
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define fore(b,c) for(int val0=b;val0<c;val0++)
#define forr(k,c,s) for(int k=c;k<s;k++)
#define pb push_back
#define mmp make_pair
#define oset(T) tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>
using namespace __gnu_pbds;
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef pair<int,int> ii;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef long double ld;
typedef vector<vii> al;
typedef vector<ll> vl;
const int INF = 1e9;
const ll INFL = 1LL<<61;
const int MN = 55;
string bs[MN];
ll w[MN];
int main() {
	ios::sync_with_stdio(0);cout.precision(20);cout.tie(0);cin.tie(0);
	int n;
	cin >> n;
	for(int i=0;i<n;i++) {
		string s;
		cin >> s;
		bs[i] = s;
		ll t;
		cin >> t;
		w[i] = t;
	}
	string x;
	cin >> x;
	int sid = -1;
	for(int i=0;i<n;i++) {
		if(bs[i] == x) {
			sid = i+1;
		}
	}
	ll res = 0;
	for(int i=sid;i<n;i++) {
		res += w[i];
	}
	cout << res << '\n';
}



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

int main() {

int a,b,c;
cin >> a >> b >> c;
int d = 100*a + 10*b + c;
if (d%4 == 0){
  cout << "YES" << endl;
}else{
  cout << "NO" << endl;
}
}



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

#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

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

int main()
{
    int n, a, b;
    cin >> n >> a >> b;
    cout << min(a * n, b) << endl;

    return 0;
}

Measured memory_bytes: 764
def abc():
    n = int(input())
    words = []
    for i in range(n):
        words.append(input().rstrip())
    if len(words) != len(set(words)):
        print('No')
        return
    for i in range(n-1):
        if words[i][-1] != words[i+1][0]:
            print('No')
            return
    print('Yes')


abc()


Measured memory_bytes: 3060
#include <stdio.h>

int isPrime(int x){
	if(x==1){
		return -1;
	}
	int i;
	for(i=2;i<x;i++){
		if(x%i==0){
			return -1;
		}
	}
	return 1;
}

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

	int i;
	int ans[55];
	printf("31 ");
	for(i=31; i<=55555; i+=30){
		if(isPrime(i) == 1){
			if(i != 31)	printf("%d ",i);
			N--;
			if(N==0)	break;
		}
	}
	
	
	return 0;}

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

int main() {
  string S;
  cin >> S;
  
  int ss = S.size();
  
  int ans = 1000;
  for(int i=0;i<=ss-3;i++){
    int atai=0;
    atai = (S.at(i)-'0')*100 + (S.at(i+1)-'0')*10 + (S.at(i+2)-'0')*1 ;
    
    int sa = abs (753-atai);
    
    ans = min(ans,sa);
  }
  
  cout << ans << endl;
    
}

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

typedef complex<ll> Point;
typedef vector<Point> VP;
#define X real()
#define Y imag()

namespace std {
    bool operator<(const Point a, const Point b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}

int main(void){
    int n;
    cin >> n;
    VP ps(n);
    rep(i,n){
        ll x, y;
        cin >> x >> y;
        ps[i] = Point(x,y);
    }
    sort(all(ps));
    int res = n;
    rep(i,n)rep(j,i){
        ll dx = ps[i].X - ps[j].X;
        ll dy = ps[i].Y - ps[j].Y;
        int cost = n;
        rep(k,n){
            if (find(all(ps), Point(ps[k].X + dx, ps[k].Y + dy)) != ps.end()){
                cost--;
            }
        }
        res = min(res, cost);
    }
    cout << res << endl;
    return 0;
}


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

using namespace std;

#define MAX_N 36
#define MAX 1000

char getChar(int x){
  return (x < 10 ? x+'0' : x+'A'-10);
}

int main(){
  int N,M,Q;
  while(cin >> N >> M >> Q, N){
    string S,B[MAX+1];
    bool sw[MAX+1][MAX_N];
    sw[0][0] = false;
    for(int i = 1 ; i <= Q ; i++){
      cin >> S >> B[i];
      for(int j = 0 ; j < N ; j++){
        sw[i][j] = (S[j] == '1' ? !sw[i-1][j] : sw[i-1][j]);
      }
    }
    string ans;
    for(int i = 0 ; i < M ; i++){
      bool use[MAX_N];
      fill(use,use+N,true);
      for(int j = 1 ; j <= Q ; j++){
        for(int k = 0 ; k < N ; k++){
          if(!sw[j][k] && B[j][i] == '1' ||
              sw[j][k] && B[j][i] == '0'){
            use[k] = false;
          }
        }
      }
      bool ok = true;
      int x = -1;
      for(int j = 0 ; j < N ; j++){
        if(use[j]){
          if(x != -1){ ok = false; }
          x = j;
        }
      }
      ans += (ok ? getChar(x) : '?');
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 2292
S = list(input())
listbit = []
lenplus = len(S)-1
for i in range(2**lenplus):
    suuji = ''
    for j in range(len(S)):
        suuji += S[j]
        if (i >> j & 1):
            suuji += '+'
    listbit.append(suuji)

ans = 0
for i in listbit:
    ans += eval(i)
print(ans)

Measured memory_bytes: 3064
N, M, X, Y = [int(_) for _ in input().split()]
x = [int(_) for _ in input().split()]
y = [int(_) for _ in input().split()]
for z in range(X+1, Y+1):
  if all([xx < z for xx in x]) and all([z <= yy for yy in y]):
    print('No War')
    break
else:
  print('War')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
typedef long long ll;
const int c=1e5;
const ll mod=1e9+7;
/*bool p[1000];
void sieve(){
p[0]=p[1]=1;
for(int i=2;i<=100;i++){
    for(int j=i*i;j<=100;j+=i){
        p[j]=1;
    }
}
}*/
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n,s,k;
ll sum=0;
    cin>>n>>s;
    ll w[n+5],v[n+5];
    for(int i=1;i<=n;i++){
        cin>>w[i]>>v[i];
        //p[i]={w,v};
        sum+=v[i];
    }
ll dp[sum+5];
int mx=0;
for(int j=1;j<=sum;j++){
     dp[j]=1e18;
    }
    dp[0]=0;
for(int i=1;i<=n;i++){
    for(int j=sum;j>=v[i];j--){
       dp[j]=min(dp[j],dp[j-v[i]]+w[i]);
    }
}
for(int j=0;j<=sum;j++){
     if(dp[j]<=s){
        mx=max(mx,j);
     }
    }

cout<<mx;
    return 0;
}


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

#define FOR(i,n) for(int i=0; i<n; i++)
#define FORI(i,z,n) for(int i=z; i<n; i++)

using namespace std;

int findSlot(vector<int>  &tail, int d) {
    int l=-1;
    int h=tail.size()-1;

    while (h - l != 1){
        int m = (h+l)/2;
        if (tail[m] >= d)
            h = m;
        else
            l = m;
    }
    return h;
}


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

    vector<int> digits(n);
    vector<int> tail;

    FOR(i, n) {
        int d;
        cin >> d;
        if (tail.empty()) {
            tail.push_back(d);
        } else if (d > tail.back()) {
            tail.push_back(d);
        } else {
            int toChange = findSlot(tail, d);
            tail[toChange] = d;
        }
    }

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



Measured memory_bytes: 3688
#include <iostream>
#include <stdio.h>
#include<math.h>

#define N 200050

using namespace std;

int main(void){
    // Your code here!
    
    int n;
    //double
    int d;//int d;
    int count=0;
    //int x[N],y[N];
    int x,y;
    
    scanf("%d %d",&n,&d);
    
    for(int i=0; i<n; i++){
    scanf("%d %d",&x,&y);
    
    //d=sqrt( pow( x, 2 ) + pow( y, 2 ) );
    
    if( sqrt( pow( x, 2 ) + pow( y, 2 ) )<=d  ) count++;
    
   
    }
    
    printf("%d\n",count);
    
    return 0;
}


Measured memory_bytes: 3804
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <map>
#include <set>
#include <sstream>
#include <stdio.h>
#include <cstring>

using namespace std;

#define Rep(i,a,b) for(int i = a; i < b; i++)
#define rep(i,b) Rep(i,0,b)
#define rrep(i,a) for(int i = a; i >= 0; i--)
#define allof(a) (a).begin(), (a).end()
#define pb push_back

typedef long long ll;
const int inf = 1e9 + 7;
const ll infll = 1ll << 60ll;
const ll mod = 1e9 + 7;
// 0~3までは右左下上 4~7までは斜め
constexpr int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
constexpr int dy[] = { 0, -1, 0, 1, 1, -1, -1, 1 };

/*
// 最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}

// 最小公約数
long lcm(long a, long b) {
	return a / gcd(a, b) * b;
}*/
/*
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);


	return 0;
}*/

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

	ll n;
	cin >> n;
	vector<ll> x(n), y(n), h(n);
	ll si = -1;
	rep(i, n) {
		cin >> x[i] >> y[i] >> h[i];
		if (h[i] > 0) {
			si = i;
		}
	}
	// 100 * 100 = 1e4 より 1マスにつき100回は処理できる
	// ch = h[i] + abs(x[i] - cx) + abs(y[i] - cy)

	ll ch = -1, cx = -1, cy = -1;
	// 矛盾がないか調べる 高さが0でないとき
	rep(i, 101) {
		rep(j, 101) {
			bool can = true;
			ch = h[si] + abs(x[si] - i) + abs(y[si] - j);
			rep(k, n) {
				if (h[k] > 0 && ch != h[k] + abs(x[k] - i) + abs(y[k] - j)) {
					can = false;
					break;
				}
				else if (h[k] == 0 && (ch > abs(x[k] - i) + abs(y[k] - j))) {
					can = false;
						break;
				}
			}
			if (can) {
				cout << i << " " << j << " " << ch << endl;
				return 0;
			}
		}
	}

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define sz(v)   ((int)(v).size())
#define  all(v)    ((v).begin()),((v).end())
#define  allr(v)    ((v).rbegin()),((v).rend())
#define   pb         push_back
#define   mp         make_pair
#define  clr(v,val)      memset(v,val,sizeof(v))
#define    lcm(a,b)                ((a*b)/(__gcd(a,b)))
typedef  long long     ll ;
typedef  unsigned long long     ull ;
const double eps= (1e-9);
using namespace std;
using namespace __gnu_pbds;
int getBit(ll num, int idx) {return ((num >> idx) & 1ll) == 1;}
ll setBit1(ll num, ll idx) {return num | (1ll<<idx);}
ll setBit0(ll num, int idx) {return num & ~(1ll<<idx);}
ll flipBit(ll num, int idx) {return num ^ (1ll<<idx);}
int dcmp(long double a,long double b){   return fabsl(a-b)<=eps ? 0: (a>b)? 1:-1  ;}
void GO(){ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);}
const int N=200000+9,mod=1e9+7;
ll solve(ll r,ll d){

   return r/d;
}
int main(){
    GO();

    int T;
    T=1;
    while(T--){
        int l,r,d;
        cin>>l>>r>>d;
        ll ans= solve(r,d)-solve(l-1,d);
        cout<<ans<<"\n";


    }

}




















































































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

int main(void) {
	int n,s=0;
	cin >> n;
	int a[n];
	int x=101;
	for (int i=0;i<n;i++) {
		cin >> a[i];
		s += a[i];
		if (a[i] %10 != 0) {
			if (a[i] < x) {
				x = a[i];
			}
		}
	}
	if (s%10 == 0) {
		if (x == 101) {
			s=0;
		} else {
			s -= x;
		}
	}
	cout << s << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;
int main()
{
    set<char>s;
    ll n;
    cin >> n;
    while(n --)
    {
        char c;
        cin >> c;
        s.insert(c);
    }
    if(s.size() == 4)
    {
        cout << "Four";
    }
    else 
    {
        cout << "Three";
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
// ABC098-A-
/*
int main(){
    int a, b;
    cin >> a >> b;
    cout << max(a + b, max(a - b, a * b)) << endl;
}
 */

// ABC099-A-
/*
int main(){
    int a;
    bool okey = true;
    cin >> a ;
    if (a > 999) {
        okey = false;
        a -= 1000;
    }
    
    if (okey) {
        cout << "ABC" << endl;
    }else{
        cout << "ABD" << endl;
    }
}
*/

//ABC100-A-
/*
int main(){
    int a, b;
    cin >> a >> b;
    if (a > 8 || b > 8) {
        cout << ":(" << endl;
    }else{
        cout << "Yay!" << endl;
    }
    
}
 */
//ABC101-A-

int main(){
    int ans = 0;
    for (int i = 0; i < 4; i++) {
        char s;
        cin >> s;
        if(s == '+'){
            ans++;
        }else{
            ans--;
        }
    }
    cout << ans << endl;
}

//ABC102-A-
/*
int main(){
    int n;
    cin >> n;
    if (n % 2 == 0) {
        cout << n << endl;
    }else{
        cout << n * 2 << endl;
    }
}
*/
//ABC102-A-
/*
int main(){
    int a, b, c;
    cin >> a >> b >> c;
    vector<int>task;
    task = {a, b, c};
    sort(task.begin(), task.end());
    cout << task.at(2) - task.at(0) << endl;
}
*/




Measured memory_bytes: 256
package main

import (
	"fmt"
)

type Edge struct {
	to int
	id int
}

func dfs(edges [][]Edge, visited []bool, colors []int, from, now int) {
	if visited[now] {
		return
	}
	visited[now] = true

	ng := -1
	for _, e := range edges[now] {
		if e.to == from {
			ng = colors[e.id]
		}
	}

	color := 1
	for _, e := range edges[now] {
		if color == ng {
			color++
		}
		if e.to == from || visited[e.to] || colors[e.id] != 0 {
			continue
		}
		colors[e.id] = color
		color++
		dfs(edges, visited, colors, now, e.to)
	}
}

func max(nums []int) int {
	ret := nums[0]
	for _, v := range nums {
		if v > ret {
			ret = v
		}
	}
	return ret
}

func main() {
	var n int
	fmt.Scan(&n)
	edges := make([][]Edge, n)
	for i := 0; i < n-1; i++ {
		var a, b int
		fmt.Scan(&a, &b)
		a--
		b--
		edges[a] = append(edges[a], Edge{to: b, id: i})
		edges[b] = append(edges[b], Edge{to: a, id: i})
	}

	colors := make([]int, n-1)
	dfs(edges, make([]bool, n), colors, -1, 0)

	fmt.Println(max(colors))
	for _, col := range colors {
		fmt.Println(col)
	}
}


Measured memory_bytes: 35328
import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    
    int N = scan.nextInt();
    int M = scan.nextInt();
    
    if (N == M){
      System.out.println("Yes");
    } else {
      System.out.println("No");
    }
  
  }
}

Measured memory_bytes: 23764
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 1000000007;
typedef long long LL;

template<typename T>
istream& operator >> (istream& is, vector<T>& vs){
  for(T& v: vs) is >> v;
  return is;
}

template<typename T>
ostream& operator << (ostream& os, const vector<T>& vs){
  for (const T& v : vs) os << v << " ";
  return os;
}

constexpr int kMax = 1e6 + 1;
bool b[kMax] = {};

int main() {
  LL N; cin >> N;
  vector<LL> A(N); cin >> A;
  LL S = 0, vmax = 0;
  for (LL x : A) {
    S = gcd(S, x);
    vmax = max(vmax, x);
  }
  bool setwise = (S == 1);

  bool pairwise = true;
  for (int i = 0; i < N; ++i){
    LL x = A[i];
    for (int j = 1; j * j <= x; ++j) {
      if (x % j != 0) continue;
      LL y = j;
      LL z = A[i] / j;
      if (b[y] && y != 1) {
        pairwise = false;
        break;
      }
      if (b[z] && z != 1) {
        pairwise = false;
        break;
      }
      b[y] = true;
      b[z] = true;
    }
    if (!pairwise) break;
  }

  if (pairwise) {
    cout << "pairwise coprime" << endl;
  } else if (setwise) {
    cout << "setwise coprime" << endl;
  } else {
    cout << "not coprime" << endl;
  }
}


Measured memory_bytes: 11096
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
 
# 遅延評価で加えてあげるだけ
 
N,Q = map(int,input().split())
AB = [[int(x) for x in input().split()] for _ in range(N-1)]
PX = [[int(x) for x in input().split()] for _ in range(Q)]
 
graph = [[] for _ in range(N+1)]
for a,b in AB:
    graph[a].append(b)
    graph[b].append(a)
 
value = [0] * (N+1)
for p,x in PX:
    value[p] += x
 
def dfs(v,parent,add):
    value[v] += add
    for x in graph[v]:
        if x == parent:
            continue
        dfs(x,v,value[v])
 
dfs(1,0,0)
 
answer = ' '.join(map(str,value[1:]))
print(answer)


Measured memory_bytes: 285828
#include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define rep(i, n) repd(i, 0, n)
typedef long long ll;

using namespace std;

int inputValue();
void inputArray(int *, int);
void inputVector(vector<int> *, int);
template <typename T> void output(T, int);
int gcd(int a, int b);

int main() {
    // source
    string s;
    cin >> s;
    int ans = 700;
    rep(i, s.length()) {
        if (s[i] == 'o') {
            ans += 100;
        }
    }
    cout << ans << endl;

    return 0;
}

int inputValue() {
    int a;
    cin >> a;
    return a;
}

void inputArray(int *p, int a) {
    rep(i, a) { cin >> p[i]; }
}

void inputVector(vector<int> *p, int a) {
    rep(i, a) {
        int input;
        cin >> input;
        p->push_back(input);
    }
}

template <typename T> void output(T a, int precision) {
    if (precision > 0) {
        cout << setprecision(precision) << a << "\n";
    } else {
        cout << a << "\n";
    }
}

int gcd(int a, int b) {
    if (b > a) {
        int temp = a;
        a = b;
        b = temp;
    }
    if (b == 0) {
        return a;
    }
    return (b, b % a);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define td(v) v.begin(),v.end()
#define tdr(v) v.rbegin(),v.rend()
#define endl "\n"
#define Matrix vector<vector<int> >
using namespace std;
const int MOD = 1e9+7;
const int MOD2 = 1e9 + 9;
const int INF = 5e18;
 
int gcd(int a, int b){return (b == 0 ? a : gcd(b, a%b));}
int lcm(int a,int b){return (a*b)/gcd(a,b);}
 
 
inline long long mod(long long n, long long m){
    long long ret = n%m;
    if(ret < 0) ret += m;
    return ret;
}
 
int exp(int a, int b){
    int result = 1;
    while (b > 0){
        if (b & 1)
            result = result*a;
 
        b >>= 1;
        a = a*a;
    }
    return result;
}
vector<int>adj[234567];
vector<int>val(234567);
vector<bool>flag(234567,false);
vector<int>vet;
vector<int>res;
void dfs(int pos){
    flag[pos]=true;
    int x = val[pos];
    int guard;
    bool incrementou = false;
    auto it = lower_bound(td(vet),x);
    int posicao = it-vet.begin();
    if(it==vet.end()){
        incrementou=true;
        vet.push_back(x);
    }
    else{
        guard=vet[posicao];
        vet[posicao]=x;
    }
    res[pos]=vet.size();
    for(int i=0;i<adj[pos].size();i++){
        if(!flag[adj[pos][i]])
            dfs(adj[pos][i]);
    }
    if(incrementou){
        vet.pop_back();
    }
    else{
        vet[posicao]=guard;
    }
}
void solve(){
    int n;
    cin>>n;
    res.assign(n+1,0);
    for(int i=1;i<=n;i++){
        cin>>val[i];
    }
    for(int i=0;i<n-1;i++){
        int x,y; cin>>x>>y;
        adj[x].push_back(y);
        adj[y].push_back(x);  
    }
    dfs(1);
    for(int i=1;i<=n;i++){
        cout<<res[i]<<endl;
    }
}
signed main(){
    fastio; 
    // int x=0;
    int t=1;
    // cin>>t;
    while(t--)
        solve();
}

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

using namespace std;
int n;

void dfs(string s, char mx) {
  if (s.size() == n) {
    cout << s << '\n';
  } else {
    for (char c = 'a'; c <= mx; ++c) {
      if (c == mx) {
	dfs(s + c, c + 1);
      } else {
	dfs(s + c, mx);
      }
    }
  }
}

int main() {
  cin >> n;
  dfs("", 'a');
  return 0;
}



Measured memory_bytes: 1536
c=1
s=j=0
eval"N,K,*A="+`dd`.split*?,
A.sort!
K.upto(N){|i|s+=c.*A[i-1]-A[-i]
c=c*i*($*[j+=1]=j<2?1:M/j*-$*[M%j])%M=10**9+7}
p s%M

Measured memory_bytes: 40968
#include "bits/stdc++.h"
#define REP(i,n) for(int i=0;i< (n);i++)
#define REPR(i, n) for(int i = (n);i >= 0;i--)
#define FOR(i, m, n) for(int i = (m);i < (n);i++)
#define FORR(i, m, n) for(int i = (m);i >= (n);i--)
#define SORT(v, n) std::sort(v, v+n);
#define VSORT(v) std::sort(v.begin(), v.end());
#define VRSORT(v) std::sort(v.rbegin(), v.rend());
#define ll long long
#define pb(a) push_back(a)
#define ALL(obj) (obj).begin(),(obj).end()

using namespace std;

const int INF = 99999999;
const ll LINF = 9999999999999;

typedef pair<int, int> P;
typedef pair<ll, ll> LP;
int vx[4] = { 0,1,0,-1 };
int vy[4] = { 1,0,-1,0 };


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

	ll x, y;
	cin >> x >> y;

	cout << max(x+y,max(x-y,x*y))<<endl;
	
	return 0;

}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<map>
#include<bitset>
using namespace std;

typedef long long ll;
#define rep(i, n) for(int i = 0;i < (n);i++)
#define repr(i, n) for(int i = (n);i >= 0;i--)
#define repf(i, m, n) for(int i = (m);i < (n);i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1;} return 0;}
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1;} return 0;}
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
//////////////////////////////////////////////////


int main() {
    int n; cin >> n;
    vector<int> w(n);
    int sum = 0;
    rep(i,n) cin >> w[i], sum += w[i];
    int ans = sum, tmp = 0;
    rep(i,n) {
        tmp += w[i];
        chmin(ans, abs(sum-tmp*2));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define LL long long
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPA(i,n) for(int i=1;i<(n);++i)
#define PII pair<int,int>
#define PLI pair<long long, int>
#define PLL pair<long long, long long>
#define MOD ((int)1e6 + 3)
#define INF ((int)1e9)
#define INFLL ((LL)1e18)
#define ALL(x) (x).begin(),(x).end()
#define ctoi(x) (x - 'a') 
#define CTOI(x) (x - 'A')
#define BIT(x) (1 << (x))
using namespace std;

LL modinv(LL a){
    LL b = MOD, u = 1, v = 0;
    while(b){
        LL t = a / b;
        a -= t * b;swap(a, b);
        u -= t * v;swap(u, v);
    }
    u%=MOD;
    if(u < 0) u += MOD;
    return u;

}
int exp(int a, int b){
    LL res = 1;
    LL sum = a;
    for(int i=0;i<30;++i){
        if(BIT(i)&b){
            res = (res * sum)%MOD;
        }
        sum = (sum * sum) % MOD;
    }
    return res;
}

int N;
int K;
vector<vector<int> > road;

int count(int np, int lp, int deep){
    int res = 0;
    if(deep<0){
        ++res;
    }
    REP(i, road[np].size()){
        if(road[np][i]==lp)continue;
        res += count(road[np][i], np, deep-1);
    }
    return res;
}

int main(){
    cin >> N >> K;
    road.resize(N);
    REP(i, N-1){
        int a, b;
        cin >> a >> b;
        --a;
        --b;
        road[a].push_back(b);
        road[b].push_back(a);
    }
    int ans = INF;
    REP(i, N){
        if(K%2){
            REP(j, road[i].size()){
                ans = min(ans, count(road[i][j], i, K/2)+count(i, road[i][j], K/2));
            }
        }else{
            ans = min(ans, count(i, -1, K/2));
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 512
N, K = [int(str) for str in input().strip().split()]
X = [int(str) for str in input().strip().split()]

ans = 2 * 10**9

for i in range(N - K + 1):
    time = abs(X[i + K - 1] - X[i]) + min(abs(X[i]), abs(X[i + K - 1]))
    ans = min(ans, time)

print(ans)

Measured memory_bytes: 14380
#include <stdio.h>

int main(){
	char s[101];
	int i,count=0;
	scanf("%s",s);
	for(i=0;i<101;i++){
		if(i%2==0 && (s[i]=='R' || s[i]=='U' || s[i]=='D'))count++;
		if(i%2==1 &&(s[i]=='L' || s[i]=='U' || s[i]=='D'))count++;
		if(s[i]=='\0')break;
	}
	if(i==count)printf("Yes\n");
	else printf("No\n");
	return 0;
}

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

int N;

long long s=0;

int main(){
    cin>>N;
    for(int i=1;i<=N;i++){
        if(i%3==0||i%5==0){
            continue;
        }else {s=s+i;}
    }
    cout<<s<<endl;
}

Measured memory_bytes: 3644
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main {
    public static boolean[][][] found;
    public static double[][][] dp;
    public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        int N = Integer.parseInt(reader.readLine());
        String[] lo = reader.readLine().split(" ");
        int two = 0,one =0,three=0;
        for (int i = 0; i <N ; i++) {
            int y = Integer.parseInt(lo[i]);
            if(y==1) one++;
            else if(y==2) two++;
            else three++;
        }
        found = new boolean[one+two+three+1][two+three+1][three+1];
        dp = new double[one+two+three+1][two+three+1][three+1];
        System.out.println(rec(one,two,three,N));
    }
    public static double rec(int one,int two,int three,int N){
        if(one<0 || two<0 ||three<0) return 0.0;
        else if(found[one][two][three]) return dp[one][two][three];
        else if(one==0 && two==0 && three==0){
            found[one][two][three]=true;
            return 0.0;
        }
        else{
            found[one][two][three]=true;
            dp[one][two][three] =  (N/(double)(one+two+three) + ((double)(one)/(double)(one+two+three))*rec(one-1,two,three,N)+
                    ((double)(two)/(double)(one+two+three))*rec(one+1,two-1,three,N) +
                    ((double)(three)/(double)(one+two+three))*rec(one,two+1,three-1,N));
            return dp[one][two][three];
        }
    }
}


Measured memory_bytes: 294804
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll GCD(ll x,ll y){
    if(y == 0) return x;
    else return GCD(y,x%y);
}
const int MOD = 1000000007;

int main() {
    int x; cin >> x;
    ll a = 0,cnt = 0;
    vector<int> vec;
    for(int i = 0;a < x;i++){
        a+=i;
        cnt++;
        vec.push_back(i);
    }
    
    int k = 0;
    
    while(true){
        if(a-vec[k] == x){
            cnt--;
            a-=vec[k];
            break;
        }
        k++;
    }
    cout << cnt;
}




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

int main() {
  int n,k,h,ans=0;
  cin >> n >> k;
  rep(i,n) {
  	cin>> h;
  	if(h>=k) ans++;
  }
  cout << ans << endl; 
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * Built using CHelper plug-in Actual solution is at the top
 */
public class Main {
	public static void main(String[] args) {
		InputReader in = new InputReader(System.in);
		PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)), true);
		TaskB solver = new TaskB();
		solver.solve(1, in, out);
		out.flush();
		out.close();
	}
}

class Pair {
	long first;
	long second;
	long third;

	Pair(long first, long second, long third) {
		this.first = first;
		this.second = second;
		this.third = third;
	}
}

class TaskB {

	public void solve(int testNumber, InputReader in, PrintWriter pw) {
		int N = in.nextInt();
		int h[] = new int[N + 1];
		for (int i = 1; i <= N; i++) {
			h[i] = in.nextInt();
		}
		int dp[] = new int[N + 1];
		dp[1] = 0;
		dp[2] = Math.abs(h[2] - h[1]) + dp[1];
		for (int i = 3; i <= N; i++) {
			dp[i] = Math.min(Math.abs(h[i] - h[i - 1]) + dp[i - 1], Math.abs(h[i] - h[i - 2]) + dp[i - 2]);
		}
		pw.println(dp[N]);

	}

	int __gcd(int a, int b) {
		if (b == 0)
			return a;
		return __gcd(b, a % b);

	}

	public int getInt(int num) {
		int ret = -1;
		switch (num) {
		case 0:
			ret = 6;
			break;
		case 1:
			ret = 2;
			break;
		case 2:
			ret = 5;
			break;
		case 3:
			ret = 5;
			break;
		case 4:
			ret = 4;
			break;
		case 5:
			ret = 5;
			break;
		case 6:
			ret = 6;
			break;
		case 7:
			ret = 3;
			break;
		case 8:
			ret = 7;
			break;
		case 9:
			ret = 6;
			break;
		}
		return ret;
	}

	public int isPow(long num) {
		int count = 0;
		while (num > 0) {
			num /= 2;
			count++;
		}
		return count;
	}
}

class InputReader {
	BufferedReader br;
	StringTokenizer st;

	public InputReader(InputStream in) {
		br = new BufferedReader(new InputStreamReader(in));
		st = null;
	}

	public String next() {
		while (st == null || !st.hasMoreTokens()) {
			try {
				st = new StringTokenizer(br.readLine());
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return st.nextToken();
	}

	public int nextInt() {
		return Integer.parseInt(next());
	}

	public long nextLong() {
		return Long.parseLong(next());
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}
}


Measured memory_bytes: 36832
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#define deb(x) cout<<#x<<" "<<x<<endl;
#define print(arr,n) for(int i=0;i<n;++i) { cout<<arr[i]<<" "; } cout<<endl;
#define ub(x,el) upper_bound(x.begin(),x.end(),el) - x.begin()
#define lb(x,el) lower_bound(x.begin(),x.end(),el) - x.begin();
#define bs(x,el) binary_search(x.begin(),x.end(),el)
#define MOD 1000000007
#define finish return 0
using namespace std;
using namespace __gnu_pbds; 
typedef long long int ll;
typedef tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> ordered_set;
template<int D, typename T> struct Vec : public vector<Vec<D - 1, T>> { static_assert(D >= 1, "Vector dimension must be greater than zero!"); template<typename... Args> Vec(int n = 0, Args... args) : vector<Vec<D - 1, T>>(n, Vec<D - 1, T>(args...)) { }}; template<typename T> struct Vec<1, T> : public vector<T> { Vec(int n = 0, T val = T()) : vector<T>(n, val) { } };
inline ll mod(ll x) { return (x%MOD + MOD)%MOD; }
ll power(ll x,ll y, ll p) { ll res = 1; x = x % p; while (y > 0) { if (y & 1) res = (res*x) % p; y = y>>1; x = (x*x) % p;   } return res; } 
ll power(ll x,ll y) { ll res = 1; while (y > 0) { if (y & 1) res = (res*x); y = y>>1; x = (x*x);   } return res; } 
ll mod(ll num, ll den){ return mod(mod(num) * power(den,MOD-2,MOD)); }
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	ll n;
	cin>>n;
	vector< vector<ll> > G(n+1);
	for(ll i=2;i<=n;++i)
	{
		ll x;
		cin>>x;
		G[x].push_back(i);
	}
	for(ll i=1;i<=n;++i)
	{
		cout<<G[i].size()<<endl;
	}
}

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

int main(){
    string s;
    cin >> s;

    if(s[0]==s[1]){
        cout << "Bad" << endl;
    }else if(s[1]==s[2]){
        cout << "Bad" << endl;
    }else if(s[2]==s[3]){
        cout << "Bad" << endl;
    }else{
        cout << "Good" << endl;
    }
    return 0;
}

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}

const int MAX_N = 212345;
const int MAX_Q = 212345;
pair<char,char> qs[MAX_Q];

int main2() {
  int N, Q; cin >> N >> Q;
  string s; cin >> s;
  REP(i, Q) {
    cin >> qs[i].first;
    cin >> qs[i].second;
  }
  int left = -1;
  int right = N;

  for (int i = Q - 1; i >= 0; i--) {
    int t = qs[i].first;
    int d = qs[i].second;

    if (d == 'L') {
      if (s[left + 1] == t) {
        left++;
      }
      if (right != N && s[right] == t) {
        right++;
      }
    } else {
      if (s[right - 1] == t) {
        right--;
      }
      if (left != -1 && s[left] == t) {
        left--;
      }
    }
    if (right - left - 1 <= 0) break;
  }
  int ans = right - left - 1;
  cout << ans << endl;
  return 0;
}

int main() {
  for (;!cin.eof();cin>>ws)
    main2();
  return 0;
}


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

int main() {
  int N, K; cin>>N>>K;
  vector<int> p(N);
  for(int i=0;i<N;i++){
    cin>>p.at(i);
  }
  
  sort(p.begin(), p.end());
 
  int ans = 0;
  for(int i=0;i<K;i++){
    ans += p.at(i);
  }
  cout<<ans<<endl;
}

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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif

const int inf=1e9;
const int64_t inf64=1e18;
const double eps=1e-9;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
    	os << v << ",";
    }
    os << "]";
    return os;
}

void solve(){
    int n;
    int64_t x;
    cin >> n >> x;
    vector<int64_t> a(n);
    rep(i,0,n) cin >> a[i];
    int64_t ans=0;
    rep(i,0,n-1){
        int s=a[i]+a[i+1];
        if(s<=x) continue;
        ans+=s-x;
        if(s-x<=a[i+1]) a[i+1]-=s-x;
        else a[i+1]=0;
    }
    cout << ans << endl;
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(10);
    solve();
    return 0;
}


Measured memory_bytes: 1024
n,m,v,p = map(int,input().split())
lis = list(map(int,input().split()))
lis.sort(reverse=True)
ans = 0
trash = 0
for i in range(n):
    if i+1 <= p:
        ans += 1
    else:
        if lis[i] + m >= lis[p-1]:
            if (lis[i]+m)*(i-(p-1))-trash >= m * (v-(p-1)-(n-i)):
  #                 print(lis[i]+m,i-(p-1)-trash,m*(v-(p-1)-(n-i)))
                ans += 1
    if i+1 >= p:
        trash += lis[i]
print(ans)


Measured memory_bytes: 14480
#define  _CRT_SECURE_NO_WARNINGS
#pragma comment (linker, "/STACK:526000000")

#include "bits/stdc++.h"

using namespace std;
typedef string::const_iterator State;
#define eps 1e-11L
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL

#define MOD 998244353LL
#define seg_size 262144*2LL
#define pb push_back
#define mp make_pair
typedef long long ll;
#define REP(a,b) for(long long (a) = 0;(a) < (b);++(a))
#define ALL(x) (x).begin(),(x).end()

unsigned long xor128() {
	static unsigned long x = 123456789, y = 362436069, z = 521288629, w = time(NULL);
	unsigned long t = (x ^ (x << 11));
	x = y; y = z; z = w;
	return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}

void init() {
	iostream::sync_with_stdio(false);
	cout << fixed << setprecision(2);
}

#define int ll

int cnt[200000] = {};
int union_tree[200000] = {};
int union_find(int now) {
	if (union_tree[now] == now) return now;
	return union_tree[now] = union_find(union_tree[now]);
}
int dp[200000] = {};
void solve() {
	int n;
	cin >> n;
	vector<int> inputs;
	REP(i, n) {
		int a;
		cin >> a;
		inputs.push_back(a);
	}
	for (int i = 0; i < n; ++i) {
		if (cnt[i] || inputs[i] == 0) continue;
		int now = i;
		while (inputs[now] != 0 && cnt[now] == 0) {
			cnt[now] = 1;
			now += inputs[now];
		}
		if (inputs[now] == 0||cnt[now] == 2) {
			now = i;
			while (inputs[now] != 0 && cnt[now] == 1) {
				cnt[now] = 2;
				now += inputs[now];
			}
			continue;
		}
		now = i;
		while (inputs[now] != 0 && cnt[now] == 1) {
			cnt[now] = 3;
			now += inputs[now];
		}
	}
	int now = 0;
	int ans = 0;
	REP(i, n) {
		union_tree[i] = i + inputs[i];
	}
	queue<int> next;
	next.push(0);
	dp[0] = 1;
	while (next.empty() == false) {
		int now = next.front();
		next.pop();
		REP(q,7){
			if (now + q >= n) break;
			if (cnt[now + q] == 3) continue;
			int going = union_find(now + q);
			if (dp[going] == 0) {
				dp[going] = dp[now] + 1;
				next.push(going);
			}
		}
	}
	cout << dp[n-1]-1 << endl;
}

#undef int
int main() {
	init();
	solve();
}


Measured memory_bytes: 7496
fun main(args: Array<String>) {
	val s = Array(3) { "" }

	for (i in 0..s.lastIndex) {
		s[i] = readLine()!!
	}

	var turn = 0

	while (s[turn] != "") {
		val pre = turn
		turn = s[turn][0] - 'a'

		s[pre] = s[pre].removeRange(0, 1)
	}

	println('A' + turn)
}


Measured memory_bytes: 35560
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int A1, A2, A3;
    cin >> A1 >> A2 >> A3;
    if (A1 + A2 + A3 >= 22)
    {
        cout << "bust" << endl;
    }
    else
    {
        cout << "win" << endl;
    }
}

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

int main(){
	int day; cin >> day;
	string s;
	switch(day){
		case 25: s = "Christmas"; break;
		case 24: s = "Christmas Eve"; break;
		case 23: s = "Christmas Eve Eve"; break;
		case 22: s = "Christmas Eve Eve Eve"; break;
	}
	cout << s << endl;
}

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

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int MD = (int)1e9 + 7;
void dbg(){ cerr << "\n"; }  template <typename T,typename ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }


int f(int n, int k, string s){
	VI a; a.reserve(n+10);
	if(s[0]=='0') a.push_back(0);
	int sm =1;
	rep(i,n-1){
		if(s[i] == s[i+1]) sm++;
		else{ a.push_back(sm); sm =1; }
	}
	if(sm!=0) a.push_back(sm);
	if(a.back()=='0') a.push_back(0);
	vector<ll> sk(sz(a)+1);
	rep(i, sz(a)) sk[i+1] = sk[i]+a[i];
	
	ll mx=0;
	for(int i=0; i<sz(a); i+=2){
		mx=max(mx, sk[min(i+k*2+1, sz(a))] - sk[i]);
	}
	return mx;
}


int main(){
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n,k;
	string s;
	cin >>n >>k >>s;
	
	auto z=f(n, k, s);
	cout << z <<"\n";
	return 0;
}

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

using namespace std;

#define mx 111

int main()
{
    //freopen("input.txt", "r", stdin);

    int x, n;

    cin >> x;

    n = x / 1000;

    if(n*1000 == x)
    {
        x = 0;
    }
    else{
        x = (n+1) * 1000 - x;

    }

    cout << x << endl;









    return 0;
}


Measured memory_bytes: 3636