akhauriyash/Code-Regression huggingface dataset:
S=input()
L=len(S)
Key="keyence"

for i in range(8):
    if i==0:
        temp=S[L-7:L+1]
    elif 1<=i<=6:
        temp=S[0:i]+S[L+i-7:L+1]
    else:
        temp=S
    if temp == Key:
        print("YES")
        exit()
print("NO")

Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<string>
#include<queue>
#include<utility>
#include<cmath>
#include<sstream>
#include<istream>

using namespace std;


int main()
{

  int N;
  cin >> N;

  if(N%2 == 0)  cout << N/2 - 1 << endl;
  else  cout << N/2 << endl;

  return 0;
}


Measured memory_bytes: 256
MOD=10**9+7
s=input()
s.rstrip()
s=s[::-1]
dp=[[0]*13 for _ in range(len(s)+1)]
dp[0][0]=1

coef=1
for i in range(len(s)):
    if s[i]=='?':
        for j in range(13):
            for k in range(10):
                ind=(j+coef*k)%13
                temp=dp[i+1][ind]+dp[i][j]
                dp[i+1][ind] = temp-MOD if temp>=MOD else temp
    else:
        si=int(s[i])
        for j in range(13):
            ind=(j+coef*si)%13
            temp=dp[i+1][ind]+dp[i][j]
            dp[i+1][ind] = temp-MOD if temp>=MOD else temp
    coef=coef*10%13


print(dp[len(s)][5])

Measured memory_bytes: 64032
#include<stdio.h>
int main(void){
    int a, b;
    int f1, f2;
    double f3;
    scanf("%d %d", &a, &b);
    f1=a/b;
    f2=a%b;
    f3=1.0*a/b;
    printf("%d %d %.8lf\n", f1, f2, f3);
    return 0;
}


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

using namespace std;
using ll = unsigned long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;

int main(void) {
    ll a;
    float b;
    cin >> a >> b;
    cout << a *  ll(round(100 * b)) / 100 << endl;

    return 0;
}


Measured memory_bytes: 3732
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,m,c;
    cin>>n>>m>>c;
    vector<int> b(m);
    for(int i=0; i<m; i++){
        cin>>b.at(i);
    }
    vector<vector<int>> a(n,vector<int>(m));
    for(int i=0; i<n; i++){
        for(int j=0; j<m; j++){
            cin>>a.at(i).at(j);
        }
    }

    int ans=0;
    for(int i=0; i<n; i++){
        int sum=0;
        for(int j=0; j<m; j++){
            sum+=b.at(j)*a.at(i).at(j);
        }
        if(sum+c>0) ans++;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
void frog1(int arr[],int n,int k)
{
  int dp[n]={0};
  for(int i=1;i<n;i++)
  {
      dp[i]=INT_MAX;
      for(int j=i-1;j>=0 && (i-j)<=k;j--)
      {
          dp[i]=min(dp[i],abs(arr[i]-arr[j])+ dp[j]);
      }
      
  }
  cout<<dp[n-1];
  
}
int main()
{
     int n,k;
     cin>>n>>k;
     int arr[n];
     for(int i=0;i<n;i++)
     {
       cin>>arr[i];
     }
     frog1(arr,n,k);
     return 0;
}


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

public class Main {
	
	Scanner sc = new Scanner(System.in);
	public void run() {
		while(sc.hasNext()){
			String n = sc.nextLine();
			if(n.equals("#")) break;
			else calc(n);
		}
	}
	public void calc(String line){
		//char[] right = {'h','i','j','k','l','m','n','o','p','u','y'};
		String right = "hijklmnopuy";
		int now = -1;
		int count = 0;
		
		String first = String.valueOf(line.charAt(0));
		if(right.indexOf(first) != -1){
			now = 1;
		}
		else now = 0;
		
		for(int i = 1; i < line.length(); i++){
			String c = String.valueOf(line.charAt(i));
			int rightDayo = right.indexOf(c);
			if(rightDayo != -1 && now == 0){
				count++;
				now = 1;
			}
			else if(rightDayo == -1 && now == 1){
				count++;
				now = 0;
			}
		}
		System.out.println(count);
	}
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 22320
import java.util.Scanner;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.TreeMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;

class Main{
    static double mod = 1e9+7;
    static HashMap<String,Integer> map;
    static int[] a;
    static long ans;
    static String[] march = {"M","A","R","C","H"};
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        Library lib = new Library();
        int N = sc.nextInt();
        sc.nextLine();
        map = new HashMap<>();
        for (String s:march){
            map.put(s,0);
        }
        a = new int[5];
        for (int i=0;i<N;i++){
            String s = sc.nextLine();
            String x = String.valueOf(s.charAt(0));
            if (x.equals("M") || x.equals("A") || x.equals("R") || x.equals("C") || x.equals("H")){
                if (map.containsKey(x)){
                    map.put(x,map.get(x)+1);
                } else {
                    map.put(x,1);
                }
            }
        }
        ans = 0;
        dfs(0);
        System.out.println(ans);
    }

    public static void dfs(int pos){
        if (pos==5){
            task();
            return;
        } else {
            a[pos] = 0;
            dfs(pos+1);
            a[pos] = 1;
            dfs(pos+1);
        }
    }

    public static void task(){
        int cnt = 0;
        long res = 1;
        for (int i=0;i<5;i++){
            if (a[i]==1){
                cnt++;
                res *= map.get(march[i]);
            }
        }
        if (cnt!=3){
            return;
        } else {
            ans += res;
            return;
        }
    }
}

class Library{
    static long a;
    static long b;

    public static long gcd(long a,long b){
        Library lib = new Library();
        if (a<b){
            lib.swap(a,b);
        }
        if (b==0){
            return a;
        } else {
            return gcd(b,a%b);
        }
    }

    public static void swap(long a,long b){
        long x = a;
        a = b;
        b = x;
        return;
    }
}

Measured memory_bytes: 91868
// #define _GLIBCXX_DEBUG

#include <algorithm>
#include <chrono>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <string>
#include <vector>
#include <chrono>
#include <cmath>

#define int long long

using namespace std;

signed main() {
  int x;
  cin >> x;

  for (int b = -1001; b <= 1001; b++) {
    for (int a = 0; a <= 1001; a++) {
      int t = a * a * a * a * a;
      int u = b * b * b * b * b;
      if (t > x + u) {
        break;
      }

      if (t - u == x) {
        cout << a << " " << b << endl;
        return 0;
      }
    }
  }

  return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
int INF = 1e9+7;
int mod = 998244353;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int cnt[1000005];
signed main() {
    int N,K;
    cin >> N >> K;
    vector<int>p(N);
    for(int i = 0; i < N; i++) {
        cin >> p[i];
    }
    sort(p.begin(),p.end());
    int ans = 0;
    for(int i = 0; i < K; i++) {
        ans+=p[i];
    }
    cout << ans << endl;
}


Measured memory_bytes: 3620
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <iterator>  // std::back_inserter()
#include <algorithm>  // std::copy()
#include <functional>  // std::greater<T>()
#include <utility>  // std::swap()
#include <numeric>  // accumulate(ALL(vec), 0)  0 は初期値
#include <cmath>
#include <climits>  // INT_MIN
#include <cctype>  // std::isdigit()
using namespace std;

#define ALL(obj) (obj).begin(), (obj).end()
#define REP(i, n) for (int i=0; i < (int)(n); i++)  // 0 ~ n-1
#define REPN(i, n) for (int i=1; i <= (int)(n); i++)  // 1 ~ n
#define DESCEND greater<int>()  // sort 降順 大きい順
#define UNIQUE(vec) (vec).erase(unique(ALL((vec))), (vec).end());  // 必ずsortを行なってから
#define MIN(vec) min_element(ALL((vec)))  // イテレータのため、値を取り出すときは * を先頭につける
#define MAX(vec) max_element(ALL((vec)))
#define IDX(vec, element_iter) distance((vec).begin(), element_iter)
#define SUM(vec) accumulate(ALL((vec)), 0)  // 0 は初期値
#define COPY(vec1, vec2) copy(ALL(vec1), back_inserter(vec2))  // vec1をvec2にコピーする vec2は空にしておく必要あり
typedef long long ll;

const int MOD = 1000000007;  // 1 000 000 007


template <class T>
T digitSum(T num) {
    ll sum = 0;
    while (num != 0) {
        sum += num%10;
        num /= 10;
    }
    return sum;
}

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

    // input
    int N;
    cin >> N;
    
    // calculation
    if (N%digitSum(N) == 0) {
        cout << "Yes" << "\n";
    } else {
        cout << "No" << "\n";
    }
    
    return 0;
}


Measured memory_bytes: 256
house= [[[0 for r in range(10)] for f in range(3)] for b in range(4)]
n = int(input())

for i in range(n):
 b, f, r, v = list(map(int, input().split() ))
 house[b-1][f-1][r-1] = house[b-1][f-1][r-1] + v

for b in range(4):
 for f in range(3):
  for r in range(10):
   print(f" {house[b][f][r]}",end="")
  print()
 if b<3:
  print("####################")



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

#define MOD 998244353
long long int ppow(long long int i, long long int j) {
	long long int res = 1LL;
	while (j) {
		if ((j & 1LL)) {
			res *= i;
			if (res >= MOD) {
				res %= MOD;
			}
		}
		j >>= 1;
		i *= i;
		if (i >= MOD) {
			i %= MOD;
		}
	}
	return res;
}

int n;
vector<int> v;
int cn[200002];

int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		int a;
		scanf("%d", &a);
		if (i == 0 && a) {
			puts("0");
			return 0;
		}
		if (a == 0 && i) {
			puts("0");
			return 0;
		}
		cn[a]++;
	}
	int leaf = 1;
	long long int way = 1;
	for (int i = 1; i <= n - 1; i++) {
		for (int j = 1; j <= cn[i]; j++) {
			way *= leaf;
			way %= MOD;
		}
		leaf = cn[i];
	}
	printf("%lld\n", way);
	return 0;
}

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

const int N = 1e5 + 69;
const long long MAX = 1e18;

int n;
long long ar[N];

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);

	cin >> n;
	long long ans = 1;
	bool zero = false;
	for(int i = 1; i <= n; i++) {
		cin >> ar[i];
		if(ar[i] == 0){
			zero = true;
		}
	}
	if(zero) {
		cout << 0 << "\n";
		return 0;
	}
	for(int i = 1; i <= n; i++) {
		long double ans1 = (long double) ans;
		long double MX = (long double) MAX;
		long double tes = (long double) ar[i];
		// cerr << ans << " " << MX/tes << "\n";
		if(ans1 > MX / tes){
			cout << -1 << "\n";
			return 0;
		}
		ans = ans * ar[i];
	}

	cout << ans << "\n";
	return 0;

}


Measured memory_bytes: 4388
A, B, C = map(int, input().split())
l = [abs(A//2 * B * C - (A - A//2)*B*C), abs(B//2 * A * C - (B - B//2)*A*C), abs(C//2 * B * A - (C - C//2)*B*A)]
print(min(l))

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

template<typename T>
struct BIT {
    int n;
    vector<T> dat;

    BIT(int n=0){
        initialize(n);
    }

    void initialize(int nin){
        n = nin;
        dat.resize(n, 0);
    }

    T sum(int i){
        T s = 0;
        while(i >= 0){
            s += dat[i];
            i = (i & (i+1)) - 1;
        }
        return s;
    }

    T sum_between(int i, int j){
        return sum(j) - sum(i-1);
    }

    void plus(int i, T x){
        while(i < n){
            dat[i] += x;
            i |= i+1;
        }
    }

    // a[0]+...+a[ret] >= x
    int lower_bound(T x){
        if(x < 0) return -1;
        int ret = -1;
        int k = 1;
        while(2*k <= n) k <<= 1;
        for( ;k>0; k>>=1){
            if(ret+k < n && dat[ret+k] < x){
                x -= dat[ret+k];
                ret += k;
            }
        }
        return ret + 1;
    }
};

int main(){
    int N, Q;
    string S;
    cin >> N >> S >> Q;

    BIT<int> bit[26];
    for(int k=0; k<26; k++) bit[k].initialize(N);
    for(int i=0; i<N; i++) bit[S[i]-'a'].plus(i, 1);

    while(Q--){
        int t;
        cin >> t;
        if(t == 1){
            int i;
            char c;
            cin >> i >> c;
            i--;
            bit[S[i]-'a'].plus(i, -1);
            S[i] = c;
            bit[S[i]-'a'].plus(i, 1);
        }else{
            int l, r;
            cin >> l >> r;
            l--; r--;
            int ans = 0;
            for(int k=0; k<26; k++) if(bit[k].sum_between(l, r)) ans++;
            cout << ans << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 51716
#include<bits/stdc++.h>
using namespace std;
int main()
  {
  string a,b,c;
  cin>>a>>b;
  int a2,b2;
  cin>>a2>>b2;
  cin>>c;
  cout<<a2-(a==c)<<" "<<b2-(c==b)<<endl;
  return 0;
  }


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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
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;
}
int vector_finder(std::vector<ll> vec, int number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}

int main() {
  int N, K; cin >> N >> K;
  ll S; cin >> S;
  vector<ll> A(N);
  REP(i, N) {
    if(S != pow(10, 9)) A[i] = S + 1;
    else A[i] = 1;
  }
  REP(i, K) A[i] = S;
  REP(i, N) cout << A[i] << " ";
  cout << endl;
}


Measured memory_bytes: 2048
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE BangPatterns #-}

import Control.Applicative
import Control.Monad
import Control.Arrow
import Data.List
import Data.Maybe
import Data.Char
import qualified Data.ByteString.Char8 as B
import Text.Printf

import Network.CGI.Protocol

readInt = ( readLn :: IO Int )
readInts = map ( read :: String -> Int ) . words <$> getLine

getList = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine

which a b f = if f then a else b
mp [ a, b ] = ( a, b )

main = interact $ replace ',' ' '


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

int main() {
  int A, B, C;
  cin >> A >> B >> C;
  
  int cup1, cup2;
  cup1 = A - B;
  
  cup2 = C - cup1;
  
  if (cup2 > 0){
    cout << cup2 << endl;
  }
  else {
    cout << 0 << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    int h1,s1,h2,s2;
    cin>>h1>>s1>>h2>>s2;
    while(true)
    {
        h2 -= s1;
        if(h2<=0)
        {
            cout<<"Yes";
            return 0;
        }
        h1-=s2;
        if(h1<=0)
        {
            cout<<"No";
            return 0;
        }
    }
}


Measured memory_bytes: 3528
#include <iostream>
#include <cmath>
#include <string>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
using namespace std;
typedef long long ll;

int main(void) {
    int n;
    cin >> n;
    int t[n+1], x[n+1], y[n+1];
    int i, dis, time;
    
    t[0]=0;
    x[0]=0;
    y[0]=0;
    for(i=1; i<=n; i++)
        cin >> t[i] >> x[i] >> y[i];
    
    for(i=1; i<=n; i++) {
        dis=abs(x[i]-x[i-1])+abs(y[i]-y[i-1]);
        time=t[i]-t[i-1];
        if(dis>time || dis%2!=time%2) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}


Measured memory_bytes: 1408
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val n = sc.nextInt()
  val x = Array.fill(n)(sc.nextInt())
  val sorted = x.sorted
  val med1 = sorted.apply(n/2)
  val med2 = sorted.apply(n/2-1)
  for (i <- 1 to n){
    if (x(i-1)<=med2){
      println(med1)
    } else{
      println(med2)
    }
  }
}

Measured memory_bytes: 74976
a,b,c,d = [int(x) for x in input().split()]
h,w = d-b,c-a

def rep(t,c):
	for i in range(t):
		print(c,end='')
rep(1,'L')
rep(h+1,'U')
rep(w+1,'R')
rep(1,'D')
rep(1,'R')
rep(h+1,'D')
rep(w+1,'L')
rep(1,'U')

rep(h,'U')
rep(w,'R')
rep(h,'D')
rep(w,'L')

print()

Measured memory_bytes: 42968
#include<stdio.h>
#define N 10000
int main(){
  int cnt=0,cnt1=0;
  int i,j,n,q,S[N],T[N];
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&S[i]);
  }
  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&T[i]);
  }
  for(i=0;i<q;i++){
    for(j=0;j<n;j++){
      if(T[i]==S[j]){
	cnt1=1;
	cnt++;
      }
      if(cnt1==1){break;
      }
    }
    cnt1=0;
  }
	  printf("%d\n",cnt);
  return 0;
}



Measured memory_bytes: 2108
#include<bits/stdc++.h>
using namespace std;
#define endl "\n";
#define M 1000000007
#define start ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define test ll t; cin>>t; while(t--)
typedef long long int ll;
int main()
{
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif

	start
	ll n, m;
	cin>> n >> m;
	for(ll i=0; i<m; i++)
	{
		ll x;
		cin>>x;
		n -= x;
	}
	if(n>=0)
	{
		cout<<n;
	}
	else
	{
		cout<<"-1";
	}
	// test
	// {

	// }
	return 0;
}

Measured memory_bytes: 3652
import math
from functools import reduce
def gcd(*numbers):
    return reduce(math.gcd, numbers)
k = int(input())
ans = 0
for a in range(1,k+1):
    ans += a
for a in range(1,k):
    for b in range(a+1,k+1):
        ans += 6 * math.gcd(a,b)
for a in range(1,k-1):
    for b in range(a+1,k):
        for c in range(b+1,k+1):
            ans += 6 * gcd(a,b,c)
print(ans)

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

#define int long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define dbg(x) cerr << #x << ": " << x << endl;
#define dbg2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define dbg3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define dbgB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const double PI = 3.14159265358979323846;

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<typename T>
void print1(T begin, T end) {
  while (begin != end) {
    cout << (*begin) << " ";
    *begin++;
  }
  cout << endl;
}

template<typename T>
void print2(T Array, int height, int width) {
  for (int i = 0; i < height; i++) {
    for (int j = 0; j < width; j++) {
      cout << " " << Array[i][j];
    }
    cout << endl;
  }
}

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

int N;
double dp[3333][3333];
double p[3333];

signed main() {
  cin >> N;
  repp (i, 0, N) {
    cin >> p[i];
  }

  dp[0][0] = 1;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      dp[i+1][j+1] += dp[i][j] * p[i];
      dp[i+1][j] += dp[i][j] * (1 - p[i]);
    }
  }

  double ans = 0;
  for (int i = N/2+1; i <= N; i++) {
    ans += dp[N][i];
  }
  printf("%.10f\n", ans);

  return 0;
}

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

#define rep(i,n) for(int i = 0; i < n; i++)
#define Rep(i,n) for(int i = 1; i <= n; i++)
#define sz(x) int(x.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define endl '\n'
#define fi first
#define se second
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
template<class T> using V = vector<T>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll &a, const ll &b){return ((a)+(b)-1)/b;}
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; }



int main(){
    int n;
    cin >> n;
    int ans = 0;
    Rep(i,n) {
        int a;
        cin >> a;
        if(a % 2 == 1 && i % 2 == 1) ans++;

    }
    cout << ans << endl;
}

Measured memory_bytes: 3640
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include "bits/stdc++.h"

typedef long long ll;
using namespace std;


#define FOR(i,n) for(ll i=0;i<n;i++) 
#define RFOR(i,n) for(ll i=n-1;i>=0;--i)
#define COUT(str) cout << str << endl


//入力
int n,k,x,y,sum; 

int main() {

	scanf("%d %d %d %d", &n,&k,&x,&y);
	
	if (n > k) {
		sum = k*x+(n-k)*y;
	}
	else {
		sum = n*x;
	}

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

	return 0;
}


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

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

using namespace std;

vector<int> p;
vector<bool> er;
void sieve(int n){
	er.assign(n+1,true);
	er[0]=er[1]=false;
	for(int i=2;i*i<=n;i++) if(er[i]) for(int j=i*i;j<=n;j+=i) er[j]=false;
	rep(i,n+1) if(er[i]) p.emplace_back(i);
}

bool f(int n,int q,int e){ // whether q^e | n!
	for(int i=2;i<=n;i++) if(i%q==0) {
		int a=i;
		do{
			a/=q;
			e--;
			if(e==0) return true;
		}while(a%q==0);
	}
	return false;
}

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

	sieve(n);

	int m=p.size(),ans=0;
	rep(i,m) rep(k,m) rep(j,k) if(i!=j && i!=k) {
		if(f(n,p[i],2) && f(n,p[j],4) && f(n,p[k],4)) ans++;
	}
	rep(i,m) rep(j,m) if(i!=j) {
		if(f(n,p[i],2) && f(n,p[j],24)) ans++;
		if(f(n,p[i],4) && f(n,p[j],14)) ans++;
	}
	rep(i,m){
		if(f(n,p[i],74)) ans++;
	}
	cout<<ans<<endl;

	return 0;
}


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

int main() {
  int N;
  cin >> N;
  int l[N];  
  for(int i=0; i<N; i++){ 
    cin >> l[i];
  }
  
  int l_max = 0;
  for(int k=0; k<N; k++){
  	if(l_max<l[k]){
    	l_max = l[k];
    }
  }
  
  
  //cout << l_max << endl;
  int l_rest = l_max;
  
  for(int j=0; j<N; j++){
  	l_rest = l_rest - l[j];
  	//cout << l_rest << endl;
    if(l_rest < -l_max){
    	cout << "Yes" << endl;
        return 0;
    }
    
  }
  
  cout << "No" << endl;
  return 0;
}


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

#define FOR(i,a,b) for(int i=(a);i<(b);++(i))
#define REP(i,n) FOR(i,0,n)

#define dump(x) cerr << #x << " = " <<(x)<<endl;
#define debug(x) cerr << #x << " = " <<(x) << "(L" << __LINE__ << ")" << __FILE__ << endl;

#define BIT_ON(x,b) ((x)|=(b))
#define BIT_OFF(x,b) ((x)&=~(b))
#define BIT_IS_ON(x,b) (((x)&(b))==(b))


using namespace std;

int main(void){
  int N, M;
  vector<string> f(200);
  vector<int> ans(200);
  int i,j;
  cin >> N;
  
  int size = 0;
  REP(i,N){

    string s;
    cin >> s;
    bool exist = false;
    
    REP(j, size){
      if(f[j]==s){
        exist = true;
        ans[j]++;
      }
    }

    if(!exist){
      f[size] = s;
      ans[size] = 1;
      size++;
    }
    
  } 

  cin >> M;
  
  REP(i,M){

    string s;
    cin >> s;
    bool exist = false;
    
    REP(j, size){
      if(f[j]==s){
        exist = true;
        ans[j]--;
      }
    }

    if(!exist){
      f[size] = s;
      ans[size] = -1;
      size++;
    }
  } 

  int m = *max_element(ans.begin(), ans.end());
  //REP(i,size){   cout << ans[i] << endl;  }
  cout << m << endl;


  return 0;
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
a = A[0]


def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a % b)


for i in range(1, N):
    a = gcd(a, A[i])


print(a)

Measured memory_bytes: 14224
#include<iostream>

using namespace std;

int main() {
	int n, a, b, c;
	cin >> n;
	while(n>0) {
		cin >> a >> b >> c;
		if(a > b && a > c){			
			if(a*a == b*b + c*c) cout << "YES" << endl;
			else cout << "NO" <<endl;
		
		}else if(b > a && b > c){			
			if(b*b == a*a + c*c) cout << "YES" << endl;
			else cout << "NO" <<endl;

		}else{			
			if(c*c == a*a + b*b) cout << "YES" << endl;
			else cout << "NO" <<endl;
		}
		n--;
	}
	return 0;
}

Measured memory_bytes: 1156
import sys, math, itertools, collections, bisect 
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8') 
inf = float('inf') ;mod = 10**9+7 
mans = inf ;ans = 0 ;count = 0 ;pro = 1

a, b = map(int, input().split())
for i in range(a, b+1):
    num_str = str(i)
    chk = ''.join(list(reversed(num_str)))
    if num_str == chk:
        ans += 1
print(ans)

Measured memory_bytes: 74296
#include <iostream>
#include <cmath>
using namespace std;
int main(void){
    
    int N, D;
    cin >> N >> D;
    
    int ans = 0;
    for(int i = 0; i < N; i++){
        long long x, y;
        cin >> x >> y;
        double distance = sqrt(x * x + y * y);
        if(distance <= D) ans++; 
    }
    
    cout << ans << endl;
}


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

int main(){
	string S,T;
    cin >> S >> T ;
    if(T.size()==S.size()+1 ){
      rep(i,S.size()){
        if(S.at(i)==T.at(i)){
          int si=S.size();
          if(i==si-1){
            cout << "Yes" << endl;
          }
          continue;
        }
        else{
          cout << "No" << endl;
          break;
        }
      }
    }
    else {
      cout << "No" << endl;
    }
     
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define range(a) a.begin(),a.end()
int main(){
	int P,Q,R;cin>>P>>Q>>R;
	cout<<P+Q+R-max(P,max(Q,R))<<endl;
}

Measured memory_bytes: 256
import queue

h, w = map(int, input().split())
s = [list(input()) for _ in range(h)]

ans = 0
for i in range(h):
    for j in range(w):
        if s[i][j] == ".":
            t = [["."]*w for _ in range(h)]
            t[i][j] = 0
            q = queue.Queue()
            q.put((j, i))
            while True:
                x, y = q.get()
                for k, l in (1, 0), (-1, 0), (0, 1), (0, -1):
                    if (0 <= x+k and x+k < w and
                        0 <= y+l and y+l < h and
                        s[y+l][x+k] == "." and t[y+l][x+k] == "."):
                            t[y+l][x+k] = t[y][x] + 1
                            q.put((x+k, y+l))
                            
                if q.empty():
                    ans = max(ans, t[y][x])
                    break
print(ans)

Measured memory_bytes: 65108
#include <bits/stdc++.h>
using namespace std;
#define int long long
using ll=long long;
using vi=vector<int>;
using pii=pair<int,int>;
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define FORE(x,c) for(auto &x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define SZ(c) ((int)c.size())
#define CONTAIN(c,x) (c.find(x)!=end(c))
#define OUTOFRANGE(y,x,h,w) (y<0||x<0||y>=h||x>=w)
#define dump(...)
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
#define INF (1001001001)
#define INFLL (1001001001001001001ll)
template<class T> ostream& operator << (ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v)) os<<*i<<(i==end(v)-1?"":"\n"); return os; }
template<class T> istream& operator >> (istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is>>*i; return is; }
template<class T> istream& operator >> (istream &is, pair<T,T> &p) {
    is>>p.first>>p.second; return is; }
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> using heap = priority_queue<T,vector<T>,greater<T>>;
struct before_main_function {
    before_main_function() {
        #ifdef int
            #undef INF
            #define INF INFLL
            #define stoi stoll
        #endif
        cin.tie(0);ios::sync_with_stdio(false);
        cout<<setprecision(15)<<fixed;
        #define endl "\n"
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

signed main() {
    int a=2;
    int b=1;
    int n;
    cin>>n;
    if(n==1) {
        cout<<1<<endl;
        return 0;
    }
    int c;
    REP(i,n-1) {
        c=a+b;
        a=b;
        b=c;
    }
    cout<<c<<endl;
    return 0;
}


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

#define fast ios_base::sync_with_stdio(false);   cin.tie(NULL); cout.tie(NULL);
#define fl(i,a,n) for(int i=a; i<n; i++)
#define ll long long 
#define pb push_back
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define test()  int tt;  cin>>tt;  while(tt--)
#define nl  cout<<"\n"
#define dbg(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args)    {
    cout << *it << " = " << a << endl;
    err(++it, args...);
}
const int mod=1e9+7;

int main()  {
    fast;
    int n,k;  cin>>n>>k;
    int h[n],ans[n];
    fl(i,0,n)   cin>>h[i];
    ans[0]=0;
    fl(i,1,n)   {
        ans[i]=INT_MAX;
        for(int j=i-1;j>=max(0,i-k);j--)
            ans[i]=min(ans[i],ans[j]+abs(h[i]-h[j]));
    }
    cout<<ans[n-1];
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
    private static final int MOD = 1_000_000_007;
    private static final String YES = "Yes";
    private static final String NO = "No";

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

        int X = sc.nextInt();

        System.out.println(solve(X));
    }

    private static int solve(int X) {
        int count = 0;

        int total = 0;
        while (true) {
            count++;
            total += X;
            total %= 360;

            if (total%360 == 0) break;
        }

        return count;
    }
}

Measured memory_bytes: 35728
#include <iostream>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <vector>
#include <queue>
#define ll long long
using namespace std;
vector<ll>d;
int main()
{
   ll x,y,a,b;
   cin>>x>>y;
   a=x;
   while(a<=y)
   {
       d.push_back(a);
       a=a*2;
   }
   printf("%d\n",d.size());
    return 0;
}


Measured memory_bytes: 256
n = int(input())
S = [input() for i in range(n)]
m = int(input())
T = [input() for i in range(m)]

from collections import Counter
CS = Counter(S)
CT = Counter(T)
maxv = 0
for k, v in CS.items():
	maxv = max(maxv, v - CT[k])
print(maxv)

Measured memory_bytes: 38256
#include <bits/stdc++.h>
using namespace std;
 
using ll=long long;
 
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define pb push_back
#define eb emplace_back
#define a first
#define b second
#define bg begin()
#define ed end()
#define all(x) x.bg,x.ed
const ll MOD = 998244353;


int main() {
    int n; 
    cin >> n;
    int cnt = 0, cnta = 0, cntb = 0, cntba = 0;
    rep(i, n) {
        string s;
        cin >> s;
        rep(j, s.size()-1) if (s[j] == 'A' && s[j+1] == 'B') ++cnt;
        if (s[s.size()-1] == 'A') {
            if (s[0] == 'B') ++cntba;
            else ++cnta;
        } else {
            if (s[0] == 'B') ++cntb;
        }
    } 

    if (cntba == 0) {
        cnt += min(cnta, cntb);
    } else {
        if (cnta + cntb > 0) cnt += cntba + min(cnta, cntb);
        else cnt += cntba-1;
    }
    cout << cnt << endl;
    return 0;
}

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

template<int mod> class ModInt
{
 private:
    lint val;
 public:
    lint value(){ return val; }
    ModInt(lint x=0){ val=x%mod; }
    ModInt pow(int n){
        ModInt res(1),x(val);
        while(n>0){ if(n&1) res*=x; x*=x; n>>=1; }
        return res;
    }
    ModInt inv(){ return pow(mod-2); }
    ModInt& operator+=(ModInt rhs){ val+=rhs.val; if(val>=mod) val-=mod; return *this; }
    ModInt& operator-=(ModInt rhs){ val+=mod-rhs.val; if(val>=mod) val-=mod; return *this; }
    ModInt& operator*=(ModInt rhs){ val=val*rhs.val%mod; return *this; }
    ModInt& operator/=(ModInt rhs){ *this*=rhs.inv(); return *this; }
    ModInt operator+(ModInt rhs){ return ModInt(val)+=rhs; }
    ModInt operator-(ModInt rhs){ return ModInt(val)-=rhs; }
    ModInt operator*(ModInt rhs){ return ModInt(val)*=rhs; }
    ModInt operator/(ModInt rhs){ return ModInt(val)/=rhs; }
};
using mint=ModInt<1000000007>;

template<typename T> class BiCoef
{
 public:
    vector<T> fact,ifact,inv;
    BiCoef(int N):fact(N+1),ifact(N+1),inv(N+1){
        fact[0]=ifact[N]=inv[0]=1;
        for(int i=1;i<=N;i++) fact[i]=fact[i-1]*i;
        ifact[N]/=fact[N];
        for(int i=N-1;i>=0;i--) ifact[i]=ifact[i+1]*(i+1);
        for(int i=1;i<=N;i++) inv[i]=ifact[i]*fact[i-1];
    }
    T comb(int n,int k){
        if(n<0 or k<0 or n<k) return 0;
        return fact[n]*ifact[k]*ifact[n-k];
    }
};

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

   int N,K; cin>>N>>K;
   const int MAX=500010;
   BiCoef<mint> bc(MAX);

   mint ans=0;
   for(int i=0;i<=min(N-1,K);i++){
      mint x=bc.comb(N,i)*bc.comb(N-1,N-i-1);
      ans+=x;
      // cout<<i<<' '<<x.value()<<endl;
   }
   cout<<ans.value()<<endl;
   return 0;
}


Measured memory_bytes: 12032
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
//---------------------------------//

void dfs(int u, const vector<vector<pii>> & g, vector<int> & done) {
	if (done[u]) return;
	done[u] = true;
	
	for (pii e : g[u]) {
		int v = e.fi;
		if (!done[v]) dfs(v, g, done);
	}
}

int main() {
	int N, M, P;
	cin >> N >> M >> P;
	
	vector<vector<pii>> g(N), rg(N);
	REP(i, M) {
		int a, b, c;
		scanf("%d %d %d", &a, &b, &c);
		--a; --b;
		g[a].emplace_back(b, c - P);
		rg[b].emplace_back(a, c - P);
	}
	
	vector<ll> d(N, -longINF);
	d[0] = 0;
	vector<int> loop(N);
	REP(i, M + 1) {
		REP(j, N) {
			if (d[j] == -longINF) continue;
			for (pii e : g[j]) {
				int v = e.fi;
				int c = e.se;
				if (chmax(d[v], d[j] + c)) {
					if (i == M) loop[v] = true;
				}
			}
		}
	}
	
	vector<int> done[2];
	REP(i, 2) done[i].resize(N);
	dfs(0, g, done[0]);
	dfs(N - 1, rg, done[1]);
	
	bool upl = false;
	REP(i, N) upl |= done[0][i] && done[1][i] && loop[i];
	
	if (upl) puts("-1");
	else cout << max(d[N - 1], 0ll) << endl;
	
	return 0;
}


Measured memory_bytes: 640
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <string>
#include <functional>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <stack>
#define SIZE 100005

using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

vector <int> vec[SIZE];
int n,K;
int ret;

int dfs(int v=0,int p=-1,int d=0)
{
	int now=0;
	for(int i=0;i<vec[v].size();i++)
	{
		int to=vec[v][i];
		now=max(now,dfs(to,v,d+1)+1);
	}
	if(d>=2&&now>=K-1)
	{
		//printf("%d %d\n",v,now);
		ret++;
		now=-1;
	}
	return now;
}
int main()
{
	scanf("%d %d",&n,&K);
	ret=0;
	for(int i=0;i<n;i++)
	{
		int to;
		scanf("%d",&to);to--;
		if(i==0)
		{
			if(to!=0) ret++;
		}
		else
		{
			vec[to].push_back(i);
		}
	}
	dfs();
	printf("%d\n",ret);
	return 0;
}


Measured memory_bytes: 13568
from heapq import heappush, heappop

INF = float('inf')

# 単一始点最短経路を求める（ダイクストラ法）
def Dijkstra(adjList, vSt):
    numV = len(adjList)
    numUsed = 0
    costs = [INF] * numV
    costs[vSt] = 0
    prevs = [[] for _ in range(numV)] ###
    PQ = []
    heappush(PQ, (0, vSt))

    while PQ:
        c, vNow = heappop(PQ)
        if c > costs[vNow]: continue

        numUsed += 1
        if numUsed == numV: break

        costNow = c
        for v2, wt in adjList[vNow]:
            c2 = costNow + wt
            if c2 < costs[v2]:
                costs[v2] = c2
                prevs[v2] = [vNow] ###
                heappush(PQ, (c2, v2))
            elif c2 == costs[v2]: ###
                prevs[v2].append(vNow) ###

    return prevs ###


N, M = map(int, input().split())
adjL = [[] for v in range(N)]
adjM = [[0] * N for v in range(N)]
for _ in range(M):
    a, b, c = map(int, input().split())
    adjL[a - 1].append((b - 1, c))
    adjL[b - 1].append((a - 1, c))
    if a > b: a, b = b, a
    adjM[a - 1][b - 1] = 1

for i in range(N):
    prevs = Dijkstra(adjL, i)
    for u in range(N):
        for v in prevs[u]:
            if u < v:
                adjM[u][v] = 0
            else:
                adjM[v][u] = 0

print(sum(map(sum, adjM)))


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

int main(){
    int N;
    cin >> N;
    int len = 0, ok = 0;
    while(N--){
        int a, b;
        cin >> a >> b;
        if(a == b){
            len++;
            if(len >= 3) ok = 1;
        }else{
            len = 0;
        }
    }
    cout << (ok ? "Yes" : "No") << endl;
    return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,a,n) for(ll i=(a); i<(ll)(n); i++)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(v) (v).begin(), (v).end()

int main(void) {
    string s;
    cin >> s;
    for (int i=0; i<s.size()-1; i++) {
        if (s[i] == 'A' && s[i+1] == 'C') {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}


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

int main()

{   string s;
    int n=s.length();
    int i , count=0;
    cin>>n;
    cin>>s;
    for(i=0;i<s.length();i++){
        if(s[i]=='A'){
            if(s[i+1]=='B'){
                if(s[i+2]=='C'){
                    count=count+1;}}}
        else{ continue;}}
    cout<<count<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
template <class T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

typedef long long ll;

#define sz(x) int(x.size())
#define rep(i,n) for (int i = 0; i < (n); ++i)

int main() {
  string s, t;
  cin >> s >> t;
  vector<vector<int> > is(26);

  int n = sz(s);
  int m = sz(t);
  rep(i, n) is[s[i] - 'a'].push_back(i);
  rep(i, n) is[s[i] - 'a'].push_back(i + n);

  ll ans = 0;
  int p = 0;
  rep(i, m) {
    int c = t[i] - 'a';
    if (sz(is[c]) == 0) {
      puts("-1");
      return 0;
    }
    p = *lower_bound(is[c].begin(), is[c].end(), p)+1;
    if (p >= n) {
      p -= n;
      ans += n;
    }
  }
  ans += p;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1724
###############################################################################
#Imports
import collections
import itertools
from functools import lru_cache
import sys
import math
###############################################################################
#Constants
MOD = int(1e9)+7
###############################################################################
#Helper
def helper():
	pass
###############################################################################
#Solver
def solve():
	n = int(input())
	arr = list(map(int, input().split(' ')))
	sm = 1
	if 0 in arr:
		print(0)
		return
	for num in arr:
		sm *= num
		if sm > int(1e18):
			print(-1)
			return
	print(sm)

###############################################################################
#Driver
t = 1
for _ in range(t):
	solve()
###############################################################################


Measured memory_bytes: 81752
import sys

def S(): return sys.stdin.readline().rstrip()

N,M = map(int,S().split())
mod = 10**9+7

a = M  # (M_P_N)**2
for i in range(1,N):
    a *= M-i
    a %= mod

# 包除原理
# 2つめの条件は常に成り立った状況で考える
# {1,…,N}の部分集合Sの元iに対してA_i=B_iが成り立つようなA_1,…,B_1,…の組の個数を考える
ans = a**2 % mod
r = ans
for i in range(1,N+1):
    r *= (N-i+1)
    r %= mod
    r *= pow(i,mod-2,mod)
    r %= mod
    r *= pow(M-i+1,mod-2,mod)*(-1)
    r %= mod
    ans += r
    ans %= mod

print(ans)

Measured memory_bytes: 67920
leftp,rightp=0,0
loopnum = int(input())

for i in range(loopnum):
    st=input().split()
    stnew = sorted(st)
        
    if st[0]==st[1]:
        leftp = leftp+1
        rightp = rightp+1
    elif st != stnew:
        leftp=leftp+3
    elif st == stnew:
        rightp = rightp+3
        
print(str(leftp)+" "+str(rightp))


Measured memory_bytes: 5600
#include <bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define print(x) cout << (x) << endl
typedef long long ll;
const ll MOD = 1000000007;
const ll MOD2 = 998244353;

using namespace std;

int main(){
    vector<int> c(9,0);
    int n;  cin >> n;
    for(int i=0; i<n; i++){
        int a;  cin >> a;
        if(a < 3200) c[a/400]++;
        else c[8]++;
    }
    int mi, ma;
    mi = 0;
    ma = 0;
    for(int i=0; i<8; i++) if(c[i] > 0){mi++; ma++;}
    if(mi == 0) mi++;
    ma += c[8];
    cout << mi << " " << ma << endl;
    return 0;
}

Measured memory_bytes: 3600
#include<bits/stdc++.h>
#define int long long
#define endl "\n"
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;

int32_t main()
{
	IOS
	int n;cin>>n;
	vector<int>h(n+1);
	vector<int>dp(n+1);
	for(int i=1;i<=n;i++)
	cin>>h[i];
	
	dp[1]=0;
	for(int i=2;i<=n;i++)
	{
		dp[i]=1e15;
		for(int j=i-1;j>i-3 && j > 0 ;j--)
		{
			dp[i]=min(dp[i],dp[j]+abs(h[i]-h[j]));
		}
	}
	
	cout << dp[n] << endl;
	
}


Measured memory_bytes: 1792
N,K = map(int,input().split())
R,S,P = map(int,input().split())
T = list(input())

ans = 0
check = {i:0 for i in range(N)}
for i in range(N):
    if i <= K-1:
        if T[i] == 'r':
            ans += P
        elif T[i] == 's':
            ans += R
        else:
            ans += S
    else:
        if T[i] != T[i-K]:
            if T[i] == 'r':
                ans += P
            elif T[i] == 's':
                ans += R
            else:
                ans += S
        elif T[i] == T[i-K] and check[i-K] == 1:
            if T[i] == 'r':
                ans += P
            elif T[i] == 's':
                ans += R   
            else:
                ans += S
        else:
            check[i] = 1

print(ans)




Measured memory_bytes: 15960
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int ans = 0;
        for (int i = 1 ; i <= N ; i++) {
            int l = sc.nextInt();
            int r = sc.nextInt();
            ans += r - l + 1;
        }
        System.out.println(ans);
    }

}

Measured memory_bytes: 26812
/**
 *     author: qodjf
 *     created: 07.11.2020 10:50:20
 */
#include <bits/stdc++.h>
using namespace std;

string to_string(string s) { return '"' + s + '"'; }
string to_string(const char *s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
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;
}

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifndef ONLINE_JUDGE
#define dbg(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define dbg(...) 42
#endif

template <class T>
inline bool chmax(T &a, T b) {
  return a < b && (a = b, true);
}
template <class T>
inline bool chmin(T &a, T b) {
  return a > b && (a = b, true);
}

#define mst(x, a) memset(x, a, sizeof(x))
#define all(a) begin(a), end(a)
#define rep(i, begin, end)                            \
  for (__typeof(end) i = (begin) - ((begin) > (end)); \
       i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;
constexpr int INF = 0x3f3f3f3f;
constexpr ll LLINF = 0x3f3f3f3f3f3f3f3f;
constexpr ll MOD = 1e9 + 7;

int A[2][110];
int dp[3][110];

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

  int N;
  cin >> N;
  rep(i, 0, 2) {
    rep(j, 0, N) { cin >> A[i][j]; }
  }
  mst(dp, 0);
  rep(i, 1, 3) {
    rep(j, 1, N + 1) {
      dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]) + A[i - 1][j - 1];
    }
  }
  cout << dp[2][N] << endl;
}


Measured memory_bytes: 3644
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<bool> vb;
#define pb push_back
#define fi first
#define se second
#define in insert
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int mod = 1e9 + 7;
void solve(){
    int n;
    cin >> n;
    unordered_set<int> s;
    for (int i = 0; i < n; ++i) {
        int x;
        cin >> x;
        s.in(x);
    }
    if (s.size() % 2 == 0) cout << s.size() - 1;
    else cout << s.size();
}
int main(){
    speed;
    int t = 1;
    //cin >> t;
    for (int i = 1; i <= t; ++i) {
        solve();
    }
}

Measured memory_bytes: 4388
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC098
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split();
            int a = int.Parse(input[0]);
            int b = int.Parse(input[1]);

            int c = a + b;

            if((a - b) > c)
            {
                c = a - b;
            }

            if((a * b) > c)
            {
                c = a * b;
            }

            Console.WriteLine(c);
            Console.ReadLine();
        }
    }
}


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

int main()
{
  string S;
  cin >> S;
  int ans=999;
  for(int i=0; i<=S.length()-3; i++)
  {
    int num = 100*(S[i]-'0') + 10*(S[i+1]-'0') + (S[i+2]-'0');
    ans = min(ans, abs(753-num));
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define per(i,j,n) for(int i=(int)(j);(int)(n)<=i;i--)
#define int long long
#define ll long long
#define ALL(a) (a).begin(),(a).end()
#define pb push_back
#define mp make_pair
#define endl "\n"
#define vi vector<ll>
#define pii pair<ll,ll>
#define vii vector<vi>
const int MOD=1e9+7;
//const int MOD=998244353;
const int INF=(1ll<<62)-1;
signed main(){
  ll N; cin>>N;
  vi A(2*N);
  rep(i,0,2*N) cin>>A[i];
  sort(ALL(A));
  ll ans=0;
  rep(i,0,N) ans+=A[i*2];
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define MAX 1e9+1
#define MIN -1

int main(){
    int n;
    cin >> n;
    int max_n=MIN,min_n=MAX;
    int a;
    for(int i=0;i<n;i++){
        cin >> a;
        max_n = max(max_n,a);
        min_n = min(min_n,a);
    }
    cout << abs(max_n-min_n) << endl;

    
}


Measured memory_bytes: 256