akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

class mint{
	static const int MOD=998244353;
	int x;
public:
	mint():x(0){}
	mint(long long y){ x=y%MOD; if(x<0) x+=MOD; }

	mint& operator+=(const mint& m){ x+=m.x; if(x>=MOD) x-=MOD; return *this; }
	mint& operator-=(const mint& m){ x-=m.x; if(x<   0) x+=MOD; return *this; }
	mint& operator*=(const mint& m){ x=1LL*x*m.x%MOD; return *this; }
	mint& operator/=(const mint& m){ return *this*=inverse(m); }
	mint operator+(const mint& m)const{ return mint(*this)+=m; }
	mint operator-(const mint& m)const{ return mint(*this)-=m; }
	mint operator*(const mint& m)const{ return mint(*this)*=m; }
	mint operator/(const mint& m)const{ return mint(*this)/=m; }

	friend mint inverse(const mint& m){
		int a=m.x,b=MOD,u=1,v=0;
		while(b>0){ int t=a/b; a-=t*b; swap(a,b); u-=t*v; swap(u,v); }
		return u;
	}

	friend istream& operator>>(istream& is,mint& m){ long long t; is>>t; m=mint(t); return is; }
	friend ostream& operator<<(ostream& os,const mint& m){ return os<<m.x; }
	int to_int()const{ return x; }
};

mint pow(mint m,long long k){
	mint res=1;
	for(;k>0;k>>=1,m*=m) if(k&1) res*=m;
	return res;
}

class linear_sieve{
	vector<int> lpf,p;
public:
	linear_sieve(int n):lpf(n+1){
		for(int i=2;i<=n;i++){
			if(lpf[i]==0){
				lpf[i]=i;
				p.emplace_back(i);
			}
			for(int j=0;j<p.size()&&p[j]<=lpf[i]&&i*p[j]<=n;j++) lpf[i*p[j]]=p[j];
		}
	}

	const vector<int>& primes()const{ return p; }

	bool is_prime(int a)const{
		assert(a<=(int)lpf.size()-1);
		return a>0 && lpf[a]==a;
	}

	map<int,int> prime_factorize(int a)const{
		assert(a<=(int)lpf.size()-1);
		map<int,int> pf;
		for(;a>1;a/=lpf[a]) ++pf[lpf[a]];
		return pf;
	}
};

template<class T>
vector<T> divisors(const map<T,int>& pf){
	vector<T> res={T(1)};
	for(const auto& q:pf){
		int m=res.size();
		T pp=1;
		rep(i,q.second){
			pp*=q.first;
			rep(i,m) res.emplace_back(res[i]*pp);
		}
	}
	sort(res.begin(),res.end());
	return res;
}

int main(){
	linear_sieve LS(1e6);

	int n; scanf("%d",&n);
	vector<int> a(n);
	rep(i,n) scanf("%d",&a[i]);

	static vector<int> J[1000001];
	rep(i,n) for(int d:divisors(LS.prime_factorize(a[i]))) J[d].emplace_back(i);

	static mint coef[1000001];

	mint ans=0;
	for(int d=1;d<=1e6;d++){
		mint sum=0,sqsum=0;
		for(int i:J[d]){
			sum+=a[i];
			sqsum+=mint(a[i])*a[i];
		}
		mint prodsum=(sum*sum-sqsum)/2;

		coef[d]=mint(1)/d;
		for(int h:divisors(LS.prime_factorize(d))) if(h<d) coef[d]-=coef[h];

		ans+=coef[d]*prodsum;
	}
	printf("%d\n",ans.to_int());

	return 0;
}


Measured memory_bytes: 74588
#include<cstdio>
#include<vector>
#include<iostream>
#include<map>
#include<queue>
#include<algorithm>
#include<cstring>
#include<cmath>
#define eps 1e-10
#define inf 100000000
using namespace std;
int n,m,c;
struct node
{
    int t,cost;
    node(int t=0,int cost=0):t(t),cost(cost) {}
};
vector<node> G[105];
int d[105][105];
void spfa()
{
    queue<pair<int,int> > q;
    bool vis[105][105];
    for(int i=1;i<=n;i++)
    for(int j=0;j<=n;j++) d[i][j]=inf;
    d[1][0]=0;memset(vis,0,sizeof(vis));
    q.push(make_pair(1,0));
    while(!q.empty())
    {
        pair<int,int> p=q.front();q.pop();
        int x=p.first,y=p.second;
        vis[x][y]=0;
        for(int i=0;i<G[x].size();i++)
        {
            int v=G[x][i].t,co=G[x][i].cost;
            if(d[v][y]>d[x][y]+co)
            {
                d[v][y]=d[x][y]+co;
                if(!vis[v][y])
                {
                    vis[v][y]=1;
                    q.push(make_pair(v,y));
                }
            }
            if(y<n&&d[v][y+1]>d[x][y])
            {
                d[v][y+1]=d[x][y];
                if(!vis[v][y+1])
                {
                    vis[v][y+1]=1;
                    q.push(make_pair(v,y+1));
                }
            }
        }

    }
}
main()
{
    while(scanf("%d%d%d",&n,&m,&c),n+m+c)
    {
        memset(G,0,sizeof(G));
        for(int i=1;i<=m;i++)
        {
            int s,t,c;
            scanf("%d%d%d",&s,&t,&c);
            G[s].push_back(node(t,c));
        }
        spfa();
        int ans;
        for(int j=1;j<=n;j++)
        if(d[n][j]<=c) {ans=j;break;}
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 1644
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ii pair<int, int>
#define fi first
#define se second

vector<int> P, N;

int cont(vector<int> &arr, int i, int x, int lim)
{
	int b = i, e = arr.size() - 1, ans = -1;
	while(b <= e)
	{
		int m = (b + e) / 2;
		if(arr[m] * x <= lim)
			b = m + 1, ans = m;
		else 
			e = m - 1;
	}
	if(ans == -1) return 0;
	return ans - i + 1;
}

int cont2(vector<int> &arr, int x, int lim)
{
	int b = 0, e = arr.size() - 1, ans = -1;
	while(b <= e)
	{
		int m = (b + e) / 2;
		if(arr[m] * x <= lim)
			e = m - 1, ans = m;
		else 
			b = m + 1;
	}
	if(ans == -1) return 0;
	return (int)arr.size() - ans;
}

int check(int v)
{
	int cnt = 0;
	for(int i = 0; i < P.size(); i++)
		cnt += cont(P, i + 1, P[i], v);
	for(int i = 0; i < N.size(); i++)
		cnt += cont(N, i + 1, N[i], v);
	for(int i = 0; i < N.size(); i++)
		cnt += cont2(P, -N[i], v);
	return cnt;
}

int bb(int k)
{
	int b = -1000000000000000010;
	int e = 1000000000000000010;
	int ans;
	while(b <= e)
	{
		int m = (b + e) / 2;
		int cnt = check(m);
		if(cnt >= k) ans = m, e = m - 1;
		else b = m + 1;
	}
	return ans;
}

int32_t main()
{
	int n, k;
	cin >> n >> k;
	for(int i = 0; i < n; i++)
	{
		int x;
		cin >> x;
		if(x >= 0) P.push_back(x);
		else N.push_back(-x);
	}
	sort(P.begin(), P.end());
	sort(N.begin(), N.end());	
	
	cout << bb(k) << '\n';	

	return 0;
}

Measured memory_bytes: 2548
n = int(input())
sp = []
for i in range(n):
    s, p = map(str, input().split())
    sp.append([s, int(p), i + 1])
sp = sorted(sp, key=lambda x: x[1], reverse=True)
sp = sorted(sp, key=lambda x: x[0])
for i in sp:
    print(i[2])


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>


int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    ll n;
    cin>>n;
    vector<ll> a(3*n);
    for(ll i=0;i<3*n;i++){
        cin>>a[i];
    }
    vector<ll> v(3*n,0);
    vector<ll> w(3*n,0);
    priority_queue<ll,vector<ll>,greater<ll>> pq;
    ll sum=0;
    for(ll i=0;i<n;i++){
        sum+=a[i];
        pq.push(a[i]);
    }
    v[n-1]=sum;
    for(ll i=n;i<3*n;i++){
        if(pq.top()<a[i]){
            sum = sum-pq.top()+a[i];
            pq.pop();
            pq.push(a[i]);
        }
        v[i] = sum;
    }
    sum=0;
    priority_queue<ll,vector<ll>> pq2;
    for(ll i=3*n-1;i>=2*n;i--){
        sum+=a[i];
        pq2.push(a[i]);
    }
    w[2*n] = sum;
    for(ll i=2*n-1;i>=0;i--){
        if(pq2.top()>a[i]){
            sum = sum-pq2.top()+a[i];
            pq2.pop();
            pq2.push(a[i]);
        }
        w[i]=sum;
    }
    ll ans = -(1LL<<60);
    for(ll i=n-1;i<2*n;i++){
        ans = max(ans,v[i]-w[i+1]);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 9588
#include<map>
#include <cstdio>
#include<string>
#include <complex>
#include<iostream>

using namespace std;

#define loop(i,a,b) for(int i=(a); i<int(b);i++)
#define rep(i,b) loop(i,0,b)

complex<double> ps[1100];

int main(){
    complex<double> p(1,1);
    loop(i,1,1100){
        ps[i] = p;
        double t = arg(p);
        p += polar(1.0,t+acos(-1)/2);
    }

    while(1){
        int x; cin >> x;
        if(x==-1) break;
        x--;
        printf("%.20lf\n%.20lf\n", ps[x].real(), ps[x].imag());
    }
}

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

int main()
{
    string s, p;
    cin >> s;
    cin >> p;
    
    string s2 = s+s;
    for (int i=0; i<s.size(); i++)
    {
        string p_tmp = s2.substr(i,p.size());
        if (p==p_tmp)
        {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}


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

#define rep2(x,fr,to) for(int x=(fr);x<(to);x++)
#define rep(x,to) for(int x=0;x<(to);x++)
#define repr(x,fr,to) for(int x=(fr);x>=(to);x--)
#define all(c) c.begin(),c.end()
#define sz(v) (int)v.size()

using namespace std;
typedef long long  ll; typedef vector<int> VI; typedef pair<int,int> pii; typedef vector<ll> VL; const int MD = 1e9 + 7;
void dbg(){cerr<<"\n";} template <class F,class ...S> void dbg(const F& f, const S&...s){cerr <<f <<": "; dbg(s...);}



int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	ll h,w, m;
	cin >>h >>w >>m;
	set<ll> st;
	VL smh(h+3), smw(w+3);

	rep(i, m){
		int yy, xx;
		cin >>yy >>xx;
		st.insert(yy *w + xx);
		smw[xx]++;
		smh[yy]++;
	}
	
	auto ck=[&](ll a, ll b){
		return st.count(a*w +b) > 0;
	};

	vector<pii> srh, srw;
	rep(i, h+1) if(smh[i]>0) srh.emplace_back(smh[i], i);
	rep(i, w+1) if(smw[i]>0) srw.emplace_back(smw[i], i);
	
	sort(srh.rbegin(), srh.rend());
	sort(srw.rbegin(), srw.rend());
	
	ll mx = srh[0].first + srw[0].first;
	int ct = 0;
	for(auto& yy :srh){
		if(yy.first + srw.front().first < mx) break;
		for(auto& xx :srw){
			ll kei = yy.first + xx.first;
			if(kei < mx) break;
			if(!ck(yy.second, xx.second)){
				cout << mx <<"\n"; return 0;
			}
			if(++ct > m+1) break;
		}
	}
	
	cout << (ct>m? mx: mx-1) <<"\n";
	
	return 0;
}



Measured memory_bytes: 30304
a,b=map(int, input().split())
tower=[0 for i in range(1000)]
tower[0] = 1

for i in range(1, 1000):
    tower[i] = tower[i-1] + (i + 1)
    diff_a = tower[i-1] - a
    diff_b = tower[i] - b
    if (diff_a == diff_b) and diff_a > 0 and diff_b > 0:
        print(diff_a)
        break


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

using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;
#define DEBUG freopen("in.txt", "r", stdin);

struct fastio {
    fastio() {
        ios::sync_with_stdio(false);
        cout << setprecision(10) << fixed;
        cin.tie(0);
    }
};

fastio _fast_io;

ll n, s;
bool check(ll x, ll y) {
    ll ret = 0;
    while (x) {
        ret += x % y;
        x /= y;
    }
    return ret == s;
}
int main() {
    cin >> n >> s;
    ll d = n - s;
    if (d < 0) {
        cout << -1 << endl;
        return 0;
    }
    if (d == 0) {
        cout << n + 1 << endl;
        return 0;
    }

    ll m = sqrt(n) + 1;
    for (ll i = 2; i < m; ++i) {
        if (check(n, i)) {
            cout << i << endl;
            return 0;
        }
    }
    // b > sqrt(n);
    // (b−1)*B=n−s
    ll t = n / m + 1;
    for (ll B = t; B >= 1; --B) {
        if (d % B == 0) {
            ll b = d / B + 1;
            if (b > B && n / b == B) {
                cout << b << endl;
                return 0;
            }
        }
    }
    cout << -1 << endl;
    return 0;
}


Measured memory_bytes: 3712
import java.io.*;
        import java.util.*;

public class Main {
    //-------------------------------------------------------------//
    public static final void main(String[] args) {
        new Main().solve();
    }
    //-------------------------------------------------------------//
    private final Scanner sc = new Scanner(System.in);
    void solve() {
        int N = sc.nextInt();
        int[] minNum = new int[26];
        Arrays.fill(minNum, 10000);
        boolean[] canUse = new boolean[26];
        Arrays.fill(canUse, true);
        for (int i = 0; i < N; i++) {
            String s = sc.next();
            int[] cnt = new int[26];
            Arrays.fill(cnt, 0);
            boolean[] ok = new boolean[26];
            for (int j = 0; j < s.length(); j++) {
                char c = s.charAt(j);
                ok[c - 'a'] = true;
                cnt[c - 'a']++;
            }
            for (int j = 0; j < 26; j++) {
                if (!ok[j]) canUse[j] = false;
                minNum[j] = Math.min(minNum[j], cnt[j]);
            }
        }

        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < 26; i++) {
            if (canUse[i]) {
                for (int j = 0; j < minNum[i]; j++) {
                    sb.append((char)('a' + i));
                }
            }
        }
        System.out.println(sb.toString());
    }
}

Measured memory_bytes: 23252
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;

int main(){
    ll a,b,c,x,y;
    cin>>a>>b>>c>>x>>y;
    int mn=min(x,y);
    ll ans=0;
    ans+=min(c*mn*2,(a+b)*mn);
    if(x>=y){
        x-=y;
        ans+=min(a*x,c*x*2);
    }
    else{
        y-=x;
        ans+=min(b*y,c*y*2);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> a(N); 

  for (int i = 0; i < N; i++) 
    cin >> a.at(i);
    
    sort(a.begin(), a.end());
    reverse(a.begin(), a.end());

  int A=0, B=0;
  for (int i = 0; i < N; i++) {
    if (i%2==0)
       A+=a.at(i);
    else
       B+=a.at(i);
  }

  cout << A-B << endl;
}

Measured memory_bytes: 256
// Problem : 
// 			C - Walking Takahashi
// 			
// 		
// Contest : AtCoder - AtCoder Beginner Contest 175
// URL : https://atcoder.jp/contests/abc175/tasks/abc175_c
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
using namespace std;
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char *name, Arg1 &&arg1) {
    cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args&&... args) {
    const char *comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << " : " << arg1 << " | ";
    __f(comma + 1, args...);
}
#define int long long int
#define ld long double
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define MOD 1000000007
#define mod 998244353
#define bug cout<<"HY"<<endl
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define numize(A) A.numize(unique(A.begin(), A.end()) - A.begin())
typedef pair<int,int> P;
int power(int a,int b)
{
    if(b==0)
        return 1;
    if(b%2==0)
        return (power((a*a)%mod,b/2))%mod;
    return (a*(power((a*a)%mod,b/2))%mod)%mod;
}
int modInv(int n)
{
    return power(n, MOD-2);
}
int nCr(int n, int r, int p=MOD)
{
   if (r==0)
      return 1;
    int Fact[n+1];
    Fact[0] = 1;
    for (int i=1 ; i<=n; i++)
    {
        Fact[i] = (Fact[i-1]*i)%p;
    }
    return (((Fact[n]* modInv(Fact[r])) % MOD) *(modInv(Fact[n-r]) % MOD)) % MOD;
}
double PI=3.14159265359;
void solve()
{
	int x,k,d;
	cin>>x>>k>>d;
	x=abs(x);
	int num=x/d;
	if(num>=k)
	{
		x-=k*d;
		cout<<x<<endl;
		return;
	}
	else
	{
		x-=num*d;
		k-=num;
		if(k%2)
		{
			cout<<abs(x-d)<<endl;
		}
		else
		{
			cout<<abs(x)<<endl;
		}
	}
}
int32_t main()
{
    boost;
    int  t=1;
    // cin>>t;
    while(t--)
    {
    	solve();
    }
}


Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string str;
    getline(cin,str);
    int point=0;
    bool flag=1;
    for(int i=0;i<str.size();i++){
        if(str[i]==' '||str[i]=='.'||str[i]==','){
            if(i-point>2&&i-point<7){
                if(!flag)cout<<" ";
                for(int j=point;j<i;j++)cout<<str[j];
                flag=false;
            }
            point=i+1;
        }
    }
    cout<<endl;
}

Measured memory_bytes: 1168
n, m = map(int, input().split())
s = input()
s = s[::-1]
place = 0
res = []
while place < n:
  sub_s = s[place+1:place+m+1]
  if "0" in sub_s:
    dist = len(sub_s) - sub_s[::-1].index("0")
  else:
    print(-1)
    exit()
  place += dist
  res.append(str(dist))
print(" ".join(res[::-1]))

Measured memory_bytes: 10564
#include <stdio.h>

int main(void)
{
    int i,j,k,n,x,count;
   
 do{
    scanf("%d %d",&n,&x);
  
    if(n == 0 && x == 0)
    break;
   
    count = 0;
   
    for(i = 1;i < n-1;i++){
    	for(j = i+1;j < n;j++){
    		for(k = j+1;k < n+1;k++){
    			if(i+j+k==x){
    				count = count + 1;
    			}
    		}
    	}
    }
   	 printf("%d\n",count);
   }while(1);
		
	return 0;
}

Measured memory_bytes: 1760
import sys

sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inl = lambda: [int(x) for x in sys.stdin.readline().split()]
ins = lambda: sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw))


def solve():
    a, b, c, d = inl()
    return max([a * c, a * d, b * c, b * d])


print(solve())


Measured memory_bytes: 9208
N, M = map(int, input().split())
K = [0 for _ in range(M)]
S = [[] for _ in range(M)]
for m in range(M):
  ks = list(map(int, input().split()))
  K[m] = ks[0]
  S[m] = ks[1:]
P = list(map(int, input().split()))
#print(N, M, K, S, P)

def dfs(n, sw):
  if n > 0:
    return dfs(n-1, sw + [0]) + dfs(n-1, sw + [1])
  else:
    answer = 1
    for m in range(M):
      count = 0
      for k in range(K[m]):
        count += sw[S[m][k]-1]
      if count % 2 != P[m]:
        answer = 0
        break
    return answer
        
print(dfs(N, []))

Measured memory_bytes: 41452
#include<stdio.h>
#include<string.h>
#include<math.h>

int main() {
	double  x1,y1,x2,y2,kyori;
	
	scanf("%lf %lf %lf %lf", &x1, &y1, &x2, &y2);
	
	kyori=pow(x2-x1,2)+pow(y2-y1,2);
	kyori = sqrt(kyori);

	printf("%0.8f\n", kyori);
	return 0;
}


Measured memory_bytes: 2040
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<string>
#include<cmath>
#include<queue>
#include<vector>
#include<sstream>
#include<algorithm>
#include<stack>
#include<bitset>
#include<map>
#include<set>
#define rep(i,n) for(int i=0;(i)<(n);i++)
#define rep1(i,n) for(int i=1;(i)<=(n);i++)
#define mst(a,b) memset(a,b,sizeof(a))
#define scd(a) scanf("%d",&a)
#define scdd(a,b) scanf("%d%d",&a,&b)
#define scddd(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define dbg(a) cout<<"* "<< #a <<" : "<<a<<endl
#define fr first
#define se second
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define lowbit(x) x&(-x)
#define ac cout<<ans<<endl
//#define DEBUG 0
using namespace std;
const double pi=acos(-1.0);
const double eps=1e-6;
const ull hashp=1e7+19;
const ll INF=0x3f3f3f3f3f3f3f3fll;
const int inf=0x3f3f3f3f;
const int mod=1e9+7;
const int maxn=1e5+100;
int a[]={300000,200000,100000,400000};
void solve()
{
	int x,y;
	scdd(x,y);
	int ans=0;
	if(x<=3)ans+=a[x-1];
	if(y<=3)ans+=a[y-1];
	if(x==y&&y==1)ans+=a[3];
	ac;
}
int main(){
    //IOS;
    //freopen("D://data.txt","r",stdin);
    solve();
    return 0;
}


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

using ll =  long long;
using pint =  pair<int,int>;

#define INF 99999999
#define rep(i,n) for(int (i)=0,temp=(int)(n);(i)<temp;++(i)) 
#define repi(i,start,end) for(int (i)=(start),temp=(int)(end);i<(end);++(i))
#define rfor(v,x) for(const auto& (x) : (v)) //xは値を表す
#define all(x) (x).begin(),(x).end()
#define SORT(v, n) sort((v), (v)+(n))
#define vsort(v) sort((v).begin(), (v).end())
#define vfsort(v,lambda) sort(all((v)),(lambda))
#define vint vector<int>
#define vvint vector<vector<int>> //vvint v(n,vint(n))のように宣言できる
#define vin(v) rep(i,(v).size()) {cin >> (v)[i];}
//最終奥義(使うときはINFも書き換えろ!!)
//#define int long long
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; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int ctoi(char c) {return c-'0';}
//lambda式 -> [&](int x, int y){return x<y;}
//vector内の重複を削除-> v.erase(unique(all(v)),v.end());

signed main(void){
  string s;cin>>s;
  int n=s.length();
  vint v(n);
  rep(i,n)v[i]=s[n-i-1]-'0';
  v.push_back(0);
  rep(i,n){
    if(v[i]>5||v[i]==5&&v[i+1]>=5){
      v[i+1]++;
      v[i]=10-v[i];
    }
  }
  cout << accumulate(all(v),0LL) << endl;
}


Measured memory_bytes: 11012
e1,e2,e3,e4=map(int,input().split())

i=0

while i<3:
    if e1>e2:
        e1,e2=e2,e1
    if e2>e3:
        e2,e3=e3,e2
    if e3>e4:
        e3,e4=e4,e3
    i+=1
    
if e1==e2:
    if e3==e4:
        print("yes")
    else:
        print("no")
else:
    print("no")


Measured memory_bytes: 5596
#include <iostream>
#include <string>
#include <vector>
#include <iomanip>
#include <algorithm>
using namespace std;
int main() {
	vector <int> w, r;
	int n, counter=0,i1 = 0, j1 = 0;
	string s;
	cin>>n>>s;
	for (int i = 0; i < n; i++) {
		if (s[i] == 'W') {
			w.push_back(i);
		}
		else {
			r.push_back(i);
		}
	}
	reverse(r.begin(), r.end());
	int rInd = 0, wInd = 0;
	while (wInd < w.size() && rInd < r.size() && w[wInd] < r[rInd]) {
		wInd++;
		rInd++;
		counter++;
	}
	cout << counter;
}

Measured memory_bytes: 4212
#include <stdio.h>
int main(void)
{
	int i, n;
	char t[4];
	int c[4];
	for (i=0; i<4; ++i) c[i]=0;
	while (scanf("%d,%s", &n, t) != EOF) {
		switch (t[0]) {
			case 'A': if (t[1]=='B') c[2]++; else c[0]++; break;
			case 'B': c[1]++; break;
			case 'O': c[3]++; break;
		}
	}
	if (c[1] == 7) return 1;
	for (i=0; i<4; ++i) printf("%d\n", c[i]);
	return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<stdio.h>
#include<queue>
#include<algorithm>
using namespace std;
queue <int> qy,qx,qcnt;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int n,m,x,y,cnt,nx,ny,mini,ansx,ansy;
int t[20][20],sx,sy,tx,ty,vd[20][20],ghost[20][20];
string in;
int main(){
  while(cin>>n>>m&&n){
    for(int i=0;i<n;i++){
      cin>>in;
      for(int j=0;j<(int)in.size();j++){
	if(in[j]=='A')sx=j,sy=i;
	else if(in[j]=='B')tx=j,ty=i;
	t[i][j]=(in[j]=='#');
      }
    }
    
    for(int i=0;i<20;i++)for(int j=0;j<20;j++)vd[i][j]=0;
    vd[sy][sx]=1;
    qx.push(sx);
    qy.push(sy);
    qcnt.push(1);
    while(!qx.empty()){
      x=qx.front();qx.pop();
      y=qy.front();qy.pop();
      cnt=qcnt.front();qcnt.pop();
      for(int i=0;i<4;i++){
	nx=x+dx[i];ny=y+dy[i];
	if(!(0<=nx&&nx<m&&0<=ny&&ny<n))continue;
	if(vd[ny][nx]>0||t[ny][nx]==1)continue;
	vd[ny][nx]=cnt+1;
	qx.push(nx);
	qy.push(ny);
	qcnt.push(cnt+1);
      }
    }
    
    
    cin>>in;
    cnt=0;
    mini=99999999;
    for(int i=0;i<20;i++)for(int j=0;j<20;j++)ghost[i][j]=0;
    
    for(int I=0;I<400;I++){
      
      
      ghost[ty][tx]=1;
      for(int i=0;i<(int)in.size();i++){
	cnt++;
	
	if(cnt>=vd[ty][tx]&&vd[ty][tx]!=0){
	  if(mini>cnt){
	    mini=cnt;
	    ansy=ty;
	    ansx=tx;
	  }
	}
	if(in[i]=='5')continue;
	else if(in[i]=='8'){
	  if(ty==0)continue;
	  ty--;
	}else if(in[i]=='6'){
	  if(tx==m-1)continue;
	  tx++;
	}else if(in[i]=='4'){
	  if(tx==0)continue;
	  tx--;
	}else{
	  if(ty==n-1)continue;
	  ty++;
	}
      }//for
    }//while
    if(mini==99999999)cout<<"impossible"<<endl;
    else cout<<mini-1<<' '<<ansy<<' '<<ansx<<endl;
  }
  return 0;
}

Measured memory_bytes: 1232
#include<bits/stdc++.h>
using namespace std;
#define debug 1

long long n,m,ans=0;
const long num[]={0,1,3,6,10,15,21,28,36,45,55,66,78};

const long MAXPRIME=1001000;
bool is_prime[MAXPRIME];
/*void find_prime() {
	memset(1,is_prime,sizeof(is_prime));
	is_prime[0]=0;is_prime[1]=0;
	register long i,j;
	for(i=2;i<MAXPRIME;++i)
		if(is_prime
}
*/
int main() {
	cin>>n;
	
	memset(is_prime,1,sizeof(is_prime));
	is_prime[0]=0;is_prime[1]=0;
	register long i,j;
	for(i=2;i<MAXPRIME;++i)
		if(is_prime[i]) {
			for(j=2;i*j<MAXPRIME;++j)
				is_prime[i*j]=0;
			
			m=0;
			while(n%i==0) {
				n/=i;
				++m;
			}
			for(long k=0;k<12;++k)
				if(m<num[k+1]) {
					ans+=k;
					break;
				}
//			if(n==1) break;
		}
	
	if(n!=1) ++ans;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 4608
#include<iostream>
#include <string>
#include <iomanip>
#include <vector>
#include <queue>
#include <algorithm>
#include <functional>
#include <math.h>
#include <stack>
#include <cctype>
using namespace std;
#define int long long
#define pi 2*acos(0.0)
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define REP(i,n) for (int i=0;i<(n);i++)

signed main()
{
	int a, b, c;
	cin >> a >> b >> c;
	if (c >= a && c <= b) cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 256
/* “Whether you think you can or you think you can’t, you’re right” - Henry Ford */

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fast                      \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0);
#define all(x) x.begin(), x.end()
#define F first
#define S second
#define pb push_back
#define pl pair<ll, ll>
#define vl vector<ll>
#define vi vector<int>
#define endl '\n'

template <typename T, typename TT>
ostream &operator<<(ostream &os, const pair<T, TT> &t)
{
    return os << t.first << " " << t.second;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &t)
{
    for (auto &i : t)
        os << i << " ";
    return os;
}
template <typename T>
istream &operator>>(istream &is, vector<T> &v)
{
    for (T &t : v)
        is >> t;
    return is;
}
template <typename T1, typename T2>
istream &operator>>(istream &is, vector<pair<T1, T2>> &v)
{
    for (pair<T1, T2> &t : v)
        is >> t.first >> t.second;
    return is;
}

const ll mod = 1e9 + 7;

ll dfs(vector<vl> &v, vector<bool> &vis, ll u)
{
    if (vis[u])
        return 0;
    vis[u] = 1;
    ll c = 1;
    for (auto x : v[u])
    {
        c += dfs(v, vis, x);
    }
    return c;
}

void solve()
{
    ll n, m;
    cin >> n >> m;
    vector<vl> v(n);
    while (m--)
    {
        ll a, b;
        cin >> a >> b;
        a--, b--;
        v[a].pb(b);
        v[b].pb(a);
    }
    ll ans = 0;
    vector<bool> vis(n, 0);
    for (int i = 0; i < n; i++)
    {
        if (!vis[i])
        {
            ll c = dfs(v, vis, i);
            ans = max(ans, c);
        }
    }
    cout << ans << endl;
}

int main()
{
    fast;
    ll t = 1;
    // cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}


Measured memory_bytes: 23524
import java.util.Scanner;
public class Main{
  public static void main(String[]args){
    Scanner sc=new Scanner(System.in);
    int a=sc.nextInt();
    int b=sc.nextInt();
    int h=sc.nextInt();
    int Area=(a+b)*(h/2);
    System.out.println(Area);
  }
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define REPR(i, n) for(int i = (n); i >= 0; i--)
#define FOR(i, m, n) for(int i = (m); i < (n); i++)
#define INF 1e9
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << ": " << x << endl;

using namespace std;
typedef long long ll;

signed main() {
  string n;
  cin >> n;
  if(n[0] == '7' || n[1] == '7' || n[2] == '7')
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}


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

int A[111];

int main() {
    int N, s = 0; scanf("%d",&N);
    for(int i=0; i<N; i++) {
        scanf("%d",&A[i]);
        s += A[i];
    }
    int mni = 0;
    for(int i=0; i<N; i++) {
        if(max(A[mni]*N - s, s - A[mni]*N) > max(A[i]*N - s, s - A[i]*N)) mni = i;
    }
    printf("%d",mni);
    return 0;
}


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

using namespace std;

typedef long long lli;
typedef vector<lli> vll;
typedef vector<bool> vbl;
typedef vector<vector<lli>> mat;
typedef vector<unordered_map<lli,lli>> graph;

lli h,w;
mat c;
lli a;

lli ans;

int main(){
  cin >> h >> w;
  c = mat(10,vll(10));
  for(lli i = 0;i < 10;i++){
    for(lli j = 0;j < 10;j++){
      cin >> c[i][j];
    }
  }
  for(lli i = 0;i < 10;i++){
    for(lli j = 0;j < 10;j++){
      for(lli k = 0;k < 10;k++){
        c[j][k] = min(c[j][k],c[j][i]+c[i][k]);
      }
    }
  }
  for(lli i = 0;i < h;i++){
    for(lli j = 0;j < w;j++){
      cin >> a;
      if(a < 0) continue;
      ans += c[a][1];
    }
  }
  cout << ans << endl;
}


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

namespace Atcoder_C_times3ordivide2
{
	class Program
	{
		static void Main(string[] args)
		{
			int N = int.Parse(Console.ReadLine());

			int[] num = new int[N];

			string[] buff = Console.ReadLine().Split(' ');

			for (int i = 0; i < buff.Length; i++) num[i] = int.Parse(buff[i]);

			long[] C = new long[N + 1];
			C[0] = 0;

			for(int i = 1; i <= N; i++)
			{
				if( num[i- 1] % 2 != 0)
				{
					C[i] = C[i - 1];
				}
				else
				{
					long count = 0;
					while( num[i-1] % 2 == 0)
					{
						num[i - 1] = num[i - 1] / 2;
						count++;
					}
					C[i] = C[i - 1] + count;
				}
			}

			Console.WriteLine(C[N]);
		}
	}
}


Measured memory_bytes: 13920
n,a,b=map(int,input().split())
mod=pow(10,9)+7

def pow_speed(x,n,mod):
    res = 1
    while n > 0:
        if n & 1 == 1:
            res *= x
        x *= x
        x%=mod
        n >>= 1
    return res

def comb(n,x):
    rec=1
    for i in range(n-x+1,n+1):
        rec=rec*i%mod
    rec2=1
    for i in range(1,x+1):
        rec2=rec2*i%mod
    rec2=pow_speed(rec2,mod-2,mod)
    return rec*rec2

print((pow_speed(2,n,mod)-comb(n,a)-comb(n,b)-1)%mod)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define endl '\n'
#define modulo 1000000007
//#define int int64_t
#define float double
#define PI acos(-1)
#define sinDegrees(x) sin((x) * PI / 180.0)
#define tanDegrees(x) tan((x) * PI / 180.0)
#define atanDegrees(x) atan(x)* 180.0 / PI
using namespace std;
int power(int x,int y,int m)
{
int temp;
if(y == 0)
return 1;
temp = (power(x, y/2,m))%m;
if (y%2 == 0)
return ((temp%m)*temp);
else
return ((x*temp%m)*temp%m)%m;
}
int inv(int x)
{
return (power(x,modulo-2,modulo))%modulo;
}
bool comp(int a,int b)
{
return a<b;
}
///Solution created by:Ahmadsm2005
int32_t main()
{
//freopen("output.txt","w", stdout);
//freopen("rect.in","r", stdin);
iostream::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin>>n;
puts(n%10==3?"bon":(n%10==2||n%10==4||n%10==5||n%10==7||n%10==9)?"hon":"pon");
return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define loop2(i, s, n, a) for (int i = int(s); i < int(n); i += a)
#define loop(i, s, n) loop2(i, s, n, 1)
#define rep(i, n) loop(i, 0, n)

#define pb push_back
#define all(in) in.begin(),in.end()

using ll = long long;
using ull = unsigned long long;
using namespace std;

bool judge(string s, char c){
    int n = s.length();
    bool ans = true;
    rep(i,n){
        if(s[i] != c){
            ans = false;
            break;
        }
    }
    return ans;
} //　文字列sが全てcか判定する

int main(){
    string s; cin >> s;

    int ans = 100;
    for(char c = 'a'; c <= 'z'; (char)c++){
        int count = 0;
        string data = s;
        while(!judge(data,c)){
            count++;
          	string next = "";
            int num = data.length();
            rep(i,num-1) {
              if(data[i] == c || data[i+1] == c) next += c;
        	  else next += data[i];
            }
          	data = next;
        }
        ans = min(ans, count);
    }

    cout << ans << endl;
}



Measured memory_bytes: 3564
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define vll vector<ll>
#define ub upper_bound
#define lb lower_bound
#define all(v) ((v).begin()),((v).end())
#define allr(v) ((v).rbegin()),((v).rend())
#define ff first
#define ss second
#define mp make_pair
#define pll pair<ll,ll> 
#define fo(i,n) for(ll i=0;i<n;i++)
#define foa(i,s,e) for(ll i=(s);i<e;i++)
#define fod(i,s,e) for(ll i= (s);i>=(e);i--)
ll mod1 = 1e9 + 7;
ll mod2 = 998244353;
ll mul(ll x,ll y){
    return (1ll* (x%mod1)*(y%mod1));
}
ll power(ll x,ll y){ll z=1;while(y>0){if(y%2)z=mul(z,x);x =mul(x,x) ;y/=2;}return z;}
//ll power(ll x,ll y){ll z=1;while(y>0){if(y%2)z=mul(z,x);x =mul(x,x) ;y/=2;}return z;}
ll gcd(ll a,ll b){if(a<b) return gcd(b,a);if(b==0) return a;return gcd(b,a%b);} 
ll min(ll a,ll b){if(a<b)return a;return b;}
ll max(ll a,ll b){if(a>b)return a;return b;}
ll n,k;

ll check(ll med,vll a){
    vll v = a;
    ll op = k;
    ll s = n/2;
    
    ll piv = med;
    foa(i,n/2,n){
        if(v[i]<piv){
            op -= (piv - v[i]);

            if(op<0)return 0;
        }
        else{
            piv = v[i];
        }
    }
    return 1;

}


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("inputf.txt" , "r" , stdin) ;
    freopen("outputf.txt" , "w" , stdout) ;
    //freopen("error.txt" , "w" , stderr) ;
    #endif
    
    ll a,b,c,k;
    cin>>a>>b>>c>>k;
    ll ans = 0;
    ans+=min(a,k);
    k-=a;
    if(k>0){
        k-= min(k,b);
    }
    if(k>0){
        ans-=min(k,c);
        k-=min(k,c);

    }
    cout<<ans<<endl;
    
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(int x){
  char f[10];
  int m=0, s=0;
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
int main(){
  int K, N;
  rd(N);
  rd(K);
  if(K==1){
    wt_L(0);
    wt_L('\n');
  }
  else{
    wt_L(N-K);
    wt_L('\n');
  }
  return 0;
}
// cLay varsion 20190609-2 [beta]

// --- original code ---
// {
//   int N, K;
//   rd(N, K);
//   wt(if[K==1,0,N-K]);
// }


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define finish(x) return cout << x << endl, 0
#define ll long long

int n;
vector <int> a, b;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n;
    a.resize(n);
    for(auto &i : a) cin >> i;
    b.resize(n);
    for(auto &i : b) cin >> i;
    auto check = [](int i){
        if(a[i] == b[i]) return false;
        int s = b[(i - 1 + n) % n] + b[(i + 1) % n];
        return b[i] >= s;
    };
    deque <int> ready;
    for(int i = 0 ; i < n ; i++){
        if(check(i)) ready.push_back(i);
    }
    ll ans = 0;
    while(ready.size()){
        int i = ready.front();
        ready.pop_front();
        int diff = b[i] - a[i];
        if(diff < 0) finish(-1);
        int s = b[(i - 1 + n) % n] + b[(i + 1) % n];
        int x = diff / s;
        ans += x;
        b[i] -= x * s;
        for(auto j : {(i - 1 + n) % n, (i + 1) % n}){
            if(check(j)) ready.push_back(j);
        }
    }
    for(int i = 0 ; i < n ; i++){
        if(a[i] != b[i]) finish(-1);
    }
    cout << ans << endl;
}


Measured memory_bytes: 2304
#include <iostream>
#include <vector>
#include <algorithm>
#define ll long long
using namespace std;
int main(){
    ll n,k;
    cin>>n>>k;
    vector<ll> h(n);
    for(ll i=0;i<h.size();i++){
        cin>>h[i];
    }
    sort(h.begin(),h.end());
    reverse(h.begin(),h.end());
    ll anum=0;
    for(ll i=k;i<h.size();i++){
        anum+=h[i];
    }
    cout<<anum<<endl;
    return 0;
}

Measured memory_bytes: 1792
#include<iostream>
using namespace std;
int main(){
	char c[3];
	cin>>c[0]>>c[1]>>c[2];
	int a=700;
	if(c[0]=='o')a+=100;
	if(c[1]=='o')a+=100;
	if(c[2]=='o')a+=100;
	cout<<a<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <numeric>
    
using namespace std;    
typedef long long ll;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

int main(){
    
    string s, t;
    cin >> s >> t;
    
    sort(all(s));
    sort(rall(t));
    if(s < t) cout << "Yes" << endl;
    else cout << "No" << endl;    
}


Measured memory_bytes: 256
'use strict';
process.stdin.on('data', function(chunk) {
  
  var inputs = chunk.toString().trim();
  var data = inputs.split(' ').map(Number);
  var a = data[0];
  var b = data[1];
  var c = data[2];
  var count = 0;
   
  for (var i = a; i < b + 1; i++) {
    if (c % i === 0) {
      count++;
    }
  }
  console.log(count);
 
 
});
process.stdin.resume();
process.stdin.setEncoding('utf8')

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

#define rep(i,n) for(ll i=0;i<(n);++i)
#define reps(i,n) for(ll i=1;i<=(n);++i)
using ll = long long;
using str = string;
constexpr long long INF = (1LL<<60);
constexpr long long MOD = (1e9+7);
template<class T>inline T gcd(T a,T b){if(b==0)return a; return(gcd(b,a%b));}
template<class T>inline T lcm(T a,T b){return a/gcd(a,b)*b;}
template<class T>inline bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
inline void dump(){cout<<endl;}
template<class Head,class... Tail>inline void dump(Head&& head, Tail&&... tail){cout<<head<<", ";dump(forward<Tail>(tail)...);}
template<typename T>inline istream &operator>>(istream&input,vector<T>&v){for(auto &elemnt:v)input>>elemnt;return input;}

main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);
  
  ll n;
  cin>>n;
  vector<long double> x(n),y(n);
  rep(i,n)cin>>x[i]>>y[i];

  vector<pair<long double,ll>> a(n);
  long double sx=0.0,sy=0.0;
  rep(i,n){
    sx+=x[i];
    sy+=y[i];
    a[i].first=atan2(x[i],y[i]);
    a[i].second=i;
  }
  sort(a.begin(),a.end());

  long double ans=0.0;
  rep(i,n)rep(j,n){
    long double xx=0.0,yy=0.0;
    for(ll k=i;k<=j;++k){
      xx+=x[a[k].second];
      yy+=y[a[k].second];
    }
    long double tmp=sqrt(xx*xx+yy*yy);
    long double _x=sx-xx,_y=sy-yy;
    chmax(tmp,sqrt(_x*_x+_y*_y));
    chmax(ans,tmp);
  }

  cout<<(ans)<<endl;
  
  
}


Measured memory_bytes: 256
#include <cstring>
#include <cstdio>
#include <vector>
#define pb push_back
int lst[200005], to[2000005], pre[2000005], cap[2000005], tot;
int dep[200005], que[200005], fst[200005];
inline void add_edge(int u, int v, int _cap)
{
	// printf("%d %d %d\n", u, v, _cap);
	auto add = [&] (int x, int y, int c)
	{
		to[tot] = y;
		pre[tot] = lst[x];
		cap[tot] = c;
		lst[x] = tot++;
	};
	add(u, v, _cap);
	add(v, u, 0);
}
bool bfs(int s, int t)
{
	memset(dep, -1, sizeof(dep));
	dep[s] = 0;
	int he = 0, ta = 0;
	que[ta++] = s;
	while (he < ta)
	{
		int u = que[he++];
		for (int i = lst[u]; ~i; i = pre[i])
		{
			if (cap[i] && dep[to[i]] == -1)
			{
				dep[to[i]] = dep[u] + 1;
				que[ta++] = to[i];
			}
		}
	}
	return ~dep[t];
}
int dfs(int u, int t, int rem)
{
	if (u == t)
		return rem;
	int ans = 0;
	for (int i = fst[u]; ~i; i = pre[i])
	{
		if (cap[i] && dep[to[i]] == dep[u] + 1)
		{
			int res = dfs(to[i], t, std::min(rem - ans, cap[i]));
			cap[i] -= res;
			cap[i ^ 1] += res;
			if (cap[i])
				fst[u] = i;
			ans += res;
			if (ans == rem)
				return ans;
		}
	}
	if (!ans)
		dep[u] = -1;
	return ans;
}
inline int dinic(int s, int t)
{
	int ans = 0;
	while (bfs(s, t))
	{
		memcpy(fst, lst, sizeof(lst));
		ans += dfs(s, t, 1e9);
	}
	return ans;
}
std::vector<int> vec[200005], bel[200005];
int fa[200005], rep[200005];
bool vis[200005];
int add(int u)
{
	int res = 1;
	vis[u] = true;
	for (int x : bel[u])
	{
		if (!vis[rep[x]])
		{
			fa[x] = u;
			res += add(rep[x]);
		}
	}
	return res;
}
int main()
{
	// freopen("AGC029-F.in", "r", stdin);
	memset(lst, -1, sizeof(lst));
	int n;
	scanf("%d", &n);
	for (int i = 0; i + 1 < n; i++)
	{
		int len;
		scanf("%d", &len);
		while (len--)
		{
			int u;
			scanf("%d", &u);
			if (--u)
				add_edge(i + 1, u + n - 1, 1);
			vec[i].pb(u);
			bel[u].pb(i);
		}
		add_edge(0, i + 1, 1);
		add_edge(i + n, n + n, 1);
	}
	if (dinic(0, n + n) != n - 1)
	{
		puts("-1");
		return 0;
	}
	for (int i = 1; i < n; i++)
	{
		for (int j = lst[i]; ~j; j = pre[j])
		{
			if (to[j] && !cap[j])
				rep[i - 1] = to[j] - n + 1;
		}
	}
	if (add(0) != n)
	{
		puts("-1");
		return 0;
	}
	for (int i = 0; i + 1 < n; i++)
		printf("%d %d\n", fa[i] + 1, rep[i] + 1);
	return 0;
}


Measured memory_bytes: 36736
#include<iostream>
#include<algorithm>
#include<iomanip>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include <cstdio>
#include<map>
#include<string>
#include<assert.h>
#include<unordered_map>
#include <cstring>//memset();
#define Amr_Abdelazim ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define pp pop_back
#define ll long long
#define ld long double
#define pll pair<ll,ll> 
#define vll vector<ll> 
#define vvll vector<vector<ll> >  
#define vpll vector<pair<ll,ll> > 
#define all(v) v.begin(),v.end()
#define rep(i,n)   for(int i=0;i<n;i++)
#define repp(s,i,n)   for(int i=s;i<n;i++)
#define print(v) for(auto i:v)cout<<i<<" ";cout<<"\n"; 
#define mkp make_pair
#define clr(ar,v) memset(ar,v,sizeof(ar));
#define TC ll t;cin>>t;while(t--)
#define in_vec ll n;cin>>n;vll v(n);rep(i,n)cin >> v[i];
#define EPS 1e-9
using namespace std;
const int mod = 1000000007;
const int N = 1000005;
class cmp{
public:
	bool operator() (pair<ll, pll> &A, pair<ll, pll> &B){
		return A > B;
	}
};
bool by_sec(pll &A, pll &B){
	return A.second < B.second;
}
bool is(pll a, pll b){
	return !((a.first > b.second&&a.second > b.second) || (a.first < b.first&&a.second < b.first));
}
ld dist(pll p1, pll p2){
	return (ld)sqrt((ld)(p1.first - p2.first)*(p1.first - p2.first) + (ld)(p1.second - p2.second)*(p1.second - p2.second));
}
string a, b;
ll vis[3000 + 9][3000 + 9];
void lcs(ll m, ll n)
{
	for (int i = 1; i <= m; i++)
	{
		for (int j = 1; j <= n; j++)
		{
			if (a[i - 1] == b[j - 1])
				vis[i][j] = vis[i - 1][j - 1] + 1;

			else
				vis[i][j] = max(vis[i - 1][j], vis[i][j - 1]);
		}
	}
}
string ans(ll m, ll n)
{
	if (m == 0 || n == 0)
		return string("");
	if (a[m - 1] == b[n - 1])	
		return ans(m - 1, n - 1) + a[m - 1];	
	if (vis[m - 1][n] > vis[m][n - 1])
		return ans( m - 1, n);
	else
		return ans(m, n - 1);
}
int main()
{
	Amr_Abdelazim
		//clr(vis, -1);
	cin >> a >> b;
	lcs(a.size(),b.size()); 
	string s = ans(a.size(),b.size());
	cout << s << "\n";
	return 0;
}

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

int main(){
  int x, n;
  cin >> x >> n;
  vector<int> vec(n);
  for(int i=0; i<n; ++i) cin >> vec[i];
  int ans1 = x, ans2 = x;
  while(1){
    bool ansis = false;
    for(int i=0; i<n; ++i){
      if(vec[i] == ans1) ansis = true;
    }
    if(ansis) --ans1;
    else{
      cout << ans1 << endl;
      return 0;
    }
    ansis = false;
    for(int i=0; i<n; ++i){
      if(vec[i] == ans2) ansis = true;
    }
    if(ansis) ++ans2;
    else{
      cout << ans2 << endl;
      return 0;
    }
  }
}

Measured memory_bytes: 3628
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <cstdio>
#include <string.h>
#define rep(i,n) for (int i = 0; i < (int)n; i++)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<pi, pi> pp;
typedef pair<ll, ll> pl;
double PI = 3.1415926535897932;
const double EPS = 1e-9;
const ll MOD = 1000000007;
const int inf = 1 << 30;
const ll linf = 1LL << 60;

int main() {
    int n;
    cin >> n;
    cout << n*n*n << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int m, n_min, n_max;
int P[200];

int main(void) {
	while (scanf("%d%d%d", &m, &n_min, &n_max) == 3 && (m | n_min | n_max) != 0) {
		int i;
		int answer = 0, answer_gap = -1;
		for (i = 0; i < m; i++) {
			if (scanf("%d", &P[i]) != 1) return 1;
		}
		for (i = n_min - 1; i < n_max; i++) {
			int gap = P[i] - P[i + 1];
			if (gap >= answer_gap) {
				answer = i + 1;
				answer_gap = gap;
			}
		}
		printf("%d\n", answer);
	}
	return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<ll,ll>;
const ll mod = 1e9+7;
#define ALL(x) (x).begin(),(x).end()
#define pow(x,y) modpow(x,y)
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define REPS(i,n) for(ll (i)=1;(i)<=(n);(i)++)
#define RREP(i,n) for(ll (i)=(n-1);(i)>=0;(i)--)
#define RREPS(i,n) for(ll (i)=(n);(i)>0;(i)--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());

template <class T = int>T in(){
    T x;
    cin >> x;
    return (x);
}

template<class T> inline void chmin(T& a, T b){
    if (a > b){
        a = b;
    }
}

template<class T> inline void chmax(T& a, T b){
    if (a < b){
        a = b;
    }
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(10);
    bool Y = 0;
    int N = in();
    REP(i,N){
        if(in<char>() == 'Y')Y = 1;
    }
    cout << (Y ? "Four" : "Three") << "\n";
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

long long Fact(int n);
int main(){
  int n;
  cin>>n;
  cout<<Fact(n)<<endl;
  return 0;
}

long long Fact(int n){
  long long fact=1;
  for( int i=1;i<=n;i++ ){
    fact*=i;
  }
  return fact;
}

Measured memory_bytes: 1156
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define pii pair<int,int>
const long long MOD=1000000007;

int main(){
    int a;
    string s;
    cin>>a>>s;
    if(a>=3200) cout<<s<<endl;
    else cout<<"red"<<endl;
    return 0;
}

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

class Main{       
   public static void main(String[] args){

      Scanner sc = new Scanner(System.in);
    
      int N = sc.nextInt();
      
      String S = String.valueOf(N);
      
      if(S.charAt(0) == S.charAt(2)){
          System.out.println("Yes");
          return;
      }else{
          System.out.println("No");          
          return;
      }
      
   }
}
        

Measured memory_bytes: 21972
n=int(input())
t,a=map(int,input().split())
h=list(map(int,input().split()))
min=10000 #  aとの差
ans=0

for i in range(n):
    temp=t-h[i]*0.006
    #print(temp)
    c=abs(temp-a)
    if c<min:
        ans=i+1
        min=c
        
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cmath>
using namespace std;
using ll = long long;

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

    int n;
    string s;
    cin >> n >> s;

    int r = 0;
    char c = 0;
    for (int i = 0; i < n; i++) {
        if (s[i] != c) r++;
        c = s[i];
    }

    cout << r << endl;

    return 0;
}

Measured memory_bytes: 512
import java.util.*;
public class Main {
  public static void main(String[] args){

    Scanner sc = new Scanner(System.in);
    int A = sc.nextInt();
    int B = sc.nextInt();
    int C = sc.nextInt();

    if ((A <= C) && (B >= C)) {
      System.out.println("Yes");  
    } else {
      System.out.println("No");
    }

  }
}

Measured memory_bytes: 21332
#include <stdio.h>
#include <atcoder/dsu>

int main(){
  int N, Q;
  int t, u, v;
  scanf("%d %d", &N, &Q);
  atcoder::dsu d(N);

  for(int i = 0; i < Q; i++){
    scanf("%d %d %d", &t, &u, &v);
    if(t==0){
      d.merge(u, v);
    } else {
      if(d.same(u, v)){
        printf("1\n");
      }else{
        printf("0\n");
      }
    }
  }

  return 0;
}


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

using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0;i<(int)(n);i++)

int main(){
    int n,m;
    cin>>n>>m;
    int a[104]={};
    ll sum=0;
    REP(i,n){
        cin>>a[i];
        sum+=a[i];
    }
    int count=0;
    REP(i,n){
        if(sum<=4LL*m*a[i])count++;
    }
    if(count>=m)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


Measured memory_bytes: 256
A,B,C = map(int,input().split())
flag = False

if(A == B and A != C):
  flag = True
  print('Yes')
elif(A == C and A != B):
  flag = True
  print('Yes')
elif(B == C and A != B):
  flag = True
  print('Yes')
else:
  print('No')

Measured memory_bytes: 38384
#include<iostream>
#include<vector>
using namespace std;
int main(){
  int n;
  cin>>n;
  vector<int> cost(n);
  vector<int> value(n);
  for(int i=0; i<n; i++)
    cin>>value[i];
  
  for(int i=0; i<n; i++)
    cin>>cost[i];

  int sum=0;
  int diff;
  for(int i=0; i<n; i++){
    diff = value[i] - cost[i];
    if(diff>0){
      sum+=diff;
    }
  }

  cout<<sum<<endl;
  return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e3+5;

int main(){	
	int n,k,ans = 0;
	scanf("%d%d",&n,&k);
	while(n){
		n /= k;
		ans++;
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 256