akhauriyash/Code-Regression huggingface dataset:
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;
import java.util.stream.IntStream;

public class Main {

	public static void main(String[] args) throws IOException {
		new Main().solve();
	}

	private void solve() throws IOException {
		try {
			//			solveA();
			solveB();
			//			 solveC();
			//			 solveD();
			//			 solveE();
			//			 solveF();
		} finally {
			if (in != null) {
				in.close();
			}
			if (out != null) {
				out.flush();
				out.close();
			}
		}

	}

	private void solveA() {
		int numA = nextInt();
		int numB = nextInt();

		int cnt = 0;
		for (int i = 0; i < 2; i++) {
			if (numA > numB) {
				cnt += numA;
				numA--;
			} else {
				cnt += numB;
				numB--;
			}
		}

		out.println(cnt);
	}

	private void solveB() {
		int numN = nextInt();
		int[] wk = IntStream.range(0, numN).map(i -> nextInt()).toArray();

		int cnt = 1;
		int baseHeight = wk[0];
		for (int i = 1; i < wk.length; i++) {
			if (wk[i - 1] <= wk[i] && baseHeight <= wk[i]) {
				cnt++;
			}
			baseHeight = Math.max(baseHeight, wk[i]);
		}

		out.println(cnt);
	}

	private void solveC() {
		int numN = nextInt();

		out.println("");
	}

	private void solveD() {
		int numN = nextInt();

		out.println("");
	}

	private void solveE() {
		int numN = nextInt();

		out.println("");
	}

	private void solveF() {
		int numN = nextInt();

		out.println("");
	}

	private final PrintWriter out = new PrintWriter(System.out);
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	private void skipUnprintable() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
	}

	public boolean hasNext() {
		skipUnprintable();
		return hasNextByte();
	}

	public int nextInt() {
		return Integer.parseInt(next());
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}
}

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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
	return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
	for(auto &e:u) fill_v<T>(e,v...);
}

auto dp = make_v<int>(1, 1);
vector<int> w;

int dfs(int l, int r) {
  if (~dp[l][r]) return dp[l][r];
  if (r - l <= 1) return 0;

  int &res = dp[l][r];
  res = 0;
  for (int i = l; i <= r; i++) {
    res = max(res, dfs(l, i) + dfs(i, r));
  }
  if (abs(w[l] - w[r-1]) <= 1 and dfs(l+1, r-1) == r - l - 2)
    res = max(res, r-l);

  return res;
}

int main() {
  int n;
  while (cin >> n && n) {
    w = vector<int>(n);
    REP(i, n) cin >> w[i];

    dp = make_v<int>(n+1, n+1);
    fill_v<int>(dp, -1);

    cout << dfs(0, n) << endl;
  }
}




Measured memory_bytes: 3560
import java.util.*;

class Main{
    static Scanner sc = new Scanner(System.in);
    public static void main(String args[]){
        long X=Math.abs(sc.nextLong()),K=sc.nextLong(),D=sc.nextLong(),end=0,endl=0;
        if(K>X/D){
            if(X-(X/D)*D<((X/D)+1)*D-X){
                end=X-(X/D)*D;
                endl=D-end;
                if((K-X/D)%2==0){
                    System.out.println(end);
                }else{
                    System.out.println(endl);
                }
            }else{
                endl=X-(X/D)*D;
                end=D-endl;
                if((K-(X/D)-1)%2==0){
                    System.out.println(end);
                }else{
                    System.out.println(endl);
                }
            }
        }
        else{
            System.out.println(Math.abs(X-D*K)<Math.abs(X+D*K)?Math.abs(X-D*K):Math.abs(X+D*K));
        }
    }
}

Measured memory_bytes: 35600
#include<bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0;i < (n);i++)
#define lint long long
const lint mod=1e9+7;
const lint inf=2.19e15+1;
const long double eps=1e-10;
template <class T,class U>bool chmin(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool chmax(T& a,U b){if(a<b){a=b;return true;}return false;}
struct Edge {
    long long to;
};
using Graph = vector<vector<Edge>>;



signed main(){
    lint n;
    lint ans = 0;
    cin >> n;
    for(lint i=1; i<n; i++){
        ans += n / i;
        if(n / i * i == n)ans--;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3620
from sys import stdin
##  input functions for me
def ria(sep = ''):
    if sep == '' :
        return list(map(int, input().split())) 
    else: return list(map(int, input().split(sep)))
def rsa(sep = ''):
    if sep == '' :
        return input().split() 
    else: return input().split(sep)
def ri(): return int(input())
def rd(): return float(input())
def rs(): return input()
##

## main ##
N, K = map(int, input().split())
S = rs()

a = [0] * N
prev = 1
v = 0
for i in range(N):
    if S[i] != prev: v += 1
    a[i] = v
    prev = S[i]

ma = 0
l = 0
r = 0
for v in range(a[0], a[N - 1] + 1):
    while a[l] < v : l += 1
    rv = 0
    if S[l] == '0':
        rv = v + 2 * K - 1
    else :
        rv = v + 2 * K
    while r < N and a[r] <= rv: r += 1
    ma = max(ma, r - l)

print(ma)
 




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

int main() {
  int n;
  cin >> n;
  vector<int> vec(n);
  priority_queue<int> que;
  rep(i,n){
    int s;
    cin >> s;
    vec[i] = s;
    que.push(s);
    //cout << vec[i] << endl;
  }

  int fir=que.top(); que.pop();
  int sec=que.top(); que.pop();

  //cout << sec << endl;

  rep(i,n){
    if(vec[i] == fir){
      cout << sec << endl;
    }
    else{
      cout << fir << endl;
    }
  }
}


Measured memory_bytes: 3316
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#define rep(i,n) for(int (i) = 0; (i) < (n); ++(i))
using namespace std;
typedef long long ll;

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    sort(a.begin(), a.end());

    for(int i = 0; i < n-1; ++i){
        if(a[i] == a[i+1]){
            cout << "NO" << endl;
            return 0;
        }
    }

    cout << "YES" << endl;
    return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>

int main(void){

int i,N,R[200000],max,min;

for(scanf("%d",&N);i<N;scanf("%d",&R[i++]));

max=R[1]-R[0];
min=R[0];

for(i=1;i<N;i++){

max=max<R[i]-min?R[i]-min:max;
min=min>R[i]?R[i]:min;

}

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

return 0;

}

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


#define off ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define lmax1 9223372036854775807
#define max1 2147483647
#define lmin1 -9223372036854775808
#define pi 3.141592653589793116
#define mod 1e9+7

int main() {
    off;
    int a,b,c;
    cin>>a>>b>>c;
    cout<<min(b/a,c)<<'\n';    

      return 0;
}

Measured memory_bytes: 256
def es(k,le):
    i=k
    x=0
    while le>x:
        x+=len(l[i])
        i+=1
    if le==x:return i
    else: return 0



while True:
    n=int(input())
    if n==0:break
    l=[input() for _ in range(n)]
    ans=1
    for i in range(n):
        k=i
        k=es(k,5)
        if k==0:continue
        k=es(k,7)
        if k==0:continue
        k=es(k,5)
        if k==0:continue
        k=es(k,7)
        if k==0:continue
        k=es(k,7)
        if k==0:continue
        print(ans+i)
        break


Measured memory_bytes: 5612
#include<cstdio>
#include<queue>
#include<set>
#include<map>
#include<utility>

using namespace std;

long long n;
int a, b, c, d;
priority_queue<pair<long long, long long>> pq;
map<long long, long long> m;
set<long long> s;

void push(long long x, long long y, bool flag = false) {
  if (m.find(y) == m.end() || x < m[y]) {
    if (flag) {
      s.insert(y);
    }
    m[y] = x;
    pq.push({-x, y});
  }
}

void solve() {
  scanf("%lld %d %d %d %d", &n, &a, &b, &c, &d);
  pq = priority_queue<pair<long long, long long>>();
  m.clear();
  push(0, n);
  while (!pq.empty()) {
    long long x = -pq.top().first;
    long long y = pq.top().second;
    if (y % 2 == 0) {
      push(x + a, y / 2);
      s.erase(y/2);
    }
    if (y % 3 == 0) {
      push(x + b, y / 3);
      s.erase(y/3);
    }
    if (y % 5 == 0) {
      push(x + c, y / 5);
      s.erase(y/5);
    }
    if (s.find(y) == s.end()) {
      push(x + d, y + 1, true);
      push(x + 2*d, y + 2, true);
      push(x + d, y - 1, true);
      push(x + 2*d, y - 2, true);
      if (y < 1e18/d) {
        push(x + y*d, 0, true);
      }
    }
    do {
      pq.pop();
    } while(!pq.empty() && pq.top().first != -m[pq.top().second]);
  }
  printf("%lld\n", m[0]);
}

int main() {
  int t;
  scanf("%d", &t);
  for (int i = 0; i < t; i++) {
    solve();
  }
}


Measured memory_bytes: 7136
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner std = new Scanner(System.in);
		String stdin = std.nextLine();
		String stdout = "";
		for(int i=0; i<stdin.length(); i++){
			if(String.valueOf(stdin.charAt(i)).matches("[a-z]")){
				stdout += String.valueOf(stdin.charAt(i)).toUpperCase();
			}else if(String.valueOf(stdin.charAt(i)).matches("[A-Z]")){
				stdout += String.valueOf(stdin.charAt(i)).toLowerCase();
			}else{
				stdout += String.valueOf(stdin.charAt(i));
			}
		}
		System.out.println(stdout);
	}
}

Measured memory_bytes: 36652
#include <stdio.h>
#include <stdlib.h>

int w[300], can_erase[301][301], dp[301][301];

int max(int a, int b){
	return a >= b ? a : b;
}

int ABS(int a){
	return a >= 0 ? a : -a;
}

int main(){
	int N, i, j, k;
	while(1){
		scanf("%d", &N);
		if(N == 0){
			return 0;
		}
		for(i = 0; i < N; i++){
			scanf("%d", &w[i]);
		}
		for(i = 0; i < N; i++){
			for(j = i + 1; j <= N; j++){
				can_erase[i][j] = 0;
			}
		}
		for(i = 0; i <= N; i++){
			can_erase[i][i] = 1;
		}
		for(k = 1; k <= N; k++){
			for(i = 0; i + k <= N; i++){
				for(j = i + 1; j < i + k; j++){
					if(ABS(w[i] - w[j]) <= 1 && can_erase[i + 1][j] == 1 && can_erase[j + 1][i + k] == 1){
						can_erase[i][i + k] = 1;
					}
				}
			}
		}
		for(i = 0; i <= N; i++){
			for(j = i; j <= N; j++){
				dp[i][j] = 0;
			}
		}
		for(k = 1; k <= N; k++){
			for(i = 0; i + k <= N; i++){
				dp[i][i + k] = dp[i + 1][i + k];
				for(j = i + 1; j <= i + k; j++){
					if(can_erase[i][j] == 1){
						dp[i][i + k] = max(dp[i][i + k], dp[j][i + k] + j - i);
					}
				}
			}
		}
		printf("%d\n", dp[0][N]);
	}
}


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

const int mod = 1000000007;
struct mint {
  ll x;
  mint(ll x=0):x(x%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
  
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

bool comp(int a, int b) {
  return abs(a) > abs(b);
}

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  int mall = 0;
  rep(i, n) { cin >> a[i]; if (a[i] < 0) mall++; }

  mint ans = 1;
  if (mall == n && k % 2 == 1) {
    sort(a.begin(), a.end());
    reverse(a.begin(), a.end());
    rep(i, k) ans *= (a[i] + 1000000007);
    cout << ans.x << endl;
    return 0;
  }

  sort(a.begin(), a.end(), comp);

  int m = 0;
  rep(i, k) {
    ans *= (a[i] + 1000000007);
    if (a[i] < 0) m++;
  }

  bool flug = true;
  for (int i = k; i < n; i++) {
    if (a[i] > 0) flug = false;
  }

  if (m % 2 == 0 || n == k || ans.x == 0 || (m % 2 == 0 && flug)){
    cout << ans.x << endl;
  } else {
    ll pmin = -1, mmax = 1, mmin = 1, pmax = -1;
    for (int i = k - 1; i >= 0; i--) {
      if (a[i] >= 0 && pmin == -1) {
        pmin = a[i];
      }
      if (a[i] < 0 && mmin == 1) {
        mmin = a[i];
      }
    }
    for (int i = k; i < n; i++) {
      if (a[i] < 0 && mmax == 1) {
        mmax = a[i];
      }
      if (a[i] >= 0 && pmax == -1) {
        pmax = a[i];
      }
    }
    ll mm = mmax * mmin, pp = pmax * pmin;
    if (pmax == -1 || mmin == 1) {
      ans = ans / pmin * (mmax + 1000000007);
    } else if (mmax == 1 || pmin == -1) {
      ans = ans / (mmin + 1000000007) * pmax;
    } else if (mm > pp) {
      ans = ans / pmin * (mmax + 1000000007);
    } else {
      ans = ans / (mmin + 1000000007) * pmax;
    }
    cout << ans.x << endl;
  }

  return 0;
}
/*
*/


Measured memory_bytes: 4028
import sys
sys.setrecursionlimit(100000)
class UnionFind:
    def __init__(self, n):
        self.p=[i for i in range(n)]
        self.r=[0 for i in range(n)]
    
    def root(self,x):
        if self.p[x]==x:
            return x
        else:
            self.p[x] = self.root(self.p[x])
            return self.p[x]
    
    def uni(self,x,y):
        x=self.root(x)
        y=self.root(y)
        if(x==y):
            return
        if self.r[x]<self.r[y]:
            self.p[x]=y
        else:
            self.p[y]=x
            if self.r[x]==self.r[y]:
                self.r[x]+=1
    
    def same(self,x,y):
        return self.root(x)==self.root(y)

n,k,l=map(int,input().split())
uf_d=UnionFind(n)
uf_m=UnionFind(n)
for i in range(k):
    a,b=map(int,input().split())
    uf_d.uni(a-1,b-1)
for i in range(l):
    a,b=map(int,input().split())
    uf_m.uni(a-1,b-1)

dic={}
d=[]
for i in range(n):
    ky=(uf_d.root(i),uf_m.root(i))
    if ky in dic:
        dic[ky]+=1
    else:
        dic[ky]=1
    d.append(ky)
for i in range(n):
    print(dic[d[i]],end=' 'if i!=n-1 else '\n')

Measured memory_bytes: 57692
using System;

namespace ALDS1_4B_1{
    public class Program{
        public static void Main(string[] args){
            var n = int.Parse(Console.ReadLine());
            var an = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            Console.ReadLine();
            var tq = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            var cnt = 0;

            foreach(var t in tq){
                var left = 0;
                var right = n;
                while(left < right){
                    var mid = (left + right) / 2;
                    if(an[mid] == t){
                        cnt++;
                        break;
                    }

                    if(t < an[mid]) right = mid;
                    else left = mid + 1;
                }
            }

            Console.WriteLine(cnt);
        }
    }
}

Measured memory_bytes: 19708
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <algorithm>
#include <set>

using namespace std;

int main() {
  int A, B;
  cin >> A >> B;
  int ans = 0;
  for (int i=A; i<=B; i++) {
    string s = to_string(i);
    if (s.at(0) == s.at(4) && s.at(1) == s.at(3)) {
      ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
n, m = [int(i) for i in input().split()]
pe = [0] * n
isok = [False] * n
for _ in range(m):
    p, s = [i for i in input().split()]
    p = int(p) - 1
    if s == "AC":
        isok[p] = True
    else:
        if not isok[p]:
            pe[p] += 1
pen = 0
ans = 0
for i in range(n):
    if isok[i]:
        ans += 1
        pen += pe[i]
print(ans,pen)

Measured memory_bytes: 46440
//

#include <iostream>
#include <numeric>
#include <vector>
#include <algorithm>
#include <math.h>
#include<limits>
#include<iomanip>

using namespace std;
int main() {
	// insert code here...
	int N, K;
	cin >> N >> K;
	//cout << N << K << endl;
	vector<double> p(N);
	//cout << "1/N" <<1 / double(N) << endl;
	for (int j = 1; j < N + 1; j++) {
		int score = j;
		p[j - 1] = 1 / double(N);
		int num_need = 0;
		while (score < K) {
			score = score * 2;
			num_need++;
		}
		
		//cout << score << endl;
		//cout << num_need <<endl;
		p[j - 1] = p[j - 1] * pow(0.5, num_need);
		//cout << "p[" << j - 1 << "]" << p[j - 1] << endl;
	}
	double answer = accumulate(p.begin(), p.end(), 0.0); // double型で返してほしいときは0.0 int型で返してほしいときは0
	cout  << setprecision(10) <<answer << endl; //setprecision(d) : 出力の小数点以下の桁数の設定 (iomanip をincludeする必要あり )
	return 0;
}

Measured memory_bytes: 1024
p = 10 ** 9 + 7


def func(a, n):
    bi = str(format(n, "b"))
    res = 1
    for i in range(len(bi)):
        res = (res * res) % p
        if bi[i] == "1":
            res = (res * a) % p
    return res


N = int(input())
n = func(10, N)
no_0 = func(9, N)
no_9 = func(9, N)
no_09 = func(8, N)
ans = (n - no_0 - no_9 + no_09)
if ans < 0:
    ans += p
if ans < 0:
    ans += p
print(ans)


Measured memory_bytes: 61896
fn main() {
    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()
    }

    let nmc = read_vec::<i32>();
    let n = nmc[0];
    let m = nmc[1];
    let c = nmc[2];
    let b = read_vec::<i32>();
    let mut a = Vec::new();
    for i in 0..n {
      a.push(read_vec::<i32>());
    }
    println!("{}", answer(n,m,c,b,a));
}

fn answer(n:i32, m:i32, c:i32, b:Vec<i32>, a:Vec<Vec<i32>>) -> i64 {
    let mut ans = 0;
    for i in 0..n {
      let mut sum = c;
      for j in 0..m {
        sum += b[j as usize]*a[i as usize][j as usize]
      }
      if sum > 0 {
        ans += 1;
      }
    }
    ans
}


Measured memory_bytes: 4352
N,K=map(int,input().split())
x=list(map(int,input().split()))
#print(x)

list1=[]
for i in range(N-K+1):
    if x[i+K-1]<=0:
        list1.append(x[i]*(-1))
    elif x[i]>=0:
        list1.append(x[i+K-1])
    else:
        list1.append(x[i+K-1]*2-x[i])
        list1.append(x[i+K-1]-x[i]*2)
#print(list1)
print(min(list1))


Measured memory_bytes: 14384
//  main.cpp
//  ABC131C
#include <iostream>
#include<vector>
#include<cassert> // combinationを使う時
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
// 最大公約数
ll gcd(ll a,ll b){
    if(b>0){
        return gcd(b,a%b);
    }else{
        return a;
    }
}
// 最小公倍数
ll lcm(ll a,ll b){
    return a/gcd(a,b)*b;
}
ll f(ll i,ll j,ll k){
    ll ret=i-i/j;
    ret-=i/k;
    ret+=i/lcm(j,k);
    return ret;
}
int main(int argc, const char * argv[]) {
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    cout<<f(b,c,d)-f(a-1,c,d)<<endl;
    return 0;
}


Measured memory_bytes: 3148
#include "bits/stdc++.h"
using namespace std;

int main() {
  int x, y;
  cin >> x >> y;
  for (int i=0 ;i<=x; i++) {
    if ((2*i + 4*(x-i)) == y) {
      cout << "Yes" << endl;
      return 0;
    }
  }

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


Measured memory_bytes: 3604
N=int(input())
L=list(map(int,input().split()))
if N<=2:
  print(0)
else:
  ans=0
  for i in range(N-2):
    for j in range(i+1,N-1):
      for k in range(j+1,N):
        if L[i] !=L[j] and L[i]!=L[k] and L[j]!=L[k]:
          ma=max(L[i],L[j],L[k])
          mi=min(L[i],L[j],L[k])
          nu=L[i]+L[j]+L[k]-ma-mi
          if ma<mi+nu:
            ans+=1
  print(ans)

Measured memory_bytes: 8976
#include<bits/stdc++.h>
using namespace std;
#define inf 1000000000
#define INF 1000000000000000
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
void init(){
  cin.tie(0);
  ios::sync_with_stdio(false);
}



template< typename T >
struct edge {
  int src, to;
  T cost;

  edge(int to, T cost) : src(-1), to(to), cost(cost) {}

  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}

  edge &operator=(const int &x) {
    to = x;
    return *this;
  }

  operator int() const { return to; }
};

template< typename T >
using Edges = vector< edge< T > >;
template< typename T >
using WG = vector< Edges< T > >;
using UG = vector< vector< int > >;
template< typename T >
using Matrix = vector< vector< T > >;



template< typename T >
vector<T> dijkstra(WG<T> &g,int s){
  const auto lim = numeric_limits<T>::max();
  vector<T> dist(g.size(),lim);
  using Pi = pair<T,int>;
  priority_queue<Pi,vector<Pi>,greater<Pi>> q;
  dist[s] = 0;
  q.emplace(dist[s],s);
  while(!q.empty()){
    T cost;
    int idx;
    tie(cost,idx) = q.top();
    q.pop();
    if(dist[idx] < cost) continue;
    for( auto &e : g[idx]){
      auto next_cost = cost + e.cost;
      if(dist[e.to] <= next_cost) continue;
      dist[e.to] = next_cost;
      q.emplace(dist[e.to],e.to);
    }
  }
  return dist;
}


int c,n,m,s,d;

main(){
  while(true){
    cin>>c>>n>>m>>s>>d;
    if(n==0) break;

    s--;d--;
    WG<int> es(n*(c+1));

    rep(k,m){
      int a,b,f;
      cin>>a>>b>>f;
      a--;b--;
      rep(i,c+1){
        es[a*(c+1)+i].PB(edge<int>(b*(c+1)+i,f));
        es[b*(c+1)+i].PB(edge<int>(a*(c+1)+i,f));
      }
      FOR(i,1,c+1){
        es[a*(c+1)+i].PB(edge<int>(b*(c+1)+i-1,f/2));
        es[b*(c+1)+i].PB(edge<int>(a*(c+1)+i-1,f/2));
      }
    }

    vector<int> res=dijkstra(es,s*(c+1)+c);

    int ans=INF;
    rep(i,c+1){
      //cout<<res[d*(c+1)+i]<<endl;
      ans=min(ans,res[d*(c+1)+i]);
    }

    cout<<ans<<endl;

  }
}






Measured memory_bytes: 3396
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>

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

typedef int long long ll;
using namespace std;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const ll MOD = 1e9 + 7;

int main() {
    int s;
    int n;
    cin>>s>>n;
    int ki[10]={0,0,0,0,0,0,0,0,0,0};
    rep(i,n){
        int a;cin>>a;
        ki[a]++;
    }

    for(int i=s;i<=10*s;i++){
        int j=i;
        bool flag=1;
        while(j>=1){
            int u=j%10;
            if(ki[u]!=0){
                flag=0;break;
            }
            j/=10;
        }
        if(flag){
            cout<<i<<endl;return 0;
        }


    }



    return 0;
}


Measured memory_bytes: 256
// AtCoder template
// 見た奴全員saba!
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i = 0; i < n; ++i)
// B
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n; cin >> n;
    int a[n]; rep(i,n) cin >> a[i];
    rep(i,n){
        if(a[i]%2==0 && a[i]%3 != 0 && a[i]%5 != 0){
            cout << "DENIED";
            return 0;
        }
    }
    cout << "APPROVED";
}

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

using namespace std;

#define DUMP(x) std::cout << (#x) << " = " << (x) << "\n"
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define ALL(r) r.begin(), r.end()
#define DUP(x, y) (((x) + (y) - 1) / (y))

using ll = std::int64_t;
using vint = std::vector<int>;
using vll = std::vector<ll>;
using pint = std::pair<int, int>;

constexpr std::int32_t INF = 1001001001;

void Main() {
    int t, x;
    cin >> t >> x;

    cout << (double)t / x << endl;
}

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



Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<ctime>
#include<algorithm>
#include<vector>
#include<iostream>
#include<set>
#include<map>
#include<functional>
#include<queue>
#include<string>

using namespace std;

typedef long long LL;
const int MX=524299,md=924844033;
int g;
int w[2][MX],rev[MX];
int n,N;
vector<int>G[MX];

inline int pw(int x,int y){
	int ans=1;
	while(y){
		if(y&1)ans=(LL)ans*x%md;
		x=(LL)x*x%md,y>>=1;
	}
	return ans;
}
inline int inv(int x){return pw(x,md-2);}
bool ck(int g){
	for(int i=2;i*i<=md-1;i++)if((md-1)%i==0&&(pw(g,i)==1||pw(g,(md-1)/i)==1))return false;
	return true;
}
void calg(){
	g=2;while(!ck(g))++g;
}
void ini(){
	w[0][0]=1;
	int G=pw(g,(md-1)/N);
	for(int i=1;i<N;i++)w[0][i]=(LL)w[0][i-1]*G%md;
	for(int i=0;i<N;i++)w[1][i]=w[0][(N-i)%N];
	for(int i=1;i<N;i++)rev[i]=(rev[i>>1]>>1)|((i&1)*(N>>1));
}
void FFT(int a[],int typ){
	for(int i=0;i<N;i++)if(i<rev[i])swap(a[i],a[rev[i]]);
	int x,y;
	for(int i=1;i<N;i<<=1)
		for(int j=0,d=N/(i<<1);j<N;j+=(i<<1))
			for(int k=j,l=0;k<j+i;k++,l+=d)
				x=(LL)w[typ][l]*a[k+i]%md,y=a[k],a[k]=(y+x)%md,a[k+i]=(md+y-x)%md;
	if(typ){
		int iv=inv(N);
		for(int i=0;i<N;i++)a[i]=(LL)a[i]*iv%md;
	}
}

int c[MX];

int dfs(int k,int f){
	int sz=1;
	for(vector<int>::iterator it=G[k].begin();it!=G[k].end();it++)if(*it!=f)sz+=dfs(*it,k);
	if(k!=1)++c[sz],++c[n-sz];
	return sz;
}
int main(){
	calg();
	scanf("%d",&n);
	for(N=1;N<n;N<<=1);N<<=1;
	ini();
	for(int i=1;i<n;i++){
		static int u,v;
		scanf("%d%d",&u,&v);
		G[u].push_back(v),G[v].push_back(u);
	}
	dfs(1,0);
	static int fac[MX],facinv[MX],inv[MX];
	inv[1]=1;
	for(int i=2;i<=n;i++)inv[i]=(LL)inv[md%i]*(md-md/i)%md;
	fac[0]=facinv[0]=1;
	for(int i=1;i<=n;i++)fac[i]=(LL)fac[i-1]*i%md;
	for(int i=1;i<=n;i++)facinv[i]=(LL)facinv[i-1]*inv[i]%md;
	
	static int a[MX],b[MX];
	for(int i=0;i<n;i++)a[i]=facinv[i];
	for(int i=0;i<n;i++)b[i]=(LL)c[n-i]*fac[n-i]%md;
	FFT(a,0),FFT(b,0);
	for(int i=0;i<N;i++)a[i]=(LL)a[i]*b[i]%md;
	FFT(a,1);
	for(int i=1;i<=n;i++)printf("%lld\n",((LL)n*fac[n]%md*facinv[i]%md*facinv[n-i]%md-(LL)facinv[i]*a[n-i]%md+md)%md); 
	return 0;
}


Measured memory_bytes: 45824
#include<bits/stdc++.h>
#define mins(a,b) a=min(a,b)
#define maxs(a,b) a=max(a,b)
using namespace std;
 
int main(){
  int n,m;
  string s,t;
  cin>>n>>m>>s>>t;
  long long int a,aa;
  bool out=false;
  aa=__gcd(n,m);
  a=aa*(n/aa)*(m/aa);
  for(int i=0;i<aa;i++){
    if(s[i*(n/aa)]!=t[i*(m/aa)]){
      out=true;
      break;
    }
  }
  if(out)
    cout<<-1<<endl;
  else
    cout<<a<<endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define rep(i,ini,n) for(int i=ini;i<n;i++)
#define _rep(i,ini,n) for(int i=ini;i>=n;i--)
#define ToEnd(a) a.begin(),a.end()
uint64_t MOD=1000000007;

int main(){
    int N,K,R,S,P; cin>>N>>K>>R>>S>>P;
    string T; cin>>T;

    map<char,int> mp;
    mp['r']=P;
    mp['s']=R;
    mp['p']=S;

    int64_t ans=0;
    rep(i,0,K){
        char c='.';
        rep(j,0,ceil((double)(N-i)/K)){
            int idx=i+j*K;
            if(c==T.at(idx)) c='.';
            else{c=T.at(idx); ans+=mp[c];}
        }
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(a,n) for (ll a = 0; a < (n); ++a)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<vector<ll> > Graph;
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; }
const ll INF = 1e18;


int main(){
    ll n;
    cin >> n;
    ll a,b;
    cin >> a >> b;
    vector<ll>p(n);
    ll one=0;
    ll two=0;
    ll thr=0;
    rep(i,n){
        cin >> p[i];
        if(p[i]<=a)one++;
        else if(p[i]<=b)two++;
        else thr++;
    }
    ll ans = min(one,min(two,thr));
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
#define Priq priority_queue<int,vi,greater<int>>
#define pb push_back
#define mp make_pair
#define INF (1ll<<60)
signed main(){
  int N; cin>>N;
  vi A(N);
  rep(i,0,N) cin>>A[i];
  vi dp(N+1);
  rep(i,0,N) dp[i+1]=dp[i]+A[i];
  int ans=INF;
  REP(i,2,N){
    int X=disup(dp,dp[i]/2),Y=disup(dp,(dp[i]+dp[N])/2);
    rep(j,0,(1ll<<2)){
      bitset<2> B(j);
      int P=X,Q=Y;
      if(B.test(0)) P--;
      if(B.test(1)) Q--;
      vi C(4);
      C[0]=dp[P];
      C[1]=dp[i]-dp[P];
      C[2]=dp[Q]-dp[i];
      C[3]=dp[N]-dp[Q];
      sort(ALL(C));
      if(C[0]>0) ans=min(ans,C[3]-C[0]);
    }
  }
  cout<<ans<<endl;
  }


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

#define REP(i,p,n) for(ll i=p;i<ll(n);++i)
#define rep(i,n) REP(i,0,n)

using ll = long long;
using pll = pair<ll, ll>;

struct UnionFind
{
    vector<int> uf;

    // 親なし(-1)で初期化しておく
    void init(int n) { uf.assign(n, -1); }

    // 親がいないなら自分を返す, 親がいたら経路圧縮して返す(root直下に繋ぐ)
    int find(int x) { return uf[x] < 0 ? x : (uf[x] = this->find(uf[x])); }

    // 繋げようとする(unionは予約語なんですよね, これが)
    bool connect(int a, int b)
    {
        a = this->find(a); // aのルートノード
        b = this->find(b); // bのルートノード
        if (a != b){ uf[b] = a; return true; } // 新しくつなげた
        return false; // もうつながってる
    }

} uf;

int main()
{
    ll N, M;
    cin >> N >> M;

    uf.init(N);

    rep (i, M)
    {
        ll a, b;
        cin >> a >> b;
        --a;
        --b;

        uf.connect(a, b);
    }

    vector<ll> friends(N, 0);

    ll ans = 0;

    rep (i, N)
    {
        const auto x = uf.find(i);
        ++friends[x];

        ans = max(ans, friends[x]);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 5840
#include <bits/stdc++.h>
#define int long long int
#define endl "\n"
using namespace std;
void solve()
{
	//Enter your code here Tanmay:)
	int n,k;
	cin>>n>>k;
	int arr[n];
	for(int i=0;i<n;i++)
	{
		cin>>arr[i];
	}
	sort(arr,arr+n);
	int sum=0;
	for(int i=n-k-1;i>=0;i--)
	{
		sum+=arr[i];
	}
	cout<<sum;
}
signed main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int t=1;
	//cin>>t;
	while(t--)
	{
		solve();
	}
	return 0;
}
/*
int eulortotent(int n)
     {
    //Enter your code here Tanmay:)
    int total=n;
        for(int p=2;p*p<=n;p++)
        {
            if (n%p==0)
        {
            total /= p;
            total *= (p-1);
            while ( n % p == 0 ) 
                n /= p;
        }
    }

    if(n>1)
    {
        total/=n;
        total*=(n-1);
    }

  return total;
}
*/

Measured memory_bytes: 1792
#include<stdio.h>

int main(void){
	
	int n,S[100000],q,T[50000],i,j,C=0,mid,left,right;

	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d", &S[i]);	
	}
	
	scanf("%d",&q);
	for(j=0;j<q;j++){
		scanf("%d",&T[j]);
	}
	
	for(j=0;j<q;j++){
	left = 0;
	right = n;
	while(left<right){
		mid = (left+right)/2;
		if(S[mid] == T[j]){C++;break;}
		else if(S[mid]>T[j])right = mid;
		else left = mid+1;
	}
	}
	
	printf("%d\n",C);
	
	return 0;}
	
	
	

Measured memory_bytes: 1188
#include <iostream>
#include <cstdio>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <cmath>
#include <stack>
#include <algorithm>
#include <cstring>
#include <sstream>
#include <iomanip>
#include <bitset>
#define fir first
#define sec second
#define REP(i , n) for(int i = 0 ; i < (n) ; i++)
#define BACK(i , n) for(int i = (n) - 1 ; i >= 0 ; i--)
#define pb push_back
#define mp make_pair
using namespace std;
using pii = pair<int , int>;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using vi = vector<int>;
using vii = vector<vi>;
const int MOD = 1e9 + 7 , MAX = 2e9 , MIN = -MAX , invers = 5e8 + 4;
const ll MAX_LL = 2e18 , MIN_LL = -MAX_LL;
int gcd(int a , int b){return !b ? a : gcd(b , a % b);}
int lcm(int a , int b){return a / gcd(a , b) * b;}
int pangkat(int num , int derajat){
    if (derajat == 1)
        return num;
    int x = pangkat(num , derajat >> 1); x = (ll)x * x % MOD;
    if (derajat & 1)
        x = (ll)x * num % MOD;
    return x;
}
struct pasang{
    int y , idx;
    bool operator < (const pasang &a){
        return y < a.y;
    }
};
struct triple{
    int x , y , idx;
    bool operator < (const triple &a)const{
        return x < a.x;
    }
};
int main(){
    int n;
    cin >> n;
    triple arr[n];
    int ans[n];

    REP(i , n)
        cin >> arr[i].x>> arr[i].y,
        arr[i].idx = i;
    sort(arr , arr + n);
    bool computed[n + 1] = {0};

    int ptr = n;
    for (int i = 0 ; i < n ; ){
        int l = i , mini = arr[i].y;

        do{
            mini = min(mini , arr[i].y);
            computed[arr[i].y] = 1;
            while(computed[ptr])
                --ptr;
        }while(++i , ptr > mini);

        for (int j = l ; j < i ; j++)
            ans[arr[j].idx] = i - l;
    }
    REP(i , n)
        cout << ans[i] << '\n';
}


Measured memory_bytes: 6948
//----------------------------templates
    #pragma GCC optimize ("Ofast")
    #pragma GCC target ("tune=native")
    #pragma GCC target ("avx")
    //----------------------------
    #include <bits/stdc++.h>
    using namespace std;

    typedef long long ll;
    typedef unsigned long long ull;
    #define int ll

    #define FOR(i,j,n) for (int i=(int)(j);i<(n);i++)
    #define REP(i,n) for (int i=0;i<(int)(n);i++)
    #define REPS(i,n) for (int i=1;i<=(int)(n);i++)
    #define REPN(i,n) for (int i=(int)(n)-1;i>=0;i--)
    #define REPNS(i,n) for (int i=(int)(n);i>0;i--)

    #define I(n) scanf("%lld", &(n))
    #define LL(n) scanf("%lld", &(n))
    #define pb(n) push_back((n))
    #define mp(i,j) make_pair((i),(j))
    #define eb(i,j) emplace_back((i),(j))
    #define y0 y3487465
    #define y1 y8687969
    #define j0 j1347829
    #define j1 j234892
    #define uniq(v) v.erase( unique(v.begin(), v.end()), v.end() )

    #define all(x) (x).begin(),(x).end()
    #define sz(x) ((int)(x).size())

    typedef vector<int> vi;
    typedef pair<int,int> pi;
    typedef vector<pi> vpi;
    typedef vector<vi> vvi;
    typedef vector<vpi> vvpi;
    typedef vector<vvi> vvvi;

    const int mod = 1000000007;

//--------------------------------------------

ll facts[2000010],invs[2000010];
ll powll(ll base,ll power){
    ll ans = 1;
    while (power){
        if (power&1) ans = (base*ans)%mod;
        base = (base*base)%mod;
        power >>= 1;
    }
    return ans;
}
int pascal(int n, int r){
    return facts[n+r] * invs[r] % mod * invs[n] % mod;
}
signed main(){
    int n = 2000002;
    ll f = 1;
    facts[0] = 1;
    FOR(i,1,n+1){
        f *= i;
        f %= mod;
        facts[i] = f;
    }
    ll inv = powll(f,mod-2);
    invs[n] = inv;
    REPNS(i,n){
        inv *= i;
        inv %= mod;
        invs[i-1] = inv;
    }
    int r1,c1,r2,c2;
    cin >> r1 >> c1 >> r2 >> c2;
    cerr << pascal(r2+1,c2+1) << " " << pascal(r1,c2+1) << " " 
         << pascal(r2+1,c1)  << " " << pascal(r1,c1) << endl;
    int ret = pascal(r2+1,c2+1) - pascal(r1,c2+1) - pascal(r2+1,c1) + pascal(r1,c1);
    ret = (ret + mod * 2) % mod;
    cout << ret << endl;
}

Measured memory_bytes: 31488
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(false), cin.tie(0)
#define debug(a) cout << #a ": " << a << endl
using namespace std;
typedef long long ll;
const double PI = acos(-1.0);
int main(void){
    IOS;
    int n, m;
    cin >> n >> m;
    int sum = 0;
    for (int i = 1; i <= m; ++i){
        int x; cin >> x;
        sum += x;
    }
    cout << max(n-sum, -1);
    return 0;
}

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

#define ll long long
#define ull unsigned long long

using namespace std;

int main() {
	ll N, M;
	cin >> N >> M;

	vector <pair<ll, ll>> C;
	for (int ii = 0; ii < N; ++ii){
		ll A, B;
		cin >> A >> B;
		C.push_back(make_pair(A, B));
	}
	sort(C.begin(), C.end());	//時間が短い順に並んでいる

	ll idx = 0;
	ll ans = 0;
	priority_queue<ll> q;
	for (int ii = M-1; ii >= 0; --ii){
		ll aa = M - ii;
		while(aa == C[idx].first) {
			q.push(C[idx].second);
			idx++;
			if (idx == N) break;
		}
		if (!q.empty()){
			ans += q.top();
			q.pop();
		}
	}

	cout << ans << "\n";


	return 0;
}


Measured memory_bytes: 3568
#include <stdio.h>
#include <iostream>
using namespace std;

int main(void)
{		
	int n;
	int trump[4][13] = {0};
	cin >> n;
	for (int i = 0; i < n; i++) {
		char mark;
		int mark_n;
		cin >> mark;
		if (mark == 'S') mark_n = 0;
		else if (mark == 'H') mark_n = 1;
		else if (mark == 'C') mark_n = 2;
		else if (mark == 'D') mark_n = 3;
		
		int rank;
		cin >> rank;
		trump[mark_n][rank - 1] = 1;
	}
	
	char marks[4] = {'S', 'H', 'C', 'D'};
	for (int j = 0; j < 4; j++) {
		for (int k = 0; k < 13; k++) {
			if (trump[j][k] == 0) {
				cout << marks[j] << " " << k + 1 << endl;
			}
		}
	}
	
	return 0;
}

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

using namespace std;

#define INF 1e9

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

    int n;
    cin>>n;

    while(1){
        int a[4];

        for(int i=0;i<4;i++)cin>>a[i];

        int ans=INF,b[4]={};
        int c[4]={10,50,100,500};

        for(int i=0;i<=a[0];i++){
            for(int j=0;j<=a[1];j++){
                for(int k=0;k<=a[2];k++){
                    for(int l=0;l<=a[3];l++){
                        int sum=10*i+50*j+100*k+500*l;

                        if(sum<n)continue;

                        int p=a[0]-i+a[1]-j+a[2]-k+a[3]-l,d=sum-n;

                        for(int q=3;q>=0;q--){
                            p+=d/c[q];
                            d%=c[q];
                        }

                        if(ans>p){
                            ans=p;
                            b[0]=i;
                            b[1]=j;
                            b[2]=k;
                            b[3]=l;
                        }                        

                    }
                }
            }
        }

        for(int i=0;i<4;i++){
            if(b[i]!=0){
                cout<<c[i]<<" "<<b[i]<<endl;
            }
        }

        cin>>n;

        if(n!=0)cout<<endl;
        else break;

    }

}


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T,class U> using P = pair<T,U>;
template<class T> using vec = vector<T>;
template<class T> using vvec = vector<vec<T>>;

constexpr ll mod = 1e9+7;
struct mint {
    ll x;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    // for prime mod
    mint inv() const {
        return pow(mod-2);
    }
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res/=a;
    }
};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vec<int> g(1<<20,0);
    for(int i=0;i<N;i++){
        int a;
        cin >> a;
        g[a]++;
    }
    for(int i=0;i<20;i++){
        for(int S=(1<<20)-1;S>=0;S--) if(!(S&(1<<i))) g[S] += g[S^(1<<i)];
    }
    mint two = 2;
    mint ans = 0;
    for(int S=0;S<(1<<20);S++){
        int d = __builtin_popcount(S);
        if(d%2==0) ans += two.pow(g[S])-1;
        else ans -= two.pow(g[S])-1;
    }
    cout << ans.x << endl;
}


Measured memory_bytes: 6980
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const int MOD2 = 998244353;

int a[1010], b[1010];
map<int, int> mpa, mpb;

int main(){
    int n, m;
    cin >> n >> m;
    rep(i, n){
        cin >> a[i];
        mpa[a[i]]++;
    }
    rep(i, m){
        cin >> b[i];
        mpb[b[i]]++;
    }
    if (mpa.size() != n || mpb.size() != m || (!mpa[m*n] || !mpb[m*n])) {
        cout << 0 << endl;
        return 0;
    }

    ll ans = 1;
    ll cnta = 0, cntb = 0;

    for(ll num = n*m; num > 0; num--){
        if (mpa[num] && mpb[num]) {
            cnta++;
            cntb++;
        }
        else if (mpa[num] && !mpb[num]){
            ans *= cntb;
            cnta++;
            ans %= MOD;
        }
        else if (!mpa[num] && mpb[num]){
            ans *= cnta;
            ans %= MOD;
            cntb++;
        }
        else {
            ans *= max(cnta * cntb - (n*m-num), (ll)0);
            ans %= MOD;
        }
    }

    cout << ans << endl;

    return 0;
}

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

int main() {
    int N, M, X, Y;
    cin >> N >> M >> X >> Y;
    vector<int> x(N);
    vector<int> y(M);

    for (int i = 0; i < N; i++) cin >> x[i];
    for (int i = 0; i < M; i++) cin >> y[i];

    sort(x.begin(), x.end());
    sort(y.begin(), y.end());

    bool x_cond = X < x.back();
    bool y_cond = y.front() <= Y;
    bool boundary = x.back() < y.front();

    cout << (x_cond && y_cond && boundary ? "No War" : "War") << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
main(){
  string s;
  long long now;
  //A=1,X=2,Y=3,Z=4,W=5,B=6
  while(1){
    cin>>s;
    if(s=="#")break;
    now=1;
    for(int i=0;i<s.size();i++){
      if(s[i]=='0'){
	switch(now){
	case 1:
	  now=2;
	  break;
	case 2:
	  now=-1;
	  break;
	case 3:
	  now=2;
	  break;
	case 4:
	  now=5;
	  break;
	case 5:
	  now=6;
	  break;
	case 6:
	  now=3;
	  break;
	default:
	  break;
	}
      }
      if(s[i]=='1'){
	switch(now){
	case 1:
	  now=3;
	  break;
	case 2:
	  now=4;
	  break;
	case 3:
	  now=-1;
	  break;
	case 4:
	  now=6;
	  break;
	case 5:
	  now=3;
	  break;
	case 6:
	  now=2;
	  break;
	default:
	  break;
	}
      }
    }
    if(now==6){
      cout<<"Yes"<<endl;
    }
    else{
      cout<<"No"<<endl;
    }
  }
}

Measured memory_bytes: 1184
// template.cpp {{{
#include <bits/stdc++.h>
using namespace std;

using lint = long long;
#define reps(i, a, n) for (lint i = (a); i < (lint)(n); ++i)
#define rep(i, n) reps(i, 0, n)
struct pre_{pre_(){cin.tie(0);ios::sync_with_stdio(0);}} pre__;
// }}}

signed main() {
  int n, f;
  map<pair<string, string>, int> chie;

  cin >> n >> f;
  rep(i, n) {
    int m;
    cin >> m;
    vector<string> v(m);
    for (auto&& s : v) cin >> s;
    for (auto&& s : v) {
      for (auto&& t : v) {
        if (s >= t) continue;
        chie[make_pair(s, t)]++;
      }
    }
  }

  vector<pair<string, string>> res;
  for (auto&& m : chie) {
    if (m.second >= f) {
      res.emplace_back(m.first);
    }
  }

  cout << res.size() << endl;
  for (auto&& t : res) {
    cout << t.first << " " << t.second << endl;
  }
}

Measured memory_bytes: 3608
import Control.Monad
func x = do
  mfr_in <- (return. map (read::String->Int) . words) =<< getLine
  let m:f:r:[] = mfr_in
  if (m==(-1)) && (f==(-1)) && (r==(-1))
    then return () else do
      score m f r
      func x

score m f r | (m == -1) || (f == -1)   = putStrLn "F"
            | (m + f) >= 80            = putStrLn "A"
            | (m + f) >= 65            = putStrLn "B"
            | (m + f) >= 50            = putStrLn "C"
            | (m + f) >= 30 && r >= 50 = putStrLn "C"
            | (m + f) >= 30            = putStrLn "D"
            | otherwise                = putStrLn "F"

main = func 0


Measured memory_bytes: 4076
from collections import defaultdict
n = int(input())
d = defaultdict(lambda: 0)
for i in range(n):
    s = input()
    d[s] += 1
k = max(d.values())
ansl = []
for key, value in d.items():
    if value == k:
        ansl.append(key)
ansl = sorted(ansl)
print(*ansl)


Measured memory_bytes: 101796