akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>

using namespace std;

//#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ;
#endif

#define equals(a,b) (fabs((a)-(b)) < EPS)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

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; }

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

template <typename T>
void print_array(const T &ary, int size){
    REP(i,size){
        cout << ary[i] << " ";
    }
    cout << endl;
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;
const double EPS = (1e-10);

LL N,M,V,P;
bool check(VL& A, int mid){
    //VL B = A;
    LL now = A[mid] + M;
    dump(now)
    LL c = max(0LL,V-(P-1)-mid-1);
    dump(c)

    if(c == 0){
        if(A[N-P] <= now){
            return true;
        }else{
            return false;
        }
    }else{
        LL rem = c * M;
        for(int i = mid+1; i <= N-P; i++){
            rem -= min(max(now-A[i],0LL),M);
        }
        if(rem <= 0){
            if(A[N-P] <= now) return true;
            else return false;
        }else{
            return false;
        }
    }
}

signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(12);

    cin >> N >> M >> V >> P;
    VL A(N);
    REP(i,N) cin >> A[i];

    sort(A.begin(),A.end());
    //REP(i,N){
    //    cout << A[i] << " ";
    //}
    //cout << endl;

    int ng = -1;
    int ok = N-1;
    while(abs(ok-ng) > 1){
        int mid = (ok+ng) / 2;
        if(mid >= N-P){
            ok = mid;
            continue;
        }
        dump(mid)
        if(check(A,mid)){
            ok = mid;
        }else{
            ng = mid;
        }
        dump(ok)
        dump(ng)
    }
    cout << N - ok << endl;


}


Measured memory_bytes: 1024
using System;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');

            int x = int.Parse(input[0]);
            int y = int.Parse(input[1]);

            bool isMatch = false;

            for (int i = 0; i <= x; i++)
            {
                int bird = i;
                int turtle = x - i;
                
                if ((bird * 2) + (turtle * 4) == y)
                {
                    isMatch = true;
                }
            }

            string ans = isMatch ? "Yes" : "No";
            Console.WriteLine(ans);

        }
    }
    
}

Measured memory_bytes: 27300
n = int(input())
s = list(input())

ans = s.count('R') * s.count('G') * s.count('B')

for i in range(n):
    for j in range(i + 1, n):
        k = 2 * j - i

        if k >= n:
            continue

        if s[i] != s[j] and s[j] != s[k] and s[k] != s[i]:
            ans -= 1

print(ans)


Measured memory_bytes: 9136
#include <cstdio>
#include <array>
#define repeat(i,n) for (int i = 0; (i) < int(n); ++(i))
#define repeat_from(i,m,n) for (int i = (m); (i) < int(n); ++(i))
#define repeat_reverse(i,n) for (int i = (n)-1; (i) >= 0; --(i))
using namespace std;

constexpr int n = 8;
bool is_on_field(int y, int x) { return 0 <= y and y < n and 0 <= x and x < n; }
int main() {
    // input
    array<array<char, n>, n> f;
    repeat (y, n) repeat (x, n) scanf(" %c", &f[y][x]);
    // solve
    auto use = [](array<array<char, n>, n> f, int y, int x, char c) {
        int cnt = 0;
        repeat_from (dy, -1, +1+1) repeat_from (dx, -1, +1+1) if (dy != 0 or dx != 0) {
            f[y][x] = c;
            for (int k = 1; ; ++ k) {
                int ny = y + k*dy;
                int nx = x + k*dx;
                if (not is_on_field(ny, nx)) break;
                if (f[ny][nx] == '.') break;
                if (f[ny][nx] == c) {
                    while (-- k) {
                        f[y + k*dy][x + k*dx] = c;
                        ++ cnt;
                    }
                    break;
                }
            }
        }
        return make_pair(f, cnt);
    };
    int pass = 0;
    for (int turn = 0; ; ++ turn) {
        char c = turn % 2 == 0 ? 'o' : 'x';
        int result_y = -1, result_x = -1;
        int result = 0;
        repeat (y, n) repeat (x, n) if (f[y][x] == '.') {
            int cnt = use(f, y, x, c).second;
            if (result < cnt or (result == cnt and turn % 2 == 1)) {
                result_y = y;
                result_x = x;
                result = cnt;
            }
        }
        if (not result) {
            pass += 1;
            if (pass >= 2) {
                break;
            }
        } else {
            pass = 0;
            f = use(f, result_y, result_x, c).first;
        }
    }
    // output
    repeat (y, n) {
        repeat (x, n) {
            printf("%c", f[y][x]);
        }
        printf("\n");
    }
    return 0;
}

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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = ((int)(n)-1); i >= 0; i--)
#define all(x) (x).begin(),(x).end()

using namespace std;
using ll = long long;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> P;
 
const int INF = 1e9;
//const ll INF = 1e18;
const double EPS = 1e-10;
const int MOD = 1e9+7;
const double PI = acos(-1.0);

class UnionFind{
private:
	vector<int> par; //�e
	vector<int> sizes; //�f�[�^�̐�

public:
	UnionFind(int n){ 
		par.resize(n);
		sizes.resize(n);
		for(int i = 0; i < n; i++){
			par[i] = i;
			sizes[i] = 1;
		}
	}
	//�؂̍������߂�
	int find(int x){
		if(par[x] == x) return x;
		else return par[x] = find(par[x]);
	}
	//x��y�̑�����W���𕹍�
	void unite(int x,int y){
		x = find(x); //x,y�͊e�f�[�^�̍��m�[�h�𓾂�
		y = find(y);
		if(x == y) return;
		//if (sizes[x] < sizes[y]) swap(x,y);
		par[y] = x; //x��y�̐e�ƂȂ�悤�ɘA������
		sizes[x] += sizes[y];
	}
	//x��y�������W���ɑ����邩�ۂ�
	bool same(int x, int y){
		return find(x) == find(y);
	}
	//x��������W���̃f�[�^��
	int size(int x){
		return sizes[find(x)];
	}
};

int main()
{
	IOS;
	int n,m;
	cin >> n >> m;
	vi a(m),b(m);
	rep(i,m){
		cin >> a[i] >> b[i];
		a[i]--,b[i]--;
	}
	UnionFind uni(n);
	vector<ll> ans(m);
	ans[m-1] = (ll)n*(n-1)/2;
	for(int i = m-1; i >= 1; i--){
		ans[i-1] = ans[i];
		if(!uni.same(a[i],b[i])){
			ans[i-1] -= (ll)uni.size(a[i])*uni.size(b[i]);
			uni.unite(a[i],b[i]);
		}
	}
	rep(i,m) cout << ans[i] << endl;
	return 0;
}

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

using namespace std;

#define ll long long
#define ull unsigned long long
#define ar array
#define sz(a) (int) a.size()
#define fi first
#define se second
#define all(s) s.begin(), s.end()
#define vi vector<int>
#define pb push_back
#define eb emplace_back
#define ii pair<int, int>
#define bit(x, y) ((x >> y) & 1)
#define lwb lower_bound
#define upb upper_bound

#define F_OR(i, a, b, s) for (int i = (a); ((s) > 0 ? i < (b) : i > (b)); i += (s))
#define F_OR1(e) F_OR(i, 0, e, 1)
#define F_OR2(i, e) F_OR(i, 0, e, 1)
#define F_OR3(i, b, e) F_OR(i, b, e, 1)
#define F_OR4(i, b, e, s) F_OR(i, b, e, s)
#define GET5(a, b, c, d, e, ...) e
#define F_ORC(...) GET5(__VA_ARGS__, F_OR4, F_OR3, F_OR2, F_OR1)
#define FOR(...) F_ORC(__VA_ARGS__)(__VA_ARGS__)

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

  int n;
  cin >> n;
  cout << (n - 1) / 2 << '\n';
}


Measured memory_bytes: 3588
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
#include<cstdio>
#include<cstdlib>
#include<unordered_map>
#include<unordered_set>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592
#define PI acos(-1.0);

const double EPS = 1e-10;

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;


int main(){
    int n,k; cin >> n >> k;
    vector<bool> ok(n,false);
    rep(i,k){
        int d; cin >> d;
        rep(j,d){
            int a; cin >> a;
            a--;
            ok[a] = true;
        }
    }
    int ans = 0;
    rep(i,n){
        if(!ok[i]) ans++;
    }
    cout << ans << endl;
}



Measured memory_bytes: 3628
#include <iostream>
#include <vector>
#include<algorithm>
#include<iomanip>
#include<queue>
using namespace std;
#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++)
typedef pair<int,int> pint;
typedef long long ll;
const int inf   = 1<<29;
const ll  longinf = 1LL<<60;
int dx[4]={1,0,-1,0}, dy[4]={0,1,0,-1};

int main(){
  int n;
  cin>>n;
  string s;
  cin>>s;
  int cnt=0;
  rep(i,n){
    if(s[i]=='(')
      cnt++;
    else{
      cnt--;
      if(cnt<0){
        cnt++;
        cout<<"(";
        }
      }
    }
  cout<<s;
  rep(i,cnt)
    cout<<")";
  cout<<endl;
  return 0;
  }

  

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


/*
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <ctype.h>
*/



using namespace std;

typedef pair<int , int > pii;
typedef pair<long , long> pll;
typedef pair<pii , int > piii;
typedef pair<pll , long > plll;
typedef vector<int> vi;
typedef vector<long> vl;
typedef vector <pii> vii;
typedef vector<pll> vll;
typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef unsigned long long int ulli;
typedef long long int lli;
typedef double d;
typedef float f;
typedef string s;
typedef char ch;
typedef pair<int,ll> pill;

#define loop(n) for(int i = 0; i < (n); i++)
#define lp(x , s , e) for(int x = (s); x < (e); x++)
#define lpe(x , s , e) for(int x = (s); x <= (e); x++)
#define readline(s) getline(cin,s)
#define NumofDigits(n) ((int)log10(n)+1)
#define CountofNumber(array,n,x)  (upper_bound(array, array+n, x)-lower_bound(array, array+n, x))
#define F first
#define S second
#define EPS 1e-7
#define modulo ll (1e9 + 7)
const long double PI = 3.141592653589793238L;
#define MP make_pair
#define PB push_back
#define all(a) a.begin(),a.end()
#define clr(x , val) memset((x) , (val) , sizeof(x))
#define endl '\n'

ll power(ll a, ll b)
{
    ll res = 1;
    for(int i = 0; i<b; i++)
       res *= a;

    return res;
}


int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int a , b , c , d;
    cin >> a >> b >> c >> d;
    while(true)
    {
    	c -= b;
    	if(c <= 0)
    	{
    		cout << "Yes" << endl;
    		return 0;
    	}
    	a -= d;
    	if(a <= 0)
		{
			cout << "No" << endl;
			return 0;
		}
    }
    return 0;
}


Measured memory_bytes: 3592
#include <iostream>

#include <cstring>

#include <string>
#include <vector>
#include <algorithm>

using namespace std;

#define SZ(a) int((a).size())
#define REP(i,n) for(int i=0,_n=(n);i<_n;++i)
#define FOR(i,a,b) for(int i=(a),_b=(b);i<=_b;++i)

typedef long long llong;
typedef vector<int> VI;
typedef vector<VI> VVI;

#define MAXN 100004
int N;
int A[MAXN];

bool solve() {
   int n1 = 0, n2 = 0, n4 = 0;
   REP(i, N) {
      int a = A[i];
   // fprintf(stderr, "%d: %d %d\n", a, a%4, a%2);
      if ((a % 4) == 0)
         n4++;
      else if ((a % 2) == 0)
         n2++;
      else
         n1++;
   }

   if (n1 == 0) {
      fprintf(stderr, "Case 1\n");
      return true;
   }

   if (N == 2) {
      fprintf(stderr, "Case 2\n");
      return n4 > 0;
   }

   if (N == 3)
      return n1 == 1 || n4 > 0;

   if (n4 >= n1)
      return true;

   if (n1 == n4+1 && n2 == 0)
      return true;

   return false;
}

int main(int argc, char* argv[]) {
   ios_base::sync_with_stdio(false); 
   cin.tie(NULL);

   cin >> N;
   REP(i, N)
      cin >> A[i];

   cout << (solve() ? "Yes" : "No") << endl;

   return 0;
}


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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define repr(i,n) for(int i=(int)(n-1);i>=0;i--)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout << #x" = " << x << endl
#define print(x) cout << x << endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<int, P> PIP;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;
typedef set<int> S;

#define INF INT_MAX/3
#define MAX_N 1000000001


int main(){
  cin.sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  string a[n], b[m];

  rep(i, n) {
    cin >> a[i];
  }
  rep(i, m) {
    cin >> b[i];
  }

  bool ok = true;
  if(n > m){
    rep(i, n - m) {
      rep(j, n - m) {
        ok = true;
        rep(k, m) {
          rep(l, m) {
            if(b[k][l] != a[i + k][j + l]) {
              ok = false;
              break;
            }
          }
          if(!ok) break;
        }
        if(ok) break;
      }
      if(ok) break;
    }
  }else {
    rep(i, n) {
      rep(j, n) {
        if(a[i][j]!=b[i][j]) {
          ok = false;
          break;
        }
      }
    }
  }

  print(((ok) ? "Yes" : "No"));

  return 0;
}

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

int gcd(int a, int b) {
  if(a>b) {
    if(a%b == 0) {
      return b;
    } else {
      return gcd(b, a%b);
    }
  } else {
    if(b%a==0) {
      return a;
    } else {
      return gcd(a, b%a);
    }
  }
}

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

  int GCD = A[0];

  for(int i=1;i<N;i++) {
    GCD = gcd(GCD, A[i]);
  }

  cout << GCD << endl;
  
  return 0;
}

Measured memory_bytes: 640
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ViewPatterns #-}
{-# LANGUAGE TemplateHaskell #-}
--atcoder {-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NoImplicitPrelude #-}

import Prelude
import System.IO
import System.Environment
import System.Exit
import qualified Data.Char as Char
import qualified Data.Text as T
import qualified Data.Text.IO as TIO
import qualified Control.Monad
--atcoder import qualified Data.Semigroup
import qualified Data.Map as Map
import qualified Data.Set as Set

readInt :: IO Int
--readInt = read <$> getLine
readInt = getLine >>= (return . read)

readInts :: IO [Int]
readInts = map (read :: String -> Int) <$> words <$> getLine

solve :: Int -> Int -> Int -> Int
solve n a b = min (a*n) b

main :: IO ()
main = do
    nab <- getLine >>= (return . words) >>= (return . map (read :: String -> Int))
    let n = nab !! 0
    let a = nab !! 1
    let b = nab !! 2
    let ret = solve n a b
    print ret

Measured memory_bytes: 508
#include<bits/stdc++.h>
using namespace std; 
 
long double a,b,h,m,c,d1,d2;
int main()
{
	cin>>a>>b>>h>>m;
	d1=(long double)m/360.0+(long double)h/6;
	d2=(long double)m/30;
	d2=(d1-d2);
	c=sqrt(2*a*b)*sqrt((a*a+b*b)/(2*a*b)-cos(d2*3.14159265358979323846264338327950L));
	cout<<fixed<<setprecision(20)<<c; 
}


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

const ll MOD = 1000000007;

int main(void) {
  ll N, K;
  cin >> N >> K;
  vector<ll> A(N);
  REP(i, 0, N) cin >> A[i];

  vector<vector<ll>> dp(N + 1, vector<ll>(K + 1, 0));
  dp[0][K] = 1;

  REP(i, 0, N) {
    vector<ll> sum(K + 2);
    REP(j, 0, K + 1) {
      sum[j + 1] = (sum[j] + dp[i][j]) % MOD;
    }

    REP(j, 0, K + 1) {
      ll t = min(j + A[i], K) + 1;
      dp[i + 1][j] += (sum[t] - sum[j] + MOD) % MOD;
      dp[i + 1][j] %= MOD;
    }
  }

  cout << dp[N][0] << endl;
}

Measured memory_bytes: 80256
#include<iostream>
#include<cstdio>
#include<algorithm>
#define nMAX 10000
#define aMAX 1000000
using namespace std;

int main(void)
{
  int n,a[nMAX];
  long maxv,minv,sum;

  do{
    cin >> n;
  }while(n <= 0 || n > nMAX);

  while(1){
    int flag = 1;
    for(int i = 0;i < n;i++){
      cin >> a[i];
      if(a[i] > aMAX || a[i] < -1 * aMAX) flag = 0;
    }
    if( flag == 1) break;
  }
  
  maxv = -1 * aMAX;
  minv = a[0];

  for(int i = 0;i < n;i++){
    maxv = max(maxv,(long)a[i]);
    minv = min(minv,(long)a[i]);
    sum += a[i];
  }

  cout << minv << " " << maxv << " " << sum << endl;
  
  return 0;
} 
    

Measured memory_bytes: 1204
#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 ALL(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;

int main() {
  int N;
  cin >> N;
  int A1[N], A2[N];

  REP(i, N) cin >> A1[i];
  REP(i, N) cin >> A2[i];

  int ans = 0;
  int sum_a1 = 0;
  REP(i, N) {
    sum_a1 += A1[i];
    int s = sum_a1;
    FOR(j, i, N - 1) s += A2[j];
    ans = max(ans, s);
  }

  cout << ans << endl;

  return 0;
}


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

#include <iostream>
#include <stdio.h>
#include <array>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <list>
#include <algorithm>
#include <map>
#include <cmath>

using namespace std;

typedef double db;
typedef long long ll;
typedef pair<int, int> PII;

int a, b;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,a,b) for(i=(a);i<=(b);i++)
#define REP(i,n) FOR(i,0,n)
#define REPP(i,n) FORR(i,0,n)
#define MAX(a,b) a>b? a:b
#define MIN(a,b) a>b? b:a


const int MOD = 1e9 + 7;
const ll INF=1e10;
const db PI = acos(-1.0);
const db EPS = 1e-10;


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

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


ll MAXX(vector<ll> a,ll k) {
	ll max = 0;
	REP(i, k) {
		if (a[i] >= max) max = a[i];
	}
	return max;
}

ll MINN(vector<ll> a,ll k) {
	ll min = 1e10;
	REP(i, k) {
		if (a[i] <= min)min = a[i];
	}
	return min;
}

ll SUM(vector<ll> a, ll k) {
	ll sum = 0;
	REP(i, k) {
		sum += a[i];
	}
	return sum;
}

db AVE(vector<ll> a, ll k) {
	db ave = SUM(a,k)/(db)k;
	return ave;
}


int main() {
	int n;
  	cin>>n;
	vector<int> v(n);
  	REP(i,n){
    	cin>>v[i];
    }
  	sort(v.begin(),v.end());
  	cout<<v[n/2]-v[n/2-1];
	return 0;
}

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

int main()
{
  long h, w;
  cin >> h >> w;
  long q = h / 2;
  long r = h % 2;
  long ans = 0;
  if (h == 1 || w == 1) cout << 1 << endl;
  else
  {
    ans = q * (((w + 1) / 2) + (w / 2));
    if (r) ans += (w + 1) / 2;
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>

unsigned long long gcd(unsigned long long a, unsigned long long b)
{
    if (b == 0)
    {
        return a;
    }
    return gcd(b, a % b);
}

unsigned long long dd(unsigned long long m, unsigned long long c, unsigned long long d)
{
    return m - ((m / c) + (m / d) - m / (c * d / gcd(c, d)));
}

int main()
{
    unsigned long long a, b, c, d; std::cin >> a >> b >> c >> d;
    std::cout << (dd(b, c, d) - dd(a - 1, c, d)) << std::endl;
    return 0;
}


Measured memory_bytes: 256
package main

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

func main() {
	rd := bufio.NewReader(os.Stdin)
	for {
		s, err := rd.ReadString('\n')
		if err == io.EOF {
			return
		}
		arr := strings.Split(strings.TrimSpace(s), " ")
		a, _ := strconv.Atoi(arr[0])
		b, _ := strconv.Atoi(arr[1])
		for i := 0; i < a; i++ {
			for j := 0; j < b; j++ {
				switch {
				case 0 < i && i < a-1 &&
					0 < j && j < b-1:
					fmt.Print(".")
				default:
					fmt.Print("#")
				}
			}
			fmt.Println()
		}
		if a == 0 && b == 0 {
			return
		}
		fmt.Println()
	}
}



Measured memory_bytes: 1108
#include <bits/stdc++.h>
#define int long
#define ll long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define IOS cin.tie(0); ios::sync_with_stdio(false)
const int INF = 1e9;
using namespace std;

main() {
    IOS;
    int N; cin >> N;
    int A[N];
    rep(i,N) {cin >> A[i]; A[i]--;}
    int ans=0;
    rep(i,N){
        if(A[A[i]]==i) ans++;
    }
    cout << ans/2 << endl;
}

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

vector<int> to[200005];
vector<int> ans;

void dfs(int v, int p=-1) {
  for (int u : to[v]) {
    if (u == p) continue;
    ans[u] += ans[v];
    dfs(u,v);
  }
}

int main() {
  int n, q;
  cin >> n >> q;
  rep(i,n-1) {
    int a, b;
    cin >> a >> b;
    --a; --b;
    to[a].push_back(b);
    to[b].push_back(a);
  }
  ans.resize(n);
  rep(i,q) {
    int p, x;
    cin >> p >> x;
    --p;
    ans[p] += x;
  }
  dfs(0);
  rep(i,n) {
    cout << ans[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 23424
#include <iostream>
#include<string>
using namespace std;
int main(void){
    string S;
    cin>>S;
    int T;
    T=S.size();
    int A,B;
    for (int i=0; i<T; i++) {
        if(S[T-i-1]=='A'){
            A=T-i-1;
            
        }
        if(S[i]=='Z'){
            B=i;
            
        }
    }   
    cout<<B-A+1<<endl;
    
    
    return 0;
    
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
 
int main() {

  int m;
  cin >> m;
  
  int n;
 
  if(m <= 599)  n = 8;
    else if(m >= 600 && m <= 799) n = 7;
  else if(m >= 800 && m <= 999) n = 6;
  else if(m >= 1000 && m <= 1199) n = 5;
  else if(m >= 1200 && m <= 1399) n = 4;
  else if(m >= 1400 && m <= 1599) n = 3;
  else if(m >= 1600 && m <= 1799) n = 2;
  else n = 1;
  
  cout << n << endl;
}

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

#define ld long double
#define ll long long
#define ull unsigned long long
#define F first
#define S second
#define nl '\n'
#define pii pair <ll, ll>
#define pb push_back
#define mp make_pair
#define pi 3.14159265358979323846264
#define y1 abacaba
#define fn "abc"
#define sz(a) (int)(a).size()
#define all(a) (a).begin(), (a).end()
#define pcnt(i) __builtin_popcount(i)
#define lcm(a,b) (a * b) / __gcd(a, b)
#define chill_wave ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pressF freopen("lepus.in", "r", stdin); freopen("lepus.out", "w", stdout);

using namespace std;

const long long MXN = 1e6 + 3;
const long long MAXN = 2e3 + 7;
const long long MOD = 1e9;
const long long INF = 1e18;
const long long MAXLOG = 20;

inline void f_math(bool ok = 0) { chill_wave if(ok) { pressF; } }

//int dx[]= {1,0,-1,0}; int dy[]= {0,1,0,-1}; //4 Direction
//int dx[]={1,1,0,-1,-1,-1,0,1}; int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction
//int dx[]={2,1,-1,-2,-2,-1,1,2}; int dy[]={1,2,2,1,-1,-2,-2,-1};//Knight Direction
//int dx[]={-1,-1,+0,+1,+1,+0}; int dy[]={-1,+1,+2,+1,-1,-2}; //Hexagonal Direction

ll n, dp1[MXN], dp2[MXN], dp3[MXN];

int main() {

    f_math();

    cin >> n;
    for(int i = 1; i <= n; i++) {
        ll a, b, c;
        cin >> a >> b >> c;
        dp1[i] = max(dp2[i - 1], dp3[i - 1]) + a;
        dp2[i] = max(dp1[i - 1], dp3[i - 1]) + b;
        dp3[i] = max(dp1[i - 1], dp2[i - 1]) + c;
    }
    cout << max({dp1[n], dp2[n], dp3[n]});
    return 0;
}


Measured memory_bytes: 9216
A,B,K=map(int,input().split())
List_A = list(map(int, input().split()))
List_B = list(map(int, input().split()))
SumListA=[]
SumListA.append(0)
SumListB=[]
SumListB.append(0)
res =0
a=0
for i in range(A):
  SumListA.append(SumListA[i]+List_A[i])
for i in range(B):
  SumListB.append(SumListB[i]+List_B[i])

j=B
for i in range(A+1):
  if SumListA[i] > K:
    break
  while K-SumListA[i] < SumListB[j]:
    j += -1
  res = max(i+j,res)
print(res)

Measured memory_bytes: 47540
import math

def kochCurve(p1, p2, n):
    if n == 0:
        print "%5f %5f" % (p2[0], p2[1])
        return

    s = ((p2[0] - p1[0]) / 3.0 + p1[0], (p2[1] - p1[1]) / 3.0 + p1[1])
    t = ((p2[0] - p1[0]) * 2.0 / 3 + p1[0], (p2[1] - p1[1]) * 2.0 / 3 + p1[1])
    u = (math.cos(math.pi/3)*(t[0]-s[0])-math.sin(math.pi/3)*(t[1]-s[1])+s[0], math.sin(math.pi/3)*(t[0]-s[0])+math.cos(math.pi/3)*(t[1]-s[1])+s[1])

    kochCurve(p1, s, n - 1)
    kochCurve(s, u, n - 1)
    kochCurve(u, t, n - 1)
    kochCurve(t, p2, n - 1)

if __name__ == "__main__":
    n = int(input())
    p1 = (0, 0)
    p2 = (100, 0)
    print "%5f %5f" % (p1[0], p1[1])
    kochCurve(p1, p2, n)

Measured memory_bytes: 6608
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define print(A,x,n) rep(i,0,n){cout<<(i ? " ":"")<<A[i]x;}cout<<endl;
#define pprint(A,y,m,n) rep(j,0,m){print(A[j],y,n);}
const long mod=1e9+7;
const int size=4001;
const int inf=1e9;
int N,K;
int cnt[2][size][size] = {};
int calc(int a,int b,int c,int d,int i){
	return cnt[i][c][d] - cnt[i][a][d] - cnt[i][c][b] + cnt[i][a][b];
}
int main(){
	cin>>N>>K;
	int x,y;char c;
	rep(i,0,N){
		cin>>x>>y>>c;
		(x %= 2*K)++; (y %= 2*K)++;
		if(c == 'B'){
            cnt[0][x][y]++;
            cnt[0][x+2*K][y]++;
            cnt[0][x][y+2*K]++;
            cnt[0][x+2*K][y+2*K]++;
        }else{
            cnt[1][x][y]++;
            cnt[1][x+2*K][y]++;
            cnt[1][x][y+2*K]++;
            cnt[1][x+2*K][y+2*K]++;
        }
	}
	rep(i,1,4*K+1)rep(j,1,4*K+1){
		cnt[0][i][j] += cnt[0][i-1][j] + cnt[0][i][j-1] - cnt[0][i-1][j-1];
		cnt[1][i][j] += cnt[1][i-1][j] + cnt[1][i][j-1] - cnt[1][i-1][j-1];
	}
	int ans = 0; int res;
	rep(a,0,2*K)rep(b,0,2*K){
		res = 0;
		res += calc(a,b,a+K,b+K,0) + calc(a+K,b,a+2*K,b+K,1);
		res += calc(a,b+K,a+K,b+2*K,1) + calc(a+K,b+K,a+2*K,b+2*K,0);
		ans = max(ans , res);
	}cout<<ans<<endl;//pprint(cnt[0],,4*K+1,4*K+1);
}

Measured memory_bytes: 125312
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define lowbit(a) ((a) & -(a))
#define clean(a, b) memset(a, b, sizeof(a))
const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const int maxn = 1e7 + 9;
 
int _;

//========================================================================
int vis[maxn];
int main()
{
    ll n;
    ll ans=0;
    scanf("%lld",&n);
    for(int i=1;i<=n;i++)
    {
        for(int j=i;j<=n;j+=i) vis[j]++;
    }
    for(ll i=1;i<=n;i++)
    {
        ans+=i*vis[i];
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 42884
/// awoooooo

# include <bits/stdc++.h>
# define sz(x) (int)((x).size())

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair < int, int > pii;
typedef complex < ld > point;

const int N = (int)2e5 + 5;
const int inf = (int)1e9 + 7;

int n, m;
string a, b;
map < int, char > c;

int main(){
  cin >> n >> m >> a >> b;
  ll l = n * 1ll * m / __gcd(n, m);
  for(ll i = 1, e = 0; e < n; i += l / n, ++e){
    c[i] = a[e];
  }
  for(ll i = 1, e = 0; e < m; i += l / m, ++e){
    if(c.count(i) && c[i] != b[e]){
      cout << "-1\n";
      return 0;
    }
  }
  cout << l << "\n";
  return 0;
}


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

#define MAX 10000
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define repo(i,o,n) for(int i=o;i<n;i++)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end());
#define vdelete(v) (v).erase(unique(all(v)), (v).end());
#define pb(n) push_back(n);

int n,ans,mx;

main() {
    cin >> n;
    rep(i,n) {
        int hoge;
        cin >> hoge;
        ans += hoge;
        mx = max(mx,hoge);
    }
    cout << ans-mx/2 << endl;

}

Measured memory_bytes: 256
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define mod 1000000007
#define fi first
#define se second
#define pii pair<int,int>
#define int long long
#define endl '\n'
#define pll pair<long long,long long>
#define LONGLONG_MAX 100000000000000
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
long long power(long long a,long long b){
    long long ans=1;
    while(b>0){
        if(b&1){ans=(ans*a)%mod;}
                a=(a*a)%mod;
                b>>=1;
        }
    return ans;
        
}
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    srand(time(0));
    int a,v;
    cin>>a>>v;
    int b,w;
    cin>>b>>w;
    int t;
    cin>>t;
    if(a==b){
    	cout<<"YES";
    }
    else if(w>=v){
    	cout<<"NO";
    }
    else if(t>=((abs(b-a)+v-w-1)/(v-w))){
    	cout<<"YES";
    }
    else cout<<"NO";
    return 0;
}


Measured memory_bytes: 3652
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     @hamayanhamayan0
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/














ll X, K, D;
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> X >> K >> D;
	X = abs(X);

	ll need = X / D;
	if (K < need) {
		cout << X - D * K << endl;
		return;
	}

	K -= need;
	X -= D * need;

	if (K % 2 == 1) X -= D;
	cout << abs(X) << endl;
}







Measured memory_bytes: 3640
#include <stdio.h>
#define N 100

int min(int x, int y)
{
  if(x < y) return x;
  else if(x > y) return y;
}


int main()
{
  int i,j,k,l,v,n;
  int A[N+1],B[N+1][N+1];

  scanf("%d",&n);

  for(i=1; i<=n; i++)
    scanf("%d%d",&A[i-1],&A[i]);

  for(i=1; i<=n; i++)
    B[i][i] = 0;


  for(k=2; k<=n; k++){
    for(i=0; i<=n-k+1; i++){
      j = i+k-1;
      B[i][j] = (1<<21);
      for(l=i; l<=j-1; l++){
        B[i][j] = min(B[i][j], B[i][l]+B[l+1][j]+A[i-1]*A[l]*A[j]);
        v = B[i][l]+B[l+1][j]+A[i-1]*A[l]*A[j];
      }
    }
  }

  printf("%d\n",B[1][n]);

  return 0;
}


Measured memory_bytes: 2108
n, x = map(int, input().split())

BP = [1]
P = [1]

for i in range(n):
  BP.append(BP[i]*2+3)
  P.append(P[i]*2+1)
  
def check_P_num(n, x):
  
  if n==0:
    return 1
  
  if x==BP[n]:
    return(P[n])
  elif x==1:
    return(0)
  elif x == BP[n-1]+2:
    return(P[n-1]+1)
  elif x <= BP[n-1]+1:
    return(check_P_num(n-1, x-1))
  else:
    return(check_P_num(n-1, x-BP[n-1]-2)+P[n-1]+1)
  
  
print(check_P_num(n, x))

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

const int INF = 1e9;
int main(){
    string S;
    cin >> S;
    int L = S.length();
    int ans = INF;
    for(int i = 0; i < L-2; i++){
        string sub = S.substr(i,3);
        int tmp = stoi(sub);
        ans = min(ans,abs(753-tmp));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
g = [[] for i in range(n+1)]
d = {}
l = [-1] * (n-1)
max_idx = 0
for i in range(n-1):
  u,v = map(int, input().split())
  d[(u,v)] = i
  d[(v,u)] = i
  g[u].append((u,v))
  g[v].append((v,u))
  if len(g[max_idx]) < len(g[u]):
    max_idx = u
  if len(g[max_idx]) < len(g[v]):
    max_idx = v
m = len(g[max_idx])
stack = []
count = m
while len(g[1]) > 0:
  u2, v2 = g[1].pop()
  l[d[(u2, v2)]] = count
  count -= 1
  stack.append((u2, v2))

while len(stack) > 0:
  u, v = stack.pop()
  #print(u,v)
  if len(g[v]) > 0:
    count = m
    while len(g[v]) > 0:
      u2, v2 = g[v].pop()
      if count == l[d[(u, v)]]:
        count -= 1
      if l[d[(u2, v2)]] == -1:
        l[d[(u2, v2)]] = count
        count -= 1
        stack.append((u2, v2))
print(m)
for i in range(n-1):
  print(l[i])
  


Measured memory_bytes: 64312
#include <stdio.h>

using namespace std;

int main(){
	int a,b;
	while(true){
		scanf("%d %d",&a,&b);
		if(a == 0 && b == 0) break;
		if(a > b) printf("%d %d\n",b,a);
		else{
			printf("%d %d\n",a,b);
		}
	}
}


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

using namespace std;

long long a[105][100005], m[105], p[105], n, w;

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

    for(int i = 1; i <= n; ++i){
        cin >> m[i] >> p[i];
    }

    for(int j = 1; j <= w; ++j){
        for(int i = 1; i <= n; ++i){
            a[i][j] = a[i - 1][j];
            if(j - m[i] >= 0) a[i][j] = max(a[i][j], a[i - 1][j - m[i]] + p[i]);
        }
    }

    cout << a[n][w];

    return 0;
}


Measured memory_bytes: 79360
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() {
	ios::sync_with_stdio(false); cin.tie(0);
	string s;
	cin >> s;
	stack<char> st;
	for (char c : s) {
		if (st.empty()) {
			st.push(c);
			continue;
		}
		if (st.top() == 'S' && c == 'T') st.pop();
		else st.push(c);
	}
	cout << (int) st.size() << endl;
	return 0;	
}

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

using namespace std;

int a[10];
int l[10],r[10],bl[10],br[10];
int main()
{
	int T;cin >> T;
	while(T--)
	{
		for(int i = 0;i < 10;++i)
			cin >> a[i];
		int flag = 0;
		for(int op = 0;op < 1 << 10;++op)
		{
			int lcnt = 0,rcnt = 0;
			for(int i = 0;i < 10;++i)
			{
				if(op >> i & 1)
					l[lcnt++] = a[i];
				else
					r[rcnt++] = a[i];
			}
			bool ok = 1;
			for(int i = 1;i < lcnt && ok;++i)
			{
				if(l[i] < l[i-1])
					ok = 0;
			}
			for(int i = 1;i < rcnt && ok;++i)
				if(r[i] < r[i-1])
					ok = 0;
			if(ok)
			{
				flag = 1;
				cout << "YES\n";
				break;
			}
		}
		if(!flag)
			cout << "NO\n";
	}
	return 0;
}


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

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

    int num_N = 0;
    int num_S = 0;
    int num_W = 0;
    int num_E = 0;

    for(int i=0; i<S.size(); i++){
        if(S[i]=='N'){num_N++;}
        if(S[i]=='S'){num_S++;}
        if(S[i]=='W'){num_W++;}
        if(S[i]=='E'){num_E++;}
    }

    if(num_N == num_S || num_N*num_S > 0){
        if(num_W == num_E || num_W*num_E > 0){
            cout << "Yes" << endl;
            return 0;
        }
    }

    cout << "No" << endl;
    return 0;

}

Measured memory_bytes: 3616
void main() {
  auto a = ri, b = ri, c = ri, d = ri, e = ri, k = ri;
  if(e - a > k) writeln(":(");
  else writeln("Yay!");
}
// ===================================

import std.stdio;
import std.string;
import std.functional;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}


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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define IN(a, b, x) (a<=x&&x<b)
#define MP make_pair
#define PB push_back
#define INF (1LL<<30)
#define LLINF (1LL<<60)
#define PI 3.14159265359
#define EPS 1e-12
//#define int ll

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }

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

// ????????????????????????????????¶?????°??????????????????
const int MAX_N = 1<<20;
struct RSQRAQ {
  int n;
  ll dat[2*MAX_N-1], lazy[2*MAX_N-1];

  RSQRAQ(){}
  RSQRAQ(int n_) {init(n_);}
  void init(int n_) {
    n = 1; while(n < n_) n *= 2;
    REP(i, 2*n-1) dat[i] = lazy[i] = 0;
  }

  void eval(int k, int l, int r) {
    if(lazy[k]) {
      dat[k] += lazy[k];
      if(r-l>1) {
        lazy[2*k+1] += lazy[k] / 2;
        lazy[2*k+2] += lazy[k] / 2;
      }
      lazy[k] = 0;
    }
  }

  void update(int a, int b, ll x) {update(a, b, x, 0, 0, n);}
  void update(int a, int b, ll x, int k, int l, int r) {
    eval(k, l, r);
    if(b <= l || r <= a) return;
    if(a <= l && r <= b) {
      lazy[k] += (r-l)*x;
      eval(k, l, r);
    } else {
      update(a, b, x, 2*k+1, l, (l+r)/2);
      update(a, b, x, 2*k+2, (l+r)/2, r);
      dat[k] = dat[2*k+1] + dat[2*k+2];
    }
  }

  ll query(int a, int b) {return query(a, b, 0, 0, n);}
  ll query(int a, int b, int k, int l, int r) {
    eval(k, l, r);
    if(b <= l || r <= a) return 0;
    if(a <= l && r <= b) return dat[k];
    ll vl = query(a, b, 2*k+1, l, (l+r)/2);
    ll vr = query(a, b, 2*k+2, (l+r)/2, r);
    return vl + vr;
  }
};

RSQRAQ seg;
signed main(void)
{
  int n, q;
  cin >> n >> q;
  seg.init(n);
  REP(i, q) {
    int a;
    cin >> a;
    if(a) {
      int s, t;
      cin >> s >> t;
      s--;
      cout << seg.query(s, t) << endl;
    } else {
      int s, t, x;
      cin >> s >> t >> x;
      s--;
      seg.update(s, t, x);
    }
  }

  return 0;
}

Measured memory_bytes: 7212
S = list(input())
A = [0]*(len(S)+1)

node_value = 0
for i in range(len(S)):
    if S[i] == "<":
        node_value += 1
        A[i+1] = node_value
    else:
        node_value = 0

node_value = 0
for i in range(len(S)-1,-1,-1):
    if S[i] == ">":
        node_value += 1
        A[i] = max(A[i], node_value)
    else:
        node_value = 0

print(sum(A))

Measured memory_bytes: 32532
/*
            _ _  ___            __ _ _  _       _     
 _   _  ___| | |/ _ \__      __/ _| | || |  ___| |__  
| | | |/ _ \ | | | | \ \ /\ / / |_| | || |_/ __| '_ \ 
| |_| |  __/ | | |_| |\ V  V /|  _| |__   _\__ \ | | |
 \__, |\___|_|_|\___/  \_/\_/ |_| |_|  |_| |___/_| |_|
 |___/                 

*/

#include <bits/stdc++.h>
using namespace std;
#define sz(x) (ll)(x).size()
#define trav(x) for(auto it: x)
#define all(x) x.begin(), x.end()
#define stp fixed<<setprecision(20)
#define db(x) cout<<#x<<": "<<x<<endl
#define tc ll tt; cin>>tt; while(tt--)
#define For(i, st, en) for(ll i=st; i<en; i++)
#define rFor(i, st, en) for(ll i=st; i>=en; i--)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define tr(x) for(auto it=x.begin(); it!=x.end(); it++)
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define printv(x) For(i, 0, sz(x)){cout<<x[i]<<" ";} cout<<endl;
#define print2v(x) For(i, 0, sz(x)){For(j, 0, sz(x[0])){cout<<x[i][j]<<" ";} cout<<endl;}
#define ll long long
#define int long long
#define F first
#define S second
#define pb push_back
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector< vector<int> > vvi;
typedef vector< pair<int, int> > vpi;
#define endl '\n'
#define MAXN 300005
#define MOD 1000000007
#define INF 1000000000000000007


signed main(){
	fast
	int n;
	cin>>n;
	int ans = (n*n*n);
	cout<<ans<<endl;

    return 0;
}
    



Measured memory_bytes: 256
#!/usr/bin/env python3
from collections import deque, Counter
from heapq import heappop, heappush
from bisect import bisect_right

def main():
    M = int(input())
    # d = [None]*M
    # c = [None]*M
    sumc = 0
    sumd = 0
    for i in range(M):
        td, tc = map(int, input().split())
        # d[i] = td
        # c[i] = tc
        sumc += tc
        sumd += td*tc
    # result = sumd%10+sumd//10
    # # print(sumd,c,d,result)
    # if result > 9:
    #     print(sum(c)+sumd//10)
    # else:
    print(sumc-1+(sumd-1)//9)

if __name__ == "__main__":
    main()


Measured memory_bytes: 3316
S=list(input())
A=list(reversed(S))#全体の回文
N=len(S)
S1=S[:(N)//2]
rS1=list(reversed(S1))
if S1!=rS1:
    print("No")
    exit()
S2=S[(N+1)//2:]
rS2=list(reversed(S2))
if S2!=rS2:
    print("No")
    exit()
if S!=A:
    print("No")
    exit()
print("Yes")

Measured memory_bytes: 3064
#include"bits/stdc++.h"
using namespace std;
#define LL long long

LL N,M,K,ans,r;
LL a, b;
string s;
bool graph[9][9];
int dfs(LL now,bool visit[],LL V) {
	for (int i = 1; i < V + 1; i++) {
		if (visit[i] == false) {
			break;
		}
		else if(i==V){
			return 1;
		}
	}
	int num = 0;

	for (int i = 1; i <= V; i++) {
		if (visit[i] == false && graph[now][i] == true) {
			visit[i] = true;
			num += dfs(i, visit, V);
			visit[i] = false;
		}
	}
	return num;
}
int main() {

	cin >> N>>M;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			graph[i][j] = false;
		}
	}
	for (int i = 0; i < M; i++) {
		cin >> a >> b;
		graph[a][b] = true;
		graph[b][a] = true;
	}
	bool v[9];
	for (int i = 1; i <= N; i++) {
		v[i] = false;
	}
	v[1] = true;
	cout << dfs(1,v,N) << endl;
	return 0;

}


Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

fn main() {
	let (h, n): (u32, u32) = (read(), read());
	let mut a: u32;
	let mut sum: u32 = 0;
	for _ in 0..n {
		a = read();
		sum += a;
	}
	let ans = if sum >= h { "Yes" } else { "No" };
	println!("{}", ans);
}

fn read<T: FromStr>() -> T {
	let stdin = stdin();
	let stdin = stdin.lock();
	let token: String = stdin
		.bytes()
		.map(|c| c.expect("failed to read char") as char)
		.skip_while(|c| c.is_whitespace())
		.take_while(|c| !c.is_whitespace())
		.collect();
	token.parse().ok().expect("failed to parse token")
}



Measured memory_bytes: 4352
from operator import mul
from functools import reduce
from collections import defaultdict
import sys
input = sys.stdin.readline


def cmb(n,r):
    r = min(n-r,r)
    if r < 0: return 0 
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under


def main():
    N = int(input())
    d = defaultdict(int)
    for _ in range(N):
        l = sorted(list(input()[:-1]))
        s = ''.join(l)
        d[s] += 1
    # print(d)

    cnt = 0
    for key in d:
        cnt += cmb(d[key], 2)
    
    print(cnt)


if __name__ == '__main__':
    main()

Measured memory_bytes: 18424
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
#define dec(x) cout << fixed << setprecision(x);
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;
 
 
int main(){
  ll N,X;
  cin >> N >>X;
  vl vec(N);
  rep(i,N){
    cin >> vec.at(i);
  }
  ll ans = X;
  rep(i,N){
    ans -=vec.at(i);
  }
sort(vec.begin(), vec.end());
  
  ll ANZ = ans /vec.at(0);
  
  cout << ANZ +N<< endl;
}
  

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <deque>
#include <numeric>
#include <sstream>
#include <iomanip>
using lint = long long;

long long modpow(long long a, long long n, long long p)
{
    long long out = 1;
    while (n)
    {
        if (n & 1)
        {
            out = out * a % p;
        }
        a = a * a % p;
        n >>= 1;
    }
    return out;
}

long long modinv(long long a, long long p)
{
    long long b = p, u = 1, v = 0;
    while (b)
    {
        long long t = a / b;
        a -= t * b;
        std::swap(a, b);
        u -= t * v;
        std::swap(u, v);
    }
    u %= p;
    if (u < 0)
        u += p;
    return u;
}

const int MAX = 510000;
const int MOD = 998244353;

long long 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;
    }
}

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

int main()
{
    lint n, m, k;
    scanf("%lld", &n);
    scanf("%lld", &m);
    scanf("%lld", &k);

    lint ans = 0;

    COMinit();

    for (int i = 0; i <= k; ++i)
    {
        lint cur = 0;
        cur += ((COM(n - 1, i) * m) % MOD);
        cur = cur * modpow(m - 1, n - i - 1, MOD) % MOD;
        ans = (ans + cur) % MOD;
    }

    std::cout << ans << "\n";

    return 0;
}


Measured memory_bytes: 15172
while True:
    n=input()
    if n==0:break
    L=[500,100,50,10,5,1]
    temp=1000-n
    cnt=0
    for i in L:
        j=0
        while i*j<=temp:
	    j+=1
        temp-=i*(j-1)
        cnt+=(j-1)
    print cnt

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

int main() {
    int N;
    cin >> N;
    if(N==1){
        cout << "Hello World" << endl;
    }
    else{
        int A,B;
        cin >> A >> B;
        cout << A+B << endl;
    }
}


Measured memory_bytes: 256