akhauriyash/Code-Regression huggingface dataset:
<?php
solve1();


// 自力解
function solve1(){
	$n = (int)trim(fgets(STDIN));

	$list = [];
	for ($i=0; $i < $n; $i++) { 
		$node = new BTreeNode($i);
		$list[$node->getId()] = $node;
	}
	for ($i=0; $i < $n; $i++) { 
		$input = explode(' ', trim(fgets(STDIN)));
		$id = (int)$input[0];
		$list[$id]->setLeft((int)$input[1]);
		if (isset($list[(int)$input[1]])) {
			$list[(int)$input[1]]->setParentId($id);
		}
		$list[$id]->setRight((int)$input[2]);
		if (isset($list[(int)$input[2]])) {
			$list[(int)$input[2]]->setParentId($id);
		}
	}
	for ($i=0; $i < $n; $i++) { 
		if ($list[$i]->getParentId() === -1) {
			// root
			$curId = $i;
			break;
		}
	}
	// objectは参照渡しされるので、$listを参照渡しにしなくても$list内のobjectは関数内部で変更される！！
	dfs($list, $curId, 0);

	foreach ($list as $v) {
		$type = 'leaf';
		if ($v->getParentId() === -1) {
			$type = 'root';
		}elseif ($v->hasChild()) {
			$type = 'internal node';
		}
		$parent = $v->getParentId();
		$sibling = -1;
		if ($parent !== -1) {
			$sibling = $list[$parent]->getAnotherChild($v->getId());
		}
		echo 'node ' . $v->getId() .': parent = ' . $v->getParentId() .
			', sibling = ' . $sibling . ', degree = ' . count($v->getChildren()) . 
			', depth = ' . $v->getDepth() . ', height = ' . $v->getHeight() . ', ' . $type . PHP_EOL;
	}
}

function dfs($list, $id, $depth){
	$list[$id]->setDepth($depth);
	++$depth;
	$height = 0;
	if($list[$id]->hasChild()){
		$children = $list[$id]->getChildren();
		foreach ($children as $c) {
			$h = dfs($list, $c, $depth);
			$height = max($height, $h);
		}
	}
	$list[$id]->setHeight($height);
	return ++$height;
}

class BTreeNode
{
	private $id;
	private $depth = 0;
	private $height = 0;
	private $parent_id = -1;
	private $left = -1;
	private $right = -1;

	function __construct($id)
	{
		$this->id = $id;
	}
	function setParentId($p_id){
		$this->parent_id = $p_id;
	}
	function setLeft($l_id){
		$this->left = $l_id;
	}
	function setRight($r_id){
		$this->right = $r_id;
	}
	function getId(){
		return $this->id;
	}
	function getParentId(){
		return $this->parent_id;
	}
	function getLeft(){
		return $this->left;
	}
	function getRight(){
		return $this->right;
	}
	function hasChild(){
		return ($this->left !== -1) || ($this->right !== -1);
	}
	function getChildren(){
		$children = [];
		if ($this->hasLeft()) {
			$children[] = $this->left;
		}
		if ($this->hasRight()) {
			$children[] = $this->right;
		}
		return $children;
	}
	function getAnotherChild($c_id){
		$c = -1;
		if ($this->getLeft() === $c_id) {
			$c = $this->getRight();
		}elseif ($this->getRight() === $c_id) {
			$c = $this->getLeft();
		}
		return $c;
	}
	function hasLeft(){
		return $this->left !== -1;
	}
	function hasRight(){
		return $this->right !== -1;
	}
	function setDepth($d){
		$this->depth = $d;
	}
	function addDepth(){
		$this->depth += 1;
	}
	function getDepth(){
		return $this->depth;
	}
	function setHeight($h){
		$this->height = $h;
	}
	function getHeight(){
		return $this->height;
	}
}


Measured memory_bytes: 9460
#pragma region Template
#include <bits/stdc++.h>
using namespace std;
struct ios_accelerate { ios_accelerate() { ios::sync_with_stdio(false); cin.tie(nullptr); } } CALL;

#define REP(i, n) for(int i = 0; i < n; i++)
#define RNG(i, a, b) for(int i = a; i < b; i++)
#define RBF(i, v) for(auto& i : v)
#define ALL(x) x.begin(), x.end()

using LL = long long;
using UL = unsigned long;
using ULL = unsigned long long;
template<typename T> using V = vector<T>;
template<typename T> using VV = vector<vector<T>>;
template<typename T> using P = pair<T, T>;
template<typename T> using VP = vector<pair<T, T>>;

const double PI = 3.141592653589793;
const int MOD = 1000000007;
const LL INF64 = static_cast<LL>(1e18) + 2;
const int INF = static_cast<int>(1e9) + 2;

template<typename T> inline void upsort(vector<T>& x) { sort(x.begin(), x.end()); }
template<typename T> inline void downsort(vector<T>& x) { sort(x.begin(), x.end(), greater<T>()); }
template<typename T> inline void col(T x) { cout << x << '\n'; }
template<> inline void col(double x) { cout << fixed << setprecision(12) << x << '\n'; }
#pragma endregion

signed main() {
    int N, Y;
    cin >> N >> Y;

    int z = -1;
    for (int x = 0; x <= N; x++) {
        for (int y = 0; y <= N; y++) {
            z = (Y - 10000 * x - 5000 * y) / 1000;
            if (z < 0) continue;
            if (x + y + z == N) {
                cout << x << ' ' << y << ' ' << z << endl;
                return 0;
            }
        }
    }

    cout << "-1 -1 -1\n";
    return 0;
}


Measured memory_bytes: 3612
#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 ALL(v) v.begin(), v.end()
#define downque(que) priority_queue<ll> que;
#define upque(que) priority_queue<ll, vector<int>, greater<int>> que;
typedef long long ll;
typedef vector<vector<int>> Matrix;
const int MOD = 1e9 + 7;
const int MAX = 1e7;
const int INF = numeric_limits<int>::max();




int main(){
  int n,res=0; cin >> n;

  int a[2][n];
  REP(i, 2)
      REP(j, n) cin >> a[i][j];

  REP(i,n)//いつ下の段に行くかで全探索
  {
    int sum = 0;
    REP(j,n){
      if(j<=i)
        sum += a[0][j];
      if(j>=i)
        sum += a[1][j];

    }
    if (res < sum)
      res = sum;
  }
  cout << res << endl;
  }

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val t = readLine()!!.map { it - '0' }
    for (i in 0 until (1 shl 3)) {
        var sum = t[0]
        var ans = "" + t[0]
        for (j in 0 until 3) {
            if (i and (1 shl j) > 0) {
                sum -= t[j + 1]
                ans += "-" + t[j + 1]
            } else {
                sum += t[j + 1]
                ans += "+" + t[j + 1]
            }
        }
        if (sum == 7) {
            println("$ans=7")
            return
        }
    }
}

Measured memory_bytes: 33812
import java.util.*;
import static java.lang.Math.*;
import java.math.BigInteger;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		// 入力
		String s = sc.next();
		
		// 計算
		int result = 0;
		for(int i = 0; i < s.length()/2; i++){
		    if(s.charAt(i) != s.charAt(s.length()-1-i)) result++;
		}
		
		// 出力
		System.out.println(result);
	}
}


Measured memory_bytes: 22996
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;

namespace LogicSummoner
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = GetNumber();

            var count = Enumerable.Range(0, N)
                .Select(x => GetNumber())
                .Count(x => IsPrimeNum(x));

            System.Console.WriteLine(count);
        }

        static bool IsPrimeNum(int num)
        {
            if (num < 2) return false;
            else if (num == 2) return true;
            else if (num % 2 == 0) return false;

            double sqrtNum = Math.Sqrt(num);
            for (int i = 3; i <= sqrtNum; i += 2)
            {
                if (num % i == 0)
                {
                    return false;
                }
            }

            return true;
        }

        //static StreamReader Console = new StreamReader("input.txt");

        static int GetNumber()
        {
            return int.Parse(Console.ReadLine().Trim());
        }

        static double GetDounble()
        {
            return double.Parse(Console.ReadLine().Trim());
        }

        static int[] GetNumbersInt(int n = 0)
        {
            return Console.ReadLine().Trim().Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries).Select(x => int.Parse(x)).ToArray();
        }

        static long[] GetNumbersLong(int n = 0)
        {
            return Console.ReadLine().Trim().Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries).Select(x => long.Parse(x)).ToArray();
        }

        static double[] GetNumbersDouble(int n = 0)
        {
            return Console.ReadLine().Trim().Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries).Select(x => double.Parse(x)).ToArray();
        }

        static string[] GetStrings(int n = 0)
        {
            return Console.ReadLine().Trim().Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries).ToArray();
        }
    }
}

Measured memory_bytes: 9424
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

total = 0
for i in range(n):
    if a[i] - b[i] >= 0:
        total += b[i]
    else:
        if a[i+1] > b[i] - a[i]:
            total += b[i]
            a[i+1] -= b[i] - a[i]
        else:
            total += a[i+1] +a[i]
            a[i+1] = 0


print(total)

Measured memory_bytes: 81892
#include <bits/stdc++.h>
#define all(vec) vec.begin(),vec.end()
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
const ll INF=1LL<<30;
const ll LINF=1LL<<61;
const double eps=1e-9;
const ll MOD=1e9+7;
int main(){
    int n;cin>>n;
    vector<ll> a(n),b(n);
    vector<P> v1,v2;
    for(int i=0;i<n;i++){
        cin>>a[i];
        v1.push_back(P(a[i],i));
    }
    sort(all(v1));
    for(int i=0;i<n;i++){
        cin>>b[i];
        v2.push_back(P(b[i],i));
    }
    sort(all(v2));
    struct edge{int to;ll cost;};
    vector<vector<edge>> G(n);
    for(int i=1;i<n;i++){
        int u=v1[i].second,v=v1[i-1].second;ll c=abs(v1[i].first-v1[i-1].first);
        G[u].push_back({v,c});
        G[v].push_back({u,c});
    }
    for(int i=1;i<n;i++){
        int u=v2[i].second,v=v2[i-1].second;ll c=abs(v2[i].first-v2[i-1].first);
        G[u].push_back({v,c});
        G[v].push_back({u,c});
    }
    priority_queue<P,vector<P>,greater<P>> q;
    vector<ll> d(n,LINF);
    d[0]=0;
    q.push(P(0,0));
    while(!q.empty()){
        int v=q.top().second;q.pop();
        for(auto e:G[v]){
            if(d[e.to]<=d[v]+e.cost)continue;
            d[e.to]=d[v]+e.cost;
            q.push(P(d[e.to],e.to));
        }
    }
    for(int i=0;i<n;i++){
        cout<<d[i]<<endl;
    }
}



Measured memory_bytes: 21508
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  long int A, B, C, K;
  cin >> A >> B >> C >> K;


  if (A >= K){
    cout << K << endl;
    return 0;
  }


  if (A + B >= K){
    cout << A * 1 << endl;
    return 0;
  }

  cout << A * 1 - 1 * (K - A - B) << endl;

}

Measured memory_bytes: 3640
#include <iostream>
#include <bitset>
#include <fstream>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <functional>
#include <cctype>
#include <list>
#include <limits>
#include <unordered_map>
#define Debug 0
//#include <boost/multiprecision/cpp_int.hpp>

const double EPS = (1e-10);


using namespace std;
using Int = long long;
//using namespace boost::multiprecision;

const Int MOD = 1000000007;

Int mod_pow(Int x, Int n) {
    Int res = 1;
    while(n > 0) {
        if(n & 1) res = (res * x) % MOD; //ビット演算(最下位ビットが1のとき)
        x = (x * x) % MOD;
        n >>= 1; //右シフト(n = n >> 1)
    }
    return res;
}

//最大公約数
template<typename T>
T gcd(T a, T b) {
    return b != 0 ? gcd(b, a % b) : a;
}

//最小公倍数
template<typename T>
T lcm(T a, T b) {
    return a * b / gcd(a, b);
}

vector<pair<int, int>> pa;
int main(){
    int N; cin >> N;
    int ma = 0;
    int ma_i = 1000;
    for (int i = 0; i < N; i++) {
        int a, b; cin >> a >> b;
        pa.push_back({a, b});
        if (b > ma) ma = b;
    }
    for (auto i: pa) {
        if (i.second == ma) {
            if (ma_i > i.first) ma_i = i.first;
        }
    }
    for (auto i: pa) {
        if (i.first == ma_i) {
            cout << i.first << " " << i.second << endl;
            break;
        }
    }

}





Measured memory_bytes: 3112
h,n=map(int,input().split())
INF=10**18
dp=[INF]*(h+1)
dp[0]=0
for _ in range(n):
  a,b=map(int,input().split())
  for i in range(h+1):
    dp[min(i+a,h)]=min(dp[min(i+a,h)],dp[i]+b)
print(dp[h])

Measured memory_bytes: 74452
n=int(input())
a=input()
b=input()
c=input()
ans=0
for i in range(n):
	if a[i]==b[i]==c[i]:
		continue
	elif a[i]==b[i] or b[i]==c[i]\
	or c[i]==a[i]:
		ans+=1
	else:
		ans+=2
print(ans)


Measured memory_bytes: 3060
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
	Scanner scan = new Scanner(System.in);

	int a = scan.nextInt();
	int b = scan.nextInt();
        int t = scan.nextInt();
 
	double time = t+0.5;
	int x = (int)time/a;
	System.out.println(x*b);
    }
}


Measured memory_bytes: 23380
#include <iostream>
#include <string>

using namespace std;

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

    long long sum = 0;
    long long tmp = 0;
    int digit = S.size() - 1;

    for(int bit = 0; bit < (1 << digit); bit++){
        tmp = S[0] - '0';
        for(int i=0; i<digit; i++){
            if(bit & (1<<i)){
                sum += tmp;
                tmp = S[i+1] - '0';
            }else{
                tmp = tmp*10 + S[i+1] - '0';
            }
        }
        sum += tmp;
    }

    cout << sum << endl;
}

Measured memory_bytes: 256
use proconio::input;

fn main() {
    input!{
        a: i128,
        v: i128,
        b: i128,
        w: i128,
        t: i128,
    }
    
    let s = v - w;
    let d = (b - a).abs();

    if d > t * s{
        println!("NO");
    } else {
        println!("YES");
    }
}


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

#define For(i, j, k) for(int i = j; i <= k; i++)
#define Forr(i, j, k) for(int i = j; i >= k; i--)
#define pb push_back

using namespace std;

const int N = 100010;

typedef long long LL;

int n, m, col[N];
vector<int> G[N];

int banu, banv;

bool DFS_bipartite(int o){
	for(int v : G[o]){
		if((o == banu && v == banv) || (o == banv && v == banu)) continue;
		if(!col[v]){
			col[v] = 3 - col[o];
			if(!DFS_bipartite(v)) return false;
		}
		else if(col[o] == col[v]) return false;
	}
	return true;
}

bool vis[N];
int stk[N], top;
int cycle[N], c;

void DFS_cycle(int o, int f){
	vis[o] = true;
	stk[++top] = o;
	for(int v : G[o]){
		if(v == f) continue;
		if(!vis[v]) DFS_cycle(v, o);
		else if(!c){
			Forr(i, top, 1){
				cycle[++c] = stk[i];
				if(stk[i] == v) break;
			}
		}
	}
	--top;
}

int szx[N], szy[N];

LL DFS_work(int o, int f){
	szx[o] += col[o] == 1;
	szy[o] += col[o] == 2;
	LL ret = 0;
	for(int v : G[o]){
		if((o == banu && v == banv) || (o == banv && v == banu)) continue;
		if(v == f) continue;
		ret += DFS_work(v, o);
		szx[o] += szx[v], szy[o] += szy[v];
	}
	return ret + abs(szx[o] - szy[o]);
}

LL calc(int x){
	memset(szx, 0, sizeof szx), memset(szy, 0, sizeof szy);
	szx[banu] += x, szx[banv] -= x;
	return DFS_work(1, 0) + abs(x);
}

int main(){
	scanf("%d%d", &n, &m);
	For(i, 1, m){
		int u, v;
		scanf("%d%d", &u, &v);
		G[u].pb(v), G[v].pb(u);
	}
	
	col[1] = 1;
	bool bipart = DFS_bipartite(1);
	DFS_cycle(1, 0);
	
//	cerr << "cycle length = " << c << endl
//		 << "bipart = " << bipart << endl;

	if(!c){
		LL ans = DFS_work(1, 0);
		if(szx[1] != szy[1]) puts("-1");
		else printf("%lld\n", ans);
	}
	else if(bipart){
		banu = cycle[1], banv = cycle[2];

		DFS_work(1, 0);
		if(szx[1] != szy[1]){
			puts("-1");
			return 0;
		}

		int L = -n, R = n;
		while(L < R){
			int m1 = L + (R - L) / 3, m2 = R - (R - L) / 3;
			if(calc(m1) > calc(m2)) L = m1 + 1;
			else R = m2 - 1;
		}

		printf("%lld\n", calc(L));
	}
	else{
		banu = cycle[1], banv = cycle[2];
		memset(col, 0, sizeof col);

		col[1] = 1;
		assert(DFS_bipartite(1));
		
		DFS_work(1, 0);
		int d = szx[1] - szy[1];
		if(d % 2){
			puts("-1");
			return 0;
		}

		memset(szx, 0, sizeof szx), memset(szy, 0, sizeof szy);
		szy[banu] += d / 2, szy[banv] += d / 2;
		printf("%lld\n", DFS_work(1, 0) + abs(d / 2));
	}

	return 0;
}

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

int main(){
  int a,b,c,d,e,f;
  cin >> a >> b >> c >> d >> e >> f;
  vector<bool> x((f+1)/100+1, false);
  for(int i = 0; i <= f/100; i++){
    for(int j = 0; j <= f/100; j++){
      if(i*a + j*b <= (f+1)/100){
        x[i*a + j*b] = true;
      }
    }
  }
  vector<bool> y(f+1, false);
  for(int i = 0; i <= f/c; i++){
    for(int j = 0; j <= f/d; j++){
      if(i*c + j*d <= f)
        y[i*c + j*d] = true;
    }
  }

  double max_noudo = 0.0;
  int max_water = a;
  int max_sugar = 0;
  for(int i = 1; i < x.size(); i++){
    for(int j = 0; j < y.size(); j++){
      if(i * 100 + j > f) break;
      if(x[i] && y[j]){
        if(i * e == j){
          // 最高濃度
          cout << i * 100 + j << " " << j << endl;
          return 0;
        }
        double noudo = (double)j / i;
        if(noudo > e) continue;
        if(max_noudo < noudo){
          max_noudo = noudo;
          max_water = i;
          max_sugar = j;
        }
      }
    }
  }
  cout << max_water * 100 + max_sugar << " " << max_sugar << endl;
}


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

#ifndef DEBUG
#define endl '\n'
#define debug(...)
#else
#define debug(...) __VA_ARGS__
#endif
#define debugf(...) debug(printf(__VA_ARGS__);)

using ll = long long;
const int N = 2e5 + 5;
const int Y = 2019;

int f[Y];



int (((((main)))))() <%
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);

    string s; cin >> s;
    int n = s.size();

    // 10^p*x + y - r1 = aY
    //          y - r2 = bY
    // 10^p*x - r1 + r2 = (a - b)Y
    // 10^p*x is a multiple of Y iff r1 = r2

    ll ans = 0;
    int x = 0;
    int pt = 1; // current power of ten
    for (int i = n-1; i >= 0; i--) {
        x += pt * (s[i] - '0') % Y;
        x %= Y;
        pt = pt * 10 % Y;
        ans += f[x];
        if (x == 0) ans++;
        f[x]++;
    }
    cout << ans << endl;

    return 0;
%>

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

using ll = long long;

const int INF = 1001001001;
const ll INF_LL = 1001001001001001001LL;

int main(void){
  char b; cin >> b;

  if(b=='A') cout << "T" << endl;
  else if(b=='C') cout << "G" << endl;
  else if(b=='G') cout << "C" << endl;
  else if(b=='T') cout << "A" << endl;
    
  return 0;
}


Measured memory_bytes: 3596
#include <iostream>
#include <queue>
#include <string>

using namespace std;

int main() {
    priority_queue<long> pq;
    string inst;
    while (true) {
        cin >> inst;
        if (inst == "end") {
            break;
        } else if (inst == "insert") {
            long key;
            cin >> key;
            pq.push(key);
        } else {
            cout << pq.top() << '\n';
            pq.pop();
        }
    }
}



Measured memory_bytes: 11244
/*
Author: Arham_doshi
@quote "Code like there's no tommorow!"
 ***************************************   UNAUTHORISED COPYING OF CODE PROHIBITED   **********************************
*/
#include <bits/stdc++.h>

#define int         long long
#define double      long double
#define pb          push_back
#define pf          push_front
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define rall(a)     (a).rbegin(),(a).rend()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        998244353 
#define PI          3.141592653589
#define bs(v,n)     binary_search(all((v)),(n))
#define lb(v,n)     lower_bound(all((v)),(n))
#define ub(v,n)     upper_bound(all((v)),(n))
#define fo(i,l,u)   for(i=l;i<u;i++)
#define rfo(i,l,u)  for(i=l;i>=u;i--)
#define allfo(s)    for(auto it=(s).begin();it!=(s).end();it++)
#define _init(b)     memset(b,-1,sizeof(b))
#define _init0(b)     memset(b,0,sizeof(b))
#define MOD         1000000007



using namespace std;

int gcd(int a, int b) {  if (a == 0)  return b; return gcd(b % a, a); }  
bool mod(double a,double b) {return a/b - floor(a/b);}

int occurs(vi v,int n){
auto it=lb(v,n);auto it1=ub(v,n);int x=it1-it;return x;}

int logb(int base, int x) {
    return (log(x) / log(base));
}



signed main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int i,j,x,t,n,k;
    cin>>i>>j;
    if(i<10&&j<10){
        cout<<i*j;
    }
    else{
        cout<<-1;
    }
    
    return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> d1(n);
  vector<int> d2(n);
  for (int i = 0; i < n; i++)
  {
    cin >> d1[i] >> d2[i];
  }
  int t = 0;
  bool u = true;
  for (int i = 0; i < n; i++)
  {
    if (d1[i] == d2[i])
    {
      t++;
    }else
    {
      t = 0;
    }
      if (t == 3)
    {
      cout << "Yes" << endl;
      u = false;
      break;
    }
    
  }
  if (u)
  {
    cout << "No" << endl;
  }
  
  
}


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

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

typedef long long ll;
using namespace std;
int mod = 1000000007;

int main(void){
    string A = "keyence";
    string S; cin >> S;
    int lenS = S.length();
    rep(i, 8){
        string L = A.substr(0, i);
        string R = A.substr(i);
        if(S.substr(0, i) == L && S.substr(lenS-(7-i)) == R){
            cout << "YES" << endl;
            return 0;
        }
    }
    cout << "NO" << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<sstream>
#include<vector>
#include<string>
#include<algorithm>

using namespace std;

int main(){
  long long N;
  cin>>N;
  vector<long long> A(N+1);
  vector<long long> B(N);
  for(long long i=0; i<N+1; i++) cin>>A[i];
  for(long long i=0; i<N; i++) cin>>B[i];
  long long hunt=0;
  for(long long i=0; i<N; i++){
    if(A[i]<B[i]){
      hunt+=A[i];
      if(A[i+1]<=(B[i]-A[i])){
        hunt+=A[i+1];
        A[i+1]=0;
      }else{
        A[i+1]-=(B[i]-A[i]);
        hunt+=(B[i]-A[i]);
      }
    }else{
      hunt+=B[i];
    }
  }
  cout<<hunt<<endl;

  return 0;
}



Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <ios>     // std::left, std::right
#include <iomanip> // std::setw(int), std::setfill(char)
#include <string>
#include <cmath>

using namespace std;

int main(){
    int R;
    cin >> R;
    if (0 <= R && R < 1200){
        cout << "ABC" << endl;
    } else if (R < 2800){
        cout << "ARC" << endl;
    } else {
        cout << "AGC" << endl;
    }
}


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

using namespace std;

typedef long long ll;

class DisjointSet{
  public:
    vector<int> p; //parent
    DisjointSet(int size){
      for(int i=0;i<size;i++) makeSet(i); //initialize
    }
    void makeSet(int x){
      p.push_back(x);
    }
    void unite(int x, int y){
      link(findSet(x), findSet(y));
    }
    int findSet(int x){
      if(x != p[x]) p[x]=findSet(p[x]);
      return p[x];
    }
    void link(int x, int y){
      p[y]=x;
    }
    bool isSameSet(int x, int y){
      return findSet(x)==findSet(y);
    }
};

int main(){
  int n, q; cin >> n >> q;
  DisjointSet ds=DisjointSet(n);
  for(int i=0;i<q;i++){
    int com, x, y; cin >> com >> x >> y;
    if(com){
      if(ds.isSameSet(x, y)) cout << 1 << endl;
      else cout << 0 << endl;
    }else{
      ds.unite(x, y);
    }
  }
}

Measured memory_bytes: 3232
#include <stdio.h>
 
int main() {
int i, tmp, max;
int count[101] = {0};
while( scanf("%d",&tmp) != EOF ) {
count[tmp]++;
}
 
max = 0;
for(i = 1; i < 101; i++ ) {
if(max < count[i]) {
max = count[i];
}
}
for(i = 1; i < 101; i++ ) {
if(count[i] == max ) {
printf("%d\n",i) ;
}
}
return 0;
}

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

int main() {
  int N, A, min, x;
  cin >> N;
  
  for (int i = 0; i < N; i++){
    cin >> A;
    x=0;
    while((A % 2) == 0){
      A /= 2;
      x++;
    }
    if(i==0){
      min=x;
    }else{
      if(min>x)
        min=x;
    }
  }
  cout << min << endl;
}

Measured memory_bytes: 3564
#C Build Staris
import sys
N = int(input())
H = list(map(int, input().split()))

for i in range(N-1):
    if H[i] < H[i+1]:
        H[i+1] -= 1
    elif H[i] != H[i+1]:
        print('No')
        sys.exit()
print('Yes')

Measured memory_bytes: 15020
#include <iostream>
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
#include <array>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <cstdint>
#include <unordered_set>
#include <ctime>
#include <numeric>
typedef long long int llint;

int main(void){
  int n;
  std::cin >> n;

  llint sum = 0;

  for(int i=1; i<=n; i++){
    if(i%3!=0 && i%5!=0) sum+= i;
  }



  std::cout << sum << std::endl;
  return 0;
}


Measured memory_bytes: 3636
#include <stdio.h>
#include <stdio.h>

typedef struct {
	char suit;
	int value;
} card;

void output(card C[], int N);
void swap(card *C1, card *C2);
void bubbleSort(card C[], int N9);
void selectionSort(card C[], int N);
int isStable(card cBubble[],card cSelection[], int N);


int main(void) {
	int N;
	int i;
	
	card cBubble[36], cSelection[36];
	
	scanf("%d", &N);
	
	for (i = 0; i < N; i++) {
		scanf(" %c%d", &cBubble[i].suit, &cBubble[i].value);
		cSelection[i] = cBubble[i];
	}
	
	bubbleSort(cBubble, N);
	printf("Stable\n");

	selectionSort(cSelection, N);
	if (isStable(cBubble, cSelection, N)) {
		printf("Stable\n");
	}else {
		printf("Not stable\n");
	}
	
	return 0;
}


void output(card C[], int N) {
	int i;
	for (i = 0; i < N; i++) {
		if (i > 0) printf(" ");
		printf("%c%d",C[i].suit, C[i].value);
	}
	printf("\n");
}


void swap(card *C1, card *C2) {
	card tmp = *C1;
	*C1 = *C2;
	*C2 = tmp;
}

void bubbleSort(card C[], int N) {
	int i, j;
	
	for (i = 0; i < N - 1; i++) {
		for (j = N - 1;j >= i + 1 ; j--) {
			if (C[j - 1].value > C[j].value) {
				swap(&C[j - 1], &C[j]);
			}
		}
	}
	output(C, N);

}

void selectionSort(card C[], int N) {
	int i, j, minj;

	for (i = 0; i < N - 1; i++) {
		minj = i;
		for (j = i; j < N; j++) {
			if (C[j].value < C[minj].value) {
				minj = j;
			}
		}
		swap(&C[i], &C[minj]);
	}
	output(C, N);
}


int isStable(card cBubble[],card cSelection[], int N) {
	int i;
	
	for (i = 0; i < N; i++) {
		if (cBubble[i].suit != cSelection[i].suit) {
			return 0;
		}
	}

	return 1;
}

Measured memory_bytes: 612
#include <cstdio>

int main() {
  int A, B, C;
  scanf("%d %d %d", &A, &B, &C);

  if (A == B) {
    printf("%d\n", C);
  } else if (B == C) {
    printf("%d\n", A);
  } else if (C == A) {
    printf("%d\n", B);
  }
}

Measured memory_bytes: 128
#include <iostream>
#include<vector>
#define rep(i,n) for(int i = 0; i < (n); i++)

using namespace std;

int main() {
    vector<int>x(5);
    rep(i,5)cin>>x[i];
    rep(i,5){
        if(x[i]==0){
            cout<<i+1<<endl;
            break;
        }
    }
    return 0;
}

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

deque<int> solve(long long n)
{
    if (n == 1)
        return deque<int>(1, 1);
    
    deque<int> aux;
    if (n & 1) {
        aux = solve((n - 1) / 2);
        aux.push_back((int) aux.size() + 1);
    } else {
        aux = solve(n - 1);
        aux.push_front((int) aux.size() + 1);
    }
    
    return aux;
}

int main(void)
{
    long long n; cin >> n;
    deque<int> ans = solve(n);
    
    for (int i = 1, n = (int) ans.size(); i <= n; ++i)
        ans.push_back(i);
    
    cout << ans.size() << "\n";
    for (int x : ans)
        cout << x << " ";
    
    return 0;
}

Measured memory_bytes: 256
c=[0,0,0]
for i in 0..2
  c[i]=gets.split.map &:to_i
end
b=c[0]
a=[0,0,0]
for i in 0..2
  a[i]=c[i][0]-b[0]
end
ok=1
for i in 0..2
  for j in 0..2
    ok&&=a[i]+b[j]==c[i][j]
  end
end
puts(ok ?'Yes':'No')





Measured memory_bytes: 3836
{-# LANGUAGE ScopedTypeVariables #-}

module Main where

import Data.Maybe (fromJust)
import qualified Data.ByteString.Char8 as BS
bytestr2Int = fst . fromJust . BS.readInt
getInt = bytestr2Int <$> BS.getLine
getIntL_H = map bytestr2Int. BS.words <$> BS.getLine
getIntL_V n = replicate n $ getInt
getInt2D n = replicate n $ getIntL_H


data Curr = Zero
          | One Int
          | Filled Int Int Int
          deriving (Show)

main :: IO ()
main = do
    [k,s] <- getIntL_H
    putStrLn . show $ check k s 0 Zero

check k s a c =
    if s<0 then
        0
    else if k<a || a<0 then do
        0
    else case c of
        Zero -> do
            check k s (a+1) c + check k (s-a) 0 (One a)
        (One x) -> do
            check k s (a+1) c + check k 0 (s-a) (Filled x a (s-a))
        _ -> do
            1

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

int main() {
    int n;
    string s;
    cin>>n>>s;
    int x=0;
    int mx=0;
    for (char c:s) {
        if (c=='I') {
            x++;
            mx=max(mx,x);
        }
        else
            x--;
    }
    cout<<mx<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll>pi;
const int MAXN=100005;
const int MOD=1000000007;
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define DEC(i,a,b) for(int i=(a);i>=(b);i--)
#define fst first
#define snd second
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define sz(v) ((int)(v).size())
#define db(x) cerr<<#x<<" = "<<x<<"\n"
#define LOW(v,x) (lower_bound(all(v),(x))-(v).begin())

void test(ll S){
	ll a,b,c,d;
	if(S>=1000000000000000000LL-1000000000LL){
		b=c=1e9,d=1000000000000000000LL-S,a=1;
	}
	//~ cout<<"0 0 1 0 0 "<<s<<"\n";
	else{
		c=sqrt(S),b=(S+c-1)/c,d=b*c-S,a=1;
	}
	for(auto i:{a,b,c,d})assert(0<=i&&i<=1e9);
	//~ if(b*c-a*d!=S)while(true);
	//~ if(d>b)int A[100000005];
	assert(b*c-a*d==S);
	assert(d<=b);
	cout<<"0 0 "<<a<<' '<<b<<' '<<c<<' '<<d<<"\n";
}
int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	ll S;cin>>S;
	test(S);
	//~ test(999999999999999935LL);
	//~ for(ll i=999999999999999999LL-1e9;i>=0;i--){
		//~ db(i);
		//~ test(i);
	//~ }
}
/*
999999999999999935

10 3
3 5 6
*/


Measured memory_bytes: 256
N = int(input())
T = [int(i) for i in input().split()]
M = int(input())
for i in range(M):
    P, X = map(int, input().split())
    result = 0
    for j in range(len(T)):
        if j == (P-1):
            result += X
        else:
            result += T[j]
    print(result)


Measured memory_bytes: 3064
#include <cstdio>
#include <iostream>
#include <string>
using namespace std;
#define ref(i,x,y)for(int i=x;i<=y;++i)
string s;
int main()
{
	cin>>s;
	int l=s.size();
	s=" "+s;
	int cnt1=1,cnt2=l;
	int ans=0;
	while(cnt1<=cnt2)
	{
		if(cnt1==cnt2)break;
		if(s[cnt1]==s[cnt2]){cnt1++,cnt2--;continue;}
		if(s[cnt1]=='x'){cnt1++;ans++;continue;}
		if(s[cnt2]=='x'){cnt2--;ans++;continue;}
		ans=-1;break;
	}
	cout<<ans<<endl;
}

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

#define ll long long

double dp[3005][3005];

double solve(double p[],ll n,ll h)
{
  if(h==0)
    return 1;
  if(n<0)
    return 0;
  if(dp[n][h]>-0.5)
    return dp[n][h];
  return dp[n][h]=(p[n]*solve(p,n-1,h-1)+(1-p[n])*solve(p,n-1,h));
}


int main()
{
  ll n;
  cin>>n;
  double p[n];
  for(ll i=0;i<n;i++)
  {
    cin>>p[i];
    
  }
  for(ll i=0;i<n;i++)
    for(ll j=0;j<3005;j++)
      dp[i][j]=-1;
  
  double ans=solve(p,n-1,(n+1)/2);
  cout<<setprecision(10)<<ans<<endl;
}

Measured memory_bytes: 74308
import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.math;



void main() {
    int input;
    immutable limitList = 200000;
    bool[] listNumbers = new bool[](limitList);
    int[] listPrimeNumbers;

    listNumbers.fill(true);
    foreach (i; 2..limitList.to!double.sqrt.to!int) {
        if (listNumbers[i]) {
            for (int j = i*2; j < limitList; j += i) listNumbers[j] = false;
        }
    }

    foreach (i; 2..listNumbers.length) {
        if (listNumbers[i]) {
            listPrimeNumbers ~= i.to!int;
        }
    }

    while ((input = readln.chomp.to!int) != 0) {
        ulong sum = 0;

        foreach (i; 0..listPrimeNumbers.length) {
            if (i == input) break;
            sum += listPrimeNumbers[i];
        }

        writeln(sum);
    }
}

Measured memory_bytes: 1232
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b) - 1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)

#define PB push_back
#define MP make_pair
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define CLR(a) memset(a,0,sizeof(a))
#define SET(a,c) memset(a,c,sizeof(a))

#define DEBUG(x) cout<<"#x"<<": "<<x<<endl

using namespace std;

typedef long long int ll;
typedef vector<int> vi;
typedef vector<ll> vl;

const ll INF = INT_MAX/3;
const ll MOD = 1000000007;
const double EPS = 1e-15;
const int dx[] = {1,0,-1,0} , dy[] = {0,1,0,-1};

double dp[100001];

int main(){

    SET(dp,0.0);
    dp[1] = 1.0;
    dp[2] = 1.5;
//     dp[3] = 2.125;

    FOR(i,3,100001){
	double m = 1.0,p = 1.0 , r = 0.5;
	RREP(j,i-1){
	    if(m < EPS) break;
	    dp[i] += (dp[j] + (double)(i - 1 - j) ) * (1-r) * m;
	    p *= 0.5;
	    r *= 0.5;
	    m *= p;
	}
	dp[i] += m * (double)(i);
    }

    int n;
    while(cin >> n , n){
	printf("%.5lf\n",dp[n]);
    }

    return 0;
}

Measured memory_bytes: 1976
import java.util.*;

class Main{
	public static void main(String[] $){
		//System.err.println();
		Scanner s=new Scanner(System.in);
		int n=s.nextInt();
		int[] a=new int[n];
		Arrays.setAll(a,i->s.nextInt());

		for(int i=0;i<n;++i){
			for(int j=0;j<n;++j){
				{
					int t=a[i];
					a[i]=a[j];
					a[j]=t;
				}
				if(f(a)){
					System.out.println("YES");
					return;
				}
				{
					int t=a[i];
					a[i]=a[j];
					a[j]=t;
				}
			}
		}
		System.out.println("NO");
	}

	private static boolean f(int[] a){
		for(int k=1;k<a.length;++k)
			if(a[k-1]>a[k])
				return false;
		return true;
	}
}


Measured memory_bytes: 28372
t=input()
trigger=1
key=''
d=-1
app=['dreamer','eraser','dream','erase']
while len(t)>0 and trigger:
    for i in range(4):
        key=app[i]
        if key==t[:len(key)]:
            t=t[len(key):]
            trigger+=1
            d=i
            break
    trigger-=1
    if trigger==0 and d==0 and t[:3]=='ase':
        t='er'+t
        trigger+=1
if t=='':
    print('YES')
else:
    print('NO')

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

int main() {
  string S;
  ll K;
  cin >> S >> K;

  char ans = S.front();

  if (S.front() == '1') {
    int cnt = 0;
    char c = '0';
    rep(i, S.size()) {
      if (S[i] != '1') {
        c = S[i];
        break;
      }
      cnt++;
    }
    if (cnt < K)
      ans = c;
  }
  cout << ans << endl;
}

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

using namespace std;


int main()
{
    int N, M, X, Y;
    int tmp;
    int max = -INT_MAX, min = INT_MAX;

    cin >> N >> M >> X >> Y;
    // find max of x
    for (int i = 0; i < N; i++) {
        cin >> tmp;
        if (max < tmp) {
            max = tmp;
        }
    }

    // find min of y
    for (int i = 0; i < M; i++) {
        cin >> tmp;
        if (min > tmp) {
            min = tmp;
        }
    }

    if (max < min) {
        if (min <= X || Y <= max) {
            cout << "War" << endl;
        } else {
            cout << "No War" << endl;
        }
    } else {
        cout << "War" << endl;
    }
    
    return 0;   
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n,s) for(int i=(s);i<(n);i++)
#define rrep(i,n) for(int i=(n-1);i>=0;i--)
#define rreps(i,n,s) for(int i=s;i>=n;i--)
#define MOD 1000000007
using ll = long long;
using namespace std;
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 (a>b) { a=b; return 1; } return 0; }

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
ll n, m;
cin >> n >> m;
vector<ll> a(n);
ll ans = n;
rep(i, m){
     cin >> a[i];
     ans -= a[i];
}
if(ans>=0){
    cout << ans << endl;
}
else{
    cout << -1 << endl;
}
//system("pause");
return 0;
}

Measured memory_bytes: 11120
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        while(true){
            int a = sc.nextInt();
            int b = sc.nextInt();
            int c = sc.nextInt();
            int sum = a + b;
            if(a == -1 && b == -1 && c== -1){
                break;
            }else if(a == -1 || b == -1){
                System.out.println("F");
            }else{
                if(sum<30){
                    System.out.println("F");
                }else if(sum<50){
                    if(c<50){
                        System.out.println("D");
                    }else{
                        System.out.println("C");
                    }
                }else if(sum<65){
                    System.out.println("C");
                }else if(sum<80){
                    System.out.println("B");
                }else{
                    System.out.println("A");
                }
            }
        }
        sc.close();
    }
}


Measured memory_bytes: 26428
N=int(input())
H_list=list(map(int, input().split()))
count=0
for i in range(len(H_list)):
  if i==0:
    min_H=H_list[i]
    count=count+1
    continue
  if H_list[i]>=min_H:
    count=count+1
    min_H=H_list[i]

print(count)
    
   


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main(){
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int ans = 0;
    for(int i=1; i<=100; i++){
        if(a<i && i<=b && c<i && i<=d){
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int Maxn = 2000000 + 100;
int N, M;
int A[Maxn], P[Maxn], Cnt[Maxn];
int main()
{
	scanf("%d%d", &N, &M);
	int x, y, Ans = 0;
	for (int i = 1; i <= N; ++i)
	{
		scanf("%d", &A[i]);
		Cnt[A[i]] ++;
		P[A[i] - Cnt[A[i]] + 1] ++;
	}
	for (int i = 1; i <= N; ++i)
		if (!P[i])Ans ++;
	for (int i = 1; i <= M; ++i)
	{
		scanf("%d%d", &x, &y);
		if (A[x] - Cnt[A[x]] + 1 >= 1 && P[A[x] - Cnt[A[x]] + 1] == 1)
			Ans ++;
		P[A[x] - Cnt[A[x]] + 1] --;
		Cnt[A[x]] --;
		A[x] = y;
		Cnt[A[x]] ++;
		if (A[x] - Cnt[A[x]] + 1 >= 1 && P[A[x] - Cnt[A[x]] + 1] == 0)
			Ans --;
		P[A[x] - Cnt[A[x]] + 1] ++;
		printf("%d\n", Ans);
	}
	return 0;
}

Measured memory_bytes: 10368
N, M = map(int, input().split())
List_LR = [list(map(int,input().split())) for i in range(M)]
L = [List_LR[i][0] for i in range(len(List_LR))]
R = [List_LR[i][1] for i in range(len(List_LR))]
 
L_max = max(L)
R_min = min(R)

ans = R_min - L_max +1
if ans < 0 : ans = 0
print(ans)

Measured memory_bytes: 29016
#include <stdio.h>

int main(){
	int i,ans;
	char str[101];
	char data[8] = "IVXLCDM";

	while(scanf("%s",str) != EOF){
		ans = 0;
		for(i = 0;str[i] != '\0';i++){
			switch(str[i]){
				case 'I':
					if(str[i+1] == 'V' || str[i+1] == 'X'){
						ans -= 1;
					}else{
						ans += 1;
					}
					break;
				case 'V':
					ans += 5;
					break;
				case 'X':
					if(str[i+1] == 'L' || str[i+1] == 'C'){
						ans -= 10;
					}else{
						ans += 10;
					}
					break;
				case 'L':
					ans += 50;
					break;
				case 'C':
					if(str[i+1] == 'D' || str[i+1] == 'M'){
						ans -= 100;
					}else{
						ans += 100;
					}
					break;
				case 'D':
					ans += 500;
					break;
				case 'M':
					ans += 1000;
					break;
			}
		}

		printf("%d\n",ans);
	}

	return 0;
}

Measured memory_bytes: 540
#include <iostream>
#include <algorithm>
#include <utility>
#include <queue>
using namespace std;
pair<int, int> ab[100000];
priority_queue<int> pq;

int main(){
    int n, m;
    cin >> n >> m;
    int a, b;
    for (int i = 0; i < n; i++){
        cin >> a >> b;
        ab[i] = make_pair(a, b);
    }
    sort(ab, ab + n);
    int j = 0;
    int ans = 0;
    for (int i = 1; i <= m; i++){
        while ((ab[j].first <= i) && (j < n)){
            pq.push(ab[j].second);
            j++;
        }
        if (!pq.empty()){
            ans += pq.top();
            pq.pop();
        }
    }
    cout << ans << '\n';
}


Measured memory_bytes: 1660
// Author: pankaj_m05 
// Problem: D
// Created: 17.05.2020 18:20:52

#include<bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);
#define f_in(file) freopen(file, "r", stdin)
#define f_out(file) freopen(file, "w", stdout)
#define sz(a) int((a).size())
#define gc getchar_unlocked
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(c) c.begin(), c.end()
#define tr(c,i) for(typeof(c).begin() i = c.begin(); i != c.end(); i++)
#define present(c,x) (c.find(x) != c.end())  // Set and Maps
#define cpresent(c,x) (find(allc,x) != c.end()) // Vectors
using namespace std;

typedef vector< int > vi;
typedef vector< vi > vvi;
typedef pair< int, int > ii;
typedef long long ll;

const int mod = 1e9 + 7;
const int mxN = 1e5;

void scan(int& x)  { 
	x = 0; 
    bool neg = 0; 
    register int c = gc(); 
    if (c == '-') 
        neg = 1, c = gc();  
    while ((c < 48) || (c > 57)) 
        c = gc(); 
    for ( ; c < 48||c > 57 ; c = gc()); 
    for ( ; c > 47 && c < 58; c = gc()) 
        x= (x << 3) + ( x << 1 ) + ( c & 15 ); 
    if (neg) x *= -1;

}

int n;
vector< int > adj[mxN + 1];
bool vis[mxN + 1];
int sign[mxN + 1] = { 0 };


void bfs() {
	queue<int> q;  
	q.push(1);
	while(!q.empty()) {
		int v = q.front();
		q.pop();
		if(!vis[v]) {
			vis[v] = 1;
			for(int u : adj[v]) { 
				q.push(u);
				if(sign[u] == 0) 
					sign[u] = v;
			}
		}
	}
}
                      
int main(void) { 
	fast
	int m;
	bool flag = 1;
	scan(n); scan(m);                     
	for(int i = 0; i < m; ++i) {
		int u, v; 
		scan(u); scan(v);
		adj[u].pb(v);
		adj[v].pb(u);
		if(u == 1 || v == 1)
			flag = 0;
	}
	if(flag){
		cout << "No" << '\n';
		return 0;
	}
	cout << "Yes" << '\n';
	bfs();
	for(int i = 2; i <= n; ++i) {
		cout << sign[i] << '\n';
	}
	return 0;
}                                          

Measured memory_bytes: 11156
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    ll cnt = 0;
    vint p(n);
    REP(i,n){
        cin >> p[i];
    }
    REP(i,n-1){
        if(p[i]==i+1){
            swap(p[i],p[i+1]);
            cnt++;
        }
    }
    if(p[n-1]==n)cnt++;
    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 3728
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()		//sort(all(vi S)) sort(all(string S))

typedef long long ll;
typedef vector<int> vi;
typedef set<int> seti;
typedef vector<string> vs;

const int MOD = 1e9+7;
const int INF = 1e9;

int solve(ll a){
	int res = 0;
	while(a){
		res += a%10;
		a /= 10;
	}
	return res;
}
int x,y;
int main() {
	int N;
	cin>>N;
	int ans = INF;
	rep1(i,N){
		x = solve(i);
		y = solve(N-i);
		ans = min(ans,x+y);
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <stdio.h>
using namespace std;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPL(i,f,n) for(int i=f, i##_len=(n); i<i##_len; ++i)
typedef long long ll;

int main() {
	string MARCH = "MARCH";
	cin.tie(0);
	ios::sync_with_stdio(false);

	ll N,M;
	cin >> N >> M;
	ll ans;
	if (N >= 2 && M >= 2) {
		ans = (N - 2)*(M - 2);
	}
	else if (N == 1 && M == 1) {
		ans = 1;
	}
	else if (N == 1 && M > 1) {
		ans = M-2;
	}
	else if (N > 1 && M == 1) {
		ans = N-2;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
from collections import deque

d = ' '
n, q = map(int, input().split(d))

tree = [[] for _ in range(n)]

for _ in range(n - 1):
    a, b = map(int, input().split(d))
    a -= 1
    b -= 1
    tree[a].append(b)
    tree[b].append(a)

count = [0 for _ in range(n)]
for _ in range(q):
    p, x = map(int, input().split(d))
    p -= 1
    count[p] += x

ret = [0 for _ in range(n)]
q = deque(maxlen=n)
q.append((0, 0))
while len(q) > 0:
    f, c = q.popleft()
    ret[c] = count[c] + ret[f]
    for n in tree[c]:
        if n != f:
            q.append((c, n))

print(*ret)

Measured memory_bytes: 65256
#!/usr/bin/env python3
import sys


def solve(N: int, M: int, A: "List[int]"):
    print(max(-1, N - sum(A)))
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    A = [ int(next(tokens)) for _ in range(M) ]  # type: "List[int]"
    solve(N, M, A)

if __name__ == '__main__':
    main()


Measured memory_bytes: 9964