akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <deque>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;

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

	auto result = -1;
	if (sum >= 0)
	{
		result = 0;
		vector<ll> diff(N);
		auto num = 0ll;
		for (auto i = 0; i < N; ++i)
		{
			diff[i] = A[i] - B[i];
			if (diff[i] < 0)
			{
				num += diff[i];
				++result;
			}
		}

		sort(diff.begin(), diff.end(), greater<ll>());

		for (auto i = 0; i < N && num < 0; ++i)
		{
			num += diff[i];
			++result;
		}
	}

	cout << result << endl;

	return 0;
}

Measured memory_bytes: 2560
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		String S = sc.next(); String ans = S.concat("");

		int left = 0, right = 0;

		// left
		for(int i = 0; i < N; i++) {
			if(S.charAt(i) == '(') left++;
			else if(left > 0) left--;
		}
		// ans + ')' * left
		while(left > 0) {
			ans += ")";
			left--;
		}

		//right
		for(int i = N - 1; i >= 0; i--) {
			if(S.charAt(i) == ')') right++;
			else if(right > 0) right--;
		}
		// '(' * right + ans
		while(right > 0) {
			ans = "(" + ans;
			right--;
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 21844
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
#include <map>
#include <unordered_map>
#include <chrono>
#include <numeric>
using namespace std;
using ll = long long;
const ll INF = (ll)1e18+1;
const ll DIV = 1000000007;
//#define TEST
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
#ifdef TEST
    chrono::system_clock::time_point start, end;
    start = chrono::system_clock::now();
#endif
    long K;
    long A, B;
    cin >> K;
    cin >> A >> B;
    ll ans = B / K;
    if(ans * K >= A && ans * K <= B) cout << "OK" << endl;
    else cout << "NG" << endl;

#ifdef TEST
    end = chrono::system_clock::now();
    cerr << static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count() / 1000.0) << "[ms]" << endl;
#endif
    return 0;
}

Measured memory_bytes: 3656
fun main(args : Array<String>) {
    val (n, k) = readLine()!!.split(" ").map { it.toInt() }
    val pp = readLine()!!.split(" ").map { it.toInt() }

    var sum = 0
    var max = 0
    var maxIndex = 0

    repeat(k) {
        sum += pp[it]
    }

    for (i in k until n) {
        sum += pp[i]
        sum -= pp[i-k]

        if (sum > max) {
            max = sum
            maxIndex = i-k+1
        }
    }

    var ans = 0.0
    for (i in maxIndex until maxIndex+k) {
        var tmpSum = 0
        repeat(pp[i]) {
            tmpSum += it + 1
        }

        ans += tmpSum.toDouble() / pp[i].toDouble()
    }

    println(ans)
}



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

void trace(int A[], int N)
{
    for (int i = 0; i < N; i++)
    {
        if (i > 0)
        {
            printf(" ");
        }
        printf("%d", A[i]);
    }
    printf("\n");
}

int selectionSort(int A[], int N)
{
    int cnt = 0;
    for (int i = 0; i < N; i++)
    {
        int minj = i;
        for (int j = i; j < N; j++)
        {
            if (A[j] < A[minj])
            {
                minj = j;
            }
        }
        if (i != minj)
        {
            swap(A[i], A[minj]);
            cnt++;
        }
    }
    return cnt;
}

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

    int A[N];

    for (int i = 0; i < N; i++)
    {
        scanf("%d", &A[i]);
    }
    
    int cnt = selectionSort(A, N);
    trace(A, N);
    printf("%d%s", cnt, "\n");

    return 0;
}


Measured memory_bytes: 3228
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> Pl;
typedef pair<double,double> Pd;
#define all(a) (a).begin(),(a).end()
#define rep(i,n) repi(i,0,(n))
#define repi(i,a,b) for(ll i=(a);i<(b);i++)
#define rrep(i,n) rrepi(i,(n),0)
#define rrepi(i,a,b) for(ll i=(a);i>=(b);i--)
#define SHOW(x) cout << #x << ": " << x << endl;
const double Pi = acos(-1);
const ll INF=1e18;
const int iINF = 1e9;

int main(){
  int n;
  bool flag = false;
  cin>>n;
  repi(i,1,10)repi(j,1,10)if(n == i*j)flag = true;
  if(flag)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <numeric>
#include <cmath>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, k, n) for(int i = (k); i < (int)(n); i++)
using namespace std;
using ll = long long;

int main(){
    int N, cnt = 0, ans = 0, tmp = 0;
    int A, B;
    cin >> A >> B;
    if(A * B % 2 == 1)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
#include <iomanip>
using namespace std;
#define PI  3.14159265358979323846264338327950

int main(){
  long double a,b,h,m;
  cin >> a >> b >> h >> m;
  long double A,B,C,X,rad,ans;
  A = 30*h + 0.5*m;
  B = 6*m;
  C = min(A,B);
  A = max(A,B);
  B = C;
  X = min(A-B,360-A+B);
  rad = X*PI/180;
  ans = a*a + b*b - 2*a*b*cosl(rad);
  ans = sqrtl(ans);
  cout << std::setprecision(10) << ans << endl;  
    
  return 0;
}


Measured memory_bytes: 4080
#include <stdio.h>

int main()
{
    int H, W, x, y;
    while(1)
    {
        scanf("%d %d",&H, &W);
        if(H == 0 && W == 0) break;
        for(y = 1; y <= H; y++)
        {
            for(x = 1; x <= W; x++)
            {
                if((x + y) % 2 == 0)
                {
                    printf("#");
                }
                else
                {
                    printf(".");
                }
            }
            printf("\n");
        }
        printf("\n");
    }
    return 0;
}

Measured memory_bytes: 572
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;




int main() {	
	int N;long long int A,B;cin>>N>>A>>B;
	vector<vector<pair<long long int,long long int>>>vs(5,vector<pair<long long int,long long int>>(1,make_pair(0,0)));
	for (int i = 0; i < N; ++i) {
		int t;
		long long int x,y;cin>>t>>x>>y;t--;
		vs[t].push_back(make_pair(x,y));
	}
	sort(vs.begin(), vs.end(), [](const vector<pair<long long int,long long int>>&l, const vector<pair<long long int,long long int>>&r) {return l.size() < r.size(); });
	vector<pair<long long int,long long int>>l;
	vector<pair<long long int,long long int>>r;
	for (auto v1 : vs[0]) {
		for (auto v2 : vs[1]) {
			for (auto v3 : vs[2]) {
				l.emplace_back(v3.first+v1.first+v2.first,v1.second+v2.second+v3.second);
			}
		}
	}
	for (auto v1 : vs[3]) {
		for (auto v2 : vs[4]) {
			r.emplace_back( v1.first + v2.first, v1.second + v2.second );
		}
	}
	sort(l.begin(),l.end());
	sort(r.begin(),r.end(),greater<pair<long long int,long long int>>());
	auto rt=r.begin();
	auto lt=r.begin();
	map<long long int,int>nb;
	bool ok=false;
	for (auto n:l) {
		while (rt != r.end()) {
			if (rt == r.end())break;
			if (rt->first + n.first >=A) {
				nb[rt->second]++;
				rt++;
			}else{
				break;
			}
		}
		while (lt !=r.end()) {
			if (lt == r.end())break;
			if (lt->first + n.first >B) {
				nb[lt->second]--;
				if(nb[lt->second]==0)nb.erase(lt->second);
				lt++;
			}else{
				break;
			}
		}
		auto at=nb.lower_bound(A-n.second);
		auto bt=nb.upper_bound(B-n.second);
		if(at!=bt)ok=true;
	}
	if(ok)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 19720
N, M = map(int, input().split())
AB = []
for i in range(M):
    a, b = map(int, input().split())
    AB.append([b, a])
AB.sort()
for i in range(M):
    if i == 0:
       j = AB[i][0] - 1
       ans = 1
    else:
        if AB[i][1] <= j and j < AB[i][0]:
            1
        else:
            j = AB[i][0] - 1
            ans += 1

print(ans)


Measured memory_bytes: 20072
#include <bits/stdc++.h>
#define PI 3.1415926535897932
#define _GLIBCXX_DEBUG
using namespace std;
int main() {
  
  int N,T;
  cin>>N>>T;
  
  vector<vector<int>> P(N,vector<int>(2));
  for(int i=0;i<N;i++){
    cin>>P[i][0]>>P[i][1];
  }
  
  int mini=10000000;
  
  
  for(int i=0;i<N;i++){
    if(P[i][1]<=T){
      mini=min(mini,P[i][0]);
    }
  }
  
  if(mini==10000000){
    cout<<"TLE"<<endl;
  }
  else{
    cout<<mini<<endl;
  }
}

Measured memory_bytes: 3552
n=gets.chomp.to_i

a=Array.new(n)

n.times do |i|
  a[i] = gets.chomp.to_s
end

a=a.uniq

if a.length != n
  puts "No"
  exit
end

str = a[0][a[0].length-1]

for i in 1..n-1 do
  if a[i][0] != str
    puts "No"
    exit
  end
  str = a[i][a[i].length-1]
end

puts "Yes"

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


int nextInt() { int x; scanf("%d", &x); return x;}

const int MAX_N = 111;
int x[MAX_N], y[MAX_N], h[MAX_N];

int main2() {
  int N = nextInt();
  REP(i, N) {
    x[i] = nextInt();
    y[i] = nextInt();
    h[i] = nextInt();
  }

  for (int cx = 0; cx <= 100; cx++) {
    for (int cy = 0; cy <= 100; cy++) {
      map<int, int> count;
      int n = 0;
      int cap = 1001001001;
      REP(i, N) {
        int d = abs(cx - x[i]) + abs(cy - y[i]);
        if (h[i] == 0) {
          cap = min(cap, d);
        } else { 
          n++;
          count[h[i] + d]++;
        }
      }
      for (auto it = count.begin(); it != count.end(); ++it) {
        if (1 <= it->first && it->first <= cap && it->second == n) {
          cout << cx << " " << cy << " " << (it->first) << endl;
          return 0;
        }
      }
    }
  }

  return 0;
}

int main() {
  for (;!cin.eof();cin>>ws)
    main2();
  return 0;
}


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

int main(){
  int N,L;
  cin >> N >> L;
  vector<string> vec(N);
  for(int i = 0; i < N; i++){
    cin >> vec.at(i);
  }
  sort(vec.begin(),vec.end());
  
  string ans = "";
  for(int i = 0; i < N; i++){
    ans += vec.at(i);
  }
  cout << ans << endl;
}
  

Measured memory_bytes: 256
N, A, B = [ int(i) for i in input().split() ]

AB = A+B
for i in input():
    if AB > 0:
        if i == "a":
            AB -= 1
            print('Yes')
            continue
        elif i == 'b':
            if B > 0:
                B -= 1
                AB -= 1
                print('Yes')
                continue
    print('No')



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

int main(){
  vector<int> s(3);
  for(int i=0;i<3;i++){
    cin >> s.at(i);
  }
  
  sort(s.begin(),s.end());
  
  if(s.at(0)==s.at(1)&&s.at(1)!=s.at(2)){
    cout << 2 << endl;
  }else if(s.at(0)!=s.at(1)&&s.at(1)==s.at(2)){
    cout << 2 << endl;
  }else if(s.at(0)==s.at(1)&&s.at(1)==s.at(2)){
    cout << 1 << endl;
  }else{
    cout << 3 << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL); 

#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define in insert
#define ld long double


#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...) 1
#endif
template<class T> ostream& operator<<(ostream &os, vector<T> V) {os << "[ "; for(auto v : V) os << v << " "; return os << "]";}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {return os << "(" << P.first << "," << P.second << ")";}
template <typename T,typename U>pair<T,U> operator+(const pair<T,U> & l,const std::pair<T,U> & r) { return {l.first+r.first,l.second+r.second};}
typedef long long int ll;

typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
#define int ll
const ll mod =1e9+7;
const ll MAX_NODES =200001;
const ll MAX_LOG =50;
const ll maxn = 400000+10;
const ll md = (ll) 1e9 + 7;
 
inline ll add(ll a, ll b) {
  a += b;
  if (a >= md) a -= md;
  return a;
}
 
inline ll sub(ll a, ll b) {
  a -= b;
  if (a < 0) a += md;
  return a;
}
 
inline ll mul(ll a, ll b) {
  return (ll) ((long long) a * b % md);
}
 
inline ll power(ll a, long long b) {
  ll res = 1;
  while (b > 0) {
    if (b & 1) {
      res = mul(res, a);
    }
    a = mul(a, a);
    b >>= 1;
  }
  return res;
}
 
inline ll inv(ll a) {
  a %= md;
  if (a < 0) a += md;
  ll b = md, u = 0, v = 1;
  while (a) {
    ll t = b / a;
    b -= t * a; swap(a, b);
    u -= t * v; swap(u, v);
  }
  assert(b == 1);
  if (u < 0) u += md;
  return u;
}

vector<int> fact(maxn+5);
void init (int n)
{
  fact[0] = 1;
  for(int i = 1;i<=n;i++)
  {
    fact[i] = mul(i,fact[i-1]);
  }
}
int nck(int n,int k)
{
  return mul(fact[n],mul(inv(fact[k]),inv(fact[n-k])));
}


int32_t main()
{
  
   IOS
   init(300000);
   int n,k;
   cin>>n>>k;
   int ans =0;
   for(int i = k;i<=n+1;i++){
       int last = mul(mul(i,(n-i+1+n)),inv(2));
       int first = ((i-1)*(i))/2 ;
       first%=mod;
       ans+=(last-first+1+mod)%mod;
       ans%=mod;         

   }
   cout<<ans<<endl;
	

}

Measured memory_bytes: 6276
#![allow(non_snake_case)]

use std::collections::*;

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

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

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

#[allow(dead_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 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()
    }
}

trait Joinable {
    fn join(self, sep: &str) -> String;
}

impl<U: ToString, T: Iterator<Item = U>> Joinable for T {
    fn join(self, sep: &str) -> String {
        self.map(|x| x.to_string()).collect::<Vec<_>>().join(sep)
    }
}
fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin.bytes().map(|c| c.unwrap() as char));
    let S: String = sc.get();
    let mut q: VecDeque<char> = S.chars().collect();
    let Q: usize = sc.get();
    let mut flip = false;
    for _ in 0..Q {
        let ty: usize = sc.get();
        if ty == 1 {
            flip = !flip;
        } else {
            let mut f: usize = sc.get();
            let c: char = sc.char();
            if flip {
                f = 3 - f;
            }
            if f == 1 {
                q.push_front(c);
            } else {
                q.push_back(c);
            }
        }
    }
    let ans: String;
    if flip {
        ans = q.into_iter().rev().collect();
    } else {
        ans = q.into_iter().collect();
    }
    println!("{}", ans);
}


Measured memory_bytes: 6396
#pragma GCC optimize("trapv")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,sse,sse2,fma,tune=native")
#include<bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define pb push_back
#include <x86intrin.h>
#define pb push_back
using namespace std;
using ll = long long;
using pi = pair<int, int>;
using vi = vector<int>;
const int maxn = 5005, mod = 998244353;
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	string s, t;
	int a, b;
	cin >> s >> t >> a >> b;
	string z;
	cin >> z;
	if(s==z) a--;
	else b--;
	cout << a << " " << b << '\n';
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <vector>
#include <set>
#include <list>
#include <map>
#include <deque>
#include <algorithm>
#include <utility>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
#define for1(i,n) for (ll i=0;i<(n);i++)
#define for2(i,m,n) for (ll i=(m);i<(n);i++)
#define for3(i,m,n,d) for (ll i=(m);i<(n);i+=(d))
#define DEBUG 0
template <class T>
void dumplist(T list)
{
    for (auto item : list) {
        cout << item << " ";
    }
    cout << endl;
}

void solve()
{
    string S;
    cin >> S;
    ll i = 0;
    ll len = S.length();
    ll cntA = 0;
    ll cntBC = 0;
    ll ans = 0;
    string S2;
    list<string> S3;
    for1(i,len) {
        char c = S[i];
        if (c == 'B') {
            if ((i+1 < len) && (S[i+1] == 'C')) {
                S2 += 'X';
                ++i;
            } else {
                S2 += c;
            }
        } else {
            S2 += c;
        }
    }

    len = S2.length();
    string S2s;
    bool flag = false;
    for1(i,len) {
        char c = S2[i];
        if (c == 'A' || c == 'X') {
            S2s += c;
            flag = true;
        } else {
            if (flag) {
                flag = false;
                S3.push_back(S2s);
                S2s = "";
            }
        }
    }
    if (flag) {
        flag = false;
        S3.push_back(S2s);
        S2s = "";
    }

    for (string s3: S3) {
        ll sc = 0;
        for (char c3: s3) {
            if (c3 == 'A') {
                sc += 1;
            } else if (c3 == 'X') {
                ans += sc;
            }
        }
    }
    //dumplist(S3);

    cout << ans << endl;
}

int main()
{
    do {
        solve();
    } while (DEBUG);
}


Measured memory_bytes: 4488
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using uint = unsigned int;
#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 per(i,n) for(int i=int(n)-1;i>=0;i--)
#define per1(i,n) for(int i=int(n);i>0;i--)
#define all(c) c.begin(),c.end()
#define si(x) int(x.size())
#define pb emplace_back
#define fs first
#define sc second
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;
template<class T,class U> void chmax(T& x, U y){if(x<y) x=y;}
template<class T,class U> void chmin(T& x, U y){if(y<x) x=y;}
template<class T> void mkuni(V<T>& v){sort(all(v));v.erase(unique(all(v)),v.end());}
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

#ifdef LOCAL
#define show(x) cerr << "LINE" << __LINE__ << " : " << #x << " = " << (x) << endl
void dmpr(ostream& os){os<<endl;}
template<class T,class... Args>
void dmpr(ostream&os,const T&t,const Args&... args){
	os<<t<<" ~ ";
	dmpr(os,args...);
}
#define shows(...) cerr << "LINE" << __LINE__ << " : ";dmpr(cerr,##__VA_ARGS__)
#define dump(x) cerr << "LINE" << __LINE__ << " : " << #x << " = {";  \
	for(auto v: x) cerr << v << ","; cerr << "}" << endl;
#else
#define show(x) void(0)
#define dump(x) void(0)
#define shows(...) void(0)
#endif

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);		//DON'T USE scanf/printf/puts !!
	cout << fixed << setprecision(20);

	auto solve = [&](V<int> p){
		int N = p.size();
		rep(i,N) if(p[i]%2 != i%2) return false;
//		show("------------_");show(p);
		int mn = 1e9, mx = -1;
		int L = 0;
		rep(i,N){
			chmin(mn,p[i]); chmax(mx,p[i]);
			if(mn == L && mx == i){
				int R = i;	//[L,R]
//				show(L);show(R);
				int n = R-L+1;
				V<int> v(n); rep(i,n) v[i] = p[i+L] - L;
				if(n > 1){
					assert(p[L] != L && p[R] != R);		//xoxoxoxox
					if(n%2 == 0) return false;
					rep(i,n) if(i%2==1 && v[i] != i) return false;
					V<int> ls,rs;
					rep(i,n) if(i%2 == 0){
						if(v[i] == i) return false;
						if(v[i] < i) rs.pb(v[i]);
						else ls.pb(v[i]); 
					}
					rep(i,si(ls)-1) if(ls[i] > ls[i+1]) return false;
					rep(i,si(rs)-1) if(rs[i] > rs[i+1]) return false;
				}

				mn = 1e9, mx = -1;
				L = i+1;
			}
		}
		assert(mx == -1);
		return true;
	};

	int N; cin >> N;
	V<int> p(N); rep(i,N) cin >> p[i], p[i]--;
	if(solve(p)) cout << "Yes" << endl;
	else cout << "No" << endl;
}


Measured memory_bytes: 5052
//I am so vegetable
#pragma GCC optimize(2)
#include <bits/stdc++.h>
#define FIO ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define PB push_back
#define IN insert
#define ER erase
#define CT count
#define EP empty
#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 _sfor(p,st) for(auto &p:st)
using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9+7;
const double eps = 1e-6;
const double pi = 3.141593;
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
ll qpow(ll x, ll y) { ll ans = 1; for (; y > 0; y >>= 1) { if (y & 1)ans *= x; x *= x; }return ans; }
ll qpow(ll x, ll y, int MOD) { ll ans = 1; for (; y > 0; y >>= 1) { if (y & 1)ans = ans*x%MOD; x = x*x%MOD; }return ans; }
ll inv(ll x, int mod = MOD) { return qpow(x, mod - 2) % mod; }
ll m_m(ll a){ return (a%MOD+MOD)%MOD; }

int main() {
	//ofstream cout("E:\\acm dream\\out.txt",ios::out);
	FIO;
	int a,b,c,d;cin>>a>>b>>c>>d;
	while(1){
		c-=b;
		if(c<=0){
			cout<<"Yes";
			break;
		}
		a-=d;
		if(a<=0){
			cout<<"No";
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
int n, k;
const int nx = 1e5 + 5;
long long ac[nx][2];
long long dp[105][nx];

long long knapsack(long long i, long long w) {
	if (w > k) return -INT_MAX;
	if (i == n) return 0;
	if (dp[i][w] != -1) return dp[i][w];
	long long& ans = dp[i][w];
	ans = max(ans, knapsack(i + 1, w));
	if (w + ac[i][0] <= k) ans = max(ans, knapsack(i + 1, w + ac[i][0]) + ac[i][1]);
	return ans;
}
int main() {

	cin >> n >> k;
	memset(dp, -1, sizeof dp);
	for (int i = 0; i < n; i++) cin >> ac[i][0] >> ac[i][1];
	cout << knapsack(0, 0) << "\n";
}

Measured memory_bytes: 82304
#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,m,x,y,ans,f1[300000],f2[300000],sum;
int read(){
	char c=getchar();while (c!='-'&&(c<'0'||c>'9'))c=getchar();
	int kk=1,k=0;if (c=='-')kk=-1,c=getchar();
	while (c>='0'&&c<='9')k=k*10+c-'0',c=getchar();return kk*k;
}void putit1(int x,int y){for (;x<=200000;x+=x&(-x))f1[x]+=y;}
void putit2(int x,int y){for (;x<=200000;x+=x&(-x))f2[x]+=y;}
int findit1(int x){int ans=0;for (;x;x-=x&(-x))ans+=f1[x];return ans;}
int findit2(int x){int ans=0;for (;x;x-=x&(-x))ans+=f2[x];return ans;}
void doit(int x,int y){ 
	if (x>y){
		doit(x,m);doit(1,y);putit1(1,m-x+1),putit1(y+1,-m+x-1); 
	}else{
		putit2(x,1);putit2(y+1,-1);putit1(x,-x);putit1(y+1,x);
	}
}void doit1(int x,int y){
	if (x<y)sum+=y-x;else sum+=y+m-x;
	x=x%m+1;if (x==y)return;doit(x,y);
}
signed main(){
	n=read();m=read();x=read();ans=1e15;
	for (int i=1;i<n;i++)y=read(),doit1(x,y),x=y;
	for (int i=1;i<=m;i++)ans=min(ans,sum-findit1(i)-findit2(i)*i);//,cout<<findit1(i)+findit2(i)*i<<' '<<sum-findit1(i)-findit2(i)*i<<endl;
	cout<<ans<<endl;
}


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

const int MOD = 1e9 + 7;
const int iINF = 1e9;
const long long int llINF = 1e18;
const double PI = acos(-1.0);
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, init, n) for(int i = init; i < (n); i++)

using namespace std;
using ll = long long int;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using edge = struct
{
    int to;
    int cost;
};

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

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

    vector<int> C(N), S(N), F(N);

    rep(i, N - 1) cin >> C[i] >> S[i] >> F[i];

    rep(i, N)
    {
        int time = 0;

        REP(j, i, N - 1)
        {
            if(time <= S[j])
             time = S[j] + C[j];
            else if(time % F[j] == 0)
                time += C[j];
            else 
                time += C[j] + F[j] - time % F[j];
        }        

        cout << time << endl;
    }

    return 0;
}











Measured memory_bytes: 256
//Apparat : drobucs, aleonov, vit_72
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <iomanip>
#include <algorithm>
#include <string>
#include <queue>
#include <numeric>
#include <stack>

//#pragma warning(disable : 4996)
//#pragma GCC optimize("O3")

using namespace std;

#define nptr nullptr
#define all(x) (x).begin(), (x).end()
#define drobucs ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0);
#define ff first
#define ss second
#define pb push_back
#define sz(x) (int)(x).size()

typedef  long long ll;

const int maxn = (int)1e6 + 13;
const ll INFL = (1ll << 63ll) - 1ll;
const ll INF = (1ll << 31ll) - 1ll;
const ll MOD = (int)1e9 + 7, MOD2 = 998244353;//1e9 + 21, 1e9 + 33, 1e9 + 87, 1e9 + 93
const ll base = 101, base2 = 37;



int main() {
	drobucs;
	
	ll x;
	cin >> x;
	for (ll i = 0; i <= 5000; ++i) {
		ll d = i * i * i * i * i;
		ll l = -5000, r = 5000;
		while (r - l > 1) {
			ll m = (l + r) / 2;
			if (d - m * m * m * m * m <= x)r = m;
			else l = m;
		}
		if (d - r * r * r * r * r == x) {
			cout << i << " " << r << "\n";
			return 0;
		}
	}
	
	return 0;
}

Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
#define SORT(x) sort(x.begin(),x.end())
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
int main(){
    string s;
    cin>>s;
    int n=s.size();
    if(n%2) n--;
    else    n-=2;
    bool flag;
    while(1){
        flag=true;
        for(int i=0;i<n/2;i++){
            if(s[i]!=s[n/2+i])  flag=false;
        }
        if(flag){
            cout<<n<<endl;return 0;
        }
        n-=2;
    }

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include<tuple>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>

using namespace std;

using ll = long long;

#define bil ((ll)1e9)
#define mod ((ll)1e9+7)

int main(int argc,char* argv[]){
    string s;
    cin >> s;

    string str;
    for(int i=0;i<s.size();i++){
        if(s.at(i)=='0')
            str.push_back('0');
        else if(s.at(i)=='1')
            str.push_back('1');
        else if(s.at(i)=='B')
            if(str.size()==0)
                continue;
            else
                str.erase(str.end()-1);
    }

    cout << str << endl;

    return 0;
}


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

namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            //ulong N = ulong.Parse(Console.ReadLine());
            //var input = Console.ReadLine().Split(' ').Select(x => ulong.Parse(x)).ToArray();

            //ulong a = 1;
            //for (ulong i = 0; i < N - 1; i++)
            //{
            //    ulong tmp = Lcm(input[i], input[i + 1]);

            //    a = (tmp / input[i]) * a + tmp / input[i + 1];
            //    input[i + 1] = tmp;
            //}

            //Console.WriteLine((double)input[N - 1] / a);

            int N = int.Parse(Console.ReadLine());
            var input = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            double sum = 0;
            foreach (int a in input)
            {
                sum += (double)1 / a;
            }
            Console.WriteLine(1 / sum);
        }

        static ulong Gcd(ulong m, ulong n)
        {
            ulong temp;
            while (m % n != 0)
            {
                temp = n;
                n = m % n;
                m = temp;
            }
            return n;
        }

        static ulong Lcm(ulong m, ulong n)
        {
            return m * n / Gcd(m, n);
        }
    }
}



Measured memory_bytes: 13396
#include <cstdio>
#include <cstring>
#include <climits>
#include <algorithm>
using namespace std;
const int SIZEN = 200010;
typedef long long LL;
LL a[SIZEN] = {0};
LL L1[SIZEN] = {0};
LL L2[SIZEN] = {0};
LL R1[SIZEN] = {0};
LL R2[SIZEN] = {0}; 
LL sum[SIZEN];
int main(){
	int N;scanf("%d",&N);
	for(int i = 1;i <= N;i++){
		scanf("%lld",&a[i]);
		sum[i] = a[i] + sum[i-1];
	}
	for(int i = 1;i <= N;i++){
		if(a[i] == 0)a[i] == 0;
		else if(a[i] % 2 == 0)a[i] = 2;
		else a[i] = 1;
	} 
	for(int i = 1;i <= N;i++){
		if(a[i] == 0)		L1[i] = min(L1[i-1] + 2,sum[i]),L2[i] = min(L1[i],min(L2[i-1] + 1,sum[i]));
		else if(a[i] == 1)	L1[i] = min(L1[i-1] + 1,sum[i]),L2[i] = min(L1[i],min(L2[i-1],sum[i]));
		else 				L1[i] = min(L1[i-1],sum[i]),	L2[i] = min(L1[i],min(L2[i-1] + 1,sum[i]));
	}
	for(int i = N-1;i >= 0;i--){
		if(a[i+1] == 0)		R1[i] = min(R1[i+1] + 2,sum[N]-sum[i]), 	R2[i] = min(R1[i],min(R2[i+1]+1,sum[N]-sum[i]));
		else if(a[i+1] == 1)	R1[i] = min(R1[i+1] + 1,sum[N] - sum[i]),	R2[i] = min(R1[i],min(R2[i+1],sum[N]-sum[i]));
		else 				R1[i] = min(R1[i+1],sum[N] - sum[i]),		R2[i] = min(R1[i],min(R2[i+1]+1,sum[N]-sum[i]));
	}
	LL ans =LLONG_MAX ;
	for(int i = 0;i <= N;i++){
		ans = min(ans,min(L1[i]+R2[i],L2[i]+R1[i]));
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 9472
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
#define int long long
#define ull unsigned long long
#define ld long double
#define rep(a) rep1(i,a)
#define rep1(i,a) rep2(i,0,a)
#define rep2(i,b,a) for(int i=(b); i<((int)(a)); i++)
#define rep3(i,b,a) for(int i=(b); i>=((int)(a)); i--)
#define all(a) a.begin(),a.end()
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define sz(a) ((int)a.size())
#define pow2(x) (1ll<<(x))
#define ceiling(a,b) (((a)+(b)-1)/(b))
#define print0(a) cout << (a) << ' '
#define print1(a) cout << (a) << '\n'
#define print2(a,b) cout << (a) << ' ',print1(b)
#define print3(a,b,c) cout << (a) << ' ',print2(b,c)
#define print4(a,b,c,d) cout << (a) << ' ',print3(b,c,d)
#ifdef i_am_noob
#define debug(a) print2(#a,a)
#else
#define debug(a) 
#endif
#define ordered_set tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>
 
using namespace std;
using namespace __gnu_pbds;
 
const int Mod=1000000007,Mod2=998244353;
const int MOD=Mod2;
 
inline int add(int a, int b){return (a+b>=MOD?a+b-MOD:a+b);}
inline int sub(int a, int b){return (a+MOD-b>=MOD?a-b:a+MOD-b);}
int Pow(int a, int b){
	if(!b) return 1;
	int tmp=Pow(a*a%MOD,b>>1);
	return (b&1?tmp*a%MOD:tmp);
}
inline int inverse(int n){return Pow(n,MOD-2);}
 
const int maxn=100005;
//i_am_noob
int n,maxl[maxn][2],minr[maxn][2],ans=0,b[maxn],c[maxn];
bool ok;

struct seg{int l,r;}a[maxn];
bool comp(seg i, seg j){return i.r>j.r;}

signed main(){
	ios_base::sync_with_stdio(0),cin.tie(0);
	cin >> n;
	rep(n) cin >> a[i].l >> a[i].r;
	sort(a,a+n,comp);
	maxl[0][0]=a[0].l,minr[0][0]=a[0].r;
	rep2(i,1,n) maxl[i][0]=max(maxl[i-1][0],a[i].l),minr[i][0]=min(minr[i-1][0],a[i].r);
	maxl[0][1]=a[n-1].l,minr[0][1]=a[n-1].r;
	rep2(i,1,n) maxl[i][1]=max(maxl[i-1][1],a[n-1-i].l),minr[i][1]=min(minr[i-1][1],a[n-1-i].r);
	rep(n-1) ans=max(ans,max(0ll,minr[i][0]-maxl[i][0]+1)+max(0ll,minr[n-2-i][1]-maxl[n-2-i][1]+1));
	rep(n) b[i]=a[i].l,c[i]=a[i].r;
	sort(b,b+n),sort(c,c+n);
	rep(n) ans=max(ans,a[i].r-a[i].l+1+max(0ll,(a[i].r==c[0]?c[1]:c[0])-(a[i].l==b[n-1]?b[n-2]:b[n-1])+1));
	print1(ans);
	return 0;
}

Measured memory_bytes: 6528
# from fractions import gcd
# mod = 10 ** 9 + 7
# N = int(input())
# a = list(map(int,input().split()))
# a,b,c = map(int,input().split())
# ans = [0] * N
# math.ceilで切り上げ
# dp = [[0] * 4 for i in range(3)] #2次元配列初期化
# dp = [[[0] * 2 for i in range(3)] for j in range(5)]
# (ord('A'))でASCII出力 Aは65
import math
import numpy as np
import statistics
import string
import sys
from array import array
from collections import deque
from functools import wraps
import time

def intinput():
    return int(input())
def listintinput():
    return list(map(int, input().split()))
def splitintinput():
    return map(int, input().split())
def factorialsurplus(x, y, z):  # xからyまでの階乗をzで割ったあまりを求める
    ret = 1
    for i in range(x, y + 1):
        ret = (ret * i) % z
    return (ret)
def isprime(x):
    if x == 1:
        return False
    if x == 2:
        return True
    sq = int(math.sqrt(x))
    for i in range(2,sq+1):
        if x % i == 0:
            return False
    return True
def hcfnaive(a,b):#最大公約数 math.gcdが使えない時の手段として入れとく。pythonが更新されたらいらなくなるはず
    if(b==0):
        return a
    else:
        return hcfnaive(b,a%b)

N = intinput()
A = listintinput()

joushi = [0] * N
for i in range(N-1):
    joushi[A[i]-1] += 1
for w in joushi:
    print(w)


Measured memory_bytes: 50972
using System;
using System.Linq;
class Program
{
    static void Main(string[] args)
    {
        int n = int.Parse(Console.ReadLine());
        string[] aInput = Console.ReadLine().Split(' ');
        int[] a = Array.ConvertAll(aInput, int.Parse);
        int[] ans = new int[n + 1];
        for (int i = 0; i < n - 1; i++)
        {
            ans[a[i]]++;
        }
        for(int i = 1; i < n + 1; i++)
        {
            Console.WriteLine(ans[i]);
        }
    }
}

Measured memory_bytes: 39116
import java.io.*;
import java.util.*;
class Main{
    public static void main(String[] args) throws Exception {
		hayami saori = new hayami();
		int[] num = new int[3];
		
		int five = 0;
		int seven = 0;
		for(int i = 0;i < num.length;i++){
			num[i] = saori.saori_hayami();
			if(num[i] == 5){
				five++;
			}
			if(num[i] == 7){
				seven++;
			}
		}
		if(five == 2 && seven == 1){
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
		
    }
}

class hayami implements Closeable {
	private final InputStream in = System.in;
	private final byte[] hayami = new byte[1024];
	private int Hayami = 0;
	private int saori = 0;
	private boolean HayamiSaori() {
		if (Hayami < saori) {
			return true;
		}else{
			Hayami = 0;
			try {
				saori = in.read(hayami);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (saori <= 0) {
				return false;
			}
		}
		return true;
	}
	private int SaoriHayami() { 
		if (HayamiSaori()) {
            return hayami[Hayami++];
         }else{
             return -1;
         }
	}
	private static boolean hayami_saori(int hayami) { 
		return 33 <= hayami && hayami <= 126;
	}
	public boolean hayamisaori() { 
		while(HayamiSaori() && !hayami_saori(hayami[Hayami])) Hayami++; return HayamiSaori();
	}
	public String nextHayami() {
		if (!hayamisaori()) throw new NoSuchElementException();
		StringBuilder hayamin = new StringBuilder();
		int saori = SaoriHayami();
		while(hayami_saori(saori)) {
			hayamin.appendCodePoint(saori);
			saori = SaoriHayami();
		}
		return hayamin.toString();
	}
	public long saorihayami() {//nextLong
		if (!hayamisaori()) throw new NoSuchElementException();
		long hayami = 0;
		boolean misao = false;
		int saori = SaoriHayami();
		if (saori == '-') {
			misao = true;
			saori = SaoriHayami();
		}
		if (saori < '0' || '9' < saori) {
			throw new NumberFormatException();
		}
		while(true){
			if ('0' <= saori && saori <= '9') {
				hayami *= 10;
				hayami += saori - '0';
			}else if(saori == -1 || !hayami_saori(saori)){
				return misao ? -hayami : hayami;
			}else{
				throw new NumberFormatException();
			}
			saori = SaoriHayami();
		}
	}
	public int saori_hayami() {//nextInt
		long hayami = saorihayami();
		if (hayami < Integer.MIN_VALUE || hayami > Integer.MAX_VALUE) throw new NumberFormatException();
		return (int) hayami;
	}
	public double Hayamin() { //nextDouble
		return Double.parseDouble(nextHayami());
	}
	public void close() {
		try {
			in.close();
		} catch (IOException e) {
		}
    }
    
}

Measured memory_bytes: 22484
from collections import Counter as ct
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))

def do():
    n=INT()
    a=LIST()
    a_ct=ct(a)
    ans=0
    #print(a_ct)
    for i in a_ct:
        t=a_ct[i]
        #print(a_ct[i])
        if t>=2:
            ans+=(t*(t-1))//2
    
    for i in a:
        t=a_ct[i]
        temp=ans
        if t>=2:
            temp=temp-(t*(t-1))//2+((t-2)*(t-1))//2
        print(temp)
    
if __name__ == '__main__':
    do()

Measured memory_bytes: 26780
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<sstream>
#include<numeric>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()

using namespace std;

typedef unsigned int uint;
typedef long long ll;

int prevs[1<<15][15];
int id[15];
int pos[15];
int num[15];

int main(){
  int n;
  scanf("%d",&n);
  REP(i,n){
    scanf("%d%d%d",id+i,pos+i,num+i);
    num[i] *= 20;
  }
  //time, flag, weight, pos, prev
  typedef pair<double,pair<int,pair<int,pair<int,int> > > > data;
  priority_queue<data,vector<data>,greater<data> > pq;

  memset(prevs, -1, sizeof(prevs));

  REP(i,n){
    int f = ((1<<n)-1) ^ (1<<i);
    pq.push(mp(0.0,mp(f,mp(num[i],mp(i,n)))));
  }

  while(pq.size()){
    data d = pq.top();
    double time = d.f;
    int flag    = d.s.f;
    int weight  = d.s.s.f;
    int p       = d.s.s.s.f;
    int prev    = d.s.s.s.s;

    //printf("time=%f, flag=%d, weight=%d, p=%d, prev=%d\n",time,flag,weight,p,prev);
    pq.pop();

    if(prevs[flag][p] != -1) continue;
    prevs[flag][p] = prev;

    if(flag == 0){
      int ans[n];
      REP(i,n){
        ans[n-i-1] = p;
        prev = prevs[flag][p];
        flag = flag ^ (1<<p);
        p = prev;
      }
      REP(i,n) printf("%d%c",id[ans[i]],i==n-1?'\n':' ');
      break;
    }

    REP(i,n){
      if(flag & (1<<i)){
        //time, flag, weight, pos, prev
        double tt =
          time + abs(pos[p] - pos[i]) / (2000.0 / (70.0 + weight));
        int ww = weight + num[i];
        int ff = flag ^ (1<<i);
        pq.push(mp(tt,mp(ff,mp(ww,mp(i,p)))));
      }
    }
  }
  return 0;
}

Measured memory_bytes: 21000
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2155

#include<iostream>
#include<map>
#include<vector>
#include<algorithm>
#include<cmath>
#include<climits>
#include<ctime>
#include<cstring>
#include<numeric>

#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;

using namespace std;

struct Packet
{
	int time;
	int source;
	int dest;

	Packet(int t, int s, int d): time(t),source(s),dest(d){}
	
	bool operator<( const Packet& right ) const {
		return time < right.time;
	}
};

int main()
{
	int M,N;

	while(cin >> N >> M && N)
	{
		vector< Packet > packets;
		vector<int> PC( N, 0 ); 
		
		int T,S,D;
		rep(nth,M)
		{
			cin >> T >> S >> D;
			packets.push_back( Packet(T,S-1,D-1) );
		}

		sort(ALL(packets));

		
		PC[0] = 1;
		rep(i,M)
		{
			Packet p =  packets[i];
			if(PC[p.source]){ PC[p.dest] = PC[p.source]; }
		}

		int ans = accumulate(ALL(PC),0);
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1848
#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n, q, i, ans[200100]={0}, cnt=0;
    cin >> n >> q;
    atcoder :: dsu d(n);
    for(i=0;i<q;i++){
        int t, u, v;
        cin >> t >> u >> v;
        if(t==0) d.merge(u, v);
        else if(d.same(u, v)){
            ans[cnt]=1;
            cnt++;
        }
        else{
            ans[cnt]=0;
            cnt++;
        }
    }
    for(i=0;i<cnt;i++){
        cout << ans[i] <<endl;
    }
    return 0;
}


Measured memory_bytes: 4800
/********************************
*MAHBUBCSEJU                    *
*CSE 22                         *
*JAHANGIRNAGAR UNIVERSITY       *
*TIMUS:164273FU                 *
*UVA>>LIGHTOJ>>HUST:mahbubcseju */
#include<bits/stdc++.h>
#define ll long long int
#define ull unsigned long long int
#define I(a) scanf("%d",&a)
#define I2(a,b) scanf("%d%d",&a,&b)
#define I3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define L(a) scanf("%lld",&a)
#define L2(a,b) scanf("%lld%lld",&a,&b)
#define L3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define PI(a) printf("%d\n",a)
#define PL(a) printf("%lld\n",a)
#define PT(t) printf("Case %d: ",t)
#define PB push_back
#define x first
#define y second
#define xx first.first
#define xy first.second
#define yx second.first
#define yy second.second
#define SC scanf
#define PC printf
#define NL printf("\n")
#define SET(a) memset(a,0,sizeof a)
#define SETR(a) memset(a,-1,sizeof a)
#define SZ(a) ((int)a.size())
//#define pi 2.0*acos(0.0)
#define R(a) freopen(a, "r", stdin);
#define W(a) freopen(a, "w", stdout);
#define CB(x) __builtin_popcount(x)
#define STN(a) stringtonumber<ll>(a)
#define lol printf("BUG\n")
#define mk make_pair
using namespace std;
template <class T> inline T BM(T p, T e, T M) {
    ll ret = 1;
    for(; e > 0; e >>= 1) {
        if(e & 1) ret = (ret * p) % M;
        p = (p * p) % M;
    }
    return (T)ret;
}
template <class T> inline T gcd(T a, T b) {
    if(b == 0)return a;
    return gcd(b, a % b);
}
template <class T> inline T mdINV(T a, T M) {
    return BM(a, M - 2, M);
}
template <class T> inline T PW(T p, T e) {
    ll ret = 1;
    for(; e > 0; e >>= 1) {
        if(e & 1) ret = (ret * p);
        p = (p * p);
    }
    return (T)ret;
}
template <class T>string NTS ( T Number ) {
    stringstream ss;
    ss << Number;
    return ss.str();
}
template <class T>T stringtonumber ( const string &Text ) {
    istringstream ss(Text);
    T result;
    return ss >> result ? result : 0;
}
template <class T>bool ISLEFT ( T a,T b,T c) {
    if(((a.xx-b.xx)*(b.yy-c.yy)-(b.xx-c.xx)*(a.yy-b.yy))<0.0)return 1;//Uporer dike //A,b,c, x okkher ordera sorted
    else return 0;
}
#define mx 10000
#define md 1000000007
#define maxp 2050180000

typedef pair<int ,int > P;

////////define value/////
vector<int>v[2002];
ll sum;
int k;
void dfs(int u,int p,int l)
{
    if(l>k/2)sum++;

    for(int i=0;i<v[u].size();i++)
    {
        int x=v[u][i];
        if(x==p)continue;
        dfs(x,u,l+1);
    }
}

int main()
{

    int n;
    I2(n,k);
    vector<P>v1;
    for(int i=1;i<=n-1;i++){
        int x,y;
        I2(x,y);
        v[x].PB(y);
        v[y].PB(x);
        v1.PB(mk(x,y));

    }
    ll res=n;

    if(k%2==0)
    {
        for(int i=1;i<=n;i++)
        {
            sum=0;
            dfs(i,0,0);
            res=min(res,sum);
        }
        PL(res);

    }
    else
    {
        for(int i=0;i<v1.size();i++)
        {
            int x=v1[i].x;
            int y=v1[i].y;
            sum=0;
            dfs(x,y,0);
            dfs(y,x,0);
            res=min(res,sum);

        }
        PL(res);
    }
    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
int INF = 1e9+7;
int mod = 1e9+7;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0 ,-1};
signed main(){
    int N;
    cin >> N;
    vector<vector<P>>ki(N);
    for(int i = 0; i < N-1; i++) {
        int a,b,c;
        cin >> a >> b >> c;
        a--;b--;
        ki[a].push_back({b,c});
        ki[b].push_back({a,c});
    }
    int Q,K;
    cin >> Q >> K;
    vector<int>cnt(N,-1);
    cnt[K-1] = 0;
    //cntは、頂点iから、Kまでの距離を指す
    queue<int> que;
    que.push(K-1);
    while(!que.empty()) {
        int X = que.front();
        que.pop();
        for(int i = 0; i < ki[X].size(); i++) {
            if(cnt[ki[X][i].first] == -1) {
                que.push(ki[X][i].first);
                cnt[ki[X][i].first] = cnt[X]+ki[X][i].second;
            }
        }
    }
    for(int i = 0; i < Q; i++) {
        int x,y;
        cin >> x >> y;
        x--;y--;
        cout << cnt[x]+cnt[y] << endl;
    }
}

Measured memory_bytes: 11992
A, B, C, X, Y = (int(x) for x in input().split())

ans = 0

C *= 2

if(A + B > C):
    ans += min(X, Y) * C
    if(X > Y):
        ans += A * (X - Y)
    else:
        ans += B * (Y - X)
else:
    ans = A * X + B * Y

print(min(ans, C * max(X, Y)))

Measured memory_bytes: 3064
#include <stdio.h>
int main(void)
{
	int a,b,c,i;
	scanf("%d %d %d",&a,&b,&c);
	if(a&&b==1||c==1){
	printf("Open\n");
	}
	else{
	printf("Close\n");
	}
	return 0;
}

Measured memory_bytes: 584
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define rrep(i,x) for(ll i = (ll)(x)-1;0 <= i; i--)
#define reps(i,x) for(ll i = 1; i < (ll)(x)+1; i++)
#define rreps(i,x) for(ll i = (ll)(x); 1 <= i; i--)
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
const ll INF = numeric_limits<ll>::max()/4;
const int n_max = 1e5+10;

template<class T>
bool chmax(T &a, T b){if(a < b){a = b; return true;} return false;}
template<class T>
bool chmin(T &a, T b){if(a > b){a = b; return true;} return false;}
int main(){
    ll n,k,q; cin >> n >> k >> q;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    ll ans = INF;
    rep(i,n){
        vector<ll> temp, temp_sum, clear;
        rep(j,n){
            if(a[j] >= a[i])temp.emplace_back(a[j]);
            else{
                if(temp.size() >= k){
                    sort(all(temp));
                    rep(jj,temp.size() - k + 1)temp_sum.emplace_back(temp[jj]);
                }
                temp = clear;
            }
        }
        // debug(i);debug(temp.size());
        if(temp.size() >= k){
            sort(all(temp));
            rep(jj,temp.size() - k + 1)temp_sum.emplace_back(temp[jj]);
        }
        if(temp_sum.size() >= q){
            sort(all(temp_sum));
            chmin(ans, temp_sum[q-1] - temp_sum[0]);
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 384
#include<stdio.h>
#include<math.h>

int main() {
	double x1, y1, x2, y2;
	scanf("%lf %lf %lf %lf", &x1, &y1, &x2, &y2);
	printf("%lf\n", sqrt((x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2)));
	return 0;
}


Measured memory_bytes: 2736