akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
/*
#include<algorithm>
#include<array>
#include<cassert>
#include<cmath>
#include<cstdlib>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<typeinfo>
#include<utility>
#include<vector>
*/
#define int long long int
#define double long double
using namespace std;
#define MOD 1000000007
#define INF 1000000000000000007
const int MAX_N = 1 << 17;
#define rep(i, n) for (int(i) = 0, i##_len = (n); (i) < i##_len; (i)++)
#define reps(i, x) for (int(i) = 1; (i) <= (int)(x); (i)++)
#define rrep(i, x) for (int(i) = ((int)(x)-1); (i) >= 0; (i)--)
#define rreps(i, x) for (int(i) = ((int)(x)); (i) > 0; (i)--)
#define FOR(i, a, b) for (int(i) = (a); (i) < (b); (i)++)
#define pb push_back
#define mp make_pair
#define bit(n) ((int)(1) << (n))
#define all(x) (x).begin(), (x).end()
#define debug(x) std::cout << #x << ": " << (x) << std::endl
#define nint int
using namespace std;

int dy[] = {0, 0, 1, -1, 0};
int dx[] = {1, -1, 0, 0, 0};
typedef pair<int, int> pii;
typedef pair<double, double> dop;
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;
}
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
struct aaa {
    aaa()
    {
        cin.tie(0);
        ios::sync_with_stdio(0);
        cout << fixed << setprecision(20);
    };
} aaaaaaa;


signed main()
{
    int n;
    cin >> n;
    std::string s;

    cin >> s;
    std::vector<int> count(26, 1);
    for (int i = 0; i < n; i++) {
        count[(int)(s[i] - 'a')]++;
    }
    int sum = 1;
    for (int i = 0; i < 26; i++) {
        sum *= count[i];
        sum %= MOD;
    }
    cout << sum - 1 << endl;
    return 0;
}

Measured memory_bytes: 512
N = int(input())
A = [int(input()) for i in range(N)]
A.sort()
j = 1
J = 1
ans = 0
for j in range(1,len(A)):
  if (A[j-1] == A[j]):
    J += 1
  else:
    if (J%2 != 0):
      ans += 1
      J = 1
    else:
      J = 1
if (J%2 != 0):
  ans += 1
print(ans)

Measured memory_bytes: 7388
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

const (
	initialBufSize = 1e4
	maxBufSize     = 1e6 + 7
)

var buf []byte = make([]byte, maxBufSize)
var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(buf, maxBufSize)
}

func main() {
	N := nextInt()
	pf := primeFuctorize(N)
	var ans int
	for _, v := range pf {
		ans += cntTimes(v)
	}
	fmt.Println(ans)
}

func cntTimes(a int) int {
	sum := 0
	for i := 1; ; i++ {
		sum += i
		if sum > a {
			return i - 1
		}
	}
}

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func abs(a int) int {
	if a > 0 {
		return a
	} else {
		return -a
	}
}

func pow(p, q int) int {
	res := p
	if q == 0 {
		return 1
	}
	for i := 0; i < q-1; i++ {
		res *= p
	}
	return res
}

func MinOf(vars ...int) int {
	min := vars[0]
	for _, i := range vars {
		if min > i {
			min = i
		}
	}
	return min
}

func MaxOf(vars ...int) int {
	max := vars[0]
	for _, i := range vars {
		if max < i {
			max = i
		}
	}
	return max
}

func gcdof2numbers(a int, b int) int {
	if b == 0 {
		return a
	}
	return gcdof2numbers(b, a%b)
}

func lcmof2numbers(a int, b int) int {
	return a / gcdof2numbers(a, b) * b
}

// マイナスの場合は考慮していない
func fuctorial(a int) int {
	if a == 1 || a == 0 {
		return 1
	} else {
		return fuctorial(a-1) * a
	}
}

func NextPermutation(x sort.Interface) bool {
	n := x.Len() - 1
	if n < 1 {
		return false
	}
	j := n - 1
	for ; !x.Less(j, j+1); j-- {
		if j == 0 {
			return false
		}
	}
	l := n
	for !x.Less(j, l) {
		l--
	}
	x.Swap(j, l)
	for k, l := j+1, n; k < l; {
		x.Swap(k, l)
		k++
		l--
	}
	return true
}

// 素因数分解したmapを返す
func primeFuctorize(n int) map[int]int {
	pf := map[int]int{}
	for i := 2; i*i <= n; i++ {
		for n%i == 0 {
			pf[i]++
			n /= i
		}
	}
	if n != 1 {
		pf[n]++
	}
	return pf
}


Measured memory_bytes: 1812
#include <bits/stdc++.h>
#define int llint
#define rep(i, a, n) for(int (i) = (int)(a);(i) < (int)(n);++(i))
#define repe(i, a, n) for(int (i) = (int)(a);(i) <= (int)(n);++(i))
#define repif(i, a, x) for(int (i) = (int)(a);(x);++(i))
#define repr(i, a, n) for(int (i) = ((int)(a)-1);(i) >= (int)(n);--(i))
#define reper(i, a, n) for(int (i) = (int)(a);(i) >= (int)(n);--(i))
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define SIZE(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()
#define RNG(x, a, n) &((x)[a]), &((x)[n])
#define ADD(a, b) ((((a)%MOD)+((b)%MOD))%MOD)
#define MUL(a, b) ((((a)%MOD)*((b)%MOD))%MOD)
#define CEIL(x) ((int)ceil(((double)x)))
#define POW(x, y) ((int)pow(x, y))
#define UNIQUE(x) (x).erase(unique(ALL((x))), (x).end())
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define yes cout << "yes" << endl;
#define no cout << "no" << endl;
#define fcout cout << fixed << setprecision(10)
#define pb push_back
#define pf push_front
#define mp make_pair
#define mt make_tuple
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define EPS (1e-20)
#define INF 2147483647
#define MOD 1000000007
using llint = long long;
using VI = std::vector<int>;
using PII = std::pair<int, int>;
using SI = std::set<int>;
using MII = std::map<int, int>;
using TIII = std::tuple<int, int, int>;
using VLL = std::vector<llint>;
using MCI = std::map<char, int>;
using namespace std;


int N, K;
int x[60], y[60];


int cnt(int x1, int x2, int y1, int y2){
	int res = 0;
	rep(i, 0, N)
		if(x1 <= x[i] && x[i] <= x2 && y1 <= y[i] && y[i] <= y2) res++;
	return res;
}


int solve(){
	int ans = LLONG_MAX;
	rep(i, 0, N){
		rep(j, i+1, N){
			rep(k, 0, N){
				rep(l, k+1, N){
					int x1 = min(x[i], x[j]);
					int x2 = max(x[i], x[j]);
					int y1 = min(y[k], y[l]);
					int y2 = max(y[k], y[l]);
					if(cnt(x1, x2, y1, y2) >= K) chmin(ans, (x2-x1)*(y2-y1));
				}
			}
		}
	}
	return ans;
}



signed main(){
	cin >> N >> K;
	rep(i, 0, N) cin >> x[i] >> y[i];

	cout << solve() << endl;

	return 0;
}

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

int main(void){
    string S;
    cin >> S;
    int N = S.size();
    vector<char> Trans(S.size());
    if (S[0] == '0'){
        for(int i = 0;i < S.size(); i++){
            Trans[i] = i % 2 == 0 ? '0' : '1';
        }
    }else{
        for(int i = 0;i < S.size(); i++){
            Trans[i] = i % 2 == 0 ? '1' : '0';
        }
    }
    int count = 0;
    for(int i = 0;i < S.size();i++){
        if(S[i] != Trans[i]){
            count++;
        }
    }
    cout << min(count,N-count) << endl;
    return 0;
}


Measured memory_bytes: 512
# -*- coding: utf-8 -*-
n, k, q= map(int, input().split())
a=[k]*n
for i in range(q):
    p = int(input())
    a[p-1]+=1
for i in range(n):
    if a[i]-q > 0:
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 6596
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define ll long long
#define ull unsigned long long
#define db double
#define ldb long double
#define rep(i,a,b) for(i=a;i<=b;i++)
#define rev(i,a,b) for(i=b;i>=a;i--)
#define gcd(a,b) __gcd(a,b)
#define MOD 1000000007
#define scll(t) scanf("%lld",&t)
#define sclf(t) scanf("%lf", &t)
#define scst(t) scanf("%s", &t)
#define max(a,b) (a>=b?a:b)
#define min(a,b) (a<b?a:b)
#define MEM(a,b) memset(a, (b), sizeof(a))
#define all(v) v.begin(), v.end()
const double pi=acos(-1.0);
typedef pair<ll, ll> PII;
typedef vector<ll> VI;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef map<ll,ll> MPII;
typedef set<ll> SETI;
typedef multiset<int> MSETI;
typedef long int int32;
typedef unsigned long int uint32;
typedef long long int int64;
typedef unsigned long long int  uint64;

template <typename T> inline void write(T x)
{
	ll i = 20;
	char buf[21];
	// buf[10] = 0;
	buf[20] = '\n';

	do
	{
		buf[--i] = x % 10 + '0';
		x/= 10;
	}while(x);
	do
	{
		putchar(buf[i]);
	} while (buf[i++] != '\n');
}

void read(ll &x)
{
    bool neg=false;
    register ll c;
    x =0;
    c=getchar();
    if(c=='-')
    {
        neg = true;
        c=getchar();
    }
    for(;(c>47 && c<58);c=getchar())
        x = (x<<1) + (x<<3) +c -48;
    if(neg)
        x *=-1;
}



int main()
{
	ll w;
	string s;
	cin>>s;
	cin>>w;
	ll cnt=w-1;
	for(ll i=0;i<s.length();i++){
		cnt++;
		if(cnt==w){
			cout<<s[i];
			cnt=0;
		}
	}
	
	
	return 0;
}


















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

int main(){
  int n, m, b;
  long long a;
  cin >> n >> m;
  vector<pair<long long, int> > v;
  for ( int i = 0; i < n; i++){
    cin >> a >> b;
    v.push_back(make_pair(a, b));
  }
  sort(v.begin(), v.end());
  long long sumPrice = 0;
  int sumAmount = 0, crrAmount;
  for ( int i = 0; i < n; i++){
    pair<long long, int> p = v[i];
    crrAmount = min(m - sumAmount, p.second);
    sumAmount += crrAmount;
    sumPrice += p.first * crrAmount;
    if (sumAmount == m) break;
  }

  cout << sumPrice << endl;

  return 0;
}

Measured memory_bytes: 2420
#include<stdio.h>
int main(void){
    int n;
    scanf("%d",&n);
    int d[n];
    int a;
    int count = 0;
    for (int i = 0; i < n; i++)
    {
        scanf("%d",&d[i]);
    }
    for (int i = 0; i < n -1 ; i++)
    {
        for (int j = i + 1; j < n; j++)
        {
          a = d[i] * d[j];
          count += a;  
        }
        
    }
    printf("%d\n",count);
    return 0;
}

Measured memory_bytes: 1712
#include<iostream>
#include<vector>
#include<algorithm>
#define ll long long
using namespace std;
ll a[1000000 + 5];
//bool prime[1000000 + 5];
//ll b[1000000+5];
vector<ll> v;
constexpr auto mod = 1000000 + 7;
int gcd(int a, int b) {
	return b == 0 ? a : gcd(b, a % b);
}
int main() {
	vector<int> prime;
	vector<bool> isprime(1e6 + 5, true), cnt(1e6);
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	for(int i=2;i<=1000;i++)
		if (isprime[i]) {
			prime.push_back(i);
			for (int j = i * i; j <= 1000000; j += i)
				isprime[i] = false;
		}
	int n, gcd1 = 0,pairwise=1;
	cin >> n;
	while (n--) {
		int num;
		cin >> num;
		gcd1 = gcd(gcd1, num);
		if (pairwise) {
			for (int i = 0; i < prime.size() && (ll)prime[i] * prime[i] <= num; i++) {
				if (num % prime[i] == 0) {
					if (cnt[prime[i]]) {
						pairwise = 0;
						break;
					}
					cnt[prime[i]] = true;
					while (num % prime[i] == 0) {
						num /= prime[i];
					}
				}
			}
			if (num > 1)
			{
				if (cnt[num]) {
					pairwise = 0;
				}
				else
				{
					cnt[num] = true;
				}
			}
		}
	}
	if (pairwise == 1)
		cout << "pairwise coprime";
	else if (gcd1 == 1)
		cout << "setwise coprime";
	else
		cout << "not coprime";
	return 0;
}

Measured memory_bytes: 3388
// Author: Wenxing Mei
//   File: c.cpp
//   Date: 2019-03-10 23:43
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define per(i, b, a) for (int i = (int)b - 1; i >= (int)a; --i)
#define repv(ele, cont) for (auto &ele : cont)
#define all(x) x.begin(), x.end()
#define mp make_pair
#define eb emplace_back
#define ep emplace
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<ll> vll;
// END OF TEMPLATE

int main() {
#ifndef LOCAL
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#endif
    int N, M;
    cin >> N >> M;
    vii x(N);
    rep(i, 0, N) cin >> x[i].fi >> x[i].se;
    sort(all(x));
    ll c = 0;
    rep(i, 0, N) {
        if (M <= x[i].se) {
            c += 1ll * M * x[i].fi;
            break;
        } else {
            c += 1ll * x[i].fi * x[i].se;
            M -= x[i].se;
        }
    }
    cout << c << endl;
    return 0;
}


Measured memory_bytes: 1024
n = input()
if n[-1] == "2" or n[-1] == "4" or  n[-1] == "5" or  n[-1] == "7" or  n[-1] == "9":
  print("hon")
elif n[-1] == "0" or n[-1] == "1" or  n[-1] == "6" or  n[-1] == "8":
  print("pon")
elif n[-1] == "3":
  print("bon")

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

int main() {
    string S;
    cin >> S;
    int c = 0;
    for (int i = 0; i < 3; i++)
    {
        if(S[i] == 'o') c++;
    }
    int sum = 700 + 100 * c;
    cout << sum << endl;
}

Measured memory_bytes: 3640
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <utility>
#include <cstdio>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <cmath>
#include <set>
#include <map>
#define my_abs(x) ((x) < 0 ? -(x) : (x))
#define mp std::make_pair
#define pb push_back
typedef long long ll; 
ll MOD, fact[3005], inv[3005], dp[3005][3005], pw[10000005];
inline ll quick_pow(ll a, int n, ll mod)
{
	ll res = 1; 
	while (n)
	{
		if (n & 1)
			res = res * a % mod; 
		a = a * a % mod; 
		n >>= 1; 
	}
	return res; 
}
inline ll C(int n, int m)
{
	return fact[n] * inv[m] % MOD * inv[n - m] % MOD; 
}
int main()
{
	// freopen("ARC096-E.in", "r", stdin); 
	int n; 
	scanf("%d%lld", &n, &MOD); 
	fact[0] = inv[0] = 1; 
	for (int i = 1; i <= n; i++)
	{
		fact[i] = fact[i - 1] * i % MOD; 
		inv[i] = quick_pow(fact[i], MOD - 2, MOD); 
	}
	pw[0] = 1; 
	for (int i = 1; i < 10000005; i++)
		pw[i] = pw[i - 1] * 2 % MOD; 
	ll ans = 0; 
	dp[1][1] = 1; 
	for (int i = 2; i <= n; i++)
	{
		for (int j = 1; j <= i; j++)
			dp[i][j] = (dp[i - 1][j - 1] + j * dp[i - 1][j]) % MOD;
	}
	for (int i = 0; i <= n; i++)
	{
		ll coef = 1; 
		for (int k = 1; k <= i; k++)
			(coef += pw[(n - i) * k] * (dp[i][k + 1] * (k + 1) % MOD + dp[i][k])) %= MOD; 
		(ans += C(n, i) * coef % MOD * quick_pow(2, quick_pow(2, n - i, MOD - 1), MOD) * (i & 1 ? -1 : 1)) %= MOD;
	}
	printf("%lld\n", (ans + MOD) % MOD);
	return 0; 
}


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

#define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
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; }

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif




ll n, m;

struct numinfo {
	int digit;
	int match;
	int min_match;
	int n;
};


vector<numinfo> nums;


bool dfs( int i, int remain_match, int remain_keta ){
	if ( i == SZ(nums) ){
		eprintf( "remain=%d %d   ", remain_match, remain_keta );
		rep(k,SZ(nums)){
			eprintf( "%d ", (int)nums[k].n );
		}
		eprintf( "\n" );
		if ( remain_match == 0 && remain_keta <= 0 )
			return true;
		return false;
	}
	for ( int k = remain_match/nums[i].match; k >= 0; k-- ){
		nums[i].n = k;
		int creatable_keta = (remain_match-k*nums[i].match)/nums[i].min_match;
		if ( remain_keta-k-creatable_keta > 0 )
			continue;
		if ( dfs( i+1, remain_match-k*nums[i].match, remain_keta-k ) )
			return true;
	}
	return false;
}


int main(){
	cin >> n >> m;
	
	vector<int> a(m);
	rep(i,m){
		cin >> a[i];
	}
	sort(a.rbegin(),a.rend());
	
	int digit_to_match[] = { 0, 2, 5, 5, 4, 5, 6, 3, 7, 6 };
	set<int> s;
	rep(i,m){
		int match = digit_to_match[a[i]];
		if ( s.count(match) == 0 )
			nums.push_back({a[i],match,100,0});
		s.insert(match);
	}
	m = nums.size();
	
	int min_match = 100;
	for ( int i = nums.size()-1; i >= 0; i-- ){
		nums[i].min_match = min_match;
		chmin(min_match, nums[i].match);
		eprintf( "digit,=%d match=%d min_match=%d\n", nums[i].digit, nums[i].match, nums[i].min_match );
	}
	
	for ( int keta = n / min_match; keta > 0; keta-- ){
		eprintf( "\n\nketa=%d\n", keta );
		if ( dfs( 0, n, keta ) ){
			sort(nums.begin(), nums.end(), [](numinfo &l, numinfo &r){
				return l.digit>r.digit;
			});
			rep(i,m){
				rep(j,nums[i].n){
					cout << nums[i].digit;
				}
			}
			cout << endl;
			return 0;
		}
	}
	
	return 0;
}




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

using ll = long long;

class union_find {
public:
    union_find(int n) : par(n, -1) {}

    int root(int x) {
        return par[x] < 0 ? x : par[x] = root(par[x]);
    }

    bool unite(int x, int y) {
        x = root(x), y = root(y);
        if(x == y) return false;
        if(par[x] > par[y]) swap(x, y);
        par[x] += par[y];
        par[y] = x;
        return true;
    }

    int size(int x) {
        return -par[root(x)];
    }

private:
    vector<int> par;
};

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

    ll cur = (ll)n * (n - 1) / 2;
    union_find uf(n);
    vector<ll> ans(m);
    for(int i = m - 1; i >= 0; --i) {
        ans[i] = cur;
        const ll sz1 = uf.size(a[i]), sz2 = uf.size(b[i]);
        if(uf.unite(a[i], b[i])) {
            cur -= sz1 * sz2;
        }
    }

    for(int i = 0; i < m; ++i) {
        cout << ans[i] << endl;
    }
}


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

#define int long long
#define endl "\n"
#define MOD 1000000007
#define INF 1000000010
#define EPS 1e-9
#define fst first
#define scd second

#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define lp(i,n) rep(i,n)
#define repn(i,n) for(int i=n;i>=0;i--)

signed main(){
  cin.tie(0);
  //ios::sync_with_stdio(false);
  string s;
  cin>>s;
  stack<char> c,cprev;
  stack<int> now,nowprev,prevmove;
  now.push(1);
  prevmove.push(-1);
  int ans=0;
  int num=0,num2=0;
  rep(i,s.size() ){

    if(s[i]=='(' || s[i]==')'){
      if(s[i]=='('){
        c.push(s[i]);
        if(prevmove.top() == 0) now.push(1);
        prevmove.push(0);
      }else{
        if(c.empty() ){
          prevmove.push(2);
          nowprev.push(now.top());
          now.pop();
          now.push(1);
        }else{
          cprev.push(c.top());
          c.pop();
          if(prevmove.top() == 1){

            nowprev.push(now.top() );
            now.pop();

          }
          ans+=now.top();
          num=now.top();now.pop();
          now.push(num+1);
          prevmove.push(1);
        }
      }
      cout<<ans<<endl;
    }else{
      num=prevmove.top();prevmove.pop();
      if(num==2){
        cout<<ans<<endl;
        now.pop();
        now.push(nowprev.top() );
        nowprev.pop();
        continue;
      }
      if(num==1){
        c.push(cprev.top() );cprev.pop();
        num2=now.top();now.pop();
        ans-=(num2-1);
        now.push(num2-1);
        if(prevmove.top() == 1){
          if(nowprev.top() == -1) nowprev.pop();
          else{
            now.push(nowprev.top() );
            nowprev.pop();
          }
        }
      }else{
        if(prevmove.top() == 0) now.pop();
        c.pop();
      }
      cout<<ans<<endl;
    }
  }




  return 0;
}



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

int main(){
    string s;
    cin >> s;
    for(int i=s.size()-2;i>0;i-=2){
        string sub1 = s.substr(0,i/2), sub2 = s.substr(i/2,i/2);
        if(sub1 == sub2){
            cout << i << endl;
            break;
        }
    }

    return 0;
}


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

int main(void){
    string S,T;
    cin >> S;
    cin >> T;

    int count = 0;
    for(int i=0;i < S.length();i++){

        if(S[i] != T[i]){
            count++;
        }
    }

    cout << count << endl;

    return 0;
}

Measured memory_bytes: 3916
#include<stdio.h>
#include<math.h>

int main(){
	int i,n;
	long min,max,sum=0;
	long array[10000]={0};
	
	scanf("%d",&n);
	
	for(i=0;i<n;i++){
		scanf("%ld",&array[i]);
		
		if(i==0){
			min = array[i];
			max = array[i];
		}else{
			if(min>array[i]){
				min = array[i];
			}
			if(max<array[i]){
				max = array[i];
			}
		}
		sum += array[i];
	}

	printf("%ld %ld %ld\n",min,max,sum);
	
return 0;
}


Measured memory_bytes: 2080
<?php
$h = (int)trim(fgets(STDIN));
if ($h == 1) {
	echo 1;
	exit();
}

$cnt = 0;
while (true) {
	$h = (int)floor($h/2);
	$cnt += 1;
	if ($h == 0) {
		break;
	}
}
echo pow(2, $cnt) - 1;

Measured memory_bytes: 4604
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i, s, n) for (int i = (s); i < (n); i++)
#ifdef LOCAL
#define INPUT_FILE                   \
  ifstream in("atcoder-problems/abc079_b.txt"); \
  cin.rdbuf(in.rdbuf());
#define print_vec(v) \
rep(l, v.size()) { cout << v[l] << " "; } \
cout << endl;
#else
#define INPUT_FILE
#define print_vec(v)
#endif
#define CIN_OPTIMIZE \
  cin.tie(0);        \
  ios::sync_with_stdio(false);
typedef pair<int, int> P;
typedef long long ll;
typedef pair<ll, ll> pl;
const int INF = 100100100;
const ll LINF = 1e18+100;
const int MOD = 1e9 + 7;

int main() {
  INPUT_FILE CIN_OPTIMIZE;

  int N;
  cin >> N;
  
  vector<ll> c(N + 1);
  c[0] = 2;
  c[1] = 1;
  repi(i, 2, N + 1) { c[i] = c[i - 2] + c[i - 1]; }

  cout << c[N] << endl;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> l(n);
  for(int i = 0; i < n; i++) cin >> l.at(i);
  
  sort(l.begin(), l.end());
  int ans = 0;
  for(int i = 0; i < n; i++){
    for(int j = i+1; j < n; j++){
      for(int k = j+1; k < n; k++){
        int x = l.at(i), y = l.at(j), z = l.at(k);
        if(x == y || y == z) continue;
        if(x + y <= z) continue;
        ans++;
      }
    }
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
 
int main(){
int N;  cin >> N;
vector<int> H(N); 
for (int i = 0; i < N; i++) {
    cin >> H[i];
}

for (int i = N - 1; i > 0; i--) {
    if (H[i] >= H[i - 1]) {
        continue;
    } else if (H[i] == H[i - 1] - 1) {
        H[i - 1] = H[i - 1] - 1;
    } else {
        cout << "No" << endl;
        return 0;
    }
}

cout << "Yes" << endl;

}

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


int dfs(int i, auto& visited, auto& llst)
{
    visited[i] = true;

    int visited_cnt = 0;
    rep(k, visited.size()) if (visited[k]) ++visited_cnt;
    if (visited_cnt == llst.size()) {
        visited[i] = false;
        return 1;
    }

    int cnt = 0;
    for (auto j: llst[i]) {
        if (visited[j]) continue;
        cnt += dfs(j, visited, llst);
    }
    visited[i] = false;

    return cnt;
}


int main()
{
    int N, M, a, b;
    cin >> N >> M;
    vector<vector<int>> llst(N);
    rep(i,M) {
        cin >> a >> b; a--; b--;
        llst[a].push_back(b);
        llst[b].push_back(a);
    }

    vector<bool> visited(N, false);
    cout << dfs(0, visited, llst) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define LL long long
#define ull unsigned long long
#define ULL ull
#define mp make_pair
#define pii pair<int,int>
#define piii pair<int, pii >
#define pll pair <ll,ll>
#define pb push_back
#define big 20160116
#define INF 2147483647
#define pq priority_queue
using namespace std;
inline 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;
}
namespace Mymath{
	LL qp(LL x,LL p,LL mod){
		LL ans=1;
		while (p){
			if (p&1) ans=ans*x%mod;
			x=x*x%mod;
			p>>=1;
		}
		return ans;
	}
	LL inv(LL x,LL mod){
		return qp(x,mod-2,mod);
	}
	LL C(LL N,LL K,LL fact[],LL mod){
		return fact[N]*inv(fact[K],mod)%mod*inv(fact[N-K],mod)%mod;
	}
	template <typename Tp> Tp gcd(Tp A,Tp B){
		if (B==0) return A;
		return gcd(B,A%B);
	}
	template <typename Tp> Tp lcm(Tp A,Tp B){
		return A*B/gcd(A,B);
	}
};
namespace fwt{
	using namespace Mymath;
	void FWT(int a[],int n,LL mod)
	{
	    for(int d=1;d<n;d<<=1)
	        for(int m=d<<1,i=0;i<n;i+=m)
	            for(int j=0;j<d;j++)
	            {
	                int x=a[i+j],y=a[i+j+d];
	                a[i+j]=(x+y)%mod,a[i+j+d]=(x-y+mod)%mod;
	                //xor:a[i+j]=x+y,a[i+j+d]=x-y;
	                //and:a[i+j]=x+y;
	                //or:a[i+j+d]=x+y;
	            }
	}

	void UFWT(int a[],int n,LL mod)
	{
		LL rev=inv(2,mod);
	    for(int d=1;d<n;d<<=1)
	        for(int m=d<<1,i=0;i<n;i+=m)
	            for(int j=0;j<d;j++)
	            {
	                int x=a[i+j],y=a[i+j+d];
	                a[i+j]=1LL*(x+y)*rev%mod,a[i+j+d]=(1LL*(x-y)*rev%mod+mod)%mod;
	                //xor:a[i+j]=(x+y)/2,a[i+j+d]=(x-y)/2;
	                //and:a[i+j]=x-y;
	                //or:a[i+j+d]=y-x;
	            }
	}
	void solve(int a[],int b[],int n,LL mod)
	{
	    FWT(a,n,mod);
	    FWT(b,n,mod);
	    for(int i=0;i<n;i++) a[i]=1LL*a[i]*b[i]%mod;
	    UFWT(a,n,mod);
	}
};
const int Maxn=705;
int n,m;
int adj[Maxn][Maxn];
int col[Maxn];
int cnt1,cnt2;
void dfs(int x,int c){
	col[x]=c;
	if (c==1) cnt1++;
	else cnt2++;
	for (int i=1;i<=n;i++){
		if (adj[x][i]){
			if (col[i] && col[i]==c){
				printf("-1\n");
				exit(0);
			}
			if (!col[i]){
				dfs(i,3-c);
			}
		}
	}
}
int dp[Maxn][Maxn];
int main(){
	scanf("%d %d",&n,&m);
	for (int i=0;i<m;i++){
		int u,v;
		scanf("%d %d",&u,&v);
		adj[u][v]=adj[v][u]=true;
	}
	for (int i=1;i<=n;i++){
		for (int j=1;j<=n;j++){
			if (i!=j) adj[i][j]^=1;
		}
	}
	vector<pii > v;
	for (int i=1;i<=n;i++){
		if (col[i]==0){
			cnt1=cnt2=0;
			dfs(i,1);
			v.pb(mp(cnt1,cnt2));
		}
	}
	dp[0][0]=1;
	for (int i=0;i<v.size();i++){
		for (int j=0;j<=n;j++){
			if (j>=v[i].first)dp[i+1][j]|=dp[i][j-v[i].first];
			if (j>=v[i].second) dp[i+1][j]|=dp[i][j-v[i].second];
		}
	}
	int d=v.size();
	int ans=1e9;
	for (int i=0;i<=n;i++){
		if (dp[d][i]) ans=min(ans,(i-1)*(i)/2+(n-i-1)*(n-i)/2);
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 4096
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int ans=0;
    int n;
    int l,r;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>l>>r;
        ans+=r-l+1;//l到r的人数为l-r+1(公式)
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
def get_next(chr):
    if chr == 'a':
        return a.pop(0)
    if chr == 'b':
        return b.pop(0)
    if chr == 'c':
        return c.pop(0)        

a,b,c=(list(input()) for x in range(3))

n=a.pop(0)
while not ((len(a)==0 and n=='a') or (len(b)==0 and n=='b') or (len(c)==0 and n=='c')):
    n = get_next(n)

print (str.upper(n))

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

int main(){
  int N, M;
  cin >> N >> M;
  vector<pair<int, int>> P(N);
  int A, B;
  for(int i=0; i<N; i++){
    cin >> A >> B;
    P.at(i)=make_pair(A, B);
  }
  sort(P.begin(), P.end());
  int Now=0;
  int64_t Ans=0;
  for(int i=0; i<M; i++){
    if(P.at(Now).second>0){
      P.at(Now).second--;
      Ans+=P.at(Now).first;
    }
    else{
      Now++;
      i--;
    }
  }
  cout << Ans << endl;
}

Measured memory_bytes: 1024
#include<iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
	vector<uint16_t> A;
	for (size_t i = 0; i < 9; ++i)
	{
		uint16_t a_ij;
		cin >> a_ij;
		A.push_back(a_ij);
	}

	size_t N;
	cin >> N;
	if (N >= 3)
	{
		vector<uint16_t>::iterator itr;
		uint16_t hit(0);
		for (size_t i = 0; i < N; ++i)
		{
			uint16_t bn(0);
			cin >> bn;
			itr = find(A.begin(), A.end(), bn);
			if (itr != A.end())
				hit |= 1 << distance(A.begin(), itr);
		}
		const uint16_t tate(1 | 1 << 3 | 1 << 6);
		const uint16_t yoko(1 | 1 << 1 | 1 << 2);
		const uint16_t naname1(1 | 1 << 4 | 1 << 8);
		const uint16_t naname2(1<<2 | 1 << 4 | 1 << 6);

		for (size_t i = 0; i < 3; ++i)
		{
			uint16_t check;
			check = tate << i;
			if ((hit & check) == check)
			{
				cout << "Yes" << endl;
				return 0;
			}
			check = yoko << i*3;
			if ((hit & check) == check)
			{
				cout << "Yes" << endl;
				return 0;
			}
		}
		if ((hit & naname1) == naname1
			|| (hit & naname2) == naname2)
		{
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 3064
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> //tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;

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

  cout << (N * (N - 1) + M * (M - 1)) / 2 << endl;
}

Measured memory_bytes: 256
//g++ -std=c++14 test.cpp -o test.out

#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <stack>
#include <map> 
#include <unordered_map> 
#include <utility>
#include <limits.h>
#include <bitset>
#include <set>
using namespace std;
 
#define LL unsigned long long int
const LL INF = (1LL<<60);
const int INF_INT = 2147483647-1e6-1;
const LL mod = 1000000007ll;
const int mod_int = 1000000007;

LL N,P;
string S;

LL ans = 0;

void solve(){
	reverse(S.begin(),S.end());
	if(P==2 || P==5){
		for(int i=0;i<N;i++){
			LL num = S[i] - '0';
			if(num%P==0) ans += (N-i);
		}
		return;
	}

	vector<LL> pow10(200001,1);
	for(int i=1;i<=200000;i++) pow10[i] = (pow10[i-1]*10LL)%P;

	//1桁目からi桁目までを1つの数値とみなした時
	//それをPで割ったあまりをsub[i]とする
	//ただしsub[0]=0ときめる
	vector<LL> sub(N+1,0);
	for(int i=0;i<N;i++){
		LL num = S[i] - '0';
		sub[i+1] = (sub[i]+(num*pow10[i])%P)%P;
	}

	//subのうち、Pで割ったあまりがiのものの数を
	//classfied_by_mod[i]とする
	vector<LL> classfied_by_mod(P,0);
	for(int i=0;i<=N;i++){
		classfied_by_mod[sub[i]]++;
	}

	for(int i=0;i<P;i++){
		ans += (classfied_by_mod[i]-1)*classfied_by_mod[i]/2;
	}
}

int main(){
    cin >> N >> P;
    cin >> S;

    solve();

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

Measured memory_bytes: 3716
#include <bits/stdc++.h>
#include <cstdlib>
using namespace std;
#define ll long long
typedef vector<vector<ll> > matrix;
#define pb push_back
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
const double PI  =3.141592653589793238463;
long long MOD = 1000000007;

int stringToInteger(string x){
    int gg=0;
    stringstream geek(x);
    geek >> gg;
    return gg;
}

ll powmod(ll a,ll b,ll m)
{
    ll ans=1;
    while(b>0){ if(b%2)
        {ans*=a; ans%=m;}
         b/=2; a=a*a; a=a%m;
        }
        return ans%m;
}
ll gcd(ll a,ll b)
{

    return __gcd(a,b);
}
ll mulmod(ll a,ll b,ll m)
{  ll ans=0;
    a %=m;
    while (b>0)
    {       if(b&1) ans = (ans + a) % m;
        a = (a * 2)%m;
        b /= 2;
    }
    return ans % m;
}

ll f[2000001];



ll pow(ll a, ll b, ll MOD)
{
 ll x=1,y=a;
 while(b > 0)
 	{
 		if(b%2 == 1)
 	{
 		x=(x*y);
 		if(x>MOD) x%=MOD;
 	}
 	y = (y*y);
 	if(y>MOD) y%=MOD;
 	b /= 2;
 	}
 return x;
}

/* Modular Multiplicative Inverse
 Using Euler's Theorem
 a^(phi(m)) = 1 (mod m)
 a^(-1) = a^(m-2) (mod m) */
ll InverseEuler(ll n, ll MOD)
{
 return pow(n,MOD-2,MOD);
}

bool prime[100005];
void seive()
{  memset(prime,true,sizeof(prime));
    for(int i=2;i*i<=100005;i++)
    {
         if(prime[i]==true) {
        for(int j=2*i;j<=(100005);j+=i)
           { prime[j]=false;}
           }

    }
}
bool in(float x1,float y1,float x,float y,float r )
{
    if(abs(x1-x)*abs(x1-x)+abs(y1-y)*abs(y1-y)<=r*r) return true;
    return false;
}
bool cmp(pair<int,int> &a,pair<int,int> &b)
{

        return (a.second<b.second);
}
//
//vector<vector<int> >matrix;
matrix mul(matrix A,matrix B)
{
    matrix C(3, vector<ll>(3));
    for(int i=1;i<=2;i++)
    for(int j=1;j<=2;j++)
     for(int k=1;k<=2;k++)
         C[i][j] = (C[i][j] + A[i][k] * B[k][j]);
    return C;

}
matrix pow(matrix A, int p)
{
    if (p == 1)
        return A;
    if (p % 2)
        return mul(A, pow(A, p-1));
    matrix X = pow(A, p/2);
    return mul(X, X);
}
ll fib(int N,int a,int b)
{
    vector<ll> F1(3);
    F1[1] = a;
    F1[2] = b;
    matrix T(3, vector<ll>(3));
    T[1][1] = 0, T[1][2] = 1;
    T[2][1] = -1, T[2][2] = 1;
    if (N == 1)
        return a;
    if(N==2) return b;
    T = pow(T, N-1);
    ll res = 0;
    for(int i=1;i<=2;i++)
        res = (res + T[1][i] * F1[i]+ MOD)%MOD ;
    return res;
}

//1 2 3 4 5
int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

 int t =1;
 while(t--)
  {
      int n;
      cin>>n;
      vector<int>v;
      map<int,int>mp;
      ll ans;
      for(int i=0;i<n;i++)
      {
          ll a;
          cin>>a;
          mp[a]++ ;
          if(mp[a]==2) {v.pb(a); mp[a]=0;}

      }
      sort(v.begin(),v.end());
      int k = v.size();
      if(k>=2)
cout<<1ll*v[k-1]*v[k-2];
else cout<<0;
     // 3 0 3 0 3

  }
}


Measured memory_bytes: 4992
#include <iostream>

using namespace std;

int main(int argc, const char * argv[]) {
    int K, S;
    cin >> K >> S;
    
    int count = 0;
    //cout << "X" << "\t" << "Y" << "\t" << "Z" << endl;
    for(int X = 0; X <= K; X++)
    {
        for(int Y = 0; Y <= S-X; Y++)
        {
            int Z = S-X-Y;
            if (X >= 0 && Y >= 0 && Z >= 0 &&
                X <= K && Y <= K && Z <= K)
            {
                //cout << X << "\t" << Y << "\t" << Z << endl;
                count++;
            }
            
        }
    }
    
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 760
import java.util.*;

public class Main {
	public static void main(String[] args) {
		PriorityQueue<String> caca = new PriorityQueue<String>();
		Scanner scn = new Scanner(System.in);
		int n = scn.nextInt();
		int n2 = scn.nextInt();
		for(int i = 0;i<n;i++)caca.add(scn.next());
		for(int i = 0;i<n;i++)System.out.print(caca.poll());
		System.out.println();
		scn.close();
	}
}

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

int main(){
	double n,y,num;
    while(cin >> n,n){
        cin >> y;
        double r,b,t,ma = -1000,tmp;
        while(n--){
            cin >> b >> r >> t;
            if(t == 1){
                tmp = (1.0+y*(r/100.0));
                if(ma < tmp){
                    ma = tmp;
                    num = b;
                }
            }
            else if(t == 2){
                tmp = (1.0+(r/100.0));
                tmp = pow(tmp,y);
                if(ma < tmp){
                    ma = tmp;
                    num = b;
                }
            }
        }
        cout << num << endl;
    }
}

Measured memory_bytes: 1364
s = str(input())
if s == 'SUN':
    print(7)
if s == 'MON':
    print(6)
if s == 'TUE':
    print(5)
if s == 'WED':
    print(4)
if s == 'THU':
    print(3)
if s == 'FRI':
    print(2)
if s == 'SAT':
    print(1)

Measured memory_bytes: 3060
/*
Haskell???TLE????????????C++??§????????????

URL: http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_4_C&lang=jp
?????????: Search - Dictionary
????\???????: 19:48:20-

*/
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <set>
#include <string>
using namespace std;

set<string> g;

int main()
{
	int n;
	cin >> n;
	for(int i=0; i<n; i++) {
		string a,b;
		cin >> a >> b;
		if(a == "insert") {
			g.insert(b);
		} else {
			cout << (g.count(b) ? "yes" : "no") << endl;
		}
	}
}

Measured memory_bytes: 32208
def prime_factors(n):
    i = 2
    factors = []
    while i * i <= n:
        if n % i:
            i += 1
        else:
            n //= i
            factors.append(i)
    if n > 1:
        factors.append(n)
    return factors

N, P = [int(e) for e in input().split()]

l = prime_factors(P)

c = 1
for n in list(set(l)):
    c *= n ** (l.count(n) // N)

print(c)

Measured memory_bytes: 3060
#include<stdio.h>
#define MAX 500001

int A[MAX],H;

void MaxHeapify(int x){
  int l,r,largest;
  l = 2*x;
  r = 2*x+1;

  if(l<=H && A[l] > A[x]){
    largest = l;
  }
  else largest = x;
  if(r<=H && A[r] > A[largest]){
    largest = r;
  }
  if(largest!=x){
    int tmp = A[x];
    A[x]=A[largest];
    A[largest]= tmp;
    MaxHeapify(largest);
  }
  return ;
}

void BuildMaxHeap(){
  int i;
  for(i=H/2;i>=1;i--){
    MaxHeapify(i);
  }
  return;
}

int main(){
  int i;
  scanf("%d",&H);
  for(i=1;i<=H;i++){
    scanf("%d",&A[i]);
  }
  BuildMaxHeap();
  for(i=1;i<=H;i++)printf(" %d",A[i]);
  printf("\n");
  return 0;
}



Measured memory_bytes: 3672
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i, s, n) for (int i = (s); i < (n); i++)
typedef pair<int, int> P;
typedef long long ll;
const int INF = 100100100;
const int MOD = 1e9 + 7;

int main() {

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

  int N , M;
  cin >> N >> M;
  
  vector<vector<int>> c(N);
  vector<int> P(M);
  vector<int> Y(M);

  rep(i, M) {
    cin >> P[i] >> Y[i];
    c[--P[i]].push_back(Y[i]);
  }

  rep(i, N) { sort(c[i].begin(), c[i].end()); }
  rep(i, M) {
    ll id = lower_bound(c[P[i]].begin(), c[P[i]].end(), Y[i]) -  c[P[i]].begin();
    printf("%06d%06lld\n", P[i] + 1, id + 1);
  }
}

Measured memory_bytes: 7808
#define HAVE_STRUCT_TIMESPEC
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a,b;
    cin>>a>>b;
    int ans=0;
    if(b==1){
        cout<<0;
        return 0;
    }
    for(int i=1;i<=27;++i){
        ans=i*a-i+1;
        if(ans>=b){
            ans=i;
            break;
        }
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 256
function Main(input){
  input = input.trim().split('\n');
  var K = input[0];
  var S = input[1];
  var ans = '';
  if (S.length <= K){
    ans = S;
  }else{
    ans = S.slice(0,K) + '...';
  }
  console.log(ans);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 30132
use std::io::{self, BufRead};
use std::collections::HashMap;
use std::cmp::max;
use std::mem::swap;

fn main() {
  let stdin = io::stdin();
  let mut lines = stdin.lock().lines();
  let line = lines.next().unwrap().unwrap();
  let vs: Vec<usize> = line.split(' ').map(|x| x.parse().unwrap()).collect();
  let n = vs[0];
  let k = vs[1];
  let line = lines.next().unwrap().unwrap();
  let vs: Vec<usize> = line.split(' ').map(|x| x.parse().unwrap()).collect();
  let r = vs[0];
  let s = vs[1];
  let p = vs[2];
  let t: Vec<char> = lines.next().unwrap().unwrap().chars().collect();
  let points: Vec<Vec<usize>> = vec![vec![0, 0, p], vec![r, 0, 0], vec![0, s, 0]];
  let char_to_usize: HashMap<char, usize> = [('r', 0), ('s', 1), ('p', 2)].iter().cloned().collect();
  let mut total: usize = 0;
  for i in 0..k {
    let len = n / k + (if i < n % k { 1 } else { 0 });
    let mut temp: Vec<usize> = vec![0; 3];
    let o = char_to_usize[&t[i]];
    for s in 0..3 {
      temp[s] = points[o][s];
    }
    for j in 1..len {
      let mut next: Vec<usize> = vec![0; 3];
      let o = char_to_usize[&t[j*k+i]];
      next[0] = max(temp[1] + points[o][0], temp[2] + points[o][0]);
      next[1] = max(temp[2] + points[o][1], temp[0] + points[o][1]);
      next[2] = max(temp[0] + points[o][2], temp[1] + points[o][2]);
      swap(&mut temp, &mut next);
    }
    total += *temp.iter().max().unwrap();
  }
  println!("{}", total);
}

Measured memory_bytes: 4476
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
mt19937 mrand(random_device{}()); 
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head

const int N=201000;
int a[N],b[N],n;
priority_queue<PII> q;
ll cnt;
void fail() {
	puts("-1");
	exit(0);
}
int main() {
	scanf("%d",&n);
	for (int i=1;i<=n;i++) scanf("%d",a+i);
	for (int i=1;i<=n;i++) scanf("%d",b+i),q.push(mp(b[i],i));
	while (!q.empty()) {
		int u=q.top().se; q.pop();
		int pr=(u+n-2)%n+1,nx=u%n+1;
		if (b[u]==a[u]) continue;
		if (b[u]<a[u]) fail();
		if (a[u]>=b[pr]&&a[u]>=b[nx]) {
			if ((b[u]-a[u])%(b[pr]+b[nx])!=0) fail();
			cnt+=(b[u]-a[u])/(b[pr]+b[nx]);
			b[u]=a[u]; continue;
		}
		if (b[u]<b[pr]+b[nx]) fail();
		cnt+=b[u]/(b[pr]+b[nx]);
		b[u]%=b[pr]+b[nx];
		if (b[u]==0) fail();
		q.push(mp(b[u],u));
	}
	printf("%lld\n",cnt);
}


Measured memory_bytes: 3700
import sys

# A - Multiple Array
N = int(input())
A, B =[], []

for _ in range(N):
  a, b = map(int, input().split())
  A.append(a)
  B.append(b)

A.reverse()
B.reverse()
count = 0

for i in range(N):
  a = A[i] + count

  if a % B[i] != 0:
    quotient = a // B[i]
    count += B[i] * (quotient+1) - a

print(count)

Measured memory_bytes: 16848
#include<iostream>
using namespace std;
int main()
{
  int n;
  for(;cin>>n,n;)
    {
      bool l=false,r=false;
      bool next=true;
      int cnt=0;
      for(int i=0;i<n;i++)
	{
	  string str;
	  cin>>str;

	  if(str=="lu")
	    l=true;
	  if(str=="ru")
	    r=true;
	  if(str=="ld")
	    l=false;
	  if(str=="rd")
	    r=false;
	  if(next==l && next==r)
	    {
	      cnt++;
	      next=!next;
	    }
	}
    cout<<cnt<<endl;
    }
}

Measured memory_bytes: 1208
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <queue>
#include <unordered_map>

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

using namespace std;

ll gcd(ll a, ll b) {
    if(a < b)
        return gcd(b,a);
    if(b ==0)
        return a;
    ll x = a%b;
    if(b/2 < x)
        return gcd(b, b-x);
    return gcd(b, x);
}

int main(){
    ll n,m; cin>> n >> m;
    vector<ll> a(n);
    for(ll i = 0; i< n; i++) {
        cin >> a[i];
    }
    ll x = a[0];
    ll y = 0;
    while(x%2==0) {
        x /= 2;
        y++;
    }
    ll shift = 1ll << y;
    for(ll i = 0; i< n; i++) {
        if(a[i]%shift != 0 || a[i]%(shift << 1) == 0) {
            cout << 0 << endl;
            return 0;
        }
    }
    for(ll i = 0; i< n; i++) {
        a[i] >>= 1;
    }
    vector<ll> ruiseki(n);
    ruiseki[0] = a[0];
    for(ll i = 1; i< n; i++) {
        ruiseki[i] = ruiseki[i-1]*a[i]/gcd(ruiseki[i-1], a[i]);
        if(ruiseki[i] > m) {
            cout << 0 << endl;
            return 0;
        }
    }

    printf("%lld\n", ll(ceil(m/ruiseki[n-1]/2.0)));
}


Measured memory_bytes: 1792
#include<stdio.h>
int main(void)
{
	char s[3][4];
	for (int i = 0; i < 3; i++) {
		for (int j = 0; j < 4; j++) {
			scanf("%c", &s[i][j]);
			//printf("%d%d%c", i, j, s[i][j]);
		}
	}
	printf("%c%c%c", s[0][0], s[1][1], s[2][2]);

	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <cmath>
using namespace std;
#define fast                                                                   \
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int long long
#define ll long long
#define f(i, n) for (int i = 0; i < n; i++)
#define fo(i,a,n) for (i = a; i <= n; i++)
#define F first
#define S second
#define pii pair<int,int>
#define sz size()
#define all(v) v.begin(),v.end()
#define pb push_back
#define pf push_front    
#define PB pop_back
#define pll pair<long long, long long>
#define vi vector<int>
#define vl vector<int>
#define mp make_pair
#define mod 1000000007
typedef unsigned long long ull;
const int N = 200005;
const int MOD = 998244353 ;



void solve(){
    int a, b, k;
    cin>>a>>b>>k;
    if(k <= a){
        cout<<(a-k)<<" "<<b;
        return ;
    }
    k -= a;
    a = 0;
    b -= k;
    b = max(b,0ll);
    cout<<a<<" "<<b;
}


int32_t main() {
    fast
    int t;
    t = 1;
    //cin >> t;
    while(t--)solve();
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

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

int main()
{
	string S, T;
	int match = 0;
	cin >> S;
	cin >> T;

	rep(i, 3) if (S[i] == T[i]) match++;

	cout << match << endl;

	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void) {
    int i;
    int k;
    int N[100];
    int check=0;
 
    do{
      scanf("%d", &k);
    }while(k<1||k>100);
  
    for(i=0; i<k; i++){
       do{
       scanf("%d", &N[i]); 
       }while(N[i]<1||N[i]>1000);
    }
    for(i=0; i<k; i++){ 
       if(N[i]%2==0){
         if(N[i]%3!=0&&N[i]%5!=0){ 
           check=1;
         }
       } 
    }
    if(check==0) puts("APPROVED");
    if(check==1) puts("DENIED");
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  int s[n];
  for(int i=0;i<n;i++)
    cin >> s[i];
  int hi=0,ans=0;
  for(int i=0;i<n;i++){
    if(s[i]>hi)
      hi=s[i];
    ans+=s[i];
  }
  ans-=hi/2;
  cout << ans << endl;
}

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

int main(){
  int n;
  int a=0;
  int b=0;
  cin >> n;
  for(int i=0;i<n;i++){
    string j,k;
    cin >> j >> k;
    if(j>k){
      a+=3;
    }else if(j<k){
      b+=3;
    }else if(j==k){
      a+=1;
      b+=1;
    }
  }
  cout << a << ' ' << b << endl;
  return 0;
}



Measured memory_bytes: 3236
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <bits/stdc++.h>

using namespace std;
 
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
 
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
 
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
 
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
 
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define fore(i,a) for(auto &i:a)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
 
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
 

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

LL lcm(LL a, LL b){
    LL g = gcd(a,b);
    return a/g *b;
}



int main(){
    int N;
    cin >> N;
    vector<int> a(N);
    vector<pair<int,int>> v(N);
    for(int i=0;i<N;++i){
    cin >> a[i];
    v[i]={a[i],i};
    }
    sort(ALL(v));
    int x= v[N/2-1].first, y=v[N/2].first;
    vector<int> ans(N);
    for(int i=0;i<N;++i){
        if(i<N/2){
        ans[v[i].second]=y;
        }
        else{
            ans[v[i].second]=x;
        }
    }
    for(int i=0;i<N;++i){
        cout << ans[i] << endl;
    }
}

Measured memory_bytes: 5376