akhauriyash/Code-Regression huggingface dataset:
n = int(input())
F = []
P = []
for _ in range(n):
    F.append(list(map(int, input().split())))
for _ in range(n):
    P.append(list(map(int, input().split())))
ans = -1000000000
for pattern in range(1, 2 ** 10):
    _ans = 0
    for shop in range(n):
        match_cnt = 0
        for i in range(10):
            if F[shop][i] == 0:
                continue
            if (pattern >> i) & 1:
                match_cnt += 1
        _ans += P[shop][match_cnt]
    ans = max(ans, _ans)
print(ans)


Measured memory_bytes: 74120
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))

C_plus = []
C_minus = []
for i in range(N):
    c = A[i]-B[i]
    if c>=0:
        C_plus.append(c)
    else:
        C_minus.append(c)
    
C_plus.sort()
C_plus = C_plus[::-1]

minus_num=len(C_minus)
minus=-sum(C_minus)

count=0
for i in range(len(C_plus)):
    if minus<=0:
        break
    minus-=C_plus[i]
    count+=1

if minus>0:
    print(-1)
else:
    print(minus_num+count)

Measured memory_bytes: 19068
#include <bits/stdc++.h>
#define ll long long
#define all(x) (x).begin(), (x).end()
using namespace std;

int main() {
    int n;
    cin >> n;
    string s;
    cin >> s;
    int sum = n;
    for (int i = 1; i < n; i++) {
        if (s[i] == s[i - 1]) sum--;
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 512
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>

using namespace std;

class Node{
    public:
        unsigned int key;
        Node *next;
        Node *prev;
};

typedef struct Node *NodePointer;

NodePointer nil;

NodePointer listSearch(int key){
    for(auto t = nil->next;t!=nil;t=t->next){
        if(t->key==key)
            return t;
    }
    return nil;
}

int getSize(){
    int count=0;
    for(auto t = nil->next;t!=nil;t=t->next){
        count++;
    };
    return count;
}

void init(){
      nil = new Node();
      nil->next = nil;
      nil->prev = nil;
}

void printList(){

//   cout<<getSize()<<endl;

    NodePointer cur = nil->next;
    int isf = 1;
    while(1){
        if ( cur == nil ) break;
        if ( isf == 0)  printf(" ");
        cout<<cur->key;
        cur = cur->next;
        isf = 0;
    }
    cout<<endl;
}

void deleteNode(NodePointer t){
    t->next->prev=t->prev;
    t->prev->next=t->next;
}

void deleteFirst(){
      NodePointer t = nil->next;
      if ( t == nil ) return;
      deleteNode(t);
}

void deleteLast(){
      NodePointer t = nil->prev;
      if( t == nil )return;
      deleteNode(t);
}

void Delete(int key){
    if(listSearch(key)!=nil){
        deleteNode(listSearch(key));
    }
}


void insert(int key){
      NodePointer x;
      x = new Node();
      x->key = key;
      x->next=nil->next;
      nil->next->prev=x;
      x->prev=nil;
      nil->next=x;

}

int main(){
      int key, n, i;
      int size = 0;
      char com[20];
      int np = 0, nd = 0;
      cin>>n;
      init();
      for ( i = 0; i < n; i++ ){
          scanf("%s%d", com, &key);
          if ( com[0] == 'i' ) {
//            cout<<"insert"<<endl;
            insert(key); np++; size++;
        }else if ( com[0] == 'd' ){
//            cout<<"delete ";
            if (strlen(com) > 6){
//                cout<<com[6]<<" ";
                if ( com[6] == 'F' ){
                    deleteFirst();
//                    cout<<"First"<<endl;
                }else if ( com[6] == 'L' ){
                    deleteLast();
//                    cout<<"Last"<<endl;
                }
            } else {
                    Delete(key); nd++;
//               cout<<key<<endl; 
            }
            size--;
        }

  //      printList();

//       cout<<"["<<i<<"]"<<endl;
      }
//      cout<<"print"<<endl;
      printList();
      return 0;
}

Measured memory_bytes: 35612
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }

    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scan.nextInt();
        int X = scan.nextInt()-1;
        int Y = scan.nextInt()-1;
        HashMap<Integer, Integer> dp = new HashMap<>();
        for (int i = 0; i < N; i++) {
            for (int j = i + 1; j < N; j++) {
                int distance = Math.min(j - i, Math.min(Math.abs(i - X) + 1 + Math.abs(j - Y), Math.abs(j - X) + 1 + Math.abs(i - Y)));
                dp.merge(distance, 1, Integer::sum);
            }
        }
        for (int k = 1; k < N; k++) {
            System.out.println(dp.getOrDefault(k, 0));
        }
    }
}


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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define UB upper_bound
#define LB lower_bound
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

int n, a[100];

bool ask(LL v) {
	string s;
	cout << "? " << v << endl;
	cin >> s;
	return (s == "Y");
}

void ans(LL v) {
	cout << "! " << v << endl;
	exit(0);
}

LL ex(LL x, LL y) {
	return (y == 0 ? 1 : x * ex(x, y - 1));
}

int main() {
	int e = -1;
	inc(i, 10) {
		if(! ask(ex(10, i))) { e = i; break; }
	}
	
	if(e == -1) {
		inc(i, 10) { 
			if(ask(2 * ex(10, i))) { ans(ex(10, i)); }
		}
	}
	
	LL L = ex(10, e - 1), H = ex(10, e);
	while(H - L > 1) {
		LL M = (L + H) / 2;
		(ask(M * 10) ? H : L) = M;
	}
	ans(H);
	
	return 0;
}


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

using namespace std;
typedef long long ll;

int main(){
    int n;
    string s;
    cin >> n >> s;

    for(int i=0; i<s.length(); i++){
        if((s[i] + n) <= 'Z'){
            s[i] += n;
        }else{
            s[i] += 'A' + n - 'Z' -1 ;
        }
    }

    cout << s << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int n,m;
  scanf("%d%d",&n,&m);
  int a[n];
  int i;
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
  }
  long long int ans = 0;
  int tmp[n+1];
  tmp[0]=0;
  int j=0;
  for(i=0;i<n;i++){
    tmp[i+1]=(tmp[i]+a[i])%m;
    for(j=0;j<=i;j++){
      if(tmp[i+1]==tmp[j]){
        ans++;
      }
    }
  }
  printf("%lld\n",ans);
  return 0;
}


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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) begin(r),end(r)
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)
#define vvl(v,w,h,init) vector<vector<ll>> v(w,vector<ll>(h,init))
#define mp(a,b) make_pair(a,b)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using pii = pair<int,int> ;
using pll = pair<ll,ll> ;

template<typename T>
void O(T t){
  cout << t << endl;
}

const ll mod = 1e9+7;
constexpr ll inf = ((1<<30)-1)*2+1 ;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0,1,-1,1,-1};
const int dx[] = {0,-1,0,1,1,-1,-1,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n,W;
  cin >> n >> W;
  vector<vector<ll>> v(4);
  vector<vector<ll>> sum(4);
  ll a,b,w,v2;
  cin >> a >> b;
  v[0].push_back(b);
  rep(i,n-1){
    cin >> w >> v2;
    v[w-a].push_back(v2);
  }
  rep(i,4){
    sort(all(v[i]));
    reverse(all(v[i]));
    sum[i].resize(v[i].size()+1);
    rep(j,sum[i].size()-1){
      sum[i][j+1] += sum[i][j] + v[i][j];
    }
  }
  ll ans = 0;
  rep(i,v[0].size()+1){
    rep(j,v[1].size()+1){
      rep(k,v[2].size()+1){
        rep(l,v[3].size()+1){
          if(i * a + j * (a+1) + k * (a+2) + l * (a+3) <= W){
            ans = max(ans,sum[0][i] + sum[1][j] + sum[2][k] + sum[3][l]) ;
          }
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
package main
 
import (
	"fmt"
)

func main() {
  var a, b, c int
  
  ans := 1
  fmt.Scanf("%d %d %d", &a, &b, &c)
  if a != b{
    ans++
  }
  if a != c && b != c{
    ans++
  }
  
  fmt.Printf("%d", ans)
}

Measured memory_bytes: 1832
def yakusu(m):
  cnt=1
  for i in range(1,(m//2)+1):
    if m%i==0:
      cnt+=1
  return cnt
ans=0
n=int(input())
for j in range(1,n+1):
  if yakusu(j)==8 and j%2!=0:
    ans+=1
print(ans)
               

    


Measured memory_bytes: 2940
#import<complex>
#import<cstdio>
#define F(a,b,c) acos((b*b+c*c-a*a)/2/b/c)
int main(){typedef double D;int n;D d,e,f,g,h,i;for(scanf("%d",&n);n--;){scanf("%lf%lf%lf%lf%lf%lf",&d,&g,&e,&h,&f,&i);std::complex<D> a(d,g),b(e,h),c(f,i);D A=abs(b-c),B=abs(c-a),C=abs(a-b),s=sin(2*F(A,B,C)),t=sin(2*F(B,C,A)),u=sin(2*F(C,A,B)),v=s+t+u;printf("%.3f %.3f %.3f\n",(d*s+e*t+f*u)/v,(g*s+h*t+i*u)/v,A/sin(F(A,B,C))/2);}}

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

int main() {
    int n, x[100], y[100];
    cin >> n;

    for (int i = 0; i < n; i++) {
        cin >> x[i];
    }
    for (int i = 0; i < n; i++) {
        cin >> y[i];
    }

    for (int p = 1; p <= 3; p++) {
        double D = 0;
        for (int i = 0; i < n; i++) {
            D += pow(abs(x[i] - y[i]), p);
        }
        D = pow(D, 1.0 / p);
        printf("%f\n", D);
    }

    double D = 0;
    for (int i = 0; i < n; i++) {
        double x_y = abs(x[i] - y[i]);
        D = max(D, x_y);
    }
    printf("%f\n", D);

    return 0;
}


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

using namespace std;

# define int long long
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<double, int> pdi;
typedef pair<ll, ll> pll;

# define S second
# define F first
# define kill(x) return(cout << x << endl, 0)
# define debug(x) cerr<< #x << " : " << x << endl
# define ddebug(x, y) cerr<< #x << " : " << x  << ", " << #y << " : " << y << endl
# define sz(s) (int)s.size()
# define sq(x) (x) * (x)
# define PB(x) push_back(x)
# define smax(x, y) (x) = max((x), (y))
# define smin(x, y) (x) = min((x), (y))
# define all(x) x.begin(), x.end()
# define SP fixed << setprecision(10)

const int MAXN = 300 + 10;
int n;
string s[MAXN];

bool f(int a)
{
	for (int i = 0; i < n; i ++)
		for (int j = i; j < n; j ++)
			if (s[(i + a) % n][j] != s[(j + a) % n][i])
				return false;
	return true;
}

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

	cin >> n;
	for (int i = 0; i < n; i ++)
		cin >> s[i];

	int ans = 0;
	for (int i = 0; i < n; i ++)
		ans += f(i);

	cout << ans * n << endl;


	return 0;
}






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

int main() {
  int N;
  cin >> N;
  vector<int> H(N + 1);
  H[N] = 1000000001;
  rep(i, N) cin >> H[i];

  int ans = 0;
  int count = 0;
  rep(i, N) {
    if (H[i] >= H[i + 1]) {
      count++;
    } else {
      ans = max(ans, count);
      count = 0;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 640
a = [[[0 for i in range(10)] for j in range(3)] for k in range(4)]

n = int(input())

for i in range(n):
    b, f, r, v = [int(i) for i in input().split()]
    a[b-1][f-1][r-1] += v

for i, x in enumerate(a):
    for y in x:
        for z in y:
            print(' %d' % z, end='')
        print('')
    if i < 4 - 1:
        print('####################')

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

int main(){
	int n,cnt[100] = {},mi = 100,ma = 0;
	bool flag = true;
	cin >> n;
	for(int i = 0;i < n;i++){
		int a;
		cin >> a;
		cnt[a]++;
		mi = min(mi,a);
		ma = max(ma,a);
	}
	if(ma % 2){
		if(mi != ma / 2 + 1) flag = false;
		if(cnt[mi] != 2) flag = false;
	}
	else {
		if(mi != ma / 2) flag = false;
		if(cnt[mi] != 1) flag = false;
	}
	for(int i = mi + 1;i <= ma;i++) if(cnt[i] < 2) flag = false;
	if(flag) cout << "Possible" << endl;
	else cout << "Impossible" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

int A[100], n;

using namespace std;

void insertionSort(){
    for(int i=1;i<n;++i){
        int v = A[i];
        int j = i-1;

        while(j>=0 && A[j] > v){
            A[j+1] = A[j];
            j--;
        }
        A[j+1] = v;
        for(int j= 0;j < n;++j){
            cout << A[j];
            if(j != n-1)cout << " ";
        }
        cout << "\n";
    }
}

int main(){
    cin >> n;
    
    for(int i=0; i<n; ++i ){
        cin >> A[i];
        cout << A[i];
        if(i != n-1)cout << " ";
    }
    cout << "\n";
    insertionSort();
    
    return 0;
}


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

int main() {
  int N;
  string S;
  cin >> N >> S;

  bool a = true;
  if (N%2 != 0){
      a = false;
  }else{
      for (int i; i<N/2; i++){
          if (S.at(i)!=S.at(i+N/2)){
              a = false;
          }
      }
  }
  if (a){
      cout << "Yes";
  }else{
      cout << "No";
  }
  return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<unordered_map>
#include<algorithm>
#include<math.h>
#include<string>
#include<utility>
#include<queue>
#include<stdlib.h>
int main() {
	using namespace std;
	int a,b;
	cin >> a>>b;
	cout << a*b<<" "<<2*a+2*b << endl;
	return 0;
}


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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
template<typename T> using pq = priority_queue<T>;
template<typename T> using minpq = priority_queue<T, vector<T>, greater<T>>;
template<typename T, typename K> using ump = unordered_map<T, K>;
const ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll e5 = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = n - 1; i >= 0; i--)
#define repone(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define each(i, mp) for(auto& i:mp)
#define eb emplace_back
#define F first
#define S second
#define all(obj) (obj).begin(), (obj).end()

template<class T>
void dump_debug(T list) {
#ifdef MY_DEBUG
    each(e, list) cout << e << " ";
    printf("\n");
#endif
}

/* ------------- ANSWER ------------- */
/* ---------------------------------- */

int main() {
#ifdef MY_DEBUG
    while (true) {
#endif
        string s;
        cin >> s;
        ll n = s.size();

        ll ans = 0;
        bool two = false;
        for (ll i = 0; i < n; ++i) {
            if (!two && i < n - 1 && s[i] == s[i + 1]) {
                two = true;
                i++;
            } else {
                two = false;
            }
            ans++;
        }
        cout << ans << endl;
#ifdef MY_DEBUG
    }
#endif
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin>>n;
map<string,int> mp;
mp["AC"]=0;
mp["TLE"]=0;
mp["WA"]=0;
mp["RE"]=0;
while(n--)
{
    string s;
    cin>>s;
    mp[s]++;
}
cout<<"AC x "<<mp["AC"]<<endl;
cout<<"WA x "<<mp["WA"]<<endl;
cout<<"TLE x "<<mp["TLE"]<<endl;
cout<<"RE x "<<mp["RE"]<<endl;

   return 0;
}


Measured memory_bytes: 3596
n, k = map(int, input().strip().split())
arr = list(map(int, input().strip().split()))

dp = [0 for i in range(k+1)]

for i in range(len(dp)):
    if dp[i] == 0:
        for j in arr:
            if j+i < k+1:
                dp[j+i] = 1

ans = "First" if dp[-1] else "Second"
print(ans)

Measured memory_bytes: 9864
#include <iostream>
#include <string>
#include <map>

using namespace std;

typedef long long ll;

ll gcd (ll p, ll q) {
  if (q == 0) return p;
  return gcd(q, p % q);
}

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

  ll n, m;
  cin >> n >> m;

  string s, t;
  cin >> s >> t;

  map<ll, char> taken;
  for (ll i = 0; i < n; i++) {
    taken[i * m] = s[i];
  }

  for (ll i = 0; i < m; i++) {
    if (taken.count(i * n) && taken[i * n] != t[i]) {
      cout << -1 << endl;
      return 0;
    }
  }

  cout << n * m / gcd(n, m) << endl;
}


Measured memory_bytes: 6144
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main()
{
	ios::sync_with_stdio(false);
	int n; cin >> n;
	vector<ll> a(n);
	for (int i = 0; i < n; i++)
		cin >> a[i];
	ll result = 0;
	for (int i = 0; i < n; i++)
		for (int j = 0; j < n; j++)
			if (i != j)
				result = max(result, abs(a[i] - a[j]));
	cout << result << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#ifdef ONLINE_JUDGE
#define trace(...)
#endif

using LL = long long;

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

	int n; cin >> n;
	int sum = 0, ans = 0;
	for (int i = 0; i < n; i++) {
		int a; cin >> a;
		ans += a * sum;
		sum += a;
	}
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 256
import sys
nodes = ['OFFSET'] + [-1] * 4000000
_num_nodes = 0
outputs = [None] * 2000000
_num_outputs = 0

def max_heapify(idx):
    left_idx = idx * 2
    right_idx = left_idx + 1

    max_idx = idx

    if nodes[left_idx] > nodes[max_idx]:
        max_idx = left_idx
    if nodes[right_idx] > nodes[max_idx]:
        max_idx = right_idx

    if max_idx != idx:
        tmp = nodes[idx]
        nodes[idx] = nodes[max_idx]
        nodes[max_idx] = tmp
        max_heapify(max_idx)
    return


def insert(node_no):
    global _num_nodes
    nodes[_num_nodes+1] = node_no
    _num_nodes += 1
    idx = _num_nodes
    while idx > 1:
        parent_idx = idx // 2
        if nodes[idx] > nodes[parent_idx]:
            tmp = nodes[parent_idx]
            nodes[parent_idx] = nodes[idx]
            nodes[idx] = tmp
        else:
            break
        idx = parent_idx
    return


def extract():
    global _num_outputs
    outputs[_num_outputs] = nodes[1]
    _num_outputs += 1
    global _num_nodes
    nodes[1] = nodes[_num_nodes]
    nodes[_num_nodes] = -1
    _num_nodes -= 1
    max_heapify(1)
    return


def main():
    commands = sys.stdin.readlines()
    for command in commands:
        if command[0] == 'i':
            insert(int(command[7:]))
        elif command[1] == 'x':
            extract()
        elif command[1] == 'n':
            break

    for i in range(_num_outputs):
        print(outputs[i])
    return


main()


Measured memory_bytes: 246460
from math import gcd

N = int(input())
X = list(map(int, input().split()))

left = [0] * (N + 2)
right = [0] * (N + 2)

for i in range(N):
    left[i + 1] = gcd(left[i], X[i])

for i in reversed(range(N)):
    right[i + 1] = gcd(right[i + 2], X[i])

ans = 1
for i in range(N):
    ans = max(ans, gcd(left[i], right[i + 2]))

print(ans)


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

string s;
int n,p;
int t[20];


vector<int> solve(){
  vector<int> res(1<<4);

  if(s[p]!='('){
    res[t[s[p]-'0']]=1;
    p++;
    return res;
  }

  p++;
  vector<int> lv=solve();
  p++;
  vector<int> rv=solve();
  p++;

  for(int i=0;i<(1<<4);i++){
    for(int j=0;j<(1<<4);j++){
      res[i|j]+=lv[i]*rv[j];
      res[i&j]+=lv[i]*rv[j];
      res[i^j]+=lv[i]*rv[j];
    }
  }
  return res;
}

int main(){
  while(1){
    getline(cin,s);    
    if(s=="END")break;
    cin>>n;
    for(int i=1;i<=n;i++){
      int S=0,a;
      for(int j=0;j<4;j++){
	cin>>a;
	S+=(a<<j);
      }
      t[i]=S;
    }  
    p=0;
    vector<int> ans=solve();
    cout<<ans[(1<<4)-1]<<endl;
    cin.ignore();
  }
  return 0;
}

Measured memory_bytes: 1212
#include <stdio.h>

int main(){
    long long int input_N;
    long long int sum_num = 0;

    scanf("%lld", &input_N);
    long long int a = (input_N/15 - 1);

    for(auto i=0; i<input_N && i<=15; i++){
        if((!(i%3)==0) && (!(i%5)==0)){
            sum_num += i;
        }
    }
    // printf("%lld\n", sum_num);

    for(auto i=1; i<=a; i++){
        sum_num += 120*i + 60;
    }
    // printf("%lld\n", sum_num);

    for(auto i=(a+1)*15+1; i<=input_N; i++){
        if((!(i%3)==0) && (!(i%5)==0)){
            sum_num += i;
        }
    }
    
    printf("%lld", sum_num);

    return(0);
}

Measured memory_bytes: 1732
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
using ll = long long;
typedef pair<int, int> P;
ll Mod = 1000000007;
int main() {
  string S;
  cin >> S;
  int N = S.size();
  int ans = N;
  bool one = false;
  bool zero = false;
  for (int i = (N-1)/2; i >= 0; i--) {
    if (S[i] == '1') {
      one = true;
    } else {
      zero = true;
    }
    if (S[N-1-i] == '1') {
      one = true;
    } else {
      zero = true;
    }
    if (one && zero) {
      ans = N-1-i;
      break;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3700
#include <iostream>
#include <iomanip>
#include <complex>
#include <vector>
#include <algorithm>
#include <array>
#include <utility>
using namespace std;

const double EPS = 1e-10;
const double INF = 1e12;
#define EQ(n,m) (abs((n)-(m)) < EPS)
#define X real()
#define Y imag()
 
typedef complex<double> P;
typedef vector<P> VP;
struct L : array<P, 2>{
    L(const P& a, const P& b){ at(0)=a; at(1)=b; }
    L(){}
};

namespace std{
    bool operator < (const P& a, const P& b){
        return !EQ(a.X, b.X) ? a.X<b.X : a.Y<b.Y;
    }
    bool operator == (const P& a, const P& b){
        return abs(a-b) < EPS;
    }
}

double dot(P a, P b){
    return (conj(a)*b).X;
}
double cross(P a, P b){
    return (conj(a)*b).Y;
}
int ccw(P a, P b, P c){
    b -= a;
    c -= a;
    if(cross(b,c) > EPS) return +1; //ccw
    if(cross(b,c) < -EPS) return -1; //cw
    if(dot(b,c) < -EPS) return +2; //c-a-b
    if(abs(c)-abs(b) > EPS) return -2; //a-b-c
    return 0; //a-c-b
}
bool intersectSS(const L& a, const L& b){
    return ( ccw(a[0],a[1],b[0]) *ccw(a[0],a[1],b[1]) <= 0 ) &&
        ( ccw(b[0],b[1],a[0]) *ccw(b[0],b[1],a[1]) <= 0 );
}
P crosspointLL(const L &l, const L &m) {
  double A = cross(l[1]-l[0], m[1]-m[0]);
  double B = cross(l[1]-l[0], l[1]-m[0]);
  return m[0] + B/A *(m[1]-m[0]);
}
bool isParallel(const P &a, const P &b){
    return abs(cross(a,b)) < EPS;
}
bool isParallel(const L &a, const L &b){
    return isParallel(a[1]-a[0], b[1]-b[0]);
}

int main(){
    int rep;
    cin >> rep;
    for(int r=0; r<rep; r++){
        int sx,sy, gx,gy;
        cin >> sx >> sy >> gx >> gy;
        L rail(P(sx,sy), P(gx,gy));
        int n;
        cin >> n;
        vector<pair<P, int> > cp;
        for(int i=0; i<n; i++){
            int l, o, tag;
            cin >> sx >> sy >> gx >> gy >> l >> o;
            L r = L(P(sx,sy), P(gx,gy));
            tag = l^o;
            if(!isParallel(rail, r) && intersectSS(rail, r)){
                cp.push_back(make_pair(crosspointLL(rail, r), tag));
            }
        }
        sort(cp.begin(), cp.end());
        int ans = 0;
        for(int i=0; i<(int)cp.size()-1; i++){
            if(cp[i].second != cp[i+1].second) ans++;
        }
        cout << ans << endl;
    }
    return 0;
}



Measured memory_bytes: 3092
#include <bits/stdc++.h>
using namespace std;
#define ll long long int 
#define ld double
#define mp make_pair
#define pb push_back
#define mod 1000000007
#define ff first
#define ss second
#define pll pair <ll,ll>
#define nl "\n"
ll dp[3002][3002];
int main()
{
	ios_base::sync_with_stdio(false);
	string s,t;
	cin>>s>>t;
	ll i,j;
	ll n=s.length(),m=t.length();
	dp[0][0]=0;
	for(i=1;i<=n;i++)
	{
		for(j=1;j<=m;j++)
		{
			dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
			dp[i][j]=max(dp[i][j],dp[i-1][j-1]+(s[i-1]==t[j-1]));
		}
	}
	string ans="";
	i=n,j=m;
	while(i>0 && j>0)
	{
		if(s[i-1]==t[j-1])
		{
			ans+=s[i-1];
			i--;
			j--;
		}
		else if(dp[i-1][j]>dp[i][j-1])
			i--;
		else
			j--;
	}
	reverse(ans.begin(),ans.end());
	cout<<ans<<nl;
	return 0;
}

Measured memory_bytes: 70656
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef long long ll;
int N, M;
ll K;
ll A[200000], B[200000];
ll suma[200001], sumb[200001];

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    int a = 0, b = 0;
    cin >> N >> M >> K;
    for(int i = 0; i < N; i++) cin >> A[i];
    for(int i = 0; i < M; i++) cin >> B[i];
    for(int i = 1; i <= N; i++) suma[i] = suma[i-1]+A[i-1];
    for(int i = 1; i <= M; i++) sumb[i] = sumb[i-1]+B[i-1];

    int ans = 0;
    for(int i = 0; i <= N; i++){
        if(K < suma[i]) break;
        ll L = K-suma[i];
        auto p = upper_bound(sumb, sumb+M+1, L);
        int tmp = i+p-sumb-1;
        ans = max(ans, tmp);
    }    
    cout << ans << endl;
}

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

#define rep(i, a, b) for (ll i = (a); i < (b); i++)
typedef uint64_t ull;
typedef int64_t ll;
typedef std::pair<ll, ll> PLL;

using namespace std;

ll M = 1000000007;

ll dp[52][52][3000];

signed main() {
  ll N, K;
  cin>>N>>K;
  dp[0][0][0] = 1;
  for (int i=0; i<N; i++) {
    for (int j=0; j<N; j++) {
      for (int k=0; k<=N*N; k++) {
        {
          // i番目同士をくっつける
          (dp[i+1][j][k + j*2] += dp[i][j][k]) %= M;
        }
        {
          // どちらも保留
          (dp[i+1][j+1][k + (j+1)*2] += dp[i][j][k]) %= M;
        }
        {
          // i番目の片方をくっつける
          (dp[i+1][j][k + j *2] += dp[i][j][k] * 2 * j) %= M;
        }
        if (j-1 >= 0) {
          // i番目と何処かをくっつける
          (dp[i+1][j-1][k + (j-1) *2] += dp[i][j][k] * j * j) %= M;
        }
      }
    }
  }
  cout<<dp[N][0][K]<<endl;
  return 0;
}


Measured memory_bytes: 61184
n,q = gets.chomp.split(" ").map{|i|i=i.to_i}
a=[]
b=[]
$hash = {}
n.times{|i|
  $hash[i.to_s] = []
}

(n-1).times do
  arr = gets.chomp.split(" ").map{|ii|ii=ii.to_i}
  a<<arr[0]
  b<<arr[1]
end
(n-1).times do|i|
  $hash[(a[i]-1).to_s] << (b[i]-1)
end
p=[]
x=[]
q.times do|i|
  arr = gets.chomp.split(" ").map{|ii|ii=ii.to_i}
  p<<arr[0]
  x<<arr[1]
end

$count_arr = Array.new(n,0) # 最終的な値が入る

q.times{|i|
  $count_arr[p[i]-1] += x[i]
}

#pp $count_arr
#pp $hash

#def kasan(n,aa)
#  if($hash[aa.to_s] != nil) then
#    $hash[aa.to_s].each do |m|
#      $count_arr[m] += $count_arr[aa]
#      kasan(n,m)
#    end
#  end
#  return
#end
#kasan(n,0)
n.times do|i|
  $hash[i.to_s].each do|m|
    $count_arr[m] += $count_arr[i]
  end
end

puts $count_arr.join(" ")

Measured memory_bytes: 69432
#include<bits/stdc++.h>
#define ll long long
#define endl "\n"
#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;  
int main() 
{
	FAST
    int c=0;
    string s,s1;
	cin>>s>>s1;
  	if(s[0]==s1[0]) c++;
  	if(s[1]==s1[1]) c++;
  	if(s[2]==s1[2]) c++;
  	cout<<c;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <climits>
#include <ctime>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <set>
#include <map>
#include <iostream>
#include <deque>
#include <complex>
#include <string>
#include <iomanip>
#include <sstream>
#include <bitset>
#include <valarray>
#include <iterator>
using namespace std;
typedef long long int ll;
typedef unsigned int uint;
typedef unsigned char uchar;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;

#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();i++)
#define ALL(container) container.begin(), container.end()
#define RALL(container) container.rbegin(), container.rend()
#define SZ(container) ((int)container.size())
#define mp(a,b) make_pair(a, b)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"["; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"]"; return os;
}
template<class T> ostream& operator<<(ostream &os, const set<T> &t) {
os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}

const int INF = 1<<28;
const double EPS = 1e-8;
const int MOD = 1000000007;


int n;

main(){
	int sum = 0;
	REP(i, 5){
		cin >> n;
		sum += max(40, n);
	}
	cout << sum/5 << endl;
	return 0;
}

Measured memory_bytes: 1160
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.bigint, std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }
T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }
T[] RDA(T = long)(T fix = 0) { if (_f.isOpen)  return _RDA!T(_f, fix); else return _RDA!T(fix); }

size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }

long mod = 10^^9 + 7;
//long mod = 998244353;
//long mod = 1_000_003;
void moda(T)(ref T x, T y) { x = (x + y) % mod; }
void mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(T)(ref T x, T y) { x = (x * y) % mod; }
void modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }

void main()
{
	auto S = RD!string;

	string ans;
	foreach (i; 0..S.length)
		ans ~= "x";

	writeln(ans);
	stdout.flush;
	debug readln;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll N, A, B, v[50], c[51][51], ans;
double acc;
int main() {
    for(int i{}; i <= 50; ++i)
        for(int j{}; j <= i; ++j)
            c[i][j] = (!j || i == j ? 1ll :  c[i - 1][j - 1] + c[i - 1][j]);
    cin >> N >> A >> B;
    for(int i{}; i < N; ++i)
        cin >> v[i];
    sort(v, v + N, greater<ll>());
    cout.precision(10); cout << fixed;
    for(int i{}; i < A; ++i) acc += v[i];
    acc /= A;
    if(v[0] == v[A - 1]) {
        int cnt = count(v, v + N, v[0]);
        cout << acc << endl;
        for(int i = A; i <= B; ++i)
            ans += c[cnt][i];
        cout << ans << endl;
    }
    else {
        int cnt = count(v, v + N, v[A - 1]), z = count(v, v + A, v[A - 1]);
        cout << acc << endl;
        cout << c[cnt][z] << endl;
    }
}


Measured memory_bytes: 256
import java.util.Scanner;
class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int A = sc.nextInt();
    int B = sc.nextInt();
    int outlet = 1;
    int cnt = 0;
    while(B>outlet){
      --outlet;
      outlet += A;
      cnt++;
    }
    System.out.print(cnt);
  }
}


Measured memory_bytes: 22608
'''
Created on 2020/08/25

@author: harurun
'''
def main():
  import sys
  pin=sys.stdin.readline
  pout=sys.stdout.write
  perr=sys.stderr.write
  
  N,K=map(int,pin().split())
  D=list(map(int,pin().split()))
#   l=[0,1,2,3,4,5,6,7,8,9]
#   for i in D:
#     l.remove(i)
  j=N
  while True:
    for k in str(j):
      if int(k) in D:
        break
    else:
      print(j)
      break
    j+=1
  return 
main()

Measured memory_bytes: 9128
import java.util.*

fun main(args: Array<String>) {
  val sc = Scanner(System.`in`)
  val n = sc.nextInt()
  val w = (1..n).map { sc.next() }

  val ans = b(w)
  println(ans)
}

private fun b(w: List<String>): String {
  val set = mutableSetOf<String>()
  var preLast = w.get(0).first()
  for (wi in w) {
    if (set.contains(wi)) return "No"
    if (wi.first() != preLast) return "No"
    set.add(wi)
    preLast = wi.last()
  }
  return "Yes"
}


Measured memory_bytes: 36044
use proconio::{input, fastout};

#[fastout]
fn main() {
    input!{
        inp: String,
    }
    let n = inp.chars().collect::<Vec<char>>();
    if n[0] == n[1] && n[1] == n[2] {
	println!("Yes");
    } else if n[1] == n[2] && n[2] == n[3] {
	println!("Yes");
    } else {
	println!("No");
    }
}


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

int main(void){
  const int inf=1<<30;
  typedef tuple<int,int,int>t3;
  int n,Q,i,cur=0,s,t,x,v;
  set<t3>q;
  scanf("%d %d",&n,&Q);vector<int> ans(Q,-1),ds(Q);
  multiset<int>ms;ms.insert(inf);
  for (i=0;i<n;i++){
    scanf("%d %d %d",&s,&t,&x);
    q.insert(make_tuple(s-x,x,1));
    q.insert(make_tuple(t-x,x,0));
  }

  for (i=0;i<Q;i++)scanf("%d",&ds[i]);

  while (!q.empty()){
    t3 e=*q.begin();q.erase(q.begin());
    tie(t,x,s)=e, v=*ms.begin();v=v!=inf?v:-1;
    while(cur<Q&&ds[cur]<t)ans[cur++]=v;
    if(s)ms.insert(x);
    else ms.erase(ms.find(x));
  }

  for (i=0;i<Q;i++)printf("%d\n",ans[i]);
  return 0;
}


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

int n,q;
string s[100010];
int cnt[100010][26][26];
int sub[100010];

struct Trie{
	bool f;
	int num[26];
	Trie *nxt[26];
	Trie(){
		f=false;
		for(int i=0;i<26;i++){
			num[i]=0;
			fill(nxt,nxt+26,(Trie*)0);
		}
	}
};

Trie *insert(string &t,Trie *r){
	for(int i=0;i<t.size();i++){
		int c=t[i]-'a';
		if(!r->nxt[c])r->nxt[c]=new Trie;
		++(r->num[c]);
		r=r->nxt[c];
	}
	r->f=true;
	return r;
}

void pre(int id,string &t,Trie *r){
	for(int i=0;i<t.size();i++){
		sub[id]+=r->f;
		int c=t[i]-'a';
		for(int j=0;j<26;j++){
			cnt[id][j][c]+=r->num[j];
		}
		r=r->nxt[c];
	}
}

int main(void){
	scanf("%d",&n);
	Trie *r=new Trie();
	for(int i=0;i<n;i++){
		cin >> s[i];
		Trie *v=r;
		insert(s[i],v);
	}
	for(int i=0;i<n;i++){
		Trie *v=r;
		pre(i,s[i],v);
	}
	scanf("%d",&q);
	for(int i=0;i<q;i++){
		int k;
		string pr;
		cin >> k >> pr;
		k--;
		int ret=sub[k];
		for(int p=0;p<26;p++){
			for(int q=p+1;q<26;q++){
				ret+=cnt[k][pr[p]-'a'][pr[q]-'a'];
			}
		}
		printf("%d\n",ret+1);
	}
	return 0;
}

Measured memory_bytes: 309504
n = int(input())
a = list(map(int,input().split()))
acts = []
while True:
    for i in range(len(a)):
        idx = len(a)-i-1
        if a[idx] == idx+1:
            a.pop(idx)
            acts.append(idx+1)
            break
    else:
        print('-1')
        break
    if len(a) == 0:
        acts.reverse()
        print('\n'.join(map(str,acts)))
        break

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <unordered_map>
#include <cmath>
#include <utility> // pair make_pair
#include <algorithm>
#include <iomanip>

#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,63,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define ll long long
//#define int ll

using namespace std;
using Graph = vector<vector<int> >;


struct UnionFind {
  vector<int> par; // 親ノード
  vector<int> rank; // ランク

  UnionFind(int n = 1) {
    init(n);
  }

  void init(int n = 1) {
    par.resize(n);
    rank.resize(n);
    for (int i = 0; i < n; i++) {
      par[i] = i;
      rank[i] = 0;
    }
  }

  int root(int x) {
    if (par[x] == x) {
      return x;
    } else {
      int r = root(par[x]);
      return par[x] = r;
    }
  }

  bool issame(int x, int y) {
    return root(x) == root(y);
  }

  bool merge(int x, int y) {
    x = root(x); y = root(y);
    if (x == y) return false;
    if (rank[x] < rank[y]) swap(x, y); // y is smaller, x is bigger
    if (rank[x] == rank[y]) rank[x]++;
    par[y] = x; // parent of y is x
    return true;
  }
  
};

int main() {
  int N, K, L; cin >> N >> K >> L;

  UnionFind Forest1(N), Forest2(N);

  
  for (int i = 0; i < K; i++) {
    int p, q;
    cin >> p >> q;
    p--; q--;
    Forest1.merge(p, q);
  }

  for (int i = 0; i < L; i++) {
    int r, s;
    cin >> r >> s;
    r--; s--;
    Forest2.merge(r, s);
  }

  map<pair<int, int>, int> Ans;
  
  for (int i = 0; i < N; i++) {
    Ans[make_pair(Forest1.root(i), Forest2.root(i))]++;
  }

  for (int i = 0; i < N; i++) {
    cout << Ans[make_pair(Forest1.root(i), Forest2.root(i))] << " ";
  }

  cout << endl;
  
}


Measured memory_bytes: 15104
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;

const long long N = 3e6 + 17;
ll a[N], b[N], cnt, ans, lnt, n, m, r1, r0, l1, l0, sum, mx, h, c[N], t[N], mn = N, x, y, k;
pair<ll,ll>pr[N];
vector<ll>v,v2;
map<ll,ll>mp;
bool used[N];
char ch[N];
ll prime[N] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53};

int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    cin >> n >> m;
    if(n <= 8 and m <= 8)
    {
        cout << "Yay!";
    }
    else 
    {
        cout << ":(";
    }
    return 0;
}


Measured memory_bytes: 4352
#include "bits/stdc++.h"

using namespace std;

int table[100];

int main(void) {
    int n; cin >> n;
    for (int i = 0; i < 100; i++) {
        table[i] = 51;
    }

    for (int i = 0; i < n; i++) {
        string t; cin >> t;
        for (char j = 0; j <= ('z' - 'a'); j++) {
            int cnt = 0;
            for (int k = 0; k < t.length(); k++) {
                if ((j + 'a') == t[k]) cnt++;
            }
            
            table[j] = min(table[j], cnt); 
        }
    }

    string res = "";

    for (int i = 0; i <= ('z' - 'a'); i++) {
        if (table[i] == 51) continue;
        for (int j = 0; j < table[i]; j++) {
            cout << (char)(i + 'a');
        }
    }

    cout << endl;

    return 0;
}

Measured memory_bytes: 256
# coding: utf-8
N=int(input())
A=list(map(int,input().split()))
Q=int(input())

num=[0 for i in range(10**5+1)]

for i in range(N):
    num[A[i]]+=1

ans=sum(A)

for q in range(Q):
    B,C=map(int,input().split())
    num[C]+=num[B]
    ans+=(C-B)*num[B]
    num[B]=0
    print(ans)

Measured memory_bytes: 83384
import java.util.Scanner;

public class Main {

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

		String[] strs  = new String[h];

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

		StringBuilder sb =new StringBuilder();
		// up/down bar
		for(int i = 0; i < (w+2); i++){
			sb.append('#');
		}
		String  updown= new String(sb);

		// display
		System.out.println(updown);
		for(int i=0; i < h;i++){
			System.out.print("#");
			System.out.print(strs[i]);
			System.out.println("#");
		}
		System.out.println(updown);

		sc.close();
	}
}


Measured memory_bytes: 21204
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;

public static class P
{
    public static void Main()
    {
        var nmq = Console.ReadLine().Split().Select(int.Parse).ToArray();
        var (n, m, q) = (nmq[0], nmq[1], nmq[2]);
        var query = Enumerable.Repeat(0, q).Select(_ => Console.ReadLine().Split().Select(int.Parse).ToArray()).ToArray();
        int res = 0;
        for (int i = 0; i < (1 << (m + n)); i++)
        {
            List<int> seq = new List<int>();
            for (int j = 0; j < n + m; j++)
            {
                if ((i >> j & 1) == 1)
                {
                    var next = j + 1 - seq.Count;
                    if (next > m) goto end;
                    seq.Add(next);
                }
            }
            if (seq.Count != n) continue;

            //Console.WriteLine(string.Join(" ", seq));
            res = Max(res, query.Where(x => seq[x[1] - 1] - seq[x[0] - 1] == x[2]).Sum(x => x[3]));
            end:;
        }
        Console.WriteLine(res);
    }
}


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

typedef long long ll;
const int N = 1e5 + 77;
const int mod = (int)1e9 + 7;

int main()
{
  int n, m, a[5];
  for (int i = 0; i < 5; i++)
  {
    scanf("%d", a + i);
    if (a[i] == 0)
      m = i + 1;
  }
  printf("%d\n", m);
  return 0;
}

Measured memory_bytes: 3812
# https://maspypy.com/atcoder-%E5%8F%82%E5%8A%A0%E6%84%9F%E6%83%B3-2019-02-16abc-155#toc3
# https://atcoder.jp/contests/abc155/submissions/10152895
# 写経


# 条件を満たす要素を抽出
# ndarray[条件式]

def binary_search(*, ok, ng, func):
    while abs(ok - ng) > 1:
        mid = (ok + ng) // 2
        if func(mid):
            ok = mid
        else:
            ng = mid
    return ok


def main():
    import sys
    import numpy as np

    inf = 10 ** 18 + 1
    input = sys.stdin.readline

    N, K = map(int, input().split())
    A = np.array(input().split(), dtype=np.int64)

    A.sort()

    zero = A[A == 0]
    pos = A[A > 0]
    neg = A[A < 0]

    def count(x):
        """
        定数cに対して Ai*Aj<=c となる(i,j)の数え上げ
        順序制約 i<j -> 順序制約のない(i,j)からi==jの場合の個数を引いて2で割る
        iを固定して a=Ai とする
        a=0
            ax=0(<=c?),解なしまたは任意のx
        a>0
            ax<=c
            <-> x<=c/a
            <-> x<=c//a
        a<0
            ax<=c
            <-> (-a)x>=(-c)

            否定をとり,aの対候補全体=Nから引く

            (-a)x<(-c)
            <-> (-a)x<=(-c-1)
            <-> x<=(-c-1)//(-a)
        """
        cnt = 0
        if x >= 0:
            cnt += zero.size * N  # (a:=0)*v<=x
        cnt += np.searchsorted(a=A, v=x // pos, side='right').sum()  # (a:>0)*v<=x
        cnt += (N - np.searchsorted(a=A, v=(-x - 1) // (-neg), side='right')).sum()  # (a:<0)*v<=x
        cnt -= ((A * A) <= x).sum()  # i==j
        assert cnt % 2 == 0
        return cnt // 2

    ans = binary_search(
        ng=-inf,
        ok=inf,
        func=lambda x: count(x) >= K
    )

    print(ans)


if __name__ == '__main__':
    main()


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

using namespace std;

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

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

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

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

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int main(){
  int n;
  cin>>n;
  int x=1;
  while(x*x<=n)x++;
  x--;
  cout<<(x*x)<<endl;
  return 0;
}


Measured memory_bytes: 256
N=int(input())
L=[]
for i in range(N):
    x,y=list(map(int,input().split()))
    L.append([x,y])
D=[]
for i in range(N-1):
    for j in range(i+1,N):
        d=((L[i][0]-L[j][0])**2+(L[i][1]-L[j][1])**2)**0.5
        D.append(d)
Ave=sum(D)/len(D)
print(Ave*(N-1))

Measured memory_bytes: 62248
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <bitset>
#include <cmath>
#include <string>
#include <fstream>
#define FI first
#define SE second
#define VE vector<int>
#define PB push_back
#define PA pair<long long,long long>
#define MA make_pair
#define LL long long
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
using namespace std;
//
const int INF=1e9+7;
const int MOD=1e9+7;
//
LL N;
vector<PA> V[100000];
LL D[100000];
bool used[100000];
int main(){
  cin>>N;
  FOR(i,0,N-1){
    LL A,B,C;
    cin>>A>>B>>C;
    A--;B--;
    V[A].PB(MA(B,C));
    V[B].PB(MA(A,C));
  }
  LL Q,K;
  cin>>Q>>K;
  K--;
  queue<PA> que;
  que.push(MA(K,0));
  D[K]=0;
  used[K]=true;
  while(!que.empty()){
    PA P=que.front();que.pop();
    LL v=P.FI;
    FOR(i,0,(int)V[v].size()){
      LL num=V[v][i].FI;
      if(!used[num]){
        D[num]=D[v]+V[v][i].SE;
        que.push(MA(num,D[num]));
        used[num]=true;
      }
    }
  }
  FOR(i,0,Q){
    LL X,Y;
    cin>>X>>Y;
    X--;Y--;
    cout<<D[X]+D[Y]<<endl;
  }
  return 0;
}


Measured memory_bytes: 10864
#include <iostream>
using namespace std;
typedef long long ll;
ll n,m,MOD=1e9+7,a,b,ans,bik[1000001];
ll f(ll x,ll y){
    if(y==0)return 1;
    if(y%2==0)return f(x,y/2)*f(x,y/2)%MOD;
    return x*f(x,y-1)%MOD;
}
ll comb(ll x, ll y){
    return bik[x]*f(bik[x-y],MOD-2)%MOD*f(bik[y],MOD-2)%MOD;
}
int main(void){
    cin>>n>>m;
    bik[0]=1;
    for(ll i=1;i<=1000000;i++){
        bik[i]=bik[i-1]*i;
        bik[i]%=MOD;
    }
    a=n+m;
    if(a%3!=0){
        cout<<0<<endl;
        return 0;
    }
    n-=a/3;
    m-=a/3;
    //cout<<n<<" "<<m<<endl;
    if(n>=0&&m>=0){
        cout<<comb(n+m,m)<<endl;
    }
    else cout<<0<<endl;
}


Measured memory_bytes: 8064