akhauriyash/Code-Regression huggingface dataset:
import sys
input = sys.stdin.readline

n = int(input())
s = list(str(input()))
q = int(input())

s = [ord(c)-ord('a') for c in s]

#def segfunc(x,y):
    #return x | y

def init(init_val):
    #set_val
    for i in range(n):
        seg[i+num-1]={init_val[i]}
    #built
    for i in range(num-2,-1,-1) :
        seg[i]=seg[2*i+1] | seg[2*i+2]

def update(k,x):
    k += num-1
    seg[k] = x
    while k:
        k = (k-1)//2
        seg[k] = seg[k*2+1] | seg[k*2+2]

def query(p,q):
    if q<=p:
        return ide_ele
    p += num-1
    q += num-2
    res=ide_ele
    while q-p>1:
        if p&1 == 0:
            res = res | seg[p]
        if q&1 == 1:
            res = res | seg[q]
            q -= 1
        p = p//2
        q = (q-1)//2
    if p == q:
        res = res | seg[p]
    else:
        res = (res | seg[p]) | seg[q]
    return res

#####単位元######
ide_ele = set()

#num:n以上の最小の2のべき乗
num =2**(n-1).bit_length()
seg=[ide_ele]*2*num

init(s)
#print(seg)

for i in range(q):
    t, x, y = map(str, sys.stdin.readline().split())
    if t == '2':
        l = int(x)-1
        r = int(y)-1
        print(len(query(l, r+1)))
    else:
        i = int(x)-1
        c = {ord(y)-ord('a')}
        update(i, c)


Measured memory_bytes: 471408
#include "bits/stdc++.h"
// Custom Header {{{
#define all(x) x.begin(), x.end()
#define rep(i,n)    for (i64 i = 0; i < (n); ++i)
#define reps(i,s,t) for (i64 i = (s); i <= (t); ++i)
#define repr(i,s,t) for (i64 i = (n); i >= (t); --i)
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;}
constexpr int INF  = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
// }}}

struct Edge { // {{{
    int src, to;
    i64 cost;
    Edge(int src,  int to, i64 cost) : src(src), to(to), cost(cost) {}
    Edge(int to, i64 cost = 0) : Edge(-1, to, cost) {}
    Edge() {}
    bool operator< (const Edge &o) const { return cost < o.cost; }
    bool operator> (const Edge &o) const { return cost > o.cost; }
};
using Edges = vector<Edge>;
using WGraph = vector<vector<Edge>>;
using UGraph = vector<vector<int>>;
// }}}

vector<i64> SPFA(const WGraph &G, int src) // {{{
{
    vector<i64> dist(G.size(), LINF);
    vector<int> cnt(G.size(), 0);
    vector<bool> pending(G.size(), false);
    queue<int> que;

    que.emplace(src);
    ++cnt[src];
    dist[src] = 0;

    while(!que.empty()) {
        const int u = que.front(); que.pop();
        pending[u] = false;
        for (const auto &e : G[u]) {
            if (!chmin(dist[e.to], dist[u] + e.cost)) continue;
            if (pending[e.to]) continue;
            if (++cnt[e.to] >= G.size()) return {};
            pending[e.to] = true;
            que.emplace(e.to);
        }
    }

    return dist;
}
// }}}


/*
   Verified On: 2019-08-11
   https://atcoder.jp/contests/abc137/tasks/abc137_e
*/
void arrivableNodeDFS(int u, const WGraph &G, bool vist[])
{
    if (!vist[u]) {
        vist[u] = true;
        for (const auto &e : G[u]) arrivableNodeDFS(e.to, G, vist);
    }
}
void ABC137_E() // {{{
{
    int N, M, P;
    cin >> N >> M >> P;

    WGraph G(N), revG(N);
    rep(i, M) {
        int a, b, c;
        cin >> a >> b >> c;
        --a; --b;
        c -= P;
        G[a].emplace_back(a, b, -c);
        revG[b].emplace_back(b, a, -c);
    }

    bool canArrive[2555] {};
    bool canGoal[2555] {};

    arrivableNodeDFS(0, G, canArrive);
    arrivableNodeDFS(N-1, revG, canGoal);

    WGraph H(N);
    rep(u, N) {
        if (canArrive[u] && canGoal[u]) {
            for (const auto &e : G[u]) H[u].emplace_back(e);
        }
    }

    const auto cost = SPFA(H, 0);
    if (cost.empty()) {
        cout << -1 << endl;
    } else {
        cout << max<i64>(0, -cost[N-1]) << endl;
    }
}
// }}}

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


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

int main() {
    long A, B, C, X, Y;
    cin>>A>>B>>C>>X>>Y;
    if(A+B<=2*C){
        cout<<A*X+B*Y<<endl;
    }
    else {
        long ans = 0;
        ans += 2*C*min(X, Y);
        if(X>Y){
            if((X-Y)*(2*C) < A*(X-Y)) ans += (X-Y)*(2*C);
            else ans += A*(X-Y);
        }
        else{
            if((Y-X)*(2*C) < B*(Y-X)) ans += (Y-X)*(2*C);
            else ans += B*(Y-X);
        }
        cout<<ans<<endl;
    }
}


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

int main() {

    char s[100000];
    
    scanf("%s", s);

    for (int i = 97; i < 97+ 26; i++) {

        char *p;
        p = strchr(s, i);
        
        if(p == NULL) {
            printf("%c", i);
            return 0;
        }

    }
    
    printf("None");
    
    


}


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

int main(){
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	ll n;
	cin>>n;
	ll s = 0;
	for (ll i = 1; i<=n; i++){
		if (i%3!=0&&i%5!=0){
			s+=i;
		}
	}
	cout<<s<<endl;
	return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <algorithm>
#include <limits>
using namespace std;
vector<int> S;

int merge(int left,int mid,int right){
  int n1=mid-left;
  int n2=right-mid;
  int count=0;
  vector<int> L(S.begin()+left,S.begin()+left+n1);
  vector<int> R(S.begin()+mid,S.begin()+mid+n2);
  L.push_back(numeric_limits<int>::max());
  R.push_back(numeric_limits<int>::max());
  int i=0,j=0;
  for(int k=left;k<right;k++){
    if (L[i]<=R[j]){
      S[k]=L[i];
      i++;
    }else{
      S[k]=R[j];
      j++;
    }
    count++;
  }
  return count;
}


int mergeSort(int left,int right){
  if (left+1<right){
    int mid=(left+right)/2;
    int cnt=0;
    cnt+=mergeSort(left,mid);
    cnt+=mergeSort(mid,right);
    cnt+=merge(left,mid,right);
    return cnt;
  }
  return 0;
}

int main(){
  int n;
  cin>>n;
  S.resize(n);
  for(int i=0;i<n;i++){
    cin>>S[i];
  }
  int cnt=mergeSort(0,n);
  int i=0;
  while(i<n){
    if (i++>0) cout<<" ";
    cout<<S[i-1];
  }
  cout<<endl;
  cout<<cnt<<endl;
  return 0;
}
  



Measured memory_bytes: 8708
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>

#define rep(i, n) for(int i = 0; i < (n); i++)
#define pb push_back

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
int dx[4] = {0,1,0,-1};
int dy[4] = {-1, 0, 1, 0};
const int INF = 1 << 29;
const double EPS = 1e-9;
const int MAX_N = 20;
int W, H, ans = 1;
vector<string> field;

int dfs(int x, int y){
		rep(i, 4){
				int tx = x + dx[i], ty = y + dy[i];
				if(0 <= ty && 0 <= tx && ty < H && tx < W && field[ty][tx] == '.' ){
						ans++;
						field[ty][tx] = '#';
						dfs(tx, ty);
				}
		}
		return ans;
}

int main(){
		while(1){
				cin >> W >> H;
				if(W == 0 && H == 0) break;

				field.resize(H);
				rep(i,H) cin >> field[i];
				int sx, sy;

				//rep(i,H) cout << field[i] << endl;

				rep(y,H)rep(x,W)if(field[y][x] == '@'){ sx = x; sy = y; }

				//cout << sx << " " <<sy <<endl;
				dfs(sx, sy);
				//rep(i,H) cin >> field[i];
				cout << ans <<endl;
				ans = 1;
		}
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#define REP(x,y,z) for(int x=y;x<=z;x++)
#define FORD(x,y,z) for(int x=y;x>=z;x--)
#define MSET(x,y) memset(x,y,sizeof(x))
#define FOR(x,y) for(__typeof(y.begin()) x=y.begin();x!=y.end();x++)
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define SZ size()
#define M 
void RI(){}
template<typename... T>
void RI( int& head, T&... tail ) {
    scanf("%d",&head);
    RI(tail...);
}
using namespace std;
typedef long long LL;
struct P
{
	double x,y;
	P(){}
	P(double a,double b)
	{
		x = a;
		y = b;
	}
};
int n,q;
vector<P> poly;

double dis(P a,P b)
{
	return sqrt( (a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y) );
}

bool onPolygon(vector<P> &polygon, P p)
{
	int cnt = polygon.size();
	P cur,nxt;
	double t;
	
	REP(i,0,cnt-1)
	{
		cur = polygon[i];
		nxt = polygon[(i+1)%cnt];

		t = dis(p,cur) + dis(p,nxt) - dis(cur,nxt);
		if( fabs(t) <= 1e-9 ) return true;
	}
	return false;
}

bool windingNumber(vector<P> &polygon, P p)
{
	int w=0;
	int cnt = polygon.size();
	P cur,nxt;

	REP(i,0,cnt-1)
	{
		cur = polygon[i];
		nxt = polygon[(i+1)%cnt];

		if( (cur.x>=p.x) ^ (nxt.x>=p.x) )
			w += (cur.x-p.x) * (nxt.y-p.y) >= (nxt.x-p.x) * (cur.y-p.y) ? 1 : -1;
	}
	return w!=0;
}

int main()
{
	P p;
	int x,y;
	RI(n);
	REP(i,1,n)
	{
		RI(x,y);
		poly.PB( P(x,y) );
	}

	RI(q);
	while(q--)
	{
		RI(x,y);
		p = P(x,y);

		if( onPolygon(poly, p) )
			puts("1");
		else if( windingNumber(poly, p) )
			puts("2");
		else
			puts("0");
	}
	return 0;
}

Measured memory_bytes: 3148
# frozen_string_literal: true

$h, $w = gets.chomp.split(' ').map(&:to_i)

$map = []

$count_sharp = 0

$h.times do
  line = gets.chomp.split('')
  $count_sharp += line.count { |s| s == '#' }

  $map << line
end

$queue = [[0, 0, 1]]

$visited = {}
$res = 0

until $queue.empty?
  i, j, dist = $queue.shift
  next if $map[i][j] == '#'
  next if $visited["#{i},#{j}"]

  if i == $h - 1 && j == $w - 1
    puts $h * $w - dist - $count_sharp
    exit(0)
  end

  $visited["#{i},#{j}"] = true

  $queue << [i + 1, j, dist + 1] if i + 1 < $h
  $queue << [i - 1, j, dist + 1] if i - 1 >= 0
  $queue << [i, j + 1, dist + 1] if j + 1 < $w
  $queue << [i, j - 1, dist + 1] if j - 1 >= 0
end

puts '-1'


Measured memory_bytes: 2172
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define dd double
#define endl "\n"
#define pb push_back
#define all(v) v.begin(),v.end()
#define mp make_pair
#define fi first
#define se second
#define fo(i,n) for(int i=0;i<n;i++)
#define fo1(i,n) for(int i=1;i<=n;i++)
ll mod=1000000007;
ll n,k,t,m,q,flag=0;
ll po(ll k ,ll n,ll ans,ll temp,ll ans1){
    if(n==0)return ans;
    while(temp<=n){
        ans*=ans1;ans%=mod;ans1=ans1*ans1;ans1%=mod;n=n-temp;temp*=2;
    }
    return po(k,n,ans,1,k)%mod;
    //eg. po(2,78,1,1,2);
}
ll min(ll a,ll b){if(a>b)return b;else return a;}
ll max(ll a,ll b){if(a>b)return a;else return b;}
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    
    //cin>>t;
    t=1;
    while(t--){
        
        string s;
        cin>>s;
        if(s[2]==s[3] && s[4]==s[5])cout<<"Yes";
        else cout<<"No";
    }

    return 0;
}


Measured memory_bytes: 256
N = int(input())
kind = []
unkind = []
for _ in range(N):
    a = int(input())
    k = u = 0
    for _ in range(a):
        ans, y = [int(_) for _ in input().split()]
        ans -= 1
        if y:
            k += 2**ans
        else:
            u += 2**ans
    kind += [k]
    unkind += [u]
ans = 0
for B in range(2**N - 1, -1, -1):
    k = 0
    u = 0
    for b in range(N):
        if (B >> b) & 1:
            k |= kind[b]
            u |= unkind[b]
    if (k & B) == k and (u & B) == 0:
        ans = max(ans, bin(B).count('1'))
print(ans)


Measured memory_bytes: 3064
#include <iostream>
#include <cctype>
using namespace std;
 
int main(){
    char ch;
    int cnt[26] = {0};
    while(cin >> ch){
        if(isupper(ch)) cnt[ch - 'A']++;
        else if(islower(ch)) cnt[ch - 'a']++;
    }
    for(int i=0;i<26;i++){
        cout << char(i +'a') << " : " << cnt[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 3068
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); ++i)
#define outl(x) cout<< (x) << '\n'
using pii = pair<int,int>;
using ll = long long;

int N;
ll M;
ll a[1000010];

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

    cin >> N >> M;
    rep(i, N) {
        cin >> a[i];
    }

    ll ans = 0;
    ll sum = 0;
    map<ll, ll> mp;

    mp[0]++;
    rep(i, N) {
        (sum += a[i]) %= M;
        ans += mp[sum];
        ++mp[sum];
    }

    outl(ans);


    return 0;
}



Measured memory_bytes: 4992
#include <iostream>

using namespace std;

void solve() {
  int a, b;
  cin >> a >> b;
  if (b < 0) {
    if (abs(b-a) % 2 == 1) {
      cout << "Positive" << endl;
    } else {
      cout << "Negative" << endl;
    }

  } else if (0 < a) {
    cout << "Positive" << endl;
  } else {
    cout << "Zero" << endl;
  }
}

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


Measured memory_bytes: 256
import numpy as np
def resolve():
    N,M = map(int,input().split())
    H = list(map(int,input().split()))
    ans = np.ones(N, dtype=int)
    for _ in range (M):
        A,B = map(int,input().split())
        if H[A-1] <= H[B-1]:
            ans[A-1] = 0
        if H[B-1] <= H[A-1]:
            ans[B-1] = 0
    print(sum(ans))
resolve()

Measured memory_bytes: 38348
n = int(input())

amap = [list(map(int, input().split())) for _ in range(n)]
isnt_const = False
cost = 0
for i in range(n):
  for j in range(i+1, n):
    isnt_add = False
    for k in range(n):
      if i == k or k == j:
        continue
      if amap[i][j] > amap[i][k] + amap[k][j]:
        isnt_const = True
        break
      elif amap[i][j] == amap[i][k] + amap[k][j]:
        isnt_add = True
    if not isnt_add:
      cost += amap[i][j]

if isnt_const:
  print(-1)
else:
  print(cost)


Measured memory_bytes: 44380
#include <bits/stdc++.h>
 
using namespace std;
 
#define lli long long int
#define REP(i,s,l) for(lli i=s;i<l;i++)
#define DEBUG 0
#define INF (1LL<<50)
#define MOD 1000000007

signed main(){

	lli a,b;
	cin>>a>>b;

	vector<lli> v;
	v.push_back(a+b);
	v.push_back(a-b);
	v.push_back(a*b);

	sort(v.begin(),v.end());

	cout<<v[2]<<endl;
	

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#define MAX 2000001
#define VMAX 10000

main()
{
  unsigned short *A, *B;
  int C[VMAX+1]; //カウント用
  int i, j, n;

  scanf("%d", &n);
  A = malloc(sizeof(short)*n + 1);
  B = malloc(sizeof(short)*n + 1);

  for(i=0; i<=VMAX; i++) C[i]=0;

  /* Aの読込み & Cにそれぞれの数の出現数をカウント */
  for(i=0; i<n; i++)
    {
      scanf("%hu", &A[i+1]);
      C[A[i+1]]++;
    }

  /* C[i]にi以下の数の出現数を記録(handout 6th lecture p17) */
  for(i=1; i<=VMAX; i++) C[i] = C[i] + C[i-1];

  /* Counting Sort */
  for(j=1; j<=n; j++)
    {
      B[C[A[j]]] = A[j];
      C[A[j]]--;
    }

  /* print */
  for(i=1; i<=n; i++)
    {
      printf("%d", B[i]);
      if(i != n)
	{
	  printf(" ");
	}
    }
  printf("\n");

  free(A);
  free(B);
  return 0;
}

Measured memory_bytes: 8408
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 
class Program
{
    static void Main(string[] args)
    {
        int a,b,c;
        string[] str = Console.ReadLine().Split(' ');
        a = int.Parse(str[0]);
        b = int.Parse(str[1]);
        c = int.Parse(str[2]);
        int i;
        for(i = 0; i < 100; i++){
            int x = b * i + c;
            if(x % a == 0){
                Console.WriteLine("YES");
                break;
            }
        }
        if(i == 100){
            Console.WriteLine("NO");
        }
    }
}

Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 
  int N,K;
  cin >> N >> K;
  vector<bool> have(N, false);
  
  for (int i = 0; i < K; i++){
    int d;
    cin >> d;
    for (int j = 0; j < d; j++){
      int A;
      cin >> A;
      have.at(A - 1) = true;
    }
  }
  
  int count = 0;
  for (int i = 0; i < N; i++){
    if (!have.at(i)){
      count++;
    }
  }
  
  cout << count;
      
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep2(i, a, n) for(ll i = a; i < (ll)(n); i++)
#define memi cout << endl
#define kono(n) cout << fixed << setprecision(n)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define hina cout << ' '
#define in(n) cin >> n
#define in2(n, m) cin >> n >> m
#define in3(n, m, l) cin >> n >> m >> l
#define out(n) cout << n
const ll mei = (ll)1e9 + 7;

int main(){
  ll a, n, b, c;
  in(n);
  vector<ll> w(n);
  a = 0;
  rep(i, n){
    in(w[i]);
    a += w[i];
  }
  b = a;
  c = 0;
  rep(i, n){
    a -= w[i];
    c += w[i];
    b = min(b, abs(a - c));
  }
  out(b);
  memi;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
using ll=long long;
 
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define pb push_back
#define eb emplace_back
#define a first
#define b second
#define bg begin()
#define ed end()
#define all(x) x.bg,x.ed
const int MOD = 1000000007; 

int main() {
    int n, k;
    cin >> n >> k;
    unordered_map<int, int> as;
    rep(i, n) {
        int a; cin >> a;
        as[a]++;
    }
    int m = as.size();
    int ret = 0;
    if (m > k) {
        vector<pair<int, int>> av(as.begin(), as.end());
        sort(av.begin(), av.end(), [](const auto& p1, const auto& p2){ return p1.second < p2.second;});
        rep(i, m-k) ret += av[i].second;
    }
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 10056
package main

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

const (
	initialBufSize = 10000
	maxBufSize     = 1000000
)

var (
	sc *bufio.Scanner = func() *bufio.Scanner {
		sc := bufio.NewScanner(os.Stdin)
		buf := make([]byte, initialBufSize)
		sc.Buffer(buf, maxBufSize)
		sc.Split(bufio.ScanWords)
		return sc
	}()
	mod int = 1e9 + 7
)

func main() {
	N := getInt()
	S := getString()
	T := getString()

	for i := 0; i < N; i++ {
		fmt.Print(string(S[i]))
		fmt.Print(string(T[i]))
	}
}

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

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

func abs(a int) int {
	return int(math.Abs(float64(a)))
}

func pow(p, q int) int {
	return int(math.Pow(float64(p), float64(q)))
}

func min(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton min() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Min(float64(res), float64(nums[i])))
	}
	return res
}

func max(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton max() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Max(float64(res), float64(nums[i])))
	}
	return res
}

func strSearch(a []string, b string) bool {
	for i := 0; i < len(a); i++ {
		if a[i] == b {
			return true
		}
	}
	return false
}

func printIntArray(array []int) {
	strArray := fmt.Sprint(array)
	fmt.Println(strArray[1 : len(strArray) - 1])
}

func calcMod(x int) int {
	return x % mod
}


Measured memory_bytes: 640
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.LinkedHashMap;
import java.util.Map;

public class Main {

	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int size = Integer.parseInt(br.readLine());
		int num = 0;
		Map<Integer, Integer> inputMap = new LinkedHashMap<Integer, Integer>();
		String[] inputNums = br.readLine().split(" ");
		for (int i = 0; i < size; i++) {
			num = Integer.parseInt(inputNums[i]);
			if (inputMap.containsKey(num)) {
				int cnt = inputMap.get(num);
				inputMap.put(num, cnt + 1);
			} else {
				inputMap.put(num, 1);
			}
		}

		size = Integer.parseInt(br.readLine());
		inputNums = br.readLine().split(" ");
		int sum = 0;
		for (int i = 0; i < size; i++) {
			num = Integer.parseInt(inputNums[i]);
			if (inputMap.containsKey(num)) {
				int cnt = inputMap.get(num);
				sum += 1;
			}
		}
		System.out.println(sum);
	}
}

Measured memory_bytes: 29304
#include<stdio.h>

int main(){
	int a, b, d = 0, r = 0;
	double f = 0;
	scanf("%d %d", &a, &b);
	d = a / b;
	r = a % b;
	f = (double)a / (double)b;
	printf("%d %d %lf\n",d ,r, f);
	return 0;
}

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

void solve(char *str, int n) {
    int r = 0, b = 0, i;
    for(i = 0; i < n; ++i) {
        if(str[i] == 'B') { ++b; } 
        else { ++r; }
    }
    //printf("r: %d b: %d\n", r, b);
    if(r > b) { printf("Yes\n"); } else { printf("No\n"); }
}

int main(void) {
    int n;
    scanf("%d", &n);
    char *str = (char*)malloc((n+4)*sizeof(char));
    scanf("%s", str);
    solve(str, n);
    return 0;
}

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

#define rep(i, n) for(int i = 0; i < (n); ++i)

using namespace std;

int n, a, b, c;
int d[100];

int main(){
	cin >> n >> a >> b >> c;
	rep(i, n){
		cin >> d[i];
	}

	sort(d, d + n, greater<int>());

	int ans = c / a;
	rep(i, n){
		c += d[i];
		a += b;
		ans = max(c / a, ans);
	}
	cout << ans << endl;
	return 0;
}

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


int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int n ;
    cin >> n;
    int arr[n - 1];
    for (int i = 0; i < n; i++) {
        cin >> arr[i];
    }
    map<int , int>m;
    for (int i = 0; i < n - 1; i++) {
        m[arr[i]]++;
    }
    for (int i = 1; i <= n; i++) {
        if (m.find(i) == m.end()) {
            cout << 0 << "\n";
        }
        else {
            cout << m[i] << "\n";
        }
    }
    return 0;

}





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

int main() {
  
  int A, B;
  cin >> A >> B;
  
  if (A == B) {
    cout << 2 * A << endl;
  }
  else {
    cout << 2 * max(A,B) -1 << endl;
  }

return 0;
}

Measured memory_bytes: 3604
import sys

def solve(circleA, circleB):
    xa, ya, ra = circleA
    xb, yb, rb = circleB
    # ?????????????????????????????????????????´????????????
    if ra <= rb:
        if distancePow2(xa, ya, xb, yb) < pow(rb - ra, 2):
            return -2
    else:
        if distancePow2(xa, ya, xb, yb) < pow(rb - ra, 2):
            return 2

    # ??±???????????????????????????
    if pow(rb - ra, 2) <= distancePow2(xa, ya, xb, yb) <= pow(rb + ra, 2):
        return 1

    return 0

def distancePow2(xa, ya, xb, yb):
    return pow(xb - xa, 2) + pow(yb - ya, 2)

n = int(input())
for i in range(0, n):
    inStr = input()
    circleAInfo = [float(data) for data in inStr.split(" ")[0:3]]
    circleBInfo = [float(data) for data in inStr.split(" ")[3:6]]
    print(solve(circleAInfo, circleBInfo))

Measured memory_bytes: 7616
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n, k;
		int s[];
		int a[][];
		boolean f;


		while (true) {
			n = sc.nextInt();
			k = sc.nextInt();
			if ((n | k) == 0) {
				break;
			}
			s = new int[k];
			for (int i = 0; i < k; i++) {
				s[i] = sc.nextInt();
			}
			f = true;
			for (int i = 0; i < n; i++) {
				for (int j = 0; j < k; j++) {
					s[j] -= sc.nextInt();
					if (s[j] < 0) {
						f = false;
					}
				}
			}
			
			System.out.println(f == true ? "Yes" : "No");
		}
	}
}

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

using namespace std;

int main(){
  string str;
  cin >> str;
  
  if(str.at(2)==str.at(3) && str.at(4)==str.at(5)){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}


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

int main_()
{
    int N;
    vector<int> As;
    cin >> N;
    copy_n(istream_iterator<int>(cin), N, back_inserter(As));
    auto as_sort(As);
    partial_sort(as_sort.begin(), as_sort.begin() + 2, as_sort.end(),
                 [](int a, int b) { return a > b; });

    vector<int> outs;
    transform(As.begin(), As.end(), back_inserter(outs),
              [&as_sort](int a) { return (a < as_sort[0] ? as_sort[0] : as_sort[1]); });

    copy(outs.begin(), outs.end(), ostream_iterator<int>(cout, "\n"));
}
int main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    main_();
    return 0;
}


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

int main(){
#ifndef ONLINE_JUDGE
//	freopen("in.txt","r",stdin);
#endif
	//read
	int sum=0;
	char ch;
	while(cin>>ch)
		sum+=int(ch-'0');
	if(sum%9==0)
		cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
} 

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
const int N=1e3+10,maxn=5050;
vector<int> G[N];
int w[N],f[N],c[N]; 	//dp[i]指i点另外一种颜色的最小值 
const int INF=0x3f3f3f3f;
int dp[2][maxn];
#define y x^1
void dfs(int k){
	for(int i=G[k].size()-1;i>=0;i--)
		dfs( G[k][i] );
	memset(dp,0x3f,sizeof(dp));
	int x=1;dp[x][0]=0;
	for(int i=G[k].size()-1;i>=0;i--){
		int u=G[k][i];
		x^=1;
		memset(dp[x],0x3f,sizeof(dp[x]));
		for(int j=w[k];j>=0;j--){
			if(j>=w[u]) dp[x][j]=min(dp[x][j],dp[y][j-w[u]]+f[u]);
			if(j>=f[u]) dp[x][j]=min(dp[x][j],dp[y][j-f[u]]+w[u]);
		}
	}
	f[k]=INF;
	for(int i=0;i<=w[k];i++)
		f[k]=min(f[k],dp[x][i]);
}
int main()
{
	int n;cin>>n;
	for(int a,i=2;i<=n;i++){
		scanf("%d",&a);
		G[a].push_back(i);
	}
	for(int i=1;i<=n;i++)	scanf("%d",&w[i]);
	dfs(1); 
	if(f[1]<INF)	cout<<"POSSIBLE";
	else cout<<"IMPOSSIBLE";
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001001001001
#define mod 1000000007
#define mod2 998244353
#define pi acos(-1)
#define all(v) v.begin(),v.end()

int main(){
    string a,b;cin>>a>>b;
    string str="";
    bool flag=false;
    str+=a;
    str+=b;
    int num=stoi(str);
    for(int i=1;i*i<=num;i++){
        if(i*i==num){
            flag=true;
            break;
        }else{
            continue;
        }
    }
    if(flag){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
int main(){
    int H,W,A,B;
    cin >>H>>W>>A>>B;
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            if((i<B&&j<A)||(i>=B&&j>=A)){
                cout<<1;
            }
            if((i<B&&j>=A)||(i>=B&&j<A)){
                cout<<0;
            }
            if(j==W-1){
                cout<<endl;
            }
        }
    }
    
}

Measured memory_bytes: 1280
def DFS(graph,root,parent):
  dist = [-1]*(n+1)
  dist[root] = 0
  stack = [root]
  while stack:
    x = stack.pop()
    for y in graph[x]:
      if dist[y] == -1:
        parent[y] = x
        dist[y] = dist[x]+1
        stack.append(y)
  return dist

#親のリスト、頂点v、kが与えられたときに「vのk個上の祖先」を見る
class Doubling:
  def __init__(self,graph,root):
    self.root = root
    n = len(graph)-1
    self.ancestor_ls = [[0]*(n+1)]
    self.distance = DFS(graph,root,self.ancestor_ls[0])
    self.bitn = n.bit_length()
    for i in range(1,self.bitn+1):
      ancestor_ls_app = [0]*(n+1)
      for j in range(1,n+1):
        ancestor_ls_app[j] = self.ancestor_ls[i-1][self.ancestor_ls[i-1][j]]
      self.ancestor_ls.append(ancestor_ls_app)
  
  def dist(self):
    return self.distance
  
  def parent(self):
    return self.ancestor_ls[0]

  def ancestor(self,v,depth):
    if depth == 0:
      return v
    if n<depth:
      return self.root
    ret = v
    for i in range(self.bitn):
      if depth&1<<i:
        ret = self.ancestor_ls[i][ret]
    return ret
  
  def LCA(self,u,v):
    if self.distance[u]<self.distance[v]:
      u,v = v,u
    dif = self.distance[u]-self.distance[v]
    w = self.ancestor(u,dif)
    if w == v:
      return v
    for i in range(self.bitn,-1,-1):
      if self.ancestor_ls[i][w] != self.ancestor_ls[i][v]:
        w,v = self.ancestor_ls[i][w],self.ancestor_ls[i][v]
    return self.ancestor_ls[0][v]

import sys
input = sys.stdin.readline
n = int(input())
ab = [list(map(int,input().split())) for i in range(n-1)]
graph = [[] for i in range(n+1)]
for a,b in ab:
  graph[a].append(b)
  graph[b].append(a)

sol = Doubling(graph,1)
pls = sol.parent()

m = int(input())
cons = [0 for i in range(m)]
for i in range(m):
  u,v = map(int,input().split())
  lca = sol.LCA(u,v)
  while u != lca:
    cons[i] |= 1<<u
    u = pls[u]
  while v != lca:
    cons[i] |= 1<<v
    v = pls[v]
ans = 0
for i in range(2**m):
  x = 0
  for j in range(m):
    if i & 1<<j:
      x |= cons[j]
  bcnt = 0
  for j in range(n+1):
    if x & 1<<j:
      bcnt += 1
  if bin(i).count("1")%2 == 1:
    ans -= 2**(n-1-bcnt)
  else:
    ans += 2**(n-1-bcnt)
print(ans)

Measured memory_bytes: 42220
#include <stdio.h>
int gcd(int,int);
int main(){
  int a,b;
  scanf("%d %d", &a,&b);
  printf("%d\n" ,gcd(a,b));
  return 0;
}

int gcd(int x, int y){
  int r,d;
  if(x<y){
    d=x;
    x=y;
    y=d;
  }

    while(y!=0){
      r=x%y;
      x=y;
      y=r;
    }
      return x;

}


Measured memory_bytes: 2128
#include<bits/stdc++.h>
#define ll long long
#define F(type, i, a, b) for(type i = a; i <= b; i ++)
#define RF(type, i, a, b) for(type i = a; i >= b;i --)
#define sz(a) sizeof(a)
#define deb(a) cerr<<" ["<<#a<<"->"<<a<<"] "
#define next_line cerr<<'\n'
#define all(a) a.begin(), a.end()
#define iter(it, s) for(auto it = s.begin(); it != s.end(); it ++)

using namespace std;

typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

ll n, arr[21][21], mod = 1e9 + 7;
//Whenever a subset is a variable then we can represent it
//through masks(basically its a number whose set bits shows selected numbers)
//It helps to represent a subset of a set.
//As of here though it depends on where we start in the array
//it also depends on the womens already selected i.e 
//the set of women already selected , which could be easily represented
//by a mask(instead of a boolean array) as N is too small (i.e 21)
ll NumberOfways(ll st, ll mask, vector<vector<ll> > &dp){
    if(st == n)
        return 1LL;
    if(dp[st][mask] != -1)
        return dp[st][mask];
    ll count = 0LL;
    F(ll, i, 0, n - 1){
        if((arr[st][i]) && (!(mask & (1 << i)))){ 
            count += NumberOfways(st + 1, mask | (1 << i), dp);
            count %= mod;
        }
    }
    dp[st][mask] = count;
    return count;
}

void solve()
{
    cin>>n;
    F(ll, i, 0, n - 1){
        F(ll, j, 0, n - 1){
            cin>>arr[i][j];
        }
    }
    vector<vector<ll> > dp(n, vector<ll>(1 << n, -1));
    cout<<NumberOfways(0, 0, dp);
}

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    #ifndef ONLINE_JUDGE
        // freopen("input.txt", "r", stdin);
        // freopen("output.txt", "w", stdout);
        // freopen("Debug.txt", "w", stderr);
    #else
    #endif
    solve();
}


Measured memory_bytes: 363736
#include <string.h>
#include <stdio.h>
#include <iostream>
#include <string>
#include <cstring>
#include <math.h>
#include <set>
#include <vector>
#include <algorithm>
#include <map>


using namespace std;

typedef long long ll;
const double PI = acos(-1.0);
#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))

int a[205] = {0};

int main(){
    ios::sync_with_stdio(false);
    int n, i, j, ans;
    for(i = 1; i <= 200; i++)
        for(j = 1; j <= i; j++)
            if(i%j==0)
                a[i]++;

    while(scanf("%d", &n)!=EOF){
        ans = 0;
        for(i = 1; i <= n; i++)
            if(a[i] == 8 && i % 2)
                ans++;

        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 256
/*
	X is a child of Y.@XÌeð²×Ä­B
	X is the parent of Y.@YÌeð²×Ä­
	X is a sibling of Y. XÆYÌ[³ª¯¶©mF·é
	X is a descendant of Y. XÌeðÄAIÉ
	X is an ancestor of Y.@YÌeðÄAIÉ
*/
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cstdio>
#include <sstream>
#include <set>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)

map<string,string> data;
map<string,int> dp;

vector< pair<string,int> > rec;

int n,m,I,back;

void input(string parent,int depth){
	while( I < n ){
		string nstr = rec[I].first;
		int ndp = rec[I].second;
		data[nstr] = parent;
		dp[nstr] = depth;
		I++;
		if(depth < ndp){
			input(nstr,ndp);
			if(back){
				back--;
				return;
			}
		}else if(depth > ndp){
			back = depth-ndp-1;
			return;
		}
	}
}

bool func(string a,string b){
	if(a == "")return false;
	return a==b ? true : func(data[a],b);
}

int main(){
	string s;
	while(scanf("%d %d\n",&n,&m) , n){
		int prevCount=0,tmpCount;
		vector< pair<string,int> > in(n,make_pair("",-1));
		data.clear();dp.clear();
		
		for(int i=0;i<n;i++){
			getline(cin,s);
			if(i){
				in[i-1].second = count(s.begin(),s.end(),' ');
			}
			s.erase(remove(s.begin(),s.end(),' '),s.end());
			in[i].first = s;
		}
		rec=in;
		I = back = 	0;
		input("",0);
		
		bool flag;
		for(int i=0;i<m;i++){
			vector<string> tmp;
			getline(cin,s);
			s = s.substr(0,s.length()-1);
			stringstream ss(s);	
			while(ss >> s)tmp.push_back(s);
			string X = tmp[0], Y = tmp[5] , type = tmp[3];
		
		
			if(type == "child")flag = (data[X] == Y);
			if(type == "parent")flag = (data[Y] == X);
			if(type == "sibling")flag = (data[X] == data[Y]);
			if(type == "descendant")flag = (func(X,Y)) ;
			if(type == "ancestor")flag = (func(Y,X)) ;
			
			cout << (flag?"True":"False") << endl;
		}
		cout << endl;
	}
}

Measured memory_bytes: 1076
N = int(input())

for l in range(N):
    outCount = 0
    score = 0
    bases = 0
    while True:
        action = input()
        if action == "HIT":
            if bases == 3:
                score += 1
            else:
                bases += 1
        elif action == "HOMERUN":
            score += bases + 1
            bases = 0
        elif action == "OUT":
            outCount += 1

        if outCount == 3:
            print(score)
            break




Measured memory_bytes: 5592
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define inf 1001001001
using namespace std;
using ll = long long;
using P = pair<int,int>;
int main(void) {
    string s; cin >> s;
    int sz = s.size();
    int head = 2, tail = sz-2;
    bool ok = true;
    int cnt = 0;
    rep(i, sz) {
        if(0<=s[i]-'a' && s[i]-'a'<=25) cnt++;
    }
    if(cnt != sz-2) ok = false;
    if(s[0]!='A') ok = false;
    bool judge = false;
    for(int i=head; i<=tail; i++) {
        if(s[i] == 'C') judge = true;
    }
    if(!judge) ok = false;
    if(ok) cout << "AC";
    else cout << "WA";
}


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

using namespace std;

int selection_sort(vector<int> &vec){
    int x = 0;
    for(int i=0; i<vec.size(); i++){
        int minj = i;
        for(int j=i; j<vec.size(); j++){
            if(vec[j] < vec[minj])
                minj = j;
        }
        if(minj != i)
            x++;
        swap(vec[minj], vec[i]);
    }
    return x;
}

int main(){
    int N; cin >> N;
    
    vector<int> vec(N);
    for(auto &v: vec)
        cin >> v;
    
    int x = selection_sort(vec);
    
    for(int i=0; i<N; i++)
        cout << vec[i] << (i==N-1? "\n": " ");
    cout << x << endl;
    
    return 0;
}



Measured memory_bytes: 3096
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <cmath>

using namespace std;
#define PI 3.1415926535897932384626433832795
#define MOD (1000000007)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
#define swap(a, b, type) { type _tmp = a; a = b; b = _tmp; }
typedef long long ll;
typedef unsigned long long ull;

int main()
{
	int N;
	ll ans = 1;

	cin >> N;
	repc(i, 1, N) ans = (ans * i) % MOD;
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
//#define local
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define rep(i,n); for(long long i = 0;i < (n);i++)
using ll = long long;
using P = pair<long long,long long>;
template <class T> using vec = vector<T>;
#ifdef local
#include "debug.cpp"
#else
#define debug(...)
#endif

map<ll,ll>prime_factor(ll n){
    map<ll,ll> ret;
    for(ll i=2;i*i<=n;i++){
        while(n%i==0){
            ret[i]++;
            n/=i;
        }
    }
    if(n!=1)ret[n]=1;
    return ret;
}

ll gcd(ll a,ll b){return b == 0 ? a : gcd(b,a%b);}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    //cout << fixed << setprecision(10);
    ll n; cin >> n;
    vec<ll> a(n); rep(i,n)cin >> a[i];
    set<ll> s;
    bool pr = true;
    rep(i,n){
        for(auto p : prime_factor(a[i])){
            if(s.count(p.first)){
                pr = false;
                break;
            }
            s.insert(p.first);
        }
        if(!pr)break;
    }
    if(pr){
        cout << "pairwise coprime" << endl;
        return 0;
    }
    ll g = a[0];
    rep(i,n)g = gcd(g,a[i]);
    cout << (g == 1 ? "setwise coprime" : "not coprime") << endl;
}

Measured memory_bytes: 11100
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a[3],k;
	cin>>a[0]>>a[1]>>a[2]>>k;
	sort(a,a+3);
	for(int i=0;i<k;i++){
		a[2]*=2;
	}
	cout<<a[0]+a[1]+a[2]<<endl;
}


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

int main(void){
  int N,K;
  cin >> N >> K;
  int V[N];
  rep(i,N)cin >> V[i];
  //cout << N << endl;
  //rep(i,N)cout << V[i]<<endl;

  
  priority_queue<int,vector<int>,greater<int>> que;
  int ans=0;
  int p,q,r;
  int sum;
  
  for(p=0;p<=min(K,N);p++){
  	for(q=0;q<=min(K-p,N-p);q++){
       sum = 0;
      rep(i,p+1){
        if(i>0){que.push(V[i-1]);
      	sum+=V[i-1];
      	//cout << V[i-1] <<" ";
        }
      }
      rep(j,q+1){
       	 if(j>0){
       	    que.push(V[N-j]);
            sum+=V[N-j];
        //    cout << V[N-j] << " " ;
       	 }
      }
     
     //cout << sum << endl;
      ans = max(ans,sum);
    for(r=1;r<=min(K-p-q,p+q);r++){
            if(!que.empty()){
                if(que.top()>0)break;
                //cout << que.top() << " ";
                sum -=que.top();
                que.pop();
                ans = max(ans,sum);
            }
    }
    //cout << endl;
     while(!que.empty()){
        que.pop();
     }
    } 
  }
	cout << ans << endl;
  
  
}

Measured memory_bytes: 256
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]


def main():
    n,m=map(int,input().split())
    l=[list(map(int,input().split())) for _ in range(m)]
    l.reverse()
    res = [(n*(n-1))//2]
    u = UnionFind(n)
    for sl in l:
        a = sl[0]-1
        b = sl[1]-1
        if u.find(a) == u.find(b):
            res.append(res[-1])
        else:
            res.append(res[-1] - u.size(a) * u.size(b))
            u.union(a,b)
    res.pop()
    res.reverse()
    print("\n".join(map(str,res)))
main()

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

#define MAX 100002

map<int,int> mp[2];
vector<pair<int,int> > v[2];
int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		int a;
		scanf("%d",&a);
		mp[i&1][a]++;
	}
	mp[0][-1]=0;
	mp[1][-1]=0;
	mp[0][-2]=0;
	mp[1][-2]=0;
	for(int i=0;i<2;i++){
		for(auto it:mp[i]){
			v[i].push_back(make_pair(it.second,it.first));
		}
		sort(v[i].begin(),v[i].end());
		reverse(v[i].begin(),v[i].end());
	}
	int sum=0;
	for(int i=0;i<3;i++){
		for(int j=0;j<3;j++){
			if(v[0][i].second==v[1][j].second)continue;
			sum=max(sum,v[0][i].first+v[1][j].first);
		}
	}
	cout<<n-sum<<endl;
	return 0;
}


Measured memory_bytes: 6136
# import itertools
# import math


def solve(A, B, C):
    ans = A - B - C
    if ans < 0:
        ans = abs(ans)
    else:
        ans = 0
    return ans


# N = int(input())
# S = input()
A, B, C = map(int, input().split())
# A = list(map(int, input().split()))

# P = []
# S = []
# for i in range(N):
#     pp, ss  = map(int, input().split())
#     P.append(pp)
#     S.append(ss)

print(solve(A, B, C))


Measured memory_bytes: 2940
#include<iostream>
#include<vector>
#include<stack>
using namespace std;
static const int MAX=1000000;
static const int NIL=-1;
int n;
vector<int>G[MAX];//頂点数を1000000
                  //隣接セット
int color[MAX];

void dfs(int r,int c){
  stack<int>S;
  S.push(r);//始点rをスタックに追加
  color[r]=c; //色を入れる
  while(!S.empty()){ //スタックが空でない場合
    int u=S.top();
    S.pop(); //スタックからuを取り出し訪問
    for(int i=0;i<G[u].size();++i){
      //頂点uに隣接する頂点vを探索
      int v=G[u][i];
      if(color[v]==NIL){
	color[v]=c;
	S.push(v); //id(色)はかわらない
      }
    }
  }
}

int main(){
  int s,t,m,q;
  cin>>n>>m;
  for(int i=0;i<m;++i){
    cin>>s>>t;
    G[s].push_back(t); //ｓからｔへ辺
    G[t].push_back(s); //t→s
  }
  int id=1; //colorに入れる色
  for(int i=0;i<n;++i){
    color[i]=NIL; //すべてにNIL
  }
  for(int u=0;u<n;++u){
    if(color[u]==NIL) dfs(u,id++);
  }
  cin>>q;
  for(int i=0;i<q;++i){
    cin>>s>>t;
    if(color[s]==color[t]) cout<<"yes"<<endl;
    else cout<<"no"<<endl;
  }
  return 0;
}



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

#define lli long long int
#define REP(i,s,l) for(lli i=s;i<l;i++)
#define DEBUG 0
#define INF (1LL<<50)
#define MOD 1000000007

int main(){
    lli a, b, tmp;
    cin >> a >> b;

    lli x = a * b;
    if(a<b){
        tmp = a;
        a = b;
        b = tmp;
    }
    lli r = a % b;
    while(r!=0){
        a = b;
        b = r;
        r = a % b;
    }
    cout << x/b << endl;
    return 0;
}

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

int main(){
  string s;
  cin >> s;
  if(s == "MON") cout << 6 << endl;
  else if(s == "TUE") cout << 5 << endl;
  else if(s == "WED") cout << 4 << endl;
  else if(s == "THU") cout << 3 << endl;
  else if(s == "FRI") cout << 2 << endl;
  else if(s == "SAT") cout << 1 << endl;
  else if(s == "SUN") cout << 7 << endl;
}

Measured memory_bytes: 256
import sys
  
for s in sys.stdin:
    if '?' in s:
        break
    else:
        a_str,op,b_str = s.split()
        a,b = int(a_str),int(b_str)

        if op == '+':
            print(a + b)
        elif op == '-':
            print(a - b)
        elif op == '/':
            print(a //  b)
        elif op == '*':
            print(a * b)


Measured memory_bytes: 5600
def f():
    return int(raw_input())
def f2():
    return map(int, raw_input().split())

def merge(left, mid, right):
    L = S[left:mid]
    R = S[mid:right]
    lp, rp, xp = 0, 0, 0
    a, b = L[0], R[0]
    c = right - left
    x = [0] * c
    flg = True
    while flg:
        while flg and a <= b:
            x[xp] = a
            lp += 1
            xp += 1
            try:
                a = L[lp]
            except:
                for e in R[rp:]:
                    x[xp] = e
                    xp += 1
                flg = False
        while flg and a >= b:
            x[xp] = b
            rp += 1
            xp += 1
            try:
                b = R[rp]
            except:
                for e in L[lp:]:
                    x[xp] = e
                    xp += 1
                flg = False
    S[left:right] = x
    return c

def mergesort(left, right):
    c = 0
    if left + 1 < right:
        mid = (left + right)/2
        c += mergesort(left, mid)
        c += mergesort(mid, right)
        c += merge(left, mid, right)
    return c

global S
n = f()
S = f2()

c = mergesort(0, n)
print " ".join(map(str,S))
print c

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

#define ll long long
using namespace std;

int main()
{
	int h, w, x, y;
	cin >> h >> w >> x >> y;
	if (h % x == 0 && w % y == 0)cout << "No" << endl;
	else
	{
		cout << "Yes" << endl;

		for (int i = 0; i < h; i++)
		{
			for (int j = 0; j < w; j++)
			{
				if (j > 0)cout << " ";
				cout << ((i+1) % x == 0 && (j+1) % y == 0 ? -(x * y - 1) * 1000 - 1 : 1000);
			}
			cout << endl;
		}
	}
	return 0;
}


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

const int maxn = 2e5 + 5;
char str[maxn];
int dp[maxn][2], n;

int main(){
	scanf("%s",str+1);
	n = std::strlen(str+1);
	dp[0][0] = dp[0][1] = 0;
	for(int i=1;i<=n;i++){
		if(i >= 1 && str[i] != str[i-1]) dp[i][0] = std::max(dp[i][0], 1+dp[i-1][0]);
		if(i >= 1)dp[i][0] = std::max(dp[i][0], 1+dp[i-1][1]);
		if(i >= 3 && (str[i] != str[i-2] || str[i-1] != str[i-3])) dp[i][1] = std::max(dp[i][1],dp[i-2][1] + 1);
		if(i >= 2) dp[i][1] = std::max(dp[i-2][0] + 1,dp[i][1]);
	}
	printf("%d",std::max(dp[n][0],dp[n][1]));
	return 0;
}

Measured memory_bytes: 2048
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <math.h>

using namespace std;

int main(){
    while(1){
    int n=0;
    cin >> n;
    if(n==0)return 0;
    int score[n];
    int memory=0; 
    int min=100000000;
    for(int i=0; i<n; i++)cin >> score[i];
    for(int i=0; i<n; i++){
        for(int j = i+1; j<n; j++){
            memory = score[i]-score[j];
            if(memory < 0) memory *= -1;
            if(memory < min)min = memory;
        }
    }
        cout << min << endl;
    }
}


Measured memory_bytes: 3064
#include <algorithm>
#include <array>
#include <cassert>
#include <iostream>
#include <vector>
using namespace std;

template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }
template<typename T, size_t size> ostream& operator<<(ostream &os, const array<T, size> &arr) { os << '{'; string sep; for (const auto &x : arr) os << sep << x, sep = ", "; return os << '}'; }
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }

void dbg_out() { cerr << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }

#ifdef NEAL_DEBUG
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif


int main() {
    ios::sync_with_stdio(false);
#ifndef NEAL_DEBUG
    cin.tie(nullptr);
#endif

    int N, W;
    cin >> N >> W;
    vector<int64_t> dp(W + 1, 0);

    for (int i = 0; i < N; i++) {
        int w, v;
        cin >> w >> v;

        for (int x = W - w; x >= 0; x--)
            dp[x + w] = max(dp[x + w], dp[x] + v);
    }

    cout << *max_element(dp.begin(), dp.end()) << '\n';
}


Measured memory_bytes: 1024