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

using pii = pair<int, int>;

int main() {
	int n;
	while(cin >> n, n) {
		vector<int> p(n), d(n);
		for(int i = 1; i < n; ++i) {
			cin >> p[i];
			p[i]--;
		}
		for(int i = 1; i < n; ++i) {
			cin >> d[i];
		}
		vector<vector<pii>> g(n);
		for(int i = 1; i < n; ++i) {
			g[i].emplace_back(p[i], d[i]);
			g[p[i]].emplace_back(i, d[i]);
		}
		
		int ans = 0;
		function<pii(int, int, int)> dia = [&] (int v, int p, int sum) {
			pii res = make_pair(sum, v);
			for(auto& e : g[v]) {
				int to = e.first, cost = e.second;
				if(to == p) continue;
				if(g[to].size() == 1u) {
					continue;
				}
				res = max(res, dia(to, v, sum + cost));
			}
			return res;
		};
		auto v1 = dia(0, -1, 0);
		int x = dia(v1.second, -1, 0).first;
		ans -= dia(v1.second, -1, 0).first;
		for(int i = 1; i < n; ++i) {
			if(g[p[i]].size() == 1u || g[i].size() == 1u) {
				ans += d[i];
			} else {
				ans += 3 * d[i];
			}
		}
		cout << ans << endl;
	}
}


Measured memory_bytes: 3196
function main()

  N = parse(Int,readline())
  
  num1 = 2
  num2 = 1
  tmp = 0
  
  for i in 1:N
    
    tmp = num2
    num2 = num1 + num2
    num1 = tmp
    
  end
  
  println(num1)
  
end

main()

Measured memory_bytes: 109956
#include<bits/stdc++.h>
using namespace std;
#define int long long

signed main() {
  string S,T,U;
  int A,B;
  cin >> S >> T;
  cin >> A >> B;
  cin >> U;
  if(S==U) A--;
  else B--;
  cout << A << " " << B << endl;
}


Measured memory_bytes: 256
n = int(input())
T = list(map(int, input().split()))
m = int(input())
P = [list(map(int, input().split())) for i in range(m)]

for i in range(m):
    tmp = T[:]
    tmp[P[i][0] - 1] = P[i][1]
    print(sum(tmp))

Measured memory_bytes: 3060
#include <vector>
#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <numeric>

using namespace std;
typedef long long li;
typedef pair <li, li> pi;
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)

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

    vector<pi> ins;
    rep(i, n) {
        li x;
        cin >> x;
        ins.emplace_back(x, i);
    }

    sort(ins.begin(), ins.end());

    set<li> used;
    used.insert(-1);
    used.insert(n);

    li ans = 0;
    for (pi p : ins) {
        li x = p.first;
        li i = p.second;

        auto lit = used.lower_bound(i);
        li right = *lit;
        lit--;
        li left = *lit;
        li ld = i - left;
        li rd = right - i;
        ans += x * ld * rd;
        used.insert(i);
    }

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


Measured memory_bytes: 12780
import sys
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value

#N = ii()
#ss = [sys.stdin.readline().rstrip() for i in range(2*N)]
#for i in range(N):
S = input()
T = input()
#S = ss[2*i]
#T = ss[2*i+1]

ls, lt = len(S), len(T)
dp = dp2(0, ls+1, lt+1)
#if S[0] == T[0]:
    #dp[1][1] = 1

for i in range(lt):
    for j in range(ls):
        dp[i][j+1] = max(dp[i][j], dp[i][j+1])
        dp[i+1][j] = max(dp[i][j], dp[i+1][j])
        if S[j] == T[i]:
            dp[i+1][j+1] = dp[i][j] + 1
        else:
            dp[i+1][j+1] = max(dp[i][j+1], dp[i+1][j])

'''
# 貰うDP
dp = dp2(0, ls+1, lt+1)
for i in range(1, lt+1):
    for j in range(1, ls+1):
        if S[j-1] == T[i-1]:
            dp[i][j] = dp[i-1][j-1] + 1
        else:
            dp[i][j] = max(dp[i-1][j], dp[i][j-1])
'''


i, j = lt, ls
ans = ''

while dp[i][j] != 0:
    if dp[i][j] == dp[i-1][j]:
        i -= 1
    elif dp[i][j] == dp[i][j-1]:
        j -= 1
    else:
        ans += S[j-1]
        i -= 1
        j -= 1

print(ans[::-1])


Measured memory_bytes: 115548
use std::io;

fn selection_sort(vec : &mut Vec<u64>) -> usize {
    let len = vec.len();
    let mut count : usize = 0;
    
    for n in 0 .. len {
        let mut min = n;

        for m in n .. len {
            if vec[m] < vec[min] {
                min = m;
            }
        }

        if min != n {
            vec.swap(min, n);
            count += 1;
        }
    }

    return count;
}

fn show_answer(vec : &Vec<u64>, count : usize) {
    println!("{}\n{}",
             vec.iter()
             .map(|x| x.to_string())
             .collect::<Vec<String>>()
             .join(" "),
             count);
}

fn main () {
    let mut s = String::new();
    let stdin = io::stdin();

    let _ = stdin.read_line(&mut s);
    let n = s.trim()
        .parse::<usize>().unwrap_or(0);

    s.clear();

    let _ = stdin.read_line(&mut s);
    let mut vec : Vec<u64> = s.split_whitespace()
        .take(n)
        .map(|s| s.parse().unwrap_or(0)).collect();
    //let mut vec = vec![5u64,3,2,4,1];
    
    //let answer = bubble_sort(&mut vec);
    let answer = selection_sort(&mut vec);

    show_answer(&vec, answer);
    
}



Measured memory_bytes: 5036
N = int(input())

A = list(map(int, input().split()))

ans = 1
keta = 0
if 0 in A:
  print(0)
  exit()

for x in A:
  ans *= x
  keta += len(str(x))
  if ans > 1000000000000000000:
    print(-1)
    exit()

print(ans)


Measured memory_bytes: 21524
#include <stdio.h>
#include <math.h>

static const int N = 10000;

int main(){
  int i, j, k, num[N], count = 0;

  scanf("%d",&i);
  for(j = 0; j < i; j++){
    scanf("%d",&num[j]);
  }
  for(j = 0; j < i; j++){
    if(num[j] == 2){
      count++;
      continue;
    }
    else if(num[j] < 2 || num[j] % 2 == 0) continue;

    k = 3;
    while(k <= sqrt(num[j])){
      if(num[j] % k == 0) break;
      k = k + 2;
    }
    if(k > sqrt(num[j])) count++;
  }

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

Measured memory_bytes: 632
import copy

S = list(input())
ja = 0

sremove = ""
S_tmp = []

for i in range(len(S)):
    for j in range(i,len(S)+1):
        S_tmp = copy.deepcopy(S)

        del S_tmp[i:j]

        if "".join(S_tmp) == "keyence":
            ja = 1
            break

if ja == 1:
    print("YES")

else:
    print("NO")

Measured memory_bytes: 3444
w,h,n = map(int, input().split())
xl, xu, yl, yu = 0, w, 0, h
for _ in range(n):
  x,y,a = map(int,input().split())
  if a == 1:
    xl = max(xl, x)
  elif a == 2:
    xu = min(xu, x)
  elif a == 3:
    yl = max(yl, y)
  else:
    yu = min(yu, y)

if xl >= xu or yl >= yu:
  print(0)
else:
  print((xu-xl)*(yu-yl))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

#define N               200005
#define ff              first
#define ss              second
#define ll              long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<ll,ll>
#define vi              vector<ll>
#define mii             map<ll,ll>
#define pq_max          priority_queue<ll>
#define pq_min          priority_queue<ll,vi,greater<ll> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define inp(arr,n)      for(ll x=0;x<n;x++) cin>>arr[x];
#define w(x)            ll x; cin>>x; while(x--)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;


void fio(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
}

int main(){
    fio();

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

    ll j1, j2, j3, j4;
    j1 = a * c;
    j2 = a * d;
    j3 = b * d;
    j4 = b * c;

    ll res = max(max(j1,j2), max(j3,j4));

    cout<<res;

    return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
	ll n,a[110],sum=0;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
		sum+=a[i];
	}
	ll ans=0,num=a[0];
	for(int i=1;i<n;i++){
		if(abs(sum-a[i]*n)<abs(sum-num*n)){
			ans=i;
			num=a[i];
		}
	}
	cout<<ans<<endl;
	return 0;
}

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

int main()
{
	int n,t=0,h=0;
	cin >> n;
	string str1, str2;
	for(int i = 0; i < n; i++){
		cin >> str1 >> str2;
		if(str1 == str2){
			t += 1;
			h += 1;
		}else if(str1 < str2){
			h += 3;
		}else{
			t += 3;
		}
	}
	cout << t << " " << h << endl;
	return 0;
}


Measured memory_bytes: 3168
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}


struct SCC{
  vector<vector<int> > G,R,T,C;
  vector<int> vs,used,blg;
  SCC(){}
  SCC(int n):G(n),R(n),used(n),blg(n){}

  void add_edge(int u,int v){
    G[u].emplace_back(v);
    R[v].emplace_back(u);
  }

  void dfs(int v){
    used[v]=1;
    for(int u:G[v])
      if(!used[u]) dfs(u);
    vs.emplace_back(v);
  }

  void rdfs(int v,int k){
    used[v]=1;
    blg[v]=k;
    C[k].emplace_back(v);
    for(int u:R[v])
      if(!used[u]) rdfs(u,k);
  }

  int build(){
    int n=G.size();
    for(int v=0;v<n;v++)
      if(!used[v]) dfs(v);

    fill(used.begin(),used.end(),0);
    int k=0;
    for(int i=n-1;i>=0;i--){
      if(!used[vs[i]]){
        T.emplace_back();
        C.emplace_back();
        rdfs(vs[i],k++);
      }
    }
    for(int v=0;v<n;v++)
      for(int u:G[v])
        if(blg[v]!=blg[u])
          T[blg[v]].push_back(blg[u]);

    for(int i=0;i<k;i++){
      sort(T[i].begin(),T[i].end());
      T[i].erase(unique(T[i].begin(),T[i].end()),T[i].end());
    }
    return k;
  }
  int operator[](int k) const{return blg[k];};
};

struct TwoSat{
  int n;
  SCC scc;
  TwoSat(int n):n(n),scc(n*2){}
  int negate(int v){return (n+v)%(n*2);}
  void add_if(int u,int v){
    // u -> v <=> !v -> !u
    scc.add_edge(u,v);
    scc.add_edge(negate(v),negate(u));
  }
  void add_or(int u,int v){
    // u or v <=> !u -> v
    add_if(negate(u),v);
  }
  void add_nand(int u,int v){
    // u nand v <=> u -> !v
    add_if(u,negate(v));
  }
  void set_true(int v){
    //  v <=> !v ->  v
    scc.add_edge(negate(v),v);
  }
  void set_false(int v){
    // !v <=>  v -> !v
    scc.add_edge(v,negate(v));
  }
  vector<int> build(){
    scc.build();
    vector<int> res(n);
    for(int i=0;i<n;i++){
      if(scc[i]==scc[n+i]) return {};
      res[i]=scc[i]>scc[n+i];
    }
    return res;
  }
};

//INSERT ABOVE HERE
signed main(){
  int n,m;
  cin>>n>>m;

  TwoSat G(n);
  for(int i=0;i<m;i++){
    int a,b;
    cin>>a>>b;
    a--;b--;
    G.add_if(a,b);
  }
  G.build();

  for(int i=0;i<n;i++){
    int flg=0;
    for(int j=0;j<n;j++){
      if(G.scc.blg[i]!=G.scc.blg[j]) continue;
      if(flg) cout<<" ";
      flg=1;
      cout<<j+1;
    }
    cout<<endl;
  }

  return 0;
}



Measured memory_bytes: 5696
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main(void){
    int h, w, k, ans = 0;
    cin >> h >> w >> k;
    string c[6];
    for(int i=0;i<h;i++) cin >> c[i];
    for(int i=0;i<(1<<h);i++){
        for(int j=0;j<(1<<w);j++){
            string a[6];
            for(int x=0;x<h;x++){
                a[x] = string(w, '.');
                for(int y=0;y<w;y++) a[x][y] = c[x][y];
            }
            for(int x=0;x<h;x++) if(((i>>x)&1)==1) for(int y=0;y<w;y++) a[x][y] = 'R';
            for(int y=0;y<w;y++) if(((j>>y)&1)==1) for(int x=0;x<h;x++) a[x][y] = 'R';
            int cnt = 0;
            for(int x=0;x<h;x++){
                for(int y=0;y<w;y++){
                    if(a[x][y] == '#') cnt++;
                }
            }
            if(cnt == k) ans++;
        }
    }
    cout << ans << endl;
}


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

#define ll long long
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

using namespace std;
const int N = 2e5 + 5;
int main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int h, a;
    cin >> h >> a;
    cout << (h + a - 1) / a;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <utility>
#include <functional>
#include <cmath>

#define REP(i,x,y) for(int i=(int)(x);i<(int)(y);i++)
#define RREP(i,x,y) for(int i=(int)(x);i>(int)(y);i--)
#define all(x) (x).begin(),(x).end()

#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define eprintf(...) 42
#endif

typedef long long ll;

using namespace std;

string str;

int solve() {
    int ans, half;
    bool flag;
    REP(i, 1, str.length()){
        flag = true;
        if((str.length() - i) % 2 == 1) continue;
        half = (str.length() - i) / 2;
        REP(j, 0, half){
            if(str[j] != str[j + half]){
                flag = false;
                break;
            }
        }
        if(flag){
            ans = str.length() - i;
            break;
        }
    }
    return ans;
}

int main() {
    // to shorten execution time for iostream
    cin.tie(0);
    ios::sync_with_stdio(false);

    cin >> str;
    cout << solve() << "\n";
    return 0;
}


Measured memory_bytes: 256
//Author: Fuadul Hasan(fuadul202@gmail.com)
//BSMRSTU,Gopalganj
#include<bits/stdc++.h>
using namespace std;int tc = 1;
#define happy ios::sync_with_stdio(false);
#define coding  cin.tie(0);
#define F first
#define S second
#define mp make_pair
#define ll long long
#define Pi atan(1)*4
#define pb  push_back
#define vpr vector<pr> 
#define pr pair<int, int> 
#define vi std::vector<int>
#define vll std::vector<ll>
#define YES printf("YES\n");
#define NO printf("NO\n");
#define Yes printf("Yes\n");
#define No printf("No\n");
#define all(n) n.begin(),n.end()
#define point(x) setprecision(x)
#define Test printf("Case %d: ",tc++);
#define Unique(c) (c).resize(unique(all(c))-(c).begin())
#define vout(v) for (auto z: v) cout << z << " "; cout << endl;

const int M = 1e9 + 7;
const ll  Inf = (ll)2e18 + 5;
const int N   = 2e5 + 5;
ll vis[N],res[N];

int solve() 
{
	//happy coding

	 ll n;cin>>n;
	 string s; cin>>s;
	 ll idx = find(all(s),'.') - s.begin();
	 ll a = stoi(s.substr(0,idx));
	 ll b = stoi(s.substr(idx+1));
	 ll mn = a*100+b;
	 cout<<(mn*n)/100<<endl;
	
	return 0;
}
int main(){
	int test = 1;
	//scanf("%d", &test);
	while (test--)solve();return 0;
}



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

int main(){
  string S ; 
  cin >> S ; 
  int N = S.size() ; 
  vector<char> A(N) , B(N) ; 
  int cntA = 0 , cntB = 0  ; 
  
  
  for(int i = 0 ; i < N ; i++){
    if(i % 2 == 0 ){
      A.at(i) = '0' ; 
      B.at(i) = '1' ; 
    }
    else{
      A.at(i) = '1' ; 
      B.at(i) = '0' ;       
    }
    
  }
  
  for(int i = 0 ; i < N ;i++){
    if(S.at(i) == A.at(i) && S.at(i) != B.at(i)){
      cntA++ ; 
    }
    else if(S.at(i) == B.at(i) && S.at(i) != A.at(i)){
      cntB++ ; 
    }
    
  }

  cout << N - max(cntA , cntB) << endl ; 
  
}



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

int main() {
  long H;
  cin>>H;
  vector<long> a(100);
  a[0]=1;
  for(int i=1;i<100;i++){
      a[i]=a[i-1]*2+1;
  }
  int i=0;
  while(H>pow(2,i)){
    i++;
  }
  //cout<<i<<endl;
  if(H==pow(2,i)) cout<<a[i]<<endl;
  else if (H<pow(2,i)) cout<<a[i-1]<<endl;
  }


Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<string.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
long long int mod=1e9+7;
bool debug=false;
typedef long long ll;
class Pair{
	public:
		int a,b;
		vector<int>key;
	Pair(){a=0;b=0;}
	Pair(int _a,int _b){a=_a;b=_b;}
	bool operator <(const Pair&r)const{
		return a<r.a;
	}
	
};
int main(){
	int n,m;
	cin>>n>>m;
	long long int k;
	k=1<<n;
	vector<Pair> c(m);
	int tmp1,tmp2;
	rep(i,m){
		cin>>tmp1>>tmp2;
		c[i].a=tmp1;
		c[i].b=tmp2;
		rep(j,tmp2){
			cin>>tmp1;
			c[i].key.push_back(tmp1-1);
		}
	}
	/*
	sort(c.begin(),c.end());
	rep(i,m){
		cout<<c[i].a<<" "<<c[i].b<<endl;
	}
	*/
	vector<int>dp1(k,mod),dp2(k);
	int sigma;
	dp1[0]=0;
	rep(i,m){
		/*
		cout<<"i="<<i<<endl;
		rep(hoge,k){
			cout<<dp1[hoge]<<endl;
		}
		*/
		rep(j,k){
			dp2[j]=dp1[j];
		}
		sigma=0;
		rep(r,c[i].b){
			sigma+=(1<<c[i].key[r]);
		}
		rep(j,k){
			if(dp2[j|sigma]>dp1[j]+c[i].a){
				dp2[j|sigma]=dp1[j]+c[i].a;
			}
		}
		rep(j,k){
			dp1[j]=dp2[j];
		}
	}
	/*
		cout<<"i="<<m<<endl;
		rep(hoge,k){
			cout<<dp1[hoge]<<endl;
		}
	*/
	if(dp1[k-1]==mod){
		cout<<-1<<endl;
	}else{
		cout<<dp1[k-1]<<endl;
	}


	

	return 0;
}

Measured memory_bytes: 384
/***
  *  بسم الله الرحمن الرحيم
  *
  * author : Ahmed al mohammed
  *
***/

#import "bits/stdc++.h"
#define P push
#define F first
#define S second
#define pb push_back
typedef long long ll;
#define pf push_front
#define PQ priority_queue
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*b)/__gcd(a,b)
#define  lp(a,x) (lower_bound(a.begin(),a.end(),x)-a.begin())
#define  up(a,x) (upper_bound(a.begin(),a.end(),x)-a.begin())
#define hurry ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

using namespace std;

ll pw(ll x ,ll os)
{
    if(os==0)return 1;
    ll z=pw(x,os/2);
    if(os%2)return z*z*x;
    else return z*z;
}

void sieve(){
    ll n=1e6;
    bool a[n+2]={};
    for(int i=2;i*i<=n;i++){
         if(!a[i])
        for(int j=i*i;j<=n;j+=i){
            a[j]=1;
        }
    }
    for(int i=2;i<=n;i++){
        if(a[i]^1)cout<<i<<" ";
    }
}


long long Cnr(long long n,long long r){
    r=min(r,n-r);
    long long ans=1;
    for(long long i=1 ; i<=r ; i++){
        ans*=(n--);
        ans/=i;
    }
    return ans;
}

bool isprime(ll x){
for(ll i=2;i*i<=x;i++){
    if((x%i)==0)return false;
}
return true;
}
ll a[1000002];
void run_case() {
  int d,s,t;
  cin>>d>>t>>s;
  t=t*s;
  if(t>=d)cout<<"Yes";
  else cout<<"No";
   }
int main(){
    hurry
    int tests=1;
  // cin>>tests;
    while(tests--)
         run_case();

    return 0;
}


Measured memory_bytes: 3632
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;

int main(){
	double x[105],y[105],n,sum=0,max;
	cin>>n;
	for(int i=0;i<n;i++)cin>>x[i];
	for(int i=0;i<n;i++)cin>>y[i];
	for(int i=0;i<n;i++){
		sum+=abs(x[i]-y[i]);
	}
	cout<<fixed<<setprecision(8);
	cout<<sum<<endl;
	sum=0;
	for(int i=0;i<n;i++){
		sum+=abs(x[i]-y[i])*abs(x[i]-y[i]);
	}
	cout<<sqrt(sum)<<endl;;
	sum=0;
	for(int i=0;i<n;i++){
		sum+=abs(x[i]-y[i])*abs(x[i]-y[i])*abs(x[i]-y[i]);
	}
	cout<<pow(sum,1.0/3)<<endl;
	sum=0;
	max=abs(x[0]-y[0]);
	for(int i=1;i<n;i++){
		if(abs(x[i]-y[i])>max){
			max=abs(x[i]-y[i]);
		}
	}
	cout<<max<<endl;
}


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

int main() {
  int n;
  cin >> n;
  vector<int> p(n);
  int count = 0;
  for(int i = 0; i < n; i++){
    cin >> p.at(i);
    if(i + 1 != p.at(i)) count++;
  }
  
  if(count > 2) cout << "NO" << endl;
  else cout << "YES" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 1100000000

template <typename T,typename F>
struct segtree{
	F func;
	vector<T> v;
	int n;
	
	T init_value;
	
	segtree(int sz,F f,T iv):func(f){
		init_value = iv;
		n=1;
		while(true){
			if(n>=sz)break;
			n*=2;
		}
		v.resize(2*n,init_value);

		for(int i=n-1;i>=0;i--){
			v[i]=func(v[i<<1],v[(i<<1)+1]);
		}
	}
	
	segtree(vector<T> &x,F f,T iv):func(f){
		init_value = iv;
		n=1;
		while(true){
			if(n>=x.size())break;
			n*=2;
		}
		v.resize(2*n,init_value);
		
		for(int i=0;i<x.size();i++){
			v[n+i]=x[i];
		}
		for(int i=n-1;i>=0;i--){
			v[i]=func(v[i<<1],v[(i<<1)+1]);
		}
	}

	void update(int x,T val){
		x+=n;
		v[x]=val;
		while(x>0){
			x>>=1;
			v[x]=func(v[x<<1],v[(x<<1)+1]);
		}
	}
	
	T query(int l,int r){
		if(l>=r)return init_value;
		l+=n;
		r+=n;
		T res1 = init_value;
		T res2 = init_value;
		while(true){
			if(l&1){
				res1=func(res1,v[l++]);
			}
			if(r&1){
				res2=func(v[--r],res2);
			}
			if(l>=r)break;
			l>>=1;r>>=1;
		}
		return func(res1,res2);
	}
	
	void show(){
		int n = 1;
		for(int i=1;i<v.size();i++){
			for(int j=0;j<n;j++){
				if(j!=0)cout<<' ';
				cout<<v[i+j];
			}
			cout<<endl;
			i+=n-1;
			n*=2;
		}
	}
	
};

vector<vector<int>> E(1,vector<int>());
map<int,pair<int,int>> mp;

void dfs(auto &seg,int l,int r,int p){
	if(l>=r)return;
	auto L = seg[l&1].query(l,r);
	auto R = seg[(l&1)^1].query(L.second,r);
	int t = E.size();
	E[p].push_back(t);
	mp[t] = {L.first,R.first};
	E.push_back(vector<int>());
	seg[l&1].update(L.second,{Inf,Inf});
	seg[(l&1)^1].update(R.second,{Inf,Inf});
	dfs(seg,l,L.second,t);
	dfs(seg,L.second+1,R.second,t);
	dfs(seg,R.second+1,r,t);
}

int main(){
	
	int N;
	cin>>N;
	
	auto f = [](pair<int,int> a,pair<int,int> b){
		return min(a,b);
	};
	
	vector<segtree<pair<int,int>,decltype(f)>> seg(2,segtree<pair<int,int>,decltype(f)>(N,f,{Inf,Inf}));
	
	vector<int> P(N);
	for(int i=0;i<N;i++){
		cin>>P[i];
		P[i]--;
		seg[i&1].update(i,{P[i],i});
	}
	
	dfs(seg,0,N,0);
	
	priority_queue<pair<pair<int,int>,int>,vector<pair<pair<int,int>,int>>,greater<pair<pair<int,int>,int>>> Q;
	Q.emplace(mp[1],1);
	vector<int> ans;
	while(Q.size()!=0){
		auto t = Q.top();
		Q.pop();
		ans.push_back(t.first.first);
		ans.push_back(t.first.second);
		for(int i=0;i<E[t.second].size();i++){
			int to = E[t.second][i];
			Q.emplace(mp[to],to);
		}
	}
	
	for(int i=0;i<ans.size();i++){
		if(i!=0)cout<<' ';
		cout<<ans[i]+1;
	}
	cout<<endl;
	
	return 0;
}

Measured memory_bytes: 61948
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
import itertools
input = sys.stdin.readline

##### リストの 二分木検索 #####
# bisect_left(lists, 3)
# bisect_right(lists, 3)

##### プライオリティキュー #####
# heapq.heapify(a) #リストaのheap化
# heapq.heappush(a,x) #heap化されたリストaに要素xを追加
# heapq.heappop(a) #heap化されたリストaから最小値を削除＆その最小値を出力

# heapq.heappush(a, -x) #最大値を取り出す時は、pushする時にマイナスにして入れよう
# heapq.heappop(a) * (-1) #取り出す時は、-1を掛けて取り出すこと

##### タプルリストのソート #####
# sorted(ans) #(a, b) -> 1st : aの昇順, 2nd : bの昇順
# sorted(SP, key=lambda x:(x[0],-x[1])) #(a, b) -> 1st : aの昇順, 2nd : bの降順
# sorted(SP, key=lambda x:(-x[0],x[1])) #(a, b) -> 1st : aの降順, 2nd : bの昇順
# sorted(SP, key=lambda x:(-x[0],-x[1])) #(a, b) -> 1st : aの降順, 2nd : bの降順

# sorted(SP, key=lambda x:(x[1])) #(a, b) -> 1st : bの昇順
# sorted(SP, key=lambda x:(-x[1])) #(a, b) -> 1st : bの降順

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))

def main():
	N = inputInt()
	P = inputList()

	ans = 0
	mmin = 0
	for i,val in enumerate(P):
		if i == 0:
			ans += 1
			mmin = val
			continue

		if val <= mmin:
			ans += 1
			mmin = val
			#print("{} {} {}".format(i,val,mmin))
		else:
			pass

	print(ans)



if __name__ == "__main__":
	main()


Measured memory_bytes: 71816
N , M ,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
if sum(A)+sum(B) <= K:
  print(N+M)
else:
  k = 0
  SB = 0
  while SB < K and k <M:
    SB += B[k]
    k += 1
  iM = k  
  k = 0
  SA = 0
  while SA < K and k < N:
    SA += A[k]
    k += 1
  if SA > K:
    k -=1
    SA -= A[k]
  km = k
  i = 0
  while i <iM:
    if SA + B[i] < K:
      SA += B[i]
      i += 1
      if km < i + k:
        km = i + k
    elif SA + B[i] == K:
      SA +=B[i]
      i += 1
      if km < i + k:
        km = i + k
    else:
      SA -= A[k - 1]
      k -= 1
  #print(SA)  
  print(km)    
    

Measured memory_bytes: 40760
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(v) v.begin(),v.end()
#define len(x) (ll)(x).length()
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int INF=1e9;
const int di[] = {-1,0,1,0};
const int dj[] = {0,-1,0,1};

int a[4];

int main() {
  string s;
  cin>>s;
  rep(i,4) a[i]=s[i]-'0';
  for(int x=0;x<8;x++){
    int sum=a[0];
    string s;
    s+='0'+a[0];
    rep(i,3){
      if(x&(1<<i)){
        sum+=a[i+1];
        s+='+';
        s+='0'+a[i+1];
      }else{
        sum-=a[i+1];
        s+='-';
        s+='0'+a[i+1];
      }
    }
    if(sum==7){
      cout<<s<<"=7"<<endl;
      return 0;
    }
  }
}

Measured memory_bytes: 3636
// -*- mode:c++; coding:utf-8; c-basic-offset:2; -*-
// ALDS1_9_C: Priority Queue

#include <algorithm>
#include <cstdio>
#include <vector>

class PriorityQueue {
  std::vector<int> v_;

public:
  void insert(int i)
  {
    v_.push_back(i);
    upto(v_.size()-1);
  }

  int extract_max()
  {
    const auto max = v_.front();
    v_[0] = v_.back();
    v_.pop_back();
    downto(0);
    return max;
  }
  
private:
  void upto(int k)
  {
    while (k > 0) {
      auto p = (k-1)/2;
      if (v_[p] > v_[k]) {
        break;
      }
      std::swap(v_[p], v_[k]);
      k = p;
    }
  }

  void downto(int k)
  {
    const auto n = static_cast<int>(v_.size());
    while (k < n/2) {
      auto c = 2*k + 1; // left
      if (c+1 < n && v_[c] < v_[c+1]) {
        ++c; // right
      }
      if (v_[c] < v_[k]) {
        break;
      }
      std::swap(v_[k], v_[c]);
      k = c;
    }
  }
};

int main()
{
  PriorityQueue pq;
  char buf[7+1]; // "extract".size() + 1('\0')
  int k;
  while (true) {
    std::scanf("%7s", buf);
    if (buf[0] == 'i') { // insert k
      std::scanf("%d", &k);
      pq.insert(k);
    } else if (buf[1] == 'x') { // extract
      auto max = pq.extract_max();
      std::printf("%d\n", max);
    } else { // end
      break;
    }
  }
}

// eof

Measured memory_bytes: 6428
#include <iostream>

using namespace std;


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

    int c = 0;
    int ans;
    for (int i = 100; i >= 1; i--) {
        if (a % i == 0 && b % i == 0) {
            c++;
            if (c == k) {
                ans = i;
                break;
            }
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <cstdlib>
#include <cstdio>
#include <string>
#include <cstring>
#include <cassert>
#include <utility>
#include <iomanip>
#include <chrono>
#include <random>
#include <bitset>

using namespace std;

#define sz(x) (int) x.size()
#define unique(x) x.erase(unique(x.begin(), x.end()), x.end())
#define all(a) a.begin(), a.end()
#define sqr(x) ((x) * (x)) 
#define y1 aksjdaskdjksjfksdjf
#define left kdnvldvoiwejifejg
#define right lkdsjflksdjfdjfk
#define prev asdasfsadjkjsdfjs
#define tm aklsjdasjdasjdkdjjf
#define lcm hddalkwjeidjjhasda
#define random_shuffle asdasdd

const int MAXN = 105;

int a, b;
int d[MAXN][MAXN];
int f[MAXN][MAXN];
vector < pair< pair<int, int>, int > > ans;

void addEdge(int from, int to, int w) {
  ans.push_back({{from, to}, w});
}

int main() { 

  scanf("%d %d", &a, &b);
  for (int i = 0; i < a; i++) {
    for (int j = 0; j < b; j++) {
      scanf("%d", &d[i][j]);
    }
  }

  for (int i = 0; i < a; i++) {
    for (int j = 0; j < b; j++) {
      for (int x = 0; x <= 100; x++) {
        for (int y = 0; y <= 100; y++) {
          int cur = (i + 1) * x + (j + 1) * y;
          f[x][y] = max(f[x][y], d[i][j] - cur);
        }
      }
    }
  }

  for (int i = 1; i <= a; i++) {
    for (int j = 1; j <= b; j++) {
      int dist = 1e9;
      for (int x = 0; x <= 100; x++) {
        for (int y = 0; y <= 100; y++) {
          dist = min(dist, i * x + j * y + f[x][y]);
        }
      }
      if (dist != d[i - 1][j - 1]) {
        puts("Impossible");
        return 0;
      }
    }
  }

  puts("Possible");
  
  int n = 2;
  addEdge(1, 2, 0);
  for (int i = 1; i <= 100; i++) {
    n++;
    addEdge(n - 1, n, -1);
  }

  n++;
  for (int i = 1; i <= 100; i++) {
    n++;
    addEdge(n - 1, n, -2);
  }
  n++;
  addEdge(n - 1, n, 0);

  for (int x = 0; x <= 100; x++) {
    for (int y = 0; y <= 100; y++) {
      addEdge(2 + x, n - 1 - y, f[x][y]);
    }
  }

  printf("%d %d\n", n, sz(ans));
  for (int i = 0; i < sz(ans); i++) {
    printf("%d %d ", ans[i].first.first, ans[i].first.second);
    if (ans[i].second >= 0) {
      printf("%d\n", ans[i].second);
    } else if (ans[i].second == -1) {
      printf("X\n");
    } else {
      printf("Y\n");
    }
  }
  printf("%d %d\n", 1, n);

  return 0;
}


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

using namespace std;


int main()
{
    int N, tmp, count = 0;
    bool flag;
    vector<int> vec;

    cin >> N;

    for (int i = 0; i < N; i++) {
        cin >> tmp;
        flag = true;
        vec.push_back(tmp);
        for (int j = 0; j < i; j++) {
            if (vec[j] > tmp) {
                flag = false;
            }
        }
        if (flag == true) {
            count++;
        }
    }

    cout << count << endl;
   

    return 0;   
}

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

using _i64 = int64_t;
using _u64 = uint64_t;
using _f64 = double;

#define _for(i, start, end) for(_i64 i = (_i64)start; i < (_i64)end; ++i)
#define _rep(i, number) _for(i, 0, number)
#define _foreach(e, data) for(auto& e : data)
#define _all(data) data.begin(), data.end()

template<typename type>
_i64 _size(const type& data) { return static_cast<_i64>(data.size()); }
template<typename type, size_t size>
_i64 _size(const type (&)[size]) { return static_cast<_i64>(size); }

enum _flag : bool { able = true, disable = false };

struct _time {
    _time(_flag flag) { check = flag; if(!check) { return; } gettime(start); }
    ~_time() {
        if(!check) { return; }; gettime(end);
        _i64 elapse = chrono::duration_cast<chrono::milliseconds>(end - start).count();
        cout << endl << "Time: " << elapse << " ms" << endl;
    }
    private:
    using _timer = chrono::time_point<chrono::system_clock>;
    _timer start, end; bool check;
    void gettime(_timer& time) { time = chrono::system_clock::now(); }
};

struct _ini { _ini() { ios::sync_with_stdio(false); cin.tie(nullptr); } } _ini;

int main() {
    {
        _time time(disable);
        _i64 n; _i64 n_tarou = 0; _i64 n_hanako = 0; string c_tarou, c_hanako;
        cin >> n;
        _rep(i, n) {
            cin >> c_tarou >> c_hanako;
            if(c_tarou > c_hanako) { n_tarou += 3; }
            else if(c_tarou < c_hanako) { n_hanako += 3; }
            else { n_tarou++; n_hanako++; }
        }
        cout << n_tarou << " " << n_hanako << endl;
    }
    return 0;
}


Measured memory_bytes: 3232
#include <stdio.h>

int search(int A[], int n, int key) {
  int i = 0;
  A[n] = key;
  while (A[i] != key) i++;
  return i != n;
}

int main() {
  int i, n, A[10000 + 1], q, key, sum = 0;

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

  scanf("%d", &q);
  for (i = 0; i < q; i++) {
    scanf("%d", &key);
    if (search(A, n, key)) sum++;
  }
  printf("%d\n", sum);

  return 0;
}


Measured memory_bytes: 2112
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cout<<*i<<" "; cout<<endl; }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
string alphabet[] = {"ld", "mb", "mp", "nc", "nd", "ng", "nt", "nw", "ps", "qu", "cw", "ts"};
int toi(string s){
  if(s.size()==1){
    return s[0] -  'a';
  }else{
    REP(i,12)if(alphabet[i]==s)return 26 + i;
  }
  return -1;
}
string tos(int n){
  if(n < 0 || n >= 38) return "";
  string s = " ";
  if(n < 26) s[0] = 'a' + n;
  else s = alphabet[n-26];
  return s;
}

int main(){
  int n;
  cin>>n; cin.ignore();
  int cnt[38][38] = {};
  string s;
  while(getline(cin, s)){
    stringstream ss(s);
    string word;
    while(ss>>word){
      string prev = "";
      REP(i,word.size()){
        string s = "";
        s += word[i];
        if(i+1 < word.size() && toi(s + word[i+1]) != -1){
          s += word[++i];
        }
        if(prev != ""){
          cnt[toi(prev)][toi(s)]++;
        }
        prev = s;
      }
    }
  }
  REP(i,38){
    string from = tos(i);
    string to = "";
    int maxn = -1;
    REP(j,38)if(cnt[i][j]>maxn){
      to = tos(j);
      maxn = cnt[i][j];
    }
    printf("%s %s %d\n",from.c_str(), to.c_str(), maxn);
  }
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace  std;
template<class TH> void _dbg(const char *sdbg, TH h){ cerr<<sdbg<<'='<<h<<endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')cerr<<*sdbg++;
  cerr<<'='<<h<<','; _dbg(sdbg+1, a...);
}

template<class T> ostream &operator<<(ostream& os, vector<T> V) {
  os << "["; for (auto vv : V) os << vv << ","; return os << "]";
}
template<class L, class R> ostream &operator<<(ostream &os, pair<L,R> P) {
  return os << "(" << P.first << "," << P.second << ")";
}
#ifdef LOCAL
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) 42
#endif

  
using ll = long long;
using ld = long double;
using uint = unsigned int;
using ull = unsigned long long;
template<typename T>
using pair2 = pair<T, T>;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vii = vector<pii>;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define re(n) for (int i = 0; i < n; ++i)
#define rep(i,a,b) for (int i = a; i < b; ++i)
#define eb emplace_back

//OutPut
#define ps(x) cout << x << endl;
#define ps_end(x) {ps(x); return;}


const int md = 1e9 + 7; //998244353 ;
const int dir[4][2] = {{-1,0}, {1, 0}, {0, -1}, {0, 1}};
template<class T> bool ckmin(T& a, const T& b) { 
  return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { 
  return a < b ? a = b, 1 : 0; }
ll pw(auto x, auto y) {  ll s = 1; while(y) { if (y & 1) s = s * x % md; x= 1LL * x * x % md; y /= 2; } return s;}

const int maxn = 1e6 + 10;

int n, m, nq, nk;
string str;

void task() {
  cin >> n;
  vi a(n), b(n);
  re(n) cin >> a[i] >> b[i];
  re(n - 2) {
    if (a[i] == b[i] && a[i+1] == b[i+1] && a[i+2] == b[i+2]) ps_end("Yes");
  }
  ps("No");
  //Read the stuff at the bottom
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout<<fixed<<setprecision(20);
  int T = 1;
  //cin >> T;
  for (int ti = 1; ti <= T; ++ti) {
    task();
  }
  return 0;
}

/* stuff you should look for
  * int overflow, array bounds
  * special cases (n=1?)
  * do smth instead of nothing and stay organized
  * write down
*/


Measured memory_bytes: 3644
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>

int main()
{
  int i,k;
  char str[200];
  scanf("%d",&k);
  scanf("%s",&str);
  if(strlen(str)<=k) printf("%s",str);
  else  
    {
	for(i=0;i<k;i++)
    	printf("%c",str[i]); 
	printf("...");
    }
  return 0;
}

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

int main() {
  int a, b, c, d, e, f;
  cin >> a >> b >> c >> d >> e >> f;
  vector<pair<int,int>> w, s;
  for (int i = 0; i <= 30; i++) {
    for (int j = 0; j <= 30; j++) {
      if (a * i * 100 + b * j * 100 <= f)
        w.push_back({i,j});
    }
  }
  for (int i = 0; i <= 3000; i++) {
    for (int j = 0; j <= 3000; j++) {
      if (i * c + j * d <= f)
        s.push_back({i,j});
    }
  }
  double m = 0;
  int aa = 0, bb = 0;
  for (int i = 0; i < w.size(); i++) {
    for (int j = 0; j < s.size(); j++) {
      int ww = a * w[i].first * 100 + b * w[i].second * 100;
      int ss = s[j].first * c + s[j].second * d;
      if (ww + ss == 0) continue;
      if (ss * 100 > ww * e) continue;
      if (ww + ss > f) continue;
      if ((double)(100 * ss) / (ww + ss) >= m) {
        m = (double)(100 * ss) / (ww + ss);
        aa = ww + ss;
        bb = ss;
      }
    }
  }
  cout << aa << " " << bb;
  return 0;
}


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

int main() {
	int A,B,SUM,DIF,MUL ;
	cin>>A>>B;
	SUM=A+B;
	DIF=A-B;
	MUL=A*B;
	if(SUM>=DIF && SUM>=MUL) {
			cout<<SUM;
		}
	else if (DIF>=MUL){
		cout<<DIF; }
	else cout<<MUL;
	
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
#include<stack>
#include<cmath>
#include<iomanip>
#include<set>
#include<numeric>
#include<sstream>
#include<random>
#include<cassert>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
using pii = pair<int, int>;
const int inf = 1e9 + 7;
int dy[] = {0, 0, -1, 1, -1, 1, -1, 1};
int dx[] = {1, -1, 0, 0, -1, 1, 1, -1};
#define ceil(a, b) a / b + !!(a % b)

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    int a[n]; rep(i, n) cin >> a[i];
    sort(a, a + n);
    int l = a[0];
    rrep(i, 1, n) {
        //cout << l << " " << a[i] << endl;
        if (abs(l - (double)a[n - 1] / 2) > abs(a[i] - (double)a[n - 1] / 2)) {
            l = a[i];
        }
    }
    cout << a[n - 1] << " " << l << endl;
}



Measured memory_bytes: 640
class Solver(object):
    def __init__(self):
        self.n, self.k = list(map(int, input().split(" ")))

    def solve(self):
        total = 0
        total += self.case_zero()
        if self.k % 2 == 0:  # k is even
            total += self.case_k2()
        print(total)

    def case_zero(self):
        multiples = self.n // self.k
        return multiples ** 3
    
    def case_k2(self):
        multiples = 0
        for i in range(1, self.n+1):  # i = 1 .. n
            if i % self.k == self.k/2:
                multiples += 1
        return multiples ** 3


if __name__ == "__main__":
    s = Solver()
    s.solve()

Measured memory_bytes: 3064
import java.util.*;

public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int v = scan.nextInt();
		int e = scan.nextInt();
		Map<Integer, List<Integer>> adj_list = new HashMap<Integer, List<Integer>>();

		while ( e-- > 0 ){
			int x = scan.nextInt();
			int y = scan.nextInt();
			if ( !adj_list.containsKey(x) ) adj_list.put(x, new ArrayList<Integer>());
			List<Integer> cur_neigh = adj_list.get(x);
			cur_neigh.add(y);
		}
		//at this point the adjascency list is built
		boolean iscycle = graph_iscycle(adj_list, v);
		if ( iscycle ) System.out.println("1");
		else System.out.println("0");
	}

	public static boolean graph_iscycle(Map<Integer, List<Integer>> adj_list, int v_size){

		boolean visited[] = new boolean[v_size];
		boolean in_visit[] = new boolean[v_size];

		for ( int v : adj_list.keySet()){
			if ( !visited[v] ){
				boolean res = check_cycle_util(v, visited, in_visit, adj_list);
				if ( res ) return true;
			}
		}
		return false;
	}

	//returns true if the graph contains a cycle
	private static boolean check_cycle_util(int v, boolean visited[], boolean in_visit[], Map<Integer, List<Integer>> adj_list){		
		visited[v] = true;
		in_visit[v] = true;

		if ( adj_list.containsKey(v) ){
			for ( int neigh : adj_list.get(v) ){
				if ( !visited[neigh] ){
					boolean res = check_cycle_util(neigh, visited, in_visit, adj_list);
					if ( res ) return true;
				}
				else if ( in_visit[neigh] ) return true;
			}			
		}

		in_visit[v] = false;
		return false;
	}
}

Measured memory_bytes: 31664
#include<iostream>
using namespace std;
int main(){
  int n;
  while(cin >>n,n){
    int num[5000],m[5001],ans;
    for(int i=0,a; i<n; i++) cin >>num[i];
    for(int i=1; i<n; i++) num[i]+=num[i-1];
    m[0] = 0;
    for(int i=0; i<n; i++){
      if(num[i]<m[i]) m[i+1] = num[i];
      else m[i+1] = m[i]; 
    }
    ans = num[0];
    for(int i=0; i<n; i++) if(ans < num[i]-m[i]) ans = num[i]-m[i];
    cout <<ans<<endl;
  }
  return 0;
}

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

string a;
char j,k,e,n;

int main(void)
{
    cin >> a;
    j = a[0];
    k = a[1];
    e = a[2];
    n = a[3];
    if(j==k && k==e || k==e && e==n)
        cout << "Yes";
    else
        cout << "No";
    return 0;
}


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

#define upper 9

using namespace std;

int main(void){
	int n = 0;
	vector<int> vec;
	while(cin >> n){
		int count = 0;
		for(int a=0; a<=upper; ++a){
			for(int b=0; b<=upper; ++b){
				for(int c=0; c<=upper; ++c){
					for(int d=0; d<=upper; ++d){
						if ((a+b+c+d) == n){
							++count;
						}
					}
				}
			}
		}
		vec.push_back(count);
	}
	vector<int>::iterator it = vec.begin();
	while(it != vec.end()){
		cout << *it << endl;
		++it;
	}
	return 0;
}

Measured memory_bytes: 1216
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
using namespace std;
int main()
{
	int n;
	scanf("%d", &n);
	n %= 26;
	string s;
	cin >> s;
	int len = s.length();
	for(int i = 0; i < len; i++){
		printf("%c", (s[i] - 65 + n) % 26 + 65);
	}
	return 0;
}

Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inm = lambda: map(int, sys.stdin.readline().split())
inl = lambda: list(inm())
ins = lambda: sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw))

N, M = inm()


def solve():
    r = [False] * N
    r[0] = True
    cnt = [1] * N
    for i in range(M):
        x, y = inm()
        x -= 1
        y -= 1
        if r[x]:
            r[y] = True
        cnt[x] -= 1
        cnt[y] += 1
        if cnt[x] == 0:
            r[x] = False

    return sum(r)


print(solve())


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

using namespace std;
#define deb(x) cout << #x << ": " << x << endl
#define fo(i, n) for (ll i = 0; i < n; i++)
#define fkn(i, k, n) for (i = k; i < n; i++)
#define ll long long
#define F first;
#define S second;
#define PB(x) push_back(x);
#define MP(x,y) make_pair(x,y);
typedef vector<ll> vll;

bool powerOfTwo(ll x)
{
    return !(x & (x - 1));
}


int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll n,k;
    cin>>n>>k;
    vector<ll> v(n);
    ll sum=0;
    fo(i,n) cin>>v[i];
    sort(v.begin(),v.end());
    for(int i=0;i<k;i++)
    {
        sum+=v[i];
    }
    cout<<sum;
    
}




Measured memory_bytes: 3656
import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) throws IOException {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        InputReader.OutputWriter out = new InputReader.OutputWriter(outputStream);


        int l = in.nextInt();
        int r = in.nextInt();
        long min = Long.MAX_VALUE;
        HashSet<Integer> set = new HashSet<>();
        for (int i = l; i <=r; i++) {
            set.add(i%2019);
            if(set.size() == 2019) break;
        }
        int [] a = new int[set.size()];
        int index = 0;
        for(int i : set) {
            a[index++] = i;
        }
        for (int i = 0; i < a.length; i++) {
            for (int j = i+1; j < a.length; j++) {
                min = Math.min(min,(a[i]*a[j])%2019);
            }
        }
        out.println(min);

       /* min = Integer.MAX_VALUE;
        for (long i = l; i <=r; i++) {
            for (long j = i+1; j <=r; j++) {
                min = Math.min(min,(i*j)%2019);
            }
        }
        out.println(min);*/
        out.flush();
    }
    static double distance(int [] a, int [] b) {
        double d = 0;
        for (int i = 0; i < a.length; i++) {
            int temp = (a[i]-b[i])*(a[i]-b[i]);
            d+=temp;
        }
        return Math.sqrt(d);
    }
    static boolean isInteger(double d) {
        return d == (int)d;
    }
    static int f(LinkedList<Integer> q) {
        int size = q.size();
        int count = 0;
        size/=2;
        while (size-->0) {
            int first = q.pollFirst();
            int second = q.pollFirst();
            if(first+second>=10) count++;
            int newValue = (first+second)%10;
            q.addLast(newValue);
        }
        return count;
    }
}

class InputReader extends BufferedReader {
    StringTokenizer tokenizer;

    public InputReader(InputStream inputStream) {
        super(new InputStreamReader(inputStream), 32768);
    }

    public InputReader(String filename) {
        super(new InputStreamReader(Thread.currentThread().getContextClassLoader().getResourceAsStream(filename)));
    }

    public String next() {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(readLine());
            } catch (IOException e) {
                throw new RuntimeException();
            }
        }
        return tokenizer.nextToken();
    }

    public Integer nextInt() {
        return Integer.valueOf(next());
    }
    public Long nextLong() {return  Long.valueOf(next());}

    static class OutputWriter extends PrintWriter {
        public OutputWriter(OutputStream outputStream) {
            super(outputStream);
        }

        public OutputWriter(Writer writer) {
            super(writer);
        }

        public OutputWriter(String filename) throws FileNotFoundException {
            super(filename);
        }

        public void close() {
            super.close();
        }
    }
}

Measured memory_bytes: 21844
fun main(args: Array<String>) {
    val (N, C) = readLine()!!.split(" ").map { it.toInt() }
    val maxT = 100000
    val onAirTVCounts = Array(C + 1, { IntArray(maxT + 1) })
    onAirTVCounts.forEach {
        it.fill(0)
    }
    // This is not correct
    // See http://wk1080id.hatenablog.com/entry/2018/01/17/020356
    val tvInfo = mutableListOf<Triple<Int, Int, Int>>()
    (1..N).forEach {
        val (s, t, c) = readLine()!!.split(" ").map { it.toInt() }
        tvInfo.add(Triple(s, t, c))
    }

    val global = IntArray(maxT + 1)
    global.fill(0)
    (1 .. C).forEach {currentC ->
        // On each chaneel, imos method
        tvInfo.forEach {
            val (s, t, c) = it
            if (c == currentC) {
                onAirTVCounts[currentC][s - 1]++
                onAirTVCounts[currentC][t]--
            }
        }

        (0 until maxT).forEach {
            onAirTVCounts[currentC][it+1] += onAirTVCounts[currentC][it]
        }
        onAirTVCounts[currentC].forEachIndexed { index, value ->
            // consider as 1 tv show if it continuous
            if (value > 0) {
                global[index]++
            }
        }
    }
    println(global.max()!!)
}


Measured memory_bytes: 98008
#!/usr/bin python3
# -*- coding: utf-8 -*-

import sys
input = sys.stdin.readline
from collections import deque

def main():

    K = int(input())

    q = deque([])   # キュー
    for i in range(1,10):
        q.append(i)
    k=0
    while k<K:
        p = q.popleft()     # キュー取りだし（先頭）
        k+=1
        x=p%10
        if x-1>=0:
            q.append(p*10+x-1)
        q.append(p*10+x)
        if x+1<=9:
            q.append(p*10+x+1)
    print(p)

if __name__ == '__main__':
    main()

Measured memory_bytes: 11944
#include<stdio.h>
int main() {
	int a=0, b=0, c=0;
	int work;
	scanf("%d %d %d", &a, &b, &c);
	if (a > b) {
		work = a;
		a = b;
		b = work;
	}
	if (a > c) {
		work = a;
		a = c;
		c = work;
	}
	if (b > c) {
		work = b;
		b = c;
		c = work;
	}
	printf("%d %d %d\n", a, b, c);
	return 0;
}


Measured memory_bytes: 2056