akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <queue>
#include <algorithm>
#include <string>
#include <utility>
#include <vector>
#include <map>
#include <stack>
#include <iomanip>
#include <set>
#include <sstream>
#include <cmath>
#include <deque>
#include <bitset>
using namespace  std;
typedef pair<string, int> Psi;
typedef pair<long long , long long> P;
typedef long long int64;
#define REP(i, n) for(int (i)=0; (i)<(n); ++i)
#define FOR(i, a, b) for(int (i)=0; (i)<(a); ++i)
#define ALL(a) (a).begin(),(a).end()
#define PB push_back
#define FST first
#define SND second
int main(){
    stack<int> st;
    stack<P> st2;
    vector<int64> A;
    int64 res = 0;
    int64 tmpres = 0;
    string s; cin >> s;
    for(int i=0, n=s.size(); i<n; ++i){
        if(s[i] == '/' && st.size()){
            int64 x = st.top(); st.pop();
            res += i-x;
            int a = i-x;
            while(st2.size() && st2.top().first > x){
                a += st2.top().second; st2.pop();
            }
            st2.push(P(x, a));
        }
        else if(s[i] == '\\') {
            st.push(i);
        }
    }
    cout << res << endl;
    vector<int> ans;
    while(st2.size()){
        ans.PB(st2.top().second);
        st2.pop();
    }
    reverse(ALL(ans));
    cout << ans.size();
    REP(i, ans.size()){
        cout << " " << ans[i];
    } 
    cout << endl;
    return 0;
}


Measured memory_bytes: 3244
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
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<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};

int l,r;

int main(){
	cin>>l>>r;
	int res=0;
	for(int i=l;i<=r;i++){
		string s=to_string(i),t=s;
		reverse(t.begin(),t.end());
		if(s==t) res++;
	}
	cout<<res<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>
#include<complex>

using namespace std;

#define ll long long
#define ld long double
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

const double PI=acos(-1);
const double EPS=1e-9; //うまくいかなかったらゆるめる

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef pair<int,pii> pip;
typedef vector<pii> vp;
typedef vector<vi> vvi;

int gcd(int a, int b){if(b==0) return a;return gcd(b,a%b);}
int lcm(int a, int b){return a/gcd(a,b)*b;}


signed main(void) {
    int n,k;
    cin >> n >> k;
    vi v(n,0);
    rep(i,k){
        int d;
        cin >> d;
        rep(i,d){
            int a;
            cin >> a;
            a--;
            v[a]++;
        }
    }
    int ans = 0;
    rep(i,n)if(v[i] == 0)ans++;
    cout << ans << endl;

}


Measured memory_bytes: 3168
#include <iostream>
using namespace std;
int num[10];
bool dfs(int start, int topl, int topr)
{
	if (start == 9)
	{
		if (num[start] > topl || num[start] > topr)
			return true;
		else
			return false;
	}
	else
	{
		bool b1 = false, b2 = false;
		if (num[start] > topl)
			b1=dfs(start + 1, num[start], topr);
		if (num[start] > topr)
			b2 = dfs(start + 1, topl, num[start]);
		return (b1 || b2);
	}
}
	
int main()
{
	int k;
	cin >> k;
	while (k--)
	{
		for (int i = 0; i <= 9; ++i)
			cin >> num[i];
		if (dfs(0,0,0))
			cout << "YES" << endl;
		else
			cout << "NO" << endl;
	}
	return 0;
}

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

int main() {
    int n, tmp, a[100], count, minIdx;

    // Input
    cin >> n;
    for (int i=0; i<n; i++) {
        cin >> a[i];
    }
    count = 0;

    // Sort
    for (int i=0; i<n; i++) {
        minIdx = i;
        for(int j=i; j<=n-1; j++) {
            if (a[j] < a[minIdx]) {
                minIdx = j;
            }
        }
        // Swap
        if (a[i] != a[minIdx]) {
            tmp = a[i];
            a[i] = a[minIdx];
            a[minIdx] = tmp;
            count++;
        }
    }

    // Output
    for (int i=0; i<n; i++) {
        cout << a[i];
        if (i==n-1) {
            cout << endl;
        } else {
            cout << ' ';
        }
    }
    cout << count << endl;

    return 0;
}


Measured memory_bytes: 3088
n = int(input())
p = []
a, b = map(int, input().split())
p.append(a)
p.append(b)
for _ in range(n-1):
    a, b = map(int, input().split())
    p.append(b)

m = [[0]*(n+1) for _ in range(n+1)]
for l in range(1, n):
    for i in range(1, n-l+1):
        j = i+l
        m[i][j] = float('inf')
        for k in range(i, j):
            m[i][j] = min(m[i][j], m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j])
print(m[1][n])


Measured memory_bytes: 5664
#include <stdio.h>
#include <string.h>
 
int main(){
    char N[51];
    scanf("%s" ,N);
    if( N[0] ==  N[strlen(N)-1] ){
	printf("%c\n",N[0]);
    }else{
	printf("o\n");
    }
    return 0;
}

Measured memory_bytes: 2740
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <tuple>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr int INF = 2000000000;
constexpr int HINF = INF / 2;
constexpr double DINF = 100000000000000000.0;
constexpr long long LINF = 9223372036854775807;
constexpr long long HLINF = 4500000000000000000;
const double PI = acos(-1);
int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
#define ALL(x)    (x).begin(),(x).end()
#define UNIQ(c)   (c).erase(unique(ALL((c))), end((c)))
#define mp        make_pair
#define eb        emplace_back
#define REP(i, a) for (int i = 0; i < (a); i++)

int C[1000];
int n;
int main() {
	cin >> n;
	int minl = INF;
	int maxl = 0;
	for (int i = 0; i < n; i++) {
		int a;
		cin >> a;
		C[a]++;
		minl = min(minl, a);
		maxl = max(maxl, a);
	}
	if (maxl == minl&&minl == 1) {
		cout << "Possible" << endl;
		return 0;
	}
	if (!(C[1] == 0 || C[1] == 1)) {
		cout << "Impossible" << endl;
		return 0;
	}
	else if (C[1] == 1) {
		if (maxl >= 3) {
			cout << "Impossible" << endl;
			return 0;
		}
	}
	if (C[minl] >= 3) {
		cout << "Impossible" << endl;
		return 0;
	}
	if (C[minl] == 2) {
		if (maxl - minl != minl - 1) {
			cout << "Impossible" << endl;
			return 0;
		}
		for (int i = minl+1; i <= maxl; i++) {
			if (C[i] <= 1) {
				cout << "Impossible" << endl;
				return 0;
			}
		}
	}
	if (C[minl] == 1) {
		if (maxl - minl != minl) {
			cout << "Impossible" << endl;
			return 0;
		}
		for (int i = minl+1; i <= maxl; i++) {
			if (C[i] <= 1) {
				cout << "Impossible" << endl;
				return 0;
			}
		}
	}
	cout << "Possible" << endl;
	return 0;
}

Measured memory_bytes: 256
from collections import Counter,defaultdict,deque
import sys
import bisect
import math
import itertools
import string
import queue
import copy
from heapq import heappop, heappush
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7

def inp(): # n=1
    return int(input())
def inpm(): # x=1,y=2
    return map(int,input().split())
def inpl(): # a=[1,2,3,4,5,...,n]
    return list(map(int, input().split()))
def inpls(): # a=['1','2','3',...,'n']
    return list(input().split())
def inplm(n): # x=[] 複数行
    return list(int(input()) for _ in range(n))
def inpll(n): # [[1,1,1,1],[2,2,2,2],[3,3,3,3]]
    return sorted([list(map(int, input().split())) for _ in range(n)])
def sortx(x,n,k):
    if k == 0:x.sort(key=lambda y:y[1,n])
    else:x.sort(reversed=True, key=lambda y:y[1,n])
def graph():
    n=inp()
    g=[[] for _ in range(n)]
    for i in range(n):
        a=inp()
        a-=1
        g[i].append(a)
        g[a].append(i)
    return n,g
def graphm():
    n,m=inpm()
    g=[[] for _ in range(n)]
    for _ in range(m):
        a,b,w=inpm()
        a-=1
        b-=1
        g[a].append((b,w))
        g[b].append((a,w))
    return n,m,g

def dijkstra(s,n,g): # sからの最短距離 頂点数n
    s -= 1
    que = []
    d = [10**15 for _ in range(n)]
    d[s] = 0
    heappush( que,(0,s) )
    while len(que)>0:
        p =  heappop(que)
        v = p[1]
        if d[v] < p[0]:
            continue
        for i in range(len(g[v])):
            edge = g[v][i]
            if d[edge[0]] > d[v] + edge[1]:
                d[edge[0]] = d[v] + edge[1]
                heappush( que,(d[edge[0]] , edge[0]) )
    return d

def main():
    n=inp()
    a=inpl()
    a.sort()
    if a[n-1]-a[0]>1 or a[n-1]>=n or a[0]<1:
        print("No")
        return
    cnt=1
    for i in range(n-1):
        if a[i+1]==a[i]:
            cnt+=1
        else:
            break
    if cnt==n:
        if a[0]==n-1 or n//a[n-1]>=2:
            print("Yes")
            return
        else:
            print("No")
            return
    if cnt>a[0]:
        print("No")
        return
    if (a[n-1]-(n%a[n-1]))>cnt:        
        print("No")
        return
    print("Yes")    


if __name__ == "__main__":
    main()




Measured memory_bytes: 54428
import java.util.Scanner;


public class Main {

    public static void main(String[] args) {

    	Main main=new Main();

    	main.run();

    }

    void run() {

    	Scanner sc=new Scanner(System.in);

    	int H=sc.nextInt();
    	int W=sc.nextInt();

    	String buf="";

    	for(int i=0;i<H;i++) {


    		for(int j=0;j<W;j++) {
    			buf=sc.next();

    			if(buf.equals("snuke")) {

    				char c=(char) ('A'+j);

    				String result=String.valueOf(c).toUpperCase()+(i+1);


    				System.out.println(result);
    				return ;
    			}
    		}

    	}


    }
}



Measured memory_bytes: 23636
n,m = map(int,input().split())
H = list(map(int,input().split()))
l = [0]*n
AB = [list(map(int,input().split())) for _ in range(m)]
for a,b in AB:
    if H[a-1]>H[b-1]:
        l[a-1] += 1
        l[b-1] -= 10000
    elif H[a-1]==H[b-1]:
        l[a-1] -= 10000
        l[b-1] -= 10000
    else:
        l[a-1] -= 10000
        l[b-1] += 1
ans = 0
for _ in range(n):
    if l[_]>=0:
        ans += 1
print(ans)

Measured memory_bytes: 33836
_, k, *ab = `dd`.split.map{|t|t.to_i}

m = [0] * (100_001)
ab.each_slice(2){|(a,b)| m[a] += b }

sz = 0
m.each_with_index do |b,i|
  sz += b
  (puts i; break) if k <= sz
end

Measured memory_bytes: 21760
n, m, x = map(int, input().split())
C = []
A = []
for i in range(n):
    L = list(map(int, input().split()))
    C.append(L[0])
    A.append(L[1:m+1])
# print(C, A)
ans = sum(C) + 1

for i in range(2**n):
    # print(bin(i))
    study = [0] * m
    price = 0
    for j in range(n):
        if i >> j & 1:
            for k in range(m):
                study[k] += A[j][k]
            price += C[j]
            # print(study, price)
            if min(study) >= x:
                ans = min(ans, price)

if ans == sum(C) + 1:
    print(-1)
else:
    print(ans)


Measured memory_bytes: 9232
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
using namespace std;


int main() {
	const long long int kuni = 10000000000;
	long long int n, m, rui[500000] = {}, rui2[500000] = {}, a[500000], a2[500000], res[500000] = {}, ax = 0;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		rui[i] = rui[i - 1] + a[i];
	}

	for (int i = 1; i <= n; i++) {
		cin >> a2[i];
		rui2[i] = rui2[i - 1] + a2[i];
	}
	for (int i = 1; i <= n; i++){
		res[i] = rui[i] + rui2[n] - rui2[i - 1];
		if (ax < res[i]) { ax = res[i]; }
	}
	cout << ax;
}


Measured memory_bytes: 12160
#include<iostream>
#include<cmath>
#include<string>
#include<map>
#include<queue>
using namespace std;
#define N 3
#define N2 9

struct Puzzle{
  int f[N2];
  int space;
  string path;

  bool operator < (const Puzzle &p) const{
    for(int i = 0 ; i < N2 ; i++){
      if(f[i] == p.f[i]) continue;
      return f[i] > p.f[i];
    }
    return false;
  }
};

static const int dx[4] ={-1, 0, 1, 0};
static const int dy[4] = {0, -1, 0, 1};
static const char dir[4] = {'u', 'l', 'd', 'r'};

bool isTarget(Puzzle p){
  for(int i = 0 ; i < N2 ; i++)
    if(p.f[i] != (i + 1)) return false;
  return true;
}

string bfs(Puzzle s){
  queue<Puzzle>Q;
  map<Puzzle, bool>V;
  Puzzle u, v;
  s.path = "";
  Q.push(s);
  V[s] = true;

  while(!Q.empty()){
    u = Q.front();
    Q.pop();
    if(isTarget(u)) return u.path;
    int sx = u.space / N;
    int sy = u.space % N;
    for(int r = 0 ; r < 4 ; r++){
      int tx = sx + dx[r];
      int ty = sy + dy[r];
      if(tx < 0 || ty < 0 || tx >= N || ty >= N) continue;
      v = u;
      swap(v.f[u.space], v.f[tx * N + ty]);
      v.space = tx * N + ty;
      if(!V[v]){
	V[v] = true;
	v.path += dir[r];
	Q.push(v);
      }
    }
  }

  return "unsolvable";
}

int main(){
  Puzzle in;

  for(int i = 0 ; i < N2 ; i++){
    cin >> in.f[i];
    if(in.f[i] == 0){
      in.f[i] = N2;
      in.space = i;
    }
  }
  string ans = bfs(in);
  cout<< ans.size()<<endl;

  return 0;
}


Measured memory_bytes: 30592
#include <bits/stdc++.h>
using namespace std;
 
int N,M,ans;
vector<int> visit;
vector<set<int> > adj;
 
void dfs(int i){
  visit[i]=1;
  for(int a:adj[i]) if(visit[a]==0) dfs(a);
}
 
int main(){
  cin >> N >> M;
  visit.resize(N+1);
  adj.resize(N+1);
  for(int i=0; i<M; ++i){
    int x,y,z; cin >> x >> y >> z;
    adj[x].insert(y);
    adj[y].insert(x);
  }
 
  for(int i=1; i<=N; ++i){
    if(visit[i]==0){
      ++ans;
      dfs(i);
    }
  }
 
  cout<<ans<<endl;
}

Measured memory_bytes: 17792
N = gets.to_i
As = gets.split.map(&:to_i)
M = 10**9 + 7

require 'prime'
l = As.inject(&:lcm)

def mpow(x, n)
  ret = 1
  while n > 0
    if n.even?
      x = x * x % M
      n >>= 1
    else
      ret = ret * x % M
      n -= 1
    end
  end
  ret
end

inv = ->(x){mpow(x, M - 2)}
puts l*As.inject(0){|s, a| (s + inv[a]) % M} % M

Measured memory_bytes: 72096
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ll long long
#define lld long double
#define ALL(x) x.begin(), x.end()
#ifdef DEBUG
#define line() cerr << "[" << __LINE__ << "] ";
#define dump(i) cerr << #i ": " << i << " ";
#define dumpl(i) cerr << #i ": " << i << endl;
#else
#define line(i)
#define dump(i)
#define dumpl(i)
#endif
using namespace std;

int main(int argc, char const *argv[])
{
    int n, m, p;
    cin >> n >> m >> p;
    ll a[m], b[m], c[m];
    rep(i, m)
    {
        cin >> a[i] >> b[i] >> c[i];
        a[i]--;
        b[i]--;
        c[i] = p - c[i];
    }
    const ll INF = (1ll << 60);
    ll dist[n];
    rep(i, n) dist[i] = INF;
    dist[0] = 0;
    rep(i, n) rep(j, m)
    {
        if (dist[a[j]] == INF)
            continue;
        if (dist[b[j]] > dist[a[j]] + c[j])
        {
            dist[b[j]] = dist[a[j]] + c[j];
            if (i == n - 1)
            {
                dist[b[j]] = -INF;
            }
        }
    }
    rep(i, n) rep(j, m)
    {
        if (dist[a[j]] == -INF)
        {
            dist[b[j]] = -INF;
        }
    }
    if (dist[n - 1] != -INF)
    {
        cout << max(0ll, -dist[n - 1]) << endl;
    }
    else
    {
        cout << -1 << endl;
    }

    return 0;
}


Measured memory_bytes: 384
#ifndef call_from_test
#include<bits/stdc++.h>
using namespace std;
#endif
//BEGIN CUT HERE
vector< vector<int> >
bfs(vector<string> &st,int sy,int sx,char wall,int dir){
  int h=st.size(),w=st.front().size();
  vector<vector<int> > dp(h,vector<int>(w,-1));
  using P = pair<int, int>;
  queue<P> qu;

  dp[sy][sx]=0;
  qu.emplace(sy,sx);

  int dy[]={1,-1,0,0,1,1,-1,-1};
  int dx[]={0,0,1,-1,1,-1,1,-1};
  auto in=[&](int y,int x){return 0<=y&&y<h&&0<=x&&x<w;};

  while(!qu.empty()){
    int y,x;
    tie(y,x)=qu.front();qu.pop();
    for(int k=0;k<dir;k++){
      int ny=y+dy[k],nx=x+dx[k];
      if(!in(ny,nx)||st[ny][nx]==wall) continue;
      if(~dp[ny][nx]) continue;
      dp[ny][nx]=dp[y][x]+1;
      qu.emplace(ny,nx);
    }
  }

  return dp;
}
//END CUT HERE
#ifndef call_from_test
//INSERT ABOVE HERE
signed ABC088_D(){
  int h,w;
  cin>>h>>w;
  vector<string> s(h);
  for(int i=0;i<h;i++) cin>>s[i];
  auto dp=bfs(s,0,0,'#',4);

  if(dp[h-1][w-1]<0){
    cout<<-1<<endl;
    return 0;
  }

  int cnt=0;
  for(int i=0;i<h;i++)
    for(int j=0;j<w;j++)
      cnt+=s[i][j]=='.';
  cout<<cnt-(dp[h-1][w-1]+1)<<endl;
  return 0;
}
/*
  verified on 2019/12/10
  https://atcoder.jp/contests/abc088/tasks/abc088_d
*/

signed main(){
  ABC088_D();
  return 0;
}
#endif


Measured memory_bytes: 256
// Ver19.03
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define INF (1 << 29) * 2
#define LLINF 4545454545454545454
#define MOD 1000000007
#define ll long long
#define ull unsigned long long
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
int upll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? -1 : *(ll *)a > *(ll *)b ? 1 : 0; }
int downll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? 1 : *(ll *)a > *(ll *)b ? -1 : 0; }
void sortup(ll *a, int n) { qsort(a, n, sizeof(ll), upll); }
void sortdown(ll *a, int n) { qsort(a, n, sizeof(ll), downll); }

int main()
{
  ll n, a, ans = 0;
  scanf("%lld", &n);
  for (int i = 0; i < n; i++)
  {
    scanf("%lld", &a);
    ans += log2(a & -a);
  }
  printf("%lld\n", ans);
}


Measured memory_bytes: 128
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
 
public class Main {
 
    public static final int BIG_NUM  = 2000000000;
    public static final int MOD  = 1000000007;
 
    public static void main(String[] args) {
 
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int ans;
 
        while(true){
 
            try {
                String inputed = br.readLine();
                if(inputed.length() == 1 && inputed.equals("0"))break;
 
                ans = 0;
                for(int i = 0; i < inputed.length(); i++){
                    ans += inputed.charAt(i)-'0';
                }
 
                System.out.printf("%d\n", ans);
 
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}


Measured memory_bytes: 25004
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, a, b) for (int i = a; i < (b); i++)
#define FOR(i, n) for (int i = n; i >= 0; i--)
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <cstring>
#include <vector>
#define ll long long
#define INF 1000000001;
using namespace std;
struct Edge{int from, to, cost;};

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

    cin >> a;

    vector<ll> alph(26,0);
    //int alph[27];
    //REP(i,27) alph[i] = 0;
    
    REP(i, a.length()){
        alph[int(a[i])-97]++;
    }


    ll all = (a.length()*(a.length()-1))/2;

    ll ans = 0;
    for(ll i = 0; i < 26; i++){
        ans += (alph[i]*(alph[i]-1))/2;
    }
    cout << all - ans + 1 << endl;

    return 0;
}


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

int parent(int i){
	return i / 2;
}

int left(int i){
	return 2 * i;
}

int right(int i){
	return 2 * i + 1;
}

int main()
{
	int H, i, A[100001];
	cin >> H;
	for (int i = 1; i <= H; ++i)cin >> A[i];
	for (int i = 1; i <= H; ++i)
	{
		cout << "node " << i << ": key = " << A[i] << ", ";
		if (parent(i) >= 1)cout << "parent key = " << A[parent(i)] << ", ";
		if (left(i) <= H)cout << "left key = " << A[left(i)] << ", ";
		if (right(i) <= H)cout << "right key = " << A[right(i)] << ", ";
		putchar('\n');
	}
	return 0;
}


Measured memory_bytes: 3092
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define jizz ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define pb push_back
#define MP make_pair
#define F first
#define S second
#define ET cout << "\n"
#define MEM(i,j) memset(i,j,sizeof i)
#define ALL(v) v.begin(),v.end()
#define DB(a,s,e) {for(int i=s;i<e;++i) cerr << a[i] << " ";ET;}
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

vector<pii> v;
vector<int> dp;

int main()
{jizz
	int n,x1,y1,x2,y2,flip=0,x,y;
	const double pi=acos(-1);
	cin >> x1 >> y1 >> x2 >> y2 >> n;
	if(x1>x2) swap(x1,x2),swap(y1,y2);
	if(y1>y2) flip=1,y2=2*y1-y2;
	for(int i=0;i<n;++i)
	{
		cin >> x >> y,flip&&(y=2*y1-y);
		if(x>=x1&&y>=y1&&x<=x2&&y<=y2)
			v.pb(MP(x,y));
	}
	sort(ALL(v));
	for(auto i:v)
	{
		int t=lower_bound(ALL(dp),i.S)-dp.begin();
		if(t==dp.size()) dp.pb(i.S);
		else dp[t]=i.S;
	}
	cout << fixed << setprecision(15);
	if(dp.size()==min(x2-x1,y2-y1)+1) cout << 100.*(x2-x1+y2-y1)-(20.-5.*pi)*(dp.size()-1)+10.*pi-20. << "\n";
	else cout << 100.*(x2-x1+y2-y1)-(20.-5.*pi)*dp.size() << "\n";
}

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

using namespace std;

/*  テンプレここから */
typedef long long ll;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repi(i, start, end) for(int i = start; i < end; i++)
#define all(x) (x).begin(), (x).end()
#define INF (1e9)
#define add_mod(a, b, x) ( (ll)(a) + (ll)(b) ) % (ll)(x)
#define mul_mod(a, b, x) ( ((ll)(a) % (ll)(x)) * ((ll)(b) % (ll)(x)) ) % (ll)(x)
#define out(x) cout << (x) << endl;
#define outyes(bool_val) cout << (bool_val ? "yes" : "no") << endl;
#define outYes(bool_val) cout << (bool_val ? "Yes" : "No") << endl;
#define outYES(bool_val) cout << (bool_val ? "YES" : "NO") << endl;
#define outPossible(bool_val) cout << (bool_val ? "Possible" : "Impossible") << endl;
#define outPOSSIBLE(bool_val) cout << (bool_val ? "POSSIBLE" : "IMPOSSIBLE") << endl;

ll sub_mod(ll a, ll b, ll x){
    ll tmp = (a - b) % x;
    if(tmp < 0) tmp += x;
    return tmp;
}
ll gcd(ll a, ll b){
    if(b == 0) return a;
    else return gcd(b, a % b);
}

int dx[] = {0, 1, 0, -1};
int dy[] = {-1, 0, 1, 0};
/*  テンプレここまで */

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

    int a, b, c, d;
    cin >> a >> b >> c >> d;

    cout << max(a * b, c * d) << endl;
}

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

int main() {
int K;
  string S;
  cin >> K;
  cin >> S;
  if(S.length() > K){
    for(int a = 0;a < K;a++)cout << S[a];
    cout << "..." << endl;
  }else{
   cout << S << endl; 
  }


}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
#define MP make_pair
#define PB push_back
#define PP pop_back()
#define set(x,y) memset(x,y,sizeof(x))
#define MIN3(x,y,z) min(min(x,y),z)
#define MAX3(x,y,z) max(max(x,y),z)
#define ALL(x) x.begin(),x.end()
#define sz(x) (int) x.size()
#define sag node*2+1
#define sol node*2
#define FOR(i,j,k) for(int i=j;i<=k;i++)
#define ROF(i,j,k) for(int i=j;i>=k;i--)
#define dbgs(x) cerr<<(#x)<<" --> "<<(x)<<" "
#define dbg(x) cerr<<(#x)<<" --> "<<(x)<<endl;getchar()
#define ii pair<int,int>
#define pll pair<ll,ll>
#define st first
#define nd second
#define ll long long
#define llu long long unsigned
#define lf double
#define orta (bas+son)/2
#define MOD 1000000007
#define inf 200000000000001
#define N 300005
using namespace std;

ll ans;
int n,a[N];

int main() {

  scanf("%d",&n);
  FOR(i,1,3*n) {
    scanf("%d",&a[i]);
  }
  sort(a+1,a+1+3*n);
  ROF(i,3*n,n+1) {
    ans+=a[i-1];
    i--;
  }
  printf("%lld",ans);

}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long INF = 1LL<<60;

ll GCD(ll x,ll y){
    if(y == 0) return x;
    else return GCD(y,x%y);
}

ll LCM(ll a,ll b){
    return a / GCD(a,b) * b;
}

const int MOD = 1000000007;


//void warshall_floyd(int n){
//    for(int k=0;k<n;k++){
//        for(int i=0;i<n;i++){
//            for(int j=0;j<n;j++){
//                d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
//            }
//        }
//    }
//}
//ll calc_digit(ll N) {
//    ll res = 0;
//    while (N) {
//        ++res;
//        N /= 10;
//    }
//    return res;
//}
//ll sum_digit(ll N) {
//    ll res = 0;
//    while (N) {
//        res += N % 10;
//        N /= 10;
//    }
//    return res;
//}


int main() {
    string s,t; cin >> s >> t;
    sort(s.begin(),s.end());
    sort(t.begin(),t.end(),greater<int>());
    if(s < t){
        cout << "Yes";
    }else{
        cout << "No";
    }
}


Measured memory_bytes: 3580
#!/usr/bin/env python3

n = int(input())
s = list(str(input()))


base_a = ord("A")

for i in range(len(s)):
    index = (ord(s[i])-base_a+n) % 26 + base_a
    s[i] = chr(index)

for i in range(len(s)):
    print(s[i], end="")
print()


Measured memory_bytes: 4596
s = input()
od = ["R","U","D"]
ev = ["L","U","D"]
f = True
for i in range(len(s)):
    if i%2==0:
        if s[i]in od:pass
        else: f=False
    if i%2==1:
        if s[i]in ev:pass
        else: f=False
if f:print("Yes")
else:print("No")


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s,t;
	cin>>s>>t;
	int ans=0;
	for (int i=0;i<s.length();i++)
	{
		if (s[i]!=t[i])   ans++;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 3856
#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <ios>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <utility>
#include <vector>
#define itn int
#define retrun return
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
using namespace std;
typedef long long llong;
typedef pair<int, int> pii;
llong gcd(llong a, llong b) {
  if (a < b) std::swap(a, b);
  if (a % b == 0)
    return b;
  else
    return gcd(b, a % b);
}
llong lcm(llong a, llong b) {
  llong g = gcd(a, b);
  return a * b / g;
}
//ここまで共通
double ans;
int main() {
	double a, b, x;
	cin >> a >> b >> x;
	const double pi = 2.0 * asin(1.0);
	if (x > (a * a * b) / 2) {
		double l = (a * a * b - x) * 2 / (a * a);
		ans = atan(l / a);
		ans = ans * 180 / pi;
	}
	else {
		double l = 2 * x / ( a * b);
		ans = pi / 2 - atan(l / b);
		ans = ans * 180 / pi;
	}
	printf("%12.12lf", ans);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
 
int main() {
    string S;
    cin >> S;
    int cnt = 0;
    for (size_t i=0; i<S.size(); ++i) {
        if (S[i] == '1') ++cnt;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 3540
#include <stdio.h>
int main(void) {
    int n,k;
    char s[50];
    scanf("%d%d",&n,&k);
    scanf("%s",s);

    if(s[k-1]=='A') {
        s[k-1] = 'a';
    }
    else if(s[k-1]=='B') {
        s[k-1] = 'b';
    }
    else {
        s[k-1] = 'c';
    }
    printf("%s\n",s);
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
using ll = long long;
using P = pair<int,int>;
using PP = pair<int,pair<int,int>>;
using T = tuple<string,int,int>;
const ll INF = 1LL<<60;

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

  int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
  for(int i = 0; i < s.size(); i++){
    if(i % 2){
      if(s[i] == '1') c1++;
      else c2++;
    }
    else{
      if(s[i] == '1') c3++;
      else c4++;
    }
  }
  int ans = min(c1 + c4, c2 + c3);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 512
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <queue>
#define MOD (1000000007l)
#define rep(i, n) for(long i = 0; i < n; i++)

using namespace std;

int main(void) {
  cout.precision(12);

  long N;
  cin >> N;
  vector<long> a(3*N);
  rep(i, 3*N) cin >> a[i];

  priority_queue<long, vector<long>, greater<long>> before_queue;
  priority_queue<long> after_queue;

  long before_sum = 0;
  long after_sum = 0;

  vector<long> before_result(3*N, 0);
  vector<long> after_result(3*N, 0);

  for(long i = 0; i < N; i++) {
    before_sum += a[i];
    before_queue.push(a[i]);
  }
  before_result[N-1] = before_sum;
  for (long i = N; i < 2*N; i++) {
    before_sum += a[i];
    before_queue.push(a[i]);
    before_sum -= before_queue.top();
    before_queue.pop();
    before_result[i] = before_sum;
  }

  for (long i = 3*N-1; i >= 2*N; i--) {
    after_sum += a[i];
    after_queue.push(a[i]);
  }
  after_result[2*N] = after_sum;
  for (long i = 2*N-1; i >= N; i--) {
    after_sum += a[i];
    after_queue.push(a[i]);
    after_sum -= after_queue.top();
    after_queue.pop();
    after_result[i] = after_sum;
  }

/*
  rep (i, 3*N) cout << before_result[i] << " ";
  cout << endl;
  rep (i, 3*N) cout << after_result[i] << " ";
  cout << endl;
*/

/*
  for (long i = N-1 + 1; i < 2*N; i++) before_result[i] = max(before_result[i-1], before_result[i]);
  for (long i = 2*N - 1; i >= N; i--) after_result[i] = min(after_result[i+1], after_result[i]);
*/

  bool not_calculated = true;
  long result;

  for (long i = N-1; i < 2*N; i++) {
    long tmp_result = before_result[i] - after_result[i+1];
    if (not_calculated or result < tmp_result) result = tmp_result;
    not_calculated = false;
  }

  cout << result << endl;

  return 0;
}


Measured memory_bytes: 9588
#include <bits/stdc++.h>
using namespace std;
#define INF 1<<29
typedef pair<int,int> P;

int a[1<<15][1001];
int main() {
  int n,m,k,p;
  cin >> n >> m >> k >> p;
  p--;
  vector<P> v[n];
  for(int i=0; i<m; i++) {
    int x,y,z;
    cin >> x >> y >> z;
    x--;y--;
    v[x].push_back(P(y,z));
    v[y].push_back(P(x,z));
  }
  int d[n][n];
  for(int i=0; i<n; i++) {
    for(int j=0; j<n; j++) d[i][j]=INF;
  }
  for(int i=0; i<n; i++) {
    priority_queue<P,vector<P>,greater<P> > que;
    que.push(P(0,i));
    d[i][i]=0;
    while(!que.empty()) {
      P p=que.top();que.pop();
      int c=p.first,x=p.second;
      if(c>d[i][x]) continue;
      for(int j=0; j<v[x].size(); j++) {
	int y=v[x][j].first;
	if(d[i][y]>c+v[x][j].second) {
	  d[i][y]=c+v[x][j].second;
	  que.push(P(d[i][y],y));
	}
      }
    }
  }
  P b[m];
  for(int i=0; i<k; i++) {
    cin >> b[i].first >> b[i].second;
    b[i].first--;b[i].second--;
  }
  for(int t=0; t<(1<<(k*2)); t++) {
    for(int i=0; i<n; i++) a[t][i]=INF;
  }
  a[0][p]=0;
  for(int t=0; t<(1<<(k*2)); t++) {
    for(int i=0; i<n; i++) {
      if(a[t][i]==INF) continue;
      for(int j=0; j<k; j++) {
	if(!(t&(1<<j))) a[t|(1<<j)][b[j].first]=min(a[t|(1<<j)][b[j].first],a[t][i]+d[i][b[j].first]);
	if(t&(1<<j) && !(t&(1<<(j+k)))) a[t|(1<<(j+k))][b[j].second]=min(a[t|(1<<(j+k))][b[j].second],a[t][i]+d[i][b[j].second]);
      }
    }
  }
  int ans=INF;
  for(int i=0; i<n; i++) ans=min(ans,a[(1<<(k*2))-1][i]);
  if(ans==INF) cout << "Cannot deliver" << endl;
  else cout << ans << endl;
  return 0;
}


Measured memory_bytes: 21600
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;


void main()
{
  int a, b, c;
  readf("%s %s %s\n", &a, &b, &c);
  auto x = 1;
  bool[int] f;
  auto tc = a % b;
  bool res;
  while (f.get(tc, true)) {
    if (tc == c) {
      res = true;
      break;
    }
    f[tc] = false;
    x++;
    tc = (x * a) % b;
  }

  if (res) {
    writeln("YES");
  } else {
    writeln("NO");
  }
}


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

using namespace std;
typedef long long ll;
ll MOD = 1e9 + 7;
ll dp[101][200001];
ll sdp[200001];
int num[200001];
int main() {
	int N, K;
	cin >> N >> K;
	int M = 0;
	int i = 1;
	while (i <= N) {
		int j = N / i;
		if (i <= j) {
			num[M++] = 1;
			i++;
		}
		else {
			num[M++] = N / j - i + 1;
			i = N / j + 1;
		}
	}
	dp[0][0] = 1;
	for (int k = 0; k < K; k++) {
		memset(sdp, 0, sizeof(sdp));
		sdp[0] = dp[k][0];
		for (int j = 1; j < M; j++) {
			sdp[j] = (sdp[j - 1] + dp[k][j]) % MOD;
		}
		for (int j = 0; j < M; j++) {
			dp[k + 1][j] = sdp[M - j - 1] * num[j] % MOD;
		}
	}
	ll ans = 0;
	for (int i = 0; i < M; i++) (ans += dp[K][i]) %= MOD;
	cout << ans << endl;
}

Measured memory_bytes: 159488
#! /usr/bin/env python3

import sys
from collections import deque, Counter
int1 = lambda x: int(x) - 1
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

N = int(readline())

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a


c = list(Counter(prime_factorize(N)).values())

ans = 0
used = {}

for i in range(len(c)):
    cnt = 1
    while True:
        if c[i] >= cnt:
            c[i] -= cnt
            ans += 1
            cnt += 1
        else:
            break

print(ans)


Measured memory_bytes: 9536
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <iterator>
#pragma warning(disable:4996)
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
#define MOD 1000000007
using namespace std;

const long max_comb=300;
vector<ll> fac(max_comb+1); //n!(mod M)
vector<ll> ifac(max_comb+1); //k!^{M-2} (mod M)

ll mpow(ll x, ll n){ //x^n(mod M)
    ll ans = 1;
    while(n != 0){
        if(n&1) ans = ans*x % MOD;
        x = x*x % MOD;
        n = n >> 1;
    }
    return ans;
}

ll comb(long a, long b){     // C(a,b) = a! * b!^(M-2) * (a-b)^(M-2)
    if(a == 0 && b == 0)return 1;
    if(a < b || a < 0)return 0;
    ll tmp = ifac[a-b]* ifac[b] % MOD;
    return tmp * fac[a] % MOD;
}

ll perm(long a, long b){     // P(a,b) = a! * (a-b)!^(M-2)
    if(b == 0)return 1;
    if(a < b || a < 0)return 0;
    ll tmp = ifac[a-b] % MOD;
    return tmp * fac[a] % MOD;
}

void pre_comb()
{
    fac[0] = 1;
    ifac[0] = 1;
    for(long i = 0; i<max_comb; i++){
        fac[i+1] = fac[i]*(i+1) % MOD; // n!(mod M)
        ifac[i+1] = ifac[i]*mpow(i+1, MOD-2) % MOD; // k!^{M-2} (mod M)
    }
    return;
}


ll dp[205][100005];

int main(int argc, char* argv[])
{
    long n, x;
    scanf("%ld%ld", &n, &x);

    vector<long> s(n);
    long i,j;
    for(i=0; i<n; i++) {
        scanf("%ld", &s[i]);
    }
    sort(s.rbegin(), s.rend());

    pre_comb();

    dp[0][x]=1;
    for(i=0; i<n; i++) {
        for(j=0; j<=x; j++) {
            if(dp[i][j]) {
                long m;
                for(m=i+1; m<=n; m++) {
                    ll tmp = dp[i][j];
                    tmp = (tmp * perm(n-i-1, m-i-1))%MOD;
                    dp[m][j%s[m-1]] = (dp[m][j%s[m-1]] + tmp)%MOD;
                }
            }
        }
    }

    ll ans=0;
    for(i=0; i<s[n-1]; i++) {
        ans = (ans + i*dp[n][i])%MOD;
    }
    printf("%lld\n", ans);

    return 0;
}


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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ANS(ans) cout << ans << endl
#define FLG(flg) if(flg) cout << "Yes" << endl; else cout << "No" << endl;
#define YES cout << "Yes" << endl;
#define NO cout << "No" << endl;
#define COUT(s) cout << s << endl;
#define AN vector<int> a(n); for(int i = 0; i < n; i++) cin >> a[i];
#define IN  int n;  cin >> n;
#define VI  vector<int> 
#define SS stringstream ss;
#define SOLVE cout << solve() << endl;
 
int main() {
    int a, b;
    cin >> a >> b;
    if ((a >= 1) && (a <= 9) && (b >= 1) && (b<= 9)) cout << a*b << endl;
    else  cout << -1 << endl;
}

Measured memory_bytes: 256
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <numeric>
#include <sstream>
#include <iostream>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cfloat>
#include <cmath>
#include <ctime>
#include <cassert>
#include <cctype>
#include <cstdio>
#include <cassert>
using namespace std;

#define EPS 1e-12
#define ull unsigned long long
#define ll long long
#define VI vector<ll>
#define PII pair<ll, ll> 
#define VVI vector<vector<ll> >
#define VVVI vector<vector<vector<ll>>>
#define VVVVI vector<vector<vector<vector<ll>>>>
#define REP(i,n) for(ll i=0,_n=(n);(i)<(ll)_n;++i)
#define REPR(i,n) for(ll i=(ll)(n)-1;0<=(i);--i)
#define RANGE(i,a,b) for(ll i=(ll)a,_b=(ll)(b);(i)<_b;++i)
#define RANGER(i,a,b) for(ll i=(ll)(b)-1,_a=(ll)(a);(_a)<=i;--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define ALLR(c) (c).rbegin(), (c).rend()
#define PB push_back
#define MP(a, b) make_pair(a, b)
#define POPCOUNT __builtin_popcount
#define POPCOUNTLL __builtin_popcountll
#define CLEAR(table, v) memset(table, v, sizeof(table));
#define UNIFORM_DOUBLE(a, b) (((b-a)*(double)rand()/RAND_MAX)+a) // [a, b) 
#define UNIFORM_LL(a, b) (ll)UNIFORM_DOUBLE(a, b) // [a, b) 
#define IN(v, lo, hi) ((lo)<=(v) && (v)<(hi))
#define DD(v) cout<<#v<<": "<<v<<endl
#define FI first
#define SE second
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const map<T0, T1>& v) { for( typename map<T0, T1>::const_iterator p = v.begin(); p!=v.end(); p++ ){os << p->first << ": " << p->second << " ";} return os; }
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const pair<T0, T1>& v) { os << v.first << ": " << v.second << " "; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<T>& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << " "; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const set<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const deque<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<vector<T> >& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << endl; } return os; }
template<typename T>void maxUpdate(T& a, T b) {a = max(a, b);}
template<typename T>void minUpdate(T& a, T b) {a = min(a, b);}

#define MOD 1000000007LL
#define INF (1LL<<60)

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll R,D,X;
	while(cin>>R>>D>>X) {
		REP(i, 10) {
			X = R*X-D;
			cout<<X<<endl;
		}
	}
	
	return 0;
}


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

#define DUMP(x) cerr << #x << "=" << x << endl
#define DUMP2(x, y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<")"<< endl
#define BINARY(x) static_cast<bitset<16> >(x)

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

#define in_range(x, y, w, h) (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))
#define ALL(a) (a).begin(),(a).end()

typedef long long ll;
const int INF   = 1e9;
const ll  INFLL = 1e18;
typedef pair<int, int> PII;
typedef vector<vector<int>> Graph;
int dx[4]={0, -1, 1, 0}, dy[4]={-1, 0, 0, 1};

int main()
{
    ios::sync_with_stdio(false);
    int N; cin >> N;
    vector<int> P(N);
    rep(i, N) cin >> P[i];

    vector<PII> A(N);
    rep(i, N) A[i] = PII(P[i], i);
    sort(A.begin(), A.end());

    int mx = 1;
    {
        int l = 0, r = 0;
        while (l < N && r < N-1) {
            if (A[r].second < A[r+1].second) {
                r++;
                mx = max(mx, r - l + 1);
            } else {
                r++;
                l = r;
            }
        }
    }

    sort(A.begin(), A.end(), greater<PII>());
    {
        int l = 0, r = 0;
        while (l < N && r < N-1) {
            if (A[r].second > A[r+1].second) {
                r++;
                mx = max(mx, r - l + 1);
            } else {
                r++;
                l = r;
            }
        }
    }

    cout << N - mx << endl;
}



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

int main(void){
    long long int a, b, x;
    cin >> a >> b >> x;
    if (a == 0)
        cout << b / x + 1<< endl;
    else
        cout << b / x - (a - 1) / x << endl;
    return 0;
}

Measured memory_bytes: 256
from collections import deque

n = int(input())
ab = [list(map(int, input().split())) for _ in range(n-1)]

l = [[] for _ in range(n+1)]
for a, b in ab:
    l[a].append(b)
    l[b].append(a)

parents = [-1] * (n+1)
order = []
q = deque()
q.append(1)
while q:
    c = q.pop()
    order.append(c)
    for i in l[c]:
        if i == parents[c]:
            continue
        parents[i] = c
        q.append(i)

color = [-1] * (n+1)
for i in order:
    ng = color[i]
    c = 1
    for j in l[i]:
        if j == parents[i]:
            continue
        if c == ng:
            c += 1
        color[j] = c
        c += 1

ans = []
for a, b in ab:
    if a == parents[b]:
        ans.append(color[b])
    else:
        ans.append(color[a])

print(max(ans))
print('\n'.join(list(map(str, ans))))


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

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 1
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define TO_STRING(VariableName) # VariableName
#define LOG(x) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<endl;
#define LOG2(x,y) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<endl;
#define LOG3(x,y,z) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;
#define LOG4(w,x,y,z) if(DEBUG)cout<<TO_STRING(w)<<"="<<w<<" "<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;

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; }


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

void func(long long N, std::vector<long long> A, std::vector<long long> B){

    vector<pair<lli,lli>> v;

    REP(i,0,N)v.push_back({B[i],-A[i]});

    SORT(v);

    lli now = 0;
    REP(i,0,N){
        if(now-v[i].second>v[i].first){
            cout<<"No"<<endl;
            return;
        }
        now += -v[i].second;
    }

    cout<<"Yes"<<endl;

}

int main(){
    // cout << fixed << setprecision(5);

    long long N;
    scanf("%lld",&N);
    std::vector<long long> A(N);
    std::vector<long long> B(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
        scanf("%lld",&B[i]);
    }
    func(N, std::move(A), std::move(B));
    return 0;
}


Measured memory_bytes: 9584
#include <iostream>
#include <algorithm>
#include <string>
#include <cstdio>
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define endl "\n"
typedef long long ll;
#define traceV(v) for(auto x:v)cout<<x<<" ";cout<<endl
#define traceM(mp) for(auto x:mp)cout<<x.first<<" "<<x.second<<endl
#define MOD 1000000007

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

  int X,Y,Z; cin>>X>>Y>>Z;

  cout << Z <<" "<< X <<" "<< Y << endl;
  return 0;
}


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

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


//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);

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


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

    vector<ll> plans(n + 2, 0);
    rep(i, n) {
        ll a;
        cin >> a;

        plans[i + 1] = a;
    }


    vector<ll> normal_costs(n + 1, 0);
    rep(i, n + 1) {
        ll from = plans[i];
        ll to = plans[i + 1];
        ll cost = abs(from - to);
        normal_costs[i] = cost;
    }
    ll sum = accumulate(normal_costs.begin(), normal_costs.end(), 0ll);

    vector<ll> via_costs(n, 0);
    rep(i, n) {
        via_costs[i] = normal_costs[i] + normal_costs[i + 1];
    }

    vector<ll> direct_costs(n, 0);
    rep(i, n) {
        ll from = plans[i];
        ll to = plans[i + 2];
        ll cost = abs(from - to);
        direct_costs[i] = cost;
    }

    rep(i, n) {
        ll before = via_costs[i];
        ll after  = direct_costs[i];
        ll diff = before - after;

        cout << sum - diff << endl;
    }

}

Measured memory_bytes: 4352
N = int(input())
X = list(map(int,input().split()))
q = int(input())
for i in range(q):
    a = input().split()
    t = int(a[1])
    s = int(a[2])
    
    if a[0] =="0":
        print(min(X[t:s]))
    elif a[0] == "1":
        print(max(X[t:s]))



Measured memory_bytes: 5632
n,k=map(int,input().split())
r,s,p=map(int,input().split())
t=list(input())

dp=[0]*n
a = {"r":p, "s":r, "p":s}

for i in range(n):
    if i>=k and t[i]==t[i-k]: # どうせ得点できないので、次に影響しないように'x'
        dp[i]=0
        t[i]='x'
    else:
        dp[i]=a[t[i]]   
print(sum(dp))

Measured memory_bytes: 50288
import java.util.*;
 
public class Main {
 
	public static Scanner scan = new Scanner(System.in);
	public static void main(String[] args) {
      
 	String a = scan.next();
	      if(a.charAt(0) > 96 && a.charAt(0) < 123) 
	        System.out.println('a');
	      if(a.charAt(0) > 64 && a.charAt(0) < 91)
	        System.out.println('A');
    }
}

Measured memory_bytes: 35684
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

    println!("{}", answer);
}

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let rs: Vec<&str> = iterator.next().unwrap().split('S').collect();
    let ans = rs.iter().map(|it| it.len()).max().unwrap();
    ans.to_string()
}


Measured memory_bytes: 2056
use std::cmp::*;
use std::io::*;

fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let s: Vec<u8> = itr.next().unwrap().bytes().collect();

    let mut memo = vec![0; 125];
    for &n in s.iter() {
        memo[n as usize] += 1;
    }

    for i in 97..123 {
        if memo[i] % 2 != 0 {
            println!("No");
            return;
        }
    }
    println!("Yes")
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
int p[53], s[53];
int main()
{
  int N, r = 0;
  cin >> N;
  for (int i = 0; i < N; i ++) cin >> p[i], s[i] = p[i];
  sort(s, s + N);
  for (int i = 0; i < N; i ++) if (p[i] != s[i]) r ++;
  if (r <= 2) cout << "YES" << endl;
  else cout << "NO" << endl;
}


Measured memory_bytes: 256