akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int h,w,i,j;
int a[105],b[105];
char s[105][105];
int main(){
cin>>h>>w;
for(int i=1;i<=h;i++)
for(int j=1;j<=w;j++)
{
cin>>s[i][j];
if(s[i][j]=='#')a[i]=1,b[j]=1;
}
for(int i=1;i<=h;i++)
{
if(a[i]==1)
{
for(int j=1;j<=w;j++)
if(b[j]==1) cout<<s[i][j];
cout<<endl;
}
}
return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define Rep(i,N) for(int i = 0; i < N; i++)
int main()
{
  int data;
  int sum = 0;
  int maxv = INT_MIN;
  Rep(p,2) {
    Rep(i,4) {
      cin >> data;
      sum += data;
    }
    maxv = max(maxv,sum);
    sum = 0;
  }
  cout << maxv << endl;
  return 0;
}

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
			// 整数の入力
			int a = sc.nextInt();
			for (int i = 1; i <= 9; i++) {
				for (int j = 1; j <= 9; j++) {
					if (a == i * j) {
						System.out.println("Yes");
						System.exit(0);
					}
				}
			}
			System.out.println("No");
		}
	}
}


Measured memory_bytes: 21840
#include <iostream>
#include <string>

int main() 
{
    std::string line;
    std::getline(std::cin, line);
    if (line[2] == line[3] && line[4] == line[5]) {
        std::cout << "Yes" << std::endl;
    } else {
        std::cout << "No" << std::endl;
    }
    return 0;
}


Measured memory_bytes: 256
import numpy as np
from itertools import combinations
n,K = map(int,input().split())
num_ls = [i for i in range(n+1)]
csum_num_ls = list(np.cumsum(num_ls))
mod = 1000000007

ans = 0
for k in range(K,n+1):
    smallest = csum_num_ls[k-1]
    biggest = csum_num_ls[-1] - csum_num_ls[-k-1]
    ans_k = biggest - smallest + 1
    ans += ans_k
    ans %= mod
ans += 1
print(ans)


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

int H, W, M;
matrix A, B, S;
m2 dp;

void input() {
    cin >> H >> W;
    A = B = S = matrix(H, vector<int>(W));
    M = 0;
    rep(i, H) rep(j, W){
        cin >> A[i][j];
    }
    rep(i, H) rep(j, W){
        cin >> B[i][j];
        S[i][j] = max(A[i][j] - B[i][j], B[i][j] - A[i][j]);
        M = max(M, S[i][j]);
    }
}

int main() {
    input();
    M *= H + W;
    dp = m2(H+1, vector<vector<bool>>(W+1, vector<bool>(M+1, false)));
    dp[1][1][S[0][0]] = true;
    for (int i = 1; i <= H; i++) {
        for (int j = 1; j <= W; j++) {
            if ((i == 1) && (j == 1)) continue;
            for (int k = 0; k < S[i-1][j-1]; k++) {
                int x = S[i-1][j-1] - k;
                if ((dp[i-1][j][x]) || (dp[i][j-1][x])) {
                    dp[i][j][k] = true;
                    continue;
                }
                x = k + S[i-1][j-1];
                if (x <= M) {
                    if ((dp[i-1][j][x]) || (dp[i][j-1][x])) {
                        dp[i][j][k] = true;
                        continue;
                    }
                }
            }
            for (int k = S[i-1][j-1]; k <= M; k++) {
                int x = k - S[i-1][j-1];
                if ((dp[i-1][j][x]) || (dp[i][j-1][x])) {
                    dp[i][j][k] = true;
                    continue;
                }
                x = k + S[i-1][j-1];
                if (x <= M) {
                    if ((dp[i-1][j][x]) || (dp[i][j-1][x])) {
                        dp[i][j][k] = true;
                        continue;
                    }
                }
            }
        }
    }
    rep(i, M+1) {
        if (dp[H][W][i]) {
            cout << i << endl;
            return 0;
        }
    }
}


Measured memory_bytes: 11136
#include <iostream>

using namespace std;
bool AP[256];
int main()
{
    string S;
    cin>>S;
    S+=((char)'a'-1);
    for(int i = 0;i<256;i++)
        AP[i] = 0;
    for(auto k : S)
        AP[k] = true;
    for(int i = S.size();i--;i>=0)
    {
        for(int j = S[i];j<='z';j++)
        {
            if(AP[j]==false)
            {
               S[i] = j;
               S.resize(i+1);
               cout<<S<<endl;
               return 0;
            }
        }
        AP[S[i]] = false;
    }
    cout<<-1<<endl;
    return 0;
}


Measured memory_bytes: 256
// The moment you think of giving up you have already lost the battle
#include <iostream>
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long int ll;
typedef long double dl;
#define PI  3.14159265358979323846
#define Mod 1000000007
ll fast(ll n,ll a,ll m)
{
    if(n==0)
        return 1;
    else if(n==1)
        return a;
    else
    {
        ll r=fast(n/2,a,m);
        if(n%2==0)
        {
            return (((r%m)*(r%m))%m);
        }
        else
        {
            return (((((r%m)*a)%m)*r)%m);
        }
    }
}

int main()
{
    ll K,A,B;
    cin>>K>>A>>B;
    ll p=B/K;
    ll q=(A-1)/K;
    p-=q;
    if(p>0)
        cout<<"OK";
    else
        cout<<"NG";

}


Measured memory_bytes: 3608
import java.io.*;
import java.util.*;
class Main  {
	public static void main (String[] args) {
		Scanner in=new Scanner(System.in);
		char p=(in.nextLine()).charAt(0);
		int k=((int)p)+1;
		char u=(char)k;
		System.out.print(u);
		
	}
}

Measured memory_bytes: 21332
import sys
input = sys.stdin.readline
INF = 10**18

def li():
    return [int(x) for x in input().split()]


N, M = li()
# 区間は半開区間 [a, b)
Intervals = [li() for _ in range(M)]

Intervals.sort(key=lambda l: l[1])

last_end = - INF
required_cnt = 0
for interval in Intervals:
    start, end = interval[0], interval[1]
    # 重なってなければ一点必要
    # 半開区間なのでlast_endとstartが等しくても重なってない
    if last_end <= start:
        last_end = end
        required_cnt += 1

print(required_cnt)

Measured memory_bytes: 91624
#include <stdio.h>
int main(void){
    // Your code here!
    int S;
    scanf("%d",&S);
    int h,m,s;
    scanf("%d",&h);
    scanf("%d",&m);
    scanf("%d",&s);
    h=S/3600;
    m=(S%3600)/60;
    s=(S%3600)%60;
    printf("%d:%d:%d\n",h,m,s);
    return 0;
}



Measured memory_bytes: 2716
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
vector<vector<int>> v(100000);
int vis[100000]={0};
pair<ll,ll> dp[100000];
ll mod=1e9+7;
void dfs(int ci){
    vis[ci]=1;
    ll w=1;
    ll b=1;
    for(auto x : v[ci]){
        if(vis[x]==0){
            dfs(x);
            w=(w*((dp[x].first+dp[x].second)%mod))%mod;
            b=(b*(dp[x].first)%mod)%mod;
        }
    }
    dp[ci]={w,b};
}
int main() {
    /*
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output1.txt", "w", stdout);
    #endif*/
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int n;
    cin>>n;
    for(int i=0;i<n-1;i++){
        int a,b; cin>>a>>b; a--; b--;
        v[a].push_back(b);
        v[b].push_back(a);
    }
    for(int i=0;i<100000;i++){
        dp[i]={-1,-1};
    }
    dfs(0);
    cout<<(dp[0].first+dp[0].second)%mod;
}

Measured memory_bytes: 13184
def main():
    N = int(input())
    if(N==1):
        print('{:.10f}'.format(1.0))
        return
    if(N%2==0):
        print('{:.10f}'.format(0.5))
    else:
        result = (N - (N-1)/2)/N
        print('{:.10f}'.format(result))

if __name__ == "__main__":
    main()

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

int main() {
  string s;
  cin >> s;
  int length = s.length() - 3;
  int n = (int)( rand() * (length-0+1.0) / (1.0 + RAND_MAX));
  cout << s[n] << s[n + 1] << s[n + 2] << endl;
  return 0;
}

Measured memory_bytes: 3612
#include <iostream>
#include <algorithm>
using namespace std;
bool bt[1000001]={};
int main()
{
	int n,it=1;cin>>n;
	while (!bt[n])
	{
		bt[n]=1;
		if (n%2) {n=3*n+1;}
		else {n/=2;}
		it++;
	}
	cout<<it<<"\n";
	return 0;
}

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

using namespace std;

#define intt long long
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

const int N = 100005;
const double PI = 3.14159265359;

int n;
int a[N];

int main() {

	FAST;

	int r;
	cin >> r;
	double ans = 2 * PI * r;
	cout << setprecision(9) << fixed << ans << '\n';
	return 0;
}

Measured memory_bytes: 3764
#include<stdio.h>
#include<string.h>

char H[1050000][14]; 
int getChar(char ch){
  if ( ch == 'A') return 1;
  else if ( ch == 'C') return 2;
  else if ( ch == 'G') return 3;
  else if ( ch == 'T') return 4;
}
long long getKey(char str[]){
  long long sum = 0, p = 1, i;
  for ( i = 0; i < strlen(str); i++ ){
    sum += p*(getChar(str[i]));
    p *= 5;
  }
  return sum;
}
 
int h1(int key){
  return key % 1050000;
}
int h2(int key){
  return 1 + (key % (1050000-1));
}
int find(char str[]){
  long long key, i, h;
  key = getKey(str);
  while(1){
    h = (h1(key) + i * h2(key)) % 1050000;
    if(strcmp(H[h], str) == 0) return 1;
    else if(strlen(H[h]) == 0) return 0;
    i++;
  }
  return 0;
}
int insert(char str[]){
  long long key, i, h;
  key = getKey(str);
  while(1){
    h = (h1(key) + i * h2(key)) % 1050000;
    if(strcmp(H[h], str) == 0) return 0;
    else if(strlen(H[h]) == 0){
      strcpy(H[h], str);
      return 0;
    }
    i++;
  }
  return 0;
}
int main(){
  int i, n, h;
  char str[14], com[9];
  for ( i = 0; i < 1050000; i++ ) H[i][0] = '\0';    
  scanf("%d", &n);   
  for ( i = 0; i < n; i++ ){
    scanf("%s %s", com, str);  
    if ( com[0] == 'i' ){
      insert(str);
    } else {
      if (find(str)){
        printf("yes\n");
      } else {
        printf("no\n");
      }
    }
  }
 
  return 0;
}

Measured memory_bytes: 14964
S = input()
S = S[::-1]
t = ['maerd','remaerd','esare','resare']
i = 0
frag = 0
while i <= len(S)-1 and frag == 0:
  k = 0
  for j in range(4):
    d = t[j]
    if S[i:len(d)+i] == d:
      i = i + len(d)
    else:
      k = k + 1
      if k == 4:
        frag = 1
        print('NO')
if i == len(S):
  print('YES')

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
//INSERT ABOVE HERE
signed main(){
  Int n,m,s,t;
  cin>>n>>m>>s>>t;
  s--;t--;
  vector<vector<Int> > G(n);
  for(Int i=0;i<m;i++){
    Int a,b;
    cin>>a>>b;
    a--;b--;
    G[a].emplace_back(b);
    G[b].emplace_back(a);
  }
  using P = pair<Int, Int>;
  vector<vector<Int> > dp(2,vector<Int>(n,-1)); 
  queue<P> q;
  q.emplace(0,s);
  dp[0][s]=0;
  while(!q.empty()){
    Int d,v;
    tie(d,v)=q.front();q.pop();
    for(Int u:G[v]){
      Int nd=d+1;
      if(~dp[nd&1][u]) continue;
      dp[nd&1][u]=nd;
      q.emplace(nd,u);
    }
  }

  if(dp[0][t]==2){
    cout<<2<<endl;
    return 0;
  }

  if(dp[1][t]<0){
    cout<<-1<<endl;
    return 0;
  }

  auto isp=[](Int x){
	     if(x<2) return false;
	     for(Int i=2;i*i<=x;i++)
	       if(x%i==0) return false;
	     return true;
	   };

  Int ans=dp[1][t];
  while(!isp(ans)) ans+=2;
  cout<<ans<<endl;
  
  return 0;
}



Measured memory_bytes: 10984
N,x=map(int,input().split())
candies = list(map(int,input().split()))
count = 0
for i in range(len(candies)):
    if i == 0:
        if candies[i] > x:
            count += candies[i] - x
            candies[i] = x
    else:
        if candies[i-1] + candies[i] > x:
            count += candies[i-1] + candies[i] - x
            candies[i] = candies[i] - (candies[i-1] + candies[i] - x)
print(count)

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


int main(){
    int a, b, c, X, Y, x=0, y=0;
    cin >> a >> b >> c >> X >> Y;
    long long int ans, cost=0;
    ans = a * X + b * Y;
    int i = 1;
    while(x <= X || y <= Y){
        cost = 2 * c * i;
        cost += max(0, X-i) * a + max(0, Y-i) * b;
        ans = min(ans, cost);
        x++;
        y++;
        i++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import math

q = int(input())
a = []
for i in range(q):
    a.append(list(map(int, input().split())))
for i in range(q):
    b = max(2 * int(math.sqrt(a[i][0] * a[i][1])) - 3, 0)
    while True:
        status = True
        if b % 2 == 0:
            if (b // 2 + (a[i][0] <= b // 2)) * (b // 2 + 2 - (a[i][1] >= b//2 + 2)) < a[i][0] * a[i][1] and (b // 2 + 1 + (a[i][0] <= b // 2 + 1)) * (b // 2 + 1 - (a[i][1] >= b // 2 + 1)) < a[i][0] * a[i][1]:
                b = b + 1
            else:
                break
        else:
            if ((b - 1) // 2 + (a[i][0] <= (b - 1) // 2)) * ((b + 5) // 2 - (a[i][1] >= (b + 5) // 2)) < a[i][0] * a[i][1] and ((b + 1) // 2 + (a[i][0] <= (b + 1) // 2)) * ((b + 3) // 2 - (a[i][1] >= (b + 3) // 2)) < a[i][0] * a[i][1] and ((b + 3) // 2 + (a[i][0] <= (b + 3) // 2)) * ((b + 1) // 2 - (a[i][1] >= (b + 1) // 2)) < a[i][0] * a[i][1]:
                b = b + 1
            else:
                break
    print(b - 1)

Measured memory_bytes: 3188
n = int(input())
lis = list(map(int,input().split()))
num = [0 for i in range(n+1)]
for nn in lis:
  num[nn] += 1
ans = 0
for nnn in num:
  ans += (nnn*(nnn-1))//2
for i in range(n):
  print(ans-(num[lis[i]]*(num[lis[i]]-1))//2+((num[lis[i]]-1)*(num[lis[i]]-2))//2)


Measured memory_bytes: 26140
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.util.InputMismatchException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int a = in.nextInt();
            int b = in.nextInt();

            int cnt = 0;
            for (int i = a; i <= b; i++) {
                String s = String.valueOf(i);
                String rev = new StringBuilder(s).reverse().toString();

                if (s.equals(rev)) cnt++;
            }

            out.println(cnt);
        }

    }

    static class InputReader {
        BufferedReader br;
        StringTokenizer st;

        public InputReader(InputStream inputStream) {
            br = new BufferedReader(new InputStreamReader(inputStream));
            st = new StringTokenizer("");
        }

        public String nextString() {
            while (!st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine(), " ");
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(nextString());
        }

    }
}



Measured memory_bytes: 36308
// SeeAlso: 

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define MAX 100000
#define NIL -1
#define MOD 1000000007

typedef int _loop_int;
#define rep(i,n) for(int i = 0; i < n; i++)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define debug(x) cout<<#x<<": "<<x<<endl
#define debig_vec(v) cout<<#v<<":";rep(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

// 最大公約数
inline constexpr ll gcd(ll a,ll b){if(!a||!b)return 0;while(b){ll c=b;b=a%b;a=c;}return a;}
// 最小公倍数
inline constexpr ll lcm(ll a,ll b){if(!a||!b)return 0;return a*b/gcd(a,b);}

#define print2D(h, w, arr) rep(i, h) { rep(j, w) cout << arr[i][j] << " "; cout << endl; }
template<class T> void print(const T& x){cout << setprecision(12) << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }

int main() {
    int h, a;
    cin >> h >> a;
    int c = h / a;
    if (h%a !=0) {
        c ++;
    }
    print (c);
    return 0;
}


Measured memory_bytes: 256
import sys
import math
import time
readline = sys.stdin.readline


def main():
    listSum = [1, 3, 6]
    k = int(input())
    sumGCD = 0
    for a in range(1, k + 1):
        for b in range(a, k + 1):
            for c in range(b, k + 1):
                sumGCD += gcd(a, b, c) * listSum[len(set([a, b, c])) - 1]
    print(sumGCD)


def gcd(a, b, c):
    return math.gcd(math.gcd(a, b), c)


if __name__ == '__main__':
    s = time.time()
    main()
    # print(time.time() - s)


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

int main() {
    int K; cin >> K;
    long long int ans = 0;
    for(int i = 1; i <= K; i++){
        for(int j = 1; j <= K; j++){
            for(int kk = 1; kk <= K; kk++){
                int a = max(i, j);
                int b = min(i, j);
                int hantei = 1;
                while(hantei != 0){
                    int r = a % b;
                    if(r == 0) hantei = 0;
                    else{
                        a = b;
                        b = r;
                    }
                }
                a = max(kk, b);
                b = min(kk, b);
                hantei = 1;
                while(hantei != 0){
                    int r = a % b;
                    if(r == 0) hantei = 0;
                    else{
                        a = b;
                        b = r;
                    }
                }
                ans += b;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#include <math.h>
#include <numeric>
using namespace std;
 
int gcd (int a, int b){
  int tmp, r;
  
  if(a<b){
    tmp = a;
    a = b;
    b = tmp;
  }
 
  // ユークリッドの互除法 
  r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }
  return b;
}

/*int gcd_abc(int a,int b, int c){

  int tmp;
  tmp = gcd(a,b);

  return(gcd(tmp,c));
}*/


int main() {
  int K,result,tmp;

  cin >> K;
  result=0;
  
  for(int a=1; a<=K; a++){
    for(int b=1; b<=K; b++){
      for(int c=1; c<=K; c++){
        tmp = gcd(a,b);
        tmp = gcd(tmp,c);
        result += tmp;
      }
    }
  }
  cout << result << endl;
}





Measured memory_bytes: 3636
#include<bits/stdc++.h>
typedef long long int ll;
using namespace std;
#define sz 200009
ll n,m,i,j,k,l,t,arr[sz];
int main()
{
    scanf("%lld",&n);
    double c=n/3.0;
    c=c*c*c;
    printf("%.10f\n",c);
    return 0;
}


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

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

    long long int an = 0;
    rep1(i,n+1){
        an += i * (n/i) * (n/i + 1) /2;
    }
    cout << an << endl;
}

Measured memory_bytes: 3624
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;
constexpr double pi = acos(-1);
constexpr double EPS = 1e-10;

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

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

    int n; cin>>n;
    vector<int> s(1<<n);
    multiset<int> st;
    for(int i=0; i<(1<<n); i++){
        cin>>s[i];
        st.insert(s[i]);
    }

    sort(s.begin(), s.end(), greater<int>());

    st.erase(s[0]);

    vector<int> v;
    v.emplace_back(s[0]);

    for(int i=0; i<n; i++){
        int sz = v.size();
        for(int j=0; j<sz; j++){
            auto itr = st.lower_bound(v[j]);
            if(itr == st.begin()) continue;

            itr--;
            v.emplace_back(*itr);
            st.erase(itr);
        }

        sort(v.begin(), v.end(), greater<int>());
    }

    if(v.size() == (1 << n)) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 14712
a,b = map(int,input().split())

dp = [0 for i in range(b+1)]

for i in range(a):
	w,h = map(int,input().split())
	for j in range(b,w-1,-1):
		dp[j] = max(dp[j],dp[j-w] + h)

print(max(dp))

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

typedef long long ll;

using namespace std;

int n, k, s, p, r;

int check(char x){
    if (x == 's') return r;
    if (x == 'p') return s;
    if (x == 'r') return p;
    return 0;
}

int main(){
    string t;
    cin >> n >> k >> r >> s >> p >> t;
    ll ans = 0;
    for (int i = 0; i < n; i++){
        if (i < n - k) {
            if (t[i] == t[i + k]){
                t[i + k] = 'a';
            }
        } //else {
            //ans += check(t[i]);
        //}
        ans += check(t[i]);
    }
    cout << ans;
    return 0;
}








Measured memory_bytes: 512
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "iomanip"
#include "random"

using namespace std;

const long long int MOD = 1000000007;
const long double EPS = 0.00000001;


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



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

	cin >> N >> K;
	vector<vector<int>>edge(N + 1);
	for (int i = 0; i < N - 1; i++) {
		cin >> L >> R;
		edge[L].push_back(R);
		edge[R].push_back(L);
	}
	M = N;
	if (K % 2) {
		for (int i = 1; i <= N; i++) {
			for (auto j : edge[i]) {
				if (j > i) {
					vector<int>dis(N + 1, INT_MAX);
					int box = 0;
					dis[i] = 0;
					dis[j] = 0;
					queue<int>Q;
					Q.push(i);
					Q.push(j);
					while (!Q.empty()) {
						int c = Q.front();
						for (auto k : edge[c]) {
							if (dis[k] > dis[c] + 1) {
								dis[k] = dis[c] + 1;
								if (dis[k] > K / 2) {
									box++;
								}
								Q.push(k);
							}
						}
						Q.pop();
					}
					M = min((int)M, box);
				}
			}
		}
	}
	else {
		for (int i = 1; i <= N; i++) {
			vector<int>dis(N + 1, INT_MAX);
			int box = 0;
			dis[i] = 0;
			queue<int>Q;
			Q.push(i);
			while (!Q.empty()) {
				int c = Q.front();
				for (auto k : edge[c]) {
					if (dis[k] > dis[c] + 1) {
						dis[k] = dis[c] + 1;
						if (dis[k] > K / 2) {
							box++;
						}
						Q.push(k);
					}
				}
				Q.pop();
			}
			M = min((int)M, box);
		}
	}
	cout << M << endl;
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    int A,B;
    cin >> A >> B;
    cout << (B + A - 3)/(A - 1) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

long long MOD = 1e9+7;
int MAX_INT = 1e9;

int main(void){
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

  long long H, W;
  cin >> H >> W;

  if(H == 1 || W == 1) cout << 1 << endl;
  else cout << (H * W + 1) / 2 << endl;

  return 0;
}


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

int main () {
    int x,a,b;
    cin >> x >> a >> b;
    if (b-a > x) {
        cout << "dangerous" << endl;
    } else if (b > a) {
        cout << "safe" << endl;
    } else {
        cout << "delicious" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
lr_array = [[int(x) for x in input().split()] for x in range(m)]
res_l  = 0
res_r  = float("inf")
for l, r in lr_array:
    res_l = max(res_l, l)
    res_r = min(res_r, r)
if res_l == res_r:
    print(1)
elif res_l > res_r:
    print(0)
else:
    print(res_r-res_l+1)


Measured memory_bytes: 21156
#include<iostream>
using namespace std;
int main(){
  int a,b,c;
  cin>>a>>b>>c;
  if(a>b){
    int t;
    t=a;
    a=b;
    b=t;
  }
  if((b-a)==1)
  cout<<"No"<<endl;
  else if((b>c)&&(a<c))
    cout<<"Yes"<<endl;
     else
     cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

typedef long long ll;
const ll INF = 1e17;
const ll BIG = 1000000007;

int main(){

	int N, M;
	cin >> N >> M;

	int x = 1;
	int y = N;

	for (int i = 1; i <= M; i++) {
		int l, r;
		cin >> l >> r;
		if (l > x) { x = l; }
		if (r < y) { y = r; }

	}

	cout << max(0,y - x + 1);


	system("PAUSE");
}

Measured memory_bytes: 504
/* Bell + Pascal + Catalan + Pythogorian + triangular + Fibonaci*/

#include <iostream>
#include <algorithm>
using namespace std;
#include <vector>
#include <map>
#include <set>
#include <cmath>    //floor ceil
#include <cstdio>
#include <climits>  //INT_MAX
#include <cstring>
#include <cstdlib>
#include <stack>
#include <list>
#include <queue>
#include <deque>
#include <unordered_map>

#define mp make_pair
#define pb push_back
#define endl "\n"
#define debug(x) cerr<<#x<<'='<<(x)<<endl;
#define lli long long int
#define ll long long
#define f first
#define s second
#define MOD 1000000007

int main () {
    int x;
    cin >>x;
    if(x>=30) cout<<"Yes";
    else cout<<"No";
    return 0;
}

Measured memory_bytes: 3588
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
    int n;
    cin>>n;
    if(n%2){
        vector<pint> ans;
        rep(i,n)rep(j,n){
            if(i>=j)continue;
            if(i+j==n-2)continue;
            ans.push_back({i+1,j+1});
        }
        cout<<ans.size()<<endl;
        for(auto p : ans){
            cout<<p.first<<" "<<p.second<<endl;
        }
    }
    else {
        vector<pint> ans;
        rep(i,n)rep(j,n){
            if(i>=j)continue;
            if(i+j==n-1)continue;
            ans.push_back({i+1,j+1});
        }
        cout<<ans.size()<<endl;
        for(auto p : ans){
            cout<<p.first<<" "<<p.second<<endl;
        }
    }
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
using P = pair<ll, ll>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep1(i, n) for(ll i=1;i<=(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define INF 1000000000

void solve_zenkoku2_a() {
	ll N, ans;
	cin >> N;
	
	if (N % 2 == 0) {
		ans = N / 2 - 1;
	}
	else {
		ans = (N - 1) / 2;
	}

	cout << ans << "\n";
}

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

	solve_zenkoku2_a();

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){

        int n,i,b,f,r,v=0,a[4][3][10]={0};
        scanf("%d",&n);
        for(i=0;i<n;i++){
                scanf("%d %d %d %d",&b,&f,&r,&v);
                a[b-1][f-1][r-1]+=v;
        }

        for(b=0;b<4;b++){
                for(f=0;f<3;f++){
                        for(r=0;r<10;r++)
                                printf("%2d",a[b][f][r]);
                        puts("");
                        }
                if(b!=3)        puts("####################");
        }
        return 0;
}


Measured memory_bytes: 2024
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
struct Pr{
	ll x,y;
}l_r[410000],r_l[410000];
 
struct Te{
	int ls,rs,lv,rv;
}t[410000];
 
int n;
ll mid;
vector<Pr>V[410000];
 
void insert(int x,Pr y){
	int i=V[x].size()-1;
	if(V[x].empty()){V[x].push_back(y);return;}
	if(V[x][i].y<=y.y)return;
	//while(!V[x].empty()&&V[x][i].x>=y.x)V[x].pop_back();
	V[x].push_back(y);
}
 
int dfs(int u){
	V[u].clear();
	int i,j,dt=t[u].lv+t[u].rv,ltor=0,rtol=0;
	int ls=t[u].ls,rs=t[u].rs,lv=t[u].lv,rv=t[u].rv;
	if(t[u].ls==0){
		insert(u,(Pr){0,0});
		return 1;
	}int jud=dfs(t[u].ls)|dfs(t[u].rs);
	if(jud==0)return 0;
	for(i=V[ls].size()-1,j=V[rs].size()-1;i>=0;i--){while(j>=0&&V[ls][i].y+V[rs][j].x+dt>mid)j--;if(j>=0)l_r[++ltor]=(Pr){V[ls][i].x+lv,V[rs][j].y+rv};}
	for(i=V[ls].size()-1,j=V[rs].size()-1;j>=0;j--){while(i>=0&&V[ls][i].x+V[rs][j].y+dt>mid)i--;if(i>=0)r_l[++rtol]=(Pr){V[rs][j].x+rv,V[ls][i].y+lv};}
	reverse(l_r+1,l_r+ltor+1);
	reverse(r_l+1,r_l+rtol+1);
	i=1;j=1;
	while(i<=ltor&&j<=rtol){
		if(l_r[i].x<r_l[j].x){insert(u,l_r[i]);i++;}
		else {insert(u,r_l[j]);j++;}
	}while(i<=ltor){insert(u,l_r[i]);i++;}
	while(j<=rtol){insert(u,r_l[j]);j++;}
	return !V[u].empty();
}
 
int main(){
	int x,y;
	scanf("%d",&n);
	ll L=-1,R=17179869184ll;
	for(int i=2;i<=n;i++){
		scanf("%d %d",&x,&y);
		if(t[x].ls==0)t[x].ls=i,t[x].lv=y;
		else t[x].rs=i,t[x].rv=y;
	}while(L+1<R){
		mid=(L+R)>>1;
		if(dfs(1)){
			R=mid;
		}else L=mid;
		//for(int )
	}printf("%lld\n",R);
	return 0;
}

Measured memory_bytes: 43560
#include<bits/stdc++.h>
#define endl "\n"
#define ll long long int
#define MOD 1000000007
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define rep(i,a,b) for(long long int i=a;i<b;i++)
#define nrep(i,a,b) for(long long int i=a;i>=b;i--)
using namespace std;
int main()
{
	fast;
  	ll n1;
  cin>>n1;
  	cout<<(n1*(n1-1))/2;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define lli long long int
#define inf 2147483647
#define infll LLONG_MAX
#define rep(i, n) for(int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);
    
    int n, in;
    cin >> n;
    map<int, int> m;

    m[n] = 0;
    for(int i = 1; i<n; i++){
        m[i] = 0;
        cin >> in;
        m[in]++;
    }
    for(auto p: m){
        cout << p.second << endl;
    }
}

Measured memory_bytes: 13020
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#pragma GCC target ("avx2")
#pragma GCC optimization ("unroll-loops")
#define rep(i, n) for(int i=0;i<(int)(n);++i)
template <typename T> ll gcd(T a, T b) {return b?gcd(b, a%b):a;}
template <typename T> ll lcm(T a, T b) {return a * b / gcd(a, b);};
template <typename T> inline void chmin(T &a, const T& b){if(a>b)a=b;}
template <typename T> inline void chmax(T &a, const T& b){if(a<b)a=b;}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll h, w;
  cin >> h >> w;
  ll ans = w * (h/2);
  if (h % 2) {
    ans += (w+1)/2;
  }
  if (h == 1 || w == 1) {
    ans = 1;
  }
  cout << ans << '\n';
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>

using namespace std;

const int N = 110;
double dp[N][N];
int L[N], B[N];

int main(){
	cout.setf(ios::fixed);
	cout.precision(8);

	int n, t, l, b;
	while (cin >> n >> t >> l >> b, n){
		memset(dp, 0, sizeof(dp));
		memset(L, 0, sizeof(L));
		memset(B, 0, sizeof(B));
		while (l--){
			int x;
			cin >> x;
			L[x] = 1;
		}
		while (b--){
			int x;
			cin >> x;
			B[x] = 1;
		}

		dp[0][0] = 1;
		for (int i = 0; i < t; ++i){
			for (int j = 0; j < n; ++j){
				double prob = dp[i][j] / 6;
				for (int k = 1; k <= 6; ++k){
					int nxt = j + k;
					if (nxt > n) nxt = n - (nxt-n);
					if (B[nxt]) nxt = 0;
					dp[i + 1 + L[nxt]][nxt] += prob;
				}
			}
			dp[i + 1][n] += dp[i][n];
		}
		cout << dp[t][n] << '\n';
	}

	return 0;
}

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

using namespace std;
int main(){
    int N;
    cin >> N;
    vector<int> a(N);
    for (auto it = a.begin(); it != a.end(); ++it){
        cin >> *it;
    }
    int counter =0;
    for (auto it = a.begin(); it != a.end(); ++it){
        while(*it%2 == 0){
            *it = *it/2;
            counter++;
        }
    }
    cout << counter << endl;
    return 0;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val N = readLine()!!
    val ans = readLine()!!.split(" ").map(String::toInt).map {
        var tmp = it
        var res = 0
        while(tmp%2==0) {
            res++
            tmp /= 2
        }
        res
    }.min()
    println(ans)
}

Measured memory_bytes: 38088
#include <stdio.h>

int main(){
	int n,d;
    int nokori;
    int k;
    int count;
  
  	scanf("%d %d",&n,&d);
  
    k = d*2 + 1;
    nokori = n;
  
    while(0 < nokori){
    	if(k < nokori){
            count++;
     		nokori = nokori - k; 
    	}else{
        	count++;
            break;
        }
    } 
  	printf("%d",count);  
   	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main(){
    int A, B, H, M;
    cin >> A >> B >> H >> M;
    double rad = (double)(H*30 + M*0.5 - M*6)*M_PI/180.0;
    double ans = sqrt(A*A + B*B -2.0*A*B*cos(rad));
    printf("%10.10f\n", ans);

    return 0;
}

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

using namespace std;

int main() {
  long long A, B, N;
  cin >> A >> B >> N;
  long long x = min(B - 1, N);
  long long ans = A * x / B - A * (x / B);
  cout << ans << endl;

  return 0;
}
/* vim:set fdm=marker: */


Measured memory_bytes: 3632
#include<stdio.h>
  typedef struct{
  double x;
  double y;
}point;

double root=1.732050807568877;

void kock (int n,point p1,point p2){
  point s,t,u;
  if (n == 0)return;
   s.x=(p1.x*2+p2.x*1)/3;
   s.y=(p1.y*2+p2.y*1)/3;
   t.x=(p1.x*1+p2.x*2)/3;
   t.y=(p1.y*1+p2.y*2)/3;
   u.x=(t.x-s.x)/2-(t.y-s.y)*(root/2)+s.x;
   u.y=(t.x-s.x)*(root/2)+(t.y-s.y)/2+s.y;

   kock(n-1, p1, s);
   printf("%.8lf %.8lf\n",s.x,s.y);
   kock(n-1, s, u);
   printf("%.8lf %.8lf\n",u.x,u.y);
   kock(n-1, u, t);
   printf("%.8lf %.8lf\n",t.x,t.y);
   kock(n-1, t, p2);
}
int main (){
  int n;
  point p1={0,0},p2={100,0};
  scanf("%d",&n);
  printf("%.8lf %.8lf\n",p1.x,p1.y);
  kock(n,p1,p2);
  printf("%.8lf %.8lf\n",p2.x,p2.y);
  return 0;
}



Measured memory_bytes: 2060
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <cmath>

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

constexpr ll LLINF {1001002003004005006};//ll = 9*LLINF
constexpr int INTINF {1000000000};//int = 2*INTINF

#define  rep(i,n)   for(int i = 0; i < (n); ++i)
#define rrep(i,n)   for(int i = 1; i <= (n); ++i)
#define drep(i,n)   for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for(int i = s; i < t;  ++i)

template<typename T>
void maxs(T& x, T&& y) {
  x=std::max(x,y);
}
template<typename T>
void maxs(T& x, T& y) {
  x=std::max(x,y);
}

template<typename T>
void mins(T& x, T&& y) {
  x=std::min(x,y);
}
template<typename T>
void mins(T& x, T& y) {
  x=std::min(x,y);
}

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

  int n, x, t;
  cin >> n >> x >> t;
  cout << ((n+(x-1))/x)*t << '\n';
}


Measured memory_bytes: 3540
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;

class Solution {
public:
    int solve(int l, int r) {
        const long long MOD = 2019;

        vector<int> cnts(MOD, 0);

        int N = MOD * 2 + 123;

        for (int i = l, j = 0; i <= r && j < N; ++i, ++j) {
            ++cnts[i % MOD];
        }

        long long res = MOD;
        for (int i = 0; i < MOD; ++i) {
            for (int j = i; j < MOD; ++j) {
                if ((i == j && cnts[i] > 1) || (i != j && cnts[i] > 0 && cnts[j] > 0)) {
                    res = min(res, (i * 1LL * j) % MOD);
                }
            }
        }

        return res;
    }
};

int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int l, r;
    cin >> l >> r;
    Solution sol;

    cout << sol.solve(l, r) << "\n";

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int N,C,i,j,s,t,c,cs[100001],sum,ans,len;
vector<pair<int,int>> vii[31],tmp;
int main(void){
  cin>>N>>C;
  for(i=0;i<N;i++){
    cin>>s>>t>>c;
    vii[c].push_back(make_pair(s,t));//チャンネルごとに開始時刻と終了時刻のペアをまとめる
  }
  for(i=1;i<=C;i++){
    sort(vii[i].begin(),vii[i].end());//チャンネルごとに開始時刻、終了時刻でそれぞれ昇順にソート
    tmp.clear();
    len=vii[i].size();
    for(j=0;j<len;j++)
      if(tmp.empty()||tmp.back().second<vii[i][j].first)tmp.push_back(vii[i][j]);//tmp.empty()は一番最初でtrueとなる
      else tmp.back().second=vii[i][j].second;//録画する最後の番組の終了時刻と次に録画する番組の開始時刻が連続しているときはつなげる
    len=tmp.size();
    for(j=0;j<len;j++){
      //累積和で各時間での録画機の個数を求めるために
      cs[tmp[j].first]++;//開始時刻には++をして
      cs[tmp[j].second+1]--;//終了時刻+1には--をしておく
    }
  }
  for(i=0;i<100001;i++){
    sum+=cs[i];//sumは時刻iで使用している録画機の個数
    ans=max(ans,sum);
  }
  cout<<ans<<endl;
  return EXIT_SUCCESS;
}


Measured memory_bytes: 1920
#include<iostream>
#include<cstdio>
#include <stdio.h>
#include<algorithm>
#include<cstring>
#include <string>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<map>
#include<vector>
#include<bits/stdc++.h>
#include <set>
#define ll   long long
#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
#define inf 0x3f3f3f3f
#define pi 3.1415926535898
#define mod 998244353
#define N 200010
using namespace std;
ll inv[N];
ll fac[N];
ll n,m,k,ans;
ll pows(ll a,ll n)
{
    ll ans=1;
    while(n)
    {
        if(n&1)
        {
            ans=ans*a%mod;
        }
        a=a*a%mod;
        n>>=1;
    }
    return ans%mod;
}

ll C(ll m,ll n)//组合数公式
{
    return fac[m]*inv[n]%mod*inv[m-n]%mod;
}
int main()
{
    cin>>n>>m>>k;
    int xx=max(n,m);
    fac[0]=1;
    ans=0;
    ll p=pows(m-1,n-k-1);
    for(int i=1; i<=xx; i++)
    {
        fac[i]=fac[i-1]*i%mod;
    }
    inv[xx]=pows(fac[xx],mod-2);
	for(int i=xx-1;i>=0;i--)inv[i]=inv[i+1]*(i+1)%mod;
    for(int i=n-k; i<=n; i++)
    {
        ans=(ans+m*p%mod*C(n-1,i-1)%mod)%mod;
        p=p*(m-1)%mod;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 6692
#include <iostream>
#include <math.h>

using namespace std;

bool check(int num){
	int SQRT;
	bool checker = false;
	SQRT = (int)sqrt(num);
	for(int i = 2; i < SQRT; i++){
		if(num % i == 0){
			checker = true;
			break;
		}else{
			continue;
		}
	}

	return checker;
}

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

	while(1){
		if(check(X)){
			X++;
		}else{
			cout << X << endl;
			break;
		}
	}


	return 0;


}




Measured memory_bytes: 256
fun main(args: Array<String>) {
    val n = readLine()?.toLong() ?: return

    var result = Int.MAX_VALUE

    for (a in 1..(Math.sqrt(n.toDouble()).toLong())) {
        if ((n % a) != 0L) {
            continue
        }
        val b = n / a
        val f = f(a, b)
        if (f < result) {
            result = f
        }
    }

    println(result)
}

private fun f(a: Long, b:Long): Int {
    var max = Math.max(a, b)
    var count = 0
    while (max >= 1) {
        max /= 10
        count++
    }
    return count
}

Measured memory_bytes: 31624
import sys

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

k,s = na()
ans = 0
for x in range(k+1):
    for y in range(k+1):
        z = s - (x+y)
        if z >= 0 and z <= k:
            ans += 1
print(ans)


Measured memory_bytes: 3060
#include <iostream>
#include <string>
#define REP(i,n) for(int i=0;i<(n);++i)
using namespace std;

int main(){
    string S;
    cin >> S;
    int len = S.size();
    REP(i,len-1){
        if(S[i] == S[i+1]){
            cout << i+1 << " " << i+2 << endl;
            return 0;
        }
    }
    REP(i,len-2){
        if(S[i] == S[i+2]){
            cout << i+1 << " " << i+3 << endl;
            return 0;
        }
    }
    cout << "-1 -1" << endl;
}

Measured memory_bytes: 512
// Copyright 2019 yaito3014
#include "bits/stdc++.h"
using namespace std;

int main() {
  cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false);
  int H, A;
  cin >> H >> A;
  cout << (int)ceil(H / (float)A) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B,L,R;
string S,T;
const ll MOD = (1e+9) + 7;
const ll INF = 1LL << 60;
typedef pair<ll,ll> P;

typedef vector<P> vp;
typedef vector<vp> matP;

int main(){
    cin>>A>>B;
    ll ans = 0;
    reps(i,A,B+1){
        if(i%10 == i/10000){
            if((i/10)%10 == (i%10000)/1000) ++ans;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
import sys
read = lambda: sys.stdin.readline().rstrip()
 
N,W=map(int,read().split())
 
def solve_knapsack(capacity):
    # basic checks
 
    dp = [0]*(capacity + 1)
    # populate the capacity = 0 columns, with '0' capacity we have '0' profit
 
    for i in range(0, N):
        weights,profits = map(int,read().split())
        for c in range(capacity, weights-1, -1):
            tmp = profits + dp[c - weights]
            if tmp > dp[c]: dp[c] = tmp
 
    # maximum profit will be at the bottom-right corner.
    return dp[capacity]
  
def main():
 
    res = solve_knapsack(W)
 
    print(res)
if __name__ == "__main__":
	main()

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

using namespace std;

long long a,b,c,d,ans;

long long gcd(long long a,long long b)
{
    if(a % b)
        gcd(b,a % b);
    else
        return b;
}

long long f(long long a,long long c,long long d)
{
    long long s = a - (a / c + a / d - (a /(c * d / gcd(c,d))));
    return s;
}

int main()
{
    ans = 0;
    scanf("%lld%lld%lld%lld",&a,&b,&c,&d);
    ans = f(b,c,d) - f(a - 1,c,d);
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 256
package main

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

var sc = NewScanner()

func main() {
	n := sc.NextInt()
	k := sc.NextInt()

	a := make([]int, n)

	for i := 0; i < n; i++ {
		a[i] = sc.NextInt()
	}

	sort.Ints(a)

	min := a[0]
	i := 0
	for ; i < n; i++ {
		if min != a[i] {
			break
		}
	}
	result := (n - i) / (k - 1)
	if (n-i)%(k-1) > 0 {
		result += 1
	}
	fmt.Println(result)
}

type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	return &Scanner{sc}
}

func (sc *Scanner) NextInt() int {
	sc.sc.Scan()
	i, err := strconv.Atoi(sc.sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}


Measured memory_bytes: 2048
// Try AtCoder
// author: Leonardone @ NEETSDKASU

fn main() {
    let mut stdin = String::new();
    std::io::Read::read_to_string(&mut std::io::stdin(), &mut stdin).unwrap();
    let mut stdin = stdin.split_whitespace();
    let mut get = || stdin.next().unwrap();
    macro_rules! get { () => ( get().parse().unwrap() ) }
    
    let n = get!();
    let mut vs = vec![0; n];
    for i in 0..n {
    	vs[i] = get!();
    }
    let mut ans = 0;
    let mut p = 2;
    loop {
    	for &v in &vs {
        	if v % p != 0 {
            	println!("{}", ans);
                return;
            }
    	}
        ans += 1;
        p *= 2;
    }
}

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

using namespace std;

#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

int main() {
    int N, C;
    cin >> N >> C;
    vector<vl> D(C, vl(C));
    vector<vl> c(N, vl(N));
    rep(i, C) rep(j, C) cin >> D[i][j];
    rep(i, N) rep(j, N) cin >> c[i][j], c[i][j]--;

    vector<vl> cost(3, vl(C, 0));
    rep(col, C) {
        rep(y, N) rep(x, N) {
            int k = (y + x) % 3;
            cost[k][col] += D[c[y][x]][col];
        }
    }

    ll ans = 1e18;
    rep(i, C) rep(j, C) rep(k, C) {
        if(i == j || j == k || k == i) continue;
        ans = min(ans, cost[0][i] + cost[1][j] + cost[2][k]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2176
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i = 0;i<((ll)(n));i++)
#define reg(i,a,b) for(ll i = ((ll)(a));i<=((ll)(b));i++)
#define irep(i,n) for(ll i = ((ll)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(ll i = ((ll)(b));i>=((ll)(a));i--)
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T = int> void print(vector<T> v){for(auto a:v)cout<<a<<" ";cout<<endl;}

/*
*/

template<class T> class bit {
public:
    vector<T> dat;
    int N;

    bit(){}
    void init(int _N){
		N=_N;
		dat.assign(N,0);
	}
    // sum [0,i)
    T sum(int i){
        int ret = 0;
        for(--i; i>=0; i=(i&(i+1))-1) ret += dat[i];
        return ret;
    }
    // sum [i,j)
    T sum(int i, int j) { return sum(j) - sum(i); }
    // add x to i
    void add(int i, T x) { for(; i < N; i|=i+1) dat[i] += x; }
};

string s;
ll n,q;
bit<int> a[26];

void init(){
	cin>>n>>s>>q;
	rep(i,26)a[i].init(2*n);
	rep(i,n)a[s[i]-'a'].add(i,1);
}

int main(void){
	init();
	rep(i,q){
		int qu;
		cin>>qu;
		if(qu==1){
			int p;
			char c;
			cin>>p>>c;
			a[s[p-1]-'a'].add(p-1,-1);
			a[c-'a'].add(p-1,1);
			s[p-1]=c;
		}else{
			int l,r,ans=0;
			cin>>l>>r;
			rep(j,26){
				if(a[j].sum(r)-a[j].sum(l-1)>0)ans++;
			}
			cout<<ans<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 102532
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <cstdio>
#include <cstring>
using namespace std;

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

    int64_t cur = 0, maxi = -1;
    for (int64_t i = 1; cur < n; i++) {
        cur += i;
        maxi = i;
    }

    cur = n;
    while (cur > 0)
    {
        if (maxi <= cur) {
            cout << maxi << endl;
            cur -= maxi;
        }
        maxi--;
    }

    return 0;
}

Measured memory_bytes: 384