akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
using namespace std;
vector<bool> Number(101, false);

int main(){

    vector<vector<int>> card(3, vector<int>(3, 0));
    for (int i = 0; i < 3;i++){
        for (int j = 0; j < 3;j++){
            cin >> card[i][j];
        }
    }

    int N;
    cin >> N;
    for (int i = 0;i < N;i++){
        int t;
        cin >> t;
        Number[t] = true;
    }

    for (int i = 0; i < 3;i++){
        bool ch = true;
        for (int j = 0; j < 3;j++){
            if(Number[card[i][j]] == false)
                ch = false;
        }
        if(ch){
            cout << "Yes" << endl;
            return 0;
        }
    }

    for (int i = 0; i < 3; i++)
    {
        bool ch = true;
        for (int j = 0; j < 3; j++)
        {
            if (Number[card[j][i]] == false)
                ch = false;
        }
        if (ch)
        {
            cout << "Yes" << endl;
            return 0;
        }
    }

    bool ch = true;
    for(int i = 0; i < 3;i++){
        if(Number[card[i][i]] == false)
            ch = false;
    }
    if(ch){
        cout << "Yes" << endl;
        return 0;
    }
    ch = true;
    for (int i = 0; i < 3; i++)
    {
        if (Number[card[i][2-i]] == false)
            ch = false;
    }
    if (ch)
    {
        cout << "Yes" << endl;
        return 0;
    }
    cout << "No" << endl;
    return 0;
}

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

const long long int INF = pow(10, 16);

long long int N, K, h[100000];
long long int DP[100000];

void dp() {
	DP[0] = 0;
	for (int i = 1; i < N; i++) {
		DP[i] = INF;
	}
	for (int i = 0; i < N; i++) {
		for (int j = i + 1; j <= i + K && j < N; j++) {
			DP[j] = min(DP[j], DP[i] + abs(h[j] - h[i]));
		}
	}
}

int main() {
	cin >> N >> K;
	for (int i = 0; i < N; i++) {
		cin >> h[i];
	}
	dp();
	cout << DP[N - 1];
}

Measured memory_bytes: 1792
n = int(input())
h = [int(i) for i in input().split()]
h.append(0)

count = 0
tank = 0
while True:
    for i in range(len(h)):
        if h[i] == 0 and tank != 0:
            count += 1
            tank = 0

        elif h[i] != 0:
            h[i] -= 1
            tank = 1
    if sum(h) == 0:
        break

print(count)

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

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<pii,int> piii;
typedef pair<ll,ll> pll;

#define reps(i,f,n) for(int i = int(f); i <= int(n); i++)
#define rep(i,n) reps(i,0,int(n)-1)
#define rrep(i,n) for(int i = n-1; i >= 0; i--)

#define all(x) (x).begin(),(x).end()
#define X first
#define Y second

#define sz size()
#define eb emplace_back
#define pb push_back

int n, k;
vector< vector<int> > g;
const ll MOD = 1000000007LL;
const bool DBG = false;


ll f(int s){
  vector<bool> used;
  ll ans = k;
  used.resize(n, false);
  queue<int> q;
  q.push(s);
  used[s] = true;
  while(!q.empty()){
    int t = q.front();q.pop();
    int x = 1;
    int y = 0;
    rep(i, g[t].size()){
      int u = g[t][i];
      x++;
      if(used[u]) continue;
      q.push(u);
      used[u] = true;
      y++;
    }
    if(DBG)cout << "xy" << x << " " << y << endl;
    if(k-x+1 <= 0) return 0;

    rep(i, y){
      int z = k-x+i+1;
      if(DBG)cout << " * " << z << endl;
      ans *= z;
      ans %= MOD;
    }
  }
  return ans;
}

int main(void){
  cin >> n >> k;
  g.resize(n);
  rep(i,n-1){
    int a,b;
    cin >> a >> b;
    --a;--b;
    g[a].pb(b);
    g[b].pb(a);
  }
  cout << f(0) << endl;
  return 0;
}


Measured memory_bytes: 6520
#include <bits/stdc++.h>
typedef long long ll;
#define MOD 1000000007

using namespace std;
 
 
int main(){
    int N; double M; cin >> N >> M;
    vector<int> A(N);
    double sum = 0;
    for (int i = 0; i < N; i++)
    {
        cin >> A[i];
        sum += A[i];
    }
    sort(A.begin(),A.end(),greater<int>());
    if(A[M-1] >= sum/(4.0*M)) cout << "Yes" << endl;
    else cout << "No" << endl;
    
}

Measured memory_bytes: 256
/*input
869121
*/
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define int long long
const int m = 1e9+7;
ll powermod(ll b,ll e,ll m=1e9+7)
{
	if(e==0) return 1;
	if(e&1) return b*powermod(b*b%m,e/2,m)%m;
	return powermod(b*b%m,e/2,m);
}
signed main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int n; cin>>n;
	int ans = powermod(10, n);
	ans -= powermod(8, n);
	ans = (ans+m)%m;
	int atleast1nineandno0s = (powermod(9,n)-powermod(8,n)+m)%m;
	for (int i = 0; i < 2; ++i)
	{
		ans -= atleast1nineandno0s;
		ans = (ans+m)%m;
	}
	cout<<ans;
	return 0;	
}

Measured memory_bytes: 3580
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
using i64 = int64_t;
using ll = long long;
ll gcd(ll a, ll b){
  if(a < b){
    return gcd(b,a);
  }
  if(a % b ==0){
    return b;
  }
  else{
    return gcd(b,a%b);
  }
}
ll lcm(ll a, ll b){
  return a*b/gcd(a,b);
}
ll a_div_num(ll p,ll q,ll r){//1~rまででpでもqでも割れない個数
  ll np = ll(r/p);
  ll nq = ll(r/q);
  ll pkatsuq = ll(r/(lcm(p,q)));
  return r - (np + nq -pkatsuq);
}
int main() {
  ll a,b,c,d;
  cin >> a >> b >> c >> d;
  cout << a_div_num(c,d,b) - a_div_num(c,d,a-1) << endl;
  return 0;
}

Measured memory_bytes: 256
N,C = map(int, input().split())
cost = [list(map(int, input().split())) for _ in range(C)]
color = [list(map(lambda x:int(x)-1, input().split())) for _ in range(N)]

mod3 = {0:[], 1:[], 2:[]}
for i in range(N):
    for j in range(N):
        m = (i+j)%3
        mod3[m].append(color[i][j])
        
from collections import Counter
from itertools import combinations, permutations
cnts = [Counter(mod3[i]) for i in range(3)]
# print(cnts)
ans = float('inf')
for comb in combinations(range(C), 3):
    for p in permutations(comb):
        cond = 0
        for i in range(3):
            for col in cnts[i].keys():
                cond += cnts[i][col]*cost[col][p[i]]
        ans = min(ans, cond)
        #print(cond, p)
print(ans)
    

Measured memory_bytes: 9872
n,k=map(int,input().split())
x=list(map(int,input().split()))
a=[x[i] for i in range(n) if x[i]<0]
b=[x[i] for i in range(n) if x[i]>=0]
na=len(a)
nb=len(b)
if 0 in x:
    k-=1
    b=[x[i] for i in range(n) if x[i]>0]
    nb=nb-1

if k==0:
    print(0)
    exit()
ans=10**10
if na>=k:
    ans=-a[-k]

if nb>=k:
    ans=min(ans,b[k-1])

if nb==0:
    print(-a[-k])
    exit()

if na==0:
    print(b[k-1])
    exit()

for i in range(1,nb+1):
    m=k-i
    if m>na or m<0:
        continue
    elif 0<m<=na:
        ans=min(ans,min(b[i-1]-2*a[-m],2*b[i-1]-a[-m]))
    elif m==0:
        ans=min(ans,b[k-1])
print(ans if k!=0 else 0)


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

const int INF=0x3f3f3f3f;

int pool[62][62][7000];
int*dp[62][62];
int a[62],r[62],b[62];
int pa[62],pr[62],pb[62];

int main(){
	memset(pool,0x3f,sizeof(pool));
	rep(i,62)rep(j,62)dp[i][j]=&pool[i][j][3500];
	int n,K;cin>>n>>K;
	rep(i,n)scanf("%d",&a[i]);
	rep(i,K)scanf("%d",&r[i]);
	rep(i,K)scanf("%d",&b[i]);
	sort(a,a+n,greater<>());
	sort(r,r+K,greater<>());
	sort(b,b+K,greater<>());
	rep(i,n)pa[i+1]=pa[i]+a[i];
	rep(i,K)pr[i+1]=pr[i]+r[i];
	rep(i,K)pb[i+1]=pb[i]+b[i];
	dp[0][0][0]=0;
	rep(i,n)rep(j,K+1)for(int k=0;k<=50*i;k++){
		if(dp[i][j][k]==INF)continue;
		int j2=i-j;
		if(j<K){
			dp[i+1][j+1][k+a[i]]=min(dp[i+1][j+1][k+a[i]],dp[i][j][k]+max(0,a[i]-r[j]));
		}
		if(j2<K){
			dp[i+1][j][k]=min(dp[i+1][j][k],dp[i][j][k]+max(0,a[i]-b[j2]));
		}
	}
	int Min=INF;
	rep(j,K+1)for(int k=0;k<=50*n;k++){
		if(dp[n][j][k]==INF)continue;
		int k2=pa[n]-k;
		if(k<=pr[K]&&k2<=pb[K]){
			Min=min(Min,dp[n][j][k]);
		}
	}
	if(Min==INF)puts("-1");
	else cout<<Min<<endl;
}


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

int main(){
  long long n;
  cin>>n;
  if(n%2==1){
    cout<<0<<endl;
  }else{
    long long sum=0;
    long long x=10;
    while(x<=n){
      sum+=n/x;
      x*=5;
    }
    cout<<sum<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
    int n;
    while (cin >> n) {
        int d = n;
        long long res = 0;
        while (d < 600) {
            long long y = d * d;
            res += n * y;
            d += n;
        }
        cout << res << endl;
    }
    return 0;
}

Measured memory_bytes: 0
/*
AUTHOR :: AMAN VERMA
"If debugging is the process of removing bugs, then programming must be the process of putting them in"//
*/

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define vec vector<int>
#define ll long long
#define llu unsigned long long
#define ld long double
#define pb push_back
#define mp make_pair
#define fastio	ios_base::sync_with_stdio(0);cin.tie(0)

#define  FOR(i, j, k, in) for (int i=j ; i<k ; i+=in)
#define  FORE(i, j, k, in) for (int i=j ; i<=k; i+=in)

#define endl '\n'
#define debug cout<<"AMAN"<<endl;

#define mod 1000000007
#define PI 3.14159265358979323846

const ll MAX = 1e5 + 5;

ll modadd(ll a , ll b)
    {
    return((a%mod)+(b%mod)+mod)%mod;
    }

ll modsub(ll a , ll b)
    {
    return((a%mod) - (b%mod) + mod)%mod;
    }

double tick(){static clock_t oldt,newt=clock();double diff=1.0*(newt-oldt)/CLOCKS_PER_SEC;oldt=newt;return diff;}
const int MOD	= 1e9 + 7;

using namespace std;
using namespace __gnu_pbds;
void printString(long long int n)
    {
    char str[MAX]; // To store result (Excel column name)
    int i = 0; // To store current index in str which is result

    while (n > 0) {
        // Find remainder
        int rem = n % 26;

        // If remainder is 0, then a 'Z' must be there in output
        if (rem == 0) {
            str[i++] = 'z';
            n = (n / 26) - 1;
        }
        else // If remainder is non-zero
        {
            str[i++] = (rem - 1) + 'a';
            n = n / 26;
        }
    }
    str[i] = '\0';
    reverse(str, str + strlen(str));
    cout << str << endl;

    return;
}

// Driver program to test above function
int main()
{
    long long int num;
    cin>>num;
    printString(num);
    return 0;
}


Measured memory_bytes: 3620
#define _GLIBCXX_DEBUG
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <cmath>

using namespace std;
int main(){
  int n,m;
  cin>>n>>m;
  cout<<pow(2,m)*(1900*m+100*(n-m));
}

Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <cmath>
#include <deque>
#include <iterator>
#include <map>
#include <queue>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
template<class T> inline bool chmax(T& a, T b) {if (a<b) {a=b; return true;} return false;}
template<class T> inline bool chmin(T& a, T b) {if (a>b) {a=b; return true;} return false;}

const ll MOD = 1000000007;
const ll HIGHINF = (ll)1e18;

vll a, l;

ll LIS(ll n) {
  l[0] = a[0];
  ll length = 1;

  rep(i, 1, n) {
    if (l[length-1] < a[i]) {
      l[length++] = a[i];
    } else {
      *lower_bound(l.begin(), l.begin()+length, a[i]) = a[i];
    }
  }
  return length;
}

int main() {
  ll n; cin >> n;
  a.resize(n); l.resize(n);
  REP(i, n) cin >> a[i];
  cout << LIS(n) << endl;
  return 0;
}



Measured memory_bytes: 4416
#include<bits/stdc++.h>
using namespace std;
#define  ft  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define  ll  long long
#define  pi  pair<int,int>
#define  pb  push_back
#define  F   first
#define  S   second
const int N=2e5+3;
//string s,p;
//vector<int>v;
//map<int,int>mp;

int main()
{
    ft
    ll t,i,j,n,m,l,r=0,s=0;
    cin>>n>>m;
    n%=m;
    if((m-n)<n)
    {
        n=m-n;
    }
    cout<<n<<"\n";
    return 0;
}



Measured memory_bytes: 256
s = input()
a = [str(c) for c in s]

if a.count('R') == 3:
  print(3)
elif a.count('R') == 0:
  print(0)
elif a.count('R') == 1:
  print(1)
elif a.count('R') ==2:
  if a[1] == 'R':
    print(2)
  else:
    print(1)

Measured memory_bytes: 9112
import math

def I(): return int(input())
def LI(): return list(map(int,input().split()))
def MI(): return map(int,input().split())
def LLI(n): return [list(map(int, input().split())) for _ in range(n)]

#bisect.bisect_left(list,key)はlistのなかでkey未満の数字がいくつあるかを返す
#bisect.bisect_right(list, key)はlistのなかでkey以下の数字がいくつあるかを返す
#これを応用することで
#len(list) - bisect.bisect_left(list,key)はlistのなかでkey以上の数字がいくつあるかを返す
#len(list) - bisect.bisect_right(list,key)はlistのなかでkeyより大きい数字がいくつあるかを返す
#これらを使うときはあらかじめlistをソートしておくこと！

n,k = MI()
a = LI()

def cutting_isOK(x,li,k):
    ans = 0
    for i in range(n):
        ans += math.ceil(li[i]/x) - 1
    if ans <= k:
        return True
    else:
        return False
left = 0
right = 10**9+1
while abs(left-right) > 1:
    mid = (left+right)//2
    if cutting_isOK(mid,a,k):
        right = mid
    else:
        left = mid
print(right)


Measured memory_bytes: 31020
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define RREP(i, n) for (int i = n; 0 <= i; i--)
#define FOR(i, start, end) for (int i = start; i < end; i++)
#define FORSTEP(i, start, end, step) for (int i = start; i < end; i += step)
#define RFOR(i, start, end) for (int i = start; end <= i; i--)
#define ALL(a) a.begin(), a.end()
#define MOD(a) a %= 1000000007
typedef long long ll;
const int INF32 = 2147483647;
const ll INF64  = 9223372036854775807;
using namespace std;

vector<int> prime(int N) {
    vector<int> pri;
    vector<bool> is_prime;
    is_prime    = vector<bool>(N + 1, true);
    is_prime[0] = is_prime[1] = false;
    FOR(i, 2, N + 1) {
        if (is_prime[i]) {
            pri.push_back(i);
            FORSTEP(j, 2 * i, N + 1, i) is_prime[j] = false;
        }
    }
    return pri;
}

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

    int Q;
    cin >> Q;
    vector<int> l(Q), r(Q);
    REP(i, Q) cin >> l[i] >> r[i];

    auto pri = prime(100000);
    vector<int> v;
    REP(i, pri.size()) {
        if (pri[i] % 2 == 1) {
            if (binary_search(ALL(pri), (pri[i] + 1) / 2)) {
                v.push_back(pri[i]);
            }
        }
    }

    REP(i, Q) {
        auto left  = lower_bound(ALL(v), l[i]);
        auto right = upper_bound(ALL(v), r[i]);
        int ans    = (right - v.begin()) - (left - v.begin());
        cout << ans << '\n';
    }

    return 0;
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
using ll = long long;
const int INF = 2147483647;

int main(){
	int x;
	cin >> x;
	ll sum=0;
	int i=1;
	while(1){
		sum+=i;
		if(sum>=x) break;
		i++;
	}
	cout << i << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define f first
#define s second
#define ll long long
const int N = 1e5+10;
vector < int > graph[N] ;
int vis[N] , n , mx1  ,m;
map < int , int > mp ;
int dfs ( int node ){
    int mx = 0 ;
    for (auto i : graph[node]){
        if (!vis[i]) {
            vis[i] = 1 ;
            mp[i] = dfs(i) ;
            mx = max(mx,mp[i]+1);
        }
        else
            mx = max(mx,1+mp[i]);
    }
    mp[node] = mx ;
    return mp[node] ;
}
int main()
{
    ios_base::sync_with_stdio( false ), cin.tie( nullptr ), cout.tie( nullptr );
    cin >> n >> m ;
    for ( int i = 0 ; i < m ; i++ ){
        int u , v ;
        cin >> u >> v ;
        graph[u].push_back(v) ;
    }
    int mx = 0 ;
    for ( int i = 1 ; i <= n ; i++) {
        if (!vis[i]){
            vis[i] = 1 ;
            mx = max(dfs(i),mx) ;
        }
    }
    cout << mx ;
}



Measured memory_bytes: 14848
main(a,b,c,d,e,f,x,i){for(i=3;i--;printf("%d %d %d\n",x/3600,x/60%60,x%60))scanf("%d%d%d%d%d%d",&a,&b,&c,&d,&e,&f),x=(d*3600+e*60+f)-(a*3600+b*60+c);exit(0);}

Measured memory_bytes: 600
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
 int main() {
	 int A, B, C;
	 cin >> A >> B >> C;
	 if (A + B >= C) {
		 cout << "Yes" << endl;
	 }
	 else {
		 cout << "No" << endl;
	 }
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <chrono>
#include <stack>
#include <string>
#include <bitset>
#include <unordered_map>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <cassert>
#include <tuple>
#include <iomanip>
#include <random>
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <fstream>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<bool> vb;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define in insert
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int INF = 1e9 + 5;
void solve(){
    int n, k, q;
    cin >> n >> k >> q;
    vector<ll> a(n, k-q);
    for(int i = 0; i < q; i++){
        int x;
        cin >> x;
        a[x-1]++;
    }
    for(int i = 0; i < n; i++) (a[i] > 0) ? cout << "Yes\n" : cout << "No\n";
}
int main(){
    speed;
    int t = 1;
    //cin >> t;
    while(t--) solve();
}

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

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<ll,pll> plpl;
typedef tuple<ll,ll,ll> tl;
//ll mod=1000000007;
ll mod=998244353;
ll inf=1000000000000000000;
#define rep(i,m,n) for(int i=m;i<n;i++)
#define rrep(i,n,m) for(int i=n;i>=m;i--)
ll lmax(ll a,ll b){
    if(a<b)return b;
    else return a;
}
ll lmin(ll a,ll b){
    if(a<b)return a;
    else return b;
}
ll gya[200010];
ll kai[200010];
ll beki(ll n,ll k){
    ll i=k;
    ll ret=1;
    ll now=n;
    while(i>0){
        if(i%2==1){
            ret*=now;
            ret%=mod;
        }
        now*=now;
        now%=mod;
        i/=2;
    }
    return ret;
}
ll gyaku(ll n){
    return beki(n,mod-2);
}
void nckinit(ll n){
    kai[0]=1;
    kai[1]=1;
    for(int i=2;i<=n;i++){
        kai[i]=kai[i-1]*i;
        kai[i]%=mod;
    }
    gya[n]=gyaku(kai[n]);
    for(int i=n-1;i>=1;i--){
        gya[i]=gya[i+1]*(i+1);
        gya[i]%=mod;
    }
    gya[0]=1;
}
ll nck(ll n,ll k){
    if(k<0)return 0;
    if(k==0||n==k)return 1;
    ll ret=kai[n];
    ret*=gya[n-k];
    ret%=mod;
    ret*=gya[k];
    ret%=mod;
    return ret;
}
ll npk(ll n,ll k){
    if(k<0)return 0;
    if(k==0)return 1;
    ll ret=kai[n];
    ret*=gya[n-k];
    ret%=mod;
    return ret;
}
int main(){
    ll k,n;cin>>k>>n;
    nckinit(10000);
    ll ans[2*k+1];
    ll zen=nck(n+k-1,n);
    for(int i=2;i<=k+1;i+=2){
        ll sum=0;
        ll s=i/2;
        rep(j,1,s+1){
            if(2*j>n)break;
            ll cnt=1;
            cnt*=nck(s,j)*pow(-1,j+1);
            cnt=(cnt+mod)%mod;
            cnt*=nck(n-2*j+k-1,n-2*j);
            cnt%=mod;
            sum+=cnt;
            sum=(sum+mod)%mod;
        }
        //cout<<sum<<endl;
        ans[i]=sum;
        if(i!=k+1)ans[i+1]=sum;
    }
    rep(i,2,2*k+1){
        if(i<=k+1)cout<<(zen-ans[i]+mod)%mod<<endl;
        else cout<<(zen-ans[2*k+2-i]+mod)%mod<<endl;
    }
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;


int main()
{
    string s, t;
    cin >> s >> t;
    sort(ALL(s));
    sort(ALL(t));
    reverse(ALL(t));
    if (s < t) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

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

int main(){
    ll n;
    vector <ll> a(5);
    cin >> n >> a[0] >> a[1] >> a[2] >> a[3] >> a[4];
    vector <ll> z(6,0);
    z[0]=n;
    rep(i,4){
        a[i+1]=min(a[i],a[i+1]);
    }

    ll ans;
    if(n%a[4]==0){
    ans=n/a[4];
    }
    else{
        ans=n/a[4]+1;
    }
    ans+=4;

    cout << ans << endl;

    

    return 0;
}

Measured memory_bytes: 3580
import sys
from statistics import *
from collections import *
from operator import itemgetter
stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

n = ni()
a = ni()
print('Yes' if n - (n // 500) * 500 <= a else 'No')

Measured memory_bytes: 5276
n, m, q = map(int, input().split())
l = [[int(i) for i in input().split()] for _ in range(q)]
m -= 1
mx = 0


def gen_A(x, y, A, c):
  global mx
  if x == n and y == m:
    pts = 0
    for i in l:
      if int(A[i[1]-1])-int(A[i[0]-1]) == i[2]:
        pts += i[3]
    mx = max(mx, pts)
    return
  if x < n:
    nA = A+str(c)
    gen_A(x+1, y, nA, c)
  if y < m:
    nc = c+1
    gen_A(x, y+1, A, nc)


gen_A(0, 0, "", 0)
print(mx)

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

const int di[]={-1,-1,-1,0,0,1,1,1};
const int dj[]={-1,0,1,-1,1,-1,0,1};

int main(){
  int h,w;
  cin >> h >> w;
  vector<string> s(h);
  for(int i=0;i<h;++i){
    cin >> s[i];
  }
  int co=0;
  vector<vector<char>> ans(h,vector<char>(w,0));
  for(int i=0;i<h;++i){
    for(int j=0;j<w;++j){
      if(s[i][j]=='#'){
        ans[i][j]='#';
      }else{
        co=0;
        for(int k=0;k<8;++k){
          int dx=i+di[k];
          int dy=j+dj[k];
          if(dx<0 || dx>=h || dy<0 || dy>=w) continue;
          if(s[dx][dy]=='#'){
            co++;
          }
        }
        ans[i][j]=co+'0';
      }
    }
  }
  for(int i=0;i<h;++i){
    for(int j=0;j<w;++j){
      if(j!=w-1){
        cout << ans[i][j];
      }else{
        cout << ans[i][j] << endl;
      }
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main() {
  int n;
  char c;
  cin >> n;
  for(int i=0;i<n;i++){
    cin >> c;
    if(c=='Y'){
      cout << "Four" << endl;
      return 0;
    }
  }
    
    cout << "Three" << endl;
    return 0;
}

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

using namespace std;

int main()
{
  string s;
  cin >> s;
  
  sort(s.begin(), s.end());
  
  if (s == "abc") {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    int K,X;
    cin >> K >> X;
    

    for(int i=max(X-K+1,-1000000);i < min(X+K,1000000); i++){
        cout << i << " " ;
    }
    
    cout <<  endl;
    return 0;
}

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

class Proc{
public:
	string nam;
	int tim;
	Proc(){ nam = ""; tim = 0; }
};

int main(){
	queue<Proc> Q;

	int n, q;
	cin >> n >> q;

	for (int i = 0; i < n; i++){
		Proc P;
		cin >> P.nam >> P.tim;

		Q.push(P);
	}

	int total_tim = 0;

	while (!Q.empty()){
		Proc P = Q.front(); Q.pop();

		if (P.tim <= q){
			total_tim += P.tim;

			cout << P.nam << " " << total_tim << endl;
		}
		else{
			total_tim += q;
			P.tim -= q;

			Q.push(P);
		}
	}
	return 0;
}

Measured memory_bytes: 4404
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Scanner;
import java.util.Set;

public class Main {
    long[][] c = new long[51][51];

    void solve(Scanner sc, PrintWriter pw) {
        int N = sc.nextInt();
        int K = sc.nextInt();
        long S = sc.nextLong();
        long T = sc.nextLong();
        long[] data = new long[N];
        for (int i = 0; i < N; i++) {
            data[i] = sc.nextLong();
        }
        for (int i = 0; i <= N; i++) {
            c[i][0] = 1;
            for (int j = 1; j <= i; j++) {
                c[i][j] = c[i - 1][j] + c[i - 1][j - 1];
            }
        }
        long[] sum = new long[(N + 1)];
        for (int i = 1; i <= N; i++) {
            for (int j = 1; j <= Math.min(i, K); j++) {
                sum[i] += c[i][j];
            }
        }
        long result = 0;
        List<Long> nums = new ArrayList<>();
        for (long mask = 0; mask < (1L << 18); mask++) {
            if (((T ^ S) & mask) != mask) {
                continue;
            }
            boolean isAdd = (countBit(mask) % 2) == 0;
            nums.clear();
            for (int i = 0; i < N; i++) {
                if ((data[i] & S) != S) {
                    continue;
                }
                if ((data[i] | T) != T) {
                    continue;
                }
                nums.add(data[i] & mask);
            }
            Collections.sort(nums);
            int begin = 0;
            int nextBegin;
            while (begin < nums.size()) {
                nextBegin = begin + 1;
                while (nextBegin< nums.size() && nums.get(nextBegin).equals(nums.get(nextBegin - 1))) {
                    nextBegin++;
                }
                result += (isAdd ? 1L : -1L) * (sum[nextBegin - begin]);
                begin = nextBegin;
            }
        }
        pw.println(String.format("%d", result));
    }

    private int countBit(long mask) {
        int result = 0;
        while (mask > 0) {
            result += (mask & 1);
            mask >>= 1;
        }
        return result;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        PrintWriter pw = new PrintWriter(System.out);
        new Main().solve(sc, pw);
        pw.flush();
        pw.close();
        sc.close();
    }
}


Measured memory_bytes: 63520
C = input()
d = {
    'a':'b',
    'b':'c',
    'c':'d',
    'd':'e',
    'e':'f',
    'f':'g',
    'g':'h',
    'h':'i',
    'i':'j',
    'j':'k',
    'k':'l',
    'l':'m',
    'm':'n',
    'n':'o',
    'o':'p',
    'p':'q',
    'q':'r',
    'r':'s',
    's':'t',
    't':'u',
    'u':'v',
    'v':'w',
    'w':'x',
    'x':'y',
    'y':'z'
}
print(d[C])




Measured memory_bytes: 3060
/*author @dhanush*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL)
#define pb push_back
#define se second
#define fi first
/* FUCK ratings iam in love with expreience*/
ll freq[1001][1001];
ll dp[1001];
ll mod = 1000000007;
int main()
{


  string s;
  cin >> s;
  int ans = 0;
  int maxi = 0;
  for (int i = 0; i < 3; i++)
  {
    if (s[i] == 'R')
    {
      ans++;
      maxi = max(maxi, ans);
    }
    else
      ans = 0;
  }
  cout << maxi << endl;

}





Measured memory_bytes: 3616
#include<stdio.h>

int main(){
    int input[10][10];
    int i, j, s;

    for(i = 0; i < 10; i++){
        for(j = 0; j < 10; j++) input[j][i] = 0;
    }

    while(scanf("%1d%1d%1d%1d%1d%1d%1d%1d%1d%1d", &input[0][0], &input[1][0], &input[2][0], &input[3][0], &input[4][0], &input[5][0], &input[6][0], &input[7][0], &input[8][0], &input[9][0]) != EOF){
        for(i = 0; i < 9; i++){
            for(j = 0; j < 9; j++){
                s = input[j][i] + input[j+1][i];
                if(s >= 10) s -= 10;
                input[j][i+1] = s;
            }
        }
        printf("%d\n", input[0][9]);
    }
    return 0;
}

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


mod = 998244353
N = int(input())
A = [int(input()) for _ in range(N)]

S = sum(A)
L = S//2
dp1 = [0]*(L+1)
dp2 = [0]*(L+1)
dp1[0] = 1
dp2[0] = 1
for a in A:
    for i in reversed(range(L-a+1)):
        dp1[i+a] = (dp1[i+a] + dp1[i])%mod
        dp2[i+a] = (dp2[i+a] + dp2[i]*2)%mod

p1 = 0
p2 = 0
for s in range(1,L+1):
    p1 = (p1 + dp1[s]*6)%mod
    p2 = (p2 + dp2[s]*3)%mod
ans = (pow(3, N, mod) + 3 - 3*pow(2, N, mod) - p2 + p1) % mod
print(ans)

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

int main() {
    long long int N, A, B;
    cin >> N >> A >> B;

    long long int M = N / (A+B) * A;
    if(N % (A+B) <= A) {
        M += N % (A+B);
    } 
    else{
        M += A;
    }
    cout << M << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int p[60];
int main ()
{
	int i,j,n,r=0;
	scanf("%i",&n);
	for(i=1;i<=n;i++)
	{
		scanf("%i",&p[i]);
	}
	for(i=1;i<=n;i++)
	{
		if(p[i]==i)
		{
			r=r+1;
		}
	}
	//printf("%i\n",r)
	if(r>=n-2)
	{
		printf("YES");
	}
	else
	{
		printf("NO");
	}
	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>

typedef long long ll;
typedef unsigned long long ull;
using namespace std;

#define FALSE printf("false\n");
#define TRUE printf("true\n");
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i = 0;i < ((int)(n));++i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define test(a) cout<<"line:"<<__LINE__<<"["<<(#a)<<": "<<(a)<<"]"<<endl

const int INF = 1e9+7;
const ll INFL = 9*1e18;
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };

#define SUM(vec) accumulate(all(vec),0LL) // 配列の中身を全部足す
template<typename T>void print(T&& x){cout<<x<<endl;}// 改行付き出力
ll inline digit(ll num){int tmp = 0;while(num){tmp++;num/=10;}return tmp;} // 桁数
template<typename T>inline T digitSum(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;} // 各桁の和
template<typename T>inline T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);} // 最大公約数
template<typename T>inline T lcm(T a, T b){T g = gcd(a,b);return a/g*b;} // 最小公倍数
template<typename T>inline T power(T a,T b){T tmp=1;rep(i,b){tmp*=a;}return tmp;} // 累乗
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; }
int ctoi(char c){return c - '0';}

// TODO: write
int main() { 
  int n;cin>>n;--n;
  vector<int> c(n),s(n),f(n);rep(i,n)cin>>c[i]>>s[i]>>f[i];
  rep(i,n){
    int time = 0;
    for(int j = i;j < n;++j){
      //test(time);
      time += max(0,s[j]-time);
      time += (f[j]-(time-s[j])%f[j])%f[j];
      time += c[j];
    }
    print(time);
  }

  print(0);
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
 
// 素数判定
int isprime(int x){
  int i;
  if(x == 2)return true;
  // xが2の値のときは素数
  if(x < 2 || x%2==0)return false;
  // xが2より小さいときまたは2で割り切れるときは素数ではない
  i = 3;
   
  while(i*i <=x){
    // 合成数はその(正の)平方根以下の素因数をもつことを利用してiがxの平方根以下で調べる
    if(x%i==0)return false;
    i = i + 2;
  }
  return true;
}
 
int main(){
  int i,n,cnt=0;
  cin >> n;
  for(i = 0;i < n; i++){
    int prime;
    cin >> prime;
    bool ans = isprime(prime); //素数判定
    if(ans == 1)cnt++; // 素数をカウント
  }
   cout << cnt << endl;
  return 0;
}

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

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

  if ( a % 2 == 1 && b % 2 ==1) {
    cout << "Odd" << endl; 
  }
  else {
      cout << "Even" << endl; 
  }
}



Measured memory_bytes: 256
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <chrono> //1e+9??§?????? auto end= chrono::system_clock::now()-st;  cout<<end.count()%1e+9<<endl;
using namespace std;
typedef int ll;
typedef pair<ll,ll> P;
typedef long double db;

#define fr first
#define sc second
#define pb push_back
#define rep(i,x) for(ll i=0;i<x;i++)
#define rep1(i,x) for(ll i=1;i<=x;i++)
#define rrep(i,x) for(ll i=x-1;i>=0;i--)
#define rrep1(i,x) for(ll i=x;i>0;i--)

ll N,S,T;
ll V[3001],C[3001];
ll dp1[3002][3001];//i?????§???j????????\??????????\???????
ll dp2[3002][3001];
int main()
{
	cin>>N>>T>>S;
	T-=S;
	rep1(i,N){
		cin>>V[i]>>C[i];
	}
	rep1(i,N){
		for(ll j=0;j<=S;j++){
			if(j-C[i]>=0){
				dp1[i][j]=max(dp1[i-1][j],dp1[i-1][j-C[i]]+V[i]);
			}
			else dp1[i][j]=dp1[i-1][j];
		}
	}
	rrep1(i,N){
		for(ll j=0;j<=T;j++){
			if(j-C[i]>=0){
				dp2[i][j]=max(dp2[i+1][j],dp2[i+1][j-C[i]]+V[i]);
			}
			else dp2[i][j]=dp2[i+1][j];
		}
	}
	ll ans=0;
	for(ll i=0;i<=N;i++){
		ans=max(ans,dp1[i][S]+dp2[i+1][T]);
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 62232
package main

import (
	"fmt"
	"sort"
)

func main() {
	var N, M int
	fmt.Scan(&N, &M)
	drinks := make(map[int]int)
	var A, B int
	for i := 0; i < N; i++ {
		fmt.Scan(&A, &B)
		drinks[A] += B
	}

	k := make([]int, 0, len(drinks))
	for p := range drinks {
		k = append(k, p)
	}
	sort.Ints(k)

	ans := 0
	for i := 0; i < len(k); i++ {
		c := drinks[k[i]]
		if M < c {
			c = M
		}
		ans += k[i] * c
		M -= c
		if M <= 0 {
			break
		}
	}

	fmt.Println(ans)
}


Measured memory_bytes: 9732
n = gets.split.first.to_i
xs = gets.split.map(&:to_i) 

cxs = xs.clone
cxs.sort!
ans = []
a = cxs[ (n / 2) - 1 ]
b = cxs[ (n / 2) ]
xs.size.times do |i|
  if xs[i] < b
    ans << b
  else
    ans << a
  end
end

puts ans

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


int main(){

 string Cad,Ans;
 cin>>Cad;
 int i;

 Ans=Cad;

 for(i=0;i<Ans.size();i++){
   if(Ans[i]=='?')Ans[i]='D';
 }

 cout<<Ans;
}


Measured memory_bytes: 3920
#include<stdio.h>

int main()
{
	int n,i,j=0,k;
	char str[1008],temp;
	
	scanf("%d",&n);
	temp=getchar();
	for(i=0;i<n;i++){
		for(j=0;;j++){
			str[j] = getchar();
			if(str[j] == '\n'){
				str[j] = '\0';
				break;
			}
		}
		
		for(k=0;k<j;k++){
			if(str[k]=='H' && str[k+1]=='o' && str[k+2]=='s' && str[k+3]=='h' && str[k+4]=='i' && str[k+5]=='n' && str[k+6]=='o')str[k+6]='a';
		}
		printf("%s\n",str);
	}
	
	return 0;
}

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

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> ii;
typedef pair<ii, ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
typedef map<ll, ll> mpii;
typedef unordered_map<ll, ll> umpii;

#define pb(v) push_back(v)
#define all(v) v.begin(), v.end()
#define upb(v, key) (upper_bound(all(v), key) - v.begin())
#define lob(v, key) (lower_bound(all(v), key) - v.begin())

ll inf = 1e9;
ll INF = inf * 1ll * inf;
ll mod = 1e9 + 7;
double eps = 1e-9;
const ld pi = ld(3.1415926535897932384626433832795);
ll dr[] = {-1, 0, 0, 1};
ll dc[] = {0, 1, -1, 0};

template <class TH>
void _dbg(const char *sdbg, TH h) { cerr << sdbg << '=' << h << endl; }
template <class TH, class... TA>
void _dbg(const char *sdbg, TH h, TA... a)
{
  while (*sdbg != ',')
    cerr << *sdbg++;
  cerr << '=' << h << ',';
  _dbg(sdbg + 1, a...);
}
template <class T>
ostream &operator<<(ostream &os, vector<T> V)
{
  os << "[";
  for (auto vv : V)
    os << vv << ",";
  return os << "]";
}
template <class L, class R>
ostream &operator<<(ostream &os, pair<L, R> P)
{
  return os << "(" << P.st << "," << P.nd << ")";
}
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)

/*...................................................*/

main()
{
  int n, m, i, j;
  cin >> n >> m;
  vector<string> a(n);
  for(i = 0; i < n; i++)
  cin >> a[i];
  vvi dp(n, vi(m));
  dp[0][0] = a[0][0] == '.';
  for(i = 1; i < m; i++)
  if(a[0][i] == '.')
  dp[0][i] = dp[0][i - 1];
  for(i = 1; i < n; i++)
  if(a[i][0] == '.')
  dp[i][0] = dp[i - 1][0];
  for(i = 1; i < n; i++)
  for(j = 1; j < m; j++)
  if(a[i][j] == '.')
  dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % mod;
  
  cout << dp[n - 1][m - 1];
}

Measured memory_bytes: 9216
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int N= scan.nextInt();
        int A = scan.nextInt();
        int B = scan.nextInt();
        int P = 0;
        int Q1 = 0;
        int Q2 = 0;
        int Q3 = 0;

        for(int i = 0; i < N; i++){
            P = scan.nextInt();
            if( P <= A) {
                Q1++;
            }else if(P >= A + 1 && P <= B){
                Q2++;
            }else if(P >= B + 1){
                Q3++;
            } else {
                //nothing
            }
        }
        scan.close();

        if(Q1 <= Q2 && Q1 <= Q3){
            System.out.println(Q1);
        }else if(Q2 <= Q1 && Q2 <= Q3){
            System.out.println(Q2);
        }else if(Q3 <= Q1 && Q3 <= Q2){
            System.out.println(Q3);
        }

    }
}

Measured memory_bytes: 22740
n , x , m = map(int,input().split())
amari = [-1 for i in range(m)]
amari[x] = 0
cou = 0
now = x
p = 0
zyun = [x]
while True:
    nex = (now**2) % m
    if nex == 0:
        p = 1
        break
    elif amari[nex] == -1:
        amari[nex] = amari[now] + 1
        now = nex
        zyun.append(nex)
    elif amari[nex] != -1:
        p = 2
        break

if p == 1:
    ans = 0
    for i in range(m):
        if amari[i] != -1:
            ans += i
    print(ans)
elif p == 2:
    ans = 0
    ans += sum(zyun[:amari[nex]])
    ans += sum(zyun[amari[nex]:]) * ((n-amari[nex])//(amari[now]-amari[nex]+1))
    y = (n-amari[nex]) % (amari[now]-amari[nex]+1)
    if y != 0:
        ans += sum(zyun[amari[nex]:amari[nex]+y])
    print(ans)

Measured memory_bytes: 73540
#include<iostream>
using L=int;using namespace std;
#define R for(L i=H;i>=0;i--)
#define P for(L j=0;j<N;j++)
#define D d[max(i-A[j],0)]
L H,N,A[1005],B[1005],d[30004]={};main(){cin>>H>>N;P cin>>A[j]>>B[j];R d[i]=1e9;d[H]=0;R P D=min(D,d[i]+B[j]);cout<<d[0];} 

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
using ll = long long int;

int main()
{
	ll x, k, d;
	cin >> x >> k >> d;
	if(x < 0LL) x = -x;
	ll s = x / d;
	if(s > k) s = k;
	x -= (s * d);
	k -= s;
	cout << (k % 2 == 0 ? x : abs(x - d)) << endl;
	return 0;
}

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

int main(){
    int a,b;
    vector<long long int>c(100);
    cin>>a>>b>>c[0];
    for(int i=0;i<10;i++){
    	c[i+1]=a*c[i]-b;
    	cout<<c[i+1]<<endl;
    }
    
   return 0;
}

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

bool compare(pair<int,string> &a,pair<int,string> &b){
    return a.first > b.first;
}

int main() {
    
    int N,K;
    cin >> N >> K;
    int R,S,P;
    cin >> R >> S >> P;
    // vector<pair<int,string>> vec;
    // vec.push_back(make_pair(R,"r"));
    // vec.push_back(make_pair(S,"s"));
    // vec.push_back(make_pair(P,"p"));
    
    //sort(vec.begin(),vec.end(),compare);
    
    string T;
    cin >> T;
    
    vector<int> DP(T.size()+1,0);
    DP[0] = 0;
    map<int,string> mp;
    for(int i = 0; i < T.size();i++){
        
        if(T.substr(i,1)=="r"&&mp[i-K]!="P"){
            DP[i+1] = max(DP[i]+P,DP[i+1]);
            mp[i]="P";
        }else if(T.substr(i,1)=="s"&&mp[i-K]!="R"){
            DP[i+1] = max(DP[i]+R,DP[i+1]);
            mp[i]="R";
        }else if(T.substr(i,1)=="p"&&mp[i-K]!="S"){
            DP[i+1] = max(DP[i]+S,DP[i+1]);
            mp[i]="S";
        }else{
            DP[i+1] = DP[i];
        }
        
    }
    
    cout << DP[T.size()]<<endl;
    
    
}

Measured memory_bytes: 16768
N,M=map(int,input().split())
gridA=[None]*N
gridB=[None]*M
for i in range(N):
  gridA[i]=input()
for i in range(M):
  gridB[i]=input()

def isMatch(y,x):
  for i in range(M):
    for j in range(M):
      if gridB[i][j]!=gridA[y+i][x+j]:
        return False
  return True

for i in range(N-M+1):
  for j in range(N-M+1):
    if isMatch(i,j):
      print("Yes")
      exit(0)
print("No")
  

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


int main() {
  int a,b; cin >> a >> b;
  if(a!=1&&b!=1){
    if(a<b){
      cout << "Bob" << endl;
    }
    else if(a==b){
      cout << "Draw" << endl;
    }
    else{
      cout << "Alice" << endl;
    }
  }
  else if(a==1&&b==1){
    cout << "Draw" << endl;
  }
  else if(a==1){
    cout << "Alice" << endl;
  }
  else{
    cout << "Bob" << endl;
  }
}
      
  

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, int> LP;
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; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int k, n;
	cin >> k >> n;
	vector<int> a(n+1);
	rep(i,n) cin >> a[i];
	a[n] = k + a[0];
	int mx = 0;
	rep(i,n) chmax(mx, a[i+1] - a[i]);
	int ans = k - mx;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3980
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#include<algorithm>//next_permutation
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
#define dec(n) cout << fixed << setprecision(n);
#define large "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
#define small "abcdefghijklmnopqrstuvwxyz"
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;

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

const ll MOD = 1000000007;
const ll MAX = 2000001;

ll mod(ll a){
  return a % MOD;
}

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

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

void nCrprep() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll 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;
    }
}

ll nCr(ll n, ll r){
    if (n < r) return 0;
    if (n < 0 || r < 0) return 0;
    return fac[n] * (finv[r] * finv[n - r] % MOD) % MOD;
}

ll nCrcheep(ll n,ll r){
  if(r == 0) return 1;
  else if(r == 1) return n;
  else return nCrcheep(n-1,r-1)*n/r;
}

vector<pair<ll,ll>> prime_factorize(ll n){
  vector<pair<ll,ll>> res;
  
  for(ll i=2; i*i <= n; i++){
    if(n % i != 0) continue;
    
    ll ex = 0;
    while(n % i == 0){
      ex++;
      n /= i;
    }
    
    res.push_back({i,ex});
  }
  
  if(n != 1) res.push_back({n,1});
  
  return res;
  
}




int main(){
  string s,t; cin >> s >> t; bool flag = false;
  ll ss = s.size(); ll ts = t.size();
  
  for(ll i=ss-ts; i >= 0; i--){
    flag = true;
    for(ll j=0; j < ts; j++){
      if(s[i+j] != t[j] and s[i+j] != '?'){
        flag = false;
        break;
      }
    }
    
    if(flag){
      for(ll j=0; j < ts; j++){
        s[i+j] = t[j];
      }
      break;
    }
  }
  
  if(flag){
    rep(i,ss){
      if(s[i] == '?') s[i] = 'a';
    }
    
    cout << s << endl;
  }
  else cout << "UNRESTORABLE" << endl;
  
}

Measured memory_bytes: 3620
#include <stdio.h>

int main(void){
	char s[2];
	int a = 0,b = 0,x = 0,i = 0;
	scanf("%d""%d""%d",&a,&b,&x);
	i =x - a;
	if(i<=b && a <= x)
		printf("YES\n");
	else
		printf("NO\n");
	
		return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>
using namespace std;

#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

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; }
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; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }


long long solve(long long a) {
    long long res = 0;
    for (long long d = 60; d >= 1; --d) {
        if (a & (1LL<<d)) {
            if (a % 2 == 0) res += (1LL<<d);
        }
    }
    if ( ((a+1)/2) % 2 == 0 ) res ^= 1;
    return res;
}

int main() {
    long long A, B;
    while (cin >> A >> B) {
        cout << (solve(B) ^ solve(A-1)) << endl;
    }
}














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

int main(){
  int a, b;
  cin >> a >> b;
  int ans;
  if (a < 10 && b < 10) ans = a * b;
  else ans = -1;
  cout << ans;
}

Measured memory_bytes: 256
/*
 Abu Jafor Mohammad Saleh
 ios_base :: sync_with_stdio(false);
 cin.tie(NULL);
 
 */

#include<cstdio>
#include<iomanip>
#include<sstream>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<algorithm>
#include<set>
#include<queue>
#include<deque>
#include<stack>
#include<list>
#include<iostream>
#include<fstream>
#include<numeric>
#include<string>
#include<vector>
#include<cstring>
#include<map>
#include<iterator>
#include<limits>
#include <algorithm>
#include <unordered_map>
#include<fstream>
#define f first
#define s second
#define MOD 1000003

#define INF (int)1e9
#define PI 3.1415926535897932384626433832795
#define BOUNDARY(i, j) ((i >= 0 && i < rows) && (j >= 0 && j < coloums))

//#include<bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long
const int maxn = 100001;
using namespace std;
int X[] = {0, 1, 0, -1};
int Y[] = {-1, 0, 1, 0};
int rows,coloums;
long long  gcd(long long  a, long long b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}


int main()
{
    fast;
    ll a;
    cin>>a;
    ll ans = ((a/500)*1000) + (((a%500)/5)*5);
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
	int s[10000], t[500];
	int i, j;
	int n, m, count = 0;

	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		scanf("%d", &s[i]);
	}

	scanf("%d", &m);
	for (i = 0; i < m; i++) {
		scanf("%d", &t[i]);
		for (j = 0; j < n; j++) {
			if (t[i] == s[j]) {
				count++;
				break;
			}
		}
	}

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

	return 0;
}



Measured memory_bytes: 1992
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<string>
using namespace std;
int main() {
	int n; cin >> n;
	vector<int> a(n - 1);
	vector<int> ans(n);
	for (int i = 0; i < n - 1; i++) {
		cin >> a.at(i);
		ans.at(a.at(i) - 1)++;
	}
	for (int i = 0; i < n; i++) {
		cout << ans.at(i) << endl;
	}
}

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

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

int main() {
  int a, b;
  cin >> a >> b;
  if (a > b) cout << "a > b" << endl;
  if (a < b) cout << "a < b" << endl;
  if (a == b) cout << "a == b" << endl;
  return 0;
}



Measured memory_bytes: 3080