akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <unordered_map>
#include <list>
#include <numeric>
#include <utility>
#include <iterator>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <ctime>
#include <cassert>

#define INF 1000000000
#define LINF 9000000000000000000
#define mod 1000000007

#define rep(i,n) for(int i=0;i<int(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back
#define mp make_pair

using namespace std;

/*
cin.tie(0);
ios::sync_with_stdio(false);
*/

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int ddx[8]={-1,-1,0,1,1,1,0,-1};
int ddy[8]={0,1,1,1,0,-1,-1,-1};
bool debug=false;

/*---------------------------------------------------*/

int mkan[200005];

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n,ans=INF;
  cin>>n;
  vector<int> p(n),hoge(n+1);
  rep(i,n){
    cin>>p[i];
    hoge[p[i]]=i;
  }
  for(int i=0;i<n;i++){
    if(i<hoge[p[i]+1]){
      mkan[p[i]]=1;
    }
  }
  for(int i=200004;i>=0;i--){
    if(mkan[i]!=0)mkan[i]+=mkan[i+1];
  }
  for(int i=1;i<=n;i++){
    //cout<<"debug "<<i<<": "<<mkan[i]<<endl;
    ans=min(ans,max(n-(mkan[i]+1),0));
  }
  cout<<ans<<endl;
  return 0;
}


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

using namespace std;

using ll = long long;

int main(){
    ll n, m;
    cin >> n >> m;
    ll ans = 0;
    for(ll i = 0; i < m; ++i){
        ll tmp; cin >> tmp;
        ans += tmp;
    }
    if(n - ans < 0)cout << -1;
    else cout << n - ans;
    return 0;
}


Measured memory_bytes: 3588
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;

const double kInf = 1e10;
const double kEps = 1e-8;
const double kPi = 2 * acos(0);
const int kItr = 100;

int N, B;
double D, P[10], H[10];

void read();
void solve();

bool is_ok(double, double);

inline bool flt(double a, double b) { return a + kEps < b; }

int main() {
  cout.setf(ios::fixed), cout.precision(5);
  read();
  solve();
  return 0;
}

void read() {
  cin >> D >> N >> B, ++B;
  for (int i = 0; i < N; ++i)
    cin >> P[i] >> H[i];
}

void solve() {
  double res = kInf;

  for (int i = 1; i <= B; ++i) {
    double low, up, mid;

    low = kPi / 4, up = kPi / 2;
    for (int itr = 0; itr < kItr; ++itr) {
      mid = (low + up) / 2;
      if (is_ok(mid, D / i))
        up = mid;
      else
        low = mid;
    }

    res = min(res, sqrt((D / i) / sin(2 * low)));
  }

  cout << res << "\n";
}

bool is_ok(double tht, double l) {
  double v = sqrt(l / sin(2 * tht)), vx = v * cos(tht), vy = v * sin(tht), x, y;

  for (int i = 0; i < N; ++i) {
    x = fmod(P[i], l);
    y = vy * x / vx - x * x / (2 * vx * vx);
    if (flt(y, H[i]))
      return false;
  }

  return true;
}

Measured memory_bytes: 1352
cooking_times = [int(input()) for i in range(5)]
fractional_times = []
result = 0

for time in cooking_times:
    if time % 10 == 0:
        result += time
    else:
        result += time - time % 10
        fractional_times.append(time % 10)

if fractional_times != []:
    result += (len(fractional_times) - 1) * 10
    result += min(fractional_times)

print(result)

Measured memory_bytes: 3316
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto& (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<" "<<p.se<<endl
#define sar(a,n) cout<<#a<<":";rep(pachico,n)cout<<" "<<a[pachico];cout<<endl
#define svec(v) cout<<#v<<":";rep(pachico,v.size())cout<<" "<<v[pachico];cout<<endl
#define svecp(v) cout<<#v<<":";each(pachico,v)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl
#define sset(s) cout<<#s<<":";each(pachico,s)cout<<" "<<pachico;cout<<endl
#define smap(m) cout<<#m<<":";each(pachico,m)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int> P;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<P> vp;
typedef vector<string> vs;

const int MAX_N = 100005;

class KMP
{
public:
    vector<int> table, res;
    string pattern;
    int plen;
    KMP(const string s){
        pattern = s;
        plen = (int)pattern.size();
        table.resize(plen+1);
        table[0] = -1;
        int j = -1;
        rep(i,plen){
            while(j >= 0 && pattern[i] != pattern[j]){
                j = table[j];
            }
            table[i+1] = ++j;
        }
    }
    void search(const string& text){
        int head = 0, j = 0, tlen = (int)text.size();
        while(head + j < tlen){
            if(pattern[j] == text[head + j]) {
                if(++j == plen){
                    res.push_back(head);
                    head = head + j - table[j];
                    j = table[j];
                }
            }else{
                head = head + j - table[j];
                if(j){
                    j = table[j];
                }
            }
        }
    }
};

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int n = len(s);
    KMP x(s);
    reverse(all(s));
    KMP y(s);
    vi tx = x.table,ty = y.table;
    srep(i,1,n+1){
        tx[i-1] = i-tx[i];
        ty[i-1] = i-ty[i];
    }
    if(tx[n-1] == n || n%tx[n-1] != 0){
        cout << "1\n";
        cout << "1\n";
    }else if(tx[n-1] == 1){
        cout << n << "\n";
        cout << "1\n";
    }else{
        cout << "2\n";
        int ans = 0;
        rep(i,n-1){
            if(tx[i] == i+1 || (i+1)%tx[i] != 0){
                if(ty[n-2-i] == n-1-i || (n-1-i)%ty[n-2-i] != 0){
                    ans++;
                }
            }
        }
        cout << ans << "\n";
    }
    return 0;
}

Measured memory_bytes: 9652
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define cool ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	#define int  long long int
	#define pb push_back
	#define fe first
    #define lb lower_bound 
    #define ub upper_bound
    #define pii pair<pair<int,int>,pair<int,int> >
	#define se second
	#define endl "\n"
	#define pi pair<int, int>
	#define vi vector<int> 
	#define vvi vector<vi>
    #define bs   binary_search
	#define rep(i,a,b) for(int i=a;i<b;i++)
	#define rep1(i,a,b) for(int i=a;i<=b;i++)	
    #define all(c) (c).begin(),(c).end()
    #define sz(x)       (int)x.size() 
	#define PI 3.14159265358979323846
    
	const int N =1e6;
    
     int mod= 1e9+7;
     
     int dx[4]={0,0,+1,-1};
     int dy[4]={+1,-1,0,0};
   
    void solve(){
         int n,k;
         cin>>n>>k;
         string s;         
         cin>>s;
         int len=sz(s);
         char prev;
         int ct=0,ans=0;
         rep(i,0,len){
			  if(prev!=s[i]){
				  ct++;
				  prev=s[i];				  
			  }
			  
			  if(i<len-1 && s[i]=='L' && s[i+1]=='L')ans++;
			  if(i<len-1 && s[i]=='R' &&  s[i+1]=='R') ans++;		  
		 }
		 
		 int yo=(ct-1)/2;
		 
		 if(k>yo)
		   ans=len-1;
		 else
		    ans+=k*2;
		cout<<ans<<endl; 
		        
      
     }
   
   
   
   
      int32_t main() {
	    cool;
	    int t=1;
        //cin>>t;
	    while(t--)
	       solve();
	       
	       
	       return 0;	   
	   }


Measured memory_bytes: 512
h1,m1,h2,m2,k = list(map(int,input().split()))

if k <= m2:
    m2 -= k
else:
    h2 -= 1
    m2 += 60 - k

if m1 <= m2:
    ans = (h2-h1)*60 + m2-m1
else:
    ans = (h2-h1-1)*60 + m2-m1 + 60

print(ans)

Measured memory_bytes: 9180
#include <stdio.h>

int main(void) {
	int count[4][3][10]={};
	int n; //n件のデータ
	int b,f,r,v; //b棟f階r番目の部屋にv人
	int i,x,y,z;//カウント変数
	
	scanf("%d",&n);
	for(i=0;i<n;i++){
	scanf("%d %d %d %d",&b,&f,&r,&v);
	count[b-1][f-1][r-1]=v+count[b-1][f-1][r-1];
	}
	for(x=0;x<4;x++){
		for(y=0;y<3;y++){
			for(z=0;z<10;z++){
				printf(" %d",count[x][y][z]);
			}
			printf("\n");
		}
		if(x<3)
		printf("####################\n");
	}
	
	
	
	
	return 0;
}



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

using namespace std;

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define MOD 1000000007
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)

signed main(){

	lli a,b,c;
	cin>>a>>b>>c;

	swap(a,b);
	swap(a,c);

	cout<<a<<" "<<b<<" "<<c<<endl;
	return 0;
}

Measured memory_bytes: 764
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		while (true) {
			int H = in.nextInt(), W = in.nextInt();
			if (H == 0)
				break;

			int dp[][] = new int[H][W];
			for (int i = 0; i < H; i++) {
				String str = in.next();
				for (int j = 0; j < W; j++) {
					dp[i][j] = str.charAt(j) == '.' ? 1 : 0;
				}
			}

			for (int i = 0; i < H; i++) {
				for (int j = 0; j < W; j++) {
					if (i - 1 >= 0 && dp[i][j] > 0 && dp[i - 1][j] > 0)
						dp[i][j] = dp[i - 1][j] + dp[i][j];
				}
			}
			
			int max=0;
			for(int i=0;i<H;i++) {
				Stack<rect> stk=new Stack<>();
				for(int j=0;j<W;j++) {
					rect rct=new rect(dp[i][j],j);
					if(stk.isEmpty() || rct.h>stk.peek().h) {
						stk.push(rct);
					}
					else if(rct.h<stk.peek().h) {
						max=Math.max(max, cRect(stk,rct));
					}
				}
				max=Math.max(max, cRect(stk,new rect(0,W)));

			}
			
			System.out.println(max);
		}
	}
	
	static int cRect(Stack<rect> stk,rect rct) {
		int max=0,p=0;
		while(!stk.isEmpty()) {

			int h=stk.peek().h,i=stk.peek().i;
			if(h<rct.h)break;
			
			max=Math.max(max, h*(rct.i-i));
			p=i;
			stk.pop();
		}
		stk.push(new rect(rct.h,p));
		return max;
	}

}

class rect{
	int h,i;
	rect(int a,int b){
		h=a; i=b;
	}
}


Measured memory_bytes: 57664
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<unordered_map>
#include<unordered_set>
using namespace std;
typedef long long ll;
#define chmin(a,b) a=min(a,b)
#define chmax(a,b) a=max(a,b)
#define mod 1000000007
#define mad(a,b) a=(a+b)%mod;
#define mul(a,b) a=a*b%mod;
vector<ll> v[300010];
int main(){
  ll n,a,b;
  cin>>n>>a>>b;
  if(n-a>a*(b-1)||n-a<b-1){
      cout<<-1<<endl;
      return 0;
  }
  ll s=0;
  for(ll p=n-a;p>0;p--){
      if(v[s].size()==b-1)s++;
      v[s].push_back(p);
  }
  for(ll i=a-1;i>=0;i--){
      cout<<n-i<<endl;
      for(auto t:v[i])cout<<t<<endl;
  }
  return 0;
}


Measured memory_bytes: 11508
#include <bits/stdc++.h>
typedef long long int LL;
typedef unsigned long long int ULL;
using namespace std;

// 插入此處

LL a[200005];
LL suffix[200005];
int n;
int t;

LL mem[200005][3];
LL vis[200005][3];

LL dp(int x, int miss) {
    if (x >= n) {
        return 0;
    } else if (n % 2 == 1 && miss == 2) {
        return suffix[x];
    } else if (n % 2 == 0 && miss == 1) {
        return suffix[x];
    } else if (vis[x][miss]) {
        return mem[x][miss];
    }
    LL ret = max(dp(x + 1, miss + 1), a[x] + dp(x + 2, miss));
    vis[x][miss] = true;
    mem[x][miss] = ret;
    return ret;
}

int main() {
    scanf("%d", &n);
    LL t = n / 2;
    for (int i = 0; i < n; i++) {
        scanf("%lld", &a[i]);
    }
    suffix[n + 1] = 0;
    for (int i = n - 1; i >= 0; i -= 2) {
        suffix[i] = suffix[i + 2] + a[i];
    }
    printf("%lld\n", dp(0, 0));
}


Measured memory_bytes: 21000
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <unordered_map>
#include <vector>
#include <string.h>
#include <set>

using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> void printvec(const vector<T>& v) {
  for (auto x : v) { cout << x << " "; }
  cout << endl;
}
template<class T> void printtree(const vector< vector<T> >& tree) {
  for (long long i = 0; i < tree.size(); ++i) {
    cout << i + 1 << ": "; printvec(tree[i]);
  }
}
template<class T, class U> void printmap(const map<T, U>& mp) {
  for (auto x : mp) { cout << x.first << "=>" << x.second << endl; }
}

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

#define rep(i, n) for(ll i = 0; i < n; ++i)
#define all(s) s.begin(), s.end()
#define sz(x) (ll)(x).size()
#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> triple;
typedef double D;
typedef vector<ll> vl;
typedef vector<P> vp;

const ll INF = 1e9;
const ll MOD = 1000000007;  // 1e9 + 7

int main(int argc, char** argv) {
  cin.tie(NULL);
  cout.tie(NULL);
  ios_base::sync_with_stdio(false);
  //cout << setprecision(10) << fixed;

  ll n;
  cin >> n;
  // dp[i][j] .. max value when [0, i) and select j at i.
  vector<vector<ll>> dp(n+1, vector<ll>(3));

  rep(i, n) {
    vector<ll> d(3); // happiness
    cin >> d[0] >> d[1] >> d[2];

    rep(j, 3) rep(k, 3) {
      if (j == k) { continue; } // select k != j
      chmax(dp[i+1][j], dp[i][k] + d[j]);
    }
  }

  ll ans = 0;
  rep(i, 3) {
    chmax(ans, dp[n][i]);
  }
  cout << ans << endl;
}


Measured memory_bytes: 5760
import sys
input = sys.stdin.readline

def Find(x, par):
  if par[x] < 0:
    return x
  else:
    # 経路圧縮
    par[x] = Find(par[x], par)
    return par[x]

def Unite(x, y, par, rank):
  x = Find(x, par)
  y = Find(y, par)

  if x != y:
    # rankの低い方を高い方につなげる
    if rank[x] < rank[y]:
      par[y] += par[x]
      par[x] = y
    else:
      par[x] += par[y]
      par[y] = x
      if rank[x] == rank[y]:
        rank[x] += 1

def Same(x, y, par):
  return Find(x, par) == Find(y, par)

def Size(x, par):
  return -par[Find(x, par)]

n, m = map(int, input().split())
P = list(map(int, input().split()))
P = [p-1 for p in P]

par = [-1]* n
rank = [0]*n

for i in range(m):
    x, y = map(int, input().split())
    x, y = x-1, y-1
    Unite(x, y, par, rank)

ans = 0
for i in range(n):
    if P[i] == i:
        ans += 1
    else:
        if Same(i, P[i], par):
            ans += 1
print(ans)

Measured memory_bytes: 86544
import java.util.*;
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();

    if (a >= b) {
    	for (int i = 0; i < a; i++) {
		    System.out.print(""+b);    	
    	}
    } else {
    	for (int i = 0; i < b; i++) {
		    System.out.print(""+a);    	
    	}
    }
  }
}



Measured memory_bytes: 22484
#include<stdio.h>

int main(){
  int n,m;
  int i,j;

  scanf("%d",&n);
  scanf("%d",&m);
  while((n!=0)&&(m!=0)){
    int a[m],b[m];
    int fc[n+1];
    int f[n+1];
    int cnt;

    for(i=0;i<m;i++){
      scanf("%d %d",&a[i],&b[i]);
    }
    for(i=0;i<n+1;i++){
      fc[i]=0;
      f[i]=0;
    }

    j=0;

    for(i=0;i<m;i++){
      if(a[i]==1){
	fc[b[i]]=1;
	f[j]=b[i];
	j++;
      }
    }

    for(i=0;i<j;i++){
      int k;
      for(k=0;k<m;k++){
	if(a[k]==f[i]){
	  fc[b[k]]=1;
	}
	if((b[k]==f[i])&&(a[k]!=1)){
	  fc[a[k]]=1;
	}
      }
    }

    cnt=0;
    for(i=0;i<n+1;i++){
      if(fc[i]==1){
	cnt++;
      }
    }

    printf("%d\n",cnt);

    scanf("%d",&n);
    scanf("%d",&m);
  }

  return 0;
}

Measured memory_bytes: 684
#pragma GCC optimize "-O3"
#pragma GCC target ("avx")
#define _USE_MATH_DEFINES
#include<numeric>
#include<bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define inf (1ll<<60)
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v),greater<int>())
#define SPEED ios::sync_with_stdio(false);cin.tie(0);cout<<fixed<<setprecision(12)
signed gcd(int a, int b){return b?gcd(b,a%b):a;}
signed lcm(int a, int b){return a*b/gcd(a,b);}
//priority_queue<int, vi, greater<int> > que;//æ˜‡é †

using namespace std;

const int mod=1e9+7;

signed main(){
  SPEED;
  int a;
  while(scanf("%d",&a)!=EOF){
    printf("3C%02d\n",(a-1)%39+1);
  }
  return 0;
}



Measured memory_bytes: 3208
#include<iostream>
#include<vector>
#include<string>
#include <algorithm>
#include <queue>
#include <climits>
#include<cmath>
#include <sstream>
#include <iomanip>
#include <bits/stdc++.h>
int main()
{
    int64_t a,b,d,e;
    std::cin>> a;
    b = 10000000000000;

    for( int i = 1; i <= sqrt( a ); i++ )
    {
        if( a % i == 0 )
        {
            d = a / i;

            if( ( d + i ) < b )
            {
                b = d + i;
            }
        }
    }

    b -= 2;
    std::cout<< b <<"\n";
    
}




Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS

#pragma GCC optimize("O3")

#include <iostream>
#include <algorithm>
#include <vector>
#include <cassert>
#include <cstring>
#include <numeric>
#include <set>
#include <queue>
#include <deque>
#include <array>
#include <string>
#include <cmath>
#include <random>
#include <ctime>
#include <map>
#include <functional>
#include <bitset>
#include <complex>
#include <iomanip>
#include <unordered_map>
#include <unordered_set>

#define sz(a) (int)((a).size())
#define all(a) (a).begin(), (a).end()
#define pb push_back

using namespace std;
using ll = long long;
using vi = vector<int>;
using pii = pair<int, int>;
using ld = long double;

int main() {
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int n;
	cin >> n;
	vi a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	vector<vector<ll>> dp(n, vector<ll>(n));
	for (int i = 0; i < n; i++) {
		dp[i][i] = ((n - 1) % 2 == 0 ? a[i] : -a[i]);
	}
	for (int i = n - 1; i >= 0; i--) {
		for (int j = i + 1; j < n; j++) {
			if ((j - i) % 2 != (n - 1) % 2) {
				dp[i][j] = min(-a[i] + dp[i + 1][j], -a[j] + dp[i][j - 1]);
			}
			else {
				dp[i][j] = max(a[i] + dp[i + 1][j], a[j] + dp[i][j - 1]);
			}
		}
	}
	cout << dp[0][n - 1];
}


Measured memory_bytes: 70784
object Main extends App {

  import scala.io.StdIn._

  val Array(n, q) = readLine.trim.split(' ').map(_.toInt)
  var nums= readLine.trim.split(' ').map(_.toInt).map{value ⇒ new BiList(value, None, None)}.let{a ⇒
    for (i ← 1 until a.length){
      a(i - 1).next = Some(a(i))
      a(i).prev = Some(a(i - 1))
    }
    a
  }
  val holder = new ListHolder(nums.head, nums.last)
  nums = nums.sortBy(_.value)
  val queries = readLine.trim.split(' ').map(_.toInt - 1)
  for (query <- queries){
    holder.swapAt(nums(query))
  }
  println(
    holder.toList.map(_.toString).mkString(" ")
  )
  class ListHolder(var first: BiList, var last: BiList) {
    def swapAt(q: BiList): Unit = {
      (q.prev, q.next) match {
        case (Some(leftLast), Some(rightFirst)) ⇒
          q.next = Some(first)
          first.prev = Some(q)
          q.prev = Some(last)
          last.next = Some(q)
          first = rightFirst
          last = leftLast
          first.prev = None
          last.next = None
        case (None, Some(rightFirst)) ⇒
          q.prev = Some(last)
          last.next = Some(q)
          first = rightFirst
          last = q
          first.prev = None
          last.next = None
        case (Some(leftLast), None) ⇒
          q.next = Some(first)
          first.prev = Some(q)
          first = q
          last = leftLast
          first.prev = None
          last.next = None
        case (None, None) ⇒
      }

    }
    def toList: List[Int] = {
      var l = last
      var res: List[Int] = l.value::Nil
      while (first != l){
        l = l.prev.get
        res ::= l.value
      }
      res
    }
  }
  class BiList(val value: Int, var prev: Option[BiList], var next: Option[BiList]) {
    override def toString: String = s"BiList($value, ${prev.map(_.value)}, ${next.map(_.value)})"
  }

  implicit class Extenion[T](val value :T){
    def also(func: T ⇒ Unit): T = {
      func(value)
      value
    }
    def let[R](func: T ⇒ R): R = func(value)
  }
}


Measured memory_bytes: 154540
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T>& V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> >& Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T>& mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }
template<typename T>vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>auto make_v(size_t a,Ts... ts){return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type fill_v(T &t,const V &v){t=v;}
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type fill_v(T &t,const V &v){for(auto &e:t) fill_v(e,v);}
/*
 <url:>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

template<class Type>
Type solve(Type res = Type()){
    vector<int> ok(3);
    ll A,B; cin >> A >> B;
    A--; B--;
    ok[A] = ok[B] = true;
    for(int i = 0; i < 3;i++){
        if(ok[i] == false) res = i+1;
    }
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    // solve(0);
    cout << fixed << setprecision(15) << solve<ll>() << endl;
    return 0;
}


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

using namespace std;

int main(){

        int height,width;

        while(true){
                cin >> height >> width;
                if(height == 0 && width == 0)break;

                for(int i = 0; i < height; i++){
                        for(int j = 0; j < width; j++){
                                cout << "#";
                        }
                        cout << "\n";
                }
                cout << "\n";
        }

        return 0;
}

Measured memory_bytes: 1120
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <bitset>
#include <climits>
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define RFOR(i,a,b) for (int i=(a)-1;i>=(b);i--)
#define ll long long
#define ull unsigned long long
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const int INF = 1e9;
const ll LL_INF = 1e18;
const int MOD = 1e9 + 7;

using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  int a[100005];
  int maxa = 0, maxi;
  REP(i,n){
    cin >> a[i];
    if(a[i] > maxa){
      maxa = a[i];
      maxi = i;
    }
  }
  double diff = INF;
  int pairi;
  REP(i,n){
    if(i == maxi) continue;
    if(abs(maxa / 2.0 - a[i]) < diff){
      diff = abs(maxa / 2.0 - a[i]);
      pairi = i;
    }
  }
  cout << a[maxi] << ' ' << a[pairi] << endl;
  return 0;
}


Measured memory_bytes: 1272
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
const int maxn=0x7fffff;
int n,k,i;
int a[10001];
bool cmp(int x,int y){
	return x>y;
}
int main(){
	cin>>n>>k;
	for(i=1;i<=n;i++){
		cin>>a[i];
	}
	sort(a+1,a+n+1,cmp);
	int sum=0;
	for(i=1;i<=k;i++){
		sum+=a[i];
	}
	cout<<sum;
	return 0;
}


Measured memory_bytes: 256
// C - Linear Approximation
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main(){
	int N; cin>>N;
	vector<ll> B(N);
	for(int i=0; i<N; ++i){ cin>>B[i]; B[i] -= i+1; }
	sort(B.begin(), B.end());
	ll l = accumulate(B.begin()+N/2+(N%2), B.end(), 0LL);
	ll r = accumulate(B.begin(), B.begin()+N/2, 0LL);
	cout<< l-r <<endl;
}


Measured memory_bytes: 1792
package main

import (
	"fmt"
	"math"
)

func main() {

	var A, B, H, M int
	fmt.Scanf("%d %d %d %d", &A, &B, &H, &M)

	var angle float64
	var result float64
	angle = math.Abs((30*float64(H)+0.5*float64(M))-6*float64(M)) * math.Pi / 180

	result = math.Sqrt(float64(A)*float64(A) +
		float64(B)*float64(B) -
		2*float64(A)*float64(B)*math.Cos(angle))

	fmt.Println(result)
}


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

int main() {
    int a, b, c;
    cin >> a >> b >> c;

    cout << min(c, b / a) << endl;
    return 0;
}


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

#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))

typedef long long LL;

int main(){
  LL x;
  cin >> x;
  cout << x/11*2+(x%11==0?0:(x%11>6?2:1)) << endl;
  return 0;
}


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

vector<int64_t> primes={2,3,5,7};
int primes_extend(int calc_from, int calc_to);
int factoring(int64_t n, map<int64_t,int> &factors);

int main()
{

	int64_t n;
	cin >> n;

	if (n==1)
	{
		cout << 0 << endl;
		return 0;
	}

	primes_extend(10,100);
	primes_extend(100,10000);
	primes_extend(10000,1000100);
	
	map<int64_t,int> factors;
	factoring(n,factors);
	for (pair<int64_t,int> p:factors)
	{
	 	//fprintf(stderr,"%ld: %d\n",p.first,p.second);
	}

	map<int64_t,int> nn;
	for (int64_t i=1;i<=100;++i)
	{
		nn[i*(i+1)/2]=i;
	}

	int count=0;
	for (pair<int64_t,int> p:factors)
	{
		auto it=nn.upper_bound(p.second);
		--it;
		count+=it->second;
	}
	cout << count << endl;

}



int primes_extend(int calc_from, int calc_to)
{

	for (int i=calc_from;i<=calc_to;++i)
	{
		int j;
		int loop_max=sqrt(i);
		for (j=0;(primes[j]<=loop_max)&&(j<primes.size());++j)
		{
			if ((i%primes[j])==0)
			{
				// not prime...
				break;
			}
		}
		if ((j>=primes.size())||(primes[j]>loop_max))
		{
			primes.push_back(i);
		}
	}
	//fprintf(stderr,"count: %d\n",primes.size());
	return 0;
}

int factoring(int64_t n, map<int64_t,int> &factors)
{
	int64_t maxfactor=sqrt(n);
	for (int i=0;(n>1)&&(primes[i]<=maxfactor);++i)
	{
		while ((n%primes[i])==0)
		{
			n/=primes[i];
			factors[primes[i]]++;
		}
	}
	if (n!=1)
	{
		factors[n]++;
	}

	return 0;
}




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

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
template<typename T> void view(T cont) {std::cout << cont << std::endl;}
template<typename T> void view(T* cont, ll sz) {rep(i, sz) std::cout << cont[i] << " "; std::cout << std::endl;}
template<typename T> void view(const std::vector<T>& v) {for (const auto& f: v) std::cout << f << " "; std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv) { for (const auto& v: vv) {view(v);}}
const long long INF = 1LL<<60;
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;
}

const int MAX_N = 110000;
const int INF_val = 1e+9;
vector<int> dp(MAX_N, 0);
vector<int> memo(MAX_N, -1);

int rec(int n) {
    if (n == 0) return 0;
    if (memo[n] != -1) return memo[n];

    int res = INF_val;
    for (int i = 1; i <= n; i *= 6) {
        res = min(res, rec(n - i) + 1);
    }
    for (int j = 1; j <= n; j*= 9) {
        res = min(res, rec(n - j) + 1);
    }
    return memo[n] = res;
}

int main(){
    int N; cin >> N;
    cout << rec(N) << endl;
}

Measured memory_bytes: 5760
#include<bits/stdc++.h>
using namespace std;
#define ll long long
typedef pair<ll,ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define M 1000000007
#define all(a) (a).begin(),(a).end()
#define rep(i,n) reps(i,0,n)
#define reps(i,m,n) for(int i=(m);i<(n);i++)
vector<vector<int>> g;
vector<int> dp;
int rec(int v){
  if(dp[v]!=-1) return dp[v];
  int rtn=0;
  for(auto au:g[v]){
    chmax(rtn,rec(au)+1);
  }
  return dp[v]=rtn;
}
int main(){
  int n,k;cin>>n>>k;
  g.assign(n,vector<int>());
  dp.assign(n,-1);
  rep(i,k){
    int a,b;cin>>a>>b;a--,b--;
    g[a].push_back(b);
  }
  int res=0;
  rep(i,n){
    chmax(res,rec(i));
  }
  cout<<res;
}

Measured memory_bytes: 8192
#include <bits/stdc++.h>
using namespace std;
vector<int> S[2];

bool package_solve(vector<int> &S, int x) {
  vector<int> A[2];
  int cur = 1, pre = 0;
  A[pre].push_back(0);
  for (int s: S) {
    A[cur].clear();
    for (int v: A[pre]) A[cur].push_back(v + s), A[cur].push_back(v - s);
    sort(A[cur].begin(), A[cur].end());
    A[cur].erase(unique(A[cur].begin(), A[cur].end()), A[cur].end());
    swap(cur, pre);
  }
  return count(A[pre].begin(), A[pre].end(), x);
}
  
char s[10000];

int main() {
  int x, y;
  scanf("%s", s);
  int l = strlen(s);
  scanf("%d%d", &x, &y);
  
  int cur = 0, step = 0, i = 0;
  for (i = find(s, s + l,'T') - s, x -= i ; i < l; ++i) {
    if (s[i] == 'T') S[cur].push_back(step), step = 0, cur ^= 1;
    else ++step;
  }
  S[cur].push_back(step);
  puts(package_solve(S[0], x) and package_solve(S[1], y)?"Yes":"No");
  
}

Measured memory_bytes: 384
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;

int main()
{
	int a, b, s;
	int m;
	scanf("%d%d", &a, &b);
	if(b <= 9) s = a*10 + b;
	if(b <= 99 && b >= 10) s = a * 100 + b;
	if(b >= 100) s = a * 1000 + b;
	m = sqrt(s);
	if(m * m == s) printf("Yes\n");
	else printf("No\n");
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <climits>

int main()
{
  int n, time_limit;
  std::cin >> n >> time_limit;
  int result = INT_MAX;
  for (int i = 0; i < n; i++) {
    int cost, time;
    std::cin >> cost >> time;
    if (time <= time_limit) {
      result = std::min(result, cost);
    }
  }
  if (result == INT_MAX) {
    std::cout << "TLE\n";
  } else {
    std::cout << result << '\n';
  }
  return 0;
}


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

int main() {
  long N, K;
  cin >> N >> K;
  vector<long> A(N);
  for (int i = 0; i < N; i++) cin >> A.at(i);
  sort(A.begin(), A.end());
  long L = -2e18, R = 2e18;
  while (R - L > 1) {
    long M = (L + R) / 2, sum = 0;
    for (int i = 0; i < N; i++) {
      if (A.at(i) < 0) sum += N - (upper_bound(A.begin(), A.end(), (long double)M / A.at(i)) - A.begin());
      if (A.at(i) > 0) sum += lower_bound(A.begin(), A.end(), (long double)M / A.at(i)) - A.begin();
      if (A.at(i) == 0) sum += (M > 0) ? N : 0;
      if (A.at(i) * A.at(i) < M) sum--;
    }
    (sum / 2 < K) ? L = M : R = M;
  }
  cout << L << "\n";
}


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

namespace atcorder2
{
    class Program
    {
        public static long Read()
        {
            return long.Parse(ReadLine());
        }

        public static long[] Reads()
        {
            return ReadLine().Split().Select(long.Parse).ToArray();
        }


        public static long gcd(long x,long y)
        {
            if (y < x) gcd(y, x);
            while (y != 0)
            {
                var z = x % y;
                x = y;
                y = z;
            }
            return x;
        }

        public static long C(long n,long k)
        {
            long x=1;
            for (long i = 1; i <=k; i++)
            {
                x *= n - i + 1;
                x /= i;
            }
            return x;
        }
        static void Main(string[] args)
        {
            var sw = new StreamWriter(OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            var n = Read();
         
            var d = new Dictionary<string, long>();
            for (int i = 0; i < n; i++)
            {
                var c = ReadLine().ToArray();
                Array.Sort(c);
                var s = new string(c);
                if (d.ContainsKey(s)) d[s]++;
                else d.Add(s, 1);
            }
            long ans = 0;
            foreach (var item in d)
            {
                ans += item.Value * (item.Value - 1) / 2;
            }

            WriteLine(ans);


            Console.Out.Flush();
        }
    }
}


Measured memory_bytes: 34008
#include <iostream>
#include <iomanip>
#include <math.h>
typedef long double ld;
using namespace std;
int main(){
  int n; ld ans=0.00;cin>>n;int x[n],y[n];
  for(int i=0;i<n;i++){
    cin >> x[i]>>y[i];
  }
  for(int i=0;i<n;i++){
    for(int j=i;j<n;j++){
      ans=ans+sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]));
    }
  }
  cout <<setprecision(20)<< ans/n*2 <<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=200005,M=1e9+7;
int n,m,a,b,fac[N],inv[N],dp[N];
int ksm(int x,int y){
	if (!y)return 1;
	int z=ksm(x,y/2);
	z*=z;z%=M;
	if (y&1)z*=x;
	return z%M;
}
int C(int x,int y){
	if (x<y)return 0;
	return fac[x]*inv[y]%M*inv[x-y]%M;
}
signed main(){
	scanf("%lld%lld%lld%lld",&n,&m,&a,&b);
	n--;m--;
	fac[0]=inv[0]=1;
	for (int i=1;i<N;i++)fac[i]=fac[i-1]*i%M,inv[i]=ksm(fac[i],M-2);
	int sum=0;
	for (int i=b-1;i>=0;i--){
		dp[i]=(C(n+m-i-(n-a+1),n-(n-a+1))-sum+M)%M;
		(sum+=dp[i])%=M;
	}
	int ans=C(n+m,n);
	for (int i=0;i<b;i++)(ans+=M-C(i+(n-a+1),i)*dp[i]%M)%=M;
	printf("%lld\n",ans);
	return 0;
}

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

int main(){
  int n;
  string s;
  cin >> n >> s;
  int cnt =0;
  rep(i,s.size()-2){
    if(s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C')cnt++;
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 3620
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	wfp := os.Stdout
	cnt := 0

	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
		cnt = 1
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)
	solve(scanner, writer)
	for i := 0; i < cnt; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
	writer.Flush()
}

func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	n := getNextInt(scanner)
	k := getNextInt(scanner)
	aa := make([]int, n)
	mm := make([]int, n+1)
	for i := 0; i < n; i++ {
		aa[i] = getNextInt(scanner)
		if mm[i] > aa[i] {
			mm[i+1] = mm[i]
			continue
		}
		mm[i+1] = aa[i]
	}

	var ans, s int64
	ans = math.MaxInt64
	for b := 0; b < 1<<uint(n); b++ {
		sum := 0
		m := 0
		for i := 0; i < n; i++ {
			sum += b >> uint(i) & 1
		}
		if sum < k {
			continue
		}
		s = 0
		for i := 0; i < n; i++ {
			if b>>uint(i)&1 == 0 {
				continue
			}
			m = maxint(m, mm[i])
			if aa[i] < m+1 {
				s += int64(m + 1 - aa[i])
			}
			m = maxint(aa[i], m+1)
		}
		if ans > s {
			ans = s
		}
	}
	fmt.Fprintln(writer, ans)
}

func maxint(a, b int) int {
	if a < b {
		return b
	}
	return a
}


Measured memory_bytes: 640
n, a, b = list(map(lambda x: int(x), input().split()))
s = input()


num_a = 0
num_b = 0

rank_b = 0

for i in range(len(s)):
    if s[i] == 'c':
        print('No')

    elif s[i] == 'a':
        if num_a + num_b < a + b:
            print('Yes')
            num_a += 1
        else:
            print('No')

    elif s[i] == 'b':
        rank_b += 1

        if num_a + num_b < a + b and rank_b <= b:
            print('Yes')
            num_b += 1
        else:
            print('No')


Measured memory_bytes: 4116
open Printf
open Scanf

let id x = x

let (n, m, q) = scanf "%d %d %d" (fun n m q -> n, m, q)

let table = Array.init (n + 1) (fun i -> Array.init (n + 1) (fun j -> 0))

let () =
    for i = 1 to m do 
        let (l, r) = scanf " %d %d" (fun l r -> l, r) in
        for j = r to n do
            table.(l).(j) <- table.(l).(j) + 1
        done
    done

let _ = Array.init q (fun i ->
    let (q1, q2) = scanf " %d %d" (fun q1 q2 -> q1, q2) in
    let c = ref 0 in
    for i = q1 to q2 do
        c := !c + table.(i).(q2)
    done;
    printf "%d\n" !c)

Measured memory_bytes: 6144
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> VI;
 
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; }
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()


int main(){
  int n,q;cin>>n>>q;
  vector<tuple<int,int,int>> ev(n*2);
  rep(i,n){
    int s,t,x;scanf("%d %d %d",&s,&t,&x);
    ev[i]=make_tuple(s-x,1,x);
    ev[n+i]=make_tuple(t-x,-1,x);
  }
  set<int> xset;
  sort(all(ev));
  int now=0;
  rep(i,q){
    int d;scanf("%d",&d);
    while(now!=2*n){
      if((get<0>(ev[now]))>d)break;
      auto forset=ev[now];
      now++;
      if(get<1>(forset)==1){
        xset.insert(get<2>(forset));
      }
      else{
        xset.erase(*xset.find(get<2>(forset)));
      }
    }
    if(xset.empty())printf("%d\n",-1);
    else printf("%d\n",*xset.begin());
  }
}


Measured memory_bytes: 15360
import java.math.BigDecimal;
import java.util.Scanner;
public class Main
{
	public static void main(String[] args) 
	{
		Scanner in=new Scanner(System.in);
		while(in.hasNext())
		{
			double x1=in.nextDouble(),y1=in.nextDouble();
			double x2=in.nextDouble(),y2=in.nextDouble();
			double x3=in.nextDouble(),y3=in.nextDouble();
			double px=in.nextDouble(),py=in.nextDouble();
			
			double a=Math.sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
			double b=Math.sqrt((x2-x3)*(x2-x3)+(y2-y3)*(y2-y3));
			double c=Math.sqrt((x1-x3)*(x1-x3)+(y1-y3)*(y1-y3));
			
			double ap=Math.sqrt((x1-px)*(x1-px)+(y1-py)*(y1-py));
			double bp=Math.sqrt((x2-px)*(x2-px)+(y2-py)*(y2-py));
			double cp=Math.sqrt((x3-px)*(x3-px)+(y3-py)*(y3-py));
			
			double s=(a+b+c)/2;
			double S=Math.sqrt(s*(s-a)*(s-b)*(s-c));
			double as=(a+ap+bp)/2;
			double aS=Math.sqrt(as*(as-a)*(as-ap)*(as-bp));
			double bs=(b+bp+cp)/2;
			double bS=Math.sqrt(bs*(bs-b)*(bs-bp)*(bs-cp));
			double cs=(c+cp+ap)/2;
			double cS=Math.sqrt(cs*(cs-c)*(cs-cp)*(cs-ap));
			double pS=aS+bS+cS;
			
			BigDecimal bi1 = new BigDecimal(String.valueOf(S));
			BigDecimal bi2 = new BigDecimal(String.valueOf(pS));
			double k1= bi1.setScale(9, BigDecimal.ROUND_HALF_UP).doubleValue();
			double k2= bi2.setScale(9, BigDecimal.ROUND_HALF_UP).doubleValue();
			if(k1==k2)
				System.out.println("YES");
			else
				System.out.println("NO");
		}
	}
}

Measured memory_bytes: 13000
from collections import defaultdict
n,q=map(int,input().split())
Edges=defaultdict(list)
for _ in range(n-1):
    a,b=map(int,input().split())
    Edges[a-1].append(b-1)
Nodes = [0]*n
for _ in range(q):
    p,x=map(int,input().split())
    Nodes[p-1] += x

def dfs(Edges,Nodes,visited):
    stack = []
    visited = set()
    stack.append((0, 0))

    while len(stack)>0:
        current, preval = stack.pop()
        if current in visited:
            continue
        visited.add(current)
        Nodes[current] += preval
        preval = Nodes[current]
        for i in Edges[current]:
            stack.append((i, preval))
    return Nodes

visited = [False]*(len(Nodes))
Nodes = dfs(Edges,Nodes,visited)

print(" ".join(list(map(str,Nodes))))

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

int main() {
  int A,B,ans;
  cin>>A>>B;
  if(A>=13)
    ans=B ;
  else if(A>=6&&A<=12)
    ans=B/2 ;
  else if(A<=5)
    ans=0 ;
  cout<< ans  << endl ;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
double speed(double a);

double t_time = 0.0;
int N, t[100], v[100];
int main(void) {
	double distance = 0.0;
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> t[i];
		t_time += t[i];
	}
	for (int i = 0; i < N; i++) {
		cin >> v[i];
	}

	for (double i = 0.0; i < t_time; i += 0.5) {
		distance += 0.25 * (speed(i) + speed(i + 0.5));
	}
	printf("%lf", distance);

	return 0;
}
double speed(double x) {
	double f[102], t_t = 0, f_tmp;
	f[0] = x;
	f_tmp = f[0];
	f[1] = t_time - x;
	if (f_tmp > f[1])	f_tmp = f[1];
	for (int i = 0; i < N; i++) {
		t_t += t[i];
		if (t_t - t[i] >= x) {
			f[i + 2] = v[i] + (t_t - t[i] - x);
		}
		else if (t_t - t[i] < x && t_t >= x) {
			f[i + 2] = v[i];
		}
		else if (t_t < x) {
			f[i + 2] = v[i] + (x - t_t);
		}
		if (f_tmp > f[i + 2])	f_tmp = f[i + 2];
	}
	return f_tmp;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <ios>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>
#include <map>
using namespace std;
typedef long long ll;
#define mp make_pair;
#define pb push_back;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int H,W;
  cin >> H >> W;
  string s[H];
  
  rep(j, H){
    cin >> s[j];
  }
  int ans = 0;
  int yoko[H][W];
  int tate[H][W];

  rep(j, H){
    rep(i, W){
      yoko[j][i] = -1;
      tate[j][i] = -1;
    }

  }

  rep(j, H){
    rep(i, W){
      if(s[j][i] == '#'){	
	continue;
      }
      if(yoko[j][i] == -1){
	int tmp_i = i+1;
	int tmp_yoko=1;
	while(tmp_i <W){
	  if(s[j][tmp_i] == '.'){
	    tmp_yoko++;
	    tmp_i++;
	  }
	  else{
	    break;
	  }
	}
	for(int k = i; k < tmp_i; k++){
	  yoko[j][k] = tmp_yoko;
	  //	  cout << tmp_yoko << endl;
	}
      }
    }
  }
  rep(i, W){
    rep(j, H){
      if(s[j][i] == '#'){
	continue;
      } 
      if(tate[j][i] == -1){
	int tmp_j = j+1;
	int tmp_tate=1;
        while(tmp_j <H){
          if(s[tmp_j][i] == '.'){
            tmp_tate++;
            tmp_j++;
          }
          else{
            break;
          }
        }
	for(int k = j; k < tmp_j; k++){
          tate[k][i] = tmp_tate;
	  //	  cout << tmp_tate << endl; 
	}
      }
    }
  }
  rep(j, H){
    rep(i, W){
      if(s[j][i] == '#'){
	continue;
      }
      else {
	ans = max(ans, tate[j][i] + yoko[j][i]-1) ;	
      }
    }
  }
  cout << ans << endl;
  return 0;
    

}


Measured memory_bytes: 35840
use std::io::{stdin, Read};

macro_rules! parse {
    ($it: ident ) => {};
    ($it: ident, ) => {};
    ($it: ident, $var:ident : $t:tt $($r:tt)*) => {
        let $var = parse_val!($it, $t);
        parse!($it $($r)*);
    };
    ($it: ident, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = parse_val!($it, $t);
        parse!($it $($r)*);
    };
}

macro_rules! parse_val {
    ($it: ident, [$t:tt; $len:expr]) => {
        (0..$len).map(|_| parse_val!($it, $t)).collect::<Vec<_>>();
    };
    ($it: ident, ($($t: ty),*)) => {
        ($(parse_val!($it, $t)),*)
    };
    ($it: ident, $t: ty) => {
        $it.next().unwrap().parse::<$t>().unwrap()
    };
}

fn solve(s: &str) {
    let mut it = s.split_whitespace();
    parse!(it, mut a: usize, b: usize, mut c: usize, d: usize);
    loop {
        if c <= b {
            println!("Yes");
            return;
        }
        c -= b;
        if a <= d {
            println!("No");
            return;
        }
        a -= d;
    }
}

fn main() {
    let mut s = String::new();
    stdin().read_to_string(&mut s).unwrap();
    solve(&s);
}

#[cfg(test)]
mod tests {
    use super::*;
    #[test]
    fn test_input() {
        let s = "
        ";
        solve(s);
    }
}


Measured memory_bytes: 2080