akhauriyash/Code-Regression huggingface dataset:
use std::io::Write;

fn read() -> String {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().chars().collect()
}

fn query(b: &[usize]) -> bool {
    for i in 1..b.len() {
        for j in 0..i {
            assert!(b[i] != b[j]);
        }
    }
    let mut out = String::new();
    out.push('?');
    for b in b.iter() {
        out.push_str(&format!(" {}", *b));
    }
    println!("{}", out);
    std::io::stdout().flush().ok();
    let s = read();
    match s.chars().next().unwrap() {
        'R' => true,
        'B' => false,
        _ => unreachable!(),
    }
}

fn run() {
    let n: usize = read().parse().unwrap();
    let mut a: Vec<usize> = (1..(2 * n + 1)).collect();
    for i in 0..n {
        let v = a[i];
        a.push(v);
    }
    let mut ans = vec!['\n'; 2 * n + 1];
    let left = query(&a[..n]);
    let mut l = 0;
    let mut r = n;
    while r - l > 1 {
        let m = (l + r) / 2;
        if left == query(&a[m..(m + n)]) {
            l = m;
        } else {
            r = m;
        }
    }
    let r = l + n;
    let l = l + 1;
    for i in 0..(2 * n) {
        if l <= i && i < r {
            continue;
        }
        let mut b = vec![];
        b.extend_from_slice(&a[l..r]);
        b.push(a[i]);
        if query(&b) {
            ans[i] = 'R';
        } else {
            ans[i] = 'B';
        }
    }
    let mut b = vec![];
    let mut red = 0;
    let mut blue = 0;
    for i in 0..(2 * n) {
        if red < n / 2 && ans[i] == 'R' {
            b.push(a[i]);
            red += 1;
        } else if blue < n / 2 && ans[i] == 'B' {
            b.push(a[i]);
            blue += 1;
        }
    }
    let b = b;
    for i in 0..(2 * n) {
        if ans[i] == '\n' {
            let mut c = b.clone();
            c.push(a[i]);
            ans[i] = if query(&c) {'R'} else {'B'};
        }
    }
    let mut out = String::new();
    out.push_str("! ");
    for &c in ans.iter() {
        out.push(c);
    }
    println!("{}", out);
}

fn main() {
    run();
}


Measured memory_bytes: 4816
#include <bits/stdc++.h>
#define ll long long
#define inf 100000000000000000
#define mod 1000000007
#define endl '\n'
#define omarshagar                    \
	ios_base::sync_with_stdio(false); \
	cin.tie(NULL);                    \
	cout.tie(NULL);
using namespace std;

ll faspow(ll base ,ll pow)
{
    if(pow==0)return 1;
    ll mul=faspow(base,pow/2.0)%mod;
    mul*=mul;
    mul%=mod;
    if(pow%2==1)mul*=base;
    mul%=mod;
    return mul;
}
int main()
{
    omarshagar
    int n;
    cin>>n;
    ll arr1[n];
    ll arr2[n];
    ll arr3[n];
    for(int i=0;i<n;i++)
    {
        cin>>arr1[i];
    }
    for(int i=0;i<n;i++)
    {
        cin>>arr2[i];
    }
    for(int i=0;i<n;i++)
    {
        cin>>arr3[i];
    }
    sort(arr1,arr1+n);
    sort(arr2,arr2+n);
    sort(arr3,arr3+n);
    ll sum2[n+1]={};

    for(int i=0;i<n;i++)
    {
        // arr2[i]=87465;
        ll *loc=upper_bound(arr3,arr3+n,arr2[i]);
        sum2[i+1]= (arr3+n)-loc;
        //cout<<sum2[i+1]<<endl;
    }
    //cout<<0<<" ";
    for(int i=1;i<=n;i++)
    {
        sum2[i]=sum2[i]+sum2[i-1];
        //cout<<sum2[i]<<" ";
    }
    //cout<<endl;
    ll res=0;
    int nn=n+1;
    for(int i=0;i<n;i++)
    {
        ll mul=0;

        ll *locc=upper_bound(arr2,arr2+n,arr1[i]);
        ll loc2=n-((arr2+n)-locc);
        //cout<<loc2<<endl;
        if(loc2<n) {
            mul = (sum2[n] - sum2[loc2]);
            res += mul;
            
        }
    }
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define sz(x) int(x.size())
#define pb push_back
using ll=long long;
using P = pair<int,int>;
#define chmax(x,y) x = max(x,y)
const ll MOD=1000000007,MOD2=998244353,INF=1e18;



int main() {
    int N;
    cin>>N;
    vector<string> S(N);
    rep(i,N){cin>>S.at(i);}
    sort(S.begin(),S.end());
    int count=1;
    rep(i,N-1){
        if(S.at(i+1)!=S.at(i)){count++;}
    }
    cout<<count<<endl;
}


Measured memory_bytes: 9600
#include <stdio.h>
#include <vector>
#include <iostream>
#include <queue>
#include <bits/stdc++.h>

#define rep(i,n) for (int i=0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<ll> vl;


int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    int n;
    cin >> n;
    vi l(n);
    rep(i, n) cin >> l[i];
    
    sort(l.begin(), l.end(), greater<int>());
    
    ll ans = 0;
    for(int i=0;i<n-2;i++){
        for (int j=i+1;j<n-1;j++){
            for (int k=j+1;k<n;k++){
                if (l[i] < (l[j] + l[k])){
                    ans++;
                }else{
                    break;
                }
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using long_t = int64_t;

struct Solver {
	Solver() {
		ios::sync_with_stdio( false );
		cout << fixed << setprecision( 10 );
	}

	void solve() {
		int N, M;
		cin >> N >> M;

		int sum = 0;
		for( int i = 0; i < M; ++i ) {
			int a;
			cin >> a;
			sum += a;
		}

		cout << (sum <= N ? N-sum : -1) << endl;
	}
};

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


Measured memory_bytes: 3604
using namespace std;
#include <cstdio>
#include <cstring>
#include <algorithm>
int a,k;
int query(int a,int k,int x){
	int t=x/k;
	x-=t*k;
	a-=t*k;
	int d=a/k;
	if (((x-k)%(d+1)+(d+1))%(d+1)==d) return d;
	return query(d*k-1,k,((x-k)%(d+1)+(d+1))%(d+1));
}
int main(){
	int n,xo=0;
	scanf("%d",&n);
	for (int i=1;i<=n;++i){
		scanf("%d%d",&a,&k);
		int d=a/k;
		if (a<k)
			xo^=0;
		else if ((0-(a%k+1)%(d+1)+(d+1))%(d+1)==d)
			xo^=d;
		else
			xo^=query(d*k-1,k,((0-(a%k+1))%(d+1)+(d+1))%(d+1));
	}
	if (xo==0)
		printf("Aoki\n");
	else
		printf("Takahashi\n");
	return 0;
}





















Measured memory_bytes: 1644
H, W = gets.split.map(&:to_i)
board = H.times.map { gets.split.map(&:to_i) }

op_list = []
(H - 1).times do |i|
  y = i + 1
  W.times do |j|
    x = j + 1
    if board[i][j].odd?
      op_list.push([y, x, y + 1, x])
      board[i + 1][j] += 1
    end
  end
end
(W - 1).times do |j|
  i = H - 1
  y = H
  x = j + 1
  if board[i][j].odd?
    op_list.push([y, x, y, x + 1])
    board[i][j + 1] += 1
  end
end

puts op_list.size
puts op_list.map { |op| op.join(' ') }.join("\n")


Measured memory_bytes: 48252
N,W = map(int,input().split())
from collections import defaultdict
wvl = defaultdict(list)
for i in range(N):
    w,v = map(int,input().split())
    if i == 0:
        f_w = w
    wvl[w].append(v)

import itertools
for i in range(f_w, f_w+4):
    wvl[i] = [0] + list(itertools.accumulate(sorted(wvl[i], reverse=True)))

ans = 0
for i in range(101):
    if len(wvl[f_w])-1 < i:
        break
    for j in range(101-i):
        if len(wvl[f_w+1])-1 < j:
            break
        for k in range(101-i-j):
            if len(wvl[f_w+2])-1 < k:
                break
            rest = W - f_w * i - (f_w+1) * j - (f_w+2) * k
            l = min(rest // (f_w + 3), len(wvl[f_w+3])-1)
            if l < 0:
                break
            
            ans = max(ans, wvl[f_w][i] + wvl[f_w+1][j] + wvl[f_w+2][k] + wvl[f_w+3][l])
            
print(ans)            

Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
int n;
long long ans=0;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	    {
	    	int a;
	    	scanf("%d",&a);
	    	ans+=(long long)(a-1);
	    }
	printf("%lld",ans);    
	return 0;
}

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

using namespace std;
vector<long long> factors;
#define ll long long

#define pii pair<int,int>
#define pll pair<ll,ll>
#define _ <<'\n'
#define __ << ' '
#define all(x) (x).begin(), (x).end()
#define gcd __gcd
int IT_MAX = 1 << 17;
int MOD = 1000'000'007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const double PI = acos(-1);
const double ERR = 1e-10;
#define szz(x) (int)(x).size()
#define IOS ios_base::sync_with_stdio(false); cout.tie(0);cin.tie(0);
#define flush fflush(stdout)

template<class T>
istream &operator>>(istream &ist, vector<T> &vec)
{
	for (auto i = vec.begin(); i != vec.end(); ++i)
	{ ist >> vec[i]; }
	return ist;
}

ll mod(ll a, ll m)
{ return (a + (abs(a) / m) * m + m) % m; }

//****************************don't use int!!!!!!!****************************//
//***************************code starts here!!!!!****************************//


int main()
{
	IOS
	char c;
	cin >> c;
	if (c == 'A')
	{
		cout << 'T';
		return 0;
	} else if (c == 'C')
	{
		cout << 'G';
		return 0;
	} else if (c == 'G')
	{
		cout << 'C';
		return 0;
	} else if (c == 'T')
	{
		cout << 'A';
		return 0;
	}

	return 0;
}

Measured memory_bytes: 256
n = int(input())
h = [int(e) for e in input().split()]
cost = [0] * n
cost[1] = abs(h[1] - h[0])
for i in range(2, n):
  cost[i] = min(abs(h[i] - h[i - 1]) + cost[i - 1], abs(h[i] - h[i - 2]) + cost[i - 2])
print(cost[n - 1])


Measured memory_bytes: 13708
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include <cstdint>

using namespace std;

int main() {
	int64_t N;
	cin >> N;

	vector<int64_t> L(87);
	L.at(0) = 2;
	L.at(1) = 1;
	for (int i = 2; i < 87; i++) {
		L.at(i) = L.at(i - 1) + L.at(i - 2);
	}

	cout << L.at(N) << endl;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main{
    public static void main (String args[]){

        //初期処理
    //    Scanner sc=new Scanner(System.in);
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        HashSet<String> set = new HashSet<>();
        String[] sArray=new String[2];
    //    int n=Integer.parseInt(sc.nextLine());
    try{
    int n =Integer.parseInt(br.readLine());
        for (int i = 0; i < n; i++) {
    //        sArray = sc.nextLine().split(" ");
    sArray=br.readLine().split("\\s+");
                if ( sArray[0].equals("insert")){
                    set.add(sArray[1]);
                }else{
                    if (set.contains(sArray[1])){
                        System.out.println("yes");
                    } else {
                        System.out.println("no");
                    }
                }
        }
    }catch(IOException e){e.printStackTrace();}
}
}



Measured memory_bytes: 340164
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <math.h>
#include <string>
using namespace std;
 
const double PI = acos(-1);
const int M=998244353;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define oo 1e16


int main()
{
//	freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	
	int a;
	cin>>a;
	printf("%d\n",a+a*a+a*a*a );
	return 0;
}

Measured memory_bytes: 3220
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define IFOR(i, m, n) for(ll i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) (v).begin(), (v).end()

int main(){
  ll n; cin >> n;
  vector<ll> a(n);
  REP(i,n){
    cin >> a[i];
    a[i]--;
  }
  ll cnt = 0;
  REP(i,n) if(i == a[a[i]]) cnt++;
  cout << cnt/2 << endl;
}


Measured memory_bytes: 1024
/*https://atcoder.jp/contests/abc086/tasks/abc086_b*/
#include<bits/stdc++.h>
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
#ifndef ONLINE_JUDGE
	// for getting input from input.txt
	freopen("input.txt", "r", stdin);
	// for writing output to output.txt
	freopen("output.txt", "w", stdout);
#endif
	string a, b;
	cin >> a >> b;
	a += b;
	double x = stoi(a);
	// cout << x << endl;
	x = sqrt(x);
	b = to_string(x);
	// cout << b << endl;
	for (int i = 0; i < b.size(); i++)
	{
		if (b[i] == '.' && b[i + 1] != '0')
		{
			cout << "No";
			// cout << b[i] << " " << b[i + 1] << endl;
			return 0;
		}
	}
	cout << "Yes";
}

Measured memory_bytes: 3796
import java.util.Scanner;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        S = S.replaceAll("B", "");
        if (S.length() == 0 || S.length() == 3) 
            System.out.println("No");
        else 
            System.out.println("Yes");
    }
}

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

int main() {
  int n, a1, a2, a3;
  cin >> n;
  if(n % 10 == 1){
    a1 = 9;
  }else{
    a1 = 1;
  }
  n /= 10;

  if(n % 10 == 1){
    a2 = 9;
  }else{
    a2 = 1;
  }
  n /= 10;

  if(n % 10 == 1){
    a3 = 9;
  }else{
    a3 = 1;
  }
  n /= 10;

  cout << a1 + a2 * 10 + a3 * 100 << endl;
}

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

using namespace std;
#define rep(i,n) for (int i =0;i<(n);++i)
using ll = long long;
using P = pair<int, int>;
//int choose2(ll x){
	//	return x*(x-1)/2;}
const int INF = 1001001001;

int main() {
	int N;
		cin >> N;
		vector<int> A(N);
		vector<int> B(N,0);
	
		rep(i, N-1) {
			cin >> A[i];
			B[A[i]-1]++;
		}
		rep(i, N) cout << B[i]<<endl;
		
	
}

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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    ll A, B, C, X, Y;
    cin >> A >> B >> C >> X >> Y;

    ll tmp = min(X, Y);
    ll ans = min(A * tmp + B * tmp, 2 * C * tmp);
    X -= tmp;
    Y -= tmp;
    if (X == 0) {
        ans += min(B * Y, 2 * C * Y);
    } else {
        ans += min(A * X, 2 * C * X);
    }
    cout << ans << '\n';
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin, (x).rend()
typedef long long ll;

int main(){
	int n; cin>>n;
	while(n>0)n-=1000;
	cout<<n*-1<<endl;
	return 0;
}


Measured memory_bytes: 3592
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <tuple>
#include <memory>
#include <cmath>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <cfloat>
#include <cassert>
#include <random>
int main() {
	int n; std::cin >> n;
	std::vector<int> sticks(n); for (auto& s : sticks) std::cin >> s;
	std::sort(sticks.begin(), sticks.end());
	int count = 0;
	for (auto i = 0; i < n; ++i) for (auto j = i + 1; j < n; ++j) for (auto k = j + 1; k < n; ++k) {
		if (sticks[i] + sticks[j] > sticks[k]) {
			++count;
		}
	}
	std::cout << count << std::endl;
}

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

int main(){
    int N;
    cin>>N;
    vector<pair<int,int>> work;
    rep(i,N){
        int a,b;
        cin>>a>>b;
        work.push_back(pair<int,int>(b,a));
    }
    sort(work.begin(),work.end());
    ll cnt=0;
    rep(i,N){
        cnt+=work[i].second;
        if(cnt>work[i].first){
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
    return 0;
}

Measured memory_bytes: 5372
#include<bits/stdc++.h>
using namespace std;
#define maxn   200005
#define ll long long

int main()
{
	cin.tie(0);
	cout.tie(0);
	ios_base::sync_with_stdio(0);
    int n,k;cin>>n>>k;
    int arr[n],i,j;
    for(i=0;i<n;i++)
    cin>>arr[i];
    if(n==1){cout<<0;return 0;}
    vector<int>dp(n,INT_MAX);
    dp[0]=0;
    for(i=1;i<n;i++)
    for(j=max(0,i-k);j<i;j++)
    dp[i]=min(dp[i],dp[j]+abs(arr[j]-arr[i]));
    
    cout<<dp[n-1];
}

Measured memory_bytes: 1024
import fractions

a, b, c, d = map(int, input().split())

cxd = (c * d) // fractions.gcd(c, d)
sa = b - a
ans = (b - b//c - b//d + b//cxd) - ((a-1) - (a-1)//c - (a-1)//d + (a-1)//cxd)

print(ans)

Measured memory_bytes: 5048
#include <iostream>
#include <string>
#include <stddef.h>
#include <stack>
#include <queue>

using namespace std;

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

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

int main() {
  vector<vector<int>> G(3, vector<int>(3));
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      cin >> G[i][j];
    }
  }
  bool judge = false;
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      if (G[i][i] + G[j][j] == G[i][j] + G[j][i]) {
        judge = true;
      }
      else {
      judge = false;
      break;
      }
    }
  }
  if (judge) cout << "Yes" << endl;
  else cout << "No" << endl;
}


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

int main() {
  int n,m,wa = 0,ac = 0;
  cin >> n >> m;
  vector<bool>seen(n,false);
  vector<int>ans(n,0);
  rep(i,m){
    int p;
    string s;
    cin >> p >> s;
    p--;
    if(s == "WA"){
      if(!seen[p]) ans[p]++;
    }
    else{
      if(!seen[p]){
        wa += ans[p];
        ac++;
        seen[p] = true;
      }
    }
  }
  cout << ac << " " << wa << endl;
}

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

int N, Xor;
vector<int> arr, low;

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

    arr.resize(N);
    Xor = 0;

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

    low = vector<int>(31, 0);

    for(int i = 0; i < N; i++) {
        for(int j = 0; j < 31; j++) {
            if(arr[i] & (1<<j)) {
                low[j] = 1;
                break;
            }
        }
    }

    bool ok = false;
    int bf = 0;
    int ans = 0;
    for(int i = 31; i >= 0; i--) {
        if(Xor & (1<<i)) ok = true;
        if(ok) {
            if(bf != ((Xor & (1<<i))? 1 : 0)) {
                if(!low[i]) {
                    printf("-1");
                    return 0;
                }
                ans++;
            }
            bf = ((Xor & (1<<i))? 1 : 0);
        }
    }

    cout << ans;
}


Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
using namespace std;
#define MON 1000000007
#define INF (1<<29)
typedef long long Int;
typedef pair<Int, Int> P;

#define max(x, y) ((x)>(y)?(x):(y))
#define min(x, y) ((x)<(y)?(x):(y))

vector<int> far(10800);
vector<int> up(10800);
int u, v, w, n;
class Edge{
public:
  int from, to, rev;
  Int cost, lim;
  Edge(int from, int to, Int cost, int lim = -1, Int rev = -1):
    from(from),to(to),cost(cost),lim(lim),rev(rev){}
};


class Graph{
public:
  int n;
  int m;
  vector<vector<Edge>> edge;
  Graph(int n = 0):n(n),m(0){
    edge = vector<vector<Edge>>(n);
  }
  void add_edge(int from, int to, int cost = 1, int lim = -1)
  {
    if(lim == -1){
      edge[from].push_back(Edge(from, to, cost));
      return;
    }
    edge[from].push_back(Edge(from, to, cost, lim, edge[to].size()));
    edge[to].push_back(Edge(to, from, -cost, 0, edge[from].size() - 1));
  }
};

Graph g;

void dfs0(int x, int last = -1){
  for(auto e: g.edge[x]){
    if(e.to != last)dfs0(e.to, x);
  }
  if(last == -1)return;
  auto it = g.edge[x].begin();
  while(it->to != last)it++;
  g.edge[x].erase(it);
  return;
}

void dfs1(int x, int last = -1){
  far[x] = 0;
  for(auto e:g.edge[x]){
    if(e.to == last)continue;
    dfs1(e.to, x);
    far[x] = max(far[e.to] + e.cost, far[x]);
  }
  for(int i = 1;i < g.edge[x].size();i++){
    if(far[g.edge[x][0].to] + g.edge[x][0].cost < far[g.edge[x][i].to] + g.edge[x][i].cost)
      swap(g.edge[x][0], g.edge[x][i]);
  }
  for(int i = 2;i < g.edge[x].size();i++){
    if(far[g.edge[x][1].to] + g.edge[x][1].cost < far[g.edge[x][i].to] + g.edge[x][i].cost)
      swap(g.edge[x][1], g.edge[x][i]);
  }
}

void dfs2(int x, int last = -1, int w = 0){
  if(last != -1){
    if(g.edge[last][0].to == x){
      if(g.edge[last].size() > 1)up[x] = far[g.edge[last][1].to] + g.edge[last][1].cost + w;
      else up[x] = w;
    }
    else up[x] = far[last] + w;
    up[x] = max(up[x], up[last] + w);
  }
  for(auto e:g.edge[x]){
    if(e.to == last)continue;
    dfs2(e.to, x, e.cost);
  }
}

int main(){
  cin >> n;
  g = Graph(n);
  for(int i = 0;i < n-1;i++){
    cin >> u >> v >> w;
    g.add_edge(u, v, w);
    g.add_edge(v, u, w);
  }
  dfs0(0);
  dfs1(0);
  dfs2(0);
  for(int i = 0;i < n;i++){
    cout << max(far[i], up[i]) << endl;
  }
  return 0;
}


Measured memory_bytes: 4684
#include<iostream>
#include <string>
int main(){
  std::string S,T;
  std::cin>>S>>T;
  if(S==T)std::cout<<"Yes"<<std::endl;
  else{
	  for(int i=0;i<S.length();i++){
		  char U;
		  U=S[0];
		  for(int j=0;j<S.length();j++){
			  if(j+1!=S.length())S[j]=S[j+1];
			  else S[j]=U;
 
		  }
		  if(S==T){
			  std::cout<<"Yes"<<std::endl;
			  return 0;
		  }
	  }
	  std::cout<<"No"<<std::endl;
  }
}

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

void act(int x, int y){
	char c;
	
	if(x < 0){
		c = 'R';
	}else{
		c = 'L';
	}
	for(int i = 0; i < abs(x); i++){
		cout << c;
	}
	
	if(y < 0){
		c = 'U';
	}else{
		c = 'D';
	}
	for(int i = 0; i < abs(y); i++){
		cout << c;
	}
//	cout << " ";
}

void act2(int x, int y){
	char c, d;
	
	if(x < 0){
		c = 'R';
		cout << 'D';
	}else{
		c = 'L';
		cout << 'U';
	}
	for(int i = 0; i < abs(x) + 1; i++){
		cout << c;
	}
	
	if(y < 0){
		d = 'U';
	}else{
		d = 'D';
	}
	for(int i = 0; i < abs(y) + 1; i++){
		cout << d;
	}
	if(c == 'R'){
		cout << 'L';
	}else{
		cout << 'R';
	}
//	cout << " ";
}


int main(){
	int sx, sy, tx, ty;
	cin >> sx >> sy >> tx >> ty;
	
	int actx = sx - tx;
	int acty = sy - ty;
	act(actx, acty);
	
	actx = tx - sx;
	acty = ty - sy;
	act(actx, acty);
	
	actx = sx - tx;
	acty = sy - ty;
	act2(actx, acty);
	
	actx = tx - sx;
	acty = ty - sy;
	act2(actx, acty);	
	
	cout << endl;
}

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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
using ull = unsigned long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

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

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

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v)is >> e;
  return is;
}

int Sum(const string&s){
  int n = (int)s.size();
  int sum = 0;
  for(int i = 0; i < n; ++i)sum += s[i] - '0';
  return sum;
}

struct UFT{
  int * p;
  
  UFT(int N):p(new int[N]){fill(p,p+N,-1);}  
  ~UFT(){delete[] p;}  
  int par(int a)   { if( p[a] >= 0 ){ p[a] = par( p[a] ); return p[a]; } return a;  }
  int size(int a)  { return -p[par(a)]; }
  bool	same(int a, int b) { return par(a) == par(b); }
  void unite(int a, int b){
    a = par(a);  b = par(b);
    if( a == b ) return;
    if( size(a) < size(b) )a^=b^=a^=b;
    p[a] -= size(b);
    p[b] = a;
  }
};


int main(){
  UFT uft(13);
  uft.unite(4,6);
  uft.unite(4,9);
  uft.unite(4,11);
  uft.unite(1,3);
  uft.unite(1,5);
  uft.unite(1,7);
  uft.unite(1,8);
  uft.unite(1,10);
  uft.unite(1,12);
  int a,b;cin >> a >> b;
  cout << (uft.same(a, b) ? "Yes" : "No") << endl;
  return 0;
}


Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
int main(){
    char s[11];
    char t[11];
    char ts[11];
    int e=0;
    scanf("%s",s);
    scanf("%s",t);
    while(1){
        if(s[e]=='\0')break;
        e++;
    }
    for(int i=0;i<e;i++){
        ts[i]=t[i];
    }
    ts[e]='\0';
    if(strcmp(s,ts)==0)printf("Yes");
    else printf("No");
    
    return 0;
}

Measured memory_bytes: 3832
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import sys

input = sys.stdin.readline
n, m, x, y = map(int, input().split())
x_list = list(map(int, input().split()))
y_list = list(map(int, input().split()))

x_list.sort()
y_list.sort()

for i in range(int(x_list[-1]) + 1, int(y_list[0]) + 1):
    if (i > x) and (i <= y):
        print("No War") 
        exit()

print("War")


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define int long long

const int maxn = 10010;
const int inf = 0x3f3f3f3f;

inline int read() {
    register int g = 1; register char ch;
    while(!isdigit(ch = getchar())) if(ch == '-') g = -1;
    register int x = ch ^ '0';
    while(isdigit(ch = getchar())) x = (((x << 2) + x) << 1) + (ch ^ '0');
    return x * g;
}

inline void print(int x) {
    if(x < 0) putchar('-'), x = -x;
    if(x > 9) print(x / 10);
    putchar(x % 10 + '0');
}

int x, y;

signed main() {
	x = read(), y = read();
	print(x + y / 2);
	return 0;	
}

Measured memory_bytes: 256
from sys import exit
n,m,X,Y=map(int,input().split())
x=list(map(int,input().split()))
y=list(map(int,input().split()))
mx=max(x)
my=min(y)
for z in range(X+1,Y+1):
  if mx<z and z<=my:
    print('No War')
    exit()
print('War')

Measured memory_bytes: 3064
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef  long long int ll;
typedef long double db;
#define pb push_back
#define mp make_pair
#define np(str) next_permutation(str.begin(),str.end())
#define ub(v,val) upper_bound(v.begin(),v.end(),val)
#define lb(v,val) lower_bound(v.begin(),v.end(),val)
#define sortv(vec) sort(vec.begin(),vec.end())
#define rev(p) reverse(p.begin(),p.end());
#define v vector
#define PI 3.1415926535
#define len length()
#define repc(i,s,e) for(ll i=s;i<e;i++)
#define np(str) next_permutation(str.begin(),str.end())
#define fi first
#define se second
#define mset(a,val) memset(a,val,sizeof(a));
#define mt make_tuple
#define repr(i,n) for(i=n-1;i>=0;i--)
#define rep(i,n) for( i=0;i<n;i++)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const int M = 1e9 + 7;
ll INF = 1e10;
ll n;
const int MAX = 1000001;

struct Query
{
	ll l, r, idx;
};

// cmp function to sort queries according to r
bool cmp(Query x, Query y)
{
	return x.r < y.r;
}

// updating the bit array
void update(ll idx, ll val, ll bit[], ll n)
{
	for (; idx <= n; idx += idx & -idx)
		bit[idx] += val;
}

// querying the bit array
ll query(ll idx, ll bit[], ll n)
{
	ll sum = 0;
	for (; idx > 0; idx -= idx & -idx)
		sum += bit[idx];
	return sum;
}

void answeringQueries(ll arr[], ll n, Query queries[], ll q)
{
	// initialising bit array
	ll bit[n + 1];
	memset(bit, 0, sizeof(bit));

	// holds the rightmost index of any number
	// as numbers of a[i] are less than or equal to 10^6
	ll last_visit[MAX];
	memset(last_visit, -1, sizeof(last_visit));

	// answer for each query
	ll ans[q];
	ll query_counter = 0;
	for (ll i = 0; i < n; i++)
	{
		// If last visit is not -1 update -1 at the
		// idx equal to last_visit[arr[i]]
		if (last_visit[arr[i]] != -1)
			update (last_visit[arr[i]] + 1, -1, bit, n);

		// Setting last_visit[arr[i]] as i and updating
		// the bit array accordingly
		last_visit[arr[i]] = i;
		update(i + 1, 1, bit, n);

		// If i is equal to r of any query  store answer
		// for that query in ans[]
		while (query_counter < q && queries[query_counter].r == i)
		{
			ans[queries[query_counter].idx] =
			    query(queries[query_counter].r + 1, bit, n) -
			    query(queries[query_counter].l, bit, n);
			query_counter++;
		}
	}

	// print answer for each query
	for (ll i = 0; i < q; i++)
		cout << ans[i] << endl;
}

int main() {
	// your code goes here
	IOS;

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ll  i, j, t, k, x, y, z, m,  N;
	cin >> n >> m;
	ll a[n];
	rep(i, n)
	cin >> a[i];
	Query queries[m];
	rep(i, m) {
		cin >> x >> y;
		x--, y--;
		queries[i].l = x;
		queries[i].r = y;
		queries[i].idx = i;

	}
	ll q = sizeof(queries) / sizeof(queries[0]);
	sort(queries, queries + q, cmp);
	answeringQueries(a, n, queries, q);
	return 0;

}




Measured memory_bytes: 35060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
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; }
const ll INF = 1LL << 60;
const int MAX = 1000000010;
const ll MOD = 1000000007;

int main() {
    int N; cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }

    ll money = 1000;
    ll kabu = 0;

    for (int i = 0; i < N - 1; i++) {
        if (A[i] < A[i + 1]) {
            kabu = money / A[i];
            money -= (ll)A[i] * kabu;
            money += (ll)A[i + 1] * kabu;
            kabu = 0;
        }
    }

    cout << money << endl;
    return 0;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define debug(x) cerr<<#x<<": "<<x<<endl;
#define MOD 1000000007ULL;
#define rep(i,n) for(int i=0;i<n;i++)


int main() {
	ll a,b,c,d;
  	cin>>a>>b>>c>>d;
  	ll ans;
  	if(b>=0&&d>=0) ans=max(b*d,a*c);
  	if(b>=0&&d<0){
     	if(a<0) ans=max(a*c,b*d);
      	if(a>=0) ans=max(a*d,b*c);
    }
  	if(d>=0&&b<0){
     	if(c<0) ans=max(a*c,b*d);
      	if(c>=0) ans=max(c*b,a*d);
    }
  	if(b<0&&d<0) ans=max(b*d,a*c);
  
  	cout<<ans<<endl;
  	
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define Open(s) freopen(s".in","r",stdin);freopen(s".out","w",stdout);
#define inl inline
#define reg register
#define i64 long long 
#define int long long 
using namespace std;
inl int read(){int x=0,f=0;char ch=0;while(!isdigit(ch))f|=(ch=='-'),ch=getchar();while(isdigit(ch))(x*=10)+=(ch^48),ch=getchar();return f?-x:x;}
inl void Ot(reg int x){if(x<0)x=-x,putchar('-');if(x>=10)Ot(x/10);putchar(x%10+'0');}
inl void Print(reg int x,char til='\n'){Ot(x);putchar(til);}
inl int Max(reg int x,reg int y){return x>y?x:y;}
inl int Min(reg int x,reg int y){return x<y?x:y;}
inl int Abs(reg int x){return x<0?-x:x;}
const int MAXN=105060;
int n,k;
int Smin,Smax;
int a[MAXN],ans;
int sum[MAXN];
int fac[MAXN],inv[MAXN];
const int Mod=1e9+7;
inl int qpow(int x,int y=Mod-2){
	int ret=1;
	for(;y;y>>=1,x=x*x%Mod)if(y&1)ret=ret*x%Mod;
	return ret;
}
void Init(){
	inv[0]=fac[0]=1;
	for(reg int i=1;i<=n;i++)fac[i]=(fac[i-1]*i)%Mod;
	inv[n]=qpow(fac[n]);
	for(reg int i=n-1;i>=1;i--)inv[i]=inv[i+1]*(i+1)%Mod;
}
int C(int n,int m){return fac[n]%Mod*inv[m]%Mod*inv[n-m]%Mod;}
signed main(){
	#ifndef ONLINE_JUDGE
		//freopen("../../data.in","r",stdin);
	#endif
	cin>>n>>k;
	if(k==1)return puts("0"),0;
	Init();
	for(reg int i=1;i<=n;i++)
		cin>>a[i];
	sort(a+1,a+n+1);
	// cout<<C[n]<<endl;
	// for(reg int i=1;i<=n;i++)
		// printf("C(%lld,%lld)=%lld\n",i,k-1,C[i]);
	for(reg int i=1;i<=n-k+1;i++)
		Smin=(C(n-i,k-1)*a[i]%Mod+Smin)%Mod;
	for(reg int i=n;i>=k;i--)
		Smax=(C(i-1,k-1)*a[i]%Mod+Smax)%Mod;
	// cout<<Smax<<" "<<Smin<<endl;
	cout<<(Smax-Smin+Mod+Mod)%Mod<<endl;
	return 0;
}

Measured memory_bytes: 2560
#include<cstring>
#include<cstdio>

char s[5];

int main()
{
	scanf("%s",s);
	for(int i=1;i<4;i++)
		if(s[i]==s[i-1])
		{
			printf("Bad");
			return 0;
		}
	printf("Good");
	return 0;
}


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

class Main {

	public static void main(String[] args) throws Exception {
		final Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int[] A = new int[(int) (M)];
		int[] B = new int[(int) (M)];
		for (int i = 0; i < M; i++) {
			A[i] = sc.nextInt() - 1;
			B[i] = sc.nextInt() - 1;
		}


		long answer = (long) N * (N - 1) / 2L;
		UnionFind uf = new UnionFind(N);
		long[] a = new long[M + 1];
		a[M] = answer;
		for (int i = M - 1; i >= 0; i--) {
			if (!uf.connected(A[i], B[i])) {
				answer -= (long) uf.count(A[i]) * uf.count(B[i]);
				uf.union(A[i], B[i]);
			}

			a[i] = answer;
		}

		StringBuilder sb = new StringBuilder();
		for (int i = 1; i <= M; i++) {
			sb.append(a[i]).append("\n");
		}

		System.out.print(sb);
	}

	private static class UnionFind {

		private int[] parent;
		private int[] count;

		public UnionFind(int n) {
			parent = new int[n];
			count = new int[n];
			for (int i = 0; i < n; i++) {
				parent[i] = i;
				count[i] = 1;
			}
		}

		public boolean union(int v, int w) {
			int a = root(v);
			int b = root(w);
			if (a == b) return false;

			if (count[a] >= count[b]) {
				parent[b] = a;
			} else {
				parent[a] = b;
			}
			count[a] = count[b] = count[a] + count[b];

			return true;
		}

		public boolean connected(int v, int w) {
			return root(v) == root(w);
		}

		public int count(int v) {
			return count[root(v)];
		}

		private int root(int v) {
			while (parent[v] != parent[parent[v]]) parent[v] = parent[parent[v]];
			return parent[v];
		}
	}

}


Measured memory_bytes: 93224
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007

int main() {

  long long x,y;
  cin >> x >> y;

  if(x == 0) {
    if(y>0)cout << y << endl;
    else cout << abs(y)+1 << endl;
  }else if(y == 0) {
    if(x > 0) cout << x+1 << endl;
    else cout << abs(x) << endl;
  }else if(x*y > 0) {
    if(x<y) cout << y-x << endl;
    else cout << x-y+2 << endl;
  }else if(x*y < 0) {
    if(abs(x)<abs(y)) cout << abs(y)-abs(x)+1 << endl;
    else cout << abs(x)-abs(y)+1 << endl;
  }
}


Measured memory_bytes: 256
#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 a;
    string s;
    cin >> a >> s;
    if (a >= 3200)
        cout << s << endl;
    else
        cout << "red" << endl;
    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

int main() {
    ll a, b, c;
    cin >> a >> b >> c;
    int flag = 0;

    if(c - (a + b) > 0){
        if(4*a*b < (c - (a+b)) * (c - (a+b)))flag = 1;
    }
    if(flag)yn;
    return 0;
}
 
 


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define FOR(i, x, y) for(int i = x; i < y; i++)
#define endll cout << "\n"
#define For(n) for(int i = 0; i < n; i++)
const ll maxn = 1000000 + 100;
const int mod = 1e9 + 7;
ll a[maxn];
int main()
{
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int n;
    ll res = 0;
    cin >> n;
    for(int i = 0; i < n; i++)
    {
        cin >> a[i];
        res += a[i];
    }
    ll maj = 0;
    ll ans = 1e18;
    for(int i = 0; i < n - 1; i++)
    {
        maj += a[i];
        ans = min(ans, abs(res - 2 * maj));
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 1792
main(){
	int n,p,d1,d2,d,mp,md;
	for(;scanf("%d",&n),n;){
		md=0;
		for(;n--;){
			scanf("%d%d%d",&p,&d1,&d2);
			d=d1+d2;
			if(d>md){
				md=d;
				mp=p;
			}
		}
		printf("%d %d\n",mp,md);
	}
	exit(0);
}

Measured memory_bytes: 416
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int k = sc.nextInt(), s = sc.nextInt(), ret = 0;
			for (int x = 0; x <= k; x++) {
				for (int y = 0; y <= k; y++) {
					if (s - x - y <= k && s - x - y >= 0) ret++;
				}
			}
		System.out.println(ret);
		sc.close();
	}
}

Measured memory_bytes: 9684
#include<iostream>
#include<string>
#include<cmath>

using namespace std;
 
int main()
{
  unsigned long long N;
  cin >> N; 
  
  // ALL - Miod3 -mod5 + mod15
  unsigned long long all,mod3,mod5,mod15;
  all = N*(N+1)/2;
  mod3 = ceil(N/3)*(ceil(N/3)+1)/2*3;
  mod5 = ceil(N/5)*(ceil(N/5)+1)/2*5;
  mod15 = ceil(N/15)*(ceil(N/15)+1)/2*15;  
  
  cout << all -mod3 -mod5 + mod15;
  return 0;
}

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

using namespace std;

template <typename Heap>
struct Shifter {
    using T=typename Heap::value_type;

    Heap h;
    T s=0;
    void shift(T x) {
        s += x;
    }
    void push(T x) {
        h.push(x - s);
    }
    T top() {
        return h.top() + s;
    }
    void pop() {
        h.pop();
    }
};
template<class T> using MaxHeap = Shifter<priority_queue<T>>;
template<class T> using MinHeap = Shifter<priority_queue<T, vector<T>, greater<T>>>;

using ll=long long;
void solve() {
    int n; cin >> n;
    vector<int> x(n), y(n);
    for (int i = 0; i < n; i++) {
        cin >> x[i] >> y[i];
        y[i] -= x[i];
    }
    
    MaxHeap<ll> L;
    MinHeap<ll> R;
    L.push(x[0]); R.push(x[0]);
    ll res = 0;
    for (int i = 1; i < n; i++) {
        int z = x[i];
        L.shift(-y[i]);
        R.shift(y[i-1]);
        if (L.top() > z) {
            res += L.top() - z;
            L.push(z); L.push(z);
            R.push(L.top());
            L.pop();
        } else if (z > R.top()) {
            res += z - R.top();
            R.push(z); R.push(z);
            L.push(R.top());
            R.pop();
        } else {
            L.push(z); R.push(z);
        }
    }
    cout << res;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    cout << endl;
}


Measured memory_bytes: 2804
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <cstring>
#include <utility>
#include <numeric>
#include <queue>

using namespace std;

bool check[100000][3];

int main(){

    int N, M;
    cin >> N >> M;
    vector<vector<int>> E(N);

    int u, v;
    for(int i = 0; i < M; i++){
        cin >> u >> v;
        E[u - 1].push_back(v - 1);
    }
    int S, T;
    cin >> S >> T;
    S--;
    T--;

    for(int i = 0; i < N; i++){
        for(int j = 0; j < 3; j++){
            check[i][j] = false;
        }
    }

    queue<pair<int, pair<int, int>>> q;
    q.push(make_pair(S, make_pair(0, 0)));
    check[S][0] = true;

    int ans = -1;

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

        int node = temp.first;
        int timing = temp.second.first;
        int cost = temp.second.second;

        if(timing == 0 && node == T){
            ans = cost;
            break;
        }

        if(timing == 0){
            cost++;
        }

        int nextTiming = (timing + 1) % 3;
        for(int e: E[node]){
            if(!check[e][nextTiming]){
                q.push(make_pair(e, make_pair(nextTiming, cost)));
                check[e][nextTiming] = true;
            }
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 6016
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    scanf("%d",&n);
    int dp[100100];
    int i,j;
    for(i=0;i<=100000;i++)
    {
        dp[i] = 1e7;
    }
    dp[0] = 0;
    for(i=0;i<=100000;i++)
    {
        dp[i] = min(dp[i],dp[i-1] + 1);
        for(j=6;j+i<=100000;j*=6)
        {
            dp[i+j] = min(dp[i+j],dp[i]+1);
        }
        for(j=9;j+i<=100000;j*=9)
        {
            dp[i+j] = min(dp[i+j],dp[i]+1);
        }
    }
    printf("%d\n",dp[n]);
    return 0;
}


Measured memory_bytes: 640
/* Akshat Sharma @akshat98 */
#include <iostream>
#include <bits/stdc++.h>
#define IOS  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define mp   make_pair
#define pb   push_back
#define F    first
#define S    second
#define ll   long long
#define MOD  1000000007
#define MAX  1000000001
#define vi   vector<int>
#define vl   vector<ll>
#define vpi  vector<pair<int,int> >
#define vpl  vector<pair<ll,ll> >
#define rep(i,a,b) for(i=a;i<b;i++)
#define reqp(i,a,b) for(i=a;i<=b;i++)
#define ren for(i=0;i<n;i++)
#define ALL(a)  (a).begin(),(a).end()
using namespace std;
typedef pair<int,int>pii;
typedef pair<ll,ll>pll;


int main()
{
	#ifndef ONLINE_JUDGE
	freopen("input_file.txt", "r", stdin);
	//freopen("output_file.txt", "w", stdout);
	#endif
	ll i,j,k,l,n,test_case,m,r;
	test_case=1;
	//cin>>test_case;
	while(test_case--){
		cin>>n>>m;
		j=0;
		rep(i,0,m){
			cin>>r;
			j+=r;
		}
		if(n>=j)cout<<n-j<<"\n";
		else cout<<"-1\n";


	}
	
	return 0;
}

Measured memory_bytes: 3636
#include <stdio.h>

int n,s,i ;

int main(void){

    scanf ("%d",&n) ;
    
    i = n ;
    
    while (i>0){
        s += i%10 ;
        i = i/10 ;
    }
    
    if ( n%s==0 ){
        printf ("Yes") ;
    }
    else{
        printf ("No") ;
    }
    
    
    return 0 ;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll LCM(ll a,ll b) {
    ll temp=__gcd(a,b);
    return (a/temp*b);
}
int main(int argc,char const *argv[]) {
    ll t;
    cin>>t;
    ll ara[100010];
    for(int i=1;i<=t;i++) {
        cin>>ara[i];
    }
    ll ans=1LL;
    for(int i=1;i<=t;i++) {
        ans=LCM(ara[i],ans);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using P = pair<int,int>;

int main() {
  int n;
  cin >> n;
  vector<P>table(n);
  
  for (int i = 0; i < n; i++) {
    int a,b;
    cin >> a >> b;
    table.at(i) = make_pair(b,a);
  }
  sort(table.begin(),table.end());
  
  bool ok = true;
  int sum = 0;
  for (int i = 0; i < n; i++) {
    sum += table.at(i).second;
    if (sum > table.at(i).first) {
      ok = false;
      break;
    }
  }
  cout << (ok ? "Yes" : "No") << endl;
}

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

#define f first
#define s second
#define ll long long
#define pb push_back
#define mp make_pair
#define inp(x) cin>>x
#define print(x) cout<<x
#define pii pair<int,int>
#define pll pair<ll,ll>
#define gcd(a,b) __gcd(a,b)
#define reset(d,val) memset(d,val,sizeof(d))
#define sort(v) sort(v.begin(),v.end())
#define sort_arr(arr,i,f) sort(arr+i,arr+f)
#define pq priority_queue<int,vector<int>,greater<int> >
#define pq1 priority_queue<pll,vector<pll>,greater<pll> >

const int mod = 1e9+7;

ll dp[21][1<<21];
int arr[21][21];
int n;

ll f(int i,int mask) {
	if(mask==(1<<n)-1) return 1;
	if(dp[i][mask]!=-1) return dp[i][mask];
	ll ans = 0;
	for (int j = 0; j < n; ++j)
	{
		if(!(mask&(1<<j)) && arr[i][j]) {
			//cout<<"heell";
			ans = (ans+f(i+1,mask|(1<<j)))%mod;
		}
	}
	return dp[i][mask] = ans%mod;
}

int main(int argc, char const *argv[])
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	//int n;
	cin>>n;
	for (int i = 0; i < n; ++i)
	{
		for(int j=0;j<n;j++) cin>>arr[i][j];
	}
	memset(dp,-1,sizeof(dp));
	cout<<(f(0,0)+mod)%mod;
	return 0;
}


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

#define rng(i, a, b) for (int i = int(a); i < int(b); i++)
#define rep(i, b) rng(i, 0, b)
#define gnr(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define per(i, b) gnr(i, 0, b)

using namespace std;

using ll = unsigned long long;
using P = pair<int, int>;

const ll LIMIT = 1'000'000'000'000'000'000;
const int LIMIT_KETA = 18;

int calcKeta(ll n) {
  int res = 0;
  while ((n / 10) != 0) {
    res++;
    n /= 10;
  }
  return res;
}

int main() {
  int n;
  cin >> n;
  ll res = 1;
  ll beforeRes = res;
  bool over = false;
  bool containZero = false;
  rep(i, n) {
    int resKeta = calcKeta(res);
    ll aa;
    cin >> aa;
    int aaKeta = calcKeta(aa);
    if (resKeta + aaKeta > LIMIT_KETA) {
      res = 0;
      over = true;
    }
    res *= aa;
    if (res > LIMIT) {
      res = 0;
      over = true;
    }
    if (res < beforeRes) {
      res = 0;
      over = true;
    }
    if (aa == 0) {
      res = 0;
      containZero = true;
      break;
    }
    beforeRes = res;
  }
  if (containZero) {
    cout << 0 << endl;
  } else if (over) {
    cout << -1 << endl;
  } else {
    cout << res << endl;
  }
  return 0;
}


Measured memory_bytes: 3604
#include <iostream>

using namespace std;
char s[4];


void output(int i,int j,int k){
    cout<<s[0];
    if(i) cout<<'+';
    else cout<<'-';
    cout<<s[1];
    if(j) cout<<'+';
    else cout<<'-';
    cout<<s[2];
    if(k) cout<<'+';
    else cout<<'-';
    cout<<s[3]<<"=7";
}

int main(){
    int a,b,c,d,ans;
    int i,j,k;
    cin>>s;
    a=s[0]-'0';
    b=s[1]-'0';
    c=s[2]-'0';
    d=s[3]-'0';
    ans=a;
    for(i=0;i<=1;i++){
        ans=a;
        if(i) ans=ans+b;
        else ans-=b;
        for(j=0;j<2;j++){
            if(j) ans+=c;
            else ans-=c;
            for(k=0;k<2;k++){
                if(k) ans+=d;
                else ans-=d;
                if(ans==7){
                    output(i,j,k);
                    return 0;
                }
                if(k) ans-=d;
                else ans+=d;
            }
            if(j) ans-=c;
            else ans+=c;
        }
        if(i) ans-=b;
        else ans+=b;
    }
    return 0;
}


Measured memory_bytes: 256
n,k=map(int,input().split())
a=list(map(int,input().split()))
a=sorted(a,reverse=True)
mod=10**9+7
l=0
r=n-1
ans=1
if k%2==1:
  ans=a[0]
  l=1
if ans<0:
  c=1
  for i in range(k):
    c=c*a[i]%mod
  print(c)
  
else:
  for i in range(k//2):
    L=a[l]*a[l+1]
    R=a[r]*a[r-1]
    if L>=R:
      ans=ans*L%mod
      l+=2
    else:
      ans=ans*R%mod
      r-=2
  print(ans)
      

Measured memory_bytes: 31796
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
        solver.solve(1, in, out);
        out.close();
    }

    static class Task {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            long min = in.nextLong();
            long max = in.nextLong();

            long count = 0;
            long t = min;

            while (max >= t) {
                count++;
                t *= 2;
            }
            out.print(count);
        }

    }
}



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

int main(){
  long long N;
  long long Y;
  cin >> N >> Y;
  long long now_nedan = 0;
  long long num_man,num_gosen,num_sen,total_num;
  for(num_man = 0 ; num_man <= N; ++num_man){
    for(num_gosen = 0; num_gosen <= N; ++num_gosen){
      num_sen = N - num_man - num_gosen;
      if(num_sen >= 0){
        now_nedan = 10000 * num_man + 5000 * num_gosen + 1000 * num_sen;
        total_num = num_man + num_gosen + num_sen;
      }
      if(now_nedan == Y && total_num == N) break;
    }
    if(now_nedan == Y && total_num == N) break;
  }
  if(now_nedan == Y && total_num == N) cout << num_man << " " << num_gosen << " " << num_sen << endl;
  else cout << "-1 -1 -1" << endl;
}



Measured memory_bytes: 256