akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        UnionFind uf = new UnionFind(n);
        
        int[][] xy = new int[m][2];
        for (int i = 0; i < m; i++) {
            int x = sc.nextInt() - 1;
            int y = sc.nextInt() - 1;
            xy[i][0] = x;
            xy[i][1] = y;
        }
        
        long[] size = new long[n];
        Arrays.fill(size, 1);
        long[] answer = new long[m];
        answer[m - 1] = (long)n * (n - 1) / 2;
        
        for (int i = m - 1; i > 0 ; i--) {
            int x = xy[i][0];
            int y = xy[i][1];
            if (uf.same(x, y)) {
                answer[i - 1] = answer[i];
                continue;
            }
            
            int rx = uf.root(x);
            int ry = uf.root(y);
            answer[i - 1] = answer[i] - size[rx] * size[ry];
            long sizex = size[rx];
            long sizey = size[ry];
            size[rx] += sizey;
            size[ry] += sizex;
            uf.unite(x, y);
        }
        
        for (long a : answer) {
            System.out.println(a);
        }
    }
    
    public static class UnionFind {
        int[] par;
        int connectedComponent;
    
        UnionFind(int n) {
            par = new int[n];
            connectedComponent = n;
            for (int i = 0; i < n; i++) {
                par[i] = i;
            }
        }
    
        int root(int x) {
            if (par[x] == x) return x;
            return par[x] = root(par[x]);
            // 1-2-4の場合、4の親=2を4の根=1に繋ぎ変えた上で親を返す
            // ↑根まで辿る深さを減らす為
            // return a = b;とは、aにbを代入し、aを返すという意味
        }
    
        void unite(int x, int y) {
            int rx = root(x);
            int ry = root(y);
            if (rx != ry) {
                par[ry] = rx;
                connectedComponent--;
            }
        }
    
        boolean same(int x, int y) {
            int rx = root(x);
            int ry = root(y);
            return rx == ry;
        }
        
        void printPar() {
            System.out.println(Arrays.toString(par));
        }
    }
}

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

int main(){
    int n;cin>>n;
    double ans=0;
    vector<int> v;
    for(int i=0;i<n;i++){
        v.push_back(i);
    }
    vector<pair<double,double>> xy(n);
    for(int i=0;i<n;i++){
        double x,y;cin>>x>>y;
        xy[i]={x,y};
    }
    double count=0;
    do{
        for(int i=0;i<n-1;i++){
            double xx=(xy[v[i]].first-xy[v[i+1]].first);
            double yy=(xy[v[i]].second-xy[v[i+1]].second);
            ans+=sqrt(xx*xx+yy*yy);
        }
        count++;
    }while(next_permutation(v.begin(),v.end()));
    cout<<setprecision(10)<<ans/count<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)
#define repa(i,n) for (auto& i: n)

template<class T> inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}

#ifdef DEBUG
template <class T, class N> void verr(const T& a, const N& n) { rep(i, n) cerr << a[i] << " "; cerr << "\n" << flush; }
ll dbgt = 1; void err() { cerr << "passed " << dbgt++ << "\n" << flush; }
template<class H, class... T> void err(H&& h,T&&... t){ cerr<< h << (sizeof...(t)?" ":"\n") << flush; if(sizeof...(t)>0) err(forward<T>(t)...); }
#endif

const ll INF = 4e18;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
//--------------------------------------------------------------------------------//

int main() {
    init();
    ll N;
    cin >> N;
    vl A(N);
    rep(i, N) cin >> A[i];
    ll K = *max_element(all(A));

    vl C(K + 1);
    rep(i, N) C[A[i]]++;
    rep(i, K) C[i + 1] += C[i];
    
    vl ans(N);
    repr(i, N) ans[--C[A[i]]] = A[i];

    rep(i, N) cout << ans[i] << (i == N - 1 ? '\n' : ' ');
}


Measured memory_bytes: 34108
import java.io.*;
import java.util.*;
import java.math.*;
import java.util.regex.Pattern;

class Main {
    public static void main(String args[])
    {
     int x,y;long tem,sum=0;
     Scanner sc=new Scanner(System.in);
     x=sc.nextInt(); y=sc.nextInt();
     if((x+y)==2)
     {
      sum=300000+300000+400000;
     }
     else if((x+y)==3)
     {
         sum=200000+300000;
     }
     else if(x==2 && y==2)
     {
         sum=200000+200000;
     }
     else if((x==2 && y==3) ||(x==3 && y==2))
     {
         sum=200000+100000;
     }
     else if(x==3 && y==3)
     {
         sum=100000+100000;
     }
     else if((x==3 && y==1) || (x==1 && y==3))
     {
         sum=100000+300000;
     }
     else if((x==1 && y>3)||(x>3 && y==1))
     {
         sum=300000;
     }
     else if((x==2 && y>3)||(x>3 && y==2))
             {
                 sum=200000;
             }
     else if((x==3 && y>3) || (x>3 && y==3))
     {
         sum=100000;
     }
     else if(x>3 && y>3)
     {
         sum=0;
     }
     System.out.println(sum);
    }
}



Measured memory_bytes: 23636
#include <iostream>
#include <sstream>
#include <stdio.h>
//#define _USE_MATH_DEFINES
#include <math.h>
#include <set>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <limits>
#include <bitset>
#include <stack>
#include <queue>
#include <ctype.h>

typedef long long int lli;
#define rep(i,s,N) for(int i=s;i<N;i++)
#define MOD 1000000007
#define more(a,b) (((a)>(b))?(a):(b))
#define less(a,b) (((a)<(b))?(a):(b))

using namespace std;


int main(void)
{
	int N; cin >> N;
	vector<lli> A(N), B(N); rep(i, 0, N)cin >> A[i] >> B[i];
	lli ans = 0;
	for (int i = N - 1; i >= 0;i--) {
		if ((ans + A[i]) % B[i] != 0) {
			ans += B[i] - (ans + A[i]) % B[i];
		}
		//cout << ans << endl;
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
using namespace std;

int main()
{
    int a, b;
    cin >> a >> b;
    int x = a+b;
    int y = a-b;
    int z = a*b;
    cout << max(x, max(y, z)) << endl;
}

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

#define int long long
#define For(i, a, b) for (int i = (a); i <= static_cast<int>(b); i++)
#define Forr(i, a, b) for (int i = (a); i >= static_cast<int>(b); i--)
#define rep(i, n) For(i, 0, n - 1)
#define repall(i, arr) for (auto& i : (arr))
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define dump(x) cerr << #x << " = " << (x) << '\n'

template <typename T>
using pq = priority_queue<T>;
template <typename T>
using pqr = priority_queue<T, vector<T>, greater<T>>;
const int INF = INT_MAX / 2;
constexpr int MOD = 1e9 + 7;

template <typename T1, typename T2>
ostream& operator<<(ostream& stream, const pair<T1, T2>& p) {
    return stream << p.first << " " << p.second;
}
template <typename T>
void print(const vector<vector<T>> matrix) {
    repall (vec, matrix)
        print(vec);
}
template <typename T>
void print(const vector<T> vec) {
    unsigned int len = vec.size();
    rep (i, len - 1)
        cout << vec[i] << ' ';
    cout << vec[len - 1] << '\n';
}
template <typename Arg>
void print(const Arg arg) {
    cout << arg << '\n';
}
template <typename Head, typename... Args>
void print(const Head head, const Args... args) {
    cout << head << " ";
    print(args...);
}
template <typename T>
T sum_(vector<T> vec, auto init = 0) {
    return std::accumulate(all(vec), T(init));
}
// -------------------------------------------------------------------

using P = pair<int, int>;

signed main() {
    cin.tie(0), cout.tie(0), ios::sync_with_stdio(false);

    double t, x;

    cin >> t >> x;

    print(t / x);

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
	ll a,b;cin>>a>>b;
	if(a>b){
		for (int i = 0; i < a; ++i)
		{
			cout<<b;
		}
	}
	else
	{
		for (int i = 0; i < b; ++i)
		{
			cout<<a;
		}	
	}
	cout<<"\n";
}    

Measured memory_bytes: 256
n, m = list(map(int, input().split()))
# a = list(map(int, input().split()))
# abc = [int(input()) for i in range(5)]
to = [[] for i in range(n)]
for i in range(m):
    a, b = map(int, input().split())
    to[a-1].append(b-1)
    to[b-1].append(a-1)
# print(to)
for i in range(len(to[0])):
    if n-1 in to[to[0][i]]:
        print("POSSIBLE")
        exit()
print("IMPOSSIBLE")


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

int main()
{
	string s;
	int q;

	cin >> s>>q;

	
		string c;

	while(cin >> c) {
		if (c == "print") {
			int a, b;

			cin >> a >> b;
			for (int i = 0; i < b - a + 1; i++)
				cout << s[a + i];
			cout << endl;
		}
		else if (c == "reverse") {
			int a, b;

			cin >> a >> b;
			for (int i = 0; i < (b - a + 1) / 2; i++) {
				char temp = s[a + i];

				s[a + i] = s[b - i];
				s[b - i] = temp;
			}
		}
		else if (c == "replace") {
			int a, b;
			string p;
			
			cin >> a >> b;
			cin >> p;
			for (int i = 0; i < b - a + 1; i++) {
				s[a + i] = p[i];
			}
		}
	}

	return 0;
}


Measured memory_bytes: 1212
#include<bits/stdc++.h>
using namespace std;
int a,b,ans;
int main()
{
	scanf("%d%d",&a,&b);
	int s=1;
	while(s<b)
	{
		s+=a-1;
		ans++;
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
using namespace std;

typedef long long ll;
ll n,m,ans=1ll<<60;

ll abs_(ll x){
	return x>0?x:-x;
}

void work(ll x,ll y){
	for(ll i=1;i<x;i++){
		ll s1=i*y;
		ll lx=x-i,ly=y;
		if(lx%2==0||ly%2==0)ans=min(ans,abs_(s1-lx*ly/2));
		else{
			ll s2=lx/2*ly,s3=(lx/2+1)*ly;
			ans=min(ans,max(s1,max(s2,s3))-min(s1,min(s2,s3)));
			s2=ly/2*lx,s3=(ly/2+1)*lx;
			ans=min(ans,max(s1,max(s2,s3))-min(s1,min(s2,s3)));
		}
	}
}

int main(){
	scanf("%lld %lld",&n,&m);
	work(n,m);
	work(m,n);
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const long long INF= 1e+18+1;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll> >vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
const ll MOD=1000000007LL;
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int main(){
  ll n;cin>>n;
  string a,b,c;cin>>a>>b>>c;
  ll ans=n*2;
  rep(i,n){
    if(a[i]==b[i]&&b[i]==c[i])ans-=2;
    else if(a[i]==b[i]||b[i]==c[i]||a[i]==c[i])ans--;
  }
  cout<<ans<<endl;
}
      

Measured memory_bytes: 256
#include <iostream> // C++の入出力
#include <stdio.h> // C の入出力
#include <algorithm> // sort などのアルゴリズム
#include <string.h> // C の文字列用
#include <ctype.h> // C の文字種用
#include <string> // C++の文字列
using namespace std;
int main(void){
    while(1){
        int n,p,step=0;
        cin>>n>>p;
        if(n==0&&p==0)break;
        int data[n];
        for(int i=0;i<n;i++)data[i]=0;
        int box=p;
        for(int i=0;;i++){
            if(i==0){
                data[0]+=1;
                box-=1;
                continue;
            }
            if(box>0){
                data[i%n]++;
                box--;
            }else if(box==0){
                box+=data[i%n];
                data[i%n]=0;
            }
            if(box==0&&data[i%n]==p){
                step=i%n;
                break;
            }
        }
        cout<<step<<endl;
    }
    return 0;
}

Measured memory_bytes: 1160
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <fstream>
#include <vector>
#include <utility>
#include <cstring>
using namespace std;
typedef long long ll;

int W,D,R[21],C[21];

int main() {
	while(true) {
		cin >> W >> D;
		if (W == 0) break;
		memset(R, 0, sizeof(R));
		memset(C, 0, sizeof(C));
		int h;
		for (int i = 0; i < W; ++i) {
			cin >> h;
			C[h]++;
		}
		for (int i = 0; i < D; ++i) {
			cin >> h;
			R[h]++;
		}
		int ans = 0;
		for (int i = 1; i <= 20; ++i) {
			ans += i * (C[i] + R[i] - min(C[i], R[i]));
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
 
using namespace std;
 
#define MAX 20

struct P{
  double x, y;
}; 

int N;
P h, d, c[MAX];
 
double dist(P a, P b){
  return sqrt(pow(a.x-b.x,2) + pow(a.y-b.y,2));
}

bool used[MAX];
bool rec(int now, double sum, int dep){
  if(dep == N){
    return true;
  }

  for(int i = 0 ; i < N ; i++){
    if(!used[i]){
      if(sum + dist(c[now],c[i]) >= dist(d,c[i])){
        return false;
      }
    }
  }

  for(int i = 0 ; i < N ; i++){
    if(!used[i]){
      used[i] = true;
      if(rec(i, sum+dist(c[now],c[i]),dep+1)){
        return true;
      }
      used[i] = false;
    }
  }
  return false;
}

void solve(){
  for(int i = 0 ; i < N ; i++){
    memset(used, false, sizeof(used));
    if(rec(i, dist(h,c[i]), 0)){
      puts("YES");
      return;
    }
  }
  puts("NO");
}
 
int main(){
  while(scanf("%d%lf%lf%lf%lf" ,&N, &h.x, &h.y, &d.x, &d.y)
        , (N + h.x + h.y + d.x + d.y)){
    for(int i = 0 ; i < N ; i++){
      scanf("%lf%lf" ,&c[i].x, &c[i].y);
    }
    solve();
  }
  
  return 0;
}

Measured memory_bytes: 1204
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b)-1);i>=((int)(a));i--)
typedef long long int lli;
typedef pair<int, int> mp;
#define fir first
#define sec second
#define IINF INT_MAX
#define LINF LLONG_MAX
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#define pque(type) priority_queue<type,vector<type>,greater<type> >
#define memst(a,b) memset(a,b,sizeof(a))

int main(void){
	int n, l;
	cin >> n >> l;
	vector<string> s(n);
	rep(i, n)cin >> s[i];
	
	sort(s.begin(),s.end());
	
	rep(i, n) cout << s[i];
	
	cout << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>

#define MAX 1000

int main() {

	char x[MAX];
	int i, sum;

	while (1) {
		scanf("%s", x);
		if (x[0] == '0') break;

		sum = 0;

		for (i = 0; i < strlen(x); i++) {
			sum = sum + x[i] - 48;
		}

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

	}
	return 0;

}


Measured memory_bytes: 2100
#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<utility>
#include<map>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;


long long int gcd(long long int a, long long int b)
{
	if (b == 0)
		return a;
	return gcd(b, a % b);
}



map<long long int, long long int>m3[300001];
int main() {

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

	long long int n, m, k;
	cin >> n >> m >> k;
	map<long long int, long long int>m1;
	map<long long int , long long int >m2;

	long long int maxia = INT_MIN;
	long long int maxib = INT_MIN;
	while (k--)
	{
		long long int a, b;
		cin >> a >> b;
		m1[a]++;
		m2[b]++;
		m3[a][b] = 1;
		if (maxia < m1[a])
			maxia = m1[a];
		if (maxib < m2[b])
			maxib = m2[b];

	}

	vector<long long int>left;
	vector<long long int>right;
	for (auto i = m1.begin(); i != m1.end(); i++)
	{
		if (i->second == maxia)
		{
			left.push_back(i->first);
		}
	}

	for (auto i = m2.begin(); i != m2.end(); i++)
	{
		if (i->second == maxib)
		{
			right.push_back(i->first);
		}
	}

	long long int ans = 0;
	long long int c1 = 0;
	for (long long int i = 0; i < left.size(); i++)
	{
		for (long long int j = 0; j < right.size(); j++)
		{	c1++;
			ans = max(ans, maxia + maxib - m3[left[i]][right[j]]);
			if (c1 > n)
				break;
		}
		if (c1 > n)
			break;
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 96952
#include<stdio.h>

int
main(int argc, char *argv[])
{
        int a, b;
        char buf[30];

        while (fgets(buf, 30, stdin)) {
                sscanf(buf, "%d %d", &a, &b);
                a += b;
                b = 0;
                do {
                        a /= 10;
                        b++;
                } while (a >= 1);
                printf("%d\n", b);
        }
        return 0;
}

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

using namespace std;


typedef long long ll;
ll mod=1e9+0LL;
ll MOD=1e18+0LL;
double pi=acos(-1);


int main()
{
    int cs=1;
    //scanf("%d",&cs);
    while(cs--)
    {
        ll n,m;
        cin>>n>>m;
        cout<<(ll)(n*m);
    }
}


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

Alist = [A[i]-(i+1) for i in range(N)]
Alist.sort()
x = N//2
b = Alist[x]
ans = 0
for i in range(N) :
    ans += abs(Alist[i]-b)
    
print(ans)

Measured memory_bytes: 26708
#include <iostream>

using namespace std;

int memo[5001];
void init(){
  fill(memo, memo+5001, 1<<20);
  for(int i = 0; i*200 <= 5000 ; i++){
    for(int j = 0; j*300 <= 5000 ; j++){
      if(i*200+j*300 > 5000)break;
      for(int k = 0; k*500 <= 5000 ; k++){
	if(i*200+j*300+k*500 > 5000)break;
	int sum = i*200+j*300+k*500;
	int m = (i/5)*1520+(i%5)*380 + (j/4)*1870+(j%4)*550 + (k/3)*2244 + (k%3)*850;
	memo[sum] = min(memo[sum], m);
      }
    }
  }
}
int main(){
  int n;
  init();
  while(cin >> n, n){
    cout << memo[n] << endl;
  }
  return 0;
}

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

XOR = 0
for el in A[2:]:
    XOR ^= el

if (A[0] + A[1] - XOR) % 2 != 0:
    print(-1)
    exit(0)

AND = (A[0] + A[1] - XOR) // 2
if XOR & AND != 0:
    print(-1)
    exit(0)

ok = False
u = 0
v = 0

bits = list()
for bit in range(60, -1, -1):
    if XOR >> bit & 1 == 0 and AND >> bit & 1 == 1:
        u |= 1 << bit
        v |= 1 << bit
    elif XOR >> bit & 1 == 1 and AND >> bit & 1 == 0:
        bits.append(bit)

for bit in bits:
    if (u | (1 << bit)) <= A[0]:
        u |= 1 << bit

if u > A[0] or u == 0:
    print(-1)
    exit(0)
print(A[0] - u)

Measured memory_bytes: 81640
"use strict"

function main(input) {
  const N = ~~input
  const cake = 4
  const donut = 7
  // let ans;

  for (let i = 0; i <= Math.ceil(N / cake); i++) {
    for (let j = 0; j <= Math.ceil(N / donut); j++) {
      if (cake * i + donut * j === N) {
        console.log("Yes")
        return false
      }
    }
  }

  console.log("No")
}

main(require("fs").readFileSync("/dev/stdin", "utf8"))


Measured memory_bytes: 7372
import java.util.Scanner;
import java.util.Arrays;
import java.util.ArrayList;

class Main{
	public static void main(String[] args){
      	Scanner sc = new Scanner(System.in);
      	int n = sc.nextInt();
      	int a = sc.nextInt();
      	if(n%500 <= a)
      		System.out.println("Yes");
      	else
          System.out.println("No");
	}
}

Measured memory_bytes: 21716
input_data = gets.chomp.split(" ")
n = input_data[0].to_i
a = input_data[1].to_i
b = input_data[2].to_i
c = input_data[3].to_i
x = input_data[4].to_i

while n != 0 do 
    count = 0
    g = gets.chomp.split(" ")
    g.each_with_index do |v, i|
        v = v.to_i
        while v != x && count <= 10000
            count += 1
            x = (a * x + b) % c
        end
        #最後の数字でなければ実行する。　99がインデックス１と99のインデックス２
        if i != g.length - 1
            count += 1
            x = (a * x + b) % c
        end
        break if count > 10000
    end
    
    if count > 10000
        p -1
    else
        p count
    end
    input_data = gets.chomp.split(" ")
    n = input_data[0].to_i
    a = input_data[1].to_i
    b = input_data[2].to_i
    c = input_data[3].to_i
    x = input_data[4].to_i
end


Measured memory_bytes: 6916
#include <bits/stdc++.h>
using namespace std;
  #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  #define int long long
  #define endl "\n"
  #define all(v) v.begin(),v.end()
  #define double long double
  #define trace1(x)                cerr<<#x<<": "<<x<<endl
  #define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
  #define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
  #define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
  #define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<< ": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
  #define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
  #define cases int testcases;cin>>testcases; while(testcases--)
  const int N = 200005;



int32_t main()
{

    IOS



    int n;
    cin >> n;

    vector<int> v(n);

    for(int i = 0; i < n; i++)cin >> v[i];



    int money = 1000;


    stack<int> q;

    int buy = 0,sell = 0;

    int stocks = 0;

    for(int i = 0; i < n; i++)
    {
      // if(i == 4)
      // {
      //   trace2(q.front(),v[i]);
      // }
    //  trace1(i);
     // trace3(1,money,stocks);

      if(q.empty())
      {
        q.push(v[i]);
        buy = v[i];
        int k = money/buy;
        stocks += k;
        money-=k*buy;
      }
      else if(q.top() <=v[i])
      {
        q.push(v[i]);
      }
      else
      {
        sell = q.top();
      //  trace1(sell);
        money += sell*stocks;
       // trace1(money);
        stocks = 0;
        while(!q.empty())q.pop();

        q.push(v[i]);
        buy = v[i];
       // trace1(buy);
        int k = money/buy;
        stocks += k;
        money-=k*buy;

       // trace2(stocks,money);
      }
     // trace3(2,money,stocks);
    }

    if(!q.empty())
    {
      money += v[v.size()-1]*stocks;
    }

    cout << money;








    return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define endl "\n"
#define speed(); ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define sz(x) (int)(x).size()
#define _USE_MATH_DEFINES
using namespace std;
typedef long long int lli;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

int main() {
    speed();
    int k, n;
    cin >> k >> n;
    int A[n];
    rep(i, 0, n) cin >> A[i];
    int dis = k - A[n-1] + A[0];
    rep(i, 0, n-1) {
        if (A[i+1] - A[i] > dis)
            dis = A[i+1] - A[i];
    }
    cout << k - dis << endl;
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define vi vector<int>
#define vvi vector<vi>
#define forr(i,k,n) for(int i=k; i<n; i++)
#define iforr(i,k,n) for(int i=n-1; i>=k; i--)
#define rep(i,n) forr(i,0,n)
#define irep(i,n) iforr(i,0,n)
#define aut(i,arr) for(auto& i:arr)
#define all(arr) arr.begin(), arr.end()
#define pb push_back
#define pii pair<int,int>
#define vpii vector<pii>
#define f first
#define db double
#define s second
#define ll long long 
#define ull unsigned long long
#define E '\n'
#define lmax 9223372036854775807;
#define MOD 1000000007
using namespace std;
vi v;
vvi ed;
void dfs(int i)
{
	v[i]=1;
	aut(j,ed[i])
		if(!v[j])
			dfs(j);
}
void Fast_IO() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("code.in","r",stdin);
    freopen("code.out","w",stdout);
    #endif
}

int main()
{
	//Fast_IO();
	int t;
	//cin>>t;
	t=1;
	while(t--)
	{
		int n;
		cin>>n;
		vvi arr(n,vi(3));
		rep(i,n){
			cin>>arr[i][0];
			cin>>arr[i][1];
			cin>>arr[i][2];
		}
		vvi dp(n+1,vi(3,0));
		irep(i,n){
			rep(j,3){
				dp[i][j]=max(dp[i+1][(j+1)%3]+arr[i][(j+1)%3],dp[i+1][(j+2)%3]+arr[i][(j+2)%3]);
			}
		}
		cout<<max(max(dp[0][0],dp[0][1]),dp[0][2]);
		cout<<E;
	}
	return 0;
}

Measured memory_bytes: 11136
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <tuple>
#include <math.h>
#include <set>
#include <stack>
#include <bitset>
#include <map>
#include <queue>
#include <random>
#include <unordered_set>
#include <unordered_map>
#define DEBUG
#define fi first
#define se second
#define pqueue priority_queue
#define pb(x) push_back(x)
#define endl '\n'
#define all(x) x.begin(), x.end()
#define int long long
#define mk(a, b) make_pair(a, b)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<ull> vull;
typedef vector<ll> vll;
// typedef tuple<int, int, int> tiii;
typedef pair<int, int> pii;
typedef vector<pair<int, int> > vpii;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector< vector<int> > vvi;
typedef vector<char> vc;

const int INF = 1e9;
const ll INFLL = 1e16;
const int MOD = 1000000007;
const int MAXN = 3e5;
//const ld eps = 1e-6;
const ld eps2 = 1e-9;
const int MOD2 = 998244353;
const int dosz = 5e5;
const int SZ = (1<<18);
const ld PI = atan2l(0, -1);


void fast_io(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
#ifdef DEBUG
        // freopen("a.in", "r",stdin);
#else
       // freopen("substrcmp.in", "r", stdin);
       // freopen("substrcmp.out", "w", stdout);
#endif
}

void solve(){
    string s;
    cin >> s;
    if(s=="AAA" || s == "BBB"){
        cout << "No";
    } else{
        cout << "Yes";
    }

}

signed main() {
    fast_io();
    int q = 1;
    // cout << fixed << setprecision(6);
    // cin >> q;
    // cout << 1 << endl;
    while(q--){
        solve();
    }
    return 0;
}


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

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;
    for (int left = 0; left < N; left++) {
        while (right < N && (sum ^ a[right]) == (sum + a[right])) {
            sum += a[right];
            right++;
        }
        res += right - left;
        sum -= a[left];
    }
    cout << res << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
	int A,B,C;
  	vector<int> v;
  	while(cin>>A>>B>>C){
    	v.erase(v.begin(),v.end());
      	v.push_back(A);
      	v.push_back(B);
      	v.push_back(C);
      	sort(v.begin(),v.end());
    	if(v[1] == C)
          cout<<"Yes"<<endl;
      	else
          cout<<"No"<<endl;
    }
	return 0;
}

Measured memory_bytes: 256
//============================================================================
// Name        : JOI.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
using namespace std;
int A,B,C,D,P;
int main() {
	cin>>A>>B>>C>>D>>P;

	int S,T;
	S=P*A;
	if(C<P)T=B+(P-C)*D;
	if(C>P || C==P)T=B;

	if(S>T)cout<<T<<endl;
	if(S<T)cout<<S<<endl;
	if(S==T)cout<<S<<endl;
	return 0;
}

Measured memory_bytes: 3052
#include<iostream> 
#include<stdio.h>
#include<math.h>
#include<vector>
#include<queue>
#include<algorithm>
#include<map>
#include<string.h>
#define debug(a)	cout << "*" << a << "*" << endl
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
struct	node{
	ll l, r;
}w[3000], h[3000], d[50];

bool cmp1(node a, node b)
{
	return a.l < b.l;
}
bool cmp2(node a, node b)
{
	return a.r < b.r;
}
struct per{
	ll n, s, w, e;
	ll m;
	friend bool operator<(per a, per b)
	{
		return a.m < b.m;
	}
}dot[8000000];
ll n, k, hn, wn, dn, sum;
ll ans;
bool check(per a, node b)
{
	if (a.s <= b.r && b.r <= a.n && a.w <= b.l && b.l <= a.e)
		return true;
	return false;
}
int main()
{
	scanf("%lld%lld", &n, &k);
	for (int i = 0; i < n; i++)
		scanf("%lld%lld", &d[i].l, &d[i].r);
	sort(d, d + n, cmp1);
	for (int i = 0; i < n; i++)
		for (int j = i + 1; j < n; j++)
		{
			w[wn].l = d[i].l;
			w[wn].r = d[j].l;
			wn++;
		}
	sort(d, d + n, cmp2);
	for (int i = 0; i < n; i++)
		for (int j = i + 1; j < n; j++)
		{
			h[hn].l = d[i].r;
			h[hn].r = d[j].r;
			hn++;
		}
	for (int i = 0; i < wn; i++)
	{
		for (int j = 0; j < hn; j++)
		{
			dot[dn].n = h[j].r;
			dot[dn].s = h[j].l;
			dot[dn].w = w[i].l;
			dot[dn].e = w[i].r;
			dot[dn].m = (h[j].r - h[j].l) * (w[i].r - w[i].l);
			//printf("%lld %lld %lld %lld %lld\n", dot[dn].n, dot[dn].s, dot[dn].w, dot[dn].e, dot[dn].m); 
			dn++;
		}
	}
	sort(dot, dot + dn);
	for (int i = 0; i < dn; i++)
	{
		sum = 0;
		for (int j = 0; j < n; j++)
		{
			if (check(dot[i], d[j]))
			{
				sum++;
			}
		}
		if (sum >= k)
		{
			ans = dot[i].m;
			break;
		}	
	}
	cout << ans << endl;
}



Measured memory_bytes: 59648
#include<bits/stdc++.h>
using namespace std;
#define ll long long                                    // long long省略
#define pb push_back                                    // push_back省略
#define mp make_pair                                    // make_pair省略
#define fi first                                        // first省略
#define se second                                       // second省略
#define itn int                                         // int誤字保険
#define count cout                                      // cout誤字保険
#define vecotr vector                                   // vector誤字保険
#define ednl endl                                       // endl誤字保険
#define opt() cin.tie(0); ios::sync_with_stdio(false)   // 入出力速度改善

#define rep(i,l,r) for(ll i=(l);i<(r);i++)               // 範囲[l, r)で刻み1のfor文(順方向)
#define repp(i,l,r,k) for(ll i=(l);i<(r);i+=(k))         // 範囲[l, r)で刻みkのfor文(順方向)
#define rrep(i,l,r) for(ll i=(r-1);i>=(l);i--)           // 範囲[l, r)で刻み1のfor文(逆方向)
#define rrepp(i,l,r,k) for(ll i=(r-1);i>=(l);i-=(k))     // 範囲[l, r)で刻みkのfor文(逆方向)
#define all(x) (x).begin(), (x).end()                   // vectorのポインタ位置指定用
#define max(p,q)((p)>(q)?(p):(q))                       // max拡張
#define min(p,q)((p)<(q)?(p):(q))                       // min拡張
#define bit(n,m)(((n)>>(m))&1)                          // 変数nのm番目のbitを取り出す

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int dy[]={0, 1, 0, -1};                                 // 4方向近傍
int dx[]={1, 0, -1, 0};                                 // 4方向近傍

int main(){
    ll a,b,c;cin>>a>>b>>c;
  	cout << b*(c/a) << ednl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define endl "\n"
#define fastio ios_base::sync_with_stdio(false); cin.tie(nullptr);
#define all(x) x.begin(),x.end()
#define y1 omg
#define INF 1000000010
#define FOR(x, n) for(int x=0; x<n; x++)
#define ini(x, n) memset(x, n, sizeof(x));
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<ll> vl;

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


ll a, b, n, ans = 1;

ll f(ll x) {
	return (a * x) / b - a * (x / b);
}

int main() {
	cin >> a >> b >> n;
	cout << f(min(n, b - 1));
}

Measured memory_bytes: 3620
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <set>
#include <utility>
#include <cstdlib>

using namespace std;


int main(){
    int r, D, x;
    cin >> r >> D >> x;

    for(int i = 0; i < 10; i++){
        x = r * x - D;
        cout << x << endl;
    }



    return 0;
}



Measured memory_bytes: 256
//  Created by conan1024hao in 2019.
//  Copyright © 2019 conan1024hao. All rights reserved.
//  専用ライブラリです、自由にコピーして構いません。
//  感谢看我的代码！Wechat:conan1024hao QQ:810396815
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define IINF 10e8
#define INF 10e16
#define MOD 1000000007
#define  mod 1000000007
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
//using Int=int_fast64_t;
typedef long long int ll;
typedef pair<ll,ll>Pll;
typedef pair<int,int>Pin;
long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }
long long LCM(long long a, long long b)  {return a/GCD(a,b)*b;}
int dx[8]={-1,0,1,0,1,1,-1,-1};
int dy[8]={0,-1,0,1,1,-1,1,-1};
char dir[4]={'u','l','d','r'};
ll cmp1(pair<ll,string>a,pair<ll,string> b){
        if(a.fi!=b.fi)
        return a.fi<b.fi;
        else
        return a.se<b.se;
}
//--------------------------------------------------------------------------

//---------------------------------------------------------------------------
int main(){//問題をちゃんと見ろ!!!!!!!!!!!!!!!!!      llか??????????        memset()!!!!!!!!!!!!       ペナを減らせ!!!!!!!!!!!!!
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------
    ll n,T;cin>>n>>T;
    vector<ll>t(n);
    for(ll i=0;i<n;i++)cin>>t[i];
    ll sum=0;
    ll no=T;
    for(ll i=1;i<n;i++){
        sum+=min(t[i]-t[i-1],T);
    }
    sum+=T;
    cout<<sum<<endl;
    //-------------------------------
    return 0;
}
//---------------------------------------------------------------------------






Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#define int long long
#define endl '\n'
#define INF 1000000000000000000
#define EPS 1e-10
#define PI 3.141592653589793238
#define all(a) a.begin(),a.end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define pb push_back
#define double long double
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<P, ll> PP;
typedef complex<double> com;
template<class T, class S> bool chmax(T &a, const S &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T, class S> bool chmin(T &a, const S &b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll n, ll m) { return (m ? gcd(m, n%m) : n); }
ll lcm(ll n, ll m) { return n / gcd(n, m)*m; }

class FFT {
	static void fft(vector<com>& vec, int inv) {
		int s = vec.size();
		if (s == 1) return;
		vector<com> veca, vecb;
		for (int i = 0; i < s / 2; i++) {
			veca.pb(vec[2 * i]);
			vecb.pb(vec[2 * i + 1]);
		}
		fft(veca, inv);
		fft(vecb, inv);
		com x = 1;
		com z = polar(1.0, 2 * inv * PI / s);
		int t = s / 2 - 1;
		for (int i = 0; i < s; i++) {
			vec[i] = veca[i&t] + x * vecb[i&t];
			x *= z;
		}
	}
public:
	template<class T>
	static vector<int> multiply(vector<T> f, vector<T> g) {
		int s = 1;
		while (s < f.size() + g.size()) {
			s *= 2;
		}
		f.resize(s); g.resize(s);
		fft(f, 1); fft(g, 1);
		for (int i = 0; i < s; i++) f[i] *= g[i];
		fft(f, -1);
		vector<int> res;
		for (int i = 0; i < s; i++) {
			double d = f[i].real() / s;
			res.pb((int)(d + 0.5));
		}
		return res;
	}
};

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(20);
	//modcalc();

	int n, k;
	cin >> n >> k;
	vector<int> a(n);
	rep(i, n) cin >> a[i];
	sort(all(a));
	int ng = -1, ok = n;
	while (ok - ng > 1) {
		int mid = (ng + ok) / 2;
		bitset<10010> dp;
		dp[0] = 1;
		rep(i, n) if (i != mid && a[i] <= 5000) dp |= (dp << a[i]);
		bool flag = false;
		for (int i = max(0LL, k - a[mid]); i < k; i++) if (dp[i]) flag = true;
		if (flag) ok = mid;
		else ng = mid;
	}
	cout << ok << endl;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var n, k, c int
	var s string
	fmt.Scan(&n, &k, &c, &s)

	var i, j int
	a := make([]int, k)
	for i < n && j < k {
		if s[i] == 'o' {
			a[j] = i
			i += c
			j++
		}
		i++
	}

	b := make([]int, k)
	i, j = n-1, k-1
	for i >= 0 && j >= 0 {
		if s[i] == 'o' {
			b[j] = i
			i -= c
			j--
		}
		i--
	}

	for i := 0; i < k; i++ {
		if a[i] == b[i] {
			fmt.Println(a[i] + 1)
		}
	}
}


Measured memory_bytes: 6784
#include<bits/stdc++.h>
using namespace std;
int dp[100005];
int n,W;
int main(){
	memset(dp,63,sizeof(dp));
	scanf("%d%d",&n,&W);
	dp[0]=0;
	for(int i=0;i<n;i++){
		int w,v;
		scanf("%d%d",&v,&w);
		for(int j=100000;j>=w;j--)dp[j]=min(dp[j],dp[j-w]+v);
	}
	int pos;
	for(int i=0;i<=100000;i++)if(dp[i]<=W)pos=i;
	printf("%d\n",pos);
	return 0;
}

Measured memory_bytes: 768
#define _CRT_SECURE_CPP_OVERLOAD_SECURE_NAMES 1
#include <sstream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <random>
#include <ctime>

#define MOD 1000000007

const long long INF = 10000000000000000;

using namespace std;

int main(){
	long long H,W;
	cin>>H>>W;
	if(H==1 || W==1){
		cout<<"1"<<endl;
		return 0;
	}
	bool flg=true;
	long long ans=H*W;
	for(int i=1;i<H;i++){
		long long s1=i*W;
		long long s_min;
		long long s_max;
		long long s2;
		long long s3;
		if((H-i)%2==0){
			s2=(long long)((H-i)/2)*W;
			s3=s2;
		}else{
			s2=(long long)((H-i-1)/2)*W;
			s3=(long long)((H-i-1)/2+1)*W;
		}
		if(s2<0){
			cout<<s1<<" "<<s2<<" "<<s3<<" "<<(H-i)<<"*"<<W<<endl;
			return 0;
		}
		//cout<<"divH "<<s1<<" "<<s2<<" "<<s3<<endl;

		s_max=max(s1,max(s2,s3));
		s_min=min(s1,min(s2,s3));
		if(s_max>0 && s_min>0)
			ans=min(ans,s_max-s_min);

		if(W%2==0){
			s2=(long long)(H-i)*W/2;
			s3=s2;
		}else{
			s2=(long long)(H-i)*(W-1)/2;
			s3=(long long)(H-i)*((W-1)/2+1);
		}
		//cout<<"divW "<<s1<<" "<<s2<<" "<<s3<<endl;
		s_max=max(s1,max(s2,s3));
		s_min=min(s1,min(s2,s3));
		//if((s_max-s_min)==)
		if(s_max>0 && s_min>0)
			ans=min(ans,s_max-s_min);

	}
	for(int i=1;i<W;i++){
		long long s1=i*H;
		long long s_min;
		long long s_max;
		long long s2;
		long long s3;
		if((W-i)%2==0){
			s2=(long long)(W-i)*H/2;
			s3=s2;
		}else{
			s2=(long long)((W-i-1)/2)*H;
			s3=(long long)((W-i-1)/2+1)*H;
		}
		//cout<<"divH "<<s1<<" "<<s2<<" "<<s3<<" "<<i<<endl;
		s_max=max(s1,max(s2,s3));
		s_min=min(s1,min(s2,s3));
		if(s_max>0 && s_min>0)
			ans=min(ans,s_max-s_min);
		if(H%2==0){
			s2=(long long)(W-i)*H/2;
			s3=s2;
		}else{
			s2=(long long)(W-i)*(H-1)/2;
			s3=(long long)(W-i)*((H-1)/2+1);
		}
		//cout<<"divW "<<s1<<" "<<s2<<" "<<s3<<endl;
		s_max=max(s1,max(s2,s3));
		s_min=min(s1,min(s2,s3));
		if(s_max>0 && s_min>0)
			ans=min(ans,s_max-s_min);
	}
	cout<<ans<<endl;
	return 0;
}

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

#define NIL -1
#define MAX 10000

struct Node{ int parent,left,right; };
Node T[MAX];

int n;

// ここからプロトタイプ宣言
void preParse(int u);
void inParse(int u);
void postParse(int u);
// ここまでプロトタイプ宣言

int main(){
	cin>>n;		for(int i=0;i<n;i++) T[i].parent = NIL;

	int id,l,r;
	for(int i=0;i<n;i++){
		cin>> id >> l >> r ;

		T[id].left=l;
		T[id].right=r;

		if(T[id].left != NIL)  T[l].parent=id;
		if(T[id].right != NIL) T[r].parent=id;
	}

	int root;
	for(int i=0;i<n;i++)
		if(T[i].parent == NIL) root=i;

		printf("Preorder\n");
			preParse(root);
			printf("\n");

		printf("Inorder\n");
			inParse(root);
			printf("\n");

		printf("Postorder\n");
			postParse(root);
			printf("\n");

	return 0;
}


// ---------------------
// 関数

void preParse(int u){
	if(u == NIL) return;

	printf(" %d",u);
	preParse(T[u].left);
	preParse(T[u].right);
}

void inParse(int u){
	if(u == NIL) return;

	inParse(T[u].left);
	printf(" %d",u);
	inParse(T[u].right);
}

void postParse(int u){
	if(u == NIL) return;

	postParse(T[u].left);
	postParse(T[u].right);
	printf(" %d",u);
}



Measured memory_bytes: 3212
#include<cstdio>
int main()
{
	int a,b,c,ans;
	scanf("%d%d%d",&a,&b,&c);
	if(a==b&&b==c) ans=1;
	else if(a==b||a==c||b==c) ans=2;
	else ans=3;
	printf("%d\n",ans);
	return 0;
}

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

int main(){
  int N;
  cin >> N;
  if ((N/1000 == (N-(N/1000)*1000)/100) && (N/1000 == (N-(N/100)*100)/10)) {
    cout << "Yes" << endl;
  }
  else if (((N-(N/1000)*1000)/100 == (N-(N/100)*100)/10) && ((N-(N/1000)*1000)/100 == N-(N/10)*10)) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**9)

def mi(): return map(int,input().split())
def ii(): return int(input())
def isp(): return input().split()
def deb(text): print("-------\n{}\n-------".format(text))

INF=10**20
def main():
    X=ii()
    print("Yes" if X >= 30 else "No")




if __name__ == "__main__":
    main()

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

string P = "Positive";
string M = "Negative";

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

    if(a > 0){
        cout << P << endl;
        return 0;
    }


    if(b >= 0){
        cout << "Zero" << endl;
        return 0;
    }

    if((b-(a-1)) % 2 == 0){
        cout << P << endl;
    }else{
        cout << M << endl;
    }

    return 0;
}



Measured memory_bytes: 256
from heapq import *
Q = int(input())
L, R = [], []
ans = 0
for _ in range(Q):
    a = [int(a) for a in input().split()]
    if a[0] == 1:
        ans += a[2]
        if len(L) == 0 or a[1] <= -L[0]:
            heappush(L, -a[1])
            ans += -L[0] - a[1]
        else:
            heappush(R, a[1])
            ans += a[1] + L[0]
        if len(R) > len(L):
            ans -= R[0] + L[0]
            heappush(L, -heappop(R))
        elif len(L) - len(R) >= 2:
            heappush(R, -heappop(L))
    else:
        print(-L[0], ans)

Measured memory_bytes: 11108
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>

using namespace std;

// int min(int a, int b, int c, int d, int e){
//     int min;
//     if(a<=b && a<=c && a<=d && a<=e){
//         min = a;
//     }
//     else if(b<=a && b<=c && b<=d && b<=e){
//         min = b;
//     }
//     else if(c<=a && c<=b && c<=d && c<=e){
//         min = c;
//     }
//     else if(d<=a && d<=b && d<=c && d<=e){
//         min = d;
//     }
//     else if(e<=a && e<=b && e<=c && e<=d){
//         min = e;
//     }
//     return min;
// }

int main() {
    int a,b,c,d,e;
    cin >> a >> b >> c >> d >> e;
    int t = 0;
    int last = 0;
    
    int a1=a%10;
    int b1=b%10;
    int c1=c%10;
    int d1=d%10;
    int e1=e%10;
    
    if (a%10 == 0){
        a1 = a1+10;
    }
    if (b%10 == 0){
        b1 = b1+10;
    }
    if (c%10 == 0){
        c1 = c1+10;
    }
    if (d%10 == 0){
        d1 = d1+10;
    }
    if (e%10 == 0){
        e1 = e1+10;
    }
    
    if (min({a1, b1, c1, d1, e1}) == a1){
        last = a;
        a=0;
    }
    else if (min({a1, b1, c1, d1, e1}) == b1){
        last = b;
        b=0;
    }
    else if (min({a1, b1, c1, d1, e1}) == c1){
        last = c;
        c=0;
    }
    else if (min({a1, b1, c1, d1, e1}) == d1){
        last = d;
        d=0;
    }
    else if (min({a1, b1, c1, d1, e1}) == e1){
        last = e;
        e=0;
    }
    
    a = ceil(double(a)/10.0)*10;
    b = ceil(double(b)/10.0)*10;
    c = ceil(double(c)/10.0)*10;
    d = ceil(double(d)/10.0)*10;
    e = ceil(double(e)/10.0)*10;
    t = a + b + c + d + e + last;
    cout << t << endl;
}

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

const int MAXN = 3000;
const int MOD = 998244353;

inline int add(int x, int y) {x += y; return x >= MOD ? x - MOD : x;}
inline int sub(int x, int y) {x -= y; return x < 0 ? x + MOD : x;}
inline int mul(int x, int y) {return (int)(1LL * x * y % MOD);}

int pow_mod(int b, int p) {
	int ret = 1;
	for(int i=p;i;i>>=1,b=mul(b,b))
		if( i & 1 ) ret = mul(ret, b);
	return ret;
}

int f[MAXN + 5][MAXN + 5], A, B, C, D;

int main() {
	scanf("%d%d%d%d", &A, &B, &C, &D);
	
	for(int i=A;i<=C;i++) {
		int tmp = 0;
		for(int j=B;j<=D;j++) {
			if( i == A && j == B ) f[A][B] = 1;
			else {
				tmp = mul(add(tmp, f[i-1][j-1]), i - 1);
				f[i][j] = add(tmp, mul(f[i-1][j], j));
			}
		}
	}
		
	int ans = 0;
	for(int i=1;i<=D;i++)
		ans = add(ans, mul(f[C][i], pow_mod(C, D - i)));
	printf("%d\n", ans);
}

Measured memory_bytes: 36836
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int gcd(int x, int y){
    if(x < y) return gcd(y, x);
    if(y == 0) return x;
    return (gcd(y, x%y));
}   

int main(){
    int k;
    cin >> k;
    ll sm = 0;
    for(int a=1;a<=k;a++){
        for(int b=1;b<=k;b++){
            for(int c=1;c<=k;c++){
                sm += gcd(gcd(a,b), c);
            }
        }
    }
    cout << sm << endl;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int i,c=0,n,j,p=0;
    string a;
    cin>>a;
    for(i=0,j=a.size()-1; i<a.size(),j>=0; i++,j--)
    {
        if(a[i]!=a[j])
        {
            c++;
        }
    }
    cout<<c/2<<endl;
}


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

int main(){
  long long int a;
  double b;
  int new_b;
  long long int sol;
  
  cin >> a>>b;
//  cout << b<<endl;
  
  new_b = (int)(b*100+0.5);
//  cout << new_b<<endl;
  
  sol = a*new_b;
  sol = sol/100;
  
  cout << sol << endl;
  return 0;
  
}



Measured memory_bytes: 3716
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define DUMP(x) cout << #x << " = " << (x) << endl
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef pair<int, int> PII;

int main() {
  string s; cin >> s;
  int ans = 0;
  REP(i, 3) {
    if (s[i] == '1') ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 764
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<29;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-9;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

int n;

int main(){
	cin>>n;
	vp a(n);
	for(int i=0;i<n;i++){
		int x,y;
		cin>>x>>y;
		a[i]={x+y,x-y};
	}
	sort(a.begin(),a.end());
	int t=0,mx=-inf;
	for(int i=0;i<n;i++){
		if(mx<=a[i].second){
			mx=a[i].first;
			t++;
		}
	}
	cout<<t<<endl;
}

Measured memory_bytes: 1024