akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;

int gcd(int a, int b) {

	if (b % a == 0)
		return a;
	else {
		while (b > a) 
			b -= a;
		return gcd(b,a);
	}
}

int main()
{
	int a, b;
	long long int ans=1;
	cin >> a >> b;
	if (a > b) {
		int t = a;
		a = b;
		b = t;
	}
	ans *= a/gcd(a,b);
	ans *= b;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ld double
#define ll long long
#define pb emplace_back
#define mk make_pair
#define mod 1000000007
#define ff first
#define ss second
#define FIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define all(x) x.begin(),x.end()
ll power(ll a, ll b){ll res=1;a=a%mod; while(b){if(b&1)res=(res*a)%mod; a=(a*a)%mod;b/=2;}return res;}
ll invmod(ll a){return power(a,mod-2);}
int fun(ll j)
{
    int ans=0,x=1;
    while(j%2==0&&j!=0)
    {
        j/=2;
        ans++;
    }
    return ans;
}
int main(void)
{
    FIO	
    int n,ans=0;
    cin>>n;
    vector<ll> arr(n);
    for(int i=0;i<n;i++) cin>>arr[i];
    for(auto j : arr) if(j%2==0) ans+=fun(j);
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <map>
using namespace std;

bool solve(const string &S) {
    map<char,int> ma; // あるなら 1、ないなら 0
    for (int i = 0; i < S.size(); ++i){
        if (ma.count(S[i])) ma[S[i]] = 1;
        else ma[S[i]] = 1;
    }
    if (ma['N'] != ma['S']) return false;
    if (ma['W'] != ma['E']) return false;
    return true;
}

int main() {
    string S; cin >> S;
    if (solve(S)) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define RI register int
int read() {
    int q=0;char ch=' ';
    while(ch<'0'||ch>'9') ch=getchar();
    while(ch>='0'&&ch<='9') q=q*10+ch-'0',ch=getchar();
    return q;
}
const int mod=1e9+7,N=100005;
int n,ans;
int a[N],du[N],kj[N],vis[N],hjw[N],sum[N],f[N];
int qm(int x) {return x>=mod?x-mod:x;}
void workkj(int x) {
    int now=0,fr=0,ed=0,hpp=0;
    while(kj[x]) {
        ++now,kj[x]=0;
        if(hjw[x]) {
            if(!fr) ed=fr=now,hpp=hjw[x];
            else {
                int kl=(hjw[x]<now-ed)+(hjw[x]<=now-ed);
                ans=1LL*ans*kl%mod,ed=now;
            }
        }
        x=a[x];
    }
    if(!fr) ++sum[now];
    else {
        int kl=(hpp<now-ed+fr)+(hpp<=now-ed+fr);
        ans=1LL*ans*kl%mod;
    }
}
void work() {
    for(RI i=1;i<=n;++i) {
        if(du[i]) continue;
        int x=i,len=0;while(!kj[x]) x=a[x],++len;
        hjw[x]=len;
    }
    ans=1;
    for(RI i=1;i<=n;++i) if(kj[i]) workkj(i);
    for(RI i=1;i<=n;++i) {
        if(!sum[i]) continue;
        f[0]=1;
        for(RI j=1;j<=sum[i];++j) {
            if(i>1&&(i&1)) f[j]=qm(f[j-1]+f[j-1]);
            else f[j]=f[j-1];
            if(j>1) f[j]=qm(f[j]+1LL*f[j-2]*(j-1)%mod*i%mod);
        }
        ans=1LL*ans*f[sum[i]]%mod;
    }
}
int main()
{
    n=read();
    for(RI i=1;i<=n;++i) a[i]=read(),++du[a[i]];
    for(RI i=1;i<=n;++i) {
        if(vis[i]) continue;
        int x=i;while(!vis[x]) vis[x]=i,x=a[x];
        if(vis[x]!=i) continue;
        while(!kj[x]) kj[x]=1,x=a[x];
    }
    for(RI i=1;i<=n;++i)
        if((kj[i]&&du[i]>2)||(!kj[i]&&du[i]>1)) {puts("0");
		return 0;
  }
    work();
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 2176
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

class Point{
public:
    double y, x;
    Point(double y0, double x0){
        y = y0;
        x = x0;
    }
    Point(){
        y = x = 0.0;
    }
    double cross(const Point& p) const{
        return x * p.y - y * p.x;
    }
    Point operator-(const Point& p) const{
        return Point(y - p.y, x - p.x);
    }
};

int main()
{
    for(;;){
        vector<Point> p(3);
        Point p1;
        for(int i=0; i<3; ++i){
            if(!(cin >> p[i].x >> p[i].y))
                return 0;
        }
        cin >> p1.x >> p1.y;

        bool plus = true;
        bool minus = true;
        for(int i=0; i<3; ++i){
            Point p2 = p[(i+1)%3] - p[i];
            Point p3 = p1 - p[i];
            if(p2.cross(p3) < 0)
                plus = false;
            else
                minus = false;
        }
        if(plus || minus)
            cout << "YES" << endl;
        else
            cout << "NO" << endl;
    }
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>

using namespace std;

int main() {
    string s, t;
    cin >> s >> t;
    int ans = 1001;
    for(int i=0; i<=s.size()-t.size(); i++) {
        int curr = 0;
        for(int j=0; j<t.size(); j++) {
            if(s[i+j] != t[j]) curr++;
        }
        ans = min(curr, ans);
    }
    cout << ans;
    return 0;
}


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

#define rep(i, a, b) for (int i = (a), i##end = (b); i <= i##end; ++i)
#define per(i, a, b) for (int i = (a), i##end = (b); i >= i##end; --i)

mt19937 Rnd(chrono::high_resolution_clock::now().time_since_epoch().count());

template <typename T>
inline void chkmax(T &x, T y) { if (x < y) x = y; }

template <typename T>
inline void chkmin(T &x, T y) { if (x > y) x = y; }

inline int read() {
  #define nc getchar()
  int x = 0;
  char c = nc;
  while (c < 48) c = nc;
  while (c > 47) x = (x << 3) + (x << 1) + (c ^ 48), c = nc;
  return x;
  #undef nc
}

typedef long long ll;
const int maxn = 2e5 + 10;
int n, T, tot, cnt;
ll dp[2][30], sum[maxn];

struct node {
  int x, y;
} a[maxn];

int main() {
  cin >> n >> T;
  rep(i, 1, n) {
    int x = read(), y = read();
    if (!x) {
      sum[++cnt] = y;
    } else {
      a[++tot] = {x, y};
    }
  }
  sort(sum + 1, sum + cnt + 1);
  sort(a + 1, a + tot + 1, [] (node P, node Q) {
    return 1ll * Q.x * (P.y + 1) < 1ll * P.x * (Q.y + 1);
  });
  rep(i, 1, cnt) sum[i] += sum[i - 1] + 1;
  int sel = 1;
  memset(dp, 0x3f, sizeof dp);
  dp[0][0] = 0;
  rep(i, 1, tot) {
    memset(dp[sel], 0x3f, sizeof dp[sel]);
    dp[sel][0] = 0;
    rep(j, 1, 29) {
      dp[sel][j] = dp[sel ^ 1][j];
      ll v = dp[sel ^ 1][j - 1] + 1;
      if (v <= T) chkmin(dp[sel][j], v + a[i].x * v + a[i].y);
    }
    sel ^= 1;
  }
//  putchar('#');
//  rep(i, 1, cnt) printf("%lld%c", sum[i], "\n "[i  < cnt]);
  int res = 0;
  rep(i, 0, 29) {
    ll v = dp[sel ^ 1][i];
    if (v > T) continue;
//    printf("(%d %lld)\n", i, dp[sel ^ 1][i]);
    int tmp = upper_bound(sum + 1, sum + cnt + 1, T - v) - sum - 1;
    chkmax(res, i + tmp);
  }
  cout << res;
  return 0;
}

Measured memory_bytes: 1792
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "functional"

using namespace std;

constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-8;

//int N, M, K, H, W, L, R;
long long int N, M, K, H, W, L, R;


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

	cin >> N >> M;
	if (N > 9 || M > 9)cout << -1 << endl;
	else cout << N * M << endl;
}



Measured memory_bytes: 256
a = list(map(int,input().split()))
b = [0]*2
c = [0]*2
s = 0
for i in range(a[1]):
  if i == 0:
    b[0],c[0] = map(int,input().split())
  else:
    b[1],c[1] = map(int,input().split())
    if (b[1] > c[0]) or (c[1] < b[0]):
      s += 1
      break
    else:
      if b[1] >= b[0]:
        b[0] = b[1]
      if c[1] <= c[0]:
        c[0] = c[1]
if s == 0:
  print(c[0]-b[0]+1)
else:
  print(0)

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {

	/**
	 *AOJテァツ板ィテ」ツδ療」ツδュテ」ツつクテ」ツつァテ」ツつッテ」ツδ?
	 */
	public static void main(String[] args) {
		// TODO ティツ?ェテ・ツ仰陛ァツ板淌ヲツ按静」ツ?陛」ツつ古」ツ?淌」ツδ。テ」ツつステ」ツδε」ツδ嘉」ツδサテ」ツつケテ」ツつソテ」ツδ?
		Scanner scan = new Scanner(System.in);
		int k = 0, u = 0, p = 0, c = 0;
		String str;
		str = scan.next();
		char chr;
		int a = 0;
		for (int i = 0; i < str.length(); i++) {
			chr = str.charAt(i);
			switch (chr) {
			case 'K':
				k++;
				break;
			case 'U':
				u++;
				break;
			case 'P':
				p++;
				break;
			case 'C':
				c++;
				break;
			default:
				break;
			}
		}
		a = Math.min(k, u);
		a = Math.min(a, p);
		a = Math.min(a, c);
		System.out.println(a);
	}
}

Measured memory_bytes: 17320
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod 1000000007

int main(){
    int n,k;
    cin>>n>>k;
    vector<ll> x(n);
    for(int i=0;i<n;i++) cin>>x[i];
    ll ans= 1001002003004005006;
    ll r;
    for(int i=0;i<n-k+1;i++){
        r=abs(x[i]-x[i+k-1])+min(abs(x[i]),abs(x[i+k-1]));
        ans=min(ans,r);
    }
    
    cout<<ans<<endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define int long long

using namespace std;

typedef vector<int> vi;

string s;
int n, w, h, z, inpa, inpb, inf = 1000000007;
vi a, res;

signed main()
{
    scanf("%lld %lld %lld", &h, &w, &n);
    res.assign(10, 0);
    z = (h - 2) * (w - 2);
    for (int nn = 0; nn < n; nn++)
    {
        scanf("%lld %lld", &inpa, &inpb);
        for (int i = 0; i <= 2; i++)
        {
            for (int j = 0; j <= 2; j++)
            {
                int aa = inpa - i, bb = inpb - j;
                if (aa > 0 && bb > 0 && aa <= h - 2 && bb <= w - 2)
                {
                    a.push_back(inf * (aa) + bb);
                }
            }
        }
    }
    sort(a.begin(), a.end());
    /*
    for(int i=0;i<a.size();i++)
    {
        cout << a[i] << " ";
    }
    cout << endl;
    */
    int num = 1;
    for (int i = 0; i < a.size(); i++)
    {
        if (a[i] == a[i + 1])
        {
            ++num;
        }
        else
        {
            ++res[num];
            --z;
            num = 1;
        }
    }
    printf("%lld\n", z);
    for (int i = 1; i < 10; i++)
    {
        printf("%lld\n", res[i]);
    }
    return 0;
}


Measured memory_bytes: 10604
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i) = 0; (i) < (n); ++(i))
#define rrep(i,n) for(int (i) = (n) - 1; (i) >= 0; --(i)) //Reversi rep
#define nfor(i,a,b) for(int (i) = (a); (i) < (b); ++(i)) //Natural for
#define rfor(i,a,b) for(int (i) = (b); (i) >= (a); --(i)) //Reversi for
#define ll long long
#define mod (1000000007)
#define YES cout << "YES" << endl;
#define Yes cout << "Yes" << endl;
#define yes cout << "yes" << endl;
#define NO cout << "NO" << endl;
#define No cout << "No" << endl;
#define no cout << "no" << endl;

int asc(const void *a, const void *b) {
    return *(int *)a - *(int *)b;
}

int desc(const void *a, const void *b) {
    return *(int *)b - *(int *)a;
}

int main()
{
    int n,m;
    string counts[101];
    int count[101],scount = 0;
    rep(i, 101)count[i] = 0;
    bool c;
    cin >> n;
    string s,t;
    rep(i, n){
        c = false;
        cin >> s;
        rep(j, scount){
            if (counts[j] == s) {
                ++count[j];
                c = true;
            }
        }
        if (!c) {
            counts[scount] = s;
            ++count[scount];
            ++scount;
        }
    }
    cin >> m;
    rep(i, m){
        cin >> t;
        rep(j, scount){
            if (counts[j] == t) {
                --count[j];
            }
        }
    }
    qsort(count, 101, sizeof(int), desc);
    if (count[0] >= 0) {
        cout << count[0] << endl;
    }else{
        cout << 0 << endl;
    }
    return 0;
}


Measured memory_bytes: 256
function Main(input){
  var inp = input.split(' ');
  var a = parseInt(inp[0]);
  var b = parseInt(inp[1]);
  
  var total = a + b;
  var average = Math.round(total / 2);
  console.log(average);
}

Main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7372
#include<bits/stdc++.h>
#define pb push_back
#define mem(a,x) memset(a,x,sizeof(a))
using namespace std;
typedef long long ll;
typedef pair <int,int> PAIR;
const int maxn = 5e5 + 7;
const double pi = acos(-1);
const ll mod = 1e9 + 7;
const double eps = 1e-6;
const int inf = 0x3f3f3f3f;

int main(){
	int n;
	scanf("%d",&n);
	if(n >= 400 && n < 600) printf("8\n");
	if(n >= 600 && n < 800) printf("7\n");
	if(n >= 800 && n < 1000) printf("6\n");
	if(n >= 1000 && n < 1200) printf("5\n");
	if(n >= 1200 && n < 1400) printf("4\n");
	if(n >= 1400 && n < 1600) printf("3\n");
	if(n >= 1600 && n < 1800) printf("2\n");
	if(n >= 1800 && n < 2000) printf("1\n");
	return 0;
} 

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

int main() {
  int n;
  int result = 0;
  cin >> n;
  long long int a[n];

  for (int i = 0; i < n; ++i) {
    scanf("%lld", &a[i]);
  }

  bool divide = true;
  while (divide == true) {
    for (int i = 0; i < n; ++i) {
      if (a[i] % 2 != 0) {
        divide = false;
      } else {
        a[i] /= 2;
      }
    }
    if (divide == true) {
      result++;
    }
  }
  cout << result << endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
  private static long solve(long n, long m) {
    if (n == 1 && m == 1) {
      return 1;
    }
    if (n == 1 || m == 1) {
      return Math.max(n, m) - 2;
    }
    return (n - 2) * (m - 2);
  }

  public static void main(String[] args) {
    Scanner s = new Scanner(System.in);
    int n = s.nextInt();
    int m = s.nextInt();
    System.out.println(solve(n, m));
  }
}


Measured memory_bytes: 23124
n,m=map(int,input().split())
arr=list(map(int,input().split()))

arr.sort()
arr.reverse()

ans=0
total=sum(arr)
#print(total)
for i in range(m):
    if(arr[i]>=(total/(4*m))):
        ans+=1

#print(ans)
if(ans==m):
    print("Yes")
else:
    print("No")



Measured memory_bytes: 3060
function main(input) {
	var lines = input.split("\n");
	var dataSetLength = parseInt(lines[0]);
	var currentLine = 1;
	var salesTotals = [];
	while (currentLine < lines.length && dataSetLength > 0) {
		var sale = lines[currentLine].split(" ").map(function(value) {return parseInt(value)});
		if (sale.length === 1) {
			var validSales = salesTotals.reduce(function(result, value) {
				if (value.salesTotal >= 1000000) {
					result.push(value.id);
				}
				return result;
			}, []);
			if (validSales.length <= 0) {
				console.log("NA");
			} else {
				for(var i = 0; i < validSales.length; i++) {
					if(!isNaN(validSales[i])) console.log(validSales[i]);
				}
			}
			salesTotals = [];
			dataSetLength = parseInt(sale[0]);
		} else if(!isNaN(sale[1]) && !isNaN(sale[2])) {
			var saleIndex = 0;
			for (; saleIndex < salesTotals.length; saleIndex++) {
				if (salesTotals[saleIndex].id === sale[0]) break;
			}
			var currentSalesTotal = (salesTotals[saleIndex] || {salesTotal: 0}).salesTotal;
			salesTotals[saleIndex] = {
				id: sale[0],
				salesTotal: currentSalesTotal + (sale[1] * sale[2])
			};
		}
		currentLine++;
	}
}
main(require('fs').readFileSync('/dev/stdin','utf8'));

Measured memory_bytes: 18104
#include<iostream>
#include<iomanip>
#include<bitset>
#include<cmath>
using namespace std;
struct Point{double x,y,z;};
Point operator-(const Point&a,const Point&b)
{
	return (Point){a.x-b.x,a.y-b.y,a.z-b.z};
}
Point operator*(const Point&a,double k)
{
	return (Point){a.x*k,a.y*k,a.z*k};
}
int N,M,R;
Point S[2000];double r[2000];
Point T[15];double br[15];
Point E;
void input(Point&p)
{
	cin>>p.x>>p.y>>p.z;
}
bitset<2000>A[15];
double norm(const Point&a)
{
	return a.x*a.x+a.y*a.y+a.z*a.z;
}
double distance(const Point&a,const Point&b)
{
	double L=0,R=1;
	for(int ccc=0;ccc<100;ccc++)
	{
		double M1=(L*2+R)/3;
		double d1=norm(b-a*M1);
		double M2=(L+R*2)/3;
		double d2=norm(b-a*M2);
		if(d1<d2)R=M2;
		else L=M1;
	}
	return norm(b-a*R);
}
bool in(Point p,int id)
{
	return norm(S[id]-p)<r[id]*r[id];
}
main()
{
	while(cin>>N>>M>>R,M)
	{
		for(int i=0;i<N;i++)
		{
			input(S[i]);
			cin>>r[i];
		}
		for(int i=0;i<M;i++)
		{
			input(T[i]);
			cin>>br[i];
		}
		input(E);
		for(int i=0;i<M;i++)
		{
			A[i]=0;
			for(int j=0;j<N;j++)
			{
				double d=distance(T[i]-E,S[j]-E);
				if(d<r[j]*r[j]&&(!in(T[i],j)||!in(E,j)))A[i][j]=1;
			}
		}
		double ans=0;
		for(int i=0;i<1<<M;i++)
		{
			bitset<2000>now=0;
			for(int j=0;j<M;j++)if(i>>j&1)now|=A[j];
			if(now.count()<=R)
			{
				double ret=0;
				for(int j=0;j<M;j++)
				{
					if(i>>j&1)
					{
						ret+=br[j]/norm(T[j]-E);
					}
				}
				ans=max(ans,ret);
			}
		}
		cout<<fixed<<setprecision(16)<<ans<<endl;
	}
}



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

constexpr int inf = 0x3f3f3f3f;
constexpr ll linf = 0x3f3f3f3f3f3f3f3fLL;

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

    string a, b; cin >> a >> b;
    int n = a.length(), m = b.length();
    if (n != m) {
        cout << (n > m ? "GREATER" : "LESS") << endl;
        return 0;
    }

    for (int i = 0; i < n; i++) {
        if (a[i] != b[i]) {
            cout << (a[i] > b[i] ? "GREATER" : "LESS") << endl;
            return 0; 
        }
    }
    cout << "EQUAL" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
#define pb push_back
#define all(c) c.begin(),c.end()
#define MOD 998244353
typedef double ld;
#define PI 3.14159265



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

    int n;
    cin >> n;
    char c;
    set<char> s;
    for(int i = 0 ; i < n ; i++) {
        cin >> c;
        s.insert(c);
    }
    if(s.size() == 3) cout << "Three" << endl;
    else cout << "Four" << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

struct UnionFind{
    vector<int> par;

    UnionFind(int n) : par(n,-1) { }
    void init(int n) { par.assign(n,-1); }

    int root(int x){
        if(par[x]<0) return x;
        else return par[x]=root(par[x]);
    }

    bool issame(int x,int y){
        return root(x)==root(y);
    }

    bool merge(int x,int y){
        x=root(x);
        y=root(y);
        if(x==y) return false;
        if(par[x]>par[y]) swap(x,y);
        par[x]+=par[y];
        par[y]=x;
        return true;
    }

    int size(int x){
        return -par[root(x)];
    }
};

int main() {
    ll n,m;
    cin>>n>>m;
    int A[m],B[m];
    rep(i,m){
        cin>>A[i]>>B[i];
        A[i]--,B[i]--;
    }

    UnionFind uf(n);
    ll cur=n*(n-1)/2;
    vector<ll> res;
    rep(i,m){
        res.push_back(cur);
        int a=A[m-1-i],b=B[m-1-i];
        if(uf.issame(a,b)) continue;

        ll sa=uf.size(a),sb=uf.size(b);
        cur-=sa*sb;
        uf.merge(a,b);
    }

    reverse(all(res));
    rep(i,m) cout<<res[i]<<endl;
}



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


int main() {
  int N, K;
  cin >> N >> K;
  vector<int> snuke(N, 0);
  for (int i = 0; i < K; i++) {
    int d;
    cin >> d;
    for (int j = 0; j < d; j++) {
      int a;
      cin >> a;
      snuke[a - 1]++;
    }
  }
  int cnt = 0;
  for (int i = 0; i < N; i++) {
    if (snuke[i] == 0) {
      cnt++;
    }
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 3628
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(300000)


def solve(x: int):
    ret = 'ARC'
    if x < 1200:
        ret = 'ABC'
    print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    x = int(next(tokens))  # type: int
    solve(x)

if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#[allow(unused_imports)]
use itertools::Itertools;
#[allow(unused_imports)]
use itertools_num::ItertoolsNum;
#[allow(unused_imports)]
use std::cmp;
#[allow(unused_imports)]
use std::iter;
#[allow(unused_imports)]
use superslice::*;

fn run() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());

    let n: usize = sc.read();

    for i in 1..=9 {
        if n % i == 0 && n / i >= 1 && n / i <= 9 {
            println!("Yes");
            return;
        }
    }
    println!("No");
}

fn main() {
    std::thread::Builder::new()
        .name("run".into())
        .stack_size(256 * 1024 * 1024)
        .spawn(run)
        .unwrap()
        .join()
        .unwrap();
}

pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> IO<R, W> {
        IO(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: std::ops::Deref<Target = str>>(&mut self, s: S) {
        use std::io::Write;
        self.1.write(s.as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn read_vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn read_pairs<T: std::str::FromStr>(&mut self, n: usize) -> Vec<(T, T)> {
        (0..n).map(|_| (self.read(), self.read())).collect()
    }
    pub fn read_pairs_1_indexed(&mut self, n: usize) -> Vec<(usize, usize)> {
        (0..n)
            .map(|_| (self.read::<usize>() - 1, self.read::<usize>() - 1))
            .collect()
    }
    pub fn read_chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
    pub fn read_char_grid(&mut self, n: usize) -> Vec<Vec<char>> {
        (0..n).map(|_| self.read_chars()).collect()
    }
    pub fn read_matrix<T: std::str::FromStr>(&mut self, n: usize, m: usize) -> Vec<Vec<T>> {
        (0..n)
            .map(|_| (0..m).map(|_| self.read()).collect())
            .collect()
    }
}


Measured memory_bytes: 2248
#include <iostream>
#include <stdio.h>
using namespace std;
 
int main()
{
  int N, P[200000];
  int answer=0, min=200001;
  scanf("%d", &N);
  for (int i=0; i<N; i++){
    scanf("%d", &P[i]);
  }
  for (int i=0; i<N; i++){
    if (P[i]<=min){
      answer ++;
      min = P[i];
    }
  }
  printf("%d\n", answer);
  return 0;
}

Measured memory_bytes: 1024
N = int(input())
X = input()
x = X[::-1]
one = X.count('1')
up = 0
down = 0
for i in range(N):
    up += (int(x[i]) * pow(2,i,one+1) % (one+1))
    up %= one+1
    if one > 1:
        down += (int(x[i]) * pow(2,i,one-1) % (one-1))
        down %= one-1
# print(up,down)
def f(ud,one):
    if ud == 0:
        return 1

    cnt = 0
    while ud != 0:
        ud = ud % one
        one = format(ud,'b').count('1')
        cnt += 1
    return cnt



for i in range(len(X)):
    if X[i] == '1':
        if one > 1:
            print(f((down - pow(2,(len(X)-1) - i, one-1)) % (one-1),one-1))
        #print(down - pow(2,(len(X)-1) - i, one-1) % (one-1))
        else:
            print(0)

    else:
        print(f((up + pow(2,(len(X)-1) - i, one+1)) % (one+1),one+1))
        #print(up + pow(2,(len(X)-1) - i, one+1) % (one+1))


Measured memory_bytes: 85348
#include<iostream>
#include<math.h>
#include<limits.h>

using namespace std;

int main(void) {
	long long int i,N,pep,min=LONG_LONG_MAX,minNum,plus=0;
	cin >> N;
	for(i=1;i<=5;i++) {
		cin >> pep;
		if(pep<min) {
			min = pep;
			minNum = i;
		}
	}
	if(N%min) plus=1;
	printf("%lld\n",(N/min)+4+plus);
}

Measured memory_bytes: 256
def is_kaibun(s):
    return s[::1] == s[::-1]

def main():
    s = input()
    n = len(s)
    #print(s[0:(n-1)//2+1])
    #print(s[(n+3)//2:n+1])
    kaibun = is_kaibun(s) and is_kaibun(s[0:(n-1)//2]) and is_kaibun(s[(n+3)//2-1:n+1])
    print("Yes" if kaibun else "No")

if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        String[] a = reader.readLine().split(" ");
        int R = Integer.parseInt(a[0]);
        int G = Integer.parseInt(a[1]);
        int B = Integer.parseInt(a[2]);
        int N = Integer.parseInt(a[3]);
        // r * R + g * G + b * B == N => r = (N - g * G + b * B) / R
        int count = 0;
        for (int g = 0; g <= N; g++) {
            for (int b = 0; b <= N; b++) {
                int rR = N - g * G - b * B;
                if ((0 <= rR) && (rR % R == 0)) {
                    count++;
                }
            }
        }
        System.out.println(count);
    }
}


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

int main(){
  int a;
  cin >> a;
  if (a >= 2800){
  	cout << "AGC" << endl;
}
  else if (a < 2800 && a >= 1200){
    cout << "ARC" << endl;
  }
  else{
    cout << "ABC" << endl;
  }
  
}



Measured memory_bytes: 256
from collections import defaultdict,deque
import math
def main():
    s = input()
    lis = ["maerd", "remaerd", "esare", "resare"]
    s = s[::-1]

    i = 0
    while(i < len(s)-4):
        if(s[i:i+5] in lis):
            i+=5
        elif(i+7 <= len(s) and s[i:i+7]=="remaerd"):
            i += 7
        elif(i+6<=len(s) and s[i:i+6]=="resare"):
            i+=6
        else:
            print("NO")
            exit()
    print("YES")
if __name__ == '__main__':
    main()


Measured memory_bytes: 9152
#include <stdio.h>
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <queue>
#include <list>
#include <stack>
#include <math.h>
#include <map>
#include <unordered_map>
using namespace std;

#define ll long long
#define ull unsigned long long

int main()
{
	long n;
	cin >> n;
	vector<pair<ll, ll>> in(n);
	for (long i = 0; i < n; i++)
		cin >> in[i].first >> in[i].second;
	sort(in.begin(), in.end(), [](const pair<ll, ll> &l, const pair<ll, ll> &r) {return l.second < r.second; });
	ll now = 0;
	for (long i = 0; i < n; i++)
	{
		now += in[i].first;
		if (now <= in[i].second)
			continue;
		printf("No");
		return 0;
	}
	printf("Yes");
	return 0;
}


Measured memory_bytes: 3328
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
using namespace std;
using ll = long long;
int main(){
  int a,b;
  double sum=0;
  cin >> a;
  rep(i,a){cin >> b;sum += 1.0/b;}
   cout << fixed << setprecision(15) << 1.0/sum << endl;
  return 0;
}


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

using namespace std;

#define pb push_back
#define mp make_pair
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
typedef long long LL;
typedef pair<int, int> PII;

LL n;

int main() {
    cin >> n;
    LL best = 1;
    for (LL a = 2; a * a <= n; ++a) {
        if (n % a == 0) {
            best = a;
        }
    }
    LL num = n / best;
    int ans = 0;
    while (num) {
        num /= 10;
        ++ans;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
from math import sqrt, ceil
n = int(input())
ans = 0
for i in range(1, n+1, 2):
    score = 0
    for d in range(1, ceil(sqrt(i))+1):
        p, m = divmod(i, d)
        if m == 0:
            if p != d:
                score += 2
            else:
                score += 1
    if score == 8:
        ans += 1
print(ans)

Measured memory_bytes: 9128
N, M, C = map(int, input().split())
B = list(map(int, input().split()))
A = [input().split() for l in range(N)]

i = 0
for a in A:
  s = 0
  for x, y in zip(a, B):
    s += int(x) * y

  if s + C > 0:
    i += 1
  else:
    pass


print(i)

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

using ll = long long;

int main() {
    ll b;
    while(cin >> b, b) {
        int ans_len = -1, low = -1;
        for(int len = sqrt(2 * b) + 1; len >= 1; --len) {
            if(2 * b % len != 0) continue;
            ll t = 2 * b / len - len + 1;
            if(t & 1) continue;
            if(t / 2 <= 0) continue;
            ans_len = len, low = t / 2;
            break;
        }
        cout << low << " " << ans_len << endl;
    }
}



Measured memory_bytes: 3036
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000

vector<int> G[100010];

int d[100010][2];

void dfs(int x, int k, int p = -1, int depth = 0) {
    d[x][k] = depth;
    for(auto to: G[x]) {
        if (to == p) continue;
        dfs(to, k, x, depth + 1);
    }
}

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    rep(i, N - 1) {
        int s, t;
        cin >> s >> t;
        s--; t--;
        G[s].push_back(t);
        G[t].push_back(s);
    }
    dfs(0, 0);
    dfs(N - 1, 1);
    int cnt1 = 0, cnt2 = 0;
    rep(i, N) {
        if (d[i][0] <= d[i][1]) cnt1++;
        else cnt2++;
    }
    if(cnt1 > cnt2) {
        cout << "Fennec" << endl;
    } else {
        cout << "Snuke" << endl;
    }
    //cout << cnt1 << " " << cnt2 << endl;


    return 0;
}


Measured memory_bytes: 12800
#include<stdio.h>
 
int main(void){
 
char num[1001];
 
int i=0;
 
int sum=1;
 
while(sum!=0){
 
sum=0;
 
i=0;
 
scanf("%c",&num[i]);
 
while(num[i]!='\n'){
 
i++;
 
scanf("%c",&num[i]);
 
}
 
num[i]='\0';
 
i=0;
 
while(num[i]!='\0'){
 
sum+=num[i]-'0';
 
i++;
 
}
 
if(sum!=0){
 
printf("%d\n",sum);
 
}
 
}
 
return 0;
 
}

Measured memory_bytes: 536
require 'set'
def combination(n,k)
  (n-k+1..n).inject(:*) / (1..k).inject(:*)
end

n,m = gets.strip.split.map(&:to_i)
abs = m.times.map{ gets.strip.split.map(&:to_i) }

island_groups = n.times.map{|i| [i] }
group_index = []
n.times do |i|
  group_index[i] = i
end

results = []
inconvenientness = combination(n,2)

abs.reverse.each do |ab|
  results.push inconvenientness
  a,b = ab.map{|i| i-1 }
  a_index = group_index[a]
  b_index = group_index[b]
  next if a_index == b_index
  if island_groups[a_index].size > island_groups[b_index].size
    parent_index = a_index
    parent_group = island_groups[a_index]
    child_group = island_groups[b_index]
  else
    parent_index = b_index
    parent_group = island_groups[b_index]
    child_group = island_groups[a_index]
  end
  inconvenientness -= parent_group.size * child_group.size
  parent_group.concat(child_group)
  child_group.each do |i|
    group_index[i] = parent_index
  end
end

puts results.reverse.join("\n")


Measured memory_bytes: 29252
N = int(input())
T, A = map(int, input().split())

H = list(map(int, input().split()))

mn = None
for i, h in enumerate(H):
    d = abs(A - (T - h * 0.006))
    mn = (i, d) if mn is None or mn[1] > d else mn
print(mn[0] + 1)

Measured memory_bytes: 3064
using System;

namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            int thit,tak,ahit,atak;
            bool count = false;
            string[] str = Console.ReadLine().Split(' ');
            thit = int.Parse(str[0]);
            tak = int.Parse(str[1]);
            ahit = int.Parse(str[2]);
            atak = int.Parse(str[3]);
            while(thit>0 || ahit > 0)
            {
                ahit = ahit - tak;
                if (ahit <= 0)
                {
                    count = true;
                    break;
                }
                thit = thit - atak;
                if (thit <= 0)
                {
                    break;
                }
            }
            if (count)
            {
                Console.WriteLine("Yes");
            }
            else Console.WriteLine("No");
        }
    }
}


Measured memory_bytes: 27528
A, B, K = map(int, input().split())
ans = []

if B + 1 - A < 2 * K:
  ans = [i for i in range(A, B + 1)]
else:
  ans = [i for i in range(A, A + K)] + [i for i in range(B + 1 - K, B + 1)]
for a in ans:
  print(a)

Measured memory_bytes: 3060
from itertools import accumulate
n,m,k = map(int, input().split())
a = map(int, input().split())
b = map(int, input().split())
varl = [0] + list(accumulate(a))
varl2 = [0] + list(accumulate(b))
ans, i = 0, n
for iterater in range(m+1):
    while varl[i]+varl2[iterater] > k and i>0:
        i -= 1
    if i==0 and varl2[iterater] > k:
        break
    ans = max(ans, i+iterater)
print(ans)

Measured memory_bytes: 51604
#include<iostream>
#include<string>
#include<cstdlib>
#include<algorithm>
#include<cctype>

using namespace std;

int main(){

	int a,b;
	cin>>a>>b;
	
	if(a+b>=10){
	cout<<"error"<<endl;
	}else cout<<a+b<<endl;
	
	
}




Measured memory_bytes: 256
N = int(input())

# 1, 6, 9 の階乗の組み合わせの合計が N
ans = N
for i in range(N + 1):
    cnt = 0
    total = i
    while total > 0:
        cnt += total % 6
        total //= 6
    j = N - i
    while j > 0:
        cnt += j % 9
        j //= 9
    ans = min(ans, cnt)
print(ans)


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

 
    return 0;
}


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

typedef long long ll;
typedef unsigned long long llu;

int main(int argc, char *argv[]) {
  ll n, m;
  cin >> n >> m;

  ll p = pow(2, m);
  cout << (1900*m*p) + (100*(n-m)*p) << endl;

  return 0;
}

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

#define dump(...) cout<<"# "<<#__VA_ARGS__<<'='<<(__VA_ARGS__)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple

using uint=unsigned;
using ll=long long;
using ull=unsigned long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using vd=vector<double>;
using vvd=vector<vd>;
using vs=vector<string>;

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}

template<typename Tuple>
void print_tuple(ostream&,const Tuple&){}
template<typename Car,typename... Cdr,typename Tuple>
void print_tuple(ostream& os,const Tuple& t){
	print_tuple<Cdr...>(os,t);
	os<<(sizeof...(Cdr)?",":"")<<get<sizeof...(Cdr)>(t);
}
template<typename... Args>
ostream& operator<<(ostream& os,const tuple<Args...>& t){
	print_tuple<Args...>(os<<'(',t);
	return os<<')';
}

template<typename Ch,typename Tr,typename C>
basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>& os,const C& c){
	os<<'[';
	for(auto i=begin(c);i!=end(c);++i)
		os<<(i==begin(c)?"":" ")<<*i;
	return os<<']';
}

constexpr int INF=1e9;
constexpr int MOD=1e9+7;
constexpr double EPS=1e-9;

bool is_st(list<char>& t,list<char>::iterator i)
{
	if(i==end(t) || *i!='S') return false;
	i++;
	if(i==end(t) || *i!='T') return false;
	return true;
}

list<char>::iterator rm_st(list<char>& t,list<char>::iterator i)
{
	assert(is_st(t,i));
	rep(_,2) i=t.erase(i);
	if(i!=begin(t)) i--;
	return i;
}

int main()
{
	for(string s;cin>>s;){
		list<char> t(all(s));
		for(auto i=begin(t);i!=end(t);){
			if(is_st(t,i))
				i=rm_st(t,i);
			else
				i++;
		}
		cout<<t.size()<<endl;
	}
}


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

using namespace std;

typedef long long int64;

char dp[1 << 26];

inline int tapris(int bit)
{
  return (dp[bit]);
}

int N, A[5];
int latte[10];
int malta[5];

int main()
{
  memset(dp, -1, sizeof(dp));
  for(int i = 0; i < 1 << 26; i++) dp[i] = __builtin_popcount(i);

  cin >> N;

  int64 sum = 0LL;
  for(int i = 0; i < N; i++) {
    cin >> A[i];
    sum += A[i];
  }

  int proc = 0;
  for(int i = 0; i < 1 << 5; i++) {
    if(tapris(i) <= 1) continue;
    int ei = 0;
    for(int j = 0; j < 5; j++) {
      for(int k = j + 1; k < 5; k++) {
        if((i >> j) & 1 && (i >> k) & 1) {
          latte[ei] |= 1 << proc;
        }
        ei++;
      }
    }
    for(int j = 0; j < 5; j++) {
      if((i >> j) & 1) malta[j] |= 1 << proc;
    }
    ++proc;
  }

  int64 ret = 0;
  for(int i = 0; i < 1 << proc; i++) {
    bool iz = true;
    for(int j = 0; j < 10; j++) {
      iz &= tapris(i & latte[j]) <= 1;
    }
    int64 beet = 0LL;
    for(int j = 0; j < 5; j++) {
      int get = tapris(i & malta[j]);
      iz &= get <= A[j];
      beet += get;
    }
    if(iz) ret = max(ret, beet - tapris(i));
  }

  cout << sum - ret << endl;

}

Measured memory_bytes: 68652
#include<bits/stdc++.h>
#include<cstring>
using namespace std;
int main(void){
	int n=0;
	scanf("%d",&n);
	int*data = (int*)malloc(sizeof(int));
	int ans=0;
	int temp=0;
	for(int i=0;i<n;i++){
		scanf("%d",&temp);
		ans+=(temp-1);
	}
	printf("%d\n",ans);
	return 0;
}

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

using namespace std;

int _count_digit( long long num){
    int count = 1;
    while(num / 10 > 0){
        count++;
        num /=10;
    }

    return count;
}

int get_large_digit(long long A, long long B){
    return max( _count_digit(A), _count_digit(B) );
}

int main() {
    long long N;
    cin >> N;

    int ans = INT_MAX;
    for (long long i = 1; i * i <= N; ++i) {

        if (N % i == 0) {
            int tmp = get_large_digit( i, N/i );
            ans = min(ans, tmp);
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main() {
  /* code */
  int n, i, maxh = 0, can_see = 1, h;
  scanf("%d\n", &n);
  scanf("%d", &h);
  maxh = h;
  for (i = 0; i < n - 1; i++) {
    /* code */
    scanf(" %d\n", &h);
    if (maxh <= h) {
      /* code */
      maxh = h;
      can_see++;
    }
  }
  printf("%d\n", can_see);
  return 0;
}

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

int main() {
    int N, L[110] = {0};
    cin >> N;
    for(int i=0; i<N; i++) { cin >> L[i]; }

    int L_max = *max_element(L, L + 110);
    if (L_max < accumulate(L, L + 110, 0) - L_max) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define all(n) begin(n),end(n)
typedef long long ll;
const ll MOD=pow(10,9)+7;
int main()
{
    int N;
    cin >> N;
    vector<int> a(N),b(N);
    for(int i=0; i<N; i++){
        cin >> a.at(i) >> b.at(i) ;
    }
    string ans = "No";
    for(int i=0; i<N-2; i++){
        if(a.at(i)==b.at(i) && a.at(i+1)==b.at(i+1) && a.at(i+2)==b.at(i+2)){
            ans = "Yes";
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3628
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

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

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

// Self settings
// clang-format off
#define MAX_N 100000
#define REP(i, N) for (int i = 0; i < (int)(N); ++i)
#define SLN(i,N) (i == N-1 ? "\n" : " ")
ll fact(ll n) { ll res = 1; for(ll i=2;i<=n;++i) res = res * i; return res;}
ll nCr(ll n, ll r) {return (fact(n)/fact(n-r)*fact(r)) ;}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
const ll MOD = 1e9+7;
const ll INF = 1LL << 60;
const int inf = 1 << 30;
// clang-format on

int N, K;
int R, S, P;
string T;

char win(char ss) {
  switch (ss) {
    case 'r':
      return 'p';
    case 's':
      return 'r';
    case 'p':
      return 's';
  }
  return ' ';
}

char cap(char ss) {
  switch (ss) {
    case 'r':
      return 'R';
    case 's':
      return 'S';
    case 'p':
      return 'P';
  }
  return ' ';
}

int score(char ss) {
  switch (ss) {
    case 'r':
      return R;
    case 's':
      return S;
    case 'p':
      return P;
  }
  return 0;
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> N >> K;
  cin >> R >> S >> P;
  cin >> T;

  ll ans = 0;
  string mine = T;

  // 0: R, 1: S, 2: P
  for (int i = N - 1; i >= 0; i--) {
    char hand = win(T[i]);
    if (i + K >= N) {
      mine[i] = hand;
      ans += score(hand);
    } else if (i + K < N) {
      if (mine[i + K] != hand) {
        mine[i] = hand;
        ans += score(hand);
      } else {
        mine[i] = cap(hand);
      }
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 512
import std.stdio, std.string, std.conv, std.range;
import std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, std.random, core.bitop;

enum inf = 1_001_001_001;
enum infl = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;

void main() {
    int K;
    scan(K);
    int N = 8;
    auto s = new int[](N);
    s[] = -1;
    foreach (i ; 0 .. K) {
        int ri, ci;
        scan(ri, ci);
        s[ri] = ci;
    }

    auto p = iota(N).array;

    do {
        if (iota(N).filter!(i => s[i] != -1).any!(i => s[i] != p[i])) continue;

        auto ng = new bool[][](N, N);
        bool ok = true;

        foreach (i ; 0 .. N) {
            int r = i, c = p[i];
            if (ng[r][c]) {
                ok = false;
                break;
            }
            foreach (ii ; 1 ..  N - i) {
                if (c + ii < N) {
                    ng[r + ii][c + ii] = true;
                }
                if (c - ii >= 0) {
                    ng[r + ii][c - ii] = true;
                }
            }
        }

        debug {
            writefln("%(%s\n%)", ng);
        }

        if (ok) {
            auto ans = new char[][](N, N);
            fillAll(ans, '.');
            foreach (i ; 0 .. N) {
                ans[i][p[i]] = 'Q';
            }
            writefln("%-(%s\n%)", ans);
            return;
        }

    } while (nextPermutation(p));
}









void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x > arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x < arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}



Measured memory_bytes: 2752
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
typedef pair<int,int> Pi;
typedef tuple<int,int,int> tp;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
void solve(int M,int T, int P, int R){
    vector<tp> V(T);//cnt time
    rep(i,0,T)get<2>(V[i]) = i+1;
    int errors[T][P];
    int result[T][P];
    rep(i,0,T)rep(j,0,P)errors[i][j] = result[i][j] = 0;
    rep(i,0,R){
        int m,t,p,j;
        cin >> m >> t >> p >> j;
        t--;p--;
        if(j == 0){
            //AC
            //get<1>(V[t]) = m;
            get<0>(V[t])++;
            result[t][p] = m + 1;
        }else{
            //WA
            errors[t][p]++;
        }
    }
    rep(i,0,T){
        rep(j,0,P){
            //ACしたときのみWA数*20minペナルティ追加
            if(!result[i][j])continue;
            get<1>(V[i]) += result[i][j] - 1 + errors[i][j] * 20;
        }
    }
    sort(V.begin(), V.end(), [](tp a, tp b){
        if(get<0>(a) != get<0>(b))return get<0>(a) > get<0>(b);
        if(get<1>(a) != get<1>(b))return get<1>(a) < get<1>(b);
        return get<2>(a) > get<2>(b);
    });
    cout << get<2>(V[0]);
    
    rep(i,1,T){
        if(get<0>(V[i-1]) == get<0>(V[i]) && get<1>(V[i-1]) == get<1>(V[i])){
            cout << "=";
        }else{
            cout << ",";
        }
        cout << get<2>(V[i]);
    }
    cout << endl;
}
main(){
    int M,T,P,R;
    cin >> M >> T >> P >> R;
    while(M){
        solve(M,T,P,R);
        cin >> M >> T >> P >> R;
    }
}


Measured memory_bytes: 3096
#include<bits/stdc++.h>
#include<numeric>
#include<cassert>
//#include <boost/multiprecision/cpp_int.hpp>
#define ll long long int
#define CON 100010
const long long mod=1e9+7;
const int INF=1001001001;
const int inf=100000;
//const ll inf=1e9+7;
//const ll ful=1e18;
using namespace std;
//namespace mp = boost::multiprecision;
int main() 
{
	int n;
	cin>>n;
	vector<int> b(n-1);
	vector<int> a(n);
	for(int i=0;i<n-1;++i)
	{
		cin>>b[i];
	}
	a[0]=b[0];
	a[n-1]=b[n-2];
	ll ans=a[0]+a[n-1];
	for(int i=1;i<n-1;++i)
	{
		a[i]=min(b[i-1],b[i]);
		ans+=a[i];
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG

using namespace std;
typedef long long ll;

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REP(a, b, m) for (ll a = (ll)(b); a < (ll)(m); a++)

int main()
{
    ll a, b, n;
    cin >> a >> b >> n;
    ll ans = 0;
    if (b <= n)
    {
        cout << a * (b - 1) / b << endl;
    }
    else
    {
        cout << a * n / b << endl;
    }
}

Measured memory_bytes: 3636
N, Y = map(int, input().split())

for i in range(0, N+1, 1):
  isFinish = False
  for j in range(0, N+1-i, 1):
    sen = 1000 * i
    gosen = 5000 * j
    man = 10000 * (N - i - j)
    
    if sen + gosen + man == Y:
      print(N - i - j, j, i)
      isFinish = True
      break
  
  if isFinish:
    break
else:
  print(-1, -1, -1)

Measured memory_bytes: 9220
#include<bits/stdc++.h>
using namespace std;
string s2="keyence",s3="";
int ans=0,ans2=0;
int main()
{
	string s;
	cin>>s;
	int cha=s.size()-7;
	if(s==s2)
	{
		cout<<"YES"<<endl;
		return 0;
	}
	for(int i=0;i<7;i++)
	{
		s3="";
		for(int c=0;c<i;c++)
			s3+=s[c];
		for(int c=i+cha;c<s.size();c++)
			s3+=s[c];
		if(s3==s2)
		{
			cout<<"YES"<<endl;
			return 0;
		}
	}
	cout<<"NO"<<endl;
	return 0;
}


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

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

        boolean[] isPrimes = new boolean[1000000];
        for (int x = 2; x < 1000000 / 2 + 1; x++) {
            if (!isPrimes[x]) {
                for (int y = 2; y < 999999 / x + 1; y++) {
                    isPrimes[x * y] = true;
                }
            }
        }

        int count = 0;
        int[] nPrimes = new int[1000000];
        for (int i = 2; i < 1000000; i++) {
            if (!isPrimes[i]) {
                count++;
            }
            nPrimes[i] = count;
        }

        while (sc.hasNext()) {
            int n = sc.nextInt();
            System.out.println(nPrimes[n]);
        }
    }
}

Measured memory_bytes: 31972