akhauriyash/Code-Regression huggingface dataset:
#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#endif

#include <bits/stdc++.h>

using namespace std;

#define POW2(X) (1<<(X))
#define CKBIT(S,X) (((S)&POW2(X))!=0)

template<class T> inline void nlmin(T &a,T b){ a=min(a,b); }
template<class T> inline void nlmax(T &a,T b){ a=max(a,b); }
template<class T> inline T sqr(T x){ return x*x; }
#define SIZE(A) ((int)A.size())
#define LENGTH(A) ((int)A.length())

#define PB(X) push_back(X)
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define RFOR(i,a,b) for(int i=(a);i>=(b);--i)

#define REP(i,n) for(int i=0;i<=(n);++i)
#define ALL(A) A.begin(),A.end()
template<class T> int CMP(T a[],const T b[],int n) { return memcmp(a,b,n*sizeof(T)); }
template<class T> void COPY(T a[],const T b[],int n) { memcpy(a,b,n*sizeof(T)); }
template<class T> void SET(T a[],int val,int n) { memset(a,val,n*sizeof(T)); }
//using uint=unsigned int;
typedef long long int64;
//using uint64=unsigned long long;
typedef pair<int,int> pii;
typedef vector<int> VI;
typedef vector<VI> VII;
// using VD=vector<double>;
const int kmod = 1000000007;
const int N = 1000 + 10;

char a[N][N];
int dp[N][N];
int main() {
	int h, w;
	while (cin >> h >> w) {
		FOR (i, 1, h) FOR (j, 1, w) {
			cin >> a[i][j];
			dp[i][j] = 0;
		}

		dp[1][1] = 1;
		FOR (i, 1, h) FOR (j, 1, w) {
			if (i == 1 and j == 1) continue;
			if (a[i][j] == '.') {
				dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % kmod;
			}
		}
		cout << dp[h][w] << endl;
	}
	return 0;
}

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

/*  define  */
#define rep(i,j) for(int i=0;i<j;i++)

/*  using namespace  */
using namespace std;
using ll = long long;

template<class T> T gcd(T a, T b){ return ((b == 0) ? a : gcd(b, a % b)); }
int main(void)
{
	ll N,X;
	ll cnt=1;
	cin>>N;
	vector<ll> x(N);
	rep(i,N){
		cin>>X;
		if(X==cnt) cnt++;
	}
	if(cnt==1) cout<<-1<<endl;
	else cout<<N-cnt+1<<endl;
}


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

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

    int i1, i2, i3;

    cin >> i1 >> i2 >> i3;

    int count = 0;

    for (int i = 3; i < n; ++i)
    {
        if ((i2 > i1 && i2 < i3) || (i2 < i1 && i2 > i3))
        {
            ++count;
        }

        i1 = i2;
        i2 = i3;
        int input;
        cin >> input;
        i3 = input;
    }

    if ((i2 > i1 && i2 < i3) || (i2 < i1 && i2 > i3))
    {
        ++count;
    }

    cout << count << endl;
}

Measured memory_bytes: 256
n=int(input())
s=[0]*n
ct=0
a=0
b=0
c=0
for i in range(n):
    s[i]=input()
for i in range(n):
    for j in range(len(s[i])):
        t=s[i]
        ts=list(t)
        ts.append(0)
        if ts[j]=='A' and ts[j+1]=='B':
            ct+=1
    if ts[0]=='B' and ts[len(s[i])-1]!='A':
        a+=1
    if ts[len(s[i])-1]=='A' and ts[0]!='B':
        b+=1
    if ts[0]=='B' and ts[len(s[i])-1]=='A':
        c+=1
if max(a,b)>0 or c==0:
    print(ct+min(a,b)+c)
elif max(a,b)==0:
    print(ct+c-1)

Measured memory_bytes: 3700
#include "bits/stdc++.h"
using namespace std;
#define watch(x) cout << (#x) << " is " << (x) << endl



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


  long long a,b;

   cin>>a>>b;
   long long n;
    cin>>n;

   // for(int i=1;i<=n;i++){

     //  cout<<(a*i)/b<<" "<<a*(i/b)<<endl;;
      
    //}

    long long ans=(a*(min(n,b-1)))/b - a*(min(n,b-1)/b);


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


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

// code
int gcd(int &x, int &y){
    if(x==y){
        return x;
    }
    if(x < y){
        swap(x, y);
    }
    while(x >= y){
        if(x%y == 0){break;}
        x = x%y;
        if(x < y){
        swap(x, y);
        }
    }
    return y;
}

// main function
int main(){
    // input
    int x, y;
    cin >> x >> y;

    cout << gcd(x,y) << endl;
}


Measured memory_bytes: 3116
#include <iostream>
#include <cstdio>
#include <map>
using namespace std;

typedef long long LL;

int main ()
{
    int n;
    cin >> n;
    map<char,LL> mp;
    while (n--)
    {
        string s;
        cin >> s;
        mp[ s[0] ]++;
    }
    LL _=mp['M'],__=mp['A'],___=mp['R'],____=mp['C'],_____=mp['H'];
    cout << _*__*___ + _*__*____+_*__*_____ + _*___*____ + _*___*_____+_*____*_____+__*___*____+__*___*_____+__*____*_____+___*____*_____<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(v, a, b) for(int v = (a); v < (b); ++v)
#define FORE(v, a, b) for(int v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define REV(v, a, b) for(int v = (a); v >= (b); --v)
#define ALL(x) (x).begin(), (x).end()
#define ITR(it, c) for(auto it = (c).begin(); it != (c).end(); ++it)
#define RITR(it, c) for(auto it = (c).rbegin(); it != (c).rend(); ++it)
#define EXIST(c,x) ((c).find(x) != (c).end())
#define LLI long long int
#define fst first
#define snd second
#ifdef DEBUG
#include <boost/core/demangle.hpp>
#define dump(x) cerr << "L" << __LINE__ << ": in " << __PRETTY_FUNCTION__ << " \e[32;1m" << boost::core::demangle(typeid(x).name()) << "\e[37m" << " " << (#x) << " = " << (x) << "\e[m" << endl;
#else
#define dump(x)
#endif
using namespace std;
template <typename T> using V = vector<T>;
template <typename T, typename U> using P = pair<T,U>;
template <typename I> void join(ostream &ost, I s, I t, string d=" "){for(auto i=s; i!=t; ++i){if(i!=s)ost<<d; ost<<*i;}ost<<endl;}
template <typename T> istream& operator>>(istream &is, vector<T> &v){for(auto &a : v) is >> a; return is;}
template <typename T, typename U> istream& operator>>(istream &is, pair<T,U> &p){is >> p.first >> p.second; return is;}

template <typename T> ostream& operator<<(ostream &os, vector<T> &v){os << "{";ITR(i,v){if(i!=v.begin())os << ","; os << *i;}os << "}"; return os;}
template <typename T, typename U> ostream& operator<<(ostream& os, pair<T,U> &p){os << "(" << p.first << "," << p.second << ")"; return os;}

template <typename T> T& chmin(T &a, const T &b){return a = min(a,b);}
template <typename T> T& chmax(T &a, const T &b){return a = max(a,b);}

int dp[3100][3100];


void restore_lcs(const string &a, const string &b, int i, int j, string &r){
  if(i==0 || j==0) return;
  if(a[i-1] == b[j-1]){
    restore_lcs(a,b,i-1,j-1,r);
    r.push_back(a[i-1]);
  }else{
    if(dp[i-1][j] >= dp[i][j-1]) restore_lcs(a,b,i-1,j,r);
    else restore_lcs(a,b,i,j-1,r);
  }
}

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

  string s,t; cin >> s >> t;

  REP(i,s.size()){
    REP(j,t.size()){
      if(s[i] == t[j]){
	dp[i+1][j+1] = dp[i][j] + 1;
      }else{
	dp[i+1][j+1] = max(dp[i][j+1], dp[i+1][j]);
      }
    }
  }

  string ans;
  restore_lcs(s,t,s.size(),t.size(),ans);
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 37248
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <map>
#define rep(i, n) for(int i=0;i<(int)(n);i++)
#define pb(a) push_back(a)
#define MAX(a, b) ((a < b)?b:a)
#define MIN(a, b) ((a > b)?b:a)
typedef long long int ll;
typedef unsigned long long int ull;
using namespace std;

template<typename T> void cinpb(vector<T>& x) { T n; cin >> n; x.push_back(n); }
ull gcd(ull a, ull b) { return b ? gcd(b, a%b) : a; }
ull lcm(ull m, ull n) {	return ((0 == m) || (0 == n)) ? 0 : ((m / gcd(m, n)) * n); }
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };

void yesno(bool f) { cout << (f ? "Yes" : "No") << endl; }

//

ull n, m;
string s, t;

ll func()
{
	cin >> n >> m >> s >> t;

	ull l = lcm(n, m);

	map<int, char> mp;


	for ( ull i = 0; i < n; i++ )
	{
		ull pos = i * l / n;
		if ( l <= pos ) return -1;

		mp[pos] = s[i];
	}

	for ( ull i = 0; i < m; i++ )
	{
		ull pos = i * l / m;
		if ( l <= pos ) return -1;

		if ( mp.count(pos) == 0 )
		{
			mp[pos] = t[i];
		}
		else
		{
			if ( mp[pos] != t[i] ) return -1;
		}
	}

	
	return l;
}

int main()
{
	cout << func() << endl;
	return 0;
}

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

int main() {
  string s;
  cin >> s;
  
  int count = 0;
  for(int i = 0; i < 3; i++){
    if(s.at(i) == 'o') count++;
  }
  
  cout << 700 + 100 * count << endl;
}

Measured memory_bytes: 256
//int a = stoi(c); 文字列をintへ
//小文字から大文字
//transform(a.begin(), a.end(), a.begin(), ::toupper);
//数値計算 個数以外はdouble
//map 全探索
//auto begin = p.begin(), end = p.end();
//for (auto it = begin; it != end; it++) {}
//mapのキー：it->first mapのバリュー：it->second
//大文字判定 isupper(文字) 小文字判定 islower(文字)
//do{}while(next_permutation(ALL(配列)))
//小文字に対応する文字コード：S[i] - 'a'
//文字コード→小文字：(char)(数字+'a')
//グラフの距離:隣接行列で扱う
//bool型　初期値はTrue
//島渡りの問題：中間ノードに着目
//数が大きい時の比較はstring型で行う
//全て0になったか調べたい->0になるたびにcntする
//例外処理は最初にする
//x = p^m + q^n...の約数の個数:(n+1)*(m+1)....
//N!のどの素因数で何回割れるか
//⇔1~Nまでの数がそれぞれどの素因数で何回割り切れるかの和
//パズルの問題->一般化して全探索
//stack<ll> s;
//s.push(要素);s.top();s.pop();
//queue<ll> q;
//q.push(要素);q.front();q.pop();
//同じ作業繰り返す系の問題：収束先を見つける
//過半数：N/2.0で判定
//優先度付きキュー
//priority_queue<
//ll,
//vector<ll>
//> q;
#include <bits/stdc++.h>
#define rep(i,N) for(int i = 0; i < N;i++)
#define ALL(a) (a).begin(),(a).end()
#define ll long long int
#define PI 3.14159265358979323846264338327950L
using namespace std;


//割るやつ
const ll MOD = (pow(10, 9) + 7);

// K進数でのNの桁数
ll dig(ll N, ll K) {
	ll dig = 0;
	while (N) {
		dig++;
		N /= K;
	}
	return dig;
}
// a,bの最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}

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

//階乗計算
ll f(ll n) {
	if (n == 0 || n == 1) return 1;
	else return (n * f(n - 1));
}

//Nのd桁目の数
ll dignum(ll N, ll d) {
	ll x = pow(10, d);
	N %= x;
	ll y = pow(10, d - 1);
	N /= y;
	return N;
}

//Nをdで何回割れるか
ll divcnt(ll N, ll d) {
	ll ans = 0;
	while (1) {
		if (N%d == 0) {
			ans++;
			N /= d;
		}
		else break;
	}

	return ans;
}

//素数判定
bool prime(ll num) {
	if (num < 2) return false;
	else if (num == 2) return true;
	else if (num % 2 == 0) return false;
	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2) {
		if (num % i == 0) return false;
	}
	return true;
}

//フィボナッチ数列
vector<ll> memo(pow(10, 6) + 1);
ll fibo(ll n) {
	if (n == 1) return 1;
	else if (n == 2) return 1;
	else if (memo[n] != 0) return memo[n];
	else return memo[n] = fibo(n - 1) + f(n - 2);
}

ll RS(ll N, ll P, ll M) {
	if (P == 0) return 1;
	if (P % 2 == 0) {
		ll t = RS(N, P / 2, M);
		return t * t % M;
	}
	return N * RS(N, P - 1, M);
}

int main() {
	ll N;cin >> N;
	vector<ll> A(N);rep(i,N)cin >> A[i];
	ll Q; cin >>Q;
	vector<ll> B(Q),C(Q);rep(i,Q)cin >> B[i] >> C[i];

	ll sum = 0;
	for(int i = 0; i < N ; i++)sum += A[i];

	map<ll,ll> p;
	rep(i,N) p[A[i]]++;

	for(int i = 0; i  < Q;i++){
		ll x = C[i] - B[i];
		sum += x * p[B[i]];

		cout << sum << endl;

		p[C[i]] += p[B[i]];
		p[B[i]] -= p[B[i]];
	}
}

Measured memory_bytes: 19272
import java.util.*;
public class Main{
	public static void main(String[] args){
      	Scanner sc = new Scanner(System.in);
    	int n = sc.nextInt();
      	int h = sc.nextInt();
      	int w = sc.nextInt();
      	System.out.println((n-h+1)*(n-w+1));
    }
}

Measured memory_bytes: 35828
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <random>
#include <chrono>
#include <tuple>
#include <random>

using namespace std;

typedef long long ll;
typedef long double ld;
#define fastInp cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);

const ll SIZE = 1e6 * 2 + 10, INF = 1e9 * 1e9 + 10;



int main()
{
	fastInp;

	ll n;
	cin >> n;
	string s;
	cin >> s;

	ll cR = 0, cW = 0, ans = INF;
	vector<ll> pr, suf;
	suf.push_back(0);
	pr.push_back(0);
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == 'R') {
			cR++;
		}
		else {
			cW++;
		}
		ll vl = 0;
		if (s[i] == 'W') {
			vl++;
		}
		pr.push_back(pr.back() + vl);
	}

	ans = min(cR, cW);

	for (int i = s.size() - 1; i >= 0; i--) {
		ll vl = 0;
		if (s[i] == 'R') {
			vl++;
		}
		suf.push_back(suf.back() + vl);
	}

	reverse(suf.begin(), suf.end());
	for (int i = 1; i < s.size(); i++) {
		ll vl1 = pr[i], vl2 = suf[i];
		ans = min(ans, max(vl1, vl2));
	}

	cout << ans;
	return 0;
}

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

int main(){
    ll n, k;
    cin >> n >> k;
    ll h[n];
    for(ll i = 0; i < n; i++){
        cin >> h[i];
    }

    sort(h, h + n, greater<ll>());
    ll ans = 0;

    for(ll i = k; i < n; i++){
        ans += h[i];
    }

    cout << ans << endl;
}

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

typedef long long ll;

int n;
string s;


vector<pair<int, int> >v;

int main() {
    ios::sync_with_stdio(0);
    cin >> n >> s;
    int r = 0;
    int w = 0;
    for (int i = 0; i < n; i++) {
        if (s[i] == 'W') {
            w++;
        } else {
            r++;
        }
    }
    int ans = min(w, r);
    int cnt = 0;
    for (int i = 0; i < r; i++) {
        if (s[i] == 'R') {
            cnt++;
        }
    }
    ans = min(ans, r - cnt);
    cnt = 0;
    for (int i = n - 1; i >= n - w; i--) {
        if (s[i] == 'W') {
            cnt++;
        }
    }
    ans = min(ans, w - cnt);
    cout << ans << endl;



    


    
}

Measured memory_bytes: 3736
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define IINF 100000000
#define INF 300000000000000000
#define MOD 1000
#define mod 1000000007
#define INT_MAX_ 2147483647
#define REP(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define REPE(i, a, n) for (ll i = a; i <= (ll)(n); i++)
#define rep(i,n)for (ll i = 0; i < (ll)(n); i++)
#define Endl endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
#define me memset
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef pair<int,int>Pin;
typedef pair<ll,ll>Pll;
template<class T> using V=vector<T>;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T> >;
long long GCD(long long a, long long b) {return b?GCD(b,a%b):a;}
long long LCM(long long a, long long b) {return a/GCD(a,b)*b;}
int dx[5]={-1,0,1,0,0};
int dy[5]={0,-1,0,1,0};
int ddx[8]={-1,0,1,0,1,1,-1,-1};
int ddy[8]={0,-1,0,1,1,-1,1,-1};
ll cmp1(pair<ll,ll>a,pair<ll,ll> b){
        if(a.se!=b.se)
        return a.se<b.se;
        else
        return a.fi<b.fi;
}
//----------------------------------------------------------------------

//----------------------------------------------------------------------
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------  
    //ll begin_time=clock();
    //-------------------------------
    ll x;cin>>x;
    ll now=100;
    ll cnt=0;
    while(now<x){
        cnt++;
        now=now*1.01;
    }
    cout<<cnt<<endl;
    //-------------------------------  
    //ll end_time=clock();cout<<"time="<<end_time-begin_time<<"ms"<<endl;
    //-------------------------------
    return 0;
}
//----------------------------------------------------------------------





































Measured memory_bytes: 3640
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>

#define rep(i, x, n) for(int i = x; i < n; i++)
using namespace std;
const long long INF = 1LL << 60;

long long GCD(long long a, long long b) {
    if(b == 0)
        return a;
    else
        return GCD(b, a % b);
}
long long LCM(long long a, long long b) {
    long long g = GCD(a, b);
    return a / g * b;
}

int main() {
    int N;
    cin >> N;
    vector<int> x(N);
    rep(i, 0, N) { cin >> x[i]; }
    int min = 1000000000;
    rep(i, 1, 101) {
        int tmp = 0;
        rep(t, 0, N) { tmp += (i - x[t]) * (i - x[t]); }
        if(tmp < min) {
            min = tmp;
        }
    }
    cout << min << endl;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;
typedef long long ll;

struct mint{
    static const long long MOD = 1000000007;

    long long v;

    mint() : v(0) {}
    mint(long long x){
        x = x % MOD;
        if(x < 0){ x += MOD; }
        v = x;
    }
    mint& operator+=(mint a){
        v += a.v;
        if(v >= MOD){ v -= MOD; }
        return *this;
    }
    mint& operator*=(mint a){
        v *= a.v;
        v %= MOD;
        return *this;
    }
    mint& operator-=(mint a){
        v -= a.v;
        if(v < 0){ v += MOD; }
        return *this;
    }
    mint& operator/=(mint a){
        return (*this) *= a.inv();
    }

    mint operator*(mint a) const{
        return mint(v) *= a;
    }

    mint operator+(mint a) const {
        return mint(v) += a;
    }

    mint operator-(mint a) const {
        return mint(v) -= a;
    }

    mint operator/(mint a) const {
        return mint(v) /= a;
    }

    mint pow(long long k) const {
        mint res(1),tmp(v);
        while(k){
            if(k&1) res *= tmp;
            tmp *= tmp;
            k >>= 1;
        }
        return res;
    }
    mint inv(){return pow(MOD - 2); }

    static mint comb(long long n, int k){
        mint res(1);
        for(int i = 0; i < k; ++i){
            res *= mint(n - i);
            res /= mint(i + 1);
        }
        return res;
    }

    static mint factorial(long long n){
        mint res(1);
        for(int i = n; i > 1; --i){
            res *= mint(i);
        }
        return res;
    }

    bool operator<(const mint &a) const {
        return v < a.v;
    };
};

mint operator*(long long l, mint r){ return r * l; }


int main(){
    ll n, m;
    cin >> n >> m;
    if(abs(n - m) >= 2){
        cout << 0 << endl;
    }else if(abs(n - m) == 0){
        cout << (mint::factorial(n) * mint::factorial(m) * 2).v << endl;
    }else{
        cout << (mint::factorial(n) * mint::factorial(m)).v << endl;
    }
    return 0;
}


Measured memory_bytes: 256
// clang-format off
#include <bits/stdc++.h>

#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (size_t i = 0; i < size_t(n); i++)
#define forn1(i,n) for (size_t i = 1; i <= size_t(n); i++)
#define popcnt __builtin_popcount
#define ffs __builtin_ffs
#define ctz __builtin_ctz
#define clz __builtin_clz
#define all(a) (a).begin(), (a).end()
 
using namespace std;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
using pil = pair<int,ll>;
using pll = pair<ll,ll>;
template <typename T> using vec = vector<T>;
using vi = vec<int>;
using vl = vec<ll>;
template <typename T> using que = queue<T>;
template <typename T> using deq = deque<T>;

template <typename T> T id(T b) {return b;};
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}
template <typename S, typename K> bool contains(S &s, K k) { return s.find(k) != s.end(); }
void fastio() { ios_base::sync_with_stdio(false); cin.tie(nullptr); }
constexpr ll TEN(int n) { if (n == 0) return 1LL; else return 10LL*TEN(n-1); }
// clang-format on

const int MAX_N = 100000;
int n, k, r, s, p;
string t;
bool done[MAX_N];

int main() {
    fastio();

    cin >> n >> k >> r >> s >> p >> t;

    int ans = 0;
    forn(i, n) {
        if (i >= k) {
            if (t[i - k] == t[i] && done[i - k]) continue;
        }

        if (t[i] == 'r') {
            ans += p;
        } else if (t[i] == 's') {
            ans += r;
        } else {
            ans += s;
        }

        done[i] = true;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 592
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <iomanip>
#include <functional>
#include <queue>
#include <stack>
#include <map>
#include <vector>
#include <cmath>
#include <cctype>
#include <cstdio>
#define ll long long
#define INF 1000000000000000001
#define MOD 1000000007
using namespace std;

int main(){
    while(1){
        int n;
        cin >> n;
        if(n==0){
            break;
        }
        
        int a[1000];
        for(int i=0; i<n; i++){
            cin >> a[i];
        }
        
        sort(a,a+n);
        
        int ans = 10000000;
        for(int i=1; i<n; i++){
            ans = min(ans,a[i]-a[i-1]);
        }
        cout<<ans<<endl;
    }
    return 0;
    
}



Measured memory_bytes: 3108
#include<bits/stdc++.h>
using namespace std;
long long int abs(long long int a,long long int b)
{
	if(a>b)
	{
		return a-b;
	}
	else
	{
		return  b-a;
	}
}
int main()
{
long long int n,k;
cin>>n>>k;
long long int arr[n],arr1[n];
for(long long int i=0;i<n;i++)
{
	cin>>arr[i];
}
if(n<=k)
{
	cout<<arr[n-1]-arr[0]<<endl;
	return 0;
}
arr1[0]=0;
for(long long int i=1;i<k;i++)
{
	arr1[i]=abs(arr[i],arr[0]);
}
// arr1[1]=abs(arr[1],arr[0]);
for(long long int i=k;i<n;i++)
{
	long long int mn=99999999999;
	for(long long int j=1;j<=k;j++)
	{	
		long long int a=abs(arr[i-j],arr[i])+arr1[i-j];
		if(a<mn)
		{
			mn=a;
		}
	}
	arr1[i]=mn;
}
// for(long long int i=0;i<n;i++)
// {
// 	cout<<arr1[i]<<" ";
// }
// cout<<endl;
cout<<arr1[n-1]<<endl;











	return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include<cstdio>
#include<string>
#include<vector>
#include<map>
#include<stack>
#include<queue>
using namespace std;
int main() {
	int n;
	cin >> n;
	long long int l[87] = {0};
	l[0] = 2;
	l[1] = 1;
	for (int i = 2; i <= n; i++) {
		l[i] = l[i - 1] + l[i - 2];
	}
	cout << l[n] << endl;
	return 0;
}


Measured memory_bytes: 256
/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <list>
#include <stack>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#define   mod  998244353
#define   int  long long 
#define   ld   long double
#define   pb   push_back
#define   vi  vector<int> 
#define   co(x)  cout << x << endl;
#define   dbg(x)  cerr << #x << " = " << x << '\n'
#define   sz(x)  (int)x.size()
#define   all(a) (a.begin(),a.end())
#define   ff   first
#define   ss   second
#define   pii  pair<int,int> 
#define   lcm(a,b) (a*b)/__gcd(a,b) 
using namespace std;


/// https://atcoder.jp/contests/agc032/tasks/agc032_b 


signed main()
{
    int n; cin >> n;
    vector <pii> ans;
   	int bad = n;
   	if (n%2==0) bad++;
   	for (int i=1;i<=n;i++){
   		for (int j=i+1;j<=n;j++){
   			if (i+j == bad) continue;
   			ans.emplace_back(i,j);
   		}
   	}
   	cout << sz(ans) << endl;
   	for (auto &it: ans)
   		co(it.ff << " " << it.ss) ; 
    return 0;
}

Measured memory_bytes: 3736
#include <bits/stdc++.h>
using namespace std;
#define pb emplace_back
#define fi first
#define se second
#define mp make_pair
#define SZ(x) ((int)(x.size()))
#define FOI(i,a,n) for(int (i)=int(a);(i)<=int(n);++(i))
#define FOD(i,a,n) for(int (i)=int(a);(i)>=int(n);--(i))
#define IN(x,y) ((y).find((x))!=(y).end())
#define ALL(t) t.begin(),t.end()
#define MSET(tabl,i) memset(tabl, i, sizeof(tabl))
#define PSET(x,y) fixed<<setprecision(y)<<lf(x)
#define DBG(c) cout<<#c<<" = "<<c<<endl;
#define RTIME ((double)clock()/(double)CLOCKS_PER_SEC)

template<typename T,typename S>inline bool REMIN(T&a,const S&b){return a>b?a=b,1:0;}
template<typename T,typename S>inline bool REMAX(T&a,const S&b){return a<b?a=b,1:0;}

typedef long long ll;
typedef long double lf;
typedef pair<int, int> pi;
typedef vector<pi> vpi;
typedef vector<int> vi;
typedef vector<vi> vvi;

int bit(ll x, int pos){ return (x >> pos) & 1; }
ll power(ll base, ll exp, ll c = 1e9 + 7) { if(!exp) return 1; ll r = power(base, exp >> 1, c); r=(r*r)%c; if(exp&1) r=(r*base)%c; return r; }

ll T,N,M,K;  
int a,b,c;
string s1,s2;

const lf PI = 2*acos(0);
const ll INF = 1e9 + 4;
const int NMAX = 3e5+5;
const ll MOD = 1000000007;

ll ans = INF;

queue<int> lines[303];
int newma, newnum;

set<int> rem;

bool gen_rep() {
	int ar[303];
	MSET(ar, 0);
	FOI(i, 1, N) {
		while(SZ(lines[i]) and IN(lines[i].front(), rem)) {
			lines[i].pop();
		}
		if(SZ(lines[i])) {
			ar[lines[i].front()] ++;
		} else {
			return 0;
		}
	}
	newma = 0;
	FOI(i, 1, M) {
		if(REMAX(newma, ar[i])) {
			newnum = i;
		}
	}
	return 1;
}

int main(){
	ios_base::sync_with_stdio(false); cin.tie(0);
	
	cin >> N >> M;
	FOI(i, 1, N) {
		FOI(j, 1, M) {
			cin >> a;
			lines[i].push(a);
		}
	}

	while(gen_rep()) {
		REMIN(ans, newma);
		rem.insert(newnum);
		FOI(i, 1, N) {
			if(lines[i].front() == newnum) {
				lines[i].pop();
			}
		}
	}

	cout << ans << '\n';
	
	return 0;
}


Measured memory_bytes: 768
#include <iostream>
#include <stdio.h>
using namespace std;

int main()
{
	int  n, m, b = 0;

		cin >> n >> m;
		n = n - 1;
		m = m - 1;
		while (n >= 1) {
			b = b + n;
			n--;
}
		while (m >= 1) {
			b = b + m;
			m--;
		}

	cout << b;

}

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;
typedef pair<int,int> P;

int main(void){
  ll n,m; cin >> n >> m;
  vector<pair<ll,ll>> ab;
  rep(i,n){
    int a,b;
    cin >> a >> b;
    ab.push_back(make_pair(a,b));
  }
  sort(ab.begin(),ab.end());
  ll ans = 0;
  ll count = 0;
  rep(i,n){
    if(count + ab.at(i).second >= m){
      ans += (m-count) * ab.at(i).first;
      break;
    }
    else{
      count += ab.at(i).second;
      ans += ab.at(i).first*ab.at(i).second;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 2420
from collections import defaultdict

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

d = defaultdict(int)

for i in range(N):
    d[A[i]] += 1

def func(v):
    if v < 3:
        return v
    a = v//3 + v%3

    return func(a)

ans = 0
se = 0
dd = [0 for i in range(3)]
for k, v in d.items():
    value = v // 3 + (v % 3)
    value = func(v)
    # dd[value] += 1
    if value % 3 == 0 or value % 3 == 1:
        ans += 1
    else:
        se += 1

print(ans + ((se//2)*2))

Measured memory_bytes: 18656
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class Main implements Runnable {

    private static int MOD = 1_000_000_007;

    public static void main(String[] args) {
        // Run with 32MB stack
        Thread thread = new Thread(null, new Main(), "", 32 * 1024 * 1024);
        thread.start();
    }

    @Override
    public void run() {
        final Scanner scanner = new Scanner(System.in);
        solve(scanner);
    }

    static void solve(Scanner scanner) {
        int N = scanner.nextInt();
        int M = scanner.nextInt();
        long[][] items = new long[N][2];
        for (int i = 0; i < N; i++) {
            items[i][0] = scanner.nextInt();
            items[i][1] = scanner.nextInt();
        }
        Arrays.sort(items, Comparator.comparing(x -> x[0]));
        long pay = 0;
        for (int i = 0; i < N; i++) {
            if (items[i][1] >= M) {
                pay += items[i][0] * M;
                break;
            }
            pay += items[i][0] * items[i][1];
            M -= items[i][1];
        }
        System.out.println(pay);
    }
}

Measured memory_bytes: 95556
#include<iostream>
#include<cstdio>
#include<cstdlib>
using namespace std;
int a[100005];
int go(int l,int r)
{
	if(l<1||r<1)return 0;
	if(l>r)return 0;
	if(l==r)return a[l];
	int m=1111111111,w=0;
	for(int i=l;i<=r;i++)
		if(a[i]<m)
		{
			m=a[i];
			w=i;
		}
	int j=a[w];
	for(int i=l;i<=r;i++)
		a[i]-=j;
	int lf=go(l,w-1);
	int rg=go(w+1,r);
	return j+lf+rg;
}
int main()
{
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	int ans=go(1,n);
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include <string> 
#include <vector>  
#include<math.h>

#define INF 1000000000
using namespace::std;



long Lmax(long x, long y) {
	if (x > y)return x;
	return y;
}

int max(int x, int y) {
	if (x > y)return x;
	return y;
}

long Lmin(long x, long y) {
	if (x < y)return x;
	return y;
}


int min(int x, int y) {
	if (x < y)return x;
	return y;
}

int abs(int x) {
	if (x < 0) {
		return -x;
	}
	return x;
}

long long N,wa, K,ans,m,a,r,c,h,num[5];
string s[100000];

int main() {
	cin >> N;
	m, a, r, c, h = 0;
	ans = 0;
	for (int i = 0; i < N; i++) {
		cin >> s[i];
		if (s[i][0] == 'M') {
			num[0]++;
		}
		if (s[i][0] == 'A') {
			num[1]++;
		}
		if (s[i][0] == 'R') {
			num[2]++;
		}
		if (s[i][0] == 'C') {
			num[3]++;
		}
		if (s[i][0] == 'H') {
			num[4]++;
		}
	}

	for (int i = 0; i < 3; i++) {
		for (int j = i + 1; j < 4; j++) {
			for (int k = j + 1; k < 5; k++) {
				ans += num[i] * num[j] * num[k];
			}
		}
	}
	cout << ans << endl;

	return 0;
}




Measured memory_bytes: 6144
import kotlin.comparisons.*
import java.util.*

const val MOD = 1000000007L

fun readI() = readLine()!!.toInt()
fun readL() = readLine()!!.toLong()
fun readD() = readLine()!!.toDouble()
fun readIs() = readLine()!!.split(' ').map(String::toInt)
fun readLs() = readLine()!!.split(' ').map(String::toLong)
fun readDs() = readLine()!!.split(' ').map(String::toDouble)

fun main(args: Array<String>) {
  val (n, k) = readIs()
  val s = readLine()!!.toCharArray()
  s[k - 1] = s[k - 1].toLowerCase()
  println(s.joinToString(""))
}


Measured memory_bytes: 37916
import math
import sys
input = sys.stdin.readline


def main():
    X = int(input())
    
    ans = 1
    for a in range(2, math.ceil(math.sqrt(X))):
        b = 2
        while a**(b+1) <= X:
            b += 1
        ans = max(ans, a**b)

    print(ans)

if __name__ == '__main__':
    main()

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

int main(void){
    // Your code here!
    string s;
    cin >> s;
    vector<int> abcd;
    for(int i = 0; i < 4; i++)
        abcd.push_back(s[i] - '0');
        
    for(int i = 0; i < 8; i++){
        int temp_i = i;
        int sum = abcd[0];
        for(int j = 0; j < 3; j++){
            if(temp_i % 2 == 0)
                sum += abcd[j+1];
            else
                sum -= abcd[j+1];
            temp_i = temp_i >> 1;
        }
        
        if(sum == 7){
            cout << abcd[0];
            for(int j = 0; j < 3; j++){
                if(i % 2 == 0)
                    cout << '+';
                else
                    cout << '-';
                i = i >> 1;
                cout << abcd[j+1];
            }
            cout << "=7";
            break;
        }
    }
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<vector>
using namespace std;

#define lld long long

int gcd(int a, int b) {
  int t;    // 補助変数
  while ( b != 0 ) {          // 他方が0になるまで
    t = a%b; a = b; b = t;    // 一方を剰余に置き換える
  }
  return a;                   // 他方が0になったときの一方がGCD
}

int gcd3(int a, int b, int c) {
  int s, t;
  s = gcd(a, b);
  t = gcd(c, s);
  return t;
}

int main(){
    lld K;
    cin >> K;
    lld sum = 0;
    for(int i=0;i<K;i++){
        for(int j=0;j<K;j++){
            for(int k=0;k<K;k++){
                sum += gcd3(i+1,j+1,k+1);
            }
        }
    }
    cout << sum << endl;
}

Measured memory_bytes: 3632
# include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pii pair<int,int>
typedef long long ll;
int n;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin>>n;
    n=n%1000;
    int ans;
    ans=1000-n;
    if(ans==1000) ans=0;
    cout<<ans<<endl;
}

Measured memory_bytes: 3644
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
#define check(v) rep(i,v.size()) cout << v[i] << " ";\
cout << endl
#define INF 1e8
typedef long long ll;
using namespace std;
//オーバーフローに気をつけろよおおおおおお
//確認忘れるなよおおおおおお

int n, a[100001];

ll number(int sign){
    ll ret = 0, sum = 0;
    rep(i,n){
        sum += a[i];
        if(sum * sign <= 0){
            ret += abs(sum)+1;
            sum = sign;
        }
        sign *= -1;
    }
    return ret;
}
int main() {
    cin >> n;
    rep(i,n) cin >> a[i];
    cout << min(number(1), number(-1)) << endl;

    return 0;
}

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

int main() {
  int64_t a, b, k;
  cin >> a >> b >> k;
  
  if (b - a + 1 < 2 * k) {
    for (int i = a; i <= b; i++) {
      cout << i << endl;
    }
  }
  else {
    for (int i = 0; i < k; i++) {
      cout << a + i << endl;
    }
    for (int i = 0; i < k; i++) {
      cout << b - k + 1 + i << endl;
    }
  }
}


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

#define PI 3.14159265359
#define INF 1e9
#define LINF 1e18
#define IMOD 1000000007 
#define irep(i,n) for(int i = 0; i < (int)(n); i++)
#define irep2(i,a,n) for(int i = (int)(a); i <= (int)(n); i++)
#define lrep(i,n) for(long long  i = 0; i < (long long)(n); i++)
#define lrep2(i,a,n) for(long long i = (long long)(a); i <= (long long)(n); i++)

#define irrep(i,n) for(int i = (int)(n); i > -1; i--)
#define irrep2(i,a,n) for(int i = (int)(n); i >= (int)(a); i--)

typedef long long ll;
typedef std::vector<char> v_char;
typedef std::vector<v_char > v2_char;
typedef std::vector<double> v_double;
typedef std::vector<v_double > v2_double;
typedef std::vector<int> v_int;
typedef std::vector<v_int > v2_int;
typedef std::vector<ll> v_ll;
typedef std::vector<v_ll > v2_ll;
typedef std::vector<std::string> v_string;
typedef std::vector<v_string > v2_string;
typedef std::vector<bool> v_bool;
typedef std::vector<v_bool > v2_bool;
typedef std::pair<ll, ll> pll;
typedef std::pair<int, int> pii;

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

using namespace std; 

int main(void)
{
    int a, b;
    cin >> a >> b;

    int g_a, g_b;
    
    v2_int group = {{1,3,5,7,8,10,12}, {4,6,9,11},{2}};

    irep(i, 3) {
        irep(j, group[i].size()) {
            if(group[i][j] == a) { g_a = i; }
            if(group[i][j] == b) { g_b = i; }
        }
    }
    if(g_a == g_b) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}   
/** atcoder **/


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define FOREACH(x, a) for (auto&(x) : (a))
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
ll N;
vector<ll> X, Y;
vector<char> U;
const string DIRECTION = "LDRU";
const ll POS_MAX = 200000;
const ll INF = 1e18;
void rotate() {
  REP(i, N) {
    ll m = POS_MAX / 2, x = X[i] - m, y = Y[i] - m;
    X[i] = -y + m, Y[i] = x + m;
    REP(j, 4) {
      if (DIRECTION[j] == U[i]) {
        U[i] = DIRECTION[(j + 1) % 4];
        break;
      }
    }
  }
}

ll solveForLine() {
  ll res = INF;
  vector<vector<ll>> XsL(POS_MAX + 1), XsR(POS_MAX + 1);
  REP(i, N) {
    if (U[i] == 'L') {
      XsL[Y[i]].push_back(X[i]);
    } else if (U[i] == 'R') {
      XsR[Y[i]].push_back(X[i]);
    }
  }
  REP(i, POS_MAX + 1) {
    if (SZ(XsL[i]) == 0 || SZ(XsR[i]) == 0) {
      continue;
    }
    sort(ALL(XsL[i]));
    sort(ALL(XsR[i]));
    for (ll xr : XsR[i]) {
      if (XsL[i][0] > xr) {
        chmin(res, (-xr + XsL[i][0]) * 5);
        continue;
      }
      if (XsL[i].back() <= xr) {
        continue;
      }
      ll ng = 0, ok = SZ(XsL[i]) - 1;
      while (ng + 1 < ok) {
        ll m = (ok + ng) / 2;
        (XsL[i][m] > xr ? ok : ng) = m;
      }
      chmin(res, (-xr + XsL[i][ok]) * 5);
    }
  }
  return res;
}
ll solveForVertical() {
  ll res = INF;
  ll sz = 2 * POS_MAX + 1;
  vector<vector<ll>> XsR(sz), XsU(sz);
  REP(i, N) {
    if (U[i] == 'R') {
      XsR[X[i] + Y[i]].push_back(X[i]);
    } else if (U[i] == 'U') {
      XsU[X[i] + Y[i]].push_back(X[i]);
    }
  }
  REP(i, sz) {
    if (SZ(XsR[i]) == 0 || SZ(XsU[i]) == 0) {
      continue;
    }
    sort(ALL(XsR[i]));
    sort(ALL(XsU[i]));
    for (ll xr : XsR[i]) {
      if (XsU[i][0] > xr) {
        chmin(res, (-xr + XsU[i][0]) * 10);
        continue;
      }
      if (XsU[i].back() <= xr) {
        continue;
      }
      ll ng = 0, ok = SZ(XsU[i]) - 1;
      while (ng + 1 < ok) {
        ll m = (ok + ng) / 2;
        (XsU[i][m] > xr ? ok : ng) = m;
      }
      chmin(res, (-xr + XsU[i][ok]) * 10);
    }
  }
  return res;
}
int main() {
  cin >> N;
  X = vector<ll>(N);
  Y = vector<ll>(N);
  U = vector<char>(N);
  REP(i, N) { cin >> X[i] >> Y[i] >> U[i]; }
  ll ans = INF;
  REP(_, 4) {
    chmin(ans, solveForLine());
    chmin(ans, solveForVertical());
    rotate();
  }
  if (ans == INF) {
    cout << "SAFE" << endl;
    return 0;
  }
  cout << ans << endl;
}


Measured memory_bytes: 40804
Scanf.scanf "%s" (fun s ->
    let n = String.length s in
    let module S = Set.Make (struct type t = char let compare = compare end) in
    let rec loop i set =
        if i = 26 then set else loop (i + 1) (S.add (char_of_int (i + 97)) set)
    in
    let set = loop 0 S.empty in
    if n < 26 then (
        let rec loop i set =
            if i = n then Printf.printf "%s%c\n" s (S.min_elt set)
            else loop (i + 1) (S.remove s.[i] set)
        in
        loop 0 set
    ) else (
        let check s =
            let n = String.length s in
            let rec loop i set =
                if i = n then true else
                    if S.mem s.[i] set then false else
                        loop (i + 1) (S.add s.[i] set)
            in
            loop 0 S.empty
        in
        let rec loop len prefix cur =
            if cur = 26 then (
                if len = 0 then print_endline "-1" else
                    loop (len - 1) (String.sub prefix 0 (len - 1)) (int_of_char s.[len - 1] - 97 + 1)
            ) else (
                let s = Printf.sprintf "%s%c" prefix (char_of_int (cur + 97)) in
                if check s then print_endline s else
                    loop len prefix (cur + 1)
            )
        in
        loop n s 26
    )
)

Measured memory_bytes: 1792
#include<stdio.h>
#include<vector>
#include<algorithm>

using namespace std;

int main(){
  int n,k,k2,k4;
  int x,y;
  char c;
  int ans=0,sum,suma,sumb;

  scanf("%d%d", &n,&k);
  k2 = k*2;
  k4 = k2*2;
  vector<vector<int>> vvi(k4,vector<int>(k4,0));
  for(int i=0;i<n;++i){
    scanf("%d%d%*c%c",&x,&y,&c);
    if(c == 'B'){
      ++vvi[x%k2][y%k2];
      ++vvi[x%k2+k2][y%k2];
      ++vvi[x%k2][y%k2+k2];
      ++vvi[x%k2+k2][y%k2+k2];
    }else{
      ++vvi[x%k2][(y+k)%k2];
      ++vvi[x%k2+k2][(y+k)%k2];
      ++vvi[x%k2][(y+k)%k2+k2];
      ++vvi[x%k2+k2][(y+k)%k2+k2];
    }
  }
  for(int i=0;i<k4;++i){
    for(int j=0;j<k4-1;++j){
      vvi[j+1][i] += vvi[j][i];
    }
  }
  for(int i=0;i<k4;++i){
    for(int j=0;j<k4-1;++j){
      vvi[i][j+1] += vvi[i][j];
    }
  }
  for(int i=0;i<k2;++i){
    for(int j=0;j<k2;++j){
      suma = vvi[i+k][j+k] + vvi[i][j] - vvi[i+k][j] - vvi[i][j+k];
      sumb = vvi[i+k2][j+k2] + vvi[i+k][j+k] - vvi[i+k2][j+k] - vvi[i+k][j+k2];
      sum = suma + sumb;
      if(ans < sum) ans = sum;
    }
  }
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 62848
#include<iostream>
using namespace std;
long ans;
string s;
main()
{
	cin>>s;
	int n=s.size();
	for(int i=0;i<1<<(n-1);i++)
	{
		long sum=0;
		long now=0;
		for(int j=0;j<n;j++)
		{
			now*=10;
			now+=s[j]-48;
			if(i&1<<j)
			{
				sum+=now;
				now=0;
			}
		}
		sum+=now;
		ans+=sum;
	}
	cout<<ans<<endl;
}


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

using namespace std;

int main()
{
  int n,l;
  cin >> n >> l;
  vector<string> vi;
  for(int i=0;i<n;i++)
  {
    string st;
    cin >> st;
    vi.push_back(st);
  }
  sort(vi.begin(), vi.end());
  for(int i=0;i<vi.size();i++)
  {
    cout<<vi[i];
  }
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
#include <cmath>

#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
const int inf = 1e9;
const ll linf = 1LL << 50;
vector<int> edge[100001];

template <typename T>
struct Graph_ {
		int n;
		vector<vector<pair<int, T> > > edge;
		vector<T> dis;
		Graph_(int ns) {
				n = ns;
				edge.resize(n);
				dis.resize(n);
		}
		void dijkstra(int s){
				dijkstra(s, 0);
		}
		T dijkstra(int s, int t){
				// initialize
				fill(dis.begin(), dis.end(), -1);
				vector<bool> used;
				used.resize(n);
				fill(used.begin(), used.end(), false);
				dis[s] = 0;
				// dijkstra
				priority_queue<pair<T, int>, vector<pair<T, int> >, greater<pair<T, int> > > q;
				q.push(make_pair(0, s));
				while(!q.empty()){
						pair<T, int> p = q.top(); q.pop();
						int at = p.second;
						T distance = p.first;
            if(used[at])continue;
						used[at] = true;
						for(auto itr = edge[at].begin(); itr != edge[at].end(); ++itr){
								int to = (*itr).first;
								T cost = (*itr).second;
								if(used[to])continue;
								if(dis[to] == -1 || dis[to] > distance + cost){
										q.push(make_pair(distance + cost, to));
										dis[to] = distance + cost;
								}
						}
				}
				return dis[t];
		}
		void adde(int at, int to, T cost){
				edge[at].push_back(make_pair(to, cost));
		}
};

typedef struct Graph_<int> GraphI;
typedef struct Graph_<ll> GraphL;

int main(int argc, char const* argv[])
{
  int n;
  cin >> n;
  GraphI graph(100001);
  for(int i = 0; i < n; i++){
    int a;
    cin >> a;
    a--;
    graph.adde(i, a, 1);
  }
  graph.dijkstra(0);
  cout << graph.dis[1] << endl;
	return 0;
}


Measured memory_bytes: 8448
#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;
int main()
{
	int n;
	int a[200005],temp[200005];
	while(cin>>n)
	{
		for(int i=1;i<=n;i++)
		{
			scanf("%d",&a[i]);
			temp[i]=a[i];
		}
		sort(a+1,a+n+1);
		int  flag; 
		for(int i=1;i<=n;i++)
		  {
		     flag=temp[i];
		     if(flag<=a[n/2])cout<<a[n/2+1]<<endl;
		     else cout<<a[n/2]<<endl;
		   }
		
	}
}

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

using namespace std;

#define ll long long 
#define Coming ios_base :: sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"

int main()
{
	
	int a, b, c, d, e, k;
	
	cin >> a >> b >> c >> d >> e >> k;
	
	int ans1 = b-a;
	int ans2 = c-a;
	int ans3 = d-a;
	int ans4 = e-a;
	
	if(ans1 > k || ans2 > k || ans3 > k || ans4 > k)
	{
		cout << ":(\n";
		return 0;
	}
	
	
	int ans5 = c-b;
	int ans6 = d-b;
	int ans7 = e-b;
	
	
	if(ans5 > k || ans6 > k || ans7 > k)
	{
		cout << ":(\n";
		return 0;
	}
	
	int ans8 = d-c;
	int ans9 = e-c;
	
	if(ans8 > k || ans9 > k)
	{
		cout << ":(\n";
		return 0;
	}
	
    int ans10 = e-d;
    
    if(ans10 > k) 
    {
		cout << ":(\n";
		return 0;
	}
	
	cout << "Yay!\n";
	
	return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;

// Brainf*ck
public class Main {
	Scanner sc = new Scanner(System.in);

	String in;
	String[][] d;

	void run() {
		in = sc.nextLine();
		solve();
	}

	void solve() {
		int n = 256;
		int lb = 33, ub = 126;
		String[] plus = new String[n];
		String[] minus = new String[n];
		plus[0] = minus[0] = "";
		for (int i = 1; i < n; i++) {
			plus[i] = plus[i - 1] + '+';
			minus[i] = minus[i - 1] + '-';
		}
		d = new String[n][n];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				if (i < j) {
					update(i, j, plus[j - i]);
					update(i, j, minus[256 + i - j]);
				} else if (i > j) {
					update(i, j, minus[i - j]);
					update(i, j, plus[256 + j - i]);
				} else {
					update(i, j, "");
				}
			}
			update(i, 0, ">");
		}
		for (int a = 0; a < n; a++) {
			// +i*j
			for (int j = 1; j < n; j++) {
				for (int i = 1; i < n; i++) {
					// >i...i[<j...j>-]<
					int next = (a + i * j) % 256;
					if (can(a, next, i + j + 7)) {
						update(a, next, ">" + plus[i] + "[<" + plus[j] + ">-]<");
					}
					next = ((a - i * j) % 256 + 256) % 256;
					if (can(a, next, i + j + 7)) {
						update(a, next, ">" + plus[i] + "[<" + minus[j]
								+ ">-]<");
					}
				}
			}
			// *k
			for (int k = 2; k < 20; k++) {
				// [>k...k<-]>
				int next = a * k % 256;
				update(a, next, "[>" + plus[k] + "<-]>");
				next = (-a * k % 256 + 256) % 256;
				update(a, next, "[>" + minus[k] + "<-]>");
			}
			// /k
			for (int k = 2; k < 20; k++) {
				update(a, a / k, minus[a % k] + "[>+<" + minus[k] + "]>");
			}
		}
		int[][] p = new int[n][n], w = new int[n][n];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				p[i][j] = i != j ? i : -1;
				w[i][j] = d[i][j].length();
			}
		}
		for (int k = 0; k < n; k++) {
			for (int i = 0; i < n; i++) {
				for (int j = 0; j < n; j++) {
					if (w[i][k] + w[k][j] < w[i][j]) {
						w[i][j] = w[i][k] + w[k][j];
						p[i][j] = p[k][j];
					}
				}
			}
		}
		StringBuilder sb = new StringBuilder();
		char from = 0;
		for (char to : in.toCharArray()) {
			LinkedList<String> list = new LinkedList<String>();
			for (int now = to; now != from; now = p[from][now]) {
				list.addFirst(d[p[from][now]][now]);
			}
			for (String s : list) {
				sb.append(s);
			}
			sb.append('.');
			from = to;
		}
		String ans = sb.toString();
		println(ans);
	}

	boolean can(int i, int j, int len) {
		return len < 21 && (d[i][j] == null || len < d[i][j].length());
	}

	void update(int i, int j, String s) {
		if (d[i][j] == null || s.length() < d[i][j].length()) {
			d[i][j] = s;
		}
	}

	void println(String s) {
		System.out.println(s);
	}

	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 44936