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

using namespace std;

using ll = long long; 

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

    int n;
    cin >> n;
    int a[n], b[n];
    vector<pair<int, int>> sums;
    for (int i = 0; i < n; ++i) {
        cin >> a[i] >> b[i];
        sums.emplace_back(a[i] + b[i], i);
    }
    sort(sums.rbegin(), sums.rend());

    ll a_total = 0;
    for (int i = 0; i < n; ++i) {
        int idx = sums[i].second;
        if (i % 2 == 0) {
            a_total += ll(a[idx]);
        } else {
            a_total -= ll(b[idx]);
        }
    }

    cout << a_total << '\n';

    return 0;
}


Measured memory_bytes: 1912
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	int arr[n+1];
	arr[0]=-100000;
	for(int i=1;i<=n;i++){cin>>arr[i];}
	long long int dp[n+1];
	dp[0]=0;
	dp[1]=0;
	for(int i=2;i<=n;i++){
		dp[i]=min(dp[i-1]+abs(arr[i]-arr[i-1]),dp[i-2]+abs(arr[i]-arr[i-2]));
		}
	cout<<dp[n]<<endl;
	
	}


Measured memory_bytes: 1408
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
 
using namespace std;
 
typedef long long ll;
 
#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=b-1LL;i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;
 
#define MOD 1000000007

int main(){
  ll n,r;
  cin>>n>>r;
  if(n>=10){
    cout << r << endl;
  }
  else{
    cout << r+100*(10-n) << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
	int main(){
		IOS
		int a,b;
		cin>>a>>b;
		if(a<6){
			cout<<"0"<<endl;
		}
		else  if(a>12)
			cout<<b<<endl;
		else
			cout<<b/2<<endl;
		
	} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
 using namespace std;
 using pii = pair<int, int>;
 using ll = long long;
 #define rep(i, j, n) for(int i = j; i < (int)(n); i++)
 const ll MOD = 1000000007;
 const ll INFL = (1LL << 60);
 const int INFI = (1 << 30);

 int main() {
   vector<int> cnt(4, 0);

   int N; cin >> N;

   rep(i, 0, N) {
     string tmp; cin >> tmp;
     if (tmp == "AC") cnt.at(0)++;
     else if (tmp == "WA") cnt.at(1)++;
     else if (tmp == "TLE") cnt.at(2)++;
     else cnt.at(3)++;
   }

   cout << "AC x " << cnt.at(0) << endl;
   cout << "WA x " << cnt.at(1) << endl;
   cout << "TLE x " << cnt.at(2) << endl;
   cout << "RE x " << cnt.at(3) << endl;
 }


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

using namespace std;

typedef long long ll;

const int MAX = 2010101;
ll MOD = 1000000007;

ll fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
        fac[0] = fac[1] = 1;
        finv[0] = finv[1] = 1;
        inv[1] = 1;
        for (int i=2; i<MAX; i++) {
                fac[i] = fac[i - 1] * i % MOD;
                inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
                finv[i] = finv[i - 1] * inv[i] % MOD;
        }
}

ll COM(int n, int k) {
        if (n < k) return 0;
        if (n < 0 || k < 0) return 0;
        return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(int, char**) {
	COMinit();
	int x, y; cin >> x >> y;
	int diff = abs(x - y);
	int rem = min(x, y) - diff;
	if (rem<0 || rem%3!=0) {
		cout << 0 << endl;
		return 0;
	}
	ll ret = COM(diff + 2 * rem/3, rem/3);
	cout << ret << endl;
	return 0;
}


Measured memory_bytes: 47360
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod=1e9+7;
int main(void){
    string K;
    int D;
    cin>>K>>D;
    int n=K.size();
    ll dp[10010][2][100]={};
    dp[0][0][0]=1;
    for(int i=0;i<n;i++){
        int a=K[i]-'0';
        for(int j=0;j<D;j++){
            for(int x=0;x<10;x++){
                dp[i+1][1][(j+x)%D]+=dp[i][1][j];
                if(x==a){
                    dp[i+1][0][(j+x)%D]+=dp[i][0][j];
                }
                else if(x<a){
                    dp[i+1][1][(j+x)%D]+=dp[i][0][j];
                }
                dp[i+1][0][(j+x)%D]%=mod;
                dp[i+1][1][(j+x)%D]%=mod;
            }
        }
    }
    cout<<(dp[n][0][0]+dp[n][1][0]-1+mod)%mod<<endl;
}

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

int main()
{
  ll n;
  cin >> n;
  
  ll x, y;
  ll ans = 1e13;
  for(int i = 1; i <= sqrt(n); i++)
  {
    if(n % i == 0)
    {
      x = i;
      y = n / i;
      
      if( ((x-1) + (y-1)) < ans )
      {
        ans = (x-1) + (y-1);
      }
    }
  }
  
  cout << ans << endl;
}


Measured memory_bytes: 3680
n, m = map(int, input().split())
sc_dict = {}
for i in range(m):
    si, ci = map(int, input().split())
    if not si in sc_dict.keys():
        sc_dict[si] = [ci]
    elif not ci in sc_dict[si]:
        sc_dict[si].append(ci)

flag = 0
for k, v in sc_dict.items():
    if len(v) >= 2:
        flag = 1
        break
    if n != 1 and k == 1 and 0 in v:
        flag = 1
        break

if flag:
    print(-1)
elif n == 1 and 1 in sc_dict.keys() and 0 in sc_dict[1]:
    print(0)
elif n == 1 and not 1 in sc_dict.keys():
    print(0)
else:
    res = ''
    for i in range(n):
        if i+1 in sc_dict.keys():
            res += str(sc_dict[i+1][0])
        elif i == 0:
            res += '1'
        else:
            res += '0'
    print(res)

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

int main(){
  string s;
  cin>>s;
  int ans=0;
  ans+=s[0]-1-'0';
  ans+=9*(s.size()-1);
  int ans0=0;
  rep(i,s.size()){
    ans0+=s[i]-'0';
  }
  ans=max(ans,ans0);
  cout<<ans<<endl;
}

Measured memory_bytes: 256
/**
 * @brief  : c++ code for AtCoder
 * @author : rk222
 * @created: 2019.07.07 20:59:47
 */

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef pair<int, P> P1;

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define rep(i, x) for (int i = 0; i < x; i++)
#define rep1(i, x) for (int i = 1; i <= x; i++)
#define rrep(i, x) for (int i = x - 1; i >= 0; i--)
#define rrep1(i, x) for (int i = x; i > 0; i--)
#define sor(v) sort(v.begin(), v.end())
#define rev(s) reverse(s.begin(), s.end())
#define lb(vec, a) lower_bound(vec.begin(), vec.end(), a)
#define ub(vec, a) upper_bound(vec.begin(), vec.end(), a)
#define uniq(vec) vec.erase(unique(vec.begin(), vec.end()), vec.end())
#define mp1(a, b, c) P1(a, P(b, c))

#define disp(x) cout << #x << ": " << x << endl
#define disp_vec(v)                                                                           \
    cout << #v << ":";                                                                        \
    rep(i, v.size()) cout << " " << v[i];                                                     \
    cout << endl

const int INF = 100000000;
const int M = 100000000;
const int dir_4[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
const int dir_8[8][2] = {{1, 0}, {1, 1}, {0, 1}, {-1, 1}, {-1, 0}, {-1, -1}, {0, -1}, {1, -1}};

/* ------------------------------------- */

int main() {
    ll l, r;
    scanf("%lld%lld", &l, &r);
    ll ret = 2019LL;
    for (ll i = l; i <= l + 2030; i++) {
        if (i > r)
            break;
        for (ll j = l; j <= l + 2030; j++) {
            if (j > r)
                break;
            if (j <= i)
                continue;
            ll a = (j * i) % 2019LL;
            // cout << a << endl;
            ret = min(ret, a);
        }
    }
    printf("%lld\n", ret);

    /* --------------------------------- */
    return 0;
}

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

int main() {
    string s,t;cin>>s>>t;
    int n = s.size();
    rep(i,n){
        int tmp=0;
        rep(j,n){
            if(s[j]!=t[(i+j)%n])tmp=1;
    }
    if(tmp==0){
        cout<<"Yes"<<endl;
        return 0;
    }
    }
    cout<<"No"<<endl;
	return 0;
}



Measured memory_bytes: 3600
import java.util.Scanner;
class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		
		while(scan.hasNext()){
			String str = scan.nextLine();
			int n = str.length();
			for(int i = n-1;i >= 0;i--){
				char t = str.charAt(i);
				System.out.print(t);
			}
			System.out.println();
		}
	}
}

Measured memory_bytes: 11000
#include <stdio.h>
#include <stdlib.h>
int main()
{
    int a,b,c,d;
    while(~scanf("%d %d %d %d",&a,&b,&c,&d))
    {
        if(a*b>=c*d)
            printf("%d\n",a*b);
        else
            printf("%d\n",c*d);
    }
        return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
int main(void)
{
    int a,b,d,r;
    double f;
    scanf("%d %d",&a,&b);
    d=a/b;
    r=a%b;
    f=(double)a/b;
    printf("%d %d %f\n",d,r,f);
    return 0;
}



Measured memory_bytes: 2100
#include <iostream>
#include <cmath>
using namespace std;
const int MAXN = 10005;
int a[MAXN], b[MAXN];

int main()
{
    int n;
    long long int diff1 = 0, diff2 = 0;

    cin >> n;

    for(int i = 1; i <= n; i++)
        cin >> a[i] ;
    for(int i = 1; i <= n; i++)
        cin >> b[i] ;

    for(int i = 1; i <= n; i++)
    {
        if(a[i] >= b[i])
        {
            diff1 += a[i] - b[i] ;
        }
        else
        {
            //int t = b[i] - a[i];
            //if(t & 1)
            //    t -= 1;
            diff2 += (b[i] - a[i]) / 2 * 2;
        }
    }

    if(diff2 / 2 >= diff1)
        cout << "Yes" << endl ;
    else
        cout << "No" << endl ;

    return 0;
}


Measured memory_bytes: 384
//----------------------------------------------------------------------
#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(void) {
    int n; cin >> n;
    int ans= 0;
    for(int i = 1; i <= n; ++i) {
        int yaku= 1;
        int tmp = i;
        int number = 0;
        while(tmp >= yaku) {
            if(tmp%yaku==0) {
                number++;
                yaku++;
            }else{
                yaku++;
            }
        }
        if(number == 8 && i %2 != 0) {
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;

typedef long long ll;

const ll M=1e9+7;
const int N=1e3+10;

ll myPow(ll a,ll n)
{
    ll ans=1;
    while(n>0)
    {
        if(n&1)
        {
            ans=ans*a%M;
        }
        a=a*a%M;
        n>>=1;
    }
    return ans;
}

ll fac[N],inv[N];

void init()
{
    fac[0]=1;
    for(int i=1;i<N;i++)
    {
        fac[i]=fac[i-1]*i%M;
    }
    inv[N-1]=myPow(fac[N-1],M-2);
    for(int i=N-2;i>=0;i--)
    {
        inv[i]=inv[i+1]*(i+1)%M;
    }
}

int main()
{
    init();
    int n,k;
    while(cin>>n>>k)
    {
        ll ans=0;
        for(int i=0;i<k;i++)
        {
            ll tmp=fac[k]*inv[k-i]%M*inv[i]%M*myPow(k-i,n)%M;
            ans+=(i%2?-1:1)*tmp;
            ans=(ans+M)%M;
        }
        cout<<ans<<endl;
    }

    return 0;
}



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

class Program
{
    static void Main()
    {
        new Program().Solve();
    }
    
    public void Solve()
    {
        var n=int.Parse(Console.ReadLine());
        var map=new Dictionary<int,bool>();
        for(int i=0;i<n;i++)
        {
            var a=int.Parse(Console.ReadLine());
            bool o;
            map.TryGetValue(a,out o);
            map[a]=!o;
        }
        int ans=0;
        foreach(var p in map)
        {
            if(p.Value)ans++;    
        }
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 21088
class Pos
  attr_accessor :x, :y

  def initialize(x, y)
    @x = x
    @y = y
  end

  def to_s
    "ball #{@x} #{@y}"
  end
end

BIG_NUM = 10**10

N = gets.chop.to_i
balls = []
N.times do |n|
  x, y = gets.chop.split.map(&:to_i)
  balls << Pos.new(x, y)
end

if N == 1
  puts 1
  exit 
end

diffs = []
N.times do |i|
  N.times do |j|
    next if i == j
    diffs << Pos.new(balls[i].x - balls[j].x, balls[i].y - balls[j].y)
  end
end

diffs.sort! { |a, b| a.x * BIG_NUM + a.y <=> b.x * BIG_NUM + b.y }

max_same = 1
until diffs.empty?
  ct = 1
  cur = diffs.shift
  while !diffs.empty? && diffs[0].x == cur.x && diffs[0].y == cur.y
    ct += 1
    diffs.shift
  end
  max_same = [max_same, ct].max
end
puts N - max_same


Measured memory_bytes: 2168
#include <algorithm>
#include <stdio.h>

using namespace std;

int gcd(int x,int y){
    int r;
    if(x < y){
        // 入れ替え
        swap(x,y);
    }
    
    while(y > 0){
        r = x % y;
        x = y;
        y = r;
    }
    return x;
}

int main(){
    int x,y;
    scanf("%d %d",&x,&y);
    printf("%d\n",gcd(x,y));
    return 0;
}



Measured memory_bytes: 2764
#include<iostream>
#include<string>
#include<stdio.h>
#include<sstream>


using namespace std;


int main(){
    int res=0;

    string str;
    int n;
    int a, b;

    cin>>n>>a>>b;

    for (int i=1; i<n+1;++i ){
        str=to_string((int)i);

        int sum=0;
        for(int j=0; j<(int)str.size(); ++j){
            //istringstream ss;
            //cout<<(int)str[j]<<endl;
            sum+=str[j]-'0';

            int l;
            //sum+=stoi();
        }
        //cout<<sum<<endl;
        if(sum>=a && sum<=b){
            res+=i;
        }
    }
    cout<<res;






}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define SZ(x) ((int)(x).size())
#define debug(x) cerr << #x << ": " << x << '\n'
const int INF = (1<<60);
typedef long long int Int;
typedef pair<int,int> P;
using ll = long long;
using VI = vector<int>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

signed main(){
    const Int n=4;
    Int d[n][n];
    for(Int i=0;i<n;i++){
        for(Int j=0;j<n;j++){
            d[i][j] = 10000*(i!=j);
        }
    }

    for(Int i=1;i<n;i++){
        Int a,b;cin >> a >> b;
        a--,b--;
        d[a][b] = 1;
        d[b][a] = 1;
    }

    for(Int k=0;k<n;k++){
        for(Int i=0;i<n;i++){
            for(Int j=0;j<n;j++){
                chmin(d[i][j],d[i][k]+d[k][j]);
            }
        }
    }
    
    for(Int i=0;i<n;i++){
        for(Int j=0;j<n;j++){
            if(d[i][j]==3){
                cout << "YES" << endl;
                return 0;
            }
        }
    }
    cout << "NO" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <iomanip>
#include <cmath>
#include <cstdio>
#include <set>
#define REP(i,n) for (int i=0;i<(n);++i)
using namespace std;
using ll = long long;

ll a, b, k;
bool prime[300010];

int main() {
  cin >> a;
  set<int> st;
  for(int i = 2; i <= 300000; ++i) {
    if (!prime[i]) {
      st.insert(i);
      for(int j = i; j <= 300000; j += i) prime[j] = true;
    }
  }
  cout << *st.lower_bound(a) << '\n';
  return 0;
}



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

int main(){
    using namespace std;
    unsigned long N, M;
    cin >> N >> M;
    unsigned long L{0}, R{N + 1};
    for(unsigned long i = 0, l, r; i < M; ++i){
        cin >> l >> r;
        L = max(l, L);
        R = min(r, R);
    }
    cout << (R >= L ? R - L + 1 : 0) << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n ; i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define whole(f, x, ...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x) // decltypeで型取得、引数があればva_argsのところに入れる
using namespace std;
typedef long long ll; // long longをllでかけるようにした
const int INF = 1e9;

int main(void){
    int n, q; cin >> n >> q;
    string s;
    cin >> s;
    vector<int> A(n);
    REP(i, n - 1){
        if(s[i] == 'A' && s[i + 1] == 'C') A[i + 1] = A[i] + 1;
        else A[i + 1] = A[i];
    }
    REP(i, q){
        int r, l; cin >> r >> l;
        cout << A[l - 1] - A[r - 1] << endl;
    }
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define rep1(i, n) for(int i=1; i<=n; i++)
#define repr(i, n) for(int i=n-1; i>=0; i--)
#define repr1(i, n) for(int i=n; i>=1; i--)
#define all(v) v.begin(),v.end()
using ll = long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
const double EPS = 1e-10;
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; }

ll dp[2010][2010];

int main() {
    int n; cin >> n;
    vector<pli> a(n);
    rep(i, n) {
        cin >> a[i].first;
        a[i].second = i;
    }

    sort(all(a));
    reverse(all(a));
    rep(i, n+1) rep(j, n+1) dp[i][j] = -LLINF;
    dp[0][0] = 0;
    rep(i, n) {
        rep(j, n) {
            chmax(dp[i+1][j+1], dp[i][j] + a[i].first * abs(a[i].second - j));
            chmax(dp[i+1][j], dp[i][j] + a[i].first * abs(a[i].second - (n-i+j-1)));
        }
    }

    ll ans = 0;
    rep(i, n+1) chmax(ans, dp[n][i]);
    cout << ans << endl;
}


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

#define DUMP(x) cerr << #x << "=" << x << endl
#define DUMP2(x, y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<")"<< endl
#define BINARY(x) static_cast<bitset<16> >(x)

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

#define in_range(x, y, w, h) (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))
#define ALL(a) (a).begin(),(a).end()

typedef long long ll;
const int INF = 1e9;
typedef pair<int, int> PII;
int dx[4]={0, -1, 1, 0}, dy[4]={-1, 0, 0, 1};

int main()
{
    ios::sync_with_stdio(false);

    string S;
    cin >> S;

    vector<string> list = { "dream", "dreamer", "erase", "eraser" };

    int p = S.size();
    while (true) {
        bool ok = false;
        for (auto t : list) {
            if (p - (int)t.size() >= 0 && S.substr(p - t.size(), t.size()) == t) {
                p -= t.size();
                ok = true;
                break;
            }
        }
        if (!ok) break;
    }
    cout << (p == 0 ? "YES" : "NO") << endl;
}


Measured memory_bytes: 512
N = int(input())
T = input().rstrip().split(" ")
T = [int(i) for i in T]
M = int(input())
for i in range(M):
    To = T[:]
    temp = input().rstrip().split(" ")
    P = int(temp[0])
    X = int(temp[1])
    T[P-1] = X
    print(sum(T))
    T = To[:]

Measured memory_bytes: 3064
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <functional>
#include <stack>
#include <iomanip>
#include <limits>
using namespace std;
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
using Graph=vector<vector<int>>;
using edge= struct{int to;ll cost;};

template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}

typedef priority_queue<ll> PQ_HIGH;
typedef priority_queue<ll,VL,greater<ll>> PQ_LOW;

#define EPSILON 1.0e-12

bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
};
//降順
bool compare_by_b_high(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second > b.second;
    }else{
        return a.first < b.first;
    }
};
bool compare_by_b_higheer(tuple<string, int, int> a, tuple<string, int, int> b) {
    if(get<0>(a) != get<0>(b)){
      return get<0>(a) <get<0>(b);
    }else{
        if(get<1>(a) != get<1>(b)){return get<1>(a) > get<1>(b);}
        else{return get<2>(a) > get<2>(b);}
    }
};


int main(){
  int N,D;cin>>N>>D;
  vector<vector<double>> d(N,vector<double>(D,0));
  REP(i,N){
    REP(j,D){
      cin>>d[i][j];
    }
  }
  int count=0;
  for(int i=0;i<N-1;i++){
    for(int j=i+1;j<N;j++){
      double tmp,tmp1;
      tmp=tmp1=0;
      REP(r,D){
        tmp+=pow(d[i][r]-d[j][r],2);
      }
      tmp=pow(tmp,0.5);
      tmp1=int(tmp);
      if(tmp1==tmp){
        count++;
      }
    }
  }
  cout<<count<<endl;
}

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

int main()
{
	int N;
	cin >> N;
	vector<int> p(N);
	for (int i = 0; i < N; i++)
		cin >> p[i];
	sort(p.begin(), p.end());
	p[N - 1] /= 2;
	int ans = 0;
	for (int i = 0; i < N; i++)
		ans += p[i];
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String [] args){
        Scanner sc =new Scanner(System.in);
        int N =sc.nextInt();
        String s[]  = new String[N];
        long m=0;
        long a=0;
        long r=0;
        long c=0;
        long h=0;
        for (int i=0;i<N;i++) {
            s[i] = sc.next();
            if(s[i].charAt(0) == 'M') {
                m++;
            }
            if(s[i].charAt(0) =='A') {
                a++;
            }
            if(s[i].charAt(0) =='R') {
                r++;
            }
            if(s[i].charAt(0) =='C') {
                c++;
            }
            if(s[i].charAt(0)=='H') {
                h++;
            }
        }
        long ans =m*a*r + m*a*c + m*a*h + m*r*c + m*r*h + m*c*h
                +a*r*c + a*r*h + a*c*h + r*c*h;
        System.out.println(ans);

    }
}

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

int main()
{
  long n, m;
  cin >> n >> m;
  vector<long> p(m), y(m), count(n + 1), id(m);
  for (int i = 0; i < m; i++) {
    cin >> p.at(i) >> y.at(i);
    y.at(i) = 100000 * y.at(i) + i;
  }
  sort(y.begin(), y.end());
  for (int i = 0; i < m; i++) {
    long order = y.at(i) % 100000;
    count.at(p.at(order))++;
    id.at(order) = 1000000 * p.at(order) + count.at(p.at(order));
  }
  for (int i = 0; i < m; i++) {
    printf("%12.12ld\n", id.at(i));
  }
}


Measured memory_bytes: 4608
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
//#include <utility>
#include <set>
#include <iostream>
//#include <memory>
#include <string>
#include <vector>
#include <algorithm>
//#include <functional>
#include <sstream>
//#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
//#include <cctype>
#include <cstring>
//#include <ctime>
#include <iterator>
#include <bitset>
//#include <numeric>
//#include <list>
//#include <iomanip>

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <unordered_set>
#include <unordered_map>
#include <forward_list>

#define cauto const auto&
#else

#endif

using namespace std;


namespace{
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
}


#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define F first
#define S second
#define mkp make_pair
#define RALL(v) (v).rbegin(),(v).rend()


#define MOD 1000000007LL
#define EPS 1e-8
static const int INF=1<<24;

void mainmain(){
	string s;
	while(getline(cin,s)){
		stringstream ss;
		ss<<s;
		string s1;
		ss>>s1;
		cout<<s1<<" ";
		int a,b,c=0;
		ss>>a>>b;
		cout<<a+b<<" ";
		cout<<a*200+b*300<<endl;
	}
}



}
main() try{
    mainmain();
}
catch(...){
}

Measured memory_bytes: 1228
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<map>
typedef long long ll;
typedef double dd;
#define For(i,j,k) for (int i=(int)j;i<=(int)k;++i)
#define Forr(i,j,k) for (int i=(int)j;i>=(int)k;--i)
#define Set(a,p) memset(a,p,sizeof(a))
using namespace std;

template<typename T>bool chkmax(T &a,T b) { return a<b?a=b,1:0; }
template<typename T>bool chkmin(T &a,T b) { return a>b?a=b,1:0; }

const int maxn=2e5+1e2;
int n;
ll Ans,val[maxn];
map<ll,int>cnt;

inline void file() {
	freopen("AGC023A.in","r",stdin);
	freopen("AGC023A.out","w",stdout);
}

inline int read() {
	int x=0,p=1;
	char c=getchar();
	while (!isdigit(c)) { if (c=='-') p=-1; c=getchar();}
	while (isdigit(c)) { x=(x<<1)+(x<<3)+(c-'0'); c=getchar();}
	return x*p;
}

int main() {
//	file();
	n=read();
	For (i,1,n) val[i]=read(),val[i]+=val[i-1];
	For (i,0,n) cnt[val[i]]++;
	For (i,0,n) {
		Ans+=1ll*cnt[val[i]]*(cnt[val[i]]-1)/2;
		cnt[val[i]]=0;
	}
	printf("%lld\n",Ans);
	return 0;
}

Measured memory_bytes: 14336
a = gets.chomp.to_i
b = gets.chomp.to_i
c = gets.chomp.to_i
d = gets.chomp.to_i
ans = 0
if a >= b
    ans += b
else
    ans += a
end
if c >= d
    ans += d
else
    ans += c
end
print(ans)

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

class Program
{
    #region Lib

    static int Gcd(int a, int b)
    {
        if (a % b == 0)
            return b;
        else
            return Gcd(b, a % b);
    }

    #endregion

    static void Main()
    {
        var k = ReadInts()[1];
        var nums = ReadInts();
        Array.Sort(nums);

        long maxSum = 0;
        long minSum = 0;

        ModInt.COMinit();

        for (int i = k - 1; i < nums.Length; i++)
        {
            maxSum += ModInt.COM(i, k - 1) * nums[i];
            maxSum %= ModInt.MOD;
        }

        Array.Reverse(nums);

        for (int i = k-1; i < nums.Length; i++)
        {
            minSum += ModInt.COM(i, k - 1) * nums[i];
            minSum %= ModInt.MOD;
        }

        var ret = (maxSum + ModInt.MOD - minSum) % ModInt.MOD;

        Console.WriteLine(ret);
    }




    #region Utils
    public static int[] ReadInts()
    {
        return Console.ReadLine().Split().Select(int.Parse).ToArray();
    }
    #endregion

}



static class ModInt
{

    public const int MOD = 1000000000 + 7;

    const int MAX = 510000;

    static long[] fac = new long[MAX];
    static long[] finv = new long[MAX];
    static long[] inv = new long[MAX];

    public static void COMinit()
    {
        fac[0] = fac[1] = 1;
        finv[0] = finv[1] = 1;
        inv[1] = 1;
        for (int i = 2; i < MAX; i++)
        {
            fac[i] = fac[i - 1] * i % MOD;
            inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
            finv[i] = finv[i - 1] * inv[i] % MOD;
        }
    }

    // 二項係数計算
    public static long COM(int n, int k)
    {
        if (n < k) return 0;
        if (n < 0 || k < 0) return 0;
        return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
    }

}



Measured memory_bytes: 34868
#include <bits/stdc++.h>
#define rep(i,cc,n) for(int i=cc;i<=n;++i)
#define drep(i,cc,n) for(int i=cc;i>=n;--i)
#define sz(s) (int)(s.size())
#define vecprint(v) rep(i,0,v.size()-1)cout << v[i] << " ";cout << endl;
#define arrprint(v,n) rep(i,0,n-1)cout << v[i] << " ";cout << endl;
#define matprint(v,n,m) rep(i,0,n-1){rep(j,0,m-1){cout << v[i][j] << " ";}cout << endl;}
using namespace std;
const int mod=1000000007;
const int INF=1001001001;
typedef long long ll;
typedef pair<int,int> P;

int main(){
    ll a,b,c;
    cin >> a >> b >> c;
    if((4*a*b < (a+b-c)*(a+b-c)) &&(a+b-c < 0))puts("Yes");
    else puts("No");

    // cout << ans << endl;
//  printf("%.10f\n",ans);

    return 0;
}

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

using namespace std;

int main() {
    long long int n;
    cin>>n;
    long long int a[n];
    long long int sum = 0;
    for(int i = 0; i < n; i++) {
        cin>>a[i];
        if( i > 0) {
            sum += a[i]%MOD;
        }
    }
    sum = sum%MOD;
    long long int ans = 0;
    for(int i = 0; i < n; i++) {
        if(i > 0) {
            sum = (sum+MOD-a[i]%MOD)%MOD;
            ans += (a[i]%MOD * sum)%MOD;
        } else {
            ans += (a[i]%MOD * sum)%MOD;
        }
    }
    cout<<ans%MOD;
    return 0;
}

Measured memory_bytes: 5204
import sys 
from collections import deque
sys.setrecursionlimit(10**6)
def S(): return sys.stdin.readline().rstrip()
def SL(): return map(str,sys.stdin.readline().rstrip().split())
def I(): return int(sys.stdin.readline().rstrip())
def IL(): return map(int,sys.stdin.readline().rstrip().split())
def LS(): return list(sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))

def main():
    x = LI()
    for i in range(len(x)):
        if x[i] == 0:
            print(i+1)
            exit()
    return

if __name__=='__main__':
    main()

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

ll findpow(ll a,ll b){
    ll cnt=0,i,j;
    while(a>1){
        a=a/b;
        cnt++;
    }
    return cnt;
}

int main(){
    ll i,j,k,sum,flag=0,t,m,n;
   string s1,s2,s;
   cin>>n;
   k=n/500;
   t=n-k*(500);
   t=t/5;
   cout<<k*1000+5*t<<endl;




	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int a,b,c,tmp;
  scanf("%d%d%d",&a,&b,&c);
  
  if(a>b){
    tmp=a;
    a=b;
    b=tmp;
  }
  if(b>c){
    tmp=c;
    c=b;
    b=tmp;
  }
  if(a>b){
    tmp=a;
    a=b;
    b=tmp;
  }
  
  if(a+b==c){
    printf("Yes");
  }else{
    printf("No");
  }
  
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define REVERSE(a) reverse(a.begin(), a.end())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define int long long
#define INF 1000000000000000000
using namespace std;

typedef vector<int> vec;
typedef vector<vec> mat;
typedef pair<int, int> Pii;

template<typename T>
void readvec(vector<T> &a);
void readindex(vector<int> &a);



signed main(){

    int N; cin >> N;
    string S; cin >> S;

    int dmin = INF;
    int d = 0;
    REP(i, N){
        if(S[i] == '(') d++;
        else d--;
        dmin = min(d, dmin);
    }

    if(dmin < 0){
        REP(i, -1 * dmin) S = '(' + S;
        d -= dmin;
    }
    REP(i, d) S = S + ')';
    
    cout << S;
    
    return 0;
}


template<typename T>
void readvec(vector<T> &a){
    REP(i, a.size()){
        cin >> a[i];
    }
}
void readindex(vector<int> &a){
    REP(i, a.size()){
        cin >> a[i];
        a[i]--;
    }
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < n; ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end()) 
#define FORV(i, v) for (auto i = v.begin(); i != v.end(); i++)
using namespace std;

typedef long long ll;

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; }
const int INF = 1001001001;
const long long INFL = (1LL<<60);
const double eps = (1e-9);


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

  int n;
  cin >> n;

  list<int> l;
  l.push_back(-1);
  rep(i, n) {
    int t;
    cin >> t;
    l.push_back(t);
  }

  vector<int> a(n, 0);

  for (int i = n; i > 0; i--) {
    int j = 0;
    auto tmp = l.end();
    for (auto itr = l.begin(); itr != l.end(); itr++) {
//      cerr << "j: " << j << "   " << *itr << endl;
      if (*itr == j) {
        tmp = itr;
      }
      j++;
    }
//    cerr << "tmp: " << *tmp << endl;
    if (tmp == l.end()) {
      puts("-1");
      return 0;
    }
    a[i-1] = *tmp;
    l.erase(tmp);
  }

  rep(i, n) {
    cout << a[i] << endl;
  }

  return 0;
}


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

using namespace std;

#define LL long long
#define N 200005
#define mod 1000000007LL

LL ans, a[N], b[N], _gcd, p, q;
int n, cur, T, i, r, vis[N], p0;
map<pair<LL,LL>, int> K;
pair<LL,LL> Q[N];
pair<pair<LL,LL>, int> label[N];

LL power(LL x,int y)
{
	LL t=1;
	for (; y; y>>=1) {
		if (y&1) t=t*x%mod;
		x=x*x%mod; 
	}
	return t;
}

int main (void)
{
	//freopen("1.in","r",stdin);
	//freopen("1.out","w",stdout);
	scanf("%d",&n);
	for (i=1; i<=n; i++) {
		scanf("%lld%lld",&a[i],&b[i]);
		if (a[i]<0||!a[i]&&b[i]<0) a[i]=-a[i],b[i]=-b[i];
		if (!a[i]&&!b[i]) {
		    p0++;
			continue;
		}
		_gcd=__gcd(abs(a[i]),abs(b[i]));
		a[i]/=_gcd,b[i]/=_gcd;
		Q[i]=make_pair(a[i],b[i]);
	}	
	sort(Q+1,Q+n+1);
	cur=T=1;
	for (i=2; i<=n; i++) {
		if (Q[i].first==Q[i-1].first&&Q[i].second==Q[i-1].second) cur++;
		else label[T]=make_pair(Q[i-1],cur),T++,cur=1;
	}
	if (cur) label[T]=make_pair(Q[i-1],cur);
	for (i=1; i<=T; i++) K[label[i].first]=i;
	ans=1;
	for (i=1; i<=T; i++) {
		if (vis[i]) continue;
		p=-label[i].first.second; q=label[i].first.first;
		if (!p&&!q) continue;
		if (p<0||!p&&q<0) p=-p,q=-q;
		_gcd=__gcd(abs(p),abs(q));
		p/=_gcd,q/=_gcd;
		r=K[make_pair(p,q)];
		//printf("%d %d\n",i,r);
		if (r) {
			ans=ans*(power(2LL,label[i].second)+power(2LL,label[r].second)-1)%mod;
			if (ans<0) ans+=mod;
			vis[i]=vis[r]=1;
		}
		else {
			ans=ans*power(2LL,label[i].second)%mod;
			vis[i]=1;
		}
		//printf("%lld %d\n",ans,T);
	}
	ans=(ans-1)%mod;
	if (ans<0) ans+=mod;
	ans=(ans+p0)%mod;
	printf("%lld\n",ans);
	//fclose(stdin);
	//fclose(stdout);
	return 0;
}

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

int N,M;
int A[1000];

int main(){
	cin >> N >> M;
	int all = 0;
	for(int i = 0; i < N; i++){
		cin >> A[i];
		all += A[i];
	}

	int cnt = 0;
	for(int i = 0; i < N; i++){
		if(A[i] * 4 * M >= all)
			cnt++;
	}
	cout << (cnt >= M ? "Yes" : "No") << endl;

	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>

#define MAX 200001

void run(){
  char S[MAX];
  scanf(" %s", S);
  signed long long int len = strlen(S);
  char *a = S;
  long long int n = -1, cnt = 0, ans = 0;
  while(n!=len-1){
    while(a[++n] == 'B' && n != len-1) cnt++;
    if(a[n] == 'W') ans += cnt;
  }
  printf("%lld\n", ans);
}


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


Measured memory_bytes: 384
N = 5

def f(x)
  ((x + 9) / 10) * 10
end

def main(argv)
  a = [0] * N
  N.times{|i| a[i] = gets.chomp.to_i}
  
  m = 1e+9.to_i
  md = 10
  N.times do |i|
    d = a[i] % 10
    
    if d == 0 then
      next
    end
    
    if md > d then
      md = d
      m = a[i]
    end
  end
  
  s = a.map{|x| f(x)}.reduce(:+)
  
  s = s - f(m) + m
  
  puts s.to_s
end

if self.to_s == 'main' then
  main(ARGV)
end

Measured memory_bytes: 1788
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include <iomanip>
using namespace std;

int main(){
    long long int n,q,x=0,l,r;
    string s;
    cin>>n>>q>>s;
    vector<long long int>a(10000000);
    a[0]=0;
    for(int i=0;i<n-1;i++){
        if(s[i]=='A'&&s[i+1]=='C'){
            x++;
        }
        a[i+1]=x;
    }
    for(int i=0;i<q;i++){
       cin>>l>>r;
       cout<<a[r-1]-a[l-1]<<endl;
    }
    return 0;
}

Measured memory_bytes: 79232
#[allow(unused_imports)]
use proconio::{fastout, input, marker::*};

#[fastout]
fn main() {
    input! {
        n: usize, d: f64,
        xy: [(f64, f64); n],
    }
    let mut ans = 0;

    for i in 0..n {
        if (xy[i].0 * xy[i].0 + xy[i].1 * xy[i].1).sqrt() <= d {
            ans += 1;
        }
    }

    println!("{}", ans);
}


Measured memory_bytes: 7856
#include <stdio.h>


int main()
{
  int n,q,x,i,j;
  int num[10000];
  int cnt=0;

  scanf("%d",&n);
  for(i=0;i<n;i++) scanf("%d",&num[i]);
  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&x);
    for(j=0;j<n;j++){
      if(num[j]==x){
        cnt++;
        break;
      }
    }
  }

  printf("%d\n",cnt);

  return 0;
}



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

int main() {
    int a;
    cin >> a;
    if(a == 0){
        cout << 1 << endl;
    }else{
        cout << 0 << endl;
    }
}

Measured memory_bytes: 3592
maxn = 100005

def solve(n):
	if n<=9:
		return n
	q = [0 for i in range(maxn)]
	front = 1
	rear = 0
	for i in range(1,10):
		rear += 1
		q[rear] = i
	cnt = 9
	while 1:
		u = q[front]
		front += 1
		if u%10 != 0:
			t = u*10 + u%10 -1
			rear += 1
			q[rear] = t
			cnt += 1
			if cnt==n:
				return t
		t = u*10 + u%10
		rear += 1
		q[rear] = t
		cnt += 1
		if cnt==n:
			return t;
		if u%10 != 9:
			t = u*10 + u%10 + 1
			rear += 1
			q[rear] = t
			cnt += 1
			if cnt==n:
				return t

print(solve(int(input())))    

Measured memory_bytes: 7264
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int H,W;
  cin>>H>>W;
  vector<string> vec(H);
  
  for(int i=0;i<H;i++){
    cin>>vec.at(i);
  }
  for(int i=0;i<W+2;i++){
  cout<<"#";
  }
  cout<<endl;
  for (int i =0;i<H;i++){
  cout<<"#"<<vec.at(i)<<"#"<<endl;
  }
      for(int i=0;i<W+2;i++){
  cout<<"#";
  }
  cout<<endl;
  }


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

 
N,Q = map(int,input().split())
AB = [[int(x) for x in input().split()] for _ in range(N-1)]
PX = [[int(x) for x in input().split()] for _ in range(Q)]
 
graph = [[] for _ in range(N+1)]
for a,b in AB:
    graph[a].append(b)
    graph[b].append(a)
 
value = [0] * (N+1)
for p,x in PX:
    value[p] += x
 
def dfs(v,parent,add):
    value[v] += add
    for x in graph[v]:
        if x == parent:
            continue
        dfs(x,v,value[v])
 
dfs(1,0,0)
 
answer = ' '.join(map(str,value[1:]))
print(answer)

Measured memory_bytes: 285828
/*
　　　  ∧＿∧　やあ
　　 （´・ω・｀)　　　　　/　　　　　ようこそ、バーボンハウスへ。
　　 ／∇y:::::＼　　　 [￣]　　　　　このテキーラはサービスだから、まず飲んで落ち着いて欲しい。
　　 |:⊃:|:::::|　　　|──|
￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣|　うん、「また」なんだ。済まない。
￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣|￣　  仏の顔もって言うしね、謝って許してもらおうとも思っていない。
￣￣￣￣￣￣￣￣￣￣￣￣￣￣／|
　　　　∇　∇　∇　∇　　　／.／|　　　でも、この提出を見たとき、君は、きっと言葉では言い表せない
　　　　┴　┴　┴　┴　／ ／　  |　　　「ときめき」みたいなものを感じてくれたと思う。
￣￣￣￣￣￣￣￣￣￣|／　　  |　　　殺伐としたコンテストの中で、そういう気持ちを忘れないで欲しい
￣￣￣￣￣￣￣￣￣￣　　　　 |　　　そう思って、この提出を投げたんだ。
　　　(⊆⊇)　(⊆⊇)　(⊆⊇)　　|
　    ||　　 ||　　||　　|　　　 じゃあ、判定を聞こうか。
　　.／|＼　／|＼ ／|＼
*/

#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <array>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
#define fst first
#define snd second
#define ALL(obj) (obj).begin(),(obj).end()
#define debug(x) cerr << #x << " -> " << x << " (line:" << __LINE__ << ")" << '\n';
#define debugpair(x, y) cerr << "(" << #x << ", " << #y << ") -> (" << x << ", " << y << ") (line:" << __LINE__ << ")" << '\n';
typedef long long lint;
typedef priority_queue<int> p_que;
typedef priority_queue<int, vector<int>, greater<int>()> p_que_rev;
const int INF = INT_MAX;
const lint LINF = LLONG_MAX;
const int MOD = 1000000000 + 7;
const double EPS = 1e-9;
const double PI = acos(-1);
const int di[]{0, -1, 0, 1, -1, -1, 1, 1};
const int dj[]{1, 0, -1, 0, 1, -1, -1, 1};

int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    int a, b, c, d;
    scanf("%d %d %d %d", &a, &b, &c, &d);
    string ans;
    if(abs(c - a) <= d){
        ans = "Yes";
    }
    else if(abs(b - a) <= d && abs(c - b) <= d){
        ans = "Yes";
    }
    else {
        ans = "No";
    }
    cout << ans << "\n";
    return 0;
}

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

using namespace std;

#define int long long
#define MOD 1000000007

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()

#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second
template <typename T>
void print(T x)
{
    std::cout << x << '\n';
}

//typedef long long ll;
#define TENNINE 1000000005
#define TENFIVE 100005
//#define int long long

int x, y, a, b, c;

signed main()
{
    cin >> x >> y >> a >> b >> c;
    vector<int> p(a), q(b), r(c);
    rep(i, a)
    {
        cin >> p[i];
    }
    rep(i, b)
    {
        cin >> q[i];
    }
    rep(i, c)
    {
        cin >> r[i];
    }

    sort(rall(p));
    sort(rall(q));
    sort(rall(r));

    deque<int> a2, b2;

    rep(i, x)
    {
        a2.pb(p[i]);
    }

    rep(i, y)
    {
        b2.pb(q[i]);
    }

    int k = 0;

    while (1)
    {
        int ta = a2.back();
        int tb = b2.back();
        if (ta <= tb)
        {
            if (ta < r[k])
            {
                a2.push_front(r[k]);
                a2.pop_back();
                k++;
            }
            else
            {
                break;
            }
        }
        else
        {
            if (tb < r[k])
            {
                b2.push_front(r[k]);
                b2.pop_back();
                k++;
            }
            else
            {
                break;
            }
        }
    }

    int ans = 0;

    for (auto temp : a2)
    {
        ans += temp;
    }
    for (auto temp : b2)
    {
        ans += temp;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 4096
N,Q = gets.split.map(&:to_i)
S = gets.chomp
lr = Q.times.map { gets.chomp.split.map(&:to_i) }

A = Array.new(N)
A[0] = 0
(1...N).each do |i|
  if S[i-1,2] == 'AC'
    A[i] = A[i-1]+1
  else
    A[i] = A[i-1]
  end
end

Q.times do |j|
  ans = A[lr[j][1]-1] - A[lr[j][0]-1]
  puts ans
end

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

int main()
{
	int n,ans=0,x=0;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		int ch;
		cin>>ch;
		if(ch>=x)
		{
			ans++;
			x=ch;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  ll N, K; cin >> N >> K;
  vector<ll> P(N), C(N);
  for (auto& x: P) cin >> x, x--;
  for (auto& x: C) cin >> x;
  ll res = -1e18;
  for (int i = 0; i < N; i++) {
    vector<ll> sum;
    ll t = 0;
    int idx = i;
    do {
      t += C[idx];
      sum.push_back(t);
      idx = P[idx];
    } while (idx - i);
    for (int j = 0; j < min<int>(K, sum.size()); j++) res = max(res, sum[j]);
    ll sz = sum.size();
    for (int j = 0; j < sz; j++) {
      if (j < K % sz) {
        res = max(res, K / sz * sum.back() + sum[j]);
      } else {
        int cnt = K / sz - 1;
        if (cnt < 0) break;
        res = max(res, cnt * sum.back() + sum[j]);
      }
    }
  }
  cout << res << endl;
}


Measured memory_bytes: 3804
# coding: utf-8
import time
import re
import math
import fractions

def main():
    A,B,C,D=map(int,input().split())
    ccount=B//C-(A-1)//C
    dcount=B//D-(A-1)//D
    CD=C*D//fractions.gcd(C,D)
    cdcount=B//CD-(A-1)//CD
    N=B-A+1
    print(N-(ccount+dcount-(cdcount)))
start=time.time()
main()
#print("処理速度 {}sec".format(time.time()-start))
#"YNeos"[True::2]
#A=list(map(int,input().split()))
#A,B,C=map(int,input().split())
#n=int(input())
# global n,A,s,memo,mx,mn,L,B



Measured memory_bytes: 5064
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <cassert>

using namespace std;

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

    int64_t x;
    cin >> x;

    int64_t sum = 0;

    for (int i = 1; i <= x; i++) {
        sum += i;
        if (sum >= x) {
            cout << i << endl;
            return 0;
        }
    }

    return 0;
}



Measured memory_bytes: 256
#include <iostream>

int main(){
    int K, cont = 0, pr = 0;

    std::cin >> K;

    for(int i = 1;i<K+1;i++){
        if(i%2 == 0){
            pr++;
        }else{
            cont++;
        }
    }

    std::cout << pr*cont <<std::endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    
    string s, t;
    cin >> s >> t;
    sort(s.begin(),s.end());
    sort(t.rbegin(),t.rend());
    if(s<t) cout<< "Yes" <<endl;
    else cout<< "No" <<endl;
    
}

Measured memory_bytes: 256
/*author - Aryan Mittal*/
#include<bits/stdc++.h>
using namespace std;

#pragma GCC push_options
#pragma GCC optimize ("unroll-loops")

#define watch(x) cout << (#x) << " is " << (x) << "\n"
#define watch2(x,y) cout <<(#x)<<" is "<<(x)<<" and "<<(#y)<<" is "<<(y)<<"\n"

#define pow2(x) ((x)*(x))
#define ll long long
#define ld long double
#define eb emplace_back
#define pb push_back
#define pf push_front

#define mod 1000000007
#define clock (clock() * 1000.0 / CLOCKS_PER_SEC)

#define mp make_pair
#define ff first
#define ss second
#define null NULL

#define all(c) (c).begin(),(c).end()
#define nl "\n"

typedef vector<ll> vl;
typedef vector< vl > vvl;
typedef pair< ll,ll> pll;
typedef map< ll,ll> mll;

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

    ll n,m;
    cin>>n>>m;

    ll a[m];
    ll sum=0;
    for(ll i=0;i<m;i++){
        cin>>a[i];
        sum += a[i];
    }

    if(sum>n){
        cout<<"-1"<<"\n";
    }else{
        cout<<n-sum<<"\n";
    }
    
    return 0;
}

Measured memory_bytes: 3696
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <cstdio>
#include <string>
#include <cmath>
#include <queue>
#include <tuple>
#include <set>
#include <assert.h>
#include <sstream>
#include <string>
//#include <bits/stdc++.h>
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i,i0,n) for(int (i)=(i0);(i)<(n);(i)++)
#define FORR(i,i0,n) for(int (i)=(n)-1; (i)>=(i0);(i)--)
#define SORT(x) sort(x.begin(),x.end())
#define SORTR(x) sort(x.begin(),x.end(),greater <>())
#define rn return
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
using namespace std;
using ll = long long;
typedef std::pair<int,int> P;
 #include <boost/multiprecision/cpp_int.hpp>

using bint = boost::multiprecision::cpp_int;
 
 


int main(){
    bint n;
    cin >> n;
    if (n%2 == 1) {cout << 0; rn 0;}
    bint ans = 0;
    int power = 1;
    while((bint)pow(5,power) <= n){
        ans += (n/(bint)pow(5,power))/2;
        power++;
    }
    cout << ans;
}






Measured memory_bytes: 256