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

#define int long long

using namespace std;

const int N = 3010;
const int MOD = 1e9 + 7;

int n, m;
int f[N][N][2];

signed main() {
  scanf("%lld %lld", &n, &m);
  for (register int k = 1; k <= n; k++) f[0][k][0] = 1;
  f[0][0][1] = 1;
  for (register int k = 0; k < m; k++)
    for (register int i = 0; i <= n; i++) {
      f[k][i][0] %= MOD, f[k][i][1] %= MOD;
      if (i - 1 >= 0) {
        f[k + 1][i - 1][i == 1] += f[k][i][0];
        f[k + 1][i - 1][1] += f[k][i][1];
        f[k + 1][i][i == 1] += f[k][i][0];
        f[k + 1][i][1] += f[k][i][1];
      }
      if (i + 1 <= n) {
        f[k + 1][i + 1][0] += f[k][i][0];
        f[k + 1][i + 1][1] += f[k][i][1];
        f[k + 1][i][0] += f[k][i][0];
        f[k + 1][i][1] += f[k][i][1];
      }
    }
  int answ = 0;
  for (register int k = 0; k <= n; k++) answ += f[m][k][1], answ %= MOD;
  printf("%lld", answ);
  return 0;
}


Measured memory_bytes: 141568
#include<bits/stdc++.h>
using namespace std;
int N, t;
set<int>s;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> N;
	for (int i = 0; i < N; i++)
	{
		cin >> t;
		if (s.find(t) == s.end())
		{
			s.insert(t);
		}
		else
		{
			cout << "NO" << endl;
			return 0;
		}
	}
	cout << "YES" << endl;
	return 0;
}

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

int main(){
  int n;
  cin>>n;
  vector<ll> v={2,1};
  for(int i = 2;i<n+1;i++){
    v.push_back(v.at(i-2) + v.at(i-1));
  }
  cout << v.at(n) << endl;
}

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

const int64_t MOD = 1000000007;
typedef int64_t ll;
typedef uint64_t ull;

#define FOR(i, start, end) for(uint64_t i=start; i<end; i++)
#define REP(i, n) FOR(i, 0, n)

// 最大公約数gcd
// 最小公倍数lcm=m*n/gcd
uint64_t gcd(uint64_t m, uint64_t n) {
  uint64_t temp;
  while (m % n != 0){
    temp = n;
    n = m % n;
    m = temp;
  }
  return n;
}

uint64_t lcm(uint64_t m, uint64_t n) {
  return (m*n)/gcd(m,n);
}

// vector<vector<uint64_t> > v(n+1, vector<uint64_t>(n+1, 0))
// v[n][k]に組み合わせ数が入る。
void comb(vector<vector <uint64_t> > &v){
  for(uint64_t i = 0;i <v.size(); i++){
    v[i][0]=1;
    v[i][i]=1;
  }
  for(uint64_t k = 1;k <v.size();k++){
    for(uint64_t j = 1;j<k;j++){
      v[k][j]=(v[k-1][j-1]+v[k-1][j]);
    }
  }
}

// 掛け算オーバーフロー判定
bool is_product_overflow(uint64_t a, uint64_t b) {

	uint64_t prod = a * b;
	
	return (prod / b != a);
}

//素因数分解
void primeFactorization(uint64_t a, list<uint64_t> &factors){ //素因数分解を出力するプログラム
  long i,sq;
  if(a%2==0){ //偶数の場合
    factors.push_back(2);
    primeFactorization(a/2,factors); //2で割った値で再帰
    return;
  }
  sq = sqrt(a);
  for(i=3;i<=sq;i+=2){ //3以上√a以下の奇数の場合
	if(a%i==0){
	  factors.push_back(i);
      primeFactorization(a/i,factors); //割れた値で再帰
      return;
	}
  }
  //偶数でも3以上√a以下の奇数の場合でも割り切れない場合
  if(a!=1){ //aが1でないなら、a自身は素数
    factors.push_back(a);
  }
}

// フェルマーの小定理
// mod. m での a の逆元 a^{-1} を計算する
// (a/b)%m = a*movinv(b,m)%m  
int64_t modinv(int64_t a, int64_t m) {
    int64_t b = m, u = 1, v = 0;
    while (b) {
        int64_t t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

// 円周率
// M_PI

// #include <iomanip> // setprecisionを使用するのに必要
// cout << std::fixed << std::setprecision(15) << y << endl;

// 昇順
// priority_queue<int, vector<int>, greater<int> > queue;

// 降順ソート vector<int> v;
// sort(v.begin(),v.end(),greater<int>());

signed main() {
  ll n;
  cin >> n;

  if(n==1){
    cout << "0" << endl;
    return 0;
  }
  
  ll ans = 1;
  for(int i=0;i<n;i++){
    ans *= 10;
    ans %= MOD;
  }
  ll ans2 = 1;
  for(int i=0;i<n;i++){
    ans2 *= 9;
    ans2 %= MOD;
  }
  ans2 *= 2;
  ans %= MOD;
  
  ll ans3 = 1;
  for(int i=0;i<n;i++){
    ans3 *= 8;
    ans3 %= MOD;
  }
  ans3 %= MOD;
  
  ans2 -= ans3;
  while(ans2<0) ans2 += MOD;


  ans -= ans2;
  while(ans<0) ans += MOD;
  ans %= MOD;
  

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



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

typedef long long ll;
const int INF = 1e9;
const int S = 3e5;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	
	int n;
	cin>>n;
	vector<ll> count(S, 0);
	vector<ll> ans(S);
	vector<int> nums(n);
	ll total = 0;
	for (int i = 0; i < n; i++) {
		cin>>nums[i];
		count[nums[i]]++;
	}
	for (int i = 0; i < S; i++) {
		ans[i] = count[i]*(count[i]-1)/2;
		total += ans[i];
	}
	for (int i = 0; i < n; i++) {
		cout<<total-count[nums[i]] + 1<<'\n';
	}
	return 0;
}

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

int main() {
  string o, e;
  cin >> o >> e;
  rep(i, o.size() + e.size()) {
    if (i % 2 == 0) {
      cout << o[i / 2];
    }
    else {
      cout << e[i / 2];
    }
  }
  cout << endl;
  return 0;
}

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

#include <boost/range/adaptors.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;
using namespace boost::adaptors;

int main() {
    int64_t a, b;
    cin >> a >> b;

    vector<vector<bool>> ans;

    for (auto _ : irange(0L, max(0L, (a - 2)) / 50)) {
        ans.resize(ans.size() + 2, vector<bool>(100L, true));
        for (auto j : irange(0L, 50L)) {
            ans[ans.size() - 2][2 * j] = false;
        }
    }

    ans.resize(ans.size() + 2, vector<bool>(100L, true));
    auto d = a == 1 ? 0 : ((a - 2) % 50L + 1);
    for (auto j : irange(0L, d)) {
        ans[ans.size() - 2][2 * j] = false;
    }

    ans.resize(ans.size() + 1, vector<bool>(100L));

    for (auto _ : irange(0L, max(0L, (b - 2)) / 50)) {
        ans.resize(ans.size() + 2, vector<bool>(100L));
        for (auto j : irange(0L, 50L)) {
            ans[ans.size() - 2][2 * j] = true;
        }
    }

    ans.resize(ans.size() + 2, vector<bool>(100L));
    auto e = b == 1 ? 0 : ((b - 2) % 50L + 1);
    for (auto j : irange(0L, e)) {
        ans[ans.size() - 2][2 * j] = true;
    }

    cout << ans.size() << " " << ans[0].size() << endl;
    for (const auto& line : ans) {
        for (auto b : line) {
            if (b) {
                cout << '#';
            } else {
                cout << '.';
            }
        }

        cout << "\n";
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define endl "\n"
#define pb push_back
#define f(i,n) for(i=0;i<n;i++)
#define F(i,a,b) for(i=a;a<=b;i++)
#define arr(a,n) for( i=0;i<n;i++)cin>>a[i];
#define fi first
#define se second
#define mp make_pair
#define mod 1000000007
#define YES cout<<"YES"<<endl;
#define Yes cout<<"Yes"<<endl;
#define NO cout<<"NO"<<endl;
#define No cout<<"No"<<endl;
#define yes cout<<"yes"<<endl;
#define no cout<<"no"<<endl;
#define vi vector<ll>
#define ed end()
#define bg begin()
#define sz size()
#define ln length()
#define s() sort(a,a+n);
#define sr() sort(a,a+n,greater<ll>());
#define v()  sort(v.begin(),v.end());
#define vr() sort(v.begin(),v.end(),greater<ll>());
#define mod 1000000007
#define fast() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);}
ll power(ll x,ll y,ll p){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
int main() {
/*    #ifndef ONLINE_JUDGE
      // for getting input from input.txt
      freopen("input.txt", "r", stdin);
      // for writing output to output.txt
      freopen("output.txt", "w", stdout);
  #endif*/
fast();
//ll  t;cin>>t;while(t--)
{
  ll a,h;
  cin>>h>>a;
  cout<<ceil(h/float(a));
  
  
  

}
return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>//brute force forever
using namespace std;
#define ll                      long long int
#define pb                      push_back
#define pob						pop_back
#define pii						pair<int,int>
#define pll						pair<ll,ll>
#define FOR(i,n)                for(int i=0;i<n;i++)
#define FORE(i,a,b)             for(int i=a;i<=b;i++)
#define RFOR(i,n)               for(int i=n;i>0;i--)
#define RFORE(i,a,b)            for(int i=a;i>=b;i--)
#define mp                      make_pair
#define all(x)                  x.begin(),x.end()
#define rall(x)                 x.rbegin(),x.rend()
#define ff                      first
#define ss                      second
#define endl                    "\n"
#define MOD                     998244353
#define MAXN					300005
#define INFI					1000000000
#define ub(x)					upper_bound(x)
#define lb(x)					lower_bound(x)

void FIO(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
}

void printarr(int arr[],int start,int size){
	for(int i=start;i<size;i++){
		cout<<arr[i]<<" ";
	}
}

void debug(int x){
	cout<<x<<endl;
}

int main(){
    FIO();
    int t;
    t=1;
    //cin>>t;
    while(t--){
		int k;
		cin>>k;
		for(int i=0;i<k;i++){
			cout<<"ACL";
		}
		
    }
 	return 0;
}


Measured memory_bytes: 3640
import math


A, B, C, D = [int(_) for _ in input().split()]
X = C * D // math.gcd(C, D)
# print(X)


def f(n):
    c = n // C
    d = n // D
    x = n // X
    res = n - c - d + x
    # print(f"{n}, {c}, {d}, {x} = {res}")
    return res


ans = f(B) - f(A) + 1
if A % C == 0 or A % D == 0:
    ans -= 1

print(ans)


Measured memory_bytes: 9112
#include <iostream>
#include <string>
#include <vector> 
#include <algorithm>
#include <cmath>
#include <map>
#include <numeric>
#include <queue>
using namespace std;
typedef long long ll;

int main(){
   int n,m;cin>>n>>m;
   vector<pair<ll,ll> > v(n);
   for(int i=0;i<n;i++)cin>>v[i].first>>v[i].second;
   sort(v.begin(),v.end());
   ll ans=0;
   for(int i=0;i<n;i++){
       if(m>=v[i].second)ans+=v[i].first*v[i].second;
       else {ans+=m*v[i].first;break;}
       m-=v[i].second;
   }
   cout<<ans;
}

Measured memory_bytes: 1792
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc =new Scanner (System.in);
        while(sc.hasNext()){
        	double a=sc.nextInt();
            double b=sc.nextInt();
            double c=sc.nextInt();
            double d=sc.nextInt();
            double e=sc.nextInt();
            double f=sc.nextInt();
            double y=(c*d-a*f)/(b*d-a*e);
            double x=(c-b*y)/a;
 
            System.out.printf("%.3f %.3f\n",x,y);
            }
        }
}

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

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

    vector<int> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A.at(i);
    }

    //求めたい数
    int ans = 0;
    for (int i = 0; i < (N-1); i++) {
        for (int j = i + 1; j < N; j++) {
            int dif = abs(A.at(i) - A.at(j));
            if (ans < dif) {
                ans = dif;
            }
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<iostream>

using namespace std;

int main(void){

    string str;
    cin >> str;
    int i,t;
    int num_size = str.size();
    bool judge = true;

    for( i=0 ; i < (num_size/2) ; i++){
        if(str[i] != str[ (num_size - 1) - i]){
        judge = false;
        }
    }

    for( i=0 ; i < ((num_size - 1)/2); i++){
        //cout << "C1\n";
        //cout << i << ":";
        //cout << str[i] << "=";
        //cout << str[ (num_size - 1)/2 - 1 - i ] << "\n";
        if(str[i] != str[ ((num_size - 1)/2) - 1 - i ]){
        judge = false;
        }
    }

    t = 0;
    for( i= (num_size + 3)/2 - 1; i < num_size; i++){
        //cout << "C2\n";
        //cout << i << ":";
        //cout << str[i] << "=";
        //cout << str[ (num_size) - 1 - t] << "\n";
    
        if (str[i] != str[ (num_size) - 1 - t])
        {
        judge = false;
        }
        t++;
    }

    if(judge == true){
        cout << "Yes";
    } else {
        cout << "No";
    }


    return 0;
}

Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Joy
 */

#include <bits/stdc++.h>
#define REP(i, N) for (int i = 0; i < (N); ++i)
#define ALL(x) (x).begin(), (x).end()
#define MOD 1000000007
#define PB push_back
#define MP make_pair
using namespace std;
typedef long long ll;
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }

class ABiscuitGenerator {
public:
	void solve(std::istream& in, std::ostream& out) {
        int A, B, T;
        in >> A >> B >> T;
        int ans = 0;
        for (int i = 1; i * A <= T; i++) {
            ans += B;
        }
        out << ans << '\n';
	}
};


int main() {
	ABiscuitGenerator solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
S=list(input())
f=10*int(S[0])+ int(S[1])
l=10*int(S[2])+int(S[3])
if 1<=f<=12 and 1<=l<=12:
  print('AMBIGUOUS')
elif (f>=13 or f==0) and 1<=l<=12:
  print('YYMM')
elif 1<=f<=12 and (l>=13 or l==0):
  print('MMYY')
else:
  print('NA')



Measured memory_bytes: 3060
/*
ID:greenty2
LANG:C++
TASK:
*/
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long LL;
bool cmp(int x,int y)
{
	return x>y;
}
int a[100005];
long long b[100005];
int main()
{
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
	}
	sort(a+1,a+n+1,cmp);
	int num =0 ;
	int pre =1;
	int tot = 1;
	for(int i=2;i<=n;i++)
	{
		if(a[i]!=a[i-1])
		{
		//	cout<<i<<" "<<a[i]<<" "<<a[i-1]<<" "<<tot<<endl;
			if(tot>=4)
			{
				num++;
				b[num] = a[i-1];
				num++;
				b[num] = a[i-1];
			}
			else if(tot>=2)
			{
				num++;
				b[num] = a[i-1];
			}
			tot =1;
		}
		else
		{
			tot++;
		}
	}
	if(tot>=4)
			{
				num++;
				b[num] = a[n];
				num++;
				b[num] = a[n];
			}
			else if(tot>=2)
			{
				num++;
				b[num] = a[n];
			}
	long long ans = b[1]*b[2];
	cout<<ans<<endl;
}

Measured memory_bytes: 896
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;


int main(void){
  int n,m,i,j,k,f[35]={},a,ans=0;
  
  cin >> n >> m;
  for (i=0;i<n;i++){
    cin >> k;
    for (j=0;j<k;j++){
      cin >> a;
      f[a]++;
    }
  }
  
  for (i=1;i<=m;i++){
    if (f[i]==n) ans++;
  }
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 256
//
//  main.cpp
//  Contests
//
//  Created by Roman Nikitin on 09.06.17.
//  Copyright © 2017 NikRom. All rights reserved.
//

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <cassert>
#include <map>
#include <set>
#include <numeric>
#include <queue>
#include <chrono>
#include <functional>

using namespace std;

#define int long long
#define len(v) (int)v.size()
#define pb push_back
#define x first
#define y second

typedef long long ll;

namespace ConvenientStream {
    
    void useFiles(string s) {
        freopen((s + ".in").c_str(), "r", stdin);
        freopen((s + ".out").c_str(), "w", stdout);
    }
    
    template <class T_First, class T_Second>
    ostream& operator<<(ostream& os, const pair<T_First, T_Second> &p) {
        os << p.first << " " << p.second;
        return os;
    }
    
    template <class T>
    ostream& operator<<(ostream& os, const vector<T> &v) {
        if (v.empty())
            return os;
        for (int i = 0; i < len(v) - 1; i++) {
            os << v[i] << " ";
        }
        os << v[len(v) - 1];
        return os;
    }
    
    template <class T>
    ostream& operator<<(ostream& os, const vector<vector<T>> &v) {
        if (v.empty())
            return os;
        for (int i = 0; i < len(v) - 1; i++) {
            os << v[i];
            os << endl;
        }
        os << v[len(v) - 1];
        return os;
    }
    
    
    template <class T_First, class T_Second>
    istream& operator>>(istream& is, pair<T_First, T_Second> &p) {
        is >> p.first >> p.second;
        return is;
    }
    
    template <class T>
    istream& operator>>(istream& is, vector<T> &v) {
        for (auto &x : v) {
            is >> x;
        }
        return is;
    }
    
    template<class T>
    istream &operator,(istream &is, T &obj) {
        is >> obj;
        return is;
    }
    
    template<class T>
    ostream &operator,(ostream &os, const T &obj) {
        return (os << obj);
    }
    
    const string nl = "\n";
    const string sp = " ";
    const string tb = "\t";
}

using namespace ConvenientStream;

void time_debug(function<void()> &f) {
    auto start_time = chrono::high_resolution_clock::now();
    f();
    auto end_time = chrono::high_resolution_clock::now();
    auto delta = chrono::duration_cast<chrono::milliseconds>(end_time - start_time);
    cout << "TIME: " << delta.count() << " ms" << endl;
}

int d1[500005];
int d2[500005];


signed main() {
    
    int n, a, b, c, d;
    cin >> n, a, b, c, d;
    
//    int max_min_pos = min_pos - (n - i) * c;
//    int min_min_pos = min_pos + (n - i) * d;
//    int max_max_pos = max_pos - (n - i) * c;
//    int min_max_pos = max_pos + (n - i) * d;

    for (int i = 0; i < n; i++) {
        int min_pos = a + i * c;
        int max_pos = a + i * d;
        int nmax_pos = max_pos - (n - i - 1) * c;
        int nmin_pos = min_pos - (n - i - 1) * d;
        if (b <= nmax_pos && b >= nmin_pos) {
            cout << "YES";
            exit(0);
        }
    }
    
    cout << "NO";
    
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void) {
    int n, p[50], i, ct;
    scanf("%d",&n);
    for(i = 0; i < n; i++) {
        scanf("%d",&ct);
        p[i] = ct;
    }
    ct = 0;
    for(i = 0; i < n; i++) {
        if(p[i] != i+1) {ct ++;}
    }
    if(ct <= 2) {
        printf("YES\n");
    } else {
        printf("NO\n");
    }
    return 0;

}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	cin>>s;
	for(int i=0;i<s.length();i++)
	{
		if(s[i]=='C')
		{
			for(int j=i+1;j<s.length();j++)
			{
				if(s[j]=='F') 
				{
					cout<<"Yes";
					return 0;
				}
			}
		}
	}
	cout<<"No";
	return 0;
	return 0;
}

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

int main(){
  int N,ans = 0,c = 0;
  cin >> N;
  vector<int> a(N);
  for(int i = 0;i < N;i++){
    cin >> a.at(i);
  }
  sort(a.begin(), a.end());
  for(int i = 0;i < a.size();i++){
    if(c != a.at(i)){
      ans++;
      c = a.at(i);
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
fn read<T: std::str::FromStr>(
    stdin_lock: &mut std::io::StdinLock,
    buf: &mut Vec<u8>,
    delimiter: u8,
) -> T {
    buf.clear();
    let l = std::io::BufRead::read_until(stdin_lock, delimiter, buf).unwrap();
    buf.truncate(l - 1); // remove delimiter
    let s = unsafe { std::str::from_utf8_unchecked(&buf) };
    s.parse().unwrap_or_else(|_| panic!("read"))
}

fn main() {
    let stdin = std::io::stdin();
    let mut stdin_lock = stdin.lock();
    let mut buf: Vec<u8> = Vec::new();
    let n: i32 = read(&mut stdin_lock, &mut buf, b'\n');
    let mut m: i32 = n;
    let mut sn: i32 = 0;
    while m > 0 {
        sn += m % 10;
        m /= 10;
    }
    let ans = if n % sn == 0 { "Yes" } else { "No" };
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <iostream>
#include <cstdio>
#include <vector>
#include <iomanip>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
using namespace std;

int main() {
    long long A;
    long long B;
    long long N;

    cin >> A >> B >> N;
    // x = k*B + m
    // floor (Am/B)
    N = min(N, B-1);

    cout << (A*N) / B << endl;

    return 0;
}

Measured memory_bytes: 3644
from collections import Counter
n = int(input())
a = Counter(map(int, input().split()))
x = [0, 0]
for i in a.keys():
    if a[i] >= 2:
        x.append(i)
    if a[i] >= 4:
        x.append(i)
x.sort(reverse=True)
print(x[0] * x[1])

Measured memory_bytes: 24224
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<math.h>
using namespace std;
#define mod (1000000000+7)
#define N (10007)
#define INF 1e16
typedef long long ll;
typedef pair<ll,ll> P;


int main(void){
	int m,n1,n2;
	while(true){
		cin>>m>>n1>>n2;
		if(m==0 && n1==0 && n2==0)break;
		vector<int>p(m);
		for(int i=0;i<m;i++)cin>>p[i];
		sort(p.begin(),p.end(),greater<int>());
		int ans=0,index=-1;
		for(int i=n1-1;i<n2;i++){
			if(p[i]-p[i+1]>=ans){
				ans=p[i]-p[i+1];
				index=i;
			}
		}
		cout<<index+1<<endl;
	}
    return 0;
}


Measured memory_bytes: 3064
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const ll N=2e5+5;
ll n,d,a[105];
multiset<ll> st;
int main(){
    ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    ll n;cin>>n;
    string s,t;cin>>s>>t;

    ll f1=0,f2=0;
    for(ll len=1;len<=n;len++){
        if(s.substr(n-len) == t.substr(0,len))f1=len;
        if(t.substr(n-len) == s.substr(0,len))f2=len;
    }

    if(f1<f2)swap(f1,f2) , swap(s,t);

    string ans = s + t.substr(f1);
    cout<<ans.size();
}



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

const int MAX_N = 100000;

main() {
  long long N, A, B, X[MAX_N], ans = 0;
  cin >> N >> A >> B;
  REP(i, N) cin >> X[i];
  REP(i, N - 1) {
    if ((X[i + 1] - X[i]) * A <= 0) {
      ans += B;
      continue;
    }
    ans += min((X[i + 1] - X[i]) * A, B);
  }
  cout << ans << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define REP(i,s,e) for(int i=(s); i<(e);i++)
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n)
#define repe(i,n) for(auto &&i:n)
#define all(v) (v).begin(),(v).end()
#define decimal fixed<<setprecision(20)
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
using namespace std;
using LL = long long;
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 int INF = 1e9;
const LL LLINF = 1e16;

int main(){
    int n, k;
    cin >> n >> k;
    LL ans = 0;
    LL tmp = 0;
    tmp = n/k;
    ans += tmp*tmp*tmp;
    if(k%2 == 0){
         tmp = (n+k/2)/k;
        ans += tmp*tmp*tmp;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
N, M = map(int, input().split())

A = [-1 for _ in range(N + 1)]

def search(ls, n):
  while ls[n] > 0:
    n = ls[n]
  return n

for i in range(M):
  a, b = map(int, input().split())
  aa = search(A, a)
  bb = search(A, b)
  if aa != bb:
    A[b] = aa
    A[bb] = aa
    
group = -1
for i in range(1, N + 1):
  if A[i] == -1:
    group += 1
    
print(group)
  

Measured memory_bytes: 73240
MOD = 10**9 + 7

class Combination:
    def __init__(self, size):
        self.size = size + 2

        f = 1
        self.fact = fact = [f]
        for i in range(1, size+1):
            f = f * i % MOD
            fact.append(f)
        f = pow(f, MOD-2, MOD)
        self.factInv = factInv = [f]
        for i in range(size, 0, -1):
            f = f * i % MOD
            factInv.append(f)
        factInv.reverse()

    def npr(self, n, r):
        if n < r or n < 0 or r < 0:
            return 0
        return self.fact[n] * self.factInv[n - r] % MOD

    def ncr(self, n, r):
        if n < r or n < 0 or r < 0:
            return 0
        return self.fact[n] * (self.factInv[r] * self.factInv[n - r] % MOD) % MOD

    def nhr(self, n, r):  # 重複組合せ: x_1 + ... + x_n = r
        return self.ncr(n + r - 1, n - 1)

K = int(input())
S = input()
N = len(S)

comb = Combination(N + K + 100)

ans = 0
L = 1
R = pow(26, K, MOD)
inv26 = pow(26, MOD - 2, MOD)
for l in range(K + 1):
    ans += L * comb.nhr(N, l) * R
    ans %= MOD

    L = L * 25 % MOD
    R = R * inv26 % MOD

print(ans)


Measured memory_bytes: 169824
import sys
from scipy.sparse.csgraph import floyd_warshall as wf
input = sys.stdin.readline

def main():
  H, W = map(int, input().split())
  link = [list(map(int, input().split())) for i in range(10)]
  a = [list(map(int, input().split())) for i in range(H)]
  
  link = wf(link)
  
  ans = 0
  for i in range(H):
    for j in range(W):
      if a[i][j] != -1:
        ans += link[a[i][j]][1]
  print(int(ans))

if __name__ == "__main__":
  main()

Measured memory_bytes: 25992
#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma comment(linker, "/stack:200000000")

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;

#define X first
#define Y second

//#include <boost/unordered_map.hpp>
//using namespace boost;

/*
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> rbtree;
rbtree T;
*/

using i32 = int;
using i64 = long long;
using u8 = unsigned char;
using u32 = unsigned;
using u64 = unsigned long long;
using f64 = double;
using f80 = long double;
//using i128 = __int128_t;
//using u128 = __uint128_t;
using i128 = i64;
using u128 = u64;

ll power(ll a, ll b, ll p)
{
	if (!b) return 1;
	ll t = power(a, b/2, p);
	t = t*t%p;
	if (b&1) t = t*a%p;
	return t;
}

ll exgcd(ll a, ll b, ll &x, ll &y)
{
	if (b == 0)
	{
		x = 1;
		y = 0;
		return a;
	}
	ll px, py;
	ll d = exgcd(b, a%b, px, py);
	x = py;
	y = px-a/b*py;
	return d;
}

template<class T>
inline void freshmin(T &a, const T &b)
{
	if (a > b) a = b;
}

template<class T>
inline void freshmax(T &a, const T &b)
{
	if (a < b) a = b;
}

//#define getchar getchar_unlocked
//#define putchar putchar_unlocked

int inp() {
	int x = 0, f = 0; char ch;
	for(ch = getchar(); !isdigit(ch); ch = getchar())
		if(ch == '-') f = 1;
	for(; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
	return f ? -x : x;
}

ll inp_ll() {
	ll x = 0; int f = 0; char ch;
	for(ch = getchar(); !isdigit(ch); ch = getchar())
		if(ch == '-') f = 1;
	for(; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
	return f ? -x : x;
}

template<class T>
bool read(T &x)
{
	x = 0;
	char ch = getchar();
	if (ch == EOF) return 0;
	for(; !isdigit(ch); )
	{
		ch = getchar();
		if (ch == EOF) return 0;
	}
	for(; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
	return 1;
}

template<class T>
void write(T x)
{
	static char s[22];
	static char *it = s+20;
	static char *end = s+20;
	if (!x)
		*-- it = '0';
	while (x)
	{
		*-- it = x%10+'0';
		x /= 10;
	}
	for (; it < end; ++ it)
		putchar(*it);
}

template<class T>
void writeln(T x)
{
	write(x);
	putchar('\n');
}

const int MOD = 1000000007;
const int INF = 100000000;
const int MAXN = 200010;
const int MAXV = 500510;
const int K = 3;
const f80 eps = 1e-10;
const f64 alpha = 0.75;

int n, k;
vector<int> v[MAXN];

ll ans;

void dfs(int x, int p)
{
	int sons = 0;
	for (auto y : v[x])
	{
		if (y == p) continue;
		sons ++;
		dfs(y, x);
	}
	if (p == 0)
	{
		for (int i = 1; i <= sons; ++ i)
			ans = ans*(k-i)%MOD;
	}
	else
	{
		for (int i = 1; i <= sons; ++ i)
			ans = ans*(k-i-1)%MOD;
	}
}

int main()
{
	
	cin >> n >> k;
	for (int i = 1; i < n; ++ i)
	{
		int x, y;
		cin >> x >> y;
		v[x].push_back(y);
		v[y].push_back(x);
	}
	ans = k;
	dfs(1, 0);
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 10368
#include <bits/stdc++.h>
using namespace std;
#define X first
#define Y second
#define PB push_back
#define ll long long
#define pii pair<LL,LL>
#define MEM(x,y) memset(x,y,sizeof(x))
#define bug(x) cout<<"debug "#x" is "<<x<<endl;
#define FIO ios::sync_with_stdio(false);
#define ALL(x) x.begin(),x.end()
#define LOG 20
#define lson(x) ((x)<<1)
#define rson(x) ((x)<<1|1)
const int maxn=2e5+10;
int n,m,p;
int x[maxn],y[maxn],a[maxn],b[maxn],c,ans=1e9;
int main()
{
	FIO
	cin>>n>>m>>p;
	for(int i=0;i<n;i++)
		cin>>x[i];
	for(int i=0;i<m;i++)
		cin>>y[i];
	for(int i=0;i<p;i++)
	{
		cin>>a[i]>>b[i]>>c;
		a[i]--,b[i]--;
		ans=min(ans,x[a[i]]+y[b[i]]-c);
	}
	sort(x,x+n);
	sort(y,y+m);
	ans=min(ans,x[0]+y[0]);
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 1792
N = int(input())
h_list = list(map(int, input().split()))
dp = [float('INF') for i in range(N)]
dp[0] = 0

def calc_cost(now, next):
  global h_list
  global dp
  global N
  if next > N - 1: return
  if dp[next] > dp[now] + abs(h_list[next] - h_list[now]):
    dp[next] = dp[now] + abs(h_list[next] - h_list[now])

for i in range(N):
  calc_cost(i, i + 1)
  calc_cost(i, i + 2)

print(dp[N - 1])

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

int main(){
  int N;
  cin >> N;
  vector<int> a(N);
  rep(i,N){
    cin >> a[i];
  }

  int count = 0;
  bool flag = true;
    
  while(flag == true){
    rep(i,N){
    	if(a[i]%2 == 0){
      		a[i] = a[i]/2;
        }
      	else {
          flag = false;
          break ;
        }
    }
    if(flag == false) break;
    count++;
  }
  
  cout << count << endl;
  
  return 0;
}


Measured memory_bytes: 3632
N, M, V, P = map(int, input().split())
A = list(map(int, input().split()))
A.sort(reverse=True)

def isOk(i):
    x = A[i] + M
    B = [x - a for a in A[max(0, P - 1): i]]

    if not B:
        return True
    cnt = sum(B) + (P - 1) * M + (N - i) * M
    return min(B) >= 0 and cnt >= M * V

ok = 0
ng = N
while ng - ok > 1:
    mid = (ok + ng) // 2
    if isOk(mid):
        ok = mid
    else:
        ng = mid
print(ng)


Measured memory_bytes: 14480
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
typedef long long ll;
namespace mp = boost::multiprecision;
using Mint = mp::cpp_int;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = int(a); i < int(b); i++)
#define all(v) v.begin(), v.end()
#define uni(v) v.erase(unique(all(v)), v.end())
#define sort_g(v) sort(all(v), greater<int>())
#define dump(x) cerr << #x << ' ' << '=' << ' ' << x << endl

int main() {
    int A, B, C;
    cin >> A >> B >> C;
    cout << (A == B && B == C ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 1000000007;
typedef long long LL;

int main() {
  int A, B, M; cin >> A >> B >> M;
  vector<int> a(A), b(B);
  int amin = INT_MAX, bmin = INT_MAX;
  for (int i = 0; i < A; ++i) {
    cin >> a[i];
    amin = min(a[i], amin);
  }
  for (int i = 0; i < B; ++i) {
    cin >> b[i];
    bmin = min(b[i], bmin);
  }

  int vmin = amin + bmin;
  for (int i = 0; i < M; ++i) {
    int x, y, c; cin >> x >> y >> c;
    int v = a[x-1] + b[y-1] - c;
    vmin = min(vmin, v);
  }

  cout << vmin << endl;
}


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

int main(){
    long int h1,h2,k1,k2,a,b,c,d,sumh,sumk;
    cin>> h1 >> h2;
    cin>> k1 >> k2;
    cin>> a >> b >> c >> d;

    sumh=(h1*a)+(h2*b)+(h1/10)*c+(h2/20)*d;
    sumk=(k1*a)+(k2*b)+(k1/10)*c+(k2/20)*d;

    if(sumh>sumk){
        cout<<"hiroshi"<<endl;
    }
    else if(sumh<sumk){
        cout<<"kenjiro"<<endl;
    }
    else{
        cout<<"even"<<endl;
    }
    return 0;
    
}


Measured memory_bytes: 3096
N = int(input())
A = list(map(int, input().split()))
cnt_list = [0, 0, 0]
total = 0
low = 10**9
for a in A:
    low = min(low, abs(a))
    total += abs(a)
    if a == 0:
        cnt_list[1] += 1
    elif a > 0:
        cnt_list[2] += 1
    else:
        cnt_list[0] += 1
if (cnt_list[1] > 0)or(cnt_list[0] % 2 == 0):
    print(total)
else:
    print(total-2*low)


Measured memory_bytes: 14412
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <cstring> //memset(dp,0,sizeof(dp))
#include <functional>
#include <cctype>
#include <locale>
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ALL(a) (a).begin(),(a).end()
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<int,int> P;
typedef pair<long long,long long> Pll;
#define fout(num) cout << fixed << setprecision(20) << (num) << endl
//s[i]=tolower(s[i]); islower(s[i]); cout << tolower(s[i])はバグ
//vector<vector<ll>> dp(n,vector<ll>(n))
//exist x map o setconst ll MOD = 1e9+7;return fac[n]*(finv[k]*finv[n-k] % MOD) % MOD;
//木の連結成分の個数は頂点数ー辺の数

signed main(){
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    string s; cin >> s;
    int ans=0;
    if(s[0]=='R') chmax(ans,1);
    if(s[1]=='R') chmax(ans,1);
    if(s[2]=='R') chmax(ans,1);
    if(s[0]=='R'&&s[1]=='R') chmax(ans,2);
    if(s[1]=='R'&&s[2]=='R') chmax(ans,2);
    if(s[0]=='R'&&s[1]=='R'&&s[2]=='R') chmax(ans,3);
    cout << ans << endl;
    
    
}


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

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  for(int i = 0; i < n; i++) cin >> a[i];
  sort(a.begin(), a.end());
  reverse(a.begin(), a.end());
  int Alice = 0, Bob = 0;
  for(int i = 0; i < n; i++){
    if(i % 2 == 0){
      Alice += a[i];
    }
    else{
      Bob += a[i];
    }
  }
  cout << Alice - Bob << endl;
  return 0;
}

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

int main() {
    int n, a, b;
    cin >> n;
    
    if (n == 1) {
        cout << "Hello World" << endl;
    }
    else {
        cin >> a >> b;
        cout << (a + b) << endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
main(){for(int p,q,i;std::cin>>p>>q;puts("")){std::vector<int>r,u(q,1);for(;(p%=q)*u[p];u[p]=i=0,printf("%d",(p*=10)/q))r.push_back(p);if(p)for(puts("");i<r.size();printf(q?" ":"^"))q=r[i++]^p?q:0;}}

Measured memory_bytes: 4900
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for _ in range(n)]
def LIR(n):
    return [LI() for _ in range(n)]
def SR(n):
    return [S() for _ in range(n)]
def LSR(n):
    return [LS() for _ in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n = I()
    d = LIR(n)
    for i in range(n-2):
        if d[i][0] == d[i][1]:
            if d[i+1][0] == d[i+1][1]:
                if d[i+2][0] == d[i+2][1]:
                    print("Yes")
                    return
    print("No") 
    return

#Solve
if __name__ == "__main__":
    solve()


Measured memory_bytes: 65688
def digit_sum(i)
  sum = 0
  loop do
    i, mod = i.divmod(10)
    sum += mod
    break if i == 0
  end
  return sum
end

n, a, b = gets.chomp.split.map(&:to_i)
ans = 0

1.upto(n) do |i|
  sum = digit_sum(i)
  ans += i if a <= sum && sum <= b
end

puts ans

Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,int> P;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 1000000000
#define LLINF 1000000000000000ll
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
template<class T> void chmin(T& a,const T& b){if(a>b)a=b;}
template<class T> void chmax(T& a,const T& b){if(a<b)a=b;}
const int SIZE = 1<<18;
struct segtree{
	int seg[SIZE*2];
	void update(int k,int x){
		k += SIZE-1;
		seg[k]=x;
		while(k>0){
			k = (k-1)/2;
			seg[k]=min(seg[k*2+1],seg[k*2+2]);
		}
	}
	int query(int a,int b,int k,int l,int r){
		if(r<=a||b<=l)return INF;
		else if(a<=l&&r<=b)return seg[k];
		else return min(query(a,b,k*2+1,l,(l+r)/2),query(a,b,k*2+2,(l+r)/2,r));
	}
	int query(int a,int b){
		return query(a,b,0,0,SIZE);
	}
}seg[2];
int N;
int p[200100];
int pos[200100];
vector<int> child[200100];
int idx=0;
ll M = 1000000ll;
ll val[200100];
int dfs(int l,int r){
	if(r<=l)return -1;
	int id = idx++;
	int S = seg[l%2].query(l,r);
	int T = seg[(l+1)%2].query(pos[S],r);
	val[id]=S*M+T;
	child[id].pb(dfs(l,pos[S]));
	child[id].pb(dfs(pos[S]+1,pos[T]));
	child[id].pb(dfs(pos[T]+1,r));
	return id;
}
void print(vector<int> &vec){
	for(int i=0;i<vec.size();i++){
		cout << vec[i];
		if(i+1<vec.size())cout << ' ';
		else cout << endl;
	}
	return;
}
int main(){
	cin >> N;
	for(int i=0;i<N;i++){
		cin >> p[i];
		pos[p[i]]=i;
	}
	for(int i=0;i<SIZE;i++){
		seg[0].update(i,INF);
		seg[1].update(i,INF);
	}
	for(int i=0;i<N;i++){
		seg[i%2].update(i,p[i]);
	}
	dfs(0,N);
	/*for(int i=0;i<idx;i++){
		cout << val[i] << endl;
	}*/
	priority_queue<P,vector<P>,greater<P> > q;
	q.push(P(val[0],0));
	vector<int> ans;
	while(!q.empty()){
		P a = q.top();
		q.pop();
		int v = a.sec;
		ans.pb((a.fi)/M);
		ans.pb((a.fi)%M);
		for(int i=0;i<child[v].size();i++){
			int u = child[v][i];
			if(u==-1)continue;
			q.push(P(val[u],u));
		}
	}
	print(ans);
	return 0;
}

Measured memory_bytes: 29172
{-# LANGUAGE TypeFamilies, BangPatterns, FlexibleContexts, BangPatterns #-}
import Data.Array
import Data.Array.Unboxed
import qualified Data.Array.Unboxed as UA
import Data.Array.IO
import Data.Array.Unsafe
import qualified Data.Map.Strict as M
import qualified Data.Set as S
import qualified Data.Vector.Unboxed as U
import qualified Data.Vector.Unboxed.Mutable as U
import Data.Int
import Control.Monad.State.Strict hiding(foldM)
import qualified Data.ByteString.Char8 as B
import Data.ByteString(ByteString)
import Data.Char
import Debug.Trace
import Data.List(sort)

type Scanner a = StateT ByteString IO a
type family Freeze a where
  Freeze (IOUArray i v) = UArray i v
  Freeze (IOArray i v) = Array i v

foldM :: Monad m => (b -> a -> m b) -> b -> [a] -> m b
foldM f z0 xs = foldr c return xs z0
    where c x k = \z -> f z x >>= k
          {-# INLINE c #-}

scan :: Read a => Scanner a
scan = state $ \s ->
    let (s1, s2) = B.span (not . isSpace) s 
        !v = read (B.unpack s1)
    in (v, B.dropWhile isSpace s2)

scanInt :: Scanner Int
scanInt = scan

scanString :: Scanner B.ByteString
scanString = state $ \s ->
    let (s1, s2) = B.span (not . isSpace) s in
    (s1, B.dropWhile isSpace s2)

scanReal :: Scanner Double
scanReal = scan

main :: IO ()
main = B.getContents >>= \content -> flip evalStateT content $ do
    vN <- scanInt
    vX <- scanInt
    vS <- lift $ newArray_ (1, vN) :: Scanner (IOUArray Int Int)
    forM_ [1..vN] $ \i0 -> do
        scanInt >>= lift . writeArray vS (i0)
    vS <- lift $ unsafeFreeze vS 
    liftIO $ solve vN vX vS

newtype M = M Int
    deriving Show

modulo = 1000000007

instance Num M where
    M a + M b = M $ (a + b) `mod` modulo
    M a - M b = M $ (a - b) `mod` modulo
    M a * M b = M $ (a * b) `mod` modulo
    fromInteger x = M $ fromInteger x `mod` modulo
    abs = id
    signum _ = M 1

instance Fractional M where
    recip (M x) = M (recipM x modulo)

data EGCD = EGCD !Int !Int !Int

{-# NOINLINE recipM #-}
recipM :: Int -> Int -> Int
recipM x m | g /= 1 = error $ "No inverse for " ++ show x ++ " % " ++ show m 
           | s <  0 = s + m
           | otherwise = s
    where 
    EGCD s _ g = extgcd x m

extgcd :: Int -> Int -> EGCD
extgcd = go
    where 
    go a 0 = EGCD 1 0 a
    go a b = EGCD t (s - q * t) g
        where
        (q, r) = quotRem a b
        EGCD s t g = go b r

solve :: Int -> Int -> Freeze (IOUArray Int Int) -> IO ()
solve vN vX vS = print ans
    where
    sorted = sort $ UA.elems vS 
    s0 = U.generate (vX+1) id 
    M ans = M (sn U.! vX) * product (map M [1..vN])
    step !tbl (k, y) = 
        let !p1 = recip $ M k
            !p2 = 1 - p1 in
        U.generate (vX+1) $ \x ->
            let v1 = tbl U.! (x `mod` y)
                v2 = tbl U.! x
                M v = M v1 * p1 + M v2 * p2
            in v
    sn = foldl step s0 $ zip [1..vN] sorted


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

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

  int m = n * (n - 1) / 2 - n/2;
  int val = 0;
  if(n % 2 == 0) val = n + 1;
  else val = n;
  cout << m << '\n';
  for (int i = 1; i <= n; i++) {
    for (int j = i + 1; j <= n; j++) {
      if(i + j != val) cout << i << " " << j << '\n';
    }
  }
  return 0;
}

Measured memory_bytes: 256
#[allow(dead_code)]
fn main() {
    let n = i::u();
    let mut a = i::uv(n);
    a.sort();
    let mut count = 1;
    let mut size = a[0];
    for i in 1..n {
        if size * 2 >= a[i] {
            count += 1;
        } else {
            count = 1;
        }
        size += a[i];
    }
    println!("{}", count);
}

#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::io::*;
#[allow(unused_imports)]
use std::num::*;
#[allow(unused_imports)]
use std::str::*;

#[allow(dead_code)]
mod i {
    use super::*;

    pub fn read<T: FromStr>() -> T {
        stdin()
            .bytes()
            .map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>()
            .parse::<T>()
            .ok()
            .unwrap()
    }

    pub fn str() -> String {
        read()
    }

    pub fn s() -> Vec<char> {
        str().chars().collect()
    }

    pub fn i() -> i64 {
        read()
    }

    pub fn u() -> usize {
        read()
    }

    pub fn f() -> f64 {
        read()
    }

    pub fn c() -> char {
        read::<String>().pop().unwrap()
    }

    pub fn iv(n: usize) -> Vec<i64> {
        (0..n).map(|_| i()).collect()
    }

    pub fn iv2(n: usize) -> Vec<(i64, i64)> {
        (0..n).map(|_| iv(2)).map(|a| (a[0], a[1])).collect()
    }

    pub fn uv(n: usize) -> Vec<usize> {
        (0..n).map(|_| u()).collect()
    }

    pub fn uv2(n: usize) -> Vec<(usize, usize)> {
        (0..n).map(|_| uv(2)).map(|a| (a[0], a[1])).collect()
    }

    pub fn fv(n: usize) -> Vec<f64> {
        (0..n).map(|_| f()).collect()
    }

    pub fn cmap(h: usize) -> Vec<Vec<char>> {
        (0..h).map(|_| s()).collect()
    }
}


Measured memory_bytes: 4352
N = int(input())
A = list(map(int, input().split()))
m=1000
s=0
for i in range(N-1):
    if A[i] < A[i+1]:
        s+=m//A[i]
        m=m%A[i]
    if A[i] > A[i+1]:
        m += A[i]*s
        s=0

print(m+A[N-1]*s)






Measured memory_bytes: 61752
/* A Binary Search Tree I */

#include<stdio.h>
#include<stdlib.h>

struct Node{
  int key;
  struct Node *parent;
  struct Node *left;
  struct Node *right;
};

struct Node *nil;
struct Node *root;
void init(){
  nil->key=-1;
  nil->parent=nil;
  nil->left=nil;
  nil->right=nil;
}

void Preorder(struct Node *u);
void Inorder(struct Node *u);

void TreeInsert(struct Node *T, struct Node *z);

int main(){
  int n; /* command number */
  int k; 
  char com[6];
  int i;
  struct Node *T;
  struct Node *z;
  nil=malloc(sizeof(struct Node));
  init();
  /*scan*/
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%s",com);
    if(com[0]=='i'){
      scanf("%d",&k);
      z=malloc(sizeof(struct Node));
      z->key=k;
      z->left=nil;
      z->right=nil;
      if(i==0)root=z;
      TreeInsert(T,z);
      T=z;
    }else{
      Inorder(root);
      printf("\n");
      Preorder(root);
      printf("\n");
    }
  }
  free(z);
  free(nil);
  return 0;
}

void TreeInsert(struct Node *T, struct Node *z){
  struct Node *y;
  struct Node *x;
  y=nil;
  x=root;

  while(x!=nil){
    if(z==x)break;
    y=x;
    if(z->key<x->key){
      x=(x->left);
    }else{
      x=(x->right);
    }
  }
  z->parent=y;     
  if(y==nil){
    root=z; /* if T is empty */
  }else if(z->key<=y->key){
    y->left=z;
  }else{
    y->right=z;
  }
}

void Preorder(struct Node *u){
  if(u!=nil){
    printf(" %d",u->key);
    Preorder(u->left);
    Preorder(u->right);
  }
}

void Inorder(struct Node *u){
  if(u!=nil){
    Inorder(u->left);
    printf(" %d",u->key);
    Inorder(u->right);
  }
}

Measured memory_bytes: 11000
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author yosiiii
 */


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

class DAlterAltar {
public:
	void solve(std::istream& in, std::ostream& out) {
        int n;
        in >> n;
        string s;
        in >> s;
        int r=0;
        rep(i,s.size()){
            if(s[i]=='R'){
                r++;
            }
        }
        int ans=0;
        rep(i,r){
            if(s[i]!='R'){
                ans++;
            }
        }
        out << ans <<endl;
	}
};


int main() {
	DAlterAltar solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 3756
use proconio::fastout;
use proconio::input;

const MOD: usize = 1000000007;

#[fastout]
fn main() {
    input! {
        n: usize,
        ns: [usize; n],
    }
    let mut ans = 1;
    let mut table = [0, 0, 0];
    for &n in &ns {
        ans = ans * table.iter().filter(|&&x| x == n).count() % MOD;
        if let Some(i) = table.iter_mut().find(|&&mut x| x == n) {
            *i += 1;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 3340
using System;

class Program
{
    static void Main()
    {
        int[] height = new int[10];
        for (int i = 0;i < 10; i++)
        {
            height[i] = int.Parse(Console.ReadLine());
        }

        Array.Sort(height);

        Console.WriteLine(height[9]);
        Console.WriteLine(height[8]);
        Console.WriteLine(height[7]);
    }
}

Measured memory_bytes: 9252
#include <bits/stdc++.h>
#define repr(i,from,to) for(int (i)=(from);(i)<(to);(i)++)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
// const bool debug=true;
const bool debug=false;
#define DEBUG if(debug==true)
#define all(x) begin((x)), end((x))
#define vprint(x) for(auto a:(x)) cout << x << endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) { a = b; return true;}
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) { a = b; return true;}
    return false;
}


ll n,u,v;
vector<vector<ll>> nbs;
vector<ll> d(ll start) {
    queue<ll> que;
    vector<ll> dd(n,n);
    dd[start] = 0;
    que.push(start);
    while(!que.empty()) {
        ll now = que.front();
        que.pop();
        for(auto x:nbs[now]) {
            if (dd[x]==n) {
                dd[x] = dd[now]+1;
                que.push(x);
            } 
        }
    }
    return dd;
}

int main(void) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin>>n>>u>>v;
    u--;v--;
    nbs.assign(n,vector<ll>());
    rep(i,n-1) {
        ll a,b;
        cin>>a>>b;
        a--;b--;
        nbs[a].push_back(b);
        nbs[b].push_back(a);
    }
    vector<ll> du=d(u),dv=d(v);
    ll dist = 0;
    rep(i,n) {
        if (du[i]<dv[i]) {
            chmax(dist,dv[i]);
        }
    } 
    // rep(i,n) {
    //     cout << du[i] << " ";
    // }
    // cout << endl;
    // rep(i,n) {
    //     cout << dv[i] << " ";
    // }
    dist--;
    cout << dist << endl;
    return 0;
}


Measured memory_bytes: 8064