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

int main(){
  int N;
  cin >> N;
  bool n =false;
  for(int i=0;i<10;i++){
    for(int j=0;j<10;j++){
      if(i*j==N){
        cout << "Yes" << endl;
        n=true;
      }
    }
    if(n){
      break; 
    }
    if(i==9){
      cout << "No" << endl;
    }
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll countDivisibles(ll A, ll B, ll M)
{
    if (A % M == 0)
        return (B / M) - (A / M) + 1;
    return (B / M) - (A / M);
}
int main()
{
    ll A , B , M ; cin>>A>>B>>M;
    cout << countDivisibles(A, B, M) << endl;

    return 0;
}


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

int main() {
  int H, W;
  
  cin >> H >> W;
  vector <string> vec(W);
  
  for (int i = 0; i < W+2; i++){
  	cout << "#";
  }
  cout << endl;
  
  for (int i = 0; i < H; i++){
    cout << "#";
    string S;
    cin >> S;
    
    cout << S << "#" << endl;
  }
  
    for (int i = 0; i < W+2; i++){
  	cout << "#";
  }
  cout << endl;
}


Measured memory_bytes: 256
N,M = map(int,input().split())
years = []
for i in range(1,M+1):
    p,y = map(int,input().split())
    years.append((p,y,i))

prefectureOrdering = [1] * (10 ** 5 + 1)
inputOrdering = [False] * (10 ** 5 + 1)

years.sort()

for i in years:
    s = ""
    s += "0" * (6 - len(str(i[0]))) + str(i[0]) + "0" * (6 - len(str(prefectureOrdering[i[0]]))) + str(prefectureOrdering[i[0]])
    prefectureOrdering[i[0]] += 1
    inputOrdering[i[2]] = s

for i in range(1,M+1):
    print(inputOrdering[i])

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

int main(){
  int n;
  cin >> n;
  cin.ignore();

  string rule[10] = {"", ".,!? ", "abc", "def", "ghi",
                     "jkl","mno", "pqrs", "tuv", "wxyz"};
  
  for(int i=0; i<n; i++){
    string s;
    getline(cin, s);

    string ans = "", temp = "";
    int before = 0, index = 0;
    for(int j=0; j<s.size(); j++){
      if(s[j] - '0' == 0){
        ans += temp;
        temp = "";
        index = 0;
      }else if(before == s[j] - '0'){
        temp = rule[before][index];
        index = (index+1)%rule[before].size();
      }else{
        temp = rule[s[j] - '0'][0];
        index = 1;
      }
      before = s[j] - '0';
    }

    cout << ans << endl;
  }
  
  return 0;
}

Measured memory_bytes: 3032
#pragma GCC optimze("Ofast")
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define mod 1000000007
#define md 998244353
#define trace(...)
#define ll long long int
#define ld long double
#define fi first
#define se second
#define fr(i,a,b) for(ll i=a;i<=b;i++)
#define frr(i,b,a) for(ll i=b;i>=a;i--)
#define mem(a) memset(a, 0, sizeof(a))
#define vpi std::vector<pair<int,int>>
#define pii pair<int,int>
#define pb push_back
#define sall(v) sort(v.begin(),v.end())
#define all(v) (v.begin(),v.end())
#define minf -10000000
const ll infl=0x3f3f3f3f3f3f3f3fLL;
const int infi=0x3f3f3f3f;
typedef tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update> oset;
auto clk=clock();
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
int rng(int lim) {
    uniform_int_distribution<int> uid(0,lim-1);
    return uid(rang);
}
ll power(ll x, ll y,ll p) { 
    ll res = 1;      // Initialize result 
    x = x % p;  // Update x if it is more than or equal to p 
    while (y > 0) {  
        if (y & 1) // If y is odd, multiply x with result
            res = (res*x) % p;  
        y = y>>1; // y = y/2 // y must be even now
        x = (x*x) % p;   
    } 
    return res; 
}
ll power(ll x, ll y) { 
    ll res = 1;      // Initialize result 
    while (y > 0) {    
        if (y & 1)// If y is odd, multiply x with result 
            res = (res*x) ;  
        y = y>>1; // y = y/2 // y must be even now 
        x = (x*x);   
    } 
    return res; 
}
 
ll max3(ll a,ll b,ll c){
    return max(a,max(b,c));
}
ll min3(ll a,ll b,ll c){
    return min(a,min(b,c));
}
bool isPrime(ll n) { // Corner cases 
    if (n <= 1) 
        return false; 
    if (n <= 3) 
        return true; 
    if (n % 2 == 0 || n % 3 == 0) 
        return false; 
    for (ll i = 5; i * i <= n; i = i + 6) 
        if (n % i == 0 || n % (i + 2) == 0) 
            return false; 
    return true; 
}

void solve() {
    int n,cnt=0;cin>>n;
    string chk="ABC",temp,s;cin>>s;
    fr(i,0,n-3){
        temp=s.substr(i,3);
        if(temp==chk)cnt++;
    }
    cout<<cnt<<endl;
    return ;
}

int main(){
    ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    srand(chrono::high_resolution_clock::now().time_since_epoch().count());
    cout<<fixed<<setprecision(8);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    #endif
    int t;
    // cin>>t;
    t=1;
    while(t--){
        solve();
    }
    #ifndef ONLINE_JUDGE
    cout<<endl<<endl<<endl<<endl<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl;
    #endif
    return 0;
}


Measured memory_bytes: 3648
// eddy1021
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef double D;
typedef long double LD;
typedef long long LL;
typedef pair<int,int> PII;
typedef pair<LL,LL> PLL;
#define mod9 1000000009LL
#define mod7 1000000007LL
#define INF  1023456789LL
#define INF16 10000000000000000LL
#define eps 1e-9
#define SZ(x) (int)(x).size()
#define ALL(x) (x).begin(), (x).end()
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#ifndef ONLINE_JUDGE
#define debug(...) printf(__VA_ARGS__)
#else 
#define debug(...)
#endif
inline LL getint(){
  LL _x=0,_tmp=1; char _tc=getchar();    
  while( (_tc<'0'||_tc>'9')&&_tc!='-' ) _tc=getchar();
  if( _tc == '-' ) _tc=getchar() , _tmp = -1;
  while(_tc>='0'&&_tc<='9') _x*=10,_x+=(_tc-'0'),_tc=getchar();
  return _x*_tmp;
}
inline LL add( LL _x , LL _y , LL _mod = mod7 ){
  _x += _y;
  return _x >= _mod ? _x - _mod : _x;
}
inline LL sub( LL _x , LL _y , LL _mod = mod7 ){
  _x -= _y;
  return _x < 0 ? _x + _mod : _x;
}
inline LL mul( LL _x , LL _y , LL _mod = mod7 ){
  _x *= _y;
  return _x >= _mod ? _x % _mod : _x;
}
LL mypow( LL _a , LL _x , LL _mod ){
  if( _x == 0 ) return 1LL;
  LL _ret = mypow( mul( _a , _a , _mod ) , _x >> 1 , _mod );
  if( _x & 1 ) _ret = mul( _ret , _a , _mod );
  return _ret;
}
LL mymul( LL _a , LL _x , LL _mod ){
  if( _x == 0 ) return 0LL;
  LL _ret = mymul( add( _a , _a , _mod ) , _x >> 1 , _mod );
  if( _x & 1 ) _ret = add( _ret , _a , _mod );
  return _ret;
}
inline bool equal( D _x ,  D _y ){
  return _x > _y - eps && _x < _y + eps;
}
void sleep( double sec = 1021 ){
  clock_t s = clock();
  while( clock() - s < CLOCKS_PER_SEC * sec );
}
#define Bye exit(0)
int __ = 1 , _cs;
/*********default*********/
#define N 10101
void build(){

}
LL n , a[ N ] , b[ N ];
void init(){
  n = getint();
  for( int i = 0 ; i < n ; i ++ )
    a[ i ] = getint();
  for( int i = 0 ; i < n ; i ++ )
    b[ i ] = getint();
}
void no(){
  puts( "No" );
  Bye;
}
void solve(){
  LL suma = accumulate( a , a + n , 0LL );
  LL sumb = accumulate( b , b + n , 0LL );
  LL tms = sumb - suma;
  if( tms < 0 ) no();
  LL atleasta = 0 , atleastb = 0;
  for( int i = 0 ; i < n ; i ++ )
    if( a[ i ] > b[ i ] ){
      atleastb += a[ i ] - b[ i ];
    }else if( a[ i ] < b[ i ] ){
      LL nd = (b[ i ] - a[ i ] + 1) / 2;
      atleasta += nd;
      a[ i ] += 2 * nd;
      if( a[ i ] != b[ i ] )
        atleastb ++;
    }
  if( atleasta > tms ) no();
  if( atleastb > tms ) no();
  puts( "Yes" );
}
int main(){
  build();
  //__ = getint();
  while( __ -- ){
    init();
    solve();
  }
}


Measured memory_bytes: 384
#include <cstring>
#include <iostream>
using namespace std;
int main() {
    string s; cin >> s;
    int dp[2][s.size()];
    memset(dp, 0, sizeof dp);
    for (int i = 0; i < s.size(); i++) {
        int d = s[i] - '0';
        if (i == 0) {
            dp[0][0] = min(d, 11-d);
            dp[1][0] = d == 9 ? 1 : min(d+1, 10-d);
        } else {
            dp[0][i] = min(d+dp[0][i-1], 10-d+dp[1][i-1]);
            dp[1][i] = (d == 9 ? dp[1][i-1] :
                        min(1+d+dp[0][i-1], 9-d+dp[1][i-1]));
        }
    }
    cout << dp[0][s.size()-1] << endl;
}


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

int main(){
  int k,t;
  cin >> k >> t;
  vector<int> a(t);
  int max = -1;
  for(int i = 0; i < t; i++){
    cin >> a[i];
    if(max < a[i])
      max = a[i];
  }
  int ans;
  ans = k - ((k - max) * 2 + 1);
  if(ans < 0)
    ans = 0;
  cout << ans << endl;
}


Measured memory_bytes: 256
n = int(input())
s = list(input() for _ in range(n))

cnt = [0] * 5

for x in s:
    if x[0] == 'M':
        cnt[0] += 1
    if x[0] == 'A':
        cnt[1] += 1
    if x[0] == 'R':
        cnt[2] += 1
    if x[0] == 'C':
        cnt[3] += 1
    if x[0] == 'H':
        cnt[4] += 1

if cnt.count(0) > 2:
    print(0)
    exit()

ans = 0 
for i in range(len(cnt)-2):
    for j in range(i+1, len(cnt)-1):
        for k in range(j+1, len(cnt)):
            ans += cnt[i] * cnt[j] * cnt[k]

print(ans)


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

using namespace std;

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

int main() {
	int N, K;
	cin >> N >> K;

	vector<int> H(N);
	rep(i, N) {
		cin >> H[i];
	}
	sort(H.begin(), H.end());

	long sum = 0;
	repp(i, 0, N - K) {
		sum += H[i];
	}

	cout << sum << endl;
}

Measured memory_bytes: 1024
package main

import "fmt"

func main() {
	var (
		X, cnt int
	)
	fmt.Scan(&X)
	yokin := 100
	for {
		cnt++
		yokin = int(float64(yokin) * 1.01)
		if yokin >= X {
			break
		}
	}

	fmt.Println(cnt)
}

Measured memory_bytes: 1756
#pragma GCC optimize("Ofast")
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define rep2(i,n) for(int i=0;i<=n;i++)
#define repr(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define P pair<long long,long long>
#define uni(e) e.erase(unique(e.begin(),e.end()),e.end())
#define double long double
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int INF=1e10;
int MOD=1e9+7;
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void yesno(T b){if(b)out("yes");else out("no");}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
template<class T> void YESNO(T b){if(b)out("YES");else out("NO");}
template<class T> void noyes(T b){if(b)out("no");else out("yes");}
template<class T> void NoYes(T b){if(b)out("No");else out("Yes");}
template<class T> void NOYES(T b){if(b)out("NO");else out("YES");}
int keta(int a){
  double b=a;
  b=log10(b);
  int c=b;
  return c+1;
}
int kurai(int a,int b){
  int m=pow(10,b),n=pow(10,b-1);
  return (a%m)/n;
}
int ketawa(int a){
  int k=0;
  rep(i,keta(a)){
  k+=kurai(a,i+1);
  }
  return k;
}
int gcd(int a,int b){
  if(a%b==0)
    return b;
  return gcd(b,a%b);
}
int lcm(int a,int b){
    return a/gcd(a,b)*b;
}
int mid(int a,int b,int c){
  vector<int> k(3);
  k[0]=a;k[1]=b;k[2]=c;
  sort(all(k));
  return k[1];
}
bool sosuu(int a){
  bool b=1;
  if(a<=1)
    return 0;
  else{
  rep1(i,sqrt(a)-1){
  if(a%(i+1)==0)
  b=0;
  }
  return b;
  }
}
int modpow(int a,int b,int m=MOD){
 if(!b)return 1; if(b&1)return modpow(a,b-1,m)*a%m;
 int memo = modpow(a,b>>1,m);
 return memo*memo%m;
}
int fact_mod(int n) {
    int f=1; 
for(int i=2;i<n+1;i++) f=f*(i%MOD)% MOD;
    return f;
}
int mod_pow(int x,int n) {
    int res=1;
    while(n>0){
        if(n&1) res=(res*x)%MOD; 
        x=(x*x)%MOD;        
n>>=1; 
    }
    return res;
}
int c_mod(int n, int r) {
    if(r>n-r) r=n-r;
    if(r==0) return 1;
    int a=1;
    rep(i,r) 
a=a*((n-i)%MOD)%MOD;
    int b=mod_pow(fact_mod(r), MOD-2);
    return (a%MOD)*(b%MOD)%MOD;
}
signed main(){
  string a,b;
  cin>>a>>b;
  int c=0;
  rep(i,a.size()){
  if(a[i]!=b[i])
    c++;
  }
  out(c);
}

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

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

#define pow CHANGETHENAMESTUPID

using namespace std;

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

struct point {
	ldouble x; 
	ldouble y;
	point (ldouble x, ldouble y) : x (x), y (y) {}
	point () : x (0), y (0) {}
};

typedef pair<point,ldouble> circle;

ldouble distq(point p) {
	return p.x*p.x + p.y*p.y;
}

point center_from(ldouble bx, ldouble by, ldouble cx, ldouble cy) {
	ldouble B=bx*bx+by*by, C=cx*cx+cy*cy, D=bx*cy-by*cx;
	return point((cy*B-by*C)/(2*D), (bx*C-cx*B)/(2*D));
}

circle circle_from(point A, point B, point C) {
	point I = center_from(B.x-A.x, B.y-A.y, C.x-A.x, C.y-A.y);
	return {point(I.x + A.x, I.y + A.y), distq(I)};
}

circle circle_from(point A, point B) {
	return {point((A.x + B.x) / 2, (A.y + B.y) / 2), distq (point((A.x - B.x)/2, (A.y - B.y)/2))};
}

bool isIn(circle c, point p) {
	ldouble dist1 = distq(point(p.x - c.first.x, p.y - c.first.y));
	ldouble dist2 = c.second;
	return dist1 < dist2 || abs (dist1 - dist2) < 1e-35;
}

void load() {
	
}

double X, Y, d, e, x[1000], y[1000];
int n;

double dista(double a, double b) {
	return a * a + b * b;
}

void solve() {
		scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%lf%lf", &x[i], &y[i]);
		X += x[i]; Y += y[i];
	}
	X /= n; Y /= n;
	double P = 0.1;
	for (int i = 0; i < 30000; i++) {
		int f = 0;
		d = dista(X - x[0], Y - y[0]);
		for (int j = 1; j < n; j++) {
			e = dista(X - x[j], Y - y[j]);
			if (d < e) { d = e; f = j; }
		}
		X += (x[f] - X)*P;
		Y += (y[f] - Y)*P;
		P *= 0.999;
	}
	printf("%.15lf", sqrt(d));
}

int main() {
	load();
	solve();
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int a[100];
	int n, i, j, tmp;
	int minj, count = 0;

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

	for (i = 0; i < n; i++) {
		minj = i;
		for (j = i; j < n; j++) {
			if (a[j] < a[minj]) {
				minj = j;
			}
		}
		if (i != minj) {
			tmp = a[i];
			a[i] = a[minj];
			a[minj] = tmp;
			count++;
		}
	}


	for (i = 0; i < n; i++) {
		printf("%d", a[i]);
		if (i == n - 1) {
			printf("\n");
		}
		else {
			printf(" ");
		}
	}
	printf("%d\n", count);

	return 0;
}


Measured memory_bytes: 1924
import java.util.*;
class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
      	int k = sc.nextInt();
      
      if(n%k==0){System.out.println(0);}
      else{System.out.println(1);}

    }
}

Measured memory_bytes: 21844
p = int(input())
def fib(n):
    dp = [0] * 50
    for i in range(n+1):
        if i == 0 or i == 1:
            dp[i] = 1
        else:
            dp[i] = dp[i-1] + dp[i-2]
    return dp[n]
print(fib(p))



Measured memory_bytes: 5596
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
// ll mod=1000000007;
 
int main(){
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    cout.tie(NULL);
    ll t,i,j,k,temp,temp2,n,m,x,y,sum=0;
    cin >> t;
    for(i=1;i<=t;i++){
        for(j=1;j<=t;j++){
            for(k=1;k<=t;k++){
                sum+= __gcd(__gcd(i,j),k);
            }
        }
    }
    cout << sum;
}

Measured memory_bytes: 3648
n = int(input())
x = [int(a) for a in input().split()]
sorted_x = sorted(x)
for elem in x:
    if elem >= sorted_x[(len(x) + 1) // 2]:
        print(sorted_x[(len(x) + 1) // 2 - 1])
    else:
        print(sorted_x[(len(x) + 1) // 2])
    

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

using namespace std;

#define int long long
#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define FORR(i, a, b) for(ll i = (a); i > (b); --i)
#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOREACH(x, a) for(auto &(x) : (a))
#define VECCIN(x)                                                              \
    for(auto &youso_ : (x)) cin >> youso_
#define bitcnt __builtin_popcount
#define SZ(x) ((ll)(x).size())
#define fi first
#define se second
#define All(a) (a).begin(), (a).end()
template <typename T = long long> inline T IN() {
    T x;
    cin >> x;
    return (x);
}
inline void CIN() {}
template <class Head, class... Tail>
inline void CIN(Head &&head, Tail &&... tail) {
    cin >> head;
    CIN(move(tail)...);
}
#define CINT(...)                                                              \
    int __VA_ARGS__;                                                           \
    CIN(__VA_ARGS__)
#define LCIN(...)                                                              \
    ll __VA_ARGS__;                                                            \
    CIN(__VA_ARGS__)
#define SCIN(...)                                                              \
    string __VA_ARGS__;                                                        \
    CIN(__VA_ARGS__)
#define Yes(a) cout << (a ? "Yes" : "No") << "\n"
#define YES(a) cout << (a ? "YES" : "NO") << "\n"
#define Printv(v)                                                              \
    {                                                                          \
        FOREACH(x, v) { cout << x << " "; }                                    \
        cout << "\n";                                                          \
    }
template <typename T = string> inline void eputs(T s) {
    cout << s << "\n";
    exit(0);
}
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
    std::fill((T *)array, (T *)(array + N), val);
}
template <typename T> using PQG = priority_queue<T, vector<T>, greater<T>>;
template <typename T> using PQ = priority_queue<T>;

typedef long long ll;
typedef unsigned long long ul;
typedef vector<ll> VL;
typedef pair<ll, ll> PL;

const int INF = 1e9;
const int MOD = 1e9 + 7;
// const int MOD = 998244353;
const ll LINF = 1e18 + 1;
const ll dx[] = {1, -1, 0, 0};
const ll dy[] = {0, 0, 1, -1};

ll N;
vector<PL> ba;

signed main() {
    cin >> N;
    REP(i, N) {
        LCIN(A, B);
        ba.emplace_back(B, A);
    }
    sort(All(ba));
    ll now = 0;
    REP(i, N) {
        if(now + ba[i].se > ba[i].fi) eputs("No");
        now += ba[i].se;
    }
    cout << "Yes"
         << "\n";
}

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

dp = [-1]*(k+1)
dp[0] = 0
# 残りの石が i 個のときに手番が勝つ:1 else:0

for i in range(1,k+1):
    j = 0
    while j < n and a[j] <= i:
        if dp[i-a[j]] == 0:
            dp[i] = 1
            break
        j += 1
    if dp[i] == -1:
        dp[i] = 0
if dp[k] == 1:
    print('First')
else:
    print('Second')


Measured memory_bytes: 43244
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1e9;
ll power(ll a,ll b){
 ll ans=1;
 for(ll i=1;i<=b;i++){
ans*=a;
  }
  return ans;
}


ll unko(ll x){
  ll ans=0;

  
  while(x%2==0){
    x/=2;
    ans++;
  }
return ans;
}

    

int main(){
  ll N;
  cin>>N;
  
  vector<ll>a(N);
  for(ll i=0;i<N;i++){
    cin>>a[i];
  }
  ll sum=0;
  for(ll i=0;i<N;i++){
      if(sum!=0){
      a[i]=a[i]*power(3,sum);
      }
    if(a[i]%2==0){
     
      
      
      sum+=unko(a[i]);
    }
  }
  
  cout<<sum<<endl;
}

      

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repit(it, li) for(auto it=li.begin(); it!=li.end(); it++)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main(){
   int n, k;
   cin>>n>>k;
   int r, s, p;
   cin>>r>>s>>p;
   string t;
   cin>>t;

   int sc=0;
   rep(i, k){
      char pre=0;
      for(int j=i; j<n; j+=k){
         if(t[j]!=pre){
            if(t[j]=='r') sc+=p;
            if(t[j]=='s') sc+=r;
            if(t[j]=='p') sc+=s;
            pre=t[j];
         }
         else pre=0;
      }
   }

   cout<<sc<<endl;
   return 0;
}


Measured memory_bytes: 3704
#include <cassert>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <limits>
#include <numeric>
#include <iterator>

using namespace std;


int partition_tail_pivot(vector<int>& a, int p, int r){
  auto piv = a[r];
  int i = p-1;
  for(int j = p; j < r; ++j){
    if(a[j] <= piv){
      ++i;
      swap(a[i], a[j]);
    }
  }
  swap(a[i+1], a[r]);
  return i+1;
}


int main(){
  ios::sync_with_stdio(false);

  int n;
  vector<int> a; // 1 .. 10000
  cin >> n;
  for(int i = 0; i<n; ++i){int a_i; cin >> a_i; a.push_back(a_i);}
  
  int q = partition_tail_pivot(a, 0, n-1);

  //output
  
  for(int i=0; i<n; ++i){
    cout << (i==0?"":" ") 
	 << (i==q?"[":"")
	 << a[i]
	 << (i==q?"]":"");
  }
  cout << endl;
  //  cout << q << endl;

  return 0;
}

Measured memory_bytes: 1684
#include <stdio.h>
int main(void){
  int N, M;
  scanf("%d%d", &N, &M);
  int votes[N];
  int total=0;
  for (int i=0; i<N; ++i){
    scanf("%d", &votes[i]);
    total+=votes[i];}
  int count=0;
   for (int i=0; i<N; ++i){
     if (votes[i]>=(double) total/(4*M))
       ++count;}
  if (count>=M)
    printf("Yes");
  else
    printf("No");
  return 0;}

Measured memory_bytes: 128
size = int(input())
l = []
for i in map(int, input().split()):
    l.append(i)
print(' '.join(map(str,l)))

for i in range(1,size):
    tmp = l[i]
    j = i - 1

    while l[j] > tmp and j >= 0:
        l[j + 1] = l[j]
        j = j - 1
    l[j + 1] = tmp
    
    print(' '.join(map(str,l)))


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

int main(void) {
    long long N, K;
    cin >> N >> K;

    while (1) {
        N = N % K;
        long long n = N - K;
        if (n < 0) n = n * (-1);

        if (n >= N) break;
        N = n;
    } 

    cout << N << endl;
    return 0;
}

Measured memory_bytes: 3556
function main(input){
    abc=input.split('\n')[0].split(' ');
    abc=abc.sort();
    a='';
    a+=abc[2];
    a+=abc[1];
    a=parseInt(a,10);
    b=parseInt(abc[0],10);
    console.log(a+b);
    


}

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


Measured memory_bytes: 7372
#include <iostream>
#include <numeric>
#include <cmath>

using namespace std;
using ll = long long;

int main(){
  ll A,B,N;
  cin >> A >> B >> N;

  ll g = gcd(A,B);
  ll a = A/g;
  ll b = B/g;

  ll r;
  if (N >= B-1) {
    r = B-1;
  } else {
    r = N;
  }

  ll ans = floor((double)a*(double)r/(double)b);
  cout << ans << endl;

  
  return 0;
}


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


int main() {
  int N;
  cin >> N;
  vector<int> p(N);
  long long int sum = 0;
  for (int i = 0; i < N; i++) {
    cin >> p.at(i);
    sum += p.at(i);
  }
  int ave = sum / N;
  long long int s = 0;
  for (int i = 0; i < N; i++) {
    s += (p.at(i) - ave) * (p.at(i) - ave);
  }
  ave++;
  long long int s2 = 0;
  for (int i = 0; i < N; i++) {
    s2 += (p.at(i) - ave) * (p.at(i) - ave);
  }
  cout << min(s, s2)<<endl;
}

Measured memory_bytes: 256
#include<cstdio>

int main(){
    int n;
    while(scanf("%d",&n)!=EOF){
        switch(n){
    case 25:
        puts("Christmas");
        break;
    case 24:
        puts("Christmas Eve");
        break;
    case 23:
        puts("Christmas Eve Eve");
        break;
    case 22:
        puts("Christmas Eve Eve Eve");
        break;
    }
    }

    return 0;
}


Measured memory_bytes: 128
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Vector;

public class Main {
	public static void main(String args[] ) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		while(true){
			String num=br.readLine();
			if(num==null){
				break;
			}
			int a=Integer.parseInt(num.split(" ")[0]),b=Integer.parseInt(num.split(" ")[1]);
			System.out.println(a+b);
		}
	}
}

Measured memory_bytes: 17068
H, W = map(int, input().split())
S = [list(input()) for _ in range(H)]

for i in range(H):
    for j in range(W):
        count = 0
        search = [[i-1, j-1], [i-1, j], [i-1, j+1], [i, j-1], [i, j+1], [i+1, j-1], [i+1, j], [i+1, j+1]]
        if S[i][j] == '#':
            continue
        for k in search:
            if k[0]<0 or k[0]>=H or k[1]<0 or k[1]>=W:
                continue
            if S[k[0]][k[1]] == '#':
                count += 1
        S[i][j] = str(count)

for s in S:
    print("".join(s))

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

using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define REP(NAME, NUM) for (int NAME = 0; NAME < (NUM); ++NAME)
#define BREP(NAME, NUM) for (int NAME = (NUM)-1; NAME >= 0; --NAME)
#define ALL(NAME) (NAME).begin(), (NAME).end()

int main()
{
	ll r,g,b,n;
	cin >> r>>g>>b>>n;
	ll c = 0;
	REP(i,3001)
	{
		ll left = n - r * i;
		if( left < 0 ) break;
		REP( j, 3001 )
		{
			ll lleft = left - g * j;
			if( lleft < 0 ) break;
			if( lleft % b == 0 ) ++c;
		}
	}
	cout << c << endl;
	return 0;
}

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

int main () {

  int a, b, c, d;
  cin >> a >> b >> c >> d;
  if ((a * b) > (c * d)) {
    cout << a * b << endl;
  }
  else {
    cout << c * d << endl;
  }

  return 0;
}


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

int main(){
    int N,K;
    cin >> N >> K;
    vector<int>l(N);
    for(int i = 0; i < N; i++) {
        cin >> l[i];
    }
    sort(l.begin(),l.end());
    int ans = 0;
    for(int i = N-1; i >= N-K; i--) {
        ans += l[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
using namespace std;
template <class T> inline bool chmax(T &a, T b) {if (a < b) {a = b; return true;} return false;}
template <class T> inline bool chmin(T &a, T b) {if (a > b) {a = b; return true;} return false;}
typedef long long ll;
const ll INF = 1LL<<60;
const int MAX_N = 110;
const int MAX_V = 100100;

// 入力
int N;
ll W, weight[MAX_N], value[MAX_N]; // 少し余裕を持たせてサイズ110で用意

// DP table
ll dp[MAX_N][MAX_V];

int main() {
    cin >> N >> W;
    REP(i,N) cin >> weight[i] >> value[i];
  
    // 初期化
    REP(i,MAX_N) REP(j,MAX_V) dp[i][j] = INF;
  
    // 初期条件
    dp[0][0] = 0;

    // DP
    REP(i,N) {
        REP(sum_v,MAX_V) {
        // i番目の品物を選び場合
        if (sum_v - value[i] >= 0) {
          chmin(dp[i+1][sum_v], dp[i][sum_v - value[i]] + weight[i]);
        }
        // i番目の品物を選ばない場合
        chmin(dp[i+1][sum_v], dp[i][sum_v]);
      }
    }
  
    // 最適地の出力
    ll res = 0;
    REP(sum_v,MAX_V) {
        if (dp[N][sum_v] <= W) res = sum_v;
    }
    cout << res << endl;
}

Measured memory_bytes: 86272
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
	static final PrintStream out = System.out;
	static final Scanner sc = new Scanner(System.in);
	static final long Mod = 1000_000_007L;
	public static void main(String[] args) {
		Main main = new Main();
		main.solve();
		System.exit(0);
	}

	void solve() {
		int N = nextInt();
		long [] H = nextLongArray(N);

		int maxcnt = 0;
		int cnt = 0;
		for(int i=1;i<N;i++) {
			if(H[i-1]>=H[i]){
				cnt++;
				if(cnt > maxcnt) maxcnt=cnt;
			}else if(H[i-1]<H[i]){
				cnt = 0;
			}
		}

		out.println(maxcnt);
	}

	public int[] nextIntArray(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)a[i] = nextInt();
		return a;
	}
	public long[] nextLongArray(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)a[i] = nextLong();
		return a;
	}
	public int nextInt() {
		return Integer.parseInt(next());
	}
	public long nextLong() {
		return Long.parseLong(next());
	}
	public String next() {
		return sc.next();
	}

}

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

int main() {
    int N, Q; cin >> N;
    string S; cin >> S; cin >> Q;
    vector<set<int>> st(26);
    for(int i = 0; i < N; i++){
        st[S[i]-97].insert(i);
    }
    for(int i = 0; i < Q; i++){
        int c; cin >> c;
        if(c == 1){
            int idx; cin >> idx; idx-=1;
            string s; cin >> s;
            st[S[idx]-97].erase(idx);
            S[idx] = s[0];
            st[s[0]-97].insert(idx);
        }
        else if(c ==2){
            int l, r; cin >> l >> r;l-=1;r-=1;
            int cnt=0;
            for(int j = 0; j < 26; j++){
                auto it = st[j].lower_bound(l);
                if(it != st[j].end()){
                    if(*it <= r) cnt++;
                }
                
            }
            cout << cnt << endl;
        }
    }
    cout << endl;
}

Measured memory_bytes: 24196
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>


using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;

#define REP(i,n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i,a,b) for(int i = (a); i < (int)(b); ++i)
#define ALL(c) (c).begin(), (c).end()
#define SIZE(v) ((int)v.size())

#define pb push_back
#define mp make_pair
#define mt make_tuple

template <typename T>
class CumSum1D
{
public:
    CumSum1D(){};
    ~CumSum1D(){};
    void init(vector<T>& arr) {
        m_cum = arr;
        m_N = arr.size();
        FOR(i, 1, m_N) m_cum[i] += m_cum[i - 1];
    }
    // get sum of [l, r]. 0-based.
    T getSum(int l, int r) {
        T ret = m_cum[r];
        if (l != 0) ret -= m_cum[l - 1];
        return ret;
    }
    void printSum() {
        for(auto e: m_cum) cout << e << " "; cout << endl;
    }

private:
    size_t m_N;
    vector<T> m_cum;
};

int main(void)
{
    cin.sync_with_stdio(false);
    int N, Q;
    string S;
    cin >> N >> Q;
    cin >> S;

    vector<int> acs(N);
    REP(n, N - 1) {
        if (S[n] == 'A' && S[n + 1] == 'C') {
            acs[n]++;
        }
    }
    CumSum1D<int> ac_sums;
    ac_sums.init(acs);
    // for(auto e: acs) cout << e << " "; cout << endl;
    // ac_sums.printSum();
        
    REP(q, Q) {
        int l, r;
        cin >> l >> r;
        --l; --r;
        int ans = ac_sums.getSum(l, r - 1);
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 1872
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  if (A+B < C+D){
  cout << "Right" << endl;
  }
  else if (A+B  == C+D){
    cout << "Balanced" << endl;
  }
  else {
  cout << "Left" << endl;
  }
}

Measured memory_bytes: 3584
import sys
# from collections import defaultdict, deque
# import math
# import copy
from bisect import bisect_left, bisect_right
# import heapq

# sys.setrecursionlimit(1000000)

# input aliases
input = sys.stdin.readline

getS = lambda: input().strip()
getN = lambda: int(input())
getList = lambda: list(map(int, input().split()))
getZList = lambda: [int(x) - 1 for x in input().split()]

INF = 10 ** 20
MOD = 10 ** 9 + 7
def solve():
    n = getN()
    arms = []
    for i in range(n):
        x, l = getList()
        arms.append((x-l, x+l))

    arms.sort()
    # print(arms)
    prev = -INF
    ans = n
    for arm in arms:
        if arm[0] < prev:
            ans -= 1
            if arm[1] <= prev:
                prev = arm[1]
        else:
            prev = arm[1]

    print(ans)

def main():
    n = getN()
    for _ in range(n):
        solve()
if __name__ == "__main__":
    # main()
    solve()


Measured memory_bytes: 80944
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef double ld;
typedef complex<ld> Point;
const ll INF = mod * mod;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
typedef vector<int> vec;
typedef vector<string> svec;

vector<pair<string, string>> c;
void solve() {
	int n, l; cin >> n >> l;
	svec v(n);
	rep(i, n)cin >> v[i];
	vector<bool> used(n, false);
	rep(i, n) {
		if (used[i])continue;
		Rep(j,i+1, n) {
			if (used[j])continue;
			bool f = true;
			rep(k, l) {
				if (v[i][k] != v[j][l - k - 1])f = false;
			}
			if (f) {
				c.push_back({ v[i],v[j] });
				used[i] = used[j] = true;
				break;
			}
		}
	}
	string r;
	rep(i, n) {
		if (used[i])continue;
		bool f = true;
		rep(j, l) {
			if (v[i][j] != v[i][l - j - 1])f = false;
		}
		if (f) {
			if (r == "") {
				r = v[i];
			}
			else {
				r = min(r, v[i]);
			}
		}
	}
	rep(i, c.size()) {
		if (c[i].first > c[i].second)swap(c[i].first, c[i].second);
	}
	sort(c.begin(), c.end());
	string ans;
	rep(i, c.size()) {
		ans += c[i].first;
	}
	ans += r;
	per(i, (int)c.size()) {
		ans += c[i].second;
	}
	cout << ans << endl;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(5);
	//while (cin >> n>>h>>m>>s,n)solve();
	solve();
	//stop
	return 0;
}



Measured memory_bytes: 3304
N,M=map(int,input().split())
H=list(map(int,input().split()))
graph=[[] for _ in range(N)]
for i in range(M):
	A,B=map(int,input().split())
	graph[A-1].append(B)
	graph[B-1].append(A)
answer=0
for i in range(N):
	count=0
	for j in graph[i]:
		if H[i]<=H[j-1]:
			count+=1
			break
	if count==0:
		answer+=1
print(answer)
		
		

Measured memory_bytes: 29472
#include <bits/stdc++.h>
#define rep(i, m, n) for(int i = m; i < (n); i++)
#define print(x) cout << (x) << endl;
#define printv(x) for(int i = 0; i < x.size(); i++){ cout << (x[i]) << " "; } cout << endl; 
#define printa(x,n) for(int i = 0; i < n; i++){ cout << (x[i]) << " ";} cout << endl;
#define printa2(x,m,n) for(int i = 0; i < m; i++){ for(int j = 0; j < n; j++){ cout << x[i][j] << " ";} cout << endl;}
#define INF (1e9)
typedef long long ll;
typedef struct{
    int x;
    int y;
} P;

using namespace std;
ll dist[60][60] = {};
ll dist_result[60][60] = {};
int N,M;
void floyd(){
    rep(i,0,N){
        rep(j,0,N){
            dist_result[i][j] = dist[i][j];
        }
    }
    rep(k,0,N){
        rep(i,0,N){
            rep(j,0,N){
                dist_result[i][j] = min(dist_result[i][j], dist_result[i][k] + dist_result[k][j]);
            }
        }
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false); 
    int a[55], b[55];
    cin >> N >> M;
    rep(i,0,M){
        cin >> a[i] >> b[i];
        a[i]--;
        b[i]--;
    }
    int ans = 0;
    rep(i,0,N){
        rep(j,0,N){
            if(i == j){
                dist[i][j] = 0;
            }else{
                dist[i][j] = INF;
            }
        }
    }
    rep(i,0,M){
        dist[a[i]][b[i]] = 1;
        dist[b[i]][a[i]] = 1;
    }
    floyd();

    rep(i,0,M){
        dist[a[i]][b[i]] = INF;
        dist[b[i]][a[i]] = INF;

        floyd();
        if(dist_result[a[i]][b[i]] > 1e5){
            ans++;
        }
        dist[a[i]][b[i]] = 1;
        dist[b[i]][a[i]] = 1;
    }
    print(ans);

}


Measured memory_bytes: 256
#include<cstdio>
#define ll long long
const int N=2005,mo=924844033;
int n,rm,m,i,j,k,f[N][2],ans;
void work(int m,int l,int r){
	if (!m) return;int t=l<=rm;
	for (int i=0;i<=n;i++)
		f[i][t]=(f[i][0]+f[i][1])%mo,f[i][t^1]=0;
	for (int i=1;i<=m;i++){
		for (int j=n;j;j--){
			f[j][0]=((ll)f[j][0]+f[j][1]+f[j-1][0])%mo;
			f[j][1]=(f[j-1][0]+f[j-1][1])%mo;
		}
		f[0][0]=(f[0][0]+f[0][1])%mo;f[0][1]=0;
	}
	if (r<=rm) for (int i=0;i<=n;i++) f[i][1]=0;
}
int main(){
	scanf("%d%d",&n,&m);rm=m;m*=2;
	f[0][0]=1;
	for (i=1;i<=n%m;i++) work(n/m+1,i,n%m-i+1);
	for (i=1;i<=m-n%m;i++)
		work(n/m,m-i+1,n%m+i);
	for (i=0,j=n&1?-1:1,k=1;i<=n;i++,j=-j,k=(ll)k*i%mo)
		ans=(ans+(ll)(f[n-i][0]+f[n-i][1])*k*j)%mo;
	printf("%d",(ans+mo)%mo);
}

Measured memory_bytes: 128
using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;

namespace ConsoleApplication2
{
    class Program
    {

        static void Main(string[] args)
        {
            string line = null;
            while((line = Console.ReadLine()) != null)
            {
                if (line == "0")
                    break;

                int sum = 0;
                foreach (var ch in line)
                {
                    sum += int.Parse(ch.ToString());
                }
                Console.WriteLine(sum);
            }
        }
    }
}

Measured memory_bytes: 9152
import math

def is_prime(n):
    if n == 2:
        return True
    if n < 2 or n%2==0:
        return False
    
    for i in range(3, int(math.sqrt(n))+1):
        if n % i == 0:
            return False
    
    return True

num = int(input())
num_list = []
for i in range(num):
    num_list.append(int(input()))

prime_count = 0
for n in num_list:
    if is_prime(n):
        prime_count += 1

print(prime_count)


Measured memory_bytes: 6004
#include <iostream>
#include <cstdio>
#include <cassert>
#include <cstring>
#include <cmath>
#include <functional>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>
#include <map>
#include <set>
#define ms(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
const int mod = 998244353;
const int inf = 1 << 30;
const int maxn = 100000 + 5;



int main() {
  string s; cin >> s;
  if (s == "SUN") puts("7");
  else if (s == "MON") puts("6");
  else if (s == "TUE") puts("5");
  else if (s == "WED") puts("4");
  else if (s == "THU") puts("3");
  else if (s == "FRI") puts("2");
  else if (s == "SAT") puts("1");
  return 0;
}

Measured memory_bytes: 256
use std::io::prelude::*;

fn input<T>() -> T
where
    T: std::str::FromStr,
{
    let stdin = std::io::stdin();
    let token = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    token.parse().ok().unwrap()
}

fn main() {
    let a = input::<i64>();
    let b = input::<i64>();
    println!("{}", (0..b - a).sum::<i64>() - a);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int i = (int)(n); i >= 0; i--)
#define all(v) v.begin(),v.end()
typedef long long ll;

int main(){
    ll N, S;
    cin >> N >> S;
    vector<ll> A(N);
    rep(i,N) cin >> A[i];
    vector<vector<ll> > dp((N + 1), vector<ll> (3005));
    rep(i,N + 1){
        rep(j,3005){
            dp[i][j] = 0;
        }
    }
    dp[0][0] = 1;
    for (ll i = 0; i < N; i++){
        for (ll j = 0; j <= 3000; j++){
            if (j + A[i] <= 3000) dp[i + 1][j + A[i]] = (dp[i + 1][j + A[i]] + dp[i][j]) % 998244353;
            dp[i + 1][j] = (dp[i + 1][j] + (dp[i][j] * 2) % 998244353) % 998244353;
        }
    }
    cout << dp[N][S] % 998244353 << endl;
}


Measured memory_bytes: 73744
<?php
list($A, $B, $Q) = explode(" ", trim(fgets(STDIN)));
for($i = 0; $i < $A; $i++){
    $aArray[] = trim(fgets(STDIN));
}
array_unshift($aArray, -10**12);
$aArray[] = 10**12;
for($i = 0; $i < $B; $i++){
    $bArray[] = trim(fgets(STDIN));
}
array_unshift($bArray, -10**12);
$bArray[] = 10**12;

for($i = 0; $i < $Q; $i++){
    $qArray[] = trim(fgets(STDIN));
}

foreach($qArray as $q){
    $min = 10**18;
    $a = bsl($aArray, $q);
    $b = bsl($bArray, $q);
    foreach([$aArray[$a], $aArray[$a+1]] as $a1){
        $p3 = $bArray[$b]??10**12;
        $p4 = $bArray[$b+1]??10**12;
        $min = min($min, abs($q - $a1) + abs($a1 - $p3));
        $min = min($min, abs($q - $a1) + abs($a1 - $p4));
    }
    foreach([$bArray[$b], $bArray[$b+1]] as $b1){
        $p3 = $aArray[$a]??10*10;
        $p4 = $aArray[$a+1]??10*10;
        $min = min($min, abs($q - $b1) + abs($b1 - $p3));
        $min = min($min, abs($q - $b1) + abs($b1 - $p4));
    }
    printf("%d\n", $min);
}

//二分探索　target以下で最大の値の場所を返す
function bsl($nums, $target) {
    $size = count($nums);
    $min = 0; 
    $max = $size - 1;
    while(true){
        $center = floor(($min + $max) / 2);
        $centerValue = $nums[$center];
        if($target == $centerValue){
            return $center;
        }elseif($target > $centerValue){
            $min = $center + 1;
        }else{
            $max = $center;
        }
        if($min == $max){
            $center = floor(($min + $max) / 2);
            $centerValue = $nums[$center];
            if($centerValue == $target){
                return $center;
            }elseif($centerValue < $target){
                return $center;
            }else{
                return $center-1;
            }
        }
    }
}


Measured memory_bytes: 30316
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <deque>
#include <cctype>
#include <cstdio>
using namespace std;
int main(){
    int a,b;
    cin >> a >> b;
    int ans = a+b;
    if(ans>=24){
        ans = ans - 24;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (long long i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vec = vector<ll>;
using vecp = vector<P>;
using mat = vector<vec>;
using matp = vector<vecp>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define all(v) v.begin(), v.end()

vec Prime(1e7,0),W(1e7,0),isPrime(1e7+1,0);
void sosu(ll n){
  isPrime.at(0)=1;
  isPrime.at(1)=1;
  ll t=0;
  rep(i,n+1){
    if(isPrime.at(i)==0){
      Prime.at(t)=i;
      t++;
      for(ll j=2*i;j<=n;j+=i){
        isPrime.at(j)=1;
      }
    }
  }
}
bool factor(ll M){
  rep(i,100000){
    if(Prime.at(i)>1e3){
      if(M==1){
        return true;
      }else{
        if(W.at(M)==0){
          W.at(M)=1;
          return true;
        }else{
          return false;
        }
      }
    }else{
      if(M%Prime.at(i)==0&&W.at(i)!=0){
        return false;
      }else if(M%Prime.at(i)==0){
        while(M%Prime.at(i)==0){
          M/=Prime.at(i);
        }
        W.at(i)=1;
      }
    }
  }
}

int main(){
  ll N,s,k=0;
  cin >> N;
  vec A(N);
  sosu(1e6);
  rep(i,N){
    cin >> A.at(i);
    if(!factor(A.at(i))){
      k=1;
    }
    if(i==0){
      s=A.at(i);
    }else{
      s=gcd(s,A.at(i));
    }
  }
  if(k==0){
    cout << "pairwise coprime" << endl;
  }else if(s==1){
    cout << "setwise coprime" << endl;
  }else{
    cout << "not coprime" << endl;
  }
}

Measured memory_bytes: 245256
n = int(input())
B = [int(x) for x in input().split()]
res = 0
for i in range(n):
  if i == 0:
    res += B[i]
  elif i < n - 1:
    res += min(B[i-1], B[i])
  else:
    res += B[i-1]
print(res)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <array>
#include <vector>
#include <math.h>
#include <algorithm>

using namespace std;


int main(void)
{
	int n;
	int a[200];

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


	return 0;

}

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

int sum[60 * 60 * 24];
int main() {
    int n;
    while(cin >> n, n) {
        for(int i = 0; i < 60 * 60 * 24; i++) sum[i] = 0;
        for(int i = 0; i < n; i++){
            int h1, m1, s1, h2, m2, s2;
            scanf("%02d:%02d:%02d", &h1, &m1, &s1);
            scanf("%02d:%02d:%02d", &h2, &m2, &s2);
            int t1 = h1 * 60 * 60 + m1 * 60 + s1;
            int t2 = h2 * 60 * 60 + m2 * 60 + s2; 
            for(int i = t1; i < t2; i++) sum[i]++;
        }
        int ans = 0;
        for(int i = 0; i < 60 * 60 * 24; i++){
            ans = max(ans, sum[i]);
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 3568
import qualified Data.Text as T
import qualified Data.Text.IO as T
import qualified Data.Text.Read as T

main :: IO ()
main = do
  (h : _) <- map unsafeSignedDecimal . T.words <$> T.getLine :: IO [Int]
  (w : _) <- map unsafeSignedDecimal . T.words <$> T.getLine :: IO [Int]
  (n : _) <- map unsafeSignedDecimal . T.words <$> T.getLine :: IO [Int]
  let
    m = max h w
  print . ceiling $ toRational n / toRational m

unsafeSignedDecimal :: T.Text -> Int
unsafeSignedDecimal s = case T.signed T.decimal s of
  Right (n, _) -> n


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

using namespace std;

#define mod 1000000007
#define ll long long int
#define mk make_pair
#define pb push_back
#define xx first
#define yy second
#define ar array

double pi=3.141592653589793238;
const int M = 1e9+7;
const int Nmax=5005;
const int MM = 1e7+1;
const int N=50010;


int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t=1;
//cin>>t;
while(t--){
int n;
cin>>n;
string s;
cin>>s;
   int c=0;
    int cr=0;
    for(int i=0;i<n;i++)
    {
        if(s[i]=='R')
        cr++;
    }

    for(int i=cr;i<n;i++)
    {
        if(s[i]=='R')
        c++;
    }

    cout<<c;
}
	return 0;
}


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

int main() {
    int N, M;
    cin >> N >> M;

    int S[6];
    char C[6];
    for (int i = 0; i < M; ++i) {
        cin >> S[i] >> C[i];
    }

    int ans = -1;
    for (int i = 0; i < 1000; ++i) {
        string str = to_string(i);

        if (str.length() >= N) {
            bool flg = true;
            for (int j = 0; j < M; ++j) {
                if (str[S[j] - 1] != C[j]) flg = false;
            }

            if (flg) {
                ans = i;
                break;
            }
        }
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <queue>
#include <stack>
#include <utility>
#include <tuple>
#include <map>
#include <ctime>
#include <cstdlib>
#include <random>
using namespace std;

int main(){
	int n, r;
	cin >> n >> r;
	if(n >= 10)cout << r << endl;
	else cout << r + 100*(10 - n) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> A(n);
  for (int i = 0; i < n; ++i) {
    int num;
    cin >> num;
    A.at(i) = num;
  }
  sort(A.begin(), A.end());
  cout << *--A.end() - *A.begin() << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#define MAX 101
#define WHITE 0
#define GRAY 1
#define BLACK 2

void pet(int);
int A[MAX][MAX],color[MAX],d[MAX],f[MAX],count,n;

int main(){
  int i,j,k,m,l;

  scanf("%d",&n);
  for(i = 0; i < MAX; i++){
    for(j = 0; j < MAX; j++){
      A[i][j] = 0;
    }
  }

  for(i = 0; i < n; i++){
    scanf("%d",&m);
    scanf("%d",&k);
    for(j = 0; j < k; j++){
      scanf("%d",&l);
      A[m][l] = 1;
    }
  }

  for(i = 0; i <= n; i++){
    color[i] = WHITE;
  }

  for(i = 0; i < n; i++){
    if(color[i+1] == WHITE) pet(i+1);
  }

  for(i = 0; i < n; i++){
    printf("%d %d %d\n",i+1,d[i+1],f[i+1]);
  }

  return 0;
}

void pet(int p){
  int e;

  color[p] = GRAY;
  d[p] = ++count;
  for(e = 0; e < n; e++){
    if(A[p][e+1] == 0) continue;
    if(color[e+1] == WHITE){
      pet(e+1);
    }
  }
  color[p] = BLACK;
  f[p] = ++count;
}



Measured memory_bytes: 2048