akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define INF (1<<30)
#define MOD 1000000007
#define l_ength size
using ll = long long;
using namespace std;

int no(){
	cout << "NO" << endl;
	return 0;
}

int main(){
	int h, w, n, sr, sc;
	cin >> h >> w >> n >> sr >> sc;
	string s, t;
	cin >> s >> t;
	int lcnt = 0, rcnt = 0, ucnt = 0, dcnt = 0;
	for( auto c : s ){
		if( c == 'L' ) ++lcnt;
		if( c == 'R' ) ++rcnt;
		if( c == 'U' ) ++ucnt;
		if( c == 'D' ) ++dcnt;
	}
	if( sc - lcnt < 1 ){
		int pos = sc;
		for( int i = 0; i < n; ++i ){
			if( s[i] == 'L' ) --pos;
			if( pos < 1 ) return no();
			if( t[i] == 'R' && pos != w ) ++pos;
		}
	}
	if( sc + rcnt > w ){
		int pos = sc;
		for( int i = 0; i < n; ++i ){
			if( s[i] == 'R' ) ++pos;
			if( pos > w ) return no();
			if( t[i] == 'L' && pos != 1 ) --pos;
		}
	}
	if( sr - ucnt < 1 ){
		int pos = sr;
		for( int i = 0; i < n; ++i ){
			if( s[i] == 'U' ) --pos;
			if( pos < 1 ) return no();
			if( t[i] == 'D' && pos != h ) ++pos;
		}
	}
	if( sr + dcnt > h ){
		int pos = sr;
		for( int i = 0; i < n; ++i ){
			if( s[i] == 'D' ) ++pos;
			if( pos > h ) return no();
			if( t[i] == 'U' && pos != 1 ) --pos;
		}
	}
	cout << "YES" << endl;
	return 0;
}

Measured memory_bytes: 776
#include<bits/stdc++.h>
using namespace std;
int main(void){
	int n,m;
	string s;
	int sum,ave,cnt;
	sum=0;
	ave=0;
	cnt=0;
	while(scanf("%d,",&n)!=EOF){
		cin>>m;
		//cout<<n<<m<<endl;
		sum+=n*m;
		ave+=m;
		cnt++;
	}
	cout<<sum<<endl;
	if(ave%cnt==0)	cout<<ave/cnt<<endl;
	else{
		if(ave%cnt*10/cnt>=5)	cout<<ave/cnt+1<<endl;
		else			cout<<ave/cnt<<endl;
	}
	return 0;
}


Measured memory_bytes: 3144
import java.util.Scanner;
public class Main {
	public static void main(String[] args) throws Exception{
		Scanner scan=new Scanner(System.in);
		int A=scan.nextInt();
		int B=scan.nextInt();
		int C=scan.nextInt();
		int d[][]=new int[B][A];
		for(int i=0;i!=B;i++) {
			for(int j=0;j!=A;j++) {
				d[i][j]=1;
			}
		}
		for(int i=0;i!=C;i++) {
			int a=scan.nextInt();
			int b=scan.nextInt();
			int c=scan.nextInt();
			if(c==1) {
				for(int j=a-1;j!=-1;j--) {
					for(int k=0;k!=B;k++) {
						d[k][j]=0;
					}
				}
			}	if(c==2) {
				for(int j=a;j!=A;j++) {
					for(int k=0;k!=B;k++) {
						d[k][j]=0;
					}
				}
			}	if(c==3) {
				for(int j=B-b;j!=B;j++) {
					for(int k=0;k!=A;k++) {
						d[j][k]=0;
					}
				}
			}	if(c==4) {
				for(int j=B-b-1;j!=-1;j--) {
					for(int k=0;k!=A;k++) {
						d[j][k]=0;
					}
				}
			}
		}
		int ans=0;
		for(int j=0;j!=B;j++) {
			for(int k=0;k!=A;k++) {
				if(d[j][k]==1) {
					ans++;
			}
			}
	}
		System.out.println(ans);
	}
}


Measured memory_bytes: 23508
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 30;
const int MOD = 1e9 + 7;

const int N = 1e6 + 10;
char s[N];
int main() {
  scanf("%s", s);
  int n = strlen(s);
  int ret = -1;
  for (int i = 0, j; i < n; i = j) {
    for (j = i + 1; j < n && s[i] == s[j]; ++j);
    ++ret;
  }
  printf("%d\n", ret);
  return 0;
}


Measured memory_bytes: 384
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <functional>
#include <cstring>
#include <string>
#include <map>
#include <set>
#include <iostream>
#include <sstream>
#include <complex>
#include <cassert>

#define enp     puts("**chkchkchkchkchk**")
#define A       first
#define B       second
#define MP      make_pair

using namespace std;

typedef long long ll;
typedef unsigned int uint;

const int INF = 0x60000000;
const int MINF = -1000000000;
const int mod = 1000000007;
const ll cons = 100000;
const double pi = 3.141592653589793;



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

	vector <int> vec;

	int cur = -1;
	for (int i = 0; i < s.length(); i++)
	{
		if (cur == 0 && s[i] == 'W')continue;
		if (cur == 1 && s[i] == 'B')continue;

		if (s[i] == 'W')cur = 0, vec.push_back(0);
		else cur = 1, vec.push_back(1);
	}

	printf("%d\n", vec.size() - 1);

	return 0;
}

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

   typedef long long ll;
   typedef pair<ll, ll> Pii;
   typedef vector<ll> Vi;
   typedef vector<Vi> VVi;

   const double EPS = (1e-7);
   const ll INF =(1e13);
   const double PI = (acos(-1));
   const ll MOD = ll(1e9) + 7;

   #define REP(i, n) for(ll i = 0; i < (ll)(n); i++)
   #define REPR(i, n) for(ll i = n; i > -1; i--)
   #define FOR(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
   #define ALL(x) (x).begin(),(x).end()
   #define SORT(x) sort((x).begin(), (x).end())
   #define RSORT(x) sort((x).rbegin(), (x).rend()
   #define REVERSE(x) reverse((x).begin(), (x).end())
   #define SZ(x) ((ll)(x).size())
   #define pb push_back
   #define mp make_pair

   //chmax(a, b): a>bならaをbで更新　更新したときにtrueを返す
   //chmin(a, b): a<bならaをbで更新　更新したときにtrueを返す
   template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
   template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

   #define dump(x) cerr<< #x << "= " << (x) << endl;

   ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
   ll pow(ll a, ll b){if (b == 0) return 1; else if (b % 2 == 0) return pow(a * a, b / 2); else return pow(a * a, b / 2) * a;}
   ll pow(ll a, ll b, ll m){if (b == 0) return 1; else if (b % 2 == 0) return (pow(a * a, b / 2, m) % m); else return (pow(a * a, b / 2) * a) % m;}
   ll residue(ll a, ll m){return ((a % m) + m) % m;};

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

const ll MAX_N = 1e4;
ll N;
ll a[MAX_N], b[MAX_N];
int main(){
   cin >> N;
   REP(i, N) cin >> a[i];
   REP(i, N) cin >> b[i];

   ll cnt1 = 0, cnt2 = 0;
   REP(i, N){
      if(a[i] > b[i]) cnt2 += (a[i] - b[i]);
      else {
         cnt1 += (b[i] - a[i] + 1) / 2;
         cnt2 += (b[i] - a[i]) % 2;
      }
   }
   cout << ((cnt1 >= cnt2) ? "Yes" : "No") << endl;
}


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

using namespace std;
using ll = long long;
#define int ll
using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define PB push_back

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const int MOD = 1000000007;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template <typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }
template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
  out<<'('<<a.first<<','<<a.second<<')';
  return out;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
  out<<'[';
  REP(i, a.size()) {out<<a[i];if(i!=a.size()-1)out<<',';}
  out<<']';
  return out;
}

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

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

  int a, b;
  cin >> a >> b;
  cout << max({a+b, a-b, a*b}) << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <string>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <numeric>
#include <queue>
using namespace std;
#define loop(i,N) for(ll (i)=0; (i)<(N);++(i))
struct TEMP_OMAZINAI_ { TEMP_OMAZINAI_() { std::ios::sync_with_stdio(false); std::cin.tie(0); } } TEMP__omazinai_instance__;
#define INF ((1LL<<61) + (1<<29))
#define YesNo(x) {std::cout << ((x)?"Yes":"No") << std::endl;}
#define YESNO(x) {std::cout << ((x)?"YES":"NO") << std::endl;}
#define OddEven(x) {std::cout << ((x)%2?"Odd":"Even") << std::endl;}
#define ODDEVEN(x) {std::cout << ((x)%2?"ODD":"EVEN") << std::endl;}
typedef long long int ll;
ll my_gcd(ll a, ll b) { return b ? my_gcd(b, a%b) : a; };
void TEMP_INPUT_IMPL_() {};
template <class T, class... Args> void TEMP_INPUT_IMPL_(T& dest, Args&... args) { cin >> dest; TEMP_INPUT_IMPL_(args...); }
void TEMP_OUTPUT_IMPL_() {};
template <class T, class... Args> void TEMP_OUTPUT_IMPL_(T dest, Args... args) { cout << dest << (sizeof...(Args) ? " " : ""); TEMP_OUTPUT_IMPL_(args...); }
#define in(type, ...) type __VA_ARGS__; TEMP_INPUT_IMPL_(__VA_ARGS__)
#define in_v(type, name, cnt) vector<type> name(cnt); loop(i, cnt) cin >> name[i];
#define sort_v(v) std::sort(v.begin(), v.end())
#define unique_v(v) v.erase(std::unique(v.begin(), v.end()), v.end()) //必ずソート後に実行
#define out(...) (TEMP_OUTPUT_IMPL_(__VA_ARGS__), std::cout<<std::endl)
#define set_fix(x) ((std::cerr<<std::fixed<<std::setprecision(x)),(std::cout<<std::fixed<<std::setprecision(x)))
//小さい方に寄る
#define space_op(x, y, a, b, c) ([](auto x_, auto y_, auto a_, auto b_, auto c_){if(x_<y_)return a_;if(x_>y_)return c_;return b_;}(x,y,a,b,c))
#define space_out(x, y, a, b, c) out(space_op(x, y, a, b, c))

// ^^^ Template ^^^ //


int main() {
	in(ll, N, C, K);
	in_v(ll, T, N);
	sort_v(T);
	ll cnt = 0, lim_t = -1, p_cnt = 0;
	loop(i, N) {
		if (lim_t == -1) {
			lim_t = T[i] + K;
			++p_cnt;
			//cerr << "first passenger: " << T[i] << "(lim_t = " << lim_t << ")" << endl;
		} else if(T[i] <= lim_t) {
			//cerr << p_cnt << "-th passenger: " << T[i] << endl;
			++p_cnt;
		} else {
			//cerr << "next-bus passenger: " << T[i] << endl;
			if(p_cnt) ++cnt;
			p_cnt = 1;
			lim_t = T[i] + K;
		}

		if (p_cnt == C) {
			//cerr << "bus is gone" << endl;
			++cnt;
			p_cnt = 0;
			lim_t = 0;
		}
	}
	if (p_cnt) ++cnt;
	cout << cnt << endl;
	return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout.precision(30);
#define ll long long
#define ld long double
#define pi 3.14159265359
using namespace std;

int main()
{
    IOS;
    ld a,b;
    cin>>a>>b;
    b*=1000;
    a=(a*b)/1000;
    cout<<(ll)a;
    return 0;
}


Measured memory_bytes: 3756
extern crate proconio;
use proconio::fastout;
use std::cmp::Ordering;

fn fifth(x: i64) -> i64 {
    x * x * x * x * x
}

#[fastout]
fn main() {
    proconio::input! {
        x: i64
    }
    for a in 0.. {
        for b in (0..).map(|x| a - x) {
            match (fifth(a) - fifth(b)).cmp(&x) {
                Ordering::Less => (),
                Ordering::Equal => {
                    println!("{} {}", a, b);
                    return;
                }
                Ordering::Greater => break,
            }
        }
    }
}


Measured memory_bytes: 2164
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define REP(i, n) for(int i = 0;i < (n);++i)
#define RREP(i, n) for(int i = (n)-1; i >= 0; --i)

#define endl '\n'
#define pb push_back
#define eb emplace_back
#define pque priority_queue
#define umap unordered_map
#define BIG 2000000000
#define VERYBIG 1000000000000000ll
#define PI 3.1415926
#define coutdb cout<<fixed<<setprecision(15)

const int dx[]={1,0,-1,0,1,1,-1,-1}, dy[]={0,-1,0,1,1,-1,1,-1};
const long long MOD = 1e9+7;

// typedef int_fast64_t ll;
#define int int_fast64_t

template<typename T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template<typename T> inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template<typename T> inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template<typename T> inline T nHr(T a,T b){return nCr(a+b-1,b);}

typedef pair<int, int> INTP;
typedef vector<int> INTV;
struct edge2 {int to, cost;};
struct edge3 {int from, to, cost;};

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

  int N, A[100000]; cin >> N;
  INTV ans(N);
  REP(i, N){
    cin >> A[i];
    ans[A[i]-1] = i+1;
  }
  REP(i, N) cout << ans[i] << ' ';
  cout << endl;
}

Measured memory_bytes: 2432
a,b,c,d = map(int,input().split())
acnt = 0
ccnt = 0
while a > 0:
    a -= d
    acnt += 1
    # print(a)
    # print(acnt)
while c > 0:
    c -= b
    ccnt +=1
    # print(c)
    # print(ccnt)
if acnt >= ccnt:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 9112
#include<bits/stdc++.h>
using namespace std;
typedef long long int64;
const int64 INF = 1LL << 58;

int main()
{
  int N, M, K, A[20000];
  int64 dp[20001];
  
  scanf("%d %d %d", &N, &M, &K);
  for(int i = 0; i < N; i++) {
    scanf("%d", &A[i]);
  }

  fill_n(dp, 20001, INF);
  dp[0] = 0;
  for(int i = 0; i < N; i++) {
    int small = A[i], large = A[i];
    for(int64 j = 0; j < min(M, N - i); j++) {
      small = min(small, A[i + j]);
      large = max(large, A[i + j]);
      dp[i + j + 1] = min(dp[i + j + 1], dp[i] + K + (j + 1) * (large - small));
    }
  }
  printf("%lld\n", dp[N]);
}

Measured memory_bytes: 1420
x,y,z,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
a = sorted(a)[::-1]
b = sorted(b)[::-1]
c = sorted(c)[::-1]
l = []
for i in range(x):
    for j in range(y):
        for m in range(z):
            if (i+1)*(j+1)*(m*1)>k:
                break
            l.append(a[i]+b[j]+c[m])
l = sorted(l)[::-1]
for i in range(k):
    print(l[i])

Measured memory_bytes: 73884
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);++i)
#define fi first
#define se second
#define INF 1000000009
#define lINF 1000000000000000009
typedef long long ll;

int main(){
  ll n;
  cin>>n;
  ll ans=lINF;
  for(ll i=1;i*i<=n;i++){
    if(n%i==0){
      ans=min(ans,i+n/i-2);
    }
  }
  cout<<ans<<endl;
  return(0);
}


Measured memory_bytes: 256
import sys
import math
from collections import Counter


l = raw_input().split()
c = Counter()
for i in l:
    c[i] += 1
cc = c.most_common(1)
ans = l[0]
for i in range(len(l)):
    if len(l[i]) > len(ans):
        ans = l[i]
print "{0} {1}".format(cc[0][0], ans)

Measured memory_bytes: 4676
#define GLIBCXX_DEBUG
#include<bits/stdc++.h>
#include<cassert>
using namespace std;

using ll = long long;
#define REP(i,n) for(int i = 0;i < n;i++)

/*
*	verified : http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=4711518#1
*	last revised : 7.28.2020
 */
template<class T> class RangeMinQuery {
private:
	vector<T> dat; int n; T INF;
public:
	RangeMinQuery(int n_) {
		INF = numeric_limits<T>::max();
		n = 1;
		while (n < n_) n *= 2;
		dat.assign(2 * n - 1, INF);
	}
	void update(int k, T a) {
		k += n - 1; dat[k] = a;
		while (k > 0) {
			k = (k - 1) / 2;
			dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]);
		}
	}
	T query(int a, int b, int k, int l, int r) {
		if (r <= a || b <= l)return INF;
		if (a <= l && r <= b)return dat[k];
		else {
			T vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
			T vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
			return min(vl, vr);
		}
	}
	T query(int a, int b) {
		assert(a < b);
		return query(a, b, 0, 0, n);
	}
};

int main() {
	int n; cin >> n;
	vector<int> a(n), pos(n + 1);
	REP(i, n)cin >> a[i];
	REP(i, n) pos[a[i]] = i;
	RangeMinQuery<int> odd(n), even(n);
	REP(i, n) {
		if (i % 2 == 0)even.update(i, a[i]);
		else odd.update(i, a[i]);
	}
	using P = pair<int, int>;
	priority_queue<pair<int, P>> q;
	q.push(make_pair(-even.query(0, n), make_pair(0, n)));
	vector<int> ans;
	while (q.size()) {
		auto e = q.top(); q.pop();
		int l = e.second.first;
		int r = e.second.second;
		// L , ... , Xi - 1, Xi , Xi+1 , ... , Yi - 1,Yi,Yi + 1, ... , R
		int x = -e.first;
		int xi = pos[x];
		int y = ((xi % 2 == 0) ? odd.query(xi + 1, r) : even.query(xi + 1, r));
		int yi = pos[y];
		ans.push_back(x);
		ans.push_back(y);
		if (l < xi) {
			assert(l < xi);
			int v0 = ((l % 2 == 0) ? even.query(l, xi) : odd.query(l, xi));
			q.push(make_pair(-v0, make_pair(l, xi)));
		}
		if (xi + 1 < yi) {
			assert(xi + 1 < yi);
			int v1 = ((xi + 1) % 2 == 0 ? even.query(xi + 1, yi) : odd.query(xi + 1, yi));
			q.push(make_pair(-v1, make_pair(xi + 1, yi)));
		}
		if (yi + 1 < r) {
			assert(yi + 1 < r);
			int v2 = ((yi + 1) % 2 == 0 ? even.query(yi + 1, r) : odd.query(yi + 1, r));
			q.push(make_pair(-v2, make_pair(yi + 1, r)));
		}
	}

	REP(i, n)cout << ans[i] << ' ';
	cout << '\n';
}


Measured memory_bytes: 10452
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		char[] ch = s.toCharArray();
		if (ch[0] != ch[1] && ch[1] != ch[2] && ch[0] != ch[2]) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 21844
from collections import deque

import sys
input = sys.stdin.readline

S = input().strip()

is_front = True # 最初は左向き
queue = deque(S)

Q = int(input())
for _ in range(Q):
    query = input().strip().split()
    if len(query) == 1:
        is_front = not is_front
    else:
        ti, fi, ci = query
        fi = int(fi)
        if is_front:
            if fi == 1:
                queue.appendleft(ci)
            else:
                queue.append(ci)
        else:
            if fi == 1:
                queue.append(ci)
            else:
                queue.appendleft(ci)

ans = "".join(queue)
if not is_front:
    ans = ans[::-1]
print(ans)

Measured memory_bytes: 72412
#include <stdio.h>
#define MOD (int)(1e9+7)

int n, a[100001];
long long int fuct[100002], fuct_i[100002];

long long int p(long long int n, int e) {
	if (e == 0)
		return 1;
	else if (e % 2 == 0) 
		return p((n * n) % MOD, e / 2);
	else
		return (n * p(n, e - 1)) % MOD;
}

long long int nCr(int n, int r) { return r > n ? 0 : fuct[n] * fuct_i[r] % MOD * fuct_i[n - r] % MOD; }

int main(void) {
	int i, tmp, lr;
	scanf("%d", &n);
	for (i = 0; i <= n; i++) a[i] = -1;
	for (i = 0; i <= n; i++) {
		scanf("%d", &tmp);
		if (a[tmp] == -1)
			a[tmp] = i;
		else {
			lr = a[tmp] + n - i;
			break;
		}
	}
	// 階乗と階乗の逆元を求める
	fuct[0] = 1;
	for (i = 1; i <= n + 1; i++) fuct[i] = fuct[i - 1] * i % MOD;
	fuct_i[n + 1] = p(fuct[n + 1], MOD - 2);	// フェルマーの小定理
	for (i = n; i >= 0; i--) fuct_i[i] = fuct_i[i + 1] * (i + 1) % MOD;

	for (i = 1; i <= n + 1; i++) 
		printf("%lld\n", (nCr(n + 1, i) - nCr(lr, i - 1) + MOD) % MOD);

	return 0;
}

Measured memory_bytes: 3072
import fractions
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)
a, b, c, d = map(int, input().split())
a -= 1
cnt0B = b // c + b // d - b // lcm(c, d)
cnt0A = a // c + a // d - a // lcm(c, d)

print(b - a - (cnt0B - cnt0A))

Measured memory_bytes: 66028
n,m,v,p = map(int, input().split())
a = list(map(int, input().split()))
a.sort(reverse=True)
tg = a[p-1]
l = p-1
r = n
biggest = 0
while l<r:
    x = (l+r)//2
    if a[p-1]-a[x]<=m:
        border = v*m-(n-x+p-1)*m
        biggest = sum([a[x]+m-a[j] for j in range(p-1,x)])
    else:
        r = x
        continue
    if border > biggest:
        r = x
    elif border <= biggest:
        l = x+1
print(l)

Measured memory_bytes: 14964
n, m = gets.split.map(&:to_i)
h = gets.split.map(&:to_i)
i = [true] * n

$<.each do |ab|
  a, b = ab.split.map { |_| _.to_i - 1 }
  i[a] = false if h[a] <= h[b]
  i[b] = false if h[a] >= h[b]
end

p i.count(true)


Measured memory_bytes: 22520
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
mod2 = 998244353
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    #根を返す
    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

#初期化
# uf = Unionfind(n)
n,m = inpl()
ab = [inpl() for i in range(m)][::-1]
uf = UnionFind(n)
res = [n*(n-1)//2]
if m == 1:
    print(*res)
    quit()
cnt = 0
for a,b in ab[:m-1]:
    cnt += 1
    na = uf.size(a-1)
    nb = uf.size(b-1)
    uf.union(a-1,b-1)
    ns = uf.size(b-1)
    if na + nb == ns:
        tt = res[-1] - (na*nb)
    else:
        tt = res[-1]
    # if ns == n:
    #     tt = 0
    res.append(tt)

for i in res[::-1]:
    print(i)
       
    

Measured memory_bytes: 136024
#include <bits/stdc++.h>
#define mset(a, b) memset(a, b, sizeof(a))
#define mcpy(a, b) memcpy(a, b, sizeof(a))
#define rg register
using namespace std;
typedef long long LL;
const int N = 55;
const int MOD = 1e9 + 7;

template <typename T> inline void read(T &AKNOI) {
	T x = 0, flag = 1;
	char ch = getchar();
	while (!isdigit(ch)) {
		if (ch == '-') flag = -1;
		ch = getchar();
	}
	while (isdigit(ch)) {
		x = x * 10 + ch - '0';
		ch = getchar();
	}
	AKNOI = flag * x;
}

int n, nn, a[N<<1];
int dp[N][N<<1][N<<1];

inline void Inc(int &x, int y) {
	x += y; if (x >= MOD) x -= MOD;
}

void init() {
	read(n); nn = n*2-1;
	for (int i=1;i<=nn;++i) {
		read(a[i]);
	}
	sort(a+1, a+nn+1);
}

void solve() {
	dp[n][1][0] = 1;
	for (int i=n-1;i>=1;--i) {
		int fl = (a[i] != a[i+1]), fr = (a[nn-i+1] != a[nn-i]);
		for (int l=0;l<=nn;++l) {
			for (int r=0;r<=nn-l;++r) {
				int x = dp[i+1][l][r];
				if (!x) continue;
				for (int j=1;j<=l+fl;++j) {
					Inc(dp[i][l+fl-j+1][r+fr+(j>1)], x);
				}
				for (int j=1;j<=r+fr;++j) {
					Inc(dp[i][l+fl+1][r+fr-j], x);
				}
			}
		}
	}
	int ans = 0;
	for (int l=0;l<=nn;++l) {
		for (int r=0;r<=nn-l;++r) {
			Inc(ans, dp[1][l][r]);
		}
	}
	printf("%d\n", ans);
}

int main() {
	init();
	solve();
	return 0;
}


Measured memory_bytes: 1536
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <functional>
#include <string>
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstring>
using namespace std;
#define U(v) cerr << #v << ": " << (v) << endl

int main() {
    int n;
    while (cin >> n) {
        vector<int> a(n);
        for (int& p : a) cin >> p;
        if (a[0]) {
            cout << -1 << endl;
            continue;
        }
        long long ct = 0;
        bool end = false;
        for (int i = 1; i < n; ++i) {
            int d = a[i] - a[i - 1];
            if (d > 1) {
                end = true;
                break;
            } else if (d == 1) {
            } else {
                ct += a[i - 1];
            }
        }
        ct += a.back();
        if (end)
            cout << -1 << endl;
        else
            cout << ct << endl;
    }
    return 0;
}


Measured memory_bytes: 1024
#pragma GCC optimize ("Ofast")
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i=(a); i<(int)(b); i++)
#define FORD(i, a, b) for (int i=a; i>(int)(b); i--)
#define PPC(x) __builtin_popcount(x)
#define pb push_back
#define ALL(x) (x).begin(), (x).end()
#define ft first
#define sd second
#ifdef DEBUG
#include "debug.h"
#else
#define dbg(...) 0
#endif
using namespace std;

const int maxN = 1 << 20;

int T[maxN];

void solve()
{
	int n, a, b, c;
	char d;
	scanf ("%c", &d);
	d++;
	printf("%c\n", d);
}

int main()
{
	int t;
	t = 1;//scanf ("%d", &t);
	while (t--)
		solve();
	return 0;	
}


Measured memory_bytes: 256
//50
#include<iostream>

using namespace std;

int main(){
  for(;;){
    double x[4],y[4];
    for(int i=0;i<4;i++){
      cin>>x[i]>>y[i];
      if(!cin)return 0;
    }
    cout<<(((x[1]-x[0])*(x[3]-x[2])+(y[1]-y[0])*(y[3]-y[2])!=0)?"NO":"YES")<<endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=100010;
const ll mod=1e9+7;


int main() {
  int a,b,c; cin >> a >> b >> c;
  if(a==b){ cout << c << endl; return 0;}
  if(b==c){ cout << a << endl; return 0;}
  if(a==c){ cout << b << endl; return 0;}
  return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast", "unroll-loops", "no-stack-protector")
#include <bits/stdc++.h>
#define pb push_back
#define MP make_pair
#define F first
#define S second
#define mem(x, y) memset((x), (y), sizeof(x))
#define loli ios::sync_with_stdio(0), cin.tie(0);
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<typename Ta, typename Tb>istream &operator>>(istream &in, pair<Ta, Tb> &p){ return in >> p.F >> p.S; }
template<typename Ta, typename Tb>ostream &operator<<(ostream &out, pair<Ta, Tb> &p){ return out << p.F << " " << p.S; }
template<typename T>void arr_print(T a, T b){ T i = a; for(cout << *i++; i != b; i++) cout << " " << *i; cout << "\n"; }
template<typename T>ostream &print(T a){ return cout << a << "\n"; }
template<typename T, typename... Args>ostream &print(T a, Args ...args){ cout << a << " "; return print(args...); }

//--------------------Main Code--------------------

int main() {loli
	int n, cnt[4] = {};
	string s;
	cin >> n;
	while(n--){
		cin >> s;
		switch(s[0]){
			case 'A':
				cnt[0]++;
				break;
			case 'W':
				cnt[1]++;
				break;
			case 'T':
				cnt[2]++;
				break;
			case 'R':
				cnt[3]++;
				break;
		}
	}
	cout << "AC x " << cnt[0] << "\n";
	cout << "WA x " << cnt[1] << "\n";
	cout << "TLE x " << cnt[2] << "\n";
	cout << "RE x " << cnt[3] << "\n";
}

Measured memory_bytes: 3664
#include<stdio.h>

int main()
{
    long int n,a[200010],i,ans[200010];

     for(i=0;i<200009;i++)
        ans[i] = 0;

    scanf("%ld",&n);

    for(i=0;i<n;i++)
    {
        scanf("%ld",&a[i]);
        ans[a[i]]++;
    }

    long int sum = 0; 

    for(i=0;i<200009;i++)
    {
        sum += (ans[i]*(ans[i]-1))/2;
    }

    for(i=0;i<n;i++)
    {
        printf("%ld\n",
            sum - (ans[a[i]]*(ans[a[i]]-1))/2 +((ans[a[i]]-2)*(ans[a[i]]-1))/2);
    }

    return 0;
}

Measured memory_bytes: 5632
while True :
    table = input().split(" ")
    
    a = int(table[0])
    znsi = table[1]
    b = int(table[2])
    
    if znsi == "?" :
        break
    
    if znsi == "+" :
        print(a + b)
    elif znsi == "-" :
        print(a - b)
    elif znsi == "*" :
        print(a * b)
    else :
        print(a // b)


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

int main(){
    int w,h,x,y,r;

    cin >> w >> h >> x >> y >> r;

    if (x-r >= 0 && x+r <= w && y-r >= 0 && y+r <= h){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 3096
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;


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

	int n, m, i, j, k, ans = 0, a, b, ct;
	cin >> n >> m >> k;
	vector<string> s(n);
	for (i = 0; i < n; i++) cin >> s[i];

	for (i = 0; i < (1 << n); i++) {
		for (j = 0; j < (1 << m); j++) {
			ct = 0;
			for (a = 0; a < n; a++) {
				if ((1 << a) & i) continue;
				for (b = 0; b < m; b++) {
					if ((1 << b) & j) continue;
					if (s[a][b] == '#') ct++;
				}
			}
			if (ct == k) ans++;
		}
	}
	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 3192
#include <iostream>
#include <algorithm>
using namespace std;
 
int main(){
	int N, M;
	cin >> N;
	int D[N];
	for(int i = 0; i < N; i++){
		cin >> D[i];
	}
	cin >> M;
	int T[M];
	for(int i = 0; i < M; i++){
		cin >> T[i];
	}
	sort(D, D + N);
	sort(T, T + M);
	int nowD = 0;
	int nowT = 0;
	while(nowD != N && nowT != M){
		if(D[nowD] < T[nowT]){
			nowD++;
		}else if(D[nowD] > T[nowT]){
			cout << "NO" << endl;
			return 0;
		}else{
			nowD++;
			nowT++;
		}
	}
	if(nowT == M){
		cout << "YES" << endl;
	}else{
		cout << "NO" << endl;
	}
}

Measured memory_bytes: 1792
import bisect
n = int(input())
li = list(map(int,input().split()))
li.sort()
#print(li)
count = 0
for i in range(1, max(li)+1):
    index = bisect.bisect_left(li, i)
    #print(n,index,n//2)
    if index == n//2:
        #print(index)
        count += 1
print(count)

Measured memory_bytes: 53064
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <complex>
#include <cstdio>
#include <string>
#include <vector>
#include <bitset>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>

#define isNum(a) (a >= '0' && a <= '9')
#define SP putchar(' ')
#define EL putchar('\n')
#define File(a) freopen(a ".in", "r", stdin), freopen(a ".out", "w", stdout)

template<class T>
void read(T&);
template<class T>
void write(const T&);

typedef long long ll;
typedef const long long & cll;
typedef const int & ci;
typedef std::pair<int, int> pii;
const int iinf = 2147483647;
const ll llinf = 9223372036854775807ll;
using std::min;
using std::max;
using std::abs;
using std::sort;

int main () {
  int a;
  read(a);
  for (int i = 1; i <= 9; ++i) {
    for (int j = 1; j <= 9; ++j) {
      if (i * j == a) {
        puts("Yes");
        return 0;
      }
    }
  }
  puts("No");
  return 0;
}

template<class T>
inline void read(T &Re) {
  T k = 0;
  char ch = getchar();
  int flag = 1;
  while (!isNum(ch)) {
    if (ch == '-') {
      flag = -1;
    }
    ch = getchar();
  }
  while (isNum(ch)) {
    k = (k << 1) + (k << 3) + ch - '0';
    ch = getchar();
  }
  Re = flag * k;
}
template<class T>
inline void write(const T &Wr) {
  if (Wr < 0) {
    putchar('-');
    write(-Wr);
  } else {
    if (Wr < 10) {
      putchar(Wr + '0');
    } else {
      write(Wr / 10);
      putchar((Wr % 10) + '0');
    }
  }
}


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

const int N = 200005; int parent[N]; int sz[N];

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

void unite(int a, int b) {
	a = find(a); b = find(b);
	if (a == b) return;
	if (sz[a] < sz[b]) swap(a, b);
	sz[a] += sz[b];
	parent[b] = a;
}

int main() {
    int n, m; cin >> n >> m; 
    for (int i = 0; i < N; i ++) parent[i] = i;
    for (int i = 0; i < N; i ++) sz[i] = 1;
    for (int i = 0; i < m; i ++) {
        int a, b; cin >> a >> b; a--; b--;
        unite(a, b);
    } int maxsz = sz[0]; for (int i = 0; i < n; i ++) maxsz = max(maxsz, sz[i]);
    cout << maxsz << endl;
}

Measured memory_bytes: 5180
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		int x = in.nextInt();
		int r = solve(x);
		System.out.println(r);
	}

	private static int solve(int x) {
		if (x == 2)
			return 2;
		int[] s = new int[10000];
		int sm = 1;
		s[0] = 2;
		for (int i = 3;; i++) {
			int j = 0;
			while (j < sm) {
				if (i % s[j] == 0)
					break;
				j++;
			}
			if (j == sm) {
				s[sm] = i;
				sm++;
				if (i >= x)
					return i;
			}
		}
	}
}

Measured memory_bytes: 21972
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll MOD = 1000000007;

#define vec              vector<int>
#define vecll            vector<ll>
#define vecd             vector<double>
#define vecst            vector<string>
#define vecb             vector<bool>
#define v2(v,n,m,init)   vector<vector<int>>  v(n, vector<int>(m, init))
#define vb2(v,n,m,init)  vector<vector<bool>> v(n, vector<bool>(m, init))
#define vll2(v,n,m,init) vector<vector<ll>>   v(n, vector<ll>(m, init))

#define rep(i,n)         for(ll i=(ll)0; i<(ll)n; i++)
#define REP(i,m,n)       for(ll i=(ll)m; i<(ll)n; i++)
#define arr(var, n)      vec var(n); rep(i,n){cin >> var[i];}
#define arrll(var, n)    vecll var(n); rep(i,n){cin >> var[i];}
#define arrst(var, n)    vecst var(n); rep(i,n){cin >> var[i];}
#define all(var)         (var).begin(), (var).end()
#define sortall(var)     sort(all(var))
#define uniqueall(v)     v.erase(unique(v.begin(), v.end()), v.end());
#define pb(var)          push_back(var)
#define prt(var)         cout << (var) << "\n"
#define prtd(n, var)     cout << fixed << setprecision(n) << (var) << "\n"
#define prtfill(n, var)  cout << setw(n) << setfill('0') << (var);
#define prt2(v1, v2)     cout << (v1) << " " << (v2) << "\n"
#define prt3(v1, v2, v3) cout << (v1) << " " << (v2) << " " << (v3) << "\n"
#define prtall(v)        rep(i,v.size()){cout<<v[i]<<(i!=v.size()-1?" ":"\n");}
template <typename T>
bool chmax(T &a, const T& b){if(a<b){a=b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T& b){if(a>b){a=b; return true;} return false;}
//------------------------------------------------------------------
class UnionFind{

public:
  int vertexNumber;
  vector<int> parents;

  UnionFind(int n){
    vertexNumber = n;
    parents.assign(n, -1);
  }
  ~UnionFind(){}

  int find(int x){
    if(parents[x]<0){return x;}
    else {return find(parents[x]);}
  }

  void unite(int x, int y){
    x = find(x);
    y = find(y);
    if(x==y){return;}

    if(parents[x]>parents[y]){
      int tmp = x;
      x = y;
      y = tmp;
    }

    parents[x] += parents[y];
    parents[y] = x;
  }

  int size(int x){return -parents[find(x)];}

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

  int count_roots(){
    int ct=0;
    for(int i=0; i<vertexNumber; i++){
      if(parents[i]<0){ct++;}
    }
    return ct;
  }
};

int main(void){
  int n, m;
  cin >> n >> m;
  vec a(m), b(m);
  rep(i,m){
    cin >> a[i] >> b[i];
    a[i]--; b[i]--;
  }

  int ans=0;
  rep(i,m){
    UnionFind uf(n);
    rep(j,m){
      if(i==j) continue;
      uf.unite(a[j], b[j]);
    }
    if(uf.size(a[i])!=n) ans++;
  }

  prt(ans);

}


Measured memory_bytes: 3592
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#define rep(i, a, b) for(int i = (a); i < (b); i++)
#define ill long long
#define fcout cout << fixed << setprecision(10)
using namespace std;

int main() {
  ill a;
  long double b;
  cin >> a >> b;
  ill c = a * b;
  cout << c;
}


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

struct cube {
	vector<string>v;
	int E = 0, S = 1, U = 2;
	void rotate(char C) {
		int a = E, b = S;
		switch (C) {
		case'E':E = U; U = 5 - a; break;
		case'S':S = U; U = 5 - b; break;
		case'L':E = S; S = 5 - a; break;
		}
	}
	bool operator==(cube b) {
		rep(i, 4){
			rep(j, 4) {
				rep(k, 4) {
					if (v[E] == b.v[b.E] && v[5 - E] == b.v[5 - b.E] && v[S] == b.v[b.S] && v[5 - S] == b.v[5 - b.S] && v[U] == b.v[b.U] && v[5 - U] == b.v[5 - b.U])return true;
					rotate('S');
				}
				rotate('E');
			}
			rotate('L');
		}
		return false;
	}
};
cube s[30];
bool used[30];
int main() {
	int n;
	while (cin >> n, n) {
		rep(i, n) {
			s[i].v = vector<string>(6);
			rep(j, 6)cin >> s[i].v[j];
		}
		vector<int>v[30];
		rep(i, n)for (int j = i + 1; j < n; j++) {
			if (s[i] == s[j]) {
				v[i].push_back(j);
			}
		}
		int cnt = 0;
		memset(used, 0, sizeof(used));
		rep(i, n) {
			if (used[i])continue;
			cnt++;
			for (int j : v[i])used[j] = true;
		}
		printf("%d\n", n - cnt);
	}
}

Measured memory_bytes: 3280
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr long long INFL = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;
using Graph = vector<vector<int>>;



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

    int H,W,h,w;
    cin >> H >> W >> h >> w;
    cout <<H*W-(h*W+H*w-h*w) << endl;



}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
#define pb push_back
#define ll long long
#define maxn 200005
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define ms(i) memset(i,0,sizeof(i));
#define ms1(i) memset(i,-1,sizeof(i));
#define F first
#define S second
const int mod = 998244353;
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin >> n;
	double sum = 0;
	f(n){
		double add;
		cin >> add;
		sum += 1.0/add;
	}
	cout <<fixed<<setprecision(10)<< 1/sum << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
const ll mod = 1000000007;
ll N, X;
vector<ll> S;
ll inv[1000000];
ll FactorialInv[1000000];
ll Factorial[1000000];
ll beki(ll a, ll b){
    if(b == 0){
        return 1;
    }
    ll ans = beki(a, b / 2);
    ans = ans * ans % mod;
    if(b % 2 == 1){
        ans = ans * a % mod;
    }
    return ans;
}
void init_combination(){
    inv[1] = 1;
    FactorialInv[1] = 1;
    Factorial[1] = 1;
    Factorial[0] = 1;
    for(int i = 2; i < 1000000; i++){
        inv[i] = beki(i, mod - 2);
        Factorial[i] = Factorial[i - 1] * i % mod;
        FactorialInv[i] = FactorialInv[i - 1] * inv[i] % mod;
    }
}
ll combination(ll a, ll b){
    if((a == b) || (b == 0)){
        return 1;
    }
    ll ans = Factorial[a] * FactorialInv[b] % mod;
    ans = ans * FactorialInv[a - b] % mod;
    return ans;
}

ll PREV[100050];
ll NEXT[100050];

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    init_combination();
    cin >> N >> X;
    for(int i = 0; i < N; i++) {
        ll in;
        cin >> in;
        S.push_back(in);
    }
    S.push_back(1000000);
    sort(S.begin(), S.end(), greater<ll>());
    PREV[X] = 1;
    for(int index = 1; index <= N; index++) {
        for(ll val = 0; val <= 100000; val++) NEXT[val] = 0;
        for(ll val = 0; val <= 100000; val++) {
            ll newval = val % S[index];
            NEXT[newval] = (NEXT[newval] + PREV[val]) % mod;
        }
        for(ll val = 0; val <= 100000; val++) {
            PREV[val] = PREV[val] * (N - index) % mod;
            PREV[val] += NEXT[val];
            PREV[val] %= mod;
        }
    }
    ll ans = 0;
    for(ll val = 0; val <= 100000; val++) {
        ans = (ans + val * PREV[val]) % mod;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 25344
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_10_C&lang=jp

//順番が問題でないときはまずソートしてみる


#include <iostream>
#include <vector>
#include <string>
#include <algorithm> // sort
#include <map> // pair

#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)

using namespace std;

const int MAX_N=100100;
const int MAX_M=100100;

int n,m;
int a,b;

int main()
{
    int res=0;
    cin>>n>>m;

    vector<pair<int, int> > pairs(m);

    rep(i,m)
    {
        cin>>a>>b;
        pairs[i]=make_pair(b,a);
    }

    sort(pairs.begin(), pairs.end());

    int tmp=pairs[0].first-1;
    res++;

    int i=1;
    while(i<m)
    {
        if(pairs[i].second>tmp)
        //直前の橋カットでは要求を満たさない場合
        {
            tmp=pairs[i].first-1;
            res++;
        }
        i++;
        // cout<<res<<"\n";

    }
    cout<<res<<"\n";


    return 0;
}

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

Measured memory_bytes: 256
input = input().split()
inputList = list(input[0])
# a = int(input[0])
# b = int(input[1])
# c = int(input[2])

inputList.sort()

flg = 1
for i in range(0, len(inputList)-1, 2):
    if inputList[i] != inputList[i + 1]:
        flg = 0
        break
    if inputList[1] == inputList[2]:
        flg = 0
        break

if flg == 0:
    print("No")
else:
    print("Yes")


Measured memory_bytes: 38256
#include <iostream>
#include <cctype>

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

   if(S[0]!='A'){
      std::cout << "WA" << std::endl;
      return 0;
   }
   int count = 0;
   for(int i=2; i<S.size()-1; ++i){
      if(S[i]=='C') ++count;
   }
   if(count!=1) {
      std::cout << "WA" << std::endl;
      return 0;
   }
   for(int i=1; i<S.size(); ++i){
      if(S[i]!='C' && std::isupper(S[i])){
	 std::cout << "WA" << std::endl;
	 return 0;
      }
   }
   std::cout << "AC" << std::endl;
   return 0;

}


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

signed main() {
  int n;
  string s;
  cin >> n >> s;

  vector<int> R, G, B;
  rep(i,n) {
    if(s[i] == 'R') R.push_back(i);
    if(s[i] == 'G') G.push_back(i);
    if(s[i] == 'B') B.push_back(i);
  }

  long long ans = 0;
  for (auto r : R) {
    for (auto g : G) {
      int x = -1, y = -1, z = -1;
      int mi = min(r,g);
      int ma = max(r,g);
      if((r + g)%2 == 0) x = (r + g)/2;
      y = ma + abs(r - g);
      z = mi - abs(r - g);
      int add = B.size();
      if(binary_search(B.begin(),B.end(),x)) add--;
      if(binary_search(B.begin(),B.end(),y)) add--;
      if(binary_search(B.begin(),B.end(),z)) add--;
      ans += add;
    }
  }

  cout << ans << '\n';

}

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

#define MAX 10000000

long long divisors[MAX + 1] = { 0, };
int n;
long long sum = 0;

int main() {
	cin >> n;

	memset(divisors, 0, sizeof(divisors));

	for (int i = 1; i <= MAX; i++) {
		for (int j = i; j <= MAX; j += i) {
			++divisors[j];
		}
	}
	
	for (int i = 1; i <= n; i++) {
		sum += divisors[i]*i;
	}

	cout << sum;
}

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

const int MAXN = 1e5 + 21;

int n;
long long h[MAXN];
long long dp[MAXN];

int main() {
  cin >> n;
  for (int i = 1; i <= n; i++)
  		cin >> h[i];
  dp[2] = abs(h[1] - h[2]);

  for (int i = 3; i <= n; i++)
  	dp[i] = min(dp[i - 1] + abs(h[i - 1] - h[i]), dp[i - 2] + abs(h[i - 2] - h[i]));  
  
  cout << dp[n] << '\n';
  return 0; 
}

Measured memory_bytes: 1792
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <cstdlib>

using namespace std;

class c_sort01
{
private:
   int n;
   int x[100];
   
public:
   void f_sort01();
};

void c_sort01::f_sort01()
{
    int i, j, k;
    int key;
    
    cin >> n;
    
    for ( i = 0; i < n; ++i){
        cin >> x[i];
    }
    
    for ( i = 1; i <= n; ++i){
        for ( k = 0; k < n; ++k){
            cout << x[k];
            if(k == n-1){
                cout << endl;
            }else{
                cout << " ";
            }
        }
        key = x[i];
        //cout << x[i] << endl;
        //cout << "i = "<< i << endl;
        j = i -1;
        //cout << "j = "<< j << endl;
        //cout << "x[j] = "<< x[j] << endl;
        //cout << "key = "<< key << endl;
        for (; j >= 0 && x[j] > key;){
            x[j+1] = x[j];
            j=j-1;
            //cout << j << endl;
        }
        x[j+1] = key;
    }
    
}

int main(){
    c_sort01 sort01;
    
    sort01.f_sort01();
    
    return 0;
}

Measured memory_bytes: 3060
#include <cstdio>
#include <algorithm>
using namespace std;

int main(){
	int n;
	scanf("%d", &n);
	int a[3];
	for (int i = 0; i < n; i++){
		scanf("%d %d %d", &a[0], &a[1], &a[2]);
		sort(a, a+3);
		if(a[0] * a[0] + a[1] * a[1] == a[2] * a[2]){
			printf("YES\n");
		}else{
			printf("NO\n");
		}
	}

	return 0;
}

Measured memory_bytes: 1028
from bisect import bisect_left,insort_left

#入力
D = int(input())
C = [int(c) for c in input().split()]
S = []
for _ in range(D):
    s = [int(x) for x in input().split()]
    S.append(s)
T = []
for _ in range(D):
    t = int(input()) - 1
    T.append(t)
    
#スコア計算
score = 0
last_day = [[-1] for _ in range(26)]
for d in range(D):
    test = T[d]
    score += S[d][test]
    last_day[test].append(d)
minus = [0] * 26
for i in range(26):
    last_day[i].append(D)
    l = last_day[i]
    for j in range(len(l)-1):
        dd = l[j+1] - l[j] - 1
        minus[i] += C[i] * (dd * (dd + 1)) // 2
    score -= minus[i]

M = int(input())
for _ in range(M):
    d,q = map(int,input().split())
    d -= 1
    q -= 1
    old = T[d]
    T[d] = q
    #日程dでの元のテストold
    l = last_day[old]
    ind_old = l.index(d)
    dd_left = l[ind_old] - l[ind_old-1] - 1
    dd_right = l[ind_old+1] - l[ind_old] - 1
    dd = l[ind_old+1] - l[ind_old-1] - 1
    dif_old = C[old] * (((dd_left * (dd_left + 1)) // 2) + ((dd_right * (dd_right + 1)) // 2) - ((dd * (dd + 1)) // 2))
    #日程dでのテストq
    l = last_day[q]
    ind_q = bisect_left(last_day[q],d)
    dd_left = d - l[ind_q-1] - 1
    dd_right = l[ind_q] - d - 1
    dd = l[ind_q] - l[ind_q-1] - 1
    dif_q = C[q] * (((dd * (dd + 1)) // 2) - ((dd_left * (dd_left + 1)) // 2) - ((dd_right * (dd_right + 1)) // 2))
    #新しいスコア
    score += (dif_old + dif_q - S[d][old] + S[d][q])
    #情報の更新
    minus[old] -= dif_old
    minus[q] -= dif_q
    del last_day[old][ind_old]
    last_day[q].insert(ind_q,d)
    print(score)

Measured memory_bytes: 77908
import math
from functools import reduce

K=int(input())

#関数定義(最大公約数)
def gcd(*numbers):
    return reduce(math.gcd, numbers)

sum=0

for a in range(1,K+1):
    for b in range(1,K+1):
        for c in range(1,K+1):
            sum+=(gcd(a, b, c))

print(sum)

Measured memory_bytes: 74824
#define _USE_MATH_DEFINES // for C++  
#include "bits/stdc++.h"
#define LL long long
#define NUM 1000000007

using namespace std;

int main()
{
    int n;
    cin >> n;
    set<char> s;
    for (size_t i = 0; i < n; i++)
    {
        char tmp;
        cin >> tmp;
        s.insert(tmp);
    }
    if (s.size() == 3)
    {
        cout << "Three" << endl;
    }
    else
    {
        cout << "Four" << endl;
    }
}

Measured memory_bytes: 256
#include <stdio.h>
#define MAX_N 200000
#define INF 10000000000000000LL

long long s[MAX_N];

long long min(long long p, long long q)
{
    return p < q? p: q;
}

long long abs(long long p)
{
    return p >= 0? p: -p;
}

int main(void)
{
    int n, a;
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%d", &a);
        s[i] = (long long)a;
        if (i != 0) s[i] += s[i - 1];
    }
    long long sum = s[n - 1];
    long long mini = abs(sum - 2LL * s[0]);
    for (int i = 1; i < n - 1; i++)
        mini = min(mini, abs(sum - 2LL * s[i]));
    printf("%lld\n", mini);
    return 0;
}


Measured memory_bytes: 1664