akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>

int main(){
    char c;
    scanf("%c",&c);
    if(c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o'){
        printf("vowel");
    }
    else{
        printf("consonant");
    }
    printf("\n");

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int x = sc.nextInt();

    int total = 0;
    int count = 1;

    for (int i = 0; i < n; ++i) {
      int l = sc.nextInt();
      total += l;
      if (total <= x)
        ++count;
    }

    System.out.println(count);
  }
}

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

int main() {


while(1){
	char a[8][8],ans;
int c[4],b[4],j=0;
for(int kk=0;kk<=3;kk++){
c[kk]=0;
b[kk]=0;
}
for(int k=0;k<=7;k++){
	for(int l=0;l<=7;l++){
		a[k][l]=0;
		cin>>a[k][l];
		if(a[k][l]=='1'){
			b[j]=k;
			c[j]=l;
			j=j+1;
		}
	}
}
if(b[1]==0&&c[1]==0){
	break;
}
if(c[3]==c[0]+1&&b[3]==b[0]+1){
	ans='A';
}
if(c[3]==c[0]&&b[3]==b[0]+3){
	ans='B';
}
if(c[3]==c[0]+3&&b[3]==b[0]){
	ans='C';
}
if(c[3]==c[0]-1&&b[3]==b[0]+2){
	ans='D';
}
if(c[3]==c[0]+2&&b[3]==b[0]+1){
	ans='E';
}
if(c[3]==c[0]+1&&b[3]==b[0]+2){
	ans='F';
}
if(c[3]==c[0]&&b[3]==b[0]+1){
	ans='G';
}
cout<<ans<<endl;

}
return 0;
}

Measured memory_bytes: 1132
//#pragma GCC optimize(2)


#include<bits/stdc++.h>
using namespace std;
/*#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/hash_policy.hpp>
#include<ext/pb_ds/trie_policy.hpp>
#include<ext/pb_ds/priority_queue.hpp>
#include<ext/rope>*/
//using namespace __gnu_cxx;
//using namespace __gnu_pbds;
//void err(istream_iterator<string> it){cerr<<endl;}
//template<typename T, typename... Args>void err(istream_iterator<string> it, T a, Args... args){cerr << *it << " = " << a << " , ";err(++it, args...);}
//#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
#define mem(a,b) memset((a),b,sizeof((a)))
#define fpre(x) cout<<fixed<<setprecision(x)
#define clr(v) (v).clear()
#define pii pair<int,int>
#define pdd pair<double,double>
#define pli pair<ll,int>
#define pll pair<ll,ll>
#define mp make_pair
#define eb emplace_back
#define pb emplace_back
#define ll long long
#define ld long double
#define ull unsigned long long
#define uint unsigned int
#define ushort unsigned short
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define lowbit(i) (i&(-i))
#define lson rt<<1
#define rson lson|1
#define fi first
#define se second
const double eps=1e-7;
const double pi=acos(-1);
inline int dcmp(double x)
{
    if(x<-eps)
        return -1;
    if(x>eps)
        return 1;
    return 0;
}
//-----------------------------------------------head


const ll mod=1e9+7;
char s[5050];
ll dp[5050][5050];
int main()
{
    int n,c;
    while(~scanf("%d%s",&n,s))
    {
        int l=strlen(s);
        mem(dp,0);
        dp[0][0]=1;
        for(int i=0;i<=n;++i)
        {
            (dp[i+1][0]+=dp[i][0])%=mod;
            for(int j=1;j<=n;++j)
                (dp[i+1][j-1]+=dp[i][j]*2)%=mod;
            for(int j=0;j<=n;++j)
                (dp[i+1][j+1]+=dp[i][j])%=mod;
        }
        printf("%lld\n",dp[n][l]);
    }
}

/*
























*/









Measured memory_bytes: 199424
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+5;
int l[N]={0},r[N]={0},n,k,c;
string s;
int main(){
    cin>>n>>k>>c>>s;
    for(int i=0,j=0;i<n;i++){
        if(s[i]=='o'){
            l[j++]=i;
            i+=c; 
        }
    }
    for(int i=n-1,j=k-1;i>=0;i--){
        if(s[i]=='o'){
            r[j--]=i;
            i-=c;
        }
    }
    for(int i=0;i<k;i++){
        if(l[i]==r[i]) cout<<l[i]+1<<endl;
    }
    return 0;
}

Measured memory_bytes: 3332
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
int main(int argc, char const *argv[]) {
    int n, k;
    cin >> n >> k;
    if (n%2 == 1) {
        if (n/2+1 >= k) cout << "YES" << endl;
        else cout << "NO" << endl;
    } else {
        if (n/2 >= k) cout << "YES" << endl;
        else cout << "NO" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
const ll INF = 5e18;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

#ifdef DEBUG
template <class T, class N> void verr(const T& a, const N& n) { rep(i, n) cout << a[i] << " "; cout << "\n"; }
ll dbgt = 1; void err() { cout << "passed " << dbgt++ << "\n"; }
template<class H, class... T> void err(H&& h,T&&... t){ cout<< h << (sizeof...(t)?" ":"\n"); if(sizeof...(t)>0) err(forward<T>(t)...); }
#endif

void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}
//--------------------------------------------------------------------------------//
ll V[100000];
bool used[100000];
vvc<pair<ll, ll>> G;
int main() {
    init();
    ll N,M;
    cin >> N >> M;
    G.resize(N);
    rep(i,M){
        ll l, r, d;
        cin >> l >> r >> d;
        l--, r--;
        G[l].eb(r, d), G[r].eb(l, -d);
    }

    fill(V, V + N, INF);
    bool isok = true;
    queue<pair<ll,ll>> q;
    rep(i,N){
        if (used[i]) continue;
        q.emplace(i, 0);
        while(!q.empty()){
            ll now, cost;
            tie(now, cost) = q.front(), q.pop();
            if (V[now] == INF) V[now] = cost;
            else if(V[now]!=cost){
                isok = false;
                break;
            }
            if (used[now]) continue;
            used[now] = true;

            for(auto& p:G[now]){
                ll to = p.first, tco = p.second;
                q.emplace(to, cost + tco);
            }
        }
        if (!isok) break;
    }

    cout << (isok ? "Yes" : "No") << endl;
}

Measured memory_bytes: 17904
N = int(input())
A = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(A[N-1])

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

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

    int n;
    cin >> n;
    int ans = 0;
    while (n > 0)
    {
        ans += n % 10;
        n /= 10;
    }
    if (ans == 1)
        ans = 10;
    cout << ans << endl;
}

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

#define EPS 1e-9

struct tree{
	tree *left;
	tree *right;
	
	set<string> st_memo;
	double sim_memo;
	
	tree(): left(0), right(0), sim_memo(-1.0) {}
	~tree(){
		delete left;
		delete right;
	}
	
	void toset(set<string> &s){
		if( st_memo.empty() ){
			set<string> st;
			st.insert(tostr());
			
			if( left ){
				left->toset(st);
				right->toset(st);
			}
			st_memo = st;
		}
		s.insert(st_memo.begin(), st_memo.end());
	}
	
	double sim(){
		if( sim_memo < 0.0 ){
			set<string> s1, s2;
			if( left ){
				left->toset(s1);
				right->toset(s2);
			}
			else{
				sim_memo = 0.0;
				return 0.0;
			}

			set<string>::iterator it;
			int c = 0;
			for(it = s1.begin(); it != s1.end(); ++it){
				if( s2.find(*it) != s2.end() ){
					++c;
				}
			}

			s1.insert( s2.begin(), s2.end() );
			sim_memo = (double)c / s1.size();
		}
		return sim_memo;
	}
	
	static int compare(tree *t1, tree *t2){
		double s1 = t1->sim();
		double s2 = t2->sim();

		if( abs(s1 - s2) > EPS ){
			return s1 < s2 ? 1 : -1;
		}
		if( !t1->left && !t2->left ){
			return 0;
		}

		tree *t11 = t1->left, *t12 = t1->right;
		tree *t21 = t2->left, *t22 = t2->right;
		if( compare(t11, t12) < 0 ) swap(t11, t12);
		if( compare(t21, t22) < 0 ) swap(t21, t22);
		
		int c = compare(t11, t21);
		return c ? c : compare(t12, t22);
	}
	
	string tostr(){
		string s;

		if( !left ){
			s += 'x';
		}
		else{
			s += '(';
			s += left->tostr();
			s += ' ';
			s += right->tostr();
			s += ')';
		}
		
		return s;
	}
	
	void normalize(bool leftchild){
		if( !left ) return;

		if( (compare(left, right) < 0) == leftchild ){
			swap(left, right);
		}

		left->normalize(true);
		right->normalize(false);
	}

	void sort(){
		if( !left ) return;
		
		left->sort();
		right->sort();
		
		string s1 = left->tostr();
		string s2 = right->tostr();
		if( s1 > s2 ) swap(left, right);
	}
};

string str;
int pos;

tree *parse(){
	tree *ret = new tree;
	
	if( str[pos] == 'x' ){
		++pos;
		return ret;
	}

	++pos;
	ret->left = parse();
	++pos;
	ret->right = parse();
	++pos;
	
	return ret;
}

int main(){
	while( getline(cin, str), str[0] != '0' ){
		pos = 0;
		tree *root = parse();
		root->sort();
		root->normalize(true);
		cout << root->tostr() << '\n';
		
		delete root;
	}
}

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

const int MAXN = 100005;

const long long INF = 1e18;

int n, a[MAXN], e, t;

#define lc (nd<<1)
#define rc (nd<<1|1)

struct node {
	long long x, y;
	node()
	{ x = y = INF; }
	node(long long _x, long long _y)
	{ x = _x, y = _y; }
	friend node operator + (const node &a, const node &b)
	{ return (node) {min(a.x, b.x), min(a.y, b.y)}; }
};

node dat[MAXN*8];
long long tag[MAXN*8];

inline void update(int nd)
{ dat[nd] = dat[lc]+dat[rc]; }
inline void put_tag(int nd, int dt)
{ dat[nd].x += dt, dat[nd].y += dt, tag[nd] += dt; }
inline void pdw(int nd)
{
	put_tag(lc, tag[nd]);
	put_tag(rc, tag[nd]);
	tag[nd] = 0;
}
inline void modify(int nd, int L, int R, int opl, int opr, int dt)
{
	pdw(nd);
	if (L == opl && R == opr) put_tag(nd, dt);
	else {
		int mid = (L+R)>>1;
		if (opr <= mid) modify(lc, L, mid, opl, opr, dt);
		else if (opl > mid) modify(rc, mid+1, R, opl, opr, dt);
		else modify(lc, L, mid, opl, mid, dt), modify(rc, mid+1, R, mid+1, opr, dt);
		update(nd);
	}
}
inline void modify(int nd, int L, int R, int pos, const node &pt)
{
	pdw(nd);
	if (L == R) dat[nd] = pt;
	else {
		int mid = (L+R)>>1;
		if (pos <= mid) modify(lc, L, mid, pos, pt);
		else modify(rc, mid+1, R, pos, pt);
		update(nd);
	}
}
inline node query(int nd, int L, int R, int opl, int opr)
{
	if (opl > opr) return (node) {INF, INF}; 
	pdw(nd);
	if (L == opl && R == opr) return dat[nd];
	else {
		int mid = (L+R)>>1;
		if (opr <= mid) return query(lc, L, mid, opl, opr);
		else if (opl > mid) return query(rc, mid+1, R, opl, opr);
		else return query(lc, L, mid, opl, mid)+query(rc, mid+1, R, mid+1, opr);
	}
}
const int root = 1;

int main()
{
	scanf("%d%d%d", &n, &e, &t);
	for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
	modify(root, 0, n, 0, (node) {0, -2*a[1]});
	int pos = -1;
	long long dpv;
	for (int i = 1; i <= n; i++) {
		while (pos+1 < i && 2ll*(a[i]-a[pos+2]) > t) pos++;
		dpv = min(query(root, 0, n, 0, pos).y+3ll*a[i]-a[i-1], query(root, 0, n, pos+1, i-1).x+a[i]-a[i-1]+t);
		modify(root, 0, n, i, (node) {dpv, dpv-2*a[i+1]});
		modify(root, 0, n, 0, i-1, a[i]-a[i-1]);
		// for (int j = 0; j < i; j++) dp[i][i] = min(dp[i][i], dp[i-1][j]+a[i]-a[i-1]+max(t, 2*(a[i]-a[j+1])));
	}
	cout << dpv+e-a[n] << endl;
	return 0;
}


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

int main()
{
	int n;
	int ary[101][101] = {};
	int max_ = -999999999;

	cin >> n;
	for (int i = 1; i <= n; i++)
	{
		for (int j = 1; j <= n; j++)
		{
			cin >> ary[i][j];
		}
	}

	for (int i = 1; i <= n; i++)
	{
		for (int j = 1; j <= n; j++)
		{
			ary[i][j] += ary[i][j - 1];
		}
	}

	for (int i = 1; i <= n; i++)
	{
		for (int j = 1; j <= n; j++)
		{
			ary[i][j] += ary[i - 1][j];
		}
	}

	for (int a = 0; a < n; a++)
	{
		for (int b = 0; b < n; b++)
		{
			for (int c = a + 1; c <= n; c++)
			{
				for (int d = b + 1; d <= n; d++)
				{
					int t = ary[c][d] + ary[a][b] - ary[c][b] - ary[a][d];
					max_ = max(max_, t);
				}
			}
		}
	}
	cout << max_ << endl;

	return 0;
}

Measured memory_bytes: 3128
#include <iostream>
#include <cstdint>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <iomanip>
#include <sstream>
 
int main(void)
{
    int64_t H;
    std::cin >> H;

    int64_t enemy = 1;
    int64_t count = 0;

    while (H > 1) {
        H /= 2;
        count += enemy;
        enemy *= 2;
    }

    count += enemy;

    std::cout << count << std::endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin >> n;
	map<int,int> a;
	long long sum=0;
	for(int i=0; i<n; ++i){
		int tmp;
		cin >> tmp;
		++a[tmp];
		sum += tmp;
	}
	int q;
	cin >> q;
	for(int i=0; i<q; ++i){
		long long b, c;
		cin >> b >> c;
		sum += -b*a[b]+c*a[b];
		cout << sum << endl;;
		a[c] += a[b];
		a[b]=0;
	} 

}

Measured memory_bytes: 8032
def h1(key):
    return key%m

def h2(key):
    return 1+(key%(m-1))

def h(key,i):
    return (h1(key)+i*h2(key))%m

def insert(t,key):
    i=0
    while True:
        j=h(key,i)
        if t[j]==-1:
            t[j]=key
            return j
        else:
            i+=1

def search(t,key):
    i=0
    while True:
        j=h(key,i)
        if t[j]==key:
            return j
        elif t[j]==-1 or i>=m:
            return -1
        else:
            i+=1

def change(c):
    ans=""
    for i in range(len(c)):
        if c[i]=="A":
            ans+="1"
        if c[i]=="C":
            ans+="2"
        if c[i]=="G":
            ans+="3"
        if c[i]=="T":
            ans+="4"
    return int(ans)

m=1046527
n=int(input())
dict=[-1]*m
import sys
input=sys.stdin.readline
for _ in range(n):
    l=list(input().split())
    k=change(l[1])
    if l[0]=="insert":
        insert(dict,k)
    else:
        if search(dict,k)!=-1:
            print("yes")
        else:
            print("no")



Measured memory_bytes: 32188
from collections import Counter, defaultdict, deque

class UnionFind(object):
    """Union find tree."""
    def __init__(self, nodes):
        self.par = [-1] * nodes

    def root(self, key):
        if self.par[key] < 0:
            return key
        self.par[key] = self.root(self.par[key])
        return self.par[key]

    def size(self, key):
        return -self.par[self.root(key)]

    def merge(self, a, b):
        a = self.root(a)
        b = self.root(b)
        if a == b:
            return
        if self.size(a) < self.size(b):
            a, b = b, a
        self.par[a] += self.par[b]
        self.par[b] = a

N, M = map(int, input().split())
AB = []
for _ in range(M):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    AB.append([a, b])

uni = UnionFind(N)
ans = [0] * M
ans[-1] = N * (N - 1) // 2
for i, (a, b) in enumerate(AB[-1:0:-1], 1):
    ans[-i - 1] = ans[-i]
    if uni.root(a) != uni.root(b):
        ans[-i - 1] -= uni.size(a) * uni.size(b)
        uni.merge(a, b)

print(*ans, sep='\n')

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

int main(void){
  int x1,y1,x2,y2;cin>>x1>>y1>>x2>>y2;
  cout<<x2 - y2 + y1<<" "<<x2 + y2 - x1<< " "<<x1 + y1 - y2<<" "<<x2 + y1 - x1;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define SZ(x) ((int)(x).size())
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

signed main()
{
    int H,W; cin>>H>>W;
    int h,w; cin>>h>>w;
    cout<<H*W-(h*W+H*w-h*w)<<endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>

int Check(int x){
    char s[10];
    sprintf(s+1,"%d",x);
    int len=strlen(s+1);
    for(int i=1;i<=len/2;i++)
        if(s[i]!=s[len-i+1])
            return 0;
    return 1;
}

int main(){
    int A,B,Ans=0;
    scanf("%d%d",&A,&B);
    for(int i=A;i<=B;i++)
        Ans+=Check(i);
    printf("%d",Ans);
    return 0;
}
/****/

Measured memory_bytes: 128
module.exports=function(t){var e={};function n(r){if(e[r])return e[r].exports;var i=e[r]={i:r,l:!1,exports:{}};return t[r].call(i.exports,i,i.exports,n),i.l=!0,i.exports}return n.m=t,n.c=e,n.d=function(t,e,r){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:r})},n.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,e){if(1&e&&(t=n(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var i in t)n.d(r,i,function(e){return t[e]}.bind(null,i));return r},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="",n(n.s=0)}([function(t,e,n){"use strict";var r=n(1),i=new(n(2))(r.readFileSync("/dev/stdin","utf8").trim().split(/\s+/g));n(4)(i)},function(t,e){t.exports=require("fs")},function(t,e,n){"use strict";var r=n(3);t.exports=class{constructor(t){this.inp=new r(t)}inr(){return this.inp.deq()}in(){return parseInt(this.inp.deq(),10)}add(t){this.inp.enq(t)}}},function(t,e,n){"use strict";t.exports=class{constructor(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];this.size=t.length,this.items=t,this.ind=0}enq(t){this.size+=1,this.items.push(t)}deq(){var t=this.items[this.ind];return this.size-=1,this.ind+=1,t}}},function(t,e,n){"use strict";t.exports=function(t){var e=t.in(),n=t.in(),r=Math.floor((3*e+n)/2);console.log(r)}}]);

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define REP(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)

#define DEBUG(x) cout<<#x<<": "<<x<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

#define CHMIN(a, b) a=min((a), (b))
#define CHMAX(a, b) a=min((a), (b))

const int MOD=1000000007;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-11;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, m;
	cin>>n>>m;
	cout<<((1900*m+100*(n-m))*(1<<m))<<'\n';
	return 0;
}


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

using namespace std;

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define eee(a) (cerr << (#a) << ": " << (a) << endl);


using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
using mint = map<int, int>;

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

const char sp = ' ';
const char cmm = ',';
const int MOD = 1e9+7;
const int INF = 1e9;
const ll LINF = 1e18;

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

template<class T>bool chmax(T &a, const T &b) {
    if(a < b) { a = b; return 1; } return 0;
}
template<class T>bool chmin(T &a, const T &b) {
    if(b < a) { a = b; return 1; } return 0;
}
template<typename T>
void ppp(T n){
    cout << n << endl;
}
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {
    return s << "(" << p.first << ", " << p.second << ")";
}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
    int len = v.size();
    s << '[';
    for(int i = 0; i < len; ++i) {
        s << v[i]; if(i < len-1) s << ", ";
    }
    s << ']';
    return s;
}

struct aaa {
    aaa(){
        cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(15);
    }
} fastio;


vector<vector<pll> > G;
int n;
vector<ll> dis;
void dijkstra(ll s){
    dis.resize(n, LINF);
    priority_queue<pll, vector<pll>, greater<pll> > q;
    dis[s] = 0;
    q.push(make_pair(0, s));
    while(!q.empty()) {
        ll d, v;
        tie(d, v) = q.top(); q.pop();
        if(dis[v] < d) continue;
        for(pll e : G[v]) {
            if(dis[e.second] > dis[v]+e.first) {
                dis[e.second] = dis[v]+e.first;
                q.emplace(dis[e.second], e.second);
            }
        }
    }
}
int main(){

    cin >> n;
    G.resize(n);
    rep(i, n-1){
        int u, v, w;
        cin >> u >> v >> w;
        --u; --v;
        G[u].emplace_back(w%2, v);
        G[v].emplace_back(w%2, u);
    }
    dijkstra(0);
    for(auto x : dis) ppp(x%2);

    return 0;
}


Measured memory_bytes: 8704
#include<cstdio>
#include<algorithm>
#include<cmath>
#define fo(i,a,b) for(i=a;i<=b;i++)
using namespace std;
typedef long long ll;
const int maxn=200+10,maxd=10000000+10;
int x[maxn],s[maxd],pri[maxd],r[maxn],a[maxn],b[maxn];
bool bz[maxd],dis[maxn][maxn],pd[maxn];
int i,j,k,l,t,n,m,tot,top,num,sum,tmp,ans;
void prepare(){
	bz[1]=1;
	fo(i,2,maxd-10){
		if (!bz[i]) pri[++top]=i;
		fo(j,1,top){
			if ((ll)i*pri[j]>maxd-10) break;
			bz[i*pri[j]]=1;
			if (i%pri[j]==0) break;
		}
	}
}
bool dfs(int x){
	int i;
	fo(i,1,sum)
		if (dis[x][i]&&!pd[i]){
			pd[i]=1;
			if (!r[i]||dfs(r[i])){
				r[i]=x;
				return 1;
			}
		}
	return 0;
}
int main(){
	prepare();
	scanf("%d",&n);
	fo(i,1,n){
		scanf("%d",&x[i]);
		s[x[i]]^=1;
	}
	fo(i,1,maxd-9){
		if (s[i]!=s[i-1]){
			if (i%2==1) a[++num]=i;
			else b[++sum]=i;
		}
	}
	fo(i,1,num)
		fo(j,1,sum)
			if (!bz[abs(a[i]-b[j])]) dis[i][j]=1;
	fo(i,1,num){
		fo(j,1,sum) pd[j]=0;
		if (dfs(i)) tmp++;
	}
	ans+=2*((num-tmp)/2);
	ans+=2*((sum-tmp)/2);
	ans+=tmp;
	if (num%2!=tmp%2) ans+=3;
	printf("%d\n",ans);
}

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

using ll = long long;
using ld = long double;
using vi = vector<int>;
using vll = vector<ll>;
using P = pair<int, int>;

const int INF = 1e9;
const ll INFLL = 1e18;
const int MOD = 1e9 + 7;
const int NIL = -1;
const ld PI = acosl(-1);

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

int main() {
	ios::sync_with_stdio(false); cin.tie(nullptr);
	//cout << fixed << setprecision(6);
	string s;
	cin >> s;

	if(s == "ABC") cout << "ARC\n";
	else cout << "ABC\n";
	return 0;
}

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

def main():

    N = int(input())

    S = []
    nameC = ['AC', 'WA', 'TLE', 'RE']
    C = [0, 0, 0, 0]

    for i in range(N):
        S.append(input())

    for i in S:
        if i == nameC[0]:
            C[0] += 1

        elif i == nameC[1]:
            C[1] += 1

        elif i == nameC[2]:
            C[2] += 1

        elif i == nameC[3]:
            C[3] += 1

    for i in range(len(C)):
        print(nameC[i], 'x', C[i])
    

if __name__ == "__main__":
    main()

Measured memory_bytes: 16336
n = int(input())
p = list(map(int,input().split()))
ans = 0
for i in range(n-2):
    if max(p[i],p[i+1],p[i+2]) != p[i+1] and min(p[i],p[i+1],p[i+2]) != p[i+1]:
        ans += 1
print(ans)

Measured memory_bytes: 9180
#include <float.h>
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

// 内部定数
#define D_ARRAY_MAX		50										// 最大配列数

// 内部変数
static FILE *szpFpI;											// 入力
static double sd1Array[D_ARRAY_MAX];							// 配列
static int siACnt;												// 配列数

// 内部変数 - テスト用
#ifdef D_TEST
	static int siRes;
	static FILE *szpFpA;
	static int siTNo;
#endif

// 出力
int
fOut(
	char *pcpLine				// <I> １行
)
{
	char lc1Buf[1024];

#ifdef D_TEST
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, pcpLine)) {
		siRes = -1;
	}
#else
	printf("%s", pcpLine);
#endif

	return 0;
}

// ソート関数 - double昇順
int
fSortFncDU(
	const void *pzpVal1			// <I> 値１
	, const void *pzpVal2		// <I> 値２
)
{
	double *ldpVal1 = (double *)pzpVal1;
	double *ldpVal2 = (double *)pzpVal2;

	// double昇順
	if (*ldpVal1 > *ldpVal2) {
		return 1;
	}
	else if (*ldpVal1 < *ldpVal2) {
		return -1;
	}

	return 0;
}

// 実行メイン
double
fMain(
)
{
	int i;
	char lc1Buf[1024];

	// 配列数 - 取得
	fgets(lc1Buf, sizeof(lc1Buf), szpFpI);
	sscanf(lc1Buf, "%d", &siACnt);

	// 配列 - 取得
	for (i = 0; i < siACnt; i++) {
		fscanf(szpFpI, "%lf", &sd1Array[i]);
	}
	fgets(lc1Buf, sizeof(lc1Buf), szpFpI);

	// 配列 - ソート
	qsort(sd1Array, siACnt, sizeof(double), fSortFncDU);

	// 合成
	for (i = 1; i < siACnt; i++) {
		sd1Array[i] = (sd1Array[i] + sd1Array[i - 1]) / 2;
	}

	return sd1Array[siACnt - 1];
}

// １回実行
int
fOne(
)
{
	double ldRet;
	char lc1Buf[1024];

	// 入力 - セット
#ifdef D_TEST
	sprintf(lc1Buf, ".\\Test\\T%d.txt", siTNo);
	szpFpI = fopen(lc1Buf, "r");
	sprintf(lc1Buf, ".\\Test\\A%d.txt", siTNo);
	szpFpA = fopen(lc1Buf, "r");
	siRes = 0;
#else
	szpFpI = stdin;
#endif

	// 実行メイン
	ldRet = fMain();

	// 出力
	sprintf(lc1Buf, "%.6lf\n", ldRet);
	fOut(lc1Buf);

	// 残データ有無
#ifdef D_TEST
	lc1Buf[0] = '\0';
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, "")) {
		siRes = -1;
	}
#endif

	// テストファイルクローズ
#ifdef D_TEST
	fclose(szpFpI);
	fclose(szpFpA);
#endif

	// テスト結果
#ifdef D_TEST
	if (siRes == 0) {
		printf("OK %d\n", siTNo);
	}
	else {
		printf("NG %d\n", siTNo);
	}
#endif

	return 0;
}

// プログラム開始
int
main()
{

#ifdef D_TEST
	int i;
	for (i = D_TEST_SNO; i <= D_TEST_ENO; i++) {
		siTNo = i;
		fOne();
	}
#else
	fOne();
#endif

	return 0;
}



Measured memory_bytes: 128
#include <iostream>
#include <algorithm>

using namespace std;

const int MAX_N = 100000;

struct ScoreSet {
    int rank;
    int score;

    bool operator<(const ScoreSet& right) const {
        return score < right.score;
    }
};

int main() {
    int n;
    ScoreSet scores[MAX_N];
    cin >> n;

    for (int i = 0; i < n; i++) {
        cin >> scores[i].rank >> scores[i].score;
    }

    sort(scores, scores + n);    

    int ans = 0;

    for (int i = 0; i < n; i++) {
        if (i == 0) {
            ans += scores[i].rank;
        }
        
        if (i == n - 1) {
            ans += scores[i].score;
        }
        else if ((scores[i+1].rank - scores[i].rank) <= (scores[i].score - scores[i+1].score)) {
            ans += scores[i+1].rank - scores[i].rank;
        }
        else {
            ans += scores[i].score - scores[i+1].score;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 1024
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <tuple>
#include <utility>
#include <vector>
#define ll long long
#define itn int
#define endl '\n'
#define co(ans) cout<<ans<<endl
#define COYE cout<<"YES"<<endl
#define COYe cout<<"Yes"<<endl
#define COye cout<<"yes"<<endl
#define CONO cout<<"NO"<<endl
#define CONo cout<<"No"<<endl
#define COno cout<<"no"<<endl
#define FORE(i,a) for(auto &i:a)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define PB push_back
#define MP make_pair
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define EACH(V,i) for(typeof((V).begin()) i=(V).begin();i!=(V).end();++i)
#define equals(a,b) (fabs((a)-(b))<EPS)
#define INF ((1LL<<62)-(1LL<<31))
#define EPS 1e-10
#define PI 3.141592653589793238
#define MOD 1000000007
#define MAX 5100000
using namespace std;
using Edge=pair<ll,ll>;
using Graph=vector<vector<int>>;
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();}
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;}
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
  ll N;
  cin>>N;
  if(N>=30) COYe;
  else CONo;
  return 0;
}

Measured memory_bytes: 3588
// --------------------<optimizations>--------------------
#pragma GCC optimize("O3")
//(UNCOMMENT WHEN HAVING LOTS OF RECURSIONS)\
#pragma comment(linker, "/stack:200000000")
//(UNCOMMENT WHEN TRYING TO BRUTEFORCE WITH A LOT OF LOOPS)\
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>

using namespace std;

#define ll long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define pii pair<ll,ll>
#define vpii vector<pair<ll,ll> >
#define F first
#define S second
#define ld long double
#define built __builtin_popcountll
#define mst(a,i) memset(a,i,sizeof(a))
#define all(x) x.begin(),x.end()
#define itit(it,a) for(auto it=(a).begin(); it!=(a).end(); it++)
#define rep(i,a,b) for(ll i=a; i<b; i++)
#define repr(i,a,b) for(ll i=a; i>b; i--)
#define reprr(i,a,b) for(ll i=a; i>=b; i--)
#define pi 3.14159265358979323846264338327950288419716939937510582097494459230
ll max3(ll x,ll y,ll z) {return max(max(x,y),z);}
ll min3(ll x,ll y,ll z) {return min(min(x,y),z);}
const ll M=2e5+10,M2=1e6+10,mod=1e9+7,inf=1e17+10;
void add(int& a, int b) {a+=b;if(a>=mod){a-=mod;}}
#define trace1(x)			 	 cerr<<#x<<": "<<x<<endl
#define trace2(x, y)		 	 cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)		 	 cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)	 	 cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)	 cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
int X[] = {0, 1, 0, -1};
int Y[] = {-1, 0, 1, 0};
ll power(ll x,ll n){ll result=1;while(n>0){if(n%2==1)result=(result*x)%mod; x=((x%mod)*(x%mod))%mod;n=n/2;}return result;}


int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	string s;
	cin >> s;
	ll n=s.size();
	string a,b;
	a=s[0];
	ll ans=1;
	for(ll i=1; i<n; i++){
		if(a.size()){
			b+=s[i];
			if(a!=b){
				ans++;
				a="";
			}
		}
		else{
			a+=s[i];
			if(b!=a){
				ans++;
				b="";
			}
		}
	}
	cout << ans;
	return 0;
}


Measured memory_bytes: 720
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
ll const INF = 1LL << 60;

int main() {
  string T;
  cin >> T;
  ll ans = 0;
  for (int i = 0; i < T.length(); i++) {
    if (T[i] == '?') {
      T[i] = 'D';
    }
  }
  cout << T << endl;
  return 0;
}

Measured memory_bytes: 3728
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <set>
#include <algorithm>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <map>
#include <utility>
#include <numeric>
#include <chrono>
#include <ctime>
#include <bitset>
#include <iterator>

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define P pair<long long, long long>
#define debug(x) cerr << #x << ": " << x << ", "
#define debugln(x) cerr << #x << ": " << x << '\n'

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; }

using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;

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

  string s; cin >> s;
  if (s.size() == 3) {
    reverse(s.begin(), s.end());
  }
  cout << s << endl;
}

Measured memory_bytes: 256
N, x = map(int, input().split())
a = list(map(int, input().split()))
cnt = 0
for i in range(1, N):
    if a[i-1] + a[i] > x:
        rem = a[i-1] + a[i] - x
        cnt += rem
        if rem >= a[i]:
            a[i - 1] -= rem - a[i]
            a[i] = 0
        else:
            a[i] -= rem
print(cnt)



Measured memory_bytes: 14132
#include<stdio.h>
int main(){
	int i[1000],p[1000],q[1000],r[1000],P,Q,R,C,n,j,a[1000],b[1000],c[1000],d;
	
	while(1){
		scanf("%d",&n);
		if(n==0){
			break;
		}
		for(j=0;j<n;j++){
			scanf("%d%d%d%d",&i[j],&p[j],&q[j],&r[j]);
			a[j]=(p[j]+r[j])*4;
			b[j]=q[j]*9;
			c[j]=a[j]+b[j];
		}
		scanf("%d%d%d%d",&P,&Q,&R,&C);
		
		d=0;
		
		for(j=0;j<n;j++){
			if(P>=p[j] && Q>=q[j] && R>=r[j] && C>=c[j]){
				printf("%d\n",i[j]);
				d++;
			}
			if(j==n-1){
				if(d==0){
					printf("NA\n");
				}
			}
		}
	}
	
return 0;
}

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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define ALL(a) (a).begin(),(a).end()

using namespace std;
using ll = long long;

const double PI = 3.14159265358979;

void solve()
{
  ll n, m;
  cin >> n >> m;
  cout << abs(n - 2LL) * abs(m - 2LL);
}

int main()
{
  fastio;
  solve();

  return 0;
}

Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
struct Fast {Fast() {std::cin.tie(0); ios::sync_with_stdio(false);}} fast;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using vll = vector<long long>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define MOD 1000000007

int main() {
    int X, Y, Z, K; cin >> X >> Y >> Z >> K;
    vll A(1000, 0), B(1000, 0), C(1000, 0);
    rep(i, X) cin >> A[i];
    rep(j, Y) cin >> B[j];
    rep(k, Z) cin >> C[k];
    vll D(1e6 + 1, 0);
    rep(i, X) {
        rep(j, Y) {
            D[i * Y + j] = A[i] + B[j];
        }
    }
    sort(all(D), greater<ll>());
    vll E(3e6 + 1, 0);
    int a = min(X * Y, K), b = min(Z, K);
    rep(i, a) {
        rep(j, b) {
            E[i * b + j] = D[i] + C[j];
        }
    }
    sort(all(E), greater<ll>());
    rep(i, K) cout << E[i] << endl;

}



Measured memory_bytes: 31616
N = int(input())

xy_list = list()

for _ in range(N):
    xy_list.append( tuple(map(int, input().split() )) )

# for x, y in xy_list:
#     print(x,y)

from math import sqrt

def calc_dist(p1, p2):
    p1_x, p1_y = p1
    p2_x, p2_y = p2

    return sqrt((p2_x-p1_x)**2 + (p2_y-p1_y)**2)

from itertools import permutations
A_perm = permutations(xy_list, N)

sum_all = 0
cnt = 0
for a in A_perm:
    sum_dist = 0
    #for x,y in a:
    for i in range(len(a)-1):
        sum_dist = sum_dist + calc_dist(a[i], a[i+1])
    # print(sum_dist)

    sum_all = sum_all + sum_dist
    cnt = cnt + 1

print(sum_all / cnt)


Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <functional>
#include <vector>

using namespace std;

int main() {
    int n;
    string s;
    cin >> n >> s;
    vector<bool> a0(n+1), a1(n+1), a2(n+1), a3(n+1);
    std::reference_wrapper<vector<bool>> answers[] = {a0, a1, a2, a3};

    const bool S = false;
    const bool W = true;
    // init
    answers[0].get()[0] = S;
    answers[1].get()[0] = S;
    answers[2].get()[0] = W;
    answers[3].get()[0] = W;
    answers[0].get()[1] = S;
    answers[1].get()[1] = W;
    answers[2].get()[1] = S;
    answers[3].get()[1] = W;
    
    for(int i = 1; i < n; ++i){
        const bool said_same = s[i] == 'o';
        for(auto&& ar : answers){
            auto& a = ar.get();
            const bool should_same = (said_same && a[i] == S) || (!said_same && a[i] == W);
            const bool next = (should_same ? a[i-1] : !a[i-1]);
            a[i+1] = next;
        }
    }
    {
        // check
        const bool said_same = s[0] == 'o';
        for(auto&& ar : answers){
            auto& a = ar.get();
            const bool should_same = (said_same && a[0] == S) || (!said_same && a[0] == W);
            const bool next = (should_same ? a[n-1] : !a[n-1]);
            if(a[0] == a[n] && a[1] == next){
                for(int i = 0; i < n; ++i){
                    cout << (a[i] == S ? 'S' : 'W');
                }
                cout << endl;
                return 0;
            }
        }
        cout << "-1" << endl;
        return 0;
    }
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> ii;
#define F first
#define S second
#define sqr(x) (x)*(x)
#define pb(x) push_back(x)
#define sz(x) (int)x.size()
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rep(i,x,y) for(int i=x;i<(y);++i)
#define IOS ios_base::sync_with_stdio(0);cin.tie(0)
/* start */

int n,a,ans,dp[51][51][2505];

signed main(){
    IOS;
    cin >> n >> a;
    vector<int> x(n+1);
    rep(i,0,n) cin >> x[i+1];
    dp[0][0][0] = 1;
    for(int i = 1;i<=n;i++){
        for(int j = 0;j<=n;j++){
            for(int k = 0; k<2505;k++){
                dp[i][j][k]+=dp[i-1][j][k];
                if(j>0 and k-x[i]>=0) dp[i][j][k]+=dp[i-1][j-1][k-x[i]];
            }
        }
    }
    rep(j,1,n+1){
        rep(s,0,2505){
            if(j*a == s) ans+=dp[n][j][s];
        }
    }
    cout << ans << "\n";
}

Measured memory_bytes: 50176
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define range(i, l, r) for(long long int (i) = (l); (i) < (r); (i)++)
#define reversed_range(i, l, r) for (long long int (i) = (r) - 1; (i) >= l; (i)--)
using namespace std;
template <typename T>
using vec = vector<T>;
using lint = long long;
using ulint = unsigned long long;
using pint = pair<int, int>;
using plint = pair<lint, lint>;

template <typename S, typename T>
ostream& operator <<(ostream& os, pair<S, T> p) {
    os << "(";
    os << p.first << ", " << p.second;
    return os << ")";
}

template <typename T>
ostream& operator <<(ostream& os, vec<T> v) {
    os << "[";
    if (v.size() == 0) return os << "]";
    for (int i = 0; i < v.size() - 1; i++) {
        os << v.at(i) << ", ";
    }
    return os << v.at(v.size() - 1) << "]";
}

template <typename T>
ostream& operator <<(ostream& os, set<T>& s) {
    os << "{";
    if (s.begin() == s.end()) return os << "}";
    auto it_first_item = s.begin();
    cout << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        cout << ", " << *it;
    }
    return cout << "}";
}

template <typename T>
ostream& operator <<(ostream& os, unordered_set<T>& s) {
    os << "{";
    if (s.begin() == s.end()) return os << "}";
    auto it_first_item = s.begin();
    cout << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        cout << ", " << *it;
    }
    return cout << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, map<K, V> m) {
    os << "{";
    if (m.begin() == m.end()) return os << "}";
    auto it_first_item = m.begin();
    cout << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        cout << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, unordered_map<K, V> m) {
    os << "{";
    if (m.begin() == m.end()) return os << "}";
    auto it_first_item = m.begin();
    cout << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        cout << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

lint pow(lint num, lint e, lint MOD) {
    lint res = 1;
    lint cur_num = num;
    while (e) {
        if (e & 1) {
            res *= cur_num;
            res %= MOD;
        }
        cur_num *= cur_num;
        cur_num %= MOD;
        e >>= 1;
    }
    return res;
}

int main() {
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    string s, t;
    cin >> s >> t;
    sort(s.begin(), s.end());
    sort(t.begin(), t.end(), greater<char>());
    cout << (s < t ? "Yes" : "No") << "\n";
}

Measured memory_bytes: 256
n = gets.chomp.to_i
b = gets.split.map(&:to_i)
a = Array.new(n)

a[0] = b[0]
a[n-1] = b[n-2]
(1..(n-2)).each do |i|
  if b[i-1] < b[i]
    a[i] = b[i-1]
  elsif b[i-1] > b[i]
    a[i] = b[i]
  else
    a[i] = b[i]
  end
end

puts a.inject(:+)

Measured memory_bytes: 1788
#include <iostream>

using namespace std;

int main() {
	int n, m;
	char table[256];

	while (cin >> n, n) {
		for (int i = 0; i < 256; i++)
			table[i] = 0;
	
		for (int i = 0; i < n; i++) {
			char a, b;
			cin >> a >> b;
			table[a] = b;
		}
	
		cin >> m;
		for (int i = 0; i < m; i++) {
			char a;
			cin >> a;
			if (table[a])
				cout << table[a];
			else
				cout << a;
		}
		cout << endl;
	}

	return 0;
}

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

int main(void) {
	int n, t, a, i, ans;
	int h[1000];
	double temp, ans_h;
	scanf("%d", &n);
	scanf("%d%d", &t, &a);
	for (i = 0; i < n; i++) {
		scanf("%d", &h[i]);
		temp = t - h[i] * 0.006;
		if (i == 0) {
			ans = i + 1;
			ans_h = temp;
		}
		else {
			if (fabs(a - temp) < fabs(a - ans_h)) {
				ans_h = temp;
				ans = i + 1;
			}
		}

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

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
const long long INF = 0x7F7F7F7F7F7F7F7F;

int main()
{
    int n, k;
    long long h, ans=INF, dif;
    cin >> n >> k;
    vector<long long> H(n);

	for (int i = 0; i < n; i++)
	{
		cin >> H[i];
	}
    sort(H.begin(), H.end());

    for (int i=0; i<(n-k+1); i++)
    {
        dif = H[(i+k-1)]-H[i];
        ans = min(ans, dif);
    }
    cout << ans << endl;
 	return 0;
    
}

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

int main(){
    int N;
    cin >> N;
    vector<string> w(N);
    for(size_t i = 0; i < N; i++)
    {
        cin >> w[i];
    }
    for(auto it = next(w.begin(), 1); it != w.end(); ++it)
    {
        if(prev(it, 1)->substr(prev(it, 1)->length()-1, 1) != it->substr(0, 1) || find(w.begin(), it, *it) != it) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 384
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>

using namespace std;

// typedef long long ll;
// typedef vector <int> vi;
// typedef vector < vector <int> > vvi;
const int HUGEI = 2147483647;  // (1 << 31) - 1
const long long HUGEL = 9223372036854775807;  // (1 << 63) - 1
const string ABC = "abcdefghijklmnopqrstuvwxyz";
const int MAX = 2000;

long long n, x;
long long an[MAX], bn[MAX], bn2[MAX];

long long positive_modulo(long long i, long long n) {
    return (n + (i % n)) % n;
}

int main(void) {
    cin >> n >> x;
    for (int i = 0; i < n; i++) {
        cin >> an[i];
    }
    for (int i = 0; i < n; i++) bn[i] = HUGEL;
    long long res = HUGEL;
    for (int k = 0; k < n; k++) {
        for (int i = 0; i < n; i++) {
            bn2[i] = min(bn[i], an[positive_modulo(i - k, n)]);
        }
        long long su = 0;
        for (int i = 0; i < n; i++) {
            bn[i] = bn2[i];
            su += bn[i];
        }
        res = min(res, k * x + su);
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline

def main():
  n, m = map(int, input().split())
  S = [[] for _ in range(m+1)]
  for _ in range(n):
    l, r = map(int, input().split())
    S[r-l+1].append((l, r))
  
  BIT = [0]*(m+2)
  def add(i, a):
    while i <= m+1:
      BIT[i] += a
      i += i&(-i)
  def bit_sum(i):
    res = 0
    while i > 0:
      res += BIT[i]
      i -= i&(-i)
    return res
  cnt = n
  for i in range(1, m+1):
    for l, r in S[i]:
      cnt -= 1
      add(l, 1)
      add(r+1, -1)
    res = cnt
    for j in range(0, m+1, i):
      res += bit_sum(j)
    print(res)

if __name__ == "__main__":
  main()

Measured memory_bytes: 82324
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdlib>

int main() {
	int n, m, ans = 0;
	std::cin >> n;
	std::vector <int> t(n);
	for (int i = 0; i < n; ++i) { std::cin >> t[i]; }
	std::cin >> m;
	std::vector <int> p(m), x(m);
	for (int i = 0; i < m; ++i) {std::cin >> p[i] >> x[i];}
	for (int i = 0; i < m; ++i) {
		for (int j = 0; j < n; ++j) {
			ans += t[j];
		}
		std::cout << ans - t[p[i]-1] + x[i] << std::endl;
		ans = 0;
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define GET_MACRO(_1,_2,_3,_4,_5,_6,_7,_8,NAME,...) NAME
#define pr(...) cerr<< GET_MACRO(__VA_ARGS__,pr8,pr7,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__) <<endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d)
#define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e)
#define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f)
#define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g)
#define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h)
#define prArr(a) {cerr<<(#a)<<"={";int i=0;for(auto t:(a))cerr<<(i++?", ":"")<<t;cerr<<"}"<<endl;}
using namespace std;
using Int = long long;
using _int = int;
using ll = long long;
using Double = long double;
const Int INF = (1LL<<60)+1e9; // ~ 1.15 * 1e18
const Int mod = (1e9)+7;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int,Int>;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
template<class T1, class T2> ostream& operator<<(ostream& o,pair<T1,T2> p){return o<<"("<<p.first<<","<<p.second<<")";}
template<class T1, class T2, class T3> ostream& operator<<(ostream& o,tuple<T1,T2,T3> t){
  return o<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
template<class T1, class T2> istream& operator>>(istream& i,pair<T1,T2> &p){return i>>p.first>>p.second;}
template<class T> ostream& operator<<(ostream& o,vector<T> a){Int i=0;for(T t:a)o<<(i++?" ":"")<<t;return o;}
template<class T> istream& operator>>(istream& i,vector<T> &a){for(T &t:a)i>>t;return i;}
//INSERT ABOVE HERE


signed main(){
  srand((unsigned)time(NULL));
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  string s;
  cin>>s;

  if(s[0] == 'S') cout<<"Cloudy"<<endl;
  else if(s[0] == 'C')cout<<"Rainy"<<endl;
  else cout<<"Sunny"<<endl;

  return 0;
}


Measured memory_bytes: 256