akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(x) ;
#else
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

template <typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
  out << "{" << p.first << ", " << p.second << "}";
  return out;
}

template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010


int main(){
  int N;

  ll a = 1, b = 0;

  cin >> N;

  for(int i=0; i<N; i++) {
    int q, x;
    cin >> q >> x;

    if (q == 1) {
      a *= x; b *= x;
    }

    if (q == 2) {
      b += x;
    }

    if (q == 3) {
      b -= x;
    }
  }

  cout << -b << " " << a << endl;

  return 0;
}



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

import array
from bisect import *
from collections import *
import fractions
import heapq 
from itertools import *
import math
import random
import re
import string
import sys

N, M = map(int, input().split())

# 実はdicts[0], dicts[N-1]だけあれば十分
dicts = [set() for _ in range(N)]
for m in range(M):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    dicts[a].add(b)
    dicts[b].add(a)

# 島1 -> どこかの島 -> 島Nというルートが可能
if dicts[0] & dicts[N-1]:
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')


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

using namespace std;

// Function come here..
int foo(string s)
{
    int sum = 0;
    string ss;

    for (const auto e : s)
    {
        ss = e;
        sum += stoi(ss);
    }
    return sum;
}

int main(int argc, char **argv)
{
    // Problem solution come here...
    string s;
    cin >> s;

    if (stoi(s) % foo(s) == 0)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

#define N 100

int main() {
	static int aa[N];
	int n, d, x, i, j, sum;

	scanf("%d%d%d", &n, &d, &x);
	for (i = 0; i < n; i++)
		scanf("%d", &aa[i]);
	sum = 0;
	for (i = 0; i < n; i++) {
		int cnt;

		cnt = 0;
		for (j = 0; j < d; j += aa[i])
			cnt++;
		sum += cnt;
	}
	printf("%d\n", sum + x);
	return 0;
}


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

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

void solve(long long N, std::vector<std::vector<long long>> D)
{

    string ans = "No";
    ll cnt = 0;
    for (ll i = 0; i < N; i++)
    {
        if (D[i][0] == D[i][1])
        {
            cnt++;
            if (cnt == 3)
            {
                ans = "Yes";
                break;
            }
        }

        else
        {
            cnt = 0;
        }
    }
    cout << ans << endl;
}

signed main()
{
    long long N;
    scanf("%lld", &N);
    std::vector<std::vector<long long>> D(N, std::vector<long long>(2));
    for (int i = 0; i < N; i++)
    {
        for (int j = 0; j < 2; j++)
        {
            scanf("%lld", &D[i][j]);
        }
    }
    solve(N, std::move(D));
    return 0;
}


Measured memory_bytes: 3692
while True:
    m, f, r = map(int, input().split())
    if m < 0 and f < 0 and r < 0:
        break

    if m < 0 or f < 0:
        grade = 'F'
    elif m + f >= 80:
        grade = 'A'
    elif m + f >= 65:
        grade = 'B'
    elif m + f >= 50:
        grade = 'C'
    elif m + f >= 30:
        if r >= 50:
            grade = 'C'
        else:
            grade = 'D'
    else:
        grade = 'F'
    print(grade)



Measured memory_bytes: 5592
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        double a = sc.nextDouble();
        double b = sc.nextDouble();
        double x = sc.nextDouble();
        //半分以下の場合
        if (x / (a * a) <= b / 2) {
            double y = 2 * x / (a * b);
            double r = Math.atan(b / y);
            double ans = Math.toDegrees(r);
            System.out.println(ans);
        } else {
            double y = 2 * x / (a * a) - b;
            double r = Math.atan((b - y) / a);
            double ans = Math.toDegrees(r);
            System.out.println(ans);
        }



       


    }

}


Measured memory_bytes: 24404
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define ld long double
#define INF 1000000000000000000
typedef pair<ll, ll> pll;

class UnionFind {
  public:
    vector<ll> par; // 各元の親を表す配列
    vector<ll> siz; // 素集合のサイズを表す配列(1 で初期化)

    // Constructor
    UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i)
            par[i] = i; // 初期では親は自分自身
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL); // resize だとなぜか初期化されなかった
        for (ll i = 0; i < sz_; ++i)
            par[i] = i; // 初期では親は自分自身
    }

    // Member Function
    // Find
    ll root(ll x) { // 根の検索
        while (par[x] != x) {
            x = par[x] = par[par[x]]; // x の親の親を x の親とする
        }
        return x;
    }

    // Union(Unite, Merge)
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y)
            return false;
        // merge technique（データ構造をマージするテク．小を大にくっつける）
        if (siz[x] < siz[y])
            swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) { // 連結判定
        return root(x) == root(y);
    }

    ll size(ll x) { // 素集合のサイズ
        return siz[root(x)];
    }
};

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

    int N, M;
    cin >> N >> M;
    UnionFind tree(N);
    rep(i, M) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        tree.merge(a, b);
    }

    ll ans = 0;
    rep(i, N) { ans = max(ans, tree.size(i)); }

    cout << ans << endl;
}

Measured memory_bytes: 6348
#include<bits/stdc++.h>
using namespace std;
deque <int> q;
int d[100005];
int k;
int main()
{
	cin>>k;
	q.push_back(1);
	for(int i=0;i<k;i++)
	    d[i]=2e9;
	d[1]=0;
	while(q.size())
	{
		int t=q.front();
		//cout<<t<<endl;
		q.pop_front();
		int f=(t*10)%k;
		if(d[f]>d[t])
		{
			d[f]=d[t];
			q.push_front(f);
		}	    
		f=(t+1)%k;
		if(d[t]+1<d[f])
		{
			d[f]=d[t]+1;
			q.push_back(f);
		}
	}
	cout<<d[0]+1;
	return 0;
}

Measured memory_bytes: 896
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define NUM 1005
#define BIG_FLOW 50005


//辺を表す構造体{行先、容量、コスト、逆辺のインデックス}
struct Edge{
	Edge(int arg_to,ll arg_capacity,ll arg_cost,int arg_rev_index){
		to = arg_to;
		capacity = arg_capacity;
		cost = arg_cost;
		rev_index = arg_rev_index;
	}

	int to,rev_index;
	ll cost,capacity;
};

int V; //頂点数
vector<Edge> G[NUM]; //グラフの隣接リスト表現
int dist[NUM]; //最短距離
int pre_node[NUM],pre_edge[NUM]; //直前の頂点と辺
int in_num[NUM],out_num[NUM];


//fromからtoへ向かう容量capacity,コストcostの辺をグラフに追加する
void add_edge(int from,int to,int capacity,int cost){
	G[from].push_back(Edge(to,capacity,cost,G[to].size()));
	G[to].push_back(Edge(from,0,-cost,G[from].size()-1));
}

//sourceからsinkへの、流量flowの最小費用流を求める
//流せない場合は-1を返す
ll min_cost_flow(int source,int sink,ll flow){
	ll ret = 0;
	while(flow > 0){
		//ベルマンフォード方により、source-sink間最短経路を求める
		for(int i = 0; i < V; i++)dist[i] = BIG_NUM;
		dist[source] = 0;
		bool update = true;
		while(update){
			update = false;
			for(int node_id = 0; node_id < V; node_id++){
				if(dist[node_id] == BIG_NUM)continue;
				for(int i = 0; i < G[node_id].size(); i++){
					Edge &e = G[node_id][i];
					if(e.capacity > 0 && dist[e.to] > dist[node_id]+e.cost){
						dist[e.to] = dist[node_id]+e.cost; //node_idを経由した方が早い場合
						pre_node[e.to] = node_id;
						pre_edge[e.to] = i;
						update = true;
					}
				}
			}
		}

		if(dist[sink] == BIG_NUM){
			//これ以上流せない
			return -1;
		}

		//source-sink間最短路に沿って目いっぱい流す
		ll tmp_flow = flow;
		for(int node_id = sink; node_id != source; node_id = pre_node[node_id]){
			tmp_flow = min(tmp_flow,G[pre_node[node_id]][pre_edge[node_id]].capacity);
		}
		flow -= tmp_flow;
		ret += tmp_flow*dist[sink];
		for(int node_id = sink; node_id != source; node_id = pre_node[node_id]){
			Edge &e = G[pre_node[node_id]][pre_edge[node_id]];
			e.capacity -= tmp_flow;
			G[node_id][e.rev_index].capacity += tmp_flow;
		}
	}
	return ret;
}

int main(){

	int N;
	scanf("%d",&N);

	int source = N,sink = N+1;
	V = N+2;

	for(int i = 0; i < N; i++){
		in_num[i] = 0;
		out_num[i] = 0;
	}

	int tmp_num,from,to;
	int ans = 0;
	ll cost;

	for(from = 0; from < N; from++){

		scanf("%d",&tmp_num);

		for(int loop = 0; loop < tmp_num; loop++){

			scanf("%d %lld",&to,&cost);
			to--;
			add_edge(from,to,BIG_FLOW,cost);

			ans += cost;

			out_num[from]++;
			in_num[to]++;
		}
	}

	add_edge(source,0,BIG_FLOW,0);

	ll FLOW = 0;

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

		if(in_num[i] > out_num[i]){

			add_edge(source,i,in_num[i]-out_num[i],0);

		}else if(in_num[i] < out_num[i]){

			add_edge(i,sink,out_num[i]-in_num[i],0);
			FLOW += out_num[i]-in_num[i];
		}
	}

	ans += min_cost_flow(source,sink,FLOW);

	printf("%lld\n",ans);

	return 0;
}



Measured memory_bytes: 6104
#include <algorithm>
#include <iostream>
#include <iterator>
#include <limits>
#include <vector>

using namespace std;

using ll = long long;

ll solve(vector<ll> &va, vector<ll> &memo) {
  for (int i = 0; i < va.size(); ++i) {
    *upper_bound(memo.begin(), memo.end(), va[i]) = va[i];
  }

  auto r_it = lower_bound(memo.begin(), memo.end(), numeric_limits<ll>::max());
  return distance(memo.begin(), r_it);
}

int main(int argc, const char *argv[]) {
  int n;
  cin >> n;

  vector<ll> va(n);
  for (int i = 0; i < n; ++i) {
    cin >> va[i];
  }

  reverse(va.begin(), va.end());

  vector<ll> memo(n + 1, numeric_limits<ll>::max());
  cout << solve(va, memo) << '\n';
  return 0;
}

Measured memory_bytes: 1792
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<map>
#define fi first
#define se second
#define pb(i) push_back(i)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
#define mes(a,b) memset(a,b,sizeof(a))
#define sbs(i,j) substr(i,j)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N = 1e6+10;
const int INF = 0x3f3f3f3f;
const int inf = - INF;
const int mod = 1e9+7;
const double pi = acos(-1.0);


int main(){
    string o;
    string e;
    cin>>o>>e;
    int leno=o.size(),lene=e.size();
    int i=0,j=0;
    while(i!=leno||j!=lene){
        if(i<leno)cout<<o[i++];
        if(j<lene)cout<<e[j++];
    }
    cout<<endl;
    getchar();
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
int main() {
    int n, m;
    std::cin >> n >> m;
    std::vector<int> a(m), b(m);
    for (int i = 0; i < m; i++) {
        std::cin >> a[i] >> b[i];
    }
    std::vector<int> v(n), w(n);
    for (int i = 0; i < n; i++) {
        v[i] = 1;
        w[i] = i;
    }
    std::vector<long long> ans(m);
    long long connected = 0;
    for (int i = m - 1; i >= 0; i--) {
        ans[i] = (long long)n * (n - 1) / 2 - connected;
        int ai = a[i] - 1;
        int bi = b[i] - 1;
        int aj = ai, bj = bi;
        while (w[ai] != ai) {
            ai = w[ai];
        }
        while (w[bi] != bi) {
            bi = w[bi];
        }
        w[aj] = ai;
        w[bj] = bi;
        if (ai != bi) {
            int va = v[ai];
            int vb = v[bi];
            v[ai] = va + vb;
            w[bi] = ai;
            connected += (long long)va * vb;
        }
    }
    for (long long x: ans) {
        std::cout << x << std::endl;
    }
}

Measured memory_bytes: 3712
#include <stdio.h>
typedef struct{
    int s;
    int p;
}lamp;
int main()
{   int n,m;
    scanf("%d%d",&n,&m);
    lamp a[m];
    for(int i=0;i<m;i++)a[i].s=0;
    for(int i=0;i<m;i++){
        int k;
        scanf("%d",&k);
        for(int j=0;j<k;j++){
            int tmp=0;
            scanf("%d",&tmp);
            tmp--;
            a[i].s|=(1<<tmp);
        }
    }
    
    int ans=0;
    for(int i=0;i<m;i++)scanf("%d",&a[i].p);
    
    for(int i=0;i<(1<<n);i++){
        int flag=0;
        for(int j=0;j<m;j++){
            if(__builtin_parity(a[j].s&i)!=a[j].p){
                flag=1;
            }
        }
        if(flag==0){
            ans++;
        }
    }
    
    printf("%d",ans);
    return 0;
}


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

const int MAX_N = 8, MAX_M = MAX_N * (MAX_N - 1) / 2;

int N, M, a[MAX_M], b[MAX_M];

bool graph[MAX_N][MAX_N];

void solve() {
	for (int i = 0; i < M; i++) {
		graph[a[i] - 1][b[i] - 1] = true;
		graph[b[i] - 1][a[i] - 1] = true;
	}

	int ans = 0, perm[MAX_N - 1];
	for (int i = 0; i < N - 1; i++) {
		perm[i] = i + 1;
	}

	do {
		int pos = 0;
		bool ok = true;

		for (int i = 0; i < N - 1; i++) {
			if (!graph[pos][perm[i]]) {
				ok = false;
			}

			pos = perm[i];
		}

		if (ok) ans++;
	} while (next_permutation(perm, perm + N - 1));

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

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

	solve();
}

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

int main(){
    int n;
    cin >> n;
    vector<int> v(n);
    for(int i=0; i<n; i++) cin >> v[i];
    cout << *max_element(v.begin(), v.end()) - *min_element(v.begin(), v.end()) << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**7)
black = 0
white = 0
#x,y渡すと、（ｈ、ｗ）に入ってるかどうか判定
def check(s,t):
    if (0 <=  s <= h - 1) and (0 <= t <= w - 1):
        return True
    else:
        return False
def bfs(que):
    finished = set()
    while que:
        x , y, color = que.popleft()
        if x+y*w not in finished:
            finished.add(x+y*w)
            for i in range(-1,2,1):
                for j in range(-1,2,1):
                    if abs(i) + abs(j) < 2 and check(y+j,x+i):
                        if (x+i)+(y+j)*w not in finished:
                            que.append([x+i,y+j,grid[y+j][x+i]])
                        if color != grid[y+j][x+i]:
                            adjacent_list[x+w*y].append((x + i)+w*(y + j))
def dfs(node):
    global white
    global black
    finished.add(node)
    y,x = divmod(node,w)
    if grid[y][x] == '#':
        black += 1
    else:
        white += 1
    for i in adjacent_list[node]:
        if i not in finished:
            dfs(i)
from collections import deque
h,w = map(int, input().split())
grid = []
for i in range(h):
    grid.append(list(input()))
ans = 0
adjacent_list = [[] for i in range(h*w)]
"""
que = deque()
que.append([0,0,grid[0][0]])
bfs(que)
"""
for y in range(h):
    for x in range(w):
        for i in range(-1,2,1):
            for j in range(-1,2,1):
                if abs(i) + abs(j) < 2 and check(y+j,x+i):
                    if grid[y][x] != grid[y+j][x+i]:
                        adjacent_list[x+w*y].append((x + i)+w*(y + j))
#再び初期化
finished = set()
for i in range(h*w):
    #頂点iからdfsをする。黒と白をカウントしておいて最後にかける
    black = 0
    white = 0
    if i not in finished:
        dfs(i)
        ans += black * white
print(ans)

Measured memory_bytes: 193000
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vll = vector<long long>;
using vp = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
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 (b<a) {a=b; return 1;} return 0;}

long long gcd(long long a, long long b) { return b ? gcd(b, a%b) : a;}
long long lcm(long long a, long long b) { return a / gcd(a, b) * b;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int n;
    cin >> n;
    ll ans = 1;
    rep(i, n) {
        int a;
        cin >> a;
        ans = lcm(a, ans);
    }
    cout << ans << endl;
}



Measured memory_bytes: 3212
#include<bits/stdc++.h>
using namespace std;
int main(){
    long long x=753, mind=LLONG_MAX, yo;
    string asu;
    cin >> asu;
    for(int i = 0; i < asu.length()-2; ++i){
        yo = ((int)asu[i]-(int)'0')*100 + ((int)asu[i+1]-(int)'0')* 10 + ((int)asu[i+2]-(int)'0');
        mind = min(mind, abs(yo-x));
    }
    cout << mind << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
inline LL read() {
	LL x = 0, fh = 1;
	char c = getchar();
	while (c < '0' || c > '9') {
		if (c == '-') fh = -1;
		c = getchar();
	}
	while (c >= '0' && c <= '9') {
		x = (x << 1) + (x << 3) + c - '0';
		c = getchar();
	}
	return x * fh;
}
int n, i;
LL ans, x;
LL gcd(LL a, LL b) { return (b == 0 ? a : gcd(b, a % b)); }
LL lcm(LL a, LL b) { return max(a, b) / gcd(a, b) * min(a, b); }
int main() {
	n = read(); ans = read();
	for (i = 2; i <= n; i++) ans = lcm(ans, read());
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
      
#define FOR(i,a,b) for(ll i = (a); i < (ll)(b); i++)
#define REP(i,n) FOR(i,0,n)
#define YYS(x,arr) for(auto& x:arr)
#define PW(x) (1LL<<(x))
#define SZ(x) ((ll)(x).size())

#define pb emplace_back
#define fi first
#define se second

using namespace std;

using ld = long double;
using ll = long long int;

const ll INF = (ll)1e9 + 10;
const ll INFLL = (ll)1e18 + 10;
const ll MOD = 1e9+7;
     
template<class T> T &chmin( T &a , const T &b ){ return a = min(a,b); }
template<class T> T &chmax( T &a , const T &b ){ return a = max(a,b); }
template<class T> void UNIQUE(vector<T> &a){ a.erase(unique(a.begin(), a.end()), a.end()); }

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

ll in(){long long int x; assert(scanf("%lld", &x) == 1); return x;}
ld fin(){double x; assert(scanf("%lf", &x) == 1); return x;}
char yuyushiki[1000010]; string stin(){assert(scanf("%s", yuyushiki) == 1); return yuyushiki;}

// head

vector<ll> G[100010];
ll col[100010];

ll dfs1(ll x, ll p){
  ll c = 0;
  ll len = 0;
  ll od = 0;
  YYS(w, G[x]){
    if(w == p){
      continue;
    }
    len = dfs1(w, x) + 1;
    if(col[w] == 0){
      col[x] = 1;
    }
    c++;
    if(len >= 0 && len % 2 == 1){
      od++;
    }
  }
  if(od >= 2){
    puts("First");
    exit(0);
  }
  if(c <= 1){
    return len;
  }
  return -INFLL;
}

void dfs2(ll x, ll p, ll up){
  ll c = up;
  YYS(w, G[x]){
    if(w == p){
      continue;
    }
    c += 1 - col[w];
  }
  if(c == 0){
    // cout << x << endl;
    puts("First");
    exit(0);
  }
  YYS(w, G[x]){
    if(w == p){
      continue;
    }
    ll nc = c - (1 - col[w]);
    ll nup = 0;
    if(nc == 0){
      nup = 1;
    }
    dfs2(w, x, nup);
  }
}

int main(){

  ll n = in();

  REP(i, n-1){
    ll a = in() - 1;
    ll b = in() - 1;
    G[a].pb(b);
    G[b].pb(a);
  }

  dfs1(0, -1);
  dfs2(0, -1, 0);

  puts("Second");
  
  return 0;
}


Measured memory_bytes: 7936
N, M, X, Y = map(int, input().split())
x_list = [int(i) for i in input().split()]
y_list = [int(i) for i in input().split()]

for i in range(X+1, Y+1):
    for x in x_list:
        if x >= i:
            break
    else:
        for y in y_list:
            if y < i:
                break
        else:
            print("No War")
            exit()
print("War")

Measured memory_bytes: 3064
#include<iostream>
using namespace std;
int n;
int H[5000000];
void buildMaxHeap(void);
void maxHeapify(int);
int main()
{
 
  cin >> n;
  for(int i=1;i<n+1;++i){
    cin >> H[i];
  }
   buildMaxHeap();

  for(int i=1;i<n+1;++i){
    cout<<" "<<H[i]<<flush;
  }
  cout<<endl;
  return 0;
}

void buildMaxHeap()
{
  for(int i=n/2;i>0;--i){
    maxHeapify(i);
  }
}  

void maxHeapify(int i)
{
  int r,l,largest,tmp;
  l=i*2;
  r=i*2+1;

  if(l<=n&& H[l]>H[i])largest=l;
  else largest=i;

  if(r<=n && H[r]>H[largest])largest=r;

  if(largest!=i){
    tmp=H[i];
    H[i]=H[largest];
    H[largest]=tmp;
  
  maxHeapify(largest);
  }
}

Measured memory_bytes: 3116
#include <bits/stdc++.h>
#define rep(n) for (int I = 0; (I) < (n); ++(I) )
#define repeat(i, n) for( int i = 0; (i) < (n); ++(i) )
#define repeat_to(i, n) for( int i = 0; (i) <= (n); ++(i) )
#define repeat_from(i, m, n) for( int i = (m); (i) < (n); ++(i) )
#define repeat_from_to(i, m, n) for( int i = (m); (i) <= (n); ++(i) )
#define dump(x) cout << " " << #x << "=" << x
#define vdump(v) for(size_t T=0; T<v.size(); ++T){cout << " " << #v << "[" << T << "]=" << v[T];} cout << endl
using namespace std;
using lint = long long;
using ld = long double;

int main(void) {
    int w, a, b, ans;
    cin >> w >> a >> b;
    if (b+w < a) ans = a - (b+w);
    else if (a+w < b) ans = b - (a+w);
    else ans = 0;
    cout << ans << endl;
    return 0;
}

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

int main(){
  int n;
  int count = 0;
  cin >> n;
  vector<int> line(n);
  for (int i=0 ; i<n ; i++){
    cin >> line.at(i);
  }
  for (int i=0 ; i<n-2 ; i++){
    if(line.at(i) < line.at(i+1) && line.at(i+1) < line.at(i+2)){
      count ++;
    }
    else if(line.at(i) > line.at(i+1) && line.at(i+1) > line.at(i+2)){
      count ++;
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 256
import sys
n,k=map(int,input().split())
a=list(map(int,input().split()))
I=10**9+7

if sum(a)<k:
    print(0)
    sys.exit()

dp=[[float("inf")]*(k+1) for _ in range(n+1)]
for p in range(k+1):
    dp[0][p]=0
    if a[0]<p:
        dp[1][p]=0
    else:
        dp[1][p]=1
for i in range(1,n):
    s=[0]*(k+2)
    for j in range(k+1):
        s[j+1]=s[j]+dp[i][j]%I
        dp[i+1][j]=s[j+1]-s[max(0,j-a[(i+1)-1])]

print(dp[n][k]%I)

Measured memory_bytes: 314172
n = int(input())
c = input()

red = []
o = 1
r = 0
white = []
for i in c:
    if i == "W":
        white.append(o)
    if i == 'R':
       red.append(o);
       r += 1
    o+=1

w = n - r

rr = 0
for i in red:
    if i > r:
        rr += 1

print(rr)




Measured memory_bytes: 17448
import itertools
n,m,x=map(int,input().split())
dp=[list(map(int,input().split())) for _ in range(n)]
c=0
gg=0
mas=[0]*m
a=(0,1)
ans=100000000
b=list(itertools.product(a,repeat=n))
for i in b:
    gg=0
    c=0
    mas=[0]*m
    for h in range(n):
        if i[h]==1:
            c+=dp[h][0]
            for t in range(m):
                mas[t]+=dp[h][t+1]
    for y in mas:
        if y<x:
            gg=1
    if gg==0:
        ans=min(ans,c)
        
if ans!=100000000:       
    print(ans)
else:
  print("-1")

Measured memory_bytes: 9656
#include<bits/stdc++.h>
using namespace std;
int n,x,a[1000000],ans;
int read(){
	char c=getchar();while (c!='-'&&(c<'0'||c>'9'))c=getchar();
	int kk=1,k=0;if (c=='-')kk=-1,c=getchar();
	while (c>='0'&&c<='9')k=k*10+c-'0',c=getchar();return kk*k;
}
int main(){
	n=read();for (int i=1;i<=n;i++)x=read(),a[x]++,a[x+1]++,a[x+2]++;
	ans=0;for (int i=0;i<=200000;i++)ans=max(ans,a[i]);cout<<ans<<endl;
}


Measured memory_bytes: 640
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <set>

using namespace std;

#define rep(i,a,n) for(int (i)=a;(i)<(int)(n);(i)++)
#define rrep(i,a,n) for(int (i)=(n)-1;(i)>=a;(i)--)
#define all(x) (x).begin(),(x).end()

typedef long long ll;

int main() {
	int a,b,c;

	cin>>a>>b>>c;

	int ans = 0;

	rep(i,a,b+1) {
			if (c % i == 0) {
					ans++;
			}
	}

	cout << ans << endl;
}

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

int main() {
  int w, h, n, x, y, a;
  cin >> w >> h >> n;
  int s[w][h] = {};
  int xmax = w, xmin = 0, ymax = h, ymin = 0;
  for (int i = 0; i < n; i++) {
    cin >> x >> y >> a;
    if (a == 1) xmin = max(x, xmin);
    if (a == 2) xmax = min(x, xmax);
    if (a == 3) ymin = max(y, ymin);
    if (a == 4) ymax = min(y, ymax);
  }
  cout << ((xmax - xmin > 0) && (ymax - ymin > 0)
               ? (xmax - xmin) * (ymax - ymin)
               : 0)
       << endl;
}

Measured memory_bytes: 256
from itertools import combinations_with_replacement

n, m, q = map(int,input().split())

L =  [list(map(int,input().split())) for _ in range(q)]
com = list(combinations_with_replacement([i for i in range(1, m+1)], n))

ans = 0
for co in com:
    total = 0
    for a, b, c, d in L:
        if co[b-1] - co[a-1] == c:
            total += d
    ans = max(ans, total)
print(ans)

Measured memory_bytes: 21496
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;

#define REP(i,n) for(int (i)=0; (i)<(n); (i)++)
#define For(i,a,b) for(int (i)=(a); (i)<(b); (i)++)

void manhattan(vector<int> x, vector<int> y) {
    double s = 0;
    REP(i,x.size()) {
        s += abs(x[i] - y[i]);
    }
    printf("%6f\n", s);
}

void euclid(vector<int> x, vector<int> y) {
    double s = 0;
    REP(i,x.size()) {
        s += (x[i] - y[i]) * (x[i] - y[i]);
    }
    printf("%6f\n", sqrt(s));
}

void minkovski3(vector<int> x, vector<int> y) {
    double s = 0;
    REP(i,x.size()) {
        s += pow(abs(x[i] - y[i]), 3);
    }
    printf("%6f\n", pow(s, 1.0/3));
}

void chevishev(vector<int> x, vector<int> y) {
    double s = 0;
    REP(i,x.size()) {
        s = max(s, (double)abs(x[i] - y[i]));
    }
    printf("%6f\n", s);
}

int main() {
    int n;
    cin >> n;
    vector<int> x, y;
    REP(i,n) {
        int p;
        cin >> p;
        x.push_back(p);
    }
    REP(i,n) {
        int p;
        cin >> p;
        y.push_back(p);
    }
    manhattan(x,y);
    euclid(x,y);
    minkovski3(x,y);
    chevishev(x,y);
    return 0;
}

Measured memory_bytes: 1308
#include <iostream>
#include <vector>
#include <string>
#include <unordered_map>
#include <math.h>
#include <algorithm>
#include <deque>
#include <queue>
#include <climits>
#include <set>
using namespace std;
#define ll long long
#define ull unsigned long long
#define ve vector
#define umap unordered_map
#define iter iterator

void solve() {
    int x,y,z;cin>>x>>y>>z;
    cout << (x-z)/(y+z) << endl;
}

int main() {
    solve();
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll, ll> P;
using VP = vector<P>;
using VVP = vector<VP>;
using VI = vector<ll>;
using VVI = vector<VI>;
using VVVI = vector<VVI>;
const int inf = 1e9 + 7;
const ll INF = 1LL << 61;
const ll mod = 1e9 + 7;

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


int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int i, j;
    ll a;
    string s;
    cin>>a>>s;
    ll c = (s[0]-'0')*100+(s[2]-'0')*10+s[3]-'0';
    cout << a * c / 100 << endl;
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    ll h,ans=0,i=1;
    cin>>h;
    while(h>1)
    {
        i=2*i;
        ans+=i;
        h=h/2;
    }
    cout << ans+1 << endl;
    return 0;
}


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

int main(){
    int A,B;
    cin >> A >> B;
    int num = 1,i = 0;
    while(num < B){
        i++;
        num += A-1;
    }
    cout << i << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.util.*;

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

                if("Sunny".equals(h)){
                  weather = "Cloudy";
                } else if ("Cloudy".equals(h)){
                  weather = "Rainy";
                }
                System.out.println(weather);
    }
}


Measured memory_bytes: 21716
#include <bits/stdc++.h>
//#define int long long

using namespace std;
using LL = long long;
using P = pair<int, int>;

#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e18;
const int MOD = (int)1e9 + 7;

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b, c;
    cin >> a >> b >> c;
    cout << (a <= c && a + b >= c ? "YES" : "NO") << endl;
}

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

using namespace std;

#define sz(v)           ((int)((v).size()))
#define clr(v, d)       memset(v, d, sizeof(v))
#define rep(i, v)       for(int i=0; i<sz(v); ++i)
#define lp(i, n)        for(int i=0; i<(int)(n); ++i)
#define lpi(i, j, n)    for(int i=(j); i<(int)(n); ++i)
#define lpd(i, j, n)    for(int i=(j); i>=(int)(n); --i)
#define INF             1000000000

//#define DEBUG

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

const int N = 105;
int arr[N];

int main()
{
	std::ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n, res = 0;
	bool flag = 1;
	cin >> n;
	lp(i, n)
		cin >> arr[i];
	while(flag){
		flag = 0;
		int mmin = INF, idx = 0;
		lp(i, n){
			if(arr[i] > 0){
				flag = 1;
				mmin = min(mmin, arr[i]);
			}
			else{
				lpi(j, idx, i)
					arr[j] -= mmin;
				if(mmin < INF)
					res += mmin;
				idx = i+1;
				mmin = INF;
			}
		}
		lpi(j, idx, n)
			arr[j] -= mmin;
		if(mmin < INF)
			res += mmin;
		idx = 0;
		mmin = INF;
	}
	cout << res;
	return 0;
}


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

using namespace std;
int main()
{
    int n,m;
    cin>>n>>m;
    int ans=0;
    if (n>=2)
        ans+=(n*(n-1))/2;
    if (m>=2)
        ans+=(m*(m-1))/2;
    cout<<ans;

}


Measured memory_bytes: 256
def pow(x,n):
    res = 1
    for _ in range(n):
        res *= x
    return max(1,res)

def main():
    N = int(input())
    lists = [0 for i in range(N+1)]
    temp = list(map(int,input().split()))

    for elem in temp:
        lists[elem] += 1
    
    ans = 1


    if(lists[0] != 1 or temp[0] != 0):
        ans = 0
    else:
        sum = 1
        for i in range(1,N):
            ans *= pow(lists[i-1],lists[i])
            sum += lists[i]
            if(sum == N):
                break
                
            if(lists[i] == 0):
                if(sum != N):
                    ans = 0
                    break
                
    ans %= 998244353
    print(ans)
    

if __name__ == "__main__":
    main()

Measured memory_bytes: 15352
n = int(input())
A = list(map(int,input().split()))
A = [j-i-1 for i,j in enumerate(A)]
top = max(A)
bottom = min(A)
def sad(b):
  ret=0
  for i in A:
    ret += abs(i-b)
  return ret
while top - bottom > 2:
  mid1 = (top + bottom*2)//3
  mid2 = (top*2 + bottom)//3
  if sad(mid1) < sad(mid2):
    top = mid2
  else:
    bottom = mid1
print(min(sad(bottom), sad((bottom+top)//2), sad(top)))


Measured memory_bytes: 97744
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define pye cout << "Yes" << endl;
#define pno cout << "No" << endl;
#define prin(num) cout << num << endl;
#define sprin(str) cout << "str" << endl;
#define INF 1000000000
#define MOD 1000000007LL
#define MAX 100001
#define NIL -1
#define WHITE 0
#define GRAY 1
#define BLACK 2
using namespace std;
typedef long long ll;
typedef pair<ll, ll> PA;
typedef priority_queue<ll> PQ;
typedef pair<double, double> doup;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll memo[MAX];

ll rec(ll n) {
    if(n==0) return 0;
    if(memo[n]!=-1) return memo[n];
    ll res=n;
    
    for(ll psix=1; psix<=n; psix*=6)
        res=min(res, rec(n-psix)+1);
    
    for(ll pnin=1; pnin<=n; pnin*=9)
        res=min(res, rec(n-pnin)+1);
    
    return memo[n]=res;
}


int main() {
    ll N; cin >> N;
    for(ll i=0; i<=N; i++) memo[i]=-1;
    
    cout << rec(N) << endl;
}


Measured memory_bytes: 5760
use std::cmp::max;

macro_rules! scan {
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($t:ty;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
                    scan!($t)
        ).collect::<Vec<_>>()
    };
    ($t:ty;;$n:expr) => {
        (0..$n).map(|_| scan!($t;;)).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
                    scan!($($t),*)
        ).collect::<Vec<_>>()
    };

    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
}

fn main() {
    let (n, weight) = scan!(usize, usize);
    let vs = scan!(usize,usize;n);
    let x = vs[0].0;

    let mut dp = vec![vec![vec![0; 3 * n + 1]; n + 1]; n + 1];
    for (i, &(w, v)) in vs.iter().enumerate() {
        for j in 1..dp[i].len() {
            for k in 0..dp[i][j].len() {
                if k >= (w - x) {
                    dp[i + 1][j][k] = max(dp[i][j - 1][k - (w - x)] + v, dp[i][j][k]);
                } else {
                    dp[i + 1][j][k] = dp[i][j][k];
                }
            }
        }
    }

    let mut vs = vec![];
    for m in 0..dp[n].len() {
        for w in 0..dp[n][m].len() {
            if m * x + w <= weight {
                vs.push(dp[n][m][w]);
            }
        }
    }

    println!("{}", vs.iter().max().unwrap());
}


Measured memory_bytes: 30972
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#define ll long long
using namespace std;
const int N=100100;
int n,m,a[N],b[N],tot,Next[N<<1],head[N],tree[N<<1],f[N];
ll ans[N],g[N];
bool vis[N];
struct node{int x,y;}A[N];
void add(int x,int y)
{
	tot++;
	Next[tot]=head[x];
	head[x]=tot;
	tree[tot]=y;
}
bool cmp(node a,node b) { return a.x<b.x;}
int get(int x)
{
	if (f[x]==x) return x;else f[x]=get(f[x]);
	return f[x];
}
int main()
{
	scanf("%d%d",&n,&m);
	for (int i=1;i<=n;i++)
	{
		scanf("%d%d",&a[i],&b[i]);
		a[i]=max(0,a[i]-b[i]);
		A[i]=(node){a[i],i};
	}
	for (int i=1;i<=m;i++)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		add(x,y);add(y,x);
	}
	sort(A+1,A+n+1,cmp);
	for (int i=1;i<=n;i++)
	{
		f[i]=i;
		ans[i]=a[i];
		g[i]=b[i];
	}
	for (int i=1;i<=n;i++)
	{
		int u=A[i].y;
		vis[u]=1;
		for (int j=head[u];j;j=Next[j])
		{
			int v=tree[j],x=get(v);
			if (x==u||!vis[x]) continue;
			f[x]=u;
			g[u]+=g[x];
			ans[u]=min(ans[u],max(ans[x],a[u]-g[x]));
		}
	}
	printf("%lld\n",ans[A[n].y]+g[A[n].y]);
	return 0;
}


Measured memory_bytes: 5760
#include <stdio.h>
 
int main(void) {
    int m,n,l, i, c, k;
        int a[100][100], b[100][100];
     
    scanf("%d%d%d", &n, &m, &l);
    for(i = 0; n > i; i++){
    for(c = 0; m > c; c++){
        scanf("%d", &a[i][c]);
    }   
    }
    for(i = 0; m > i; i++){
    for(c = 0; l > c; c++){
        scanf("%d", &b[i][c]);
    }   
    }
     
     
    for(i = 0; n > i; i++){
    for(c = 0; l > c; c++){
        long long int buf = 0;
    for(k = 0; m > k; k++){
        buf += a[i][k] * b[k][c];
    }   
    printf("%lld", buf);
    if(c != l-1) printf(" ");
    }
    printf("\n");
    }
    return 0;
}


Measured memory_bytes: 2116
def c_Boxes_and_Candies(N, X, A):
    a = [x for x in A]
    if a[0] > X:
        # 最初からXを超えていた場合、減らさなければ条件を満たせない
        a[0] = X
    for i in range(0, N - 1):
        if a[i] + a[i + 1] > X:
            # a[i]+a[i+1]==Xになるまで減らす。a[i+1]だけ減らしたほうが得する
            a[i + 1] = X - a[i]
    ans = 0
    for i in range(N):
        ans += A[i] - a[i]
    return ans

N,X = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
print(c_Boxes_and_Candies(N, X, A))

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

int main() {
    int n, a;
    cin >> n;
    a = n % 10;
    if (a == 3) {
        cout << "bon" << endl;
    } else if (a == 0 || a == 1 || a == 6 || a == 8) {
        cout << "pon" << endl;
    } else {
        cout << "hon" << endl;
    }
    
    return 0;
}

Measured memory_bytes: 3604
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<algorithm>
using namespace std;

int main() {
	int N;
	cin >> N;
	vector<int> x(N), y(N), h(N);
	for (int i = 0; i < N; i++)
	{
		cin >> x[i] >> y[i] >> h[i];
	}

	//[0, 100]に座標があるのでMAXを定義すると楽
	int MAX = 100;

	for (int posY = 0; posY <= MAX; posY++)
	{
		for (int posX = 0; posX <= MAX; posX++)
		{
			//頂上がどれくらいの高さであってほしいか。
			//-1はまだ良く分からない時。0以上は確定してるとき
			//-2はダメだって分かった時
			int needH = -1;

			for (int i = 0; i < N; i++)
			{
				if (h[i] > 0) {
					//この頂点から見て、頂上がposY,posXの時に、
					//どれくらいの高さがあってほしいかを求める
					int tmp = h[i] + abs(posY - y[i]) + abs(posX - x[i]);
					if (needH == -1) {
						needH = tmp;
					}
					else {
						if (needH != tmp) {
							needH = -2;
							break;
						}
					}
				}
			}
			//ダメだったら別の場所を探す。
			if (needH == -2) continue;

			for (int i = 0; i < N; i++)
			{
				//高さが0の場合に矛盾してないか調べる
				if (h[i] == 0) {
					int dist = abs(posY - y[i]) + abs(posX - x[i]);
					if (needH > dist) {
						needH = -2;
						break;
					}
				}
			}

			if (needH == -2) continue;

			//見つけられたら答えをそのまま返す。
			cout << posX << " " << posY << " " << needH << endl;
			return 0;
		}
	}

}





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

vector<int> v[100000];
map<pair<int, int>, int> m;

void search(int curr, int prev) {
    int d = 1;
    int c = m[{min(curr, prev), max(curr, prev)}];
    for (auto &next: v[curr]) {
        if (prev == next) continue;
        if (d == c) d++;
        m[{min(curr, next), max(curr, next)}] = d++;
        search(next, curr);
    }
}

int main() {
    int n; cin >> n;
    vector<int> c(n, -1);
    vector<pair<int, int>> p; 
    for (int i = 0; i < n-1; i++) {
        int a, b; cin >> a >> b;
        v[a-1].emplace_back(b-1);
        v[b-1].emplace_back(a-1);
        p.emplace_back(min(a-1, b-1), max(a-1, b-1));
    }
    int k = 0;
    for (int i = 0; i < n; i++) {
        k = max(k, (int) v[i].size());
    }
    cout << k << endl;
    search(0, -1);
    for (int i = 0; i < n-1; i++) {
        cout << m[{p[i].first, p[i].second}] << endl;
    }
    return 0;
}

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


def solve(N: int, P: "List[int]"):
    cnt = 1
    min = P[0]
    for i in range(1, N):
        if P[i] <= min:
            cnt+=1
            min = P[i]
    return cnt


# Generated by 1.1.6 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
    P = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    print(solve(N, P))

if __name__ == '__main__':
    main()


Measured memory_bytes: 25984
# a, b = map(int, input().split())
# h1 = int(input())
n = int(input())

word_ary = []
word_set = set()

def main():
	for i in range(1, n + 1):
		w = input()
		if i > 1 and word_ary[i - 2][-1:] != w[0]:
			print('No')
			return
		if w in word_set:
			print('No')
			return
		word_ary.append(w)
		word_set.add(w)
	print('Yes')
			
main()


Measured memory_bytes: 2940
#include<iostream>
#include<queue>
#include<algorithm>
#include<vector>
using namespace std;
int main(){
  int n,a;
  bool Tf[305],Hf[305];
  while(cin >> n && n){
    vector<int> tque,hque;
    for(int i=0;i<=303;i++){
      Tf[i] = false;
      Hf[i] = true;
    }
    for(int i=0;i<n;i++){
      cin >> a;
      Tf[a] = true;
      Hf[a] = false;
    }
    
    for(int i=1;i<=2*n;i++){
      if(Tf[i]){
	tque.push_back(i);
      }
      else if(Hf[i])hque.push_back(i);
    }
    

    int FL = -1;
  
    while(!hque.empty() && !tque.empty()){
    
	vector<int>::iterator tit = lower_bound(tque.begin(),tque.end(),FL);
	if(tit != tque.end()){
	  //cout << "taro pop = " << *tit << endl; 
	  FL = *tit;
	  tque.erase(tit);
	}
	else FL = -1;
	if(tque.empty())break;
     
	vector<int>::iterator hit = lower_bound(hque.begin(),hque.end(),FL);
	if(hit != hque.end()){
	  //cout << "hanako pop = " << *hit << endl;
	  FL = *hit;
	  hque.erase(hit);
	
	}
	else FL = -1;
	if(hque.empty())break;
    }

    cout << hque.size() << endl;
    cout << tque.size() << endl;

  }
  return 0;
}

Measured memory_bytes: 0
from math import hypot
from collections import deque

N, K, *XYC = map(int, open(0).read().split())
XYC = list(zip(*[iter(XYC)] * 3))

Q = deque([(0, 0, 1000.0)])

ans = float("inf")
while Q:
    X, Y, r = Q.popleft()
    if ans * 0.9999995 > sorted(c * hypot(max(abs(X - x) - r, 0), max(abs(Y - y) - r, 0)) for x, y, c in XYC)[K - 1]:
        ans = min(ans, sorted(c * hypot(X - x, Y - y) for x, y, c in XYC)[K - 1])
        r /= 2
        Q += [
            (X + r, Y + r, r),
            (X - r, Y + r, r),
            (X + r, Y - r, r),
            (X - r, Y - r, r),
        ]

print(ans)

Measured memory_bytes: 3956
#if 1
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <climits>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>
#include <functional>
#include <set>
#include <map>
#include <numeric>
#include <cassert>

using namespace std;
#define int long long
#define uint unsigned long long
constexpr int MOD = 1000000007;
constexpr int INF = 1145141919810893;

#define LOADVEC(type,name,N) std::vector<type>name(N); \
for (int nnn = 0; nnn < N; ++nnn) { \
	cin >> name[nnn]; \
}

#define LOADVEC2(type,name0,name1,N) std::vector<type>name0(N),name1(N); \
for (int nnn = 0; nnn < N; ++nnn) { \
	cin >> name0[nnn];cin >> name1[nnn]; \
}

#define LOADVEC3(type,name0,name1,name2,N) std::vector<type>name0(N),name1(N),name2(N); \
for (int nnn = 0; nnn < N; ++nnn) { \
	cin >> name0[nnn];cin >> name1[nnn];cin >> name2[nnn]; \
}

#define LOAD(type,name) type name; \
cin >> name;


void proc();

signed main() {
	ios::sync_with_stdio(false);
	proc();
	return 0;
}

/*
--------------------------------------------------------
--------------------------------------------------------
---------------    template      ----------------------
--------------------------------------------------------
--------------------------------------------------------
*/



void proc() {
	LOAD(int, N);
	if (N == 2) {
		cout << 0 << endl;
		return;
	}
	int res = 0;
	for (int a = 1; ; ++a) {
		double m_ = 1.0 * N / a - 1;
		if (a >= m_)break;
		if (N % a != 0)continue;
		int m = N / a - 1;
		if (a >= m)break;
		res += m;
	}
	cout << res << endl;
}


#endif


Measured memory_bytes: 256
#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define ld long double
#define mk make_pair
#define fi first
#define se second
#define vll vector<ll>
#define pii pair<ll,ll>
#define vvll vector< vector<ll> >
#define pb push_back
#define sz(v) (v).size()
#define inf 1e18
#define md 1000000007
#define all(v) (v).begin(),(v).end()
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define tel(a){cout<<a<<"\n";}
#define tell(a,b){cout<<a<<" | "<<b<<"\n";}
#define telll(a,b,c){cout<<a<<" | "<<b<<" | "<<c<<"\n";}
#define teln(v,n){cout<<"v- ";rep(i,0,n)cout<<v[i]<<" ";cout<<"\n";}
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define tihs if(fopen("inp.txt","r"))freopen("inp.txt", "r", stdin),freopen("out.txt", "w", stdout);
using namespace std;
#define TRACE
 
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << std::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...);
}
#else
#define trace(...)
#endif
 
#define M 100010

int main(){
	IOS;
	tihs;
	
	ll n,k;cin>>n>>k;
	ld a[n];
	rep(i,0,n){
		cin>>a[i];
		a[i]=(ld)(a[i]+1.000)/(ld)(2.000);
	}
	ld ans =-1,sum=0.00;
	rep(i,0,k)sum+=a[i];
	ans=max(ans,sum);
	rep(i,k,n){
		ld pev=a[i-k],next= a[i];
		sum=sum+next-pev;
		ans=max(ans,sum);
	}
	cout<<setprecision(20)<<ans;


	return 0;
}

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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef vector<vector<long long>> VVL;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define EXIST(m,v) (m).find((v)) != (m).end()
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

#define en "\n"

constexpr double EPS = 1e-9;
constexpr double PI  = 3.1415926535897932;
constexpr int INF = 2147483647;
constexpr long long LINF = 1LL<<60;
constexpr long long MOD = 1000000007; // 998244353;

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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 Main(){
    int N; cin >> N;
    int ans = (N+999)/1000*1000 - N;
    cout << ans << en;
    return;
}

int main(void){
    cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);cout<<fixed<<setprecision(15);
    int t=1; //cin>>t;
    REP(_,t) Main();
    return 0;
}

Measured memory_bytes: 3604