akhauriyash/Code-Regression huggingface dataset:
#include <sys/time.h>

#include <iostream>
#include <iomanip>
#include <algorithm>
#include <utility>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <utility>
#include <cctype>

using namespace std;

using ll = long long;
using P = pair<int, int>;
using VP = pair<int, pair<int, int> > ;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mkp(a, b) make_pair(a, b)
ll mod = 1000000007LL;

int h,w;
int dp[1010][1010];

string m[1010];

void solve(int y, int x, int val) {
	if (y < 0 || y >= h || x < 0 || x >= w) return;
	if (dp[y][x] <= val) return;
	if (m[y][x] == '#') return;
	
	dp[y][x] = val;

	//cout << "y:" << y << " x:" << x << " val:" << val << endl; 

	solve(y    , x + 1, val);
	solve(y    , x - 1, val);
	solve(y + 1, x    , val);
	solve(y - 1, x    , val);

	for(int dx = -2; dx <= 2; dx ++) {
		for(int dy = -2; dy <= 2; dy ++) {
			int nx = x + dx;
			int ny = y + dy;
			if (m[ny][nx] == '#') continue;
			if (ny < 0 || ny >= h || nx < 0 || nx >= w) continue;
			if (dp[ny][nx] <= val) continue;


			solve(ny, nx, val + 1); 
		}
	}
}


int main() {
	priority_queue<VP, vector<VP>, greater<VP> > que;

	int sx,gx,sy,gy;



	cin >> h >> w;
	cin >> sy >> sx >> gy >> gx;

	sy--; sx--;
	gy--; gx--;



	rep(i , h) {
		cin >> m[i];
	}

	rep(y, h) {
		rep(x, w) {
			dp[y][x] = 10000000;
		}
	}

	que.push(make_pair(0, make_pair(sy,sx)));

	while(!que.empty()) {
		int dxs[] = {-1,1,0,0};
		int dys[] = { 0,0,-1,1};

		VP cur = que.top();
		que.pop();
		int val = cur.first;
		int y = cur.second.first;
		int x = cur.second.second;

		if (dp[y][x] <= val) continue;
		dp[y][x] = val;

		for(int i = 0; i < 4; i++) {
			int nx = x + dxs[i];
			int ny = y + dys[i];
			if (ny < 0 || ny >= h || nx < 0 || nx >= w) continue;
			if (m[ny][nx] == '#') continue;
			if (dp[ny][nx] <= val) continue;
			que.push(make_pair(val, make_pair(ny,nx)));
		}

		for(int dx = -2; dx <= 2; dx ++) {
			for(int dy = -2; dy <= 2; dy ++) {
				if (abs(dx) + abs(dy) <= 1) continue;

				int nx = x + dx;
				int ny = y + dy;
				if (ny < 0 || ny >= h || nx < 0 || nx >= w) continue;
				
				if (m[ny][nx] == '#') continue;
				if (dp[ny][nx] <= val) continue;
				que.push(make_pair(val + 1, make_pair(ny,nx))); 
			}
		}

	}



	if (dp[gy][gx] == 10000000) {
		cout << -1 << endl;
	} else {
		cout << dp[gy][gx] << endl;
	}
/*
	rep(i, h) {
		rep(j ,w) {
			cout << dp[i][j] << " ";
		}
		cout << endl;
	}
*/
	return 0;
}


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

int n;
long long ans=0;

int gcd(int x, int y){
	if(y==0){
		return x;
	}else if(x<y){
		return gcd(y,x);
	}else{
		return gcd(y, x%y);
	}
}

int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	cin>>n;
	for(int i=1; i<=n;i++){
		for(int j=1;j<=n;j++){
			for(int k=1;k<=n;k++){
				if(i==1 or j==1 or k==1){
					ans+=1;
				}else{
					int tmp=gcd(i,j);
					ans+=gcd(tmp,k);
				}
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3664
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i, a, n) for (int i = (a); i < (n); i++)
#define repr(i, n, a) for (int i = (n)-1; i >= (a); i--)
#define repit(it, v) for (auto(it) = (v).begin(); (it) != (v).end(); (it)++)
#define sortt(v) sort((v).begin(), (v).end())
#define sortr(v) sort((v).rbegin(), (v).rend())
#define all(v) (v).begin(), (v).end()
#define co(x) cout << (x)
#define con(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define mkp make_pair
#define mkt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
// inline void fastio() { ios::sync_with_stdio(false), cin.tie(0); }
/******* Variable ***********************************/
const int maxn = 1e6 * 50;
const int inf = 1e9 + 7;
const double pi = 3.141592653589;
/******* Function ***********************************/
int solve(int n) {
  rep(i, 1, n + 1) {
    int x = i;
    if (x % 3 == 0) {
      cout << " " << i;
    } else {
      while (x) {
        if (x % 10 == 3) {
          cout << " " << i;
          break;
        }
        x /= 10;
      }
    }
  }
  cout << endl;
}
/******* Main ****************************************/
void Main() {
  int n;
  cin >> n;
  solve(n);
}

/*********************************************************
  Smaile!
▕▔╲┊┊┊┊┊┊┊┊┊╱▔▏
┊╲┈╲╱▔▔▔▔▔╲╱┈╱┊
┊┊╲┈╭╮┈┈┈╭╮┈╱┊┊
┊┊╱┈╰╯┈▂┈╰╯┈╲┊┊
┊┊▏╭╮▕━┻━▏╭╮▕┊┊
┊┊╲╰╯┈╲▂╱┈╰╯╱
                      How`s it going?
                              |＼
                      　／￣＼　ヽ
                      ／　　　ヽ |_
                      ￣＼　　　　 ＼
                      ／￣　/|/| /ﾚ､ ヽ＿
                      ￣＼ Yヘ |/ヘ幺　∠
                      　＜_|(･> <･) 6) ／
                      　　 (ﾞ　_　ﾞ／＜
                      　　　＞､ーイ￣￣
                      　　／厂ヽ／￣/＼
                      　 ( ｜　(亀)(>　)▏

                            Take a rest before getting tired!
                                        　　 ●
                                        　　/⌒ヽ
                                        　 ｜ 　|/⌒ヽ(ヽ
                                        　 (｀　∥ー⌒) |
                                        　|￣||￣￣￣￣￣|
                                        　|―||―――――|
                                        　|　Ｕ　　　　　|
                                        　|￣￣￣￣￣￣￣|
                                        　|＿＿＿＿＿＿＿|
                                        　　|―――――|
                                        　　|―――――|
                                        ｗｗＷｗｗＷｗＷＷｗ

************************************************************/
int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}


Measured memory_bytes: 3156
#include <bits/stdc++.h>
#define rep(i, k) for(int i = 0; i < k; i++)
using namespace std;
int main() {
    string a;
    cin >> a;
    if(a == "Sunny")
        cout << "Cloudy";
    else if(a == "Cloudy")
        cout << "Rainy";
    else
        cout << "Sunny";
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
typedef vector<ll> Vec;
typedef vector<int> Vi;
typedef vector<string> Vs;
typedef vector<vector<ll>> VV;
typedef vector<vector<int>> VVi;

#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define PER(i, a, b) for(ll i=(a); i>=(b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
const ll INF=1e16+18;
const ll MAX=100005;
const ll MOD=1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
#define ALL(v) v.begin(), v.end()
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a,b)
#define Each(a,b) for(auto &a :b)
#define REPM(i, mp) for (auto i = mp.begin(); i != mp.end(); ++i)
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbgmap(mp) cerr << #mp << ":"<<endl; for (auto i = mp.begin(); i != mp.end(); ++i) { cerr << i->first <<":"<<i->second << endl;}
#define dbgarr(n,m,arr) rep(i,n){rep(j,m){cerr<<arr[i][j]<<" ";}cerr<<endl;}
#define dbgdp(n,arr) rep(i,n){cerr<<arr[i]<<" ";}cerr<<endl;
#define sum(v) accumulate(ALL(v),0)
#define fi first
#define se second

template<typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) { return s<<"("<<p.first<<", "<<p.second<<")"; }

// vector
template<typename T>
ostream &operator<<(ostream &s, const vector<T> &v) {
    int len=v.size();
    for(int i=0; i<len; ++i) {
        s<<v[i];
        if(i<len-1) s<<"	";
    }
    return s;
}

// 2 dimentional vector
template<typename T>
ostream &operator<<(ostream &s, const vector<vector<T> > &vv) {
    int len=vv.size();
    for(int i=0; i<len; ++i) {
        s<<vv[i]<<endl;
    }
    return s;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<std::setprecision(10);

    ll n;
    cin>>n;
    Vec h(n);
    rep(i,n)cin>>h[i];
    ll ans=0;
    PER(i,100,1){
        bool count = true;
        rep(j,n){
            if(h[j]>=i){
                if(count){
                    ans++;
                    count = false;
                }
            }else{
                count = true;
            }
        }
    }
    cout<<ans<<endl;
    return  0;
}


Measured memory_bytes: 256
# https://atcoder.jp/contests/abc067/tasks/arc078_b
# 1とNの最短経路について注目したときに、それぞれの最適戦略を考えてみる
# 相手を負かせたい→相手側に攻めて道を塞ぐのが有利(相手のマスが少なくなるから)
# 自分が負けそう→退避して行きたい(でも相手のマスのほうが多かったらもう逆転は不可能)
# 勝者は→先にたどり着けるノードの中で多い方が勝者(同数の場合はFennecが敗者)

import sys
read = sys.stdin.readline
from collections import defaultdict, deque


def read_ints():
    return list(map(int, read().split()))


class Tree:
    def __init__(self, N):
        '''重み付き無向木構造をクラスにしてみる(余り意味はなさそう)'''
        from collections import defaultdict, deque
        self.N = N
        self.tree = defaultdict(lambda: [])
        self.dists = None
        self.parents = None
        self.root = None

    def _link(self, a, b, d):
        '''
        d is a distance between a and b
        '''
        self.tree[a].append((b, d))
        self.tree[b].append((a, d))

    def _init_dists(self, root=0):
        self.dists = [-1] * self.N
        self.parents = [-1] * self.N
        que = deque([(root, -1, 0)])  # 現在のノード、前のノード、距離
        self.dists[root] = 0
        while que:
            u, p, d = que.popleft()
            self.parents[u] = p
            for nu, dadd in self.tree[u]:
                if nu == p:  # 親はもう探索しない
                    continue
                nd = d + dadd
                self.dists[nu] = nd
                que.append((nu, u, nd))

    def ret_dist(self, a, b):
        '''
        a,b間の距離を高速に取得する
        '''
        raise NotImplementedError()
        if self.parents == None:
            self._init_dists()
        # aとbの共通祖先を見つける必要がある
        # 共通祖先ってどうやって持ってくるんだろう...

    def ret_dists(self, u):
        '''
        uを始点とした各点への距離を返す (うまくやれば二度目は高速化できそう？)
        '''
        ret = [-1] * self.N
        que = deque([(u, -1, 0)])  # 現在のノード、前のノード、距離
        ret[u] = 0
        while que:
            u, p, d = que.popleft()
            for nu, dadd in self.tree[u]:
                if nu == p:  # 親はもう探索しない
                    continue
                nd = d + dadd
                ret[nu] = nd
                que.append((nu, u, nd))
        return ret


N = int(input())
graph = Tree(N)
for _ in range(N - 1):
    a, b = read_ints()
    a -= 1
    b -= 1
    graph._link(a, b, 1)

# def ret_dists(u):
#     ret = [-1] * N
#     que = deque([(u, -1, 0)])  # 現在のノード、前のノード、距離
#     ret[u] = 0
#     while que:
#         u, p, d = que.popleft()
#         nd = 1 + d
#         for nu in graph[u]:
#             if nu == p:  # 親はもう探索しない
#                 continue
#             ret[nu] = nd
#             que.append((nu, u, nd))

#     return ret


fennec_dist = graph.ret_dists(0)
snuke_dist = graph.ret_dists(N - 1)

n_snuke = 0  # snukeに近いノードの数
n_fennec = 0  # 0を含んでfennecに近い #fennecが塗れるので
for f, s in zip(fennec_dist, snuke_dist):
    if f > s:  # すぬけにちかい
        n_snuke += 1
    else:
        n_fennec += 1

# print(n_fennec, n_snuke)
if n_fennec > n_snuke:
    print('Fennec')
else:
    print('Snuke')


Measured memory_bytes: 77532
k = int(input())

count = 0
i = 1
while True:
    s = str(i)
    for j in range(len(s) - 1):
        if abs(int(s[j]) - int(s[j+1])) > 1:
            i += 10 ** (len(s)-j-2)
            break
    else:
        count += 1
        if count == k:
            break
        i += 1

print(i)

Measured memory_bytes: 41836
const input=require('fs').readFileSync('/dev/stdin','utf8').split(/[\s]/);let input_i=-1;const tn=():number=>{input_i++;return Number(input[input_i])};const tnn=(n:number):number[]=>{const a=[];for(let i=0;i<n;i++){a.push(tn())}return a};const ts=():string=>{input_i++;return String(input[input_i])};const tss=(n:number):string[]=>{const a=[];for(let i=0;i<n;i++){a.push(ts())}return a};const to=(...arg)=>{console.log(...arg)};const abs=(a)=>{return Math.abs(a)};const min=(...a)=>{return Math.min(...a)};const max=(...a)=>{return Math.max(...a)};const floor=(a)=>{return Math.floor(a)};const asc=(ar:number[])=>{const t=[...ar];return ar.sort((a,b)=>{return a-b})};const desc=(ar:number[])=>{const t=[...ar];return t.sort((a,b)=>{return b-a})};const sw=(a,arr:any[],op:'=='|'>='|'>'|'<='|'<'='==')=>{for(let i=0;i<arr.length-1;i+=2){if(eval(a+op+arr[i])){return arr[i+1]}}return arr[arr.length-1]};const near=(n:number,arr:number[]):number=>{let ne=arr[0],ni=0;for(let i=1;i<arr.length;i++){if(Math.abs(n-ne)>Math.abs(n-arr[i])){ne=arr[i];ni=i}}return ni};const deduplicate=(a:any[]):any[]=>{return Array.from(new Set(a))};
const main=()=>{
  let o={}
  o['a']=ts().split(''),o['b']=ts().split(''),o['c']=ts().split('')
  let n='a'
  while(true){
    if(o[n].length==0){
      to(n.toUpperCase())
      return
    }
    let a=o[n].shift()
    n=a
  }
}
main()


Measured memory_bytes: 7372
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define LEN 100005

typedef struct pp{
  char name[100];
  int t;
}P;

P *Q;
int head,tail,n;

int min(int a, int b){
  if(a<b) return a;
  else return b;
}

void enqueue(P x){
  Q[tail] = x;
  tail = (tail+1) % LEN;
}

P dequeue(){
  P x;
  x = Q[head];

  head = (head+1) % LEN;

  return x;
}

int main(){
  int elaps=0,c;
  int i,q;
  P u;

  scanf("%d %d",&n,&q);
  Q = (P *)malloc(sizeof(P) * (LEN));

  for(i=1; i<=n; i++){
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].t);
  }
  head = 1;
  tail = n+1;

  while(head != tail){
    u = dequeue();
    c = min(q, u.t);
    u.t -= c;
    elaps += c;
    if(u.t > 0) enqueue(u);
    else printf("%s %d\n",u.name, elaps);
  }

  free(Q);

  return 0;
}

Measured memory_bytes: 10648
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
#include<bitset>
using namespace std;

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

typedef int i32;
typedef long long int i64;
typedef unsigned long long int ui64;
typedef float f32;
typedef double f64;
typedef long double f128;


int main(){
    int A,B;
    cin >> A >> B;
    string ans;
    if(max(A,B)>8){
        ans = ":(";
    }else{
        ans = "Yay!";
    }
    cout << ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N,M,num=0,max=0;
  string str;
  cin >> N;
  map<string, int> f; //文字とそのコストを保存
  for(int i=0;i<N;i++){
    cin >> str;
    f[str]++;
  }
  cin >> M;
  for(int i=0;i<M;i++){
    cin >> str;
    f[str]--;
  }
  for(auto x : f) //範囲ベースforループ
    if(x.second>max) max=x.second;
  cout << (max>0?max:0) << endl;
}

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

typedef long long ll;
const int maxn = 1e5+5;
multiset<int> job[maxn];

int main()
{
    int n, m, temp, temp2;
    cin>>n>>m;
    for(int i=0;i<n;i++){
        cin>>temp>>temp2;
        job[temp].insert(temp2);
    }
    ll ans = 0;
    multiset<int>candidate;
    for(int i=m-1;i>=0;i--){
        for(auto it:job[m-i]){
            candidate.insert(it);
        }
        if(candidate.size()>0){
            auto it = candidate.end();
            it--;
            ans+=*it;
            candidate.erase(it);
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 14208
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) (x).begin(), (x).end()
#define LL long long

using namespace std;
int main()
{
  int N, K;
  cin >> N >> K;

  vector<int> vec(N);
  LL int sum = 0;
  REP(i, N)
  {
    LL mon;
    cin >> mon;
    vec.at(i) = mon;
  }
  sort(ALL(vec));
  if (N >= K)
  {
    REP(i, N - K)
    {
      sum += vec[i];
    }
    cout << sum << endl;
  }
  else
  {
    cout << 0 << endl;
  }
}

Measured memory_bytes: 1024
#include <stdio.h>
 int main(void)
{
int A, b, c;
 scanf("%d%d%d", &A, &b, &c);
 int ispoor = 0;
 if (A == b && b != c) ispoor = 1;
 if (b == c && c != A) ispoor = 1;
 if (c == A && A != b) ispoor = 1;
 if (ispoor) {
 puts("Yes");
 } else {
 puts("No");
 }
 return 0;
 }

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
typedef long long ll;
ll N = pow(10,9)+7;

int main(void){
    ll n,k;
    cin>>n>>k;
	ll dp[110][100010];
	ll cumsum[100010];
    vector<ll>a(n);
    for(ll i=0;i<n;i++)cin>>a[i];
    dp[0][0]=1;
    for(ll i=0;i<n;i++){
        cumsum[0]=0;
        for(ll j=0;j<=k;j++)cumsum[j+1]=(cumsum[j]+dp[i][j])%N;
        for(ll j=0;j<=k;j++)dp[i+1][j]=(cumsum[j+1]-cumsum[max((ll)0,j-a[i])]+N)%N;
    }
    cout<<dp[n][k]<<endl;
    return 0;
}

Measured memory_bytes: 80768
#include<iostream>
using namespace std;
int main(){
	int n,m,count,c2;
	while (cin>>n){
		count=0;
		c2=0;
	    for (int i=0;i<n;i++){
	    	cin>>m;
	    	if (m%4==0)count++;
	    	if (m%2==0&&m/2%2!=0)c2++;
		}
		   int c1=n-count-c2;
		   if ((c2&&count>=c1)||(c2==0&&count>=c1-1))cout<<"Yes"<<endl;
		   else cout<<"No"<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
import Data.Char
import Data.List
import qualified Data.ByteString.Char8 as B
import qualified Data.Vector.Unboxed as V
main=putStrLn.unwords.map show.solve.unfoldr(B.readInt.B.dropWhile isSpace)=<<B.getContents
solve(n:as)=[max k$min 1 m,k+m]::[Int]where
  k=V.foldl(\s x->s+min 1 x)0.V.init$xs
  m=V.last xs
  xs=V.accum(+)(V.replicate 9 0)$map(\a->(min 8$a`div`400,1))as

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

R = [0] * N
e = 1
R0 = 0
for i in range(N):
    R0 += e * A[i]
    e *= -1
R[0] = R0

for i in range(N - 1):
    R[i + 1] = (A[i] - R[i] // 2) * 2

print(*R)


Measured memory_bytes: 14032
S = input()
K = int(input())
L = len(S)
a = S[0]
i = 0
C = []
if L == 1:
    C = [1]
while i < L-1:
    count = 1
    b,c = S[i],S[i+1]
    i+= 1
    while b == c:
        count += 1
        if i == L-1:
            break
        b,c = S[i],S[i+1]
        i += 1
    C.append(count)
if a != S[L-1]:
    num = 0
    for co in C:
        num += co//2
    ans = int(num*K)
else:
    if len(C) == 1:
        ans  = L*K//2
    else:
        num1 = 0
        for co in C:
            num1 += co//2
        num2 = (C[len(C)-1]+C[0])//2
        for co in C[1:len(C)-1]:
            num2 += co//2
        ans = int(num1+num2*(K-1))
print(ans)

Measured memory_bytes: 3064
p={} #調理時間
r={} #注文-次の注文までの時間
for i in range(5):
    p[i] = int(input())
    r[i] = int((p[i] + 9) /10) * 10
    #print(r[i])

"""
for i in range(5):
    print(p[i],end=' ')
print('')

for i in range(5):
    print(r[i],end=' ')
print('')
"""
lastnum = 0
for i in range(1,5):
    if r[lastnum] - p[lastnum] < r[i] - p[i]:
        lastnum = i

#print(lastnum)

time = 0
for i in range(5):
    if i != lastnum:
        time += r[i]
    else:
        time += p[i]

print(time)

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

#define MAXN (1<<18)
int dsu[MAXN], sz[MAXN];
int f(int x){return dsu[x]?dsu[x]=f(dsu[x]):x;}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n,m;
    cin >> n >> m;
    fill(sz, sz + n+1, 1);
    for (int i = 0,u,v; i < m; ++i) {
        cin >> u >> v;
        int a = f(u), b = f(v);
        if (a!=b) {
            dsu[a] = b;
            sz[b] += sz[a];
        }
    }
    cout << *max_element(sz, sz+n+1);
}

Measured memory_bytes: 5176
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <climits>
#include <random>
#include <iomanip>

using namespace std;
typedef long long unsigned int ll;
typedef pair<int, int> P;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

#define fillInt(xs, x)        \
  for (int i = 0; i < (x); i++) \
    scanf("%d", &xs[i]);
#define fillLong(xs, x)       \
  for (int i = 0; i < (x); i++) \
    scanf("%ld", &xs[i]);
#define fillString(xs, x)       \
  for (int i = 0; i < (x); i++) \
    cin >> xs[i];
#define sortv(xs) sort(xs.begin(), xs.end())
#define sortvdi(xs) sort(xs.begin(), xs.end(), std::greater<long>())
#define lbv(xs, x) lower_bound(xs.begin(), xs.end(), x) - xs.begin()
#define ubv(xs, x) upper_bound(xs.begin(), xs.end(), x) - xs.begin()
#define bs(xs, x) binary_search(xs.begin(), xs.end(), x)

#define rep(i,n) for(auto i=0; i<(n); i++)
#define isValidPoint(x, y, mx, my) x >= 0 && x  < mx && y >= 0 && y < my

int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

const int MOD = 1000000007;

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

  long n;
  cin >> n;

  vector<long> h(n);
  fillLong(h, n);

  long cnt(0);
  for(long i = 1; i <= 100; i++) {
    int j = 0;
    while(j < n) {
      while(j < n && h[j] < i) {
        j++;
      }
      if(j == n) break;
      cnt++;
      while(j < n && h[j] >= i) {
        j++;
      }
    }
  } 

  cout << cnt << endl;
  
}


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

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

  bool f[10] = {};
  int num[10] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
  for (int i = 0; i < M; i++) {
    int A;
    cin >> A;
    f[A] = true;
  }
  vector<int> dp(N + 1, -1);
  dp[0] = 0;
  for (int i = 1; i <= N; i++) {
    for (int j = 1; j < 10; j++) {
      if (!f[j] || i - num[j] < 0 || dp[i - num[j]] == -1) continue;
      dp[i] = max(dp[i], dp[i - num[j]] + 1);
    }
  }
  for (int i = N; i > 0;) {
    for (int j = 9; j >= 1; j--) {
      if (f[j] && i - num[j] >= 0 && dp[i] == dp[i - num[j]] + 1) {
        cout << j;
        i -= num[j];
        break;
      }
    }
  }
}

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

const double PI = 3.14159265358979323846;
//using namespace boost::multiprecision;
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
typedef pair<ll, ll> P;
const ll INF = 1e15;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

std::istream &operator>>(std::istream &in, set<int> &o) {
    ll a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
const int mod = 1000000007;
//const ll mod = 1e10;
typedef priority_queue<long long, vector<long long>, greater<long long> > PQ_ASK;

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

    vector<ll> place(n);
    rep(i, n) cin >> place[i];

    ll ans = 0;
    for (int i = 0; i < n - 1; i++) {
        ll walk = (place[i + 1] - place[i]) * a;
        ll teleport = b;
        ll now = min(walk, teleport);
        ans += now;
    }
    cout << ans << endl;
}

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

using namespace std;

int main()
{
    const int maxn=1e5+10;
    int num[maxn],n,temp;
    memset(num,0,maxn*sizeof(int));
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        scanf("%d",&temp);
        num[temp]++;
    }
    int maxm=0;
    for(int i=0;i<maxn-2;i++)
    {
        maxm=maxm>(num[i]+num[i+1]+num[i+2])?maxm:num[i]+num[i+1]+num[i+2];
    }
    printf("%d\n",maxm);
    return 0;
}

Measured memory_bytes: 640
import java.util.Scanner;
import java.util.Arrays;

class Main{
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String str = scanner.nextLine();
        String temp[] = str.split(" ",0);
        int num[] = new int[temp.length];
        
        for(int index = 0;index < temp.length;index++){
            num [index] = Integer.parseInt(temp[index]);
        }
        
        Arrays.sort(num);
        
        System.out.println(num[0] + " " + num[1] + " " + num[2]);
    }
}


Measured memory_bytes: 26288
#include <algorithm>
#include <array>
#include <climits> // INT_MAX, LONG_MAX, LLONG_MAX, UINT_MAX, ULONG_MAX, ULLONG_MAX
#include <cmath>
#include <cstdint>
#include <cstring> // memset
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>

#define ALL(x) (x).begin(), (x).end()
#define INF 1e9
#define LOG(x) cout << #x << " = " << (x) << endl
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)

using namespace std;

int main() {
    ios::sync_with_stdio(false);

    string s;
    cin >> s;
    
    int bitmap = 0;
    REP(i, s.size())
        bitmap ^= (0x1 << (s[i] - 'a'));

    cout << (bitmap == 0 ? "Yes" : "No") << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cassert>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
#include <cassert>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int n,k;
vector<int>edge[100005];
int par[100005],ran[100005];
void init(){ for(int i=0;i<100005;i++) par[i] = i; }
int find(int x){ if(x == par[x]) return x; else return par[x] = find(par[x]); }
void unite(int x,int y){
	x = find(x); y = find(y); if(x==y) return;
	if(ran[x] < ran[y]) par[x] = y;
	else{
		par[y] = x;
		if(ran[x] == ran[y]) ran[x]++;
	}
}
bool same(int x,int y){ return find(x)==find(y); }
int ret = 0;
int dfs(int v,int u,int d){
	int MAX = -1;
	for(int i=0;i<edge[v].size();i++){
		if(edge[v][i] == u) continue;
		MAX = max(MAX,dfs(edge[v][i],v,d+1));
	}
	if(MAX != -1 && MAX+1-d == k && d>1){
		ret++; return -1;
	}
	if(MAX == -1 && k == 1 && d>1){
		ret++; return -1;
	}
	assert((MAX==-1 || MAX+1-d<k || d<=1));
	return max(MAX,d);
}
int main(){
	cin >> n >> k;
	init();
	for(int i=1;i<=n;i++){
		int a; scanf("%d",&a);
		if(i == 1 && a != 1){
			ret++; a = 1;
		}
		if(i != a){
			edge[i].pb(a);
			edge[a].pb(i);
			unite(i,a);
		}
	}
	for(int i=1;i<=n;i++){
		assert(same(1,i)) ;
	}
	dfs(1,-1,0);
	cout << ret << endl;
}

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

#define ll          long long
#define pb          push_back
#define pii         pair<int,int>
#define pll         pair<long,long>
#define vi          vector<int>
#define vll         vector<ll>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define rall(a)      (a).rbegin(),(a).rend()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define mod        1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define rem(i,a,b)  for(int i=a;i>b;i--)
#define mp(a,b)     make_pair(a,b)
#define vvi(a,b,name)    vector<vector<int>> name(a,vector<int>(b,-1))


void solve(){
    ll n;cin>>n;
    ll l,r;
    ll ans=0;
    rep(i,0,n){
        cin>>l>>r;
        ans+=r-l+1;
    }
    cout<<ans;

}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    long t=1;
    //cin>>t;
    while(t--){
        solve();
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i,n) for(int i = 0; i < n; i++)

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> P;

int main(void)
{
	int n,a,b;
	cin >> n >> a >> b;
	cout << min(b,a*n) << endl;
        return 0;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	static Scanner scanner;

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

	    int a=gi();
	    int b=gi();


	   
	    	//System.out.print(max);
int c=0;
        if (a>b) {
        	c+=a;
        	a--;
        	System.out.print(c+Math.max(a, b));
        }else {
        	c+=b;
        	b--;
        	System.out.print(c+Math.max(a, b));
        }


	}
	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}

	// doubleとして入力を取得
	public static double gd() {
		return Double.parseDouble(scanner.next());
	}
}

Measured memory_bytes: 35496
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
//#include <numeric> //iota
//#include <sstream>
#include <cstring>
//#include <tuple>
//#include <random>
//#include <string>
//#include <unordered_set>
//#include <bitset>
//#include <unordered_map>
//#include <stack>
#include <cmath>
//#include <deque>
#include <queue>
//#include <list>
#include <array>
using namespace std;
#define endl "\n"
#define all(x) (x).begin(), (x).end()
#define vec vector
#define pb push_back
#define pp pop_back
#define fi first
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define se second
#define un_map unordered_map
#define rep(i,a,n) for (int i = a; i < n; ++i) 
#define inc_rep(i,a,n,inc) for (int i = a; i < n; i += inc) 
#define couts(x) cout << x << "\n" 
#define watch(x) cout << #x << " : " << x << endl;
typedef long long ll;
typedef pair<int,int> PII;
typedef pair<long long, long long>  PLII;
template<typename T>
void print(vector<T>& v) {rep(i, 0, (int)v.size()) cout << v[i] << " ";cout << endl;}
int nxt() {int x;cin >> x;return x;}
ll nxtl() {ll x;cin >> x;return x;}
string nxts() {string x;cin >> x;return x;}
double nxtd() {double x; cin >> x; return x;}

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}

#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif


int main() {
	IOS;
	string a , b;
	cin >> a >> b;
	int n = (int)a.size();
	int m = (int)b.size();
	int minn = 1e9 + 7;
	for (int i = 0; i < n; ++i) {
		int cnt = 0;
		int d = 0;
		for (int j = i, p = 0; j < min(n, i + m); ++j, p++) {
			if (a[j] != b[p]) {
				cnt++;
			}
			d++;
		} 
		if (d == m) minn = min(minn, cnt);
	}
	cout << minn << endl;
}















	



Measured memory_bytes: 3648
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
int main()
{
    long long int k,a,b;
    cin >> k >> a >> b;
    if(b - a <= 2 || a >= k)
    {
        cout << k + 1 << "\n";
    }
    else
    {
        cout << a + ((k - (a - 1))) / 2 * (b - a) + (k - (a - 1)) % 2 << "\n";
    }
    
    return 0;
}

Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <vector>
using namespace std;
#define FOR(__I,__N) for (int __I = 0; __I < __N; ++__I)

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



int main(){
	int64 A;
	double dB;
	cin >> A >> dB;
	//int B = dB*64+dB*32+dB*4;
	int B = round(dB*100);
	int64 ans = A*B/100;
	printf("%lld\n",ans);
}




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

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

using namespace std;

int main(){
	string s,t; cin>>s>>t;
	int m=s.length(),n=t.length();

	static int dp[3001][3001],prev[3001][3001];
	rep(i,m) prev[i+1][0]=1;
	rep(j,n) prev[0][j+1]=0;
	rep(i,m) rep(j,n) {
		dp[i+1][j+1]=max({dp[i+1][j],dp[i][j+1],dp[i][j]+(s[i]==t[j]?1:0)});
		if(dp[i+1][j+1]==dp[i+1][j]){
			prev[i+1][j+1]=0;
		}
		else if(dp[i+1][j+1]==dp[i][j+1]){
			prev[i+1][j+1]=1;
		}
		else{
			prev[i+1][j+1]=2;
		}
	}

	string ans;
	int i=m,j=n;
	while(i>0 || j>0){
		if(prev[i][j]==0){
			j--;
		}
		else if(prev[i][j]==1){
			i--;
		}
		else{
			i--;
			j--;
			ans+=s[i];
		}
	}
	reverse(ans.begin(),ans.end());
	cout<<ans<<'\n';

	return 0;
}


Measured memory_bytes: 70656
#include<bits/stdc++.h>
using namespace std;
int main(){
  int A,B,C,X;
  cin >> A >> B >> C >> X;
  int count=0;
  for(int i=0;i<=A;i++){
  for(int j=0;j<=B;j++){
  for(int k=0;k<=C;k++){
  int total=500*i+100*j+50*k;
  if(total==X)count++;
  }}}
  cout << count <<endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#define max(a,b) a>b?a:b
int i, j, n, sum, pmax, t, l, r, c[200000];
int main(){
    scanf("%d %ld", &n, &t);
    for(i=0; i<n; i++)scanf("%d %d", &l, &r), c[l]++, c[r]--;
    for(i=0; i<=t; i++)sum+=c[i], pmax=max(pmax,sum);
    printf("%d\n", pmax);
    return 0;
}

Measured memory_bytes: 996
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 10000000007
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//name[i][j]-> vvl name(i,vl(j))
//map<int,int>mp
//余りを切り上げる =>  (a + b - 1) / b 
#define pi pair<ll,ll>

signed main(){
	ll n; cin>>n;
  ll ans=0;
  map<string,ll> mp;
  rep(i,0,n){
    string s; cin>>s;
    sort(all(s));
    ans+=mp[s];
    mp[s]++;
  }
  cout<<ans<<endl;

    
  
	return 0;
}


Measured memory_bytes: 11372
using System;

public class Hello
{
    public static void Main()
    {
        while (true)
        {
            var w = Console.ReadLine().Trim();
            string[] line = w.Split(' ');
            var b = int.Parse(line[0]);
            var r = int.Parse(line[1]);
            var g = int.Parse(line[2]);
            var c = int.Parse(line[3]);
            var s = int.Parse(line[4]);
            var t = int.Parse(line[5]);
            if (w == "0 0 0 0 0 0") break;
            var bad = t - (5 * b + 3 * r + g + c + s);
            var ret = 80 * b + 54 * r + 4 * g - c - 3 * bad;
            Console.WriteLine(100 + ret);
        }
    }
}



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

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}
std::random_device rnd_dev;
std::mt19937 rnd(rnd_dev() ^ time(NULL));

std::vector<int> init(int n, const std::vector<int> &c, const std::vector<std::vector<int> > &val) {
	(void) val;
	double par[26];
	for (int i = 0; i < 26; i++) par[i] = std::sqrt(c[i]);
	double sum = std::accumulate(par, par + 26, 0.0);
	int times[26];
	double acc = 0;
	for (int i = 0; i < 26; i++) {
		acc += par[i];
		times[i] = (acc + 0.00001) / sum * n;
	}
	for (int i = 25; i--; ) times[i + 1] -= times[i];
	// for (auto &i : times) i--;
	//for (auto i : times) std::cerr << i << std::endl;
	std::vector<int> res;
	for (int i = 0; i < 26; i++) for (int j = 0; j < times[i]; j++) res.push_back(i);
	std::shuffle(res.begin(), res.end(), rnd);
	// assert(res.size() == n);
	return res;
}


std::vector<int> solve(int n, const std::vector<int> &c, const std::vector<std::vector<int> > &val) {
	auto score = [&] (const std::vector<int> &all) {
		int last[26];
		for (auto &i : last) i = -1;
		int res = 0;
		for (int i = 0; i < n; i++) {
			int cur = all[i];
			last[cur] = i;
			for (int j = 0; j < 26; j++) res -= c[j] * (i - last[j]);
			res += val[i][cur];
		}
		return res;
	};
	clock_t start = clock();
	
	auto r26 = init(n, c, val);
	
	std::vector<int> cur = r26;
	int cur_score = score(cur);
	int best_score = -1000000000;
	std::vector<int> best;
	
	while (1) {
		clock_t cur_time = clock();
		if (cur_time - start > 1.95 * CLOCKS_PER_SEC) break;
		int r0 = std::uniform_int_distribution<>(0, n - 1)(rnd);
		int r1 = std::uniform_int_distribution<>(0, n - 1)(rnd);
		std::swap(cur[r0], cur[r1]);
		double threshold = 1.95 - (double) (cur_time - start) / CLOCKS_PER_SEC;
		// std::cerr << threshold << std::endl;
		int new_score = score(cur);
		if (new_score > best_score * (1 - threshold * 0.005)) cur_score = new_score;
		else std::swap(cur[r0], cur[r1]);
		if (best_score < cur_score) best_score = cur_score, best = cur;
	}
	
	return best;
}

void input() {
	int n = ri();
	std::vector<int> c(26);
	for (auto &i : c) i = ri();
	std::vector<std::vector<int> > val(n, std::vector<int>(26));
	for (auto &i : val) for (auto &j : i) j = ri();
	for (auto i : solve(n, c, val)) printf("%d\n", i + 1);
}

void random_test() {
	int n = 365;
	std::vector<int> c(26);
	for (auto &i : c) i = std::uniform_int_distribution<>(0, 100)(rnd);
	std::vector<std::vector<int> > val(n, std::vector<int>(26));
	for (auto &i : val) for (auto &j : i) j = std::uniform_int_distribution<>(0, 20000)(rnd);
	
	auto res = solve(n, c, val);
	
	
	int last[26];
	for (auto &i : last) i = -1;
	int score = 0;
	for (int i = 0; i < n; i++) {
		last[res[i]] = i;
		for (int j = 0; j < 26; j++) score -= c[j] * (i - last[j]);
		score += val[i][res[i]];
	}
	printf("%d\n", score);
}

int main() {
#	ifdef LOCAL
	random_test();
#	else
	input();
#	endif
	return 0;
}



Measured memory_bytes: 3924
#include<stdio.h>
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
int main(){
	int n,m;
	while(scanf("%d%d",&n,&m),n+m){
		for(int i=0;i<n;i++){
			for(int j=0;j<m;j++)putchar(i+j&1?'.':'#');
			puts("");
		}
		puts("");
	}
}


Measured memory_bytes: 2108
#include <iostream>
#include <set>
#include <vector>
using namespace std;
vector <int> G[200005];
int Father[200005];
int DP[200005], V[200005];
int nb0, N;
int F[200005], C0[200005], C1[200005];
int TT[200005];
int R[200005];
struct Elem
{
    int a, b;
    bool operator < (Elem const& x) const
    {
        return (1LL * a * x.b) < (1LL * b * x.a);
    }
};
void Read()
{
    cin >> N;
    for(int i = 2; i <= N; i++)
    {
        cin >> Father[i];
        G[Father[i]].push_back(i);
    }
    for(int i = 1; i <= N; i++)
    {
        cin >> V[i];
        if(V[i] == 0)
            ++nb0;
    }
}

void DFS(int node)
{
    for(int i = 0; i < G[node].size(); i++)
    {
        int neighb = G[node][i];
        DFS(neighb);
        if(V[neighb] == 0)
            DP[node] += DP[neighb];
    }
    if(V[node] == 0)
        DP[node]++;
}
int father(int x)
{
    while(TT[x] != x)
    {
        x = TT[x];
    }
    int init = x;
    while(init != x)
    {
        int next = TT[init];
        TT[init] = x;
        init = next;
    }
    return x;
}

void Unite(int x, int y)
{
    if(x == y)
        return;
    TT[x] = y;
    C0[y] += C0[x];
    C1[y] += C1[x];

}

void Solve()
{
    vector <int> X;
    set <pair <Elem, int> > S;
    for(int i = 1; i <= N; i++)
        TT[i] = i, F[i] = Father[i];
    for(int i = 1; i <= N; i++)
    {
        Elem p;
        if(V[i] == 0)
            p.a = 1, p.b = 0, C0[i] = 1, C1[i] = 0;
        else
            p.a = 0, p.b = 1, C0[i] = 0, C1[i] = 1;
        if(i > 1)
        S.insert(make_pair(p, i));
    }
    long long ans = 0;
    for(int step = 1; step < N; step++)
    {
        int node = prev(S.end()) -> second;
        int f = father(F[node]);
        ans += (1LL * C1[f] * C0[node]);
        S.erase(prev(S.end()));
        Elem p = {C0[f], C1[f]};
        if(S.find(make_pair(p, f)) != S.end())
            S.erase(make_pair(p, f));
        Unite(node, f);
        f = father(node);
        p = {C0[f], C1[f]};
        if(F[f] != 0)
            S.insert(make_pair(p, father(node)));
    }
    /*if(V[1] == 1)
        ans += nb0;*/
    cout << ans << "\n";
}
int main()
{
    Read();
    DFS(1);
    Solve();
    return 0;
}


Measured memory_bytes: 38528
from sys import stdin

input = stdin.readline
from collections import Counter

def solve():
    n = int(input())
    verdict = [ inp for inp in stdin.read().splitlines()]
    c = Counter(verdict)
    print(f'AC x {c["AC"]}')
    print(f'WA x {c["WA"]}')
    print(f'TLE x {c["TLE"]}')
    print(f'RE x {c["RE"]}')


if __name__ == '__main__':
    solve()


Measured memory_bytes: 88928
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  long long n,m;
  cin >> n >> m;
  if(n>m){
    swap(n,m);
  }
  if(n==1&&m==1){
    cout << "1" << endl;
    return 0;
  }
  else if(n==1){
    cout << m-2 << endl;
    return 0;
  }
  else{
    cout << (n-2)*(m-2) << endl;
    return 0;
  }
}

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

#define rep(i,j,n) for(int i=j;i<n;++i)
#define all(i) i.begin(),i.end()
#define rall(i) i.rbegin(), i.rend()
#define INF 1e9
#define LINF 1e18
const int mod = 1e9 + 7;

typedef long long i64;
typedef pair<int, int> pi;

template <class T> using vt = vector<T>;
template <class T> using vvt = vector<vector<T>>;

i64 gcd(i64 n, i64 m) {return (m == 0? n : gcd(m, n % m));}
i64 lcd(i64 n, i64 m) {return (n / gcd(n, m) * m);}
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};

template <class Monoid> class SegmentTree {
  using F = std::function<Monoid(Monoid, Monoid)>;

  private:
    int sz;
    std::vector<Monoid> seg;

    const F f;
    const Monoid M1;

  public:
    SegmentTree(int n, const F f, const Monoid &M1) : f(f), M1(M1) {
      sz = 1;
      while(sz < n) sz *= 2;
      seg.assign(2 * sz, M1);
    }

    void update(int k, const Monoid &x) {
      k += sz - 1;
      seg[k] = x;
      while(k > 0) {
        k = (k - 1) / 2;
        seg[k] = f(seg[2 * k + 1], seg[2 * k + 2]);
      }
    }

    void add(int k, const Monoid &x) {
      k += sz - 1;
      seg[k] += x;
      while(k > 0) {
        k = (k - 1) / 2;
        seg[k] = f(seg[2 * k + 1], seg[2 * k + 2]);
      }
    }

    Monoid query(int a, int b, int k = 0, int l = 0, int r = -1) {
      if(r == -1) r = sz;

      if(b <= l || r <= a) return M1;
      if(a <= l && r <= b) return seg[k];
      Monoid vl = query(a, b, 2 * k + 1, l, (l + r) / 2);
      Monoid vr = query(a, b, 2 * k + 2, (l + r) / 2, r);
      return f(vl, vr);
    }
};

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

  int n, q;
  cin >> n >> q;
  SegmentTree<int> seg(n, [](int a, int b){ return a + b; }, 0);
  rep(i, 0, q) {
    int c, x, y;
    cin >> c >> x >> y;
    x--;
    if(c == 0) seg.add(x, y);
    else cout << seg.query(x, y) << endl;
  }
}


Measured memory_bytes: 3892
#include <bits/stdc++.h>
#define INF 1e9
using namespace std;

#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a)  (a).begin(),(a).end()

template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}
typedef long long ll;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}

void solve() {
    int X;
    cin >> X;
    int i = 1;
    while (X-i >= 0) {
        X-=i;
        if (X-1-i < 0) break;
        i++;
    }
    cerr << X << " " << i << endl;
    if (X==0) {
        cout << i << endl;
        return;
    }

    FOR(j,1,i+1) {
        if ((X+j) > i) {
            cout << j+X << endl;
            return;
        }
    }
    cout << X+i << endl;
    return;

}

int main() {
    solve();
    return 0;
}


Measured memory_bytes: 256
import java.io.*;

class Main {
    public static void main(String[] args) {
        try {
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));// ??\????????????????????????
            
            String line = br.readLine();
            String[] dataArray = line.split(" ");
            int x = Integer.parseInt(dataArray[0]);
            int y = Integer.parseInt(dataArray[1]);
            if(x<y) System.out.println(Result.LessThan.getValue());
            if(x==y) System.out.println(Result.Equal.getValue());
            if(x>y) System.out.println(Result.GreaterThan.getValue());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

   public enum Result{
    	LessThan("a < b"),
    	Equal("a == b"),
    	GreaterThan("a > b");

	   private String name;

	   private Result(String name) {
	        this.name = name;
	    }
	    
        public String getValue() {
            return this.name;
        }
   };
}

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

int main()
{
  const int INF = 1 << 30;
  const int MAX = 1000000+1;
  bool p[MAX];
  for (int i = 0; i < MAX; ++i)
    p[i] = true;
  p[0] = p[1] = false;

  for (int i = 2; i*i < MAX; ++i) {
    if (p[i]) {
      for (int j = i+i; j < MAX; j+=i)
	p[j] = false;
    }
  }

  vector<int> prime;
  for (int i = 0; i < MAX; ++i) {
    if (p[i])
      prime.push_back(i);
  }

  long long int A, B;
  while (cin >> A >> B) {

    vector<long long int> seg(B*2+1);
    vector<int> fac(B*2+1, INF);
    for (int i = 0; i < seg.size(); ++i) {
      seg[i] = A-B+i;
      if (seg[i] < 2)
	fac[i] = -1;
    }

    for (unsigned int i = 0; i < prime.size(); ++i) {
      for (unsigned int j = (prime[i]-(A-B)%prime[i])%prime[i]; j < seg.size(); j+=prime[i]) {
	if (fac[j] == -1)
	  continue;

	int cnt = 0;
	while (seg[j]%prime[i] == 0) {
	  seg[j] /= prime[i];
	  ++cnt;
	}

	if (cnt > fac[j])
	  fac[j] = -1;
	else
	  fac[j] = cnt;
      }
    }
    
    int ans = 0;
    for (unsigned int i = 0; i < fac.size(); ++i) {
      if (fac[i] != -1)
	++ans;
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 13000
#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  int D;
  cin>>D;
  vector<int> c(26);
  for(int &i:c)
    cin>>i;
  vector<vector<int>> s(D,vector<int>(26));
  for(vector<int> &v:s)
    for(int &i:v)
      cin>>i;
  vector<int> t(D);
  vector<int> A(26,0);
  int mzint=0;
  for(int i=0;i<D;i++){
    int mzi=mzint,mzin=0,k;
    for(int j=0;j<26;j++)
      mzi-=(i+1-A[j])*c[j];
    for(int j=0;j<26;j++){
      int l=mzi+s[i][j]-(i+1-A[j])*c[j];
      if(l>mzin){
        k=j;
        mzin=l;
      }
    }
    A[k]=i+1;
    mzint=mzin;
    t[i]=k+1;
  }
  int M=100000,ans=mzint;
  while(M--){
    int d=rand()%D,q=rand()%26,ans2=ans;
    ans+=s[d][q]-s[d][t[d]-1];
    int mae=-1,ato=D;
    for(int i=d-1;i>=0;i--){
      if(t[i]==t[d]){
        mae=i;
        break;
      }
    }
    for(int i=d+1;i<D;i++){
      if(t[i]==t[d]){
        ato=i;
        break;
      }
    }
    ans-=(ato-d)*(d-mae)*c[t[d]-1];
    mae=-1,ato=D;
    for(int i=d;i>=0;i--){
      if(t[i]==q+1){
        mae=i;
        break;
      }
    }
    for(int i=d;i<D;i++){
      if(t[i]==q+1){
        ato=i;
        break;
      }
    }
    ans+=(ato-d)*(d-mae)*c[q];
    if(ans2<ans)
      t[d]=q+1;
    else
      ans=ans2;
  }
  for(int i:t)
    cout<<i<<endl;
}

Measured memory_bytes: 3716
from collections import Counter
N = int(input())
A = [int(i) for i in input().split(" ")]
count = Counter(A)
S = sum(A)
Q = int(input())
for i in range(Q):
    B,C = map(int,input().split(" "))
    n = count[B]
    count[B] -= n
    count[C] += n
    S = S - B*n + C*n
    print(S)

Measured memory_bytes: 23952