akhauriyash/Code-Regression huggingface dataset:
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
	static final PrintStream out = System.out;
	static final Scanner sc = new Scanner(System.in);
	static final long Mod = 1000_000_007L;
	public static void main(String[] args) {
		Main main = new Main();
		main.solve();
		System.exit(0);
	}

	void solve() {
		String S1 = next();
		String S2 = next();
		int N = S2.length();
		int SearchTlen = S1.length();
		char[] SearchT = (S1+S1).toCharArray();// search対象の配列
		char[] SearchC = S2.toCharArray();//searchする文字
		List<List<Integer>> list = new ArrayList<>(26);
		for(int i=0;i<26;i++){
			list.add(new ArrayList<>());
		}
		// a = 0, z = 25;
		for(int i=0;i<SearchTlen*2;i++) {
			int t = SearchT[i];
			t-=97;
			list.get(t).add(i);
		}

		long cnt = 1;
		int index = 0;
		int Previous_index = 0;// 前のindex
		for(int l=0;l<N;l++) {
			int t = SearchC[l];
			t-=97;
			if(list.get(t).size()==0) {
				out.println(-1);
				return;
			}
			index = list.get(t).get(BinarySearch(list.get(t),index));

			cnt += index - Previous_index;
			if(index >= SearchTlen) {
				index -= SearchTlen;
			}
			Previous_index = index;
			index++;
		}
		out.println(cnt);
	}
	//二部探索
	static int BinarySearch(List<Integer> a, long k) {
		int l = -1;
		int r = a.size();
		while(r - l > 1) {
			int mid = (r + l) / 2;
			if(a.get(mid) >= k) r = mid;
			else l = mid;
		}
		return r;
	}


	public int[] nextIntArray(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)a[i] = nextInt();
		return a;
	}
	public long[] nextLongArray(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)a[i] = nextLong();
		return a;
	}
	public int nextInt() {
		return Integer.parseInt(next());
	}
	public long nextLong() {
		return Long.parseLong(next());
	}
	public String next() {
		return sc.next();
	}
}

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

long long int dp[2001][2001];
int n;
long long int t;
vector <pair<long long int,long long int>> v;

long long int solve(long long int a,long long int b)
{
	if(dp[a][b]!=-1)
	{
		return dp[a][b];
	}
	int idx = a + (n-1 - b);
	//cout << idx << ' ' << a << ' ' << b << '\n';	
	if(a>b)
	{
		dp[a][b] = 0;
		return dp[a][b];
	}
	dp[a][b] = 0;
	long long int val1 = (v[idx].first)*(abs(v[idx].second - a));
	long long int val2 = (v[idx].first)*(abs(v[idx].second - b));
	dp[a][b] = max(dp[a][b],max(solve(a+1,b) + val1,solve(a,b-1)+val2));
	return dp[a][b];
}

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

	cin >> n;

	for(int i=0;i<n;i++)
	{
		cin >> t;
		v.push_back(make_pair(t,i));
	}

	sort(v.rbegin(),v.rend());

	memset(dp,-1,sizeof(dp));

	cout << solve(0,n-1) << '\n';

	return 0;
}

Measured memory_bytes: 35112
#include<iostream>
#include<cstdio>

using namespace std;

inline int read()
{
	int f = 1,x = 0;
	char ch;
	do
	{
		ch = getchar();
		if(ch == '-') f = -1;
	}while(ch < '0' || ch > '9');
	do
	{
		x = (x<<3) + (x<<1) + ch - '0';
		ch = getchar();
	}while(ch>='0'&&ch<='9');
	return f*x;
}

const int MAXN = 100000 + 10;
const int MOD = 1e9 + 7;

inline long long Pow(long long a,long long b)
{
	long long  ans = 1,mul = a;
	while(b)
	{
		if(b&1) ans = (ans * mul) % MOD;
		mul = (mul *mul)%MOD;
		b>>=1;	
	}
	return ans;
}

int n;
long long a[MAXN],x[MAXN];
long long inv[MAXN];

int main()
{
	n = read();
	for(register int i=1;i<=n;i++) a[i] = read();
	for(register int i=1;i<n;i++) x[i] = a[i+1] - a[i];
	for(register int i=1;i<=n;i++) inv[i] = (inv[i-1] + Pow(i,MOD-2))%MOD;
	long long ans = 0;
	for(register int i=1;i<n;i++) ans = (ans + x[i]*inv[i]%MOD)%MOD;
	for(register int i=1;i<n;i++) ans = (ans * i)%MOD;
	cout<<ans<<endl;
}

Measured memory_bytes: 5968
#include<bits/stdc++.h>
using namespace std;
using P = pair<int, int>;
const int M = 1000000007;

int main() {
    int n;
    cin >> n;
    int ans = 0;
    for (int i = 1; i <= 9; ++i) {
        for (int j = 1; i + j <= 9; ++j) {
            for (int k = 1; i + j + k <= 9; ++k) {
                vector<int> v;
                for (int l = 0; l < i; ++l) {
                    v.push_back(3);
                }
                for (int l = 0; l < j; ++l) {
                    v.push_back(5);
                }
                for (int l = 0; l < k; ++l) {
                    v.push_back(7);
                }
                do
                {
                    int p = 0;
                    for (auto& i : v) {
                        p = p * 10 + i;
                    }
                    if (p <= n) {
                        ++ans;
                    }
                } while (next_permutation(v.begin(), v.end()));

            }
        }
    }
    cout << ans << "\n";
    return 0;
}


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

using namespace std;
#define ll long long
#define pb push_back

int main(){
	// #ifndef ONLINE_JUDGE
 //    freopen("input.txt", "r", stdin);
 //    freopen("output.txt", "w", stdout);
	// #endif

	ios::sync_with_stdio(0);
	cin.tie(0);
	
	int a, b; cin>>a>>b;
	if(2*b > a)
		cout<<0;
	else{
		cout<<a-(2*b);
	}
	

	
	return 0;
}

Measured memory_bytes: 3640
//DFS traversal
#include <bits/stdc++.h>
 
# define C continue;
# define R return
 
# define D double
# define I insert
# define ll long long
# define ld long double
 
# define ull unsigned long long
# define ui unsigned int
 
# define pb push_back
# define pf push_front
 
# define vi vector < int >
# define vc vector < char >
# define vs vector < string >
# define vb vector < bool >
# define vd vector < D >
# define vll vector < ll >
# define vull vector < ull >
# define vld vector < ld >
# define PQ priority_queue
 
# define vvi vector < vector < int > >
# define vvb vector < vector < bool > >
# define vvc vector < vector < char > >
# define vvll vector < vector < ll > >
# define vvd vector < vector < D > >
# define vvld vector < vector < ld > >
 
# define all(v) (v).begin() , (v).end()
# define allrev(v) (v).rbegin() , (v).rend()
# define allcomp(v) v.begin() , v.end() , comp
# define allrevcomp(v) v.rbegin() , v.rend() , comp
 
# define pii pair < int , int >
# define pll pair < ll , ll >
# define pld pair < ld , ld >
# define pDD pair < D , D >
# define pipii pair<int, pii >
# define pcpii pair<char,pii>
 
# define vpld vector < pld >
# define vpii vector < pii >
# define vpll vector < pll >
# define vpDD vector < pDD >
 
# define vvpii vector < vector < pii > >
# define vpipii vector< pipii >
 
# define F first
# define S second
# define mp make_pair
 
# define unm unordered_map
# define unmii unm< int , int >
# define unmll unm< ll , ll >
# define unms unm<string,int>
# define unmci unm<char,int>
 
# define sortvia sort(a.begin(),a.end());
# define sortvib sort(b.begin(),b.end());
# define revsorta sort(a.begin(), a.end(), greater <int>());
# define revsortb sort(b.begin(), b.end(), greater <>());
# define loop(q,n) for(int i=q;i<n;i++)
# define loopj(r,n) for(int j=r;j<n;j++)
# define loopm(s,m) for(int k=s;k<m;k++)
# define test int t;cin >> t;while(t--)
# define nextline "\n"
# define tab "\t"
# define space " "
//YES
//NO
//cout
//true
//false
//yes
//no
 
const ll mod9=1e9+7;
const ll maxsize=2e9+1;
// const ll mod =998244353;
const ll mod2=1073741824;
using namespace std;
 
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
/*#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
#endif*/
    int n,w;
    cin>>n>>w;
    vll dp(w+1,0);
    int tem1,tem2;
    ll current_sum;
    //input is in the form w value
    for(int i=0;i<n;i++){
        cin>>tem1>>tem2;
        for(int j=tem1;j<=w;j++){
            current_sum=dp[j]+tem2;
            if(dp[j-tem1]<current_sum)dp[j-tem1]=current_sum;
        }
    }
    //find max in the range
    ll mxm=0;
    for(int i=0;i<w+1;i++){
        if(dp[i]>mxm)mxm=dp[i];
    }
    cout<<mxm;

    
return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define sz(arr) (int)arr.size()

using namespace std;

int main() {
  char c;
  cin >> c;

  if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u') {
    puts("vowel");
  } else {
    puts("consonant");
  }

  return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace abc50 {
    class Program {
        static void Main(string[] args) {
            int N=int.Parse(Console.ReadLine());
            int[] Ti = ScanInt;
            int M = int.Parse(Console.ReadLine());
            int[] Pi = new int[M];
            int[] Xi = new int[M];
            int Sum=0;
            for(int i = 0; i < N; i++) {
                Sum += Ti[i];
            }
            for(int i = 0; i < M; i++) {
                var input = ScanInt;
                Pi[i] = input[0]-1;
                Xi[i] = input[1];
            }
            for(int i = 0; i < M; i++) {
                Console.WriteLine(Sum - (Ti[Pi[i]]-Xi[i]));
            }
        }
        static int[] ScanInt {
            get {
                return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            }
        }
    }
}


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

int main()
{
    ll x, y;
    scanf("%lld %lld", &x, &y);
    for (ll i = 0ll; i <= 60ll; i++)
    {
        if (x * (1ll << i) > y)
        {
            printf("%d\n", i);
            return 0;
        }
    }
    printf("0\n");
    return 0;
}


Measured memory_bytes: 256
package main

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

var sc, wr = bufio.NewScanner(os.Stdin), bufio.NewWriter(os.Stdout)

func scanString() string   { sc.Scan(); return sc.Text() }
func scanRunes() []rune    { return []rune(scanString()) }
func scanInt() int         { a, _ := strconv.Atoi(scanString()); return a }
func scanInt64() int64     { a, _ := strconv.ParseInt(scanString(), 10, 64); return a }
func scanFloat64() float64 { a, _ := strconv.ParseFloat(scanString(), 64); return a }

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = scanInt()
	}
	return res
}

func debug(a ...interface{}) { fmt.Fprintln(os.Stderr, a...) }

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

//•*¨*•.¸¸♪main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)
func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1001001)

	n := scanInt()
	k := scanInt()

	ans := 0
	for i := 1; i <= n; i++ {
		if 2*i%k == 0 {
			t := (n+i)/k - i/k
			ans += t * t
		}
	}
	fmt.Fprintln(wr, ans)
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#define   ll   long long int
#define   sz   200010

using namespace std;


int main()
{

    ll a,b,c,d;

    cin>>a>>b>>c;
    d=a+b+c;

    if(d>=22)cout<<"bust"<<endl;
    else
        cout<<"win"<<endl;

    return 0;
}



Measured memory_bytes: 256
class UnionFind:
    def __init__(self, size):
        self.data = [-1 for _ in range(size)]
    def find(self, x):
        if self.data[x] < 0:
            return x
        else:
            self.data[x] = self.find(self.data[x])
            return self.data[x]
    def union(self, x, y):
        x, y = self.find(x), self.find(y)
        if x != y:
            if self.data[y] < self.data[x]:
                x, y = y, x
            self.data[x] += self.data[y]
            self.data[y] = x
        return (x != y)
    def same(self, x, y):
        return (self.find(x) == self.find(y))
    def size(self, x):
        return -self.data[self.find(x)]


N, M, *XYZ = map(int, open(0).read().split())

uf = UnionFind(N + 1)
for x, y, _ in zip(*[iter(XYZ)] * 3):
    uf.union(x, y)

print(len({uf.find(i + 1) for i in range(N)}))


Measured memory_bytes: 32184
n = gets.to_i
count = 0
max = 0
n.times do
  a,b = gets.chomp.split(' ').map(&:to_i)
  if a == b
    count += 1
    if max < count
      max = count
    end
  else
    count = 0
  end
  
end
if max >= 3
  puts "Yes"
else
  puts "No"
end


Measured memory_bytes: 14376
const func = (nums: Array<number>, count: number): number => {
  const isAllEven = nums.every(n => n % 2 === 0);
  if (!isAllEven) return count;
  return func(nums.map(n => n / 2), count + 1);
}

const Main = (input) {
  const [length, nums] = input.split("\n");
  const numsArr = nums.split(' ');
  console.log(func(numsArr.map(n => Number(n)), 0));
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7500
#include <bits/stdc++.h>
using namespace std;
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
	int x, ans;
	cin >> x;
	int s = 0;
	for(int i = 1; i <= x; i++){
		s += i;
		if(s >= x){
			ans = i;
			break;
		}
	}
	cout << ans << "\n";
	return 0;
}


Measured memory_bytes: 256
from heapq import heappop, heappush

N, M = map(int, input().split())
J_day = [[] for _ in range(M + 1)]
for i in range(N):
    A, B = map(int, input().split())
    if A <= M:
        J_day[A].append(B)

ans = 0
q = []
for m in range(1, M + 1):
    for j in J_day[m]:
        heappush(q, -j)
    if len(q):
        ans -= heappop(q)

print(ans)


Measured memory_bytes: 72352
#include<iostream>
#include<string>
#include<map>
#include<algorithm>
#include<vector>
using namespace std;
int main() {
  int N,M;
  cin >> N >> M;
  vector<int> A(N),B(N);
  for (int i=0; i<N; i++) cin >> A[i] >> B[i];
  vector<pair<int,int>> AB(N);
  for (int i=0; i<N; i++) {
    AB[i] = make_pair(A[i],B[i]);
  }
  sort(AB.begin(),AB.end());
  long long ans = 0;
  for (int i=0; i<N; i++) {
    int buy = min(M,AB[i].second);
    ans += (long long)buy*AB[i].first;
    M -= buy;
    if (M == 0) break;
  }
  cout << ans << endl;
}
  

Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <set>
#include <list>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <string>
#include <sstream>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <fstream>
#include <iomanip>
//#include <unordered_map>
using namespace std;
#define dbg(x) cerr << #x " = " << x << endl;
typedef pair<int, int> P;
typedef long long ll;
#define FIN freopen("in.txt", "r", stdin);

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll x;
    cin >> x;
    ll cur = 100.0;
    int cnt = 0;
    while(cur < x)
    {
        cur *= 1.01;
        cnt++;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 3192
//
// Created by yuu on 2019-07-07.
//

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <utility>
#include <math.h>
#include <stack>
#include <queue>
#include <cstdio>

using namespace std;

int X[100][100];
int main(void){
    int N,D;
    cin>>N>>D;

    for (int i = 0; i < N; ++i) {
        for (int k = 0; k < D; ++k) {
            cin>>X[i][k];
        }
    }

    int ans = 0;
    for (int i = 0; i+1 < N; ++i) {
        for (int j = i+1; j < N; ++j) {
            long temp = 0;
            for (int k = 0; k < D; ++k) {
                temp += pow(X[i][k] - X[j][k],2);
            }
            double temp_2;
            temp_2 = sqrt(temp);
            if(temp_2 == floor(temp_2)){
                ans++;
            }
        }
    }
cout<<ans<<endl;

    return 0;
}

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

const int INF = 100000000;
typedef pair<int, int> P;
const int MAX_H = 1000, MAX_W = 1000;
int H, W;
int sy, sx;
int gy, gx;
char maze[MAX_H][MAX_W];

int d[MAX_H][MAX_W];

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

void bfs(int y, int x);

int main()
{
  cin >> H >> W;
  for (int i = 0; i < H; i++)
  {
    for (int j = 0; j < W; j++)
    {
      cin >> maze[i][j];
    }
  }
  for (int i = 0; i < H; i++)
  {
    for (int j = 0; j < W; j++)
    {
      d[i][j] = INF;
    }
  }
  queue<P> que;
  for (int i = 0; i < H; i++)
  {
    for (int j = 0; j < W; j++)
    {
      if (maze[i][j] == '#')
      {
        d[i][j] = 0;
        que.push(P(i, j));
      }
    }
  }

  // BFS
  while (que.size())
  {
    P p = que.front();
    que.pop();
    for (int i = 0; i < 4; i++)
    {
      int ny = p.first + dy[i], nx = p.second + dx[i];
      if (0 <= ny && ny < H && 0 <= nx && nx < W && maze[ny][nx] != '#' && d[ny][nx] == INF)
      {
        que.push(P(ny, nx));
        d[ny][nx] = d[p.first][p.second] + 1;
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < H; i++)
  {
    for (int j = 0; j < W; j++)
    {
      if (d[i][j] > ans)
        ans = d[i][j];
    }
  }
  cout << ans << endl;
}




Measured memory_bytes: 13328
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
void solve()
{
	int m, d;
	cin >> m >> d;
	int ans = 0;	
	for (int i = 1; i <= d; i++)
	{
		int x = i % 10;
		int y = i / 10 % 10;
		if (x * y <= m && x>=2 && y>=2)
			ans++;
		// cout<<i<<" ";
	}
	cout << ans;

}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	


	int t;
	// cin >> t;
	t = 1;
	while (t--) solve();


	return 0;
}


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

int main() {
double N,K;
  cin >> N >> K;
  double a;
  vector<double> retu(N);
  for(int i = 0; i < N; i++){
  	cin >> a;
    retu[i] = a+1;
  }
  double mm = 0;
  for(int i = 0; i < K; i++){
  	mm += retu[i];
  }
  //これでmmはまずi = 0からK個の期待値の和
  vector<double> kitai(N);
  kitai[0] = mm;
  for(int i = 0; i < N-K; i++){
  	kitai[i+1] = kitai[i] - retu[i] + retu[i+K];
    mm = max(mm, kitai[i+1]);
  }


  cout << fixed << setprecision(5) << mm/2 << endl;
}

Measured memory_bytes: 3328
#include <iostream>
#include <vector>
#include<algorithm>
#define mod 998244353;
using namespace std;
typedef long long ll;
int main(void){
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for(int i = 0 ; i < n; i++){
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    int ans = 1000000000;
    for(int i = 0; i < n - k +1; i++){
        ans = min(a[i+k-1] - a[i], ans);
    }
    cout << ans << endl;
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>
#include <string>

using namespace std;

int main() {
    string s, t;
    cin >> s >> t;
    vector<int> atoz_s(26, -1);
    vector<int> atoz_t(26, -1);
    
    for (int i=0; i<s.size(); i++) {
        int a = s[i]-'a';
        int b = t[i]-'a';
        if (atoz_s[a] != -1 || atoz_t[b] != -1) {
            if (atoz_s[a] != b || atoz_t[b] != a) {
                cout << "No" << endl;
                return 0;
            }
        }
        else {
            atoz_s[a] = b;
            atoz_t[b] = a;
        }
    }

    cout << "Yes" << endl;
}


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

using namespace std;
typedef long long ll;
//typedef unsigned long long ll;

//#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define sz(x) ll(x.size())
//typedef pair<ll, int> P;
//typedef pair<ll, ll> P;
//const double INF = 1e10;
//const ll INF = LONG_LONG_MAX / 10;
//const ll INF = 1e15;
const ll MINF = LONG_LONG_MIN;
const int INF = INT_MAX / 10;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)

bool contain(set<char> &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);

typedef pair<char, int> P;

void print_line(vector<P> &line) {
    if (line.size() == 0ll) {
        cout << endl;
        return;
    }
    for (ll i = 0; i < line.size(); i++) {
        cout << line[i].second;
        if (i == line.size() - 1) cout << endl;
        else cout << ' ';
    }
}


typedef priority_queue<long long, vector<long long>, greater<long long> > PQ_ASK;
const int mod = 1000000007;


int merge(vector<P> &a, int left, int mid, int right) {
    int n1 = mid - left;
    int n2 = right - mid;
    vector<P> l(n1 + 1);
    vector<P> r(n2 + 1);

    for (int i = 0; i < n1; i++) {
        l[i] = a[left + i];
    }
    for (int i = 0; i < n2; i++) {
        r[i] = a[mid + i];
    }

    l[n1] = P(' ', INF);
    r[n2] = P(' ', INF);

    int i = 0, j = 0;
    int compare = 0;
    for (int k = left; k < right; k++) {
        compare++;
        if (l[i].second <= r[j].second) {
            a[k] = l[i];
            i++;
        } else {
            a[k] = r[j];
            j++;
        }
    }
    return compare;
}

int merge_sort(vector<P> &a, int left, int right) {
    int compare = 0;
    if (left + 1 < right) {
        int mid = (left + right) / 2;
        compare += merge_sort(a, left, mid);
        compare += merge_sort(a, mid, right);
        compare += merge(a, left, mid, right);
    }
    return compare;
}

int partition(vector<P> &a, int p, int r) {
    P x = a[r];
    int i = p - 1;
    for (int j = p; j < r; j++) {
        if (a[j].second <= x.second) {
            i++;
            swap(a[i], a[j]);
        }
    }
    swap(a[i + 1], a[r]);
    return i + 1;
}

void quick_sort(vector<P> &a, int p, int r) {
    if (p < r) {
        int q = partition(a, p, r);
        quick_sort(a, p, q - 1);
        quick_sort(a, q + 1, r);
    }
}

void check_stability(vector<P> &b, vector<P> &c) {
    rep(i, b.size()) {
        if (b[i] != c[i]) {
            cout << "Not stable" << endl;
            return;
        }
    }
    cout << "Stable" << endl;
}

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

    vector<P> a(n);
    rep(i, n) cin >> a[i].first >> a[i].second;
    vector<P> b = a;
    vector<P> c = a;

    quick_sort(b, 0, n - 1);
    merge_sort(c, 0, n);

    check_stability(b, c);

    rep(i, n) {
        printf("%c %d\n", b[i].first, b[i].second);
    }

}



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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

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

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main(){
    int n, w;
    cin >> n >> w;
    vi v(n), wi(n);
    rep(i, n) cin >> v[i] >> wi[i];
    vector<vi> dp(n+1, vi(w+1, 0));
    rep(i, n) rep(j, w+1) {
        if (j>=wi[i]) dp[i+1][j] = max(dp[i][j-wi[i]]+v[i], dp[i][j]);
        else dp[i+1][j] = dp[i][j];
    }
    cout << dp[n][w] << endl;
    return 0;
}



Measured memory_bytes: 6780
#include <iostream>
#include <vector>

using namespace std;

int main(){
    int a, b;
    vector<int> vs, vt;
    cin >> a;
    for(int i1=0;i1<a;i1++){
        cin >> b;
        vs.push_back(b);
    }
    
    cin >> a;
    for(int i2=0;i2<a;i2++){
        cin >> b;
        vt.push_back(b);
    }
    int count = 0;
    for(int i3=0;i3<vt.size();i3++){
        for(int i4=0;i4<vs.size();i4++){
            if(vt[i3]==vs[i4]){
                count += 1;
                break;
            }
        }
    }
    cout << count << endl;
}


Measured memory_bytes: 3200
def halt(ans)
	puts ans
	exit
end
n, m = gets.split.map(&:to_i)
hash = n.times.map { gets.chomp }.flatten.inject({}) { |sum, s| sum.merge(s.each_char.group_by(&:itself).inject({}) { |h, (k, v)| h[k] = v.count; h }) { |_,a,b| a + b } }
remain = (n / 2) * (m / 2)
hash.each do |c, count|
	i = count / 4
	hash[c] -= i * 4
	remain -= i
end
halt 'No' if remain > 0

odd = hash.find { |k,v| v.odd? }
hash[odd.first] -= 1 unless odd.nil?
halt 'No' if hash.any? { |k,v| v.odd? }
halt 'Yes'


Measured memory_bytes: 2556
n = int(input())
s = [0]*n

for i in range(n):
  s[i] = int(input())
  
s.sort()

if sum(s)%10 != 0:
  print(sum(s))
else:
  i = 0
  ss = sum(s)
  for i in range(n):
    if s[i]%10 != 0:
      print(ss-s[i])
      exit()
  print(0)

Measured memory_bytes: 62536
while True:
    m, f, r = [int(arg) for arg in input().split()]
    if m == -1 and f == -1 and r == -1:
        break
    elif m == -1 or f == -1:
        print('F')
    elif m + f >= 80:
        print('A')
    elif m + f >= 65:
        print('B')
    elif m + f >= 50:
        print('C')
    elif m + f >= 30 and r >= 50:
        print('C')
    elif m + f >= 30:
        print('D')
    else:
        print('F')



Measured memory_bytes: 5600
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
 
#define rep(i,s,n) for(int i = (s);i<(n);i++)
#define repe(i,s,n) for(int i = (s);i<=(n);i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int,int>pint;
typedef vector<int>vint;
const ll MOD=1000000007,INF=1e18;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};

int n,a,b;
int x[100010];

signed main(){
    cin>>n>>a>>b;
    x[0]=0;
    int ans=0;
    rep(i,0,n){
        cin>>x[i+1];
        if(i==0)continue;
        if((x[i+1]-x[i])*a>=b)ans+=b;
        else ans+=(x[i+1]-x[i])*a;
    }
    cout<<ans<<endl;
    return 0;
}

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

int main() {
  string S;
  long long count = 0;
  
  cin >> S;

  long long B = 0;
  for (long long i = 0; i < S.size(); i++) {
    if(S[i] == 'B'){
      B++;
    }else if(S[i] == 'W'){
      count += B;
    }
  }
  
  cout << count << endl;
}



Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); ++i)
using namespace std;
using ll = long long;
const int INF = 1001001001;
const int MOD = 1000000007;

int main() {
    while (1)  {
        int n, x;
        cin >> n >> x;
        if (n == 0 & x == 0) break;

        int cnt = 0;
        for (int i=1; i<=n-2; ++i) {
            for (int j=i+1; j<=(n-1); ++j) {
                for (int k=j+1; k<=n; ++k) {
                    if (i+j+k == x) ++cnt;
                }
            }
        }
        cout << cnt << endl;
    }
    return 0;
}


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

int main(void){
    ll n; string s; multiset<pl> rs, ls;
    cin >> n;

    rep(i, n){
        cin >> s;
        ll cur = 0, bottom = 0;
        rep(j, s.length()){
            cur += (s[j] == '(') * 2 - 1;
            bottom = min(bottom, cur);
        }
        if (cur >= 0) ls.insert({bottom, cur});
        else rs.insert({bottom - cur, -cur});
    }

    ll lv = 0, rv = 0;
    auto it = ls.rbegin();
    auto update = [&](ll& val) -> bool{
        pl p = *(it++);
        if (p.first + val >= 0) {val += p.second; return true;}
        else return false;
    };

    while(it != ls.rend()) if (!update(lv)) {cout << "No" << endl; return 0;}
    it = rs.rbegin();
    while(it != rs.rend()) if (!update(rv)) {cout << "No" << endl; return 0;}
    if (lv == rv) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 66036
print("Yes")
N, M = map(int,input().split())
path = [[] for _ in range(N)]
ind = [0 for _ in range(N)]
lis = [0] + [1 for _ in range(N-1)]
for i in range(M):
    A, B = map(int, input().split())
    path[A-1].append(B-1)
    path[B-1].append(A-1)

for p in path[0]:
    lis[p] = 0
for l in path[0]:
    for m in path[l]:
        if lis[m] ==1:
            ind[m] = l
            lis[m] = 0
            path[0].append(m)

for i in range(1,N):
  print(ind[i]+1)
            
            
           

Measured memory_bytes: 35256
character(100) S
integer(16) N,i
read*,S
read*,N
if(N<=len_trim(S))then
  if(S(1:N)==repeat("1",N))then
    print"(A)","1"
    stop
  endif
end if
do i=1,len_trim(S)
  if(S(i:i)=="1")cycle
  print"(A)",S(i:i)
  exit
end do
end

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

using namespace std;
using ll = long long;

int main() {
    string s = "";
    cin >> s;

    if(s[0] == s[1] && s[1] == s[2]){
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
    }
    
    return 0;
}

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

int main() {
  int vals[3];
  cin >> vals[0] >> vals[1] >> vals[2];
  int max = 1, max_index = 0;
  for (int i = 0; i < 3; i++) {
    if (max < vals[i]) {
      max = vals[i];
      max_index = i;
    }
  }
  int sum = 0;
  for (int i = 0; i < 3; i++) {
    if (i != max_index) {
      sum += vals[i];
    }
  }
  cout <<  (max == sum ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
a=[[int(i) for i in input().split()] for i in range(3)]
import collections 
d=collections.defaultdict(int)
for i in a:
    d[i[0]]+=1
    d[i[1]]+=1
x=[]
for i in d.values():
    x.append(i)
if x.count(1)==2 and x.count(2)==2:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 3316
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main(){
  int unused __attribute__((unused));
  int i, turn, next, cnt[3];
  char S[3][101];

  unused = scanf("%s", S[0]);
  unused = scanf("%s", S[1]);
  unused = scanf("%s", S[2]);
  cnt[0] = strlen(S[0]); cnt[1] = strlen(S[1]); cnt[2] = strlen(S[2]);

  //printf("%s %s %s %d %d %d\n", S[0], S[1], S[2], cnt[0], cnt[1], cnt[2]);
  turn = 0;
  while(1){
    if(cnt[turn]==0) break;
    next = S[turn][0] - 97;
    for(i=0; i<cnt[turn]; i++) S[turn][i] = S[turn][i+1];
    cnt[turn]--;
    turn = next;
  //printf("%s %s %s %d %d %d\n", S[0], S[1], S[2], cnt[0], cnt[1], cnt[2]);
  }

  if(turn==0) printf("A");
  else if(turn==1) printf("B");
  else if(turn==2) printf("C");
  return 0;
}

Measured memory_bytes: 128
//This code was made by Chinese_zjc_.
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<vector>
#include<map>
#define int long long
#define INF 0x3fffffffffffffff
#define pi 3.14159265358979323
using namespace std;
int lsz,lfz,s,f;
double jsz,jfz,xsz,ysz,xfz,yfz;
double sqr(double now)
{
	return now*now;
}
signed main()
{
	std::ios::sync_with_stdio(false);
	cin>>lsz>>lfz>>s>>f;
	jsz=s*30+f*0.5;
	jfz=f*6;
	if(jsz==0)
	{
		xsz=0;
		ysz=lsz;
	}
	if(0<jsz&&jsz<90)
	{
		xsz=cos((90-jsz)/180*pi)*lsz;
		ysz=sin((90-jsz)/180*pi)*lsz;
	}
	if(jsz==90)
	{
		xsz=lsz;
		ysz=0;
	}
	if(90<jsz&&jsz<180)
	{
		xsz=cos((jsz-90)/180*pi)*lsz;
		ysz=sin((jsz-90)/180*pi)*lsz*(-1);
	}
	if(jsz==180)
	{
		xsz=0;
		ysz=-lsz;
	}
	if(180<jsz&&jsz<270)
	{
		xsz=cos((270-jsz)/180*pi)*lsz*(-1);
		ysz=sin((270-jsz)/180*pi)*lsz*(-1);
	}
	if(jsz==270)
	{
		xsz=-lsz;
		ysz=0;
	}
	if(270<jsz&&jsz<360)
	{
		xsz=cos((jsz-270)/180*pi)*lsz*(-1);
		ysz=sin((jsz-270)/180*pi)*lsz;
	}
	if(jfz==0)
	{
		xfz=0;
		yfz=lfz;
	}
	if(0<jfz&&jfz<90)
	{
		xfz=cos((90-jfz)/180*pi)*lfz;
		yfz=sin((90-jfz)/180*pi)*lfz;
	}
	if(jfz==90)
	{
		xfz=lfz;
		yfz=0;
	}
	if(90<jfz&&jfz<180)
	{
		xfz=cos((jfz-90)/180*pi)*lfz;
		yfz=sin((jfz-90)/180*pi)*lfz*(-1);
	}
	if(jfz==180)
	{
		xfz=0;
		yfz=-lfz;
	}
	if(180<jfz&&jfz<270)
	{
		xfz=cos((270-jfz)/180*pi)*lfz*(-1);
		yfz=sin((270-jfz)/180*pi)*lfz*(-1);
	}
	if(jfz==270)
	{
		xfz=-lfz;
		yfz=0;
	}
	if(270<jfz&&jfz<360)
	{
		xfz=cos((jfz-270)/180*pi)*lfz*(-1);
		yfz=sin((jfz-270)/180*pi)*lfz;
	}
//	cout<<jsz<<' '<<jfz<<endl;
//	cout<<xsz<<' '<<ysz<<' '<<xfz<<' '<<yfz<<endl;
	cout<<fixed<<setprecision(20)<<sqrt(sqr(xsz-xfz)+sqr(ysz-yfz))<<endl;
	return 0;
}


Measured memory_bytes: 3960
n = int ( input())
ans = 0
test = (3,5,7,11,13)
for i in range ( 105,n+1,2) :
  div = 0
  for d in test :
    if i % d == 0 :
      div += 1
  if div == 3 and i % 9 != 0:
    ans += 1
  elif i % 27 == 0:
    ans += 1
print (ans)

Measured memory_bytes: 3060
x=input()

if len(x)>=3:
  if int(x[-2:])%5==0:
    if int(x[:-2])-int(x[-2:])//5>=0:
      print(1)
    else:
      print(0)
  elif int(x[-2:])%4==0:
    if int(x[:-2])-int(x[-2:])//4>=0:
      print(1)
    else:
      print(0)
  elif int(x[-2:])%3==0:
    if int(x[:-2])-int(x[-2:])//3>=0:
      print(1)
    else:
      print(0)
  elif int(x[-2:])%2==0:
    if int(x[:-2])-int(x[-2:])//2>=0:
      print(1)
    else:
      print(0)
  elif int(x[-2:])%1==0:
    if int(x[:-2])-int(x[-2:])//1>=0:
      print(1)
    else:
      print(0)
  else:
    print(0)
else:
  print(0)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define ll long long 
#define pb push_back
#define ff first
#define ss second
#define setbits(x)          __builtin_popcountll(x)
#define lp(a,n) for(ll i=a; i<n; i++)
#define lpi(a,n) for(int i=a; i<n; i++)
#define w(t) int t; cin>>t; while(t--)
#define vi vector<int> 
#define vll vector<ll>
#define pll pair<ll, ll>
#define pii pair<int, int>
#define inf 1e9
#define LB lower_bound
#define UB upper_bound
const int mod = 1000000007;
using namespace std;
ll gcd(ll a,ll b){
    if(a==0)return b;
    return gcd(b%a,a);
}
ll lcm(ll a, ll b){
    return (a*b)/gcd(a,b);
}

int prime[100007];
void SieveOfEratosthenes(int n) 
{ 
    memset(prime, -1, sizeof(prime)); 
  
    for (int p=2; p*p<=n; p++) 
    { 
         
        if (prime[p] == -1) 
        { 
            for (int i=p*p; i<=n; i += p) 
                prime[i] = p; 
        } 
    } 
    
} 
int lps(string s){
    int len = 0;
    int n = s.length();
    int dp[n];
    dp[0] = 0;
    for(int i=1; i<n; i++){
        if(s[i] == s[len]){
            len++;
            dp[i] = len;
            continue;
        }
        if(len!=0){
            len = dp[len-1];
            i--;
            continue;
        }
        dp[i]=0;
    }
    return dp[n-1];
}
 
ll power(unsigned ll x,unsigned  ll y) 
{ 
    ll res = 1;     
    while (y > 0) 
    { 
        if (y & 1) 
            res = res*x; 
   
        y = y>>1;
        x = x*x;  
    } 
    return res; 
}


int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
    int n;
    cin>>n;
    cout<<n+(n*n)+(n*n*n)<<endl;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
#include <algorithm>  
#include <unordered_set>
#define _USE_MATH_DEFINES
#include <cmath>
#define ll long long

using namespace std;

const double pi = 3.14159265358979323846;

vector<int> g[100005];

int main() {

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	string s, t;

	cin >> s >> t;

	if (t.substr(0, t.size() - 1) == s) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}



	return 0;
}

Measured memory_bytes: 5972
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
int main(){
    string s;
    cin>>s;
    ll dp[3][200001]={0},c=0,A[200001],mod=1e9+7;
    A[0]=1;
    rep(i,s.size()) A[i+1]=A[i]*3%mod;
    rep(i,s.size()){
        if(s[i]=='A'){
            dp[0][i+1]=(dp[0][i]+A[c])%mod;
            dp[1][i+1]=dp[1][i]%mod;
            dp[2][i+1]=dp[2][i]%mod;
        }
        if(s[i]=='B'){
            dp[0][i+1]=dp[0][i]%mod;
            dp[1][i+1]=(dp[1][i]+dp[0][i])%mod;
            dp[2][i+1]=dp[2][i]%mod;
        }
        if(s[i]=='C'){
            dp[0][i+1]=dp[0][i]%mod;
            dp[1][i+1]=dp[1][i]%mod;
            dp[2][i+1]=(dp[2][i]+dp[1][i])%mod;
        }
        if(s[i]=='?'){
            dp[0][i+1]=(dp[0][i]*3+A[c])%mod;
            dp[1][i+1]=(dp[1][i]*3+dp[0][i])%mod;
            dp[2][i+1]=(dp[2][i]*3+dp[1][i])%mod;
            c++;
        }
    }
    cout<<dp[2][s.size()];
}

Measured memory_bytes: 6684
import java.util.*;
import java.io.*;
import java.nio.charset.StandardCharsets;

public class Main {
	public static void main(String[] args) throws IOException {
		InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);
		BufferedReader in = new BufferedReader(reader);
		String[] tokens = in.readLine().split(" ");
		char X = tokens[0].charAt(0);
		char Y = tokens[1].charAt(0);

		String str = "";
		if (X == Y) {
			str = "=";
		} else if (X < Y) {
			str = "<";
		} else {
			str = ">";
		}
		System.out.println(str);
	}
}


Measured memory_bytes: 23124
import java.util.Scanner;
public class Main{
  static int n, m;
  static boolean[][] a, b;
 
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    n = sc.nextInt();
    m = sc.nextInt();
    a = new boolean[n][n];
    
    for(int i = 0; i < n; i++){
      String line = sc.next();
      for(int j = 0; j < n; j++){
        if(line.charAt(j) == '#'){
          a[i][j] = true;
        }
      }
    }
    b = new boolean[m][m];
    for(int i = 0; i < m; i++){
      String line = sc.next();
      for(int j = 0; j < m; j++){
        if(line.charAt(j) == '#'){
          b[i][j] = true;
        }
      }
    }
    
    for(int i = 0; i < n; i++){
      for(int j = 0; j < n; j++){
        if(i + m - 1 >= n || j + m - 1 >= n){
          continue;
        }
        boolean match = true;
        for(int k = 0; k < m; k++){
          for(int l = 0; l < m; l++){
            if(a[i + k][j + l] != b[k][l]){
              match = false;
              break;
            }
          }
        }
        if(match){
          System.out.println("Yes");
          return;
        }
      }
    }
 
    System.out.println("No");
  }
}


Measured memory_bytes: 21844
import numpy as np
N = int(input())
XY = np.array([list(map(int,input().split())) for _ in [0]*N])
th = np.arctan2(XY[:,1],XY[:,0])
XY = XY[th.argsort()]
ans = 0
n = np.linalg.norm
s = np.sum
for i in range(N):
    for j in range(i+1,i+N+1):
        r = n(s(XY[i:j],axis=0)+s(XY[:max(0,j-N)],axis=0))
        ans = max(ans,r)
print(ans)

Measured memory_bytes: 12500
import numpy as np
N = int(input())
A = list(map(int, input().split()))

A.sort()

nminus = len([i for i in A if i < 0])
nplus = N - nminus



if nminus == N:
    M = 2*A[N-1] - np.sum(A)
    print(M)

    caled = A[N-1]
    for i in range(nminus-1):
        print(caled,A[i])
        caled -= A[i]
elif nplus == N:
    M = np.sum(A) - 2*A[0]
    print(M)

    caled = A[0]
    for i in range(N-2):
        print(caled, A[i+1])
        caled -= A[i+1]
    print(A[N-1],caled)
else:
    M = 0
    for i in range(N-1):
        M += abs(A[i])
    M += A[N-1]
    print(M)

    caled = A[0]
    for i in range(nplus-1):
        print(caled,A[nminus+i])
        caled -= A[nminus+i]
    caled_2 = A[N-1]
    for i in range(nminus-1):
        print(caled_2,A[i+1])
        caled_2 -= A[i+1]
    print(caled_2,caled)

Measured memory_bytes: 23484
Y = Array.new
loop{
  k=Array.new
  k[0],k[1]=gets.split(' ').map{|v|v=v.to_i}
  Y.push(k) if k!=[0,0]
  break if k==[0,0]
}
X=Array.new
0.upto(Y.length-1){|s|
  x=Array.new
  y=Y[s]
  h=y[0]
  w=y[1]
  1.upto(w){|t|
    x.push("#")
    X.push(x)
  }
  1.upto(h){|u|
    puts x.join
  }
puts ""
}

Measured memory_bytes: 6120
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

using namespace std;

int main() {
  uint32_t N;
  cin >> N;
  vector<int32_t> A(N + 1), B(N);
  for (uint32_t i = 0; i < N + 1; ++i) cin >> A[i];
  for (uint32_t i = 0; i < N; ++i) cin >> B[i];

  uint64_t Sum = 0;
  for (uint32_t i = 0; i < N + 1; ++i) Sum += A[i];
  if (A[0] - B[0] > 0) {
    A[0] -= B[0];
    B[0] = 0;
  } else {
    B[0] -= A[0];
    A[0] = 0;
  }
  for (uint32_t i = 0; i < N - 1; ++i) {
    int32_t tmp = B[i] + B[i + 1];
    if (A[i + 1] - tmp > 0) {
      A[i + 1] -= tmp;
      B[i + 1] = 0;
    } else {
      A[i + 1] = (A[i + 1] > B[i]) ? A[i + 1] - B[i] : 0;
      B[i + 1] -= A[i + 1];
      A[i + 1] = 0;
    }
  }
  if (A[N] - B[N - 1] > 0) {
    A[N] -= B[N - 1];
  } else {
    A[N] = 0;
  }
  for (uint32_t i = 0; i < N + 1; ++i) Sum -= A[i];
  cout << Sum << endl;

  return 0;
}


Measured memory_bytes: 1024
<?php
/*
    Problem URL : https://beta.atcoder.jp/contests/abc068/tasks/abc068_b

    Score  :
    Result :
    Time   : ms
    Memory : KB
 */

// define('DEBUG', true);
define('DEBUG', false);

ini_set('error_reporting', E_ALL & ~E_NOTICE);

fscanf(STDIN, "%d", $N);

$log = (int) floor(log($N, 2));

echo pow(2, $log) . "\n";


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

int linearSearch(int );
#define N 10000
#define Q 500
#define true 1
#define fault 0

int S[N], n;

int main(){
  int T[Q];
  int q, i, hantei, count=0;

  scanf("%d", &n);
  if(n > N) exit(1);
  for(i=0; i<n; i++){
    scanf("%d", &S[i]);
    if(S[i] < 0 || S[i] > 1000000000) exit(2);
  }

  scanf("%d", &q);
  if(q > Q) exit(3);
  for(i=0; i<q; i++){
    scanf("%d", &T[i]);
    if(T[i] < 0 || T[i] > 1000000000) exit(4);

    hantei = linearSearch( T[i] );
    if(hantei == 1) count++;
  }

  printf("%d\n",count);


  return 0;
}

int linearSearch(int x){
  int i;

  for(i=0; i<n; i++){
    if( S[i] == x) return true;
  }
  return fault;
}





Measured memory_bytes: 2048
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define mp(x, y) make_pair(x, y)
#define pb(x) emplace_back(x)
#define IOS ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)

typedef long long ll;
typedef vector<int> V;
typedef pair<int, int> pii;

const int N = 1e5;
int a[N];
int main()
{
    int a,b;cin>>a>>b;
    if(a>=10)cout<<b;
    else cout<<b+100*(10-a);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
int n,m;
string a[1010];
int dp[1010][1010];

int recur(int x, int y){
    if(x >= n || y >= m) return 0;
    if(x == n-1 && y == m-1) return 1;
    if(dp[x][y] != -1) return dp[x][y];
    else{
        dp[x][y] = 0;
        if(a[x+1][y] == '.') dp[x][y] += recur(x+1,y) % MOD;
        if(a[x][y+1] == '.') dp[x][y] += recur(x,y + 1) % MOD;
        return dp[x][y] % MOD;
    }
}


int main(){
    cin>>n>>m;
    for(int i = 0 ; i < n; i++)cin>>a[i];
    memset(dp,-1,sizeof dp);
    cout<<recur(0,0);
}


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

int main()
{
	int r, c;
	cin >> r >> c;
	vector<vector<int>> calc(r + 1, vector<int>(c + 1));
	for (int i = 0; i < r; i++) {
		for (int j = 0; j < c; j++) {
			cin >> calc[i][j];
			calc[i][c] += calc[i][j];
			calc[r][j] += calc[i][j];
			calc[r][c] += calc[i][j];
		}
	}
	for (int i = 0; i <= r; i++) {
		for (int j = 0; j < c; j++) {
			cout << calc[i][j] << ' ';
		}
		cout << calc[i][c] << endl;
	}
	return 0;
}

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

int main() {
    int a,b,c;
    cin>>a>>b>>c;
    if (a+b>=c) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


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

int main()
{
    int n;
    string inp;
    cin >> n >> inp;
    int cnt = 0;
    for(int i=0; i<n-2; i++)
    {
        if(inp[i]=='A' and inp[i+1]=='B' and inp[i+2]=='C')
            cnt ++;
    }
    cout << cnt << endl;
    return 0;
}


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

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())
#define range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 29;

const int vmax=100010;

vi graph[vmax],ord,low,scc,par;
stack<int>s;

void add_edge(int f,int t){ graph[f].pb(t);}
void add_both_edges(int f,int t){add_edge(f,t);add_edge(t,f);}

void dfs(int v,int p,int &k){
	ord[v]=k++;
	low[v]=ord[v];
	par[v]=p;
//	s.push(v);
	for(auto &i:graph[v]){
		if(ord[i]==-1){
			dfs(i,v,k);
			low[v]=min(low[v],low[i]);
		}else if(i!=p /*scc[i]==-1*/)
			low[v]=min(low[v],ord[i]);
	}
	/*if(ord[v]==low[v]){
		while(1){
			int u=s.top();s.pop();
			scc[u]=v;
			if(u==v) break;
		}
	}*/
}

void lowlink(int n){
	int k=0;
	ord.assign(n,-1),low.resize(n);
	scc.assign(n,-1),par.resize(n);
	rep(i,n) if(ord[i]==-1) dfs(i,-1,k);
}

int main(void){
	int v,e;
	cin >> v >> e;
	rep(loop,e){
		int a,b;
		cin >> a >> b;
		add_both_edges(a,b);
	}
	lowlink(v);

/*	rep(i,v){
		cout << "ord[" << i << "]=" << ord[i]  << endl;
		cout << "low[" << i << "]=" << low[i]  << endl;
	}
*/

// Bridge
	vector<pii> bridge;
	rep(i,v){
		int j=par[i];
		if(j==-1)
			continue;
		if(ord[i] < low[j] || ord[j] < low[i] ){
			pii in(i,j);
			if(in.second<=in.first) swap(in.first,in.second);
			bridge.pb(in);
		}
	}
	sort(bridge.begin(),bridge.end());
	for(auto &i:bridge)
		cout << i.first << " " << i.second << endl;


// SCC
/*	int q;
	cin >> q;
	rep(loop,q){
		int a,b;
		cin >> a >> b;
		cout << (scc[a]==scc[b]) << endl;
	}
*/
	return 0;
}

Measured memory_bytes: 4992
import java.util.Scanner;

class Main {

    private static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        int n = sc.nextInt();
        int ans = 0;
        for (int i = 105; i <= n; i++) {
            if (i % 2 == 0) {
                continue;
            }
            int count = 0;
            for (int j = 1; j <= i; j++) {
                if (i % j == 0) {
                    count++;
                }
            }
            if (count == 8) {
                ans++;
            }
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 21844
# inputでコマンド入力の数字を取得し、listに渡して一文字ずつ配列に格納
# inputで取得された数字はすべて文字列型で格納されているので、intで数値に変換
binDigit = [int(num) for num in list(input())]

# 配列の合計を計算。各配列要素の１の個数＝各配列の合計値
sumNum = sum(binDigit)

print(sumNum)

Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
#define rep(i,s, n) for(int i = s; i < (int)(n); i++)
#define co(x) cout<<x<<endl
#define SQvec(i,j) vector<vector<int>> data(i, vector<int>(j))
#define mod 1000000007
typedef long long int lint;

int main() {
  string S,ans;
  cin >> S;
  rep(i,0,S.size()){
    if(S[i] == '0'){ans.push_back('0');}
    if(S[i] == '1'){ans.push_back('1');}
    if(S[i] == 'B' && ans.size() != 0){ans.erase(ans.size() - 1);}
  }
  co(ans);
}

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

int main() {
    int h[100001];
    int n, k;
    int min_h = INT_MAX;
    cin >> n >> k;
    for (int i = 0; i < n; i++) {
        cin >> h[i];
    }
    
    sort(h, h + n);
    
    for (int i = 0; i < n - (k - 1); i++) {
        min_h = min(min_h, h[i + k - 1] - h[i]);
    }
    
    cout << min_h << '\n';
    
    return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<cmath>
#include<cstdlib>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>

using namespace std;

typedef long long ll;

typedef std::pair<int, int> ipair;
bool lessPair(const ipair& l, const ipair& r){return l.second < r.second;}
bool morePair(const ipair& l, const ipair& r){return l.second > r.second;}

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

const ll MOD = 1e9 + 7;
void add(long long &a, long long b) { a += b; if (a >= MOD) a -= MOD; }

int main() {
   int N;
   cin >> N;
   int ans = 0;
   int V[N], C[N];
   for (int i = 0; i < N; i++) cin >> V[i];
   for (int i = 0; i < N; i++) cin >> C[i];
   for (int i = 0; i < N; i++) {
      if (V[i] - C[i] > 0) ans += V[i] - C[i];
   }
   cout << ans << endl;
   return 0;
}


Measured memory_bytes: 256