akhauriyash/Code-Regression huggingface dataset:
import sys
import math as mas

w=int(input())
n=int(input())
a=[i for i in range(1,w+1)]
for i in range(n):
	b,c=map(int,input().split(','))
	a[b-1],a[c-1]=a[c-1],a[b-1]
for i in a:print(i)

#for i in sys.stdin:
#	a,b=map(int,i.split())
#	print(gcd(a,b),lcm(a,b))

Measured memory_bytes: 7768
package main

import "fmt"

func abs(n int) int {
	if n < 0 {
		return -n
	}
	return n
}

func dax(in int) int {
	sDiff := 753
	for in > 0 {
		num := in % 1000
		x := abs(753 - num)
		if sDiff > x {
			sDiff = x
		}
		in /= 10
	}
	return sDiff
}

func main() {
	var in int
	fmt.Scan(&in)
	fmt.Println(dax(in))
}


Measured memory_bytes: 512
# -*- coding: utf-8 -*-

import math

n = int(input())
a = [input().split() for i in range(n)]

# n時間での座標(x_n,y_n)と、(n+t)時間の座標(x_(n+t), y_(n+t))との、x座標同士、y座標同士の差の絶対値の合計 S = (|x_(n+t) - x_n| + |y_(n+t) - y_n|)が、
# (1) Sがt以下
# (2) tが奇数の時Sも奇数、tが偶数の時tも偶数
# の条件を満たして入れば、可能。

def travelCheck(alpha, beta):
    timeDiff = int(beta[0]) - int(alpha[0])
    positionDiff = abs(int(beta[1]) - int(alpha[1])) + abs(int(beta[2]) - int(alpha[2]))
    flag = False
    if timeDiff >= positionDiff and (timeDiff%2 == positionDiff%2):
        flag = True
    return flag

start = ['0', '0', '0']

# positionList = []
# positionList.append(start)
# positionList.append(a)

for i in a:
    flag = travelCheck(start, i)
    start = i

if flag:
    print("Yes")
if not flag:
    print("No")


Measured memory_bytes: 32144
#include<bits/stdc++.h>
using namespace std;
#define NOT_FREE 1
#define FREE 0
int N = 8;
vector<int> row(N);
vector<int> dpos(2*N-1);
vector<int> dneg(2*N-1);
vector<int> col(N);
vector<vector<int>> init(N,vector<int>(N));
void printBoard(){
    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++){
            if(init[i][j]){
                if(row[i]!=j) return;
            }
        }
    }
    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++){
            cout << (row[i]==j?"Q":".");
        }
        cout << endl;
    }
}
void putQueen(int i){//8
    if(i==N){
        printBoard();
        return;
    }
    for(int j=0;j<=N-1;j++){
        if(col[j]==NOT_FREE||dpos[i+j]==NOT_FREE||dneg[i-j+N-1] == NOT_FREE) continue;
        //put a queen at (i,j)
        row[i] = j;
        col[j] = dpos[i+j] = dneg[i-j+N-1] = NOT_FREE;
        //try the next row; 
        putQueen(i+1);//無事おけた時
        //remove the queen at (i,j) for backtracking
        col[j] = dpos[i+j] = dneg[i-j+N-1] = FREE;
    }
}
int main(){
    for(int i=0;i<N;i++){
        row[i] = FREE,col[i] == FREE;
    }
    for(int i=0;i<2*N-1;i++){
        dpos[i] = FREE;
        dneg[i] = FREE;
    }
    int k;cin >> k;
    for(int i=0;i<k;i++){
        int r,c;cin >> r >> c;
        init[r][c] = 1;
    }

    putQueen(0);
}


Measured memory_bytes: 3168
#include <bits/stdc++.h> 
#define ll long long
#define F first
#define S second
#define FF first.first
#define FS first.second
#define pb push_back
using namespace std;
const ll N=1000006, INF=1e16, MOD=998244353;
     
ll n, q=1, a[N], b[N], c[N], m, x, y, z, X, Y, Z, o, u, h, w, mx, mn, ans=INF, Ans, k;
string s, S;
vector <ll> v[N];
pair<ll, ll> p[N];

int main(){ios_base::sync_with_stdio(false), cin.tie(0);
                    
//    cin>>q;
                        
    while(q--){ans=INF;
        
        cin>>n;n*=2;
		cout<<(double)n*3.1415;
	}
	return 0;
}

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

void fastio()
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);cout.tie(0);
  #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
  #endif
}

int freq[12*10001];

void solve()
{
	int n;cin>>n;
	int m = sqrt(n)+1;
	for(int i=1;i<12*n;i++)freq[i]=0;

	for(int x=1;x<m;x++)
		for(int y=1;y<m;y++)
			for(int z =1;z<m;z++)
				freq[x*x+y*y+z*z+x*y+y*z+z*x]++;
	for(int i=1;i<=n;i++)cout<<freq[i]<<"\n";
}

int32_t main()
{
    fastio();
        solve();
    return 0;
}

Measured memory_bytes: 4508
from collections import Counter

def solve(s):
    cs = Counter(s)
    m = len(s)
    for c in cs:
        news = list(s)
        size = len(s)
        count = 0
        while len(Counter(news[:size])) > 1:
            for i in range(size - 1):
                if news[i] != c[0] and news[i + 1] == c[0]:
                    news[i] = c[0]
            size -= 1
            count += 1
        if count < m:
            m = count
    return m

_s = input()
print(solve(_s))


Measured memory_bytes: 42348
n = int(input())
a = list(map(int, input().split()))

def f(a, sgn):
    cnt = 0
    s = 0
    for i in range(n):
        s += a[i]
        sgn *= (-1) #判定する符号は交互に変わる
        if s * sgn <= 0: #sgn一致しなければその積は負
            x = s + sgn*(-1)
            s -= x
            cnt += abs(x)
        
    return cnt
ans = min(f(a, 1), f(a, -1))
print(ans)

Measured memory_bytes: 14332
n,d=gets.split.map(&:to_i)
dots = []
n.times do
  dots << gets.split.map(&:to_i)
end
ans = 0
n.times do |i|
  ((i+1)...n).each do |j|
    dist = 0
    d.times do |di|
      dist += (dots[i][di]-dots[j][di])**2
    end
   ans += 1 if dist**(0.5) == (dist**(0.5)).to_i
  end
end

p ans

Measured memory_bytes: 1916
program sample
    implicit none
  
    integer(8) :: i,j,m,n
    real(8)::a,b
    integer(8),allocatable :: x(:),y(:)
  
    read(*,*) n ,m

    read(*,*) i,j  
    write(*,*) (n-i)*(m-j)
  
    stop
end program sample
  



Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<utility>

#define lli long long
#define all(i) i.begin(),i.end()
#define rall(i) i.rbegin(),i.rend()
#define rep0(i,j) for(int i=0;i<j;i++)
#define rep1(i,j) for(int i=1;i<=j;i++)
#define rep0d(i,j) for(int i=j-1;i>=0;i--)
#define MAX 1000000007

using namespace std;


int main() {
	int n, m;
	cin >> n >> m;
	vector<int> vec(n + 1, 1);
	int bs;
	rep1(i, m) {
		cin >> bs;
		vec[bs]=0;
	}
	rep0(i, n - 1)vec[i+2]*=(vec[i+1]+vec[i])%MAX;

	cout << vec[n];
}


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


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

    int n; cin >> n;
    int p[n]; rep(i,n) cin >> p[i];

    int ans = 0;
    rep(i,n-1){
        if(p[i]-1 == i){
            swap(p[i],p[i+1]);
            ans++;
        }
    }
    if(p[n-1] == n) ans++;
    cout << ans;
}

Measured memory_bytes: 640
#include <iostream>

int main(){
	int d;
	while(std::cin >> d){
		int sum = 0, num = (600 / d) - 1;
		for(int i = 1 ; i <= num ; ++i){
			sum += (d * (d * d * i * i));
		}
		std::cout << sum << std::endl;
	}
    return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <utility>

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define LL long long
using namespace std;

string MARCH = "MARCH";

LL compute_comb(int n_first[], int start, int n_res) {
  if (n_res == 0) return 1;
  if (5 - start < n_res) return 0;
  LL retval = 0;
  repd(i, start, 5) {
    retval += n_first[i] * compute_comb(n_first, i+1, n_res - 1);
  }
  return retval;
}

bool debug_mode = false;

int main() {
  int N;
  int n_first[5] = {};
  string S;
  cin >> N;
  rep(i, N) {
    cin >> S;
    rep(j, 5) {
      if (S[0] != MARCH[j]) continue;
      n_first[j]++;
    }
  }
  if (debug_mode) rep(i, 5) cout << n_first[i] << endl;

  LL retval = 0;
  rep(i, 3) {
    retval += n_first[i] * compute_comb(n_first, i+1, 2);
    if (debug_mode) cout << i << " " << retval << endl;
  }
  cout << retval << endl;
  return 0;
}


Measured memory_bytes: 256
# coding: utf-8

# https://atcoder.jp/contests/abc090/tasks/arc091_a
# 15:17-15:26 done


def main():
    n, m = map(int, input().split())

    if n == 1:
        if m == 1:
            return 1
        else:
            return m-2
    
    if m == 1:
        if n == 1:
            return 1
        else:
            return n-2
    
    return (n-2)*(m-2)


print(main())


Measured memory_bytes: 2940
n,m = map(int,input().split())
lis1 = list(map(int, input().split()))
ans = [1]*n

for i in range(m):
    a,b = map(int, input().split())
    a -= 1
    b -= 1
    if lis1[a] >= lis1[b]:
        ans[b] = 0
    if lis1[a] <= lis1[b]:
        ans[a] = 0

print(sum(ans))

Measured memory_bytes: 85020
#include <iostream>
#include <vector>
#include <cmath>
#include <map>
#include <algorithm>
using namespace std;

#define sz(s) (int)(s.size())
#define all(s) s.begin(), s.end()
#define ll long long
#define mkp make_pair
#define eb emplace_back

const int N = 1e6 + 9;
const int INF = 1e9 + 9;
const int mod = 1e9;
const int K = 25;
const int SZ = (1 << 17) - 1;

#define int ll


int a[N];
void solve() {
	int n;
	cin >> n;
	for (int i = 1; i <= n; ++ i) {
		cin >> a[i];
	}
	sort(a + 1, a + 1 + n);
	for (int i = 1; i < n; ++ i) {
		if (a[i] == a[i + 1]) {
			cout << "NO";
			return;
		}
	}
	cout << "YES";
}

main() {
	ios_base::sync_with_stdio(false);
	solve();
	return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <array>
#include <numeric>

using namespace std;

int main() {
  array<int,100> s;
  int n;
  while ((cin >> n) && n != 0) {
    for (int i=0; i<n; i++) cin >> s[i];
    int ssum = accumulate(s.begin(), s.begin()+n, 0);
    int smax = *max_element(s.begin(), s.begin()+n);
    int smin = *min_element(s.begin(), s.begin()+n);
    cout << (ssum-smax-smin)/(n-2) << endl;
  }
  return 0;
}

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

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

  int ans= 111;
  for(int i=1; i<=9; i++){
    if(N <= ans*i){
      ans*= i;
      break;
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include <bits/stdc++.h>
#include <vector> 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define int         long long 
#define ll          long long 
#define ld	    long double
#define pb          push_back
#define pp	    pop_back()
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define vii         vector<pii>
#define mi          map<ll,ll>
#define mii         map<pii,ll>
#define mp          make_pair
#define all(a)      (a).begin(),(a).end()
#define rall(a)     (a).rbegin(),a.rend()
#define F           first
#define S           second
#define sz(x)       (ll)x.size()
#define endl        '\n'
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define repj(j,a,b) for(ll j=a;j<b;j++)
#define lexistr(x,y)      lexicographical_compare(x.begin(),x.end(),y.begin(),y.end())
#define IOS	    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

typedef tree<ll,null_type,less<ll>,rb_tree_tag, tree_order_statistics_node_update> indexed_set;

//CONSTANTS----------------------------------
#define PI 	    3.141592653589793238462643
const ll hell=1000000007;
const ll mod=1000000007;
//function-----------------------------------
ll GCD(ll a , ll b)
{
    if(b==0)
        return a;
    else
        return GCD(b,a%b);
}
ll LCM(ll a, ll b)
{
    return a*(b/GCD(a,b));
}
bool isPrime(ll n) {
 
    if (n <= 1) return false;
    if (n <= 3) return true;
    if (n % 2 == 0 || n % 3 == 0) return false;
    for (ll i = 5; i * i <= n; i = i + 6)
        if (n % i == 0 || n % (i + 2) == 0)
            return false;
    return true;
}
ll fact(ll n)
{
    ll f=1;
    for(ll i=2;i<=n;i++)
	f=f*i;
    return f;
}
ll power(ll a,ll b)
{
  if(b==0)return 1;
  if(b==1)return a;
  ll t=power(a,b/2);
  t%=hell;
  t*=t;
  t%=hell;
  if(b%2)return (t*a)%hell;
  else
     return t;
}
//CODE------------------------------------------
ll solve()
{
	ll a,b,c,d,e,k; cin>>a>>b>>c>>d>>e>>k;
  if(e-a<=k) cout<<"Yay!";
  else cout<<":(";
  return 0;
}
//MAIN------------------------------------------
signed main(){
    IOS
    #ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
    #endif
    int t=1;
    //cin>>t;
    while(t--) {
        solve();
        cout<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <string>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;

const int M=45;
const int N=1e3+5;
int n,m,lim,tmp[M];
ll X[N],Y[N];

template <typename _Tp> inline void IN(_Tp&x) {
	char ch;bool flag=0;x=0;
	while(ch=getchar(),!isdigit(ch)) if(ch=='-') flag=1;
	while(isdigit(ch)) x=x*10+ch-'0',ch=getchar();
	if(flag) x=-x;
}

int main() {
	IN(n);
	for(int i=1;i<=n;++i) IN(X[i]),IN(Y[i]);
	bool val=abs(X[1]+Y[1])&1;
	for(int i=1;i<=n;++i)
		if((abs(X[i]+Y[i])&1)!=val) return puts("-1"),0;
	tmp[m=1]=1;
    for(int i=val;i<=30;++i) tmp[++m]=1<<i;
	printf("%d\n",lim=m);
	for(int i=1;i<=m;++i) printf("%d ",tmp[i]);puts("");
	static char ans[M];
	for(int i=1;i<=n;++i) {
		for(int j=m;j;--j) {
			if(abs(X[i])>abs(Y[i])) {
				if(X[i]>0) X[i]-=tmp[j],ans[j]='R';
				else X[i]+=tmp[j],ans[j]='L';
            } else {
				if(Y[i]>0) Y[i]-=tmp[j],ans[j]='U';
				else Y[i]+=tmp[j],ans[j]='D';
            }
		}
		printf("%s\n",ans+1);
	}
	return 0;
}

Measured memory_bytes: 256
m,d = map(int,input().split())

ans = 0
for i in range(1,m+1):
   for j in range(10, d+1):
      d1 = j // 10
      d2 = j % 10
      if d1 >= 2 and d2 >= 2 and d1 * d2 == i:
         ans += 1

print(ans)

Measured memory_bytes: 2940
#include<iostream>

using namespace std;

int main()
{
	int A, B;
	cin >> A >> B;

	if (A <= 5)
	{
		cout << 0 << endl;
	}
	else if (A <= 12)
	{
		cout << (B/2)<<endl;
	}
	else
	{
		cout << B << endl;
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <algorithm>
#include <bitset>
#include <iomanip>
#include <cstdio>
#include <new>
#include <vector>
#include <cstdlib>
#include <string>

using namespace std;

int main() {
	char str[7];

	bool flag = false;
	
	cin >> str;

	if (str[2] == str[3]) {
		if (str[4] == str[5]) {
			flag = true;
		}
	}

	if (flag) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

}

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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)
#define rrep(i, n) for(int i = ((int)n - 1); i >= 0; --i)

using ll = long long;
using ld = long double;

const ll INF = 1e18;
const int Inf = 1e9;
const double EPS = 1e-9;
const ll MOD = 1e9 + 7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
	int dx[4] = {0, 0, 1, -1};
	int dy[4] = {1, -1, 0, 0};
	int res = 0;
    int h, w;
	cin >> h >> w;
	vector<string> s(h);
	rep (i, h) cin >> s[i];
	rep (i, h) {
	  rep (j, w) {
		if (s[i][j] == '#') continue;
		rep (ii, h) {
		  rep (jj, w) {
			if (s[ii][jj] == '#') continue;
			vector<vector<int> > d(h, vector<int>(w, Inf));
			queue<pair<int, int> > q;
			q.push({i, j});
			d[i][j] = 0;
			while (!q.empty()) {
			  int x, y;
			  x = q.front().first, y = q.front().second;
			  q.pop();
			  if (x == ii && y == jj) {
				res = max(res, d[x][y]);
				break;
			  }
			  rep (k, 4) {
				int nx, ny;
				nx = x + dx[k], ny = y + dy[k];
				if (nx < 0 || ny < 0 || nx >= h || ny >= w) continue;
				if (s[nx][ny] == '#') continue;
				if (d[nx][ny] != Inf) continue;
				d[nx][ny] = d[x][y] + 1;
				q.push({nx, ny});
			  }
			}
		  }
		}
	  }
	}
	cout << res << endl;
	
    return 0;
}



Measured memory_bytes: 3672
package main

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

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024*1024), bufio.MaxScanTokenSize)
}

//func nextString() string {
//	sc.Scan()
//	return sc.Text()
//}

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

//func nextUint64() uint64 {
//	sc.Scan()
//	i, e := strconv.ParseUint(sc.Text(), 10, 64)
//	if e != nil {
//		panic(e)
//	}
//	return i
//}

func main() {
	x := nextInt()
	ans := 8

	if (x >= 400 && x <= 599) {
		ans = 8
	} else if (x >= 600 && x <= 799) {
		ans = 7
	} else if (x >= 800 && x <= 999) {
		ans = 6
	} else if (x >= 1000 && x <= 1199) {
		ans = 5
	} else if (x >= 1200 && x <= 1399) {
		ans = 4
	} else if (x >= 1400 && x <= 1599) {
		ans = 3
	} else if (x >= 1600 && x <= 1799) {
		ans = 2
	} else if (x >= 1800 && x <= 1999) {
		ans = 1
	} else {
		// do nothing
	}

	fmt.Println(ans)
}


Measured memory_bytes: 1804
INF = 10**12
N = 101


class FordFulkerson:
    def __init__(self):
        self.G = [[] for _ in range(N)]
        self.used = [False] * N

    def add_edge(self, s, t, c):
        self.G[s].append([t, c, len(self.G[t])])
        self.G[t].append([s, 0, len(self.G[s])-1])

    def dfs(self, s, t, f):
        if s == t:
            return f
        self.used[s] = True
        for i in range(len(self.G[s])):
            e = self.G[s][i]
            if not self.used[e[0]] and e[1] > 0:
                d = self.dfs(e[0], t, min(f, e[1]))
                if d > 0:
                    self.G[s][i][1] -= d
                    self.G[e[0]][e[2]][1] += d
                    return d
        return 0

    def max_flow(self, s, t):
        flow = 0
        while True:
            self.used = [False]*N
            f = self.dfs(s, t, INF)
            if f == 0:
                return flow
            flow += f

if __name__ == "__main__":
    V, E = map(int, input().split())
    ff = FordFulkerson()
    for i in range(E):
        u, v, c = map(int, input().split())
        ff.add_edge(u, v, c)
    print(ff.max_flow(0, V-1))




Measured memory_bytes: 5780
#include <cstdio>
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <set>

#define ll long long
#define pll pair<ll, ll>

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

const int INF = 1111111111;
const double EPS = 1e-9;

using namespace std;

const int N = 222222;
int a[N];
int n;

void init()
{
	cin >> n;
	rep(i, n) cin >> a[i];
}

int b[N];

void solve()
{
	int all = 0;
	rep(i, n)
	{
		all ^= a[i];
	}

	rep(i, n)
	{
		int v = all ^ a[i];
		cout << v << endl;
	}
}

int main()
{
	init();
	solve();
}


Measured memory_bytes: 3932
#include <stdio.h>

#define MAX_N 150

int main(void) {

    int n;
    int t[MAX_N];
    int m;
    int p[MAX_N];
    int x[MAX_N];
    int i;
    int time;

    time = 0;

    scanf("%d", &n);
    for(i =0; i < n; i++) {
        scanf("%d", &t[i]);
        time += t[i];
    }
    scanf("%d", &m);
    for(i = 0; i < m; i++) {
        scanf("%d %d", &p[i], &x[i]);
        time = time -t[p[i] - 1] + x[i];
        printf("%d\n", time);
        time = time +t[p[i] - 1] - x[i];
    }

    return 0;

}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <unordered_map>

using namespace std;
using ll = long long;

void _cin(){} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail){ cin >> head; _cin(forward<Tail>(tail)...); }
void _cout(){ cout << "\n"; } template <class Head, class... Tail> void _cout(Head&& head, Tail&&... tail){ cout << head; _cout(forward<Tail>(tail)...); }
int gcd(int a, int b){ return (b == 0) ? a : gcd(b, a % b); }

#define Sq(x) (x)*(x)
#define For(i, n) for(int i = 0; i < (n); i ++)
#define Rep(n) For(_, n)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) (find(Range(c), x) != c.end())
#define Search(rb, re, x) distance(rb, find(rb, re, x))
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Reverse(c) reverse(Range(c))
#define Unique(a) a.erase(unique(Range(a)), a.end())
#define Cusum(T, xs, sxs) vector<T> sxs(xs.size()+1); For(i, (int)xs.size()) sxs[i+1] = sxs[i] + xs[i]
#define Cin(T, ...) T __VA_ARGS__; _cin(__VA_ARGS__)
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinss(T, n, m, xs) Vec2(T, n, m, xs); For(i, n) For(j, m) cin >> xs[i][j]
#define Cinm(T, n, map) unordered_map<T, int> map; Rep(n){ Cin(T, x); map[x] ++; }
#define Cout(...) _cout(__VA_ARGS__)
#define Couts(xs) { for(const auto &e : xs) cout << e << " "; cout << "\n"; }
#define Coutyn(cond) Cout((cond) ? "yes" : "no")
#define CoutYn(cond) Cout((cond) ? "Yes" : "No")
#define CoutYN(cond) Cout((cond) ? "YES" : "NO")
#define vc vector
#define Mini(a, x) a = min(a, x)
#define Maxi(a, x) a = max(a, x)

constexpr int MOD = 1e9+7;

int main(void){
    Cin(int, n);
    Cin(string, s);
    
    if(s[0] == 'W'){
        Cout(0);
        return 0;
    }
    
    vc<int> d(2*n); d[0] = 0;
    for(int i = 1; i < 2*n; i ++){
        d[i] = (d[i-1] + (s[i] == s[i-1])) % 2;
    }

    int sum = 0; For(i, 2*n) sum += d[i];
    if(sum != n){
        Cout(0);
        return 0;
    }
    
    int c = 0; ll ans = 1;
    For(i, 2*n){
        if(d[i] == 0) c ++;
        else{
            ans = ans * c % MOD;
            c --;
        }
    }
    For(i, n) ans = ans * (i+1) % MOD;
    Cout(ans);
}




Measured memory_bytes: 1412
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();
// freopen("input.txt", "r", stdin);

int main() {
    int n, val;
    cin >> n;
    unordered_map<int, int> cnt;
    for(int i = 0; i < n; i++) {
        cin >> val;
        cnt[val] += 1;
    }
    int ans = 0;
    for(auto p: cnt) {
        if (p.second % 2 == 1)
            ans += 1;
    }
    cout << ans << endl;
    return 0;
}




Measured memory_bytes: 4388
#include<stdio.h>
#include<string.h>
#define max(a,b) a<b?b:a
int a[105][105],d[105][105],i,j,k,l;
char c;
int main()
{
	memset(a,-1,sizeof(a));
	memset(d,0,sizeof(d));
	for(i=j=0;;)
	{
		if(scanf("%d%c",&a[i][j],&c)==-1)
			break;
		else if(c==44)
			j++;
		else if(c==10)
			i++,j=0;
	}
	d[0][0]=a[0][0];
	for(k=1;k<i;k++)
	{
		for(j=0;a[k][j]!=-1;j++)
		{
			if(k<=i/2)
			{
				for(l=-1;l<1;l++)
					if(j+l>=0&&a[k-1][j+l]!=-1)
						d[k][j]=max(d[k][j],d[k-1][j+l]+a[k][j]);
			}
			else
			{
				for(l=0;l<2;l++)
					if(j+l>=0&&a[k-1][j+l]!=-1)
						d[k][j]=max(d[k][j],d[k-1][j+l]+a[k][j]);
			}
		}
	}
	printf("%d\n",d[i-1][0]);
	return 0;
}

Measured memory_bytes: 692
#![allow(
    non_snake_case,
    unused_variables,
    unused_assignments,
    unused_mut,
    unused_imports,
    dead_code
)]
//use proconio::fastout;
use proconio::input;
use proconio::marker::*;
//use std::collections::HashSet;
use std::cmp::*;
//use std::collections::VecDeque;

fn main() {
    input! {
      R:i32,mut G:i32,mut B:i32,K:usize
    }
    // G > R, B > G を満たせばよい。
    for _ in 0..K {
        if B <= G {
            B *= 2;
        } else if G <= R {
            G *= 2;
        } else {
            break;
        }
    }
    if B > G && G > R {
        println!("Yes");
    } else {
        println!("No");
    }
    return;
}


Measured memory_bytes: 2108
#include<bits/stdc++.h>
using namespace std; 
#define ll long long int
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>
#define INF LLONG_MAX
#define PI acos(-1)
#define MOD 1e9 + 7
#define N 1e5 + 10
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ll a,p;
  cin>>a>>p;
	cout<<((3*a)+p)/2;
}	

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){

	int n;
	cin>>n;
	int a[n];
	int b[n];
	for(int i=0;i<n;i++){
	
		cin>>a[i];
		b[a[i]-1]=i+1;
	}
	for(int i=0;i<n;i++){
	
		cout<<b[i]<<" ";
	}
	return 0;;
}


Measured memory_bytes: 4444
#include<stdio.h>

int main(void)
{
	int a,b,c;
	scanf("%d%d%d",&a,&b,&c);
	if(a>=b && a>=c)
		printf("%d",10*a+b+c);

	else if(b>=a && b>=c)
		printf("%d",10*b+a+c);

	else
		printf("%d",a+b+10*c);

	return 0;
}

Measured memory_bytes: 128
import java.util.*;
import java.io.*;

class Main {

    public static void main(String[] args) {

	final Scanner stdin = new Scanner(System.in);
	final int T = stdin.nextInt();

	for ( int i = 0; i < T; i++ ) {

	    int n = stdin.nextInt();
	    int[] up = new int[8];
	    for ( int j = 0; j < 8; j++ ) {
		up[j] = n % 10;
		n /= 10;
	    }
	    Arrays.sort( up );
	    
	    int max = 0;
	    for ( int j = 7; j >= 0; j-- ) {
		max = max * 10 + up[j];
	    }

	    int min = 0;
	    for ( int j = 0; j < 8; j++ ) {
		min = min * 10 + up[j];
	    }

	    System.out.println( max - min );	    
	}
	
    }
    
}

Measured memory_bytes: 17184
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n); i >= 0; i--)
#define REP(i, m, n) for (int i = (int)(m); i < (int)(n); i++)
#define INF 1e9
#define all(v) v.begin(), v.end()
typedef long long ll;

int main(){
  int d, g;
  cin >> d >> g;
  vector<int> p(d), c(d);
  rep(i, d) cin >> p[i] >> c[i];

  int ans = INF;
  rep(tmp, 1<<d){
    bitset<10> s(tmp);
    int sum = 0;
    int cnt = 0;
    rep(i, d){
      if(s.test(i)){
        sum += p[i]*(i+1)*100 + c[i];
        cnt += p[i];
      }
    }
    repr(i, d-1){
      if(!s.test(i)){
        for(int j=0; j<p[i] && sum<g; j++){
          sum += (i+1) * 100;
          cnt++;
        }
        break;
      }
    }
    if(sum >= g) ans = min(ans, cnt);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef pair<int,int> ii;
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >> s;
    for (int ctr1 = 0; ctr1 < s.length(); ++ctr1)
        if ((ctr1 & 1 && s[ctr1] == 'R') || ((ctr1 & 1) == 0 && s[ctr1] == 'L')) {
            cout << "No\n";
            return 0;
        }
    cout << "Yes\n";
    return 0;
}

Measured memory_bytes: 256
from collections import defaultdict

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

#a,bの最小公倍数
def lcm(a, b):
    return a * b // gcd (a, b)

def main():
    a, b, c, d = map(int, input().split())
    a -= 1
    all_data = a // c + a // d - a // lcm(c, d)
    all_data = a - all_data
    hiku = b // c + b // d - b // lcm(c, d)
    hiku = b - hiku

    print(hiku - all_data)



if __name__ == '__main__':
    main()



Measured memory_bytes: 38384
N,K=map(int,input().split())
H=list(map(int,input().split()))
dp=[0]*N

for i in range(N-1):
  A=[]
  for j in range(K):
    if i-j>=0:
      A.append(dp[i-j]+abs(H[i-j]-H[i+1]))
  dp[i+1]=min(A)

print(dp[N-1])

Measured memory_bytes: 52448
#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;

int main() {
	int L, N;
	cin >> N >> L;
	
	vector<string> dict(N);
	rep (i, N) {
		string word;
		cin >> word;
		
		dict.at(i) = word;
	}
	sort(dict.begin(), dict.end());
	rep (i, N) {
		cout << dict.at(i);
	}
	cout << endl;
	return 0;
}

	


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
A - Task Scheduling Problem
https://beta.atcoder.jp/contests/abc103/tasks/abc103_a

"""
import sys
from sys import stdin
input = stdin.readline


def solve(a1, a2, a3):
    ans = float('inf')
    ans = min(ans, abs(a2-a1) + abs(a3-a2))
    ans = min(ans, abs(a3-a1) + abs(a2-a3))
    ans = min(ans, abs(a1-a2) + abs(a3-a1))
    ans = min(ans, abs(a3-a2) + abs(a1-a3))
    ans = min(ans, abs(a2-a3) + abs(a1-a2))
    ans = min(ans, abs(a1-a3) + abs(a2-a1))
    return ans


def main(args):
    a1, a2, a3 = map(int, input().split())
    ans = solve(a1, a2, a3)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])


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

using namespace std;

typedef long long LL;
typedef pair<int , int> P2;
typedef pair<pair<int , int> , int> P3;
typedef pair<pair<int , int> , pair<int , int> > P4;
#define PB(a) push_back(a)
#define MP(a , b) make_pair((a) , (b))
#define M3P(a , b , c) make_pair(make_pair((a) , (b)) , (c))
#define M4P(a , b , c , d) make_pair(make_pair((a) , (b)) , make_pair((c) , (d)))
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define lint long long
#define ll long long
#define pq priority_queue
#define mp make_pair
#define pb push_back
#define vl vector<long long>
#define pii pair<long long,long long>
#define all(x) (x).begin(),(x).end()
#define rep(x) for(int i = 0;i < (x);i++)
#define repj(x) for(int j = 0;j < (x);j++)
#define REP(i,x) for(int (i) = 0;(i) < (x);(i)++)
#define rrep(x) for(int i = (x);i >= 0;i--)
#define mod 1000000007
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a;a=1ll*a*a;}while(b>>=1);return ans;}
int qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
long long INF = 1e10;
/************************  DEFINE  ****************************/

/************************ FUNCTION ****************************/

/************************   MAIN   ****************************/
int main(void){
    ll x,y;cin >> x >> y;
    int c = 1;
    while(x*2 <= y){
        x *= 2; c++;
    }
    cout << c << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
    char ch[1];
    char s[1];
    scanf("%s",ch);
    scanf("%s",s);
    if(ch[0]>s[0]){
        cout<<">"<<endl;
    }
    else if(ch[0]<s[0])cout<<"<"<<endl;
    else cout<<"="<<endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
    using namespace std;
     
    int main() {
      int N ;
      cin >> N;
      
      vector<long long int> x(N);
      vector<long long int> y(N);
      for(int i=0;i<N;i++){
        cin >> x.at(i) >> y.at(i);
        //cout << x.at(i) << y.at(i) << endl;
      }
      
      long long int max_x=x.at(0)-y.at(0);
      long long int min_x=x.at(0)-y.at(0);
      long long int max_y=x.at(0)+y.at(0);
      long long int min_y=x.at(0)+y.at(0);
      long long int max=0;
      
      for(int i=0;i<N;i++){
        if(max_x < x.at(i)-y.at(i)){
          max_x=x.at(i)-y.at(i);
        }
        if(min_x > x.at(i)-y.at(i)){
          min_x=x.at(i)-y.at(i);
        }
        if(max_y < x.at(i)+y.at(i)){
          max_y=x.at(i)+y.at(i);
        }
        if(min_y > x.at(i)+y.at(i)){
          min_y=x.at(i)+y.at(i);
        }
      }
      
      if(llabs(max_x-min_x)<llabs(max_y-min_y)){
        max=llabs(max_y-min_y);
      }else{
        max=llabs(max_x-min_x);
      }
      
      cout << max << endl;
      
    }

Measured memory_bytes: 6420
#include<bits/stdc++.h>
using namespace std;
bool cmp(char a,char b){
	return a>b;
}
int main(){
	char s[105],ss[105];
	cin>>s;
	cin>>ss;
	sort(s,s+strlen(s));
	sort(ss,ss+strlen(ss),cmp);
	for(int i=0;i<max(strlen(s),strlen(ss));i++){
		if(s[i]<ss[i]){
			cout<<"Yes"<<endl;
			return 0;
		}
		else if(s[i]>ss[i]){
			cout<<"No"<<endl;
			return 0;
		}
	} 
	cout<<"No"<<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;

int is_prime[300000];
int prime[300000];

int main() {
	memset(is_prime, 1, sizeof(is_prime));
	is_prime[0] = is_prime[1] = false;
	int p = 0;
	for (int i = 2; i < 300000; i++) {
		if (is_prime[i]) {
			prime[p++] = i;
			for (int j = i * 2; j < 300000; j += i)is_prime[j] = false;
		}
	}
	int n;
	while (scanf("%d", &n), n) {
		printf("%d\n", upper_bound(prime, prime + p, 2 * n) - upper_bound(prime, prime + p, n));
	}
}

Measured memory_bytes: 4476
#include <stdio.h>

int main()
{
    int N;
    int L[11];
    int max=0;
    int sum=0;
    scanf("%d", &N);
    for(int i=1; i<=N; i++) scanf("%d", &L[i]);

    for(int i=1; i<=N; i++) {
        if(max<L[i]) max=L[i];
    }

    for(int i=1; i<=N; i++) {
        sum+=L[i];
    }
    if((sum-max)<=max) printf("No");
    else printf("Yes");
}

Measured memory_bytes: 1732
#include <algorithm>
#include <iostream>
#include <unordered_map>
#include <vector>

int main(int argc, char const* argv[])
{
    int      N;
    uint32_t Y;
    std::cin >> N;
    std::cin >> Y;

    for (int i = 0; i <= N; i++) {
        for (int j = 0; j <= N - i; j++) {
            int k = N - i - j;
            if (10000 * i + 5000 * j + 1000 * k == Y) {
                std::cout << i << " " << j << " " << k << std::endl;
                return 0;
            }
        }
    }
    std::cout << "-1 -1 -1" << std::endl;
    return 0;
}


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

using namespace std;

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

	char c = getchar();
	char prevc = c;
	bool ok = 1;
	for(int i = 0; i < 3; i++) {
		c = getchar();
		if(prevc == c) ok = 0;
		prevc = c;
	}

	cout << (ok ? "Good" : "Bad");

	return 0;
}




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

int main(){
  
  ll n,W;
  cin >> n >> W;
  
  ll*w = new ll[n];
  ll*v = new ll[n];
  
  for( ll i=0 ; i<n ; i++ ){
  	cin >> w[i] >> v[i];
  }
  
  ll** dp = new ll*[2];
  
  for( ll i=0; i<2 ; i++ ){
  	dp[i] = new ll[W+1];
  	for(ll j=0 ; j<W+1 ; j++)
  		dp[i][j] = 0;
  }
  
  for(ll i=1 ; i<=n ; i++){
  	for(ll j=0 ; j<=W ; j++){
  		if(w[i-1] <= j){
  			dp[1][j] = max( dp[0][j], dp[0][j-w[i-1]] + v[i-1] );
  		}else{
  			dp[1][j] = dp[0][j];
  		}	
  	}
  	for(int k=0 ; k<=W ; k++){
  		dp[0][k] = dp[1][k];
  	}
  }
  
  cout << dp[1][W] << endl;
  return 0;
}


Measured memory_bytes: 5176
import itertools
n=int(input())
p=tuple(map(int,input().split()))
q=tuple(map(int,input().split()))

l=list(range(1,n+1))
ll=list(itertools.permutations(l,n))
pp=ll.index(p)
qq=ll.index(q)
a=pp-qq
if a<0:
  a=a*(-1)
print(str(a))

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

def sol(S):
    ret = 0
    for a in A[1:]:
        b = a
        if S * (S + b) > 0:
            b = (abs(S) + 1) * (1 if S < 0 else -1)
        if S + b == 0:
            b = b - 1 if S < 0 else b + 1
        ret += abs(b - a)
        S += b
    return ret

if A[0] == 0:
    ans = min(sol(1), sol(-1)) + 1
else:
    ans = min(sol(A[0]), sol(-1 if A[0] > 0 else 1) + abs(A[0]) + 1)
print(ans)


Measured memory_bytes: 14648
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SORT(list) sort(ALL((list)));
#define MOD 1000000007
using namespace std;
using ll = long long;
int main(){
    int n;
    cin >> n;
    map<string,int>mp;
    REP(i,n){
        string s;
        cin >> s;
        mp[s]++;
    }
    cout << "AC x " << mp["AC"] << endl;
    cout << "WA x " << mp["WA"] << endl;
    cout << "TLE x " << mp["TLE"] << endl;
    cout << "RE x " << mp["RE"] << endl;
    return 0;
}

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

int main(){
    ll n;
    cin >> n;
    ll ans = 0;
    for(ll i = 1; i*i <= n-1; i++){
        if((n-1)%i) continue;
        ans += i>1;
        ans += i!=(n-1)/i;
    }
    for(ll i = 1; i*i <= n; i++){
        if(n%i) continue;
        if(i > 1){
            ll tmp = n;
            while(tmp%i == 0)   tmp /= i;
            ans += tmp%i==1;
        }
        if(i*i == n)    continue;
        ll tmp = n, xi = n/i;
        while(tmp%xi == 0)  tmp /= xi;
        ans += tmp%xi==1;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3632
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <string.h>
#include <utility>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>

using namespace std;
typedef long long ll;

#define REP(i,n) for(int i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())

ll N;
vector<ll> a;
int main()
{
    cin >> N;
    REP(i, 3 * N) {
        ll tmp;
        cin >> tmp;
        a.push_back(tmp);
    }
    SORT(a);
    ll ans = 0;
    ll j = a.size()-1;
    ll k = 0;
    while(j > k) {
        j--;
        ans += a[j];
        j--;
        k++;
    }
    printf("%lld\n", ans);

    return 0;
}


Measured memory_bytes: 6564
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
using namespace std;


typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
	v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
	stringstream ss;
	ss << f;
	ss >> t;
}


#define REP(i,n) for(int i=0;i<int(n);++i)
#define ALL(v) (v).begin(),(v).end()
#define RALL(v) (v).rbegin(),(v).rend()
#define PB push


#define MOD 1000000007LL
#define EPS 1e-10

int main()
{
    int A, B;
    cin >> A >> B;
    if (B % A == 0)
    {
        cout << A + B << endl;
    }
    else
    {
        cout << B - A << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string>
#include <iostream>
#include <iomanip>
#include <map>
#include <algorithm>
#include <vector>
using namespace std;


int main(void) {
	string s,t;
	cin >> s >> t;
	sort(s.begin(),s.end());
	sort(t.begin(),t.end());
	reverse(t.begin(),t.end());
	cout << (s<t?"Yes":"No") << endl;
	return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0282

"""
import sys
from sys import stdin
from heapq import heappop, heappush
input = stdin.readline


pq = []                         # list of entries arranged in a heap
entry_finder = {}               # mapping of tasks to entries
REMOVED = float('inf')      # placeholder for a removed task

def add_team(score, team):
    if team in entry_finder:
        remove_team(team)
    entry = [-score, team]
    entry_finder[team] = entry
    heappush(pq, entry)

def remove_team(team):
    entry = entry_finder.pop(team)
    entry[-1] = REMOVED

def pop_team():
    while pq:
        score, team = heappop(pq)
        if team is not REMOVED:
            del entry_finder[team]
            return score, team
    raise KeyError('pop from an empty priority queue')


def main(args):
    N, R, L = map(int, input().split(' '))
    on_tv = [0] * (N + 1)       #  ????????????????????¬???????????£??????????????????????¨?
    scores = [0] * (N + 1)       #  ????????????????????¨?????????

    #for i in range(1, N+1):
    #    add_team(0, i)
    
    add_team(0, 1)

    last_time = 0
    need_pop = True
    top_score = 0

    for i in range(R):
        d, t, x = [int(x) for x in input().split(' ')]
        if need_pop:
            need_pop = False
            top_score, team = pop_team()
            if d != team:
                add_team(scores[team], team)

        on_tv[team] += (t - last_time)

        scores[d] += x
        add_team(scores[d], d)
        if x > 0 and scores[d] > top_score:
            need_pop = True

        last_time = t

    t = L
    score, team = pop_team()
    on_tv[team] += (t - last_time)

    print(on_tv.index(max(on_tv)))


if __name__ == '__main__':
    main(sys.argv[1:])

Measured memory_bytes: 88048
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll>
#define cvector vector<char>
#define svector vector<string>
#define lque queue<ll>
#define lpque priority_queue<ll>
#define dlpque priority_queue<ll,lvector,greater<ll>>
#define P pair<ll,ll>
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define rep(i,n) for(ll i=0; i<n; ++i)
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n,ans=0;cin>>n;
  lvector A(n),B(n),C(n-1);
  rep(i,n) cin>>A[i];rep(i,n) cin>>B[i];rep(i,n-1) cin>>C[i];
  rep(i,n) {
    ans+=B[A[i]-1];
    if(i+1<n&&A[i]+1==A[i+1]) ans+=C[A[i]-1];
  }
  print(ans);
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ALL(c) begin(c), end(c)
using namespace std;
using ll = long long;
using ld = long double;


void go_karatsuba(auto a, auto b, auto ret, int n){
    if(n<=16){
        for(int i=0;i<2*n;++i) ret[i] = 0;
        for(int i=0;i<n;++i)
        for(int j=0;j<n;++j) ret[i+j] += a[i]*b[j];
    }else
    if(n&1){
        go_karatsuba(a,b,ret,n-1);
        ret[n*2-3] = 0;
        for(int i=0;i<n-1;++i) ret[i+n-1] += a[i]*b[n-1] + b[i]*a[n-1];
        ret[n*2-2] = a[n-1]*b[n-1];
    }else{
        auto ar = a, al = a+n/2, 
		     br = b, bl = b+n/2,
        	 asum = ret+n*5, bsum = asum+n/2,
        	 x1 = ret, x2 = x1+n, x3 = x2+n;
        for(int i=0;i<n/2;++i){
            asum[i] = al[i] + ar[i];
            bsum[i] = bl[i] + br[i];
        }
        go_karatsuba(ar, br, x1, n/2);
        go_karatsuba(al, bl, x2, n/2);
        go_karatsuba(asum, bsum, x3, n/2);
        for(int i=0;i<n;++i) x3[i] -= x1[i]+x2[i];
        for(int i=0;i<n;++i) ret[i+n/2]+=x3[i];
	}
	ret[n*2-1] = 0;
}

template<class T>
vector<T> mul(vector<T> &_a, vector<T> &_b){
	vector<T> a = _a, b = _b;
	int n = max(size(a), size(b));
	a.resize(n);
	b.resize(n);
	vector<T> ret(n*6);
	go_karatsuba(begin(a), begin(b), begin(ret), n);
	return vector<T>(begin(ret), begin(ret)+size(_a)+size(_b)-1);
} 


int main(){
	//freopen("input.txt","r",stdin); //freopen("output.txt","w",stdout);
	ios::sync_with_stdio(0);cin.tie(0);//cout.precision(12);cout<<fixed;
	
	const int P = 2e5+3;
	const int g = 2;
	
	vector<int> f(P);
	for(int x=1,i=0;i<P-1;++i){
		f[x] = i;
		x = 1LL*x*g %P;
	}
	
	int n;
	cin>>n;
	
	vector<int> a(n);
	for(auto &_ : a) cin>>_;
	//ll answer = 0;
	//for(int i=0;i<n;++i) for(int j=0;j<n;++j) answer+=1LL*a[i]*a[j]%P;
	
	vector<ll> cnt(P-1);
	for(int x : a){
		x%=P;
		if(x) cnt[f[x]]++;
		//cerr<<x<<' '<<f[x]<<endl;
	}
	
	//for(int i=0;i<P;++i) cout<<cnt[i]<<' '; cout<<endl;
	
	auto m = mul(cnt,cnt);
	//for(auto x : m) cout<<x<<' '; cout<<endl;
	for(int i=P-1;i<size(m);++i) m[i%(P-1)]+=m[i];
	m.resize(P-1);
	//for(auto x : m) cout<<x<<' '; cout<<endl;
	
	ll ans = 0;
	for(int i=0,x=1; i<P-1; ++i, x=1LL*x*g%P) ans+=m[i]*x;
	
	for(int x:a) ans-=1LL*x*x%P;
	ans/=2;
	
	cout<<ans<<endl;
	
	//cout<<answer<<endl;
	
	return 0;
}


Measured memory_bytes: 21944
#include<iostream>
#include<vector>
#include<map>
#include<string>
using namespace std;
#define ll long long
int main()
{
	int sum = 700;
	string a;
	cin >> a;
	if (a[0] == 'o')sum += 100;
	if (a[1] == 'o')sum += 100;
	if (a[2] == 'o')sum += 100;
	cout << sum;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
using namespace std;
vector <int> G[1000006];
int dis, t;
void dfs(int u, int f, int d){
	if (d > dis)
		dis = d, t = u;
	for (int i = 0; i < G[u].size(); ++ i){
		int v = G[u][i];
		if (v != f)
			dfs(v, u, d + 1);
	}
}
int main(){
	int n;
	cin >> n;
	for (int i = 1; i < n; ++ i){
		int u, v;
		scanf("%d %d", &u, &v);
		G[u].push_back(v);
		G[v].push_back(u);
	}
	dfs(1, 0, 1);
	dis = 0;
	dfs(t, 0, 1);
	cout << (dis % 3 == 2 ? "Second" : "First") << endl;
}


Measured memory_bytes: 42368
N = int(input())
S = list(input())

count = 0
for N in range(1000):
    password = list(f"{N:03d}")
    i = 0
    p = password[i]
    for x in S:
        if x == p:
            if i < 2:
                i += 1
                p = password[i]
            else:
                count += 1
                break

print(count)


Measured memory_bytes: 9248
/*
csc -debug D.cs && mono --debug D.exe <<< "10 3
1 8 5 7 100 4 52 33 13 5
3 10
4 30
1 4"
*/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Reflection;

public class HelloWorld {
    public static void SolveCodeForces() {
        var N = cin.NextInt();
        var M = cin.NextInt();
        var A = cin.LongArray();
        Array.Sort(A, 0, N);

        var ops = new long[M][];
        for (var i = 0; i < M; i++)
            ops[i] = cin.LongArray();
        ops = ops.OrderByDescending(a => a[1]).ToArray();

        var index = 0;
        foreach (var op in ops) {
            for (var j = 0; j < op[0]; j++) {
                if (index >= N || A[index] >= op[1]) {
                    System.Console.WriteLine(A.Sum());
                    return;
                }
                A[index] = op[1];
                index++;
            }
        }
        System.Console.WriteLine(A.Sum());
    }

    static Scanner cin = new Scanner();
    static StringBuilder cout = new StringBuilder();

    static public void Main () {
        SolveCodeForces();
        // IncreaseStack(SolveCodeForces);
        // System.Console.Write(cout.ToString());
    }

    public static void IncreaseStack(ThreadStart action, int stackSize = 128000000)
    {
        var thread = new Thread(action, stackSize);
        thread.Start();
        thread.Join();
    }
}

public static class Helpers {
    public static T[] CreateArray<T>(int length, Func<int, T> itemCreate) {
        var result = new T[length];
        for (var i = 0; i < result.Length; i++)
            result[i] = itemCreate(i);
        return result;
    }
}

public class Scanner
{
    private string[] line = new string[0];
    private int index = 0;

    public string Next() {
        if (line.Length <= index) {
            line = Console.ReadLine().Split(' ');
            index = 0;
        }
        var res = line[index];
        index++;
        return res;
    }

    public int NextInt() {
        return int.Parse(Next());
    }

    public long NextLong() {
        return long.Parse(Next());
    }

    public ulong NextUlong() {
        return ulong.Parse(Next());
    }

    public string[] Array() {
        line = Console.ReadLine().Split(' ');
        index = line.Length;
        return line;
    }

    public int[] IntArray(int emptyPrefixLen = 0) {
        var array = Array();
        var result = new int[emptyPrefixLen + array.Length];
        for (int i = 0; i < array.Length; i++)
            result[emptyPrefixLen + i] = int.Parse(array[i]);
        return result;
    }

    public long[] LongArray() {
        var array = Array();
        var result = new long[array.Length];
        for (int i = 0; i < array.Length; i++)
            result[i] = long.Parse(array[i]);
        return result;
    }

    public ulong[] UlongArray() {
        var array = Array();
        var result = new ulong[array.Length];
        for (int i = 0; i < array.Length; i++)
            result[i] = ulong.Parse(array[i]);
        return result;
    }
}

Measured memory_bytes: 33524