akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using static System.Console;
using static System.Math;
using static MyIO;
using static MyUtil;

public class B
{
	public static void Main() => (new Solver()).Solve();
}

public class Solver
{
	public void Solve()
	{
		int N = GetInt();
		int M = GetInt();
		var A = GetInts(M);
	
		WriteLine(Max(-1, N - A.Sum()));
	}
}

public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt() => int.Parse(getArg());
	public static long GetLong() => long.Parse(getArg());
	public static double GetDouble() => double.Parse(getArg());
	public static decimal GetDecimal() => decimal.Parse(getArg());
	public static string GetString() => getArg();
	public static char GetChar() => getArg()[0];
	public static int[] GetInts(long N) => Enumerable.Range(0, (int)N).Select(_ => GetInt()).ToArray();
	public static long[] GetLongs(long N) => Enumerable.Range(0, (int)N).Select(_ => GetLong()).ToArray();
	public static double[] GetDoubles(long N) => Enumerable.Range(0, (int)N).Select(_ => GetDouble()).ToArray();
	public static decimal[] GetDecimals(long N) => Enumerable.Range(0, (int)N).Select(_ => GetDecimal()).ToArray();
	public static string[] GetStrings(long N) => Enumerable.Range(0, (int)N).Select(_ => GetString()).ToArray();
}

public static class MyUtil
{
	public static void chmax<T>(ref T x, T y) where T : IComparable<T>
	{
		if(x.CompareTo(y) < 0)
			x = y;
	}

	public static void chmin<T>(ref T x, T y) where T : IComparable<T>
	{
		if(x.CompareTo(y) > 0)
			x = y;
	}

	public static void swap<T>(ref T x, ref T y)
	{
		T tmp = x;
		x = y;
		y = tmp;
	}
}

Measured memory_bytes: 28984
#include<bits/stdc++.h>
using namespace std;
int main() {
    int n,k;
    cin>>n>>k;
    if(n<=1){
        cout<<"0"<<endl;
        return 0;
    }
    int arr[n];
    int dp[n];
    for(int i=0;i<n;i++){
        cin>>arr[i];
        dp[i]=INT_MAX;
    }
    if(n==2){
        cout<<arr[1]-arr[0]<<endl;
        return 0;
    }
    dp[0]=0;
    dp[1]=abs(arr[1]-arr[0]);
    for(int i=0;i<n;i++){
        for(int j=1;j<=k;j++){
            if(i+j<n){
                int temp=dp[i]+abs(arr[i+j]-arr[i]);
                if(dp[i+j]>temp)
                    dp[i+j]=temp;
            }
            else break;
        }
    }
    cout<<dp[n-1]<<endl;
}

Measured memory_bytes: 4364
import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    N,D=MI()
    D2=D**2
    ans=0
    for i in range(N):
        x,y=MI()
        d2=(x**2+y**2)
        if d2 <= D2:
            ans+=1
            
    print(ans)
        

main()


Measured memory_bytes: 73864
n,d = map(int, input().split())
Ans = 0
for i in range(n):
    xnyn = list(map(int, input().split()))
    r = (xnyn[0]**2 + xnyn[1]**2)**0.5
    if r <= d:
        Ans = Ans + 1
print(Ans)

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

const int N = 2020;

int n, z, w, a[N];

int main() {
	ios::sync_with_stdio(false), cin.tie(0);
	cin >> n >> z >> w;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	cout << max(abs(a[n - 1] - w), (n == 1? 0: abs(a[n - 1] - a[n - 2])));
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  string s;
  ll k;
  cin >> s >> k;
  int c = 0, v = 1;
  rep(i, 0, s.size()) {
    if (s[i] == '1')
      c++;
    else {
      v = s[i] - '0';
      break;
    }
  }

  if (k <= c)
    cout << 1 << endl;
  else
    cout << v << endl;
}


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

int cnt[2], color[1005];
int N, M;
vector<int> G[1005];
int flag;

void dfs(int x, int c){
  
  color[x] = c;
  cnt[c]++;

  for(auto nx : G[x] ){
    
    if( color[nx] != -1 ){
      if( c == color[nx] ) flag = 1;
      continue;
    }
    
    dfs( nx, !c );
    
  }
  
}

signed main(){

  while(1){
    
    cin>>N>>M;
    if( !N && !M ) break;
    
    for(int i=0;i<1005;i++) G[i].clear();
    
    for(int i=0;i<M;i++){
      int a, b;
      cin>>a>>b;
      G[a-1].push_back(b-1);
      G[b-1].push_back(a-1);
    }
    
    memset( cnt, 0, sizeof(cnt) );
    memset( color, -1, sizeof(color) );
    flag = 0;
    
    dfs( 0, 0 );
    
    if( flag ) cout<<0<<endl;
    else{
      
      set<int> ans;
      
      for(int i=0;i<2;i++){
	if( cnt[i] % 2 == 0 ) ans.insert( cnt[i] / 2 );
      }
      
      cout<<(int)ans.size()<<endl;
      
      for(auto num : ans ) cout<<num<<endl;
      
    }
    
  }
  
  return 0;
}



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

int main(){
  int n[3];
  int tmp=0;
  for(int i=0;i<3;i++){
    cin >> n[i];
  }
  for(int i=0;i<2;i++){
    if(n[i] >= n[i+1]){
      cout << "No" << endl;
      tmp++;
      break;
    }
  }
  if(tmp==0) cout << "Yes" << endl;
}

Measured memory_bytes: 1156
N = gets.to_i
red = []
blue = []
N.times do
  red.push(gets.split().map(&:to_i))
end
red.sort_by!{|k| -k[0]}
N.times do
  blue.push(gets.split().map(&:to_i))
end
blue.sort_by!{|k| k[1]}
cnt = 0
red.each do |x1, y1|
  blue.length.times do |i|
    x2, y2 = blue[i]
    if x1 < x2 && y1 < y2
      cnt += 1
      blue.delete_at(i)
      break
    end
  end
end

puts cnt

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

const int N = 202020;
const int M = 4040;
const int MOD = 1000000007;
const int s = 2020;
typedef long long ll;

inline char get(void) {
    static char buf[100000], *S = buf, *T = buf;
    if (S == T) {
        T = (S = buf) + fread(buf, 1, 100000, stdin);
        if (S == T) return EOF;
    }
    return *S++;
}
template<typename T>
inline void read(T &x) {
    static char c; x = 0; int sgn = 0;
    for (c = get(); c < '0' || c > '9'; c = get()) if (c == '-') sgn = 1;
    for (; c >= '0' && c <= '9'; c = get()) x = x * 10 + c - '0';
    if (sgn) x = -x;
}

int a[N], b[N];
int f[M][M];
int fac[N], inv[N];
int n, m, ans;

inline void Add(int &x, int a) {
	x += a; while (x >= MOD) x -= MOD;
}
inline int C(int n, int m) {
	return (ll)fac[n + m] * inv[n] % MOD * inv[m] % MOD;
}

int main(void) {
	read(n);
	for (int i = 1; i <= n; i++) {
		read(a[i]); read(b[i]);
		++f[s - a[i]][s - b[i]];
	}
	for (int i = 1; i < M; i++)
		for (int j = 1; j < M; j++) {
			Add(f[i][j], f[i - 1][j]);
			Add(f[i][j], f[i][j - 1]);
		}
	inv[1] = 1;
	for (int i = 2; i <= 10000; i++)
		inv[i] = (ll)(MOD - MOD / i) * inv[MOD % i] % MOD;
	fac[0] = inv[0] = 1;
	for (int i = 1; i <= 10000; i++) {
		fac[i] = (ll)i * fac[i - 1] % MOD;
		inv[i] = (ll)inv[i] * inv[i - 1] % MOD;
	}
	for (int i = 1; i <= n; i++) {
		Add(ans, f[s + a[i]][s + b[i]]);
		Add(ans, MOD - C(a[i] << 1, b[i] << 1));
	}
	ans = (ll)ans * (MOD + 1) / 2 % MOD;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 65792
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {

    int n,l;
    cin >> n >> l;

    int ans ;
    ans = n *(2 * l + n - 1) * 0.5;

    if(l > 0){
        ans -= l;
    }else if (l < 1-n){
        ans -= (l + n -1);
    }

    cout << ans << endl;
    


    return 0;
}

Measured memory_bytes: 888
#include<bits/stdc++.h>
 
#define rep(i,n) for(ll i = 0;i < n;++i)
#define all(v) v.begin(),v.end()
using namespace std;
using ll = long long;
typedef pair<int,int> P;
 
const int INF = 1001001001;
const long double PI = (acos(-1));
const int mod = 1e9+7;
const int vx[6] = {0,1,0,-1,1,-1};
const int vy[6] = {1,0,-1,0,1,1};




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

    ll l,r;
    cin >> l >> r;
    int MOD = 2019;
    ll ans = INF * 2;
    for(ll i = l;i <= r-1;++i){
        for(ll j = i+1;j <= r;++j){
            ans = min(ans,((i%MOD)*(j%MOD))%MOD);
            if(ans == 0) break;
        }
        if(ans == 0) break;
    }
    cout << ans << endl;
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
import sys

N = int(sys.stdin.readline())
A = list(map(int, sys.stdin.readline().split()))
B = list(map(int, sys.stdin.readline().split()))
# print(A)
# print(B)

# a <= b のところは一致させることができる
# a > b となっているところを a = b にするのに必要な+1の操作数を、
# a <= b となっているところが a <= b のままである「余裕な走査数」が上回っていれば良い
need_an = 0
need_bn = 0
for i in range(N):
    if A[i] > B[i]:
        need_bn += A[i] - B[i]
    elif A[i] < B[i]:
        need_an += (B[i] - A[i]) // 2

# print(need_an, need_bn)
if need_an >= need_bn:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 10484
N, T = map(int, input().split())
A = [int(i) for i in input().split()]

Amin = 10**10
P = -10**10
c = 0
for i in range(N):
    if A[i] < Amin:
        Amin = A[i]

    if A[i]-Amin == P:
        c += 1
    elif A[i]-Amin > P:
        P = A[i]-Amin
        c = 1
print(c)


Measured memory_bytes: 62832
#include <stdio.h>
#define N 2000

int A[N], n;

int solve(int i, int m){
  int res=0;
  
  if(m == 0) return 1;
  if(i >= n) return 0;

  res = solve(i+1, m) || solve(i+1, m-A[i]);
  return res;
}

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

  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
a,b = list(map(int,input().split(" ")))

if a==b:
    print("Draw")
    exit()
elif b==1:
    print("Bob")
    exit()
elif a==1:
    print("Alice")
    exit()
if a>b:
    print("Alice")
elif a<b :
    print("Bob")
else:
    print("Draw")

Measured memory_bytes: 3060
N, K = map(int, input().split())
v = list(map(int, input().split()))
ans = 0
for i in range(min(N, K) + 1):
    for j in range(i + 1):
        h = v[:j] + (v[-(i - j):] if i != j else [])
        k = K - i
        tmp = sum(h)
        for m in range(i):
            h.sort()
            if k > 0 and h[m] < 0:
                k -= 1
                tmp -= h[m]
        ans = max(ans, tmp)
print(ans)

Measured memory_bytes: 3064
import numpy as np

n,d = map(int,input().split())
dl =[0]*n
for i in range(n):
    dl[i] = list(map(int,input().split()))

cnt = 0
for i in range(len(dl)):
    for j in range(len(dl)):
        if i ==j:
            break
        if np.linalg.norm(np.array(dl[i])-np.array(dl[j])).is_integer():
            cnt +=1
            
print(cnt)
    

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

constexpr int inf = 1e9;
constexpr ll linf = 1e18;

template <typename T>
class SegTree
{
public:
    SegTree(const int n, const T &unity) : _unity(unity)
    {
        _n = 1 << __lg(2 * n - 1);
        _data.resize(2 * _n, unity);
    }

    SegTree(const vector<T> &v, const T &unity) : _unity(unity)
    {
        int n = v.size();
        _n = 1 << __lg(2 * n - 1);
        _data.resize(2 * _n, unity);

        // 最下段に要素をセット
        for (int i = 0; i < n; i++) _data[i + n] = v[i];
        // セグメント木を構築
        for (int i = n - 1; i > 0; i--) _data[i] = f(_data[2 * i], _data[2 * i + 1]);
    }

    // k番目の値をxに更新する
    void update(int k, const T &x)
    {
        k += _n; // 葉の節点に変換
        _data[k] = x;
        while (k >>= 1) _data[k] = f(_data[2 * k], _data[2 * k + 1]);
    }

    // 区間[a, b)に対してクエリ処理した結果を返す
    T query(int a, int b)
    {
        T left = _unity, right = _unity;
        a += _n, b += _n; // 葉の節点に変換
        for (; a < b; a >>= 1, b >>= 1) {
            if (a & 1) left  = f(left, _data[a++]);
            if (b & 1) right = f(_data[--b], right);
        }
        return f(left, right);
    }

    const T &operator[](size_t i) const { return _data[i + _n]; }
    T &operator[](size_t i) { return _data[i + _n]; }

private:
    int _n;          // 要素数
    vector<T> _data; // データを格納する配列
    T _unity;        // 単位元

    // クエリ処理用の関数
    T f(const T &a, const T &b) { return max(a, b); }
};


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

    int n; cin >> n;
    vector<int> h(n), a(n);
    for (int i = 0; i < n; i++) cin >> h[i];
    for (int i = 0; i < n; i++) cin >> a[i];

    SegTree<ll> seg(n + 1, 0);
    for (int i = 0; i < n; i++) {
        ll b = seg.query(0, h[i]);
        if (seg[h[i]] < b + a[i]) {
            seg.update(h[i], b + a[i]);
        }
    }
    ll ans = seg.query(0, n + 1);
    cout << ans << endl;
    return 0;
}

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

int main () {

  int N;
  int a[210];

  cin >> N;
  for (int i=0; i < N; ++i) // N個の整数を配列a[i]に入れる
    cin >> a[i];

  int res = 0; //何回割ったかを記録する

  while (true) {
    bool odds =false; //a[i]の偶数判定準備
    for (int i=0; i<N; ++i)  {
    if (a[i]%2 != 0) odds = true; // 配列内に奇数があるか判定
    } 

    if (odds) break; //奇数があった場合終了

    for (int i=0; i<N; ++i) {
    a[i] /= 2; //奇数がない場合再度割る前に配列を割る
    }

    ++res; //配列を割った回数の記録

  }

  cout << res << endl;


  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <climits>
#include <numeric>
#include <cmath>
#include <queue>
#include <sstream>
#include <string.h>

using namespace std;
typedef long long ll;

int main() {
  ll c[3][3], x[3], y[3];
  
  for(int i = 0; i < 3; i++){
    for(int j = 0; j < 3; j++){
      cin >> c[i][j];
    }
  }
 
  x[0] = 0;
  for(int i = 0; i < 3; i++) {
    y[i] = c[0][i] - x[0];
  }
  for(int i = 0; i < 3; i++) {
    x[i] = c[i][0] - y[0];
  }

  bool good = true;
  for(int i = 0; i < 3; i++){
    for(int j = 0; j < 3; j++){
      if ((x[i] + y[j]) != c[i][j]) {
        good = false;
      }
    }
  }
  if (good) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


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

// #define multitest 1
// #define Debug 1
#ifdef Debug
#define db(...) ZZ(#__VA_ARGS__, __VA_ARGS__);
template <typename Arg1>
void ZZ(const char *name, Arg1 &&arg1)
{
	std::cerr << name << " = " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void ZZ(const char *names, Arg1 &&arg1, Args &&... args)
{
	const char *comma = strchr(names + 1, ',');
	std::cerr.write(names, comma - names) << " = " << arg1;
	ZZ(comma, args...);
}
#else
#define db(...)
#endif

typedef long long ll;
typedef long double ld;
#define f first
#define s second
#define pb push_back
const long long mod = 1000000007;

ll power(int base, int index)
{
	if (index == 0)
		return 1;
	ll temp = power(base, index / 2);
	temp = (temp * temp) % mod;
	if (index & 1)
		temp = (temp * base) % mod;
	return temp;
}

int n, a, b, c;

int _n = 2000 + 10;
vector<ll> Fact(_n), Inv(_n);
int kmod = 1000000007;

void pre()
{
	Fact[0] = 1;
	for (int i = 1; i < _n; ++i)
		Fact[i] = (Fact[i - 1] * i) % kmod;
	Inv[_n - 1] = power(Fact[_n - 1], kmod - 2);
	for (int i = _n - 2; i >= 0; --i)
		Inv[i] = (Inv[i + 1] * (1 + i)) % kmod;
	// db(Inv[2]*2%mod);
}

ll ncr(int n, int r)
{
	db(n, r);
	if (n < 0 || r < 0 || (n - r < 0))
		return 0;
	return ((Fact[n] * Inv[r]) % mod * Inv[n - r]) % mod;
}

void solve()
{
	pre();
	int n, k;
	cin >> n >> k;
	for (int i = 1; i <= k; ++i)
	{
		ll one = ncr(n - k + 1, i);
		ll two = ncr(k - 1, i - 1);
		db(one, two);
		cout << (one * two) % mod << '\n';
	}
}

int main()
{
#ifndef Debug
	ios_base::sync_with_stdio(0);
	cin.tie(0);
#endif
	int t = 1;
#ifdef multitest
	cin >> t;
#endif
	while (t--)
		solve();
	return 0;
}

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

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

#define pb push_back
#define rep(i, n) for(int i = 0; i < (n); i++)
#define dep(i, a, n) for(int i = a; i >= (n); i--)
#define FOR(i, a, n) for(int i = a; i < (n); i++)
#define mod (ll)(1e9+7)
#define int ll
#define INF 100000000

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

signed main() {
	ll n, a, b, c;
  cin >> n;
  set<vector<int> > ch;
  rep(i, n) {
    vector<int> tmp;
    cin >> a >> b >> c;
    tmp.pb(a);
    tmp.pb(b);
    tmp.pb(c);
    sort(tmp.begin(), tmp.end());
    ch.insert(tmp);
  }
  cout << n - ch.size() << endl;
	return 0;
}


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

long long int dp[101][3];

int main() {

    int n,k;

    cin >> n >> k;

    int day,s;

    bool a[101] = {false};
    int b[101] = {0};

    for(int i=0;i<k;i++){
        cin >> day >> s;
        a[day] = true;
        b[day] = s-1;
    }

    dp[0][0] = 0;
    dp[0][1] = 0;
    dp[0][2] = 0;

    for(int k=0;k<3;k++){
        if(a[1] && b[1]!=k){
            dp[1][k] = 0;
        }
        else{
            dp[1][k] = 1;
        }
    }

    for(int i=2;i<=n;i++){

        for(int j=0;j<3;j++){
            if(a[i] && (b[i]!=j)){
                dp[i][j] = 0;
            }
            else {

                int sum = 0;
                for (int k = 0; k < 3; k++) {
                    /*if(i>2 && dp[i-1][k] != 0 && dp[i-2][k] != 0 && k!=j){
                        dp[i][j] += dp[i-1][k] - dp[i-2][k];
                    }
                    else {
                        dp[i][j] += dp[i-1][k];
                    }*/
                    sum += dp[i-1][k];
                }

                if(i>2) {

                    long long int sub = 0;

                    if(dp[i-1][j] != 0) {

                        sub = dp[i - 1][j] + 20000;
                        for (int k = 0; k < 3; k++) {
                            if (k != j) {
                                sub -= dp[i - 2][k];
                            }
                        }
                        sub %= 10000;
                        dp[i][j] = -sub;
                    }
                }

                dp[i][j] += sum + 10000;
            }

            dp[i][j] %= 10000;
            /*if(i>3 && dp[i-1][j] != 0 && dp[i-2][j] != 0){
                dp[i][j] = 0;
            }*/
        }

    }
/*
    ofstream ofs("output.txt");

    for(int i=0;i<=n;i++){

        for(int j=0;j<3;j++){

            ofs << dp[i][j] << " ";
        }

        ofs << endl;

    }
*/
    cout << (dp[n][0] + dp[n][1] + dp[n][2]) % 10000 << endl;

    return 0;
}

Measured memory_bytes: 3096
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repp(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define repm(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define INF (1ll<<60)
typedef long long lint;
const lint MOD =1000000007;
const lint MAX = 10000000;

 
lint fac[MAX], finv[MAX], inv[MAX];

void COMinit() // 二項係数を求める時は前処理としてCOMinit()をする
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (lint 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;
    }
}
 
// 二項係数計算
long long COM(lint n, lint k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

lint primary(lint num)
{
    if (num < 2) return 0;
    else if (num == 2) return 1;
    else if (num % 2 == 0) return 0; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return 0;
        }
    }

    // 素数である
    return 1;
}

   

int main(){
lint x,c;
cin>>x>>c;
cout<<(x)/__gcd(x,c)*c;

}

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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define LCM(a, b) (a) / __gcd((a), (b)) * (b)
#define CEIL(a, b) (a)/(b)+(((a)%(b))?1:0)
#define ln '\n'

using namespace std;
using LL = long long;
using ldouble = long double;
using P = pair<int, int>;
using LP = pair<LL, LL>;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1e9 + 7;
static const int SIZE = 200005;

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

vector<LL> Div(LL n) {
    vector<LL> ret;
    for(LL i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.pb(i);
            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}

/* 
 * s と sのi文字目以降 の最長共通接頭辞を求める
 * O(|s|)
 * */
int Z_algorithm(string s) {
    int len = s.size();
    vector<int>a(len);
    a[0] = len;
    int i = 1, j = 0;

    while(i < len) {
        while(i + j < len && s[j] == s[i + j]) {
            ++j;

        }
        a[i] = j;
        if(j == 0) {
            ++i;
            continue;

        }

        int k = 1;
        while(i + k < len && k + a[k] < j) {
            a[i + k] = a[k];
            ++k;

        }
        i += k;
        j -= k;

    }

    int mx = 0;
    for(int i = 0; i < s.size(); ++i) {
        mx = max(mx, min(i, a[i]));

    }

    return mx;
}

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

    int n;
    cin >> n;
    string s;
    cin >> s;

    int res = 0;
    for(int i = 0; i < s.size(); ++i) {
        res = max(res, Z_algorithm(s.substr(i)));

    }
    cout << res << endl;
    return 0;
}



Measured memory_bytes: 256
a, b, c, d = input().split()

a=int(a)
b=int(b)
c=int(c)
d=int(d)

X1 = min(a,b) * min(c,d)
X2 = min(a,b) * max(c,d)
X3 = max(a,b) * min(c,d)
X4 = max(a,b) * max(c,d)

print(max(X1,X2,X3,X4))


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

#define PI 3.1415926535897932
#define MOD 1000000007
#define INF 1e9

#define REP(i, n) for(int i = 0; i < (n); i++)
#define REP1(i, n) for(int i = 1; i <= (n); i++)
#define FOR(i, start, end) for(int i = (start); i < (end); i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<bool> vb;


void solve()
{
    int K; cin >> K;
    cout << K / 2 * (K - K / 2) << endl;
}

int main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    solve();

    return 0;
}

Measured memory_bytes: 256
import sys

readline = sys.stdin.readline
n, k = map(int, readline().split())
A = list(map(int, readline().split()))

visited = [False] * n
visited[0] = True
l = [1]
while True:
    x = A[l[-1]-1]
    if visited[x-1]:
        break
    l.append(x)
    visited[x-1] = True
# print(l[l.index(x):])
if len(l) > k:
    print(l[k])
else:
    print(l[l.index(x):][(k-l.index(x)) % len(l[l.index(x):])])


Measured memory_bytes: 31284
#include<stdio.h>
int main(void) {
	int n,b1,b2;
	int i,j,k;
	scanf("%d",&n);

	for (i = 0; i < n; i++) {
		scanf("%d %d",&b1,&b2);
		k = 1;
		if (b1 < b2) {
			for (j = b1; j <= b2; j++) {
				if (j != b2)
					printf("%d ", j);
				else
					printf("%d\n",j);
			}
		}
		else if (b1 > b2 && b1 > 5) {
			for (j = b1; ;) {
				if (j == 9) {
					printf("%d ", j);
					j = 5;
					k *= -1;
				}if (j == 0) {
					k *= -1;
				}
				if (j != b2)
					printf("%d ", j);
				else
					printf("%d\n",j);
				if (j == b2)break;
				j += k;
			}
		}
		else {
			for (j = b1; j >= b2; j--) {
				if (j != b2)
					printf("%d ", j);
				else
					printf("%d\n", j);
			}
		}
	}
	return 0;
}

Measured memory_bytes: 600
def check_rate(r):
  for i,rate in enumerate(rates):
    if r < rate:
      return i

n=int(input())
a=list(map(int,input().split()))
rates=[400,800,1200,1600,2000,2400,2800,3200,float("inf")]
rates_cb=[False for _ in range(len(rates))]
wild=len(rates)-1
wild_c=0
for aa in a:
  r=check_rate(aa)
  if r == wild:
    wild_c+=1
  else:
    rates_cb[r]=True

base_col=rates_cb.count(True)
minc= max(1,base_col)
maxc=base_col+wild_c
print(minc,maxc)

Measured memory_bytes: 8972
N,L = map(int,input().split())

#N = int(input())

#list(map(int,input().split()))

l = list(range(L,L+N))
ans = sum(l)
if l[-1] < 0:
    ans -= l[-1]
elif l[0] > 0:
    ans -= l[0]
print(ans)

Measured memory_bytes: 38384
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <set>
#include <deque>
#include <bitset>

long long mod = 1e9+7;
class Mint {
public:
  long long x;
  Mint(){}; // 引数なしでも定義できるように引数なしコンストラクタも用意しておく
  Mint(long long a){
    x = a%mod;
    while(x<0){
      x += mod;
    }
  };
  Mint& operator += (const Mint &a){
    x+=a.x;
    x%=mod;
    return *this;
  }
  Mint& operator -= (const Mint &a){
    x += (mod - a.x);
    x%=mod;
    return *this;
  }
  Mint& operator *= (const Mint &a){
    x*=a.x;
    x%=mod;
    return *this;
  }

  // a^n mod を計算する
  // Useaeg: Mint z = Mint(2).pow(n);
  Mint pow(long long n) const {
    if (n==0) return Mint(1);
    Mint y = pow(n>>1); // pow(n/2)を計算する
    y *= y;
    if (n%2==1) y *= *this;
    return y;
  }

  // a^{-1} mod を計算する
  Mint modinv(const Mint &a) const {
    return a.pow(mod-2);
  }

  Mint& operator /= (const Mint &a) {
    x *= modinv(a).x;
    x %= mod;
    return *this;
  }

  Mint operator + (Mint &a) const {
    Mint y(*this);
    y += a;
    return y;
  }

  Mint operator - (Mint &a) const {
    Mint y(*this);
    y -= a;
    return y;
  }

  Mint operator * (Mint &a) const {
    Mint y(*this);
    y *= a;
    return y;
  }

  Mint operator / (Mint &a) const {
    Mint y(*this);
    y/=a;
    return y.x;
  }

  // nCk @mod を計算する
  Mint nCk(Mint &n, const long long k) const {
    Mint y = Mint(1);
    Mint one = Mint(1);
    for (Mint i(0); (i.x)<k; i.x++){
      y *= (n-i);
      y /= (i + one);
    }
    return y;
  }

  // nPk @mod を計算する
  Mint nPk(Mint &n, long long k) const {
    Mint y(1);
    for (Mint i(0); (i.x)<k; i.x++){
      y *= (n-i);
    }
    return y;
  }
};


int main() {
  int N, K;
  std::cin >> N >> K;
  std::vector<int > A(N);
  for (int i=0; i<N; i++) {
    std::cin >> A[i];
  }
  std::vector<int > S(N+4);
  S[0] = 0;
  for (int i=0; i<N; i++) {
    S[i+1] = (S[i] + A[i]) % K;
  }
  for (int i=0; i<=N; i++) {
    S[i] -= i%K;
    while (S[i]<0) S[i]+=K;
  }
  std::map<int, long long> mp;
  long long ans = 0;
  for (int i=0; i<=N; i++) {
    if (i>=K) mp[S[i-K]]--; 
    ans += mp[S[i]];
    //printf("ans+=mp[%d]=%lld\n", S[i], mp[S[i]]);
    mp[S[i]]++;
  }
  std::cout << ans << std::endl;
  return 0;
}

Measured memory_bytes: 16760
import sys
import os


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    a, b = list(map(str, sys.stdin.readline().split()))
    c = int(a + b)
    print('Yes' if int(c**0.5)**2 == c else 'No')



if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include <stdio.h>
#include <iostream>
#include<vector>
#include <string>
int main(void)
{
    int n;
    long long  ini[5] = {0,0,0,0,0};
    long long conb = 0;
    scanf("%d",&n);
    (void)getchar();
    std::string a;
    for(int i=0; i < n; i++){
        std::getline(std::cin,a);
        if(a[0] == 'M')ini[0]++;
        if(a[0] == 'A')ini[1]++;
        if(a[0] == 'R')ini[2]++;
        if(a[0] == 'C')ini[3]++;
        if(a[0] == 'H')ini[4]++;
    }
    
    int i,j,k;
   for(i=0;i<3;i++){
      for(j=i+1;j<4;j++){
         for(k=j+1;k<5;k++){
            conb += ini[i] * ini[j] * ini[k];
         }
      }
   }
   printf("%lld\n",conb);
    return 0;
}

Measured memory_bytes: 256
<?php
list($s) = strs();
list($t) = strs();
$min = PHP_INT_MAX;
for ($i = 0; $i < strlen($s) - strlen($t) + 1; ++$i) {
    $cnt = 0;
    for ($j = 0; $j < strlen($t); ++$j) {
        if ($s[$i + $j] !== $t[$j]) ++$cnt;
    }
    $min = min($min, $cnt);
}
echo $min;
function strs()
{
    return explode(' ', trim(fgets(STDIN)));
}


Measured memory_bytes: 16216
import java.io.*;
import java.util.*;
import java.util.Map.Entry;
import java.util.function.Function;
import java.util.stream.Collectors;

@SuppressWarnings("unused")
public class Main {
	String fileName = "input.txt";
	final boolean isDebug = false;
	//final boolean isDebug = true;
	FastScanner in = new FastScanner(System.in);
	PrintWriter out = new PrintWriter(System.out);
	final int MOD = (int)1e9+7;
	final long INF = Long.MAX_VALUE / 2;
	//final int INF = Integer.MAX_VALUE / 2;
	
	//System.out.println();はつかわない！！
	void solve() throws Exception{
		double W = in.nextDouble(), H = in.nextDouble();
		int x = in.nextInt(), y = in.nextInt();
		out.println((W * H / 2) + " " + ((x * 2 == W && y * 2 == H) ? "1" : "0"));
	}
	
	/* end solve */
	
	/* main */
	public static void main(String[] args) throws Exception {
		new Main().m();
	}
	
	void m() throws Exception {
		if(isDebug) in = new FastScanner(new FileInputStream(fileName));
		solve();
		out.flush();
	}
	/* end main */
}
/* end Main */

class FastScanner {
	Reader input;

	FastScanner() {this(System.in);}
	FastScanner(InputStream stream) {this.input = new BufferedReader(new InputStreamReader(stream));}
	
	int nextInt() {return (int) nextLong();}

	long nextLong() {
		try {
			int sign = 1;
			int b = input.read();
			while ((b < '0' || '9' < b) && b != '-' && b != '+') {
				b = input.read();
			}
			if (b == '-') {
				sign = -1;
				b = input.read();
			} else if (b == '+') {
				b = input.read();
			}
			long ret = b - '0';
			while (true) {
				b = input.read();
				if (b < '0' || '9' < b) return ret * sign;
				ret *= 10;
				ret += b - '0';
			}
		} catch (IOException e) {
			e.printStackTrace();
			return -1;
		}
	}

	double nextDouble() {
		try {
			double sign = 1;
			int b = input.read();
			while ((b < '0' || '9' < b) && b != '-' && b != '+') {
				b = input.read();
			}
			if (b == '-') {
				sign = -1;
				b = input.read();
			} else if (b == '+') {
				b = input.read();
			}
			double ret = b - '0';
			while (true) {
				b = input.read();
				if (b < '0' || '9' < b) break;
				ret *= 10;
				ret += b - '0';
			}
			if (b != '.') return sign * ret;
			double div = 1;
			b = input.read();
			while ('0' <= b && b <= '9') {
				ret *= 10;
				ret += b - '0';
				div *= 10;
				b = input.read();
			}
			return sign * ret / div;
		} catch (IOException e) {
			e.printStackTrace();
			return Double.NaN;
		}
	}

	char nextChar() {
		try {
			int b = input.read();
			while (Character.isWhitespace(b)) {
				b = input.read();
			}
			return (char) b;
		} catch (IOException e) {
			e.printStackTrace();
			return 0;
		}
	}

	String nextStr() {
		try {
			StringBuilder sb = new StringBuilder();
			int b = input.read();
			while (Character.isWhitespace(b)) {
				b = input.read();
			}
			while (b != -1 && !Character.isWhitespace(b)) {
				sb.append((char) b);
				b = input.read();
			}
			return sb.toString();
		} catch (IOException e) {
			e.printStackTrace();
			return "";
		}
	}
}

Measured memory_bytes: 20436
int main(){
  int a,b;scanf("%d%d",&a,&b);
  double ret=0;
  for(int i=1;i<=a;i++){
    double tmp=1.0/a;
    int now=i;
    while(now<b){
now*=2;
tmp/=2; }
ret+=tmp; }
  printf("%.12f\n",ret);
}

Measured memory_bytes: 128
def main():
    N, W = map(int, input().split())
    dp = {0: 0}
    for i in range(N):
        w, v = map(int, input().split())
        nxt = {}
        for k in dp:
            if k+w <= W:
                nxt[k+w] = max(dp[k] + v, dp[k+w] if k+w in dp else 0)
        dp.update(nxt)
    ans = 0
    for k in dp:
        ans = max(ans, dp[k])
    print(ans)


if __name__ == "__main__":
    main()


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

using namespace std;

#define INF 210000000
#define int long long

int gcd(int a, int b) {
  int amari = a % b;
  int c = b;
  if (amari == 0) {
    return b;
  } else {
    return gcd(b, amari);
  }
}

int lcm(int a, int b) { return a * b / gcd(a, b); }

signed main() {
		int n;
		cin >> n;
		cout << "Christmas";
		for(int i=0;i < 25 - n;i++){
				cout << " Eve";
		}
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const int inf = 1e9;
const ll INF = 1e18;
const double pi = 3.14159265358979323846;
#define rep(i,n) for(int i=0;i<n;i++)
using Graph = vector<vector<int>>;
using pint = pair<int,int>;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};

int main(){
    int n;cin>>n;
    ll a[n],b[n],c[n];
    ll ans=0;
    rep(i,n){
        cin>>a[i]>>b[i];
        c[i]=a[i]+b[i];
        ans-=b[i];
    }
    sort(c,c+n,greater<ll>());
    //int k=n/2;
    //if(n%2==1) k++;
    rep(i,n){
        if(i%2==0) ans+=c[i];
    }
    cout<<ans<<"\n";
}


Measured memory_bytes: 2560
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i > (b); i--)
#define ALL(a) (a).begin(), (a).end()

string S;

bool can_jump(int l, int r) {
    bool rock = false;
    FOR(i, l + 1, r) {
        if (S[i] == '#') {
            if (rock) return false;
            rock = true;
        } else {
            rock = false;
        }
    }
    return true;
}

bool can_advanced_jump(int l, int r) {
    FOR(i, l, r - 1) {
        if (S[i] == '.' && S[i + 1] == '.' && S[i + 2] == '.') return true;
    }
    return false;
}

int main() {
    int N, A, B, C, D;
    cin >> N >> A >> B >> C >> D >> S;

    if (A < B && D < C) {
        if (can_jump(A - 1, C - 1) && can_jump(B - 1, D - 1) && can_advanced_jump(B - 2, D)) cout << "Yes" << endl;
        else cout << "No" << endl;
    } else if (B < A && C < D) {
        if (can_jump(A - 1, C - 1) && can_jump(B - 1, D - 1) && can_advanced_jump(A - 2, C)) cout << "Yes" << endl;
        else cout << "No" << endl;
    } else {
        if (can_jump(A - 1, C - 1) && can_jump(B - 1, D - 1)) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
    return 0;
}

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

long long N, K, dp[2009][2009], mod = 1000000007;

int main() {
	cin >> N >> K;
	dp[0][N + 1] = 1;
	for (int i = 1; i <= K; i++) {
		for (int j = 1; j <= N; j++) {
			int E = N - i + 1;
			if (j > E) continue;
			if (j != 1) dp[i][j] += dp[i - 1][j];
			for (int k = j + 1; k <= N + 1; k++) dp[i][j] += dp[i - 1][k];
			dp[i][j] %= mod;
		}
	}
	long long G = dp[K][1];
	for (int i = 0; i < N - K - 1; i++) { G *= 2; G %= mod; }
	cout << G << endl;
	return 0;
}

Measured memory_bytes: 31104
#include <iostream>
#include <string>
#include <algorithm>

int main() {
    int k;
    std::string s;
    std::cin >> k;
    std::cin >> s;
    int x = 0, m = x;
    for (int i = 0; i < k; i++) {
        x += s[i] == 'I' ? 1 : -1;
        m = std::max(m, x);
    }
    std::cout << m << std::endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=1e5+5;
const int mod=1e9+7;
int n,m,ans,size[N];
vector<int>g[N];
void dfs(int u,int fa)
{
	int sum=0;
	if(fa==0)sum=m;
	else if(fa==1)sum=m-1;
	else sum=m-2;
	sum=sum-size[fa];
	if(sum<=0){puts("0");exit(0);};
	ans=ans*sum%mod;
	for(int i=0;i<g[u].size();i++)
	{
		int v=g[u][i];
		if(v==fa)continue;
		dfs(v,u);
		size[u]++;
	}	
}
signed main()
{
	ans=1;
	cin>>n>>m;
	for(int i=1;i<n;i++)
	{
		int x,y;
		scanf("%lld%lld",&x,&y);
		g[x].push_back(y);
		g[y].push_back(x);
	}
	dfs(1,0);
	cout<<ans;
}

Measured memory_bytes: 9984
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<n; ++i)
#define rep1(i, n) for (int i=1; i<=n; ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
constexpr ll  MOD = (1e9+7);
constexpr int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
constexpr int lcm(int a, int b) { return a / gcd(a, b) * 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;
}
ll factorial(ll n, ll m=2) {
    // calculate n!
    m = max(2LL, m);
    ll rtn = 1;
    for (ll i=m; i<=n; i++) {
        rtn = (rtn * i) % MOD;
    }
    return rtn;
}
ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
ll modpow(ll a, ll n) {
    ll res = 1;
    while (n > 0) {
        if (n & 1)
            res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<vector<int>> F(n);
    vector<vector<ll>> P(n);
    rep(i, n) {
        vector<int> tmp(10);
        rep(j, 10) cin >> tmp[j];
        F[i] = tmp;
    }
    rep(i, n) {
        vector<ll> tmp(11);
        rep(j, 11) cin >> tmp[j];
        P[i] = tmp;
    }
    int res = -(1<<30);
    for (int bit=1; bit<(1<<10); ++bit) {
        int tmp=0;
        rep(i, n) {
            int cnt=0;
            rep(j, 10) if ((bit>>j&1)&&F[i][j]) cnt++;
            tmp += P[i][cnt];
        }
        chmax(res, tmp);
    }
    cout << res << endl;
    return 0;
}

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

long long dp[1001][1001] = {0};

int main() {

    string t,b;

    cin >> t >> b;

    int s1 = t.size(),s2 = b.size();

    dp[0][0] = 1;

    for(int i=0;i<s1;i++){
        dp[i+1][s2] = dp[i][s2];
        dp[i+1][s2] %= 1000000007;
        for(int j=0;j<s2;j++){
            if(t[i] == b[j]){
                dp[i+1][j+1] += dp[i][j];
                dp[i+1][j+1] %= 1000000007;
            }
            dp[i+1][j] += dp[i][j];
        }
        /*for(int y=0;y<=s2;y++){
            for(int x=0;x<=s1;x++){
                cout << dp[x][y] << " ";
            }
            cout << endl;
        }
        cout << endl;*/
    }
/*
    for(int j=0;j<s2;j++){
        for(int i=0;i<s1;i++){
            if(b[j] == t[i]) {
                dp[i + 1][j + 1] = dp[i][j];
            }
            dp[i+1][j] = dp[i][j];

        }
    }
*/
/*
    for(int y=0;y<=s2;y++){
        for(int x=0;x<=s1;x++){
            cout << dp[x][y] << " ";
        }
        cout << endl;
    }
*/




    /*for(int i=0;i<=s1;i++){
        for(int j=0;j<=s2;j++){
            cout << dp[i][j] << " ";
        }
        cout << endl;
    }*/

    cout << dp[s1][s2] << endl;
    return 0;
}

Measured memory_bytes: 10968
# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

N, K = MAP()
R, S, P = MAP()
T = list(input())

T2 = [[] for i in range(K)]
for i, t in enumerate(T):
    T2[i%K].append(t)

ans = 0
for k in range(K):
    dp = list2d(len(T2[k])+1, 3, 0)
    for i, t in enumerate(T2[k]):
        for j in range(3):
            for l in range(3):
                if i != 0 and j == l:
                    continue
                nxt = 0
                if t == 'r' and l == 2:
                    nxt = P
                elif t == 's' and l == 0:
                    nxt = R
                elif t == 'p' and l == 1:
                    nxt = S
                dp[i+1][l] = max(dp[i+1][l], dp[i][j] + nxt)
    ans += max(dp[len(T2[k])])
print(ans)


Measured memory_bytes: 67064
N,A,B,C=map(int,input().split())
l_list=[int(input())for _ in range(N)]

def dfs(now,a,b,c):
  if now==N:
    return abs(a-A)+abs(b-B)+abs(c-C)-30 if min(a,b,c)>0 else float ("inf")
  res0 =dfs(now+1,a,b,c)
  res1=dfs(now+1,a+l_list[now],b,c)+10
  res2=dfs(now+1,a,b+l_list[now],c)+10
  res3=dfs(now+1,a,b,c+l_list[now])+10
  return min(res0,res1,res2,res3)

print(dfs(0,0,0,0))



Measured memory_bytes: 3188
#include <cstdio>
#include <iostream>
#include <vector>

using namespace std;

const int INF = 1e9;
const int MOD = 1000000007;

int main() {
  size_t S, W;
  cin >> S >> W;
  if (S <= W) {
    cout << "unsafe" << endl;
  } else {
    cout << "safe" << endl;
  }
  return 0;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
int main(){
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);cout.precision(30);
    char a;
    int b;
    cin>>a;
    b=(int)a+1;
    cout<<(char)b;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

@SuppressWarnings("unchecked")
public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int k = in.nextInt();
		int ans = pow(k-1, n-1);
		System.out.println(ans*k);
	}

	static int pow(int x, int y) {
		if (x == 0) return 0;
		if (y == 0) return 1;

		int res = pow(x, y/2);
		if (y % 2 == 1) return x*res*res;
		return res*res;
	}
}

Measured memory_bytes: 35648
#include<cstdio>
#include <iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<queue>
#include<vector>
#include<functional>
#include<cmath>
#include<map>
#include<stack>
#include<cstdlib>
#include<list>
#include<set>
#include<numeric>

#define MOD 1000000007

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


int main()
{
	int N; cin >> N;
	string s, t;

	cin >> s >> t;
	int ans = 0,mx = 0;

	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			if (t[i] == s[j]) {
				int a;
				for (a = 0; a < N-j; a++) {
					if (t[i + a] != s[j + a])break;
				}
				ans = max(ans, a);
			}
		}
	}
	cout << N+N -ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a[1100];
int ans=0x3f3f3f3f;
int main()
{
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	for(int i=0;i<=100;i++)
	{
		int sum=0;
		for(int j=1;j<=n;j++)
			sum=sum+(a[j]-i)*(a[j]-i);
		ans=min(ans,sum);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
#define ENDL "\n"

int N, h, hh;
int ans = 0;

void f(){
  if(h>hh){
    ans += h-hh;
  }
  h=hh;
}

  
int main(){
  cin >> N;
  h = 0;
  for(int i=0;i<N;i++){
    cin >> hh;
    f();
  }
  hh=0;
  f();
  cout << ans << ENDL;
  //
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0;i<n;++i)
#define rep1(i,n) for(ll i=1;i<=n;++i)
#define eachdo(e,array) for(const auto& e : array)
#define upper_index(v,a) (ll)distance(v.begin(), upper_bound((v).begin(),(v).end(),a))
#define lower_index(v,a) (ll)distance(v.begin(), lower_bound((v).begin(),(v).end(),a))
#define eachdo(e,array) for(const auto& e : array)
template<class T> bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chman(T &a, T b){if(a<b){a=b;return true;}return false;}
const ll INF=1LL<<63-1;
const ll MOD=1e9+7;

struct SegmentTree{
private:
    ll unit=0;
    ll op(ll a,ll b){return a+b;}
    ll n;
    vector<ll> node;

public:
    SegmentTree(vector<ll> v){
        ll sz=(ll)v.size();
        n=1;while(n<sz) n*=2;
        node.resize(2*n-1,unit);
        for(ll i=0;i<sz;i++) node[i+n-1]=v[i];
        for(ll i=n-2;i>=0;i--) node[i]=op(node[2*i+1],node[2*i+2]);
    }

    void update(ll x,ll val){
        x+=n-1;
        node[x]+=val;
        while(x>0){
            x=(x-1)/2;
            node[x]=op(node[2*x+1],node[2*x+2]);
        }
    }

    ll query(ll a,ll b,ll k=0,ll l=0,ll r=-1){
        if (r<0) r=n;
        if (r<=a || b<=l) return unit;
        if (a<=l && r<=b) return node[k];
        ll vl = query(a,b,2*k+1,l,(l+r)/2);
        ll vr = query(a,b,2*k+2,(l+r)/2,r);
        return op(vl,vr);
    }
};

struct LazySegmentTree{
private:
    ll n;
    vector<ll> node,lazy;
public:
    LazySegmentTree(vector<ll> v){
        ll sz=(ll)v.size();
        n=1;while(n<sz) n*=2;
        node.resize(2*n-1);
        lazy.resize(2*n-1);
        for(ll i=0;i<sz;i++) node[i+n-1]=v[i];
        for(ll i=n-2;i>=0;i--) node[i]=node[2*i+1]+node[2*i+2];
    }

    void lazyEval(ll k,ll l,ll r){
        if(lazy[k]!=0){
            node[k]+=lazy[k];
            if(r-l>1){
                lazy[2*k+1]+=lazy[k]/2;
                lazy[2*k+2]+=lazy[k]/2;
            }
            lazy[k]=0;
        }
    }
    void update(ll a,ll b,ll x,ll k=0,ll l=0,ll r=-1){
        if(r<0) r=n;
        lazyEval(k,l,r);
        if(b<=l || r<=a) return;
        if(a<=l && r<=b){
            lazy[k]+=(r-l)*x;
            lazyEval(k,l,r);
        }
        else{
            update(a,b,x,2*k+1,l,(l+r)/2);
            update(a,b,x,2*k+2,(l+r)/2,r);
            node[k]=node[2*k+1]+node[2*k+2];
        }
    }

    ll query(ll a,ll b,ll k=0,ll l=0,ll r=-1){
        if(r<0) r=n;
        if(b<=l || r<=a) return 0; 

        lazyEval(k,l,r);
        if(a<=l && r<=b) return node[k];
        ll vl=query(a,b,2*k+1,l,(l+r)/2);
        ll vr=query(a,b,2*k+2,(l+r)/2,r);
        return vl+vr;
    }

    ll at(ll a){return query(a,a+1);}
};

int main(){
    ll N,M;cin>>N>>M;
    vector<ll> a(M);rep(i,M) cin>>a[i];
    vector<bool> br(N,false);rep(i,M) br[a[i]]=true;

    vector<ll> dp(N+5,0);
    dp[0]=1;
    rep(i,N+1){
        if(br[i+1]) dp[i+1]=0;
        else dp[i+1]+=dp[i];
        dp[i+1]%=MOD;
        if(br[i+2]) dp[i+2]=0;
        else dp[i+2]+=dp[i];
        dp[i+2]%=MOD;
        dp[i]%=MOD;
    }
    cout<<dp[N]<<endl;
    return 0;
}

Measured memory_bytes: 1792
#include "bits/stdc++.h"

using namespace std;

#define ll             long long int
#define endl           '\n'

static const int maxn = 2e5 + 5;

signed main()
{
      ios_base::sync_with_stdio(false);
      cin.tie(nullptr);
      cout.tie(nullptr);


      ll r;
      cin >> r;
      ll area = 3 * r * r;
      cout << area << endl;
}


Measured memory_bytes: 256
def countingsort(A,B,k):
    global n
    C=[0 for i in xrange(k+1)]
    for j in xrange(1,n+1):
        C[A[j]]+=1
    for i in xrange(1,k+1):
        C[i]+=C[i-1]
    for j in xrange(n,0,-1):
        B[C[A[j]]]=A[j]
        C[A[j]]-=1

n=input()
A=[0]
a=map(int,raw_input().split())
for i in a:
    A.append(i)
B=[0]*n+[0]
k=max(A)
countingsort(A,B,k)
B=map(str,B)
print(" ".join(B[1:]))

Measured memory_bytes: 223876
#include <bits/stdc++.h>
#define ll long long
#define ld long double
using namespace std;
//using Graph = vector<vector<int>>;
//#define pi 3.1415926535

int main()
{
  string s;
  cin >> s;

  if(s[s.size() - 1] == 's'){
    cout << s << "es" << endl;
    return 0;
  }

  cout << s << 's' << endl;

  return 0; 
}

Measured memory_bytes: 3624
import sys
sys.setrecursionlimit(500000)
MOD = 10**9+7

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]


def main():
    N, M = mi()
    fact = [1]
    for i in range(1, max(N, M)+3):
        fact.append((i*fact[-1])%MOD)
    if abs(N-M) == 1:
        print((fact[N]*fact[M])%MOD)
    elif N == M:
        print((2*fact[N]*fact[M])%MOD)
    else:
        print(0)



if __name__ == '__main__':
    main()


Measured memory_bytes: 73552