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

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

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF 1e16

struct RangeMinQuery{
  ll dat[(1<<19)-1];
  ll idx[(1<<19)-1];
  int size,n;

  void init(int n_){
    n=n_;
    size=1;
    while(size<n) size*=2;
    for(int i=0;i<n+1;i++) dat[i]=INF;
    for(int i=0;i<2*size-1;i++) idx[i]=n;
  }

  void update(int k,ll a){
    dat[k]=a;
    k+=size-1;
    idx[k]=k-(size-1);
    while(k>0){
      k=(k-1)/2;
      if(dat[idx[k*2+1]]<dat[idx[k*2+2]])idx[k]=idx[k*2+1];
      else idx[k]=idx[k*2+2];
    }
  }

  ll subquery(int a,int b,int k,int l,int r){
    if(r<=a||b<=l)return n;
    if(a<=l&&r<=b)return idx[k];
    else{
      ll il=subquery(a,b,k*2+1,l,(l+r)/2),ir=subquery(a,b,k*2+2,(l+r)/2,r);
      if(dat[il]<dat[ir])return il;
      else return ir;
    }
  }
  
  ll query(int a,int b){
    return subquery(a,b,0,0,size);
  }
};


RangeMinQuery rmq[2];
ll n;
ll a[211111];

struct range{
  ll l,r,sp;
};

bool operator<(const range& a,const range& b){
  return a.sp>b.sp;
}

int main(){
	cin.sync_with_stdio(false);
  cin>>n;
  rmq[0].init(n); rmq[1].init(n);
  rep(i,n)cin>>a[i];
  rep(i,n){
    rmq[i%2].update(i,a[i]);
  }
  priority_queue<range> que;
  que.push((range){0,n,a[rmq[0].query(0,n)]});
  vector<ll> res;

  while(que.size()){
    range ra=que.top(); que.pop();
    ll l_=rmq[ra.l%2].query(ra.l,ra.r);
    ll r_=rmq[1-(ra.l%2)].query(l_,ra.r);
    res.push_back(a[l_]);
    res.push_back(a[r_]);
    if(ra.l<l_){
      que.push((range){ra.l,l_,a[rmq[ra.l%2].query(ra.l,l_)]});
    }
    if(l_+1<r_){
      que.push((range){l_+1,r_,a[rmq[(l_+1)%2].query(l_+1,r_)]});
    }
    if(r_+1<ra.r){
      que.push((range){r_+1,ra.r,a[rmq[(r_+1)%2].query(r_+1,ra.r)]});
    }
  }
  rep(i,res.size())printf("%lld%c", res[i],i==res.size()-1?'\n':' ');
	return 0;
}


Measured memory_bytes: 22304
#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 = 1e5 + 5;
int n, m, c, t, ans;

int main() {
    cin >> n >> m;
    ans = 2000;
    for (int i = 0; i < n; ++i) {
        cin >> c >> t;
        if (t <= m) {
            ans = min(c, ans);
        }
    }
    if (ans == 2000)
        cout << "TLE" << endl;
    else
        cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3644
using System;
using System.Collections.Generic;
using System.Linq;
class Program {
  	static List<Int32> GetLine() {
    	return Console.ReadLine().Split(' ').Select(v=>Int32.Parse(v)).ToList();
    }
  
	static void Main(string[] args) {
      	//n.ForEach(v=>Console.WriteLine(v.ToString()));
      
		var n = GetLine();
      	var a = GetLine();
      	var b = GetLine();
      
      	var m = new List<List<Int32>>();
      	for (var I=0;I<n[2];++I) {m.Add( GetLine() );}
      	
      	var max = a.Min() + b.Min();
      	foreach(var M in m) {
          var tmp = a[M[0]-1] + b[M[1]-1] - M[2];
          if ( tmp < max ) { max = tmp; }
        }	
      	
      	Console.WriteLine(max);
      
	}
}

Measured memory_bytes: 39388
#include <iostream>
#include <stdio.h>
#include <algorithm> // sort

using namespace std;
static const int MAX = 100;

int main(){
    int ary[MAX] = {0};
    int N, temp, ans = 0;
    cin >> N;
    int i = 0;
    while(i < N){
        cin >> ary[i];
        i++;

    }
    sort(ary, ary + N);
    i = 0;
    int min = 0;
    while(i < N){
        if(min < ary[i]){
            min = ary[i];
            ans++;
        }
        i++;
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long lint;

#define PI acos(-1)
#define INF64 1LL << 60
#define INF32 1 << 29
#define all(a) (a).begin(), (a).end()
#define INV ((long long int)1000000007)

using namespace std;

void execute()
{
	string input;
	cin >> input;
	int a, b, c, d;
	a = input[0] - '0';
	b = input[1] - '0';
	c = input[2] - '0';
	d = input[3] - '0';
	int mem = 0;

	for (int i = 0; i < 1 << 3; i++)
	{
		mem = a;
		mem += (i & 1 ? b : -b);
		mem += (i & 1 << 1 ? c : -c);
		mem += (i & 1 << 2 ? d : -d);
		if (mem == 7)
		{
			cout << a << (i & 1 ? "+" : "-") << b << (i & 1 << 1 ? "+" : "-") << c << (i & 1 << 2 ? "+" : "-") << d << "=7" << endl;
			return;
		}
	}
	return;
}

int main()
{
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	execute();

	int stop;
	cin >> stop;

	return 0;
}

Measured memory_bytes: 256
import sys, heapq


def main():
    
    input = sys.stdin.readline
    
    N, M = map(int, input().split())
    value = [-int(inp) for inp in input().split()]

    heapq.heapify(value)

    for _ in range(M):
        elem = heapq.heappop(value)
        if elem == 0:
            break
        if elem % 2 == 0: 
        	elem //= 2
        else:
        	elem = elem // 2 + 1
        heapq.heappush(value, elem)

    print(- sum(value))
    
if __name__=="__main__":
    main()


Measured memory_bytes: 14172
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
//using ll=long long;
//#define int long long
#define _CRT_SECURE_NO_WARNINGS
#define rep(i, n) for (int i = 0; i < n; i++)
#define _GLIBCXX_DEBUG
const int MOD = 1e9 + 7;
const int INF = 1e18 + 9;
constexpr long double pi = 3.141592653589793238462643383279; //円周率
/*---------------------便利な関数--------------------------------------*/
int fact(int i) {       //階乗
    if (i == 0) return 1;
    return (fact(i - 1)) * i;
}

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

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

int keta(int n) {        //桁数を求める
    if (n == 0) return 1;
    int count = 0;
    while (n != 0) {
        n /= 10;
        count++;
    }
    return count;
}

int ketasum(int n) {    //各桁の和
    int sum = 0;
    while (n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
//最小化問題(DP)
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
//最大化問題(DP)
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

//dp注意点
//問題の種類	 初期化する値	 備考
//最小化問題 	INF	
//最大化問題	    -INF	 テーブル全体で 00 以上の値しかとらないことがわかっていれば −1−1 でもいいですし、00 でもいい場合もあります
//数え上げ問題	00	
//確率問題	      00	
//Yes/No 判定問題	False
/*-------------ここまで---------------------------------------------*/

/*signed*/int main() {
    string s;
    cin >> s;
    if (s == "Sunny") cout << "Cloudy" << endl;
    else if (s == "Cloudy") cout << "Rainy" << endl;
    else cout << "Sunny" << endl;
    return 0;
}

Measured memory_bytes: 3576
#include <iostream>
#include <map>
#include <algorithm>
#include <limits.h>
using namespace std;
int n;
const int MAXN = 2000 + 10;
map<int,int> dp[2][MAXN];
int nums[MAXN];

int get(int val, int i, int j) {
    if (dp[i][j].find(val) != dp[i][j].end()) return dp[i][j][val];
    if (j == n-1) {
        dp[i][j][val] = abs(val - nums[j]);
        return dp[i][j][val];
    }
    int ret;
    if (i == 0) {
        ret = abs(val - nums[n-1]);
        for (int k = j; k+1 < n; k++) {
            ret = max(ret, get(nums[k], 1-i, k+1));
        }
        dp[i][j][val] = ret;
    }
    else {
        ret = abs(val - nums[n-1]);
        for (int k = j; k+1 < n; k++) {
            ret = min(ret, get(nums[k], 1-i, k+1));
        }
    }
    dp[i][j][val] = ret;
    return ret;
}


int main() {
    int z, w;
    cin >> n >> z >> w;
    for (int i = 0; i < n; i++) {
        cin >> nums[i];
    }
    cout << get(w, 0, 0);

    return 0;
}

Measured memory_bytes: 896
import java.util.Scanner;

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

	Scanner sc=new Scanner(System.in);
	String S =sc.next();
	int L = S.length();
	String str = S.substring(2,L-1);

//	System.out.println(L+", "+str);
//	System.out.println(str.indexOf("C"));
//	System.out.println(str.lastIndexOf("C"));

	boolean a = false , b = false, c = false;
	boolean d= false;

//	System.out.println(S.substring(S.indexOf("C")+1)+" "+S.substring(S.indexOf("C")+1).toLowerCase());

	if (S.indexOf("A") == 0){
		a = true;
	}

	if (a == true){
		if(str.contains("C")){
			if (str.indexOf("C") == str.lastIndexOf("C")){
				b = true;
			}
		}
	}

	if (b == true){
		if(S.substring(S.indexOf("C")+1).equals(S.substring(S.indexOf("C")+1).toLowerCase())){
			d =true;
			if(S.substring(1, S.indexOf("C")).equals( S.substring(1, S.indexOf("C")).toLowerCase())){
				c =true;

			}
		}
	}

	if (c== true){
		System.out.println("AC");
	}
	else{
		System.out.println("WA");
	}



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


	}
}

Measured memory_bytes: 23764
#include<stdio.h>

int main() {
  int N, x;

  x = 0;

  scanf("%d", &N);

  while (N >= 6) {
    N -= 3;
    x += 1;
  }

  if (N >= 3) {
    x += 1;
  }

  printf("%d\n", x);
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < n; i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
typedef long long ll;

template<class T>
vector<pair<T, T>> PrimeFactorization(T n) {
    vector<pair<T, T>> f;
    for (T i = 2; i * i <= n; i++) {
        T cnt = 0;
        while (n % i == 0) {
            n /= i;
            cnt++;
        }
        if (cnt > 0) f.push_back(make_pair(i, cnt));
    }
    if (n != 1) f.push_back(make_pair(n, 1));
    return f;
}

int main() {
    int N; cin >> N;
    
    int factors[101] = {};
    for (int i = 1; i <= N; i++) {
        auto f = PrimeFactorization(i);
        for (auto elm : f) factors[elm.first] += elm.second;
    }

    map<int, int> m = {
        {3, 0},
        {5, 0},
        {15, 0},
        {25, 0},
        {75, 0},
    };

    for (int i = 1; i <= 100; i++) {
        for (auto &elm : m) {
            if (factors[i] + 1 >= elm.first) elm.second++; 
        }
    }

    // for (auto elm : m) cout << elm.first << " " << elm.second << endl;

    int ans = 0;
    ans += m[75];
    ans += m[25] * (m[3] - 1);
    ans += m[15] * (m[5] - 1);
    ans += (m[5] * (m[5] - 1)) / 2 * (m[3] - 2);
    cout << ans << endl;
    return 0;
}

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

int main(){

    int N;
    cin >> N;

    long long Li, Li_1 = 1, Li_2 = 2;
    for(int i = 2; i <= N; i++){
        Li = Li_1 + Li_2;
        Li_2 = Li_1;
        Li_1 = Li;
    }

    if(N == 1) cout << 1 << endl;
    else cout << Li << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    string S;
    cin >> S;
    int ans = 0;
    if(S == "RRR"){
        ans = 3;
    }
    else if((S == "RRS") | (S == "SRR")){
        ans = 2;
    }
    else if((S == "RSS") | (S == "RSR") | (S == "SRS") | (S == "SSR")){
        ans = 1;
    }
    else ans = 0;
    cout << ans << endl;
}


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

using namespace std;

int main(){
    string S, T;
    cin >> S >> T;
    
    bool yes = true;;
    if(S.size() + 1 == T.size()){
        for(int i = 0; i < S.size(); i++){
            if(S.at(i) != T.at(i)){
                yes = false;
                break;
            }
        }
    }else{
        yes = false;
    }
    
    if(yes){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll n,L,R,a[55],ans1,ans2,cnt1,cnt2;
bool cmp(ll a,ll b){return a>b;}
ll C[55][55];
int main()
{
    C[0][0]=1;
    for(ll i=1;i<=50;i++)
	{
        C[i][0]=1;
        for(ll j=1;j<=i;j++)
        	C[i][j]=C[i-1][j]+C[i-1][j-1];
    }
    cin>>n>>L>>R;
    for(ll i=1;i<=n;i++) scanf("%lld",&a[i]);
    sort(a+1,a+1+n,cmp); 
    for(ll i=1;i<=L;i++) ans1+=a[i];
    for(ll i=1;i<=n;i++) if(a[i]==a[L]) cnt1++;
    for(ll i=1;i<=L;i++) if(a[i]==a[L]) cnt2++;
    if(a[1]==a[L])
        for(ll i=L;i<=R;i++) 
			ans2+=C[cnt1][i];
    else 
		ans2=C[cnt1][cnt2];
    printf("%lf\n%lld",(double)ans1/L,ans2);
    return 0;
}

Measured memory_bytes: 764
using System;
using System.Linq;

namespace AtCoder.Abcdef
{
    public class QuestionA
    {
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            //Input int array
            int[] inputArray = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
            (int L, int R, int d) = (inputArray[0], inputArray[1], inputArray[2]);

            int min = L % d == 0 ? L : L + d - L % d;

            int cnt = 0;
            int curr = min;
            while (curr <= R)
            {
                cnt++;
                curr = cnt * d + min;
            }
            Console.WriteLine(cnt.ToString());
            Console.Out.Flush();
        }
    }
}


Measured memory_bytes: 28084
l,r = map(int, input().split())
L = l % 2019
R = r % 2019
ans = []

if r - l > 2019:
  print(0)
elif R - L > 0:
  for i in range(L, R):
    for j in range(i+1, R+1):
      ans.append(i * j % 2019)
  print(min(ans))
else:
  print(0)

Measured memory_bytes: 75412
#include <iostream>
#include <string>
#include <queue>
using namespace std;

#define ll long long

int main(){

    ll a, b, c;
    cin >> a >> b >> c;
    ll cnt = 0;

    for(a; a<=b; a++){
        if((c % a) == 0){
            cnt++;
        }
    }

    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
template<class T> void chmin(T &a,const T &b){if(a>b) a=b;}
template<class T> void chmax(T &a,const T &b){if(a<b) a=b;}

string S;
int N,K;

string T;
int nxt[303][26];
int dp[303][303][303];

int rec(int uplef,int dwlef,int num){
    if(N-1-uplef<dwlef) return 0;
    if(N-1-dwlef<uplef) return 0;
    if(dp[uplef][dwlef][num]) return dp[uplef][dwlef][num];
    if(2*uplef>=N&&2*dwlef>=N) return 0;
    if(N%2&&uplef==N/2&&dwlef==N/2) return 1;

    int res=0;
    chmax(res,rec(uplef+1,dwlef,num));
    chmax(res,rec(uplef,dwlef+1,num));

    int cost=2;
    if(N-1-uplef<=dwlef) cost=1;
    if(N-1-dwlef<=uplef) cost=1;
    if(S[uplef]==T[dwlef]) chmax(res,rec(uplef+1,dwlef+1,num)+cost);
    else if(num>0) chmax(res,rec(uplef+1,dwlef+1,num-1)+cost);

    return dp[uplef][dwlef][num]=res;
}

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

  cin>>S;
  cin>>K;
  N=S.size();

  T=S;
  reverse(T.begin(),T.end());
  rep(i,N+1) rep(j,26) nxt[i][j]=N;
  for(int i=N-1;i>=0;i--){
      for(int j=0;j<26;j++){
          nxt[i][j]=nxt[i+1][j];
      }
      nxt[i][T[i]-'a']=i;
  }

  cout<<rec(0,0,K)<<endl;

  return 0;
}


Measured memory_bytes: 108800
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0; i<(int)(n); ++i)

using namespace std;
int N;
int G[1000][1000];
bool used[1000];
void dfs(int u) {
    if(used[u]) return;
    used[u] = true;
    REP(i, N) if(G[u][i] && !used[i]) dfs(i);
}

char memo[1010][1010][2][2];
int rec(int odd, int even, int t, int p) {
    if(odd + even == 2) {
        return p == 0;
    } else {
        char& res = memo[odd][even][t][p];
        if(res != -1) return res;

        if(odd - 2 >= 0 && !rec(odd - 2, even + 1, t ^ 1, p ^ 1)) return res = true;
        if(even - 2 >= 0 && !rec(odd, even - 1, t ^ 1, p)) return res = true;
        if(odd - 1 >= 0 && even - 1 >= 0 && !rec(odd, even - 1, t ^ 1, p)) return res = true;
        return res = false;
    }
}


int main(){
    while(cin >> N) {
        REP(i, N) {
            string s;
            cin >> s;
            REP(j, N) G[i][j] = s[j] == 'Y';
        }
        int odd = 0, even = 0;
        int E = 0;
        bool fill[1010] = {};
        REP(i, N) if(!fill[i]) {
            memset(used, 0, sizeof(used));
            dfs(i);
            vector<int> vs;
            REP(j, N) if(used[j]) {
                fill[j] = true;
                vs.push_back(j);
            }
            for(int u : vs) for(int v : vs) if(u < v && !G[u][v]) {
                E++;
            }
            if(vs.size() % 2 == 0) {
                even ++;
            } else {
                odd ++;
            }
        }

        E += (odd + even) - 1;

        //printf("odd = %d even = %d E = %d\n", odd, even, E);

        memset(memo, -1, sizeof(memo));
        if(rec(odd, even, 0, E % 2)) {
            cout << "Taro" << endl;
        } else {
            cout << "Hanako" << endl;
        }
    }
    return 0;
}

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

int main(){
    bool flag = false;
    int i=0,j=0,N,price;
    cin >> N >> price;
    for (i=0;i<=N;i++){
        for (j=0;j<=N-i;j++){
            if (price == 10000*i+5000*j+1000*(N-i-j)){
            flag = true;
            break;
            }
        }
    if (flag){
        break;
    }
    }
    if(flag == true){
        cout << i << " "<<j << " " << N-i-j <<endl;
    }else{
        cout << "-1 -1 -1";
    }
    return 0;
}

Measured memory_bytes: 256
from heapq import *

def find(A, x):
    p = A[x]
    if p == x:
        return x
    a = find(A, p)
    A[x] = a
    return a

def union(A, x, y):
    if find(A, x) < find(A, y):
        bx, by = find(A, x), find(A, y)
    else:
        bx, by = find(A, y), find(A, x)
    A[by] = bx

N = int(input())
X, Y = [], []

for i in range(N):
    x, y = map(int, input().split())
    X.append((x, i))
    Y.append((y, i))

X.sort()
Y.sort()
H = []
heapify(H)

for i in range(N-1):
    x1, j1 = X[i]
    x2, j2 = X[i+1]
    y1, k1 = Y[i]
    y2, k2 = Y[i+1]
    heappush(H, (x2-x1, j1, j2))
    heappush(H, (y2-y1, k1, k2))

V = [i for i in range(N)]
answer = 0
while H:
    w, s, t = heappop(H)
    if find(V, s) != find(V, t):
        union(V, s, t)
        answer += w
print(answer)

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

using ll = long long;
#define countof(a) (sizeof(a)/sizeof((a)[0]))
#define rep(i, n) for(int i = 0; i < (n); i++)
#define all(a) begin(a),end(a)
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}
#define SP << " " <<
#define FMT(a) #a<<":"<<a 
#define FMT2(a,b) #a<<":"<<a<<", "<<#b<<":"<<b 
#define FMT3(a,b,c) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c 
#define FMT4(a,b,c,d) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c<<", "<<#d<<":"<<d 

template <typename T> T gcd(T a, T b) {
	if (b == 0) return abs(a);
	T r; while ((r = a % b) != 0) a = b, b = r;
	return abs(b);
}

template <typename T> T lcm(T a, T b) {
	return a/gcd(a, b) * b;
}


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

    ll A,B,C,D; cin >> A>>B>>C>>D;
    //cout << FMT4(A,B,C,D) << endl;
    ll lcm_cd = lcm(C,D);
    //cout << FMT(lcm_cd) << endl;

    ll ans = B - B/C - B/D + B/lcm_cd - (A-1 - (A-1)/C - (A-1)/D + (A-1)/lcm_cd);

    cout << ans << endl;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC153
{
    class Program
    {
        static void Main(string[] args)
        {
            a();
        }

        public static void a()
        {
            int[] ha = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
            int h = ha[0];
            int a = ha[1];
            int ans = 0;
            while(h > 0)
            {
                ans++;
                h -= a;
            }
            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 13268
#include<bits/stdc++.h>
using namespace std;
int main(){
  string n;
  cin >> n;
  if(n.at(1)!='7'&&n.at(2)!='7'&&n.at(0)!='7'){
    cout << "No" << endl;
  }else{
    cout << "Yes" << endl;
  }
}
    
  


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

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}

#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
#define A first
#define B second
#define MOD 1000000007

typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef long long ll;

int mulmd(ll a, ll b){
    ll ret = (a * b) % MOD;
    return (int)ret;
}

inline int power(ll x, ll y, int p)
{
    ll res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = mulmd(res,x);
        y = y>>1;
        x = mulmd(x,x);
    }
    return (int)res;
}

int submd(ll a, ll b){
    ll ret = a-b;
    if(ret<0){
        ret+=MOD;
    }
    return (int)ret;
}

int addmd(ll a, ll b){
    ll ret = (a + b) % MOD;
    return (int)ret;
}

int phi(int n){
    int result = n;
    for(int i=2;i*i<=n;i++){
        if(n%i==0){
            while(n%i==0){
                n=n/i;
            }
            result-=result/i;
        }
    }
    if(n>1) result-=result/n;
    return result;
}

const int N = 1e5 + 5;

int arr[N];

/**
    Check out for boundary cases, (n = 1 or n = 0)
    check for integer overflow

**/

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    int cnt = 0;
    for(int i = 1; i <= n; i++){
        int s = 0;
        int j = i;
        while(j > 0){
            j /= 10;
            s++;
        }
        if(s % 2 == 1) cnt++;
    }
    cout << cnt;
}



Measured memory_bytes: 256
#include<stdlib.h>
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<cstring>
#include<time.h>
#include<cmath>
#include<queue>
using namespace std;
#define INF 100000000
typedef long long ll;
int m,n,tn[10001],tm[10001];
int min(int a,int b){
	if(a<b){
		return a;
	}else{
		return b;
	}
}
int max(int a,int b){
	if(a>b){
		return a;
	}else{
		return b;
	}
}

int main(){
	while(1){
		int time=0,maxi=0;
		cin>>n>>m;
		if(n+m==0)break;
		for(int i=0;i<n;i++){
			cin>>tn[i];
		}
		tn[n]=INF;
		for(int i=0;i<m;i++){
			cin>>tm[i];
		}
		tm[m]=INF;
		int i=0,j=0;
		while(i<n||j<m){
			if(tn[i]<=tm[j]){
				maxi=max(maxi,tn[i]-time);
				time=tn[i];i++;
			}else{
				maxi=max(maxi,tm[j]-time);
				time=tm[j];j++;
			}
		}
		cout<<maxi<<endl;
	}
	return 0;
}	

Measured memory_bytes: 1236
import bisect
import cmath
import heapq
import itertools
import math
import operator
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353


A, B, C = list(map(int, sys.stdin.buffer.readline().split()))

ans = B//A
ans = int(min(ans, C))
print(ans)


Measured memory_bytes: 13424
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/range/adaptor/reversed.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
typedef long long int ll;

#define PI (acos(-1))
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define dumparr(x) cerr << #x ; for(auto elem: x){cerr << " " << elem;} cerr << endl;
#define dumppairs(x) cerr << #x ; for(auto elem: x){cerr << "(" << elem.first << " " << elem.second << ") ";} cerr << endl;
#define dumpline cerr << "**********************" << endl;
#define dumpwline(x) cerr << "******** " << #x << "=" << (x) << " ********" << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

int main(void){
    double r; cin >> r;
    cout << 2*PI*r << endl;
    return 0;
}

Measured memory_bytes: 3772
#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 MP make_pair

using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const int INF = 1e9 + 7;

int n, ans;
string a, b, c;

int main()
{
	cin >> n >> a >> b >> c;
	rep(i, n) {
		char ch = a[i] ^ b[i] ^ c[i];
		int tot = min((ch == a[i]) + (ch == b[i]) + (ch == c[i]), 2);
		ans += 2 - tot;
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 256
/*我是萌新*/
#include<iostream>
#include<cmath>
#include<cstring>
#include<string>
#include<algorithm>
#include <iomanip> 
#include<vector>
#include<stack>
typedef long long ll;
using namespace std;
using namespace std;
int k;
vector<long long> count(long long low, long long high)
{
    vector<long long> r;
    stack<long long> t;
    int cnt = 0;
    for (long long i = 0; i < 10; i++)
    {
        t.push(i);

    }
    while (t.size())
    {
        long long v = t.top();
        t.pop();
        if (v >= low && v <= high)
        {
            r.push_back(v);
            cnt++;
        }
        if (v == 0)
        {
            continue;
        }
        if (v > high)
        {
            continue;
        }
        long long mod = v % 10;
        if (mod > 0)
        {
            t.push(v * 10 + mod - 1);
        }
        t.push(v * 10 + mod);
        if (mod < 9)
        {
            t.push(v * 10 + mod + 1);
        }
    }
    sort(r.begin(), r.end());
    return r;
}
int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> k;
    vector<long long> ans = count(1, 3234566667);
    cout << ans[k - 1];
}



Measured memory_bytes: 1400
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();

		scan.close();
		int i=0;
		while(true) {
			if(Math.floor(i*0.08) == a && Math.floor(i*0.1) == b )break;
			if(Math.floor(i*0.08) > a || Math.floor(i*0.1) > b) {
				i=-1;
				break;
			}
			i++;
		}
		System.out.println(i);
	}
}

Measured memory_bytes: 23868
#![allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}
fn read_vec2<T: std::str::FromStr>(n: usize) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
fn main() {
    let n: String = read();
    println!("{}", if n.chars().map(|c| (c as u8 - b'0') as i64).fold(0, |s, x| s + x) % 9 == 0 {"Yes"} else {"No"});
}

Measured memory_bytes: 2296
#include <stdio.h>
int main(void){
	int P, Q, R;
	scanf("%d%d%d", &P, &Q, &R);
	if (P + Q <= Q + R && P + Q <= R + P) {
		printf("%d", P + Q);
	}
	else if (Q + R <= P + Q && Q + R <= R + P) {
		printf("%d", Q + R);
	}
	else if (R + P <= Q + R && R + P <= P + Q) {
		printf("%d", R + P);
	}



	return 0;

	}

Measured memory_bytes: 128
#include<stdio.h>
#include<string.h>
int main()
{
char str[100];
scanf("%s",str);
int i,j,n,flag=0,k,s;
  n=strlen(str);
  for(i=n;i>=1;i--)
  {
    str[i]=str[i-1];
  }
  for(i=1;i<=n/2;i++)
  {
    if(str[i]!=str[n+1-i])
       {
         flag=2;
         break;
       }
  }
       j=(n-1)/4;
       k=(n-1)/2;
       for(i=1;i<=j;i++)
       {
         if(str[i]!=str[k+1-i])
            {
              flag=2;
              break;
            }
         }
            k=(n+3)/2;
            j=(1+(n-3)/2)/2;
            s=0;
            for(i=k;i<n;i++)
            {
              s++;
              if(str[i]!=str[n+1-s])
                 {
                   flag=2;
                   break;
                 }
              }
                 if(flag==0)
                 printf("Yes");
                 else
                 printf("No");
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
using namespace std;
int main(int argc, char* argv[])
{
	string S;
	cin>>S;
	for (int i=0;i<S.length()-1;i++){
		if (S[i]==S[i+1]){
			cout<<"Bad"<<endl;
			return 0;
		}
	}
	cout<<"Good"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
  ll n,a,b;
  ll x[100009];
  cin>>n>>a>>b;
  for(int i=0;i<n;i++){
    cin>>x[i];
  }
  ll ans=0;
  for(int i=0;i<n-1;i++){
    ans+=min((x[i+1]-x[i])*a,b);
  }
  cout<<ans<<endl;
  return(0);
}


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

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

class ConnectNodeInfo{
	vector<vector<pair<ll,ll>>> graph;
public:
	ConnectNodeInfo(int node_num){
		graph.resize(node_num);
	}
	void AddNonDirectionalConnection(ll u,ll v,ll w){
		graph[u].emplace_back(v,w);
		graph[v].emplace_back(u,w);
	}
	void AddDirectionalConnection(ll u,ll v,ll w){
		graph[u].emplace_back(v,w);
	}
	vector<pair<ll,ll>>& operator[](ll index){
		return graph[index];
	}
	size_t size(){return graph.size();}
};

class BellmanFord{
	set<ll> visit;
	bool ignore_unrelated_loop{false};

	bool CanReachImpl(int start,int end,ConnectNodeInfo& connect){
		bool reach=false;
		if(start==end) return true;

		for(int i=0,ei=connect[start].size();i<ei;i++){
			auto res = visit.emplace(connect[start][i].first);
			if(!res.second) continue;
			reach |= CanReachImpl(connect[start][i].first,end,connect);
		}
		return reach;
	}
	
public:
	vector<ll> dist;
	bool CalcShortestPath(int start,ConnectNodeInfo& connect){
		dist.resize(connect.size(),1LL<<60);

		dist[start] = 0;
		for(int i=0,ei=dist.size();i<ei;i++){
			for(int u=0,eu=connect.size();u<eu;u++){
				for(int v=0,ev=connect[u].size();v<ev;v++){
					auto& e = connect[u][v];

					if(dist[e.first]>dist[u]+e.second){
						dist[e.first] = dist[u]+e.second;
						if(i==ei-1 && CanReach(start,u,connect)){
							return false;
						}
					}
				}
			}
		}
		return true;
	}
	bool CanReach(int start,int end,ConnectNodeInfo& connect){
		visit.clear();
		visit.emplace(start);
		return CanReachImpl(start,end,connect);
	}
	void SetIgnoreUnrelatedLoop(bool flag){ignore_unrelated_loop=flag;}
};

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

	auto N=in(),Q=in(),R=in();
	ConnectNodeInfo connect(N);
	REP(i,Q){
		auto u=in(),v=in(),w=in();
		connect.AddDirectionalConnection(u,v,w);
	}
	BellmanFord BF;
	if(!BF.CalcShortestPath(R,connect)){
		out("NEGATIVE CYCLE");
		return 0;
	}
	REP(i,N){
		if(!BF.CanReach(R,i,connect)){
			out("INF");
		}
		else{
			out(BF.dist[i]);
		}
	}
	return 0;
}



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

#define ll long long
#define ld long double
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define sz(x) ((int)(x).size())

const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

bool compare_by_seond(pair<int, int> a, pair<int, int> b)
{
    if (a.second != b.second)
    {
        //return a.second < b.second; //昇順
        return a.second > b.second; // 降順
    }
    else
    {
        return a.first < b.first;
    }
}
int main()
{
    int n;
    cin >> n;
    vector<int> v(n);
    rep(i,n)
    {
        cin >> v[i];
    }
    vector<int> gu(100005, 0);
    vector<int> ki(100005, 0);

    rep(i,n)
    {
        if (i%2==0) 
        {
            gu[v[i]]++;
        }
        if (i % 2 == 1)
        {
            ki[v[i]]++;
        }
    }
    vector<pair<int, int>> gu_vec;
    vector<pair<int, int>> ki_vec;
    rep(i,100005)
    {
        if (gu[i]!=0)
        {
            gu_vec.push_back(make_pair(i, gu[i]));
        }
        if (ki[i] != 0)
        {
            ki_vec.push_back(make_pair(i,ki[i]));
        }
    }
    sort(gu_vec.begin(), gu_vec.end(), compare_by_seond);
    sort(ki_vec.begin(), ki_vec.end(), compare_by_seond);
    int sub = 0;

    if (gu_vec[0].first==ki_vec[0].first)   
    {
        sub = max(gu_vec[0].second + ki_vec[1].second, ki_vec[0].second + gu_vec[1].second);
    }else
    {
        sub = gu_vec[0].second + ki_vec[0].second;
    }
    
    
    int ans = 0;
    ans =  n- sub;
    cout << ans << endl;

}

Measured memory_bytes: 2428
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

int main(void){
	int n;
	cin >> n;
	vector<int> a,b,c;
	a.resize(n); b.resize(n); c.resize(n);
	for(int i = 0; i < n; ++i){
		cin >> a[i];
	}
	for(int i = 0; i < n; ++i){
		cin >> b[i];
	}
	for(int i = 0; i < n; ++i){
		cin >> c[i];
	}
	long long ans = 0;
	sort(a.begin(), a.end()); sort(b.begin(), b.end()); sort(c.begin(), c.end());
	for(int i = 0; i < n; ++i){
		decltype(a)::iterator ita = lower_bound(a.begin(), a.end(), b[i]);
		decltype(c)::iterator itc = lower_bound(c.begin(), c.end(), b[i]+1);
		ans += (ita - a.begin()) * (c.end() - itc);
		//cout << (ita - a.begin()) << " " << (c.end() - itc) << endl;;
	}
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define rep1(i,n) for(int i = 1; i < n; i++)
#define repv(i,n) for(int i = n-1; i >= 0; i--)
#define fi first
#define sc second
#define pb push_back
using namespace std;
typedef long long ll;

char BUF[3500000];
inline void I(int&a){scanf("%d",&a);}
inline void I(int&a,int&b){scanf("%d%d",&a,&b);}
inline void I(int&a,int&b,int&c){scanf("%d%d%d",&a,&b,&c);}
inline void I(int&a,int&b,int&c,int&d){scanf("%d%d%d%d",&a,&b,&c,&d);}
inline void L(ll&a){scanf("%lld",&a);}
inline void L(ll&a,ll&b){scanf("%lld%lld",&a,&b);}
inline void L(ll&a,ll&b,ll&c){scanf("%lld%lld%lld",&a,&b,&c);}
inline void L(ll&a,ll&b,ll&c,ll&d){scanf("%lld%lld%lld%lld",&a,&b,&c,&d);}
inline void S(string&str){str.clear();scanf("%s",BUF);int s=strlen(BUF);rep(i,s)str.pb(BUF[i]);}
inline void SV(vector<int>&v){v.clear();scanf("%s",BUF);int s=strlen(BUF);rep(i,s)if('a'<=BUF[i]&&BUF[i]<='z')v.pb(BUF[i]-'a');else v.pb(BUF[i]-'A');}

const auto EPS = 1e-10;
const auto INF = 100000000;
const auto MOD = 1000000007;
typedef pair<ll,ll> P;

#define MAX_N 500

struct UF{
	int par[MAX_N];
	int rank[MAX_N];
	int si[MAX_N];

	void init(int n){
		rep(i,n){
			par[i] = i;
			rank[i] = 0;
			si[i] = 1;
		}
	}

	int find(int x){
		if(par[x] == x) return x;
		else return par[x] = find(par[x]);
	}

	void unite(int x, int y){
		x = find(x);
		y = find(y);
		if(x == y) return;
		
		if(rank[x] < rank[y]){
			par[x] = y;
			si[y] += si[x];
		} else{
			par[y] = x;
			if(rank[x] == rank[y]) rank[x]++;
			si[x] += si[y];
		}
	}

	bool same(int x, int y){
		return find(x) == find(y);
	}
} uf;

int n, m;
vector<int> e[500];
bool saw[500];

int dfs(int v){
    saw[v] = true;
    int ret = 0;
    rep(i,e[v].size()){
        if(saw[e[v][i]]) ret++;
        else ret += dfs(e[v][i]);
    }
    return ret;
}

int main(){
    I(n,m);
    uf.init(n);
    rep(i,m){
        int a, b;
        cin >> a >> b;
        a--; b--;
        e[a].push_back(b);
        uf.unite(a,b);
    }
    int ans = 0;
    rep(i,n){
        if(saw[i]) continue;
        ans += dfs(i);
    }
    cout << ans << endl;
}

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

int main() {
  int h, n;
  cin >> h >> n;
  vector<int64_t> m = {0};
  vector<pair<int64_t, int64_t>> v(n);
  rep(i, n) cin >> v[i].first >> v[i].second;
  sort(v.begin(), v.end());
  rep(i, h){
    m.push_back(10000000000);
    rep(j, n){
      int64_t tmp = v[j].first;
      if(tmp > i+1) m[i+1] = min(m[i+1], v[j].second);
      else m[i+1] = min(m[i+1], m[i-tmp+1]+v[j].second);
    }
  }
  cout << m[h] << endl;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define forr(i,a,n)	for(long long int i=a; i<n; i++)
#define loop(i,a,n)	for(long long int i=a; i>=n; i--)
const long long int mod=1000000000+7;

long long int mul(long long int x,long long int y)
{
	
   long long int ans=(x * 1ll * y) ;
 	ans%=mod;
 	ans+=mod;
 	ans%=mod;
   	return ans;
}

long long int check(long long int A[],long long int n,long long int k) 
{ 
    sort(A, A + n); 
   long long int product = 1; 
    if (A[n - 1] == 0 && (k & 1)) 
        return 0; 
    if (A[n - 1] <= 0 && (k & 1)) { 
        for (int i = n - 1; i >= n - k; i--) {
        product*=A[i];
           product%=mod;	
           product+=mod;
           product%=mod;
         }
         product+=mod;
         product%=mod;
      
        return (product); 
    } 
    long long int i = 0; 
   long long int j = n - 1; 
    if (k & 1) { 
        product*=A[j];
           product%=mod;	
           product+=mod;
           product%=mod;
        j--; 
        k--; 
    } 
    k >>= 1; 
    for (int itr = 0; itr < k; itr++) { 
       long long int left_product =(A[i+1]*A[i]);
       long long int right_product =(A[j-1]*A[j]); 
        if (left_product > right_product) { 
        	
        	left_product%=mod;
        	left_product+=mod;
        	left_product%=mod;
           product*=left_product;
           product%=mod;	
           product+=mod;
           product%=mod;
            i += 2; 
        } 
        else { 
         	right_product%=mod;
        	right_product+=mod;
        	right_product%=mod;
           product*=right_product;
           product%=mod;
           product+=mod;
           product%=mod;
            j -= 2; 
        } 
    } 
    return (product); 
} 

int main() 
{
	ios_base :: sync_with_stdio(false),cin.tie(NULL),cout.tie(0);
	
	long long int a,k;
	cin>>a>>k;
	long long int b[a];
	forr(i,0,a)
		cin>>b[i];
	long long int x=check(b,a,k);
	x+=mod;
	x%=mod;
	cout<<x;
	
	return 0; 	
}

Measured memory_bytes: 5180
N = int(input())
A = list(map(int, input().split()))
_A = [0] * (N + 1)
L = sum(A)
res = 1_000_000_000_000_000_000
for i in range(N - 1):
    _A[i + 1] = _A[i] + A[i]
    res = min(res, abs(_A[i + 1] - L + _A[i + 1]))
print(res)


Measured memory_bytes: 31580
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back 
#define pf push_front 
#define mp make_pair
#define fr first
#define sc second
#define Rep(i,n) for(int i=0;i<(n);i++)
#define All(v) v.begin(),v.end()
typedef pair<int, int> Pii; typedef pair<int, Pii> Pip;
const int INF = 1107110711071107;
int dx[4] = {0, 1, 0 ,-1}, dy[4] = {-1, 0, 1, 0};

main()
{
  bool isprime[400001] = {0};
  for(int i=1; i*7<=300000; i++) {
    for(int j=2; j*(i*7-1)<=300000; j++) {
      isprime[(i*7-1)*j] = isprime[(i*7+1)*j] = 1;
    }
  }
 
  int n;
  while( cin >> n, n != 1 ) {
    vector<int> v;
    for(int i=1; (i*7-1)<=n; i++) {
      if( !isprime[i * 7 - 1] && !(n % (i * 7 - 1)) ) v.pb( i * 7 - 1 );
      if( !isprime[i * 7 + 1] && !(n % (i * 7 + 1)) ) v.pb( i * 7 + 1 );
    }

    cout << n << ": ";
    Rep(i, v.size()-1) cout << v[i] << " ";
    cout << v[v.size()-1] << endl;
  }
}

Measured memory_bytes: 3512
#include<queue>
#include<cstdio>

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

using namespace std;

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

int h,w,c;

struct Panel{ int a[8][8]; };
struct Point{ int x,y; };

int count(const Panel &pnl){
	int ans=1;
	bool visited[8][8]={}; visited[0][0]=true;

	queue<Point> qu; qu.push((Point){0,0});
	while(!qu.empty()){
		Point p=qu.front(); qu.pop();
		rep(i,4){
			Point q={p.x+dx[i],p.y+dy[i]};
			if(0<=q.y && q.y<h && 0<=q.x && q.x<w
			&& !visited[q.y][q.x] && pnl.a[q.y][q.x]==c){
				visited[q.y][q.x]=true;
				ans++;
				qu.push((Point){q.x,q.y});
			}
		}
	}

	return ans;
}

int dfs(Panel pnl,int depth){
	if(depth==5) return count(pnl);

	int ans=0;
	char prev=pnl.a[0][0];
	for(int cc=1;cc<=6;cc++){
		if(cc==prev || (depth==3 && cc==c) || (depth==4 && cc!=c)) continue;
		Panel tmp=pnl;

		pnl.a[0][0]=cc;
		bool visited[8][8]={}; visited[0][0]=true;
		queue<Point> qu; qu.push((Point){0,0});
		while(!qu.empty()){
			Point p=qu.front(); qu.pop();
			rep(i,4){
				Point q={p.x+dx[i],p.y+dy[i]};
				if(0<=q.y && q.y<h && 0<=q.x && q.x<w
				&& !visited[q.y][q.x] && pnl.a[q.y][q.x]==prev){
					visited[q.y][q.x]=true;
					pnl.a[q.y][q.x]=cc;
					qu.push((Point){q.x,q.y});
				}
			}
		}

		ans=max(ans,dfs(pnl,depth+1));

		pnl=tmp;
	}

	return ans;
}

int main(){
	for(;scanf("%d%d%d",&h,&w,&c),h;){
		Panel pnl;
		rep(i,h) rep(j,w) scanf("%d",&pnl.a[i][j]);

		printf("%d\n",dfs(pnl,0));
	}

	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
constexpr long long INFL = 1LL << 60;
constexpr int INF = 1 << 30;

using namespace std;

using ll = long long;
using P = tuple<int, int>;
using iarr = valarray<int>;

int main()
{
    int N;
    cin >> N;
    int x = N * 800;
    int y = N / 15 * 200;
    cout << x - y << endl;
    return 0;
}

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

int main(){
    int a,b;
    cin >> a >> b;
    int min_8,max_8,min_10,max_10;
    if (a % 2 == 0){
        min_8 = 25 * a / 2;
        max_8 = 25 * (a + 1) / 2;
    }
    if ((a+1) % 2 == 0){
        min_8 = 25 * a / 2;
        min_8++;
        max_8 = 25 * (a + 1) / 2;
        max_8--;
    }
    /* 
    else{
        min_8 = 25 * a / 2;
        min_8++;
        max_8 = 25 * (a + 1) / 2;
    }
    */
    min_10 = 10 * b;
    max_10 = 10 *(b+1) - 1;
    if(max_8 > min_10 && max_10 > min_8){
        cout << max(min_8,min_10) << endl;
    }
    else{
        cout << "-1" << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> pip;
typedef pair<pll, pll> P;
const ll INF = 1ll<<29;
const ll MOD = 1000000007;
const double EPS = 1e-9;
const bool debug = 0;
//---------------------------------//

int main() {
	int K;
	cin >> K;
	
	cout << ((K + 1) / 2) * (K / 2);
	return 0;
}

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

using namespace std;

int main(void) {
	string s1, s2, s3;
	cin >> s1 >> s2 >> s3;
	transform(s1.begin(), s1.end(), s1.begin(), ::toupper);
	transform(s2.begin(), s2.end(), s2.begin(), ::toupper);
	transform(s3.begin(), s3.end(), s3.begin(), ::toupper);
	cout << s1[0];
	cout << s2[0];
	cout << s3[0];
	cout << endl;
	return 0;
}





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


int main() {
    int n;
    string s;
    cin >> n >> s;
    int e = 0;
    for (int i = 0; i < n; i++) {
        if (s[i] == 'E') e++;
    }
    int ans = n + 1;
    int cur_e = 0;
    int cur_w = 0;
    for (int i = 0; i < n; i++) {
        if (s[i] == 'W') {
            ans = min(ans, cur_w + e - cur_e);
            cur_w++;
        } else {
            cur_e++;
            ans = min(ans, cur_w + e - cur_e);
        }
        
    }
    cout << ans << endl;
}

Measured memory_bytes: 832
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <utility>
#include <string>
#include <cstdio>
#include <cmath>
#include <cstdlib>
using namespace std;

int main(){

  int num = 1;
  while (1){
    int x;
    cin >> x;

    if (x == 0){
      break;
    }

    cout << "Case " << num << ": " << x << endl;

    num++;
  }

  return 0;
}



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

int main()
{
    int n;
    int order1, value;
    list<int> l;
    list<int>::iterator itr = l.end();

    cin >> n;

    for( int i = 0; i < n; i++ )
    {
        cin >> order1;

        switch( order1 )
        {
            case 0:
                cin >> value;
                itr = l.insert( itr, value );           //insertは挿入した値を指すようになる。
                break;
            case 1:
                cin >> value;
                if( value >= 0 )
                    for( int i = 0; i < value; i++ )
                        itr++;
                else
                    for( int i = value; i < 0; i++ )
                        itr--;
                break;
            case 2:
                itr = l.erase( itr );                   //eraseは削除した要素の次の要素を指すようになるから、itrに入れておく
                break;
        }
    }

    for( list<int>::iterator i = l.begin(); i != l.end(); i++ )
        cout << *i << endl;
    }


Measured memory_bytes: 18624
inputs = [0,0,0,0,0]
inputs[0] = int(input())

inputs[1] = int(input())

inputs[2] = int(input())

inputs[3] = int(input())

inputs[4] = int(input())

k = int(input())

flag = True
for i in range(0,5):
	for j in range(0,i):
		if inputs[i] - inputs[j] > k:
			flag = False

if flag:
	print("Yay!")
else:
	print(":(")

Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define INF 999999999
#define rep(i,m,n) for(lli i = m;i < n;i++)
#define pb(n) push_back(n)
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(),n.end())
#define Out(S) cout << S << endl
#define NeOut(S) cout << S
#define HpOut(S) cout << setprecision(20) << S << endl;
#define Vecpr vector<pair<lli,lli>>
#define mod 1000000007;
bool is_prime(lli x) {
  for(lli i = 2; i * i <= x; i++) {
    if(x % i == 0) return false;
  }
  return true;
}
int main() {
  lli A,B,C=INF,D=0,E=0,F=0,G=0,H=0,N,M;
  string S,K,L;
  cin >> S;
  A=S.size();
  rep(i,0,A){
    if(S[i]=='A'){
    D=i;
    break;
    }
  }
  for(int i=A-1;i>-1;i--){
    if(S[i]=='Z'){
      E=i+1;
      break;
    }
  }
  Out(E-D);
}

Measured memory_bytes: 640