akhauriyash/Code-Regression huggingface dataset:
//Author: master19
#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 ll long long int
#define ff first 
#define ss second 
#define pb push_back
#define endl "\n"
#define PI acos(-1.0)
#define mod 1000000007LL // fixed...
#define modd 1000000007LL // Can be changed for global use
#define yes cout << "YES\n"
#define no cout << "NO\n"
#define Yes cout << "Yes\n"
#define No cout << "No\n"
#define all(arr) arr.begin(),arr.end()
#define x(arr) arr.begin(),arr.end()
#define ulli unsigned long long int
#define assign(x,val) memset(x,val,sizeof(x))
#define prec(val, dig) fixed << setprecision(dig) << val
#define Sort(arr) sort(arr.begin(), arr.end())
#define lower(str) transform(str.begin(), str.end(), str.begin(), ::tolower);
#define upper(str) transform(str.begin(), str.end(), str.begin(), ::toupper);
#define crap ios_base :: sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define get(arr, num) vector < ll > arr(num); for(int i=0; i<num; i++)cin >> arr[i];
#define get_set(arr, num, st, type) set < type > st; for(int i=0; i<num; i++) st.insert(arr[i]);
#define put(arr, num) for(int i=0; i<num; i++)cout << arr[i] << " "; cout << endl;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update > new_ds; 
ll lets_do_it();
// pi xy[] = {{-1, 0}, {1, 0} , {0, -1}, {0, 1}};
// pi dig[] = {{-1, -1}, {-1, 1}, {1, 1}, {1, -1}};
// bool isValid(ll x, ll y, ll row, ll col){
//     return ((x>=0) && (y >=0)  && (x < row) && (y < col));
// }
int main(int argc, const char** argv) {
    crap;
    ll test = 1;
    // cin >> test;
    for(int loop=0; loop<test; loop++){
        // cout << "Case #" << (loop+1) << ": "; 
        lets_do_it();
    }
    return 0;
}
ll lets_do_it(){
    // Your code goes by here !!
    ll left, right, num;
    cin >> left >> right >> num;
    ll first = left/num;
    ll second = right/num;
    if(left%num == 0){
        cout << second - first + 1 << endl;
    }else{
        cout << second - (first) << endl;
    }





























    return 0;
}


Measured memory_bytes: 3652
def SieveOfEratosthenes(n):
    f = [True] * n
    for i in range(2, int(n**0.5)+1):
        if f[i]:
            for j in range(i*i, n, i):
                f[j] = False
    return f

MAX = 10 ** 5 + 6
pn = SieveOfEratosthenes(MAX)
C = [0] * MAX
for i in range(3, MAX, 2):
    if pn[i] and pn[(i+1)//2]:
        C[i] += 1
    C[i-1] += C[i-2]
    C[i] += C[i-1]

Q = int(input())
ans = [0] * Q
for i in range(Q):
    l, r = map(int, input().split())
    ans[i] = C[r] - C[l-1]
for a in ans:
    print(a)

Measured memory_bytes: 11536
#include<bits/stdc++.h>
#define mod 1000000007
#define INF 1000000000000000005
#define F first
#define S second
#define LB lower_bound
#define UB upper_bound
#define vc vector
#define vll vector<long long>
#define pll pair<long long,long long> 
#define pb push_back
#define all(v) v.begin(),v.end()
#define T ll test;cin>>test; while(test--)
#define rep(i,a,n) for(ll i=a;i<(long long)n;++i)
#define repr(i,n,a) for(ll i=n;i>(long long)a;--i)
#define MAX 1000005
#define sz(x) (ll)x.size()
#define ins insert
#define mp make_pair
#define int  long long
typedef  long long ll;
typedef long double ld;
using namespace std;

inline int add(int a,int b){a+=b;if(a>=mod)a-=mod;return a;}
inline int sub(int a,int b){a-=b;if(a<0)a+=mod;return a;}
inline int mul(int a,int b){return (a*1ll*b)%mod;}
inline int power(int a,int b){int rt=1;while(b>0){if(b&1)rt=mul(rt,a);a=mul(a,a);b>>=1;}return rt;}
inline int inv(int a){return power(a,mod-2);}
ll dp[MAX];
ll n,k;


signed  main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);
	cin>>n>>k;
	memset(dp,0,sizeof(dp));
	ll ar[n];
	rep(i,0,n)
	{
	 cin>>ar[i];	
	 } 
	 dp[0]=0;
	 rep(i,1,k+1)
	 {
	 	for(auto j:ar)
	 	{
	 		if(i-j>=0 && dp[i-j]==0)
	 		dp[i]=1;
		 }
	 }
	if(dp[k])	 cout<<"First\n";
	else cout<<"Second\n";
	
}
   

Measured memory_bytes: 11464
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) FOR(i, 0, (n))
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define LAR(a, b) ((a)=max((a),(b)))
#define SML(a, b) ((a)=min((a),(b)))
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vl = vector<ll>;
using pii = pair<int, int>;
using vpii = vector<pair<int, int>>;
template<typename T>
using pque = priority_queue<T, vector<T>, greater<T>>;
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define ALL(a) (a).begin(), (a).end()
#ifdef LOCAL_DEBUG
#define DEBUG(...) printf(__VA_ARGS__)
#else
#define DEBUG(...)
#endif

#define N 212345
int p[N], q[N];

int main(){
	int a, b, m; scanf("%d%d%d", &a, &b, &m);
	REP(i, a) scanf("%d", p+i);
	REP(i, b) scanf("%d", q+i);
	int c = INT_MAX; REP(i, a) SML(c, p[i]);
	int d = INT_MAX; REP(i, b) SML(d, q[i]);
	int ans = c + d;
	REP(i, m){
		int x, y, z; scanf("%d%d%d", &x, &y, &z);
		SML(ans, p[x-1] + q[y-1] - z);
	}
	printf("%d\n", ans);
}


Measured memory_bytes: 1024
import java.util.*;

class Main {
	Scanner sc = new Scanner(System.in);

	public void run() {
		ArrayList<P> plist=new ArrayList<P>();
		while(sc.hasNext()){
			String[] str=sc.next().split(",");
			plist.add(new P(Double.parseDouble(str[0]),Double.parseDouble(str[1])));
		}
		P o1=plist.get(0);
		plist.remove(0);
		P prev=plist.get(0);
		plist.remove(0);
		double S=0;
		for(P p:plist){
			S+=getS(o1,prev,p);
			prev=p;
		}
		ln(S);
	}

	public double getS(P a,P b,P c){
		double sc=a.s(b).norm();
		double sa=b.s(c).norm();
		double sb=c.s(a).norm();
		double s=(sa+sb+sc)/2;
		return Math.sqrt(s*(s-sa)*(s-sb)*(s-sc));
	}

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

	public static void pr(Object o) {
		System.out.print(o);
	}

	public static void ln(Object o) {
		System.out.println(o);
	}

	public static void ln() {
		System.out.println();
	}
}

class P implements Comparable<P>{
	double x;
	double y;
	P(double _x,double _y){
		x=_x;
		y=_y;
	}

	public static  final P Xunit=new P(1,0);
	public static  final P Yunit=new P(0,1);

	//:問題によって変える。
	@Override
	public int compareTo(P o) {
		if(x>o.x){
			return 1;
		}else if(x<o.x){
			return -1;
		}
		return y>o.y?1:y<o.y?-1:0;
	}

	public static double dot(P a,P b){
			return a.x*b.x+a.y*b.y;
	}
	public static  double cross(P a,P b){
		return a.x*b.y-a.y*b.x;
	}
	public static boolean isParallel(P a1,P a2,P b1,P b2){
		return Math.abs(cross(a2.s(a1),b2.s(b1)))<Double.MIN_NORMAL;
	}
	public static boolean isVertical(P a1,P a2,P b1,P b2){
		return Math.abs(dot(a2.s(a1),b2.s(b1)))<Double.MIN_NORMAL;
	}

	public P a(P a){
		return new P(x+a.x,y+a.y);
	}
	public P s(P a){
		return new P(x-a.x,y-a.y);
	}

	public double norm(){
		return Math.sqrt(x*x+y*y);
	}
	public double arg(){
		double s=Math.acos(x/norm());
		return y>0?s:2*Math.PI-s;
	}

	public P rotate(double t){
		return new P(Math.cos(t)*this.x-Math.sin(t)*this.y,Math.sin(t)*this.x+Math.cos(t)*this.y);
	}

	public static int ccw(P a,P b,P c){
		if(P.cross(b.s(a),c.s(a))>Double.MIN_NORMAL){
			return 1;
		}
		if(P.cross(b.s(a),c.s(a))<-Double.MIN_NORMAL){
			return -1;
		}
		if(P.dot(b,c)<-Double.MIN_NORMAL)return 2;
		if(b.norm()<c.norm()-Double.MIN_NORMAL)return -2;
		return 0;
	}

	@Override
	public boolean equals(Object obj) {
		if(obj instanceof P){
			P p=(P)obj;
			return x==p.x && y==p.y;
		}
		return false;
	}
	public String toString(){
		return "("+x+","+y+")";
	}
}

Measured memory_bytes: 12000
import bisect

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

ans = 0
L = sorted(L)

for i in range(N):
    for j in range(N):
        if i >= j:
            continue
        a = L[i]
        b = L[j]
        c = bisect.bisect_left(L,a+b)
        ans += c - j - 1

print(ans)

Measured memory_bytes: 9268
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int INF = 1 << 29;
const int MOD = 1000000007;

int main() {
    // 愚直に求める
    long long n, k;
    cin >> n >> k;

    double ans = 0.0;

    // 1 <= k <= nにおいてそれぞれ確率を求めて足す
    for (long long num = 1; num <= n; num++) {
        long long number = num;
        long long index = 0;
        // 2^i >= kとなるまでループする
        while (number < k) {
            index += 1;
            number *= 2;
        }

        double plus = 1.0 / (double)n * pow(0.5, index);
        ans += plus;
    }
    cout << fixed << setprecision(12) << ans << endl;
}


Measured memory_bytes: 4068
from itertools import accumulate


def divisors(n):
    ret = set()
    for i in range(1, int(n ** 0.5) + 1):
        d, m = divmod(n, i)
        if m == 0:
            ret.add(i)
            ret.add(d)
    return sorted(ret, reverse=True)


def solve(n, k, aaa):
    s = sum(aaa)
    div = divisors(s)
    for d in div:
        mods = [a % d for a in aaa]
        mods.sort()
        subs = [0] + list(accumulate(mods))
        adds = [0] + list(accumulate(d - p for p in reversed(mods)))
        adds.reverse()
        # print(d)
        # print(mods)
        # print(adds)
        for m, a in zip(subs, adds):
            if m == a:
                if m <= k:
                    return d
                break
            if m > a:
                break


n, k = list(map(int, input().split()))
aaa = list(map(int, input().split()))
print(solve(n, k, aaa))


Measured memory_bytes: 3188
#include<stdio.h>
#include<string.h>
#define anD &&
#define oR ||
#define max(a,b) ((a)>=(b))?(a):(b)
#define min(a,b) ((a)<=(b))?(a):(b)
#define rep(i,n) for((i)=0;(i)<(n);(i)++)

void swap(int *p, int *q) {
	int tmp;
	tmp = *p;
	*p = *q;
	*q = tmp;
}

int main() {
	int n;
	scanf("%d", &n);
	int i,j,a[101] = {};
	rep(i, n) {
		scanf("%d", &a[i]);
	}
	rep(i, n) {
		rep(j, n-1) {
			printf("%d ", a[j]);
		}
		printf("%d\n", a[n-1]);
		for (j = i + 1; j > 0; j--) {
			if (a[j - 1] > a[j]) swap(&a[j - 1], &a[j]);
		}

	}
	return 0;

}

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

int a[100];
int main(){
	int n;cin>>n;
	int s=0;
	rep(i,n){
		cin>>a[i];
		s+=a[i];
	}
	int m;cin>>m;
	rep(i,m){
		int p,x;cin>>p>>x;p--;
		cout<<s-(a[p]-x)<<endl;
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mod 998244353
#define ll long long
using namespace std;
struct node{
	string str;
}arr[101];
int n;
string ans;
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++) cin>>arr[i].str;
	ans = arr[1].str;
	for(int i=1;i<=n;i++)
	{
		int t = 0;
		for(int j=1;j<=n;j++)
		{
			if(arr[i].str==arr[j].str)
			{
				t++;
			}
		}
		if(t==2)
		{
			cout<<"No";
			return 0;
		}
	}
	for(int i=2;i<=n;i++)
	{
		if(arr[i].str[0]!=arr[i-1].str[arr[i-1].str.length()-1])
		{
			cout<<"No";
			return 0;
		}
	}
	cout<<"Yes";
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main()
{
    int l,a,b,c,sum=0,temp=0,p=0,er=0,sp=0,o=0;
    char ch[100000];
    
    gets(ch);
    l=strlen(ch);
    int i,ty=0,se=0,re=0;
    if(ch[0]=='A')
    {
        sum=1;
    }
    
    for(i=2;i<l-1;i++)
    {
       if(ch[i]=='C')
        {
            temp++;
        }
    
    }
    if(temp==1)
    {
        er=1;
    
    }
    for(i=0;i<l;i++)
    {
        if(ch[i]>='A'&&ch[i]<='Z'&&ch[i]!='A'&&ch[i]!='C')
        {
            ty++;
        }
    }
    if(ty==0)
    {
        sp=1;
    }
    
    if(sp==1&&er==1&&sum==1)
    {
        printf("AC\n");
    }
    else
    {
        printf("WA\n");
    }
}

Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int main() {
  int a,b,c,x,ans=0;
  cin >> a >> b >> c >> x;
  for(int i=0; i<=a; i++) {
    for(int j=0; j<=b; j++) {
      for(int k=0; k<=c; k++) {
        if(500*i+100*j+50*k==x) {
          ans++;
        }
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<cstdio> 
#include<algorithm>
#include<cstring>
#include<cmath>
#include<set>
#include<map>
using namespace std;
#define fo(i,j,k) for(i=j;i<=k;i++)
#define fd(i,j,k) for(i=j;i>=k;i--)
#define cmax(a,b) (a=(a>b)?a:b)
#define cmin(a,b) (a=(a<b)?a:b)
typedef long long ll;
const int N=1e6+5,M=2e6+5,mo=1e9+7;
ll f[N],fac[N],i,n,K,j,ans;
ll ksm(ll x,ll y)
{
	ll ret=1;
	while (y)
	{
		if (y&1) ret=ret*x%mo;
		y>>=1;
		x=x*x%mo;
	}
	return ret;
}
void predo()
{
	fo(i,1,trunc(sqrt(n)))
	if (n%i==0)
	{
		fac[++fac[0]]=i;
		if (i*i!=n) fac[++fac[0]]=n/i;
	}
	sort(fac+1,fac+1+fac[0]);
}
int main()
{
	scanf("%lld %lld",&n,&K);
	predo();
	fo(i,1,fac[0])
	{
		f[i]=ksm(K,(fac[i]+1)/2);
		fo(j,1,i-1)
			if (fac[i]%fac[j]==0)
				(f[i]-=f[j])%=mo;
		if (fac[i]%2)
			(ans+=f[i]*fac[i])%=mo;
		else (ans+=f[i]*fac[i]/2)%=mo;
	}
	printf("%lld\n",(ans+mo)%mo);
}

Measured memory_bytes: 2304
#include<bits/stdc++.h>
#define watch(x) cout<<(#x)<<" is "<<(x)<<endl
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define pb push_back
#define pq priority_queue
#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define elif else if

using namespace std;
using ll=long long;
using ull=unsigned long long;
using ld=long double;
using pll=pair<ll,ll>;
using pss=pair<string,string>;
using pdd=pair<ld,ld>;
using graph=vector<vector<int>>;
using wgraph=vector<vector<pll>>;

const ll MOD=1000000007;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int ex[8]={1,1,0,-1,-1,-1,0,1};
const int ey[8]={0,1,1,1,0,-1,-1,-1};
const ld E=1e-9;

template<class T> void chmin(T &a, T b){a=min(a, b);}
template<class T> void chmax(T &a, T b){a=max(a, b);}

ll abs1(ll a){if(a>=0)return a;else return -a;}
ll pow1(ll a,ll b,ll p=LLONG_MAX){
  ll ret=1;
  while(b!=0){
    if((b&1)==1)ret*=a;a*=a;
    if(a>=p)a%=p;if(ret>=p)ret%=p;
    b=b>>1;
  }
  return ret;
}
int digit(ll a,ll b=10){int i=0;while(a!=0){a/=b;i++;}return i;}
ll gcd1(ll a,ll b){
  if(a==0 || b==0)return 0;
  ll n;while(a%b!=0){n=a%b;a=b;b=n;}return b;
}
ll solveLinear(ll n,ll m,ll c){
  if(n==0 && m==0)return 0;
  ll a[100],b[100];a[0]=n;b[0]=m;int i=1;
  while(b[i-1]!=0){a[i]=b[i-1];b[i]=a[i-1]%b[i-1];i++;}
  n=i;if(c%a[n-1]!=0)return 0;
  ll x=c/a[n-1],y=0;
  for(i=1;i<n;i++){ll cnt=x;x=y;y=cnt-(a[n-i-1]/b[n-i-1])*y;}
  return x;
}
ll modRev(ll a,ll p=MOD){
  a%=p;ll n=solveLinear(a,p,1);
  n%=p;if(n<0)return n+p;
  return n;
}
ll fact(ll n,ll p=MOD){
  if(n<0)return 0;
  ll ret=1;for(int i=1;i<=n;i++){ret=ret*i;if(ret>=p)ret%=p;}
  return ret;
}
ll perm(ll n,ll k,ll p=MOD){
  if(n<0 || k<0 || n<k)return 0;
  ll ret=1;rep(i,k){ret=ret*(n-i);if(ret>=p)ret%=p;}
  return ret;
}
ll binom(ll n,ll k,ll p=MOD){
  return (perm(n,k,p)*modRev(fact(k)))%p;
}
int bis(vector<int> v,int key){
  int left=-1,right=v.size();
  while(abs1(right-left)>1){
    int mid=left+(right-left)/2;
    if(v[mid]<=key)left=mid;
    else right=mid;
  }
  return left;
}

int main(){
  ll i,j,cnt=0;
  ll n,m;
  cin>>n>>m;
  ll g=1;
  vector<ll> a(n);
  for(i=0;i<n;i++){
      cin>>a[i];
      a[i]/=2;
      g=g/gcd1(g,a[i])*a[i];
      if(g>m){
          cout<<0<<endl;
          return 0;
      }
  }
  for(i=0;i<n;i++){
      if((g/a[i])%2==0){
          cout<<0<<endl;
          return 0;
      }
  }
  cout<<(m/g+1)/2<<endl;
}


Measured memory_bytes: 1024
#include <algorithm>
#include <cstdint>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <cfloat>

using namespace std;

using lint=int64_t;
using uint=uint32_t;
using ulint=uint64_t;

template<class T>
using vector2d=vector<vector<T>>;

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

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

template <class T>
void OutVec(const vector<T>& vec){
  for(int i = 0; i < vec.size() - 1; ++i){
    cout<<vec[i]<<" ";
  }
  cout<<vec.back()<<endl;
}

template <class T>
void OutVec2d(const vector2d<T>& vec){
  for(auto v:vec){
    OutVec(v);
  }
}

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

  lint n,p;
  cin>>n>>p;

  string s;
  cin>>s;
  lint result=0;

  if(p==2){
    for(int i=0;i<n;i++){
      if((s[i]-'0')%2==0){
        result+=i+1;
      }
    }

  }else if(p==5){
    for(int i=0;i<n;i++){
      if((s[i]-'0')%5==0){
        result+=i+1;
      }
    }
  }else{
    vector<lint> count(p);
    count[0]++;
    lint prev_mod=(s.back()-'0')%p;
    count[prev_mod]++;
    lint ten_mod=10;
    for(int i=n-2;i>=0;i--){
      lint this_mod=(prev_mod+(s[i]-'0')*ten_mod)%p;
      count[this_mod]++;
      prev_mod=this_mod;
      ten_mod*=10;
      ten_mod%=p;
    }
    for(int i=0;i<p;i++){
      result+=(count[i]*(count[i]-1))/2;
    }
  }


  cout<<result<<endl;




  return 0;
}




Measured memory_bytes: 892
#include <iostream>
#include <cstdio>
#include <string>

using namespace std;

int main(){
	while(1){
		string s;
		int m;
		
		cin >> s;
		if(s == "-") break;
		cin >> m;
		for(int i=0; i<m; ++i){
			int a;
			cin >> a;
			
			string add = s.substr(0,a);
			s = s+add;
			s = s.substr(a, s.size());
		}
		
		cout << s << endl;
	}
	return 0;
}



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

#define rep(i,a,b) for(int i=a;i<(b);i++)
#define trav(a,x) for(auto & a :x)
#define all(x) begin(x),end(x)
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define vpii vector<pii>
#define F first
#define S second

typedef long long ll;
typedef vector<int> vi;


const int M=1e9+7;



int main() 
{   
    ios::sync_with_stdio(0);
	cin.tie(0);
  
ll n;
cin>>n;

string res = "";
int index;
	while (n > 0)
	{
		
		 index = (n - 1) % 26;
		res = char(index + 'a') + res;
		n = (n - 1) / 26;
	}
	
	cout<<res;
 
  return 0;
}


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

using namespace std;

int n, u, v;

int dist[2][100002];
vector<int>G[100002];

void dfs (int nod, int p, int f) {
  for (auto it : G[nod])
    if (it != p) {
      dist[f][it] = dist[f][nod] + 1;
      dfs(it, nod, f);
    }
}

int main()
{
  cin >> n >> u >> v;
  for (int i = 1; i < n; i++) {
    int a, b;
    cin >> a >> b;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  dfs(u, -1, 0);
  dfs(v, -1, 1);
  int ans = 0;
  for (int i = 1; i <= n; i++)
    if (dist[0][i] < dist[1][i])
      ans = max(ans, dist[1][i] - 1);
  cout << ans;
  return 0;
}


Measured memory_bytes: 12928
import java.util.Scanner;
public class Main {
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int input = scan.nextInt();
        int A,B,C,D;

        D = input%10;
        input/=10;
        C = input%10;
        input/=10;
        B = input%10;
        input/=10;
        A = input%10;
        input/=10;

        if(A+B+C+D==7) {
            System.out.println(A + "+" + B + "+" + C + "+" + D +"=7");
        }
        else if(A+B+C-D==7){
            System.out.println(A + "+" + B + "+" + C + "-" +D + "=7");
        }
        else if(A+B-C+D==7){
            System.out.println(A + "+" + B + "-" + C + "+" + D + "=7");
        }
        else if(A+B-C-D==7){
            System.out.println(A + "+" + B + "-" + C + "-" + D + "=7");
        }
        else if(A-B+C+D==7){
            System.out.println(A + "-" + B + "+" + C + "+" + D + "=7");
        }
        else if(A-B+C-D==7){
            System.out.println(A + "-" + B + "+" + C + "-" + D + "=7");
        }
        else if(A-B-C+D==7){
            System.out.println(A + "-" + B + "-" + C + "+" + D + "=7");
        }
        else if(A-B-C-D==7){
            System.out.println(A + "-" + B + "-" + C + "-" + D + "=7");
        }


    }
}


Measured memory_bytes: 23636
import sys
L, R = map(int, input().split())
ans = 10**10
for i in range(L,R):
  for j in range(i+1,R+1):
    tmp = (i*j) % 2019
    if tmp == 0:
      print(0)
      sys.exit()
    elif tmp < ans:
      ans = tmp
print(ans)

Measured memory_bytes: 3060
nm = gets.split " "
N = nm[0].to_i
M = nm[1].to_i
relays = []

M.times do
	s_g = gets.split " "
	start = s_g[0].to_i
	goal = s_g[1].to_i
	if start == 1
		relays << goal
	end
	if goal == N
		relays << start
	end
end

if relays.length != relays.uniq.length
	puts "POSSIBLE"
else
	puts "IMPOSSIBLE"
end

Measured memory_bytes: 17916
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a, b;
  string s;
  bool isOk = true;
  
  cin >> a >> b;
  cin >> s;
  
  if(s[a] != '-') isOk = false;
  
  for (int i = 0; i < a+b+1; i++)
  {
    //cout << i << "" << s[i] <<endl;
    
    if (i != a && s[i] == '-') isOk = isOk * 0;
    
    //cout << isOk[i] << endl;
  }
  
  //cout << endl << true << endl;
  
  if(isOk) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  return 0;
}

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

typedef long long ll;
const ll INF = 1e9, MOD = 1e9 + 7;
const double EPS = 1e-9, PI = 3.141592653589793;
#define REP(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define REPR(i,a,b) for(ll i=b;i>=a;i--)
#define repr(i,n) REPR(i,0,n)
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define fi first
#define se second
#define m_p make_pair

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

    ll X,Y;
    cin >> X >> Y;
    ll dx[] = {1,1,0,-1,-1,-1,0,1};
    ll dy[] = {0,1,1,1,0,-1,-1,-1};
    string board[51];
    rep(i,X) cin >> board[i];
    rep(i,X){
        rep(j,Y){
            if(board[i][j]=='.'){
                ll cnt = 0;
                rep(k,8){
                    ll x = i + dx[k];
                    ll y = j + dy[k];
                    if(x>=0 && x<X && y>=0 && y<Y && board[x][y]=='#') cnt++;
                }
                board[i][j] = '0' + cnt;
            }
        }
    }
    rep(i,X) cout << board[i] << "\n";
    return 0;
}

Measured memory_bytes: 256
/**
 * Created by hiramekun at 20:41 on 2019-10-19.
 */
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vb = vector<bool>;
using P = pair<ll, ll>;
template<typename T> using pq = priority_queue<T>;
template<typename T> using minpq = priority_queue<T, vector<T>, greater<T>>;
template<typename T, typename K> using ump = unordered_map<T, K>;
const ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll e5 = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = ll(n - 1); i >= 0; i--)
#define each(i, mp) for(auto& i:mp)
#define eb emplace_back
#define F first
#define S second
#define all(obj) (obj).begin(), (obj).end()

template<class T>
ostream &operator<<(ostream &out, const vector<T> &list) {
    ll n = list.size();
    rep(i, n) out << list[i] << ' ';
    return out;
}

template<class T>
istream &operator>>(istream &in, vector<T> &list) {
    ll n = list.size();
    rep(i, n) in >> list[i];
    return in;
}

template<class T>
ostream &operator<<(ostream &out, const vector<vector<T>> &list) {
    ll n = list.size();
    rep(i, n) out << list[i] << '\n';
    return out;
}

/* ------------- ANSWER ------------- */
/* ---------------------------------- */

void solve() {
    ll n;
    cin >> n;
    vl a(n);
    cin >> a;
    rep(i, n) {
        a[i]--;
    }

    ll now = 0;
    ll cnt = 0;
    while (n--) {
        cnt++;
        now = a[now];
        if (now == 1) {
            cout << cnt << '\n';
            return;
        }
    }
    cout << -1 << '\n';
}

int main() {
#ifdef MY_DEBUG
    while (true) {
#endif
        solve();
#ifdef MY_DEBUG
    }
#endif
    return 0;
}

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

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

  int a[n];
  int b[n];
  int c[n-1];

  rep (i, n) cin >> a[i];
  rep (i, n) cin >> b[i];
  rep (i, n-1) cin >> c[i];

  int ans = 0;
  for (int i = 0; i < n; i++) {
    ans += b[a[i]-1];
    if (i > 0 && a[i-1] + 1 == a[i])
      ans += c[a[i-1]-1];
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#pragma comment(linker, "/stack:200000000")
 #pragma GCC optimize("Ofast")
 #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
#define int long long 
using namespace std;

signed main()
{
     ios_base::sync_with_stdio(false);
     cin.tie(NULL);  
//  #ifndef ONLINE_JUDGE
//     freopen ("INPUT.txt" , "r" , stdin);
//     freopen ("OUTPUT.txt" , "w" , stdout);
//  #endif


// -------------------------------------Code starts here--------------------------------------------------------------------- 

    int n,m;
    cin>>n>>m;
    string s;
    cin>>s;
    reverse(s.begin(),s.end());
    set<int>ss;
    
    for(int i=0;i<=n;i++)
    {
        if(s[i]=='0')
            ss.insert(i);
    }

    int x=0;
    int cnt=0;
    vector<int>ans;
    while (x<n)
    {
        auto k=ss.lower_bound(x+1);
        if(k==ss.end())
        {
            cout<<-1;
            return 0;
        }
        auto j=ss.lower_bound(x+m+1);
        j--;

        if(*j>x)
        {
            ans.push_back(*j-x);
            x=*j;
            j++;
        }
        else
        {
            cout<<-1;
            return 0;
        }
    }
    reverse(ans.begin(),ans.end());
    for(auto i:ans)
        cout<<i<<" ";

    


// -------------------------------------Code ends here------------------------------------------------------
     clock_t clk;
 	clk = clock();
 
     clk = clock() - clk;
 	cerr << fixed << setprecision(6) << "Time: " << ((double)clk)/CLOCKS_PER_SEC << "\n";
 	return 0;
 }

Measured memory_bytes: 6216
X = list(str(input()))
n = len(X)

s = []
for x in X:
    if x == 'S':
        s.append(x)
    if x == 'T':
        if s:
            if s[-1] == 'S':
                s.pop()
            else:
                s.append(x)
        else:
            s.append(x)
print(len(s))


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

int main ()
{
  int n, m, y=0;
  
  //n, m, s, tの入力を受け取る。
  cin >> n;
  string vecs[n];
  for (int i=0; i<n; i++) cin >> vecs[i];
  
  cin >> m;
  string vect[m];
  for (int i=0; i<m; i++) cin >> vect[i];
  
  
  for (int i=0; i<n; i++) {
    int x=0;
    
    //vecsを検索して加点する
    for (int j=0; j<n; j++) {
      if (vecs[i] == vecs[j])	x++;
    }
    
    //vectを検索して減点する
    for (int j=0; j<m; j++) {
      if (vecs[i] == vect[j])	x--;
    }
    if (x>y)	y=x;
  }
  cout << y << endl;
}

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

using namespace std;

#define li long long int

const int N 	= 4e2 + 3;

int n;
int a[N];
li dp[N][N];
li dp2[N][N];

li go(int l, int r) {
	if (l > r) return 0;
	if (l == r) return dp[l][r] = a[l];
	if (dp[l][r] != -1) return dp[l][r];
	li ans = 1e13;
	for (int i = l; i < r; i++) {
		ans = min(ans, go(l, i) + go(i + 1, r));
	}
	return dp[l][r] = ans;
}

li retrace(int l, int r) {
	if (l == r) return 0;
	if (dp2[l][r] != -1) return dp2[l][r];
	li ans = 4e13;
	for (int i = l; i < r; i++) {
		if (dp[l][r] == dp[l][i] + dp[i + 1][r]) {
			ans = min(ans, retrace(l, i) + retrace(i + 1, r));
		}
	}
	return dp2[l][r] = ans + dp[l][r];
}

void solve() {
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	memset(dp, -1, sizeof(dp));
	go(1, n);
	memset(dp2, -1, sizeof(dp2));
	li ans = retrace(1, n);
	cout << ans;
}

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

Measured memory_bytes: 2816
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Solve s= new Solve();
		s.solve();
	}

}
class Solve{
	 Scanner sc = new Scanner(System.in) ;

	 void solve() {
		 long A = sc.nextLong();
		 long B = sc.nextLong();
		 long C = sc.nextLong();
		 long D = sc.nextLong();

		 long last_d=0;
		 long last_cd=0;
		 long last_c,first_c,first_d,first_cd;

		 long gcd=getGCD(C,D);
		 long lcm=getLCM(C,D,gcd);
		 if(B%C==0) {
			 last_c=B/C;
		 }else {
			 last_c=B/C;
		 }
		 if(A%C==0) {
			 first_c=A/C;
		 }else {
			 first_c=A/C+1;
		 }

		 if(B%D==0) {
			 last_d=B/D;
		 }else {
			 last_d=B/D;
		 }
		 if(A%D==0) {
			 first_d=A/D;
		 }else {
			 first_d=A/D+1;
		 }

		 if(B%lcm==0) {
			 last_cd=B/lcm;
		 }else {
			 last_cd=B/lcm;
		 }
		 if(A%lcm==0) {
			 first_cd=A/lcm;
		 }else {
			 first_cd=A/lcm+1;
		 }



		 long c=last_c-first_c+1;
		 long d=last_d-first_d+1;
		 long cd=last_cd-first_cd+1;
		 long res=c+d-cd;


	//	 System.out.println(last_d);


		 System.out.println(B-A+1-res);
	}
	 private static long getGCD(long a,long b) {

		 if(b==0) return a;
			 return getGCD(b,a%b);
	 }
	 private static long getLCM(long a,long b,long gcd) {

		 return a*b/gcd;

		 }
}

Measured memory_bytes: 22740
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
int main(){
  double xa, ya, ra, xb, yb, rb;
  int n, ans;
  cin >> n;
  for(int i = 0; i < n; i++){
    cin >> xa >> ya >> ra >> xb >> yb >> rb;
    double d = sqrt( (xb-xa)*(xb-xa) + (yb-ya)*(yb-ya) );
    double r = ra + rb;
     
    if(d > r)
        ans = 0;
    else if(d <= r && d >= fabs(ra - rb))
        ans = 1;
    else{
      if(max(ra,rb) == ra)
        ans = 2;
      else
        ans = -2;
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 3140
import java.util.Scanner;

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 < b && b < c) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}



Measured memory_bytes: 26284
/**
 *    author: moririn_cocoa       
**/

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
using namespace std;

int main(void) {
  
  int A;
  int B;
  
  cin >> A;
  cin >> B;
  
  cout << 6 - A - B << endl;
  
  return 0;
}

Measured memory_bytes: 3640
from collections import defaultdict
N=int(input())
A=[int(i) for i in input().split()]
dd=defaultdict(int)
for a in A:
    dd[a]+=1
#print(dd)
B=sorted(A,reverse=True)
ans=0
for x in B:
    #print(x)
    if dd.get(x,-1)==0:
        continue
    s=len(bin(x))-3
    if x==1<<s:
        t=dd.get(x,-1)
        if t!=-1:
            ans+=t//2
            dd[x]-=(t//2)*2
            #print(ans)
            #print(dd)
    else:
        s+=1
        #print((1<<s)-x)
        t=dd.get((1<<s)-x,-1)
        if t>=1:
            ans+=1
            dd[x]-=1
            dd[(1<<s)-x]-=1
            #print(ans)
            #print(dd)
print(ans)

Measured memory_bytes: 112468
S = input()

S1 = int(S[0:2])

S2 = int(S[2:])

flag1 = False
flag2 = False

if S1 >= 1 and S1 <= 12 :
    flag1 = True
if S2 >= 1 and S2 <= 12 :
    flag2 = True

if flag1 and flag2 :
    print('AMBIGUOUS')
elif (not flag1) and flag2 :
    print('YYMM')
elif flag1 and (not flag2) :
    print('MMYY')
else :
    print('NA')


Measured memory_bytes: 3060
#include<iostream>
#include<cstdio>
#include<cstring>
#define LL long long
using namespace std;
char S[404040];
LL ans;
int main(){
	scanf("%s",S+1);
	int n=strlen(S+1);
	LL Cur=0;
	for (int i=1;i<=n;i++)
		if (S[i]=='B') Cur++;
		else ans+=Cur;
	cout<<ans;
}

Measured memory_bytes: 384
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt(), B = sc.nextInt();
		if(A >= 13) System.out.println(B);
		else if(A <= 5) System.out.println(0);
		else System.out.println(B/2);
	}
}

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

using namespace std;

//#define COM_MAX (510000)
#define MOD (1000000007)
//long long fac[COM_MAX];
//long long finv[COM_MAX];
//long long inv[COM_MAX];
//
//void COMinit(void){
//    // 法MOD での二項係数出す準備
//    fac[0] = fac[1] =1;
//    finv[0] = finv[1] =1;
//    inv[1] = 1;
//    for(int i=2; i< COM_MAX; i++){
//        fac[i]  = fac[i - 1] * i % MOD;
//        inv[i]  = MOD - inv[MOD%i] * (MOD / i) % MOD;
//        finv[i] = finv[i - 1] * inv[i] % MOD;
//    }
//
//    return;
//}
//
//long long COM(int n, int k){
//    if(n<k ){return 0;}
//    if(n<0 || k < 0 ){return 0;}
//    return fac[n]* (finv[k]* finv[n-k] % MOD) % MOD;
//}
//


// a^n (mod p)
long long modpow(long long a, long long n, long long p){
    //二分累乗法
    long long res=1;
    while(n>0){
        if(n&1){
            // x^2^0, x^2^1, ...が必要(指数を2^x乗で分解したときに存在する)ならかける
            res = res * a % p; // 乗算なので常時mod取ってok
        }
        // x^2^1, x^2^2..を順番に作っていく
        a = a*a % p;  // 乗算なので常時mod OK
        n >>= 1;
    }
    return res;
}


long long COM(long long n, long long k){
    long long a=1;
    long long b=1;
    long long div=0;

    for(long long int i=0; i< k; i++){
        a = (a*(n-i)) % MOD;
    }
    for(long long int i=1; i<= k; i++){
        b = (b*i) % MOD;
    }
    div = modpow(b, MOD-2 ,MOD);

    return (a*div) %MOD;
}

int main(void){
    long long int n;
    long long int a;
    long long int b;

    long long int base;
    long long int nca;
    long long int ncb;

    cin >> n;
    cin >> a;
    cin >> b;

    // おまじない
//    COMinit();
    // 2^n-1
    base = modpow(2, n, MOD)-1;
//    cout << base << endl;
    nca = COM(n,a);
//    cout << nca << endl;
    ncb = COM(n,b);
//    cout << ncb << endl;

    base = base-nca;
    if(base < 0){base += MOD;}
    base = base-ncb;
    if(base < 0){base += MOD;}

    cout << base << endl;

    return 0;
}



Measured memory_bytes: 256
from functools import reduce
from itertools import combinations

def gcd(a, b):
    while b: a, b = b, a % b
    return a

def gcd_list(A): return reduce(gcd, A)

K = int(input())
S = K * (K + 1) // 2
for a, b in combinations(range(1, K+1), 2):
    S += 6 * gcd(a, b)
for a, b, c in combinations(range(1, K+1), 3):
    S += 6 * gcd_list((a, b, c))
print(S)

Measured memory_bytes: 9624
N = int(input())

# 桁数を決める
digit = 1  # 桁数
num = pow(26, digit) # その桁数での最大番号
while num < N:
    digit += 1
    num += pow(26, digit)

# その桁数内でのNの順番を0-indexで求める.
# (つまり, 2桁であれば'aa' -> 0, 'zz' -> 675 となる.)
order = N - (num - pow(26, digit)) - 1

# orderを26進数表記する.
# 例えば, 3桁でorder=28のとき, X = [0, 1, 2]
X = [0] * digit
cur = digit - 1
while order > 0:
    X[cur] = order % 26
    order //= 26
    cur -= 1

# 各桁の文字は'a' + Xiとなる
ans = []
a = ord('a')
for x in X:
    c = chr(a + x)
    ans.append(c)

print(''.join(ans))

Measured memory_bytes: 9216
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>

#define INF 1000000000

using namespace std;

int main() {
    int n, ans = 0;
    cin >> n;
    vector<int> h(n + 2, 0);
    for (int i = 0; i < n; ++i) cin >> h.at(i);
    while (accumulate(h.begin(), h.end(), 0)) {
        int m = h.front(), prev = 0;
        for (int i = 0; i <= n; ++i) {
            if (h.at(i) == 0) {
                for (int j = prev; j < i; ++j) h.at(j) -= m;
                prev = i + 1;
                ans += m;
                m = h.at(i + 1);
            } else m = min(m, h.at(i));
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define ri(x) scanf("%d",&(x))
#define ri2(x,y) scanf("%d %d",&(x),&(y))
#define ri3(x,y,z) scanf("%d %d %d",&(x),&(y),&(z))
#define rll(x) scanf("%lld",&(x))
#define rll2(x,y) scanf("%lld %lld",&(x),&(y))
#define rll3(x,y,z) scanf("%lld %lld %lld",&(x),&(y),&(z))
#define gc(x) ((x) = getchar())
using namespace::std;

const long double PI = acos(-1);
const long long MOD = 1000000000 +7;

typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<ll,pll> tll;
typedef pair<int,int> ii;
typedef pair<int,ii> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<ll> vll;
typedef vector<pll> vpll;
typedef vector<tll> vtll;
typedef vector<string> vs;
typedef set<int> si;
typedef set<ii> sii;
typedef set<iii> siii;

ll gcd(ll a, ll b){ return b==0?a:gcd(b,a%b);}

ll add(ll a, ll b, ll m = MOD){
	if(a >= m) a %= m;
	if(b >= m) b %= m;
	if(a < 0) a += m;
	if(b < 0) b += m;
	ll res = a+b;
	if(res >= m or res <= -m) res %= m;
	if(res < 0) res += m;
	return res;
}

ll mul(ll a, ll b, ll m = MOD){
	if(a >= m) a %= m;
	if(b >= m) b %= m;
	if(a < 0) a += m;
	if(b < 0) b += m;
	ll res = a*b;
	if(res >= m or res <= -m) res %= m;
	if(res < 0) res += m;
	return res;
}

ll pow_mod(ll a, ll b, ll m = MOD){
	ll res = 1LL;
	a = a%m;
	while(b){
		if(b&1) res = mul(res,a,m);
		b >>= 1;
		a = mul(a,a,m);
	}
	return res;
}

ll fastexp(ll a, ll b){
	ll res = 1LL;
	while(b){
		if(b&1) res = res*a;
		b >>= 1;
		a *= a;
	}
	return res;
}

int gcdExtendido(int a, int b, int *x, int *y){
	if(a == 0){
		*x = 0;
		*y = 1;
		return b;
	}
	int x1, y1;
	int gcd = gcdExtendido(b%a,a,&x1,&y1);
	
	*x = y1-(b/a)*x1;
	*y = x1;
	return gcd;
}

int modInverso(int a, int m){
	int x, y;
	int g = gcdExtendido(a,m,&x,&y);
	if(g!=1) return -1;
	else return (x%m + m)%m;
}

/****************************************
*************P*L*A*N*T*I*L*L*A************
*****************************************/

const int N = 200000+5;

int n, k;
int a[N];

int main(){
	ri2(k,n);
	for(int i=1; i<=n; i++){
		ri(a[i]);
	}
	int ans = INT_MAX;
	for(int i=1; i<=n; i++){
		int j = i + 1 <= n? i + 1 : 1;
		ans = min(ans, k - (a[i] <= a[j]? a[j] - a[i] : k + a[j] - a[i]));
	}
	printf("%d\n",ans);
	return 0;
}


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

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  if ((a == 5 && b == 5 && c == 7) || (a == 5 && b == 7 && c == 5) || (a == 7 && b == 5 && c == 5)) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
def getN():
    return int(input())


def getNM():
    return map(int, input().split())


def getList():
    return list(map(int, input().split()))

n,m = getNM()
children = [[] for i in range(n+2)]
n_in = [0] * (n+1)
par_origin = [0] * (n+1)

#入力の処理
for i in range(n+m-1):
    a,b = getNM()
    children[a].append(b)
    n_in[b] += 1

#根を見つける
for i in range(1,n+m-1):
    if n_in[i]:
        pass
    else:
        root = i
        break

#次数を減らしながら探索
import queue
def bfs(root):
    q = queue.Queue()
    q.put(root)
    while(True):
        try:
            cur = q.get(block=False)
        except:
            break
        for c in children[cur]:
            if n_in[c] == 1:
                par_origin[c] = cur
                q.put(c)
            else:
                n_in[c] -= 1

bfs(root)
for i in range(1, n+1):
    print(par_origin[i])



Measured memory_bytes: 21328
def find(u , pre):
	pre[u] = (u if u == pre[u] else find(pre[u] , pre))
	return pre[u]

def solve():
	n , q = map(int , input().split())
	pre = list(range(n))
	for _ in range(q):
		t , u , v = map(int,input().split())
		u_root , v_root = find(u , pre) , find(v , pre)
		if(t == 1):
			print(1 if u_root == v_root else 0)
		else:
			pre[u_root] = v_root
def main():
	solve()

if __name__ == '__main__':
	main()

Measured memory_bytes: 16372
n=int(input())
a=input()
A=a.split()
B=a.split()
C=[]
for i in range(len(A)):
    C.append(0)
for j in range(len(A)):
    A[j]=int(A[j])
for k in range(len(A)):
    C[A[k]-1]=k+1
for l in range(len(C)):
    C[l]=str(C[l])
s = ' '.join(C)
print(s)

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

int main(){
    long long k,a,b,change,pls;
    cin >> k >> a >> b;
    k++;

    if(b - a < 2 || k <= a){
        cout << k<< endl;
        return 0;
    }
    else {
        k -= a;
        change = k / 2;
        pls = k % 2;
        cout << a + change * (b - a) + pls << endl;
    }
}


Measured memory_bytes: 256
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
	n = readline() |> parseInt
	p = 0
	q = 0
	for i in 1:n
		a,b = readline() |> split |> parseMap
		if p<a
			p = a
			q = b
		end
	end
	println(p+q)
end
main()

Measured memory_bytes: 153416
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")
}

pub fn read_n<T: FromStr>(n: usize) -> Vec<T> {
    read_n_logic::<T>(n, vec![])
}

pub fn read_n_logic<T: FromStr>(n: usize, mut a: Vec<T>) -> Vec<T> {
    match n {
        0 => a,
        _ => {
            a.push(read::<T>());
            read_n_logic(n - 1, a)
        }
    }
}

use std::cmp::{max, min};
fn main() {
    let n: usize = read();
    let p: Vec<i64> = read_n(n);
    let q: Vec<i64> = read_n(n);

    let mut total = 1;

    for i in 1..n + 1 {
        total *= i;
    }

    let mut total2 = 1;

    for i in 1..n + 1 {
        total2 *= i;
    }
    let mut c = vec![];
    for i in 1..n + 1 {
        c.push(i as i64);
    }
    let mut ans = 0;

    for i in p {
        let idx = c.iter().position(|&r| r == i).unwrap();
        ans += total / c.len() * (idx);
        total /= c.len();
        c.remove(idx);
    }
    let mut d = vec![];
    for i in 1..n + 1 {
        d.push(i as i64);
    }
    let mut ans2 = 0;

    for i in q {
        let idx = d.iter().position(|&r| r == i).unwrap();
        ans2 += total2 / d.len() * (idx);
        total2 /= d.len();
        d.remove(idx);
    }
    println!("{}", max(ans, ans2) - min(ans, ans2));
}


Measured memory_bytes: 4352
require 'openssl'
require 'set'; require 'prime'
INF=Float::INFINITY; MOD=998244353
n = gets.chomp.to_i
d = gets.chomp.split.map(&:to_i)

if d[0] != 0
  puts 0
  exit
end

h = Hash.new(0)
d.each do |num|
  h[num] += 1
end

if h[0] != 1
  puts 0
  exit
end

ans = 1

ha = h.sort_by{|k,v| k}
(ha.size-1).times do |i|
  if ha[i][0] + 1 != ha[i+1][0]
    puts 0
    exit
  end
  # p [ha[i][1], ha[i+1][1], ha[i][1].to_bn.mod_exp(ha[i+1][1], MOD)]
  a = ha[i][1].to_bn.mod_exp(ha[i+1][1], MOD)
  ans = (ans * a) % MOD
end

puts ans

Measured memory_bytes: 31420
package main

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

var si = bufio.NewScanner(os.Stdin)

func readInt() int {
        si.Scan()
        r, _ := strconv.Atoi(si.Text())
        return r
}

type UnionTree struct {
        id     int
        parent *UnionTree
}

func (p *UnionTree) Root() *UnionTree {
        if p.parent == nil {
                return p
        }
        root := p.parent.Root()
        if p.parent != root {
                p.parent = root
        }
        return p.parent
}
func (p *UnionTree) unite(q *UnionTree) {
        pRoot := p.Root()
        qRoot := q.Root()
        if pRoot == qRoot {
                return
        }
        if pRoot.id > qRoot.id {
                pRoot.parent = qRoot
        } else {
                qRoot.parent = pRoot
        }
}
func (p *UnionTree) same(q *UnionTree) bool {
        return p.Root() == q.Root()
}
func main() {
        si.Split(bufio.ScanWords)
        si.Buffer(make([]byte, 0), 10000000)
        N, M := readInt(), readInt()
        e := make([][2]int, M)
        for i := 0; i < M; i++ {
                a, b := readInt()-1, readInt()-1
                e[i] = [2]int{a, b}
        }
        ret := 0
        for i := 0; i < M; i++ {
                t := make([]*UnionTree, N)
                for i := 0; i < N; i++ {
                        t[i] = &UnionTree{i, nil}
                }
                for j := 0; j < M; j++ {
                        if j != i {
                                t[e[j][0]].unite(t[e[j][1]])
                        }
                }
                if !t[e[i][0]].same(t[e[i][1]]) {
                        ret += 1
                }
        }
        fmt.Println(ret)
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define fast_io ios_base::sync_with_stdio(false); cin.tie(nullptr)
#define rep(i, x, y) for(decltype(y) i = (x) - ((x) > (y)); i != (y) - ((x) > (y)); i += 1 - 2 * ((x) > (y)))
#define trav(i,a) for(auto& (i) : (a))
#define all(a) (a).begin(),(a).end()
#define sz(a) int((a).size())
#define clr(a,x) memset((a),(x),sizeof(a)) // array (0,-1)
#define dbg(x) cerr << "STDERR => " << __LINE__ << ": " << #x << " = " << (x) << "  :(\n";
inline void cpuTime() { cerr << "cpu time : " << double(clock())/CLOCKS_PER_SEC << "\n"; return; }
using ll = long long;
using ull = unsigned long long;
using F = float;
using D = double;
using vi = vector<int>;
using pii = pair<int,int>;

void solve(){
    
    int x,y;
    cin >> x >> y;
    cout << x+y/2 << "\n";

}

int main(){
    
    fast_io;
    // cin.exceptions(cin.failbit);
    
    solve();
    
    
    cpuTime();
return 0;
}


/*
 read the question carefully ( what're the exact constraints? )
 look out for SPECIAL CASES (n=1?) and OVERFLOW (ll vs int?) ARRAY OUT OF BOUNDS
 Check datatypes
*/

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

#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a)  (a).begin(),(a).end()

template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}
typedef long long ll;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}


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

    vector<pair<string,int>> v(N);
    // iまでのわ
    vector<int> rsum(N,0);

    REP(i,N) {
        string s;
        int t;
        cin >> s >> t;

        rsum[i] = t;
        if ( i > 0) rsum[i] += rsum[i-1];

        v[i] = make_pair(s,t);
    }

    string X;
    cin >> X;

    // find
    REP(i,N) {
        if (v[i].first == X) {
            cout << rsum[N-1]-rsum[i] << endl;
            return 0;
        }
    }

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
	double a,b,c,d,e,f;
	int temp;
	double x,y;
	
	while(scanf("%lf%lf%lf%lf%lf%lf",&a,&b,&c,&d,&e,&f) != EOF){
		x=(c*e-b*f)/(a*e-b*d+0.);
		y=(f*a-c*d)/(a*e-d*b+0.);
		
		/*temp = (int)x*10000;
		
		if(temp%10>=5){
			x+=0.001;
		}
		
		
		temp = (int)y*10000;
		
		if(temp%10>=5){
			y+=0.001;
		}
		*/
		if(x>-0.001 && x<0.001)x=0;
        if(y>-0.001 && y<0.001)y=0;
		printf("%.3lf %.3lf\n",x,y);
	}

	return 0;
}

Measured memory_bytes: 648
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Kamol Paul
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>
using namespace std;
#define long long long
typedef pair < long , long > pii;

class EEE {
    long j = INT_MAX;
public:
	void solve(std::istream& in, std::ostream& out) {
	    long n,m;
	    in>>n>>m;
	    long LCM=1LL;
	    long LCM2=1LL;
	    long x;
	    set <long> data;
	    for(int i =0 ;i<n;i++){
	        in>>x;
	        LCM2 = (LCM2/__gcd(LCM2,x))*x;
	        x/=2;
	        data.insert(x);
	        LCM = (LCM/__gcd(LCM,x))*x;

	        if(LCM>j){
	            out<<"0\n";
                return;
	        }
	    }
	    long l=0;
	    long lol = LCM;
	    while(lol%2==0){
	        l++;
	        lol/=2;
	    }
	    lol = 1LL<<l;
	    for(int t: data){
	        if(t%lol){
                out<<"0\n";
                return;
	        }
	    }
	    long ans= m/LCM2;
	    if((m%LCM2)>=LCM) ans++;
	    out<<ans<<endl;

	}
};


int main() {
    ios_base::sync_with_stdio(false);cin.tie(NULL);
	EEE solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using static System.Console;
using System.Linq;


class Program
{

    static void Main(string[] Args) {
        var X = Int32.Parse(ReadLine());
        if (X == 3 || X == 5 || X == 7) {
            WriteLine("YES");
            return;
        }
        WriteLine("NO");

        ReadLine();
    }
}

Measured memory_bytes: 11092