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

#define int long long
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define repo(i,o,n) for(int i=o;i<(int)(n);i++)
#define repm(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end());
#define vdelete(v) (v).erase(unique(all(v)), (v).end());
#define pb(n) push_back(n);

int n,a,x,dp[51][2501],ans;

main() {
    dp[0][0] = 1;
    cin >> n >> a;
    rep1(i,n) {
        cin >> x;
        repm(j,i) {
            rep(k,2501-x) {
                dp[j+1][k+x] += dp[j][k];
            }
        }
    }
    rep1(i,n) ans += dp[i][i*a];
    cout << ans << endl;
}



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


int main() {
  int n;
  cin>>n;
  ll dp[n+1];
  dp[0]=2; dp[1]=1;
  for(int i=2; i<=n; i++){
    dp[i]=dp[i-1]+dp[i-2];
  }
  
  cout<< dp[n] <<endl;
    
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main {
   public static void main(String[] args) {
      Scanner scanner = new Scanner(System.in);

      int a = scanner.nextInt();
      int b = scanner.nextInt();

      int area = a * b;
      int round = 2 * (a + b);

      System.out.println(area + " " + round);
   }
}

Measured memory_bytes: 26124
n=int(input())
l=sorted([6**i for i in range(1,7)]+[9**i for i in range(6)])
dp=[float('inf')]*(n+1)
dp[0]=0
for i in range(1,n+1):
    for j in range(12):
        if i-l[j]>=0:dp[i]=min(dp[i],dp[i-l[j]]+1)
print(dp[-1])

Measured memory_bytes: 3828
x = list(map(int, input().split()))

if x[0] == 0:
    print(1)
elif x[1] == 0:
    print(2)
elif x[2] == 0:
    print(3)
elif x[3] == 0:
    print(4)
elif x[4] == 0:
    print(5)


Measured memory_bytes: 9048
main = do
  n <- readLn :: IO Int
  as <- map read . words <$> getLine :: IO [Integer]
  putStrLn $ show $ sumInvMod p as $ lcmMod p as
      where p = 1000000007

sumInvMod :: Integer -> [Integer] -> Integer -> Integer
sumInvMod p as y = foldl step 0 as
    where step a x = addMod p a $ mulMod p y $ invMod p x

lcmMod :: Integer -> [Integer] -> Integer
lcmMod p as = mod (foldl lcm 1 as) p

addMod :: Integer -> Integer -> Integer -> Integer
addMod p x y = mod (x + y) p

mulMod :: Integer -> Integer -> Integer -> Integer
mulMod p x y = mod (x * y) p

invMod :: Integer -> Integer -> Integer
invMod p x = mod (xgcd p x !! 2) p

xgcd :: Integer -> Integer -> [Integer]
xgcd a b
    | a < b     = xgcdRec [0, 1, 1, 0] b a
    | otherwise = xgcdRec [1, 0, 0, 1] a b
    where xgcdRec m a 0 = a: m
          xgcdRec [x0, y0, x1, y1] a b = let d = div a b in xgcdRec [x1, y1, x0 - d * x1, y0 - d * y1] b (mod a b)


Measured memory_bytes: 4476
#include <bits/stdc++.h>
#include <iostream>
#include <string.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<ld> vd;
typedef vector<char> vc;
#define mp make_pair
#define pb push_back
#define read(array,n) for(ll i=0;i<n;i++) cin>>array[i];
#define f(i,n) for(i=0;i<n;i++)
#define F(i,n) for(i=1;i<=n;i++)
#define inf 1000000007;
// function to transform string to lowercase --> transform(s.begin(),s.end(),s.begin(),::tolower)
//(a + b ) % m = (a % m + b % m ) %m
//(a - b ) % m = ( ((//(//(a - b ) % m = ( (a % m - b % m ) + m ) %m
// a % m - b % m ) + m ) %m
//(a * b ) % m = (a % m * b % m ) %m
//(a / b ) % m = (a % m * inv(b) ) %m where inv(b) = pow(b,m,m-2)

ll power(ll i,ll j){
	ll prod=1;
	while(j>0){
		if(j&1){
			prod=prod*i;
		}
		j=j>>1;
		i=i*i;
	}
	return prod;
}
void solve(){
	ll i,j,n,k,m;
	ll a,b,c;
	cin>>a>>b>>c;
	cin>>k;
	while(k>0){
		if(b>a){
			break;
		}
		else{
			b=2*b;
			k--;
		}
	}
	while(k>0){
		if(c>b){
			break;
		}
		else{
			c=2*c;
			k--;
		}
	}
	if(c>b&&b>a){
		cout<<"Yes\n";
	}
	else{
		cout<<"No\n";
	}
}
int main(){
	// freopen("input.txt","r",stdin);
	solve();
	// ll t;
	// cin>>t;
	// while(t--){
	// 	solve();
	// }
}

Measured memory_bytes: 3636
use List::Util qw( max sum );

my $N = <>;
my $input = <>;
chomp $input;
my ( @L_array ) = split(' ', $input);

my $L_max = max( @L_array );
my $L_sum = sum( @L_array );

if ( $L_max < $L_sum - $L_max ) {
    print 'Yes';
}
else {
    print 'No';
}

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

using namespace std;
typedef long long ll;

#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = (ll)(n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define FORD(i, a, b) for (ll i = (a); i >= (b); i--)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

void solve() {
  int N, fb = 0, count = 0;
  string str;
  cin >> N >> str;
  REP(i, N) {
    if (str[i] == '(') {
      count++;
    }
    if (str[i] == ')') {
      if (count <= 0) {
        fb++;
      } else {
        count--;
      }
    }
  }
  REP(i, fb) { str = '(' + str; }
  REP(i, count) { str = str + ')'; }
  cout << str << endl;
}

signed main() {
  solve();

  return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
from math import *
from itertools import *
from collections import *
from functools import *
try:
    from math import gcd
except Exception:
    from fractions import gcd

MOD = 1000000007  # type: int

def solve(S: str):
    dp = [[0] * 4 for _ in range(len(S) + 1)]
    dp[0][0] = 1

    for i, s in enumerate(S):
        for j, a in enumerate('_ABC'):
            dp[i+1][j] = dp[i][j]
            if s == '?':
                dp[i+1][j] = 3 * dp[i][j] + (dp[i][j-1] if 1 <= j else 0)
            if s == a:
                dp[i+1][j] += dp[i][j-1]
            dp[i+1][j] %= MOD
    return dp[-1][-1] % MOD


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    result = solve(S)
    print(result)

if __name__ == '__main__':
    main()


Measured memory_bytes: 29648
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define EPS (1e-9)
#define INF (1e17)
#define PI (acos(-1))
//const double PI = acos(-1);
//const double EPS = 1e-15;
//long long INF=(long long)1E17;
#define i_7 (long long)(1e9+7)
//#define i_7 998'244'353
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
long long po(long a, long b){
    if(b==0){
        return 1;
    }
    
    long long z = po(a,b/2);
    z = mod(z*z);
    if(b%2!=0){
        z = mod(a*z);
    }
    return z;
}
 
bool prime_(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=std::sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}
 
long long gcd_(long long a, long long b){
  if(a<b){
    std::swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd_(b,a%b);
  }
}
 
long long lcm_(long long x, long long y){
  return (x/gcd_(x,y))*y;
}
 
//using namespace std;
//using namespace boost::multiprecision;
//using namespace __gnu_pbds;

int main(){
  using namespace std;
  int n;
  cin>>n;
  long long x[n], y[n];
  REP(i, n) cin>>x[i]>>y[i];
  long long M = 0;
  REP(i, n) M = max(M, x[i] + y[i]);
  long long m = INF;
  REP(i, n) m = min(m, x[i] + y[i]);
  long long ans = M - m;
  
  vector<long long> temp;
  REP(i, n) temp.push_back(x[i] - y[i]);
  sort(ALL(temp));
  ans = max(ans, temp[n - 1] - temp[0]);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 8436
def main():
    A,B,C = map(int, input().split())
    if A>B:
        D=A
    else:
        D=B

    list =[]
    for i in range(D+1):
        if i!=0:
            if (A%i == 0) & (B%i == 0) :
                list.append(i)
    print(list[(len(list)-C)])
    


main()

Measured memory_bytes: 3060
// Vicfred
// https://atcoder.jp/contests/abc050/tasks/abc050_b
// simulation
import std.algorithm;
import std.array;
import std.conv;
import std.stdio;
import std.string;

void main() {
    long n = readln.chomp.to!long;
    long[] t = 0L~readln.split.map!(to!long).array;
    long m = readln.chomp.to!long;

    long[] p = new long[m+1];
    long[] x = new long[m+1];

    foreach(i; 1..m+1) {
        readf("%s %s\n", &p[i], &x[i]);
    }

    long total = sum(t);

    foreach(i; 1..m+1) {
        writefln("%s", total-t[p[i]]+x[i]);
    }
}



Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
class Program
{
    static void Main(string[] args)
    {
        var input = Console.ReadLine().Split(" ");
        var N = int.Parse(input[0]);
        var Q = int.Parse(input[1]);

        // いろいろ初期化
        var seen = new bool[N + 1];
        var counter = new List<int>();
        var graph = new List<List<int>>();
        for (int i = 0; i <= N; i++)
        {
            graph.Add(new List<int>());
            counter.Add(0);
        }

        // グラフの読み込み
        for (int i = 1; i < N; i++)
        {
            var line = Console.ReadLine().Split(" ");
            var a = int.Parse(line[0]);
            var b = int.Parse(line[1]);
            graph[a].Add(b);
            graph[b].Add(a);
        }

        for (int i = 0; i < Q; i++)
        {
            var line = Console.ReadLine().Split(" ");
            var p = int.Parse(line[0]);
            var x = int.Parse(line[1]);

            counter[p] += x;
        }

        var quere = new Queue<int>();
        quere.Enqueue(1);

        while (quere.Count > 0)
        {
            var de = quere.Dequeue();
            if (seen[de]) continue;
            seen[de] = true;
            var count = graph[de].Count;
            for (int i = 0; i < count; i++)
            {
                var next = graph[de][i];
                if (seen[next]) continue;
                counter[next] += counter[de];
                quere.Enqueue(next);
            }
        }
        counter.RemoveAt(0);
        var outText = string.Join(" ", counter);
        Console.WriteLine(outText);
    }
}


Measured memory_bytes: 72104
#include<stdio.h>
int main(){
  int n,m,x,a[100],i,g=0,l=0;
  scanf("%d%d%d",&n,&m,&x);
  for(i=0;i<m;i++){
    scanf("%d",&a[i]);
    a[i]>x?g++:l++;
  }
  printf("%d",g>l?l:g);
}

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

int main()
{
    int n;
    cin>>n;
    
    int ans = n%10;
    
    if(ans == 2 || ans == 4 || ans == 5 || ans == 7 || ans == 9)
        cout<<"hon"<<endl;
        
    else if(ans == 0 || ans == 1 || ans == 6 || ans == 8)
        cout<<"pon"<<endl;
        
    else if (ans == 3)
        cout<<"bon"<<endl;
        
    return 0;
}

Measured memory_bytes: 3624
from collections import deque

S = deque(input())
Q = int(input())

head = 1
for _ in range(Q):
    cmd = input()
    if cmd == "1":
        head *= -1
    elif "2 1" == cmd[:3]:
        if head == 1:
            S.appendleft(cmd[4])
        else:
            S.append(cmd[4])
    else:
        if head == 1:
            S.append(cmd[4])
        else:
            S.appendleft(cmd[4])

ans = ""
for _ in range(len(S)):
    if head == 1:
        ans += S.popleft()
    else:
        ans += S.pop()

print(ans)


Measured memory_bytes: 6288
//============================================================================
// Name        : d.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include<vector>
#include<algorithm>
using namespace std;

int main() {
	int n,m;cin>>n>>m;
	int p[n];
	for(int i=0;i<n;i++){
		cin>>p[i];
		p[i]--;
	}
	int x[m],y[m];
	vector<vector<int>> a;
	vector<int> ac;
	for(int i=0;i<n;i++){
		a.push_back(ac);
	}
//	cout<<'B'<<endl;
	for(int i=0;i<m;i++){
		cin>>x[i]>>y[i];
		x[i]--;
		y[i]--;
//		cout<<x[i]<<y[i]<<endl;
		a[x[i]].push_back(y[i]);
		a[y[i]].push_back(x[i]);
//		cout<<i<<endl;
	}
	int notuse[n];

	int ans=0;
	for(int i=0;i<n;i++)notuse[i]=1;
//	cout<<'A'<<endl;
	for(int i=0;i<n;i++){
		if(notuse[i]){
			notuse[i]=0;
			vector<int> vf,vl;
			vl.push_back(i);
			vf.push_back(i);
			while(vl.size()){
				int vi=vl.back();
				vl.pop_back();
				for(int j=0;j<a[vi].size();j++){
					if(notuse[a[vi][j]]){
						notuse[a[vi][j]]=0;
						vl.push_back(a[vi][j]);
						vf.push_back(a[vi][j]);
					}
				}
			}
			sort(vf.begin(),vf.end());
			for(int j=0;j<vf.size();j++){
				if(binary_search(vf.begin(),vf.end(),p[vf[j]]))ans++;
			}

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

Measured memory_bytes: 8176
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset

using namespace std;

int main() {

	int a[4],sum,n,flag=0;

	cin >> n;

	a[0] = n / 1000;
	a[1] = (n - a[0] * 1000) / 100;
	a[2] = (n - (n/100)*100) / 10;
	a[3] = n % 10;

	sum = (a[0] + a[1] + a[2] + a[3] - 7)/2;

	cout << a[0];

	for (int i = 1; i < 4; i++) {
		if (sum == a[i]) {
			flag = 1;
		}
	}

	if (sum == a[1] + a[2]) flag = 2;
	if (sum == a[2] + a[3]) flag = 3;
	if (sum == a[1] + a[3]) flag = 4;

	if (flag == 1) {
		for (int i = 1; i < 4; i++) {
			if (sum == a[i]) {
				cout << '-';
				sum = sum - a[i];
			}
			else {
				cout << '+';
			}

			cout << a[i];
		}
	}
	else if(flag == 2)
	{
		cout << '-' << a[1] << '-' << a[2] << '+' << a[3] ;
	}
	else if (flag == 3)
	{
		cout << '+' << a[1] << '-' << a[2] << '-' << a[3] ;
	}
	else if (flag == 4)
	{
		cout << '-' << a[1] << '+' << a[2] << '-' << a[3] ;
	}
	else 
	{
		cout << '+' << a[1] << '+' << a[2] << '+' << a[3] ;
	}
	cout << "=7" << endl;

	return 0;
}


Measured memory_bytes: 256
def lcp(S):
    N = len(S)
    prefix = [0] * N
    j = 0
    for i in range(1, N):
        if i + prefix[i - j] < j + prefix[j]:
            prefix[i] = prefix[i - j]
        else:
            k = max(0, j + prefix[j] - i)
            while i + k < N and S[k] == S[i + k]:
                k += 1
            prefix[i] = k
            j = i
    prefix[0] = N
    return prefix

N = int(input())
S = input()

ans = 0
for j in range(N):
    prefix = lcp(S[j:])
    for i, p in enumerate(prefix):
        if p <= i:
            ans = max(ans, p)
print(ans)



Measured memory_bytes: 52188
#include <stdio.h>

int  main() {
	int N;
	scanf("%d",&N);
	double x;
	char u[4];
	double sum=0;
	for (int i = 0; i < N; i++) {
		scanf("%lf %s",&x,u);
		if (u[0] == 'J') {
			sum += x;
		}
		if (u[0] == 'B') {
			sum += x*380000.0;
		}
	}
	printf("%lf\n",sum);
	return 0;
}

Measured memory_bytes: 128
# coding: UTF-8
import sys
#sys.setrecursionlimit(n)
import heapq
import re
import bisect
import random
import math
import itertools
from collections import defaultdict, deque
from copy import deepcopy
from decimal import *

readl= lambda: list(map(int, sys.stdin.readline().split()))
readt= lambda: tuple(map(int, sys.stdin.readline().split()))
read = lambda: sys.stdin.readline().rstrip()
readi = lambda: int(read())
readmi = lambda: map(int, sys.stdin.readline().split())
readms = lambda: map(str, sys.stdin.readline().split())

n, k = readmi()
t = readl()
c = 0
for i in t:
    if i >= k:
        c += 1
print(c)

Measured memory_bytes: 14384
#include <bits/stdc++.h>
using namespace std;
#define popCnt(x) (__builtin_popcountll(x))
typedef long long Long;

const int N = 3003;
constexpr int MOD = round(1e9 + 7);

Long ways[N][N];
int arr[N];

pair<int, int> queries[N];

int power(int p, int b) {
  if (b == 0) return 1;
  int res = power(p, b / 2);
  res = 1LL * res * res % MOD;
  if (b & 1) {
    res = 1LL * res * p % MOD;
  }
  return res;
}

const int INV2 = power(2, MOD - 2);

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#ifdef Local
  freopen("test.in", "r", stdin);
#else
#define endl '\n'
#endif

  int n, q;
  cin >> n >> q;
  for (int i = 0; i < n; ++i) {
    cin >> arr[i];
  }

  for (int i = 0; i < q; ++i) {
    cin >> queries[i].first >> queries[i].second;
  }

  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      ways[i][j] = (i > j);
    }
  }

  for (int q_ind = q - 1; q_ind >= 0; --q_ind) {
    int x = queries[q_ind].first, y = queries[q_ind].second;
    --x, --y;

    ways[y][x] = ways[x][y] = INV2;
    for (int i = 0; i < n; ++i) {
      if (i == y || i == x) {
        continue;
      }
      ways[y][i] = ways[x][i] = 1LL * INV2 * (ways[x][i] + ways[y][i]) % MOD;
      ways[i][y] = ways[i][x] = 1LL * INV2 * (ways[i][x] + ways[i][y]) % MOD;
    }
  }

  int res = 0;
  for (int x = 0; x < n; ++x) {
    for (int y = 0; y < n; ++y) {
      res = (res + (arr[x] < arr[y]) * ways[x][y]) % MOD;
    }
  }

  res = 1LL * res * power(2, q) % MOD;
  cout << res << endl;

}



Measured memory_bytes: 70656
#include <iostream>
#include <numeric>
#include <cmath>
#include <limits>
#include <stdio.h>
#include <iomanip>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
using ll = long long;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
ll Max(ll(a), ll(b), ll(c)) {
	return max(max(a, b), c);
}
ll Min(ll(a), ll(b), ll(c)) {
	return min(min(a, b), c);
}





int main() {
	ll N,an=1;
	cin >> N;
	ll p = 2;
	ll B = N;
	
	while (p * p <= B) {
		if (N % p == 0) {
			
			ll k = 0;
			while (N % p == 0) {
				N /= p;
				k++;
			}
			ll m = 1;
			while (k >= m) {
				k -= m;
				an++;
				m++;
			}
		}
		p++;
	}
	if (N == 1) {
		an--;
	}
	cout << an << endl;
}


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

int main(){
    
    int a,b,c,d,A,B;
    cin >> a >> b >> c >> d;
    A = a * b;
    B = c * d;
    if(A > B){
        cout << A;
    }
    else{
        cout << B;
    }
    
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

template<class T>
inline bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}
template<class T>
inline bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

struct CountUnionFind{
    int sz;     // vertex number
    vector<int> par;
    vector<int> rank;
    vector<int> cnt;

    CountUnionFind(int n) : sz(n) {
        par.resize(sz);
        rank.assign(sz, 0);
        cnt.assign(sz, 1);
        for(int i = 0; i < sz; ++i){
            par[i] = i;
        }
    }

    int find(int x){
        if(par[x] == x) return x;
        else    return par[x] = find(par[x]);
    }

    bool same(int x, int y){
        return find(x) == find(y);
    }

    void unite(int x, int y){
        x = find(x), y = find(y);
        if(x == y)  return;
        if(rank[x] < rank[y]){
            par[x] = y;
            cnt[y] += cnt[x];
        }
        else{
            par[y] = x;
            cnt[x] += cnt[y];
            if(rank[x] == rank[y])  ++rank[x];
        }
    }

    int get_cnt(int x){
        return cnt[find(x)];
    }
};

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

    int n, m;
    cin >> n >> m;
    vector<P> es;
    for(int i = 0; i < m; ++i){
        int u, v;
        cin >> u >> v;
        --u, --v;
        es.emplace_back(u, v);
    }
    CountUnionFind uf(n);
    vector<ll> ans(m);
    ans[m - 1] = (ll)n * (n - 1) / 2;
    for(int i = m - 1; i > 0; --i){
        int u = es[i].first, v = es[i].second;
        ans[i - 1] = ans[i];
        if(!uf.same(u, v)){
            int foo = uf.get_cnt(u), bar = uf.get_cnt(v);
            uf.unite(u, v);
            int hoge = uf.get_cnt(u);
            ans[i - 1] += (ll)foo * (foo - 1) / 2 + (ll)bar * (bar - 1) / 2 - (ll)hoge * (hoge - 1) / 2;
        }
    }
    for(int i = 0; i < m; ++i)  cout << ans[i] << '\n';
}

Measured memory_bytes: 4084
#include <bits/stdc++.h>
#define GET_MACRO(_1,_2,_3,_4,_5,NAME,...) NAME
#define pr(...) GET_MACRO(__VA_ARGS__,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__)
#define pr1(a) (#a)<<"="<<(a)
#define pr2(a,b) pr1(a)<<", "<<pr1(b)
#define pr3(a,b,c) pr2(a,b)<<", "<<pr1(c)
#define pr4(a,b,c,d) pr3(a,b,c)<<", "<<pr1(d)
#define pr5(a,b,c,d,e) pr4(a,b,c,d)<<", "<<pr1(e)
#define int long long
#define double long double
using namespace std;
const int N = 100010;
const int INF = 1LL<<55;
const int mod = (1e9)+7;
const double EPS = 1e-8;
const double PI = 6.0 * asin(0.5);
typedef pair<double,int> P;
typedef long long ll;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
ostream& operator<<(ostream& o,P p){return o<<"("<<p.first<<","<<p.second<<")";}
istream& operator>>(istream& i,P &p){return i>>p.first>>p.second;}
ostream& operator<<(ostream& o,vector<auto> &a){int i=0;for(auto t:a)o<<(i++?" ":"")<<t;return o;}
istream& operator>>(istream& i,vector<auto> &a){for(auto &t:a)i>>t;return i;}
void prArr(auto a,string s=" "){int i=0;for(auto t:a)cout<<(i++?s:"")<<t;cout<<endl;}


int h,w;
vector<string> mp;

//   1   -1    1   -1
//  #.   ..   .#   ##
//  ..   .#   ##   #.


bool O___(int x,int y){
  return mp[y][x] == '.' && mp[y][x+1] == '.' && mp[y+1][x] == '#' && mp[y+1][x+1] == '.';
}

bool ___O(int x,int y){
  return mp[y][x] == '.' && mp[y][x+1] == '#' && mp[y+1][x] == '.' && mp[y+1][x+1] == '.';
}

bool _OOO(int x,int y){
  return mp[y][x] == '#' && mp[y][x+1] == '#' && mp[y+1][x] == '.' && mp[y+1][x+1] == '#';
}

bool OOO_(int x,int y){
  return mp[y][x] == '#' && mp[y][x+1] == '.' && mp[y+1][x] == '#' && mp[y+1][x+1] == '#';
}


signed main(){
  cin>>h>>w;

  int ofset = 1;
  mp.resize(h+ofset * 2,string(w+ofset * 2,'.'));

  for(int i=0;i<h;i++) 
    for(int j=0;j<w;j++) cin>>mp[h-i][j+1];
  
  auto getArg=[](double x,double y){
    return 180 * (arg(complex<double>(x,y))/ PI);
  };
  
  vector<P> A;
  for(int i=0;i<=h;i++)
    for(int j=0;j<=w;j++){
      if(O___(j,i)) A.push_back(P(getArg(j,i),1));
      if(___O(j,i)) A.push_back(P(getArg(j,i),-1));
      if(_OOO(j,i)) A.push_back(P(getArg(j,i),1));
      if(OOO_(j,i)) A.push_back(P(getArg(j,i),-1));
    }
  sort(A.begin(),A.end());  
  
  int ans = 1;
  int cnt = 1;
  for(int i=0;i<(int)A.size();){
    double th = A[i].first;
    while(i < (int)A.size()){
      double th2 = A[i].first;
      int type = A[i].second;
      if(abs(th - th2) > EPS) break;
      i++;
      cnt += type;
    }
    Max(ans,cnt);
  }
  cout<<ans<<endl;
  
  return 0;
}



Measured memory_bytes: 7584
package main

import (
	"bufio"
	"fmt"
	"io"
	"math"
	"os"
	"strconv"
	"strings"

)


func main() {
	solve(os.Stdin, os.Stdout)
}

type ReaderEx struct {
	baseScanner *bufio.Scanner
	words       []string
	nextWordIdx func() int
	initWordIdx func(int)
}

func NewScannerEx(stdin io.Reader) *ReaderEx {
	var this ReaderEx
	var idx int
	var wordsCnt int
	this.baseScanner = bufio.NewScanner(stdin)
	this.baseScanner.Buffer(make([]byte, 0), 1E+11)
	this.nextWordIdx = func() int {
		cur := idx
		idx = (idx + 1) % wordsCnt
		return cur
	}
	this.initWordIdx = func(wc int) {
		idx = 0
		wordsCnt = wc
	}
	return &this
}

func (me *ReaderEx) Scan(doSplit bool) (isScanned bool) {
	isScanned = me.baseScanner.Scan()
	if doSplit {
		me.words = strings.Fields(me.baseScanner.Text())
	} else {
		me.words = []string{me.baseScanner.Text()}
	}
	me.initWordIdx(len(me.words))
	return
}

func (me *ReaderEx) nextBytes() []byte {
	return []byte(me.words[me.nextWordIdx()])
}
func (me *ReaderEx) nextString() string {
	return me.words[me.nextWordIdx()]
}

type StringArray []string

func (me *ReaderEx) nextStringArray() StringArray {
	return me.words[me.nextWordIdx():]
}

func (me StringArray) toStrings() []string {
	return me
}

func (me StringArray) toInts() []int {
	strValues := me.toStrings()
	values := make([]int, len(strValues))
	for i, v := range strValues {
		n, err := strconv.Atoi(v)
		if err != nil {
			panic(err)
		}
		values[i] = n
	}
	return values
}
func (me *ReaderEx) nextInt() int {
	n, err := strconv.Atoi(me.words[me.nextWordIdx()])

	defer func() {
		if err != nil {
			panic(fmt.Sprintf("getInt(%d)", n))
		}
	}()
	return n
}

func pow(x, y, mod int) (ans int) {

	ans = 1
	for bit := 1 << uint(math.Floor(math.Log2(float64(y)))); ; bit >>= 1 {
		if y&bit != 0 {
			ans *= x
			if mod > 0 {
				ans %= mod
			}
		}
		if bit <= 1 {
			return
		}
		ans *= ans
		if mod > 0 {
			ans %= mod
		}
	}
}

type factType struct {
	prime int
	count int
}

func fact(n int) (facts []*factType) {

	for i := 2; i*i <= n; i++ {
		if n%i == 0 {
			fa := factType{prime: i}
			for n%fa.prime == 0 {
				n /= fa.prime
				fa.count++
			}
			facts = append(facts, &fa)
		}
	}
	if n > 1 {
		facts = append(facts, &factType{prime: n, count: 1})
	}
	return facts
}
func dec2bin(n int) (ret []bool) {
	for bit := 1 << uint(math.Floor(math.Log2(float64(n)))); ; bit >>= 1 {
		ret = append(ret, n&bit != 0)

		if bit <= 1 {
			return
		}
	}

}

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

func b2i(b bool) (i int) {
	if b {
		i = 1
	} else {
		i = 0
	}
	return
}

func solve(stdin io.Reader, stdout io.Writer) {

	r := NewScannerEx(stdin)
	r.Scan(true)
	k, x := r.nextInt(), r.nextInt()
	fmt.Fprintln(stdout, []string{"No", "Yes"}[b2i(500*k >= x)])

}


Measured memory_bytes: 640
#include<iostream>

int main(){
    int a = 0, b = 0;
    std::cin >> a >> b;
    if(a > b) std::cout << "a > b" << std::endl;
    else if(a < b) std::cout << "a < b" << std::endl;
    else std::cout << "a == b" << std::endl;
    return 0;
}


Measured memory_bytes: 3116
#include<iostream>
#include<vector>
#include<utility>

using namespace std;

typedef pair<int, int> Pii;

vector<int> graph[100001];
vector<int> dim(100001, 0);
vector<Pii> nodes(100001);
vector<bool> used(100001, false);

int dfs(int node, int prev){
    used[node] = true;
    int max_cost = 0, not_zero = 0, cost;
    nodes[node].second = 0;
    for(int nxt: graph[node]){
        if(nxt == prev || used[nxt]) continue;
        cost = dfs(nxt, node);
        if(cost){
            not_zero++;
            dim[node]--;
        }
        max_cost = max(max_cost, cost);
    }
    nodes[node].second = max_cost;

    if(dim[node] == 1 && node != 0){
        int total = nodes[node].first + nodes[node].second;
        nodes[node].first = 0;
        return total;
    }
    return 0;
}

int main(){
    int n,m;
    cin >> n >> m;
    for(int i=0;i<n;i++) cin >>nodes[i].first;

    int a,b;
    for(int i=0;i<m;i++){
        cin >> a >> b;
        a--; b--;
        graph[a].push_back(b);
        graph[b].push_back(a);
        dim[a]++;
        dim[b]++;
    }

    dfs(0, -1);

    int ans = 0, max_second = 0;
    for(int i=0;i<n;i++){
        ans += nodes[i].first;
        if(nodes[i].first != 0) max_second = max(max_second, nodes[i].second);
    }
    ans += max_second;
    cout << ans << endl;

}


Measured memory_bytes: 17320
n = gets.to_i
s = gets.chomp
t = gets.chomp

jama = 0
i = n - 1

while i >= 0
  if s[n - 1 - i .. n - 1] == t[0 .. i]
    jama = i + 1
    break
  end
  i = i - 1
end


puts 2 * n - jama


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

signed main(){
	ll n, sum = 0; cin >> n;
	vector<ll> a(n), data(100010, 0);
	for(int i = 0; i < n; i++) {
		cin >> a[i], sum += a[i];
		data[a[i]]++;
	}
	int Q; cin >> Q;
	vector<ll> ans(Q);
	for(int i = 0; i < Q; i++){
		int b, c; cin >> b >> c;
		ans[i] = sum + (c - b) * data[b];
		sum = ans[i];
		data[c] += data[b];
		data[b] = 0;
	}
	for(int i = 0; i < Q; i++) cout << ans[i] << endl;
}


Measured memory_bytes: 5560
#include <algorithm>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <stack>
#include <stdio.h>
#include <string>
#include <queue>
#include <vector>
using namespace std;

int n;
int A[2000001];
int B[2000001];
int C[10001];

void countingSort(int A[], int B[], int k) {
	for (int i = 0; i <= k; i++)
		C[i] = 0;

	for (int i = 0; i < n; i++) {
		C[A[i]]++;
	}

	for (int i = 1; i <= k; i++) {
		C[i] = C[i] + C[i - 1];
	}

	for (int j = 0; j < n; j++) {
		B[C[A[j]]] = A[j];
		C[A[j]]--;
	}
}

int main()
{
	cin >> n;
	for (int i = 0; i < n; i++) cin >> A[i];
	countingSort(A, B, 10000);
	for (int i = 1; i <= n; i++) {
		if (i > 1) cout << " "; 
		cout << B[i];
	}
	cout << endl;
}



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

int main()
{
        ll n;
        cin>>n;
        ll A=0;
        ll B=0;
        priority_queue<ll> pq;
        for(ll i=1;i<=n;i++) {
                ll x,y;
                cin >> x >> y;
                pq.push(x+y);
                A += x; B += y;
        }
        while(pq.size() > 1) {

                ll X=pq.top(); pq.pop();
                ll Y = pq.top(); pq.pop();
                A -= Y;
        }
        cout << A << endl;
        return 0;
}


Measured memory_bytes: 1400
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ll long long
#define mp make_pair
#define pb push_back
#define nl printf("\n")
#define ff first
#define ss second
#define set0(a) memset ((a), 0 , sizeof(a))
#define set1(a) memset((a),-1,sizeof (a))
#define pi pair<int, int>
#define ps pair<string, string>
#define pl pair<long, long>
#define pll pair<long long, long long>
#define vll vector<long long>
#define vl vector<long>
#define vi vector<int>
#define vs vector<string>
#define vps vector< ps >
#define vpi vector< pi >
#define vpl vector< pl >
#define vpll vector< pll >
#define flash  ios_base::sync_with_stdio(false); cin.tie(NULL);
#define tc(t,T) for(long long t=0;t<T;t++)
#define rep(i,s,n,d) for(long long i=s;i<n;i=i+d)
const int todx[] = { -2, -2, -1, -1,  1,  1,  2,  2 };
const int tody[] = { -1,  1, -2,  2, -2,  2, -1,  1 };
bool sortbysec(const pll &a,
              const pll &b)
{
    return (a.second < b.second);
}
/*bool cxp pair<ll, pll> &a,
              const pair<ll, pll> &b)
{
    return (a.ff < b.ff);
}*/

void func(void)
{
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
}
ll gcd(ll a,ll b){
    if(b==0)return a;
    else return gcd(b,a%b);
}
void printStack(stack<string> s){
    if(s.empty())return;

    string x=s.top();
    s.pop();
    printStack(s);
    cout<<x;
    s.push(x);

}


ll binaryexp(ll n,ll p){

    if(p==0) return 1;
    if(p%2==0) return binaryexp((n%mod)*(n%mod),p/2);
    else return ((n%mod)*binaryexp(((n%mod)*(n%mod))%mod,(p-1)/2)%mod);

}

#define meax 10000001
vll spf(meax,0);
void siv(){
    spf[1]=1;

   for(ll i=2;i<meax;i++)spf[i]=i;

   for(ll i=4;i<meax;i+=2){
        spf[i]=2;
    }
    for(ll i=3;i*i<meax;i++){
        if(spf[i]==i){
            for(ll j=i*i;j<meax;j+=i){
                if(spf[j]==j){
                    spf[j]=i;
                }
            }
        }
    }
}


int main(){
    int n;
    cin>>n;
    vll a(n+1,0);
    vll pres(n+1,0);
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
     for(int i=n-1;i>=0;i--){
        pres[i]=(pres[i+1]+a[i])%mod;

    }
    ll sum1=0;
    for(int i=0;i<n-1;i++){
        sum1=(sum1+(a[i]*pres[i+1])%mod)%mod;
    }
    cout<<sum1<<endl;
}


Measured memory_bytes: 84576
def main():
  import math 
  mf=math.factorial
  n,m=map(int,input().split())
  mod=pow(10,9)+7
  print(0 if abs(n-m)>=2 else ((mf(n)%mod)*(mf(m)%mod)*(2 if abs(n-m)==0 else 1))%mod)
if __name__=='__main__':
  main()

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

template <typename T> struct fenwick {
	int n;
	int step;
	vector<T> a;

	fenwick(int _n) : n(_n), a(n + 1) { 
		for (step = 1; 2 * step <= n; step *= 2) { }
	}

	 // update i, 0 <= i < n
	void update(int i, T v) {
		assert(0 <= i && i < n);
		for (i++; i <= n; i += (i & -i)) {
			a[i] += v;
		}
	}

	// sum [0, i), 0 <= i <= n
	T query(int i) {
		assert(0 <= i && i <= n);
		T res{};
		for (; i; i -= (i & -i)) {
			res += a[i];
		}
		return res;
	}

	// sum [a, b)
	T query(int l, int r) {
		return query(r) - query(l);
	}

	// minimum i such that sum[0, i) >= v
	// returns n+1 if sum of all elements < v
	// [NOT TESTED]
	int lowerBound(T v) {
		if (v <= 0) return 0;
		int res = 0;
		for (int len = step; len >= 1; len /= 2) {
			int nxt = res + len;
			if (nxt <= n && a[nxt] < v) {
				v -= a[nxt];
				res = nxt;
			}
		}
		return res + 1;
	}
};

const int MAXM = 1.1e5;
int N;
int M;

vector<int> evts[MAXM];
vector<int> divisors[MAXM];

int ans[MAXM];

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

	cin >> N >> M;
	for (int i = 0; i < N; i++) {
		int l, r; cin >> l >> r; r++;
		evts[l].push_back(r);
	}

	for (int x = 1; x <= M; x++) {
		for (int y = x; y <= M; y += x) {
			divisors[y].push_back(x);
		}
	}

	fenwick<int> sum(M+2);
	for (int x = 1; x <= M; x++) {
		for (int r : evts[x]) {
			sum.update(x, 1);
			sum.update(r, -1);
		}

		for (int d : divisors[x]) {
			ans[d] += sum.query(x + 1);
			if (x + d <= M) {
				ans[d] -= sum.query(x + d + 1);
			}
		}
	}

	for (int x = 1; x <= M; x++) {
		cout << ans[x] << '\n';
	}

	return 0;
}


Measured memory_bytes: 17664
#include <bits/stdc++.h> 
#define int long long
#define quickie ios_base::sync_with_stdio(false); cin.tie(NULL);
#define rep(i, a, b) for(int i=a; i<b; i++)
#define rep1(i, a, b) for(int i=a; i<=b; i++)
#define repp(i, a, b) for(int i=b-1; i>=a; i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define db double
#define mi map<int, int>
#define mc map<char, int>
#define ms map<string, int>
#define vi vector<int>
#define qi queue<int>
#define MI(x) power(x, mod-2)
#define test int t; cin >> t;
//#define mod 1000000007LL
#define mod 998244353 
using namespace std;
int power(int x, int y) ;
int gcd(int a, int b) ;
#define pi 3.141592653589
const int lll = 39800;
vi t(4*lll);
vi ans;

void solve(int v, int tl, int tr)
{
	if(tl==tr) {
		t[v] = ans[tl];
	}
	else {
		int tm = (tl+tr)/2;
		solve(v*2,tl,tm);
		solve(v*2+1,tm+1,tr);
		t[v]=t[v*2]+t[v*2+1];
	}
}

int fun(int v, int tl, int tr, int l, int r)
{
	if(l>r)
		return 0;
	if(tl==l&&tr==r)
		return t[v];
	int tm = (tl+tr)/2;
	return fun(v*2,tl,tm,l,min(r,tm))+fun(v*2+1,tm+1,tr,max(l,tm+1),r);
}

signed main() {
    quickie 
    int a, b, c, d, ans ;
    cin >> a >> b >> c >> d ;
    for(int i=0; ;i++) {
        if(i%2 == 0) {
            c -= b ;
        }
        else {
            a -= d ;
        }
        if(c <= 0 || a <= 0) {
            ans = i ;
            break ;
        }
    }
    if(ans %2 == 0) cout << "Yes\n" ;
    else cout << "No\n" ;
}

int power(int x, int y) {
    int res = 1; x %= mod;
    while (y > 0) {
        if (y & 1)
            res = (res*x) % mod;
        y = y>>1;
        x = (x*x) % mod;
    }
    return res%mod;
}
 
int gcd(int a,int b){
    if(a==0) return b;
    return gcd(b%a,a);
}

Measured memory_bytes: 4376
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[][] dp = new int[N+1][3];
        for(int i = 1; i <= N; i++){
            int a = sc.nextInt();
            int b = sc.nextInt();
            int c = sc.nextInt();
            dp[i][0] = a + Math.max(dp[i-1][1], dp[i-1][2]);
            dp[i][1] = b + Math.max(dp[i-1][0], dp[i-1][2]);
            dp[i][2] = c + Math.max(dp[i-1][0], dp[i-1][1]);
        }
        System.out.println(Math.max(dp[N][0] ,Math.max(dp[N][1], dp[N][2])));
        sc.close();
    }

}


Measured memory_bytes: 95968
#include <stdio.h>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
#include <algorithm>
#include <tuple>

//#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back

int main() {
  int N;
  cin >> N;
  
  cout << pow(N, 3) << endl;

}


Measured memory_bytes: 512
#!/usr/bin/env python3
import sys

MOD = 998244353  # type: int


def solve(N: int, D: "List[int]"):
    from collections import Counter
    c = Counter(D)

    x = sorted(list(set(D)))
    if any([0 >= i for i in D[1:]]):
        print(0)
        exit()

    if D[0] != 0 or len(x) <= 1 or max(x) - min(x) + 1 != len(x):
        print(0)
        exit()

    ans = 1
    for i in range(2, N):
        if c[i - 1] >= 2:
            ans *= pow(c[i - 1], c[i]) % MOD

    print(ans % MOD)

    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools
# (tips: You use the default template now. You can remove this line by
# using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    D = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, D)


if __name__ == '__main__':
    main()


Measured memory_bytes: 27168
# coding: utf-8


def solve(*args: str) -> str:
    n, a, b = map(int, args[0].split())

    ret = min(max(a-1, b-1), max(n-a, n-b))

    if (b-a) % 2:
        if a-1 < n-b:
            sup = a
            ret = min(ret, sup+((b-sup-1)//2))
        else:
            sup = n-b+1
            ret = min(ret, sup+((n-a-sup)//2))
    else:
        ret = min(ret, (b-a)//2)

    return str(ret)


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))


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

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}

int main() {
	int n = ri(), k = ri();
	k = std::min(k, n - 1);
	int a[n];
	for (int i = 0; i < n; i++) a[i] = ri();
	
	std::set<std::pair<int, int> > to_list;
	for (int i = 0; i < k; i++) to_list.insert({a[i], i});
	
	int64_t dp[n];
	for (int i = 0; i < n; i++) dp[i] = 1000000000000000000;
	dp[0] = 0;
	auto dp_go = [&] (int dest, int origin) {
		dp[dest] = std::min(dp[dest], dp[origin] + std::abs(a[dest] - a[origin]));
	};
	for (int i = 0; i + 1 < n; i++) {
		to_list.erase({a[i], i});
		if (i + k < n) to_list.insert({a[i + k], i + k});
		auto itr = to_list.lower_bound({a[i], 0});
		if (itr != to_list.end()) dp_go(itr->second, i);
		if (itr != to_list.begin()) dp_go(to_list.lower_bound({std::prev(itr)->first, 0})->second, i);
	}
	std::cout << dp[n - 1] << std::endl;
	return 0;
}


Measured memory_bytes: 1408
//url:
//problem name: Brick Break

#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); ++i)
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<long long,long long>;
using veci = vector<int>;
using vecl = vector<long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;

int main() {
    int N; cin >> N;
    int cu = 1;
    int cnt = 0;
    bool ok = false;
    REP(i,N) {
        int a;
        cin >> a;
        a;
        if(a == cu) {
            ok = true;
            cu++;
        } else cnt++;
    }
    if(ok) cout << cnt << endl;
    else cout << -1 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using pint = pair<int, int>;
using ll = long long;
using ull = unsigned long long;
using vll = vector<long long>;
using pll = pair<ll, ll>;
#define FOR(i, begin, end) \
    for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) \
    for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define VREP(s, ite) for (auto ite = s.begin(); ite != s.end(); ++ite)
#define FI first
#define SE second
#define ALL(v) v.begin(), v.end()
#define endl "\n"
#define ciosup  \
    cin.tie(0); \
    ios::sync_with_stdio(false);
#define eb emplace_back
#define vint vector<int>
constexpr ll INF = 1e15 + 7LL;
constexpr ll MOD = 1e9 + 7LL;
template <typename T>
istream &operator>>(istream &is, vector<T> &v) {
    for (int i = 0; i < v.size(); ++i) {
        is >> v[i];
    }
    return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    if (v.size() == 0) return os;
    for (int i = 0; i < v.size() - 1; ++i) {
        os << v[i] << " ";
    }
    os << v[v.size() - 1];
    return os;
}

void solve() {
    ll x, k, d;
    cin >> x >> k >> d;
    x = abs(x);
    ll num = x / d;
    if (x % d == 0) {
        if (k <= num) {
            cout << abs(x) - k * d << endl;
        } else {
            if ((k - num) % 2 == 0) {
                cout << 0 << endl;
            } else {
                cout << d << endl;
            }
        }
    } else {
        if (k <= num) {
            cout << abs(x) - k * d << endl;
        } else {
            if ((k - num) % 2 == 0) {
                cout << abs(x - num * d) << endl;
            } else {
                cout << abs(x - (num+1)*d) << endl;
            }
        }
    }
}

int main() {
    char tmp;
    while (cin >> tmp) {
        cin.putback(tmp);
        solve();
    }
}



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


using namespace std;


#define ll long long
#define mk make_pair
#define pb push_back
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define sz(x) (int) (x).size()


ll sum(int n);

void go(){
	ll a,b,k;cin>>a>>b>>k;
	bool turn=true;
	while(k--) {
		if(turn) { 
			if(a%2==1) {
				a--;
			}
			b+=a/2;
			a/=2;
		}else {
			if(b%2==1) {
				b--;
			}
			a+=b/2;
			b/=2;
		}
		turn=!turn;
	}
	cout << a << " " << b;
}
int main(){
   
   ios_base::sync_with_stdio(0);
   cin.tie(0);
   cout.tie(0);

   go();

   return 0;
}

ll sum(int n){                
   if(n == 0){
      return n;
   }else{
      return sum(n/10) + n%10;
   }
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstring>
#include<queue>
#include<tuple>
#include<utility>
#include<map>
#include<math.h>
#include<iomanip>
#include<stdio.h>
#include<stdlib.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define range(a) a.begin(), a.end()
#define endl "\n"
#define Yes() cout << "Yes" << endl
#define No() cout << "No" << endl
#define MP make_pair
using Graph = vector<vector<int>>;
const unsigned long long mod = 1e9 + 7;
const long long INF = 1LL<<60;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
void chmin(long long &a, long long b) { if (a > b) a = b; }
void chmax(long long &a, long long b) { if (a < b) a = b; }

int main(void){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int N;
	cin >> N;
	ll zmin = 2e9, zmax = -2e9, wmin = 2e9, wmax = -2e9;
	while(N--){
		ll x, y;
		cin >> x >> y;
		zmin = min(zmin, x + y);
		zmax = max(zmax, x + y);
		wmin = min(wmin, x - y);
		wmax = max(wmax, x - y);
	}

	cout << max(zmax - zmin, wmax - wmin) << endl;

	return 0;
}



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

#define ll long long
#define max(a,b)  (a > b) ? (a) : (b)
const int MAX = 1050;
int f[MAX];
int main(){
	for(int i=31;i>10;--i){
		int tmp = i*i;
		for(int k=tmp;k<=1000;k++)
			f[k] = max(f[k],tmp);
	}
	for(int i=10;i>=1;--i){
		for(int j=9;j>=2;--j){
			int tmp = pow(i,j);
			if(tmp <= 1000){
				for( int k = tmp;k<=1000;k++){
					f[k] = max(f[k],tmp);
				}
			}
		}
	}
	int n;
	cin>>n;
	cout<<f[n]<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cassert>

#include <cstring>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <limits>
#include <queue>
#include <unordered_map>
#include <list>
#include <set>
#include <numeric>
using namespace std;

using ll = long long;

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

int main()
{
	string s;
	size_t K;
	cin >> s >> K;

	set<string> substrs;
	for(int i = 1; i <= min(s.size(), K); ++i)
	{
		for (int j = 0; j + i - 1 < s.size(); ++j)
		{
			substrs.insert(s.substr(j, i));
		}
	}

	auto it = substrs.begin();
	rep(i, K-1)
	{
		++it;
	}

	cout << *it << endl;
}

Measured memory_bytes: 4744
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include <random>
#include <ctime>
#include <queue>
using namespace std;
const int N = 3e5 + 5;
int a[N], pref[N], suff[N];
int main(){
    int n;
    cin >> n;
    string s;
    cin >> s;
    
    for(int i = 2; i <= n; ++i){
        pref[i] = pref[i - 1] + (s[i - 2] == 'W');
    }
    for(int i = n - 1; i >= 1; --i){
        suff[i] = suff[i + 1] + (s[i] == 'E');
    }
    int ans = N;
    for(int i = 1; i <= n; ++i){
        ans = min(ans, pref[i] + suff[i]);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3076
#!/usr/bin/env python3
import numpy as np

n = int(input())
a = list(map(int, input().split()))


x = np.array(a[1:])-a[0]+np.arange(1, n)
# print(x)

y = np.array(a[1:])+a[0]-np.arange(0, n-1)
# print(y)

count = {}
ans = 0
for i in range(0, n-1):
    if not x[i] in count:
        count[x[i]] = 1
    else:
        count[x[i]] += 1

    if y[i] == 1:
        ans += 1
    if -y[i]+1 in count:
        ans += count[-y[i]+1]
# print(count)
print(ans)


Measured memory_bytes: 62588
/*last edited at 27.8.2015 by charis
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_2_A
*/

#include<iostream>
using namespace std;
	
void bubbleSort(int N, int A[], int C){
	for(int i=0; i<N; i++){
		for(int j=N-1; j>=i; j--){
			if(A[j]<A[j-1]) {
				int t=A[j-1]; A[j-1]=A[j]; A[j]=t; C++;
			}
		}
	}
	for(int i=0; i<N-1; i++){
		cout << A[i] << " ";
	}	
	cout << A[N-1] << endl;
	cout << C << endl;	
}

int main(){
	int N;
	cin >> N;
	int A[N];
	for(int i=0; i<N; i++){
		cin >> A[i];
	}
	
	int C=0;
	bubbleSort(N, A, C);
	
	return 0;
}

Measured memory_bytes: 1160