akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int H = sc.nextInt();
    int W = sc.nextInt();
    int h = sc.nextInt();
    int w = sc.nextInt();
    System.out.println(H * W - h * W - (H - h) * w);
  }
}

Measured memory_bytes: 22996
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define per(i, a, b) for(int i = b-1; i>=a ; i--)
#define trav(a, x) for(auto& a : x)
#define allin(a , x) for(auto a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<ll> vl;
typedef vector<pii> vpi;
typedef pair<ll,ll> pll;
typedef vector<string> vs;
typedef vector<pll> vpl;
typedef vector<int> vi;

int32_t main(){
	int n;
	cin >> n;
	vi v(n);
	rep(i,0,n){
		cin >> v[i];
	}	
	ll ans = (ll) 1e18;
	rep(p, -200, 200){
		ll curr = 0;
		rep(i,0,n){
			curr += (v[i] - p)*(v[i] - p);
		}
		ans = min(ans, curr);
	}
	cout << ans << endl;
}

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

int main() {
    int a,b,c;
    cin >>a>>b >>c;
    int k = (max(a,max(b,c))) ;
    int sum= a+b+c ;
    if ((3*k-sum)%2==0)
    cout <<(3*k-sum)/2 << endl;
    else
    cout << (3*k-sum+3)/2 <<endl;

}

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

long long int a, b;

int main(){
    scanf("%lld%lld", &a, &b);
    if(a + b == 15)return 0 & puts("+");
    if(a * b == 15)return 0 & puts("*");
    puts("x");
    return 0;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
k, s = [], []
ans = 0
for i in range(m):
    tmp = list(map(int, input().split()))
    k.append(tmp.pop(0))
    s.append(tmp)
p = list(map(int, input().split()))

for i in range(2**n):
    bn = str(bin(i))[2:].zfill(n)
    bright = 0
    for light in range(m):
        onbotton = 0
        for j, bit in enumerate(bn):
            if (j+1 in s[light])and (bit=='1'): onbotton+=1
        if onbotton%2 == p[light]: bright+=1
    if bright == m: ans+=1
print(ans)

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

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP0(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REP1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)

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

const int INTINF = 1e9;
const LL LLINF = 1e18;

int A, B, C, D, E, F;
double lim_prop;
double max_prop;
int ans_swater;
int ans_sugar;

// void dfs(int op1, int op2, int op3, int op4, int sw, int s)
// {
//     if (sw > F)
//         return;

//     if (sw)
//     {
//         double prop = 100 * s / (double)sw;
//         if (sw != 0 and max_prop <= prop and prop <= lim_prop)
//         {
//             ans_swater = sw;
//             ans_sugar = s;
//         }
//     }

//     dfs(op1 + 1, op2, op3, op4, sw + 100 * A, s);
//     dfs(op1, op2 + 1, op3, op4, sw + 100 * B, s);
//     dfs(op1, op2, op3 + 1, op4, sw + C, s + C);
//     dfs(op1, op2, op3, op4 + 1, sw + D, s + D);
// }

void solve()
{
    cin >> A >> B >> C >> D >> E >> F;
    lim_prop = 100 * E / ((double)E + 100);
    // dfs(0, 0, 0, 0, 0, 0);

    set<int> waters, sugars;
    for (int i = 0; 100 * A * i <= F; i++)
    {
        int Ai = 100 * A * i;
        for (int j = 0; Ai + 100 * B * j <= F; j++)
        {
            int water = Ai + 100 * B * j;
            if (water)
                waters.insert(water);
        }
    }

    for (int i = 0; C * i <= F; i++)
    {
        int Ci = C * i;
        for (int j = 0; Ci + D * j <= F; j++)
        {
            sugars.insert(Ci + D * j);
        }
    }

    for (auto sugar : sugars)
    {
        for (auto water : waters)
        {
            double prop = 100 * sugar / (double)(sugar + water);
            if (sugar + water <= F and max_prop <= prop and prop <= lim_prop)
            {
                ans_swater = sugar + water;
                ans_sugar = sugar;
                max_prop = prop;
            }
        }
    }

    cout << ans_swater << " " << ans_sugar << endl;
}

int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(10);
    solve();
    return 0;
}

Measured memory_bytes: 384
import kotlin.math.*
import java.util.*

data class Quartet<out A, out B, out C, out D>(val first: A, val second: B, val third: C, val fourth: D)

fun main(args: Array<String>) {
  val (_, m, q) = readLine()!!.split(' ').map(String::toInt)
  val rules = Array(q) {
    val (a, b, c, d) = readLine()!!.split(' ').map(String::toInt)
    Quartet(a - 1, b - 1, c, d)
  }
  var ans = 0
  for (a0 in 1..m)
    for (a1 in a0..m)
      for (a2 in a1..m)
        for (a3 in a2..m)
          for (a4 in a3..m)
            for (a5 in a4..m)
              for (a6 in a5..m)
                for (a7 in a6..m)
                  for (a8 in a7..m)
                    for (a9 in a8..m) {
                      val a = intArrayOf(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9)
                      var sc = 0
                      for (r in rules) {
                        if (a[r.second] - a[r.first] == r.third) {
                          sc += r.fourth
                        }
                      }
                      ans = max(ans, sc)
                    }
  println(ans)
}


Measured memory_bytes: 44164
N = int(input())
A = list(map(int, input().split()))
import sys

sys.setrecursionlimit(100000000)


def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


ans = A[0]
for a in A[1:]:
    ans = gcd(ans, a)

print(ans)


Measured memory_bytes: 14252
#include <bits/stdc++.h>
#define ll long long int
#define fio ios_base::sync_with_stdio(0);cin.tie(0)
#define sd(t) scanf("%d",&t)
#define pd(t) printf("%d\n",t)
#define slld(t) scanf("%lld",&t)
#define plld(t) printf("%lld\n",t)
#define sc(t) scanf("%c",&t)
#define pb(x) push_back(x)
#define ii pair<int,int>
#define vi vector<int>
#define vvi vector<vi >
#define vii vector<ii >
#define vvii vector<vii >
#define clr(x) memset(x,0,sizeof(x))
#define rep(i,begin,end) for(__typeof(end) i=begin-(begin>end);i!=end-(begin>end);i+=1-2*(begin>end))
#define M_PI 3.14159265358979323846
#define MOD 1000000007
#define MAX 100005
#define EPS 1e-12
using namespace std;

int main()
{
	ll n,a,b;
	slld(n); slld(a); slld(b);
	ll x[n+1];
	rep(i,1,n+1) slld(x[i]);

	ll ans = 0;
	rep(i,2,n+1)
	{
		ll L = a * (x[i]-x[i-1]);
		ll R = b;
		ans += min(L,R);
	}
	plld(ans);
	return 0;
}


Measured memory_bytes: 1024
import sys
input = sys.stdin.readline

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


cnt = 0

for i in a:
    for j in range(200):
        if 1 + i*j <=d:
            cnt += 1
        else:
            break


print(x+cnt)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B;
  string op;
  while(1){
  cin >> A >> op >> B;
 
  if (op == "+") {
    cout << A + B << endl;
  }
   if (op == "-") {
    cout << A - B << endl;
  }
   if (op == "*") {
    cout << A * B << endl;
  }
    if (op == "/") {
        if (B==0) {
    cout <<"error"<< endl;
  }
   else{
     cout << A / B << endl;
   }
  }
     if (op== "?") {
    break;
  }
       if (op== "=") {
    cout <<"error"<< endl;
  }
       if (op== "!") {
    cout <<"error"<< endl;
  }
  }
}


Measured memory_bytes: 3160
//#include "pch.h"
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>

#include <vector>
#include <set>
#include <map>
#include <iostream>
#include <utility>
#include <queue>
#include <algorithm>
#include <functional>
#include <string>

#define ll long long
#define fri(n) for(i=0;i<(n);i++)
#define frj(n) for(j=0;j<(n);i++)
#define min(p,q) ((p)<(q)?(p):(q))
#define max(p,q) ((p)>(q)?(p):(q))
#define swap(p,q) r=(p);(p)=(q);(q)=r
#define INF 1000000000000000000//10^18
#define INFINT 2000000001//2*10^9+1
#define MOD 1000000007
#define PI acos(-1)

using namespace std;


struct card_t{
	int idnum;
	int num;
};

int compare_num(const void *a, const void *b) {
	struct card_t *A = (struct card_t *)a;
	struct card_t *B = (struct card_t *)b;
	if(A->num - B->num >0){
		return 1;
	}else if(A->num - B->num >0){
		return -1;
	}else{
		return 0;
	}
}


int main(void)
{
	//変数の宣言
	int n,m;
	int a;
	static struct card_t card[5010];
	ll static int ruiseki[5010];
	static int dp[5010][5010];

	//よく使う変数
	int i,j,k,l;
	int flag=0;
	int ans=0;
	int count=0;
	int temp,temp1,temp2;
	int max,min;
	int len;
	int sum=0;
	int ok,ng;



	//データの読み込み


	scanf("%d %d",&n,&m);
//	scanf_s("%d %d",&n,&m);


	for(i=0;i<n;i++){
		scanf("%d",&a);
//		scanf_s("%d",&a);
		card[i].idnum=i;
		card[i].num=a;
	}

	//	printf("nは%dです\n", n);
	//	printf("データの読み込み終了\n");
	//実際の処理

	qsort(card,n,sizeof(card_t),compare_num);

	for(i=0;i<=n+5;i++){
		ruiseki[i]=0;
		for(j=0;j<=5000;j++){
			dp[i][j]=0;
		}
	}

	for(i=1;i<=n;i++){
		ruiseki[i]=ruiseki[i-1]+card[i-1].num;
	}
	
	dp[n+1][0]=1;
	for(i=n;i>=1;i--){
		for(j=0;j<=m;j++){
			if(j<card[i-1].num){
				dp[i][j]=dp[i+1][j];
			}else{
				dp[i][j]=max(dp[i+1][j],dp[i+1][j-card[i-1].num]);
			}
		}
	}

	for(i=1;i<=n;i++){
		for(j=m-1;j>=0;j--){
			if(dp[i+1][j]==1){
				temp=j;
				break;
			}
		}
		if(temp+ruiseki[i-1]>=m-card[i-1].num) ans++;
	}


	//	printf("計算部分終了\n");

	//出力


	printf("%d",n-ans);


	//	printf("結果の出力終了\n");


	return 0;
}



Measured memory_bytes: 98300
#include <bits/stdc++.h>
using namespace std;
#define TRACE(x) x
#define WATCH(x) TRACE( cout << #x" = " << x << endl)
#define PRINT(x) TRACE(printf(x))
#define WATCHR(a, b) TRACE( for(auto c = a; c != b;) cout << *(c++) << " "; cout << endl)
#define WATCHC(V) TRACE({cout << #V" = "; WATCHR(V.begin(), V.end()); } )
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define mp make_pair
#define st first
#define nd second

using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using ld = long double;
using pll = pair<ll, ll>;
using vll = vector<ll>;
using pll = pair<ll, ll>;

void buff() { ios::sync_with_stdio( false ); cin.tie( nullptr ); }

constexpr ll MOD = 1e9 + 7;

inline ll pow_mod( ll a, ll b, ll mod = MOD) {
    ll res = 1; a %= mod; assert(b >= 0);
    for(;b;b>>=1) {
        if(b&1) res = (res * a) % mod;
        a = (a * a) % mod;
    }
    return res;
}
// End of template code!
int main() 
{
    buff();
    string s, t;
    cin >> s >> t;
    int l1 = sz(s), l2 = sz(t);
    if(l1 != l2 - 1) cout << "No\n";
    else {
        bool ok = true; 
        for(int i = 0; i < l1; ++i) {
            if(s[i] != t[i]) { 
                ok = false;
                break;
            }
        }
        if(ok) cout << "Yes\n";
        else cout << "No\n";
    }
    return 0;
}



Measured memory_bytes: 3608
#include<iostream>
#include<vector>


using namespace std;



int main(){
int N; cin >> N;
  vector<int> W(N); for(int i = 0; i < N; i++){ cin >> W[i];}
  vector<int> cumul(N,0); int sum = 0;
  for(int i = 0; i < N; i++){
    sum += W[i]; cumul[i] = sum;}
  int min_diff = 1e9; 
  for(int i = 0; i < N - 1; i++){
    min_diff = min(min_diff,abs(sum - 2 * cumul[i]));}
  
  cout << min_diff << endl; return 0;}
    

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

long long INF = 10000000000000;

int main(){
    long long V, E;
    cin >> V >> E;
    long long d[V][V];
    for(long long i=0; i<V; i++){
        for(long long j=0; j<V; j++){
            d[i][j] = INF;
        }
        d[i][i] = 0;
    }
    long long s,t,cost;
    for(long long i=0; i<E; i++){
        cin >> s >> t >> cost;
        d[s][t] = cost;
    }
    for(long long k=0; k<V; k++){
        for(long long i=0; i<V; i++){
            for(long long j=0; j<V; j++){
                if(d[i][k] == INF || d[k][j] == INF) continue;
                d[i][j] = min(d[i][j],d[i][k]+d[k][j]);
            }
        }
    }
    bool neg_cyc = 0;
    for(long long i=0; i<V; i++){
        if(d[i][i]<0){
            neg_cyc = 1;
        }
    }

    if(neg_cyc == 0){
        for(long long i=0; i<V; i++){
            for(long long j=0; j<V-1; j++){
                if(d[i][j]<INF){
                    cout << d[i][j] << " ";
                }else{
                    cout << "INF" << " ";
                }
            }
            if(d[i][V-1]<INF){
                cout << d[i][V-1] << endl;
            }else{
                cout << "INF" << endl;
            }
        }
    }else{
        cout << "NEGATIVE CYCLE" << endl;
    }
    return 0;
}


Measured memory_bytes: 3184
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define PB push_back
#define MP make_pair
#define ll long long

inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}

int main(){
    std::ios::sync_with_stdio(false);
    string str;
    cin >> str;
    int w;
    cin >> w;
    string res;
    for(size_t i=0;i<str.length();i+=w)
    {
        res += str[i];
    }

    cout << res << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cassert>
#include <climits>
#include <bitset>
#include <stack>
#include <queue>
#include <iomanip>
#include <limits>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string.h>

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P;

long long int INF = 1e18;
long long int mod = 1000000007;
double Pi = 3.1415926535897932384626;

vector<ll> G[500005];
vector<P> tree[500010];
priority_queue <ll> pql;
priority_queue <P> pqp;
//big priority queue
priority_queue <ll,vector<ll>,greater<ll> > pqls;
priority_queue <P,vector<P>,greater<P> > pqps;
priority_queue <P,vector<P>,greater<P> > pqps2;
//small priority queue
//top pop

int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,-1,1};
char dir[] = "RULD";
ll bit[500005];
//↓,→,↑,←


#define p(x) cout<<x<<endl;
#define el cout<<endl;
#define pe(x) cout<<x<<" ";
#define ps(x) cout<<fixed<<setprecision(15)<<x<<endl;
#define pu(x) cout<<x;
#define re(i,n) for(i=0;i<n;i++);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define deba(x) cout<< #x << " = " << x <<endl

ll rui(ll abc,ll bed){
    //abcのbed乗を計算する
    if(bed==0){return 1;}
    else{
        ll ced = rui(abc,bed/2);
        ced *= ced;
        ced %= mod;
        if(bed%2==1){ced*=abc; ced%=mod;}
        return ced;
    }
}
ll gcd(ll number1,ll number2){
	if(number1 > number2){
		swap(number1,number2);
	}
	if(number1 == 0 || number1 == number2){
		return number2;
	}else{
		return gcd(number2 % number1,number1);
	}
}

ll i,j,k,ii,jj,r,l;
ll n,m,num,ans;
ll a,b,c,d,e,g,h,w;
ll x[500005],y[500005],z[500005];
char s[5005][5005];

ll bitsum(ll i){
	ll s = 0;
	while(i>0){
		//p("hoi");
		s += bit[i];
		i -= i & -i;
	}
	return s;
}
void bitadd(ll b,ll x){
	while(b <= n){
		//p("hoi");
		bit[b] += x;
		b += b & -b;
	}
}

int main(){
    cin>>n;
	for(i=0;i<n;i++){
		cin >> x[i];
	}
	sort(x,x+n);
	ll ans1 = 0,ans2 = 0;
	if(n%2 == 1){
		a = (n-3)/2;
		b = 2;
		c = (n-1)/2;		
		for(i=0;i<n;i++){
			if(i < a){
				ans1 += x[i] * -2;
			}else if(i < a + b){
				ans1 += x[i] * -1;
			}else{
				ans1 += x[i] * 2;
			}
		}
		a = (n-1)/2;
		b = 2;
		c = (n-3)/2;
		for(i=0;i<n;i++){
			if(i < a){
				ans2 += x[i] * -2;
			}else if(i < a + b){
				ans2 += x[i] * 1;
			}else{
				ans2 += x[i] * 2;
			}
		}
	}else{
		a = (n-2)/2;
		b = 1;
		c = 1;
		d = (n-2)/2;
		for(i=0;i<n;i++){
			if(i < a){
				ans1 += x[i] * -2;
			}else if(i < a + b){
				ans1 += x[i] * -1;
			}else if(i < a + b + c){
				ans1 += x[i];
			}else{
				ans1 += x[i] * 2;
			}
		}
	}
	p(max(ans1,ans2));
    return 0;
}

Measured memory_bytes: 31104
#include <iostream>
#include <queue>
#include <vector>
#include <map>
using namespace std;

struct query {
	int a, v;

	query(int a_, int v_) { a = a_; v = v_; }

	void print() {
		cout << a << " " << v << endl;
	}

	bool operator<(const query q) const {
		if(v == q.v)
			return a > q.a;
		else
			return v < q.v;
	}
};

int main(void) {
	int n, q;
	priority_queue<query> p;
	map<int,int> m;

	cin >> n >> q;

	p.push(query(1, 0));
	m[1] = 0;
	for(int i = 0; i < q; i++) {
		map<int,int>::iterator iter;
		int a, v;
		cin >> a >> v;

		iter = m.find(a);
		if(iter != m.end())
			iter->second += v;
		else {
			m[a] = v;
			iter = m.find(a);
		}
		p.push(query(iter->first,iter->second));

		while(1) {
			query tmp(0,0);
			tmp = p.top();
			if(tmp.v != m.find(tmp.a)->second)
				p.pop();
			else {
				tmp.print();
				break;
			}
		}
	}
}

Measured memory_bytes: 6256
#include<iostream>
#include<cmath>
#include<cstdio>

using namespace std;

const double PI = acos(-1.0);


int main() {
	int n,i;
	int x[100];
	int y[100];
	cin >> n;
	for (i = 0;i < n;i++)cin >> x[i];
	for (i = 0;i < n;i++)cin >> y[i];
	double pm = 0;
	for (i = 1;i <= 3;i++) {
		double sum = 0;
		for (int j = 0;j < n;j++) {
			sum += pow(fabs(x[j] - y[j]),i);
		}
		printf("%lf\n",pow(sum,1.0/i));
	}
	for (i = 0;i < n;i++) {
		if (pm < fabs(x[i] - y[i]))pm = fabs(x[i] - y[i]);
	}
	printf("%lf\n", pm);

	return 0;
}


Measured memory_bytes: 3320
N=int(input())
count=0
T,X,Y=0,0,0
for i in range(N):
    t,x,y=map(int,input().split())
    if abs(x-X)+abs(y-Y)<=t-T and t%2==(x+y)%2:count+=1
    T,X,Y=t,x,y
print("Yes" if count==N else "No")

Measured memory_bytes: 49000
#include <bits/stdc++.h>
using namespace std;
 
#define faster ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define mp make_pair
#define mod 1000000007
#define qmod 998244353
#define endl "\n"
#define pb push_back
#define ff first
#define ss second
 
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
 
const int MOD = 1e9 + 7;
const int INF = 1e9 + 5;
const ll LINF = LLONG_MAX;

int main(){
	int a,b;
	cin>>a>>b;
	string s = to_string(a);
	string t = to_string(b);
	string x = s+t;
	int ans = stoi(x);
	for(int i=0;i<=100000;i++){
		if(i*i==ans){
			cout<<"Yes";
			return 0;
		}

	}
	cout<<"No";

}

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

using namespace std;
typedef long long ll;
const int MAX = 100010;
ll inv[MAX],fact[MAX],fi[MAX],mod = 1000000007;
vector<int> s;
void inverse(){
	int i;
	inv[1] = 1;
	for(i=2;i<MAX;i++){
		inv[i] = mod - (mod/i)*inv[mod%i]%mod;
	}
	fact[0] = fi[0] = 1;
	for(i=1;i<MAX;i++){
		fact[i] = fact[i-1]*i%mod;
		fi[i] = (fi[i-1]*inv[i])%mod;
	}
}

ll ex[210][100010] = {};
int main(){
	int i,j,n,x;
	cin >> n >> x;
	for(i=0;i<n;i++){
		int y; cin >> y;
		s.push_back(y);
	}
	inverse();
	sort(s.rbegin(),s.rend());
	for(i=0;i<=x;i++){
		ex[n][i] = i;
	}
	for(i=n - 1;i>=0;i--){
		for(j=0;j<=x;j++){
			(ex[i][j] += (inv[n - i]*ex[i + 1][j%s[i]]%mod + (mod + 1 - inv[n - i])*ex[i + 1][j]%mod)) %= mod;
		}
	}
	cout << ex[0][x]*fact[n]%mod << endl;
}

Measured memory_bytes: 160512
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define INF 1000000007
//0=48,A=65,a=97

int main() {
    int n;cin >> n;
    vector<int> t(n+1),x(n+1),y(n+1);
    t[0]=0;
    x[0]=0;
    y[0]=0;

    for(int i = 0; i < n; i++) {
        int p,q,r;cin >> p >> q >> r;
        t[i+1]=p;
        x[i+1]=q;
        y[i+1]=r;
    }

    for(int i = 0; i < n; i++) {
        int td=t[i+1]-t[i];
        int d=abs(x[i+1]-x[i])+abs(y[i+1]-y[i]);

        if(td>=d && (td-d)%2==0) continue;
        else{
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;

    return 0;
}

Measured memory_bytes: 4264
#include<bits/stdc++.h>
#define Mod 1000000007
#define Val(x) (((long long)x) % Mod)
using namespace std;
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n,m;
	cin >> n >> m;
	if(n < m)	swap(n,m);
	if(n - m > 1) {
		cout << 0 << endl;
	}
	else {
		int a = 1 , b = 1;
		for(int i=1;i<=n;i++)	a = Val(a * i);
		for(int i=1;i<=m;i++)	b = Val(b * i);
		int ans = Val(a * b);
		if(n == m)	ans = Val(ans * 2);
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
typedef long long ll;
typedef vector<vector<ll>> vvl;
typedef vector<ll> vl;
typedef vector<vector<char>> vvc;
typedef vector<char> vc;
typedef pair<ll,ll> pll;
typedef priority_queue<string> priquest;
typedef priority_queue<string,vector<string>,greater<string>> rpriquest;
ll max(ll x,ll y){
if(x>y)return x;
else return y;
}
ll min(ll x,ll y){
  return x+y-max(x,y);
}

const ll big=1000000007;
ll exp(ll x,ll y){
    if(y==0)return 1;
    if(x==1||x==0)return x;
    if(y%2==1)return (exp(x,y-1)*x)%big;
    ll t=exp(x,y/2);
    return (t*t)%big;
}
void chmin(ll a,ll b){
    if(a>b)a=b;
    return;
}

int main(){
  int s,w;cin >> s >> w;
  string ans;
  if(w>=s)ans="unsafe";
  else ans="safe";
  cout << ans << endl;
}

Measured memory_bytes: 3628
//Coded by tzc_wk
/*
数据不清空，爆零两行泪。
多测不读完，爆零两行泪。
边界不特判，爆零两行泪。
贪心不证明，爆零两行泪。
D P 顺序错，爆零两行泪。
大小少等号，爆零两行泪。
变量不统一，爆零两行泪。
越界不判断，爆零两行泪。
调试不注释，爆零两行泪。
溢出不 l l，爆零两行泪。
*/
#include <bits/stdc++.h>
using namespace std;
#define fi			first
#define se			second
#define fz(i,a,b)	for(int i=a;i<=b;i++)
#define fd(i,a,b)	for(int i=a;i>=b;i--)
#define foreach(it,v) for(__typeof(v.begin()) it=v.begin();it!=v.end();it++)
#define all(a)		a.begin(),a.end()
#define giveup(...) return printf(__VA_ARGS__),0;
#define fill0(a)	memset(a,0,sizeof(a))
#define fill1(a)	memset(a,-1,sizeof(a))
#define fillbig(a)	memset(a,0x3f,sizeof(a))
#define fillsmall(a) memset(a,0xcf,sizeof(a))
#define mask(a)		(1ll<<(a))
#define maskx(a,x)	((a)<<(x))
#define _bit(a,x)	(((a)>>(x))&1)
#define _sz(a)		((int)(a).size())
#define filei(a)	freopen(a,"r",stdin);
#define fileo(a)	freopen(a,"w",stdout);
#define fileio(a) 	freopen(a".in","r",stdin);freopen(a".out","w",stdout)
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#define put(x)		putchar(x)
#define eoln        put('\n')
#define space		put(' ')
#define y1			y_chenxiaoyan_1
#define y0			y_chenxiaoyan_0
#define int long long
typedef pair<int,int> pii;
inline int read(){
	int x=0,neg=1;char c=getchar();
	while(!isdigit(c)){
		if(c=='-')	neg=-1;
		c=getchar();
	}
	while(isdigit(c))	x=x*10+c-'0',c=getchar();
	return x*neg;
}
inline void print(int x){
	if(x<0){
		putchar('-');
		print(abs(x));
		return;
	}
	if(x<=9)	putchar(x+'0');
	else{
		print(x/10);
		putchar(x%10+'0');
	}
}
inline int qpow(int x,int e,int _MOD){
	int ans=1;
	while(e){
		if(e&1)	ans=ans*x%_MOD;
		x=x*x%_MOD;
		e>>=1;
	}
	return ans;
}
int n=read(),a[105];
int head[200005];
struct edge{
	int to,nxt,cap;
} e[30000005];
int ecnt=1;
inline void addedge(int u,int v,int f){
	e[++ecnt].to=v;e[ecnt].cap=f;e[ecnt].nxt=head[u];head[u]=ecnt;
	e[++ecnt].to=u;e[ecnt].cap=0;e[ecnt].nxt=head[v];head[v]=ecnt;
}
int dep[200005];
inline bool bfs(int s,int t){
	queue<int> q;
	memset(dep,-1,sizeof(dep));
	q.push(s);dep[s]=0;
	while(!q.empty()){
		int cur=q.front();q.pop();
		for(int i=head[cur];i;i=e[i].nxt){
			int to=e[i].to;
			if(dep[to]==-1&&e[i].cap){
				dep[to]=dep[cur]+1;
				q.push(to);
			}
		}
	}
	if(dep[t]!=-1)	return 1;
	return 0;
}
inline int dfs(int x,int t,int f){
	if(x==t)	return f;
	int ret=0;
	for(int i=head[x];i;i=e[i].nxt){
		int y=e[i].to;
		if(dep[y]==dep[x]+1&&e[i].cap){
			int w=dfs(y,t,min(f-ret,e[i].cap));
			e[i].cap-=w;
			e[i^1].cap+=w;
			ret+=w;
			if(ret==f)	return f;
		}
	}
	if(ret==0)	dep[x]=-1;
	return ret;
}
inline int Dinic(int s,int t){
	int tot=0;
	while(bfs(s,t))	tot+=dfs(s,t,0x3f3f3f3f);
	return tot;
}
signed main(){
	fz(i,1,n)	a[i]=read();
	fz(i,1,n){
		for(int j=i+i;j<=n;j+=i)	addedge(i,j,0x3f3f3f3f);
	}
	int sum=0,tot=0;
	fz(i,1,n){
		tot+=a[i];
		if(a[i]>0)	addedge(i,n+1,a[i]);
		if(a[i]<0)	addedge(0,i,-a[i]),sum-=a[i];
	}
	cout<<tot+(sum-Dinic(0,n+1))<<endl;
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define FOR(i, a, n) for(int (i) = (int)(a); (i) < (int)(n); ++(i))
#define FORe(i, a, n) for(int (i) = (int)(a); (i) <= (int)(n); ++(i))
#define rFOR(i, a, n) for(int (i) = (int)(n)-1; (i) >= (int)(a); --(i))
#define REP(i, n) FOR((i), 0, (n))
#define REPe(i, n) FORe((i), 0, (n))
#define rREP(i, n) rFOR((i), 0, (n))
#define rep(i, n) FOR((i), 0, (n))
#define all(v) (v).begin(), (v).end()
using namespace std;
using ll = long long;
using P = pair<int,int>;

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; }

int main() {
  int n;
  cin >> n;
  vector<int> a(n), b(n), c(n);
  REP(i, n) cin >> a[i];
  REP(i, n) cin >> b[i];
  REP(i, n) cin >> c[i];
  REP(i, n) a[i]--;
  int ans = 0;
  REP(i, n) {
    ans += b[a[i]];
    if (i!=n-1 && a[i+1]==a[i]+1) ans += c[a[i]]; 
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
//#define NDEBUG

#include <bits/stdc++.h>

#define StarBurstStream ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define iter(a) a.begin(), a.end()
#define riter(a) a.rbegin(), a.rend()
#define lsort(a) sort(iter(a))
#define gsort(a) sort(riter(a))
#define mp(a, b) make_pair(a, b)
#define pb(a) push_back(a)
#define pf(a) push_front(a)
#define pob pop_back()
#define pof pop_front()
#define F first
#define S second
#define printv(a, b) {bool pvaspace=false; \
for(auto pva : a){ \
    if(pvaspace) b << " "; pvaspace=true;\
    b << pva;\
}\
b << "\n";}
#define pii pair<int, int>
#define pll pair<ll, ll>
#define modadd(a, b) (((a % MOD) + (b % MOD)) % MOD)
#define modtimes(a, b) (((a % MOD) * (b % MOD)) % MOD)

//#define TEST

typedef long long ll;
typedef unsigned long long ull;

using namespace std;

const ll MOD = 1000000007;
const ll MAX = 2147483647;

int main(){
    StarBurstStream

    int n, m;
    cin >> n >> m;

    vector<vector<int>> g(n);
    vector<int> in(n);
    for(int i = 0; i < m; i++){
        int x, y;
        cin >> x >> y;
        x--; y--;
        g[x].pb(y);
        in[y]++;
    }

    queue<int> q;
    for(int i = 0; i < n; i++) if(in[i] == 0) q.push(i);

    int ans = 0;
    vector<int> dp(n);
    while(!q.empty()){
        for(auto i : g[q.front()]){
            in[i]--;
            if(in[i] == 0) q.push(i);
            dp[i] = max(dp[i], dp[q.front()] + 1);
            ans = max(ans, dp[i]);
        }
        q.pop();
    }

    cout << ans << "\n";

    return 0;
}

Measured memory_bytes: 6528
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = Integer.parseInt(sc.next());
		int b = Integer.parseInt(sc.next());

		int d = a/b ;
		int r = a%b ;

		double c = (double) a;
		double e = (double) b;

		double f = c / e;

		System.out.print(d +" "+r+" ");
		System.out.println(String.format("%.5f",f));
	}
}

Measured memory_bytes: 26516
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
			String s = sc.next();
			System.out.println(s.charAt(2) == s.charAt(3) && s.charAt(4) == s.charAt(5) ? "Yes" : "No");

		}
	}

	/**
	 * 最小公倍数
	 */
	static long lcm(long a, long b) {
		long temp;
		long c = a;
		c *= b;
		while ((temp = a % b) != 0) {
			a = b;
			b = temp;
		}
		return c / b;
	}

	/**
	 * 最大公約数
	 */
	static long gcd(long a, long b) {
		long temp;
		while ((temp = a % b) != 0) {
			a = b;
			b = temp;
		}
		return b;
	}
}


Measured memory_bytes: 22868
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
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; }
//(a+b-1)/b
//priority_queue<ll, vector<ll>, greater<ll>> q;
using pl = pair<ll,ll>;
pl g[100100][0];
ll V,E,r; 


signed main(){
    ll n; cin >> n;
    ll a = 1,b = n - 1;
    ll ans = MOD;
    while(a < n){
        ll cnt = 0;
        string s = to_string(a);
        string t = to_string(b);
        rep(i,0,s.size())cnt += (s[i] - '0');
        rep(i,0,t.size())cnt += (t[i] - '0');
        chmin(ans,cnt);
        a++; b--;
    }
    cout << ans << endl;


	return 0;
}


Measured memory_bytes: 3688
<?php
list($n, $a, $b) = explode(" ", trim(fgets(STDIN)));
if(($b-$a)%2===0){
	echo ($b-$a)/2 . "\n";
}else{
	echo min($n-$b, $a-1) + 1 + ($b-$a-1)/2 . "\n";
}

Measured memory_bytes: 4604
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vii = vector<vi>;
using vs = vector<string>;
using in6 = int64_t;
using ind = double;
using pii = pair<int,int>;
using psi = pair<string,int>;
using vpi = vector<pii>;
using vps = vector<psi>;
#define rep(i, n) for (in6 i = 0; i < (in6)(n); i++)
#define repa(i,a,n) for(in6 i = a; i < (in6)(n); i++)
#define repdown(i,n) for(in6 i = n; i > 0; i--)
#define kyun ios::sync_with_stdio(false)
#define hinata cout << "\n"
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define inf 2147483647
#define dset(n) cout << fixed << setprecision(n)

void yes() {
  cout << "Yes";
}

void no() {
  cout << "No";
}

int main() {
  kyun;
  int a;
  cin >> a;
  vs data(a);
  rep(i,a) cin >> data[i];
  set<string> st;
  rep(i,a) st.insert(data[i]);
  cout << st.size();
  hinata;
}

Measured memory_bytes: 25096
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <functional>

using namespace std;

#define fst first
#define scd second
#define PB push_back
#define MP make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define omajinai ios::sync_with_stdio(false);cin.tie(0)
#define rep(i,x) for(int i=0;i<(int)(x);++i)
#define rep1(i,x) for(int i=1;i<=(int)(x);++i)

using ll=long long;
using ld=long double;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int, int>;
using vpii=vector<pii>;

template<class T,class U>ostream&operator<<(ostream&os,const pair<T,U>p){os<<"("<<p.fst<<", "<<p.scd<<")";return os;}
template<class T>ostream&operator<<(ostream&os,const vector<T>v){rep(i,v.size()){if(i)os<<", ";os<<v[i];}return os;}
template<typename T>T&max(T&a,T&b){if(a>=b)return a;return b;}
template<typename T>T&min(T&a,T&b){if(a < b)return a;return b;}
template<typename T>bool chmax(T&a,T b){if(a < b){a=b;return true;}return false;}
template<typename T>bool chmin(T&a,T b){if(a > b){a=b;return true;}return false;}
int in(){int a;scanf("%d",&a);return a;}
ll lin(){ll a;scanf("%lld",&a);return a;}

constexpr int inf = 1e9;
constexpr ll linf = 3e18;
constexpr double eps = 1e-9;

int ans[301];
int item[1010][3], R[1010];

int main()
{
    while (true) {
        int a = in(), b = in(), c = in();

        if (a == 0) return 0;

        fill_n(ans, a+b+c+1, 2);

        int N = in();

        rep(i, N) {
            rep(j, 3) item[i][j] = in() - 1;
            R[i] = in();

            if (R[i]) {
                rep(j, 3) ans[item[i][j]] = 1;
            }
        }

        rep(i, N) {
            int cnt = 0;
            rep(j, 3) cnt += ans[item[i][j]] == 1;

            if (cnt == 2) {
                rep(j, 3) if (ans[item[i][j]] != 1) ans[item[i][j]] = 0;
            }
        }

        rep(i, a+b+c) printf("%d\n", ans[i]);
    }
}

Measured memory_bytes: 3180
#import <Foundation/Foundation.h>
#import <stdarg.h>

@interface StdIO : NSObject
+(NSString*)stringFromStdIn;
+(NSArray*)stringsFromStdInSeparatedByString:(NSString*)separator;
+(NSArray*)numbersFromStdInSeparatedByString:(NSString*)separator;
+(void)puts:(NSString*)format, ...;
@end

@implementation StdIO
+(NSString*)stringFromStdIn
{
	return [[NSString alloc] initWithData:[[NSFileHandle fileHandleWithStandardInput] availableData] encoding:NSUTF8StringEncoding];
}

+(NSArray*)stringsFromStdInSeparatedByString:(NSString*)separator
{
	return [[StdIO stringFromStdIn] componentsSeparatedByString:separator];
}

+(NSArray*)numbersFromStdInSeparatedByString:(NSString*)separator
{
	NSArray *strings = [StdIO stringsFromStdInSeparatedByString:separator];
	NSMutableArray *numbers = [NSMutableArray array];
	for (NSString *string in strings) {
		[numbers addObject: [NSNumber numberWithInteger: [string integerValue]]];
	}
	return numbers;
}

+(void)puts:(NSString*)format, ...
{
	va_list arguments;
	va_start(arguments, format);
	NSString *stdoutString = [[NSString alloc] initWithFormat:format arguments:arguments];
	
	NSFileHandle *fileHandle = [NSFileHandle fileHandleWithStandardOutput];
	[fileHandle writeData:[stdoutString dataUsingEncoding: NSUTF8StringEncoding]];
	[fileHandle writeData:[@"\n" dataUsingEncoding: NSUTF8StringEncoding]];
	[fileHandle closeFile];	
	
	va_end(arguments);	
}
@end



int main(int argc, const char * argv[]) {
	@autoreleasepool {
		NSArray *numbers = [StdIO numbersFromStdInSeparatedByString:@" "];
		NSInteger i = [[numbers objectAtIndex:0] integerValue];
		NSInteger j = [[numbers objectAtIndex:1] integerValue];
		[StdIO puts:(i*j % 2 == 0) ? @"Even" : @"Odd"];
	}

	return 0;
}

Measured memory_bytes: 9632
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < (n); ++i)
#define All(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()   //reverse
#define strall(v) (v).cbegin(),(v).cend() //const_itterator
#define IN(a, b, x) (a<=x&&x<b)
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<ll>>;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template<typename t, typename u, typename Comp=less<>>
bool chmax(t& xmax, const u& x, Comp comp={}) { if(comp(xmax, x)) { xmax = x; return true; } return false;}
template<typename t, typename u, typename Comp=less<>>
bool chmin(t& xmin, const u& x, Comp comp={}) { if(comp(x, xmin)) { xmin = x; return true;} return false;}
const int INF = 1e9;
const ll infl = ll(1e18)+5;

/*
*ios::sync_with_stdio(false);
*cin.tie(0);
*/


int main() {
  map<ll,ll> mp;
  ll N;cin >> N;

  rep(i,N) {
    int a;
    cin >> a;
    mp[a]++;
  }
  ll ans = 0;
  for(auto m:mp){
    if(m.first > m.second) ans += m.second;
    else ans+=(m.second-m.first); 
  }
  cout << ans << endl;
}

Measured memory_bytes: 6272
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

#define ll long long
#define ld long double
typedef vector <ll> vi;                 // Vector of long long
typedef vector <vi> vvi;                // Vector of vi
typedef vector <pair<ll,ll>> ii;        // Vector of pairs
#define ff first                        // For pairs
#define ss second                       // For pairs
#define sz(a) int((a).size())           // Function to determine size of any container
#define pb push_back                    // Pushback to vector
#define mp make_pair                    // Makes pairs to be stored as pair
#define all(c) (c).begin(), (c).end()   // Mainly used by me in sorting
// ordered_set adds two new functions to set - (set).find_by_order([kth element based on zero indexing]) and order_of_key()
// order_of_key returns number of elements less that parameter. If element exists, that order is its index
#define ordered_set tree < ll ,  null_type ,  less<ll> ,  rb_tree_tag ,  tree_order_statistics_node_update >
#define MAX 3005

ll N;
vector<ld> P;
ld dp[MAX][MAX];

ld solve(ll n, ll l)
{   
    if (l > (N / 2))
        return 0;
    if (n < 0)
        return 1;
    
    if (dp[n][l] == -1)
        dp[n][l] = (P[n] * solve(n - 1, l)) + ((1 - P[n]) * solve(n - 1, l + 1));
    return dp[n][l];
}

int main(void)
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    for (int i = 0; i < MAX; i++)
        for (int j = 0; j < MAX; j++)
            dp[i][j] = -1;

    cin >> N;
    P.resize(N);
    for (int i = 0; i < N; i++)
        cin >> P[i];

    cout << fixed << setprecision(10) << solve(N - 1, 0) << "\n"; 
}

Measured memory_bytes: 141696
#include <iostream>
using namespace std;
char judge(int, int, int);

int main() {
	int n, pm, pe, pj;
	while (true) {
		cin >> n;
		if (n == 0) break;

		for (int i = 0;i < n;i++) {
			cin >> pm >> pe >> pj;
			cout << judge(pm, pe, pj) << endl;
		}
	}
}

char judge(int math, int eng, int jap) {
	float twoave = (math + eng) / 2;
	float ave = (math + eng + jap) / 3;
	if (math == 100 || eng == 100 || jap == 100) {
		return 'A';
	} else if (twoave >= 90) {
		return 'A';
	} else if (ave >= 80) {
		return 'A';
	} else if (ave >= 70) {
		return 'B';
	} else if (ave >= 50 && (math >= 80 || eng >= 80)) {
		return 'B';
	} else {
		return 'C';
	}
}

Measured memory_bytes: 1152
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int n,a[300030],sumb,sumw;
bool check(int w)
{
	int mi=0,sum=0;
	for(int i=1;i<=n;++i)
	{
		if(i&1)sum+=a[i];
		else
		{
			if(sum-mi>=w)mi=min(mi,sum-a[i]);
			sum-=a[i];
		}
	}
	return sum-mi>=w;
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;++i)scanf("%d",&a[i]);
	for(int i=1;i<=n;i+=2)sumb+=a[i];
	for(int i=2;i<=n;i+=2)sumw+=a[i];	
	if(n%2==0)
	{
		if(sumb>sumw)printf("%d %d\n",sumb,sumw);
		else printf("%d %d\n",sumw,sumb);
		return 0;
	}
	int l=0,r=sumb,mid;
	while(l<r)
	{
		mid=l+r+1>>1;
		if(check(mid))l=mid;
		else r=mid-1;
	}
	printf("%d %d\n",sumw+l,sumb-l);
	return 0;
}


Measured memory_bytes: 1280
import java.util.Scanner;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int inputNum1 = sc.nextInt();
		int intCount = 0;

		for(int i = a; i <= b; i++) {
			int intYakusuu = inputNum1 % i;
			if(intYakusuu == 0) {
				intCount++;
			}
		}
		System.out.println(intCount);
	}
}

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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl




typedef long long ll;
const ll mod = 1e9+7;
const int maxn = 2e5 + 5;



int n, m;
vector<int> g[maxn];

int dp[maxn];

int solve(int at) {
    if (~dp[at]) return dp[at];
    dp[at] = 1;
    for (int to: g[at]) {
	dp[at] = max(dp[at], 1+solve(to));
    }

    return dp[at];
}

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



    cin>>n>>m;
    
    for (int i=0; i<m; i++) {
	int u,v; cin>>u>>v;
	g[u].push_back(v);
    }

    for (int i=1; i<=n; i++) {
	dp[i]=-1;
    }

    for (int i=1; i<=n; i++) {
	if (dp[i]==-1) {
	    dp[i]=solve(i);
	}
    }


    int res=0;
    for (int i=1; i<=n; i++) {
	res=max(res,dp[i]);
    }

    res--;

    out(res);
    return 0;
}


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

#define dbg(a)	cerr << __LINE__ << ": " << #a << " = " << a << '\n'

int main(){
	long long n;	cin >> n;
	long long ans = n*(n+1)/2;
	long long three = n/3;
	three = 3*three*(three+1)/2;
	long long five = n/5;
	five = 5*five*(five+1)/2;
	long long fifteen = n/15;
	fifteen = 15 * fifteen * (fifteen+1)/2;
	cout << ans - three - five + fifteen << endl;
	return 0;
}

Measured memory_bytes: 3648
#include<iostream>
#include<iomanip>
#include<math.h>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<string>
#include<bitset>
#define INF 1000000000ll
#define MOD 1000000007ll
#define EPS 1e-10
#define REP(i,m) for(long long i=0; i<m; i++)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define DUMP(a) for(long long dump=0; dump<(ll)a.size(); dump++) { cout<<a[dump]; if(dump!=(ll)a.size()-1) cout<<" "; else cout<<endl; }
#define ALL(v) v.begin(),v.end()
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef long double ld;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n,k;
	cin>>n>>k;
	vector<ll> a(n);
	REP(i,n) cin>>a[i];
	vector<ll> c(n+1,0);
	REP(i,n) c[a[i]]++;
	ll tmp=0;
	REP(i,n+1) if(c[i]!=0) ++tmp;
	ll diff=tmp-k;
	sort(ALL(c));
	ll ans=0;
	REP(i,n+1) {
		if(c[i]==0) continue;
		if(diff>0) {
			diff--;
			ans+=c[i];
		}
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 3456
import java.math.BigDecimal;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while (true) {
			int n = sc.nextInt();
			if (n == 0) {
				sc.close();
				break;
			}

			double[][] stations = new double[n][4];
			for (int i = 0; i < stations.length; i++) {
				stations[i][0] = sc.nextDouble();
				stations[i][1] = sc.nextDouble();
				stations[i][2] = sc.nextDouble();
				stations[i][3] = sc.nextDouble();
			}

			PriorityQueue<Edge> edges = new PriorityQueue<Edge>();
			for (int i = 0; i < n; i++) {
				for (int j = i + 1; j < n; j++) {
					double x1 = stations[i][0];
					double x2 = stations[j][0];
					double y1 = stations[i][1];
					double y2 = stations[j][1];
					double z1 = stations[i][2];
					double z2 = stations[j][2];
					double r1 = stations[i][3];
					double r2 = stations[j][3];

					double dist = Math.sqrt(Math.pow((x1 - x2), 2)
							+ Math.pow((y1 - y2), 2) + Math.pow((z1 - z2), 2))
							- r1 - r2;
					dist = Math.max(dist, 0);
					edges.add(new Edge(dist, i, j));
				}
			}

			// クラスカル法
			UnionFind uf = new UnionFind(n);
			double cost = 0;
			while (!edges.isEmpty()) {
				Edge e = edges.poll();
				if (!uf.same(e.from, e.to)) {
					cost += e.weight;
					uf.unite(e.from, e.to);
				}
			}

			BigDecimal bd = new BigDecimal(String.valueOf(cost));
			System.out.println(bd.setScale(3, BigDecimal.ROUND_HALF_UP));

		}
	}
}

class UnionFind {
	int[] par;

	UnionFind(int n) {
		par = new int[n];
		for (int i = 0; i < n; i++)
			par[i] = i;
	}

	public int find(int x) {
		if (par[x] == x)
			return x;
		return par[x] = find(par[x]);
	}

	public Boolean same(int x, int y) {
		return find(x) == find(y);
	}

	public void unite(int x, int y) {
		if (find(x) == find(y))
			return;
		par[find(x)] = find(y);
	}
}

class Edge implements Comparable<Edge> {
	double weight;
	int from, to;

	Edge(double w, int f, int t) {
		this.weight = w;
		this.from = f;
		this.to = t;
	}

	@Override
	public int compareTo(Edge edge) {
		// 昇順
		if (this.weight > edge.weight) {
			return 1;
		} else if (this.weight == edge.weight) {
			return 0;
		} else {
			return -1;
		}
	}
}

Measured memory_bytes: 59712
#include <stdio.h>

int main()
{
        char str[10];

        while ( scanf( "%s", str ) == 1 ) {
                if ( str[0] == str[1] && str[0] == str[2] && str[0] != 's' ) { printf( "%c\n", str[0] ); }
                else if ( str[3] == str[4] && str[3] == str[5] && str[3] != 's' ) { printf( "%c\n", str[3] ); }
                else if ( str[6] == str[7] && str[6] == str[8] && str[6] != 's' ) { printf( "%c\n", str[6] ); }
                else if ( str[0] == str[3] && str[0] == str[6] && str[0] != 's' ) { printf( "%c\n", str[0] ); }
                else if ( str[1] == str[4] && str[1] == str[7] && str[1] != 's' ) { printf( "%c\n", str[1] ); }
                else if ( str[2] == str[5] && str[2] == str[8] && str[2] != 's' ) { printf( "%c\n", str[2] ); }
                else if ( str[0] == str[4] && str[0] == str[8] && str[0] != 's' ) { printf( "%c\n", str[0] ); }
                else if ( str[2] == str[4] && str[2] == str[6] && str[2] != 's' ) { printf( "%c\n", str[2] ); }
                else { printf( "d\n" ); }
        }
        return 0;
}



Measured memory_bytes: 2048
n = int(input())
an = [int(i) for i in input().split()]
bn = [int(i) for i in input().split()]
x,y = 0,0
for a,b in zip(an,bn):
  if a >= b:
    x += a-b
  else:
    y += (b-a)//2
print('Yes' if y >= x else 'No')

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

int check(string s, string t, int idx){
    // cout<<"Cheking started for index "<<idx<<endl;
    for (int i=0; i<t.size(); i++){
        if (s[idx+i]!='?' && s[idx+i]!=t[i])return 0;
        // idx++;
    }
    // cout<<"Check is successful"<<endl;
    return 1;
}
int main()
{
    string s, t;
    cin>>s>>t;
    int n = s.size(), m = t.size();
    int flag = 0, idx=-1;
    if (m>n){
        cout<<"UNRESTORABLE"<<endl;
        return 0;
    }
    // int flag = 0;
    for (int i=0; i<n; i++){
        if (s[i]!='?' && s[i]!=t[0])continue;
        if (n-i < m)break;
        // cout<<"calling check"<<endl;
        flag = check(s, t, i);
        // cout<<"At index "<<i<<" check is "<<check<<endl;
        if (flag == 1){
            idx = i;
        }
    }
    if (idx == -1){
        cout<<"UNRESTORABLE"<<endl;
    }
    else{
        for (int j=idx; j<idx+m; j++)s[j] = t[j-idx];
            for (int j=0; j<n; j++)if (s[j]=='?')s[j]='a';

        cout<<s<<endl;
    }
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll, ll> Pll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repn(i, n) for (int i = 0; i <= (int)(n); i++)
#define srep(i, l, n) for (int i = l; i < (int)(n); i++)
#define srepn(i, l, n) for (int i = l; i <= (int)(n); i++)
#define pb push_back 
#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
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; }

const int MOD = 1000000007;
const int INF = 1e9;
#define PI 3.14159265369;
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};


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

	int h, w;
	cin >> h >> w;
	char grid[h][w];
	int dis[h][w];
	for(int i = 0; i < h; ++i) {
		for(int j = 0; j < w; ++j) {
			dis[i][j] = INF;
		}
	}
	queue<P> Q;
	for(int i = 0; i < h; ++i) {
		for(int j = 0; j < w; ++j) {
			cin >> grid[i][j];
			if(grid[i][j]=='#') Q.push(P(i,j)), dis[i][j] = 0;
		}
	}
	while(!Q.empty()) {
		P p = Q.front();
		Q.pop();
		int x = p.first;
		int y = p.second;
		for(int i = 0; i < 4; i++){
			int nx = x + dx[i];
			int ny = y + dy[i];
			if(nx>=0&&nx<h&&ny>=0&&ny<w&&grid[nx][ny]=='.'&&dis[nx][ny]==INF) {
				dis[nx][ny] = dis[x][y] + 1;
				Q.push(P(nx,ny));
			}
		}
	}
	int ans = 0;
	for(int i = 0; i < h; ++i) {
		for(int j = 0; j < w; ++j) {
			chmax(ans, dis[i][j]);
		}
	}
	cout << ans << endl;
}

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

int main(){
  long long int n,k;
  cin >> n >> k;
  long long int ans=1001002003004005006;
  if(n==k){
    cout << 0 << endl;
  }else if(n>k){
    long long int x=n%k;
    ans=min(x,abs(x-k));
    cout << ans << endl;
  }else{
    ans=min(n,abs(n-k));
    cout << ans << endl;
  }
}

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

int main(){
  int N,sum=0;
  cin>>N;
  for(int i=0;i<N;i++){
    int A;
    cin>>A;
    if(A%2==0)
      sum++;
  }
if(sum==N)
  cout<<"second"<<endl;
else
  cout<<"first"<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<string.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
long long int mod=1e9+7;
bool debug=false;
typedef long long ll;
int main(){
	int n;
	cin>>n;
	vector<int>a(n);
	rep(i,n)cin>>a[i];
	double sum=0;
	rep(i,n){
		sum+=(double)1/(double)a[i];
	}
	printf("%.7lf\n",1.0/sum);

	return 0;
}

Measured memory_bytes: 256