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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define ll long long
#define pii pair<int,int>
#define all(x) begin(x), end(x)
#define loop(i,n) for(int i=0; i<n; i++)
#define rep(i,a,b,c) for(int i=a; i<b; i+=c)
#define brep(i,a,b,c) for(int i=a; i>b; i-=c)
#define tc(t) int t; cin>>t; while(t--)
#define sz(v) int((v).size())
#define pb push_back


using namespace std;

void __print(int x) {cout << x;}
void __print(long x) {cout << x;}
void __print(long long x) {std::cout << x;}
void __print(unsigned x) {std::cout << x;}
void __print(unsigned long x) {std::cout << x;}
void __print(unsigned long long x) {std::cout << x;}
void __print(float x) {std::cout << x;}
void __print(double x) {std::cout << x;}
void __print(long double x) {std::cout << x;}
void __print(char x) {cout << '\'' << x << '\'';}
void __print(const char *x) {cout << '\"' << x << '\"';}
void __print(const string &x) {cout << '\"' << x << '\"';}
void __print(bool x) {cout << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cout << '{'; __print(x.first); cout << ','; __print(x.second); cout << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cout << '{'; for (auto &i : x) cout << (f++ ? "," : ""), __print(i); cout << "}";}
void _print() {cout << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cout << ", "; _print(v...);}
template <typename T> inline void inp(T &any) {cin >> any;} template <typename T, typename... U>inline void inp(T &a, U &...b) {cin >> a; inp(b...);}
#define rin(args...) ll args; inp(args);
#ifndef ONLINE_JUDGE
#define debug(x...) cout << "[" << #x << "] = ["; _print(x)
#define matdeb(mat,row,col) cout << #mat << "::" << endl; printmat(mat,row,col); printpartition;
#define debugv(v,n) cout << #v << ":" << endl; printv(v,0,n-1); printpartition;
#else
#define debug(x...)
#define matdeb(mat,row,col)
#define debugv(v,n)
#endif

const int maxm = 1000000000 + 7;

double startTime;
double getCurrentTime() {
	return ((double)clock() - startTime) / CLOCKS_PER_SEC;
}


//----------->CODE BEGINS --------------->


int main()
{

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	ll n;
	cin >> n;

	ll a[n];

	int ans = 100;

	

	loop(i, n)
	{
		cin >> a[i];

		int cnt = 0;

		while(a[i]%2 == 0)
    	{
    		a[i] /= 2;
    		cnt++;
    	}

    	ans = min(ans,cnt);
	}
   
    
   cout<<ans<<endl;



}


Measured memory_bytes: 3616
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func Scan() string {
	sc.Scan()
	return sc.Text()
}

func iScan() int {
	n, _ := strconv.Atoi(Scan())
	return n
}

func fScan() float64 {
	n, _ := strconv.ParseFloat(Scan(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func SScan(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scan()
	}
	return a
}
func iSScan(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = iScan()
	}
	return a
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func sum(a []int) int {
	x := 0
	for _, v := range a {
		x += v
	}
	return x
}

var mod int = 1000000007

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	n := iScan()
	h := iSScan(n)
	mx := h[0]
	ans := 1
	for i := 1; i < n; i++ {
		if h[i] >= mx {
			mx = h[i]
			ans++
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 1776
import java.util.*;
public class Main {
   public static void main(String[] args) {
      Scanner sc = new Scanner(System.in);

      int n = sc.nextInt();

      int[] a = new int[n];
      for (int i = 0; i < a.length; i++) {
         a[i] = sc.nextInt();
      }

      int sum = 0;

      for (int i = 0; i < n - 1; i++) {
         sum = sum + Math.abs(a[i] - a[i + 1]);
      }
      sum = sum + Math.abs(a[0]) + Math.abs(a[n - 1]);

      System.out.println(sum - Math.abs(a[0]) - Math.abs(a[0] - a[1]) + Math.abs(a[1]));

      for (int i = 1; i < n - 1 ; i++) {
         int suma = sum - Math.abs(a[i] - a[i - 1]) - Math.abs(a[i] - a[i + 1]) + Math.abs(a[i - 1] - a[i + 1]);
         System.out.println(suma);
      }

      System.out.println(sum - Math.abs(a[n - 1]) - Math.abs(a[n - 1] - a[n - 2]) + Math.abs(a[n - 2]));

   }
}

Measured memory_bytes: 64528
//Let's join Kaede Takagaki Fan Club !!
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
#define all(x) x.begin(),x.end()
template<class T>
void dmp(T a){
	rep(i,a.size()) cout << a[i] << " ";
	cout << endl;
}
template<class T>
bool chmax(T&a, T b){
	if(a < b){
		a = b;
		return 1;
	}
	return 0;
}
template<class T>
bool chmin(T&a, T b){
	if(a > b){
		a = b;
		return 1;
	}
	return 0;
}
template<class T>
void g(T &a){
	cin >> a;
}
template<class T>
void o(const T &a,bool space=false){
	cout << a << (space?' ':'\n');
}
//ios::sync_with_stdio(false);
const ll mod = 1000000007;//998244353
template<class T>
void add(T&a,T b){
	a+=b;
	if(a >= mod) a-=mod;
}

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

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
   vector<int> data(N);
  for(int i=0;i<N;i++){
    int a;
    cin >> a;
  data.at(i) = a; 
  
  }
  sort(data.begin(), data.end());
  reverse(data.begin(), data.end());
  
  int Alice =0;
  int Bob = 0;
  int answer = 0;
  
   for(int i=0;i<N;i++){ 
    if(i%2 == 0){
    Alice = Alice + data.at(i);   
    }else{
     Bob = Bob + data.at(i);
    }
  }  
  answer = Alice - Bob;
  cout << answer << endl;
  
}

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

// #define int long long
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;

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; }

const ll INF = 1e15;
const int MOD = 1e9+7;
const ll LINF = 1e18;

ll n,m,s,t;
vpll G[200005];
ll dist[200005];

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  cin>>n>>m>>s>>t; s--,t--;
  rep(i,m){
    ll u,v,a,b; cin>>u>>v>>a>>b; u--,v--;
    G[u].emplace_back(v,a);
    G[v].emplace_back(u,a);
    G[u+n].emplace_back(v+n,b);
    G[v+n].emplace_back(u+n,b);
  }
  
  rep(i,200005) dist[i]=LINF;
  dist[s]=dist[t+n]=0;
  priority_queue<pll, vector<pll>, greater<pll>> q;
  q.emplace(0,s);
  q.emplace(0,t+n);
  
  while(!q.empty()){
    auto p=q.top(); q.pop();
    ll v=p.second, c=p.first;
    if(dist[v]<c) continue;
    for(auto np: G[v]){
      ll nv=np.first, nc=np.second;
      if(chmin(dist[nv],dist[v]+nc)){
        q.emplace(dist[nv],nv);
      }
    }
  }
  
  vll ans(n);
  ll base=1e15;
  ll res=0;
  rrep(i,n){
    ll tmp=base-(dist[i]+dist[n+i]);
    chmax(res,tmp);
    ans[i]=res;
  }
  rep(i,n) cout<<ans[i]<<endl;
  
}

Measured memory_bytes: 20984
#include <iostream>
#include <algorithm>
#include <cstdint>

int main() {
	std::int64_t h, w;
	std::cin >> h >> w;

	if (h == 1 || w == 1)
		std::cout << 1 << std::endl;
	else
		std::cout << ((h + 1) / 2) * (w / 2 + (w % 2)) + (h / 2) * (w / 2) << std::endl;
}

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

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


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

int main() {
    int H, W;
    std::cin >> H >> W;

    for (int i = 0; i < H; ++i) {
        char c[W];
        for (int j = 0; j < W; ++j) {
            std::cin >> c[j];
            std::cout << c[j];
        }

        std::cout << "\n";

        for (int j = 0; j < W; ++j) {
            std::cout << c[j];
        }

        std::cout << std::endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main()
{
	
	int a, b;
	int temp;
	int big, small;
	
	while(cin>>a>>b){
		
		if(a < b){
			big = b;
			small = a;
		}
		else{
			big = a;
			small = b;
		}
		
		for(;;){
			temp = big % small;
			if(temp == 0){
				break;
			}
			if(temp > small){
				big = temp;
			}
			else{
				big = small;
				small = temp;
			}
		}
		cout << small <<" "<< a/small*b << endl;
	}
}
		
		

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

using namespace std;
const int U = 100003;
typedef pair<int,int> P;
int n;
P a[U],b[U];
int kakunin[2][100000];

bool ch(int d){
	memset(kakunin,0,sizeof(kakunin));
	kakunin[0][a[0].second] = 2;
	int up = a[0].first,un = a[n-1].first;
	for(int i = 0;i < n;i++){
		if(abs(up-a[i].first) > d && abs(un-a[i].first) > d){
			return false;
		}
		if(abs(up-a[i].first) > d){
			kakunin[0][a[i].second] = 1;
		}
		if(abs(un-a[i].first) > d){
			kakunin[0][a[i].second] = 2;
		}
	}
	kakunin[1][b[0].second] = 2;
	up = b[0].first,un = b[n-1].first;
	for(int i = 0;i < n;i++){
		if(abs(up-b[i].first) > d && abs(un-b[i].first) > d){
			return false;
		}
		if(abs(up-b[i].first) > d){
			kakunin[1][b[i].second] = 1;
		}
		if(abs(un-b[i].first) > d){
			kakunin[1][b[i].second] = 2;
		}
	}
	int di = 0,bo = 0;
	for(int i = 0;i < n;i++){
		if(kakunin[0][i] == 0 || kakunin[1][i] == 0)bo++;
		else if(kakunin[0][i] != kakunin[1][i])di++;
	}
	return (di == 0 || bo + di == n);
}

int main(){
	scanf("%d",&n);
	for(int i = 0;i < n;i++){
		int x,y;
		scanf("%d%d",&x,&y);
		a[i] = (P(x+y,i));
		b[i] = (P(x-y,i));
	}
	sort(a,a+n);
	sort(b,b+n);
	int lb = 0,ub = 1000000;
	while(ub - lb > 1){
		int mid = (lb + ub) / 2;
		if(ch(mid))ub = mid;
		else lb = mid;
	}
	printf("%d\n",ub);
	return 0;
}


Measured memory_bytes: 3544
#include<bits/stdc++.h>
using namespace std;
const int N = 205;
const int maxS = 40005;
long long f[2][2*maxS],n,m,a[N];
const int MOD =1e9+7;
void init()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    freopen("AVERAGE.inp","r",stdin);
    freopen("AVERAGE.out","w",stdout);
}
void nhap()
{
    cin >> n >> m;
    for (int i=1; i<=n; i++) {
        cin >> a[i];
        a[i] -= m;
    }
}
void xuli()
{
    memset(f,0,sizeof(f));
    f[0][maxS] = 1;
    for (int i = 1; i<=n; i++) {
        for (int j = 0; j<=2*maxS-a[i]; j++) {
             f[1][j] += f[0][j];
             f[1][j+a[i]] += f[0][j];
        }
        for (int j = 0; j<2*maxS; j++) {
            f[0][j] = f[1][j];
            f[1][j] = 0;
        }
    }
    cout << f[0][maxS] - 1  << '\n';
}
int main()
{
        nhap();
        xuli();

}


Measured memory_bytes: 1536
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？

w,h,x,y=mii()

ans=w*h/2
ans1=0
if x*2==w and y*2==h:
    ans1=1
print(ans,ans1)


Measured memory_bytes: 63468
#include <bits/stdc++.h>
using namespace std;
const int inf = 2e9;
const int N = 1e5 + 5;
int dp[N];
int arr[N];
int main() {
	int n, k;
	cin >> n >> k;
	for (int i = 0; i < N; i++) {
		dp[i] = inf;
	}
	for (int i = 0; i < n; i++) {
		cin >> arr[i];
	}
	dp[0] = 0;
	for (int i = 1; i < n; i++) {
		for (int j = 1; j <= k; j++) {
			if (i - j >= 0) {
				dp[i] = min(dp[i], abs(arr[i] - arr[i - j]) + dp[i - j]);
			}
		}
	}
	cout << dp[n - 1];
	return 0;
}


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

#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define int  long long
#define rep(i,a,b)    for(int i=a;i<b;i++)
#define repn(i,a,b)   for(int i=a;i>=b;i--)
#define F first
#define S second
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define pb push_back
#define mp  make_pair
#define all(v) (v).begin(), (v).end()
#define pie 3.14159265358
#define mod2 998244353

 // lcm+min(a,b)
void solve(){   
    int n,k;cin>>n>>k;
    vi a(n);
    int ans=n;
    rep(i,0,k){
        int d;cin>>d;
        rep(i,0,d){
            int temp;cin>>temp;
            if(a[temp-1]==0)ans--;
            a[temp-1]=1;
        }
    }
    cout<<ans;
    return;
} 

signed main(){
    IOS;

    int n=1; 
     // cin>>n; 
    rep(i,0,n)solve();
    
    return 0;
}

Measured memory_bytes: 3652
#include<iostream>

using namespace std;

int main()
{
	while (1){
		int kaisu, ten1 = 0, ten2 = 0;
		cin >> kaisu;
		if (kaisu == 0)break;
		while (kaisu--)
		{
			int x, y;
			cin >> x >> y;
			if (x > y)
			{
				ten1 += x + y;
			}
			else if (x < y)
			{
				ten2 += x + y;
			}
			else
			{
				ten1 += x;
				ten2 += y;
			}
		}
		cout << ten1 << " " << ten2 << endl;;
	}
	return 0;
}

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

int main()
{
    int n;
    cin >> n;
    long long int ara[n];
    long long ans = numeric_limits<long long>::max(), cnt = 0;
    long long sum = 0, prev = 0;
    for(int i = 0; i<n; i++)
    {
        scanf("%lld", &ara[i]);
        prev = sum;
        sum += ara[i];
        if(i%2==0){
            if(sum>=0) cnt += (prev + ara[i]) + 1, sum = -1;
        }
        else{
            if(sum<=0) cnt += abs(ara[i] + prev - 1) , sum = 1;
        }

    }
    ans = cnt;
    sum = 0, cnt = 0;
    for(int i = 0; i<n; i++)
    {
        prev = sum;
        sum += ara[i];
        if(i%2==1){
            if(sum>=0) cnt += (prev + ara[i]) + 1, sum = -1;
        }
        else{
            if(sum<=0) cnt += abs(ara[i] + prev - 1) , sum = 1;
        }

    }
    ans = min(ans, cnt);
    cout << ans << endl;
    return 0;

}


Measured memory_bytes: 1024
program main
  implicit none

  integer n
  real kt

  read(*,*)n
  kt = log10(real(n))
  
  if (kt < 1) then
    write(*,*)n
    stop
  else if (kt < 2) then
    write(*,*)9
    stop
  else if (kt < 3) then
    write(*,*)9 + n - 100 + 1
    stop
  else if (kt < 4) then
    write(*,*)909
    stop
  else if (kt < 5) then
    write(*,*)909 + n - 10000 + 1
    stop
  else
    write(*,*)90909
  end if
end program main


Measured memory_bytes: 256
/* AOJ 0047
 *
 * http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0047
 *
 */

#include <stdio.h>
#define DEBUG 0

int main(){
    char input[30];
    int i;
    int from, to, tmp;
    int buf[3];

    buf[0] = 1;
    buf[1] = 0;
    buf[2] = 0;
    
    while(scanf("%s", input) ==1){
        if(DEBUG)
            printf("%s\n",input);
        from = input[0] - 'A';
        to = input[2] - 'A';
        tmp = buf[to];
        buf[to] = buf[from];
        buf[from]=tmp;
    }

    for(i=0;i<3;i++){
        if(buf[i])
            break;
    }
    printf("%c\n", 'A'+i);
    return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
/*bool is(long long a){
    if(a==2) return true;
    if(a<=1||a%2==0) return false;
    for(int i=3;i*i<=a;i+=2){
        if(a%i==0) return false;
    }
    return true;
}*/
long long gcd(long long a,long long b){
    if(b==0) return a;
    return gcd(b,a%b);
}
long long lcm(long long a,long long b){
    return(a/gcd(a,b)*b);
}
int main(){
    int n;
    cin>>n;
    long long z[n];
    cin>>z[0];
    for(int i=1;i<n;i++){
        cin>>z[i];
        z[i]=lcm(z[i-1],z[i]);
    }
    cout<<z[n-1]<<'\n';
    return 0;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <iostream>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <iomanip>
#include <math.h>
#include <time.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define repf(i, a, b) for (int i = (int)a; i < (int)b; i++)
#define repr(i, a, b) for (int i = (int)a; i > (int)b; i--)
#define all(v) (v).begin(), (v).end()
#define mp(a, b) make_pair(a, b)
#define pb(x) push_back(x)
#define eb(x) emplace_back(x)
#define F first
#define S second
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<int> vii;
typedef vector<vii> vvii;
const ll mod = 1e9 + 7;
const int infi = 1147483600;
const ll infl = 1e18 + 5;
const char ENDL = '\n';
//cout << fixed << setprecision(17) << res << endl;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll n;cin>>n;
    ll one=n*(n+1)/2;
    ll al=0;
    vll a(n);
    rep(i,n){
        cin>>a[i];
        al+=a[i];
    }
    ll time=al/one;
    if (al%one){
        cout<<"NO"<<ENDL;
        return 0;
    }
    int cnt=0;
    a.eb(a[0]);
    rep(i,n){
        ll now=a[i+1]-a[i]-time;
        if (now%n || now>0){
            cout<<"NO"<<ENDL;
            return 0;
        }
        now*=-1;
        cnt+=(now/n);
    }
    if (cnt==time){
        cout<<"YES"<<ENDL;
    }
    else{
        cout<<"NO"<<ENDL;
    }
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define int long long
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, h, w;
    cin >> n >> h >> w;
    int ans = 0;
    for(int i = 0; i < n; i++){
        int a, b;
        cin >> a >> b;
        if(h <= a && w <= b) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/range/adaptor/reversed.hpp>

using namespace std;
typedef long long int ll;

#define PI (acos(-1))
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define dumparr(x) cerr << #x ; for(auto elem: x){cerr << " " << elem;} cerr << endl;
#define dumppairs(x) cerr << #x ; for(auto elem: x){cerr << "(" << elem.first << " " << elem.second << ") ";} cerr << endl;
#define dumpline cerr << "**********************" << endl;
#define dumpwline(x) cerr << "******** " << #x << "=" << (x) << " ********" << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

struct num{
    ll idx;
    ll val;
    bool operator<(const num &o) const
    {
        return val < o.val;
    }
};


int main(void){
    ll n; cin >> n;
    vector <ll> as;
    REP(i, n){
        ll a; cin >> a; as.push_back(a);
    }
    priority_queue <num> bs_q;
    vector <ll> bs;
    REP(i, n){
        ll b; cin >> b;
        num nu = {i, b};
        bs_q.push({nu});
        bs.push_back(b);
    }
    ll ans = 0;
    ll cnt = 0;
    while(!bs_q.empty()){
        cnt ++;
        num top = bs_q.top();
        bs_q.pop();
        ll idx = top.idx;
        if (as[idx] == top.val) {
            continue;
        }
        ll diff = bs[(idx+n-1)%n] + bs[(idx+n+1)%n];
        ll diff2 = min(top.val - max(bs[(idx+n-1)%n], bs[(idx+n+1)%n]), top.val - as[idx]);
        ll sub_cnt = max(ll(1), (diff2/diff));
        top.val -=  sub_cnt * diff;
        if (as[idx] > top.val){
            cout << -1 << endl;
            return 0;
        }
        bs[idx] = top.val;
        ans += sub_cnt;
        if (as[idx] == top.val) {
            continue;
        }
        bs_q.push(top);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 10604
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>
#include <assert.h>
#include <unordered_set>
#include <random>



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

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)










int main(){
    ll n, k;
    cin >> n >> k;
    
    vector<ll> cnt(100000);
    ll itr = 0;
    for(ll i = 1; i <= n; ){
        ll t = n / i;
        if(i <= t){
            cnt[itr++] = 1;
            i++;
        }
        else{
            cnt[itr++] = n / t - i + 1;
            i = n / t + 1;
        }
    }
    
    vector<ll> dp(100000);
    dp[0] = 1;
    REP(i, k){
        vector<ll> tmp(100000);
        for(ll j = 0; j < itr; j++){
            tmp[j + 1] = (tmp[j] + dp[j]) % MOD;
        }
        for(ll j = 0; j < itr; j++){
            dp[j] = (tmp[itr - j] * cnt[j]) % MOD;
        }
    }
    
    ll ans = 0;
    for(ll i = 0; i < itr; i++){
        ans += dp[i];
        ans %= MOD;
    }
    cout << ans << endl;
}

Measured memory_bytes: 2560
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
#include <map>
#include <unordered_map>
#include <chrono>
#include <numeric>
#include <set>
using namespace std;
using ll = long long;
const ll INF = (ll)1e18+1;
const ll DIV = 1000000007;
//#define TEST

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
#ifdef TEST
    chrono::system_clock::time_point start, end;
    start = chrono::system_clock::now();
#endif
    long N;
    cin >> N;
    vector<vector<long>> Graph(N);
    long a[N-1], b[N-1];
    //辺ごとの色を登録
    vector<long> color(N);
    for(size_t i=0;i<N-1; i++)
    {
        cin >> a[i] >> b[i]; a[i]--;b[i]--;
        //各頂点の持つ辺を登録する
        Graph[a[i]].push_back(i);
        Graph[b[i]].push_back(i);
    }
    ll max_color = 0;
    for(auto v: Graph)
    {
        max_color = max(max_color, (ll)v.size());
    }
    cout << max_color << endl;

    for(size_t i=0;i<N; i++)
    {
        set<ll> s;
        //頂点 Graph[i] の持つ辺が既に別の頂点によって塗られている場合はその色を保持しておく
        for(auto e : Graph[i]) if(color[e] != -1) s.insert(color[e]);
        ll count = 1;
        for(auto e : Graph[i]){
            if(color[e] == 0){
                //頂点 Graph[i] の持つ各辺について色を塗っていく
                //色は小さな数から順に塗っていくが既に塗られている場合は新たな色を割り当てる
				while(s.count(count)) count++;
				s.insert(count);
                //辺eを塗る
				color[e] = count;
			}
		}
    }
    for(int i=0;i<N-1;i++) cout << color[i] << endl;

#ifdef TEST
    end = chrono::system_clock::now();
    cerr << static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count() / 1000.0) << "[ms]" << endl;
#endif
    return 0;
}

Measured memory_bytes: 8832
#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 FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
//const ll mod = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }



int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(25);

  int n;
  cin >> n;
  vector<int> x(n);
  rep(i, n) cin >> x[i];

  map<int, ll> mp;
  mp[0] = 1;
  x[0] = 1;
  int res = 0;
  FOR(i, 1, n) {
    mp[res]++;
    if (x[i] - x[i - 1] == 1) {
      res++;
      x[i] = x[i - 1];
    }
    chmin(x[i], x[i - 1] + 2);
  }
  ll ans = 1, cnt = 0;
  rep(i, n) {
    cnt += mp[i];
    ans = ans * cnt % mod;
    cnt--;
  }
  cout << ans << '\n';








  
  return 0;
}

Measured memory_bytes: 6912
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

const int MAX_N = 1e5 + 5;
const int MAX_L = 20; // ~ Log N
const long long MOD = 1e9 + 7;
const long long INF = 1e9 + 7;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<vi> vvi;

#define rep(i,n) for (i = 0; i < n; ++i)
#define REP(i,k,n) for (i = k; i <= n; ++i)
#define REPR(i,k,n) for (i = k; i >= n; --i)

#define LSOne(S) (S & (-S))
#define isBitSet(S, i) ((S >> i) & 1)


void solve() {
    int n, x, t;
    cin >> n >> x >> t;
    cout << ((n-1) / x +1) * t;
}

//#define LOCAL 1

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

#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    solve();

    return 0;
}

Measured memory_bytes: 3652
import sys
N, K = map(int, input().split())

AB = []
for _ in range(N):
    AB.append([int(s) for s in input().split()])

ans = 0
kbin = bin(K)[2:]
for a, b in AB:
    if K | a == K:
        ans += b
for i in range(1, len(kbin)):
    if kbin[i - 1] == "0":
        continue
    kl = list(kbin)
    kl[i - 1] = "0"
    for j in range(i, len(kbin)):
        kl[j] = "1"
    km = int("".join(kl), 2)
    anscand = 0
    for a, b in AB:
        if km | a == km:
            anscand += b
    if ans < anscand:
        ans = anscand
print(ans)


Measured memory_bytes: 61400
def spin(pazzule):
    pzl = [["" for i in range(8)] for j in range(8)]
    for i in range(8):
        for j in range(8):
            pzl[i][j] = pazzule[7-j][i]
    return pzl
    
pazzule = [list(input()) for i in range(8)]
pazzule = spin(pazzule)
print("90")
for i in range(8):
    print("".join(pazzule[i]))
print("180")
pazzule = spin(pazzule)
for i in range(8):
    print("".join(pazzule[i]))
print("270")
pazzule = spin(pazzule)
for i in range(8):
    print("".join(pazzule[i]))


Measured memory_bytes: 5564
# ABC088D - Grid Repainting
import sys
input = sys.stdin.readline

def bfs() -> None:
    q = [(0, 0)]
    while q:
        x, y = q.pop(0)
        for dx, dy in dxy:
            nx, ny = x + dx, y + dy  # next x, y
            if 0 <= nx < H and 0 <= ny < W and S[nx][ny] == "." and dist[nx][ny] == 0:
                q.append((nx, ny))
                dist[nx][ny] = dist[x][y] + 1


def main():
    global H, W, S, dist, dxy
    H, W = tuple(map(int, input().split()))
    S = tuple(input().rstrip() for _ in range(H))
    dist = [[0] * W for _ in range(H)]  # distance from (0, 0) to (x, y)
    dist[0][0] = 1
    dxy = [(1, 0), (-1, 0), (0, 1), (0, -1)]
    bfs()
    white, x = sum(s.count(".") for s in S), dist[-1][-1]
    ans = white - x if x else -1
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 3192
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <map>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<double, double, double> tddd;

void game(int, int);
int a,b,k;

int main(void){

  cin >> a >> b >> k;
  for(int i = 0;i < k; i++){
    if(i % 2 == 0){
      if(a % 2 == 0){
	int temp;
	temp = a/2;
	b += temp;
	a = temp;
      } else {
	int temp;
	temp = (a-1)/2;
	b += temp;
	a = temp;
      }
  
    } else {
      if(b % 2 == 0){
	int temp;
	temp = b/2;
	a += temp;
	b = temp;
      } else {
	int temp;
	temp = (b-1)/2;
	a += temp;
	b = temp;
      }
  
    }
  }

  cout << a << " " << b << endl;
  return 0;
}
void game(int n, int m){
  if(n % 2 == 0){
    int temp;
    temp = n/2;
    m += temp;
    n = temp;
  } else {
    int temp;
    temp = (n-1)/2;
    m += temp;
    n = temp;
  }
}

Measured memory_bytes: 256
#include <cstdio>

int main()
{
	int n, m, a;
	int *k;
	int *count;
	int count2 = 0;

	scanf("%d%d", &n, &m);

	k = new int[n];
	count = new int[m];
	for (int i = 0; i < m; i++)
	{
		count[i] = 0;
	}

	for (int i = 0; i < n; i++)
	{
		scanf("%d", &k[i]);
		for (int j = 0; j < k[i]; j++)
		{
			scanf("%d", &a);
			count[a - 1]++;
		}
	}

	for (int i = 0; i < m; i++)
	{
		if (count[i] == n) count2++;
	}

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

	delete[] k;
	delete[] count;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long lo;
typedef vector<lo> vl;
typedef vector<vl>vll;
#define all(v) (v).begin(), (v).end()
#define debug(x) cerr<<#x<<" = "<<x<<endl;
#define REPV(a, b, c) for (lo(a) = b; (a) < (c); (a)++) 
#define REP(a,b) for(lo i =(a) ;i<(b);i++)

template <typename T>

istream &operator>>(istream &in, vector<T> &v)
{
	for (unsigned i = 0; i < v.size(); i++)
		in >> v[i];
	return in;
}


void solve(){
	lo ans = 0;
		lo N; cin>>N;
		vl v(N); cin>>v;
		sort(v.begin(),v.end(),greater<lo>());
		int i=0;
		priority_queue<int>q;q.push(0);
		while(i<N){
			lo a = q.top();q.pop();
			ans+=a;
			q.push(v[i]);
			if(i!=0){
				q.push(v[i]);
			}
			i++;
		}

		cout<<ans<<endl;
}


int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cout.precision(20);
	solve();
	return 0;
}

Measured memory_bytes: 5748
import sys, bisect, math, itertools, string, queue, copy
# import numpy as np
# import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input()) # n=1
def inpm(): return map(int,input().split()) # x=1,y=2
def inpl(): return list(map(int, input().split())) # a=[1,2,3,4,5,...,n]
def inpls(): return list(input().split())  # a=['1','2','3',...,'n']
def inplm(n): return list(int(input()) for _ in range(n)) # x=[] 複数行
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)] # [[1,1,1,1],[2,2,2,2],[3,3,3,3]] 
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)]) # [[1,1,1,1],[2,2,2,2],[3,3,3,3]] 

def main():
    n,k= inpm()
    ans = 0
    while n > 0:
        n//=k
        ans += 1
    print(ans)
    
if __name__ == "__main__":
    main()




Measured memory_bytes: 39148
#include<bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define pb push_back
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};
 
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
int main(){
    int w,n;
    int a[50],b[50],ans[50];
    scanf("%d%d",&w,&n);
    REP(i,n)
        scanf("%d,%d",a + i,b + i);

    FOR(i,1,w + 1){
        int now = i;
        REP(j,n){
            if(now == a[j])
                now = b[j];
            else if(now == b[j])
                now = a[j];
        }
        ans[now] = i;
    }
    FOR(i,1,w + 1)
        printf("%d\n",ans[i]);
    return 0;
}

Measured memory_bytes: 3160
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  int n;
  cin >> n;
  multiset<ll> st;
  rep(i, n) {
    ll a;
    cin >> a;
    st.insert(a);
  }
  ll ans = 0;
  ll p2 = pow(2, 34);
  while(!st.empty()) {
    auto it = st.end();
    it--;
    ll p = p2;
    while(p > *it) {
      p /= 2;
      auto jt = st.lower_bound(p - *it);
      if(jt == it || jt == st.end() || *jt != p - *it) continue;
      st.erase(jt);
      ans++;
      break;
    }
    st.erase(it);
  }
  cout << ans << endl;
}

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

using namespace std;

enum
{
  BLACK, WHITE
};

int N;
vector< int > g[100000];
int sub[100000];
int pa[100000];

int dfs(int idx, int par = -1)
{
  sub[idx]++;
  int visited = 0;
  for(auto &to : g[idx]) {
    if(par == to) continue;
    visited++;
  }
  if(visited == 0) return (BLACK);
  int bb = 0;
  for(auto &to : g[idx]) {
    if(par == to) continue;
    int get = dfs(to, idx);
    sub[idx] += sub[to];
    if(get == BLACK) ++bb;
  }
  if(bb >= 2) {
    cout << "First" << endl;
    exit(0);
  }

  if(sub[idx] % 2 == 0) return (WHITE);
  else return (BLACK);
}

int main()
{


  cin >> N;
  for(int i = 1; i < N; i++) {
    int a, b;
    cin >> a >> b;
    --a, --b;
    g[a].push_back(b);
    g[b].push_back(a);
  }

  if(N == 2) {
    cout << "Second" << endl;
    return (0);
  }

  if(dfs(0) == BLACK) {
    cout << "First" << endl;
  } else {
    cout << "Second" << endl;
  }

}

Measured memory_bytes: 6144
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = (0); i < (n); ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define DEBUG(val) cout << #val << " : " << val << endl
#define MOD 1000000007

int main() {
  int n;
  cin >> n;
  map<string, int> m;
  REP(i, n) {
    string s;
    cin >> s;
    m[s] = 1;
  }
  cout << m.size() << endl;
}

Measured memory_bytes: 19100
import java.util.Scanner;
 
public class Main {
	public static void main(String[]args) {
		try(Scanner scan = new Scanner(System.in)){
			
			int N = scan.nextInt();
			long[]A = new long[N];
			for(int i = 0;i<N;i++)A[i] = scan.nextInt();
			
			long [] D = new long[N];
			
			
			for(int i = 0;i<N;i++) {
				if(i%2==0) {
					D[0]+=A[i];
				}else {
					D[0]+=-A[i];
				}
			}
			
			D[N-1] = 2*A[N-1]-D[0];
			
			for(int i = N-2;i>=1;i--) {
				D[i] = 2*A[i]-D[i+1];
			}
			
			for(int i = 0;i<N;i++) {
				System.out.println(D[i]);
			}
			
			
		}
		
		
	}
		
 
}

Measured memory_bytes: 69736
/***********************************************
 *                                             *
 *   author: raghav_0901 (Raghav Dalmia)       *
 *   updated on: 27-06-2020,  6:44:02 pm IST   *
 *                                             *
\***********************************************/

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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define endl '\n'
#define f(i, begin, end) \
    for (__typeof(end) i = (begin); i != (end) - (begin > end); i += 1 - 2 * ((begin) > (end)))
#define ff(i, begin, end, fl) \
    for (__typeof(end) i = (begin); i != (end)(begin > end) && fl; i += 1 - 2 * ((begin) > (end)))

#define int long long int

const int mod = INT_MAX;

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

    int n, m, k;
    cin >> n >> m >> k;

    vector<int> a(n), b(m);
    for (int &i : a) cin >> i;
    for (int &i : b) cin >> i;
    for (int i = 1; i < n; i++) a[i] += a[i - 1];
    for (int i = 1; i < m; i++) b[i] += b[i - 1];
    int ans = 0;
    for (int i = 0; i < n; i++)
    {
        if (a[i] <= k)
        {
            int temp = k - a[i];
            int pos = upper_bound(b.begin( ), b.end( ), temp) - b.begin( );
            ans = max(ans, i + pos + 1);
        }
        else
            break;
    }
    int ans1 = upper_bound(b.begin( ), b.end( ), k) - b.begin( );
    int ans2 = upper_bound(a.begin( ), a.end( ), k) - a.begin( );
    ans = max(ans, max(ans1, ans2));
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 6356
#include <bits/stdc++.h>
#define int long long
#define ll long long
using ull = unsigned long long;
using namespace std;
const int INF = 1e10;
const int MOD = 1e9 + 7;
#define dump(x)                             \
    if (dbg) {                              \
        cerr << #x << " = " << (x) << endl; \
    }
#define overload4(_1, _2, _3, _4, name, ...) name
#define FOR1(n) for (ll i = 0; i < (n); ++i)
#define FOR2(i, n) for (ll i = 0; i < (n); ++i)
#define FOR3(i, a, b) for (ll i = (a); i < (b); ++i)
#define FOR4(i, a, b, c) for (ll i = (a); i < (b); i += (c))
#define FOR(...) overload4(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)(__VA_ARGS__)
#define FORR(i, a, b) for (int i = (a); i <= (b); ++i)
template <class T>
bool chmin(T& a, const T& b) {
    if (a > b) {
        a = b;
        return 1;
    } else
        return 0;
}
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    } else
        return 0;
}
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(), (v).end()
#define SZ(x) ((int)(x).size())
#define V vector<int>
//#define S set<int>
#define itn int
bool dbg = false;

int N, K;
int R, S, P;
string T;
int t[101010];
int dp[101010][5];
int scr[10];

void solve() {
    FOR(N) {
        if (T[i] == 'r') {
            t[i] = 2;
        } else if (T[i] == 's') {
            t[i] = 0;
        } else if (T[i] == 'p') {
            t[i] = 1;
        }
    }
    scr[0] = R;
    scr[1] = S;
    scr[2] = P;
    FOR(i, 0, N) {
        FOR(j, 0, 3) {
            int tmp = 0;
            if (i >= K) {
                chmax(tmp, dp[i - K][(j + 1) % 3] + (j == t[i] ? scr[j] : 0));
                chmax(tmp, dp[i - K][(j + 2) % 3] + (j == t[i] ? scr[j] : 0));
                chmax(tmp, dp[i - K][(j + 0) % 3]);
                dp[i][j] = tmp;
            } else {
                if (t[i] == j)
                    dp[i][j] = scr[j];
            }
        }
    }
    int ans = 0;
    for (int i = N - 1; i >= N - K; i--) {
        int tmp = 0;
        FOR(j, 0, 3) {
            chmax(tmp, dp[i][j]);
        }
        ans += tmp;
    }
    cout << ans << endl;
}

signed main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cin >> N >> K;
    cin >> R >> S >> P >> T;
    solve();
    return 0;
}


Measured memory_bytes: 5200
def root(x):
    if r[x] < 0:
        return x
    else:
        r[x] = root(r[x])
        return r[x]
def unite(x, y):
    x = root(x)
    y = root(y)
    if x != y:
        if r[x] > r[y]:
            x,y = y,x
        r[x] += r[y]
        r[y] = x
n,m = map(int,input().split())
r = [-1] * n
for i in range(m):
    a,b = map(int, input().split())
    a -= 1
    b -= 1
    unite(a,b)
ans = 0
for i in r:
    if i < 0:
        ans += 1
print(ans-1)

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

#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define debug(x)  cerr << #x << " = " << x << endl
using namespace std;

typedef long long ll;
typedef long double ld;
typedef string str;
typedef pair<ll, ll> pll;

const ld PI = 3.14159265359;

const ll MOD = (ll) 998244353ll;
const ll MAXN = (ll) 123456 + 10;
const ll INF = (ll) 2242545357980376863;
const ld EPS = (ld) 1e-8;

ll in[MAXN], dan[MAXN];

vector<ll> g[MAXN];

queue<ll> q;


pll DFS(ll node, ll par){
	ll ans = 0;
	ll far = node;
	pll res;
	for(auto adj : g[node]){
		if(adj == par) continue;
		res = DFS(adj, node);
		if(ans == res.S + 1){
			if(res.F < far) far = res.F;
		}
		if(ans < res.S + 1){
			ans = res.S + 1;
			far = res.F;
		}
	}
	return {far, ans};
}

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

	ll n, m;
	cin >> n;
	ll e = n - 1;
	ll u, v;
	for(int i = 1; i < n; i++){
		cin >> u >> v;
		g[u].pb(v);
		g[v].pb(u);
	}
	pll res = DFS(1, -1);
	pll ans = DFS(res.F, -1);
	//debug(ans.S);
	//cout << min(res.F, ans.F) << endl;
	//cout << 2 * e - ans.S;
	ll d = ans.S;
	ll rem = (d - 1) % 3;
	if(rem == 0) cout << "Second";
	else cout << "First";
	return 0;
}


/*

                                 ____              ,----..               ,----..
   ,---,                       ,'  , `.           /   /   \             /   /   \
  '  .' \                   ,-+-,.' _ |          /   .     :           /   .     :
 /  ;    '.              ,-+-. ;   , ||         .   /   ;.  \         .   /   ;.  \
:  :       \            ,--.'|'   |  ;|        .   ;   /  ` ;        .   ;   /  ` ;
:  |   /\   \          |   |  ,', |  ':        ;   |  ; \ ; |        ;   |  ; \ ; |
|  :  ' ;.   :         |   | /  | |  ||        |   :  | ; | '        |   :  | ; | '
|  |  ;/  \   \        '   | :  | :  |,        .   |  ' ' ' :        .   |  ' ' ' :
'  :  | \  \ ,'        ;   . |  ; |--'         '   ;  \; /  |        '   ;  \; /  |
|  |  '  '--'          |   : |  | ,             \   \  ',  /          \   \  ',  /
|  :  :                |   : '  |/               ;   :    /            ;   :    /
|  | ,'                ;   | |`-'                 \   \ .'              \   \ .'
`--''                  |   ;/                      `---`                 `---`
                       '---'

*/



Measured memory_bytes: 23680
#include <stdio.h>
int main(void)
{
  long int n,k,t,a,min; 
  scanf("%ld",&n);
  scanf("%ld",&k);
  t=n%k;
  a=(t-k)*-1;
  if(t<a)
    min=t;
  else
    min=a;
  printf("%ld",min);
}

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

int main()
{
	cin>>s1;
	if(s1[0]=='S') printf("Cloudy\n");
	if(s1[0]=='C') printf("Rainy\n");
	if(s1[0]=='R') printf("Sunny\n");
	
	return 0;
}


Measured memory_bytes: 256
def examC():
    N = I()
    S = [I() for _ in range(N)]
    S1 = []
    for s in S:
        if s%10==0:
            continue
        S1.append(s)
    if S1==[]:
        print(0)
        return
    S1.sort()
    ans = sum(S)
    if ans%10==0:
        ans -= S1[0]
    print(ans)
    return

def examD():
    N, A, B = LI()
    H = [I() for _ in range(N)]
    H.sort()
    l = 0; r = (H[-1]-1)//B + 1
    while(r-l>1):
        now = (l+r)//2
        cur = 0
        for i in H:
            if i-now*B>0:
                cur += ((i-now*B-1)//(A-B) +1)
        if cur>now:
            l = now
        else:
            r = now
    ans = r
    print(ans)
    return

def examE():
    # 0許容(i += 1)
    class Bit():
        def __init__(self, n):
            self.size = n
            self.tree = [0] * (n + 1)
            return

        def sum(self, i):
            i += 1
            s = 0
            while i > 0:
                s += self.tree[i]
                i -= i & -i
            return s

        def add(self, i, x=1):
            i += 1
            # i==0 はだめ => 全部+1するとか
            while i <= self.size:
                self.tree[i] += x
                i += i & -i
            return

        def search(self, x):
            # 二分探索。和がx以上となる最小のインデックス(>= 1)を返す
            # maspyさんの参考　よくわかってない
            i = 0
            s = 0
            step = 1 << ((self.size).bit_length() - 1)
            while step:
                if i + step <= self.size and s + self.tree[i + step] < x:
                    i += step
                    s += self.tree[i]
                step >>= 1
            return i

        def debug(self, k):
            return [self.sum(i) for i in range(k)]

        def inversion(self, A=[3, 10, 1, 8, 5]):
            res = 0
            for i, p in enumerate(A):
                self.add(p)
                res += i + 1 - self.sum(p)
            return res
    N, K = LI()
    A = [I()-K for _ in range(N)]
    S = [[0,i] for i in range(N+1)]
    for i in range(N):
        S[i+1][0] = S[i][0]+A[i]
    S.sort()
    prev = -inf
    cnt = -1
    for i in range(N+1):
        if S[i][0]==prev:
            S[i][0] = cnt
        else:
            prev = S[i][0]
            cnt += 1
            S[i][0] = cnt
    S.sort(key=lambda x:x[1])
    A = [0]*(1+N)
    for i in range(N+1):
        A[i] = S[i][0]
    bit = Bit(cnt+1)
    #print(A)
    ans = N*(N+1)//2 - bit.inversion(A)
    if ans<0:
        ans = 0
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

import sys,copy,bisect,itertools,heapq,math,random
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10**(-12)
alphabet = [chr(ord('a') + i) for i in range(26)]

if __name__ == '__main__':
    examE()

"""

"""

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

const int MOD=1000000007;

ll gcd(ll x, ll y) {
    if (y == 0)return x;
    return gcd(y, x % y);
}

ll lcm(ll x, ll y) {
    return x * y / gcd(x, y);
}


void solve(long long N, std::vector<long long> A){
    double sum=0;
    for (int i = 0; i < N; i++) {
        sum += 1.0/A[i];
    }
    cout << 1/sum << endl;
}

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


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

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

    int f = 0;
    for (int i = 0; i < n; ++i) {
        int a;
        cin >> a;
        f += a - 1;
    }

    cout << f << endl;

    return 0;
}

Measured memory_bytes: 256
for e in iter(input,'0'):
 a=[list(map(int,input().split()))for _ in[0]*int(e)]
 b=[list(map(int,input().split()))for _ in[0]*int(input())]
 for s,t in b:
  u,v=a[0]
  x,y=s-u,t-v
  for u,v in a:
   if[u+x,v+y]not in b:break
  else:print(x,y)


Measured memory_bytes: 5984
def solve(x1, y1, x2, y2):

    x3, y3 = int(x2 - (y2 - y1)), int(y2 + (x2 - x1))
    x4, y4 = int(x1 - (y2 - y1)), int(y1 + (x2 - x1))

    return " ".join(str(i) for i in [x3, y3, x4, y4])

if __name__ == "__main__":
    l = input()
    x1, y1, x2, y2 = int(l.split()[0]),int(l.split()[1]), int(l.split()[2]), int(l.split()[3])
    print(solve(x1, y1, x2, y2))


Measured memory_bytes: 3064