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

using namespace std;

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

const char sp = ' ';
const char cmm = ',';
const int MOD = 1000000007;

using ll = long long;

ll mod(ll a, ll b){return (a%b+b)%b;}
ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void Judge(bool b){b?Yes():No();}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void JUDGE(bool b){b?YES():NO();}
ll powMod(ll b, ll e, ll m){ll r=1;while(e>0){if(e&1)r=(r%m)*(b%m)%m;b=(b%m)*(b%m)%m;e>>=1;}return r;}
double distance(ll x1, ll y1, ll x2, ll y2){return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));}

template<typename T>
void ppp(T n){cout << n << endl;}

int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);

    ll n, m;
    cin >> n >> m;
    ll money = 0;
    ll num = 0;
    vector<pair<ll, ll>> ab(n);
    rep(i, n){
        ll a, b;
        cin >> a >> b;
        ab[i] = make_pair(a, b);
    }
    sort(ab.begin(), ab.end());

    rep(i, n){
        if((ab[i].second)+num <= m){
            num += ab[i].second;
            money += (ab[i].first) * (ab[i].second);
        }
        else{
            money += (ab[i].first)*(m-num);
            break;
        }
    }
    ppp(money);

    return 0;
}


Measured memory_bytes: 1792
x=int(input())
l=[2]
for i in range(3,round((2*x)**0.5)):
  for j in range(len(l)):
    if i%l[j]==0:
      break
    if j==len(l)-1:
      l.append(i)
def pri(x,l):
  for i in range(len(l)):
    if x%l[i]==0 and x>l[i]:
      return 0
    if i==len(l)-1:
      return 1

while pri(x,l)==0:
  x+=1
print(x)

Measured memory_bytes: 3064
n = int(input())
arr = input().split()
arr = list(map(int, arr))

arr = [arr[0]] + arr
dp = [0]*len(arr)
dp[0] = 0
dp[1] = 0

for i in range(2, n+1):
    dp[i] = min(dp[i-2]+ abs(arr[i] - arr[i-2]), dp[i-1] + abs(arr[i] - arr[i-1]))
    
print(dp[n])


Measured memory_bytes: 13980
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
using P = pair<int, int>;
struct BIT{
    typedef long long ll;
    int size;
    vector<ll> bit;
    function<ll(ll, ll)> f = [](ll a, ll b){ return a+b; };
    BIT(int n){
        size = n;
        bit.assign(size+1, 0);
    }
    BIT(int n, ll ide, function<ll(ll, ll)> g){
        size = n;
        bit.assign(size+1, ide);
        f = g;
    }

    ll sum(int x){
        ll res = bit[0];
        while(x > 0){
            res = f(res, bit[x]);
            x -= (x & -x);
        }
        return res;
    }

    void add(int x, ll y){
        while(x <= size){
            bit[x] = f(bit[x], y);
            x += (x & -x);
        }
    }
};
int main(void){
    int n, q;
    cin >> n >> q;
    vector< int > c(n+1), l(q+1), r(q+1), ans(q+1, 0);
    vector< P > p;
    for(int i=1;i<=n;i++) cin >> c[i];
    for(int i=1;i<=q;i++) cin >> l[i] >> r[i];
    p.push_back(P(-1, 0));
    for(int i=1;i<=q;i++){
        p.push_back(P(r[i], i));
    }
    sort(p.begin(), p.end());
    vector< int > lp(n+1, -1);
    int pi = 1;
    BIT bit(n+2);
    for(int i=1;i<=n;i++){
        if(lp[c[i]] != -1){
            bit.add(lp[c[i]], -1);
        }
        lp[c[i]] = i;
        bit.add(i, 1);
        while(pi <= q && p[pi].first == i){
            int j = p[pi].second;
            ans[j] = bit.sum(i) - bit.sum(l[j]-1);
            pi++;
            // cout << j << " " << i << " " << ans[j] << endl;
        }
    }



    for(int i=1;i<=q;i++) cout << ans[i] << endl;

}


Measured memory_bytes: 21372
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <array>
#include <algorithm>
#include <utility>
#include <numeric>


using namespace std;


template <class ...Args>
void Input(Args &...args)
{
	(cin >> ... >> args);
}

template <class T>
void InputArray(std::size_t size, T &t)
{
	t.resize(size);
	for (auto &e : t) {
		cin >> e;
	}
}

template <class ...Args>
void InputArray(std::size_t size, Args &...args)
{
	(InputArray(size, args), ...);
}

template <class ...Args>
void InputVerticalArray(std::size_t size, Args &...args)
{
	(args.resize(size), ...);
	for (int i = 0; i < size; i++) {
		((cin >> args[i]), ...);
	}
}

template <class ...Args>
void Output(const Args &...args)
{
	((cout << args << ' '), ...) << endl;
}

template <class ...Args>
void OutputVertical(const Args &...args)
{
	((cout << args << endl), ...);
}

template <class T>
void OutputArray(const T &t)
{
	for (const auto &e : t) {
		cout << e << ' ';
	}
	cout << endl;
}

template <class ...Args>
void OutputArray(const Args &...args)
{
	(OutputArray(args), ...);
}

template <class ...Args>
void OutputVerticalArray(const Args &...args)
{
	for (int i = 0; i < min({ args.size()... }); i++) {
		((cout << args[i] << ' '), ...) << endl;
	}
}


#define inp(type, ...) \
	type __VA_ARGS__; \
	Input(__VA_ARGS__)

#define inpa(type, size, ...) \
	type __VA_ARGS__; \
	InputArray((size), __VA_ARGS__)

#define inpva(type, size, ...) \
	type __VA_ARGS__; \
	InputVerticalArray((size), __VA_ARGS__)

#define otp(...) \
	Output(__VA_ARGS__)

#define otpv(...) \
	OutputVertical(__VA_ARGS__)

#define otpa(...) \
	OutputArray(__VA_ARGS__)

#define otpva(...) \
	OutputVerticalArray(__VA_ARGS__)

#define rep(counter, range) \
	for (int (counter) = 0; (counter) < (range); (counter)++)

#define repi(range) \
	rep(i, range)

#define rrep(counter, range) \
	for (int (counter) = (range) - 1; (counter) >= 0; (counter)--)

#define rrepi(range) \
	rrep(i, range)

#define repc(element, container) \
	for (auto &(element) : (container))

#define repe(container) \
	repc(e, container)

#define all(container) \
	(container).begin(), (container).end()

#ifdef __CCR__
#	define dlog(x) clog << #x " = " << x << endl
#else
#	define dlog(x)
#endif



int main()
{
	inp(int, s);
	
	if (s < 3) {
		otp(0);
		return 0;
	}
	if (s < 6) {
		otp(1);
		return 0;
	}
	constexpr long long mod = 1000000007;
	long long result = 1;
	vector<long long> a(s - 5, 1);
	long long sum;
	int i;
	for (i = 5; i < s; i += 3) {
		sum = 0;
		rep(j, s - i) {
			sum += a[j];
			a[j] = sum % mod;
		}
		result += sum;
		result %= mod;
	}
	
	otp(result);
	
	return 0;
}


Measured memory_bytes: 3596
#include <iostream>
#include <vector>
#include <unordered_map>
#include <map>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <deque>
#include <cmath>
#include <stack>
#include <queue>
#include <string>
#include <locale>
#include <iomanip>
#include <cstring>

#define nl '\n'

using namespace std;

long long n, a;

int main(){

    set<long long> s;

    cin >> n;

    for(long long i = 0; i < n; i++){
        cin >> a;
        s.insert(a);
    }

    if(s.size() == n){
        cout << "YES";
        return 0;
    }

    cout << "NO";
}

//g++ -std=c++14 comp.cpp -o b; ./b.exe
//g++ -std=c++14 comp.cpp && ./a.out

Measured memory_bytes: 9600
#include <stdio.h>

int main(){
    int a[3], i, max, min;

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

    max = a[0];
    min = a[0];

    for(i=0; i<3; i++){
        if(max < a[i])
            max = a[i];
        
        if(min > a[i])
            min = a[i];
    }

    printf("%d\n", max-min);

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int gcd(int a, int b){
    if(a < b) swap(a,b);
    if(b == 0) return a;
    else return gcd(b, a%b);
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N; cin >> N;
    if(N == 2){
        int a, b;
        cin >> a >> b;
        for(int i = 1; i < max(a,b) + 1; ++i){
            if(a%i == 0 && b%i == 0) cout << i << endl;
        }
    }
    else {
        int a, b , c;
        cin >> a >> b >> c;
        for(int i = 1; i < max(a,max(b,c)) + 1; ++i){
            if(a%i == 0 && b%i == 0 && c%i == 0) cout << i << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3168
/*
    Author: isaf27 (Ivan Safonov)
*/

#pragma GCC optimize("O3")
#include <bits/stdc++.h>

using namespace std;

//defines
typedef long long ll;
typedef double ld;
#define TIME clock() * 1.0 / CLOCKS_PER_SEC

//permanent constants
const ld pi = acos(-1.0);
const int day[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int digarr[10] = {6, 2, 5, 5, 4, 5, 6, 3, 7, 6};
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, 1, 0, -1};
const int dxo[8] = {-1, -1, -1, 0, 1, 1, 1, 0};
const int dyo[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
const int alf = 26;
const int dig = 10;
const int two = 2;
const int th = 3;
const ll prost = 239;
const ll bt = 31;
const ld eps = 1e-8;
const ll INF = 1e18 + 239;
const int BIG = 2e9 + 239;
const int MOD = 1e9 + 7;
const ll MOD2 = (ll)MOD * (ll)MOD;

//random
mt19937_64 rnd(239); //(chrono::high_resolution_clock::now().time_since_epoch().count());

//constants
const int M = 2e5 + 239;
const int N = 2e3 + 239;
const int L = 19;
const int T = (1 << 18);
const int B = trunc(sqrt(M)) + 1;
const int X = 1e4 + 239;
const int A = 26;

int n, a, b;

int getsw(int x, int a, int b)
{
    int t1 = (x >> a) & 1;
    int t2 = (x >> b) & 1;
    x -= (t1 << a);
    x -= (t2 << b);
    x += (t2 << a);
    x += (t1 << b);
    return x;
}

vector<int> func(int n, int x)
{
    if (n == 1)
        return {0, x};
    int t = 0;
    for (int i = 0; i < n; i++)
        if ((x >> i) & 1)
        {
            t = i;
            break;
        }
    int xn = getsw(x, t, n - 1);
    xn ^= (1 << (n - 1));
    vector<int> p1 = func(n - 1, 1);
    vector<int> p2 = func(n - 1, xn ^ 1);
    for (int &u : p2)
        u ^= 1;
    for (int &u : p2)
        u = getsw(u + (1 << (n - 1)), t, n - 1);
    for (int &u : p1)
        u = getsw(u, n - 1, t);
    for (int u : p2)
        p1.push_back(u);
    return p1;
}

int32_t main()
{
    #ifdef ONPC
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n >> a >> b;
    int x = (a ^ b);
    if (__builtin_popcount(x) % 2 == 0)
    {
        cout << "NO\n";
        return 0;
    }
    cout << "YES\n";
    vector<int> p = func(n, x);
    for (int i : p)
        cout << (i ^ a) << " ";
    return 0;
}


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

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

int main() {
  int n;
  cin >> n;
  int ans = 0;
  rep(i, n) {
    int t;
    cin >> t;
    while (t % 2 == 0) {
      t /= 2;
      ans++;
    }
  }
  cout << ans;
}

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

int main(){
	char a[11] = {} , b[11] = {};
	
	scanf("%s",&a);
	scanf("%s",&b);
	
	int i = 0;
	for(i = 0;i < strlen(a);i++){
		if(a[i] != b[i]){
			printf("No\n");
			return 0;
		}
	}
	
	printf("Yes\n");
	
	return 0;
}

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

#define ll long long
#define ld long double
#define db double
#define pb push_back
#define nl '\n'
#define X first
#define Y second
#define nimble ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define all(v) (v).begin(),(v).end()
#define mod(x,m) ((((x)%(m))+(m))%(m))
#define _sz(x) (int)x.size()
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repv(v) for(int i=0;i<_sz(v);i++)
#define rep1(i,b,a) for(int i=b;i>=a;i--)
#define preci(x) fixed<<setprecision(x)
#define tc int tt=1;cin>>tt;while(tt--)

#define TRACE
#ifdef TRACE
#define see(...) __f(#__VA_ARGS__,__VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr<<name<<" : "<<arg1<<nl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma=strchr(names+1,',');cerr.write(names,comma-names)<<" : "<<arg1<<" | ";__f(comma+1, args...);
}
#else
#endif

int inf=0x3f3f3f3f;
ll infl=0x3f3f3f3f3f3f3f3fLL;
ld infd=1.0/0.0;
const ll MOD=1e9+7;// 998244353 // = (119<<23)+1
const ld pi=2*acos(0.0);

int main(){
    nimble
    int n;
    cin>>n;
    vector<ll> a(n);
    int _0=0;
    rep(i,0,n){
        cin>>a[i];
        if(a[i]==0)_0=1;
    }
    if(_0){
        cout<<0;
        return 0;
    }
    ll ss=1;
    ll x=1;
    rep(i,0,n){
        if(x>(ll)1e18/a[i]){
            cout<<-1;
            return 0;
        }
        ss*=a[i];
        x*=a[i];
    }
    cout<<ss;
    return 0;
}



Measured memory_bytes: 3988
import sys
import collections


input = sys.stdin.readline


def main():
    N = int(input())

    C = []

    for i in range(N):
        S = input().strip()
        C.append(collections.Counter(S))

    for i in range(26):
        m = float("inf")
        for j in range(N):
            m = min(m, C[j][chr(ord('a') + i)])

        if m != float("inf"):
            print(chr(ord('a') + i) * m, end="")

    print()
    

if __name__ == '__main__':
    main()



Measured memory_bytes: 3316
using System;
public class c
{
  public static void Main()
  {
    int N=int.Parse(Console.ReadLine());
    int H=int.Parse(Console.ReadLine());
    int W=int.Parse(Console.ReadLine());
    int A=N-H+1;
    int B=N-W+1;
    Console.WriteLine(A*B);
  }
}


Measured memory_bytes: 11092
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

#define a 0
#define c 1
#define g 2
#define t 3

int main(){
	int N,i,j,k,l,m;
	scanf("%d",&N);

	unsigned long long ans,mod=1000000007,memo[101][4][4][4]={0};
	
	for(i=0;i<4;i++){
		for(j=0;j<4;j++){
			for(k=0;k<4;k++){
				memo[3][i][j][k]=1;
			}
		}
	}
	memo[3][a][g][c]=0;
	memo[3][a][c][g]=0;
	memo[3][g][a][c]=0;

	for(i=3;i<N;i++){
		for(j=0;j<4;j++){
			for(k=0;k<4;k++){
				for(l=0;l<4;l++){
					for(m=0;m<4;m++){
						if(k==a && l==g && m==c)continue;
						if(k==a && l==c && m==g)continue;
						if(k==g && l==a && m==c)continue;
						if(j==a && k==g && m==c)continue;
						if(j==a && l==g && m==c)continue;

						memo[i+1][k][l][m]+=memo[i][j][k][l];
						memo[i+1][k][l][m]%=mod;
					}
				}
			}
		}
	}

	for(i=0;i<4;i++){
		for(j=0;j<4;j++){
			for(k=0;k<4;k++){
				ans+=memo[N][i][j][k];
				ans%=mod;
			}
		}
	}

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

Measured memory_bytes: 256
n,M = map(int,input().split())
d = []
for i in range(n):
    a,b = map(int,input().split())
    d.append([a,b])
 
d.sort(key=lambda x:x[0])

sum_ = 0
cnt = 0
for ab in d:
    if cnt + ab[1] > M:
        sum_ += ab[0] * (M-cnt)
        break
    else:
        cnt += ab[1]
        sum_ += ab[0]*ab[1]
print(sum_)


Measured memory_bytes: 25292
//Binary_search:二分探索法に依る検索
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vecll = vector<long long>;
#define all(c) (c).begin(), (c).end()
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)

int main()
{
    ll n, q, k;
    vecll  a;
    cin >> n;
    a.resize(n);

    for(auto &x : a) cin >> x;

    cin >> q;
    rep(i,q)
    {
        cin >> k;
        cout << distance(a.begin(),lower_bound(all(a),k)) << flush;
        cout << " " << flush;
        cout << distance(a.begin(), upper_bound(all(a), k)) << endl;
    }
    return 0;
}


Measured memory_bytes: 3624
fun main(args: Array<String>) {
    var nd = readLine()!!.split("\\s+".toRegex()).map {it.toLong()}
    val numberTests = nd[0]
    val dtmp = nd[1]
    val d = dtmp * dtmp

    var results = mutableListOf<Boolean>()

    for (i in 0..numberTests-1) {
        var xy = readLine()!!.split("\\s+".toRegex()).map {it.toLong()}
        val x = xy[0]
        val y = xy[1]

        val result = experimentB(x, y, d)
        results.add(result)
    }

    val cnt = results.filter {it == true}.size
    println(cnt)
}

fun experimentB(x : Long, y:Long, d: Long) : Boolean {
    return x * x + y * y <= d
}

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

const int mod = 1e9+7;
long long A[100001];

long long pw(int x, int n) {
    long long t=1;
    rep(i,n) t = t*x%mod;
    return t%mod;
}

int main() {
    int N;
    cin >> N;
    rep(i,N) {
        int t; cin >> t; t--;
        A[t]++;
    }


    int cnt=0;
    rep(i,N) {
        if (A[i] > 0 && A[i] != 2) {
            cout << 0 << endl;
            return 0;
        }
        if (A[i] == 2) cnt++;
    }

    cout << pw(2, cnt) << endl;
    return 0;
}


Measured memory_bytes: 1024
n = gets.to_i

s = []
h = []
c = []
d = []

n .times do
    x = gets()
    x = x.split
    if x[0] == "S"
        s[x[1].to_i] = x[1].to_i
    elsif x[0] == "H"
        h[x[1].to_i] = x[1].to_i
    elsif x[0] == "C"
        c[x[1].to_i] = x[1].to_i
    elsif x[0] == "D"
        d[x[1].to_i] = x[1].to_i
    end
end

i = 1
13.times do
unless s.include?(i)
    puts "S" + " " + i.to_s
end
i+=1
end

i = 1
13.times do
unless h.include?(i)
    puts "H" + " " + i.to_s
end
i+=1
end

i = 1
13.times do
unless c.include?(i)
    puts "C" + " " + i.to_s
end
i+=1
end

i = 1
13.times do
unless d.include?(i)
    puts "D" + " " + i.to_s
end
i+=1
end



Measured memory_bytes: 6872
#include<stdio.h>
#include<algorithm>
#include<set>
using namespace std;
long long c[31000];
int d[31000];
int main(){
	int a,b;
	while(scanf("%d%d",&a,&b),a){
		for(int i=0;i<a;i++)scanf("%lld",c+i);
		long long now=0;
		for(int i=0;i<a;i++){
			now+=c[i];
			d[i]=now%b;
		}
		set<int> S;
		S.insert(b);
		int ret=0;
		for(int i=0;i<a;i++){
			int v=*(S.upper_bound(d[i]));
			ret=max(ret,(b+d[i]-v)%b);
			S.insert(d[i]);
		}
		printf("%d\n",ret);
	}
}

Measured memory_bytes: 2556
import java.util.*;
public class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    switch(s){
        case"A":System.out.println("T");break;
        case"T":System.out.println("A");break;
        case"G":System.out.println("C");break;
        case"C":System.out.println("G");break;
    }
  } 
}

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

int main()
{
	int n;
	int i, j = 0;
	int Ocnt = 0;
	int Hcnt = 0;
	char res[10];
	int score[100];

	for(i = 0; i < 100; i++){
		score[i] = 0;
	}

	scanf("%d", &n);
	while(j != n){
		scanf("%s", res);
		if( strcmp(res, "OUT") == 0 ){
			Ocnt++;
		}
		if( strcmp(res, "HIT") == 0 ){
			Hcnt++;
			if(Hcnt == 4){
				score[j]++;
				Hcnt--;
			}
		}
		if( strcmp(res, "HOMERUN") == 0 ){
			score[j] += Hcnt + 1;
			Hcnt = 0;
		}
		if(Ocnt % 3 == 0 && Ocnt != 0){
			j ++;
			Hcnt = 0;
			Ocnt = 0;
		}
	}

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

	return 0;
}

Measured memory_bytes: 0
/// 11:57 AM 03/05/20
/// Author: t_bone_289 (An Immature Programmer.... I'm still developing !!)
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
#define pll pair<ll,ll>
#define fi first
#define se second
#define mp make_pair
#define pb emplace_back
#define endl '\n'
#define M 1000000007
#define error(x) cout << #x << " = " << x << endl;
#define pi 3.14159265358979323846
typedef long long ll;
typedef long double ld;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

template<typename T>
void ContainerError(T &v);

ll powmod(ll base, ll exp, ll MOD);

ll mpow(ll base, ll exp);

ll gcd(ll a, ll b);

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    string s;
    cin >>s;
    if(s=="ARC") {
        cout<<"ABC";
    } else {
        cout << "ARC";
    }
    return 0;
}

template<typename T>
void ContainerError(T &v) {
    cout << "{";
    for (auto &x:v) { cout << x << ','; }
    cout << "}" << endl;
    return;
}

ll powmod(ll base, ll exp, ll MOD) {
    ll res = 1;
    while (exp > 0) {
        if (exp % 2 == 1) res = (res * base) % MOD;
        base = (base * base) % MOD;
        exp /= 2;
    }
    return (res % MOD);
}

ll mpow(ll base, ll exp) {
    ll res = 1;
    while (exp > 0) {
        if (exp % 2 == 1) res = (res * base);
        base = (base * base);
        exp /= 2;
    }
    return (res);
}

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



Measured memory_bytes: 3628
function SumAbs(i, tmp){
  var sum = 0;
  sum  = tmp[i]
  if(i+1<tmp.length){
    sum += tmp[i+1]
  }
  if(i+2<tmp.length){
    sum += tmp[i+2];
  }
  return sum;
}
function Main(input){
  input = input.split("\n");
  inputStr = input[0].split(" ");
  const N = Number.parseInt(inputStr[0]);
  const K = Number.parseInt(inputStr[1]);
  inputStr = input[1].split(" ");
  const S = inputStr[0];
  //文字列Sを重み付けして配列に格納する。Lは正、Rは負とする。
  var tmp = [];
  var lst = S.substr(0,1)
  var cnt = 1;
  for(var i=1 ; i<N ; i++){
    if( S.substr(i,1) != S.substr(i-1,1) ){
      tmp.push(cnt);
      cnt = 0;
    }
    cnt += 1;
  }
  //最後の文字列確認
  if( cnt != 0){
      tmp.push(cnt);
  }
  //本体処理
  var ans = 0;
  var cnt = 0;
  if(tmp.length <= 2){
    ans = N-1;
  } else {
    //左から順にK回反転させるように変更する
    for(var j=0 ; j<K ; j++){
      //配列の置き換え
      tmp.splice(0,3,SumAbs(0,tmp));
    }
    ans = tmp.reduce(function(a, b) {
              return a + b;
    });
    ans -= tmp.length;
  }  
  console.log(ans);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 15156
use std::io::*;
const MOD: usize = 998244353;

fn mod_pow(mut x: usize, mut e: usize, m: usize) -> usize {
    let mut res = 1;
    while e > 0 {
        if e & 1 == 1 {
            res = res * x % m;
        }
        x = x * x % m;
        e >>= 1;
    }
    res
}

mod enumeration {
    pub struct Enumeration {
        fact: Vec<usize>,
        finv: Vec<usize>,
        modulo: usize,
    }
    impl Enumeration {
        pub fn new(n: usize, modulo: usize) -> Enumeration {
            let mut fact: Vec<usize> = vec![1; n];
            let mut inv: Vec<usize> = vec![1; n];
            let mut finv: Vec<usize> = vec![1; n];
            for i in 2..n {
                fact[i] = fact[i - 1] * (i as usize) % modulo;
                inv[i] = modulo - (modulo / (i as usize)) * inv[(modulo as usize % i)] % modulo;
                finv[i] = inv[i] * finv[i - 1] % modulo;
            }
            Enumeration {
                fact: fact,
                finv: finv,
                modulo: modulo,
            }
        }
        pub fn c(&self, n: usize, k: usize) -> usize {
            if n < k {
                return 0;
            }
            self.fact[n] * self.finv[n - k] % self.modulo * self.finv[k] % self.modulo
        }
    }
}

fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let n: usize = itr.next().unwrap().parse().unwrap();
    let m: usize = itr.next().unwrap().parse().unwrap();
    let k: usize = itr.next().unwrap().parse().unwrap();

    let en = enumeration::Enumeration::new(n + 1, MOD);
    let mut ans = 0;
    for i in 0..k + 1 {
        ans = (ans + en.c(n - 1, i) * m % MOD * mod_pow(m - 1, n - (i + 1), MOD) % MOD) % MOD;
    }
    println!("{}", ans);
}


Measured memory_bytes: 6724
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <list>
#include <map>

#define min_3(a, b, c) min(a, min(b, c))

typedef long long ll;
using namespace std;

int main()
{
    string sa, sb, sc;
    cin >> sa >> sb >> sc;

    char s = sa.front();
    sa.erase(sa.begin());

    while(true){
        if (s == 'a'){
            if(sa.size() != 0){
                s = sa.front();
                sa.erase(sa.begin());
            }
            else{
                cout << 'A' << endl;
                return 0;    
            }
        }
        else if(s == 'b'){
            if(sb.size() != 0){
                s = sb.front();
                sb.erase(sb.begin());
            }
            else{
                cout << 'B' << endl;
                return 0;
            }
        }
        else{
            if(sc.size() != 0){
                s = sc.front();
                sc.erase(sc.begin());
            }
            else{
                cout << 'C' << endl;
                return 0;
            }
        }
    }
}

Measured memory_bytes: 256
// general helpers
const debug = (message?: any, ...optionalParams: any[]) => {
  if (process.env.LOCAL_DEBUG === '1') console.log(message, ...optionalParams)
}

// helpers
const parseLines = (
  lines: string[]
): any => {
  const [a, b] = lines[0].split(' ').map(line => +line)
  const obj = { a, b }
  debug(obj)
  return obj
}
// solver
export const solve = (lines: string[]): string => {
  const { a, b } = parseLines(lines)
  return a * b % 2 === 0 ? 'Even' : 'Odd'
}

// main
const main = (lines: string[]) => {
  console.log(solve(lines))
}

// exec main function for submit
if (process.env.LOCAL_DEBUG !== '1') {
  const { stdin: input, stdout: output } = process
  input.resume()
  input.setEncoding('utf8')
  const lines: string[] = []
  require('readline')
    .createInterface({ input, output })
    .on('line', (line: string) => lines.push(line))
    .on('close', () => main(lines))
}


Measured memory_bytes: 7500
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;

//// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt"
int dp[501][10001];
int main() {
	int M, N; cin >> M >> N;
	vector<int>prices(M);
	for (int i = 0; i < M; ++i) {
		cin >> prices[i];
	}
	sort(prices.begin(), prices.end(), greater<int>());
	vector<int>sums(M + 1);
	sums[0] = 0;
	for (int i = 0; i < M; ++i) {
		sums[i + 1] = sums[i] + prices[i];
	}
	vector<int>cs(N), es(N);
	for (int i = 0; i < N; ++i) {
		cin >> cs[i] >> es[i];
	}
	for (int i = 0; i < 501; ++i) {
		for (int j = 0; j < 10001; ++j) {
			dp[i][j] = -1e9;
		}
	}
	dp[0][0] = 0;
	for (int i = 0; i < N; ++i) {
		for (int j = 0; j <= M; ++j) {
			dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
			if (j + cs[i] <= M) {
				int value = (sums[j + cs[i]]-sums[j]) - es[i];
				dp[i + 1][j + cs[i]] = max(dp[i + 1][j + cs[i]], dp[i][j] + value);
			}
			else {

				int value = (sums[M] - sums[j]) - es[i];
				dp[i + 1][M] = max(dp[i + 1][M], dp[i][j] + value);
			}
		}
	}
	int ans = 0;
	for (int i = 0; i <= M; ++i) {
		ans = max(ans, dp[N][i]);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 22808
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <numeric>
#include <functional>
#include <map>
#include <set>
#define REP(i, n) for(int i=0;i<n;++i)
#define rep(i, n) for(int i=1;i<=n;++i)
#define INF 10000000
#define ll long long

using namespace std;

typedef pair<int, int> P;
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

int a, b;

int main(){
    scanf("%d%d", &a, &b);

    if(b>=a){
        printf("%d", a);
    } else {
        printf("%d", a-1);
    }

	return 0;
}

Measured memory_bytes: 768
#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;


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    char A[2][3];
    rep(i, 2) rep(j, 3) cin >> A[i][j];
    if(A[0][0]==A[1][2] && A[0][1]==A[1][1] && A[0][2]==A[1][0]) cout << "YES";
    else cout << "NO";
    cout << endl;
    return 0;
}



Measured memory_bytes: 256
import sys

sys.setrecursionlimit(1000000)

N = int(input())
h = list(map(int, input().split()))

memo = [10**10 for _ in range(N+1)]

def dp(i):
    if i == 1:
        return 0
    elif i == 2:
        memo[i] = abs(h[i-2]-h[i-1])
        return memo[i]
    elif memo[i] < 10**10:
        return memo[i]
    else:
        memo[i] = min(
            dp(i-1) + abs(h[i-2]-h[i-1]),
            dp(i-2) + abs(h[i-3]-h[i-1]),
            dp(i-2) + abs(h[i-3]-h[i-2]) + abs(h[i-2]-h[i-1])
        )
        return memo[i]
print(dp(N))

Measured memory_bytes: 93588
//ABC173
#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() {
  int n;
  cin >> n;
  if(n%1000 == 0) cout << 0 << endl;
  else cout << 1000 - n%1000 << endl;
  return 0;
}



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

using namespace std;

class dsu {
public:
  vector<int> rank, p, size;
  dsu(){};
  dsu(int n) {
    rank.assign(n, 0);
    size.assign(n, 1);
    p.resize(n);
    for (int i = 0; i < n; ++i) p[i] = i;
  }

  int getSize(int x) {
    return size[findRep(x)];
  }
  
  void unite(int x, int y) {
    int p1 = findRep(x), p2 = findRep(y);
    if (p1 == p2) return;
    if (rank[p1] < rank[p2]) swap(p1, p2);

    if (rank[p1] == rank[p2]) rank[p1]++;
    p[p2] = p1;
    size[p1] += size[p2];
  }
  
  int findRep(int x) {
    if ( x != p[x] ) {
      p[x] = findRep(p[x]);
    }
    return p[x];
  }
};

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> p(N);
  for (int i = 0; i < N; ++i) {
    cin >> p[i];
    p[i]--;
  }

  dsu d (N);
  for (int i = 0; i < M; ++i) {
    int x, y;
    cin >> x >> y;
    d.unite(--x, --y);
  }

  int ans = 0;
  for (int i = 0; i < N; ++i) {
    if (d.findRep(i) == d.findRep(p[i])) ans++;
  }

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



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


#define DEBUG(x) 			   cout << '>' << #x << ':' << x << endl;
#define D(x)        		   cerr << __LINE__ << ": " << #x << " = " << (x) << '\n'
#define DD(x,y)     		   cerr << __LINE__ << ": " << #x << " = " << x << "   " << #y << " = " << y << '\n'
#define DDD(x,y,z)  		   cerr << __LINE__ << ": " << #x << " = " << x << "   " << #y << " = " << y << "   " << #z << " = " << z << '\n'
#define DBG         		   cerr << __LINE__ << ": Hi" << '\n'
#define fresh                  {ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);}
#define read                   freopen("in.txt","rt",stdin)
#define write                  freopen("out.txt","wt",stdout)
#define PI                     3.1415926535897932384626433832795
#define mems(ds_name,val)      memset(ds_name,val,sizeof(ds_name))
#define ll                     long long


void run(istream& in,ostream& out){
    int t;
    in>>t;
    int divs = t/2;
    int mods=t%2;
    if(!mods){
        out<<divs*divs<<endl;
    }
    else{
        out<<divs*(divs+1)<<endl;
    }
}


int main()
{
	//write;
    fresh;
//    read;

//    /***/
//    vector<ll> values(10000);
//    auto f = []() -> int { return rand() % 10000; };
//    generate(values.begin(), values.end(), f);
//    auto start = high_resolution_clock::now();
//    /**/

    run(cin,cout);

//    /**/
//    auto stop = high_resolution_clock::now();
//    auto duration = duration_cast<microseconds>(stop - start);
//    cout << "Time taken by function: "<< duration.count() << " microseconds" << endl;
//    /**/
     return 0;
}



Measured memory_bytes: 256
#include <stdio.h>

int main()
{
	int n,i,c;
	char s[16];
	while(scanf("%d",&n),n)
	{
		sprintf(s,"%o",n);
		for(i=0; c=s[i]; i++)
		{
			c-=48;
			printf("%d",c+c/4+c/5);
		}
		printf("\n");
	}
}

Measured memory_bytes: 768
n, m = map(int, raw_input().split())
array = []
for i in xrange(m):
	p, y = map(int, raw_input().split())
	array.append((y, p, i))

array.sort()
hash_map = dict()
for i in xrange(m):
	y, p, id = array[i]
	if p in hash_map:
		hash_map[p].append((y,id))
	else:
		hash_map[p] = []
		hash_map[p].append((y,id))

res = []
for k, v in hash_map.iteritems():
	key = str(k)
	while len(key) < 6:
		key = '0' + key
	for i in xrange(len(v)):
		year, idx = v[i]
		id = str(i+1)
		while len(id) < 6:
			id = '0' + id
		res.append((idx, key+id))
res.sort()
for i in xrange(len(res)):
	print res[i][1]






Measured memory_bytes: 58936
def solve(chess, remain_queens)
  if remain_queens == 0 then
    return true
  end

  cand_mass = collect(chess)
  cand_mass.each do |row, col|
    put_queen(row, col, chess)
    return true if solve(chess, remain_queens-1)
    remove_queen(row, col, chess)
  end
  return false
end

def collect(chess)
  candidates = []
  chess.each_with_index do |r, r_i|
    r.each_with_index do |c, c_i|
      candidates << [r_i, c_i] if chess[r_i][c_i] == 0
    end
  end
  return candidates
end

def put_queen(row, col, chess)
  do_queen(row, col, chess, 1)
end

def remove_queen(row, col, chess)
  do_queen(row, col, chess, -1)
end

def do_queen(row, col, chess, addition)
  chess[row][col] -= addition

  chess.each_with_index do |r, r_i|
    r[col] += addition unless r_i == row
  end
  chess[row].each_with_index do |c, c_i|
    chess[row][c_i] += addition unless c_i == col
  end

  r_i, c_i = row-1, col-1
  while r_i >= 0 && c_i >= 0 do
    chess[r_i][c_i] += addition
    r_i -= 1
    c_i -= 1
  end

  r_i, c_i = row+1, col-1
  while r_i <= 7 && c_i >= 0 do
    chess[r_i][c_i] += addition
    r_i += 1
    c_i -= 1
  end

  r_i, c_i = row+1, col+1
  while r_i <= 7 && c_i <= 7 do
    chess[r_i][c_i] += addition
    r_i += 1
    c_i += 1
  end

  r_i, c_i = row-1, col+1
  while r_i >= 0 && c_i <= 7 do
    chess[r_i][c_i] += addition
    r_i -= 1
    c_i += 1
  end
end

def show(chess)
  chess.each do |row|
    puts(row.map {|v| (v < 0) ? "Q" : "."}.join)
  end
end

# main
chess = []
8.times do
  chess << [0, 0, 0, 0, 0, 0, 0, 0]
end

n = gets.chomp.to_i
n.times do
  row, col = gets.chomp.split.map(&:to_i)
  put_queen(row, col, chess)
end

solve(chess, 8-n)
show(chess)

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

using namespace std;

int main()
{
    string s;
    cin>>s;
    long long int ans=0;
    for (long long int i=0;i<s.length();++i)
    {
        ans+=int(s[i]-'0');
        
    }
    
    ans%9==0?cout<<"Yes"<<endl:cout<<"No"<<endl;

    return 0;
}

Measured memory_bytes: 3704
//Robs Code
/***********HEADER***************/
#include <iostream>
#include <bitset>
#include <deque>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <algorithm>
#include <list>
#include <vector>
#include <unordered_set>
#include <unordered_map>
#include <stack>
#include <set>
#include <queue>
#include <map>
/***********MACROS***************/
#define int long long int
#define fri(l,k) for (i=l;i<=k;i++)
#define frj(l,k) for (j=l;j>=k;j--)
#define fij(a,b,l,k) for(i=a;i<=b;i++) for(j=l;j<=k;j++)
#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()
#define endl "\n"
#define pb push_back
#define _1 first
#define _2 second
#define pii pair<int,int>
using namespace std;
int n,m,i,j,l,k,x,y,a,b,cnt[3],sum[3];
/***********MAIN**************/
vector<int> v(100);
int dp[(int)1e5+1];
bool brute(int k){
	if(k == 0){
		return false;
	}
	if(k < 0){
		return true;
	}
	if(dp[k] != -1){
		return dp[k];
	}
	bool ans = false;
	for(int i=0;i<n;i++){
		ans = (ans | (brute(k-v[i])^1));
	}
	dp[k] = ans;
	return ans;
}
signed main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	cin>>n>>k;
	for(int i=0;i<n;i++){
		cin>>v[i];
	}
	memset(dp,-1,sizeof dp);
	if(brute(k)){
		cout<<"First";
	}else{
		cout<<"Second";
	}
	cout<<"\n";
	return 0;
}
//.........

Measured memory_bytes: 4224
#include <iostream>

using namespace std;

int main() {
  // input
  int a, b;
  cin >> a >> b;

  // end of days
  int eod[13];
  eod[0] = 0;
  for (int i = 0; i < 13; i++) {
    if (i == 2) {
      eod[i] = 28;
    } else if (i == 4 || i == 6 || i == 9 || i == 11) {
      eod[i] = 30;
    } else {
      eod[i] = 31;
    }
  }

  // check
  int counter = 0;
  for (int m = 1; m <= a; m++) {
    int eodm = m == a ? b : eod[m];
    for (int d = 1; d <= eodm; d++) {
      if (m == d) {
        counter++;
      }
    }
  }
  cout << counter << endl;
  return 0;
}


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

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

struct edge {
    int to, cost;
};

int n;
vector<vector<edge>> g;
vector<int> d;

//ダイクストラ法
void dijkstra(int s) {
    for (int i = 0; i < n; ++i) {
        d[i] = INF;
    }

    //最小値を取り出す優先度付きキュー
    priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> que;

    d[s] = 0;
    que.push(make_pair(0, s)); //距離を最初にして、優先度付きキューで最小値を出せるようにする

    while (!que.empty()) {
        pair<int, int> p = que.top(); que.pop();
        int v = p.second;

        //記録してある最短距離よりも取り出した要素に入っている距離情報が大きい場合は打ち切り
        if (d[v] < p.first) continue;

        for (int i = 0; i < g[v].size(); ++i) {
            edge e = g[v][i];

            if (d[e.to] > d[v] + e.cost) {
                d[e.to] = d[v] + e.cost;
                que.push(make_pair(d[e.to], e.to));
            }
        }
    }
}

int main() {

    int x, y; cin >> n >> x >> y;
    --x; --y;

    g.resize(n);
    d.resize(n);

    for (int i = 0; i < n-1; ++i) {
        g[i].push_back(edge({i+1, 1}));
        g[i+1].push_back(edge({i, 1}));
    }

    g[x].push_back(edge({y, 1}));
    g[y].push_back(edge({x, 1}));

    vector<int> ans(n, 0);
    for (int i = 0; i < n; ++i) {
        dijkstra(i);

        for (int j = 0; j < n; ++j) {
            ans[d[j]]++;
        }
    }

    for (int i = 0; i < n; ++i) {
        ans[i] /= 2;
    }

    for (int i = 1; i <= n-1; ++i) {
        cout << ans[i] << endl;
    }
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define con continue
#define pb push_back
#define fi first
#define se second
#define fr front()
#define one 1.0
#define inf 1000000000000000000
#define ret return
#define all(vl) vl.begin(),vl.end()
#define sor sort 
#define cl clear
#define m_p make_pair 
#define sz(a) a.size()
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef map<ll,ll>::iterator itll;
typedef long double ld;
typedef map<ll,ll> mapll;
typedef map<string,ll> mapstl;
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);
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	ll a,b;
	cin>>a>>b;
	cout<<lcm(a,b)<<endl;
	return 0;
}

Measured memory_bytes: 3604
import sys
imput = sys.stdin.readline
def main():
    # input
    N, weight = map(int, input().split())
    W, V = [], []
    for _ in range(N):
        w, v = map(int, input().split())
        W.append(w)
        V.append(v)
    V_max = sum(V)

    # loop
    dp = [[10**9]*(V_max+1) for _ in range(N+1)]
    dp[0][0] = 0
    for i in range(N):
        for j in range(0, V_max+1):
            if j<V[i]:
                dp[i+1][j] = dp[i][j]
            else:
                dp[i+1][j] = min(dp[i][j], dp[i][j-V[i]]+W[i])

    # check
    ans = []
    for j in range(1, V_max+1):
        if dp[i+1][j] <= weight:
            ans.append(j)
    print(max(ans))

if __name__ == '__main__':
    main()


Measured memory_bytes: 119196
n = int(input())
h = list(map(int, input().split()))

cost = [float('inf') for _ in range(n)]
cost[0] = 0

for x in range(n):
    if x + 1 < n:
        cost[x + 1] = min(cost[x + 1], cost[x] + abs(h[x + 1] - h[x]))
    
    if x + 2 < n:
        cost[x + 2] = min(cost[x + 2], cost[x] + abs(h[x + 2] - h[x]))

print(cost[n - 1])


Measured memory_bytes: 13928
n,m = map(int, input().split())
list_a = []
list_b = []
count = 0
while count < n:
    list_a.append(list(str(input())))
    count += 1
count = 0
while count < m:
    list_b.append(list(str(input())))
    count += 1
#print(list_a)
#print(list_b)[
phase = 0
if list_a != list_b:
    for i in range(0, n-m):
        for j in range(0, n-m):
            for k in range(0,m):
                if list_a[i+k][j:j+m] == list_b[k]:
                    if k != m-1:
                        continue
                    else:
                        pass
                else:
                    break
                phase = 1
                print("Yes")
                break
            if phase == 1:
                break
        if phase == 1:
            break
    else:
        print("No")
else:
    print("Yes")


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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define repr(i,a,b) for(int i=(int)(a-1);i>=b;i--)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout << #x" = " << x << endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

#define INF INT_MAX/3

int main() {
  cin.sync_with_stdio(false);
  int a, b;
  cin >> a >> b;
  cout << (1 + (b - a)) * (b - a) / 2 - b << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int K,a,b;
  cin>>K>>a>>b;
  if(a%K==0 && a/K==b/K){
     cout<<"OK"<<endl;
  }
  else if(a/K==b/K && K!=1){
    cout<<"NG"<<endl;
  }
  
  else{
    cout<<"OK"<<endl;
  }

}

Measured memory_bytes: 3636
import sys
s = input()
t = input()
k = len(s)
for i in range(k):
    if s[i] == t[0]:
        for j in range(k):
            if s[(i+j)%k] != t[j%k]:
                break
            if j == k-1:
                print("Yes")
                sys.exit()
    else:
        continue
print("No")

Measured memory_bytes: 3060
from collections import deque

k = int(input())
q = deque(range(1, 10))

for i in range(k-1):
    # popをk-1回やる
    x = q.popleft()
    y = int(str(x)[-1])
    if y-1 >= 0:
        q.append(int(str(x)+str(y-1)))
    q.append(int(str(x)+str(x)[-1]))
    if y+1 < 10:
        q.append(int(str(x)+str(y+1)))

print(q[0])




Measured memory_bytes: 16620
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#define rep(i,cc,n) for(int i=cc;i<=n;++i)
#define drep(i,cc,n) for(int i=cc;i>=n;--i)
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; }
const long long INF = 1LL <<60;
typedef long long ll;
using namespace std;

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

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

ll choose2(ll n){
    return n*(n-1)/2;
}

int main(){
    int n,k;
    string s;
    cin>>n>>k;
    cin>>s;
    if(s[k-1]=='A') s[k-1] = 'a';
    if(s[k-1]=='B') s[k-1] = 'b';
    if(s[k-1]=='C') s[k-1] = 'c';
    cout<<s<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    long long n,j,zuid,zuix;
    int i;
    cin>>n;
    cin>>j;
    zuid=j;
    zuix=j;
    for(i=1;i<n;i++)
    {
        cin>>j;
        if(j>zuid)
            zuid=j;
        if(j<zuix)
            zuix=j;
    }
    cout<<zuid-zuix;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<cstdlib>
using namespace std;
int read(){
	int x=0,f=1; char ch=getchar();
	while (ch<'0' || ch>'9') {if (ch=='-') f=-1; ch=getchar();}
	while (ch>='0' && ch<='9') {x=x*10+ch-'0'; ch=getchar();}
	return x*f;
}
int main(){
	int n=read();
	int a[10000];
	for (int i=1; i<=n; i++) a[i]=read();
	int mx=0,ans=0;
	for (int i=1; i<=n; i++) if (a[i]>=mx){
		ans++;
		mx=a[i];
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
import sys

n = int(input())
h = list(map(int, input().split()))

for i in range(n-1):
    d = h[i+1] - h[i]
    if d >= 1:
        h[i+1] -= 1
    elif d < 0:
        print('No')
        sys.exit()
print('Yes')

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

bool isAllNine(string s){
    rep(i,s.size()){
        if(s[i] != '9'){
            return false;
        }
    }
    return true;
}

int main() { 
    string s;
    cin >> s;
    if(s.size()==1){
        cout << s<<endl;
        return 0;
    }

    if(isAllNine(s.substr(1,s.size()-1))){
        cout << s[0]-'0' + (s.size()-1)*9 <<endl;
        return 0;
    }

    int ans = s[0]-'1';
    ans += (s.size()-1) * 9;
    cout << ans<<endl;
}

Measured memory_bytes: 3608
// H * W のマス目の h個の行と　w個の列を塗りつぶした時に残る白マスの数

#include <iostream>
#include <string>
using namespace std;

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

  // h個の行を塗りつぶすと h * W 個　消える
  // w個の列を塗りつぶすと w * H 個　消える
  // 重複する数は h * w なのでこれを補正する
  int output;
  output = H * W - h * W - w * H + h * w;
  cout << output << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
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;
}

ll gcd(ll a, ll b) {
    if(a < b) swap(a, b);
    if(a % b==0) return b;
    return gcd(b, a % b);
}

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;
ll a, b;

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll a, b;
    cin >> a >> b;
    cout << a * b / gcd(a, b);
    return 0;
}


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

int main(){
  int N;
  cin >> N;
  
  int n=0;
    char x;
  vector<char> v;

  while(cin >> x){
    v.push_back(x);
    n++;
  }
  int z;
   for(int x=0;x<n;x++){
      z = int(v[x]);
     z=z-65+N;
     z%=26;
     z+=65;
     v[x]=(char)z;
       cout << v[x];
   }
   }

Measured memory_bytes: 3656
ri = lambda: int(input())
rl = lambda: list(map(int,input().split()))
rr = lambda N: [ri() for _ in range(N)]
YN = lambda b: print('YES') if b else print('NO')
yn = lambda b: print('Yes') if b else print('No')
OE = lambda x: print('Odd') if x%2 else print('Even')
INF = 10**18

R=ri()
if R < 1200:
    print('ABC')
elif R<2800:
    print('ARC')
else:
    print('AGC')

Measured memory_bytes: 3064
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<cmath>
#include<cstdlib>
using namespace std;
#define int long long
const int maxn=2e5+5;
int a[maxn],ans[maxn];
signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>a[i];
    int tot=0;
    for(int i=1;i<=n;i++)
        tot^=a[i];
    for(int i=1;i<=n;i++)
        ans[i]=tot^a[i];
    for(int i=1;i<=n;i++)
        cout<<ans[i]<<(i==n?'\n':' ');
    return 0;
}


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

int main() {
  int a,b,c,d;
  cin >> a >>b;
  c=b-a+1;
  cout <<c<<" ";
  for(int i=0;i<2*a-2;i++){
  c++;
    d=c;
    cout << d <<" ";
  }
  
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int X = sc.nextInt();
        
        // He can go to X iff he can go farther than X
        // Ans. the minimum N s.t. 1+2+...+N >=X
        // N*(N+1) >= 2X  > N*(N-1)
        
        int N = (int)Math.sqrt(2*X);
        if(N*(N+1)<2*X) N++;
        System.out.println(N);
    }
}

Measured memory_bytes: 24916