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

typedef long long ll;
#define endl "\n"

const int M = (int) 1e9+7;
int n,k;
ll ans=1;
vector<ll> pos, neg;
int pcnt=0, ncnt=0;

ll solve(){
    cin>>n>>k;
    for (int i=0; i<n; ++i){
        ll foo; cin>>foo;
        if (foo>0) pos.push_back(foo);
        else neg.push_back(abs(foo));
    }
    sort(pos.begin(), pos.end());
    sort(neg.begin(), neg.end());
    int P=pos.size(), N=neg.size();
    if (k==n ? N%2==0 : P || k%2==0){
        reverse(pos.begin(), pos.end());
        reverse(neg.begin(), neg.end());
        for ( ; k; --k){
            if (pcnt<P && (ncnt>=N || pos[pcnt]>neg[ncnt])){
                ans=ans*pos[pcnt]%M; ++pcnt;
            }
            else{
                ans=ans*neg[ncnt]%M; ++ncnt;
            }
        }
        if (ncnt&1){
            ans=1;
            if (pcnt<P && ncnt>=1 && (ncnt>=N || pcnt<1 || pos[pcnt]*pos[pcnt-1]>neg[ncnt]*neg[ncnt-1])){
                for (int tt=0; tt<pcnt+1; ++tt)
                    ans=ans*pos[tt]%M;
                for (int tt=0; tt<ncnt-1; ++tt)
                    ans=ans*neg[tt]%M;
            }
            else{
                for (int tt=0; tt<pcnt-1; ++tt)
                    ans=ans*pos[tt]%M;
                for (int tt=0; tt<ncnt+1; ++tt)
                    ans=ans*neg[tt]%M;
            }
        }
        return ans%M;
    }
    ans=1;
    for(int i=0, j=0; k; --k) {
        if(i<pos.size()&&(j>=neg.size()||pos[i]<neg[j])) {
            ans=ans*pos[i]%M;
            ++i;
        } else {
            ans=ans*neg[j]%M;
            ++j;
        }
    }
    return (M-ans)%M;
}

int main(){
    // INT VS LL
    // freopen("input.txt", "r", stdin);
    //    INT VS LL
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout<<solve();
    return 0;
}

Measured memory_bytes: 5676
#include <bits/stdc++.h>
using namespace std;
#define __ <<" "<<
#define ___ <<" "
#define bash push_back
#define ALL(x) x.begin(),x.end()
//#define int long long

struct IoSetup {
    IoSetup() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout <<fixed<<setprecision(12);
        cerr <<fixed<<setprecision(12);
    }
}IoSetup;

typedef long long ll;
typedef pair < int , int >  pii;
using piii = pair<int , pii>;
static constexpr const signed int INF = 0x3f3f3f3f;
static constexpr const signed long long LINF = 0x3f3f3f3f3f3f3f3fLL;
static constexpr const signed int SMOD = 1000000007;
static constexpr const signed int NMOD = 998244353;
static constexpr const signed int dx[]={1,0,-1,0,1,1,-1,-1};
static constexpr const signed int dy[]={0,-1,0,1,-1,1,-1,1};

inline bool inside(int x,int y,int w,int h){return (x>=0 && y>=0 && x<w && y<h);}
template<class T>bool chmax(T &a, const T &b){return(a=max(a,b))==b;}
template<class T>bool chmin(T &a, const T &b){return(a=min(a,b))==b;}
inline int qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}

int n, q;
int s[200200], t[200200], x[200200];
int d[200200];

multiset<int> stop;

signed main() {

    cin >> n >> q;
    vector<piii> v;
    for(int i = 0; i < n; i++) {
        cin >> s[i] >> t[i] >> x[i];
        v.bash({s[i]-x[i], {0, x[i]}});
        v.bash({t[i]-x[i], {1, x[i]}});
    }

    for(int i = 0; i < q; i++) {
        cin >> d[i];
        v.bash({d[i], {2, 0}});
    }
    
    sort(ALL(v));
    v.bash({INF, {-1, INF}});
    
    for(int i = 0; i < v.size()-1; i++) {
        int t = v[i].first, q = v[i].second.first, u = v[i].second.second;
        if(q == 0) {
            stop.insert(u);
        }
        else if(q == 2) {
            if(stop.size()) 
                cout << *stop.begin() << endl;
            else
                cout << -1 << endl;
        }
        else {
            stop.erase(stop.lower_bound(u));
        }    
    }

  
    return 0;
}



Measured memory_bytes: 20840
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> P;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

void YN(bool flg){if(flg) cout << "YES" << endl; else cout << "NO" << endl;}
void Yn(bool flg){if(flg) cout << "Yes" << endl; else cout << "No" << endl;}
void yn(bool flg){if(flg) cout << "yes" << endl; else cout << "no" << endl;}

//素因数分解
vector<pair<ll, ll>> prime_factorize(ll n) {
    vector<pair<ll, ll>> res;
    for(ll i = 2; i * i <= n; i++) {
        if(n % i != 0) continue;
        ll ex = 0;

        while(n % i == 0) {
            ex++;
            n /= i;
        }

        res.push_back({i, ex});
    }

    if(n != 1) res.push_back({n, 1});
    return res;
}

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

    const auto &res = prime_factorize(n);

    ll ans = n;
    for(auto p : res) {
        ans *= p.first - 1;
        ans /= p.first;
    }

    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 3092
N = int(input())
lists= []
for i in range(N):
    a,b = [x for x in input().split()]
    lists.append([a,int(b)])
X = input()
add_time = False
add = 0
for i in range(N):
    if add_time == True:
        add += lists[i][1]
    if X == lists[i][0]:
        add_time = True

print(add)

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

void sorts(int* xx,int* yy);

int main(){
  int x,y;
  cin>>x>>y;
  sorts(&x,&y);
  x=x%y;
  if(!x){
    cout<<y<<endl;
    return 0;
  }
  int ans=y;
  for(int i=x;i>=0;i--){
    if(y%i==0 && x%i==0){
      ans=i;
      break;
    }
  }
  cout<<ans<<endl;
}

void sorts(int* xx,int* yy){
  if(*xx<*yy){
    int temp=*xx;
    *xx=*yy;
    *yy=temp;
  }
  return;
}

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

int main(){
  int n;
  cin >> n;
  vector<string> w(n);
  map<string, int> cnt;
  for(int i = 0; i < n; i++){
    cin >> w.at(i);
    cnt[w.at(i)]++;
  }
  
  char now = w.at(0).back();
  bool ok = true;
  for(int i = 1; i < n; i++){
    if(now == w.at(i).at(0)){
      now = w.at(i).back();
      continue;
    }
    
    ok = false;
    break;
  }
  if(cnt.size() != n) ok = false;
  
  if(ok) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
A, B, C, D, E, F = tuple(map(int, input().split()))
max_con = 0
res = (100 * A, 0)
for i in range(F // (100 * A) + 1):
    for j in range(F // (100 * B) + 1):
        if i == 0 and j == 0:
            continue
        wat = (A * i + B * j)
        x = 100 * wat
        if F < x:
            continue
        for k in range(wat * E // C + 1):
            for l in range(wat * E // D + 1):
                y = C * k + D * l
                if wat * E < y:
                    continue
                total = x + y
                if F < total:
                    continue
                if max_con < y / total:
                    max_con = y / total
                    res = (total, y)
                    # print(x + y, y)
print(*res)


Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int cmpcount = 0;

void merge(vector<int> &a, int left, int mid, int right) {
    int n1 = mid - left, n2 = right - mid;
    vector<int> l(n1), r(n2);
    for(int i=0; i<n1; i++) l[i] = a[left + i];
    for(int i=0; i<n2; i++) r[i] = a[mid + i];
    int i=0, j=0;
    for(int k=left; k<right; k++) {
        cmpcount++;
        if(j==n2 || (i!=n1 && l[i] <= r[j])) {
            a[k] = l[i++];
        } else {
            a[k] = r[j++];
        }
    }
}

void mergesort(vector<int> &a, int left, int right) {
    if(left+1 < right) {
        int mid = (left + right) / 2;
        mergesort(a, left, mid);
        mergesort(a, mid, right);
        merge(a, left, mid, right);
    }
}

int main() {
    int n;
    cin >> n;
    vector<int> s(n);
    for(int i=0; i<n; i++) cin >> s[i];
    mergesort(s, 0, n);
    for(int i=0; i<n; i++) {
        cout << s[i] << (i==n-1 ? "\n" : " ");
    }
    cout << cmpcount << endl;
}


Measured memory_bytes: 6796
#include <bits/stdc++.h>
using namespace std;
int main() {
     int N;
     cin >> N;
    vector<int> P(N);
     for(int i = 0;i < N;i++){
          cin >> P[i];
     }
     
     int ans = 0;
     for(int i = 1;i < N-1;i++){
          if((P[i-1] < P[i]) && (P[i] < P[i+1])) ans++;
          else if((P[i-1] > P[i]) && (P[i] > P[i+1])) ans++;
     }

     cout << ans << endl;
}


Measured memory_bytes: 256
def rect(h, w):
    s = '#' * w
    while h > 1:
        print(s)
        s = '#' + '.' * (w - 2) + '#'
        h -= 1
    print('#' * w)
    print()
    return

while True:
    n = list(map(int, input().split()))
    H = n[0]
    W = n[1]
    if (H == 0 and W == 0):
        break
    rect(H, W)

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

using namespace std;
typedef long long ll;
#define debug(x) cerr << x << "\n"
#define all(x) (x).begin(),(x).end()
#define exist(s, e)((s).find(e) != (s).end())

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    string s;
    string o = "";
    cin >> s;
    for(char& c : s) {
        if (c == 'B' && !o.empty()) o.pop_back();
        else if(c == '0' || c == '1')o.push_back(c);
    }
    cout << o << '\n';

    return 0;
}

Measured memory_bytes: 256
// #include<bits\stdc++.h>
#include<cstdlib>
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;

void solve(){
    string s;
    cin >> s;
    int cnt = 0;
    int mx = 0;
    int f = 0;
    for(int i = 0; i < s.size(); i++){
        if (s[i] == 'R') f = 1;
        if (i < s.size() - 1 && s[i] == 'R' &&  s[i + 1] == 'R') cnt += 1;
        mx = max(cnt , mx);
    }
    if (f) cout << mx + 1;
    else cout << 0;
}

int main()
{   
    ios::sync_with_stdio(0);
    cin.tie(0);
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    solve();
}  

Measured memory_bytes: 3644
import java.util.Scanner;
public class Main {
	 public static void main(String[] args) {
	        Scanner sc = new Scanner(System.in);
	        int sum;
	        for (String str = sc.next(); !str.equals("0"); str = sc.next()){
	            sum = 0;
	            char[] ch = str.toCharArray();
	            
	            for (int i = 0; i < str.length(); i++){
	                sum += ch[i] - '0';
	            }
	            System.out.println(sum);
	        }
	    }
	}


Measured memory_bytes: 26036
#include <stdio.h>

inline void gc(int *x) {
    *x = 0;
    for (;;) {
        int c = getc_unlocked(stdin);
        if ('0' <= c && c <= '9') {
            *x = *x * 10 + c - '0';
        } else {
            break;
        }
    }
}

#define KMAX (1000)
int s[KMAX + 1][2 * KMAX + 1];
int main(void) {
    char c;
    int n, k, x, y;
    gc(&n), gc(&k);
    for (int i = 0; i < n; i++) {
        gc(&x);
        gc(&y);
        c = getc_unlocked(stdin);
        // 改行コードは読み飛ばす
        getc_unlocked(stdin);
        y %= 2 * k;
        if (c == 'W') {
            if (y >= k) {
                y -= k;
            } else {
                x += k;
            }
        } else {
            if (y >= k) {
                y -= k;
                x += k;
            }
        }
        x %= 2 * k;
        s[y + 1][x + 1]++;
    }
    for (int y = 0; y < k; y++) {
        for (int x = 0; x < 2 * k; x++) {
            s[y + 1][x + 1] += s[y][x + 1] + s[y + 1][x] - s[y][x];
        }
    }
    int max = 0;
    int v = s[0][0] - s[0][2 * k];
    for (int y = 0; y < k; y++) {
        int u = v - s[y][0] + s[y][2 * k];
        for (int x = 0; x < k; x++) {
            int t = u - s[0][x] - s[k][x] + s[0][x + k] + s[k][x + k] +
                    2 * s[y][x] - 2 * s[y][x + k];
            t = t < n / 2 ? n - t : t;
            max = t > max ? t : max;
        }
    }
    printf("%d\n", max);
    return 0;
}


Measured memory_bytes: 7936
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;
using ll = long long;

int main()
{
  int N; cin >> N;
  vector<int> A(N), a(N);
  REP(i, N) {
    cin >> A[i];
    a[i] = A[i];
  }

  sort(ALL(a), greater<int>());
  int max1 = a[0];
  int max2 = a[1];

  for (int i = 0; i < N; ++i) {
    if (A[i] == max1) {
      cout << max2 << endl;
    } else {
      cout << max1 << endl;
    }
  }
}

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

using namespace std;

int n, S[233], F[2][100010], C[233][233], X;

signed main() {
	scanf("%lld%lld", &n, &X);
	for(int i = 0; i <= n; i++)
		for(int j = 0; j <= n; j++)
			C[i][j] = !j ? 1 : (C[i - 1][j - 1] + C[i - 1][j]) % P;
	for(int i = 1; i <= n; i++) scanf("%lld", &S[i]);
	sort(S + 1, S + n + 1);
	reverse(S + 1, S + n + 1);
	int a = 0, b = 1;
	F[0][X] = 1;
	for(int i = 1; i <= n; i++, swap(a, b)) {
		memset(F[b], 0, sizeof F[b]);
		for(int j = 0; j <= X; j++) {
			int t = j % S[i];
			F[b][t] = (F[b][t] + F[a][j]) % P;
			F[b][j] = (F[b][j] + F[a][j] * (n - i)) % P;
		}
	}
	int ans = 0;
	for(int i = 1; i <= X; i++) ans = (ans + i * F[a][i]) % P;
	printf("%d\n", (ans % P + P) % P);
	return 0;
}

Measured memory_bytes: 2176
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <string>
#include <map>
#include <utility>
#include <set>
#include <unordered_map>

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define IPSILON 1e-9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main(){
  int N;
  cin >> N;
  double d;
  if(N % 2 == 1){
    d = (double)(N / 2 + 1)/ N;
  }else{
    d = (double)(N/ 2) / N;
  }
  cout << d << endl;
  return 0;
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll p=pow(10,9)+7;
ll phi(ll n) {
    ll result = n;
    for (ll i = 2; i * i <= n; i++) {
        if(n % i == 0) {
            while(n % i == 0)
                n /= i;
            result -= result / i;
        }
    }
    if(n > 1)
        result -= result / n;
    return result;
}
ll power(ll x, ll y, ll p) 
{ 
    ll res = 1;      
    x = x % p;  
   while (y > 0) 
    { 
        if (y & 1) 
            res = (res*x) % p; 
        y = y>>1; 
        x = (x*x) % p; 
    } 
    return res; 
} 

ll modInverse(ll n, ll p) 
{ 
    return power(n, p-2, p); 
}


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,w,i,j,sum=0;
   cin>>n>>w;
   ll wt[n],v[n];
   for(i=0;i<n;i++)
   {
   cin>>wt[i]>>v[i];
   sum+=v[i];
   }
   ll dp[n][sum+1];
   memset(dp,-1,sizeof(dp));
   dp[0][0]=0;
   dp[0][v[0]]=wt[0];
   
   for(i=1;i<n;i++)
   {
       for(j=0;j<=sum;j++)
       {
           if(j>=v[i])
           {
          if(dp[i-1][j]!=-1&&dp[i-1][j-v[i]]!=-1)
          dp[i][j]=std::min(dp[i-1][j],dp[i-1][j-v[i]]+wt[i]);
          else if(dp[i-1][j]==-1&&dp[i-1][j-v[i]]!=-1)
          dp[i][j]=dp[i-1][j-v[i]]+wt[i];
          else if(dp[i-1][j]!=-1&&dp[i-1][j-v[i]]==-1)
          dp[i][j]=dp[i-1][j];
           }
           else
           {
               if(dp[i-1][j]!=-1)
               dp[i][j]=dp[i-1][j];
           }
          
       }
   }
   ll ans=0;
   for(j=0;j<=sum;j++)
   {
       if(j>ans&&dp[n-1][j]!=-1&&dp[n-1][j]<=w)
       ans=j;
   }
   cout<<ans;
   
  
 
    return 0;
    
}
    



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

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

long long MOD = 10000000000 + 7;

int main(){
  cout << setprecision(10);
  int a,b,c;
  cin >> a >> b >> c;
  cout << max(0, c - (a - b)) << endl;
}


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

char S[100005];

vector<int> stack1;

int dist[100005];

int valid[100005];

int main(){
    int N, M;
    scanf("%d%d", &N, &M);
    scanf(" %s", S);

    int cnt = 0;
    for(int i = 0; i <= N; i ++){
        if(S[i] == '0'){
            valid[cnt++] = i;
        }
    }

    int cur = N;
    while(cur > 0){
        int indx = lower_bound(valid, valid+cnt, cur-M)-valid;
        //printf("debug: %d %d\n", cur, valid[indx]);
        if(valid[indx] >= cur){
            printf("-1");
            return 0;
        }
        stack1.push_back(cur-valid[indx]);
        cur = valid[indx];
    }

    for(int i = (int)stack1.size()-1; i >= 0; i --){
        printf("%d", stack1[i]);
        if(i != 0){
            printf(" ");
        }
    }

    return 0;
}


Measured memory_bytes: 1404
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = (ll)(1e9+7);
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int (i)=0; (i)<(int)(n); (i)++)
int dx[4]={ 1,0,-1,0 };
int dy[4]={ 0,1,0,-1 };

int X;

signed main(){
    cin >> X;
    for(int i=X; i<INT_MAX; i++){
        bool ok = true;
        for(int k=2; k<=sqrt(i); k++){
            if(i%k == 0){
                ok = false;
                break;
            }
        }
        if(ok){
            cout << i << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 256
import sys
n,goalA,goalB,goalC = list(map(int, input().split()))
l = [int(input()) for _ in range(n)]
cost = []
isum = 0

def dfs(depth: int, a: int, b: int, c:int, isum:int):
    if depth == n:
        if min(a,b,c) > 0:
            cost.append(abs(a - goalA) + abs(b - goalB) + abs(c - goalC) +isum - 30)
            return
        else:
            cost.append(10**8)
            return
    
    dfs(depth+1, a, b, c, isum)
    dfs(depth+1, a + l[depth], b, c, isum + 10) 
    dfs(depth+1, a , b + l[depth], c, isum+10) 
    dfs(depth+1, a , b, c + l[depth], isum + 10) 
    

dfs(0,0,0,0,isum)
print(min(cost))

Measured memory_bytes: 5108
// In the name of GOD
#include<bits/stdc++.h>
using namespace std;

#define debug(x) cout<<#x<<" :: "<<x<<"\n";
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n";
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\n";

#define     IOS         ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define 	setprecn(x) cout<<fixed<<setprecision(x);
#define 	ll          long long int
#define 	pb          push_back
#define 	pll         pair<ll,ll>
#define 	vll         vector<ll>
#define 	ff          first
#define 	ss          second
#define 	all(a)      (a).begin(),(a).end()
#define 	sz(x)       (ll)x.size()
#define 	mod         1000000007
#define 	inf         10000000000000007
#define 	rep(i,n)    for(ll i=0;i<n;i++)
#define 	repe(i,a,b) for(ll i=a;i<b;i++)
#define 	lbnd        lower_bound
#define 	ubnd        upper_bound
#define 	bs          binary_search

ll power(ll a,ll b,ll m=mod)
{
	if(b==0)
		return 1;
	if(b==1)
		return a;
	ll c=power(a,b/2,m);
	if(b%2==0)
		return((c%m)*(c%m))%m;
	return ((((c%m)*(c%m))%m)*(a%m))%m;
}

/********************************************************/
//	d.erase(unique(all(d)), d.end());



int main()
{
	IOS;
	ll n,k,m,i,j,c=0,cs=0,t;
	t=1;

	// cin>>t;
	string s;
	while(t--)
	{
		double x,p;
		cin>>x;
		// n=s.length();
		// ll a[n];
		x/=3.0;
		p=x*x*x;
		setprecn(12);
		cout<<p;

		
		cout<<"\n";
	}
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <iomanip>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<long double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }
#define INF 1LL<<60

int main() {
    int mod = 2019;
    string S;
    cin >> S;

    int length = S.length();
    vector<int> mods(length);
    mods[length-1] = int(S[length-1] - '0');
    int base = 10;
    FORR(i, length-2, 0) {
        mods[i] = (mods[i+1] + base * int(S[i] - '0')) % mod;
        base *= 10;
        base %= mod;
    }

    map<int, int> mod_num; 

    REP(i, length) {
        // cerr << i << ": " << mods[i] << endl;
        mod_num[mods[i]]++;
    }

    int ans = 0;
    for(auto p = mod_num.begin(); p!=mod_num.end(); ++p) {
        ans += p->second * (p->second-1) / 2;
    }

    ans += mod_num[0];

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 4368
A=[]
A.append(list(map(int,input().split())))
A.append(list(map(int,input().split())))
A.append(list(map(int,input().split())))
n=int(input())
L=[]
for i in range(n):
    L.append(int(input()))
M=[[0,0,0],[0,0,0],[0,0,0]]
for i in L:
    for j in range(3):
        for k in range(3):
            if i==A[j][k]:
                M[j][k]=1

for i in range(3):
    if sum(M[i])==3:
        print("Yes")
        exit()

if M[0][0]+M[1][0]+M[2][0]==3 or M[0][1]+M[1][1]+M[2][1]==3 or M[0][2]+M[1][2]+M[2][2]==3:
        print("Yes")
        exit()

if M[0][0]+M[1][1]+M[2][2]==3 or M[0][2]+M[1][1]+M[2][0]==3:
    print("Yes")
    exit()
    
print("No")

Measured memory_bytes: 38256
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<deque>
#include<cmath>
#include<map>
#include<cstring>

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LLINF = 1LL<<60;
#define P pair<int, int>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define print(x) cout << (x) << endl

int main() {
    int N, M;
    cin >> N >> M;
    int A[N], B[N];
    priority_queue<int>Q[100001];
    priority_queue<int>Q_ALL;
    Q_ALL.push(0);
    rep(i, N) cin >> A[i] >> B[i], --A[i], Q[A[i]].push(B[i]);
    int ans = 0;
    for(int i = 0; i < M; ++i) {
        int q2 = Q_ALL.top();
        if(!Q[i].empty()) {
            int q1 = Q[i].top();
            if(q1 > q2) {
                ans += q1;
                Q[i].pop();
            }else {
                ans += q2;
                Q_ALL.pop();
            }
            while(!Q[i].empty()) {
                Q_ALL.push(Q[i].top());
                Q[i].pop();
            }
        }else {
            ans += q2;
            Q_ALL.pop();
            Q_ALL.push(0);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 7168
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UncheckedIOException;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) {
		SC sc=new SC(System.in);
		int a=sc.nextInt();
		pl(a*32);
	}
	static class SC {
		private BufferedReader reader = null;
		private StringTokenizer tokenizer = null;
		public SC(InputStream in) {
			reader = new BufferedReader(new InputStreamReader(in));
		}
		public String next() {
			if (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new UncheckedIOException(e);
				}
			}
			return tokenizer.nextToken();
		}
		public int nextInt() {
			return Integer.parseInt(next());
		}
		public long nextLong() {
			return Long.parseLong(next());
		}
		public double nextDouble() {
			return Double.parseDouble(next());
		}
		public String nextLine() {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new UncheckedIOException(e);
			}
		}
	}
	public static void pl(Object o) {
		System.out.println(o);
	}
	public static void pl() {
		System.out.println();
	}
	public static void p(Object o) {
		System.out.print(o);
	}
}



Measured memory_bytes: 24232
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
typedef long long int lli;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

int main(){
    char c;
    cin >> c;
    cout << (char)(c+1) << endl;
}

Measured memory_bytes: 256
(row, col) = map(int,input().split())
matrix=[0]*row
last = [0]*(col+1)
for r in range(row):
    line = list(map(int, input().split()))
    line.append(sum(line))
    print(*line, sep=" ")
    for j in range(col+1):
        last[j]+=line[j]
        
#print(output)
print(*last, sep=" ")


Measured memory_bytes: 5632
#B - Chocolate
N = int(input())
D,X = map(int,input().split())
A = list(int(input()) for i in range(N))

choco = 0

for i in A:
    day = [i*j + 1 for j in range(100) if i*j < D]
    choco += len(day)

print(X + choco)        
    

Measured memory_bytes: 9180
# coding: utf-8
# Your code here!
n = int(input())
s = list(map(int,input().split()))

min_value = s[0]
max_value = s[0]
sum_value = 0

for i in s:
    sum_value += i
    if i < min_value:
        min_value = i
    if i > max_value:
        max_value = i
        
print(min_value, max_value, sum_value)


Measured memory_bytes: 6596
import java.util.*;

public class Main {

	public static void main(String[] args) {

		// 入力
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		long sum = 0;
		int v[];
		v = new int[100001];
		for (int i = 0; i < n; i++) {
			int x = Integer.parseInt(sc.next());

			// 数列の総和と、各数字の登場回数を保持しておく
			sum += x;
			v[x]++;
		}

		// 各クエリ
		int q = Integer.parseInt(sc.next());
		for (int i = 0; i < q; i++) {

			// 入力
			int b = Integer.parseInt(sc.next()); // 置換前
			int c = Integer.parseInt(sc.next()); // 置換後

			// 総和の更新
			sum += (c - b) * v[b];

			// 登場回数の更新
			v[c] += v[b];
			v[b] = 0;

			// 上記方法でやることで、総和を求めるのがO(1)で済む。

			// 結果出力
			System.out.println(sum);
		}

	}
}

Measured memory_bytes: 60264
import java.util.*;

public class Main{
    public static void main(String[] args){


        Scanner sc = new Scanner(System.in);

        String S = sc.next();
        String a = "abc";
        String b = "acb";
        String c = "bac";
        String d = "cab";
        String e = "bca";
        String f = "cba";

        if(S .equals(a)){
            System.out.println("Yes");
        }else if(S.equals(b)){
            System.out.println("Yes");
        }else if(S.equals(c)){
            System.out.println("Yes");
        }else if(S.equals(d)){
            System.out.println("Yes");
        }else if(S.equals(e)){
            System.out.println("Yes");
        }else if(S.equals(f)){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }

    }
}

Measured memory_bytes: 23124
n, k = map(int, input().split())
a = [int(x) for x in input().split()]
b = [sorted(a).index(a[i]) for i in range(n)]
p = [b[i] * (k*(k+1)//2)for i in range(n)]
q = [0] * n
for i in range(n):
    num = 0
    for j in range(i,n):
        if a[j] > a[i]:
            num += 1
    q[i] = num
ans = sum(p)-sum(q)*k
print(ans%1000000007)

Measured memory_bytes: 9376
n = int(input())
x_L = list(map(int,input().split()))
x_L = list(sorted(x_L))
start = x_L[0]
end = x_L[-1]
a = 10**20
for i in range(start,end+1):
    sums = 0
    for k,val in enumerate(x_L):
        sums += (x_L[k]-i)**2
    a = min(a,sums)
print(a)

Measured memory_bytes: 38768
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <set>
#include <queue>
#include <map>
#include <numeric>
#include <functional>
#include <math.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

#define INF ((int)1e9)
#define INFLL ((ll)1e18)
#define MOD (1000000007LL)


int main(int argc, const char * argv[]) {
    ios_base::sync_with_stdio(false);
    string S;
    cin >> S;
    vector<int> vi;
    int nTemp = 0;
    char cPrev = 'R';
    for (int n = 0; n < S.length(); ++n) {
        if (S[n] == cPrev) {
            ++nTemp;
        } else {
            vi.push_back(nTemp);
            cPrev = S[n];
            nTemp = 1;
        }
    }
    vi.push_back(nTemp);
    
    for (int k = 0; k < vi.size()/2; ++k) {
        int nR = vi[2*k];
        int nL = vi[2*k+1];
        for (int n = 0; n < nR-1; ++n) cout << "0 ";
        cout << (nR+1)/2 + nL/2 << ' ' << nR/2 + (nL+1)/2 << ' ';
        for (int n = 0; n < nL-1; ++n) cout << "0 ";
    }
    cout << endl;
    
    return 0;
}


Measured memory_bytes: 1096
#include<iostream>
using namespace std;
int main(){
    string n;
    cin>>n;
    char a=n.at(0);
    char b=n.at(1);
    char c=n.at(2);
    char d=n.at(3);
    if(a==b&&b==c){puts("Yes");}
    else if(b==c&&c==d){puts("Yes");}
    else{puts("No");}}

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  int i;
  for (i = 0; i < n; i++) {
    cin >> a[i];
  }
  vector<int> sorted_a = a;
  sort(sorted_a.begin(), sorted_a.end());
  int diff = 0;
  for (i = 0; i < n; i++) {
    if (a[i] != sorted_a[i]) {
      diff++;
    }
  }
  if (diff == 0) {
    cout << 0 << endl;
    return 0;
  }

  /////
  // for (i = 0; i < sorted_a.size(); i++) {
  //   cout << sorted_a[i] << ' ';
  // }
  // cout << endl;
  // for (i = 0; i < a.size(); i++) {
  //   cout << a[i] << ' ';
  // }
  // cout << endl;
  // cout << endl;
  /////


  int q;
  cin >> q;
  int x, y;
  int change;
  for (i = 0; i < q; i++) {
    cin >> x >> y;
    change = 0;
    if (a[x - 1] != sorted_a[x - 1]) {
      change++;
    }
    if (a[y - 1] != sorted_a[y - 1]) {
      change++;
    }
    swap(a[x - 1], a[y - 1]);
    if (a[x - 1] != sorted_a[x - 1]) {
      change--;
    }
    if (a[y - 1] != sorted_a[y - 1]) {
      change--;
    }
    diff -= change;
    if (diff == 0) {
      cout << i + 1 << endl;
      return 0;
    }
    /////
    // for (int db = 0; db < sorted_a.size(); db++) {
    //   cout << a[db] << ' ';
    // }
    // cout << "  diff = " << diff << " change = " << change;
    // cout << endl;
    //
    /////
  }
  cout << -1 << endl;
  return 0;
}



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

int main(){
	int n;
	cin>>n;
	int a[n+5],b[100001]={0};
	for(int i=0;i<n;i++){
		scanf("%d",&a[i]);
		b[a[i]+1+1]++;
		b[a[i]-1+1]++;
		b[a[i]+1]++;
	} 
	int t=b[0],i;
	for( i=1;i<100001;i++){
		if(t<b[i])
			t=b[i];		
	}
	printf("%d",t);
	return 0;
}

Measured memory_bytes: 1024
# import numpy as np

def main():
    H,N = [int(x) for x in input().split()]
    A,B = [],[]
    for _ in range(N):
        a,b = [int(x) for x in input().split()]
        A.append(a)
        B.append(b)

    # dp = np.full((N+1,H+1),10 ** 18)
    # dp[0][0] = 0
    dp = [float('inf')]*(H+1)
    dp[0] = 0
    for i in range(N):
        for j in range(H+1):
            # print(i,j,dp[j],A[i],B[i])
            dp[min(j+A[i],H)] = min(dp[min(j+A[i],H)], dp[j]+B[i])
            # dp[i+1][j] = min(dp[i+1][j], dp[i][j])
            # dp[i+1][min(j+A[i],H)] = min(dp[i+1][j]+B[i], dp[i+1][min(j+A[i],H)])
            # print(dp)
    print(int(dp[H]))


if __name__ == '__main__':
    main()

Measured memory_bytes: 46940
/** Nguyen Anh Tu **/
#include <bits/stdc++.h>
#define maxn 100005
#define maxc 1000000007
#define MOD 1000000007
#define reset(x) memset(x,0,sizeof(x))
#define task ""
#define mp make_pair
#define pb push_back
#define ep emplace_back
#define F first
#define S second
#define pii pair<int,int>
#define ll long long
#define bit(p,x) ((x>>p) & 1)
#define remain(a,b) (a+b >= MOD) ? (a+b - MOD) : (a+b)
using namespace std;


int main()
{
    ios_base::sync_with_stdio(NULL); cin.tie(NULL); cout.tie(NULL);
    if(fopen(task".inp","r")){
        freopen(task".inp","r",stdin);
        freopen(task".out","w",stdout);
    }
    int k;
    cin >> k;
    for(int i=1; i<=k; ++i) cout << "ACL";
    return 0;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,j,n) for(int i=j;i<n;i++)
#define all(v) v.begin(),v.end()
using namespace std;

int main(){
  	int n; cin >> n;
    vector<int> L(n);
    rep(i,n) cin >> L[i];
    sort(all(L));
    int ans = 0;
    rep(i,n-2)rep2(j,i+1,n-1){
    	 auto tmp = lower_bound(L.begin()+j,L.end(),L[j]) - L.begin();
         tmp++;
         auto tmp2 = lower_bound(L.begin()+j,L.end(),L[i]+L[j]) - L.begin();
         //cout << "up" << L[i]+L[j] << ":" << tmp2 << endl;
         tmp2--;
         ans += tmp2 - tmp + 1;
         //cout << i << "," << j << ":" << tmp << "," << tmp2 << endl;
    }
    cout << ans << endl;

	return 0;
}


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

int main() {
  int n, m;
  cin >> n >> m;
  
  vector<int> f(m);
  
  rep(i,n) {
    int k;
    cin >> k;
    rep(j,k) {
      int a;
      cin >> a;
      f[a-1]++;
    }
  }
  
  int ans = 0;
  rep(i,m) if (f[i]==n) ans++;
  
  cout << ans << endl;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#include <unordered_map>
//#include"testlib.h"
#define endl "\n"
#define all(v) v.begin(),v.end()
#define allr(s) s.rbegin(),s.rend()
#define RT(s) return cout<<s,0
#define watch(x) cout << (#x)<<" = "<<x<<endl
#define sz(s)	(int)(s.size())
#define PI acos(-1)
#define EPS 1e-8
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ll> row;
typedef vector<row> matrix;
int dy[] = { 1, -1, 0, 0, -1, 1, 1, -1 };
int dx[] = { 0, 0, 1, -1, 1, -1, 1, -1 };
void file() {
#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
#else
	//freopen("street.in", "r", stdin);
	//freopen("out.txt", "w", stdout);
#endif
}
void fast() {
	std::ios_base::sync_with_stdio(0);
	cin.tie(NULL);
}

int main() {
	//file();
	fast();
	vector<pair<int, string>> v1{ {7, "SUN"}, {6, "MON"}, {5, "TUE"}, {4, "WED"}
		, {3, "THU"}, {2, "FRI"}, {1, "SAT"} };
	string str; cin >> str;
	for (auto it : v1)
		if (it.second == str) cout << it.first << endl;
	return 0;
}

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

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

#define m0(x) memset(x, 0, sizeof(x))
#define all(x) x.begin(), x.end()
#define rep(i, n) for(int i = 0; i < (n); i++)
#define asort(x) sort(all(x));
#define dsort(x, t) sort(x.begin(), x.end(), greater<t>());
#define dump(x)  cout << #x << " = " << (x) << endl
#define vuniq(v) v.erase(unique(v.begin(), v.end()), v.end());
#define minse(m, s) m.insert(make_pair(s, 1));
#define mfin(m, s) m.find(s) != m.end()

#define YES(n) cout << ((n) ? "YES" : "NO" ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No" ) << endl

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

ll gcd(ll a, ll b) {
    return b ? gcd(b, a%b) : a;
}

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

int main(){
    ll n, d;
    ll a[105];
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        if(i == 0){
            d = a[i];
        }else{
            d = lcm(d, a[i]);
        }
    }

    ll m = 0;
    for (int i = 0; i < n; i++) {
        m += d / a[i];        
    }

    cout << fixed << setprecision(10) << (double)d / m << endl;

    return 0;
}

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

const int MAX_N = 100010;
const int INF = 1e+8;

// テ・ツァツ凝ァツつケ 0 テ」ツ?凝」ツつ嘉」ツ?ョテヲツ慊?ァツ淞ュティツキツ敕ゥツ崢「 (テ・ツュツ佚・ツ慊ィテ」ツ?療」ツ?ェテ」ツ??・ツ?エテ・ツ青暗」ツ?ッ INF)
int d[MAX_N];
// loop[i] := テ」ツδ榲」ツつケ i テ」ツ?ォテヲツュツ「テ」ツ?セテ」ツつ凝」ツ?ィテァツ?。テゥツ卍静」ツδォテ」ツδシテ」ツδ療」ツ?ォテ」ツδ湘」ツδ榲」ツつ凝」ツ?ィテ」ツ?催」ツ?ッ -1 ,
// テ」ツ?敕」ツ??」ツ?ァテ」ツ?ェテ」ツ??」ツ?ィテ」ツ?催」ツ?ッテ」ツδォテ」ツδシテ」ツδ療・ツセツ古」ツ?ョテ、ツスツ催ァツスツョテ」ツつ津ィツソツ氾」ツ??
int loop[MAX_N];
// テ・ツ?・テ・ツ環?
int N;
int p[MAX_N];

// テ」ツδォテ」ツδシテ」ツδ療」ツ?ョテヲツ、ツ愿・ツ?コ
int is_loop(int v, map<int,bool>& memo){
	if( p[v] == 0 ) return loop[v] = v;
	if( memo.count(v) ) return loop[v] = -1;
	
	memo[v] = true;
	return loop[v] = is_loop( v + p[v] , memo );
}

// BFS
void bfs(int s=0){
	d[s] = s;
	queue<int> q;
	q.push( s );
	
	while( !q.empty() ){
		int v = q.front(); q.pop();
		
		if( v == N - 1 ) return ;
		
		for(int i=1 ; i <= 6 ; i++ ){
			if( loop[v+i] == -1 ) continue;
			int next = loop[v+i];
			if( d[v] + 1 < d[next] ){
				d[next] = d[v] + 1;
				q.push( next );
			}
		}
	}
}

int main(){
	// テ・ツ?・テ・ツ環?
	cin >> N;
	for(int i=0 ; i < N ; i++ ){
		cin >> p[i];
		d[i] = loop[i] = INF;
	}
	
	// テ」ツδォテ」ツδシテ」ツδ療」ツ?ョテヲツ、ツ愿・ツ?コ
    for(int i=0 ; i < N ; i++ ){
        if( loop[i] != INF ) continue;
        map<int,bool> memo;
        is_loop(i, memo);
    }
    bfs();
	cout << d[N-1] << endl;
}

Measured memory_bytes: 10192
#include <cstdio>
#include <iostream>
#include <iomanip>
#include<string>
#include<algorithm>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int main()
{
	int a;
	cin >> a;
	if (a == 7 || a == 5 || a == 3) { cout << "YES" << endl; }
	else { cout << "NO" << endl; }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
#include <cmath>
#include <numeric>
#include <utility>
#include <iomanip>

using namespace std;
using int64 = long long;

struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa;

vector<int> pf(int n) {
    vector<int> primes;
    if (n%2 == 0) {
        primes.push_back(2);
        while (n%2 == 0) n /= 2;
    }
    for (int i=3; i*i<=n; i+=2) {
        if (n%i) continue;
        primes.push_back(i);
        while (n%i == 0) n /= i;
    }
    if (n != 1) primes.push_back(n);

    return primes;
}

int main() {
    const int MAX_N = 1e6;
    vector<int> sieve(MAX_N+1);
    iota(sieve.begin(), sieve.end(), 0);
    for (int64 i=2; i<=MAX_N; i++) {
        if (i != sieve[i]) continue;
        for (int64 j=i*i; j<=MAX_N; j+=i)
            sieve[j] = i;
    }

    int n;
    cin >> n;
    int all_gcd;
    bool pc = true;
    unordered_map<int, bool> check;
    for (int i=0; i<n; i++) {
        int a;
        cin >> a;
        all_gcd = (i==0)? a : gcd(all_gcd, a);

        if (!pc) continue;
        set<int> st;
        while (a != 1) {
            st.insert(sieve[a]);
            a /= sieve[a];
        }
        for (auto i : st) {
            if (check[i]) pc = false;
            check[i] = true;
        }
    }

    if (pc)
        cout << "pairwise coprime" << endl;
    else if (all_gcd == 1)
        cout << "setwise coprime" << endl;
    else
        cout << "not coprime" << endl;
}


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

int main(void){
    int n,k;
    cin >> n >> k;
    int x[n];
    rep(i,n){
        int a;
        cin >> a;
        x[i] = a;
    }
    ll ans = 100100100100;
    
    for(int i=0;i<=n-k;i++){
        ll a,b;
        a = abs(x[i]) + abs(x[i+k-1]-x[i]);
        b = abs(x[i+k-1]) + abs(x[i+k-1]-x[i]);
        a = min(a,b);
        if(ans > a){
            ans = a;
        }
    }
    cout << ans <<endl;
    
    
    return 0;
}








Measured memory_bytes: 640
N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = input()
L = [0]*N
dic = dict()
dic["r"] = P
dic["s"] = R
dic["p"] = S
dic["0"] = 0
res = 0
for i in range(N):
    if i < N-K and T[i] == T[i+K] and L[i] == 0:
        L[i+K] = 1
    if L[i] == 0:
        res += dic[T[i]]
print(res)

Measured memory_bytes: 68528
#include <iostream>
#include <vector>
#include <algorithm>

int main() {
  int N;
  std::cin >> N;

  std::vector<int> A(N);
  std::vector<int> B(N);

  for (int i=0; i<N; i++) {
    std::cin >> A[i];
  }

  for (int i=0; i<N; i++) {
    std::cin >> B[i];
  }

  int ans=0;

  for (int k=29; k>=0; k--) {
    int T = 1<<k;

    for (int j=0; j<N; j++) {
      B[j] %= 2*T;
    }
    std::sort(B.begin(), B.end());

    for (int i=0; i<N; i++) {
      int a = A[i] % (2*T);

      decltype(B)::iterator lb0 = std::lower_bound(B.begin(), B.end(), T-a);
      decltype(B)::iterator ub0 = std::upper_bound(B.begin(), B.end(), 2*T-a-1);
      decltype(B)::iterator lb1 = std::lower_bound(B.begin(), B.end(), 3*T-a);
      decltype(B)::iterator ub1 = std::upper_bound(B.begin(), B.end(), 4*T-a-1);

      if (((ub0 - lb0) + (ub1 - lb1)) % 2 == 1) {
        ans ^= T;
      }
    }
  }

  std::cout << ans << std::endl;

  return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define srt(x) sort((x).begin(), (x).end());
#define rsrt(x) sort((x).rbegin(), (x).rend());
#define deb(x) cout<<#x<<" = "<<(x)<<" (L"<<LINE<<")"<<endl;
#define vdeb(x) {cout<<#x<<" = { "; rep(i, x.size()) cout<<x[i]<<' '; cout <<'}'<<" (L"<<LINE<<")"<<endl;}
using namespace std;
using ll = long long;
using vi = vector<int>;
using vivi = vector<vi>;
using vll = vector<long long>;
using vllvll = vector<vll>;
using vs = vector<string>;

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

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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;

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

bool kaibun(const string& s) {
    int l = s.size();
    if (l <= 1)
        return true;

    for (int i = 0; i <= (l - 1) / 2; i++) {
        if (s[i] != s[l - i - 1])
            return false;
    }

    return true;
}

int main() {
    ios::sync_with_stdio(false);
    string s;
    cin >> s;

    bool r = kaibun(s);
    string s2 = s.substr(0, s.size() / 2);
    r = r & kaibun(s2);

    cout << (r ? "Yes" : "No") << endl;
    return 0;
}


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

int main() {
        int n, m, q;
        cin >> n >> m >> q;
        vector<vector<int> > a(n + 1, vector<int>(n + 1));
        int i;
        for (i = 0; i < m; i++) {
                int l, r;
                cin >> l >> r;
                a[l][r]++;
        }

        for (i = 0; i < n; i++) {
                for (int j = 0; j < n; j++) {
                        a[i + 1][j + 1] += a[i + 1][j];
                }
        }

        for (i = 0; i < q; i++) {
                int l, r;
                cin >> l >> r;
                int m = 0;
                for (int j = l; j <= r; j++) {
                        m += a[j][r];
                }
                cout << m << endl;
        }
}


Measured memory_bytes: 1920
#include <bits/stdc++.h>
 
//#include <unistd.h>
//#include <iostream>
 
using namespace std;
 
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl;
#define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}
typedef long long ll;
#define int ll
 
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const long double pi = 3.1415926535897932384626433832795028841971L;
#define Sp(p) cout<<setprecision(25)<< fixed<<p<<endl;
//int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
//int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
vi dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};
vi dx2 = { 1,1,0,-1,-1,-1,0,1 }, dy2 = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
const ll MOD = 1000000007;
//const ll MOD = 998244353;
// #define mp make_pair
//#define endl '\n'
signed main() {
	string s, t;
	cin >> s >> t;
	int a, b;
	cin >> a >> b;
	string u;
	cin >> u;
	if (s == u) a--;
	else b--;
	cout << a << " " << b << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define lli long long int
#define ulli unsigned long long int
#define ld long double
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define loop(i,a,b) for(lli i=a;i<b;i++)
#define initialize(array,size,value) for(lli i=0;i<size;i++) array[i]=value
#define couta(array,size) for(lli i=0;i<size;i++) cout<<array[i]<<" "
#define vl vector<lli>
#define vp vector< pair <lli,lli> >
#define sl set<lli>
#define msp multiset < pair < long long , long long > > S;
#define pll pair<lli, lli>
#define mll map<lli, lli>            //for( map<lli, lli>::iterator i=temp.begin();i!=temp.end();i++)cout<<i->fi<<" "<<i->se<<endl;
#define mvl map<lli, vl>
#define umll unordered_map<lli, lli>
#define vt vector<pair<lli, pll >  >
#define vf vector<pair<pll,pll > >
#define qu queue<lli>
#define pq priority_queue<lli>
#define dq deque <lli>
#define ptr vector<lli>::iterator
#define bs(array,x) binary_search(array.begin(),array.end(),x) // also valid for set and multiset
#define lb(array,x) lower_bound(array.begin(),array.end(),x)
#define ub(array,x) upper_bound(array.begin(),array.end(),x)
#define nobw(array,i,j) upper_bound(array.begin(), array.end(), j)-lower_bound(array.begin(), array.end(), i) //number of numbers between i & j
#define vc clear()
#define endl '\n'
#define sp system("pause");
#define INF 9223372036854775807
#define MINF -9223372036854775808
typedef tree<pll,null_type,less<pll>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set;
//string binary = bitset<32>(n).to_string(); 
int main() 
{ 

 	ios::sync_with_stdio(0);
    cin.tie(0);
  lli n;
    cin>>n;
     vt t;
    lli ani=0;
    for(lli i=0;i<n;i++){lli x,y;cin>>x>>y;t.pb(mp(x,mp(y,0)));}
    	sort(t.begin(),t.end());
    map<pll,lli> temp;
    for(lli i=0;i<n;i++){
    	for(lli j=i+1;j<n;j++){
    		temp[mp(t[j].fi-t[i].fi,t[j].se.fi-t[i].se.fi)]++;
		}
    }
    lli maxi=0;
    for(auto i:temp)maxi=max(maxi,i.se);
    //for(lli i=0;i<n;i++)if(t[i][2]==0)ani++;
    	cout<<n-maxi;




	return 0; 
} 

// This code is contributed by rathbhupendra 


Measured memory_bytes: 384
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

#include <limits.h>

using namespace std;

typedef long long ll;

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

int main(void) {
    int A, B;
    cin >> A >> B;

    int ans = -1;
    for (int x = 0; x <= 2000; x++) {
        if (x * 8 / 100 == A && x * 10 / 100 == B) {
            ans = x;
            break;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3600