akhauriyash/Code-Regression huggingface dataset:
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author LUCIANO.
 */
import java.util.*;

public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int m = in.nextInt();
        int[] item = new int[n];
        int total = 0;
        for(int i = 0; i < n; i++) {
            item[i] = in.nextInt();
            total += item[i];
        }
        double requirement = ((double)1 / (4 * m)) * total;
        int cnt = 0;
        for(int i = 0; i < n; i++) {
            if(item[i] >= requirement) cnt += 1;
        }
        if(cnt >= m) System.out.println("Yes");
        else System.out.println("No");
    }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define INF INT_MAX
#define MOD 1000000007
#define fcout cout << fixed << setprecision(15)
 #define int long long
typedef long long ll;
typedef pair<int, int> P;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a * b / gcd(a, b);};
int mod(int a,int b){return (a+b-1)/b;};
int month[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
template<class T>inline bool chmax(T& a,T b){if(a < b){a=b;return true;}return false;};
template<class T>inline bool chmin(T& a,T b){if(a > b){a=b;return true;}return false;};



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

  int n;
  cin >> n;
  int l[n];
  rep(i, n) cin >> l[i];
  sort(l, l + n);
  int ans = 0;
  rep(i, n) {
    REP(j, i + 1, n) {
      REP(k, j + 1, n) {
        if(l[k] < l[i] + l[j]) {
          ans++;
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 384
//#include"stdc++.h"
#include<bits/stdc++.h>
using namespace std;
long long n;
vector<long long> a,b,c;

int main()
{
    cin>>n;
    a.resize(n);
    b.resize(n);
    c.resize(n);
    long long dp[n][3];
    for(long long i=0;i<n;i++)
    {
        cin>>a[i];
        cin>>b[i];
        cin>>c[i];
    }
    dp[0][0]=a[0];
    dp[0][1]=b[0];
    dp[0][2]=c[0];
    for(long long i=1;i<n;i++)
    {
        for(long long j=0;j<3;j++)
        {
            if(j==0)
            {
                if(dp[i-1][j+1]>dp[i-1][j+2])
                    dp[i][j]=a[i]+dp[i-1][j+1];
                else
                    dp[i][j]=a[i]+dp[i-1][j+2];
            }
            else if(j==1)
            {
                if(dp[i-1][j-1]>dp[i-1][j+1])
                    dp[i][j]=b[i]+dp[i-1][j-1];
                else
                    dp[i][j]=b[i]+dp[i-1][j+1];
            }
            else
            {
                if(dp[i-1][j-1]>dp[i-1][j-2])
                    dp[i][j]=c[i]+dp[i-1][j-1];
                else
                    dp[i][j]=c[i]+dp[i-1][j-2];
            }
        }
    }
    
    vector<long long> v(3);
    v.push_back(dp[n-1][0]);
    v.push_back(dp[n-1][1]);
    v.push_back(dp[n-1][2]);
    cout<<*max_element(v.begin(),v.end());
    // dp.push_back(rec(1,0));
    // dp.push_back(rec(2,0));
    // dp.push_back(rec(3,0));
    //cout<<*max_element(dp.begin(),dp.end());
 
    return  0;
 
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define ALL(a) (a.begin(), a.end())
using ll = long long;
template<typename T> void Out(T x) { cout << x << endl; }

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int m, n;
  cin >> m >> n;
  if (m == n){ Out("Yes"); return 0;}
  else { Out("No"); return 0;}
}


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

#define ll unsigned long long
#define EPSION numeric_limits<double>::epsilon()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

using namespace std;

//ifstream f("input.in");
//ofstream g("output.out");

ll GET_ans(ll a)
{
    if(a%4==1)
        return 1;
    else if(a%4==2)
        return a+1;
    else if(a%4==3||a==0)
        return 0;
    else
        return a;
}

signed main(int argc, char **argv)
{
    IOS;
    long long a, b;

    cin>>a>>b;
    ll ans = GET_ans(b) ^ GET_ans(a-1);
    cout<< ans;
    return 0;
}



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

int main(){
  int a, b;
  cin >> a >> b;
  int x = a + b, y = a - b, z = a * b;
  if(x >= y && x >= z){
    cout << x << endl;
  }else if(y >= x && y >= z){
    cout << y << endl;
  }else if(z >= x && z >= y){
    cout << z << endl;
  }
}

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

int main() {
    cin >> S;
    S += "R";
    int slen = S.length();
    vector<int> child(slen, 0);
    int count = 0;
    int flg = 0;
    int leftpos = 0;
    int Rcnt = 0;
    int Lcnt = 0;

    for(int i = 0; i < slen; ++i) {
        if(S.at(i) == 'R') {
            if(flg == 0) {
                count++;
                Rcnt++;
            }else {
                if(count % 2 != 0) {
                    if(Rcnt % 2 != 0) {
                        child.at(leftpos) = count / 2;
                        child.at(leftpos-1) = count / 2 + 1;
                    }else {
                        child.at(leftpos) = count / 2 + 1;
                        child.at(leftpos-1) = count / 2;
                    }
                }else {
                    child.at(leftpos) = count / 2;
                    child.at(leftpos-1) = count / 2;
                }
                flg = 0;
                count = 1;
                Rcnt = 1;
                Lcnt = 0;
            }
        }else if(S.at(i) == 'L') {
            if(flg == 0) {
                leftpos = i;
                flg = 1;
            }
            count++;
            Lcnt++;
        }
        // cout << leftpos << " " << flg << " " << count << " " << Rcnt << " " << Lcnt << endl;
    } 
    
    for(int i = 0; i < slen-1; ++i) {
        cout << child.at(i) << " ";
    }
}

Measured memory_bytes: 1024
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import bisect


def isincluded(array, value):
    i = bisect.bisect_left(array, value)
    if i != len(array) and array[i] == value:
        return True
    else:
        return False


def main():
    n = int(input())
    s = [int(i) for i in input().split()]
    q = int(input())
    t = [int(j) for j in input().split()]
    print(sum(1 for x in t if isincluded(s, x)))


if __name__ == "__main__":
    main()

Measured memory_bytes: 19092
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream> 
#include<map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
using namespace std;
#define MAX_MOD 1000000007
#define REP(i,n) for(long long i = 0;i < n;++i)
#define LONGINF 1000000000000000000
int main() {
	long long n;
	cin >> n;
	long long a = 0, b = 0;
	vector<long long> c, d;
	REP(i, n) {
		long long tmp, tmp2;
		cin >> tmp >> tmp2;
		c.push_back(tmp);
		d.push_back(tmp2);
	}
	a = c[0], b = d[0];
	for (int i = 1;i < n;++i) {
		long long hoge = a / c[i];
		if (a % c[i] != 0) hoge++;
		long long tmp = b/ d[i];
		if (b % d[i] != 0) tmp++;
		hoge = max(tmp, hoge);
		a = hoge * c[i];
		b = hoge * d[i];
	}
	cout << a + b << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <stack>
#include <complex>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;


int main(){
    int N, T;
    int c[10000], t[10000];
    cin >> N >> T;
    for(int i = 0; i < N; i++){
        cin >> c[i] >> t[i];
    }
    int c_min = 100000;
    for(int i = 0; i < N; i++){
        if(t[i] <= T){
            c_min = min(c[i], c_min);
        }
    }

    if(c_min == 100000){
        cout << "TLE" << endl;
    }
    else {
        cout << c_min << endl;
    }


    return 0;

}



Measured memory_bytes: 256
N, A, B = map(int, input().split())
MOD = 10**9 + 7
ans = 0
ans += pow(2, N, MOD)

S = [0]*(2*10**5+2)
S[1] = 1
for i in range(2, 2*10**5+1):
    S[i] = S[MOD%i]*(MOD-int(MOD/i))%MOD
temp = 1
for i in range(min(A, N-A)):
    temp *= (N-i)*S[i+1]
    temp %= MOD
ans -= temp
temp = 1
for i in range(min(B, N-B)):
    temp *= (N-i)*S[i+1]
    temp %= MOD
ans -= temp
print((ans-1)%MOD)


Measured memory_bytes: 42348
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
int main() {
  ll n,t,c,x;
  cin>>n>>t;
  ll ans=1e15;
  for(int i=0;i<n;i++){
    cin>>c>>x;
    if(x<=t)ans=min(ans,c);
  }
  if(ans==1e15)cout<<"TLE"<<endl;
  else cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

int main()
{
    int n,a,ac=0,wa=0,tle=0,re=0,z;
    char s[4];
    scanf("%d",&n);
    for(a=1;a<=n;a++)
    {
       scanf(" %s",s);
        if(!strcmp(s,"AC"))
            ac++;
        if(!strcmp(s,"WA"))
            wa++;
        if(!strcmp(s,"TLE"))
            tle++;
        if(!strcmp(s,"RE"))
            re++;
    }
    printf("AC x %d\nWA x %d\nTLE x %d\nRE x %d",ac,wa,tle,re);
    return 0;
}


Measured memory_bytes: 1732
import math
from functools import reduce
from collections import deque
import sys
sys.setrecursionlimit(10**7)

def s(generator, splitter, mapper):
    return [ mapper(s) for s in generator().split(splitter) ]

# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
    return [ int(s) for s in input().split(" ")]

# 改行区切りの入力をn行読み込んで数値リストにして返します。
def get_nums_n(n):
    return [ int(input()) for _ in range(n)]

def gcd(m, n):
    # 入力を m, n (m ≧ n) とする。
    tmp = max(m,n)
    n = min(m,n)
    m = tmp
    # n = 0 なら、 m を出力してアルゴリズムを終了する。
    if n == 0:
        return m
    # m を n で割った余りを新たに n とし、更に 元のnを新たにm とし 2. に戻る。
    return gcd(n, m % n)

n = int(input())
hps = get_nums_l()

print(reduce(gcd, hps))


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

using namespace std;

using ll = long long int;
using vi = vector<int>;
#define f(n) for(int i = 0; i < n; i++)
#define fj(n) for(int j = 0; j < n; j++)
#define fk(n) for(int k = 0; k < n; k++)
#define ci(n) cin >> n;
#define ic(n) int n; cin >> n;
#define lc(n) int n; cin >> n;
#define all(a) a.begin(), a.end()
#define pri(a, n) for(int i = 0; i < n; i++) cout << a[i] << " "; cout << "\n";
#define sc(a, n) int a[n] = {0}; for(int i = 0; i < n; i++) cin >> a[i];
#define scl(a, n) ll a[n] = {0}; for(int i = 0; i < n; i++) cin >> a[i];
#define pb push_back
#define eb emplace_back
#define int long long
const int inf = 2e18, maxn = 200000;

void solve(int ci)
{
    set<int> s;
    f(5) s.insert(i + 1);
    f(5)
    {
        ic(t)
        s.erase(t);
    }
    cout << *s.begin();
}


main()
{
    //cout << atan2(0, -1);
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int t = 1;
    //cin >> t;
    f(t) solve(i + 1);
}


Measured memory_bytes: 3628
n, a, b, c, d = map(int, input().split())
s = input()
if '##' in s[a-1:c] or '##' in s[b-1:d]:
    print('No')
elif c < d:
    print('Yes')
else:
    if '...' in s[b-2:d+1]:
        print('Yes')
    else:
        print('No')

Measured memory_bytes: 3572
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <tuple>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define DECIM8  fixed<<setprecision(8) 
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

using namespace std;
int main(void)
{
  int dp[5][75000];
  REP(i,5) REP(j,75000) dp[i][j]=0;
  dp[0][0]=1;
  FOR(i,1,200){
    REP(j,4){
      REP(k,35000){
	dp[j+1][k+i*i]+=dp[j][k];
      }
    }
  }
  FOR(j,1,4) REP(k,35000){
    dp[j+1][k]+=dp[j][k];
  }
  for(;;){
    int n;
    cin >> n;
    if(!n) return 0;
    cout << dp[4][n] << endl;
  }
}

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

int mymin(int a, int b, int c) {
	int tmp = a;
	if (tmp > b)tmp = b;
	if (tmp > c)tmp = c;
	return tmp;
}

using namespace std;

int main() {
	int q;
	cin >> q;
	for (int i = 0; i < q; i++) {
		int c, a, n, ct = 0;
		cin >> c >> a >> n;
		ct += mymin( c ,a ,n );
		c -= ct, a -= ct, n -= ct;
		if (a > 0 && c > 0 && a * 2 > c)ct += (c / 2);
		else if(c != 0)ct += (a + ((c - a * 2) / 3));
		cout << ct << endl;

	}
	return 0;
}

Measured memory_bytes: 1160
N = int(input())
s = [''.join(sorted(input())) for i in range(N)]
s.sort()
count = 0
num = 1
for i in range(N-1):
    if s[i] == s[i+1]:
        num += 1
    else:
        count += num * (num - 1) // 2
        num = 1
print(count + num * (num - 1) // 2)


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

int main(){
	string x;
	cin>>x;
	bool flag=false ;
	int y=x.length();
	for(int i=0;i<y;i++){
		if((i+1)&1){
			if(x[i]=='R'||x[i]=='U'||x[i]=='D') continue ;
			else {
				flag=true; 
				break;
			}
		}
		else {
			if(x[i]=='L'||x[i]=='U'||x[i]=='D') continue ;
			else {
				flag=true;
				break;
			}
		}
	}
	if(flag) cout<<"No"<<endl;
	else cout<<"Yes"<<endl;
	return 0;	
}

Measured memory_bytes: 256
#include<cstdio>
#include<vector>
#include<map>
#include<algorithm>
using namespace std;

int compress(vector<int> &xs,map<int,int> &x){
  sort(xs.begin(),xs.end());
  xs.erase(unique(xs.begin(),xs.end()),xs.end());
  for(int i=0;i<xs.size();i++){
    x[xs[i]] = i;
  }
  return xs.size();
}

int main(){
  int n;
  int x1[2000],x2[2000],y1[2000],y2[2000];
  static int field[4000][4000];
  vector<int> xs,ys;
  map<int,int> x,y;
  scanf("%d",&n);
  for(int i=0;i<n;i++){
    scanf("%d %d %d %d",x1+i,y1+i,x2+i,y2+i);
    xs.push_back(x1[i]); xs.push_back(x2[i]);
    ys.push_back(y1[i]); ys.push_back(y2[i]);
  }
  int w = compress(xs,x);
  int h = compress(ys,y);
  fill(field[0],field[0]+4000000,0);
  for(int i=0;i<n;i++){
    int xx1 = x[x1[i]], xx2 = x[x2[i]], yy1 = y[y1[i]], yy2 = y[y2[i]];
    field[xx1][yy1]++; field[xx2][yy2]++; field[xx1][yy2]--; field[xx2][yy1]--;
  }
  for(int i=1;i<w;i++) for(int j=0;j<h;j++) field[i][j] += field[i-1][j];
  for(int i=1;i<h;i++) for(int j=0;j<w;j++) field[j][i] += field[j][i-1];
  long long ans = 0;
  for(int i=0;i<w;i++){
    for(int j=0;j<h;j++){
      long long dx = xs[i+1]-xs[i], dy = ys[j+1]-ys[j];
      if(field[i][j]>0) ans += dx * dy;
    }
  }
  printf("%lld\n",ans);
  return 0;
}

Measured memory_bytes: 65748
import Data.List(sortBy, groupBy)
import Data.Ord(comparing)
import Control.Monad(forM_)

type Point = (Int, Int)
type Row = [(Int, String)]

type Score = (Point, String)

main = do
  ns <- lines <$> getContents
  let h = read $ head $ words $ head ns
  let w = read $ last $ words $ head ns
  let lines = tail ns
  let res = solve h w lines
  forM_ res putStrLn 

newRow :: String -> Row
newRow src = filter (\(y, v) -> v == "#") $ zipWith (\n v -> (n, if v == '.' then "0" else "#")) [0 .. (subtract 1 $ length src)] src

makePs :: Score -> [Point]
makePs ((x, y), v) = [(x', y') | x'<- [(subtract 1 x) .. (x + 1)], y'<- [(subtract 1 y) .. (y + 1)], (x,y) /= (x', y')]

sortPs :: Point -> Point -> Ordering
sortPs (x1, y1) (x2, y2)
  | x1 < x2 = LT
  | and [x1 == x2, y1 < y2] = LT
  | x1 > x2 = GT
  | and [x1 == x2, y1 > y2] = GT
  | and [x1 == x2, y1 == y2] = EQ

eqPs :: Point -> Point -> Bool
eqPs (x1, y1) (x2, y2)
  | and [x1 == x2, y1 == y2] = True
  | otherwise = False

sortedPs :: [String] -> [[Point]]
sortedPs s = groupBy eqPs $ sortBy sortPs $ concatMap makePs $ getMs s

countPs :: [[Point]] -> [Score]
countPs ps = zipWith (\p c -> ((head p), show c)) ps (map length ps)

preChoose :: Point -> [Score] -> Score
preChoose p ss
  | 0 < length res = head res
  | otherwise = (p, "0")
  where
    res = filter (\s -> p == (fst s)) ss

choose :: [Score] -> [Score] -> Point -> Score
choose ms ss p
  | snd v == "#" = v
  | otherwise = preChoose p ss
  where
    v =  preChoose p ms

grByP :: Score -> Score -> Bool
grByP ((ax, ay), av) ((bx, by), bv) 
  | ax == bx = True
  | otherwise = False

toShow :: [Score] -> String
toShow ss = concat $ map (\s -> snd s) ss

solve :: Int -> Int -> [String] -> [String]
solve h w line = map toShow ls
  where
    ps = [(x, y) | x <- [0 .. subtract 1 h], y <- [0 .. subtract 1 w]]
    ms = getMs line
    ss = countPs (sortedPs line)
    res = map (choose ms ss) ps
    ls = groupBy grByP res

ps = [(x :: Int , y :: Int ) | x <- [0 .. 2] , y <- [0 .. 2]]
ms = getMs ["#..", ".#.", "..#"]
ss = countPs $ sortedPs ["#..", ".#.", "..#"]

getMs :: [String] -> [Score]
getMs ls = wrap (zip [0 .. length ls] (map fspl ls)) []

wrap :: [(Int,[(Int, Char)])] -> [Score] -> [Score]
wrap [] acc = acc
wrap ns acc = wrap (tail ns) (elm ++ acc)
  where 
    h = head ns
    x = fst h
    src = snd h
    elm = conv x src [] 

conv :: Int -> [(Int, Char)] -> [Score] -> [Score]
conv x [] acc = acc
conv x src acc = conv x (tail src) acc'
  where
    h = head src
    val = snd h
    acc' = if val == '#' then ((x, fst h), "#") : acc
          else acc 

fspl :: String -> [(Int, Char)]
fspl s = zip [0 .. length s] s

test1 = [".....",".#.#.","....."]

test3 = ["#####.", "#.#.##", "####.#", ".#..#.", "#.##..", "#.#..."]

Measured memory_bytes: 3452
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
#define rep(var, n) for (int var = 0; var < (n); ++var)
#define ALL(c) (c).begin(), (c).end()

struct Cmp {
  bool operator()(const pll& lhs, const pll& rhs) {
    return lhs.first > rhs.first;
  }
};

ll len[51];
ll allcnt[51];

ll solve(int l, ll x) {
  if (x == 1) {
    if (l == 0)
      return 1;
    else
      return 0;
  }
  if (1 < x && x <= 1 + len[l - 1]) {
    return solve(l - 1, x - 1);
  } else if (x == 2 + len[l - 1]) {
    return allcnt[l - 1] + 1;
  } else if (2 + len[l - 1] < x && x <= 2 + 2 * len[l - 1]) {
    return allcnt[l - 1] + 1 + solve(l - 1, x - (2 + len[l - 1]));
  } else {
    return allcnt[l];
  }
}

int main() {
  int n;
  ll x;
  cin >> n >> x;
  len[0] = 1;
  allcnt[0] = 1;
  for (int i = 1; i <= n; i++) {
    len[i] = 3 + 2 * len[i - 1];
    allcnt[i] = 2 * allcnt[i - 1] + 1;
  }
  ll ans = solve(n, x);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#define ll long long
using namespace std;
int main(){
    ll n;
    cin>>n;
    map<ll,ll> a;
    
    for(int i=0;i<n;i++){
        int ai;
        cin>>ai;
        a[ai]++;
    }
    int ans=0;
    for(auto const& item:a){
        if(0==item.second%2) continue;
        ans++;
    }
    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 6528
from itertools import permutations
N, M, R = map(int, input().split())
r = list(map(int, input().split()))
E = [list(map(int, input().split())) for _ in range(M)]
INF = 10 ** 9
d = [[INF for j in range(N)] for i in range(N)]
for i, j, c in E:
    d[i - 1][j - 1] = c
    d[j - 1][i - 1] = c
for k in range(N):
    for i in range(N - 1):
        for j in range(i, N):
            dk = d[i][k] + d[k][j]
            if d[i][j] > dk:
                d[i][j] = dk
                d[j][i] = dk
ans = 10 ** 9
for ri in permutations(r):
    x = 0
    for i in range(R - 1):
        x += d[ri[i] - 1][ri[i + 1] - 1]
    if ans > x:
        ans = x
print(ans)


Measured memory_bytes: 10032
#include <bits/stdc++.h>
#include <deque>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
using P = pair<int, int>;

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

int main() {
  int h, w, ch, cw, dh, dw;
  cin >> h >> w;
  cin >> ch >> cw;
  --ch;
  --cw;
  cin >> dh >> dw;
  --dh;
  --dw;
  vector<string> s(h);
  for (int i = 0; i < h; i++) {
    cin >> s[i];
  }
  const int INF = 1e9;
  vector<vector<int> > dist(h, vector<int>(w, INF));
  deque<P> q;
  dist[ch][cw] = 0;
  q.emplace_back(ch, cw);
  while (!q.empty()) {
    int i = q.front().first;   // pairの1個目
    int j = q.front().second;  // pairの2個目
    q.pop_front();
    int d = dist[i][j];
    for (int v = 0; v < 4; v++) {
      int ni = i + di[v];
      int nj = j + dj[v];
      if (ni < 0 || ni >= h || nj < 0 || nj >= w) continue;
      if (s[ni][nj] == '#') continue;
      if (dist[ni][nj] <= d) continue;
      dist[ni][nj] = d;
      q.emplace_front(ni, nj);
    }
    for (int ei = -2; ei <= 2; ei++) {
      for (int ej = -2; ej <= 2; ej++) {
        int ni = i + ei;
        int nj = j + ej;
        if (ni < 0 || ni >= h || nj < 0 || nj >= w) continue;
        if (s[ni][nj] == '#') continue;
        if (dist[ni][nj] <= d + 1) continue;
        dist[ni][nj] = d + 1;
        q.emplace_back(ni, nj);
      }
    }
  }
  int ans = dist[dh][dw];
  if (ans == INF) ans = -1;
  cout << ans << endl;
  return 0;
}

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

using namespace std;
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> P;
typedef pair<ll, ll> PL;
#define FOR(i, a, b) for(int i = 0; i < (a); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).end()
#define debug(x) cout << #x << ": " << x << endl
#define out(x) cout << x << endl
//#define int long long int
const int MOD = 1000000007;
const ll LINF = (ll)1e18 - 1;
const int INF = 1e9 - 1;
const double EPS = 0.000000001;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

void print(const vector<int> &v) {
  for(auto x : v) {
    cout << x << " ";
  }
  cout << endl;
}

signed main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int h, w, k;
  cin >> h >> w >> k;
  VVI dp(h+1, VI(w, 0));
  dp[0][0] = 1;
  rep(i, h) {
    rep(j, w) {
      for(int k = 0; k < 1 << (w - 1); ++k) {
        bool flag = false;
        rep(s, w-2) {
          if(((k >> s) & 1) && ((k >> (s + 1)) & 1)) flag = true;
        }
        if(flag) continue;
        if(j >= 1 && ((k >> (j - 1)) & 1)) {
          dp[i + 1][j - 1] += dp[i][j];
          dp[i + 1][j - 1] %= MOD;
        }
        else if (j <= w - 2 && ((k >> j) & 1)) {
          dp[i + 1][j + 1] += dp[i][j];
          dp[i + 1][j + 1] %= MOD;
        }
        else {
          dp[i + 1][j] += dp[i][j];
          dp[i + 1][j] %= MOD;
        }
      }
    }
  }
  out(dp[h][k-1]);
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pp;
const int INF = 1e9;
const int MOD = 1000000007;
#define rep(i,n) for(int i=0;i<n;i++)
 
int main(){
  int n,k;
  cin >> n >> k;
  int ans = 1;
  rep(i,n){
    if(ans<k) ans*=2;
    else ans+= k;
  }
  cout << ans << endl;
}

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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

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

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

ll N;
ll len=0;
ll total=0;

vector<bool> seen;  // 訪問済みの点
vector<bool> seen2;  // 訪問済みの点

// BFSのための再帰関数
void dfs(const Graph &G, int v, int counter) {
    seen[v] = true;
    for (auto next_v : G[v]) { 
        if (seen[next_v]) continue;
        if(next_v == N-1){
            len = counter+1;
            continue; // N-1のノードに達したら終了
        }
        dfs(G, next_v, counter+1); // 再帰的に値を追加していく
    }
}

// BFSのための再帰関数
void dfs2(const Graph &G, int v, int counter) {
    seen2[v] = true;
    for (auto next_v : G[v]) { 
        if(seen2[next_v]) continue;
        if((len-1)/2 == counter) continue;
        dfs2(G, next_v, counter+1); // 再帰的に値を追加していく
    }
}

// BFSのための再帰関数
void dfs3(const Graph &G, int v, int counter) {
    total++;
    seen2[v] = true;
    for (auto next_v : G[v]) { 
        if(seen2[next_v]) continue;
        dfs3(G, next_v, counter+1); // 再帰的に値を追加していく
    }
}

int main()
{
    cout << fixed << setprecision(15);
    cin >> N;

    // グラフ
    Graph G(N);

    // 確保した配列の初期化
    seen.assign(N, false);
    seen2.assign(N, false);

    REP(i, N-1){
        ll a, b;
        cin >> a >> b;
        G[a-1].push_back(b-1);
        G[b-1].push_back(a-1);
    }

    dfs(G, 0, 0);
    dfs2(G, N-1, 0);
    dfs3(G, 0, 0);

    // cout << "len:" << len << endl;
    // cout << "total:" << total << endl;

    ll F = total-1;
    ll S = N-2-F;

    // cout << "F:" << F << endl;
    // cout << "S:" << S << endl;
    if(F>S){
        cout << "Fennec" << endl;
    }
    else{
        cout << "Snuke" << endl;
    }

    return 0;
}

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

#define all(x) x.begin(), x.end()
using namespace std;
using ll = long long;
using pii = pair<int, int>;
const int MN = 2e5 + 5, LN = 17, MOD = 1e9 + 7, INF = 0x3f3f3f3f, BSZ = 320;
int N, a[MN];
vector<int> g[MN];
int ans[MN];

void dfs(int u, int p, vector<int> &lis) {
    bool back = false;
    int it = 0, before = 0;
    if (lis.empty() || a[u] > lis.back()) {
        lis.push_back(a[u]);
        back = true;
    } else {
        it = lower_bound(all(lis), a[u]) - lis.begin();
        before = lis[it];
        lis[it] = a[u];
    }
    ans[u] = lis.size();
    for (int v : g[u]) {
        if (v == p) continue;
        dfs(v, u, lis);
    }
    if (back) lis.pop_back();
    else lis[it] = before;
}

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0);
    cin >> N;
    for (int i = 1; i <= N; i++) cin >> a[i];
    for (int i = 1; i < N; i++) {
        int u, v;
        cin >> u >> v;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    vector<int> lis;
    dfs(1, -1, lis);
    for (int i = 1; i <= N; i++) cout << ans[i] << '\n';
    return 0;
}


Measured memory_bytes: 30484
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
a = I()
print(a + a**2 + a**3)


Measured memory_bytes: 10412
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll GCD(ll x,ll y){
    if(y == 0) return x;
    else return GCD(y,x%y);
}

int main() {
    int n,k;
    string s;
    cin >> n >> k >> s;
    s[k-1] = s[k-1]+0x20;
    cout << s << endl;
}



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

using namespace std;

int N, a[100009], b[100009];
long long X, Y;

int main ()
{
//freopen ("input", "r", stdin);
//freopen ("output", "w", stdout);

scanf ("%d", &N);
for (int i=1; i<=N; i++)
    scanf ("%d", &a[i]);
for (int i=1; i<=N; i++)
{
    scanf ("%d", &b[i]);
    if (b[i] >= a[i]) Y += (b[i] - a[i]) / 2LL;
    else X += a[i] - b[i];
}
if (X <= Y) printf ("Yes\n");
else printf ("No\n");

return 0;
}


Measured memory_bytes: 384
<?php

$n = trim(fgets(STDIN));
$nums = explode(' ', trim(fgets(STDIN)));

$count = 0;
$max = 0;
for ($i = 0; $i < $n - 1; $i++) {
    $cur = $nums[$i];
    $next = $nums[$i + 1];

    if ($cur >= $next) {
        $count++;
    } else {
        if ($max < $count) {
            $max = $count;
        }
        $count = 0;
    }
}

echo $max > $count ? $max : $count;


Measured memory_bytes: 14840
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] west = new int[n];
		int[] east = new int[n];
		int min = 500000, sum;
		String s = sc.next();
		if (s.charAt(0) == 'W') {
			west[0]++;
		} else {
			east[0]++;
		}
		for (int i = 1; i < n; i++) {
			if (s.charAt(i) == 'W') {
				west[i] = west[i - 1] + 1;
				east[i] = east[i - 1];
			} else {
				east[i] = east[i - 1] + 1;
				west[i] = west[i - 1];
			}
		}
		for (int i = 0; i < n; i++) {
			sum = west[i] + east[n - 1] - east[i];
			if (s.charAt(i) == 'W') {
				sum--;
			}
			if (min > sum) {
				min = sum;
			}
			//System.out.println(east[i] + " " + west[i]);
			///System.out.println(sum);
		}
		System.out.println(min);
	}
}

Measured memory_bytes: 32196
#include <iostream>
#include <algorithm>
#include <vector>
#include <string.h>
typedef long long ll;

#define MAX(x, y)	(((x) > (y))? (x) : (y))
#define ABS(x)		(((x) < 0)? (-1*(x)) : (x))
#define REPI(x,y)	for (i=(x);i<(y);i++)
#define REPJ(x,y)	for (j=(x);i<(y);i++)
#define MEMCLR(X)	memset((X),0,sizeof((X)))

using namespace std;

ll X,Y;

int main() {
	ll x, n=1;

	cin >> X >> Y ;
	x = X;
	while( (x=2*x) <= Y ) n++;
	cout << n;

	return 0;
}


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

#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a)  (a).begin(),(a).end()

template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}
typedef long long ll;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}


int main() {
    int N,M;
    cin >> N >> M;
    if (N==M) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;

}


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

// int/long:		-2147483648 - 2147483648 (-2^31 <= int < 2^31)
// long/long long:	-9223372036854775808 - 9223372036854775807 (-2^63 <= long < 2^63)

#define	INF (1<<29)
//536870912

// lower_bound(A.begin(), A.end(), N)
// upper_bound(...

// bit: &/and, |/or, ^/xor, ~/not

#define	MOD 1000000007

int	main() {
	int n, m;
	cin >>n >>m;
	cout <<(n-1)*(m-1) <<endl;
	return 0;
}



Measured memory_bytes: 256
# 自分を含む次数

N,M = map(int,input().split())

def F(N,M):
  if N > M:
    N,M = M,N
  # N is smaller
  if N == 1:
    if M == 1:
      return 1
    else:
      # 両端だけ生き残る
      return M-2
  # 以下N,M >= 2
  # 中央の全て
  return (N-2)*(M-2)

answer = F(N,M)
print(answer)

Measured memory_bytes: 3060
Scanf.scanf "%d %d" (fun n c ->
    let xv = Array.init n (fun _ -> Scanf.scanf " %d %d" (fun x v -> x, v)) in
    Array.sort compare xv;
    let as1 = Array.make n 0 in
    let as2 = Array.make n 0 in
    let rec loop i cur mxdiff =
        if i < n then (
            let (x, v) = xv.(i) in
            let cur = cur + v in
            let mxdiff = max mxdiff (cur - x) in
            as1.(i) <- mxdiff;
            loop (i + 1) cur mxdiff
        )
    in
    loop 0 0 0;
    let rec loop i cur mxdiff =
        if i >= 0 then (
            let (x, v) = xv.(i) in
            let cur = cur + v in
            let mxdiff = max mxdiff (cur - (c - x)) in
            as2.(i) <- mxdiff;
            loop (i - 1) cur mxdiff
        )
    in
    loop (n - 1) 0 0;

    let rec loop i cur mx =
        if i = n then mx else
            let (x, v) = xv.(i) in
            let cur = cur + v in
            let cost = cur - x * 2 + (if i = n - 1 then x else as2.(i + 1)) in
            loop (i + 1) cur (max mx cost)
    in
    let a1 = loop 0 0 as2.(0) in

    let rec loop i cur mx =
        if i < 0 then mx else
            let (x, v) = xv.(i) in
            let cur = cur + v in
            let cost = cur - (c - x) * 2 + (if i = 0 then c - x else as1.(i - 1)) in
            loop (i - 1) cur (max mx cost)
    in
    let a2 = loop (n - 1) 0 as1.(n - 1) in
    Printf.printf "%d\n" @@ max a1 a2
)

Measured memory_bytes: 8448
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <map>
#include <cstdlib>
#include <queue>
using namespace std;


int main(){
	int X;
	cin>>X;
	if(X==3||X==5||X==7)cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
			
	return 0;
}


Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
long long mod=1000000007;

int main(){
  long long n;
  cin >> n;
  vector<bool> q(1010);
  vector<long long> p;
  for(int i=2;i<=1000;i++){q[i]=true;}
  for(int i=2;i<=1000;i++){
    if(q[i]){
      p.push_back(i);
      for(int j=2*i;j<=1000;j+=i){q[j]=false;}
    }
  }
  vector<long long> c(1010);
  for(int i=0;i<=n;i++){c[i]=0;}
  for(int i=2;i<=n;i++){
    long long w=i;
    for(int j=0;j<p.size();j++){
      if(w%p[j]==0){c[p[j]]++; w/=p[j]; j--;}
      if(w==1){break;}
    }
  }
  long long ans=1;
  for(int i=2;i<=n;i++){
    if(c[i]>0){ans=ans*(c[i]+1)%mod;}
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
//naveen mall
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb               push_back
#define sz(c)            (int)c.size()
#define len(c)           (int)c.length()
#define vec              vector
#define int              long long int
#define all(c)           c.begin(), c.end()
#define rall(c)          c.rbegin(), c.rend()
#define trav(a,i)        for(auto i: a)
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define invect(v,n)       for(int i=0;i<n;i++ ){int arb;cin>>arb;v.pb(arb);}
#define inset(s,n)        fl(i,0,n){int aset;cin>>aset;s.insert(aset);}
#define display(c)        trav(c,i) cout<<i<<" ";cout<<"\n";
#define F                 first
#define S                 second
#define pii               pair<int,int>
#define PB                pop_back
#define endl              "\n"
#define what(x) cerr << #x << " is " << x << endl;
int sum() { return 0; }template<typename T,typename... Args>T sum(T a, Args... args) { return a + sum(args...); }
#define p   200005




void solve()
{  
  int x,y,a,b,c;
    cin>>x>>y>>a>>b>>c;
    vec<int> A,B,C,v;
      rep(i,0,a)
        {
          int x;
          cin>>x;
          A.pb(x);
          

        }
        rep(i,0,b)
        {
          int x;
          cin>>x;
         B.pb(x);
          
        }
        rep(i,0,c)
        {
          int x;
          cin>>x;
          C.pb(x);
          
        }
        sort(rall(A));
        sort(rall(B));
        sort(rall(C));
        rep(i,0,x)
           v.pb(A[i]);
           rep(i,0,y)
           v.pb(B[i]);
           rep(i,0,(int)min(c,x+y))
           v.pb(C[i]);
           sort(rall(v));
           int ans=0;
           rep(i,0,x+y)
              ans+=v[i];
              cout<<ans;






       
                   



}







   


  

signed main()
{fast
  int t;
  //cin>>t;
  t=1;
  while(t--)
    {solve();}
  
}












Measured memory_bytes: 8304
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef long long ll;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    ll a, b, c;
    cin >> a >> b >> c;
    ll l = 4*a*b;
    ll r = (c-a-b)*(c-a-b);
    if(a+b >= c){
        cout << "No" << endl;
        return 0;
    }
    if(r > l){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#define REP(i, n) for(int i = 0; i < n; ++i)
#define FOR(i, m, n) for(int i = m; i < n; ++i)
using namespace std;
int main() {
	int N;
	cin >> N;
	vector<int> k;
	k.resize(N);
	REP(i, N) {
		cin >> k[i];
	}
	
	sort(k.rbegin(), k.rend());
	k[0] = k[0] / 2;
	int sum = 0;
	REP(i, N) {
		sum += k[i];
	}
	cout << sum << endl;
	system("pause");
	return 0;
}

Measured memory_bytes: 504
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mset(m,v) memset(m,v,sizeof(m))
#define pr(a,s) printf("Case #%lld: %lld\n",a,s)
#define mod 1000000007
#define mp make_pair
#define all(a)                a.begin(),a.end()
#define pb push_back
#define scan(a) scanf("%d",&a)
#define scanl(a) scanf("%lld",&a)
#define se second
#define fi first
#define pi 3.14159265358979323
#define pii pair<ll,ll>
 
const ll inf = 1e15;
const int MAXM = 3e3+4;
const int MAXN = 1e7+1;

double dp[MAXM][MAXM];
bool visit[MAXM][MAXM];
double arr[MAXM];
int n;

double solve(int idx, int heads) 
{
	if (idx == 0 and heads > n-heads) return 1.0;
	if (idx == 0)	return 0.0;
	if (visit[idx][heads])	return dp[idx][heads];
	double ret = 0.0;
	ret += arr[idx] * solve(idx-1, heads+1);
	ret += (1.0-arr[idx]) * solve(idx-1, heads);
	visit[idx][heads] = true;
	return dp[idx][heads] = ret; 
}

int main()
{
	mset(visit, false);
	cin>>n;
	for (int i=1;i<=n;i++) {
		cin>>arr[i];
	}
	printf("%0.10lf\n", solve(n,0));
	return 0;
}

Measured memory_bytes: 78592
#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
#define ll long long
#define pi pair<int,int>
#define pl pair<ll,ll>
#define pd pair<double,double>
#define ld long double
#define pld pair<ld,ld>
#define lg length()
#define sz size()
#define pb push_back
#define INF 1000000005
#define LINF 1000000000000000005

int n,m,w[105],v[105];

ll dp[105][100005],ans;

int32_t main(){
    ios_base :: sync_with_stdio(0); cin.tie(); cout.tie();
    cin >> n >> m;
    for(int i=1;i<=n;i++){
        cin >> w[i] >> v[i];
    }
    for(int i=0;i<=n;i++){
        for(int j=0;j<=100000;j++) dp[i][j]=INF;
    }
    dp[0][0]=0;
    for(int i=1;i<=n;i++){
        for(ll j=0;j<=100000;j++){
            if(j<v[i]) dp[i][j]=dp[i-1][j];
            else dp[i][j]=min(dp[i-1][j],dp[i-1][j-v[i]]+w[i]);
            if(dp[i][j]<=m) ans=max(ans,j);
        }
    }
    cout << ans;
}


Measured memory_bytes: 80128
#include<bits/stdc++.h> 
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace std;
using namespace __gnu_pbds;  
#define ordered_set tree<ll, null_type , less<ll> , rb_tree_tag , tree_order_statistics_node_update> 
#define ll long long
#define ull unsigned long long
#define pb push_back
#define inf 1e18
#define mk make_pair
#define ld long double
#define mod 998244353
#define fi first
#define se second
#define fastIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define test ll t; cin>>t; while(t--)
#define setbits __builtin_popcount
#define endl '\n'
#define LOCAL
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i));}
sim, class b dor(pair < b, c > d) {
    ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
    *this << "[";
    for (auto it = d.b; it != d.e; ++it)
        *this << ", " + 2 * (it == d.b) << *it;
    ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
ll dx[4]={1,-1,0,0},dy[4]={0,0,1,-1};
char ch[21][21];
ll visit[21][21],dis[21][21];
ll bfs(ll x,ll y,ll n,ll m)
{
    ll ans=0,val,val1;
    memset(visit,0,sizeof(visit));
    memset(dis,0,sizeof(dis));
    queue<pair<ll,ll>>q;
    q.push(mk(x,y));
    visit[x][y]=1;
    dis[x][y]=0;
    while(q.size()!=0)
    {
        pair<ll,ll>p=q.front();
        q.pop();
        for(int i=0;i<4;i++)
        {
            val=p.fi+dx[i];
            val1=p.se+dy[i];
            if(visit[val][val1]==0 && val>=0  && val<n && val1>=0 && val1<m && ch[val][val1]=='.')
            {
                visit[val][val1]=1;
                dis[val][val1]=dis[p.fi][p.se]+1;
                q.push({val,val1});
                ans=max(dis[val][val1],ans);
            }
        }
    }
    return ans;
}
int main()
{
    ll h,w;
    cin>>h>>w;
    for(int i=0;i<h;i++)
    {
        for(int j=0;j<w;j++)
        {
            cin>>ch[i][j];
        }
    }
    ll x,y,val,val1,ans=0;
    for(int i=0;i<h;i++)
    {
        for(int j=0;j<w;j++)
        {
            if(ch[i][j]=='.')
            {
                ans=max(ans,bfs(i,j,h,w));
            }
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <complex>
#include <stack>
#include <unordered_map>
using namespace std;



int main(){
    long long int data[100001] = {};
    long long int n, k;
    long long int a, b;
    int i= 0;
    
    cin >> n >> k;
    
    for(i = 0; i < n; i++){
        cin >> a >> b;
        data[a] += b;
    }
    
    
    long long int count = 0;
    
    for(i = 1; i <= 100000; i++){
        count += data[i];
        if(count >= k){
            break;
        }
    }
    
    cout << i << endl;
}


Measured memory_bytes: 1024
#include <vector>
#include <iostream>
using namespace std;

const int64_t INF = 1ll << 60;

int main(){
	const int V_MAX = 100000;
	int N,W;

	cin >> N >> W;
	vector<int> w;
	vector<int> v;
	w.push_back(0);
	v.push_back(0);
	for(int i=0;i<N;i++){
		int _w,_v;
		cin >> _w >> _v;
		w.push_back(_w);
		v.push_back(_v);
	}

	int64_t dp[N+1][V_MAX+1];

	for(int i=0;i<=N;i++){
		for(int j=0;j<=V_MAX;j++){
			dp[i][j] = INF;
		}
	}

	dp[0][0] = 0;
	for(int i=1;i<=N;i++){
		for(int j=0;j<=V_MAX;j++){
			if(j>=v[i]){
				dp[i][j] = min(dp[i-1][j],dp[i-1][j-v[i]]+w[i]);
			} else {
				dp[i][j] = dp[i-1][j];
			}
		}
	}

	int w_max = 0;
	for(int j=0;j<=V_MAX;j++){
		if(dp[N][j]<=W){
			w_max = max(w_max,j);
		}
	}

	cout << w_max << endl;
}

Measured memory_bytes: 79232
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>

using namespace std;
int n;
long long a[50];

struct ans_e {
  int i, j;
};

ans_e ans[100];
size_t ans_size;
int imin, imax;

void add(int x, int y) {
  if (ans_size >= 2*n) {
    cout << "ERROR";
    exit(1);
  }

  a[y] += a[x];
  if (a[y] < a[imin]) {
    imin = y;
  }

  if (a[y] > a[imax]) {
    imax = y;
  }

  ans[ans_size].i = x;
  ans[ans_size].j = y;
  ans_size++;
}

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

  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  imin = imax = 0;

  for (int i = 1; i < n; i++) {
    if (a[i] < a[imin]) {
      imin = i;
    } else if (a[i] > a[imax]) {
      imax = i;
    }
  }

  if (a[imin] >= 0) {
    for (int i = 1; i < n; i++) {
      if (a[i-1] > a[i]) {
        add(i-1, i);
      }
    }
  } else {
    if (abs(a[imax]) >= abs(a[imin])) {
      for (int i = 1; i < n; i++) {
        if (a[i-1] > a[i]) {
          while (a[i-1] > a[i]) {
            add(imax, i);
          }
        }
      }
    } else {
      for (int i = n-1; i > 0; i--) {
        if (a[i] < a[i-1]) {
          while (a[i] < a[i-1]) {
            add(imin, i-1);
          }
        }
      }
    }
  }

  // for (int i = 0; i < n; i++) {
  //   cout << a[i] << " ";
  // }
  // cout << endl;

  cout << ans_size << endl;

  for (int i = 0; i < ans_size; i++) {
    cout << ans[i].i + 1 << " " << ans[i].j + 1 << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL N = 100010;
inline LL read()
{
  LL p=0; LL f=1; char ch=getchar();
  while(ch<'0' || ch>'9'){if(ch=='-') f=-1; ch=getchar();}
  while(ch>='0' && ch<='9'){p=p*10+ch-'0'; ch=getchar();}
  return p*f;
}

LL n,c; LL a[N],sum[N],mx[N]; LL val[N];

LL ans = 0;

void solve()
{
  memset(mx,0,sizeof(mx));
  memset(sum,0,sizeof(sum));
  LL s = 0; for(LL i=n;i>=1;i--)
  {
    s += val[i]; mx[i] = max(mx[i-1] , max(0ll , s - 2 * (c-a[i])));
  }
  s = 0;
  for(LL i=1;i<=n;i++)
  {
    s += val[i]; sum[i] = max(sum[i-1],max(0ll,s-a[i]));
    ans = max(ans , sum[i] + mx[i+1]);
    // printf("%lld %lld %lld\n",i,sum[i],mx[i+1]);
  }
}

int main()
{
  n = read(); c = read();
  for(LL i=1;i<=n;i++) a[i] = read(),val[i] = read();
  solve();
  for(LL i=1;i<=n;i++) a[i] = c - a[i];
  reverse(a+1,a+n+1); reverse(val+1,val+n+1);
  solve();
  return printf("%lld\n",ans),0;
}

Measured memory_bytes: 3328
/*
有向グラフに対して使う

O(V+E)
最後にソートして多重辺を消している
参考:
https://ei1333.github.io/luzhiled/snippets/graph/strongly-connected-components.html
verify:
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_3_C&lang=jp
*/
#include <bits/stdc++.h>
using namespace std;
using ll=long long int;
template<class T,class U>constexpr bool chmin(T&a,const U b){if(a<=b)return false;a=b;return true;}
template<class T,class U>constexpr bool chmax(T&a,const U b){if(a>=b)return false;a=b;return true;}
typedef pair<int,int> pii;

using Graph=vector<vector<int>>;


template<typename G>
struct StronglyConnectedComponents{
    const G &g;
    Graph rg;
    int sz;
    vector<int> comp,order;
    vector<bool> used;
    Graph x;
    int group;

    StronglyConnectedComponents(G &g):g(g),sz(g.size()),rg(g.size()),comp(g.size(),-1),used(g.size(),false){

        for(int i=0;i<sz;i++){
            for(auto e:g[i]){
                rg[e].push_back(i);
            }
        }
        for(int i=0;i<sz;i++){
            if(!used[i]) dfs(i); 
        }
        int ptr=0;
        for(int i=sz-1;i>=0;i--){
            int x=order[i];
            if(comp[x]==-1) rdfs(x,ptr),ptr++;
        }
        group=ptr;
    }

    int operator[](int k){
        return comp[k];
    }

    void dfs(int idx){
        used[idx]=true;
        for(auto e:g[idx]){
            if(!used[e]) dfs(e);
        }
        order.push_back(idx);
    }
    void rdfs(int idx,const int ptr){
        comp[idx]=ptr;
        for(int to:rg[idx]){
            if(comp[to]==-1) rdfs(to,ptr);
        }
    }
    void build(){
        x.resize(group);
        for(int i=0;i<sz;i++){
            for(auto to:g[i]){
                int s=comp[i],t=comp[to];
                if(s==t) continue;
                x[s].push_back(t);
            }
        }
        for(int i=0;i<group;i++){
            sort(x[i].begin(),x[i].end());
            x[i].erase(unique(x[i].begin(),x[i].end()),x[i].end());        
        }
    }
};

signed main(){
    int v,e;
    cin>>v>>e;
    Graph g(v);
    for(int i=0;i<e;i++){
        int s,t;
        cin>>s>>t;
        g[s].push_back(t);
    }
    StronglyConnectedComponents<Graph> s(g);
    int Q;
    cin>>Q;
    while(Q--){
        int u,v;
        cin>>u>>v;
        if(s[u]==s[v]) cout<<1<<endl;
        else cout<<0<<endl;
    }
}


Measured memory_bytes: 4432