akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
typedef long long ll;
int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	rep(i, n) {
		cin >> a[i];
	}
	rep(i, n) {
		if (i != n-1)
			cout << a[i]<<" ";
		else
			cout << a[n-1] << endl;
	}
	int v(n);
	for(int i=1;i<=n-1;i++){
		v = a[i];
		int j = i - 1;
		while (j >= 0 && a[j] > v) {
			a[j + 1] = a[j];
			j--;
			a[j + 1] = v;
		}
		rep(i, n) {
			if(i!=n-1)
			cout << a[i]<<" ";
			else
			cout << a[n-1] << endl;
		}
	}
}


Measured memory_bytes: 3120
#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 1001001001
#define LINF 1001001001001001001
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define bit(n) (1LL<<(n))
using namespace std;

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

int main() {

    int H1, H2, M1, M2, K;
    cin >> H1 >> M1 >> H2 >> M2 >> K;

    int ans = 0;
    ans += (H2 - H1) * 60;
    ans += M2 - M1;

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

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
#define ep emplace_back
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(v) v.begin(), v.end()
#define revall(v) v.rbegin(), v.rend()
constexpr int mod=1000000007;
constexpr int mod1=998244353;
vector<int> dx={0,1,0,-1},dy={-1,0,1,0};
bool inside(int y,int x,int h,int w){ if(y<h && y>=0 && x<w && x>=0) return true; return false; }
template<class T> inline bool chmin(T& a, T b){ if(a > b){ a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b){ if(a < b){ a = b; return true; } return false; }


bool cmp(string a, string b){
	int k = min(a.size(),b.size());
	rep(i,k){
		if(a.at(i) > b.at(i)) return false;
		if(a.at(i) < b.at(i)) return true;
	}
	if(a.size() < b.size()) return true;
	return false;
}


int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;cin >> s;
	int k;cin >> k;
	int n = s.size();
	set<string> st;
	vector<string> t;
	rep(i,n){
		for(int j = 1; j <= k; j++){
			if(i + j > n) break;
			string u = s.substr(i,j);
			if(st.count(u)) continue;
			st.insert(u);
			t.pb(u);
		}
	}
	sort(t.begin(),t.end(),cmp);
	cout << t.at(k - 1) << endl;
}


Measured memory_bytes: 1792
function abc085_a()

	# STEP.01
	# get the target date
	str_data_input = Base.readline( Base.STDIN )

	# STEP.02
	# output the result
	Base.println( Base.STDOUT, "2018" * str_data_input[5:end] )

	# STEP.TRUE_END
	return Base.nothing

end

#==================================================================================================#

Main.abc085_a()


Measured memory_bytes: 107440
//khodaya khodet komak kon
#include <bits/stdc++.h>

#define F first
#define S second
#define pb push_back
#define all(x) x.begin(), x.end()
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#define int long long

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

const int N = 5000 + 10;
const ll MOD = 1000000000 + 7;
const ll INF = 1000000010;
const ll LOG = 12;

int DP[N][N], n, m;
string s;

int POW(int x, int y){
	int res = 1;
	while (y){
		if (y & 1) res = res * 1ll * x % MOD;
		y >>= 1;
		x = x * 1ll * x % MOD;
	}
	return res;
}

int32_t main(){
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n >> s;
	m = (int)s.size();
	DP[0][0] = 1;
	for (int i = 1; i <= n; i++){
		for( int j = 0; j <= i; j++){
			if (j == 0) DP[j][i] = (DP[j][i - 1] + DP[j + 1][i - 1]) % MOD;
			else DP[j][i] = (DP[j - 1][i - 1] * 2 + DP[j + 1][i - 1]) % MOD;
		}
	}
	int res = 1;
	for (int i = 1; i <= m; i++) res =  res * 2ll % MOD;
	cout << (DP[m][n] * 1ll * POW(res, MOD - 2)) % MOD;











	return 0;
}


Measured memory_bytes: 120332
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif

#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define repp(i, m, n) for(int i = m, i##_len = (n); i < i##_len; ++i)
#define reprev(i, n) for(int i = (n-1LL); i >= 0; --i)
#define all(x) (x).begin(), (x).end()
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> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

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

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s, t;
    cin >> s >> t;
    rep (i, s.size()) {
        eprintf("%s\n", (s.substr(i) + s.substr(0, i)).c_str());
        if (s.substr(i) + s.substr(0, i) == t) {
            cout << "Yes\n";
            return 0;
        }
    }
    cout << "No\n";
    return 0;
}

Measured memory_bytes: 256
/* {{{ Shinobu kawaii */
/*
  ______   __        _                  __                 
.' ____ \ [  |      (_)                [  |                
| (___ \_| | |--.   __   _ .--.   .--.  | |.--.   __   _   
 _.____`.  | .-. | [  | [ `.-. |/ .'`\ \| '/'`\ \[  | | |  
| \____) | | | | |  | |  | | | || \__. ||  \__/ | | \_/ |, 
 \______.'[___]|__][___][___||__]'.__.'[__;.__.'  '.__.'_/ 

*/
/* }}} */

#include <bits/stdc++.h>
using namespace std;

// #define int long long
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;

/* cpp template {{{ */

/* short */
#define pb push_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) (v).begin(), (v).end()
#define X real()
#define Y imag()

/* REPmacro */
#define REPS(i, a, n) for (int i = (a); i < (n); ++i)
#define REP(i, n) REPS(i, 0, n)
#define RREP(i, n) REPS(i, 1, n + 1)
#define DEPS(i, a, n) for (int i = (a); i >= n; --i)
#define DEP(i, n) DEPS(i, n, 0)

/* debug */
#define debug(x) cerr << x << " " << "(L:" << __LINE__ << ")" << '\n';

/* alias */
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;
using D = double;
using P = complex<D>;

/* const */
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;
const D EPS = 1e-9;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

/* func */
inline bool inside(int y, int x, int H, int W) {return y >= 0 && x >= 0 && y < H && x < W;}
inline int in() {int x; std::cin >> x; return x;}
template <typename T> void print(T x) {std::cout << x << '\n';}
template <typename T>
void print(std::vector<T>& v, std::string s = " ") {
  REP(i, v.size()) {
    if (i != 0) std::cout << s;
    std::cout << v[i];
  }
  std::cout << '\n';
}

/* }}} */

int n, m;

void warshall_floyd(vvi& d)
{
  REP(k, m) REP(i, m) REP(j, m) {
    d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
  }
}

signed main()
{
  while (cin >> n >> m, n || m) {
    vvi dc, dt;
    dc = dt = vvi(m, vi(m, INF));
    REP(i, n) {
      int a = in() - 1, b = in() - 1;
      dc[a][b] = dc[b][a] = in();
      dt[a][b] = dt[b][a] = in();
    }
    warshall_floyd(dc);
    warshall_floyd(dt);
    int k = in();
    REP(i, k) {
      int a = in() - 1, b = in() - 1, r = in();
      print(r ? dt[a][b] : dc[a][b]);
    }
  }

  return 0;
}

Measured memory_bytes: 3196
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9+7;
const long long INF = 1e15;

struct BIT {
  int n;
  vector<long long> d;
  BIT(int n=0):n(n),d(n+1) {}
  void add(int i, long long x=1) {
    for (i++; i <= n; i += i&-i) {
      d[i] += x;
    }
  }
  long long sum(int i) {
    long long x = 0;
    for (i++; i; i -= i&-i) {
      x += d[i];
    }
    return x;
  }
  long long sum(int l, int r) {
    return sum(r-1) - sum(l-1);
  }
};

int main(){
    int n,q;
    cin >> n >> q;
    vector<int> c(n);
    for(int i = 0; i < n; i++) cin >> c[i], c[i]--;

    vector<pair<pair<int,int>,int>> pq;
    for(int i = 0; i < q; i++){
        int l,r;
        cin >> l >> r;
        l--;r--;
        pq.push_back(make_pair(make_pair(l,r),i));
    }

    vector<int> memo(n,-1);
    vector<pair<int,int>> cp;
    for(int i = 0; i < n; i++){
        if(memo[c[i]] != -1) cp.push_back(make_pair(memo[c[i]],i));
        memo[c[i]] = i;
    }

    sort(pq.rbegin(),pq.rend());
    sort(cp.rbegin(),cp.rend());

    BIT tree(n);
    vector<int> ans(q,0);

    int ncp = 0;
    for(int i = 0; i < q; i++){
        while(true){
            if(ncp < (int)cp.size() && pq[i].first.first <= cp[ncp].first){
                tree.add(cp[ncp].second,1);
                ncp++;
            } else break;
        }
        ans[pq[i].second] = pq[i].first.second-pq[i].first.first+1-tree.sum(pq[i].first.second);
    }

    for(int i = 0; i < q; i++) cout << ans[i] << endl;


    return 0;
}

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

int main()
{
  int N;
  cin >> N;
  
  if(N == 1000 || N == 10000)
  {
    cout << "Yes" << endl;
  }
  
  else if(N%1110 < 10)
  {
    cout << "Yes" << endl;
  }
  
  
  else if((N-111)%1000 == 0)
  { 
    cout << "Yes" << endl;
  }
  
  else if((N-222)%1000 == 0)
  { 
    cout << "Yes" << endl;
  }
  
  else if((N-333)%1000 == 0)
  { 
    cout << "Yes" << endl;
  }
  
  else if((N-444)%1000 == 0)
  { 
    cout << "Yes" << endl;
  }
  
  else if((N-555)%1000 == 0)
  { 
    cout << "Yes" << endl;
  }
  
  else if((N-666)%1000 == 0)
  { 
    cout << "Yes" << endl;
  }
  
  else if((N-777)%1000 == 0)
  { 
    cout << "Yes" << endl;
  }
  
  else if((N-888)%1000 == 0)
  { 
    cout << "Yes" << endl;
  }
  
  else if((N-999)%1000 == 0)
  { 
    cout << "Yes" << endl;
  }
  
  else
  {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include<cstdio>
#include<cctype>
#include<algorithm>
using namespace std;
int n,a[200005],b[200005];
int main(){
	int n,i;
	scanf("%d",&n);
	for(i=1;i<=n;i++)
		scanf("%d",&a[i]),b[i]=a[i];
	sort(a+1,a+n+1);
	for(i=1;i<=n;i++){
		if(b[i]==a[n])
			printf("%d\n",a[n-1]);
		else
			printf("%d\n",a[n]);
	}
	return 0;
}

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

struct RGB {
    int r;
    int g;
    int b;
};

int main() {
    int N; cin >> N;
    string S; cin >> S;
    vector<RGB> vec(N);
    vec[N-1].r = vec[N-1].g = vec[N-1].b = 0;
    if (S[N-1] == 'R') vec[N-1].r++;
    else if (S[N-1] == 'G') vec[N-1].g++;
    else vec[N-1].b++;
    for (int i = N-2; i >= 0; i--) {
        vec[i] = vec[i+1];
        if (S[i] == 'R') vec[i].r++;
        else if (S[i] == 'G') vec[i].g++;
        else vec[i].b++;
    }
    ll ans = 0;
    for (int i = 0; i < N-2; i++) {
        for (int j = i+1; j < N-1; j++) {
            if (S[i] == S[j]) continue;
            if (S[i] == 'R' && S[j] == 'G') {
                ans += vec[j+1].b;
                if (j*2 - i < N && S[j*2 - i] == 'B') ans--;
            }
            else if (S[i] == 'G' && S[j] == 'B') {
                ans += vec[j+1].r;
                if (j*2 - i < N && S[j*2 - i] == 'R') ans--;
            }
            else if (S[i] == 'R' && S[j] == 'B') {
                ans += vec[j+1].g;
                if (j*2 - i < N && S[j*2 - i] == 'G') ans--;
            }
            else if (S[i] == 'G' && S[j] == 'R') {
                ans += vec[j+1].b;
                if (j*2 - i < N && S[j*2 - i] == 'B') ans--;
            }
            else if (S[i] == 'B' && S[j] == 'G') {
                ans += vec[j+1].r;
                if (j*2 - i < N && S[j*2 - i] == 'R') ans--;
            }
            else if (S[i] == 'B' && S[j] == 'R') {
                ans += vec[j+1].g;
                if (j*2 - i < N && S[j*2 - i] == 'G') ans--;
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3692
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    vector<int> a(n);
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    vector<int> b;
    for(int i=0;i<n;i++){
        if(i%2!=(n-1)%2){
            b.push_back(a[i]);
        }
        else{
            b.insert(b.begin(),a[i]);
        }
    }
    for(int i=0;i<n;i++){
        cout<<b[i]<<" ";
    }
    cout<<endl;
    return 0;
}


Measured memory_bytes: 3828
/*----------------by syr----------------*/
/*

         iii                  ii
     rBQBBBBBBE       BBR iBBBBQBBL     XBBBBBBQBBBBB
   iBBQJ    7BBB      BBsSBBr   BBQ      i      cBBB
  rBBU       iBBw     BBBQi     HBBi           KBBi
  BBH         BB5    iBBB       isL          wBB5
 GBB         iBBi    6BB                   iBBB
 BBQ         BQB     BBD                  QBBi
 BBB        BQB     iQBi                1BBv
 sBBg     wBBB      QBB               iBBB
  7BBBBBBBBBi       BBR              wBBBBBBBBBBBBB
     irvi           ii               ii    i i iii
                i5U
               BBB
               BB7
              1BB
      iPBBBBBKBBR    JBR1       rQBO   BR  UBQP  iBBQi
    7BBBGs7sXBBBi     QBBr     gBBE   rBB BB2BB7HBZQBB
   QBBi      sBQ       BBB   iBBB     SQBBR  BBBB  cBQ
  gBQ        BBg        BBB KBBi      MBBH   BBB   BBs
 iBBv       iBBi         QBBBL        BBR   pBB   iBB
 pBB        BBB         iBBBB        iBB    BBL   KBB
 MBB       BBBR        BBB JBBi      DBR   iBQ    BBL
 GBB     7BBBB2      PBBH   BBBi     BQr   DBB   iBB
  BQBXwgBBP BB7    1BBB      BBQ7   1BB    BBc   BBB
   2BBBBw   BB    EBBS        QBBi  HBa   iBB    BB7
*/
#include<bits/stdc++.h>

using namespace std;

#define PH push
#define MP make_pair
#define PB push_back
#define fst first
#define snd second
#define FOR(i, x, y) for(int i = (x); i < (y); ++i)
#define REP(i, x, y) for(int i = (x); i <= (y); ++i)
#define x0 x0123456789
#define y0 y0123456789
#define x1 x1234567890
#define y1 y1234567890
#define x2 x2345678901
#define y2 y2345678901
typedef double db;
typedef long long ll;
typedef long double ldb;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 1e9 + 7;
const int maxn = 15;

int n, d, ans = 0;
int x[maxn][maxn];

int main(){
	scanf("%d%d", &n, &d);
	FOR(i, 0, n) FOR(j, 0, d) scanf("%d", &x[i][j]);
	FOR(i, 0, n) FOR(j, i + 1, n){
		int res = 0;
		FOR(k, 0, d) res += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
		int dis = int(sqrt(res));
		if(dis * dis == res)
			++ans;
	}
	printf("%d\n", ans);
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define debug(x) cerr << #x << " " << x << '\n'
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
const int INF = 0x3f3f3f3f, N = 2e5 + 5;
const ll LINF = 1e18 + 5;
int n, col[N], k;
vector <pii> G[N];
void dfs(int u,int fa,int faedge)
{
	int cur = 0;
	for(auto it : G[u])
	{
		int v = it.first, id = it.second;
		if(v==fa) continue;
		cur++;
		if(cur==col[faedge]) cur++;
		col[id] = cur;
		dfs(v,u,id);
	}
	k = max(k,cur);
}
int main()
{
 	ios::sync_with_stdio(false);
 	cin.tie(0);
 	cin >> n;
 	for(int i=1;i<n;i++)
 	{
 		int u, v;
 		cin >> u >> v;
 		G[u].pb(mp(v,i)); G[v].pb(mp(u,i));
 	}
 	dfs(1,0,0);
 	cout << k << '\n';
 	for(int i=1;i<n;i++) cout << col[i] << '\n';
	return 0;
}


Measured memory_bytes: 10752
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    int a[200010];
    rep(i, n) cin >> a[i];
    int num = *max_element(a, a + n);
    int cnt[200100] = {};
    rep(i, n) cnt[a[i]]++;
    int tmp = num;
    rep(i, n) {
        cnt[a[i]]--;
        while(cnt[num] == 0)num--;
        cout << num << endl;
        cnt[a[i]]++;
        num = tmp;
    }

    return 0;
}


Measured memory_bytes: 3200
#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(a) (a).begin(),(a).end()
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
const int INF=1e9;
int main(){
	int w,h,n;
	int x[100100],y[100100];
	cin>>w>>h>>n;
	vector<int>vx(n),vy(n);
	REP(i,n){
		cin>>x[i]>>y[i];
		vx[i]=x[i];vy[i]=y[i];
	}
	sort(ALL(vx));
	sort(ALL(vy));
	vector<int>kx,ky;
	if(n%2){
		kx.PB(vx[n/2]);
		ky.PB(vy[n/2]);
	}else{
		kx.PB(vx[n/2-1]);
		kx.PB(vx[n/2]);
		ky.PB(vy[n/2-1]);
		ky.PB(vy[n/2]);
	}
	ll ans=1e18,ansx,ansy;
	REP(i,kx.size())REP(j,ky.size()){
		ll sum=0;
		vector<ll>V;
		REP(k,n)V.PB(abs(x[k]-kx[i])+abs(y[k]-ky[j]));
		sort(ALL(V));
		REP(k,V.size())sum+=k==V.size()-1?V[k]:V[k]*2;
		if (ans>sum){
			ansx=kx[i];
			ansy=ky[j];
			ans=sum;
		}
	}
	cout<<ans<<endl<<ansx<<" "<<ansy<<endl;
}

Measured memory_bytes: 4432
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
MOD = 10**9 + 7
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def combMod(n, r, p):
    numer = 1
    denom = 1
    for i in range(1, r+1):
        numer = numer * (n-r+i) % p
        denom = denom * i % p
    return numer * pow(denom, p-2, p) % p

def resolve():
    n, k = LI()

    ans = combMod(n + k - 1, n, MOD)

    print(ans)

if __name__ == '__main__':
    resolve()



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

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

    if (N%10 == 2 || N%10 == 4 || N%10 == 5 || N%10 == 7 || N%10 == 9) printf("hon\n");
    else if (N%10 == 0 || N%10 == 1 || N%10 == 6 || N%10 == 8) printf("pon\n");
    else printf("bon\n");
    return 0;
}


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

int main(){
  int n;
  cin >> n;
  vector<double> v(n);

  for (int i = 0; i < n; i++)
  {
    cin >> v[i];
  }
  sort(v.begin(),v.end());
  
  double ans=v[0];
  for (int i = 1; i < n; i++)
  {
    ans+=v[i];
    ans/=2.0;
  }

  printf("%.14lf\n",ans);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define For(i, l, r) for(int i = (l), _end_ = (int)(r); i <= _end_; ++i)
#define Fordown(i, r, l) for(int i = (r), _end_ = (int)(l); i >= _end_; --i)
#define Set(a, v) memset(a, v, sizeof(a))
using namespace std;

bool chkmin(int &a, int b) {return b < a ? a = b, 1 : 0;}
bool chkmax(int &a, int b) {return b > a ? a = b, 1 : 0;}

inline int read() {
	int x = 0, fh = 1; char ch = getchar();
    for (; !isdigit(ch); ch = getchar() ) if (ch == '-') fh = -1;
    for (; isdigit(ch); ch = getchar() ) x = (x<<1) + (x<<3) + (ch ^ '0');
    return x * fh;
}

int Lx = 0, Ly = 0, Lt = 0;
int main () {
	int n = read();
	For (i, 1, n) {
		int t = read(), x = read(), y = read();
		int dis = abs(Lx - x) + abs(Ly - y);
		if ((dis & 1) != (t & 1) || dis > t) return puts("No"), 0;
	}
	puts("Yes");
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <cmath>
#include <iomanip>
#include <bitset>
#include <string>
#include <stdlib.h>
using namespace std;
//cout <<  << endl;
typedef long long int ll;
typedef long double ld;

int main() {
    string s;
    cin >> s;
    for (ll i=0;i<s.size();++i){
        for (ll j=0;j<s.size();++j){
            if (i==j){
                continue;
            }
            if (s[i]==s[j]){
                cout << "no" << endl;
                return 0;
            }
        }
    }
    cout << "yes" << endl;
    return 0;
}


Measured memory_bytes: 256
use std::io;


/// https://beta.atcoder.jp/contests/agc025/tasks/agc025_a
fn main() {
    let n = read_one::<usize>();
    let mut x = n;
    let mut flg = true;
    while x > 1 {
        if x % 10 != 0 { flg = false; }
        x = x / 10;
    }

    if !flg {
        let mut x = n;
        let mut sum = 0;
        while x > 0 {
            sum += x % 10;
            x = x / 10;
        }
        println!("{}", sum);
    } else { println!("10"); }
}


#[allow(dead_code)]
fn read<T>() -> Vec<T>
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace()
        .map(|s| s.trim().parse().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_one<T>() -> T
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().unwrap()
}

Measured memory_bytes: 4352
import sys
from collections import deque
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
n = int(readline())
lst1 = list(map(int,readline().split()))
ans = []
if abs(max(lst1)) > abs(min(lst1)):
    a = lst1.index(max(lst1)) + 1
    for i in range(n):
        ans.append([a,i+1])
    for i in range(n-1):
        ans.append([i+1,i+2])
else:
    a = lst1.index(min(lst1)) + 1
    for i in range(n):
        ans.append([a,i+1])
    for i in range(n-1,0,-1):
        ans.append([i+1,i])
print(len(ans))
for i,j in ans:
    print(i,j)


Measured memory_bytes: 38384
N=int(input())
A=list(map(int,input().split()))

A.sort()
xy=[]
for i in range(N-2,0,-1):
    y=A[i]
    if y>0:
        x=A[0]
        A[0]-=y
    else:
        x=A[N-1]
        A[N-1]-=y
    xy.append((x,y))

print(A[N-1]-A[0])
xy.append((A[N-1],A[0]))
print('\n'.join([' '.join(map(str,t)) for t in xy]))

Measured memory_bytes: 28088
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			long n = scanner.nextLong(), m = scanner.nextLong();
			System.out.println((m > 2 * n) ? (m - 2 * n) / 4 + n : m / 2);
		}
	}
}


Measured memory_bytes: 35660
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N; int K;
  string S;
  cin >> N >> K;
  cin >> S;
  for(int i = 0; i < N; i++){
  	if(i + 1 == K){
      if(S.at(i) == 'A'){
        S.at(i) = 'a';
      }
      else if(S.at(i) == 'B'){
        S.at(i) = 'b';
      }
      else{
      	S.at(i) = 'c';
      }
    }
  }
  cout << S << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#include<cmath>



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

using namespace std;
string s;
int f;
int main(){
  string ans = "AC";
  cin >> s;
  if(s[0]!= 'A') ans = "WA";
  else{
    for(int i=1;i<s.size();i++){
      if(s[i]>='A' && s[i]<='Z'){
        if(s[i]!= 'C') ans = "WA";
        else if (f==1 || i<=1 || i>=s.size()-1) ans = "WA";
        f=1;
      }
    }
  }
  if(f==0) ans = "WA";
  cout << ans << endl;
  return 0;
}


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

using namespace std;

int main(){
    int m, nmin, nmax ;
    while(1){
        cin >> m >> nmin >> nmax;
        if(m==0 and nmin ==0 and nmax==0) break;
        vector<int> P(m, 0);
        for(int i=0; i< m; i++) cin >> P[i];
        int ans_index;
        int max_gap=-1;
        for(int n=nmin;n<=nmax;n++){
            if(P[n-1] - P[n] >= max_gap){
                ans_index = n;
                max_gap = P[n-1] - P[n];
            }
        }
        cout << ans_index << endl;
    }
}


Measured memory_bytes: 3080
N = int(input())
D = [[0]*10 for i in range(10)]
for n in range(1, N+1):
  s = str(n)
  i = int(s[0])
  j = int(s[-1])
  D[i][j] += 1
#print(D)
r = 0
for i in range(10):
  for j in range(10):
    r += D[i][j]*D[j][i]
print(r)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define P pair<int,int>
using ll=int64_t;
using namespace std;
#define ketasuu(n) fixed<<setprecision(n)
#define btoe(p) p.begin(),p.end()
#define etob(p) p.rbegin(),p.rend()




int main(){
    string s;
    cin>>s;
    int n=s.length();
    vector<int> p(n);
    rep(i,n) p[i]=s[i]-'0';
    int a=0,c=0,d=1;
    rep(i,n){
        if(p[i]==c) a++;
        swap(c,d);
    }
    a=min(a,n-a);
    cout<<a<<endl;
}

Measured memory_bytes: 896
#include <stdio.h>
#include <algorithm>
#include <memory.h>

typedef long long ll;

const ll N = 2e3 + 5;
const ll P = 1e9 + 7;

ll n, k;
ll fac[N * N];
ll f[N][N];

ll read()
{
    ll x = 0, f = 1;
    char ch = getchar();
    while ('0' > ch or ch > '9')
        f = ch == '-' ? -1 : 1, ch = getchar();
    while ('0' <= ch and ch <= '9')
        x = x * 10 + ch - 48, ch = getchar();
    return x * f;
}

ll pow(ll x, ll k)
{
    ll res = 1;
    for (x %= P; k; k >>= 1, x = x * x % P)
        if (k & 1)
            res = res * x % P;
    return res;
}

ll C(ll n, ll m) { return ((fac[n] * pow(fac[m], P - 2)) % P * pow(fac[n - m], P - 2) % P); }

signed main()
{
    n = read(), k = read();
    if (k == 1)
    {
        puts("1");
        return 0;
    }
    fac[0] = 1;
    for (ll i = 1; i <= n * k; i++)
        fac[i] = fac[i - 1] * i % P;
    for (ll i = 0; i <= n; i++)
        f[i][0] = 1;
    for (ll i = 1; i <= n; i++)
        for (ll j = 1; j <= i; j++)
            f[i][j] = f[i - 1][j] +
                      f[i][j - 1] * (n - j + 1) % P *
                          C(n * k - i - (j - 1) * (k - 1) - 1, k - 2) % P;
    printf("%lld", f[n][n]);
    return 0;
}

Measured memory_bytes: 55452
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll bigmod(ll a,ll p,ll m)
{
    if(p==0)
        return 1%m;
    if(p%2!=0)
    {
        return (a*(bigmod(a,p-1,m)))%m;
    }
    else
    {
        ll x=(bigmod(a,p/2,m))%m;
        return (x*x)%m;
    }
}
int main()
{
    ll a;
    cin>>a;
    cout<<(a+(a*a)+(a*a*a))<<endl;
    return 0;
}


Measured memory_bytes: 3564
#include<iostream>
#include<cstring>
#include<map>
#include<string>
#include<queue>
#include<algorithm>

#define fr first
#define sc second

using namespace std;
int x, y;
string m;
bool used[16][16];
typedef pair<string, int> Pi;

bool check(string s)
{
  for(int i = 1;i < x * y; i++)
    if(s[0] != s[i]) return false;

  return true;
}

void change(int nx, int ny, char color, string &s)
{
  if(used[nx][ny]) return;
  used[nx][ny] = true;
  if(ny + 1 < y && s[(ny + 1) * x + nx] == s[ny * x + nx]) change(nx, ny + 1, color, s);
  if(nx + 1 < x && s[ny * x + nx + 1] == s[ny * x + nx]) change(nx + 1, ny, color, s);
  if(ny - 1 >= 0 && s[(ny - 1) * x + nx] == s[ny * x + nx]) change(nx, ny - 1, color, s);
  if(nx - 1 >= 0 && s[ny * x + nx - 1] == s[ny * x + nx]) change(nx - 1, ny, color, s);

  s[ny * x + nx] = color;
  return;
}

int bfs()
{
  queue<Pi> que;
  que.push(make_pair(m, 0));
  while(true){
    Pi p = que.front(); que.pop();
    string s, t;
    s = t = p.fr;
    if(check(s)) return p.sc;
    
    if(s[0] != 'R'){
      memset(used, false, sizeof(used));
      change(0, 0, 'R', s);
      que.push(make_pair(s, p.sc + 1));
      s = t;
    }
    if(s[0] != 'G'){
      memset(used, false, sizeof(used));
      change(0, 0, 'G', s);
      que.push(make_pair(s, p.sc + 1));
      s = t;
    }
    if(s[0] != 'B'){
      memset(used, false, sizeof(used));
      change(0, 0, 'B', s);
      que.push(make_pair(s, p.sc + 1));
      s = t;
    }
  }
}

int main(void)
{
  string c;

  while(cin >> x >> y, x || y){
    m = "";
    for(int i = 0;i < x * y; i++){
	cin >> c;
	m += c;
    }

    cout << bfs() << endl;
  }  
}


Measured memory_bytes: 39020
import sys
n  = int(input())

a = [list(map(int,input().split())) for i in range(n-1)]
su = 0 
for i in range(n):
    if i == n-1:
        print(0)
    else:
        for j in range(i,n-1):
            if su < a[j][1]:
                su = a[j][1] + a[j][0]
            elif su % a[j][2] == 0:
                su += a[j][0]
            else:
                su += a[j][2] - (su - a[j][1]) % a[j][2] + a[j][0]
        print(su)
        su = 0

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string s;
  cin >> s;
  int count =0;
  if(s[0] == '1') count++;
  if(s[1] == '1') count++;
  if(s[2] == '1') count++;
  cout << count << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#ifdef DEBUG
#include "_debug.cpp"
#include "callable.hpp/callable.hpp"
#endif
#define endl '\n'
using namespace std;
using ll = long long;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string n;
    cin >> n;
    cout << ((n[0] == n[1] and n[1] == n[2] or n[1] == n[2] and n[2] == n[3]) ? "Yes" : "No") << endl;
    return 0;
}


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

int main(){
	char a;
	double weight,height;
	int number;
	
	while(cin>>number>>a>>weight>>a>>height){
		double bmi;
		bmi=weight/(height*height);
		if(25<bmi || 25==bmi){
			cout<<number<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1232
#include<bits/stdc++.h>
#define rep(i,j,k) for(int i=j;i<=k;i++)
#define rep2(i,j,k) for(int i=j;i>=k;i--)
using namespace std;
template<typename T> void read(T &num){
	char c=getchar();T f=1;num=0;
	while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9'){num=(num<<3)+(num<<1)+(c^48);c=getchar();}
	num*=f;
}
template<typename T> void qwq(T x){
	if(x>9)qwq(x/10);
	putchar(x%10+'0');
}
template<typename T> void write(T x){
	if(x<0){x=-x;putchar('-');}
	qwq(x);putchar('\n');
}
int co[100010];int in[100010]; 
int n,m,v,p;
inline bool check(int mid){
	memset(in,0,sizeof(in));
	int ba=co[mid]+m;long long tot=1ll*m*v;
	if(mid<=v){tot-=1ll*mid*m;}
	else{tot=0;}
	rep(i,mid+1,n){
		if(co[i]>=ba)break;
		if(tot>=ba-co[i]){tot-=ba-co[i];in[i]=ba-co[i];}
		else{in[i]=tot;tot=0;}
	}
	rep2(i,n,mid+1){
		if(tot>=m-in[i]){tot-=m-in[i];in[i]=m;}
		else{in[i]+=tot;break;}
	}
	int cnt=0;
	rep(i,1,n)cnt+=(co[i]+in[i]>ba);
	return cnt<=p-1;
}

int main(){
	read(n);read(m);read(v);read(p);
	rep(i,1,n)read(co[i]);
	sort(co+1,co+n+1);
	
	int l=1;int r=n;int ans=n+1;
	while(l<=r){
		int mid=(l+r)>>1;
		if(check(mid)){ans=mid;r=mid-1;}
		else{l=mid+1;}
	}
	write(n-ans+1);
	return 0;
}

Measured memory_bytes: 1024
import java.util.*;
import java.io.*;

import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
 
public class Main{
    static final long mod=1000000007;
    static int dx[]={-1,0,1,0};
    static int dy[]={0,-1,0,1};

    public  static void main(String[] args)   throws Exception, IOException{        
        Reader sc = new Reader(System.in);
        PrintWriter out=new PrintWriter(System.out);
        // int n=sc.nextInt();
        // char c[][] = new char[h][w];
        // char c[]=sc.nextString().toCharArray();
        // int d[]=new int[n];
        // for(int i=0; i<n; i++) {d[i]=sc.nextInt();}


        
//        long L=sc.nextLong();
        int n=sc.nextInt();	
        int dp[][]=new int[3][n+1];
        
        for (int i = 1; i <= n; i++) {
        	int a=sc.nextInt(),b=sc.nextInt(),c=sc.nextInt();
        	dp[0][i] = max(dp[1][i-1], dp[2][i-1]) + a;
        	dp[1][i] = max(dp[0][i-1], dp[2][i-1]) + b;
        	dp[2][i] = max(dp[0][i-1], dp[1][i-1]) + c;
		}

        int ans=max(dp[0][n],dp[1][n]);
        ans=max(dp[2][n],ans);

        out.println(ans);
        out.flush();
    }
    
    static boolean validpos(int x,int y,int r, int c){
        return x<r && 0<=x && y<c && 0<=y;
    }


    static void db(Object... os){
        System.err.println(Arrays.deepToString(os));
    }  
}

//class P {
//    int id, d;
//    P(int  id, int d) {
//        this.id=id;
//        this.d=d;
//    }
//}

//class P implements Comparable<P>{
//    int id, d;
//    P(int  id, int d) {
//        this.id=id;
//        this.d=d;
//    }
//    public int compareTo(P p){
//        return d-p.d; //des
//    }
//}

class Reader
{ 
    private BufferedReader x;
    private StringTokenizer st;
    
    public Reader(InputStream in)
    {
        x = new BufferedReader(new InputStreamReader(in));
        st = null;
    }
    public String nextString() throws IOException
    {
        while( st==null || !st.hasMoreTokens() )
            st = new StringTokenizer(x.readLine());
        return st.nextToken();
    }
    public int nextInt() throws IOException
    {
        return Integer.parseInt(nextString());
    }
    public int[] nextIntArray(int size) throws IOException{
    	int r[] = new int[size];
    	for (int i = 0; i < size; i++) {
			r[i] = this.nextInt(); 
		}
    	return r;
    }
    public long nextLong() throws IOException
    {
        return Long.parseLong(nextString());
    }
    public double nextDouble() throws IOException
    {
        return Double.parseDouble(nextString());
    }
}


Measured memory_bytes: 45400
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll MOD = 1'000'000'007;
const ld PI = acos(-1);  
const ld EPS = 0.0000000001;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define REP(i, n) for(ll i=0; i<(ll)(n); i++)
#define REPD(i, n) for(ll i=n-1; 0<=i; i--)
#define FOR(i, a, b) for(ll i=a; i<(ll)(b); i++)
#define FORD(i, a, b) for(ll i=a; (ll)(b)<=i; i--)
#define ALL(x) x.begin(), x.end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};



int main(){
    ll n;   cin >> n;
    vector<ll> a(n);
    ll res=0;
    REP(i, n){
        cin >> a[i];
        res ^= a[i];
    }
    REP(i, n){
        ll tmp = res^a[i];
        cout << tmp << ' ';
    }
  
}

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

#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i, x, n) for(int i = x; i >= n; i--)
#define rrep(i, n) RREP(i,n,0)
#define pb push_back
#pragma GCC optimize ("-O3")

using namespace std;

#define DEBUG_IS_VALID

#ifdef DEBUG_IS_VALID
#define DEB 1 
#else
#define DEB 0
#endif
#define DUMPOUT cout
#define dump(...) if(DEB) DUMPOUT<<"  "<<#__VA_ARGS__<<" :["<<__LINE__<<":"<<__FUNCTION__<<"]"<<endl<<"    "; if(DEB) dump_func(__VA_ARGS__)
template<typename T1,typename T2>ostream& operator << (ostream& os, pair<T1,T2> p){cout << "(" << p.first << ", " << p.second << ")"; return os;}
template<typename T>ostream& operator << (ostream& os, vector<T>& vec) { os << "{"; for (int i = 0; i<vec.size(); i++) os << vec[i] << (i + 1 == vec.size() ? "" : ", "); os << "}"; return os; }
template<typename T>ostream& operator << (ostream& os, set<T>& st){for(auto itr = st.begin(); itr != st.end(); itr++) cout << *itr << (next(itr)!=st.end() ? ", " : ""); cout << "}"; return os;}
template<typename T1,typename T2>ostream& operator << (ostream& os, map<T1,T2> mp){cout << "{"; for(auto itr = mp.begin(); itr != mp.end(); itr++) cout << "(" << (itr->first) << ", " << (itr->second) << ")" << (next(itr)!=mp.end() ? "," : ""); cout << "}"; return os; }

void dump_func(){DUMPOUT << endl;}
template <class Head, class... Tail>void dump_func(Head&& head, Tail&&... tail){ DUMPOUT << head; if (sizeof...(Tail) == 0) { DUMPOUT << " "; } else { DUMPOUT << ", "; } dump_func(std::move(tail)...);}
template<class T> inline bool chmax(T& a,T const& b){if(a>=b) return false; a=b; return true;}
template<class T> inline bool chmin(T& a,T const& b){if(a<=b) return false; a=b; return true;}

using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;

int main(){
  int N,K; cin >> N >> K ;
  vvl xb(K,vl(K)),xw(K,vl(K));
  vvl sb(K+1,vl(K+1)),sw(K+1,vl(K+1));
  rep(i,N){
    ll x,y; char c;
    cin >> x >> y >> c ;
    x -= (y/K)*K;
    y %= K;
    x = (x%(2*K)+2*K)%(2*K);
    if(x>=K){
      x -= K;
      c = (c=='B' ? 'W' : 'B');
    }
    if(c=='W') xw[x][y]++;
    else xb[x][y]++;
  }
  REP(i,1,K+1) rep(j,K){
    sb[i][j+1] = sb[i][j] + xb[i-1][j];
    sw[i][j+1] = sw[i][j] + xw[i-1][j];
  }
  REP(i,0,K) rep(j,K+1){
    sb[i+1][j] += sb[i][j];
    sw[i+1][j] += sw[i][j];
  }
  ll ans = 0;
  rep(t,2) {
    rep(i,K) rep(j,K){
      ll b = sb[K][K] - sb[K][j] - sb[i][K] + sb[i][j] * 2LL; 
      ll w = sw[K][j] + sw[i][K] - sw[i][j] * 2LL;
      bool a = chmax(ans,b+w);
    }
    swap(sb,sw);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 31616
def count_score(v):
    score = [0] * m
    for j in range(m):
        t = 0
        for i in range(n):
            t += a[i][j] * v[i]
        score[j] = t
    return score


def count_money(v):
    money = 0
    for i in range(n):
        money += c[i] * v[i]
    return money


def judge_understanding(score):
    ans = True
    for j in range(m):
        if score[j] < x:
            ans = False
            break
    return ans


def pu(j, in_vec, max_money):
    if j == n - 1:
        vec0 = in_vec
        vec0[n - 1] = 0
        score0 = count_score(vec0)
        money0 = count_money(vec0)
        understanding0 = judge_understanding(score0)

        vec1 = in_vec
        vec1[n - 1] = 1
        score1 = count_score(vec1)
        money1 = count_money(vec1)
        understanding1 = judge_understanding(score1)

        if understanding0:
            ans_vec = vec0
            ans_money = money0
        elif understanding1:
            ans_vec = vec1
            ans_money = money1
        else:
            ans_vec = in_vec
            ans_money = max_money
        
        return ans_vec, ans_money

    else:
        vec0 = in_vec
        vec0[j] = 0
        ans_vec0, ans_money0 = pu(j + 1, vec0, max_money)
        
        vec1 = in_vec
        vec1[j] = 1
        ans_vec1, ans_money1 = pu(j + 1, vec1, max_money)

        if ans_money0 <= ans_money1:
            ans_money = ans_money0
            ans_vec = ans_vec0
        else:
            ans_money = ans_money1
            ans_vec = ans_vec1

        return ans_vec, ans_money


if __name__ == "__main__":
    n, m, x = map(int, input().split())    
    c = [0] * n
    a = [[0] * m] * n

    for i in range(n):
        l = [int(x) for x in input().split()]
        c[i] = l[0]
        a[i] = l[1:m + 1]


    v = [0] * n

    mm = 1
    for i in range(n):
        mm += c[i]

    ans_vec, ans_money = pu(0, v, mm)

    if mm == ans_money:
        print(-1)
    else:
        print(ans_money)
    


    
    
    




Measured memory_bytes: 9320
n,q=[int(j) for j in input().split()]
l=[]
for i in range(n):
    s,t,x=[int(j) for j in input().split()]
    l.append((s-x,1,x))
    l.append((t-x,0,x))

for i in range(q):
    d=int(input())
    l.append((d,2,i))

l.sort()

ans=[-1]*q
ll=set()
m=10**18
p=False
for i,j,x in l:
    if j==1:
        ll.add(x)
        if m>x:
            m=x
            p=True
    elif j==0:
        ll.remove(x)
        if x==m:
            p=False
    else:
        if not p:
            if ll:
                p=True
                m=min(ll)
            else:
                m=-1
        ans[x]=m
print('\n'.join(map(str,ans)))



Measured memory_bytes: 105700
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define llu long long unsigned
int main()
{
    int t,a,b,x,y,z,n,mx,mn,tmp;
    int cnt=0,ans=0;
    string s="";
    vector<int>vc;
    map<int,int>mp;
    map<char,int>mc;
    scanf("%d",&n);
    char ch,ch2;
    for(int j=1;j<=n;j++){
        ans=0;
        x=j;
        if(x*x+1+1+x+1+x>n) break;
        for(int k=1;k<=n;k++){
            x=j,y=k;
            if(x*x+y*y+1+x*y+y+x>n) break;
            for(int w=1;w<=n;w++){
                x=j,y=k,z=w;
                if(x*x+y*y+z*z+x*y+y*z+z*x<=n){
                    mp[x*x+y*y+z*z+x*y+y*z+z*x]++;
                }
                else break;
            }
        }
    }
    for(int j=1;j<=n;j++){
        printf("%d\n",mp[j]);
    }



    return 0;
}








Measured memory_bytes: 4132
d,g=map(int,input().split())
p=[]
c=[]
for i in range(d):
    P,C=map(int,input().split())
    p.append(P)
    c.append(C)
ans=sum(p)
for i in range(2**d):
    z=i
    x=[]
    for j in range(d):
        x.append(z%2)
        z=z//2
    po=0
    m=0
    for j in range(d):
        if x[j]==1:
            po+=100*(j+1)*p[j]+c[j]
            m+=p[j]
    q=[[] for j in range(d)] #残りp、c
    s=0
    for j in range(d):
        if x[j]==0:
            q[s].append(100*(j+1))
            q[s].append(p[j])
            s+=1
    q=[q[j] for j in range(d) if q[j]!=[]]
    q=sorted(q,reverse=True)
    w=len(q)
    for j in range(w):
        q[j][1]-=1
    if po>=g:
        ans=min(ans,m)
    else:
        for j in range(w):
            if po+q[j][0]*q[j][1]>=g:
                m+=(g-po+q[j][0]-1)//q[j][0]
                ans=min(ans,m)
                break
            else:
                po+=q[j][0]*q[j][1]
                m+=q[j][1]
print(ans)

Measured memory_bytes: 9320
import java.util.*;
 
public class Main {
	
    public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	int N = sc.nextInt();
    	int M = sc.nextInt();
    	List<List<Integer>> list = new ArrayList<>();
    	for (int i = 0; i < N; i++) {
    		list.add(new ArrayList<>());
    	}
    	for (int i = 0; i < M; i++) {
    		int A = sc.nextInt()-1;
    		int B = sc.nextInt()-1;
    		list.get(A).add(B);
    		list.get(B).add(A);
    	}
    	int[] res = new int[N];
    	Arrays.fill(res, -1);
    	Queue<Integer> que = new ArrayDeque<>();
    	res[0] = 0;
        que.offer(0);
        while(!que.isEmpty()) {
            int room = que.poll();
            for(int hasNum : list.get(room)) {
                if(res[hasNum] != -1) {
                	continue;
                }
                res[hasNum] = room + 1;
                que.offer(hasNum);
            }
        }
        StringBuilder sb = new StringBuilder();
        System.out.println("Yes");
        for(int i = 1; i < res.length; i++) {
            sb.append(res[i] + "\n");
        }
        System.out.print(sb);
    }
}

Measured memory_bytes: 77048
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define reps(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; --i)
#define INF 1000000000000
#define MOD 1000000007
#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0, a1, a2, a3, a4, x, ...) x
#define debug_1(x1) cout << #x1 << ": " << x1 << endl
#define debug_2(x1, x2) \
    cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << endl
#define debug_3(x1, x2, x3)                                                 \
    cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
         << x3 << endl
#define debug_4(x1, x2, x3, x4)                                             \
    cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
         << x3 << ", " #x4 << ": " << x4 << endl
#define debug_5(x1, x2, x3, x4, x5)                                         \
    cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
         << x3 << ", " #x4 << ": " << x4 << ", " #x5 << ": " << x5 << endl
#ifdef _DEBUG
#define debug(...)                                                        \
    CHOOSE((__VA_ARGS__, debug_5, debug_4, debug_3, debug_2, debug_1, ~)) \
    (__VA_ARGS__)
#else
#define debug(...)
#endif

using namespace std;
using ll = long long;

int main() {
    ll n, cnt = 0;
    cin >> n;
    reps(i, n) { cnt += (n - 1) / i; }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 3116
#include <iostream>

int main() {
  int H, N; std::cin >> H >> N;
  int sum = 0;
  for (int i = 0; i < N; ++i) {
    int a; std::cin >> a;
    sum += a;
  }
  if (H <= sum) std::cout << "Yes" << std::endl;
  else          std::cout << "No" << std::endl;
}


Measured memory_bytes: 256
num, dim = gets.chomp.split(" ").map{|s| s.to_i}
 
axs_arr = []
num.times do
  axs_arr << gets.chomp.split(" ").map{|s| s.to_i}
end
 
count = 0
axs_arr.each_with_index do |axs, i|
  axs_arr[(i+1)..-1].each do |axs_add|
    sum = 0
    dim.times do |i|
      sum += (axs[i] - axs_add[i]) ** 2
    end
    count += 1 if Math.sqrt(sum) % 1 == 0.0
  end
end
 
p count

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

#define ll long long
//~ #define endl '\n'

void solve(){
	ll x; cin>>x;
	ll ans = 0;
	for(ll i = 0; i<=2000000; i++){
		if((i * 500) > x) break;
		//~ cout<<i<<endl;
		ll n_500 = i, n_5 = (x - (i * 500)) / 5;
		ans = max(ans, (n_500 * 1000) + (n_5 * 5));
	}
	cout<<ans<<endl;
}

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int t = 1; //cin>>t;
	while(t--) solve();
	return 0;
}


Measured memory_bytes: 3612
#include <stdio.h>

int gcd(int x, int y)
{
    int r;
    while(1)
    {
        r = x % y;
        if (r == 0)
            break;
        x = y;
        y = r;
    }
    return y;
}

int main(void)
{
     int a,b;
     
     scanf("%d %d",&a,&b);
     
     printf("%d\n",gcd(a,b));

     return 0;
}

Measured memory_bytes: 1844
#include<bits/stdc++.h>
using ll=long long;
using namespace std;
#define rep(i, n) for(ll i=0; i<n; i++)
#define Rep(i, j, n) for(ll i=j; i<n; i++)
#define all(vec) vec.begin(), vec.end()
template<class T> inline bool chmin(T& a, T b) {if(a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if(a < b) {a = b; return true;} return false;}
int dh[4] = {-1, 0, 0, 1};
int dw[4] = {0, -1, 1, 0}; 
using P = pair<int, int>;
const double pi = acos(-1.0);

using Graph = vector<vector<ll>>;


ll prime[10000000];
vector<bool> is_prime;

//篩です
vector<bool> seive(ll n){
  ll  p=0;
  rep(i,n+1)is_prime[i]=true;
  is_prime[0]=is_prime[1]=false;
  Rep(i,2,n+1){
    if(is_prime[i]){
      prime[p++]=i;
      for(ll j=2*i;j<=n;j+=i)is_prime[j]=false;
    }
  }
  return is_prime;//今回はどの数が素数か？が重要なので素数で有るものをtrueにしたものを返す
}

int main(){
  //input1&prepare
  ll q;
  cin>>q;
  vector<bool>isp;

  is_prime.resize(100002);
  isp=seive(100002);
  
  vector<ll>cnt(100002);//せっかくふるいにかけてもl~rの範囲で一個一個素数or素数じゃないをすると1e10となりさすがにまずい。
  //ここはその数字までに条件を満たす数がいくつあったかをカウントする
  rep(i,100002){
    if(isp[i]&&isp[(i+1)/2])cnt[i]+=cnt[i-1]+1;
    else cnt[i]=cnt[i-1];
  }

  //output 
  ll l,r;
  rep(i,q){
    cin>>l>>r;
    ll ans=cnt[r]-cnt[l-1];
    cout<<ans<<endl;
    
  }
    
    
  return 0;
}


Measured memory_bytes: 4048
#include <stdio.h>

void selectionSort(int len, double *a){
    int mini;
    double tmp;
    for (int i = 0; i < len; i++){
        mini = i;
        for (int j = i + 1; j < len; j++){
            if (a[j] < a[mini]){
                mini = j;
            }
        }
        if (mini != i){
            tmp = a[i];
            a[i] = a[mini];
            a[mini] = tmp;
        }
    }
}

int main(void){
    int N;
    scanf("%i", &N);
    double v[N];
    for (int i = 0; i < N; i++){
        scanf("%lf", &v[i]);
    }
    selectionSort(N, &v[0]);
    for (int i = 0; i < N - 1; i++){
        v[i + 1] = (v[i] + v[i + 1]) / 2.0;
    }
    printf("%f\n", v[N - 1]);
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main(){
string s;
string t;
cin>>s;
cin>>t;
long long count=0;
long long tempt=t.size();
long long temps=s.size();
long long ans=t.size();
for(long long i=0;i<temps-tempt+1;i++){
  for(long long j=0;j<tempt;j++){

    if(s[i+j]==t[j]){
      count++;
    }
  }
  ans=min(ans,tempt-count);
  count=0;
}
cout<<ans<<endl;
return 0;

}

Measured memory_bytes: 3620