akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
const double PI  =3.141592653589793238463;
long long mod = 1000000007;
int stringToInteger(string x){
    int gg=0;
    stringstream geek(x);
    geek >> gg;
    return gg;
}

ll powmod(ll a,ll b,ll m)
{
    ll ans=1;
    while(b>0){ if(b%2)
        {ans*=a; ans%=m;}
         b/=2; a=a*a; a=a%m;
        }
        return ans%m;
}
ll gcd(ll a,ll b)
{

    return __gcd(a,b);
}
ll mulmod(ll a,ll b,ll m)
{  ll ans=0;
    a %=m;
    while (b>0)
    {       if(b&1) ans = (ans + a) % m;
        a = (a * 2)%m;
        b /= 2;
    }
    return ans % m;
}
bool prime[100005];
void seive()
{  memset(prime,true,sizeof(prime));
    for(int i=2;i*i<=100005;i++)
    {
         if(prime[i]==true) {
        for(int j=2*i;j<=(100005);j+=i)
           { prime[j]=false;}
           }

    }
}








ll f[5000001];

ll pow(ll a, ll b, ll MOD)
{
 ll x=1,y=a;
 while(b > 0)
 	{
 		if(b%2 == 1)
 	{
 		x=(x*y);
 		if(x>MOD) x%=MOD;
 	}
 	y = (y*y);
 	if(y>MOD) y%=MOD;
 	b /= 2;
 	}
 return x;
}

/* Modular Multiplicative Inverse
 Using Euler's Theorem
 a^(phi(m)) = 1 (mod m)
 a^(-1) = a^(m-2) (mod m) */
ll InverseEuler(ll n, ll MOD)
{
 return pow(n,MOD-2,MOD);
}

ll C(ll n, ll r, ll MOD)
{

 return (f[n]*((InverseEuler(f[r], MOD) * InverseEuler(f[n-r], MOD)) % MOD)) % MOD;
}
int main()
{
    int n; cin>>n;double ans=0;
    for(int i=0;i<n;i++) {
          double s; cin>>s;
          ans+=(1.0/s);
          
    }
    cout<<(1.0/ans)<<endl;
}









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

typedef long long ll;
#define pii pair<int , int>
#define _FastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MAXX 100005

ll n , s , ans;
ll a[MAXX];

int main()
{
    _FastIO;
    cin >> n;
    bool flag = true;
    for(ll i = 0; i < n; i++){
        cin >> a[i];
        if(!a[i])
            s++;
    }
    if(s){
        cout << "0" << endl;
        return 0;
    }
    sort(a , a + n);
    ans = 1;
    for(ll i = 0; i < n; i++){
        ans *= a[i];
    if(ans < 0 || ans > 1000000000000000000)
        flag = false;
    }
    ll p = ans;
    for(ll i = 0; i < n; i++){
        p /= a[i];
    }
    if(flag && (p == 1)){
        cout << ans << endl;
    }
    else
        cout << "-1" << endl;
    return 0;
}


Measured memory_bytes: 4440
def gcd(a, b)
  a,b = b, a % b while b > 0
  a
end

# 最小公倍数
def lcm(a,b)
  a * b / gcd(a,b)
end


n = gets.chomp.to_i
A = gets.chomp.split.map(&:to_i)


MOD = 10**9+7
ans = 0
tmp = 0

n.times do |i|
  if i == 0
    tmp = A[i]
  else
    tmp = lcm(tmp, A[i])
  end
end

n.times do |i|
  ans += tmp/A[i]
end

p ans % MOD


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

const ll MAXN = 200000;

ll N, ans=0, tmp=0;

signed main(){
    ll A;
    double B;
    cin >> A >> B;
    B*=100.0;
    B+=0.1;
    ll C = A*(ll)B;
    C /= 100;
    cout << C << endl;
    return 0;
}

Measured memory_bytes: 3712
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define fi first
#define se second
#define PI (acos(-1))

template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i];if(i<len-1) s<<" ";
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i]<<endl;
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){
	s<<"{ ";
	for(auto itr=v.begin();itr!=v.end();++itr) {
		if (itr!=v.begin()) {s<< ", ";}
		s<<(*itr);
	}
	s<<" }";
	return s;
}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){
	s<<"{"<<endl;
	for(auto itr=m.begin();itr!=m.end();++itr){
		s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;
	}
	s<<"}"<<endl;
	return s;
}

const ll mod=1e9+7;
const ll inf=1e15;
const int INF=1e9;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin>>n;
	vector<int> a(n+1);
	FOR(i,1,n+1){
		cin>>a[i];
	}
	int now=0;
	FOR(i,1,n+1){
		if(a[i]==now+1){
			now++;
		}
	}
	if(now==0){
		cout<<-1<<endl;
	}else{
		cout<<n-now<<endl;
	}
}

Measured memory_bytes: 1024
#include <iostream>
#include<cstdlib>
#include<queue>
#include<set>
#include<vector>
#include<stack>
#include<map>
#include<string>
#include<algorithm>
#include<cmath>
#include<cstdio>

using namespace std;
#define rep(i,a) for(int i=0;i<a;i++)
#define mp make_pair
#define pb push_back
#define P pair<int,int>

#define ll __int64
#define __int64 long long

ll h,w,n;
ll a[111111],b[111111];
map<P,bool>ta;//存在
map<P,bool>used;//見たか
ll ans[10];//四角形の枚数(黒

int main(){
	cin>>h>>w>>n;
	rep(i,n){
		cin>>a[i]>>b[i];
		a[i]--;b[i]--;
		ta[mp(a[i],b[i])]=1;
	}
	int nx,ny,x,y,cnt;
	rep(i,n){
		nx=b[i];
		ny=a[i];
		cnt=0;
		for(int j=0;j>=-2;j--){
			for(int k=0;k>=-2;k--){
				y=ny+j;
				x=nx+k;
				if(y<0||x<0||x+2>=w||y+2>=h||used[mp(y,x)])continue;
				used[mp(y,x)]=1;
				cnt=0;
				rep(l,3){
					rep(r,3){
						if(ta[mp(y+l,x+r)])cnt++;
					}
				}
				//cout<<y<<" "<<x<<" "<<cnt<<endl;
				ans[cnt]++;
			}
		}
	}
	ll sum=(h-2)*(w-2);
	for(int i=1;i<10;i++)sum-=ans[i];
	ans[0]=sum;
	rep(i,10)cout<<ans[i]<<endl;
	return 0;
}


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

using namespace std;

	int p[100005];
	long long prefiksuk[100005];
	long long poz[100005];
	vector <long long> v;
	
int main (){
	
	int n,k;
	cin >> n >> k;
	
	for (int i = 0; i < n; i++){
		cin >> p[i];
	}
	
	prefiksuk[0] = p[0];
	if (n > 1){
		for (int i = 1; i < n; i++){
			prefiksuk[i] = prefiksuk[i - 1] + p[i]; 
		}
	}
	
	poz[0] = 0;
	if (p[0] > 0)poz[0] = p[0];
	
	if (n > 1){
		for (int i = 1; i < n; i++){
			if (p[i] > 0){
				poz[i] = poz[i - 1] + p[i]; 
			}else {
				poz[i] = poz[i - 1];
			}
		}
	}

	for (int br = 0; br < (n-k+1); br++){
		long long sol = 0;
		if (br == 0){
			if ((poz[n-1] - poz[k-1]) > 0){
				sol += (poz[n-1] - poz[k-1]);
			}
		}else if (br == (n-k)){
			if (poz[br-1] > 0){
				sol += poz[br-1];
			}
		}else {
			if (poz[br-1] > 0){
				sol += poz[br-1];
			}
			if ((poz[n-1] - poz[br+k-1]) > 0){
				sol += (poz[n-1] - poz[br+k-1]);
			}
		}
		
		
		if (br == 0){
			if (prefiksuk[k-1] > 0){
				sol += prefiksuk[k-1];
			}
		}else if (br == n-1){
			if ((prefiksuk[n-1]) - (prefiksuk[n-k-1]) > 0){
				sol += (prefiksuk[n-1]) - (prefiksuk[n-k-1]);
			}
		}else {
			if (((prefiksuk[br+k-1]) - (prefiksuk[br-1])) > 0){
				sol += ((prefiksuk[br+k-1]) - (prefiksuk[br-1]));
			}
		}
		
		v.push_back(sol);
	}
	
	sort (v.begin(), v.end());
	
	cout << v[v.size()-1];
	
	return 0;
}

Measured memory_bytes: 3320
N, M = map(int, input().split())
A = [list(map(int, input().split())) for i in range(N)]
A.sort()
E = 0
i = 0
C = 0
while E < M:
  if E + A[i][1] > M:
    C += (M - E) * A[i][0]
    E = M
  else:
    E += A[i][1]
    C += A[i][0] * A[i][1]
    i += 1
print(C)

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


int main(void){
    int A,B,C;
cin>>A>>B>>C;
    
    if(A==B&&A!=C)
    cout<<"Yes"<<endl;
    
    else if (B==C&&A!=C)
    cout<<"Yes"<<endl;
    
    else if (C==A&&B!=C)
    cout <<"Yes"<<endl;
    
    else 
    cout<<"No"<<endl;
    
    return 0;
}



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

int main() {
	int n;
	while(cin >> n, n) {
		vector<pair<int,int> > v;
		for(int i = 0; i < n; i++) {
			int c;
			cin >> c;
			int pts = 0;
			for(int i = 0; i < 4; i++) {
				int m, s;
				cin >> m >> s;
				pts += m * 60 + s;
			}
			v.push_back(pair<int,int>(pts, c));
		}
		sort(v.begin(), v.end());

		cout << v[0].second << endl;
		cout << v[1].second << endl;
		cout << v[v.size() - 2].second << endl;
	}
}

Measured memory_bytes: 1304
import java.util.*;
public class Main{
	public static void main(String args[]){
		ArrayList[] a;
		a=new ArrayList[10];
		a[1]=new ArrayList<Integer>();
		//a[1].add(3);
		for(int i=1;i<=9;i++){
			for(int j=1;j<=9;j++){
				System.out.printf("%dx%d=%d\n",i,j,i*j);
			}
		}
		
	}
}

Measured memory_bytes: 18076
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
inline int read()
{
	int x = 0 , f = 1; char ch = getchar();
	while(ch < '0' || ch > '9')	{if(ch == '-')	f = -1; ch = getchar();}
	while(ch >= '0' && ch <= '9') {x = (x << 3) + (x << 1) + (ch ^ 48); ch = getchar();}
	return x * f;
}
const int N = 5e5 + 5 , mod = 998244353;
ll fac[N] , inv[N];
inline ll ksm(ll a,int b)
{
	ll res = 1;
	while(b)
	{
		if(b & 1) res = res * a % mod;
		a = a * a % mod; b >>= 1;
	}
	return res; 
}
inline void init(int n)
{
	fac[0] = inv[0] = 1;
	for(int i = 1;i <= n;i ++) fac[i] = fac[i - 1] * i % mod;
	inv[n] = ksm(fac[n],mod - 2);
	for(int i = n - 1;i >= 1;i --) inv[i] = inv[i + 1] * (i + 1) % mod;
}
inline int C(int n,int m) { return (n >= m && m >= 0)? fac[n] * inv[m] % mod * inv[n - m] % mod : 0;}
int main()
{
	int n = read() , m = read();
	if(m < n) return puts("0") , 0;
	init(m); int ans = 0;
	for(int R = 0;R <= m;R ++)
	{
		int B = m - R;
		if(R < B) continue;
		if(R == B) B --;
		ans = (ans + C(R + B,R) - C(R + B,R * 2 - n + 1)) % mod;
		ans = (ans + mod) % mod;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 8064
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll ans(ll n, ll x) { return x ? (ans(x, n % x) + n / x * x * 2) : -n; }
ll x, n;
int main() {
    scanf("%lld%lld", &n, &x);
    if (n < x + x) x = n - x;
    printf("%lld\n", n + ans(n - x, x));
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <string>
#include <map>
#include <cmath>
#include <cstring>

#define fi first
#define se second
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for (int i = 1; i < (n); ++i)
#define drep(i,n) for (int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define all(x) (x).begin(), (x).end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define pb push_back
#define sz(x) (int)(x).size()
#define PQ(T) priority_queue<T, v(T), greater<T> >

#define v(T) vector<T>
#define vv(T) v(v(T))

using namespace std;
typedef long long ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;

const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;

const int mod = 1000000007;

const int MX = 3005;
int dp[MX][MX];

int main() {
    string s,t;
    cin >> s >> t;
    s += '$';
    t += '#';
    rep(i,sz(s))rep(j,sz(t)) {
        maxs(dp[i+1][j], dp[i][j]);
        maxs(dp[i][j+1], dp[i][j]);
        if (s[i]==t[j]) maxs(dp[i+1][j+1], dp[i][j]+1);
    }
    int i = sz(s)-1, j = sz(t)-1;
    string ans = "";
    while(i+j) {
        int x = dp[i][j];
        if (i && dp[i-1][j] == x) --i;
        else if (j && dp[i][j-1] == x) --j;
        else {
            --i; --j;
            ans += s[i];
        }
    }
    reverse(all(ans));
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 35456
import java.util.*;

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

    public static void main(String[] args) {
        int n = sc.nextInt();
        String s = sc.next();
        String abc = "ABC";
        int res = 0;
        int pos = s.indexOf(abc, 0);
        while (pos >= 0) {
            res += 1;
            pos = s.indexOf(abc, pos + 1);
        }
        System.out.println(res);
    }
}

Measured memory_bytes: 23764
allEatCache = {}
lenBurgerCache = {}


def nOfPatty(level, eat):
    if level == 0:
        return 1
    else:
        if level in allEatCache and eat >= lenBurger(level):
            return allEatCache[level]
        else:
            lenOfLowerLevel = lenBurger(level - 1)
            if eat <= 1:
                return 0
            if 2 <= eat <= 1 + lenOfLowerLevel:
                return nOfPatty(level - 1, eat - 1)
            if eat == 1 + lenOfLowerLevel + 1:
                return nOfPatty(level - 1, eat - 1) + 1
            else:
                tmp = nOfPatty(level - 1, eat - 1) + 1
                tmp += nOfPatty(level - 1, eat - 1 - lenOfLowerLevel - 1)
                allEatCache[level] = tmp
                return tmp


def lenBurger(level):
    if level == 0:
        return 1
    else:
        if level in lenBurgerCache:
            return lenBurgerCache[level]
        else:
            return 3 + lenBurger(level - 1) * 2


str = input().split()
n = int(str[0])
x = int(str[1])

print(nOfPatty(n, x))


Measured memory_bytes: 3064
using System;
using System.Linq;
using System.Collections.Generic;

namespace Algorithm
{
    class Program
    {
        static void Main(string[] args)
        {
            var l = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int N = l[0], K = l[1];
            var array = Console.ReadLine().Split().Select(long.Parse).ToArray();
            var max = 0L;

            for (var i = 0; i <= Math.Min(K, N); i++)
            {
                for (var j = 0; i + j <= Math.Min(K, N); j++)
                {
                    var list = new List<long>();
                    var pos = 0L;

                    for (var m = 0; m < i; m++)
                    {
                        list.Add(array[m]);
                        pos += array[m];
                    }
                    for (var n = 0; n < j; n++)
                    {
                        list.Add(array[N - n - 1]);
                        pos += array[N - n - 1];
                    }

                    list = list.OrderBy(o => o).ToList();

                    for (var k = 0; k < Math.Min(K - i - j, list.Count); k ++)
                    {
                        if (list[k] < 0) pos -= list[k];
                    }
                    max = Math.Max(pos, max);
                }
            }
            Console.WriteLine(max);
        }
    }
}


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

int arr[2010][2010] = {};

int block[2010][2010] = {};
int updn[2010][2010] = {};
int rtlt[2010][2010] = {};

int y,x,n;

void show(){
    
    for(int i = 1; i <= y; i++){
        for(int j = 1; j <= x; j++){
            cout << block[i][j] << " ";
        }
        cout << endl;
    }
    cout << endl;
    for(int i = 1; i <= y; i++){
        for(int j = 1; j <= x; j++){
            cout << updn[i][j] << " ";
        }
        cout << endl;
    }
    cout << endl;
    for(int i = 1; i <= y; i++){
        for(int j = 1; j <= x; j++){
            cout << rtlt[i][j] << " ";
        }
        cout << endl;
    }
    
    cout << endl;
}

int countBlock(int y1,int x1,int y2,int x2){
    
    return block[y2][x2] + block[y1-1][x1-1] - block[y1-1][x2] - block[y2][x1-1];
    
}
int countUpDn(int y1,int x1,int y2,int x2){
    x1--;y1--;
    y2--;
    return updn[y2][x2] + updn[y1][x1] - updn[y1][x2] - updn[y2][x1];
    
}
int countRtLt(int y1,int x1,int y2,int x2){
    x1--;y1--;
    x2--;
    return rtlt[y2][x2] + rtlt[y1][x1] - rtlt[y1][x2] - rtlt[y2][x1];
    
}

int main(void){
    
    cin >> y >> x >> n;
    
    for(int i = 0; i < y; i++){
        for(int j = 0; j < x; j++){
            char c;
            cin >> c;
            
            arr[i+1][j+1] = c - '0';
            block[i+1][j+1] = c - '0';
            
        }
    }
    
    
    for(int i = 1; i <= y; i++){
        for(int j = 1; j <= x; j++){
            block[i][j+1] += block[i][j]; 
            
            if(arr[i][j] && arr[i+1][j]){
                updn[i][j] = 1;
            }
            if(arr[i][j] && arr[i][j+1]){
                rtlt[i][j] = 1;
            }
        }
    }
    
    for(int i = 0; i <= y; i++){
        for(int j = 0; j <= x; j++){
            block[i + 1][j] += block[i][j]; 
        }
    }
    
    for(int i = 0; i <= y; i++){
        for(int j = 0; j <= x; j++){
            updn[i][j+1] += updn[i][j];
            rtlt[i][j+1] += rtlt[i][j]; 
        }
    }
    
    for(int i = 0; i <= y; i++){
        for(int j = 0; j <= x; j++){
            rtlt[i + 1][j] += rtlt[i][j]; 
            updn[i + 1][j] += updn[i][j]; 
        }
    }
    
    
    //show();
    
    
    for(int i = 0; i < n; i++){
        int y1,x1,y2,x2;
        cin >> y1 >> x1 >> y2 >> x2;
        
        cout << countBlock(y1,x1,y2,x2) - countUpDn(y1,x1,y2,x2) - countRtLt(y1,x1,y2,x2) << endl;
        //cout << ":" <<  countUpDn(y1,x1,y2,x2) << " " << countRtLt(y1,x1,y2,x2) << endl;
    }
    
    
}


Measured memory_bytes: 64896
#include <bits/stdc++.h>
#include <string>
#include <stdio.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
using namespace std;

int main(void) {
    int A,B,C,maxa=0,counter=0,count=0,argmax=0;
    vector<int> data(3);
    int a[3];
      for(int i=0;i<3;i++){
        cin >> data[i];
      }




      for(int i=0;i<3;i++){
        if(data[i]%2 ==1){
          counter++;
          a[i]=1;
        }else{a[i]=0;}
      }

      for(int i=0;i<3;i++){
        if((counter==1)&&(a[i]==0)||(counter==2)&&(a[i]==1)){
          data[i]++;
        }
      }
        maxa = *max_element( data.begin(), data.end() );
      if(counter==1||counter==2){
        count++;
      }

      for(int i=0;i<3;i++){
            count += (maxa-data[i])/2;
        }

      cout<<count<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cmath>
#include<cstdlib>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<queue>

using namespace std;

int n;
string s[2];

int main(){
  cin>>n;
  for(int i=0;i<2;i++)cin>>s[i];

  long long ans = 1;
  int i = 0;
  if(s[0][0] == s[1][0]){
    ans *= 3;
    i = 1;
  } else {
    ans *= 6;
    i = 2;
  }

  for(;i<n;i++){
    if(s[0][i-1] == s[0][i]) continue;

    if(s[0][i] != s[1][i]){
      if(s[0][i-1] == s[1][i-1]){
        ans *= 2;
        ans %= 1000000007;
      } else {
        ans *= 3;
        ans %= 1000000007;
      }
    } else {
      if(s[0][i-1] == s[1][i-1]){
        ans *= 2;
        ans %= 1000000007;
      }
    }

  }
  cout<<ans<<endl;

  return 0;
}

Measured memory_bytes: 256
def min_diam(A,B,C): # returns a "diameter"
  segments=[A,B,C]
  segments.sort()
  return (segments[0]**2+segments[1]**2)**(1/2)

while True:
  # input one dataset
  A,B,C = tuple(map(float,input().split()))
  if (A,B,C) == (0,0,0):
    break
  n = int(input())
  R = [None]*n
  for i in range(n):
    R[i] = float(input())
  # process
  diam = min_diam(A,B,C)
  # judge & output
  for r in R:
    if diam < 2*r:
      print("OK")
    else:
      print("NA")

Measured memory_bytes: 7748
#include <bits/stdc++.h>
#define int long long

using namespace std;

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

	int k ; cin >> k;
	if(k%2 == 0 || k%5 == 0) {
		cout << -1; return 0;
	}
	if(k == 7 || k == 1) {
		cout << 1 ; return 0;
	}
	if(k % 7 ==0 ) k /= 7;
	int ans = 1;
	int res = 10;    
	int mod = 9 * k;
	while(res != 1){
		res = res*10%mod;
		ans++;
	}
	cout << ans ;

  return 0;
}


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

ll n;

int main(){
  cin >> n;
  ll res = 1e13;
  for(ll i = 1; i * i <= n; i++){
    if(n % i != 0) continue;
    res = min(res, i + n / i);
  }
  res -= 2LL;
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 256
S = input()

S0 = S.replace("dream", "A")
S1 = S0.replace("erase", "B")
S2 = S1.replace("Aer", "A")
S3 = S2.replace("Br", "B")

#print(S3)
check = True
for i in range(len(S3)):
    if S3[i] != "A" and S3[i] != "B":
        check = False

print("YES" if check == True else "NO")

Measured memory_bytes: 3188
# -*- coding: utf-8 -*-

import sys
import os


s = input().strip()

S1 = []  # sum of pond
S2 = []  # each pond
area = 0

for i, c in enumerate(s):
    if c == '\\':
        S1.append(i)
    elif c == '_':
        pass
    elif c == '/' and S1:
        j = S1.pop(-1)
        area += i - j

        # for each pond
        # ?????????????????????????????´???, pond?????±??????????????????
        pond_sum = i - j  # ???????????????????????¢???
        while S2 and S2[-1][0] > j:
            pond_sum += S2[-1][1]
            S2.pop(-1)
        S2.append([j, pond_sum])

pond_areas = []
for data in S2:
    pond_areas.append(data[1])

# answer
print(area)
print(len(pond_areas), *pond_areas)

Measured memory_bytes: 7988
#include <bits/stdc++.h>
#define adj_list vector<vi>
#define endl "\n"
#define INF_INT 2e9
#define INF_LL 2e18
#define matmax 25
#define mod 1000000007
#define mp make_pair
#define pb push_back
#define pi pair<int, int>
#define pii pair<int, pair<int, int> >
#define pl pair<ll, ll>
#define pll pair<ll, pair<ll, ll> >
#define vi vector<int>
#define vl vector<ll>
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;
typedef long long int ll;

ll pow1(ll a, ll b, ll m = mod)
{
	if (b == 0)
		return 1ll;
	else if (b == 1)
		return a;
	else
	{
		ll x = pow1(a, b/2, m);
		x *= x;
		x %= m;
		if (b%2)
		{
			x *= a;
			x %= m;
		}
		return x;
	}
}

template <class avgType>
avgType avg(avgType a, avgType b) {
	return (a + b)/2;
}

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 rng64(chrono::steady_clock::now().time_since_epoch().count());

int randInt() {
	return rng() % INT_MAX;
}

ll randLL() {
	return rng64() % LLONG_MAX;
}

vector< int > hashmods = {1000000007, 1000000009, 1000000021, 1000000033, 1000000087, 1000000093};

int n, a[110000];
ll ans[110000];
vector< pi > sorted_order;

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

	sorted_order.pb(mp(0, 0));

	for (int i = 1; i <= n; i++) {
		cin>>a[i];
		sorted_order.pb(mp(a[i], i));
	}

	sort(sorted_order.begin(), sorted_order.end());
	reverse(sorted_order.begin(), sorted_order.end());

	int p1 = 0;
	ll currtot = 0, num = 0, done = 0, curr = sorted_order[0].first;
	int minind = n+1;

	while (p1 <= n) {
		ll totred = currtot - (num * curr);
		totred -= done;
		ans[minind] += totred;
		done += totred;

		while (p1 <= n and curr == sorted_order[p1].first) {
			currtot += curr;
			num++;
			minind = min(minind, sorted_order[p1].second);
			p1++;
		}

		curr = sorted_order[p1].first;
	}

	for (int i = 1; i <= n; i++)
		cout<<ans[i]<<endl;

	return 0;
}

Measured memory_bytes: 3188
# -*- coding: utf-8 -*-
# https://atcoder.jp/contests/abc140/tasks/abc140_b

import sys

N = int(input())
B = list(map(int, input().split()))
A = [B[0]]  # 回答のため作っていくリスト

for idx in range(len(B)):
    current_val = B[idx]
    if idx + 1 == len(B):
        next_val = sys.maxsize
    else:
        next_val = B[idx + 1]

    A.append(min(current_val, next_val))

print(sum(A))


Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

int main(){
  int hp, att;
  cin >> hp >> att;
  int n = 0;
  while(hp > 0){
    hp -= att;
    n++;
  }
  cout << n << endl;

  return 0;
}


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

using namespace std;

int main(){
	int w, h, x, y, r;
	cin >> w >> h >> x >> y >> r;
	if (r <= x && x <= w - r && r <= y && y <= h - r) cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 3092
#include <bits/stdc++.h>
using namespace std;
using ld = long double;
#define rep(i, j) for(int i=0; i < (int)(j); i++)
#define all(v) v.begin(),v.end()
const ld EPS = 1e-8;
bool eq(ld a, ld b) { return abs(a - b) < EPS; }

template<class T>
struct Point {
    T x, y, z;
    bool operator < (const Point<T> &r) const { return make_tuple(x, y, z) < make_tuple(r.x, r.y, r.z); }
};

template<class T>
ld length(const Point<T> &p) {
    return sqrtl(p.x * p.x + p.y * p.y + p.z * p.z);
}
template<class T>
ld dot(const Point<T> &a, const Point<T> &b) {
    return a.x * b.x + a.y * b.y + a.z * b.z;
}
template<class T>
ld angle(const Point<T> &a, const Point<T> &b) {
    return acosl(dot(a, b) / length(a) / length(b));
}
template<class T>
Point<ld> unit(Point<T> a) {
    Point<ld> p = {(ld)a.x, (ld)a.y, (ld)a.z};
    ld l = length(p);
    p.x /= l;
    p.y /= l;
    p.z /= l;
    return p;
}

bool solve() {
    using PI = Point<int>;
    int m, n, S, W; cin >> m >> n >> S >> W;
    if(m == 0 and n == 0 and S == 0 and W == 0) return false;
    vector<PI> V(m + n);
    rep(i, m) cin >> V[i].x >> V[i].y >> V[i].z;
    { // generate
        int g = S;
        for(int i=m; i<m+n; i++) {
            V[i].x = (g/7)    %100 + 1;
            V[i].y = (g/700)  %100 + 1;
            V[i].z = (g/70000)%100 + 1;
            if( g%2 == 0 ) { g = (g/2); }
            else           { g = (g/2) ^ W; }
        }
    }
    sort(all(V), [&] (PI a, PI b) { return unit(a).x > unit(b).x; });
    
    ld min_angle = 1e9;    
    PI a, b;

    auto need_check = [&] (PI &a, PI &b) {
        ld alpha = acosl(unit(a).x);
        return cosl(alpha + min_angle) < unit(b).x + EPS;
    };
    
    queue<PI> que;
    rep(i, V.size()) {
        queue<PI> nxt_que;
        while(que.size()) {
            auto p = que.front(); que.pop();
            if(not need_check(p, V[i])) continue;
            ld ang = angle(V[i], p);
            if(ang > EPS) {
                if(min_angle + EPS > ang) {                    
                    auto va = V[i], vb = p;
                    if(vb < va) swap(va, vb);
                    if(!eq(min_angle, ang) or make_pair(a, b) > make_pair(va, vb)) {
                        a = va;
                        b = vb;
                    }
                    min_angle = ang;
                }
            }
            nxt_que.push(p);
        }
        nxt_que.push(V[i]);
        swap(que, nxt_que);
    }
    printf("%d %d %d %d %d %d\n", a.x, a.y, a.z, b.x, b.y, b.z);
    return true;
}

int main() {
    while(solve());
    return 0;
}

Measured memory_bytes: 4748
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const long double PI = (acos(-1));
#define rep(i, x, n) for (int i = x; i < (int)(n); i++)
#define sc(x) scanf("%d",&x)
#define scll(x) scanf("%lld",&x)
int main(){
    int w, h, n; sc(w), sc(h), sc(n);
    vector<int> x(n), y(n), a(n);
    rep(i, 0, n) sc(x[i]), sc(y[i]), sc(a[i]);

    int xr = 0, xl = w, yu = 0, yd = h, ans;
    rep(i, 0, n){
        if (a[i]==1) xr = max(xr, x[i]);
        if (a[i]==2) xl = min(xl, x[i]);
        if (a[i]==3) yu = max(yu, y[i]);
        if (a[i]==4) yd = min(yd, y[i]);
    }
    int sx = min(w, xr+w-xl), sy = min(h, yu+h-yd);
    cout << h*w - (sx*h + sy*w - sx*sy) << endl;
    return 0;
}

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
   
    int n, sum = 0;
    cin >> n;
    for (int i = 0; i < n; i++) {
        int t;
        cin >> t;
        sum += t;
    }
    if (sum % 2 == 0)
        cout << "YES";
    else
        cout << "NO";
   
    return 0;
}


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

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

    int a, b, k;
    cin >> a >> b >> k;

    set<int> st;
    for(int i = a; i <= min(a + k - 1, b); i++){
        st.insert(i);
    }
    for(int i = max(b - k + 1, a); i <= b; i++){
        st.insert(i);
    }

    for(auto x : st){
        cout << x << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <cmath>

using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

map<int,int> mp;

int main()
{
  int n;
  scanf("%d", &n);
  for (int i=0; i<n; i++) {
    int d;
    scanf("%d", &d);
    mp[d]++;
  }

  int m;
  scanf("%d", &m);
  for (int i=0; i<m; i++) {
    int x;
    scanf("%d", &x);
    if (mp[x] == 0) {
      puts("NO");
      return 0;
    }
    mp[x]--;
  }
  puts("YES");
  return 0;
}

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

#define pb push_back
#define ll long long
#define maxn 200005
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define ms(i) memset(i,0,sizeof(i));
#define ms1(i) memset(i,-1,sizeof(i));
#define F first
#define S second

int main(){
	int n,k;
	while(cin >> n >> k){
		int cur = 0;
		int ans = 1;
		f(n){
			int add;
			cin >> add;
			cur += add;
			if(cur<=k)ans++;
			else break;
		}
		cout << ans << endl;
		exit(0);
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <tuple>
#include <queue>
#include <bitset>
#include <set>
#include <map>
#include <list>

using namespace std;


void solve(long long H, long long W, std::vector<std::vector<long long>> A, std::vector<std::vector<long long>> B){
  vector< vector< vector<long long> > > dp(H, vector<vector<long long>>(W, vector<long long>(160*80, 0)));
  dp[0][0][max(A[0][0]-B[0][0], B[0][0]-A[0][0])] = 1;
  long long ret = 160*160;
  long long t;
  int x, y;
  for (int i = 1; i < (H-1)+(W-1)+1; i++) {
    x = min(static_cast<int>(H)-1, i);
    y = 0 + max(0, i - static_cast<int>(H)+1);
    while (true) {
      if(x-1 >= 0) {
        for (int i = 0; i < 160*80; i++) {
          if (dp[x-1][y][i] == 1) {
            dp[x][y][max(i + A[x][y]-B[x][y], -(i + A[x][y]-B[x][y]))] = 1;
            dp[x][y][max(i + B[x][y]-A[x][y], -(i + B[x][y]-A[x][y]))] = 1;
          }
        }
      }
      if(y-1 >= 0) {
        for (int i = 0; i < 160*80; i++) {
          if (dp[x][y-1][i] == 1) {
            dp[x][y][max(i + A[x][y]-B[x][y], -(i + A[x][y]-B[x][y]))] = 1;
            dp[x][y][max(i + B[x][y]-A[x][y], -(i + B[x][y]-A[x][y]))] = 1;
          }
        }
      }
      x--;
      y++;
      if (x < 0 || y >= W) {
        break;
      }
    }
  }
  for (int i = 0; i < 160*80; i++) {
    if (dp[H-1][W-1][i] == 1) {
      std::cout << i << std::endl;
      return;
    }
  }
}

int main(){
  long long H;
  scanf("%lld",&H);
  long long W;
  scanf("%lld",&W);
  std::vector<std::vector<long long>> A(H, std::vector<long long>(W));
  for(int i = 0 ; i < H ; i++){
    for(int j = 0 ; j < W ; j++){
      scanf("%lld",&A[i][j]);
    }
  }
  std::vector<std::vector<long long>> B(H, std::vector<long long>(W));
  for(int i = 0 ; i < H ; i++){
    for(int j = 0 ; j < W ; j++){
      scanf("%lld",&B[i][j]);
    }
  }
  solve(H, W, std::move(A), std::move(B));
  return 0;
}


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

int main() {
    int N;  cin >> N;
    vector<vector<int>> A(2, vector<int>(N));
    for (int i = 0; i < 2; ++i) for (int j = 0; j < N; ++j) cin >> A[i][j];

    vector<int> sum1(N + 1), sum2(N + 1);
    for (int i = 0; i < N; ++i) sum1[i + 1] = sum1[i] + A[0][i];
    for (int i = 0; i < N; ++i) sum2[i + 1] = sum2[i] + A[1][i];
    //DUMP(sum1, sum2);

    int ans = 0;
    for (int i = 1; i <= N; ++i) ans = max(ans, sum1[i] + sum2[N] - sum2[i - 1]);
    cout << ans << endl;
}


Measured memory_bytes: 3636
import java.util.Scanner

object Main extends App {
  val sc = new Scanner(System.in)
  val a,b,c,k = sc.nextInt

  val res: Long = if (a >= k) {
    k
  } else if (a + b >= k) {
    a
  } else {
    a - (k-(a+b))
  }
  println(res)
}

Measured memory_bytes: 55284
import bisect, collections, copy, heapq, itertools, math, string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int, sys.stdin.readline().rstrip().split())
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())


H, W, M = MI()
h = [0] * H
w = [0] * W
item_list = [[0, 0] for _ in range(M)]

for i in range(M):
    item_h, item_w = MI()
    item_h -= 1
    item_w -= 1
    h[item_h] += 1
    w[item_w] += 1
    item_list[i][0] = item_h
    item_list[i][1] = item_w

h_max = max(h)
w_max = max(w)
h_cnt = h.count(h_max)
w_cnt = w.count(w_max)
ans = h_max + w_max

cnt = 0
for item in item_list:
    if h[item[0]] == h_max and w[item[1]] == w_max:
        cnt += 1

x = h_cnt * w_cnt
if cnt == x:
    ans -= 1

print(ans)


Measured memory_bytes: 114376
#include <iostream>
#include <string>
 
int main(void) {
  int n;
  std::string str;
  std::string::size_type id;
   
  std::cin >> n;
  std::cin.ignore();
  for(int i=0; i<n; i++) {
    getline(std::cin, str);
    while((id = str.find("Hoshino")) != std::string::npos) {
        str[id+6] = 'a';
    }
    std::cout << str << std::endl;
  }
  return 0;
}

Measured memory_bytes: 3052
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long
int fact[100010];


signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
	int N, M;
	cin >> N >> M;
	fact[0] = 1;
	fact[1] = 1;
	rep(i, 100000) fact[i + 2] = (fact[i + 1] * (i + 2)) % mod ;
	if (abs(N - M) > 1) cout << 0 << endl;
	else {
		cout << fact[N] * fact[M] * (2 - abs(N - M)) % mod << endl;
	}

    return 0;
}


Measured memory_bytes: 1024
import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.util.*

fun main(args: Array<String>) {
    val sc = FastScanner(System.`in`)

    val a = sc.nextLine().split(" ")

    when {
        a[0][0] > a[1][0] -> println(">")
        a[0][0] < a[1][0] -> println("<")
        else -> println("=")
    }

}

class FastScanner(s: InputStream) {
    private var st = StringTokenizer("")
    private val br = BufferedReader(InputStreamReader(s))

    fun next(): String {
        while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())

        return st.nextToken()
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextLine() = br.readLine()
    fun nextDouble() = next().toDouble()
    fun ready() = br.ready()
}

Measured memory_bytes: 35656
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <string>
#include <cctype>
using namespace std;
#define loop(i,a,b) for(int i=(a);i<int(b);i++)
#define rep(i,b) loop(i,0,b)

int main(){
    int n;
    while(cin>>n && n){
        vector<int> ps(n);
        rep(i,n)cin>>ps[i];
        sort(ps.begin(),ps.end());
        int a=0,b=1;
        while(1){
            while(b<n && ps[b-1]+1==ps[b]) b++;
            if(a+1!=b)printf("%d-%d%c",ps[a],ps[b-1],b==n ? '\n':' ');
            else printf("%d%c",ps[a],b==n ? '\n':' ');
            if(b==n)break;
            a=b;
            b=a+1;
        }
    }
}

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

int main()
{
	ll h, i=1, ans=0;
	cin >> h;
	while (h != 0) {
		h /= 2;
		ans += i;
		i *= 2;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
function main(input) {
    const cards = input.split(" ")
    cards.map(card => Number(card))
    const count = cards.reduce((sum,card) => {return sum + Number(card)}, 0)
    if (count>=22) {
        console.log("bust");
    } else {
        console.log("win");
    }
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7372
#include <iostream>
#include <cmath>
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
#define MAX 100050
int main(){
    long n,q;
    long a[MAX],b[MAX],c[MAX],s;
    long tb[MAX];
    cin >> n;
    s = 0;
    rep(i,n){
        cin >> a[i];
        s += a[i];
    }
    cin >> q;
    rep(i,q) cin >> b[i] >> c[i];
    
    rep(i,MAX) tb[i]=0;
    rep(i,n) tb[a[i]]++;
    
    rep(i,q){
        s += tb[b[i]] * (c[i]-b[i]);
        tb[c[i]] += tb[b[i]];
        tb[b[i]] = 0;
        cout << s << endl;
    }
}

Measured memory_bytes: 6756
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
#include <fstream>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    int n, a[10][10] = {};
    ll z = 0;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        string s = to_string(i);
        a[s[0] - '0'][s.back() - '0']++;
    }
    for (int i = 0; i < 10; i++) for (int j = 0; j < 10; j++) {
        for (int k = 0; k < 10; k++) for (int l = 0; l < 10; l++) {
            if (j == k && i == l) {
                if (i == k && j == l) {
                    z += 1ll * a[i][j] * a[k][l];
                } else {
                    z += 1ll * a[i][j] * a[k][l];
                }
            }
        }
    }
    cout << z;
}


Measured memory_bytes: 3732
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define rrep(i,n) for(int i=n-1; i>=0; i--)

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef long double lb;

const int INF=1<<27;
const int MOD=(int)1e9+7;

int main(void)
{
    int n, m;
    ll x[100010];
    ll y[100010];
    cin >> n >> m;
    rep(i,n) cin >> x[i];
    rep(i,m) cin >> y[i];
    ll sum_x = 0;
    ll sum_y = 0;
    rep(i,n){
        sum_x += (2*(i+1) - n - 1) * x[i];
        sum_x %= MOD;
    }
    rep(i,m){
        sum_y += (2*(i+1) - m - 1) * y[i];
        sum_y %= MOD;
    }
    ll ans = (sum_x * sum_y) % MOD;
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 1792
#include <bits/stdc++.h>
 
 
 
using namespace std;
 
 
 
#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define repf(i, f, l) for(int i = f; i < (int)l; ++i)
#define repit(it, t) for(__typeof((t).begin()) it = (t).begin(); it != (t).end(); it++)
#define endl "\n"
#define pb emplace_back
#define lb lower_bound
#define int long long
#define ul unsigned long
#define ull unsigned long long
#define ll long long
#define INF 1000000000000000007
#define MOD 1000000007
#define fs first
#define sd second
#define DBG0(x) { cout << #x << ": " << x << "\t"; }
#define DBG(x) {DBG0(x); cout << endl;}
#define DBG2(x, y) {DBG0(x); DBG(y);}
#define DBG3(x, y, z) {DBG0(x); DBG2(y, z);}
#define DBG4(w, x, y, z) {DBG0(w); DBG3(x, y, z);}
 
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<ul> vul;
typedef vector<ull> vull;
typedef vector<bool> vbl;
typedef pair<int, int> pii;
 
signed main(void){
    ios::sync_with_stdio(false);
    int n, m, s, t;
    cin >> n >> m >> s >> t;
    s--;
    t--;
 
    vector<map<int, int>> yen = vector<map<int, int>>();
    vector<map<int, int>> snu = vector<map<int, int>>();
    rep(i, n) {
        yen.push_back(map<int, int>());
        snu.push_back(map<int, int>());
    }
 
    vector<vint> edge = vector<vint>(n);
    rep(i, m) {
        int u, v, a, b;
        cin >> u >> v >> a >> b;
        u--;
        v--;
        yen[u][v] = a;
        snu[u][v] = b;
        yen[v][u] = a;
        snu[v][u] = b;
        edge[u].push_back(v);
        edge[v].push_back(u);
    }
 
    vint y = vint(n, INF);
    {
        y[s] = 0;
        priority_queue<pii, vector<pii>, greater<pii>> que;
        que.push(pii(0, s));
        while (que.size()) {
            int cur = que.top().second;
            que.pop();
            for (int nxt : edge[cur]) {
                int cost = yen[cur][nxt];
                if (y[cur] + cost < y[nxt]) {
                    y[nxt] = y[cur] + cost;
                    que.push(pii(y[nxt], nxt));
                }
            }
        }
    }
 
    vint ss = vint(n, INF);
    {
        ss[t] = 0;
        priority_queue<pii, vector<pii>, greater<pii>> que;
        que.push(pii(0, t));
        while (que.size()) {
            int cur = que.top().second;
            que.pop();
            for (int nxt : edge[cur]) {
                int cost = snu[cur][nxt];
                if (ss[cur] + cost < ss[nxt]) {
                    ss[nxt] = ss[cur] + cost;
                    que.push(pii(ss[nxt], nxt));
                }
            }
        }
    }
    vint ans = vint(n);
    rep(i, n) {
        ans[i] = 1000000000000000L - (y[i] + ss[i]);
    }

    for (int i = 1; i < n; ++i) {
        ans[n - i - 1] = max(ans[n - i], ans[n - i - 1]);
    }
    rep(i, n) {
        cout << ans[i] << endl;
    }
 
    return 0;
}


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

int main(){
    int num=1,n,cnt=0;
    cin >> n;
    vector<int> btn(n),visit(n);
    for(int i=0;i<n;i++)
        cin >> btn.at(i);
    while(cnt<n){
        num = btn.at(num-1);
        if(visit.at(num-1)==0)
            visit.at(num-1)=1;
        else{
            cnt = -1;
            break;
        }        
        cnt++;
        if(num==2)
            break;
    }
    if(cnt<n)
        cout << cnt << endl;
    else
        cout << -1 << endl;        
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < b; i++)
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int n;
int ans = 0;

void dfs(ll x) {
    if (n < x) return;
    int tmp = x;
    bool flag[3] = {};
    while (tmp > 0) {
        if (tmp % 10 == 3) flag[0] = true;
        if (tmp % 10 == 5) flag[1] = true;
        if (tmp % 10 == 7) flag[2] = true;
        tmp /= 10;
    }
    if (flag[0] && flag[1] && flag[2]) ans++;
    dfs(10 * x + 3);
    dfs(10 * x + 5);
    dfs(10 * x + 7);
}

int main()
{
    cin >> n;
    dfs(0);
    cout << ans << endl;
    return 0;
}


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

using namespace std;

#define all(x) (x).begin(), (x).end()
typedef long double ld;
typedef long long ll;

const int M = 200200;
const int T = 60;

int n;
int a[M];
vector<int> b;

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

bool check(int x) {
  if (b.empty())
    return true;

  int m = b.size();
  vector<int> cur(b[0], 0);
  for (int i = 1; i < m; ++i) {
    int n = cur.size();
    int nx = b[i];
    if (n < nx) {
      while ((int) cur.size() < nx) {
        cur.push_back(0);
      }
    } else {
      while ((int) cur.size() > nx) {
        cur.pop_back();
      }
      int j = nx - 1;
      while (j >= 0 && cur[j] == x - 1) {
        cur[j] = 0;
        --j;
      }
      if (j < 0) {
        return false;
      }
      cur[j]++;
      //cerr << i << ": ";
      //for (int x : cur) {
        //cerr << x << " ";
      //}
      //cerr << endl;
    }
  }
  return true;
}

void kill() {
  bool inc = true;
  for (int i = 0; i + 1 < n; ++i)
    inc &= a[i] < a[i + 1];

  if (inc) {
    cout << "1\n";
    return;
  }

  for (int i = 0; i < n; ++i)
    if (a[i] < T)
      b.push_back(a[i]);

  int l = 2, r = M;

  while (l < r) {
    int m = (l + r) / 2;
    if (check(m))
      r = m;
    else
      l = m + 1;
  }

  cout << l << "\n";

}

int main() {
#ifdef LOCAL
  assert(freopen("c.in", "r", stdin));
#endif

  ios_base::sync_with_stdio(false);

  read();
  kill();

}



Measured memory_bytes: 2168
#include <iostream>
#include <fstream>
#include <typeinfo>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<25;
const double pi=acos(-1);
const double eps=1e-8;
const vi emp;

int M,m;

int main(){
	for(int i=0;i<7;i++){
		cin>>M>>m;
		cout<<M-m<<endl;
	}
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7;

ll dfs(int K,const vector<vector<int>> &graph,int now,int from){
    int can_use_color_num;
    if(from==-1){
      can_use_color_num=K-1;
    }
    else{
      can_use_color_num=K-2;
    }
    if(K<graph[now].size()){
        return 0;
    }
    else{
        ll case_num=1;
        for(auto e:graph[now]){
            if(e==from)continue;
            case_num*=can_use_color_num;
            can_use_color_num--;
            case_num%=mod;
        }
        for(auto e:graph[now]){
            if(e==from)continue;
            case_num*=dfs(K,graph,e,now);
            case_num%=mod;
        }
        return case_num;
    }
}
int main() {
    int N,K;cin>>N>>K;
    vector<vector<int>>graph(N); for(int i=0;i<N-1;++i){
    int a,b;cin>>a>>b;a--;b--;
    graph[a].push_back(b);
    graph[b].push_back(a); }
    long long int answer=K*dfs(K,graph,0,-1);
  	answer%=mod;
    cout<<answer<<endl;
    return 0;
}
    




/*



 */



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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(x) (x).begin(),(x).end()
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

vector<vector<int>> g;
vi ans,c,seen;

void dfs(int x,int y){
    seen[x]=true;
    for(int i=0;i<g[x].size();++i){
        if(!seen[g[x][i]]){
        ans[g[x][i]]+=y;
        dfs(g[x][i],ans[g[x][i]]);}
    }
}

int main(){
    int n,q;cin>>n>>q;
    g.resize(n);
    ans.resize(n);
    c.resize(n);
    seen.resize(n);
    rep(i,n){ans[i]=0;c[i]=0;seen[i]=false;}
    rep(i,n-1){
        int a,b;
        cin>>a>>b;
        a--;b--;
        g[a].PB(b);
        g[b].PB(a);
    }
    vi p(q),x(q);
    rep(i,q){
        cin>>p[i]>>x[i];
        p[i]--;
        c[p[i]]+=x[i];
    }
    rep(i,n){
        ans[i]+=c[i];
    }
    dfs(0,ans[0]);
    rep(i,n){
        if(i!=n-1)cout<<ans[i]<<" ";
        else cout<<ans[i]<<endl;
    }
}


Measured memory_bytes: 23552
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int L = scan.nextInt();
        int D = scan.nextInt();
        int d = scan.nextInt();
        int count = 0;
        for(int i=L;i<=D;i++){
            if(i%d==0){
                count++;
            }
        }
        System.out.println(count);



    }
}

Measured memory_bytes: 35568