akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		long max = 0;
		boolean isYes = true;

		for(int i = 0; i < n; i++) {
			long tmp = in.nextInt();

			if(max < tmp) {
				max = tmp -1;
			}else if(max == tmp) {

			}else {
				isYes = false;
				break;
			}
		}

		String ans = (isYes) ? "Yes" : "No";

		System.out.println(ans);
	}
}

Measured memory_bytes: 47932
#include <stdio.h>
#include <limits>
#include <cmath>
#include<iostream>
#include<string>
#include <vector>
#include<algorithm>
using namespace std;


int main() {
	int N, A, B;
	cin >> N >> A >> B;
	int n,i;
	int Nshou,Namari,Nsum = 0;
	int power;


	for (n = 1; n <= N; n++) {
		Nshou = 0;
		Namari = n;
		for (i = 4; i >= 0; i--) {		//桁下がる
			power = (int)pow(10, i);
			Nshou += Namari / power;
			Namari = Namari % power;
			//cout << Nshou << ' ' << Namari << endl;
		}
		if (Nshou >= A && Nshou <= B) {
			Nsum += n;
			//cout << Nsum << endl;
		}
	}
	cout << Nsum << endl;
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
using namespace std;
int main(void){
    // Here your code !
    char r,b,g;
    cin>>r>>b>>g;
    int result = (int)(r -'0')*100+(int)(b -'0')*10+(int)(g -'0');
    string str =(result%4 == 0)?"YES":"NO";
    cout<<str<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define all(n) n.begin(),n.end()
struct P{
	int x,y;
	P(int a,int b){x=a,y=b;}
};

int compress(vector<int> &org,int length,vector<int> &one,vector<int> &two){
	sort(all(org));
	org.erase(unique(all(org)),org.end());
	int cur = 0;
	for(int i=(org[0]==0?1:0);i<org.size();i++){ //org[0]ª0¾Á½çíé(»êÍ±Üé)B
		if(org[i] == cur+1) cur += 1; //×ÚµÄ½ç1Â¾¯¸ç·B
		else cur += 2;	//×ÚµÄÈ¢ñ¾Á½ç2Â(1ÂÔªó­æ¤Éæéæ)
		rep(j,one.size()){
			if(one[j] == org[i]) one[j] = cur;
			if(two[j] == org[i]) two[j] = cur;
		}
	}
	return cur + (org.back()!=length); // org.back() !- length¾Á½êóÔÉÜ¾]Tª éÌÅTCYÍlength = cur+1Æ·éB
}

bool board[2000][2000];
void dfs(bool Map[2000][2000],P start,int W,int H){
	static const int dx[] = {0,0,-1,1} , dy[] = {1,-1,0,0};
	
	stack<P> S;
	S.push(start);
	while(S.size()){
		P s = S.top(); S.pop();
		rep(i,4){
			P t = P(s.x+dx[i],s.y+dy[i]);
			if(t.y >= 0 && t.x >= 0 && t.y < H && t.x < W && Map[t.y][t.x] == 0){
				Map[t.y][t.x] = true;
				S.push(t);
			}
		}
	}
}


int main(){
	int W,H;
	while(cin >> W >> H , W){
		vector<int> ox,oy,sx,ex,sy,ey;
		int n; cin >> n;
		rep(i,n){
			int x1,y1,x2,y2;
			cin >> x1 >> y1 >> x2 >> y2;			
			sx.push_back(x1),sy.push_back(y1); //s? = ¶º (ÀW³k³êéû1)
			ex.push_back(x2),ey.push_back(y2); //e? = Eã (ÀW³k³êéû2)
			
			ox.push_back(x1),oy.push_back(y1); //o? = s?àe?àÇÁ¿àÂÁ±ÞB(ÀW³kÌÚóÉg¤)
			ox.push_back(x2),oy.push_back(y2); //
		}
		// ³k compress(...)ÌÔèlÍ³kãÌÕÊTCYB
		W = compress(ox,W,sx,ex);
		H = compress(oy,H,sy,ey);
		
		
		rep(i,H)rep(j,W)board[i][j] = false; // ú»
		
		//³kãÌ¶ºÆEãÀWðgÁÄÕÊðhèÂÔ·B
		rep(i,n){
			for(int x = sx[i] ; x < ex[i] ; x++){
				for(int y = sy[i] ; y < ey[i] ; y++){
					board[y][x] = true;
				}
			}
		}
		//hèÂÔµÈªç¦é´¶BÀÛÉhèÂÔ·ÌÍdfs()ÖB
		int ans = 0;
		rep(y,H){
			rep(x,W){
				if(board[y][x] == false){
					ans++;
					dfs(board,P(x,y),W,H);
				}
			}
		}
		
		cout << ans << endl;
	}
}

Measured memory_bytes: 4088
#include<stdio.h>
int main()
{
    int a,b,c,d;
    scanf("%d%d%d",&a,&b,&c);
    d=a*b;
    if(d>c)
    {
        printf("%d\n",c);
    }
    else
    {
        printf("%d\n",d);
    }
    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
char s[100007];int get[128];
void sb()
{
    return;
}
int main(void)
{
    get['b']=0,get['p']=1,get['d']=2,get['q']=3;
    scanf("%s",s+1);
    for(int l=strlen(s+1),i=1;i<=(l>>1)+1;++i)
        if(get[s[i]]^((get[s[l-i+1]]+2)%4)) return printf("No\n"),0;
    return printf("Yes\n"),0;
    sb();
    return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+5;
const int inf=0x3f3f3f3f;
bool check(int k,int x,int y)
{
	int l=1,r=100;
	while(l<r)
	{
		int mid=(l+r+1)/2;
		if((x+mid)*(x+mid)+(y+mid)*(y+mid)<=k)
			l=mid;
		else
			r=mid-1;
	}
	if((x+r)*(x+r)+(y+r)*(y+r)==k)
		return true;
	return false;
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		int ans=0;
		for(int x=1;x<=100;x++)
		{
			for(int y=1;y<=100;y++)
			{
				int nn=i*2;
				int sum=(x+y)*(x+y);
				sum=nn-sum;
				if(check(sum,x,y))
					ans++;
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}




Measured memory_bytes: 3608
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <list>
#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() {
    string S;
    int Q;
    cin >> S >> Q;
    vector<int> T(Q), F(Q);
    vector<char> C(Q);

    list<char> v(S.begin(), S.end());
    bool order = true;

    REP(i, Q) {
        cin >> T[i];
        if(T[i] == 2) {
            cin >> F[i] >> C[i];
        }
    }

    REP(i, Q) {
        if(T[i] == 1){
            if(order)
                order = false;
            else
                order = true;
        }
        else if ((order == true && F[i]==1) || (order == false && F[i]==2)) v.push_front(C[i]);
        else v.push_back(C[i]);
    }

    // cerr << "order" << order << endl;
    if(order) {
        for(char c: v)
            cout << c;
        cout << endl;
    }
    else {
        reverse(v.begin(), v.end());
        for(char c: v)
            cout << c;
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 11776
import sys
sys.setrecursionlimit(10**6) #再帰関数の上限
import math
from copy import copy, deepcopy
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque 
#deque(l), pop(), append(x), popleft(), appendleft(x)
##listでqueの代用をするとO(N)の計算量がかかってしまうので注意
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
#import fractions#古いatcoderコンテストの場合GCDなどはここからimportする

def input(): return sys.stdin.readline()[:-1]
def printl(li): print(*li, sep="\n")
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds

def main():
    mod = 10**9+7
    #w.sort(key=itemgetter(1),reversed=True)  #二個目の要素で降順並び替え

    #N = int(input())
    N, M = map(int, input().split())
    #A = tuple(map(int, input().split())) #1行ベクトル
    #L = tuple(int(input()) for i in range(N)) #改行ベクトル
    #S = tuple(tuple(map(int, input().split())) for i in range(N)) #改行行列
    tot=[[] for _ in range(N+1)]
    ys=[0]*M
    for i in range(N):
        heapify(tot[i])
    for i in range(M):
        P, Y = map(int, input().split())
        heappush(tot[P],[Y,i])
        ys[i]=Y
    tset=[]
    ans=['']*M
    for i in range(N+1):
        t1=tot[i]
        if len(t1)<1:continue
        p=str(i).zfill(6)
        j=0
        while len(t1):
            t, i1=heappop(t1)
            tx=str(j+1).zfill(6)
            ans[i1]=p+tx
            j+=1
    print('\n'.join(ans))





if __name__ == "__main__":
    main()

Measured memory_bytes: 33920
#include <vector>
#include <iostream>
#include <cmath>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <fstream>
#include <unistd.h>
#include <string.h>
#include <string>
#include <numeric>
#include <queue>
#include <deque>
#include <sstream>
#include <iomanip>
#include <set>
#include <stack>
#include <cassert>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vvb> vvvb;
typedef vector<vvvb> vvvvb;
typedef vector<string> vs;
typedef vector<vs> vvs;
typedef vector<vvs> vvvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<vvd> vvvd;
typedef pair<ll, ll> PL;
typedef vector<PL> vpl;
typedef vector<vector<PL>> vvpl;
const int INF = 1001001001;
const ll LINF = 1e17;
const double pi = 3.1415926535897932;
const string endstr = "\n";
#define FOR(i, a, b) for(ll i = (a); i < b; i++)
#define RFOR(i, a, b) for(ll i = (a); i > b; i--)
#define rep(i, n) for(ll i = 0; i < n; i++)
#define rrep(i, n) for(ll i = n-1; i > -1; i--)
#define FORMAP(it, m) for(auto it = m.begin(); it != m.end(); it++)
#define ff first
#define ss second
#define pb push_back
#define epb emplace_back
#define ALL(X) (X).begin(),(X).end()

template <typename T>
T gcd(T a, T b) {
    return (a == 0) ? b : gcd(b%a, a);
}
template <typename T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}

bool p_comp_fs(const PL p1, const PL p2){ return p1.first < p2.first;};
bool p_comp_fg(const PL p1, const PL p2){ return p1.first > p2.first;};
bool p_comp_ss(const PL p1, const PL p2){ return p1.second < p2.second;};
bool p_comp_sg(const PL p1, const PL p2){ return p1.second > p2.second;};
template <typename T>
vector<T> uniquen(vector<T> vec){
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
    return vec;
}

inline ll popcnt(ll x){return __builtin_popcountll((unsigned long long)x);};
template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }




int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    ll N; cin >> N;
    vs S(N);
    rep(i, N) cin >> S[i];
    map<vl, ll> m;
    rep(i, N){
        auto s = S[i];
        vl cnt(26, 0);
        rep(j, 10){
            cnt[s[j]-'a']++;
        }
        m[cnt]++;
    }
    
    ll ans = 0;
    FORMAP(it, m){
        if(it->ss >= 2){
            ans += it->ss*(it->ss-1)/2;
        }
    }
    cout << ans << endstr;
    return 0;
}


Measured memory_bytes: 35456
n = int(input())
A = list(map(int, input().split()))
q = int(input())
m = list(map(int, input().split()))

flag = [False] * 2000
for i in range(2 ** n):
    # 各数字を使うかどうかを0,1で表現
    S = 0
    for j in range(n):
        if ((i >> j) & 1):
            S += A[j]
    flag[S] = True

for k in m:
    print('yes') if flag[k] else print('no')





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

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

  string s; cin >> s;
  rep(i, s.length()) {
    if(i%2==0) cout << s[i];
  }
  cout << '\n';
}


Measured memory_bytes: 592
#include <bits/stdc++.h>
#include <boost/numeric/ublas/matrix.hpp>
#include <boost/numeric/ublas/vector.hpp>

using namespace std;
using namespace boost::numeric;

typedef long long ll;
#define FOR(i,n) for(int i=0; i<int(n); i++)
#define FOR1(i,m,n) for(int i=int(m); i<int(n); i++)

const int MAXN=1e9;
const int MAXM=1e5;
const int MOD=1e9+7;
int N, M, IDX=0;
int X[MAXM];
ublas::matrix<ll> mat1(3,3), mat2(3,3);
ublas::vector<ll> vec(3);
ublas::matrix<ll> accum=ublas::identity_matrix<ll>(3);

ublas::matrix<ll> pow(ublas::matrix<ll> base, int exponent) {
    ublas::matrix<ll> ans;
    if (exponent == 0)
        ans = ublas::identity_matrix<ll>(3);
    else if (exponent % 2 == 1)
        ans = ublas::prod(base, pow(base, exponent-1));
    else {
        ublas::matrix<ll> tmp = pow(base, exponent / 2);
        ans = ublas::prod(tmp, tmp);
    }

    transform(ans.data().begin(), ans.data().end(),
              ans.data().begin(), [](ll x){return x%MOD;});
    return ans;
}

ublas::vector<ll> dp(int n) {
    if (IDX == M) {
        accum = ublas::prod(accum, pow(mat1, N-n));
        transform(accum.data().begin(), accum.data().end(),
                  accum.data().begin(), [](ll x){return x%MOD;});
        return ublas::prod(accum, vec);
    }
    else if (IDX < M && X[IDX] > n) {
        int exponent = X[IDX]-n;
        accum = ublas::prod(accum, pow(mat1, exponent));
        transform(accum.data().begin(), accum.data().end(),
                  accum.data().begin(), [](ll x){return x%MOD;});
        return dp(X[IDX]);
    }
    else {
        IDX++;
        accum = ublas::prod(accum, mat2);
        transform(accum.data().begin(), accum.data().end(),
                  accum.data().begin(), [](ll x){return x%MOD;});
        return dp(n+1);
    }
}

int main(int argc, char *argv[])
{
    int init1[3][3] = {{1,2,1},
                       {0,1,1},
                       {1,2,2}};
    int init2[3][3] = {{1,2,1},
                       {0,1,1},
                       {0,0,1}};
    int init3[3] = {0,0,1};
    ublas::vector<ll> ans;
    
    FOR(i,3) {
        FOR(j,3) {
            mat1(i,j) = init1[i][j];
            mat2(i,j) = init2[i][j];
        }
        vec(i) = init3[i];
    }

    cin >> N >> M;
    FOR(i,M) cin >> X[i];

    ans = dp(0);
    cout << ans[0] << endl;
    
    return 0;
}


Measured memory_bytes: 50688
n = int(input())
time = 0
point = [0,0]
for i in range(n):
    t,x,y = map(int,input().split())
    distance = abs(x-point[0]) + abs(y-point[1])
    dum_time = t-time
    if distance > dum_time:
        print("No")
        exit()
    elif distance%2 != dum_time%2:
        print("No")
        exit()
    time = t
    point[0] = x
    point[1] = y
print("Yes")

Measured memory_bytes: 46184
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <map>
#include <numeric>
#include <random>
using namespace std;

const int cm = 1 << 17;
char cn[cm], *ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

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

int gcd_of_vector(int A[100000], int begin, int end){
  int result = A[begin];
  for(int i=begin;i<end;i++){
    result = gcd(A[i],result);
  }
  return result;
}

int gcd_of_vector_with_skip(int A[100000], int skip, int size){
  int result = A[0];
  if(skip==0)result=A[1];
  for(int i=1;i<size;i++){
    if(i==skip)continue;
    result = gcd(A[i],result);
  }
  return result;
}

int main() {
  int gcd1,gcd2,ans,N=getint();
  int A[100000];
  for(int i=0;i<N;i++)A[i]=getint();

  if(N>=100){
    gcd1 = gcd_of_vector(A,0,N/2);
    gcd2 = gcd_of_vector(A,N/2,N);
    ans = max(gcd1,gcd2);
  }else{
    ans=0;
    for(int i=0;i<N;i++){
      ans=max(ans,gcd_of_vector_with_skip(A,i,N));
    }
  }

  cout<<ans<<"\n";

  return 0;
}


Measured memory_bytes: 768
/* 
 * Author: pawanmsr
 */

#include <bits/stdc++.h>

using namespace std;
typedef long long int ll;

// Macro //
#define X first
#define Y second
#define pii pair<int,int>
#define pll pair<ll,ll>

// Global //
int n;

// Functions //

// Main //
int main(int argc, char const *argv[])
{
    // ios_base::sync_with_stdio(false);
    // cin.tie(NULL);
    
    /* code */
    cin >> n;
    ll sum = 0;
    for (int i=1; i<=n; i++) {
        if (i%3 && i%5) {
            sum += i;
        }
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 3636
program roller_coaster
  implicit none
  integer :: n, a(100000,2) = 0, i
  read(*,*) n
  read(*,*) a(1:n,1)
  do i = 1, n
    a(i,2) = i
  end do
  call merge_sort(a(1:n,:))
  write(*,'(i0)',advance='no') a(1,2)
  do i = 2, n
    write(*,'(x,i0)',advance='no') a(i,2)
  end do
  write(*,*)
contains
  subroutine merge_sort(a)
    integer, intent(inout) :: a(:,:)
    integer :: n, m, l, i, u
    n = size(a,1)
    m = n
    l = 1
    do while (m > 1)
      do i = 1, m/2
        u = min(2*i*l,n)
        call merger(a(2*(i-1)*l+1:(2*i-1)*l,:),a((2*i-1)*l+1:u,:))
      end do
      l = 2*l
      m = (m+1)/2
    end do
  end
  subroutine merger(a1,a2)
    integer, intent(inout) :: a1(:,:), a2(:,:)
    integer :: a(size(a1,1)+size(a2,1),size(a1,2))
    integer :: i1, i2, n1, n2
    i1 = 1
    i2 = 1
    n1 = size(a1,1)
    n2 = size(a2,1)
    do while (i1 <= n1 .and. i2 <= n2)
      if (a1(i1,1) <= a2(i2,1)) then
        a(i1+i2-1,:) = a1(i1,:)
        i1 = i1+1
      else
        a(i1+i2-1,:) = a2(i2,:)
        i2 = i2+1
       end if
    end do
    if (i1 <= n1) then
      a(i1+i2-1:n1+n2,:) = a1(i1:n1,:)
    else
      a(i1+i2-1:n1+n2,:) = a2(i2:n2,:)
    end if
    a1 = a(1:n1,:)
    a2 = a(n1+1:n1+n2,:)
  end
end program roller_coaster

Measured memory_bytes: 2552
#include<bits/stdc++.h>
using namespace std;
int main(void){
	int n,i,t,ans;
	cin>>n;
	for(i=1;i<=n;i++){
		t=i*i;
		if(t>n) break;
		else ans=t;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
long long int n,s=0,i,j,k;
cin>>n;
long long int a[n],b[n],c[n],dp[n][3];
for(i=0;i<n;i++)
{
cin>>a[i]>>b[i]>>c[i];
}
dp[0][0]=a[0];
dp[0][1]=b[0];
dp[0][2]=c[0];
for(i=1;i<n;i++)
{
dp[i][0]=max(dp[i-1][1],dp[i-1][2])+a[i];
dp[i][1]=max(dp[i-1][0],dp[i-1][2])+b[i];
dp[i][2]=max(dp[i-1][0],dp[i-1][1])+c[i];

}
cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]))<<endl;
}


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

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

int main()
{   
    int n;
    cin >> n;
    REP(r, n) {
        string x;   string y;
        cin >> x;   cin >> y;

        vector<vector<int>> L(x.size()+1, vector<int> (y.size()+1, 0));

        for (int i = 0; i < x.size(); i++) {
            for (int j = 0; j < y.size(); j++) {
                if (x[i] == y[j]) {
                    L[i+1][j+1] = L[i][j] + 1;

                }
                else {
                    L[i+1][j+1] = max(L[i][j+1], L[i+1][j]);
                }
            }
        }

        cout << L[x.size()][y.size()] << endl;
                
    }
}


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

using namespace std;
typedef long long ll;

#define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define mp make_pair
#define pb push_back
#define lp(i,s,f) for(ll i = s; i < ll(f); i++)
#define inF freopen("input.in", "r", stdin);
#define outF freopen("output.in", "w", stdout);
#define endl '\n'
#define MOD 1000000007
#define mm(arr) memset(arr, 0, sizeof(arr))
#define F first
#define S second
#define int ll

int32_t main(){
    FAST
    int a, b, n; cin >> a >> b >> n;

    int x = min(n, b - 1);
    cout << (a*x)/b;
    return 0;
}


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

ll MOD = 1000000007;

ll modPlus(ll a, ll b) {
    return (a + b) % MOD;
}

int main(void)
{
    string s;
    cin >> s;
    vector<int> sum(13, 0);
    sum[0] = 1;
    int modTable[6][10] = {0};
    for (int i = 0; i < 6; i++) {
        for (int j = 0; j < 10; j++) {
            int n = 1;
            for (int x = 0; x < i; x++) n *= 10;
            modTable[i][j] = (j*n)%13;
        }
    }

    for (size_t i = 0; i < s.length(); i++) {
        int order = s.length() - 1 - i;
        vector<int> sum2(13, 0);
        if (s[i] == '?') {
            for (int j = 0; j < 10; j++) {
                int n = modTable[order%6][j];
                for (int k = 0; k < 13; k++) {
                    sum2[(k+n)%13] = (sum[k] + sum2[(k+n)%13]) % MOD;
                }
            }
        } else {
            int n = modTable[order%6][s[i] - '0'];
            for (int k = 0; k < 13; k++) {
                sum2[(k+n)%13] = (sum[k] + sum2[(k+n)%13]) % MOD;
            }
        }
        copy(sum2.begin(), sum2.end(), sum.begin());
    }
    cout << sum[5] << endl;
    return 0;
}



Measured memory_bytes: 512
#include <stdio.h>
int main (){
	int l,r,d;
	int hb=0;
	
	scanf("%d %d %d", &l, &r, &d);
	for (int i = l ;i <= r; i++){
		if(i % d==0){
			hb++;
		}
	}
		printf("%d\n", hb);
		return 0;

}

Measured memory_bytes: 1732
N,M = map(int,input().split())
lmax,mmin = 0,1000000
for i in range(M):
    l,m = map(int,input().split())
    if lmax < l:
        lmax = l
    if mmin > m:
        mmin = m

if lmax > mmin:
    ans = 0
elif lmax == mmin:
    ans = 1
else:
    ans = mmin-lmax
    ans += 1
print(ans)


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

string S; int c = 0;

int main() {
	cin >> S;
	for (int i = 0; i < S.size(); i++) {
		if (S[i] == '+') c++; else c--;
	}
	cout << c << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
typedef pair<ll, int> pl;
const ll N = 1e6 + 100;
const ll MOD = 1e9+7;

int vis[N];
int a[N];

int main() {
    int n;
	cin>>n;
	for(int i=0;i<n;i++) {
        cin>>a[i];
	}
	sort(a, a + n);

    int ret = 0;
	for (int i=0; i<n; i++) {
        int x = a[i];
        if(vis[x])continue;
        ret ++;
        if(i + 1 < n && x == a[i+1])ret --;
        for (int j=x;j<N-50;j+=x) {
            vis[j] = 1;
        }
	}

	cout<<ret<<endl;

    return 0;
}


Measured memory_bytes: 8264
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MOD = 1000000007;
struct edge {int to,costa,costb;};

signed main() {
 int n;
 cin>>n;
 int a[n+1]={};
 for(int i=1;i<=n;i++){
     for(int j=1;j*i<=n;j++){
         a[i*j]++;
     }
 }
 int ans=0;
 for(int i=1;i<=n;i+=2)if(a[i]==8)ans++;
 cout<<ans;

return 0;
}


Measured memory_bytes: 256
#[allow(dead_code)]
fn main() {
    let n = i::u();
    let h = i::uv(n);

    let mut ans = 0;
    let mut current = vec![0; n];
    for _ in 0..100 {
        let mut c = 0;
        for i in 0..n {
            if current[i] == h[i] {
                if c == 0 {
                    continue;
                }
                c = 0;
                ans += 1;
            } else {
                c += 1;
                current[i] += 1;
            }
        }
        if c > 0 {
            ans += 1;
        }
    }
    println!("{}", ans);
}

#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::io::*;
#[allow(unused_imports)]
use std::num::*;
#[allow(unused_imports)]
use std::str::*;

#[allow(dead_code)]
mod i {
    use super::*;

    pub fn read<T: FromStr>() -> T {
        stdin()
            .bytes()
            .map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>()
            .parse::<T>()
            .ok()
            .unwrap()
    }

    pub fn str() -> String {
        read()
    }

    pub fn s() -> Vec<char> {
        str().chars().collect()
    }

    pub fn i() -> i64 {
        read()
    }

    pub fn u() -> usize {
        read()
    }

    pub fn u2() -> (usize, usize) {
        (read(), read())
    }

    pub fn u3() -> (usize, usize, usize) {
        (read(), read(), read())
    }

    pub fn f() -> f64 {
        read()
    }

    pub fn c() -> char {
        read::<String>().pop().unwrap()
    }

    pub fn iv(n: usize) -> Vec<i64> {
        (0..n).map(|_| i()).collect()
    }

    pub fn iv2(n: usize) -> Vec<(i64, i64)> {
        (0..n).map(|_| iv(2)).map(|a| (a[0], a[1])).collect()
    }

    pub fn uv(n: usize) -> Vec<usize> {
        (0..n).map(|_| u()).collect()
    }

    pub fn uv2(n: usize) -> Vec<(usize, usize)> {
        (0..n).map(|_| uv(2)).map(|a| (a[0], a[1])).collect()
    }

    pub fn uv3(n: usize) -> Vec<(usize, usize, usize)> {
        (0..n).map(|_| uv(3)).map(|a| (a[0], a[1], a[2])).collect()
    }

    pub fn fv(n: usize) -> Vec<f64> {
        (0..n).map(|_| f()).collect()
    }

    pub fn cmap(h: usize) -> Vec<Vec<char>> {
        (0..h).map(|_| s()).collect()
    }
}


Measured memory_bytes: 4352
#!/usr/bin/python3
# -*- coding: utf-8 -*-



def bin_cnt(n):
  ret = 0
  while n > 0:
    if n%2==1:
      ret += 1
    n = n//2
  return ret


N,M = map(int, input().split())
Sn = []
for i in range(M):
  ln = list(map(int, input().split()))
  s_bin = 0
  for l in ln[1:]:
    s_bin += 2**(l-1)
  Sn.append([0,s_bin])
Pn = list(map(int, input().split()))
for i in range(M):
  Sn[i][0] = Pn[i]

ans = 0
for i in range(2**N):
  chk = True
  for s in Sn:
    if s[0] != bin_cnt(i&s[1])%2:
      chk = False
  if chk:
    ans += 1
print(ans)      

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define FOREACH(x, a) for (auto&(x) : (a))
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

int main() {
  ll h, w;
  cin >> h >> w;
  vector<string> s(h);
  REP(i, h) { cin >> s[i]; }

  REP(i, h) {
    REP(j, w) {
      if (s[i][j] == '#') {
        cout << '#';
        continue;
      }
      ll cnt = 0;
      FOR(k, -1, 2) FOR(l, -1, 2) {
        ll x = i + k, y = j + l;
        if (x < 0 || x >= h || y < 0 || y >= w) {
          continue;
        }
        if (s[x][y] == '#') {
          cnt++;
        }
      }
      cout << cnt;
    }
    cout << endl;
  }
}

Measured memory_bytes: 256
def gcd(a,b):
    while b!=0:
        a,b=b,a%b
    return a

def lcm(a,b):
    return a*b//gcd(a,b)

a,b,c,d = map(int,input().split())

def count(x):
    return x - x//c - x//d + x//lcm(c,d)

print(count(b) - count(a-1))


Measured memory_bytes: 2940
//==========================Head files==========================
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<queue>
#include<cmath>
#include<set>
#include<iostream>
#include<map>
#define LL long long
#define db double
#define mp make_pair
#define pr pair<int, int>
#define fir first
#define sec second
#define pb push_back
#define ms(i, j) memset(i, j, sizeof i)
using namespace std;
//==========================Templates==========================
inline int read() {
    int x = 0, f = 1; char c = getchar();
    while(c < '0' || c > '9'){if (c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9'){x = x * 10 + c - '0'; c = getchar();}
    return x * f;
}
inline LL readl() {
    LL x = 0, f = 1; char c = getchar();
    while(c < '0' || c > '9'){if (c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9'){x = x * 10 + c - '0'; c = getchar();}
    return x * f;
}
int power(int a, int b) {
	int ans = 1;
	while (b) {
		if(b & 1) ans = ans * a;
		b >>= 1; a = a * a;
	}
	return ans;
}
int power_mod(int a, int b, int mod) {
	a %= mod;
	int ans = 1;
	while (b) {
		if(b & 1) ans = (ans * a) % mod;
		b >>= 1, a = (a * a) % mod;
	}
	return ans;
}
LL powerl(LL a, LL b) {
	LL ans = 1ll;
	while (b) {
		if(b & 1ll) ans = ans * a;
		b >>= 1ll;a = a * a;
	}
	return ans;
}
LL power_modl(LL a, LL b, LL mod) {
	a %= mod;
	LL ans = 1ll;
	while (b) {
		if(b & 1ll) ans = (ans * a) % mod;
		b >>= 1ll, a = (a * a) % mod;
	}
	return ans;
}
LL gcdl(LL a, LL b) {return b == 0 ? a : gcdl(b, a % b);}
LL abssl(LL a) {return a > 0 ? a : -a;}
int gcd(int a, int b) {return b == 0 ? a : gcd(b, a % b);}
int abss(int a) {return a > 0 ? a : -a;}
//==========================Main body==========================
#define LD "%I64d"
#define D "%d"
#define pt printf
#define sn scanf
#define pty printf("YES\n")
#define ptn printf("NO\n")
//==========================Code here==========================
int main() {
	LL A, B;
	cin >> A >> B;
	cout << max(max(A + B, A - B), A * B);
	return 0;
}

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


int main()
{
    int m;
    cin >> m;
    ll sum = 0, n = 0;
    rep(i,m)
    {
        ll c, d;
        cin >> d >> c;
        n += c;
        sum += c * d;
    }
    cout << n - 1 + ((sum - 1) / 9) << endl;
    
    return 0;
}

Measured memory_bytes: 3556
#include <iostream>
#include <string>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <utility>
#include <functional>
#include <deque>
#include <cctype>
#include <stack>
#include <bitset>

using ll = long long;
typedef unsigned long long ull;
typedef std::pair<ll, ll>P;

ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}

const ll Z = 1000000007;
const ll INF = 1 << 30;
const ll INF2 = 9000000000000000000LL;
bool fl = true;
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
std::string abc = "abcdefghijklmnopqrstuvwxyz";
struct edge { ll to, cost; };
double pai = 3.141592653589793;
std::vector<P>v[100010];

int main() {
	ll n, a[300010], ans = -INF2;
	std::cin >> n;
	for (int i = 0;i < 3 * n;i++) {
		std::cin >> a[i];
	}
	std::priority_queue<ll>p,q;
	ll front[100010] = { 0 }, back[100010] = {0};
	for (int i = 0;i < n;i++) {
		p.push(-a[i]);
		front[0] += a[i];
	}
	front[1] = front[0];
	int j = 1;
	for (int k = n;k <= 2 * n-1;k++) {
		p.push(-a[k]);
		front[j] += a[k];
		front[j] += p.top();
		p.pop();
		front[j + 1] = front[j];
		j++;
	}
	for (int i = 3*n-1;i >= 2*n;i--) {
		q.push(a[i]);
		back[n] += a[i];
	}
	back[n - 1] = back[n];
	j = n - 1;
	for (int k = 2 * n-1;k >= n;k--) {
		q.push(a[k]);
		back[j] += a[k];
		back[j] -= q.top();
		q.pop();
		back[j - 1] = back[j];
		j--;
	}
	for (int i = 0;i <= n;i++) {
		ans = std::max(ans, front[i] - back[i]);
	}
	std::cout << ans << std::endl;
	
}

Measured memory_bytes: 8820
a,b,c,d,e,f,g = gets.split.map(&:to_i)
o = ((a%2==1)?1:0) + ((d%2==1)?1:0) + ((e%2==1)?1:0)
sol = a + b + d + e
sol -= 1 if o == 1
if o == 2 then
    sol -= 1
    sol -= 1 if [a,d,e].min == 0
end
puts sol

Measured memory_bytes: 1788
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>

using namespace std;

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = n;i >= m;i--)
#define REPO(i, n) for(int i = 1;i <= n;i++)
#define ll long long
#define INF 1999999999
#define MINF -1999999999
#define ALL(n) n.begin(),n.end()

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	cout << min(a + b, min(a + c, b + c)) << endl;
}

Measured memory_bytes: 256
#include <cstdio>

int n,m,q;
char map[2222][2222];
int count[2222][2222],count1[2222][2222],count2[2222][2222];

inline void build(int (*w)[2222])
{
    int i,j;
    for(i = 1;i <= n;++i)
        for(j = 1;j <= m;++j)
            w[i][j] = w[i][j] + w[i][j - 1] + w[i - 1][j] - w[i - 1][j - 1];
}

inline int query(int (*w)[2222],int x1,int y1,int x2,int y2)
{
    if(x2 >= x1 && y2 >= y1)
        return w[x2][y2] - w[x2][y1 - 1] - w[x1 - 1][y2] + w[x1 - 1][y1 - 1];
    return 0;
}

int main(void)
{
    int x1,y1,x2,y2;
    int i,j;

    //freopen("x.in","r",stdin);

    scanf("%d %d %d",&n,&m,&q);
    for(i = 1;i <= n;++i)
        scanf("%s",map[i] + 1);

    for(i = 1;i <= n;++i)
        for(j = 1;j <= m;++j)
            count[i][j] = map[i][j] == '1',count1[i][j] = i > 1 && map[i][j] == '1' && map[i - 1][j] == '1',count2[i][j] = j > 1 && map[i][j] == '1' && map[i][j - 1] == '1';
    build(count),build(count1),build(count2);

    while(q--)
    {
        scanf("%d %d %d %d",&x1,&y1,&x2,&y2);
        printf("%d\n",query(count,x1,y1,x2,y2) - query(count1,x1 + 1,y1,x2,y2) - query(count2,x1,y1 + 1,x2,y2));
    }

    return 0;
}

Measured memory_bytes: 63872
#include<iostream>
using namespace std;
int main()
{
	char a[4];
	for (int i = 0; i < 4; i++)
	{
		cin >> a[i];
	}
	if ((a[0] == a[1] && a[2] == a[3] && a[0] != a[2]) || (a[0] == a[2] && a[1] == a[3] && a[0] != a[1]) || (a[0] == a[3] && a[1] == a[2] && a[0] != a[1])) { cout << "Yes" << '\n'; }
	else cout << "No" << '\n';
}

Measured memory_bytes: 256
#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;
  cout << n * (n - 1) / 2 + m * (m - 1) / 2 << endl;
}


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

using namespace std;

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

const long long int MOD=1000000007;



int main(){
	
	while(cin>>N>>M,N){
		vector<int>v(M);
		for(auto &i:v)cin>>i;
		vector<int>w(N+1);
		for(int i=1;i<=N;i++)cin>>w[i];
		vector<vector<int>>dp(N+1,vector<int>(256,MOD));
		dp[0][128]=0;
		for(int i=0;i<N;i++){
			for(int j=0;j<256;j++){
				for(auto k:v){
					int nx=max(0,min(255,j+k));
					dp[i+1][nx]=min(dp[i+1][nx],dp[i][j]+abs(nx-w[i+1])*abs(nx-w[i+1]));
				}
			}
		}
		cout<<*min_element(dp.back().begin(),dp.back().end())<<endl;
	}
	return 0;
}


Measured memory_bytes: 23744
#include<stdio.h>
int main()
 {
    int N,i,sum=0;
    scanf("%d",&N);
    if(N>=1&&N<=100)
    {
    
    	for(i=1;i<=N;i++)
    	{
    		sum=sum+i;
    	}
    	   printf("%d\n",sum);
    }
      return 0;

}

Measured memory_bytes: 128
// RAM RAM

#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define ppb pop_back
#define vi vector<int>
#define mp make_pair
#define arrayin(a,n) for(int i=0;i<n;i++){cin>>a[i];}
#define N 55

using namespace std;


int32_t main()
{
	ios_base::sync_with_stdio(false);cin.tie(0);


    char o;
    int a,b;
    cin>>a>>o>>b;
    if(o=='+'){
    	cout<<a+b<<endl;
    }else{
    	cout<<a-b<<endl;
    }
	return 0;
}

Measured memory_bytes: 256
import numpy as np

N = int(raw_input())
A = [0] * N
for idx in xrange(N):
  A[idx] = int(raw_input())
A = np.array(zip(A,range(N)))
B = np.array(sorted(A, key=lambda x:x[0]))
C = np.array([x[1] for x in B])
D = np.array(range(N))
C = C % 2
D = D % 2
E = np.abs(C - D)

print sum(E)/2

Measured memory_bytes: 46268
#define _CRT_SECURE_NO_WARNINGS
#include"bits/stdc++.h"
#ifdef _DEBUG
#define DBG(n) n
#else
#define DBG(n)
#endif
#define INF          1e9
#define INFLL        1e18
#define EPS          1e-9
#define MOD          1000000007
#define REP(i,n)     for(ll i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)    for(ll i=1,i##_len=(n);i<=i##_len;++i)
#define REPR(i,n)    for(ll i=(n)-1;i>=0;--i)
#define REPR1(i,n)   for(ll i=(n);i>0;--i)
#define REPC(i,obj)  for(auto i:obj)
#define ALL(obj)     (obj).begin(),(obj).end()
#define SETP(n)      cout<<fixed<<setprecision(n)
#define VV(T,h,w)    move(vector<vector<T>>(h,move(vector<T>(w))))
#define VVI(T,h,w,i) move(vector<vector<T>>(h,move(vector<T>(w,i))))
using namespace std;
using ll = long long;
template<typename T = ll>inline T in() { T ret; cin >> ret; return ret; }

int main()
{
	ll n = in();
	ll sq = (ll)(floor(sqrt(n)));
	cout << sq * sq << endl;
}

Measured memory_bytes: 256
/*
 *
 * Author: r3gz3n
 * 
 * 3b 13 12 9 56 4e
 * 6 56 a a 5f f
 * 6 56 47 18 56 d
 * 13 46 14 1f 13 27
 * 52 52 a 5a 47 1
 * 1d 13 b 1b 49 17
 *
 */


#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;


#define rep(i, a, b, k) for(__typeof(a) i = a;i < b;i += k)


#define endl '\n'


class Solution {
public:
    void solve(std::istream& in, std::ostream& out) {
		int n, m, l, r, ansl = 0, ansr = 1e5;
        in >> n >> m;
        rep(i, 0, m, 1) {
            in >> l >> r;
            ansl = max(l, ansl);
            ansr = min(r, ansr);
        }
        if (ansr < ansl) out << 0 << endl;
        else out << ansr - ansl + 1 << endl;
    }
};

void solve(std::istream& in, std::ostream& out)
{
    out << std::setprecision(12);
    Solution solution;
    solution.solve(in, out);
}


#include <fstream>
#include <iostream>


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


    istream& in = cin;


    ostream& out = cout;

    solve(in, out);
    return 0;
}




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

double a, b, x;
double res;

double func1(double a, double b, double S){ //true
  //cout << "func1" << endl;
  S = a * b - S;
  double c = S * 2 / a;
  //cout << setprecision(10) << c / a<<endl;
  return atan(c / a) * 180 / M_PI;
}

double func2(double a, double b, double S){ //false
  //cout << "func2" << endl;
  double c = S * 2 / b;
  return atan(b / c) * 180 / M_PI;
}

int main(){
  cin >> a >> b >> x;
  double S = x / a;
  //cout << S << endl;
  if(S > (a * b) / 2){
    res = func1(a, b, S);
  }else{
    res = func2(a, b, S);
  }
  cout << setprecision(10) << res << endl;
  
  return 0;
}


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

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}

int main() {
	int n = ri();
	int64_t k;
	std::cin >> k;
	int a[n];
	for (int i = 0; i < n; i++) a[i] = ri();
	int b[n];
	for (int i = 0; i < n; i++) b[i] = ri();
	std::sort(a, a + n, std::greater<>());
	std::sort(b, b + n);
	int64_t l = -1;
	int64_t r = 1000000000001;
	while (r - l > 1) {
		int64_t m = l + (r - l) / 2;
		int64_t cost = 0;
		for (int i = 0; i < n; i++) {
			int64_t max = m / b[i];
			if (max < a[i]) cost += a[i] - max;
		}
		if (cost > k) l = m;
		else r = m;
	}
	std::cout << r << std::endl;
	
	return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int n,k,r,s,p; cin>>n>>k>>r>>s>>p;
	string t; cin>>t;
	string used(k,'@');
	int ret=0;
	int sz=t.size();
	for (int i=0; i<sz; i++) {
		if(t[i]=='r') {
			if(used[i%k]=='p') used[i%k]='@';
			else used[i%k]='p', ret+=p;
		}
		else if(t[i]=='s') {
			if(used[i%k]=='r') used[i%k]='@';
			else used[i%k]='r', ret+=r;
		}
		else if(t[i]=='p') {
			if(used[i%k]=='s') used[i%k]='@';
			else used[i%k]='s', ret+=s;
		}
	}
	cout<<ret<<"\n";
	return 0;
}

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

const int MAX_N = 1 << 18;
int n, dat[2*MAX_N - 1];

void init(int _n) {
  n = 1;
  while (n < _n) n *= 2;
  for (int i=0; i<2*n-1; i++) {
    dat[i] = INT_MAX;
  }
}

void update(int k, int a) {
  k += n - 1;
  dat[k] = a;
  while (k > 0) {
    k = (k - 1) / 2;
    dat[k] = min(dat[k*2 + 1], dat[k * 2 + 2]);
  }
}

int query(int a, int b, int k, int l, int r) {
  if (r <= a || b <= l) return INT_MAX;

  if (a <= l && r <= b) return dat[k];
  else {
    int vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
    int vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
    return min(vl, vr);
  }
}
int main() {

  int N;
  cin>>N;
  int a[N];
  for (int i=0; i<N; i++) cin>>a[i];
  init(N);
  for (int i=0; i<N; i++) {
    update(i, a[i]);
  }
  long long ans = 0;

  for (int i=0; i<N; i++) {
    int l_l = 0, r_l = i;
    while (r_l - l_l > 1) {
      int mid = (l_l + r_l) / 2;
      int v = query(mid, i+1, 0, 0, n);
      if (v < a[i]) {
        l_l = mid;
      } else {
        r_l = mid;
      }
    }
    int l;
    if (a[i] == query(l_l, i+1, 0, 0, n)) {
      l = l_l;
    } else {
      l = r_l;
    }
    int l_r = i, r_r = N-1;
    while (r_r - l_r > 1) {
      int mid = (l_r + r_r) / 2;
      int v = query(i, mid+1, 0, 0, n);
      if (v < a[i]) {
        r_r = mid;
      } else {
        l_r = mid;
      }
    }
    int r;
    if (a[i] == query(i, r_r+1, 0, 0, n)) {
      r = r_r;
    } else {
      r = l_r;
    }
    if (r == N) {
      --r;
    }
    ans += (long long)a[i] * (i - l + 1) * (r - i + 1);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3072
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rloop(i, n, a) for(int i = (n); i >= (a); i--)
#define loop(i, a, n) for(int i = (a); i < (n); i++)
using namespace std;
using ll = int64_t;

ll mod_pow(ll x, ll n, const ll mod){
    ll ans = 1;
    while(n){
        if(n & 1) ans = ans*x%mod;
        x = x*x%mod;
        n >>= 1;
    }
    return ans;
}

int main(){
    const ll mod = 1e9+7;
    ll n; int a, b; cin >> n >> a >> b;

    ll ans = mod_pow(2, n, mod) - 1;

    ll bunbo = 1, bunsi = 1;
    loop(i, 1, b+1){
        bunsi = (bunsi%mod) * ((n - i + 1)%mod) % mod;
        bunbo = (bunbo%mod) * (i%mod) % mod;
        if(i == a || i == b){
            ll tmp = mod_pow(bunbo, mod-2, mod);
            ans = (ans - (bunsi*tmp)%mod + mod )%mod;
        }
    }

    cout << ans%mod << endl;

    return 0;
}

Measured memory_bytes: 256
import heapq
import sys
input = sys.stdin.readline

N, M, S, T = map(int, input().split())


class Dijkstra():
    class Edge():

        def __init__(self, _to, _cost):
            self.to = _to
            self.cost = _cost

    def __init__(self, V):

        self.G = [[] for i in range(V+1)]
        self._E = 0
        self._V = V

    def add(self, _from, _to, _cost):
        """ 2頂点と、辺のコストを追加"""
        self.G[_from].append(self.Edge(_to, _cost))
        self._E += 1

    def s_path(self, s):
        """ 始点sから頂点iまでの最短路リスト 
        """
        que = []
        heapq.heapify(que)
        d = [10**15] * (self._V+1)
        d[s] = 0
        heapq.heappush(que, (0, s))
        while que:
            cost, v = heapq.heappop(que)
            if d[v] < cost:
                continue

            for e in self.G[v]:
                if d[e.to] > d[v] + e.cost:
                    d[e.to] = d[v] + e.cost
                    heapq.heappush(que, (d[e.to], e.to))
        return d
      
      
graph_snuke = Dijkstra(N)
graph_yen = Dijkstra(N)
for _ in range(M):
    u, v, a, b = map(int, input().split())
    graph_yen.add(u, v, a)
    graph_yen.add(v, u, a)
    graph_snuke.add(u, v, b)
    graph_snuke.add(v, u, b)

yen = graph_yen.s_path(S)
snuke = graph_snuke.s_path(T)
minimum_case = [10**15 for i in range(N+1)]
for i in range(N):
    minimum_case[1+i] -= (yen[i+1]+snuke[i+1])
for i in range(N-1, -1, -1):
    minimum_case[i] = max(minimum_case[i], minimum_case[i+1])
for i in range(1, N+1):
    print(minimum_case[i])

Measured memory_bytes: 144272
from collections import deque
b = deque(list())
n = int(input())
alist = list(map(int,input().split()))
num = len(alist)

if num % 2 == 0:
    for i in range(num):
        if i % 2 == 0:
            b.append(alist[i])
        elif i % 2 == 1:
            b.appendleft(alist[i])

elif num % 2 == 1:
    for i in range(num):
        if i % 2 == 1:
            b.append(alist[i])
        elif i % 2 == 0:
            b.appendleft(alist[i])

for i in b:
    print(i, end=' ')

Measured memory_bytes: 25412
<?php
/**
 * Created by PhpStorm.
 * User: ramia
 * Date: 2016/08/31
 * Time: 10:28
 */

/*
 * http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0201
 */


class Item{
	public $name;
	public $price;
	public $minimumPrice;

	public $material_items = [];

	public function __construct( $name , $price ){
		$this->name  = $name;
		$this->price = intval($price);
		$this->minimumPrice = intval($price);
	}

	public function materialItems($material_items){
		$this->material_items = $material_items;
	}

	public function getMaterials(){
		return $this->material_items;
	}

	public function setMinimumPrice( $minimumPrice ){
		$this->minimumPrice = intval($minimumPrice);
	}

	public function getMinimumPrice(){
		return $this->minimumPrice;
	}
}

while(true){
	$items = [];

	$n = fgets(STDIN);
	if( $n == 0 ){
		exit;
	}
	for( $i=0;$i<$n;$i++ ){
		$line = trim(fgets(STDIN));
		list( $name , $price ) = explode(' ',$line);
		$items[$name] = new Item( $name, $price );
	}

	$n = fgets(STDIN);
	for( $i=0;$i<$n;$i++ ){
		$line = trim(fgets(STDIN));
		$recipe_arr = explode(' ',$line);
		$generate_item = '';
		$material_items = [];
		for ( $j=0;$j<count($recipe_arr);$j++ ){
			if( $j == 0 ){
				$generate_item = $recipe_arr[$j];
			}
			if( $j >= 2 ){
				$material_items[] = $recipe_arr[$j];//$items[$recipe_arr[$j]];
			}
		}
		$items[$generate_item]->materialItems($material_items);
	}
	$emulateItem = trim(fgets(STDIN));

	$loop = true;
	while( $loop ){
		$loop = false;
		foreach ( $items as $item_key => $item_value ){
			$materials = $item_value->getMaterials();
			if( count($item_value->getMaterials()) > 0 ){
				$create_value = 0;
				foreach ( $materials as $material_value ){
					$create_value += $items[$material_value]->getMinimumPrice();
				}
				if( $item_value->getMinimumPrice() > $create_value ){
					$item_value->setMinimumPrice($create_value);
					$loop = true;
				}
			}
		}
	}
	echo $items[$emulateItem]->getMinimumPrice()."\n";
}

?>

Measured memory_bytes: 15316
#include<bits/stdc++.h>
// debug
#define d(x) cerr << #x ":" << x << endl;
#define dd(x, y) cerr << "(" #x "," #y "):(" << x << "," << y << ")" << endl;
#define ddd(x, y, z) cerr << "(" #x "," #y "," #z "):(" << x << "," << y << "," << z << ")" << endl;
#define dump(v) cerr<<#v":[ ";for (auto macro_vi:v){cerr<<macro_vi<< " ";}cerr<<"]"<<endl;
#define ddump(v) cerr<<#v":"<<endl;for(auto macro_row:v) {cerr<<"["; for (auto macro__vi:macro_row){cerr<<macro__vi<< " ";}cerr<<"]"<<endl;}
#define damp(m) for(auto macro_pair:m){cerr<< macro_pair.first<<":"<<macro_pair.second<<endl;}
#define dpair(p) cerr << #p":"<<"(" << p.first << "," << p.second << ")" << endl;
// iterate
#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define reprrev(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)
#define reprev(i, n) reprrev(i, 0, n)
#define repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++)
#define all(v) v.begin(), v.end()
// etc
#define chmin(mi, val) mi = min(mi, val);
#define chmax(ma, val) ma = max(ma, val);
using ll = long long;

using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    map<int, vector<int>> mp;
    rep(i,n){
        int ai, bi;
        cin >> ai >> bi;
        mp[ai].push_back(bi);
    }
    
    ll sum=0;
    priority_queue<int> pq;
    for(int i=m-1; 0<=i; i--){
        d(i)
        int limit = m-i;
        // cout << mp[limit].size() << endl;
        for(auto x : mp[limit]){
            pq.push(x);
        }
        d(pq.size()) 
        if (pq.size() != 0)
        {
            sum += pq.top();
            pq.pop();
        }
    }
    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 10880
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>
#include <iomanip>

using namespace std;

#define FOR(i, a, b) for(int (i)=(a);(i)<(b);(i)++)
#define IFOR(i, a, b) for(int (i)=(a);(i)<=(b);(i)++)
#define RFOR(i, a, b) for(int (i)=(a);(i)>=(b);(i)--)
#define REP(i, n) FOR((i), 0, (n))

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

int main() {
    int n;
    cin >> n;
    int ans = 0;
    REP(i, n){
        int a;
        cin >> a;
        if(i%2==0 && a%2==1) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3164