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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

ll score(ll rank){
    if (rank == 1){
        return 300000;
    } else if (rank == 2){
        return 200000;
    } else if (rank == 3){
        return 100000;
    } else {
        return 0;
    }
}

void Main() {
    ll X, Y; cin >> X >> Y;
    ll ans = 0;
    ans += score(X);
    ans += score(Y);
    if (X == 1 && Y == 1){
        ans += 400000;
    }
    cout << ans << endl;
}

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


Measured memory_bytes: 3612
package main

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

func main() {
	sc := NewScanner()
	N := sc.NextInt()
	L := sc.NextIntArray()

	total := 0
	for i := 0; i < N; i++ {
		total += L[i]
	}

	M := maxA(L...)
	if total-M > M {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}
func max(a int, b int) int {
	if a < b {
		return b
	}
	return a
}

func maxA(arg ...int) int {
	var s = arg[0]
	for _, v := range arg {
		s = max(s, v)
	}
	return s
}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


Measured memory_bytes: 640
n=int(input())
p=[int(i) for i in input().split()]
c=0
for i in range(n-1):
    if p[i]==i+1:
        p[i],p[i+1]=p[i+1],p[i]
        c+=1
if p[-1]==n:
    p[-1],p[-2]=p[-2],p[-1]
    c+=1
print(c)


Measured memory_bytes: 13880
using System;
using System.Collections.Generic;
using System.Linq;
using System.Diagnostics;

class Program
{
    static void Main(string[] args)
    {
        var sc = new Scanner();
        long n = sc.nextLong();
        int m = sc.nextInt();
        var a = new Dictionary<long, long>();

        for (int i = 0; i < n; i++)
        {
            long cin = sc.nextLong();
            if (a.ContainsKey(cin))
            {
                a[cin]++;
            }
            else
            {
                a.Add(cin, 1);
            }
        }
        for (int i = 0; i < m; i++)
        {
            int b = sc.nextInt();
            int c = sc.nextInt();

            if (a.ContainsKey(c))
            {
                a[c] += b;
            }
            else
            {
                a.Add(c, b);
            }
        }

        var key = new long[a.Count];
        a.Keys.CopyTo(key,0);
        var value = new long[a.Count];
        a.Values.CopyTo(value,0);

        Array.Sort(key, value);

        long ans = 0;
        int t = a.Count - 1;

        while (0 < n)
        {
            if (value[t] < n)
            {
                ans += key[t] * value[t];
                n -= value[t];
                t--;
            }
            else
            {
                ans += key[t] * n;
                n = 0;
            }
        }

        Console.WriteLine(ans);
    }
}

// chokudai's Scanner
class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }

    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }

    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}

Measured memory_bytes: 32992
#include<iostream>

int N;

int iikakunin(int p,int b[],int suuzi){
	int kosuu = 0;
	for(int i = 1;i <= N/p;i++){
		kosuu += b[p*i-1];
	}
	//std::cout << kosuu << " " << N/p << "\n";
	if(kosuu % 2 == suuzi){
		return 0;
	}
	return 1;
}

int main(){
	std::cin >> N;
	int a[N];
	int b[N];
	int sum = 0;
	for(int i = 0;i < N;i++){
		std::cin >> a[i];
		b[i] = 0;
	}

	for(int i = N;i > 0;i--){
		//std::cout << a[i-1] << i;
		b[i-1] = iikakunin(i,b,a[i-1]);
	}
	for(int i = 0;i < N;i++){
		sum = sum + b[i];
	}
	std::cout << sum << "\n";
	for(int i = 0;i < N;i++){
		if(b[i] == 1)std::cout << i+1 << " ";
	}
	return 0;
}

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

int main() {

    int N, M, T, t[100];
    int imos[30000] = { 0 };
    cin >> N >> M >> T;
    for(int i = 0; i < N; i++) {
        int t; cin >> t;
        imos[t - M]++, imos[t + M]--;
    }
    for(int i = 1; i <= T; i++) {
        imos[i] += imos[i - 1];
    }

    int cnt = 0;
    for(int i = 0; i < T; i++) {
        if(!imos[i]) cnt++;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 3216
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main {
	public static void main(String[] args) throws IOException{

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] str = br.readLine().split(" ");
		
		int a = Integer.parseInt(str[0]);
		int b = Integer.parseInt(str[1]);
		int c = Integer.parseInt(str[2]);
		int d = Integer.parseInt(str[3]);
		int e = Integer.parseInt(str[4]);
		int f = Integer.parseInt(str[5]);
		
		double maxDensity = 0;
		int swMax = 0;
		int sugarMax = 0;
		for(int i = 0; 100*i*a <= f; i++){
			for(int j = 0; 100*(i*a+j*b) <= f; j++){
				int water = 100*(i*a+j*b);
				int sugarLimit = (i*a+j*b)*e;
				
				for(int k = 0; k*c <= sugarLimit && water + k*c <= f; k++){
					for(int l = 0; k*c + l*d <= sugarLimit && water + k*c + l*d <= f; l++){
						
						int sugar = k*c + l*d;
						double tmpDens = (double)sugar/(sugar+water);
						
						if(tmpDens > maxDensity){
							maxDensity = tmpDens;
							swMax = sugar+water;
							sugarMax = sugar;
						}
					}
				}
			}
		}
		
		if(sugarMax == 0){
			System.out.println(100*a + " " + sugarMax);
		}
		else {
			System.out.println(swMax + " " + sugarMax);
		}
	
	}
 
}


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

// int/long:		-2,147,483,648 - 2,147,483,647 (-2^31 <= int < 2^31)
// long/long long:	-9,223,372,036,854,775,808 - 9,223,372,036,854,775,807 (-2^63 <= long < 2^63)

#define	INF (1<<30)
//1,073,741,824
//= 536,870,912 *2

#define	MOD 1000000007

#define	Rep0(i, n)	for (auto i=0; i<n; i++)
#define	Rep1(i, n)	for (auto i=1; i<=n; i++)
#define Sort(P)	sort(P.begin(), P.end())
#define Rev(P)	reverse(P.begin(), P.end())

int	main() {
	int D;
	cin >>D;
	vector<int> c(27, 0);
	Rep1(i, 26)
		cin >>c.at(i);
	vector<vector<int>> s(D+1, vector<int> (27, 0));
	Rep1(i, D)
		Rep1(j, 26)
			cin >>s.at(i).at(j);
	vector<int> t(D+1);
	Rep1(i, D)
		cin >>t.at(i);
	//
	vector<int> LAST(27, 0);
	int S=0;
	Rep1(i, D) {
		S +=s.at(i).at(t.at(i));
		Rep1(j, 26) {
			if (j==t.at(i)) {
				LAST.at(j)=0;
			} else {
				LAST.at(j)++;
				S -=c.at(j)*LAST.at(j);
			}
		}
		cout <<S <<endl;
	}
	return 0;
}



Measured memory_bytes: 3680
#include<iostream>
#include<string>
#include<math.h>
using namespace std;
using ll = long long;

int main() {
	int w, h;
	cin >> h >> w;
	char s[50][50];
	for (int i = 0;i < h;i++) {
		for (int j = 0;j < w;j++) {
			cin >> s[i][j];
		}
	}
	int dx[4] = { 1, 0, -1, 0 };
	int dy[4] = { 0, 1, 0, -1 };
	string ans = "Yes";
	int flag = 0;
	for (int i = 0;i < h;i++) {
		for (int j = 0;j < w;j++) {
			if (s[i][j] != '#')continue;
			int num = 0;
			for (int d = 0; d < 4; d++) {
				int ni = i + dy[d];
				int nj = j + dx[d];
				if (ni < 0 or h <= ni) continue;
				if (nj < 0 or w <= nj) continue;
				if (s[ni][nj] == '#')num++;
			}
			if (num == 0) {
				ans = "No";
				flag = 1;
				break;
			}
		}
		if (flag)break;
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
const ll INF=mod*mod;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(x) (x).begin(),(x).end()
ll min(ll a,ll b){
  if(a>b){
    return b;
    }
      else{
        return a;
      }
  }
  
  ll max(ll a,ll b){
    if(a>b){
      return a;
    }
    else{
      return b;
    }
  }

ll power(ll a,ll b){
 ll ans=1;
 for(ll i=1;i<=b;i++){
ans*=a;
  }
  return ans;
}

 ll gcd(ll m,ll n){
 	if(n==0){
       return m;
     }
   return gcd(n,m%n);
 }
ll lcm(ll a,ll b){
  ll g=gcd(a,b);
  return a/gcd(a,b)*b;
		

}
int main(){
  ll N;
  cin>>N;
  vector<ll>A(N);
  vector<ll>B(N);
  vector<ll>C(N-1);
  ll ans=0;
  
  rep(i,N){
    cin>>A[i];
  }
  
  rep(i,N){
    cin>>B[i];
    ans+=B[i];
  }

rep(i,N-1){
  cin>>C[i];
}
  
 for(ll i=1;i<N;i++){
   
if(A[i]==A[i-1]+1){
  ans+=C[A[i-1]-1];
}
    
 }
cout<<ans<<endl;

}


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

static const int N = 36;

struct Card { char suit; int value; };

void bubbleSort(Card a[], int n) {
    int flag = 1;

    for (int i = 0; flag; i++) {
        flag = 0;
        for (int j = n - 1; j > i; j--) {
            if (a[j].value < a[j-1].value) {
                swap(a[j], a[j-1]);
                flag = 1;
            }
        }
    }
}

void selectionSort(Card a[], int n) {
    for (int i = 0; i < n; i++) {
        int min = i;
        for (int j = i + 1; j < n; j++) {
            if (a[j].value < a[min].value) {
                min = j;
            }
        }
        if (min != i) {
            swap(a[min], a[i]);
        }
    }
}

void output(Card a[], int n) {
    for (int i = 0; i < n; i++) {
        if (i > 0) {
            cout << ' ';
        }
        cout << a[i].suit << a[i].value;
    }
    cout << endl;
}

bool isStable(Card a[], Card b[], int n) {
    for (int i = 0; i < n; i++) {
        if (a[i].suit != b[i].suit) {
            return false;
        }
    }
    return true;
}

int main() {
    Card a[N], b[N];
    int n;

    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a[i].suit >> a[i].value;
        b[i] = a[i];
    }

    bubbleSort(a, n);
    output(a, n);
    cout << "Stable" << endl;

    selectionSort(b, n);
    output(b, n);
    if (isStable(a, b, n)) {
        cout << "Stable" << endl;
    } else {
        cout << "Not stable" << endl;
    }

    return 0;
}



Measured memory_bytes: 3084
# -*- coding:utf-8 -*-
import itertools
A, B, C, D, E, F = map(int, input().split())
waterWeights = []
sugarWeights = []
ansFactor = []
for tmp in range(F//(100*A)+1):
    for tmp2 in range(F//(100*B)+1):
        factor = 100*A*tmp+100*B*tmp2
        if factor <= F:
            waterWeights.append(factor)
        else:
            pass

for tmp in range(F//C+1):
    for tmp2 in range(F//D+1):
        factor = C*tmp + D*tmp2
        if factor <= F:
            sugarWeights.append(factor)
        else:
            pass

for combi in itertools.product(waterWeights, sugarWeights):
    if combi[0]+combi[1] <= F and combi[0]+combi[1] != 0:
        if E*combi[0]/100 >= combi[1]:
            ansFactor.append(combi)
        else:
            pass
    else:
        pass
ans = sorted(ansFactor, key = lambda i: i[1]*100/(i[0]+i[1]), reverse=True)
print(str((ans[0])[0]+(ans[0])[1])+' '+str((ans[0])[1]))

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

int main() {
	int S, h, m, s;
		cin >> S;
		h = S / 3600;
		m = S % 3600 / 60;
		s = S % 3600 % 60;

			cout << h << ":" << m << ":" << s << endl;
	return 0;
}

Measured memory_bytes: 3100
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <functional>
#include <ctime>
#include <fstream>
#include <cmath>
#include <limits>
#include <chrono>
#include <numeric>
#include <type_traits>
#include <iomanip>
#include <float.h>
#include <math.h>
#include <cassert>
#pragma warning (disable: 4996)
using namespace std;

using ll = long long;
unsigned euclidean_gcd(unsigned a, unsigned b) {
    if (a < b) return euclidean_gcd(b, a);
    unsigned r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

ll ll_gcd(ll a, ll b) {
    if (a < b) return ll_gcd(b, a);
    ll r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

struct UnionFind {
    vector <ll> par;
    vector <ll> siz;
    UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    ll root(ll x) {
        while (par[x] != x) {
            x = par[x] = par[par[x]];
        }
        return x;
    }
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) {
        return root(x) == root(y);
    }

    ll size(ll x) {
        return siz[root(x)];
    }
};

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

long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}

ll merge_cnt(vector<ll>& a) {
    int n = a.size();
    if (n <= 1) { return 0; }

    ll cnt = 0;
    vector<ll> b(a.begin(), a.begin() + n / 2);
    vector<ll> c(a.begin() + n / 2, a.end());

    cnt += merge_cnt(b);
    cnt += merge_cnt(c);

    int ai = 0, bi = 0, ci = 0;
    while (ai < n) {
        if (bi < b.size() && (ci == c.size() || b[bi] <= c[ci])) {
            a[ai++] = b[bi++];
        }
        else {
            cnt += n / 2 - bi;
            a[ai++] = c[ci++];
        }
    }
    return cnt;
}

int main() {
    ll n;
    cin >> n;
    ll m;
    cin >> m;
    vector<pair<ll, ll>> z(m);
    for (int i = 0; i < m; i++) {
        cin >> z[i].first >> z[i].second;
    }
    sort(z.begin(), z.end());
    ll ans = 0;
    ll ms = -12345;
    for (int i = 0; i < m; i++) {
        if (ms <= z[i].first) {
            ans++;
            ms = z[i].second;
        }
        else {
            ms = min(ms, z[i].second);
        }
    }
    cout << ans << endl;
}

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

using namespace std;

#define REPI(x) for(int i=0;i<x;i++)
#define REPJ(x) for(int j=0;j<x;j++)
#define SCANFD(x) scanf("%d",&x)

struct Restaurant {
    int num;
    string name;  
    int point;
};

bool cmp (const Restaurant &a1, const Restaurant &a2)
{
  if (a1.name == a2.name)
    return a1.point > a2.point;
    
  return a1.name < a2.name;  
}

int main(){
  int N;
  Restaurant r;
  vector<Restaurant> rv;

  cin >> N;

  REPI (N)
  {
    r.num = i+1;
    cin >> r.name >> r.point;
    rv.push_back (r);
  }

  sort(rv.begin (), rv.end (), cmp);

  for (vector<Restaurant>::iterator i = rv.begin (); i != rv.end (); i++)
  {
    printf ("%d\n", (*i).num);
  }
  return 0;
}


Measured memory_bytes: 256
import sys
import heapq
input = sys.stdin.readline

N, M = list(map(int, input().strip().split()))
A = [-int(x) for x in input().strip().split()]
heapq.heapify(A)
for m in range(M):
    a = heapq.heappop(A)
    heapq.heappush(A, a / 2)
print(sum([int(-a) for a in A]))

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

int main(){
  string n;
  cin >> n;
  bool ju = false;
  for(int i = 0;i < 3;i++){
    if(n[i] == '7') ju = true;
  }
  if(ju) cout << "Yes";
  else cout << "No";
}

Measured memory_bytes: 3596
#include<stdio.h>

int main(){

int x,y,z,N,p;
int max=0,sum=0;

while(1){
scanf("%d",&N);if(N==0)break;
for(int i=0;i<N;i++){
scanf("%d %d %d",&p,&x,&y);
if(max<x+y){max=x+y;sum=p;}
}
printf("%d %d\n",sum,max);
sum=0;max=0;
}
return 0;
}

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

template<typename tp> inline void read(tp &x) {
  x = 0; char c = getchar(); int f = 0;
  for (; c < '0' || c > '9'; f |= c == '-', c = getchar());
  for (; c >= '0' && c <= '9'; x = (x << 3) + (x << 1) + c - '0', c = getchar());
  if (f) x = -x;
}
const int N = 4e5 + 233;
int n, q, cnt = 0;
int b[N];
vector<int> vec[N];

namespace seg {
  int tr[N << 2];
  const int xb = 2e5 + 233;
  inline void Set(int x, int val) {
    // cout << x << " " << val << " Set\n";
    ++ x;
    for (x += xb; x; x >>= 1)
      tr[x] = min(tr[x], val);
  }
  inline int Query(int s, int t) {
    // cout << s << " " << t << "\n";
    ++ s; ++ t;
    int ans = 1e18;
    for (s += xb - 1, t += xb + 1; s ^ t ^ 1; s >>= 1, t >>= 1) {
      if (~s & 1) ans = min(ans, tr[s ^ 1]);
      if ( t & 1) ans = min(ans, tr[t ^ 1]);
    }
    // cout << ans << "\n";
    return ans;
  }
}

main(void) {
  memset(seg::tr, 38, sizeof seg::tr);
  read(n);
  for (int i = 1; i <= n; i ++)
    read(b[i]), cnt += b[i] == 0;
  read(q);
  for (int i = 1; i <= q; i ++) {
    int x, y; read(x); read(y);
    vec[x].push_back(y);
  }
  seg::Set(0, 0);
  for (int x = 1; x <= n; x ++) {
    for (int y : vec[x]) {
      seg::Set(y, seg::Query(x - 1, y));
    }
    seg::Set(x, seg::Query(x - 1, x - 1) + (b[x] == 1 ? 1 : -1));
  }
  cout << seg::Query(n, n) + cnt << "\n";
}


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

int main() {
    /* Input */
    string S, T;
    cin >> S;
    cin >> T;

    /* Main Logic */
    string subT = T.substr(0, T.size() - 1);
    if (S == subT) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 3568
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, e) for (int i = (int)(s); i <= (int)(e); i++)
#define printYesNo(is_ok) puts(is_ok ? "Yes" : "No");
#define SORT(v) sort(v.begin(), v.end());
#define RSORT(v) sort(v.rbegin(), v.rend());
#define REVERSE(v) reverse(v.begin(), v.end());

int main()
{
  int V, E;
  cin >> V >> E;
  vector<vector<int>> graph(V, vector<int>(V, -1));
  rep(i, E)
  {
    int s, t, d;
    cin >> s >> t >> d;
    graph[s][t] = d;
  }

  long long ans = 1e9;
  rep(s, V)
  {
    vector<vector<long long>> dp(pow(2, V), vector<long long>(V, 1e9));
    dp[1 << s][s] = 0;
    rep(i, pow(2, V) - 1)
    {
      rep(j, V)
      {
        rep(nj, V)
        {
          if (graph[j][nj] == -1)
            continue;
          if ((i >> nj & 1) == 1)
            continue;
          if ((i >> j & 1) == 0)
            continue;
          int ni = i + (1 << nj);
          dp[ni][nj] = min(dp[ni][nj], dp[i][j] + graph[j][nj]);
        }
      }
    }
    long long score = 1e9;
    rep(i, V)
    {
      if (graph[i][s] == -1)
        continue;
      score = min(score, dp[pow(2, V) - 1][i] + graph[i][s]);
    }
    ans = min(ans, score);
  }
  if (ans == 1e9)
    ans = -1;
  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 7820
import java.util.Scanner;
import java.util.Arrays;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String a = sc.next();
		
		System.out.println(a.replace("AAA", "").length() == 0 || a.replace("BBB", "").length() == 0 ? "No" : "Yes");
	}
}


Measured memory_bytes: 35676
#include<bits/stdc++.h>
using namespace std;
int f[]={5,7,5,7,7};
int n;
int t[50];
string str;
 
int solve(){
  for(int i=0;i<n;i++){
    int a=i,j;
    for(j=0;j<5;j++){
      int b=0;
      while(b<f[j])b+=t[a++];
      if(b>f[j])break;
    }
    if(j==5)return i;
  }
  return 0;
}
 
int main(){
  while(1){
    cin>>n;
    if(n==0)break;
    for(int i=0;i<n;i++){
      cin>>str;
      t[i]=str.size();
    }
    cout<<solve()+1<<endl;
  }
  return 0;
}

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

int main(){
  int N,A,B;cin>>N>>A>>B;
  int ans=0;
  for(int i=1;i<=N;i++){
    int res=0,d=i;
    while(d){
      res+=d%10;
      d/=10;
    }
    if(res>=A&&res<=B)ans+=i;
  }
  cout<<ans<<endl;
}


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

int main() {
	int d;
	while (cin >> d) {
		int64_t s = 0;
		for (int64_t i = d; i <= 600 - d; i += d) {
			s += i * i * d;
		}

		cout << s << endl;
	}
}


Measured memory_bytes: 3004
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define ArraySizeOf(array)     (sizeof(array) / sizeof(array[0]))
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define int long long
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define _GLIBCXX_DEBUG
int INF = 1e9+7;
unsigned NthDayOfWeekToDay(unsigned n, unsigned dow, unsigned dow1)
{
unsigned day;
if(dow < dow1) dow += 7;
day = dow - dow1;
day += 7 * n - 6;
return day;
}
unsigned DayToWeekNumber(unsigned day)
{
  return (day - 1) / 7 + 1;
}
unsigned AnotherDayOfWeek(unsigned day, unsigned day0, unsigned dow0)
{
  return (dow0 + 35 + day - day0) % 7;
}
using namespace std;
signed main(){
  int N,A,B;
  cin>>N>>A>>B;
  if((B-A)%2==0)cout<<(B-A)/2<<endl;
  else cout<<min(min(min(B-1,N-A),(N-A+N-B+1)/2),A+(B-1-A)/2)<<endl;
}

Measured memory_bytes: 3608
import java.util.*;
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    
    int a[][] = new int[3][3];    
    for(int i = 0 ; i < 3 ; ++i){
      for(int j = 0 ; j < 3 ; ++j){
        a[i][j] = sc.nextInt();
      }
    }
    
    int n = sc.nextInt();
    int b[] = new int[n]; 
    for(int k = 0 ; k < n ; ++k){
      b[k] = sc.nextInt();
    }

    for(int i = 0 ; i < 3 ; ++i){
      for(int j = 0 ; j < 3 ; ++j){
        for(int k = 0 ; k < n ; ++k){
        if(a[i][j] == b[k]){
          a[i][j] = 0;
        }
        }
      }
    }
    
    String ans = "No";
    
    //横
    for(int i = 0 ; i < 3 ; ++i){
      boolean ju = false;
      for(int j = 0 ; j < 3 ; ++j){
        if(a[i][j] == 0){
          ju = true;
        }else{
          ju = false;
          break;
        }
      }
      if(ju){
        ans = "Yes";
        break;
      }
    }
    //縦
    for(int j = 0 ; j < 3 ; ++j){
      boolean ju = false;
      for(int i = 0 ; i < 3 ; ++i){
        if(a[i][j] == 0){
          ju = true;
        }else{
          ju = false;
          break;
        }
      }
      if(ju){
        ans = "Yes";
        break;
      }
    }
    //斜め
    if(a[0][0]==0 && a[1][1]==0 && a[2][2]==0){
      ans = "Yes";
    }
    
    if(a[0][2]==0 && a[1][1]==0 && a[2][0]==0){
      ans = "Yes";
    }
    
    

    System.out.println(ans);
    
  }
}

Measured memory_bytes: 35596
N = int(input())
X = list(map(int, input().split()))

SINGLE_SUM = sum(X)
DOUBLE_SUM = sum([x ** 2 for x in X])


def f(n, p):
    return n * p ** 2 - 2 * p * SINGLE_SUM + DOUBLE_SUM


min_ = None
for p in range(min(X), max(X) + 1):
    val = f(N, p)
    if min_ is None or val < min_:
        min_ = val

print(min_)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define trace1(a) cout << a << 'n';
#define trace2(a, b) cout << a << ' ' << b << 'n';
#define trace3(a, b, c) cout << a << ' ' << b << ' ' << c << 'n';
#define trace4(a, b, c, d) cout << a << ' ' << b << ' ' << c << ' ' << d << 'n';
#define trace5(a, b, c, d, e) cout << a << ' ' << b << ' ' << c << ' ' << d << ' ' << e << 'n';
#define trace6(a, b, c, d, e, f) cout << a << ' ' << b << ' ' << c << ' ' << d << ' ' << e << ' ' << f << 'n';
#define range(n) for(int i = 0; i < n; i++)
#define printArr(harry, tam) range(tam) cout << harry[i] << " n"[i == tam -1];
#define maxn -2000000 //negative value to break code and force you to put right constraint
#define mod 1000000007
#define md(x) (x) % mod;
#define sc scanf
#define pr printf
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ps push
#define prt(x) cout << (#x) << " is " << (x) << endl
#define EPS 1e-9
#define INF 1000000000
#define INFd 1e9
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ll> vll;
typedef vector<double> vd;

int main()
{
    unsigned long long s;
    cin>>s;
    if(s<=1e9)
    {
        cout<<0<<" "<<0<<" "<<1<<" "<<0<<" "<<0<<" "<<s;
    }
    else
    {
      cout<<0<<" "<<0<<" "<<1000000000<<" "<<1<<" ";
        ll y=(ceil)(s/1000000000.0);
        ll x=1000000000*y-s;

        cout<<x<<" "<<y;
    }
}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<cstring>
#include<map>
#include<cmath>
#define rep(i,j,k) for(register int i = j; i <= k; i++)
#define dow(i,j,k) for(register int i = j; i >= k; i--)
#define ll long long
using namespace std;

inline ll read() { 
	ll s = 0, t = 1; char c = getchar();
	while( !isdigit(c) ) { if( c == '-' ) t = -1; c = getchar(); }
	while( isdigit(c) ) s = s * 10 + c - 48, c = getchar();
	return s * t;
}

const int N = 1e3+5; const ll inf = 1e10;
bool vis[N]; int p[N], tot = 0;
inline void pre(int n) { 
	int t;
	rep(i,2,n) { 
		if( !vis[i] ) p[++tot] = i;
		for(register int j = 1; j <= tot && (t = i * p[j]) <= n; j++) { 
			vis[t] = 1;
			if( i % p[j] == 0 ) break;
		}
	}
//	rep(i,1,10) cout<<p[i]<<" "; cout<<endl;
}
map<ll,int> f;
const int M = 1e5+5;
ll aa[M], bb[M], a[M];

int main() { 
//	freopen("in.txt","r",stdin);
	pre(1000);
	int n = read(); ll x;
	rep(i,1,n) a[i] = read();
	rep(i,1,n) { 
		aa[i] = bb[i] = 1;
		for(register int j = 1; p[j] * p[j] <= a[i] && j <= tot; j++) { 
			if( a[i] % p[j] == 0 ) { 
				int cnt = 0;
				while( a[i] % p[j] == 0 ) a[i] /= p[j], cnt++;
				cnt %= 3;
				if( cnt == 1 ) aa[i] *= p[j], bb[i] *= p[j] * p[j];
				else if( cnt == 2 ) aa[i] *= p[j] * p[j], bb[i] *= p[j];
			}
		}
		aa[i] *= a[i];
		x = sqrt(a[i]);
		if( x * x == a[i] ) bb[i] *= x;
		else { 
			if( inf / a[i] / a[i] >= bb[i] ) bb[i] *= a[i] * a[i];
			else bb[i] = 0;
		}
		f[aa[i]]++;
	}
	
	int ans = 0; bool flag =  1;
	rep(i,1,n) { 
		if( aa[i] == 1 ) ans += flag, flag = 0;
		else { 
			ans += max(f[aa[i]],f[bb[i]]);
			f[aa[i]] = f[bb[i]] = 0;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 12928
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    long ans = 1;
    for (int i = 1; i <= N; i++) {
      ans *= i;
      ans = ans % 1000000007;
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 23636
#include <stdio.h>
#include <stdlib.h>

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

void empty(int *x,int *y){
  int i,j;
  for(i=0;i<3;i++){
    for(j=0;j<3;j++){
      if(!puz[i][j]){
	*x=j;
	*y=i;
	return;
      }
    }
  }
}

void swap(int *a,int *b){
  int tmp=*a;
 
  *a=*b;
  *b=tmp;
}

int cal(){
  int v,i,sum=0;
  for(i=0;i<9;i++){
    v=puz[i/3][i%3];
    if(v){
      v--;
      sum += abs(i/3-v/3) + abs(i%3-v%3);
    }
  }
  return sum;
}

int dfs(int x,int y,int p,int dep,const int lim){
  
  int i,h,nx,ny,res;

  h=cal();
  
  if(h==0){
    return dep;
  }
  
  if(dep+h > lim){
    return -1;
  }
  
  for(i=0;i<4;++i){
    nx=x+dx[i];
    ny=y+dy[i];
    
    if(~p && i==(p+2)%4)
      continue;
    if(!(0 <= nx && nx < 3 && 0 <= ny && ny < 3))
      continue;
    
    swap(&puz[y][x],&puz[ny][nx]);
    
    res=dfs(nx,ny,i,dep+1,lim);
    
    if(~res){
      return res;
    }
    swap(&puz[y][x],&puz[ny][nx]);
  }
  return -1;
}

int main(){
  
  int i,j,ans,x,y,l;
  
  for(i=0;i<3;i++){
    for(j=0;j<3;j++){
      scanf("%d",&puz[i][j]);
    }
  }
  
  empty(&x,&y);

  for(l=0;l<100;l++){
    for(i=0;i<3;i++){
      for(j=0;j<3;j++){
	tmp[i][j]=puz[i][j];
    }
    }
    ans=dfs(x,y,-1,0,l);

    if(ans!=-1){
      printf("%d\n",ans);
      break;
    }
    for(i=0;i<3;i++){
      for(j=0;j<3;j++){
	puz[i][j]=tmp[i][j];
    }
    }
    ans=-1;

    if(l==99){
      printf("%d\n",ans);
  }
  }
  return 0;
}



Measured memory_bytes: 2112
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
	int n;
	cin >> n;
	vector<int> d(201000, 0);
	int a, b;
	for (int i = 0; i < n; i++) {
		cin >> a >> b;
		d[a + b]++;
	}
	for (int i = 0; i < 201000; i++) {
		if (d[i] > 0) {
			int k = d[i] / 2;
			int kk = d[i] % 2;
			if (kk > 0) {
				cout << i << ' ' << 0 << endl;
			}
			d[i + 1] += k;
		}
	}
	return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>

using namespace std;

typedef long long ll;

const int MOD = 1e9 + 7;
const int INF = 1e9 + 239;

int mul(int a, int b) {
	return ((ll)a * b) % MOD;
}

signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	int n;
	cin >> n;
	vector<int> f(n);
	vector<int> s(n);
	for (auto &t : f) {
		cin >> t;
	}
	for (auto &t : s) {
		cin >> t;
	}
	vector<int> l(n, 1);
	vector<int> r(n, INF);
	{
		int c = 0;
		for (int i = 0; i < n; i++) {
			if (c < f[i]) {
				l[i] = f[i];
				r[i] = f[i];
				c = f[i];
			} else {
				r[i] = c;
			}
		}
	}
	{
		int c = 0;
		for (int i = n - 1; i >= 0; i--) {
			if (c < s[i]) {
				l[i] = max(l[i], s[i]);
				r[i] = min(r[i], s[i]);
				c = s[i];
			} else {
				r[i] = min(r[i], c);
			}
		}
	}
	int ans = 1;
	for (int i = 0; i < n; i++) {
		if (l[i] > r[i]) {
			cout << 0 << endl;
			return 0;
		}
		ans = mul(ans, r[i] - l[i] + 1);
	}
	cout << ans << endl;
}

Measured memory_bytes: 4752
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <complex>
#include <vector>
#include <limits>
#include <iomanip>
#include <cassert>

using namespace std;

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

#define debug(x) cout << #x << " = " << (x) << endl;
#define rep(i, n) for(int i = 0;i < n;i++)
#define repr(i, n) for(int i = n-1;i >= 0;i--)
#define pb push_back
#define mp make_pair
#define F first
#define S second

const long double pi = 3.141592653589793;
const int mod = 1e9 + 7;

int n, m, w;
unordered_map<int, set<int>> ux, uy;

int main() {

 // freopen("input.in","r",stdin);
 // freopen("output.out","w",stdout);
 int x, y;
 cin>>n>>m>>w;
 rep(i, w) {
   cin>>x>>y;;
   ux[x].insert(y);
   uy[y].insert(x);
 }

 int mx = 0, my = 0;
 for(auto it: ux) {
   mx = max(mx, (int) (it.S).size());
 }
 for(auto it: uy) {
   my = max(my, (int) (it.S).size());
 }

 unordered_map<int, int> ab;
 for(auto it: uy) {
  if(my == (it.S).size()) ab[it.F]=0;
 }

 int ans = mx + my;
 int ct = 0;
 for(auto it: ux) {
   if(mx == (it.S).size()) {
     ct++;
     for(auto it1: it.S) {
       if(ab.count(it1) == 1) ab[it1]++;
     }
   }
 }

 for(auto it : ab) {
   if(it.S != ct) {cout<<ans<<endl;return 0;}
 }
 cout<<ans-1;

 return 0;
}


Measured memory_bytes: 100348
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <stack>
#include <set>
#include <bitset>
using namespace std;
#define fast_io ios_base::sync_with_stdio (false) ; cin.tie(0) ; cout.tie(0) ;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define all(v) v.begin(), v.end()

typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;

ll mpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = mpow(a,b/2); return memo*memo%MOD;}
  else return mpow(a,b-1) * a % MOD;
}
ll lpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = lpow(a,b/2); return memo*memo;}
  else return lpow(a,b-1) * a;
}
ll gcd(ll a, ll b){
  if(b==0) return a;
  else return gcd(b, a%b);
}
vector<ll> kaijo_memo;
ll kaijo(ll n){
  if(kaijo_memo.size() > n) return kaijo_memo[n];
  if(kaijo_memo.size() == 0) kaijo_memo.push_back(1);
  while(kaijo_memo.size() <= n) kaijo_memo.push_back(kaijo_memo[kaijo_memo.size()-1] * kaijo_memo.size() % MOD);
  return kaijo_memo[n];
}
vector<ll> gyaku_kaijo_memo;
ll gyaku_kaijo(ll n){
  if(gyaku_kaijo_memo.size() > n) return gyaku_kaijo_memo[n];
  if(gyaku_kaijo_memo.size() == 0) gyaku_kaijo_memo.push_back(1);
  while(gyaku_kaijo_memo.size() <= n) gyaku_kaijo_memo.push_back(gyaku_kaijo_memo[gyaku_kaijo_memo.size()-1] * mpow(gyaku_kaijo_memo.size(), MOD-2) % MOD);
  return gyaku_kaijo_memo[n];
}

ll nCr(ll n, ll r){
  ll ret = 1;
  rep(i,r){
    ret *= n-i;
    ret %= MOD;
    ret *= mpow(r-i, MOD-2);
    ret %= MOD;
  }
  return ret;
}


int main(void){
  fast_io
  cout<<fixed<<setprecision(15);

  ll n,a,b;cin>>n>>a>>b;
  cout << ((mpow(2, n) - 1 + MOD)%MOD - (nCr(n, a) + nCr(n, b))%MOD + MOD) %MOD<<endl;
  return 0;
}

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

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

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> tiii;

const int INF=2000000000;
const ll LINF = 1e18+5;

struct edge{
    int to, cost;
    edge(int t, int c) {to = t; cost = c;};
};

int N, u, v;

int d[100000];
int d2[100000];
vector<edge> G[100000];

void dijkstra(int s) {
    priority_queue<pii, vector<pii>, greater<pii> > que;
    rep(i,N) {
        d[i] = 2000000;
    }
    d[s] = 0;
    que.push(pii(0,s));
    while(!que.empty()) {
        pii p = que.top();
        que.pop();
        int v = p.second;
        if(d[v] < p.first) continue;
        rep(i, G[v].size()) {
            edge e = G[v][i];
            if(d[e.to] > d[v] + e.cost) {
                d[e.to] = d[v] + e.cost;
                que.push(pii(d[e.to], e.to));
            }
        }
    }
}

void dijkstra2(int s) {
    priority_queue<pii, vector<pii>, greater<pii> > que;
    rep(i,N) {
        d2[i] = 2000000;
    }
    d2[s] = 0;
    que.push(pii(0,s));
    while(!que.empty()) {
        pii p = que.top();
        que.pop();
        int v = p.second;
        if(d2[v] < p.first) continue;
        rep(i, G[v].size()) {
            edge e = G[v][i];
            if(d2[e.to] > d2[v] + e.cost) {
                d2[e.to] = d2[v] + e.cost;
                que.push(pii(d2[e.to], e.to));
            }
        }
    }
}

bool pairCompare(const pii& Fir, const pii& Sec)
{
    return Fir.first > Sec.first; // 1番目について降順
}

int main() {
    cin >> N >> u >> v;
    u--;
    v--;
    int A[100000] = {};
    int B[100000] = {};
    rep(i,N-1) {
        cin >> A[i] >> B[i];
        A[i]--;
        B[i]--;
    }
    rep(i,N-1) {
        G[A[i]].push_back(edge(B[i], 1));
        G[B[i]].push_back(edge(A[i], 1));
    }
    
    dijkstra(u);
    dijkstra2(v);
    vector<pii> fromA;
    rep(i,N) {
        fromA.push_back(pii(d2[i], i));
    }
    // sortできる
    sort(fromA.begin(), fromA.end(), pairCompare); 
    for(auto& v : fromA) {
        int fromT = d[v.second];
        int highdif = d2[v.second] - d2[u];
        if(highdif<=0) {
            // 今現時点が最高地点
            cout << d2[u] - 1  << endl;
            return 0;
        }
        if (highdif == fromT) {
            cout << d2[v.second] - 1 << endl;
            return 0;
        }
        int needhigh = (fromT - highdif) / 2;
        if(d2[u] - needhigh > needhigh) {
            cout << d2[v.second] - 1 << endl;
            return 0;
        }
    }

    return 0;
}

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

int main(){
    int n, m;
    cin >> n >> m;
    vector<int> h(n, 0), hantei(n, 1);
    rep(i,n) cin >> h[i];
    rep(i, m){
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        if (h[a] <= h[b]) hantei[a] = 0;
        if (h[a] >= h[b]) hantei[b] = 0;
    }
    int ans = 0;
    rep(i,n) if (hantei[i] == 1) ans++;
    cout << ans << endl;
}

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

int main(){
  int n,q;
  cin>>n;
  vector<int>a(n);
  rep(i,n){
    cin>>a[i];
  }
  cin>>q;
  vector<int>b(q);
  rep(i,q){
    cin>>b[i];
  }
  int ans=0;
  rep(i,q){
    rep(j,n){
      if(a[j]==b[i]){
        ans++;
        break;
      }
    }
  }
  cout<<ans<<endl;
} 


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

using namespace std;

const int N = 105, MAX_K = 1e5 + 5, mod = 1e9 + 7;
int n, K, dp[N][MAX_K], a[N];

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

    cin >> n >> K;
    for (int i = 1; i <= n; ++i) cin >> a[i];

    for (int i = 0; i <= K; ++i) dp[0][i] = 1;

    for (int i = 1; i <= n; ++i) {
        for (int j = 0; j <= K; ++j) {
            dp[i][j] = (dp[i - 1][j] + mod - (j - a[i] < 0 ? 0 : dp[i - 1][ j - a[i] - 1 ]) ) % mod;
            if (j) dp[i][j] = (dp[i][j - 1] + dp[i][j]) % mod;
        }
    }

    cout << (dp[n][K] + mod - (K ? dp[n][K - 1] : 0) ) % mod;

    return 0;
}


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

int main(){
  string p,s;
  cin>>p>>s;
  p=p+p;
  bool flag=false;
  for(int i=0;i<(int)p.size()-(int)s.size()+1;i++){

    string t=p.substr(i, s.size() );

    if( t == s ){
      flag=true;
      break;
    }
  }
  if(flag){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
  return 0;
}


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

#define ll long long
#define endl '\n'
#ifndef _WINDOWS
// no getchar_unlocked on Windows so just call getchar
#define getchar getchar_unlocked
#endif

template <typename Func>
inline void loop(int e, Func&& f) {
    for (int i = 0; i < e; i++) {
        std::forward<Func>(f)(i);
    }
}
template <typename Func>
inline void loop(int s, int e, Func&& f) {
    for (int i = s; i < e; i++) {
        std::forward<Func>(f)(i);
    }
}
template <typename T>
inline void scanpn(T& num) {
    int c;
    num = 0;
    c = getchar();
    // bool negative = false;
    // if (c == '-') {
    // 	negative = true;
    // 	c = getchar();
    // }
    for (; (c > 47 && c < 58); c = getchar()) num = num * 10 + c - 48;
    // if (negative)
    //     number = -number;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string n;
    cin >> n;
    switch (n[(int)n.length() - 1] - '0') {
        case 2:
        case 4:
        case 5:
        case 7:
        case 9:
            cout << "hon" << endl;
            break;
        case 0:
        case 1:
        case 6:
        case 8:
            cout << "pon" << endl;
            break;
        case 3:
            cout << "bon" << endl;
        default:
            break;
    }
    return 0;
}


Measured memory_bytes: 3640
#include<bitset>
#include<math.h>
#include<limits.h>
#include<iostream>
#include<string>
#include<vector>
#include<cstdio>
#include<sstream>
#include<list>
#include<queue>
#include<algorithm>
#include<functional>
#include<map>
#include<set>
#include<utility>
#include<initializer_list>
#include<tuple>
#include<regex>
using namespace std;
#define ull unsigned long long
#define ll long long
#define rep(i, a, n) for(int i=(a);i<(int)(n);i++)
#define repc(i, a, n) for(int i=(a);i<=(int)(n);i++)
#define all(t) t.begin(), t.end()
#define rall(t) t.rbegin(), t.rend()
#define mat(type, row, col, init) vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout<<(cond? "Yes":"No")<<endl;
#define YES(cond) cout<<(cond? "YES":"NO")<<endl;
#define DBG(str) cerr<<(str)<<endl;
int main() {
	int a, b, c, x, y;
	cin >> a >> b >> c >> x >> y;
	vector<int>dp(max(x, y) + 1, 0);
	repc(i, 0, x) {
	}
	
	repc(i, 1, min(x, y)) {
		dp[i] = min(dp[i-1] + a + b, dp[i-1] + 2 * c);
	}
	ll sum = dp[min(x, y)];
	int d = max(x, y) - min(x, y);
	bool greaterA = x > y;
	if (greaterA) {
		sum += d*min(a, 2 * c);
	}
	else {
		sum += d*min(b, 2 * c);
	}
	cout << sum << endl;
	
	return 0;
}





Measured memory_bytes: 640
#include<stdio.h>
#define MAX 10000
#define NIL -1

struct Node { int p, l, r; };
struct Node T[MAX];
int n;

// ??????????????? 
void preParse(int u) {
    if (u == NIL) return;
    printf(" %d", u);
    preParse(T[u].l);
    preParse(T[u].r);
}

// ???????????????
void inParse(int u) {
    if (u == NIL ) return;
    inParse(T[u].l);
    printf(" %d", u);
    inParse(T[u].r);
}

// ???????????????
void postParse(int u) {
    if (u == NIL ) return;
    postParse(T[u].l);
    postParse(T[u].r);
    printf(" %d", u);
}

int main(int argc, char const* argv[])
{
    int i, v, l, r, root;

    scanf("%d", &n);
    for (i = 0; i < n; i++) {
        T[i].p = NIL;
    }

    for ( i = 0; i < n; i++) {
        scanf("%d %d %d", &v, &l, &r);
        T[v].l = l;
        T[v].r = r;
        if(l != NIL) T[l].p = v;
        if(r != NIL) T[r].p = v;
    }

    for ( i = 0; i < n; i++) {
        if (T[i].p == NIL) {
            root = i;
        }
    }

    printf("Preorder\n");
    preParse(root);
    printf("\n");
    printf("Inorder\n");
    inParse(root);
    printf("\n");
    printf("Postorder\n");
    postParse(root);
    printf("\n");
    return 0;
}

Measured memory_bytes: 620
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cassert>
#include<iostream>
#include<algorithm>
#define llong long long
using namespace std;
 
inline int read()
{
    int x=0; bool f=1; char c=getchar();
    for(;!isdigit(c);c=getchar()) if(c=='-') f=0;
    for(; isdigit(c);c=getchar()) x=(x<<3)+(x<<1)+(c^'0');
    if(f) return x;
    return -x;
}
 
const int N = 5000;
const llong INF = 10000000000000000ll;
int p[N+3],pp[N+3];
llong dp[N+3][N+5],sdp[N+3][N+5];
int n; llong arga,argb;
 
void update(llong &x,llong y) {x = x<y?x:y;}
 
int main()
{
    scanf("%d%lld%lld",&n,&arga,&argb);
    for(int i=1; i<=n; i++) {scanf("%d",&p[i]); pp[p[i]] = i;}
    for(int i=0; i<=n; i++) for(int j=0; j<=n; j++) dp[i][j] = INF;
    for(int i=0; i<=n; i++) dp[0][i] = 0ll;
    for(int i=1; i<=n; i++)
    {
        for(int j=0; j<=n; j++)
        {
            if(j==pp[i]) {update(dp[i][j],dp[i-1][j-1]);}
            llong tmp = dp[i-1][j]+(j<pp[i]?argb:arga);
            update(dp[i][j],tmp);
        }
        for(int j=1; j<=n; j++) dp[i][j] = min(dp[i][j-1],dp[i][j]);
    }
    llong ans = dp[n][n];
    printf("%lld\n",ans);
    return 0;
}

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

int main() {
  //宣言
  int N;
  int ans = 0;
  int L, R;
  
  //入力
  cin >> N;
  
  //処理
  for(int i = 0; i < N; i++){
    cin >> L >> R;
    ans += (R-L+1);
  }
  
  //出力
  cout << ans << endl;
}

Measured memory_bytes: 256