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

int N;
vector<int> adj[2010];
int V[2010], par[2010], leaf[2010], chk[2010], vis[2010];

void getLeaf(int u) {
    int acnt = 0;
    int bcnt = 0;
    for(int i = 0; i < adj[u].size(); i++) {
        int v = adj[u][i];
        if(chk[v]) continue;
        getLeaf(v);
        if(!leaf[v]) acnt++;
        else bcnt++;
    }

    if(acnt == 0 && bcnt <= 1) leaf[u] = 1;
}

int go(int u, int val) {
    for(int i = 0; i < adj[u].size(); i++) {
        int v = adj[u][i];
        if(!vis[ V[v] ] || V[v] < val) return go(v, val);
    }
    return u;
}

vector<int> sol;

void proc(int u) {
    //cout << "proc : " << u << endl;

    sol.push_back(u);
    int t = V[0];
    int v = u;
    while(v) {
        swap(V[v], t);
        v = par[v];
    }
    V[0] = t;

    /*
    for(int i = 0; i < N; i++) {
        cout << V[i] << ' ';
    }
    cout << endl;


    for(int i = 0; i < N; i++) {
        cout << vis[i] << ' ';
    }
    cout << endl;
    //*/
}

void dfs(int u) {
    for(int i = 0; i < adj[u].size(); i++) {
        int v = adj[u][i];
        dfs(v);
    }

    while(!vis[ V[0] ] && leaf[ V[0] ]) {
        vis[ V[0] ] = 1;
        proc(go(V[0], V[0]));
    }

    if(!vis[ V[u] ] && leaf[ V[u] ]) {
        proc(u);
    }
}

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

    for(int i = 1; i < N; i++) {
        int p; scanf("%d", &p);

        adj[p].push_back(i);
        par[i] = p;
    }

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

    for(int n = 0; n < 12; n++) {
        if(chk[0]) break;

        getLeaf(0);
        dfs(0);

        for(int i = 0; i < N; i++) if(!chk[i] && leaf[i]) chk[i] = 1;
    }

    /*
    for(int i = 0; i < N; i++) {
        cout << V[i] << ' ';
    }
    cout << endl;
    //*/

    printf("%d\n", sol.size());
    for(int i = 0; i < sol.size(); i++) {
        printf("%d\n", sol[i]);
    }
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=(ll)1e9+7;
const ll INF=(ll)1e18+10;
const double PI=acos(-1);

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 (a>b) { a=b; return 1; } return 0; }
int dy[]={-1,1,0,0};
int dx[]={0,0,-1,1};

void solve(int cn) {
    int N; cin>>N;
    vector<ll> a;
    for (int i = 0; i < N; ++i) {
        ll tmp; cin>>tmp;
        if(!a.empty()&&tmp==a.back()) continue;
        a.push_back(tmp);
    }
    ll cash=1000, stock=0;
    if(a.size()<2){
        cout<<cash<<endl;
        return;
    }
    for (int i = 0; i < a.size(); ++i) {
        ll amount=0;
        if(i==0&&a[0]<a[1]){
            amount = cash/a[i];
        }else if(i==a.size()-1){
            amount = -stock;
        }else{
            if(a[i]>a[i-1]&&a[i]>a[i+1]){
                amount = -stock;
            }else if(a[i]<a[i-1]&&a[i]<a[i+1]){
                amount = cash/a[i];
            }
        }
        cash-=amount*a[i];
        stock+=amount;
    }
    cout<<cash<<endl;
}


#define SINGLE
int main() {
#ifdef SINGLE
    solve(1);
#else
    int N;
    cin>>N;
    for(int i=0;i<N;++i){
        solve(i);
    }
#endif
    return 0;
}


Measured memory_bytes: 3636
/*input
10
1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1


*/ 
#include <iostream>
#include <bits/stdc++.h>
#include <math.h> 
    
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define gc getchar_unlocked
#define fo(i,n) for(ll i=0;i<n;i++)
#define Fo(i,k,n) for(ll i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define int long long
#define si(x)   scanf("%d",&x)
#define sl(x)   scanf("%lld",&x)
#define ss(s)   scanf("%s",s)
#define pi(x)   printf("%d\n",x)
#define pl(x)   printf("%lld\n",x)
#define ps(s)   printf("%s\n",s)
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define ms(a,x) memset(a, x, sizeof(a));
#define endl "\n"
typedef pair<int, int>  pii;
typedef vector<int>     vi;
typedef vector<pii>     vpii;
typedef vector<vi>      vvi;
int mpow(int base, int exp); 
void ipgraph(int m);
void dfs(int u, int par);
const int mod = 1000000007;
const int N = 1000000001;
const int MAX = 1e5+1;
int ans = 0;
int dp[3000][3000][2];
int  fn(int arr[],int n,int l,int r,int point){
	if(l>r){ 
		return 0;
	}
	if(dp[l][r][point]!=-1) return dp[l][r][point];
	if(!point){
		dp[l][r][point] = max(arr[l]+fn(arr,n,l+1,r,(point+1)%2),arr[r]+fn(arr,n,l,r-1,(point+1)%2));

	}
	else{
		dp[l][r][point] = min(-arr[l]+fn(arr,n,l+1,r,(point+1)%2),-arr[r]+fn(arr,n,l,r-1,(point+1)%2));
	}
	//cout<<dp[l][r][point]<<" "<<l<<" "<<r<<' '<<point<<endl;
	return dp[l][r][point];
}
int32_t main() {
    IOS;
	int n,k;
    cin>>n;
    int arr[n];
    for(int i=0;i<n;i++)cin>>arr[i];
    for(int i=0;i<n;i++){
    	for(int j=0;j<n;j++){
    		dp[i][j][0] = -1;
    		dp[i][j][1] = -1;
    	}
    }
    int ans = fn(arr,n,0,n-1,0);
	//cout<<dp[k][n]<<endl;
	cout<<dp[0][n-1][0]<<endl;
	return 0;
}






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

using namespace std;

typedef long long ll;

int main(){
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  string S; cin >> S;
  int N = S.size();
  int mint = N;
  for(int i=0;i<N-1;i++){
    if(S[i] != S[i+1]){
      int t = max(i+1, N-i-1);
      mint = min(t, mint);
    }
  }
  cout << mint << endl;
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
using namespace std;
int main() {
  int n;
  int b, f, r, v;
  cin >> n;
  vector<vector<vector<int>>> data(4, vector<vector<int>>(3, vector<int>(10)));

  for(int i=0; i<n; i++) {
    cin >> b >> f >> r >> v;
    data.at(b-1).at(f-1).at(r-1) += v;
  }

  for(int i=0; i<4; i++) {
    for(int j=0; j<3; j++) {
      for(int k=0; k<10; k++) {
        cout << " " << data.at(i).at(j).at(k);
      }
      cout << "\n";
    }
    if(i != 3) {
      for(int k=0; k<10; k++) {
        cout << "##";
      }
      cout << "\n";
    }
  }
  return 0;
}



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

int main(){
	int S,h,m,s;
	cin >> S ;
	h = S / 3600;
	m = S % 3600 / 60;
	s = S % 60;
	cout << h << ":" << m << ":" << s << endl;

	
	return 0;
}

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

namespace ABC112
{
    class D
    {
        static void Main(string[] args)
        {
            long[] input = Console.ReadLine().Split().Select(long.Parse).ToArray();
            long N = input[0];
            long M = input[1];

            long res = 0;

            for (long i = 1; i <= Math.Sqrt(M) + 1; i++)
            {

                if (M % i == 0)
                {
                    if (i <= M / N) res = Math.Max(res, i);
                    if (M / i <= M / N) res = Math.Max(res, M / i);
                }

            }
            Console.WriteLine(res);

        }
    }
}


Measured memory_bytes: 13396
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

class LowLink:
    def __init__(self, v):
        self.size = len(v)
        self.v = v
        self.pre = [None]*self.size
        self.low = [None]*self.size
        self.par = [None]*self.size
        self.articulation = []
        self.bridge = []
        for x in range(self.size):
            if self.pre[x] is None:
                self.cnt = 0
                self.pre[x] = self.low[x] = self.cnt
                self.dfs(x)

    def dfs(self, x):
        is_articulation = False
        n = 0
        for y in self.v[x]:
            if self.pre[y] is None:
                self.cnt += 1
                n += 1
                self.pre[y] = self.low[y] = self.cnt
                self.par[y] = x
                py = self.dfs(y)
                if py < self.low[x]:
                    self.low[x] = py
            else:
                if self.par[x] != y and self.pre[y] < self.low[x]:
                    self.low[x] = self.pre[y]
            if self.pre[x] <= self.low[y]:
                if self.pre[x]:
                    is_articulation = True
                if self.pre[x] < self.low[y]:
                    self.bridge.append((x,y))

        if self.pre[x] == 0 and n > 1:
            is_articulation = True
        if is_articulation:
            self.articulation.append(x)
        return self.low[x]


def solve():
    n,m = LI()
    v = [[] for i in range(n)]
    for i in range(m):
        a,b = LI()
        a -= 1
        b -= 1
        v[a].append(b)
        v[b].append(a)
    ans = LowLink(v)
    print(len(ans.bridge))
    return

#Solve
if __name__ == "__main__":
    solve()


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

int main() {
    int n; cin >> n;
    vector<ll> a(n);
    rep(i,n) cin >> a.at(i);

    ll maxa = 0;
    ll maxb = 1000000000000;
    for(int i=0; i<n; i++){
        maxa = max(maxa, a.at(i));
        maxb = min(maxb, a.at(i));
    }

    cout << maxa - maxb << endl;
}


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

using namespace std;
#define MAXN 100002

vector <pair <int,int> > adj[MAXN];
bool colors[MAXN];

void dfs(int node, int parent = - 1, long long int w = 0){
  colors[node] = w % 2;
  for(pair <int,int> &i : adj[node]){
    if(i.first == parent)continue;
    dfs(i.first,node, w + i.second);
  }
}
int main(){
  int N;
  cin >> N;
  for(int i = 1, a, b, w; i < N; i++){
    	cin >> a >> b >> w;
    	adj[a].push_back({b,w});
    	adj[b].push_back({a,w});
  }
  dfs(1);
  for(int i = 1; i <= N; i++){
    cout << colors[i] << '\n';
  }
}

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

#define repo(i,n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;

int main(){
    string S;

    cin >> S;

    string a = S;
    
    reverse(a.begin(),a.end());    
    if(S!=a){
        cout << "No" << endl;
        return 0;
    }

    int N = S.size();
    string fs;
    repo(i,(N-1)/2){
        fs.push_back(S[i]);

    }
    string bfs = fs;
    reverse(bfs.begin(),bfs.end());
    if(fs != bfs){
        cout << "No" << endl;
        return 0;
    } 

    string bs;
    for(int i = (N+3)/2 - 1; i < S.size();i++){
        bs.push_back(S[i]);
    }
    string bbs = bs;
    reverse(bbs.begin(),bbs.end());
    if(bs !=  bbs){
        cout << "No" << endl;
        return 0;
    }

    cout << "Yes" << endl;


    return 0;
}



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

#define dump(x) cout << (x) << '\n'
#define Int int64_t
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
 
Int INF = 1e18;
int inf = 1e9;
//Int mod = 1e9+7;
Int mod = 998244353;

Int n;
vector<Int> G[200001];
bool visited[200001];

Int rec(Int x) {
    visited[x] = true;
    Int ret = 1;
    for (Int i = 0; i < (Int)G[x].size(); i++) {
        ret = ret * rec(G[x][i]) % mod;
    }
    return ret + 1;
}

int main() {
    cin >> n;
    vector<pair<Int, Int>> v(n);
    for (Int i = 0; i < n; i++) {
        cin >> v[i].fi >> v[i].se;
    }
    sort(all(v));
    vector<tuple<Int, Int, Int>> vv;
    for (Int i = 0; i < n; i++) {
        vv.emplace_back(v[i].fi, i, 0);
        vv.emplace_back(v[i].fi + v[i].se, i, 1);
    }
    sort(all(vv));
    stack<pair<Int, Int>> st;
    for (Int i = 0; i < n; i++) {
        while (not st.empty() and not (v[i].fi < st.top().se)) {
            st.pop();
        }
        if (not st.empty()) {
            G[st.top().fi].push_back(i);
        }
        st.push({i, v[i].fi + v[i].se});
    }
    Int res = 1;
    for (Int i = 0; i < n; i++) {
        if (visited[i]) continue;
        res = res * rec(i) % mod;
    }
    dump(res);
    return 0;
}


Measured memory_bytes: 37736
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
//const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
//const ll MOD = ;
ll mod(ll A, ll M) {return (A % M + M) % M;}
const ll INF = 1LL << 60;
template<class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
ll divceil(ll A, ll B) {return (A + (B - 1)) / B;}
ll myctoi(char C) {return C - '0';}
char myitoc(ll N) {return '0' + N;}
#define FINALANS(A) {cout << (A) << '\n'; exit(0);}

int main()
{
  ll H, W;
  cin >> H >> W;
  vector<vector<ll>> A(H, vector<ll>(W));
  for (ll i = 0; i < H; i++)
  {
    for (ll j = 0; j < W; j++)
    {
      cin >> A.at(i).at(j);
    }
  }

  ll y = 0, x = 0;
  ll s = 0;
  vector<tuple<ll, ll, ll, ll>> ans;
  for (ll i = 0; i < H * W - 1; i++)
  {
    ll ny = y, nx = x;
    if (y % 2 == 0)
    {
      if (x == W - 1)
        ny++;
      else
        nx++;
    }
    else
    {
      if (x == 0)
        ny++;
      else
        nx--;
    }

    s += A.at(y).at(x);
    s %= 2;
    if (s == 1)
      ans.push_back(make_tuple(y, x, ny, nx));

    y = ny, x = nx;
  }

  cout << ans.size() << endl;
  for (ll i = 0; i < ans.size(); i++)
  {
    cout << get<0>(ans.at(i)) + 1 << " ";
    cout << get<1>(ans.at(i)) + 1 << " ";
    cout << get<2>(ans.at(i)) + 1 << " ";
    cout << get<3>(ans.at(i)) + 1 << endl;
  }
}

Measured memory_bytes: 8304
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include <stdlib.h>
#include <string>
#include <bitset>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <sstream>
#include <stack>
#include <iomanip>
using namespace std;
#define pb push_back
#define mp make_pair
typedef pair<int,int> pii;
typedef long long ll;
typedef double ld;
typedef vector<int> vi;
#define fi first
#define se second
#define fe first
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
#define Edg int M=0,fst[SZ],vb[SZ],nxt[SZ];void ad_de(int a,int b){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;}void adde(int a,int b){ad_de(a,b);ad_de(b,a);}
#define Edgc int M=0,fst[SZ],vb[SZ],nxt[SZ],vc[SZ];void ad_de(int a,int b,int c){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;vc[M]=c;}void adde(int a,int b,int c){ad_de(a,b,c);ad_de(b,a,c);}
#define es(x,e) (int e=fst[x];e;e=nxt[e])
#define esb(x,e,b) (int e=fst[x],b=vb[e];e;e=nxt[e],b=vb[e])
#define SZ 666666
int T,n;
set<int> s1[233],s2[233];
void adde(set<int>*v,int a,int b)
{v[a].insert(b); v[b].insert(a);}
void dele(set<int>*v,int a,int b)
{v[a].erase(b); v[b].erase(a);}
int C=0,a1[SZ],b1[SZ],a2[SZ],b2[SZ];
bool good[SZ];
int gans(int x,int f=0)
{
	int s=1; good[x]=1;
	for(auto b:s1[x])
		if(b!=f&&s2[x].count(b)) s+=gans(b,x);
	return s;
}
vector<int> e3[SZ]; int d[SZ];
void dfs(set<int>*e,int*a,int*b,int c,int x,int f=0)
{
	a[x]=++C;
	for(auto t:e[x]) if(t!=f)
	{
		if(!good[t]&&!good[x])
		{
			if(c) e3[x].pb(t),++d[t];
			else e3[t].pb(x),++d[x];
		}
		dfs(e,a,b,c,t,x);
	}
	b[x]=C;
}
int calc(int t)
{
	for(int i=1;i<=n;++i) good[i]=d[i]=0,e3[i].clear();
	int u=n-gans(t);
	dfs(s1,a1,b1,0,t);
	dfs(s2,a2,b2,1,t);
	queue<int> q;
	for(int i=1;i<=n;++i)
		if(!d[i]) q.push(i);
	while(!q.empty())
	{
		int x=q.front(); q.pop();
		for(auto b:e3[x])
			if(!(--d[b])) q.push(b);
	}
	for(int i=1;i<=n;++i)
		if(d[i]) return 2e9;
	return u;
}
bool vis[SZ];
void ddd(set<int>*e,int x)
{
	vis[x]=1;
	for(auto b:e[x]) if(!vis[b]) ddd(e,b);
}
void sol()
{
	scanf("%d",&n);
	for(int i=1;i<=n;++i)
		s1[i].clear(),s2[i].clear();
	for(int i=1,a,b;i<n;++i)
		scanf("%d%d",&a,&b),adde(s1,a,b);
	for(int i=1,a,b;i<n;++i)
		scanf("%d%d",&a,&b),adde(s2,a,b);
	int ans=2e9;
	for(int i=1;i<=n;++i)
		ans=min(ans,calc(i));
	for(int i=1;i<=n;++i) if(s2[i].size()==1)
	{
		int v=*s2[i].begin();
		dele(s2,i,v);
		for(int j=1;j<=n;++j) if(v!=j)
		{
			adde(s2,i,j);
			for(int k=1;k<=n;++k) vis[k]=0;
			ddd(s2,1);
			bool gg=0;
			for(int k=1;k<=n;++k)
				if(!vis[k]) gg=1;
			if(!gg)
			{
				int w=calc(i);
				if(w==n-1) ans=min(ans,n);
			}
			dele(s2,i,j);
		}
		adde(s2,i,v);
	}
	if(ans>n+2) ans=-1;
	printf("%d\n",ans);
}
int main()
{
	scanf("%d",&T);
	while(T--) sol();
}


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

int main()
{
  int n;
  cin >> n;
  int a[n];
  for(int i = 0; i < n; i++)
  {
    cin >> a[i];
  }
  int max, min;
  long long sum;

  for(int i = 0; i < n - 1; i++)
  { 
    if(a[i] > a[i+1])
    {
      int ex = a[i];
      a[i] = a[i+1];
      a[i+1] = ex;
    }
  }

  max = a[n-1];


  for(int i = n-1; i>0; i = i-1)
  {
    if(a[i] < a[i-1])
    {
      int sx = a[i];
      a[i] = a[i-1];
      a[i-1] = sx;
    }
  }

  min = a[0];

  for(int i = 0; i < n; i++)
  {
    sum = sum + a[i];
  }

  cout << min << " " << max << " " << sum << endl;
  return 0;
}


Measured memory_bytes: 3132
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)

ll mod = 1e09;

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

  int n;
  cin >> n;
  string s;
  cin >> s;

  int rec = 0, ans = 0;
  REP(i, n){
    if(s[i] == 'I') rec++;
    else rec--;
    ans = max(rec, ans);
  }
  cout << ans << endl;
}


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

string S;
typedef long long ll;

ll stollx(const string s){
  stringstream ss(s);
  ll a;
  ss >> a;
  return a;
}

int main(){

  cin >> S;
  int n = S.size();  
  ll res = 0;
  for(int i=0;i<(1<<(n-1));i++){

    string num = "";
    for(int j=0;j<n;j++){
      num += S[j];
      if( i & (1<<j) ){
        res += stollx( num );
        num = "";
      }
    }
    res += stollx( num );
  }
  cout << res << endl;
}


Measured memory_bytes: 256
N = int(input())
A = list(map(lambda x:int(x)-1, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

ans = 0
for now, nex in zip(A, A[1:]):
  ans += B[now]
  if now+1 == nex:
    ans += C[now]
ans += B[A[-1]]
print(ans)



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

int main(){
	int n;
	cin >> n;
	string s;
	cin >> s;
	int counts = 0;
	int mx = 0;
	rep(i,n){
		if(s[i] == 'I') counts++;
		else if(s[i] == 'D') counts--;

		mx = max(mx,counts);
	}
	cout << mx << endl;
}

Measured memory_bytes: 3628
///Bismillahir Rahmanir Rahim
#include<bits/stdc++.h>
#define u64 uint64_t
#define ll long long
#define endl "\n"
#define PI acos(-1)
#define fi first
#define si second
#define mp make_pair
#define pb push_back
#define set0(arr) memset(arr,0,sizeof(arr))
#define setinf(arr) memset(arr,126,sizeof(arr))
#define vsort(v) sort(v.begin(),v.end())
#define all(x) (x).begin(),(x).end()
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
using pll = pair<ll,ll>;
using vl = vector<ll>;
using vpll = vector<pll>;
using mll = map<ll,ll>;
using mcl = map<char,ll>;
using sl = set<ll>;
using sc = set<char>;
using dl = deque<ll>;
ll mod=1e9+7;
const int N=1e6+5;
vl adj[200005];
vpll adjc[200005];
ll vis[200005],dis[200005];
ll arr[N];
void dfs(ll x)
{
    vis[x]=1;
    for(ll i=0;i<adjc[x].size();i++)
    {
        auto p=adjc[x][i];
        if(!vis[p.first])
        {
            dis[p.first]=dis[x]+p.second;
            dfs(p.first);
        }
    }
}
int main()
{
    IOS;
    ll a,b,c,d,sz,n,m,p,x,y,z,i,j,k,f=0,tc,cnt=0,sum=0,mul=1,mi=1e18,ma=-1e18;
    string str;
    char ch;
    double db;
    //code
    cin>>n;
     set0(vis);
    for(i=1;i<n;i++)
    {
        cin>>a>>b>>c;
        adjc[a].pb({b,c});
        adjc[b].pb({a,c});
    }
    dis[1]=0;
    dfs(1);
   for(i=1;i<=n;i++)
   {
       cout<<dis[i]%2<<endl;
   }



    //code
    return 0;
}


Measured memory_bytes: 21988
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

const int mod = 1e9 + 7;
const int IMAX = 1000000;
constexpr ll modpow(ll A, ll B) {
	ll kotae = 1;
	while (B > 0) {
		if (B & 1) kotae = kotae * A % mod;
		A = A * A % mod;
		B >>= 1;
	}
	return kotae;
}
class unko {
public:
	int fac[IMAX + 1], ifac[IMAX + 1], inv[IMAX + 1];
	constexpr unko() : fac(), ifac(), inv() {
		fac[0] = 1;
		rep1(i, IMAX) fac[i] = ll(fac[i - 1]) * i % mod;
		ifac[IMAX] = modpow(fac[IMAX], mod - 2);
		for (int i = IMAX; i > 0; i--) ifac[i - 1] = ll(ifac[i]) * i % mod;
		inv[0] = 1;
		rep1(i, IMAX) inv[i] = ll(ifac[i]) * fac[i - 1] % mod;
	}
	int comb(int A, int B) {
		return ll(fac[A]) * ifac[B] % mod * ifac[A - B] % mod;
	}
} f;

int sosuu[168] = { 2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199,211,223,227,229,233,239,241,251,257,263,269,271,277,281,283,293,307,311,313,317,331,337,347,349,353,359,367,373,379,383,389,397,401,409,419,421,431,433,439,443,449,457,461,463,467,479,487,491,499,503,509,521,523,541,547,557,563,569,571,577,587,593,599,601,607,613,617,619,631,641,643,647,653,659,661,673,677,683,691,701,709,719,727,733,739,743,751,757,761,769,773,787,797,809,811,821,823,827,829,839,853,857,859,863,877,881,883,887,907,911,919,929,937,941,947,953,967,971,977,983,991,997 };

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


	int N = getint();

	vector<int> V;
	int P[168] = {};

	ll kari = 0;
	rep(i, N) {
		int tmp = getint();
		kari += f.inv[tmp];
		rep(j, 168) {
			int ptmp = 0;
			while (tmp % sosuu[j] == 0) {
				ptmp++;
				tmp /= sosuu[j];
			}
			chmax(P[j], ptmp);
		}
		if (tmp != 1) V.pb(tmp);
	}
	sort(V.begin(), V.end());

	ll lcm = 1;
	rep(i, 168) {
		rep(j, P[i]) {
			lcm = lcm * sosuu[i] % mod;
		}
	}
	int mae = -1;
	for (int i : V) {
		if (mae != i) {
			lcm = lcm * i % mod;
			mae = i;
		}
	}

	kari %= mod;
	printf("%lld", lcm* kari% mod);


	Would you please return 0;
}

Measured memory_bytes: 384
#include<stdio.h>
#include<iostream>
#include<string.h>
#include <iomanip>
#include<math.h>
#include<queue>
#include<vector>
#define Max (int)105
#define MAX2 (int)1e5+5
#define MOD ((int)1e9+7)
using namespace std;

long long int a[Max],dp[Max][MAX2],prefix[Max][MAX2];

void init(int n,int k){
	int i,j;

	for(j=0;j<MAX2;j++)
		prefix[0][j] = 1;

	for(i=1;i<=n;i++){
		for(j=0;j<=k;j++){
			if(j-a[i]-1 >= 0)
				dp[i][j] = (prefix[i-1][j] - prefix[i-1][j-a[i]-1]+MOD)%MOD;
			else
				dp[i][j] = prefix[i-1][j]%MOD;


			//printf("%d %d %d\n",i,j,dp[i][j]);
			prefix[i][j] = dp[i][j];
			if(j-1 >= 0)
				prefix[i][j] = (prefix[i][j] + prefix[i][j-1])%MOD;
			
		}
	}

}


int main(){
	
	int n,k,i;
	scanf("%d%d",&n,&k);
	for(i=0;i<n;i++)
		scanf("%lld",&a[i+1]);

	init(n,k);
	printf("%lld\n",dp[n][k]);


}










/*
Atcoder Dp G-Longest Path iterative solution

vector<int>vec[Max];
queue<int>q;

int dp[Max];
int vis[Max];

void init(){
	int i;
	for(i=0;i<Max;i++){
		dp[i] = 0;
		vis[i] = 0;
	}
}

int getMax(int a,int b){
	return (a<b)?b:a;
}

void solve(int x){
	int i,u;
	q.push(x);

	while(!q.empty()){
		u = q.front();
		q.pop();

		if(vis[u])
			continue;
		vis[u] = 1;
		
		for(i=0;i<vec[u].size();i++){
			dp[vec[u][i]] = getMax(dp[vec[u][i]],dp[u]+1);
			q.push(vec[u][i]);
		}
	}

}

int main(){
	int n,m,incoming[Max],x,y,i;
	for(i=0;i<Max;i++)
		incoming[i] = 0;
	
	init();

	scanf("%d%d",&n,&m);
	for(i=0;i<m;i++){
		scanf("%d%d",&x,&y);
		vec[y].push_back(x);
		incoming[x]++;
	}
	
	for(i=1;i<=n;i++)
		solve(i);
	
	int max = 0;
	for(i=0;i<Max;i++)
		max = getMax(max,dp[i]);
	
	printf("%d\n",max);
	return 0;
}
*/

Measured memory_bytes: 160000
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin >> n;
    int ans = 300;
    int count = 0;
    for(int i = 0;i < n;i++)
    {
        int a;
        cin >> a;
        while(a % 2 == 0)
        {
            a /= 2;
            count++;
        }
        if(count < ans)
        {
            ans = count;
        }
        count = 0;
    }
    cout << ans;

    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		for (int i = 1; i < 10; i++) {
		    for (int j = i; j < 10; j++) {
		        if (i * j == n) {
              		System.out.println("Yes");
              		return;
		        }
		    }
		}
		System.out.println("No");
	}
}


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

template <typename A, typename B>
string to_string(pair<A, B> p);
 
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);
 
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);
 
string to_string(const string& s) {
  return '"' + s + '"';
}

string to_string(const char& ch) {
	string s = "";
	s += ch;
	return "'" + s + "', ";
}
 
string to_string(const char* s) {
  return to_string((string) s);
}
 
string to_string(bool b) {
  return (b ? "true" : "false");
}
 
string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}
 
template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}
 
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
 
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
 
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}
 
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}
 
void debug_out() { cout << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << " " << to_string(H);
  debug_out(T...);
}
 
#ifdef LOCAL_DEFINE
#define debug(...) cout << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif
   
#define int long long
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(),(v).end()
typedef pair<int, int> pii;
const int mod = (int) 1000000007; // 998244353;
const int inf = (int) 2e18;



int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout << fixed << setprecision(9);
	#ifdef LOCAL_DEFINE
		freopen("in.txt", "rt", stdin);
	#endif
	
	int n, k;
	cin >> n >> k;
	vector<int> a(n);
	for(int& x : a)
		cin >> x;
	sort(all(a));
	cout << accumulate(a.begin(), a.begin() + k, 0ll) << '\n';
	
	
	return 0;
}






Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
vector<int> v;
int main()
{
    ios::sync_with_stdio(false); cin.tie(0);
    long long mod=1e9 + 7;
    long long n; cin>>n;
    long long p=1;
    for(int i=1;i<=n;i++) p=(p*i)%mod;
    cout<<p%mod;
}


Measured memory_bytes: 256
extern crate core;

use std::io::{self, Read};
use std::iter::Iterator;

fn main() {
    let mut input = String::new();
    io::stdin().read_to_string(&mut input).unwrap();
    let output = run(input);
    println!("{}", output);
}

fn run(input: String) -> String {
    fn f(list: Vec<i64>, count: i32) -> i32 {
        if list.iter().all(|&x| x % 2 == 0) {
            f(list.iter().map(|x| x / 2).collect(), count + 1)
        } else {
            count
        }
    }

    f(
        input
            .split("\n")
            .nth(1)
            .unwrap()
            .split_whitespace()
            .map(|x| x.parse::<i64>().unwrap())
            .collect(),
        0,
    ).to_string()
}

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

int main(){
	int n;
  	cin>>n;
  vector<int> v1(n);
  vector<int> v2(n);
  for(int i=0;i<n;i++){
  	cin>>v1[i]>>v2[i];
  }
  bool res= false;
  int k =3;
  for(int i=0;i<n;i++){
  	if(v1[i]==v2[i])k--;
    else (k=3);
    if(k<=0){
      res = true;
      break;}

  }
  if(res) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 3628
#include <iostream>
#include <algorithm>
#include <map>
#include <vector>
#include <set>
#include <bitset>
#include <unordered_map>
#include <queue>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <cstring>
#include <cmath>

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

int main(){
    ll N;
    ll ans = 0;
    cin >> N;
    if( N%2 == 1){
        cout << 0 << endl;
        return 0;
    }

    N /= 2;
    while( N > 0){
        ans += (N /= 5);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python
# -*- coding:utf-8 -*-

from __future__ import division, print_function, absolute_import, unicode_literals

W, H = map(int, input().split())
cx = 0
cy = 0
P = [(i, int(input()), 'W') for i in range(W)]
Q = [(i, int(input()), 'H') for i in range(H)]

PQ = sorted(P+Q, key=lambda x: x[1])
ans = 0
for index, cost, wh in PQ:
    if wh == 'W':
        cx += 1
        ans += cost * (H + 1 - cy)
    elif wh == 'H':
        cy += 1
        ans += cost * (W + 1 - cx)
print(ans)


Measured memory_bytes: 38268
//abc157_e.cpp
//Sun Mar  1 20:09:52 2020

#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#define INTINF 2147483647
#define LLINF 9223372036854775807
#define MOD 1000000007

using namespace std;
using ll=long long;
typedef pair<char,int> P;


int main(){
	int n;
	cin >> n;
	string s;
	cin >> s;
	int q;
	cin >> q;

	set<int> letter[26];
	for (int i=0;i<26;i++){
		letter[i].insert(INTINF);
	}
	for (int i=0;i<s.length();i++){
		letter[s[i]-'a'].insert(i);
	}

	for (int i=0;i<q;i++){
		int num;
		cin >> num;
		if (num==1){
			int iq;
			char cq;
			cin >> iq >> cq;
			iq--;
			letter[s[iq]-'a'].erase(iq);
			letter[cq-'a'].insert(iq);
			s[iq] = cq;
		}else {
			int l,r;
			cin >> l >> r;
			l--;
			int ans = 0;
			for (int j=0;j<26;j++){
				if (letter[j].empty()){
					continue;
				}
				int lid = *letter[j].lower_bound(l);
				int rid = *letter[j].lower_bound(r);
//				cout << j << " " << lid << " " <<rid << endl;
				if (rid-lid > 0){
					ans++;
				}
			}
			cout << ans << endl;
		}
	}

}

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

int a[6], b[6];

bool comp(int i, int j) {
	return a[i]*(a[j]+b[j])>a[j]*(a[i]+b[i]);
}

int main() {
	for (int i=0;i<6;i++) scanf("%d",&a[i]);
	for (int i=0;i<6;i++) scanf("%d",&b[i]);
	vector<int> order;
	for (int i=0;i<6;i++) if (a[i]+b[i]) order.push_back(i);
	sort(order.begin(),order.end(),comp);
	double ans = 0;
	double cur = 0;
	for (int i: order) {
		double t = min(1.,(100-cur)/(a[i]+b[i]));
		ans+=a[i]*t;
		cur+=(a[i]+b[i])*t;
	}
	printf("%1.9f\n",ans/100);

	return 0;
}

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

typedef long long ll;
using namespace std;

int main() {
    ll x, k, d;
    cin >> x >> k >> d;
    x = abs(x);
    ll stp = x / d;
    ll ans;
    if (k >= stp) {
        if ((k - stp) % 2 == 0) {
            ans = abs(x - stp * d);
        }
        else {
            stp++;
            ans = abs(x - stp * d);
        }
    }
    else {
        ans = abs(x - k * d);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3568
# たくさんあるものから優先していきのこらせる
import numpy as np
N,K = map(int,input().split())
A = np.array(input().split(), dtype=np.int32)
counter = np.bincount(A)
counter.sort()
counter = counter[::-1] # desc order
no_change = counter[:K].sum()
answer = N - no_change
print(answer)

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

using namespace std;

int dp[3001][3001];
char c[3001][3001];
string s, t;

void print_lcs(int i, int j)
{
	if (i == 0 || j == 0) return;
	if (c[i][j] == 'd')
	{
		print_lcs(i - 1, j - 1);
		cout << s[i - 1];
	}
	else if (c[i][j] == 'u')
	{
		print_lcs(i - 1, j);
	}
	else
	{
		print_lcs(i, j - 1);
	}
}

int main()
{
	cin >> s >> t;
	for (auto i = 0; i < s.size(); i++)
	{
		for (auto j = 0; j < t.size(); j++)
		{
			if (s[i] == t[j])
			{
				dp[i + 1][j + 1] = dp[i][j] + 1;
				c[i + 1][j + 1] = 'd';
			}
			else if (dp[i][j + 1] >= dp[i + 1][j])
			{
				dp[i + 1][j + 1] = dp[i][j + 1];
				c[i + 1][j + 1] = 'u';
			}
			else
			{
				dp[i + 1][j + 1] = dp[i + 1][j];
				c[i + 1][j + 1] = 'l';
			}
		}
	}

	print_lcs(s.size(), t.size());
}


Measured memory_bytes: 44288
import copy


input_line = input().split()
grid_size = int(input_line[0])
num_color = int(input_line[1])

differential_cost = {}
for color_from in range(1, num_color + 1):
    input_line = input().split()
    for color_to in range(1, num_color + 1):
        differential_cost[(color_from, color_to)] = int(input_line[color_to-1])

color_map = {}
for x in range(1, grid_size + 1):
    input_line = input().split()
    for y in range(1, grid_size + 1):
        color_map[(x, y)] = int(input_line[y-1])

current_color_dict = {}
for color in range(1, num_color+1):
    current_color_dict[color] = 0

current_color_mod0 = copy.deepcopy(current_color_dict)
current_color_mod1 = copy.deepcopy(current_color_dict)
current_color_mod2 = copy.deepcopy(current_color_dict)

for index, color in color_map.items():
    x, y = index
    if (x + y) % 3 == 0:
        current_color_mod0[color] += 1
    elif (x + y) % 3 == 1:
        current_color_mod1[color] += 1
    elif (x + y) % 3 == 2:
        current_color_mod2[color] += 1

combinations = [(color_mod0, color_mod1, color_mod2)
                for color_mod0 in range(1, num_color+1)
                for color_mod1 in range(1, num_color+1)
                for color_mod2 in range(1, num_color+1)]

cost_list = []
for combination in combinations:
    color_mod0, color_mod1, color_mod2 = combination
    if color_mod0 == color_mod1 or color_mod0 == color_mod2 or color_mod1 == color_mod2:
        continue

    cost = 0
    for color_from in range(1, num_color+1):
        cost += differential_cost[(color_from, color_mod0)] * current_color_mod0[color_from]
        cost += differential_cost[(color_from, color_mod1)] * current_color_mod1[color_from]
        cost += differential_cost[(color_from, color_mod2)] * current_color_mod2[color_from]

    cost_list.append(cost)

print(str(min(cost_list)))


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

int main(){
	int a, b, c;	cin >> a >> b >> c;
	set <int> st;
	st.insert(a);
	st.insert(b);
	st.insert(c);
	if(st.size() == 2)	puts("Yes");
	else				puts("No");
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static Scanner sc = new Scanner(System.in);
    public static void main(String[] args) throws Exception {
        String s = sc.next();
        Map<String, Integer> map = new HashMap<>();
        
        for (int i = 0; i < s.length(); i++) {
            String temp = s.substring(i, i+1);
            if (map.containsKey(temp)) {
                map.put(temp, map.get(temp)+1);
            } else {
                map.put(temp, 1);
            }
        }
        
        for (Map.Entry<String, Integer> entry: map.entrySet()) {
            if (entry.getValue()%2 != 0) {
                System.out.println("No");
                return;
            }
        }
        System.out.println("Yes");
    }
}


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

int main()
{
	int a1[4][11],a2[4][11],a3[4][11],a4[4][11],b,f,r,v,n,i,j,k;
	cin>>n;
	for(i=1;i<=3;i++)
	{
		for(j=1;j<=10;j++)
			a1[i][j]=a2[i][j]=a3[i][j]=a4[i][j]=0;
	}
	for(k=1;k<=n;k++)
	{
		cin>>b>>f>>r>>v;
		switch(b)
		{
			case 1:
				a1[f][r] += v;
				break;
			case 2:
				a2[f][r] += v;
				break;
			case 3:
				a3[f][r] += v;
				break;
			case 4:
				a4[f][r] += v;
				break;
		}
	}

	for(i=1;i<=3;i++)
	{
	   	for(j=1;j<=10;j++)
	   		cout<<' '<<a1[i][j];
	   	cout<<endl;	
	}
	cout<<"####################"<<endl;
		for(i=1;i<=3;i++)
	{
	   	for(j=1;j<=10;j++)
	   		cout<<' '<<a2[i][j];
	   	cout<<endl;	
	}
	cout<<"####################"<<endl;
		for(i=1;i<=3;i++)
	{
	   	for(j=1;j<=10;j++)
	   		cout<<' '<<a3[i][j];
	   	cout<<endl;	
	}
	cout<<"####################"<<endl;
		for(i=1;i<=3;i++)
	{
	   	for(j=1;j<=10;j++)
	   		cout<<' '<<a4[i][j];
	   	cout<<endl;	
	}
	return 0;
 } 


Measured memory_bytes: 3108
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = std::int_fast64_t;
using std::cout;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

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

	printf("%d\n", (a < 10 and b < 10 ? a * b : -1));
	return 0;
}


Measured memory_bytes: 256
#5814544

from bisect import bisect_left

N,Q = map(int,input().split())

STX = []
D = []
for _ in range(N):
    STX.append(list(map(int,input().split())))
for _ in range(Q):
    D.append(int(input()))

STX.sort(key=lambda x:x[2])

ans = [-1]*Q
skip = [-1]*Q

for s,t,x in STX:
    left = bisect_left(D,s-x)
    right = bisect_left(D,t-x)

    while left < right:
        if skip[left] == -1:
            ans[left] = x
            skip[left] = right
            left += 1
        else:
            left = skip[left]
    
for a in ans:
    print(a)

Measured memory_bytes: 74228
// {{{ by unolight
#include <bits/stdc++.h>
#define SZ(x) ((int)(x).size())
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REP1(i,a,b) for (int i = a; i <= (int)(b); i++)
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define PB push_back
#define MP make_pair
using namespace std;
typedef long long LL;
typedef vector<int> VI;
typedef pair<int,int> PII;

#ifdef UNOLIGHT
#include "dump.hpp"
#else
#define dump(...)
#endif

template<class T> inline bool chmax( T &a, const T &b ) { return b>a ? a=b,true : false; }
template<class T> inline bool chmin( T &a, const T &b ) { return b<a ? a=b,true : false; }
template <class T, class F = less<T>>
void sort_uniq(vector<T> &v, F f = F()) {
    sort(begin(v), end(v), f);
    v.resize(unique(begin(v), end(v)) - begin(v));
}
// }}}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n, qq;
    cin >> n >> qq;
    char s[n+5];
    cin >> (s+1);
    vector<char> t(qq), d(qq);
    REP(i,qq) cin >> t[i] >> d[i];
    auto ok = [&] ( int x ) {
        for ( int i=0; i<qq; i++ ) {
            if ( s[x]==t[i] ) {
                if ( d[i]=='L' ) x--;
                else x++;
            }
        }
        if ( x<1 ) return 1;
        else if ( x>n ) return 2;
        return 0;
    };
    int L, R;
    { // left bound
        int l=0, r=n+1;
        while ( r-l>1 ) {
            int x=(l+r)>>1;
            if ( ok(x)==1 ) {
                l=x;
            } else {
                r=x;
            }
        }
        L=l;
    }
    { // right bound
        int l=0, r=n+1;
        while ( r-l>1 ) {
            int x=(l+r)>>1;
            if ( ok(x)==2 ) {
                r=x;
            } else {
                l=x;
            }
        }
        R=r;
    }
    cout << n - min(n, L+n-R+1) << '\n';
    return 0;
}


Measured memory_bytes: 3892
#include <stdio.h>
#include <string.h>
int main() {
	int numA=0,numB=0;
	char s[100001]={};
	scanf("%s", s);
	for (int i = 0; i < strlen(s); i++) {
		if(i%2==0){
			if(s[i]=='1')
				numA++;
			else
				numB++;
		}else{
			if(s[i]=='0')
				numA++;
			else
				numB++;
		}
	}
	printf("%d\n", numA>numB?numB:numA);
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>
using namespace std;
 
#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
 
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }

int main(){
    long long q,h,s,d;
    long long n;
    cin>>q>>h>>s>>d;
    cin>>n;
    long long min1=min({4*q,2*h,s});
    long long min2=min({8*q,4*h,2*s,d});
    if(n%2==0) cout<<min2*(n/2)<<endl;
    else cout<<min(min2*(n/2)+min1,min1*n)<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <functional>
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <queue>
#include <string>
#include <cstring>
#include <math.h>
using namespace std;

int main() {
    string n;
   
 
   cin >> n;
  
  int judge = 0;
  
  int num = n.size();
  
  for(int i = 0;i<num;i++){
    
    int m = i+1;
    
    if(m%2==0){
      
       if(n[i]=='L'||n[i]=='U'||n[i]=='D'){
         //cout << n[i] <<endl;
         judge++;
       }
      
    }else{
      
      if(n[i]=='R'||n[i]=='U'||n[i]=='D'){
         //cout << n[i] <<endl;
         judge++; 
      }
    }
    
  }
  
  if(judge==num){
    cout << "Yes" <<endl;
  }else{
    cout << "No" <<endl;
  }
   

  return 0;
}

Measured memory_bytes: 3616
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import itertools


def main():
  n, req_a, req_b, req_c = map(int, input().split())
  reqs = [req_a, req_b, req_c]
  sizes = [int(input()) for _ in range(n)]
  minimum = float('inf')

  for pattern in itertools.product(range(-1, 3), repeat=n):
    if  0 not in pattern or 1 not in pattern or 2 not in pattern:
      continue

    uses = [[], [], []]
    cost = 0

    for s, d in enumerate(pattern):
      if d != -1:
        uses[d].append(sizes[s])

    cost = sum((len(u) - 1) for u in uses) * 10
    uses = [sum(u) for u in uses]
    cost += sum(abs(u - r) for u, r in zip(uses, reqs))

    if cost < minimum:
      minimum = cost

  print(minimum, flush=True)


if __name__ == '__main__':
  main()



Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int w = sc.nextInt();
		int h = sc.nextInt();
		int n = sc.nextInt();
		
		int l = 0;
		int r = w;
		int d = 0;
		int u = h;
		
		for (int i = 0; i < n; i++) {
			int x = sc.nextInt();
			int y = sc.nextInt();
			int a = sc.nextInt();
			
			switch (a) {
			case 1:
				l = Math.max(l, x);
				break;
			case 2:
				r = Math.min(r, x);
				break;
			case 3:
				d = Math.max(d, y);
				break;
			case 4:
				u = Math.min(u, y);
				break;
			default:
				break;
			}
		}
		
		int area = Math.max(r - l, 0) * Math.max(u - d, 0);
		System.out.println(area);
		
		sc.close();
	}
}




Measured memory_bytes: 27632
n=int(input())
a=[int(i) for i in input().split()]
arr=[0]*(n)
fin=sum(a)
for i in range(len(a)):
    arr[i] = a[i]*2
sub = 0
for i in range(n-2,-1,-2):
    sub+=arr[i]
final=[]
final.append(fin-sub)
for i in range(n-1):
    final.append(arr[i]-final[-1])
print(*final)


Measured memory_bytes: 17736
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

int main(){


    int a,b;
    cin >> a >> b;
    cout << (a-1)*(b-1) << endl;
    return 0;
}

Measured memory_bytes: 256