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

int main() {
    int N;
    cin >> N;
    vector<int> hen(N);
    for(int i=0;i<N;i++){
        cin >> hen.at(i);
    }

    sort(hen.begin(),hen.end());
    reverse(hen.begin(),hen.end());
    int total = 0;

    for(int j=1;j<N;j++){
        total = total + hen.at(j);
    }

    if(hen.at(0) < total){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include <stdio.h>
#include <vector>
#include <algorithm>

using namespace std;


int main(){

	int n,table[10],tmp;

	while(true){
		scanf("%d",&n);
		if(n == 0)break;

		for(int i = 0; i < 10; i++)table[i] = 0;

		for(int i = 0; i < n; i++){
			scanf("%d",&tmp);
			table[tmp]++;
		}

		for(int i = 0; i < 10; i++){
			if(table[i] == 0){
				printf("-\n");
			}else{
				for(int k = 0; k < table[i]; k++)printf("*");
			}
			printf("\n");
		}
	}

    return 0;
}



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

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


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

typedef long long ll;

int main()
{
    int i;
    int n;
    cin >> n;
    vector<pair<int,int>> b(n);
    for(i = 0;i < n;++i){
        cin >> b.at(i).second;
        cin >> b.at(i).first;
    }
    ll now = 0;
    sort(b.begin(),b.end());
    for(i = 0;i < n;++i){
        now += b.at(i).second;
        if(now > b.at(i).first){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

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

using namespace std;
typedef long long LL;
int main(void) {
  int n;
  string s;
  cin >> n >> s;
  vector<int> cnt(26);
  for(char c:s) ++cnt[c-'a'];
  LL answer = 1ll;
  for(int x:cnt) {
    answer *= x + 1;
    answer %= 1000000007ll;
  }
  cout << (answer + 1000000006) % 1000000007 << endl;
  return 0;
}


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

using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
typedef long long ll;


int main(){
  int a,b,c;
  cin >> a >> b >> c;
  if((b-a)==(c-b))cout << "YES" << endl;
  else cout << "NO" << endl; 
}


Measured memory_bytes: 256
x,y = list(map(int, input().split(" ")))

if x < 0:
    if y < 0:
        print(x*y)
    else:
        print(x+y)
else:
    if y < 0:
        print(x-y)
    else:
        ad = x+y
        mu = x*y
        if ad < mu:
            print(mu)
        else:
            print(ad)


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

int main() {
	int N, K,C=0,*a,*_K;
	cin >> N >> K ;
	a = new int[N];
	_K = new int[N];
	for (int i= 0; i < N; i++) _K[i] = K;
	for (int i = 0; i < N; i++) cin >> a[i];
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			if (i == j) continue;
			else if (a[j] <= _K[i]) _K[i] -= a[j];
		}
		if (a[i]<_K[i]) C++;
	}
	cout << C << endl;
	return 0;
}

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

#define __STDC_FORMAT_MACROS
#define p64 PRId64

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR (i, 0, n)
#define ALL(f, x, ...)                                                         \
    ([&] (decltype ((x)) ALL) {                                                \
        return (f) (begin (ALL), end (ALL), ##__VA_ARGS__);                    \
    }) (x)

using namespace std;
using ll = int64_t;

int main() {
    int N, D;
    cin >> N >> D;
    cout << ceil (N / (2.0 * D + 1)) << endl;
    return 0;
}

Measured memory_bytes: 3744
#include <bits/stdc++.h>
#define int long long
using namespace std;

int n,temp,ans=0;

int find_prime2(int n)
{
	int tot=0;
	while (n%2==0)  n/=2,tot++;
	return tot;
}

signed main()
{
	cin>>n;
	for (int i=1;i<=n;i++)  cin>>temp,ans+=find_prime2(temp);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#define rep(i,n) Rep(i,0,n)
#define Rep(i,k,n) for(int i=k ; i<n ; i++)
#define rep1(i,n) for(int i=1 ; i<=n ; i++)
#define vi vector<int>
#define vii vector<int,int>
#define Sort(v) sort(v.begin(),v.end())
#define Reverse(v) reverse(v.begin(),v.end())

//const int MOD = 1000000007;
//const int INF = 1<<30;
using namespace std;

string disp(bool x){
    return x ? "Yes" : "No";
}

int main(){
    while(true){
        string w; cin >> w;
        if(w == "-") break;
        
        int m; cin >> m;
        
        int h[m];
        rep(i,m) cin >> h[i];
        
        rep(i,m){
            string upper = w.substr(h[i],w.size());
            string lower = w.substr(0,h[i]);
            
            w = upper + lower;
        }
        cout << w << endl;
    }
    
    
}






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

using namespace std;
using ll = long long;

using Field = vector<vector<int>>;
using Graph = vector<vector<int>>;
using VI = vector<int>;
using VC = vector<char>;
using PI = pair<int, int>;

#define REP(i, n) for (int i = 0; i < (n); i++)
#define ALL(x) x.begin(), x.end()

const long long INF = 1LL<<60;
const int mod = 1000000007;

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 N;
vector<int> a;
vector<int> b;
vector<int> c;
vector<ll> dp[3];


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

    cin >> N;
    a.resize(N);
    b.resize(N);
    c.resize(N);
    REP(i, 3) dp[i].resize(N + 1);

    REP(i, N) {
        cin >> a.at(i) >> b.at(i) >> c.at(i);
    }

    dp[0][0] = 0;
    dp[1][0] = 0;
    dp[2][0] = 0;

    for (int i = 0; i < N; i++) {
        dp[0][i + 1] = (dp[1][i] > dp[2][i]) ? dp[1][i] + a[i] : dp[2][i] + a[i];
        dp[1][i + 1] = (dp[0][i] > dp[2][i]) ? dp[0][i] + b[i] : dp[2][i] + b[i];
        dp[2][i + 1] = (dp[0][i] > dp[1][i]) ? dp[0][i] + c[i] : dp[1][i] + c[i];
    }

    ll ans = 0;
    REP(i, 3) {
        chmax(ans, dp[i][N]);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3840
#include<iostream>

using namespace std;
int b[100001];
int main() {
	int n,a;
	cin >> n;

	for (int i = 1;i <= n;i++) {
		cin >> a;
		b[a] = i;
	}
	
	for (int i = 1;i <= n;i++) {
		cout << b[i] << " ";
	}

	cout << endl;
	return 0;
}

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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
	int n;
	cin>>n;
	long long int ans=0;
	long long int i,j;
	for(i=1;i<=n;i++)
	{
		long long int x,p=n/i;
		if(p%2==0)
		{
			x=p/2;
			ans+=i*(p+1)*x;		
		}	
		else
		{
			x=(p+1)/2;
			ans+=i*p*x;
		}
	}
	cout<<ans<<endl;
	return 0;
}



Measured memory_bytes: 3692
for _ in range(int(input())): #与えられたデータセット回繰り返す
    str0 = input() #標準入力
    int1 = [int(a) for a in str0] #入力された値を数値化する
    int1.sort() #リストの数を小さい順に並べる
    int2 = sorted(int1,reverse=True) #大きい順に並べたリストの作成
    str1 = [str(b) for b in int1] #"join"を使うために文字になおす
    str2 = [str(c) for c in int2] #上記同様
    strm1 = ''.join(str1) #リストを1個の文字列にする
    strm2 = ''.join(str2) #上記同様
    print(int(strm2) - int(strm1)) #2つの数の差を求める


Measured memory_bytes: 5596
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,B,M;cin>>N;int A[2][N];
  cin>>A[0][0];
  for(int i=1;i<N;i++){cin>>B;A[0][i]=A[0][i-1]+B;}
  cin>>A[1][0];
  for(int i=1;i<N;i++){cin>>B;A[1][i]=A[1][i-1]+B;}
  M=A[0][0]+A[1][N-1];
  for(int i=0;i<N;i++)M=max(M,A[0][i]+A[1][N-1]-A[1][i-1]);
  cout<<M<<endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    public static void Main()
    {
        string []input=Console.ReadLine().Split();
        int N = int.Parse(input[0]);
        int K = int.Parse(input[1]);
        input = Console.ReadLine().Split();
        int[] p = new int[N];
        double[] avg = new double[N];
        double max = 0;
        double temp = 0;
        for(int i=0; i < N; i++)
        {
            p[i] = int.Parse(input[i]);
            avg[i] = (p[i] - 1) * 0.5 + 1;
            if (i >= K) {
                temp = temp + avg[i] - avg[i - (K)];
            }
            else
            {
                temp += avg[i];
            }
            if (temp > max) { max = temp; }
        }
        Console.WriteLine(max);
    }
}

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

Measured memory_bytes: 25836
import sys
MAX_INT = int(10e9)
MIN_NUM = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()
 
N = I()
a = [IL()[::-1] for i in range(N)]
 
used = [-1]*N
updatelist = [i for i in range(N)]
total = N*(N-1)//2
cnt = 0
days = 0
ul = []
while updatelist:
  ul = []
  for i in updatelist:
    #print(a)
    #print(i+1)
    if len(a[i]) > 0 and used[i] != days:
      numIND = a[i][-1] -1
      #print(numIND+1)
      if a[numIND][-1] == i+1 and used[numIND] != days:
        a[i].pop(-1)
        a[numIND].pop(-1)
        used[i] = days
        used[numIND] = days
        ul.append(i)
        ul.append(numIND)
        cnt += 1
  else:
    updatelist = ul[:]
    if len(ul) != 0:
      days += 1
#print(a)
#print(cnt)
if cnt == total:
  print(days)
else:
  print(-1)

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

int main(){
	int a,b,c,d;
	cin >> a >> b >> c >> d;
	string ans = "Yes";
	if((abs(a-c)>d)&& (abs(a-b)>d || abs(b-c)>d)){
		ans = "No";
	}
	cout << ans << endl;
	return 0;

}




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

using namespace std;

typedef long long ll;
typedef pair<int,int> P;
constexpr double EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max()/2;
constexpr int MOD = 1e9+7;

vector<vector<ll>> dp(5010,vector<ll>(5010,0));
// a^b
ll mypow(ll a, ll b) {
    if (b == 0) return 1;
    ll tmp = mypow(a, b / 2);
    if (b % 2) return (((tmp*tmp) % MOD)*a) % MOD;
    else return (tmp*tmp) % MOD;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;cin>>n;
    string s;cin>>s;
    int len=s.length();
    dp[0][0] = 1;
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            dp[i+1][j+1] += dp[i][j]*2;
            dp[i+1][j+1] %= MOD ;

            if(j!=0){
                dp[i+1][j-1] += dp[i][j];
                dp[i+1][j-1] %= MOD;
            }
            else{
                dp[i+1][j] += dp[i][j];
                dp[i+1][j] %= MOD;
            }
        }
    }
    ll res=dp[n][len],tmp=mypow(2,len);
    tmp = mypow(tmp,MOD-2);
    res *= tmp; res %= MOD;
    cout<<res<<endl;
}


Measured memory_bytes: 196736
n,a,b=map(int,input().split())
c=a-b
h=[int(input()) for i in range(n)]
low=1
high=10**9+1
while high-low>0:
    k=(high+low)//2
    count=0
    for u in h:
        u-=b*k
        if u>0:
            if u%c==0:
                count+=u//c
            else:
                count+=u//c+1
    if high-low==1:
        if count<=k:
            print(k)
            break
        else:
            print(k+1)
            break
    else:
        if count<=k:
            high=k
        else:
            low=k      

Measured memory_bytes: 50520
#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
#define 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
using pl = pair<ll,ll>;
signed main(){
	string s; cin>>s;
	bool a=0,b=0; 
	rep(i,0,s.size()){
		if(s[i]=='C')a=1;
		if(a && s[i]=='F')b=1;

	}
	cout<<(b?"Yes":"No")<<endl;
	return 0;
}

Measured memory_bytes: 3580
#include <iostream>
#include <vector>
#include <string>

struct Node {
    int left = -1, right = -1;
    int number;
};

struct BTree {
    public:
        std::vector<Node> nodes;
        void insert(int q) {
            Node nd;
            nd.number = q;
            nodes.push_back(nd);
            if ( nodes.size() > 1 ) {
                add_node(q, 0);
            }
        };
        void inorder(int current) {
            if ( nodes[current].left >= 0 ) {
                inorder(nodes[current].left);
            }
            std::cout << " " << nodes[current].number;
            if ( nodes[current].right >= 0 ) {
                inorder(nodes[current].right);
            }
        };
        void preorder(int current) {
            std::cout << " " << nodes[current].number;
            if ( nodes[current].left >= 0 ) {
                preorder(nodes[current].left);
            }
            if ( nodes[current].right >= 0 ) {
                preorder(nodes[current].right);
            }
        };
    private:
        void add_node(int q, int current) {
            if ( q > nodes[current].number ) {
                if ( nodes[current].right >= 0) {
                    add_node(q, nodes[current].right);
                } else {
                    nodes[current].right = nodes.size() - 1;
                }
            } else {
                if ( nodes[current].left >= 0) {
                    add_node(q, nodes[current].left);
                } else {
                    nodes[current].left = nodes.size() - 1;
                }
            }
        }
};

int main() {
    int n;
    std::cin >> n;
    BTree btree;
    std::string str; int q;
    for (int i=0; i<n; i++) {
        std::cin >> str;
        if ( str == "insert" ) {
            std::cin >> q;
            btree.insert(q);
        } else if ( str == "print" ) {
            btree.inorder(0);
            std::cout << std::endl;
            btree.preorder(0);
            std::cout << std::endl;
        }
    }
}

Measured memory_bytes: 9060
import java.util.*;
 
public class Main {
  public static void main(String[] args) {
 	  Scanner sc = new Scanner(System.in);
 
    int n = sc.nextInt();
    int sum = 0;
    for(int i = 0; i < n; i++){
      sum += sc.nextInt() - 1;
    }
 
    System.out.println(sum);
  }
}

Measured memory_bytes: 27732
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n=sc.nextInt();
        int bit =0;
        for(int i=0;i<n;i++) {
            bit |=sc.nextInt();
        }
        System.out.println(Integer.numberOfTrailingZeros(bit));
    }
}


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

int main() {
  int a, b;
  cin >> a >> b;
  int ans = a - 2 * b;
  if(ans < 0) ans = 0;
  cout << ans << endl;
  return 0;
}


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

int main(){
  int N;
  cin>>N;
  int j=0,k=0;
  for(int i=0;i<N;i++){
    int p;
    cin>>p;
    j=max(j,p);
    k+=p;
  }
  cout<<k-j/2<<endl;
}

Measured memory_bytes: 256
N = int(input())
button = [0]
for _ in range(N):
  button.append(int(input()))
pos = 1
cnt = 0
for _ in range(N):
  pos = button[pos]
  cnt += 1
  if pos == 2:
    break

if pos == 2:
  print(cnt)
else:
  print(-1)

Measured memory_bytes: 7080
N, C = gets.split(' ').map(&:to_i)
D = Array.new(C){Array.new}
C.times do |i|
  D[i] = gets.split(' ').map(&:to_i)
end

dc = Array.new(C){[0] * 3}
N.times do |i|
  c = gets.split(' ').map(&:to_i)
  N.times do |j|
    C.times do |k|
      dc[k][(i + j) % 3] += D[c[j] - 1][k]
    end
  end
end

cand = []
(0..(C - 1)).to_a.permutation(3) do |s, t, u|
  cand.push(dc[s][0] + dc[t][1] + dc[u][2])
end

puts cand.min

Measured memory_bytes: 2684
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

def main():
    N = int(readline())

    d = {}
    d["AC"] = 0
    d["WA"] = 0
    d["TLE"] = 0
    d["RE"] = 0

    for _ in range(N):
        s = readline().strip()
        d[s] += 1

    print(f"AC x {d['AC']}")
    print(f"WA x {d['WA']}")
    print(f"TLE x {d['TLE']}")
    print(f"RE x {d['RE']}")


if __name__ == "__main__":
    main()


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

int main()
{


        long long n,m,a,b,c,d,e,f,g,p,q,r,fr,sc,tr,sz,tz,sz1,sz2,i,j,k,mx=-9,mn=999999999999; string str,ttr,ntr;
        long long x=0,y=-1,cnt=0,res=0,ttl=0,ans=0,sum=0; long long flg=0,flag=1,na=0,as=1;
        vector<long long>u,v,w; vector< pair<long long,long long> >vct,tct; vector<string>vst;
        set<long long>st,nt,tt; map<long long,long long>mp,nq,qr,mp1,mp2;

        scanf("%lld",&n);

        double pi=acos(-1);

        d=2*n;  pi=pi*d;

        printf("%0.17lf\n",pi);












    return 0;
}





Measured memory_bytes: 3788
#include <iostream>
#include <queue>

using namespace std;
static const int N = 100;
static const int INFTY = (1 << 21);

int M[N][N] = {0}, d[N], n;

void bfs() {
  int u, v;
  queue<int> q;
  for (u = 0; u < n; u++) {
    d[u] = INFTY;
  }
  d[0] = 0;
  q.push(0);
  while (!q.empty()) {
    u = q.front();
    q.pop();
    for (v = 0; v < n; v++) {
      if (M[u][v] == 0) continue;
      if (d[v] != INFTY) continue;
      d[v] = d[u] + 1;
      q.push(v);
    }
  }
  for (u = 0; u < n; u++) {
    cout << u + 1 << ' ' << ((d[u] == INFTY) ? (-1) : d[u]) << endl;
  }
}

int main() {
  int u, v, k, i, j;

  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> u >> k;
    u--;
    for (j = 0; j < k; j++) {
      cin >> v;
      v--;
      M[u][v] = 1;
    }
  }

  bfs();

  return 0;
}

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

int main() {
  int N; cin >> N;
  int a[N]; rep(i,0,N) cin >> a[i];
  
  bool c[8]; rep(i,0,8) c[i] =false;
  int ans =0, legend =0;
  rep(i,0,N) {
    rep(j,1,9) {
      if (a[i] >= 3200) {
        legend++; break;
      }
      if (a[i] >= (j-1)*400 && a[i] < j*400) c[j-1] = true; 
    }
  }
  rep(i,0,8) if(c[i]) ans++;
  
  int minC = ans;
  if (ans==0) minC =1;
  int maxC = ans + legend;

  cout << minC << " " << maxC << endl;
}

Measured memory_bytes: 3596
def comb(n,m,p=10**9+7):
    if n < m : return 0
    if n < 0 or m < 0:return 0
    m = min(m, n-m)
    top = bot = 1
    for i in range(m):
        top = top*(n-i) % p
        bot = bot*(i+1) % p
    bot = pow(bot, p-2, p)
    return top*bot % p

def s(n,m):
    return comb(n+m+2, m+1, mod)

mod = 10**9+7

r1,c1,r2,c2 = map(int, input().split())

ans = s(r2,c2) - s(r2, c1-1) - s(r1-1, c2) + s(r1-1, c1-1)
ans %= mod
print(ans)

Measured memory_bytes: 38512
#include "bits/stdc++.h"

using namespace std;
typedef long long int ll;
typedef pair<ll, ll > pi;  
typedef pair<pair<ll, ll >, ll > pii;  
vector<ll > vec;
vector<vector<ll > > vec2;
ll MOD = 1000000007;
ll INF = 1145141919454519;

int main() {

    vector<ll > A(3, 0);
    cin >> A[0] >> A[1] >> A[2];

    if(A[0] == A[1] && A[1] == A[2]){
        cout << 0 << endl;
        return 0;
    }

    ll ans = 0;
    while(true){
        sort(A.begin(), A.end());
        if(A[0] == A[1] && A[1] == A[2]){
            cout << ans << endl;
            return 0;            
        }else if(A[0] == A[1] && A[1] != A[2]){
            A[0]++;
            A[1]++;
        }else{
            A[0]+=2;
        }
        ans++;
    }

}

Measured memory_bytes: 256
A, B = [int(i) for i in input().split()]
S = input()
for i in range(A+B+1):
    if i==A:
        if S[i]=='-':
            continue
        else:
            print("No")
            quit()
    else:
        try:
            int(S[i])
        except:
            print("No")
            quit()
print("Yes")

Measured memory_bytes: 3060
n = int(input())

t0, x0, y0 = 0, 0, 0
cnt = 0

for _ in range(n):
    t, x, y = map(int, input().split())
    diff_t = t-t0
    distance = abs(x0-x)+abs(y0-y)
    if diff_t >= distance and (diff_t - distance == 0 or (diff_t - distance) % 2 == 0):
        cnt += 1
    t0, x0, y0 = t, x, y

print('Yes' if cnt == n else 'No')


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <atcoder/all>

using namespace std;
using namespace atcoder;
using usize = ::std::size_t;
using u64 = ::std::int_least64_t;
//using u64 = long long;
static constexpr u64 Inf = ::std::numeric_limits<u64>::max() / 2;


int main(int argc, char *argv[])
{
    
    
    cin.tie(0) ;
    ios::sync_with_stdio(false) ;
    
    int N, Q;
    cin >> N >> Q;
    
    dsu d(N);
    while (Q--) {
        int t, u, v;
        cin >> t >> u >> v;
        if (!t) {
            d.merge(u, v);
        } else {
            cout << (d.same(u, v) ? 1 : 0) << endl;
        }
    }
    
    
    return 0;
    
}


Measured memory_bytes: 3928
#include <bits/stdc++.h>
#include<chrono>
using namespace std;
using ll = long long;

int main() {
  int N;
  cin >> N;
  vector<int> D(N);
  for (int i = 0; i < N; i++) {
    cin >> D[i];
  }
  sort(D.begin(), D.end());
  int left = D[N/2 - 1];
  int right = D[N/2];
  
  cout << right - left << endl;
}


Measured memory_bytes: 640
module Main where
-- import Debug.Trace
import Data.List
import Data.Char
import Data.Array
import Data.Maybe
import Data.Ord
import Control.Monad

solve :: Int -> [Int] -> [[Int]]
solve n l = iter 0 (0, listArray (0, n-1) l) where
    iter p (c, ar)
        | p >= n    = [elems ar, [c]]
        | otherwise = iter (p+1) (setMin p p) where
            setMin i mi
                | i < n     = setMin (i+1) $ if ar!i < ar!mi then i else mi
                | mi == p   = (c, ar) 
                | otherwise = (c+1, ar // [(p, ar!mi), (mi, ar!p)])

readLine:: IO [Int]
readLine = fmap (map read . words) getLine

main :: IO() 
main = do
    n <- readLn :: IO Int
    l <- readLine
    mapM_ putStrLn $ map (\y -> init (concatMap (\x-> show x ++ " ") y)) (solve n l)



Measured memory_bytes: 4132
#include <iostream> 
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mk make_pair
#define MAX 1000001
ll prime[MAX];
#define FAST           ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define mod 1000000007

ll rec(vector<vector<ll> >& dp,vector<ll>& arr,int n,int i,int k,int w)
{
  ll ans=0;
  if(i>=n)
    return 0;

  if(dp[i][k]!=-1)
    return dp[i][k];


  if(k!=0)
  ans=max(rec(dp,arr,n,i+1,w,w),arr[i]+rec(dp,arr,n,i+1,k-1,w));
  else
  ans=max(rec(dp,arr,n,i+1,k,w),rec(dp,arr,n,i+1,w,w));

  return dp[i][k]=ans;

}

//ll t[400008];
// void build(vector<ll>& a, int v, int tl, int tr) {
//     if (tl == tr) {
//         t[v] = a[tl];
//     } else {
//         int tm = (tl + tr) / 2;
//         build(a, v*2, tl, tm);
//         build(a, v*2+1, tm+1, tr);
//         t[v] = max(t[v*2] ,t[v*2+1]);
//     }
// }

// ll maxi(int v, int tl, int tr, int l, int r) {
//     if (l > r) 
//         return 0;
//     if (l == tl && r == tr) {
//         return t[v];
//     }
//     int tm = (tl + tr) / 2;
//     return max(maxi(v*2, tl, tm, l, min(r, tm)) ,maxi(v*2+1, tm+1, tr, max(l, tm+1), r));
// }



// void update(int v, int tl, int tr, int pos, ll new_val) {
//     if (tl == tr) {
//         t[v] = new_val;
//     } else {
//         int tm = (tl + tr) / 2;
//         if (pos <= tm)
//             update(v*2, tl, tm, pos, new_val);
//         else
//             update(v*2+1, tm+1, tr, pos, new_val);
//         t[v] = max(t[v*2] ,t[v*2+1]);
//     }
// }


struct hash_pair {
   template <class T1, class T2>
   size_t operator()(const pair<T1, T2>& p) const{
      auto hash1 = hash<T1>{}(p.first);
      auto hash2 = hash<T2>{}(p.second);
      return hash1 ^ hash2;
   }
};

ll rec(ll a[],ll first,ll last,int n)
{
  if(first>last)
    return 0;

  ll temp=1000000000;
  ll ind=0;
  for(ll i=first;i<=last;i++)
   {
    if(temp>a[i])
    {
      temp=a[i];
      ind=i;
    }
   }
   for(ll i=first;i<=last;i++)
    a[i]-=temp;


return min(last-first+1,(rec(a,first,ind-1,n)+rec(a,ind+1,last,n)+temp));

}
int main() { 
string s,t;
cin>>s>>t;
int n=s.size();
int m=t.size();
int ans=INT_MAX;
for(int i=0;i<n-m+1;i++)
{
  int c=0;
  for(int j=0;j<m;j++)
  {
    if(s[i+j]!=t[j])
    {
     c++;
    } 
  }
ans=min(ans,c);

}

cout<<ans;
return 0;

}


Measured memory_bytes: 3608
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <tuple>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repd(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
#define repdm(i, a, b) for (ll i = (ll)(a); i > (ll)(b); i--)

int gcd(int x, int y)
{
  if (y == 0)
    return x;

  return gcd(y, x % y);
}

int main()
{

  int N;
  cin >> N;
  int a[N];

  int pre = 0;
  rep(i, N)
  {
    cin >> a[i];
    if (i == 0)
    {
      pre = a[i];
      continue;
    }
    pre = gcd(pre, a[i]);
  }
  cout << pre;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
    std::ios::sync_with_stdio(false);
    ll a, b;
    cin >> a >> b;
    if (a == b) {
        cout << "1\n";
        return 0;
    }
    ll r = 60;
    while ((a & (1LL << r)) == (b & (1LL << r))) {
        r--;
    }
    a &= (1LL << (r + 1)) - 1;
    b &= (1LL << (r + 1)) - 1;
    ll k = r - 1;
    while (k >= 0 && ((1LL << k) & b) == 0) {
        k--;
    }
    ll ans = (1LL << (r + 1)) - a;
    if (a > (1LL << (k + 1))) {
        ans -= a - (1LL << (k + 1));
    }
    cout << ans << "\n";
    return 0;
}


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

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define mp make_pair
#define pb push_back
#define pf push_front
#define fi first
#define se second

int H,W,h,w;

int main(){
  cin >> H >> W >> h >> w;
  int ans = H*W;
  ans -= (H*w+W*h-h*w);
  cout << ans <<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
#include <algorithm>
int main(void){

	int n, m;
	int i = 1;

	cin >> n >> m;

	int num[101];

	for ( i = 1; i <= n; i++){

		cin >> num[i];
	}

	for (int k = 1; k <= m; k++){

		i = 1;
		while (i != n){

			if (num[i] % k > num[i + 1] % k)
				swap(num[i], num[i + 1]);
			i++;
		}
	}

	for (i = 1; i <= n; i++) cout << num[i] << endl;
}

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

#define o(output) cout << output << endl

using namespace std;

string s;
int a,b,c,d,e;
char A,B;
priority_queue<int,vector<int>,greater<int> >small;

int main(){
  cin >> a >> b >>c;
  if(c>=a&&c<=b)o("Yes");
  else o("No");
}

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

int main() {

    int n, ntemp;

    scanf("%d", &n);

    int cnt = 0;
    while (pow(10, cnt) <= n) {
        cnt++;
    }
    
    int mysum = 0;
    ntemp = n;

    for (int i = cnt; i >= 1; i--) {
        int temp = ntemp / pow(10, i - 1);
        mysum += temp;
        ntemp -= temp * pow(10, i - 1);
    }

    if (n % mysum == 0) {
        puts("Yes");
    } else {
        puts("No");
    }
    return 0;
}


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

#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 each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;

#define INF INT_MAX/3

#define MAX_N 1000

int h,w,k;
char s[33][33],sav[33][33];

int dfs(int d){
	rep(j,w){
		for(int i=h-1;i>=0;i--){
			if(s[i][j]=='0'){
				for(int ii=i-1;ii>=0;ii--){
					if(s[ii][j]!='0'){
						swap(s[ii][j],s[i][j]);
						break;
					}
				}
			}
		}
	}
	int res=0;
	rep(i,h){
		char pre='-';
		int cnt=0;
		rep(j,w){
			if(pre==s[i][j]&&s[i][j]!='0')cnt++;
			else{
				pre=s[i][j]; cnt=1;
			}
			if(cnt>=k&&(j==w-1||s[i][j+1]!=pre)){
				res+=pow(2,d)*(s[i][j]-'0')*cnt;
				int l=j;
				while(cnt>0){
					s[i][l]='0';
					l--; cnt--;
				}
			}
		}
	}
	if(res==0)return 0;
	else return res+dfs(d+1);
}

int main(){
	cin.sync_with_stdio(false);
	cin>>h>>w>>k;
	rep(i,h)cin>>s[i];
	int res=-1;
	rep(i,h)rep(j,w){
		memcpy(sav,s,sizeof(s));
		s[i][j]='0';
		maxch(res,dfs(0));
		memcpy(s,sav,sizeof(sav));
	}
	cout<<res<<endl;
	return 0;
}


Measured memory_bytes: 256
import bisect

def isin(a, x):
    'Locate the leftmost value exactly equal to x'
    i = bisect.bisect_left(a, x)
    if i != len(a):
        if a[i] == x:
            return 1
    return 0



while(1):
    try:
        p,q=map(int,raw_input().split())
        rem=[]
        rem2=[]
        ans1=''
        ans2=''
        while(1):
            if p==0:
                print ans1
                break
            elif not isin(rem,p):
                bisect.insort(rem,p)
                rem2.append(p)
                p*=10
                ans1+=str(p/q)
                p%=q
            else:
                ind=rem2.index(p)
                stl=len(ans1)
                ans2+=' '*(ind)+'^'*(stl-ind)
                print ans1
                print ans2
                break
    except:
        break

Measured memory_bytes: 6380
#include<stdio.h>
#include<math.h>
int cplc(int p0[2],int p1[2],int p2[2],int r,double s[2],double t[2]){
  int x1=p1[0]-p0[0],y1=p1[1]-p0[1],x2=p2[0]-p0[0],y2=p2[1]-p0[1];
  long long a=x1*x1+y1*y1,b=x1*x2+y1*y2,c=x2*x2+y2*y2-r*r;
  double d=sqrt(b*b-a*c);
  if(d<0)return 0;
  s[0]=p0[0]+x1*(b+d)/a;
  s[1]=p0[1]+y1*(b+d)/a;
  t[0]=p0[0]+x1*(b-d)/a;
  t[1]=p0[1]+y1*(b-d)/a;
  return 1;
}
int main(){
  int p[4][2],n,i,r,j=0;
  double a[2][2],e=0.000005;
  scanf("%d %d %d %d",&p[2][0],&p[2][1],&r,&n);
  while(n--){
    for(i=0;i<4;i++)scanf("%d",&p[i/2][i%2]);
    cplc(p[0],p[1],p[2],r,a[0],a[1]);
    if(fabs(a[0][0]-a[1][0])<e)j=a[0][1]+e<a[1][1]?0:1;
    else                       j=a[0][0]+e<a[1][0]?0:1;
    printf("%.9f %.9f %.9f %.9f\n",a[j][0],a[j][1],a[1-j][0],a[1-j][1]);
  }
  return 0;
}

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

using namespace std;

int m, n;
int a[100][100];
int di[] = {-1, 0, 0, 1}, dj[] = {0, -1, 1, 0};

int f(int si, int sj) {  
  int res = 0;
  for (int i = 0; i < 4; i++) {
    int ni = si + di[i], nj = sj + dj[i];
    if (ni >= 0 && ni < n && nj >= 0 && nj < m && a[ni][nj]) {
      a[ni][nj] = 0;
      res = max(res, f(ni, nj));
      a[ni][nj] = 1;
    }
  }
  return res + 1;
}

int main(void) {
  while (cin >> m >> n, m) {
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        cin >> a[i][j];
      }
    }

    int ans = 0;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        if (!a[i][j]) continue;
        a[i][j] = 0;
        ans = max(ans, f(i, j));
        a[i][j] = 1;        
      }
    }

    cout << ans << endl;
  }

  return 0;
}


Measured memory_bytes: 3068
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
// const ll MOD = 1000000007;
// const int INF = 2000000000;

ll N;
vector<ll> A;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> N;
  A.resize(N);
  for (ll i = 0; i < N; i++) {
    cin >> A[i];
  }

  vector<ll> cum_A(N + 1, 0);
  for (int i = 1; i <= N; i++) {
    cum_A[i] = cum_A[i - 1] + A[i - 1];
  }
  sort(cum_A.begin(), cum_A.end());

  ll ans = 0;
  ll i = 1;
  while (i <= N) {
    ll l = 0;
    while (i <= N && cum_A[i - 1] == cum_A[i]) {
      l++;
      i++;
    }
    ans += l * (l + 1) / 2;
    i++;
  }

  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3456
#include <bits/stdc++.h>
#ifdef Wavator
#define de(...) fprintf(stderr, __VA_ARGS__), fflush(stderr);
#else
#define de(...) 98;
#endif
#define pb push_back
#define XX first
#define YY second
#define rep(i, a, b) for (auto i = (a); i < (b); ++i)
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VLL;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef vector<pair<int, int> > VP;
const int N = 100005;

int main()
{
#ifdef Wavator
    freopen("test.in", "r", stdin);
#endif
    int n;
    ll t;
    ll now = 0, mx = 0;
    scanf("%d%lld",&n,&t);
    while (n--)
    {
        ll x;
        scanf("%lld", &x);
        mx = max(mx, x);
        ll q = 1 + (t - now) / mx;
        ll p = (t - now) % mx;
        if (p - x >= 0)
            q++;
        if (q <= 0)
            q = 1;
        printf("%lld\n", q);
        now += x;
    }
    return 0;
}


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


using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0; i<int(n); i++)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVC vector<vector<char>>
#define fore(i,a) for(auto &i:a)

typedef pair <int, int> P;
template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
const int  INF = 1 << 30;
const ll INFL = 1LL<<60;
const ll mod = 1000000007;		





int main() {

	ll x, y, z, k;
	cin >> x >> y >> z >> k;

	VLL a(x), b(y), c(z);

	REP(i, x)cin >> a[i];
	REP(i, y)cin >> b[i];
	REP(i, z)cin >> c[i];

	VLL v(x*y);
	REP(i, x) {
		REP(j, y) {
			v[i*y + j] = a[i] + b[j];
		}
	}


	sort(ALL(v));
	reverse(ALL(v));
	
	VLL ans(k*z);
	REP(i, min(k,x*y)) {
		REP(j, z) {
			ans[i*z + j] = v[i] + c[j];
		}
	}
	sort(ALL(ans));
	reverse(ALL(ans));
	REP(i, k)cout << ans[i] << endl;


}



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

using namespace std;
typedef long long ll;

#define pb push_back
#define forn(i, n) for (int i = 0; i < (int)(n); i++)
#define forrn(i, s, n) for (int i = (int)(s); i < (int)(n); i++)
#define PYMOD(a, m) ((((a) % (m)) + (m)) % (m))
#define all(v) v.begin(), v.end()
#define mp make_pair
#define ff first
#define ss second

const int mod = 1e9 + 7;

int main() {
    // Code here:

    ll n, m;
    cin >> n >> m;

    if (n == 1 && m == 1)
        cout << 1 << endl;
    else if (n == 1)
        cout << m - 2 << endl;
    else if (m == 1)
        cout << n - 2 << endl;
    else
        cout << (n - 2) * (m - 2) << endl;
    
    return 0;
}


Measured memory_bytes: 256
#リストAの丸太を全てx以下にK回以内の切る回数で揃えることができるかを判断する関数。
def can_or_cannot(A,K,x):
    kaisuu_sum = 0
    for i in range(len(A)):
        if A[i]%x == 0:
            temp = (A[i]//x) - 1
            kaisuu_sum += temp
        else:
            temp = A[i]//x
            kaisuu_sum += temp

        if kaisuu_sum > K:
            return 'No'

    return 'Yes'

def main():
    N,K = map(int,input().split())
    A = list(map(int,input().split()))
    A.sort()
    #二分探索するよ
    left = 0
    right = A[N-1]

    if right == 1:
        return 1

    mid = 0
    while True:
        if right == 1:
            return 1
            
        mid = int( (left + right)/2 )
        #print(left,mid,right)
        judge = can_or_cannot(A,K,mid)
        #print(left,mid,right,judge)
        if judge == 'No':
            left = mid+1
        elif judge == 'Yes':
            right = mid

        if left == right:
            #print(left,mid,right)
            return right

print(main())


Measured memory_bytes: 30920
#include <iostream>
#include <fstream>
#include <vector>
#include <deque>
#include <set>
#include <map>
#include <unordered_map>
#include <list>
#include <array>
#include <cstdlib>
#include <stack>
#include <string>
#include <queue>
#include <chrono>
#include <functional>
#include <limits>
#include <cmath>
#include <algorithm>
#include <random>
#include <regex>
#include <tuple>
#include <numeric>
#include <cassert>
#include <utility>
#include <bitset>
#include <complex>
#include <iomanip>
#include <ostream>
#include <sstream>
#include <ctime>
using namespace std;
#define for0(i, n) for(int i = 0; i < n; i++)
#define for1(i, n) for(int i = 1; i <= n; i++)
#define pb push_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define V vector<int>
#define VP vector<pair<int, int> >
#define FASTIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define index INDEX
#ifndef ONLINE_JUDGE
#define print(x) PRINT(x, #x)
template<typename T> void PRINT(T VARIABLE, const string& NAME) {
	cerr << NAME << " = " << fixed << VARIABLE << "\n";
}
#else
#define print(x) 0 
#endif
int generate_random() {
	const int MAX_RANDOM = (int)1e6;
	mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	return uniform_int_distribution<int>(0, MAX_RANDOM)(rng);
}
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll INFLL = 2 * (ll)1e18 + 100;
#define int ll
#ifdef int 
const int INFINT = INFLL;
#else
const int INFINT = 2 * (int)1e9 + 100;
#endif
const double PI = atan(1) * 4;
const double EPS = 1e-6;
const int SEED = (int)1e3 + 7;
const int MOD = (int)1e9 + 7;
const int NMAX = (int)3 * 1e3 + 5;

double p[NMAX];
double dp[NMAX][NMAX];

int32_t main() {
#ifndef ONLINE_JUDGE
	double START_PROGRAM = clock();
#endif
	srand(time(NULL));
	cout << setprecision(20) << fixed;
	FASTIO;
    int n;
    cin >> n;
    for1(i, n) cin >> p[i];
    
    dp[1][1] = p[1];
    dp[1][0] = 1 - p[1];
    for(int i = 2; i <= n; i++)
    {
        dp[i][0] = dp[i - 1][0] * (1 - p[i]);
        for1(j, i) dp[i][j] = dp[i - 1][j] * (1 - p[i]) + dp[i - 1][j - 1] * p[i];
    }

    double sol = 0;
    for(int j = n / 2 + 1; j <= n; j++) sol += dp[n][j];
    cout << sol;




#ifndef ONLINE_JUDGE
	double END_PROGRAM = clock();
	double ELAPSED_TIME = (END_PROGRAM - START_PROGRAM) / CLOCKS_PER_SEC;
	cerr << "\n\nElapsed Time: " << ELAPSED_TIME * 1000 << "\n";
#endif
	return 0;
}






Measured memory_bytes: 68992
#include<bits/stdc++.h>
using namespace std;
int main()
{
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);cout.tie(NULL);
        int n,ans;
        cin>>n;
        if(n%1000==0){
                ans=0;
        }
        else{
                ans=1000-n+1000*(n/1000);
        }
        cout<<ans;
        
return 0;
}
/*

        creation time:  13.09.2020 09:23:27

*/                      



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

int main(){
    int k;
    cin >> k;
    queue<long long> que;
    for(long long i = 1; i <= 9; i++){
        que.push(i);
    }
    for(long long i = 1; i < k; i++){
        long long tmp = que.front();
        if(tmp % 10 != 0){
            que.push(10 * tmp - 1 + (tmp % 10));
        }
        que.push(10 * tmp + (tmp % 10));
        if(tmp % 10 != 9){
            que.push(10 * tmp + 1 + (tmp % 10));
        }
       // cout << que.front() << endl;
        que.pop();
    }
    cout << que.front() << endl;
    return 0;
}


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

int main() {
  int n;
  cin >> n;
  vector<string> s(n);
  for (auto& e : s) {
    cin >> e;
    reverse(e.begin(), e.end());
    e.insert(e.end() - 1, 'a' - 1);
  }
  sort(s.begin(), s.end());

  vector<vector<bitset<27>>> v(n);
  for (int i = 0; i < n; i++) {
    int l = s[i].size();
    v[i].resize(l + 1);
    for (int j = l - 1; j >= 0; j--) {
      v[i][j][s[i][j] - ('a' - 1)] = true;
      v[i][j] |= v[i][j + 1];
    }
  }

  int r = 0;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      int li = s[i].size(), lj = s[j].size();
      if (li > lj || s[i].substr(0, li - 2) != s[j].substr(0, li - 2)) break;
      if (v[j][li - 2][s[i].back() - ('a' - 1)]) r++;
    }
  }
  cout << r << endl;
}


Measured memory_bytes: 27556
#include <utility>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <cmath>
#include <numeric>
#include <limits>
#include <queue>
#include <cstdint>


#define ll long long int
#define rep(i,rept) for (ll i = 0; i < rept; i++)
#define Yes(b) std::cout<< (b ? "Yes" : "No")<<std::endl
#define YES(b) std::cout<< (b ? "YES" : "NO")<<std::endl
#define fr first
#define se second
#define se second
#define lolo 92233720368547757
#define susu 1000000007

using namespace std;
int64_t combination(int64_t n, int64_t r) {
	if (r * 2 > n) r = n - r;
	int64_t dividend = 1;
	int64_t divisor = 1;
	for (int64_t i = 1; i <= r; ++i) {
		dividend *= (n - i + 1);
		divisor *= i;
	}
	
	return dividend / divisor;
}
int main() {
	map<int64_t, int> ma = {};
	int64_t sum = 0 , k;
	ll n, m, a[100000] = {};
	vector<int64_t> v = {};
	cin >> n >> m;
	rep(i, n) {
		cin >> k;
		if (i != 0) {
			a[i] = (a[i - 1] + k) % m;
		}
		else a[i] = k % m;
		if (a[i] == 0) {
			sum++;
		}
		if (ma[a[i]] == 0) {
			v.emplace_back(a[i]);
		}
		ma[a[i]]++;
	}
	rep(i, v.size()) {
		if (ma[v[i]] == 1) {
			continue;
		}
		sum += combination(ma[v[i]], 2);

		
	}
	cout << sum;
	return 0;
}

Measured memory_bytes: 5496
n = int(input())
dat = list(map(int, input().split()))

import collections
buf = collections.Counter(dat)
dat = []
dat = list(buf.keys())

dat.sort()

res = 0

used = [False] * (1000100)

for i in range(len(dat)):
    ok = True

    if used[dat[i]]:
        ok = False
    if buf[dat[i]] != 1:
        ok = False

    c = 0
    v = -1
    while True:
        c += 1
        v = dat[i] * c
        if v > 1000010:
            break
        used[v] = True

    used[dat[i]] = True

    if ok:
        res += 1
#print(used[:10])
print(res)


Measured memory_bytes: 116592
#include <iostream>
#include <cmath>
using namespace std;
int main(void){
    int n=0, ph=0, pt=0;
    string ct, ch;
    cin >> n;
    for(int i=0;i<n;i++) {
        cin >> ct >> ch;
        if(ct == ch) {
            pt++;
            ph++;
            continue;
        }
        for(int j=0;j<fmin(ct.size(), ch.size());j++) {
            if(ct[j] < ch[j]) {
                ph += 3;
                break;
            } else if (ct[j] > ch[j]) {
                pt += 3;
                break;
            }
            if(j == fmin(ct.size(), ch.size()) - 1) {
                if(ct.size() < ch.size()) {
                    ph += 3;
                } else {
                    pt += 3;
                }
            }
        }
    }
    cout << pt << " " << ph << endl;
}

Measured memory_bytes: 3168
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); ++i)
typedef long long ll;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
const ll INF = 1LL << 60;

int main(){
	string s1, s2, s3;
	cin >> s1 >> s2 >> s3;
	char diff = 'A' - 'a';
	printf("%c%c%c\n", s1[0] + diff, s2[0] + diff, s3[0] + diff);

}


Measured memory_bytes: 256
import numpy as np
W = []
sum1 = 0
sum2 = 0
delta = []
N = int(input())
W = list(map(int, input().split()))

for i in range(N-1):
    sum1 = sum(W[:i+1])
    sum2 = sum(W[i+1:])
    #print(sum1,sum2)
    delta.append(abs(sum1-sum2))

print(min(delta))

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

#define FOR(i,a,n) for (int i = a; i < (int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define whole(f,x,...) ([&](decltype((x)) whole) { \
    return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)
template<typename T> bool chmin(T &a, const T &b) {if (a > b) { a = b; return true; }return false;}
template<typename T> bool chmax(T &a, const T &b) {if (a < b) { a = b; return true; }return false;}

using ll = int_fast64_t;

constexpr ll INF = (1e9);
constexpr ll MOD = (1e9+7);

int main() {
  int n, k; cin >> n >> k;
  vector<int> a(n); REP(i,n) cin >> a[i];
  vector<int> v(n);
  int min;
  min = a[0]; v[0] = 0;
  FOR(i, 1, n) {
    if (a[i] > min) v[i] = a[i] - min;
    else min = a[i];
  }
  whole(sort, v, greater<int>());
  int ans = 0;
  REP(i,n) {
    if (v[i] == v[0]) ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1152
import sys
def input():
    return sys.stdin.readline()
N = int(input().rstrip())
*A, = map(int, input().rstrip().split())
ans = sum(A)
dic = {}
for a in A:
    if a in dic:
        dic[a] += 1
    else:
        dic[a] = 1
Q = int(input().rstrip())
for _ in range(Q):
    B, C = map(int, input().rstrip().split())
    if B not in dic:
        dic[B] = 0
    if C not in dic:
        dic[C] = 0
    ans += (C-B) * dic[B]
    dic[C] += dic[B]
    dic[B] = 0
    print(ans)

Measured memory_bytes: 23768
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;

int main()
{
	int N;
	cin >> N;
	vector<int> t(N);
	vector<int> v(N);
	vector<int> maxV;
	for (auto i = 0; i < N; ++i)
	{
		cin >> t[i];
	}
	for (auto i = 0; i < N; ++i)
	{
		cin >> v[i];
	}

	t.push_back(0);
	v.push_back(0);
	maxV.push_back(0);
	for (auto i = 0; i <= N; ++i)
	{
		if (maxV[i] > v[i])
		{
			maxV[i] = v[i];
			for (auto j = i - 1; j >= 0; --j)
			{
				if (maxV[j] <= maxV[j + 1])
				{
					break;
				}
				auto diff = maxV[j] - maxV[j + 1];
				maxV[j] -= max(0, diff - t[j]);
			}
		}
		maxV.push_back(min(maxV[i] + t[i], v[i]));
	}

	auto result = 0.0;
	for (auto i = 0; i < N + 1; ++i)
	{
		auto v0 = maxV[i];
		auto v1 = maxV[i + 1];
		if (v0 > v1)
		{
			auto temp = v0;
			v0 = v1;
			v1 = temp;
		}

		if (v1 >= v0 + t[i])
		{
			result += v0 * t[i];
			result += (v1 - v0) * t[i] / 2.0;
		}
		else if (v1 >= v[i])
		{
			auto temp = v1 - v0;
			result += temp * temp / 2.0;
			result += temp * v0;
			result += (t[i] - temp) * v1;
		}
		else if (v[i] - v0 + v[i] - v1 <= t[i])
		{
			auto temp = v[i] - v0;
			result += temp * temp / 2.0;
			result += v0 * temp;
			auto temp2 = v[i] - v1;
			result += temp2 * temp2 / 2.0;
			result += v1 * temp2;
			result += v[i] * (t[i] - temp - temp2);
		}
		else
		{
			auto t1 = (v1 - v0 + t[i]) / 2.0;
			auto t2 = t[i] - t1;
			result += t1 * t1 / 2.0;
			result += v0 * t1;
			result += t2 * t2 / 2.0;
			result += v1 * t2;
		}
	}

	cout << fixed << setprecision(10) << result << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long n,k;
    cin>>n>>k;
    long long a[n];
    for(int i=0;i<n;i++)cin>>a[i];
    long long sum=0;
    for(int i=0;i<n;i++)
        for(int j=1+i;j<n;j++)
            if(a[i]<a[j])swap(a[i],a[j]);
    for(int i=0;i<k;i++)sum+=a[i];
    cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

#define MAX_PRIME 1000000
bool isprime[MAX_PRIME+1];
vector<int> primes;
void init_prime(){
  fill(isprime, isprime+MAX_PRIME+1, true);
  isprime[0] = isprime[1] = false;
  for(int i = 2; i <= MAX_PRIME; i++) {
    if (isprime[i]) {
      primes.push_back(i);
      for(int j = i*2; j <= MAX_PRIME; j += i)
      isprime[j] = false;
    }
  }
}

int main(){
  init_prime();

  int X;
  cin >> X;

  while(!isprime[X]) X++;

  cout << X << endl;
  
  return 0;
}


Measured memory_bytes: 1916