akhauriyash/Code-Regression huggingface dataset:
N = int(input())
A = list(map(int,input().split()))
A.sort()

while(len(A) != 1):
  A_min = A.pop(0)
  A = [A[i]%A_min for i in range(len(A)) if A[i]%A_min > 0]
  A.append(A_min)
  A.sort()

print(A[0])

Measured memory_bytes: 14252
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef pair<P,int> T;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
template<class T> void chmin(T& a,const T& b){if(a>b)a=b;}
template<class T> void chmax(T& a,const T& b){if(a<b)a=b;}
ll a,b,c,n,m,x,y,p;
string s;
int main(){
	cin >> a >> p;
	cout << (a*3+p)/2 << endl;
	return 0;
}

Measured memory_bytes: 764
#include <iostream>
#include <vector>
#include <bitset>
#include <string>
using namespace std;

using bits = bitset<5001>;

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

  vector<string> a(n),b(m);
  for(int i=0; i<n; i++) cin >> a[i];
  for(int i=0; i<m; i++) cin >> b[i];

  int d = n*2;

  bits x,y,mask;
  for(int i=0; i<n; i++){
    for(int j=0; j<n; j++){
      x.set( i*d + j , a[i][j] != '.' );
    }
  }

  for(int i=0; i<m; i++){
    for(int j=0; j<m; j++){
      y.set( i*d + j , b[i][j] == '.');
      mask.set(i*d + j, 1);
    }
  }

  for(int i=0; i+m<=n; i++){
    for(int j=0; j+m<=n; j++){
      int cnt = ((x ^ (y<<(i*d + j))) & (mask<<(i*d+j)) ).count();
      if(cnt == m*m){
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;


  return 0;
}


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

int main(){
    int p ,q, r;
    cin >> p >> q >> r;
    cout << min(p+q, min(q+r, r+p)) << endl;
    return 0;
}

Measured memory_bytes: 256
from collections import deque

def bfs(s, dist):
    visited = [False] * (N+1)
    q = [(s, 1)]
    visited[s] = True

    while q:
        u, c = q.pop()
        for v in graph[u]:
            if not visited[v]:
                visited[v] = True
                dist[v] = c
                q.append((v, c+1))

def main():
    dist = [[0] * (N+1) for i in range(2)]
    
    for i in range(N-1):
        a, b = map(int, input().split())
        graph[a].append(b)
        graph[b].append(a)
        
    bfs(1, dist[0])
    bfs(N, dist[1])
    
    b = w = 0
    for i in range(2, N):
        if dist[0][i] <= dist[1][i]:
            b += 1
        else:
            w += 1
    if b <= w:
        print('Snuke')
    else:
        print('Fennec')

if __name__ == '__main__':
    N = int(input())
    graph = [deque() for i in range(N+1)]

    dist = [[0] * (N+1) for i in range(2)]
    
    main()
    

Measured memory_bytes: 82788
#include <bits/stdc++.h>
using namespace std;
int main() {
  char b; cin >> b;
  if(b=='A') cout << 'T' << endl;
  if(b=='T') cout << 'A' << endl;
  if(b=='C') cout << 'G' << endl;
  if(b=='G') cout << 'C' << endl;
}
  
  

Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define INF 1000000000
int main(){
cin.tie(0);
ios::sync_with_stdio(false);

	int N,Y;
	cin>>N>>Y;
	for(int i=2000;i>=0;i--){
		for(int j=2000-i;j>=0;j--){
			if(Y==i*10000+j*5000+1000*(N-i-j) && N-i-j>=0){
				cout<<i<<" "<<j<<" "<<N-i-j<<endl;
				return 0;
			}
		}
	}
	
	cout<<-1<<" "<<-1<<" "<<-1<<endl;
	return 0;
}
			
		

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

int main() {
	int N, K;
  std::cin >> N;
	std::cin >> K;

	int i;
	int num = 1;

	for(i = 0; i < N ; i++){
		if(num <= K){
			num *= 2;
		}else{
			num += K;
		}
	}

	std::cout << num << '\n';
	return 0;

}


Measured memory_bytes: 256
import sys
import math
(a, b, C) = [float(i) for i in sys.stdin.readline().split()]
C = C * 2 * math.pi / 360
S = a * b * math.sin(C) / 2
c = math.sqrt(a ** 2 + b ** 2 - 2 * a * b * math.cos(C))
L = a + b + c
h = 2 * S / a
print(S)
print(L)
print(h)

Measured memory_bytes: 6872
#include <iostream>
using namespace std;
/*
int countbill(int Y, int N, int yen){
    int cnt;
    while(Y>=1 && N>0){
        Y = Y/yen;
        cnt++;
        N--;
    }
    return Y, N, cnt;
}
*/
int main(){
    int N, Y;
    int cnt10000 = -1, cnt5000 = -1, cnt1000 = -1;
    cin >> N >> Y;

    for(int a=0; a<=N; a++){
        for(int b=0; b+a<=N; b++){
            int c = N-a-b;
            int total = 10000*a + 5000*b + 1000*c;
            if(total == Y){
                cnt10000 = a;
                cnt5000 = b;
                cnt1000 =c;
            }
        }
    }

/*
    Y, N, cnt10000 = countbill(Y, N, 10000);
    Y, N, cnt5000 = countbill(Y, N, 5000);
    Y, N, cnt1000 = countbill(Y ,N, 1000);

*/
    cout << cnt10000 << " " << cnt5000 << " " <<  cnt1000 << endl;
    
}

Measured memory_bytes: 768
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
			int n = sc.nextInt();
			int[] v = new int[n];
			for (int i = 0; i < n; i++) {
				v[i] = sc.nextInt();
			}
			Arrays.sort(v);

			double tmp = 0;
			for (int i : v) {
				if (tmp == 0) {
					tmp = (double)i;
				} else {
					tmp = (tmp + i) / 2;
				}
			}
			System.out.println(tmp);
		}
	}
}


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

using namespace std;

const int N = 1000000 + 100;

struct Node{
	int x, y, z;
	void read(){
		scanf("%d%d%d", &x, &y, &z);
	}
	void print(){
		printf("(%d, %d, %d)\n", x, y, z);
	}
};

bool operator <(const Node &a, const Node &b){
	if (a.x < b.x) return true;
	else if (a.x > b.x) return false;
	return a.y > b.y;
}

bool ok = false;

int n, m;
int a, b, C, M;
Node v[N];

int ans[N];
int id[N];
int tmp[N];

int tot;
int t[N];
int cnt[N];


bool cmp(const int &a, const int &b){
	return v[a] < v[b];
}

void insert(int x, int val){
	for (; x < N; x += x & -x){
		if (cnt[x] != tot){
			cnt[x] = tot;
			t[x] = 0;
		}
		t[x] = max(t[x], val);
	}
}

int ask(int x){
	int ret = 0;
	for(; x > 0; x -= x & -x){
		if (cnt[x] != tot){
			cnt[x] = tot;
			t[x] = 0;
		}
		ret = max(ret, t[x]);
	}
	return ret;
}

int r(){
	a = 36969 * (a & M) + (a >> 16);
	b = 18000 * (b & M) + (b >> 16);
	return (C & ((a << 16) + b)) % 1000000;
}

void base_sort(int l, int r){
	int mid = (l + r) >> 1;
	int p1 = l, p2 = mid;
	int pos = l;
	while(p1 < mid && p2 < r){
		if (v[id[p1]].y < v[id[p2]].y){
			tmp[pos++] = id[p1++];
		}
		else{
			tmp[pos++] = id[p2++];
		}
	}
	while(p1 < mid){
		tmp[pos++] = id[p1++];
	}
	while(p2 < r){
		tmp[pos++] = id[p2++];
	}
}

void calc(int a[], int n, int b[], int m){
	tot++;
	int p1 = 0, p2 = 0;
	while(p1 < n && p2 < m){
		if (v[a[p1]].y < v[b[p2]].y){
			insert(v[a[p1]].z, ans[a[p1]]);
			p1++;
		}
		else{
			ans[b[p2]] = max(ans[b[p2]], 1 + ask(v[b[p2]].z - 1));
			p2++;
		}
	}
	while(p2 < m){
		ans[b[p2]] = max(ans[b[p2]], 1 + ask(v[b[p2]].z - 1));
		p2++;
	}
}

void work(int l, int r, bool flag){
	if (l + 1 == r) return;
	int mid = (l + r) >> 1;
	sort(id + l, id + r, cmp);
	work(l, mid, flag == true);
	work(mid, r, false);
	base_sort(l, r);
	if (flag){
		calc(id + l, mid - l, id + mid, r - mid);
	}
	if (flag){
		sort(id + mid, id + r, cmp);
		work(mid, r, flag == true);
	}
	base_sort(l, r);
	for(int i = l; i < r; i++){
		id[i] = tmp[i];
	}
}

void init(){
	for(int i = 0; i < m; i++){
		int x, y, z;
		v[i].read();
	}
	C = ~(1 << 31), M = (1 << 16) - 1;
	for(int i = m; i < m + n; i++){
		v[i].x = r();
		v[i].y = r();
		v[i].z = r();
	}
	n = m + n;
	for(int i = 0; i < n; i++){
		v[i].x += 1;
		v[i].y += 1;
		v[i].z += 1;
	}
	sort(v, v + n);
	for(int i = 0; i < n; i++){
		id[i] = i;
		ans[i] = 1;
	}
}

void solve(){
	work(0, n, true);
	int ret = 0;
	for(int i = 0; i < n; i++){
		ret = max(ret, ans[i]);
	}
	printf("%d\n", ret);
}

int main(){
	tot = 0;
	while(~scanf("%d%d%d%d", &m, &n, &a, &b)){
		if (!n && !m && !a && !b) break;
		init();
		solve();
	}
	return 0;
}

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

int isPrime(int n){
 int i=2;
 while(1)
 {
 if(i*i>n)return 1;
 if((n%i) == 0)return 0;
 i++;
 }
 return 1;
}
int main()
{
 int n;
 cin >> n;
 int nums[10000];
 int i;
 for(i=0;i<n;i++){
  cin >> nums[i];
 }
 int count=0;
 for(i=0;i<n;i++){
  if(isPrime(nums[i]))count++;
 }
 cout << count <<endl;
}

Measured memory_bytes: 1196
#include <cstdio>
#include <cstdlib>
#include <cmath>

inline bool isp(int n) {
    int ed = (int) sqrtf((float) n);
    for (int i = 2; i <= ed; ++i) {
        if ((n % i) == 0) {
            return false;
        }
    }
    return true;
}

int main() {
    int n;

    while (scanf("%d", &n) != EOF) {
        int mx = 0;
        int mi = 0;

        for (int i = n - 1; true; --i) {
            if (isp(i)) {
                mx = i;
                break;
            }
        }

        for (int i = n + 1; true; ++i) {
            if (isp(i)) {
                mi = i;
                break;
            }
        }

        printf("%d %d\n", mx, mi);
    }

    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){
    int k;cin>>k;
    long long int ans = 0;
    for(int i = 1; i<k+1; i++){
        for(int j = 1; j<k+1; j++){
            for(int l = 1; l<k+1; l++){
                ans = ans+gcd(gcd(i,j),l);
            }
        }
    }
    cout << ans;
}

Measured memory_bytes: 3588
from math import floor, ceil

T1, T2 = map(int, input().split())
A1, A2 = map(int, input().split())
B1, B2 = map(int, input().split())

if A1 > B1:
    A1, A2, B1, B2 = B1, B2, A1, A2

diff = T1 * (B1 - A1) + T2 * (B2 - A2)

if diff == 0:
    print("infinity")
elif diff > 0:
    print(0)
else:
    c = T1 * (B1 - A1) / (- diff)
    ans = floor(c) + ceil(c)
    print(ans)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define stoi stoll
using ll=long long;
using vi=vector<int>;
using pii=pair<int,int>;
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define FORE(x,c) for(auto &&x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define SZ(c) ((int)c.size())
#define CONTAIN(c,x) (c.find(x)!=end(c))
#define INSEG(l,x,r) ((l)<=(x)&&(x)<(r))
#define dump(...)
#define pb push_back
#define _ 0
const signed INF_=1001001001; const long long INF=1001001001001001001LL;
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v))os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
    is>>p.first>>p.second;return is;}
template<class T, class U> bool chmax(T &a,const U &b){return a<b?a=b,1:0;}
template<class T, class U> bool chmin(T &a,const U &b){return a>b?a=b,1:0;}
template <class T> void PSUM(T& c) {partial_sum(begin(c), end(c), begin(c));}
template<class T> using heap=priority_queue<T,vector<T>,greater<T>>;
struct before_main_function {
    before_main_function() {
        cin.tie(0); ios::sync_with_stdio(0);
        cout << setprecision(15) << fixed;
        // #define endl "\n"
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

signed main() {
    int N;
    cin >> N;
    vector<int> L(N), R(N);
    REP(i, N) {
        int l, r;
        cin >> l >> r;
        L[i] = l;
        R[i] = r;
    }
    sort(RALL(L));
    sort(ALL(R));

    auto SL = L;
    PSUM(SL);
    auto SR = R;
    PSUM(SR);

    int ans = 0;
    REP(i, N) {
        for (int d = -1; d <= 1; d++) {
            int a = i;
            int b = i + d;
            if (a < 0 || b < 0 || a >= N || b >= N) continue;
            int tmp = (SL[a] - SR[b]) * 2;
            chmax(ans, tmp);
        }
    }
    cout << ans << endl;
    return (0^_^0);
}



Measured memory_bytes: 3456
#include <bits/stdc++.h>
#define ll long long
#define int long long
const ll INM=114514;
#define vl vector<ll>
#define pl pair<ll,ll>
#define mp make_pair
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,b) for(ll i=0;i<b;i++)
#define per(i,a,b) for(ll i=b-1;i>=a;i--)
#define Yes(i) cout<<(i?"Yes":"No")<<endl
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define all(v) (v).begin(),(v).end()
using namespace std;

ll h,w;
ll dx[]={1,0,-1,0};
ll dy[]={0,1,0,-1};
char hw[52][52];
signed main() {
    cin>>h>>w;
    rep(i,h)rep(j,w)cin>>hw[i+1][j+1];
    rep(i,h)rep(j,w){
            if(hw[i+1][j+1]=='#'){
                bool paintable=false;
                rep(k,4)if(hw[i+1+dx[k]][j+1+dy[k]]=='#')paintable=true;
                if(paintable==false){
                    cout<<"No"<<endl;
                    return 0;
                }
            }

        }
    cout<<"Yes"<<endl;
}

Measured memory_bytes: 256
import std.stdio;
import std.c.stdio;
import std.range;
import std.array;
import std.functional;
import std.algorithm;
import std.conv;
import std.container;
import std.math;
import std.numeric;
import std.string;
import std.c.string;
import std.regex;
import std.typecons;

void main() {
    int N, T, S; readf("%d %d %d\n", &N, &T, &S);
    int[] A = new int[N];
    int[] B = new int[N];
    foreach (i; 0 .. N) {
        readf("%d %d\n", &A[i], &B[i]);
    }

    int[][] cache = new int[][](N, T + 1);
    foreach (i; 0 .. N) cache[i][] = -1;
    int dfs(int y, int t) {
        if (y == N) return 0;
        if (t == T) return 0;
        //[y, t].writeln;
        if (cache[y][t] >= 0) return cache[y][t];
        int ret = 0;
        // 時間をつぶす
        ret = dfs(y, t + 1);
        // 夜店yを無視
        ret = max(ret, dfs(y + 1, t));
        // 夜店yによる
        if (t + B[y] > T) goto last;
        if (t < S && S < t + B[y]) goto last;
        ret = max(ret, dfs(y + 1, t + B[y]) + A[y]);
        last: return cache[y][t] = ret;
    }

    writeln(dfs(0, 0));
}

Measured memory_bytes: 39320
x1, y1, x2, y2 = map(int,input().split())

sax = x2 -x1
say = y2- y1

x3 = x2 - say
x4 = x3 - sax
y3 = y2 + sax
y4 = y3 - say

print(x3, y3, x4, y4)

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

int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
  int cnt = 1;
  sort(vec.begin(), vec.end());
  
  for (int i = 0; i < N - 1; i++) {
    if (vec.at(i) != vec.at(i + 1)) {
      cnt++;
    }
  }
  
  cout << cnt << endl;
    
}

Measured memory_bytes: 256
def resolve():
    A, B = map(int, input().split())
    ans = 0
    for i in range(A, B+1):
        count = 0
        for j in range(len(str(i))):
            if str(i)[j] == str(i)[(j+1)*-1]:
                count += 1
        if count == len(str(i)):
            ans += 1
    print(ans)
resolve()

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

int main() {
  int K; string S; cin >> K >> S;
  string ans;
  int Ssize = S.size();
  if (Ssize > K) {
    for (int i = 0; i < K; i++) {
      ans += S[i];
    }
    ans += "...";
  } else ans = S;
  cout << ans;
}

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

int main()
{
    int n, arr[200000];
    cin >> n;
    for (int i=0; i<n; ++i) cin >> arr[i];
    
    int minv, maxv=-2000000000;
    minv = arr[0];
    
    for (int i=1; i<n; ++i) {
        maxv = max(maxv, arr[i]-minv);
        minv = min(minv, arr[i]);
    }
    
    cout << maxv << endl;
    return 0;
}



Measured memory_bytes: 3880
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
const long long INF = 1e18;

int main(){
  int N;
  cin >> N;
  vector<long long> A(N);
  for(int i = 0; i < N; ++i) cin >> A[i];
  for(int i = 1; i < N; ++i) A[i] += A[i-1];
  long long ans = INF;
  for(int i = 1; i < N-1; ++i){
    int j_ = lower_bound(A.begin(), A.end(), A[i]/2) - A.begin();
    int k_ = lower_bound(A.begin(), A.end(), (A[i]+A[N-1])/2) - A.begin();
    //cerr << j_ << " " << i << " " << k_ << endl;
    for(int j = max(j_-1,0); j < min(j_+2,i); ++j){
      for(int k = max(i+1,k_-1); k < min(k_+2,N-1); ++k){
        vector<long long> V = {A[j],A[i]-A[j],A[k]-A[i],A[N-1]-A[k]};
        //cerr << j << " " << i << " " << k << " " << V[0] << " " << V[1] << " " << V[2] << " " << V[3] << endl;
        sort(V.begin(), V.end());
        ans = min(ans,V[3]-V[0]);
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int main()
{
	string s,t,s1;
	int ans=-1000;
	cin>>s>>t;
	if (t.size()>s.size())
	{
		cout <<"UNRESTORABLE";
		return 0;
	}
	for(int j=0;j<s.size()-t.size()+1;j++)
	{
		int f=0;
		s1=s.substr(j,t.size());
		for(int i=0;i<t.size();i++)
		{
			if(s1[i]!=t[i])
			f=1;
		}
		if(f==0)
		{
			for(int i=0;i<s.size();i++)
			{
				if(s[i]=='?') s[i]='a';
			}
			cout<<s;
			return 0;
		}
	}
	for(int i=s.size()-t.size();i>=0;i--)
	{
		int F=1;
		if(t[0]==s[i]||s[i]=='?')
		{
			F=0;
			for(int j=i;j<i+t.size();j++)
			{
				if(!(s[j]==t[j-i]||s[j]=='?'))
				{
					F=1;
					break;
				}	
			}
		}
		if(F==0)
		{
			ans=i;
			break;
		}
	}
	if(ans==-1000)
	{
		cout<<"UNRESTORABLE";
		return 0;
	}
	for(int i=ans;i<ans+t.size();i++)
	{
		s[i]=t[i-ans];
	}
	for(int i=0;i<s.size();i++)
	{
		if(s[i]=='?') s[i]='a';
	}
	cout<<s;
	return 0;
}

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

int main() {
  char c;

  cin >> c;

  if (c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o') {
    cout << "vowel" << endl;
  } else {
    cout << "consonant" << endl;
  }
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define repi(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define repdi(i,a,b) for(ll i=(a)-1;i>=(b);--i)
#define repd(i,a) repdi(i,a,0)
#define itr(it,a) for( auto it = (a).begin(); it != (a).end(); ++it )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define endl '\n'
#define debug(x) std::cerr << #x << " = " << (x) << endl;

using ll = long long;
using P = std::pair<ll, ll>;

constexpr ll INF = 1ll<<60;

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

template<class S, class T>
std::ostream& operator<< ( std::ostream& out, const std::pair<S,T>& a )
{ std::cout << '(' << a.first << ", " << a.second << ')'; return out; }

template<class T>
std::ostream &operator<< ( std::ostream& out, const std::vector<T>& a )
{ std::cout << '['; rep( i, a.size() ){ std::cout << a[i]; if( i != a.size()-1 ) std::cout << ", "; } std::cout << ']'; return out; }

std::string S, T;
ll ans = INF;

int main() {
  std::cin >> S >> T;

  rep( i, S.size() ) {
    if( i+T.size() > S.size() )
      break;

    auto t = S.substr(i, T.size());

    ll cnt = 0;

    rep( j, t.size() )
      cnt += t[j] == T[j];

    chmin( ans, (ll)(T.size()-cnt) );
  }

  std::cout << ans << endl;

  return 0;
}

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

int main() { 
  int N;
  cin >> N;
  
  string S;
  int ac=0, wa=0, tle=0, re=0;
  
  for (int i=0; i<N; i++) {
    cin >> S;
    if (S == "AC") {
      ac++;
    } else if (S == "WA") {
      wa++;
    } else if (S == "TLE") {
      tle++;
    } else if (S == "RE") {
      re++;
    }
  }
  
  cout << "AC x " << ac << endl;
  cout << "WA x " << wa << endl;
  cout << "TLE x " << tle << endl;
  cout << "RE x " << re << endl;
}


Measured memory_bytes: 3496
s = input()
if len(s)==1:
    print(s)
    exit()
list = [[0]*(len(s)-1)]
def dfs(l,cnt):
    if cnt==len(s)-1:
        return 0
    ret = l.copy()
    ret[cnt] += 1
    if not l in list:
        list.append(l)
    list.append(ret)
    dfs(l,cnt+1)
    dfs(ret,cnt+1)
    return 0
dfs([0]*(len(s)-1),0)
ans = 0
for l_ in list:
    start = 0
    for i in range(len(l_)):
        if l_[i]==1:
            ans += int(s[start:i+1])
            start = i+1
        if i==len(l_)-1:
            ans += int(s[start:])

print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define ll          long long int
#define pii         pair<int,int>
#define uu          first
#define vv          second
#define fastIO      ios::sync_with_stdio(0);cin.tie(0);
using namespace std;

const int MAX = 2e5 + 5;
const ll INF = 1e18;
int main()
{
    fastIO;
    int n, m;
    cin>>n>>m;
    
    vector< vector<int> >edg(n+1), rev(n+1);
    vector<int>deg(n+1), dp(n+1);
    
    while(m--) {
        
        int u , v;
        cin>>u>>v;
        edg[u].push_back(v);
        rev[v].push_back(u);
        deg[u]++;
    }
    
    queue<int>q;
    for(int i =1 ; i <=n ; i++ ) {
        if(deg[i] == 0) q.push(i);
    }
    int ans = 0;
    
    while(!q.empty()) {
        
        int top = q.front();
        q.pop();
        for(auto x : edg[top]) dp[top] = max(dp[top] , dp[x] + 1);
        ans = max(ans, dp[top]);
        for(auto x : rev[top]) {
            deg[x]--;
            if(deg[x] == 0 ) q.push(x);
        }
    }
    cout<<ans<<'\n';
    return 0;
}

Measured memory_bytes: 14916
#include<stdio.h>
#include<math.h>
#include<stdlib.h>

int main(){
	int n, m, sum=0, eq=0;
	scanf("%d %d", &n, &m);
	int vet[n];

	for(int i=0; i<m; ++i){
		scanf("%d", &vet[i]);
		sum+= vet[i];
	} 

	eq= n-sum;
	if (eq==0)
		printf("0");
	else if(eq < 0)
		printf("-1");
	else
		printf("%d", eq);


    printf("\n");
    return 0;
	
}


Measured memory_bytes: 1728
/**
 * File              : C. Postcard .cpp
 * Author            : horcrux2301 <khajuriaharsh729@gmail.com>
 * Date              : 06.01.2019
 * Last Modified Date: 06.01.2019
 */

#include <bits/stdc++.h>
#define ll long long
#define mp(a,b)     make_pair(a,b)
#define newline     cout << endl;
#define ff          first
#define ss          second
#define pii         pair<int,int>
#define pll         pair<ll,ll>
using namespace std;

template<typename S, typename T>
ostream& operator<<(ostream& out,pair<S,T> const& p){out<<'('<<p.ff<<", "<<p.ss<<')';return out;}

template<typename T>
ostream& operator<<(ostream& out,vector<T> const& v){
int l=v.size();for(int i=0;i<l-1;i++)out<<v[i]<<' ';if(l>0)out<<v[l-1];return out;}

template<typename T>
void trace(const char* name, T&& arg1){cout<<name<<" : "<<arg1<<endl;}

template<typename T, typename... Args>
void trace(const char* names, T&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');cout.write(names, comma-names)<<" : "<<arg1<<" | ";trace(comma+1,args...);}

int main(){
    //clock_t tStart = clock();
    int test;
    test=1;
    //cin >> test;
    while(test--){
        ll n;
        cin >> n;
        ll dp[n][3], arr[n][3];
        for(ll i=0;i<n;i++){
            for(ll j=0;j<3;j++){
                cin >> arr[i][j];
                dp[i][j]=-1;
            }
        }

        dp[0][0]=arr[0][0];
        dp[0][1]=arr[0][1];
        dp[0][2]=arr[0][2];
        
        for(ll i=1;i<n;i++){
            for(ll j=0;j<3;j++){
                for(ll k=0;k<3;k++){
                    if(j==k) continue;
                    dp[i][j]=max(dp[i][j],arr[i][j]+dp[i-1][k]);
                }
            }
        }
        

        ll ans = max(dp[n-1][0],max(dp[n-1][1], dp[n-1][2]));
        cout << ans << endl;
    }
    //printf("Time taken: %.2fs\n", (double)(clock() - tStart)/CLOCKS_PER_SEC);
    return 0;
}



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

const int MAX = 10001000;      // 素数判定する最大の数
bool IsPrime[MAX];
vector<int> Era(int n = MAX) {
    vector<int> res;
    IsPrime[0] = false; IsPrime[1] = false;
    for (int i = 2; i < n; ++i) IsPrime[i] = true;
    for (int i = 2; i < n; ++i) {
        if (IsPrime[i]) {
            res.push_back(i);
            for (int j = i*2; j < n; j += i) IsPrime[j] = false;
        }
    }
    return res;
}

int main() {
    int N; cin >> N;
    vector<int> prs = Era();
    int res = 0;
    for (int i = 3; i <= N; ++i) if (IsPrime[i] && IsPrime[i+2]) ++res;
    cout << res * 2 << endl;
}



Measured memory_bytes: 16836
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define ld long double
#define pb push_back
#define all(x) (x).begin(), (x).end()
template <typename T> using ord_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int N = 2e5 + 123, M = 4e5 + 123;
int n, f[M], m, val[M];
array <int, 2> p[N];

void upd(int x, int y) {
	for (; x <= m; x |= (x + 1))
		f[x] = max(f[x], y);
}

int get(int x) {
	int res = 0;
	for (; x >= 0; x = (x & (x + 1)) - 1)
		res = max(res, f[x]);
	return res;
}

int main() {
	ios_base::sync_with_stdio(false), cin.tie(NULL);
	#ifdef LOCAL
		freopen("input.txt", "r", stdin);
	#endif
	
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> p[i][0] >> p[i][1];
		if (p[i][0] > p[i][1]) swap(p[i][0], p[i][1]);
	}
	sort(p, p + n);
	int mx = -1;
	for (int i = 0; i < n; i++)
		if (mx == -1 || p[i][1] > p[mx][1])
			mx = i;
	int R = p[0][1], B = p[mx][0];
	for (int i = 1; i < n; i++) {
		if (mx == i) continue;
		B = max(B, p[i][0]);
		R = min(R, p[i][1]);
	}
	ll res = (ll)(B - p[0][0]) * (p[mx][1] - R);
	vector <int> v;
	for (int i = 0; i < n; i++) {
		v.pb(p[i][0]), v.pb(p[i][1]);
	}
	sort(all(v));
	v.erase(unique(all(v)), v.end());
	m = v.size();
	int r = min(p[0][1], p[mx][0]);
	for (int i = 1; i < n; i++) {
		if (i == mx) continue;
		r = min(r, p[i][1]);
	}
	for (int i = 0; i < n; i++) {
		int x = lower_bound(all(v), p[i][0]) - v.begin() + 1;
		int y = lower_bound(all(v), p[i][1]) - v.begin() + 1;
		val[x] = p[i][0], val[y] = p[i][1];
		if (i > 0)
			upd(1, p[i][0]);
		if (i != mx)
			upd(x + 1, p[i][1]);
	}
	for (int i = 1; i <= m && val[i] <= r; i++) {
		int g = get(i);
		if (g == 0) continue;
		res = min(res, (ll)(p[mx][1] - p[0][0]) * (g - val[i]));
	}
	cout << res;
}


Measured memory_bytes: 9672
#include <bits/stdc++.h>
using namespace std;
#define rep(i, ns, ne) for (int i = ns; i < ne; ++i)
 
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
 
  int N, K, k;
  cin >> N >> K;
  set<int> set;
  rep(i, 0, 10) { set.insert(i); }
 
  rep(i, 0, K) {
    cin >> k;
    set.erase(k);
  }
 
  bool ok;
  int ans = N;
 
  while (ans < 100001) {
    string str = to_string(ans);
    ok = true;
    rep(i, 0, str.size()) {
      if (!set.count(str[i] - '0')) {
        ok = false;
        break;
      }
    }
    if (ok) {
      cout << ans << endl;
      break;
    }
    ans++;
  }
  getchar();
}

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

#define MO 1000000007
#define N 200098
#define int long long 

inline int read()
{
	int ret=0; char c=getchar();
	while(c<48||c>57)c=getchar();
	while(c>=48 && c<=57)ret=ret*10+c-48,c=getchar();
	return ret;
}

int u,v,n,k,vv[97],g[N],g_[N],c[N<<1][2],a[N],tot,f[N];

inline int ksm(int n, int k)
{
	vv[0]=n;
	for(int i=1;i<=29;++i){
		vv[i]=(long long)vv[i-1]*vv[i-1]%MO;
	}
	
	int s=1;
	for(int i=29; i>=0; --i){
		if(k>=1<<i){
			k-=1<<i;
			s=(long long)s*vv[i]%MO;
		}
	}
	return s;
	
}

inline int C(int n, int m)
{
	return (long long)g[n]*g_[n-m]%MO;
}

void dfs(int p,int pr)
{
	int u,ss=0;
	f[p]=1;
	for(int o=a[p]; o; o=c[o][1]){
		u=c[o][0];
		if(pr==u)continue;
		dfs(u,p);
		f[p]=(long long)f[p]*f[u]%MO;
		++ss;
	}
	if(!ss)return;
	int h=k-1; if(p!=1)--h;
	if(h<ss){
		puts("0");
		exit(0);
	}
	f[p]=(long long)f[p]*C(h,ss)%MO;
}

signed main()
{
	n=read(); k=read();
	if(k==1&&n>1){
		puts("0");
		return 0;
	}
	if(k==2&&n>2){
		puts("0");
		return 0;
	}
	if(n==1){
		cout<<k;
		return 0;
	}
	for(int i=1;i<n;++i){
		u=read(); v=read();
		c[++tot][0]=v; c[tot][1]=a[u]; a[u]=tot;
		c[++tot][0]=u; c[tot][1]=a[v]; a[v]=tot;
	}
	
	g[0]=g[1]=1;for(int i=2;i<=100000;++i)g[i]=(long long)g[i-1]*i%MO;
	g_[0]=g_[1]=1;for(int i=2;i<=100000;++i)g_[i]=ksm(g[i],MO-2);
	
	dfs(1,0);
	cout<<(long long)f[1]*k%MO;
}

Measured memory_bytes: 16384
def main():
    # import sys
    # # input = sys.stdin.readline
    # sys.setrecursionlimit(10 ** 9)
    # MOD = 10 ** 9 + 7


    S = tuple(input())
    x, y = map(int, input().split())

    N = 8010

    X = [0]
    Y = [0]
    flag = True
    for s in S:
        if s == 'F':
            if flag:
                X[-1] += 1
            else:
                Y[-1] += 1
        else:
            if flag:
                if Y[-1] != 0:
                    Y.append(0)
            else:
                if X[-1] != 0:
                    X.append(0)
            flag = not flag

    dp = [[0] * (2 * N) for _ in range(2)]
    if S[0] == 'F':
        dp[0][X[0] + N] = 1
    else:
        dp[0][X[0] + N] = 1
        dp[0][-X[0] + N] = 1

    for i in range(1, len(X)):
        x_ = X[i]
        for j in range(2 * N):
            dp[i % 2][j] = 0
            if j >= x_:
                if dp[(i - 1) % 2][j - x_]:
                    dp[i % 2][j] = 1
            if j + x_ < 2 * N:
                if dp[(i - 1) % 2][j + x_]:
                    dp[i % 2][j] = 1

    # print (dp)
    if dp[(len(X) - 1) % 2][x + N] == 0:
        print ('No')
        exit()

    dp = [[0] * (2 * N) for _ in range(2)]
    dp[0][Y[0] + N] = 1
    dp[0][-Y[0] + N] = 1

    for i in range(1, len(Y)):
        y_ = Y[i]
        for j in range(2 * N):
            dp[i % 2][j] = 0
            if j >= y_:
                if dp[(i - 1) % 2][j - y_]:
                    dp[i % 2][j] = 1
            if j + y_ < 2 * N:
                if dp[(i - 1) % 2][j + y_]:
                    dp[i % 2][j] = 1

    if dp[(len(Y)-1) % 2][y + N] == 0:
        print ('No')
        exit()

    print ('Yes')

if __name__ == '__main__':
    main()

Measured memory_bytes: 44272
def main():
    N = int(input())
    S1 = input()
    S2 = input()
    mod = 10**9 + 7
    v = set()
    v.add(S1[0])
    v.add(S2[0])
    if len(v) == 2:
        r = 6
    else:
        r = 3
    for i in range(1, N):
        if S1[i-1] == S1[i]:
            continue
        if S1[i] == S2[i] and S1[i-1] != S2[i-1]:
            continue
        if S1[i] != S2[i] and S1[i-1] != S2[i-1]:
            r *= 3
            r %= mod
            continue
        r *= 2
        r %= mod
    return r
print(main()) 


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int a[n+5],q;
	memset(a,0,sizeof(a));
	while(cin>>q)
	{
		if(getchar()=='\n')
		{
			a[q]++;
			break;
		}
		
		a[q]++;
	}
	for(int i=1;i<=n;i++)
	{
		cout<<a[i]<<endl;
	}
}

Measured memory_bytes: 4376
#include <bits/stdc++.h>
using namespace std;
int n;
int a[200002], d[200002];
int main()
{
    //freopen("test.inp","r", stdin);
    cin >> n;
    for (int i = 2; i <= n; i++)
    {
        cin >> a[i];
        d[a[i]]++;
    }
    for (int i = 1; i <= n; i++)
    {
        cout << d[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 5148
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <numeric>
#include <queue>
using namespace std;

int main(){
    int n ;
    cin >> n ;
    vector<int> s(n) ;
    for (size_t i = 0; i < n; i++)
    {
        cin >> s.at(i) ;
    }
    int q ;
    cin >> q;
    vector<int> t(q) ;
    for (size_t i = 0; i < q; i++)
    {
        cin >> t.at(i) ;
    }
    int ans = 0;
    for (size_t i = 0; i < q; i++)
    {
        int u = 0 ;
        int l = n-1 ;
        while (l-u > 1)
        {
            int x = (l+u)/2 ;
            if (s.at(x) > t.at(i))
            {
                l = x ;
            }else
            {
                u = x ;
            }
                
            
            
        }
        if (s.at(l)== t.at(i) || s.at(u) == t.at(i))
        {
            ans ++ ;
        }
        
    }
    
    cout << ans << endl; 
    
}


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

int main() {
	long long a,b,c;
	cin >> a >> b >> c;
	long long d = c - a - b;
	long long g = a * b * 4;
	string k = "No";
	if(d > 0 && g < d * d)
	{
		k = "Yes";
	}
	cout << k << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define vv(T) std::vector<std::vector<T>>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;

int		main(void)
{
	string T;
	cin >> T;

	for (int i = 0; i < (int)T.size(); i++)
	{
		char c = T[i];
		if (c == '?')
			cout << 'D';
		else
			cout << c;
	}
	cout << endl;
}



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

int main()
{
  int a, b;
  cin >> a >> b;
  
  if(a > 0){
    cout << "Positive" << endl;
  } else if(a == 0 || (a <= 0 && b >= 0 ) || b == 0) {
    cout << "Zero" << endl;
  } else {
    int numOfNegatives = b - a + 1;
    if(numOfNegatives % 2 == 0) cout << "Positive" << endl;
    else cout << "Negative" << endl;
  }
}

Measured memory_bytes: 3524
//****** @mdazmat9 **********
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define UB upper_bound
#define LB lower_bound
#define BS binary_search
#define EB emplace_back
#define PB push_back
#define endl "\n"
#define MOD 1000000007
#define F first
#define S second
#define ALL(a) (a).begin(),(a).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
int fast_pow(int x, int y, int p);


void solve() {
    int n;cin>>n;
    for(int i=0;i<n;i++){
        int x;cin>>x;
        if(x%2==0){
            if(x%3!=0 && x%5!=0){
                cout<<"DENIED"<<endl;
                return;
            }
        }
    }
    cout<<"APPROVED"<<endl;

}

int32_t main() {
    IOS;
    int test = 1;
     //cin >> test;
    while (test--) {
        solve();
    }
    return 0;
}
int fast_pow(int x, int y, int p) {
    int res = 1;
    x = x % p;
    while (y > 0) {
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}

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

int n;
vector<int> a;
vector<ll> sum;

ll abc059c(int sign) {
  int i;
  ll ans = 0;

  sum[0] = a[0];

  if (sign > 0) {
    for (i = 0; i < n; i++) {

      if (i % 2 == 0 && sum[i] <= 0) {
        ans += abs(sum[i]) + 1;
        sum[i] = 1;
      }

      if (i % 2 == 1 && sum[i] >= 0) {
        ans += abs(sum[i]) + 1;
        sum[i] = -1;
      }

      if (i < n - 1) {
        sum[i + 1] = sum[i] + a[i + 1];
      }
    }

  } else if (sign < 0) {
    for (i = 0; i < n; i++) {

      if (i % 2 == 1 && sum[i] <= 0) {
        ans += abs(sum[i]) + 1;
        sum[i] = 1;
      }

      if (i % 2 == 0 && sum[i] >= 0) {
        ans += abs(sum[i]) + 1;
        sum[i] = -1;
      }

      if (i < n - 1) {
        sum[i + 1] = sum[i] + a[i + 1];
      }
    }

  } else {
    exit(1);
  }

  return ans;
}

void solve() {
  ll ans = min(abc059c(1), abc059c(-1));

  cout << ans << "\n";

  return;
}

int main() {
  int i;
  cin >> n;

  a.resize(n);
  sum.resize(n);
  for (i = 0; i < n; i++) {
    cin >> a[i];
  }

  solve();

  return 0;
}

Measured memory_bytes: 1408
inp = input().split()
WHxyr = []

for i in range(len(inp)):
    WHxyr.append(int(inp[i]))
               
W = WHxyr[0]
H = WHxyr[1]
x = WHxyr[2]
y = WHxyr[3]
r = WHxyr[4]

xtrue = r<=x and x<=(W-r) 
ytrue = r<=y and y<=(H-r)

if xtrue and ytrue:
                 print("Yes")
else:
                 print("No")



Measured memory_bytes: 5600
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a,b,c,k,ans;
    cin>>a>>b>>c>>k;
    if(a<k){
        ans=a;
        k-=a;
        k-=b;
        if(k>-1)
            cout<<ans-k<<endl;
        else
            cout<<ans<<endl;
    }
    else
        cout<<k<<endl;
    return 0;
}


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

int main() {
    int N, a, b, ans = 0;
    cin >> N;
    for (int i = 0; i < N; ++i) {
        cin >> a >> b;
        ans += (b - a + 1);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
 
int main(){
  int a, b, c, d, e, k;
  cin >> a >> b >> c >> d >> e >> k;
  
  if(e-a>k){
    cout << ":(" <<endl;
  }
   
  else{
    cout << "Yay!" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <queue>

using namespace std;

int qsort_long_compare_ascend(const void* a, const void* b) {//long型
	long c = *(long*)a - *(long*)b;
	if (c > 0) { return 1; }
	else if (c < 0) { return -1; }
	return 0;
}
int qsort_long_compare_descend(const void* a, const void* b) {//long型
	long c = *(long*)b - *(long*)a;
	if (c > 0) { return 1; }
	else if (c < 0) { return -1; }
	return 0;
}
void ascendOrder(int size, long* array) {//昇順
	qsort(array, size, sizeof(long), qsort_long_compare_ascend);
}
void descendOrder(int size, long* array) {//降順
	qsort(array, size, sizeof(long), qsort_long_compare_descend);
}

class pairClass { // ペアのソート
public:
	pairClass() { key = 0, value = 0; }
	long key, value;
};
int qsort_int_compare_ascend(const void* a, const void* b) {//keyを見比べる
	long x = ((pairClass*)a)->key - ((pairClass*)b)->key;
	return (x > 0) ? 1 : ((x < 0) ? -1 : 0);
}
int qsort_int_compare_descend(const void* a, const void* b) {//keyを見比べる
	long x = ((pairClass*)b)->key - ((pairClass*)a)->key;
	return (x > 0) ? 1 : ((x < 0) ? -1 : 0);
}
void ascendOrder(int size, pairClass * array) {//昇順
	qsort(array, size, sizeof(pairClass), qsort_int_compare_ascend);
}
void descendOrder(int size, pairClass * array) {//降順
	qsort(array, size, sizeof(pairClass), qsort_int_compare_descend);
}

int main() {
	int N, M; cin >> N >> M;

	long* A = new long[N];
	long* B = new long[N];
	for (int i = 0; i < N; i++) {
		cin >> A[i];
		B[i] = 0;
	}

	ascendOrder(N, (long*)A);

	pairClass* P = new pairClass[M];
	for (int i = 0; i < M; i++) {
		cin >> P[i].value >> P[i].key;
	}

	descendOrder(M, (pairClass*)P);

	int k = 0;
	for (int i = 0; i < M; i++) {
		for (int j = 0; j < P[i].value; j++) {
			B[k] = P[i].key;
			k++;
			if (k == N) { break; }
		}
		if (k == N) { break; }
	}

	for (int i = 0; i < N; i++) {
		A[i] = max(A[i], B[i]);
	}

	long sum = 0;
	for (int i = 0; i < N; i++) {
		sum += A[i];
	}
	
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 4980
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <random>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include <fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;

using ll = long long;
using vll = vector<long long>;
using pll = pair<long long, long long>;
#define rep(i,n) for(long long i(0);(i)<(n);(i)++)


void solve(long long N){
    ll h, n, w, tmp;
    for(n = 1; n<= 3500; n++){
        for(w = 1; w <= 3500; w++){
            tmp = 4*n*w - w*N - n*N ;
            if(tmp <= 0) continue;
            if(  (n*w*N) %tmp   == 0){
                cout << (n*w*N)/tmp << " "<< n << " " << w << endl;
                return;
            }
        }
    }
}

int main(){
    long long N;
    scanf("%lld",&N);
    solve(N);
    return 0;
}


Measured memory_bytes: 256
//Bismillahir Rahmanir Rahim
#include<bits/stdc++.h>
#define ll              long long
#define ull             unsigned long long
#define pb              push_back
#define fastread()      (ios_base:: sync_with_stdio(false),cin.tie(NULL));
using namespace std;
int main()
{
    fastread();
    int n;
    int ac = 0,wa = 0,tle = 0,re = 0;
    cin>>n;
    while(n--){
        string s;
        cin>>s;

        if(s[0] == 'A' && s[1] == 'C')ac++;
        else if(s[0] == 'W' && s[1] == 'A')wa++;
        else if(s[0] == 'T' && s[1] == 'L' && s[2] == 'E')tle++;
        else if(s[0] == 'R' && s[1] == 'E')re++;
    }
    cout<<"AC x "<<ac<<endl;
    cout<<"WA x "<<wa<<endl;
    cout<<"TLE x "<<tle<<endl;
    cout<<"RE x "<<re<<endl;

    return 0;
}

Measured memory_bytes: 3656
#!/usr/bin/env python3
# N,M = map(int,sys.stdin.readline().split())
# a = tuple(map(int,sys.stdin.readline().split())) # single line with multi param
# a = tuple(int(sys.stdin.readline()) for _ in range(N)) # multi line with single param
# a = tuple(tuple(map(int,sys.stdin.readline().rstrip().split())) for _ in range(N)) # multi line with multi param
# s = sys.stdin.readline().rstrip()
# N = int(sys.stdin.readline())
# INF = float("inf")
import sys
A,B,C = map(int,sys.stdin.readline().split())
K = int(sys.stdin.readline())

for i in range(K):
    for j in range(K+1-i):
        #print(i,j)
        if A < 2**i*B and 2**i*B < 2**j*C:
            print("Yes")
            exit()
print("No")
#print(i,2**i*B,j,2**j*C)


Measured memory_bytes: 9152
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
int main() {
  ll n, k;
  cin>>n>>k;
  ll m;
  bool d=true;
  n=n%k;
  while(d==true) {
    ll n2=n;
    n=max(n, k)-min(n, k);
    if(n2<=n) {
      cout << n2 << endl;
      d=false;
    }
    else {
    }
  }
}

Measured memory_bytes: 3652
# coding: utf-8
# Your code here!

def main():
    N = int(input())
    A = list(map(int,input().split()))
    
    if 0 in A:
        print(0)
        return
        
    ans = 1
    for i in range(N):
        ans *= A[i]
        if ans > 1000000000000000000:
            print(-1)
            return
    
    print(ans)

main()

Measured memory_bytes: 21640
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {

    public static void main(String[] args) {
        @SuppressWarnings("resource")
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        Set<String> set = new HashSet<>();
        for (int i = 0 ; i < s.length() ; i++) {
            set.add(s.substring(i, i+1));
        }
        System.out.println(set.size() == s.length() ? "yes" : "no");
    }

}

Measured memory_bytes: 23764
#include <iostream>
#include <cassert>
//#define NDEBUG
int main(void){
    using namespace std;
 
    static const int NUM_MIN = -1000;
    static const int NUM_MAX =  1000;
    int input_num1 = 0;
    int input_num2 = 0;
    cin >> input_num1;
    cin >> input_num2;
     
    assert(NUM_MIN <= input_num1 && input_num1 <= NUM_MAX); /* Precondition */
    assert(NUM_MIN <= input_num2 && input_num2 <= NUM_MAX); /* Precondition */

    /* Comparison */
    if(input_num1 < input_num2){
      cout << "a < b" << endl;
    }
    else if(input_num1 > input_num2){
      cout << "a > b" << endl;
    }
    else{
      cout << "a == b" << endl;
    }

    return 0;
}

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

#define ll long long
#define ar array

const int mxN=1e7;
int n, c[mxN+1];

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

	cin >> n;
	for(int i=1; i<=n; ++i)
		for(int j=0; (j+=i)<=n; )
			++c[j];
	ll ans=0;
	for(int i=1; i<=n; ++i)
		ans+=(ll)i*c[i];
	cout << ans;
}


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

// fはレベルNを下からX枚食べた時に食べるパティの量を返す
long f(int N, long X, long a[], long p[]){
    if(N == 0){
        return X <= 0 ? 0 : 1;
    } 
    else if (X <= 1 + a[N-1])
    {
        return f(N-1, X-1, a, p);
    }
    else
    {
        return p[N-1] + 1 + f(N-1, X -a[N-1] -2, a, p);
    }
}

int main(void){
    int N;
    long X;
    cin >> N >> X;
    long a[N+1], p[N+1];
    a[0] = 1, p[0] = 1;
    for(int i=1; i<N+1; i++){
        a[i] = 2 * a[i-1] + 3;
        p[i] = 2 * p[i-1] + 1;
    }
    cout << f(N, X, a, p) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//do {
//    print(v);
//  } while (std::next_permutation(v.begin(), v.end()));


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

	string s;
	cin >> s;
	if (s.size() % 2 == 0 ^ s[0] == s[s.size() - 1])
		cout << "Second" << endl;
	else
		cout << "First" << endl;
	return 0;
}

Measured memory_bytes: 512
S = input()
T = input()

ans = ""
for i in range(len(S)-len(T)+1):
    flag = True
    for s,t in zip(S[i:],T):
        if s != "?" and s != t:
            flag = False
            break
    if flag:
        ans = S[:i]+T+S[i+len(T):]
if ans != "":
    print(ans.replace("?","a"))
else:
    print("UNRESTORABLE")


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
  int main()
 {
     int i,j,c,x,y;
     string s1,s2,s;
     cin>>s1>>s2;
     int dp[s2.size()+1][s1.size()+1];
     memset(dp,0,sizeof(dp));
     for(i=1;i<=s2.size();i++)
     {
         for(j=1;j<=s1.size();j++)
         {
             if(s1[j-1]==s2[i-1])
             {
                 dp[i][j]=1+dp[i-1][j-1];
             }
             else
             {
                 dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
             }
         }
     }
     x=s1.size();
     y=s2.size();
     while(dp[y][x]!=0)
     {
         c=0;
         for(j=x;j>0;j--)
         {
             if(dp[y][j]==dp[y][j-1])
             {
                 continue;
             }
             else if(dp[y][j]==dp[y-1][j])
             {
                 y--;
                 j++;
             }
             else if(dp[y][j]==dp[y-1][j-1]+1)
             {
                 x=j-1;
                 y=y-1;
                 c++;
                 s=s1[j-1]+s;
             }
         }
         if(c==0)
         {
             x=s1.size();
             y--;
         }
     }
     cout<<s;
     return 0;
 }

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

#define BOOST ios_base::sync_with_stdio(false) , cin.tie(NULL) , cout.tie(NULL)

int main()
{
    BOOST;

    string s1,s2,s3;
    cin>>s1>>s2;
    s3 = s2.substr(0,s2.size()-1);
    if(s1==s3 && s1.size()==s2.size()-1){cout<<"Yes"<<endl;}
    else cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 3616