akhauriyash/Code-Regression huggingface dataset:
package main

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

var sc = bufio.NewScanner(os.Stdin)

func scanInt() int {
	num, _ := strconv.Atoi(scanString())
	return num
}

func scanString() string {
	sc.Scan()
	return sc.Text()
}

func init() {
	sc.Split(bufio.ScanWords)
}

func main() {
	n := scanInt()
	ds := NewDisjointSets()
	for i := 0; i < n; i++ {
		ds.MakeSet(i)
	}
	w := bufio.NewWriter(os.Stdout)
	q := scanInt()
	for i := 0; i < q; i++ {
		com := scanInt()
		x, y := scanInt(), scanInt()
		switch com {
		case 0:
			ds.Union(x, y)
		case 1:
			if ds.FindSet(x) == ds.FindSet(y) {
				fmt.Fprintln(w, 1)
			} else {
				fmt.Fprintln(w, 0)
			}
		}
	}
	w.Flush()
}

type DisjointSets struct {
	ranks map[int]int
	p     map[int]int
}

func NewDisjointSets() *DisjointSets {
	return &DisjointSets{make(map[int]int), make(map[int]int)}
}

func (d *DisjointSets) MakeSet(x int) {
	d.p[x] = x
	d.ranks[x] = 0
}

func (d *DisjointSets) Link(x, y int) {
	if d.ranks[x] > d.ranks[y] {
		d.p[y] = x
	} else {
		d.p[x] = y
		if d.ranks[x] == d.ranks[y] {
			d.ranks[y] += 1
		}
	}
}

func (d *DisjointSets) FindSet(x int) int {
	if x != d.p[x] {
		d.p[x] = d.FindSet(d.p[x])
	}
	return d.p[x]
}

func (d *DisjointSets) Union(x, y int) {
	d.Link(d.FindSet(x), d.FindSet(y))
}



Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
int main(){
  string S;
  cin >> S;
  int s = S.size();
  int ans = s;
  for(int i=0; i<s-1; i++){
    if(S[i] != S[i+1]){
      ans = min(ans,max(i+1,s-i-1));
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,Q,K,A,B;
string S;
//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
typedef pair<ll, ll> P;
const ll INF = (1LL<<57);

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

bool palindrome(string &s){
    int len = s.size();
    rep(i, len / 2) if(s[i] != s[len - 1 - i]) return false;
    return true;
}

bool suffix(string &s, string &t, string &rest, bool &flag){
    bool res = false;
    flag = s.size() < t.size();
    if(flag) swap(s, t);
    if(equal(t.rbegin(), t.rend(), s.rbegin())){
        res = true;
        rest = s.substr(0, s.size() - t.size());
        if(!flag) reverse(ALL(rest));
    }
    if(flag) swap(s, t);
    return res;
}

bool prefix(string &s, string &t, string &rest, bool &flag){
    bool res = false;
    flag = s.size() < t.size();
    if(flag) swap(s, t);
    if(equal(t.begin(), t.end(), s.begin())){
        res = true;
        rest = s.substr((int)t.size());
        if(!flag) reverse(ALL(rest));
    }
    if(flag) swap(s, t);
    return res;
}

int main() {
    cin>>N;
    vector<string> s(N);
    vec c(N);
    rep(i,N) cin>>s[i]>>c[i];
    using Psb = pair<string, bool>;
    using lp = pair<ll, Psb>;
    map<Psb, ll> dist;
    priority_queue<lp, vector<lp>, greater<lp> > pque;
    rep(i,N) {
        pque.emplace(c[i], make_pair(s[i], true));
        dist[Psb(s[i], true)] = c[i];
    }
    while(!pque.empty()){
        lp p = pque.top();
        pque.pop();
        if(palindrome(p.se.fi)){
            cout<<p.fi<<endl;
            return 0;
        }
        if(dist[p.se] < p.fi) continue;

        reverse(ALL(p.se.fi));

        if(p.se.se){
            rep(i,N){
                string res;
                bool rev;
                if(suffix(p.se.fi, s[i], res, rev)){
                    Psb key = make_pair(res, !rev);
                    ll &comp = dist[key];
                    if(comp == 0 || comp > p.fi + c[i]){
                        comp = p.fi + c[i];
                        pque.emplace(comp, key);
                    }
                }
            }
        }else{
            rep(i,N){
                string res;
                bool rev;
                if(prefix(p.se.fi, s[i], res, rev)){
                    Psb key = make_pair(res, rev);
                    ll &comp = dist[key];
                    if(comp == 0 || comp > p.fi + c[i]){
                        comp = p.fi + c[i];
                        pque.emplace(comp, key);
                    }
                }
            }
        }
    }
    cout<<-1<<endl;
}

Measured memory_bytes: 3712
import itertools

n = int(input())

dic = {}


for val in range(n):
    a = int(input())
    h_L = []
    for _ in range(a):
        a1,a2 = list(map(int,input().split()))
        tmp = [a1-1,a2]
        h_L.append(tmp)
    dic[val] = h_L

ans = []
#print(dic)

bit = itertools.product([0,1],repeat=n)
#bit = [(1,1,0)]
for val in bit:
    flag = True
    for i,katei in enumerate(val):
        if katei == 0:
            continue
        if katei == 1:
            for hatsugen in dic[i]:
                #print(i,hatsugen)
                if hatsugen[1] != val[hatsugen[0]]:
                    flag = False
                    #print("aaa",i,hatsugen[1],val[hatsugen[0]])
    if flag is True:
        ans.append(sum(val))

print(max(ans))
                

Measured memory_bytes: 42332
#include <iostream>
#include <set>
#include <string>

int main(){
	int n;
	std::set<std::string> w;
	scanf("%d", &n);
	std::string hoge;
	std::cin >> hoge;
	w.insert(hoge);
	for(int i = 1; i < n; ++i){
		std::string tmp;
		std::cin >> tmp;
		if(w.count(tmp) || tmp[0] != hoge[hoge.length() - 1]){
			std::cout << "No" << std::endl;
			return 0;
		}else{
			w.insert(tmp);
			hoge = tmp;
		}
	}
	std::cout << "Yes" << std::endl;
}


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

const char NL = '\n';
const int MOD = 1e9 + 7;

void solve()
{
    int x; cin >> x;
    cout << (x >= 30 ? "Yes" : "No"); 
}

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

Measured memory_bytes: 3648
#include <iostream>

using namespace std;

void call(int n)
{
    int x;
    for (int i = 1; i <= n; i++)
    {
        x = i;
        if (x % 3 == 0)
        {
            cout << " " << i;
            continue;
        }
        while (true)
        {
            if (x % 10 == 3)
            {
                cout << " " << i;
                break;
            }
            x /= 10;
            if (x == 0)
            {
                break;
            }
        }
    }
    cout << endl;
}

int main()
{
    int h;
    while (cin >> h)
    {
        call(h);
    }
}

Measured memory_bytes: 3080
import sys
sys.setrecursionlimit(10 ** 6)
def calc(a, n, m, arr):
    if len(a) == n:
        val = 0
        for p, q, c, d in arr:
            if a[p-1] + c == a[q-1]:
                val += d
        return val
    else:
        val = 0
        for i in range(a[-1], m+1):
            a.append(i)
            val = max(val, calc(a, n, m, arr))
            a.pop(-1)
        return val

def main():
    n, m, q = map(int, input().split())
    arr = [list(map(int, input().split())) for _ in range(q)]
    a = [1]
    print(calc(a, n, m, arr))

if __name__ == "__main__":
    main()

Measured memory_bytes: 9168
#include<bits/stdc++.h>
using namespace std;
double ans=0;
int main()
{
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        double a;string b;
        cin>>a>>b;
        if(b=="JPY") ans+=a;
        else ans+=380000*a;
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using ld = long double;

const int mod = 1e9 + 7;

ll binpow(ll a, int p) {
	ll res = 1;
	while (p) {
		if (p & 1) {
			(res *= a) %= mod;
		}
		p >>= 1;
		(a *= a) %= mod;
	}
	return res;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	ll n;
	cin >> n;
	int ans = 0;
	for (ll i = 2; i * i <= n; i++) {
		int kek = 0;
		int cnt = 0;
		while (n % i == 0) {
			cnt++;
			n /= i;
			if (cnt > kek) {
				ans++;
				kek = cnt;
				cnt = 0;
			}
		}
	}
	cout << ans + (n > 1) << endl;
	return 0;
}


Measured memory_bytes: 3652
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <unordered_map>
#include <set>
#include <vector>

using namespace std;

constexpr static int MAXN = 2e5;

int n;
int x[MAXN], y[MAXN];
unordered_map <int, vector <int>> xval, yval;

int64_t total = 0;
int p[MAXN], r[MAXN];

int f(int a) {
    if (p[a] != a)
        p[a] = f(p[a]);
    return p[a];
}

void merge(int a, int b) {
    int ar = f(a);
    int br = f(b);
    if (ar == br)
        return;
    if (r[ar] < r[br])
        p[ar] = br;
    else if (r[ar] > r[br])
        p[br] = ar;
    else {
        p[br] = ar;
        r[ar] = r[ar] + 1;
    }
    total += min(abs(x[a] - x[b]), abs(y[a] - y[b]));
}

void add_edge(int u, int v) {
    if (f(u) == f(v))
        merge(u, v);
}

int main() {
    cin >> n;
    set <int> xs, ys;
    for (int i = 0; i < n; i++) {
        cin >> x[i] >> y[i];
        xs.insert(x[i]);
        ys.insert(y[i]);
        xval[x[i]].push_back(i);
        yval[y[i]].push_back(i);
    }
    vector <int> xv(xs.begin(), xs.end());
    vector <int> yv(ys.begin(), ys.end());

    vector <pair <int, pair <int, int>>> edges;
    for (int i = 0; i + 1 < xv.size(); i++)
        edges.push_back({xv[i + 1] - xv[i], {i, 0}});
    for (int i = 0; i + 1 < yv.size(); i++)
        edges.push_back({yv[i + 1] - yv[i], {i, 1}});
    sort(edges.begin(), edges.end());

    for (int i = 0; i < n; i++) {
        p[i] = i;
        r[i] = 0;
    }
    for (auto& kv : xval)
        for (int i = 0; i + 1 < kv.second.size(); i++)
            merge(kv.second[i], kv.second[i + 1]);
    for (auto& kv : yval)
        for (int i = 0; i + 1 < kv.second.size(); i++)
            merge(kv.second[i], kv.second[i + 1]);
    for (auto& e : edges) {
        vector <int> v1, v2;
        if (e.second.second == 0) {
            int i = e.second.first;
            v1 = xval[xv[i]];
            v2 = xval[xv[i + 1]];
        }
        else {
            int i = e.second.first;
            v1 = yval[yv[i]];
            v2 = yval[yv[i + 1]];
        }
        for (int i : v1)
            merge(i, v2[0]);
        for (int i : v2)
            merge(i, v1[0]);
    }

    cout << total << endl;
}


Measured memory_bytes: 33732
#include <bits/stdc++.h>
#define ll long long
using namespace std;
 
const long long MAXVAL = (long long) 1e18 + 1;
const long long MOD = 1000000007ll;
//const long long MOD = 998244353ll;
const int INF = 1000000001;
 
long long poww(int x, long long pow) {
  if (pow == 0ll ) return 1;
  if (pow == 1ll) return x % MOD;
  long long ans = poww(x, pow >> 1) % MOD;
  ans = (ans * ans) % MOD;
  if ((pow & 1) == 1) {
    ans = (ans * x ) % MOD;
  }
  return ans % MOD;
}
 
ll gcd(ll x, ll y) {
  if (x == 0) return y;
  while (y) {
    x %= y;
    swap(x, y);
  }
  return x;
}
 
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int q = 1;
   //cin >> q;
  while (q-- >0) {
    string s,t;
    cin >> s >> t;
    int n = s.length();
    int ans = 0;
    for (int i = 0; i < n; ++i) {
      if (s[i] != t[i]) ++ans;
    }
    cout << ans << endl;
  }

 
  return 0;
}


Measured memory_bytes: 3772
class Array
  def cumsum(s = 0)
    map{|t| s += t }
  end
end

# 23:13- 解説blogも見た
n, k = gets.to_s.split.map{|t| t.to_i }
v    = gets.to_s.split.map{|t| t.to_i }

rev = v.reverse
l = v.cumsum
r = rev.cumsum

s_a = 0
ans = 0
(n+1).times do |a|
  
  s_a += v[a-1] if a > 0
  s = s_a
  [n-a+1, k-a+1].min.times do |b|
    s += rev[b-1] if b > 0
    q = v[0, a] + rev[0, b]
    q.sort!
    # p [q, s]
    rem_k = [a+b, k-a-b].min
    toridasu = 0
    rem_k.times do |i|
      q[i] < 0 ? (toridasu += q[i]) : break
    end
    ans = s - toridasu if ans < s - toridasu
  end
end

puts ans

Measured memory_bytes: 1916
/// {{{
#include "bits/stdc++.h"
#define   ALL(x)  x.begin(), x.end()
#define   iostreamBooster()  do{cin.tie(nullptr);ios::sync_with_stdio(false);}while(0)
#define   rep(i, s, t)       for(int i = int(s); i < int(t); ++i)
using namespace std;
typedef long long i64;
typedef pair<int,int> pii;
template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;}
constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
// }}}


signed main()
{
  int a, p;
  cin >> a >> p;

  cout << (a * 3 + p) / 2 << endl;
  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define mod 998244353
long long p[100010];

void init() {
    p[0] = p[1] = 1;
    for (int i = 0; i < 18; i++) {
        p[1] = p[1] * 10 % mod;
    }
    for (int i = 1; i <= 100000; i++) {
        p[i+1] = p[i] * p[1] % mod;
    }
}

void calc(int n, vector<long long> &v) {
    int m; cin >> m;
    vector<int> e[n+1];
    vector<int> g(n+1, -1);
    for (int i = 0; i < m; i++) {
        int a, b; cin >> a >> b;
        e[a].emplace_back(b);
        e[b].emplace_back(a);
    }
    for (int i = n; i > 0; i--) {
        set<int> s;
        for (auto &to: e[i]) {
            s.emplace(g[to]);
        }
        int t = 0;
        for (auto &x: s) {
            if (x == -1) continue;
            if (x != t) break;
            t++;
        }
        g[i] = t;
    }
    for (int i = 1; i <= n; i++) {
        v[g[i]] = (v[g[i]] + p[i]) % mod;
    }
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    init();
    int n; cin >> n;
    vector<long long> x(512, 0), y(512, 0), z(512, 0);
    calc(n, x); calc(n, y); calc(n, z);
    long long ans = 0;
    for (int i = 0; i < 512; i++) {
        for (int j = 0; j < 512; j++) {
            ans = (ans + x[i] * y[j] % mod * z[i^j] % mod) % mod;
        }
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 6528
#include<bits/stdc++.h>
using namespace std;
//Optimisations
#pragma GCC target ("avx2")
#pragma GCC optimization ("unroll-loops")
#pragma GCC optimize("O2")
//shortcuts for functions
#define pb push_back
#define mp make_pair
#define ff first 
#define ss second
#define all(v) v.begin(),v.end()
#define prec(n) fixed<<setprecision(n)
#define n_l '\n'
// make it python 
#define gcd __gcd
#define append push_back
#define str to_string
// utility functions shortcuts
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define sswap(a,b) {a=a^b;b=a^b;a=a^b;}
#define swap(a,b) {auto temp=a; a=b; b=temp;}
#define init(dp) memset(dp,-1,sizeof(dp));
#define set0(dp) memset(dp,0,sizeof(dp));
#define bits(x) __builtin_popcount(x)
#define SORT(v) sort(all(v))
#define endl "\n"
#define forr(i,n) for(ll i=0;i<n;i++)
// declaration shortcuts
typedef long long int ll;
#define int ll
// Constants
constexpr int dx[] = {-1, 0, 1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, -1, 0, 1, 1, -1, 1, -1};
constexpr ll INF = 1999999999999999997; 
constexpr int inf= INT_MAX;
constexpr int MAXSIZE = int(1e6)+5;
constexpr auto PI  = 3.14159265358979323846L;
constexpr auto oo  = numeric_limits<int>::max() / 2 - 2;
constexpr auto eps = 1e-6;
constexpr auto mod = 1000000007;
constexpr auto MOD = 1000000007;
constexpr auto MOD9 = 1000000009;
constexpr auto maxn = 100006;
//void IOfile(){
//freopen(file_name, reade_mode, stdin);
//freopen(file_name, write_mode, stdout);
//}
void fastio(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}
int32_t main(){
	fastio();
	int n;
	cin >> n;
	vector<pair<int,int>>v;
	vector<int>c;
	for(int i = 0; i < n; i++){
		int a,b;
		cin >> a >> b;
		v.push_back({a + b,i});
		v.push_back({a + b,i});
		c.push_back(a-b);
	}
	sort(all(v));
	int ans = abs(v[v.size() - 1].ff - v[0].ff);
	sort(all(c));
	ans = max(ans,c[c.size() - 1] - c[0]);
	cout << ans;
}

Measured memory_bytes: 13548
let () = Scanf.scanf "%d" @@ fun n ->
  let ps = Array.init n @@ fun _ -> Scanf.scanf " %d" Fun.id in
  let ids = Array.init (n - 2) @@ fun i -> i + 1 in
  let check acm id = if (ps.(id - 1) < ps.(id) && ps.(id) < ps.(id + 1)) || (ps.(id - 1) > ps.(id) && ps.(id) > ps.(id + 1)) 
                      then acm + 1 else acm in
  let ans = Array.fold_left check 0 ids in
  Printf.printf "%d\n" ans

Measured memory_bytes: 3820
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <deque>
#include <vector>
#include <bitset>
#include <cmath>
#include <utility>
#define Maxn 100005
#define Maxm 1000005
#define lowbit(x) x&(-x)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define PI acos(-1.0)
#define eps 1e-7
#define LL long long 
#define Inf (1LL<<62)
#define inf 0x3f3f3f3f
#define input freopen("input.txt","r",stdin)
#define output freopen("output.txt","w",stdout)
using namespace std;
struct P
{
	int x,y;
	int id;
}p[Maxn];
int head[Maxn],k;
bool cmp1(P a,P b)
{
	if(a.x!=b.x)
		return a.x<b.x;
	else
		return a.y<b.y;
}
bool cmp2(P a,P b)
{
	if(a.y!=b.y)
		return a.y<b.y;
	else
		return a.x<b.x;
}
struct Edge
{
	int s;
	int e;
	int w;
	int next;
}edge[Maxn<<2];
void add(int s,int e,int w)
{
	edge[k].s=s;
	edge[k].e=e;
	edge[k].w=w;
	edge[k].next=head[s];
	head[s]=k++;
}
bool cmp(Edge a,Edge b)
{
	return a.w<b.w;
}
int father[Maxn];
void init(int n)
{
	for(int i=0;i<n;i++)
		father[i]=i;
}
int find(int x)
{
	return father[x]==x?x:father[x]=find(father[x]);
}
LL kruscal(int n)
{
	init(n);
	sort(edge,edge+k,cmp);
	int cnt=0;
	LL ans=0;
	for(int i=0;i<k;i++)
	{
		int u=edge[i].s;
		int v=edge[i].e;
		int w=edge[i].w;
		int x=find(u);
		int y=find(v);
		if(x!=y)
		{
			ans+=w;
			father[x]=y;
			cnt++;
		}
		if(cnt==n-1)
			break;
	}
	if(cnt<n-1)
		return -1;
	return ans;
}
int main()
{
	int n;
	//input;output;
	while(~scanf("%d",&n))
	{
		k=0;
		memset(head,-1,sizeof(head));
		for(int i=0;i<n;i++)
		{
			scanf("%d%d",&p[i].x,&p[i].y);
			p[i].id=i;
		}
		sort(p,p+n,cmp1);
		for(int i=0;i<n-1;i++)
		{
			add(p[i].id,p[i+1].id,p[i+1].x-p[i].x);
			add(p[i+1].id,p[i].id,p[i+1].x-p[i].x);
		}
		sort(p,p+n,cmp2);
		for(int i=0;i<n-1;i++)
		{
			add(p[i].id,p[i+1].id,p[i+1].y-p[i].y);
			add(p[i+1].id,p[i].id,p[i+1].y-p[i].y);
		}
		//cout<<k<<endl;
		printf("%lld\n",kruscal(n));
	}
	return 0;
}

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

struct UnionFind
{
    vector<int> d; //データを持つ。リンクの情報とサイズの情報
    //リンクがあるなら親のID
    //根なら-のサイズ
    //非負なら子である。
    UnionFind(int n) : d(n, -1) {} //コンストラクタはそのクラスのオブジェクトを初期化するために使われる。
    //初期化の意味　最初は全て-1＝全員根でサイズ1。
    int find(int x)
    {
        if (d[x] < 0) //もし今の頂点が根ならその頂点番号を渡す。
        {
            return x;
        }
        return find(d[x]); //根でないなら、親を探すように指示を送る。
        //経路縮約(メモ化)を行うと　return d[x]=find(d[x]);
    }
    bool unite(int x, int y) //二つ頂点を持ってきてこれらをくっつける。
    {
        x = find(x);
        y = find(y); //初期状態では両方を根とする。x,yは根(親)のid
        if (x == y)
        {
            return false; //クラスカル法の時に使うらしい
        }
        if (d[x] > d[y])
        {
            swap(x, y);
        }
        d[x] += d[y]; //xにyをくっつける。サイズの小さい方を大きい方にくっつけること！！
        d[y] = x;     //親のidに張り替える。
        return true;
    }
    bool same(int x, int y) //同じ集合に属しているかどうか.

    {
        return find(x) == find(y);
    }
    int size(int x)
    {
        return -d[find(x)];
    }
};

int main()
{
    //まず友達関係の組みを入れる。
    ll n, m, k;
    cin >> n >> m >> k;
    //map<ll, ll> frie;
    vector<ll> frie(n);
    vector<vector<ll>> blo(n);
    UnionFind fd(n);
    for (int i = 0; i < m; i++)
    {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        frie[a] += 1;
        frie[b] += 1;
        fd.unite(a, b);
    } //これで友達関係は全てグループ化したはず。
    for (int i = 0; i < k; i++)
    {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        //blo[i][0] = a;
        //blo[i][2] = b;
        blo[a].push_back(b);
        blo[b].push_back(a);
    }

    for (int i = 0; i < n; i++)
    {
        ll c = fd.size(i) - frie[i] - 1;
        //ブロック関係のやつ。もし、ブロック関係とのやつが同じところに存在していればって感じで。
        //iに関するブロックしている情報が欲しい。
        for (int x : blo[i])
        {
            if (fd.same(i, x) == 1)
            {
                c--;
            }
        }

        cout << c << " ";
    }
    //あとは、それぞれのグループに
}

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

int main(){
  double W, H, x, y;
  cin >> W >> H >> x >> y;
  int judge = 0;
  if(x == W/2 && y == H/2) judge = 1;
  cout << fixed << setprecision(7);
  cout << W * H / 2 << ' ' << judge << endl;
}


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

#define  floop(a,b) for(long long i=a;i<=b;i++)
#define  test long long t_c;cin>>t_c;for(long long ks=1;ks<=t_c;ks++)
#define pb push_back
#define vi vector<int>
#define all(x) x.begin(),x.end()
#define cy cout<<"YES\n";
#define cn cout<<"NO\n";
#define nl cout<<endl;

typedef long long ll;
typedef long long int lli;
using namespace std;
int main()
{
    ios::sync_with_stdio(0);
    int k;
    cin>>k;
    string s="ACL";
    for(int i=0;i<k;i++)
    {
        cout<<s;
    }
    nl;

}


Measured memory_bytes: 3612
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br =
				new BufferedReader(new InputStreamReader(System.in));
		for (String data; (data = br.readLine()) != null; ) {
			String ans = solve(data);
			System.out.println(ans);
		}

	}

	public static String solve(String data) {
		int[] hand = new int[10]; // (0,) 1, 2, 3, ... , 9
		for (int i=0; i < data.length(); i++) {
			char ch = data.charAt(i);
			hand[ch - '0']++;
		}
		StringBuilder ans = new StringBuilder();
		for (int i=1; i <= 9; i++) {
			if ( isWin(hand, i) )
				ans.append(i + " ");
		}
		if (ans.length() == 0) return "0";
		return ans.toString().trim();
	}

	private static boolean isWin(int[] hand13, int tsumo) {
		if (hand13[tsumo] >= 4) return false;
		int[] hand14 = Arrays.copyOf(hand13, hand13.length);
		hand14[tsumo]++;
//		if (hand14[tsumo] > 4) return false;
		return isWin(hand14);
	}

	private static boolean isWin(int[] hand14) {
		atamaloop:
		for (int atama = 1; atama <= 9; atama++) {
			if (hand14[atama] < 2) continue;
			int[] hand = Arrays.copyOf(hand14, hand14.length);
			hand[atama] -= 2;
			int mentsu = 0;
			mentsuloop:
			for (int pai = 1; pai <= 9; pai++) {
				if (hand[pai] == 4) {
					koutsu(hand, pai);
					mentsu++;
					if (shuntsu(hand, pai)) {
						mentsu++;
						if (mentsu == 4) {
							return true;
						} else {
							continue mentsuloop;
						}
					}
					continue atamaloop;
				}
				if (hand[pai] == 3) {
					koutsu(hand, pai);
					mentsu++;
					if (mentsu == 4) {
						return true;
					} else {
						continue mentsuloop;
					}
				}
				if (hand[pai] == 2) {
					if (shuntsu(hand, pai)) {
						mentsu++;
						if (shuntsu(hand, pai)) {
							mentsu++;
							if (mentsu == 4) {
								return true;
							} else {
								continue mentsuloop;
							}
						}
					}
					continue atamaloop;
				}
				if (hand[pai] == 1) {
					if (shuntsu(hand, pai)) {
						mentsu++;
						if (mentsu == 4) {
							return true;
						} else {
							continue mentsuloop;
						}
					}
					continue atamaloop;
				}
				if (hand[pai] == 0) {
					continue mentsuloop;
				}
			}
		}
		return false;
	}

	private static void koutsu(int[] hand, int pai) {
		hand[pai] -= 3;
	}

	private static boolean shuntsu(int[] hand, int pai) {
		if (pai >= 8) return false;
		if (hand[pai] > 0 && hand[pai+1] > 0 && hand[pai+2] > 0) {
			hand[pai]--;
			hand[pai+1]--;
			hand[pai+2]--;
			return true;
		}
		return false;
	}
}

Measured memory_bytes: 24404
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  priority_queue<double, vector<double>, greater<double>> val;
  double v;
  for(int i=0;i<n;i++){
    cin >> v;
    val.push(v);
  }
  while(val.size()!= 1){
    double x,y;
    x = val.top();val.pop();
    y = val.top();val.pop();
    val.push((x+y)/2);
  }
  cout << setprecision(15) << val.top() << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<math.h>
using namespace std;

int main() {
  long long int a, ans = 0, kans;
  cin >> a;
  if(a >= 11) {
    ans = a / 11;
    ans *= 2;
    kans = a % 11;
  }else {
    kans = a;
  }

  if(kans > 0) {
    kans -= 6;
    ans++;
    if(kans > 0) {
      kans -= 5;
      ans++;
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <iomanip>
#include <cmath>
#include <cstdio>
#include <set>
#define REP(i,n) for (int i=0;i<(n);++i)
using namespace std;
using ll = long long;

ll n, a, b;

int main() {
  cin >> n >> a >> b;
  if ((b - a) % 2 == 0) {
    cout << (b - a) / 2 << endl;
  } else {

    ll ans1 = a;
    ll tmp = b - a;
    ans1 += (tmp - 1) / 2;

    ll ans2 = n - b + 1;
    tmp = a + n - b + 1;
    ans2 += (n - tmp) / 2;
    cout << min(ans1, ans2) << endl;
  }
  return 0;
}



Measured memory_bytes: 256
use proconio::fastout;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;

#[fastout]
fn main() {
    input! {
        n: usize,
        k: usize,
        mut p: [usize; n],
    }
    p.sort();
    println!("{}", p[..k].iter().sum::<usize>());
}


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

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

const int INF = 1e9;
const int MOD = 1e9 + 7;

int cnt[110];

int main() {
  int N, K;
  cin >> N >> K;
  int d[K];
  for (int i = 0; i < K; i++) {
    cin >> d[i];
    for (int j = 0; j < d[i]; j++) {
      int a;
      cin >> a;
      cnt[a]++;
    }
  }

  int ans = 0;
  for (int i = 1; i <= N; i++) if (cnt[i] == 0) ans++;

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

Measured memory_bytes: 3636
#include <iostream>
#include <string>
#include <iomanip>
#include <ios>
using namespace std;
int main(void){
  string word;
  cin >> word;
  
  int n = 0;
  int s = 0;
  int e = 0;
  int w = 0;
  
  int N = word.length();
  
  for(int i=0;i<N;i++){
    if(word[i] == 'N')
      n++;
    if(word[i] == 'S')
      s++;
    if(word[i] == 'E')
      e++;
    if(word[i] == 'W')
      w++;
  }
  
  if((n == 0 && s == 0) ||n * s != 0){
    if((e == 0 && w == 0) ||e * w != 0){
      cout << "Yes" << endl;
    }
    else
      cout << "No" << endl;
  }
  
  else
    cout << "No" << endl;
  
  return 0;
}

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

vector<int> e[3001];
int a[3001];
bool win[3001];
void dfs(int x,int p){
	win[x]=false;
	for(int it:e[x])
		if(it!=p){
			dfs(it,x);
			if(a[x]>a[it] && !win[it])
				win[x]=true;
		}
}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	for(int i=1,u,v;i<n;i++)
		cin>>u>>v, e[u].emplace_back(v),e[v].emplace_back(u);
	for(int i=1;i<=n;i++){
		dfs(i,0);
		if(win[i])
			cout<<i<<' ';
	}
	cout<<endl;
}


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

// {U}{INT,LONG,LLONG}_{MAX,MIN}
#define INF         INT_MAX/3
#define LLINF       LLONG_MAX/3
#define MOD         (1000000007LL)
#define MODA(a, b)  a=((a)+(b))%MOD
#define MODP(a, b)  a=((a)*(b))%MOD
#define inc(i, l, r)   for(int i=(l);i<(r);i++)
#define dec(i, l, r)   for(int i=(r)-1;i>=(l);i--)
#define pb          push_back
#define se          second
#define fi          first
#define mset(a, b)  memset(a, b, sizeof(a))

using LL  = long long;
using G   = vector<vector<int>>;

int di[] = {0, -1, 0, 1};
int dj[] = {1, 0, -1, 0};
// }}}

// Union-Find {{{
// O(a(n))
// verified AOJ DSL_1_A
struct UF {
    vector<int> p;  // parent
    vector<int> r;  // rank

    UF(int n) {
        p.resize(n);
        r.resize(n);
        for(int i=0;i<n;i++){
            p[i] = i;
            r[i] = 1;
        }
    }

    int find(int x) {
        if(x == p[x]){
            return x;
        }else{
            return p[x] = find(p[x]);
        }
    }

    void unite(int x, int y) {
        x = find(x);
        y = find(y);
        if(x == y) return;
        if(r[x] < r[y]){
            p[x] = y;
        }else{
            p[y] = x;
            if(r[x] == r[y]){
                r[x]++;
            }
        }
    }
}; // }}}

int main() {
    cin.tie(0);ios::sync_with_stdio(false);
    int n;cin >> n;
    vector<pair<LL, int>> x(n), y(n);
    inc(i, 0, n){
        LL xx, yy;cin >> xx >> yy;
        x[i] = {xx, i};
        y[i] = {yy, i};
    }
    sort(x.begin(), x.end());
    sort(y.begin(), y.end());
    vector<pair<LL, pair<int, int>>> v;
    inc(i, 1, n){
        v.pb({x[i].fi-x[i-1].fi, {x[i].se, x[i-1].se}});
        v.pb({y[i].fi-y[i-1].fi, {y[i].se, y[i-1].se}});
    }
    sort(v.begin(), v.end());
    LL ans = 0;
    UF uf(n);
    inc(k, 0, 2*n){
        LL d = v[k].fi;
        int i = v[k].se.fi;
        int j = v[k].se.se;
        if(uf.find(i) == uf.find(j)) continue;
        ans += d;
        uf.unite(i, j);
    }
    cout << ans << endl;
    return 0;
}


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

int main() {
    int x;
    cin >> x;

    int ans = 1;
    for (int pow = 2; pow <= 10; pow++) {
        int i = 2;
        while (1) {
            int a = 1;
            for (int j = 0; j < pow; j++) {
                a *= i;
            }

            if (a > x) {
                break;
            }
            ans = max(ans, a);

            i++;
        }
    }

    cout << ans << endl;

    return 0;
}


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

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<pll> vpl;

#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  ll n,p;
  cin>>n>>p;
  string s;
  cin>>s;

  if(10%p==0){
    ll ans=0;
    REP(r,n){
      if((s[r]-'0')%p==0)
      ans+=r+1;
    }

    cout<<ans<<endl;
  }
  else{
    map<ll, ll> m;
    ll power=1;
    ll remind=0;
    m[remind]+=1;
    for(ll i=n-1; i>=0; i--){
      ll num=s[i]-'0';
      remind = (remind+num*power%p)%p;
      m[remind]+=1;

      power = power*10%p;
    }

    ll ans=0;
    REP(i,p)
      ans += m[i]*(m[i]-1)/2;

    cout<<ans<<endl;
  }

}


Measured memory_bytes: 1044
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string.h>
#include <string>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <math.h>
#include <algorithm>
#include <numeric>

using namespace std;

// マクロ&定数 ============================================================
typedef unsigned int uint;
typedef long long ll;
//typedef pair<int, int> P;

typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<bool> vbool;
typedef vector<string> vstring;
typedef vector<char> vchar;

typedef vector<pair<int, int>> vpint;
typedef vector<pair<ll, ll>> vpll;
typedef vector<pair<double, double>> vpdouble;

typedef vector<vector<int>> vvint;
typedef vector<vector<ll>> vvll;
typedef vector<vector<double>> vvdouble;
typedef vector<vector<bool>> vvbool;

typedef vector<vector<string>> vvstring;

const int c_YET = -1;
const int INF = 1e9 + 1;
const ll LLINF = 1e17 + 1;
const int DX[9] = { 0,0,1,-1, 1, 1, -1, -1, 0 }; // 4;４近傍
const int DY[9] = { 1,-1,0,0, 1, -1, 1, -1, 0 }; // 8:８近傍 9:(0,0)を含む
const ll MOD = 1e9 + 7; //10^9 + 7
const ll MAX = 1e9;
const double PI = 3.14159265358979323846264338327950288;
//========================================================================



int main() {

	//==================================
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(30);
	//==================================


	int N;
	cin >> N;



	vvstring det(N);// i+1桁での標準形一覧


	det[0].emplace_back("a");
	
	for (int i = 1; i < N; i++)
	{
		if (i == 3)
		{
			int a = 0;
		}
		for (int j = 0; j < det[i - 1].size(); j++)
		{
			
			string base = det[i - 1][j];
			int base_max = 0;
			for (int k = 0; k < base.length(); k++)
			{
				base_max = max(base_max, int(base[k]) - int('a'));
			}

			for (int c = 0; c <= base_max+1; c++)
			{
				det[i].emplace_back(det[i - 1][j] + char(c+'a'));
			}
		}
	}

	sort(det[N - 1].begin(), det[N - 1].end());

	det[N - 1].erase(unique(det[N - 1].begin(), det[N - 1].end()), det[N - 1].end());
	for (int i = 0; i < det[N - 1].size(); i++)
	{
		cout << det[N - 1][i] << endl;
	}


}



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

#ifdef STEVEN
#define pp(...) cerr << "\t[" << #__VA_ARGS__ << "]:\t", dbg_out(__VA_ARGS__)
#define ppp(x) cerr << x << "\n"
#else
#define pp(...)
#define ppp(...)
#endif
using namespace std;
// ====

typedef long long ll;
const int MAXN = 1000100;

int main() {
  string s;
  cin >> s;
  if (s.size() == 6 && s[2] == s[3] && s[4] == s[5]) cout << "Yes\n";
  else cout << "No\n";
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
int a[5];
for(int i=0;i<5;i++)cin >> a[i];
sort(a,a+5);
for(int i=4;i>=0;i--){
if(i==0){
cout << a[i] << "\n";
break;
}
cout << a[i] << " ";
}
return 0;
}

Measured memory_bytes: 1180
n,x = map(int, input().split())
a = list(map(int, input().split()))
cost = a[:]
ans = sum(a)
for k in range(1,n):
  sc = k*x
  for i in range(n):
    if cost[i] > a[i-k]: cost[i] = a[i-k]
    sc += cost[i]
  if sc < ans: ans = sc
print(ans)

Measured memory_bytes: 3188
N, K = map(int, input().split())
P = list(map(int, input().split()))

next_end = K

num = sum(P[:next_end])

max_num = num

for start in range(1, N - K + 1):
    num -= P[start - 1]
    num += P[next_end]
    max_num = max(num, max_num)
    next_end += 1

print((max_num + K) / 2)

Measured memory_bytes: 24804
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<pair<int,int>> da(n);
  for(int i=0;i<n;i++){
    int x;
    cin >> x;
    da[i]=make_pair(x,i);
  }
  sort(da.begin(),da.end());
  vector<int> ans(n);
  for(int i=0;i<n;i++){
    if(i<n/2){
      ans[da[i].second]=da[n/2].first;
    }
    else{
      ans[da[i].second]=da[n/2-1].first;
    }
  }
  for(int i=0;i<n;i++){
    cout << ans[i] << endl;
  }
}

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

int min(int a, int b){
	return (a > b)? b : a;
}

int main(){
	const int INF = 10000;
	int pas = INF, jui = INF;
	int n;
	
	for(int i = 0; i < 3; i++){
		scanf("%d", &n);
		pas = min(pas, n);
	}
	for(int i = 0; i < 2; i++){
		scanf("%d", &n);
		jui = min(jui, n);
	}
	
	printf("%d\n", pas + jui - 50);
	
	return 0;
}

Measured memory_bytes: 1020
import math
import itertools

n = int(input())
towns = []
for _ in range(n):
    x, y = input().split()
    towns.append((int(x), int(y)))

sum = 0
for towns in list(itertools.permutations(towns)):
    for i in range(n - 1):
        sum += math.sqrt((towns[i][0] - towns[i + 1][0]) ** 2 + (towns[i][1] - towns[i + 1][1]) ** 2)

print(sum / math.factorial(n))

Measured memory_bytes: 8052
#include<stdio.h>

int main(void){
    int a,b,c,count=0,i;
    
    scanf("%d",&a);
    scanf("%d",&b);
    scanf("%d",&c);
    
    for(i=a;i<=b;i++){
        if(c%i==0){
            count++;
        }
    }
    
    printf("%d\n",count);
    
    return 0;
}


Measured memory_bytes: 2096
a,b,c,d,e,f=map(int,input().split())
w=[]
for i in range(f//100+1):
    for j in range(f//100+1):
        x=100*a*i+100*b*j
        if x<=f:
            w.append(x)
s=[]
for i in range(f):
    for j in range(f):
        y=i*c+j*d
        if y<=f:
            s.append(y)
max_con=0
ans,ans_2=0,0
for i in w:
    for j in s:
        if i==0 and j==0:
            continue
        elif e*(i//100)<j:
            continue
        elif f<i+j:
            continue
        else:
            con=(100*j)/(i+j)
            if max_con<=con:
                max_con=con
                ans=i+j
                ans_2=j
print(ans,ans_2)


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

int main(){
    int a, b;
    const int tax8=8/100, tax10=10/100;
    cin >> a >> b;
    rep(1,10000){
        if((i*8/100)==a && (i*10/100)==b){
            cout << i << endl;
            return 0;
        }
    }
    cout << "-1" << endl;
    return 0;
}


Measured memory_bytes: 256
//  cout << char(i+48) << endl;//なぜかaは47と得る時がある。+48で出力もaにできる。
//  cout << char(97) << endl;//アスキーコードでaを出力
// sort(b.begin(), b.end());//bという配列を小さい方からソート
// reverse(b.begin(), b.end());//bという配列をリターン
// 10桁でdouble出力するパターン１ 
// printf("%.10f\n", ma);
// 10桁でdouble出力するパターン２
//cout << fixed << setprecision(10);
//  cout << ma << endl;

/*01 02 03 12 13 23　と６回見ていくパターン 
for(int i=0;i<n-1;i++){
  for(int j=i+1;j<n;j++){
    }
  }
*///vector<vector<int>> data(3, vector<int>(4));//int型の2次元配列(3×4要素の)の宣言
//int64_t a;
//10のi乗pow(10, i);
/*string s; stringでの文字列を数字型に変える方法
  cin >> s;
  rep(i,s.size()-2) {
  int a= (s.at(i)-'0')*100 + (s.at(i+1)-'0')*10+ s.at(i+2) -'0';
    */
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
  int n,a,b;
  cin >> n >> a >> b;
  if((b-a)%2==0) cout<<"Alice"<<endl;
  else cout<<"Borys"<<endl;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
from itertools import accumulate
from collections import Counter
import math
a = list(accumulate(a))
b = Counter(a)
def comb(n):
    return math.factorial(n)/math.factorial(n-2)/math.factorial(2)
cnt = 0
for v in b.values():
    if v >= 2:
        cnt += comb(v)
print(int(cnt+a.count(0)))

Measured memory_bytes: 33812
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <algorithm>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1010101010;
constexpr lint LINF = 1LL << 60;

template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
	for (const auto &e : vec) os << e << (&e == &vec.back() ? "\n" : " ");
	return os;
}

#ifdef _DEBUG
template <class T>
void dump(const char* str, T &&h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head &&h, Tail &&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + (*(str + 1) == ' ' ? 2 : 1), t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

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

	struct rw { 
		int s, t, x; 
		rw(int s = 0, int t = 0, int x = 0) :s(s), t(t), x(x) {}
	};
	vector<rw> RW(N);
	for (int i = 0; i < N; i++) {
		int s, t, x;
		cin >> s >> t >> x;
		RW[i] = { s, t, x };
	}
	sort(RW.begin(), RW.end(), [](auto &l, auto &r) { return (l.s - l.x) < (r.s - r.x); });

	int idx = 0;
	priority_queue<pair<int,int>, vector<pair<int,int>>, greater<pair<int,int>>> pq;
	for (int i = 0; i < Q; i++) {

		int d;
		cin >> d;

		while (idx < N && RW[idx].s - RW[idx].x <= d) {
			pq.emplace(RW[idx].x, RW[idx].t - RW[idx].x);
			idx++;
		}
		while (!pq.empty() && pq.top().second <= d) pq.pop();

		cout << (pq.empty() ? -1 : pq.top().first) << "\n";

	}

	return 0;
}

Measured memory_bytes: 5360
#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 x, a, b;
  cin >> x >> a >> b;
  cout << (x - a) % b << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}

int t[210],v[210];

int main(){
  int n;
  cin >> n;
  rep(i,n) cin >> t[i];
  rep(i,n) cin >> v[i];
  
  double ret = 0, sp = 0;
  rep(i,n){
    for(double j=0; j<t[i]; j += 0.5){
      bool flag1 = true, flag2 = true;
      double ti = t[i]-j-0.5;
      for(int k = i+1; k<n;k++){
        ti += t[k];
        if(sp+0.5-ti > v[k+1]) flag1 = false;
        if(sp-v[k+1] > ti) flag2 = false;
      }
      if(sp+0.5 <= v[i] && flag1 && (sp+0.5-(t[i]-j-0.5)) <= v[i+1]){
        ret += sp*0.5;
        ret += 0.125;
        sp += 0.5;
      }else if(sp-v[i+1] <= t[i]-j-0.5 && flag2){
        ret += sp*0.5;
      }else{
        sp -= 0.5;
        ret += sp*0.5;
        ret += 0.125;
      }
    }
  }
  
  printf("%.15f\n",ret);
  return 0;
}

Measured memory_bytes: 256
while 1:
    m,f,r = map(int,input().split())
    point = m + f
    if m == -1 and f == -1 and r == -1:
        break
    if m == -1 or f == -1:
        print('F')
    elif point >= 80:
        print('A')
    elif point >= 65:
        print('B')
    elif point >= 50:
        print('C')
    elif point >= 30:
        if r >= 50:
            print('C')
        else:
            print('D')
    else:
        print('F')

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

static class Ball
{
    static void Main()
    {
        var input = Console.In.ReadToEnd()
            .Split( 
                new[] { '\r', '\n' },
                StringSplitOptions.RemoveEmptyEntries )
            .Skip( 1 )
            .Select( x => Array.ConvertAll( x.Split(), int.Parse ) );
        var q =
            from a in input
            select a
                .Aggregate(
                    new[] { 0, 0 },
                    (x, y) => x != null
                        ? x[0] > y 
                            ? x[1] > y ? null : new[] { x[0], y }
                            : new[] { y, x[1] }
                        : null ) != null ? "YES" : "NO";
        q.ToList().ForEach( Console.WriteLine );
    }
}

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

int main(){
  int n, k;
  cin >> n >> k;
  vector<int> p(n);
  rep(i, n) cin >> p.at(i);
  sort(p.begin(), p.end());
  int ans = 0;
  rep(i, k) ans += p.at(i);
  cout << ans << endl;
}

Measured memory_bytes: 3628
#include<iostream>
using namespace std;
int main(){
  int n,t,a,b,i,ans;
  cin >> n >> t;ans = 55555;
  for(i=0;i<n;i++){
    cin >> a >> b;
    if (b<=t && a < ans) ans = a;
  }
  if (ans==55555) cout << "TLE" << endl;
  else cout << ans << endl;
}
  

Measured memory_bytes: 256
from collections import Counter

N = int(input())
A = list(map(int, input().split()))

P = []
Q = []

for i in range(N):
    P.append(i + 1 + A[i])
    Q.append(i + 1 - A[i])

P = Counter(P)
Q = Counter(Q)

res = 0

for v, c in P.items():
    if v in Q:
        res += c * Q[v]

print(res)

Measured memory_bytes: 62244
#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>;

ll num = 1000000000;

int main(void)
{
  ll n, k;
  cin >> n >> k;
  vector<ll> as(n);
  vector<ll> towns(100000000);
  rep(i, n) cin >> as[i];

  map<ll, ll> m;
  ll current = 1;
  ll cnt = 1;
  ll num;
  ll yobun;
  m[current] = cnt;
  towns[0] = 1;
  while(true) {
    cnt++;
    ll next = as[current-1];
    towns[cnt-1] = next;
    if(m[next]) {
      yobun = m[next] -1;
      num = cnt - m[next];
      break;
    }
    current = next;
    m[next] = cnt;
  }
  if (k < yobun) {
    cout << towns[k] << endl;
    return 0;
  }
  ll index = (k+1-yobun)%num;
  ll ans = towns[index ? yobun+index-1 : num+yobun-1];

   cout << ans << endl;


  return 0;
}


Measured memory_bytes: 798340
// Aizu 1172: Chebyshev's Theorem
// 2017.9.13 bal4u@uu

#include <stdio.h>

#define MAX  250000
#define SQRT 500     // sqrt(MAX)
char prime[MAX + 5], *p, *q, *pmax = prime + MAX;

void mkprime()
{
	int k;
	prime[1] = 1; prime[2] = 0;
	for (k = 3, p = prime + 3; k <= SQRT; k += 2, p += 2)
		if (!*p) for (q = p + k; q <= pmax; q += k) *q = 1;
}

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

	mkprime();
	while (scanf("%d", &n) && n) {
		m = n << 1, ans = 0; if (n == 1) ans++;  // for 2
		i = n + 1; if (!(i & 1)) i++;            // for odd num only
		for ( ; i <= m; i += 2) if (!prime[i]) ans++;
		printf("%d\n", ans);
	}
	return 0;
}

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

int main(){
	int n;
	cin >> n;
	int g = n%10;
	if(g == 2 || g == 4 || g == 5 || g == 7 || g == 9) cout << "hon\n";
	else if(g == 0 || g == 1 || g == 6 || g == 8) cout << "pon\n";
	else cout << "bon\n";
}


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

public class Main{
  public static void main(String[] args)throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    
    String input = br.readLine();
    
    System.out.println(input.replaceAll(".", "x"));
  }
}

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

const int mod=1000000007;
vector<pair<int,int> > v[1010];
int n,fa[1010],m,t[2010],tn,ans,mi[2010];
struct edg{int x,y,v;}e[2010];
long long X,nw;

int ask(int x) {return fa[x]==x?x:fa[x]=ask(fa[x]);}
bool cmp(edg a,edg b) {return a.v<b.v;}

int dfs(int x,int y,int la)
{
	if (x==y) return 0;
	for (int i=0,sz=v[x].size(); i<sz; i++)
		if (v[x][i].first!=la) 
		{
			int nw=dfs(v[x][i].first,y,x);
			if (nw!=-1) return max(nw,v[x][i].second);
		}
	return -1;
}

int main()
{
	mi[0]=1;
	for (int i=1; i<=2000; i++) mi[i]=2ll*mi[i-1]%mod;
	scanf("%d%d%lld",&n,&m,&X);
	if (n==1) return puts("0"),0;
	for (int i=1; i<=m; i++) scanf("%d%d%d",&e[i].x,&e[i].y,&e[i].v);
	sort(e+1,e+1+m,cmp),tn=0,nw=0;
	for (int i=1; i<=n; i++) fa[i]=i,v[i].clear();
	for (int i=1; i<=m; i++) 
	{
		if (ask(e[i].x)!=ask(e[i].y))
		{
			fa[ask(e[i].x)]=ask(e[i].y),nw+=e[i].v;
			v[e[i].x].push_back(make_pair(e[i].y,e[i].v));
			v[e[i].y].push_back(make_pair(e[i].x,e[i].v));
		} else t[++tn]=e[i].v-dfs(e[i].x,e[i].y,0);
	}
	sort(t+1,t+1+tn);
	if (nw>X) return puts("0"),0;
	if (nw==X) ans=1ll*(mi[n-1]+mod-2)*mi[m-n+1]%mod; else ans=0;
	for (int i=1; i<=tn; i++)
	{
		if (t[i]+nw<X) continue;
		if (t[i]+nw>X) break;
		ans=(ans+2ll*mi[tn-i])%mod; 
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define reps(i,n) for(int i=1;i<(int)(n);i++)

typedef long long ll;
using namespace std;

int gcd(int a, int b) { //最大公約数
  if (b==0) return a;
  else return gcd(b, a%b);
}

int lcm(int a, int b) { //最小公倍数
  return a * b / gcd(a, b);
}


int main()
{
  ll x,a,b;
  cin>>x>>a>>b;
  if(abs(x-a)<abs(x-b)){
    cout<<"A"<<endl;
  }else{
    cout<<"B"<<endl;
  }

  return 0;
}


Measured memory_bytes: 3524
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] d = new int[n];
        for(int i = 0; i < n; i++){
            d[i] = sc.nextInt();
        }
        Arrays.sort(d);
        int count = 1;
        for(int i = 0; i < n-1; i++){
            if(d[i] < d[i+1]){
                count++;
            }
        }
        System.out.print(count);
    }
}

Measured memory_bytes: 21844