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

public class Main{
	public static void main(String[] args)  throws IOException,NumberFormatException{
		try {
		FastScanner sc=new FastScanner();
		int n=sc.nextInt(),m=sc.nextInt();
		int a[][]=new int[m][2];
		for(int i=0;i<m;i++) {
			a[i][0]=sc.nextInt();
			a[i][1]=sc.nextInt();
		}
		int road[]=new int[50];
		for(int i=0;i<m;i++) {
			road[a[i][0]-1]++;
			road[a[i][1]-1]++;
		}
		for(int i=0;i<n;i++) {
			System.out.println(road[i]);
		}
		}
		catch(Exception e) {
			return ;
		}
		
	}
	static final Random random=new Random();
	
	static void ruffleSort(int[] a) {
		int n=a.length;
		for(int i=0;i<n;i++) {
			int oi=random.nextInt(n),temp=a[oi];
			a[oi]=a[i]; a[i]=temp;
		}
		Arrays.sort(a);
	}
	
	public static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens())
				try { 
                                      st=new StringTokenizer(br.readLine());				               
                              } catch (IOException e) {}
			return st.nextToken();
		}
		
		int nextInt() {
			return Integer.parseInt(next());
		}
		
		long nextLong() {
			return Long.parseLong(next());
		}
		
		int[] readArray(int n) {
			int[] a=new int[n];
			for (int i=0; i<n; i++) a[i]=nextInt();
			return a;
		}
		
		long[] readLongArray(int n) {
			long[] a=new long[n];
			for(int i=0; i<n ; i++) a[i]=nextLong();
			return a;
		}
		
		String nextLine() 
        { 
            String str = ""; 
            try
            { 
                str = br.readLine(); 
            } 
            catch (IOException e) 
            { 
                e.printStackTrace(); 
            } 
            return str; 
        } 
	}

}


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

int main(){
    ll h,n;
    cin>>h>>n;
    vector<pair<ll,ll>> v(n);
    rep(i,n){
        ll a,b;
        cin>>a>>b;
        v[i]=make_pair(a, b);
    }
    V dp(h+1,1e9);
    dp[0]=0;
    rep(i,h+1){
        rep(j,n){
            dp[min(h,i+v[j].first)]=min(dp[min(h,i+v[j].first)],dp[i]+v[j].second);
        }
    }
    cout<<dp[h]<<endl;
}


Measured memory_bytes: 384
using System;
using System.Linq;
class ProgramD {
    static void Main() {
        var line = Console.ReadLine().Split().Select(int.Parse).ToArray();
        int N = line[0], A = line[1], B = line[2];
        var list = Enumerable.Repeat(0, N).Select(_ => int.Parse(Console.ReadLine())).ToList();
        long left = 0, right = 1000000000;

        while (right - left > 1) {
            long mid = (left + right) / 2, damage = mid * B;

            if (mid >= list.Sum(x => x <= damage ? 0 : (x - damage - 1) / (A - B) + 1)) right = mid;
            else left = mid;
        }
        Console.WriteLine(right);
    }
}

Measured memory_bytes: 18272
#include<iostream>
#include<cstdio>
#include<vector>
#include<cstring>
using namespace std;
int n;
int res;
vector<int>v;
int lst=-1;
int match[210];
int me,mo;
int mx;
bool f[10000010];
vector<int>ok[210];
bool vis[210];
int prm[1000010];
int sz;
int l;
bool bp(int x)
{
	for(int i=0;i<ok[x].size();i++)
	{
		int y=ok[x][i];
		if(vis[y])continue;
		vis[y]=vis[x]=true;
		if(match[y]==-1 || bp(match[y]))
		{
			match[y]=x;
			return true;
		}
	}
	return false;
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		int x;
		scanf("%d",&x);
		if(x!=lst+1)
		{
			if(lst+1)v.push_back(lst+1);
			v.push_back(x);
		}
		lst=x;
		mx=lst+1;
	}
	v.push_back(lst+1);
	f[1]=true;
	for(int i=2;i<=mx;i++)
	{
		if(!f[i])prm[++sz]=i;
		for(int j=1;j<=sz;j++)
		{
			if(prm[j]*i>mx)break;
			f[prm[j]*i]=true;
			if(i%prm[j]==0)break;
		}
	}
	l=v.size();
	for(int i=0;i<l;i++)
	{
		match[i]=-1;
		if(v[i]&1)mo++;else me++;
		for(int j=i+1;j<l;j++)
		{
			if(v[j]-v[i]!=2 && !f[v[j]-v[i]])
			{
				ok[i].push_back(j);
				ok[j].push_back(i);
			}
		}
	}
	for(int i=0;i<l;i++)
	{
		memset(vis,false,sizeof(vis));
		if(bp(i))res++;
	}
	res/=2;
	printf("%d",res+((me-res)/2+(mo-res)/2)*2+((me-res)%2)*3);
	return 0;
} 

Measured memory_bytes: 13952
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\n"
#define pb push_back
#define fi first`
#define se second
void solve()
{
	ll n,k;
	cin>>n>>k;
	std::vector<ll> v(n),ans(n);
	for(auto &i:v)
		cin>>i;
	for(auto &i:ans)
		i=1e9;

	ans[0]=0;		

	for(int i=1;i<n;i++)
		for(int j=1;(i>=j and j<=k);j++)
			ans[i]=min(ans[i],ans[i-j]+abs(v[i]-v[i-j]));

	cout<<ans[n-1];

}

int main()
{



  ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t = 1;
    // cin >> t;
    while(t--)
    {
        solve();
        // cout << endl;
    }

}




Measured memory_bytes: 1792
// D - Flat Subsequence
#include <bits/stdc++.h>
using namespace std;

#include <atcoder/segtree>
int op(int a, int b){ return max(a,b); } // 処理
int e(){ return 0; } // 単位元
using MONOID = int;
using SEG_T = atcoder::segtree<MONOID, op, e>;
#define SEGT_MAX 300005

int main(){
	int n, k; cin>>n>>k;
	vector<int> A(n); for(auto& a:A) cin>>a;
	SEG_T seg(SEGT_MAX);
	int ans = 0;
	for(int& a:A){
		int l = max(0, a - k);
		int r = min(a + k + 1, SEGT_MAX);
		int longest = seg.prod(l, r); // [l,r)
		seg.set(a, longest + 1);
		ans = max(ans, longest + 1);
	}
	cout<< ans <<endl;
}


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

int main()
{
	int m = 0, f = 0, r = 0, count = 0;
	string grade[100];
	while (1){
		cin >> m >> f >> r;
		if (m == -1 && f == -1 && r == -1) break;
		if (m == -1 || f == -1)                             grade[count++] = "F";
		else if (m + f >= 80)                               grade[count++] = "A";
		else if (m + f >= 65)                               grade[count++] = "B";
		else if ((m + f >= 50) || (m + f >= 30 && r >= 50)) grade[count++] = "C";
		else if (m + f >= 30)                               grade[count++] = "D";
		else                                                grade[count++] = "F";
	}
	for (int i = 0; i < count; i++) cout << grade[i] << endl;
	return 0;
}

Measured memory_bytes: 1188
N, K, C = map(int, input().split())
S = input()

L = [0] * K
k = 0
i = 0
rest = C
while k < K:
    if rest >= C and S[i] == 'o':
        L[k] = i
        k += 1
        rest = 0
    else:
        rest += 1
    i += 1

R = [0] * K
k = K
i = N - 1
rest = C
while k > 0:
    if rest >= C and S[i] == 'o':
        R[k - 1] = i
        k -= 1
        rest = 0
    else:
        rest += 1
    i -= 1

ans = []
for k in range(K):
    if L[k] == R[k]:
        ans.append(L[k] + 1)
print(*ans, sep='\n')


Measured memory_bytes: 31748
import itertools

n, m = map(int, input().split())
road = [[0] * n for i in range(n)]

graph = [[] for i in range(n)]
for j in range(m):
    x, y = map(int, input().split())
    road[x - 1][y - 1] += 1
    road[y - 1][x - 1] += 1
    graph[x - 1].append(y - 1)
    graph[y - 1].append(x - 1)
# print(road)
# print(graph)

count = 0

for can in itertools.permutations(range(n)):
    if can[0] != 0:
        break
    # print(can)
    plus = 1
    for k in range(n - 1):
        # print(road[can[k]][can[k + 1]])
        plus *= road[can[k]][can[k + 1]]
    count += plus


def dfs(node, prev, visited):
    visited.append(node)
    if len(visited) == n:
        return 1

    res = 0
    for edge in graph[node]:
        if edge == prev:
            continue
        if edge in visited:
            continue
        res += dfs(edge, prev, visited[:])

    return res


dfs = dfs(0, -1, [])

if count == dfs:
    print(dfs)


Measured memory_bytes: 3064
#include<iostream>
#include<cstdio>
#include<vector>
#include<cstring>
#include<queue>
#include<map>
#include<set>
#include<algorithm>
#include<stack>
#include<cmath>
#include<iomanip>
#include<cstdlib>
#include<sstream>
#include<climits>
#include<cassert>
#include<time.h>

using namespace std;
#define f(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define pb push_back
#define ss second
#define ff first
#define vi vector<int>
#define vl vector<ll>
#define s(n) scanf("%d",&n)
#define ll long long
#define mp make_pair
#define PII pair <int ,int >
#define PLL pair<ll,ll>
#define inf 1000*1000*1000+5
#define v(a,size,value) vi a(size,value)
#define sz(a) a.size()
#define all(a) a.begin(),a.end()
#define tri pair < int , PII >
#define TRI(a,b,c) mp(a,mp(b,c))
#define xx ff
#define yy ss.ff
#define zz ss.ss
#define in(n) n = inp()
#define vii vector < PII >
#define vll vector< PLL >
#define viii vector < tri >
#define vs vector<string>
#define DREP(a) sort(all(a)); a.erase(unique(all(a)),a.end());
#define INDEX(arr,ind) (lower_bound(all(arr),ind)-arr.begin())
#define ok if(debug)
#define trace1(x) ok cerr << #x << ": " << x << endl;
#define trace2(x, y) ok cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)    ok      cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)  ok cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " \
                                << #d << ": " << d << endl;
#define trace5(a, b, c, d, e) ok cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " \
                                     << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) ok cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " \
                                    << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;

#define read(a) freopen(a,"r",stdin)
#define write(a) freopen(a,"w",stdout)
ll MOD = int(1e9) + 7;

int debug = 1;
const int N = int(1e6) + 5;
using namespace std;
int main()
{
        int i,j,t;
        ll n;
        ios::sync_with_stdio(false);
        cin>>n;
        vll a(n);
        rep(i,n)
        {
                cin>>a[i].ff;a[i].ss = i+1;
        }
        ll ans = 0;
        set < int > s;
        s.insert(0);s.insert(n+1);
        sort(all(a));
        rep(i,n)
        {

                ll l = *(--s.lower_bound(a[i].ss));
                ll r = *s.lower_bound(a[i].ss);
                ll len = r-l-1;
                ans += a[i].ff*(a[i].ss-l)*(r - a[i].ss);
                s.insert(a[i].ss);
        }
        cout<<ans;

}


Measured memory_bytes: 12800
#include<bits/stdc++.h>
using namespace std;
int main(){

   long long int n,a,b,c,d,e,f,g,i,j,k,l,t,u;
   double res,arr[100][100];
   string x,y;
   char ch,ch1;
   vector<int> v;
   vector<int> v1;
  set<string> s;
  cin>>a;
  while(a--){
     cin>>x;
     s.insert(x);
  }
  cout<<s.size()<<endl;

 return 0;
}


Measured memory_bytes: 19256
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <functional>
#include <map>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <list>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;
#define rep(i,n) for(int (i)=0;(i)<(ll)(n);++(i))
#define repd(i,n,d) for(ll (i)=0;(i)<(ll)(n);(i)+=(d))
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset((m),(v),sizeof(m))
#define chmin(x,y) (x=min(x,y))
#define chmax(x,y) (x=max(x,y))
#define fst first
#define snd second
#define UNIQUE(x) (x).erase(unique(all(x)),(x).end())
template<class T> ostream &operator<<(ostream &os, const vector<T> &v){int n=v.size();rep(i,n)os<<v[i]<<(i==n-1?"":" ");return os;}

int main(){
	int a, b, c, d;
	cin>>a>>b;
	cout<<(a+b+1)/2<<endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String a = sc.next();
		String b = sc.next();
		String c = sc.next();

		char temp = 'a';

		boolean cut = true;
		while(cut){
			switch (temp) {
			case 'a':
				if(a.length() == 0){
					cut = false;
					temp = 'A';
					break;
				}else{
					temp = a.charAt(0);
					a = a.substring(1);
					break;
				}
			case 'b':
				if(b.length() == 0){
					cut = false;
					temp = 'B';
					break;
				}else{
					temp = b.charAt(0);
					b = b.substring(1);
					break;
				}
			case 'c':
				if(c.length() == 0){
					cut = false;
					temp = 'C';
					break;
				}else{
					temp = c.charAt(0);
					c = c.substring(1);
					break;
				}
			}
		}
		System.out.println(temp);
		sc.close();
	}
}


Measured memory_bytes: 21844
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
#define ll long long
#define rep(i, n) for(int i = 0; i < n; i++)

int main() {
    int n;
    cin >> n;
    if(n%1000 == 0) cout << 0 << endl;
    else cout << 1000-n%1000 << endl;
    return 0;
}

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




void solve()
{
       int n,k;
       cin >> n >> k ;
       int w[n],v[n];

       for(int i = 0 ; i < n ; i ++) cin >> w[i] >> v[i];
       
       vector< vector<long int> > memo(n+1, vector< long int> (1000*n+1,INT_MAX));

       memo[0][0] = 0 ;

      
    
      auto print = [&]()
      {
          for(int i = 0 ; i <= n ; i ++)
          {
              for(int j = 0 ; j <= k; j ++)
              {
                  cout << memo[i][j] << "   ";
              }
              
              cout << endl; 
          }
      };
      
      int res = 0; 
      for(int i = 1; i <= n ; i ++)
           for(int j = 0 ; j <= 1000*n ; j ++){

	           	if( j-v[i-1] < 0 ) 
	                 memo[i][j] = memo[i-1][j]; 
	           	  else 
	           	    memo[i][j] = min({memo[i-1][j], w[i-1] + memo[i-1][j-v[i-1]]}); 

	           	if(memo[i][j] <= k ) res = j ; 

           	 }
              
      
      
      //print(); 

      cout << res ;



}

int main()
{

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

	 int test = 0, t = 1;
	 if(test) cin >> t;
	 for(int i = 0 ; i < t ; i ++)
	 {
         solve(); 
	 }

	return 0;
}


Measured memory_bytes: 83196
import numpy as np

N, M, C = [int(x) for x in input().split()]
B = np.array([int(x) for x in input().split()])

count = 0
for i in range(N):
  A = np.array([int(x) for x in input().split()])
  if np.dot(A, B) + C > 0:
    count += 1
  
print(count)

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

bool search(const string t, const string s){
    for(int i=0;i<t.length();i++){
        if(s[i] != t[i] && s[i] != '?'){
            return false;
        }
    }
    return true;
}

int main(){
    string s, t;
    cin >> s >> t;
    bool flg = false;
    int start = -1;
    string temp_t(t.length(), '?');
    for(int j=s.length()-t.length();0<=j;j--){
        string temp = s.substr(j, t.length());
        if(search(temp_t, temp)){
            flg = true;
            start = j;
            break;
        }
    }
    for(int i=t.length()-1;0<=i;i--){
        for(int j=s.length()-t.length()+i;i<=j;j--){
            if(t[i] == s[j]){
                string temp = s.substr(j-i, t.length());
                if(search(t, temp)){
                    flg = true;
                    if(start < j-i){
                        start = j-i;
                    }
                }
            }
        }
    }

    if(flg){
        s.erase(start, t.length());
        s.insert(start, t);
        for(int i=0;i<s.length();i++){
            if(s[i] == '?'){
                s[i] = 'a';
            }
        }
        cout << s << endl;
    }
    else{
        cout << "UNRESTORABLE" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        int a = Math.max(A,B);
        int b = Math.min(A,B);
        int ans = Math.max(2*a-1,a+b);
        System.out.println(ans);
    }
}

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

int main(){
    int n, k;
    cin >> n >> k;
    vector<int> a(n, 0), indeg(n, 0), v(n);
    for(int i = 0; i < n; i++){
        cin >> v[i];
        v[i]--;
        if(v[i] != -1)   indeg[v[i]]++;
    }
    priority_queue<pair<int,int>> pq;
    for(int i = 0; i < n; i++){
        if(indeg[i] == 0)   pq.push({k, i});
    }
    while(!pq.empty()){
        pair<int,int> p = pq.top(); pq.pop();
        int x = p.first, y = p.second;
        if(a[y] == 1)    continue;
        a[y] = 1;
        if(x == 1 || v[y] == -1)    continue;
        if(a[v[y]] == 0) pq.push({x-1, v[y]});
    }
    for(int i = 0; i < n; i++)  if(v[i] == -1)   a[i] = 1;
    cout << accumulate(a.begin(), a.end(), 0) << endl;
    return 0;
}


Measured memory_bytes: 5048
import java.util.Scanner;

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

		int N = sc.nextInt();

		String[] W = new String[N];

		String[] chaf = new String[N];

		String[] chal = new String[N];

		for(int i=0;i<N; i++) {
			W[i] = sc.next();
		}



		for(int i=0;i<N; i++) {
		chal[i] = String.valueOf(W[i].charAt(W[i].length()-1));
		chaf[i] = String.valueOf(W[i].charAt(0));
	}

		for(int i=0;i<N;i++) {
			for(int j=0;j<N;j++) {
				if(i!=j) {
					if(W[i].equals(W[j])) {System.out.print("No");
						System.exit(0);
					}

				}
			}
		}

		for(int i=0; i<N-1; i++) {
			if(chal[i].equals(chaf[i+1])) {		}
			else {System.out.print("No");
			System.exit(0);
			}
		}

		System.out.print("Yes");

}
}


Measured memory_bytes: 23380
/*
confirm 0LL and 1LL
confirm cornercases such as 0
confirm times of cin < 10^6
*/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Pld = pair<ld, ld>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecD = vector<ld>;
using VecS = vector<string>;
using Graph = vector<VecP>;
template <typename T>
using Vec1 = vector<T>;
template <typename T>
using Vec2 = vector<Vec1<T> >;
#define REP(i, m, n) for(ll (i) = (m); (i) < (n); ++(i))
#define REPN(i, m, n) for(ll (i) = (m); (i) <= (n); ++(i))
#define REPR(i, m, n) for(ll (i) = (m)-1; (i) >= (n); --(i))
#define REPNR(i, m, n) for(ll (i) = (m); (i) >= (n); --(i))
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPNR(i, n, 1)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define fs first
#define sc second
template <typename T>
bool chmax(T &a, const T b){if(a < b){a = b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T b){if(a > b){a = b; return true;} return false;}
template <typename T>
ll pow2(const T n){return (1LL << n);}
template <typename T>
void cosp(const T n){cout << n << ' ';}
void co(void){cout << '\n';}
template <typename T>
void co(const T n){cout << n << '\n';}
template <typename T1, typename T2>
void co(pair<T1, T2> p){cout << p.fs << ' ' << p.sc << '\n';}
template <typename T>
void co(const Vec1<T> &v){for(T i : v) cosp(i); co();}
template <typename T>
void co(initializer_list<T> v){for(T i : v) cosp(i); co();}
template <typename T>
void ce(const T n){cerr << n << endl;}
void sonic(){ios::sync_with_stdio(false); cin.tie(0);}
void setp(const ll n){cout << fixed << setprecision(n);}
constexpr int INF = 1e9+1;
constexpr ll LINF = 1e18+1;
constexpr ll MOD = 1e9+7;
//constexpr ll MOD = 998244353;
constexpr ld EPS = 1e-11;
const ld PI = acos(-1);

inline ll hash_(ll a, ll b){
	return (a << 20) + b;
}

int main(void){
	ll n;
	cin >> n;
	Vec a(n);
	rep(i, n) cin >> a[i];

	unordered_map<ll, ll> mp;

	rep(i, n){
		REPN(k, i / 2, i / 2 + 1) mp[hash_(i, k)] = -LINF;
		mp[hash_(-2, 0)] = 0;
		mp[hash_(-1, 0)] = 0;
		REPN(j, i - 5, i - 2){
			REPN(k, i / 2, i / 2 + 1){
				if(mp.find(hash_(j, k - 1)) != mp.end()) chmax(mp[hash_(i, k)], mp[hash_(j, k - 1)] + a[i]);
			}
		}
	}

	ll ans = -LINF;
	rep(i, n) if(mp.find(hash_(i, n / 2)) != mp.end()) chmax(ans, mp[hash_(i, n / 2)]);
	co(ans);

	return 0;
}


Measured memory_bytes: 21516
#include<bits/stdc++.h>
using namespace std;
 
using ll = long long;
using pll = pair<ll, ll>;
#define all(x) (x).begin(), (x).end()
#define call(x) (x).cbegin(), (x).cend()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define sz(x) ((x).size())
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define rep(i, a, b) for(ll i = ll(a); i < ll(b); i++)
const double PI = acos(-1);
const int mod = 1e9+7;
const long long INF = (1LL << 60);
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
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 stringcount(string s, char c){return count(s.cbegin(), s.cend(), c);}
bool isInteger(double x){return floor(x) == x;}
ll ceil(ll a, ll b){return ((a)+(b)-1)/b;}
template<class T> inline bool chmax(T &a, const T &b){ if(a < b){ a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b){ if(a > b){ a=b; return 1; } return 0; }

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

  ll n, k;
  cin >> n >> k;
  vector<ll> a(n);
  rep(i, 0, n){
    cin >> a[i];
  }
  sort(all(a));

  ll cnt = 1;
  vector<ll> v;
  rep(i, 0, n){
    if(a[i] == a[i+1]) cnt++;
    else v.pb(cnt), cnt = 1;
  }
  sort(rall(v));
  //rep(i, 0, sz(v)) cout << v[i] << endl;
  
  ll ans = 0;
  rep(i, k, sz(v)){
    ans += v[i];
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3956
/*  -*- coding: utf-8 -*-
 *
 * 1600.cc: Entrance Examination
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_M = 200;

/* typedef */

/* global variables */

int ps[MAX_M];

/* subroutines */

/* main */

int main() {
  for (;;) {
    int m, nmin, nmax;
    scanf("%d%d%d", &m, &nmin, &nmax);
    if (m == 0) break;

    for (int i = 0; i < m; i++) scanf("%d", ps + i);

    int maxg = -1, n = -1;
    for (int i = nmax; i >= nmin; i--) {
      int g = ps[i - 1] - ps[i];
      if (maxg < g) maxg = g, n = i;
    }

    printf("%d\n", n);
  }
  return 0;
}



Measured memory_bytes: 3152
N = int(input())
D = list(map(int,input().split()))
mod = 998244353
from collections import defaultdict
C = dict()
for i in range(max(D)+1):
    C[i] = 0
if D[0] > 0 or D.count(0) != 1:
    print(0)
    exit()
for e in D:
    C[e] += 1
ans = 1
for key,item in C.items():
    if key == 0:
        continue
    if item == 0:
        print(0)
        exit()
    ans *= int(C[key-1]**item)
    ans = ans % mod
print(ans)


Measured memory_bytes: 20832
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.Arrays;
import java.util.Collections;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) throws IOException {
		FastScanner in = new FastScanner(System.in);
		
		
		int [] a= new int[3];
		for (int i = 0; i < 3; i++) {
			a[i]= in.nextInt();
		}
		Arrays.sort(a);
		System.out.println(a[0]+a[1]);
		
		
	}
	static class FastScanner {
		BufferedReader br;
		StringTokenizer st;

		public FastScanner(InputStream in) {
			br = new BufferedReader(new InputStreamReader(in));
			st = new StringTokenizer("");
		}

		public double nextDouble() throws NumberFormatException, IOException {
			return Double.parseDouble(next());
		}

		public String next() throws IOException {
			if (!st.hasMoreTokens()) {
				st = new StringTokenizer(br.readLine());
				return next();
			}
			return st.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}
	}
}


Measured memory_bytes: 21204
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>

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

const ll INF = 1e15;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(int i = 0; i < n; i++)
#define RREP(i, n) for(int i = n - 1; i >= 0; i--)
#define REP2(i, n, k) for(int i = 0; i < n; i += k)


int main() {
    int n;
    
    cin >> n;
    
    cout << n / 3 << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int> 
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fi first
#define se second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
string n;
int k;
ll ans=0;
int dfs2(vector<int> now){
    int nans=0;
    if(now[0]==1){
        nans=1;
        nans*=n[1]-'0'-1;
        for(int i=0;i<now.size()-1;i++) nans*=9;
        string ha=n;
        for(int i=2;i<=n.size()-1;i++) ha[i]='0';
        if(now.size()==3)
            for(int i=1;i<=9;i++)
                for(int j=1;j<=9;j++){
                    ha[now[1]]=i+'0';
                    ha[now[2]]=j+'0';
                    if(ha<=n) nans++;
                }
        if(now.size()==2)
            for(int i=1;i<=9;i++){
                ha[now[1]]=i+'0';
                if(ha<=n) nans++;
            }
        if(now.size()==1) nans++;
    }
    else{
        nans=1;
        for(int i=0;i<now.size();i++) nans*=9;
    }
    return nans;
}
void dfs(int cnt,vector<int> now){
    if(cnt && now[cnt-1]==n.size()-1 && cnt!=k) return;
    if(cnt==k){
        ans+=dfs2(now);
        return;
    }
    for(int ha=(cnt==0?1:now[cnt-1]+1);ha<=n.size()-1;ha++){
        vector<int> ooo=now;
        ooo.pb(ha);
        dfs(cnt+1,ooo);
    }
}
int main(){
    cin>>n>>k;
    n='$'+n;
    vector<int> o;
    dfs(0,o);
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
def Main(S, Q, queries):
    right = S
    left = ""
    flipped = False
    T1 = 0
    for q in queries:
        if int(q[0]) == 1:
            if not flipped:
                flipped = True
            else:
                flipped = False
            continue
        else:
            if int(q[1]) == 1:
                if flipped:
                    right += q[2]
                else:
                    left += q[2]
            else:
                if not flipped:
                    right += q[2]
                else:
                    left += q[2]
    le = list(left)
    le.reverse()
    left = "".join(le)
    ans = left + right
    if flipped:
        l = list(ans)
        l.reverse()
        ans = "".join(l)
    return ans
        

def main():
    S = str(input())
    Q = int(input())
    queries = []
    for i in range(Q):
        queries.append(list(map(str, input().split())))
    print(Main(S, Q, queries))

if __name__ == '__main__':
    main()

Measured memory_bytes: 42996
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int mod = 1000000007;
const double PI = acos(-1);

int main()
{
	int k;
	cin >> k;
	set<int> s;
	int x = 7 % k;
	int ans = 1;
	while (s.count(x) == 0) {
		if (x == 0) {
			cout << ans << endl;
			return 0;
		}
		s.insert(x);
		x = (x * 10 + 7) % k;
		ans++;
	}
	cout << -1 << endl;
}


Measured memory_bytes: 50468
#include <iostream>

int main() {
  int R;
  std::cin >> R;

  if ( R < 1200 ) {
    std::cout << "ABC" << std::endl;
  } else if ( R < 2800 ) {
    std::cout << "ARC" << std::endl;
  } else {
    std::cout << "AGC" << std::endl;
  }

  return 0;
}


Measured memory_bytes: 256
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
inf=float('inf')
mod = 10**9+7
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N=I()
    V=LI()
    ans = 0
    for i in range(N-1):
        V.sort()
        V.append((V[0]+V[1])/2)
        V.remove(V[0])
        V.remove(V[0])
    print(*V)
            
if __name__ == '__main__':
    main()

Measured memory_bytes: 38384
#include<cstdio>
#include<cstring>
#include<algorithm>
#define N 200005
#define Pii pair<int, int>
#define fi first
#define se second
#define mk make_pair
using namespace std;
const int mod = 1e9+7;
inline int read(){
	int sum = 0, t = 1; char ch = getchar();
	while(ch < '0' || ch > '9'){ if(ch == '-') t = -1; ch = getchar(); }
	while(ch >= '0' && ch <= '9'){ sum = sum * 10 + ch - '0'; ch = getchar(); }
	return sum * t;
}

int n, val[N], top;

Pii a[N], seg[N];

void upd(int &x, int y){ x += y; if(x >= mod) x -= mod; }

int add(int x, int y){ x += y; return x >= mod ? x - mod : x; }

struct node{
	int Mx, Mn, S;
	void up(int x){	upd(S, (Mx = Mn = x)); }
	friend node operator + (node a, node b){ return (node){ max(a.Mx, b.Mx), min(a.Mn, b.Mn), add(a.S, b.S) }; }
};

struct segment{
	node tr[N<<2];
	#define ls ri << 1
	#define rs ri << 1 | 1
	#define mid (l + r >> 1)
	#define to_l ls, l, mid
	#define to_r rs, mid + 1, r

	void build(int ri, int l, int r){
		if(l == r){
			tr[ri].Mx = 0; tr[ri].Mn = 0x3f3f3f3f;
			tr[ri].S = 0;
			return ;
		}
		build(to_l); build(to_r);
		tr[ri] = tr[ls] + tr[rs];
	}

	void modify(int ri, int l, int r, int pos, int val){
		if(l == r) return tr[ri].up(val);
		if(pos <= mid) modify(to_l, pos, val);
		else modify(to_r, pos, val);
		tr[ri] = tr[ls] + tr[rs];
	}
	
	node query(int ri, int l, int r, int L, int R){
		if(l >= L && r <= R) return tr[ri];
		if(R <= mid) return query(to_l, L, R);
		if(L > mid) return query(to_r, L, R);
		return query(to_l, L, R) + query(to_r, L, R);
	}
}S;

int main(){
	n = read();
	for(int i = 1; i <= n; i++)
		val[++top] = a[i].se = read(), a[i].fi = read();
	sort(val + 1, val + top + 1);
	top = unique(val + 1, val + top + 1) - val - 1;
	sort(a + 1, a + n + 1);
	for(int i = 1; i <= n; i++)
		a[i].se = lower_bound(val + 1, val + top + 1, a[i].se) - val;
	S.build(1, 1, n);
	for(int i = 1; i <= n; i++){
		S.modify(1, 1, n, a[i].se, i);
		seg[i].fi = S.query(1, 1, n, a[i].se, n).Mn;
	}
	S.build(1, 1, n);
	for(int i = n; i ; i--){
		S.modify(1, 1, n, a[i].se, i);
		seg[i].se = S.query(1, 1, n, 1, a[i].se).Mx;
	}
	S.build(1, 1, n);
	sort(seg + 1, seg + n + 1);
	int ans = 0;
	for(int i = 1; i <= n; i++){
		int f = 0;
		if(seg[i].fi == 1) f++;
		upd(f, S.query(1, 1, n, max(seg[i].fi - 1, 1), n).S);
		if(seg[i].se == n) upd(ans, f);
		S.modify(1, 1, n, seg[i].se, f);
	}
	printf("%d\n", ans);
}


Measured memory_bytes: 13440
#include <bits/stdc++.h>
#include <cstdlib> 
using namespace std;
int main() {
  int N,M;cin >> N >> M;
  vector<int> vec(N,0);
  int a;
  for(int i=0;i<M;i++){
  	cin >> a;
    vec[a-1] +=1;
    cin >> a;
    vec[a-1] +=1;
  }
  
  for(int j=0;j<N;j++) cout << vec[j] << endl;
}

Measured memory_bytes: 256
# 整数の入力
numbers = int(input())
#　数に合わせてリストを作る
number_list = []
for num in range(numbers):
	number_list.append(num+1)

#引数が配列、何回処理できるか返す関数を作る 
def how_many_times_divisible(n):
	#回数をまずは０で定義
	count = 0
    #一つずつ処理される入ってきた値が割り切れなくなるまで
	while n % 2 == 0:
		#2でわる
		n = n / 2
		#回数を一上げる
		count = count + 1
    #割れなくなったら返す
	return count
  
#map(how_many_times_divisible,number_list))で最大何回割れるかをそれぞれ数えてリストにする
#print(list(map(how_many_times_divisible,number_list)))
#[0, 1, 0, 2, 0, 1, 0]
list_how_many_times_divisible = list(map(how_many_times_divisible,number_list))
#この中で一番大きい値の番号をだす
index_number = list_how_many_times_divisible.index(max(list_how_many_times_divisible))

#答えはインデックス番号と実際の値がずれるため+1をする
ans = index_number + 1
print(ans)

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

using namespace std;

int main()
{
    int cards[4][13], n;

    for (int i = 0; i < 4; i++)
    {
        for (int j = 0; j < 13; j++)
        {
            cards[i][j] = 0;
        }
    }

    cin >> n;

    for (int i = 0; i < n; i++)
    {
        char s;
        int n;

        cin >> s >> n;

        if (s == 'S')
        {
            cards[0][n - 1] = 1;
        }
        if (s == 'H')
        {
            cards[1][n - 1] = 1;
        }
        if (s == 'C')
        {
            cards[2][n - 1] = 1;
        }
        if (s == 'D')
        {
            cards[3][n - 1] = 1;
        }
    }

    for (int i = 0; i < 4; i++)
    {
        for (int j = 0; j < 13; j++)
        {
            if (cards[i][j] == 0)
            {
                if (i == 0)
                {
                    cout << "S"
                         << " " << j + 1 << endl;
                }
                if (i == 1)
                {
                    cout << "H"
                         << " " << j + 1 << endl;
                }
                if (i == 2)
                {
                    cout << "C"
                         << " " << j + 1 << endl;
                }
                if (i == 3)
                {
                    cout << "D"
                         << " " << j + 1 << endl;
                }
            }
        }
    }
}


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

using namespace std;

#define SZ(x) (int)(x.size())

using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const ld eps = 1e-9;
const ll MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}

template<typename T1, typename T2>
ostream& operator<<(ostream &os, const pair<T1, T2> p) {
  os << p.first << ":" << p.second;
  return os;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  ll n; cin >> n;
  vll a(n), b(n);
  for(int i=0;i<n;++i) {
    cin >> a[i];
    b[i] = 2 * a[i];
  }
  vvll dpl(n, vll(30, LINF)), dpr(n, vll(30, LINF));

  for(int i=0;i<30;++i) {
    dpr[n-1][i] = i;
  }
  for(int i=n-2;i>=0;--i) {
    for(int j=0;j<30;++j) {
      ld tmp = log2((ld)a[i] / a[i+1]) / 2.0 + j;
      tmp -= eps;
      ll m = tmp < 0 ? 0ll : (ll)(floor(tmp) + eps) + 1;
      if(m < 30) {
        dpr[i][j] = j + dpr[i+1][m];
      } else {
        dpr[i][j] = j + dpr[i+1][29] + (n-i-1) * (m - 29);
      }
    }
  }
  for(int i=0;i<30;++i) {
    dpl[0][i] = i;
  }
  for(int i=1;i<n;++i) {
    for(int j=0;j<30;++j) {
      ld tmp = log2((ld)a[i] / a[i-1]) / 2.0 + j;
      tmp -= eps;
      ll m = tmp < 0 ? 0ll : (ll)(floor(tmp) + eps) + 1;
      if(m < 30) {
        dpl[i][j] = j + dpl[i-1][m];
      } else {
        dpl[i][j] = j + dpl[i-1][29] + i * (m - 29);
      }
    }
  }

  ll ans = LINF;
  for(int i=0;i<n-1;++i) {
    ans = min(ans, 2 * (dpl[i][0] + dpr[i+1][0]) + (i+1));
  }
  ans = min(ans, 2*dpr[0][0]);
  ans = min(ans, 2*dpl[n-1][0] + n);

  cout << ans << endl;

}


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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)
#define mp make_pair

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int32 k, x;
    cin >> k >> x;
    FOR(i,x-k+1,x+k)cout << i << " ";
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
import math

A, B, H, M = (int(x) for x in input().split())

minuteAngle = math.radians(M*6)

hourAngle = math.radians(M*1/2 + H*30)

angleC = abs(hourAngle - minuteAngle)

print(math.sqrt((A**2) + (B**2) - (2*A*B*math.cos(angleC))))


Measured memory_bytes: 9548
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string.h>
#include <string>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <math.h>
#include <algorithm>
#include <numeric>

using namespace std;

// マクロ&定数 ============================================================
typedef unsigned int uint;
typedef long long ll;
//typedef pair<int, int> P;

typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<bool> vbool;
typedef vector<string> vstring;

typedef vector<pair<int, int>> vpint;
typedef vector<pair<ll, ll>> vpll;
typedef vector<pair<double, double>> vpdouble;

typedef vector<vector<int>> vvint;
typedef vector<vector<ll>> vvll;
typedef vector<vector<double>> vvdouble;
typedef vector<vector<string>> vvstring;
typedef vector<vector<bool>> vvbool;

const int c_YET = -1;
const int INF = 1e9 + 1;
const ll LLINF = 1e17 + 1;
const int DX[9] = { 0,0,1,-1, 1, 1, -1, -1, 0 }; // 4;４近傍
const int DY[9] = { 1,-1,0,0, 1, -1, 1, -1, 0 }; // 8:８近傍 9:(0,0)を含む
const ll MOD = 1e9 + 7; //10^9 + 7
const ll MAX = 1e9;
const double PI = 3.14159265358979323846264338327950288;
//========================================================================



int main() {

	////==================================
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(30);
	////==================================



	ll N, K;
	cin >> N >> K;

	//for (ll N = 1; N < 100; N++)
	//{
	//	for (ll K = 1; K < 100; K++)
	//	{

			ll half = 0;
			ll multi = N / K;

			if (K % 2 == 0)
			{
				half = N / (K / 2);
				multi = N / K;
				half -= multi;
			}
			else
			{
				multi = N / K;
			}

			ll ans1 = half * half * half + multi * multi * multi;

			cout << half * half * half + multi * multi * multi << endl;



	//	}
	//}




}





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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x,n) bitset<n>(x)
#define PI 3.14159265358979323846

typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> PP;

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

string s;

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

	cin>>s;
	int cnt=0;
	if(s[0]=='1') cnt++;
	if(s[1]=='1') cnt++;
	if(s[2]=='1') cnt++;
	cout<<cnt<<endl;

	return 0;
}


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


using namespace std;


int main() {
    int n, x;

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

        int ans {};

        for (int i = 1; i <= n - 2; ++i)
            for (int j = i + 1; j <= n - 1; ++j)
                for (int k = j + 1; k <= n; ++k)
                    if (i + j + k == x)
                        ++ans;


        cout << ans << endl;

    }

    

    return 0;
} 

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

using namespace std;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

void test_case() {
	string s;
	cin >> s;
	int n = s.size();
	stack<char> res;
	for(int i = 0; i < n; i ++) {
		if(s[i] == 'B') {
			if(res.size() != 0) {
				res.pop();
			}
		} else {
			res.push(s[i]);
		}
	}
	string result;
	while(res.size()) {
		result += res.top();
		res.pop();
	}
	reverse(result.begin(), result.end());
	cout << result;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int t = 1; 
	//scanf("%d", &t);
	while(t --) {
		test_case();
	}
	return 0;
}


Measured memory_bytes: 3604
N,M = map(int, input().split())
A = list(map(int, input().split()))
all=0
for i in range(N):
    all+=A[i]
all = all/(4*M)
count=0
for j in range(N):
    if A[j] >= all:
        count+=1
if count < M:
    print('No')
else :
    print('Yes')

Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<functional>
#include<math.h>
using namespace std;
#define N (1000000000+7)
#define INF 1e16
typedef long long ll;
typedef pair<int,int> P;

ll A(ll x){
    if(x>=0)return x;
    else return -x;
}

ll gcd(ll a, ll b) {
	if (b > a) {
		ll tmp = b;
		b = a;
		a = tmp;
	}
	if (a%b == 0)return b;
	else return gcd(b, a%b);
}
int main(void){
    int X;
    cin>>X;
    ll k = gcd(360,X);
    cout<<360/k<<endl;
    return 0;
}

Measured memory_bytes: 3632
import collections

def solution1(kard):
    #強いものから順に探していく
    if fourcard(kard):
        print("four card")
    elif fullhouse(kard):
        print("full house")
    elif straight(kard):
        print("straight")
    elif threecard(kard):
        print("three card")
    elif twopair(kard):
        print("two pair")
    elif onepair(kard):
        print("one pair")
    else:
        print("null")

def fourcard(kard):
    if kard.count(kard[0])==4 or kard.count(kard[1])==4:
        return True
    else:
        return False

def fullhouse(kard):
    list=collections.Counter(kard)
    if len(list)==2:
        return True
    else:
        return False

def straight(kard):
    c=sorted(kard,reverse=True)
    if c[0]==(c[1]+1)==(c[2]+2)==(c[3]+3)==(c[4]+4) or (c[0]==(c[1]+1)==(c[2]+2)==(c[3]+3) and c[4]==1 and c[0]==13):
        return True
    else:
        return False
    

def threecard(kard):
    if kard.count(kard[0])==3 or kard.count(kard[1])==3 or kard.count(kard[2])==3:
        return True
    else:
        return False
    
def twopair(kard):
    list=collections.Counter(kard)
    if len(list)==3:
        return True
    else:
        return False

def onepair(kard):
    list=collections.Counter(kard)
    if len(list)==4:
        return True
    else:
        return False


while True:
    try:
        kard=list(map(int,input().split(",")))
    except:
        break
    solution1(kard)



Measured memory_bytes: 6004
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        #[allow(unused_mut)]
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

#[allow(dead_code)]
type Pi = (i32, i32);
fn pri<T: std::fmt::Display>(x: T) {println!("{}", x);}

fn main() {
    input!{
        v: [u32; 10],
    }
    let mut v = v;
    v.sort();
    pri(v[9]); pri(v[8]); pri(v[7]);
}


Measured memory_bytes: 5028
#include <bits/stdc++.h>
using namespace std;
long long st;
long long n,x,y,z;
int state;
const long long si=1e9+7;
long long dp[45][1<<17];
int main()
{
	scanf("%d%d%d%d",&n,&x,&y,&z);
	long long ans=1;
	for (int i=1;i<=n;i++)
	ans=(ans*10)%si;
	st=(1<<z-1)|(1<<z+y-1)|(1<<(x+y+z-1));
	state=(1<<x+y+z)-1;
	dp[0][0]=1;
	for (int i=1;i<=n;i++)
	  for (int j=0;j<=state;j++)
	    {
		  if (dp[i-1][j]==0)
		   continue;
		  for (int k=1;k<=10;k++)
		    {
			int noww=(j<<k)|(1<<k-1);
			noww=noww&state;
			if ((noww&st)!=st)
			 dp[i][noww]=(dp[i][noww]+dp[i-1][j])%si; 
			}
		}
	for (int i=0;i<=state;i++)
	  ans=(ans-dp[n][i]+si)%si;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 41216
s=input()
ans=0
count=0
t=""
if s[0]=="A":
  ans+=1
for i in range(2,len(s)-1):
  # print(s[i])
  if s[i]=="C":
    count+=1
    t=s[1:i]+s[i+1:]	
# print(t)
if t.islower()==True and ans==1 and count==1:
  print("AC")
else:
  print("WA")

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

#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 ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
#define LINF 1e18
typedef long long ll;


int main() {
    string A,B; cin >> A >> B;
    if(A.size() > B.size()) cout << "GREATER" << endl;
    else if(A.size() < B.size()) cout << "LESS" << endl;
    else{
        REP(i,A.size()){
            if(A[i]>B[i]){
                cout << "GREATER" << endl;
                return 0;
            }else if(A[i]<B[i]){
                cout << "LESS" << endl;
                return 0;
            }
        }
        cout << "EQUAL" << endl;
    }

    return 0;
}

Measured memory_bytes: 3596