akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
const int maxn = 200005;
typedef long long ll;
ll a[maxn]={0};
int n;
ll find1(ll m){
    ll ret=0;
    ll num=0;
    long double f = 1.0;
    for(int i=0;i<n;++i){
        if(a[i]<0){
            num=lower_bound(a,a+n,f*m/a[i])-a;
            num=n-num;
        }
        else if(a[i]==0){
            if(m>=0)
                num=n;
            else
                num=0;
        }
        else
            num=upper_bound(a,a+n,f*m/a[i])-a;
        ret+=num;
        if(a[i]*a[i]<=m)
            ret--;
    }
    return ret/2;
}
ll find2(ll m){
    ll ret=0;
    ll num=0;
    long double f = 1.0;
    for(int i=0;i<n;++i){
        if(a[i]<0)
            num=upper_bound(a,a+n,f*m/a[i])-a;
        else if(a[i]==0){
            if(m<=0)
                num=n;
            else
                num=0;
        }
        else{
            num=lower_bound(a,a+n,f*m/a[i])-a;
            num=n-num;
        }
        ret+=num;
        if(a[i]*a[i]>=m)
            --ret;
    }
    return ret/2;
}
int main()
{
    ll k;
    scanf("%d%lld",&n,&k);
    for(int i=0;i<n;i++){
        scanf("%lld",&a[i]);
    }
    sort(a,a+n);
    ll l = -1e18,r=1e18;
    ll m = (l+r)/2;
    ll ans = 0 ;
    ll ans1,ans2;
    while(l<=r){
        m=(l+r)/2;
        ans1=find1(m);
        ans2=find2(m);
        if(ans1>=k&&ans2>=(1ll*n*(n-1)/2-k+1)){
            ans = m ;
            break;
        }
        else if(ans1>=k)
            r=m-1;
        else
            l=m+1;
        
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 1920
#include<bits/stdc++.h>
using namespace std;
#define sync ios_base::sync_with_stdio(false), cin.tie(NULL)
#define F first
#define S second
#define pb emplace_back
#define mt make_tuple
#define mp make_pair
#define gcd __gcd
#define PI 3.141592653589
// Input
#define in(a) scanf("%d",&a)
#define in2(a,b) scanf("%d%d",&a,&b)
#define in3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define llin(a) cin >> a
#define inl(a) scanf("%lld",&a)
#define read(v,i,n) for(i=0;i<n;i++)in(v[i])
#define twod(mat,i,j,n,m) rep(i,n){rep(j,m)in(mat[i][j]);}
#define sc(ch) scanf("%c",&ch)
#define sstr(str) scanf("%s",str)
// Output
#define pr(a) printf("%d ",a)
#define pr2(a,b) printf("%d %d\n",a,b)
#define pr3(a,b,c) printf("%d %d %d\n",a,b,c)
#define out(a) printf("%d\n",a)
#define outl(a) printf("%lld\n",a)
#define llpr(a) cout << a << " "
#define llout(a) cout << a << "\n"
#define yes printf("YES\n")
#define no printf("NO\n")
#define lin printf("\n")
// Iterator
#define lp(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) for(i=0;i<n;i++)
#define all(vec) vec.begin(),vec.end()
#define lower(v,k) lower_bound(v.begin(),v.end(),k)-v.begin()
#define upper(v,k) upper_bound(v.begin(),v.end(),k)-v.begin()
#define tf(mytuple) get<0>(mytuple)
#define ts(mytuple) get<1>(mytuple)
#define tt(mytuple) get<2>(mytuple)
// Debug
#define dbg(v,i,n) for(i=0;i<n;i++)pr(v[i]); lin
#define what(x) cerr << #x << " : " << x << "\n"
#define ck printf("continue\n")
#define debug(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args)
{
	cerr << *it << " = " << a << "\n";
	err(++it, args...);
}
// Data Type
#define ll long long int
#define ii pair<int,int>
#define pli pair<ll,int>
#define triple tuple<int,int,int>
#define vi vector<int>
#define vii vector<pair<int,int> >
#define vvi vector<vector<int> >
#define viii vector<pair<pair<int,int>,int> >
#define vvii vector<vector<pair<int,int> > >
#define M 1000000007
#define N 100005  //check the limits, man
const ll INF = 1e18;
int cnt[N];
int bit[N];
void update(int j,int x)
{
    for(;j<N;j+=j&(-j))
        bit[j]+=x;
}
int query(int j)
{
    int x=0;
    for(;j>0;j-=(j)&(-j))
        x+=bit[j];
    return x;
}
int B;
int main()
{
    int n,m,l,r,i,j,k,a,b;
    in2(n,m);
    vector<triple> vp(n);
    rep(i,n)
    {
        in2(l,r);
        vp[i]=mt(r-l+1,l-1,r);
    }
    sort(all(vp));
    B=3;
    lp(j,1,B)
    {
        a=0;
        rep(i,n)
        {
            b=(tt(vp[i])/j)-(ts(vp[i])/j);
            if(b)
                a++;
        }
        cnt[j]=a;
    }
    i=0;
    while(i<n && tf(vp[i])<B)
        update(ts(vp[i])+1,1),update(tt(vp[i])+1,-1),i++;
    lp(j,B,m+1)
    {
        a=0;
        for(k=j;k<=m;k+=j)
            a+=query(k);
        cnt[j]=a+(n-i);
        while(i<n && tf(vp[i])<=j)
            update(ts(vp[i])+1,1),update(tt(vp[i])+1,-1),i++;
    }
    lp(j,1,m+1)
        out(cnt[j]);
}





Measured memory_bytes: 5248
def c_colon_dist():
    from cmath import pi, exp
    A, B, H, M = [int(i) for i in input().split()]
    def rot(h, rad): return h * exp(1j * (pi / 2 - rad))

    hour_rad, minute_rad = (60 * H + M) * pi / 360, M * pi / 30
    hour_pos, minute_pos = rot(A, hour_rad), rot(B, minute_rad)
    return abs(hour_pos - minute_pos)

print(c_colon_dist())

Measured memory_bytes: 9560
N,K = map(int,input().split())
h = [int(input()) for _ in range(N)]
h.sort()
max_min = h[K-1] - h[0]
check = int()
for i in range(1,N-K+1):
    check = h[i + K-1] - h[i]
    if check < max_min:
        max_min = check
print(max_min)

Measured memory_bytes: 50264
import java.util.*;

public class Main {
    public static void main( String[] args) {
        int length;
        Scanner sc = new Scanner(System.in);
        String num = sc.next(); //1
        num = num.replaceAll("0", "");  //2
        length = num.length();  //3
        System.out.println(length); //4
    }
}

/* Process
1.in 3 String number(it's easier string than int.)
2.change 0 to " " (3 String number became only 1.)
3.search length 1 (It's answer.)
4.out results
*/

Measured memory_bytes: 23252
#include <iostream>
#include <string>
#include <array>
#include <vector>
#include <cmath>
#include<cstdio>
#include<iomanip>
#include <algorithm>
#include <numeric>
#include <iterator>
#include <limits>
#include <set>
#include <map>
#include <bitset>

int main()
{
    long long a{};
    std::string b{};
    std::cin >> a >> b;
    const auto b1 = std::stoll(b);
    const auto b2 = std::stoll(b.substr(b.size() - 2));
    const auto result = a * b1 + a * b2 / 100;
    std::cout << result << std::endl;
    return 0;
}


Measured memory_bytes: 3600
#include<iostream>
#include<stdlib.h>
#include<vector>
#include<algorithm>
#include<stdio.h>
#include<string>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<limits.h>
#define rep(i,n) for(ll i = 0; i < (ll)n; i++)
#define swap(a,b) a^=b;b^=a;a^=b;
#define chmax(a,b) {if(a < b) a = b;}
#define chmin(a,b) {if(a > b) a = b;}
using namespace std;
typedef long long ll;
ll gcd(ll, ll);
vector<bool> to_binary(int);
int sum(vector<int>);
int min(vector<int>);
int max(vector<int>);
ll nCr(ll n, ll r);

const ll INF = 1LL << 60;

typedef tuple<ll, ll> mtupl;

bool mycomp(mtupl x, mtupl y) {
	return get<1>(x) < get<1>(y);
}

vector<vector<ll>> memo;

ll get(int x, int y) {
	if (memo[x][y] != -1)
		return memo[x][y];

	if (x == 0) return 1;
	if (y < x) return 0;

	memo[x][y] = get(x, y - 1) + get(x - 1, y - 1);
	return memo[x][y];
}

ll mpow(ll a, ll b) {
	ll ans = 1;
	for (ll i = 0; i < b; i++) {
		ans *= a;
		ans %= 1000000007;
	}
	return ans;
}

int main(void) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	//Program Start	


	/* ABC 125_c
	*/
	int N;
	cin >> N;

	vector<ll> A(N);
	rep(i, N) cin >> A[i];

	vector<ll> Forward(N + 1), Backward(N + 1);

	Forward[0] = 0;
	Backward[0] = 0;

	ll tmp = A[0];
	for (int i = 0; i < N; i++) {
		tmp = gcd(tmp, A[i]);
		Forward[i + 1] = tmp;
	}

	tmp = A[N - 1];
	for (int i = 0; i < N; i++) {
		tmp = gcd(tmp, A[N - i - 1]);
		Backward[i + 1] = tmp;
	}
	/*
	for (auto v = Forward.begin(); v != Forward.end(); v++) {
		printf("%d ", *v);
	}
	cout << endl;
	for (auto v = Backward.begin(); v != Backward.end(); v++) {
		printf("%d ", *v);
	}
	cout << endl;
	*/

	ll max = 0;
	for (int i = 0; i < N; i++) {
		//cout << Forward[i] << endl;
		//cout << Backward[N - i - 1] << endl;
		max = std::max(max, gcd(Forward[i], Backward[N - i - 1]));
	}

	cout << max << endl;


	//cout << gcd(100, 0) << endl;

ProgramEndPointLabel:;

	//Program End
	system("pause");

	return 0;
}

ll nCr(ll n, ll r) {
	ll res = 1;
	for (int i = 0; i < r; i++) {
		res *= (n - i);
	}
	for (int i = 1; i <= r; i++) {
		res /= i;
	}
	return res;
}

int vsum(vector<int> v) {
	int res = 0;
	for (auto it = v.begin(); it != v.end(); it++)
		res += *it;
	return res;
}
int vmin(vector<int> v) {
	int min = INT32_MAX;
	for (auto it = v.begin(); it != v.end(); it++)
		min = std::min(min, *it);
	return min;
}
int vmax(vector<int> v) {
	int max = 0;
	for (auto it = v.begin(); it != v.end(); it++)
		max = std::max(max, *it);
	return max;
}

ll gcd(ll A, ll B) {
	if (A == 0 || B == 0) return max(A, B);
	int r = A % B;
	while (r != 0) {
		A = B;
		B = r;
		r = A % B;
	}

	return B;
}

vector<bool> to_binary(int x) {
	vector<bool> res;
	while (x != 0) {
		res.push_back(x % 2);
		x /= 2;
	}
	return res;
}

Measured memory_bytes: 2816
#include<cstdio>
#include<vector>
#include<algorithm>

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

using namespace std;

main(){
	const int Ne=2*123456;
	static bool er[Ne+1]; er[0]=er[1]=true;
	for(int i=2;i*i<=Ne;i++) if(!er[i]) for(int j=i*i;j<=Ne;j+=i) er[j]=true;
	vector<int> p; rep(i,Ne+1) if(!er[i]) p.push_back(i);

	for(int n;scanf("%d",&n),n;) printf("%d\n",upper_bound(all(p),2*n)-upper_bound(all(p),n));
}

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

#define ll long long
#define ull unsigned long long 

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

    int ans = 0;
    for(int i=0; i<n-1; ++i){
        string a= s.substr(0, i+1);
        string b= s.substr(i+1);

        set<char> s1(a.begin(), a.end());
        set<char> s2(b.begin(), b.end());

        // cout << a << "    " << b << endl;

        // for(auto x:s1)
        //     cout << x;
        //     cout << "      ";
        // for(auto x:s2)
        //     cout << x;
        // cout << endl << endl << endl;

        int count=0;
        for(int j=0; j<s1.size(); ++j){
            auto el = s1.begin();
            advance(el, j);
            if(binary_search(s2.begin(), s2.end(), *el))
                count++;
        }
        ans = max(ans, count);
    }
    cout << ans;
}


Measured memory_bytes: 3632
#include<stdio.h>
int main()
{
    int a,b,i,j,k;
    scanf("%d",&a);
    int x[a][6];
    for(i=0;i<a;i++){
        for(j=0;j<6;j++){
            scanf("%d",&x[i][j]);
        }
    }
 
    for(i=0;i<a-1;i++){
        for(j=i+1;j<a;j++){
            for(k=0;k<122;k++){
                if(x[i][0]==x[j][0]&&x[i][5]==x[j][5]){
                    if(x[i][1]==x[j][1]&&x[i][4]==x[j][4]){
                        if(x[i][2]==x[j][2]&&x[i][3]==x[j][3]){
                            puts("No");
                            return 0;
                        }
                    }
                    else{
                        b=x[j][1];x[j][1]=x[j][2];x[j][2]=x[j][4];
                        x[j][4]=x[j][3];x[j][3]=b;
                    }
                }
                if(k%2){
                    b=x[j][1];x[j][1]=x[j][0];x[j][0]=x[j][4];
                    x[j][4]=x[j][5];x[j][5]=b;
                }
                else{
                    b=x[j][5];x[j][5]=x[j][2];x[j][2]=x[j][0];
                    x[j][0]=x[j][3];x[j][3]=b;
                }
            }
        }
    }
    puts("Yes");
    return 0;
}


Measured memory_bytes: 2108
import java.util.*;

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

		Scanner sc=new Scanner(System.in);

		int a=sc.nextInt();
		int b=sc.nextInt();
		int x[]={a+b,a-b,a*b};

		int max=-10000;
		for(int i=0;i<3;i++){
			if(max<x[i]){
				max=x[i];
			}
		}
		System.out.println(max);

	}
}


Measured memory_bytes: 23764
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
  ll n,k ;
  cin >> n >>k;
  vector<ll> v(n),dp(n) ;
  for(ll i=0;i<n;i++) cin >> v[i] ;
  for(ll i=1;i<n;i++)
  {
    ll a = dp[i-1] + abs(v[i]-v[i-1]);
    for(ll j=1;j<=k;j++)
    {
      if(i-j>=0)a = min(a,dp[i-j]+abs(v[i]-v[i-j])) ;
    }
    dp[i] = a ;
  }
  cout << dp[n-1] << endl;

}

Measured memory_bytes: 4812
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.NoSuchElementException;
import java.util.Random;

class Main {
	public static void main(String[] args) {
		new Main().run();
	}
	
	void run() {
		FastScanner sc=new FastScanner();
		PrintWriter pw=new PrintWriter(System.out);
		int[] a=new int[5];
		for(int i=0;i<5;++i)a[i]=sc.nextInt();
		int k=sc.nextInt();
		Arrays.sort(a);
		boolean ok=a[a.length-1]-a[0]<=k;
		pw.println(ok?"Yay!":":(");
		pw.close();
	}

	
	static void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}

}


class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public int nextInt() {
    	return Integer.parseInt(next());
    }
    
    public long nextLong() {
    	return Long.parseLong(next());
    }
}

Measured memory_bytes: 21204
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using vll = vector<ll>;
using vll2 = vector<vector<ll>>;
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll LINF = (1LL << 60) - 1LL;
constexpr ll MOD = 1e9 + 7;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, k;
    cin >> n >> k;
    vector<ll> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    sort(all(a));
    auto check = [&](ll x) {
        ll cnt = 0;
        for (int i = 0; i < n; i++) {
            if (a[i] == 0) {
                if (x >= 0) {
                    cnt += n;
                }
            } else if (a[i] > 0) {
                auto f = [&](ll s) { return a[i] * s <= x; };
                cnt += partition_point(all(a), f) - a.begin();
            } else {
                auto f = [&](ll s) { return a[i] * s > x; };
                cnt += a.end() - partition_point(all(a), f);
            }
            if (a[i] * a[i] <= x) {
                cnt--;
            }
        }
        return cnt / 2LL;
    };
    ll ok = LINF, ng = -LINF;
    while (ok - ng > 1LL) {
        ll mid = (ok + ng) / 2LL;
        if (check(mid) >= k) {
            ok = mid;
        } else {
            ng = mid;
        }
    }
    cout << ok << endl;
}

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


int main() {
	int N, x;
	cin >> N >> x;
	vector<int> a(N);
	for (int i = 0; i < N; ++i) cin >> a[i];

	vector<int> cpa = a;

	long long ans = 0;
	for (int i = 0; i < N; ++i) {
		if (i == 0) {
			if (cpa[i] > x) ans += cpa[i] - x, cpa[i] = x;
		}
		else {
			if (cpa[i] + cpa[i-1] > x) ans += cpa[i] + cpa[i-1] - x, cpa[i] = x - cpa[i-1];
		}
	}

	cpa = a;
	long long ans2 = 0;
	for (int i = N - 1; i >= 0; i--) {
		if (i == N - 1) {
			if (cpa[i] > x) ans2 += cpa[i] - x, cpa[i] = x;
		}
		else {
			if (cpa[i] + cpa[i+1] > x) ans2 += cpa[i] + cpa[i+1] - x, cpa[i] = x - cpa[i+1];
		}
	}



	cout << min(ans, ans2) << endl;
	return 0;
}

Measured memory_bytes: 4048
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <functional>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <cassert>
#include <exception>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<string,ll> P;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<P> vp;
#define rep(i,a,n) for(ll i = (a);i < (n);i++)
#define per(i,a,n) for(ll i = (a);i > (n);i--)
#define lep(i,a,n) for(ll i = (a);i <= (n);i++)
#define pel(i,a,n) for(ll i = (a);i >= (n);i--)
#define clr(a,b) memset((a),(b),sizeof(a))
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define sz size()
#define print(X) cout << (X) << endl
const ll INF = 1e+9+7;
ll n,m,l,ans;
string s,t;
ll d[200010],dp[500][500];

int main(){
  cin >> s;
  bool f = true;
  pel(i,s.sz-1,0){
    t += s[i];
    if(t.sz == 5){
      if(t == "maerd" || t == "esare"){
        t = "";
      }
    }else if(t.sz == 6){
      if(t == "resare"){
        t = "";
      }
    }else if(t.sz == 7){
      if(t != "remaerd")f = false;
      t = "";
    }
  }
  if(f)puts("YES");
  else puts("NO");
  return 0;
}

Measured memory_bytes: 512
<?php

$stdin = preg_split('/ /', trim(fgets(STDIN)));
$n = $stdin[0];

for ($i = 1; $i <= $n; $i++) {
    if ($i % 3 == 0) {
        print " {$i}";
    } else {
        $j = $i;
        while ($j != 0) {
            if ($j % 10 == 3) {
                print " {$i}";
                break;
            }
            $j /= 10;
        }

    }
}
print "\n";

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

int main() {
  int H, W;
  cin >> H >> W;
  vector<string> a(H);
  vector<string> b(H+2);
  for(int i = 0; i < H; i++) {
    cin >> a.at(i);
  }
  for(int i = 0; i < H+2; i++) {
    if(i == 0 || i == H+1) {
      for(int j = 0; j < W+2; j++) {
        cout << "#";
      }
      cout << " " << endl;
    }
    else {
      cout << "#" << a.at(i-1) << "#" << endl;
    }
  }
}



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

int main() {
  int N, M, C;
  cin >> N >> M >> C;
  vector<int> B(M);
  for (int i = 0; i < M; i++) {
    cin >> B.at(i);
  }
  vector<vector<int>> A(N, vector<int>(M));
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < M; j++) {
      cin >> A.at(i).at(j);
    }
  }
  vector<int> D(N);
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < M; j++) {
      D.at(i) += A.at(i).at(j) * B.at(j);
    }
    D.at(i) += C;
  }
  int ans;
  for (int i = 0; i < N; i++) {
    if (D.at(i) > 0) {
      ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
  private static final long INF = 1_000_000_000_000_000_000L;
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    List<List<Dst>> from = new ArrayList<>();
    for (int i = 0; i < N; i++) {
      from.add(new ArrayList<>());
    }
    for (int i = 0; i < N-1; i++) {
      int a = sc.nextInt();
      int b = sc.nextInt();
      a--;
      b--;
      int c = sc.nextInt();
      from.get(a).add(new Dst(b,c));
      from.get(b).add(new Dst(a,c));
    }

    int Q = sc.nextInt();
    int K = sc.nextInt();
    K--;
    
    PriorityQueue<Dst> pq = new PriorityQueue<>((a,b)->{
      if (a.cost == b.cost) {
        return 0;
      }
      return a.cost > b.cost ? 1 : -1;
    });
    long[] cost = new long[N];
    Arrays.fill(cost, INF);
    
    pq.offer(new Dst(K,0));
    while (!pq.isEmpty()) {
      Dst now = pq.poll();
      if (cost[now.to] <= 0) continue;
      cost[now.to] = -now.cost;
      
      for (Dst p : from.get(now.to)) {
        long newCost = now.cost+p.cost;
        if (cost[p.to] > 0 && newCost < cost[p.to]) {
          cost[p.to] = newCost;
          pq.offer(new Dst(p.to,newCost));
        }
      }
    }
      
    StringBuilder ans = new StringBuilder();
    for (int i = 0; i < Q; i++) {
      int x = sc.nextInt();
      int y = sc.nextInt();
      x--;
      y--;
      ans.append(-(cost[x]+cost[y])).append('\n');
    }
    System.out.print(ans.toString());
  }
  private static class Dst {
    private final int to;
    private final long cost;
    Dst(int to, long cost) {
      this.to = to;
      this.cost = cost;
    }
  }
}

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

ll dfs(int temp, string s) {
  //base case
  if (s.length() == 0) return 0;
  ll sum = temp + stoll(s);
  for (ll i = 0; i < s.length() - 1; ++i) {
    int newTemp = temp + stoll(s.substr(0, i + 1));
    sum += dfs(newTemp, s.substr(i + 1));
  }
  return sum;
}

void solve() {
  string s;
  cin >> s;
  cout << dfs(0,s) << endl;
}

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


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

#ifdef LOCAL
#define debug(var) cerr << #var << " = " << var << endl;
#else
#define debug(var)
#endif

void init() {
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
}

void solve() {
	int n, m, a, b, c;
	string s, p, q;
	cin >> s >> p >> q;
	if (s.back() == p[0] && p.back() == q[0]) {
		cout << "YES";
	} else {
		cout << "NO";
	}
}

int main() {
	init();
	int t = 1; //scanf("%d", &t);
	while (t--) {
		solve();
	}
	return 0;
}


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

using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;
typedef vector < vector<ll> > Mat;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int H, W, N;
Pii P[int(1e4+5)];

int ans[105][105];

int main(){
  cin >> H >> W >> N;
  for (int i = 1; i <= N; i++){
    cin >> P[i].fi;
    P[i].se = i;
  }

  int nowi = 1, nowj = 1;
  for (int i = 1; i <= N; i++){
    while (P[i].fi > 0){
      P[i].fi--;
      ans[nowi][nowj] = P[i].se;

      if (nowi % 2 == 1){
        nowj++;
        if (nowj == W + 1) nowj = W, nowi++;
      }else{
        nowj--;
        if (nowj == 0) nowj = 1, nowi++;
      }
    }
  }

  for (int i = 1; i <= H; i++){
    cout << ans[i][1];
    for (int j = 2; j <= W; j++) cout << " " << ans[i][j];
    cout << endl;
  }

  return 0;
}


Measured memory_bytes: 3700
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], A = l[1];
            var x = Console.ReadLine().Split().Select(int.Parse).ToArray();

            var dp = new long[N + 1, N + 1, 2501];
            dp[0, 0, 0] = 1;

            for (var i = 0; i < N; i++)
            {
                for (var j = 0; j < N; j++)
                {
                    for (var k = 0; k < 2501; k++)
                    {
                        if (dp[i, j, k] == 0) continue;

                        dp[i + 1, j, k] += dp[i, j, k];
                        dp[i + 1, j + 1, k + x[i]] += dp[i, j, k];
                    }
                }
            }

            var ans = 0L;
            for (var i = 1; i <= N; i++)
                ans += dp[N, i, A * i];

            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 60256
program prob4
    implicit none
    integer::p(100005), a(100005)
    integer::i, j, Q, l, r

    p = 0
    do i = 2, 100000
        if(p(i) == 0) then
            do j = 2*i, 100000, i
                p(j) = 1
            end do
        end if
    end do

    a = 0
    do i = 3, 100000
        if(p(i) == 0 .and. p((i+1)/2) == 0) then
            a(i) = a(i-1) + 1
        else
            a(i) = a(i-1)
        end if
    end do
    
    read(*,*) Q
    do i = 1, Q
        read(*,*) l, r
        write(*,*) a(r) - a(l-1)
    end do
    stop
end program

Measured memory_bytes: 3616
#include <bits/stdc++.h>
#define Pct puts("------ Yes ------");
#define rep(a, b, c) for(int a = (b); a <= (c); ++ a)
#define per(a, b, c) for(int a = (b); a >= (c); -- a)
#define fir first
#define sec second
#define ls son[u][0]
#define rs son[u][1]
#define eps 1e-8
#define PI acos(-1.0)
using namespace std;
template <class T> void rd(T &x){ x = 0; int 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 - '0', ch = getchar(); x *= f; }

typedef long long ll;
ll a, b;

int main(){
	rd(a), rd(b);
	if(a + 5 >= b){
		ll res = 0;
		for(ll i = a; i <= b; ++ i) res ^= i;
		printf("%lld\n", res);
		exit(0);
	}
	ll res = 0;
	if(a & 1) res ^= a, a ++;
	if(~b & 1) res ^= b, b --;
	if(((b - a + 1) / 2) & 1) res ^= 1;
	printf("%lld\n", res);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
 // #include <ext/pb_ds/tree_policy.hpp>
 // #include <ext/pb_ds/assoc_container.hpp>
 #include<chrono>
  using namespace std;
   using namespace std::chrono;      
  // using namespace __gnu_pbds; 
 #define fastio     ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
 #define fi         first
 #define se         second
 #define int         long long 
 #define pb         push_back
 #define emp        emplace_back
 #define vv(x)      vector<x>
 #define mp(x,y)    map<x,y>
 #define dq(x)      deque<x>
 #define pql(x)     priority_queue<x>
 #define pqs(x)     priority_queue<x,vv(x),greater<x> >
 #define M          1000000007
 #define forf(i,a,b) for(int i=a;i<b;i++)
 #define it(x)      x::iterator
 #define ll         long long 
 #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", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
 #define vii        vector<int>
 #define big        1e18
 #define sm         -2e18
 #define mkr        make_pair
 #define vpi        vector<pair<int,int> >
 #define pii        pair<int,int>
 #define rng        500005
 #define sz(x)      (int)x.size()
 #define rv(x)      reverse(x.begin(),x.end())
 #define out(x)     cout<<x.fi<<" "<<x.se<<endl;
#define MEM(x,val) memset(x,val,sizeof(x))

 // typedef tree<pii, null_type, less<pii>, rb_tree_tag,  
 //            tree_order_statistics_node_update>  odst; 


void pr_init()
{
   
    #ifndef ONLINE_JUDGE
    freopen("gin.txt", "r", stdin);
   // freopen("output.txt", "w", stdout);
   
    #endif
}

void solve()
{
  string s,t;
  cin >> s >> t;
  
  int an = INT_MAX;
  for(int i=0;i<sz(s)-sz(t)+1;i++)
  {
    int cur =0 ;
    for(int j=i;j<i+sz(t);j++)
    {
      if(s[j]!=t[j-i]) cur++;
    }
    an = min(an,cur);
  }
  cout<<an;
}

int32_t main()
{
  pr_init();
  fastio;
  auto start = high_resolution_clock::now(); 
  solve(); 
  auto stop = high_resolution_clock::now();
  auto duration = duration_cast<microseconds>(stop - start); 
  
    // cout << "Time taken by function: "
    //      << duration.count() << " microseconds" << endl; 

  return 0;
}

Measured memory_bytes: 3656
<?php
list($n, $m) = explode(" ", trim(fgets(STDIN)));
$tree = new UFT($n);
for($i = 0; $i < $m; $i++){
    list($from, $to, $_) =  explode(" ", trim(fgets(STDIN)));
    $tree->unite($from, $to);
}
for($i = 1; $i <= $n; $i++){
    $map[$tree->getRoot($i)] = true;
}
echo count($map);

class UFT{
    public $parent;
    public $size;
    public $rank;
    public function __construct($size){
        for($i = 1; $i <= $size; $i++){
            $this->size[$i] = 1;
            $this->rank[$i] = 1;
            $this->parent[$i] = 0;
        }
    }
    public function dump(){
        o("--------------");
        o($this->parent);
        o($this->size);
        o($this->rank);
    }
    public function getRoot($i){
        if($this->parent[$i] == 0){
            return $i;
        }else{
            return $this->getRoot($this->parent[$i]);
        }
    }
    public function unite($i, $j){
        $rootI = $this->getRoot($j);
        $rootJ = $this->getRoot($i);
        if($rootJ == $rootI)return false;//元から同じグループ
        if($this->rank[$rootI] > $this->rank[$rootJ])list($rootI, $rootJ) = [$rootJ, $rootI];//Rank(J)>Rank(I)に揃えておく
        $this->parent[$rootI] = $rootJ;
        if($this->rank[$rootI] == $this->rank[$rootJ]){
            $this->rank[$rootJ]++;
        }
        $this->size[$rootJ]+=$this->size[$rootI];
        $this->size[$rootI] = '*';//不要な情報となるので潰す/デバッグ出力向けに*を入れている
        $this->rank[$rootI] = '*';//同上
    }
    public function size($i){return $this->size[$this->getRoot($i)];}
    public function isUnion($i, $j){return $this->getRoot($i) == $this->getRoot($j);}
}

Measured memory_bytes: 24432
N=int(input())
A=list(map(int,input().split()))

from collections import Counter
C=Counter(A)
ANS=0
for i in C.values():
    ANS+=i*(i-1)//2

for a in A:
    k=C[a]

    print(ANS-(k*(k-1)//2)+((k-1)*(k-2)//2))

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

int main(){
	long long A,B;	cin>>A>>B;

	set<long long>a,b;

	if(A%2==0){
		a.insert(2);
		while(A%2==0)A/=2;
	}
	for(long long i=3; i*i<=A; i+=2){
		if(A%i==0){
			a.insert(i);
			while(A%i==0)A/=i;
		}
	}
	if(A>1)a.insert(A);

	if(B%2==0){
		b.insert(2);
		while(B%2==0)B/=2;
	}
	for(long long i=3; i*i<=B; i+=2){
		if(B%i==0){
			b.insert(i);
			while(B%i==0)B/=i;
		}
	}
	if(B>1)b.insert(B);

	int ans=1;
	for(auto i=a.begin(); i!=a.end(); i++){
		for(auto t=b.begin(); t!=b.end(); t++){
			if(*i == *t){
				ans++;
				break;
			}
		}
	}

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


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

int dp[110][110][110];

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  int A, B, C;
  cin >> A >> B >> C;
  fill_n((int*)dp, 110 * 110 * 110, 1 << 30);
  dp[A][B][C] = 0;
  for (int i = 0; i < 100; i++) {
    for (int j = 0; j < 100; j++) {
      for (int k = 0; k < 100; k++) {
        if (dp[i][j][k] == 1 << 30) continue;
        dp[i + 2][j][k] = min(dp[i + 2][j][k], dp[i][j][k] + 1);
        dp[i][j + 2][k] = min(dp[i][j + 2][k], dp[i][j][k] + 1);
        dp[i][j][k + 2] = min(dp[i][j][k + 2], dp[i][j][k] + 1);
        dp[i + 1][j + 1][k] = min(dp[i + 1][j + 1][k], dp[i][j][k] + 1);
        dp[i + 1][j][k + 1] = min(dp[i + 1][j][k + 1], dp[i][j][k] + 1);
        dp[i][j + 1][k + 2] = min(dp[i][j + 1][k + 2], dp[i][j][k] + 1);
      }
    }
  }
  int ans = 1 << 30;
  for (int i = 0; i < 100; i++) {
    ans = min(ans, dp[i][i][i]);
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 5504
from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations # (string,3) 3回
from collections import deque
from collections import defaultdict
import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
n,q = readInts()
G = [[] for _ in range(n)]
for i in range(n-1):
    a,b = map(lambda x: int(x) - 1,input().split())
    G[a].append(b)
    G[b].append(a)
val = [0] * n
for i in range(q):
    p,x = readInts()
    p -= 1
    val[p] += x
stack = [(0,-1)]
while stack:
    v,p = stack.pop()
    for nv in G[v]:
        if nv == p:
            continue
        val[nv] += val[v]
        stack.append((nv,v))
# def dfs(v,p):
#     if p != -1:
#         val[v] += val[p]
#     for nv in G[v]:
#         if nv == p:
#             continue
#         dfs(nv,v)
#
# dfs(0,-1)
print(*val)


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

int main(){
    int n,k,ans;
    cin>>n>>k;
    ans=0;
    vector<int>p(n);
    rep(i,n) cin>>p[i];
    sort(p.begin(),p.end());
    rep(i,k) ans+=p[i];
    cout<<ans<<endl;
}

Measured memory_bytes: 3644
N, H = map(int, input().split())
A = []
B = []
for i in range(N):
    a, b = map(int,input().split())
    A.append(a)
    B.append(b)
A_sorted = sorted(A, reverse=True)
B_sorted = sorted(B, reverse=True)

ans = 0
attack_sum = 0
for i in range(N):
    if B_sorted[i] >= A_sorted[0]:
        if H > attack_sum:
            attack_sum += B_sorted[i]
            ans += 1
        else:
            print(ans)
            exit(0)
    else:break
ans += - (-(H - attack_sum) // A_sorted[0])
print(ans)



Measured memory_bytes: 18380
#include <iostream>
#include <vector>
#include <map>
#include <queue>
#include <string>
#include <algorithm>
#include <cmath>
#include <climits>
#define REP(i, n) for(int i=0; i<(n); i++)
#define FOR(i, a, n) for(int i=(a); i<(n); i++)
using namespace std;

int main(){
    string a,b,c;cin>>a>>b>>c;char capa = a[0]-32;char capb = b[0]-32;char capc = c[0]-32;cout << capa << capb << capc << endl;
    return 0;
}

Measured memory_bytes: 256
N, P = map(int, input().split())
A = list(map(int, input().split()))

even = 0
odd  = 0
for a in A:
    if a % 2 == 0:
        even += 1
    else:
        odd += 1

ans = 2 ** (even + odd - 1)
if odd == 0:
    if P == 1: ans = 0
    else: ans = 2 ** even
    
print(ans)


Measured memory_bytes: 3060
def solve():
    N, A, B = map(int, input().split())

    n_times = N // (A+B)
    amari = N % (A+B)

    cnt = 0
    if A <= amari:
        cnt = A
    else:
        cnt = amari
    
    print(n_times * A + cnt)

if __name__ == '__main__':
    solve()

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
using pii = pair<int, int>;
const int MOD = 1e9 + 7;
const int INF = 1 << 29;
const int N = 1e5 + 10;
 
struct IOsetup{
  IOsetup(){
   ios_base::sync_with_stdio(false);
   cin.tie(nullptr);
   cout.tie(nullptr);
   cout << fixed << setprecision(20);
  }
}IO;
 
int32_t main(){
 int a[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
 int k;
 cin >> k;
 cout << a[k - 1] << endl;
}

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

int main(){
	string Str;
	cin >> Str;
	int countStr01 = 0;
	int countStr10 = 0;
	for(int i = 0;i < Str.length(); i++){
		if(i % 2 == 0 && Str.at(i) == '1'){
			countStr01++;
		}else if(i % 2 == 1 && Str.at(i) == '0'){
			countStr01++;
		}
	}
	for(int i = 0;i < Str.length();i++){
		if(i % 2 == 0 && Str.at(i) == '0'){
			countStr10++;
		}else if(i % 2 == 1 && Str.at(i) == '1'){
			countStr10++;
		}
	}
	cout << min(countStr01, countStr10) << endl;
}

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

int main() {
  long n, a, b;
  cin >> n >> a >> b;
  if (n == 1 || a > b) {
    cout << ((a == b) ? 1 : 0) << endl;
    return 0;
  }
  cout << (n - 2) * (b - a) + 1 << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define pli pair<ll, int>
#define pil pair<int, ll>
#define pll pair<ll, ll>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define endl '\n'
const int inf = 1000000007;
const ll INF = 1e18;
int mod = 998244353;
// int mod = 1000000007;
const double eps = 1e-8;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
template<typename T, typename U> T pow_(T a, U b) { return b ? pow_(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, ll b, ll _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T, class U> ostream& operator << (ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<class T> ostream& operator << (ostream& os, const vector<T>& vec) { rep(i, sz(vec)) { if (i) os << " "; os << vec[i]; } return os; }
template<class T> ostream& operator << (ostream& os, const set<T>& s) { for (auto si : s) os << si << " "; return os; }
template<typename T> inline istream& operator >> (istream& is, vector<T>& v) { rep(j, sz(v)) is >> v[j]; return is; }
template<class T, class T2> inline void add(T &a, T2 b) { (a += (b % mod + mod)) %= mod; }
template<class T> void operator += (vector<T>& v, vector<T> v2) { rep(i, sz(v2)) v.eb(v2[i]); }

void solve();

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout << fixed << setprecision(12);
    int T;
    T = 1;
    while (T--) solve();
}

void solve() {
    ll n;
    cin >> n;
    
    auto prime_factorize = [&](ll x) {
        ll y = x;
        map<ll, int> mp;
        for (ll i = 2; i * i <= x; ++i) {
            int c = 0;
            while (y % i == 0) {
                y /= i;
                ++c;
            }
            if (c) mp[i] = c;
        }
        if (y != 1) mp[y] = 1;
        return mp;
    };
    auto mp = prime_factorize(n);
    // for (auto e : mp) cerr << e << endl;
    
    ll ans = 0;
    for (auto e : mp) {
        auto bin = [&](ll ok, ll ng) {
            auto check = [&](ll x) {
                if ((x + 1) * x / 2 <= e.S) return 1;
                return 0;
            };
            while (abs(ok - ng) > 1) {
                ll mid = (ok + ng) / 2;
                if (check(mid)) ok = mid;
                else ng = mid;
            }
            return ok;
        };
        ans += bin(0, inf);
    }
    cout << ans << endl;
}


Measured memory_bytes: 3648
/*
 _     _                             
| |__ | |__   __ _  __ _ _   _  __ _ 
| '_ \| '_ \ / _` |/ _` | | | |/ _` |
| |_) | | | | (_| | (_| | |_| | (_| |
|_.__/|_| |_|\__,_|\__, |\__, |\__,_|
                   |___/ |___/       
*/
#include<bits/stdc++.h>

#define ll          long long
#define pb          push_back
#define ppb         pop_back
#define	endl		'\n'
#define mii         map<ll int,ll int>
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define what_is(x)  cerr << #x << " is " << x << endl;
using namespace std;

#define N  1000050

ll int fir(ll int n)
{
	ll int ret;
	while(n!=0)
	{
		ret=n%10;
		n/=10;
	}
	return ret;
}

ll int las(ll int n)
{
	return n%10;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int TESTS=1;
	// cin>>TESTS;
	while(TESTS--)
	{
		ll int n;
		cin>>n;
		map<pii,ll int> ma;
		for(int f=1;f<=9;f++)
		{
			for(int l=1;l<=9;l++)
			{
				for(ll int i=1;i<=n;i++)
				{
					if(f==fir(i)&&l==las(i))
					{
						ma[{f,l}]++;
					}
				}
			}
		}
		ll int ans=0;
		for(auto it:ma)
		{
			ans+=it.S*ma[{it.F.S,it.F.F}];
		}
		// ans/=2;
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define FAST ios_base::sync_with_stdio(0); cin.tie(); cout.tie();
 
#define MAXX 100005
 
#define PI   3.14159265358979323846264338327950

#define PB push_back 
#define F first
#define S second
 
#define ll 	 long long int

#define mod  1000000007





int main()
{
	FAST;
	ll n;
	cin >> n;
	ll ans = 1000*(n/ 500);
	n %= 500;
	ans += 5*(n / 5);
	cout << ans;
	return 0;
}

Measured memory_bytes: 3616
import qualified Data.ByteString.Char8 as BS
import Control.Monad
import Data.Maybe

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words

getIntList = readIntList <$> BS.getLine
getIntNList n = map readIntList <$> replicateM (fromIntegral n) BS.getLine

getCommon :: [[Int]] -> [Int] -> [Int]
getCommon [] ys = ys
getCommon (xs:xss) [] = getCommon xss (tail xs)
getCommon (xs:xss) ys = getCommon xss (filter (\y -> y `elem` tail xs) ys)

main = do
  [n, m] <- getIntList
  ass <- getIntNList n
  print $ length (getCommon ass [])
  

Measured memory_bytes: 764
#include <stdio.h>
#include <math.h>

int main() {
  double A,B,D,E,H,M,x,y,z;
  scanf("%lf %lf %lf %lf",&A,&B,&H,&M);
  x = M_PI * M / 30;
  y = M_PI * H / 6 + M_PI * M / 360;
  if (x>=y)
    z = x - y;
  else
    z = y - x;
  D = A * A + B * B - 2 * A * B * cos(z);
  E = sqrt(D);
  printf("%.10lf",E);
}

Measured memory_bytes: 2576
// https://atcoder.jp/contests/arc074/tasks/arc074_a

#include "algorithm"
#include "bitset"
#include "cmath"
#include "functional"
#include "iomanip"
#include "iostream"
#include "map"
#include "numeric"
#include "queue"
#include "set"
#include "string"
#include "vector"
#define rep(i, to) for (ll i = 0; i < (to); ++i)
#define rep1(i, to) for (ll i = 1; i <= (to); ++i)
#define repf(i, from, to) for (ll i = from; i < (to); ++i)
#define repr(i, from) for (ll i = from - 1; i >= 0; --i)
#define all(vec) vec.begin(), vec.end()
#define unless(cond) if (!(cond))
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef long double ld;
template <typename T>
using V = vector<T>;
using VL = V<ll>;
using VVL = V<VL>;
template <typename T, typename U>
using P = pair<T, U>;
using PL = P<ll, ll>;
using VPL = V<PL>;
template <typename T>
inline bool chmax(T& a, T b);
template <typename T>
inline bool chmin(T& a, T b);
void print_ints(vector<ll> v);
template <typename T>
void drop(T a);

const ll INF = 1e18;

void solve() {
  ll H, W;
  cin >> H >> W;

  auto _solve = [](ll h, ll w) -> ll {
    ll res = INF;

    // T 型
    rep1(first_h, h - 1) {
      VL ss = {first_h * w, (h - first_h) * (w / 2),
               (h - first_h) * (w - w / 2)};

      chmin(res, *max_element(all(ss)) - *min_element(all(ss)));
    }

    // I 型

    rep1(first_h, h - 1) {
      VL ss = {first_h * w, ((h - first_h) / 2) * w,
               (h - first_h - (h - first_h) / 2) * w};

      chmin(res, *max_element(all(ss)) - *min_element(all(ss)));
    }

    return res;
  };

  ll res = min(_solve(H, W), _solve(W, H));
  cout << res << endl;
}

struct exit_exception : public std::exception {
  const char* what() const throw() { return "Exited"; }
};

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

  try {
    solve();
  } catch (exit_exception& e) {
  }

  return 0;
}
#endif

template <typename T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

template <typename T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

void print_ints(vector<ll> v) {
  rep(i, v.size()) {
    if (i > 0) {
      cout << " ";
    }

    cout << v[i];
  }

  cout << endl;
}

template <typename T>
void drop(T res) {
  cout << res << endl;
  throw exit_exception();
}


Measured memory_bytes: 256
// 3_abc132_c
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define SZ(x) ((int)(x).size())
#define INF (1e16)
typedef long long ll;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> d(n);
    rep(i, n){
        cin >> d[i];
    }
    sort(d.begin(), d.end());

    int l, r;
    l = d[n / 2 - 1];
    r = d[n / 2];

    cout << r - l << endl;
    return 0;
}


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

int main()
{
	int a, b;
	scanf("%d%d", &a, &b);
	if (1 <= a && a <= 9 && 1 <= b && b <= 9)
		printf("%d\n", a * b);
	else puts("-1");
	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <cmath>
#include <vector>
#include <set>

using namespace std;

#define EPS (1e-8)

struct Point {
    double x, y, z;
    Point(){}
    Point(double x, double y, double z) :
        x(x), y(y), z(z) {}
};

double dot(const Point &a, const Point &b)
{
    return a.x*b.x + a.y*b.y + a.z*b.z;
}

double norm(const Point &p)
{
    return dot(p, p);
}

double abs(const Point &p)
{
    return sqrt(norm(p));
}

bool can_watch(const Point &a, const Point &b, double the)
{
    double t = acos(dot(a, b) / abs(a) / abs(b));
    return (t < the + EPS);
}

int main()
{
    int n, m;
    while (cin >> n, n) {
        vector<Point> s(n);
        for (int i = 0; i < n; i++) {
            cin >> s[i].x >> s[i].y >> s[i].z;
        }
        Point p;
        double the;
        set<int> stars;
        cin >> m;       
        for (int i = 0; i < m; i++) {
            cin >> p.x >> p.y >> p.z >> the;
            for (int j = 0; j < n; j++) {
                if (can_watch(s[j], p, the)) {
                    stars.insert(j);
                }
            }
        }
        cout << stars.size() << endl;
    }
    return 0;
}

Measured memory_bytes: 1324
s=list(input())
def C(s):
    if s[0]!='A':
        return False
    if 'C' in s:
        i=s.index('C')
        if 2<=i<=len(s)-2:
            k=s.pop(i)
            l=s.pop(0)
            if ''.join(s).islower():
                return True
            
    return False
if (C(s)):
    print('AC')
else:
    print('WA')


Measured memory_bytes: 2940
using System;

class MyClass
{
    static void Main(string[] args)
    {
        string[] str = Console.ReadLine().Split(' ');
        int a = int.Parse(str[0]);
        int b = int.Parse(str[1]);
        if (a < b)
        {
            Console.WriteLine("a < b");
        }
        if (a > b)
        {
            Console.WriteLine("a > b");
        }
        if (a == b)
        {
            Console.WriteLine("a == b");
        }
    }
}


Measured memory_bytes: 5284
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)n; i++)
using ll = long long;
const ll mod = 1e9+7;

int main(){
  int n, m;
  cin >> n >> m;
  ll x[n], y[m];
  rep(i,n) cin >> x[i];
  rep(i,m) cin >> y[i];
  sort(x,x+n,greater<ll>());
  sort(y,y+m,greater<ll>());
  ll sx = 0, sy = 0;
  rep(i,n) (sx += x[i]*(n-1-2*i)) %= mod;
  rep(i,m) (sy += y[i]*(m-1-2*i)) %= mod;
  cout << sx*sy % mod << endl;
  return 0;
}


Measured memory_bytes: 1792