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

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

using ll = long long;
ll INF = LLONG_MAX;
 
using vc = vector<char>;
using vi = vector<int>;

int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int N; cin >> N;
    vector<vc> grid (N, vc (N));
    F0R(i, N) {
        F0R(j, N) { 
            cin >> grid[i][j];
        }
    }

    ll ans = 0;
    F0R(i, N) {
        vector<vc> symmetric_grid (N, vc (N));
        F0R(y, N) {
            F0R(x, N) {
                symmetric_grid[y][x] = grid[y][(x+i)%N];
            }
        }
        bool isSymmetric = true;
        F0R(y, N){ 
            F0R(x, N) {
                if (symmetric_grid[y][x] != symmetric_grid[x][y]) isSymmetric=  false;
            }
        }
        if (!isSymmetric) continue;
        ans += N;
    }
    cout << ans;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define LIM 1<<17
/// TONI BO$$ was here
/// #MLC

using namespace std;
char BUF[LIM];
int poz;

inline char getChar(){
    poz++;
    if(poz>=LIM){
    	fread(BUF,LIM,1,stdin);
    	poz=0;
    }
    return BUF[poz];
}

inline int getNr(){
    int r=0, semn=1;
    char ch=getChar();
    while(isdigit(ch)==0 && ch!='-') ch=getChar();
    if(ch=='-'){
        semn=-1;
        ch=getChar();
    }
    while(isdigit(ch)!=0){
        r=r*10+semn*(ch-'0');
        ch=getChar();
    }
    return r;
}

int main()
{
    int n,t,a,rez,p,x,i;
    //freopen(".in","r",stdin);
    //freopen(".out","w",stdout);
    scanf("%d%d%d",&n,&t,&a);
    a*=1000;
    t*=1000;
    rez=1e9;
    p=0;
    for(i=1; i<=n; i++)
    {
        scanf("%d",&x);
        if(rez>abs(t-x*6-a))
            rez=abs(t-x*6-a),p=i;
    }
    printf("%d",p);

    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i, n) for (int i = 0; i < n; i++)

int main() {
  int N;
  string A, B, C;
  cin >> N >> A >> B >> C;

  int count = 0;
  // N文字目についてチェック
  rep(i, N) {
    set<char> S;
    S.insert(A[i]);
    S.insert(B[i]);
    S.insert(C[i]);

    switch (S.size()) {
      case 1:
        break;
      case 2:
        count++;
        break;
      case 3:
        count += 2;
        break;
      default:
        cout << "error" << endl;
    }
  }

  cout << count << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define F(i,n) for (int i=1; i<=(int)n; i++)
#define FF(i,n) for (int i=0; i<(int)n; i++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define pi pair < int , int >
#define re(x) (int)x.size()
#define y1 u228
using namespace std;
typedef long long ll;
const int N = 2e5+228;
const int big = 2e9;
const int md = 1e9 + 7;
ll k,a,b,ans,tex;
int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);
    //freopen("input.txt","r",stdin);
    cin>>k>>a>>b;
    tex=1ll;
    if (k>=a-1){
        tex+=a-1ll;
        k-=a-1ll;
    }
    if (tex>=a){ ans=tex;
    if (b-a>=2){
        ll kol=k/2ll;
        ans+=kol*(b-a);
        k%=2;
    }
    }
    ans+=k;
    cout<<ans<<endl;
    return 0;
}







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

using namespace std;

int main() {
	int N;
	cin >> N;
	
	vector<bool> flag(100, true);
	int ans = 0;
	for (int i = 0; i < N; i++) {
		int d;
		cin >> d;
		d--;
		if (flag[d]) ans++;
		flag[d] = false;
	}

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

Measured memory_bytes: 256
package main

import (
	"fmt"
	"math"
)

var H, W int
var ans int = 999999999999

func main() {
	fmt.Scan(&H, &W)

	if H*W%3 == 0 {
		fmt.Println(0)
	} else {
		for i := 1; i < H; i++ {
			Sa := i * W
			Sb := (H - i) * floor(W/2)
			Sc := H*W - Sa - Sb

			s_max := max(Sa, Sb, Sc)
			s_min := min(Sa, Sb, Sc)
			ans = min(ans, s_max-s_min)
		}

		for i := 1; i < H; i++ {
			Sa := i * W
			Sb := floor((H-i)/2) * W
			Sc := H*W - Sa - Sb

			s_max := max(Sa, Sb, Sc)
			s_min := min(Sa, Sb, Sc)
			ans = min(ans, s_max-s_min)
		}

		for i := 1; i < W; i++ {
			Sa := i * H
			Sb := (W - i) * floor(H/2)
			Sc := H*W - Sa - Sb

			s_max := max(Sa, Sb, Sc)
			s_min := min(Sa, Sb, Sc)
			ans = min(ans, s_max-s_min)
		}
		for i := 1; i < W; i++ {
			Sa := i * H
			Sb := floor((W-i)/2) * H
			Sc := H*W - Sa - Sb

			s_max := max(Sa, Sb, Sc)
			s_min := min(Sa, Sb, Sc)
			ans = min(ans, s_max-s_min)
		}
		fmt.Println(ans)
	}
}

/*  ----------------------------------------  */

func gcd(x, y uint64) uint64 {
	if x%y == 0 {
		return y
	} else {
		r := x % y
		return gcd(y, r)
	}
}

func combination(x, y int) int {
	return permutation(x, y) / permutation(y, y)
}

func permutation(x, y int) int {
	var ans int = 1
	for i := x - y; 0 < i; i-- {
		ans *= i
	}
	return ans
}

func max(x ...int) int {
	var res int = x[0]
	for i := 1; i < len(x); i++ {
		res = int(math.Max(float64(x[i]), float64(res)))
	}
	return res
}

func min(x ...int) int {
	var res int = x[0]
	for i := 1; i < len(x); i++ {
		res = int(math.Min(float64(x[i]), float64(res)))
	}
	return res
}

func pow(x, y int) uint64 { return uint64(math.Pow(float64(x), float64(y))) }
func abs(x int) int       { return int(math.Abs(float64(x))) }
func floor(x int) int     { return int(math.Floor(float64(x))) }
func ceil(x int) int      { return int(math.Ceil(float64(x))) }

type si struct {
	s int
	i int
}

type SortBy []si

func (a SortBy) Len() int           { return len(a) }
func (a SortBy) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a SortBy) Less(i, j int) bool { return a[i].s < a[j].s }


Measured memory_bytes: 512
A,B,K= list(map(int,input().split()))

for i in range(K):
    if i%2==0:
        if A%2:
            A-=1
        B+= A//2
        A = A//2
    else:
        if B%2:
            B-=1
        A+= B//2
        B = B//2

print(A,B)

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <vector>
typedef long long ll;
using namespace std;

ll x[100010];
int a[100010], nsw[100010], now[100010], vid[100010], vnum[100010], repl[100010];
bool looked[100010]={};
vector<vector<int>> v;

int main() {
	int N;
	cin >> N;
	for(int i=0; i<N; ++i) cin >> x[i];
	int M;
	ll K;
	cin >> M >> K;
	for(int i=0; i<M; ++i) cin >> a[i];
	for(int i=1; i<N; ++i) nsw[i]=i;
	for(int i=0; i<M; ++i) swap(nsw[a[i]-1], nsw[a[i]]);
	for(int i=1; i<N; ++i) now[nsw[i]]=i;
	int cnt=0;
	for(int i=1; i<N; ++i){
		if(!looked[i]){
			int b=i;
			v.emplace_back();
			do{
				vnum[b]=v[cnt].size();
				v[cnt].emplace_back(b);
				vid[b]=cnt;
				looked[b]=1;
				b=now[b];
			}while(b!=i);
			++cnt;
		}
	}
	for(int i=1; i<N; ++i){
		ll sz=v[vid[i]].size();
		ll r=(K%sz+vnum[i])%sz;
		repl[v[vid[i]][r]]=i;
	}
	cout << x[0] << endl;
	ll ans=x[0];
	for(int i=1; i<N; ++i){
		ans += x[repl[i]]-x[repl[i]-1];
		cout << ans << endl;
	}
	return 0;
}

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

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

	long long N, K;
	cin >> N >> K;

	long long rem = N % K;
	long long val = llabs(rem - K);

	if (rem < val)
		cout << rem;
	else
		cout << val;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll ;
const ll MOD = 1e9 + 7;
const ll dx[4] = { -1,1,0,0 };
const ll dy[4] = { 0,0,-1,1 };
const ll MAX = 1e5 + 50 ;
const ll oo = 1e16;
#define pb push_back
#define f first
#define s second
#define all(v) v.begin(),v.end()
long long gcd(long long  a, long long  b) { return (b == 0 ? a : gcd(b, a % b)); }
ll n , m , q , ans; string s ;
set < pair < int , int > > ed;
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    cin >> n ;
    if(n%2){
        for(int i = 1 ; i <= n/2 ; ++i)
            ed.insert({i , n - i});

        cout << n * (n - 1) / 2 - (int)ed.size() << '\n';
        for(int i = 1 ; i <= n ; ++i)
            for(int j = i + 1 ; j <= n ; ++j)
                if(ed.find({i , j}) == ed.end())
                    cout << i << ' ' << j << '\n';

        return 0 ;
    }

        for(int i = 1;i <= n/2 ; ++i)
            ed.insert({i , n - i + 1});

      cout << n * (n - 1) / 2 - (int)ed.size() << '\n';
      for(int i = 1 ; i <= n ; ++i)
            for(int j = i + 1 ; j <= n ; ++j)
                if(ed.find({i , j}) == ed.end())
                    cout << i << ' ' << j << '\n';
     return 0;
}


Measured memory_bytes: 256
#include <vector>
#include <bitset>
#include <map>
#include <queue>
#include <climits>
#include <algorithm>
#include <iostream>
#include <cmath>
#include <set>
using namespace std;

template <unsigned T>
bool prevSubset(bitset<T>& bs, const bitset<T>& mask)
{
    if(bs.none())
        return false;
    bs = bs.to_ulong() - 1ull;
    bs &= mask;
    return true;
}


int n;
vector<vector<int> > edges;
vector<bitset<100> > isEdges;

int solve(bitset<100> bs, int i)
{
	int ret = 0;
	for(int j=i; j<n; ++j){
		if((bs & isEdges[j]) == bs){
			bs[j] = true;
			ret = max(ret, solve(bs, j+1));
			bs[j] = false;
		}
	}

	if(bs.count() <= 1)
		return ret;

	int tmp1 = 0;
	for(int i=0; i<n; ++i){
		if(!bs[i])
			continue;
		int tmp2 = INT_MAX;
		for(int j=0; j<n; ++j){
			if(bs[j] && j != i)
				tmp2 = min(tmp2, edges[i][j]);
		}
		tmp1 += tmp2;
	}

	return max(ret, tmp1);
}

int main()
{
	int m;
	cin >> n >> m;
	edges.assign(n, vector<int>(n, 0));
	isEdges.assign(n, 0);

	for(int i=0; i<m; ++i){
		int a, b, c;
		cin >> a >> b >> c;
		-- a;
		-- b;
		edges[a][b] = edges[b][a] = c;
		isEdges[a][b] = isEdges[b][a] = true;
	}

	cout << solve(0, 0) << endl;

	return 0;
}

Measured memory_bytes: 920
#include<stdio.h>

int main (void){
    int d;
    scanf("%d",&d);
    int p[d];
    int i,e,r ;
    for (i=0;i<d;i++)
        scanf("%d",&p[i]);
    int max ;
    max=0;
    for(e=0;e<d;e++){
     if (p[e] > max) max = p[e];
}
    int sum =0;
    for(r=0;r<d;r++)
        sum = sum +p[r];
    
    sum = sum - max/2;
    printf("%d",sum);

return 0;
}

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

int main() {
    int n;
    cin >> n;
    vector<long long int> a(n), b(n);
    for(int i = 0; i < n; i++){
        cin >> a[i], a[i]--;
        b[a[i]]++;
    }
    long long int ans = 0;
    for(int i = 0; i < n; i++){
        ans += (b[i] * (b[i] - 1) / 2);
    }
    for(int i = 0; i < n; i++){
        cout << ans - (b[a[i]] - 1) << endl;
    }
    return 0;
}

Measured memory_bytes: 5760
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

map<ll, ll> prime_factor(ll n){
	map<ll, ll> res;
	for(ll i = 2; i*i <= n; i++){
		while(n%i == 0){
			res[i]++;
			n /= i;
		}
	}
	if(n != 1) res[n] = 1;
	return res;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    map<ll, ll> mp;
    for(int i = 1; i <= n; ++i){
        for(auto p : prime_factor(i)){
            mp[p.first] += p.second;
        }
    }
    ll c75 = 0, c25 = 0, c15 = 0, c5 = 0, c3 = 0;
    for(int i = 1; i <= n; ++i){
        if(mp[i] >= 74) ++c75;
        if(mp[i] >= 24) ++c25;
        if(mp[i] >= 14) ++c15;
        if(mp[i] >= 4) ++c5;
        if(mp[i] >= 2) ++c3;
    }
    ll ans = c75 + c25*(c3-1) + c15*(c5-1) + c5*(c5-1)*(c3-2)/2;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define f(x) (x)*(x)
using namespace std;
int n,a[1001],cnt,ans,ans2,ans3;
int main(){
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        cnt+=a[i];
    }
    int t=cnt/n;
    for(int i=1;i<=n;i++){
        ans+=f(a[i]-t);
        ans2+=f(a[i]-t-1);
        ans3+=f(a[i]-t+1);
    }
    int tt=ans<ans2? ans:ans2;
    tt=tt>ans3? ans3:tt;
    cout<<tt;
    return 0;
}

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

int main(void) {

	int a, b, c;

	cin >> a >> b >> c;

	if (b - a == c - b)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;


	return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef pair<P,int> T;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
template<class T> void chmin(T& a,const T& b){if(a>b)a=b;}
template<class T> void chmax(T& a,const T& b){if(a<b)a=b;}
int dig(int x){
	int res = 0;
	while(x){
		x /= 10;
		res++;
	}
	return res;
}
int main(){
	int N;
	cin >> N;
	int ans = 0;
	for(int i=1;i<=N;i++){
		if(dig(i)%2==1)ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
K, A, B = map(int, input().split())

if A >= B:
    print(K + 1)
    
elif B - A <= 2:
    print(K + 1)

else:
    tmp = (K - (A - 1)) // 2 #ビスケの数をAからBにできる回数
        
    res = (B - A) * tmp + A  
    if (K - (A - 1)) % 2 == 1:
        res += 1
    print(res)

Measured memory_bytes: 3060
#include <stdio.h>
#include <stdlib.h>
int main(){
  int *A, N, j ,flag, temp, count;

  scanf("%d",&N);
  A = (int *)malloc(sizeof(int) * N);
  for(j=0; j<N; j++){
    scanf("%d",&A[j]);
  }

  count = 0;
  flag = 1;
  while(flag){
    flag = 0;
    for(j=N-1; j>0; j--){
      if(A[j]<A[j-1]){
	temp = A[j];
	A[j] = A[j-1];
	A[j-1] = temp;
	flag = 1;
	count++;
      }
    }
  }
  for(j=0; j<N; j++){
    printf("%d",A[j]);
    if(j != N-1) printf(" ");
  }
  printf("\n%d\n",count);
  
  return 0;
}



Measured memory_bytes: 2140
const NMAX=100000;
var n,m,i,j:integer;
    x:array[1..NMAX] of integer;
    y:array[1..NMAX] of integer;
    
procedure sortx(p,q:integer);
  var i,j,k,w:integer;
begin i:=p;j:=q; k:=x[(p+q) div 2];
  repeat
    while x[i]<k do i:=i+1;
    while k<x[j] do j:=j-1;
    if i<=j then begin
      w:=x[i]; x[i]:=x[j]; x[j]:=w;
      i:=i+1; j:=j-1
    end
  until i>j;
  if p<j then sortx(p,j);
  if i<q then sortx(i,q)
end;
procedure sorty(p,q:integer);
  var i,j,x,w:integer;
begin i:=p;j:=q; x:=y[(p+q) div 2];
  repeat
    while y[i]<x do i:=i+1;
    while x<y[j] do j:=j-1;
    if i<=j then begin
      w:=y[i]; y[i]:=y[j]; y[j]:=w;
      i:=i+1; j:=j-1
    end
  until i>j;
  if p<j then sorty(p,j);
  if i<q then sorty(i,q)
end;

begin
  read(n);
  readln(m);
  for i:=1 to m do read(x[i]);
  sortx(1,m);
  for i:=1 to m-1 do y[i]:=x[i+1] - x[i];
  sorty(1,m-1);
  j:=0;
  for i:=1 to m-n do j:=j+y[i];
  write(j)
end.


Measured memory_bytes: 896
#include <iostream>
#include <algorithm>

int isRightTriangle(int a, int b, int c)
{
	int s[3] = {a, b, c};
	std::sort(s, s+3);
	return (s[0] > 0) && (s[2] * s[2] == s[0] * s[0] + s[1] * s[1]);
}

int main()
{
	int count = 0;
	std::cin >> count;
	for (int i = 0; i < count; ++i) {
		int a = 0, b = 0, c = 0;
		std::cin >> a >> b >> c;
		std::cout << (isRightTriangle(a,b,c) ? "YES" : "NO") << std::endl;
	}

	return 0;
}

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

const string YES = "Yes";
const string NO = "No";

void solve(long long N, std::vector<long long> t, std::vector<long long> x, std::vector<long long> y){
    // 移動時間 >= マンハッタン距離 かつ、座標の偶奇のチェック
    bool flg = true;
    long long nowx, nowy,nowt;
    long long nextx, nexty,nextt;
    nowx = 0; nowy = 0; nowt = 0;

    for(int i= 0; i < t.size(); i++){
        nextx = x[i];
        nexty = y[i];
        nextt = t[i];

        long long dist = abs(nowx - nextx) + abs(nowy - nexty);
        long long time = nextt - nowt;
        if(time >= dist && (time - dist) % 2 == 0){
            continue;
        } else { 
            flg = false;
            break;
        }
        nowx = nextx;
        nowy = nexty;
        nowt = nextt;
    }
    cout << (flg ? "Yes" : "No") << endl;

}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> t(N);
    std::vector<long long> x(N);
    std::vector<long long> y(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&t[i]);
        scanf("%lld",&x[i]);
        scanf("%lld",&y[i]);
    }
    solve(N, std::move(t), std::move(x), std::move(y));
    return 0;
}


Measured memory_bytes: 2560
#include<stdio.h>

int main(void){

  int p, q, r, sum;
  int max_1, max_2;

  scanf("%d", &p);
  scanf("%d", &q);
  scanf("%d", &r);

  if(p > q){
    max_1 = p;
  }
  else{
    max_1 = q;
  }

  if(max_1 > r){
    max_2 = max_1;
  }
  else{
    max_2 = r;
  }

  sum = p + q + r - max_2;

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

  return 0;
}


Measured memory_bytes: 128
import math

A, B, H, M = map(int, input().split())

# H時 : rad = 2*pi / 12 * H + (2*pi / 12) * m/60
# m分 : rad = 2*pi /60 * m

rad_h = (2 * math.pi / 12) * H + (2 * math.pi / 12) * M / 60  # 0~2*pi
rad_m = (2 * math.pi / 60) * M  # 0 ~ 2*pi

rad = abs(rad_h - rad_m)

if rad == 0:
    C = abs(A - B)
elif math.pi <= rad:
    rad = 2 * math.pi - rad

C = math.sqrt(A ** 2 + B ** 2 - 2 * A * B * math.cos(rad))
print(C)


Measured memory_bytes: 9460
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	r, _ := strconv.Atoi(nextLine())
	return r
}

func main() {
	sc.Split(bufio.ScanWords)
	d, n := nextInt(), nextInt()
	if n < 100 {
		fmt.Println(int(math.Pow(100, float64(d)) * float64(n)))
	} else {
		fmt.Println(int(math.Pow(100, float64(d)) * 101))
	}
}


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

using ll = long long;
using namespace std;
const int INFint = 2e9+1;
const ll INFll = 2e18+1;
ll MOD=1e9+7;


int main() {
  int N;
  cin>>N;
  int left = 0,right = N;
  cout << 0 << endl;
  string hazime;
  cin>>hazime;
  while(right - left > 1){
    int mid = (left + right) / 2;
    cout << mid << endl;
    string s;
    cin>>s;
    if((s != hazime && mid % 2 == 0) || (s == hazime && mid%2 == 1)){
      right = mid;
    }else{
      left = mid;
    }
    //cout << left << " " << right << endl;
  }
  cout << left << endl;
  //for(int i(0);i<20;i++){
    //cout << i << endl;
    //string s;
    //cin>>s;
  //}
  return 0;
}

Measured memory_bytes: 852
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
using namespace std;
long long INFI=1e15;
vector<long long>a;
long long n;
vector<vector<long long>>dp;
long long cost(long long s,long long e)
{
  if(e==s)return 0;
  if(dp[s][e]!=INFI)return dp[s][e];
  for(long long i=s;i<e;i++)
  {
    dp[s][e]=min(cost(s,i)+cost(i+1,e),dp[s][e]);
  }
  dp[s][e]+=a[e]-a[s-1]*(s>1);
  return dp[s][e];
}
int main()
{
  ios::sync_with_stdio(false);
  cin>>n;
  a=vector<long long>(n+1);
  dp=vector<vector<long long>>(n+1,vector<long long>(n+1,INFI));
  for(long long i=0;i<n;i++)
  {
    cin>>a[i+1];
    a[i+1]+=a[i]*(i>0);
  }
  cout<<cost(1,n);



  return 0;

}


Measured memory_bytes: 1536
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < (int)(n); i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
using ll = long long;

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

    int r = 0;
    REP(i, 0, N) {
        if (S[i] == 'R') r++;
    }

    int ans = 0;
    REP(i, 0, r) {
        if (S[i] == 'W') ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3748
#include<stdio.h>

int main(void){
	char a[256];
	scanf("%s",a);

	printf("%c%c%c%c %c%c%c%c%c%c%c%c\n",a[0],a[1],a[2],a[3],a[4],a[5],a[6],a[7],a[8],a[9],a[10],a[11]);

	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define finish(x) return cout << x << endl, 0
#define ll long long

vector <int> v[5];

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    for(int i = 0 ; i < 3 ; i++){
        int x, y;
        cin >> x >> y;
        v[x].push_back(y);
        v[y].push_back(x);
    }
    for(int i = 1 ; i <= 4 ; i++)
        if(v[i].size() > 2)
            finish("NO");
    cout << "YES" << endl;
}


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

int main()
{
	//ios_base::sync_with_stdio(false);
	//cin.tie(NULL);
	
	ll n;
	cin>>n;
	
	for(ll i=0;i<n;i++)
	{
	    cin>>arr[i];
	}
	
	ll dp[n]={0};
	
	dp[1]=abs(arr[1]-arr[0]);
	
	for(ll i=2;i<n;i++)
	{
	    dp[i]=min(dp[i-2]+abs(arr[i]-arr[i-2]) , dp[i-1] +abs(arr[i]-arr[i-1]));
	}
	
	cout<<dp[n-1]<<"\n";
	
}


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

using vi = std::vector<int>;
using vvi = std::vector<vi>;

vvi edges;
std::vector<bool> visited;
std::vector<int64_t> counter;

void dfs(int, int64_t);

int main()
{
	int N, Q;
	scanf("%d%d", &N, &Q);
	edges.resize(N);
	for (int i{}; i < N - 1; i++)
	{
		int a, b;
		scanf("%d%d", &a, &b);
		a--; b--;
		edges[a].push_back(b);
		edges[b].push_back(a);
	}
	counter.resize(N);
	for (int i{}; i < Q; i++)
	{
		int p, x;
		scanf("%d%d", &p, &x);
		p--;
		counter[p] += x;
	}

	visited.resize(N);
	dfs(0, 0ll);
	for (int i{}; i < N; i++)
		printf("%lld%c", counter[i], i + 1 == N? '\n': ' ');

	return 0;
}

void dfs(int index, int64_t sum)
{
	if (visited[index]) return;
	visited[index] = true;
	counter[index] += sum;
	for (auto& e: edges[index])
		dfs(e, counter[index]);
	return;
}


Measured memory_bytes: 21120
n=int(input())
S=sorted([int(input()) for i in range(n)])
if sum(S) % 10 != 0:
  print(sum(S))
else:
  for i in range(n):
    if S[i] % 10 != 0:
      print(sum(S)-S[i])
      break
  else:
    print(0)

Measured memory_bytes: 62372
class PriorityQueue
  def initialize#(&comp)
    @heap = []
    @node_num = 0
    # if !block_given?
    #   @comp = lambda { |x, y| x <= y }
    # else
    #   @comp = comp
    # end
  end

  def push(x)
    i = @node_num # 自分のノード番号
    @node_num += 1
    while i > 0
      par = (i - 1) / 2 # 親のノード番号
      break if func(@heap[par], x) # 逆転してないなら抜ける
      # 親ノードを下ろして自分を上に
      @heap[i] = @heap[par]
      i = par
    end
    @heap[i] = x
  end

  alias_method(:<<, :push)

  def pop
    # 最(小|大)値
    ret = @heap[0]
    # 根にもってくる値
    @node_num -= 1
    x = @heap[@node_num]
    # 根から下ろしていく
    i = 0
    while i * 2 + 1 < @node_num
      # 子どうしを比較
      a, b = i * 2 + 1, i * 2 + 2
      a = b if b < @node_num && !func(@heap[a], @heap[b])
      break if func(x, @heap[a])
      @heap[i] = @heap[a]
      i = a
    end
    @heap[i] = x
    return ret
  end

  def get
    @node_num == 0 ? nil : @heap[0]
  end

  def empty?
    return get.nil?
  end
end

def func(x, y)
  return x > y
end

n, m = gets.split.map(&:to_i)
a = gets.split.map(&:to_i)
q = PriorityQueue.new #{ |x, y| x > y }



a.each do |ai|
  q << ai
end
m.times do
  max_n = q.pop()
  q << (max_n / 2)
end
ans = 0
n.times do
  ans += (q.pop)
end
p ans


Measured memory_bytes: 9556
#ifndef BZ
#pragma GCC optimize "Ofast"
#endif
#include <bits/stdc++.h>
using namespace std;
using ull = uint64_t;
using ll = int64_t;
using ld = long double;

const int MOD = 1e9 + 7;

ll pw(ll a, ll b) {
    if (!b) {
        return 1;
    }

    ll v = pw(a, b / 2);
    v = (v * v) % MOD;

    if (b & 1) {
        v = (v * a) % MOD;
    }

    return  v;
}

const int MAXN = 100228;
ll rev[MAXN];

int main() {
#ifdef BZ
    freopen("input.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); cout.setf(ios::fixed); cout.precision(20);
    int n;
    cin >> n;
    ll ans = 0;
    ll cur = 0;
    ll fact = 1;

    for (int i = 1; i <= n; ++i) {
        rev[i] = pw(i, MOD - 2);
        cur = (cur + rev[i]) % MOD;
        fact *= i;
        fact %= MOD;
    }

    for (int i = 0; i < n; ++i) {
        ll x;
        cin >> x;
        ans = (ans + x * cur) % MOD;
        cur = (cur - rev[n - i] + rev[i + 2] + MOD) % MOD;
    }

    cout << (ans * fact) % MOD << "\n";
}
 

Measured memory_bytes: 1024
#include <cstdio>
#include <array>
#include <utility>

template <unsigned int N> struct shuumai{
    unsigned int minPrime[N + 1];
    unsigned int Primes[N + 1];
    unsigned int size_;

    constexpr shuumai(void): minPrime(), Primes(), size_(0U){
        minPrime[0] = 1; minPrime[1] = 1;
        for(int even = 2, odd = 3; odd <= N; even += 2, odd += 2){
            minPrime[even] = 2;
            minPrime[odd] = odd;
        }
        if(!(N & 1)) minPrime[N] = 2;
        Primes[size_++] = 2;

        for(int x = 3; x <= N; x += 2){
            if(minPrime[x] == x) Primes[size_++] = x;
            for(int y = 0; y < size_ and Primes[y] <= minPrime[x] and x * Primes[y] <= N; ++y)
                    minPrime[x * Primes[y]] = Primes[y];
        }
    }
    // 範囲for文用の begin() と end()
    const unsigned int *begin(void) const noexcept{ return Primes; }
    const unsigned int *end(void) const noexcept{ return Primes + size_;}
    const unsigned int size(void) const {return this.size_;}
};

using uint = unsigned int;
constexpr uint N = 1e6;
constexpr uint mod = 1e9 + 7;
constexpr uint M = mod - 2;
constexpr shuumai<N> P;
std::array<uint, N + 1> Count;

// a^nを返す関数
const uint power(uint a, uint n)noexcept{
    unsigned long long res = 1, waiting = a;
    while(n){ 
        if(n & 1) { res *= waiting; res %= mod; }
        waiting *= waiting; waiting %= mod; 
        n >>= 1;
    }
    return res;
}

uint fastRead(void) {
	char c;
	while(true){
        c = getchar();
        if('0' <= c) break;
	}
    uint res = c - '0';
	while(true){
		c = getchar();
        if(c < '0') break;
		res = 10 * res + (c - '0');
	}
    return res;
}


int main(void){
    uint n = fastRead();
    uint inv_sum = 0U;
    for(uint _ = 0; _ < n; ++_){
        uint a = fastRead();
        inv_sum += power(a, M); if(inv_sum >= mod) inv_sum -= mod;
        while(a - 1U){
            uint fac = P.minPrime[a];
            uint cnt = 1U; a /= fac;
            while(!(a % fac)) a /= fac, cnt++;
            if(Count[fac] < cnt) Count[fac] = cnt; 
        }
    }

    unsigned long long int lcm = 1;
    for(unsigned int x : P) if(Count[x]) (lcm *= power(x, Count[x])) %= mod;
    unsigned int res = lcm * inv_sum % mod;
    
    printf("%u\n", res);
    return 0;
}


Measured memory_bytes: 3200
import java.util.*;
import java.lang.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] W = new int[N];
        int total = 0;
        for(int n=0; n<N; n++){
            W[n]=sc.nextInt();
            total += W[n];
        }
        int current = 0;
        int ans = 1000000;
        for(int n=0; n<N; n++){
            current += W[n];
            ans = Math.min(ans, Math.abs(current-(total-current)));
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 23380
n=gets.to_i
dp=[0]+[Float::INFINITY]*n
(0..n).each do |i|
    [6, 9].each do |a|
        k=1
        while i+k<=n
            t=dp[i+k]
            dp[i+k]=dp[i]+1 if t>dp[i]+1
            k*=a
        end
    end
end
puts dp[n]

Measured memory_bytes: 3324
#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>

int main()
{
  long long int i,j,i1,j1,c,b;
  int n,k;
  scanf("%d %d",&n,&k);
  c = 0;
  i1 = j1 = -1;
  for(i=0;i<=n-3;i++){
    for(j=1;j<=5;j++){
      if( ( 9*( 7*i+j ) + 72 ) % 11 == (long long int)k ){
        i1 = i;
        j1 = j;
        c++;
        break;
      }
    }
    if( i1>=0 ) break;
  }
  
  if(c==0){
    printf("0\n");
    return EXIT_SUCCESS;
  }
  
  b = ( n-4 - i1)/11;
  if(b>0){
    i1 += b*11;
    c += 5*b;
  }
  c--;
  for(i=i1;i<=n-3;i++){
    for(j=1;j<=5;j++){
      if( ( 9*( 7*i + j ) + 72 ) % 11 == (long long int)k ){
        c++;
      }
    }
  }
  printf("%d\n",(int)c);

  return EXIT_SUCCESS;
}



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


int main() {
    
    int n,w;
    cin>>n>>w;
    vector <long long> val(n,0);
    vector <long long> wt(n,0);
    
    for(int i=0;i<n;i++)cin>>wt[i]>>val[i];
    
    vector <vector <long long>> dp(n+1,vector <long long>(w+1,0));
    
    
    for(int i=1;i<=n;i++){
        for(int j=1;j<=w;j++){
            if(j>=wt[i-1]){
                dp[i][j]=max(dp[i-1][j],dp[i-1][j-wt[i-1]]+val[i-1]);
            }
            else dp[i][j]=dp[i-1][j];
        }
    }
    cout<<dp[n][w]<<endl;
    
}

Measured memory_bytes: 80256
#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;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) cin >> a[i];
    
    /* しゃくとり法 */
    long long res = 0;
    int right = 0;
    int sum = 0; // AND 和
    for (int left = 0; left < n; ++left) {
        while (right < n && (sum ^ a[right]) == (sum + a[right])) {
            sum += a[right];
            ++right;
        }
        res += right - left;
        //if (left == right) ++right;
        //else {
            sum -= a[left]; // a[left] を削除 (sum ^= a[left] でも OK)
        //}
    }
    
    cout << res << endl;
}


Measured memory_bytes: 1024
$_=<>;($a,$b)=glob<>;s#F+#push@{$`=~y/T//&1},length$&#ge;$a-=/^1/&&shift@0;$s=$_?b:a,map$$s+=($$s>0?-$_:$_),sort{$b-$a}@$_ for 0,1;print$a|$b?No:Yes

Measured memory_bytes: 1152
#include<bits/stdc++.h>
 using namespace std;
 
 int main()
 {
 int n;
 cin>>n;
 int ar[n];
 for(int i=0;i<n;i++)
  cin>>ar[i];
  int y=0;
  for(int i=0;i<n;i++)
   {
   if(ar[i]%2==0 && (ar[i]%3!=0 && ar[i]%5!=0))
     {cout<<"DENIED"<<endl;y=1;break;}
   }
   if(y==0) cout<<"APPROVED"<<endl;
  return 0;
 }

Measured memory_bytes: 256
abc = list(input().split())
counter_f = 0
counter_s = 0
for i in abc:
    if int(i) == 5:
        counter_f += 1
    elif int(i) == 7:
        counter_s += 1
if counter_f==2 and counter_s ==1:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define BIG 1000000010
#define EPS 1e-9
#define fst first
#define scd second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long
#define endl "\n"


signed main(){
  cin.tie(0);	
  ios::sync_with_stdio(false);
  int n;
  cin>>n;
  int b[100];
  int ans=0;
  rep(i,n-1) cin>>b[i];
  ans+=b[n-2];
  repn(i,n-2){
    if(i==0){
      ans+=b[0];
      break;
    }
    ans+=min(b[i],b[i-1]);
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  for(int i=1;i<=6;i++){
    cin>>s[i];
  }
  if(s[3]==s[4]&&s[5]==s[6]){
    cout<<"Yes";
  }
  else{
    cout<<"No";
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep2(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) rep2(i,0,n)
#define FOR(i) for(cin>>i;i>0;i--)
#define elif else if
#define pb push_back
#define ll long long
#define mp make_pair
#define all(x) x.begin(),x.end()
#define re(x) {cout<<x<<endl;return 0;}
//#define x first
//#define y second

using namespace std;

int main()
{
	int n;
	cin>>n;
	rep(i,n) cout<<"ACL";
	cout<<endl;
	return 0;}

Measured memory_bytes: 3516
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pp pair<pair<ll, ll>,pair<ll, ll>>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define vii vector<int>
#define vll vector<ll>
#define mat vector<vector<ll>>
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define eb emplace_back
#define fi first
#define sc second
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define sz(x) (ll) (x).size()
#define pq priority_queue<ll>
#define pqg priority_queue<ll,vector<ll>,greater<ll>>
#define LB(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define UB(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
#define ERASE(v) sort(v.begin(),v.end());v.erase(unique(v.begin(),v.end()),v.end())
#define int ll
// #define ll int
using namespace std;
const ll INF = (1 << 30 ) - 1;
const ll LLINF = (1LL << 60LL);
const ll MOD = 1000000007;
const ll mod = 998244353;
const ll MAX = 1100000;
const double pi = acos(-1);
const double eps = 1e-10;
ll dx[8] ={1,0,-1,0,1,-1,1,-1};
ll dy[8] ={0,1,0,-1,1,-1,-1,1};
 
template<class T> 
inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> 
inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
 
struct Timer{
    chrono::system_clock::time_point start, end;
    Timer(){ start = chrono::system_clock::now(); }
    ~Timer(){
        end = chrono::system_clock::now();
        auto msec = chrono::duration_cast<chrono::milliseconds>(end - start).count();
        cerr<<"time : "<<msec<<" ms"<<endl;
    }
};


void solve(){
    ll a,b;
    cin>>a>>b;
    map<pll,ll> mp;
    rep2(i,1,100000){
        ll c=i*108/100-i;
        ll d=i*110/100-i;
        if(mp[pll(c,d)]==0) mp[pll(c,d)]=i;
    }
    if(mp[pll(a,b)]==0) cout<<-1<<endl;
    else cout<<mp[pll(a,b)]<<endl;
}

 
signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    // Timer TM;
     
    solve();


    return 0;
}

Measured memory_bytes: 1280
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		double a;
		int b = 3;
		a = sc.nextDouble();
		double num = Math.pow(a, b);
		int num2 = (int) num;
		System.out.println(num2);
		sc.close();
	}
}


Measured memory_bytes: 27848
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define ios ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)

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

//-------------------ここから回答する-----------------------

void solve(void)
{
    int w, a, b;
    cin >> w >> a >> b;
    int ans = max(0, max(b - (a + w), a - (b + w)));
    cout << ans << endl;
}
int main(void)
{
    solve();
}


Measured memory_bytes: 3532
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    string s;
    string p;
    string x;
    cin>>s;
    cin>>p;
    for(int i=0;i<n;i++)
    {
        cout<<s[i]<<p[i];
    }



    return 0;

}


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

//#define int long long
#define ll long long
#define all(v) (v).begin(), (v).end()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

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;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

signed main()
{   
    gearup;
    int n; cin >> n;
    int x = n;
    int res = 0;
    while(x>0){
        res+=x%10;
        x/=10;
    }
    cout << (n%res==0?"Yes":"No") << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200005;
#define lson root<<1
#define rson root<<1|1
#define Mid (l+r>>1)
struct Seg_Tree{
	int Min,lazy;
}tree[MAXN<<2];
int N,Q,cnt,ans;
int a[MAXN],sum1[MAXN],sum0[MAXN];
vector < int > S[MAXN]; 
inline int read(){
	int x=0,f=1;char c=getchar();
	while(c<'0' || c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0' && c<='9'){x=x*10+c-'0';c=getchar();}
	return x*f;
}
inline void push_up(int root){
	tree[root].Min=min(tree[lson].Min,tree[rson].Min);
}
inline void push_down(int root){
	tree[lson].lazy+=tree[root].lazy;
	tree[rson].lazy+=tree[root].lazy;
	tree[lson].Min+=tree[root].lazy;
	tree[rson].Min+=tree[root].lazy;
	tree[root].lazy=0;
}
inline void Insert(int root,int l,int r,int Pos,int k){
	if(l==Pos && r==Pos){
		tree[root].Min=min(tree[root].Min,k);
		return ;
	}if(tree[root].lazy) push_down(root);
	if(Pos<=Mid) Insert(lson,l,Mid,Pos,k);
	else Insert(rson,Mid+1,r,Pos,k);
	push_up(root);
}
inline void Update(int root,int l,int r,int L,int R,int k){
	if(l>=L && r<=R){
		tree[root].lazy+=k,tree[root].Min+=k;
		return ;
	}if(tree[root].lazy) push_down(root);
	if(R<=Mid) Update(lson,l,Mid,L,R,k);
	else if(L>Mid) Update(rson,Mid+1,r,L,R,k);
	else Update(lson,l,Mid,L,R,k),Update(rson,Mid+1,r,L,R,k);
	push_up(root);
}
inline int Query(int root,int l,int r,int L,int R){
	if(l>=L && r<=R) return tree[root].Min;
	if(tree[root].lazy) push_down(root);
	if(R<=Mid) return Query(lson,l,Mid,L,R);
	else if(L>Mid) return Query(rson,Mid+1,r,L,R);
	else return min(Query(lson,l,Mid,L,R),Query(rson,Mid+1,r,L,R));
}
int main(){
	N=read();for(register int i=1;i<=N;i++) 
	    a[i]=read(),sum1[i]=sum1[i-1]+(a[i]==1),sum0[i]=sum0[i-1]+(a[i]==0);
	Q=read();for(register int i=1;i<=Q;i++){
		int x=read(),y=read();
		S[x].push_back(y); 
	}for(register int i=0;i<MAXN<<2;++i) tree[i].Min=1e9;
	Insert(1,0,N,0,0);
	for(int i=1;i<=N;i++){
		for(int j=0;j<S[i].size();j++) Insert(1,0,N,S[i][j],Query(1,0,N,0,S[i][j]));
		Update(1,0,N,0,i-1,a[i]?1:-1);
	}printf("%d",Query(1,0,N,0,N)+sum0[N]);
	return 0;
}


Measured memory_bytes: 17536
#include <stdio.h>
int main()
{
    int a,b,c,t,i;
    scanf("%d%d",&a,&b);
    if(b<10)
        c=a*10+b;
    else if(b<100)
        c=a*100+b;
    else
        c=a*1000+b;
    for(i=1;i<=1000;i++)
    {
        if(i*i==c)
            {
                t=0;
                break;
            }
            else
                t=1;
 
    }
    if(t==0)
        printf("Yes\n");
    else
        printf("No\n");
 
    return 0;
}


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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define a first
#define b second
#define sz size()
#define pb(x) push_back(x) 
#define bg begin()
#define ed end()
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define mp(x,y) make_pair(x,y)
const ll MOD=1000000007;

vector<ll> pw2(51,1); vector<ll> pw10(19,1);
ll maxx(ll x,ll y,ll z){return max(max(x,y),z);}
ll minn(ll x,ll y,ll z){return min(min(x,y),z);}
ll mid(ll x,ll y,ll z){return x>y?y>=z?y:min(z,x):x>=z?x:min(y,z);}
ll gcd(ll x,ll y){if(x%y==0) return y;else return gcd(y,x%y);}
ll lcm(ll x,ll y){return x*(y/gcd(x,y));}
ll myceil(ll x,ll y){if(x<=y) return 1;else if(x%y==0) return x/y;else return x/y+1;}

ll fac[300001],finv[300001],inv[300001];//Nの制約

// テーブルを作る前処理
void table() {
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(int i=2;i<300001;i++){
        fac[i]= fac[i-1]*i%MOD;
        inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
        finv[i]=finv[i-1]*inv[i]%MOD;
    }
}

// 二項係数計算
ll comb(int n, int k){
    if(n<k) return 0;
    if(n<0 || k<0) return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}

//a,b x
int main(){
    table();
    ll N,M; cin>>N>>M;
    ll ans=1;
    ll tmp=M;
    for(int i=2;i*i<=M;i++){
        ll cnt=0;
        while(1){
            if(tmp%i==0){
                tmp/=i;
                cnt++;
            }
            else break;
        }
        ans=(ans*comb(N-1+cnt,cnt))%MOD;
    }
    if(tmp!=1) ans=(ans*N)%MOD;
    
    cout<<ans;
}

Measured memory_bytes: 7296
/*
   一行目にnが与えられる。二行目にn個の要素を持つ数列Sが与えられる。
   三行目にqが与えられる。四行目にq個の要素を持つ数列Tが与えられる。

   Tに含まれる整数の中で、Sに含まれるものの個数Cを出力する。

   input:
   5
   1 2 3 4 5
   3
   3 4 1

   output:
   3
*/

#include <stdio.h>

int linerserch(int S[], int n, int key)
{
   for (int i = 0; i < n; i++)
      if (S[i] == key)
         return 1;

   return 0;
}

int main()
{
   int n;
   scanf("%d", &n);

   int S[n];
   for (int i = 0; i < n; i++)
      scanf("%d", &S[i]);

   int q;
   scanf("%d", &q);

   int T[q];
   for (int i = 0; i < n; i++)
      scanf("%d", &T[i]);

   int count = 0;

   for (int i = 0; i < q; i++)
      if (linerserch(S, n, T[i])) count++;

   printf("%d\n", count);
   return 0;
}


Measured memory_bytes: 2100
import heapq
N, M = map(int, input().split())
E = [[] for _ in range(N)]
RE = [[] for _ in range(N)]
S = [0] * N
for _ in range(M):
  l, r, d = map(int, input().split())
  S[l - 1] = 1
  E[l - 1].append([d, r - 1])
  RE[r - 1].append([d, l - 1])
D = [None] * N
def dijkstra(i):
  D[i] = 0
  Q = [[0, i]]
  while Q:
    d, s = heapq.heappop(Q)
    for dist, adj in E[s]:
      if D[adj] == None:
        D[adj] = D[s] + dist
        heapq.heappush(Q, [D[adj], adj])
      elif D[adj] == 'Error' or D[adj] != D[s] + dist:
        D[s] = 'Error'
        break
    else:
      for dist, adj in RE[s]:
        if D[adj] == None:
          D[adj] = D[s] - dist
          heapq.heappush(Q, [D[adj], adj])
        elif D[adj] == 'Error' or D[adj] != D[s] - dist:
          D[s] = 'Error'
          break
      else:
        continue
    break
for i in range(N):
  if D[i] == 'Error':
    print('No')
    break
  elif D[i] == None:
    dijkstra(i)
else:
  for d in D:
    if d == 'Error':
      print('No')
      break
  else:
    print('Yes')

Measured memory_bytes: 127776
#include <stdio.h>
#include <map>
#include <algorithm>
#include <vector>
#include <queue>
#include <cmath>

#define INF 1 << 29
#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)

using namespace std;

typedef pair<int,int> s;
typedef long long int ll;

int abs(int x){
  return x > 0 ? x : -x;
}

int length(char c[]){
  int cnt=0;
  for(cnt=0;c[cnt]!='\0';cnt++){
  }
  return cnt;
}

int n,m;

int main(){
  scanf("%d %d",&n,&m);
  int pow_2 = pow(2,m);
  printf("%d\n",pow_2*(1900*m+100*(n-m)));
}


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

int main() {
	long N, M;
	cin >> N >> M;
	long long sum = 0;
	if (N == 1) {
		if (M == 1) {
			sum = 1;
		} else if (M == 2) {
			sum = 0;
		} else {
			sum = M-2;
		}
	} else if (N == 2) {
		if (M == 1) {
			sum = 0;
		} else if (M == 2) {
			sum = 0;
		} else {
			sum = 0;
		}
	} else {
		if (M == 1) {
			sum = N-2;
		} else if (M == 2) {
			sum = 0;
		} else  {
			sum = (N-2)*(M-2);
		}
	}
	cout << sum << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
#define PI acos(-1)
#define hell 1000000007
#define HELL 998244353
#define io ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define fix(n) cout << fixed << setprecision(n)
#define mset(a,n) memset(a,n,sizeof a)
#define rep(i,a,b) for (__typeof((b)) i=(a);i<(b);i++)
#define repp(i,a,b,p) for(__typeof((b)) i=(a);i<(b);i+=p)
#define ren(i,a,b) for(__typeof((a)) i=(a);i>=(b);i--)
#define renn(i,a,b,p) for(__typeof((a) i=(a);i>=(b);i-=p)
#define lbd lower_bound
#define ubd upper_bound
#define ll long long
#define ld long double
#define pb push_back
#define fi first
#define se second
#define vll vector<ll>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define all(v) (v).begin(), (v).end()
#define sz(x) (ll)x.size()
#define endl "\n"
#define out(n) cout<<n<<" "
#define outl(n) cout<<n<<endl
#define line cout<<endl
#define bug(n) {outl(n);return;}
#define N 105
ll n,W,w[N],v[N],dp[N*1000],s;
void solve(){
	cin>>n>>W;
	rep(i,1,n+1)cin>>w[i]>>v[i],s+=v[i];
	dp[0]=0;
    rep(i,1,n+1){
        ren(j,s-v[i],0)dp[j+v[i]]=min(dp[j+v[i]],dp[j]+w[i]);
    }
    ren(i,s,0){
        if(dp[i]<=W)bug(i);
    }
}
void prep(){
    rep(i,1,N*1000)dp[i]=1e18;
}
int main(){
    io;
    ll t=1;
    // cin>>t;
    prep();
    fix(12);
    while(t--)
        solve();
    return 0;
}

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

using namespace std;

const int inf = 0x3f3f3f3f;

int vetor[100010][3], pd[100010][3];
int n, k;

int solve(int x, int y){
  if(pd[x][y] != 0) return pd[x][y];
  if(x >= n) return 0;

  for(int i=0 ; i<3 ; i++){
    if(i == y) continue;

    pd[x][y] = max(pd[x][y], solve(x+1, i));
  }

  pd[x][y] += vetor[x][y];

  return pd[x][y];
}

int main(){
  cin>>n;

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

  memset(pd, 0, sizeof pd);

  cout<<max(solve(0, 0), max(solve(0, 1), solve(0, 2)))<<endl;
}

Measured memory_bytes: 8832
#include <stdio.h>

int main(){
    int i, l[10], v1, v2, sum;
    double lc;
    
    while(scanf("%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d", &l[0], &l[1], &l[2], &l[3], &l[4], &l[5], &l[6], &l[7], &l[8], &l[9], &v1, &v2) != EOF){
    	lc = 0; sum = 0;
        for (i = 0; i < 10; i++) lc += l[i];
        lc *= (double)v1 / (v1 + v2);
        for (i = 0; i < 10; i++){
            sum += l[i];
            if (lc <= sum) {printf("%d\n", i + 1); break;}
        }
    }
    return 0;
}

Measured memory_bytes: 596
#define _DEBUG
#include "bits/stdc++.h"
#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0,a1,a2,a3,a4,x,...) x
#define debug_1(x1) cout<<#x1<<": "<<x1<<endl
#define debug_2(x1,x2) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<endl
#define debug_3(x1,x2,x3) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<endl
#define debug_4(x1,x2,x3,x4) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<endl
#define debug_5(x1,x2,x3,x4,x5) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<", "#x5<<": "<<x5<<endl
#ifdef _DEBUG
#define debug(...) CHOOSE((__VA_ARGS__,debug_5,debug_4,debug_3,debug_2,debug_1,~))(__VA_ARGS__)
#else
#define debug(...)
#endif
#define rep(index,num) for(int index=0;index<(int)num;index++)
#define rep1(index,num) for(int index=1;index<=(int)num;index++)
#define brep(index,num) for(int index=(int)num-1;index>=0;index--)
#define brep1(index,num) for(int index=(int)num;index>0;index--)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=(ll)1e+18+1;
int INF=1e+9+1;
int main(){
	ll K;
	scan(K);
	vint now;
	now.push_back(0);
	rep(i,K){
		int flag=0;
		for(int j=0;j<now.size()-1;j++){
			if(now[j]<=now[j+1]&&now[j]<9){
				now[j]++;
				rep(k,j){
					now[k]=max(0,now[j]-(j-k));
				}
				flag=1;
				break;
			}
		}
		if(flag==0){
			if(now.back()==9){
				rep(j,now.size()) now[j]=0;
				now.push_back(1);
			}
			else{
				now.back()++;
				for(int j=0;j<now.size()-1;j++){
					now[j]=max(0,now.back()-((int)now.size()-j-1));
				}
			}
		}
	}
	brep(i,now.size()){
		printf("%d",now[i]);
	}
	kaigyo;
	return 0;
}


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

using namespace std;

int n,m;
vector <int> veca;

int main()
{
    cin >> n >> m;
    for (int i=1;i<=sqrt(m);i++)
    {
        if (m%i==0)
        {
            if ((m/(m/i))>=n)
                veca.push_back(m/i);
            if ((m/i)>=n)
                veca.push_back(i);
        }
    }
    sort(veca.begin(),veca.end());
    cout << veca[veca.size()-1] << endl;
}


Measured memory_bytes: 256