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

#ifdef _LOCAL
  #include <debug.hpp>
  #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
  #define debug(...) 42
#endif

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vl2;
const bool multiple_queries = false;
#define rep(i, n) for(ll i = 0; i < (n) ; ++i)
#define For(i, a, b) for(ll i = (a); i < (b) ; ++i)
#define revrep(i, n) for(ll i = (n) - 1; i >= 0 ; --i)
#define revFor(i, b, a) for(ll i = (b) - 1; i >= (a) ; --i)
#define all(v) v.begin(), v.end()
#define rall(v) (v).rbegin(), (v).rend()
#define popcount(i) __builtin_popcountl((i))
#define substring(s, start, end) s.substr((start), (end) - (start) + 1)

void print(){cout;}
void println(){cout << endl;}

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
  cout << head;
  if (sizeof...(tail) != 0) cout << " ";
  print(forward<Tail>(tail)...);
}

template <class T>
void print(vector<T>& vs){
  for (auto v: vs){
    cout << v;
    if (&v != &vs.back()) cout << " ";
  }
  cout << endl;
}

template <class Head, class... Tail>
void println(Head&& head, Tail&&... tail) {
  cout << head;
  if (sizeof...(tail) != 0) cout << " ";
  println(forward<Tail>(tail)...);
}

template <class T>
void println(vector<T>& vs){for (auto v: vs) cout << v << endl;}

struct event{
  ll loc, val; bool del;
  bool operator<(const event& e) const{
    if (loc == e.loc) return !del;
    return loc < e.loc;
  }

  bool operator>(const event& e) const{
    if (loc == e.loc) return del;
    return loc > e.loc;
  }

  tuple<ll, ll, bool> get_value(){return make_tuple(loc, val, del);}
};
string to_string(event e){return "{" + to_string(e.loc) + ", " + to_string(e.val) + ", " + to_string(e.del) + "}";}

template<typename T>
void read_vector(ll n, vector<T>& v, ll offset = 0){
  v.resize(n);
  rep(i, n){
    cin >> v[i];
    if (offset) v[i] += offset;
  }
}

void solve(){
  ll n, Q;
  cin >> n >> Q;
  priority_queue<event, vector<event>, greater<event>> q;
  rep(i, n){
    ll s, t, x;
    cin >> s >> t >> x;
    // s - x <= d < t - x
    q.push({s - x, x, false});
    q.push({t - x, x, true});
  }

  const ll INF = 1LL << 60;
  vl ds, ans(Q, -1);
  read_vector(Q, ds);
  multiset<ll> ss; ll cur = 0;
  
  while (!q.empty()){
    event e = q.top(); q.pop();
    ll v, x; bool del;
    tie(v, x, del) = e.get_value();
    ll val = ss.empty() ? -1 : *ss.begin();
    while (cur < Q && ds[cur] < v) ans[cur++] = val;

    if (!del) ss.insert(x);
    else ss.erase(ss.find(x));
  }
  
  println(ans);
}

void test(ll num = 0, bool verbose = false){
  rep(i, max(1LL, num)){
    ll t = clock();
    if (verbose) cout << "\n#####" << " " << i + 1 << " " << "#####" << " " << "\n## Answer ##\n";
    solve();
    if (verbose) {cout << "\nElapsed Time:" << " " << 1000.0 * (clock() - t) / CLOCKS_PER_SEC << " " << "[ms]" << endl;}
  }
}

int main(void){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  #ifdef _LOCAL
    test(6, true);
  #else
    ll t = 0;
    if (multiple_queries) cin >> t;
    test(t, false);
  #endif
  return 0;
}

Measured memory_bytes: 25204
void main()
{
    long A, B, m;
    rdVals(A, B, m);
    long[] a = rdRow;
    long[] b = rdRow;

    long result = a.reduce!min + b.reduce!min;
    foreach (i; 0 .. m)
    {
        long x, y, c;
        rdVals(x, y, c);
        --x, --y;
        result = min(result, a[x]+b[y]-c);
    }

    result.writeln;
}

enum long mod = 10^^9 + 7;
enum long inf = 1L << 60;

T rdElem(T = long)()
if (!is(T == struct))
{
    return readln.chomp.to!T;
}

alias rdStr = rdElem!string;
alias rdDchar = rdElem!(dchar[]);

T rdElem(T)()
if (is(T == struct))
{
    T result;
    string[] input = rdRow!string;
    assert(T.tupleof.length == input.length);
    foreach (i, ref x; result.tupleof)
    {
        x = input[i].to!(typeof(x));
    }
    return result;
}

T[] rdRow(T = long)()
{
    return readln.split.to!(T[]);
}

T[] rdCol(T = long)(long col)
{
    return iota(col).map!(x => rdElem!T).array;
}

T[][] rdMat(T = long)(long col)
{
    return iota(col).map!(x => rdRow!T).array;
}

void rdVals(T...)(ref T data)
{
    string[] input = rdRow!string;
    assert(data.length == input.length);
    foreach (i, ref x; data)
    {
        x = input[i].to!(typeof(x));
    }
}

void wrMat(T = long)(T[][] mat)
{
    foreach (row; mat)
    {
        foreach (j, compo; row)
        {
            compo.write;
            if (j == row.length - 1) writeln;
            else " ".write;
        }
    }
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.traits;
import std.container;
import std.functional;
import std.typecons;
import std.ascii;
import std.uni;

Measured memory_bytes: 8496
import bisect


def main(ls):
    total = 0

    for i in range(len(ls) - 2):
        for j in range(i + 1, len(ls) - 1):
            a = ls[i]
            b = ls[j]
            left = j + 1
            num = bisect.bisect_left(ls, a + b) - left
            total += num

    print(total)


_n = input()
ls = list(sorted(map(int, input().strip().split())))

main(ls)


Measured memory_bytes: 42204
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
int main() {
    // ifstream in("data1.txt");
    // cin.rdbuf(in.rdbuf());
    int A, B;
    cin >> A >> B;
    int ab = A * B;
    if(ab % 2 == 1 || (ab * 2) % 2 == 1 || (ab * 3) % 2 == 1) {
        cout << "Yes" << '\n';
    } else {
        cout << "No" << '\n';
    }
}


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


def main():
  A, B, H, M = map(int, input().split())

  mx = B * math.sin(math.pi * M / 30)
  my = B * math.cos(math.pi * M / 30)

  hx = A * math.sin(math.pi * (H * 60 + M) / 360)
  hy = A * math.cos(math.pi * (H * 60 + M) / 360)

  print(math.sqrt((mx - hx) ** 2 + (my - hy) ** 2))


if __name__ == '__main__':
  main()


Measured memory_bytes: 62644
import java.util.*;
public class Main
{
	public static void main(String[] args) {
	Scanner sc=new Scanner(System.in);
	int n=sc.nextInt();
	int flag=0;
	while(n>0){
	    if(n%10==7){
	        flag=1;
	    }
	    n=n/10;
	    
	}
	if(flag==1){
	    System.out.println("Yes");
	}else{
	    System.out.println("No");
	}
	    
	}
}


Measured memory_bytes: 35732
d = int(input())
c = list(map(int,input().split()))
s = [list(map(int,input().split())) for i in range(d)]
ld = [0]*26
score = 0

def dec(day):
    ans = 0
    for i in range(26):
        ans += c[i]*(day-ld2[i])
    return ans

rss = [[0,0] for i in range(d+1)]

for i in range(1,d+1):
    st = rss[i-1][0]
    ma = float('INf')*(-1)
    for t in range(26):
        ld2=ld.copy()
        ld2[t]=i
        score=st+s[i-1][t]-dec(i)
        ma = max(score,ma)
        if score==ma:
            t2=t+1
    ld[t2-1]=i
    rss[i][1]=t2
    rss[i][0]=ma
    print(t2)


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

#define vi vector<int>
#define ii pair<int,int>
#define vii vector<pair<int,int>>
#define vvi vector<vector<int>>

typedef long long ll;
typedef unsigned long long ull;

#define pb push_back
#define mp make_pair
#define fi first
#define se second

using namespace std;

int a[4][4];
int s1,s2,s3,s4,s5,s6;

int main (void) {
    ios_base::sync_with_stdio(false);

    for (int i = 1; i < 4; i++) {
        for (int j = 1; j < 4; j++) {
            cin >> a[i][j];
        }
    }

    s1 = a[1][1] + a[2][2] + a[3][3];
    s2 = a[1][3] + a[2][2] + a[3][1];
    s3 = a[1][2] + a[2][1] + a[3][3];
    s4 = a[1][2] + a[2][3] + a[3][1];
    s5 = a[3][2] + a[2][3] + a[1][1];
    s6 = a[3][2] + a[2][1] + a[1][3];

    if (s1 == s2 && s2 == s3 && s3 == s4 && s4 == s5 && s5 == s6)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#pragma warning(disable : 4996)

int main()
{
    int N, K,i;
    

    scanf("%d %d", &N, &K);

    int count = K;

    for (i = 1; i < N; i++) {
        count *= (K - 1);
    }

    printf("%d", count);

    return 0;

}

Measured memory_bytes: 2100
#include <iostream>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <tuple>
#include <queue>
using namespace std;
typedef long long ll;

int main(void){
    int n, k;
    cin >> n >> k;
    if ((n + 1) / 2 >= k) cout << "YES" << endl;
    else cout << "NO" << endl;
    
    
}


Measured memory_bytes: 256
import sys
fin = sys.stdin.readline
from collections import defaultdict

class UnionFind(object):
    def __init__(self, N):
        self.__root = list(range(N))
    

    def root(self, x):
        if self.__root[x] == x:
            return x
        else:
            # root abbreviation
            self.__root[x] = self.root(self.__root[x])
            return self.__root[x]

    
    def same(self, x, y):
        return self.root(x) == self.root(y)


    def unite(self, x, y):
        x = self.root(x)
        y = self.root(y)
        if (x == y):
            return
        self.__root[x] = y
        return


N, K, L = [int(elem) for elem in fin().split(' ')]
road_list = tuple([tuple([int(elem)-1 for elem in fin().split(' ')]) for _ in range(K)])
train_list = tuple([tuple([int(elem)-1 for elem in fin().split(' ')]) for _ in range(L)])

uf_road = UnionFind(N)
uf_train = UnionFind(N)

for p, q in road_list:
    uf_road.unite(p, q)

for r, s in train_list:
    uf_train.unite(r, s)


key_list = []
count = defaultdict(int)
for i in range(N):
    # logN
    key = (uf_road.root(i), uf_train.root(i))
    key_list.append(key)
    count[key] += 1

assert len(key_list) == N
answer_list = [0] * N
for i, key in enumerate(key_list):
    answer_list[i] = str(count[key])
print(' '.join(answer_list))


Measured memory_bytes: 163848
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        int cnt = 0;
        for (int i = 0; i < n; i++){
            int m = Integer.parseInt(br.readLine());
            if (isPrime(m)){
                cnt++;
            }
        }
        System.out.println(cnt);
    }
    static boolean isPrime(int q){
        if (q == 2) return true;
        if (q < 2 || ((q & 1) == 0)) return false;
        
        int i = 3;
        while (i * i <= q){
            if (q % i == 0){
                return false;
            }
            i++;
            if ((i & 1) == 0) i++;
        }
        return true;
        
    }
}

Measured memory_bytes: 22696
#include<bits/stdc++.h>
using namespace std;
#define intl long long int 

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	intl i,j,n;
	cin>>j>>n;
	vector<intl> ar(n);
	intl sum=0;
	for(i=0;i<n;i++){
		cin>>ar[i];
		sum+=ar[i];
	}
	if(sum>=j){
		cout<<"Yes\n";
	}
	else
		cout<<"No\n";
}


Measured memory_bytes: 1024
#include<stdio.h>
int main(){
    int inact[100][100];
    int act[100];
    int ans[100];
    int row, col;
    int i, j;
    for(i = 0;i < 100;i++){
        for(j = 0;j < 100;j++){
            inact[i][j] = 0;
        }
        act[i] = 0;
        ans[i] = 0;
    }
    scanf("%d %d", &row, &col);
    for(i = 0;i < row;i++){
        for(j = 0;j < col;j++){
            scanf("%d", &inact[i][j]);
        }
    }
    for(i = 0;i < col;i++){
        scanf("%d", &act[i]);
    }
    for(i = 0;i < row;i++){
        for(j = 0;j < col;j++){
            ans[i] += inact[i][j] * act[j];
        }
    }
    for(i = 0;i < row;i++){
        printf("%d\n", ans[i]);
    }
    return 0;
}


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

int main() {
 int n; cin >>n;
 string s; cin >> s;
 bool ans=1;
 if(n%2==1)cout << "No" << endl;
 else{
   for(int i=0;i<n/2;i++){
     if(s[i]!=s[n/2+i])ans=0;
   }
  if(ans)cout <<"Yes" << endl;
  else cout << "No" << endl;
  }


}


Measured memory_bytes: 256
n = gets.to_i
a = gets.chomp.split.map(&:to_i) + [0]
b = [0]
a.each{|x| b << x if x != b.last}

h = Hash.new{|h, k| h[k] = [0, 0]}
for x in 1...(b.length - 1)
    if b[x] > b[x - 1] && b[x] > b[x + 1]
        h[b[x]][0] += 1
    elsif b[x] < b[x - 1] && b[x] < b[x + 1]
        h[b[x]][1] += 1
    end
end
h.delete(0)

count, max = 0, 0
h.keys.sort.reverse_each{|k|
    count += h[k][0] - h[k][1]
    max = count if max < count
}
puts max


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

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);i--)
#define rrep(i,n) RFOR(i,n,0)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

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

	ll n;
	cin >> n;

	ll a[n][n];
	rep(i,n) rep(j,n) cin >> a[i][j];

	bool b[n][n] = {};

	ll sum = 0;
	FOR(i,0,n){
		FOR(j,i+1,n){
			sum += a[i][j];
		}
	}

	ll ans = 0;

	rep(k,n){
		rep(i,n){
			rep(j,n){
				if(k != i && i != j && j!= k) {
					if(a[i][j] > a[i][k] + a[k][j]){
						cout << -1 << endl;
						return 0;
					}else{
						if((a[i][j] == a[i][k] + a[k][j]) && (!b[i][j] || !b[j][i])){
							ans += a[i][j];
							b[i][j] = true;
							b[j][i] = true;
						}
					}
				}
			}
		}
	}
	
	cout << (sum - ans) << endl;
}

Measured memory_bytes: 1024
#include <iostream>
using ll = long long;
using namespace std;
/* initialize */

/* main */
int main() {
    int n,u,k, v;
    int A[100][100];
    cin >> n;
    for (int i = 0; i < n; ++i) for (int j = 0; j < n; ++j) A[i][j] = 0;
    for (int i = 0; i < n; ++i) {
        cin >> u >> k;
        for (int j = 0; j < k; ++j) {
            cin >> v;
            A[u-1][v-1] = 1;
        }
    }
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n-1; ++j) {
            cout << A[i][j] << " ";
        }
        cout << A[i][n-1] << "\n";
    }
    return 0;
}


Measured memory_bytes: 3128
S=list(str(input()))
T=list(str(input()))
ans=10000
for i in range(len(S)-len(T)+1):
    s=0
    for u in range(len(T)):
        if S[i+u]==T[u]:
            s+=1
            #print(s)
    s=len(T)-s
    ans=min(ans,s)
print(ans)

Measured memory_bytes: 65432
#include<iostream>
#include<map>
#define ll long long
using namespace std;
const int N=2e5+10;
map<string,int>m;
void io() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); }
int main(int argc, char const *argv[])
{
	io();
	int n;
	cin>>n;
	string temp;
	for(int i=0;i<n;i++)
	{
		cin>>temp;
		m[temp]++;
	}
	cout<<"AC x "<<m["AC"]<<endl;
	cout<<"WA x "<<m["WA"]<<endl;
	cout<<"TLE x "<<m["TLE"]<<endl;
	cout<<"RE x "<<m["RE"]<<endl;
	return 0;
}

Measured memory_bytes: 3200
#include<bits/stdc++.h>
using namespace std;
int n;
long long a[100100],mx=1e18;
int main(){
	#ifndef DavidLaptop
		#ifdef FILIN
			freopen(FILIN,"r",stdin);
			freopen(FILOUT,"w",stdout);
		#endif
	#endif
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	sort(a+1,a+n+1);
	if(a[1]==0){
		cout<<0<<endl;
		return 0;
	}
	for(int i=2;i<=n;i++){
		if(mx/a[i-1]<a[i]){
			cout<<-1<<endl;
			return 0;
		}
		a[i]*=a[i-1];
	}
	if(a[n]>1e18){
		cout<<-1<<endl;
		return 0;
	}
	cout<<a[n]<<endl;
	return 0;
}



Measured memory_bytes: 4400
#define _CRT_SECURE_NO_WARNINGS
//#define _USE_MATH_DEFINES
#include<stdio.h>
//#include<stdlib.h>
#include<math.h>
#include<string.h>
//#include<time.h>
#define P(type,x) fprintf(stdout,"%"#type"\n",x)
#define PI 4.0*atan(1.0)
double solve(int x);
int main() {
	int m, n;
	double ans1, ans2;
	while (~fscanf(stdin, "%d", &m), m) {
		ans1 = solve(m);
		fscanf(stdin, "%d", &n);
		ans2 = solve(n);
		if (ans1==ans2)  puts("0");
		else if (ans1>ans2) puts("1");
		else puts("2");
	}
	return 0;
}
double solve(int x) {
	int i;
	double ans = 0.0,tmp,theta = 360.0;
	for (i = 0; i<x - 1; i++) {
		fscanf(stdin, "%lf", &tmp);
		theta -= tmp;
		tmp = tmp*PI / 180.0;
		ans += (sin(tmp/2)*cos(tmp/2));
	}
	theta = PI*theta / 180.0;
	ans += sin(theta/2)*cos(theta/2);
	return ans;
}

Measured memory_bytes: 620
#include <stdio.h>

int main()
{
	int H, W, h, w;
	scanf("%d %d %d %d", &H, &W, &h, &w);
	if (H % h == 0 && W % w == 0) {
		printf("No\n");
		fflush(stdout);
		return 0;
	}
	
	int i, j, a[502][502], pos = 1 << 20, neg;
	if (H % h != 0) {
		neg = -((h - 1) * pos + 1);
		for (i = 1; i <= H; i++) {
			if (i % h == 0) for (j = 1; j <= W; j++) a[i][j] = neg;
			else for (j = 1; j <= W; j++) a[i][j] = pos;
		}
	} else {
		neg = -((w - 1) * pos + 1);
		for (j = 1; j <= W; j++) {
			if (j % w == 0) for (i = 1; i <= H; i++) a[i][j] = neg;
			else for (i = 1; i <= H; i++) a[i][j] = pos;
		}
	}
	
	printf("Yes\n");
	for (i = 1; i <= H; i++) {
		for (j = 1; j < W; j++) printf("%d ", a[i][j]);
		printf("%d\n", a[i][W]);
	}
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 3424
fn read<T: std::str::FromStr>(
    stdin_lock: &mut std::io::StdinLock,
    buf: &mut Vec<u8>,
    delimiter: u8,
) -> T {
    buf.clear();
    let l = std::io::BufRead::read_until(stdin_lock, delimiter, buf).unwrap();
    buf.truncate(l - 1); // remove delimiter
    let s = unsafe { std::str::from_utf8_unchecked(&buf) };
    s.parse().unwrap_or_else(|_| panic!("read"))
}

fn main() {
    let stdin = std::io::stdin();
    let mut stdin_lock = stdin.lock();
    let mut buf: Vec<u8> = Vec::new();
    let n: usize = read(&mut stdin_lock, &mut buf, b' ');
    let m: usize = read(&mut stdin_lock, &mut buf, b'\n');
    let mut xv = vec![0i32; m];
    for i in 0..m - 1 {
        xv[i] = read(&mut stdin_lock, &mut buf, b' ');
    }
    xv[m - 1] = read(&mut stdin_lock, &mut buf, b'\n');

    if n >= m {
        println!("{}", 0);
    } else {
        xv.sort();

        let mut yv = vec![0i32; m];
        yv[0] = 0;
        for i in 1..m {
            yv[i] = xv[i] - xv[i - 1];
        }
        yv.sort();

        let mut ans = 0;
        for i in 0..m - n + 1 {
            ans += yv[i];
        }
        println!("{}", ans);
    }
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#include <stdlib.h>
#include <stdio.h>

using namespace std;

const int Nmax = 1e5 + 5;
int N,S,Max,p;
int a[Nmax][3],dp[Nmax][3];

int main()
{
    scanf("%d",&N);
    for(int i = 1; i <= N; ++i)
    {
        scanf("%d%d%d", &a[i][0],&a[i][1], &a[i][2]);
        for(int j = 0; j < 3; ++j)
        {
            for(int k = 0; k < 3; ++k)
                if(j != k)
                    dp[i][j] = max(dp[i - 1][k],dp[i][j]);
            dp[i][j] += a[i][j];
        }
    }
    printf("%d",max({dp[N][0],dp[N][1],dp[N][2]}));
    /// cout << dp[N][0] << " " << dp[N][1] << " " << dp[N][2];
    return 0;
}


Measured memory_bytes: 2560
S = input()
if(S[0]=='A' and S[2:-1].count('C') == 1):
  cnt = 0
  for i in S:
    if(not (97<=ord(i) and ord(i)<=122)):
      cnt+=1
  if(cnt==2):
    print('AC')
  else:
    print('WA')
else:
  print('WA')


Measured memory_bytes: 2940
#include<stdio.h>
main()
{
    int a,b,c,x,y,z;
    scanf("%d%d%d",&a,&b,&c);
    z=(a>b)?((a>c)?a:c):((b>c)?b:c);
    x=(a>b)?((b>c)?c:b):((a>c)?c:a);
    y=(z==a)?((b>c)?b:c):((x==a)?((b>c)?c:b):a);
    printf("%d %d %d\n",x,y,z);
    return 0;
}



Measured memory_bytes: 2024
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define SUM(a)  accumulate((a).begin(),(a).end(),0)
#define SORT(a) sort(ALL(a))
#define REV(a) reverse(ALL(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
typedef long long ll;
const int INTINF = 1<<29;
const ll LLINF = 1LL<<61;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
const int DX[8]={ 0, 1, 0,-1, 1, 1,-1,-1};
const int DY[8]={ 1, 0,-1, 0, 1,-1, 1,-1};


int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  int a;
  cin >> n;
  int cnt = 0;
  REP(i,n){
    cin >> a;
    while (a%2==0){
        cnt++;
        a = a / 2;
    }
  }
  cout << cnt << endl;
}


Measured memory_bytes: 256
#include<stdio.h>

int main()
{
	char s[17];
	char *t= "CODEFESTIVAL2016";
	int i,count=0;

	scanf("%s", s);

	for (i = 0; i < 16; i++) {
		if (s[i] != t[i])count++;
	}
	printf("%d", count);
	return 0;

}

Measured memory_bytes: 128
/*
 #pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
*/
#pragma GCC optimize("O3")
#pragma GCC target ("sse4")

#define NDEBUG
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <cstring>
#include <vector>
#include <map>
#include <cmath>
#include <climits>
#include <list>
#include <functional>
#include <numeric>

//find out the use of the below
#include <utility>
#include <sstream>
#include <iomanip>
#include <cstdlib>
#include <ctime>
#include <memory.h>
#include <cassert>

using namespace std;
//using namespace __gnu_pbds;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> set_t;
#define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define mp(a,b) make_pair((a),(b))
#define pii pair<int,int>
#define pll pair<LL,LL>
#define pdd pair<double,double>
#define pb push_back
#define x first
#define y second
#define sqr(x) ((x)*(x))
#define PQ(T) priority_queue<T,vector<T>,greater<T> >
#define EPS 1e-6
#define MEM(x) memset(x,0,sizeof(x))
#define MEMS(x) memset(x,-1,sizeof(x))
#define PI acos(-1)
bool cmp(const pii& a, const pii& b){
    return atan2(a.y, a.x) < atan2(b.y, b.x);
}
int main(){
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt","w", stdout);
    fio;
    int n;
    cin >> n;
    vector<pii> en(n, mp(0,0));
    for (int i = 0; i < n; ++i){
        cin >> en[i].x >> en[i].y;
    }
    sort(en.begin(), en.end(), cmp);
    long long ansq = 0;
    for (int i = 0; i < n; ++i){
        long long tx = en[i].x, ty = en[i].y;
        for (int tj = i+1; tj <= i+n-1; ++tj){
            int j = tj%n;
            ansq = max(ansq, tx*tx + ty*ty);
            tx += en[j].x;
            ty += en[j].y;
        }
        ansq = max(ansq, tx*tx + ty*ty);
    }
    cout << setprecision(12) << sqrt((long double)ansq);
    return 0;
} /* BEFORE submitting, check for:
 *  1. Integer overflow
 *  2. Float/Double precision errors
 *  3. Array index out of bounds
 *  4. Edge cases.(n=1, n=max, etc.)
 *  5. Time complexity. No TLEs
 */



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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;

const ll LongINF=1e13+7;
const int INF=1e9+7;
const int dx[]={0,1,0,-1};
const int dy[]={1,0,-1,0};

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;}
template <class T, class Y>T GCD(T a, Y b){if(a<b){int c=a;a=b;b=c;}if (a % b == 0){return b;}return GCD(b, a % b);}
template<class T,class Y>T LCM(T a,Y b){return (a*b)/GCD(a,b);}
void clear(queue<pair<int, int>> &q){queue<pair<int, int>> empty;swap(q, empty);} //queueの中身の型は適時変更を忘れない

using vi=vector<int>;
using vii=vector<vi>;

#define REP(i,a,b) for(ll i=(a);i<(b);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define rv reverse
#define ALL(a) (a).begin(),(a).end()
#define decimal(x) fixed<<setprecision(x)


int main(){
    ll n,m;
    cin>>n;
    m=n;
    map<ll,int> mp;
    for(ll i=2;i*i<=m;i++){
        while(n%i==0){
            n/=i;
            mp[i]++;
        }
    }
    if(n!=1){
        mp[n]++;
    }
    ll cnt=0;
    for(auto x:mp){
        ll y=x.second;
        //cout<<x.first<<" "<<y<<endl;
        ll i=1;
        while(y>=i){
            y-=i;
            cnt++;
            i++;
        }
    }
    if(m==1){
        cout<<0<<endl;
        return 0;
    }
    if(cnt==0)cnt++;
    cout<<cnt<<endl;
    return 0;
}

//a=97,z=122

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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 ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

#define INF 1e15

#define restorej(i,j) ((i)/2+(j)-1)
#define DP(i,j) (((j)-(i)/2+1>2)?-INF:dp[i][(j)-(i)/2+1])

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin>>n;
    vll a(n);
    rep(i,n) cin>>a[i];
    vector<vll> dp(n+1,vll(3,-INF));
    dp[0][1] = 0;
    dp[1][1] = 0, dp[1][2] = a[0];
    FOR(i,2,n)rep(j,3){
        int rj = restorej(i,j);
        dp[i][j] = max(DP(i-1,rj), DP(i-2,rj-1)+a[i-1]);
    }
    cout<<dp[n][1]<<"\n";
    return 0;
}


Measured memory_bytes: 15836
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Security.Principal;
using System.Text;
class Simple{
    private long N;
    private long[] a, b;
    void Solve(){
        //input
        N = io.Int;
        a = new long[N];
        b = new long[N];
        for(int i = 0; i < N; ++i){
            a[i] = io.Int;
            b[i] = io.Int;
        }
        //cal
        var cnt = 0L;
        var revA = a.Reverse().ToArray();
        var revB = b.Reverse().ToArray();
        for(int i = 0; i < N; ++i){
            while((revA[i] + cnt) % revB[i] != 0) cnt += revB[i] * ((revA[i] + cnt) / revB[i] + 1) - (revA[i] + cnt);
        }
        //ret
        Console.WriteLine(cnt);
    }
    SimpleIO io = new SimpleIO();
    public static void Main(string[] args) { new Simple().Stream(); }
    void Stream(){
        Solve();
        io.writeFlush();
    }
}
class SimpleIO{
    string[] nextBuffer;
    int BufferCnt;
    char[] cs = new char[]{' '};
    StreamWriter sw = new StreamWriter(Console.OpenStandardOutput()){AutoFlush = false};
    public SimpleIO(){
        nextBuffer = new string[0];
        BufferCnt = 0;
        Console.SetOut(sw);
    }
    public string Next(){
        if(BufferCnt < nextBuffer.Length) return nextBuffer[BufferCnt++];
        string st = Console.ReadLine();
        while(st == "") st = Console.ReadLine();
        nextBuffer = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        BufferCnt = 0;
        return nextBuffer[BufferCnt++];
    }
    public string String => Next();
    public char Char => char.Parse(String);
    public int Int => int.Parse(String);
    public long Long => long.Parse(String);
    public double Double => double.Parse(String);
    public void writeFlush() { Console.Out.Flush(); }
}


Measured memory_bytes: 23500
#include <bits/stdc++.h>
using namespace std;
#define ll long long int 
#define ar array
const ll mod = 1e9 + 7;
int main() {
	// your code goes here
	int n;
    cin >> n;
    vector<ll> a(n);
    for (ll &x : a) cin >> x;
    vector<vector<ar<ll, 2>>> dp(n, vector<ar<ll, 2>>(n));
    for (int i = 0; i < n; ++i) {
        dp[i][i][0] = a[i];
        dp[i][i][1] = 0;
    }
    for (int Rminus = 1; Rminus < n; ++Rminus) {
        for (int L = 0; L + Rminus < n; ++L) {
            int R = L + Rminus;
            dp[L][R][0] = max(dp[L + 1][R][1] + a[L], dp[L][R - 1][1] + a[R]);
            dp[L][R][1] = min(dp[L + 1][R][0], dp[L][R - 1][0]);
            
        }


    }
    ll ans = 2 *  dp[0][n - 1][0] - accumulate(a.begin(), a.end(), 0LL);
    cout << ans;



	return 0;
}


Measured memory_bytes: 143960
#include <stdio.h>

int main(void)
{
	int h[10], n, fir = 0, sec = 0, thi = 0;
	for (n = 0; n <= 9; n++){
		scanf("%d", &h[n]);
		if (h[n] >= fir){
			thi = sec;
			sec = fir;
			fir = h[n];
		} else if (h[n] >= sec){
			thi = sec;
			sec = h[n];
		} else if (h[n] >= thi){
			thi = h[n];
		}
	}
	printf("%d\n%d\n%d\n", fir, sec, thi);
	return 0;
}

Measured memory_bytes: 600
import java.util.*;

public class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] X = new int[N];
		for(int i = 0; i < N; i++){
			X[i] = sc.nextInt();
		}
		
		int sum = 0;

		for(int i = 0; i < N - 1; i++){
			for(int j = i + 1; j < N; j++){
				sum += X[i] * X[j];
			}
		}
		System.out.println(sum);
	}
}


Measured memory_bytes: 21972
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>

class union_find {
public:
    union_find(int n)
        : par_(n, -1)
    {}
    void init(int n) {
        par_.assign(n, -1);
    }

    int root(int x) {
        return par_[x] < 0 ? x : par_[x] = root(par_[x]);
    }

    bool unite(int x, int y) {
        x = root(x); y = root(y);
        if(x == y) {
            return false;
        } else {
            if(par_[x] < par_[y]) {
                par_[x] += par_[y];
                par_[y] = x;
            } else {
                par_[y] += par_[x];
                par_[x] = y;
            }
            return true;
        }
    }

    bool same(int x, int y) {
        return root(x) == root(y);
    }

    int size(int x) {
        return -par_[root(x)];
    }

private:
    std::vector<int> par_;
};

int main()
{
  typedef std::pair<int,std::pair<int,int> > bridge;
  int n,m;
  while (true) {
    std::cin >> n >> m;
    if (n==0 && m==0) {
      break;
    }
    int totalcost = 0;
    std::vector<bridge> bridges(m);
    for (int i = 0; i < m; i++) {
      int a,b,cost;
      std::cin >> a >> b >> cost;
      bridges[i] = bridge(cost,std::make_pair(a,b));
    }
    std::sort(bridges.begin(),bridges.end());
    union_find reachable(n);
    for (int i = 0; i < m; i++) {
      if (!(reachable.same(bridges[i].second.first,bridges[i].second.second))) {
	totalcost += bridges[i].first;
	reachable.unite(bridges[i].second.first,bridges[i].second.second);
      }
    }
    std::cout << totalcost << std::endl;
  }
}

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

int main() {
  double a, b, x;
  cin >> a >> b >> x;
  double s = x / a;
  double rad;
  if (s >= a * b / 2) {
    double h = (a * b - s) * 2 / a;
    rad = atan2(h, a);
  } else {
    double w = s * 2 / b;
    rad = atan2(b, w);
  }
  double PI = acos(-1);
  double deg = rad / PI * 180;
  printf("%.10f\n", deg);
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define INF 0x3f3f3f3f
using namespace std;
const int maxn = 1e3;
string s;

void read()
{
    cin >> s;
}

void solve()
{
    for(int i = 0; i < s.length(); ++i)
        if((i%2 && s[i] == 'R') || (!(i%2) && s[i] == 'L'))
        {
            cout << "No" << endl;
            return;
        }
    cout << "Yes" << endl;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    read();
    solve();
    return 0;
}


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

using namespace std;

int main() {
    ios::sync_with_stdio(false);

    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;

    cout << n - max(int(unique(s.begin(), s.end()) - s.begin()) - 2 * k, 1) << endl;

    return 0;
}


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

using namespace std;

inline void init()
{
    int a,b;
    cin >> a >> b;
    if(a<b)
        cout << 0;
    else
        cout << 10;
    cout << endl;
}

inline void solve()
{

}

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


Measured memory_bytes: 256
#include <stdio.h>

int main() {
    int N, A[100], minj, change, count = 0;
    int i, j;
    
    scanf("%d", &N);
    
    for (i = 0; i < N; i++) {
        scanf("%d", &A[i]);
    }
    
    for (i = 0; i < N - 1; i++) {
        minj = i;
        
        for (j = i; j < N; j++) {
            if (A[j] < A[minj]) {
                minj = j;
            }
        }
        
        if (A[minj] < A[i]) {
            change = A[i];
            A[i] = A[minj];
            A[minj] = change;
            
            count++;
        }
    }
    
    for (i = 0; i < N; i++) {
        if (i > 0) {
            printf(" ");
        }
        
        printf("%d", A[i]);
    }
    
    putchar('\n');
    
    printf("%d\n", count);
    
    return 0;
}



Measured memory_bytes: 2088
#include<bits/stdc++.h>
using namespace std;
int min(int x,int y)
{
	return (x>=y)?y:x;
}
int main()
{
	int n,k,h[100005]={0},result[100005]={0},i,j;
	cin>>n>>k;
	for(i=0;i<n;i++)
		cin>>h[i];
	for(i=1;i<n;i++)
	{
		result[i]=INT_MAX;
		for(j=i-1;j>=0&&j>=i-k;j--)
		{
			result[i]=min(result[j]+abs(h[j]-h[i]),result[i]);
		}
	}
	cout<<result[n-1];
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define MOD 1000000007
#define SIZE 123456
 
using namespace std;
typedef long long ll;

int N;
int A[SIZE],B[SIZE];
ll ans;

int main(){

cin>>N;
for(int i=0; i<N; i++) scanf("%d",&A[i]);

if(N%2==0){
    for(int i=0; i<N; i++){
        if(A[i]%2==0){
            cout<<0<<endl;
            return 0;
        }else{
            B[A[i]]++;
        }
    }
    for(int i=1; i<N; i++){
        if(i%2==1){
            if(B[i]!=2){
                cout<<0<<endl;
                return 0;
            }
        }
    }
    ans=1LL;
    for(int i=0; i<N/2; i++){
        ans=ans*2%MOD;
    }
    cout<<ans<<endl;
}else{
    for(int i=0; i<N; i++){
        if(A[i]%2==1){
            cout<<0<<endl;
            return 0;
        }else{
            B[A[i]]++;
        }
    }
    for(int i=0; i<N; i++){
        if(i%2==0){
            if(i==0){
                if(B[i]!=1){
                cout<<0<<endl;
                return 0;
                }
            }
            if(i!=0&&B[i]!=2){
                cout<<0<<endl;
                return 0;
            }
        }
    }
    ans=1LL;
    for(int i=0; i<N/2; i++){
        ans=ans*2%MOD;
    }
    cout<<ans<<endl;
}


return 0;
 
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define loop(n) for (int ngtkana_is_a_genius = 0; ngtkana_is_a_genius < int(n); ngtkana_is_a_genius++)
#define rep(i, begin, end) for (int i = int(begin); (i) < int(end); i++)
#define all(v) v.begin(), v.end()
#define rand(l, r) std::uniform_int_distribution<>(l, r)(mt)
using lint = long long;
auto mt = std::mt19937_64(std::random_device{}());
auto cmn = [](auto& a, auto b){ if (a > b) {a = b; return true;} return false; };
auto cmx = [](auto& a, auto b){ if (a < b) {a = b; return true;} return false; };
void debug_impl() { std::cerr << std::endl; }
template <typename Head, typename... Tail>
void debug_impl(Head head, Tail... tail) { std::cerr << " " << head; debug_impl(tail...); }
#ifndef STOPIT
#define debug(...)\
  do {\
    std::cerr << std::boolalpha << "[" << #__VA_ARGS__ << "]:";\
    debug_impl(__VA_ARGS__);\
    std::cerr << std::noboolalpha;\
  } while (false)
#else
#define debug(...) {}
#endif

void err() { std::cout << "Impossible" << std::endl; exit(0); }
#define require(exp) do { if (!(exp)) { err(); } } while(false)

bool query(int a, int b) {
  std::cout << "? " << a << " " << b << std::endl;
  char c; std::cin >> c;
  return c == 'Y';
}

void answer(std::vector< int > ans) {
  std::cout << "!" << " ";
  for (int x : ans) std::cout << x;
  std::cout << std::endl;
}

int main() {
  std::cin.tie(0); std::cin.sync_with_stdio(false);
  int A, B; std::cin >> A >> B;
  if (A <= B) err();
  int n = A + B;
  std::vector< int > chain;
  rep(i,0,n) {
    if (chain.empty()) {
      chain.emplace_back(i);
      continue;
    }
    bool res = query(chain.back(), i);
    if (res) {
      chain.emplace_back(i);
    } else {
      A--,B--;
      chain.pop_back();
    }
  }
  assert((B+1) <= (int)chain.size());
  int pivot = chain.back();
  std::vector< int > ans(n, true);
  rep(i,0,n) {
    if (i == pivot) continue;
    ans.at(i) = query(pivot, i);
  }
  answer(ans);
  return 0;
}


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

#define int long long
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(int i=0; i<(int)n; i++)
#define ll long long
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define COUT(x) cout<<x<<endl;
#define PB(x) push_back(x)
#define MP make_pair
int gcd(int a,int b){return b?gcd(b,a%b):a;}
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int INF = 1e9;
const int MOD = 1e9+7;

signed main(){
    int a[3][3];
    rep(i,3)rep(j,3)cin>>a[i][j];
    int n; cin>>n;
    int b[n];
    rep(i,n) cin >> b[i];
    bool hit[3][3];
    rep(i,3)rep(j,3)hit[i][j]=false;
    rep(i,3){
        rep(j,3){
            rep(k,n){
                if(a[i][j]==b[k]) hit[i][j]=true;
            }
        }
    }
    bool can=false;
    rep(i,3){
        if(hit[i][0]&&hit[i][1]&&hit[i][2]) can=true;
        if(hit[0][i]&&hit[1][i]&&hit[2][i]) can=true;
    }
    
    if(hit[0][0]&&hit[1][1]&&hit[2][2]) can=true;
    if(hit[0][2]&&hit[1][1]&&hit[2][0]) can=true;


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

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;
int n, w[301000];
long long s;
int main(){
    int i, c;
    scanf("%d",&n);
    n*=3;
    for(i=1;i<=n;i++)scanf("%d",&w[i]);
    sort(w+1,w+n+1);
    for(i=n-1,c=0;c<n/3;i-=2,c++)s += w[i];
    printf("%lld\n",s);
}

Measured memory_bytes: 1408
ary = gets.chomp.split("")
t = 0
res = 0
ary.each do |a|
  if ['A', 'C', 'G', 'T'].include?(a)
    t += 1
    res = t if t > res
  else
    res = t if t > res
    t = 0
  end
end

puts res


Measured memory_bytes: 1788
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <queue>
using namespace std;

#define LL long long

const int MAXN = 200000 + 5;


int main()
{
    int N, ans;
    LL D, X, Y;
    cin >> N >> D;
    ans = 0;
    while (N --){
        cin >> X >> Y;
        if (X * X + Y * Y <= D * D){
            ans ++;
        }
    }
    cout << ans;
    system("pause");
    return 0;
}

Measured memory_bytes: 3732
#include <algorithm>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
#define fst first
#define snd second
using ll = long long;
using I = pair<int, int>;

int main() {
  int N;
  ll K;
  while (cin >> N >> K) {
    map<ll, ll> mp;
    for (int i = 0; i < N; i++) {
      ll a, b;
      cin >> a >> b;
      mp[a] += b;
    }
    ll sum = 0;
    for (auto& e : mp) {
      sum += e.second;
      if (sum >= K) {
        cout << e.first << endl;
        break;
      }
    }
  }
  return 0;
}


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

int search(int n,int a[],int key) {
    a[n]=key;
    int i=0;
    while(a[i]!=key) {
        i++;
        if(i==n) return n;
    }
    return i;
}

int main() {
    int n;cin>>n;
    int a[10001];
    for(int i=0;i<n;i++) {
        cin>>a[i];
    }
    int q;cin>>q;
    int ans=0;
    for(int i=0;i<q;i++) {
        int x;cin>>x;
        if(search(n,a,x)!=n) {
            ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3104
// abc128_e
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

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

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF ((1 << 29)-1)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;

struct Kouji {
    int s, t, x;
    bool operator<(const Kouji& other) { return s < other.s; }
};
ostream& operator <<(ostream& os, Kouji p) { return os << "(" << p.s << ", " << p.t << ", " << p.x << ")"; }

int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif

    int N, Q;
    cin >> N >> Q;

    vector<Kouji> koujis(N);
    REP(i, N) {
        cin >> koujis[i].s >> koujis[i].t >> koujis[i].x;
        koujis[i].s -= koujis[i].x;
        koujis[i].t -= koujis[i].x;
    }
    sort(ALL(koujis), [](const Kouji& a, const Kouji& b) { return a.s < b.s; });

    vector<int> D(Q);
    REP(i, Q) cin >> D[i];
    sort(ALL(D));

    auto comp = [](const Kouji& a, const Kouji& b) { return a.x > b.x; };
    priority_queue<Kouji, vector<Kouji>, decltype(comp)> pq(comp);

    int kouji_idx = 0;
    REP(i, Q) {
        int d = D[i];

        for (; kouji_idx < N; kouji_idx++){
            if (d < koujis[kouji_idx].s) {
                break;
            }
            pq.push(koujis[kouji_idx]);
        }

//        auto tmp = pq;
//        cout << kouji_idx << ", "; while (!tmp.empty()) {cout << tmp.top() << " "; tmp.pop();} print("");

        while (!pq.empty()) {
            Kouji tp = pq.top();
            if (d < tp.t) {
                print(tp.x); break;
            } else {
                pq.pop();
            }
        }

        if (pq.empty()) {
            print(-1);
        }
    }

    return 0;
}


Measured memory_bytes: 8180
#include <bits/stdc++.h>
#define ii pair<int,int>

using namespace std;

int main() {
#ifdef _DEBUG
	freopen("_in" , "r", stdin );
	freopen("_out", "w", stdout);
#endif
	int n; cin >> n;
	vector<ii> v(n);
	for (int i = 0; i < n; i++) {
		int t; cin >> t;
		v[i].first = t;
		v[i].second = i + 1;
	}
	sort(v.begin(), v.end());
	for (int i = 0; i < n; i++) {
		cout << v[i].second << ' ';
	}
}


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

int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
   	int n,k,x,y;cin>>n>>k>>x>>y;
	if(n>k){
        cout << (n-k)*y + k*x;
        return 0;
    }
    cout << n*x;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
	
	int a, b;
	
	while (true) {
		cin >> a >> b;

		if (a == 0 || b == 0) break;

		for (int i = 0; i < a; i++)	{
			for (int j = 0; j < b; j++)	{
				cout << '#';
			}
			cout << endl;
		}
		cout << endl;
	}

	return 0;
}


Measured memory_bytes: 3104
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <functional>
#include <bitset>
#include <cmath>
#include <stack>
#include <iomanip>
#include <map>
#include <math.h>
#include <list>
#include <deque>
typedef long long ll;
using namespace std;
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 int MOD = 1000000007;
const ll INF = 1LL << 60;

ll GCD(ll a, ll b) { return b ? GCD(b, a%b) : a; }
ll LCM(ll a, ll b) {return a / GCD(a, b) * b;}

ll facctorialMethod(ll k){
    ll sum = 1;
    for (int i = 1; i <= k; ++i)
    {
        sum *= i;
		sum %= MOD;
    }
    return sum;
}

int main()
{
	int N,M;
	cin >> N >> M;
	if(abs(N - M) > 1)
	{
		cout << 0 << endl;
		return(0);
	}
	ll a,b;
	a = facctorialMethod(N);
	b = facctorialMethod(M);
	ll ans = a * b % MOD;
	if(N == M) ans = ans * 2 % MOD;
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int lint
typedef long long lint;
typedef pair<int,int> P;
const int    INF=(int)1e9;
const int    MOD=(int)1e9+7;
const double EPS=(double)1e-10;
struct Accelerate_Cin{
    Accelerate_Cin(){
        cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);
    };
};

struct edge{
  int to,cost;
};

int N,M;
vector<edge>E[200010];
vector<edge>EE[200010];
int vis[200010],col[200010];

bool bfs(){
  for(int i=0;i<N;i++){
    if(!vis[i]){
      col[i]=0;
      vis[i]=1;
      queue<int>que;
      que.push(i);
      while(!que.empty()){
        int q=que.front();que.pop();

        for(auto p : E[q]){
          if(vis[p.to]){
            if(col[q]+p.cost!=col[p.to])return false;
          }else{
            col[p.to]=col[q]+p.cost;
            vis[p.to]=1;
            que.push(p.to);
          }
        }

        for(auto p : EE[q]){
          if(vis[p.to]){
            if(col[q]-p.cost!=col[p.to])return false;
          }else{
            col[p.to]=col[q]-p.cost;
            vis[p.to]=1;
            que.push(p.to);
          }
        }

      }
    }
  }

  return true;
}

signed main(){
  cin>>N>>M;
  for(int t=0;t<M;t++){
    int a,b,c;
    cin>>a>>b>>c;
    a--;b--;
    edge temp1={b,c};
    edge temp2={a,c};
    E[a].push_back(temp1);
    EE[b].push_back(temp2);
  }

  if(bfs()){
    cout<<"Yes"<<"\n";
  }else{
    cout<<"No"<<"\n";
  }
  return 0;
}


Measured memory_bytes: 22528
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        n: usize,
        mut L: [usize; n]
    }

    L.sort();
    let mut ans = 0;
    for i in 0..n {
        for j in i+1..n {
            for k in j+1..n {
                 if L[i] + L[j] > L[k] && L[i] != L[j] && L[j] != L[k] && L[k] != L[i] {
                     ans += 1;
                }
            }
        }
    }

    println!("{}", ans);


}


Measured memory_bytes: 2184
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define i_7 (ll)(1E9+7)
#define i_5 (ll)(1E9+5)
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    else return c+i_7;
}
typedef pair<int,int> i_i;
typedef pair<ll,ll> l_l;
ll inf=(ll)1E12;//10^12
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
const double EPS=1E-8;
////////////////////////////////////////


int calc(vector<int>s,vector<int>t){
    vector<int>v;
    for(auto x:s)v.pb(x);
    for(auto x:t)v.pb(x);
    sort(v.begin(),v.end());
    int n=v.size();
    int res=v[1]-v[0];
    rep(i,1,n-2)res=min(res,v[i+1]-v[i]);
    return res;
}

int main() {
    ios::sync_with_stdio(false);cin.tie(0);
    
    int n;cin>>n;
    int d[n];rep(i,0,n-1)cin>>d[i];
    int t[13];memset(t,0,sizeof(t));
    t[0]=1;
    rep(i,0,n-1)t[d[i]]++;
    vector<int>time;time.pb(24);
    vector<int>search;
    rep(i,0,12){
        if(i==0||i==12){
            if(t[i]>=2){
                cout<<0<<endl;
                return 0;
            }else if(t[i]==1){
                time.pb(i);
            }
        }else{
            if(t[i]>=3){
                cout<<0<<endl;
                return 0;
            }else if(t[i]==2){
                time.pb(i);time.pb(24-i);
            }else if(t[i]==1){
                search.pb(i);
            }
        }
    }
    int m=search.size();
    int ans=0;
    rep(i,0,(1<<m)-1){
        vector<int>u;
        rep(j,0,m-1){
            if((i>>j)&1){
                u.pb(search[j]);
            }else{
                u.pb(24-search[j]);
            }
        }
        ans=max(ans,calc(time,u));
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256