akhauriyash/Code-Regression huggingface dataset:
import typing
from typing import List, NamedTuple, Deque, Set, Counter

class node:
    def __init__(self, id: int) -> None:
        self.id: int = id
        self.parent: node = self
        self.root: node = self
        self.rank: int = 0
        self.connection: List[node] = []

    def addConnection(self, other: 'node') -> None:
        self.connection.append(other)
        other.connection.append(self)

    def delConnection(self, other: 'node') -> None:
        self.connection.remove(other)
        other.connection.remove(self)

    def setParent(self, other: 'node') -> None:
        self.parent = other
        self.rank = other.rank +1
    
    def setRoot(self, other: 'node') -> None:
        self.root = other

    def setAsRoot(self) -> None:
        self.parent = self
        self.root = self
        self.rank = 0


def makePath(root: node, target: node) -> Deque[node]:
    path: Deque[node] = Deque()
    path.append(target)
    while path[0] != root:
        path.appendleft(path[0].parent)
    return path


def bfs(root: node):
    reserved: Deque[node] = Deque([root])
    seen: Set[int] = {root.id}
    while len(reserved) > 0:
        current_node = reserved.popleft()
        for next_node in current_node.connection:
            if next_node.id in seen:
                continue
            next_node.setParent(current_node)
            next_node.setRoot(root)
            seen.add(next_node.id)
            reserved.append(next_node)


def main():
    N = int(input())
    Edge = [map(int, input().split()) for _ in range(N-1)]

    Node: List[node] = [node(i) for i in range(N)]
    for a, b in Edge:
        Node[a-1].addConnection(Node[b-1])

    #Node[0]からbfs
    bfs(Node[0])
    #between:Node[0]とNode[N-1]の間にあるノード数
    between: int = Node[N-1].rank -1
    #sep:お互い陣地を取り合った時に衝突する点までの距離fromNode[0]
    sep = (between+1)//2
    path = makePath(Node[0], Node[N-1])
    #衝突点の結合を削除, 再度bfs
    path[sep].delConnection(path[sep+1])
    path[sep+1].setAsRoot()
    bfs(path[sep+1])
    #2分した木のノード数集計
    fennec, snuke = Counter([n.root.id for n in Node]).values()
    #勝者判定
    print('Fennec' if fennec > snuke else 'Snuke')


if __name__ == '__main__':
    main()

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

void solve()
{
    long long n,w;
    cin>>n>>w;
    long long  v[n+1],wt[n+1];
    for(long long i=1;i<=n;i++)
        cin>>wt[i]>>v[i];
    long long dp[n+2][w+2]={0};
    for(long long i=0;i<=n;i++)
    {
        for(long long j=0;j<=w;j++)
            dp[i][j]=0;
    }
    for(long long i=1;i<=n;i++)
    {
        for(long long j=1;j<=w;j++)
        {    if(j>=wt[i])
                dp[i][j]=max(dp[i-1][j],v[i]+dp[i-1][j-wt[i]]);
             else
                dp[i][j]=dp[i-1][j];
        }
    }
    cout<<dp[n][w]<<"\n";
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    solve();
    return 0;
}

Measured memory_bytes: 80000
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int n, a[1009];
int main() {
	cin >> n;
	for (int i = 0; i < n; i++) cin >> a[i];
	if (*max_element(a, a + n) <= 0) {
		int ptr = max_element(a, a + n) - a;
		cout << a[ptr] << endl; ptr++;
		cout << n - 1 << endl;
		for (int i = n; i > ptr; i--) cout << i << endl;
		for (int i = 1; i < ptr; i++) cout << 1 << endl;
	}
	else {
		vector<int> v; long long cs = 0;
		for (int i = 0; i < 2; i++) {
			long long ss = 0; vector<int> sv;
			for (int j = i; j < n; j += 2) {
				if (a[j] > 0) ss += a[j], sv.push_back(j + 1);
			}
			if (ss > cs) {
				cs = ss;
				v = sv;
			}
		}
		vector<int> seq;
		for (int i = n; i > v.back(); i--) seq.push_back(i);
		for (int i = (int)v.size() - 2; i >= 0; i--) {
			for (int j = (v[i] + v[i + 1]) / 2; j > v[i] + 1; j--) {
				seq.push_back(j);
			}
		}
		for (int i = 1; i < v.front(); i++) seq.push_back(1);
		for (int i = 0; i < (int)v.size() - 1; i++) seq.push_back(2);
		cout << cs << endl;
		cout << seq.size() << endl;
		for (int i : seq) cout << i << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define debug(x) cout<<#x<<": "<<x<<endl
#define DEBUG(x) cout<<#x<<": "<<x<<endl
int powint(int a, int x){
	int res = 1;
	REP(i,x){
		res = res *a; 
	}
	return res;
}

using namespace std;

#define vi vector<int>

int main(){
	int N;
	cin>>N;
	vi a(N,0);
	REP(i,N){
		cin>>a[i];
		a[i] -= i+1;
	}
	/*
	int mid=0;
	REP(i,N){
		mid+=a[i];
	}
	mid /= N;
	*/
	sort(a.begin(),a.end());
	int b = -1;
	if(N%2==0){
		int t= N/2 -1;
		b = a[t];
	} else {
		int t = N/2;
		b = a[t];
	}
	//debug(b);

	long long ans = 0;
	REP(i,N){
		//debug(a[i]);
		ans += abs(a[i]-b);
	}

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


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

using namespace std;

int main(){
    int N,M,Q;
    cin >> N >> M >> Q;

    vector<vector<int>> sum(N+1,vector<int> (N+1,0)),sumL(N+1,vector<int> (N+1,0));

    for(int i=0;i<M;i++){
        int L,R;
        cin >> L >> R;
        sum[L][R]++;
    }

    for(int i=0;i<=N;i++){
        for(int j=0;j<=N;j++){
            if(j==0){
                sumL[i][j] = sum[i][j];
            }else{
                sumL[i][j] = sumL[i][j-1] + sum[i][j];
            } 
        }
    }

    for(int i=0;i<Q;i++){
        int p,q,ans=0;
        cin >> p >> q;
        for(int j=p;j<=q;j++){
            ans += sumL[j][q] - sumL[j][p-1];
        }

        cout << ans << endl;
    }
}

Measured memory_bytes: 2944
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  int K;
  cin>>N>>K;
  int P[N];
  int count =0;
 if(N>=1&&K>=1&&N<=100000&&K<=500){
  for(int i=0;i<N;i++){
      cin>>P[i];
      if(P[i]>=K&&P[i]>=1&&P[i]<=500){
          count++;
      }
  }
  cout<<count;
 }
   return 0;
   
}

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

constexpr int INF = (1 << 30);

int main() {
	int n;
	cin >> n;
	vector<int> dp(n + 1, INF);
	
	for (int i = 0; i < n; i++) {
		int e;
		cin >> e;
		*lower_bound(dp.begin(), dp.end(), e) = e;
	}
	
	cout << lower_bound(dp.begin(), dp.end(), INF) - dp.begin() << '\n';
	
	return 0;
}


Measured memory_bytes: 3120
#include<cstdio>
#include<cstring>
#include<cctype>
#include<cmath>
#include<queue>
#include<stack>
#include<set>
#include<vector>
#include<algorithm>
#define ll long long
#define lowbit(x) x&-x
using namespace std;
int read(){
    char c;int s=0,t=1;
    while(!isdigit(c=getchar()))if(c=='-')t=-1;
    do{s=s*10+c-'0';}while(isdigit(c=getchar()));
    return s*t;
}
int min(int a,int b){return a<b?a:b;}
int max(int a,int b){return a<b?b:a;}
int ab(int x){return x>0?x:-x;}
//int MO(int x){return x>=MOD?x-MOD:x;}
//void insert(int u,int v){tot++;e[tot].v=v;e[tot].from=first[u];first[u]=tot;}
/*------------------------------------------------------------*/
const int inf=0x3f3f3f3f;

int n;
ll x,y,z,k;
int main(){
    scanf("%lld%lld",&x,&y);
    z=y/x;
    k=1;
    for(int i=1;i<=70;i++){
    	k=k*2;
    	if(z<k){printf("%d",i);return 0;}
    }
    return 0;
}

Measured memory_bytes: 128
#include<algorithm>
#include<cmath>
#include<fstream>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<random>
#include<set>
#include<sstream>
#include<sys/time.h>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(prints) FUNC(printe) FUNC(printw) FUNC(printew) FUNC(printb) FUNC(printd) FUNC(printde) FUNC(printdu);
#endif
template <class S, class T>
istream& operator >> (istream& in, pair<S, T>& p){ return in >> p.first >> p.second; }
template <class T>
istream& operator >> (istream& in, vector<T>& v){ for(auto& e : v){ in >> e; } return in; }

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, k;
    cin >> n >> k;
    vector<int> hs(n); cin >> hs;
    for(int i = 0; i < 200; i++){
        hs.push_back(0);
    }
    vector<int> dp(n + 200, M);
    dp[0] = 0;
    for(int i = 0; i < n; i++){
        for(int j = 1; j <= k; j++){
            dp[i + j] = min(dp[i + j], dp[i] + abs(hs[i] - hs[i + j]));
        }
    }
    cout << dp[n - 1] << '\n';
}


Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
long long dis[15][15],x,ans,n,m,i,j,k;
int main()
{
	cin>>n>>m;
	for (i=0;i<=9;i++)for (j=0;j<=9;j++)cin>>dis[i][j];
	for (k=0;k<=9;k++)for (i=0;i<=9;i++)for (j=0;j<=9;j++)dis[i][j]=min(dis[i][j],dis[i][k]+dis[k][j]);
	for (i=1;i<=n;i++)for (j=1;j<=m;j++){cin>>x;if (~x)ans+=dis[x][1];}
	cout<<ans;return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Comparator;
import java.util.LinkedList;
import java.util.List;

public class Main {
  public static void main(String[] args) {
    new Main().run();
  }

  public void run() {
    
    try(BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(System.out)) {
          String[] s = in.readLine().split(" ");
          int n = Integer.parseInt(s[0]);
          int k = Integer.parseInt(s[1]);

          String line = in.readLine();
          int[] a = new int[n];
          char regex = ' ';
          boolean isContinue = true;
          for(int i=0, offset=0,next=0; isContinue; i++, offset = ++next) {
            if((next = line.indexOf(regex,offset)) == -1) {
              next = line.length();
              isContinue = false;
            }
            a[i] = Integer.parseInt(line.substring(offset,next));
          }

          List<Long> list = new LinkedList<>();
          for(int i=0; i<n; i++) {
            long sum = 0;
            for(int j=i; j<n; j++) {
              sum += (long)a[j];
              list.add(sum);
            }
          }

          long ans = 0;
          for(int i=62;i>=0;--i) {
            long b = 1L << i;
            int cnt = 0;
            for(long v: list) {
              if( (v&b) > 0 )
                ++cnt;
              if(cnt == k) {
                ans |= b;
                list.removeIf(e -> (e&b) == 0);
                break;
              }
            }
          }

          System.out.println(ans);
      }
      catch(IOException e) {
        System.err.println(e);
      }
  }
}

Measured memory_bytes: 56404
import collections

N = int(input())
H_list = list(map(int, input().split()))

if(N == 1):
    print(0)
else:
    point = 0
    step_candidates = collections.Counter()
    for n in range(N-1):
        if(H_list[n] < H_list[n+1]):
            step_candidates[point] = n - point
            point = n+1
    if(point != N - 1):
        step_candidates[point] = N - 1 - point

    print(step_candidates.most_common()[0][1])

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

using namespace std;

const int MAX_H=100,MAX_W=100;

int H,W;
char f[MAX_H][MAX_W+1];

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

void dfs(int x,int y,char c){
	f[y][x]='_';
	for (int i=0;i<4;i++){
		int a=x+dx[i],b=y+dy[i];
		if (a>=0 && a<W && b>=0 && b<H && f[b][a]==c){
			dfs(a,b,c);
		}
	}
}

int main(){
	vector<int> res;
	do{
		cin>>H>>W;
		if (H!=0 || W!=0){
			for (int i=0;i<H;i++){
				cin>>f[i];
			}
			int cnt=0;
			for (int i=0;i<H;i++){
				for (int j=0;j<W;j++){
					if (f[i][j]!='_'){
						dfs(j,i,f[i][j]);
						cnt++;
					}
				}
			}
			res.push_back(cnt);
		}
	}while (H!=0 || W!=0);
	for (vector<int>::iterator ite=res.begin();ite!=res.end();ite++){
		cout<<*ite<<endl;
	}
	return 0;
}

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

using namespace std;

deque<int> dq;
deque<int>::iterator its;

int pos = 0, a;

int main(){
	int n;
	scanf("%d", &n);
	for(int i=0;i<n;i++){
		scanf("%d", &a);
		if(pos == 0) dq.push_back(a);
		else dq.push_front(a);
		pos = 1-pos;
	}

	if(pos == 0){
		while(!dq.empty()){
			printf("%d ", dq.front());
			dq.pop_front();
		}
	}
	else{
		while(!dq.empty()){
			printf("%d ", dq.back());
			dq.pop_back();
		}
	}
}

Measured memory_bytes: 2944
n = gets.to_i
nums = gets.split.map(&:to_i)
plus_nums = nums.select { |num| num >= 0 }.sort
minus_nums = nums.select { |num| num < 0 }.sort.reverse
changes = []

if plus_nums.empty?
  a = minus_nums.shift
  b = minus_nums.shift
  plus_nums << (b.abs - a.abs)
  changes << [a, b]
elsif minus_nums.empty?
  a = plus_nums.shift
  b = plus_nums.shift
  minus_nums << b - a
  changes << [a, b]
end

until plus_nums.empty? || minus_nums.empty?
  a = plus_nums.shift
  b = minus_nums.shift
  if plus_nums.empty?
    changes << [a, b]
    plus_nums << (a.abs + b.abs)
  else
    changes << [b, a]
    minus_nums << -(a.abs + b.abs)
  end
end

puts plus_nums.first || minus_nums.first
changes.each { |a, b| puts "#{a} #{b}"}


Measured memory_bytes: 24768
#include <iostream>
#include <vector>
#include <queue>
#include <cmath>

#define INF 100000000000

using namespace std;

class Vertex{
public:
  int num, before;
  double distance;

  bool operator<(const Vertex &b) const{
    if(distance > b.distance){
      return true;
    }else{
      return false;
    }
  }
};

class Edge{
public:
  int from, to;
  double cost;
};

vector < vector < Edge > > edge;
vector < Vertex > vertex;

vector < int > X;
vector < int > Y;

int N;

void dijkstra(int start){
  priority_queue < Vertex > pq;
  pq.push(vertex[start]);
  while(!pq.empty()){
    Vertex p=pq.top();
    pq.pop();
	int l=edge[p.num].size();
    for(int i=0; i<l; i++){
      if(vertex[edge[p.num][i].to].distance > vertex[p.num].distance + edge[p.num][i].cost){
	vertex[edge[p.num][i].to].distance = vertex[p.num].distance + edge[p.num][i].cost;
	vertex[edge[p.num][i].to].before = p.num;
	pq.push(vertex[edge[p.num][i].to]);
      }
    }
  }
}

double distance(int i, int j){
	unsigned long long int x=X[i]-X[j];
	unsigned long long int y=Y[i]-Y[j];
	return sqrt(x*x+y*y);
}

int main(){
	int xs, ys, xt, yt;

	cin>>xs>>ys>>xt>>yt;
	cin>>N;

	vertex.resize(N+2);
	edge.resize(N+2);
	
	int x, y, r;
	vector<int> R;
	X.resize(N+2);
	Y.resize(N+2);
	R.resize(N+2);

	X[0]=xs;
	Y[0]=ys;
	R[0]=0;

	for(int i=1; i<=N; i++){
		cin>>x>>y>>r;
		X[i]=x;
		Y[i]=y;
		R[i]=r;
	}

	X[N+1]=xt;
	Y[N+1]=yt;
	R[N+1]=0;

	for(int i=0; i<N+2; i++){
		edge[i].resize(N+2);

		vertex[i].num=i;
		vertex[i].distance=INF;
		vertex[i].before=0;
	}

	for(int i=0; i<N+2; i++){
		for(int j=i+1; j<N+2; j++){
			edge[i][j].from=i;
			edge[i][j].to=j;
			edge[i][j].cost=distance(i, j)-R[i]-R[j];
			if(edge[i][j].cost<0){
				edge[i][j].cost=0;
			}

			edge[j][i].from=j;
			edge[j][i].to=i;
			edge[j][i].cost=distance(j, i)-R[j]-R[i];
			if(edge[j][i].cost<0){
				edge[j][i].cost=0;
			}
		}
	}

	vertex[0].distance=0;
	dijkstra(0);

	printf("%.10f\n", vertex[N+1].distance);

	return 0;
}


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

int main() {
    int K, A, B;
    cin >> K >> A >> B;

    for (int i = A; i <= B; i++) {
        if (i % K == 0) {
            cout << "OK" << endl;
            return 0;
        }
    }
    cout << "NG" << endl;
    return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
int main(){
	string s;
	cin>>s;
	int a[33]={0};
	for(int i=0;i<s.length();i++){
		a[s[i]-'a']=1;
	}
	if(s=="zyxwvutsrqponmlkjihgfedcba"){
		puts("-1");
		return 0;
	}
	for(int i=0;i<26;i++){
		if(!a[i]){
			cout<<s<<char('a'+i)<<endl;
			return 0;
		}
	}
	int i=0,t=0;
	for(i=s.length()-1;i>=0;i--){
		a[s[i]-'a']=0;
		if(s[i]>s[i-1]){
			t=s[i-1]-'a';
			break;
		}
	}
	for(int j=0;j<i-1;j++){
		cout<<s[j];
	}
	for(int i=t;i<26;i++){
		if(!a[i]){
			cout<<char('a'+i)<<endl;
			break;
		}
	}
}
/*
abcdefghijklmnopqrstuvwxyz
yzxwvutsrqponmlkjihgfedcba
*/

Measured memory_bytes: 256
// ------------------------------------
// Date:2018/ 3/14
// Problem:ARC 078 SplittingPile c.cpp
//
// ------------------------------------

#include <bits/stdc++.h>

using namespace std;

#define EACH(i,a) for (auto&& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define debug(x) cerr << #x << ":" << x << endl

typedef long long ll;

static const int INF = 1000000001;

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

  int N;
  cin >> N;
  
  vector< int > A(N);
  ll sum = 0ll;
  REP(i, N) {
    cin >> A[i];
    sum += A[i];
  }

  ll ans = INF;
  ll tmp = 0ll;
  RFOR(i, 1, N) {
    tmp += A[i];
    sum -= A[i];
    ans = min(ans, abs(sum - tmp));
  }
  if (N == 2) {
    ans = abs(A[1] - A[0]);
  }

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



Measured memory_bytes: 1152
@{$_ x3}=1for A..D;for$i(1..<>-1){$x=0;for$j(glob'{A,B,C,D}'x3){$x+=/D/*(($$j[$i]+="$_$j"!~/ABC|A.*C.*B|CAB/*${$j=~/../;$_.$&}[$i-1])%=$%=1e9+7)for A..D}}print$x%$%

Measured memory_bytes: 1024
//#include "stdafx.h"
#include <iostream>
#include <iomanip>
#include <string>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <vector>
#include <cassert>
#include <fstream>
#include <algorithm>
#include <list>
#include <random>
#include <ctime>
#include <cmath>
#include <random>
#include <bitset>
#include <complex>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
//#define int ll
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef vector< vvi > vvvi;
typedef vector<short> vs;
typedef vector<vs> vvs;
typedef vector<vvs> vvvs;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef pair<ld, ld> pld;
typedef complex<double> base;

#define mmin(a, b) a = min(a, (b))
#define mmax(a, b) a = max(a, (b))
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define ALL(a) a.begin(),a.end()
#define sqr(x) (x) * (x)
#define fori(i, n) for(int i = 0; i < int(n); ++i)
#define cint const int & 
#define SZ(a) ((int)(a.size()))
#define watch(x) cout << (#x) << " = " << x << endl;

const double PI = 2 * acos(0.0);

template<class T>
void show(const vector<T> &a) {
	for (T x : a)
		cout << x << " ";
	cout << endl;
}


signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	int n;
	cin >> n;
	vl a(n);
	fori(i, n)
		cin >> a[i];
	ll j = -1;
	ll ans = 0;
	ll mask = 0;
	for (ll i = 0; i < n; ++i) {
		if (j < i) {
			++j;
			mask ^= a[i];
		}
		while (j + 1 < n && !(mask & a[j + 1])) {
			++j;
			mask ^= a[j];
		}
		ans += j - i + 1;
		mask ^= a[i];
	}
	cout << ans << endl;
}


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

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

	vector<int> v(n);
	for (auto &t : v) {
		cin >> t;
	}
	int cnt = 1, sum = 0;
	for (auto t : v) {
		sum += t;
		if (sum <= x) {
			cnt++;
		}
		else {
			break;
		}
	}
	cout << cnt;
}

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

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cout<<setprecision(32);

	string s, t;
	cin>>s>>t;
	vector<int> p(26, -1);
	int n = s.size();
	for(int i = 0; i < n; i++){
		int cs = s[i] - 'a';
		int ct = t[i] - 'a';
		if(p[cs] == -1){
			p[cs] = ct;
		}
		if(p[cs] != ct){
			cout<<"No"<<endl;
			exit(0);
		}
	}
	set<int> st;
	for(int i = 0; i < 26; i++){
		if(p[i] != -1 && st.find(p[i]) != st.end()){
			cout<<"No"<<endl;
			exit(0);
		}
		if(p[i] != -1)st.insert(p[i]);
	}
	cout<<"Yes"<<endl;

	return 0;
}

Measured memory_bytes: 916
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define REP(i,a,b) for(int i=int(a);i<(int)b;++i)
#define Graph vector<vecctor<ll>>
#define pairs vector<pair<ll,ll>>
#define pb push_back



using namespace std;
using ll = long long;

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




int main(void)
{
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    vector<ll> a(n+1);
    rep(i,n+1){
        cin >> a[i];
    }
    if(n == 0){
        if(a[0] == 1){
            cout << 1 << endl;
            return 0;
        }else{
            cout << -1 << endl;
            return 0;
        }
    }
    vector<ll> b(n+1);
    vector<ll> sum_a(n+1);
    sum_a[n] = 0;
    rep(i,n){
        sum_a[n-i-1] = sum_a[n-i] + a[n-i];
    }
    b[0] = 1-a[0];
    for(int i = 1;i <= n; ++i){
        if(2*b[i-1] < a[i]){
            cout << -1 << endl;
            return 0;
        }

        b[i] = min(2*b[i-1],sum_a[i-1])-a[i];

    }

    ll ans = 0;

    rep(i,n+1){
        ans += a[i] + b[i];
    }

    

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


Measured memory_bytes: 5580
#include <stdio.h>
#include<string.h>

int main(void){
  int i,n,m,count[1000001],res;
  char s[1000001],ioi[4]="IOI";
  
  while(scanf("%d",&n),n){
    scanf("%d %s",&m,s);
    for(i=0;i<1000001;count[i]=0,i++);

    for(i=0;i<=m;i++)
      if(strncmp(s+i,ioi,3)==0)count[i]=count[i-2]+1;
    
    for(i=0,res=0;i<m;i++)if(count[i]>=n)res++;
    printf("%d\n",res);
  }
  return 0;
}

Measured memory_bytes: 0
// https://atcoder.jp/contests/abc076/tasks/abc076_a

#include <iostream>
using namespace std;

int main()
{
  /* Magic word */
  cin.tie(0);
  ios::sync_with_stdio(false);
  /* ---------- */

  int r, g;

  cin >> r >> g;

  cout << r + (g - r) * 2 << '\n';

  return 0;
}


Measured memory_bytes: 256
#include <string.h>
#include <stdio.h>

int main(void)
{
    char a[10],b[10];
    scanf("%s%s",a,b);
    if (a[0] > b[0]) {
        printf(">\n");
    }else if (a[0] < b[0]) {
        printf("<\n");
    }else{
        printf("=\n");
    }
    return 0;
}

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

#define endl '\n'
#define LL long long
#define MP make_pair
#define REP(i, n) for(int i = 0; i < n; ++i)
#define REPR(i, n) for(int i = n - 1; i >= 0; --i)
#define FOR(i, a, b) for(int i = a; i < b; ++i)
#define FORR(i, a, b) for(int i = b - 1; i >= a; --i)
#define EB emplace_back
#define ST first
#define ND second
#define S size()
#define RS resize

using VI = vector<int>;
using VVI = vector<VI>;
using PI = pair<int, int>;
using VPI = vector<PI>;
using VVPI = vector<VPI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VB = vector<bool>;

VVI graf;
VB vis;
VI topo;
int licz;

void dfs(int v)
{
    vis[v] = true;
    for(int &u : graf[v])
        if (!vis[u])
            dfs(u);
    topo[licz] = v;
    licz--;
}

int main()
{ 
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    licz = n - 1;
    graf.RS(n);
    vis.RS(n);
    topo.RS(n);
    REP(i, m)
    {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        graf[a].EB(b);
    }
    REP(i, n)
        if (!vis[i])
            dfs(i);
    VI dp(n);
    int wyn = 0;
    REP(i, n)
    {
        REP(j, int(graf[topo[i]].S))
        {
            dp[graf[topo[i]][j]] = max(dp[graf[topo[i]][j]], dp[topo[i]] + 1);
            wyn = max(wyn, dp[graf[topo[i]][j]]);
        }
    }
    cout << wyn;
}

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

int N,Q;
string s[1000];
int a[1000];
int b[1000];

void solve(int m){
  for(int i=0;i<N;i++){
    if(b[i]-a[i]<m&&m<=b[i]){
      cout<<s[i]<<' '<<a[i]-(b[i]-m)<<endl;
      return;
    }
  }
  cout<<"Unknown"<<endl;
}

int main(){
  while(1){
    cin>>N>>Q;
    if(N==0&&Q==0)break;
    for(int i=0;i<N;i++){
      cin>>s[i]>>a[i]>>b[i];
    }
    for(int i=0;i<Q;i++){
      int m;
      cin>>m;
      solve(m);
    }
  }
  return 0;
}

Measured memory_bytes: 1300
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
ll ar[500009],br[500009];
int main()
{
    ll a,b,c,i,j,k=0;
    string s,d;
    char q,w;
    cin>>a>>b;
    for(i=1;i<=b;i++)
    {
        cin>>j;
        k=k+j;
    }
    if(k>=a)
    {
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef long double ld;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

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

  cout << (n + 1) / 2 << endl;


  
  return 0;
}

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

int main() {
  int N;
  cin >> N;
  int a[N];
  for(int i=0; i<N; i++){
    cin >> a[i];
  }
  
  int count = 1;
  int ans=0;
  for(int i=1;i<N;i++){
    if(a[i] == a[i-1]){
      count++;
      if(i==N-1) ans+=count/2;
    }
    if(a[i] != a[i-1]){
      if(count > 1){
	ans+=count/2;
	count=1;
      }
    }
    //    cout << count <<endl;
  }
  cout << ans << endl;

}


Measured memory_bytes: 256
h, n = map(int, input().split())
magics = []
max_a = 0
for i in range(n):
    a, b = map(int, input().split())
    max_a = max(a, max_a)
    magics.append((a, b))

#dp[i] -> HPをi減らすのに必要な魔力の最小値
dp = [10 ** 9 + 7 for i in range(h + max_a)]
dp[0] = 0
for i in range(h + max_a):
    for j in magics:
        dp[i] = min(dp[i], dp[max(i - j[0], 0)] + j[1])

print(dp[h])


Measured memory_bytes: 40944
// clang-format off
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979;
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
bool odd(const int &n) { return n & 1; }
bool even(const int &n) { return ~n & 1; }
template<typename T> int len(const T &v) { return v.size(); }
template<typename T = int> T in() { T x; cin >> x; return x; }
template<typename T = int> T in(T &&x) { T z(forward<T>(x)); cin >> z; return z; }
template<typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &x : v) is >> x; return is; }
template<typename A, typename B> istream &operator>>(istream &is, pair<A, B> &p) { return is >> p.first >> p.second; }
template<typename T> ostream &operator<<(ostream &os, const vector<vector<T>> &v) { int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "" : "\n"); return os; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "" : " "); return os; }
template<typename A, typename B> ostream &operator<<(ostream &os, const pair<A, B> &p) { return os << p.first << ' ' << p.second; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
// clang-format on

main() {
  int n, q;
  cin >> n >> q;
  vector<priority_queue<int>> s(n);
  while (q--) {
    int c = in();
    if (c == 0) {
      int t, x;
      cin >> t >> x;
      s[t].emplace(x);
    }
    if (c == 1) {
      int t = in();
      if (s[t].empty()) continue;
      cout << s[t].top() << endl;
    }
    if (c == 2) {
      int t = in();
      if (s[t].empty()) continue;
      s[t].pop();
    }
  }
}



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

int main() {
    int a,b;
    cin >> a >> b;
    if(a%3==0 || b%3==0 || (a+b)%3==0){
        cout << "Possible";
    }
    else{
        cout << "Impossible";
    }
}

Measured memory_bytes: 256
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    println(problem142a(n))
}

fun problem142a(n: Int): Double {
    return if (n % 2 == 0) (n / 2) / n.toDouble() else (n / 2 + 1) / n.toDouble()
}

Measured memory_bytes: 29352
#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 = 1e9 + 7;

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

    LL n, a, b, c, d;
    cin >> n >> a >> b >> c >> d;

    REP(i, n-1){
        if(a + c * i - d * (n - 1 - i) <= b && a + d * i - c * (n - 1 - i) >= b){
            cout << "YES" << endl;
            return 0;
        }
    }
    cout << "NO" << endl;
}


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

using namespace std;	
typedef long long LL;
const int nn = 1e6 + 5;

int main() {
	int A, B;
	scanf("%d %d", & A, & B);
	if (A >= 13) {
		printf("%d\n", B);
	} else if (A >= 6) {
		printf("%d\n", B / 2);
	} else printf("0\n");
}

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

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

  int ans = n - i + 1;

  cout << ans << endl;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Edge
    {
        internal int to, cap, rev;

        public Edge(int to, int cap, int rev)
        {
            this.to = to;
            this.cap = cap;
            this.rev = rev;
        }
    }

    class FordFulkerson
    {
        readonly int n, INFTY = int.MaxValue;

        Dictionary<int, List<Edge>> G;
        bool[] used;

        public FordFulkerson(int V)
        {
            n = V;

            G = new Dictionary<int, List<Edge>>();
            for (int i = 0; i < n; i++) G.Add(i, new List<Edge>());
        }

        public void AddEdge(int from, int to, int cap)
        {
            G[from].Add(new Edge(to, cap, G[to].Count));
            G[to].Add(new Edge(from, 0, G[from].Count - 1));
        }

        public int MaxFlow(int s, int t)
        {
            int flow = 0;

            while (true)
            {
                used = new bool[n];

                int f = DFS(s, t, INFTY);

                if (f == 0) return flow;
                flow += f;
            }
        }

        private int DFS(int v, int t, int f)
        {
            if (v == t) return f;

            used[v] = true;

            for (int i = 0; i < G[v].Count; i++)
            {
                Edge e = G[v][i];

                if (!used[e.to] && e.cap > 0)
                {
                    int d = DFS(e.to, t, Math.Min(f, e.cap));

                    if (d > 0)
                    {
                        e.cap -= d;
                        G[e.to][e.rev].cap += d;
                        return d;
                    }
                }
            }
            return 0;
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int V = int.Parse(input[0]);
            int E = int.Parse(input[1]);

            FordFulkerson FF = new FordFulkerson(V);

            for (int i = 0; i < E; i++)
            {
                input = Console.ReadLine().Split(' ');
                int u = int.Parse(input[0]);
                int v = int.Parse(input[1]);
                int c = int.Parse(input[2]);

                FF.AddEdge(u, v, c);
            }

            Console.WriteLine(FF.MaxFlow(0, V - 1));
        }
    }
}

Measured memory_bytes: 10104
import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    N=I()
    H=I()
    W=I()
    ans=(N-H+1)*(N-W+1)
    print(ans)

main()


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

int main()
{
  int n;
  cin>>n;
  vector<int>arr(n);
  for(int i=0;i<n;i++)
  {
    cin>>arr[i];
  }
  
  vector<int>dp(n);
  dp[0]=0,dp[1]=abs(arr[1]-arr[0]);
  
  for(int i=2;i<n;i++)
  {
    dp[i]=min( dp[i-1] + abs(arr[i]-arr[i-1]) , dp[i-2] + abs(arr[i]-arr[i-2])  );
  }
  cout<<dp[n-1];
  
  return 0;
}

Measured memory_bytes: 1024
#include"bits/stdc++.h"
#include<boost/multi_array.hpp>
#include<boost/optional.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptors.hpp>
#include<boost/operators.hpp>
#include<boost/dynamic_bitset.hpp>

namespace adaptor = boost::adaptors;

std::vector<std::set<int>> set_tree(int N,std::vector<std::set<int>>const& graph)
{
	boost::dynamic_bitset<> flag(N);
	std::vector<std::set<int>> tree(N);
	std::queue<std::pair<int, int>> queue;
	queue.emplace(*std::begin(graph[0]), 0);
	while (queue.size())
	{
		int i, p;
		std::tie(i, p) = queue.front();
		queue.pop();
		if (flag[i])
		{
			continue;
		}
		flag[i] = true;
		tree[i].emplace(p);
		tree[p].emplace(i);
		for (auto n : graph[i])
		{
			queue.emplace(n, i);
		}
	}
	return tree;
}

boost::optional<std::vector<std::pair<int, int>>> run(int N, int M, std::vector<std::set<int>> graph)
{
	std::vector<std::pair<int, int>> directed;
	auto tree = set_tree(N, graph);
	std::queue<int> queue;
	std::vector<int> count(N);
	auto edge_set = [&](int from, int to)
	{
		directed.emplace_back(from, to);
		graph[from].erase(to);
		tree[from].erase(to);
		graph[to].erase(from);
		tree[to].erase(from);
		++count[from];
		if (tree[from].size() == 1)
		{
			queue.emplace(from);
		}
		if (tree[to].size() == 1)
		{
			queue.emplace(to);
		}
	};
	for (auto i : boost::irange(0, N))
	{
		if (tree[i].size() == 1)
		{
			queue.emplace(i);
		}
	}
	while (queue.size())
	{
		auto i = queue.front();
		queue.pop();
		if (tree[i].size() == 0)
		{
			continue;
		}
		auto n = *std::begin(tree[i]);
		if (graph[i].size() == 1)
		{
			if (count[i] % 2 == 1)
			{
				edge_set(i, n);
			}
			else
			{
				edge_set(n, i);
			}
			continue;
		}
		if (count[i] % 2 == 1)
		{
			auto k = *std::begin(graph[i]);
			if (k == n)
			{
				k = *std::next(std::begin(graph[i]));
			}
			edge_set(i, k);
		}
		if (graph[i].size() % 2 == 0)
		{
			auto ite = std::begin(graph[i]);
			auto end = std::end(graph[i]);
			while (ite != end)
			{
				auto k = *ite;
				++ite;
				edge_set(i, k);
			}
		}
		else
		{
			auto ite = std::begin(graph[i]);
			auto end = std::end(graph[i]);
			while (ite != end)
			{
				auto k = *ite;
				++ite;
				if (k != n)
				{
					edge_set(i, k);
				}
			}
		}
	}
	if (std::all_of(count.begin(), count.end(), [](int i) {return i % 2 == 0; }))
	{
		return directed;
	}
	else
	{
		return boost::none;
	}
}

void Main()
{
	int N, M;
	std::cin >> N >> M;
	std::vector<std::set<int>> graph(N);
	for (auto i : boost::irange(0, M))
	{
		int a, b;
		std::cin >> a >> b;
		--a; --b;
		graph[a].emplace(b);
		graph[b].emplace(a);
	}
	auto ret = run(N, M, std::move(graph));
	if (ret)
	{
		for (auto&& p : *ret)
		{
			std::cout << p.first + 1 << " " << p.second + 1 << std::endl;
		}
	}
	else
	{
		std::cout << -1 << std::endl;
	}
}

int main()
{
	std::cin.tie(nullptr);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	Main();
}

Measured memory_bytes: 30080
#include <stdio.h>
#define MAX_N 101
#define INF (1<<28);

int N;
int G[MAX_N][MAX_N];

int main() {
  int i, j, k;
  int id, v, c;
  int tmp;
  for(i = 0; i < MAX_N; ++i) {
    for(j = 0; j < MAX_N; ++j) {
      G[i][j] = i == j ? 0 : INF;
    }
  }
  scanf("%d", &N);
  for(i = 0; i < N; ++i) {
    scanf("%d %d", &id, &k);
    while(k--) {
      scanf("%d %d", &v, &c);
      G[id][v] = c;
    }
  }

  for(k = 0; k < N; ++k) {
    for(i = 0; i < N; ++i) {
      for(j = 0; j < N; ++j) {
        tmp = G[i][k] + G[k][j];
        if(tmp < G[i][j]) G[i][j] = tmp;
      }
    }
  }

  for(i = 0; i < N; ++i) {
    printf("%d %d\n", i, G[0][i]);
  }

  return 0;
}

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

using namespace std;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#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);i>=(b);i--)
#define RREP(i, n) RFOR(i, n, 0)
#define MFOR(i, m) for(auto i=(m).begin();i!=(m).end();i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())

typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1 << 22;


template<typename T>
void printv(vector<T> const& s) {
  REP(i, SZ(s)) {
    cout << s[i] << " ";
  }
  cout << endl;
}

int main () {
  cin.tie(0);
  cout << setprecision(10);

  int n, m, q; cin >> n >> m >> q;
  vector<P> p(m);
  REP(i, m) {
    cin >> p[i].fi >> p[i].se;
    p[i].fi--;
    p[i].se--;
  }

  vector<map<int, int>> a(n);
  REP(i, m) {
    a[p[i].fi][p[i].se]++;
  }

  vvi dp(n);
  REP(i, n){
    dp[i].resize(n, 0);
  }

  
  RREP(i, n-1) {
    if(i == n-1) dp[i][n-1] = a[i][n-1];
    else dp[i][n-1] = dp[i+1][n-1] + a[i][n-1];
    FOR(j, i, n) {
      if(j == i) dp[i][j] = a[i][j];
      else if(i == n-1) dp[i][j] = dp[i][j-1] + a[i][j];
      else if(j == i+1) dp[i][j] = dp[i+1][j] + dp[i][j-1] + a[i][j];
      else dp[i][j] = dp[i+1][j] + dp[i][j-1] - dp[i+1][j-1] + a[i][j];
    }
  }

  REP(i, q) {
    int p, q; cin >> p >> q;
    cout << dp[p-1][q-1] << endl;
  }
  
}


Measured memory_bytes: 9344
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long N;
  cin>>N;
  int a=0;
  long long M;
  M=N;
  while(1){
  	if(M==0)break;
  	a=a+M%10;
    M=M/10;
  }
  if(N%a==0)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <chrono>
using namespace std;
using namespace std::chrono;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
vector<int> dx={0,1,0,-1},dy={-1,0,1,0};



struct Timer{
	time_point<system_clock> start;
	Timer() : start(system_clock::now()) {}
	double seconds() {return duration<double>(system_clock::now() - start).count();}
};


struct Edge{
	int u, v, d;
};


struct Info{
	int id, u, t;
};


int T = 10000, V = 400, E = 800;
const int inf = 1000000000;
vector<Edge> G;
vector<Info> info;
vector<vector<int>> G2;
vector<bool> carry, delivered;
vector<int> ans;



void input(){
	cin >> V >> E;
	G.resize(E);
	G2.resize(V);
	rep(i,V){
		G2.at(i).resize(V);
		rep(j,V){
			G2.at(i).at(j) = inf;
		}
	}
	rep(i,E){
		cin >> G.at(i).u >> G.at(i).v >> G.at(i).d;
		G.at(i).u--;
		G.at(i).v--;
		G2[G.at(i).u][G.at(i).v] = G.at(i).d;
		G2[G.at(i).v][G.at(i).u] = G.at(i).d;
	}
	
	/*
	rep(k,V){
		rep(i,V){
			if(G2[i][k] == -1) continue;
			rep(j,V){
				if(G2[k][j] == -1) continue;
				G2[i][j] = min(G2[i][j], G2[i][k] + G2[k][j]);
			}
		}
	}
	*/
	
	cin >> T;
	rep(i,T){
		int n;cin >> n;
		if(n == 1){
			Info I;
			cin >> I.id >> I.u;
			I.u--;
			I.t = i;
			info.pb(I);
		}
	}
	ans.resize(T);
	rep(i,T) ans.at(i) = -2;
	carry.resize(info.size());
	delivered.resize(info.size());
	rep(i,info.size()){
		carry.at(i) = false;
		delivered.at(i) = false;
	}
}


void output(){
	rep(i,T){
		cout << ans.at(i) + 1 << endl;
	}
}


deque<int> order;


void solve(){
	rep(i,T){
		rep(j,info.size()){
			if(!delivered.at(j) && info[j].t <= i) carry.at(j) = true;
		}
		int mi = inf, num = 0;
		rep(j,info.size()){
			if(carry.at(j)){
				if(G2[0][info[j].u] < mi){
					mi = G2[0][info[j].u];
					num = info[j].u;
				}
			}
		}
		if(mi < inf){
			for(int j = 0; j < mi && i + j < T; j++){
				ans.at(i + j) = num;
			}
			i += mi;
			for(int j = 0; j < mi && i + j < T; j++){
				ans.at(i + j) = 0;
			}
			i += mi - 1;
		}
	}
}


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

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

signed main () {
	int n, q;
	cin >> n >> q;
	vector < pair < int, pair < int, int > > > schedule;
	for (int i = 0; i < n; ++i) {
		int s, t, x;
		cin >> s >> t >> x;
		schedule.push_back(make_pair(x, make_pair(s - x, t - x - 1)));
	}
	multiset < pair < int, int > > d;
	for (int i = 0; i < q; ++i) {
		int x;
		cin >> x;
		d.insert(make_pair(x, i));
	}
	vector < int > ans(q, -1);
	sort(schedule.begin(), schedule.end());
	for (auto pr: schedule) {
		if (d.empty())
			break;
		else {
			int x = pr.first, l = pr.second.first, r = pr.second.second;
			auto it = d.lower_bound(make_pair(l, -1));
			vector < pair < int, int > > rem;
			while (!d.empty() && it != d.end() && it -> first <= r) {
				rem.push_back(*it);
				it = next(it);
			}
			for (auto prr: rem) {
				ans[prr.second] = x;
				d.erase(d.find(prr));
			}
			
		}
	}
	for (int i = 0; i < q; ++i) 
		cout << ans[i] << '\n';
}


Measured memory_bytes: 15472
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cctype>
typedef long long i64;
using namespace std;
inline int read(int f = 1, int x = 0, char ch = ' ')
{
    while(!isdigit(ch = getchar())) if(ch == '-') f = -1;
    while(isdigit(ch)) x = x*10+ch-'0', ch = getchar();
    return f*x;
}
const int N = 2e3+5;
int n, m, tot, nxt[N<<1], to[N<<1], h[N], ans, s[N], f[N], g[N]; char a[N];
void add(int x, int y) { nxt[++tot] = h[x], to[tot] = y, h[x] = tot; }
void dfs(int x, int fa)
{
    s[x] = a[x] == '1', g[x] = 0; int p = 0;
    for(int i = h[x], y; i; i = nxt[i]) if((y = to[i]) != fa) 
        dfs(y, x), s[x] += s[y], g[x] += (g[y]+=s[y]), p = g[p]>g[y]?p:y;
    f[x] = 2*g[p]<=g[x]?g[x]/2:g[x]-g[p]+min(f[p], (2*g[p]-g[x])/2);
}
int main()
{
    n = read(), scanf("%s", a+1), ans = -1;
    for(int i = 1, x, y; i < n; ++i) x = read(), y = read(), add(x, y), add(y, x);
    for(int x = 1; x <= n; ++x) 
    {
        dfs(x, 0);
        if(f[x]*2 == g[x]) ans = ~ans?min(ans, f[x]):f[x];
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define div1 1000000007
const long long INF = 1LL << 60;
using namespace std;
typedef long long ll;
typedef long double ld;
// a>b -> a==b;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
// a<b -> a==b;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

int main(void)
{
    ll N, K, i, j, d[101], A[101][101], judge[101]={0}, ans=0;

    cin >> N >> K;

    for(i=1; i<=K; i++){
        cin >> d[i];

        for(j=1; j<=d[i]; j++){
            cin >> A[i][j];
            judge[A[i][j]]++;
        }
    }

    for(i=1; i<=N; i++){
        if(judge[i]==0) ans++;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3684
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func Scanner() string {
	sc.Scan()
	return sc.Text()
}

func intScanner() int {
	n, _ := strconv.Atoi(Scanner())
	return n
}

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, 1000000007)
	sc.Split(bufio.ScanWords)
	a, b := intScanner(), intScanner()
	x := smaller(b-1, intScanner())
	fmt.Println((a * x) / b)
}
func smaller(x, y int) int {
	if x < y {
		return x
	} else {
		return y
	}
}


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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
typedef long long ll;
#define mod 1000000007
const int maxn = 200010;
ll fac[maxn+1];
void factorial(){
    fac[0] = 1; 
    for (ll i=1 ; i<=maxn; i++) 
        fac[i] = fac[i-1]*i%mod; 
}

ll power(ll x, ll y){ 
    ll res = 1; 
    x = x % mod;
    while (y > 0){ 
    	if (y & 1) 
            res = (res*x) % mod; 
        y = y>>1;
        x = (x*x) % mod; 
    } 
    return res; 
} 
//Inverse
ll inverse(ll n){ 
    return power(n, mod-2);
}

ll func(ll n, ll r) {    
	if (r==0) 
      return 1; 
    return (fac[n]* inverse(fac[r]) % mod * inverse(fac[n-r]) % mod) % mod; 
}

int main() {
    fastio
    ll n, k; cin >> n >> k;
    factorial();
    
    k = min(n, k);
    ll res = 0;
    for(ll i = 0; i <= k ; i++){
		res += func(n, i)*func(i + (n-i-1), n-i-1);
		res %= mod;
	}
    //ll res = func(k+n-1, n-1);
    //ll ch = func(15, 7);
    cout<<(res)%mod<<endl;
	return 0;
}






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

int n;

int main(){
  cin >> n;
  string res = "APPROVED";
  rep(i, n){
    int a; cin >> a;
    if(a % 2 == 0 && (a % 3 != 0 && a % 5 != 0)){
      res = "DENIED";
    }
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 256
N,K = map(int,input().split())
list1 = []
for i in range(N):
    list1.append(list(map(int,input().split())))
num = [0]*(10**5+1)
for j in range(N):
    num[list1[j][0]] += list1[j][1]
c = 0
d = 0
for k in range(10**5+1):
    c += num[k]
    if c >= K:
        d = k
        break
print(d)

Measured memory_bytes: 30288
import java.util.Scanner
import java.util.HashSet

fun main(args: Array<String>) {
  val cin = Scanner(System.`in`)
  val str = cin.next()

  var hsc: HashSet<Char> = hashSetOf()

  for (c in str) {
    hsc.add(c)
  }

  if (str.length == hsc.size) {
    println("yes")
  } else {
    println("no")
  }
  cin.close()
}

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

using namespace std;
#define INF 100001

int main()
{
    int N,W;
    cin >> N >> W;
    vector<int> v(N+1,0),w(N+1,0),m(N+1,0);
    vector<int> dp(W+1,0);
    for(int i = 1; i <= N ;i ++){
        cin >> v[i] >> w[i] >> m[i];
    }


    for(int i = 1;i <= N;i++){
        for(int k = 1; m[i] > 0;k++){
            int l = min(k,m[i]);
            for(int j = W;j >=w[i]*l;j--){
                dp[j] = max(dp[j],dp[j-w[i]*l]+v[i]*l);
            }
            m[i]-=l;
        }
    }
    int ans = 0;
    for(int i = 0;i <= W;i++){
        ans = max(ans,dp[i]);
    }
    cout << ans << "\n"; 
}




Measured memory_bytes: 3152
#include <iostream>
    #include <string>
    using namespace std;
     
    int main()
    {
        string s;
        cin >> s;
        int l;
        while((l = s.length()) != 0){
            if(s.rfind("erase") == l-5 || s.rfind("dream") == l-5){
                s = s.substr(0, l-5);
            }else if(s.rfind("eraser") == l-6){
                s = s.substr(0, l-6);
            }else if(s.rfind("dreamer") == l-7){
                s = s.substr(0, l-7);
            }else{
                cout << "NO" << endl;
                return 0;
            }
        }
        cout << "YES" << endl;
        return 0;
    }

Measured memory_bytes: 512