akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;

int pow_mod(int a, int n, int mod) {
  int res = 1;
  while (n > 0) {
    if (n & 1) res *= a;
    a = a*a;
    a %= mod;
    n >>= 1;
    res %= mod;
  }
  return res;
}

int main() {
  string S;
  cin >> S;
  int N = S.size();
  vector<int> mod(N+1);
  mod[N] = 0;
  for (int s = N-1; s >= 0; s--) {
    int a = S[s] - '0';
    mod[s] = a * pow_mod(10, (N-1)-s, 2019) + mod[s+1];
    mod[s] %= 2019;
  }
  map<int, int> cnt;
  for (auto m : mod) {
    cnt[m]++;
  }
  int ans = 0;
  for (auto c : cnt) {
    ans += c.second * (c.second - 1) / 2;
  }
  cout << ans << endl;
}


Measured memory_bytes: 4364
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
using namespace std;

using ll = long long;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline void dump(vector<T> v) { for (auto& x : v) cerr << x << " "; cerr << endl; }
template<class T> inline void dump(vector<pair<T, T>> v) { for (auto& p : v) cerr << p.first << " " << p.second << endl; }
template<class T> inline void dump(vector<vector<T>> vv) { for (auto& v : vv) {for (auto& x : v) cerr << x << " "; cerr << endl;} }

constexpr int INF = 1e9+5;
constexpr long long INFLL = 1LL<<60;
constexpr double eps = (1e-9);

constexpr ll mod = 1000000007;

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

  int n;
  cin >> n;
  map<int, int> mp;
  rep(i, n) {
    int a;
    cin >> a;
    mp[a]++;
  }

  ll ans = 0;
  for (auto& p : mp) {
    if (p.first <= p.second) {
      ans += p.second - p.first;
    } else {
      ans += p.second;
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 4736
using System;
using System.Linq;
using System.Collections.Generic;
class Program
{
    static void Main(string[] args)
    {
        int R = int.Parse(Console.ReadLine());
        if(R >= 2800)
        {
            Console.WriteLine("AGC");
        }
        else if(R >= 1200)
        {
            Console.WriteLine("ARC");
        }
        else
        {
            Console.WriteLine("ABC");
        }
    }
}


Measured memory_bytes: 11092
#include<iostream>
#include<vector>
#include<queue>
#define rep(i,n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;

ll mod = 1000000007;

long long modpow(long long x, long long n) {
  if (n == 0) return 1;
  if (n % 2 == 0) {
    long long res = modpow(x,n/2);
    res *= res;
    res %= mod;
    return res;
  } else {
    return x * modpow(x,n-1) % mod;
  }
}


ll com(ll n, ll r) {
  ll ans = 1;
  for(int i = 0;i < r; i++){
    ans *= n - i;
    ans %= mod;
  }
  for(int i= 0;i<r;i++){
    ans *= modpow(i+1,mod-2);
    ans %= mod;
  }

  return ans;
}


int main() {
  ll n,m;
  ll ans = 0;
  cin >> n >> m;

  if (n > 1) {
    ans += com(n,2);
  }
  if (m > 1) {
    ans += com(m,2);
  }

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


Measured memory_bytes: 888
// Bismillah .Ya Allah...
#include<bits/stdc++.h>
using namespace std;
typedef long long int  ll;
typedef pair<int,int> PII;
const int mod = 1e9+7,INF = 1e9;
const ll mx = 1e18;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll n,ans=0;
    cin>>n;
    for(int i=2;i<=sqrt(n);i++)
    {
        int coun=0,pre=0;
        if(n%i==0)
        {
            while(n%i==0)
            {
                n= n/i;
                coun++;
            if(coun>pre)
            {
                pre = coun;
                ans++;
                coun=0;
            }
            }
        }
    }
    if(n>1)
        ans++;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3692
#include<bits/stdc++.h>
using namespace std;
#define MN 105
#define inf 0x7f7f7f7f
int fr[MN],nex[MN*MN],vi[MN*MN],wi[MN*MN],tot=0,pi[MN*MN];
void Add(int x,int y,int z){
	vi[++tot]=y;wi[tot]=z;nex[tot]=fr[x];fr[x]=tot;
	vi[++tot]=x;wi[tot]=0;nex[tot]=fr[y];fr[y]=tot;
}
int v[MN],n;
int cur[MN],dep[MN],s,t,xr[MN];
void init(){
	++xr[dep[t]=1];
	queue<int> Q;Q.push(t);
	while(!Q.empty()){
		int x=Q.front();Q.pop();
		for(int i=fr[x];i;i=nex[i])if(!dep[vi[i]]){
			++xr[dep[vi[i]]=dep[x]+1];
			Q.push(vi[i]);
		}
	}
	for(int i=0;i<=n+1;++i)cur[i]=fr[i];
}
long long dfs(int x,int f){
	if(x==t||f==0)return f;
	int flow=0,fl;
	for(int &i=cur[x];i;i=nex[i]){
		if(dep[x]==dep[vi[i]]+1&&(fl=dfs(vi[i],min(f,wi[i])))>0){
			f-=fl;flow+=fl;wi[i]-=fl;wi[(i&1)?(i+1):(i-1)]+=fl;if(!f)return flow;
		}
	}
	if(!(--xr[dep[x]]))dep[s]=n+3;
	else ++xr[++dep[x]],cur[x]=fr[x];
	return flow;
}
int main(){
	long long sum=0;scanf("%d",&n);
	for(int i=1;i<=n;++i)scanf("%d",v+i);
	for(int i=1;i<=n;++i){
		if(v[i]>=0)Add(i,n+1,v[i]),sum+=v[i];
		else Add(0,i,-v[i]);
		for(int j=2;j*i<=n;++j){
			Add(i,j*i,inf);
		}
	}
	s=0;t=n+1;init();
	while(dep[s]<=n+2)sum-=dfs(s,inf);
	cout<<sum;
	return 0;
}

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

int main(){
  int n,k,sum=0;
  cin>>n>>k;
  int arr[100];
  for(int i=0;i<n;i++)
  {
    cin>>arr[i];
  }
  for(int i=0;i<n;i++)
  {
    int d=arr[i];
    int c=abs(arr[i]-k);
     sum+=2*min(d,c);
  }
  cout<<sum<<endl;
}
  

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
#include<set>
#include<algorithm>
#include<utility>
#include<map>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
const int INF = 1001001001;

ll pow_mod(ll p, ll n, ll m) {
	if (n == 0) return 1;
	else if (n == 1) return p % m;
	else if (n % 2 == 1) return p * pow_mod(p, n - 1, m) % m;
	else {
		ll tmp = pow_mod(p, n / 2, m);
		return (tmp * tmp) % m;
	}
}

ll gcd(ll x, ll y) {
	if (y == 0) {
		return x;
	}
	return gcd(y, x % y);
}

ll com_mod(ll n, ll k, ll m) {
	if (k == 0) return 1;
	else {
		ll x = 1;
		ll y = 1;
		for (ll i = 0; i < k; i++) {
			x = (x * (n - i)) % m;
			y = (y * (i + 1)) % m;
		}
		ll res = (x * pow_mod(y, m - 2, m)) % m;
		return res;
	}
}

int main() {
	string s; cin >> s; if (s[2] == s[3] && s[4] == s[5]) cout << "Yes" << endl; else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 3592
#include<bits/stdc++.h>
#define rep(i,j,n) for(int i=(j);i<(n);i++)
#define per(i,n,j) for(int i=(n);i>=(j);i--)
using ll=long long;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll a,ll b){return(a%b)?gcd(b,a%b):b;}
ll lcm(ll a,ll b){return(a*b/gcd(a,b));}
const ll INF=1LL<<60;

int n;
vector<int> h(110);

int main(){
    cin>>n;
    rep(i,0,n) cin>>h[i];
    int cnt=0;
    int x=0;
    int ans=0;
    while(cnt!=n){
        cnt=0;
        rep(i,0,n){
            if(h[i]!=0){
                h[i]--;
                x++;
                if(i==n-1){
                    ans++;
                    x=0;
                }
            }
            else if(h[i]==0){
                if(x!=0) ans++;
                x=0;
                cnt++;
            }
        }
    }
    cout<<ans<<"\n";
    return 0;
}


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

const int N = 2e5 + 10;
typedef long long ll;
ll n, m, Q, fa[N], A[N], B[N], tot, num;

int getfa(int x) { return fa[x] == x ? x : fa[x] = getfa(fa[x]); }

int main() {
    cin >> n >> m >> Q;
    rep(i, 0, n - 1) fa[i] = i;
    num = n;  // 连通块个数
    rep(i, 1, Q) {
        int a, b, c; scanf("%d%d%d", &a, &b, &c);
        int x = getfa(a), y = getfa(b);
        if (!c && x != y) fa[y] = x, num--;
        if (c) A[++tot] = a, B[tot] = b;
    }
    rep(i, 1, tot) if (getfa(A[i]) == getfa(B[i])) { puts("No"); return 0; }
    if ((1ll * num * (num - 1) / 2 < m + num - n) || ((num == 2 || m < n) && tot)) puts("No");
    else puts("Yes");
    return 0;
}


Measured memory_bytes: 3712
N=int(input())
ans=N
for i in range(N+1):
    cnt=0
    t=i
    while t>0:
        cnt+=t%6
        t//=6
    j=N-i
    while j>0:
        cnt+=j%9
        j//=9
    ans = min(ans,cnt)
print(ans)

Measured memory_bytes: 9192
/**
 *   @FileName	a.cpp
 *   @Author	kanpurin
 *   @Created	2020.08.20 03:18:30
**/

#include "bits/stdc++.h" 
using namespace std; 
typedef long long ll;


class UnionFind {
private:
    vector<int> par;
public:
    UnionFind(int n) {
        par.resize(n, -1);
    }
    int root(int x) {
        if (par[x] < 0) return x;
        return par[x] = root(par[x]);
    }
    bool unite(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return false;
        if (size(rx) < size(ry)) swap(rx, ry);
        par[rx] += par[ry];
        par[ry] = rx;
        return true;
    }
    bool same(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
    int size(int x) {
        return -par[root(x)];
    }
};
int main() {
    int n;cin >> n;
    vector<pair<int,int>> p(n),q(n);
    for (int i = 0; i < n; i++) {
        int a,b;cin >> a >> b;
        p[i].first = a;
        p[i].second = q[i].second = i;
        q[i].first = b;
    }
    sort(p.begin(), p.end());
    sort(q.begin(), q.end());
    UnionFind uf(n);
    typedef tuple<int,int,int> T;
    priority_queue<T,vector<T>,greater<T>> pq;
    for (int i = 0; i < n-1; i++) {
        pq.push(make_tuple(p[i+1].first - p[i].first,p[i+1].second,p[i].second));
        pq.push(make_tuple(q[i+1].first - q[i].first,q[i+1].second,q[i].second));
    }
    ll ans = 0;
    while(!pq.empty()) {
        auto t = pq.top();
        pq.pop();
        int x = get<1>(t);
        int y = get<2>(t);
        if (!uf.same(x,y)) {
            ans += get<0>(t);
            uf.unite(x,y);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 8388
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    int n = scanner.nextInt();
    List<Integer> x = new ArrayList<>();
    for (int i = 0; i < n; i++) {
      x.add(scanner.nextInt());
    }

    int min = Integer.MAX_VALUE;
    for (int i = 0; i < 100; i++) {
      int sum = 0;
      for (int j = 0; j < x.size(); j++) {
        sum += Math.pow(x.get(j)-i, 2);
      }
      min = Math.min(min, sum);
    }
    System.out.println(min);
  }

}


Measured memory_bytes: 21972
#include <iostream>

using namespace std;

int main(int argc, char const *argv[])
{
    string S;
    cin >> S;
    long long answer = 0;
    int countW = 0;
    for(auto it = S.rbegin() ; it != S.rend() ; ++it){
        if(*it == 'W'){
            ++countW;
        } else{
            answer += countW;
        }
    }
    cout << answer << '\n';
    return 0;
}


Measured memory_bytes: 3744
#include<bits/stdc++.h>
using namespace std;
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<long long> vlong;
#define _GLIBCXX_DEBUG
#define vpush(a,x) a.push_back(x);
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)
const int INF = 1 << 30;
const int dx[] = {1,0,-1,0,1,1,-1,-1};
const int dy[] = {0,-1,0,1,1,-1,-1,1};
#define stp(x)  setprecision(x)
int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n;
  cin>>n;
  vint t(n);
  int sum=0;
  rep(i,n){
    cin>>t[i];
    sum+=t[i];
  }
  int m;
  cin>>m;
  int p,x;
  rep(i,m){
    int tmp=sum;
    cin>>p>>x;
    tmp-=t[p-1];
    tmp+=x;
    cout<<tmp<<'\n';
  }
  return(0);
}


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

int main(){
    int n;  cin >> n;
    int ans = 0;
    rep(i, n){
	int l,r;
	cin >> l >> r;
	ans += r-l+1;
    }
    cout << ans << endl;
}



Measured memory_bytes: 256
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def TUPLE(): return tuple(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7 
#mod = 998244353
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10

A, B, Q = MAP()
s = [-INF] + [INT() for _ in range(A)] + [INF]
t = [-INF] + [INT() for _ in range(B)] + [INF]

for _ in range(Q):
	x = INT()
	idx_s = bisect(s, x)
	idx_t = bisect(t, x)

	ans = INF
	for S, T in product([idx_s, idx_s-1], [idx_t, idx_t-1]):
		if min(s[S], t[T]) <= x <= max(s[S], t[T]):
			tmp = abs(s[S]-t[T]) + min(abs(x-s[S]), abs(x-t[T]))
		else:
			tmp = max(abs(x-s[S]), abs(x-t[T]))
		ans = min(ans, tmp)

	print(ans)



Measured memory_bytes: 19100
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define watch(x) cout<<(#x)<<"="<<(x)<<'\n'
#define mset(d,val) memset(d,val,sizeof(d))
#define setp(x) cout<<fixed<<setprecision(x)
#define forn(i,a,b) for(ll i=(a);i<(b);i++)
#define fore(i,a,b) for(ll i=(a);i<=(b);i++)
#define pb push_back
#define F first
#define S second
#define pqueue priority_queue
#define fbo find_by_order
#define ook order_of_key
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef long double ld;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;
void amin(ll &a, ll b){ a=min(a,b); }
void amax(ll &a, ll b){ a=max(a,b); }
void SD(int t=0){ cout<<"PASSED "<<t<<endl; }
const ll INF = ll(1e18);
const int MOD = 1e9+7;

vector<ll> fact,ifact,inv,pow2;
ll add(ll a,ll b)
{
	a%=MOD; b%=MOD;
	a+=b;a%=MOD;
	if(a<0) a+=MOD;
	return a;
}
ll mult(ll a, ll b)
{
	a%=MOD; b%=MOD;
	ll ans=(a*b)%MOD;
	if(ans<0) ans+=MOD;
	return ans;
}
ll pw(ll a, ll b)
{
	ll r=1;
	while(b){
		if(b&1) r=mult(r,a);
		a=mult(a,a);
		b>>=1;
	}
	return r;
}
ll inverse(ll a)
{
	return pw(a,MOD-2);
}
ll choose(ll a, ll b)
{
	if(a<b) return 0;
	if(b==0) return 1;
	if(a==b) return 1;
	return mult(fact[a],mult(ifact[b],ifact[a-b]));
}
void init(ll _n)
{
	fact.clear(); ifact.clear(); inv.clear(); pow2.clear();
	fact.resize(_n+1); ifact.resize(_n+1); inv.resize(_n+1); pow2.resize(_n+1);
	pow2[0]=1; ifact[0]=1; fact[0]=1;
	for(int i=1;i<=_n;i++){
		pow2[i]=add(pow2[i-1],pow2[i-1]);
		fact[i]=mult(fact[i-1],i);
	}
	ifact[_n] = inverse(fact[_n]);
	for(int i=_n-1;i>=1;i--){
	    ifact[i] = mult(ifact[i+1], i+1);
	}
	for(int i=1;i<=_n;i++){
	    inv[i] = mult(fact[i-1], ifact[i]);
	}
}

bool DEBUG=0;
const int MAXN = 1000005;

ll K,n;
string s;

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	init(2e6+2);
	cin>>K>>s;
	n=s.length();
	
	ll ans=0;
	fore(i,n,n+K){
		ans=add(ans, mult(mult(choose(i-1,n-1),pw(25,i-n)), pw(26,n+K-i)));
		/*cout<<"choo="<<choose(i,n)<<'\n';
		cout<<"pw="<<pw(25,i-n)<<'\n';
		cout<<"pw2="<<pw(26,n+K-i)<<'\n';
		watch(ans);
		cout<<'\n';*/
	}
	cout<<ans<<'\n';
	
	return 0;
}


Measured memory_bytes: 66748
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
#define MOD @
#define ADD(X,Y) ((X) = ((X) + (Y)%MOD) % MOD)
typedef long long i64; typedef vector<int> ivec; typedef vector<string> svec;

int N, K;
int A[101010], B[101010], C[101010];

void verify()
{
	for (int i = 0; i < N; ++i) {
		if (A[i] + B[i] > C[i]) {
			throw 1234;
		}
	}
}

i64 rsum(i64 l, i64 r)
{
	return r * (r + 1) / 2 - (l - 1) * l / 2;
}

int main()
{
	scanf("%d%d", &N, &K);

	//printf("%lld %lld\n", rsum(K, K + 2 * N - 1), rsum(K + 2 * N, K + 3 * N - 1));

	if (rsum(K, K + 2 * N - 1) > rsum(K + 2 * N, K + 3 * N - 1)) {
		puts("-1");
		return 0l;
	}

	int alo = K, ahi = K + 2 * N - 1;
	int blo = K + 2 * N, bhi = K + 3 * N - 1;

	if (N % 2 == 1) {
		for (int i = 0; i <= N / 2; ++i) {
			A[i] = alo + i;
			B[i] = ahi - N / 2 + i;
			C[i] = blo + i * 2;
		}
		for (int i = 0; i < N / 2; ++i) {
			A[i + N / 2 + 1] = alo + N / 2 + 1 + i;
			B[i + N / 2 + 1] = alo + N + i;
			C[i + N / 2 + 1] = blo + 1 + i * 2;
		}
	} else {
		for (int i = 0; i < N / 2; ++i) {
			A[i] = alo + i;
			B[i] = ahi - N / 2 + i + 1;
			C[i] = blo + i * 2;
		}
		for (int i = 0; i < N / 2; ++i) {
			A[i + N / 2] = alo + N / 2 + i;
			B[i + N / 2] = alo + N + i;
			C[i + N / 2] = blo + 1 + i * 2;
		}
	}

	verify();
	for (int i = 0; i < N; ++i) printf("%d %d %d\n", A[i], B[i], C[i]);
	return 0;
}


Measured memory_bytes: 3832
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>

using namespace std;

typedef long long ll;

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

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

#define MAX_N 100000

class Edge {
    public:
        int from;
        int to;
        int index;
};

// bool visited[MAX_N];

map<pair<int, int>, int> colors;

void color(const int cur_nd, int cur_color, const int color_variation, vector<vector<Edge> > &edges) {
    // if (visited[cur_nd]) {
    //     return;
    // }
    // visited[cur_nd] = true;
    for (int i = 0; i < (int) edges[cur_nd].size(); i++) {
        int other = edges[cur_nd][i].to;
        if (colors.find(make_pair(other, cur_nd)) != colors.end()) {
            colors[make_pair(cur_nd, other)] = colors[make_pair(other, cur_nd)];
        } else {
            colors[make_pair(cur_nd, other)] = ((cur_color++) % color_variation) + 1;
            color(edges[cur_nd][i].to, cur_color, color_variation, edges);
        }
    }
}

int main(void) {
    int N;
    cin >> N;

    vector<vector<Edge> > edges(N);
    for (int i = 0; i < N - 1; i++) {
        int a, b;
        cin >> a >> b;
        edges[a - 1].push_back({a - 1, b - 1, i});
        edges[b - 1].push_back({b - 1, a - 1, MAX_N + 1});
    }

    int max_edge = -1;
    int nd_max_edge = -1;
    for (int i = 0; i < N; i++) {
        if ((int) edges[i].size() > max_edge) {
            max_edge = (int) edges[i].size();
            nd_max_edge = i;
        }
    }

    vector<bool> visited(N, false);
    color(nd_max_edge, 1, max_edge, edges);

    cout << max_edge << endl;

    vector<Edge> res;
    for (int i = 0; i < (int) edges.size(); i++) {
        for (int j = 0; j < (int) edges[i].size(); j++) {
            res.push_back(edges[i][j]);
        }
    }

    sort(res.begin(), res.end(), [](const Edge &a, const Edge &b) {
            return a.index < b.index;
    });

    for (int i = 0; i < N - 1; i++) {
        cout << colors[make_pair(res[i].from, res[i].to)] << endl;
    }

    return 0;
}


Measured memory_bytes: 23156
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n: usize = read();
    let mut btc_sum: f64 = 0.0;
    let mut jpy_sum: f64 = 0.0;

    for _ in 0..n {
        let x: f64 = read();
        let u: String = read();
        if u == "BTC" {
            btc_sum += x;
        } else {
            jpy_sum += x;
        }
    }
    println!("{}", btc_sum * 380000.0 + jpy_sum)
}


Measured memory_bytes: 2096
#include <bits/stdc++.h>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

using P = pair<ll, ll>;
P getRev(const P& p) {
    return make_pair(p.se, p.fi);
}
ll calc(const vector<P>& v) {
    map<P, int> mp;
    priority_queue<P> x;
    priority_queue<P,vector<P>,greater<P> > y;
    rep(i, v.size()) {
        mp[v[i]]++;
        x.push(v[i]);
        y.push(getRev(v[i]));
    }
    ll ret = 0LL;
    ll cur = 0LL;
    while(x.size() > 0) {
        auto p = x.top(); x.pop();
        while(x.size() > 0 && mp[p] == 0) {
            p = x.top(); x.pop();
        } 
        if(mp[p] == 0) {

            // cout << endl;
            return ret + abs(cur);
        }
        mp[p]--;
        if(p.fi <= cur && cur <= p.se);
        else {
            ret += abs(cur - p.fi);
            cur = p.fi;
        }

        // cout << " " << cur;
        if(y.size() == 0) {

            // cout << endl;
            return ret + abs(cur);
        }
        auto q = getRev(y.top()); y.pop();
        while(y.size() > 0 && mp[q] == 0) {
            q = getRev(y.top()); y.pop();
        }
        if(mp[q] == 0) {

            // cout << endl;
            return ret + abs(cur);
        }
        mp[q]--;
        if(q.fi <= cur && cur <= q.se);
        else {
            ret += abs(cur - q.se);
            cur = q.se;
        }

        // cout << " " << cur;
    }
    // cout << endl;
    return ret + abs(cur);
}

int main(){
    int n;
    cin >> n;
    vl l(n), r(n);
    rep(i, n) cin >> l[i] >> r[i];
    vector<P> x(n), y(n);
    rep(i, n) {
        x[i] = make_pair(l[i], r[i]);
        y[i] = make_pair(-r[i], -l[i]);
    }
    cout << max(calc(x), calc(y)) << endl;
    // cout << calc(x) << " " << calc(y) << endl;
    return 0;
}

Measured memory_bytes: 17832
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <functional>
#include <ctime>
#include <cmath>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iomanip>
#include <float.h>
#include <math.h>
using namespace std;
using ll = long long;
unsigned euclidean_gcd(unsigned a, unsigned b) {
    if (a < b) return euclidean_gcd(b, a);
    unsigned r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

ll ll_gcd(ll a, ll b) {
    if (a < b) return ll_gcd(b, a);
    ll r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

class UnionFind {
public:
    vector <ll> par;
    vector <ll> siz;
    UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    ll root(ll x) {
        while (par[x] != x) {
            x = par[x] = par[par[x]];
        }
        return x;
    }
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) {
        return root(x) == root(y);
    }

    ll size(ll x) {
        return siz[root(x)];
    }
};

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}

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

Measured memory_bytes: 4796
#include <bits/stdc++.h>
#define ll long long int
#define REP(i,n) for(ll i=0;i<n;i++)
#define SZ(v) (ll)v.size()
#define endl "\n"
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define pbds tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
const ll INF=1e29;
const ll MOD=1000000007;
const ll nxm=2e7+5;
void solve()
{
string s;
cin>>s;
ll n=SZ(s);
for(ll i=n-1;i>=0;i--)
{
if(s[i]=='?')
    s[i]='D';
}
cout<<s;
}
int main(){
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	ll t=1;
//	cin>>t;
	while(t--){
		solve();
	}


	return 0;
}
/*
    if(i==n-1)
    {
        if(s[i]=='?')
            s[i]='D';
    }
    else
    {
        if(s[i]=='?')
        {
        if(s[i+1]=='D')
            s[i]='P';
        else
            s[i]='D';
        }

    }
    */


Measured memory_bytes: 3744
fn main() {
    let (n, k) = read_tuple::<usize>();
    let scores = read_vec::<i64>();
    let t: Vec<char> = read::<String>().chars().collect();

    let mut is_free = vec![true; n];
    let mut total_score = 0;
    for (i, x) in t.iter().enumerate() {
        if i < k || is_free[i - k] || *x != t[i - k] {
            total_score += match *x {
                'r' => scores[2],
                'p' => scores[1],
                's' => scores[0],
                _ => unreachable!(),
            };
            is_free[i] = false;
        } 
    }
    println!("{:?}", total_score);
}


fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}

fn read_tuple<T: std::str::FromStr + Copy>() -> (T, T) {
    let temp = read_vec();
    (temp[0], temp[1])
}


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

int main(int argc, char *argv[])
{
    struct meal {
        int v;
        int t;
        bool operator<(const meal& m) const {
            return t < m.t;
        }
    };
    int N, T;
    cin >> N >> T;
    vector<meal> M(N);
    for (int i = 0; i < N; i++) {
        cin >> M[i].t >> M[i].v;
    }
    sort(begin(M), end(M));
    vector<vector<int>> memo(N, vector<int>(T + 1, -1));
    function<int(int, int)> solve = [&](int index, int time) {
        if (index == N) return 0;
        if (time >= T) return 0;
        int& res = memo[index][time];
        if (res != -1) return res;
        res = solve(index + 1, time);
        res = max(res, solve(index + 1, time + M[index].t) + M[index].v);
        return res;
    };
    cout << solve(0, 0) << endl;
    return 0;
}


Measured memory_bytes: 35712
// by ul {{{
#include <bits/stdc++.h>
#include <unistd.h>
#define SZ(x) ((int)(x).size())
#define ALL(c) begin(c),end(c)
#define REP(i,n) for ( int i=0; i<(int)(n); i++ )
#define REP1(i,a,b) for ( int i=(int)(a); i<=(int)(b); i++ )
#define FOR(it,c) for ( auto it=(c).begin(); it!=(c).end(); it++ )
#define MP make_pair
#define PB push_back
using namespace std;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef long long LL;

void RI() {}

template<typename... T>
void RI( int& head, T&... tail ) {
    scanf("%d",&head);
    RI(tail...);
}

template<typename T>
void _dump( const char* s, T&& head ) { cerr<<s<<"="<<head<<endl; }

template<typename T, typename... Args>
void _dump( const char* s, T&& head, Args&&... tail ) {
    int c=0;
    while ( *s!=',' || c!=0 ) {
        if ( *s=='(' || *s=='[' || *s=='{' ) c++;
        if ( *s==')' || *s==']' || *s=='}' ) c--;
        cerr<<*s++;
    }
    cerr<<"="<<head<<", ";
    _dump(s+1,tail...);
}

#define dump(...) _dump(#__VA_ARGS__, __VA_ARGS__);

template<typename Iter>
ostream& _out( ostream &s, Iter b, Iter e ) {
    s<<"[";
    for ( auto it=b; it!=e; it++ ) s<<(it==b?"":" ")<<*it;
    s<<"]";
    return s;
}

template<typename A, typename B>
ostream& operator <<( ostream &s, const pair<A,B> &p ) { return s<<"("<<p.first<<","<<p.second<<")"; }
template<typename T>
ostream& operator <<( ostream &s, const vector<T> &c ) { return _out(s,ALL(c)); }
template<typename T>
ostream& operator <<( ostream &s, const set<T> &c ) { return _out(s,ALL(c)); }
template<typename A, typename B>
ostream& operator <<( ostream &s, const map<A,B> &c ) { return _out(s,ALL(c)); }
// }}}

int n;
string s;
void input() {
    RI(n);
    cin >> s;
}

void solve() {
    
}

int main( int argc, char *argv[] ) {
    input();
    string ans;
    for(auto i:s) {
        ans += (char)(((i-'A') + n) % 26 + 'A');
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env pypy
from __future__ import division, print_function

import os
import sys
from __builtin__ import xrange as range
from collections import Counter
from cStringIO import StringIO
from future_builtins import ascii, filter, hex, map, oct, zip
from io import IOBase

import __pypy__


def main():
    W, H, x, y = map(int, input().split())
    _x, _y = W - x, H - y
    print(W * H / 2, int((_x, _y) == (x, y)))


# region fastio

BUFSIZE = 8192


class FastI(IOBase):
    def __init__(self, file):
        self._fd = file.fileno()
        self._buffer = StringIO()
        self.newlines = 0

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count("\n") + (not b)
            ptr = self._buffer.tell()
            self._buffer.seek(0, 2), self._buffer.write(b), self._buffer.seek(ptr)
        self.newlines -= 1
        return self._buffer.readline()


class FastO(IOBase):
    def __init__(self, file):
        self._fd = file.fileno()
        self._buffer = __pypy__.builders.StringBuilder()
        self.write = lambda s: self._buffer.append(s)

    def flush(self):
        os.write(self._fd, self._buffer.build())
        self._buffer = __pypy__.builders.StringBuilder()


def print(*args, **kwargs):
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()


sys.stdin, sys.stdout = FastI(sys.stdin), FastO(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

# endregion

if __name__ == "__main__":
    main()


Measured memory_bytes: 29164
package main

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

func main() {
	n := splitStrStdin("")
	if n[0] == "9" || n[1] == "9" {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

/* template */
var sc = bufio.NewScanner(os.Stdin)

// 文字列を1行取得
func strStdin() (stringInput string) {
	sc.Scan()
	stringInput = sc.Text()
	stringInput = strings.TrimSpace(stringInput)
	return
}

// 整数値1つ取得
func intStdin() (num int) {
	stringInput := strStdin()
	num, _ = strconv.Atoi(strings.TrimSpace(stringInput))
	return
}

// 空白や空文字だけの値を除去したSplit()
func splitWithoutEmpty(stringTargeted string, delim string) (stringReturned []string) {
	stringSplited := strings.Split(stringTargeted, delim)

	for _, str := range stringSplited {
		if str != "" {
			stringReturned = append(stringReturned, str)
		}
	}
	return
}

// デリミタで分割して文字列スライスを取得
func splitStrStdin(delim string) (stringReturned []string) {
	// 文字列で1行取得
	stringInput := strStdin()

	// 空白で分割
	stringReturned = splitWithoutEmpty(stringInput, delim)

	return
}

// デリミタで分割して整数値スライスを取得
func splitIntStdin(delimiter string) (intAry []int) {
	// 文字列スライスを取得
	strAry := splitStrStdin(delimiter)

	// 整数スライスに保存
	for i := range strAry {
		num, err := strconv.Atoi(strAry[i])
		if err != nil {
			panic(err)
		}
		intAry = append(intAry, num)
	}
	return
}
/* template */

Measured memory_bytes: 640
n = int(input())
anstmp = ["a"]
cnt = 0
for i in anstmp:
  t = max(ord(k) for k in i)-95
  if cnt > 100000:
    break
  for j in range(1,t+1):
    anstmp.append(i+chr(j+96))
  cnt += 1
ans = set()
for i in anstmp:
  if len(i) == n:
    ans.add(i)
ans = list(ans)
ans.sort()
print(*ans,sep="\n")

Measured memory_bytes: 48652
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
template<class T> using V=vector<T>; 
// #define fi first
// #define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
const ll mod=998244353;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
struct Data{
    int fi,se,v;
    ll val;
    Data(int fi,int se,int v,ll val):fi(fi),se(se),v(v),val(val) {} 
    bool operator<(const Data &d)const{return d.val<val;}
};
V<int> dy={-1,0,1,0},dx={0,-1,0,1};
int main(){
    ll h,w,k;
    cin>>h>>w>>k;
    int x1,y1,x2,y2;
    cin>>x1>>y1>>x2>>y2;
    x1--;y1--;x2--;y2--;
    V<string> s(h);
    for(int i=0;i<h;i++)cin>>s[i];
    priority_queue<Data> q;
    V<V<V<ll>>> d(h,V<V<ll>>(w,V<ll>(4,1e13)));
    d[x1][y1][0]=0;
    q.emplace(x1,y1,0,0);
    while(q.size()){
        int x=q.top().fi,y=q.top().se,bfo=q.top().v,val=q.top().val;
        q.pop();
        for(int i=0;i<4;i++){
            int nx=x+dx[i],ny=y+dy[i];
            if(nx<0||nx>=h||ny<0||ny>=w)continue;
            if(s[nx][ny]=='@')continue;
            if(i==bfo&&val>0){
                if(d[nx][ny][bfo]>d[x][y][bfo]+1){
                    d[nx][ny][i]=d[x][y][bfo]+1;
                    q.emplace(nx,ny,i,d[nx][ny][i]);
                }
            }
            else if(d[nx][ny][i]>(d[x][y][bfo]+k-1)/k*k+1){
                    d[nx][ny][i]=(d[x][y][bfo]+k-1)/k*k+1;
                    q.emplace(nx,ny,i,d[nx][ny][i]);
                }
        }
    }
    ll ans=1e13;
    for(int i=0;i<4;i++)chmin(ans,d[x2][y2][i]);
    cout<<(ans>=ll(1e13)?-1:(ans+k-1)/k)<<"\n";
}


Measured memory_bytes: 144896
#include <algorithm>
#include <cstdint>
#include <iostream>
#include <vector>
#include <string>
#include <set>

using namespace std;

int main() {
  int64_t N, K;
  cin >> N >> K;
  vector<int64_t> tel(N+1);
  for (int64_t n = 1; n <= N; ++n) {
    cin >> tel[n];
  }
  set<int64_t> checker;
  vector<int64_t> route;
  int64_t next = 1;
  int64_t i = 0;
  for (; i <= K; ++i) {
    if (checker.count(next)) {
      break;
    }
    checker.insert(next);
    route.push_back(next);
    next = tel[next];
  }
  if (i != K + 1) {
    auto start = find(route.begin(), route.end(), next);
    size_t size = route.end() - start;
    K -= (start - route.begin());
    cout << *(start + (K % size)) << endl;
  } else {
    cout << route.back() << endl;
  }
  return 0;
}


Measured memory_bytes: 13544
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include <cmath>
#include <limits>
#include <utility>
#include <map>


#define rep(p,q) for(int i = p;i < q;i++)
#define ll long long

using namespace std;

const int cons = 1e9 + 7;


ll d[300][300];
ll a[300][300];

//D
int main(void) {
	int n = 0;
	cin >> n;

	
	rep(0, n) {
		for (int j = 0; j < n; j++) {
			int cost;
			cin >> cost;
			d[i][j] = cost;
			a[i][j] = cost;
			
		}
	}
	rep(0, n) {
		for (int j = 0; j < n; j++) {
			for (int k = 0; k < n; k++) {
				d[j][k] = min(d[j][k], d[j][i] + d[i][k]);
			}
		}
	}
	ll ans = 0;
	bool isFinished = false;
	rep(0, n) {
		for (int j = i+1; j < n; j++) {
			if (a[i][j] > d[i][j]) {
				ans = -1;
				isFinished = true;
				break;
			}
			else {
				for (int k = 0; k < n; k++) {
					if (i == k || k == j) {
						if(k == n-1) ans += a[i][j];
						else continue;
					}
					if (d[i][j] == d[i][k] + d[k][j]) {
						//ans += d[i][j];
						break;
					}
					else if (k == n - 1) {
						ans += a[i][j];
					}
				}

			}
		}
		if (isFinished)break;
	}
	cout << ans << endl;
}


Measured memory_bytes: 1664
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cctype>
#include <cassert>
#include <limits>
#include <functional>
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r,v) auto r = (v)
#else
#define aut(r,v) __typeof(v) r = (v)
#endif
#define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)
#define all(o) (o).begin(), (o).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset(m,v,sizeof(m))
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
using namespace std;
typedef vector<int> vi; typedef pair<int,int> pii; typedef vector<pair<int,int> > vpii; typedef long long ll;
template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }

int main() {
	int N, M;
	while(~scanf("%d%d", &N, &M)) {
		vector<vpii> v(N);
		rep(i, N) {
			int K;
			scanf("%d", &K);
			v[i].resize(K);
			rep(j, K)
				scanf("%d%d", &v[i][j].first, &v[i][j].second);
		}
		vector<vector<double> > dp(N+1, vector<double>(M+1, -1));
		dp[0][0] = 0;
		rep(i, N) {
			const vpii &w = v[i];
			rer(j, 0, M) {
				double x = dp[i][j];
				if(x < 0) continue;
				int l = 0, p = 0;
				double h = 0;
				rer(k, 0, M - j) {
					amax(dp[i+1][j+k], x + h);
					if(l == w.size())
						break;
					h += 1. / w[l].first;
					++ p;
					if(p == w[l].first * w[l].second) {
						p = 0;
						++ l;
					}
				}
			}
		}
		double ans = *max_element(all(dp[N]));
		printf("%.10f\n", ans);

	}
	return 0;
}

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

int main(){
    string S,T,U;
    int a,b;
    cin >> S >> T >> a >> b >> U;

    if(S == U){
        a--;
    }else{
        b--;
    }

    cout << a <<" "<< b;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main(){
    string name[1000],nmemo;
    int n,a,b,c,num=0,score[1000];
    while(1){
        num++;
    cin>>n;
        if(n==0){
            break;
        }
        if(num!=1){
            cout<<endl;
        }
    for(int i=0;i<n;i++){
        cin>>name[i]>>a>>b>>c;
        score[i]=a*3+c;
    }
    int max=-10000,count=0,j=0,s;bool bo=false;
    while(1){
        if(count==n){
            break;
        }
        for(int i=0;i<n;i++){
            if(score[i]>max){
                max=score[i];
                s=i;
            }
        }
        cout<<name[s]<<","<<score[s]<<endl;
        count++;
        score[s]=-10;
        max=-10000;
    }
    }
    return 0;
}

Measured memory_bytes: 3180
#include <iostream>

int main() {
	long long n, a, b;
	std::cin >> n >> a >> b;
	long long use = std::min(a - 1, n);
	n -= use;
	std::cout << std::max(n + use + 1, use + 1 + (b - a) * (n / 2) + n % 2) << '\n';
}

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

using namespace std;

long long f(long long x, long long a, long long b) {
    // a <= b
    long long lcm = a*b / __gcd(a, b);
    return x - (x/b + x/a) + x/lcm;
}

int main() {
    long long A, B, C, D;
    cin >> A >> B >> C >> D;
    cout << f(B, C, D) - f(A-1, C, D) << endl;
}

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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    int N, M;
    cin >> N >> M;
    vector<P> items(M);
    rep(i, M) {
        ll a, b;
        cin >> a >> b;
        ll t = 0;
        rep(i, b) {
            int c;
            cin >> c;
            c--;
            t |= 1 << c;
        }
        items[i] = make_pair(a, t);
    }
    vector<ll> dp(1 << N, INF);
    dp[0] = 0;
    rep(i, 1 << N) {
        rep(j, M) {
            P p = items[j];
            dp[i | p.second] = min(dp[i | p.second], dp[i] + p.first);
        }
    }
    if (dp[(1 << N) - 1] == INF) {
        cout << -1 << '\n';
    } else {
        cout << dp[(1 << N) - 1] << '\n';
    }
}

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


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

first = scores.select{|n| n <= A}.count
second = scores.select{|n| n > A && n <= B}.count
third = scores.select{|n| n > B}.count

puts [first, second, third].min

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

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

    int n;
    cin >> n;
    cout << (n+n*n+n*n*n);
    
    return 0;
}

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

int main(){
   int n;
   int k = 0;
   int p = 1;
   int64_t a = 0;
   cin >> n >> k;
   while(n/k!=0){
     n = n/k;
     p++;
   }
cout << p << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    // 整数の入力
	double w, h, x, y;
    double a,b;
    double c_x,h2;
    cin >> w >> h >> x >> y;
    if(x==w/2&&y==h/2){
        cout << w*h/2 << " " << 1 << endl;
        return 0;
    }else {
        /*
        a = (y-h/2)/(x-w/2);
        b = y-a*x;
        c_x = -b/a;
        h2 = a*w + b;
        */
        cout << w*h/2 << " " << 0 << endl;
        return 0;
    }    
}

Measured memory_bytes: 256
function gcd(a,b){
  if(b==0){return a;}
  return gcd(b, a%b);
}

function main(input) {
  const formatted_input = input.split('\n');

  const N = parseInt(formatted_input[0], 10);
  const As = formatted_input[1].split(' ').map(x => parseInt(x));

  var L = [];
  var R = [];
  var l_tmp = 0;
  var r_tmp = 0;
  for( var i = 0 ; i<N ; i++ ){
    l_tmp = gcd(l_tmp, As[i]);
    r_tmp = gcd(r_tmp, As[N-1-i]);
    L.push(l_tmp);
    R.push(r_tmp);
  }
  R = R.reverse();

  var results = [];
  for( var i = 0 ; i < N ; i++ ){
    if(i==0){
      results.push(R[i+1]);      
    }else if(i==N-1){
      results.push(L[i-1]);      
    }else{
      results.push(gcd(L[i-1],R[i+1]));
    }
  }

  console.log(Math.max(...results));
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));




Measured memory_bytes: 32244
#include <iostream>
int main()
{
    int long n;
    std::cin>>n;
    long double check=1;
    long double a;
    long long ans=1;
    for(int i=0;i<n;i++){
        std::cin>>a;
        ans*=a;
        check*=a;
    } 
    if(check>1000000000000000000){
        std::cout<<"-1"<<std::endl;
    }
    else{
        std::cout<<ans<<std::endl;
    }
}


Measured memory_bytes: 3812
#include <iostream>
#include <string>
using namespace std;
int main(void){
	int n,k;
	while(cin >> n >> k,n|k){
		bool ok=true;
		int r[100],tmp;
		for(int i=0;i<k;i++)
			cin >> r[i];
		for(int j=0;j<n;j++){
			for(int i=0;i<k;i++){
				cin >> tmp;
				r[i]-=tmp;
				if(r[i]<0)
					ok=false;
			}
		}
		if(ok)
			cout << "Yes" << endl;
		else
			cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 1152
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

template <class T>
struct Edge {
  using w_type = T;
  Edge(int u, int v, w_type w): u(u), v(v), w(w) { }
  int u, v;
  w_type w;
  bool operator<(const Edge<T> & rhs) const {
    if (w != rhs.w) { return w < rhs.w; }
    if (u != rhs.u) { return u < rhs.u; }
    return v < rhs.v;
  }
};

class DisjointSet {
public:
  DisjointSet(const unsigned n_sets): n_sets_(n_sets) {
    p_.reserve(n_sets);
    rank_.reserve(n_sets);
  }
  void MakeSet(const unsigned x) { p_[x] = x; rank_[x] = 0; }
  void Union(const unsigned lhs, const unsigned rhs) {
    Link(FindSet(lhs), FindSet(rhs));
  }
  void Link(const unsigned lhs, const unsigned rhs) {
    if (rank_[lhs] > rank_[rhs]) { p_[rhs] = lhs; }
    else {
      p_[lhs] = rhs;
      if (rank_[lhs] == rank_[rhs]) { ++rank_[rhs]; }
    }
  }
  unsigned FindSet(const unsigned x) {
    if (x != p_[x]) { p_[x] = FindSet(p_[x]); }
    return p_[x];
  }

private:
  unsigned n_sets_;
  vector<unsigned> p_;
  vector<unsigned> rank_;
};

template <class Edge>
decltype(auto) Kruskal(vector<Edge> & edges,
                 typename vector<Edge>::size_type node_num) {
  using size_type = typename vector<Edge>::size_type;
  using const_it = typename vector<Edge>::const_iterator;
  using w_type = typename Edge::w_type;

  w_type weight_sum = 0;
  size_type edge_num = 0;
  DisjointSet dis_set(node_num);
  for (size_type i = 0; i < node_num; ++i) { dis_set.MakeSet(i); }
  sort(edges.begin(), edges.end());
  for (auto & e: edges) {
    if (dis_set.FindSet(e.u) != dis_set.FindSet(e.v)) {
      weight_sum += e.w;
      dis_set.Union(e.u, e.v);
      ++edge_num;
    }
    if (edge_num == node_num - 1) { break; }
  }

  return weight_sum;
}

int main(int argc, char const *argv[]) {
  vector<Edge<unsigned>> edges;
  unsigned V, E;
  cin >> V >> E;
  for (unsigned i = 0; i < E; ++i) {
    unsigned u, v;
    unsigned w;
    cin >> u >> v >> w;
    edges.emplace_back(u, v, w);
  }
  cout << Kruskal(edges, V) << endl;
  return 0;
}

Measured memory_bytes: 4464
N=int(input())
A=list(map(int,input().split()))
d4=len([i for i in A if i%4==0])
d2=len([i for i in A if i%2==0 and i%4!=0])

N=N-(d4*2)
if N==1:
    N=0
else:
    N-=d2

print("Yes" if N<=0 else "No")


Measured memory_bytes: 63640