akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

template <class Monoid> struct SegmentTree{
    using Func = function<Monoid(Monoid, Monoid)>;

    int size;
    vector<Monoid> seg;
    const Func merge;
    const Monoid def;

    SegmentTree(int n, Monoid d, const Func f): merge(f), def(d){
        for(size = 1; size <= n; size <<= 1);
        seg.assign(size*2, def);
    }

    Monoid& operator[] (int i) { return seg[i+size]; };
    void build(){ for(int i = size-1;i >= 0;i--) seg[i] = merge(seg[i*2], seg[i*2+1]); }

    void update(int i, Monoid val){
        seg[i += size] = val;
        while(i >>= 1) seg[i] = merge(seg[i*2], seg[i*2+1]);
    }

    void add(int i, Monoid val){ update(i, val+seg[i+size]); }

    Monoid get(int a, int b){
        Monoid l = def, r = def;
        for(a += size, b += size; a < b; a >>= 1, b >>= 1){
            if(a & 1) l = merge(l, seg[a++]);
            if(b & 1) r = merge(r, seg[--b]);
        }
        return merge(l, r);
    }
};

int main(){
    int n, k;
    cin >> n >> k;

    int a[200010];
    for(int i = 0;i < n;i++) cin >> a[i];

    SegmentTree<int> seg(n, INT_MIN, [](int a, int b){ return max(a, b);});
    SegmentTree<int> rseg(n, INT_MAX, [](int a, int b){ return min(a, b);});

    for(int i = 0;i < n;i++) seg[i] = a[i];
    for(int i = 0;i < n;i++) rseg[i] = a[i];

    int soted[200010] = {};
    for(int i = 0;i < n-1;i++) soted[i+1] = soted[i] + (a[i] < a[i+1] ? 1 : 0);

    seg.build();
    rseg.build();

    int s = 0;
    if(soted[k-1] == k-1) s = 1;
    int ans = soted[k-1] == k-1 ? 0 : 1;

    for(int i = 1;i < n;i++){
        if(i+k > n) break;
        if(seg.get(i, i+k-1) > a[i+k-1] || rseg.get(i, i+k-1) < a[i-1]){
            if(soted[i+k-1] - soted[i] == k-1){
                s = 1;
            }else{
                ans++;
            }
        }
    }

    cout << ans + s<< endl;
    return 0;
}

Measured memory_bytes: 5888
using System;
using System.Collections.Generic;

namespace agc_001
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            string[] tmp = Console.ReadLine().Split(' ');
            int[] L = new int[N * 2];
            int sum = 0;

            for (int i=0; i < N*2; i++)
            {
                L[i] = int.Parse(tmp[i]);
            }

            Array.Sort(L);

            for(int i = (L.Length)-2; i >= 0; i-=2)
            {
                sum += L[i];
            }

            Console.WriteLine(sum);

        }
    }
}

Measured memory_bytes: 2776
#include <cassert>
#include <map>
#include <functional>
#include <vector>
#include <unordered_map>
#include <iostream>
using namespace std;

constexpr int NMAX = 100100, stroke = 300;
int depth[NMAX], jump[NMAX], parent[NMAX], weight[NMAX], color[NMAX];
unordered_map<int, int> all_sum;
unordered_map<int, unordered_map<int, int> > col_sum, col_cnt;

vector<vector<tuple<int, int, int> > > adj;

void compute() {
    function<void(int, int, int)> dfs = [&] (int u, int p, int d) {
        depth[u] = d;
        parent[u] = p;
        for (auto e : adj[u]) {
            int v = get<0>(e);
            if (v == p) continue;
            color[v] = get<1>(e);
            weight[v] = get<2>(e);
            dfs(v, u, d+1);
        }
    };
    dfs(0, -1, 0);
    for (int u = 0; u < adj.size(); u++) {
        int pp = u;
        for (int i = 0; i < stroke && pp >= 0; i++, pp = parent[pp]) ;
        jump[u] = pp;
    }
    for (int u = 0; u < adj.size(); u++) {
        if (depth[u] % stroke == 0 && depth[u] > 0) {
            for (int v = u, i = 0; i < stroke; i++, v = parent[v]) {
                all_sum[u] += weight[v];
                col_sum[u][color[v]] += weight[v];
                col_cnt[u][color[v]]++;
            }
        }
    }
}    

int ancestor(int u, int cnt) {
    while (cnt >= stroke) { cnt -= stroke; u = jump[u]; }
    while (cnt > 0) { cnt--; u = parent[u]; }
    return u;
}

int lca(int u, int v) {
    int du = depth[u], dv = depth[v];
    if (du > dv) u = ancestor(u, du - dv);
    else if (du < dv) v = ancestor(v, dv - du);
    while (jump[u] != jump[v]) u = jump[u], v = jump[v];
    while (u != v) u = parent[u], v = parent[v];
    return u;
}

int query(int x, int y, int u, int v) {
    int ans = 0;
    if (depth[u] / stroke > depth[v] / stroke) {
        for (int i = depth[u] % stroke; i > 0; i--) {
            if (color[u] == x) ans += y;
            else ans += weight[u];
            u = parent[u];
        }
    }
    while (depth[u] - stroke >= depth[v]) {
        ans += all_sum[u];
        auto it = col_cnt[u].find(x);
        if (it != col_cnt[u].end()) ans += col_cnt[u][x] * y - col_sum[u][x];
        u = jump[u];
    }
    while (depth[u] > depth[v]) {
        if (color[u] == x) ans += y;
        else ans += weight[u];
        u = parent[u];
    }
    
    return ans;
}

int main() {
    int n, q; cin >> n >> q;
    adj.resize(n);
    for (int i = 1; i < n; i++) {
        int a, b, c, d; cin >> a >> b >> c >> d;
        a--; b--; c--;
        adj[a].push_back(make_tuple(b, c, d));
        adj[b].push_back(make_tuple(a, c, d));
    }
    compute();

    while (q--) {
        int x, y, u, v; cin >> x >> y >> u >> v;
        x--; u--; v--;
        int w = lca(u, v);
        cout << query(x, y, u, w) + query(x, y, v, w) << endl;
    }
}


Measured memory_bytes: 19968
from decimal import Decimal

x1, y1 = map(str, input().split())
x2, y2 = map(str, input().split())
x3, y3 = map(str, input().split())
x1, y1 = Decimal(x1), Decimal(y1)
x2, y2 = Decimal(x2), Decimal(y2)
x3, y3 = Decimal(x3), Decimal(y3)

#3辺の長さ
a = (((x1-x2)**Decimal('2'))+((y1-y2)**Decimal('2')))**Decimal('0.5')
b = (((x3-x2)**Decimal('2'))+((y3-y2)**Decimal('2')))**Decimal('0.5')
c = (((x1-x3)**Decimal('2'))+((y1-y3)**Decimal('2')))**Decimal('0.5')
s = ((a+b+c)/Decimal('2'))

r = (a*b*c)/(((s*(s-a)*(s-b)*(s-c))**Decimal('0.5'))*Decimal('4'))
xa, ya = (x1+x2)/2, (y1+y2)/2
xb, yb = (x3+x2)/2, (y3+y2)/2

if (y3-y2) != 0 and (y2-y1) != 0:
    a1, b1 = -(x3-x2)/(y3-y2), ((x3-x2)*xb+(y3-y2)*yb)/(y3-y2)
    a2, b2 = -(x2-x1)/(y2-y1), ((x2-x1)*xa+(y2-y1)*ya)/(y2-y1)
    cx = (b2-b1)/(a1-a2)
    cy = a1 * cx + b1

if y3-y2 == 0:
    cx = xb
    a2, b2 = -(x2-x1)/(y2-y1), ((x2-x1)*xa+(y2-y1)*ya)/(y2-y1)
    cy = a2 * cx + b2

if y2-y1 == 0:
    cx = xa
    a1, b1 = -(x3-x2)/(y3-y2), ((x3-x2)*xb+(y3-y2)*yb)/(y3-y2)
    cy = a1 * cx + b1

print(cx, cy, r)


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

typedef long long ll;

int main() {
    int N, K, A, ans = 0;
    cin >> N >> K;
    vector<int> c(N, 0), d;
    rep(i, N) {
        cin >> A;
        c[A - 1]++;
    }
    rep(i, N) {
        d.push_back(c[i]);
    }
    sort(d.begin(), d.end());
    rep(i, N - K) {
        ans += d[i];
    }
    cout << ans << "\n";
}

Measured memory_bytes: 2168
#include        "algorithm"
#include        "iostream"
#include        "numeric"
#include        "iomanip"
#include        "cstring"
#include        "math.h"
#include        "bitset"
#include        "string"
#include        "vector"
#include        "random"
#include        "chrono"
#include        "ctime"
#include        "queue"
#include        "stack"
#include        "map"
#include        "set"

#include        "ext/pb_ds/assoc_container.hpp" // Common file
#include        "ext/pb_ds/tree_policy.hpp" // Including tree_order_statistics_node_update
#include        "ext/pb_ds/detail/standard_policies.hpp"

using namespace std;
using namespace __gnu_pbds;


#define          f first
#define          lgn 25
#define          endl '\n'
#define          sc second
#define          pb push_back
#define          N (int)2e5+5
#define          PI acos(-1.0)
#define          int long long 
#define          vi vector<int>
#define          mod 1000000007
#define          ld long double
#define          eb emplace_back
#define          mii map<int,int>
#define          vpii vector<pii>
#define          pii pair<int,int>
#define          pq priority_queue
#define          BLOCK (int)sqrt(N)
#define          test(x) while(x--)
#define          all(x) begin(x),end(x)
#define          allr(x) x.rbegin(),x.rend()
#define          fo(i,a,n) for(int i=a;i<n;i++)
#define          rfo(i,n,a) for(int i=n;i>=a;i--)
#define          FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define          time() cerr << "Time : " << (double)clock() / (double)CLOCKS_PER_SEC << "s\n"
#define          bug(...)       __f (#__VA_ARGS__, __VA_ARGS__)

typedef tree< int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update > 
OS ;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

template <typename Arg1>
void __f (const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << endl; }
template <typename Arg1, typename... Args>
void __f (const char* names, Arg1&& arg1, Args&&... args)
{
     const char* comma = strchr (names + 1, ',');
     cout.write (names, comma - names) << " : " << arg1 << " | "; __f (comma + 1, args...);
}

const int inf = 0x3f3f3f3f;
const int INF = 0x3f3f3f3f3f3f3f3f;

int n,m,k,q;
string s;
vi adj[N];
int b[N],par[N],a[N];

void go()
{
    cin >> n;

    fo(i,1,n+1) cin >> a[i] , b[i] = a[i] , a[i] = ( a[i] + a[i-1] )%mod;

    int ans = 0;

    fo(i,1,n+1)
    {
        int now = ( a[i-1]%mod * b[i]%mod )%mod;
        ans = ( ans%mod + now%mod )%mod;
    }

    cout << ans << endl;
}

int32_t main()
{
    FAST;     
    int t=1; 
    // cin>>t;
    test(t) go();
}



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

#define _GLIBCXX_DEBUG

//vector<int> A(M), B(M);
//vector<vector<char>> answer(N, vector<char>(N, '-'));

int main() {
  float d, t, s;
  
  cin >> d >> t >> s;
  
  if(d/s <= t) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  return 0;
}

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

int u[100], b[100];
int dp[100][100];

int main(void){
  int n;
  cin >> n;
  for(int i = 0; i < n; i++){
    cin >> u[i] >> b[i];
  }

  for(int i = 0; i < n; i++){
    for(int j = 0; j < n; j++){
      if(i != j) dp[i][j] = INT_MAX;
    }
    dp[i][i] = 0;
  }

  for(int i = 1; i <= n; i++){
    for(int j = 0; j < n - i; j++){
      for(int k = j; k < j + i; k++){
        dp[j][j+i] = min(dp[j][j+i], dp[j][k] + dp[k+1][j+i] + u[j] * b[k] * u[k+1] * b[j+i]);
      }
    }
  }

  cout << dp[0][n-1] << endl;
  return 0;
}

Measured memory_bytes: 1196
import java.util.Scanner;

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

      sc.nextLine();

      String line = sc.next();

      int[] results = new int[n];
      for (int i = 0; i < line.length() - 1; i++) {
        if (line.charAt(i) == 'A' && line.charAt(i + 1) == 'C') {
          results[i + 1] = results[i] + 1;
        } else {
          results[i + 1] = results[i];
        }
      }

      for (int i = 0; i < q; i++) {
        int l = sc.nextInt();
        int r = sc.nextInt();
        System.out.println(results[r - 1] - results[l - 1]);
      }
    }
  }
}

Measured memory_bytes: 65544
def gozyo(x,y):
    while True:
        if y == 0:
            return x
        x = x % y
        z = x
        x = y
        y = z
    
a,b = map(int,input().split())
if a < b:
    c = a
    a = b
    b = c
print(gozyo(a,b))


Measured memory_bytes: 5596
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner cin = new Scanner(System.in);
		int s;
		s=0;
		for(int i=0;i<5;++i){
			int x;
			x=cin.nextInt();
			if(x<40){
				s=s+40;
			}else if(x>=40){
				s=s+x;
			}
		}System.out.println(s/5);
	}
}

Measured memory_bytes: 17300
#include <iostream>
using namespace std;
typedef long long ll;

ll term(ll a, ll d, ll b)
{
	if(a%d == 0)
return (b-a)/d + 1;
else
{
ll temp = a+d-(a%d);
if(b-temp >= 0)
return (b-temp)/d + 1;	
return 0;
}
}

ll gcd(ll x, ll y) 
{ 
    if (y == 0) 
        return x; 
    return gcd(y, x % y);  
      
}


int main() {
	ll a, b, c, d;
	cin >> a >> b >> c >> d;
	ll n1 = term ( a, c, b);
	ll n2 = term (a, d, b);
	ll temp = (c*d)/gcd(c,d);
	ll n3 = term (a,temp , b);
	ll t = b-a+1;
	cout << t-(n1-n3+n2);
	
	// your code goes here
	return 0;
}

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

int main(){
    int a,b,c;
    cin>>a>>b>>c;
    int x,y;
    cin>>x>>y;
    
    int ans = 1001001001;
    int cost;
    rep(i,max(x,y)+1){
        cost = 2*i*c;
        cost += max(0,x-i)*a;
        cost += max(0,y-i)*b;
        
        ans = min(ans, cost);
    }
    
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
/*  */
#include <iostream>
#include <sstream>
#include <string>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#include <deque>
#include <bitset>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <climits>
#include <cctype>
#include <cassert>
#include <functional>
#include <iterator>
#include <iomanip>
using namespace std;
//#pragma comment(linker,"/STACK:102400000,1024000")

#define sti				set<int>
#define stpii			set<pair<int, int> >
#define mpii			map<int,int>
#define vi				vector<int>
#define pii				pair<int,int>
#define vpii			vector<pair<int,int> >
#define rep(i, a, n) 	for (int i=a;i<n;++i)
#define per(i, a, n) 	for (int i=n-1;i>=a;--i)
#define clr				clear
#define pb 				push_back
#define mp 				make_pair
#define fir				first
#define sec				second
#define all(x) 			(x).begin(),(x).end()
#define SZ(x) 			((int)(x).size())
#define lson			l, mid, rt<<1
#define rson			mid+1, r, rt<<1|1
#define getBits(x)		__builtin_popcount(x)
#define getBitIdx(x)	__builtin_ffs(x)

typedef long long LL;



int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	// #ifndef ONLINE_JUDGE
		// freopen("data.in", "r", stdin);
		// freopen("data.out", "w", stdout);
	// #endif
	
	int a, b, c;
	bool visit[105];
	
	cin >> a >> b >> c;
	memset(visit, false, sizeof(visit));
	c %= b;
	
	for (int i=a%b; !visit[i]; i=(i+a)%b) {
		visit[i] = true;
	}
	puts(visit[c] ? "YES":"NO");
		
	
	// #ifndef ONLINE_JUDGE
		// printf("time = %ldms.\n", clock());
	// #endif
	
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#ifdef ENABLE_DEBUG_OUTPUT
#define DEBUG_LOG(s) cout << s << endl;
#else
#define DEBUG_LOG(s) void();
#endif

int main(){
    int s, w;
    cin >> s >> w;

    cout << ((s <= w) ? "unsafe" : "safe") << endl;
    return 0;
}

Measured memory_bytes: 3592
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>

const int MOD = 1000000007, INF = 1111111111;
using namespace std;
using lint = long long;

template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
	for (int i = 0; i < (int)vec.size(); i++) {
		os << vec[i] << (i + 1 == vec.size() ? "" : " ");
	}
	return os;
}

#ifdef _DEBUG
template <class Head>
void dump(const char* str, Head &&h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head &&h, Tail &&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + 1, t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int A, B;
	cin >> A >> B;

	cout << 2 * B - A << "\n";

	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
	private static final Scanner scan = new Scanner(System.in);

	public static void main(String[] args){

		int[] d = new int[6];
		for(int i = 0; i < 6; i++){
			d[i] = scan.nextInt();
		}
		Dice dice = new Dice(d);
		int q = scan.nextInt();
		for(int i = 0; i < q; i++){
			int n = scan.nextInt();
			int m = scan.nextInt();
			dice.setTop(n);
			dice.setSouth(m);
			System.out.println(dice.show(Dice.EAST));
		}
	}
}

class Dice{

	int[] _d = new int[6];
	public static final int
		TOP = 0, SOUTH = 1, EAST = 2,
		WEST = 3, NORTH = 4, BOTTOM = 5;

	public Dice(int[] d){ 
		for(int i = 0; i < 6; i++){
			_d[i] = d[i];
		}
	}

	public int show(int side){
		return _d[side];
	}

	public void setTop(int num){
		if(_d[TOP] != num){
			if(_d[SOUTH] == num){
				moveNorth();
			} else if(_d[EAST] == num){
				moveWest();
			} else if(_d[WEST] == num){
				moveEast();
			} else if(_d[NORTH] == num){
				moveSouth();
			} else if(_d[BOTTOM] == num){
				moveSouth();
				moveSouth();
			}
		}
	}

	public void setSouth(int num){
		for(int i = 0; i < 4; i++){
			if(_d[SOUTH] != num){
				moveRight();
			}
		}
	}

	private void moveSouth(){
		int tmp = _d[TOP];
		_d[TOP] = _d[NORTH];
		_d[NORTH] = _d[BOTTOM];
		_d[BOTTOM] = _d[SOUTH];
		_d[SOUTH] = tmp;
	}

	private void moveEast(){
		int tmp = _d[TOP];
		_d[TOP] = _d[WEST];
		_d[WEST] = _d[BOTTOM];
		_d[BOTTOM] = _d[EAST];
		_d[EAST] = tmp;
	}

	private void moveWest(){
		int tmp = _d[TOP];
		_d[TOP] = _d[EAST];
		_d[EAST] = _d[BOTTOM];
		_d[BOTTOM] = _d[WEST];
		_d[WEST] = tmp;
	}

	private void moveNorth(){
		int tmp = _d[TOP];
		_d[TOP] = _d[SOUTH];
		_d[SOUTH] = _d[BOTTOM];
		_d[BOTTOM] = _d[NORTH];
		_d[NORTH] = tmp;
	}

	private void moveRight(){
		int tmp = _d[SOUTH];
		_d[SOUTH] = _d[WEST];
		_d[WEST] = _d[NORTH];
		_d[NORTH] = _d[EAST];
		_d[EAST] = tmp;
	}
}

Measured memory_bytes: 26360
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce
import pprint
sys.setrecursionlimit(10 ** 9)


INF = 10 ** 13
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007

#　制約を考えないの組み合わせ数は重複組み合わせでわかる
# そこから、移動がk回のことを考え、0人の部屋が何個あるかで場合分け、全事象から引く。
#　全事象考える必要ない?

m, k = LI()
n = m * 2 + 2

fac = [1] * (n + 1)
inv = [1] * (n + 1)
for j in range(1, n + 1):
    fac[j] = fac[j-1] * j % mod


inv[n] = pow(fac[n], mod-2, mod)
for j in range(n-1, -1, -1):
    inv[j] = inv[j+1] * (j+1) % mod


def comb(n, r):
    if r > n or n < 0 or r < 0:
        return 0
    return fac[n] * inv[n - r] * inv[r] % mod


ret = 0
for i in range(min(m, k + 1)):
    ret = ret + comb(m, i) * comb(m - 1, i) % mod
    ret %= mod


print(ret)

Measured memory_bytes: 47980
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int N,M,X;
  cin>>N>>M>>X;
  int A[N+10];
  int i,j,k;
  int ansu=0;
  int ansd=0;
  for(i=0;i<M;i++)
  {
    cin>>A[i];
  }
  for(k=0;k<M;k++)
  {
    if(X<A[k])
    {
      ansu++;
    }
  }
  for(k=0;k<M;k++)
  {
    if(A[k]<X)
    {
      ansd++;
    }
  }
  cout<<min(ansu,ansd)<<endl;
  return 0;
}


Measured memory_bytes: 256
/*
confirm 0LL and 1LL
confirm cornercases such as 0
confirm times of cin < 10^6
*/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecVec = vector<Vec>;
#define REP(i, m, n) for(ll (i) = (m); (i) < (n); ++(i))
#define REPN(i, m, n) for(ll (i) = (m); (i) <= (n); ++(i))
#define REPR(i, m, n) for(ll (i) = (m)-1; (i) >= (n); --(i))
#define REPNR(i, m, n) for(ll (i) = (m); (i) >= (n); --(i))
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPNR(i, n, 1)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fs first
#define sc second
template <typename T>
bool chmax(T &a, const T& b){if(a < b){a = b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T& b){if(a > b){a = b; return true;} return false;}
template <typename T>
void co(const T n){cout << n << endl;}
template <typename T>
void cosp(const T n){cout << n << ' ';}
void coVec(const Vec &v){for(ll i : v) cosp(i); cout << endl;}
void sonic(){ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);}
void setp(ll n){cout << fixed << setprecision(n);}
const ll INF = 1e9+1;
const ll LINF = 1e18+1;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const double PI = acos(-1);
const double EPS = 1e-9;

int main(void){
	ll n;
	cin >> n;
	ll a, cnt = 0;
	rep(i, n){
		cin >> a;
		if(a == cnt+1) cnt++;
	}
	if(cnt) co(n-cnt);
	else co(-1);

	return 0;
}


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

using namespace std;

int c2(int n){
    if(n < 2) return 0;
    return (n-1)*n/2;
}

void solve(){
    int i,j;
    string str;
    cin >> i >> j;
    long long ans = 0;
    ans += c2(i);
    ans += c2(j);
    cout << ans << endl;
}

int main(){
    solve();
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma warning (disable:4996)

using namespace std;
using ll = long long;
using LL = ll;
using ull = unsigned long long;
using uLL = ull;
#define clean_0(A) memset((A),0,sizeof(A))
#define clean_1(A) memset((A),-1,sizeof(A))
#define For(i,a,b) for(int (i)=(a);(i)<=b;++(i))
#define Max_(a,b) ((a)>=(b)?(a):(b))
#define Min_(a,b) ((a)<=(b)?(a):(b))
template<typename T>
inline T Max(T a, T b) { return a >= b ? a : b; }
template<typename T>
inline T Min(T a, T b) { return a <= b ? a : b; }

constexpr int INF = 0x7F7F7F7F;
constexpr double eps = 1e-9;

constexpr ll mod1 = 197;
constexpr ll mod2 = 19260817;
constexpr ll mod3 = ll(1e8) + 7;
constexpr ll mod4 = ll(1e9) + 7;;
constexpr ll mod5 = 998244353;
constexpr int mod = mod4;

constexpr int maxn = int(3e5) + 1;
constexpr int MAXN = maxn;
namespace io {

#define in(a) (a=read())
#define out(a) write(a)
#define outn(a) (out(a),putchar('\n'))

#define I_int  int
	inline I_int read() {
		I_int x = 0, f = 1; char c = getchar();
		while (c < '0' || c > '9') { if (c == '-') f = -1; c = getchar(); }
		while (c >= '0' && c <= '9') { x = x * 10 + c - '0'; c = getchar(); }
		return x * f;
	}
	template<typename T>
	bool scan_d(T& ret)
	{
#define p(x) ((x)>='0'&&(x)<='9')
		int c; int sgn;
		if (c = getchar(), c == EOF)return false;
		while (c != '-' && !p(c))c = getchar();
		sgn = (c == '-') ? -1 : 1;
		ret = (c == '-') ? 0 : c - '0';
		while (c = getchar(), p(c))ret = ret * 10 + c - '0';
		ret *= sgn;
		return true;
#undef p
	}
	char F[200];
	template<typename T>
	inline void write(T x) {
		if (x == 0) { putchar('0'); return; }
		auto tmp = x > 0 ? x : -x;
		if (x < 0) putchar('-');
		int cnt = 0;
		while (tmp > 0) {
			F[cnt++] = tmp % 10 + '0';
			tmp /= 10;
		}
		while (cnt > 0) putchar(F[--cnt]);
	}
	void read(char* s, int Arr[], size_t n)
	{
		for (size_t i = 0; i < n; ++i)Arr[i] = strtoll(s, &s, 10);
	}
#undef I_int

}
using namespace io;



/*template<typename T>
constexpr T _gcd(T a, T b)
{
	return b ? _gcd(b, a % b) : a;
}
template<typename T>
constexpr T combinator(T n, T m, T Mod = mod - 1)
{
	m = min(m, n - m);
	T ret = 1;
	for (T i = 1; i <= m; ++i)
	{
		ret = ret * (n - m + i) / i % Mod;
	}
	return ret;
}
template<typename T>
constexpr T poww(T a, T b, T Mod = mod)
{
	T ret = 1;
	a %= Mod;
	b %= Mod - 1;
	if (b < 0)b += Mod - 1;
	while (b)
	{
		if (b & 1)ret = ret * a % Mod;
		a = a * a % Mod;
		b >>= 1;
	}
	return ret;
}

struct Combinator
{
	static constexpr int Mod = ::mod;
	static constexpr int Maxn = ::maxn;
	int dp[Maxn][Maxn];//this is C(n,m)%(mod-1)
	constexpr Combinator() :dp()
	{
		for (int i = 0; i < Maxn; ++i)
		{
			for (int j = 0; j <= i; ++j)
			{
				if (j == 0) dp[i][j] = 1;
				else if (i == j) dp[i][j] = 1;
				else dp[i][j] = (dp[i - 1][j] + dp[i - 1][j - 1]) % (Mod - 1);
			}
		}
	}
};*/


int main()
{
	int n;
	int a[200];
	while (cin >> n)
	{
		for (int i = 0; i < n; ++i)cin >> a[i];
		int sum = accumulate(a, a + n, 0);
		int average = round(double(sum) / n);
		ll ans = 0;
		for (int i = 0; i < n; ++i)ans += (a[i] - average) * (a[i] - average);
		cout << ans << endl;
	}
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

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 int inf = INT_MAX;
const int MOD = 1000000007;
const long long INF = LLONG_MAX;

// -------------------------------------------------------

ll N;

int main() {
  //
  cin >> N;
  ll vsum = 0;
  repe(i, 1, N) { vsum += i * (N - i + 1); }

  ll esum = 0;
  rep(i, 0, N - 1) {
    ll u, v;
    cin >> u >> v;
    if (u > v) {
      swap(u, v);
    }
    esum += u * (N - v + 1);
  }

  cout << vsum - esum;
}


Measured memory_bytes: 3656
#include<iostream>

using namespace std;

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

	if (a % 2 == 0 || b % 2 == 0) {
		cout << "Even" << endl;
	}
	else {
		cout << "Odd" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
constexpr array<int, 4> dx = {1, 0, -1, 0};
constexpr array<int, 4> dy = {0, 1, 0, -1};
constexpr int MOD = 100000000 + 7;

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

    int n;
    cin >> n;
    cout << n / 2 - !(n % 2) << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
    int a;
    int b;
    cin>>a>>b;
    int sum1,sum2,sum3;
    sum1=a*2-1;
    sum2=b*2-1;
    sum3=a+b;
    int sum=max(sum1,max(sum2,sum3));
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
int main() {
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    int ans = 0;
    if(a>b){
        ans += b;
    }
    else{
        ans += a;
    }
    if(c>d){
        ans += d;
    }
    else{
        ans += c;
    }
    cout << ans << endl;
}



Measured memory_bytes: 256
n, k = map(int, input().split())
a = list(map(int, input().split()))
mod = 10**9 + 7
res = 1
a.sort(reverse=True)
if a[0]<0 and k%2==1:
    for i in range(k):
        res = (res*a[i])%mod
else:
    right = n-1
    left = 0
    while k > 1:
        if a[right]*a[right-1] < a[left]*a[left+1]:
            res = (res*a[left])%mod
            left += 1
            k -= 1
        else:
            res = (res*a[right]*a[right-1])%mod
            right -= 2
            k -= 2
    if k == 1:
        res = (res*a[left])%mod

print(res)

Measured memory_bytes: 31756
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define dbg(x) cerr << #x << " = " << x << endl
#define _ << ' ' <<
using namespace std;
using ll = long long;
using vi = vector<int>;


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    int sol = 0;
    for (int i = 1; i < n; ++i)
        if (s[i] == s[i - 1])
            sol++;

    cout << min(n - 1, sol + 2 * k);
}


Measured memory_bytes: 512
H,N=map(int, input().split())
A=[]
B=[]

dp=[10**10]*(H+1)
dp[0]=0
for n in range(N):
  a,b=map(int, input().split())
  A.append(a)
  B.append(b)
    
for h in range(1,H+1):
  for n in range(N):
    if h-A[n]>=0:
      dp[h]=min(dp[h],dp[h-A[n]]+B[n])
    else:
      dp[h]=min(dp[h],B[n])
print(dp[H])

Measured memory_bytes: 42348
#include<bits/stdc++.h>
using namespace std;
int main() {
	long long n,x;
	cin >> n;
	for(int i=1; i<=sqrt(n); i++)
		if(n%i == 0)
			x = i;
	cout << x-1+n/x-1 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pp;
typedef pair<ll,ll> pll;
void read(int& x){ scanf("%d",&x); }
void read(ll& x){ scanf("%lld",&x); }
template<typename T,typename... Args>
void read(T& a,Args&... b){ read(a); read(b...); }
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define x first
#define y second
int gcd(int a, int b){ return b?gcd(b, a%b):a; }

int n;

int arr[2010];
vector<int> edge[2010];

vector<int> join_all(int init, vector<vector<int>>& vs){
    vector<int> ret;
    priority_queue<pp> pq;
    if(init != -1) ret.pb(init);
    int n=vs.size();
    for(int i=0; i<n; ++i){
        reverse(all(vs[i]));
        pq.push(pp{vs[i].back(), i});
        vs[i].pop_back();
    }
    while(pq.size()){
        int a, b; tie(a, b)=pq.top(); pq.pop();
        ret.pb(a);
        if(vs[b].size()) pq.push(pp{vs[b].back(), b}), vs[b].pop_back();
    }
    return ret;
}

bool vis[2010];
bool vis_dfs[2010];
int par[2010];

vector<int> comp;
void dfs(int x){
    vis_dfs[x]=1;
    comp.pb(x);
    for(int y:edge[x]) if(!vis[y] && !vis_dfs[y]) dfs(y);
}

vector<int> dfs2(int x){
    vis_dfs[x]=1;
    vis[x]=1;
    vector<vector<int>> cv;
    for(int y:edge[x]) if(!vis[y] && !vis_dfs[y]){
        cv.pb(dfs2(y));
    }
    return join_all(arr[x], cv);
}

vector<int> work_comp(int x){
    comp.clear(); dfs(x);
    for(int a:comp) vis_dfs[a]=0;
    int k=comp.size(), mi=comp[0];
    for(int i=1; i<k; ++i) if(arr[mi]>arr[comp[i]]) mi=comp[i];
    vis[mi]=1;
    return dfs2(mi);
}

int main()
{
	read(n);
	for(int i=1; i<=n; ++i) read(arr[i]);
	
	for(int i=1; i<n; ++i) for(int j=i+1; j<=n; ++j){
        if(gcd(arr[i], arr[j])!=1){
            edge[i].pb(j);
            edge[j].pb(i);
        }
	}
	
	for(int i=1; i<=n; ++i)
        sort(all(edge[i]), [&](const int&a, const int&b){return arr[a]<arr[b]; });
	
	vector<vector<int>> vs;
	
	for(int i=1; i<=n; ++i) if(!vis[i]) vs.pb(work_comp(i));
    
    for(int x:join_all(-1, vs)) printf("%d ", x);
    return 0;
}


Measured memory_bytes: 17664
#include <bits/stdc++.h>
#define rep(i,m,n) for(int i=m;i<n;i++)
#define c(n) cin>>n
#define co(n) cout<<n<<endl
using namespace std;

int main(){
  long a,b=2,c=0,d=0,e,n,m=0;
  cin>>a>>b>>c>>d;
  int x3,x4,y3,y4;
  x3=c-d+b;
  x4=a-d+b;
  y3=d+c-a;
  y4=b+c-a;
  co(x3<<" "<<y3<<" "<<x4<<" "<<y4);
    
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i,n) for (int i=0;i<(int)(n);i++)
#define codefor int test;scanf("%d",&test);while(test--)
#define yn(ans) if(ans)printf("Yes\n");else printf("No\n")
#define YN(ans) if(ans)printf("YES\n");else printf("NO\n")
#define vector2d(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__))
#define umap unordered_map
#define uset unordered_set
using namespace std;
using ll = long long;
const int MOD=1000000007;
//入力系
void scan(int& a){scanf("%d",&a);}
void scan(long long& a){scanf("%lld",&a);}
template<class T> void scan(T& a){cin>>a;}
template<class T> void scan(vector<T>& vec){for(auto&& it:vec)scan(it);}
void in(){}
template <class Head, class... Tail> void in(Head& head, Tail&... tail){scan(head);in(tail...);}
//出力系
void print(const int& a){printf("%d",a);}
void print(const long long& a){printf("%lld",a);}
void print(const double& a){printf("%.15lf",a);}
template<class T> void print(const T& a){cout<<a;}
template<class T> void print(const vector<T>& vec){if(vec.empty())return;print(vec[0]);for(auto it=vec.begin();++it!= vec.end();){putchar(' ');print(*it);}}
void out(){putchar('\n');}
template<class T> void out(const T& t){print(t);putchar('\n');}
template <class Head, class... Tail> void out(const Head& head,const Tail&... tail){print(head);putchar(' ');out(tail...);}
//デバッグ系
template<class T> void dprint(const T& a){cerr<<a;}
template<class T> void dprint(const vector<T>& vec){if(vec.empty())return;cerr<<vec[0];for(auto it=vec.begin();++it!= vec.end();){cerr<<" "<<*it;}}
void debug(){cerr<<endl;}
template<class T> void debug(const T& t){dprint(t);cerr<<endl;}
template <class Head, class... Tail> void debug(const Head& head, const Tail&... tail){dprint(head);cerr<<" ";debug(tail...);}
ll intpow(ll a, ll b){ ll ans = 1; while(b){ if(b & 1) ans *= a; a *= a; b /= 2; } return ans; }
ll modpow(ll a, ll b, ll p){ ll ans = 1; while(b){ if(b & 1) (ans *= a) %= p; (a *= a) %= p; b /= 2; } return ans; }

int main(){
    int n,m,x,a;
    in(n);
    vector2d(int,graph,n,n,0);
    rep(i,n){
        in(a,m);
        rep(j,m){
            in(x);
            //debug(x);
            graph[a-1][x-1]=1;
        }
    }
    rep(i,n)out(graph[i]);
}


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

#define REP(i, n) for(decltype(n) i = 0; i < n; i++)

#define ALL(c)   c.begin(), c.end()
#define SORT(c)  std::sort(ALL(c))
#define RSORT(c) std::sort(ALL(c), std::greater<decltype(c)::value_type>())

using namespace std;
using ll = long long;

const int MOD  = (int)1e9 + 7;
const int INF  = (int)1e9 + 1;
const ll  LINF = (ll)1e18 + 1;

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

    int N;
    std::cin >> N;

    std::vector<int> B(N - 1);
    REP(i, N - 1) {
        std::cin >> B[i];
    }

    vector<int> A(N, 0);
    A[0] = B[0];
    REP(i, N - 1) {
        A[i] = (B[i] < A[i]) ? B[i] : A[i];
        A[i + 1] = B[i];
    }

    std::cout << accumulate(ALL(A), 0LL) << std::endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
typedef unsigned int uint;

inline static uint gl(void){
    uint x = 0;
    for(;;){
        const uint c = getchar_unlocked() - 48;
        if(c < 10){
            x = x*10 + c;
        }else{
            break;
        }
    }
    return x;
}

#define H 200000
uint v[H] __attribute__((aligned(64)));
int main(void){
    const uint h = gl();
    gl();
    const uint n = gl();
    memset(v, 0x33, sizeof(uint)*H);
    //for(uint i=0; i<H; i++){ v[i] = 0x33333333; }
    for(uint i=0; i<n; i++){
        const uint x = gl()-1;
        const uint y = gl()-1;
        v[x] = y<v[x] ? y : v[x];
    }
    uint right = 0;
    for(uint x=1; x<h; x++){
        const auto b = v[x];
        const auto r = right+1;
        if(b<r){
            printf("%d\n", x);
            return 0;
        }else if(b>r){
            right=r;
        }
    }
    printf("%d\n", h);
    return 0;
}


Measured memory_bytes: 896
#include <cstdio>
#include <vector>
#include <algorithm>
#include <iostream>
#include <array>
#include <map>
#include <cmath>

using namespace std;


int main() {
    int64_t n, m;
    cin >> n >> m;
    if (m > n) {
        int t = m;
        m = n;
        n = t;
    }
    if (m == 1) {
        cout << 1 << endl;
    } else {
        double a = 0.000001 + ceil(n / 2.0) * ceil(m / 2.0) + floor(n / 2) * floor(m / 2);
        n = a;
        cout << n << endl;
    }
}


Measured memory_bytes: 256
//#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>

using namespace std;
char str[200005];
int main() {
    //  freopen("test.in", "r", stdin);
    //  freopen("ac.txt", "w", stdout);
   int n;
   scanf("%d",&n);
   scanf("%s",str);
   int r = 0;
   for(int i=0;i<n;++i){
       r+=(str[i]=='R');
   }
   int ans =0 ;
   for(int i=0;i<r;++i){
       ans+=(str[i]=='W');
   }
   printf("%d",ans);
}


Measured memory_bytes: 3968
import java.util.Scanner;

//20180510
//04

public class Main {
    public static void main(String[] args){
		Scanner scanner = new Scanner(System.in);
		String[] list = {"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"};
		int[] count = new int[list.length];

		while (scanner.hasNextLine()) {
			String str = scanner.nextLine();
			char[] cha = str.toCharArray();

			for(int i = 0;i < cha.length;i++) {
				for(int j = 0;j < list.length;j++) {
					String up = String.valueOf(Character.toUpperCase(cha[i]));
					String lo = String.valueOf(Character.toLowerCase(cha[i]));
					if(list[j].equals(up) || list[j].equals(lo)) {
						count[j]++;
					}
				}
			}
		}
		for(int j = 0;j < list.length;j++) {
			System.out.printf("%s : %d\n",list[j],count[j]);
		}
		scanner.close();
    }
}


Measured memory_bytes: 29828
// C.

#include <iostream>
#include <cstdio>
#include <algorithm>

using namespace std;

int main(int argc, char *argv[]) {
  int n;
  cin >> n;
	long long t = 0, x = 0, y = 0;
  bool ans = true;
  for (int i = 0; i < n; ++i) {
    long long nt, nx, ny;
    cin >> nt >> nx >> ny;
    long long dt = nt - t, dx = abs(nx - x), dy = abs(ny - y);
    dt -= (dx + dy);
    if (dt < 0 || (dt % 2) != 0) {
      ans = false;
    }
  }
  cout << (ans ? "Yes" : "No") << endl;
	return 0;
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()

int main(void){

    int x, y, z;
    cin >> x >> y >> z;

    swap(x, y);
    swap(x, z);

    printf("%d %d %d\n", x, y, z);

    return 0;
}

Measured memory_bytes: 3752
#include <iostream>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <string.h>
#include <fstream>
using namespace std;

typedef long long ll;
typedef pair<ll,ll> P;
#define REP(i,n) for(long long i = 0; i < (long long)(n); i++)
#define pb push_back // vectorに要素追加
#define INF (ll)1e18
 
const ll MAX_N = 2e5;
ll N,Q;
ll par[MAX_N];
ll p[MAX_N], x[MAX_N];
vector<ll> graph[MAX_N]; //無向 graph[頂点a][頂点b]
ll counter[MAX_N];
ll total_counter[MAX_N];
vector<ll> child[MAX_N]; //graph[親][子]
bool visited[MAX_N]; // 各頂点が通過済みか
 
void dfs(ll i){ //　親子を見つける
    visited[i] = true; // 今いるところをtrueに置き換える
    REP(j, graph[i].size()){
        ll target = graph[i][j];
        if (visited[target]==false){
            child[i].pb(target); // target edge は i edge の子
            dfs(target);
        }
    }
    return;
}
 
void dfs2(ll i, ll val_count){ // countを行う
    total_counter[i] += val_count + counter[i];
    REP(j, child[i].size()){
        ll target = child[i][j];
        dfs2(target, total_counter[i]);
    }
    return;
}
 
 

int main() {
	// 入力
    cin>>N>>Q;
    REP(i,N-1){// 無効グラフとして取得
        ll a,b;cin>>a>>b;a--;b--;
        graph[a].pb(b);
        graph[b].pb(a);
    }
    REP(i,Q){
        ll tmp_p, tmp_x;cin>>tmp_p>>tmp_x;tmp_p--;
        p[i] = tmp_p;x[i] = tmp_x;
    }

    // 解法
    // REP(i,N){//無効グラフをプリント
    //     printf("%lld: ", i);
    //     REP(j,graph[i].size()){
    //         printf("%lld ", graph[i][j]);
    //     }
    //     printf("\n");
    // }
    dfs(0); // 親子を見つけて木に変換
    // REP(i,N){//木をプリント
    //     printf("%lld: ", i);
    //     REP(j,child[i].size()){
    //         printf("%lld ",child[i][j]);
    //     }
    //     printf("\n");
    // }

    REP(i,Q){// 頂点にのみカウンターを入力
        counter[p[i]] += x[i];
    }
    dfs2(0, 0); //枝にカウンターを流していく
    // REP(i,N){//counterをプリント
    //     printf("%lld: %lld\n", i, counter[i]);
    // }
    // REP(i,N){//total_counterをプリント
    //     printf("%lld: %lld\n", i, total_counter[i]);
    // }
    // 出力
    REP(i,N)printf("%lld ", total_counter[i]);
    printf("\n");
}


Measured memory_bytes: 43776
#include <bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define x first
#define y second
using namespace std;
using ll  = long long;
#define int ll

signed main() {
#ifdef LC
    assert(freopen("input.txt", "r", stdin));
#endif
    ios::sync_with_stdio(0), cin.tie(0);

	int x;
	cin >> x;
	int k = 0;
	int s = 0;
	do {
		++k;
		s += x;
		s %= 360;
	} while (s);
	cout << k << "\n";
    return 0;
}


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

# define ll long long
# define mod 1000000007
# define MAX 100005
# define PI 3.141592653589793238                                                                                  //shortcut keys

# define pb push_back
# define mp make_pair
# define all(x) x.begin(),x.end()
# define fr(i,a,b) for(int i=a;i<=b;i++)

# define decimal(k) fixed<<setprecision(k)
# define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);        //---------------------------------------------------------------
using namespace std;

int main()
{
   string s;cin>>s;
   int cnt=0;
   fr(i,0,2){
   	if(s[i]=='R')cnt++;
   }
   if(cnt==3)cout<<3<<'\n';
   else if(cnt==0)cout<<0<<'\n';
   else if(cnt==1)cout<<1<<'\n';
   else if(s[0]==s[1]||s[1]==s[2])cout<<2<<'\n';
   else cout<<1<<'\n';
   return 0;
	 
}



Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
int cards[1000];

int main() {

    int n, m, g, b, idx = -1, sum = 0;
    scanf("%d %d", &n, &m);
    for (int i = 0; i < m; i++) {
        scanf("%d %d", &g, &b);
        if (g >= n) continue;
        cards[++idx] = g;
    }
    if (idx < 1) printf("%d\n", 0);
    else {
        sort(cards, cards+idx+1, greater<int>());
        for (int i = 0; i < idx; i++) {
            sum += n - cards[i];
        }
        printf("%d\n", sum);
    }
    return 0;
}



Measured memory_bytes: 3184
/// Code By t_bone_289 (Tushar Singh)
/// An Immature Programmer.... I'm still developing !!
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define pll pair<ll,ll>
#define fi first
#define se second
#define mp make_pair
#define pb emplace_back
#define endl '\n'
#define M 1000000007
#define error(x) cout << #x << " = " << x << endl;
#define pi 3.14159265358979323846
typedef long long ll;
typedef long double ld;
template <typename T>
void ContainerError(T &v){cout<<"{";for(auto &x:v){cout<<x<<',';}cout<<"}"<<endl;return;}
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
ll powmod(ll base,ll exp,ll MOD){ll res=1;while(exp>0){if(exp%2==1) res=(res*base)%MOD;base=(base*base)%MOD;exp/=2;}return (res%MOD);}
ll mpow(ll base,ll exp){ll res=1;while(exp>0){if(exp%2==1) res=(res*base);base=(base*base);exp/=2;}return (res);}
ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll n;
    cin>>n;
    n=n*n;
    cout<<n;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define loop(n, i) for(int i=0;i<n;i++)
#define loop1(n, i) for(int i=1;i<=n;i++)
#define rloop(n, i) for(int i=n;i;i++)
#define HERE cout << "HERE: " << __LINE__ << endl;
#define INSP(v) cout << v << " at " << __LINE__ << endl;
using namespace std;
using ll = long long;
template <class T>
using V = vector<T>;

int main() {
    int n; cin >> n;
    V<long double> A(n);
    loop (n, i) cin >> A[i];

    sort(A.begin(), A.end());
    long double acc = A[0];
    loop (n - 1, i) {
        acc = (acc + A[i + 1]) / 2.0;
    }
    cout << fixed << setprecision(10) << acc << endl;
    return 0;
}



Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <iomanip>
#include <utility>
using namespace std;

struct UnionFind {
  vector<int> data;
  UnionFind(int size) : data(size, -1) { }
  bool unionSet(int x, int y) {
    x = root(x); y = root(y);
    if (x != y) {
      if (data[y] < data[x]) swap(x, y);
      data[x] += data[y]; data[y] = x;
    }
    return x != y;
  }
  bool findSet(int x, int y) {
    return root(x) == root(y);
  }
  int root(int x) {
    return data[x] < 0 ? x : data[x] = root(data[x]);
  }
  int size(int x) {
    return -data[root(x)];
  }
};

int main(int argc, char const *argv[]) {
  int N,K,L;
  cin >> N >> K >> L;
  struct UnionFind road(N);//道路
  struct UnionFind rail(N);//鉄道
  //まず道路だけ
  for(int i = 0; i < K; i++){
    int p,q;
    cin >> p >> q;
    p -= 1;
    q -= 1;
    road.unionSet(p,q);
  }
  //次は鉄道
  for(int i = 0; i < L; i++){
    int p,q;
    cin >> p >> q;
    p -= 1;
    q -= 1;
    rail.unionSet(p,q);
  }
  std::vector<struct pair<int,int>> root(N);//firstはroad、secondはrail
  for(int i = 0; i < N; i++){
    root[i].first = road.root(i);
    root[i].second = rail.root(i);
  }
  sort(root.begin(), root.end());
  //結果表示
  for(int i = 0; i < N; i++){
    struct pair<int,int> g(road.root(i),rail.root(i));
    vector<struct pair<int,int>>::iterator up_b = upper_bound(root.begin(),root.end(),g);
    vector<struct pair<int,int>>::iterator lo_b = lower_bound(root.begin(),root.end(),g);
    cout << distance(lo_b, up_b) << " ";
  }
}


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

char nth_letter(int n)
{
    assert(n >= 0 && n <= 25);
    return "abcdefghijklmnopqrstuvwxyz"[n];
}

int main() {
   ll n;
   cin >> n;
   int len = 1;
   ll kurai = 26;
   while(n > kurai) {
      n -= kurai;
      len++;
      kurai *= 26;
   }
//   cout << "For debug -- n : " << n << ", kurai : " << kurai << endl;

   kurai /= 26;
   n--;
   rep(i,len){
      char ans = nth_letter(n/kurai);
      cout << ans;
      n %= kurai;
      kurai /= 26;
   }
   cout << endl;

}

Measured memory_bytes: 3588
def main():
	n = int(input())
	ans =0
	f=0
	for i in range(0 , n):
		t = int(input())
		if t%2!=0:
			f=1
	if f==1:
		print("first")
	else:
		print("second")
if __name__=="__main__":
	main()

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

int main()
{
	int n,t[100][26]={},ans=0;
	string s;
	cin>>n>>s;
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<26;j++)
		{
			if(i)t[i][j]+=t[i-1][j];
		}
		t[i][s[i]-'a']++;
	}
	for(int i=0;i<n-1;i++)
	{
		int sum=0;
		for(int j=0;j<26;j++)
		{
			if(t[i][j]&&t[n-1][j]-t[i][j])sum++;
		}
		ans=max(ans,sum);
	}
	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 < (int)(n); i++)
#define ll long long
int main(){
    ll x,y;
    cin >> x >> y;
    int cnt=0;
    while(x<=y){
        x *= 2;
        cnt++;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
n,k = map(int,input().split())
ans = {i+1 : 0 for i in range(n)}
for i in range(k):
    d = int(input())
    a = [int(x) for x in input().split()]
    for i in a:
        ans[i] += 1
print(len([i for i in ans.values() if i == 0]))

Measured memory_bytes: 9108
#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>

using namespace std;

int main()
{
    while (true) {
        int n;
        int r;
        cin >> n >> r;

        if (n == 0 && r == 0) {
            break;
        }

        vector<int> v(static_cast<size_t>(n));
        iota(begin(v), end(v), 1);
        reverse(begin(v), end(v));
        for (int i = 0; i < r; ++i) {
            int p;
            int c;
            cin >> p >> c;
            vector<int> t;
            copy_n(begin(v) + (p - 1), c, back_inserter(t));
            copy_n(begin(v), (p - 1), back_inserter(t));
            copy(begin(v) + (p - 1) + c, end(v), back_inserter(t));
            v = t;
        }
        cout << v[0] << endl;
    }
}

Measured memory_bytes: 2984