akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
#define pb push_back
#define csl ios_base::sync_with_stdio(false); cin.tie(NULL)
typedef long long ll;
#define reps(i,a,b) for(ll i=ll(a);i<ll(b);i++)
#define rep(i,b) for(ll i=0;i<ll(b);i++)
typedef vector<long long> vll;
typedef vector<pair<int,int>> vii;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
int main()
{
    csl;
    int a,b;
    cin >> a >> b;
    map<int,int> m;
    m[a]++,m[b]++;
    int flag = -1;
    for(auto i:{1,2,3})
    {
            if(m[i])
                continue;
            else
                flag = i;
    }

    cout << flag << endl;

}


Measured memory_bytes: 3600
s = input()
t = input()

from collections import defaultdict
pos = defaultdict(list)
for i, char in enumerate(s):
    pos[char].append(i)

from bisect import bisect_left

ans = 0
before = -1
flag = True
for char in t:
    if pos[char] == []:
        flag = False
        break

    if before > pos[char][-1]:
        ans += len(s)
        before = pos[char][0] + 1
    else:
        idx = bisect_left(pos[char], before)
        before = pos[char][idx] + 1

if flag:
    print(ans + before)
else:
    print(-1)


Measured memory_bytes: 46320
#include <iostream>
#include <vector>
#include <limits>
#include <queue>

using namespace std;
typedef long long ll;

int main(){
    ll h, w;
    cin >> h >> w;

    vector<vector<ll>> c(10, vector<ll>(10));
    for(int i = 0; i < 10; ++i){
        for(int j = 0; j < 10; ++j){
            cin >> c.at(i).at(j);
        }
    }

    vector<ll> d(10, numeric_limits<ll>::max());
    d.at(1) = 0;
    priority_queue<pair<ll, ll>> q;
    q.push(make_pair(- d.at(1), 1));
    while(!q.empty()){
        auto p = q.top();
        q.pop();
        if(- p.first > d.at(p.second)){ continue; }
        for(int j = 0; j < 10; ++j){
            if(j == p.second){ continue; }
            if(d.at(j) > - p.first + c.at(j).at(p.second)){
                d.at(j) = - p.first + c.at(j).at(p.second);
                q.push(make_pair(- d.at(j), j));
            }
        }
    }

    ll ans = 0;
    for(int i = 0; i < h; ++i){
        for(int j = 0; j < w; ++j){
            ll a;
            cin >> a;
            if(a != -1){
                ans += d.at(a);
            }
        }
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
	int h, w;
	
	while (1) {
		cin >> h >> w;
		if (h == 0 && w == 0) break;

		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				cout << "#";
			}
			cout << endl;
		}
                cout << endl;
	}

	return 0;
}


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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int Mod =(1e9)+7;
using P = pair<ll,ll>;

 ll mod=998244353;

const int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];

ll RepeatSquaring(ll N, ll P, ll M){
    if(P==0) return 1;
    if(P%2==0){
        ll t = RepeatSquaring(N, P/2, M);
        return t*t % M;
    }
    return N * RepeatSquaring(N, P-1, M)%M;
}
// テーブルを作る前処理
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;
}

int main(){
    ll n,m,k;cin >>n>>m>>k;
    COMinit();
    ll ans=0;
    for (int i = 0; i <= k; ++i) {
            ll x=m*RepeatSquaring(m-1,n-i-1,mod)%mod;
           ans+=COM(n-1,i)*x;
           ans%=mod;
    }
    cout <<ans <<endl;
//    cout <<RepeatSquaring(2,16,10000000000)<<endl;
    return 0;
}

Measured memory_bytes: 15588
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;

struct state{
    int node;
    int cnt;
    ll nokori;
    bool operator<(const state& r)const{
        if(cnt!=r.cnt) return cnt>r.cnt;
        else return nokori<r.nokori;
    }
};

int main(){
    int N,M;
    ll L;
    cin >> N >> M >> L;
    ll inf = 1e18;
    vector<vector<ll>> dist(N,vector<ll>(N,inf)),edge(N,vector<ll>(N,inf));
    for(int i=0;i<M;i++){
        int a,b; ll c;
        cin >> a >> b >> c;
        a--,b--;
        if(c>L) continue;
        edge[a][b] = c;
        edge[b][a] = c;
    }
    vector<vector<ll>> ans(N,vector<ll>(N,inf));
    auto calc = [&](int s){
        vector<int> vis(N,-1);
        vis[s] = L;
        priority_queue<state> Q;
        Q.push({s,0,L});
        while(!Q.empty()){
            state now = Q.top(); Q.pop();
            if(ans[s][now.node]<now.cnt) continue;
            for(int x=0;x<N;x++) if(now.node!=x && edge[now.node][x]!=inf){
                state ne = now;
                ne.node = x;
                if(now.nokori-edge[now.node][x]<0){
                    ne.cnt++;
                    ne.nokori = L-edge[now.node][x];
                }else{
                    ne.nokori = now.nokori-edge[now.node][x];
                }
                if(ans[s][ne.node]>ne.cnt || (ans[s][ne.node]==ne.cnt && vis[ne.node]<ne.nokori)){
                    ans[s][ne.node] = ne.cnt;
                    vis[ne.node] = ne.nokori;
                    Q.push(ne);
                }
            }
        }
    };
    for(int i=0;i<N;i++) calc(i);
    int Q;
    cin >> Q;
    for(int i=0;i<Q;i++){
        int s,t;
        cin >> s >> t;
        s--,t--;
        cout << (ans[s][t]!=inf? ans[s][t]:-1) << endl;
    }
}

Measured memory_bytes: 2688
prev = false

while (line = gets)
  n = line.strip.to_i

  ds = []
  for i in (0..4)
    ds.unshift n % 10
    n /= 10
  end

  puts if prev
  prev = true

  puts ds.map{|d| d < 5 ? '*' : ' '}.join("")
  puts ds.map{|d| d > 4 ? '*' : ' '}.join("")
  puts ds.map{'='}.join("")
  puts ds.map{|d| d % 5 != 0 ? '*' : ' '}.join("")
  puts ds.map{|d| d % 5 != 1 ? '*' : ' '}.join("")
  puts ds.map{|d| d % 5 != 2 ? '*' : ' '}.join("")
  puts ds.map{|d| d % 5 != 3 ? '*' : ' '}.join("")
  puts ds.map{|d| d % 5 != 4 ? '*' : ' '}.join("")
end

Measured memory_bytes: 6116
// 見せてやるぜ、奇跡ってやつをよぉ……
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
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 DEBUG_VLL(vec) REP(sz, vec.size()) cerr<<vec[sz]<<(sz==vec.size()-1?'\n':' ');

const ll MOD = 1000000007;
const ll HIGHINF = (ll)1e18;
const int INF = 1e9;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, k; cin >> n >> k;
    V< V<int> > edges(n);
    for (int i = 0; i < n - 1; i++) {
        int a, b; cin >> a >> b;
        edges[a - 1].emplace_back(b - 1);
        edges[b - 1].emplace_back(a - 1);
    }

    if (!(k & 1)) {
        int ans = INF;
        for (int i = 0; i < n; i++) {
            V<int> d(n, INF);
            d[i] = 0;
            queue<int> que; que.push(i);
            while (!que.empty()) {
                int q = que.front(); que.pop();
                for (int e: edges[q]) {
                    if (d[e] > d[q] + 1) {
                        d[e] = d[q] + 1;
                        que.push(e);
                    }
                }
            }
            int tmp = 0;
            for (int i = 0; i < n; i++) if (d[i] > k / 2) tmp++;
            chmin(ans, tmp);
        }
        cout << ans << '\n';
    } else {
        int ans = INF;
        for (int i = 0; i < n; i++) {
            for (int v: edges[i]) {
                V<int> d(n, INF);
                d[i] = d[v] = 0;
                queue<int> que; que.push(i); que.push(v);
                while (!que.empty()) {
                    int q = que.front(); que.pop();
                    for (int e: edges[q]) {
                        if (d[e] > d[q] + 1) {
                            d[e] = d[q] + 1;
                            que.push(e);
                        }
                    }
                }

                int tmp = 0;
                for (int i = 0; i < n; i++) if (d[i] > (k - 1) / 2) tmp++;
                chmin(ans, tmp);
            }
        }
        cout << ans << '\n';
    }
    return 0;
}


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

#define LL long long
#define LD long double
#define SC(t,x) static_cast<t>(x)
#define AR(t) vector < t >
#define PII pair < int, int >
#define PLL pair < LL, LL >
#define PIL pair < int, LL >
#define PLI pair < LL, int >
#define MP make_pair
#define PB push_back
#define PF push_front
#define POB pop_back
#define POF pop_front
#define PRF first
#define PRS second
#define INIT(ar,val) memset ( ar, val, sizeof ( ar ) )
#define lp(loop,start,end) for ( int loop = start; loop < end; ++loop )
#define lpd(loop,start,end) for ( int loop = start; loop > end; --loop )
#define lpi(loop,start,end) for ( int loop = start; loop <= end; ++loop )
#define lpdi(loop,start,end) for ( int loop = start; loop >= end; --loop )
#define qmax(a,b) (((a)>(b))?(a):(b))
#define qmin(a,b) (((a)<(b))?(a):(b))
#define qabs(a) (((a)>=0)?(a):(-(a)))

const int INF = 0x3fffffff;
const int SINF = 0x7fffffff;
const long long LINF = 0x3fffffffffffffff;
const long long SLINF = 0x7fffffffffffffff;
const int MAXN = 100007;
const int MAXM = 400007;

struct eT
{
	int setd ( int _u, int _v, int _l )
	{
		u = _u, v = _v, last = _l;
	}
	
	int u, v, last;
}edge[MAXM];

int n, m;
int ke, la[MAXN];
int c[MAXN];
int c0, c1, c2;

void init ();
void input ();
void work ();

bool dfs ( int now, int nc );



int main()
{
	init();
	input();
	work();
}



void init ()
{
	// Init Everything Here
	
	ios::sync_with_stdio ( false );
}

void input ()
{
	// input method
	
	scanf ( "%d%d", &n, &m );
	int u, v;
	ke = 0;
	INIT ( la, -1 );
	lp ( i, 0, m ){
		scanf ( "%d%d", &u, &v );
		edge[ke].setd ( u, v, la[u] );
		la[u] = ke++;
		edge[ke].setd ( v, u, la[v] );
		la[v] = ke++;
	}
}

void work ()
{
	// main work
	
	INIT ( c, -1 );
	lpi ( i, 1, n ){
		if ( c[i] == -1 ){
			if ( la[i] == -1 ) ++c0;   // Single vertex
			else if ( dfs ( i, 0 ) ) ++c2;   // Bipartite
			else ++c1;   // Non-bipartite
		}
	}
	
	cout << SC ( LL, c1 + c2 ) * ( c1 + c2 ) + SC ( LL, c2 ) * c2 + SC ( LL, c0 ) * 2 * n - SC ( LL, c0 ) * c0 << endl;
}



bool dfs ( int now, int nc )
{
	if ( ~c[now] ) return c[now] == nc;
	c[now] = nc;
	
	bool flag = true;
	for ( int i = la[now]; ~i; i = edge[i].last ) flag &= dfs ( edge[i].v, nc ^ 1 );
	
	return flag;
}

Measured memory_bytes: 7552
import math
#短針の長さA,長針の長さB, H時M分
A, B, H, M = map(int, input().split())

#print(A**2)

#0時から短針の作る角度aA
aA = 30*H+M/2

#０時から長針の作る角度aB
aB = 6*M
kakudo = aA - aB
#print(kakudo)

if kakudo >= 180:
    kakudo = 360 - kakudo

#print(kakudo)
#print(math.cos(math.radians(kakudo)))
#print(aA)
#print(aB)
ans = 0
ans2 = 0  #余弦定理
ans2 = A**2 + B**2 - 2*A*B*math.cos(math.radians(kakudo))

ans = math.sqrt(ans2)

#print(ans2)
print(ans)

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

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

typedef long long ll;
using namespace std;
int mod[10] = {0,5,3,3,3,3,3,4,3,4};

char moji[10][5] = {{},
                    {'.', ',', '!', '?', ' '},
                    {'a', 'b', 'c'},
                    {'d', 'e', 'f'},
                    {'g', 'h', 'i'},
                    {'j', 'k', 'l'},
                    {'m', 'n', 'o'},
                    {'p', 'q', 'r', 's'},
                    {'t', 'u', 'v'},
                    {'w', 'x', 'y', 'z'}};

int main(void){
    int N; cin >> N;
    rep(i, N){
        string res = "";
        string S; cin >> S;
        int lenS = S.length();
        int idx = 0;
        while(idx < lenS){
            int row = 0;
            int num = S[idx] - '0';
            while(S[idx++] != '0'){
                row++;
            }
            if(num > 0){
                res += moji[num][(row-1) % mod[num]];
            }
        }
        cout << res << endl;
    }
    return 0;
}


Measured memory_bytes: 3176
H, W = list(map(int, input().split()))

if (H == 1 or W == 1):
    print(1)
else:
    if H % 2 == 0:
        print(H * W // 2)
    else:
        if W % 2 == 0:
            print(H * W // 2)
        else:
            print(H * (W + 1) // 2 - (H - 1) // 2)

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

int n, a[100005], ans;

int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++) {
		scanf("%d",&a[i]);
		ans += abs(a[i] - a[i-1]);
	}
	ans += abs(a[n]);
	for(int i=1;i<=n;i++) {
		printf("%d\n",ans-abs(a[i]-a[i-1])-abs(a[i+1]-a[i])+abs(a[i+1]-a[i-1]));
	}
}


Measured memory_bytes: 1664
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll m=1000000007;
int main()
{
	int n,cost=0;
	cin>>n;
	int arr[n][3];
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<3;j++)
		{
			cin>>arr[i][j];
		}
	}
	int dp[n][3],a,b,c;
	dp[0][0]=arr[0][0],dp[0][1]=arr[0][1],dp[0][2]=arr[0][2];
	for(int i=1;i<n;i++)
	{
		dp[i][0]=max(arr[i][0]+dp[i-1][1],arr[i][0]+dp[i-1][2]);
		dp[i][1]=max(arr[i][1]+dp[i-1][0],arr[i][1]+dp[i-1][2]);
		dp[i][2]=max(arr[i][2]+dp[i-1][1],arr[i][2]+dp[i-1][0]);
		
	}
	cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]));
}



Measured memory_bytes: 5916
def DFS(S):
    word_list = [ "dreamer","dream", "eraser", "erase"]
    stack = ["dream", "dreamer", "erase", "eraser"]
    while stack:
        word = stack.pop()
        if word == S[0]:
            return "YES"
        for i in word_list:
            next_word = word + i
            check = S[0][:len(word + i)]
            if next_word != check:
                continue
            if next_word == check:
                stack.append(next_word)
    return "NO"






if __name__ == "__main__":
    S = [input()]
    print(DFS(S))

Measured memory_bytes: 166456
def resolve():
	n = int(input())
	s = input()
	ans = 0
	for i in range(1, n-1):
		c = 0
		a, b = set(s[:i]), set(s[i:])
		for j in a:
			for k in b:
				if j == k:
					c += 1

		ans = max(ans, c)
	print(ans)
resolve()

Measured memory_bytes: 40348
#include <algorithm>
#include <cmath>
#include <complex>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#include <functional>
#include <cstring>
#include <regex>
#include <random>
#include <cassert>
#include <stack>
#include <climits>
using namespace std;

#pragma region

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, s, n) for (int i = (s); i < (int)(n); i++)
#define revrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define revrepr(i, s, n) for (int i = (n) - 1; i >= s; i--)
#define debug(x) cerr << #x << ": " << x << "\n"
#define popcnt(x) __builtin_popcount(x)

const double PI = acos(-1.0);

using ll = long long;
using P = pair<int, int>;

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

template<class T>
istream& operator >>(istream &is, vector<T> &v) {
    for (int i = 0; i < (int)v.size(); i++) cin >> v.at(i);
    return is;
}

template<class T, class U>
ostream& operator <<(ostream &os, pair<T, U> p) {
    cout << '(' << p.first << ", " << p.second << ')';
    return os;
}

template<class T>
void print(const vector<T> &v, const string &delimiter = " ") { rep(i, v.size()) cout << (0 < i ? delimiter : "") << v.at(i); cout << endl; }

template<class T>
void print(const vector<vector<T>> &vv, const string &delimiter) { for (const auto &v: vv) print(v, delimiter); }

#pragma endregion


int main() {
    int n;
    cin >> n;
    vector<ll> a(n);
    cin >> a;
    sort(a.rbegin(), a.rend());

    ll ans = 0;
    int cnt = 0;
    rep(i, n) {
        ans += a[i];
        cnt++;
        if (cnt == n - 1) break;

        if (i == 0) continue;

        ans += a[i];
        cnt++;
        if (cnt == n - 1) break;
    }

    cout << ans << endl;
}

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

using std::vector;
using std::sort;
using std::max;
using std::cin;
using std::cout;
using std::ios;
using std::endl;
const int N = 100010;
int _w;

int n, a[N], in[N], d[N];
int q[N], begin, end;
vector<int> v[N];

bool cmp( int i, int j ) {
	return d[i] < d[j];
}

int main() {
	ios::sync_with_stdio(false);
	cin >> n;
	for( int i = 2; i <= n; ++i ) {
		cin >> a[i];
		++in[a[i]];
		v[a[i]].push_back(i);
	}
	for( int i = 1; i <= n; ++i )
		if( !in[i] )
			q[end++] = i;
	while( begin != end ) {
		int u = q[begin++];
		sort(v[u].begin(), v[u].end(), cmp);
		for( int i = 0; i < (int)v[u].size(); ++i )
			d[u] = max( d[u], d[v[u][i]] ) + 1;
		--in[a[u]];
		if( in[a[u]] == 0 )
			q[end++] = a[u];
	}
	cout << d[1] << endl;
	return 0;
}


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

int main()
{
	int Test=1; while (Test--){
		int a, b, c, d; scanf("%d%d%d%d", &a, &b, &c, &d);
    puts(abs(a - c) <= d || (abs(a - b) <= d && abs(b - c) <= d) ? "Yes" : "No");
	}

	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <string>
#include <iostream>
#include <iomanip>
#include <map>
#include <algorithm>
#include <vector>
#include <math.h>
#define MOD (long long)1000000007
#define INF (long long)998244353
using namespace std;

int main(void){
    int n,k;
    cin >> n >> k;
    long double ans=0,prohibit;
    int j,count;
    for(int i=1; i<=n; i++){
        prohibit=1;
        j=i;
        count=1;
        while(j<k){
            j*=2;
            prohibit*=2;
        }
        ans+=(long double)1/(prohibit*n);
    }
    cout << setprecision(15) << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <climits>
#include <cstring>
#include <string>
#include <vector>
#include <cmath>
#include <map>

using namespace std;

#define ll long long
#define mod 1000000007
#define vi vector<int>
#define vll vector<ll>
#define pb(x) push_back(x)

ll power(int x, unsigned int y){
    ll res = 1;
    while(y > 0){
        if(y & 1) res = res * x;
        y >>= 1;
        x *= x;
    }
    return res;
}

void solve(){

    ll x; cin >> x;

    for(int i = -118; i < 120; i++){
        for(int j = -119; j < 119; j++){
            if(power(i, 5) - power(j, 5) == x){
                cout << i << ' ' << j;
                return;
            }
        }
    }

}
int main(){


    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    solve();

}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;

#if DEBUG && !ONLINE_JUDGE
    ifstream input_from_file("input.txt");
    #define cin input_from_file
#else

#endif

const int INF = 1e9;


int main() {
    ios::sync_with_stdio(false);
    cin.tie(0); // Togliere nei problemi con query online

    int N, M, X;
    cin >> N >> M >> X;
    vector<int> C(N);
    vector<vector<int>> A(N);
    for (int i = 0; i < N; i++) {
        cin >> C[i];
        A[i].resize(M);
        for (int j = 0; j < M; j++) cin >> A[i][j];
    }

    int res = INF;
    for (int k = 0; k < (1<<N); k++) {
        vector<int> lev(M, 0);
        int costo = 0;
        for (int i = 0; i < N; i++) {
            if (!(k&(1<<i))) continue;
            for (int j = 0; j < M; j++) lev[j] += A[i][j];
            costo += C[i];
        }
        bool fatto = true;
        for (int j = 0; j < M; j++) if (lev[j] < X) fatto = false;
        if (fatto) {
            res = min(res, costo);
        }
    }
    if (res == INF) cout << -1 << "\n";
    else cout << res << "\n";
}


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

int main(){
    int a,b,c,count=0;
    scanf("%d %d %d",&a,&b,&c);
    for(int i = a;i<b+1;i++){
        if(c%i==0){
            count++;
        }
    }
    printf("%d\n",count);
}


Measured memory_bytes: 3220
//#include <bits/stdc++.h>
//#include <stdio.h>
#include<iostream>
#include<cstdio>
#include<bitset>
#include<algorithm>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<string.h>
#include<cmath>
#include<utility>
#include<functional>
#include<map>
#include<set>
#include<cctype>
#include<fstream>


#define FOR(i, a, b) for( int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for( int i=(a);i>=(b);i--)
#define LFOR(i, a, b) for( long long int i=(a);i<=(b);i++)
#define LRFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000 //2000000000
#define LLINF 1000000000000000000 //9000000000000000000
#define PI 3.14159265358979
#define MAXI 7500000

using namespace std;
typedef long long int ll;
typedef pair< long long int, long long  int> P;

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




int main(void) {
	char b;

	cin >> b;

	switch (b) {
	case 'A':
		cout << "T" << endl;
		break;
	case  'T':
		cout << "A" << endl;
		break;
	case 'C':
		cout << "G" << endl;
		break;
	case 'G':
		cout << "C" << endl;
		break;
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <chrono>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repl(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define rep2l(i, s, n) for (ll i = (ll)(s); i < (ll)n; i++)

int main() {
    ld A;
    ld B;
    cin >> A >> B;
    ld res = A*B;
    res *= 100;
    cout << (ll)(res/100) << endl;
}

Measured memory_bytes: 3784
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
typedef long long ll;
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; }
const long long INF = 1LL << 60;
const int inf = 1001001001;
 
template <typename T>
struct UnionFind {
   vector<T> par; 
 
   UnionFind(T N) : par(N) { 
        for(T i = 0; i < N; i++) par[i] = i;
   }
 
   int root(T x) { 
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
   }
 
   void unite(T x, T y) { 
       T rx = root(x); 
       T ry = root(y); 
       if (rx == ry) return; 
       par[rx] = ry; 
   }
 
   bool same(T x, T y) { 
       T rx = root(x);
       T ry = root(y);
       return rx == ry;
   }
};


ll rec(ll N) {
    if (N == 1){
        return 1;
    }
    return rec(N/2) * 2 + 1;
}

int main() {
    ll N;
    cin >> N;
    cout << rec(N) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int x;
  cin>>x;
  if(400<=x&&x<600){
    cout<<'8';
  } else if(600<=x&&x<800){
    cout<<'7';
  } else if(800<=x&&x<1000){
    cout<<'6';
  } else if(1000<=x&&x<1200){
    cout<<'5';
  } else if(1200<=x&&x<1400){
    cout<<'4';
  } else if(1400<=x&&x<1600){
    cout<<'3';
  } else if(1600<=x&&x<1800){
    cout<<'2';
  } else {
     cout<<'1'<<endl;
  }
}

Measured memory_bytes: 3632
#include <algorithm>
#include <complex>
#include <cstdlib>
#include <ctime>
#include <time.h>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <numeric>
#include <limits>
#include <type_traits>


using namespace std;
#define SAY_YES cout << "YES" << endl;
#define SAY_Yes cout << "Yes" << endl;
#define SAY_NO cout << "NO" << endl;
#define SAY_No cout << "No" << endl;
#define IFYES(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "YES" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "NO" << endl;  \
    }
#define IFYes(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "Yes" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "No" << endl;  \
    }
#define IFyes(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "yes" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "no" << endl;  \
    }
#define DEBUG_OUTPUT_ARRAY(XXX, ONE)                            \
    for (int i = 0; i < (ONE); i++)                             \
    {                                                           \
        cout << "DEBUG: i = " << i << " -> " << XXX[i] << endl; \
    }
#define DEBUG_OUTPUT_ARRAY2(XXX, ONE, TWO)                             \
    for (int i = 0; i < (ONE); i++)                                    \
    {                                                                  \
        cout << "<<< i = " << i << " >>>" << endl;                     \
        for (int j = 0; j < (TWO); j++)                                \
        {                                                              \
            cout << "DEBUG: j = " << j << " -> " << XXX[i][j] << endl; \
        }                                                              \
    }
#define DEBUG_OUTPUT_ARRAY2_BOX(XXX, ONE, TWO) \
    for (int i = 0; i < (ONE); i++)            \
    {                                          \
        cout << i << "  ";                     \
        for (int j = 0; j < (TWO); j++)        \
        {                                      \
            cout << XXX[i][j] << " ";          \
        }                                      \
        cout << endl;                          \
    }

typedef pair<long long int, long long int> pll;


const long long int mod = 1000000007;
const long long int INF = 1e18;
const long double PI=3.14159265358979323; 


long long int N,M,K,sum=0,res=0,A,B,C,D;

int main()
{
    cout << fixed << setprecision(18);
    cin>>A>>B>>C>>D;
    IFYes((C+B-1)/B<=(A+D-1)/D);
}    


Measured memory_bytes: 3596
#include <stdio.h>
int a[110];
int main(){
    int n,i,j,cnt=0,t;
    scanf("%d",&n);
    for(i=1;i<=n;i++)
        scanf("%d",&a[i]);
    for(i=1;i<=n;i++)
        for(j=n;j>i;j--)
            if(a[j]<a[j-1])t=a[j],a[j]=a[j-1],a[j-1]=t,cnt++;
    for(i=1;i<=n;i++){
        if(i!=1)printf(" ");
        printf("%d",a[i]);
    }
    printf("\n%d\n",cnt);
    return 0;
}

Measured memory_bytes: 1852
from math import ceil
s=input()
x,y=map(int,input().split())
s2=s.split("T")
N=len(s2)
dp_x=[set() for i in range(ceil(N/2)+1)]
dp_x[0].add(0)
dp_y=[set() for i in range(N//2+1)]
dp_y[0].add(0)
for k in range(N):
  c=len(s2[k])
  if k==0:
    for a in dp_x[0]:
      dp_x[1].add(a+c)
  elif k%2==1:
    for b in dp_y[(k-1)//2]:
      dp_y[(k+1)//2].add(b+c)
      dp_y[(k+1)//2].add(b-c)
  elif k%2==0:
    for a in dp_x[k//2]:
      dp_x[(k+2)//2].add(a+c)
      dp_x[(k+2)//2].add(a-c)
      
      
if x in dp_x[-1] and y in dp_y[-1]:
  print("Yes")
else:
  print("No")
      

      
     

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


ll vm[200001][22][22];

int main()
{
	ll n;
	cin >> n;
	vector<string> s(n);
	for(ll i =0;i<n;i++)cin >> s[i];
	vector<pair<ll,ll>> vp(n);
	for(ll i =0 ;i<n;i++)
	{

		pair<ll,ll> p = pair<ll,ll>(0,0);//5,2
		for(ll j = 0;j<s[i].size();j++)
		{
			if(s[i][j]=='.')
			{
				ll x = s[i].size()-j-1;
				p.first -= x;
				p.second-=x;
			}
		}
		ll  x = 0;
		for(ll j = 0;j<s[i].size();j++)
		{
			if(s[i][j]=='.')continue;
			x *= 10;
			x += s[i][j] - '0';
		}
		while(x%5==0)
		{
			p.first++;
			x/=5;
		}
		while(x%2==0)
		{
			p.second++;
			x/=2;
		}
		
		if(p.first>9)p.first = 10;
		if(p.second>9)p.second=10;
		vp[i] = p;
		//cout<<p.first<<' ' << p.second<<endl;
		p.first += 10;
		p.second += 10;
		vm[i][p.first][p.second]++;
	}
	for(ll i = n-1;i>0;i--)
	{
		for(ll f = -10;f<12;f++)
		{
			for(ll t = -10;t<12;t++)
			{
				pair<ll,ll> now = pair<ll,ll> (f,t);
				now.first+=10;now.second+=10;
				vm[i-1][now.first][now.second] += vm[i][now.first][now.second];
			}
		}
	}
	ll ans = 0;
	for(ll i =0;i<n-1;i++)
	{
		auto now = vp[i];
		now.first *= -1;
		now.second *= -1;
		for(ll f = now.first;f<12;f++)
		{
			for(ll t = now.second;t<12;t++)
			{
				
				pair<ll,ll> tmp = make_pair(f,t);
				tmp.first+=10;tmp.second+=10;
				ans += vm[i+1][tmp.first][tmp.second];
			}
		}
	}
	cout << ans << endl;


}


Measured memory_bytes: 768676
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
using ll = long long;

int main(){
    int n, m; cin >> n >> m;
    vector<pair<int, int>> v(n);
    for (int i = 0; i < n; i++) {
        int a, b; cin >> a >> b;
        v[i] = make_pair(a, b);
    }
    sort(v.begin(), v.end());
    long long ans = 0, sum = 0, flag = 0;
    for (int i = 0; i < n; i++) {
        if (flag) break;
        while (v[i].second) {
            if (sum == m) {flag = 1; break;}
            ans += v[i].first;
            v[i].second--;
            sum++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

// c++11
#include <array>
#include <tuple>
#include <unordered_map>
#include <unordered_set>

#define mp make_pair
#define mt make_tuple
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;

using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

const int INF = 1 << 29;
const double EPS = 1e-9;
const ll MOD = 1000000007;

const int dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1};
const int MAX_N = 100010;
bool contain[MAX_N];
int N,M;
vector<int> edges[MAX_N];
deque<int> result;
bool check(){
  int head = result.front();
  int tail = result.back();
  for (auto &node : edges[head]){
    if (not contain[node]){
      contain[node] = true;
      result.push_front(node);
      return false;
    }
  }
  for (auto &node : edges[tail]){
    if (not contain[node]){
      contain[node] = true;
      result.push_back(node);
      return false;
    }
  }
  return true;
}
int main() {
  cin >> N >> M;
  for (int i = 0; i < M; i++){
    int a,b;
    cin >> a >> b;
    a--,b--;
    edges[a].push_back(b);
    edges[b].push_back(a);
  }
  result.push_back(0);
  contain[0] = true;
  result.push_back(edges[0][0]);
  contain[edges[0][0]] = true;
  while (not check());
  cout << result.size() << endl;
  while (not result.empty()){
    int res = result.front();
    result.pop_front();
    cout << res + 1 << " ";
  }
  cout << endl;
  return 0;
}


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

const int maxn = 1e5+10;
const int mod = 1e9+7;
int n,k;
int arr[maxn];

int32_t main()
{
    cin >> n >> k;
    for(int i = 1;i<=n;i++){
        cin >> arr[i];
    }
    int dp[maxn];
    dp[1] = 0;
    dp[2] = abs(arr[2] - arr[1]);
    for(int i = 3;i<=k;i++){
        dp[i] = abs(arr[i] - arr[1]);
        for(int j = 1;j<i;j++){
            dp[i] = min(dp[i],dp[j] + abs(arr[i] - arr[j]));
        }
    }
    for(int i = k+1;i<=n;i++){
        dp[i] = dp[i-k] + abs(arr[i-k] - arr[i]);
        for(int j = i - k;j<i;j++){
            dp[i] = min(dp[i],dp[j] + abs(arr[i] - arr[j]));
        }
    }
    cout << dp[n] << endl;
}


Measured memory_bytes: 4408
#include <bits/stdc++.h>
#define rep(i,N) for (int i = 0; i < (N); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main(void){
  string s;
  cin >> s;

  string week[7] = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};
  rep(i,7){
    if (s == week[i]){
      cout << 7 - i << endl;
    }
  }
}


Measured memory_bytes: 3492
n=""
while True:
	a=map(int,raw_input().split())
	b=a[0]+a[1]
	if a[0]==-1 & a[1]==-1 & a[2]==-1:
		break
	if b>=80:
		n="A"
	elif b>=65:
		n="B"
	elif b>=50:
		n="C"
	elif b>=30:
		n="D"
		if a[2]>=50:
			n="C"
	else:
		n="F"
	if a[0]==-1 or a[1]==-1:
		n="F"
	print(n)



Measured memory_bytes: 4648
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<utility>
#include<cstdio>
#include<set>
#include<string>
#include<map>
#include<queue>
#include<stack>
#include <bitset>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,x,n) for (int i= x;i<n;i++)
#define all(v) v.begin(), v.end()
using ll = long long;
using vi = vector<int>; 
using vvi = vector<vi>;
typedef pair<int,int> P;
string s;
int k;
ll INF = 10000000000000000;
int main(){
    int N;
    cin >>N;
    vi buka(N);
    rep(i,N-1){
        buka[i]=0;
    }
    int A;
    rep(i,N-1){
        cin >>A;
        buka[A-1]++;
    }
    rep(i,N){
        cout <<buka[i]<<endl;
    }
}

Measured memory_bytes: 3988
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    string s = to_string(n);
    if(s[0]==s[1]&&s[1]==s[2]) puts("Yes\n");
    else{
        if(s[3]==s[1]&&s[1]==s[2]) puts("Yes\n");
        else puts("No\n");
    }
    
    
}

    

Measured memory_bytes: 256
class PriorityQueue
    def initialize(arr)
        @size = arr.size
        @array = arr
        @array.unshift(nil)
        h = (@size / 2) | 0
        h.downto(1) do |i|
            maxHeapify(i)
        end
    end
    def getArray
        return @array[1..@size]
    end
    def maxHeapify(i)
        left = 2 * i
        right = 2 * i + 1
        largest = 0
        if left <= @size && @array[left] > @array[i]
            largest = left
        else
            largest = i
        end
        if right <= @size && @array[right] > @array[largest]
            largest = right
        end
        if largest != i
            @array[i], @array[largest] = @array[largest], @array[i]
            maxHeapify(largest)
        end
    end
    def pop
        return -(1<<29) if @size < 1
        maxv = @array[1]
        @array[1] = @array[@size]
        @size -= 1
        maxHeapify(1)
        maxv
    end
    def push(e)
        @size += 1
        i = @size
        @array[i] = -(1<<29)
        return if e < @array[i]
        @array[i] = e
        while i > 1 && @array[i/2] < @array[i]
            @array[i], @array[i/2] = @array[i/2], @array[i]
            i = i / 2
        end
    end
end

n, k = gets.chomp.split(" ").map(&:to_i)
h = gets.chomp.split(" ").map(&:to_i)

if n > k
    pq = PriorityQueue.new(h)
    k.times do |i|
        pq.pop
    end
    puts pq.getArray.inject(:+)
else
    puts 0
end

Measured memory_bytes: 19084
using System;
using System.Linq;//リストの使用
using System.Collections.Generic;
using System.Text;//テキストの高速出力に必要
class Program
{
	static void Main()
	{
		string[] input = Console.ReadLine().Split(' ');
		int n = int.Parse(input[0]);
		long k = long.Parse(input[1]);
		int[] nums = Array.ConvertAll(Console.ReadLine().Split(' '),int.Parse);
    int[] turns = new int[n];//それぞれの数のターン
    int a = 200001;
    List<int>[] positionList = new List<int>[a];
    for(int i = 0; i < a; i++) positionList[i] = new List<int>();
    int[] numsCount = new int[a];
    int[] numsNumber = new int[n];//それぞれの数は、何番目-1に出たものか

    for(int i = 0; i < n; i++)
    {
      positionList[nums[i]-1].Add(i);
      numsNumber[i] = numsCount[nums[i]-1];
      numsCount[nums[i]-1]++;
    }

    int lookingPosition = 0;
    int nowTurn = 1;
    while(true)
    {
      if(positionList[nums[lookingPosition]-1][positionList[nums[lookingPosition]-1].Count()-1]
        == lookingPosition)
      {
        nowTurn++;
        turns[lookingPosition] = nowTurn;
        lookingPosition = positionList[nums[lookingPosition]-1][0]+1;
        if(lookingPosition == n) break;
      }else
      {
        turns[lookingPosition] = nowTurn;
        lookingPosition 
          = positionList[nums[lookingPosition]-1][numsNumber[lookingPosition]+1]+1;
        if(lookingPosition == n) break;
      }
    }

    k %= nowTurn;

    int leftPosition = 0;
    for(int i = 0; i < n; i++)
    {
      if(turns[i] == k)
      {
        if(numsNumber[i] != numsCount[nums[i]-1]-1)
        {
          leftPosition = positionList[nums[i]-1][numsNumber[i]+1]+1;
        }else leftPosition = positionList[nums[i]-1][0]+1;
      }
    }

    var stack = new Stack<int>();
    bool[] used = new bool[a];
    for(int i = leftPosition; i < n; i++)
    {
      if(!used[nums[i]])
      {
        stack.Push(nums[i]);
        used[nums[i]] = true;
      }else
      {
        while(true)
        {
          int topMemo = stack.Peek();
          used[topMemo] = false;
          stack.Pop();
          if(topMemo == nums[i]) break;
        }
      }
    }

    int aa = stack.Count;
    int[] answers = new int[aa];
    for(int i = 0; i < aa; i++)
    {
      int popMemo = stack.Peek();
      answers[aa-1-i] = popMemo;
      stack.Pop();
    }

		if(nowTurn != 1) Console.WriteLine(string.Join(" ", answers));
	}
}

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

#define f(x, y, z) for (int x = (y), __ = (z); x < __; ++x)
#define _rep(i, a, b) for (int i = (a); i <= (b); ++i)
#define mst(x, a) memset(x, a, sizeof(x))

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
const int INF = 1 << 27;
const ll LLINF = (ll)1 << 60;
const ll MOD = 1e9 + 7;

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

int N;
vector<vector<int>> g;
const int MAXN = 1e5 + 10;
int black[MAXN];
int white[MAXN];

void dfs(int x, int parent) {
  ll b = 1, w = 1;
  for (int child : g[x]) {
    if (child != parent) {
      dfs(child, x);
      b = b * white[child] % MOD;
      w = w * (white[child] + black[child]) % MOD;
    }
  }
  black[x] = b;
  white[x] = w;
}

int main() {
  scanf("%d", &N);
  g = vector<vector<int>>(N);
  int x, y;
  while (~scanf("%d%d", &x, &y)) {
    g[x - 1].push_back(y - 1);
    g[y - 1].push_back(x - 1);
  }

  dfs(0, -1);
  printf("%lld\n", (black[0] + white[0]) % MOD);
}


Measured memory_bytes: 13440
#include<iostream>
#include<string>

using namespace std;

struct LectCor {
	int bl[2];
	int tr[2];
};

int main() {
	int N, W, H;
	cin >> W >> H >> N;

	LectCor lect;
	lect.bl[0] = 0;
	lect.bl[1] = 0;
	lect.tr[0] = W;
	lect.tr[1] = H;

	for (int i = 0; i < N; i++) {
		int x, y, a;
		cin >> x >> y >> a;
		switch (a)
		{
		case 1:
			if (x > lect.bl[0]) {
				lect.bl[0] = x;
			}
			break;
		case 2:
			if (x < lect.tr[0]) {
				lect.tr[0] = x;
			}
			break;
		case 3:
			if (y > lect.bl[1]) {
				lect.bl[1] = y;
			}
			break;
		case 4:
			if (y < lect.tr[1]) {
				lect.tr[1] = y;
			}
			break;
		default:
			break;
		}
	}
	if ((lect.tr[1] - lect.bl[1]) < 0 || (lect.tr[0] - lect.bl[0]) < 0) {
		cout << 0 << endl;
	}
	else {
		cout << (lect.tr[1] - lect.bl[1])*(lect.tr[0] - lect.bl[0]) << endl;
	}
}

Measured memory_bytes: 384
import java.util.Scanner;


public class Main {

	public static void main(String[] args)  {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		int MAX = 10000000;
		int[] cnt = new int[MAX+1];  
		
		Long ans = 0l;
		for(int i = 1 ; i <= n ; i++) {
			int value =  i;
			while(MAX >= value) {
				cnt[value]++;
				value += i;
			}
			
			Long tmp = (long) i;
			Long tmp2 = (long) cnt[i];
			ans += tmp * tmp2;
		}
		System.out.println(ans);
	}
}




Measured memory_bytes: 83012
from collections import Counter

N,A = map(int, input().split())
X = list(map(int, input().split()))
X = [x-A for x in X]

cnt = Counter([0, X[0]])

for x in X[1:]:
    temp = Counter([])
    for k,v in cnt.items():
        temp[k + x] += v
        
    cnt += temp
    
print(cnt[0]-1)
    


Measured memory_bytes: 3564
// ░░░░░░░░( •̪●)░░░░░░░░░░░░░░░░░░░░░░░░
// ░░░░░░███████ ]▄▄▄▄▄▄▄▄▃░░░▃░░░░ ▃░
// ▂▄▅█████████▅▄▃▂░░░░░░░░░░░░░░░░░
// [███████████████████].░░░░░░░░░░░░░░
// ◥⊙▲⊙▲⊙▲⊙▲⊙▲⊙▲⊙◤...░░░░░░░░░░░░

//PointBlank's code (⌐■_■)

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
 
#define repp(I, A, B) for(int I = A; I <= B; I++)
#define rep(I, A, B) for(int I = A; I < B; I++)
#define rrep(I, B, A) for(int I = B; I >= A; I--)
#define pb emplace_back
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define LB lower_bound
#define UB upper_bound
#define MP make_pair
#define mem(A, B) memset(A, B, sizeof(A));
#define mem0(A) memset(A, 0, sizeof(A));
#define quickio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define debug(this) cerr<<"> "<<#this<<" : "<<this<<"\n"
#define bitsf(n) __builtin_popcount(n)
#define in_edges(M) repp(I, 1, M){ll A, B; cin >> A >> B; v[A].pb(B), v[B].pb(A);}
#define in_edges2(M) repp(I, 1, M){ll A, B; cin >> A >> B; v[A].pb(B);}
#define endl "\n"
ll power(ll x, ll y); 

const ll MOD = 1000000007;

bool edge[10][10];

int chk(vector<int> &v){
	int st = 1;
	for(auto i : v) 
		if(edge[st][i]) st = i;
		else return 0;
	return 1;
}
 
int main() //PointBlank's code ¯\_(ツ)_/¯
{
	int n, m;
	cin >> n >> m;
	rep(i, 0, m){
		int a, b;
		cin >> a >> b;
		edge[a][b] = edge[b][a] = 1;
	}
	vector<int> path;
	repp(i, 2, n) path.pb(i);

	int res = 0;
	do{
		res += chk(path);
	}while(next_permutation(all(path)));

	cout << res;
}

ll power(ll x, ll y)
{ 
    ll res = 1; x %= MOD;
    while(y > 0){if(y & 1) res = (res*x) % MOD; y = y>>1, x = (x*x) % MOD;} 
    return res; 
}

Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
  let stdin = stdin();
  let stdin = stdin.lock();
  let token: String = stdin
    .bytes()
    .map(|c| c.expect("failed to read char") as char)
    .skip_while(|c| c.is_whitespace())
    .take_while(|c| !c.is_whitespace())
    .collect();
  token.parse().ok().expect("failed to parse token")
}

use std::cmp::{max, min};
use std::collections::BTreeMap;

fn main() {
  let n = read::<i64>();
  let mut dist: BTreeMap<char, i64> = BTreeMap::new();
  let mut s_vec = vec![];

  for _ in 0..n {
    let s = read::<String>();
    s_vec.push(s);
  }

  let first = &s_vec[0];
  for c in first.chars() {
    let current = dist.entry(c).or_insert(0);
    *current += 1;
  }

  for i in &s_vec {
    let mut map: BTreeMap<char, i64> = BTreeMap::new();

    for (k, v) in dist.iter() {
      map.insert(*k, 0);
    }

    for c in i.chars() {
      let current = map.entry(c).or_insert(0);
      *current += 1;
    }


    for (k, v) in map.iter() {
      if dist.contains_key(k) {
        let current = dist.entry(*k).or_insert(0);
        if v < current {
          *current = *v;
        }
      }
    }
  }

  let mut ans = String::from("");

  for (k, v) in dist.iter() {
    for _ in 0..*v {
      ans.push(*k);
    }
  }
  println!("{}", ans);

}



Measured memory_bytes: 4352
n = gets.to_i
b = gets.split.map(&:to_i)

ans = []
while b != []
    j = true
    (n-1).downto(0) do |i|
        if b[i] == i + 1
            ans.unshift(i + 1)
            b.delete_at(i)
            j = false
            break
        end
    end

    if j
        puts -1
        exit
    end
    n -= 1
end

puts ans

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

using namespace std;
typedef long long ll;

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=ll(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=ll(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) x.begin(),x.end() //sortなどの引数を省略したい
#define SIZE(x) ll(x.size()) //sizeをsize_tからllに直しておく
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB emplace_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
#define Umap unordered_map
#define Uset unordered_set

int main(){
    ll n;
    cin >> n;
    vector<ll> v(n), c(n);
    REP(i, n) cin >> v[i];
    REP(i, n) cin >> c[i];
    ll ans = 0;
    REP(i, n) ans += max(v[i]-c[i], ll(0));
    cout << ans;
    return 0;
}

Measured memory_bytes: 3568
import std.algorithm;
import std.array;
import std.container;
import std.conv;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void scan(T...)(ref T a) {
    string[] ss = readln.split;
    foreach (i, t; T) a[i] = ss[i].to!t;
}
T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

bool calc(int[] a) {
    int x = 0;
    for (int i = 0; i < a.length; i++) {
        if (i + 1 != a[i]) {
            x++;
        }
    }
    return x <= 2;
}

void main() {
    readint;
    auto a = readints;
    writeln(calc(a) ? "YES" : "NO");
}


Measured memory_bytes: 256
#include <iostream>
#include <cassert>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <bitset>
#include <vector>
#include <complex>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
string s , t;

int main(){
    cin >> s;
    t = s;
    reverse(all(t));
    if(s == t) cout << "Second" << endl;
    else if((sz(s) + (s[0] == t[0]) ) & 1) cout << "First" << endl;
    else cout << "Second" << endl;
    return 0;
}


Measured memory_bytes: 512
s = input()

say = "YES"
while len(s)>0:
    if s[-5:] == 'dream':
        s = s[:-5]
    elif s[-7:] == 'dreamer':
        s = s[:-7]
    elif s[-5:] == 'erase':
        s = s[:-5]
    elif s[-6:] == 'eraser':
        s = s[:-6]
    else:
        say = "NO"
        break
    
print(say)

Measured memory_bytes: 3188