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

using namespace std;

int main(){
    char now = 'A', a, b;
    while(~scanf(" %c,%c", &a, &b)){
	if(a == now)now = b;
	else if(b == now)now = a;
    }
    printf("%c\n", now);
    return 0;
}

Measured memory_bytes: 972
#include"bits/stdc++.h"
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

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

struct UnionFind {
    vector<int> d; // 根なら (-サイズ), そうでないなら親の番号
    UnionFind(int N) : d(N, -1){} // 全て根として初期化

    int root(int x) { // データ x が属する木の根を再帰で得る
        if (d[x] < 0) return x;
        return d[x] = root(d[x]);
    }

    bool unite(int x, int y) { // x と y の木を併合. 併合した場合 true
        x = root(x); y = root(y); // x <- x の根, y <- y の根
        if (x == y) return false; 
        // merge technique（データ構造をマージするテク. 小を大にくっつける）
        if (d[x] > d[y]) swap(x, y);    // x の木のサイズ > y の木のサイズにする. d[x], d[y] < 0 に注意.
        d[x] += d[y];   // x の木のサイズ += y の木のサイズ
        d[y] = x;   // y の親は x
        return true;
    }

    bool same(int x, int y) { // 2つのデータ x, y が属する木が同じなら true
        return root(x) == root(y);
    }
    
    int size(int x) { // 素集合のサイズ
        return -d[root(x)]; // d[root(x)] < 0 に注意.
    }
};

void Main(){
    const ll INF = 1e18;
    int n, k; cin >> n >> k;
    vi p(n), c(n);
    UnionFind UF(n);
    rep(i, n) {
        cin >> p[i]; p[i]--;
        UF.unite(i, p[i]);
    }
    rep(i, n) cin >> c[i];

    vector<vll> tot(n, vll(2 * n + 1, 0));
    rep(i, n){
        int now = i;
        rep(j, 2 * n){
            int next = p[now];
            tot[i][j+1] = tot[i][j] + c[next];
            now = next;
        }
    }
    /*
    rep(i, n){    
        cout << i << ": ";
        rep(j, n+1) cout << tot[i][j] << " ";
        cout << endl;
    }
    //*/
    ll ans = -INF;
    ll ansi;
    
    rep(i, n){
        ll sz = UF.size(i);
        ll cnt = k / sz;
        ll rem = k % sz;
        ansi = tot[i][1];
        ll mx = -INF;
        if(cnt > 0 && tot[i][sz] > 0) {
            ansi = tot[i][sz] * (cnt - 1);
            rep3(j, 0, rem + sz) mx = max(mx, tot[i][j]);
            ansi += mx;
        }else{
            rep3(j, 1, min(k, n)) mx = max(mx, tot[i][j]);
            ansi = mx;
        }
        // cout << i << ": " << cnt << " " << rem << " " << ansi << " " << mx << endl;
        ans = max(ans, ansi);
    }
    cout << ans << endl;
    return;
}

int main(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}

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

struct E{
  int cost,to;
  E(int _to,int _cost){
    cost = _cost;
    to = _to;
  }
};

const int MAX = 100;
vector<E>G[MAX];
int G2[MAX][MAX];
set<set<int> >S;
int res;
int N,M;

void func(set<int>&st){
  vector<int>vec(st.begin(),st.end());
  if(S.count(st))return;
  S.insert(st);
  int sum = 0;
  for(int i = 0 ; i < vec.size() ; i++){
    int cost = 1e8;
    for(int j = 0 ; j < vec.size() ; j++){
      if(i == j)continue;
      cost = min(cost,G2[vec[i]][vec[j]]);
    }
    if(cost == 1e8)cost = 0;
    sum += cost;
  }
  res = max(res,sum);
  for(int i = 0 ; i < vec.size() ; i++){
    for(int j = 0 ; j < G[vec[i]].size() ; j++){
      int to = G[vec[i]][j].to;
      if(st.count(to))continue;
      bool flag = true;
      for(int k = 0 ; k < vec.size() ; k++){
        if(G2[to][vec[k]] == 0){
          flag = false;
          break;
        }
      }
      if(flag){
        set<int>n_st = st;
        n_st.insert(to);
        func(n_st);
      }
    }
  }
}

int main(){
  cin >> N >> M;
  for(int i = 0 ; i < N ; i++){
    G[i].clear();
    for(int j = 0 ; j < N ; j++){
      G2[i][j] = 0;
    }
  }
  for(int i = 0 ; i < M ; i++){
    int a,b,c; cin >> a >> b >> c;
    a--; b--;
    G[a].push_back(E(b,c));
    G[b].push_back(E(a,c));
    G2[a][b] = G2[b][a] = c;
  }
  
  res = 0;
  for(int i = 0 ; i < N ; i++){
    set<int>st;
    st.insert(i);
    func(st);
  }
  cout << res << endl;

  return 0;
}

Measured memory_bytes: 8164
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for(int i=0; i<n; i++)
#define rep2(i, s, e) for(int i=s; i<e; i++)
#define print(i) cout << i << endl;

int main(){

    int d, g; cin >> d >> g;

    int p[d], c[d];
    rep(i, d){
        cin >> p[i] >> c[i];
    }

    int mincnt = 1e9;
    for(int bit = 0; bit < (1<<d); bit++){
        int score = 0;
        int cnt = 0;
        int remain[d] = {};
        for(int i=0; i<d; i++){
            if(bit & (1<<i)){
                score += c[i] + 100*(i+1)*p[i];
                cnt += p[i];
            }
            else{
                remain[i] = p[i] - 1;
            }
        }

        for(int i=d-1; i>=0; i--){
            if(score < g){
                int ntemp = (g - score)/(100*(i+1));
                if(ntemp < remain[i]){
                    score += 100*(i+1) * ntemp;
                    cnt += ntemp;
                }
                else{
                    score += 100*(i+1) * remain[i];
                    cnt += remain[i];
                }
            }
            if(score >= g){
                mincnt = min(mincnt, cnt);
            }
        }
    }

    cout << mincnt;

    return 0;
}

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

def main():
    N = int(input())
    A = [0] * N
    for i in range(N):
        A[i] = int(input())
    A.sort()

    tmp = N // 2
    if N % 2 == 1:
        L, M, R = A[:tmp], A[tmp], A[tmp+1:]
        # max(R[0]の隣にMを配置, L[-1]の隣にMを配置)
        print((sum(R) - sum(L)) * 2 + max(L[-1] - M, M - R[0]))
    else:
        L, R = A[:tmp], A[tmp:]
        """
        L[-1], R[0]は、第1項で
        それぞれ1回多く計算されているため、
        (L[-1] - R[0])としている
        """
        print((sum(R) - sum(L)) * 2 + (L[-1] - R[0]))

if __name__ == "__main__":
    main()

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

int main() {
    int num;
    cin >> num;
    auto max = -1000000;
    auto min = 1000000;
    long long total = 0;
    while(num--) {
    	int a;
		cin >> a;
		total += a;
		if (max < a) max = a;
		if (min > a) min = a;
    }
    cout << min << " " << max << " " << total << endl; 
}

Measured memory_bytes: 1164
n,m=map(int,input().split())
H=list(map(int,input().split()))
c=[0]*n
for i in range(m):
    a,b=map(int,input().split())
    if H[a-1]<H[b-1]:
        c[a-1]+=1
    elif H[b-1]<H[a-1]:
        c[b-1]+=1
    else:
        c[b-1]+=1
        c[a-1]+=1
x=0
for y in c:
    if y==0:
        x+=1

print(x)


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


int main(){
	string input;
	cin >> input;
	string memo;
	for(int i=input.size();i>=0;){
		//memo = input;
		if(i == 0)break;
		if(i-7>=0){
		memo = input.substr(i-7,7);
		if(memo == "dreamer"){
			i -= 7;
			continue;
		}
		}
		if(i-6>=0){
		memo = input.substr(i-6,6);
		if(memo == "eraser"){
			i -= 6;
			continue;
		}
		}
		if(i-5>=0){
		memo = input.substr(i-5,5);
		if(memo == "erase"){
			i -= 5;
			continue;
		}
		if(memo == "dream"){
			i -= 5;
			continue;
		}
		
		}
		cout << "NO" << endl;
		return 0;
		
	}
	
	cout << "YES" << endl;
	
	return 0;
}


Measured memory_bytes: 512
N = gets.chomp.to_i
colors = gets.chomp.chars.map { |c| c == "R" ? 1 : 0 }

w = 0
r = colors.size - 1
ans = 0
while w < r
  w += 1 while w < r && !colors[w].zero?
  r -= 1 while w < r && colors[r].zero?
  break if w == r
  colors[w] = 1
  colors[r] = 0
  ans += 1
end

puts ans


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

#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

#define MAXX 100005

#define PI 3.14159265358979323846264338327950

#define ll  long long int
vector<ll> v;
multiset<ll> ms;
multiset<ll>::iterator it;
ll a[MAXX], b[MAXX];
int main()
{
	FAST;
	ll n, t, m, o = 1, z, p, ans = 0;
	cin >> a[1] >> a[2] >> a[3] >> a[4] >> a[5];
	for(ll i = 1; i <= 5; i++){
		if(a[i] == 0){
			cout << i << endl;
			return 0;
		}
	}
	

}

Measured memory_bytes: 3540
#include "bits/stdc++.h"
using namespace std;
const int MAX = 700000;
const int MOD = 1000000007;

long long  fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
/*第二引数で第一引数を割ったときの切り上げの計算*/
long long int maxtime(long long int x, long long int y){
	return(x + y - 1) / y;

}
/*最大公約数*/
long long int lcm(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;

	if (number2 > number1) {
		m = number2;
		n = number1;
	}
	long long int s = -1;
	while (s != 0) {
		s = m % n;
		m = n;
		n = s;
	}
	return m;
}
/*最大公倍数*/
long long int gcd(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;
	return m / lcm(m, n) * n;
}
/*逆元計算*/
long long int  modinv(long long a, long long m) {
	long long int b = m, u = 1, v = 0;
	while (b) {
		long long int t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
// index が条件を満たすかどうか
vector<long long int >meguru;
bool isOK(int index, int key) {
	if (meguru[index] >= key) return true;
	else return false;
}
// 汎用的な二分探索のテンプレ
int binary_search(int key) {
	int left = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
	int right = (int)meguru.size(); // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()
	/* どんな二分探索でもここの書き方を変えずにできる！ */
	while (right - left > 1) {
		int mid = left + (right - left) / 2;

		if (isOK(mid, key)) right = mid;
		else left = mid;
	}
	/* left は条件を満たさない最大の値、right は条件を満たす最小の値になっている */
	return right;
}
long long modpow(long long a, long long n, long long mod) {
	long long res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}
int main() {
	int h, w;
	cin >> h >> w;
	char dp[101][101] = {};
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			char a;
			cin >> a;
			dp[i][j] = a;
		}
	}
	for (int i = 0; i < w+2; i++) {
		cout << "#";
	}
	cout << endl;
	for (int i = 0; i < h; i++) {
		cout << "#";
		for (int j = 0; j < w; j++) {
			cout <<dp[i][j];
		}
		cout << "#";
		cout << endl;
	}
	for (int i = 0; i < w+2; i++) {
		cout << "#";
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<string.h>
#include <algorithm>
#include<math.h>
#include<vector>
#include <queue>
#include <deque> 
#define ll long long
#define M 1000000007 
#define MM 998244353
using namespace std;
 
int main()
{
	int a, b, t;

	cin >> a >> b >> t;

	cout << b*(t/a);

    return 0;
}

Measured memory_bytes: 3640
n = int(input())
a = list(map(int, input().split()))
b = [a[i] - i - 1 for i in range(n)]
b = sorted(b)
if n % 2 == 1:
  c = b[(n-1)//2]
else:
  c = round((b[n//2-1] + b[n//2])//2)

print(sum(map(abs,[b[i]-c for i in range(n)])))

Measured memory_bytes: 33320
from collections import deque

mod = 10**9+7
n, k = map(int, input().split())
edges = [[] for i in range(n)]
if n == 1:
    print(k)
    exit()
for i in range(n-1):
    a, b = map(int, input().split())
    a-=1
    b-=1
    edges[a].append(b)
    edges[b].append(a)

start = None
for i in range(n):
    if len(edges[i]) == 1:
        start = i
        break

ans = 1
kumi = [0]*n
q = deque()
q.append((start,-1, 1, 0, 0))
while q:
    now, par, par_cnt,par2,child_cnt = q.popleft()
    a = par_cnt
    a *= k - par2 - child_cnt
    a %= mod
    cnt = 0
    for to in edges[now]:
        if to != par:
            if cnt == 0:
                q.append((to, now, a, min(par2+1, 2), 0))
            else:
                q.append((to, now, 1, min(par2+1, 2), cnt))
            cnt += 1
    if cnt == 0:
        ans *= a
        ans %= mod
print(ans)



Measured memory_bytes: 77856
/*
	@・ω・@ <だれだろうね
*/

/*****/

#include <iostream>
#include <array>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <iomanip>	//cout << fixed << setprecision(桁数);
#include <stdexcept>

//#define int long long

using namespace std;
using ll = long long;
using ld = long double;
using vecll = vector<long long>;
using pll = pair<long long, long long>;
template<class T> using pr = pair<T, T>;
template<class T> using vec = vector<T>;

#define debug(x) (std::cerr << (x) << "\n")
#define debug_tab(n, x) (std::cerr << strMulti("\t",n) << (x) << "\n")
#define debug_cout(x) (std::cerr << #x << " : " <<  (x) << "\n")
#define debug_tabcout(n, x) (std::cerr << strMulti("\t",n) << #x << " : " <<  (x) << "\n")
#define debug_headcout(h, x) (std::cerr << (h) << " : " <<  (x) << "\n")
#define debug_tabheadcout(n, h, x) (std::cerr << strMulti("\t",n) << (h) << " : " <<  (x) << "\n")

#define str(n)	(n.toString())

#define rep(i, n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define rep1(i, n) for(ll i=1, i##_len=(n); i<=i##_len; ++i)
#define rrep(i, n) for(ll i=(n)-1; i >= 0; --i)
#define rrep1(i, n) for(ll i=(n); i > 0; --i)
#define all(x) (x).begin(), (x).end()
#define pair(a, b) make_pair(a, b)
constexpr int INF = 2000000100;
constexpr ll MOD = 1000000007;	// 10e9+7
template<class T> bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> T divup(T a, T b) { if (a % b == 0) { return a / b; } return a / b + 1; }
std::string strMulti(std::string t, int n) { std::string out = ""; for (int i = 0; i < n; i++) { out += t; } return out; }
template<class T> T math_P(T m, T n) { T ret = 1; for (T i = m; i > m - n; i--) { ret *= i; } return ret; }
template<class T> T math_C(T m, T n) { T ret = math_P(m, n); for (T i = 2; i <= n; i++) { ret /= i; } return ret; }
template<class T> bool cmp_2nd(pair<T, T> a, pair<T, T> b) { if (a.second != b.second) { return a.second < b.second; } return a.first < b.first; }
template<class T> T mod_pow(T x, T n, const T& p) { T ret = 1; while (n > 0) { if (n & 1) { (ret *= x) %= p; } (x *= x) %= p; n >>= 1; } return ret; }

/*****/

ll N;
vecll A, B, C;

void Main()
{
	cin >> N;
	A.resize(N);
	B.resize(2 * 100000 + 10);
	C.resize(2 * 100000 + 10);
	rep(i, N)
	{
		cin >> A[i];
		B[A[i]]++;
	}

	ll sum = 0;
	rep(i, 2 * 100000 + 10)
	{
		if (B[i] != 0)
		{
			C[i] = math_C(B[i], 2ll);
			sum += C[i];
		}
	}

	//debug_cout(sum);

	//sort(all(A));

	rep(i, N)
	{
		//debug_cout(i);
		
		//debug_tabcout(1, C[A[i]]);
		//debug_tabcout(1, math_C(B[A[i]] - 1ll, 2ll));

		ll ret = sum - C[A[i]] + math_C(B[A[i]] - 1ll, 2ll);

		cout << ret << '\n';
	}
}

/*****/

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

	std::cout << std::fixed << std::setprecision(10);

	/*
	while (true)
	{
		Main();
		cout << endl;
	}
	//*/

	Main();
	cout << /** endl /*/ flush /**/;

	return 0;
}


Measured memory_bytes: 7296
#include <bits/stdc++.h>
using namespace std;
set<int> ss;
int main()
{
    int n,num;
    scanf("%d",&n);
    for(int i = 0; i < n; ++i)
    {
        scanf("%d",&num);
        if(ss.find(num) != ss.end())
            ss.erase(num);
        else
            ss.insert(num);
    }
    cout << ss.size() << endl;
    return 0;
}


Measured memory_bytes: 4864
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")
#include <bits/stdc++.h>

#define fast_in_out     ios_base::sync_with_stdio(false);cin.tie(0);
using namespace std;
int arr[11];
int main()
{
    fast_in_out
    int n,k,x;
    cin>>n>>k;
    for(int i=0;i<k;i++){
        cin>>x;
        arr[x]=1;
    }

    while(1){
        int cur=n;
        bool chosen=true;
        while(cur>0){
            int d=cur%10;
            cur/=10;
            if(arr[d]){
                chosen=false;
                break;
            }
    }
        if(chosen){
            cout<<n<<'\n';
            return 0;
        }
        n++;
    }
    return 0;
}


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

int main(){
    int N, M;
    cin >> N >> M;
    vector<int> A(M);
    vector<int> B(M);
    for(int i=0; i<M; i++){
        cin >> A.at(i) >> B.at(i);
    }

    int num[55] = {0};
    for (int i = 0; i < M; ++i) {
        num[A[i]]++;
        num[B[i]]++;
    }

    for (int i = 1; i <= N; i++) {
        cout << num[i] << endl;
    }
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a; cin >> a;
	int cnt[a + 50] = {0};
	for(int i=0; i < a - 1; i++)
	{
		int t; cin >> t;
		cnt[t] ++;
	}
	for(int i=1; i<=a; i++)
	{
		cout << cnt[i] << '\n';
	}
	return 0;
}

Measured memory_bytes: 4416
c1=[int(x) for x in input().split()]
c2=[int(x) for x in input().split()]
c3=[int(x) for x in input().split()]
b=[x for x in c1]
a=list(range(3))
a[0]=0
a[1]=c2[0]-b[0]
a[2]=c3[0]-b[0]
C1=[x+a[0] for x in b]
C2=[x+a[1] for x in b]
C3=[x+a[2] for x in b]
if (c1==C1)&(c2==C2)&(c3==C3):
	print("Yes")
else:
	print("No")


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

ll b[51][2];
ll a[51][2];

int main() { 
	int n, m;
	cin >> n >> m;
	for (int i = 0; i < n; ++i) {
		cin >> a[i][0] >> a[i][1];
	}
	for (int i = 0; i < m; ++i) {
		cin >> b[i][0] >> b[i][1];
	}
	for (int i = 0; i < n; ++i) {
		int index = 0;
		ll val = abs(a[i][0] - b[0][0]) + abs(a[i][1] - b[0][1]);
		for (int j = 0; j < m; ++j) {
			ll p = abs(a[i][0] - b[j][0]) + abs(a[i][1] - b[j][1]);
			if (p < val) {
				val = p;
				index = j;
			}
		}
		//cout << val << endl;
		cout << index + 1 << endl;
	}
	return 0; 
} 



Measured memory_bytes: 256
#include<bits/stdc++.h>
using  namespace std;
#define pb push_back
#define M 1000000007
typedef long long int ll;


void solve(){

	ll n, k, arr[200005], cnt, s, e, m;
	cin >> n >> k;
	for(ll i = 0; i < n; i++){
		cin >> arr[i];
		e = max(e, arr[i]);
	}
	s = 1;
	while(s < e){
		m = (s + e) / 2;
		cnt = 0;
		for(ll i = 0; i < n; i++){
			cnt += (arr[i] / m) + ll(((arr[i]%m) > 0)) - 1;
		}
		if(cnt <= k)
			e = m;
		else
			s = m + 1;
	}
	cout << e << endl;
}	

int main(){

	int t;
	// cin >> t;
	t = 1;
	for(int q = 0; q < t; q++){
		solve();
	}

	return 0;
}

Measured memory_bytes: 5148
#include <bits/stdc++.h>
#define F first
#define S second

using namespace std;
typedef long long int64;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int n;
	cin >> n;
	int64 sum = 0;
	for (int i = 1; i <= n; ++ i) {
		if (i % 3 != 0 && i % 5 != 0) {
			sum += i;
		}
	}
	cout << sum;
}

Measured memory_bytes: 3648
#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <memory.h>
#include <cassert>
 
using namespace std;

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

    int ac,wa,tle,re;
    ac=0, wa=0, tle=0, re=0;

    int n;
    cin>>n;
    while(n--) {
        string s;
        cin>>s;
        if(s=="AC") {
            ac++;
        }
        else if(s=="WA") {
            wa++;
        }
        else if(s=="TLE") {
            tle++;
        }
        else if(s=="RE") {
            re++;
        }
    }
    cout<<"AC "<<"x "<<ac<<endl;
    cout<<"WA "<<"x "<<wa<<endl;
    cout<<"TLE "<<"x "<<tle<<endl;
    cout<<"RE "<<"x "<<re<<endl;
}




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

int main(void){
    while(true){
        int n, p;
        cin >> n >> p;

        if(n == 0 && p == 0){ break; }

        int bucket = p;
        vector<int> stone(n, 0);
        for(int i = 0; ; i = (i + 1) % n){
            if(bucket ==0){
                bucket += stone[i];
                stone[i] = 0;
            }
            else{
                --bucket;
                ++stone[i];

                if(stone[i] == p){
                    cout << i << endl;
                    break;
                }
            }
        }
    }

    return 0;
}

Measured memory_bytes: 3000
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <cctype>
#include <cmath>
#include <map>
#include <set>
#define rep(i, m, n) for(int i = m;i < n;i++)
#define repr(i, n) for(int i = n;i >= 0;i--)
#define ll long long
#define ull unsigned long long
#define push(a) push_back(a)
#define pop(a) pop_back(a)
#define debug(x) cout<<#x<<": "<<x<<endl
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define INF 999999999
#define PI 3.14159265358979
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

int main(){
  int n,s[105]={},sum=0;
  cin>>n;
  rep(i,0,n){
    cin>>s[i];
    sum+=s[i];
    if(s[i]%10==0)s[i]=0;
  }
  if(sum%10!=0){
    cout<<sum<<endl;
    return 0;
  }
  sort(s,s+n);
  rep(i,0,n){
    sum-=s[i];
    if(sum%10!=0){
      cout<<sum<<endl;
      return 0;
    }
  }
  cout<<0<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
using namespace std;

int main(){
  int N;
  cin >> N;
  bool flag = false;
  rep(i, 9){
    rep(j, 9){
      if ((i+1) * (j+1) == N) flag = true;
    }
  }
  if (flag == true) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 3636
function Main(input) {
  input=input.split("\n");
　const STRING=input[0];
  var previous1,previous2;
  if(STRING[0]===STRING[1]){
    console.log(1,2);
    return;
  }
  previous1=STRING[0];
  previous2=STRING[1];
  for(var i=2;i<STRING.length;i++){
    if(STRING[i]==previous1){
      console.log(i-1,i+1);
      return;
    }else if(STRING[i]==previous2){
      console.log(i,i+1);
      return;
    }
    previous1=STRING[i-1];
    previous2=STRING[i];
  }
  console.log(-1,-1);
}

//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
  
  

Measured memory_bytes: 32584
#include <cstdio>
#include <algorithm>

using namespace std;

int main() {
    int n, count=0;
    scanf("%d", &n);
    getchar();
    for (int i=0; i<n; i++) {
        int c = getchar();
        if (c == 'R') count++;
        else count--;
    }
    printf("%s\n", (count>0) ? "Yes" : "No");
    return 0;
}

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

int main(){
    long N;
    cin >> N;
    long a,count,ans;
    count=1; ans=0;
    for(long i=0; i<N; i++){
        cin >> a;
        if(a!=count){
            ans++;
        }else{
            count++;
        }
    }
    if(ans>=N){
        ans=-1;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
    int n,m;
    long long dp[51][51][51],c[51][51],mo,f1[51][51],f2[51][51];
    int main()
    {
    	scanf("%d",&n);
    	dp[1][0][0]=1;
    	mo=1000000007;
    	c[0][0]=1;
    	for(int i=1;i<=n;i++)
    	{
    		c[i][0]=c[i][i]=1;
    		for(int j=1;j<=i-1;j++) c[i][j]=(c[i-1][j-1]+c[i-1][j])%mo;
    	}
    	for(int k=0;k<=n-1;k++)
    	for(int i=0;i<=n-k;i++)
    	for(int j=0;j<=n-i-k;j++) if(i+j>0)
    	{
    		if(i>j) dp[i][j][k]=(dp[i][j][k]+f1[i-j][k])%mo;
    		else dp[i][j][k]=(dp[i][j][k]+f2[j-i][k])%mo;
    		for(int i1=1;i1<=i;i1++)f1[i1][k+i+j]=(f1[i1][k+i+j]+((dp[i][j][k]*c[n-k][j+i1])%mo)*c[n-k-j-i1][i-i1])%mo;
    		for(int i1=0;i1<=j;i1++)f2[i1][k+i+j]=(f2[i1][k+i+j]+((dp[i][j][k]*c[n-k][i+i1])%mo)*c[n-k-i-i1][j-i1])%mo;
    	} 
    	printf("%d\n",f2[0][n]);
    } 

Measured memory_bytes: 896
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <map>
#include <numeric>
#include <random>
#include <queue>
#include <deque>
#include <tuple>
#include <iomanip>

using namespace std;
typedef long long ll;

const int INF = (1 << 30) - 1;
const ll INFLL= (1LL << 61) - 1;
const int MOD = 1000000007;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N,D;
  cin>>N>>D;
  cout<<(N+2*D)/(2*D+1)<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int n;
main()
{
  cin>>n;
vector<int>a(n);
  for(int i=0;i<n;i++)
  {
cin>>a[i];a[i]-=i;
  }
  sort(a.begin(),a.end());
  long ans=0;
  for(int i=0;i<n;i++)ans+=abs(a[i]-a[n/2]);
  cout<<ans<<endl;
}

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

typedef long long ll;

const int INF = 1e9;

int main() {
    int N;
    cin >> N;
    vector<int> h(N+5);
    for (int  i = 0; i < N; i++)
    {
        cin >> h[i];
    }
    vector<int> dp(N+5,INF);
    dp[0] = 0;
    for (int i=0;i<N;i++){
        dp[i+1] = min(dp[i+1], dp[i] + abs(h[i+1]-h[i]));
        dp[i+2] = min(dp[i+2], dp[i] + abs(h[i+2]-h[i]));
    }
    int ans = dp[N-1];

    cout << ans << "\n";
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){
    int x,n;
    cin >> x >> n;
    int p[n];
    vector<int>xx;
    xx.push_back(x);
    for(int i=1;i<=300;i++){
        xx.push_back(x-i);
        xx.push_back(x+i);
    }
    map<int,bool>m;
    for(int i=0;i<n;i++){
        cin >> p[i];
        m[p[i]] = true;
    }
    int tmp;
    for(int i=0;i<xx.size();i++){
        if(m[xx[i]] == false){
            tmp = xx[i];
            break;
        }
    }
    
    cout << tmp << endl;
}

Measured memory_bytes: 3616
import sys
input = sys.stdin.buffer.readline
S = input()
Q = int(input())
#S = "a"*100000
#Q = 200000
pre = ""
suf = ""

rev = 0
for i in range(Q):
    q = input().split()
    '''
    if i % 3 == 0:
        q = ('1')
    if i % 3 == 1:
        q = (2,'1','b')
    if i % 3 == 2:
        q = (2,'2','b')
        '''

    if len(q) == 1:
        rev = (rev + 1) % 2
    else:
        _, f, c = q
        f = f.decode()
        c = c.decode()
        if f == '1':
            if rev == 0:
                pre += c
            else:
                suf += c
        else:
            if rev == 0:
                suf += c
            else:
                pre += c

S = S.decode()[:-1]
ans = pre[::-1] + S + suf
if rev == 0:
    print(ans)
else:
    print(ans[::-1])


Measured memory_bytes: 4596
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

int dig[10];

bool valid(int cost)
{
	string S = to_string(cost);
	for(auto it: S)
	{
		if(dig[int(it-'0')]) return false;
	}
	return true;
}

int main(void)
{
	int n, k, x;
	scanf("%d%d", &n, &k);
	for(int i = 0;i < k;i++)
	{
		scanf("%d", &x);
		dig[x] = 1; 
	}

	for(int pay = n;;pay++)
	{
		if(valid(pay))
		{
			printf("%d\n", pay);
			return 0;
		}
	}
}

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

typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

const int  MOD=1000000007;
const int  INF= int(1e9);


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


    int n;
    cin>>n;
    int gcd = __gcd(2,n);
    int product = 2*n;
    int res = product/gcd;
    cout<<res<<"\n";



    return 0;
}


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

bool isPrime(int x){
  if(x == 0 || x == 1) return false;
  for(int i = 2; i * i <= x; i++){
    if(x % i == 0){
      return false;
    }
  }
  return true;
}

int main(){
  int n;
  while(cin >> n, n){
    int ans = 0;
    for(int i = n + 1; i <= 2 * n; i++){
      if(isPrime(i)){
        ans++;
      }
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 1160
#include<iostream>
#include<algorithm>
using namespace std;
struct elem
{
    int x,y;
};
elem v[100002];

inline bool cmp(const elem &a,const elem &b)
{
    if(a.x==b.x)
        return a.y<b.y;
    return a.x<b.x;
}

int main()
{
    int n,m,i,k=0,j,minim;
    cin>>n>>m;
    for(i=1;i<=m;i++)
    {
        cin>>v[i].x>>v[i].y;
    }
    sort(v+1,v+m+1,cmp);
    i=1;
    while(i<=m)
    {
        j=i;
        minim=v[j].y;
        i++;
        while(i<=m&&v[i].x<minim)
        {
            minim=min(minim,v[i].y);
            i++;
        }
        k++;
    }
    cout<<k;
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>
#include <limits.h>
using namespace std;
typedef long long ll;

int main(void){
    ll a, b;
    cin >> a >> b;
    
    ll ans = 0;
    for (int i = 0; i < 40; i++) {
        ll k;
        if (i == 0) {
            if (a % 2 == 0 && b % 2 == 0) k = (b - a) / 2;
            else k = (b - a) / 2 + 1;
        }
        else {
            if (b < pow(2, i)) break;
            
                if (a / ll(pow(2, i)) % 2 == 1) {
                    if (b / ll(pow(2, i)) % 2 == 1) {
                        if (a % ll(pow(2, i)) >= b % ll(pow(2, i)))
                        k = ll(pow(2, i)) - a % ll(pow(2, i)) + b % ll(pow(2, i)) + 1;
                        else
                        k = - a % ll(pow(2, i)) + b % ll(pow(2, i)) + 1;
                    }
                    else {
                        k = - a % ll(pow(2, i)) + ll(pow(2, i));
                    }
                }
                else {
                    if (b / ll(pow(2, i)) % 2 == 1) {
                        k = -ll(pow(2, i)) + b % ll(pow(2, i + 1)) + 1;
                    }
                    else {
                        k = 0;
                    }
                }
                
        }
                //cout << k << endl;
        //cout << a / ll(pow(2, i + 1)) << " " << a % ll(pow(2, i + 1))
        //<< " " << b / ll(pow(2, i + 1)) << " " << b % ll(pow(2, i + 1)) << endl;
        
        if (k % 2 == 1) ans += pow(2, i);
    }
    
    cout << ans << endl;
    
}

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

int main() {
  int a, b;
  cin >> a >> b;
  if ((a+b)%2 == 0){
    cout << (a+b)/2 << endl;
  }
  else {
    cout << (a+b)/2 + 1 << endl;
  }
}


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

typedef unsigned long long ull;

int main(){
    int n, m, l;
    ull S;
    cin >> n >> m >> l;
    int A[n][m];
    int B[m][l];
    for (int i=0;i<n;i++){
        for (int j=0;j<m;j++){
            cin >> A[i][j];
        }
    }
    for (int i=0;i<m;i++){
        for (int j=0;j<l;j++){
            cin >> B[i][j];
        }
    }

    for (int i=0;i<n;i++){
        for (int j=0;j<l;j++){
            S = 0ull;
            for (int k=0;k<m;k++){
                S += (A[i][k] * B[k][j]);
            }
            if(j == l-1){
                cout << S <<endl;
            }else{
                cout << S << " ";
            }
        }
    }
    return 0;
}

Measured memory_bytes: 3100
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<string>

using namespace std;
int main()
{
    string a;
    cin>>a;
    string b=a;
    reverse(a.begin(),a.end());
    for(int i=0;i<a.size();++i)
    {
        if(a[i]=='b') a[i]='d';
        else if(a[i]=='d') a[i]='b';
        else if(a[i]=='p') a[i]='q';
        else if(a[i]=='q') a[i]='p';
    }
    if(a==b) cout<<"Yes";
    else cout<<"No";
    return 0;
}

Measured memory_bytes: 512
#include <vector>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>
#include <tuple>
#include <set>
#include <map>
#include <complex>
#include <iomanip>
#include <cmath>
using namespace std;
typedef long long ll;

int main()
{
  char s;
  cin >> s;
  if (s == 'a' || s == 'i' || s == 'u' || s == 'e' || s == 'o') cout << "vowel" << endl;
  else cout << "consonant" << endl;
}

Measured memory_bytes: 256
import sys
from itertools import accumulate

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    W, H, N, *XYA = map(int, read().split())

    x_left = 0
    x_right = W
    y_left = 0
    y_right = H
    for x, y, a in zip(*[iter(XYA)] * 3):
        if a == 1 and x_left < x:
            x_left = x
        elif a == 2 and x_right > x:
            x_right = x
        elif a == 3 and y_left < y:
            y_left = y
        elif a == 4 and y_right > y:
            y_right = y

    print(max(x_right - x_left, 0) * max(y_right - y_left, 0))
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 9112
package main

import "fmt"

var mod = int64(1e9) + 7

func main() {
	var n, a, b int64
	fmt.Scanf("%d %d %d\n", &n, &a, &b)

	nways := power(2, n) - nChooseK(n, a) - nChooseK(n, b) - 1
	for nways < 0 {
		nways += mod
	}

	fmt.Printf("%d\n", nways%mod)
}

func nChooseK(n, k int64) int64 {
	ret := int64(1)
	f := int64(1)
	for i := int64(1); i <= k; i++ {
		ret = (ret * (n - i + 1)) % mod
		f = (f * i) % mod
	}
	return (ret * power(f, mod-2)) % mod
}

func power(a, b int64) int64 {
	ret := int64(1)
	for b > 0 {
		if b%2 != 0 {
			ret = (ret * a) % mod
		}
		b /= 2
		a = (a * a) % mod
	}
	return ret
}


Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <string>
#include <cctype>
#include <stack>
#include <queue>
#include <vector>
#include <cstdlib>
#include <list>
#include <cmath>
#include <map>
#include <utility>

#define _USE_MATH_DEFINES
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define INF 999999999
#define atcoder 1000000007
#define MAX_N 100

using namespace std;

int main() {

	char a, b;

	cin >> a >> b;

	if (a == b)
		cout << 'H' << endl;
	else
		cout << 'D' << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
char in[2];
int main() {
  int a, b, c; cin >> a >> b >> c;
  if (a+b+c>=22) cout << "bust" << endl;
  else cout << "win" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long lli;
#define mod 1000000007
#define mod2 998244353
#define fori(n) for (int i = 0; i < n; i++)
#define forj(n) for (int j = 0; j < n; j++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define fast ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define endl "\n"
#define sortvec(a) sort(a.begin(), a.end())

void print(){cout<<endl;}
template<typename T,typename... Args>
void print(T a, Args... args) {cout<<a<<" ";print(args...);}
lli llipowerp(lli x, lli y, lli p)
{
    lli res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1) res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}
lli binarySearch(vector<int> arr, int l, int r, int x)
{
    if (r >= l)
    {
        lli mid = l + (r - l) / 2;
        if (arr[mid] == x)
            return mid;
        if (arr[mid] > x)
            return binarySearch(arr, l, mid - 1, x);
        return binarySearch(arr, mid + 1, r, x);
    }
    return -1;
}
template <typename T>
inline void printvec(vector<T> inp){
    for(auto it:inp) cout<<it<<" ";
    cout << endl;
}
//---------------------------------------------------------------------------------

int main()
{
    int n;
    cin>>n;
    vector<int> a(n,0);
    fori(n-1) cin>>a[i+1];
    vector<int> counts(n+1,0);
    fori(n){
        counts[a[i]]++;
    }
    vector<int> suff(n+1,0);
    lli curr=0;
    for(int i=n;i>=0;i--){
        curr+=counts[i];
        suff[i]=curr;
    }
    for(int i=1;i<=n;i++) cout<<counts[i]<<endl;

}

Measured memory_bytes: 5632
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		
		Scanner cd = new Scanner(System.in);
		int a=cd.nextInt();
		int b=cd.nextInt();
		cd.close();
		if((a*b)%2==1) System.out.println("Odd");
		else System.out.println("Even");
	}

}


Measured memory_bytes: 20692
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define outmat(v) for(auto i : v){for(auto j : i) cout << j << " ";cout << endl;}
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define pb push_back
#define mod 1000000007
#define infi 1900000000
#define infl 1100000000000000000
#define cyes cout << "Yes" << endl
#define cno cout << "No" << endl
#define csp << " " <<
#define outset(n) cout << fixed << setprecision(n);
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
template<typename T> using ve = vector<T>;
template<typename T> using pq2 = priority_queue<T>;
template<typename T> using pq1 = priority_queue<T,vector<T>,greater<T>>;




int main()
{
    int N;
    cin >> N;
    ll K;
    cin >> K;
    vl A(N);
    in(N,A);
    
    vl S(N+1);
    S[0] = 0;
    rep(i,N) S[i+1] = S[i]+A[i];
    rep(i,N+1) S[i] -= i;
    rep(i,N+1) S[i] %= K;
    
    ll ans = 0;
    map<ll,ll> inK;
    K = min((ll)N+1,K);
    rep(i,K) inK[S[i]]++;
    
    rep(i,N){
        inK[S[i]]--;
        ans += inK[S[i]];
        
        if(i+K <= N) inK[S[i+K]]++;
    }
    out(ans);

    
    
    
    

    return 0;
}


Measured memory_bytes: 15872
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
char s[101010];
int main()
{
	int ans=0,l;
	scanf("%s",s);
	l=strlen(s);
	for(int i=1;i<l;i++)
		if(s[i]!=s[i-1])
			ans++;
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 384
N, C, K = map(int, input().split())
T = [int(input()) for _ in range(N)]
T.sort()

result = 0
wating = 0
first = None
for i in range(N):
    if wating == 0:
        first = i
        wating = 1
    elif T[first] + K < T[i]:
        result += 1
        first = i
        wating = 1
    else:
        wating += 1
    if wating == C:
        result += 1
        first = None
        wating = 0
if wating > 0:
    result += 1
print(result)

Measured memory_bytes: 7512
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define RFOR(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define rep(i,n) FOR(i,0,(n))
#define REPS(i,n) FOR(i,1,(n)+1)
#define RREP(i,n) RFOR(i,0,(n))
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define debug(x) cout << #x << " = " << (x) << endl;
#define SORT(x) sort(rng(x))
#define RSORT(x) sort(rrng(x))
#define SUM(x) accumulate(rng(x),0)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = 1<<30;
const ll INFLL = 1LL<<60;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//cout << fixed << setprecision(10);

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

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

ll dp[10010];

int main () {
  int n, m;
  cin >> n >> m;
  vll a(m);
  rep(i,m) cin >> a[i];
  vi f = {-1,2,5,5,4,5,6,3,7,6};

  rep(i,10010) dp[i] = -INFLL;
  dp[0] = 0;
  rep(i,10001) {
    for (ll A : a) {
      if (i-f[A] < 0) continue;
      chmax(dp[i], dp[i-f[A]]+1);
    }
  }

  string ans = "";
  int remain = dp[n];
  int match = n;
  SORT(a);
  while (match > 0) {
    for (int i = m-1; i >= 0; --i) {
      if (match-f[a[i]] >= 0 && dp[match-f[a[i]]] == remain-1) {
        ans += (char)('0'+a[i]);
        match -= f[a[i]];
        remain--;
        break;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

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


int main() {
	int s;
	int i;
	int j;
  	int k;
	int n;
	int a[3010];
	int np[3010][3010];

	cin >> n >> s;
	for (i = 0; i < n; i++) {
		cin >> a[i];
	}
	for (i = 0; i < n; i++) {
		for (j = 0; j < s+1; j++) {
			np[i][j]=0;
		}
	}
	np[0][0]=2;
	np[0][a[0]]=1;
  	for (i = 1; i < n; i++) {
		for (j = 0; j <= s; j++) {
			np[i][j]=2*np[i-1][j];
			np[i][j]=np[i][j] % 998244353;
		}
		for (j = 0; j <= s-a[i]; j++) {
			k=j+a[i];
			np[i][k]=np[i][k]+np[i-1][j];
			np[i][k]=np[i][k] % 998244353;
		}
    }
	cout << np[n-1][s];
	return 0;
}

Measured memory_bytes: 38912
#include<iostream>
using namespace std;
const int BUF = 2000005;
const int MOD = 1000000007;


int add(int a, int b) {
    return (a + b) % MOD;
}

int sub(int a, int b) {
    return (a - b + MOD) % MOD;
}

int mul(int a, int b) {
    return 1LL * a * b % MOD;
}


int nNum;
int a[BUF], b[BUF];

void read() {
    cin >> nNum;
    for (int i = 0; i < nNum; ++i) cin >> a[i];
    for (int i = 0; i < nNum; ++i) cin >> b[i];
}


void work() {
    static int s[BUF];
    static int t[BUF];
    for (int i = 0; i < nNum; ++i) {
        s[i] = a[i] ^ a[(i + 1) % nNum];
        t[i] = b[i] ^ b[(i + 1) % nNum];
    }

    const int P = 1<<30;

    int sHash = 0;
    int tHash = 0;
    for (int i = 0; i < nNum; ++i) {
        sHash = add(mul(sHash, P), s[i]);
        tHash = add(mul(tHash, P), t[i]);
    }
    
    int pPowNNum = 1;
    for (int i = 0; i < nNum - 1; ++i) {
        pPowNNum = mul(pPowNNum, P);
    }
    
    for (int shift = 0; shift < nNum; ++shift) {
        if (sHash == tHash) {
            cout << shift << ' ' << (a[shift] ^ b[0]) << endl;
        }
        sHash = sub(sHash, mul(s[shift], pPowNNum));
        sHash = mul(sHash, P);
        sHash = add(sHash, s[shift]);
    }
}


int main() {
    read();
    work();
    return 0;
}


Measured memory_bytes: 14464
/*
*	User: Isanchez_Aguilar
*	Problem: CodeForces 
*/
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>
#include <map>
#include <set>

using namespace std;
using Long = long long;

int main(void)
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	int n;
	cin >> n;

	int maxFreq = 0;
	map<string, int> freq;

	for (int i = 0; i < n; ++i)
	{
		string s;
		cin >> s;

		++freq[s];

		if (freq[s] > maxFreq)
			maxFreq = freq[s];
	}


	for (auto p : freq)
	{
		if (p.second == maxFreq)
			cout << p.first << "\n";
	}

	return 0;
}


Measured memory_bytes: 23808
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
  int n,m,l,s,t,e,cnt=0,a[100000][3],b[100000];
  cin>>n>>m;
  while(1){
    scanf("%d %d %d",&s,&t,&e);
    if(s+t+e==0)break;
    a[cnt][0]=s;
    a[cnt][1]=t;
    a[cnt][2]=e;
    cnt++;
  }
  cin>>l;
  for(int i=0;i<l;i++){
    int c[100000]={};
    for(int j=1;j<=m;j++){
      scanf("%d",&b[j]);
    }
    for(int j=0;j<cnt;j++){
      c[a[j][0]]+=a[j][2]*b[a[j][1]];
    }
    for(int j=1;j<=n;j++){
      printf("%d",c[j]);
      if(j!=n)printf(" ");
    }
    printf("\n");
  }
  return 0;
}

Measured memory_bytes: 4232
import sys

n = int( sys.stdin.readline() )
output = []
for i in range( 1, n+1 ):
	x = i
	if x%3 == 0:
		output.append( " {:d}".format( i ) )
	else:
		while x != 0:
			if x%10 == 3:
				output.append( " {:d}".format( i ) )
				break
			x = x//10
print( "".join( output ) )

Measured memory_bytes: 4712
import java.util.*;

// DFS(深さ優先探索)の練習。
public class Main {

	// すべてのルンルン数を入れるリスト
	public static ArrayList<Long> lunlun;

	public static void main(String[] args) {

		// 入力
		Scanner sc = new Scanner(System.in);
		int k = Integer.parseInt(sc.next());

		lunlun = new ArrayList<Long>();
		saiki(1);
		saiki(2);
		saiki(3);
		saiki(4);
		saiki(5);
		saiki(6);
		saiki(7);
		saiki(8);
		saiki(9);

		// できあがったリストの中身ソート
		Collections.sort(lunlun);

		// リストの中身を全列挙
		for (long p : lunlun) {
			//System.out.println(p);
		}

		// k番目に小さいルンルン数を求めよ
		System.out.println(lunlun.get(k - 1));
	}

	// 引数で与えられたルンルン数をリストに入れて、次の探索へ進む関数
	public static void saiki(long value) {

		// リストに格納
		lunlun.add(value);

		// 問題の制約上、ルンルン数の桁数は11桁未満なので、11桁になりそうな場合は打ち切り
		if (1000000000 <= value) {
			return;
		}

		// 次へ
		if (value % 10 == 0) {
			saiki(value * 10);
			saiki(value * 10 + 1);
		} else if (value % 10 == 9) {
			saiki(value * 10 + 8);
			saiki(value * 10 + 9);
		} else {
			saiki(value * 10 + value % 10 - 1);
			saiki(value * 10 + value % 10);
			saiki(value * 10 + value % 10 + 1);
		}
	}

}

Measured memory_bytes: 47672
#include <iostream>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <string>
#include <cctype>
#include <map>
#include <queue>

using namespace std;

const int mod = 1000000007;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))
#define ll long long

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

    vector<int> vec;
    for (int i = 0; i < n; i++)
    {
        int num;
        cin >> num;
        vec.push_back(num);
    }

    sort(vec.begin(), vec.end(), greater<int>());
    
    int ans = 0;
    for (int i = 0; i < k; i++)
    {
        ans+= vec[i];
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 256