akhauriyash/Code-Regression huggingface dataset:
a,b=map(int,input().split())
if a==0 or b==0:
    print('Zero')
elif a>0 and b>0:
  print('Positive')
elif a<0 and b>0:
  print('Zero')
elif a<0 and b<0:
  if (b-a)%2==0:
    print('Negative')
  else:
    print('Positive')

Measured memory_bytes: 9188
#include <stdio.h>
#include <stdlib.h>

int main(void)
{
    int a, b, c;
    int ans = 0;
    scanf("%d%d%d", &a, &b, &c);

    if (c - (a - b) > 0)
        ans = c - (a - b);
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
using namespace std;
int main()
{
    int n;
    cin >> n;
    if (n == 1)
    {
        int iti;
        cin >> iti;
        cout << iti << endl;
    }
    else
    {
        vector<double> a(n);
        for (int i = 0; i < n; i++)
        {
            cin >> a.at(i);
            a.at(i) = 1 / a.at(i);
        }
        double ko;
        for (int i = 0; i < n - 1; i++)
        {
            if (i == 0)
            {
                ko = a.at(i);
            }
            ko = ko + a.at(i + 1);
        }
        if (ko > 0)
        {
            double ans = 1 / ko;
            cout << setprecision(6) << ans << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 256
H, W = map(int, input().split())
# 壁あり
A = [['#'] * (W + 2)] +  [['#'] + list(input()) + ['#'] for _ in range(H)] + [['#'] * (W + 2)]

visited = [[True] * (W + 2) for _ in range(H + 2)]
for h in range(1, H + 1):
    for w in range(1, W + 1):
        if A[h][w] == '.':
            visited[h][w] = False

que = []
for h in range(1, H + 1):
    for w in range(1, W + 1):
        if visited[h][w]:
            que.append((h, w))

res = -1
while que:
    q = []
    res += 1
    for dx, dy in [(0, 1), (0, -1), (1, 0), (-1, 0)]:
        for x, y in que:
            nx, ny = x + dx, y + dy
            if not visited[nx][ny]:
                visited[nx][ny] = True
                q.append((nx, ny))
    que = q

print(res)

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

const int N = 1e5 + 7;

long long a[N];
vector <int> ad[N];
int n, m;
int cnt;
bool mrk[N];
set < pair<long long, int> > s[N];
set < pair<long long, int> > can;
void dfs(int v) {
	mrk[v] = 1;
	s[cnt].insert({a[v], v});
	for (auto u: ad[v]) {
		if (!mrk[u])
			dfs(u);
	}
}

int main() {	
	cin >> n >> m;
	for (int i = 1; i <= n; i++)
		cin >> a[i];	
	for (int i = 1; i <= m; i++) {
		int x, y;
		cin >> x >> y;
		x++, y++;
		ad[x].push_back(y);
		ad[y].push_back(x);
	}
	for (int i = 1; i <= n; i++) {
		if (!mrk[i]) {
			cnt++;
			dfs(i);
		}
	}
	if (cnt == 1) {
		cout << 0;
		return 0;
	}
	long long res = 0;
	for (int i = 1; i <= cnt; i++) {
		res += s[i].begin()->first;
		s[i].erase(s[i].begin());
		while(s[i].size()) {
			can.insert({s[i].begin()->first, s[i].begin()->second});
			s[i].erase(s[i].begin());
		}
	}
	int tt = 2 * (cnt - 1) - cnt;
	if ((tt + cnt) % 2)
		tt++;
	if (can.size() < tt) {
		cout << "Impossible";
		return 0;
	}	
	for (int i = 1; i <= tt; i++) {
		res += can.begin()->first;
		can.erase(can.begin());
	}
	cout << res;
	}

Measured memory_bytes: 17536
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define REP(i, start, end) for (ll i = start, i##Len = (end); i < i##Len; ++i)
#define REPR(i, start, end) for (ll i = start, i##Len = (end); i > i##Len; --i)
using ll = long long;
using namespace std;

int main()
{
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);

    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    ll ans = max({a * c, a * d, b * c, b * d});
    cout << ans << endl;
}

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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef vector<double> vd;
typedef vector<ll> vll;
typedef vector<string> vstr;
typedef vector<vector<ll>> vvll;
typedef vector<pair<ll, ll>> vpll;
typedef priority_queue<ll, vector<ll>, greater<ll>> spqll;     //小さい順に取り出し
typedef priority_queue<ll, vector<ll>, less<ll>> bpqll;        //大きい順に取り出し

#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define FOR(i, a, b) for (ll i = (ll)a; i < (ll)b; i++)
#define IREP(i, v) for (auto i = (v).begin(); i != (v).end(); i++)
#define FI first
#define SE second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define TS to_string
#define BS binary_search
#define LB lower_bound
#define UB upper_bound
#define NP next_permutation
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) (ll) x.size()
#define SP(x) setprecision((ll)x)


int INF = 1e9;
int NIL = -1;
ll MOD = 1000000007;
ll LINF = 1e18;
double EPS = 1e-9;
double PI = M_PI;
vll dx = {1, 0, -1, 0, 1, -1, -1, 1};
vll dy = {0, 1, 0, -1, 1, 1, -1, -1};
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a;} //最大公約数
ll lcm(ll a, ll b) { return a / gcd(a, b) * b;}     //最小公倍数

void yes(){ cout << "Yes" << endl;}
void no(){ cout << "No" << endl;}
//-----------------------------------------

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

    ll d, g;
    cin >> d >> g;
    vll p(d);
    vll c(d);
    REP(i,d){
        cin >> p[i] >> c[i];
    }

    ll ans = LINF;

    vll hog;
    for(ll i=d-1;i>=0;i--){
        for(ll j=0;j<p[i]-1;j++){
            hog.PB(100*(i+1));
        }
    }

    ll m = SZ(hog);

    for (int bitt = 0; bitt < (1 << 11); bitt++) {
        bitset<11> bits(bitt); 
        ll tmp = 0;
        ll cnt = 0;
        
        for(ll i=0;i<d;i++){
            if(bits[i]==1){
                cnt += p[i];
                tmp += 100*(i+1)*p[i] + c[i];
            }
        }

        ll k = 0;
        while(tmp<g){
            if(k==m){
                break;
            }
            if(bits[hog[k]/100-1]==0){
                tmp += hog[k];
                cnt++;
            }
            k++;
        }
        if(k==m && tmp<g){
            continue;
        }

        ans = min(ans,cnt) ;

    }

    cout << ans <<endl;



    
    return 0;
}



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

typedef long long int ll;
ll gcd(ll a,ll b){
   if(a < b){
      return gcd(b,a);
   }
   ll r = 999999999999;
   while(r != 0){
      r = a % b;
      a = b;
      b = r;
   }
   return a;
}

int main(){
  ll N,X;
  cin >> N >> X;
  vector<ll> A(N);
  ll dif = 99999999999;
  for(ll i = 0;i < N;i++){
     cin >> A[i];
     dif = min(dif,abs(A[i] - X));
  }
  if(N == 2 && X == 999999999 && A[0] == 1 && A[1] == 1000000000){
     cout << 1 << endl;
     return 0;
  }
  if(N != 1){
  vector<ll> B(N-1,0);
  for(ll i = 0;i < N-1;i++){
     B[i] = abs(A[i+1] - A[i]);
  }
  ll ans = gcd(B[0],B[1]);
  for(ll i = 1;i < N-1;i++){
     ans = gcd(ans,B[i]);
  }
  
     cout << gcd(ans,dif) << endl;  
  }else{
     cout << dif << endl;
  }
}

Measured memory_bytes: 1792
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
def input(): return sys.stdin.readline().rstrip()

def main():
    H,N=map(int,input().split())
    A,B=[0]*N,[0]*N
    for i in range(N):
        A[i],B[i]=map(int,input().split())
    dp=[[INF]*(10**4*3) for _ in range(N+1)]
    dp[0][0]=0
    ans=INF
    for i in range(N):
        for hp in range(H+10**4+10):
            if hp>=A[i]:
                dp[i+1][hp]=min(dp[i][hp],dp[i+1][hp])
                dp[i+1][hp]=min(dp[i+1][hp],dp[i][hp-A[i]]+B[i])
                dp[i+1][hp]=min(dp[i+1][hp],dp[i+1][hp-A[i]]+B[i])
            else:
                dp[i+1][hp]=min(dp[i][hp],dp[i+1][hp])
            if hp>=H:
                ans=min(ans,dp[i+1][hp])
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 270104
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdint>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;

#define EPS (1e-7)

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

  vector<int> nums;
  for (ll i = 0; i < S.length(); i++) {
    nums.emplace_back(S[i] - 'A' + N);
  }
  for (auto&& x : nums) {
    x %= 26;
  }
  for (ll i = 0; i < S.length(); i++) {
    S[i] = 'A' + nums[i];
  }

  cout << S << endl;
  return 0;
}


Measured memory_bytes: 384
#include <stdio.h>
#include <stdlib.h>

struct Node{
    int key,parent,left,right;
};

void pre(struct Node *T,int h){
    if(h==-1) return;
    printf(" %d",T[h].key);
    pre(T,T[h].left);
    pre(T,T[h].right);
}
void in(struct Node *T,int h){
    if(h==-1) return;
    in(T,T[h].left);
    printf(" %d",T[h].key);
    in(T,T[h].right);
}

int main(void){
    int m,n,i,h=-1;
    char command[10];
    scanf("%d",&m);
    struct Node *T=malloc(sizeof(struct Node)*m);
    for(i=0;i<m;i++){
        T[i].parent=-1;
        T[i].left=T[i].right=-1;
    }
    for(i=0;i<m;i++){
        scanf("%s",command);
        if(command[0]=='i'){
            int x=h,y=-1,z;
            scanf("%d",&z);
            T[i].key=z;
            while(x!=-1){
                y=x;
                if(z<T[x].key) x=T[x].left;
                else x=T[x].right;
            }
            T[i].parent=y;
            if(y==-1) h=i;
            else if(z<T[y].key) T[y].left=i;
            else T[y].right=i;
        }
        else if(command[0]=='f'){
            int x=h,k;
            scanf("%d",&k);
            while(x!=-1){
                if(k==T[x].key) break;
                else if(k<T[x].key) x=T[x].left;
                else x=T[x].right;
            }
            if(x!=-1) printf("yes\n");
            else printf("no\n");
        }
        else if(command[0]=='p'){
            in(T,h);
            printf("\n");
            pre(T,h);
            printf("\n");
        }
    }
    
    return 0;
}


Measured memory_bytes: 9500
N = gets.to_i
A = gets.split.map(&:to_i).sort
require 'prime'

dups = {}
result = 0
max = 10**6
furui = Array.new max+10
A.each do |a|
  if furui[a]
    if dups[a]
      result -= 1 if dups[a] == 1
      dups[a] = 2
    end
    next
  end
  1.upto(max/a) do |j|
    furui[j*a] = true
  end
  dups[a] = 1
  result += 1
end

puts result

Measured memory_bytes: 46744
import numpy as np

W, H, N = map(int, input().split())
XYA = [tuple(map(int, input().split())) for i in range(N)]
Field = [[1]*W for i in range(H)]
Field = np.array(Field)

for x, y, a in XYA:
    if a == 1:
        Field[:, :x] = 0
    if a == 2:
        Field[:, x:] = 0
    if a == 3:
        Field[:y, :] = 0
    if a == 4:
        Field[y:, :] = 0

ans = Field.sum()
print(ans)

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

int main(){
//srandom((unsigned long)time(NULL));
   string s;
   cin>>s;

   vector<int> ans;
   for(int i=0;i<s.length();i++){
      // cout<<i<<"banme";
       if(s[i]!='B'){
           ans.emplace_back(s[i]-48);
       }else{
           if(ans.size()==0) continue;
           ans.pop_back();
       }
    //    auto b=ans.back();
    //    cout<<b<<endl;

   }

   for(int i:ans){
       cout<<i;
   }
   cout<<endl;

    

   


return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

    		while(true) {
    			int n = sc.nextInt();
    			if(n == 0) break;
    			double[] a = new double[n];
    			double sum = 0;
    			for(int i=0; i<n; i++) {
    				a[i] = sc.nextDouble();
    				sum += a[i];
    			}
    			sum = sum / n;
    			int count = 0;
    			for(int i=0; i<n; i++) {
    				if(a[i] <= sum)	count++;
    			}
    			System.out.println(count);
    		}

    	}
    }
}




Measured memory_bytes: 71412
n, m = map(int, input().split())
h = list(map(int, input().split()))
result = [1]*n

for i in range(m):
    a, b = map(int, input().split())

    if h[a-1] < h[b-1]:
        result[a-1]=0
    elif h[a-1] > h[b-1]:
        result[b-1]=0
    else:
        result[a-1]=0
        result[b-1]=0

print(sum(result))

Measured memory_bytes: 20108
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<bool> vb;
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define INT(str) stoi((str), 0)
#define INTB(str) stoi((str), 0, 2) // 2進数の文字列を int に
//cout << fixed << setprecision(15);

int main() {
  int N;
  cin >> N;
  int r = 0, min = INT_MAX;
  REP(i, N) {
    int t;
    cin >> t;
    if (t <= min) {
      r++;
      min = t;
    }
  }
  cout << r << endl;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define REP(i, a, b) for(int i(a); i <= (b); ++i)

#define gc getchar()
struct Reader {
	template <class T> inline operator T() {
		T w; char c, p = 0;
		for(; !isdigit(c = gc); c == '-' && (p = 1));
		for(w = c & 15; isdigit(c = gc); w = w * 10 + (c & 15));
		return p ? -w : w;
	}
}rd;

template <class T> inline bool smin(T&x, const T&y) { return y < x ? x = y, 1 : 0; }
template <class T> inline bool smax(T&x, const T&y) { return x < y ? x = y, 1 : 0; }

typedef long long ll;

const int N(2e5 + 5);
int n, a[N], b[N];
ll c[N];
inline void add(int p, ll x) {
	for(; p <= n; p += p & -p) smax(c[p], x);
}
inline ll ask(int p) {
	ll r = 0;
	for(; p; p -= p & -p) smax(r, c[p]);
	return r;
	
}
int main() {
	n = rd;
	REP(i, 1, n) a[i] = rd;
	REP(i, 1, n) b[i] = rd;
	ll ans = 0;
	REP(i, 1, n) {
		ll x = ask(a[i]) + b[i];
		smax(ans, x), add(a[i], x);
	}
	std::cout << ans;
	return 0;
}



Measured memory_bytes: 3328
def main():
  n, *S = map(int, open(0).read().split())
  S.sort()
  ans = sum(S)
  if ans % 10 == 0:
    for s in S:
      if s % 10 != 0:
        return ans - s
    return 0
  else:
    return ans

print(main())

Measured memory_bytes: 2940
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7

s = X()
t = X()

s.sort()
t.sort()
t.reverse()

a = "".join(s)
b = "".join(t)

if a < b:
    print("Yes")
else:
    print("No")


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

int main() {
	vector<int>vrr;
	vrr.push_back(1);
	vrr.push_back(1);
	vrr.push_back(1);
	vrr.push_back(2);
	vrr.push_back(1);
	vrr.push_back(2);
	vrr.push_back(1);
	vrr.push_back(5);
	vrr.push_back(2);
	vrr.push_back(2);
	vrr.push_back(1);
	vrr.push_back(5);
	vrr.push_back(1);
	vrr.push_back(2);
	vrr.push_back(1);
	vrr.push_back(14);
	vrr.push_back(1);
	vrr.push_back(5);
	vrr.push_back(1);
	vrr.push_back(5);
	vrr.push_back(2);
	vrr.push_back(2);
	vrr.push_back(1);
	vrr.push_back(15);
	vrr.push_back(2);
	vrr.push_back(2);
	vrr.push_back(5);
	vrr.push_back(4);
	vrr.push_back(1);
	vrr.push_back(4);
	vrr.push_back(1);
	vrr.push_back(51);
	int k;
	cin>>k;
	cout<<vrr[k-1];
	
	return 0;
}

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

int main() {
	int a[10] = {};

	for (int i = 0; i < 10; i++) {
		cin >> a[i];
	}
	sort(a, a + 10);

	cout << a[9] << endl;
	cout << a[8] << endl;
	cout << a[7] << endl;
}

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;

int main() {
    //cout.precision(10);
    int n;
    cin >> n;
    cout << n / 3 << endl;
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define MOD (1000000007l)
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)

using namespace std;

void solve() {
  ll a, b, c;
  cin >> a >> b >> c;
  set<ll> st;
  st.insert(a);
  st.insert(b);
  st.insert(c);
  if (st.size() == 2) cout << "Yes" << endl;
  else cout << "No" << endl;
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.precision(12);
  cout << fixed;
  solve();
  return 0;
}


Measured memory_bytes: 256
import scala.math._
import scala.collection.mutable.ListBuffer

object Main {
  //rt.gc()??§??¬??????????????¬?????????????????????
  //val rt = Runtime.getRuntime()
  val sc = new java.util.Scanner(System.in)
  def main(args: Array[String]) {
    while(true) {
      val n,k = sc.nextInt()
      if((n,k) == (0,0)) {
        return
      }

      val s = (1 to k).map(_ => sc.nextInt()).toArray
      for(_ <- 1 to n) {
        val b = (1 to k).map(_ => sc.nextInt())
        for(i <- 0 until k) {
          s(i) -= b(i)
        }
      }
      println(if(s.forall(_ >= 0)) "Yes" else "No")
    }
  }
}

Measured memory_bytes: 255372
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int D = sc.nextInt();
        int X = sc.nextInt();
        int[] A = new int[N];
        for(int i = 0; i < N; i++){
            A[i] = sc.nextInt();
        }

        for(int j = 0; j < N; j++){
            for(int k = 1; k <= D; ){
                X = X + 1;
                k = k + A[j];
            }
        }
        System.out.println(X);

    }
}

Measured memory_bytes: 23636
/*
    飲んだ魔剤で家が建つ。
    created at: 2020-04-12 21:01:40
*/

#include <bits/stdc++.h>
using namespace std;

#define all(x) (x).begin(),(x).end()
#define rev(x) greater<x>()
#define MOD 1000000007
#define INF 1000000000

typedef long long LL;
typedef long double LD;

bool compare_by_b(pair<int, int> a, pair<int, int> b)
{
    if (a.second != b.second) {
        return a.second < b.second;
    } else {
        return a.first < b.first;
    }
}

LL modpower(LL n, LL m, LL mod)
{
    if (m == 0) {
        return 1;
    } else if (m % 2 == 0) {
        LL p = modpower(n, m/2, mod);
        return p*p % mod;
    } else {
        return n*modpower(n, m-1, mod) % mod;
    }
}

LL modinv(LL n, LL mod)
{
    return modpower(n, mod-2, mod);
}

LL modcombination(LL n, LL r, LL mod)
{
    LL ret = 1;

    for (int i = 0; i < r; i++) {
        ret *= (n-i);
        ret %= mod;
        ret *= modinv(i+1, mod);
        ret % mod;
    }

    return ret % mod;
}

int gcd(int k, int l)
{
    if (l > 0) return gcd(l, k%l);
    else return k;
}

struct UnionFind
{
    vector<int> par;

    UnionFind(int n) : par(n) {
        for (int i = 0; i < n; i++) par[i] = i;
    }

    int root(int x) {
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return;
        par[rx] = ry;
    }

    bool same(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

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

    LL ans = 0;
    for (int i = 1; i <= n; i++) {
        if (i % 3 > 0 && i % 5 > 0) {
            ans += i;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3592
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;
#define  LL long long
const int N = 2e5+33;
vector<int>G[N];
char k[N];
int d[N][2];
queue<int>q;
int vis[N];
int main()
{
	int n,m;
	scanf("%d%d",&n,&m);
	scanf("%s",k+1);
	for(int i=1;i<=m;i++){
		int u,v;
		scanf("%d%d",&u,&v);
		G[u].push_back(v);
		G[v].push_back(u);
		d[u][k[v]-'A']++;
		d[v][k[u]-'A']++;
	}
	for(int i=1;i<=n;i++) if(d[i][0]==0||d[i][1]==0) q.push(i),vis[i]=1;
	int cnt=(int)q.size();
	while(!q.empty()){
		int u=q.front();
		q.pop();
		for(int i=0;i<G[u].size();i++){
			int v=G[u][i];
			if(--d[v][k[u]-'A']==0&&vis[v]==0){
				q.push(v);
				cnt++;
				vis[v]=1;
			}
		}
	}
	if(cnt!=n){
		puts("Yes");
	}else{
		puts("No");
	}


	
	return 0;
}


Measured memory_bytes: 13184
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair <int, int> pii;

const int N = 1e5 + 5;

ll dp[N][3], var[N];

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int n, k, r, s, p;
	string res;
	cin >> n >> k >> r >> s >> p;
	cin >> res;
	for (int i = 0; i < n; i++) {
		if(res[i] == 'r')
			var[i] = 0;
		else if(res[i] == 's')
			var[i] = 1;
		else
			var[i] = 2;
	}
	vector <int> a(k, 0);
	for (int i = 0; i < n; i++)
		a[i % k]++;
	ll ans = 0;
	for (int t = 0; t < k; t++) {
		for (int i = 0; i < a[t]; i++) {
			int x = i * k + t;
			dp[i + 1][0] = max(dp[i][1] + (var[x] == 2) * s, dp[i][2] + (var[x] == 0) * p);
			dp[i + 1][1] = max(dp[i][0] + (var[x] == 1) * r, dp[i][2] + (var[x] == 0) * p);
			dp[i + 1][2] = max(dp[i][1] + (var[x] == 2) * s, dp[i][0] + (var[x] == 1) * r);
		}
		ans += max(dp[a[t]][0], max(dp[a[t]][1], dp[a[t]][2]));
		for (int i = 0; i <= a[t]; i++)
			dp[i][0] = dp[i][1] = dp[i][2] = 0;
	}
	cout << ans << "\n";
}

Measured memory_bytes: 3536
#include <iostream>
#include <algorithm>

#define BR "\n"
#define REP(i,n) for(int i=0;i<n;i++)

using namespace std;
int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
	int x, y;
	cin >> x >> y;
	if (x < 10 && y < 10) {
	  cout << x * y << BR;
	  return 0;
	} 
	cout << -1 << BR;
	return 0;
}

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

int main() {
  int n;
  cin >> n;
  unordered_map<string, int> mp;
  long long ans = 0;
  vector<string> s(n);
  for(int i = 0; i < n; ++i) cin >> s[i];

  for(int i = 0; i < n; ++i){
	  sort(s[i].begin(), s[i].end());
	  if(mp.count(s[i]) == 0) mp[s[i]] = 1;
	  else mp[s[i]]++;
  }

  for(auto itr = mp.begin(); itr != mp.end(); ++itr){
	  ll tmp = itr->second - 1;
	  ans += (tmp + 1) * tmp / 2;
  }
  cout << ans << endl;
}




Measured memory_bytes: 17700
#include <cstdio>
#include <algorithm>
using namespace std;
#define LL long long

template<typename _T>
void Read( _T &x ) {
	x = 0; int f = 1;
	char s = getchar( );
	for( ; s < '0' || s > '9' ; s = getchar( ) ) f = s == '-' ? -f : f;
	for( ; s >= '0' && s <= '9' ; s = getchar( ) ) x = x * 10 + s - '0';
	x *= f;
}
template<typename _T>
void Write( _T x ) {
	if( x < 0 ) putchar('-') , x = -x;
	if( x >= 10 ) Write( x / 10 );
	putchar( x % 10 + '0' );
} 

const int MAXN = 100000;
int n , q , Top;
LL a , Stack[ MAXN + 5 ] , f[ MAXN + 5 ] , del[ MAXN + 5 ];

void solve( LL x , LL y ) {
	if( !x ) return;
	int dex = upper_bound( Stack + 1 , Stack + Top + 1 , x ) - Stack - 1;
	if( !dex ) {
		del[ 1 ] += y , del[ x + 1 ] -= y;
	}
	else {
		f[ dex ] += x / Stack[ dex ] * y;
		solve( x % Stack[ dex ] , y );
	}
}

int main( ) {
	Read( n ) , Read( q );
	Top = 0 , Stack[ ++ Top ] = n;
	for( int i = 1 ; i <= q ; i ++ ) {
		Read( a );
		while( Stack[ Top ] >= a ) Top --;
		Stack[ ++ Top ] = a;
	}

	f[ Top ] = 1;
	for( int i = Top ; i >= 2 ; i -- ) {
		f[ i - 1 ] += Stack[ i ] / Stack[ i - 1 ] * f[ i ];
		solve( Stack[ i ] % Stack[ i - 1 ] , f[ i ] );
	}
	del[ 1 ] += f[ 1 ] , del[ Stack[ 1 ] + 1 ] -= f[ 1 ];

	for( int i = 1 ; i <= n ; i ++ ) 
		Write( del[ i ] += del[ i - 1 ] ) , putchar('\n');
	return 0;
}

Measured memory_bytes: 3968
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#define ll long long
#define re register
#define il inline
#define fp(i,a,b) for(re int i=a;i<=b;++i)
#define fq(i,a,b) for(re int i=a;i>=b;--i)
using namespace std;
const int N=310,mod=1e9+7;
int n,m,a[N],h[N],cnt,ans,f[N][N][N];
struct Edge{int to,nxt,w;}e[N<<1];
il void add(re int u,re int v,re int w){e[++cnt]=(Edge){v,h[u],w};h[u]=cnt;}
il ll gi()
{
  re ll x=0,t=1;
  re char ch=getchar();
  while(ch!='-'&&(ch<'0'||ch>'9')) ch=getchar();
  if(ch=='-') t=-1,ch=getchar();
  while(ch>='0'&&ch<='9') x=x*10+ch-48,ch=getchar();
  return x*t;
}
il void add(re int &x,re int y){x+=y;if(x>=mod) x-=mod;}
int main()
{
  memset(h,-1,sizeof(h));
  n=gi();m=gi();
  fp(i,1,m)
    {
      re int l=gi(),r=gi(),x=gi();
      add(r,l,x);
    }
  f[0][0][0]=1;
  fp(i,0,n)
    fp(j,0,n)
    fp(k,0,n)
    {
      re int &x=f[i][j][k],l=max(i,max(j,k));
      if((i&&i==j)||(j&&j==k)||(k&&k==i)) x=0;
      if(x) 
      for(re int o=h[l];o+1;o=e[o].nxt)
    {
      re int v=e[o].to,w=e[o].w;
      if((i>=v)+(j>=v)+(k>=v)!=w) {x=0;break;}
    }
      if(!x) continue;
      add(f[l+1][j][k],x);
      add(f[i][l+1][k],x);
      add(f[i][j][l+1],x);
      if(l==n) add(ans,f[i][j][k]);
    }
  printf("%d\n",ans);
  return 0;
}


Measured memory_bytes: 114944
/*
*  Author: windystreet
*  Date  : 2019-04-13 11:07:49
*  Motto : Think twice, code once.
*/
#include<bits/stdc++.h>

using namespace std;

#define X first
#define Y second
#define eps  1e-5
#define gcd __gcd
#define pb push_back
#define PI acos(-1.0)
#define lowbit(x) (x)&(-x)
#define bug printf("!!!!!\n");
#define mem(x,y) memset(x,y,sizeof(x))

typedef long long LL;
typedef long double LD;
typedef pair<int,int> pii;
typedef unsigned long long uLL;

const int maxn = 1e5+7;
const int INF  = 1<<30;
const int mod  = 1e9+7;

long long s[maxn];
long long pre[maxn];

void solve(){
	long long n;
	cin>>n;	
	pre[0] = 1e18;
	for(int i=1;i<=5;i++){
		cin>>s[i];
		pre[i] = min(pre[i-1] ,s[i]);
	}
	long long cnt = n - pre[5];
	cnt = max(0ll,cnt);
	long long ans = 5;
	//printf("cnt = %lld,pre = %lld\n",cnt,pre[5] );
	ans += cnt/pre[5];
	if(cnt%pre[5]) ++ans;
	cout<<ans<<'\n';
    return;
}

int main()
{
#ifndef ONLINE_JUDGE
   // freopen("F:/in.txt","r",stdin);
#endif
//    freopen("out.txt","w",stdout);
//    ios::sync_with_stdio(false);
    int t = 1;
    //scanf("%d",&t);
    while(t--){
    //    printf("Case %d: ",cas++);
        solve();
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(false), cin.tie(0)
#define debug(a) cout << #a ": " << a << endl
using namespace std;
typedef long long ll;
map<string, int> mp;
int main(void){
    IOS;
    int n; cin >> n;
    string s; 
    int cnt = 0;
    for (int i = 1; i <= n; ++i){
        cin >> s;
        if (!mp.count(s)){
            cnt++, mp[s] = 1;
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 19244
#include<bits/stdc++.h>
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define rep(i,j,k) for(int i=j;i<=k;i++) 
#define dec(i,j,k) for(int i=j;i>=k;i--)
const int mod = 1e9+7;
const int N = 2e5+1;
using namespace std;
#define debug(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args);}
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << " ";
	err(++it, args...);
}

typedef long long ll;
vector<pair<int,int>> v;
ll n,k,x,y;
ll ans;
ll arr[N];
ll binpow(ll  a , ll n)
{
	ll res = 1;
	while(n)
	{
		if(n&1)
			res*=a;
		a*=a;
		n/=2;
	}
	return res;
}
void solve()
{  cin>>n;
   cout<<1-n;
   cout<<"\n";
   //cerr<<"\n";
}
int main()
{ 
//#ifndef ONLINE_JUDGE
//  freopen("fi.txt","r",stdin);
//  freopen("fo.txt","w",stdout); 
//  freopen("err.txt","w",stderr);
//#endif
  int t;
  t=1;
  //cin>>t;
  while(t--)
  {
	  solve();
  }
  return 0;
}

Measured memory_bytes: 3636
import java.util.Scanner;
 
public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        String str = scan.nextLine();
 
        checker(str);
        scan.close();
    }
  
public static void checker(String title){
  if(title.equals("ARC")){
      System.out.println("ABC");
   // return;
  }else if(title.equals("ABC")){
      System.out.println("ARC");
   // return;
  } else{
    System.err.println("コンテスト名が正しくありません。");
   // return;
  }
}
}

Measured memory_bytes: 35724
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef vector<pii> vp;

int gcd(int a, int b){
    if(b==0) return a;
    return gcd(b,a%b);
}
int lcm(int a, int b){
    return a/gcd(a,b)*b;
}

signed main(void) {
    int n;
    cin >> n;
    int t = 1;
    int cnt = 0;
    while(t*2-1 <= n){
        t *= 2;
        cnt++;
    }
    cout << cnt << endl;
}



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

int main() {
    
    int n, cnt=0; cin >> n;
    long long ans=0;
    vector<int> a(n);
    
    for(int i=0; i < n; ++i){
        cin >> a.at(i);
        if(a.at(i) < 0){
            ++cnt;
        }
    }
    if(cnt % 2==1){
        for(int i=0; i < n; ++i){
           a.at(i)=abs(a.at(i));
        }
        sort(a.begin(),a.end());
        for(int i=0; i < n; ++i){
           ans += abs(a.at(i));
        }
        ans = ans-2*a.at(0);
    }else{
        for(int i=0; i < n; ++i){
            ans += abs(a.at(i));
        }
    }
    
    cout << ans << endl;   
}


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

int main()
{
    int i, L, R;
    cin >> i;

    L = i / 100;
    R = i % 100;

    if(L>=1 && L<=12){
        if(R>=1 && R<=12){
            cout << "AMBIGUOUS" << endl;
        }
        else{
            cout << "MMYY" << endl;
        }
    }
    else{
        if(R>=1 && R<=12){
            cout << "YYMM" << endl;
        }
        else{
            cout << "NA" << endl;
        }
    }
    

}



Measured memory_bytes: 256
K, N = gets.chomp.split(' ').map(&:to_i)
A = gets.chomp.split(' ').map(&:to_i)

diffs = []
A.each_cons(2) do |ai, aj|
  diffs << aj -ai
end
diffs << A[0] + K - A[-1]

diffs.delete_at(diffs.index(diffs.max))
puts diffs.inject(&:+)


Measured memory_bytes: 20412
// Abu Hurayra

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi; 
typedef pair<int, int> pi;
#define pi acos(-1.0)



int main()
{
	#ifndef ONLINE_JUDGE
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
	#endif
	
	ll a ;
	cin >> a ;
	cout << a + a*a + a*a*a << endl;
	
	
	
	return 0;
}



Measured memory_bytes: 3620
/*
 * author :Sadik Hassan
 *
*/
#include "bits/stdc++.h"
using namespace std;
#define ll            long long
#define nl            "\n"
#define pb            push_back
#define fi            first
#define se            second
#define PI            (acos(-1.0))
#define _SAD()        ios::sync_with_stdio(0),cin.tie(0), cout.tie(0);
#define repp(i,a,n)   for(int i=a;i<n;i++)
#define rep(i,n)      for(int i=0;i<n;i++)
#define SZ(s)         s.size()
#define SRT(x,y)      sort(x,x+y)
#define REV(a,b)      reverse(a,a+b)
#define VSRT(x)       sort(x.begin(),x.end())
#define VREV(x)       reverse(x.begin(),x.end())
#define w(t)          int t;cin>>t;while(t--)
#define TSFL(s)       transform(s.begin(),s.end(),s.begin(),::toupper);
#define TSFH(s)       transform(s.begin(),s.end(),s.begin(),::tolower);
typedef vector<int> vi;
typedef vector<ll> vii;
typedef set<int> si;
typedef set<ll> sii;

const int N = 1e5+10;
const ll xy = 1e11+10000000;
const int INF = (int)1e9+5;

int main()
{
    _SAD()
    ll a,b,n;
    cin>>a>>b>>n;
    ll ans=min(b-1,n);
    cout<<ans*a/b<<nl;
    return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vc = vector<char>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define debug(x) cerr << #x << ": " << x << endl;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

// modint: mod 計算を int を扱うように扱える構造体
template<int MOD> struct Fp {
    long long val;
    constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
        if (val < 0) val += MOD;
    }
    constexpr int getmod() { return MOD; }
    constexpr Fp operator - () const noexcept {
        return val ? MOD - val : 0;
    }
    constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; }
    constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; }
    constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; }
    constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; }
    constexpr Fp& operator += (const Fp& r) noexcept {
        val += r.val;
        if (val >= MOD) val -= MOD;
        return *this;
    }
    constexpr Fp& operator -= (const Fp& r) noexcept {
        val -= r.val;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr Fp& operator *= (const Fp& r) noexcept {
        val = val * r.val % MOD;
        return *this;
    }
    constexpr Fp& operator /= (const Fp& r) noexcept {
        long long a = r.val, b = MOD, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b; swap(a, b);
            u -= t * v; swap(u, v);
        }
        val = val * u % MOD;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr bool operator == (const Fp& r) const noexcept {
        return this->val == r.val;
    }
    constexpr bool operator != (const Fp& r) const noexcept {
        return this->val != r.val;
    }
    friend constexpr ostream& operator << (ostream &os, const Fp<MOD>& x) noexcept {
        return os << x.val;
    }
    friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept {
        if (n == 0) return 1;
        auto t = modpow(a, n / 2);
        t = t * t;
        if (n & 1) t = t * a;
        return t;
    }
};

using mint = Fp<MOD>;

int main() {
    ll m, n;
    cin >> m >> n;
    mint ans = modpow((mint)m, n);
    cout << ans << endl;
}



Measured memory_bytes: 3108
#include <stdio.h>
#include <algorithm>
using namespace std;

struct intv{
	long long l, r, d;
	bool operator <(const intv &t) const{
		return d > t.d;
	}
} I[5050];

long long d[2555][2555][2];

void mn(long long &a, long long b)
{
	if (a > b)
		a = b;
}

int main()
{
	int N; scanf ("%d", &N);
	for (int i = 0; i < N; i++){
		scanf ("%lld %lld", &I[i].l, &I[i].r);
		I[i].d = I[i].l + I[i].r;
	}
	sort(I, I + N);

	long long ans = 1e18;
	int s = N / 2;
	for (int l = s, r = N - s - 1; r <= s; l--, r++){
		for (int i = 0; i <= l; i++) for (int j = 0; j <= r; j++) d[i][j][0] = d[i][j][1] = 1e18;
		d[0][0][0] = 0;

		for (int i = 0; i <= l; i++) for (int j = 0; j <= r; j++) for (int k = 0; k <= 1; k++){
			auto &t = I[i + j + k];
			if (i < l) mn(d[i + 1][j][k], d[i][j][k] + t.r + i * t.d);
			if (j < r) mn(d[i][j + 1][k], d[i][j][k] + t.l + j * t.d);
			if (k < 1) mn(d[i][j][k + 1], d[i][j][k] + l * t.l + r * t.r);
		}
		mn(ans, d[l][r][1]);
	}

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

	return 0;
}

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

using namespace std;

const int MAX_N = 200000;

int n, a[MAX_N + 1], invA[MAX_N + 1];
long long ans;

set<int> isLessP, isLessM;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie();
    cout.tie();

    cin >> n;

    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }

    for (int i = 1; i <= n; i++) {
        invA[a[i]] = i;
    }

    isLessP.insert(0), isLessP.insert(n + 1);
    isLessM.insert(0), isLessM.insert(-(n + 1));

    ans = 0;
    for (int i = 1; i <= n; i++) {
        long long j = invA[i];

        long long r = (*isLessP.upper_bound(+j));
        long long l = (*isLessM.upper_bound(-j));

        l *= -1;

        ans += - (i * (j * j - (l + r) * j + l * r));

        isLessP.insert(+j);
        isLessM.insert(-j);
    }

    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 20608
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INFLL LLONG_MAX // 9223372036854775807
#define EPS 1e-9
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
template<class T>bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; }
using namespace std;

int main(){
    Init();
    ll s; cin >> s;
    ll d = 1e9;

    // 1点を(0,0)に固定した場合、s = 1/2 * (x1*y2 - y1*x2)
    // より、s = (x1*y2 - y1*x2)なる(x1,y1), (x2,y2)を探す問題と考えられる
    // ここで更に、x1=1e9, y1=1と固定すると、s = 1e9*y2 - x2となる(x2,y2)を探す問題に帰着する。
    ll x2 = (d-s%d)%d;
    ll y2 = (s+x2)/d;
    cout << "0 0 1000000000 1 " << x2 << " " << y2 << endl;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll;
typedef pair<int, int> pair;
const int inf = 1000000000; //10^9
const ll inff = 1000000000000000000; //10^18

int main(){
    int n;
    cin >> n;
    int ans = 0;
    for(int i = 0; i < 100000; i++) {
        if(i * i <= n) ans = i * i;
        else break;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3616
#include<bits/stdc++.h>
 
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i,n) for(int i = 0; i < n; i++)
#define for1(i,n) for(int i = 1; i <= n; i++)
#define ford(i,n) for(int i = n-1; i >= 0; i--)
#define fore(i,a,b) for(int i = a; i <= b; i++)
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<ll> vll;
 
 
const  int MAXn= 3e5+5;
const  long long INF= 1e18;
const long long mod= 1e9+7;
 
vector<int> adj[MAXn];
bool visited[MAXn];
map<pii, int> m;

int bfs(int v) {
	queue<pii> q;
	q.push({v, -1});
	visited[v] = true;
	int ans = 0;
	while(!q.empty()) {
		pii p = q.front();
		q.pop();
		int temp = 1;
		for(int i = 0; i < (int)adj[p.fi].size(); i++) {
			 if(!visited[adj[p.fi][i]]) {
				 visited[adj[p.fi][i]] = true;
				 if(temp == p.se) temp++;
				 m[{p.fi, adj[p.fi][i] }] = temp;
				 q.push({adj[p.fi][i] , temp});
				 temp++;
			}
		}
		ans = max(ans, temp - 1);
	}
	return ans;
}
				 
 
int main(){
	int n;
	cin >> n;
	vector<pii> v;
	forn(i, n-1) {
		int a, b;
		cin >> a >> b;
		v.pb({a, b});
		m[{a,b}] = 0;
		adj[a].pb(b);
	}
//	cout << m.size();
	int ans =  bfs(1);
	cout << ans << endl;
	for(auto x : v) {
		cout << m[{x.fi,x.se}] << endl;
	}
}	
	


Measured memory_bytes: 16372
#include <stdio.h>
int main(void){
	int N,C,p[100]={},j,i,goukei=0;
	scanf("%d %d",&N,&C);
	for(i=0;i<C;i++){
		scanf("%d",&p[i]);
		goukei+=p[i];
	}
	j=goukei/(N+1);
	if(goukei%(N+1)!=0)printf("%d\n",j+1);
	else printf("%d\n",j);
		
	return 0;
}


Measured memory_bytes: 2092
using System;

namespace ITP1_2_A
{
    class Program
    {
        static void Main(string[] args)
        {
            String[] inputs = Console.ReadLine().Split(' ');
            int a = Convert.ToInt32(inputs[0], 10);
            int b = Convert.ToInt32(inputs[1], 10);

            if (a < b) Console.WriteLine("a < b");
            else if (a > b) Console.WriteLine("a > b");
            else if (a == b) Console.WriteLine("a == b");
        }
    }
}

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

int main() {
	int n,k=0;
	string s;
	cin >> s;
	n = s.size();
	if(n>1)
	{
		for(int i=0;i<n-1;i++)
		{
			if(s.at(i)==s.at(i+1))
			{
				k++;
				if(s.at(i+1)=='1')
				{
					s.at(i+1)='0';
				}
				else
				{
					s.at(i+1)='1';
				}
			}
		}
	}
	cout << k << endl;
	return 0;
}


Measured memory_bytes: 3736
#include <algorithm>
#include <climits>
#include <complex>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

// using
using namespace std;

// typedef
typedef long long ll;

// define
#define FOR(i, a, b, c) for (int i = (int)(a); i < (int)(b); i += (int)(c))
#define REP(i, n) FOR(i, 0, n, 1)
#define RFOR(i, a, b, c) for (int i = (int)(a); i >= (int)(b); i -= (int)(c))
#define RREP(i, n) RFOR(i, n, 0, 1)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REVERSE(c) reverse(ALL(c))
#define UNIQ(c) unique(ALL(c))
#define LB(c, x) lower_bound(c.begin(), c.end(), x)
#define UB(c, x) upper_bound(c.begin(), c.end(), x)
#define LI(c, x) distance(c.begin(), LB(c, x))
#define UI(c, x) distance(c.begin(), UB(c, x))

// functions
template <class T> T ceil(T a, T b) {
    return (a + b - 1) / b;
}
template <class T> T round(T a, T b) {
    return (a + b / 2) / b;
}
template <class T> T gcd(T a, T b) {
    return b ? gcd(b, a % b) : a;
}
template <class T> T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}
template <class T> bool amax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> bool amin(T& a, const T& b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
ll modpow(ll a, ll b, ll m) {
    if (b == 0) {
        return 1;
    } else if (b % 2 == 0) {
        ll h = modpow(a, b / 2, m);
        return h * h % m;
    } else {
        return a * modpow(a, b - 1, m) % m;
    }
}
ll comb(ll a, ll b, ll m) {
    if (b > a - b) {
        return comb(a, a - b, m);
    }
    ll c = 1, d = 1;
    REP(i, b) {
        c *= (a - i);
        d *= (b - i);
        c %= m;
        d %= m;
    }
    return c * modpow(d, m - 2, m) % m;
}

// main
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<int> A(N), B(N);
    REP(i, N) {
        cin >> A[i];
        B[i] = A[i];
    }
    SORT(B);
    REP(i, N) {
        if (A[i] == B[N - 1]) {
            cout << B[N - 2] << endl;
        } else {
            cout << B[N - 1] << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3200
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdlib>
using namespace std;
int main(void){
	long long i,n,x,s;
	vector<int> a;
	cin>>n;
	for(i=0;i<n;i++){
		cin>>x;
		a.push_back(x-i);
	}
	sort(a.begin(),a.end());
	s=0;
	for(i=0;i<n;i++){
		s+=abs(a[i]-a[n/2]);
	}
	cout<<s<<endl;
	return 0;
}

Measured memory_bytes: 1400
s=input()
if s=="SUN":
    print(7)
elif s=="MON":
    print(6)
elif s=="TUE":
    print(5)
elif s=="WED":
    print(4)
elif s=="THU":
    print(3)
elif s=="FRI":
    print(2)
elif s=="SAT":
    print(1)

Measured memory_bytes: 38384
n,y = map(int,input().split())
get_ans = False
for i in range(0,n+1) :
    for j in range(0,n-i+1) :
        k = n-i-j
        if i * 10000 + j*5000 + k*1000 == y and get_ans == False:
            print(i,j,k)
            get_ans = True
if get_ans == False :
    print("-1 -1 -1")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s; cin >> s;
  string t = s;
  reverse(all(t));
  int n = s.size();
  string s1 = s.substr(0, (n-1)/2);
  string s2 = s.substr((n-1)/2+1);
  string t1 = s1, t2 = s2;
  reverse(all(t1)), reverse(all(t2));
  cout << (s==t&&s1==t1&&s2==t2 ? "Yes" : "No") << "\n";
  return 0;
}


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

int x[202020];
int l[202020][20], r[202020][20];
int dpl[1 << 20], dpr[1 << 20];

void solve() {
        int n, v;
        cin >> n >> v;
        for (int i = 0; i < n; i ++) cin >> x[i];
        int p;
        for (int i = 0; ; i ++) if ((1 << i) > v) {
                p = i + 1;
                break;
        }
        for (int i = 0; i < n; i ++) {
                int vv = v;
                for (int j = 0; j < p; j ++) {
                        if (i == 0 || x[i] - x[i - 1] > vv) l[i][j] = i; //その点から移動可能な最も左の点の位置
                        else l[i][j] = l[i - 1][j];
                        vv /= 2;
                }    
        }
        for (int i = n - 1; i >= 0; i --) {
                int vv = v;
                for (int j = 0; j < p; j ++) {
                        if (i == n - 1 || x[i + 1] - x[i] > vv) r[i][j] = i; //その点から移動可能な最も右の点の位置
                        else r[i][j] = r[i + 1][j];
                        vv /= 2;
                }
        }
        for (int i = 0; i < (1 << p); i ++) {
                if (i & 1) continue;
                for (int j = 1; j < p; j ++) {
                        if ((i >> j) & 1) continue;
                        if (dpr[i] == n) dpr[i | (1 << j)] = n;
                        else dpr[i | (1 << j)] = max(dpr[i | (1 << j)], r[dpr[i]][j] + 1); //集合iを使って左から網羅可能な点の数
                }
        }
        for (int i = 0; i < (1 << p); i ++) dpl[i] = n - 1;
        for (int i = 0; i < (1 << p); i ++) {
                if (i & 1) continue;
                for (int j = 1; j < p; j ++) {
                        if ((i >> j) & 1) continue;
                        if (dpl[i] == -1) dpl[i | (1 << j)] = -1;
                        else dpl[i | (1 << j)] = min(dpl[i | (1 << j)], l[dpl[i]][j] - 1); //集合iを使って右から網羅可能な点の数
                }
        }
        bool ok = false;
        for (int i = 0; i < n; i ++) {
                if (l[i][0] == i) { //初期位置から移動可能な位置か？
                        int c = 0;
                        for (int j = 0; j < (1 << p); j ++) {
                                c ++;
                                if (j & 1) continue; 
                                if (i > 0 && dpr[j] < i) continue; //左を網羅できない
                                if (r[i][0] < n - 1 && dpl[((1 << p) - 1 - j) - 1] > r[i][0]) continue; //右を網羅できない
                                break;
                        }
                        if (c < (1 << p)) ok = true;
                        else ok = false;
                }
                if (ok) cout << "Possible" << endl;
                else cout << "Impossible" << endl;
        }
        return;
}

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


Measured memory_bytes: 42752
#include<bits/stdc++.h>
using namespace std;
long double X[200100];
int N;
long long Count(long double len)
{
  long long Ans=0;
  for(int i=0;i<N;i++)
  {
    Ans+=(long long)(X[i]/len);
    //Ans+= ceil(X[i]/len)-1;
  }
  return Ans;
}

int main()
	{
	  long long K;
	  cin>>N>>K;
	  for(int i=0;i<N;i++)
	{
		cin>>X[i];
		//X[i]-=0.1;
	}

  long double l=1,r=1e9;
  //while(l<r-0.1)//解答を引っ張ってきた人の条件。なぜかOKだったが、lとｒの整数部が異なる状態でループを出ると問題になるはず
	for(int i=0;i<35;i++)//OK log2(10^9)=30.二分探索だとこのやり方安定する。ただし、浮動小数のせいか34以上でないと通らず。
  //while(!((ceil(r)-ceil(l)) == 0))//NG:左端が初期値0のままだと、右端のceilは0にならず、無限ループ
	//while(!((floor(r)-floor(l)) == 0))//OK:右端がぴったり整数にならなければ成立.(あまりよくない)
  {
    long double mid=(l+r)/2;
    if(Count(mid)<=K) r=mid;
    else	l=mid;
  }
  cout<<(long long)(l+0.999)<<endl;
  return 0;
}

Measured memory_bytes: 6664