akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
#include <deque>
#include <numeric>
#include <complex>

using namespace std;

#define mod 1000000007

int main()
{
	long long int n, k;
	cin >> n >> k;
	long long int a[200001];
	for(int i = 0; i < n; i++){
		cin >> a[i];
	}
	map<long long int, long long int> cnt;
	long long int sum = 0;
	long long int ans = 0;
	long long int tmp[200001] = {};
	cnt[0] = 1;
	for(int i = 1; i <= n; i++){
		// sum: [0, i)の和
		sum += a[i - 1];
		sum %= k;
		tmp[i] = (sum - (i % k) + k) % k;
		if(i >= k) cnt[tmp[i - k]]--;
		// if(i < k && tmp[i] == 0) ans++;
		if(cnt.find(tmp[i]) != cnt.end()){
			ans += cnt[tmp[i]];
			cnt[tmp[i]]++;
		} else {
			cnt[tmp[i]] = 1;
		}
		// cout << i << " " << tmp[i] << " " << ans << endl;
	}
	cout << ans << endl;
}


Measured memory_bytes: 15872
#!/usr/bin/env python3
import sys
try:
    from typing import List
except ImportError:
    pass


def solve(R: int, G: int):
    print(2 * G - R)


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


if __name__ == '__main__':
    main()


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

#define for_(i,a,b) for(int i=(a);i<(b);++i)

int main() {
	int N, A, B; cin >> N >> A >> B;
	string S; cin >> S;
	
	int a = 0, b = 0;
	for_(i,0,N) {
		if (S[i] == 'a') {
			if (a + b < A + B) { ++a; puts("Yes"); }
			else puts("No");
		}
		if (S[i] == 'b') {
			if (a + b < A + B && b < B) { ++b; puts("Yes"); }
			else puts("No");
		}
		if (S[i] == 'c') puts("No");
	}
}

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

int main() {
  int N;
  cin >> N;
  vector<int> d(N);
  for(int i = 0; i < N; i++){
    cin >> d.at(i);
  }
  int ans = 0;
  for(int i=0;i<N-1;i++){
    for(int j=i+1;j<N;j++){
      ans += d.at(i) * d.at(j);
    }
  }
  cout << ans << endl;
}


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

int main(void) {
  int A, B;
  int max;
  int i;

  max = 0;
  scanf("%d%d", &A, &B);
  for (i = 0; i < 2; i++) {
    if (A > B) {
      max += A;
      A--;
    } else {
      max += B;
      B--;
    }
  }
  printf("%d\n", max);
  fflush(stdout);
  return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<string>

using namespace std;

int main() {
	string s;
	int kaisi = 0, owari = 0, mojisu = 0;

	cin >> s;

	for (int i = 0; i < s.size(); i++) {
		if (s[i] == 'A') {
			for (int j = s.size() - 1; j > 0; j--) {
				if (s[j] == 'Z') {
					mojisu = j - i+1;
					break;
				}
			}
		}
		if (mojisu != 0) {
			break;
		}
	}

	cout << mojisu << endl;

	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <functional>
#include <iomanip>

using namespace std;

#ifdef LOCAL
    #define debug(v) cerr<<v<<"\n"
#else
    #define debug(...) 42
#endif
#define out(v) cout<<v<<"\n"
#define _overload3(_1,_2,_3,name,...) name
#define _all1(a) (a).begin(),(a).end()
#define _all2(a,n) (a),(a)+n
#define all(...) _overload3(__VA_ARGS__,42,_all2,_all1,)(__VA_ARGS__)
#define _rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _fromto2(i,n) for(int i=0;i<=(n);++i)
#define _fromto3(i,a,b) for(int i=(a);i<=(b);++i)
#define fromto(...) _overload3(__VA_ARGS__,_fromto3,_fromto2,)(__VA_ARGS__)

#define rrep(i,n) for(int i=(n);i>=0;--i)
#define iter(it,v) for(auto it=v.begin();it!=v.end();++it)
const int MOD = 1e9+7;
const int INF = 1e9;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<class T>ostream& operator<<(ostream& os, vector<T>& vec){os<<"{";for(int i=0;i<vec.size();++i)os<<(i?", ":"")<<vec[i];os<<"}";return os;}
template<class T1,class T2>ostream& operator<<(ostream& out,const pair<T1,T2>& rhs){out<<"("<<rhs.first<<", "<<rhs.second<<")";return out;}
#include<type_traits>
template<typename T,size_t SIZE,enable_if_t<!is_same<remove_cv_t<T>,char>::value,nullptr_t> = nullptr>ostream& operator<<(ostream& os,T(&arr)[SIZE]){os<<"{";for(size_t i=0;i<SIZE;++i)os<<(i?", ":"")<<arr[i];os<<"}";return os;}

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

int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  string S; cin >> S;
  if (S == "SUN")
    cout << 7;
    if (S == "MON")
      cout << 6;
    if (S == "TUE")
      cout << 5;
    if (S == "WED")
      cout << 4;
    if (S == "THU")
      cout << 3;
    if (S == "FRI")
      cout << 2;
    if (S == "SAT")
      cout << 1;

    cout << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>

#define CH(N,A,B) (A<=N&&N<B)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define RREP(i,a,b) for(int i=(b-1);a<=i;i--)
#define D first
#define C second

using namespace std;

const double INF = 1000000000.0;

//test
vector<string> sv;

double d[35][35][35];
bool visited[35][35][35];
int N,M,S,G;
pair<int, int> p[35][35];

struct ST{
  double ti;
  int bn;
  int cn;
  int sp;
  ST(double _ti, int _bn, int _cn, int _sp){
    ti = _ti;
    bn = _bn;
    cn = _cn;
    sp = _sp;
  }
  bool operator >(const ST &e) const{
    return ti > e.ti;
  }
};

int main() {
  while(1){
    cin>>N>>M;
    if(N==0 && M==0) break;
    cin>>S>>G;
    S--; G--;

    REP(i,0,N)REP(j,0,N)REP(k,0,35) d[i][j][k] = INF;
    REP(i,0,N)REP(j,0,N)REP(k,0,35) visited[i][j][k] = false;
    REP(i,0,N)REP(j,0,N) p[i][j].D = p[i][j].C = -1;

    bool flag = true;

    REP(i,0,M){
      int x,y,d,c;
      cin>>x>>y>>d>>c;
      p[x-1][y-1].D = p[y-1][x-1].D = d;
      p[x-1][y-1].C = p[y-1][x-1].C = c;
    }

    d[S][S][0] = 0.0;

    priority_queue< ST, vector<ST>, greater<ST> > PQ;
    ST st(0.0,S,S,0);
    PQ.push(st);


    while(!PQ.empty()){
      ST u = PQ.top(); PQ.pop();
      double mtime = u.ti;
      int ubn=u.bn, ucn=u.cn, usp=u.sp;
      //visited[ubn][ucn][usp] = true;
      if(d[ubn][ucn][usp] < mtime) continue;
      //cout<<"POP! "<<"u.ti: "<<u.ti<<"; u.bn: "<<u.bn<<"; u.cn: "<<u.cn<<"; u.sp: "<<u.sp<<endl;

      if(ucn == G && usp == 1){
        //printf("%.5lf\n",d[ubn][ucn][usp]);
        sv.push_back(to_string(mtime));
        flag = false;
        break;
      }

      visited[ubn][ucn][usp] = true;
      for(int v = usp-1; v <= usp+1; v++){
        if(v <= 0) continue;
        REP(next,0,N){
          if(/*visited[ucn][next][v] ||*/ p[ucn][next].D == -1 || p[ucn][next].C < v || ucn == next) continue;
          if(ubn == next) continue; //Uturn
          if(d[ucn][next][v] > mtime + (double)p[ucn][next].D/(double)v){
            d[ucn][next][v] = mtime + (double)p[ucn][next].D/(double)v;
            ST tst(d[ucn][next][v], ucn,next,v);
            PQ.push(tst);
            //cout<<"PUSH! "<<"u.ti: "<<d[ucn][next][v]<<"; u.bn: "<<ucn<<"; u.cn: "<<next<<"; u.sp: "<<v<<endl;
          }
        }
      }

    }
    if(flag){
      //cout<<"unreachable"<<endl;
      sv.push_back("unreachable");
    }
  }

  REP(i,0,sv.size()) cout<<sv[i]<<endl;

  return 0;
}

Measured memory_bytes: 3768
#!/usr/bin/ruby

NN = ARGF.gets.to_i

$mt = []
(NN - 1).times do
  $mt << ARGF.gets.split.shift.to_i
end
$mt += ARGF.gets.chomp.split.collect {|el| el.to_i}

$cache = Array.new(NN + 1) {Array.new(NN + 1)}

#p $mt

def calcmul(ss, ee)
  dif = ee - ss
  if dif <= 1
    return 0
  else
    cse = $cache[ss][ee]
    if cse.nil?
      if dif == 2
        #p ss, ee
        cse = $mt[ss] * $mt[ss + 1] * $mt[ss + 2]
      else
        kk = ss + 1
        #puts "#{ss}:#{kk}:#{ee}"
        cse = calcmul(ss, kk) + calcmul(kk, ee) + $mt[ss] * $mt[kk] * $mt[ee]
        for kk in (ss + 2)..(ee - 1)
          tcse = calcmul(ss, kk) + calcmul(kk, ee) + $mt[ss] * $mt[kk] * $mt[ee]
          if tcse < cse
            cse = tcse
          end
        end
      end
      $cache[ss][ee] = cse
    end
    return cse
  end
end

puts calcmul(0, NN)



Measured memory_bytes: 6968
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = (int)(a); i <= (int)(n); ++i)
#define rrep(i, a, n) for (int i = (int)(a); i >= (int)(n); --i)
#define debug(x) cerr << #x << " = " << x << "\n"
#define debugv(x) \
  rep(f, 0, (x.size() - 1)) cerr << x[f] << (f == (x.size() - 1) ? "\n" : " ")
#define all(x) x.begin(), x.end()
#define int long long
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
const int MX = 1e5 + 5, INF = 5 << 28, MOD = 1e9 + 7;

int N, A, B;
vi H;
void input() {
  cin >> N >> A >> B;
  H.resize(N);
  rep(i, 0, N - 1) { cin >> H[i]; }
}
bool enough(int t) {
  int cnt = 0;
  rep(i, 0, N - 1) {
    int rest = H[i] - t * B;
    if (rest > 0) {
      cnt += rest / (A - B) + (rest % (A - B) != 0);
    }
  }
  return cnt <= t;
}
int bs(int l, int r) {
  if (l == r) return l;
  int m = (l + r) / 2;
  return enough(m) ? bs(l, m) : bs(m + 1, r);
}
void solve() { cout << bs(0, INF) << endl; }
signed main() {
  input();
  solve();
  return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

ll d(ll x,int a){
    if(x==0) return 0;
    return x/a+d(x/a,a);
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    istream& in(cin);
    ostream& out(cout);
    ll n;
    in>>n;
    if(n&1) cout<<0<<endl;
    else cout<<d(n/2,5)<<endl;
}

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

void simulate(){
	int outCount=0;
	int point=0;

	bool *base;
	base = new bool[4];
	for (int i=0;i<4;i++){
		base[i]=false;
	}

	string event;
	while(outCount!=3){
		cin >> event;


		if(event == "HIT"){
			if(base[3]){
				point++;
				base[3]=false;
			}
			if(base[2]){
				base[3]=true;
				base[2]=false;
			}
			if(base[1]){
				base[2]=true;
				base[1]=false;
			}
			base[1]=true;
		}

		else if(event == "HOMERUN"){
			for(int i=1;i<=3;i++){
				if(base[i]){
					point++;
					base[i]=false;
				}
			}
			point++;
		}

		else if(event == "OUT"){
			outCount++;
		}

		else{
			cout << "undefined" << endl;
			exit(1);
		}

	}

	cout << point << endl;
}

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

	for(int i=0;i<n;i++){
		simulate();
	}

	return 0;
}



Measured memory_bytes: 3144
package main

import "fmt"

func main() {
	var S string
	fmt.Scanf("%s", &S)

	if isKaibun(S) && isKaibun(S[0:(len(S)-1)/2]) && isKaibun(S[(len(S)+3)/2-1:]) {
		fmt.Println("Yes")
		return
	}

	fmt.Println("No")
}

func isKaibun(s string) bool {
	for i := 0; i < len(s)/2; i++ {
		if s[i] != s[len(s)-1-i] {
			return false
		}
	}
	return true
}


Measured memory_bytes: 512
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <algorithm>
#include <climits>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <string>
#include <list>
#include <ctime>
#include <complex>
#include <bitset>
#include <tuple>
#include <functional>

#define IOS ios::sync_with_stdio(false);cin.tie(0)
#define all(x) x.begin(), x.end()
#define ff first
#define ss second
#define MOD 1000000007LL
#define rep(i,a,n) for (int i=a ; i<n ; i++)
#define per(i,a,n) for (int i=n-1 ; i>=a ; i--)
#define LLINF (llong)1e18+5
#define INF 1e9+1
#define endl '\n'

using namespace std;
using llong = long long;
using VI = vector<int>;
using VLL = vector<long long>;
using PII = pair<int, int>;

//struct cmp {
//	bool operator() (pair<PII, int> a, pair<PII, int> b)
//	{
//		return a.ss > b.ss;
//	}
//};

int main()
{
	IOS;
	
	int n;
	cin >> n;
	VI a(n);
	int cnt = 0;
	rep(i, 0, n) {
		cin >> a[i];
		if (i % 2 == 0 && a[i] % 2 == 1) cnt++;
	}
	cout << cnt;

	return 0;
}

Measured memory_bytes: 3620
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
const int MAXN=100005;
int a[MAXN],b[MAXN];
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        scanf("%d%d",&a[i],&b[i]);
    ll res=0;
    for(int i=n;i>=1;i--)
        res+=((b[i]-a[i]-res)%b[i]+b[i])%b[i];
    printf("%lld\n",res);
    return 0;
}

Measured memory_bytes: 1152
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <stack>
#include <cctype>
#include <complex>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <cassert>

using namespace std;
typedef complex<int> P;


vector<int> pnum;

int prime(int a){
	if(a == 1) return false;
	if(a == 2) return true;
	for(int i=2;i<sqrt(a)+1;i++){
		if(a%i==0) return false;
	}
	return true;
}

bool solve(){
	int a, b, n;
	cin>> a>> b>> n;
	if(a==0 && b==0 && n==0) return false;
	
	int cnt = 0;
	while(1){
		if(prime(a)) cnt++;
		if(cnt>=n) break;
		a += b;
	}
	
	cout<< a<< endl;
	return true;
}

int main(){
	cout.setf(ios::fixed);
	cout.precision(10);
	while(solve());

	return 0;
}

 

Measured memory_bytes: 1160
#include<iostream>
using namespace std;
int main()
{
	int a,b;
	cin>>a>>b;
	if(a==1&&b!=1)
	cout<<"Alice"<<endl;
	else
	if(b==1&&a!=1)
	cout<<"Bob"<<endl;
	else if(a>b)
	cout<<"Alice"<<endl;
	else if(a<b)
	cout<<"Bob"<<endl;
	else
	cout<<"Draw"<<endl;
	return 0;
}

Measured memory_bytes: 256
import math
def prime(g):
    l = []
    p = 2
    while p * p <= g:
        if g % p != 0:
            p += 1
            continue
        while g % p == 0:
            g //= p
        l.append(p)
        p += 1
    if g != 1:
        l.append(g)
    return len(l)

a, b = map(int, input().split())
g = math.gcd(a, b)
print(prime(g) + 1)


Measured memory_bytes: 9024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)

#define SIZE(x) ((ll)(x).size()) 
#define MAX(x) *max_element(ALL(x)) 
#define MIN(x) *min_element(ALL(x)) 
#define ALL(x) (x).begin(),(x).end() 

#define inf 1000000000000 
#define mod 1000000007 
#define MAXR 100000 

#define PB push_back 
#define MP make_pair 
#define F first 
#define S second 

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
    // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
bool is_prime(ll n){
    int a = sqrt(n);
    if(n == 1 || n == 2 || n == 3) return true;
    else{
        bool frag = true;
        FOR(i, 2, a+1){
            if(n % i == 0) frag = false;
        }
        return frag;
    }
}

struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};


int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, k;
    cin >> n >> k;
    combination m(n);
    FOR(i, 1, k+1){
        cout << m(n-k+1, i) * m(k-1, i-1) << endl;
    }
}


Measured memory_bytes: 3596
N = int(input())
S = [input() for _ in range(N)]
ans = 0
for k in range(N):
    f = True
    for i in range(N):
        for j in range(i + 1, N):
            if S[i][(j + k) % N] != S[j][(i + k) % N]:
                f = False
                break

        if not f:
            break
    if f:
        ans += N
print(ans)

Measured memory_bytes: 42480
#include <atcoder/all>
#include <iostream>

using namespace std;
using namespace atcoder;

int main(void) {
    int N, Q;
    cin >> N >> Q;

    fenwick_tree<int64_t> fen(N);
    for(int i=0; i<N; i++) {
        int a;
        cin >> a;
        fen.add(i, a);
    }

    while(Q--) {
        int t;
        cin >> t;
        if(t == 0) {
            int p, x;
            cin >> p >> x;
            fen.add(p, x);
        } else {
            int l, r;
            cin >> l >> r;
            cout << fen.sum(l, r) << endl;
        }
    }
    return 0;
}


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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)

void solve(int N) {
  for (int i = 1; i <= 9; i++) {
    for (int j = 1; j <= 9; j++) {
      if (i * j == N) {
        cout << "Yes" << endl;
        return;
      }
    }
  }
  cout << "No" << endl;
}

int main() {
  int N;
  cin >> N;
  solve(N);
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define xx first
#define yy second
#define mp make_pair
#define pb push_back
#define mset(x, y) memset(x, y, sizeof x)
#define mcpy(x, y) memcpy(x, y, sizeof x)
using namespace std;

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

inline int Read()
{
	int x = 0, f = 1, c = getchar();
	for (; !isdigit(c); c = getchar())
		if (c == '-')
			f = -1;
	for (;  isdigit(c); c = getchar())
		x = x * 10 + c - '0';
	return x * f;
}

const int MAXN = 20;
const int MAXM = 32780;

int n, m, tot, val[MAXM], adj[MAXN][MAXN], f[MAXM][MAXN];

int main()
{
#ifdef wxh010910
	freopen("data.in", "r", stdin);
#endif
	n = Read(), m = Read();
	for (int i = 1, x, y, w; i <= m; i ++)
		x = Read() - 1, y = Read() - 1, w = Read(), adj[x][y] = adj[y][x] = w, tot += w;
	for (int i = 0; i < 1 << n; i ++)
		for (int j = 0; j < n; j ++)
			if (i >> j & 1)
				for (int k = j + 1; k < n; k ++)
					if (i >> k & 1)
						val[i] += adj[j][k];
	mset(f, -1);
	for (int i = 1; i < 1 << n; i += 2)
		f[i][0] = val[i];
	for (int i = 1; i < 1 << n; i += 2)
		for (int j = 0; j < n; j ++)
			if (~f[i][j])
			{
				for (int s = (1 << n) - 1 ^ i, k = s; k; k = k - 1 & s)
					f[i | k][j] = max(f[i | k][j], f[i][j] + val[k | 1 << j]);
				for (int k = 0; k < n; k ++)
					if (adj[j][k] && !(i >> k & 1))
						f[i | 1 << k][k] = max(f[i | 1 << k][k], f[i][j] + adj[j][k]);
			}
	return printf("%d\n", tot - f[(1 << n) - 1][n - 1]), 0;
}


Measured memory_bytes: 2944
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
int main(void) {
	vector<long long> f;
	long long f1;
	long long a[110000];
	long long b[110000];
	vector<long long> p, pp, q, qq;
	long long c, d;
	long long k;
	long long l;
	long long n, m;
	long long s, t;
	long long x, y;
	long long le, ri, mi;
	long long np, nq;
	long long z;
	long long f0;
	long long start;
	scanf("%lld %lld %lld", &n, &l, &t);

	x = 0;
	y = 0;
	for (int i = 0; i < n; i++) {
		scanf("%lld %lld", &a[i], &b[i]);
		f1 = a[i] - (((b[i] * 2) - 3)*t);
		if (f1 < 0) {
			f1 = (-f1) % l;
			f1 = (l - f1) % l;
		}
		else f1 = f1 % l;
		if (i == 0)f0 = f1;
		f.push_back(f1);
		if (b[i] == b[0]) {
			pp.push_back(i);
		}
		else {
			qq.push_back(i);
		}
	}
	sort(f.begin(), f.end());
	if (b[0] == 1) {
		z = 0;
		for (int i = 0; i < qq.size(); i++) {
			x = a[qq[i]];
			x -= a[0];
			x = (x + l) % l;
			y = (l - x + (2 * t) - 1) / l;
			z = (z + y) % n;
		}
		for (int i = 0; i < f.size();i++) {
			if (f[i] == f0) {
				x = i - z;
				x = (x + n) % n;
				break;
			}
		}
		for (int i = 0; i < n; i++) {
			y = (x + i) % n;
			printf("%d\n", f[y]);
		}
	}
	else {
		z = 0;
		for (int i = 0; i < qq.size(); i++) {
			x = a[0];
			x -= a[qq[i]];
			x = (x + l) % l;
			y = (l - x + (2 * t) - 1) / l;
			y = y % n;
			y = (n - y) % n;
			z = (z + y) % n;
		}
		for (int i = f.size() - 1; i >= 0; i--) {
			if (f[i] == f0) {
				x = i - z;
				x = (x + n) % n;
				break;
			}
		}
		for (int i = 0; i < n; i++) {
			y = (x + i) % n;
			printf("%d\n", f[y]);
		}
	}
	return 0;

}

Measured memory_bytes: 4844
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <math.h>

// ===============================================================

using namespace std;
using ll = long long;
using vl = vector<long long>;
using vll = vector<vector<long long>>;
using vs = vector<string>;
using vc = vector<char>;
using vcc = vector<vector<char>>;
using vm = vector<short>;
using vmm = vector<vector<short>>;
using pii = pair<int, int>;
using psi = pair<string, int>;
using ld = long double;
using ull = unsigned long long;

// ===============================================================

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

ll lcm(ll a, ll b) //最小公倍数
{
	return a * b / gcd(a, b);
}

ll box(double a) //doubleの切り捨て
{
	ll b = a;
	return b;
}

ll fff(double a) //doubleの四捨五入
{
	ll b = a + 0.5;
	return b;
}

ll sum(ll n) { //整数sまでの合計
	if (n == 0) {
		return 0;
	}

	int s = sum(n - 1);
	return s + n;
}

bool prime(ll num)//素数判定、primeならtrue,違うならfalse
{
	if (num < 2) return false;
	else if (num == 2) return true;
	else if (num % 2 == 0) return false;
	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			return false;
		}
	}

	// 素数である
	return true;
}

// ===============================================================

int main() {
	ll a, b, c;
	cin >> a >> b >> c;
	vl e{ a + b,b + c,a + c };
	sort(e.begin(), e.end());
	cout << e[0];
}

Measured memory_bytes: 3584
N,M=map(int,input().split())
stu=[None]*N
for i in range(N):
  a,b=map(int,input().split())
  stu[i]=[a,b]
  
check=[None]*M
for i in range(M):
  c,d=map(int,input().split())
  check[i]=c,d

for i in range(N):
  minj=M
  minval=10**9
  for j in range(M):
    val=abs(stu[i][0]-check[j][0])+abs(stu[i][1]-check[j][1])
    if val<minval:
      minj=j+1
      minval=val
  print(minj)

Measured memory_bytes: 3064
n, k = map(int, input().split())
*P, = map(int, input().split())
x = sum((P[i]+1)/2 for i in range(k))
m = x
for i in range(1, n-k+1):
    x = x-(P[i-1]+1)/2+(P[i-1+k]+1)/2
    m = max(m, x)
print(m)


Measured memory_bytes: 25604
#include <stdio.h>
int main(){
  
    int A, B;
  
    scanf("%d", &A);
    scanf("%d", &B);
  
    if(A > B){
      printf("%d\n", A + A - 1);
    }
    else if(A == B){
      printf("%d\n", A + B);
    } 
    else if(A < B){
      printf("%d\n", B + B - 1);
    }
  
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=5e18;

typedef pair<double,ll> pdl;

int main() {
  double xs,ys,xg,yg;
  cin >> xs >> ys >> xg >> yg;
  ll n;
  cin >> n;
  vector<double> x(n+2);
  vector<double> y(n+2);
  vector<double> r(n);
  x[n]=xs;
  y[n]=ys;
  x[n+1]=xg;
  y[n+1]=yg;
  vector<vector<double>> d(n+2,vector<double>(n+2));
  d[n][n+1]=d[n+1][n]=sqrt((x[n]-x[n+1])*(x[n]-x[n+1])+(y[n]-y[n+1])*(y[n]-y[n+1]));
  for(ll i=0;i<n;i++) cin >> x[i] >> y[i] >> r[i];
  for(ll i=0;i<n;i++) {
    for(ll j=i+1;j<n+2;j++) {
      if(i==j) {
        d[i][j]=d[j][i]=0;
      }
      else if(j>=n) {
        d[i][j]=d[j][i]=max(sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]))-r[i],0.0);
      }
      else {
        d[i][j]=d[j][i]=max(sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]))-r[i]-r[j],0.0);
      }
    }
  }
  vector<double> ans(n+2,-1);
  priority_queue<pdl,vector<pdl>,greater<pdl>> q;
  q.push(pdl(0.0,n));
  while(q.size()) {
    double td=q.top().first;
    ll f=q.top().second;
    q.pop();
    if(ans[f]>-1) continue;
    ans[f]=td;
    for(ll i=0;i<n+2;i++) {
      if(ans[i]<0.0) {
        q.push(pdl(ans[f]+d[f][i],i));
      }
    }
  }
  cout << fixed << setprecision(10) << ans[n+1] << endl;
}

Measured memory_bytes: 18416
N,K = list(map(int,input().split()))
V =list(map(int,input().split()))

max_score = 0
for i in range(N+1):
    for j in range(N+1):
        if not (i+j>K or i+j>N):
    
            H=V[:i]+V[N-j:]
            H.sort()
            suteru=[]
            for k in range(min(len(H),K-i-j)):
                if H[k]>0:
                    break
                else:
                    suteru.append(H[k])
            max_score=max(sum(H)-sum(suteru),max_score)
       
print(max_score)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define rep(i,N) for(ll i=0; i<N; i++)
using namespace std;
using ll = long long;
int main(){
    ll N; cin >> N;
    ll a[N+1]; for(ll i=1; i<=N; i++) cin >> a[i];

    ll ball[N+1];
    for(ll i=N; i>=(N+1)/2+1; i--){
        if(a[i] == 1) ball[i] = 1;
        else ball[i] = 0;
    }
    for(ll i=(N+1)/2; i>=1; i--){
        ll j = 2; ll sum = 0;
        while(j*i <= N){
            sum += ball[i*j];
            j++;
        }
        if(sum % 2 == a[i]) ball[i] = 0;
        else ball[i] = 1;
    }
    ll sum = 0;
    for(ll i=1; i<=N; i++){
        if(ball[i] == 1) sum++;
    }
    cout << sum << endl;
    for(ll i=1; i<=N; i++){
        if(ball[i] == 1) cout << i << " ";
    }
}

Measured memory_bytes: 3968
#include <iostream>
int main() {
    int n,m;
    scanf("%d%d", &n, &m);
    int a[n][m], b[m];
    for (int i=0; i<n; i++) for (int j=0; j<m; j++) scanf("%d", &a[i][j]);
    for (int i=0; i<m; i++) scanf("%d", &b[i]);
    for (int i=0; i<n; i++) {
        int c=0;
        for (int j=0; j<m; j++) c += a[i][j] * b[j];
        printf("%d\n", c);
    }
    return 0;
}

Measured memory_bytes: 3236
import java.util.*;
import java.lang.Math;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    
   	int n = sc.nextInt();
    int stack;
    int count = 0;
    int count2;
    int div = 1;
    
    if(n < 105) System.out.println(0);
    else{
    	for(int i = 105;i <= n;i+=2){
          stack = i;
          div = 1;
          for(int j = 3;j <= stack;j += 2){
            count2 = 1;
          	while(stack % j == 0){
              stack /= j;
              count2++;
            }
            div *= count2;
          }
          if(div == 8) count++;
        }
      System.out.println(count);
    }

  }
}


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

using namespace std;

typedef unsigned uint;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ldbl;
typedef pair<int, int> pii;
typedef pair<uint, uint> puu;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pull;
typedef pair<double, double> pdd;
typedef vector<int> vi;
typedef vector<uint> vu;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef vector<pii> vpii;
typedef vector<puu> vpuu;
typedef vector<pll> vpll;
typedef vector<pull> vpull;
typedef vector<string> vstr;
typedef vector<double> vdbl;
typedef vector<ldbl> vldbl;
#define pb push_back
#define ppb pop_back
#define pfr push_front
#define ppfr pop_front
#define emp emplace
#define empb emplace_back
#define be begin
#define rbe rbegin
#define all(x) (x).be(), (x).end()
#define rall(x) (x).rbe(), (x).rend()
#define fir first
#define sec second
#define mkp make_pair
#define brif(cond) if (cond) break
#define ctif(cond) if (cond) continue
#define retif(cond) if (cond) return
void canhazfast() {ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);}
template<typename T> T gcd(T a, T b) {return b ? gcd(b, a%b) : a;}
template<typename T> T extgcd(T a, T b, T &x, T &y)
{
    T x0 = 1, y0 = 0, x1 = 0, y1 = 1;
    while (b) {
        T q = a/b; a %= b; swap(a, b);
        x0 -= q*x1; swap(x0, x1);
        y0 -= q*y1; swap(y0, y1);
    }
    x = x0; y = y0; return a;
}
int ctz(uint x) {return __builtin_ctz(x);}
int ctzll(ull x) {return __builtin_ctzll(x);}
int clz(uint x) {return __builtin_clz(x);}
int clzll(ull x) {return __builtin_clzll(x);}
int popcnt(uint x) {return __builtin_popcount(x);}
int popcntll(ull x) {return __builtin_popcountll(x);}
int bsr(uint x) {return 31^clz(x);}
int bsrll(ull x) {return 63^clzll(x);}

int main()
{
    canhazfast();

    constexpr int m = 2019;
    int l, r, ans = m;

    cin >> l >> r;
    retif(r-l > m) cout << "0\n", 0;
    for (int i = l+1; i <= r; ++i) {
        for (int j = l; j < i; ++j) ans = min(ans, (i%m)*(j%m)%m);
    }
    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
using namespace std;
int main() {
  int a, b, c;
  cin >> a >> b >> c;
  int r[110];
  int sum = 0;
  if(c == 0) {
    cout << "YES" << endl;
    return 0;
  }
  for(int i = 1; i < b; i++){
    r[i] = (a*i) % b;
    if(r[i] == 0) continue;
    if(c % r[i] == 0) {
      cout << "YES" << endl;
      return 0;
    }
  }
  cout << "NO" << endl;
  return 0;
}


Measured memory_bytes: 3684
#include<bits/stdc++.h>
using namespace std;
#define optimizar_io ios_base::sync_with_stdio(0); cin.tie(0);
#define fore(i, a, b) for(int i = a; i < b; i++)
#define fori(i, a, b) for(int i = a; i <= b; i++)
#define pb push_back
#define popb pop_back
#define mk make_pair
#define fi first
#define se second
#define endl '\n'
#define MAX 100005
typedef long long int lli;
typedef long double ld;
const double PI = acos(-1.0);
ld eps = 1e-9;

vector<lli> DP(MAX, -1);

lli dp(vector<lli> &h, int i) {
	if(i == (h.size() - 1)) return 0;
	if(i > h.size()-1) return MAX;	
	if(DP[i] != -1) return DP[i];
	return DP[i] = min(dp(h, i+1) + abs(h[i] - h[i+1]), dp(h, i+2) + abs(h[i] - h[i+2]));
}

int main() {
	optimizar_io
	int n; cin >> n;
	vector<lli> h(n);
	fore(i, 0, n) cin >> h[i];
	cout << dp(h, 0) << endl;
}

Measured memory_bytes: 4992
#include <iostream>
#include <string>

#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;
string keys[10];
string input;

void solve() {
    string ans;
    string now;
    int cnt = 0;
    for (auto c : input) {
        if (c == '0') {
            ans += now;
            now = "";
            cnt = 0;
        } else {
            now = keys[c - '0'][cnt];
            cnt++;
            cnt %= keys[c - '0'].size();
        }
    }
    cout << ans << endl;
}

int main() {
    keys[1] = ".,!? ";
    keys[2] = "abc";
    keys[3] = "def";
    keys[4] = "ghi";
    keys[5] = "jkl";
    keys[6] = "mno";
    keys[7] = "pqrs";
    keys[8] = "tuv";
    keys[9] = "wxyz";
    int n;
    cin >> n;
    rep(i, n) {
        cin >> input;
        solve();
    }
}

Measured memory_bytes: 3156
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.LinkedHashMap;
import java.util.Map;

public class Main {

	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int size = Integer.parseInt(br.readLine());
		int num = 0;
		Map<Integer, Boolean> inputMap = new LinkedHashMap<Integer, Boolean>();
		String[] inputNums = br.readLine().split(" ");
		for (int i = 0; i < size; i++) {
			num = Integer.parseInt(inputNums[i]);
			if (!inputMap.containsKey(num)) {
				inputMap.put(num, true);
			}
		}

		size = Integer.parseInt(br.readLine());
		inputNums = br.readLine().split(" ");
		int sum = 0;
		for (int i = 0; i < size; i++) {
			num = Integer.parseInt(inputNums[i]);
			if (inputMap.containsKey(num)) {
				sum += 1;
			}
		}
		System.out.println(sum);
	}
}

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

bool loop(string s){
    string r = s;
    reverse(r.begin(), r.end());
    if(s == r){
        return true;
    }else
    {
        return false;
    }
    
}


int main(void){
    string s;
    cin >> s;
    int n = s.length();
    string f = s.substr(0, (n-1)/2);
    string b = s.substr((n+3)/2-1, n);
   // cout << f << endl <<b <<endl;
    if(f != b || !loop(f)){
        cout << "No" << endl;
    }else{
        cout<< "Yes"<<endl;
    }
    return 0;
}

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

int main()
{
    ll n, k;
    cin >> n >> k;
    vector<ll> a(n);
    for(int i = 0; i < n; i++)
    {
        cin >> a[i];
    }

    ll beforeLoop = 0;
    ll next = a[0];
    set<ll> visited;
    visited.insert(1);
    ll loopStart = 0;
    while(true)
    {
        beforeLoop++;
        if(visited.find(next) != visited.end())
        {
            loopStart = next;
            break;
        }
        visited.insert(next);
        next = a[next - 1];
    }

    ll loopLenght = 0;
    next = a[loopStart - 1];
    while(true)
    {
        loopLenght++;
        if(next == loopStart)
        {
            break;
        }
        next = a[next - 1];
    }
    beforeLoop -= loopLenght;

    if(k < beforeLoop)
    {
        next = 1;
        for(int i = 0; i < k; i++)
        {
            next = a[next - 1];
        }

        cout << next;

        return 0;
    }

    ll jumpCount = k - beforeLoop;
    jumpCount = jumpCount % loopLenght;

    next = loopStart;
    for(int i = 0; i < jumpCount; i++)
    {
        next = a[next - 1];
    }

    cout << next;

    return 0;
}

Measured memory_bytes: 13928
/*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Code author: Saurabh Singhal
Code copy karne vaale tera muh kaala
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*/

#include<bits/stdc++.h>
#define mp(a,b) make_pair(a,b)
#define pb push_back
#define ppb pop_back

using namespace std;
typedef long long int ll;
typedef vector<ll> vi_t;
typedef vector<ll> vll_t;
ll t=1,n,m,k;
vll_t a,b;
int main(){
	//scanf("%d",&t);
	while(t--){
		cin>>n>>m;
		vector< pair<ll,ll> >v;
		for(ll i=0;i<n;i++){
			ll u,w;
			cin>>u>>w;
			v.pb(mp(u,w));
		}
		sort(v.begin(),v.end());
		ll count=0,price=0;
		for(ll i=0;i<n;i++){
			if(v[i].second+count<=m){
				price+=v[i].second*v[i].first;
				count+=v[i].second;
			}
			else{
				price+=(v[i].first*(m-count));
				count=m;
			}
		}
		cout<<price<<endl;
	}
}

Measured memory_bytes: 2420
#include <bits/stdc++.h>
#define debug(x) cerr << "\n" \
                      << #x << ": " << x << "\n"
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define INF (1LL << 30)
#define int long long
#define pii pair<long long, long long>
#define MOD 1000000007
#define print(x) cout << (x) << endl
using namespace std;
typedef long long ll;

int diff(int x, int y){
    if (x>y){
        return abs(x-y);
    }
    else return abs(y-x);
}
signed main()
{
    int N,K;
    cin>>N>>K;
    vector<int> X(N);
    rep(i,N){
        cin>>X[i];
    }
    /*
    min(abs(left),abs(right)) を加える
     */
/* 
    vector<int> WA(N,0);
    WA[0] = diff(X[0],0);
    FOR(i,1,N){
        WA[i] = WA[i-1] + diff(WA[i-1], X[i]);
    }
    */

    vector<int> anss;
    rep(i,N){
        if (i+K-1 < N){
            anss.push_back(diff(X[i+K-1],X[i]) + min(abs(X[i+K-1]),abs(X[i])));
        }
    }

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

    cout<<anss[0]<<endl;





    return 0;
}

Measured memory_bytes: 1660
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
/*
//#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
*/

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
/*
//#if __cplusplus >= 201103L
#include <array>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
*/
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 mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl

#define uni(x) x.erase(unique(all(x)),x.end())
template<class T,class U>inline void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>inline void chmax(T &t,U f){if(t<f)t=f;}
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) > (b) ? (b) : (a))

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

#define INF INT_MAX/3
#define MAX_N 1000
#define M_INF 1000000000
int n,m,v,i;
ll t,x,y;
void solve(){
   cin.tie(0);
  ios::sync_with_stdio(false);
  cin>>n;
  ll flg = 0;
  ll X = 0,Y = 0,T = 0;
  std::vector<PPI> v(n);
  rep(i,n) cin>>v[i].fi>>v[i].se.fi>>v[i].se.se;
  sort(all(v));
  i = 0;
  while(n--){
    t = v[i].fi;
    x = v[i].se.fi;
    y = v[i].se.se;
    // cout<<t<<" "<<x<<" "<<y<<endl;
    if(((t-T) - (abs(x-X) + abs(y-Y))) % 2 == 0 && (t-T) >= (abs(x-X) + abs(y-Y))){

    } else{
    flg++;
    }
    i++;
    X = x;
    Y = y;
    T = t;
  }
  if(flg > 0)  cout<<"No"<<endl;
  else cout<<"Yes"<<endl;
}

int main(){
  solve();
  return 0;
}


Measured memory_bytes: 1792
import os
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353

N = int(sys.stdin.buffer.readline())
A = list(map(int, sys.stdin.buffer.readline().decode().rstrip()))


def pp(A, offset=0):
    s = ' ' * offset + ' '.join(map(str, A))
    print(s)


def test(A):
    i = 0
    while len(A) > 1:
        pp(A, i)
        A = list(map(lambda a: abs(a[0] - a[1]), zip(A, A[1:])))
        i += 1
    pp(A, i)
    return A


def convert(counts):
    ret = []
    if counts[0][1] > 1:
        ret.append((0, counts[0][1] - 1))
    for (n1, cnt1), (n2, cnt2) in zip(counts, counts[1:]):
        ret.append((abs(n1 - n2), 1))
        if cnt2 > 1:
            ret.append((0, cnt2 - 1))

    n = None
    count = 0
    filtered = []
    for a, cnt in ret:
        if a != n:
            n = a
            count = 0
            filtered.append((n, 0))
        count += cnt
        filtered[-1] = (n, count)
    return filtered

#
# A = []
# for _ in range(N):
#     import random
#
#     A.append(random.randint(0, 2))
# ans = test(A)
# print(ans)

# cnt2[n]: n! が 2 で何回割れるか
cnt2 = []
cnt = 0
for n in range(N + 10):
    while n >= 2 and n % 2 == 0:
        n //= 2
        cnt += 1
    cnt2.append(cnt)

# 0, 1, 2 だけにする
A = list(map(lambda a: abs(a[0] - a[1]), zip(A, A[1:])))
# 1が入ってるとき、2は0と同一視できる
if 1 in A:
    for i in range(len(A)):
        if A[i] == 2:
            A[i] = 0
mod = 2 if 1 in A else 4

ans = 0
n = len(A) - 1
for r in range(len(A)):
    cnt = cnt2[len(A) - 1] - cnt2[r] - cnt2[n - r]
    # cnt = math.factorial(n) // math.factorial(r) // math.factorial(n - r)
    if cnt == 0:
        ans += A[r]
        ans %= mod
    # print(n, r, cnt)
print(ans)




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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

#define ll long long
#define ld long double
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)

#define xx first
#define yy second
#define mp make_pair
#define pll pair<ll,ll>
#define mll map<ll,ll>
#define vll vector<ll>
#define pdd pair<double,double>
#define ALL(v) (v).begin(), (v).end()

const ll MOD=1e9+7; ;
const ll inf=1e18;

#define MODSET(d) if ((d) >= MOD) d %= MOD;
#define MODNEGSET(d) if ((d) < 0) d = ((d % MOD) + MOD) % MOD;
#define put(x) cout<<#x<<" = "<<x<<endl;

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}

ll power(ll a,ll n){
    ll ans=1;
    while(n){
        if(n&1)
            ans=(ans*a);
        n>>=1;
        a=(a*a);
    }
    return ans;
}


ll powerMod(ll a,ll n){
    ll ans=1;
    while(n){
        if(n&1)
            ans=(ans*a)%MOD;
        n/=2;
        a=(a*a)%MOD;
    }
    return ans;
}

ll powerMod1(ll a,ll n,ll mod){
    ll ans=1;
    while(n){
        if(n&1)
            ans=(ans*a)%mod;
        n>>=1;
        a=(a*a)%mod;
    }
    return ans;
}

ll lcm(ll a,ll b){
    return a*(b/__gcd(a,b));
}

ll sumdigit(ll n){
    ll sum=0;
    while(n){
        sum+=n%10;
        n=n/10;
    }
    return sum;
}

ll countSetBit(ll a){
    return __builtin_popcount(a);
}
ll countBit(ll a){
    ll sum=0;
    while(a){
        sum++;
        a>>=1;
    }
    return sum;
}

ll length(ll a){
    ll ans=0;
    while(a){
        ans++;
        a=a/10;
    }
    return ans;
}

bool isVowel(char c){
	if(c=='a' or c=='e' or c=='i' or c=='o' or c=='u')
		return true;
	return false;
}

int main()
{
    fast;
    ll t;
    //cin>>t;
    t=1;
    while(t--){
          ll n;
          cin>>n;
          set<ll>m;
          for(int i=0;i<n;i++){
            ll k;
            cin>>k;
            m.insert(k);
          }
          if(m.size()==n)
            cout<<"YES";
          else cout<<"NO";
    }
    return 0;
}


Measured memory_bytes: 9600
#include <iostream>
#include <cstdio>
#include <vector>
using namespace std;


long long N, W;
vector<vector<long long> > dp(101, vector<long long>(100001));
vector<long long> w(101);
vector<long long> v(101);

void knap(){
    for(long long i = 0; i <= N; i++) dp[i][0] = 0;

    for(long long i = 1; i <= N; i++){
        for(long long j = 1; j <= W; j++){
            if(w[i] <= j) dp[i][j] = max(dp[i-1][j], dp[i-1][j - w[i]] + v[i]);
            else dp[i][j] = dp[i-1][j];
        }
    }
}

int main(){
    cin >> N >> W;
    for(long long i = 1; i <= N; i++) cin >> w[i] >> v[i];

    knap();

    cout << dp[N][W] << endl;
    return 0;
}

Measured memory_bytes: 83016
#include <iostream>
#include <cstdio>
using namespace std;
int a[100][100], n;
int d[200];
void duyet(int u)
{
    for(int v=0; v<n; v++)
    {
        if(a[u][v]>0 && d[v]>(d[u]+a[u][v]))
        {
            d[v]=d[u]+a[u][v];
            duyet(v);
        }
    }
}
int main()
{
    long long int s,t,u;
    cin>>n;
    for(int i=0; i<n; i++)
    {
        cin>>s>>t;
        for(int j=1; j<=t; j++)
        {
            cin>>s>>u; a[i][s]=u;
        }
        d[i]=1e6;
    }
    d[0]=0;
    duyet(0);
    for(int i=0; i<n; i++)
    {
        cout<<i<<" "<<d[i]<<endl;
    }
    return 0;
}



Measured memory_bytes: 3088
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <vector>
#include <bitset>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <deque>
#include <string>
#include <list>
#include <iterator>
#include <algorithm>
#include <unordered_map>
#define int                long long
#define pb                 push_back
#define pi                 pair<int,int>
#define vi                 vector<int>
#define all(v)             v.begin(),v.end()
#define MOD                1000000007
#define F                  first
#define S                  second
#define FOR(i,r)           for(int i=0;i<r;i++)
#define REP(i,l,r)         for(int i=l;i<r;i++)
#define RER(i,l,r)         for(int i=l;i>=r;i--)
#define print(v)           for(auto i : v)cout << i << ' ';
#define FASTIO             ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mem(arr,k)         memset(arr,k,sizeof(arr));
#define pii                acos(-1.0)
#define PI                 3.1415926535897932385
#define Sin(a)             sin((pi*a)/180)
#define test()             int x;cin >> x;while(x--){solve();}
#define test2()            int x;cin >> x;for(int i=1;i<=x;i++){cout << "Case #" << i << " : ";solve();}
#define watch(x)           cout << (#x) << " is " << (x) << endl
using namespace std;


/* Mathematical Functions */
int power(int x,int y);
bool isPrime(int n);
int modInv(int a,int b);
int gcdExtended(int a,int b,int *x,int* y);
int mpower(int a,int b,int p);

const int inf = (int)1e17;
const int N = (int)3e5+5;

int32_t main(){

	
	FASTIO;
	int n;
	cin >> n;
	vector<int>r1(n),r2(n);
	REP(i,0,n){
		cin >> r1[i] >> r2[i];
	}	
	sort(all(r1));
	sort(all(r2));
	if(n&1){
		int md = n/2;
		cout << r2[md]-r1[md]+1 << endl;
	}
	else{
		int md1 , md2;
		md1 = n/2;
		md2 = n/2 - 1;
		int v1 = r1[md1]+r1[md2];
		int v2 = r2[md1]+r2[md2];
		cout << v2-v1+1 << endl;
	}
    return 0;

}
int modInv(int a, int m)
{
int x, y;
int g = gcdExtended(a, m, &x, &y);
int res = (x%m + m) % m;
return res;
}
 
int gcdExtended(int a, int b, int *x, int *y)
{
if (a == 0){
    *x = 0, *y = 1;
    return b;
  }
  int x1, y1;
  int gcd = gcdExtended(b%a, a, &x1, &y1);
  *x = y1 - (b/a) * x1;
  *y = x1;
  return gcd;
}
 
int mpower(int x, int y, int p)
{
int res = 1;
x = x % p;
while(y > 0){
    if(y & 1) res = (res*x) % p;
      y = y>>1;
      x = (x*x) % p;
    }
    return res;
}
int power(int x, int y)
{
int res = 1;
while (y > 0){
    if (y & 1) res = res*x;
      y = y>>1;
      x = x*x;
    }
    return res;
}
 
bool isPrime(int n)
{
if (n <= 1)  return false;
  if (n <= 3)  return true;
    if (n%2 == 0 || n%3 == 0) return false;
      int p=sqrt(n);
      for(int i=5;i<=p;i=i+6)
        if (n%i == 0 || n%(i+2) == 0)
          return false;
      return true;
}

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

int main() {
	int x,a,b,aa,bb;
	cin >> x>>a>>b;
	string ans;
	if (x > a) {
		aa = x - a;
	}
	else {
		aa = a - x;
	}
	if (x > b) {
		bb = x - b;
	}
	else {
		bb = b - x;
	}
	if (aa > bb) {
		ans = "B";
	}
	else {
		ans = "A";
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256