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

//a^n (mod m)
const long long mod = 13;
long long modpow(long long a, long long n) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

//mod mでの a の逆元を求める
long long modinv(long long a) {
    long long b = mod, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= mod; 
    if (u < 0) u += mod;
    return u;
}

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

    ll MOD=1e9+7;

    int n=s.size();
    ll dp[n+1][13]={};
    dp[0][0]=1;
    ll p[111111]={};

    for(int i=0;i<n;i++){
        p[i] = modpow(10,i);
    }

    reverse(s.begin(),s.end());

    for(int i=0;i<n;i++){
        for(int j=0;j<13;j++){
            if(s[i]=='?'){
                for(int k=0;k<=9;k++){
                    int next = (j+k*p[i])%13;
                    dp[i+1][next] += dp[i][j];
                    dp[i+1][next]%=MOD;
                }
            }
            else {
                int next = (j+(s[i]-'0')*p[i])%13;
                dp[i+1][next] += dp[i][j];
                dp[i+1][next]%=MOD;
            }
        }
    }
    cout<<dp[n][5]<<endl;
}


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

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

        Scanner sc=new Scanner(System.in);

        while(sc.hasNext()){
            String[] st=sc.next().split(",");
            int[] card = new int[5];
            for(int i=0; i<5;i++){
            	card[i]=Integer.parseInt(st[i]);
            }
            Arrays.sort(card);
            System.out.println(judge(card));

        }
    }

    public static String judge(int[] card){
    	if(card[0]==card[3] || card[1]==card[4])return "four card";
        if((card[0]==card[1] && card[2]==card[4]) || (card[0]==card[2] && card[3]==card[4]))return "full house";
        if(card[0]+1 == card[1] && card[1]+1 == card[2] && card[2]+1 == card[3] && card[3]+1 == card[4])return "straight";
        if(card[0] == 1 && card[1] == 10 && card[2] == 11 && card[3] == 12 && card[4] == 13)return "straight";
        if(card[0]==card[2] || card[1]==card[3] || card[2]==card[4])return "three card";
        if((card[0]==card[1] && card[2]==card[3]) || (card[0]==card[1] && card[3]==card[4]) || (card[1]==card[2] && card[3]==card[4]))return "two pair";
        if(card[0]==card[1] || card[1]==card[2] || card[2]==card[3] || card[3]==card[4])return "one pair";
		return null;

    }
}

Measured memory_bytes: 26072
#include <iostream>
#include <string>
#include <map>
#include <algorithm>
#define rep(i,s,n)for(int i = s;i<n;i++)
#define repe(i,s,n)for(int i = s;i<=n;i++)
using namespace std;
typedef long long ll;
static const ll MOD = 1e9 + 7;

int main() {
	ll n, a, b; cin >> n >> a >> b;

	ll X = n * a;
	ll Y = b;

	cout << min(X, Y) << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll p=pow(10,9)+7;
ll phi(ll n) {
    ll result = n;
    for (ll i = 2; i * i <= n; i++) {
        if(n % i == 0) {
            while(n % i == 0)
                n /= i;
            result -= result / i;
        }
    }
    if(n > 1)
        result -= result / n;
    return result;
}
ll power(ll x, ll y, ll p) 
{ 
    ll res = 1;      
    x = x % p;  
   while (y > 0) 
    { 
        if (y & 1) 
            res = (res*x) % p; 
        y = y>>1; 
        x = (x*x) % p; 
    } 
    return res; 
} 

ll modInverse(ll n, ll p) 
{ 
    return power(n, p-2, p); 
}


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,w,i,j;
   cin>>n>>w;
   ll wt[n],v[n];
   for(i=0;i<n;i++)
   cin>>wt[i]>>v[i];
   ll dp[w+1];
   memset(dp,-1,sizeof(dp));
   dp[0]=0;
   for(i=0;i<n;i++)
   {
       for(j=w;j>=wt[i];j--)
       {
           if(dp[j-wt[i]]!=-1)
           dp[j]=std::max(dp[j],dp[j-wt[i]]+v[i]);
       }
   }
   sort(dp,dp+w+1);
   cout<<dp[w];
   
 
    return 0;
    
}
    



Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        int ans = (int) ((100 * (N - M) + 1900 * M) * Math.pow(2, M));
        System.out.println(ans);
    }

}

Measured memory_bytes: 22740
n, k = gets.split.map(&:to_i)
as = gets.split.map(&:to_i)

steps = Array.new(n + 1, -1)
visited = []
to_visit = 1

while steps[to_visit] == -1
  steps[to_visit] = visited.size
  visited << to_visit
  to_visit = as[to_visit - 1]
end

i = steps[to_visit]
cycles = visited.size - i

if k < i
  puts visited[k]
else
  puts visited[i + ((k - i) % cycles)]
end


Measured memory_bytes: 30412
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n-1);i>=0;i--)
#define all(x) (x).begin(),(x).end()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(std::unique(all(x)), x.end());
typedef long long ll;
const int INF = 1e9;
const ll MOD = 1e9+7;
const ll LINF = 1e18;
const double PI=acos(-1);
using namespace std;
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; }
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

ll gcd (ll x,ll y) {
    if (x < y) swap(x, y);
    if (y == 0) return x;
    return gcd(x % y, y);
}
ll lcm (ll x,ll y) {
    return x/gcd(x, y)*y;
}

int main() {
    int n;
    cin>>n;
    vector<int> a(n);
    rep(i,n)  cin>>a[i];
    int now=1;
    int ans=n;
    rep(i,n){
        if(a[i]==now) {
            ans--;
            now++;
        }
    } 
    if(now==1) cout<<-1<<endl;
    else cout<<ans<<endl;
}

Measured memory_bytes: 1024
#include <iostream>

using namespace std;

long long N, M, ans;

int main(){
	cin>>N>>M;
	
	//if(N && M >= 2){
		long long t = min(N, M/2);
		ans = t;
		N -= t;
		M -= t * 2;
	//}
	
	ans += M /4;
	
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 256
n = int(input())
xl = list(map(int, input().split()))
xl.sort()

def cost(p):
    res = 0
    for x in xl:
        res += (x-p)**2
    return res

res = 10**9
for p in range(xl[0],xl[-1]+1):
    res = min(res, cost(p))

print(res)


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

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin >> n;
	vector<pair<int,int>> d(n);
	for (auto& x: d) {
		cin >> x.first >> x.second;
	}
	for (int i = 0; i < n; ++i) {
		if (d[i].first == d[i].second) {
			int streak = 0;
			while (i < n && d[i].first == d[i].second) {
				++streak; ++i;
			}
			if (streak >= 3) {
				cout << "Yes\n";
				return 0;
			}
			--i;
		}
	}
	cout << "No\n";
	return 0;
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
#define ALL(a)  (a).begin(),(a).end()
 
const ll mod = 1000000007;
const ll LINF = 1e13;
const ll LLINF = 1e18;
const ll ALPHABET = 26;
 
template <class T>
void Swap(T& r, T& l) {
  T tmp = r;
  r = l;
  l = tmp;
}
 
template<typename T>
istream& operator >> (istream& is, vector<T>& vec) {
  for (T& x : vec) is >> x; //for(int i=0; i<vec.size(); i++) is >> x[i]; とかでもいい
  return is;
}


int main(){
    // ll N,S,K;
    // ll a,b,c;
    string s;

    cin >> s;

    bool ans =true;

    for (ll i = 0; i < s.size(); i++)
    {
        if (i%2==1){
            if (!( s[i] == 'L' || s[i] == 'U' || s[i] == 'D' )){
                ans = false;
                cerr << i <<endl;
            } 
        }else{
            if (!( s[i] == 'R' || s[i] == 'U' || s[i] == 'D' )) {
                ans = false;
                cerr << i <<endl;
            }
        }
    }
    

  cout << (ans?"Yes":"No");

}


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

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define FOR(i ,a, b) for (int i = a ; i <= b ; i++)
#define sz(a) int(a.size())
#define cuti(a) cout << a << endl;
#define cutii(a,b) cout << a << " " << b << endl;
#define cutiii(a,b,c) cout << a << " " << b << " " << c << endl;
#define vec(a) vector<int > a;

template<typename T,typename U> inline void chmin(T &x,U y){ if(y<x) x = y; }

typedef long long LL;
typedef pair<int ,int > pii;
typedef pair<string ,int > psi;
typedef pair<string ,string > pss;
typedef pair<LL, LL> pLL;

const long long oo = 1e9 + 7;
const double PI = acos(-1.0);

double DEG_to_RAD(double d) { return d * PI / 180.0; }

int n,a,b;

int main(){
   // freopen("test.txt","r",stdin);
    cin >> n >> a >> b;
    cout << min(1LL*n*a,1LL*b) << endl;
}


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

//TO_STRING
template <typename A, typename B>
string to_string(pair<A, B> p);
 
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);
 
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);
 
string to_string(const string& s) {
  return '"' + s + '"';
}

string to_string(char ch){
  string s;
  s += ch;
  return s;
}

string to_string(const char* s) {
  return to_string((string) s);
}
 
string to_string(bool b) {
  return (b ? "true" : "false");
}
 
string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}
 
template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}
 
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
 
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
 
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + 
    to_string(get<2>(p)) + ")";
}
 
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + 
    to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}

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

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

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

typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<pi> vpi;
typedef vector<char> vch;
typedef vector<string> vstr;
typedef vector<vi> vvi;
typedef vector<vpi> vvpi;
typedef vector<pll> vpll;
typedef vector<vll> vvll;
typedef vector<vb> vvb;
typedef vector<vvi> vvvi;
typedef vector<vch> vvch;
typedef vector<vstr> vvstr;

#define all(x) x.begin(), x.end()
#define pb push_back
#define pf push_front
#define fi first
#define se second  
#define sz(x) ((ll)x.size())



void solve() {
 ull x;
 cin >> x;
 ull cur = 100;
 int year = 0;
 while (cur < x) {
  year++;
  cur = cur + cur / 100;
 }
 cout << year << endl;
}

int main() {
  ios::sync_with_stdio(false);  
  cin.tie(0);cout.tie(0); 
  
  int t = 1;
  for (int tc = 1; tc <= t; tc++) {
  	solve();
  }
}

Measured memory_bytes: 3644
X,K,D=map(int,input().split())

if abs(X)-(D*K)>0:
    print(abs(X)-(D*K))
    exit()
X=abs(X)
c=X//D
K-=c
X%=D
if K%2==0:
    print(X)
else:
    print(abs(X-D))

Measured memory_bytes: 61820
import java.util.Scanner

object Main {
  def main(args: Array[String]): Unit = {
    val sc = new Scanner(System.in)
    val D = Integer.parseInt(sc.next)
    
    println(
      if (D == 25) "Christmas"
      else if (D == 24) "Christmas Eve"
      else if (D == 23) "Christmas Eve Eve"
      else "Christmas Eve Eve Eve"
    )
  }
}

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

int main(){
long long sum=0;
int N;
cin >> N;
for(int i=1;i<=N;i++){
  if(i%3!=0 && i%5!=0){
    sum+=i;
  }
}
  cout << sum << endl;
  return 0;
}

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

int main() {
  int n,m;
  cin >> n >> m;
  vector<vector<int>> data(m, vector<int>(2));
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < 2; j++) {
      cin >> data.at(i).at(j);
    }
  }
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < m-i; j++) {
      if(data.at(i).at(0)==data.at(i+j).at(0) && data.at(i).at(1)!=data.at(i+j).at(1)){
      cout << -1 << endl;
      return 0;
      }
      if(n>1 && data.at(i).at(0)==1 && data.at(i).at(1)==0){
      	cout << -1 << endl;
        return 0;
      }
    }
  }
  int one=0;
  int two=0;
  int thr=0;
  if(n==2)
  one=10;
  if(n==3)
  one=100;
  for (int i = 0; i < m; i++) {
      if(data.at(i).at(0)==1)
      one = (data.at(i).at(1))*pow(10,n-1);
      if(data.at(i).at(0)==2)
      two = (data.at(i).at(1))*pow(10,n-2);
      if(data.at(i).at(0)==3)
      thr = (data.at(i).at(1));
  }
  cout << one+two+thr << endl;   			
}





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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

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

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int main(){
  int n;
  set<int> S;
  cin>>n;
  while(n--){
    int x; cin>>x;
    if(S.count(x)){
      S.erase(x);
    }else{
      S.insert(x);
    }
  }
  cout << S.size() << endl;
  return 0;
}


Measured memory_bytes: 4864
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		int K = scan.nextInt();
		int X = scan.nextInt();
		int Y = scan.nextInt();
		int total = 0;
		
		if(N>K){
		total = X*K + Y*(N-K);
		}else{
		total = X*N;	
		}
		System.out.println(total);

	}

}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;

int n,m,r;
int travelCities[9];
vector<vector<pii> > adjList(4000);

 int dd[205][205];

void dijk(int s)
{
    vector<int> dist(n,1000000000);
    dist[s]=0;
    priority_queue<pii,vector<pii>,greater<pii> > pq;
    pq.push(pii(0,s));
    while(!pq.empty())
    {
        pii fr = pq.top();
        pq.pop();
        int d = fr.first, u = fr.second;
        if(d>dist[u]) continue;
        for(int j=0;j<adjList[u].size();++j)
        {
            pii v = adjList[u][j];
            if(dist[u]+v.second<dist[v.first])
            {
                dist[v.first]=dist[u]+v.second;
                pq.push(pii(dist[v.first],v.first));
            }
        }
    }
}

int visited[205];

int solve(int s, int nm)
{
    if(nm==r-1) return 0;
    int mn(1000000000);
    visited[travelCities[s]]=1;
    for(int i = 0;i<r;++i)
    {
        if(!visited[travelCities[i]] && i!=s)
        {
            mn = min(mn,dd[travelCities[s]][travelCities[i]] + solve(i,nm+1));
            visited[travelCities[i]]=0;
        }
    }
    visited[travelCities[s]]=0;
    return mn;
}

int main()
{
    cin >> n >> m >> r;
    for(int i=0;i<r;++i) cin >> travelCities[i],travelCities[i]--;
    for(int i=0;i<m;++i)
    {
        int a,b,c;
        cin >> a >> b >> c;
        a--;
        b--;
        adjList[a].push_back(pii(b,c));
        adjList[b].push_back(pii(a,c));
    }

    for(int i=0;i<r;++i)
    {
        int s = travelCities[i];
        vector<int> dist(n,1000000000);
        dist[s]=0;
        priority_queue<pii,vector<pii>,greater<pii> > pq;
        pq.push(pii(0,s));
        while(!pq.empty())
        {
            pii fr = pq.top();
            pq.pop();
            int d = fr.first, u = fr.second;
            if(d>dist[u]) continue;
            for(int j=0;j<adjList[u].size();++j)
            {
                pii v = adjList[u][j];
                if(dist[u]+v.second<dist[v.first])
                {
                    dist[v.first]=dist[u]+v.second;
                    pq.push(pii(dist[v.first],v.first));
                }
            }
        }
        for(int j=i+1;j<r;++j)
        {
            //cout << travelCities[i] << " " << travelCities[j] <<" : "<< dist[travelCities[j]] << endl;
            dd[travelCities[i]][travelCities[j]] = dd[travelCities[j]][travelCities[i]] = dist[travelCities[j]];
        }
    }
    int mn=1000000000;
    for(int i=0;i<r;++i)
    {
        mn=min(mn,solve(i,0));
    }
    cout << mn;
    return 0;
}


Measured memory_bytes: 768
#include <iostream>
#include <cstdio>
#include <functional>
#include <vector>
#include <algorithm>

int main()
{
    int N = 1, K = 1;

    std::cin >> N >> K;
    int h = 0;
    int count = 0;
    for (int i = 0; i < N; ++i) {
        std::cin >> h;
        if (h >= K) {
            count++;
        }
    }


    // Output
    printf("%d\n", count);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stack>

int main()
{
    std::stack<int> s;
    while (true) {
        int n;
        std::cin >> n;
        if (std::cin.eof()) break;

        if (n == 0) {
            std::cout << s.top() << std::endl;
            s.pop();
        }
        else s.push(n);
    }
}

Measured memory_bytes: 1200
#include <bits/stdc++.h>
typedef long long ll;
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
using namespace std;
const ll MAX_N=1e4;
ll N,a[MAX_N],b[MAX_N],c[MAX_N];
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>N;
	REP(i,N){
		cin>>a[i];
	}
	REP(i,N){
		cin>>b[i];
		c[i]=a[i]-b[i];
	}
	ll sm=0;
	REP(i,N){
		sm+=c[i];
	}
	bool ans;
	if(sm>0)ans=false;
	else{
		sm*=-1;
		REP(i,N){
			if(c[i]<0){
				sm-=(-c[i]+1)/2;
			}
		}
		if(sm>=0){
			ans=true;
		}else{
			ans=false;
		}
	}
	cout<<(ans ? "Yes":"No")<<endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
// #define int long long
using namespace std;

signed main() {
  int N, K;
  string S;
  cin >> N >> S >> K;
  
  char n = S.at(K-1);
  
  for( int i = 0; i < S.size(); i++ ){
    if( S.at(i) != n ){
      S.replace(i, 1, 1, '*');
    }
  }
  cout << S << endl;
      
}


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

// エイリアス
using  ll = long signed long;
using ull = long unsigned long;
using  ld = long double;
using   P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;

// 汎用マクロ
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOREACH(i,q) for (auto &i : q)
#define UNIQUE(v) do { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); } while (false)
#define SZ(x) ((int)(x).size())
template <class T>inline bool chmin(T &a, const T b) {if (a > b) { a = b; return true;} return false;}
template <class T>inline bool chmax(T &a, const T b) {if (a < b) { a = b; return true;} return false;}
template <class T>inline void line_out(const vector<T> vec) {int n = SZ(vec); rep(i, n) { cout << vec[i]; if(i < n-1) cout << " ";}cout << endl;}
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 28;
const ll INF64 = 1ll << 55;
const int mod = 1000000007;
//const int mod = 998244353;
struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }
 
  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};

int main()
{
  ll d, t, s;
  cin >> d >> t >> s;
  ll time = d/s;
  if(d%s != 0) ++time;
  if(time <= t) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 3616
#include<iostream>
        using namespace std;
        int main()
        {
          int a,b;
          cin>>a>>b;
          if(b%2==1) return 0;
          if(a>=13) cout<<b<<'\n';
          else if(a<=12&&a>=6) cout<<(b/2)<<'\n';
          else cout<<0<<'\n';
          return 0;}

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

int main()
{
	string ABCD; cin >> ABCD;
	int NUM[4];
	for (int i = 0; i < 4; i++)NUM[i] = ABCD[i] - '0';

	for (int i = 0; i < 8; i++) {
		int x = i;
		bool sign[3];
		for (int j = 0; j < 3; j++)sign[j] = x&(1 << j);

		int ans = NUM[0];
		for (int j = 0; j < 3; j++) {
			if (sign[j])ans += NUM[j + 1];
			else ans -= NUM[j + 1];
		}

		if (ans == 7) {
			cout << NUM[0];
			for (int j = 0; j < 3; j++) {
				cout << (sign[j] ? "+" : "-");
				cout << NUM[j + 1];
			}
			cout <<"=7"<< endl;
			return 0;
		}
	}

    return 0;
}



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

int selectionsort(int A[],int N){
    int count = 0;
    for (int i=0; i<N; i++){
        int minj = i;
        for (int j=i; j<N; j++){
            if (A[j] < A[minj]) minj = j;
        }
        if (i!=minj){
            int v = A[i];
            A[i] = A[minj];
            A[minj] = v;
            count += 1;
        }
        
    }
    return count;
}

int main(){
    int N;
    cin >> N;
    int A[N];
    for (int i=0; i<N; i++) cin >> A[i];
    int count = selectionsort(A,N);
    
    for (int j=0; j<N; j++){
        if (j==N-1) cout << A[j] << "\n";
        else cout << A[j] << " ";
    }
    cout << count << "\n";
    
    return 0;
}


Measured memory_bytes: 3080
import java.util.Scanner;


public class Main {

    public static void main(String args[])
    {
        Scanner sc=new Scanner(System.in);
        int a=sc.nextInt();
        int b=sc.nextInt();
        int c=a*b;
        int d=a+b;
        int e=a-b;
        if(c>=d && c>=e)
        {
            System.out.println(c);
        }
        else if(d>=c && d>=e)
        {
            System.out.println(d);
        }
        else
        {
            System.out.println(e);
        }
    }
}


Measured memory_bytes: 21716
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		String s = sc.next();
		sc.close();
		String ans = "";
		for (int i = 0; i < s.length(); i++) {
			ans += String.valueOf((char) (((s.charAt(i) + n - 65) % 26) + 65));
		}
		System.out.println(ans);
	}

	public static int[] arrayInt(Scanner sc, int n) {
		int[] array = new int[n];
		for (int i = 0; i < n; i++) {
			array[i] = sc.nextInt();
		}
		return array;
	}

	public static long[] arrayLong(Scanner sc, int n) {
		long[] array = new long[n];
		for (int i = 0; i < n; i++) {
			array[i] = sc.nextLong();
		}
		return array;
	}

	public static double[] arrayDouble(Scanner sc, int n) {
		double[] array = new double[n];
		for (int i = 0; i < n; i++) {
			array[i] = sc.nextDouble();
		}
		return array;
	}
}


Measured memory_bytes: 147540
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		long[][] map=new long[n][n];
		long ans=0;
		for(int i = 0; i<n; i++){
			for(int j = 0; j<n; j++){
				map[i][j]= sc.nextLong();
			}
		}
		boolean[][] mapb=new boolean[n][n];
		for(int i = 0; i<n; i++){
			for(int j = 0; j<n; j++){
				for(int k = 0; k<n; k++){
					if(i!=j && i!=k && j!=k){
						if(map[k][j]>map[k][i]+map[i][j]){
							System.out.println("-1");
							return;
						}else if(map[k][j]==map[k][i]+map[i][j]){
							mapb[k][j]=true;
						}
					}
				}
			}
		}
		for(int i = 0; i<n; i++){
			for(int j = 0; j<n; j++){
				if(!mapb[i][j]){
					ans+=map[i][j];
				}
			}
		}
		System.out.println(ans/2);
	}
}


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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, K;
    cin >> N >> K;
    int ans = 0;
    for (int n = 0; n < N; ++n){
        int x;
        cin >> x;
        ans += min(x, K - x);
    }
    cout << ans * 2 << endl;
    return 0;
}


Measured memory_bytes: 256
n=gets.to_i
s=gets.split.map!{|i| i.to_i}
s.sort!
ans=0
for i in 0..n-1
  if s[i]==s[i+1]
    ans+=1
    break
  end
end
if ans==0
  puts "YES"
else
  puts "NO"
end


Measured memory_bytes: 28644
n=int(input())
p=list(map(int,input().split()))
s=sorted(p)
flag=0
from copy import deepcopy as dc
if p==s:
    flag=1
for i in range(n):
    for j in range(i+1,n):
        d=dc(p)
        d[i],d[j]=d[j],d[i]
        if d==s:
            flag=1
if flag==1:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 3444
fun main(args: Array<String>) {
    val S = next()
    val N = S.length
    val r1 = 0 .. (N - 1) / 2 - 1
    val r2 = (N + 3) / 2 - 1 .. N - 1
    fun isPal(s: String) =
        (0 until s.length / 2).all { n ->
//System.err.println("n:$n [${s[n]}][${s[s.length - n - 1]}]")
            s[n] == s[s.length - n - 1] }
    val ans = isPal(S) && isPal(S.substring(r1)) && isPal(S.substring(r2))
    println(if (ans) "Yes" else "No")
}

fun next() = readLine()!!
fun nextInt() = Integer.parseInt(next())
fun nextInt(offset: Int = 0) = nextInt() + offset
fun nextLong() = java.lang.Long.parseLong(next())
fun nextLong(offset: Long = 0L) = nextLong() + offset
fun nextDouble() = next().toDouble()
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map { Integer.parseInt(it) }
fun listOfInt(offset: Int = 0) = listOfString().map { Integer.parseInt(it) + offset }
fun listOfLong() = listOfString().map { java.lang.Long.parseLong(it) }
fun listOfLong(offset: Long = 0L) = listOfString().map { java.lang.Long.parseLong(it) + offset }
fun listOfDouble() = listOfString().map { it.toDouble() }


Measured memory_bytes: 33608
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.util.InputMismatchException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskD solver = new TaskD();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskD {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int[] a = in.nextIntArray(n);

            int max = -1;
            int idx = -1;
            for (int i = 0; i < n; i++) {
                if (max < a[i]) {
                    idx = i;
                    max = a[i];
                }
            }

            int ans = -1;
            int diff = Integer.MAX_VALUE;
            for (int i = 0; i < n; i++) {
                if (i == idx) continue;

                if (Math.abs(max / 2 - a[i]) < diff) {
                    diff = Math.abs(max / 2 - a[i]);
                    ans = i;
                }
            }

            out.println(max + " " + a[ans]);
        }

    }

    static class InputReader {
        BufferedReader in;
        StringTokenizer tok;

        public String nextString() {
            while (!tok.hasMoreTokens()) {
                try {
                    tok = new StringTokenizer(in.readLine(), " ");
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
            }
            return tok.nextToken();
        }

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

        public int[] nextIntArray(int n) {
            int[] res = new int[n];
            for (int i = 0; i < n; i++) {
                res[i] = nextInt();
            }
            return res;
        }

        public InputReader(InputStream inputStream) {
            in = new BufferedReader(new InputStreamReader(inputStream));
            tok = new StringTokenizer("");
        }

    }
}



Measured memory_bytes: 35896
#include <stdio.h>

double dp[100][100];

#define REP(i, n) for (int i = 0; i < (n); i++)
#define MAX(x, y) ((x) > (y) ? (x) : (y))

int main(void)
{
	double grow[100][100]; //[ツ前ツづ個氾ャツ猟ソ][ツ債。ツづ個氾ャツ猟ソ]
	int n, m;
	
	while (1){
		REP(i, 100) dp[0][i] = 1.0;
		
		scanf("%d%d", &n, &m);
		
		if (n == 0 || m == 0){
			break;
		}
		
		REP(i, n) REP(j, n) scanf("%lf", &grow[i][j]);
		
		for (int i = 1; i < m; i++){
			for (int j = 0; j < n; j++){
				dp[i][j] = dp[i - 1][0] * grow[0][j];
				for (int k = 1; k < n; k++){
					dp[i][j] = MAX(dp[i][j], dp[i - 1][k] * grow[k][j]);
				}
			}
		}
		
		double ans = 0;
		REP(i, n){
			ans = MAX(ans, dp[m - 1][i]);
		}
		
		printf("%.2lf\n", ans);
	}
	return (0);
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <map>
#include <utility>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <stack>
#include <queue>

#define REP(i,a,n) for(int i=a;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define vsort(v) sort(v.begin(),v.end())
#define asort(a,n) sort(a, a + n)
#define vi vector<int>
#define vd vector<double>

//ここからAtCoder向けdefine
#define yes cout << "YES" << endl;
#define no cout << "NO" << endl;

using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, a, b;
    cin >> n >> a >> b;
    int c = b - a;
    (c % 2 == 0) ? cout << "Alice" << endl : cout << "Borys" << endl;

    return 0;
}

Measured memory_bytes: 888
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <string>
#include <vector>
#include <utility>
#include <complex>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <tuple>
#include <bitset>
#include <algorithm>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef complex<ld> compd;
#define rep(i,n)	for(int i=0;i<n;i++)
#define srep(i,a,n)	for(int i=a;i<n;i++)
#define REP(i,n)	for(int i=0;i<=n;i++)
#define SREP(i,a,n)	for(int i=a;i<=n;i++)
#define rrep(i,n)	for(int i=n-1;i>=0;i--)
#define RREP(i,n)	for(int i=n;i>=0;i--)
#define all(a)	(a).begin(),(a).end()
#define mp(a,b)	make_pair(a,b)
#define mt	make_tuple
#define fst	first
#define scn second
#define bicnt(x)	__buildin__popcount(x)
#define debug(x)	cout<<"debug: "<<x<<endl
#define DEBUG 0

const ll inf = (ll)1e16;
const ll mod = (ll)1e9 + 7;
const ld eps = 1e-18;
const int dx[] = { 0,1,0,-1 };
const int dy[] = { 1,0,-1,0 };

int main() {
	int n;	cin >> n;
	vector<ll> a(n);
	rep(i, n)	cin >> a[i];
	ll ret = 0;
	while (true) {
		bool flag = true;
		rep(i, n)	flag &= (a[i] < n);
		if (flag)	break;
		vector<ll> cnt(n + 1, 0);
		rep(i, n)	cnt[i + 1] = max(0LL, (ll)ceill(((ld)(a[i] - n + 1) / n)));
		rep(i, n)	cnt[i + 1] += cnt[i];
		ret += cnt[n];
		rep(i, n) {
			a[i] -= (cnt[i + 1] - cnt[i])*(n + 1) - cnt[n];
		}
	}
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;//リストの使用
using System.Collections.Generic;
using System.Text;//テキストの高速出力に必要
class Program
{
	static void Main()
	{
		string[] input = Console.ReadLine().Split(' ');
		int a = int.Parse(input[0]);
		int b = int.Parse(input[1]);
    int m = int.Parse(input[2]);
    int[] numsA = Array.ConvertAll(Console.ReadLine().Split(' '),int.Parse);
    int[] numsB = Array.ConvertAll(Console.ReadLine().Split(' '),int.Parse);
    int answer = 999999;

    int[,] vertexes = new int[m,3];
    for(int i = 0; i < m; i++)
    {
      int[] nums = Array.ConvertAll(Console.ReadLine().Split(' '),int.Parse);
      vertexes[i,0] = nums[0];
      vertexes[i,1] = nums[1];
      vertexes[i,2] = nums[2];
    }

    int minA = 999999;
    int minB = 999999;
    for(int i = 0; i < a; i++) minA = Math.Min(minA, numsA[i]);
    for(int i = 0; i < b; i++) minB = Math.Min(minB, numsB[i]);
    answer = minA+minB;

    for(int i = 0; i < m; i++)
    {
      answer = Math.Min(answer, numsA[vertexes[i,0]-1] +numsB[vertexes[i,1]-1] -vertexes[i,2]);
    }

		Console.WriteLine(answer);
	}
}

Measured memory_bytes: 33244
void main() {
    int[] tmp = readln.split.to!(int[]);
    int a = (tmp[0] + 13) % 15, b = (tmp[1] + 13) % 15;
    if (a > b) {
        "Alice".writeln;
    } else if (a < b) {
        "Bob".writeln;
    } else {
        "Draw".writeln;
    }
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni;

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  double h,n;
  cin>>h>>n;
  double sum=0;
  for(int i=0;i<n;i++)
  {
    int x=0;
    cin>>x;
    sum+=x;
  }
  if(sum>=h)
    cout<<"Yes";
  else
    cout<<"No";
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define forr(x,n) for(int x = 0; x < n; ++x)
#define pr pair<int,int>
#define ll long long int
const int mod=1e9+7;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int k,n;
    cin>>k>>n;
    int a[n];
    forr(i,n)
    cin>>a[i];
    sort(a,a+n);
    int mx=-1;
    forr(i,n-1)
    mx=max(mx,a[i+1]-a[i]);
    mx=max(mx,k-a[n-1]+a[0]);
    cout<<k-mx;
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i < (n);++i)
using namespace std;
using ll = long long; 
using P = pair<int,int>;
using vv = vector<vector<ll>>;
template <class _t> inline bool chmax (_t& a,_t b){if(a<b){a=b;return true;}return false;} template <class _t> inline bool chmin (_t& a,_t b){if(a>b){a=b;return true;}return false;}

const long long inf = 1ll << 60;
const long long mod = 1000000007;

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

int main() {
    int n;cin >> n;
    string s;cin >> s;
    if(s.size()<=n){
	cout << s << endl;
	return 0;
    }
    for(int i=0;i<n;i++){
	cout << s[i];
    }
    cout << "..." << endl;
    return 0;
}


Measured memory_bytes: 3596
# Nとcの定義
N = int(input())
C = input()

# 赤色の個数
red_num = str.count(C, "R")

# 左からred_num個までに含まれる白色の個数
white_num_left = str.count(C[:red_num], "W")

# 最小の操作回数
min_ope = white_num_left

# 最小の操作回数の出力
print(min_ope)

Measured memory_bytes: 9292
import java.util.*;


public class Main {

    private static final int INF = Integer.MAX_VALUE;

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

        List<Integer> list = new ArrayList<>();
        for(int tmp = 0; tmp< n; tmp++){
            int a = sc.nextInt();
            list.add(a);
        }
        int result = 0;

        for(int tmp = 1; tmp<n -1; tmp++){
            int pm = list.get(tmp - 1);
            int p = list.get(tmp);
            int ph = list.get(tmp + 1);

            if((pm < p && p<ph) || (pm >p && p>ph)){

                    result++;
            }
        }

        System.out.println(result);



    }
}


Measured memory_bytes: 23252
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A,B;
  int result = 0;
  cin >> A >> B;
  for(int i = A; i <= B; i++){
    string num = to_string(i);
    if(num[0] == num[4] && num[1] == num[3])
      result++;
  }
  cout << result << endl;
}

Measured memory_bytes: 256
/** @xigua */
#include <stdio.h>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <cstring>
#include <queue>
#include <set>
#include <string>
#include <map>
#include <climits>
#include <bitset>
#include <ctime>
#define PI acos(-1)
using namespace std;
typedef long long ll;
typedef double db;
const int maxn = 1e5 + 5;
const int mod = 1e9 + 7;
const int INF = 1e8 + 5;
const ll inf = 1e15 + 5;
const db eps = 1e-8;
const ll hp = 2333;
const ll base = 1e9+13;

void solve() {
    int c[15][15];
    ll dp[15][15];
    ll n, m; //int a[205][205];

    while (cin >> n >> m) {
        ll ans = 0;
        for (int i = 0; i <= 9; i++) {
            for (int j = 0; j <= 9; j++) {
                cin >> dp[i][j];
               // dp[i][j] = c[i][j];
            }
        }
        for (int k = 0; k <= 9; k++) {
        for (int i = 0; i <= 9; i++) {
            for (int j = 0; j <= 9; j++) {
                    dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]);
                }
            }
        }
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= m; j++) {
                int x; cin >> x;
                if (x == -1) continue;
                ans += dp[x][1];
              //  cout << dp[x][1] << endl;
            }
        }
        cout << ans << endl;
    }
}

int main() {
    int t = 1, cas = 1;
   //memset(dp, 0, sizeof(dp));
 //  freopen("in.txt", "r", stdin);
   // freopen("out.txt", "w", stdout);
   // scanf("%d", &t);
    while(t--) {
        solve();
    }
    return 0;
}


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

int main(void){

    vector<int> input(10,0);
    
    int times;
    cin >> times;

    while(times > 0){

        for(int i = 0;i < 10;i++){
            cin >> input[i];
        }
        vector<int> a(10,0);
        vector<int> b(11,0);
        a[0] = input[0];
        int j = 1,k = 0,flag = 1;
        int keep1 = 0,keep2 = 0;
        
        for(int i = 1;i < 10;i++){

            if(a[j-1] < input[i] && b[k] < input[i]){
                a[j++] = input[i];
            }else if(b[k] < input[i]){
                b[k] = input[i];
            }else{
                flag = 0;
                break;
            }
        }

        if(flag){
            cout << "YES" << endl;
        }else{
            cout << "NO" << endl;
        }
        times--;
    }




    return 0;
}

Measured memory_bytes: 3064
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <regex>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
using ll = long long;
using VL=vector<ll>;

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
const long long INF =  99999999999;
ll N,K;
const ll M = 1000000007;

vector<ll> fac(300001); //n!(mod M)
vector<ll> ifac(300001); //k!^{M-2} (mod M)
//a,bの範囲的にこれだけ配列を用意していけば十分

ll mpow(ll x, ll n){ //x^n(mod M) ←普通にpow(x,n)では溢れてしまうため，随時mod計算
    ll ans = 1;
    while(n != 0){
        if(n&1) ans = ans*x % M;
        x = x*x % M;
        n = n >> 1;
    }
    return ans;
}

ll comb(ll a, ll b){ //aCbをmod計算
    if(a == 0 && b == 0)return 1;
    if(a < b || a < 0)return 0;
    ll tmp = ifac[a-b]* ifac[b] % M;
    return tmp * fac[a] % M;
}

int main()
{
    cin >> N >> K;
    vector<ll> a(N+1);
    a[0]=-INF;
    FOR(i,1,N+1)cin>>a[i];
    sort(a.begin(),a.end());

    //大した量ではないので，先にfax[i]とifax[i]を全て計算しておく
    fac[0] = 1;
    ifac[0] = 1;
    for(ll i = 0; i<100020; i++){
        fac[i+1] = fac[i]*(i+1) % M; // n!(mod M)
        ifac[i+1] = ifac[i]*mpow(i+1, M-2) % M; // k!^{M-2} (mod M) ←累乗にmpowを採用
    }

    ll ans=0;
    for(int i=K;i<=N;i++){
      ans+=(a[i]*comb(i-1,K-1)%M+M)%M;
      ans%=M;
    }
    for(int i=1;i<=N-K+1;i++){
      ans-=(a[i]*comb(N-i,K-1)%M+M)%M;
      ans=(ans+M)%M;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 5760
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<deque>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#include<iomanip>
#include<cassert>
#include<regex>
#include<bitset>
#include<complex>
#include<chrono>
#include<random>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

ll gcd(ll n, ll m) {
	ll tmp;
	while (m!=0) {
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m) {
	return abs(n * m) / gcd(n, m);//gl=xy
}
 
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;
}
 
using namespace std;
//ここから
int n;
vector<ll>h;
ll a,b;
bool C(ll mid){
  vector<ll>v=h;
  ll sum=0;
  rep(i,n){
    v[i]-=b*mid;
  }
  rep(i,n){
    if(v[i]>0)sum+=(v[i]+a-b-1)/(a-b);
  }
  return sum<=mid;
}
void solve(){
  cin>>n>>a>>b;
  h.resize(n);
  rep(i,n)cin>>h[i];
  ll l=0,r=1e9;
  while(r-l>1){
    ll mid=(l+r)/2;
    if(C(mid))r=mid;
    else l=mid;
  }
  cout<<r;
}

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


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<int(n);++i)
#define all(a) (a).begin(),(a).end()
typedef long long ll;
#define rep1(i,n) for(int i=1;i<=int(n);++i)
#define lb(s,x) (lower_bound(all(s),x)-s.begin())


using P = pair<ll,ll>;
#define w first
#define v second

vector<P> all_enumerate(vector<P> vp, ll W, bool need_sort){
    int N = vp.size();
    vector<P> dp;
    for (int mask = 0; mask < (1<<N); mask++) {
        ll sumV = 0, sumW = 0;
        for (int i = 0; i < N; i++) {
            if (mask & (1<<i)) {
                sumV += vp[i].v;
                sumW += vp[i].w;
            }
        }
        if (sumW <= W) {
            dp.push_back({sumW, sumV});
        }
    }
    if (!need_sort) return dp;
    // V降順
    sort(dp.begin(), dp.end(), [](P a, P b){
        return a.v != b.v ? a.v > b.v : a.w < b.w;
    });
    vector<P> res;
    int w_border = W+1;
    for(P s : dp){
        if( w_border > s.w){
            w_border = s.w;
            res.push_back(s);
        }
    }
    // V昇順 & W昇順
    reverse(res.begin(), res.end());
    return res;
}

int main(void){
    cin.tie(0); ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> v(n+1),w(n+1);
    rep1(i,n){
        cin >> v[i] >> w[i];
    }
    int H2 = log2(n)/2 + 4;
    vector<vector<P>> dp((1<<H2)+1);
    for (int i = 1; i < (1<<H2); i++) {
        if (i > n) break;
        vector<P> vp;
        int x = i;
        while(x) {
            vp.push_back({w[x], v[x]});
            x /= 2;
        }
        dp[i] = all_enumerate(vp, 100000LL, true);
    }
    int Q;
    cin >> Q;
    rep(q,Q){
        int x, L;
        cin >> x >> L;
        vector<P> vp;
        while((1<<H2) <= x) {
            vp.push_back({w[x], v[x]});
            x /= 2;
        }
        vector<P> dp1 = dp[x];
        vector<P> dp2 = all_enumerate(vp, L, false);
        ll max_v = 0;
        for (P p : dp2) {
            int pos = lb(dp1, P({L - p.w + 1, 0LL})) - 1;
            if (pos < 0) {
                if (p.w <= L) {
                    max_v = max(max_v, p.v);
                }
            } else {
                if (p.w + dp1[pos].w <= L) {
                    max_v = max(max_v, p.v + dp1[pos].v);
                }
            }
        }
        cout << max_v << endl;
    }
    return 0;
}




Measured memory_bytes: 158716
# -*- coding:utf8 -*-

n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

ans = 0
for i in range(n):
    ans += b[a[i] - 1]
    if i != 0 and a[i] == a[i - 1] + 1:
        ans += c[a[i - 1] - 1]
print(ans)

Measured memory_bytes: 3064
#import<iostream>
main(){std::string s;std::cin>>s;long long r=0,d=0,i=0,b,c;for(;i<s.size();d=b^c?0:d){b=s[i]==66,c=s[i+1]>66;s[i++]<66?d++:r+=b&c?d:0;}std::cout<<r;}

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

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

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

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

int main(){
    int n, k; cin>>n>>k;
    vector<ll> a(n), maxsum(n, 0), sum(n, 0);
    for(int i=0; i<n; i++){
        cin>>a[i];
        if(i==0){
            if(a[0]>0) maxsum[0]=a[0];
            sum[0]=a[0];
        }
        else{
            if(a[i]>0) maxsum[i]=maxsum[i-1]+a[i];
            else maxsum[i]=maxsum[i-1];
            sum[i]=sum[i-1]+a[i];
        }
    }

    if(n==k){
        cout << (sum[n-1]>0?sum[n-1]:0) << endl;
        return 0;
    }

    ll ans=max(sum[k-1]+(maxsum[n-1]-maxsum[k-1]), (sum[n-1]-sum[n-k-1])+maxsum[n-k-1]);
    ans=max({ans, maxsum[n-1]-maxsum[k-1], maxsum[n-k-1]});
    for(int i=1; i+k<n; i++){
        ans=max(ans, (sum[i+k-1]-sum[i-1])+(maxsum[n-1]-maxsum[i+k-1])+(maxsum[i-1]));
        ans=max(ans, (maxsum[n-1]-maxsum[i+k-1])+(maxsum[i-1]));
    }
    cout << ans << endl;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define INF 2147483647//int max
const int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,int>;


int main() {
    int a,b;
    cin >> a >> b;
    int h = 0;
    for(int i=1;i<b-a;i++){
        h += i;
    }
    cout << h-a << endl;
    return 0;
}

/*
やっほい！
　　　　　　　やほほい！
　　　　+　　 　*
　　　 ∧∧　　. ∧∞∧　*
*　ヽ(=´ω｀)人(´ω｀*)ﾉ
　.～（ O x.） （ 　 O)～　+
。*　 　∪　　　　∪
*/

Measured memory_bytes: 256