akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;


void solve(long long A, long long B, long long C, long long D){
    if ((A + B) > (C + D)) cout << "Left" << endl;
    else if ((A + B) < (C + D)) cout << "Right" << endl;
    else cout << "Balanced" << endl; 
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    long long C;
    scanf("%lld",&C);
    long long D;
    scanf("%lld",&D);
    solve(A, B, C, D);
    return 0;
}


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

using namespace std;

#define INF 1e9
#define rep(i,a,n) for(ll i=(a);i<(n);i++)
#define repv(i,a,n) for(ll i=(n)-1;i>=a;i--)
#define ll long long int
#define endl "\n"
#define pb push_back

vector<int> adj[1000005];
bool vis[1000005];

void dfs(int i) {
	vis[i] = true;
	for(auto child:adj[i]) {
		if(!vis[child])
			dfs(child);
	}
}

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

   	int n, m;
   	cin >> n >> m;
   	rep(i,0,m) {
   		int a, b;
   		cin >> a >> b;
   		adj[a].pb(b);
   		adj[b].pb(a);
   	}
   	int c = 0;
   	rep(i,1,n+1) {
   		if(!vis[i]) {
   			c++;
   			dfs(i);
   		}
   	}
   	c--;
   	cout << c;
}



Measured memory_bytes: 30696
n = int(input())
L = list(map(int, input().split()))
L = sorted(L)
ans = 0

for i in range(n):
    for j in range(i,n):
        for k in range(j,n):
            if L[i]!=L[j] and L[j]!=L[k] and L[k]!=L[i]:
                if L[k] < L[i] + L[j]:
                    ans += 1

print(ans)


Measured memory_bytes: 68084
fn main() {
	let mut s = String::new();
	use std::io::Read;
	std::io::stdin().read_to_string(&mut s).unwrap();
	let mut s = s.split_whitespace();
	let n: usize = s.next().unwrap().parse().unwrap();
	let mut a: Vec<_> = (0..n).map(|i| {
		let x: i32 = s.next().unwrap().parse().unwrap();
		let y: i32 = s.next().unwrap().parse().unwrap();
		(x, y, i)
	}).collect();
	let mut edges = vec![vec![]; n];
	a.sort_by_key(|a| a.0);
	for i in 0..n - 1 {
		let (ax, _, ai) = a[i];
		let (bx, _, bi) = a[i + 1];
		let d = bx - ax;
		edges[ai].push((bi, d));
		edges[bi].push((ai, d));
	}
	a.sort_by_key(|a| a.1);
	for i in 0..n - 1 {
		let (_, ay, ai) = a[i];
		let (_, by, bi) = a[i + 1];
		let d = by - ay;
		edges[ai].push((bi, d));
		edges[bi].push((ai, d));
	}

	let mut ans = 0;
	let mut used = vec![false; edges.len()];
	let mut q = std::collections::BinaryHeap::new();
	q.push((0, 0));
	while let Some((cost, to)) = q.pop() {
		let cost = -cost;
		if used[to] {
			continue;
		}
		used[to] = true;
		ans += cost as i64;
		for &(to, cost) in edges[to].iter() {
			q.push((-cost, to));
		}
	}
	println!("{}", ans);
}


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

int main()
{
    
    int i;
    int j;
    int n;
    int m;
    int point;
    int max=0;
    
    cin >> n;
    vector<string>codeN(n);
    for(i=0;i<n;i++)cin >> codeN[i];
    
    cin >> m;
    vector<string>codeM(m);
    for(i=0;i<m;i++)cin >> codeM[i];
    
    for(i=0;i<n;i++)
    {
        point = 0;
        
        for(j=0;j<n;j++)
        {
            if(codeN[i] == codeN[j])
            {
                point++;
            }
        }
        
        for(j=0;j<m;j++)
        {
            if(codeN[i] == codeM[j])
            {
                point--;
            }
        }
        
        if(max < point)
        {
            max = point;
        }
    }
    
    cout << max << endl;
        
}

Measured memory_bytes: 256
#include <stdio.h>
 
int main(){
   int n,m,c[31],i,j,k,a;
    
   scanf("%d %d",&n,&m);
   for (i=1;i<=m;i++) c[i]=0;
   for (i=0;i<n;i++) {
      scanf("%d",&k);
      for (j=0;j<k;j++) {
         scanf("%d",&a);
         c[a]++;
      }
   }
   k=0;
   for (i=1;i<=m;i++)
      if (c[i]==n) k++;
   printf("%d\n",k);
   return 0;
}


Measured memory_bytes: 128
#include<stdio.h>

int main(){
	int x;
	int y;
	int z;
	
	scanf("%d %d %d",&x,&y,&z);
	int total = x+y+z;
	
	if (total >=22){
		printf("bust\n");
	}
	else{
	
		printf("win\n");
	}
	
	
	
	
	
	
	
	return 0;
}

Measured memory_bytes: 3156
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
 
int n;
int array[100];
int main(){
    int i;
    cin >> n;
    for(int i=0;i<n;i++){
        cin >> array[i];
    }
    cout << array[0];
    for(int i=1;i<n;i++){
        cout << ' ' << array[i];
    }
    cout << endl;
    for(int j=1;j<n;j++){
        int key = array[j];
        i = j-1;
        while(i>=0 && array[i] > key){
            array[i+1] = array[i];
            i--;
        }
        array[i+1] = key;
        cout << array[0];
        for(int k=1;k<n;k++){
            cout << ' ' << array[k];
        }
        cout << endl;
    }
}

Measured memory_bytes: 3092
use std::io;
use std::cmp;
use std::collections::BinaryHeap;
use std::collections::HashMap;
use std::collections::HashSet;
use std::f64::consts::PI;

fn read_line() -> String {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).ok();
    buf
}

fn main() {
    let line: Vec<usize> = read_line().split_whitespace().map(|s| s.parse().unwrap()).collect();
    let k = line[0];
    let mut a: Vec<u64> = read_line().split_whitespace().map(|s| s.parse().unwrap()).collect();
    a.reverse();

    let mut min = 2;
    let mut max = 2;
    for i in 0..k {
        let x = (min + a[i] - 1) / a[i] * a[i]; 
        let y = max / a[i] * a[i]; 
        if min <= x && x <= y && y <= max {
            min = x;
            max = y + a[i] - 1;
        } else {
            min = 0; max = 0;
            break;
        }
    }
    if min > 0 && max > 0 {
        println!("{} {}", min, max);
    } else {
        println!("-1");
    }
}


Measured memory_bytes: 8444
#include <bits/stdc++.h>
#include<ext/pb_ds/hash_policy.hpp>
#include<ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long LL;
typedef unsigned long long uLL;
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
LL z = 1;
int read(){
	int x, f = 1;
	char ch;
	while(ch = getchar(), ch < '0' || ch > '9') if(ch == '-') f = -1;
	x = ch - '0';
	while(ch = getchar(), ch >= '0' && ch <= '9') x = x * 10 + ch - 48;
	return x * f;
}
int ksm(int a, int b, int p){
	int s = 1;
	while(b){
		if(b & 1) s = z * s * a % p;
		a = z * a * a % p;
		b >>= 1;
	}
	return s;
}
int x[5], y[5], a, b;
int main(){
	int i, j, n, m, p, q;
	for(i = 1; i <= 2; i++) x[i] = read(), y[i] = read();
	p = x[2] - x[1];
	q = y[2] - y[1];
	x[3] = x[2] - q, y[3] = y[2] + p;
	x[4] = x[3] - p, y[4] = y[3] - q;
	printf("%d %d %d %d", x[3], y[3], x[4], y[4]);
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void){
   int N;
   int cnt=0;
   scanf("%d",&N);
   char S[N];
   scanf("%s",S);
   for(int i=0;i+2<N;i++){
      if(S[i]==65&&S[i+1]==66&&S[i+2]==67){
         cnt++;
      }
   }
   printf("%d",cnt);
   return 0;
}


Measured memory_bytes: 1732
import sys
 
s = ""
for line in sys.stdin:
    s += line
 
char = "abcdefghijklmnopqrstuvwxyz"
 
for c in char:
    n1 = s.count(c)
    n2 = s.count(c.upper())
    print(c + " : " + str(n1 + n2))


Measured memory_bytes: 5560
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<iomanip>
#include<set>
#include<bitset>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define brep(index,num) for(int index=num-1;index>=0;index--)
#define brep1(index,num) for(int index=num;index>0;index--)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
int main(){
	int N,M,A[100001];
	ll costsum=0;
	ll rui[200002]={};
	scan(N>>M);
	rep(i,N){
		scan(A[i]);
		A[i]--;
	}
	rep(i,N-1){
		costsum+=(A[i+1]+M-A[i])%M;
		int beg=A[i],las=A[i+1];
		if(las<beg){
			las+=M;
		}
		rui[beg+2]++;
		rui[las+1]-=las-beg;
		rui[las+2]+=las-beg-1;
	}
	rep1(i,2*M+1){
		rui[i]+=rui[i-1];
	}
	rep1(i,2*M+1){
		rui[i]+=rui[i-1];
	}

	ll reducemax=0;
	rep(i,M){
		reducemax=max(reducemax,rui[i]+rui[i+M]);
	}
	prin(costsum-reducemax);
	return 0;
}


Measured memory_bytes: 2176
#include <bits/stdc++.h>
#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define sort(a) sort((a).begin(),(a).end())
#define rev(a) reverse((a).begin(),(a).end())
using db = double;
using namespace std;
typedef long long ll;


int main() {
  int n;
  cin >> n;
  vector<int> d(n);
  rep(i,n) cin >> d[i];
  sort(d);
  int cnt = 0;
  rep(i,n-1) {
    if (d[i] == d[i+1]) continue;
    cnt++;
  }
  cnt++;
  cout << cnt << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cstdlib>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const long long INF = 1LL << 60;

int N;
long long h[100010];

long long dp[100010];

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

    for (int i = 0; i < 100010; ++i) dp[i] = INF;

    dp[0] = 0;

    for (int i = 1; i < N; ++i) {
        chmin(dp[i], dp[i - 1] + abs(h[i] - h[i - 1]));
        if (i > 1) chmin(dp[i], dp[i - 2] + abs(h[i] - h[i - 2]));
    }

    cout << dp[N-1] << endl;
}

Measured memory_bytes: 1792
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)



ll f(ll x, ll y) {
    if(x == 0 || y == 0) return 0;
    
    if(x < y && y % x == 0) return y / x * x * 2 - x;
    if(x > y && x % y == 0) return x / y * y * 2 - y;
    
    if(x < y) return f(x, y - y / x * x) + y / x * x * 2;
    else if(x > y) return f(x - x / y * y, y) + x / y * y * 2;
    else return x;
}

int main() {
    ll n, x;
    cin >> n >> x;
    cout << f(x, n - x) + n << endl;
}


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

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;
Node treeSearch(Node u, int k){
  while(u!=NIL && k!=u->key){
    if(k<u->key){
      u=u->left;
    }
    else{
      u=u->right;
    }
  }
  return u;
}


void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x!=NIL){
    y=x;
    if(z->key < x->key){
      x=x->left;
    }
    else{
      x=x->right;
    }
  }
  z->parent=y;
  if(y==NIL){
    root=z;
  }
  else if(z->key < y->key){
      y->left=z;
    }
    else{
      y->right=z;
    }
  }

void inorder(Node u){
  if(u==NIL){
    return;
  }
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);
}
void preorder(Node u){
  if(u==NIL){
    return;
  }
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }

  return 0;
}



Measured memory_bytes: 20460
#include <iostream>
#include <iomanip>
#include <cmath>
#include <vector>
#include <queue>
#include <limits>
#include <algorithm>
#include <string>
#include <set>
#include <map>
using namespace std;

int main()
{
	string S, T;
	cin >> S >> T;

	int32_t N = S.size();
	map<char, char> _map, _map_r;
	bool res = true;
	for (int32_t i = 0; i < N; i++) {
		if (_map.count(S[i]) < 1) {
			if (_map_r.count(T[i]) < 1) {
				_map[S[i]] = T[i];
				_map_r[T[i]] = S[i];
			} else if (_map_r[T[i]] != S[i]) {
				res = false;
				break;
			}
		} else if (_map[S[i]] == T[i]) {
			continue;
		} else {
			res = false;
		}
	}

	cout << (res ? "Yes" : "No") << endl;

	return 0;
}


Measured memory_bytes: 776
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <utility>

using namespace std;
typedef long long ll;

int main() {
  int h, w;
  cin >> h >> w;
  vector<string> v(h);
  bool hodd =false, wodd=false;
  if(h%2==1)
    hodd = true;
  if(w%2)
    wodd = true;

  for(int i=0;i<h;i++) {
    string s;
    cin >> v[i];
  }
  vector<int> cnt_char(26, 0);
  for(int i=0;i<h;i++) {
    for(int j=0;j<w;j++) {
      cnt_char[v[i][j]-'a']++;
    }
  }
  int cnt_two=0;
  int cnt_one=0;
  for(int i=0;i<26;i++) {
    if(cnt_char[i]%4 == 2) cnt_two++;
    else if(cnt_char[i]%2==1) cnt_one++;
  }
  bool ans;
  if(!hodd && !wodd) {
    if(cnt_one + cnt_two > 0) ans = false;
    else ans = true;
  } else if(!hodd && wodd) {
    if(cnt_one > 0) ans = false;
    else{
      if(cnt_two > h/2) ans = false;
      else ans = true;
    }
  } else if(hodd && !wodd) {
    if(cnt_one > 0) ans = false;
    else {
      if(cnt_two > w/2) ans = false;
      else ans = true;
    }
  } else {
    if(cnt_one <= 1 && cnt_two <= (h+w-2)/2)
      ans = true;
    else
      ans = false;
  }
  if(ans)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;

}


Measured memory_bytes: 256
import itertools

N, M, R = map(int, input().split())
r = list(map(lambda x: int(x) - 1, input().split()))
A = [0] * M
B = [0] * M
C = [0] * M
for i in range(M):
    A[i], B[i], C[i] = map(int, input().split())
MAX = 10 ** 10
dist = [[MAX] * N for _ in range(N)]

for i in range(M):
    dist[A[i]-1][B[i]-1] = C[i]
    dist[B[i]-1][A[i]-1] = C[i]
    
for k in range(N):
    for i in range(N):
        for j in range(N):
            dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])

ans = 10 ** 10
for per in itertools.permutations(r, R):
    cost = 0
    for i in range(R-1):
        cost += dist[per[i]][per[i+1]]
    ans = min(ans, cost)

print(ans)

Measured memory_bytes: 46936
#include <stdio.h>

int main(void)
{
        int a,b,c[3];
        scanf("%d%d",&a,&b);

        c[0]=a+b;c[1]=a-b;c[2]=a*b;
        if(c[0]>=c[1] && c[0]>=c[2])printf("%d\n",c[0]);
        else if(c[1]>=c[0] && c[1]>=c[2]) printf("%d\n",c[1]);
        else printf("%d\n",c[2]);
        return 0;
}


Measured memory_bytes: 1700
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <unordered_map>
#include <climits>
#include <set>
#include <unordered_set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <complex>
#include <regex>
#include <locale>
#include <random>
#include <type_traits>
#include <chrono>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); --i)
#define REP(i, n) FOR(i, 0, (n))
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)

#define FOREACH(x, arr) for (auto &(x) : (arr))
#define FORITER(x, arr) for (auto(x) = (arr).begin(); (x) != (arr).end(); ++(x))

#define SHOW_VECTOR(v) {std::cerr << #v << "\t:";for(const auto& xxx : v){std::cerr << xxx << " ";}std::cerr << "\n";}
#define SHOW_MAP(v){std::cerr << #v << endl; for(const auto& xxx: v){std::cerr << xxx.first << " " << xxx.second << "\n";}}

using LL = long long;

//------------------------------------------
//------------------------------------------


int main() {

    int N;
    cin >> N;

    vector<double> v(N);
    REP(i, N) cin >> v[i];

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

    double ans = (v[0] + v[1]) / 2.0;

    for (int i = 2; i < N; i++) {
        ans = (ans + v[i]) / 2.0;
    }

    cout << fixed << setprecision(20) << ans << endl;

}





































Measured memory_bytes: 256
n = int(input())
s = str(input())

r_count = s.count('R')
g_count = s.count('G')
b_count = s.count('B')

ans = r_count * g_count * b_count

for i in range(n-2):
    for j in range(i+1, n-1):
        k = 2*j-i
        if k >= n:
            continue
        if s[i] != s[j] and s[j] != s[k] and s[k] != s[i]:
            ans -= 1

print(ans)

Measured memory_bytes: 67884
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define F first
#define S second
using namespace std;
int main()
{
    ll n; cin>>n; ll a[n]; for(ll i=0;i<n;i++) cin>>a[i];
    ll s=0;
    for(ll i=1;i<n;i++)
    {
        if(a[i-1]>a[i])
        {
            s+=(a[i-1]-a[i]);
            a[i]=a[i-1];
        }
    }
    cout<<s;
}



Measured memory_bytes: 5172
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define debug(x)      cerr << "L" << __LINE__ << ": " << #x << " = " << (x) << endl
#define debugvec(v)   rep(i, v.size()) cerr << "L" << __LINE__ << ": " << #v << "[" << i << "] = " << v[i] << endl;
#define debugvec2(v)  cerr << "L" << __LINE__ << ": " << #v << " = { "; rep(i, v.size()) cerr << v[i] << (i + 1 == v.size() ? "" : ", "); cerr << " }" << endl;
typedef long long ll;  /* 10^18 くらいまでいける */

int main(){
  double t, x;
  cin >> t >> x;

  cout << t/x << endl;

  return 0;
}

Measured memory_bytes: 256
def judge():
    if t > h:
        point["t"] += 3
    elif t < h:
        point["h"] += 3
    else:
        point["t"] += 1; point["h"] += 1

n = int(input())
point = {"t": 0, "h": 0}
for i in range(n):
    t, h = input().split()
    judge()
print(point["t"], point["h"])



Measured memory_bytes: 5600
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;

namespace AOJ
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }

        static void Main(string[] args)
        {
            SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            var pq = new priority_queue();
            while(true)
            {
                var line = ReadLine().Split();
                if (line[0] == "end")
                { break; }
                else if (line[0] == "insert")
                {
                    pq.insert(long.Parse(line[1]));
                }
                else if (line[0] == "extract") 
                {
                    WriteLine(pq.extract());
                }
            }
            Out.Flush();
        }
        class priority_queue
        {
            long[] A = new long[2000000];
            int num = 0;
            public void insert (long v)
            {
                A[num] = long.MinValue;
                ++num;
                increaseKey(num, v);
            }
            void increaseKey(int i, long key)
            {
                if (key < A[i - 1]) return;
                A[i - 1] = key;
                while (1 < i && A[i / 2 - 1] < A[i - 1])
                {
                    var t = A[i - 1];
                    A[i - 1] = A[i / 2 - 1];
                    A[i / 2 - 1] = t;
                    i = i / 2;
                }
            }
            public long extract()
            {
                var max = A[0];
                A[0] = A[num - 1];
                --num;
                maxHeapify(1);
                return max;
            }
            void maxHeapify(int i)
            {
                var H = num;
                var l = left(i);
                var r = right(i);
                var largest = 0;
                if (l <= H && A[i - 1] < A[l - 1])
                { largest = l; }
                else
                { largest = i; }
                if (r <= H && A[largest - 1] < A[r - 1])
                { largest = r; }
                if (largest != i)
                {
                    var t = A[i - 1];
                    A[i - 1] = A[largest - 1];
                    A[largest - 1] = t;
                    maxHeapify(largest);
                }
            }
            int left(int l) => l * 2;
            int right(int r) => r * 2 + 1;
        }
    }
}


Measured memory_bytes: 26580
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner stdin =new Scanner(System.in);
		int n=stdin.nextInt();
		String s[]=new String[n];
		int i;
		String c,d;
		boolean flag=false;
		for(i=0;i<n;i++){
			c=stdin.next();
			s[i]=c;
		}
		for(i=0;i<n;i++){
			d=s[i];
			if(d.contains("Y"))
				flag=true;
		}
		if(flag)
			System.out.println("Four");
		else
			System.out.println("Three");
	}
}

Measured memory_bytes: 21844
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;

int main()
{
  int a, d, n;
  while(cin >> a >> d >> n, a || d || n) {
    int cnt = 0;
    FOR(i,0,10000000) {
      int x = a + d * i;
      if(x == 1) continue;
      bool prime = true;
      for(int j = 2; j * j <= x; j++) {
        if(x % j == 0) {
          prime = false;
          break;
        }
      }
      if(prime) cnt++;
      if(cnt == n) {
        cout << x << endl;
        break;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 3080
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#define ll long long
#define SIZE 3010
#define rep(i, a, b) for (int i = a; i <= b; ++i)
using namespace std;
void io() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); }
const ll mod = 998244353;
ll n, s, a[SIZE], dp[SIZE], ans;

int main() {
	io(); cin >> n >> s;
	rep(i, 1, n) cin >> a[i];
	rep(i, 1, n) {
		for (int j = s; j >= a[i]; --j) {
			dp[j] += dp[j - a[i]];
			dp[j] %= mod;
		}
		if (a[i] <= s) dp[a[i]] = (dp[a[i]] + i) % mod;
		ans = (ans + dp[s]) % mod;
	}
	cout << ans;
}

Measured memory_bytes: 256
def main():
    n = int(input())
    num_list = list(map(int, input().split()))

    result_list = [0]*n

    for i in range(n-1):
        result_list[num_list[i]-1] += 1

    for i in range(n):
        print(result_list[i])

if __name__ == '__main__':
    main()


Measured memory_bytes: 99940
#include<cstdio>
int main(){
    float f;
    while(scanf("%f",&f)!=-1){
        if(f<=48.00)printf("light fly\n");
        else if(f<=51.00)printf("fly\n");
        else if(f<=54.00)printf("bantam\n");
        else if(f<=57.00)printf("feather\n");
        else if(f<=60.00)printf("light\n");
        else if(f<=64.00)printf("light welter\n");
        else if(f<=69.00)printf("welter\n");
        else if(f<=75.00)printf("light middle\n");
        else if(f<=81.00)printf("middle\n");
        else if(f<=91.00)printf("light heavy\n");
        else printf("heavy\n");
    }
}

Measured memory_bytes: 0
import sys
import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

MOD = 1_000_000_007

def main(N, K):
    K -= 1
    U = 5000
    C = np.zeros((U, U), np.int64)
    C[0, 0] = 1
    for n in range(1, U):
        C[n] += C[n - 1]
        C[n, 1:] += C[n - 1, :-1]
        C[n] %= MOD

    dp = np.zeros((N + 10, N + 10), np.int64)
    dp[0, 0] = 1
    for n in range(1, N + 10):
        dp[n, n] = (dp[n - 1, n - 1] + dp[n - 1, n]) % MOD
        for m in range(n + 1, N + 10):
            dp[n, m] = (dp[n - 1, m] + dp[n, m - 1]) % MOD
    for n in range(N + 9, 0, -1):
        dp[n] -= dp[n - 1]
        dp[n] %= MOD
    ans = 0
    if K == N - 1:
        return dp[:N, N - 1].sum() % MOD
    for r in range(N - K, N + 1):
        x = C[r - 2, N - K - 2]
        a = N - r
        b = K - a
        if b == 0:
            x = x * (dp[:a + 1, a].sum() % MOD) % MOD
        else:
            x *= (dp[1:a + 2, a + 1] * C[b - 1:a + b, b - 1][::-1] %
                  MOD).sum() % MOD
            x %= MOD
        ans += x
    ans %= MOD
    for i in range(N - K - 2):
        ans = ans * 2 % MOD
    return ans % MOD

if sys.argv[-1] == 'ONLINE_JUDGE':
    import numba
    from numba.pycc import CC
    i4 = numba.int32
    i8 = numba.int64
    cc = CC('my_module')

    def cc_export(f, signature):
        cc.export(f.__name__, signature)(f)
        return numba.njit(f)

    main = cc_export(main, (i8, i8))
    cc.compile()

from my_module import main

N, K = map(int, read().split())
print(main(N, K))

Measured memory_bytes: 253856
#include <iostream>
using namespace std;
typedef long long ll;
int n, m, k;
ll a[200001], b[200001]; // 累積和を格納する

void solve() {
  int ans = 0;
  int j = m;
  // aを先頭から見ていく
  for (int i = 0; i <= n; i++) {
    // aだけでkを超えたら満たせないのでbreak
    if (a[i] > k) break;
    // bを後ろからみる
    while (b[j] + a[i] > k) {
      j--;
    }
    ans = max(ans, i + j);
  
  }
  printf("%d\n", ans);
}

int main() {
  cin >> n >> m >> k;
  // 累積和のため先頭に0を追加
  a[0] = 0;
  b[0] = 0;
  for (int i = 1; i < n + 1; i++) {
    cin >> a[i];
    a[i] += a[i-1];
  }
  for (int i = 1; i < m + 1; i++) {
    cin >> b[i];
    b[i] += b[i-1];
  }
  
  solve();
}

Measured memory_bytes: 6804
#include <iostream>

using namespace std;

int main()
{
    int a , b;
    cin>>a>>b;
    if(1<=a<=9&&1<=b<=9)
    {
        if(a<b)
        {
            for(int i=0 ; i<b ; i++)
            {
                cout<<a;
            }
            cout<<endl;
        }
        else if(a>b)
        {
            for(int i=0 ; i<a ; i++)
            {
                cout<<b;
            }
            cout<<endl;
        }
        else
        {
            for(int i=0 ; i<a ; i++)
            {
                cout<<b;
            }
            cout<<endl;
        }
    }
    return 0;
}


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

int main() {
  int n; cin >>n;
  vector<int> a(n);
  int max = 0, min = 1000;
  for (int i=0; i<n; i++){
    cin >>a.at(i);
    int j = a.at(i);
    if (j>max) max = j;
    if (j<min) min = j;
  }
  cout <<max - min <<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main()
{
	string str;
	int w;
	cin >> str;
	cin >> w;
	for (int i = 0; i < str.length(); i++)
	{
		if ((i) % w == 0)
			cout << str[i];
	}
    return 0;
}

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

using namespace std;
#define inputInt(a) int a; cin >> a; 
#define inputInt2(a,b) int a; int b; cin >> a >> b; 
#define inputInt3(a,b,c) int a; int b; int c; cin >> a >> b >> c;
#define inputLong(a) long a;cin >> a; 
#define inputIntArray(a,N) int a[N];for(int i=0;i<N;i++){cin >> a[i];}
#define inputLongArray(a,N) long a[N];for(int i=0;i<N;i++){cin >> a[i];}
#define inputIntArray2(a,b,N) int a[N]; int b[N]; for(int i=0;i<N;i++){cin >> a[i] >> b[i];}
#define output(answer) cout << answer << endl;
#define fN(i,N)    for(int i=0; i<N; i++)
#define fSE(i,s,e) for(int i=s; i<=e; i++)
#define ll long long
#define pb push_back
#define mp make_pair
#define fi first
#define se second
const ll MOD2 = 998244353;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main()
{
  //input
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  double a, b, x; cin >> a >> b >>x;
  
  //main
  double theta;
  if(x >= a*a*b/2){
    theta = atan(a*a*a/(2*(a*a*b-x)))/(2*acos(-1))*360;
  }else{
    theta = atan(2*x/(a*b*b))/(2*acos(-1))*360;
  }
  
  // output
  cout << fixed << setprecision(10) << 90-theta << endl;
  
  return 0;
}

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

using namespace std;

const int inf = 1 << 25;

struct edge
{
  int to, cap, rev, id, isrev;
  edge(){}
  edge(int to, int cap, int rev, int id, int isrev):to(to), cap(cap), rev(rev), id(id), isrev(isrev){}
};

struct Dinic
{
  vector< vector<edge> > G;
  int level[333], iter[333];
  //vector<int> level, iter;
  //Dinic(int V):G(V), level(V), iter(V){};
  Dinic(int V)
  {
    G.clear(); G.resize(V);
  }
  void add_edge(int f, int t, int id)
  {
    G[f].push_back(edge(t, 1, (int)G[t].size(), id, 0));
    G[t].push_back(edge(f, 1, (int)G[f].size()-1, id, 1));
  }
  void bfs(int s)
  {
    //fill(level.begin(), level.end(), -1);
    memset(level, -1, sizeof(level));
    queue<int> que;
    level[s] = 0;
    que.push(s);
    while(!que.empty()) {
      int v = que.front(); que.pop();
      for(int i = 0; i < (int)G[v].size(); i++) {
	edge& e = G[v][i];
	if(e.cap > 0 && level[e.to] < 0) {
	  level[e.to] = level[v] + 1;
	  que.push(e.to);
	}
      }
    }
  }
  int dfs(int v, int t, int f)
  {
    if(v == t) return f;
    for(int &i = iter[v]; i < (int)G[v].size(); i++) {
      edge& e = G[v][i];
      if(e.cap > 0 && level[v] < level[e.to]) {
	int d = dfs(e.to, t, min(f, e.cap));
	if(d > 0) {
	  e.cap -= d;
	  G[e.to][e.rev].cap += d;
	  return d;
	}
      }
    }
    return 0;
  }
  int max_flow(int s, int t)
  {
    int flow = 0;
    while(1) {
      bfs(s);
      if(level[t] < 0) return flow;
      //fill(iter.begin(), iter.end(), 0);
      memset(iter, 0, sizeof(iter));
      int f; while((f = dfs(s, t, inf)) > 0) flow += f;
    }
  }
};

int main()
{
  int N, M; cin >> N >> M;
  Dinic dinic(N);
  for(int i = 0; i < M; i++) {
    int X, Y; cin >> X >> Y; X--, Y--;
    dinic.add_edge(X, Y, i);
  }
  int S, T; cin >> S >> T; S--, T--;
  int ans = dinic.max_flow(S, T);
  vector<int> used_rev;
  for(int v = 0; v < (int)dinic.G.size(); v++) {
    for(int i = 0; i < (int)dinic.G[v].size(); i++) {
      edge e = dinic.G[v][i];
      if(e.cap < 1 && e.isrev == 1) used_rev.push_back(e.id);
    }
  }
  sort(used_rev.begin(), used_rev.end());
  cout << ans << endl;
  cout << (int)used_rev.size() << endl;
  for(int i = 0; i < (int)used_rev.size(); i++) cout << used_rev[i]+1 << endl;
  return 0;
}

Measured memory_bytes: 3252
using System;
using static System.Console;
using static System.Int32;
using static System.Math;
using System.Linq;
using System.Collections.Generic;

class Solution
{
    static void Main()
    {
    lb:
        var n = Parse(ReadLine());
        var dic = new Dictionary<KeyValuePair<int, int>, int>();
        for (int a = 1; a <= n; ++a)
        {
            var iti = a % 10;
            if (iti == 0) continue;
            int juu = a;
            while (10 <= juu) juu /= 10;
            var p = new KeyValuePair<int, int>(juu, iti);
            int val;
            if (dic.TryGetValue(p, out val))
            {
                dic[p] = val + 1;
            }
            else
            {
                dic[p] = 1;
            }
        }
        int result = 0;
        foreach (var pair in dic)
        {
            var key = new KeyValuePair<int, int>(pair.Key.Value, pair.Key.Key);
            int val;
            if (!dic.TryGetValue(key, out val)) continue;
            result += pair.Value * val;
        }
        WriteLine(result);
    }
}


Measured memory_bytes: 17412
#include <bits/stdc++.h>
#include <algorithm>
#define rep(i, n) for (int i=0; i<n; ++i)
#define all(obj) (obj).begin(),(obj).end()
using namespace std;
typedef long long ll;
long long GCD(long long x, long long y) { return y ? GCD(y, x%y) : x; }

int main(){
    int N, M;
    cin >> N >> M;
    int mi = 0;
    int ma = 100001;
    rep(i, M){
        int L, R;
        cin >> L >> R;
        if(L>mi) mi = L;
        if(R<ma) ma = R;
    }
    int ans = ma-mi+1;
    cout << (ans>0 ? ans: 0) << endl;
    return 0;
}


Measured memory_bytes: 3636
import sys
import time
import random
import math
from collections import deque
import heapq
import itertools
from decimal import Decimal
import bisect
from operator import itemgetter
MAX_INT = int(10e18)
MIN_INT = -MAX_INT
mod = 1000000000+7
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

def tami(ans):
  res = 0
  LastDay = [0]*26
  for i in range(D):
    res += s[i][ans[i]]
    for j in range(26):
      if ans[i] == j:
        continue
      res -= (i+1 - LastDay[j]) * c[j]
    LastDay[ans[i]] = i+1
  return res

def nasu():
  res = []
  LastDay = [0]*26
  for d in range(1,D+1):
    tmp = ["", 0]
    for i in range(26):
      if tmp[1] < s[d-1][i] + (d - LastDay[i]) * c[i]:
        tmp = [i, s[d-1][i] + (d - LastDay[i]) * c[i]]
    res.append(tmp[0])
    LastDay[tmp[0]] = d
  return res

def nbo(ans, score, num):
  tmp_ans = ans[:]
  for _ in range(num):
    random_date = random.randint(0,D-1)
    random_val = random.randint(0,25)
    tmp_ans[random_date] = random_val
  scoscore = tami(tmp_ans)
  if scoscore > score:
    return (True, tmp_ans, scoscore)
  else:
    return (False, tmp_ans, scoscore)

start = time.time()
D = I()
c = IL()
s = [IL() for i in range(D)]

ans = nasu()
#print(ans)

score = tami(ans)
#print(score)

end = time.time()
num = 2
while (time.time() - start) < 1.8:
  judge, anans, scoscore = nbo(ans, score, num)
  if judge == True:
    ans, score = anans, scoscore
    #print(ans)
    #print(tami(ans))
for i in ans:
  print(i+1)

Measured memory_bytes: 88568
//Author: AnandRaj doubleux
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pll> vpll; 

#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define test() int t;cin>>t;while(t--)
#define all(v) v.begin(),v.end()
#define prinp(p) cout<<p.first<<" "<<p.second<<endl
#define prinv(V) for(auto v:V) cout<<v<<" ";cout<<endl
#define take(V,f,n) for(int in=f;in<f+n;in++) cin>>V[in]
#define what(x) cerr<<#x<<" = "<<x<<endl
#define KStest() int t,t1;cin>>t;t1=t;while(t--)
#define KScout cout<<"Case #"<<t1-t<<": "
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int MOD = 1e9+7,MAX = 1e6+5;
const ll INF = 1e18+5;

int main()
{
	string s;
	cin>>s;
	int sum=0;
	for(auto c:s)
	{
		sum += (c-'0');
	}
	if(sum%9==0) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}	

Measured memory_bytes: 3704
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define bit(n,m)(((n)>>(m))&1)
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
//#define MOD 998244353
#define MOD 1000000007
#define invp(a,p)pom(a,p-2,p)

int main(){
  char s[101];
  char t[101];
scanf("%s %s",s,t);
  printf("%s%s",t,s);

return 0;
}

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

using namespace std;
using ll = long long;

const ll INFF= 1e18 + 5;

int main() {
    int h, n;
    cin >> h >> n;
    int a[n + 1], b[n + 1];
    vector<ll> dp(h + 1, INFF);
    for (int i = 1; i <= n; ++i) {
        cin >> a[i] >> b[i];
    }
    dp[0] = 0;
    vector<ll> dp2 = dp;
    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= h; ++j) {
            int x = j - a[i];
            if (x < 0) x = 0; 
            dp[j] = min(dp2[j], dp[x] + b[i]);
        }
        dp2 = dp;
    }
    cout << dp[h] << "\n";
    return 0;
}

Measured memory_bytes: 384
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let v = read_vec::<usize>();
    let (n, m, p) = (v[0], v[1], v[2] as i64);
    let mut g = vec![vec![]; n];
    for i in 0..m {
        let v = read_vec::<usize>();
        let (a, b, c) = (v[0] - 1, v[1] - 1, v[2] as i64);
        g[a].push((b, p - c));
    }
    let (d, f) = shortest_path(&g, 0);
    if f[n - 1] {
        println!("-1");
        return;
    }
    println!("{}", max(-d[n - 1], 0));
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

const INF: i64 = std::i64::MAX;

fn shortest_path(graph: &Vec<Vec<(usize, i64)>>, start: usize) -> (Vec<i64>, Vec<bool>) {
    let n = graph.len();
    let mut dist = vec![INF; n];
    dist[start] = 0;
    for _ in 0..n {
        for v in 0..n {
            for &(to, cost) in &graph[v] {
                if dist[v] == INF || dist[to] <= dist[v] + cost {
                    continue;
                }
                dist[to] = dist[v] + cost;
            }
        }
    }

    let mut negative = vec![false; n];
    for _ in 0..n {
        for v in 0..n {
            for &(to, cost) in &graph[v] {
                if dist[v] == INF {
                    continue;
                }
                if dist[to] > dist[v] + cost {
                    dist[to] = dist[v] + cost;
                    negative[to] = true;
                }
                if negative[v] {
                    negative[to] = true;
                }
            }
        }
    }

    return (dist, negative);
}


Measured memory_bytes: 2316
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

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

    map<string, ll> mp;
    rep(i, n) {
        string s;
        cin >> s;
        mp[s]++;
    }

    ll u = 0;
    for(auto p : mp) {
        chmax(u, p.second);
    }

    vector<string> v;
    for(auto p : mp) {
        if(u == p.second) {
            v.pb(p.first);
        }
    }

    sort(all(v));

    for(auto p : v) {
        out(p);
    }

    re0;
}

Measured memory_bytes: 26868
#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; typedef vector<ll> VL;
void dbg(){ cerr << "\n"; }  template <class T, class ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }
template <class T, class T2> void amax(T& a,T2 b){ if(a < b) a = b;}

int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n;
	cin >>n;
	int ct=0, cx=0, cy=0;
	bool ok =true;
	rep(i, n){
		int t, x, y;
		cin >>t >>x >>y;
		if(abs(x-ct)+abs(y-cy) > t-ct) ok=false;
		if((abs(x-ct)+abs(y-cy) - (t-ct)) %2) ok=false;
		
	}
	puts(ok?"Yes":"No");
	return 0;
}


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

int main()
{
    int x, y;
    
    int n = 0, a[10010][2] = {};
    while (1) {
        cin >> x >> y;
        if (!x && !y) break;
        if (x < y) {
            a[n][0] = x;
            a[n][1] = y;
        } else {
            a[n][0] = y;
            a[n][1] = x;
        }
        n++;
    }

    for (int i = 0; i < n; i++) {
        cout << a[i][0] << " " << a[i][1] << endl;
    }

    return 0;
}

Measured memory_bytes: 3100
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
//#include <regex>

/* g++ -g -std=c++0x */
/* g++ -g -std=c++11 */

using namespace std;

// freopen("input.txt", "rt", stdin);
// freopen("output.txt", "wt", stdout);

#define ALL(c)          (c).begin(), (c).end()
#define ALLR(c)         (c).rbegin(), (c).rend()
#define FOR(i,a,b)      for (int i=(a); i < (b); ++i)
#define FORR(i,a,b)     for (int i=(a); i > (b); --i)
#define FOR_ALL(i,c)    for (__typeof((c).begin()) i=(c).begin();   \
                             i != (c).end(); ++i)
#define FOR_ALLR(i,c)   for (__typeof((c).rbegin()) i=(c).rbegin(); \
                             i != (c).rend(); ++i)
#define SZ(array)       (sizeof(array)/sizeof(array[0]))
#define lc(x)           (x<<1)     /* 2*x */
#define rc(x)           (x<<1 | 1) /* 2*x+1 */
#define lowbit(x)       (x & (-x)) /* 0b10100 -> 0b100 */

typedef long long       LL;
typedef map<int,int>    MII;
typedef pair<int,int>   PII;
typedef set<int>        SI;
typedef vector<bool>    VB;
typedef vector<double>  VD;
typedef vector<int>     VI;
typedef vector<string>  VS;

/* check if a key is in container C */
template <class C>
inline bool in_(const typename C::key_type& k, const C& A)
{ return A.find(k) != A.end(); }
inline bool in_(const string& s, const string& S)
{ return S.find(s) != string::npos; }

int main()
{
/* #ifndef ONLINE_JUDGE */
/*     freopen("foo", "rt", stdin); */
/* #endif */
    std::ios::sync_with_stdio(false);

    int a, b;
    while (cin >> a >> b) {
        cout << a * b - a - b + 1 << endl;
    }
}


Measured memory_bytes: 256
from collections import deque

N, M = map(int, input().split())
to = [[] for _ in range(N)]
for _ in range(M):
    a, b = map(int, input().split())
    to[a - 1].append(b - 1)
    to[b - 1].append(a - 1)

q = deque()
q.append((0, set(), -1))
ans = 0
while len(q):
    a, s, p = q.pop()
    s.add(a)
    if len(s) == N:
        ans += 1
        continue
    for b in to[a]:
        if b not in s:
            q.append((b, s | {b}, a))
print(ans)


Measured memory_bytes: 3444
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**8)
INF = float("inf")


def solve(K: int):

    X = set()

    def rec(keta, x):
        X.add(x)
        if keta == 10:
            return
        y = x % 10
        if 0 <= y - 1:
            rec(keta+1, x*10 + y-1)
        rec(keta+1, x*10+y)
        if y+1 <= 9:
            rec(keta+1, x*10+y+1)

    for i in range(1, 10):
        rec(1, i)
    X = sorted(X)
    print(X[K-1])

    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    K = int(next(tokens))  # type: int
    solve(K)


if __name__ == '__main__':
    main()


Measured memory_bytes: 21512
N, K = gets.chomp.split(" ").map(&:to_i)

# a < b のとき
asb = (K..N-1).map { |a| N - a }.inject(:+)

# a >= b のとき
alb = 0
(K+1..N).each do |b|
  between = (N-b+1)
  slots = between / b
  rest = between % b
  alb += (b-K) * slots
  alb += rest - K if rest > K
  alb -= 1 if K == 0
end

puts alb + asb


Measured memory_bytes: 2684
s = input()

def check(strings):
    n = len(s)
    if s[::-1] != s:
        return False
    s2 = s[:(n-1)//2]
    if s2[::-1] != s2:
        return False
    s3 = s[(n+3)//2 - 1:]
    if s3[::-1] != s3:
        return False

    return True

print('Yes' if check(s) else 'No')

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

using namespace std;

int main() {
    ios::sync_with_stdio(false);

    int n, m, c, f = 1, p, a, b;
    cin >> n >> m;

    vector<vector<int> > g (n+1);

    for(int i = 0; i < m; i++) {
        cin >> a >> b;
        g[a].push_back(b);
        g[b].push_back(a);
    }

    int u[n+1] = {0}, d[n+1];
    for(int i = 0; i <= n; i++)
        d[i] = INT_MAX;
    deque<int> q;
    q.push_back(1);
    u[1] = 1;
    d[1] = 0;

    while(q.size()) {
        c = q.front();
        q.pop_front();

        for(int i = 0; i < g[c].size(); i++) {
            if(!u[g[c][i]]) {
                u[g[c][i]] = 1;
                q.push_back(g[c][i]);
                d[g[c][i]] = min(d[g[c][i]], d[c] + 1);
            }
        }
    }

    for(int i = 1; i <= n; i++)
        f = min(f, u[i]);
    cout << (f?"Yes\n":"No");

    if(f)
        for(int i = 2; i <= n; i++) {
            p = 0;
            for(int j = 0; j < g[i].size(); j++)
                if(d[g[i][j]] < d[g[i][p]])
                    p = j;
            cout << g[i][p] << "\n";
        }
}


Measured memory_bytes: 10652
#include<set>
#include<map>
#include<queue>
#include<cmath>
#include<string>
#include<cstdio>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
#define rep(i,a,b) for (int i=a; i<=b; i++)
#define per(i,a,b) for (int i=a; i>=b; i--)
#define debug(x) {cout<<(#x)<<" "<<x<<endl;}
using namespace std;
typedef long long LL;

inline int read() {
    int x=0,f=1; char ch=getchar();
    while (!(ch>='0'&&ch<='9')) {if (ch=='-')f=-1;ch=getchar();}
    while (ch>='0'&&ch<='9') {x=x*10+(ch-'0'); ch=getchar();}
    return x*f;
}

const int N = 110;

int n,w,w0;
int na,nb,nc,nd;
int a[N],b[N],c[N],d[N];

int dp[N][N][N][N];

int main() {

	#ifndef ONLINE_JUDGE
	//	freopen("data.in","r",stdin);
	//	freopen("data.out","w",stdout);
	#endif

	n=read(),w=read(); w0=read(); a[++na]=read();
	rep(i,2,n) {
		int wx=read();
		if (wx==w0) a[++na]=read();
		else if (wx==w0+1) b[++nb]=read();
		else if (wx==w0+2) c[++nc]=read();
		else d[++nd]=read();
	}
	a[0]=b[0]=c[0]=d[0]=0;
	sort(a+1,a+na+1); sort(b+1,b+nb+1); sort(c+1,c+nc+1); sort(d+1,d+nd+1);
	int ans=0;
	int suma=0;
	rep(i,0,na) {
		if (i>w/w0) break;
		suma+=a[na-i+1]; 
		int sumb=suma;
		rep(j,0,nb) {
			if (j>(w-i*w0)/(w0+1)) break;
			sumb+=b[nb-j+1];
			int sumc=sumb;
			rep(k,0,nc) {
				if (k>(w-i*w0-j*(w0+1))/(w0+2)) break;
				sumc+=c[nc-k+1];
				int sumd=sumc;
				rep(l,0,nd) {
					if (l>(w-i*w0-j*(w0+1)-k*(w0+2))/(w0+3)) break;
					sumd+=d[nd-l+1];
					ans=max(ans,sumd);
				}
			}
		}
	}
	
	printf("%d\n",ans);

	return 0;
}


Measured memory_bytes: 384