akhauriyash/Code-Regression huggingface dataset:
# coding:utf-8

import sys
import math
import time
#import numpy as np
import collections
from collections import deque
import queue
import copy


#X = str(input()).split()
#a = [int(x) for x in input().split()]


NM = str(input()).split()
N = int(NM[0])
M = int(NM[1])

p = (1/2)**M
q = 1/p

ans = q*(M*1900)+q*((N-M)*100)

print(int(ans))



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

int main(){
    int n,y;
    cin >> n >> y;
    int sum=0;
    int a=0,b =0,c =0;
    if(y/10000 > n){
        cout << "-1 -1 -1"<<endl;
        return 0;
    }
    for(a =0;a<=(y/10000);a++){
        for(b=0;b<=(y/5000);b++){

            c = (y-10000*a-5000*b)/1000;
            if(c<0){
                continue;
            }
            if(a+b+c == n){
                cout << a <<endl << b  << endl << c<<endl;
                return 0;
            }
        }
    }
    cout << "-1 -1 -1" << endl;
    return 0;

}

Measured memory_bytes: 256
#include <iostream>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include <cstdlib>
using namespace std;
long long  a[200000];
long long  n,a1,b1;
long  check(long long  zhi)
{
    long long  t=b1*zhi;
    long long  add=0;
    for(int i=1;i<=n;i++)
    {
        if(a[i]-t>0)
        {
            if((a[i]-t)%(a1-b1)==0)
                add+=(a[i]-t)/(a1-b1);
            else
                add+=(a[i]-t)/(a1-b1)+1;
        }
    }
    return add<=zhi;
}
int  main()
{
    cin>>n>>a1>>b1;
    for(int i=1;i<=n;i++)
        scanf("%d",&a[i]);
    long long  st=0,en=1e9;
    long long  mid;
    int t;
    while(st<en-1)
    {
        mid=(en+st)>>1;
        if(check(mid))
        {
            en=mid;
            t=mid;
        }
        else
            st=mid;
    }
    cout<<en<<endl;
    //system("pause");
    return 0;
}


Measured memory_bytes: 1024
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil,pi,factorial
    from operator import itemgetter
    def I(): return int(input())
    def MI(): return map(int, input().split())
    def LI(): return list(map(int, input().split()))
    def LI2(): return [int(input()) for i in range(n)]
    def MXI(): return [[LI()]for i in range(n)]
    def SI(): return input().rstrip()
    def printns(x): print('\n'.join(x))
    def printni(x): print('\n'.join(list(map(str,x))))
    inf = 10**17
    mod = 10**9 + 7
#main code here!
    n=I()
    lis=LI()
    lis.sort()
    #print(lis)
    sm=list(accumulate(lis))
    #print(sm)
    count=1
    for i in range(n-1):
        j=n-1-i
        if 2*sm[j-1]>=lis[j]:
            count+=1
        else:
            break
    print(count)
    






if __name__=="__main__":
    main()


Measured memory_bytes: 94932
#include<bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 1;

int main() {
	int n;
	cin >> n;
	vector<int> h(n);

	for(int i = 0 ; i < n ; i++) cin >> h[i];

	vector<int> dp(n, inf);

	dp[0] = 0;

	// for(int i = 0 ; i < n ; i++)cout << dp[i] << " ";
	// cout << "\n";
	for(int i = 0 ; i < n ; i++) {
		// int x[] = {i + 1, i + 2};
		// cout << x[0] << " : " << x[1] << endl; 
		for(int j = i + 1; j < i + 3; j++) {
			if(j < n) {
				// cout << 1;
				dp[j] = min(dp[j], dp[i] + abs(h[i] - h[j]));
			}
		}
		// cout << endl;
	}
	cout << dp[n - 1] << endl;
	return 0;
}


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

int main(){
    int a,b,c,ans=0;
    cin>>a>>b>>c;

    if(b>=c||a+b>=c){
        cout<<b+c<<endl;
        return 0;
    }

    ans+=a+(b*2);

    if(c-b-a!=0) ans++;

    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <list>
#include <set>
#include <stack>
#include <deque>
#include <queue>
#include <cmath>
#include <algorithm>
#include <utility>
#include <functional>
#include <fstream>
#define debug(x) cout << #x << " = " << x << endl
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define repr(i,n) for(int i = (n); i > -1; i--)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const double EPS = 1e-9;


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

  ll n,m;
  cin>>n>>m;
  ll mx = max(n,m);
  ll mi = min(n,m);
  ll diff = mx - mi;
  ll ans = 1;
  if(diff == 0) {
    FOR(i, 1, mx + 1) {
      ans = ans * i % MOD;
    }
    FOR(i, 1, mx + 1) {
      ans = ans * i % MOD;
    }
    ans = ans * 2 % MOD;
  } else if(diff == 1) {
    FOR(i, 1, n + 1) {
      ans = ans * i % MOD;
    }
    FOR(i, 1, m + 1) {
      ans = ans * i % MOD;
    }
  } else {
    ans = 0;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#include <bitset>
#define M 1000000007
#define M1 998244353

#define tr(container, it) \
for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)

#define fast                        \
  ios_base::sync_with_stdio(false); \
  cin.tie(NULL);

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

ll power(ll x, ll n)
{
    ll result = 1;
    while (n)
    {
        if (n % 2 == 1)
            result = result * x;
        n = n / 2;
        x = x * x;
    }
    return result;
}

ll gcd(ll a, ll b)
{
    if (!b)
        return a;
    return gcd(b, a % b);
}

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

inline ll mul(ll x, ll y, ll m)
{
    ll z = 1LL * x * y;
    if (z >= m)
    {
        z %= m;
    }
    return z;
}

ll powmod(ll x, ll y, ll m)
{
    ll r = 1;
    while (y)
    {
        if (y & 1)
        {
            r = mul(r, x, m);
        }
        y >>= 1;
        x = mul(x, x, m);
    }
    return r;
}



void start()
{
    fast;
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
}
/***********************************************************************************************************/

int main()
{
    start();
    int n, a, b;
    cin>>n>>a>>b;
    string s;
    cin>>s;
    int c=0;
    int d=0;
    for (int i=0;i<n;i++)
    {
        if (s[i]=='a')
        {
            if (c<a+b)
            {
                cout<<"Yes"<<"\n";
                c++;
            }
            else
            {
                cout<<"No"<<"\n";
            }
        }
        else if (s[i]=='b')
        {
            if (c<a+b&&d<b)
            {
                cout<<"Yes"<<"\n";
                c++;
                d++;
            }
            else
            {
                cout<<"No"<<"\n";
            }
        }
        else
        {
            cout<<"No"<<"\n";
        }
    }
    return 0;
}

Measured memory_bytes: 3752
#include <bits/stdc++.h>
using namespace std;
int main(){
	long long a,b,c;
	cin>>a>>b>>c;
	int ar[11];
	ar[0]=c;
	for(int i=1;i<=10;i++){
		ar[i]=a*ar[i-1]-b;
		cout<<ar[i]<<endl;
	}
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
#define pb push_back
#define sz(x) ((int)(x).size())
#define all(x) x.begin(),x.end()
#define dmp(x) cerr<<#x<<":"<<x<<endl
#define FOR(i,a,b) for(int i=(int)a,c=(int)b;i<c;++i)
#define rep(i,b) FOR(i,0,b)
#define ROF(i,a,b) for(int i=b-1,c=(int)a;i>=c;--i)
#define per(i,b) ROF(i,0,b)
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

signed main(){
  int n,k;
  cin>>n>>k;
  double d[11111];
  d[0]=1;
  for(int i=1;i<11111;i++){
    d[i]=d[i-1]/2.0;
  }
  double ans=0;
  for(int i=1;i<=n;i++){
    double t=i;
    for(int j=0;;j++){
	 if(t>=k){
	   ans+=1.0/(double)n*d[j];
	   break;
	 }
	 t*=2;
    }
  }
  printf("%.12lf\n",ans);
  return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll inf=1e9+7;
ll L[51];
ll f(ll n,ll x){
    if(n==0)return 1;
    else if(x==1)return 0;
    else if(x>=1&&x<=1+L[n-1])return f(n-1,x-1);
    else if(x==L[n-1]+2)return f(n-1,L[n-1])+1;
    else if(x>=(L[n-1]+3)&&x<=(2*(L[n-1]+1)))return f(n-1,L[n-1])+1+f(n-1,x-(L[n-1]+2));
    else if(x==(2*L[n-1]+3))return 2*f(n-1,L[n-1])+1;
    return 0;
}
int main(){
    ll n,x;cin>>n>>x;
    L[0]=1;
    REP(i,1,n+1){
        L[i]=L[i-1]*2+3;
    }
    cout<<f(n,x)<<endl;
}

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

using namespace std;

typedef long long ll;
const long long mod = 1000000007;



int main(){
   ll n, i, j;
    
   cin>>n; 
   double p[n];

   for(i = 0;i < n;i++)
    cin>>p[i];

  
    double dp[n + 1][n + 1]; 
    memset(dp, 0.0, sizeof(dp)); 
  
    dp[0][0] = 1.0; 
  
    for (int i = 1; i <= n; i += 1) { 
  
        for (int j = 0; j <= i; j += 1) { 
  
          
            if (j == 0) 
                dp[i][j] = dp[i - 1][j] 
                           * (1.0 - p[i-1]); 
            else
                dp[i][j] = dp[i - 1][j] 
                               * (1.0 - p[i-1]) 
                           + dp[i - 1][j - 1] * p[i-1]; 
        } 
    } 
  
    double ans = 0.0; 
  
   
    for (int i = (n + 1) / 2; i <= n; i += 1) 
        ans += dp[n][i]; 

    cout<<setprecision(12)<<ans;
} 


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

using namespace std;

int main(){
    long long l, r; cin >> l >> r;
    long long ans=2019;
    if(r-l>=2019){
        ans=0;
    } else{
        for(long long li=l; li<r; ++li){
            for(long long ri=li+1; ri<=r; ++ri){
                ans=min(ans, (li*ri) % 2019);
            }
        }
    }
    cout << ans << endl;
    return 0;
}



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

using namespace std;

int main()
{
    string S;
    cin >> S;
    int ans = 0;
    int count = 0;
    //cout << ans << endl;
    while (count + 1 < S.size())
    {
        if (S[count] != S[count + 1])
        {
            S = S.erase(count, 2);
            count--;
            if (count < 0)
            {
                count = 0;
            }
            ans = ans + 2;
        }
        else
        {
            count++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 512
n = int(input())
array = list(map(int, input().split()))

total = 0
flag = -1
minus = 0
for tmp in range(len(array)):
    total += array[tmp]
    if total * flag <= 0:
        minus += abs(total*flag)+1
        total = flag
    flag *= -1

total = 0
flag = 1
plus = 0
for tmp in range(len(array)):
    total += array[tmp]
    if total * flag <= 0:
        plus += abs(total*flag)+1
        total = flag
    flag *= -1

print(min(minus, plus))

Measured memory_bytes: 14468
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()
#define LL long long

using namespace std;

int main(){
    int N;cin>>N;
    int x[N];
    REP(i,N)cin>>x[i];
    LL L;cin>>L;
    int logN = (int)log2(N) + 1;

    int doub[N][logN+1];
    fill(doub[0],doub[N],x[N-1]+1);
    REP(i,N-1)doub[i][0]=upper_bound(x,x+N,x[i]+L)-x-1;
    REP(k,logN)REP(i,N)doub[i][k+1]=doub[min(N-1,doub[i][k])][k];





    int q;cin>>q;
    REP(i,q){
        int a,b;cin>>a>>b;
        if(a>b)swap(a,b);
        a--;b--;

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

        cout<<(a==b ? ans:ans+1)<<endl;
    }
    return 0;
}

Measured memory_bytes: 8192
#include<iostream>
#include<string>
#include<algorithm>
#include <stdio.h>
#include<iostream>
#include<iomanip>
#include<cmath>
#include<array>
#include<vector>
#include<set>
#include <utility>
#include <map>
using namespace std;
long long max(long long a ,long long b){
  if(a>b)return a;
  else return b;
}
int main(){
  int n,m; cin >> n>>m;
  int left=0,right=n;
  for(int i=0;i<m;i++){
  int l,r; cin>>l>>r;
  left=max(left,l);
  right=min(right,r);
  }
  if(left>right) cout<<0<<endl;
  else cout<<right-left+1<<endl;
}


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

namespace Internship
{
    class Program
    {
        static void Main(string[] args)
        {
            int seconds = int.Parse(Console.ReadLine());
            int s = seconds % 60;
            int m = seconds / 60 % 60;
            int h = seconds / 60 / 60;
            Console.WriteLine("{0}:{1}:{2}", h, m, s);
        }
    }
}

Measured memory_bytes: 9148
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
//#include <boost/math/common_factor_rt.hpp>
#define USE_MATH_DEFINES
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;
namespace mp = boost::multiprecision;
// namespace mt = boost::math
using Bint = mp::cpp_int;

int main() {
    int n, k;
    cin >> n >> k;
    Bint ans = n - k + 1;
    cout << ans << endl;
    for (int i = 1; i < k; i++) {
        ans = ans * (n - k - i + 1) * (k - i) / (i + 1) / i;
        cout << ans % 1000000007 << endl;
    }
}

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

#include <cstdio>
using namespace std;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define deg_to_rad(deg) (((deg) / 360) * 2 * M_PI)
#define rad_to_deg(rad) (((rad) / 2 / M_PI) * 360)

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

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

typedef long long ll;

void solve(long long N, std::vector<long long> A) {
    ll buka[200001] = {};
    for (auto i : A) {
        buka[i]++;
    }
    for (int i = 1; i <= N; i++) {
        cout << buka[i] << endl;
    }
}

int main() {
    long long N;
    scanf("%lld", &N);
    std::vector<long long> A(N - 2 + 1);
    for (int i = 0; i < N - 2 + 1; i++) {
        scanf("%lld", &A[i]);
    }
    solve(N, std::move(A));
    return 0;
}


Measured memory_bytes: 6452
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll MOD=1e9+7;
void solve()
{
	ll x,k,d;
	cin>>x>>k>>d;
	if(x>0)
	{
		// moves needed to reach the smallest +ve no
		ll m=x/d;
		if(m<=k)
		{
			x-=m*d;
			k-=m;
		}
		else
		{
			x-=k*d;
			k=0;
		}
		ll ans=x;
		if(k%2!=0) ans=abs(x-d);
		cout<<ans<<"\n";
	}
	else
	{
		// to reach the smallest -ve no
		ll m=-x/d;
		if(m<=k)
		{
			x+=m*d;
			k-=m;
		}
		else
		{
			x+=k*d;
			k=0;
		}
		ll ans=abs(x);
		if(k%2!=0) ans=abs(x+d);
		cout<<ans<<"\n";
	}
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	solve();
	return 0;
}

Measured memory_bytes: 3596
import java.util.*;

class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    Integer a[] = new Integer[n];
    Integer b[] = new Integer[n];
    for (int i=0; i<n; i++){
      a[i] = sc.nextInt();
    }
    for (int i=0; i<n; i++){
      b[i] = sc.nextInt();
    }
    int sum =0;   
    for (int i=0; i<n; i++){
      int v = a[i] -b[i];
      if (v>0){
        sum += v;
      }
    }
    System.out.println(sum);
  }
}

Measured memory_bytes: 22612
// IOI 2021
#include <bits/stdc++.h>
using namespace std;
 
#define endl '\n'
#define ends ' '
#define die(x) return cout << x << endl, 0
#define all(v) v.begin(), v.end()
#define sz(x) (int)(x.size())
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cerr << ends << H; debug_out(T...); }
#define debug(...) cerr << "{" << #__VA_ARGS__ << "}:", debug_out(__VA_ARGS__)
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
 
////////////////////////////////////////////////////////////////////
 
const int N = 2e3 + 5;

int A[N << 1], DP[N][N], B[N], W[N], BW[N][N], WB[N][N], WW[N], BB[N];
char C[N << 1];

int main() {
 
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	mt19937 Rnd(time(0));

	int n; cin >> n;
	for (int i = 0; i < n + n; i++) cin >> C[i] >> A[i], A[i]--, (C[i] == 'B' ? B : W)[A[i]] = i;
	for (int i = 0; i < n; i++) for (int j = 0; j < i; j++) WW[i + 1] += (W[j] > W[i]), BB[i + 1] += (B[j] > B[i]);
	for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) BW[i + 1][j + 1] = BW[i + 1][j] + (W[j] > B[i]), WB[i + 1][j + 1] = WB[i + 1][j] + (B[j] > W[i]);
	for (int i = 0; i <= n; i++) for (int j = 0; j <= n; j++) if (i + j > 0) {
		DP[i][j] = INF;
		if (i) DP[i][j] = min(DP[i][j], DP[i - 1][j] + BB[i] + BW[i][j]);
		if (j) DP[i][j] = min(DP[i][j], DP[i][j - 1] + WW[j] + WB[j][i]);
	}
	cout << DP[n][n] << endl;

	return 0;
}


Measured memory_bytes: 50676
import math
a, b, h, m = map(int, input().split())

ji_arg = (h * 30) + (m / 2)
hun_arg = 6 * m
if abs(ji_arg - hun_arg) <= 180:
    c = abs(ji_arg - hun_arg) * math.pi / 180
    x = a ** 2 + b ** 2 - 2 * a * b * math.cos(c)
    x = math.sqrt(x)
    print(x)
else:
    c = abs(360 - ji_arg + hun_arg) * math.pi / 180
    x = a ** 2 + b ** 2 - 2 * a * b * math.cos(c)
    x = math.sqrt(x)
    print(x)

Measured memory_bytes: 9532
#include<stdio.h>
#include<string.h>
int main(){
    char w[6];
    char s[]="Sunny";
    char c[]="Cloudy";
    char r[]="Rainy";
    scanf("%s",w);
    if(strcmp(w,s)==0){
        printf("%s\n",c);
    }
    if(strcmp(w,c)==0){
        printf("%s\n",r);
    }
    if(strcmp(w,r)==0){
        printf("%s\n",s);
    }
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const double PI = acos(-1.0);
const double eps = 1e-6;
const int INF = 1000000000;
const int mod = 1e9+7;
const int maxn = 2e5+5;
ll n,m;
int dp[1005][15];
string s;
ll dfs1(ll pos,ll dep){
	if(dep==0) return 1;
	if(pos==s.length()) return 0;
	ll ans = 0;
	ans+=dfs1(pos+1,dep);
	ans%=mod;
	ans+=(9*dfs1(pos+1,dep-1)%mod);
	ans%=mod;
	return ans%mod;
}
ll dfs2(ll pos,ll dep){
	if(dep==0) return 1;
	if(pos==s.length()) return 0;
	ll ans = 0;
	if(s[pos]=='0') ans+=dfs2(pos+1,dep);
	if(s[pos]>'0')
		ans+=dfs1(pos+1,dep);
	ans%=mod;
	//cout<<ans<<endl;
	if(s[pos]>'0')
		ans+=dfs2(pos+1,dep-1);
	ans%=mod;
	if(s[pos]>'0')
		ans+=(dfs1(pos+1,dep-1)*(s[pos]-'0'-1)%mod);
	ans%=mod;
	return ans%mod;
}
int main() {
	cin>>s;
	cin>>n;
	ll ans = 0;
	ans+=dfs2(1,n-1);
	ans%=mod;
	ans+=(dfs1(1,n-1)*(s[0]-'0'-1)%mod);
	ans%=mod;
	ans+=dfs1(1,n);
	cout<<(ans+mod)%mod;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define Rep(i,j,n) for(int i=j; i<n; i++)
#define rep(i,n) for(int i=0; i<n; i++)
#define PI 3.14159265359
#define INF 1000100100//000000000
#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define P pair<int, int>
#define PP pair<int,P>
#define T tuple<int,int,int> 
using namespace std;

int main(){
  int n,m; cin >> n >> m;
  cout << pow(2,m)*(1900*m+100*(n-m)) << endl;
  return 0;
}


Measured memory_bytes: 4212
import numpy as np
n = int(input())
arr = np.array(list(map(int, input().split())))

big = arr.max()
arr = np.delete(arr, arr.argmax())

if big % 2 == 0:
    small = arr[(np.abs(arr - big // 2)).argmin()]
else:
    a = (np.abs(arr - (big + 1) // 2)).min()
    b = (np.abs(arr - (big) // 2)).min()
    if a <= b:
        small = arr[(np.abs(arr - (big + 1) // 2)).argmin()]
    else:
        small = arr[(np.abs(arr - big // 2)).argmin()]

print(big, small)

Measured memory_bytes: 23056
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import time,random

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
mod2 = 998244353
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)


def main():
    n,m = LI()
    h = LI()
    ab = [LI_() for _ in range(m)]
    r = [1] * n
    for a,b in ab:
        if h[a] <= h[b]:
            r[a] = 0
        if h[b] <= h[a]:
            r[b] = 0

    return sum(r)


print(main())





Measured memory_bytes: 32168
//abc043_b.cpp
//Sun Oct 21 10:27:30 2018

#include <iostream>
#include <string>
#include <queue>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <stack>
#define INTINF 2147483647
#define LLINF 9223372036854775807
using namespace std;
using ll=long long;
typedef pair<int,int> P;

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

	string t;
	for (int i=0;i<s.size();i++){
		if (s[i] == '0' || s[i] == '1'){
			t += s[i];
		}else if (t.size() != 0) {
			t.pop_back();
		}
	}

	cout << t << endl;
}

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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) (x).begin(),(x).end()
#define endl "\n"

using ll = long long;
using P = pair<int,int>;
using mp =  map<string,int>;

const int MOD = 1e9 + 7;
const int INF = 1001001001;

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

    int n;
    cin >> n;
    map<int, int> mp;
    rep(i, n){
        int a;
        cin >> a;
        mp[a]++;
        if(mp[a] == 2) mp.erase(a);
    }

    int ans = 0;
    for (auto& p : mp) {
        ans += p.second;
    }

    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 4992
#include <iostream>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cstdio>
#include <math.h>
#include <map>
#include <queue>
#include <string>
using namespace std;

int n;
char s[1000001],s2[1000001];

int main(){
	while(cin>>n){
		if(n==0)return 0;
		for(int i=0;i<10001;i++){s[i]=0;s2[i]=0;}
		cin>>s;
		int l=0;
		while(isdigit(s[l]))l++;
		for(int i=0;i<n;i++){
			int m,t=0,cur=0;
			for(int j=0;j<l;j++){
				if(t==0){m=s[j]-'0';t=1;}
				else {
					if(s[j]-'0'==m)t++;
					else {
						int f=0;
						if(t>99){s2[cur++]=t/100+'0';t%=100;f=1;}
						if(t>9||f){s2[cur++]=t/10+'0';t%=10;}
						s2[cur++]=t+'0';
						s2[cur++]=m+'0';
						m=s[j]-'0';t=1;
					}
				}
			}
			int f=0;
			if(t>99){s2[cur++]=t/100+'0';t%=100;f=1;}
			if(t>9||f){s2[cur++]=t/10+'0';t%=10;}
			s2[cur++]=t+'0';
			s2[cur++]=m+'0';
			for(int i=0;i<cur;i++)s[i]=s2[i];
			l=cur;
		}
		for(int i=0;i<l;i++)cout<<s[i];
		cout<<endl;
	}
}

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

using namespace std;

int main(){
  int64_t n,p;
  cin >> n;
  for(int i = sqrt(n);i > 0;i--){
    if(n % i == 0){
      p = i;
      break;
    }
  }
  cout << p + n/p - 2;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#define fastIO ios_base::sync_with_stdio(false);cin.tie(NULL);
using namespace std;
 
int main(){
  fastIO;
  int h,w;
  cin>>h>>w;
  
  for(int i=0;i<h;i++){
    string s;
    cin >> s;
    cout << s << endl << s << endl;
  }
  
  return 0;
}


Measured memory_bytes: 3668
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>

using namespace std;

long long n,a[200005],rj[200005],sl,najm,k=1;

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

cin >> n;

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

//sort (a,a+n);

for (int i = 0;i<n;i++){
	if ( a[i] == k){
		sl++;
		k++;
	}
}

if (sl != 0)
	cout << n-sl;
else
	cout << -1;

return 0;
}



Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
#define repi(i,n) for(int i=0;i<(int)(n);i++)
#define repd(i,n) for(int i=(int)(n);i>=0;i--)
#define repm(i,m) for(auto i=m.begin();i!=m.end();i++)

int main()
{
    int N;
    cin >> N;
    vector<int> A(N);
    repi(i,N){
        cin >> A[i];
    }
    int cnt = 0;
    repi(i,N){
        while(A.at(i)%2 == 0){
            A.at(i)/=2;
            cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}

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

int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);
	int n,m;
	cin>>n>>m;
	int res=(100*(n-m)+1900*m)*(1<<m);
	cout<<res<<'\n';
}



Measured memory_bytes: 3628
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
typedef long long int keytype;

//quicksort(<#keytype *a#>, <#int first#>, <#int last#>)

void quicksort(keytype a[], long long int first, long long int last){
    long long int i, j;
    keytype x, t;
    
    x = a[(first + last) / 2];
    i = first;  j = last;
    for ( ; ; ) {
        while (a[i] < x) i++;
        while (x < a[j]) j--;
        if (i >= j) break;
        t = a[i];  a[i] = a[j];  a[j] = t;
        i++;  j--;
    }
    if (first  < i - 1) quicksort(a, first , i - 1);
    if (j + 1 < last) quicksort(a, j + 1, last);
}

int main() {
    long long int a[3];
    scanf("%lld %lld %lld",&a[0],&a[1],&a[2]);
    quicksort(a, 0, 2);
    if (a[0]==a[1] && a[1]==a[2]){
        printf("No");
    }else if(a[0]==a[1] || a[1]==a[2]){
    	printf("Yes");
    }else{
    	printf("No");
    }
    
    return 0;
}


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

using namespace std;
using ll = long long;

const int N = 100 + 5;
const int K = 1e5 + 5;
const int MOD = 1e9 + 7;

ll dp[N][K];

int main() { 
    ios_base::sync_with_stdio(false); 
    cin.tie(0);
    int n, k;
    cin >> n >> k;
    vector<int> a(n + 1);
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    dp[0][0] = 1;
    for (int i = 1; i <= n; i++) {
        vector<int> sum(k + 1);
        sum[0] = dp[i - 1][0];
        for (int j = 1; j <= k; j++) {
            sum[j] = (sum[j - 1] + dp[i - 1][j]) % MOD;
        }
        for (int j = 0; j <= k; j++) {
            // for (int give = 0; give <= min(a[i], j); give++) {
            //     (dp[i][j] += dp[i - 1][j - give]) %= MOD;
            // }
            int add = sum[j];
            int leave = j - a[i] - 1;
            if (leave >= 0) {
                add = (add - sum[leave] + MOD) % MOD;
            }
            dp[i][j] = add;
        }
    }
    cout << dp[n][k] << '\n';
}


Measured memory_bytes: 79740
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<string>


using namespace std;
typedef long long ll;
typedef pair<int, int> pr;
const int maxn = 3e5;
const int inf = 0x3f3f3f3f;

char s[300];
int main() {
	int n;
	while (~scanf("%d", &n)) {
		scanf("%s", &s);
		int res = 0;
		int len = strlen(s);
		for(int i = 0; i < len; ++i)
			if (s[i] == 'A') {
				if (i + 2 < len && s[i + 1] == 'B' && s[i + 2] == 'C') ++res;
			}
		printf("%d\n", res);
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    int H,N;
    cin >>H;
    cin >>N;
    int arr[N];
    for(int i=0;i<N;i++)
        cin>>arr[i];
    for(int i=0;i<N;i++)
    {
       H=H-arr[i];
    }
    if (H<=0)
        cout<<"Yes";
    else
        cout<<"No";
    return 0;
}


Measured memory_bytes: 640
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

int main(void) {
  int a, b;
  scanf("%d%d", &a, &b);
  if (a <= 0 && 0 <= b) {
    puts("Zero");
  } else if (a > 0) {
    puts("Positive");
  } else {
    int cnt = b - a + 1;
    if (cnt & 1) puts("Negative");
    else puts("Positive");
  }
}


Measured memory_bytes: 128
#include<stdio.h>
#define MAX 100000
#define SENTINEL 2000000000

typedef struct Card{
    char suit;
    int value;
}Card;

Card L[MAX/2 + 2],R[MAX/2 + 2];

void merge(Card A[], int n, int left, int mid, int right){
    int i,j,k;
    int n1 = mid-left;
    int n2=right-mid;
    for(i=0;i<n1;i++) L[i]=A[left+i];
    for(i=0;i<n2;i++) R[i]=A[mid+i];
    L[n1].value=R[n2].value=SENTINEL;
    i=j=0;
    for(k=left;k<right;k++){
        if(L[i].value<=R[j].value){
            A[k]=L[i++];
        }else{
            A[k]=R[j++];
        }
    }
}

void mergeSort(Card A[], int n, int left, int right){
    int mid;
    if(left+1<right){
        mid = (left+right)/2;
        mergeSort(A,n,left,mid);
        mergeSort(A,n,mid,right);
        merge(A,n,left,mid,right);
    }
}

int partition(Card A[], int n, int p, int r){
    int i,j;
    Card x,t;
    x=A[r];
    i=p-1;
    for(j=p;j<r;j++){
        if(A[j].value<=x.value){  //xより小さいとき
            i++;
            t=A[i];
            A[i]=A[j];
            A[j]=t;
        }
    }
    t=A[i+1];
    A[i+1]=A[r];
    A[r]=t;
    return i+1;
}

void quickSort(Card A[], int n, int p, int r){
    int q;
    if(p<r){
        q=partition(A,n,p,r);
        quickSort(A,n,p,q-1);
        quickSort(A,n,q+1,r);
    }
}

int main(void){
    int n,i,v;
    Card A[MAX],B[MAX];
    char S[10];
    int stable=1;
    scanf("%d",&n);
    
    for(i=0;i<n;i++){
        scanf("%s %d",S,&v);
        A[i].suit=S[0];
        B[i].suit=S[0];
        A[i].value=v;
        B[i].value=v;
    }
    
    mergeSort(A,n,0,n);
    quickSort(B,n,0,n-1);
    
    for(i=0;i<n;i++){
        if(A[i].suit!=B[i].suit){
            stable=0;
            break;
            //printf("nnn %c %d %c %d\n",A[i].suit,A[i].value,B[i].suit,B[i].value);
        }
    }
    if(stable==1) printf("Stable\n");
    else printf("Not stable\n");
    for(i=0;i<n;i++){
        printf("%c %d\n",B[i].suit,B[i].value);
    }
    return 0;
}



Measured memory_bytes: 4048
#include <iostream>
#include <cstdint> 
#include <vector>
#include <algorithm>
#include <numeric>

using namespace std;
 
int main(){
    int n;
    cin >> n;
    
    vector<int> score(n);
    vector<int> sum(n);
    
    for(int i = 0; i < n; ++i){
        cin >> score[i];
    }
    
    int allsum = std::accumulate(begin(score), end(score), 0);
    
    if(allsum % 10 != 0){
        cout << allsum << endl;
        return 0;
    }
    
    for(int i = 0; i < n; ++i){
        sum[i] = allsum - score[i];
    }
        
    for(int& s : sum){
        if(s % 10 == 0) s = 0;
    }
    
    cout << *max_element(begin(sum), end(sum)) << endl;   
 
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int counter(int n,vector<int>L){
 int c =0;
    sort(L.begin(),L.end());
    REP(i,n){
        FOR(j,i,n){
            FOR(k,j,n){
               if( L.at(i)+L.at(j)>L.at(k)
                   && L.at(i)!=L.at(j)
                   && L.at(j)!=L.at(k)){
                   c++;
               }

            }
        }
    }

    return c;

}

int main(){
 int n;
 cin >>n;
 vector<int>L(n);
 REP (i,n)cin>>L.at(i);

 cout <<counter(n,L)<<endl;
}

Measured memory_bytes: 3612
#include "bits/stdc++.h"
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)
#define ALL(v) v.begin(), v.end()
#define FS first
#define SC second
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())
#define MEMSET(v, h) memset((v), h, sizeof(v))
#define SQR(x) ((x) * (x))
#define BIT(n) (1LL<<(n))
#define PCNT(x) __builtin_popcountll(x)
#define GCD(x,y) __gcd(x,y)
#define LCM(x,y) x/__gcd(x,y)*y
#define PB push_back
#define MP make_pair
#define endl "\n"
using namespace std;
typedef long long lint;
typedef long long LL;
typedef long double LD;
typedef vector<int> VI;
typedef vector<LL> VLL;
typedef vector<bool> VB;
typedef vector<vector<int> > VVI;
typedef vector<vector<LL> > VVLL;
typedef vector<vector<bool> > VVB;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
const LL MOD=1000000007ll;
const LL INF=2000000000ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int dx[4] = {1,0,-1,0};
int dy[4] = {0,1,0,-1};

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

    string s,t,u;
    cin >> s;

    t = s;
    reverse(ALL(t));
    int f = 0, N = s.length();
    if (s == t) {
      f++;
    }

    t = s.substr(0,(N-1)/2);
    u = t;
    reverse(ALL(u));
    if (t == u) f++;

    t = s.substr((N+1)/2);
    u = t;
    reverse(ALL(u));
    if (t == u) f++;

    if (f == 3) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

void move(int,int);
int count=0;
char Map[20][21];
int main()
{
  int i,j,ii,jj,w,h;
  while(1){
    scanf("%d%d",&w,&h);
    // printf("%d %d\n",w,h);
    if(w==0&&h==0)break;
    for(i=0;i<20;i++){
      for(j=0;j<21;j++)Map[i][j]='#';
    }
    for(i=0;i<h;i++){
      scanf("%s",Map[i]);
    }
    for(i=0;i<h;i++){
      for(j=0;j<w;j++){
	if(Map[i][j]=='@'){
          ii=i;
	  jj=j;
	}
      }
    }
    move(ii,jj);
    printf("%d\n",count);
    count=0;
  }
  return 0;
}

void move(int hh,int ww)
{
  if(hh<0||ww<0||Map[hh][ww]=='#')return;
  Map[hh][ww]='#';
  count++;
  if(Map[hh-1][ww]=='.')move(hh-1,ww); 
  if(Map[hh+1][ww]=='.')move(hh+1,ww);
  if(Map[hh][ww-1]=='.')move(hh,ww-1); 
  if(Map[hh][ww+1]=='.')move(hh,ww+1);
}

Measured memory_bytes: 620
#include "bits/stdc++.h"

using namespace std;

using u32 = uint32_t;
using u64 = uint64_t;
using i64 = int64_t;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define F0R(i,b) FOR(i,0,b)
#define RFO(i,a,b) for (int i = (b-1); i >= a; i--)
#define RF0(i,b) RFO(i,0,b)

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

  int N;
  cin >> N;

  vector<int> balls;
  balls.reserve(N);
  unordered_map<int, u64> cnt;

  F0R(i, N) {
    int a;
    cin >> a;

    balls.push_back(a);

    auto it = cnt.find(a);
    if (it != cnt.end()) {
      it->second++;
    }
    else {
      cnt[a] = 1;
    }
  }

  u64 all = 0;
  for (auto pair : cnt) {
    all += pair.second * (pair.second - 1) / 2;
  }

  F0R(k, N) {

    cout << (all - cnt[balls[k]] + 1) << '\n';
  }
}


Measured memory_bytes: 8392
s = gets.chomp
k = gets.to_i
n = s.size

x = 0
x += 1 while x < n && s[0] == s[x]

y = 0
y += 1 while y < n && s[0] == s[-y]

c = 1
sum = 0
(n - 1).times do |i|
    if s[i] == s[i+1]
        c += 1
    else
        sum += c / 2
        c = 1
    end
end
sum += c / 2

if x == n
    puts n * k / 2
elsif s[0] == s[-1]
    puts sum * k - (x / 2 + (y - 1) / 2 - (x + y - 1) / 2) * (k - 1)
else
    puts sum * k
end

Measured memory_bytes: 1788
#include<stdio.h>

#define MAX 100005
#define NTL -1

struct Node{int p, l, r;};
struct Node T[MAX];

int n,H,D[MAX];

int main() {
  int i,j,d,v,c,l;

  scanf("%d",&n);
  for(i = 0 ; i < n ; i++) {
    T[i].p = T[i].l = T[i].r = NTL;
  }

  for(i = 0 ; i < n ; i++) {
    scanf("%d %d",&v,&d);
    for(j = 0 ; j < d ; j++) {
      scanf("%d",&c);
      if(j == 0)
	T[v].l = c;
      else T[l].r = c;
      l = c;
      T[c].p = v;
    }
  }

  H = 0;
  for(i = 0 ; i < n ; i++) {
    D[i] = getDepth(i);
    if(D[i] > H)
      H =D[i];
  }

  for(i = 0 ; i < n ; i++)
    print(i);
  return 0;
}

int getDepth(int x) {
  int d=0;

  for(; T[x].p != NTL ; d++)
    x = T[x].p;
  return d;
}

int print(int x) {
  int i,c;

  printf("node %d: ",x);
  printf("parent = %d, ",T[x].p);
  printf("depth = %d, ",D[x]);

  if(T[x].p == NTL)
    printf("root, ");
  else if(T[x].l == NTL)
    printf("leaf, ");
  else printf("internal node, ");

  printf("[");
  for(i = 0, c = T[x].l ; c != NTL ; i++, c = T[c].r) {
    if (i) printf(", ");
    printf("%d", c);
  }
  printf("]\n");
}



Measured memory_bytes: 3360
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}

bool is_prime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く


    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }


    // 素数である
    return true;
}

bool v[100005];
int n[100005];
int n_cum[100005];

int main(){
  int q; cin >> q;
  
  rep(i,100005) v[i] = is_prime(i);
  rep(i,100005) {n[i] = 0; n_cum[i] = 0;}
  rep(i,100001){
    if(i%2==0) continue;
    if(v[i]==true && v[(i+1)/2] == true) n[i] = 1;
  }
  for(int i=1;i<100005;i++){
    n_cum[i] = n_cum[i-1]+n[i];
  }
  
  rep(i,q){
    int l,r; cin >> l >> r;
    cout << n_cum[r]-n_cum[l-1] << endl;
  }
  return 0;
}

Measured memory_bytes: 1536
#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <cmath>
#include <math.h>
#include <algorithm>
#include <map>
#include <sstream>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <functional>
#include <utility>
#include <stdio.h>
#define ll long long
#define MP make_pair
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define PLI pair<ll, int>
#define PIL pair<int, ll>
#define F first
#define S second
#define SHN 1e9
#define LSHN 1e18
using namespace std;
int n,m;
vector<int> v[100010];
vector<int> tp;
bool visit[100010];
int d[100010];
void dfs(int x)
{
	visit[x]=1;
	for (int i=0;i<v[x].size();i++)
	{
		int xi=v[x][i];
		if (visit[xi]) continue;
		dfs(xi);
	}
	tp.push_back(x);
}
int main()
{
	cin >>n>>m;
	for (int i=0;i<m;i++)
	{
		int x,y;
		cin >>x>>y;
		v[x-1].push_back(y-1);
	}
	for (int i=0;i<n;i++) if (!visit[i]) dfs(i);
	reverse(tp.begin(),tp.end());
	for (int i=0;i<n;i++)
	{
		int x=tp[i];
		for (int j=0;j<v[x].size();j++)
		{
			int xi=v[x][j];
			d[xi]=max(d[xi],d[x]+1); 
		}
	} 
	cout <<*max_element(d,d+n);
	return 0;
} 

Measured memory_bytes: 8056
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define owo ios_base::sync_with_stdio(0);cin.tie(0);
#define MOD (ll)(1e9+7)
#define INF (ll)(1e18)
#define debug(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define time__(d) for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false);\
debug("%s time : %.4fs\n", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> PII;
typedef pair<int,int> pii;
typedef vector<vector<int>> vii;
int gcd(int A,int B) {if(!B)return A;return gcd(B,A%B);}
struct edge
{
	int to;
	int cost;
	ll time;
	
};

int main()
{
	int n,m,s;
	cin>>n>>m>>s;
	vector<edge>adj[n];
	vector<int>C(n),D(n);
	vector<ll>ans(n,INF);
	vector<vector<ll>> dist(n,vector<ll>(5550,INF));
	for(int i = 0;i<m;i++)
	{
		int v,u,a,b;
		cin>>v>>u>>a>>b;
		v--;u--;
		adj[v].pb(edge{u,a,b});
	    adj[u].pb(edge{v,a,b});
	}
	for(int i=0;i<n;i++)cin>>C[i]>>D[i];
	
	typedef pair<ll,pii> state;
	priority_queue<state,vector<state>,greater<state>>pq;
	s = min(s,5500);
	pq.push({0,{0,s}});//cost,vertex,coins
	dist[0][s] = 0;
	while(!pq.empty())
	{
		state v = pq.top();
		pq.pop();
		int c = v.se.se; // coins
		int p = v.se.fi; // vertex
		//cout<<p<<" "<<v.fi<<" "<<c<<endl;
		int new_c = min(5500,c + C[p]);
		if(dist[p][new_c] > v.fi+D[p]){
			dist[p][new_c] = v.fi+D[p];
			pq.push({dist[p][new_c],{p,new_c}});
		}
		
		for(edge x : adj[p]){
			if(c >= x.cost && dist[x.to][c - x.cost] > v.fi + x.time){
				dist[x.to][c-x.cost] = v.fi + x.time;
				pq.push({v.fi+x.time,{x.to,c-x.cost}});
			}	
		}
	}
	for(int i=1;i<n;i++)
	{
		for(int j = 0;j<=5500;j++){
			ans[i] = min(ans[i],dist[i][j]);
		}
		cout<<ans[i]<<endl;
	}
	
	
}


Measured memory_bytes: 9500
#include<cstdio>
#include<cstring>
using namespace std;
char s[15], t[15];
int slen, tlen,i;

int main()
{
	scanf("%s%s", s, t);
	slen= strlen(s);
	tlen= strlen(t);
	if(tlen == slen +1){
		for(i=0; i<slen; i++){
			if(s[i] != t[i]) {
				printf("No");
				return 0;
			}
		}
		if(i == slen) printf("Yes");
	}else printf("No");
	return 0;
}

Measured memory_bytes: 1728
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define ld long double
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; }
using P=pair<long long,long long>;
#define rep(i,n) for(long long i=0; i<(long long)n; i++)
#define req(i,n) for(long long i=n-1; i>=0; i--)
#define range(i,a,b) for(long long i=a; i<b; i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((long long)(x).size())
#define COUT(x) cout << x << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define onBoard(y,x) (y>=0 && y<h && x>=0 && x<w)
#define vint vector<int>
#define pri_que priority_queue
#define vvint vector<vector<int>>
#define vstr vector<string>
#define vp vector<pair<int,int>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define SUM(x) accumulate(x.begin(),x.end(),0)
#define MAX(x) *max_element(x.begin(),x.end())
#define MIN(x) *min_element(x.begin(),x.end())
#define couty cout<<"Yes"<<endl
#define coutn cout<<"No"<<endl
#define coutY cout<<"YES"<<endl
#define coutN cout<<"NO"<<endl
#define yn(x) cout<<(x?"Yes":"No")<<endl
#define YN(x) cout<<(x?"YES":"NO")<<endl
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
long long lcm(long long a, long long b){return a/gcd(a,b)*b;}
const long long dx[8]={1,0,-1,0,1,-1,-1,1};
const long long dy[8]={0,1,0,-1,1,1,-1,-1};
const long long INF = 1e12;
const long long MOD = 1e9+7;

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

    int a,b,x; cin >> a >> b >> x;

    cout<<b/x-(a?(a-1)/x:-1)<<endl;
}

Measured memory_bytes: 3612
//fold
#ifndef KHALIL
#include <bits/stdc++.h>
#else
#include "header.h"
#endif
#define endl '\n'
#define mp make_pair
#define tostr(x) static_cast<ostringstream&>((ostringstream()<<dec<<x)).str()
#define rep(i,begin,end) for(auto i = begin;i < end;i++)
#define repr(i,begin,end) for(auto i = begin-1;i >= end;i--)
#define pb push_back
#define sz(a) ((int)(a).size())
#define fi first
#define se second
#define abs(a) ((a) < (0) ? (-1)*(a) : (a))
#define SQ(a) ((a)*(a))
#define eqd(a,b) (abs(a-b)<1e-9)
#define X real()
#define Y imag()
using namespace std;
typedef long long ll;
typedef long double ld;
template <typename t> t in(t q){cin >> q;return q;}
template <typename T> ostream& operator<<(ostream& os, const vector<T>& v){os << "[";for (int i = 0; i < sz(v); ++i) { os << v[i]; if (i != sz(v) - 1) os << ",";}os << "]";return os;}
template <typename T, typename S>ostream& operator<<(ostream& os, const map<T, S>& v){for (auto it : v)os << "(" << it.first << ":" << it.second << ")";return os;}
template <typename T, typename S>ostream& operator<<(ostream& os, const pair<T, S>& v){os << "(" << v.first << "," << v.second << ")";return os;}
const long double PI = acosl(-1);
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 rng64(chrono::steady_clock::now().time_since_epoch().count());
inline int rand(int l,int r){return uniform_int_distribution<int>(l, r)(rng);}
inline ll rand(ll l,ll r){return uniform_int_distribution<ll>(l, r)(rng64);}
//endfold
#define  N  (200005)
#define MOD (1000000000ll + 7ll)
#define OO (1050000000)
#define OOL (1100000000000000000)

//global
ll a[N];
map<ll,int> act;
map<ll,int> ful;

vector<int> s;
bitset<100005> prim;

void fill(){
	int sqr = 47;
	s.push_back(2);
	for (int i = 3; i <= 2200; i += 2){
		if(!prim[i]){
			if(i <= sqr)
				for (int j = i*i; j <= 2200; j += i)
					prim[j] = true;
			s.push_back(i);
		}
	}
}

ll sqr(ll x){
	ll l = 1,r = x;
	while(l <= r){
		ll mid = (l+r)/2;
		ll ans = mid*mid;
		if(ans < x) l = mid+1;
		if(ans > x) r = mid-1;
		if(ans == x) return mid;
	}
	return 0;
}

int main(){
	//fold
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	cout << setprecision(10);
	//endfold
	fill();
	int n;
	cin >> n;	
	rep(i,0,n){
		cin >> a[i];
	}
	rep(i,0,n){
		vector<pair<int,int>> bs;
		for (int j = 0; j < sz(s) && s[j]*s[j] <= a[i]; ++j){
			int k = 0;
			while(a[i]%s[j] == 0){
				k++;
				a[i] /= s[j];
				if(k == 3) k = 0;
			}
			if(k) bs.push_back({s[j],k});
		}
		if(a[i] > 1){
			ll q = sqrtl(a[i]);
			if(q*q == a[i]) bs.push_back({q,2});
			else bs.push_back({a[i],1});
		}
		ll bsn = 1;
		ll rsn = 1;
		for(pair<int,int> w:bs){
			if(w.second == 1){
				bsn *= w.first;
				rsn *= w.first;
				rsn *= w.first;
			}
			if(w.second == 2){
				bsn *= w.first;
				bsn *= w.first;
				rsn *= w.first;
			}
		}
		if(bsn <= rsn) act[bsn]++;
		ful[min(bsn,rsn)]++;
	}
	int ans = 0;
	for(auto el:ful){
		if(el.first == 1) continue;
		ans += max(act[el.first],el.second-act[el.first]);
	}
	cout << ans+(act[1]>0);
	return 0;
}

Measured memory_bytes: 13568
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;

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

    int N;
    cin >> N;
    vector<P> V(N);
    for (int i = 0; i < N; ++i) {
        int A;
        cin >> A;
        V.at(i) = make_pair(A, i + 1);
    }
    sort(V.begin(), V.end());
    for (int i = 0; i < N; ++i) {
        if (i) cout << ' ';
        cout << V.at(i).second;
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 1664
K, A, B = map(int, input().split())

if A + 2 >= B or A-1+2 > K:
  print(1+K)
  exit()

# A-1回ビスケット増やした後、
# (A枚を1円に交換、1円をB枚に交換)の繰り返し
d = B - A
num = (K - (A-1)) // 2
mod = (K - (A-1)) % 2
print(A + (B-A)*num + mod)

Measured memory_bytes: 3060
//
//  main.cpp
//  NOMURA_2020_B
//
//  Created by Joe Mori on 2020/05/30.
//  Copyright © 2020 Joe Mori. All rights reserved.
//

#include <iostream>
#include<string>
int main() {
    // insert code here...
    std::string str;
    std::cin>>str;
    for(long long int i=0;i<str.length();i++){
        if(str.at(i)=='?'){
            str.at(i)='D';
        }
    }
    std::cout<<str<<std::endl;
    return 0;
}


Measured memory_bytes: 3752
use std::io;

fn main() {
	let mut buf = String::new();
	io::stdin().read_line(&mut buf).expect("");
	let mut buf = String::new();
	io::stdin().read_line(&mut buf).expect("");
	let mut iter = buf.split_whitespace();
	let s: Vec<char> = iter.next().unwrap().chars().collect();
	let t: Vec<char> = iter.next().unwrap().chars().collect();
	for i in 0..s.len() {
		print!("{}{}", s[i], t[i]);
	}
	print!("\n");
}

Measured memory_bytes: 4352