akhauriyash/Code-Regression huggingface dataset:
#import itertools
#import fractions
#import numpy as np
#mod = 10**4 + 7
"""def kiri(n,m):
  r_ = n / m
  if (r_ - (n // m)) > 0:
    return (n//m) + 1
  else:
    return (n//m)"""
 
# Written by NoKnowledgeGG @YlePhan
 
import math
#mod = 10**9+7
 
 
 
def main():
  a,b = map(str,input().split())
  tmp = ""
  tmp += a
  tmp += b
  if math.sqrt(int(tmp)) == int(math.sqrt(int(tmp))):
    print('Yes')
  else:
    print('No')
if __name__ == '__main__':
  main()

Measured memory_bytes: 3060
# include <bits/stdc++.h>
# define ll int64_t
# define rep(i,n) for(ll i=0;i<n;i++)
# define rrep(i,n) for(ll i=1;i<=n;i++)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define mod 1000000007
# define vec vector
#define dump(x) cerr<<#x<<"="<<x<<endl

using namespace std;

bool compare_by_b(pair<string,ll> a,pair<string,ll> b){
    if(a.second != b.second) return a.second<b.second;
    else return a.first<b.first;
}

bool my_compare(pair<string,ll> a,pair<string,ll> b){
    
    if(a.first != b.first) return a.first<b.first;
    if(a.second != b.second) return a.second>b.second;
    else return true;
}

ll factorial(ll n){
    ll x=1;
    rrep(i,n) x*=i;
    return x;
}

ll gcd(ll a,ll b)
{
   if (a%b == 0) return(b);
   else return(gcd(b,a%b));
}

ll lcm(ll a,ll b)
{
   return a/gcd(a,b)*b;
}

ll modinv(ll a,ll m) {
    ll b=m,u=1,v=0;
    while(b){
        ll t=a/b;
        a-=t*b; swap(a,b);
        u-=t*v; swap(u,v);
    }
    u%=m;
    if (u<0) u+=m;
    return u;
}

ll modpow(ll a,ll n,ll mod1) {
    ll res=1;
    while(n>0){
        if(n&1) res=res*a%mod1;
        a = a*a%mod1;
        n >>= 1;
    }
    return res;
}


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll n,sum=1;
    cin>>n;
    
    rrep(i,n) sum = sum * i % mod;
    
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
 
typedef long long ll;
 
int main() {
    int N, M;
    string S;
    cin >> N >> M >> S;
    vector<int> ans(0);
    while (N > 0) {
        bool f = false;
        for (int i = M; i > 0; i--) {
            if (i > N) continue;
            if (S[N - i] == '0') {
                ans.push_back(i);
                N -= i;
                f = true;
                break;
            }
        }
        if (!f) {
            cout << "-1\n";
            return 0;
        }
    }
    int n = ans.size();
    rep(i, n) {
        cout << ans[n - 1 - i];
        if (i == n - 1) cout << endl;
        else cout << " ";
    }
}

Measured memory_bytes: 1144
/// CommentaryAC

#include <iostream>
using namespace std;
int N;
int A[210];
int main(){ 
    cin >> N;
    for (int i=0;i<N;++i) cin >> A[i];
    int res = 0;
    while (true){
        bool exist_odd = false;
        for (int i=0;i<N;++i){
            if (A[i]%2!=0) exist_odd = true;
        }
        if (exist_odd) break;
        for (int i=0;i<N;i++){
            A[i] /= 2;
        }
    ++res;
    }


    cout << res << endl;
}

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

using i64 = int64_t;

int main(){
    int n;
    cin >> n;
    int ans = 0, a = 0, b = 0, ab = 0;
    for(int i=0;i<n;++i){
        string s;
        cin >> s;
        for(int j=0;j<s.size()-1;++j){
            if(s[j] == 'A' && s[j+1] == 'B')ans++;
        }
        if(s.back() == 'A' && s[0] != 'B')a++;
        if(s[0] == 'B' && s.back() != 'A')b++;
        if(s.back() == 'A' && s[0] == 'B')ab++;
    }

    ans += max(0, ab - 1);
    if(ab > 0){
        if(a>0){
            ans++;
            a--;
        }
        if(b>0){
            ans++;
            b--;
        }
    }
    ans += min(a, b);

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
int main(){
    string S,T;
    cin>>S>>T;
    int ans=10000000;
    for(int i=0;i<=S.size()-T.size();i++){
        int cou=0;
        for(int j=0;j<T.size();j++){
            if(S[i+j]!=T[j])cou++;
        }
        ans=min(ans,cou);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3260
#include <iostream>
using namespace std;
int main()
{
	long long n, a, b, c, d, e;
	cin >> n >> a >> b;
	c = n / (a + b);
	d = c * a;
	e = n % (a + b);
	if(e<a)
		cout << d + e << endl;
	else
		cout << d + a << endl;
}


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

const long long mod = 998244353;
int n, s; long long d[3030], a;

int main()
{
	cin >> n >> s;

	for (int i = 1; i <= n; i++){
		int x; cin >> x;
		if (x > s) continue;

		a = (a + d[s - x] * (n - i + 1)) % mod;
		if (x == s) a = (a + i * (n - i + 1)) % mod;

		for (int j = s - x; j > 0; j--) d[j + x] = (d[j + x] + d[j]) % mod;
		d[x] = (d[x] + i) % mod;
	}
	printf ("%lld\n", a);

	return 0;
}

Measured memory_bytes: 3224
#include <bits/stdc++.h>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph= vector<vector<int>>; 
#define rep(i,n) for (ll i=0; i < (n); ++i)
#define rep2(i,n,m) for(ll i=n;i<=m;i++)
#define rep3(i,n,m) for(ll i=n;i>=m;i--)
#define pb push_back
#define eb emplace_back
#define ppb pop_back
#define mpa make_pair
const ll INF=1e18 ;
inline void chmax(ll& a,ll b){a=max(a,b);}
inline void chmin(ll& a,ll b){a=min(a,b);}
 
int main(){
   int a,b,c,d,e ;cin>>a>>b>>c>>d>>e ;
   cout<<c*60+d-(a*60+b)-e<<endl ;
    return 0;
  }

Measured memory_bytes: 3616
from collections import deque
H, W = map(int, input().split())
N = int(input())
a = list(map(int, input().split()))
queue = deque([])
ans = [[0] * W for _ in range(H)]

for i in range(N):
    queue.extend([i + 1] * a[i])

x, y = 0, 0
direction = True
while queue:
    ans[x][y] = queue.popleft()
    if direction:
        if 0 <= y < W - 1:
            y += 1
        else:
            x += 1
            direction = False
    else:
        if 0 < y <= W - 1:
            y -= 1
        else:
            x += 1
            direction = True

for i in ans:
    print(' '.join(map(str, i)))

Measured memory_bytes: 3956
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

func main() {
	number := nextInt()
	cnt := number * number * number
	fmt.Println(cnt)
}


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

using namespace std;
typedef long long ll;

#define INF (long long)(1e9+7)
#define REP(i,n) for(ll i = 0; i < n; i++)
#define REP1(i,n) for(ll i = 1; i <= n; i++)

int main(void)
{
    int N;
    ll res = 1;
    cin >> N;
    REP1(i, N) res = (res * i) % INF;
    cout << res << endl;
}


Measured memory_bytes: 256
from collections import deque
k = int(input())


def generate_lunlun(x):
    d = int(x) % 10
    if d != 0:
        yield x+str(d-1)
    yield x+str(d)
    if d != 9:
        yield x+str(d+1)


d = deque([str(i) for i in range(1, 10)])
for _ in range(k):
    x = d.popleft()
    for y in generate_lunlun(x):
        d.append(y)
print(x)


Measured memory_bytes: 17012
private const val MOD = 1000000007L

private fun modComb(n: Long, k: Long, m: Long): Long {
    if (n < k) return 0L
    val kk = Math.min(k, n - k)

    var n1 = 1L
    for (i in 1..kk) {
        n1 *= (n - i + 1)
        n1 %= m
    }

    var n2 = 1L
    for (i in 1..kk) {
        n2 *= i
        n2 %= m
    }

    return n1 * modInv(n2, m) % m
}

private fun modInv(n: Long, m: Long): Long = modPow(n, m - 2, m)

private fun modPow(base: Long, p: Long, m: Long): Long = when {
    p == 0L -> 1L
    p == 1L -> base
    p % 2L == 0L -> modPow(base, p / 2L, m).let { it * it % m }
    else -> base * modPow(base, p - 1L, m) % m
}

fun main(args: Array<String>) {
    val (n, a, b) = readLine()!!.split(" ").map { it.toLong() }
    val all = modPow(2L, n, MOD) - 1L

    val nCa = modComb(n, a, MOD)
    val nCb = modComb(n, b, MOD)
    val tmp = (nCa + nCb) % MOD

    if (all < tmp) {
        println((all - tmp) % MOD + MOD)
    } else {
        println(all - tmp)
    }
}

Measured memory_bytes: 37984
import sys
input = sys.stdin.readline


def main():
    N = int(input())
    K = int(input())
    X = list(map(int, input().split()))
    
    ans = 0
    for x in X:
        ans += 2 * min(abs(x), abs(x-K))
    print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::{Write, BufWriter};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, [ $t:tt ]) => {{
        let len = read_value!($next, usize);
        (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    }};

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused)]
macro_rules! debug {
    ($($format:tt)*) => (write!(std::io::stderr(), $($format)*).unwrap());
}
#[allow(unused)]
macro_rules! debugln {
    ($($format:tt)*) => (writeln!(std::io::stderr(), $($format)*).unwrap());
}

fn solve() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (write!(out,$($format)*).unwrap());
    }
    input! {
        h: i64, w: i64, n: i64,
    }
    let m = max(h, w);
    puts!("{}\n", (n + m - 1) / m);
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


Measured memory_bytes: 8572
N = int(input())
Ps = []
for n in range(N):
    p = int(input())
    Ps.append(p)

sort_Ps =  sorted(Ps)[::-1]
sum = sort_Ps[0] // 2
for p in range(1,N):
    sum += sort_Ps[p]

print(int(sum))

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

int main(){
  int N;
  cin >> N;
  vector<int> A(N+1);
  for(int i = 0; i < N+1; ++i){
    cin >> A.at(i);
  }

  long ans = 0, sum = 0;
  for(int i = 0; i < N+1; ++i){
    sum += A.at(i);
  }

  long node = 1;
  for(int i = 0; i < N+1; ++i){
    ans += node;
    node = (node - A.at(i)) * 2;
    sum -= A.at(i);
    node = min(node, sum);
    if(node < 0){
      ans = -1;
      break;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3796
N,K=map(int,input().split())
A=list(map(int,input().split()))

ans=[]
judge={}
j=0 #A進み
while A[j] not in judge.keys() or judge[A[j]]!=2:
    ans.append(A[j])
    if A[j] not in judge.keys():
        judge[A[j]]=0
    judge[A[j]]+=1
    j=A[j]-1

st=ans.index(A[j])

if st<K:
    ans=ans[st:]
    K-=st
    l=len(ans)
    #print(ans)
    print(ans[K%l-1])
else:
    print(ans[K-1])

Measured memory_bytes: 35412
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<set>
#include<queue>
#include<stack>
#include<bitset>
#include<functional>
#include<map>
#include<iomanip>
#include<limits>
#include<unordered_set> 
#include<cmath>
using namespace std;
//long long p = 998244353;
long long p = 1000000007;
#define int long long
#define vel vector<long long>
#define vvel vector<vel>
#define rep(i,n) for(int i=0;i<n;i++)
#define sor(v) sort(v.begin(),v.end())
#define mmax(a,b) a=max(a,b)
#define mmin(a,b) a=min(a,b)
#define mkp make_pair
#define pin pair<int,int>
#define qin pair<pin,int>
#define V vector
#define Endl endl
#define veb vector<bool>
#define fcout cout << fixed << setprecision(15)
#define rev(s) reverse(s.begin(),s.end())
#define lower(h,val) lower_bound(h.begin(),h.end(),val)-h.begin()
#define upper(h,val) upper_bound(h.begin(),h.end(),val)-h.begin()
int max_kai = 150000;
vel kai(max_kai, 1);
vel inv_kai;
int rui(int a, int n, int mod) {
    if (n == 0) { return 1 % mod; }
    int x = rui(a, n / 2, mod);
    x *= x; x %= mod;
    if (n % 2 == 1) { x *= a; x %= mod; }
    return x;
}
vel pa;
int root(int x) {
    if (pa[x] == -1) { return x; }
    int ans = root(pa[x]); pa[x] = ans;
    return ans;
}
void marge(int x, int y) {
    x = root(x);
    y = root(y);
    if (x != y) { pa[x] = y; }
}
int gcd(int x, int y) {
    if (x < y) { return gcd(y, x); }
    if (y == 0) { return x; }
    return gcd(y, x % y);
}
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
vel uni(vel x) {
    if (x.size() == 0) { return x; }
    sor(x);
    int n = x.size();
    vel ans(1, x[0]);
    for (int j = 1; j < n; j++) {
        if (x[j - 1] != x[j]) { ans.push_back(x[j]); }
    }
    x = ans;
    return x;
}
void pr(vel& v) {
    int n = v.size();
    if (n != 0) {
        cout << v[0];
        rep(i, n - 1) {
            cout << " " << v[i + 1];
        }
        cout << endl;
    }
}
signed main(){
    double a, b, p, q, r;
    cin >> a >> b >> p >> q >> r;
    double st = p * b;
    st -= q * (b - a);
    st /= (q+r);
    fcout << st+b << endl;
    return 0;
}



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

#define int long long
using ll = long long;
using ld = long double;
using intpair = pair<int, int>;
using intmap = map<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
const int MOD = 1e9 + 7;
inline int mod(ll a, int m = MOD) { return (a % m + m) % m; }
inline bool bit(ll b, ll i) { return b & (1 << i); }
inline ll ceiv(ll a, ll b) { return (a + b - 1) / b; }
// struct Fast {Fast(){cin.tie(0);ios::sync_with_stdio(0);}} fast;

#define debug(x) cerr << #x << ": " << x << '\n'
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()

signed main(){
    int n;
    string s;
    cin >> n >> s;
    
    int l = 0, r = n-1, ans = 0;
    while(true){
        while(s[l] == 'R' && l < r) l++;
        while(s[r] == 'W' && l < r) r--;
        if(l == r) break;
        swap(s[l], s[r]);
        ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3748
PRIME = 10 ** 9 + 7
n = int(input())
a = list(map(int, input().split()))

b = [0 for i in range(n - 1)]
b[0] = a[0]

for i in range(1, n - 1):
  b[i] = (b[i - 1] + a[i]) % PRIME

ans = 0
for i in range(n - 1):
  ans += (b[i] * a[i + 1]) % PRIME
  ans %= PRIME

print(ans)

Measured memory_bytes: 31432
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

#define MOD 1000000007LL

class UnionFind{
  int n;
  vector<int> data;
public:
  UnionFind(int _n):n(_n),data(_n,-1){}
  bool link(int a, int b){
    int ra=find_root(a);
    int rb=find_root(b);
    if(ra!=rb){
      if(data[rb]<data[ra]) swap(ra,rb);
      data[ra]+=data[rb];
      data[rb]=ra;
    }
    return (ra!=rb);
  }
  bool check(int a, int b){
    return (find_root(a)==find_root(b));
  }
  int find_root(int a){
    return ((data[a]<0)?a:(data[a]=find_root(data[a])));
  }
};

ll mod_pow(ll x, ll n, ll mod){
  ll res = 1;
  while(n>0){
    if(n&1) res = res*x%mod;
    x = x*x%mod;
    n >>= 1;
  }
  return res;
}

struct ST {
  int i;
  int src, dst;
  ll weight;
  ll mst;
  ST(){}
  ST(int i, int src, int dst, ll weight):i(i),src(src),dst(dst),weight(weight),mst(-1){}
};
bool operator<(const ST& a, const ST& b){
  return a.weight > b.weight;
}

int N, M;
ll X;
ST edges[2005];


ll calc(int a){
  priority_queue<ST> que;
  rep(i,M){
    if(i == a) continue;
    que.push(edges[i]);
  }
  UnionFind uf(N);
  ll X = 0;
  int cnt = 0;
  {
    ST st = edges[a];
    uf.link(st.src, st.dst);
    X += st.weight;
    cnt++;
  }
  
  while(cnt < N-1){
    ST st = que.top(); que.pop();
    if(uf.check(st.src, st.dst)) continue;
    uf.link(st.src, st.dst);
    X += st.weight;
    cnt++;
  }
  return X;
}


map<ll,int> memo;
ll f(ll X){
  ll cnt = 0;
  FOR(it,memo){
    if(it->first <= X) cnt += it->second;
  }

  if(cnt == 0) return mod_pow(2, M, MOD);
  return mod_pow(2, M-cnt+1, MOD);
}

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

  rep(i,M){
    int u, v;
    ll w;
    cin >> u >> v >> w;
    u--; v--;
    edges[i] = ST(i,u,v,w);
  }


  ll mn = 1e18;
  rep(i,M){
    ll W = calc(i);
    edges[i].mst = W;
    mn = min(mn, W);
    memo[W]++;
  }
  
  if(mn > X){
    cout << 0 << endl;
  }
  else{
    ll ans = (f(X-1) - f(X) + MOD)%MOD;
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 556
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
using namespace std;

int main(){

    int r; cin >> r;

    cout << 3 * r * r << endl;

    return 0;
}

Measured memory_bytes: 256
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn main() {
    let n = read_vec::<usize>();
    let v = read_vec::<i32>();
    let mut v2 = v.clone();
    v2.sort();

    let mut d = 0;
    for i in 0..n[0] {
        if v[i] != v2[i] {
            d += 1;
        }
    }

    if d == 0 || d == 2 {
        println!("YES");
    } else {
        println!("NO");
    }
}


Measured memory_bytes: 4352
//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

//

fn eval(p: &[(i32, i32)]) -> f64 {
    let mut ans = 0.0f64;
    let mut now = (0i32, 0i32);
    let mut b = 0f64;
    for &(x, y) in p {
        let dx = (x - now.0) as f64;
        let dy = (y - now.1) as f64;
        let (dx, dy) = (dx * b.cos() + dy * b.sin(), -dx * b.sin() + dy * b.cos());
        let c = (dx / (dx * dx + dy * dy).sqrt()).acos();
        ans += c;
        now = (x, y);
        if dy > 0.0 {
            b += c;
        } else {
            b -= c;
        }
    }
    ans
}

fn enumerate(k: usize, p: &mut [(i32, i32)]) -> f64 {
    let n = p.len() - 1;
    if k >= n {
        return eval(&p);
    }
    let mut ans = enumerate(k + 1, p);
    for i in (k + 1)..n {
        p.swap(k, i);
        let v = enumerate(k + 1, p);
        if v < ans {
            ans = v;
        }
    }
    let v = p[k];
    for i in (k + 1)..n {
        p[i - 1] = p[i];
    }
    p[n - 1] = v;
    ans
}

fn run() {
    input! {
        n: usize,
        p: [(i32, i32); n],
    }
    let mut p = p;
    p.push((0, 0));
    let ans = enumerate(0, &mut p);
    println!("{:.10}", ans / std::f64::consts::PI * 180.0);
}

fn main() {
    run();
}



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

public class hello
{
    public static void Main()
    {
        var a = new List<int>();
        var a2 = new List<int>();
        var b = new List<int>();
        var b2 = new List<int>();
        var s = Console.ReadLine().Trim();
        for (int i = 0; i < s.Length; i++)
        {
            if (i % 2 == 0) { a.Add(int.Parse(s[i].ToString())); a2.Add(int.Parse(s[i].ToString())); }
            else if (s[i] == '+') { b.Add(0); b2.Add(0); }
            else { b.Add(1); b2.Add(1); } 
        }
        var norm = getNomal(a, b);
        var left = getFromLeft(a2, b2);
        var bob = int.Parse(Console.ReadLine().Trim());
        string res;
        if (bob == norm && bob != left) res = "M";
        else if (bob != norm && bob == left) res = "L";
        else if (bob == norm && bob == left) res = "U";
        else res = "I";
        Console.WriteLine(res);
    }
    public static int getFromLeft(List<int> a, List<int> b)
    {
        while (true)
        {
            if (a.Count() == 1) return a[0];
            if (b[0] == 0) a[0] += a[1];
            else a[0] *= a[1];
            a.RemoveAt(1);
            b.RemoveAt(0);
        }
    }
    public static int getNomal(List<int> a, List<int> b)
    {
        while (true)
        {
            if (b.Sum() == 0) return a.Sum();
            for (int i = 0; i < b.Count(); i++)
                if (b[i] == 1)
                {
                    a[i] *= a[i + 1];
                    a.RemoveAt(i + 1);
                    b.RemoveAt(i);
                }
        }
    }
}


Measured memory_bytes: 8124
#include <iostream>
#include <utility>
#include <stdio.h>
#include <math.h>
#include <algorithm>
#define llint long long
#define mod 998244353
#define eps 1e-8

using namespace std;

llint n;
llint x[1000005];

llint modpow(llint a, llint n)
{
	if(n == 0) return 1;
	if(n % 2){
		return ((a%mod) * (modpow(a, n-1)%mod)) % mod;
	}
	else{
		return modpow((a*a)%mod, n/2) % mod;
	}
}

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n;
	for(int i = 1; i <= n; i++) cin >> x[i];
	
	llint ans = 0;
	for(int i = 1; i <= n; i++){
		llint tmp = modpow(2, n-i);
		tmp *= modpow(x[i]+1, i-1) * x[i] % mod, tmp %= mod;
		ans += tmp, ans %= mod;
	}
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 10896
#coding:utf-8
#1_4_C 2015.3.29
while True:
    data = input().split()
    if data[1] == '?':
        break
    elif data[1] == '+':
        print(int(data[0]) + int(data[2]))
    elif data[1] == '-':
        print(int(data[0]) - int(data[2]))
    elif data[1] == '*':
        print(int(data[0]) * int(data[2]))
    elif data[1] == '/':
        print(int(data[0]) // int(data[2]))

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

int main(){
	int a1, a2, a3;
	cin >> a1 >> a2 >> a3;
	if( (a1+a2+a3) > 21 ){
		cout << "bust" << endl;
	}
	else{
		cout << "win" << endl;
	}
}


Measured memory_bytes: 3592
#include <iostream>

using namespace std;

int main(){
    int x1,y1,x2,y2;
    int x3,y3,x4,y4;
    cin >> x1 >> y1 >> x2 >> y2;
    
    int dx = x2 - x1, dy = y2 - y1;
    int x = x2, y = y2;
 
    for(int i = 0; i < 2; i++){
        int _dx = -dy;
        int _dy = dx;
        dx = _dx;
        dy = _dy;
 
        x = x + dx;
        y = y + dy;
 
        cout << x << " " << y;
        if (i == 0) printf(" ");
        else printf("\n");
    }
}

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

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

    int N; cin >> N;
    vector<int> U(N), V(N);
    bool flag = false;
    int X, Y; cin >> X >> Y;
    int b = (abs(X) + abs(Y)) % 2;
    U[0] = X + Y;
    V[0] = X - Y;
    for (int i = 1; i < N; i++) {
        cin >> X >> Y;
        int b2 = (abs(X) + abs(Y)) % 2;
        if (b != b2) flag = true;
        U[i] = X + Y;
        V[i] = X - Y;
    }
    if (flag) {
        cout << -1 << "\n";
        return 0;
    }

    vector<int> v;
    for (int i = 30; i >= 0; i--) v.push_back(1<<i);
    if (b == 0) v.push_back(1);
    cout << v.size() << "\n";
    cout << v.front();
    for (int i = 1; i < v.size(); i++) cout << " " << v[i];
    cout << "\n";

    for (int i = 0; i < N; i++) {
        int sumU = 0, sumV = 0;
        for (int j = 0; j < v.size(); j++) {
            if (sumU < U[i]) {
                sumU += v[j];
                if (sumV < V[i]) {
                    sumV += v[j];
                    cout << "R";
                }
                else {
                    sumV -= v[j];
                    cout << "U";
                }
            }
            else {
                sumU -= v[j];
                if (sumV < V[i]) {
                    sumV += v[j];
                    cout << "D";
                }
                else {
                    sumV -= v[j];
                    cout << "L";
                }
            }
        }
        cout << "\n";
    }
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int aHP = scanner.nextInt();
        int aPower = scanner.nextInt();
        int bHP = scanner.nextInt();
        int bPower = scanner.nextInt();
        bHP -= aPower;
        while(bHP > 0) {
            aHP -= bPower;
            if (aHP < 1) {
                System.out.println("No");
                return;
            }
            bHP -= aPower;
        }
        System.out.println("Yes");
    }
}

Measured memory_bytes: 35848
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mit map<int,int>::iterator
#define sit set<int>::iterator
#define itrm(g,x) for(mit g=x.begin();g!=x.end();g++)
#define itrs(g,x) for(sit g=x.begin();g!=x.end();g++)
#define ltype int
#define rep(i,j,k) for(ltype(i)=(j);(i)<=(k);(i)++)
#define rap(i,j,k) for(ltype(i)=(j);(i)<(k);(i)++)
#define per(i,j,k) for(ltype(i)=(j);(i)>=(k);(i)--)
#define pii pair<int,int>
#define fi first
#define se second
#define mpr make_pair
#define pb push_back
#define fastio ios::sync_with_stdio(false)
const int inf=0x3f3f3f3f,mod=1000000007;
const double pi=3.1415926535897932,eps=1e-6;
int n,mx;string s[200005];map<string,int> m;
vector<string> ans;
int main()
{
    scanf("%d",&n);
    rep(i,1,n) {
        cin>>s[i];
        m[s[i]]++;
        mx=max(mx,m[s[i]]);
    }
    rep(i,1,n) {
        if(mx == m[s[i]]){
            m[s[i]]--;
            ans.pb(s[i]);
        }
    }
    sort(ans.begin(),ans.end());
    rap(i,0,ans.size()){
        cout<<ans[i]<<'\n';
    }
    return 0;
}

Measured memory_bytes: 28404
/*

                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                    prayer
*/

// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(long long i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) {rep(_,v.size())cout<<" "<<v[_];cout<<endl;}
#define show2d(v) {rep(__,v.size())show1d(v[__]);}
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
#define yes cout<<"Yes\n"
#define no cout<<"No\n"

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)return 0;
        if(data[y]<data[x])swap(x,y);
        data[x]+=data[y],data[y]=x;
        return 1;
    }
    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)];
    }
};
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);

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

	if(n==1){
		if(m==0)cout<<"0 0 1 1"<<endl;
		else cout<<-1<<endl;
	}else{
		vi t;
		t.pb(m);
		rep(i,1<<n)if(i-m)t.pb(i);
		t.pb(m);
		for(int i=(1<<n)-1;i>=0;i--)if(i-m)t.pb(i);
		show1d(t);
	}
}


Measured memory_bytes: 4080
#include<iostream>
using namespace std;
#define sz 105

char f,g;
bool flag;
int arr[sz][sz],brr[sz],crr[sz];

int cal(int n){
    int x=0;

    for(int i=1; i<=n; i++){
        if(n%i==0)x++;
    }
    return x;

}


int main(){

    int n,m, i,j,k, x,y,z;

    cin>>n;
    x=0;
    for(i=1; i<=n; i+=2){
      if(cal(i)==8)x++;
    }
    cout<<x<<endl;



    return 0;

}

Measured memory_bytes: 3624
import qualified Data.Vector.Unboxed as VU
import qualified Data.ByteString.Char8 as B

solve :: B.ByteString -> VU.Vector Int
solve bs = 
    VU.zipWith (+)
        (VU.scanl (\a x -> step 'W' a x) 0 (VU.fromList $ B.unpack bs))
        (VU.scanr (\x a -> step 'E' a x) 0 (VU.fromList $ B.unpack bs))
    where
        step :: Char -> Int -> Char -> Int
        step c a x
            | c == x = a + 1
            | otherwise = a

main = do
    n <- readLn :: IO Int
    s <- B.getLine
    print $ VU.minimum $ solve s

Measured memory_bytes: 9852
from math import factorial

N, A, B = map(int, input().split())
V = sorted(list(map(int, input().split())), reverse=True)

print(sum(V[:A]) / A)
if V[0] == V[A - 1]:
    n = sum([1 for v in V if v == V[0]])
    print(sum([factorial(n) // factorial(r) // factorial(n - r)
               for r in range(A, min(n, B) + 1)]))
else:
    n = sum([1 for v in V if v == V[A - 1]])
    r = sum([1 for v in V[:A] if v == V[A - 1]])
    print(factorial(n) // factorial(r) // factorial(n - r))


Measured memory_bytes: 38768
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <algorithm>

using namespace std;

int main(void)
{
    long N, M;
    scanf("%ld %ld", &N, &M);

    vector<long> P(100000);
    vector<long> Y(100000);
    long i;
    for(i=0; i<M; i++) {
        scanf("%ld %ld", &(P[i]), &(Y[i]));
    }

    vector<long> J(100000);  // index in P[i]

    vector<vector<pair<long, long> > > vvpairTable(N);
    for(i=0; i<M; i++) {
        vvpairTable[P[i]-1].push_back( make_pair( Y[i], i ) );
    }

    for(i=0; i<N; i++) {
        if ( !vvpairTable[i].empty() ) {
            sort( vvpairTable[i].begin(), vvpairTable[i].end() );
            long j;
            for(j=0; j<vvpairTable[i].size(); j++) {
                J[vvpairTable[i][j].second] = j+1;
            }
        }
    }

    for(i=0; i<M; i++) {
        printf("%06d%06d\n", P[i], J[i]);
    }


    return 0;
}


Measured memory_bytes: 9344
import statistics
def main():
    N, A = int(input()), list(map(int, input().split()))
    for i in range(N):
        A[i] -= i + 1
    m = int(statistics.median(A))
    a, b = m, m + 1
    c, d = 0, 0
    for el in A:
        c += abs(el-a)
        d += abs(el-b)
    print(min(c, d))
main()

Measured memory_bytes: 27252
unittest
{
	assert( [ "2 2", "2 0", "0 0", "-1 0", "1 0" ].parse.expand.solve == "2\n1" );
	assert( [ "3 4", "10 10", "-10 -10", "3 3", "1 2", "2 3", "3 5", "3 5" ].parse.expand.solve == "3\n1\n2" );
	assert( [
		"5 5",
		"-100000000 -100000000",
		"-100000000 100000000",
		"100000000 -100000000",
		"100000000 100000000",
		"0 0",
		"0 0",
		"100000000 100000000",
		"100000000 -100000000",
		"-100000000 100000000",
		"-100000000 -100000000"
	].parse.expand.solve == "5\n4\n3\n2\n1" );
}



import std.algorithm;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto nm = input.front.split.to!( long[] );
	auto abs = new long[ 2 ][ nm[ 0 ] ];
	foreach( ref ab; abs )
	{
		input.popFront;
		ab = input.front.split.to!( long[] );
	}
	auto cds = new long[ 2 ][ nm[ 1 ] ];
	foreach( ref cd; cds )
	{
		input.popFront;
		cd = input.front.split.to!( long[] );
	}
	return tuple( abs, cds );
}

auto solve( long[ 2 ][] abs, long[ 2 ][] cds )
{
	auto anss = new long[ abs.length ];
	
	foreach( ref ans, ab; lockstep( anss, abs ) )
	{
		auto dm = long.max;
		
		foreach( i, cd; cds )
		{
			auto d = ( ab[ 0 ] - cd[ 0 ] ).abs + ( ab[ 1 ] - cd[ 1 ] ).abs;
			if( d < dm )
			{
				dm = d;
				ans = i + 1;
			}
		}
	}
	
	return anss.map!( to!string ).join( "\n" );
}


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

using namespace std;

int N[3][3];

int main(int argc, char *argv[])
{
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      cin >> N[i][j];
    }
    N[i][0] -= N[i][2];
    N[i][1] -= N[i][2];
  }

  for (int i = 0; i < 2; i++) {
    if (!(N[0][i] == N[1][i] && N[1][i] == N[2][i])) {
      puts("No");
      return 0;
    }
  }

  puts("Yes");
}


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

#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, m, n) for(int i = (int)(m); i < (int)(n); ++i)


int solution(string& S)
{
    int N = S.size();
    vector<int> num_appeared(2019, 0);  // 余り i の現れた回数
    num_appeared[0] = 1;
    int ans = 0, res = 0, digit = 1;
    for(int i = N-1; i >=0; --i){
        res = (digit*(S[i]-'0')+res) % 2019;
        digit = (10*digit) % 2019;
        ans += num_appeared[res];
        ++num_appeared[res];
    }
    return ans;
}

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

    cout << solution(S) << endl;

    return 0;
}

Measured memory_bytes: 3752
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <functional>
#include <map>

#define M 2001

long long L[M];
long long n;

using namespace std;

long long check(long long i, long long j)
{
	long long ans = L[i] + L[j] - 1;
	long long l = j + 1, r = n;
	while (l <= r)
	{
		long long mid = (l + r) / 2;
		if (L[mid] == ans)
		{
			return mid;
		}
		else if (L[mid] < ans)
			l++;
		else
			r--;
	}
	return r;
}

int main()
{
	long long tot = 0;

	cin >> n;

	for (long long i = 1; i <= n; i++)
		cin >> L[i];

	sort(L + 1, L + n + 1);

	for (long long i = 1; i <= n - 2; i++)
		for (long long j = i + 1; j <= n - 1; j++)
		{
			long long num = 0;
			long long pos = check(i, j);
			for (long long k = 1; k <= n; k++)
				if (L[pos] == L[pos + k])
					num++;
				else
					break;
			pos += num;
			tot += pos - j;
		}

	cout << tot << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <numeric>
#include <array>
#include <cmath>
#include <memory>
using namespace std;
//変数デバッグ
#define DEB(variable) cout << #variable << '=' << variable << endl

//for簡易表記(引数ミス防止)
#define FOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin); (LoopVariable) < (numberOFend); (LoopVariable)++)
#define DEFOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin)-1; (LoopVariable) >= (numberOFend); (LoopVariable)--)
#define REP(LoopVariable,numberOFend) for(int LoopVariable = 0;(LoopVariable)<(numberOFend);LoopVariable++)

constexpr long long int linf = numeric_limits<long long int>::max()-5;
constexpr int inf= numeric_limits<int>::max()-5;
constexpr long long int mod = 1000000007;

int main(){
    int a, b, c, d, e, k;
    cin >> a >> b >> c >> d >> e >> k;
    if(e-a>k){
        cout << ":(" << endl;
    }else{
        cout << "Yay!" << endl;
    }

    return 0;
}


Measured memory_bytes: 888
#include <iostream>

using namespace std;

int main(void) {
    static const unsigned int unit = 1000;

    unsigned int price = 0;
    cin >> price;
    unsigned int change = 0;
	if ((price % unit) != 0) {
        change = unit - (price % unit);
    }
    cout << change << endl;
  	return 0;
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
// type alias
typedef long long LL;
typedef pair<int,int> II;
typedef tuple<int,int,int> III;
typedef vector<int> VI;
typedef vector<string> VS;
typedef unordered_map<int,int> MAPII;
typedef unordered_set<int> SETI;
template<class T> using VV=vector<vector<T>>;
// minmax
template<class T> inline T SMIN(T& a, const T b) { return a=(a>b)?b:a; }
template<class T> inline T SMAX(T& a, const T b) { return a=(a<b)?b:a; }
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// collection
#define ALL(c) (c).begin(),(c).end()
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// stdout
#define println(args...) fprintf(stdout, ##args),putchar('\n');
// debug cerr
template<class Iter> void __kumaerrc(Iter begin, Iter end) { for(; begin!=end; ++begin) { cerr<<*begin<<','; } cerr<<endl; }
void __kumaerr(istream_iterator<string> it) { (void)it; cerr<<endl; }
template<typename T, typename... Args> void __kumaerr(istream_iterator<string> it, T a, Args... args) { cerr<<*it<<"="<<a<<", ",__kumaerr(++it, args...); }
template<typename S, typename T> std::ostream& operator<<(std::ostream& _os, const std::pair<S,T>& _p) { return _os<<"{"<<_p.first<<','<<_p.second<<"}"; }
#define __KUMATRACE__ true
#ifdef __KUMATRACE__
#define dump(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); __kumaerr(_it, args); }
#define dumpc(ar) { cerr<<#ar<<": "; FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }
#define dumpC(beg,end) { cerr<<"~"<<#end<<": "; __kumaerrc(beg,end); }
#else
#define dump(args...)
#define dumpc(ar)
#define dumpC(beg,end)
#endif
// $ cp-batch SimplifiedReversi | diff SimplifiedReversi.out -
// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG -fsanitize=address SimplifiedReversi.cpp && ./a.out

/*

 9/19/2020

 5:59-

 */

//const int MAX_N=1e6+1;
int N,Q;

void solve() {
  LL res=((LL)N-2)*((LL)N-2);
  VV<II> xs(2,{{-(N-1),N-2}});
  while(Q--) {
    int t,p; cin>>t>>p;
    --p,--t;
    int tt=1-t;
    auto i=lower_bound(ALL(xs[t]),make_pair(-p,0))-xs[t].begin();
    int x;
    if(i==SZ(xs[t])) {
      x=(-xs[tt].back().first)-1;
      xs[t].emplace_back(-p,x);
      //assert(-p>xs[t].back());
    } else {
      x=xs[t][i].second;
    }
    //dump(p,t,x);
    res-=x;
    //dumpc(xs[0]);
    //dumpc(xs[1]);
  }
  cout<<res<<endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout<<setprecision(12)<<fixed;

  cin>>N>>Q;
  solve();

  return 0;
}


Measured memory_bytes: 5192
#![allow(unused)]

use proconio::{input, fastout};
use proconio::marker::{Chars, Usize1};

macro_rules! debug {
    ($($a:expr),*) => {
        eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

#[fastout]
fn main() {
    input! {
        xs: [i64; 5],
    }

    for i in 0..5 {
        if xs[i] == 0 {
            println!("{}", i + 1);
            break
        }
    }
}


Measured memory_bytes: 2116
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long N = sc.nextLong();
        long M = sc.nextLong();
        Map<Long, Long> heightMap = new HashMap<>();
        Map<Long, List<Long>> connectMap = new HashMap<>();
        for (long i = 0; i < N; i++) {
            heightMap.put(i + 1, sc.nextLong());
            connectMap.put(i + 1, new ArrayList<>());
        }

        for (int i = 0; i < M; i++) {
            long A = sc.nextLong();
            long B = sc.nextLong();
            List<Long> aList = connectMap.get(A);
            aList.add(heightMap.get(B));
            connectMap.put(A, aList);
            List<Long> bList = connectMap.get(B);
            bList.add(heightMap.get(A));
            connectMap.put(B, bList);
        }

        sc.close();

        long result = 0;
        for (Long key : connectMap.keySet()) {
            List<Long> heighList = connectMap.get(key);
            if (heighList.isEmpty()) {
                result++;
            } else {
                Long height = heightMap.get(key);
                boolean isOK = true;
                for (long val : heighList) {
                    if (val >= height) {
                        isOK = false;
                        break;
                    }
                }
                if (isOK) {
                    result++;
                }
            }
        }

        System.out.println(result);
    }

}


Measured memory_bytes: 84876
A = str(input())
B = str(input())
C = str(input())

p = 0
while True:
    if p == 0:
        if A == "":
            print("A")
            exit()
        if A[0] == "b":
            p = 1
        elif A[0] == "c":
            p = 2
        A = A[1:]
    elif p == 1:
        if B == "":
            print("B")
            exit()
        if B[0] == "a":
            p = 0
        elif B[0] == "c":
            p = 2
        B = B[1:]
    else:
        if C == "":
            print("C")
            exit()
        if C[0] == "b":
            p = 1
        elif C[0] == "a":
            p = 0
        C = C[1:]



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

struct comp{
    bool operator()(pair<int, int> p1, pair<int, int> p2){
        if(p1.second == p2.second){
            return p1.first < p2.first; 
        }
        return p1.second < p2.second;
    }
};

int main() {
    int n;
    cin >> n;
    pair<int, int> arr[n];
    for(int i = 0; i < n; i++){
        cin >> arr[i].first >> arr[i].second;
    }
    sort(arr, arr+n, comp());
    string ans = "Yes";
    lli t = 0;
    for(auto i : arr){
        t += i.first;
        if(t > i.second){
            ans = "No";
            break;
        }
    }
    cout << ans << "\n";
}

Measured memory_bytes: 1792
def koyakusu(a, b)
  loop do
    rem = b % a
    return a if rem == 0
    b, a = a, rem
  end
end

def kobaisu(a, b)
  (a*b)/koyakusu(a, b)
end

while str = gets
  a, b = str.split(' ').map(&:to_i).sort
  puts "#{koyakusu(a, b)} #{kobaisu(a, b)}"
end

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

using namespace std;

typedef long long ll;

const ll MOD = 1000000007;
const ll INF = 1LL<<60;
//int INF = numeric_limits<int>::max();

int main(int, char**) {
	int n; cin >> n;
	vector<int> ret(n, 0);
	for (int i=0; i<n; i++) {
		int a; cin >> a;
		ret[a - 1] = i + 1;
	}
	for (int i=0; i<n; i++) cout << ret[i] << " ";
	cout << endl;
	return 0;
}

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

public class FindingMissingCards
{
    //?????????????????????????????????????????????????¶??????????????????????????????????
    static void Main(string[] args)
    {
        /*---??£?¨???¨---*/
        int i;
        int count;
        string[] buffer;
        ////S???0,H???13,C???26,D???39??¨????????°?????§???????????????????????????
        List<int> resultList = new List<int> {
            1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,
            27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52
        };
        /*---??£?¨???¨---*/

        /*????????°?????\??????????????????????????????????????????*/
        count = int.Parse(Console.ReadLine());

        string[,] inputCardList = new string[count, 2];
        for (i = 0; i < count; i++){
            buffer = Console.ReadLine().Split(' ');
            inputCardList[i,0] = buffer[0];
            inputCardList[i,1] = buffer[1];
        }

        /*?????¨???????????????????????¢???*/
        for(i = 0; i < count; i++){
            //S???0,H???13,C???26,D???39??¨????????\????????????????????????????????°?????¨??????????????????
            switch (inputCardList[i,0]){
                case "S":
                    resultList.Remove(int.Parse(inputCardList[i,1]));
                    break;
                case "H":
                    resultList.Remove(13 + int.Parse(inputCardList[i, 1]));
                    break;
                case "C":
                    resultList.Remove(26 + int.Parse(inputCardList[i, 1]));
                    break;
                case "D":
                    resultList.Remove(39 + int.Parse(inputCardList[i, 1]));
                    break;
            }
        }

        /*????????????????????????????????????????????????????????????????????§????????????????????????*/
        for (i = 0; i < resultList.Count; i++){
            switch((resultList[i] - 1) / 13) {
                case 0:
                    Console.WriteLine("S {0}", resultList[i] );
                    break;
                case 1:
                    Console.WriteLine("H {0}", resultList[i] - 13);
                    break;
                case 2:
                    Console.WriteLine("C {0}", resultList[i] - 26);
                    break;
                case 3:
                    Console.WriteLine("D {0}", resultList[i] - 39);
                    break;
            }

        }
    }
}

Measured memory_bytes: 9764