akhauriyash/Code-Regression huggingface dataset:
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

use std::collections::HashMap;

fn main() {
    input! {
        n: usize,
        mut s: [chars; n],
    }

    for i in 0..s.len() {
        s[i].sort();
    }
    s.sort();
    let mut sum: usize = 0;
    let mut count: usize = 0;
    for i in 1..s.len() {
        if s[i] != s[i - 1] {
            sum += count * (count + 1) / 2;
            count = 0;
        } else {
            count += 1;
        }
    }
    sum += count * (count + 1) / 2;
    println!("{}", sum);
}


Measured memory_bytes: 14588
import java.util.Scanner;

class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();

        int tmp;

        if (c < b) {
            tmp = c;
            c = b;
            b = tmp ;
        }

        if (b < a) {
            tmp = b;
            b = a;
            a = tmp;
        }

        if (c < b) {
            tmp = c;
            c = b;
            b = tmp;
        }

        System.out.println(a + " " + b + " " + c);


    }

}


Measured memory_bytes: 26108
//#pragma GCC optimize(2)
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn=1e5+5;
const int mod=1e9+7;
int f;
string s;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
	cin>>s;
    f=1;
    for(int i=0;i<s.size()/2;i++){
        if(s[i]!=s[s.size()-i-1]){
            f=0;
            break;
        }
    }
    for(int i=0;i<s.size()/2/2;i++){
        if(s[i]!=s[s.size()/2-i-1]){
            f=0;
            break;
        }
    }
    if(f==1) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <queue>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <complex>
#include <cstdint>
#include <tuple>
#include <numeric>
#define M_PI       3.14159265358979323846


using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define FILL(a, x) memset(a, x, sizeof(a))

//repetition
//------------------------------------------
#define FOR(i,s,n) for(int i=s;i<(int)n;++i)
#define REP(i,n) FOR(i,0,n)

int main() {
	int n;
	string a, b, c;
	cin >> n >> a >> b >> c;
	int ret = 0;
	REP(i, n) {
		int x = (a[i] != b[i]) + (a[i] != c[i]) + (b[i] != c[i]);
		if (x == 3)ret += 2;
		else if (x == 2)ret += 1;
	}
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define Repr(i, n, a) for (int i = (n); i >= (a); i--)
#define rep(i, n) Rep(i, 0, n)
#define repr(i, n) Repr(i, n, 0)
#define all(a) a.begin(), a.end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;

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

    int a, b, c;
    cin >> a >> b >> c;
    if (a <= c && c <= b)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

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

#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(v) reverse((v).begin(),(v).end())
#define ANS(ans) cout<<(ans)<<endl;
#define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
typedef vector<int> VI;
typedef pair<int, int> P;
 
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  for (int i = 0; i < (n); ++i)

int main() {
    int n;
    cin>>n;
    VI v(n);
    REP(i,n){
        cin>>v[i];
    }

    long long ans = 1;
    VI rgb(3,0);

    REP(i,n){
        int seeing = v[i];
        int tmp=0;
        REP(j,3){
            if(rgb[j]==seeing){
                if(tmp == 0){
                    rgb[j]++;
                }
                tmp++;
            }
        }
        ans = ans*tmp%1000000007;
    }
    ANS(ans);

    return 0;
}


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

    int main() {
      int N; cin >> N;  // 入力値：最大８桁
      int w = N;        // １０で割っていく数
      int F = 0;            // 各桁の数値の和

      rep(i,8){
        F += w % 10;  // １の位を加算
        w /= 10;      // １０で割って切り捨て
//        cout << i << ":" << w << "-" << F << endl;
      }

      // はーシャッド数判定
      if ( N % F == 0 ) {
        cout << "Yes" << endl;
      } else {
        cout << "No" << endl;
      }
    }

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

int main(){
  int N;
  string s,t;
  cin >> N >> s >> t;
  if(s==t){
    cout << N << endl;
  }else{
    for(int i=1;i<N;i++){
      if(s.substr(i,N-i)==t.substr(0,N-i)){
        cout << N-i+2*i << endl;
        return 0;
      }
    }
    cout << 2*N << endl;
  }
  return 0;
}


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

#define MOD 1000000007 // 1e9+7
#define PI acos(-1.0)
#define ll long long int // 10^18
#define INF 1000000001 // 1e9+1

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

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

  // ifstream in("input.txt");
  // cin.rdbuf(in.rdbuf());

  string s;cin>>s[0]>>s[1];
  if(s[0]=='H' && s[1]=='H'){
    P('H');
  }else if(s[0]=='H' && s[1]=='D'){
    P('D');
  }else if(s[0]=='D' && s[1]=='H'){
    P('D');
  }else{
    P('H');
  }
  return 0;
}


Measured memory_bytes: 256
using System;
using static System.Console;
using System.Linq;

namespace Main
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] tmp = ReadLine().Split(' ').Select(int.Parse).ToArray();
            WriteLine((tmp[0] + tmp[1] + tmp[2]) >=22 ? "bust": "win");
        }
    }
}

Measured memory_bytes: 13268
#!/usr/bin/env python3
import sys


def solve(N: int, K: int, H: "List[int]"):
    print(sum(sorted(H, reverse=True)[K:len(H)]))
    return



# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    H = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, K, H)

if __name__ == '__main__':
    main()


Measured memory_bytes: 30596
from sys import stdin
input = stdin.readline

N = int(input())
A = list(map(int, input().split()))

ans = 1

if 0 in A:
    print(0)
    exit()

for a in A:
    ans *= a
    if a > pow(10, 18) or ans > pow(10, 18):
        print(-1)
        exit()


print(ans)


Measured memory_bytes: 21708
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define sz(x) x.size()
using namespace std;
typedef long long ll;
int main(void) {
    string s; cin >> s;
    int state = 0;
    int cnt = 0;
    int cur = 0;
    int n = sz(s);
    vector<int> ans(n);
    rep(i, n) {
        if(state == 0){
            if(s[i]=='R') cnt++;
            else{
                ans[i-1]+=cnt-cnt/2; ans[i]+=cnt/2;
                state = 1; cnt = 1; cur = i;
            }
        }else{
            if(s[i]=='L') cnt++;
            else{
                ans[cur-1]+=cnt/2; ans[cur]+=cnt-cnt/2;
                state = 0; cnt = 1;
            }
            if(i==n-1){
                ans[cur-1]+=cnt/2; ans[cur]+=cnt-cnt/2;
            }
        }
    }
    if(s[n-2]=='R') ans[n-1] += 1;
    rep(i, n) {
        printf("%d\n",ans[i]);
    }
}


Measured memory_bytes: 1024
from bisect import bisect_left


def main():
    n, k = list(map(int, input().split()))
    v = list(map(int, input().split()))

    score = 0
    for i in range(n + 1):
        for j in range(n - i + 1):
            if k < i + j:
                continue

            hands = v[:i] + v[n - j:]
            hands = sorted(hands)

            # throw away negative points
            p = min(bisect_left(hands, 0), k - i - j)

            score = max(score, sum(hands[p:]))

    print(score)


main()

Measured memory_bytes: 3064
import java.util.Scanner;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] A = new int[N];
        for(int i=0;i < A.length;i++){
            A[i] = sc.nextInt();
        }
        int count = 0;
        int minj;
        for(int i = 0;i < N;i++){
            minj = i;
            for(int j = i;j < N;j++){
                if(A[j] < A[minj]){
                    minj = j;
                }
            }
            int tmp = A[i];
            A[i] = A[minj];
            A[minj] = tmp;
            if(A[i] != A[minj]) count++;
        }
        for (int i = 0;i < A.length-1;i++){
            System.out.printf("%d ",A[i]);
        }
        System.out.println(A[N-1]);
        System.out.println(count);
    }
}



Measured memory_bytes: 26364
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;

int main() {
	double a, b, h, m;
	cin >> a >> b >> h >> m;

	double ma =  m / 60 * 2; 
	double ha = (h + m / 60) / 12 * 2;

	double angle = abs(ma - ha);
	if (2 - angle < angle) {
		angle = 2 - angle;
	}

	double ans = sqrt(a*a + b*b - 2*a*b*cos(angle * M_PI));
	cout << setprecision(9) << scientific << ans << endl;
	return 0;
}

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

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
using vll = vector<ll>;
template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;

constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;

template<typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template<typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

int N, M;
vector<vint> G(100005);
bool flag[100005] = {};
int color[100005];

int dfs(int v, int c = 0) {
    int ret = 1;
    if (color[v] != -1 && c != color[v]) return (0);
    color[v] = c;
    if (flag[v]) return (1);
    flag[v] = true;
    for (auto &u : G[v]) ret &= dfs(u, 1 - c);
    return (ret);
}

int main() {
    cin >> N >> M;
    fill_n(color, 100005, -1);
    for (int i = 0; i < M; i++) {
        int u, v;
        cin >> u >> v; --u, --v;
        G[u].push_back(v);
        G[v].push_back(u);
    }
    int colorable = 0;
    int cnt = 0;
    for (int i = 0; i < N; i++) {
        if (!flag[i] && G[i].size() > 0) {
            if (dfs(i)) colorable++;
            else cnt++;
        }
    }
    int rem = count(flag, flag + N, false);

    ll ans = (ll)rem * 2 * N - (ll)rem * rem;

    ans += 2 * (ll)colorable * colorable;
    ans += 2 * (ll)colorable * cnt + cnt * cnt;

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

Measured memory_bytes: 10112
#include <stdio.h>

int main(void)
{
	int a,b,c,d,e,f;
	scanf("%d %d %d %d",&a,&b,&c,&d);
	e=(a+b+c+d)/60;
	f=(a+b+c+d)%60;
	printf("%d\n%d\n",e,f);
	return 0;
}

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

string to_string(string s) {
  return '"' + s + '"';
}

string to_string(const char* s) {
  return to_string((string) s);
}

string to_string(bool b) {
  return (b ? "true" : "false");
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

void test_case() {
  int a;
  string s;
  cin >> a;
  cin >> s;
  if (a >= 3200) {
    cout << s << "\n";
  } else {
    cout << "red\n";
  }
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  test_case();
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const bool debug =0;

inline void read(int &x){
    char ch;
    bool flag=false;
    for (ch=getchar();!isdigit(ch);ch=getchar())if (ch=='-') flag=true;
    for (x=0;isdigit(ch);x=x*10+ch-'0',ch=getchar());
    x=flag?-x:x;
}

inline void write(int x){
    static const int maxlen=100;
    static char s[maxlen];
    if (x<0) {   putchar('-'); x=-x;}
    if(!x){ putchar('0'); return; }
    int len=0; for(;x;x/=10) s[len++]=x % 10+'0';
    for(int i=len-1;i>=0;--i) putchar(s[i]);
}


const int MAXN = 3e5+100;

int h,w,n;
char s[ MAXN ] ,t[ MAXN ];

int a[ MAXN ],b[ MAXN ];
int org_x,org_y;

bool doit(int org,int lim){
int l=1,r=lim;
for (int i=n;i>=1;i--)
{
    if ( a[i]==-1 )
        l++;

    if ( a[i]==1 )
        r--;

    if ( l>r )
        return 1;

    if ( b[i-1]==-1 )
    {
        r++;
        r=min(r,lim);
    }

    if ( b[i-1]==1 )
    {
        l--;
        l=max(l,1);
    }
}
//printf(" l = %d  r=%d  %d\n",l,r,org);
if ( ( l<=org ) && ( org<=r ) )
    return 0;
return 1;
}


void change(char ch_1,char ch_2,char s[],int a[]){
for (int i=1;i<=n;i++)
    if ( s[i]==ch_1 )
        a[i]=-1;
    else
    if ( s[i]==ch_2 )
        a[i]=1;
    else
        a[i]=0;
}

int main(){
    read(h);read(w);read(n);
    read(org_x);    read(org_y);
    scanf("%s%s",s+1,t+1);

    change('U','D',s,a);
    change('U','D',t,b);

    /*
    for (int i=1;i<=n;i++)
        printf("%d ",a[i]);
    puts("");

    for (int i=1;i<=n;i++)
        printf("%d ",b[i]);
    puts("");
    */

    if ( doit(org_x,h) )
    {
        puts("NO");
        return 0;
    }

    change('L','R',s,a);
    change('L','R',t,b);

    /*
    for (int i=1;i<=n;i++)
        printf("%d ",a[i]);
    puts("");

    for (int i=1;i<=n;i++)
        printf("%d ",b[i]);
    puts("");
    */

    if ( doit(org_y,w) )
    {
        puts("NO");
        return 0;
    }

    puts("YES");
    return 0;
}


Measured memory_bytes: 2176
#include <iostream>

//#include <algorithm>
//#include <vector>
//#include <cmath>
//#include <cstring>
//include <queue>
//#include <map>
//cout<<*itr<<endl;
//#define ll long long //data types used often, but you don't want to type them time by time
//#define ALL(c) (c).begin(),(c).end() //handy for function like "sort()"
//#define FOREACH(itr,cont) for (auto itr=cont.begin(); itr!=cont.end(); itr++) // traverse an STL data structure
#define F(i,R) for (int i = 0; i < R; i++) //next four are for "for loops"

using namespace std;
int main()
{
    ios_base::sync_with_stdio(0); //to synchronize the input of cin and scanf
    int x,i=0,num=0,till=0,size=0,sum=0;
    cin>>size>>num;

    F(i,num){
        cin>>x;
        sum+=x;
    }
        if(size<=sum)
            cout<<"Yes"<<endl;
        else
            cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include <iostream>

int main()
{
	int R, G, B, N;
	std::cin >> R >> G >> B >> N;

	unsigned long long counter = 0;

	for ( int r = 0; r <= 3000; r++ )
	{
		int rN = r * R;
		for ( int g = 0; g <= 3000 - r; g++ )
		{
			int gN = g * G;

			if ( rN + gN <= N )
			{
				if ( ( ( N - ( rN + gN ) ) % B ) == 0 )
				{
					counter++;
				}
			}
			else
			{
				break;
			}
		}
	}

	std::cout << counter << std::endl;

	return ( 0 );
}


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

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

struct fastio {
    fastio() {
        ios::sync_with_stdio(false);
        cout << setprecision(10) << fixed;
        cin.tie(0);
    }
};

fastio _fast_io;

const int N = 1e6 + 5;
int n, cur, b;
bool seen[N];

int main() {
    cin >> n;
    // 77?7 / n
    cur = 7;
    b = 1;
    while (cur) {
        if (seen[cur]) {
            cout << -1 << endl;
            exit(0);
        } else {
            seen[cur] = true;
        }
        while (cur < n) {
            cur = cur * 10 + 7;
            ++b;
        }
        cur %= n;
    }
    cout << b << endl;
    return 0;
}


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

int main(){
	int n,t1,t2,p1,p2,rank;
	int *wpts;
	
	cin >> n;
	wpts = new int[n+1];
	
	for(int i = 0; i < n; i++){
		wpts[i] = 0;
	}
	
	for(int i = 0; i < n * (n -1) / 2; i++){
		cin >> t1 >> t2 >> p1 >> p2;
		
		if(p1 > p2){
			wpts[t1-1] += 3;
		}else if (p1 < p2){
			wpts[t2-1] += 3;
		}else{
			wpts[t1-1]++;
			wpts[t2-1]++;
		}
	}
	
	for(int i = 0; i < n; i++){
		rank = 1;
		for(int j = 0; j < n; j++){
			rank += (wpts[i] < wpts[j]) ? 1 : 0;
		}
		cout << rank << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1188
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s;
    cin>>s;
    if(s[2]==s[3] && s[4]==s[5])
    {
        cout<<"Yes";
    }
    else
    {
        cout<<"No";
    }
    return 0;
}







Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
#define rep2(i,a,n) for(int i=a;i<n;i++)
#define been(ix) (ix).begin(),(ix).end()
using namespace std;
typedef long long ll; 
typedef vector<int> vi;
typedef vector<long long> vl;
const ll INFL = 1e18;
const int INF = 1001001001; 
typedef pair<int,int> P;
#define foreach(ix,i) for(auto& (ix) : (i))
typedef long double ld;
const int mod =1000000007;
const double PI = acos(-1);

int main(){
	string s;
    cin>>s;
    rep(i,3)cout<<s[i];
    cout<<endl;
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
#include<numeric>
#define int long long
#define f(i,n) for(int i=0;i<n;i++)
int gcd(int a , int b){ return b ? gcd(b,a%b) : a;}
using namespace std;
signed main(){
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  int cd=c*d/gcd(c,d);
  int C,D,CD;
  C=b/c-(a-1)/c;
  D=b/d-(a-1)/d;
  CD=b/cd-(a-1)/cd;
  cout<<(c!=d?(b-a+1)-(C+D-CD):(b-a+1)-C)<<endl;
  return 0;
}


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

vector<ll> a(51,1),p(51,1);

ll solver(ll n, ll x) {
  if (x==1) return (n==0)?1:0;
  else if (x<=a[n-1]+1) 
    return solver(n-1,x-1);
  else if (x==a[n-1]+2) 
    return 1+p[n-1];
  else if (x==a[n])
    return p[n];
  else return p[n-1]+1+solver(n-1,x-a[n-1]-2);
}

int main()
{
  ll n,x;
  cin>>n>>x;
  for (int i = 1; i < a.size(); ++i)
  {
    a[i]=2*a[i-1]+3;
    p[i]=2*p[i-1]+1;
  }
  cout<<solver(n,x)<<endl;
}

Measured memory_bytes: 3576
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
using P = pair<int, int>;
const int INF = 1e9;
const long long LINF = 1e18;
const long long MOD = 1e9 + 7;

signed main(){
    int n,k;
    cin >> n >> k;
    ll h[n];
    rep(i,n){
        cin >> h[i];
    }
    sort(h,h + n);
    reverse(h, h + n);
    ll ans = 0;
    for(int i = k; i < n; i++){
        ans += h[i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <iomanip>
#include <math.h>
#include <algorithm>
#include <functional> 
#include <string>
#include <vector>

#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <utility>
#include <limits.h>

using namespace std;

typedef long long LL;

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define dump(c) { for (auto it = c.begin(); it != c.end(); ++it) if (it == c.begin()) cout << *it; else cout << ' ' << *it; cout << endl; } 
#define dumpMap(m) { for (auto it: m) cout << it.first << "=>" << it.second << ' '; }

const int MOD = 1e9+7;

int dp[100000][2]; // [top node index][colour of the parent node, 0: black, 1: white]
bool done[100000][2];

LL solve(const vector<vector<int>>& nodes, int current, int parent, int parentColor = 1)
{
    LL ret = dp[current][parentColor];
    if (!done[current][parentColor]) {
        if (nodes[current].size() == 1 && 0 <= parent) {
            // current is the leaf
            ret = (ret + parentColor + 1) % MOD;
        } else {
            for (int currentColor = 0; currentColor < 2; ++currentColor) {
                if (parentColor == 0 && currentColor == 0) continue;
                int x = 1;
                for (int next: nodes[current]) {
                    if (next != parent) {
                        x = (x * solve(nodes, next, current, currentColor)) % MOD;
                    }
                }
                ret = (ret + x) % MOD;
            }
        }

        dp[current][parentColor] = ret;
        done[current][parentColor] = true;
        // cout << "dp[" << current << "][" << parentColor << "] = " <<  dp[current][parentColor] << endl;
    }
    return ret;
}

int main()
{
    int N;
    cin >> N;

    vector<vector<int>> nodes(N);
    rep(i, N-1) {
        int x, y;
        cin >> x >> y;
        --x;
        --y;
        nodes[x].push_back(y);
        nodes[y].push_back(x);
    }

    cout << solve(nodes, 0, -1, 1) << endl;

    return 0;
}


Measured memory_bytes: 16384
#include <iostream>

using namespace std;

int kei(int n, int a, int b) {

	int p = n;
	int aa = 0;
	while (p > 0) {
		aa += p % 10;
		p /= 10;
	}

	if (a <= aa && aa <= b) {
		return n;
	}

	return 0;
}

int main() {

	int n;
	cin >> n;

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

	int ans = 0;
	for (int i = 1; i <= n; i++) {
		ans += kei(i, a, b);
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
IDENTIFICATION DIVISION.
      PROGRAM-ID. 132A.
      DATA DIVISION.
      WORKING-STORAGE SECTION.
      01 INP.
      	03 A PIC X(1).
       	03 B PIC X(1).
       	03 C PIC X(1).
       	03 D PIC X(1).
       
      PROCEDURE DIVISION.
      
      ACCEPT INP.
      
      EVALUATE TRUE
      WHEN ( A = B ) AND ( C = D )
       	IF A = C
        DISPLAY "No"
        ELSE
        DISPLAY "Yes"
      	END-IF
      WHEN ( A = C ) AND ( B = D )
      WHEN ( A = D ) AND ( B = C )
       	IF A = B
        DISPLAY "No"
        ELSE
        DISPLAY "Yes"
      	END-IF
      WHEN OTHER
        DISPLAY "No"
      END-EVALUATE.
      
      STOP RUN.
  


Measured memory_bytes: 384
L, R = [int(_) for _ in input().split()]

# L, R = [4 + 2019, 5 + 2019 ]
if L - R >= 2019:
    ans = 0
    print(ans)
else:
    ans = 2018
    for i in range(L, R + 1):
        for j in range(i + 1, R + 1):
            ans = min(ans, (i * j) % 2019)
            if ans == 0:
                print(ans)
                exit()

print(ans)

Measured memory_bytes: 3060
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int N = in.nextInt();
		long H = in.nextLong();
		int[] a = new int[N];
		int[] b = new int[N];
		for (int i = 0; i < N; i++) {
			a[i] = Integer.parseInt(in.next());
			b[i] = Integer.parseInt(in.next());
		}
		Arrays.sort(a);
		Arrays.sort(b);
		long ans = 0;
		for (int i = b.length - 1; i >= 0 && H > 0; i--) {
			if (b[i] > a[a.length - 1]) {
				H -= b[i];
				ans++;
			} else {
				break;
			}
		}
		if (H > 0) {
			ans += H / a[a.length - 1] + ((H % a[a.length - 1] != 0) ? 1 : 0);
		}
		System.out.println(ans);
		in.close();
	}
}

Measured memory_bytes: 57108
from fractions import gcd
a,b,c,d=map(int,input().split())

def lcm(a, b):
    return a * b // gcd (a, b)

e=lcm(c,d)

i_max=b//c
j_max=b//d
k_max=b//e

i_min=a//c
if a%c==0:
    i_min-=1
j_min=a//d
if a%d==0:
    j_min-=1
k_min=a//e
if a%e==0:
    k_min-=1

i=i_max-i_min
j=j_max-j_min
k=k_max-k_min

print(b-a+1-(i+j-k))



Measured memory_bytes: 5236
import java.awt.*

fun int() = readLine()!!.toInt()
fun list() = readLine()!!.split(" ").map {it.toInt()}

fun main() {
	val n = int()
	val a = Array(n) {
		val (x,y) = list()
		Point(x,y)
	}

	var r = 0.0
	for(i in 0 until n)
		for(j in i+1 until n)
			r += a[i].distance(a[j])
	println(r*2/n)
}


Measured memory_bytes: 36644
from collections import defaultdict
bjisho = defaultdict(int)
rjisho = defaultdict(int)
blue = int(input())
for i in range(blue):
    bjisho[input()] += 1
red = int(input())
for i in range(2+blue, red+2+blue):
    rjisho[input()] += 1
for i in bjisho:
    if i in rjisho:
        bjisho[i] -= rjisho[i]
dst = max(bjisho.values()) if max(bjisho.values()) > 0 else 0
print(dst)


Measured memory_bytes: 3444
N = int(input())
dp = [float('inf')] * (10**5+1)
dp[0] = 0

for i in range(1, N+1):
    dp[i] = min(dp[i-1], dp[i-6], dp[i-6**2], dp[i-6**3], dp[i-6**4], dp[i-6**5], dp[i-6**6],
                dp[i-9], dp[i-9**2], dp[i-9**3], dp[i-9**4], dp[i-9**5]) + 1

print(dp[N])


Measured memory_bytes: 3828
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
#define sp(n) cout << fixed << setprecision(n)
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; }
typedef long long ll;
using namespace std;
int main(void){
    string s;int w;cin>>s>>w;
    for(int i=0;i<s.size();i+=w)cout<<s[i];
    cout<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int k, x;
int main () {
	scanf("%d%d", &k, &x);
	for (int i = x - k + 1; i <= x + k - 1; i++) {
		printf("%d ", i);
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 256
import sys
from math import factorial
from collections import Counter
from fractions import Fraction
import heapq, bisect, fractions
import math
import itertools
sys.setrecursionlimit(10 ** 5 + 10)
INF = 10**15 +5
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
MOD = 10**9 + 7

N, M, Q = MAP()
req = []
for i in range(Q):
    a, b, c, d = MAP()
    req.append([a-1, b-1, c, d])

A = [[1]*N, ]
def plus(a):
    n = len(a)
    if a[n-1] !=M:
        a[n-1] = a[n-1]+1
        return a
    if n==1: return [M,]
    res = plus(a[:n-1])
    return res + [res[n-2],]

while True:
    a = A[-1]
    if a == [M]*N:
        break
    A.append(plus(a))

res = 0
for i in range(len(A)):
    temp = 0
    for j in range(Q):
        if A[i][req[j][1]] - A[i][req[j][0]] == req[j][2]:
            temp += req[j][3]
    if temp > res:
        res = temp

print(res)

Measured memory_bytes: 86912
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <map>
#include <set>
#include <sstream>
#include <stdio.h>
#include <cstdio>
#include <cstring>

using namespace std;

#define Rep(i,a,b) for(int i = a; i < b; i++)
#define rep(i,b) Rep(i,0,b)
#define rrep(i,a) for(int i = a; i >= 0; i--)
#define allof(a) (a).begin(), (a).end()

typedef long long ll;
const int inf = 1e9 + 7;
const ll infll = 1ll << 60ll;
const ll mod = 1e9 + 7;
// 0~3までは右左下上 4~7までは斜め
constexpr int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
constexpr int dy[] = { 0, -1, 0, 1, 1, -1, -1, 1 };

/*
// 最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}

// 最小公約数
long lcm(long a, long b) {
	return a / gcd(a, b) * b;
}*/

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

	int n, m;
	cin >> n;
	map<string, int> mps;
	vector<string> ss(n);
	rep(i, n) {
		string s;
		cin >> s;
		ss[i] = s;
		mps[s]++;
	}
	cin >> m;
	map<string, int> mpt;
	rep(i, m) {
		string t;
		cin >> t;
		mpt[t]++;
	}

	int maxNum = 0;

	rep(i, n) {
		maxNum = max(mps[ss[i]] - mpt[ss[i]], maxNum);
	}

	cout << maxNum << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
#include <array>
#include <queue>
#include <map>
#include <stack>
typedef long long int llint;

bool dp[100001] = {true};

int main(void){

  int n;
  std::string s;
  std::cin >> n >> s;

  std::vector<int> idx1(10, -1);
  std::vector<std::vector<int> > idx2(10, std::vector<int>(10, -1));
  for(int i=0; i<s.size(); i++){
    int tmp = s[i] - '0';
    //std::cout << tmp << std::endl;
    if(idx1[tmp] == -1){
      idx1[tmp] = i;
    }
    for(int j=0; j<10; j++){
      if(idx1[j] == -1) continue;
      if(idx1[j] == i) continue;
      //std::cout << idx1[j] << " " << tmp << std::endl;
      if(idx2[j][tmp] == -1) idx2[j][tmp] = i;
    }
  }
  
  /**
  for(const auto& elem: idx2){
    for(const auto& e: elem){
      std::cout << e << " ";
    }
    std::cout << std::endl;
  }
  **/

  int count = 0;
  for(int i=0; i<10; i++){
    for(int j=0; j<10; j++){
      if(idx2[i][j] == -1) continue;
      bool check[10] = {};
      for(int k=idx2[i][j]+1; k<s.size(); k++){
	int tmp = s[k] - '0';
	check[tmp] = true;
      }
      for(int k=0; k<10; k++){
	if(check[k]) count++;
      }
    }
  }

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using P = pair<lint, lint>;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
constexpr int MOD = 1000000007;
constexpr int INF = 2147483647;
void yes(bool expr) {
  cout << (expr ? "Yes" : "No") << "\n";
}
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  lint N;
  cin >> N;
  vector<lint> A(N);
  REP(i, N) cin >> A[i];
  lint ans = A[0] - 1;
  lint now = 2;
  FOR(i, 1, N) {
    if(A[i] == now) {
      now++;
    } else if(A[i] > now) {
      ans += (A[i] - 1) / now;
    }
    
  }
  cout << ans << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
using namespace __gnu_pbds;
using namespace __gnu_cxx;

typedef pair<int,int> pii;
typedef long long int ll; 
typedef tree<pii,null_type,less<pii>,rb_tree_tag, \
tree_order_statistics_node_update> ordered_set;

#define int ll   
#define long int
#define pb push_back
#define all int i=0; i<n; i++
#define INF LLONG_MAX

#define Nirvana ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define endl '\n'
#define mod 1000000007
#define pii pair<int, int> 
long expo(long base, long exp) 
{ 
    long t = 1L; 
    while (exp > 0)  
    { 
        if (exp % 2 != 0)  t = (t * base); 
        base = (base * base) ; 
        exp /= 2; 
    } 
    return t; 
} 
#define pow expo
#define pi acos(-1.00)

int dig(int n){
	int cur = 0;
	while(n!=0){
		cur++;
		n/=10;
	}
	return cur;
}

int f(int i){
	string s = to_string(i);
	return int(s[0] - '0');
}
int l(int i){
	string s = to_string(i);
	return int(s[s.length()-1] - '0');
}
int32_t main(){

	int n;
	cin>>n;

	map<pair<int, int>, int>m;
	for(int i=1; i<=n; i++){
		m[{f(i), l(i)}]++;
	}
	int ans = 0;
	for(int i=0; i<10; i++){
		for(int j=0; j<10; j++){
			ans+=m[{i, j}]*m[{j, i}];
		}
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define each(a, b) for(auto (a): (b))
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define pb push_back
#define show(x) cout <<#x<<" = "<<(x)<<endl
#define spair(p) cout <<#p<<": "<<p.fi<<" "<<p.se<<endl
#define svec(v) cout<<#v<<":";rep(kbrni,v.size())cout<<" "<<v[kbrni];cout<<endl
#define sset(s) cout<<#s<<":";each(kbrni,s)cout <<" "<<kbrni;cout<<endl

using namespace std;

typedef pair<int,int>P;

const int MAX_N = 100005;



int main()
{
    int n;
    cin >> n;
    rep(i,n){
        string s;
        cin >> s;
        string bf = s;
        vector<string> vec;
        rep(j,s.size()-1){
            s = bf;
            vector<string> vec1;
            vector<string> vec2;
            string t = s.substr(0,j+1);
            vec1.pb(t);
            reverse(all(t));
            vec1.pb(t);
            reverse(all(s));
            t = s.substr(0,s.size()-j-1);
            vec2.pb(t);
            reverse(all(t));
            vec2.pb(t);
            rep(k,vec1.size()){
                rep(l,vec2.size()){
                    string hoge1 = vec1[k] + vec2[l];
                    string hoge2 = vec2[k] + vec1[l];
                    vec.pb(hoge1);
                    vec.pb(hoge2);
                }
            }
        }
        sort(all(vec));
        vec.erase(unique(all(vec)),vec.end());
        cout << (int)vec.size() << "\n";
    }
    return 0;
}

Measured memory_bytes: 3172
#include <bits/stdc++.h>
#define N 100005
using namespace std;

int par[N];
int treerank[N];
int p[N];
int countn[N]={0};

void settree(int n);
int root(int x);
void uni(int x,int y);
bool chtree(int x,int y);

int main(){
  int i,n,a,b,m,max=0;
  cin >> n >> m;
  settree(n);
  for(i=1;i<=n;i++)cin >> p[i];
  for(i=0;i<m;i++){
    cin >> a >> b;
    uni(a,b);
  }
  for(i=1;i<=n;i++){
    a = root(i);
    b = root(p[i]);
    //cout << i << " "<<a <<" "<<b<<endl;
    if(a==b)max++;
    /*if(a==b)countn[a]++;
      if(countn[a]>max)max = countn[a];*/
  }
  cout << max <<endl;
  return 0;
}

void settree(int n){
  for(int i=1;i<=n;i++){
    par[i]=i;
    treerank[i]=0;
  }
}
int root(int x){
  if(par[x]==x)return x;
  return par[x]=root(par[x]);
}
bool chtree(int x,int y){
  return root(x)==root(y);
}
void uni(int x,int y){
  x = root(x);
  y = root(y);
  if(x==y)return;
  if(treerank[x]<treerank[y])par[x]=y;
  else if(treerank[y]<treerank[x])par[y]=x;
  else {
    par[y]=x;
    treerank[x]++;
  }
}


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

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;


//conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}


int main(){
  int n;
  string s;
  cin >> n >> s;
  ll r=0,b=0;
  rep(i,n){
    if(s[i] == 'R') r++;
    else b++;
  }
  cout << (r>b?"Yes":"No") << endl;
  return 0;
}


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

#define rep(i, n) for(int (i)=0; (i)<(n); (i)++)
#define FILL0(x) memset(x,0,sizeof(x))

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

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

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


    int X, N;
    cin >> X >> N;
    ll p[N];
    rep(i, N)
    {
        cin >> p[i];
    }
    string s;
    if(N==0)
    {
        getline(cin, s);
         getline(cin, s);
    }  
    
    sort(p, p+N);

    int index = lower_bound(p, p+N, X)-p;

    if(p[index]!=X)
    {
        cout << X << endl;
        return 0;
    }

    int ans1=p[N-1]+1;
    for(int i=index; i<N-1; i++)
    {
        if(p[i+1]>p[i]+1)
        {
            ans1=p[i]+1;
            break;
        }
    }


    int ans2=p[0]-1;
    for(int i=index; i>0; i--)
    {
        
        if(p[i-1]<p[i]-1)
        {
            ans2=p[i]-1;
            break;
        }
    }

    if(abs(ans1-X)<abs(ans2-X))
    {
        cout << ans1 << endl;
    }
    else
    {
        cout << ans2 << endl;
    }
    





    return 0;
}



Measured memory_bytes: 3656
from itertools import accumulate
import sys
sys.setrecursionlimit(10**6)
n, k = map(int, input().split())
p = list(map(int, input().split()))
c = list(map(int, input().split()))

def dfs(G, v, p):
    seen[v] = True
    sc.append(c[v])

    for nv in G[v]:
        if nv == p:
            continue
        if seen[nv]:
            pos[0] = nv
            return

        dfs(G, nv, v)
        if pos[0] != -1:
            return


G = [[] for _ in range(n)]
for i in range(n):
    G[i].append(p[i]-1)

seen = [False]*n
ans = -float('inf')
for i in range(n):
    if seen[i] == False:
        pos = [-1]
        sc = []
        dfs(G, i, -1)

        if sc:
            sumsc = sum(sc)
            lenc = len(sc)
            for j in range(lenc):
                if j != 0:
                    sc = sc[1:] + [sc[0]]
                ac = list(accumulate(sc))
                
                if sumsc <= 0:
                    ans = max(ans, max(ac[:min(k, lenc)]))
                else:
                    if k%lenc == 0:
                        ans = max(ans, ac[-1]*(k//lenc - 1) + max(ac))
                    else:
                        ans = max(ans, ac[-1]*(k//lenc) + max(ac[:k%lenc]))
print(ans)

Measured memory_bytes: 14400
"""from collections import *
from itertools import *
from bisect import *
from heapq import *

import math
from fractions import gcd
import sys
#input = sys.stdin.readline

import copy
"""
from collections import *
N=int(input())
AB=[list(map(int,input().split())) for i in range(N)]
x,y=1,1

for a,b in AB:
    if x<=a and y<=b:
        x=a;y=b

    elif x>a and y>b:
        c=max([x//a+bool(x%a),y//b+bool(y%b)])
        x=a*c
        y=b*c

    elif x>a:
        c=x//a+bool(x%a)
        x=a*c
        y=b*c
    elif y>b:
        c=y//b+bool(y%b)
        x=a*c
        y=b*c
print(sum([x,y]))


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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef vector<vector<long long>> VVL;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

#define en "\n"

constexpr double EPS = 1e-9;
constexpr double PI  = 3.141592653589793238462643383279;
constexpr int INF = 2147483647;
constexpr long long LINF = 1LL<<60;
constexpr long long MOD = 1000000007; // 998244353

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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

ll K;
ll N, LOGN; // LOGN = floor(log2(N))+1;
VL A;
vector<vector<ll>> tab;
void doubling(){
    for(int i=0; i<N; i++) tab[i][0] = A[i];

    for(int k=0; k<LOGN; k++)
        for(int i=0; i<N; i++){
            if(tab[i][k] == -1) tab[i][k+1] = -1;
            else tab[i][k+1] = tab[tab[i][k]][k];
        }
}

int main(void){
    cin >> N >> K; LOGN = floor(log2(K));
    tab.resize(N, VL(LOGN+1, -1));
    A.resize(N); REP(i,N){ cin >> A[i]; A[i]--;}

    doubling();

    int ans = 0;
    REP(i,LOGN+1){
        if(K & (1LL<<i)) ans = tab[ans][i];
    }
    cout << ans+1 << en;
    return 0;
}

Measured memory_bytes: 106724
for i in range(5):
  if i == 0:
    a = int(input())
  elif i == 1 or i == 2 or i == 3:
    tmp = int(input())
  else:
    b = int(input())
k = int(input())
if k >= b - a:
  print("Yay!")
else:
  print(":(")

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

#define all(x) (x).begin(),(x).end()
#define MOD 1000000007

using namespace std;

int main(){
	int n;	cin >> n;
	vector<int> a;
	for( int i = 0; i < n; i++ ){
		int tmp;	cin >> tmp;
		if( i == 0 || a[i-1] != tmp ){
			a.push_back( tmp );
		}
	}
	vector<pair<int, int>> upR;
	long long int money = 1000;

	for( int i = 1; i < a.size(); i++ ){
			upR.push_back( make_pair( a[i-1], a[i] - a[i-1] ) );
		if( i > 1 && upR[ upR.size() - 1 ].second > 0 && upR[ upR.size() - 2 ].second > 0 ){
			upR[ upR.size() - 2 ].second += upR[ upR.size() - 1].second;
			upR.pop_back();
		}
	}

/*
	for( int i = 0; i < upR.size(); i++ ){
		cout << upR[i].first << "," << upR[i].second << endl;
	}
*/

	for( int i = 0; i < upR.size(); i++ ){
		if( upR[i].second > 0 ){
			money += money / upR[i].first * upR[i].second;
		}
	}

	cout << money << endl;

	return 0;
}


Measured memory_bytes: 3628
n=int(input())
w=[input() for _ in range(n)]
check=0
if len(w) > len(set(w)):
    print('No')
    check = 1
else:
    wl=w[0][-1]
    for i in w[1:]:
        if wl==i[0]:
          	wl = i[-1]
        else:
            print('No')
            check = 1
            break
if check==0:
    print('Yes')
    

Measured memory_bytes: 3060
import java.util.*;

public class Main {
  public static void main(String args[]) {
  	Scanner sc = new Scanner(System.in);
    String a = sc.next();
    String b = sc.next();
    String c = sc.next();
    
    if (a.charAt(a.length() - 1) == b.charAt(0)) {
    	if (b.charAt(b.length() - 1) == c.charAt(0)) {
        	System.out.println("YES");
          	return;
        }
    }
    System.out.println("NO");
  }
}

Measured memory_bytes: 25300
#include<iostream>
#include<vector>
#include<algorithm>
#include<stdlib.h>
#include<utility>
#include<functional>
#include<cfenv>
#include<cmath>
#include<string>
#include<queue>
#include<stack>
#include<map>
#include<set>

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define vint vector<int>
#define vvint vector<vint>
#define P pair<ll,ll>
#define INT_MAX 2147483647
#define MOD 1000000007
#define PI 3.14159265358979323846
#define all(a) (a).begin(),(a).end()
using namespace std;
typedef long long ll;

#define MAX 1000000000000


int main(void) {
	double n, m; cin >> n >> m;
	vector<double> a((int)n);
	double sum = 0;
	rep(i, n) {
		cin >> a[i];
		sum += a[i];
	}
	sort(a.begin(),a.end(),greater<double>());
	if (a[int(m-1)]/sum<1 / (4 * m)) {
		cout << "No" << endl;
		return 0;
	}
	cout << "Yes" << endl;
	return 0;

}

Measured memory_bytes: 3744
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define vi vector<int>
#define pii pair<int, int>
#define forr(i,a,n) for (int i = (a); i < (n); ++i)
#define rforr(i,a,n) for (int i = (a); i > (n); --i)
#define ALL(x) x.begin(),x.end()
#define LEN(X) ((int)(X).size())
#define CASET int _T; cin >> _T; forr(caset,0,_T)
#define int ll

int mod = 1000000000+7;

int power(int base, ll exp) {
    if (exp == 0) return 1;
    ll res = (ll) power(base,exp/2); res = res*res%mod;
    return (exp%2==0) ? res : (base*res)%mod;
}
int mult(int a, int b) {
    return (1LL*a*b)%mod;
}
int mult(int a, int b, int c) {
    return mult(mult(a,b), c);
}
int mult(int a, int b, int c, int d) {
    return mult(mult(a,b,c),d);
}
int inv(int a) {
    return power(a, mod-2);
}

signed main() {
    ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    int n,k; cin >> n >> k;
    vi a(n); forr(i,0,n) cin >> a[i];

    int ans = 0;
    sort(ALL(a));

    vi nck(n,1); nck[1] = k;
    forr(i,2,n) {
        nck[i] = mult(nck[i-1],i-1+k,inv(i));
        nck[i] %= mod;
    }

    forr(i,k-1,n) {
        ans += (a[i]*nck[i-k+1]) % mod;
        ans %= mod;
    }
    rforr(i,n-k,-1) {
        ans += mod - (a[i]*nck[n-k-i]) % mod;
        ans %= mod;
    }
    cout << ans << '\n';

}


Measured memory_bytes: 1792
N = int(input())
A = sorted(map(int, input().split()))
B = []
for i in range(len(A)):
  if A[i]%2==0:
    B.append(A[i])

for i in B:
  if i%3!=0 and i%5!=0:
    print('DENIED')
    exit()
print('APPROVED')


Measured memory_bytes: 38256
#include <stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
int kuaipai();
int a,b,c[200005],d[200005];
int main()
{
    int n,m,i,u=0,r=0,x=0,y=0,t;
    scanf("%d%d",&n,&m);
    for(i=1;i<=m;i++)
    {
        scanf("%d%d",&a,&b);
        if(a==1)
        c[u++]=b;
        else if(b==n)
        d[r++]=a;
    }
    qsort(c,u,sizeof(c[0]), kuaipai);
    qsort(d,r, sizeof(d[0]), kuaipai);
    for(t=1;t<=200000;t++)
    {
        if(c[x]>d[y])
            y++;
        if(c[x]<d[y])
            x++;
        if(c[x]==d[y])
        {
            printf("POSSIBLE\n");return 0;
        }
    }
    printf("IMPOSSIBLE\n");
    return 0;
}

int kuaipai(const void *aaaaaa, const void *bbbbbb)
{return *(int *)aaaaaa - *(int *)bbbbbb;}

Measured memory_bytes: 1396