akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;

const double PI = 3.141592653589793;
signed main(void)
{
	long double a, b, h, m;
	long double r_m, r_h, dx, dy, A_x, A_y, B_x, B_y, ans;

	cin >> a >> b >> h >> m;
	r_h = (60 * h + m) / 720 * 2 * PI; 
	r_m = m / 60 * 2 * PI;
	A_x = a * cosl(r_h);
	A_y = a * sinl(r_h);
	B_x = b * cosl(r_m);
	B_y = b * sinl(r_m);
	ans = sqrtl((long double)(A_x - B_x) * (A_x - B_x) +\
			(long double)(A_y - B_y) * (A_y - B_y));
	cout << fixed << setprecision(20) << ans << endl;
	return 0;
}


Measured memory_bytes: 4152
#include <iostream>
#include <algorithm>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
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 (b<a) { a=b; return 1; } return 0; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}
const ll INF = 1e15;
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
typedef pair<ll,ll> P;
const ll MAX = 300010;
constexpr ll nx[8] = {1,0,-1,0,-1,-1,1,1};
constexpr ll ny[8] = {0,1,0,-1,-1,1,-1,1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    vector<ll> t(n),v(n);
    rep(i,n) cin >> t[i];
    rep(i,n) cin >> v[i];
    vector<vector<double>> dp(40010,vector<double>(210,0));
    rep(i,n){
        t[i] *= 2;
        v[i] *= 2;
    }
    rep(i,n-1) t[i+1] += t[i];
    ll index = 0;
    rep(i,t[n-1]){
        if (i == t[index]) index++;
        rep(j,201){
            if (i != 0 && dp[i][j] == 0) continue;
            if (j > v[index]) continue;
            if (i+1 == t[index]){
                if (j == v[index]){
                    chmax(dp[i+1][j-1],dp[i][j]+(2*j-1.0)/8.0);
                    chmax(dp[i+1][j],dp[i][j]+2*j/8.0);
                    continue;
                }
            }
            if (j == 0){
                chmax(dp[i+1][j],dp[i][j]+2*j/8.0);
                chmax(dp[i+1][j+1],dp[i][j]+(2*j+1.0)/8.0);
                if (i == 0) break;
            }
            else if (j == 200){
                chmax(dp[i+1][j-1],dp[i][j]+(2*j-1.0)/8.0);
                chmax(dp[i+1][j],dp[i][j]+2*j/8.0);
            }
            else{
                chmax(dp[i+1][j-1],dp[i][j]+(2*j-1.0)/8.0);
                chmax(dp[i+1][j],dp[i][j]+2*j/8.0);
                chmax(dp[i+1][j+1],dp[i][j]+(2*j+1.0)/8.0);
            }
        }
    }
    printf("%.10f\n",dp[t[n-1]][0]);
}


Measured memory_bytes: 67584
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<string>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;

int main() {
    int A,B,K;
    cin >> A >> B >> K;
    int min_AB = min(A,B);
    vector<int> vec;

    for (int i = 1; i <= min_AB; i++) {
        if (A % i == 0 && B % i == 0) {
            vec.push_back(i);
        }
    }

    cout << vec.at(vec.size() - K) << endl;
}

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

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

    int a, b;
    cin >> a >> b;

    if (b % a == 0) {
        cout << a + b  << '\n';
    } else {
        cout << b - a  << '\n';
    }

    return 0;
}


Measured memory_bytes: 256
import math
from math import gcd
INF = float("inf")

import sys
input=sys.stdin.readline
import itertools
from collections import Counter

def main():
    n,k,q = map(int, input().split())
    ans = [k-q]*n
    for i in range(q):
        k = int(input())  - 1
        ans[k] += 1
    for i in ans:
        if i > 0:
            print("Yes")
        else:
            print("No")


if __name__=="__main__":
    main()


Measured memory_bytes: 12192
#![allow(non_snake_case)]
#![allow(dead_code)]
#![allow(unused_macros)]
#![allow(unused_imports)]

use std::str::FromStr;
use std::io::*;
use std::collections::*;
use std::cmp::*;

struct Scanner<I: Iterator<Item = char>> {
    iter: std::iter::Peekable<I>,
}

macro_rules! exit {
    () => {{
        exit!(0)
    }};
    ($code:expr) => {{
        if cfg!(local) {
            writeln!(std::io::stderr(), "===== Terminated =====")
                .expect("failed printing to stderr");
        }
        std::process::exit($code);
    }}
}

impl<I: Iterator<Item = char>> Scanner<I> {
    pub fn new(iter: I) -> Scanner<I> {
        Scanner {
            iter: iter.peekable(),
        }
    }

    pub fn safe_get_token(&mut self) -> Option<String> {
        let token = self.iter
            .by_ref()
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        if token.is_empty() {
            None
        } else {
            Some(token)
        }
    }

    pub fn token(&mut self) -> String {
        self.safe_get_token().unwrap_or_else(|| exit!())
    }

    pub fn get<T: FromStr>(&mut self) -> T {
        self.token().parse::<T>().unwrap_or_else(|_| exit!())
    }

    pub fn vec<T: FromStr>(&mut self, len: usize) -> Vec<T> {
        (0..len).map(|_| self.get()).collect()
    }

    pub fn mat<T: FromStr>(&mut self, row: usize, col: usize) -> Vec<Vec<T>> {
        (0..row).map(|_| self.vec(col)).collect()
    }

    pub fn char(&mut self) -> char {
        self.iter.next().unwrap_or_else(|| exit!())
    }

    pub fn chars(&mut self) -> Vec<char> {
        self.get::<String>().chars().collect()
    }

    pub fn mat_chars(&mut self, row: usize) -> Vec<Vec<char>> {
        (0..row).map(|_| self.chars()).collect()
    }

    pub fn line(&mut self) -> String {
        if self.peek().is_some() {
            self.iter
                .by_ref()
                .take_while(|&c| !(c == '\n' || c == '\r'))
                .collect::<String>()
        } else {
            exit!();
        }
    }

    pub fn peek(&mut self) -> Option<&char> {
        self.iter.peek()
    }
}

fn is_ok(s: &Vec<char>) -> bool {
    let n = s.len();
    if n % 2 != 0 {
        return false;
    }
    for i in 0..n/2 {
        if s[i] != s[i + n/2] {
            return false;
        }
    }
    true
}

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin.bytes().map(|c| c.unwrap() as char));
    let mut S: Vec<char> = sc.chars();
    let N = S.len();
    for _ in 0..N {
        S.pop();
        if is_ok(&S) {
            println!("{}", S.len());
            return;
        }
    }
    unreachable!();
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define GET_MACRO(_1,_2,_3,_4,_5,NAME,...) NAME
#define pr(...) GET_MACRO(__VA_ARGS__,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__)
#define pr1(a) (#a)<<"="<<(a)
#define pr2(a,b) pr1(a)<<", "<<pr1(b)
#define pr3(a,b,c) pr2(a,b)<<", "<<pr1(c)
#define pr4(a,b,c,d) pr3(a,b,c)<<", "<<pr1(d)
#define pr5(a,b,c,d,e) pr4(a,b,c,d)<<", "<<pr1(e)
#define int long long
#define double long double
using namespace std;
const int N = 100010;
const int INF = 1LL<<55;
const int mod = (1e9)+7;
const double EPS = 1e-8;
const double PI = 6.0 * asin(0.5);
typedef pair<int,int> P;
typedef long long ll;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
ostream& operator<<(ostream& o,P p){return o<<"("<<p.first<<","<<p.second<<")";}
istream& operator>>(istream& i,P &p){return i>>p.first>>p.second;}
ostream& operator<<(ostream& o,vector<auto> &a){int i=0;for(auto t:a)o<<(i++?" ":"")<<t;return o;}
istream& operator>>(istream& i,vector<auto> &a){for(auto &t:a)i>>t;return i;}
void prArr(auto a,string s=" "){int i=0;for(auto t:a)cout<<(i++?s:"")<<t;cout<<endl;}

int h,w;
vector<string> mp;

int bfs(char sx,int sy,char goal){
  vector<vector<int> > D(h,vector<int>(w,INF));
  
  queue<P> Q;
  Q.push(P(sx,sy));
  D[sy][sx] = 0;

  int dx[] = {0,0,1,-1};
  int dy[] = {1,-1,0,0};

  auto in=[&](int x,int y){return !(x < 0 || y < 0 || x >= w || y >= h);};
  auto go=[&](int x,int y,int i,char ch){
    while(1){
      int nx = x + dx[i];
      int ny = y + dy[i];
      if(!in(nx,ny)) return P(-1,-1);
      
      if((mp[ny][nx] != ch && !isupper(mp[ny][nx]))) return P(-1,-1);
      if(isupper(mp[ny][nx])) return P(nx,ny);
      x = nx;
      y = ny;
    }
  };
  
  while(!Q.empty()){
    P t = Q.front();Q.pop();
    int x = t.first;
    int y = t.second;

    if(mp[y][x] == goal) return D[y][x];
    
    for(int i=0;i<4;i++){
      int nx = x + dx[i];
      int ny = y + dy[i];
      auto to = go(nx,ny,i,mp[ny][nx]);
      if(to == P(-1,-1)) continue;
      tie(nx,ny) = to;
      if(D[ny][nx] != INF) continue;

      D[ny][nx] = D[y][x] + 1;
      Q.push(P(nx,ny));
    }
  }
  assert(0);
}

signed main(){

  char s,t;
  cin>>h>>w>>s>>t;
  mp.resize(h);
  cin>>mp;

  int sx,sy;
  for(int i=0;i<h;i++)
    for(int j=0;j<w;j++){
      if(!isupper(mp[i][j])) continue;
      mp[i-1][j] = mp[i+1][j] = '|';
      mp[i][j-1] = mp[i][j+1] = '-';
      if(mp[i][j] == s) sx = j, sy = i;
    }

  int ans = bfs(sx,sy,t);

  cout<<ans<<endl;

  
  return 0;
}



Measured memory_bytes: 3216
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
using namespace std;
typedef long long ll;

int main(){

    int n; cin >> n;

    int x[n], y[n], h[n];
    for(int i=0; i<n; i++){
        cin >> x[i] >> y[i] >> h[i];
    }

    int itg = 0;
    for(int i=0; i<n; i++){
        if(h[i] > 0){
            itg = i;
        }
    }

    int ansx, ansy, ansh;
    bool isAnswer = true;
    for(int i=0; i<=100; i++){
        for(int j=0; j<=100; j++){
            int top = h[itg] + abs(i - x[itg]) + abs(j - y[itg]);
            
            isAnswer = true;
            for(int k=0; k<n; k++){
                if(k == itg) continue;

                if(max(0, top - abs(x[k] - i) - abs(y[k] - j)) != h[k]){
                    isAnswer = false;
                }
            }
            if(isAnswer){
                ansx = i;
                ansy = j;
                ansh = top;
                break;
            }
        }
        if(isAnswer) break;
    }

    cout << ansx << " " << ansy << " " << ansh << endl;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int W, H, x, y, r, a, b, c, d;
	scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);
	
	if (W - x >= r && H - y >= r && x - r >= 0 && y - r >= 0)
		printf("Yes\n");
	else
		printf("No\n");
	
	return 0;
}

Measured memory_bytes: 580
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
ll mod = 1000000007;

ll n, k, t, d;
vector<pair<ll, int>> sushi;

int main() {
    cin >> n >> k;
    
    for(int i = 1; i <= n; i++) {
        cin >> t >> d;
        //おいしさを第1要素、ネタを第2要素としてsushiに入れる
        sushi.push_back({d, t});
    }

    //おいしさの昇順にsushiをソート
    sort(sushi.begin(), sushi.end());

    //ネタの種類数を数えるためのmap
    map<int, ll> mp;

    ll ans = 0; //満足ポイント
    ll sum = 0; //おいしさの合計
    ll r = 0; // i < n-k のときに、i番目の寿司とr番目の寿司を入れかえることでネタの種類数を増やす。そのrを調べる変数  

    //おいしさの大きいものから順に調べる
    for(int i = n-1; i >= 0; i--) {
        //おいしさがk番以内に大きい寿司のときは
        if(i >= n-k) {
            //その寿司のネタをキーとするmapの値を1増やして
            mp[sushi[i].second]++;
            //sumにその寿司のおいしさを加える
            sum += sushi[i].first;

            //おいしさがk番目に大きい寿司まで調べたら
            if(i == n-k) {
                //sに現時点でのネタの種類数を入れて
                ll s = mp.size();
                //ansに現時点での満足ポイントを入れる
                ans = sum + s*s;
                // i < n-k のときにi番目の寿司と入れ替える候補をn-k番以降から調べる
                r = n-k;
            }
        }
        //おいしさがk番目より小さい寿司のときは
        else {
            //その寿司のネタがmapのキーになかったら(ネタがすでにキーとしてある場合その寿司はネタの種類数を増やせないので調べなくてよい)
            if(!mp.count(sushi[i].second)) {
                //その寿司のネタをキーとするmapの値を1増やす
                mp[sushi[i].second]++;

                //ネタの種類を２個以上の寿司が持つものの中でおいしさが最も小さい寿司の番号rを求める
                while(r <= n-1 && mp[sushi[r].second] == 1) {
                    r++;
                }
                //そのような寿司が存在しない場合もう調べなくてよいのでループを抜ける
                if(r == n) {
                    break;
                }
                
                //おいしさの合計にi番目の寿司のおいしさを加えて, r番目の寿司のおいしさを引く(つまりr番目の寿司の代わりにi番目の寿司を食べる)
                sum += sushi[i].first - sushi[r].first;
                //r番目の寿司のネタをキーとするmapの値を1減らす
                mp[sushi[r].second]--;
                //r番目の寿司を食べてももうネタの種類は増えないので調べなくてよい。次の入れ替える候補はr+1から調べる
                r++;
                //sに現時点でのネタの種類数を入れて
                ll s = mp.size();
                //ansに現時点での満足ポイントの最大値を入れる
                ans = max(ans, sum + s*s);
            }
        }
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5744
#include <iostream>

using namespace std;

int N;
int a[10000];
long long cnt = 0;

int main() {
    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> a[i];
    }
    for (int i = 0; i < N; i++) {
        while (a[i] % 2 == 0) {
            a[i] /= 2;
            cnt++;
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 888
#include <iostream>

using namespace std;

int main()
{
    float cf,cp;
    int n;
    cin>>n;
    cp=n*1.0;
    if(n%2==0){
        cf=n/2;
    }
    else {
        cf=n/2+1;
    }
    cout<<cf/cp;
    return 0;
}


Measured memory_bytes: 256
N,Q = gets.split.map &:to_i
es = {}
es[0] = { 1 => 1 }
es[1] = { 0 => 1 }
(N-1).times {
  a,b = gets.split.map &:to_i
  es[a] ||= {}; es[b] ||= {}
  es[a][b] = es[b][a] = 1
}

accum = Array.new(N+1, 0)
ans = Array.new(N+1, 0)
Q.times {
  p,x = gets.split.map &:to_i
  accum[p] += x
}

stack = [0]
while stack.size > 0 do
  n = stack.pop
  es[n].keys.each{ |m|
    es[m].delete(n)
    ans[m] += ans[n] + accum[m]
    stack << m
  }
end

puts ans[1..-1] * " "

Measured memory_bytes: 93668
#include<stdio.h>
#define INFTY 1000000
#define WHITE 0
#define GRAY 1
#define BLACK 2
int prim();
int n,M[100][100];
int main(void){
  int i,j,e;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      scanf("%d",&e);
      M[i][j]=(e==-1) ? INFTY :e;
    }
  }
  printf("%d\n",prim());
  return 0;
}
int prim(){
  int u,minv,i;
  int d[100],p[100],color[100];

  for(i=0;i<n;i++){
    d[i]=INFTY;
    p[i]=-1;
    color[i]=WHITE;
  }

  d[0]=0;

  while(1){
    minv=INFTY;
    u=-1;
    for(int i=0;i<n;i++){
      if(minv>d[i]&&color[i]!=BLACK){
	u=i;
	minv=d[i];
      }
     }
    if(u==-1)
      break;
    color[u]=BLACK;
    for(int v=0;v<n;v++){
      if(color[v]!=BLACK&&M[u][v]!=INFTY){
	if(d[v]>M[u][v]){
	  d[v]=M[u][v];
	  p[v]=u;
	  color[v]=GRAY;
	}
      }
    }
  }
  int sum=0;
  for(i=0;i<n;i++){
    if(p[i]!=-1)
      sum+=M[i][p[i]];
  }
  return sum;
}
    
  
  
  



Measured memory_bytes: 2088
import java.io.BufferedReader
import java.util.*
import kotlin.math.max

fun main() = agc024b()

@OptIn(ExperimentalStdlibApi::class)
fun agc024b() = SimpleFastIOWithToken_agc024b().exec {
    val n = readInt()
    val pList = IntArray(n) { readInt() - 1 }

    val valueToIndex = IntArray(n)
    repeat(n) { valueToIndex[pList[it]] = it }
    var maxRaiseStreak = 0
    var left = 0

    while (left in valueToIndex.indices) {
        var right = left
        while (right + 1 in valueToIndex.indices && valueToIndex[right] < valueToIndex[right + 1]) right++
        maxRaiseStreak = max(maxRaiseStreak, right - left + 1)
        left = right + 1
    }

    val answer = n - maxRaiseStreak

    println(answer)
}

// region kokokara template dayo (^o^)
@Suppress("unused", "HasPlatformType", "MemberVisibilityCanBePrivate", "ClassName")
private class SimpleFastIOWithToken_agc024b(private val separator: String = System.lineSeparator()) {
    private val br: BufferedReader = System.`in`.bufferedReader()
    private var st: StringTokenizer = StringTokenizer("")
    private val sb: StringBuilder = StringBuilder()
    private fun prepareNext() = run { if (!st.hasMoreTokens()) st = StringTokenizer(br.readLine()) }

    fun readString(): String = run { prepareNext() }.run { st.nextToken() }
    fun readStringList(size: Int): List<String> = List(size) { readString() }
    fun readInt(): Int = Integer.valueOf(readString())
    fun readIntList(size: Int): List<Int> = List(size) { readInt() }
    fun readLong(): Long = java.lang.Long.valueOf(readString())
    fun readLongList(size: Int): List<Long> = List(size) { readLong() }
    inline fun <reified T> readArray(size: Int, init: () -> T) = Array(size) { init() }
    inline fun <T> readList(size: Int, init: () -> T) = List(size) { init() }

    fun println(): Unit = run { sb.append(separator) }
    fun print(any: Any): Unit = run { sb.append(any) }
    fun println(any: Any): Unit = print(any.toString() + separator)

    fun exec(action: SimpleFastIOWithToken_agc024b.() -> Unit) = run {
        Thread(null, { action() }, "(^o^)", 128 * 1024 * 1024).apply { start() }.join()
    }.run { kotlin.io.print(sb) }

    fun readLine(): Nothing = error("readLine is disabled.")
}
// endregion kokomade template dayo (^o^)


Measured memory_bytes: 57028
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int n,l;
  cin>>n>>l;
  vector<string> s(n);
  for (string &x:s){
    cin>>x;
  }
  sort(s.begin(),s.end());
  for (string &x:s){
    cout << x;
  }
  cout <<endl;
}

Measured memory_bytes: 256
import java.util.Scanner

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    var head = mutableListOf<Char>()
    var tail = sc.next().toMutableList()
    val Q = sc.nextInt()
    for (i in 1..Q) {
        val T = sc.nextInt()
        if (T == 1) {
            val tmp = head
            head = tail
            tail = tmp
        } else {
            val F = sc.nextInt()
            val C = sc.next().first()
            if (F == 1) {
                head.add(C)
            } else {
                tail.add(C)
            }
        }
    }
    val ans = head.joinToString(separator = "").reversed() + tail.joinToString(separator = "")
    println(ans)
}

Measured memory_bytes: 117300
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <stdio.h>
using namespace std;

//typedefリスト
typedef vector<int> vint;
typedef vector<string> vstr;

int main(void) {
	int N, X,mi;
	mi = 1001;
	cin >> N >> X;
	vint m(N);
	for (int i = 0; i < N; i++) {
		cin >> m[i];
		X -= m[i];
		mi = min(m[i], mi);
	}
	cout << N + X / mi << endl;



}


Measured memory_bytes: 256
import sys
from collections import deque
mapin = lambda: map(int, sys.stdin.readline().split())
listin = lambda: list(map(int, sys.stdin.readline().split()))
inp = lambda: sys.stdin.readline()

class UnionFind():
    def __init__(self,n):
        self.N = n
        self.par = [-1] * n
    
    def find(self,n):
        if self.par[n] < 0:
            return n
        else:
            self.par[n] = self.find(self.par[n])
            return self.par[n]
    
    def unite(self,x,y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return False
        else:
            if -self.par[x] < -self.par[y]:
                x,y = y,x
            self.par[x] += self.par[y]
            self.par[y] = x
    
    def size(self,x):
        return -self.par[self.find(x)]
    
    def tree_num(self):
        res = 0
        for i in self.par:
            res += i < 0
        return res
    
    def same(self,x,y):
        return self.find(x) == self.find(y)
    
    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

N,M = mapin()
UF = UnionFind(N)
for i in range(M):
    a,b = mapin()
    a,b = a - 1,b - 1
    UF.unite(a,b)
ans = 0
for i in UF.par:
    if i < 0:
        if ans < -i:
            ans = -i
print(ans)


Measured memory_bytes: 15028
#include <iostream>
#include <algorithm>
using namespace std;
int a,b;
char c;
int main(){
	cin>>a>>b;
	for(int i=0;i<a;i++){
		cin>>c;
		if(c>'9'||c<'0'){
			cout<<"No";
			return 0;
		}
	}
	cin>>c;
	if(c!='-'){
		cout<<"No";
		return 0;
	}
	for(int i=0;i<b;i++){
		cin>>c;
		if(c>'9'||c<'0'){
			cout<<"No";
			return 0;
		}
	}
	cout<<"Yes";
	return 0;
} 

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

#define PI 4*atan(1)
#define INF 1e8

int dx[4] = {1,0,-1,0};
int dy[4] = {0,1,0,-1};

int main(){
  int N;
  string S;
  cin >> N >> S;

  int max = 0;
  int x = 0;
  for(int i = 0; i < S.size(); i++){
    if(S[i] == 'I'){
      x++;
      if(x > max)max = x;
    }
    else if(S[i] == 'D')x--;
  }
  cout << max << endl;
}


Measured memory_bytes: 256
#入力とか変数宣言とか
N, M = gets.split.map(&:to_i)
as = Array.new(M,Array.new(2,0))
ans = Array.new(M,0)
M.times do |i|
  as[i] = gets.split.map(&:to_i)
end
 
#木, $par[i]=iならば根
$par = (0..(N-1)).to_a
 
#ユニオンのサイズを保持する。初期値は1
$size = Array.new(N,1)
 
#ここからUnion-find#
#根を求める関数
def get_root(x)
  if $par[x] == x then
    return x
  else
    #経路圧縮, 根にたどり着くまで再帰
    $par[x] = get_root($par[x])
    return $par[x]
  end
end
 
#xとyが同じ集合に属するか否か
def is_same?(x, y)
  get_root(x)==get_root(y)
end
 
#xとyの属する集合を併合して、不便さの変化deltaを返す
def unite(x,y)
  delta = 0
  x = get_root(x)
  y = get_root(y)
 
  if !(x==y) then
    delta = $size[y]*$size[x]
    x,y = y,x if $size[x]>$size[y]
    #yが新たな親になる
    $par[x]=y
    #サイズを更新
    $size[y] += $size[x]
    $size[x] = 0
  end
  return delta
end
#ここまでUnion-find#
 
#エントリーポイント#
#入力の後ろから繋ぎたいので、入力を逆順にする
as = as.reverse
  
#数列ans[i]の最終項はN*(N-1)/2
ans[M-1] = N*(N-1)/2
  
#一つずつ繋ぎつつ答えをansに格納
(M-1).times do |i|
  #つないで答えをもらってくる
  ans[M-2-i] = ans[M-1-i] - unite(as[i][0]-1,as[i][1]-1)
end
 
puts ans

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

int main() {
    int A, B;
    cin >> A >> B;

    bool isOk = false;
    if (A % 3 == 0 || B % 3 == 0 || (A + B) % 3 == 0) {
        isOk = true;
    }

    if (isOk) {
        cout << "Possible" << endl;
    } else {
        cout << "Impossible" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
from string import ascii_lowercase
from bisect import bisect_right
s = input()
t = input()
p = {c: [] for c in s}
for x, c in enumerate(s):
    p[c].append(x)
z = 0
l = -1
for c in t:
    if c not in p:
        print(-1)
        break
    x = bisect_right(p[c], l)
    if x == len(p[c]):
        x = 0
        z += 1
    l = p[c][x]
else:
    print(z * len(s) + l + 1)


Measured memory_bytes: 47344
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int H = sc.nextInt();
    int W = sc.nextInt();
    for (int i=0; i<W+2; i++) {
      System.out.print("#");    
    }
    System.out.println();
    for (int i=0; i<H; i++) {
      System.out.print("#");
      System.out.print(sc.next());      
      System.out.print("#");
      System.out.println();
    }
    for (int i=0; i<W+2; i++) {
      System.out.print("#");    
    }
   }
}

Measured memory_bytes: 22868
import java.util.HashMap;
import java.util.Scanner;

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

		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();

		HashMap<Integer, Integer>map = new HashMap<Integer, Integer>();

		long total = 0;
		for (int i=0; i<n; i++){
			int a = sc.nextInt();
			total += a;
			if (map.containsKey(a)){
				map.put(a, map.get(a) + 1);
			} else {
				map.put(a, 1);
			}
		}
		int q = sc.nextInt();
		for (int i = 0; i < q; i++){
			int b = sc.nextInt();
			int c = sc.nextInt();
			if (map.containsKey(b)){
				int cnt = map.get(b);
				total += (c-b) * cnt;
				map.put(b, 0);
				if (map.containsKey(c)){
					map.put(c, map.get(c) + cnt);
				} else {
					map.put(c, cnt);
				}
			}
			System.out.println(total);
		}
	}

}

Measured memory_bytes: 64372
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define sd(n) scanf("%d",&n)
#define sl(n) scanf("%lld",&n)
#define pd(n) printf("%d",n)
#define pl(n) printf("%lld",n)
#define sf(n) scanf("%Lf",&n)
#define pf(n) printf("%.12Lf",n)
#define psp printf(" ")
#define endc printf("\n")

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;

const int maxn = 4e4 + 600;
const ld  eps  = 1e-10;
const ld LIM = 3e8;

ld a[maxn];
ld b[maxn];
ld c[maxn];
int occ[maxn];
int n; ld sep;
int bit[maxn];


bool sepsort(int i,int j) {
	return ((c[i] - a[i]*sep)/b[i]) < ((c[j] - a[j]*sep)/b[j]);
}

vector<int> getseq(ld z) {
	sep = z;
	vector<int> ans; for (int i = 1; i <= n; i++) ans.pb(i);
	sort(ans.begin(), ans.end(), sepsort);

	return ans;
}

void upd(int x) {
	while (x < maxn) { bit[x]++; x += x & (-x); }
}

int qry(int x) {
	int ans = 0;
	while (x > 0) { ans += bit[x]; x -= x & (-x); }
	return ans;
}

int inv(vector<int> A) {
	for (int i = 0; i < n; i++) A[i] = occ[A[i]];
	fill(bit, bit + maxn, 0);

	int ans = 0;

	for (int i = n - 1 ; i >= 0; i--) {
		ans += qry(A[i]); upd(A[i]);
	}

	return ans;
}

ld solve() {
	int C = (n * (n - 1)/2)/2;
	vector<int> S = getseq(LIM), Q;
	
	for (int i = 0; i < n; i++) occ[S[i]] = i + 1;

	ld l = -LIM, r = LIM;
	while (r - l > eps) {
		ld mid = (l + r)/2;
		Q = getseq(mid);
		int z = inv(Q);
		if (z > C) l = mid;
		else r = mid;
	}

	return (l + r)/2;
}

int main() {
	sd(n);
	for (int i = 1; i <= n; i++) {
		sf(a[i]); sf(b[i]); sf(c[i]);
	}
	
	ld mx = solve();
	for (int i = 1; i <= n; i++) swap(a[i], b[i]);
	ld my = solve();

	cout<<setprecision(12)<<mx<<" "<<my<<endl;	

	return 0;
}

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

using LL = long long;

int brute_force(LL A, LL B){
	int answer = 0;
	for (int i = A; i <= B; ++i){
		answer ^= i;
	}
	return answer;
}

int number_of_odds(LL A, LL B){
	return (B-A)/2 + ((B&1) | (A&1));
}

int main(){
	LL A, B; cin >> A >> B;
	//cout << "Brute Force: " << brute_force(A, B) << endl;
	LL answer = 0;
	for (int i = 62; i >= 1; --i){
		if (B < (1LL << i)) continue;
		LL left_removed = 0, right_removed = 0;
		if (A & (1LL << i)){
			left_removed = (1LL << i) - (A % (1LL << i));
		}
		if (B & (1LL << i)){
			right_removed = (1LL << i) - 1 - (B % (1LL << i));
		}
		answer |= (((left_removed + right_removed) & 1) << i);
	}
	if (number_of_odds(A, B) & 1){
		answer += 1;
	}
	cout << answer << endl;
	return 0;
}

Measured memory_bytes: 256
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <tuple>
# include <unordered_map>
# include <numeric>
# include <complex>
# include <bitset>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
typedef pair<LL, LL> P;
constexpr int INF = 2000000000;
constexpr int HINF = INF / 2;
constexpr double DINF = 100000000000000000.0;
constexpr long long LINF = 9223372036854775807;
constexpr long long HLINF = 4500000000000000000;
constexpr long long MMOD = 500000004;
const double PI = acos(-1);
int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
# define ALL(x)      (x).begin(),(x).end()
# define UNIQ(c)     (c).erase(unique(ALL((c))), end((c)))
# define mp          make_pair
# define eb          emplace_back
# define FOR(i,a,b)  for(int i=(a);i<(b);i++)
# define RFOR(i,a,b) for(int i=(a);i>=(b);i--)
# define REP(i,n)    FOR(i,0,n)
# define INIT        std::ios::sync_with_stdio(false);std::cin.tie(0)

vector<pair<int,LL>> G[101010];

LL l[202020], r[202020], d[202020];
bool used[101010];
LL pos[101010];
int n, m;

bool serch(int p) {
	queue<int>q;
	q.push(p);

	while (!q.empty()) {
		int Pos = q.front();
		q.pop();
		used[Pos] = true;
		REP(i, G[Pos].size()) {
			if (!used[G[Pos][i].first]) {
				q.push(G[Pos][i].first);
				used[G[Pos][i].first] = true;
				pos[G[Pos][i].first] = pos[Pos] + G[Pos][i].second;
			}
			else {
				if (pos[Pos] + G[Pos][i].second != pos[G[Pos][i].first])return false;
			}
		}
	}
	return true;
}


int main() {
	cin >> n >> m;
	int first;
	REP(i, m) {
		cin >> l[i] >> r[i] >> d[i];
		l[i]--, r[i]--;
		if (!i)first = l[i];
		G[r[i]].emplace_back(mp(l[i], d[i]));
		G[l[i]].emplace_back(mp(r[i], -d[i]));
	}
	REP(i, n)pos[i] = LINF;
	REP(i, n) {
		if (!used[i]) {
			pos[i] = 0;
			if (serch(i) == false) {
				cout << "No" << endl;
				return 0;
			}

		}
	}
	cout << "Yes" << endl;
}

Measured memory_bytes: 18816
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define pb push_back
#define all(v) v.begin(),v.end()
#define fi first
#define se second
#define bigger (char)toupper
#define smaller (char)tolower
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef long long ll;
typedef unsigned long long ull;

int main() {
    int N,T,A;
    cin>>N>>T>>A;
    vector<double> H(N);
    rep(i,N) cin>>H.at(i);
    rep(i,N) H.at(i)=T-(H.at(i)*0.006);
    rep(i,N) H.at(i)-=A;
    rep(i,N) H.at(i)=abs(H.at(i));
    vector<double> C=H;
    sort(H.begin(),H.end());
    int answer;
    rep(i,N) {
        rep(j,N) {
            if(H.at(0)==C.at(j)) answer=j+1;
        }
    }
    cout<<answer<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<string>
#include<cstring>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<bitset>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

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; }

#define mod 1000000007LL
#define eps 0.0001
#define pi acos(-1)
#define INF 10000000000000000

#define rep(i, n) for(int i = 0;i < n;++i)
#define rep1(i, n) for(int i = 1;i < n;++i)
#define pri(x) cout << (x) << "\n"
#define pri2(x, y) cout << (x) << " " << (y) << "\n"
#define pri3(x, y, z) cout << (x) << " " << (y) << " " << (z) << "\n"
#define chmin

#define lset(h, n) memset(h, n, sizeof(h));
    

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    // ---------------------
    // コーディング開始
    // ---------------------
    ll n;
    ll y;
    cin >> n >> y;
    
    ll le = y/1000 - n;
    if(le < 0 ) {
        pri3("-1","-1","-1");
        return 0;
    }
    rep(i,le/4+1){
        rep(j,le/9+1){
           if(i*4+j*9==le){
               if(n>=i+j){
                pri3(j,i,n-i-j);
                return 0;
               }
           }
        }
        if(i==le/4){
            pri3("-1","-1","-1");
            return 0;
        }
    }
}



Measured memory_bytes: 256
R, G, B, N = map(int, input().split())
p1, p2, p3 = sorted([R, G, B], reverse=True)

count = 0

if N % p1 == 0:
    count += 1
for _p1 in range(N // p1, -1, -1):
    existP1 = N - p1 * _p1

    if existP1 >= p2 and existP1 % p2 == 0:
        #print("p1={}*{}, p2={}*{}".format(p1, _p1, p2, existP1 // p2))
        count += 1
    for _p2 in range(existP1 // p2, -1, -1):
        existP2 = existP1 - p2 * _p2
        if existP2 >= p3 and existP2 % p3 == 0:
            count += 1        
            
print(count)

Measured memory_bytes: 3064
#include <iostream>
using namespace std;
int main(){
  int a,b,k;
  while(cin >> a >> b){
    if(a <= 1000000 && b <= 1000000 && 0 <= a && 0<= b){
      a = a + b;
      for(int j=10000000,k=8;j>=1;j/=10,k--){
	if((b = a/j)>0){
	  cout << k << endl;
	  break;
	}
      }
    }
  }
  return 0;
}

Measured memory_bytes: 1160
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int x = sc.nextInt();
		int n = sc.nextInt();
if(n==0){System.out.println(x);}else{
		int p[] = new int[n];
		int q[] = new int[102 - n];
		q[0] = 0;
		q[101 - n] = 101;
		for (int i = 0; i < n; i++) {
			p[i] = sc.nextInt();
		}

		Arrays.sort(p);
		int look = 0;
		int lookb = 0;
		for (int i = 0; i <= 101; i++) {
			if (!(p[lookb] == i)) {
				// System.out.println("!"+i);
				q[look] = i;
				look++;

			} else {
				lookb++;
				if (lookb >= n) {
					lookb--;
				}
			}
		}
/*		for (int i = 0; i < q.length; i++) {
			System.out.println(q[i]);
		}
*/
		int sub=x;
		int ans=0;
for(int i=0;i<q.length;i++){
if(sub>Math.abs(q[i]-x)){
	sub=Math.abs(q[i]-x);
	ans=q[i];
}
}System.out.println(ans);
}
	}
}

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

int mod = 1000000007;
int c[200001];
int nx[200001];
int dp[200001];
int n;

ll f(int i) {
  if(i==n) return 1;
  if(dp[i]) return dp[i];
  if(!nx[i] || nx[i]==i+1){
    dp[i] = f(i+1) % mod;
  } else{
    dp[i] = (f(i+1) + f(nx[i])) % mod;
  }
  
  return dp[i];
}

int main(void) {
  cin >> n;

  map<int,int> m;
  for (int i = 1; i <= n; i++) {
    cin >> c[i];
    if(m[c[i]]){
      nx[m[c[i]]] = i;
    }
    m[c[i]]=i;
  }
  
  cout << f(1) << endl;
  
  return 0;
}


Measured memory_bytes: 17408
#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#define llint long long
#define inf 1e18
#define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++)
#define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))

using namespace std;
typedef pair<llint, llint> P;

llint n;

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n;
	for(int i = 0; i < n; i++){
		for(int j = 0; j < n; j++){
			if(i >= j) continue;
			for(int k = 0; ; k++){
				if(((i>>k)&1) != ((j>>k)&1)){
					cout << k+1 << " ";
					break;
				}
			}
		}
		cout << endl;
	}
	
	return 0;
}

Measured memory_bytes: 512
N, M, L = map(int, input().split())
INF = 10**18
G = [[INF]*N for i in range(N)]
for i in range(M):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    if c <= L:
        G[a][b] = c
        G[b][a] = c
for k in range(N):
    for i in range(N):
        for j in range(N):
            G[i][j] = min(G[i][j], G[i][k]+G[k][j])
G2 = [[INF]*N for i in range(N)]
for i in range(N):
    for j in range(N):
        if G[i][j] <= L:
            G2[i][j] = 1
for k in range(N):
    for i in range(N):
        for j in range(N):
            G2[i][j] = min(G2[i][j], G2[i][k]+G2[k][j])
Q = int(input())
ans = []
for i in range(Q):
    s, t = map(int, input().split())
    s -= 1
    t -= 1
    if G2[s][t] == INF:
        ans.append(-1)
    else:
        ans.append(G2[s][t]-1)
print(*ans, sep="\n")


Measured memory_bytes: 68184
ans = []
while True:
    n = int(input())
    if n == 0:
        break
    s = list(map(int, input().split()))
    mean = sum(s)/n
    alpha = 0
    for i in range(n):
        alpha += (s[i] - mean)**2
    alpha = (alpha/n)**(1/2)
    ans.append(alpha)

for i in range(len(ans)):
    print(ans[i])


Measured memory_bytes: 5672
/*|In The Name Of Allah|*/

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N = 1e5+5;

ll n , k;

int main(){
    cin >> n >> k;
    if(n % k == 0){
        cout << 0 << endl;
    } else {
        cout << min(n , abs( (n % k) - k));
    }
}


Measured memory_bytes: 256
n=int(input())
a=[]
for i in range(n):
    a.append(int(input()))
visited={}
for i in range(1,n+1):
    visited[i]=-1
count=0
i=0
while True:
    count+=1
    if visited[a[i]]==0:
        print("-1")
        exit()
    if a[i]==2:
        print(count)
        exit()
    visited[a[i]]=0
    i=a[i]-1


Measured memory_bytes: 90156
#include <iostream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <functional>
#include <vector>
#include <map>
#include <set>
#include <tuple>

using namespace std;

#define D(x) x
#define REP(i,a,b) for (int i = (a); i < (b); ++i)

int main() {
    ios_base::sync_with_stdio(false);
    cout << setprecision(12) << fixed;

    int H, W; cin >> H >> W;
    char A[H][W];
    REP(h,0,H) {
        REP(w,0,W) {
            cin >> A[h][w];
        }
    }

    REP(w,0,W) {
        cout << '#';
    }
    cout << endl;

    REP(h,1,H-1) {
        REP(w,0,W) {
            if (w % 2 == 0 || A[h][w] == '#') {
                cout << '#';
            } else {
                cout << '.';
            }
        }
        cout << endl;
    }

    REP(w,0,W) {
        cout << A[H-1][w];
    }
    cout << endl << endl;

    REP(w,0,W) {
        cout << A[H-1][w];
    }
    cout << endl;

    REP(h,1,H-1) {
        REP(w,0,W) {
            if (w % 2 == 1 || A[h][w] == '#') {
                cout << '#';
            } else {
                cout << '.';
            }
        }
        cout << endl;
    }

    REP(w,0,W) {
        cout << '#';
    }
    cout << endl;

	return 0;
}


Measured memory_bytes: 1024
var N,K,i,c,j,a:Longint;
ex:Array[1..100]of Boolean;
begin
read(N,K);
for i:=1 to K do begin
read(c);
for j:=1 to c do begin
read(a);
if not ex[a]then begin
ex[a]:=True;
dec(N);
end;
end;
end;
writeln(N);
end.

Measured memory_bytes: 1328
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include <functional>
#include<time.h>
#include <stack>
#include<iomanip>
using namespace std;
#define rep(i,a,n) for(int i=(a);i<(n);i++)
#define ll long long
#define llint long long int
#define reverse(v)  reverse(v.begin(), v.end());
#define Yes(ans) if(ans)cout<<"Yes"<<endl; else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl; else cout<<"NO"<<endl;
#define hei(a) vector<a>
#define whei(a) vector<vector<a>>
#define UF  UnionFind 
#define Pint pair<int,int>
#define keta(a)  fixed << setprecision(a)
constexpr auto INF = 100000000000;
constexpr auto mod = 1000000007;
//辞書順はnext_permutation( begin( v ), end( v ) );やで！
// lower_boundは二分探索
struct edge { int to, cost; };
long long modpow(long long a, long long n, long long mod) {
	long long res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}

// mod. m での a の逆元 a^{-1} を計算するよ！
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}


//aCbをmod.mで割った余りを求める
ll int c(ll int a, ll int b, ll int m) {
	ll int ans = 1;
	for (ll int i = 0; i < b; i++) {
		ans *= a - i;
		ans %= m;
	}
	for (ll int i = 1; i <= b; i++) {
		ans *= modinv(i, m);
		ans %= m;
	}
	return ans;
}

//sは初めの点、vは頂点size、dは最短距離を求める(初期化はINF),Gは有向グラフ
void dijkdtra(int s, int v, vector<int>& d, whei(edge)& G) {
	priority_queue<Pint, vector<Pint>, greater<Pint>> que;//firstが距離、secondが頂点
	d[s] = 0;//スタートの距離はもちろんzero
	que.push(Pint(0, s));
	while (!que.empty()) {
		Pint p = que.top();
		que.pop();
		int V = p.second;
		if (d[V] < p.first)continue;
		for (int i = 0; i < G[V].size(); i++) {
			edge e = G[V][i];
			if (d[e.to] > d[V] + e.cost) {
				d[e.to] = d[V] + e.cost;
				que.push(Pint(d[e.to], e.to));
			}
		}
	}
}

llint binary_search(vector<int>&s,int a) {
	llint l = -1;
	llint r = (llint)s.size();
	while (r - l > 1) {
		llint mid = l + (r - l) / 2;

		if (s[mid]>=a) r = mid;
		else l = mid;
	}
	return r;
}

//remono君のコード書き換え
int main() {
	int n;
	cin >> n;
	hei(int) a(n), b(n), c(n);
	rep(i, 0, n)cin >> a[i];
	rep(i, 0, n)cin >> b[i];
	rep(i, 0, n)cin >> c[i];
	sort(a.begin(), a.end());
	sort(b.begin(), b.end());
	sort(c.begin(), c.end());
	llint ans = 0;
	rep(i, 0, n) {
		ans += (binary_search(a, b[i]))*(n -binary_search(c, b[i]+1));
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <algorithm>
#include <iterator>
#include <string>
#include <vector>
#include <stack>
#include <math.h>
#include<bits/stdc++.h>
using namespace std;
#define ll long long
typedef pair<int, int> pii;
int main(){
priority_queue <ll int> q;
ll int n,m,k,i,used=0,sum=0;
cin>>n>>m;
for(i=0;i<n;i++){
  cin>>k;
  q.push(k);
}
while(used<m){
  k=q.top();
  q.pop();
  q.push(k/2);
  used++;
}
while( !(q.empty()) ){
  sum+=q.top();
  q.pop();
}
cout <<sum<<endl;
}


Measured memory_bytes: 1400
import sys, re
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2
from collections import deque, defaultdict, Counter
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop, heapify
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

class UnionFind():
    def __init__(self, n):
        self.n = n
        # parents[i]: 要素iの親要素の番号
        # 要素iが根の場合、parents[i] = -(そのグループの要素数)
        self.parents = [-1] * n
    def find(self, x):
        if 0 > self.parents[x]:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x
    # 要素xが属するグループの要素数を返す
    def size(self, x):
        return -self.parents[self.find(x)]
    def same(self, x, y):
        return self.find(x) == self.find(y)
    # 要素xが属するグループに属する要素をリストで返す
    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]
    # 全ての根の要素をリストで返す
    def roots(self):
        return [i for i, x in enumerate(self.parents) if 0 > x]
    # グループの数を返す
    def group_count(self):
        return len(self.roots())
    # 辞書{根の要素: [そのグループに含まれる要素のリスト], ...}を返す
    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}
    # print()での表示用
    # all_group_members()をprintする
    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


N, M, K = MAP()
friends = defaultdict(list)
tree = UnionFind(N)
for _ in range(M):
	A, B = MAP()
	tree.union(A-1, B-1)
	friends[A-1].append(B-1)
	friends[B-1].append(A-1)

blocks = defaultdict(list)
for _ in range(K):
	C, D = MAP()
	blocks[C-1].append(D-1)
	blocks[D-1].append(C-1)

for i in range(N):
	minus = 0
	for b in blocks[i]:
		if tree.same(i, b):
			minus += 1
	print(tree.size(i)-len(friends[i])-1-minus, end = " ")
print()

"""
print("friends")
print(friends)

print("blocks")
print(blocks)

i = 1
print("i={}".format(i))
print("tree.size(i)={}".format(tree.size(i)))
print("tree.find(i))={}".format(tree.find(i)))
print("tree.members(i)={}".format(tree.members(i)))
print("tree.roots={}".format(tree.roots()))
print("tree.group_count={}".format(tree.group_count()))
print("tree.all_group_members={}".format(tree.all_group_members()))
"""



Measured memory_bytes: 66796
#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e5+10;
typedef long long ll;
int a[maxn],rt[maxn];
int lc[maxn*40],rc[maxn*40],tol;
ll sum[maxn*40];
map<int,int>vis;
void init(){
	tol=1;
	vis.clear();
}
void update(int &u, int x, int y, int p, ll v)
{
    sum[tol] = sum[u]+v,lc[tol] = lc[u],rc[tol] = rc[u];
    u = tol++;
    if(x == y) return;
    int m = (x+y)>>1;
    if(p <= m) update(lc[u],x,m,p,v);
    else update(rc[u],m+1,y,p,v);
}
ll query(int u, int x, int y, int ql, int qr)
{
    if(ql <= x && y <= qr) return sum[u];
    int m = (x+y)>>1;
    ll ans = 0;
    if(ql <= m) ans += query(lc[u],x,m,ql,qr);
    if(qr > m) ans += query(rc[u],m+1,y,ql,qr);
    return ans;
}
int main(){
	int n,q;
	init();
	scanf("%d%d",&n,&q);
	for(int i=1;i<=n;i++)scanf("%lld",&a[i]);
	for(int i=1;i<=n;i++){
		rt[i]=rt[i-1];
		if(vis.find(a[i])!=vis.end())
		{
			int tmp=rt[i-1];
			update(tmp,1,n,vis[a[i]],-1);
			rt[i]=tmp;
			update(rt[i],1,n,i,1);
		}
		else
		{
			rt[i] = rt[i-1];
            update(rt[i],1,n,i,1);
        }
        vis[a[i]]=i;
	}
	while(q--){
		int l,r;
		scanf("%d%d",&l,&r);
		printf("%lld\n",query(rt[r],1,n,l,r));
	}
	return 0;

}


Measured memory_bytes: 318984
#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <bitset>

#include <queue>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <ctime>
////
//#include <random>//
/////////

typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;

////定数
const int INF = (int)1e9 + 10;
const LL MOD = (LL)1e9 + 7;
const LL LINF = (LL)4e18 + 20;
const LD PI = acos(-1.0);
const double EPS = 1e-9; 
/////////
using namespace::std;
//////////////
int N;
int root = 0;
vector< vector<int> > G;
vector<LL> V;
vector<bool> use;
void cal(int p,LL asd) {
	use[p] = true;
	V[p] += asd;
	int len = G[p].size();
	for (int i = 0; i < len; ++i) {
		int ter = G[p][i];
		if (use[ter] == true)continue;
		cal(ter, V[p]);
	}
}
void solve() {
	int N, Q;
	cin >> N >> Q;
	G = vector<vector<int>>(N);
	V = vector<LL>(N, 0);
	use = vector<bool>(N, false);

	for (int i = 0; i < N - 1; ++i) {
		int a, b;
		cin >> a >> b;
		--a; --b;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	for (int i = 0; i < Q; ++i) {
		LL p, x;
		cin >> p >> x;
		--p;
		V[p] += x;
	}
	
	cal(root,0);
	LL ans = 0;
	for (int i = 0; i < N; ++i) {
		cout << V[i] << " ";
	}
	//cout << ans << endl;
}

signed main(void) {
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}


Measured memory_bytes: 24320