akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
using namespace std;

int main()
{
    for(;;){
        int n;
        cin >> n;
        if(n == 0)
            return 0;

        vector<double> px(n), py(n), pz(n), vx(n), vy(n), vz(n), r(n), vr(n);
        for(int i=0; i<n; ++i)
            cin >> px[i] >> py[i] >> pz[i] >> vx[i] >> vy[i] >> vz[i] >> r[i] >> vr[i];

        multimap<double, pair<int, int> > mm;
        for(int i=0; i<n; ++i)
            mm.insert(make_pair(r[i] / vr[i], make_pair(i, i)));
        for(int i=0; i<n; ++i){
            for(int j=i+1; j<n; ++j){
                double a = pow(vx[i] - vx[j], 2) +
                           pow(vy[i] - vy[j], 2) +
                           pow(vz[i] - vz[j], 2) -
                           pow(vr[i] + vr[j], 2);
                double b = ((vx[i] - vx[j]) * (px[i] - px[j]) +
                            (vy[i] - vy[j]) * (py[i] - py[j]) +
                            (vz[i] - vz[j]) * (pz[i] - pz[j]) +
                            (vr[i] + vr[j]) * ( r[i] +  r[j])) * 2;
                double c = pow(px[i] - px[j], 2) +
                           pow(py[i] - py[j], 2) +
                           pow(pz[i] - pz[j], 2) -
                           pow( r[i] +  r[j], 2);

                double d = b * b - 4 * a * c;
                if(d < 0)
                    continue;

                double t1 = (- b - sqrt(d)) / (2 * a);
                double t2 = (- b + sqrt(d)) / (2 * a);
                if(t1 > 0)
                    mm.insert(make_pair(t1, make_pair(i, j)));
                if(t2 > 0)
                    mm.insert(make_pair(t2, make_pair(i, j)));
            }
        }

        vector<bool> check(n, false);
        vector<double> ans(n);
        for(const auto& p : mm){
            int i = p.second.first;
            int j = p.second.second;
            if(!check[i] && !check[j]){
                check[i] = check[j] = true;
                ans[i] = ans[j] = p.first;
            }
        }

        for(int i=0; i<n; ++i)
            printf("%.10f\n", ans[i]);
    }
}

Measured memory_bytes: 2752
package main

import "fmt"

func main() {
	var N int
	fmt.Scan(&N)
	V := make([]int, 0, N)
	C := make([]int, 0, N)
	var input int
	for i := 0; i < N; i++ {
		fmt.Scan(&input)
		V = append(V, input)
	}
	for i := 0; i < N; i++ {
		fmt.Scan(&input)
		C = append(C, input)
	}
	for i := 0; i < N; i++ {
		V[i] = V[i] - C[i]
	}
	value := 0
	for _, v := range V {
		if v > 0 {
			value += v
		}
	}
	fmt.Println(value)

}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using ll = long long;
using namespace std;
int main()
{
	int n;
	ll k;
	cin >> n >> k;
	vector<int> a(n);
	rep(i, n) {
		cin >> a[i]; a[i]--;
	}
	vector<pair<int, int>> city(n, pair<int, int>(0, 0));
	vector<int> history, history_mod;
	int cur = 0;
	int ans = 0;
	for (cur = 0; cur < k; ++cur) {
		if (city[ans].second == 0) {
			city[ans].first = cur;
			city[ans].second++;
		}
		else {
			history_mod.resize(history.size() - city[ans].first);
			copy(history.begin() + city[ans].first, history.end(), history_mod.begin());
			ans = a[ans];
			break;
		}
		history.emplace_back(ans);
		ans = a[ans];
	}
	ll res = k - cur;
	if (res != 0) {
		res %= history_mod.size();
		ans = history_mod[res];
	}
	cout << ans + 1 << endl;
	return 0;
}

Measured memory_bytes: 6192
def input_int():
    return map(int, input().split())

def one_int():
    return int(input())

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))

N=one_int()

alpha =list("abcdefghij")

def dfs(string, counter, N):
    if N==counter:
        lists.append(string)
        return 
    
    for i in range(counter):
        if i==0:
            dfs(string + alpha[i], counter+1, N)
        elif alpha[i-1] in string:
            dfs(string + alpha[i], counter+1, N)

lists = []

dfs("a", 2, N+1)

for i in sorted(lists):
    print(i)

Measured memory_bytes: 13568
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
int a, b, c;

int main() {
	while(~scanf("%d %d %d", &a, &b, &c)) {
		if(b >= c - a && c >= a) puts("YES");
		else puts("NO");
	}
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define wfile freopen("output.txt", "w", stdout)
#define rfile freopen("input.txt", "r", stdin)
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
void enable_io(){
    #ifdef LOCAL_PROJECT
        wfile;
        rfile;
    #endif
}
int exp(int x, int n)
{
    ll ans = 1;
    while(n > 0){
        if(n & 1){
            ans = (ans * (ll)x)%2019;
        }
        n >>= 1;
        x = (x*(ll)x)%2019;
    }
    return ans;
}
int main(int argc, char const *argv[])
{   
    fastio;
    enable_io();
    int T = 1;
    //cin >> T;
    for(int t = 0; t < T; t++){
        string s;
        cin >> s;
        int n = s.length();
        vector<int> pref(n+1,0);
        map<int,int> mx;
        mx[0]++;
        pref[n] = 0;
        for(int i = n-1; i >= 0; i--){
            pref[i] = (pref[i+1] + ((ll)(s[i] - '0')*exp(10,n-1-i))%2019)%2019;    
        }
        ll ans = 0;
        for(int i = n-1; i >= 0; i--){
            ans += mx[pref[i]];
            mx[pref[i]]++;
        }
        cout << ans << endl; 
        //cout << 181718171%2019 << endl;   
    }
    return 0;
}


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

int main() {
  int i;
  string s, t;
  
  cin >> s >> t;

  for(i = 0; s[i] == t[i]; i++);
  if(s[i] == t[i+1] && i == s.length())
    printf("Yes\n");
  else
    printf("No\n");

  return 0;
}


Measured memory_bytes: 3620
#include <iostream>
#include <string>

using namespace std;

int main(){
  int H,W;
  cin >> H >> W;
  char a[H][W];
  char b[H][W];
  char c[H][W];
  int i,j,k,l;
  int h_flag= 0,w_flag= 0;
  l=0;
  for(i = 0; i < H; i++){
    for(j = 0;j < W;j++){
      cin >> a[i][j];
      if(a[i][j] == '#') w_flag= 1;
    }
    if(w_flag){
      for(k = 0;k < W;k++){
        b[l][k] = a[i][k];
      }
      l++;
    }
    w_flag = 0;
  }
  l = 0;
  for(i = 0; i < sizeof(b[0])/sizeof(b[0][0]); i++){
    for(j = 0; j < sizeof(b)/sizeof(b[0]);j++){
      if(b[j][i] == '#') h_flag = 1;
    }
    if(h_flag){
      for(k = 0;k < sizeof(b)/sizeof(b[0]);k++){
        c[k][l] = b[k][i];
      }
      l++;
    }
    h_flag = 0;
  }

  for(i = 0;i < sizeof(c)/sizeof(c[0]);i++){
    for(j = 0;j < sizeof(c[0])/sizeof(c[0][0]); j++){
      if(c[i][j] == '.' || c[i][j] == '#'){
        cout << c[i][j];
      }
    }
    cout << endl;
  }

  return 0;

}


Measured memory_bytes: 256
package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	wfp := os.Stdout

	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)

	n := getNextInt(scanner)
	q := getNextInt(scanner)

	nodes := make([]Node, n)
	for i := 0; i < n; i++ {
		nodes[i].p = i
	}
	for i := 0; i < q; i++ {
		t := getNextInt(scanner)
		x := getNextInt(scanner)
		y := getNextInt(scanner)

		rx := root(x, nodes)
		ry := root(y, nodes)

		if t == 1 {
			if rx != ry {
				fmt.Fprintln(writer, "?")
				continue
			}
			fmt.Fprintln(writer, nodes[x].d-nodes[y].d)
			continue
		}

		z := getNextInt(scanner)

		nodes[rx].d = z + nodes[y].d - nodes[x].d
		nodes[rx].p = ry
	}

	writer.Flush()
}
func root(i int, nodes []Node) int {
	if i == nodes[i].p {
		return i
	}
	p := root(nodes[i].p, nodes)
	nodes[i].d += nodes[nodes[i].p].d
	nodes[i].p = p

	return p
}

type Node struct {
	p, d int
}



Measured memory_bytes: 11996
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = Integer.parseInt(sc.nextLine());
		String s = sc.nextLine();
		sc.close();
		if(a >= 3200){
			System.out.println(s);
		}else{
			System.out.println("red");
		}
	}
}

Measured memory_bytes: 21716
#include "bits/stdc++.h"

#define REP(i,num) for(int i=0;i<(num);++i)
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	map<char,int> M;
	M['I'] = 1;
	M['V'] = 5;
	M['X'] = 10;
	M['L'] = 50;
	M['C'] = 100;
	M['D'] = 500;
	M['M'] = 1000;

	string S;
	while(cin>>S){
		int sum = 0;
		int N=S.size();
		
		for(int i=0;i<N;){
			if(i<N-1 && M[S[i]]<M[S[i+1]]){
				sum += M[S[i+1]]-M[S[i]];
				i+=2;
			}
			else{
				sum += M[S[i]];
				i++;
			}
		}
		out(sum);
	}
	return 0;
}


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

string s[200];
int n, m;

int main(){
	cin>>n>>m;
	
	for(int i=1; i<=n; i++){
		cin>>s[i];
		s[i]="#"+s[i]+"#";
	}
	
	for(int i=0; i<=n+1; i++){
		if(i==0||i==n+1){
			for(int j=0; j<=m+1; j++) cout<<"#";
			cout<<endl;
		}
		else cout<<s[i]<<endl;
	}
}


Measured memory_bytes: 3604
// https://atcoder.jp/contests/abc150/tasks/abc150_d
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define CEIL(a, b) ((a - 1) / b + 1)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int c, int d) { return c / gcd(c, d) * d; }

// 解説
// https://www.hamayanhamayan.com/entry/2020/01/11/145024
void solve() {
    int N, M;
    cin >> N >> M;
    vector<int> A(N);
    REP(i, N) { cin >> A[i]; }
    int t = A[0];
    REP(i, N) { t = lcm(t, A[i]); }
    // 最小公倍数が奇数倍になっていることを確認
    // OK: lcm(6, 10) = 30で、30/6=5, 30/10=3
    // NG: lcm(6, 15) = 30で、30/15=2は偶数倍
    REP(i, N) {
        if ((t / A[i]) % 2 == 0) {
            cout << "0\n";
            return;
        }
    }
    cout << (M + t / 2) / t << endl;
}

signed main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    solve();
}


Measured memory_bytes: 3988
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<math.h>
#include<bitset>
#include <numeric>
using namespace std;
using ll=long long;
using ld=long double;
using pint=pair<int,int>;
using pll=pair<ll,ll>;
#define LONG_INF 9223372036854775807
#define INF 1000000000LL
#define EPS 1e-10
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define dump(a) rep(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define all(v) v.begin(),v.end()
#define pb push_back


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

    string S, T;
    cin >> S >> T;
    int N = (int)(S.length());
    int ret=0;
    rep(i, N){
        if(S[i]!=T[i]) ret++;
    }
    cout << ret << endl;

    return 0;
}

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

#define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long int



int main()
{
    FASTIO;
    int n,m;
    cin>>n>>m;

    vector<list<int>> graph(n);
    vector<int> indegree(n,0);

    for(int i = 0;i<m;i++)
    {
        int u,v;
        cin>>u>>v;

        u--;v--;
        graph[u].push_back(v);
        indegree[v]++;
    } 

    vector<bool> visited(n,false);
    queue<int> q;

    for(int i = 0;i<n;i++)
    {
        if(indegree[i]==0)
        {
            q.push(i);
        }
    }

    int ans = 0;

    while(!q.empty())
    {
        ans++;

        int cur_size = q.size();

        for(int j = 0;j<cur_size;j++)
        {
            int cur = q.front();
            q.pop();
            for(int ele : graph[cur])
            {
                indegree[ele]--;
                if(indegree[ele]==0)
                {
                    q.push(ele);
                }
            }
        }
    }

    // as ans is node of node and we want edges
    cout<<ans-1; 

}

Measured memory_bytes: 5504
#include<iostream>
#include<math.h>
#include<algorithm>
#define ll long long int
#define FOR(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define REP(i,n) FOR(i,0,n)
#define REP1(i,n) FOR(i,1,n)

using namespace std;

int main(){
	int n, k;
    cin >> n >> k;
    if(k*2-1 <= n) cout << "YES" << endl;
    else cout << "NO" << endl;
	return 0;
}


Measured memory_bytes: 256
A, B = map( int, input().split())
A -= 1
TA = [0]*41
TB = [0]*41
if A%4 == 1 or A%4 == 2:
    TA[0] = 1
if B%4 == 1 or B%4 == 2:
    TB[0] = 1
for i in range(40,0,-1):
    if 2**i <= A:
        TA[i] = (A - 2**i +1)%2
        A -= 2**i
    if 2**i <= B:
        TB[i] = (B - 2**i + 1)%2
        B -= 2**i
a = 0
b = 0
for i in range(41):
    a += TA[i]*(2**i)
    b += TB[i]*(2**i)
print(a^b)


Measured memory_bytes: 3188
//Compiler optimization
#pragma GCC optimize("Ofast")

//include
#include <bits/stdc++.h>
using namespace std;

//typedef
typedef long long ll;
typedef double db;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef string S;
typedef queue<int> qi;
typedef pair<ll,ll> P;
typedef vector<P> vp;
typedef vector<vl> mat;

//macro
#define reverse(a) reverse(a.begin(),a.end())
#define unique(a) a.erase(unique(a.begin(),a.end()),a.end())
#define fr(i,n)for(ll i=0;i<(n);i++)
#define ifr(i,n)for(ll i=(n)-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define each(x, v) for (auto &x : v)

//abbreviation
#define pb push_back
#define elif else if
#define mp make_pair
#define endl '\n'

//debug
#define debug(x) cerr << #x << ": " << x << endl
#define v_debug(v) cerr << #v << endl;fr(i,v.size()) cerr << i << ": " << v[i] << endl

//const
const  ll INF = 1e18;


int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << setprecision(20);
    ll ans = 0;
    ll n;cin >> n;
    fr(i,n-1){
        ll u,v;cin >> u >> v;
        if(u>v)swap(u,v);
        ans -= u*(n-v+1);
    }
    fr(i,n)ans+=(i+1)*(n-i);
    cout << ans << endl;
}

Measured memory_bytes: 3640
import fractions
import itertools
n,x=map(int,input().split())
X=[int(i) for i in input().split()]
gcd_=[]
for i in X:
    gcd_.append(abs(i-x))
gcd_=list(itertools.accumulate(gcd_,fractions.gcd))

print(gcd_[-1])


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

// template {{{  0 
// using {{{ 1
using ll = long long int;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vii = vector<pii>;
using vll = vector<pll>;
// }}} 1
// definition {{{ 1
// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)
#define Scll(x) scanf("%lld", &x)
#define Scll2(x,y) scanf("%lld%lld", &x, &y)
#define Scll3(x,y,z) scanf("%lld%lld%lld", &x, &y, &z)
#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2
// constants {{{ 2
#define EPS (1e-7)
#define INF (2e9)
#define PI (acos(-1))
// }}} 2
// systems {{{ 2
#define Repe(x,y,z) for(ll x = z; x < y; x++)
#define Rep(x,y) Repe(x,y,0)
#define RRepe(x,y,z) for(ll x = y-z-1; x >= 0; x--)
#define RRep(x,y) RRepe(x,y,0)
// }}} 2
// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n")
#define YESNO(a) (a)?printf("YES\n"):printf("NO\n")
// }}} 2
// }}} 1
// input {{{ 1
// }}} 1
// }}} 0

int main() {

    int a,b,c,d;
    Scd2(a,b);
    Scd2(c,d);

    bool taka = true;
    while( a>0 && c>0 ){
        c -= b;
        if( c<=0 ) break;
        a -= d;
        if( a<=0 ) taka = false;
    }

    YesNo(taka);

    return 0;
}



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

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

typedef long long ll;
const ll MOD = 1e9 + 7;

int main() {
  int A, B;
  std::cin >> A >> B;
  if(A > 9 or B > 9) {
    std::cout << "-1" << '\n';
    return 0;
  } else {
    std::cout << A * B << '\n';
    return 0;
  }
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from itertools import accumulate #list(accumulate(A))

N, M = mi()
A = li2(N)

A.sort(key=lambda x:x[0])

ans = 0
i = 0
while M > 0:
    if M >= A[i][1]:
        ans += A[i][0] * A[i][1]
        M -= A[i][1]
        i += 1
    else:
        ans += A[i][0] * M
        break

print(ans)

Measured memory_bytes: 28956
alph = "abcdefghijklmnopqrstuvwxyz"
ans = [0] * 26
while True:
    s = input()
    t = s[-3:] if len(s) >= 3 else s

    for x in s.lower():
        if alph.find(x) >= 0:
            ans[alph.find(x)] += 1
            
    if t == "z" or t == '"""' or t == "nt." or t == "en.":
        break

for al, num in zip(alph, ans):
    print(f'{al} : {num}')


Measured memory_bytes: 5572
#include<iostream>
#include<algorithm>
#include<set>
#include<map>
using namespace std;
typedef long long Int;

Int a[108000];
Int n;
set<Int> checked;
map<Int, Int> ok;
Int go[108000];
Int need[108000];
Int sum[108000];
Int res;
int main(){
  cin >> n;
  for(Int i = 0;i < n;i++){
    cin >> a[i];
    ok[a[i]]++;
  }
  sort(a, a + n);
  for(Int i = 0;i < n;i++){
    if(i == 0)sum[i] = a[i];
    else sum[i] = a[i] + sum[i-1];
  }
  for(Int i = 0;i < n-1;i++){
    go[i] = (sum[i] * 2 >= a[i+1]);
    need[i] = sum[i] * 2 - a[i+1];
  }
  go[n-1] = true;

  for(Int i = n-2;i >= 0;i--){
    go[i] &= go[i+1];
  }
  for(Int i = 1;i < n;i++){
    need[i] = min(need[i], need[i-1]);
  }

  for(Int i = 0;i < n;i++){
    if(checked.count(a[i]))continue;
    checked.insert(a[i]);
    if(!go[i])continue;
    if(i == 0){
      res += ok[a[i]];
      continue;
    }
    if(need[i-1] + a[i] >= 0){
      res += ok[a[i]];
    }
  }
  
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 14336
#include <iostream>
#include <stack>
#include <algorithm>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <functional>
#include <string>
#include <cstdlib>
#include <numeric>
#include <cstdbool>
#include <cstring>
#include <map> 
#include<set>
#include<queue>
#include <iomanip>

typedef long long ll;

#define rep(i,n) for(ll i=0;i<n;i++)
using namespace std;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const long long INF = 1000000000000000;
const ll inf = -1e18;
typedef pair<ll, ll> P;
ll ma = 1000000000 + 7;
ll mx = 1000003;
ll h,n, w,m,t; string s;
ll R, C;
ll sy, sx, gy, gx;
char maze[20][20];
ll dis[20][20];
int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, 1, 0, -1 };
ll gcd(ll x, ll y) {
	if (x % y == 0) return y;
	return gcd(y, x % y);
}
ll lcm(ll a,ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
void comb(vector<vector <ll> >& v) {
	for (ll i = 0; i < v.size(); i++) {
		v[i][0] = 1;
		v[i][i] = 1;
	}
	for (ll k = 1; k < v.size(); k++) {
		for (int j = 1; j < k; j++) {
			v[k][j] = (v[k - 1][j - 1] + v[k - 1][j])%ma;
		}
	}
}

ll GetDigit(ll num) {
	return log10(num) + 1;
}
ll Combination(int n, int r)
{
	if (n - r < r) r = n - r;
	if (r == 0) return 1;
	if (r == 1) return n;

	vector<ll> numerator(r);
	vector<ll> denominator(r);

	for (int k = 0; k < r; k++)
	{
		numerator[k] = n - r + k + 1;
		denominator[k] = k + 1;
	}

	for (int p = 2; p <= r; p++)
	{
		int pivot = denominator[p - 1];
		if (pivot > 1)
		{
			int offset = (n - r) % p;
			for (int k = p - 1; k < r; k += p)
			{
				numerator[k - offset] /= pivot;
				denominator[k] /= pivot;
			}
		}
	}

	ll result = 1;
	for (int k = 0; k < r; k++)
	{
		if (numerator[k] > 1) result *= numerator[k];
		result %= ma;
	}

	return result;
}

ll bfs() {
	queue<P> que;
	for (int i = 0; i < R; i++) {
		for (int j = 0; j < C; j++) dis[i][j] = INF;
	}
	que.push(P(sy - 1, sx - 1));
	dis[sy - 1][sx - 1] = 0;

	while (que.size() > 0) {
		P p = que.front();
		que.pop();
		if (p.first == gy - 1 && p.second == gx - 1) break;
		for (ll i = 0; i < 4; i++) {
			ll ny = p.first + dy[i];
			ll nx = p.second + dx[i];
			if (0 <= ny && ny < R && 0 <= nx && nx < C && maze[ny][nx] == '.' && dis[ny][nx] == INF) {
				que.push(P(ny, nx));
				dis[ny][nx] = dis[p.first][p.second] + 1;
			}
		}
	}
	return dis[gy - 1][gx - 1];
}
ll dp[20500];
int main() {
	ll a, b;
	cin >> n >> a >> b;
	cin >> s;
	ll p = 0;
	ll q = 1;
	rep(i, n) {
		if (s[i] == 'a') {
			if (p < a + b) {
				++p;
				cout << "Yes" << endl;
			}
			else {
				cout << "No" << endl;
			}
		}
		else if (s[i] == 'b') {
			if (p < a + b && q <= b) {
				++p; ++q;
				cout << "Yes" << endl;
			}
			else {
				cout << "No" << endl;
			}
		}
		else {
			cout << "No" << endl;
		}
	}
}



Measured memory_bytes: 896
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>

using namespace std;
#define int long long int
const int INF = 1001001001001001LL;
const int MOD = 1000000007;

struct info{
    string l;
    int p,a,b,c,d,e,f,s,m;
    double n;
    double r,t;
    void k(){
        t = a+b+c + (d+e) * m;
        r = f*s*m-p;
        n = r / t;
    }
    bool operator<(const info & a)const{
        return n == a.n ? l < a.l : n > a.n;
    }
};

signed main(){
    

    while(1){
        int n; cin >> n;
        if(!n) break;

        vector<info> v(n);
        for(int i = 0; i < n; i++){
            cin >> v[i].l >> v[i].p >> v[i].a >> v[i].b >> v[i].c >> v[i].d >> v[i].e >> v[i].f >> v[i].s >> v[i].m;
            v[i].k();
        }

        sort(v.begin(), v.end());
        for(int i = 0; i < n; i++) cout << v[i].l << endl;
        cout << "#" << endl;
    }
    return 0;
}




Measured memory_bytes: 3244
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())

l = [a,b,c,d,e]
min_MOD = 9
min_ind = -1
for i in range(5):
    x = l[i]%10
    if x <= min_MOD and x != 0:
        min_ind = i
        min_MOD = x
#print(min_ind)
        
ans = 0
for i in range(5):
    if i == min_ind:
        ans += l[i]
    else:
        if l[i]%10 == 0:
            ans += l[i]
        else:
            ans += l[i]+10 - l[i]%10
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <string>
#include <cmath>
#include <set>

#define lowbit(x) (x&(-x))
#define MAX(a,b) (a<b?b:a)
#define MIN(a,b) (a<b?a:b)
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
const int N = 1e7;
const int maxn = 2e5 + 5;
ll mod = 1e9 + 7;

int n;
ll a[maxn], s[maxn];

ll tmp[4];
int main()
{
	scanf("%d", &n);
	for (int i = 1; i <= n; i++)
	{
		scanf("%lld", a + i);
		s[i] = s[i - 1] + a[i];
	}

	ll ans = 1e15;
	for (int i = 2; i < n - 1; i++)
	{
		int p1, p2;

		int l = 1, r = i - 1, mid;
		while (l < r)
		{
			mid = (l + r) / 2 + 1;
			if (s[mid] <= s[i] - s[mid]) l = mid;
			else r = mid - 1;
		}
		p1 = r;

		l = i + 1, r = n - 1;
		while (l < r)
		{
			mid = (l + r) / 2 + 1;
			if (s[mid] - s[i] <= s[n] - s[mid]) l = mid;
			else r = mid - 1;
		}
		p2 = r;

		ll maxv, minv;
		for (int j = p1; j <= p1 + 1; ++j)
		{
			for (int k = p2; k <= p2 + 1; ++k)
			{
				maxv = MAX(s[j], s[i] - s[j]);
				minv = MIN(s[j], s[i] - s[j]);
				maxv = MAX(maxv, MAX(s[k] - s[i], s[n] - s[k]));
				minv = MIN(minv, MIN(s[k] - s[i], s[n] - s[k]));

				ans = MIN(ans, maxv - minv);
			}
		}
	}

	printf("%lld", ans);
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
#define x_ real()
#define y_ imag()
#define cross(a, b) (conj(a)*(b)).imag()
#define dot(a, b) (conj(a)*(b)).real()
#define PI acos(-1)
#define F first
#define S second
#define fastIO ios_base::sync_with_stdio(false), cin.tie(NULL)
#define fileIO freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)
#define ordered_set tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef complex<ld> point;
typedef tuple<int, int, int> line;
typedef vector<point> polygon;
typedef pair<double, double> pd;
pair<int, int> dirs[] = { {1, 2}, {-1, 2}, {2, 1}, {2, -1}, {-2, 1}, {-2, -1}, {1, -2}, {-1, -2} };
const double eps = 1e-6;
int N = 1e3 + 7;


int main() {
	fastIO;
	int x1, x2, y1, y2;
	cin >> x1 >> y1 >> x2 >> y2;
	double side = hypot(x1-x2, y1-y2);
	double angle = atan2(y2-y1, x2-x1);
	int x3 = round(x2 + side * cos(angle+PI/2));
	int y3 = round(y2 + side * sin(angle+PI/2));
	int x4 = round(x3 + side * cos(angle+PI));
	int y4 = round(y3 + side * sin(angle+PI));

	cout << x3 << " " << y3 << " " << x4 << " " << y4;




}


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

int solve(int A, int B, int C) {
    if (A % 2 == 1 || B % 2 == 1 || C % 2 == 1) return 0;
    if (A == B && B == C) return -1;
    return solve((A + B) / 2, (B + C) / 2, (C + A) / 2) + 1;
}

int main() {
    int A, B, C;
    cin >> A >> B >> C;
    cout << solve(A, B, C) << endl;
}


Measured memory_bytes: 256
from collections import deque
k = int(input())
a = deque([1,2,3,4,5,6,7,8,9])
count=0
while count !=k:
  b = a.popleft()
  count += 1
  if b%10==0:
    a.append(b*10)
    a.append(b*10+1)
  elif b%10==9:
    a.append(b*10+8)
    a.append(b*10+9)
  else:
    a.append(b*10+b%10-1)
    a.append(b*10+b%10)
    a.append(b*10+b%10+1)
print(b)

Measured memory_bytes: 11996
def main():
    n, k = map(int, input().split())
    h = list(map(int, input().split()))
    dp = [10**9+1]*n
    dp[0] = 0
    for i in range(1, n):
        buf = [dp[j] + abs(h[j]-h[i]) for j in range(max(i-k,0), i)]
        dp[i] = min(buf)
    print(dp[n-1])

if __name__ == "__main__":
    main()


Measured memory_bytes: 13980
A = int(input())
B = int(input())
C = int(input())
X = int(input())


cnt = 0
for i in range(A + 1):
    for j in range(B + 1):
        for k in range(C + 1):
            if ((500 * i) + (100 * j) + (50 * k)) == X:
                cnt += 1

print(cnt)

Measured memory_bytes: 3060
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val t = (1..2).map { sc.next() }
    println(if (t[0][0]==t[1][2] && t[1][0]==t[0][2] && t[0][1]==t[1][1]) "YES" else "NO")
}

Measured memory_bytes: 31268
#include <bits/stdc++.h>
#define all(x) begin(x),end(x)
#define rall(x) (x).rbegin(),(x).rend()
#define REP(i,b,n) for(int i=(int)(b);i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define repsz(i,v) rep(i,(v).size())
#define aur auto&
#define bit(n) (1LL<<(n))
#define eb emplace_back
#define mt make_tuple
#define fst first
#define snd second
using namespace std;
typedef long long ll;
//#define int long long
template<class C>int size(const C &c){ return c.size(); }
template<class T,class ...U>bool chmin(T&a, const U&...bs){const T b(bs...);if(a<=b)return false;a=b;return true;}
template<class T,class ...U>bool chmax(T&a, const U&...bs){const T b(bs...);if(a>=b)return false;a=b;return true;}


// TopologicalSort ts(n);
// ts.add_edge(u, v);
// bool ts.run(); true if this graph is DAG.
// ts.ord[idx] = v
// ts.idx[v] = idx
struct TopologicalSort{//{{{
    vector<vector<int>> g;
    TopologicalSort(const int &n) : g(n){}
    inline void add_edge(const int &s, const int &t){ g[s].emplace_back(t); }
    vector<int> ord, idx;
    bool run(){//{{{
        const int n = g.size();
        ord.resize(n); idx.resize(n);
        vector<int> d(n);
        for(int u = 0; u < n; ++u) for(auto &v : g[u]) ++d[v];
        int ql = -1, qr = -1;
        for(int u = 0; u < n; ++u) if(d[u] == 0) ord[++qr] = u;
        while(ql != qr){
            int u = ord[++ql]; idx[u] = ql;
            for(auto &v : g[u]) if(!--d[v]) ord[++qr] = v;
        }
        return qr + 1 == g.size();
    }//}}}
};//}}}

struct UnionFind{ //{{{
    vector<int> par;
    int n, cnt;
    UnionFind(const int &x=0){init(x);}
    void init(const int &x){par.assign(cnt = n = x, -1);}
    inline int find(const int &x){ return par[x]<0 ? x : par[x] = find(par[x]); }
    inline bool same(const int &x, const int &y){ return find(x) == find(y); }
    inline bool unite(int x, int y){
        if((x = find(x)) == (y = find(y))) return false;
        --cnt;
        if(par[x] > par[y]) swap(x, y);
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    inline int count() const { return cnt; }
    inline int count(int x){ return -par[find(x)]; }
};
//}}}

bool solve(){
    int n, m;
    cin >> n >> m;
    TopologicalSort ts(n);
    vector<vector<int>> g(n);
    rep(_, n+m-1) {
        int a, b; cin >> a >> b;
        --a; --b;
        g[b].emplace_back(a);
        ts.add_edge(a, b);
    }
    ts.run();

    vector<int> res(n);
    for(const auto &v: ts.ord) {
        pair<int, int> mx = make_pair(-1, -1);
        for (auto &p : g[v]) {
            chmax(mx, make_pair(ts.idx[p], p));
        }
        res[v] = mx.second + 1;
    }
    rep(i, n) cout << res[i] << endl;

    return true;
}
signed main(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << std::fixed << std::setprecision(10);
    solve();
    return 0;
}
// vim:set foldmethod=marker commentstring=//%s:


Measured memory_bytes: 12920
from itertools import combinations
from sys import stdin


def main():
    N = int(stdin.readline().rstrip())
    person = list(range(1, N + 1))
    xy = []
    for i in range(N):
        A = int(stdin.readline().rstrip())
        xy.append([tuple(int(x) for x in stdin.readline().rstrip().split()) for _ in range(A)])
    for i in range(N, 0, -1):
        for comb in combinations(person, i):
            result = [None] * N
            is_fail = False
            for num in comb:
                for x, y in xy[num - 1]:
                    if y == 0:
                        if x in comb:
                            is_fail = True
                            break
                    else:
                        if x not in comb:
                            is_fail = True
                            break

                    if result[x - 1] is None:
                        result[x - 1] = y
                    elif result[x - 1] == y:
                        pass
                    else:
                        is_fail = True
                        break
                if is_fail:
                    break
            else:
                print(i)
                return
    print(0)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
/*
  AOJ 2746
  Title:jfen
  @kankichi573
*/
#include <stdio.h>
#include <string.h>


void extract(char *s,char ban[][10],int *w,int *h)
{
  int x,y,c;
  char *p;
  x=y=0;
  for(p=s,c=0;*p;p++)
    {
      if(*p=='b')
	ban[y][x++]='*';
      else if(isdigit(*p))
	x += (*p - '0');
      else if(*p == '/')
	*w= x,x = 0,y++;
    }
  *h=y+1;
  //printf("w=%d h=%d\n",*w,*h);
}

void move(char ban[][10],int a,int b,int c,int d)
{
  //printf("abcd=%d %d %d %d\n",a,b,c,d);
  ban[a-1][b-1]='-';
  ban[c-1][d-1]='*';
}

void display(char ban[][10],int w,int h)
{
  int i,j;
  for(i=0;i<h;i++)
    {
      for(j=0;j<w;j++)
	printf("%c",ban[i][j]);
      printf("\n");
    }
  printf("---------\n");
}
answer(char ban[][10],int w,int h)
{
  int i,j;
  char c,cnt,pr;

  for(i=0;i<h;i++)
    {
      cnt=0;
      for(j=0;j<w;j++)
	{
	  c=ban[i][j];
	  if(c=='-')
	    {
	      cnt++;
	      if(j==w-1)
		printf("%d",cnt);
	    }
	  else if(c=='*')
	    {
	      if(cnt)
		printf("%d",cnt);
	      printf("b");
	      cnt=0;
	    }
	}
      if(i<h-1)
	printf("/");
    }
      printf("\n");
}

main()
{
  char s[1000],ban[9][10];
  int a,b,c,d,w,h;

  while(1)
    {
      scanf("%s",s);
      if(s[0]=='#')
	break;
      scanf("%d %d %d %d",&a,&b,&c,&d);

      memset((void *)ban,(int)'-',sizeof(ban));
      extract(s,ban,&w,&h);
#ifdef DEBUG
      display(ban,w,h);
#endif
      move(ban,a,b,c,d);
#ifdef DEBUG
      display(ban,w,h);
#endif
      answer(ban,w,h);
    }
  return(0);
}

Measured memory_bytes: 600
#define _USE_MATH_DEFINES
#include <math.h>
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <algorithm>

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

using namespace std;
typedef long long ll;

int main() {

    ll N,K;
    cin >> N >> K;
    ll h;
    ll out = 0;
    rep(i,N){
        cin >> h;
        if(h>=K) out++;
    }
    cout << out << endl;
    
    return 0;
}


Measured memory_bytes: 256
// E - Almost Everywhere Zero

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const int MOD = 1e9 + 7;

ll dp[101][2][4]; // dp[i][j][k]:個数, i:決めた桁数（左から）, j:未満フラグ, k:0でない数字の個数

ll solve(string N, int K) {
	dp[0][0][0] = 1;

	int L = N.size();

	for (int i=0; i<L; i++) {
		int D = N[i] - '0';

		// ==== 過去に対応する桁より小さい値を入れたことがない（dp[i][0][k]からの更新） ==== //

		// D未満を選ぶとき、更新先の未満フラグは1
		for (int d=0; d<D; d++) {
			if (d == 0) {
				dp[i+1][1][0] += dp[i][0][0];
				dp[i+1][1][1] += dp[i][0][1];
				dp[i+1][1][2] += dp[i][0][2];
				dp[i+1][1][3] += dp[i][0][3];
			} else {
				dp[i+1][1][1] += dp[i][0][0];
				dp[i+1][1][2] += dp[i][0][1];
				dp[i+1][1][3] += dp[i][0][2];
			}
		}

		// Dを選ぶとき、更新先の未満フラグは0
		int d = D;
		if (d == 0) {
			dp[i+1][0][0] += dp[i][0][0];
			dp[i+1][0][1] += dp[i][0][1];
			dp[i+1][0][2] += dp[i][0][2];
			dp[i+1][0][3] += dp[i][0][3];
		} else {
			dp[i+1][0][1] += dp[i][0][0];
			dp[i+1][0][2] += dp[i][0][1];
			dp[i+1][0][3] += dp[i][0][2];
		}

		// ==== 過去に対応する桁より小さい値を入れたことがある（dp[i][1][k]からの更新） ==== //
		// → 全て（0 以上 9 以下）の値が候補
		for (int d=0; d<=9; d++) {
			if (d == 0) {
				dp[i+1][1][0] += dp[i][1][0];
				dp[i+1][1][1] += dp[i][1][1];
				dp[i+1][1][2] += dp[i][1][2];
				dp[i+1][1][3] += dp[i][1][3];
			} else {
				dp[i+1][1][1] += dp[i][1][0];
				dp[i+1][1][2] += dp[i][1][1];
				dp[i+1][1][3] += dp[i][1][2];
			}
		}
	}

	return dp[L][0][K] + dp[L][1][K];
}

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

	ll ans = solve(N, K);

	cout << ans << endl;

	return 0;
}

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

int main(){
    int n,k;
    cin>>n>>k;
    char a[k];
    rep(i, k)
    {
        cin >> a[i];
    }
    int ans=n;
    while(true){
        string s=to_string(ans);
        int l=(int)s.length();
        bool key=true;
        rep(i,l){
            rep(j,k){
                if(s[i]==a[j]){
                    key=false;
                    break;
                }
            }
            if(key==false)
            break;
        }
        if(key){
            cout<<s<<endl;
            return 0;
        }
        ans++;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <set>

using namespace std;

int main() {
	int N=0;
	cin >> N;
	set<int> s;
	int tmp;
	for(int i=0;i<N;i++) {
	  cin >> tmp;
	  s.insert(tmp);
	}
	
	cout << s.size();
}

Measured memory_bytes: 256
#include<iostream>
#include<sstream>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<complex>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cassert>

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define mp make_pair
#define pb push_back
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define dbg(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<endl

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf = (int)1e9;
const double INF = 1e12, EPS = 1e-9;

struct flowGraph{
	struct edge{ int to, cap, rev; };
	
	int n, *level, *iter;
	vector<vector<edge> > G;
	
	flowGraph(int sz) : n(sz){
		G.resize(n);
		iter = new int[n]; level = new int[n];
	}
	~flowGraph(){
		delete iter; delete level;
	}
	
	int add(int s, int t, int cap){
		G[s].pb((edge){t, cap, G[t].size()});
		G[t].pb((edge){s, 0, G[s].size() - 1});
		return G[s].size() - 1;
	}
	void bfs(int s){
		rep(i, n) level[i] = -1;
		queue<int> q;
		level[s] = 0;
		q.push(s);
		while(!q.empty()){	
			int v = q.front();
			q.pop();
			rep(i, G[v].size()){
				edge &e = G[v][i];
				if(e.cap > 0 && level[e.to] < 0){
					level[e.to] = level[v] + 1;
					q.push(e.to);
				}
			}
		}
	}
	int dfs(int v, int t, int f){
		if(v == t) return f;
		for(int &i = iter[v]; i < (int)G[v].size(); i++){
			edge &e = G[v][i];
			if(e.cap > 0 && level[v] < level[e.to]){
				int d = dfs(e.to, t, min(f, e.cap));
				if(d > 0){
					e.cap -= d;
					G[e.to][e.rev].cap += d;
					return d;
				}
			}
		}
		return 0;
	}
	int max_flow(int s, int t, int lim = inf){
		int flow = 0;
		while(1){
			bfs(s);
			if(level[t] < 0) return flow;
			rep(i, n) iter[i] = 0;
			int f;
			while((f = dfs(s, t, lim - flow)) > 0) flow += f;
			if(flow == lim) return flow;
		}
	}
};
int n, e, q;
int m[1000], a[1000], b[1000];

int main(){
	cin >> n >> e >> q;
	map<pi, int> id;
	flowGraph g(n);
	rep(i, e){
		int f, t;
		cin >> f >> t;
		f--; t--;
		rep(it, 2){
			int j = g.add(f, t, 1);
			if(!id.count(mp(f, t))) id[mp(f, t)] = j;
			swap(f, t);
		}
	}
	rep(i, q){
		cin >> m[i] >> a[i] >> b[i];
		a[i]--; b[i]--;
		rep(it, 2){
			if(!id.count(mp(a[i], b[i]))){
				int j = g.add(a[i], b[i], 0);
				id[mp(a[i], b[i])] = j;
			}
			swap(a[i], b[i]);
		}
	}
	int ans = g.max_flow(0, n - 1);
	
	rep(i, q){
		if(m[i] == 1){
			g.G[a[i]][id[mp(a[i], b[i])]].cap++;
			g.G[b[i]][id[mp(b[i], a[i])]].cap++;
			ans += g.max_flow(0, n - 1);
		}
		else{
			int j = g.G[a[i]][id[mp(a[i], b[i])]].rev;
			if(g.G[b[i]][j].cap == 0){
				swap(a[i], b[i]);
				j = g.G[a[i]][id[mp(a[i], b[i])]].rev;
			}
			
			int t = g.max_flow(a[i], b[i], 1);
			if(!t){
				g.max_flow(n - 1, 0, 1);
				int u = g.max_flow(a[i], b[i], 1);
				assert(u);
				ans--;
			}
			g.G[a[i]][id[mp(a[i], b[i])]].cap = 0;
			g.G[b[i]][j].cap = 0;
			g.G[b[i]][id[mp(b[i], a[i])]].cap = 0;
			g.G[a[i]][g.G[b[i]][id[mp(b[i], a[i])]].rev].cap = 0;
		}
		cout << ans << endl;
	}
	
	return 0;
}

Measured memory_bytes: 5148
void main()
{
    long n = readln.chomp.to!long;
    string[] tmp = readln.split;
    string s = tmp[0], t = tmp[1];

    foreach (i; 0 .. n)
    {
        write(s[i], t[i]);
    }
    writeln;
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni;

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

using namespace std;

string S;
int N;

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

	for (unsigned int i = 0; i < S.size(); i++) {
		char x = (char)((int)S[i] + N);
		if (x > 'Z') {
			x = x - 'Z' + 'A' - 1;
		}
		cout << x << flush;
	}
	cout << endl;
}

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

using namespace std;

int main() {
    int n,m;cin>>n>>m;
    vector<int> a(m);
    vector<int> b(m);
    for(int i = 0;i<m;i++)
        cin >> a[i] >> b[i];
    map<int,int> ma;
    for(int i=0;i<m;i++){
        ma[a[i]]++;
        ma[b[i]]++;
    }
    for(int i=0;i<n;i++)
        cout << ma[i+1] << endl;

}


Measured memory_bytes: 256
import java.io.IOException;
import java.util.NoSuchElementException;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;

import java.util.Arrays;

public class Main {
    public static void main(String[] args) throws IOException {
        try (
            BufferedReader reader = new BufferedReader(
                new InputStreamReader(System.in))) {
            final String s = reader.readLine();

            final String sl[] = s.split(" ");
            int a = Integer.parseInt(sl[0]);
            int b = Integer.parseInt(sl[1]);
            int c = Integer.parseInt(sl[2]);
            int d = Integer.parseInt(sl[3]);

            System.out.println(
                (Math.abs(b - a) <= d && Math.abs(c - b) <= d)
                    || Math.abs(c - a) <= d  ? "Yes" : "No");
        }
    }
}


Measured memory_bytes: 21204
#include <stdio.h>
#define INFTY 1000000001
struct C
{
    char c;
    int x;
};
typedef struct C data;
int partition(data *,int,int);
void quicksort(data *,int,int);
void mergesort(data *,int,int);
void merge(data *,int,int,int);
int main (){
    int n,i,flag=0;
    data a[100000],b[100000];
    scanf("%d\n",&n);
    for(i=0;i<n-1;i++){
        scanf("%c %d\n",&a[i].c,&a[i].x);
        b[i]=a[i];
    }
    scanf("%c %d",&a[i].c,&a[i].x);
    b[i]=a[i];
    quicksort(a,0,n-1);
    mergesort(b,0,n);
    for(i=0;i<n;i++){
        if(a[i].c!=b[i].c){
            flag=1;
            break;
        }
    }
    if(flag){
        printf("Not stable\n");
    }
    else{
        printf("Stable\n");
    }
    for(i=0;i<n;i++){
        printf("%c %d\n",a[i].c,a[i].x);
    }
    return 0;
}
int partition(data *A,int p,int r){
    data x,tmp;
    int i,j;
    x=A[r];
    i=p-1;
    for(j=p;j<r;j++){
        if(A[j].x<=x.x){
            i++;
            tmp=A[i];
            A[i]=A[j];
            A[j]=tmp;
        }
    }
    tmp=A[i+1];
    A[i+1]=A[r];
    A[r]=tmp;
    return i+1;
}
void quicksort(data *A,int p,int r){
    int q;
    if(p<r){
        q = partition(A, p, r);
        quicksort(A, p, q-1);
        quicksort(A, q+1, r);
    }
}
void mergesort(data *A,int left,int right){
  int mid;
  if(left+1<right){
    mid=(left+right)/2;
    mergesort(A,left,mid);
    mergesort(A,mid,right);
    merge(A,left,mid,right);
  }
}
void merge(data *A,int left,int mid,int right){
  int n1,n2,i,j,k;
  n1=mid-left;
  n2=right-mid;
  data L[n1+1],R[n2+1];
  for(i=0;i<n1;i++)
    L[i]=A[left+i];
  for(i=0;i<n2;i++)
    R[i]=A[mid+i];
  L[n1].x=INFTY;
  R[n2].x=INFTY;
  i=0;
  j=0;
  for(k=left;k<right;k++){
    if(L[i].x<=R[j].x){
      A[k]=L[i];
      i++;
    }
    else{
      A[k]=R[j];
      j++;
    }
  }
}



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

using std::vector;

int main(void)
{
  uint32_t N{}; std::cin >> N;
  vector<uint32_t> H(N);
  std::for_each(H.begin(), H.end(), [](auto& h){ std::cin >> h; });

  vector<uint32_t> res{};
  res.reserve(N);
  auto inf = H.begin();
  uint32_t min{}, max{};
  for(auto it = H.begin(); it != H.end(); ++it)
  {
    if(it == inf)
    {
      max = *it;
    }
    else
    {
      if(*it < *std::prev(it))
      {
        if(max)
        {
          res.push_back(max - min);
          max = 0;
        }
        min = *it;
      }
      else
      {
        max = *it;
      }
    }
  }
  if(max) res.push_back(max - min);

  auto ans = std::accumulate(res.begin(), res.end(), 0U);
  std::cout << ans << '\n';

  return 0;
  }

Measured memory_bytes: 256
/*
 * @Author: Luisvacson
 * @LastEditors: Luisvacson
 * @Descriptions: None
 * @Date: 2020-09-26 20:09:34
 * @LastEditTime: 2020-09-26 20:26:15
 * @FilePath: \VSC\C++\Practice\AC ACLBC C.cpp
 */
#include <bits/stdc++.h>
using namespace std;

int f[100005];
int find(int x)
{
    if (f[x] != x)
        f[x] = find(f[x]);
    return f[x];
}

void un(int x, int y)
{
    f[find(x)] = find(y);
}

int n, m;
bool vis[100005];
signed main()
{
    scanf("%d%d", &n, &m);
    register int i;

    for (i = 1; i <= n; ++i)
        f[i] = i;

    int x, y;
    for (i = 1; i <= m; ++i) {
        scanf("%d%d", &x, &y);
        un(x, y);
    }
    int ans = 0;
    for (i = 1; i <= n; ++i) {
        if (find(i) == i)
            ++ans;
    }

    printf("%d\n", ans - 1);
    return 0;
}

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

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

    string a,b;
    cin >> a >> b;

    bool similar=true;
    for(int i = 0; i < a.size(); ++i){
        if(a[i]!=b[i]){
            similar=false;
        }
    }
    similar?cout<<"Yes":cout<<"No";
    return 0;
}


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

using namespace std;

int main()
{
  int n, m;

  scanf("%d %d", &n, &m);

  int x[60];

  for (int i = 0; i < 60; i++)
  {
    x[i] = 0;
  }

  int a;
  for (int i = 0; i < 2 * m; i++)
  {
    scanf("%d", &a);

    x[a]++;
  }

  for (int i = 1; i <= n; i++)
  {
    printf("%d\n", x[i]);
  }
}

Measured memory_bytes: 256
//
//  main.cpp
//  Study
//
//  Created by 佐々木勇星 on 2020/03/12.
//  Copyright © 2020 佐々木勇星. All rights reserved.
//

#include <iostream>
#include <vector>
#include <cmath>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <map>

using namespace std;


int main(int argc, const char * argv[]) {

    int n;
    cin >> n;
    
    cout << ((n + 2 - 1) / 2) - 1 << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>

typedef  long long ll;
#define mop 1000000007
using namespace std;

int main() {
    

    vector <ll> v;
    for (ll i=0;i<3;i++){
        ll p;
        cin >> p;
        v.push_back(p);
    }
    sort(v.begin(), v.end());
    cout << v[0]*v[1]/2 << endl;


}




Measured memory_bytes: 256
n = gets.chomp.to_i
 a = gets.chomp.split(" ").map(&:to_i)
 b = gets.chomp.split(" ").map(&:to_i)
atr = [*1..n]
arr = []
atr.permutation (n) do |i|
    arr << i
end
ans1 = 0
ans2 = 0
arr.each_with_index do |item,i|
    if a == item
        ans1 = i
    end
    if b == item
        ans2 = i
    end
end
puts (ans1-ans2).abs

Measured memory_bytes: 20464