akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<algorithm>
#include<map>
#include<cstdlib>
#include<cmath>
#include<numeric>
#include<iomanip>
#include<functional>
#include<cstdlib>
#include<queue>
#include<deque>
const double PI = acos(-1);
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
using ll =long long;
const int mod = 1000000007;

//map<string>a
class mint {
	long long x;
public:
	mint(long long x = 0) : x((x% mod + mod) % mod) {}
	mint operator-() const {
		return mint(-x);
	}
	mint& operator+=(const mint & a) {
		if ((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint & operator-=(const mint & a) {
		if ((x += mod - a.x) >= mod) x -= mod;
		return *this;
	}
	mint & operator*=(const  mint & a) {
		(x *= a.x) %= mod;
		return *this;
	}
	mint operator+(const mint & a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint & a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint & a) const {
		mint res(*this);
		return res *= a;
	}
	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}
	// for prime mod
	mint inv() const {
		return pow(mod - 2);
	}
	mint& operator/=(const mint & a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint & a) const {
		mint res(*this);
		return res /= a;
	}

	friend ostream& operator<<(ostream & os, const mint & m) {
		os << m.x;
		return os;
	}
};
int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}
//組み合わせ
void recursive_comb(vector<int> indexes, int s, int rest, std::function<void(vector<int>)> f) {
	if (rest == 0) {
		f(indexes);
	}
	else {
		if (s < 0) return;
		recursive_comb(indexes, s - 1, rest, f);
		indexes[rest - 1] = s;
		recursive_comb(indexes, s - 1, rest - 1, f);
	}
}

// nCkの組み合わせに対して処理を実行する
void foreach_comb(int n, int k, std::function<void(vector<int>)> f) {
	vector<int>indexes(k);
	recursive_comb(indexes, n - 1, k, f);
}

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

int main() {
	int h, w, K;
	cin >> h >> w >> K;
	vector<string>c(h);
	rep(i, h) {
		cin >> c[i];
	}
	vector<string>ct(h);
	rep(k, h) {
		ct[k]=c[k];
	}
	ll tmp,ans;
	ans = 0;
	for(int i = 0; i < pow(2,h+w); i++) {
		tmp = 0;

		rep(k, h) {
			ct[k] = c[k];
		}

		for (int j = 0; j< w + h;j++) {
			if ((i&(int)pow(2,j))== (int)pow(2, j)){
				if (j < h) {
					for (int l = 0; l < w; l++) {
						ct[j][l] = 'r';

					}

				}
				else{
				
					for (int l = 0; l < h; l++) {
						ct[l][j-h] = 'r';

					}

				}

			}


		}
		for (int j = 0; j < h; j++) {
			for (int k = 0; k < w; k++) {

				if (ct[j][k] == '#') {
					tmp++;
				}
			}


		}
		if (tmp == K) {
			ans++;
		}
	}
	cout << ans;
}
	


Measured memory_bytes: 3200
#!/usr/bin/env python
from __future__ import division, print_function

import os
import sys
from io import BytesIO, IOBase

if sys.version_info[0] < 3:
    from __builtin__ import xrange as range
    from future_builtins import ascii, filter, hex, map, oct, zip


def main():
    n, k, s = map(int, input().split())
    if s != 10**9:
        a = [s] * k + [10**9] * (n - k)
    else:
        a = [s] * k + [1] * (n - k)
    print(*a)


# region fastio

BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


def print(*args, **kwargs):
    """Prints the values to a stream, or to sys.stdout by default."""
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()


if sys.version_info[0] < 3:
    sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
    sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)

input = lambda: sys.stdin.readline().rstrip("\r\n")

# endregion

if __name__ == "__main__":
    main()


Measured memory_bytes: 47812
$n = <>;chomp $n;
$an = <>;chomp $an;
@a = split / /, $an;

for (0..$n-1) {
    if ($_ % 2) {
        push @b, $a[$_];
    }
    else {
        unshift @b, $a[$_];
    }
}

@b = reverse @b unless $n % 2;

print join " ", @b;


Measured memory_bytes: 40996
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int x1,x2,y1,y2;
    cin >> x1 >> y1 >> x2 >> y2;
    int dx = x2-x1;
    int dy = y2-y1;
    
    int x3 = x2-dy;
    int y3 = y2+dx;
    int x4 = x1-dy;
    int y4 = y1+dx;
    cout << x3 << " " << y3 << " " << x4 << " " << y4 << endl;
}

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

int main() {
    ll X, Y;
    cin >> X >> Y;

    int cnt = 0;
    while (X <= Y) {
        ++cnt;
        X *= 2LL;
    }

    cout << cnt << endl;
}

Measured memory_bytes: 256
s =  list(input())
if len(set(s)) == 4:
    print("Yes")
elif len(set(s)) == 2:
    if "N" in s and "S" in s:
        print("Yes")
    elif "W" in s and "E" in s:
        print("Yes")
    else:
        print("No")
else:
    print("No")


Measured memory_bytes: 3060
import sys
from collections import deque  # 双方向キュー
from collections import defaultdict  # 初期化済み辞書
from heapq import heapify, heappush, heappop, heappushpop  # プライオリティキュー
from bisect import bisect_left, bisect_right  # 二分探索
#import numpy as np  # 1.8.2
#import scipy  # 0.13.3
#sys.setrecursionlimit(int(1e+6))
s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in ss]
ss2nnn = lambda ss: [s2nn(s) for s in ss]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [sys.stdin.readline().rstrip() for _ in range(n)]
ii2sss = lambda n: [list(sys.stdin.readline().rstrip()) for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))
MOD = int(1e+9) + 7

def main():
    N, M = i2nn()
    UV = ii2nnn(M)
    S, T = i2nn()
    to = [[] for _ in range(N+1)]
    for u, v in UV:
        to[u].append(v)
    bit = [0] * (N+1)
    q = deque()
    q.append((S, 1, 0))
    while q:
        i, b, c = q.popleft()
        if b & bit[i] == b:
            continue
        if i == T and (b & 1) == 1:
            print(c//3)
            return
        bit[i] |= b
        b2 = bit[i] << 1
        if b2 >= 8:
            b2 -= 7
        for j in to[i]:
            q.append((j, b2, c+1))
    print(-1)

main()


Measured memory_bytes: 85980
from collections import deque
n = int(input())
dl = deque()
for _ in range(n):
    cmd = input()
    if ' ' in cmd:
        op,v = cmd.split()
    else:
        op = cmd
    if   op == 'insert'     : dl.appendleft(v) 
    elif op == 'delete'     :
        try: dl.remove(v)
        except ValueError: pass
    elif op == 'deleteFirst': dl.popleft() 
    elif op == 'deleteLast' : dl.pop() 
print(*dl)

Measured memory_bytes: 71868
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
ll mod = 1000000007;

struct edge {
    int to, weight;
};

vector<edge> G[200010];
bool visit[100010];
int d[100010];

bool dfs(int v, int dist) {
    if(visit[v]) {
        if(d[v] != dist) {
            return true;
        }
        else {
            return false;
        }
    }

    visit[v] = true;
    d[v] = dist;
    for(int i = 0; i < G[v].size(); i++) {
        if( dfs(G[v][i].to, d[v] + G[v][i].weight) ) {
            return true;
        }
    }
    return false;
}

int main() {
    int n, m;
    cin >> n >> m;

    rep(i, m) {
        int L, R, D;
        cin >> L >> R >> D;
        L--;  R--;
        G[L].push_back({ R,D });
        G[R].push_back({ L,-D });
    }

    rep(i, n) {
        if(!visit[i] && dfs(i, 0)) {
            cout << "No" << endl;
            return 0;
        }
    }
    
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 14464
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <deque>
#include <list>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>

using namespace std;


#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int (i)=(n); (i)>=(0); (i)--)
#define SIZE(x) ((int)(x).size())
#define GCD(a, b) int gcd(int a,int b){return b?gcd(b,a%b):a;}
#define QP(a, b) int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define all(v) (v).begin(),(v).end()


template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
template<typename A, size_t N, typename T>
void FILL(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

typedef vector<int, int> vint;
typedef pair<int,int> pint;
typedef vector<pint>vpint;
typedef long long ll;

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1LL << 60;
const ll MOD = 1000000007LL;


ll func(ll n, ll m){
    if(n < 0) return 0;
    else return n/m + 1;
}


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll a, b, x; cin >> a >> b >> x;
    cout << func(b, x) - func(a-1, x);
    cout << endl;
    return 0;
}



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

int main() {
    rep(i, 5){
        int x; cin >> x;
        if(x == 0){
            cout << i+1 << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 3588
import java.util.Scanner;

public class Main {

	public static void main(String args[]) {

		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] a1 = new int[N];
		int[] a2 = new int[N];

		for(int i=0;i<N;i++) {
			a1[i] = sc.nextInt();
		}

		int suma2 = 0;
		for(int i=0;i<N;i++) {
			a2[i] = sc.nextInt();
			suma2 += a2[i];
		}

		int suma1 = a1[0];
		int maxsum = suma1 + suma2;
		for(int i=1;i<N;i++) {
			suma1 += a1[i];
			suma2 -= a2[i-1];
			if(maxsum < (suma1 + suma2)) {
				maxsum = (suma1 + suma2);
			}
		}
		System.out.println(maxsum);
	}

}


Measured memory_bytes: 23892
# ABC077C

# import bisect

# N=int(input())
# A=sorted(list(map(int,input().split())))
# B=sorted(list(map(int,input().split())))
# C=sorted(list(map(int,input().split())))

# bC=[0 for i in range(N)]
# for i in range(N):
#     bC[i]=N-bisect.bisect(C,B[i])
    
# bCS=[0]*(N+1)
# for i in range(N):
#     bCS[i+1] = bCS[i]+bC[i]
    
# ans=0
# for i in range(N):
#     x=bisect.bisect(B,A[i])
#     ans+=bCS[N]-bCS[x]
        
# print(ans)

# 以下賢い

import bisect

N=int(input())
A=sorted(list(map(int,input().split())))
B=sorted(list(map(int,input().split())))
C=sorted(list(map(int,input().split())))

ans=0
for i in range(N):
    ans+=bisect.bisect_left(A,B[i])*(N-bisect.bisect_right(C,B[i]))
print(ans)

Measured memory_bytes: 107108
#include <stdio.h>

void Swap(int* x, int* y){
    int tmp;
    tmp = *x;
    *x = *y;
    *y = tmp;
}

int partition(int A[], int p, int r){
    int x = A[r];
    int i = p - 1;
    int tmp;
    for(int j = p; j < r; j++){
        if(A[j] <= x){
            i++;
            Swap(&A[i], &A[j]);
        }
    }
    Swap(&A[i+1], &A[r]);
    return i+1;
}

int main(){
    int n, i;
    scanf("%d", &n);
    int A[n];
    for(i = 0; i < n; i++){
        scanf("%d", &A[i]);
    }
    int q = partition(A, 0, n-1);
    for(i = 0; i < n; i++){
        if(i != 0) printf(" ");
        if(i == q) printf("[");
        printf("%d", A[i]);
        if(i == q) printf("]");
    }
    printf("\n");
    return 0;
}


Measured memory_bytes: 2112
import java.io.*;
import java.util.*;
import static java.lang.System.*;
import static java.lang.Math.*;

public class Main
{	
	public static void main(String []args)throws IOException
	{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		
		//long X=Long.parseLong(br.readLine());
		String []s=br.readLine().split(" ");
		long A=Long.parseLong(s[0]);
		long B=Long.parseLong(s[1]);
		long C=Long.parseLong(s[2]);
		long K=Long.parseLong(s[3]);
		
		long sum=0;
		boolean flag=true;
		
		if(K>A && flag==true)
		{
			K-=A;
			sum+=A;
			//out.println("if A K="+ K+" sum="+sum);
		}
		
		else if(K<=A && flag==true)
		{
			sum+=K;
			K=0;
			flag=false;
			//out.println("elif A K="+ K+" sum="+sum);
		}
		
		if(K>B &&  flag==true)
		{
			K-=B;
			//out.println("if B K="+ K+" sum="+sum);
		}
			
		else if(K<=B && flag==true)
		{
			K=0;
			flag=false;
			//out.println("elif B K="+ K+" sum="+sum);		
		}
		
		if(K>C && flag==true)
		{
			K-=C;
			sum-=C;
			//out.println("if C K="+ K+" sum="+sum);		
		}
		else if(K<=C && flag==true)
		{
			sum-=K;
			K=0;
			flag=false;
			//out.println("elif C K="+ K+" sum="+sum);		
		}
		
		
		//ans = flag==true? "Yes" : "No";
			
		out.println(sum);
		
	}
	
	
}




Measured memory_bytes: 32384
function main(input) {
    var x = input[0]-0;
    var ans = 1;
    for(var i=2;i<=x;i++){
        for(var j=2;Math.pow(i,j)<=x;j++){
            ans = Math.max(ans,Math.pow(i,j));
        }
    }
    console.log(ans);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8').trim().split("\n"))


Measured memory_bytes: 9420
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

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

    ll n, a, b;
    cin >> n >> a >> b;
    vll x(n), d(n - 1);
    REP(i, n) cin >> x[i];
    REP(i, n - 1) d[i] = x[i + 1] - x[i];
    
    ll res = 0;
    REP(i, n - 1){
        res += min(a * d[i], b);
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 1792
//InTheNameOfGod
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define rep(i,j,k) for(int i=j;i<k;++i)
#define rrep(i,j,k) for(int i=j;i>=k;i--)
#define pb push_back
#define lb(i) i&(-i);
template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
const int maxn =1;
ll a,b,c,k;
int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);
    cin>>a>>b>>c>>k;
    a-=b;
    if(k%2)a*=-1;
    cout<<a;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

#define N 100

int main(){
  int i,j,A[N];
  int length;  //データの長さ
  int key;

  scanf("%d",&length);
  
  for(i = 0;i < length;i++){   //入力
    scanf("%d",&A[i]);
   
  }
  
  for(j = 0;j <= length-1;j++){
    key = A[j];
    i = j - 1;
    while(i >= 0 && A[i] > key){
      A[i+1]=A[i];
      i = i- 1;
      A[i+1] = key;
    }
    
    for(i = 0;i < length-1;i++){   //表示
      printf("%d ",A[i]);
    }
    printf("%d",A[i]);
    printf("\n");
  }
  return 0;
}

Measured memory_bytes: 604
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

vector<int>edge[100005];
int n;
int dp[2][100005];
int lim;
P solve2(vector<int>&v){
	//v is sorted
	int sz = v.size();
	//check if perfect-matching exists
	if(sz%2 == 0){
		rep(i,sz/2){
			if(v[i]+v[sz-1-i] > lim) goto nxt;
		}
		return mp(sz/2,0);
	}
	nxt:;
	
	int lb = 0, ub = sz/2+1;
	while(ub-lb > 1){
		int mid = (lb+ub)/2;
		rep(i,mid){
			if(v[i]+v[2*mid-1-i] > lim){
				goto fail;
			}
		}
		lb = mid; continue;
		fail:; ub = mid;
	}
	int max_match = lb;
	
	lb = -1, ub = v.size()-1;
	while(ub-lb > 1){
		int mid = (lb+ub)/2;
		if(0 <= mid && mid <= 2*max_match-1){
			int L = 0, R = 2*max_match;
			rep(a,max_match){
				if(L == mid) L++;
				if(R == mid) R--;
				assert(L < R);
				if(v[L]+v[R] > lim) goto bad;
				L++; R--;
			}
			ub = mid; continue;
			bad:; lb = mid;
		}
		else{
			ub = mid; continue;
		}
	}
	return mp(sz-max_match-1, v[ub]);
}
void dfs(int v,int u){
	bool ex = 0;
	rep(i,edge[v].size()){
		int to = edge[v][i];
		if(to == u) continue;
		ex = 1; dfs(to,v);
	}
	if(!ex){
		dp[0][v] = 0;
		dp[1][v] = 0;
		return;
	}
	int ans = 0;
	vector<int>path;
	rep(i,edge[v].size()){
		int to = edge[v][i];
		if(to == u) continue;
		if(dp[1][to]+1 > lim){
			//must cut
			ans += dp[0][to]+1;
			path.pb(1);
		}
		else{
			ans += dp[0][to];
			path.pb(dp[1][to]+1);
		}
	}
	sort(path.begin(),path.end());
	P mn = solve2(path);
	ans += mn.fi;
	dp[0][v] = ans;
	dp[1][v] = mn.sc;
}
int solve(int M){
	lim = M;
	dfs(1,-1);
	int ret = dp[0][1];
	if(dp[1][1] > 0) ret++;
	return ret;
}
int main(){
	scanf("%d",&n);
	rep(i,n-1){
		int a,b; scanf("%d%d",&a,&b);
		edge[a].pb(b);
		edge[b].pb(a);
	}
	int ans = solve(INF);
	int lb = 0, ub = n;
	while(ub-lb > 1){
		int mid = (lb+ub)/2;
		if(solve(mid) == ans) ub = mid;
		else lb = mid;
	}
	cout << ans << " " << ub << endl;
	return 0;
}

Measured memory_bytes: 17152
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}

fn main(){
    let nk:Vec<usize> = read_vec();
    let S: String = read();

    let mut cs: Vec<char> = S.chars().collect();
    cs[nk[1] - 1] = (cs[nk[1] - 1] as u8 + 0x20) as char;
    for c in cs {
        print!("{}", c);
    }
    println!();
}


Measured memory_bytes: 4352
def main():
    N = int(input())

    cnt = [0]*5
    for i in range(N):
        S = input()
        if S[0] == 'M':
            cnt[0] += 1
        if S[0] == 'A':
            cnt[1] += 1
        if S[0] == 'R':
            cnt[2] += 1
        if S[0] == 'C':
            cnt[3] += 1
        if S[0] == 'H':
            cnt[4] += 1

    ans = 0
    for i in range(3):
        for j in range(i+1, 4):
            for k in range(j+1, 5):
                ans += cnt[i] * cnt[j] * cnt[k]

    print(ans)


main()


Measured memory_bytes: 3064
#include<cstdio>
#include<iostream>
#include<queue>
#include<algorithm>
#include<cstring>
#include<cctype>
#include<vector>
#include<ctime>
#include<cmath>
#define LL long long
#define pii pair<int,int>
#define mk make_pair
#define fi first
#define se second
using namespace std;
const LL mod = 1e9 + 7;
const int N = 2e3 + 3;
inline int read(){
	int v = 0,c = 1;char ch = getchar();
	while(!isdigit(ch)){
		if(ch == '-') c = -1;
		ch = getchar();
	}
	while(isdigit(ch)){
		v = v * 10 + ch - 48;
		ch = getchar();
	}
	return v * c;
}
int n,k;
int a[N];
int pos[N];
int sum[N];
int main(){
	LL ans = 0;
	n = read();k = read();
	for(int i = 1;i <= n;++i) a[i] = read();
	for(int i = 1;i <= n;++i)
		for(int j = i + 1;j <= n;++j)
			if(a[j] < a[i]) pos[i]++;
	for(int i = 1;i <= n;++i)
		for(int j = 1;j <= n;++j)
			sum[i] += (a[i] > a[j]);
	for(int i = 1;i <= n;++i){
		ans = (ans + 1ll * k * pos[i] % mod + 1ll * (k - 1) * k / 2 % mod * sum[i] % mod) % mod;	
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define vll vector<ll>
#define pll pair<ll,ll>
#define forA(i,a,n,x) for(ll i=a;i<n;i+=x)
#define forD(i,a,n,x) for(auto i=n-1;i>=0;i-=x)
#define ranit(it,n) for(auto it:n)
#define testCases ll t;cin>>t;while(t--)
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define mod 1000000007
#define init(a,x) memset(a,x,sizeof(a))

int main()
{
	ios_base::sync_with_stdio(false);	cin.tie(NULL);	cout.tie(NULL);
	bool ans= false;
	ll n; cin>>n; ll c=0;
	vector<pll > v(n);
	forA(i,0,n,1)
	{
		cin>>v[i].F>>v[i].S;
	}
//Di,1=Di,2,                Di+1,1=Di+1,2           and Di+2,1=Di+2,2 hold.
	forA(i,0,n-2,1)
	{
		if(v[i].F == v[i].S && v[i+1].F==v[i+1].S && v[i+2].F==v[i+2].S)c++;
	}

	if(c>0)cout<<"Yes";
	else cout<<"No";

	return 0;
}

Measured memory_bytes: 3600
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <iterator>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <regex>
using namespace std;
using pii  = pair<int,int>;
using ll=long long;
using ld=long double;
#define pb push_back
#define mp make_pair
#define sc second
#define fr first
#define stpr setprecision
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,n) for(ll i=0;i<(n);++i)
#define Rep(i,a,b) for(ll i=(a);i<(b);++i)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define rRep(i,a,b) for(int i=a;i>=b;i--)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define ALL(x) (x).begin(),(x).end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define endl '\n'
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
ll gcd(ll a,ll b){return (b == 0 ? a : gcd(b, a%b));}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll MOD=1000000007;
constexpr ll INF=1000000011;
constexpr ll MOD2=998244353;
constexpr ll LINF = 1001002003004005006ll;
constexpr ld EPS=10e-8;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<typename T> istream& operator>>(istream& is,vector<T>& v){for(auto&& x:v)is >> x;return is;}
template<typename T,typename U> istream& operator>>(istream& is, pair<T,U>& p){ is >> p.first; is >> p.second; return is;}
template<typename T,typename U> ostream& operator>>(ostream& os, const pair<T,U>& p){ os << p.first << ' ' << p.second; return os;}
template<class T> ostream& operator<<(ostream& os, vector<T>& v){
  for(auto i=begin(v); i != end(v); ++i){
    if(i !=begin(v)) os << ' ';
    os << *i;
  }
  return os;
}

int main(){
  string S;
  cin >> S;
  cout << (S.substr(0,4)=="YAKI" ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
	int n, a[100];
	cin >> n;
	int A = 0, B = 0;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	sort(a, a + n);
	for (int i = n - 1; i >= 0; i -= 2) {
		A += a[i];
	}
	for (int i = n - 2; i >= 0; i -= 2) {
		B += a[i];
	}
	cout << abs(A - B) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int  long long 
#define speedrap ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int be(int a,int b,int mod) {if(b == 0) return 1; if(b%2 == 1) return (a*be(a,b-1,mod))%mod; else return (be(a,b/2,mod)*be(a,b/2,mod))%mod;}
const int mod = 1e9 + 7;
#define PI 3.14159265359
#define pf push_front
#define pb push_back
#define bitcount __builtin_popcount
#define sc(a) scanf("%d", &a);
#define sz(s) (int)s.size()
#define eb emplace_back
#define pf push_front
#define mkp(x,y) make_pair(x,y)
#define all(x) x.begin(),x.end()
#define INF 0x3f3f3f3f
const int siz = 2*(1e6 + 10);
const int logi = 21;
const double epsilon = 1e-6;
int prime[siz];
int has[siz];
bool cmp(const int &a,const int &b)
{
  return (abs(a-b)>1);
}


signed main()
{
	#ifndef ONLINE_JUDGE
 	freopen("in.txt", "r", stdin);
 	freopen("out.txt", "w", stdout);
 	#else
// // online submission
 	#endif 
	speedrap
	int t;
	t = 1;
	//cin>>t;
	while(t--)
	{	
	int k,a,b;
	cin>>k>>a>>b;

	int flag = 0;
	for(int i = 0 ; i <= 1000 ; i+= k)
	{
		if(i >= a and  i <= b)
		{
			flag = 1; 
		}
	}

	if(flag == 1)
	{
		cout<<"OK";
	}
	else
	{
		cout<<"NG";
	}
	}
}


Measured memory_bytes: 3640
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cassert>
#include <cstdint>
#include <cctype>
#include <numeric>
#include <bitset>
#include <functional>

using namespace std;

using ll =  long long;
using Pll = pair<ll, ll>;
using Pii = pair<int, int>;

constexpr int INF = 1 << 30;
constexpr ll LINF = 1LL << 60;
constexpr ll MOD = 1000000007;
constexpr long double EPS = 1e-10;
constexpr int dyx[4][2] = {
    { 0, 1}, {-1, 0}, {0,-1}, {1, 0}
};

ll modpow(ll a, ll t) {
    ll ret = 1LL;
    while(t){
        if(t & 1LL){
            ret *= a;
            ret %= MOD;
        }
        a *= a;
        a %= MOD;
        t >>= 1;
    }
    return ret;
}

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    ll n;
    cin >> n;

    ll ans = (modpow(9LL, n) + modpow(9LL, n)) % MOD;
    ans += (MOD - modpow(8LL, n)) % MOD;
    ans %= MOD;
    ans = (modpow(10LL, n) + MOD - ans) % MOD;
    ans %= MOD;

    cout << ans << endl;
}


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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))
#define sz(v) ((int) v.size())

using namespace std;

using i64 = long long;
using f80 = long double;
using vi32 = vector<int>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << endl; exit(0); }
inline void no() { cout << "No" << endl; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); return a / gcd(a, b) * b; }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { x = max(x, y); }
template <typename T> inline void amin(T &x, T y) { x = min(x, y); }
template <typename T> inline T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }

void solve() {
  i64 x;
  cin >> x;
  for (i64 b = -1000; b <= 1000; b++) {
    i64 w = x + exp(b, 5);
    bool sign = w >= 0;
    if (w < 0) w *= -1;
    i64 a = 0;
    while (exp(a, 5) < w) a += 1;
    if (exp(a, 5) == w) {
      cout << (sign ? a : -a) << " " << b << endl;
      return;
    }
  }
}


Measured memory_bytes: 3644
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <cstring>
#include <cstdlib>
using namespace std;

#define REP(i,n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> pint;
template <class T> inline void chmax(T &a, const T b) { a = max(a, b); }
template <class T> inline void chmin(T &a, const T b) { a = min(a, b); }
template <class T> void pp(T v, int n) { REP(i,n) cout<<v[i]<< ' '; cout << endl; }

void inline TorF(bool tf, const string &trueMessage, const string &falseMessage) {
  cout << (tf ? trueMessage : falseMessage) << endl;
}
void inline YESNO(bool tf) { TorF(tf, "YES", "NO"); }
void inline YesNo(bool tf) { TorF(tf, "Yes", "No"); }

int H, W;
bool f(  vector<vector<bool> > a, int hmask, int wmask, int K) {
  REP(h, H) {
    if((hmask >> h) & 1) {
      REP(w, W) a[h][w] = false;
    }
  }
  REP(w, W) {
    if((wmask >> w) & 1) {
      REP(h, H) a[h][w] = false;
    }
  }
  int cnt = 0;
  REP(h,H) REP(w,W) {
    if(a[h][w]) cnt++;
  }
  return cnt == K;
}

int main() {
  vector<vector<bool> > a;
  int K; cin>>H>>W>>K;
  a = vector<vector<bool> > (H, vector<bool>(W, false));
  REP(h,H) {
    string line ; cin>>line;
    REP(w,W) {
      if(line[w] == '#') a[h][w] = true;
    }
  }
  int ans = 0;
  REP(h, 1<<H) {
    REP(w, 1<<W) {
      bool ret = f(a, h, w, K);
      if(ret) ans++;
    }
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 3196
#include<bits/stdc++.h>
using namespace std;
#define pb push_back 
#define in long long
#define inf INT_MAX
#define ninf INT_MIN
#define M 1000000007

int main()
{
   in n,k; cin>>n>>k;
   in y=n%k;
   in mn=min(y,k-y);
   cout<<mn;
   
   return 0;
   
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;
/*
 * 	Heart beats fast
 * 		Colors and promises
 * 			How to be brave
 * 				How can I love when I am afraid to fall...
 */
public class Main
{
	static final long mod=1000000007;
	static final double eps=1e-8;
	static final boolean debug=false;
	static Reader in=new Reader();
	public static void main(String[] args) throws IOException
	{
		Map<String, Integer> a=new HashMap<String, Integer>();
		Set<String> b=new HashSet<String>();
		int n=ni();
		String te;
		for(int i=0; i<n; i++)
		{	
			te=ns();
			b.add(te);
			a.put(te, a.getOrDefault(te, 0)+1);
		}
		int m=ni();
		for(int i=0; i<m; i++)
		{	
			te=ns();
			b.add(te);
			a.put(te, a.getOrDefault(te, 0)-1);
		}
		Iterator<String> itr=b.iterator();
		int an=0;
		while(itr.hasNext())
		{
			te=itr.next();
			an=Math.max(an, a.get(te));
		}
		pr(an);
		System.out.println(ans);
	}
	static StringBuilder ans=new StringBuilder();
	static long powm(long a, long b, long m)
	{
		long an=1;
		long c=a;
		while(b>0)
		{
			if(b%2==1)
				an=(an*c)%m;
			c=(c*c)%m;
			b>>=1;
		}
		return an;
	}
	static void pd(){if(debug)ans.append("hola");}
	static void pd(Object a){if(debug)ans.append(a+"\n");}
	static void pr(Object a){ans.append(a+"\n");}
	static void pr(){ans.append("\n");}
	static void p(Object a){ans.append(a);}
	static int ni(){return in.nextInt();}
	static long nl(){return in.nextLong();}
	static String ns(){return in.next();}
	static double nd(){return in.nextDouble();}
	static String pr(String a, long b)
	{
		String c="";
		while(b>0)
		{
			if(b%2==1)
				c=c.concat(a);
			a=a.concat(a);
			b>>=1;
		}
		return c;
	}
	static class Reader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;
        public Reader() {
            reader = new BufferedReader(new InputStreamReader(System.in), 32768);
            tokenizer = null;
        }
        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }
        public int nextInt() {
            return Integer.parseInt(next());
        }
        public long nextLong() {
        	return Long.parseLong(next());
        }
        public double nextDouble() {
        	return Double.parseDouble(next());
        }
    }
}

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

const int N = 55, MOD = 1e9+7;
int n, base[N][N];
long long k;

//MATRIX EXPONENTIATION
void mat_mult (int dest[][N], int mat1[][N], int mat2[][N]) {
  int ans[N][N];
  memset(ans, 0, sizeof(ans));
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++)
      for (int k = 0; k < n; k++)
        ans[i][j] = (ans[i][j] + 1LL * mat1[i][k] * mat2[k][j])%MOD;
  memcpy(dest, ans, sizeof(ans));
}
void mat_exp (int base[][N], long long exp) {
  if (exp == 1) return;
  int ans[N][N];
  memcpy(ans, base, sizeof(ans));
  mat_exp(ans, exp/2);
  mat_mult(ans, ans, ans);
  if (exp&1)
    mat_mult(ans, ans, base);
  memcpy(base, ans, sizeof(ans));
}
//END MATRIX EXPONENTIATION

void add_self(int& a, int b) {
  a += b;
  if (a >= MOD)
    a -= MOD;
}

int32_t main() {
  scanf("%d%lld", &n, &k);

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

  mat_exp(base, k);

  int ans = 0;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++)
      add_self(ans, base[i][j]);

  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 1024
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
using System.Numerics;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            Solve();
            //Out.Flush();
            Read();
        }

        static void Solve()
        {
            var n = Sarray()[0];
            var ai = Sarray();
            Array.Sort(ai);
            var max = ai.Max();
            var mid = (max + 1) / 2;
            var dif = long.MaxValue;
            var r = max;
            foreach (var a in ai)
            {
                var d = Abs(a - mid);
                if (d < dif)
                {
                    r = a;
                    dif = d;
                }
            }
            WriteLine($"{max} {r}");
        }

        static long Mod = 998244353;
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static public (T1 a, T2 b) Slice<T1, T2>()
        {
            var t = ReadLine().Split();
            return (
            (T1)Convert.ChangeType(t[0], typeof(T1)),
            (T2)Convert.ChangeType(t[1], typeof(T2)));
        }
        static public (T a, T b) Slice2<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)));
        }
        static public (T a, T b, T c) Slice3<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)),
            (T)Convert.ChangeType(t[2], typeof(T)));
        }
    }
}

Measured memory_bytes: 38532
n, a, b = [int(x) for x in input().split(' ')]
dis = [a*int(x) for x in input().split(' ')]
dist = [dis[x+1] - dis[x] for x in range(n-1)]
out = 0
for j in dist:
    if j > b:
        out += b
    else:
        out += j
print(out)


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

#define pb push_back
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define ll long long
 
const int N=1e5+5,MAX=3e7,MOD=1e9+7;
 
using namespace std;

int n;
int main()
{	
	
 	
    	scanf("%d",&n);
    	std::vector<int> a(n);
    	for(int i=0;i<n;i++)scanf("%d",&a[i]);

    	int sum=0,ans=1e9;

    	for(int i=0;i<n;i++){
    		sum+=a[i];
    		int othersum= 0;
    		for(int j=i+1;j<n;j++)othersum+=a[j];
    		ans=min(ans,abs(othersum-sum));
    	}

    	printf("%d\n",ans );
}

Measured memory_bytes: 256
import queue

n, m = map(int, input().split())
cave = [[] for i in range(n+1)]
for i in range(m):
    a, b = map(int, input().split())
    cave[a].append(b)
    cave[b].append(a)

q = queue.Queue()
q.put(1)
shirube = [0] * (n+1)
shirube[1] = 1

while not q.empty():
    v = q.get()
    for i in cave[v]:
        if shirube[i] == 0:
            shirube[i] = v
            q.put(i)

cnt = 0
for i in range(2, n+1):
    if shirube[i] == 0:
        cnt += 1
if cnt > 0:
    print("No")
else:
    print("Yes")
    for i in range(2, n+1):
        print(shirube[i])


Measured memory_bytes: 34436
"""
int(input())
map(int, input().split())
list(map(int, input().split()))
input()
input().split()
"""


n=int(input())

s=str(n)

cnt=0
for i in range(len(s)):
    tmp=int(s[i])
    cnt+=tmp

if (cnt%9==0):print("Yes")
else: print("No")

Measured memory_bytes: 9144
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm> 
#include<stack>
using namespace std;
char s[600005],c,s1[600005];
int main()
{
	long long f,q,t,zhuan=0,l,r,i;
	cin>>s1;
	for(i=0;i<strlen(s1);i++)
	{
		s[i+250000]=s1[i];
	}
	l=250000;
	r=l+strlen(s1)-1;
	cin>>q;
	while(q--)
	{
		cin>>t;
		if(t==1)
		{
			zhuan++;
		}
		if(t==2)
		{
			cin>>f;
			if(f==1)
			{
				cin>>c;
				if(zhuan%2==0)
				{
					l--;
					s[l]=c;
				}
				if(zhuan%2==1)
				{
					r++;
					s[r]=c;
				}
			}
			if(f==2)
			{
				cin>>c;
				if(zhuan%2==0)
				{
					r++;
					s[r]=c;
				}
				if(zhuan%2==1)
				{
					l--;
					s[l]=c;
				}
			}
		}
	}
	if(zhuan%2==0)
	{
		for(i=l;i<=r;i++)
			cout<<s[i];
	}
	else
	{
		for(i=r;i>=l;i--)
			cout<<s[i];
	}
}

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

typedef long long ll;
typedef long double ld;

#define pb push_back
#define sort(s) sort(s.begin(),s.end())
#define reverse(s) reverse(s.begin(),s.end())
#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++)

const ll mod = 1e9+7;

//最大公約数
ll gcd(ll a, ll b) {
    return b ? gcd(b, a%b) : a;
}

//最小公倍数
ll lcm(ll a, ll b) {
    return a / gcd(a, b) * b;
}

//素数判定
bool isPrime(ll x){
    ll i;
    if(x < 2)return 0;
    else if(x == 2) return 1;
    if(x%2 == 0) return 0;
    for(i = 3; i*i <= x; i += 2) if(x%i == 0) return 0;
    return 1;
}

//桁和
int digsum(ll n) {
    int res = 0;
    while(n > 0) {
        res += n%10;
        n /= 10;
    }
    return res;
}

//桁数
int dignum(ll n) {
    int res = 0;
    while(n > 0) {
        res++;
        n /= 10;
    }
    return res;
}

//文字列中の特定の文字カウント
ll stringcount(string s,char c){
    return count(s.cbegin(),s.cend(),c);
}

//階乗
ll ka(ll i){
    ll res=1;
    while(i>0){
        res=res*i;
        i--;
    }
    return res;
}
 
//ncr
ll ncr(ll x,ll y){
    ll a = x;
    ll b = 1;
    if(y>(x/2)){
        y=x-y;
    }
    for(ll i=1;i<y;i++){
        a*=x-i;
        b*=i+1;
    }
    return a/b;
}

//フィボナッチ数列
ll f(ll x){
    ll dp[x+1];
    dp[1]=1;
    dp[2]=1;
    for(ll i=3;i<=x;i++){
        dp[i]=dp[i-1]+dp[i-2];
    }
    return dp[x];
}

//char->int
int ctoi(char c){
    return c-'0';
}



int main(){
    int h,w;
    cin >> h >> w;

    char c[h][w];

    rep(i,h){
        rep(j,w){
            cin >> c[i][j];
        }
    }

    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cout << c[i][j];
        }
        cout << endl;
        for(int j=0;j<w;j++){
            cout << c[i][j];
        }
        cout << endl;
    }
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N = INT()
B = LIST()

A = []
A.append(B[0])
for i in range(1, N-1):
    A.append(min(B[i-1], B[i]))
A.append(B[-1])

print(sum(A))


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const int maxV = 90010;

 
const int maxN = 1e5+10;

const int INF = 1e9+6;
const int MOD = 1e9+7;


int n,k;
int a[maxN];
int main() {
	scanf("%d%d",&n,&k);
	int ans = 0;
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		if(a[i] >= k)
		{
			ans++;
		}
	}
	cout<<ans<<endl; 
    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int maxn=1000;
int main()
{
    char str[1000];
    scanf("%s",str);
    if(str[0]=='S'){
        printf("Cloudy\n");
    }
    else if(str[0]=='C'){
        printf("Rainy\n");
    }
    else if(str[0]=='R'){
        printf("Sunny\n");
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <list>
#include <deque>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;
#define dump(a) cout << (a) << endl;
typedef long long ll;
ll mod = 1e9+7;

int main() {
    string s;
    cin >> s;
    ll l = s.size()-1;
    ll cnt = 0;
    for (int i = l; i >= 0; i--) {
        if (s[i] == 'B') {
            cnt += (l-i);
            l--;
        }
    }
    dump(cnt);
    return 0;  
}

Measured memory_bytes: 640
#include <iostream>
#include <cmath>
using namespace std;

int main()
{
    int a,b,c,d,e,f;
    while(cin >> a >> b >> c >> d >> e >> f) {
        int det = a*e - d*b;
        double x = floor(((double)(c*e - b*f) / det) * 1000 + 0.5) / 1000;
        double y = floor(((double)(a*f - c*d) / det) * 1000 + 0.5) / 1000;
        printf("%.3lf %.3lf\n", x, y);
        
    }
}

Measured memory_bytes: 0
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<stdlib.h>
#define nil -1
int d[100005];
int h[100005];
struct shu{
int left;
int right;
int parent;
};
int zuida(int a,int b){
if(a>b)return a;
else return b;
}
shu a[100005];
int xiongdi(int u){
if(a[u].parent==nil) return nil;
else if(a[ a[u].parent ].left!=u&&a[a[u].parent].left!=nil)return a[a[u].parent].left;
else if(a[ a[u].parent ].right!=u&&a[a[u].parent].right!=nil)return a[a[u].parent].right;
else return nil;
}
int gao(int u){
int h1=0,h2=0;
if(a[u].right!=nil)h1=gao(a[u].right)+1;
if(a[u].left!=nil)h2=gao(a[u].left)+1;
return h[u]=zuida(h1,h2);
}
void shendu(int u,int p){
d[u]=p;
if(a[u].right!=nil)shendu(a[u].right,p+1);
if(a[u].left!=nil)shendu(a[u].left,p+1);
}
void shuchu(int u){
printf("node %d: ",u);
printf("parent = %d, ",a[u].parent);
printf("sibling = %d, ",xiongdi(u));
int x=0;
if(a[u].left!=nil)x++;
if(a[u].right!=nil)x++;
printf("degree = %d, ",x);
printf("depth = %d, ",d[u]);
printf("height = %d, ",h[u]);
if(a[u].parent==nil)printf("root");
else if(a[u].left==nil&&a[u].right==nil)printf("leaf");
else printf("internal node");
}

int main(){
int n;
scanf("%d",&n);
int k,m,l,p;
for(int i=0;i<n;i++){
    a[i].parent=nil;
}
for(int i=0;i<n;i++){
    scanf("%d%d%d",&k,&m,&l);
    a[k].left=m;
    a[k].right=l;
    if(m!=nil)a[m].parent=k;
    if(l!=nil)a[l].parent=k;
}
int x;
for(int i=0;i<n;i++){
    if(a[i].parent==nil){
        x=i;
        break;
    }
}
shendu(x,0);
gao(x);
for(int i=0;i<n;i++){
    shuchu(i);
    printf("\n");
}
return 0;
}

Measured memory_bytes: 2616
from collections import Counter

def main():
    n, k = map(int, input().split())
    r, s, p = map(int, input().split())
    T = list(input())
    l = list()
    ans = 0
    for i in range(k):
        l.append(T[i])
    for i in range(k, n):
        if l[i-k] == T[i]:
            l.append(None)
        else:
            l.append(T[i])
    res = Counter(l)
    ans = res['r'] * p + res['s'] * r + res['p'] * s
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 10864
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		char[] str = sc.next().toCharArray();

		int alpha[][] = new int[n][26];

		for(int i = n - 2; i >= 0; i--){
			for(int j = 0; j < 26; j++){
				alpha[i][j] = alpha[i + 1][j];
			}

			alpha[i][str[i + 1] - 'a']++;
		}

		//debug
//		for(int i = 0; i < 26; i++){
//			for(int j = 0; j < n; j++){
//				System.out.print(alpha[j][i]+" ");
//			}
//			System.out.println();
//		}

		long result = 0;
		int mod = 1_000_000_007;
		for(int i = 0; i < n; i++){
			long tmp = 1;

			for(int j = 0; j < 26; j++){
				if(alpha[i][j] == 0 || j == str[i] - 'a'){
					continue;
				}

				tmp *= (alpha[i][j] + 1);
				tmp %= mod;
			}

			result += tmp;
			result %= mod;
		}

		System.out.println(result);
	}
}


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

using ll = long long;
#define REP(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}

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

  ll ans = 1;
  ll INF = pow(10, 9) + 7;
  REP(i, N) {
    ans = ans * (i + 1);
    ans = ans % INF;
  }

  cout << ans << endl;
}

Measured memory_bytes: 256