akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
inline void chmin (int& a, int b) {
  if (a > b) a = b;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n), b(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i] >> b[i];
  }
  long long sum = 0;
  int minv = 1e9 + 1;
  for (int i = 0; i < n; i++) {
    sum += a[i];
    if (a[i] > b[i]) {
      chmin(minv, b[i]);
    }
  }
  if (minv == 1e9 + 1) {
    cout << 0 << '\n';
  } else {
    cout << sum - minv << '\n';
  }
  return 0;
}

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

int main() {
    int64_t N, M;
    cin >> N >> M;
    vector<int64_t> H(N);
    for (int64_t& h : H) {
        cin >> h;
    }

    vector<vector<int64_t>> connect(N);
    for (int64_t i = 0; i < M; i++) {
        int64_t A, B;
        cin >> A >> B;
        A--; B--;
        connect[A].push_back(B);
        connect[B].push_back(A);
    }

    int64_t ans = 0;
    for (int64_t i = 0; i < N; i++) {
        bool ok = true;
        for (int64_t j : connect[i]) {
            if (H[i] <= H[j]) {
                ok = false;
                break;
            }
        }
        if (ok) {
            ans++;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 9860
a = int(input())
b = int(input())
c = 0
if a == 1:
  if b == 2:
    c = 3
  if b == 3:
    c = 2
if a == 2:
  if b == 1:
    c = 3
  if b == 3:
    c = 1
if a == 3:
  if b == 1:
    c = 2
  if b == 2:
    c = 1
print(c)

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, s, e) for (int i = (int)(s); i < (int)(e); i++)
#define _rep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define _REP(i, e, s) for (int i = (int)(e - 1); i >= (int)(s); i--)

#define yes cout << "yes" << endl;
#define Yes cout << "Yes" << endl;
#define YES cout << "YES" << endl;

#define no cout << "no" << endl;
#define No cout << "No" << endl;
#define NO cout << "NO" << endl;

#define AC cout << "AC" << endl;
#define WA cout << "WA" << endl;

#define out(s) cout << s << endl;

#define ll long long
#define ull unsigned long long
#define vi vector<int>

const double PI = 3.14159265358979323846;

int main() {
    char b;
    cin >> b;
    if (b == 'A') {
        out('T');
    } else if (b == 'T') {
        out('A');
    } else if (b == 'C') {
        out('G');
    } else {
        out('C');
    }
}


Measured memory_bytes: 256
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
#include <random>
#include <cassert>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define MEM(a,b) memset((a),(b),sizeof(a))
const LL INF = 1e9 + 7;
const int N = 1e5 + 10;

int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int r, d;
	LL x;
	cin >> r >> d >> x;
	for (int i = 1; i <= 10; i++)
	{
		x = x * r - d;
		cout << x << endl;
	}
	return 0;
}

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

H = [[1,10 ** 9] for _ in range(N)]

for i in range(N):
  if i == 0:
    hmin = T[i]
    hmax = T[i]
  elif T[i-1] < T[i]:
    hmin = T[i]
    hmax = T[i]
  else:
    hmin = 1
  H[i][0] = hmin
  H[i][1] = hmax
  #print(H)
for i in range(N-1,-1,-1):
  if i == N-1:
    hmin = A[i]
    hmax = A[i]
  elif A[i] > A[i+1]:
    hmax = A[i]
    hmin = A[i]
  else:
    hmin = 1
  H[i][0] = max(hmin,H[i][0])
  H[i][1] = min(hmax,H[i][1])
  #print(H)

#print(H)
ans = 1
for i in range(N):
  if H[i][1] < H[i][0]:
    print(0)
    exit()
  ans *= (H[i][1] - H[i][0] + 1)
  ans %= 10 ** 9 + 7
print(ans)

Measured memory_bytes: 95332
#include<iostream>
using namespace std;
int main(){
int n,k,d,p,ans=0;
  cin>>n>>k;
  int a[n+1]={};
  a[0]=0;
  for(int i=0;i<k;i++){
    cin>>d;
    for(int j=0;j<d;j++){
      cin>>p;
      a[p]++;
     
    }
  }
  for(int i=1;i<=n;i++){
    if(a[i]==0) ans++;
  
  }
  cout<<ans<<endl;
  return 0;
}

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

using namespace std;

bool Match(const string &sub, const string &str, size_t start)
{
    for (size_t i = 0; i < sub.size(); i += 1) {
        if (sub[i] != str[start + i] && str[start + i] != '?') {
            return false;
        }
    }
    return true;
}

size_t FindSubPos(const string &str, const string &sub)
{
    if (sub.size() > str.size()) {
        return string::npos;
    }

    for (int i = str.size() - sub.size(); i >= 0; i -= 1) {
        if (Match(sub, str, i)) {
            return i;
        }
    }
    return string::npos;
}

void Apply(const string &sub, string &str, size_t start)
{
    for (size_t i = 0; i < sub.size(); i += 1) {
        if (str[start + i] == '?') {
            str[start + i] = sub[i];
        }
    }
}

string Solve(const string &str, const string &sub)
{
    auto pos = FindSubPos(str, sub);
    if (pos == string::npos) {
        return "UNRESTORABLE";
    }

    string res(str);
    Apply(sub, res, pos);
    Apply(string(res.size(), 'a'), res, 0);

    return res;
}

int main()
{
    string str, sub;
    getline(cin, str);
    getline(cin, sub);

    auto res = Solve(str, sub);
    cout << res << "\n";

    return 0;
}


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

int main()
{
    int N;
    int ans[4] = {0};
    string tmp = "";

    cin >> N;
    for (int i = 0; i < N; i++)
    {
        cin >> tmp;
        if (tmp == "AC") {
            ans[0]++;
        }
        else if (tmp == "WA") {
            ans[1]++;
        }
        else if (tmp == "TLE") {
            ans[2]++;
        }
        else if (tmp == "RE") {
            ans[3]++;
        }
        else {}
    }

    cout << "AC x " << ans[0] << endl;
    cout << "WA x " << ans[1] << endl;
    cout << "TLE x " << ans[2] << endl;
    cout << "RE x " << ans[3] << endl;

    return 0;
}

Measured memory_bytes: 3624
from collections import deque,defaultdict,Counter
from itertools import accumulate
import bisect
from heapq import heappop,heappush
from fractions import gcd
from copy import deepcopy
import math
import queue
#import numpy as np
#import sympy as syp(素因数分解とか)
Mod = 1000000007
import sys

sys.setrecursionlimit(100000) 
  
def sieve_of_eratosthenes(n):
    if not isinstance(n,int):
        raise TypeError("n is not int")
    if n<2:
        raise ValueError("n is not effective")
    prime = [1]*(n+1)
    for i in range(2,int(math.sqrt(n))+1):
        if prime[i] == 1:
            for j in range(2*i,n+1):
                if j%i == 0:
                    prime[j] = 0
    res = []
    for i in range(2,n+1):
        if prime[i] == 1:
            res.append(i)
    return res

def factorial(i):
    if i == 1:
        return 1
    else:
        return i*factorial(i-1)
 
class UnionFind:
    def __init__(self,n):
        self.parent = [i for i in range(n+1)]
        self.rank = [0 for i in range(n+1)]
    
    def findroot(self,x):
        if x == self.parent[x]:
            return x
        else:
            y = self.parent[x]
            y = self.findroot(self.parent[x])
            return y
    
    def union(self,x,y):
        px = self.findroot(x)
        py = self.findroot(y)
        if px < py:
            self.parent[py] = px
        else:
            self.parent[px] = py
 
    def same_group_or_no(self,x,y):
        return self.findroot(x) == self.findroot(y)




def main(): #startline--------------------------------------------
    X,Y = map(int,input().split())
    A = [300000,200000,100000]
    B = [0]*(300)
    A += B
    if X == 1 and Y == 1:
        print(A[X-1]+A[Y-1]+400000)
    else:
        print(A[X-1]+A[Y-1])
if __name__ == "__main__":
    main() #endline===============================================
    

Measured memory_bytes: 5688
import numpy as np

def input_numbers():
    temp = list(map(int, input().split()))
    return temp

temp = input_numbers()

n = temp[0]
m = temp[1]

like = []
for i in range(n):
    like += [input_numbers()]

ls = []
for i in range(m + 1):
    ls += [0]

for i in range(n):
    for j in range(1, like[i][0] + 1):
        ls[like[i][j]] += 1

count = 0

for i in ls:
    if(i == n):
        count += 1

print(count)


Measured memory_bytes: 21116
from copy import *
from sys import *
import math
import queue
from collections import defaultdict,Counter,deque
from fractions import Fraction as frac

setrecursionlimit(1000000)

#dp[i][j]: iまでからj枚えらんで和がkになるのは何通り
def main():
	n,a,b =  map(int,input().split())
	print(b if b < a*n else a*n)

def zip(a):
	mae = a[0]
	ziparray = [mae]
	for i in range(1,len(a)):
		if(mae != a[i]):
			ziparray.append(a[i])
			mae = a[i]
	return ziparray

def is_prime(n):
	if n < 2: return False

	for k in range(2, int(math.sqrt(n)) + 1):
		if n % k == 0:
			return False

	return True

def list_replace(n,f,t):
	return [t if i==f else i for i in n]

def base_10_to_n(X, n):
	X_dumy = X
	out = ''
	while X_dumy>0:
		out = str(X_dumy%n)+out
		X_dumy = int(X_dumy/n)
	if(out == ''): return '0'
	return out

def gcd(m,n):
	x = max(m,n)
	y = min(m,n)
	while(x%y!=0):
		z = x%y
		x = y
		y = z
	return y

class queue():
	def __init__(self):
		self.q = deque([])
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.popleft()
	def size(self):
		return len(self.q)
	def debug(self):
		return self.q

class stack():
	def __init__(self):
		self.q = []
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.pop()
	def size(self):
		return len(self.q)
	def debug(self):
		return self.q

class graph():
	def __init__(self):
		self.graph = defaultdict(list)
	def addnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].append(t)
		self.graph[t].append(f)
	def rmnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].remove(t)
		self.graph[t].remove(f)
	def linked(self,f):
		return self.graph[f]

class dgraph():
	def __init__(self):
		self.graph = defaultdict(set)
	def addnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].append(t)
	def rmnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].remove(t)
	def linked(self,f):
		return self.graph[f]

main()

Measured memory_bytes: 63212
#include <bits/stdc++.h>
using namespace std;
int main(){
bool a,b,c;
a=false;
b=false;
c=false;
string S;
cin>>S;
for(int i=0; i<3; i++){
    if(S.at(i)=='a'){
        a=true;
    }
    else if(S.at(i)=='b'){
        b=true;
    }
    else if(S.at(i)=='c'){
        c=true;
    }
}
if(a==true&&b==true&&c==true){
    cout<<"Yes"<<endl;
}
else
{
    cout<<"No"<<endl;
}

}


Measured memory_bytes: 3620
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int H1,M1,H2,M2,K;
    
    scanf("%d %d %d %d %d",&H1,&M1,&H2,&M2,&K);
    
    printf("%d\n", (H2*60+M2)-(H1*60+M1)-K);
}


Measured memory_bytes: 3816
#include<bits/stdc++.h>
using namespace std;
const int N=200005;
int b;
int n;
int a[N];
int x;
int main()
{
	scanf("%d",&n);
	b=1;
	for(int i=1;i<=n;i++){
		scanf("%d",&x);
		a[n/2+(i/2)*b]=x;
		b=-b;
	}
	if(n%2==0)for(int i=0;i<n;i++)cout<<a[i]<<' ';
	else for(int i=n-1;i>=0;i--)cout<<a[i]<<' ';
}

Measured memory_bytes: 2944
#include <algorithm>
#include <deque>
#include <iostream>
#include <map>
#include <tuple>
#include <vector>

#define INF 1000000000
#define rep(i, n) for (int i = 0; (i) < (n); (i)++)
using namespace std;
using ll = long long;

vector<pair<int, int>> P;
int N, M;
ll G[50][50];
ll TMP[50][50];

bool check(int i) {
  rep(i, N) rep(j, N) TMP[i][j] = G[i][j];

  auto a = P[i].first;
  auto b = P[i].second;
  TMP[a][b] = INF;
  TMP[b][a] = INF;

  rep(k, N) {
    rep(i, N) {
      rep(j, N) { TMP[i][j] = min(TMP[i][j], TMP[i][k] + TMP[k][j]); }
    }
  }

  bool ret  = false;
  rep(i, N) {
    rep(j, N) {
      if (TMP[i][j] == INF)
        ret = true;
    }
  }
  return ret;
}

int main(void) {
  cin >> N >> M;
  rep(i, N) rep(j, N) G[i][j] = INF;

  rep(i, M) {
    int a, b;
    cin >> a >> b;
    G[a - 1][b - 1] = 1;
    G[b - 1][a - 1] = 1;
    P.push_back({a-1, b-1});
  }
  int ret = 0;
  rep(i, M) {
    if(check(i)) {
      ret++;
    }
  }
  cout << ret << endl;   
  return 0;
}


Measured memory_bytes: 3716
#include <iostream>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <cassert>
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define RREP(i,n) for(int i=(n)-1; i>=0; --i)
#define SREP(i,s,n) for(int i=(s), i##_len=(n); i<i##_len; ++i)


using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

template <typename T>
T gcd(T a, T b) {
    if(a < b) gcd(b, a);
    if (b == 1) return 1;
    T r;
    while ((r=a%b)) {
        a = b;
        b = r;
    }
    return b;
}

bool comp(pair<int, int> a, pair<int, int> b) {
    return a.second > b.second;
}

struct UnionFind {
    vector<int> par;
    vector<int> rank;
    
    UnionFind(int n = 1) {
        init(n);
    }
    
    void init(int n = 1) {
        par.resize(n); rank.resize(n);
        for (int i = 0; i < n; ++i) {
            par[i] = i;
            rank[i] = 0;
        }
    }
    
    int root(int x) {
        if (par[x] == x) {
            return x;
        }
        else {
            int r = root(par[x]);
            return par[x] = r;
        }
    }
    
    bool issame(int x, int y) {
        return root(x) == root(y);
    }
    
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (rank[x] < rank[y]) swap(x, y);
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        return true;
    }
};

#define MOD (1000000007)

int main(int argc, const char * argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    string S, T;
    cin >> S >> T;
    int ans = 0;
    REP(i, 3) {
        ans += (S[i] == T[i]);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<vector>
#include<cstring>
#include<algorithm>
using namespace std;
const int INF=1e9+7;
const int N=1e6+3;
const int S=25000;

int n,k,sum;
int a[N];
bool vis[S];
int prime[S],pcnt;
int cnt[S];
vector<int>vec;

void Init() {
	for(int i=2;i<S;i++) {
		if(!vis[i]) prime[++pcnt]=i;
		for(int j=1;j<=pcnt&&i*prime[j]<S;j++) {
			vis[i*prime[j]]=true;
			if(i%prime[j]==0)
				break;
		}
	}
}
int ans;
int b[N];
void Check(int num) {
	for(int i=1;i<=n;i++)
		b[i]=a[i]%num;
	sort(b+1,b+n+1);
	int tot=0,l=1,r=n;
	while(l<r) {
		int dir=min(b[l],num-b[r]);
		tot+=dir;
		b[l]-=dir;
		b[r]+=dir;
		if(b[l]==0) l++;
		if(b[r]==num) r--;
	}
	if(tot<=k)
		ans=max(ans,num);
}
void Dfs(int pos,int num) {
	if(pos==vec.size()) {
		if(num>ans)
			Check(num);
		return ;
	}
	int id=vec[pos];
	Dfs(pos+1,num);
	for(int i=1;i<=cnt[id];i++)
		num*=prime[id],Dfs(pos+1,num);
}
int main() {
	Init();
	scanf("%d %d",&n,&k);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]),sum+=a[i];
	for(int i=1;i<=pcnt;i++) {
		if(sum%prime[i]==0) {
			vec.push_back(i);
			while(sum%prime[i]==0)
				sum/=prime[i],cnt[i]++;
		}
	}
	if(sum!=1) {
		prime[++pcnt]=sum,cnt[pcnt]=1;
		vec.push_back(pcnt);
	}
	Dfs(0,1);
	printf("%d\n",ans);
}

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

using namespace std;

#define MAX_V 101
#define MAX_E 1001
#define INF 1e9

struct Edge{
  int to,cost;
  Edge(int to,int cost) : to(to),cost(cost) {}
};

struct P{
  int d,v,c;
  P(int d,int v,int c) : d(d),v(v),c(c) {}
  bool operator < (const P &p)const{
    if(c != p.c){
      return c > p.c;
    }else{
      return d > p.d;
    }
  }
};

int V,E,C;
int d[MAX_V][MAX_E];
vector<Edge> G[MAX_V];

void init(){
  for(int i = 0 ; i < MAX_V ; i++){
    G[i].clear();
  }
}

int dijkstra(){
  fill(d[0],d[0]+MAX_V*MAX_E,INF);
  d[0][0] = 0;
  priority_queue<P> Q;
  Q.push(P(0,0,0));
  while(!Q.empty()){
    P p = Q.top(); Q.pop();
    int v = p.v, c = p.c;
    if(d[v][c] < p.d){ continue; }
    if(v == V-1 && p.d <= C){ return c; }
    for(int i = 0 ; i < (int)G[v].size() ; i++){
      Edge e = G[v][i];
      if(d[v][c]+e.cost < d[e.to][c]){
        d[e.to][c] = d[v][c]+e.cost;
        Q.push(P(d[e.to][c],e.to,c));
      }
      if(d[v][c] < d[e.to][c+1]){
        d[e.to][c+1] = d[v][c];
        Q.push(P(d[e.to][c+1],e.to,c+1));
      }
    }
  }
  return -1;
}

int main(){
  int f,t,c;
  while(cin >> V >> E >> C,V){
    init();
    for(int i = 0 ; i < E ; i++){
      cin >> f >> t >> c;
      f--; t--;
      G[f].push_back(Edge(t,c));
    }
    cout << dijkstra() << endl;
  }
  return 0;
}

Measured memory_bytes: 1616
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, e) for (int i = (int)(s); i <= (int)(e); i++)
#define printYesNo(is_ok) puts(is_ok ? "Yes" : "No");
#define SORT(v) sort(v.begin(), v.end());
#define RSORT(v) sort(v.rbegin(), v.rend());
#define REVERSE(v) reverse(v.begin(), v.end());
using ll = long long;
using P = pair<int, int>;

ll gcd(ll a, ll b)
{
  return b ? gcd(b, a % b) : a;
}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
template <typename T>
void printlnVector(T v)
{
  rep(i, v.size())
  {
    cout << v[i] << endl;
  }
}

template <typename T>
void printVector(T v)
{
  rep(i, v.size())
  {
    cout << v[i] << " ";
  }
  cout << endl;
}

int main()
{
  int K;
  cin >> K;
  ll ans = 0;

  rep(i_a, K) rep(i_b, K) rep(i_c, K)
  {
    ll n = gcd(i_a + 1, i_b + 1);
    ans += gcd(n, i_c + 1);
  }
  cout << ans << endl;
  return 0;
}

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

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef unordered_set<int> si;
typedef pair<int, int> pp;
typedef vector<pp> vpp;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#define all(e) (e).begin(), (e).end()
#define pb push_back

template <typename T>
bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

template <typename T>
bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}


template <typename T>
void printV(vector<T> A) {
  if (A.empty()) cerr << "EMTPY\n";
  else { 
    cerr << "[";
    for (int i = 0; i < A.size() -1 ; ++i) {
      cerr << A[i] << ", ";
    }
    if (A.size()) cerr << A.back() << "]\n";
  }
}


template <typename T>
void printVV(vector<vector<T>> A) {
  cerr << "[";
  for (auto v : A) {
    printV<T>(v);
  }
  cerr << "]";
}

template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << ": " << arg1 << endl;
}

template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&& ...args) {
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

int main(int argc, char **argv) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n, k; cin >> n >> k;
  vi arr(n+1);
  for (int i = 1; i <= n; ++i) {
    cin >> arr[i];
  }

  vector<ll> in(n+1);

  ll cur = 1;
  ll cycle = 0;
  ll timer = 0;
  while (k) {
    if (in[cur] != 0) {
      cycle = 1 + timer - in[cur];
      break;
    }
    in[cur] = ++timer;
    cur = arr[cur];
    k -= 1;
  }

  if (k) {
    k %= cycle;
    for (int i = 0; i < k; ++i) {
      cur = arr[cur];
    }
  }
  cout << cur << endl;

  return 0;
}



Measured memory_bytes: 5548
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>

#define to(k) E[k].to
#define next(k) E[k].next

using namespace std ;

const int N = 200010 ;

struct Edge{
    int to, next ;
}E[N * 2] ;
int n ;
int tot ;
int cnt ;
int q[N] ;
int p[N] ;
int d[N] ;
int fa[N] ;
int vis[N] ;
int dep[N] ;
int deg[N] ;
int head[N] ;

void add(int u, int v){
    to(++ cnt) = v, next(cnt) = head[u], head[u] = cnt ;
    to(++ cnt) = u, next(cnt) = head[v], head[v] = cnt ;
}
int dfs(int u, int faa){
    int ret = u, s ;
    fa[u] = faa, dep[u] = dep[faa] + 1 ;
    for (int k = head[u] ; k ; k = next(k)){
        if (to(k) != faa){
            s = dfs(to(k), u) ;
            if (dep[ret] < dep[s]) ret = s ;
        }
    }
    return ret ;
}
int main(){
    cin >> n ;
    int rt1, rt2, num, u, v ;
    for (int i = 1 ; i < n ; ++ i)
        scanf("%d%d", &u, &v), add(u, v) ;
    rt1 = dfs(1, 0) ; fa[rt1] = 0 ;
    dep[rt1] = 0 ; rt2 = dfs(rt1, 0) ;
    //cout << rt1 << " " << rt2 << endl ;
    for ( ; rt2 ; rt2 = fa[rt2])
        vis[rt2] = 1, d[++ tot] = rt2 ;
    //cout << tot << endl ;
    for (int i = 1 ; i <= n ; ++ i){
        if (vis[i]) continue ; bool ans = 0 ;
        for (int k = head[i] ; k ; k = next(k))
            if (vis[to(k)]) { deg[to(k)] ++, ans = 1 ; break ; }
        if (!ans) return puts("-1"), 0 ;
    }
    num = 0 ;
    for (int i = 1 ; i <= tot ; ++ i){
        for (int j = 1 ; j <= deg[d[i]] ; ++ j)
            p[num + j] = num + j + 1 ;
        p[num + deg[d[i]] + 1] = num + 1 ; num += deg[d[i]] + 1 ;
    }
    num = 0 ;
    for (int i = tot ; i >= 1 ; -- i){
        for (int j = 1 ; j <= deg[d[i]] ; ++ j)
            q[num + j] = num + j + 1 ;
        q[num + deg[d[i]] + 1] = num + 1 ; num += deg[d[i]] + 1 ;
    }
    for (int i = 1 ; i <= n ; ++ i)
        if (p[i] != q[i]){
            if (p[i] < q[i]){
                for (int j = 1 ; j <= n ; ++ j)
                    printf("%d ", p[j]) ; puts("") ;
                return 0 ;
            }
            else {
                for (int j = 1 ; j <= n ; ++ j)
                    printf("%d ", q[j]) ; puts("") ;
                return 0 ;
            }
        }
    for (int j = 1 ; j <= n ; ++ j)
        printf("%d ", p[j]) ; puts("") ;
    return 0 ; 
}


Measured memory_bytes: 12416
n,m=map(int,input().split())
ass=[tuple(map(int,input().split())) for i in range(m)]
ass.sort(key=lambda x:x[1])

reg = 0
counter = 0

for ab in ass:
    if ab[0]>=reg:
        counter = counter+1
        reg=ab[1]

print(counter)


Measured memory_bytes: 18248
//
#include <bits/stdc++.h>
using namespace std;
#define INF 1000000000
#define PI 3.14159265
#define EPS 1e-9
#define Pi acos(-1.0)
typedef pair<int, int> ii;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;
#define forr(i,a,b) for(int i=(a); i<(b); i++)
#define clean(arr,val) memset(arr,val,sizeof(arr))
#define forn(i,n) forr(i,0,n)
#define PB push_back
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<pll> vpll;

/*CODE START HERE*/

int n, ans, x;
string s;

int main(){
    ios::sync_with_stdio(0);
    cin >> n;
    cin >> s;
    ans = 0;
    forn(i,n){
        if(s[i] == 'I') x++;
        else x--;
        ans = max(x,ans);
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
/*
    Author:zeke
    
    pass System Test!
    GET AC!!
*/
#include <iostream>
#include <queue>
#include <vector>
#include <iostream>
#include <vector>
#include <string>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <map>
#include <iomanip>
#include <utility>
#include <stack>
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rep3(var, min, max) for (ll(var) = (min); (var) < (max); ++(var))
#define repi3(var, min, max) for (ll(var) = (max)-1; (var) + 1 > (min); --(var))
#define Mp(a, b) make_pair((a), (b))
#define F first
#define S second
#define Icin(s) \
    ll(s);      \
    cin >> (s);
#define Scin(s) \
    ll(s);      \
    cin >> (s);
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef vector<V> VV;
typedef vector<P> VP;
ll MOD = 1e9 + 7;
ll INF = 1e18;
ll n;
VV vec;
VV vec2;
VV res;
void dfs(int x, int prev, int prev1)
{
    V vec2;
    ll j = 1;
    rep(i, vec[x].size())
    {
        if(j==prev1){
            j++;
        }
        if(vec[x][i]==prev){
            continue;
        }
        res.push_back({x,vec[x][i],j});
        dfs(vec[x][i],x,j);
        j++;
    }
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    cin >> n;
    vec.resize(n);
    vec2.resize(n);
    map<pair<ll, ll>, ll> mp;
    rep(i, n - 1)
    {
        ll a, b;
        cin >> a >> b;
        a--;
        b--;
        vec[a].push_back(b);
        vec[b].push_back(a);
        mp[{a, b}] = i;
    }
    ll Max = 0;
    rep(i, n - 1)
    {
        chmax(Max, (ll)vec[i].size());
    }
    cout << Max << endl;
    V vec5;
    dfs(0, -1,-1);
    V res2(n);
    rep(i,n-1){
        res2[mp[{res[i][0], res[i][1]}]] = res[i][2];
    }
    rep(i,n-1){
        cout << res2[i] << endl;
    }
}


Measured memory_bytes: 21424
#include<stdio.h>
typedef long long LL;
int sz=0;
LL IN(void)
{
  LL x=0;int f=0,c=getchar();while(c<48||c>57){f^=c==45,c=getchar();}
  while(c>47&&c<58){x=x*10+c-48,c=getchar();}return f?-x:x;
}
int main(void)
{
  LL N=IN();int str[12];
  while(N){N--;str[sz++]='a'+N%26;if(str[sz-1]<97){sz--;str[sz]='z';}N/=26;}
  for(int i=sz-1;i>=0;i--)printf("%c",str[i]);
}

Measured memory_bytes: 1512
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double dbl;
#define sqr(int) (int * int)
#define sqr3(int) (int * int * int)
#define pi M_PI
#define nl "\n"



  float a,sum=0;
  int main(){
	ios::sync_with_stdio(true);
	cin.tie(0);
	cin >> a;
	for(int i = 1; i<=a; i++){
		if(i%2 !=0 ){
			sum++;
		} 
	}
	
	
	printf("%.10f", sum/a);
	
	}

	
	


	



Measured memory_bytes: 3776
#include<bits/stdc++.h>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
#define endl '\n'
typedef long long ll;
typedef pair<ll,ll> pll;
typedef long double ld;
const ll inf=998244353;
const ll mod=998244353;
signed main(){
    ll n;cin>>n;
    vector<ll>a(n);
    ll sum=0;
    rep(i,n){
        cin>>a[i];
        sum^=a[i];
    }
    rep(i,n){
        cout<<(sum^a[i])<<' ';
    }
    cout<<endl;
}

Measured memory_bytes: 4840
import collections
N = int(input())
S = list(input())
C = collections.Counter(S)
ans = C['R'] * C['G'] * C['B']
for i in range(1, N - 1):
    b = S[i]
    ans -= sum(
        a != b and b != c and c != a for a, c in zip(S[i - 1::-1], S[i + 1:]))
print(ans)


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

//#define int long long
#define DBG 0
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)
#define all(c) c.begin(),c.end()
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);

//?????§??¬?´???°
int gcd(int x, int y) { return y ? gcd(y, x%y) : x; }

signed main() {
	string s; cin >> s;
	int dot = -1, l = -1, r = -1;
	string t = "";
	rep(i, 0, s.size()) {
		if (s[i] == '.')dot = i;
		else if (s[i] == '(')l = i;
		else if (s[i] == ')')r = i;
		else t += s[i];
	}
	if (l == -1) {
		int w = s.size() - dot - 1;
		dump(w);
		int a = stoi(t);
		int b = pow(10, w);
		int g = gcd(a, b);
		cout << a / g << "/" << b / g << endl;
	}
	else {
		dump(t);
		string u = t.substr(0, l - 1);
		dump(u);
		int a = stoi(t) - stoi(u);
		dump(a);
		int w = r - l - 1;
		dump(w);
		int b = (pow(10, w) - 1)*pow(10, (l - dot - 1));
		dump(b);
		int g = gcd(a, b);
		cout << a / g << "/" << b / g << endl;
	}
	return 0;
}

Measured memory_bytes: 3356
#include "bits/stdc++.h"
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(int i=0;i<n;i++)
#define rep3(i,a,b) for(int i=a;i>=b;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define tii tuple<int,int,int>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define edge(v,a,b) v[a].pb(b);v[b].pb(a);
ll MOD=1e9+7;
#define INF 1e9+7
#define N 400001
#define MAX_V 400010
#define vec vector<int>
#define ALL(c) (c).begin(),(c).end()
using namespace std;
int in() {int x;scanf("%d",&x);return x;}
ll lin() {ll x;scanf("%lld",&x);return x;}
template<typename A, size_t NNN, typename T>
void Fill(A (&array)[NNN], const T &val){
    fill( (T*)array, (T*)(array+NNN), val );
}
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
#define umap unordered_map<ll,int,custom_hash>
struct pair_hash
{
    template<class T1,class T2>
    size_t operator() (const pair<T1,T2> &p)const{
        return hash<T1>()(p.first)^hash<T2>()(p.second);
    }
};


main(){
    int n=in();
    n=25-n;
    cout<<"Christmas ";
    while(n){
        cout<<"Eve ";
        n--;
    }
}

Measured memory_bytes: 256
#include <cstdio>

const int MN = 505;

int N, M;
char A[MN][MN], B[MN][MN], C[MN][MN];

int main() {
	scanf("%d%d", &N, &M);
	for (int i = 1; i <= N; ++i) {
		scanf("%s", A[i] + 1);
		for (int j = 1; j <= M; ++j) {
			(i & 1 ? B : C)[i][j] = '#';
			(i & 1 ? C : B)[i][j] = '.';
		}
		B[i][1] = C[i][M] = '#';
		B[i][M] = C[i][1] = '.';
		for (int j = 1; j <= M; ++j)
			if (A[i][j] == '#')
				B[i][j] = C[i][j] = '#';
	}
	for (int i = 1; i <= N; ++i) printf("%s\n", B[i] + 1); puts("");
	for (int i = 1; i <= N; ++i) printf("%s\n", C[i] + 1);
	return 0;
}

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

int main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  vector<int> a;
  int N;
  cin >> N;
  int temp = N;

  while(N--)
  {
    int x;
    cin >> x;
    a.push_back(x);
  }

  int x = 1;
  int count = 0;
  for ( auto i : a )
  {
    if ( i != x )
      count++;
    else
      x++;
  }

  if (count == temp )
    cout << -1 << endl;
  else
    cout << count << endl;
  
  return 0;
}


Measured memory_bytes: 1400
// B.

#include <iostream>
#include <algorithm>
#include <sstream>
#include <cstdio>
#include <cstring>

using namespace std;

typedef long long LL;

int main(int argc, char *argv[])
{
	LL n, a, b, c, d;
	cin >> n >> a >> b >> c >> d;
	bool ans = false;
	for (LL i = 0; i <= (n - 1); ++i) {
		LL p = a + i * c - (n - 1 - i) * c;
		LL q = (d - c) * i;
		LL r = (d - c) * (n - 1 - i);
		if ((p - r) <= b && b <= p + q) {
			ans = true;
			break;
		}
	}
	cout << (ans ? "YES" : "NO") << endl;
	return 0;
}


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

int main(){
    string s;
    cin >> s;
    int a[s.size()];
    for(int i=0;i<s.size();i++){
        a[i]=s[i]-'0';
    }
    int cnt=0;
    for(int i=1;i<s.size();i++){
        if(a[i-1]==0&&a[i]==0){
            a[i]=1;
            cnt++;
        }
        if(a[i-1]==1&&a[i]==1){
            a[i]=0;
            cnt++;
        }
    }
    cout << cnt << endl;
}


Measured memory_bytes: 896
n=int(input())
F=[int(input().replace(' ',''),2) for i in range(n)]
P=[list(map(int,input().split())) for i in range(n)]
ans=-10**10
 
for i in range(1,2**10):
  a=0
  for f,p in zip(F,P):
    a+=p[bin(f&i).count('1')]
  ans=max(ans,a)
print(ans)

Measured memory_bytes: 3064
n, k = map(int, input().split())
k -= 1

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

ans = float("inf")
for i in range(n):
    if i + k >= n:
        continue
    d = abs(x[i] - x[i + k]) + min(abs(x[i]), abs(x[i + k]))
    ans = min(ans, d)

print(ans)

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

int gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }
int lcm(int x, int y) { return x / gcd(x, y) * y; }

int main() {
  int n, a, b;
  cin >> n >> a;
  for (int i = 1; i < n; i++) {
    cin >> b;
    a = lcm(a, b);
  }
  cout << a << endl;

  return 0;
}


Measured memory_bytes: 3100
#include <stdio.h>
int main(void){
    int c1,c2,c3,i,cnt;
    
    while(scanf("%d %d %d",&c1,&c2,&c3)!=EOF){
        for(i=1,cnt=0;i<=10;i++){
            if(i==c1||i==c2||i==c3){
                continue;
            }
            if(c1+c2+i<=20){
                cnt++;
            }
        }
        if(cnt<4)puts("NO");
        else puts("YES");
    }
    return 0;
}

Measured memory_bytes: 576
using System;
using System.Collections.Generic;

namespace CompetitiveProgramming
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split(' ');
            Console.WriteLine(int.Parse(str[0]) + (int.Parse(str[1])/2));

        }
    }
}


Measured memory_bytes: 11092
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		
		Scanner scan = new Scanner(System.in);
		int time = scan.nextInt();
		
		int s = time % 60;
		time -= s;
		
		int h = time / 3600;
		time -= h * 3600;
		
		int m = time / 60;
		
		
		System.out.println(h + ":" + m + ":" + s);
		
	}

}

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

int dp[2054360];
int a[2][4]= {0,1,2,3,4,5,6,7};
int mov[4][2] = {1,0,0,-1,-1,0,0,1};

int encode()
{
    return a[0][0]*262144+a[0][1]*32768+a[0][2]*4096+a[0][3]*512+a[1][0]*64+a[1][1]*8+a[1][2];
}

void dfs(int x,int y,int ord)
{
    dp[encode()] = ord;
    for(int i=0; i<4; i++)
    {
        int tx = x + mov[i][0], ty = y + mov[i][1];
        if(tx >= 0 && tx < 2 && ty >= 0 && ty < 4)
        {
            swap(a[x][y],a[tx][ty]);
            if(dp[encode()] > ord+1)
                dfs(tx, ty, ord+1);
            swap(a[x][y], a[tx][ty]);
        }
    }
    return;
}

int main()
{
    for(int i=0;i<2054360;i++) dp[i] = 70;
    dfs(0,0,0);
    while(~scanf("%d%d%d%d%d%d%d%d",&a[0][0],&a[0][1],&a[0][2],&a[0][3],&a[1][0],&a[1][1],&a[1][2],&a[1][3]))
    {
        int tx,ty;
        printf("%d\n",dp[encode()]);
    }
    return 0;
}

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

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<=(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define Eback(s) s.erase(s.end()-1,s.end())
#define rev(v) reverse(all(v))
#define minvec(v) *min_element(all(v))
#define maxvec(v) *max_element(all(v))
#define sumvec(v) accumulate(all(v),0)
#define mapmax(v) v.rbegin()->first
#define mapmin(v) v.begin()->first
#define pb push_back
#define pf push_front
#define mod 1000000007
#define m_p make_pair
#define DOUBLE fixed << setprecision(15)
#define OK puts("OK")
#define OK1 puts("OK1")
#define OK2 puts("OK2")
#define SIZE(s) (int)s.size()
#define INF ((1LL<<62)-(1LL<<31))
#define zero(x,n) setw(x) << setfill('0') << n

typedef long long ll;

typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<double> vd;
typedef vector<char> vc;
typedef vector<string> vs;

typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
typedef vector<pair<ll,ll>> vpll;

const double pi = acos(-1.0);

template<class A, class B>
ostream& operator<<(ostream& ost, const pair<A, B>&p) {
	ost << "{" << p.first << ", " << p.second << "} ";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost, const vector<T>&v) {
	ost << "{";
	for (int i = 0; i<(int)v.size(); i++) {
		if (i)ost << " ";
		ost << v[i];
	}
	ost << "} \n";
	return ost;
}

template<class A, class B>
ostream& operator<<(ostream& ost, const map<A, B>&v) {
	ost << "{";
	for (auto p:v) {
		ost << "{" << p.first << ", " << p.second << "} ";
	}
	ost << "} ";
	return ost;
}

template<class T>
inline bool chmax(T& a, T b){if(a<b){a=b;return true;} return false;}

template<class T>
inline bool chmin(T& a, T b){if(a>b){a=b;return true;} return false;}

void YES(bool b) {cout << (b?"YES\n":"NO\n");}
void Yes(bool b) {cout << (b?"Yes\n":"No\n");}
void yes(bool b) {cout << (b?"yes\n":"no\n");}
void Yay(bool b) {cout << (b?"Yay!\n":":(\n");}

ll gcd(ll x, ll y) {return __gcd(x,y);}
ll lcm(ll x, ll y) {return x/__gcd(x,y)*y;}

int main()
{
	ll a,b,c;
	cin >> a >> b >> c;
	cout << c << " " << a << " " <<  b << endl;
	return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using static System.Math;
using System.Numerics;
static class Program{
	const int mod=(int)1e9+7;
	static void Main(){
		Sc sc=new Sc();
		var s=sc.Ia;
		long p=s[1],a=s[0],c=0;
		while(a!=0){
			a/=p;
			c++;
		}
		Console.WriteLine(c);
	}
}
public class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
	public object[] Oa{get{return Console.ReadLine().Split();}}
	public int[] Ia2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),int.Parse);}}
	public int[] Ia3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),int.Parse);}
	public int[] Ia3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),int.Parse);}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),long.Parse);}}
	public long[] La3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),long.Parse);}
	public long[] La3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),long.Parse);}
	public double[] Da2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),double.Parse);}}
	public double[] Da3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),double.Parse);}
	public double[] Da3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),double.Parse);}
	public T[] Arr<T>(int n,Func<T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f();}return a;}
	public T[] Arr<T>(int n,Func<int,T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i);}return a;}
	public T[] Arr<T>(int n,Func<string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(Console.ReadLine().Split());}return a;}
	public T[] Arr<T>(int n,Func<int,string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i,Console.ReadLine().Split());}return a;}
}

Measured memory_bytes: 11220
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>

using namespace std;

struct node{

    int key;
    node *right, *left, *parent;

};

node *NIL, *root;

void insert( int k ){

    node *y = NIL;
    node *x = root;
    node *z;

    z = ( node * )malloc( sizeof(node) );

    z -> key = k;
    z -> left = NIL;
    z -> right = NIL;

    while( x != NIL ){

        y = x;

        if( z -> key < x -> key ){

            x = x -> left;

        } else {

            x = x -> right;

        }

    }

    z -> parent = y;

    if( y == NIL ){

        root = z;

    } else {

        if( z-> key < y -> key ){

            y -> left = z;

        } else{

            y -> right = z;

        }

    }

}


void inorder( node *u ){

    if( u == NIL ) return;
    inorder( u -> left );
    printf(" %d", u -> key );
    inorder( u -> right );

}

void preorder( node *u ){

    if( u == NIL ) return;
    printf(" %d", u -> key );
    preorder( u -> left );
    preorder( u -> right );   

}


int main(){

    int n, i, x;
    string com;

    scanf("%d", &n);

    for( i = 0 ; i < n ; i++ ){

        cin >> com;

        if( com == "insert" ){

            scanf("%d", &x);
            insert(x);

        } else if( com == "print" ){

            inorder( root );
            printf("\n");
            preorder( root );
            printf("\n");

        }

    }

    return 0;

}




Measured memory_bytes: 26740
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<int> a(n+1,0);
  int ans=0,b;
  for(int i=0;i<n;i++){
    cin >> b;
    if(n<b)ans++;
    else a[b]++;
  }
  for(int i=1;i<=n;i++){
    if(a[i]>i)ans+=a[i]-i;
    else if(a[i]<i)ans+=a[i];
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
signed main(){
	long long n,a,b,l,r,sa,sb;
  	cin>>n>>a>>b;
  	if( (b - a) % 2  == 0)
      	cout<<(b-a)/2<<endl;
  
  	else{
      sa=a,sb=b;
      l=sa;
      sb-=sa;
      l+=(sb-1)/2;
      
      sa=a,sb=b;
      r=n-sb+1;
      sa+=n-sb+1;
      r+=(n-sa)/2;
      cout<<min(l,r)<<endl;
    }
    return(0); 
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstring>
#include <iomanip>

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) v.erase(unique(v.begin(), v.end()), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

#define MAX_V 1000000
#define MAX_N 20
int n, k;
int a[MAX_N];
int tmpA[MAX_N];

void input() {
  cin >> n >> k;
  rep(i, 0, n) cin >> a[i];
}

void init() {
  rep(i, 0, n) tmpA[i] = a[i];
}

void solve() {
  ll rsl = 1e18;
  for(int bit = 0; bit < 1 << n; ++bit) {
    init();
    ll tmp = 0;
    int viewable = 1;
    int max_v = tmpA[0];
    rep(i, 1, n) {
      if(bit & (1 << i)) {
        if(tmpA[i] <= max_v) {
          tmp += max_v - tmpA[i] + 1;
          tmpA[i] = max_v + 1;
        }
        chmax(max_v, tmpA[i]);
        ++viewable;
      } else {
        if(tmpA[i] > max_v) {
          ++viewable;
          max_v = tmpA[i];
        }
      }
    }
    if(viewable >= k) chmin(rsl, tmp);
  }
  cout << rsl << endl;
}


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


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

string s;
bool b;

int main()
{
    cin>>s;
    b=true;
    for (int i=0;i<s.size();i++)
    {
        if (i%2==0)
        {
            if (s[i]=='L') b=false;
        }
        else
        {
            if (s[i]=='R') b=false;
        }
    }
    if (b) cout<<"Yes";
    else cout<<"No";
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <math.h>
#include <string>
#include <numeric>
#include <algorithm>
#include <utility>


using std::cout;
using std::cin;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;


ll gcd(ll a, ll b) {
    while (b != 0) {
        auto tmp = a;
        a = b;
        b = tmp % a;
    }
    return a;
}

ll lcm(ll a, ll b) {
    return (a * b) / gcd(a, b);
}

int isPrime(int a) {
    for (int i = 2; i * i <= a; ++i) {
        if (a % i == 0) {
            return 0;
        }
    }
    return 1;
}





void oneCase () {
    int n, w;
    cin >> n >> w;
    vector<int> wgt(n);
    vector<int> val(n);
    for (int i = 0; i < n; ++i) {
        cin >> wgt[i] >> val[i];
    }
    map<ll, ll> maxVal;
    maxVal[0] = 0;
    for (int sub = 0; sub < n; ++sub) {
        map<ll, ll> newMax;

        for (auto p : maxVal) {
            auto weight = p.first;
            auto cost = p.second;
            if (newMax.count(weight) == 0) {
                newMax[weight] = cost;
            } else {
                newMax[weight] = max(cost, newMax[weight]);
            }

            if (weight + wgt[sub] > w) {
                continue;
            }
            if (newMax.count(weight + wgt[sub]) == 0 ) {
                newMax[weight + wgt[sub]] = cost + val[sub];
            } else {
                newMax[weight + wgt[sub]] = max(newMax[weight + wgt[sub]], cost + val[sub]);
            }
        }


        swap(maxVal, newMax);
    }
    ll best = 0;
    for (auto p : maxVal) {
        if (p.first <= w) {
            best = max(best, p.second);
        }
    }
    cout << best << "\n";

}





int main() {
    int t = 1;
//    cin >> t;
    while (t > 0) {
        oneCase();
        --t;
    }

    return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<queue>
#include<bitset>
#include<algorithm>
#include<climits>
#include<vector>
#include<deque>
#include<cmath>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define fill(x,y) memset(x,y,sizeof(x))
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define dump(a) rep(i,a.size()){ cout<<a[i]<<" "; } cout<<endl;
#define dumparr(a,n) rep(i,n){ cout<<a[i]<<" "; } cout<<endl;
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define INF INT_MAX/3
#define EPS 1e-7

/* 基本的にダイクストラ
 * nodeをバリアの中心点、edgeを全点間に張って、その長さを(中心同士の距離-半径二つ)とする
 * O(n^2)
 */

int main(){
  ll xs,ys, xt,yt;
  ll n;
  ll x[1003], y[1003], r[1003];
  cin>>xs>>ys>>xt>>yt>>n;
  rep(i,n){
    cin>>x[i]>>y[i]>>r[i];
  }
  // x[0]~x[n-1]は点, x[n]がstart, x[n+1]がend
  x[n]=xs; y[n]=ys; r[n]=0;
  x[n+1]=xt; y[n+1]=yt; r[n+1]=0;

  // ダイクストラ
  double d[1003]; // sからの最小距離
  bool used[1003];
  rep(i,n+2) d[i]=1e200;
  fill(used, false);
  d[n] = 0;
  while(true) {
    /* dumparr(used, n+2); */
    /* dumparr(d,n+2); */
    ll v = -1; // 残ってるうちで最短のもの
    rep(i,n+2){
      if(!used[i] && (v == -1 || d[i] < d[v])) v = i;
    }
    /* dbg(v); */
    if(v==-1) break; // 終わり
    used[v] = true;
    rep(u,n+2) { 
      /* dbg(sqrt((x[u]-x[v])*(x[u]-x[v])+(y[u]-y[v])*(y[u]-y[v]))); */
      double dist = mmax(0, sqrt((x[u]-x[v])*(x[u]-x[v])+(y[u]-y[v])*(y[u]-y[v]))-r[u]-r[v]);
      d[u] = mmin( d[u], d[v]+dist );
    }
  }
  /* dumparr(d, n+2); */
  printf("%.10f\n", d[n+1]);

  return 0;
}


Measured memory_bytes: 256
s = gets.chomp.chars

while str = s.pop(5).join
  break if str == ""
  if str == "erase"
  elsif str == "dream"
  elsif str == "eamer"
    if s.pop(2).join != "dr"
      puts "NO"
      exit
    end
  elsif str == "raser"
    if s.pop != "e"
      puts "NO"
      exit
    end
  else
    puts "NO"
    exit
  end
end

puts "YES"


Measured memory_bytes: 11260