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

#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)a, i##_len=(b); i<i##_len; i++)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

#define all(box) box.begin(), box.end()

using namespace std;

using P = pair<int,int>;
using ll = long long;

const long long INF = LLONG_MAX/3;

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

struct UnionFind{
	std::vector<int> par,siz;
	void init(int n){
		par.resize(n);
		for(int i=0;i<n;i++)par[i]=i;
		siz.resize(n,1);
	}
	UnionFind(int n){
		init(n);
	}
	int root(int n){
		if(par[n]==n)return n;
		else return par[n]=root(par[n]);
	}
	bool issame(int x,int y){
		return (root(x)==root(y));
	}
	bool marge(int a,int b){
		if(issame(a,b))return false;
		else{
			a=root(a),b=root(b);
			if(siz[a]<siz[b])swap(a,b);
			siz[b]+=siz[a];
			par[a]=par[b];
			return true;
		}
	}
	int size(int n){
		return siz[root(n)];
	}
};

long long gcd(long long a,long long b){
    if(b==0)return a;
    return gcd(b,a%b);
}
long long lcm(long long i,long long j){
    return i*(j/gcd(i,j));
}

const int MOD=998244353;
long long fac[510000], finv[510000], inv[510000];
long long MAX=510000;
bool COMinited=false;
long long COM(int n, int k){
	if(COMinited==false){
		fac[0] = fac[1] = 1;
    	finv[0] = finv[1] = 1;
    	inv[1] = 1;
    	for (int i = 2; i < MAX; i++){
        	fac[i] = fac[i - 1] * i % MOD;
        	inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        	finv[i] = finv[i - 1] * inv[i] % MOD;
    	}
		COMinited=true;
	}
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}
template< typename T >
struct BinaryIndexedTree {
  vector< T > data;

  BinaryIndexedTree(int sz) {
    data.assign(++sz, 0);
  }

  T sum(int k) {
    T ret = 0;
    for(++k; k > 0; k -= k & -k) ret += data[k];
    return (ret);
  }

  void add(int k, T x) {
    for(++k; k < data.size(); k += k & -k) data[k] += x;
  }
};
signed main(){
	int n;
	cin>>n;
	int a[300010];
	rep(i,3*n)cin>>a[i];
	sort(a,a+3*n);
	int re=0;
	rep(i,n,3*n){
		re+=a[i];
		i++;
	}
	cout<<re<<endl;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
template <typename T> void read(T &t) {
	t=0; char ch=getchar(); int f=1;
	while (ch<'0'||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
	do { (t*=10)+=ch-'0'; ch=getchar(); } while ('0'<=ch&&ch<='9'); t*=f;
}
const int INF=1e9;
int n,m,d[710][710],tot,ans;
int c[710],a[710],b[710],dp[710][710];
int C(int x) { return x*(x-1)/2; }
void dfs(int x) {
	if (c[x]==1) a[tot]++;
	else b[tot]++;
	for (int i=1;i<=n;i++) if (d[i][x]) {
		if (c[i]) {
			if (c[i]!=3-c[x]) { printf("-1\n"); exit(0); }
			continue;
		}
		c[i]=3-c[x];
		dfs(i);
	}
}
int main() {
	
	read(n); read(m);
	for (int i=1;i<=n;i++) for (int j=1;j<=n;j++) if (i!=j) d[i][j]=1;
	int x,y;
	for (int i=1;i<=m;i++) {
		read(x); read(y);
		d[x][y]=d[y][x]=0;
	}
	for (int i=1;i<=n;i++) if (!c[i]) {
		c[i]=1; tot++;
		dfs(i);
	}
	dp[0][0]=1;
	for (int i=0;i<tot;i++) {
		for (int j=0;j<=n;j++) if (dp[i][j]) {
			if (j+a[i+1]<=n) dp[i+1][j+a[i+1]]=1;
			if (j+b[i+1]<=n) dp[i+1][j+b[i+1]]=1;
		}
	}
	ans=INF;
	for (int j=0;j<=n;j++) if (dp[tot][j]) ans=min(ans,C(j)+C(n-j));
	printf("%d\n",ans);
	return 0;
}
/*
  0. Enough array size? Enough array size? Enough array size? Interger overflow?
  
  1. Think TWICE, Code ONCE!
  Are there any counterexamples to your algo?
    
  2. Be careful about the BOUNDARIES!
  N=1? P=1? Something about 0?
    
  3. Do not make STUPID MISTAKES!
  Time complexity? Memory usage? Precision error?
*/

Measured memory_bytes: 7536
import java.util.*;
 
public class Main {
	public static int max = 0;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        int K = sc.nextInt();
        long[] A = new long[N+1];
        A[0] = 0;
        int borderA = 0;
        boolean keyA = true;
        for (int i = 1; i < N+1; i++) {
        	long Ai = sc.nextLong();
        	A[i] = Ai+A[i-1];
        	if (K < A[i] && keyA) {
        		borderA = i-1;
        		keyA = false;
        	} else if (i == N && keyA) {
        		borderA = i;
        	}
        }
        long[] B = new long[M+1];
        B[0] = 0;
        int borderB = 0;
        boolean keyB = true;
        for (int i = 1; i < M+1; i++) {
        	long Bi = sc.nextLong();
        	B[i] = Bi+B[i-1];
        	if ((K < B[i] || i == M) && keyB) {
        		borderB = i;
        		keyB = false;
        	} else if (i == N && keyB) {
        		borderB = i;
        	}
        }
        for (int i = 0; i <= borderA; i++) {
        	long res = K-A[i];
        	int jc = 0;
        	for (int j = borderB;-1 < j; j--) {
        		if (B[j] <= res) {
        			jc = j;
        			borderB = j;
        			break;
        		}
        	}
        	if (max < (i + jc)) {
        		max = i+jc;
        	}
        }
        System.out.println(max);
    }
}

Measured memory_bytes: 64748
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ms(x, t) memset(x, t, sizeof(x))
#define ff first
#define ss second
#define all(ar) ar.begin(), ar.end()
#define rall(ar) ar.rbegin(), ar.rend()
#define endl "\n"
typedef pair<int, int> pll;
typedef pair<int, pll> plll;
typedef vector<int> vl;
typedef vector<vector<int>> vvl;
typedef vector<pll> vpll;
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char *name, Arg1 &&arg1) {
  cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&... args) {
  const char *comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}

const int limit = 1e5 + 1;
const int inf = 1e7;
const int mod = 1e9 + 7;

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, m;
  cin >> n >> m;
  vl a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  vl v[n];
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    x--;
    y--;
    v[x].push_back(y);
    v[y].push_back(x);
  }

  int count = 0;
  for (int i = 0; i < n; i++) {
    bool flag = true;
    for (int j = 0; j < v[i].size(); j++) {
      if (a[i] <= a[v[i][j]]) {
        flag = false;
        break;
      }
    }
    if (flag) {
      count++;
    }
  }
  cout << count << endl;

  return 0;
}

Measured memory_bytes: 9784
# AOJ 1104: Where's Your Robot?
# Python3 2018.7.14 bal4u

# N,E,S,W -> 0,1,2,3
f = [[0,1],[1,0],[0,-1],[-1,0]]
b = [[0,-1],[-1,0],[0,1],[1,0]]

while True:
	w, h = map(int, input().split())
	if w == 0: break
	r, c, d = 1, 1, 0
	while True:
		buf = input().split()
		if   buf[0] == "STOP": break
		elif buf[0] == "RIGHT": d = (d+1)%4
		elif buf[0] == "LEFT": d = (d+3)%4
		else:
			if buf[0] == "FORWARD":
				r2 = r + int(buf[1])*f[d][1]
				c2 = c + int(buf[1])*f[d][0]
			else:   # BACKWARD k
				r2 = r + int(buf[1])*b[d][1]
				c2 = c + int(buf[1])*b[d][0]
			if r2 < 1: r2 = 1
			if r2 > h: r2 = h
			if c2 < 1: c2 = 1
			if c2 > w: c2 = w
			r, c = r2, c2
	print(c, r)



Measured memory_bytes: 5624
import sys
import math
import collections
import itertools
import array
import inspect

# Set max recursion limit
sys.setrecursionlimit(10000)

# Debug output
def chkprint(*args):
    names = {id(v):k for k,v in inspect.currentframe().f_back.f_locals.items()}
    print(', '.join(names.get(id(arg),'???')+' = '+repr(arg) for arg in args))

# Binary converter
def to_bin(x):
    return bin(x)[2:]

# --------------------------------------------

M = None

def f(C):
    return abs(sum(C[0][:M])) + abs(sum(C[1][:M])) + abs(sum(C[2][:M]))

def main():
    global M

    N, M = [int(_) for _ in input().split()]

    C = []
    for _ in range(N):
        x, y, z = [int(__) for __ in input().split()]
        C.append([x, y, z])

    if M == 0:
        print(0)
        sys.exit()

    V = [[] for _ in range(8)]


    for c in C:
        V[0].append(c[0] + c[1] + c[2])
        V[1].append(c[0] + c[1] - c[2])
        V[2].append(c[0] - c[1] + c[2])
        V[3].append(c[0] - c[1] - c[2])
        V[4].append(- c[0] + c[1] + c[2])
        V[5].append(- c[0] + c[1] - c[2])
        V[6].append(- c[0] - c[1] + c[2])
        V[7].append(-c[0] - c[1] - c[2])

    ans = -1
    for v in V:
        v.sort(reverse=True)
        ans = max(ans, abs(sum(v[:M])))

    print(ans)




main()


Measured memory_bytes: 5140
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
#define KDNGU ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define S second
#define F first

using namespace std;

typedef long long LL;
typedef long double LD;

const int N = 1e3 + 9, M = 1e3 + 9, OO = 0x3f3f3f, MOD = 1e9 + 7;


int dp[N][M];

int main(){
    int n, m;
    cin >> n >> m;
    char grid[n][m];
    for (int i = 0; i < n; ++i)
        for (int j = 0; j < m; ++j)
            cin >> grid[i][j];
    dp[0][0] = 1;
    for (int i = 0; i < n; ++i)
        for (int j = 0; j < m; ++j){
            if(grid[i][j] == '#')
                continue;
            if (i)
                dp[i][j] = ( (dp[i][j])%MOD + (dp[i - 1][j])%MOD )%MOD;
            if (j)
                dp[i][j] = ( (dp[i][j])%MOD + (dp[i][j - 1])%MOD )%MOD;
        }
    cout << dp[n - 1][m - 1];
}
/*
    GOOD LUCK :*
*/


Measured memory_bytes: 5120
#Macで実行する時
import sys
import os
if sys.platform=="darwin":
	base = os.path.dirname(os.path.abspath(__file__))
	name = os.path.normpath(os.path.join(base, '../atcoder/input.txt'))
	sys.stdin = open(name)

from math import ceil

n = int(input())

print(ceil(n/2))




Measured memory_bytes: 9164
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
typedef pair<int,int> P; typedef pair<Int,Int> Pl;
const int mod = 1e9+7;
#define END {cout<<ans<<'\n'; return 0;}
#define ALL(v) v.begin(),v.end()
#define Pr(type) priority_queue<type>
#define gPr(type) priority_queue<type,vector<type>,greater<type>>
#define V(type) vector<type>
#define rep(i,n) for(int i=0; i<n; i++)
#define rer(i,st,en) for(int i=st; i<=en; i++)
#define eb emplace_back
#define pri1(a) cout<<a<<'\n'
#define pri2(a,n) rep(i,n)cout<<a[i]<<'\n'
#define pri3(a,n) rep(i,n)cout<<a[i]<<(i!=n-1?' ':'\n')
template<class T> inline bool cmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool cmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }



int n,m,_,x,y,q;
string s;

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

  cin>>n; int a[n]; rep(i,n)cin>>a[i];
  rer(i,1,n){
    m=i; pri3(a,n);
    while(m&&a[m-1]>a[m]){
      swap(a[m-1],a[m]); m--;
    }
  }
}


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

int main(){
  int N; cin >> N; int a[N+1], b[N], k=0; long long ans=0;
  for(int i=0; i<N+1; i++) cin >> a[i];
  for(int i=0; i<N; i++) cin >> b[i];
  for(int i=0; i<N; i++){
    k=min(a[i], b[i]); ans+=k;
    if (k<b[i]){
      b[i]-=k; k=min(a[i+1], b[i]);
      ans+=k; a[i+1]-=k;
    }
  }
  cout << ans << endl;
}


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

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef pair<LL, LL> PLL;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())

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

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

int med(int x, int y, int z){
  VI xs{x,y,z}; SORT(xs); return xs[1];
}
int naive(int N, VI xs){
  N = 2*N-1;
  while(N > 1){
	VI tmp(N-2);
	REP(i,N-2){
	  tmp[i] = med(xs[i], xs[i+1], xs[i+2]);
	}
	xs = tmp;
	N -= 2;
  }
  return xs[0];
}

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

  int N; cin >> N;
  int NN = 2*N-1;
  VI xs(NN);
  REP(i,NN) cin >> xs[i];
  if(N == 2){
	cout << 2 << endl;
	return 0;
  }

  int lb = 1, ub = NN+1;
  int c = N-1;
  while(ub-lb>1){
	int m = (lb + ub) / 2;
	VI bit(NN);
	REP(i,NN) bit[i] = (xs[i] >= m);

	int l = c-1, r = c+1;
	while(0 <= l)
	  if(bit[l] == bit[l+1]) break;
	  else --l;
	while(r < NN)
	  if(bit[r-1] == bit[r]) break;
	  else ++r;

	int ge = 0;
	if(0 <= l || r < NN){
	  if(c-l != r-c){
		ge = (c-l<r-c?bit[l]:bit[r]);
	  }
	  else{
		if(bit[l] == bit[r])
		  ge = bit[l];
		else
		  ge = (bit[c] + N+1) % 2;
	  }
	}
	else
	  ge = bit[0];

	if(ge) lb = m;
	else ub = m;
  }
  cout << lb << endl;

  /*
  if(lb != naive(N,xs)){
	return 1;
  }
  */
  
  return 0;
}


Measured memory_bytes: 1808
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream> 
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>  
using namespace std;
#define eps 0.00000001
#define LONG_INF 10000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define f(n) for(int i=0;i<n;++i)
#define REP(i,n) for(long long i = 0;i < n;++i)
int maxium[1000000] = {};
int color[1000000] = {};
vector<int> vertex[1000000];
int main() {
	int n, m,query;
	cin >> n >> m;
	REP(i, m) {
		int a, b;
		cin >> a >> b;
		vertex[a].push_back(b);
		vertex[b].push_back(a);
	}
	vector<pair<int, int>> hoge;
	vector<int> colorful;
	cin >> query;
	REP(i, query) {
		int a, b;
		cin >> a >> b;
		hoge.push_back(make_pair(a, b));
		int c;
		cin >> c;
		colorful.push_back(c);
	}
	reverse(colorful.begin(), colorful.end());
	reverse(hoge.begin(), hoge.end());
	for (int i = 0;i < query;++i) {
		if (maxium[hoge[i].first] < hoge[i].second+1) {
			queue<pair<int, int>> nya;
			map<int, int> visited;
			nya.push(make_pair(hoge[i].first, hoge[i].second+1));
			maxium[hoge[i].first] = hoge[i].second + 1;
			while (nya.empty() == false) {
				pair<int, int> now = nya.front();nya.pop();
				if (visited[now.first] == false) {
					visited[now.first] = true;
					if (color[now.first] == 0)color[now.first] = colorful[i] + 1;
					now.second--;
					if (now.second != 0) {
						for (int q = 0;q < vertex[now.first].size();++q) {
							if (maxium[vertex[now.first][q]] < now.second) {
								maxium[vertex[now.first][q]] = now.second;
								nya.push(make_pair(vertex[now.first][q], now.second));
							}
						}
					}
				}
			}
		}
	}
	for (int i = 1;i <= n;++i) {
		cout << max(color[i] - 1,0) << endl;
	}
	return 0;
}

Measured memory_bytes: 36684
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repI(i, d, n) for (int i = (d); i < (n); ++i)
#define reps1(i, n) for (int i = 1; i < (n); ++i)
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using ll = long long;
using P = pair<int, int>;
using Pl = pair<ll, ll>;
using M = map<int, int>;
ll const INF = 1ll<<61;
double pi = 3.141592653589793238;

int main() {
  ll a, b;
  cin >> a >> b;
  cout << 6 - a - b << endl;

  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <boost/optional.hpp>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define REP(i, n) for(int i = 0, i##_MACRO = (n); i < i##_MACRO; i++)
#define RANGE(i, a, b) for(int i = (a), i##_MACRO = (b); i < i##_MACRO; i++)
#define EACH(e, a) for(auto&& e : a)
#define ALL(a) std::begin(a), std::end(a)
#define RALL(a) std::rbegin(a), std::rend(a)
#define FILL(a, n) memset((a), n, sizeof(a))
#define FILLZ(a) FILL(a, 0)
#define INT(x) (static_cast<int>(x))

using namespace std;

using ll = long long;
using VI = vector<int>;
using VI2D = vector<vector<int>>;

constexpr int INF = 2e9;
constexpr double EPS = 1e-10;
constexpr double PI = acos(-1.0);

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

template <typename T>
constexpr int sign(T x) {
	return x < 0 ? -1 : x > 0 ? 1 : 0;
}

template <>
constexpr int sign(double x) {
	return x < -EPS ? -1 : x > EPS ? 1 : 0;
}

template <typename T, typename U>
constexpr void chmax(T& m, U x) {
	m = max(m, x);
}

template <typename T, typename U>
constexpr void chmin(T& m, U x) {
	m = min(m, x);
}

template <typename T>
constexpr T square(T x) {
	return x * x;
}

int main() {
	int n, m;
	cin >> n >> m;
	VI a(n);
	int sum = 0;
	REP(i, n) {
		cin >> a[i];
		sum += a[i];
	}
	int k = (sum % (4 * m)) ? (sum / (4 * m) + 1) : (sum / (4 * m));
	sort(ALL(a), greater<int>());
	REP(i, m) {
		if(a[i] < k) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <array>
#include <deque>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <iomanip>

using namespace std;
using ll=long long int;

template <typename T>
T pow(T a, ll n) {
    T ret = 1;
    while (n > 0) {
        if (n & 1) ret *= a; 
        a *= a;
        n >>= 1;
    }
    return ret;
}

template <ll mod>
class ModInt {
private:
    ll num;
public:
    ModInt() {};
    ModInt(ll n) { num = n % mod; }
    ModInt inv() const { return pow(*this, mod-2); }
    explicit operator ll() const { return num; }

    ModInt& operator+=(const ModInt& a) {
        num += a.num; 
        if (num >= mod) num -= mod; 
        return *this;
    }
    ModInt& operator-=(const ModInt& a) {
        if (num < a.num) num += mod;
        num -= a.num;
        return *this;
    }
    ModInt& operator*=(const ModInt& a) {
        num = num * a.num % mod;
        return *this;
    }
    ModInt& operator/=(const ModInt& a) { return *this *= a.inv(); }
    friend ModInt operator+(const ModInt& a, const ModInt& b) { return ModInt(a) += b; }
    friend ModInt operator-(const ModInt& a, const ModInt& b) { return ModInt(a) -= b; }
    friend ModInt operator*(const ModInt& a, const ModInt& b) { return ModInt(a) *= b; }
    friend ModInt operator/(const ModInt& a, const ModInt& b) { return ModInt(a) /= b; }

    friend ostream& operator<<(ostream& os, const ModInt& a) { return os << a.num; }
    friend istream& operator>>(istream& is, ModInt& a) {
        ll tmp;
        is >> tmp;
        a.num = tmp % mod;
        return is;
    }
};
using mint = ModInt<1000000007>;

mint dp[201][100001];

int main() {
    int n, x;
    cin >> n >> x;
    vector<int> s(n);
    for (auto &e: s) cin >> e;
    sort(s.begin(), s.end(), greater<int>());

    dp[0][x] = 1;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j <= x; ++j) {
            if ((ll)dp[i][j] == 0) continue;
            dp[i+1][j%s[i]] += dp[i][j];
            dp[i+1][j] += dp[i][j] * (n - i - 1);
        }
    }

    mint ans = 0;
    for (int j = 0; j <= x; ++j) {
        ans += dp[n][j] * j;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 154240
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        Map<String,Integer> map = new HashMap<>();
        for(int i=0; i<n; i++) {
            String key = sc.next();
            if(map.containsKey(key)) {
                map.put(key, map.get(key) + 1);
            }else {
                map.put(key, 1);
            }
        }
        int max = Collections.max(map.values());
        List<String> s = new ArrayList<>();
        Set<Map.Entry<String,Integer>> entries = map.entrySet();
        for(Map.Entry<String, Integer> entry : entries) {
            if(entry.getValue() == max ) {
                s.add(entry.getKey());
            }
        }
        Collections.sort(s);
        for(String ss : s) {
            System.out.println(ss);
        }
    }
}

Measured memory_bytes: 82068
#include<bits/stdc++.h>
typedef long long ll;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
ll n,i,ta,has;
map<ll,ll> me;
int main()
{
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>n;
	while(n--)
	{
		cin>>ta;
		if(me[ta])
		{
			has--;
			me[ta]=0;
		}
		else
		{
			me[ta]=1;
			has++;
		}
	}
	cout<<has<<"\n";
}

Measured memory_bytes: 6528
def prime(n):
    natural=[]
    n=n+1
    N=[True for i in range(n)]
    N[0],N[1]=0,0
    for i in range(4,n,2):N[i]=False
    for i in range(3,int(n**0.5)):
        if N[i]==True:
            for j in range(i*2,n,i):N[j]=False
    for i in range(n):
        if N[i]==True:
             natural.append(i)
    return natural


box=prime(55555)
count=0
new=[]
for i in box:
    if i%5==1:
        new.append(i)
        count +=1
    if count>=55:break
print(*[new[i] for i in range(int(input()))])

Measured memory_bytes: 43376
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int,int>;

ll solve() {
    ll N;
    cin >> N;
    vector<ll> A(N-1), B(N-1);
    vector<vector<pii>> G(N);    // to, edge
    for ( int i = 0; i < N-1; i++ ) {
        cin >> A[i] >> B[i];
        A[i]--, B[i]--;
        G[A[i]].push_back(pii(B[i], i));
        G[B[i]].push_back(pii(A[i], i));
    }
    int k = -1;
    for ( int i = 0; i < N; i++ ) {
        k = max(k, (int)G[i].size());
    }

    vector<int> cl(N-1, -1); // edge color;
    vector<int> uc(N, -1); // v used color;
    vector<int> used(N);
    queue<int> q;
    q.push(0);
    while ( !q.empty() ) {
        int v = q.front();
        q.pop();
        used[v] = 1;
        int c = 1;
        for ( pii u : G[v] ) {
            if ( used[u.first] ) {
                continue;
            }
            if ( uc[v] == c ) c++;
            cl[u.second] = c;
            uc[u.first] = c;
            c++;
            q.push(u.first);
        }
    }

    cout << k << "\n";
    for ( int i = 0; i < N-1; i++ ) {
        cout << cl[i] << "\n";
    }
    return 0;
}

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

Measured memory_bytes: 9344
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5+10;
ll a[maxn],g1[maxn],g2[maxn];
multiset<int> se;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	memset(g1,0,sizeof(g1));
	memset(g2,0,sizeof(g2));
	ll n;
	cin >> n;
	cin >> a[1];
	g1[1] = a[1];
	for(int i=2;i<=n;i++){
		cin >> a[i];
		g1[i] = __gcd(a[i],g1[i-1]);
	}

	g2[n] = a[n];
	for(int i=n-1;i>=1;i--){
		g2[i] = __gcd(g2[i+1],a[i]);
	}
//	for(int i=1;i<=n;i++){
//		cout << g2[i] << "  ";
//	}
//	cout <<endl;
	ll ma = -1;
	for(int i=1;i<=n;i++){
		ll cc = __gcd(g1[i-1],g2[i+1]);
		ma = max(ma,cc);
	}
	cout << ma << endl;
} 

Measured memory_bytes: 2560
N,A,B,C=map(int, input().split())
L=[int(input()) for i in range(N)]
from itertools import product
ans=10**9
for p in product(range(4),repeat=N):
    l=[0]*3
    cost=0
    for i,t in enumerate(p):
        if t<3:
            if l[t]>0:
                cost+=10
            l[t]+=L[i]
    if min(l)>0:
        ans=min(ans,cost+abs(A-l[0])+abs(B-l[1])+abs(C-l[2]))
print(ans)

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

int main() {
    string S; cin >> S;
    rep(i, S.size()){
        if(S[i] == '?'){
            S[i] = 'D';
        }
    }
    cout << S << endl;

    return 0;
}

Measured memory_bytes: 3752
/* I have already deleted My old account because somebody stole my code
and i have no idea how. If you are copying this code atleast make it look different 
Yours Faithfully
Shobhit Yadav */

#include<bits/stdc++.h>
using namespace std;
#define ll long long 

ll A,B;
/*ll freq[200005];*/
void solve(){
	 /*memset(freq,0,sizeof(freq));*/
  cin>>A>>B;
  
  cout<<A*B<<'\n';
}



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

	return 0;
}

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

int main() {
    int A, B;
    cin >> A >> B;
    if(((A+B) % 2) == 1){
        cout << "IMPOSSIBLE" << "\n";
        return 0;
    }
    cout << (A+B)/2;
    return 0;
}

Measured memory_bytes: 256
class Fenwick:
    def __init__(self, size):
        self.arr = [0]*size
    
    def update(self, i, val):
        while i < len(self.arr): self.arr[i] += val; i |= i+1
    
    def getsum(self, i):
        res = 0
        while i >= 0: res+= self.arr[i]; i = (i&(i+1))-1
        return res

def paramin(F, l, r):
    while l <= r:
        mid = (l+r)//2
        if F(mid): ans, r = mid, mid-1
        else: l = mid+1
    return ans

from itertools import accumulate
def medleq(i):
    x = vals[i]
    M = [(y<=x)*2-1 for y in L]
    MA = list(accumulate(M))
    cnt = sum(y>0 for y in MA)
    F = Fenwick(2*n+3)
    for y in MA:
        c = y+n+1
        cnt+= F.getsum(c-1)
        F.update(c, 1)
    return cnt >= target

n = int(input())
L = list(map(int,input().split()))
tot = n + n*(n-1)//2
target = tot//2 + 1
vals = sorted(set(L))
print(vals[paramin(medleq, 0, len(vals)-1)])

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

using namespace std;
#define ll long long
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(vr) vr.begin(),vr.end()
const ll N=5e3+10,inf=1e17;
ll a[N],n,sub[N],dp[N][N][2],val[N][2];
vector<int> G[N];

void read()
{
    cin>>n;
    for (int i=1;i<=n;i++) cin>>a[i];
    for (int i=1,u,v;i<n;i++)
    {
        cin>>u>>v;
        G[u].pb(v);
        G[v].pb(u);
    }
}

void opt(ll &x,ll y) { x=min(x,y); }

void dfs(int u,int r)
{
    sub[u]=1;
    if (a[u]>0)
    {
        dp[u][0][0]=a[u];
        dp[u][0][1]=inf;
    }
    else
    {
        dp[u][0][0]=inf;
        dp[u][0][1]=a[u];
    }
    for (int v : G[u])
        if (v!=r)
        {
            dfs(v,u);
            for (int i=0;i<sub[u]+sub[v];i++)
                for (int t=0;t<=1;t++) val[i][t]=inf;
            for (int i=0;i<sub[u];i++)
                for (int j=0;j<sub[v];j++)
                    for (int x=0;x<=1;x++)
                        for (int y=0;y<=1;y++)
                        {
                            opt(val[i+j][x | y],dp[u][i][x]+dp[v][j][y]);
                            if ((y==0 && dp[v][j][y]<inf) || dp[v][j][y]<0) opt(val[i+j+1][x],dp[u][i][x]);
                        }
            sub[u]+=sub[v];
            for (int i=0;i<sub[u];i++)
                for (int t=0;t<=1;t++) dp[u][i][t]=val[i][t];
        }
}

void process()
{
    dfs(1,0);
    for (int i=0;i<sub[1];i++)
        if (dp[1][i][1]<0 || dp[1][i][0]<inf)
        {
            cout<<i;
            return;
        }
}

int main()
{
    //freopen("ss.inp","r",stdin);
    ios::sync_with_stdio(false);
    cin.tie(0);
    read();
    process();
    return 0;
}


Measured memory_bytes: 391552
<?php
$n = int();
$hArray = ints();

$min = $hArray[0]-1;
for($i = 0; $i < $n; $i++){
  if($hArray[$i] < $min){
    echo "No";exit;
  }
  $min = max($min, $hArray[$i] - 1);
}
echo "Yes";exit;

function str(){
  return trim(fgets(STDIN));
}
function ints(){
  return array_map("intval", explode(" ", trim(fgets(STDIN))));
}
function int(){
  return intval(trim(fgets(STDIN)));
}
function o(...$val){
    if(count($val)==1)$val = array_shift($val);
    $trace = debug_backtrace();
    echo $trace[0]['line'].")";
    if(is_array($val)){
        if(count($val) == 0){
            echo "empty array";
        }elseif(!is_array(current($val))){
            echo "array:";
            echo implode(" ", $val)."\n";
        }else{
            echo "array:array\n";
            foreach($val as $row){
                echo implode(" ", $row)."\n";
            }
        }
    }else{
        echo $val."\n";
    }
}

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

int p, val[30000];
int a[30000], b[30000];
const int VAL_INIT = 4e8 + 5e7;
int n;

int main()
{
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> p;
		val[p] = VAL_INIT + i;
	}
	a[1] = 1, b[1] = val[1] - 1;

	for (int i = 2; i <= n; i++) {
		if (val[i] < val[i - 1]) {
			a[i] = a[i - 1] + 1;
			b[i] = b[i - 1] - (val[i - 1] - val[i]) - 1; /// diferenta
		}
		else {
			b[i] = b[i - 1] - 1;
			a[i] = a[i - 1] + (val[i] - val[i - 1]) + 1; /// diferenta
		}
	}

	for (int i = 1; i <= n; i++)
		cout << a[i] << " \n"[i == n];
	for (int i = 1; i <= n; i++)
		cout << b[i] << ' ';

	return 0;
}

Measured memory_bytes: 896
#include<iostream>
#include<sstream>
#include<fstream>
#include<vector>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<functional>
#include<climits>
#include<utility>
#include <iomanip>
#include<map>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;

#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
#define FORB(i,s,e,st) for (int i = int(s); i < int(e); i+=(int(st)))
#define FOR(i,s,e) FORB(i,s,e,1)
#define REP(i,x) FOR(i,0,x)
#define CLR(a) memset((a), 0 ,sizeof(a))


const int MOD = 1e+9+7;
const double PI  = acos(-1.0);


int main(){
  int n,in,ret=0;
  vi lst;
  cin>>n;
  REP(i,2*n){
    cin>>in;
    lst.push_back(in);
  }
  sort(lst.begin(),lst.end());
  REP(i,n){
    ret+=lst[i*2];
  }
    cout<<ret<<"\n";

}


Measured memory_bytes: 256
#include <stdio.h>

int n, A[50];

int solve(int i, int m){
  if ( m == 0 ){
    return 1;
  }
  if ( i >= n ){
    return 0;
  }
  int res = solve(i + 1, m) || solve(i + 1, m - A[i]);
  return res;
}

int main(){
  int q, m, i;

   scanf("%d", &n);
  for( i = 0; i < n; i++){
    scanf("%d", &A[i]);
  }
  scanf("%d", &q);
  for( i = 0; i < q; i++){
    scanf("%d", &m);
    if( solve(0,m) ){
      printf("yes\n");
    } else {
      printf("no\n");
    }
  }
  return 0;
}

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


#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }

using pll = pair<long long, long long>;
int N;
long long D, A;
vector<long long> X, H;

long long solve() {
    // モンスターを X が小さい順に
    vector<int> ids(N);
    for (int i = 0; i < N; ++i) ids[i] = i;
    sort(ids.begin(), ids.end(), [&](int i, int j) {
            return X[i] < X[j]; });
    vector<long long> nX(N), nH(N);
    for (int i = 0; i < N; ++i) nX[i] = X[ids[i]], nH[i] = H[ids[i]];
    X = nX, H = nH;

    // imos 法で処理していく
    vector<long long> S(N+1, 0);
    long long res = 0;
    for (int i = 0; i < N; ++i) {
        if (S[i] < H[i]) {
            // モンスター i を倒すのに必要な回数
            long long need = (H[i] - S[i] + A - 1) / A;
        
            // X[i] を左端とした爆発が届く範囲を求める
            long long right = X[i] + D * 2;
            int id = upper_bound(X.begin(), X.end(), right) - X.begin();
            
            // imos しながら爆発させる
            S[i] += need * A;
            S[id] -= need * A;
            res += need;
        }

        // imos の累積和をとる操作
        S[i+1] += S[i];
    }
    return res;
}

int main() {
    cin >> N >> D >> A;
    X.resize(N); H.resize(N);
    for (int i = 0; i < N; ++i) cin >> X[i] >> H[i];
    cout << solve() << endl;
}


Measured memory_bytes: 8832
import sys
input=sys.stdin.readline
n=int(input())
count=0
for i in range(2,10**6+1):
    num=1
    while num<=n:
        if n%num==0:
            if (n//num-1)%i==0:
                count+=1
        num=num*i
if n>10**6:
    count+=1
for i in range(1,10**6+1):
    if (n-1)%i==0:
        if (n-1)//i>10**6:
            count+=1
print(count)




Measured memory_bytes: 41068
#include <cstdio>
#include <cstdlib>
#include <cmath>

const int maxn = 1e4 + 20;

int n;
int a[maxn], b[maxn];

int main()
{
	scanf("%d", &n);
	for(int i = 1; i <= n; i++) scanf("%d", &a[i]);
	for(int i = 1; i <= n; i++) scanf("%d", &b[i]);
	
	long long sum = 0, cnt = 0;
	
	for(int i = 1; i <= n; i++) a[i] -= b[i];
	for(int i = 1; i <= n; i++)
	{
		if(a[i] >= 0) sum += a[i];
		else cnt += abs(a[i]) / 2;
	}
	
	printf("%s\n", sum <= cnt ? "Yes" : "No");
	return 0;
}

Measured memory_bytes: 256
let k, s = Scanf.scanf " %d %d" @@ fun a b -> a, b
let ans = ref 0
let _ =
  for x = 0 to k do
    for y = 0 to k do if 0 <= s - x - y && s - x - y <= k then incr ans done done;
  Printf.printf "%d\n" !ans

Measured memory_bytes: 384
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
      Scanner scanner = new Scanner(System.in);
      String s = scanner.nextLine();
      String t = scanner.nextLine();
      int counter = 0;
      int count = 0;
      for (int j = 0; j <= (s.length() - t.length()); j++) {
        for (int i = 0; i < t.length(); i++) {
          if (t.charAt(i) == s.charAt(j + i)) {
            counter = counter + 1;
          }
        }
        if (count == 0 || counter > count) {
          count = counter;
        }
        counter = 0;
      }
      System.out.println(t.length() - count);
    }
}


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

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

Measured memory_bytes: 3596
#include<bits/stdc++.h>
#include<map>
using namespace std;
typedef long long int lli;
typedef long long ll;
#define mod 10000000007
int main()
{
  ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   cout.tie(NULL);
   lli n,i,count=0;
   cin>>n;
   lli a[n];
   for(i=0;i<n;i++)
   cin>>a[i];
   for(i=0;i<n;i++)
   {
       if(a[i]%2!=0 && i%2==0)
         count++;
   }
   cout<<count<<"\n";
}

Measured memory_bytes: 3644
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <sstream>
#include <random>
#include <utility>
#include <map>
#include <vector>
#define REP(i,x) for(int i=0; i<(x); i++)

using namespace std;

int main(int argc, const char * argv[]) {
    int n;
    cin >> n;
    int a[n];
    REP(i, n){
        cin >> a[i];
    }
    int b = 1;
    sort(a, a+n);
    for(int i=1; i<n; i++){
        if(a[i] != a[i-1]){
            b++;
        }
    }
    cout << b << endl;
    
    return 0;
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

	static Scanner scanner;

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

        int N=gi();
        int k=0;
        for (int i=1; i<=9; i++) {
        	if (N<=100*i+10*i+i) {
        		k=100*i+10*i+i;
              break;
        	}
        }
	    System.out.println(k);
	    
//        if (a>0) {
//        	System.out.println("Yes");
//        }else {
//        	System.out.println("No");
//        }
	}


	public static long d(long n) {
		String a=String.valueOf(n);
		return (long)a.length();
	}

	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}

	// doubleとして入力を取得
	public static double gd() {
		return Double.parseDouble(scanner.next());
	}
}

Measured memory_bytes: 35700
def submit():
    n, m = map(int, input().split())
    edge = {i + 1: [] for i in range(n)}
    indig = {i + 1: 0 for i in range(n)}
    dp = [-1 for _ in range(n + 1)]

    # トポロジカル順序を求める
    for _ in range(m):
        x, y = map(int, input().split())
        edge[x].append(y)
        indig[y] += 1

    indig0 = []
    for node in range(1, n + 1):
        if indig[node] == 0:
            indig0.append(node)
            dp[node] = 0

    topo = []
    while indig0:
        p = indig0.pop()
        topo.append(p)
        for e in edge[p]:
            indig[e] -= 1
            if indig[e] == 0:
                indig0.append(e)

    # トポロジカル順序に従いdpする
    for node in topo:
        for e in edge[node]:
            dp[e] = max(dp[e], dp[node] + 1)
    
    print(max(dp))

if __name__ == "__main__":
    submit()
    

Measured memory_bytes: 81380
#include<cstdio>
#include<iostream>
#include<ctype.h>
#include<string>
#include<algorithm>
using namespace std;
int main(){
	int N, sum1 = 0, sum2 = 0, min;
	cin >> N;
	int a[N];
	for(int i = 0; i < N; i++){
		cin >> a[i];
	}
	for(int i = 0; i < N - 1; i++){
		for(int s = 0; s <= i; s++){
			sum1 += a[s];
		}
		for(int j = i + 1; j < N; j++){
			sum2 += a[j]; 
		}
		if(i == 0){
			min = abs(sum1 - sum2);
		}
		else if(abs(sum1 - sum2) < min){
			min = abs(sum1 - sum2);
		}
		sum1 = sum2 = 0;
	}
	cout << min << endl;
	return 0;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))
a = []
b = []
for i in range(N):
    a.append(A[i] + i)
    b.append(i - A[i])

from collections import Counter

Ac = Counter(a)
Bc = Counter(b)

ans = 0

for k in Ac.keys():
    ans += Ac[k]*Bc[k]

print(ans)


Measured memory_bytes: 63984
# -*- coding: utf-8 -*-
A,B,C,X,Y = map(int, input().split())

prices = []
for c in range(0,max([X,Y])*2+1,2):
    a = max([X - c//2, 0])
    b = max([Y - c//2, 0])
    prices.append(A*a+B*b+C*c)

print(min(prices))


Measured memory_bytes: 7064
S = input()
counter = 0
# while True:
#     tmp=S.count('BW')
#     if tmp == 0:
#         print(counter)
#         break
#     else:
#         counter+=tmp
#         S=S.replace('BW','WB')

# i=0
# while True:
#     tmp = S[i:].find('W')
#     print(S[i:])
#     if tmp == -1:
#         print(counter)
#         break
#     else:
#         counter += tmp
#         i+=1

sum=0
for i in range(len(S)):
    if S[i]=='W':
        sum+=i
        counter+=1

n=counter-1
minus=n*(n+1)/2
print(int(sum-minus))

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

int main()
{
    int k, s;
    cin >> k >> s;

    int answer = 0;
    for (int x = 0; x <= k; x++)
    {
        for (int y = 0; y <= k; y++)
        {
            int z = s - x - y;
            if ((z >= 0) & (z <= k))
            {
                answer++;
            }
        }
    }
    cout << answer << endl;
}

Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def main():
    n,k=MI()
    r,s,p=MI()
    t=input()
    ans=0
    for m in range(k):
        pc="a"
        for c in t[m::k]:
            if c==pc:
                pc="a"
                continue
            if c=="r":ans+=p
            if c=="s":ans+=r
            if c=="p":ans+=s
            pc=c
    print(ans)

main()

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


LL findGCD(LL a, LL b)
{
    if(a == 0) return b;
    findGCD(b % a, a);
}

LL findLCM(LL a, LL b)
{
    LL gcd = findGCD(a, b);
    return (a * b) / gcd;
}

int main() {
	LL a, b, c, d;
	cin >> a >> b >> c >> d;

	LL cnt = b / c;

	cnt -= ((a - 1) / c);

	cnt += (b / d);

	cnt -= ((a - 1) / d);

	LL lcm = findLCM(c, d);

	LL cntt = b / lcm;
	cntt -= ((a - 1) / lcm);

	cnt -= cntt;

	cout << b - a + 1 - cnt << "\n";

	return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
long long a[100004];
int main(){
long n;
cin>>n;
long long s=0,ans=0,d=0;
for(long i=1;i<=n;i++){cin>>a[i];
if(a[i]==0){
    ans=ans+s/2;s=0;
}
else s=s+a[i];

}
ans=ans+s/2;
cout<<ans<<endl;}




Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
main(){
  int a[3],k;
  for(int i=0;i<3;i++)cin>>a[i];
  sort(a,a+3);
  cin>>k;
  cout<<a[0]+a[1]+a[2]*pow(2,k)<<endl;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
	
	int a,b;
	int  s,k;
	
	while(cin>>a>>b){
	s=a+b;
		k=0;
	while(s!=0){
	s=s/10;
	k++;
	}
		cout<<k<<endl;
	}
	}

Measured memory_bytes: 1160
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <stdio.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;
 
const ll nmax = 1e9 + 7;
const ll Mod = 998244353;
const double PI = 2 * asin(1);

int N, M, Count[100005][2];
int main(){
  scanf("%d%d", &N, &M);

  for (int i = 0; i < M; i++){
    int P; char S[10];
    scanf("%d %s", &P, S);

    if (Count[P][0]) continue;
    
    if (S[0] == 'A') Count[P][0]++;
    else Count[P][1]++;
  }

  int AC = 0, WA = 0;
  for (int i = 0; i < 1e5 + 5; i++){
    if (Count[i][0] == 0) continue;
    AC += Count[i][0];
    WA += Count[i][1];
  }
  printf("%d %d\n", AC, WA);

  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>
#include <cmath>
#include <bitset>
#include <queue>

using namespace std;
#define rep(i, n) for(i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define sqr(x) (x)*(x)
typedef long long ll;

void solve() {
    int k, a, b;
    cin >> k >> a >> b;
    int num = k;
    int count = 1;
    while(k*count <= b) {
        if(a <= k*count && k*count <= b) {
            cout << "OK";
            return;
        }
        count++;
    }
    cout << "NG";
}

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

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

int main(){
    int n,h,count = 0;
    cin >> n >> h;
    vector<int> a(n),b(n);
    for(int i = 0;i < n;i ++){
        cin >> a.at(i) >> b.at(i);
    }
    
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    int j = n;
    while(h > 0){
        if(j > 0 && b.at(j-1) > a.at(n-1)){
            h -= b.at(j-1);
            count ++;
            j --;
        }else{
            break;
        }
    }

    while(h > 0){
        h -= a.at(n-1);
        count ++;
    }

    cout << count << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x ,n) for(int i = x; i < n; i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main(){
    map<string,int>mp;
    int n,m,ans=0;
    string s,t;
    
    cin >> n;
    rep(i,n){
        cin >> s;
        mp[s]++;
    }
    
    cin >> m;
    rep(i,m){
        cin >> t;
        mp[t]--;
    }
    
    for(auto i=mp.begin();i!=mp.end();i++)ans=max(ans,i->second);
    
    cout << ans;
    
	return 0;
}

Measured memory_bytes: 3628
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define db(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<'\n'
const int N = 1e6;

int main() {
    ios_base::sync_with_stdio(0);
    int a,b,n,p,T,cas=0;
    cin>>p>>n;
    int s=0;
    for(int i=0;i<n;++i) {
        cin>>a;
        s+=a;
    }
    if(s>p) cout<<-1<<endl;
    else cout<<p-s<<endl;
    return 0;
}

Measured memory_bytes: 3644
#include<bits/stdc++.h>
#define ll long long
#define sz 100002
int a,b,test,i,j;
using namespace std;
int main()
{
    string s;
    int mark[27],i,j;
    memset(mark,0,sizeof(mark));
    cin>>s;
    for(int i=0;i<s.size();i++)
    {
        mark[s[i]-'a']++;
    }
    for(int i=0;i<26;i++)
    {
        if(mark[i]%2!=0){cout<<"No"<<endl;return 0;}
    }
    cout<<"Yes"<<endl;



}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  string a,b;
  int n,c=0,ans=0,first=0;
  cin>>a;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>b;
    b+=b;
    for(int j=0;j<10;j++){
      if(a[0]==b[j]){
	for(int k=0;k<a.size();k++){
	  if(a[k]==b[j+k]) c++;
	}
	if(c==a.size()&&first==0){
	  ans++;
	  first++;
	}
	c=0;
      }
    }
    first=0;
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3196
from operator import mul
from functools import reduce
from fractions import gcd
import math
import bisect
import itertools
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
INF = float("inf")

MOD = 1000000007
class Combination(object):
    def __init__(self, N, MOD):
        self.fac = [0] * (N + 1)
        self.inv = [0] * (N + 1)
        self.finv = [0] * (N + 1)
        self.fac[0] = 1
        self.finv[0] = 1
        if N > 0:
            self.fac[1] = 1
            self.inv[1] = 1
            self.finv[1] = 1
 
        # 前計算
        for i in range(2, N + 1):
            self.fac[i] = self.fac[i - 1] * i % MOD
            self.inv[i] = self.inv[MOD % i] * (MOD - (MOD // i)) % MOD
            self.finv[i] = self.finv[i - 1] * self.inv[i] % MOD
 
    def com(self, N, k):
        return (self.fac[N] * self.finv[k] * self.finv[N - k]) % MOD


def main():
    N, M, K = map(int, input().split())

    ans = 0
    Com = Combination(N*M-2, MOD)
    a = Com.com(N*M-2, K-2)
    for dx in range(1, M):
        b = (M-dx) * N * N
        ans += a * b * dx
        ans %= MOD
    for dy in range(1, N):
        b = (N-dy) * M * M
        ans += a * b * dy
        ans %= MOD
    
    print(ans)


if __name__ == '__main__':
    main()

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

int main() {
    string s, t;
    cin >> s >> t;
    list<char> ls;
    for(auto ch : s) ls.push_back(ch);

    for(int i = 0; i < s.length(); i++) {
        bool ok = true;
        int cnt = 0;
        for(auto ch : ls) {
            if(ch != t[cnt++]) {
                ok = false;
                break;
            }
        }
        if(ok) {
            cout << "Yes";
            return 0;
        }
        char temp = ls.back();
        ls.pop_back();
        ls.push_front(temp);
    }

    cout << "No";
}

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

using namespace std;

int main() {
    int N, M, ans = 0, t;
    cin >> N >> M;

    for (int i = 1; i*i <= M; i++) {
        if (M % i == 0) {
            t = M / i;
            if (i <= M / N) {
                ans = max(ans, i);
            }
            if (t <= M / N) {
                ans = max(ans, t);
            }
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n,a[201];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<n;i++)
		scanf("%d",&a[i]);
	int sum=a[1]+a[n-1];
	for(int i=2;i<n;i++)
		sum+=min(a[i-1],a[i]);
	printf("%d\n",sum);
	return 0;
}

Measured memory_bytes: 256