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

using namespace std;

int main(void) {
	int h, n; cin >> h >> n;
	int a[n], b[n];
	for (int i = 0; i < n; i++) {
		cin >> a[i] >> b[i];
	}
	
	int dp[h + 1] = {};
	for (int j = 0; j < h; j++) {
		dp[j] = INT_MAX;
	}
	for (int i = 0; i < n; i++) {
		for (int j = h; j >= 0; j--) {
			if (dp[j] != INT_MAX)
				dp[max(0, j - a[i])] = min(dp[max(0, j - a[i])], dp[j] + b[i]);
		}
	}
	
	cout << dp[0] << "\n";
	
	return 0;
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(const char c[]){
  int i=0;
  for(i=0;c[i]!='\0';i++){
    putchar_unlocked(c[i]);
  }
}
int main(){
  int R;
  rd(R);
  if(R<1200){
    wt_L("ABC");
    wt_L('\n');
  }
  else if(R<2800){
    wt_L("ARC");
    wt_L('\n');
  }
  else{
    wt_L("AGC");
    wt_L('\n');
  }
  return 0;
}
// cLay varsion 20190609-2 [beta]

// --- original code ---
// {
//   int R;
//   rd(R);
//   wt( if[R<1200, "ABC", R<2800, "ARC", "AGC"] );
// }


Measured memory_bytes: 256
/*
      author  : nishi5451
      created : 15.08.2020 00:18:18
*/

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


int main(){
    vector<int> a(5);
    rep(i,5) cin >> a[i];
    int sum = 0;
    int k = 10;
    rep(i,5){
        if(a[i]%10==0){
            sum += a[i];
        }
        else{
            k = min(k,a[i]%10);
            sum += (a[i]/10+1)*10;
        }
    }
    if(k!=10){
        sum -= (10-k);
    }
    cout << sum << endl;
    return 0;
}

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

bool isPrime[1<<15];

void GetPrime();

int main(void)
{
	GetPrime();
	int sz=sizeof(isPrime);

	while(1)
	{
		int a, ans=0;
		cin >> a;
		if(a == 0)break;

		for(int i=0; i<=a/2; i++)
		{
			if(isPrime[i])
			{
				for(int j=i; j<sz; j++)
					if(isPrime[j] && i+j==a)
						ans++;
			}
		}
		cout << ans << endl;
	}
	return 0;
}



void GetPrime()
{
	isPrime[0] = false;
	isPrime[1] = false;

	int sz = sizeof(isPrime);
	for(int i=2; i<sz; i++)
		isPrime[i] = true;
	
	for(int i=2; i*i<=sz; i++)
	{
		if(isPrime[i])
		{
			for(int j=i+i; j<sz; j+=i)
				isPrime[j]=false;
		}
	}
}

Measured memory_bytes: 1192
#include<iostream>
#include<algorithm>
using namespace std;
int main() {
	int n; cin >> n; int ans = 100;
	for (int i = 0; i < n; i++) {
		int a; cin >> a;
		int cnt = 0;
		while (a % 2 == 0) { cnt++; a /= 2; }
		ans = min(ans, cnt);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
<?php
  $five_hundred = trim(fgets(STDIN));
  $one_hundred = trim(fgets(STDIN));
  $fifty = trim(fgets(STDIN));
  $price = trim(fgets(STDIN));

  $count = 0;

  for ($i = 0; $i <= $five_hundred; $i++) {
    for ($j = 0; $j <= $one_hundred; $j++) {
        for ($k = 0; $k <= $fifty; $k++) {
            $answer = 500 * $i + 100 * $j + 50 * $k;
            if ($answer == $price) {
                $count = $count + 1;
            }
        }
    }
  }
  
  echo $count . "\n";

Measured memory_bytes: 16152
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

input = sys.stdin.readline

sys.setrecursionlimit(100000)


def read_int():
    return int(input())


def read_int_n():
    return tuple(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, Q, STX, D):
    E = []
    for i, (s, t, x) in enumerate(STX):
        E.append((s-x, 1, x, i))
        E.append((t-x, -1, x, i))

    E.sort(reverse=True)

    q = []
    done = set()

    ans = [-1] * Q
    for j, d in enumerate(D):
        while E and E[-1][0] <= d:
            t, e, x, i = E.pop()
            if e == 1:
                heapq.heappush(q, (x, i))
            else:
                done.add((x, i))

        while q and q[0] in done:
            heapq.heappop(q)

        if q:
            ans[j] = q[0][0]

    for i in range(Q):
        print(ans[i])


def main():
    N, Q = read_int_n()
    STX = tuple(read_int_n() for _ in range(N))
    D = tuple(read_int() for _ in range(Q))
    (slv(N, Q, STX, D))


if __name__ == '__main__':
    main()


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

using namespace std;

#define all(x) x.begin(), x.end()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define reps(i, m, n) for (int i = m; i <= n; ++i)

using i64 = long long;
using pii = pair<i64, i64>;

template<class A, class B>inline bool chmax(A &a, const B &b){return b > a ? a = b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b < a ? a = b,1 : 0;}

constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int MOD = int(1e9) + 7;

signed main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

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

  if (s == t) {
    cout << "Yes" << "\n";
    return 0;
  }

  bool isYes = true;
  map<char, char> smp, tmp;

  for (int i = 0; i < s.length(); ++i) {
    if (smp.count(s[i])) {
      if (smp[s[i]] != t[i]) isYes = false;
    }
    if (tmp.count(t[i])) {
      if (tmp[t[i]] != s[i]) isYes = false;
    }
    smp[s[i]] = t[i];
    tmp[t[i]] = s[i];
  }

  cout << (isYes ? "Yes" : "No") << "\n";

  return 0;
}

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

#pragma GCC optimize("O2,no-stack-protector,unroll-loops,fast-math")

#define F first
#define S second
#define pb push_back
#define SZ(x) (ll)(x.size())
#define all(x) x.begin(),x.end()
#define MP make_pair

typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const ll maxn=5e2+10, maxm=5e4+10, lg=21, mod=1e9+7, inf=1e18;

ll H,W,h,w,a[maxn][maxn];

int main(){
	ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	
	cin>>H>>W>>h>>w;
	if(H%h==0 && W%w==0) return cout<<"No",0;
	cout<<"Yes\n";
	if(H%h){for(int i=0;i<H;i++)if(i%h==0)for(int j=0;j<W;j++) a[i][j]=1000*h-1;}
	else if(W%w){for(int i=0;i<W;i++)if(i%w==0)for(int j=0;j<H;j++) a[j][i]=1000*w-1;}
	for(int i=0;i<H;i++,cout<<endl)for(int j=0;j<W;cout<<a[i][j++]-1000<<' ');
	
	return 0;
}






Measured memory_bytes: 5644
#include<bits/stdc++.h>
#define rep(i, n) for(int (i)=0 ;i <(n); ++(i))
#define REP(i,m,n) for(int (i) = (m); (i) <= (n); ++(i))
#define yorn(f) puts((f)?"Yes":"No")
#define YORN(f) puts((f)? "YES":"NO")
typedef long long ll;
using namespace std;

int main() {
  int a, b;
  cin >> a >> b;
  bool f = false;
  for(int i = 1; i<=3; i++) {
    int p = a*b*i;
    if(p%2 != 0) f = true;
  }
  yorn(f);
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n,m,x;
	cin>>n>>m>>x;
	vector<int>c(n);
	vector<vector<int> >v;
	for(int i=0;i<n;i++)
	{
		cin>>c[i];
		vector<int>a(m);
		for(int j=0;j<m;j++)cin>>a[j];
		v.push_back(a);
	}
	int ans=1e9;
	for(int mask=1;mask<(1<<n);mask++)
	{
		int cur=0;
		vector<int>b(m,0);
		for(int i=0;i<n;i++)
		{
			if(!(mask&(1<<i)))continue;
			cur+=c[i];
			for(int j=0;j<m;j++)
			{
				b[j]+=v[i][j];
			}
		}
		bool ok=1;
		for(int i=0;i<m;i++)
		{
			if(b[i]<x)ok=0;
		}
		if(ok)ans=min(ans,cur);
	}
	if(ans==1e9)cout<<-1;
	else cout<<ans;
	return 0;
}


Measured memory_bytes: 3572
#include <stdio.h>
#include <string.h>
int main(){
    
    char s[202]={};
    char s2[202]={};
    char p[101]={};
    int i;
    
    scanf("%s %s",s,p);
    
    for(i=0;i<2;i++){
        strcat(s2,s);
    }
    if(strstr(s2,p)=='\0') printf("No\n");
    else if(strstr(s2,p)!='\0') printf("Yes\n");
    return 0;
}


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

int main(){
	int S,h,m,s;
	cin>>S;
	h=(S-S%3600)/3600;
	S=S%3600;
	m=(S-S%60)/60;
	s=S%60;
	cout<<h<<":"<<m<<":"<<s<<endl;
}


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

int main(){
    char t;
    cin >>t;
    if(t=='A') cout << 'T' << endl;
    else if(t=='T') cout << 'A' << endl;
    else if(t=='C') cout << 'G' << endl;
    else cout <<'C' << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>



#define REP(i,n) for(int i = 0; i < (n); i++)
#define RREP(i,n) for(int i = (n) - 1; i >= 0; i--)
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define RFOR(i,b,a) for(int i = (b) - 1; i >= (a); i--)
#define STRS(i,str) for(int i = 0; (str)[i]; i++)


int main(){
	unsigned long long able[6000];
	able[0] = 1;
	int n, p, a;
	int max = 1;
	unsigned long long ans = 0;
	scanf("%d%d", &n, &p);
	REP(i, n){
		scanf("%d", &a);
		RREP(j, max) able[j + a] += able[j];
		max += a;
	}
	for(int i = p; i < max; i += 2) ans += able[i];
	printf("%llu\n", ans);
}



Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <map>
typedef long long ll;
using namespace std;
string in;
ll pos;
ll Mol(map<string, ll>);
ll Atom(map<string, ll>);
ll let(map<string, ll>);

main(){
  int x;
  while(cin >> in){
    map<string,ll> data;
    if(in!="END_OF_FIRST_PART"){
      cin >> x;
      data[in]=x;
      while(1){
	cin >> in;
	if(in=="END_OF_FIRST_PART") break;
	cin >> x;
	data[in]=x;
      }
    }
    while(1){
      cin >> in;
      if(in=="0") break;
      pos=0;
      ll ans=Mol(data);
      if(ans==-2){
	cout << "UNKNOWN" << endl;
	continue;
      }else cout << ans << endl;
    }
  }
  return 0;
}

ll Mol(map<string, ll> data){
  if(pos==in.size()) return -1;
  ll x=0;
  ll tmp;
  while(1){
    if(in[pos]==')') break;
    tmp=Atom(data);
    if(tmp==-1) break;
    if(tmp<=-2) return -2;
    x+=tmp;
  }
  return x;
}
ll Atom(map<string, ll> data){
  ll x;
  if(pos==in.size()) return -1;
  if(in[pos]=='('){
    pos++;
    x=Mol(data);
    pos++;
    if(in[pos]>='0' && in[pos]<='9'){
      int a;
      a=(int)in[pos++]-'0';
      if(in[pos]>='0' && in[pos]<='9'){
	int b;
	b=(int)in[pos++]-'0';
	x*=(ll)a*10+b;
      }else x*=a;
    }
  }else{
    x=let(data);
    if(in[pos]>='0' && in[pos]<='9'){
      int a;
      a=(int)in[pos++]-'0';
      if(in[pos]>='0' && in[pos]<='9'){
	int b;
	b=(int)in[pos++]-'0';
	x*=(ll)a*10+b;
      }else x*=(ll)a;
    }
  }
  return x;
}
ll let(map<string, ll> data){
  if(pos==in.size()) return -1;
  pos++;
  string tmp="";
  tmp+=in[pos-1];
  if(pos-1==in.size()-1){
    if(data[tmp]==0) return -2;
    return data[tmp];
  }
  if(in[pos]>='a' && in[pos]<='z'){
    tmp+=in[pos];
    pos++;
    if(data[tmp]==0) return -2;
    return data[tmp];
  }
  if(data[tmp]==0) return -2;
  return data[tmp];
}

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

int main(){
	int a,b,c,d;
	cin >> a >> b >> c >> d;
	if(a+b > c+d){
		cout << "Left" << endl;
	}
	else if (a+b==c+d){
		cout << "Balanced" << endl;
	}else{
		cout << "Right" << endl;
	}
  return 0;

}


Measured memory_bytes: 256
n = int(input())
s = input()
r, g, b = 0, 0, 0
for i in s:
    if i == 'R':
        r += 1
    elif i == 'G':
        g += 1
    else:
        b += 1
bad = 0
for i in range(n):
    gap = 0
    while i+(gap+1)*2 <= n-1:
        if s[i] != s[i+gap+1] and s[i+gap+1] != s[i+(gap+1)*2]\
                and s[i] != s[i+(gap+1)*2]:
            bad += 1
        gap += 1
print(r*g*b-bad) 


Measured memory_bytes: 73420
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <math.h>
#include <stack>
using namespace std;
typedef long long ll;

int x[10][10];

int cal(vector<int> v){
	int a=0;
	for(int p:v){
		a=x[a][p];
	}
	return a;
}

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	for(int i=0;i<10;i++){
		for(int j=0;j<10;j++){
			cin >> x[i][j];
		}
	}
	int ans=0;
	for(int i=0;i<10000;i++){
		vector<int> v;
		int cp=i;
		for(int j=0;j<4;j++){
			v.push_back(cp%10);
			cp/=10;
		}
		int e=cal(v);
		v.push_back(e);
		bool ok=1;
		for(int j=0;j<5;j++){
			for(int k=0;k<10;k++){
				if(v[j]==k)continue;
				vector<int> vv=v;
				vv[j]=k;
				if(cal(vv)==0)ok=0;
			}
		}
		for(int j=0;j<4;j++){
			if(v[j]==v[j+1])continue;
			vector<int> vv=v;
			swap(vv[j],vv[j+1]);
			if(cal(vv)==0)ok=0;
		}
		if(!ok)ans++;
	}
	cout << ans << endl;
}


Measured memory_bytes: 3236
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
int main(){
	int A, B, K; 
	cin >> A >> B >> K; 
	int count = 0; 
	for(int i = 100; i >= 1; i--){
		if(A % i == 0 && B % i == 0){
			count ++; 
		}
		if(count == K){
			cout << i << endl; 
			break; 
		}
	}
}

Measured memory_bytes: 256
var n,a,b:longint;
begin
  read(n,a,b);
  repeat
    if a+1<b then inc(a) else
    begin
      writeln('Borys');
      exit;
    end;
    if a<b-1 then dec(b) else
    begin
      writeln('Alice');
      exit;
    end;
  until 1=0;
end.

Measured memory_bytes: 128
#include<cstdio>
#include<cstring>
#include<cctype>
#include<algorithm>
#define r register
#define min(a,b) (a<b?a:b)
typedef long long ll;
inline ll read(){
	r ll x=0,f=1;r char ch=getchar();
	for(;!isdigit(ch);f=ch=='-'?-1:1,ch=getchar());
	for(;isdigit(ch);x=(x<<3)+(x<<1)+(ch^48),ch=getchar());
	return x*f;
}
int n;
struct data{
	int num,v;
	friend bool operator<(data a,data b){
		return a.v!=b.v?a.v>b.v:a.num<b.num;
	}
}s[100005];
ll ans[100005];
int buf[35];
inline void write(ll x){
	r int cnt=0;
	if(!x)putchar('0');
	while(x)buf[++cnt]=x%10+48,x/=10;
	while(cnt)putchar(buf[cnt--]);
	puts("");
}
int main(){
	n=read();r ll l=0;int last=0x3f3f3f3f;
	for(r int i=1;i<=n;i++)s[i].v=read(),s[i].num=i;
	std::sort(s+1,s+1+n);
	for(r int i=1,pos=1;i<=n;i=++pos){
		while(pos<n&&s[pos+1].v==s[i].v)pos++;l+=pos-i+1;
		ans[last=min(last,s[i].num)]+=(s[i].v-s[pos+1].v)*l;
	}
	for(r int i=1;i<=n;i++)write(ans[i]);
    return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <algorithm>
#include <set>
#include <stack>
#include <deque>
#include <cmath>
#include <map>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < n; i++)
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    cin >> a[0];
    ll ans = 0;
    for (int i = 1; i < n; i++) {
        cin >> a[i];
        if (a[i-1] == a[i]) {
            ans++;
            a[i] = -1;
        }
    }
    cout << ans << endl;
}

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

int main(void)
{
   char a[15],b[15],c[15];
    int x,y;
    
    scanf("%s %s %d %d %s",&a,&b,&x,&y,&c);
    
    if((strcmp(a,c)==0))
    
        x--;
        
   
    
    if((strcmp(b,c)==0))
    
        y--;
        
    
    
    printf("%d %d",x,y);
        
    return 0;
}

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

#define endl "\n"
#define INF (int) 9e18
#define HELL (int) (1e9 + 7)
#define int long long
#define double long double
#define uint unsigned long long
#define deb(x) cerr << #x << " => " << x << "\n"
#define deba(x) cerr << #x << "\n"; for (auto a : x) cerr << a << " "; cerr << "\n";
#define debm(x) cerr << #x << "\n"; for (auto a : x){for(auto b : a) cerr << b << " "; cerr << "\n";}
#define getMat(x, n, m, val) vector<vector<int>> x(n, vector<int> (m, val))
#define fastio ios_base :: sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#define pout cout << fixed << setprecision(10)

int fastpow(int a, int b, int m) {
    int res = 1; a %= m; while (b > 0) {
        if (b & 1) res = (res * a) % m; a = (a * a) % m; b >>= 1;
    } return res;
}

int now() {
    return chrono::duration_cast<chrono::milliseconds>(chrono::system_clock::now()
    .time_since_epoch()).count();
}

int32_t main() { fastio;
    time_t start = now();

    int n; cin >> n;
    vector<int> arr(n);
    vector<int> freq(n + 5);
    int res = 0;
    for (int i = 0; i < n; i++) {
        cin >> arr[i];
        freq[arr[i]]++;
    }
    for (auto f : freq) {
        if (f) {
            res += f * (f - 1) / 2;
        }
    }
    for (int i = 0; i < n; i++) {
        int f = freq[arr[i]];
        int temp = res;
        res -= f * (f - 1) / 2;
        res += (f - 1) * (f - 2) / 2;
        cout << res << endl;
        res = temp;
    }

    cerr << "TIME => " << now() - start << endl;
    return 0;
}

Measured memory_bytes: 5760
#include <iostream>
#include <iomanip>
#include <string>
#include <limits.h>
#include <math.h>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>

using namespace std;

int main(int argc, char* argv[]){
  int n,m;
  cin >> n >> m;
  cout << (100 * n + 1800 * m) * pow(2,m) << endl;


  return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <unordered_map>
using namespace std;
typedef long long lli;
lli n;
vector<vector<lli> > c;
unordered_map<lli,lli> m;
lli ans = 0;
lli to_lli(vector<lli>& v){
    lli ret = 0;
    for(lli i = 0;i < v.size();i++){
        ret *= 1000;
        ret += v[i];
    }
    return ret;
}
void rotate(vector<lli>& v){
    for(lli i = 0;i < 3;i++) swap(v[i],v[i+1]);
    //for(lli k = 0;k < v.size();k++) cout << v[k] << " ";cout << endl;
}
void rotate(lli& x){
    x = x / 1000 + (x % 1000) * 1000000000;
}
void recover(vector<lli>& v){
    lli x = to_lli(v);
    for(lli i = 0;i < 4;i++){
        rotate(x);
        m[x]++;
    }
}
void dec(vector<lli>& v){
    lli x = to_lli(v);
    for(lli i = 0;i < 4;i++){
        rotate(x);
        m[x]--;
    }
}
void dec(lli& x){
    for(lli i = 0;i < 4;i++){
        rotate(x);
        m[x]--;
    }
}
void inc(vector<lli>& v){
    lli x = to_lli(v);
    for(lli i = 0;i < 4;i++){
        rotate(x);
        m[x]++;
    }
}
lli select(vector<lli>& v){
    lli x = to_lli(v);
    lli ret = m[x];
    dec(x);
    return ret > 0 ? ret : 0;
}


int main(int argc, char const *argv[]) {
    cin >> n;
    c = vector<vector<lli> > (n,vector<lli> (4));
    for(lli i = 0;i < n;i++){
        cin >> c[i][0] >> c[i][1] >> c[i][2] >> c[i][3];
        lli x = to_lli(c[i]);
        for(lli j = 0;j < 4;j++){
            rotate(x);
            m[x]++;
        }
    }
    for(lli i = 0;i < n;i++){
        dec(c[i]);
        for(lli j = i + 1;j < n;j++){
            dec(c[j]);
            for(lli k = 0;k < 4;k++){
                rotate(c[j]);
                lli adder = 1;
                vector<lli> v1{c[i][1],c[i][0],c[j][1],c[j][0]};
                vector<lli> v2{c[i][0],c[i][3],c[j][2],c[j][1]};
                vector<lli> v3{c[i][3],c[i][2],c[j][3],c[j][2]};
                vector<lli> v4{c[i][2],c[i][1],c[j][0],c[j][3]};
                adder *= select(v1);
                adder *= select(v2);
                adder *= select(v3);
                adder *= select(v4);
                ans += adder;
                recover(v1);
                recover(v2);
                recover(v3);
                recover(v4);
            }
            inc(c[j]);
        }
        inc(c[i]);
    }
    cout << ans/3 << endl;
    return 0;
}


Measured memory_bytes: 239576
import java.util.*;
import java.io.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);

        String N = sc.next();
        String ans = "";
        for (int i = 0; i < N.length(); i++) {
            if (N.charAt(i) == '1') {
                ans += "9";
            } else if (N.charAt(i) == '9') {
                ans += "1";
            } else {
                ans += N.substring(i, i+1);
            }
        }
        out.printf("%s\n", ans);
        out.flush();
    }
}


Measured memory_bytes: 21716
#include <bits/stdc++.h>
using namespace std;
#define int long long
using ll=long long;
using vi=vector<int>;
using vl=vector<long long>;
using pii=pair<int,int>;
using pll=pair<long long,long long>;
#define ITR(i,c) for(auto i=begin(c);i!=end(c);++i)
#define FORE(x,c) for(auto &x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define REPW(i,n) for(i=0;i<(int)(n);++i)
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)   // c++14
#define SZ(c) ((int)c.size())
#define EXIST(c,x) (c.find(x)!=end(c))
#define OUTOFRANGE(y,x,h,w) (y<0||x<0||y>=h||x>=w)
#define dump(...)
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
#define INF (1001001001)
#define INFLL (1001001001001001001ll)
template<class T> ostream& operator << (ostream &os,const vector<T> &v) {
    ITR(i,v) os << *i << (i==end(v)-1 ? "" : "\n"); return os; }
template<class T> istream& operator >> (istream &is,vector<T> &v) {
    ITR(i,v) is >> * i; return is; }
template<class T> istream& operator >> (istream &is, pair<T,T> &p) {
        is >> p.first >> p.second; return is; }
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;}
//------------------------------------------------------------------------------
struct before_main_function {
    before_main_function() {
        #ifdef int
            #undef INF
            #define INF INFLL
            #define stoi stoll
        #endif
        cin.tie(0);ios::sync_with_stdio(false);
        cout<<setprecision(15)<<fixed;
    }
} before_main_function;
//------------------------------------------------------------------------------

signed main() {
    int H,W,h,w;
    cin>>H>>W>>h>>w;
    vector<vector<int>> g(H,vector<int>(W,4000));
    for(int i=h-1;i<H;i+=h) {
        for(int j=w-1;j<W;j+=w) {
            g[i][j]=-(h*w-1)*4000-1;
        }
    }
    int sum=0;
    REP(i,H) {
        REP(j,W) {
            sum+=g[i][j];
        }
    }
    if(sum<0) {
        cout<<"No"<<endl;
    }
    else {
        cout<<"Yes"<<endl;
        REP(i,H) {
            REP(j,W) {
                cout<<g[i][j];
                if(j!=W-1) cout<<" ";
                else cout<<endl;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 3584
//
//  main.cpp
//  competitive
//
//  Created by shinku on 2018/10/06.
//  Copyright © 2018 shinku. All rights reserved.
//

#include <iostream>
#include <utility>
#include <vector>

using namespace std;
int main(int argc, const char * argv[]) {
    int n;
    cin >> n;
    vector<int> h,x,y;
    for(int i = 0;i < n;i++) {
        int xx,yy,hh;
        cin >> xx >> yy >> hh;
        h.push_back(hh);
        x.push_back(xx);
        y.push_back(yy);
    }
    for(int cx = 0;cx <= 100;cx++) {
        for(int cy = 0;cy <= 100;cy++) {
            bool ok = true;
            int hh = 0;
            for(int i = 0;i < n;i++) {
                if(h[i] != 0) {
                    hh = h[i] + abs(x[i] - cx) + abs(y[i] - cy);
                }
            }
            if(hh == 0) {
                throw;
            }
            for(int i = 0;i < n;i++) {
                if(h[i] != max(0,hh - (abs(x[i] - cx) + abs(y[i] - cy)))) {
                    ok = false;
                }
            }
            if(ok) {
                cout << cx << " " << cy << " " << hh;
            }
        }
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>

using namespace std;

typedef long long ll;

int Szukaj(vector<ll>& a, int x)
{
    int l = 0, p = a.size() - 1, s, r = -1;
    while (l <= p)
    {
        s = (l + p) / 2;
        if (a[s] >= x)
        {
            r = s;
            p = s - 1;
        }
        else
            l = s + 1;
    }
    return r;
}

int main()
{
    ios_base::sync_with_stdio(0);
    int n, q;
    cin >> n >> q;
    vector<ll> a(n);
    for (int i = 0; i < n; ++i)
        cin >> a[i];
    vector<ll> parz(n), nieparz(n);
    for (int i = 0; i < n; ++i)
    {
        if (i == 0)
        {
            parz[0] = a[0];
            nieparz[0] = 0;
        }
        if (i == 1)
        {
            parz[1] = parz[0];
            nieparz[1] = a[1];
        }
        if (i >= 2)
        {
            if (i % 2 == 0)
            {
                parz[i] = parz[i - 1] + a[i];
                nieparz[i] = nieparz[i - 1];
            }
            else
            {
                parz[i] = parz[i - 1];
                nieparz[i] = nieparz[i - 1] + a[i];
            }
        }
    }
    vector<ll> suf(n);
    suf[n - 1] = a[n - 1];
    for (int i = n - 2; i >= 0; --i)
        suf[i] = suf[i + 1] + a[i];
    for (int i = 0; i < q; ++i)
    {
        int x;
        cin >> x;
        if (x > a[n - 1])
        {
            if ((n - 1) % 2 == 0)
                cout << parz[n - 1];
            else
                cout << nieparz[n - 1];
            cout << endl;
            continue;
        }
        int pier = Szukaj(a, x);
        int l = pier, p = n - 1, s, r = -1;
        while (l <= p)
        {
            s = (l + p) / 2;
            int dl_suf = n - s;
            int R = a[s] - x;
            int ile = s - pier + 1;
            int nr = Szukaj(a, x - R);
            if (nr < pier && nr != -1)
                ile += (pier - 1) - nr + 1;
            if (ile - 1 >= dl_suf - 1)
            {
                r = s;
                p = s - 1;
            }
            else
                l = s + 1;
        }
        ll odp = suf[r];
        int dl_suf = n - r;
        int nast = r - dl_suf - 1;
        if (nast >= 0)
        {
            if (nast % 2 == 0)
                odp += parz[nast];
            else
                odp += nieparz[nast];
        }
        cout << odp;
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 4864
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main () {
    ll N;
    cin >> N;
    vector<ll> a(3*N);
    for (int i = 0; i < a.size(); i++) {
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    ll ans = 0;
    for (int i = 0; i < N; i++) {
        ans += a[3*N-2-i*2];
    }
    cout << ans << endl;
}

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


const long long LINF = 1e18;

int main(){
    int n; cin >> n;
    vector<ll>a(n);

  	REP(i, n) {
      cin >> a[i];
    
    // 0はどんなにかけても0
    // 先にやっておかないと後にでてくる-1出力判定のところでひっかかることがある
        if(a[i] == 0){
        cout << 0 << endl;
        return 0;
        }       
    }

    ll ans = 1;
    REP(i, n){
        //1e18よりでかいか判定（オーバーフロー対策済)
      	//1e18 < ans * a[i] →　1e18 / a[i] < ans （移項）
      	//右辺のans * a[i]のところがオーバーフローするので移項してならないようにするテク
        if(LINF / a[i] < ans){
            cout << -1 << endl;
            return 0;
        }
        ans *= a[i];
    }
    cout << ans << endl;
    return 0;
}


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

int main()
{
    int a,b,k,i,j = 0;
    cin >> a >> b >> k;
    for(i = max(a,b);i >=0;--i){
        if(b%i == 0 && a%i == 0){
            ++j;
            if(j == k){
                break;
            }
        }
    }
    cout << i << endl;
    return 0;
}

Measured memory_bytes: 256
n,m,k=map(int,input().split())
#コンビネーション逆元
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod


mod = 998244353 #出力の制限
N = 10**6
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル


for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )
ans=0
for i in range(k+1):
    ans+=m*cmb(n-1,i,mod)*pow(m-1,n-1-i,mod)
    ans%=mod
print(ans)

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

#define WHATS(var) cout<<#var<<"="<<var<<endl;

using ll = long long int;
using ha = pair<ll, ll>;
struct RollingHash {
	static const ll mul0 = 10009, mul1 = 10007;
	static const ll add0 = 10010007, add1 = 13333331;
	static const ll mod=1e9+7;
	size_t len;
	//vector<ll> hash_, hash2_;
	vector<ha>hash_;
	//static vector<ll> pmo_, pmo2_;
	static vector<ha>pmo_;
	void init(const vector<ll>& s) {
		len = s.size();
		hash_.resize(len + 1);
		hash_[0] = make_pair(0, 0);

		if (pmo_.empty()) {
			pmo_.push_back(make_pair(1, 1));
		}
		while (pmo_.size() <= len) {
			pmo_.push_back(make_pair(
				pmo_.back().first*mul0%mod, 
				pmo_.back().second*mul1%mod)
			);
		}
		for (unsigned int i = 0; i < len; ++i) {
			hash_[i + 1] = make_pair(
				(hash_[i].first * mul0 + s[i])%mod,
				(hash_[i].second*mul1 + s[i])%mod
			);
		}
		return;
	}
	void init(const string& s) {
		vector<ll>v;
		for (char c : s) {
			v.push_back(c);
		}
		init(v);
	}
	ha hash(const int l, const int r)const { // s[l..r]
		return make_pair(
			(hash_[r + 1].first - hash_[l].first * pmo_[r + 1 - l].first+mod*mod)%mod,
			(hash_[r + 1].second - hash_[l].second * pmo_[r + 1 - l].second+mod*mod)%mod
		);
	}
	ha  hash()const { // s[all]
		return hash(0, len - 1);
	}

	//hash�̌����@
	static ha concat(const ha L, const ha R, const int RLength) { // hash(L+R) 
		return make_pair(
			(R.first + L.first*pmo_[RLength].first)%mod,
			(R.second + L.second*pmo_[RLength].second)%mod
		);
	}

	//index�̈ʒu��from����to�ɕς������̂̃n�b�V����Ԃ��B
	ha get_changed_hash(const int index, const ll from, const ll to)const {
		const ha p(hash());
		return make_pair(
			(p.first + (to - from) * pmo_[len - index - 1].first)%mod,
			(p.second + (to - from) * pmo_[len - index - 1].second)%mod
		);
	}
};
vector<ha> RollingHash::pmo_;
int main() {
	ios::sync_with_stdio(false);
	string S,T;cin>>S>>T;
	string S2;
	while(S2.size()<T.size())S2+=S;
	S2+=S;
	vector<int>oks(S.size());
	RollingHash rhs2,rht;
	rhs2.init(S2);
	rht.init(T);
	//cout<<S2<<endl;
	for(int i=0;i<S.size();++i){
		//cout<<rhs2.hash(i,i+T.size()-1).first<<rhs2.hash(i,i+T.size()-1).second<<endl;

		if(rhs2.hash(i,i+T.size()-1)==rht.hash()){
			oks[i]=true;
			//cout<<i<<endl;
		}
	}

	vector<vector<int>>edges(S.size());
	vector<int>nums(S.size());
	for(int i=0;i<S.size();++i){
		if(oks[i]){
			edges[i].push_back((i+T.size())%S.size());
			nums[(i+T.size())%S.size()]++;
		}
	}

	queue<int>que;
	vector<int>cnts(S.size(),-1);
	for(int i=0;i<S.size();++i){
		if(nums[i]==0){
			que.emplace(i);
			cnts[i]=0;

		}
	}
	while(!que.empty()){
		int now=que.front();
		que.pop();
		for(auto e:edges[now]){
			nums[e]--;
			if(nums[e]==0){
				cnts[e]=max(cnts[e],cnts[now]+1);
				que.emplace(e);
			}
		}
	}
	if(find(cnts.begin(),cnts.end(),-1)!=cnts.end()){
		cout<<-1<<endl;
	}else{
		cout<<*max_element(cnts.begin(),cnts.end())<<endl;
	}

	return 0;
}


Measured memory_bytes: 90748
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(300000)


def solve(N: int, a: "List[int]"):
    used = [False] * (N + 1)
    ret = -1
    cnt = 1
    a = [0] + a
    tmp = a[1]
    while True:
        if tmp == 2:
            ret = cnt
            break
        if used[tmp]:
            break
        else:
            used[tmp] = True
            cnt += 1
            tmp = a[tmp]
    print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    a = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, a)

if __name__ == '__main__':
    main()


Measured memory_bytes: 8736
N = int(input())
l = list(map(int, input().split()))
l.append('END')
ans = l.copy()
for i in range(len(l)):
    ans[i] = 0
try:
    for i in range(len(l)):
        ans[l[i] - 1] += 1
except TypeError:
    pass
for i in ans:
    print(i)

Measured memory_bytes: 32304
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,(n)-1,0)
#define all(v) v.begin(), v.end()
#define endk '\n'
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ld eps = 1e-10;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b){if(a>b) a=b;}
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b){if(a<b) a=b;}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n; cin >> n;
  vector<ll> X(n); rep(i, n) cin >> X[i];
  vector<ll> Y(n);
  copy(all(X), begin(Y));
  sort(all(Y));
  int m = Y[n/2-1], M = Y[n/2];
  rep(i, n) {
    if(X[i] <= m) cout << M << endk;
    else cout << m << endk;
  }
  return 0;
}


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

int main(){
    
    int n,d;  cin >> n >> d;
    if(n == 1){
        cout << 1 << endl;
        return 0;
    }else{
        if(n%(2*d+1) == 0){
            cout << n/(2*d+1) << endl;
            return 0;
        }else{
            cout << n/(2*d+1)+1 << endl;
            return 0;
        }
    }
}

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

string s;
string t[] = {"dream", "dreamer", "erase", "eraser"};

bool match(string &T) {
	if (s.size() < T.size()) return false;
	for (int i = 1; i <= T.size(); ++i) {
		if (s[s.size()-i] != T[T.size()-i]) return false;
	}
	return true;
}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	cin >> s;

	while(true) {
		if (s.size() == 0) return cout << "YES\n", 0;
		bool ok = false;
		for (int i = 0; i < 4; ++i) {
			if (match(t[i])) {
				ok = true;
				for (int j = 1; j <= t[i].size(); ++j) s.erase(s.begin() + s.size() - 1);
				break;
			}
		}
		if (!ok) return cout << "NO\n", 0;
	}
}

Measured memory_bytes: 512
# -*- coding: utf-8 -*-
import collections
import queue


class Dinic:
    def __init__(self, N):
        self.N = N
        self.edges = collections.defaultdict(list)
        self.level = [0 for _ in range(self.N)]
        self.iter = [0 for _ in range(self.N)]

    def add(self, u, v, c, directed=True):
        if directed:
            self.edges[u].append([v, c, len(self.edges[v])])
            self.edges[v].append([u, 0, len(self.edges[u])-1])
        else:  # TODO: must be Verified
            self.edges[u].append([v, c, len(self.edges[v])])
            self.edges[v].append([u, 0, len(self.edges[u]) - 1])
            self.edges[v].append([u, c, len(self.edges[u])])
            self.edges[u].append([v, 0, len(self.edges[v]) - 1])

    def bfs(self, s):
        self.level = [-1 for _ in range(self.N)]
        self.level[s] = 0
        que = collections.deque([s]) #queue.Queue()
        #que.put(s)
        while que: #.empty():
            v = que.popleft() #.get(s)
            for i in range(len(self.edges[v])):
                e = self.edges[v][i]
                if e[1] > 0 and self.level[e[0]] < 0:
                    self.level[e[0]] = self.level[v] + 1
                    que.append(e[0]) # put(e[0])

    def dfs(self, v, t, f):
        if v == t:
            return f
        for i in range(self.iter[v], len(self.edges[v])):
            self.iter[v] = i
            e = self.edges[v][i]
            if e[1] > 0 and self.level[v] < self.level[e[0]]:
                d = self.dfs(e[0], t, min(f, e[1]))
                if d > 0:
                    e[1] -= d
                    self.edges[e[0]][e[2]][1] += d
                    return d
        return 0

    def maxFlow(self, s, t):
        flow = 0
        while True:
            self.bfs(s)
            if self.level[t] < 0:
                return flow
            self.iter = [0 for _ in range(self.N)]
            f = self.dfs(s, t, float('inf'))
            while f > 0:
                flow += f
                f = self.dfs(s, t, float('inf'))


H, W = map(int, input().split())
graph = Dinic(2*H*W + 2)
delta = [-1, 1, W, -W]
goal = 2 * H * W + 1
for i in range(H):
    S = str(input())
    for j, s in enumerate(S):
        curEdge = i * W + j + 1
        if s == '.':
            graph.add(curEdge, curEdge+H*W, 1)
        else:
            if i == 0 or i == H-1 or j == 0 or j == W-1:
                print(-1)
                quit()
            graph.add(curEdge, curEdge+H*W, float('inf'))
            graph.add(0, curEdge, float('inf'))
        for d in delta:
            if 0 < curEdge+d < 2*H*W+1:
                graph.add(curEdge+H*W, curEdge+d, float('inf'))

for i in range(1, W+1):
    graph.add(i+H*W, goal, float('inf'))
    graph.add(i+(2*H-1)*W, goal, float('inf'))

for i in range(1, H-1):
    graph.add((i+H)*W+1, goal, float('inf'))
    graph.add((i+H+1)*W, goal, float('inf'))


print(graph.maxFlow(0, goal))

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

int main(){
    int N, A;
    cin >> N >> A;
    bool flag = false;
    for(int i = 0;i <= A;i++){
        if((N - i) % 500 ==0 ) flag = true; 
    }
    if(flag) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
import sys
import copy
import math
import bisect
import pprint
import bisect
from functools import reduce
from copy import deepcopy
from collections import deque
from decimal import *

import numpy as np

import math

if __name__ == '__main__':
    a = [str(i) for i in input().split()]
    b = int(a[0])
    c = int(a[1].replace(".",""))
    d = Decimal(a[0]) * Decimal(c) / Decimal(100)
    e = int(d)
    print(e)


Measured memory_bytes: 27224
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long n, a, b;
  cin>>n>>a>>b;
  if((b - a) % 2){
    long long x = (b - a) / 2;
  	long long ans = min(a, n - b + 1) + x;
  	cout<<ans<<endl;
  }
  else{
    cout<<(b - a) / 2<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<map>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) (x).begin(),(x).end()
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//vector<vector<要素の型>> 変数名(要素数1, vector<要素の型>(要素数2, 初期値));
//vector<vector<要素の型>> 変数名(要素数1, vector<要素の型>(要素数2));  // 初期値を省略




ll hma(ll h){//How many attacks
	
	if(h==1) return 1;

	return hma(h/2)*2+1;
}




int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	string ts="test";
	
	//int n; cin >> n;
	
	ll h; cin >> h;
	
//	vector<ll> a(h+1,0); a[1]=1;
	
	//cout << a.max_size() << endl;
	
	cout << hma(h) << endl;
	
	
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
int INF = 1e9+7;
ll N;
bool check(ll n) {
    string s = to_string(n);
    return (s.find('3') != string::npos &&
            s.find('5') != string::npos &&
            s.find('7') != string::npos);
}
int dfs(ll n) {
    if (n > N) return 0;
    int res = 0;
    if (check(n)) res = 1;

    res += dfs(n*10 + 3);
    res += dfs(n*10 + 5);
    res += dfs(n*10 + 7);
    return res;
}

int main() {
    cin >> N;
    cout << dfs(0) << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
  int n;
  cin >> n;
  int i;
  vector<int> a(n);
  vector<int> b(100001,0);
  for(i=0;i<n;i++) cin >> a[i];
  sort(a.begin(),a.end());
  for(i=0;i<n;i++){
    if(a[i]==0){
      b[a[i]]++;
      b[a[i]+1]++;
    }
    else{
    b[a[i]-1]++;
    b[a[i]]++;
    b[a[i]+1]++;
    }
  }
  int max = *max_element(b.begin(),b.end());
  cout << max << "\n";
  return 0;
}

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

int n, k;
int r, s, p;
string t;

void Max(int &x, int y){
  x = max( x, y );
}

int DP(int begin){
  
  string str;
  
  for(int i=begin;i<n;i+=k) str += t[i];
  
  int sz = str.size();
  
  vector<vector<int> > dp( sz + 1, vector<int>( 3, 0 ) );
  
  for(int i=0;i<sz;i++){
    
    for(int j=0;j<3;j++){
      
      for(int toj=0;toj<3;toj++){
	
	if( j == toj ) continue;
	
	if( toj == 0 && str[i] == 'r' ) Max( dp[i+1][toj], dp[i][j] + p );
	if( toj == 1 && str[i] == 's' ) Max( dp[i+1][toj], dp[i][j] + r );
	if( toj == 2 && str[i] == 'p' ) Max( dp[i+1][toj], dp[i][j] + s );
	
	Max( dp[i+1][toj], dp[i][j] );
	
      }
      
    }
    
  }
  
  int res = 0;
  
  for(int i=0;i<3;i++) Max( res, dp[sz][i] );
  
  return res;
}

signed main(){
  
  cin >> n >> k;
  
  cin >> r >> s >> p;
  
  cin >> t;
  
  int ans = 0;
  
  for(int i=0;i<k;i++) ans += DP( i );
  
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 5888
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;


void main()
{
  double a, b, x;
  readf("%s %s %s\n", &a, &b, &x);
  auto v = a * a * b;
  double h, th;
  if (v / 2 - x > 0) {
    h = 2.0 * x / (a * b);
    th = 90 - (180 / PI) * atan(h / b);
  } else {
    h = 2.0 * (v - x) / (a * a);
    th = (180 / PI) * atan(h / a);
  }

  writefln("%.12f", th);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,count;
  count = 0;
  cin >> N;
  vector<int> vec(N);
  for(int i = 0; i < N; i++){
    cin >> vec.at(i);
    while(vec.at(i) % 2 ==0){
      count += 1;
      vec.at(i) /= 2;
    }
  }
  cout << count << endl;
      
      
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define deb(x) cout << #x << " = "<< x << "\n";

signed main() {
	//freopen("in.txt", "r",stdin);
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	
	int n; cin >> n;
	vector<int> cnt(100001);
	
	int sum = 0;
	for(int i = 0, x; i < n; i++) {
		cin >> x;
		sum += x;
		cnt[x]++;	
	}
	
	int q, b, c; cin >> q;
	while(q--) {
		cin >> b >> c;
		sum += cnt[b] * (c - b);
		cnt[c] += cnt[b];
		cnt[b] = 0; 
		cout << sum << "\n";
	}
}


Measured memory_bytes: 3912
from itertools import permutations, combinations,combinations_with_replacement,product

n = int(input())
p = [0 for i in range(5)]

for i in range(n):
    kar = input()
    if kar[0] == "M":
        p[0] += 1
    elif kar[0] == "A":
        p[1] += 1
    elif kar[0] == "R":
        p[2] += 1
    elif kar[0] == "C":
        p[3] += 1
    elif kar[0] == "H":
        p[4] += 1

a=[0,1,2,3,4]

tyu = list(combinations(a,3))
ans = 0
for x , y , z in tyu:
    ans += p[x]*p[y]*p[z]
print(ans)

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

# input
l = list()
for _ in range(5):
    l.append(int(input()))
k = int(input())

# solve
ans = True
for i in range(len(l)):
    for j in range(len(l) - i):
        if l[j] - l[i] > k:
            ans = False

# output
print('Yay!' if ans else ':(')


Measured memory_bytes: 2940
#include <iostream>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <limits>
#include <numeric>
#include <algorithm>
#include <functional>

using namespace std;

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

	int N;
	cin >> N;

	string S;
	cin >> S;

	if (N % 2 == 0)
	{
		bool check = true;
		for (int i = 0; i < N / 2; i++)
		{
			if (S[i] != S[i + (N / 2)])
			{
				check = false;
				break;
			}
		}

		if (check)
		{
			cout << "Yes";
			return 0;
		}
	}

	cout << "No";

	return 0;
}


Measured memory_bytes: 3604
# include <iostream>
# include <string>
# include <algorithm>
# include <vector>
# include <cstring>
# include <stdio.h>
# include <map>
# include <queue>

# define ll long long
# define pii pair<int,int>
# define FOR(a,b) for(int a=1; a<=b; a++)
# define REP(a,b) for(int a=0; a<b; a++)
# define FORU(a,b,c) for(int a=b; a<=c; a++)
# define FORD(a,b,c) for(int a=b; a>=c; a--)

using namespace std;

struct Ball {
  char color;
  int number;
};

Ball ball[4005];
int sumw[4005][4005], sumb[4005][4005], posw[4005], posb[4005];
int dp[4005][4005];

int n;

int solve(int w, int b){ //w = white balls placed so far, b = black balls
  if(w > n && b > n) return 0;
  if(dp[w][b] != -1) return dp[w][b];

  int res = 1e9;
  if(w <= n){
    int whiteBalls = sumw[2*n][w-1] - sumw[posw[w]][w-1]; //number of white balls in the left
    int blackBalls = sumb[2*n][b-1] - sumb[posw[w]][b-1]; //number of black balls in the right
    int cost = abs(posw[w] + whiteBalls + blackBalls - (w+b-1));
    res = min(res, solve(w+1, b) + cost);
  }

  if(b <= n){
    int whiteBalls = sumw[2*n][w-1] - sumw[posb[b]][w-1];
    int blackBalls = sumb[2*n][b-1] - sumb[posb[b]][b-1];
    int cost = abs(posb[b] + whiteBalls + blackBalls - (w+b-1));
    res = min(res, solve(w, b+1) + cost);
  }

  return dp[w][b] = res;
}

int main(){

  ios :: sync_with_stdio(false);
  cin >> n;
  FOR(i,2*n){
    cin >> ball[i].color >> ball[i].number;
    if(ball[i].color == 'W'){
      sumw[i][ball[i].number] = 1;
      posw[ball[i].number] = i;
    }
    else{
      sumb[i][ball[i].number] = 1;
      posb[ball[i].number] = i;
    }
  }

  memset(dp, -1, sizeof(dp));

  FOR(i, 2*n){ //posisi
    FOR(num, n){ //angka
      sumw[i][num] += sumw[i-1][num] + sumw[i][num-1] - sumw[i-1][num-1];
      sumb[i][num] += sumb[i-1][num] + sumb[i][num-1] - sumb[i-1][num-1];
    }
  }

  cout << solve(1,1) << endl;

  return 0;
}

Measured memory_bytes: 188160
#include <bits/stdc++.h>
#include <string>
#include <cstring>
#include <algorithm>
#include <math.h>
#include <map>
#include <bitset>
#include <cmath>
#include <set>
#include <utility>

#define INF 1000000000000
#define MOD 1000000007 //10^9+7:合同式の法

using namespace std;
typedef long long ll;

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)

int main(){
    int N,min=0,max=0;
    cin >> N;
    vector<int> a(N);
    bool hai=false,cha=false,green =false,mizu=false,ao=false,ki=false,ora=false,red=false;

    for(int i = 0;i < N;i++)
        cin >> a.at(i);

    for(int i = 0;i < N;i++){
        if(a.at(i) >=1 and a.at(i) <= 399 and hai == false){
            hai = true;
            min++;
            max++;
        }else if(a.at(i) >= 400 and a.at(i) <= 799 and cha == false){
            cha = true;
            min++;
            max++;
        }else if(a.at(i) >= 800 and a.at(i) <= 1199 and green == false){
            green = true;
            min++;
            max++;
        }else if(a.at(i) >= 1200 and a.at(i) <= 1599 and mizu == false){
            mizu = true;
            min++;
            max++;
        }else if(a.at(i) >= 1600 and a.at(i) <= 1999 and ao == false){
            ao = true;
            min++;
            max++;
        }else if(a.at(i) >= 2000 and a.at(i) <= 2399 and ki == false){
            ki = true;
            min++;
            max++;
        }else if(a.at(i) >= 2400 and a.at(i) <= 2799 and ora == false){
            ora = true;
            min++;
            max++;
        }else if(a.at(i) >= 2800 and a.at(i) <= 3199 and red == false){
            red = true;
            min++;
            max++;
        }else if(a.at(i) >= 3200){
            max++;
        }else
        {
            continue;
        }
        
    }

    if(max > 0 and min == 0)
        min++;

    cout << min << " " << max << endl;

}

Measured memory_bytes: 3596