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

#define rep(i, n) for(long long i=0;i<(long long)(n);i++)
#define rep2(i, s, n) for(long long i=(s);i<(long long)(n);i++)
#define repi(i, n) for(int i=0;i<(int)(n);i++)
#define rep2i(i, s, n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(), v.end()

#define deg2rad(deg) (((deg)/360)*2*M_PI)
#define rad2deg(rad) (((rad)/2/M_PI)*360)

using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;

const ll INF = (1LL<<60);
const int INFi = (1<<29);

/*素数判定*/
bool is_prime(ll n){
    if(n==1) return false;
    for(ll i=2;i*i<=n;i++){
        if(n%i==0) return false;
    }
    return true;
}

/*約数列挙*/
vll enum_divisors(ll n){
    vll l;
    for(ll i=1;i*i<=n;i++){
        if(n%i==0){
            l.push_back(i);
            if(n/i != i) l.push_back(n/i);
        }
    }
   sort(all(l));
   return l;
}

/*素因数分解*/
vector<P> prime_factorize(ll n){
    vector<P> l;
    for(ll i=2;i*i<=n;i++){
        if(n%i!=0) continue;
        ll e = 0;
        while(n%i==0){
            e++;
            n /= i;
        }
        l.push_back({i, e});
    }
    if(n!=1) l.push_back({n, 1});
    return l;
}

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

/*最大公約数*/
ll gcd(ll a, ll b){
    return __gcd(a,b);
}

int main(){

    ll n, k; cin >> n >> k;
    vll p(n);
    ll mx = 0;
    rep(i, n){
        cin >> p[i];
        mx = max(mx, p[i]);
    }

    vll s(mx+1);
    s[0] = 0;
    rep2(i, 1, mx+1){
        s[i] = s[i-1] + i;
    }

    vector<ld> q(n);
    rep(i,n){
        q[i] = (ld)s[p[i]]/(ld)p[i];
    }

    ld sum = 0;
    rep(i, k) sum += q[i];

    ld mx_sum = sum;
    for(ll i=0;i+k<n;i++){
        sum = sum - q[i] + q[i+k];
        mx_sum = max(mx_sum, sum);
    }

    cout << fixed << setprecision(10) << mx_sum << endl;

    return 0;
}

Measured memory_bytes: 7996
n,m,l=map(int, input().split())
A=[list(map(int, input().split())) for i in range(n)]
B=[list(map(int, input().split())) for j in range(m)]
C=[[0 for i in range(l)] for i in range(n)]

for i in range(n):
    for j in range(l):
        for k in range(m):
            C[i][j]+=A[i][k]*B[k][j]
    print(*C[i])



Measured memory_bytes: 7048
#include <iostream>

using namespace std;

bool input(bool board[][12])
{
	char buf[13];
	for (int i=0; i<12; i++) {
		if ( !(cin >> buf) ) return false;
		for (int j=0; j<12; j++) board[i][j] = buf[j] - '0';
	}
	return true;
}

void DFS(bool board[][12], int comp[][12], int comp_num, pair<int, int> pos)
{
	int i = pos.first;
	int j = pos.second;
	
	if (comp[i][j] == comp_num) return;
	comp[i][j] = comp_num;
	
	if (i>0  && board[i-1][j] && comp[i-1][j]==0) DFS(board, comp, comp_num, pair<int,int>(i-1,j) );
	if (i<11 && board[i+1][j] && comp[i+1][j]==0) DFS(board, comp, comp_num, pair<int,int>(i+1,j) );
	if (j>0  && board[i][j-1] && comp[i][j-1]==0) DFS(board, comp, comp_num, pair<int,int>(i,j-1) );
	if (j<11 && board[i][j+1] && comp[i][j+1]==0) DFS(board, comp, comp_num, pair<int,int>(i,j+1) );
}

int main()
{
	bool board[12][12];
	
	while ( input(board) ) {
		int component[12][12];
		for (int i=0; i<12; i++) {
			for (int j=0; j<12; j++) component[i][j] = 0;
		}
		
		int component_num = 0;
		
		for (int i=0; i<12; i++) {
			for (int j=0; j<12; j++) {
				if (!board[i][j]) continue;
				if (component[i][j] > 0) continue;
				component_num++;
				DFS( board, component, component_num, pair<int,int>(i,j) );
			}
		}
		cout << component_num << endl;
	}
	
	return 0;
}

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

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

const ll mod =  1000000007;
const int inf = 1e9;
const long long INF = 1LL << 60;   // INFの値は1152921504606846976

ll pow(ll x,ll n){  // xのn乗 (mod m)
    ll res = 1;
    if(n > 0){
        res = pow(x,n / 2);
        if(n % 2 == 0){
            res = (res * res) % mod;
        }else{
            res = (((res * res) % mod) * x) % mod;
        }
    }
    return res;
}

int main()
{
    ll n,k;  cin >> n >> k;
    ll ans = 0;
    ll cnt[k+1];   // sub[i] := iのときのgcdの数
    rep(i,k+1) cnt[i] = 0;

    for(int i = k; i >= 1; i--){
        cnt[i] = pow(k/i,n);
        for(int j = 2 * i; j < k + 1; j += i){
            cnt[i] -= cnt[j];
        }
    }
    //rep(i,k+1) cout <<cnt[i] << endl;

    for(int i = k; i >= 1; i--){
        ans += ( i * cnt[i] );
        //cout << i << ':' << pow((k/i),n) - pow((k/i)-1,n) << endl;
        ans %= mod;
    }
    cout << (ans+mod*2)%mod << endl;
}


Measured memory_bytes: 4376
#include<bits/stdc++.h>
using namespace std;
int a[200000], b[200000];
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	for (int i = n - 1; i >= 0; i--) {
		cin >> b[i];
	}
	int lbound = -1, ubound = -1;
	for (int i = 0; i < n; i++) {
		if (a[i] == b[i]) {
			lbound = i;
			int j;
			for (j = i + 1; j < n && a[j] == b[j]; j++);
			ubound = j;	
			break;
		}
	}
	if (lbound == -1) {
		cout << "Yes\n";
		for (int i = 0; i < n; i++) {
			cout << b[i] << ' ';
		}
		cout << '\n';
		return 0;
	}
	int share = a[lbound];
	int k = 0;
	int miss = 0;
	while (miss < n && lbound < ubound) {
		if (a[k] != share && b[k] != share) {
			b[lbound++] = b[k];
			b[k] = share;
			miss = 0;
		}
		k = (k + 1) % n;	
		miss++;
	}
	if (miss < n) {
		cout << "Yes\n";
		for (int i = 0; i < n; i++) {
			cout << b[i] << ' ';
		}
		cout << '\n';
	} else {
		cout << "No\n";
	}
	return 0;
}


Measured memory_bytes: 5204
import sys
sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline    ####
def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')
# from math import ceil, floor, log2
# from collections import deque
# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
# import numpy as np    # cumsum
# from bisect import bisect_left, bisect_right

def solve():
    N, M, K = MI()
    
    if K == 0:
        print('Yes')
        return

    for i in range(N+1):
        cnt = i * M
        for j in range(M+1):
            # jd = cnt + (N - i) * j - i * j
            jd = cnt + (N - 2 * i) * j
            # print(i, j, jd)
            if jd == K:
                print('Yes')
                return
    print('No')


if __name__ == '__main__':
    solve()


Measured memory_bytes: 9164
#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);
  }
  sort(a.begin(),a.end());
  int ans = a.at(n - 1) - a.at(0);
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <queue>

using ll = long long int;

int main(int argc,char *argv[])
{
	ll n;
	std::cin >> n;

	std::vector<ll> a(n-1,0);
	for (int i = 0;i < n-1;++i) { std::cin >> a[i]; }

	std::sort(a.begin(), a.end());
	
	std::vector<ll> p(n-1,0);
	ll idx = 0;
	++p[a[idx]-1];
	for (int i = 1;i < n-1;++i)
	{
		if (a[idx] != a[i])
		{
			idx = i;
		}
			++p[a[idx]-1];
	}

	for (int i = 0;i < n-1;++i) { std::cout << p[i] << std::endl; }
	std::cout << 0 << std::endl;

	return 0;
}

Measured memory_bytes: 6432
import math
n,d = map(int,input().split())
cnt = 0
x = []
for i in range(n):
    a = list(map(int,input().split()))
    x.append(a)
for i in range(n):
    for j in range(i):
        dis = 0
        for k in range(d):
            dis += (x[i][k]-x[j][k])**2
        dis = math.sqrt(dis)
        if dis.is_integer():
            cnt+=1
print(cnt)

Measured memory_bytes: 3064
import sys
from collections import deque

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


def main():
    N = input()
    length = len(N)
    K = int(input())

    # 左からi桁目まで見て，N以下が確定していて，0でない数字がk個ある数字の個数
    dp_1 = [[0] * (10) for _ in range(length)]

    # 左からi桁目まで見て，N以下が確定していなくて，0でない数字がk個ある数字の個数
    dp_2 = [[0] * (10) for _ in range(length)]

    dp_1[0][0] = 1
    dp_1[0][1] = int(N[0]) - 1

    dp_2[0][1] = 1

    for i in range(1, length):
        # 小さいのが確定しているものに対して，0以外のものを追加
        for k in range(1, K + 2):
            dp_1[i][k] += dp_1[i - 1][k - 1] * 9

        # 小さいものが確定しているものに対して，0を追加
        for k in range(0, K + 2):
            dp_1[i][k] += dp_1[i - 1][k]

        # 大小がわからないものから，小さいのが確定する
        if N[i] == "0":
            for k in range(K + 2):
                dp_2[i][k] += dp_2[i - 1][k]
        else:
            # 0を追加する
            for k in range(K + 2):
                dp_1[i][k] += dp_2[i - 1][k]

            # その他の数字を追加
            for k in range(1, K + 2):
                dp_1[i][k] += dp_2[i - 1][k - 1] * (int(N[i]) - 1)

            # 依然として大小関係がわからない
            for k in range(1, K + 2):
                dp_2[i][k] += dp_2[i - 1][k - 1]

    ans = dp_1[-1][K] + dp_2[-1][K]
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3316
#include <iostream>
#include <cmath>


int stepTime;
int m;


double calcMean(int currentStep, double acceptProb){

	
	double sumUp = (double)(currentStep * stepTime) * acceptProb;

	if(sumUp <= 0.01){
		return 0;
	}
	else{
		acceptProb = std::pow((1.0 - 1.0 / std::pow(2, m)), currentStep) / std::pow(2, m);

		return sumUp + calcMean(currentStep + 1, acceptProb);
	}

}


int main(void){

	int n;
	std::cin >> n >> m;

	stepTime = 100 * (n - m) + 1900 * m;

	std::cout << (int)(calcMean(1, 1.0 / std::pow(2, m) ) + 0.5) << std::endl;

	return 0;
}

Measured memory_bytes: 256
n,k,s = gets.split.map &:to_i

if n > s then
	puts ([s] * k + [s + 1] * (n - k)).join(" ")
else
	r = n - k + 1

	div = s / r
	mod = s % r

	result = [div] * r

	(-mod .. -1).each{ |i|
		result[i] += 1
	}

	n_div = n / result.size
	n_mod = n % result.size

	puts (result * n_div + result[0...n_mod]).join(" ")
end

Measured memory_bytes: 5500
using System;

class Program
{
    static void Main()
    {
        int input = -1;
        int smallest = 1000000;
        int x = 0;
        int threez = 0;
        
        input = int.Parse(Console.ReadLine());
        while(input != 0) {
            smallest = 1000000;
            for(int z = 0; Math.Pow(z, 3) <= input; z++) {
                threez = (int)Math.Pow(z, 3);
                for(int y = 0; Math.Pow(y, 2) <= input - threez; y++) {
                    x = input - threez - (int)Math.Pow(y, 2);
                    if (x + y + z < smallest) {
                        smallest = x + y + z;
                    }
                }
            }
            Console.WriteLine(smallest);
            input = int.Parse(Console.ReadLine());
        }
    }
}

Measured memory_bytes: 5836
#include <iostream>
#include <cstring>
#include <algorithm>
#include <deque>
using namespace std;

#define rep(i, N) for(int (i) = 0; (i) < N; (i) ++)
#define rrep(i, N) for(int (i) = (N); (i) >= 0; (i) --)
#define pint pair<int, int>
#define INF 1e9

typedef long long ll;

#include <vector>
#include <stack>

ll gcd(ll a, ll b){
    if(a < b){
        return gcd(b, a);
    }
    if(b == 0) return a;
    return gcd(b, a % b);
}

int main(){
    int N;
    int K;
    cin >> N >> K;
    ll cd = -1;
    ll a_max = 0;
    rep(i, N){
        ll a;
        cin >> a;
        cd = (cd < 0) ? a : cd;
        cd = gcd(a, cd);
        a_max = max(a_max, a);
    }
    if(cd == gcd(cd, K) && K <= a_max){
        cout << "POSSIBLE" << endl;
    }else{
        cout << "IMPOSSIBLE" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
checkclass :: Double -> String
checkclass w 
    | w<=48.00  = "light fly"
    | w<=51.00  = "fly"
    | w<=54.00  = "bantam"
    | w<=57.00  = "feather"
    | w<=60.00  = "light"
    | w<=64.00  = "light welter"
    | w<=69.00  = "welter"
    | w<=75.00  = "light middle"
    | w<=81.00  = "middle"
    | w<=91.00  = "light heavy"
    | otherwise = "heavy"

solve::Double-> IO ()
solve w = do
    putStrLn $ checkclass w

main::IO ()
main=do
    str<-getContents::IO String
    mapM_ solve $ map (\x->read x::Double) . lines $ str

Measured memory_bytes: 4020
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        String ans = "";
        for(int i = 0; i < s.length();i++){
            ans += "x";
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 23252
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007
const int MAX = 510000;
const int MOD = 1000000007;

ll a[100010];
ll c[100010];
vector<vector<ll>>b(100010);
void dep(ll now,ll p,ll root){
	c[now]=root;
	if(b[now].size()==1&&b[now][0]==p){
		return ;
	}
	for(int i=0;i<b[now].size();i++){
		ll next=b[now][i];
		if(next==p||c[next]!=-1){
			continue;
		}
		dep(next,now,root);
	}
}

int main() {
	ll n,m;
	cin>>n>>m;
	for(int i=0;i<100010;i++){
		c[i]=-1;
	}
	for(int i=0;i<n;i++){
		ll x;
		cin>>x;x--;
		a[i]=x;
	}
	for(int i=0;i<m;i++){
		ll x,y;
		cin>>x>>y;x--;y--;
		b[x].push_back(y);
		b[y].push_back(x);
	}
	for(int i=0;i<100010;i++){
		if(c[i]!=-1){
			continue;
		}
		dep(i,-1,i);
	}
	ll ans=0;
	for(int i=0;i<n;i++){
		ll now=a[i];
		if(i==now){
			ans++;
			continue;
		}
		ll root =c[now];
		if(root==c[i]){
			ans++;
		}
	}
	cout << ans;
	// your code goes here
	return 0;
}

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

#define IOS cin.tie(0);ios_base::sync_with_stdio(false)

#define ll      long long
#define Fi      first
#define Se      second
#define Pb      push_back
#define vi      vector<int>
#define vs      vector<string>
#define vp      vector<pair<int,int>>
#define vvi     vector<vector<int>>
#define vvp     vector<vector<pair<int,int>>>
using Graph  =  vector<vector<int>>; //Caution!! Segmentation Fault!! Don't forget to add +1!

#define sz(x) (int)x.size()
#define all(v) v.begin(),v.end()
#define output_s(s) printf("%s\n",(s).c_str())

#define rep(i,n)        for(int i=0;i<(int)(n);i++)
#define Rep(i,n,m)      for(int i=(int)(n);i<(int)(m);i++)
#define RepS(i,n,m)     for(int i=(int)(n);i<=(int)(m);i++)
#define RRepS(i,n,m)    for(int i=(int)(n);i>=(int)(m);i--)
#define SRepS(i,n,m)     for(int i=(int)(n);i*i<=(int)(m);i++)
#define RepA(x)         for(auto &item:(x))

void CINT(){} //@shibh308's template
template<class Head,class... Tail> void CINT(Head&& head,Tail&&... tail){cin>>head; CINT(move(tail)...);}    
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)
#define VCIN(x) for(auto &item:x) cin>>item

void OUT(){}
template<class Head,class...Tail> void OUT(Head&& head,Tail&&...tail){cout<<head<<(sizeof...(tail)?" ":"\n"); OUT(move(tail)...);}
#define COUT(...) OUT(__VA_ARGS__)

template<typename TypeInt>TypeInt GCD(TypeInt a,TypeInt b){return a%b==0?b:GCD(b,a%b);} //最大公約数
template<typename TypeInt>TypeInt LCM(TypeInt a,TypeInt b){return a*b/GCD(a,b);} //最小公倍数
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return true;}return false;}
template<class T>bool comp(T a,T b){return abs(a)<abs(b);} //比較関数

void YES(bool f){printf(f?"YES\n":"NO\n");}
void Yes(bool f){printf(f?"Yes\n":"No\n");}
void Possible(bool f){printf(f?"Possible\n":"Impossible\n");}
void POSSIBLE(bool f){printf(f?"POSSIBLE\n":"IMPOSSIBLE\n");}

//----------------------library------------------------//

//const int dx[4]={1,0,-1,0};
//const int dy[4]={0,1,0,-1};
const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};
const int NMAX = 200;
const int INF = 1e9;
const int MOD = 1e9+7;
bool flag;

//----------------------Global-------------------------//

signed main(){
    CIN(N);
    int ans;
    vi A(N-1);
    rep(i,N-1)cin>>A[i];
    ans=A[0]+A[N-2];
    Rep(i,1,N-1){
        ans+=min(A[i],A[i-1]);
    }
    printf("%d\n",ans);

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
 
int main(void)
{
    int a, b, c, d, e, f;
    scanf("%d %d %d", &a, &b, &c);
    d = a + b;
    e = b + c;
    f = c + a;
    if ((d <= e) && (d <= f)){
    printf("%d",d);
    }
    else if ((e <= f) && (e <= d))
    {
        printf("%d", e);
    }
    else
    {
        printf("%d", f);
    }
    return 0;
}

Measured memory_bytes: 128
N , M = map(int,input().split())
a = []
for i in range(N):
    ll = list(map(int,input().split()))
    a.append(ll)

a_sort = sorted(a,key=lambda x:x[0])

cash = 0
for i in range(N):
    if M == 0:
        break
    elif M - a_sort[i][1] > 0:
        cash += a_sort[i][0] * a_sort[i][1]
        M -= a_sort[i][1]
    else:
        cash += M * a_sort[i][0]
        M = 0
print(cash)

Measured memory_bytes: 29792
#include <iostream>
#include <set>
#include <vector>
using namespace std;
int main(void){
    int n, cnt = 0;
    multiset<int> ms;
    vector<int> v;
    cin >> n;
    for(int i=0;i<(1<<n);i++){
        int s;
        cin >> s;
        ms.insert(s);
    }
    {
        auto itr = ms.end(); itr--;
        v.push_back(*itr);
        //cout << (*itr) << endl;
        ms.erase(itr);
    }

    for(int i=1;i<=n;i++){
        int vs = v.size();
        for(int j=0;j<vs;j++){
            /*cout << "---" << endl;
            for(int x : ms){
                cout << (x) << endl;
            }
            cout << "---" << endl;*/
            auto itr = ms.lower_bound(v[j]);
            if(itr == ms.begin()){
                puts("No");
                return 0;
            }
            itr--;
            //cout << (*itr) << endl;
            v.push_back(*itr);
            ms.erase(itr);
        }
    }
    puts("Yes");
}


Measured memory_bytes: 13692
n, l = [int(i) for i in input().split()]
num = 0
a = []
for i in range(n):
  num += i + l
  a.append(i+l)
if(l >= 0):
  ans = num - min(a)
  print(ans)
else:
  if(max(a) >= 0):
    print(num)
  else:
    ans = num - max(a)
    print(ans)
    


Measured memory_bytes: 3316
n = gets.chomp.to_i
h = gets.chomp.split(" ").map(&:to_i)
max = 0
count = 0
i = 0

while true
    if h.size == 1
        puts max
        break
    end
    if h[i] >= h[i+1]
        count += 1
        #p count
    else
        
        count = 0
    end
    max = [max,count].max
    i += 1
    if i == n-1
        puts max
        break
    end
    
end


Measured memory_bytes: 21908
(defparameter n (read))
(defparameter target-list (loop for i from 1 to n by 2 collect i))

(defun count-8 ()
  (count 8 (mapcar #'calc-divisor target-list)))

(defun calc-divisor (num)
  (loop for i from 1 to num count (= 0 (mod num i))))

(princ (count-8))

Measured memory_bytes: 13408
#define ll long long
#define INF 99999999
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#include<bits/stdc++.h>
using namespace std;
int main (){
    int k,n;
    cin >> k >> n;
    vector<int> a(n+1);
    vector<int> b(n);
    int ans =0;
    rep(i,n){
        cin >>a[i];
    }
    a[n] = k+ a[0];
    rep(i,n){
        b[i] = a[i+1] - a[i];
    }
    sort(b.begin(),b.end());
    rep(i,n-1){
        ans += b[i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<algorithm>
using namespace std;
static const int MAX=2000000;
int main(){
    int n;
    int R[MAX];
    cin>>n;
    for(int i=0;i<n;i++){
        cin >>R[i];
    }
    int maxv = -1000000000;
    int minv =R[0];
    for(int i=1;i<n;i++){
       maxv =max(maxv,R[i] - minv);
       minv = min(minv,R[i]);
    }
   
    cout<<maxv<<endl;
    return 0;
}


Measured memory_bytes: 3904
main :: IO ()
main = do
    [n, m, x, y] <- readInts
    xs           <- readInts
    ys           <- readInts
    putStrLn $ if solve n m x y xs ys then "No War" else "War"

solve :: Int -> Int -> Int -> Int -> [Int] -> [Int] -> Bool
solve n m x y xs ys = any (\z -> maximum xs < z && minimum ys >= z) [x + 1 .. y]

readInts :: IO [Int]
readInts = map read . words <$> getLine

Measured memory_bytes: 1020
#include<stdio.h>

int a,b;

int main()
{
	scanf("%d%d",&a,&b);
	int i;
	bool flag=0;
	for(i=1;i<=1250;i++)
	{
		if((int)(i*0.08)==a && (int)(i*0.1)==b)
		{
			printf("%d\n",i);
			flag=1;
			break;
		}
	}
	if(flag==0)printf("-1\n");
}


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

int main() {
	int n;
	cin>>n;
	int a[n],b[n],c[n-1];
	for(int i=0;i<n;i++)
		{
			cin>>a[i];
			a[i]--;
		}
	for(int i=0;i<n;i++)
		cin>>b[i];
	for(int i=0;i<n-1;i++)
		cin>>c[i];
	int ans=0;
	ans+=b[a[0]];
	for(int i=1;i<n;i++)
	{
		ans+=b[a[i]];
		if(a[i]==a[i-1]+1)
		{
			ans+=c[a[i-1]];
		}
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
s = input()
dat = []
# 0 = R, L = 1
mode = 0
r = 0
l = 0
for i in range(len(s)):
    if mode == 0:
        if s[i] == "R":
            r += 1
        elif s[i] == "L":
            l += 1
            mode = 1
    elif mode == 1:
        if s[i] == "L":
            l += 1
        elif s[i] == "R":
            dat.append((r, l))
            mode = 0
            l = 0
            r = 1
# 最後のLの処理
dat.append((r, l))
res = []
for r,l in dat:
    t = r + l
    if t % 2 == 1:
        for i in range(r-1):
            res.append("0")
        if r %2 == 1:
            res.append(str(t//2+1))
            res.append(str(t//2))
        else:
            res.append(str(t // 2))
            res.append(str(t // 2+1))
        for i in range(l-1):
            res.append("0")
    else:
        for i in range(r-1):
            res.append("0")
        res.append(str(t//2))
        res.append(str(t//2))
        for i in range(l-1):
            res.append("0")
print(" ".join(res))


Measured memory_bytes: 57968
import math
N, K = (int(i) for i in input().split())

if K == 1:
    pow_base = 1
else:
    pow_base = math.floor(math.log((K-1),2)) + 1
base = N * (2 ** pow_base)

res = 0
for i in range(1, N+1):
    if i >= K :
        res += (2 ** pow_base)
    else:
        power = math.floor(math.log((K-1) // i, 2)) + 1
        res += 2 ** (pow_base - power)
print(res / base)




Measured memory_bytes: 38768
#include <bits/stdc++.h>
typedef long long ll;
const ll INF = 1e9;
const ll MOD = 1e9+7;
const ll LINF = 1e18;
using namespace std;

#define dump(x)  cout << #x << " = " << (x) << endl;
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl
#define possible(n) cout << ((n) ? "possible" : "impossible"  ) << endl

#define SANKOU(n,a,b) cout << ((n) ? (#a) : (#b) ) << endl

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define REP(i,n) for(ll i=0;i<(n);++i)
#define REPR(i,n) for(ll i=n;i>=0;i--)

#define FOREACH(x,a) for(auto&& (x) : (a) )

#define WFA(d,v) REP(k,v)REP(i,v)REP(j,v)d[i][j]=min(d[i][j],d[i][k]+d[k][j])

#define SCOUT(x) cout<<(x)<<" "
#define ENDL cout<<endl

#define VECCIN(x) for(auto&youso_: (x) )cin>>youso_
#define VECIN2(x,y) REP(i,x.size())cin>>x[i]>>y[i]
#define VECCOUT(x) if(1){for(auto tt=x.begin();tt!=x.end();tt++){if(tt!=x.begin())cout<<" ";cout<<(*tt);}cout<<endl;}

#define ALL(obj) (obj).begin(),(obj).end()

#define EXIST(n,x) (find(ALL(n),x)!=n.end())
#define UNIQUE(obj) sort(ALL( obj )); obj.erase(unique(ALL(obj)),obj.end())
#define EN(x) if(1){cout<<#x<<endl;return 0;}
#define COUT(x) cout<<(x)<<endl
void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail){
    cin>>head;
    CINT(move(tail)...);
}
#define CIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

template <class T = ll>
T IN(){T x;cin>>x;return (x);}

template <class Head>
void VT(Head head){}
template <class Head,class Seco,class... Tail>
void VT(Head&& head,Seco&& seco,Tail&&... tail){
    seco.resize(head);
    VT(head,move(tail)...);
}
void VT2(){}
template <class Head,class... Tail>
void VT2(Head&& head,Tail&&... tail){
  VECCIN(head);
  VT2(move(tail)...);
}

template <class Head>
void VT3(Head&& head){}
template <class Head,class Seco,class... Tail>
void VT3(Head&& head,Seco&& seco,Tail&&... tail){
  seco[head]=IN();
  VT3(head,move(tail)...);
}

#define VC1(n,...) V __VA_ARGS__;VT(n,__VA_ARGS__);VT2(__VA_ARGS__); //aaabbbccc
#define VC2(n,...) V __VA_ARGS__;VT(n,__VA_ARGS__);REP(i,n)VT3(i,__VA_ARGS__); //abcabcabc

// #include <boost/multiprecision/cpp_ll.hpp>
// using namespace boost::multiprecision; // cpp_ll

#define P pair<ll,ll>
#define V vector<ll>
#define M map<ll,ll>
#define S set<ll>

#define pb(a) push_back(a)
#define mp make_pair

signed main(){
    SCIN(s, t);
    vector<S> vt(26);
    int n = t.size();
    REP(i,n)vt[t[i]-'a'].insert(i);
    REP(i,n){
        REP(j,26){
            if(vt[j].count(i)){
                swap(vt[j], vt[s[i]-'a']);
                break;
            }
        }
    }
    string k(n, 'X');
    REP(j,26)FOREACH(xx,vt[j])k[xx]=j+'a';
    Yes(k==s);

}


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


void solve(long long X){
    int k = 0;
    int g = 0;
    k = X / 500;
    X = X - (k*500);

    g = X / 5;
    cout << k*1000 + g * 5 <<endl;
    return;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long X;
    scanf("%lld",&X);
    solve(X);
    return 0;
}


Measured memory_bytes: 256
n_a, n_b, m = gets.split.map(&:to_i)
a = gets.split.map(&:to_i)
b = gets.split.map(&:to_i)

ans = a.min + b.min

m.times do
    xyc = gets.split.map(&:to_i)
    t = a[xyc[0]-1] + b[xyc[1]-1] - xyc[2]
    ans = t if ans > t
end

p ans

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

#define cc(x) cout << (x) << endl
#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)
typedef long long ll;

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

const ll inf = 1LL<<58;
const int iinf = 1<<30;

ll gcd(ll a, ll b){
    if(b==0){
        return a;
    }
    return gcd(b, a%b);
}

// vector<int> takasa(101);

int main(){
    ll n, k;
    cin >> n >> k;
    vector<ll> h(n);
    rep(i,n){
        cin >> h[i];
    }
    sort(h.begin(), h.end());
    ll tmp=inf;

    rep(i,n-k+1){
        amin(tmp, h[i+k-1]-h[i]);
    }

    cc(tmp);
}

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

int main() {
  int start, end, times, answer = 0;
  cin >> start >> end;
  times = end - start + 1;
  for (int i = 0; i < times; i++){
    int one, two, four, five, number;
    number = start + i;
    one = number % 10;
    two = (number / 10) % 10;
    four = (number / 1000) % 10;
    five = (number / 10000) % 10;
    if (one == five && two == four){
      answer++;
    }
  }
  cout << answer << endl;
}

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

int main() {
    string s, t;
    cin >> s >> t;
    int min = 0;
    for (int i = 0; i <= s.size() - t.size(); i++) {
	int cnt = 0;
	for (int j = 0; j < t.size(); j++) {
	    if (s[i + j] != t[j]) {
		cnt++;
	    }
	}
	if (min > cnt || min == 0) {
	    min = cnt;
	}
    }
    cout << min << endl;
    return 0;
}



Measured memory_bytes: 3596
void main() {
    int n = readln.chomp.to!int;
    writeln(800 * n - n / 15 * 200);
}

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>
// Hey! 僕の提出を見てくれてありがとう.
// ロボ子さん可愛いぞ！！！！！君もV沼にはまろう↓
// https://www.youtube.com/channel/UCDqI2jOz0weumE8s7paEk6g
using namespace std;
using ll = long long;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}//a,bの最大公約数(gcd)を求める
ll lcm(ll a,ll b){return abs(a*b)/gcd(a,b);}//a,bの最小公倍数(lcm)を求める
vector<ll> enum_div(ll n){vector<ll> ret;for(int i=1 ; i*i<=n ; i++){if(n%i == 0){ret.push_back(i);if(i!=1 && i*i!=n)ret.push_back(n/i);}}ret.push_back(n);return ret;}
//↑nの約数を求める
vector<bool> IsPrime; void sieve(size_t max){if(max+1 > IsPrime.size())IsPrime.resize(max+1,true);IsPrime[0] = false;IsPrime[1] = false;for(size_t i=2; i*i<=max; ++i)if(IsPrime[i])for(size_t j=2; i*j<=max; ++j)IsPrime[i*j] = false;}
//↑エラトステネスの篩で素数を求める
#define roundup(divisor,dividend) (divisor + (dividend - 1)) / dividend //切り上げ割り算
#define all(x) (x).begin(),(x).end() //xの初めから終わりまでのポインタ
#define size_t ll //size_tは自動でllに変換される
#define pb(x) push_back(x)
#define pri_queue priority_queue //優先度付きキュー
#define syo(x) fixed << setprecision(x) //iostreamで小数をx桁表示
//sortを降順にする時は greater<型>()
void solve(long long N, std::vector<long long> P, std::vector<long long> Q){
  vector<ll> x(N);
  for (int i = 0; i < N; i++) {
    x[i] = i+1;
  }
  ll a,b,l=1;
  do{
    bool an = true , bn = true;
    for (int i = 0; i < N; i++) {
      if(x[i] != P[i])an = false;
      if(x[i] != Q[i])bn = false;
    }
    if(an) a = l;
    if(bn) b = l;
    l++;
  }while(next_permutation(all(x)));
  cout << abs(b-a) << endl;
}

int main(){
    long long N;
	scanf("%lld",&N);
	std::vector<long long> P(N);
	for(int i = 0 ; i < N ; i++){
		scanf("%lld",&P[i]);
	}
	std::vector<long long> Q(N);
	for(int i = 0 ; i < N ; i++){
		scanf("%lld",&Q[i]);
	}
    solve(N, std::move(P), std::move(Q));
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include<algorithm>
#include<string>
#include <map>
#include <queue>
#include <stack>

#define DIV 1000000007
using namespace std;

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

    int w, v;
    vector<vector<long long>> dp(N+1, vector<long long>(W + 1));
    for (int i = 1; i <= N; i++) {
        cin >> w >> v;
        for (int j = 0; j <= W; j++) {      
             dp[i][j] = dp[i - 1][j];
             if (j - w >= 0)
                 dp[i][j] = max(dp[i][j],dp[i - 1][j - w] + v);
        }

    }
    cout << dp[N][W] << endl;
}


Measured memory_bytes: 80256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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<int MOD> struct ModInt {
    static const int Mod = MOD; unsigned x; ModInt() : x(0) { }
    ModInt(signed sig) { x = sig < 0 ? sig % MOD + MOD : sig % MOD; }
    ModInt(signed long long sig) { x = sig < 0 ? sig % MOD + MOD : sig % MOD; }
    int get() const { return (int)x; }
    ModInt &operator+=(ModInt that) { if ((x += that.x) >= MOD) x -= MOD; return *this; }
    ModInt &operator-=(ModInt that) { if ((x += MOD - that.x) >= MOD) x -= MOD; return *this; }
    ModInt &operator*=(ModInt that) { x = (unsigned long long)x * that.x % MOD; return *this; }
    ModInt &operator/=(ModInt that) { return *this *= that.inverse(); }
    ModInt operator+(ModInt that) const { return ModInt(*this) += that; }
    ModInt operator-(ModInt that) const { return ModInt(*this) -= that; }
    ModInt operator*(ModInt that) const { return ModInt(*this) *= that; }
    ModInt operator/(ModInt that) const { return ModInt(*this) /= that; }
    ModInt inverse() const { long long a = x, b = MOD, u = 1, v = 0;
        while (b) { long long t = a / b; a -= t * b; std::swap(a, b); u -= t * v; std::swap(u, v); }
        return ModInt(u); }
    bool operator==(ModInt that) const { return x == that.x; }
    bool operator!=(ModInt that) const { return x != that.x; }
    ModInt operator-() const { ModInt t; t.x = x == 0 ? 0 : Mod - x; return t; }
};
template<int MOD> ostream& operator<<(ostream& st, const ModInt<MOD> a) { st << a.get(); return st; };
template<int MOD> ModInt<MOD> operator^(ModInt<MOD> a, unsigned long long k) {
    ModInt<MOD> r = 1; while (k) { if (k & 1) r *= a; a *= a; k >>= 1; } return r; }
typedef ModInt<1000000007> mint;
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     @hamayanhamayan0
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/














int N, K;
mint cnt[101010];
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N >> K;

    rrep(g, K, 1) {
        cnt[g] = mint(K / g) ^ N;
        int gg = g * 2;
        while (gg <= K) {
            cnt[g] -= cnt[gg];
            gg += g;
        }
    }

    mint ans = 0;
    rep(g, 1, K + 1) ans += cnt[g] * g;
    cout << ans << endl;
}







Measured memory_bytes: 4044
#include <stdio.h>
int main(){
    int H[100],W[100],i,k,ix,o;
    i=0;
    while(1){
        scanf("%d %d",&H[i],&W[i]);
        if(H[i]==0&&W[i]==0){
            ix=i;
            break;
        }
        i++;
    }
    for(i=0;i<ix;i++){
        for(o=0;o<H[i];o++){
            for(k=0;k<W[i];k++){
                if(o>0&&o<H[i]-1&&k>0&&k<W[i]-1){
                    printf(".");
                }else{
                    printf("#");
                }
            }
            printf("\n");
        }
        printf("\n");
    }
    return 0;
}

Measured memory_bytes: 1808
def gcd(a, b):
    if b > a:
        return gcd(b, a)
    if a % b == 0:
        return b
    return gcd(b, a % b)

if __name__ == '__main__':
    N = int(input())
    nums = [int(n) for n in input().split()]
    if len(nums) == 1:
        print(nums[0])
        exit()

    ret = gcd(nums[0], nums[1])
    for n in nums[1:]:
        ret = gcd(ret, n)
    print(ret)

Measured memory_bytes: 14228
<?php
fscanf(STDIN, "%d",$cnt);
$arr=explode(' ',trim(fgets(STDIN)));

$v_cnt=0;

$h_1	=$arr[0];
$max_h	=$arr[0];

for($i=1;$i<count($arr);$i++){
	//echo $arr[$i];
	if($arr[$i]>=$h_1 && $arr[$i]>=$max_h){
		$v_cnt++;
		if($arr[$i]>=$max_h){
			$max_h=$arr[$i];
		}
	}
}

echo $v_cnt+1;

?>

Measured memory_bytes: 3828
#include <bits/stdc++.h>
using namespace std;
typedef long long 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; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/

// const ll mod = 1e9+7;

// void chmod(ll &M){
//     if(M >= mod) M %= mod;
//     else if(M < 0){
//         M += (abs(M)/mod + 1)*mod;
//         M %= mod;
//     }
// }


int main(){
    int N; cin >> N;
    vector<int> a(N), b(N);
    for(int i=0; i<N; ++i) cin >> a[i];
    for(int i=0; i<N; ++i) cin >> b[i];

    int ans = 0;

    for(int k=28; k>=0; --k){
        int T = 1<<k;
        for(int i=0; i<N; ++i) { a[i] %= 2*T; b[i] %= 2*T; }
        sort(b.begin(), b.end());
        ll cnt = 0;
        for(int i=0; i<N; ++i){
            auto i2 = lower_bound(b.begin(), b.end(), 2*T-a[i]);
            auto i1 = lower_bound(b.begin(), b.end(), T-a[i]);
            
            auto i4 = lower_bound(b.begin(), b.end(), 4*T-a[i]);
            auto i3 = lower_bound(b.begin(), b.end(), 3*T-a[i]);
            
            int cnt1 = i2-i1;
            int cnt2 = i4-i3;

            cnt += cnt1+cnt2;
        }
        if(cnt%2 == 1) ans += T;
        // 上、if(cnt%2 == 1)にするとWAになる　cnt<0 になることなんてある？
    }

    cout << ans << endl;
}

Measured memory_bytes: 1792
#include <iostream>
using namespace std;
int main()
{
	int N;
	while( cin >> N ) {
		int ans = 0;
		for(int i=1; i<=N; ++i){
			int cnt = 0;
			for(int j=1; j<=i; ++j)
				if( i%2 == 1 && i%j == 0 )	cnt++;
			if( cnt == 8 )	ans++;	
		}
		cout << ans << endl;	
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;i<(n);i++)
#define REP(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define INF INT_MAX
#define MOD 1000000007
#define fcout cout << fixed << setprecision(15)
#define int long long
#define yorn(f) puts((f)?"Yes":"No")
#define YORN(f) puts((f)?"YES":"NO")
#define sec second
#define fir first
typedef long long ll;
typedef pair<int, int> P;
typedef priority_queue<int> pque;
typedef vector<int> Vec;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a/gcd(a,b)*b;};
int mod(int a,int b){return (a+b-1)/b;};
template<typename A, size_t N, typename T>
void Fill(A(&array)[N],const T &val){std::fill((T*)array,(T*)(array+N),val);}
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;};



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

	int n;
	string s;
	cin >> n >> s;
	Vec r;
	Vec g;
	Vec b;
	rep(i, n) {
		if(s[i] == 'R')	r.push_back(i);
		if(s[i] == 'G') g.push_back(i);
		if(s[i] == 'B') b.push_back(i);
	}

	int ans = 0;
	rep(i, r.size()) {
		rep(j, g.size()) {
			int d = abs(r[i] - g[j]);
			int L = min(r[i], g[j]);
			int R = max(r[i], g[j]);
			ans += b.size();
			if(L - d >= 0 && s[L - d] == 'B') ans--;
			if(R + d < n && s[R + d] == 'B') ans--;
			if(d % 2 == 0 && s[L + d / 2] == 'B') ans--;
		}
	}
	cout << ans << endl;
	return 0;
}

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

int main(){
  long long a,b,k;
  cin>>a>>b>>k;
  if(k<=a){
    cout<<a-k<<" "<<b<<endl;
  }
  else if(k<=a+b){
    cout<<0<<" "<<b-(k-a)<<endl;
  }
  else
    cout<<0<<" "<<0<<endl;
}

Measured memory_bytes: 256
a, b = map(int, input().split())

if a == min(a, b):
    tmp_a = 0
    for i in range(b):
        tmp_a += a*(10**i)
    print(tmp_a)
else:
    tmp_b = 0
    for i in range(a):
        tmp_b += b*(10**i)
    print(tmp_b)


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
int const p=998244353;
int f[200005],fac[200005],inv[200005];
int pw(int x,int y)
{
	int res=1;
	while(y)
	{
		if(y&1)res=1ll*res*x%p;
		x=1ll*x*x%p;
		y>>=1;
	}
	return res;
}
int main()
{
	int n,m,k;
	scanf("%d%d%d",&n,&m,&k);
	f[1]=m;
	fac[0]=inv[0]=1;
	for(register int i=1;i<=n;++i)fac[i]=1ll*fac[i-1]*i%p,inv[i]=pw(fac[i],p-2);
	for(register int i=2;i<=n;++i)
	{
		f[i]=1ll*(m-1)*f[(i-1)]%p;
	}
	int ans=0;
	for(int i=0;i<=k;i++)
	{
		ans+=1ll*f[n-i]*fac[n-1]%p*inv[i]%p*inv[n-i-1]%p;ans%=p;
	}
	cout<<ans;
}

Measured memory_bytes: 6000
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define Red ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define rep(i, n) for(int i =0 ; i < n; ++i)
#define Rep(i,a,b) for(int i=a;i<=b;i++)
#define pii pair < int, int >
typedef vector<int> vi;
typedef  long long ll;
const int mod =1e9+7;
const int N = (int)2e5 + 5;

void solve(){
 		int k,s;
 		cin>>k>>s;
 		int ans=0;
 		set<pair<int,pair<int,int> > >ss;
 		for(int i=0;i<=k;i++){
 			for(int j=0;j<=k;j++){
 				if(s-i-j>=0 &&s-i-j<=k)
 					ans++;
 			}
 		}
 		cout<<ans;
 
}

int main(){
	Red;
	int t=1;
	//cin>>t;
	while(t--)
	solve();
	return 0;
}

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

int main()
{
  int inf = 1000000000;
  int n, m, x;
  cin >> n >> m >> x;
  int c[n], a[n][m], r[m];
  rep(i, n){
    cin >> c[i];
    rep(j, m) cin >> a[i][j];
  }
  int ans = 1000000000;
  for(int i = 0; i < (1 << n); i++){
    rep(j, m) r[j] = 0;
    int y = i;
    int cnt = 0;
    int sum = 0;
    while(y > 0){
      if(y & 1){

        sum += c[cnt];
        rep(j, m) r[j] += a[cnt][j];
      }
      y /= 2;
      cnt++;
    }
    int ok = 0;
    rep(j, m) {
      if(r[j] >= x) ok++;
    }
    if(ok == m) ans = min(ans, sum);
  }
  cout << (ans != 1000000000 ? ans : -1) << endl;
        

  return 0;
}

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

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

struct edge {
    int to, cost;
};

void dijkstra(int s, vector<edge> G[], vector<ll>& d) {
    fill(d.begin(), d.end(), INF);
    d[s] = 0;

    priority_queue<P, vector<P>, greater<P>> que;
    que.push(P(0, s));

    while (!que.empty()) {
        P p = que.top();
        que.pop();
        int v = p.second;
        if (d[v] < p.first) continue;
        for (int i = 0; i < G[v].size(); i++) {
            edge e = G[v][i];
            if (d[e.to] > d[v] + e.cost) {
                d[e.to] = d[v] + e.cost;
                que.push(P(d[v] + e.cost, e.to));
            }
        }
    }
}

int main() {
    int n, m, s, t;
    cin >> n >> m >> s >> t;
    vector<edge> A[m * 2], B[m * 2];
    for (int i = 0; i < m; i++) {
        int u, v, a, b;
        cin >> u >> v >> a >> b;

        edge e;

        e = {v, a};
        A[u].push_back(e);
        e = {u, a};
        A[v].push_back(e);

        e = {v, b};
        B[u].push_back(e);
        e = {u, b};
        B[v].push_back(e);
    }

    vector<ll> money(n + 1), sunuke(n + 1);
    dijkstra(s, A, money);
    dijkstra(t, B, sunuke);

    vector<P> sum(n);
    for (int i = 0; i < n; i++) {
        sum[i] = P(money[i + 1] + sunuke[i + 1], i + 1);
    }

    sort(sum.begin(), sum.end());
    for (int i = 0, j = 0; i < n; i++) {
        while (sum[j].second <= i){
            j++;
        }
        ll ans = 1e15 - sum[j].first;
        cout << ans << endl;
    }
}

Measured memory_bytes: 21756
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <queue>
#include <cassert>
#include <iomanip>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int iINF = 1001001001;
const long long llINF = 1LL << 60;
void prime_factorize(ll n, vector<ll> & ret)
{
    if (n <= 1)	return;
    for (ll i = 2; i * i <= n; i++) {
        if (n % i == 0) {
            prime_factorize(i, ret);
            prime_factorize(n / i, ret);
            return;
        }
    }
    ret.push_back(n);
    return;
}
int main()
{
    /*int c; cin >> c;
    if (30 <= c) cout << "Yes" << endl;
    else cout << "No" << endl;
    */

    /*ll n, d; cin >> n >> d;
    d *= d;
    int ans = 0;
    rep(i, n) {
        ll x, y; cin >> x >> y;
        ll dd = x * x + y * y;
        if (dd <= d) ans++;
    }
    cout << ans << endl;
    */

    /*ll k; cin >> k;
    rep(i, 100100) {
        vector<ll> fact = prime_factorize(k);
        for (ll l : fact) {
            if (l == k) {
                cout << 
            }
        }
    }
    */

    int k; cin >> k;
    string s; cin >> s;
    int num = s.size();
    int w, r;
    w = r = 0;
    for (char c : s) {
        if (c == 'R') r++;
        else w++;
    }
    if (w == 0 || r == 0) {
        cout << 0 << endl;
        return 0;
    }
    vector<int> rnum, wnum;
    rep(i, num) {
        if (s[i] == 'R') rnum.push_back(i);
        else wnum.push_back(i);
    }
    sort(ALL(wnum));
    sort(rALL(rnum));
    num = min(wnum.size(), rnum.size());
    int ans = 0;
    rep(i, num) {
        if (rnum[i] < wnum[i]) break;
        ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4692
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<cmath>
#include<tuple>
typedef long long int ll;
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define F first
#define S second
using namespace std;
const ll INF = 10000000000000;

int A, B;

int main() {
	cin >> A >> B;
	int C = A - B * 2;
	if (C >= 0)cout << C << endl;
	else cout << "0" << endl;

	return 0;
}

Measured memory_bytes: 256
N, K = map(int, input().split())
A = tuple(map(int, input().split()))
T = input()

bestmove = {'r':2, 's':0, 'p':1}

ans = 0
for k in range(K):
    t = T[k::K]
    prev = -1
    for opp in t:
        me = bestmove[opp]
        if prev != me:
            prev = me
            ans += A[me]
        else:
            prev = -1

print(ans)


Measured memory_bytes: 73536
#include <cstdio>
using namespace std;
char c[108][108];
int main(){
	register int a, b, n = 100, m = 100, i, j, x, y;
	scanf("%d %d", &a, &b);
	for (i = 1; i <= n; ++i) for (j = 1; j <= m; ++j) c[i][j] = '#';
	x = y = 1;
	while (--a) {
		c[x][y] = '.';
		if (y == 99) x += 2, y = 1;
		else y += 2;
	}
	for (i = x + 2; i <= n; ++i) for (j = 1; j <= m; ++j) c[i][j] = '.';
	x = y = 99;
	while (--b) {
		c[x][y] = '#';
		if (y == 1) x -= 2, y = 99;
		else y -= 2;
	}
	printf("%d %d\n", n, m);
	for (i = 1; i <= n; ++i) puts(c[i] + 1);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <string.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for(int i = m; i < n; i++) 
typedef long long int ll;
double ki(int x) {
	double a=(double)1 / 2 * x*(x + 1);
	return (double)a / x;

}

int main(){
    int N, K;
    cin>>N>>K;
	vector<int>p(N);
	
	rep(i, N) {
		cin>>p.at(i);
	}
	
	vector<int> Y(N+1);
    
	int sum = 0;
	rep(i, N) {
		sum += p.at(i);
		Y.at(i+1) = sum;
	}
    
	int max = 0;
	int index = 0;
	rep(i, N + 1) {
        if(i==N-K+1) break;
		if (Y.at(i + K) - Y.at(i) > max) {
			max = Y.at(i + K) - Y.at(i);
			index = i;
		}
	}
    
	double sum2 = 0;
	int count = 0;
	for (int i = index; count < K; i++) {
		sum2 += ki(p.at(i));
		count++;
	}
	cout<<fixed << setprecision(12)<<sum2<<endl;
    
    return 0;
}

Measured memory_bytes: 1792
n = int(input())

A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
sum =0 
for i in range(n):
  sum += B[i]

for i in range(n-1):
  if A[i] == A[i+1] - 1:
    j = A[i]-1
    sum += C[j]

    
print(sum)

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

const int INF = 1e9 + 5;

int main() {
	int n;
	cin >> n;
	int x;
	vector<int> height;
	for(int i=0; i<n; i++) {
		cin >> x;
		height.push_back(x);
	}
	vector<int> sum(n,INF);
	sum[0] = 0;
	sum[1] = abs(height[0] - height[1]);
	for(int i=2; i<n; i++) {
		sum[i] = min(
				sum[i-1]+abs(height[i] - height[i-1]) 
				,sum[i-2]+abs(height[i] - height[i-2])
				);
	}
	cout << sum[n-1];
	return 0;
}


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

int main(){
  int n;
  cin >> n;
  for(int i=0;i<n;i++){
    int a;
    cin >> a;
    if(a%2 == 0){
      if(a%3!=0 && a%5!=0){
        cout << "DENIED" << endl;
        break;
      }
    }
    if(i==n-1){
      cout << "APPROVED" << endl;
    }
  }
}

Measured memory_bytes: 256