akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define MAX_N 100001
#define INF_INT 2147483647
#define INF_LL 9223372036854775807
#define REP(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
void init(int n);
int find(int n);
void unite(int x,int y);
bool same(int x, int y);
ll bpow(ll,ll,ll);
typedef vector<int> vec;
typedef vector<vec> mat;
mat mul(mat &A,mat &B);
mat pow(mat A,ll n);
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};


bool cmp_P(const P &a,const P &b){
  return a.second < b.second;
}
int main()
{
  ll n,a[200001];
  vector<ll> gusu(0),kisu(0);
  cin >> n;
  REP(i,n)cin >> a[i];
  REP(i,n){
    if(i%2){
      kisu.push_back(a[i]);
    }else
      gusu.push_back(a[i]);
  }
  if(n % 2 == 0){
    reverse(kisu.begin(),kisu.end());
    REP(i,kisu.size()){
      printf("%lld ",kisu[i]);
    }
    REP(i,gusu.size()){
      printf("%lld ",gusu[i]);
    }
    
  }else{
    reverse(gusu.begin(),gusu.end());
    REP(i,gusu.size()){
      printf("%lld ",gusu[i]);
    }
    REP(i,kisu.size()){
      printf("%lld ",kisu[i]);
    }
    
  }
  cout << endl;
  
  
  return 0;
}

int par[MAX_N];
int ranks[MAX_N];

//n要素で初期化
void init(int n){
  REP(i,n){
    par[i] = i;
    ranks[i] = 0;
  }

}

//木の根を求める
int find(int x){
  if(par[x] == x){
    return x;
  }else{
    return par[x] = find(par[x]);
  }
}

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

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

ll bpow(ll a, ll n,ll mod){
  int i = 0;
  ll res=1;
  while(n){
    if(n & 1)
      res = (res*a) % mod;
    a = (a*a) % mod;
    n >>= 1;
  }
  return res;
}
const int MOD = 1000000007;
mat mul(mat &A, mat &B){
  mat C(A.size(),vec(B[0].size()));
    REP(i,A.size())REP(k,B.size())REP(j,B[0].size()){
    C[i][j] = (C[i][j] + A[i][k] * B[k][j]) % MOD;
  }
  return C;
}

mat pow(mat A,ll n)
{
  mat B(A.size(),vec(A.size()));
  REP(i,A.size()){
    B[i][i] = 1;
  }
  while(n > 0){
    if ( n & 1) B = mul(B,A);
    A = mul(A,A);
    n >>= 1;
  }
  return B;
}


Measured memory_bytes: 5484
K=int(input())
N=50
a = list(range(N))
m = K // N
b = K % N
a=list(map(lambda x: x + m, a))
for i in range(b):
    a[i] += N
    for j in range(N):
        if j != i:
            a[j] -= 1
print(N)
print(' '.join(map(str,a)))

Measured memory_bytes: 3064
#define _CRT_NONSTDC_NO_WARNINGS
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <array>
#include <algorithm>
#include <list>
#include <iomanip>
#include <queue>
#include <functional>
#include <cassert>
#include <cmath>
#include <set>
#include <map>
#include <numeric>

#define NL << endl
#define REP(i,n) for(int (i) = 0; i < (n); ++(i))
#define IN(n) cin >> (n)
#define INR(n) for(auto&& e:(n)) cin >> e
#define Yes cout << "Yes" NL
#define No cout << "No" NL

using namespace std;
using ll = long long;
using ull = unsigned long long;
constexpr int INTMAX = numeric_limits<int>::max();
constexpr int INTMIN = numeric_limits<int>::min();
constexpr ll LLMAX = numeric_limits<long long>::max();
constexpr ll LLMIN = numeric_limits<long long>::min();
constexpr int MOD = 1000000007;


int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }

using namespace std;

signed main() {
	int n;
	IN(n);
	int cnt2 = 0;
	int cnt4 = 0;
	int cnt1 = 0;
	for (int i = 0; i < n; i++) {
		int t;
		cin >> t;
		if (t % 4 == 0) cnt4++;
		else if (t % 2 == 0) cnt2++;
		else cnt1++;
	}

	if (cnt2 > 0) cnt1++;
	if (cnt4 + 1 >= cnt1) Yes;

	else No;

	return 0;

}



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

int main(){
  string a,b;
  cin >> a >> b;
  if(a==b) cout << "EQUAL" << endl;
  else if(a.size()>b.size()) cout << "GREATER" << endl;
  else if(a.size()<b.size()) cout << "LESS" << endl;
  
  else{
    int i;
    for(i=0;i<a.size();i++){
      if(a.at(i)!=b.at(i))
        break;
    }
    if(a.at(i)>b.at(i)) cout << "GREATER" << endl;
    else if(a.at(i)<b.at(i)) cout << "LESS" << endl;
  }
}

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

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

    vector<vector<int>> v(N+1, vector<int>(3, 0));
    for (int i = 1; i <= N; ++i) cin >> v[i][0] >> v[i][1] >> v[i][2];
    bool ans = true;
    for (int i = 1; i <= N; ++i) {
        int moveTime = v[i][0] - v[i-1][0];
        int moveXY = v[i][1] - v[i-1][1] + v[i][2] - v[i-1][2];
        if (moveTime < moveXY) ans = false;
        if (moveTime % 2 != 0 && moveXY % 2 == 0) ans = false;
        if (moveTime % 2 == 0 && moveXY % 2 != 0) ans = false;
    }
    if (ans) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 5760
import java.util.*;
class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String hi = sc.next();
        if(hi.compareTo("2019/04/30")>0) {
            System.out.println("TBD");
        }else {
            System.out.println("Heisei");
        }
    }
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
int main(void){
	int n;
	int a,b;
	string aa,bb;
	int i;
	
	
	cin>>n;
	a=0;	b=0;
	for(i=0;i<n;i++){
		cin>>aa>>bb;
		if(aa>bb)	a+=3;
		else if(aa<bb)	b+=3;
		else			a++,b++;
	}
	cout<<a<<" "<<b<<endl;
	return 0;
}


Measured memory_bytes: 3148
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<cstdlib>
using namespace std;
const int N=2e5+5,YL=1e9+7;
inline int MO(const int &x){return x>=YL?x-YL:x;}
inline int in(){int k;cin>>k;return k;}
int a[N],p[N],b[N],mp[N];
inline int low(int x){return x&(-x);}
int n,tot;
inline void insert(int x)
{
	if(x==1){if(a[x]!=1)puts("-1"),exit(0);return p[1]=1,void();}
	if(a[x]==1){for(int i=1;i<x;++i)mp[++p[i]]=i;mp[p[x]=1]=x;return;}
	for(int i=1,cnt=0;i<x;++i)
	{
		if(a[x]>a[mp[i]])++cnt;
		if(cnt==a[x]-1)
		{
			mp[p[x]=i+1]=x;
			for(int j=1;j<x;++j)
				if(p[j]>i)mp[++p[j]]=j;
			return;
		}
	}
	puts("-1");exit(0);
}
int main()
{
	ios::sync_with_stdio(0);cin>>n;
	for(int i=1;i<=n;++i)cin>>a[i],insert(i);
	for(int i=1;i<=n;++i)b[p[i]]=a[i];
	for(int i=1;i<=n;++i)cout<<b[i]<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
						
#define fast_cin() ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define endl '\n'
#define int long long

const int mod = 1e9 + 7;
				
int32_t main() {
	fast_cin();  
	int n;
	cin >> n;
	int sum = 0;
	vector<int> a(n);
	for (int &i : a) cin >> i, sum += i, sum %= mod;
	int ans = 0;
	for (int i = 0; i < n; ++i) {
		sum -= a[i];
		sum += mod, sum %= mod;
		ans += (sum * a[i]) % mod;
		ans %= mod;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4760
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;


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

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		//BufferedReader br = new BufferedReader(new FileReader("sample.txt"));
		while(true){
		String x=br.readLine();
		if(x.equals("-"))break;
		int y=Integer.parseInt(br.readLine());
		int z=0;
		String str;
		StringBuilder stb=new StringBuilder(x);
		
		for(int i=0;i<y;i++){
			z=Integer.parseInt(br.readLine());
			stb=stb.append(stb.substring(0,z));
			stb=stb.delete(0, z);
		}System.out.println(stb);
		
		}
		}
		
		}

Measured memory_bytes: 16904
N = int(input())
A = list(map(int, input().split()))
B = [0]*(N+1)
x = []
 
for n in range(N):
  i = N-n
  BB = B[::i]
  if (sum(BB))%2 == A[i-1]:
    B[i] = 0
  else:
    B[i] = 1
    x.append(str(i))
  
print(len(x))
print(' '.join(x))

Measured memory_bytes: 18764
package main

import (
	"fmt"
)

func main() {
	var n, k, x, y int
	fmt.Scanf("%d", &n)
	fmt.Scanf("%d", &k)
	fmt.Scanf("%d", &x)
	fmt.Scanf("%d", &y)

	var ans int
	for i := 1; i <= n; i++ {
		if i > k {
			ans = ans + y
		} else {
			ans = ans + x
		}
	}

	fmt.Println(ans)
}


Measured memory_bytes: 512
#include "iostream"

using namespace std;

int main() {
  long long n;
  cin >> n;
  int a, b;
  cin >> a >> b;
  if ((n / 6) % 2 == 1) {
    a = -a;
    b = -b;
  }
  if (n % 6 == 0) {
    cout << a << " " << b << endl;
  }
  if (n % 6 == 1) {
    cout << a - b << " " << b << endl;
  }
  if (n % 6 == 2) {
    cout << a - b << " " << a << endl;
  }
  if (n % 6 == 3) {
    cout << -b << " " << a << endl;
  }
  if (n % 6 == 4) {
    cout << -b << " " << a - b << endl;
  }
  if (n % 6 == 5) {
    cout << -a << " " << a - b << endl;
  }
  return 0;
}


Measured memory_bytes: 3120
R,C,K=map(int,input().split())
l=[[0] * C for i in range(R)]
for i in range(K):
  a,b,c=map(int,input().split())
  a-=1
  b-=1
  l[a][b]=c
dp=[0]*C
for i in range(R):
  ndp=[0]*C
  kdp=[0]*4
  kdp[0]=dp[0]
  kdp[1]=l[i][0]+dp[0]
  ndp[0]=kdp[1]
  for j in range(1,C):
    kdp[0]=max(kdp[0],dp[j])
    for k in range(2,-1,-1):
      kdp[k+1]=max(kdp[k+1],kdp[k]+l[i][j])
    ndp[j]=max(kdp)
  dp=ndp
print(dp[C-1])

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

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		long n = sc.nextLong();
		sc.close();

		List<Long> b = new ArrayList<>();
		b.add(0L);
		b.add(26L);
		long base = 26;
		while (true) {
			base *= 26;
			b.add(b.get(b.size() - 1) + base);
			if (b.get(b.size() - 1) > 1000000000000001L) {
				break;
			}
		}

		int a = 0;
		for (int i = b.size() - 1; i >= 0; i--) {
			if (n > b.get(i)) {
				a = i + 1;
				n -= b.get(i);
				break;
			}
		}

		int[] c = new int[a];
		int i = 0;
		n--;
		while (n > 0) {
			c[i] = (int) (n % 26);
			n /= 26;
			i++;
		}

		for (i = a - 1; i >= 0; i--) {
			char d = (char) ('a' + c[i]);
			System.out.print(d);
		}
		System.out.println();
	}
}


Measured memory_bytes: 35856
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int MAXN=100010;
const ll P=998244353,T=1000000000000000000%P;
int n,x,y,eg[3],m[3],hd[3][MAXN],nx[3][MAXN*2],ver[3][MAXN*2],mx[3],sg[3][MAXN],tmp[MAXN];
ll cnt[3][MAXN],ans;
ll qpow (ll a,ll b) {
	ll res=1;
	while (b) {
		if (b&1) {res=(res*a)%P;}
		a=(a*a)%P,b>>=1;
	}
	return res;
}
void add_edge (int t,int x,int y) {
	ver[t][++eg[t]]=y;
	nx[t][eg[t]]=hd[t][x];
	hd[t][x]=eg[t];
	return;
}
int main () {
	scanf("%d",&n);
	for (int i=0;i<=2;i++) {
		scanf("%d",&m[i]);
		for (int j=1;j<=m[i];j++) {
			scanf("%d%d",&x,&y);
			add_edge(i,min(x,y),max(x,y));
		}
		for (int j=n;j>=1;j--) {
			int cur=0;
			for (int k=hd[i][j];k;k=nx[i][k]) {
				tmp[sg[i][ver[i][k]]]++;
				while (tmp[cur]) {cur++;}
			}
			sg[i][j]=cur;
			for (int k=hd[i][j];k;k=nx[i][k]) {tmp[sg[i][ver[i][k]]]--;}
			cnt[i][cur]=(cnt[i][cur]+qpow(T,j))%P,mx[i]=max(mx[i],cur);
		}
	}
	for (int i=0;i<=mx[0];i++) {
		for (int j=0;j<=mx[1];j++) {
			ans=(ans+((cnt[0][i]*cnt[1][j])%P)*cnt[2][i^j])%P;
		}
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 7552
# coding: utf-8

n = int(raw_input())

for i in range(n):
	n1 = int(raw_input())
	n2 = int(raw_input())
	sum = n1 + n2
	strsum = str(sum)
	if len(strsum) > 80:
		print("overflow")
	else:
		print(strsum)


Measured memory_bytes: 4676
#include<stdio.h>
int H;
void maxHeapify(int* ,int);
void buildMaxHeap(int*);
int main(){
  int i,A[500001];
  scanf("%d",&H);
  for(i=1;i<=H;i++) scanf("%d",&A[i]);
  buildMaxHeap(A);
  for(i=1;i<=H;i++) printf(" %d",A[i]);
  printf("\n");
  return 0;
}
void maxHeapify(int* A,int i){
  int l,r,largest;
  int tmp;
  l=i*2;
  r=i*2+1;
  if(l<=H && A[l]>A[i]) largest=l;
  else largest=i;
  if(r<=H && A[r]> A[largest])largest=r;
  if(largest!=i){
    tmp=A[i];
    A[i]=A[largest];
    A[largest]=tmp;
    maxHeapify(A,largest);
  }
}
void buildMaxHeap(int* A){
int i;
for(i=H/2;i>=1;i--) maxHeapify(A,i);
}






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

/* #pragma */
/*
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
*/

/*alias*/
#define F first
#define S second

#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define itn int

/*template*/
template<class T>inline bool amax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>inline bool amin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }

/* func */
int GCD(int a,int b){return b?GCD(b,a%b):a;}
long long GCD(long long a, long long b){return b ? GCD(b, a%b) : a;}
int LCM(int a, int b){return a * b / GCD(a, b);}
long long LCM(long long a, long long b){return a * b / GCD(a, b);}

/*struct*/
struct aaa {
	aaa() {
		cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20);
	};
}aaaaaaa;

/* const */
const int INF = 1001001001;
const long long LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7; //10^9
const double EPS = 1e-9;
const int dx[] = { 1, 1, 0, -1, -1, -1, 0, 1 }, dy[] = { 0, 1, 1, 1, 0, -1, -1, -1 };
//const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
//Counterclockwise from the 6o'clock direction
//Take the x-axis downward and the y-axis right

//#define int long long

//g++ -std=c++14 -Wall --pedantic-errors -o template template.cpp
//g++ -std=c++14 -Wall --pedantic-errors template.cpp
//chcp 65001

/*global*/



signed main()
{
	int r; cin >> r;

	cout << 3*r*r;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<ll>;
using vii = vector<vi>;
using Pll = pair<ll, ll>;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
const int MOD = 1e9+7;
const int INF = 2e9;
template<class T> void print(const T& t){ cout << t << endl; }
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; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int main(){
  bool z = true;
  ll n;
  cin >> n;
  ll t1 = 0;
  ll v = 0;
  ll u = 0;
  rep(i,n){
    ll t;
    cin >> t;
    ll x, y;
    cin >> x >> y;
    ll num = abs(x - v) + abs(y - u);
    ll time = t - t1;
    if(num%2!=time%2)z = false;
    if (num > time)z = false;
    v = x;
    u = y;
    t1 = t;
  }
  if(z)print("Yes");
  else print("No");
}

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

int calc_sat(int D, int N, vector<int> c, vector<vector<int>> s, vector<int> t) {
	vector<int> last(N,-1);
	int sat = 0;  // 満足度
	rep(d,D) {
		last[t[d]] = d;
		sat += s[d][t[d]];
		rep(i,N) {
			sat -= c[i] * (d-last[i]);
		}
	}
	return sat;
}

int main() {
	int D;
	cin >> D;
	const int N = 26; // コンテストの種類
	vector<int> c(N);
	rep(i,N) cin >> c[i];
	vector<vector<int>> s(D, vector<int>(N));
	rep(i,D) rep(j,N) cin >> s[i][j];

	vector<int> t(D); // 開催するコンテスト

	int c_max = 0; // c[i]が最も大きいコンテスト
	rep(i,N) if (c[c_max]<c[i]) c_max = i;

	rep(i,D) {
		t[i] = c_max;
	}

	rep(i,D) {
		printf("%d\n", t[i]+1);
	}

	return 0;
}


Measured memory_bytes: 3776
#include<bits/stdc++.h>
using namespace std;
int main()
{
   long long int n;
     cin>>n;

     set<long long int>p;

        for(long int i=1;i<=sqrt(n);i++)
        {
             if(n % i==0)
             {
             long long int x=n/i;
            long long int sum=i+x-2;
            p.insert(sum);
          }
        }
        auto y=p.begin();
         cout<<(*y);
}


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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))

using namespace std;

using i64 = long long;
using f80 = long double;
using vi32 = vector<int>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << endl; exit(0); }
inline void no() { cout << "No" << endl; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); return a / gcd(a, b) * b; }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { x = max(x, y); }
template <typename T> inline void amin(T &x, T y) { x = min(x, y); }
template <typename T> inline T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }

void solve() {
  int m1, d, m2;
  cin >> m1 >> d >> m2;
  cout << (m1 != m2) << endl;
}


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

typedef pair<int,int> ii;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ll> vll;
#define pb push_back
#define eb emplace_back
#define pob pop_back
#define psf push_front
#define pof pop_front
#define mkp make_pair
#define mkt make_tuple
#define all(x) x.begin(), x.end()

int n;
const int MAXS = 5e5;
int fen[MAXS + 3];
int a[MAXS + 3];
queue<int> elems[MAXS + 3];
vii queries[MAXS + 3];

void update(int pos, int delta){
    while(pos <= n){
        fen[pos] += delta;
        pos += pos & (-pos);
    }
}

int query(int pos){
    int answer = 0;
    while(pos){
        answer += fen[pos];
        pos -= pos & (-pos);
    }
    return answer;
}

int main(){
	ios::sync_with_stdio(false), cin.tie(nullptr);
    cin>>n;
    int q; cin>>q;
    vii arq;
    bool vis[n+2] = {};
    for (int i=1; i<=n; i++){
        cin>>a[i];
        elems[a[i]].push(i);
        if (!vis[a[i]]){
            update(i, 1);
            vis[a[i]] = 1;
        }
    }
    for (int i=0; i<q; i++){
        int l,r; cin>>l>>r;
        queries[l].pb(ii(i, r));
    }
    
    vii ans;
    for (int i=1; i<=n; i++){
        //first answer all, then update:
        for (int j=0; j<queries[i].size(); ++j){
            int r = queries[i][j].second;
            int index = queries[i][j].first;
            int cans = query(r);
            ans.pb(ii(index, cans));
        }
        int el = a[i];
        int pos = elems[el].front();
        elems[el].pop();
        update(pos, -1);
        if (!elems[el].empty()) update(elems[el].front(), 1);
    }
    sort(all(ans));
    for (int i=0; i<q; i++){
        cout<<ans[i].second<<'\n';
    }
    
	return 0;
}
/*
NARCO
*/


Measured memory_bytes: 371268
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        s: chars
    }
    // let mut ch = s[0];
    // for i in 1..s.len() {
    //     if ch != s[i] {
    //         ch = s[i];
    //     }else{

    //         ch = s[i];
    //     }
    // }
    let mut rle:Vec<(char, u64)> = vec![];
    let mut ch:char = 'a';
    let mut len = 0;
    let mut ind = vec![];
    for i in 0..s.len() {
        if ch == 'R' && s[i]=='L' {
            ind.push(i);
        }
        if i==0 {
            ch = s[i];
            len = 1;
            continue;
        }
        if ch==s[i] {
            len+=1;
        }
        if ch!=s[i] {
            rle.push((ch, len));
            ch = s[i];
            len = 1;
        }
        if i==s.len()-1 {
            rle.push((ch, len));
        }
    }
    // println!("{:?}", rle);
    let mut flag = false;
    let mut ans = 0;
    for i in 0..rle.len() {
        // println!("{}", ans);
        let k = if flag {
            flag = false;
            rle[i].1- 1
        }else{
            rle[i].1
        };
        // println!("k: {}", k);
        if k%3 == 0 {
            ans+=(k/3) * 2;
        }
        if k%3 == 1 {
            ans+=(k/3) * 2 + 1;
        }
        if k%3 == 2{
            flag = true;
            if i==rle.len()-1 {
                ans+=(k/3) * 2 + 1;
            }else{
                ans+=(k/3) * 2 + 2;
            }
        }
    }
    println!("{}", ans);
}

Measured memory_bytes: 10764
program cm
  implicit none
  integer::N
  character(10),allocatable,dimension(:)::S
  integer::ans

  integer::i
  read*,N
  allocate(S(N))
  do i=1,N
    read*,S(i)
  end do
  call heapsort(N,S)
  ans=1
  do i=2,N
    if(S(i)/=S(i-1))ans=ans+1
  end do
  print"(i0)",ans
contains
subroutine heapsort(n,array)
  implicit none
!ここの入力は状況に応じて変更すること
  integer,intent(in) :: n
  character(10),intent(inout) :: array(1:n)
  integer::i,k,j,l
  character(10):: t

  l=n/2+1
  k=n
  do while(k /= 1)
     if(l > 1)then
        l=l-1
        t=array(L)
     else
        t=array(k)
        array(k)=array(1)
        k=k-1
        if(k == 1) then
           array(1)=t
           exit
        endif
     endif
     i=l
     j=l+l
     do while(j<=k)
        if(j < k)then
           if(array(j) < array(j+1))j=j+1
        endif
        if (t < array(j))then
           array(i)=array(j)
           i=j
           j=j+j
        else
           j=k+1
        endif
     enddo
     array(i)=t
  enddo
  return
end subroutine heapsort

end program cm

Measured memory_bytes: 4820
// Author: HarshKumar

#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
const ll N = 1e6 + 6, M = 1e9 + 7;
ll f[N];
int main()
{
    ios::sync_with_stdio(false), cin.tie(nullptr);
    ll n, q, s = 0;
    cin >> n;
    vector<ll> a(n);
    for (ll &e : a)
        cin >> e, s += e, f[e]++;
    cin >> q;
    while (q--)
    {
        ll b, c;
        cin >> b >> c;
        s -= f[b] * b;
        f[c] += f[b];
        s += f[b] * c;
        f[b] = 0;
        cout << s << '\n';
    }
}

Measured memory_bytes: 4684
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



#define SIZE 100005

struct Edge{
	Edge(int arg_to,ll arg_dist){
		to = arg_to;
		dist = arg_dist;
	}
	int to;
	ll dist;
};

ll ans;
int V;
vector<Edge> G[SIZE];


ll recursive(int node_id,int parent){

	ll max_path1 = 0;
	ll max_path2 = 0;

	for(int i = 0; i < G[node_id].size(); i++){

		int child = G[node_id][i].to;
		if(child == parent)continue;

		ll tmp_dist = G[node_id][i].dist+recursive(child,node_id);

		if(tmp_dist > max_path1){

			max_path2 = max_path1;
			max_path1 = tmp_dist;

		}else if(tmp_dist > max_path2){

			max_path2 = tmp_dist;
		}
	}
	ans = max(ans,max_path1+max_path2);

	return max_path1;
}


int main(){

	scanf("%d",&V);

	int from,to;
	ll dist;

	for(int loop = 0; loop < V-1; loop++){

		scanf("%d %d %lld",&from,&to,&dist);
		G[from].push_back(Edge(to,dist));
		G[to].push_back(Edge(from,dist));
	}

	ans = 0;
	recursive(0,-1);

	printf("%lld\n",ans);

	return 0;
}




Measured memory_bytes: 18044
import * as fs from "fs";

const input = (fs.readFileSync("/dev/stdin", "utf8") as string).split("\n");
const [n, m] = input[0].split(" ").map((x: string): number => +x);

let result = 0;
if (n >= 2) {
	result += n * (n - 1) / 2;
}
if (m >= 2) {
	result += m * (m - 1) / 2;
}
console.log(result);


Measured memory_bytes: 7500
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<stdbool.h>
#include<math.h>
#define INFINI 100000001


int main(){

char s1[4],s2[4];

scanf("%s",s1);
scanf("\n%s",s2);

int i;
bool isvalide=true;
for(i=0;i<3;i++)
if(s1[i]!=s2[2-i]){
        
        isvalide=false;
           break;}
if(isvalide)printf("YES");
else printf("NO");

}


Measured memory_bytes: 128
def chmin(a, b):
    if a > b:
        a = b
        return a
    else:
        return a

n, k = map(int, input().split())
ls = list(map(int, input().split()))

dp = [10**9] * n
dp[0] = 0


for i in range(1, n):
    for j in range(k):
        if i - j < 1:
            continue
        else:
            dp[i] = chmin(dp[i], dp[i - 1 - j] + abs(ls[i] - ls[i - 1 - j]))

print(dp[n - 1])

Measured memory_bytes: 52448
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>
#include <set>
#include <array>
#include <stdio.h>
#include <string.h>
using ll = long long;
using ull = unsigned long long;
using namespace std;
#define int long long
#define CONTAINS_VEC(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define ARY_REVERSE(v,a) (reverse((v), (v)+(a)))
#define REP(i, n) for (int (i)=0; (i) < (n); (i)++)
#define CONTAINS_MAP(m, a) (m).find((a)) != m.end()
#define CONTAINS_SET(m, a) (m).find((a)) != m.end()
void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; }

signed main()
{
	string s;
	cin >> s;
	REP(i, s.length())
	{
		char ch = s[i];
		if (ch == '9') ch = '1';
		else if (ch == '1') ch = '9';
		cout << ch;
	}
	cout << endl;
}



Measured memory_bytes: 3012
#include <bits/stdc++.h> 
#define lb lower_bound 
#define ub upper_bound 
#define sqr(x) (x)*(x) 
#define lowbit(x) (x)&(-x) 
#define mem(a,x) memset(a,x,sizeof(a));
using namespace std; 
typedef long long ll;
int main(){
	int a[5];
	for(int i=0;i<5;i++) scanf("%d",&a[i]);
	for(int i=0;i<5;i++){
		if(a[i]==0) printf("%d\n",i+1);
	}
}

Measured memory_bytes: 3752
import math
b=[]
c=[]
d=9
e=0
f=0
g=0
for i in range(5):
    a=int(input())
    b.append(a)
    c.append(int(str(a)[-1]))
for u in range(5):
    if c[u] < d and c[u] > 0:
        d=c[u]
        e=u
f=b[e]
b.pop(e)
for u in b:
    g += math.ceil(u/10)*10
print(g+f)

Measured memory_bytes: 3064
#include <stdio.h>
#define cube(X) (X)*(X)*(X)
int main(){
  long long int N,K;

  scanf("%lld %lld",&N,&K);

  if(K%2)
    printf("%lld\n",cube(N/K));
  else
    printf("%lld\n",cube(N/K)+cube(N/K+(N%K>=K/2)));
		     
  return 0;
}


Measured memory_bytes: 128
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<pii> vpii;
typedef vector<vi> vvi;
typedef vector<vb> vvb;
typedef vector<vpii> vvpii;
const int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
const int MOD = 1000000007;
const double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
bool odd(const int &n) { return n & 1; }
bool even(const int &n) { return !odd(n); }
void solve();
main { solve(); return 0; }
// clang-format on

void solve() {
  int n;
  cin >> n;
  map<string, bool> t;
  rep(i, n) {
    string s;
    cin >> s;
    t[s] = true;
  }
  int m;
  cin >> m;
  bool d = false;
  rep(i, m) {
    string s;
    cin >> s;
    if (t.count(s)) {
      d ^= 1;
      cout << (d ? "Opened" : "Closed") << " by " << s << endl;
    } else {
      cout << "Unknown " << s << endl;
    }
  }
}

Measured memory_bytes: 3252
N,M = input().split()
N = int(N) 
all_foods_bags = [input().split() for i in range(N)] 


for i, foods_bags in enumerate(all_foods_bags):
    foods_bags.pop(0)
    all_foods_bags[i] = foods_bags

 
for i, foods_bags in enumerate(all_foods_bags):
    if i == 0:
        original_food_set = set(foods_bags)
    
    else:
        original_food_set = original_food_set & set(foods_bags)

print(len(original_food_set))

Measured memory_bytes: 3060
import bisect
import copy
import heapq
import sys
import itertools
import math
import queue
from functools import lru_cache
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
mod = 10 ** 9 + 7 

def read_values(): return map(int, input().split())
def read_index(): return map(lambda x: int(x) - 1, input().split())
def read_list(): return list(read_values())
def read_lists(N): return [read_list() for n in range(N)]


def main():
    N = int(input())
    A = read_list()
    A.sort()

    F = [True] * (A[-1] + 1)
    for i in range(N - 1):
        if A[i] == A[i + 1]:
            F[A[i]] = False

    res = 0
    for a in A:
        if F[a]:
            res += 1
        for b in range(a, len(F), a):
            F[b] = False

    print(res)


if __name__ == "__main__":
    main()

Measured memory_bytes: 34572
#include <bits/stdc++.h>
using namespace std;
void run_case(){
    int n;
    cin>>n;
    vector<int> a(n);
    for(int i = 0; i< n; i++) cin>>a[i];
    int ans = 0;
    for(int i = 0; i< n; i++){
        for(int j = i+1; j< n; j++){
            for(int k = j+1; k< n; k++){
                int chk = (a[i] == a[j]) + (a[i] == a[k]) + (a[j] == a[k]);
                int big = max({a[i], a[j], a[k]});
                if(chk == 0 && a[k] + a[i] + a[j] - big > big ) {
                    ans++;
                }
            }
        }
    }
    cout<<ans<<"\n";
}
int main() {
    ios::sync_with_stdio(false), cin.tie(0);
    if (fopen("input.in", "r")) 
        freopen("input.in", "r", stdin), freopen("output.out", "w", stdout);
    int t;
    t = 1;
    while(t--){
        run_case();
    }
}


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

int main(){
    int N, ai, i;
    int arr[8];
    for (i=0; i<8; i++) {
        arr[i] = 0;
    }

    int cnt_clr = 0, cnt_over3200 = 0; 
    
    cin >> N;
    for (i=0; i<N; i++) {
        cin >> ai;
        if (ai < 400) arr[0]++;
        else if (ai < 800) arr[1]++;
        else if (ai < 1200) arr[2]++;
        else if (ai < 1600) arr[3]++;
        else if (ai < 2000) arr[4]++;
        else if (ai < 2400) arr[5]++;
        else if (ai < 2800) arr[6]++;
        else if (ai < 3200) arr[7]++;
        else cnt_over3200++;
    }

    for (i=0; i<8; i++) {
        if (arr[i] > 0) cnt_clr++;
    }

    cout << max(1, cnt_clr) << " " << cnt_clr + cnt_over3200 << endl;

    return 0;
}


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

// @@ !! LIM()

int main(/* int argc, char *argv[] */) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  string s; cin >> s;
  ll k = s.at(s.size() - 1) - '0';
  if (k == 3) {
    cout << "bon";
  }else if (k == 0 || k == 1 || k == 6 || k == 8) {
    cout << "pon";
  }else {
    cout << "hon";
  }
  cout << endl;

  return 0;
}



Measured memory_bytes: 3660
import java.io.File;
import java.io.IOException;
import java.util.*;
 
public class Main {
 
	public static void main(String[] args) throws IOException {
		//File file = new File("input.txt");
		//Scanner in = new Scanner(file);
		
		Scanner in = new Scanner(System.in);
		
		int H = in.nextInt();
		int W = in.nextInt();
		int D = in.nextInt();
		
		int[][] A = new int[H*W+1][2];
		for(int i = 0; i < H; i++) {
			for(int j = 0; j < W; j++) {
				int num = in.nextInt();
				int[] xy = {i + 1, j + 1};
				A[num] = xy;
			}
		}
		
		/*
		for(int i = 1; i <= H * W; i++) {
			int[] a = A[i];
			System.out.println(a[0] + " " + a[1]);
		}
		*/
		
		int[] distSum = new int[H*W+1];
		for(int i = D + 1; i <= H * W; i++) {
			int[] n = A[i];
			int[] p = A[i-D];
			distSum[i] = distSum[i-D] + Math.abs(n[0] - p[0]) + Math.abs(n[1] - p[1]);
		}
		
		/*
		for(int i = D + 1; i <= H * W; i++) {
			System.out.println(i + ":" + distSum[i]);
		}
		*/
		
		
		int Q = in.nextInt();
		for(int i = 0; i < Q; i++) {
			int L = in.nextInt();
			int R = in.nextInt();
			if(L <= D) System.out.println(distSum[R]);
			else System.out.println(distSum[R] - distSum[L]);
		}
	}
}

Measured memory_bytes: 106060
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string s, n;
  cin >> s >> n;
  int c=0;
  for (int i = 0; i < s.size(); i++) {
    if (s.at(i) != n.at(i)) {
      c++;
    }
  }
  cout << c << endl;
}

Measured memory_bytes: 3828
#include<string>
#include<cctype>
#include<iostream>
#include<cstdio>
#include<cmath>
#include<queue>
using namespace std;
#define inf 0x3f3f3f3f
const int maxn = 36 + 8;
/*template<class T>
void swap(T &a,T &b)
{
    T c = a;
    a = b;
    b = c;
}
*/
struct node{
    char c;
    int n;
};

node x[maxn],y[maxn],z[maxn];

int n,minj;
void bubbleSort(node y[])
{
    for(int i = 0; i < n; i++){
        for(int j = n-1; j >= i+1; --j){
            if(y[j].n < y[j-1].n){
                swap(y[j],y[j-1]);
            }
        }
    }
    return;
}

void  selectSort(node z[])
{
    for(int i = 0; i < n-1; ++i){
        minj = i;
        for(int j = i; j < n; ++j){
            if(z[j].n < z[minj].n){
                minj = j;
            }
        }
        swap(z[minj],z[i]);
    }
    return;
}

void see(node m[])
{
    for(int i = 0; i < n; ++i){
        printf("%s%c%d",i == 0 ? "" : " ",m[i].c,m[i].n);
    }
    printf("\n");
}

bool judge(node a[],node b[])
{
    for(int i = 0; i < n ;++i){
        if(a[i].c != b[i].c ){
            return false;
        }
    }
    return true;
}
int main()
{
    scanf("%d",&n);
    for(int i = 0; i < n; ++i){
        char ch = (char)getchar();
        scanf("%c%d",&x[i].c, &x[i].n);
        y[i].c = z[i].c = x[i].c;
        y[i].n = z[i].n = x[i].n;
    }
    bubbleSort(y);
    see(y);
    cout << "Stable" << endl;
    selectSort(z);
    see(z);
    printf("%s\n",judge(y,z) == 0 ? "Not stable" : "Stable");
    return 0;
}

Measured memory_bytes: 3224
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
using namespace std;
#define REP(i, n) for(int i=0; i<(int)(n); i++) 
typedef long long int lli;
const int inf = 1e9;

void dfs(int pos, vector<int> &idx, vector<bool> &used, vector<vector<int> > &adj){
	if(used[pos]) return;
	used[pos] = true;
	idx.push_back(pos);
	REP(i, adj[pos].size()){
		dfs(adj[pos][i], idx, used, adj);
	}
}

int solve(vector<int> &p, vector<vector<int> > &adj){
	int ret = 0;
	vector<bool> used(p.size(), false);
	REP(i, p.size()){
		if(used[i]) continue;
		vector<int> search;
		dfs(i, search, used, adj);
		set<int> a;
		REP(j, search.size()){
			a.insert(p[search[j]]);
		}
		REP(j, search.size()){
			if(a.find(search[j]) != a.end()){
				ret++;
			}
		}
	}
	return ret;
}

int main(){
	int n,m;
	cin >> n >> m;
	vector<int> p(n+1, inf);
	REP(i, n) cin >> p[i+1];
	vector<vector<int> > adj(n+1);
	REP(i, m){
		int x,y;
		cin >> x >> y;
		adj[x].push_back(y);
		adj[y].push_back(x);
	}
	cout << solve(p, adj) << endl;
	return 0;
}

Measured memory_bytes: 15224
#gcdは3.4.3だとfractionsにある
from fractions import gcd
import math

from math import factorial as f

from math import ceil,floor,sqrt

from sys import exit

from copy import deepcopy
import numpy as np

import bisect
import re
import heapq


from copy import deepcopy
import itertools

ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))






def main():
    n = ii()
    s = input()
    n2 = n//2

    if n%2:
        print('No')
    else:
        for i in range(n2):
            if not s[i] == s[i+n2]:
                print('No')
                exit()
        print('Yes')




main()


Measured memory_bytes: 22908
// https://atcoder.jp/contests/abc083/tasks/abc083_b

#include <bits/stdc++.h>
using namespace std;

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

    int ans = 0;
    for (int x = 1; x <= n; x++)
    {
        int s = 0;
        int y = x;
        while (y > 0)
        {
            s += y % 10;
            y /= 10;
        }
        if (a <= s & s <= b)
        {
            ans += x;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3592
#pypyは内包表記使わない
def main():
    import sys
    #input = sys.stdin.readline
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations
    #from itertools import accumulate, product
    from bisect import bisect_left,bisect_right
    from math import floor, ceil
    #from operator import itemgetter

    #mod = 1000000007

    N = int(input())
    K = int(input())
    x = list(map(int, input().split()))
    res = 0
    for i in x:
        res += min(i, abs(K-i)) * 2
    print(res)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3444
#include <climits>
#include <iostream>
#include <queue>
#include <utility>
#include <vector>
using namespace std;

int main() {
	int N, u, v;
	cin >> N;
	vector<vector<pair<int, long>>> a(N);
	for (int i = 0; i < N - 1; i++) {
		long w;
		cin >> u >> v >> w;
		a[u - 1].emplace_back(v - 1, w);
		a[v - 1].emplace_back(u - 1, w);
	}
	priority_queue<pair<int, long>> b;
	b.emplace(0, 0);
	vector<bool> c(N);
	vector<long> d(N, LONG_MAX);
	d[0] = 0;
	while (!b.empty()) {
		pair<int, long> e = b.top();
		b.pop();
		c[e.first] = true;
		for (pair<int, long>& i : a[e.first]) {
			if (c[i.first]) continue;
			if (d[e.first] + i.second < d[i.first]) {
				d[i.first] = d[e.first] + i.second;
				b.emplace(i.first, d[i.first]);
			}
		}
	}
	for (long& i : d) cout << i % 2 << endl;
}

Measured memory_bytes: 8704
using System;

namespace ITP1_10_A{
    class sample{
        static void Main(string[] args){
            var coordinate = Console.ReadLine().Split(' ');
            double column = double.Parse(coordinate[3]) - double.Parse(coordinate[1]);
            double row = double.Parse(coordinate[2]) - double.Parse(coordinate[0]);
            double distance = column*column + row*row;
            Console.WriteLine(Math.Sqrt(distance));
        }
    }
}


Measured memory_bytes: 15968
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <math.h>
#include <cmath>
#include <ctime>
#include <stdlib.h>

using namespace std;

#define int long long
#define endl "\n"
#define all(v)  v.begin(),v.end()
#define fir first
#define sec second
#define m_p make_pair
#define m_t make_tuple
#define rep(i,n)  for(int i=0; i<(int) (n); i++)
typedef pair<int, int> P;

const double pai = 3.1415926535897;
const int mod = 1000000007;
const int INF = 1000000021;
const int MAX = 510000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];


//x未満の要素数を返す二分探索関数
int b_s(vector<int>& vec, int xx) {
	return lower_bound(all(vec), xx) - vec.begin();
}
template<typename T>void vecout(vector<T>& vec) { for (T t : vec) cout << t << " "; cout << endl; }
template<typename TT>void vecin(vector<TT>& vec) {
	for (int i = 0; i < vec.size(); i++) {
		cin >> vec[i];
	}
}
template<class tt> struct counter {
	map<tt, int>mp;
	bool add(tt t, int xx) {
		if (!mp.count(t)) {
			mp[t] = xx;
			return true;
		}
		mp[t] += xx;
		if (!mp[t]) {
			mp.erase(t);
		}
		return false;
	}

};

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; 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;
	}
}

//n個を1個以上のx組のグループに分ける重複組み合わせはcom(n-1,x-1)
long long COM(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;
}
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
long long modpow(int a, int n) {
	int res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}

bool chmax(int& xx, int yy) {
	if (xx < yy) {
		xx = yy;
		return true;
	}
	return false;
}
bool chmin(int& xx, int yy) {
	if (xx > yy) {
		xx = yy;
		return true;
	}
	return false;
}
int gcd(int xx, int yy) {
	int p = xx;
	int q = yy;
	if (q > p)swap(p, q);
	while (p % q != 0) {
		p %= q;
		swap(p, q);
	}
	return q;
}
int lcm(int xx, int yy) {
	return xx * yy / gcd(xx, yy);
}
bool prime(int xx) {
	if (xx <= 1) {
		return 0;
	}
	for (int i = 2; i * i <= xx; i++) {
		if (xx % i == 0) {
			return 0;
		}
	}
	return 1;
}



signed main() {
	int a, b, c;
	cin >> a >> b >> c;
	if (sqrtl(a * b) < (c - a - b) / 2.0) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

Measured memory_bytes: 3668
icase=0
if icase==0:
    n,l=map(int,input().split())
    s=n*(l-1)+n*(n+1)//2
    smin=200*200
    for i in range(1,n+1):
        ss=abs((l+i-1))
#        print(ss)
        if smin>ss:
            smin=ss
            sv=s-(l+i-1)
#            print("sv",sv,"ss",ss)
    print(sv)
    

Measured memory_bytes: 3060
#include "bits/stdc++.h"
using namespace std;

const int MOD = 1000000007;

int g[15];
int dp[1 << 15];

int main() {
        int n, m;
        scanf("%d%d", &n, &m);
        for (int i = 0; i < m; i ++) {
                int a, b;
                scanf("%d%d", &a, &b);
                a --, b --;
                g[a] |= (1 << b);
        }               
        dp[0] = 1;
        for (int ST = 1; ST < (1 << n); ST ++) {
                int U = ((1 << n) - 1) ^ ST;
                for (int S = ST - 1; S >= 0; S --) {
                        S &= ST;
                        int T = ST ^ S;
                        if ((T & 3) == 3) continue;
                        long long res = 1;
                        for (int i = 0; i < n; i ++) {
                                if (T & (1 << i)) (res *= 1 << __builtin_popcount(g[i] & U)) %= MOD;
                                if (U & (1 << i)) (res *= (1 << __builtin_popcount(g[i] & T)) - 1) %= MOD;
                        }
                        (dp[ST] += res * dp[S] % MOD) %= MOD;
                }
        }
        printf("%d\n", dp[(1 << n) - 1]);
        return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i,m,n) for(int i=m;i<n;i++)
#define co(n) cout<<n<<endl
#define all(n) (n).begin(),(n).end()
#define pb(n,m) n.push_back(m)
#define pi(n,m) n.insert(n.begin(),m);
#define ee(n) n.erase(n.end()-1)
#define eb(n) n.erase(n.begin())
#define check(n) reverse(all(n));rep(z,0,n.size())cout<<n[z];co("");reverse(all(n));
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

int main(){
  ll a,b,n,m;
  cin>>a>>b>>n;
  m=min(b-1,n);
  m=a*m/b-m/b*a;
  co(m);
  return 0;
}

Measured memory_bytes: 3600
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		char[] arr = sc.next().toCharArray();
		ArrayDeque<Character> deq = new ArrayDeque<>();
		int count = 0;
		for (char c : arr) {
		    if (deq.size() == 0 || c == deq.peek()) {
		        deq.push(c);
		    } else {
		        deq.pop();
		        count++;
		    }
		}
		System.out.println(count * 2);
   }
}


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

beated_monsters = 0
for i in range(N):
    if A[i] >= B[i]:
        beated_monsters += B[i]
        continue
    else:
        beated_monsters += A[i]
        left = B[i] - A[i]
        if A[i+1] < left:
            beated_monsters += A[i+1]
            A[i+1] = 0
        else:
            beated_monsters += left
            A[i+1] -= left

print(beated_monsters)

Measured memory_bytes: 81892