akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <functional>
#include <ctime>
#include <cmath>
#include <limits>
#include <numeric>
#include <type_traits>
using namespace std;
using ll = long long;

unsigned euclidean_gcd(unsigned a, unsigned b) {
    if (a < b) return euclidean_gcd(b, a);
    unsigned r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

class UnionFind {
public:
    vector <ll> par;
    vector <ll> siz;
    UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    ll root(ll x) {
        while (par[x] != x) {
            x = par[x] = par[par[x]];
        }
        return x;
    }
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

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

    ll size(ll x) {
        return siz[root(x)];
    }
};

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}

int main() {
    ll n;
    cin >> n;
    ll a = 1;
    ll b = 1;
    for (int i = 0; i < n; i++) {
        ll x,y;
        cin >> x >> y;
        ll p=a;
        ll q;
        for (ll j = 0; j < 100000; j++) {
            if ((p + j) % x == 0) {
                p += j;
                break;
            }
        }
        q = p / x * y;
        if (q < b) {
            p = 1000000000000000001;
            q = 1000000000000000001;
        }
        ll d = b;
        ll c;
        for (ll j = 0; j < 100000; j++) {
            if ((d + j) % y == 0) {
                d += j;
                break;
            }
        }
        c = d / y * x;
        if (c < a) {
            c = 1000000000000000001;
            d = 1000000000000000001;
        }
        a = min(p, c);
        b = min(q, d);
    }
    cout << a + b << endl;
}

Measured memory_bytes: 256
from networkx import*
n,*t=[t.split()for t in open(0)]
n,m=map(int,n)
g=Graph()
g.add_edges_from(t)
try:a,b=map(len,bipartite.sets(g));a*=b
except:a=n*~-n//2
print(a-m)

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define deg_to_rad(deg) (((deg) / 360) * 2 * M_PI)
#define rad_to_deg(rad) (((rad) / 2 / M_PI) * 360)

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

typedef long long ll;

void solve(long long N) {
  int ans = 0;
  rep(i, N + 1) {
    ll tmp = i;
    int keta = 0;
    while (tmp != 0) {
      keta++;
      tmp /= 10;
    }
    if (keta % 2 == 1) {
      ans++;
    }
  }
  cout << ans << endl;
}

int main() {
  long long N;
  scanf("%lld", &N);
  solve(N);
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cctype>
#include <complex>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <vector>

using std::cin;
using std::cout;
using std::endl;

using std::string;
using std::to_string;
using std::vector;
using std::set;
using std::queue;
using std::priority_queue;

using std::min;
using std::max;
using std::sort;
using std::abs;

char flip_animal(char c){
    return c == 'S' ? 'W' : 'S';
}
char flip_question(char c){
    return c == 'o' ? 'x' : 'o';
}

string solve(int n, const string& q, char a0, char a1) {
    string a(n, '?');
    a[0] = a0;
    a[1] = a1;

    for(int i = 1; i < n - 1; i++){
        char flip = a[i] == 'S' ? q[i] : flip_question(q[i]);
        a[i+1] = flip == 'o' ? a[i-1] : flip_animal(a[i-1]);
    }

    char flip1 = a[n-1] == 'S' ? q[n-1] : flip_question(q[n-1]);
    char next1 = flip1 == 'o' ? a[n-2] : flip_animal(a[n-2]);

    char flip2 = a[0] == 'S' ? q[0] : flip_question(q[0]);
    char next2 = flip2 == 'o' ? a[n-1] : flip_animal(a[n-1]);
    return next1 == a[0] && next2 == a[1] ? a : "";
}

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

    string q;
    cin >> q;

    string a;
    a = solve(n, q, 'S', 'S');
    if(!a.empty()){
        cout << a << endl;
        return 0;
    }
    a = solve(n, q, 'S', 'W');
    if(!a.empty()){
        cout << a << endl;
        return 0;
    }
    a = solve(n, q, 'W', 'S');
    if(!a.empty()){
        cout << a << endl;
        return 0;
    }
    a = solve(n, q, 'W', 'W');
    if(!a.empty()){
        cout << a << endl;
        return 0;
    }
    cout << -1 << endl;
    return 0;
}


Measured memory_bytes: 704
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <cmath>
#include <queue>
#include <stack>
#include <list>
#include <functional>
#include <numeric>
#include <iostream>
#include <string>
#include <time.h>
#include <bitset>

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }

ll N, M, X, C[23], A[23][23];

int main() {

	cin >> N >> M >> X;
	rep(i, N) {
		cin >> C[i];
		rep(j, M) cin >> A[i][j];
	}

	ll ans = 2123456789;

	rep(b, 1 << N) {
		ll subC = 0;
		ll x[23] = {};
		rep(i, N) {
			if ((b >> i) & 1) {
				subC += C[i];
				rep(j, M) x[j] += A[i][j];
			}
		}

		bool f = true;
		rep(j, M) {
			if (x[j] < X) f = false;
		}

		if (f) {
			ans = min(ans, subC);
		}

	}

	if (ans == 2123456789)
		cout << -1 << endl;
	else
		cout << ans << endl;

	return 0;
}


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

int main() {
  int H, W;
  cin >> H >> W;
  vector<vector<char>> v(H, vector<char>(W));
  
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> v.at(i).at(j);
    }
  }
  
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      char c = v.at(i).at(j);
      if ((c == '.') || (c == 'x')) {
        if (!j) {
          int cnt = 1;
          for (int k = 1; k < W; k++) {
            if (v.at(i).at(k) == '.') cnt++;
            if (v.at(i).at(k) == 'x') cnt++;
          }
          if (cnt == W) {
            for (int k = 0; k < W; k++) {
              v.at(i).at(k) = 'x';
            }
          }
        }
        
        int cnt = 0;
        for (int k = 0; k < H; k++) {
          if (v.at(k).at(j) == '.') cnt++;
          if (v.at(k).at(j) == 'x') cnt++;
        }
        if (cnt == H) {
          for (int k = 0; k < H; k++) {
            v.at(k).at(j) = 'x';
          }
        }
      }
    }
  }
  
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      char c = v.at(i).at(j);
      if (c != 'x') {
        cout << c;
      }
    }
    
    int f = 0;
    for (int j = 0; j < W; j++) {
      if (v.at(i).at(j) != 'x') f = 1;
    }
    if (f) cout << endl;
  }
}

Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<malloc.h>
#include<stdlib.h>
#include<cstring>
#include<algorithm>
int main()
{
	int n;
	while(~scanf("%d",&n))
	{
		int t,x,y;
		int a=0,b=0;
		while(n--)
		{
			scanf("%d %d %d",&t,&x,&y);
			if(((t%2)==(x+y)%2)&&t>=x+y)
			a=1;
			else
			b=1;
		}
		if(b==1)
		puts("No");
		else puts("Yes");
	}
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
    // 入力
    int n;
    cin >> n;
    vector<int> p;
    int p_tmp;
    for (int i = 0; i < n; i++) {
        cin >> p_tmp;
        p.push_back(p_tmp);
    }

    vector<int> t;
    t.push_back(0);
    t.push_back(0);
    t.push_back(0);

    int count = 0;
    for (int i = 1; i < n - 1; i++) {
        t[0] = p[i-1];
        t[1] = p[i];
        t[2] = p[i+1];
        sort(t.begin(), t.end());
        if (t[1] == p[i]) {
            if (t[0] != t[1]) {
                count++;
            }
        }
    }
    cout << count << endl;

}

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

int main(){
  int n,m;
  cin>>n>>m;
  int a[n],b[n],c[m],d[m];
  for(int i=0;i<n;i++){
    cin>>a[i]>>b[i];
  }
  for(int i=0;i<m;i++){
    cin>>c[i]>>d[i];
  }
  for(int i=0;i<n;i++){
    long long mn=1000000000000;
    int cou;
    for(int j=0;j<m;j++){
      if(mn>abs(a[i]-c[j])+abs(b[i]-d[j])){
        mn=abs(a[i]-c[j])+abs(b[i]-d[j]);
        cou=j+1;
      }
    }
    cout<<cou<<endl;
  }
}
  


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


int main() 
{
    int A,B;
	int wk1,wk2;
  
    cin>> A>>B;
  
	int i;
	for(i=10;i<=10000;i++){
      wk1=floor(i*0.08);
      wk2=floor(i*0.1);
      if(wk1==A&&wk2==B)
        break;
    }
 
  	if(i>10000)
      cout<<-1;
	else
      cout<<i;
  
    return 0;
}

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

using namespace std;

int main(void) {
    long long int x;
    cin >> x;
    long long int s = 100;
    long long int ans = 0;
    while (s < x) {
        s *= 1.01;
        ans++;
    }
    cout << ans << endl;
}

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

template <class _T> inline bool chmax (_T& a,_T b){if(a<b){a=b;return true;}return false;}
template <class _T> inline bool chmin (_T& a,_T b){if(a>b){a=b;return true;}return false;}

const long long INF = 1LL << 60;

ll GCD(ll a,ll b){
	if(b == 0) return a;	
	return GCD(b,a%b);
}
int main(void){
	ll a,b;cin >> a >> b;
	cout << a/GCD(a,b)*b << endl;
	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define BIG 1000000010
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long 

signed main(){
  int k;
  cin>>k;
  cout<<50<<endl;
  int a[10];
  rep(i,50){
    a[i]=i+(k+i)/50;
    cout<<a[i];
    if(i!=49) cout<<" ";
  }
  cout<<endl;
  

  return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env ruby

A = gets.to_i
B = gets.to_i
C = gets.to_i
X = gets.to_i

dp = Array.new(A) { Array.new(B){ Array.new(C, X) } }

ans = 0
(0..A).each do |a|
  (0..B).each do |b|
    (0..C).each do |c|
      sub = X - (500*a + 100*b +  50*c)
      ans += 1 if sub == 0
    end
  end
end

puts ans


Measured memory_bytes: 2812
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <queue>
#include <string>
#include <vector>
using namespace std;
using ll = int64_t;
#define rep(i, j, n) for (int i = j; i < (int)n; ++i)
#define rrep(i, j, n) for (int i = (int)n - 1; j <= i; --i)

int main() {
  ll a[3];
  rep(i, 0, 3) cin >> a[i];
  if (a[0] % 2 == 0 || a[1] % 2 == 0 || a[2] % 2 == 0)
    cout << 0 << endl;
  else {
    sort(a, a + 3);
    cout << a[0] * a[1] << endl;
  }
  return 0;
}

Measured memory_bytes: 3556
#include <stdio.h>

int main(void){

  int N, T, i, num;
  int c[1000], t[1000];
  int min = 1000;
  int flag = 0;

  scanf("%d %d", &N, &T);

  for (i=0; i<N; ++i){
    scanf("%d %d", &c[i], &t[i]);

    if (t[i] <= T && c[i] <= min){
      min = c[i];
      num = i;
      ++flag;
    }
  }

  if (flag > 0){
    printf("%d\n", c[num]);
  }else{
    printf("TLE\n");
  }

  return 0;
}


Measured memory_bytes: 128
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <limits.h>
#include <cmath>
#include <queue>
#include <map>
#include <iomanip>
#include <random>
#include <fstream>
#define rep(i, n) for (int i = 0; i < n; i++)
#define PI 3.14159265358979323846
#define MOD 1000000007
using namespace std;
using ll = long long;

const int MAX = 1000000;

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

// テーブルを作る前処理
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++){
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

// 二項係数計算
long long COM(int n, int k){
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll gcd(ll a, ll b)
{
  ll r;
  while ((r = a % b))
  {
    a = b;
    b = r;
  }
  return b;
}

template <class T> struct cord{
  T x,y;
};

template <class T> double dist(cord<T> a, cord<T> b){
  T dx=a.x-b.x;
  T dy=a.y-b.y;
  return sqrt(dx*dx+dy*dy);
}

int main()
{

  //cout << fixed << setprecision(10);
  
  int m; cin >> m;
  cout << 24+24-m;

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main() {
  int n = 0;
  char s[10240];
  int i = 0;
  scanf("%d", &n);
  scanf("%s", s);

  for (i = 0; i < 10240; i++) {
    if (s[i] == '\0') { break; }
    s[i] = (s[i] - 'A' + n) % 26 + 'A';
  }

  printf("%s\n", s);
}


Measured memory_bytes: 128
n,m,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))

for i in range(n):
    if i == 0:
        continue
    else:
        a[i] += a[i-1]

for i in range(m):
    if i == 0:
        continue
    else:
        b[i] += b[i - 1]

a = [0]+a
b = [0]+b

i = 0
j = m
ans = 0

while a[i] <= k:
    while b[j] > k-a[i]:
        j -= 1
        if j<0:
            j=0
            break

    ans =max(ans,i+j)
   
    i += 1
    if i > n:
        break

print(ans)


Measured memory_bytes: 118144
# a_k の値を x に更新
def update(k, x):
    k += T0-1
    data[k] = x
    while k >= 0:
        k = (k - 1) // 2
        data[k] = max(data[2*k+1], data[2*k+2])
# 区間[l, r)の最小値
def query(l, r):
    L = l + T0; R = r + T0
    s = 0
    while L < R:
        if R & 1:
            R -= 1
            s = max(s, data[R-1])

        if L & 1:
            s = max(s, data[L-1])
            L += 1
        L >>= 1; R >>= 1
    return s
#================================================
N,K=map(int,input().split())
A=[0]*N
for i in range(N):
    A[i]=int(input())

T=max(A)
T0=2**(T.bit_length())
data=[0]*(2*T0)

DP=[0]*N
for i in range(N-1,-1,-1):
    X=query(max(A[i]-K,0),min(A[i]+K,T)+1)
    DP[i]=X+1
    update(A[i],X+1)

print(max(DP))

Measured memory_bytes: 130844
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String tmpS = scanner.next();
        String S[] = tmpS.split("");
        String tmpT = scanner.next();
        String T[] = tmpT.split("");
        int count = 0;

        scanner.close();
        for (int i = 0; i < tmpS.length(); i++){
            if (!(S[i].equals(T[i]))){
                count++;
            }
        }
        
        System.out.println(count);
    }
}


Measured memory_bytes: 66004
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

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

const long long INF = 1e18;
//const ll mod = 1000000007;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int l, r, d;
    cin >> l >> r >> d;
    int ans = r / d - (l - 1) / d;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
using namespace std;
#define rep(i,a,b) for(int64_t i=(a); i<(b); ++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int64_t i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
#define INF 1000000000000000;
#define MOD 1000000007LL;
#define RANGE(a,b,c) (a).begin()+(b),(a).begin()+(c) // [b,c) イテレータ
typedef pair<int64_t, int64_t> PII;
typedef vector<int64_t> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;

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

int64_t N, K, R, S, P;
string T;
cin>> N >> K >> R >> S >> P >> T;

int64_t ans = 0;
rep(i, 0, K){
    if (T[i] == 'r') ans += P;
    else if (T[i] == 's') ans += R;
    else if (T[i] == 'p') ans += S;
    char prev = T[i];
    for (int j = i + K; j < N; j += K){
        if (prev != T[j]) {
            if (T[j] == 'r') ans += P;
            else if (T[j] == 's') ans += R;
            else if (T[j] == 'p') ans += S;
            prev = T[j];
        }
        else 
            prev = 'a';
    }
}


cout << ans << endl;



}
// 書いて考える
// 境界，出力文字列 チェック
// 可読性優先．高速化次点．
// まずは全探索，分割統治，次にDP
// 制限を見る．境界に注意．求めたい量の変域．動かせる量．
// 偶奇，逆から，ソート，出現回数，出現位置，DP， 余事象，包除
// データ構造． 問題の特徴量．単調性，二分探索
// 存在判定：構成方法，入力の特徴
// gcd, lcm ,素因数分解．
// 例外を十分に含む一般化．想像力の限界
// 小さい系から例示
// 代数的処理
// 始めは過剰に例示・場合分けしてもいい．各場合を確実に対処．
// 自明な例から処理，除外．
// 小数のときは，精度の設定する．doubel 変数に数値を入力するときは 123. とする．
// テストケース作成は数表あり



Measured memory_bytes: 512
# /user/bin/python
# -*- coding: utf-8 -*-

MX_KETA = 40
Bn = [0] * 40

def xor(n):
  As = [0] * 40
  if n % 4 in [1,2]:
    As[0] = 1
  for i in range(39):
    rem = (n+1)%(4*2**i)
    As[i+1] = max(0, rem-2*2**i) % 2
  return As

def solve(a,b):
  ans = 0
  for i in range(40):
    ans += (a[i]^b[i]) * 2**i
  return ans

A,B = map(int, input().split())
Ab = xor(A-1)
Bb = xor(B)
print(solve(Ab, Bb))


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

using namespace std;
typedef long long ll;
typedef pair<int,int> PI;
const double EPS=1e-8;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define F first
#define S second
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define SZ(a) (int)((a).size())
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) a.rbegin(),a.rend()
#define FLL(a,b) memset((a),b,sizeof(a))
#define CLR(a) FLL(a,0)
#define declare(a,it) __typeof(a) it=(a)
#define FOR(it,a) for(declare(a.begin(),it);it!=a.end();++it)
#define FORR(it,a) for(declare(a.rbegin(),it);it!=a.rend();++it)
template<class T,class U> ostream& operator<< (ostream& o, const pair<T,U>& v){return o << "(" << v.F << ", " << v.S << ")";}
template<class T> ostream& operator<< (ostream& o, const vector<T>& v){o << "{";rep(i,SZ(v)) o << (i?", ":"") << v[i];return o << "}";}
int dx[]={0,1,0,-1,1,1,-1,-1};
int dy[]={1,0,-1,0,-1,1,1,-1};
int s2i(string& a){stringstream ss(a);int r;ss>>r;return r;}
int geti(){int n;scanf("%d", &n);return n;}

int x[100],y[100];


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

  double sumx = 0;
  double sumy = 0;
  for(int i = 0; i < n; ++i){
    cin >> x[i] >> y[i];
    sumx += x[i];
    sumy += y[i];
  }
  sumx /= n;
  sumy /= n;
  
  bool ok = true;
  for(int i = 0; i < n; ++i){
    double ax = x[(i+1)%n] - x[i];
    double ay = y[(i+1)%n] - y[i];
    double bx = x[(i+1+n/2)%n] - x[(i+n/2)%n];
    double by = y[(i+1+n/2)%n] - y[(i+n/2)%n];
    ok &= abs(ax*by - bx*ay) < EPS;
    ok &= abs(ax*ax+ay*ay-(bx*bx + by*by)) < EPS;
  }
  
  if(ok && ~n%2) printf("%.10f %.10f\n", sumx, sumy);
  else cout << "NA" << endl;
  
  return 0;
}

Measured memory_bytes: 1204
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <tuple>
#include <iomanip>
#include <climits>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
//typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define revrep(i, n) for(ll i = (n)-1; i >= 0; i--)
#define pb push_back
#define f first
#define s second
#define chmin(x, y) x = min(x, y);
#define chmax(x, y) x = max(x, y);

//const ll INFL = LLONG_MAX;//10^18 = 2^60
const ll INFL = 1LL<<60;
//const int INF = INT_MAX;
const ll INF = 1 << 30;//10^9
ll MOD = 1000000007;
//ll MOD = 998244353;

vector<ll> dy = {0, 1, 0, -1, 1, 1, -1, -1, 0};
vector<ll> dx = {1, 0, -1, 0, 1, -1, 1, -1, 0};

void pres(double A, ll x = 10){cout << fixed << setprecision(x) << A << endl;}
void BinarySay(ll x, ll y = 60){rep(i, y) cout << (x>>(y-1-i) & 1); cout << endl;}
ll cnt_bit(ll x){return __builtin_popcountll(x);}

ll pow_long(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2) res *= x;
    x *= x; k /= 2;
  }
  return res;
}

ll pow_mod(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2){
      res *= x; res %= MOD;
    }
    x *= x; x %= MOD;
    k /= 2;
  }
  return res;
}

ll inverse(ll x){return pow_mod(x, MOD - 2);};

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

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

//コンビネーション
const int MAXcomb = 200010;
ll fac[MAXcomb], finv[MAXcomb], inv[MAXcomb];
//facはn!,finvは1/n!
//invは逆元
void COMinit(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < MAXcomb; i++){
        fac[i] = fac[i-1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
        finv[i] = finv[i-1] * inv[i] % MOD;
    }
}
ll comb(int n, int k){
    if(n < k) return 0;
    if(n < 0 || k < 0) return 0;
    return fac[n] * finv[k] % MOD * finv[n-k] % MOD;
}



void solve(){
  ll N, K;
  cin >> N >> K;
  vector<string> A(K, "");
  ll R, S, P;
  cin >> R >> S >> P;
  string T;
  cin >> T;
  rep(i, T.size()){
    A[i%K] += T[i];
  }
  ll ans = 0;
  rep(i, K){
    string s = A[i];
    rep(j, s.size()){
      if(j + 1 < s.size() && s[j] == s[j+1]){
        if(s[j] == 'r'){
          ans += P;
          j++;
        }else if(s[j] == 'p'){
          ans +=  S;
          j++;
        }else{
          ans += R;
          j++;
        }
      }else{
        if(s[j] == 'r'){
          ans += P;
        }else if(s[j] == 'p'){
          ans += S;
        }else{
          ans += R;
        }
      }
    }
  }
  cout << ans << endl;
}

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


Measured memory_bytes: 5200
// code.begin();
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define pb push_back 
#define what_is(x) cerr<<#x<<" is "<<x<<endl;
#define print(v) for(auto i:v) cout<<i<<" ";cout<<endl;
#define my_time ios_base::sync_with_stdio(false);cin.tie(NULL);
#define ll long long 
#define endl "\n"
#define MOD 1000000007
const long long int INF=1e18;
#define mod 1000000007
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
typedef tree<int, null_type, less<int>, rb_tree_tag, 
             tree_order_statistics_node_update> 
    ordered_set; 
//find_by_order(x)
//order_of_key(x)  


int power(int x,unsigned int y)
{
    int res=1;
    
    while(y>0)
    {
        // if y is odd multiply with result
        if(y&1)
        res=res*x;
        
        y=y>>1; // y=y/2;
        x=x*x;
        
    }
    return res;
}

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

ll  max3(ll  a, ll  b, ll c)
{
    return max(c, max(a, b));
}
int min3(int a, int  b, int  c)
{
    return min(a, min(b, c));
}

int  powermod(int  x, int  y, int p )
{
    int res = 1;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res % p;
}
int logg(int  a)
{
    int  x = 0;
    while (a > 1)
    {
        x++;
        a /= 2;
    }
    return x;
}


int modinv(int x)
{
    return powermod(x, mod - 2, mod);
}
const int nax=1e5+5;

vector<int> dp(nax,-1);
  vector<int> arr[nax+1];
  vector<bool> vis(nax+1,false);
  int dfs(int u)
  {
      if(dp[u]!=-1)
      return dp[u];
      int temp=0;
      for(int i:arr[u])
      {
          temp=max(temp,dfs(i)+1);
      }
      return dp[u]=temp;
  }




int  main(){
	my_time;

int t;
t=1;
//cin>>t;int test=0;
while(t--)
{
   
  int n;
  cin>>n;
  int m;
  cin>>m;

  int a,b;
  for(int i=0;i<m;i++)
  {
      cin>>a>>b;
      arr[a].push_back(b);
  }
  
  int ans=0;
  for(int i=1;i<=n;i++)
  {
      ans=max(ans,dfs(i));
     // cout<<dfs(i)<<endl;
  }
   cout<<ans<<endl;
   
}
    return 0;
}


//code.end();





Measured memory_bytes: 11128
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b;
  cin >> a >> b;
  int s[13]={13,1,2,3,4,5,6,7,8,9,10,11,12};
  if(a==b){
    cout << "Draw";
  }else if(s[a-1]>s[b-1]){
    cout << "Alice";
  }else{
    cout << "Bob";
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <iomanip>

using namespace std;

int main() {
	double n,x[100],y[100],d1sum,d2sum,d3sum,dinf;
	d1sum = 0;
	d2sum = 0;
	d3sum = 0;
	cin >> n;
	for(int i = 0;i < n ; i++){
		cin >> x[i];
	}
	for(int i = 0;i < n ; i++){
		cin >> y[i];
		d1sum +=fabs(x[i]-y[i]);
		d2sum +=pow(fabs(x[i]-y[i]),2);
		d3sum +=pow(fabs(x[i]-y[i]),3);
		dinf = max(fabs(x[i]-y[i]),dinf);
	}
	cout << fixed << setprecision(6) << d1sum << endl << pow(d2sum,1.0/2.0) << endl << pow(d3sum,1.0/3.0) << endl << dinf << endl;
    return 0;
}

Measured memory_bytes: 3452
A = list(input())

for i in range(2**3):
    num = int(A[0])
    ans = A[0]
    for j in range(3):
        if ((i >> j)&1):
           num += int(A[j+1])
           ans += "+"+A[j+1]
        else:
           num -= int(A[j+1])
           ans += "-"+A[j+1]
    if num == 7:
        print(ans+"=7")
        break

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順

int main() {
    int N; cin >> N;
    vector<int> V;
    int prev = INT32_MAX;
    rep(i,N) {
        int a; cin >> a;
        if (a == prev) continue;
        prev = a;
        V.push_back(a);
    }
    N = V.size();

    bool up;
    int i = 0;
    ll res = 0;
    while (i < N) {
        res++;
        if (i == N-1) break;
        up = (V[i] < V[i+1]);
        if (up) {
            while (i < N-1 && V[i] < V[i+1]) i++;
        } else {
            while (i < N-1 && V[i] > V[i+1]) i++;
        }
        i++;
    }
    cout << res << endl;
}


Measured memory_bytes: 3848
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define INF 1<<30
#define LINF 1LL<<60

int main(void) {
	cin.tie(0); ios::sync_with_stdio(false);
	string S; cin >> S;
	bool s, e, n, w;
	s = e = n = w = false;
	for (int i = 0; i < S.length(); i++) {
		if (S[i] == 'S')s = true;
		else if (S[i] == 'E') e = true;
		else if (S[i] == 'N') n = true;
		else w = true;
	}
	if (s == n && e == w) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return		0;
}

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

int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> v(n);

  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    v[a].push_back(b);
    v[b].push_back(a);
  }

  bool ok = false;
  for (auto s : v[0]) {
    for (auto t : v[s])
      if (t == n - 1) {
        puts("POSSIBLE");
        return 0;
      }
  }

  puts("IMPOSSIBLE");
  return 0;
}


Measured memory_bytes: 12016
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string s;
  cin >>s;
  long long t;
  cin >>t;
  for(int i=0;i<s.size();i++){
    if(s.at(i) !='1'&&t>i){
      cout << s.at(i);
      return 0;
    }
  }
  cout << "1";
}

Measured memory_bytes: 256
void main() {
    int[] abc = readln.split.to!(int[]);
    auto g = abc.sort!"a < b".group.assocArray;
    foreach (key, val; g) {
        if (val == 1) key.writeln;
    }
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni;

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

public class AtCoderA
{
    static void Main()
    {
        Dictionary<string, int> dic = new Dictionary<string, int>();
        {
            var line = Console.ReadLine();
            for (int i = 0; i < 4; i++)
            {
                string str = line.Substring(i, 1);
                if (!dic.ContainsKey(str))
                {
                    dic.Add(str, 1);
                }
                else
                {
                    dic[str] = dic[str] + 1;
                }
            }
        }
        foreach (var item in dic)
        {
            if (item.Value != 2)
            {
                Console.WriteLine("No");
                return;
            }
        }
        Console.WriteLine("Yes");
    }
}

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

int main() {
    int n;
    string s;
    cin >> n >> s;
    int x = 0, mx = 0;
    for (int i = 0; i < n; i++) {
        char ID = s[i];
        if (ID == 'I') {
            mx = max(mx, ++x);
        } else {
            mx = max(mx, --x);
        }
    }
    cout << mx << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main()
{
    int len,i;
    char a[100000];
    while(scanf("%s",a)!=EOF)
    {
        getchar();
        len=strlen(a);
        for(i=0;i<len;i++)
        {
            if(i%2==0)
                printf("%c",a[i]);
        }
        memset(a,0,sizeof(a));
        printf("\n");
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <map>
#include <set>
#include <algorithm>
using namespace std;
#define MAX 100000

int main(){
  int n;
  cin >>n;
  int A[n+2][n+2]={0};
  int t,k,l;
  for(int i=1;i<=n;i++){
    cin >> t >> k;
    for(int j=1;j<=k;j++){
      cin >> l;
      A[i][l]=1;
    }
  }
  for(int i=1;i<=n;i++){
    for(int j=1;j<=n;j++){
      if(j-1) cout << " ";
      cout << A[i][j];
    }
    cout << endl;
  }
  return 0;
}


Measured memory_bytes: 3116
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

  public static void main(String[] args) throws IOException {
    
    try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {

      int n = Integer.parseInt(br.readLine());
      int[] seqS = new int[n];
      String[] line = br.readLine().split(" ");
      for (int i=0; i<n; i++)
        seqS[i] = Integer.parseInt(line[i]);

      int q = Integer.parseInt(br.readLine());
      String[] lines = br.readLine().split(" ");
      
      int cnt=0;
      for (String ref : lines) {
        if( isExistSeachByBinary(seqS, Integer.parseInt(ref)) )
          cnt++;
      }

      System.out.println(cnt);
    }
  }

  static boolean isExistSeachByBinary(int[] tar, int ref) {
    int left = 0;
    int right= tar.length;
    int mid;
    while( left < right ) {
      mid  = (left + right) / 2;
      if( tar[mid] > ref ) right = mid;
      else if(tar[mid] < ref ) left = mid + 1;
      else return true;
    }

    return false;
  }
}


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

using namespace std;

using int64 = long long;
const int mod = 1e9 + 7;

const int64 infll = (1LL << 62) - 1;
const int inf = (1 << 30) - 1;

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
  }
} iosetup;


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

template< typename T1, typename T2 >
istream &operator>>(istream &is, pair< T1, T2 > &p) {
  is >> p.first >> p.second;
  return is;
}

template< typename T >
ostream &operator<<(ostream &os, const vector< T > &v) {
  for(int i = 0; i < (int) v.size(); i++) {
    os << v[i] << (i + 1 != v.size() ? " " : "");
  }
  return os;
}

template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}

template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

template< typename T = int64 >
vector< T > make_v(size_t a) {
  return vector< T >(a);
}

template< typename T, typename... Ts >
auto make_v(size_t a, Ts... ts) {
  return vector< decltype(make_v< T >(ts...)) >(a, make_v< T >(ts...));
}

template< typename T, typename V >
typename enable_if< is_class< T >::value == 0 >::type fill_v(T &t, const V &v) {
  t = v;
}

template< typename T, typename V >
typename enable_if< is_class< T >::value != 0 >::type fill_v(T &t, const V &v) {
  for(auto &e : t) fill_v(e, v);
}

template< typename T >
struct WeightedUnionFind {
  vector< int > data;
  vector< T > ws;

  WeightedUnionFind() {}

  WeightedUnionFind(int sz) : data(sz, -1), ws(sz) {}

  int find(int k) {
    if(data[k] < 0) return k;
    auto par = find(data[k]);
    ws[k] += ws[data[k]];
    return data[k] = par;
  }

  T weight(int t) {
    find(t);
    return ws[t];
  }

  bool unite(int x, int y, T w) {
    w += weight(x);
    w -= weight(y);
    x = find(x), y = find(y);
    if(x == y) return false;
    if(data[x] > data[y]) {
      swap(x, y);
      w *= -1;
    }
    data[x] += data[y];
    data[y] = x;
    ws[y] = w;
    return true;
  }

  T diff(int x, int y) {
    return weight(y) - weight(x);
  }
};


int main() {
  int N, M;
  while(cin >> N >> M, N) {
    WeightedUnionFind< int > tree(N);
    while(M--) {
      char A;
      int B, C, D;
      cin >> A >> B >> C;
      --B, --C;
      if(A == '!') {
        cin >> D;
        tree.unite(B, C, D);
      } else {
        if(tree.find(B) == tree.find(C)) {
          cout << tree.diff(B, C) << endl;
        } else {
          cout << "UNKNOWN" << endl;
        }
      }
    }
  }
}




Measured memory_bytes: 3632
//author:emre yazicioglu

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
#define fori(a,b,c) for(ll a = b;a < ll(c);a++)
#define ford(a,b,c) for(ll a = b;a >= ll(c);a--)
#define pb push_back

const int N = 2e6 + 7;
ll n,m,k,cnt,cur,ans;
ll dp[N],ar[N];
vector <ll> v;

int main(){

	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);

	// freopen("in.txt","r",stdin);
	// freopen("out.txt","w",stdout);

	cin >> n;
	fori(i,1,n + 1)
		cin >> ar[i];
	
	dp[2] = abs(ar[1] - ar[2]);
	fori(i,3,n + 1)
		dp[i] = min(dp[i - 2] + abs(ar[i - 2] - ar[i]), dp[i - 1] + abs(ar[i - 1] - ar[i])); 
	
	cout << dp[n];

}

Measured memory_bytes: 5120
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)

using lint = long long;
using plint = pair<double, lint>;

int N;
lint L;

array<plint, 500000> deq;
int s = 0;
int t = -1;

double Qsum = 0;
lint Vnow = 0;

void trim()
{
    while (Vnow > L)
    {
        lint nuku = min(Vnow - L, deq[s].second);
        deq[s].second -= nuku;
        Vnow -= nuku;
        Qsum -= nuku * deq[s].first;
        if (deq[s].second == 0) s++;
    }
}

void add(double tadd, lint vadd)
{
    if (deq[t].first < tadd) // 追加するほうが高温の場合、先頭から余剰分を抜いていく
    {
        t++; deq[t] = plint(tadd, vadd);
        Qsum += tadd * vadd;
        Vnow += vadd;
        trim();
    }
    else // 低温の場合、うしろとくっつけていく
    {
        if (deq[t].second + vadd >= L)
        {
            Qsum = deq[t].first * (L - vadd) + tadd * vadd;
            Vnow = L;
            s = 0, t = -1;
            t++; deq[t] = plint(Qsum / L, L);
        }
        else
        {
            double Qaddnew = deq[t].first * deq[t].second + tadd * vadd;
            lint vaddnew = deq[t].second + vadd;
            Qsum -= deq[t].first * deq[t].second;
            Vnow -= deq[t].second;
            t--;
            add(Qaddnew / vaddnew, vaddnew);
        }
    }
}

array<double, 500000> res;

array<double, 500000> temps;
array<lint, 500000> vs;

int main()
{
    cin >> N >> L;
    // scanf("%d", &N);
    // scanf("%lld", &L);
    REP(i, N) cin >> temps[i] >> vs[i];
    REP(i, N)
    {
        // double tmp;
        // lint v;
        // scanf("%lf %lld", &tmp, &v);

        if (i == 0)
        {
            t++; deq[t] = plint(temps[i], vs[i]);
            Qsum = temps[i] * vs[i];
            Vnow = vs[i];
        }
        else add(temps[i], vs[i]);

        res[i] = Qsum / L;
    }
    REP(i, N) printf("%.7f\n", res[i]);
}


Measured memory_bytes: 28544
from operator import itemgetter

N = int(input())
SP = []
lst = []
for i in range(N):
  lst = list(input().split())
  lst.append(i+1)
  SP.append(lst)
  SP[i][1] = int(SP[i][1])
SP = sorted(SP, key=itemgetter(1), reverse=True)
SP = sorted(SP, key=itemgetter(0))

for i in range(N):
  print(SP[i][2])

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 29;
struct graph{
    int ob;
    int di;
};
int main(){
    int N;
    cin >> N;
    vector<int> a(N), b(N), c(N);
    vector<vector<graph>> d(N + 1, vector<graph>(0));
    for (int i = 1; i <= N - 1; i++){
        cin >> a.at(i) >> b.at(i) >> c.at(i);
        graph g = {b.at(i), c.at(i)}, h = {a.at(i), c.at(i)};
        d.at(a.at(i)).push_back(g);
        d.at(b.at(i)).push_back(h);
    }
    int Q, K;
    cin >> Q >> K;
    vector<int> x(Q + 1), y(Q + 1);
    for (int i = 1; i <= Q; i++){
        cin >> x.at(i) >> y.at(i);
    }
    
    vector<int64_t> KY(N + 1, INF);
    KY.at(0) = 0;
    d.at(0).push_back({K, 0});
    stack<int> q;
    q.push(0);
    while (!q.empty()){
        int st = q.top();
        q.pop();
        for(int i = 0; i < d.at(st).size(); i++){
            int st_1 = d.at(st).at(i).ob;
            int ky_1 = d.at(st).at(i).di;
            if (KY.at(st_1) != INF) continue;
            else{
                q.push(st_1);
                KY.at(st_1) = KY.at(st) + ky_1;
            }
        }
    }
    for (int i = 1; i <= Q; i++){
        cout << KY.at(x.at(i)) + KY.at(y.at(i)) << endl;
    }
}

Measured memory_bytes: 10740
T = int(input())
def gcd(a,b):
	if a < b:
		a,b = b,a
	while b > 0:
		c = a % b
		a = b
		b = c
	return a

YES = 'Yes'
NO = 'No'
for i in range(T):
	A,B,C,D = map(int,input().split())
	if D < B or A < B:
		print(NO)
		continue
	D = D % B
	if C >= B:
		print(YES)
		continue
	rest = A % B
	if rest > C:
		print(NO)
		continue
	if D == 0:
		print(YES)
		continue
	g = gcd(B,D)
	left = C - rest
	right = B - rest
	n = left // g + 1
	if n * g < right:
		print(NO)
	else:
		print(YES)

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

int main()
{
    string s, t;
    cin >> s >> t;
    int n = sz(s), m = sz(t);
    vector<vector<int>> is(26);
    rep (i, n) {
        is[s[i] - 'a'].push_back(i);
    }
    rep (i, n) {
        is[s[i] - 'a'].push_back(i + n);
    }

    ll ans = 0;
    int p = 0;
    rep (i, m) {
        int c = t[i] - 'a';
        if (sz(is[c]) == 0) {
            puts("-1");
            return 0;
        }

        p = *lower_bound(is[c].begin(), is[c].end(), p) + 1;
        if (p >= n) {
            p -= n;
            ans += n;
        }
    }

    ans += p;
    cout << ans << endl;
    return 0;
}


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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) for(i64 i = 1; i <= n; ++i)
#define RREP(i, n) for(i64 i = n - 1; i >= 0 ; --i)
#define RREPS(i, n) for(i64 i = n; i >= 1; --i)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define pb push_back
#define mp make_pair
#define F first
#define S second

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 (b<a) { a=b; return 1; } return 0; }

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }


struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


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

    i64 cnt = 0;

    auto calc_divisor = [](i64 n) {
        vector<i64> res;
        for (i64 x = 2; x * x <= n; x++) {
            if (n % x == 0) {
                res.pb(x);
                if (x * x != n) res.pb(n / x);
            }
        }
        if (n != 1) res.pb(n);

        return res;
    };

    vector<i64> ndiv = calc_divisor(N);
    REP(i, ndiv.size()) {
        i64 n = N;
        while (n % ndiv[i] == 0) n /= ndiv[i];
        if (n % ndiv[i] == 1) cnt++;
    }

    vector<i64> nm1div = calc_divisor(N - 1);
    cnt += nm1div.size();

    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 384
// In the name of God

#include <bits/stdc++.h>

using namespace std;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int n, r;	
	cin >> n >> r;
	if(n >= 10) cout << r;
	else cout << r+100*(10-n);
	return 0;
}


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

using namespace std;

int64_t solve(int64_t a, int64_t b, int64_t x) {
  int64_t ret = b / x;
  if (a == 0) {
    ret++;
  } else {
    ret -= (a - 1) / x;
  }
  return ret;
}

int main() {
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);
  int64_t a;
  std::cin >> a;
  int64_t b;
  std::cin >> b;
  int64_t x;
  std::cin >> x;
  auto const res = solve(a, b, x);
  std::cout << res << std::endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
    using namespace std;
     
    int main() {
		int N,R=0;
    	cin >> N;
    	vector<int> d(N);
    	for (int i=0; i<N; i++){
    		cin >> d.at(i);
    	}
    	for (int i=0; i<N-1; i++){
    		for (int j=i+1; j<N; j++){
    			R += d.at(i)*d.at(j);
    		}
    	}
    	cout << R << endl;
    	
    }

Measured memory_bytes: 256
#include<iostream>

using namespace std ;

int main()
{
	int h ,w ;
	while( cin >> h >> w ,h | w )
	{
			for( int i = w ; i > 0 ; i-- ,cout << "#" ) ;
		for( ; h > 2 ; h-- )
		{
			cout << endl << "#" ;
			for( int i = w - 1 ; i > 1 ; i-- ,cout << "." ) ;
			cout << "#" ;
		}
		cout << endl ;
		for( ; w > 0 ; w-- ,cout << "#" ) ;
		cout << endl << endl ;
	}
	return 0 ;
}

Measured memory_bytes: 3056
N = int(input())
a = list(map(int, input().split()))

res = [-1 for i in range(N//2)] + [ai for ai in a[N//2 : N]]

for i in range(N//2, 0, -1):
    res[i-1] = (sum(res[2*i-1:N:i]) % 2) ^ a[i-1]

ans = [i+1 for i in range(N) if res[i] == 1]
print(len(ans))

if len(ans) != 0:
    print(' '.join(list(map(str,ans))))

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

#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) cin>>aa;(p).push_back(aa);
#define vecpl2(p) long long a	b;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define MOD 1000000007
#define cey ce("Yes")
#define cen ce("No")
#define ceY ce("YES")
#define ceN ce("NO")
ll dp[30000][10];
ll dp2[30000][10];

int main()
{
	int N;
	string S;
	cin >> N >> S;
	map<string, int> K;

	for (int x = 1; x < N - 1;x++) {
		fy(10) {
			dp[x][y] = dp[x - 1][y];
		}
		dp[x][S[x - 1] - '0'] = 1;
	}

	for (int x = N-2; x >= 0; x--) {
		fy(10) {
			dp2[x][y] = dp2[x + 1][y];
		}
		dp2[x][S[x + 1] - '0'] = 1;
	}

	for (int x = 1; x < N - 1; x++) {
		fy(10) {
			fz(10) {
				if (dp[x][y]==1&&dp2[x][z]==1) {
					string ans= to_string(y).c_str();
					ans+= to_string(S[x]-'0').c_str();
					ans += to_string(z).c_str();
					K[ans] = 1;
				}
			}
		}
	}
	int sum = 0;
	fx(10) {
		fy(10) {
			fz(10){
				string ans = to_string(x).c_str();
				ans += to_string(y).c_str();
				ans+=to_string(z).c_str();
				sum += K[ans];
		}
		}
	}
	ce(sum)


    return 0;
}



Measured memory_bytes: 5120
#include <iostream>
#include<string>
#include<cstring>
#include <cstdio>
#include<utility>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<bitset>
#include<queue>
#include<stack>
#include<set>
#include <limits>
#include <climits>
#include <numeric>
#include <cassert>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<int>VI;
typedef pair<int,int>P;
typedef pair<double,double>P_D;
#define PI 3.1415926535897932384626433832795
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define reprev(i, n) for (ll i = (ll)n - 1; i >= 0; i--)
#define ALL(a)  (a).begin(),(a).end()
#define C_MAX(a, b) ((a)>(b)?(a):(b))
#define fi first
#define se second
#define MAX 100100//5
#define MAX_N 200100
#define MAX_B 1001001//6
#define MAX_S 10010010//7
#define SENTINEL 2000000000//9
#define NIL -1
#define MOD 1000000007
#define INF 1 << 29
#define INFTY 1000000000000000000LL
#define MAX_INT INT_MAX

int main(){
    ll n;cin>>n;
    vector<ll>a(n);
    rep(i,n)cin>>a[i];
    deque<ll>dq;
    rep(i,n){
        ll idx=lower_bound(ALL(dq),a[i])-dq.begin();
        if(idx==0)dq.push_front(a[i]);
        else dq[idx-1]=a[i];
    }
    cout<<dq.size()<<endl;
}

Measured memory_bytes: 1792
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
const int mod=1e9+7;
int a[1011],b[1011];
int main()
{
	int n;
	scanf("%d",&n);
	a[0]=a[1]=-1;
	for(int i=2;i<=1001;i++)
	{
		if(a[i]==0)
		{
			for(int j=2;j*i<1001;i++)
			a[j*i]=-1;
		}
	}
	int s=1;
	for(int i=2;i<1001;i++)
	{
		if(a[i]==0)
		b[s++]=i;
	}
	for(int i=2;i<=n;i++)
	{
		int k=i,j=1;
		while(k>1)
		{
			while(k%b[j]==0)
			{
				a[b[j]]++;
				k/=b[j];
			}
			j++;
		}
	}
	long long ans=1;
	for(int i=0;i<=n;i++)
	if(a[i]!=-1)
	ans=ans*(a[i]+1)%mod;
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
// Begin Header {{{
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i,n) for(ll i=0; i<n; i++)
#define loop(i, j, n) for(ll i=j; i<n; i++)
#define all(x) (x).begin(), (x).end()
constexpr int INF  = 0x3f3f3f40;
const long long mod=1e9+7;
const long double PI = acos(0);
template <class T>void UNIQUE(vector<T> &x){
	sort(all(x));
	x.erase(unique(all(x)), x.end());
}

// }}} End Header
int main() {
	int h, w;
	cin >> h >> w;
	vector<string> s(h);
	rep(i,h){
		cin >> s[i];
	}
	vector<int>x = {1, -1, 0, 0};
	vector<int>y = {0, 0, 1, -1};
	rep(i,h){
		rep(j,w){
			if(s[i][j] == '#'){
				bool ok = false;
				rep(k,4){
					if(i+y[k]<0 || i+y[k]>=h || j+x[k]<0 || j+x[k]>=w) continue;
					if(s[i+y[k]][j+x[k]] == '#') ok = true;
				}
				if(!ok){
					cout << "No" << endl;
					return 0;
				}
			}
		}
	}
	cout << "Yes" << endl;
	
	return 0;
}

Measured memory_bytes: 3624