akhauriyash/Code-Regression huggingface dataset:
import java.math.BigInteger;
import java.util.*;

public class Main {

	private static List<Abcdn> getStrings(Scanner sc, int num) {
		List<Abcdn> stringList = new ArrayList<>();
		while(num>0) {
			long n = sc.nextLong();
			long a = sc.nextLong();
			long b = sc.nextLong();
			long c = sc.nextLong();
			long d = sc.nextLong();
			stringList.add(new Abcdn(n,a,b,c,d));
			num--;
		}
		return stringList;
	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		List<Abcdn> array = getStrings(sc, n);
		for (int i = 0; i < n; i++) {
			Abcdn abcdn = array.get(i);

			Map<Long, BigInteger> map = new HashMap<>();
			map.put(0L, BigInteger.ZERO);
			map.put(1L, new BigInteger(String.valueOf(abcdn.d)));
			calc(abcdn, map, abcdn.n);
			System.out.println(map.get(abcdn.n));
		}
	}

	private static BigInteger calc(Abcdn abcdn, Map<Long, BigInteger> map, long n) {
		if (map.containsKey(n)) {
			return map.get(n);
		}
		long la = (n/2)*2;
		long ua = ((n+1)/2)*2;
		long lb = (n/3)*3;
		long ub = ((n+2)/3)*3;
		long lc = (n/5)*5;
		long uc = ((n+4)/5)*5;
		String value = "1000000000000000000";
		BigInteger res = new BigInteger(value);
		if (n < res.longValue()/abcdn.d) res = new BigInteger(String.valueOf(n)).multiply(new BigInteger(String.valueOf(abcdn.d)));
		res = res.min(calc(abcdn, map, la/2).add(new BigInteger(String.valueOf(abcdn.a))).add(new BigInteger(String.valueOf(Math.abs(la-n)*abcdn.d))));
		res = res.min(calc(abcdn, map, ua/2).add(new BigInteger(String.valueOf(abcdn.a))).add(new BigInteger(String.valueOf(Math.abs(ua-n)*abcdn.d))));
		res = res.min(calc(abcdn, map, lb/3).add(new BigInteger(String.valueOf(abcdn.b))).add(new BigInteger(String.valueOf(Math.abs(lb-n)*abcdn.d))));
		res = res.min(calc(abcdn, map, ub/3).add(new BigInteger(String.valueOf(abcdn.b))).add(new BigInteger(String.valueOf(Math.abs(ub-n)*abcdn.d))));
		res = res.min(calc(abcdn, map, lc/5).add(new BigInteger(String.valueOf(abcdn.c))).add(new BigInteger(String.valueOf(Math.abs(lc-n)*abcdn.d))));
		res = res.min(calc(abcdn, map, uc/5).add(new BigInteger(String.valueOf(abcdn.c))).add(new BigInteger(String.valueOf(Math.abs(uc-n)*abcdn.d))));
//		res = Math.min(res, calc(abcdn, map, ua/2) + abcdn.a + Math.abs(ua-n)*abcdn.d);
//		res = Math.min(res, calc(abcdn, map, lb/3) + abcdn.b + Math.abs(lb-n)*abcdn.d);
//		res = Math.min(res, calc(abcdn, map, ub/3) + abcdn.b + Math.abs(ub-n)*abcdn.d);
//		res = Math.min(res, calc(abcdn, map, lc/5) + abcdn.c + Math.abs(lc-n)*abcdn.d);
//		res = Math.min(res, calc(abcdn, map, uc/5) + abcdn.c + Math.abs(uc-n)*abcdn.d);
		map.put(n, res);
		return res;
	}

}

class Abcdn  {
	long n;
	long a;
	long b;
	long c;
	long d;

	public Abcdn(long n, long a, long b, long c, long d) {
		this.n = n;
		this.a = a;
		this.b = b;
		this.c = c;
		this.d = d;
	}
}



Measured memory_bytes: 87000
#include<bits/stdc++.h>
using namespace std;
int main() {
  int A, B, mouse, res = 1;
  cin >> A >> B;
  mouse = A;
  A--;
  while(mouse < B) {
    mouse += A;
    res++;
  }
  if(B == 1) res = 0;
  cout << res << endl;
}

Measured memory_bytes: 3472
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <math.h>
#include <complex>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <functional>
#include <assert.h>
#define int long
#define ll long long
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define SZ(x) x.size()
#define fi first
#define se second
const int INF = 1e9;
using namespace std;

template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;

using pi=pair<int,int>;
using vi=vc<int>;

template <typename T>
vector<T> dijkstra(int s,vector< vector< pair<int, T> > > & G){
  const T INF = numeric_limits<T>::max();
  using P = pair<T, int>;
  int n=G.size();
  vector<T> ds(n,INF);
  vector<int> bs(n,-1);
  priority_queue<P, vector<P>, greater<P> > pq;
  ds[s]=0;
  pq.emplace(ds[s],s);
  while(!pq.empty()){
    P p=pq.top();pq.pop();
    int v=p.second;
    if(ds[v]<p.first) continue;
    for(auto& e:G[v]){
      int u=e.first;
      T c=e.second;
      if(ds[u]>ds[v]+c){
        ds[u]=ds[v]+c;
        bs[u]=v;
        pq.emplace(ds[u],u);
      }
    }
  }
  return ds;
}

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(20);

    int N; cin >> N;
    vc<vc<pi>> G(N);
    rep(i,N-1){
        int a,b,c; cin >> a >> b >> c;
        a--; b--;
        G[a].eb(b,c);
        G[b].eb(a,c);
    }

    int Q,K; cin >> Q >> K;
    vi dis = dijkstra(K-1,G);
    vi v;
    rep(i,Q){
        int a,b; cin >> a >> b;
        a--; b--;
        v.eb(dis[a]+dis[b]);
    }
    rep(i,Q){
        cout << v[i] << endl;
    }
}

Measured memory_bytes: 11888
//Sani buyuk Osman Pasa Plevneden cikmam diyor.
//FatihSultanMehmedHan
//Abdulhamid Han
//Bismillahirrahmanirrahim
//█▀█─█──█──█▀█─█─█
//█▄█─█──█──█▄█─█▄█
//█─█─█▄─█▄─█─█─█─█

#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>

using namespace std;

typedef long long lo;
typedef pair< int,int > PII;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define FOR for(lo i=1;i<=n;i++)
#define mid ((start+end)/2)
#define ort ((bas+son)/2)

const lo MAX = -1000000000000000000;
const lo MIN = 1000000000000000000;
const lo inf = 1000000000;
const lo KOK = 100000;
const lo LOG = 30;
const lo li = 500005;
const lo mod = 1000000007;

lo n,m,b[li],a[li],k,flag,t;
lo cev;
string s;
vector<lo> v;
vector<lo> r;
vector<lo> l;

int main(void){
	fio();
	cin>>s;
	for(lo i=0;i<(lo)s.size();i++){
		if(s[i]=='R')r.pb(i);
		if(s[i]=='L')l.pb(i);
	}
	sort(l.begin(),l.end());
	sort(r.begin(),r.end());
	for(lo i=0;i<(lo)s.size();i++){
		if(s[i]=='R'){
			lo at=lower_bound(l.begin(),l.end(),i)-l.begin();
			lo hamle=l[at]-i;
			if(hamle%2==0)b[l[at]]++;
			else b[l[at]-1]++;
		}
		else{
			lo at=upper_bound(r.begin(),r.end(),i)-r.begin();
			at--;
			lo hamle=r[at]-i;
			if(hamle%2==0)b[r[at]]++;
			else b[r[at]+1]++;
		}
	}
	for(lo i=0;i<(lo)s.size();i++){
		cout<<b[i]<<" ";
	}
	return 0;
}


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

int main(){
  int n;
  string s;
  cin >> n >> s;
  int n100, n010, n001;
  int ans = 0;
  for(int i=0; i<1000; ++i){
    n100 = i/100;
    n010 = i/10%10;
    n001 = i%10;
    bool f1 = true, f2 = false, f3 = false;
    for(int j=0; j<n; ++j){
      int si = s[j] - '0';
      if(f3 && n001 == si){ ++ans; break;}
      if(f2 && n010 == si){ f3 = true; f2 = false;}
      if(f1 && n100 == si){ f2 = true; f1 = false;}
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String args[]){
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        long sum = 1;
        for(int i = n ; i >= 1 ; i--){
        	sum *= i;
        }
        System.out.println(sum);
    }
}

Measured memory_bytes: 17160
s = gets.chomp

front_half = s.slice(0..1).to_i
end_half = s.slice(2..3).to_i

if front_half.between?(1,12) && end_half.between?(1,12)
  puts "AMBIGUOUS"
elsif front_half.between?(1,12) && !end_half.between?(1,12)
  puts "MMYY"
elsif !front_half.between?(1,12) && end_half.between?(1,12)
  puts "YYMM"
else
  puts "NA"
end



Measured memory_bytes: 1916
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;

#define REP(i,n) for(long long i = 0; i < (n); i++)
#define FOR(i, m, n) for(long long i = (m);i < (n); ++i)
#define ALL(obj) (obj).begin(),(obj).end()

template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;

const ll MOD = (ll)1e9 + 7;
const ll MOD2 = 998244353;
const ll HINF = (ll)1e18;
const ll LINF = (ll)1e15;
const long double PI = 3.1415926535897932384626433;

template<typename T> vector<T> make_v(size_t N,T init){return vector<T>(N,init);}
template<typename... T> auto make_v(size_t N,T... t){return vector<decltype(make_v(t...))>(N,make_v(t...));}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) {o << "{"; for (auto &x : obj) o << " {" << x.first << " : " << x.second << "}" << ","; o << " }"; return o;}
template <class T>ostream &operator<<(ostream &o, const set<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) {o << "{"; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "}"; return o;}
template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) {o << "{" << obj.first << ", " << obj.second << "}"; return o;}
template <template <class tmp>  class T, class U> ostream &operator<<(ostream &o, const T<U> &obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr)o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
void print(void) {cout << endl;}
template <class Head> void print(Head&& head) {cout << head;print();}
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {cout << head << " ";print(forward<Tail>(tail)...);}
template <class T> void chmax(T& a, const T b){a=max<T>(a,b);}
template <class T> void chmin(T& a, const T b){a=min<T>(a,b);}
void YN(bool flg) {cout << ((flg) ? "YES" : "NO") << endl;}
void Yn(bool flg) {cout << ((flg) ? "Yes" : "No") << endl;}
void yn(bool flg) {cout << ((flg) ? "yes" : "no") << endl;}

long long GCD(long long a, long long b) {
    return ((b == 0) ? a : GCD(b, a % b));
}

int main() {
	int N; cin >> N;
	V<ll> a(N); REP(i,N) cin >> a[i];
	int M = sqrt(N) + 10;
	V<ll> b(M,0);
	for(int i = 0; i < N; i += M){
		ll cnt = 0;
		for(int j = i; j < i + M && j < N; ++j){
			cnt = GCD(cnt,a[j]);
		}
		b[i/M] = cnt;
	}
	ll ans = 0;
	for(int i = 0; i < N; ++i){
		ll cnt = 0;
		for(int j = 0; j < M; ++j) if(j != (i/M)) cnt = GCD(cnt,b[j]);
		for(int j = i/M; j < (i/M) + M && j < N; ++j) if(j != i) cnt = GCD(cnt,a[j]); 
		chmax(ans,cnt);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1024
import itertools
N = int(input())
s = [int(input()) for _ in range(N)] + [0]
L = list(itertools.combinations(s,N))
res = 0
for l in L:
    tmp_sum = sum(l)
    if tmp_sum%10==0:
        continue
    res = max(res,tmp_sum)
print(res)

Measured memory_bytes: 3060
#include <stdio.h>
#include <stdlib.h>

int main()
{
    int A,B,C,D;
    while(~scanf("%d %d %d %d",&A,&B,&C,&D))
    {
       if(A*B>C*D)
        printf("%d\n",A*B);
       else
        printf("%d\n",C*D);
    }
    return 0;
}


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

using namespace std;

int main(){
    vector<int> a;
    int k;
    for(int i = 0; i < 5; i++){
        int tmp;
        cin >> tmp;
        a.push_back(tmp);
    }
    cin >> k;

    vector<int>::iterator iter_max = max_element(a.begin(), a.end());
    vector<int>::iterator iter_min = min_element(a.begin(), a.end());
    
    size_t max =  distance(a.begin(), iter_max);
    size_t min = distance(a.begin(), iter_min);

    if(a[max] - a[min] <= k)cout << "Yay!" << endl;
    else cout << ":(" << endl;


    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(),(obj).end()
#define sortall(obj) sort(ALL(obj))
#define revall(obj) reverse(ALL(obj))
#define SortRevAll(obj) revall(sortall(obj))
typedef string str;
typedef long long ll;
const int mod=1e9+7;
const int INF=1e9;
const ll LINF=1e18;
#define VI vector<int>
#define P pair
#define M map
#define F first()
#define S second()
#define PB(a) push_back(a)
#define IN(a) insert(a)
#define ins(a) int a;cin >> a
#define lls(a) ll a;cin >> a
#define in(a) cin >> a
#define sts(a) string (a);cin >> a
#define For(i,m,n) for(int i=m;i<n;i++)
#define rep(i,n) For(i,0,n)
#define Forr(i,m,n) for(int i=n-1;i>=m;i--)
#define repr(i,n) Forr(i,0,n)
#define print(a) cout << a << endl
#define Endl cout << endl
#define YES(n) cout << ((n)? "YES" : "NO") << endl
#define Yes(n) cout << ((n)? "Yes" : "No") << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE" ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl
#define br(c,y,n) cout << ((c)? y : n) << endl

int main()
{
    ins(n);ins(h);ins(w);int cnt=0;
    VI a(n),b(n);
    rep(i,n){
        in(a.at(i));
        in(b.at(i));
        if(a.at(i)>=h&&b.at(i)>=w)cnt++;
    }
    print(cnt);
    return 0;
}


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

#define FOR( i, m, n )   for( int i = m; i < n; i++ )
#define REP( i, n )      FOR( i, 0, n )
#define ALL( a )         (a).begin(), (a).end()

int main(){
  int n;

  while( 1 ){
    cin >> n; if( n == 0 ) break;

    int cnt = 0;
    FOR( i,1,  n / 2 + 1 ){
      int tmp = 0, it = i;
      while( 1 ){
	tmp += it;
	it++;
	if( tmp == n ) cnt++;
	if( tmp > n ) break;
      }
    }

    cout << cnt << endl;
  }

}



Measured memory_bytes: 2956
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <cmath>
#include <iomanip>
#include <bitset>
#include <string>
#include <stdlib.h>
using namespace std;
//cout <<  << endl;
typedef long long int ll;
typedef long double ld;

int main(){
    string a;
    cin >> a;
    for (int i=0;i<3;++i){
        if (a[i]=='1'){
            a[i]='9';
            continue;
        }
        a[i]='1';
    }
    cout << a << endl;
    return 0;
}


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

struct Data {
	using type = int;
	type val, lazy;

	static type id() { return INT_MAX; }
	static type op(const type& l, const type & r) { return min(l, r); }

	Data(type v) : val(v), lazy(-1) {}
	void update(type a) { lazy = a; }
	type get() { return lazy == -1 ? val : lazy; }
	void push() {
		if (lazy == -1) return;
		val = lazy;
	}
	void push(Data& l, Data& r) {
		if (lazy == -1) return;
		val = lazy;
		l.lazy = lazy;
		r.lazy = lazy;
	}
};

template <typename M>
class LazySegmentTree {
	using T = typename M::type;
	const int n;
	vector<M> data;
	int size(int n) {
		int res = 1;
		while (res < n) res <<= 1;
		return res;
	}
	void suc(int l, int r, int node, int lb, int ub, T val) {
		if (ub <= l || r <= lb) return;
		if (ub - lb > 1) data[node].push(data[node * 2], data[node * 2 + 1]);
		if (l <= lb && ub <= r) {
			data[node].update(val);
			return;
		}
		int c = (lb + ub) / 2;
		suc(l, r, node * 2, lb, c, val);
		suc(l, r, node * 2 + 1, c, ub, val);
		data[node] = M::op(data[node * 2].get(), data[node * 2 + 1].get());
	}
	T sub(int l, int r, int node, int lb, int ub) {
		if (ub <= l || r <= lb) return M::id();
		if (l <= lb && ub <= r) return data[node].get();
		data[node].push(data[node * 2], data[node * 2 + 1]);
		int c = (lb + ub) / 2;
		return M::op(sub(l, r, node * 2, lb, c), sub(l, r, node * 2 + 1, c, ub));
	}
public:
	LazySegmentTree(int n_) : n(size(n_)), data(n * 2, M::id()) {}
	void init(const vector<T>& data_) {
		for (int i = 0; i < (int)data_.size(); i++)
			data[i + n] = data_[i];
		for (int i = n - 1; i >= 0; i--)
			data[i] = M::op(data[i * 2], data[i * 2 + 1]);
	}
	void update(int l, int r, T val) {
		suc(l, r + 1, 1, 0, n, val);
	}
	T find(int l, int r) {
		return sub(l, r + 1, 1, 0, n);
	}
};

int main()
{
	ios::sync_with_stdio(false), cin.tie(0);
	int n, q, com, x, y, val;
	cin >> n >> q;
	LazySegmentTree<Data> st(n);
	while (q--) {
		cin >> com >> x >> y;
		if (com) {
			printf("%d\n", st.find(x, y));
		}
		else {
			cin >> val;
			st.update(x, y, val);
		}
	}
	return 0;
}

Measured memory_bytes: 4936
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys,collections,itertools,re,math,fractions,decimal,random,array,bisect,heapq

# decimal.getcontext().prec = 50
# sys.setrecursionlimit(10000)
# MOD = 10**9 + 7

def solve(f):
    n, m = f.read_int_list()
    p = [i-1 for i in f.read_int_list()]
    uf = UnionFind(n)
    for _ in xrange(m):
        x, y = f.read_int_list()
        uf.unite(x-1, y-1)

    ans = 0
    for i, pi in enumerate(p):
        if uf.in_the_same_set(i, pi):
            ans += 1

    return ans


class UnionFind(object):
    def __init__(self, number_of_nodes):
        # Don't use self.par directly! (call self.root)
        self.par = array.array("L", range(number_of_nodes))
        self.rank = array.array("L", (0 for _ in range(number_of_nodes)))

    def root(self, node):
        if self.par[node] == node:
            return node
        else:
            r = self.root(self.par[node])
            self.par[node] = r
            return r

    def in_the_same_set(self, node1, node2):
        return self.root(node1) == self.root(node2)

    def unite(self, node1, node2):
        x = self.root(node1)
        y = self.root(node2)
        if x == y:
            pass
        elif self.rank[x] < self.rank[y]:
            self.par[x] = y
        else:
            self.par[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1


class Reader(object):
    def __init__(self, filename=None):
        self.file = open(filename) if filename is not None else None
        self.case = 1

    def __readline(self):
        return self.file.next().strip() if self.file else raw_input()

    def next_case(self):
        self.file.next()
        self.case += 1

    def read_int(self): return int(self.__readline())
    def read_float(self): return float(self.__readline())
    def read_long(self): return long(self.__readline())
    def read_decimal(self): return decimal.Decimal(self.__readline())
    def read_str(self): return self.__readline()

    def read_int_list(self): return map(int, self.__readline().split())
    def read_float_list(self): return map(float, self.__readline().split())
    def read_long_list(self): return map(long, self.__readline().split())
    def read_decimal_list(self): return map(decimal.Decimal, self.__readline().split())
    def read_str_list(self): return self.__readline().split()

if __name__ == '__main__':
    filename = sys.argv[1] if len(sys.argv) > 1 else None
    f = Reader(filename)
    if f.file:
        while True:
            print "Case #%d\n"%f.case, solve(f)
            try:
                f.next_case()
            except StopIteration:
                break
    else:
        print solve(f)


Measured memory_bytes: 14848
#include<bits/stdc++.h>
#define ll long long
#define maxn 200005
using namespace std;
inline int read(){
	int u=0,f=1;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9'){u=u*10+c-'0';c=getchar();}
	return u*f;
}

struct node{
	int l,r,bo;
}p[maxn];

bool cmpl(node a,node b){
	return (a.l==b.l?a.r>b.r:a.l<b.l);
}

bool cmpr(node a,node b){
	return a.r>b.r;
}

int l,r,n,m,ans;
int main(){
	n=read();m=read();l=1,r=m;
	for(int i=1;i<=n;i++)p[i].l=read(),p[i].r=read();
	sort(p+1,p+n+1,cmpl);
	for(int i=1;i<=n;i++){
		if(p[i].l>m)break;
		if(l<=p[i].l){
			l++;ans++;
			p[i].bo=1;
		}
	}
	sort(p+1,p+n+1,cmpr);
	for(int i=1;i<=n;i++){
		if(r<l)break;
		if(r>=p[i].r&&!p[i].bo){
			r--;ans++;
			p[i].bo=1;
		}
	}
	cout<<n-ans<<endl;
	return 0;
}



Measured memory_bytes: 2560
while True:
    n, x = map(int, input().split())
    if n == x == 0:
        break
  
    result = 0
    for a in range(1, x // 3):
        for b in range(a + 1,  x // 2):
            c = x - a - b
            if b < c <= n:
                result += 1    
    print(result)

Measured memory_bytes: 7612
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()
#define bit(k) (1LL<<(k))
#define SUM(v) accumulate(all(v), 0LL)

typedef pair<int, int> i_i;
typedef pair<ll, ll> l_l;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
struct fast_ios{ fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; }fast_ios_;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

#define TOSTRING(x) string(#x)
template <typename T> istream &operator>>(istream &is, vector<T> &vec) { for (T &x : vec) is >> x; return is; }
template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { os  << "["; for(auto _: v) os << _ << ", "; os << "]"; return os; };
template <typename T> ostream &operator<<(ostream &os, set<T> &st) { os << "("; for(auto _: st) { os << _ << ", "; } os << ")";return os;}
template <typename T, typename U> ostream &operator<<(ostream &os, const pair< T, U >& p){os << "{" <<p.first << ", " << p.second << "}";return os; }
template <typename T, typename U> ostream &operator<<(ostream &os, const map<T, U> &mp){ os << "["; for(auto _: mp){ os << _ << ", "; } os << "]" << endl; return os; }

#define DUMPOUT cerr
void dump_func(){ DUMPOUT << endl; }
template <class Head, class... Tail> void dump_func(Head &&head, Tail &&... tail) { DUMPOUT << head; if (sizeof...(Tail) > 0) { DUMPOUT << ", "; } dump_func(std::move(tail)...); }

#ifdef DEBUG
#define dbg(...) dump_func(__VA_ARGS__)
#define dump(...) DUMPOUT << string(#__VA_ARGS__) << ": "; dump_func(__VA_ARGS__)
#else
#define dbg(...)
#define dump(...)
#endif

const int INF = (ll)1e9;
const ll INFLL = (ll)1e18+1;
const ll MOD = 1000000007;
// const ll MOD = 998244353;
const long double PI = acos(-1.0);

/*
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const string dir = "DRUL";
*/

vector<int> v[100010];
int main() {
    ll N, K;
    vector<ll> p(3);
    string T;
    cin >> N >> K;
    rep(i,3)cin >> p[i];
    cin >> T;
    vector<int> vt(N,-1);
    rep(i,N){
        if(T[i] == 'r')vt[i] = 0;
        if(T[i] == 's')vt[i] = 1;
        if(T[i] == 'p')vt[i] = 2;
    }
    rep(i,N)v[i%K].emplace_back(vt[i]);
    ll ans = 0;
    rep(i,N){
        auto t = v[i];
        int M = t.size();
        if(M == 0)break;
        // この配列についてdp
        vvec<ll> dp(M+1, vec<ll>(3,0));
        rep(j,M)rep(a,3)rep(b,3){
            // j => k
            if(a == b)continue;
            int kati = (b + 1) % 3;
            if(t[j] == kati){
                chmax(dp[j+1][b], dp[j][a] + p[b]);
            }
            else{
                chmax(dp[j+1][b], dp[j][a]);
            }
        }
        dump(ans);
        ans += *max_element(all(dp[M]));
    }
    cout << ans << endl;
}


Measured memory_bytes: 12220
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  	string S;
    int m;
  	cin >> S;
  	m=(S[5]-'0')*10+S[6]-'0';
  	if (m<=4){
      cout << "Heisei";
    }
  	else{
      cout << "TBD";
    }
}


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

#define ll long long
using namespace std;

const ll INF = 1e11;
ll n, m, l, q;
ll graph[311][311];
ll graph2[311][311];
ll st[300*300+10][2];
ll abc[300*300+10][3];


void input(){
  cin>>n>>m>>l;
  for(int i=0;i<m;i++){cin>>abc[i][0]>>abc[i][1]>>abc[i][2];}
  cin>>q;
  for(int i=0;i<q;i++){cin>>st[i][0]>>st[i][1];}
}

int main(){
  input();

  for(int i=0; i<=n; i++){
    for(int j=0; j<=n; j++){
      graph[i][j]=INF;
      graph2[i][j]=INF;
    }
    graph[i][i]=0;
    graph2[i][i]=0;
  }

  for(int i=0; i<m; i++){
    graph[abc[i][0]][abc[i][1]] = abc[i][2];
    graph[abc[i][1]][abc[i][0]] = abc[i][2];
  }

  for(int k=0; k<=n; k++){
    for(int i=0; i<=n; i++){
      for(int j=0; j<=n; j++){
        if (graph[i][j] > graph[i][k] + graph[k][j]){graph[i][j] = graph[i][k] + graph[k][j];}
      }
    }
  }

  for(int i=0; i<=n; i++){
    for(int j=0; j<=n; j++){
      if(graph[i][j] <= l){graph2[i][j] = 1;}
    }
  }

  for(int k=0; k<=n; k++){
    for(int i=0; i<=n; i++){
      for(int j=0; j<=n; j++){
        if (graph2[i][j] > graph2[i][k] + graph2[k][j]){graph2[i][j] = graph2[i][k] + graph2[k][j];}
      }
    }
  }

  for(int i=0; i<q; i++){
    ll result = graph2[st[i][0]][st[i][1]]==(INF) ? -1 : graph2[st[i][0]][st[i][1]]-1;
    cout <<result << endl;
  }

 return 0;
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rrep(i,n) for (int i = (int)(n)-1; i>=0; --i)
#define For(i,a,b) for(auto i=(a);i<=(b);++i)
#define rFor(i,a,b) for(auto i=(b);i>=(a);--i)
#define call(var) cerr<<#var<<"="<<var<<"\n";
#define dup(x,y) (((x)+(y)-1)/(y))
#define all(x) (x).begin(),(x).end()
using ll=long long;
using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
using Graph = vector<vi>;
using P = pair<int,int>;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;
const double pi = acos(-1);
template<class t,class u> inline bool chmax(t&a,u b){if(a<b){a=b;return true;}return false;}
template<class t,class u> inline bool chmin(t&a,u b){if(b<a){a=b;return true;}return false;}
template<class T> istream& operator>>(istream& is, vector<T>& a){rep(i,a.size()) is >> a[i]; return is;}
template<class T> ostream& operator<<(ostream& os, vector<T>& a){rep(i,a.size()) os << a[i] << " "; return os;}
template<class T, class U> istream& operator>>(istream& is, pair<T,U>& p){is >> p.first >> p.second; return is;}
template<class T, class U> ostream& operator<<(ostream& os, const pair<T,U>& p){os << "("<< p.first << "," << p.second << ")"; return os;}
template<class T, class U> ostream& operator<<(ostream& os, const map<T,U>& mp){for(auto& t : mp) os << t.first << " " << t.second << "\n"; return os;}

int main(){
    int n,k;cin >> n >> k;
    vi p(n);
    cin >> p;
    sort(all(p));

    cout << accumulate(p.begin(), p.begin() + k, 0) << "\n";
}

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

int main(){
	int n;
	cin >> n;
	
	int b[300000] = {};
	
	for(int i = 0;i < n;i++){
		int x, y;
		cin >> x >> y;
		b[x+y] += 1;
	}

	for(int i = 0;i < 300000-1;i++){
		b[i+1] += b[i] / 2;
		b[i] %= 2;
	}

	for(int i = 0;i < 300000;i++){
		if(b[i] != 0){
			cout << i << " " << 0 << endl;
		}
	}

	return 0;
}


Measured memory_bytes: 4268
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int isPrime(int n){
  for(int i=2;i*i<=n;i++) if(n%i==0) return 0;
  return 1;
}
int main(){
  int n,p,i,j,k,o,dp[200000]={};
  for(i=2;i<200000;i++) dp[i]=isPrime(i);
  cin >> n >> p;
  while(n!=-1){
    int c=0;
    int l[100]={};
    i=n;
    while(c<100){
      i++;
      if(dp[i]==1){
	l[c]=i;
	c++;
      }
    }
    vector <int> v;
    for(i=0;i<100;i++){
      for(j=i;j<100;j++){
	v.push_back(l[i]+l[j]);
      }
    }
    sort(v.begin(),v.end());
    cout << v[p-1] << endl;
    cin >> n >> p;
  }
  return 0;
}

Measured memory_bytes: 2056
#include<iostream> 
#include<string> 
#include<vector> 
#include<algorithm> 
#include<cmath>
#include<set>
#include<utility>

using namespace std;
int xxx(int y)
{
	return y * y;
}

int main()
{
	int k, s;
	cin >> k >> s;
	int ans = 0;
	for (int i = 0; i <= k; i++)
	{
		for (int j = 0; j <= k; j++)
		{
			if (s-i - j <= k&&s-i-j>=0)
			{
				ans++;
			}
			
		}
	}
	cout << ans << endl;


}


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

class UnionFind{
private:
    std::vector<int> parent;
    std::vector<int> size;
    
public:
    UnionFind(int N){
        parent.resize(N);
        size.resize(N);
        for(int i = 0; i < N; i++){
            parent[i] = i;
            size[i] = 1;
        }
    }

    int root(int x){
        if (parent[x] == x) return x;
        int rx = root(parent[x]);
        parent[x] = rx;
        return rx;
    }

    void unite(int x, int y){
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return;
        parent[rx] = ry;
        size[ry] += size[rx];
    }

    bool same(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
    
    int get_size(int x){
        return size[root(x)];
    }
};

int main(){
    int N, M;
    std::cin >> N >> M;
    UnionFind tree(N);
    std::vector< int > A(M);
    std::vector< int > B(M);
    for(int i=0; i<M; i++){
        std::cin >> A[i] >> B[i];
        tree.unite(A[i]-1, B[i]-1);
    }
    
    int max = 0;
    
    for(int i=0; i<N; i++){
        int cur = tree.get_size(i);
        if(max < cur){
            max = cur;
        }
    }
    
    std::cout << max << std::endl;
    
    
    return 0;
    
}


Measured memory_bytes: 12580
//g++ -std=gnu++14 a.cpp
//#include <bits/stdc++.h>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <tuple>
#include <iomanip>
#include <random>
#include <math.h>

using namespace std;

#define ll long long
#define rep(i, n) for(ll i = 0; i < (n); i++)
ll MOD = 1e9 + 7;
int INF = 1 << 30;
ll INFL = 1LL << 60;

int main(){
  ll N;
  cin >> N;
  vector<ll> A(N),B(N);
  rep(i,N)cin >> A[i] >> B[i];
  ll min,max;
  vector<ll> mi(N),ma(N);
  sort(A.begin(),A.end());
  sort(B.begin(),B.end());
  if(N%2==1){
    min = A[(N+1)/2-1];
    max = B[(N+1)/2-1];
  }else{
    min = A[N/2-1]+A[N/2];
    max = B[N/2-1]+B[N/2];
  }
  cout << max - min + 1 << endl;

}


Measured memory_bytes: 9576
def check(w, h, x, y, r)
    if x < r
        return "No"
    end
    if y < r
        return "No"
    end
    if x > w - r
        return "No"
    end
    if y > h - r
        return "No"
    end
    
    return "Yes"
end

w, h, x, y, r = gets.split.map &:to_i
puts check(w, h, x, y, r)



Measured memory_bytes: 8880
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>

typedef long long ll;
typedef unsigned long long ull;
using namespace std;

#define FALSE printf("false\n");
#define TRUE printf("true\n");
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i = 0;i < ((int)(n));++i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define test(a) cout<<"line:"<<__LINE__<<"["<<(#a)<<": "<<(a)<<"]"<<endl

const int INF = 1e9+7;
const ll INFL = 9*1e18;

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

// const int dx[8] = {1, 1, 0,-1,-1,-1, 0, 1};
// const int dy[8] = {0, 1, 1, 1, 0,-1,-1,-1};

#define SUM(vec) accumulate(all(vec),0LL) // 配列の中身を全部足す
template<typename T>void print(T&& x){cout<<x<<endl;}// 改行付き出力
ll inline digit(ll num){int tmp = 0;while(num){tmp++;num/=10;}return tmp;} // 桁数
template<typename T>inline T digitSum(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;} // 各桁の和
template<typename T>inline T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);} // 最大公約数
template<typename T>inline T lcm(T a, T b){T g = gcd(a,b);return a/g*b;} // 最小公倍数
template<typename T>inline T power(T a,T b){T tmp=1;rep(i,b){tmp*=a;}return tmp;} // 累乗
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; }
int ctoi(char c){return ('0' <= c && c <= '9')?(c - '0'):-1;}


// TODO: write
int main() {
  int n;cin>>n;
  vector<int> a(n);
  rep(i,n)cin>>a[i];
  
  rep(i,n){
    if(a[i]%2 == 0){
      if(!(a[i]%3 == 0 || a[i]%5 == 0)) {
        print("DENIED");
       
        return 0;
      }
    }
  }
  print("APPROVED");
  return 0;
}



Measured memory_bytes: 256
//
//  main.cpp
//

#include <algorithm>
#include <array>
#include <assert.h>
#include <iomanip>
#include <iostream>
#include <limits>
#include <math.h>
#include <memory>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

using ll = int64_t;
using ull = uint64_t;

template<typename T>
vector<T> make_vec_nd(T init, size_t size) {
    return vector<T>(size, init);
}
template<typename T, typename... Args>
auto make_vec_nd(T init, size_t size, Args... rest) {
    auto inner = make_vec_nd(init, rest...);
    return vector<decltype(inner)>(size, inner);
}

int main() {
    string s, t;
    cin >> s;
    cin >> t;
    struct DPInfo {
        ll length;
        pair<ll, ll> last;
    };
    auto info_max = [](DPInfo lhs, DPInfo rhs) {
        if (lhs.length < rhs.length) {
            return rhs;
        } else {
            return lhs;
        }
    };
    auto dp = make_vec_nd(DPInfo{0, {-1, -1}}, s.size(), t.size());
    for (ll i = 0; i < s.size(); i++) {
        for (ll j = 0; j < t.size(); j++) {
            if (i > 0) {
                dp[i][j] = info_max(dp[i][j], dp[i-1][j]);
            }
            if (j > 0) {
                dp[i][j] = info_max(dp[i][j], dp[i][j-1]);
            }
            if (s[i] == t[j]) {
                ll prev = 0;
                if (i > 0 && j > 0) {
                    prev = dp[i-1][j-1].length;
                }
                dp[i][j] = info_max(dp[i][j], DPInfo{prev+1, {i, j}});
            }
        }
    }
    string ans;
    ll i = s.size() - 1;
    ll j = t.size() - 1;
    while (true) {
        DPInfo info = dp[i][j];
        if (info.length == 0) {
            break;
        }
        ans.push_back(s[info.last.first]);
        i = info.last.first - 1;
        j = info.last.second - 1;
        if (i < 0 || j < 0) {
            break;
        }
    }
    reverse(ans.begin(), ans.end());
    cout << ans << endl;
}



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

int main() {
  int n; cin >> n;
  int m = n * (n-1) / 2;

  auto make_game = [&](int i, int j) {
    if (i > j) swap(i, j);
    return (n-1+n-i)*i/2 + (j-i-1);
  };

  vector<int> t[m];
  int degree[m] = {};
  for (int i = 0; i < n; i++) {
    int a[n-1];
    for (int j = 0; j < n-1; j++) {
      cin >> a[j];
      a[j]--;
    }
    for (int j = 0; j < n-2; j++) {
      int g = make_game(i, a[j]);
      int h = make_game(i, a[j+1]);
      t[g].push_back(h);
      degree[h]++;
    }
  }

  queue<int> que;
  int dist[m];
  for (int i = 0; i < m; i++) {
    if (degree[i] == 0) {
      que.push(i);
      dist[i] = 1;
    }
  }

  int ans = 0;
  while (!que.empty()) {
    int g = que.front(); que.pop();
    for (int h : t[g]) {
      if (--degree[h] == 0) {
        que.push(h);
        dist[h] = dist[g] + 1;
        ans = max(ans, dist[h]);
      }
    }
  }

  for (int i = 0; i < m; i++) {
    if (degree[i]) {
      cout << -1 << endl;
      return 0;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 31488
#include <iostream>

using namespace std;

int main()
{
	ios::sync_with_stdio(false);

	int X,Y,Z,A,B;

	cin >> A >> B;

	X = A + B;
	Y = A - B;
	Z = A * B;

	if(X >= Y && X >= Z){

		cout << X << "\n";

	} else if(Y >= X && Y >= Z){

		cout << Y << "\n";

	} else if(Z >= X && Z >= Y){

			cout << Z << "\n";
		}

	return 0;

}


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

typedef char                SINT8;
typedef unsigned char       UINT8;
typedef short               SINT16;
typedef unsigned short      UINT16;
typedef int                 SINT32;
typedef unsigned int        UINT32;
typedef long long           SINT64;
typedef unsigned long long  UINT64;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))

using namespace std;

int main() {

	SINT32 ans = 0;
	SINT32 N = 0;
	SINT32 count = 1;
	
	vector<SINT32> DATA(1000);
	for (SINT32 i = 0; i < 101; i ++) {
		DATA[i] = 0;
	}

	cin >> N;
	DATA [N] = 1;

	while (1) {
		count++;
		if ((N % 2) == 0) {
			N = N /2;
		} else {
			N = N*3+1;
		}
		if (DATA [N] == 1) {
			break;
		} else {
			DATA [N] = 1;
		}
	}
	
	
	cout << count << endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
using namespace std;
int main()
{
    int n,m,u,s=0;
    scanf("%1d%1d%1d",&n,&m,&u);
    s=(u==1?s+1:s);
    s=(m==1?s+1:s);
    s=(n==1?s+1:s);
    printf("%d\n",s);
    return 0;
} 

Measured memory_bytes: 128
from collections import Counter
n, k = map(int, input().split())
a = list(map(int, input().split()))
l = Counter(a)
if len(set(a)) <= k:
    print(0)
else:
    ci = list(l.values())
    ci.sort()
    i = 0
    cnt = len(ci)
    ans = 0
    while cnt > k:
        cnt -= 1
        ans += ci[i]
        i += 1
    print(ans)

Measured memory_bytes: 43952
import java.util.Scanner;
public class Main{
	public static  void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();
		if(a<b)
			System.out.println("a < b");
		if(a==b)
				System.out.println("a == b");
		if(a>b)
				System.out.println("a > b");
	}
}

Measured memory_bytes: 26108
#define _CRT_SECURE_NO_WARNINGS
#define MOD 1000000007 
#define INF 100000000
//#define MOD 3025908521 
#include <iostream>
#include <vector>
#include <list>
#include <set>
#include <bitset>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <string>
#include <functional>
#include <algorithm>
#include <iterator>
#include <cstdio>
#include <utility>
#include <unordered_map>
#include <cmath>
#include <chrono>
#include <random>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

typedef pair<ll, ll> P;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvl;
#define FOR(i,a,b) for(ll i=(a);i<=(b);++i)
#define RFOR(i,a,b) for(ll i=(a);i>=(b);i--)
#define REP(i,n) FOR(i,0,n-1)
#define RREP(i,n) RFOR(i,n-1,0)
#define ALL(obj) (obj).begin(), (obj).end()

inline ll madd(ll a, ll b) {
	a %= MOD;b %= MOD;
	return (a + b) % MOD;
}
inline ll msub(ll a, ll b) {
	a %= MOD;b %= MOD;
	a += MOD;
	return (a - b) % MOD;
}
inline ll mmul(ll a, ll b) {
	a %= MOD;b %= MOD;
	return (a*b) % MOD;
}
inline ll mpow(ll a, ll r) {
	long long res = 1;
	while (r > 0) {
		if (r & 1) res = res * a % MOD;
		a = a * a % MOD;
		r >>= 1;
	}
	return res;
}
inline ll minv(ll a) {
	a %= MOD;
	ll b = MOD, u = 0, v = 1;
	while (a) {
		ll t = b / a;
		b -= t * a; swap(a, b);
		u -= t * v; swap(u, v);
	}
	if (u < 0) u += MOD;
	return u;
}
inline ll mdiv(ll a, ll b) {
	a %= MOD;
	a *= minv(b);
	return a%MOD;
}


//ll fact[]
//inline ll combi(int a, int b) {
//	return mmul(fact[a], mmul(fact_inv[b], fact_inv[a - b]));
//}

struct UnionFind {
	vector<int> data;
	UnionFind(int size) : data(size, -1) { }
	bool unite(int x, int y) {
		x = root(x); y = root(y);
		if (x != y) {
			if (data[y] < data[x]) swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
		return x != y;
	}
	bool same(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};

struct edge { ll to, cost; };

int main() {
	multiset<ll> st;
	ll n, m;
	cin >> n >> m;
	REP(i, n) {
		ll j;
		cin >> j;
		st.insert(j);
	}
	REP(i, m) {
		auto itr = st.end();
		itr--;
		ll top = *itr/2;
		st.erase(itr);
		st.insert(top);
	}
	ll result = 0;
	auto itr = st.begin();
	REP(i, n) {
		result += *itr;
		itr++;
	}
	cout << result;
	
	return 0;
}


Measured memory_bytes: 4992
package main

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

var (
	readString func() string
	stdout     *bufio.Writer
)

func init() {
	readString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = readInt()
	}
	return b
}

func readLengthAndSlice() (int, []int) {
	n := readInt()
	return n, readIntSlice(n)
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}

func eprintln(args ...interface{}) (int, error) {
	return fmt.Fprintln(os.Stderr, args...)
}

// readString() string
// readInt() int
// readIntSlice(n int) []int
// readLengthAndSlice() []int

// -----------------------------------------------------------------------------

func main() {
	defer stdout.Flush()

	p := NewPrimes(55555)
	a := make([]int, 0, 60)

	for i := 2; i <= 55555; i++ {
		if p.IsPrime(i) && i%5 == 2 {
			a = append(a, i)
		}
	}

	n := readInt()
	sp := ""
	for i := 0; i < n; i++ {
		printf("%s%d", sp, a[i])
		sp = " "
	}
	println()
}

// -----------------------------------------------------------------------------

type Primes []bool

func NewPrimes(n int) Primes {
	m := n + 1
	p := make([]bool, m)
	for i := 3; i < m; i += 2 {
		p[i] = true
	}
	p[2] = true
	for i := 3; i*i < m; i += 2 {
		if !p[i] {
			continue
		}
		for j := i + i; j < m; j += i {
			p[j] = false
		}
	}

	return p
}

func (ps Primes) IsPrime(x int) bool {
	return ps[x]
}


Measured memory_bytes: 768
from collections import defaultdict
def Combi2(n):
  return n*(n-1)//2
def Combi3(n):
  return n*(n-1)*(n-2)//6
def main():
  n=int(input())
  d=defaultdict(int)
  l="MARCH"
  for _ in range(n):
    s=input()[0]
    if s in l:
      d[s]+=1
  if len(d)<3:
    print(0)
    return
  s=sum(d.values())
  ans=Combi3(s)
  for i in d.values():
    if i>=2:
      ans-=Combi2(i)*(s-i)
      if i>=3:
        ans-=Combi3(i)
  print(ans)
main()

Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
typedef long long int lli;
#define optimize ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define F first
#define S second
#define forn(i,n) for(int i = 0; i<n; i++)
#define forab(i,a,b) for(int i = a; i<b; i++)
#define forll(i,a,b) for(lli i = a; i<b; i++)
#define mp make_pair
#define pb emplace_back
#define sortv(v) sort(v.begin(), v.end())
#define debug(x) cout<<#x<<" : "<<x<<endl
#define all(x) x.begin(),x.end()
const int mod1 = 1000000007;
const int mod2 = 998244353;

int main()
{
	optimize

	int n;
	lli d;
	cin>>n>>d;
	int ans = 0;
	lli x,y;
	forn(i,n)
	{
		cin>>x>>y;

		if(x*x + y*y <= d*d)
			ans++;
	}

	cout<<ans<<endl;

	
	return 0;
}

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

int main(){
    int A,B,C;
    int X;
    int count=0;
    cin>>A;
    cin>>B;
    cin>>C;
    cin>>X;
    for(int a=0; a<=A; a++){
        for(int b=0; b<=B; b++){
            for(int c=0; c<=C; c++){
                int sum = 500*a + 100*b + 50*c;
                if(sum==X){
                    count++;
                }
            }
        }
    }
    cout<<count<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
vector<int> x4 = {0, 1, 0, -1}, x8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<int> y4 = {1, 0, -1, 0}, y8 = {1, 1, 0, -1, -1, -1, 0, 1};
template<class T> struct edge { int from, to; T cost;};
template<class T> inline bool chmin(T& a, T b){if (a>b){a = b; return true;}return false;}
template<class T> inline bool chmax(T& a, T b){if (a<b){a = b; return true;}return false;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }
template<class T> inline T power(T a,T b,T m){ if (b==0) return 1;
  T tmp = power(a,b/2,m); if (b%2==0) return tmp*tmp%m; else return tmp*tmp%m*a%m; }
template<class T> inline T gcd(T a, T b){if (b==0) return a; return gcd(b, a%b);}
template<class T> inline T lcm(T a, T b){return a / gcd(a,b) * b;}
// ax+by=gcd(a,b)を解く
template<class T> inline T extgcd(T a,T b,T &x,T &y){if (b==0){x=1; y=0; return a;} T d=extgcd(b,a%b,y,x); y -= a/b*x; return d;}
void hey(){ cout <<"hey" <<endl; }


struct Dice {
  int omote,ura,up,down,left,right;
  Dice(vector<int> &a){
    omote = a[0]; ura = a[5];
    up = a[4]; down = a[1];
    left = a[3]; right = a[2];
  }

  void operate(int &a,int &b,int &c,int &d){
    int buf = a;
    a = b; b = c; c = d; d = buf;
  }

  void rotate(char c){
    if (c == 'E') operate(omote, left, ura, right);
    if (c == 'N') operate(omote, down, ura, up);
    if (c == 'S') operate(omote, up, ura, down);
    if (c == 'W') operate(omote, right, ura, left);
    if (c == 'R') operate(down, right, up, left);
    if (c == 'L') operate(down, left, up, right);
  }
};

bool isidentical(Dice d1, Dice d2){
  bool ok = true;
  if (d1.omote != d2.omote ) ok = false;
  if (d1.ura != d2.ura ) ok = false;
  if (d1.up != d2.up ) ok = false;
  if (d1.down != d2.down ) ok = false;
  if (d1.left != d2.left ) ok = false;
  if (d1.right != d2.right ) ok = false;
  return ok;
}

int main() {
  vector<int> a(6); rep(i, 6) cin >>a[i];
  vector<int> b(6); rep(i, 6) cin >>b[i];
  Dice d1 = Dice(a);
  Dice d2 = Dice(b);
  bool ok = false;
  rep(i, 6){
    char c = i % 2 == 0 ? 'N' : 'W';
    d2.rotate(c);
    ok = ok | isidentical(d1, d2);
    rep(j, 4){
      d2.rotate('L');
      ok = ok | isidentical(d1, d2);
    }
  }
  cout <<(ok ? "Yes" : "No") <<endl;
}


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

int main(){
  int n,k,s=0,x;
  cin >> n >> k;
  for (int i=0;i<n;i++){
    cin >> x;
    if(x<k-x)
      s+=x*2;
    else
      s+=(k-x)*2;
  }
  cout << s <<endl;
}
  

Measured memory_bytes: 256
S = input()

flag = 0

words = ("dream","erase","dreamer","eraser")
count = 0

while len(S) >= 5:

    for i in words:
        N = len(i)
        if S[-N:] in words:
            n = len(S) - N
            S = S[:n]
            flag = 1
            break
        else:
            flag = 0
            continue


    if flag == 0:
        break



if len(S) == 0:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 9184
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int a = Integer.parseInt(sc.next());
        int b = Integer.parseInt(sc.next());
        if (a <= 8 && b <= 8) {
            System.out.println("Yay!");
        } else {
            System.out.println(":(");
        }
    }
}


Measured memory_bytes: 21844
import sys
import os
if sys.platform=="darwin":
	base = os.path.dirname(os.path.abspath(__file__))
	name = os.path.normpath(os.path.join(base, '../Documents/input.txt'))
	#print(name)
	sys.stdin = open(name)

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

i = 0
ans = 0

while i < n:
	if i==0:
		i = i + 1
	if l[i]==l[i-1]:
		l[i]=max(l)+1
		i = i + 1
		ans = ans + 1
	else:
		i = i + 1

print(ans)
#print(l)




Measured memory_bytes: 3064
def main():
    N=int(input())
    l=[0]*10**5
    sm=0
    A=map(int, input().split())
    for a in A:
        l[a-1]+=1
        sm+=a
    Q=int(input())
    BC=[list(map(int,input().split())) for _ in range(Q)]
    for bc in BC:
        cnt=l[bc[0]-1]
        l[bc[0]-1]=0
        l[bc[1]-1]+=cnt
        sm=sm-bc[0]*cnt+bc[1]*cnt
        print(sm)
    return

if __name__=='__main__':
    main()


Measured memory_bytes: 28360
#![doc = " # Bundled libraries"]
#[allow(unused_imports)]
use itertools::Itertools;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;
fn main() {
    input! { s : String , }
    if s.ends_with("s") {
        println!("{}es", s);
    } else {
        println!("{}s", s);
    }
}


Measured memory_bytes: 2116