akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"

using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
	REP(i, v.size()) { if (i)os << " "; os << v[i]; }return os;
}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
	REP(i, v.size()) { if (i)os << endl; os << v[i]; }return os;
}

const ll INF = LLONG_MAX;
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

#define int long long

inline void my_io() {

	std::ios::sync_with_stdio(false);

	std::cin.tie(0);

	cout << fixed << setprecision(16);

	//cout << setprecision(10) << scientific << ans << endl;
}

signed main() {
	ll n, a;

	cin >> n;

	double ans = 0.0;

	REP(i, n) {
		cin >> a;
		ans += 1.0 / (double)a;
	}

	ans = 1.0 / ans;

	cout << setprecision(10) << scientific << ans << endl;
}

Measured memory_bytes: 256
import copy
H, W, K = map(int, input().split())

C = [list(input()) for i in range(H)]
# cumsumH = []
# cumsumW = []

# for h in range(H):
#     cumsumH += [sum([c == '#' for c in C[h]])]
# for w in range(W):
#     cumsumW += [sum([C[i][w] == '#' for i in range(H)])]
ans = 0
# print(cumsumH)
# print(cumsumW)

for h in range(2**H):
    for w in range(2**W):
        CC = copy.deepcopy(C)
        tmp = 0
        for i in range(H):
            if (h >> i) & 1:
                for j in range(W):
                    CC[i][j] = 'R'
        for i in range(W):
            if (w >> i) & 1:
                for j in range(H):
                    CC[j][i] = 'R'
        for i in range(H):
            for j in range(W):
                if CC[i][j] == '#':
                    tmp += 1
        if tmp == K:
            ans += 1
            # print(h, w)

print(ans)


Measured memory_bytes: 76840
#include<bits/stdc++.h>
#define ll long long
#define eps 1e-8
#define INF 0x3f3f3f3f
#define pb push_back
#define endl '\n'
#define IO ios::sync_with_stdio(false)
using namespace std;
const ll maxn = 1e6 + 5;
const ll mod = 1e9 + 7;
int a,b,c,n,m,t,k,num[maxn];
string str;
int main(){
    char c;
    cin >> c;
    if(c >= 'A' && c <= 'Z')
        cout << 'A' << endl;
    else
        cout << "a" << endl;
    return 0;
}


Measured memory_bytes: 3632
use std::io;

fn read_line()-> String {
    let mut s = String::new();
    let _ = io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn dev2(i: i32,c:i32) -> i32 {
	if i % 2 != 0 {
		c
	}else{
		dev2(i/2,c+1)
	}
}

fn main() {
	let N = read_line().parse::<i32>().unwrap();
	let mut c:i32 = 0;
	let mut d:i32 = 0;
	let mut r:i32 = 1;
	for i in 1..(N+1) {
		c = dev2(i,0);
		if d <= c {
			r = i;
			d = c;
		}
	}
	println!("{}",r);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define loop(i,n) rep(i,0,n)
using namespace std;
using ll = long long;
int main(){
    int h,w,a,b;
    cin >> h >> w >> a >> b;
    loop(i,h){
        loop(j,w){
            if((i<b)==(j<a))cout << "0";
            else cout << "1";
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int m; cin >> m;
  cout << 48-m << "\n";
  return 0;
}


Measured memory_bytes: 3592
SA = input()
SB = input()
SC = input()

na = len(SA)
nb = len(SB)
nc = len(SC)

a = b = c = 0

target = SA[a]
a += 1
while True:
    if target == 'a':
        if a < na:
            target = SA[a]
        a += 1
    elif target == 'b':
        if b < nb:
            target = SB[b]
        b += 1
    elif target == 'c' :
        if c < nc:
            target = SC[c]
        c += 1
    
    if a == na + 1:
        ans = 'A'
        break
    if b == nb + 1:
        ans = 'B'
        break
    if c == nc + 1:
        ans = 'C'
        break

print(ans)

Measured memory_bytes: 3064
S = input()
K = int(input())

N = len(S)
T = list(S)
for i in range(N - 1):
    if T[i] == 'a':
        continue
    if K >= ord('z') - ord(T[i]) + 1:
        K -= ord('z') - ord(T[i]) + 1
        T[i] = 'a'

T[N - 1] = chr(ord('a') + (ord(T[N - 1]) - ord('a') + K) % 26)
print("".join(T))

Measured memory_bytes: 4212
h,w=list(map(int,input().split()))
a=[]
for i in range(h):
    a1=list(input())
    a.append(a1)
print('#'*(w+2))
for i in range(h):
    print('#',end="")
    for j in range(w):
        print(a[i][j],end="")
    print('#',end="")
    print("")
print('#'*(w+2))

Measured memory_bytes: 4596
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <deque>
#include <string.h>
#include <math.h>
typedef long long ll;
#define INF			100000
#define MAX(x, y)	(((x) > (y))? (x) : (y))
#define MIN(x, y)	(((x) < (y))? (x) : (y))
#define ABS(x)		(((x) < 0)? (-1*(x)) : (x))
#define SWAP
#define REP(i,x,y)	for (int (i)=(x);(i)<(y);(i)++)
#define REP_(i,x,y)	for ((i)=(x);(i)<(y);(i)++)
#define MEMCLR(X)	memset((X),0,sizeof((X)))

using namespace std;
typedef pair<int, int> Point;
typedef vector<vector<Point>> Graph;

ll A,B;
int Q;

int main() {
	
	cin >> Q;

	while (Q--) {
	 	cin >> A >> B;
		
		if (A>B) swap(A,B);
		
		if (A==B || A+1==B) cout << 2*(A-1) << endl;
		else {
			ll C = floor(sqrt(A*B));
			if (C*C==A*B) C--;
			if (C*(C+1)>=A*B) cout << (2*C-2) << endl;
			else cout << (2*C-1) << endl;
		}
	}
	
	return 0;
}


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

int main(){
    int N,A,f;
    cin >> N;
    f = 0;
    for(int i = 0;i < N;i++){
        cin >> A;
        if(A%2 == 0){
            if(A%3 != 0 && A%5 != 0){
                f = 1;
                break;
            }
        }
    }
    if(f == 0){
        cout << "APPROVED" << endl;
    }
    else{
        cout << "DENIED" << endl;
    }

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,k,val,pos;
	cin >> n >> k;	
	for(int i = 0;i<n;i++) {
		cin >> val;
		if(val == 1)
			pos = i;
	}
	
	int cont = 0; 
	int atual = pos;
	
	while(atual >0){
		atual -=(k-1);
		cont++;
	}
	
	atual = -atual;
	atual+=pos;
	
	while(atual < n-1){
		atual +=(k-1); 
		cont++;
	}
	
	
	cout<<cont<<endl;

}

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

int main()
{
  int a, b, c;
  cin >> a >> b >> c;

  if(a + b < c) {
    cout << (a + b + b + 1) << endl;
  } else {
    cout << (c + b) << endl;
  }

  return 0;
}


Measured memory_bytes: 256
N,T=gets.strip.split(' ').map(&:to_i)
c=[]
t=[]
anc=1001
N.times{|i|
    c[i],t[i]=gets.strip.split(' ').map(&:to_i)
    if c[i]<anc&&t[i]<=T
        anc=c[i]
        end
}
if anc==1001
    puts "TLE"
    else
    puts anc
    end

Measured memory_bytes: 3836
#include <algorithm>
#include <cstdio>
using namespace std;

int dp[101][10001];

int main(){
    int N,W;
    int v[1001],w[1001];
    scanf("%d%d",&N,&W);
    for(int i = 0;i < N;i++){
        scanf("%d%d",v+i,w+i);
    }
    for(int j = 0;j < W;j++){
        dp[0][j] = 0;
    }
    for(int i = 1;i <= N;i++){
        for(int j = 0;j <= W;j++){
            if(j - w[i-1] < 0){
                dp[i][j] = dp[i-1][j];
            }
            else{
                dp[i][j] = max(dp[i-1][j],dp[i-1][j-w[i-1]] + v[i-1]);
            }
        }
    }
    printf("%d\n",dp[N][W]);
    return 0;
}


Measured memory_bytes: 6684
#include <bits/stdc++.h>
using namespace std;
long long n,a,b;
long long mo[200001];
long long x[200001];
bool check(long long mid){
  long long howmany=0;
  for(int i=0;i<n;i++){
    x[i]=mo[i];
    x[i]-=b*mid;
    howmany+=max((long long)0,(long long)(x[i]+(a-b)-1)/(a-b));}
  return howmany<=mid;
}
int main(){
  cin>>n>>a>>b;
  for(int i=0;i<n;i++)
    cin>>mo[i];
  long long lb=0,ub=1e9+100;
  while(lb<=ub){
    long long mid=(lb+ub)/2;
    if(!check(mid))
      lb=mid+1;
    else
      ub=mid-1;}
  cout<<lb;
  return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int main(){
    unsigned long long N,m=0,a=0,r=0,c=0,h=0;
    cin >> N;
    vector<string> S(N);
    for(int i = 0;i < N;i ++){
        cin >> S[i];
        if(S[i][0]=='M') m++;
        if(S[i][0]=='A') a++;
        if(S[i][0]=='R') r++;
        if(S[i][0]=='C') c++;
        if(S[i][0]=='H') h++;
    }
    cout << m*a*r+m*a*c+m*a*h+m*r*c+m*r*h+
            m*c*h+a*r*c+a*r*h+a*c*h+r*c*h << endl;
    
    return 0;
}

Measured memory_bytes: 6144
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<vector<int> > Graph;
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; }

int main(){
    int n;
    cin >> n;
    int field[2][110];
    rep(i,2){
        rep(j,n){
            cin >> field[i][j];
        }
    }
    int ans = 0;
    rep(i,n){
        int s = 0;
        rep(j,i+1){
            s += field[0][j];
        }
        for(int k = i;k<n;k++){
            s += field[1][k];
        }
        ans = max(ans,s);
    }
    cout<<ans << endl;
    return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include<stdio.h>
int main() {
	int h, w,i,j;
	while (1) {
		scanf("%d%d", &h, &w);
		if (h + w == 0)break;
		for (i=0; i<h; ++i) {
			for (j = 0; j < w; ++j) {
				if(!((i+j)%2))putchar('#');
				else putchar('.');
			}
			putchar('\n');
		}
		putchar('\n');
	}
		return 0;
}

Measured memory_bytes: 572
import java.util.*;
import static java.lang.System.*;
import java.io.*;
import java.math.*;

public class Main {

	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);
		int a = sc.nextInt();
		int b = sc.nextInt();
		if ( a != 1 && b != 1){
			out.println(1);
		}
		else if (a != 2 && b != 2)
			out.println(2);
		else
			out.println(3);
		

		out.close();
	}

static class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}
}

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

int main(){
	int E,Y;
	cin>>E>>Y;
	int X=Y-1867;
	switch(E){
		case 0:
				if(X<=44){
					cout<<"M"<<X<<endl;
				}else if(X>121){
					cout<<"H"<<X-121<<endl;
				}else{
					if(X<59){
						cout<<"T"<<X-44<<endl;
					}else{
						cout<<"S"<<X-58<<endl;
					}
				}
				break;
		case 1:
				cout<<1867+Y<<endl;
				break;
		case 2:
				cout<<1911+Y<<endl;
				break;
		case 3:
				cout<<1925+Y<<endl;
				break;
		case 4:
				cout<<1988+Y<<endl;
				break;
	}
	return 0;
}

Measured memory_bytes: 3060
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
inline void add(long long &x, long long y) {
  x += y;
  if (x >= mod) x -= mod;
}
signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  int n, x;
  cin >> n >> x;
  vector<int> in(n);
  for (int i = 0; i < n; i++) {
    cin >> in[i];
  }
  sort(in.rbegin(), in.rend());
  vector<vector<long long>> dp(n + 1, vector<long long>(x + 1));
  dp[0][x] = 1;
  for (int i = 0; i < n; i++) {
    for (int d = 0; d <= x; d++) {
      add(dp[i + 1][d % in[i]], dp[i][d]);
      add(dp[i + 1][d], dp[i][d] * (n - 1 - i) % mod);
    }
  }
  long long ans = 0;
  for (int d = 0; d <= x; d++) {
    add(ans, d * dp[n][d] % mod);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 158592
N, M, X,=map(int, input().rstrip().split()) #input parameters
A=list(map(int, input().rstrip().split())) #input parameters
work1=[]
work2=[]
for i in range(len(A)):
    if A[i]<X:
        work1.append(A[i])
    else:
        work2.append(A[i])
print(min(len(work1),len(work2)))

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

int main() {
	int N;

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

	vector<long long> B( N );
	long long ans = 0;
	int cnt = 0;
	for( int i = 0; i < N; i++ ) {
		if( A[i] < 0 ) {
			B[i] = -A[i];
			cnt++;
		}
		else {
			B[i] = A[i];
		}
		ans += B[i];
	}
	if( cnt % 2 ) {
		long long mi = *min_element( B.begin(), B.end() );
		ans -= mi * 2;
	}

	cout << ans << endl;
 
	return 0;
}

Measured memory_bytes: 1792
while 1:
    m=n=int(input())
    if n==0:break
    i=2
    a=1
    while i*i<=n:
        c=0
        while n%i==0:
            n//=i
            c+=1
        if c:
            a*=(i**(c+1)-1)//(i-1)
        i+=1
    if n>1:
        a*=1+n
    if a==2*m:
        print("perfect number")
    elif a<2*m:
        print("deficient number")
    else:
        print("abundant number")


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

vector <int> dp(100005);

// int solve(vector <int> arr,int i)
// {

// 	if(i==2)return arr[2]-arr[1];
// 	if(i==3)return arr[3]-arr[1];
// 	if(dp[i]!=-1)return dp[i];
// 	return dp[i]=min(   ( abs(arr[i]-arr[i-1])+solve(arr,(i-1))) , (abs(arr[i]-arr[i-2])+solve(arr,(i-2)) )   );
// 	for(int i=)
// }

int main()
{
	int n;
	cin>>n;
	vector <int> arr(n+1);
	for(int i=1;i<=n;i++)
	{
		cin>>arr[i];
	}
	
	dp[2]=abs(arr[2]-arr[1]);
	dp[3]=abs(arr[3]-arr[1]);
		
	for(int i=4;i<=n;i++)
	{
		dp[i]=min(   ( abs(arr[i]-arr[i-1])+dp[i-1]) , (abs(arr[i]-arr[i-2])+dp[i-2]) )   ;
	}


	cout<<dp[n]<<endl;
	return 0;
}


Measured memory_bytes: 3968
#include<bits/stdc++.h>
using namespace std;
const int N=4005,P=998244353;
int n,k,fac[N],ifac[N],s[N];
int pw(int a,int b){int r=1;for(;b;b>>=1,a=1ll*a*a%P)if(b&1)r=1ll*r*a%P;return r;}
int C(int a,int b){return a<b?0:1ll*fac[a]*ifac[b]%P*ifac[a-b]%P;}
int main()
{
	scanf("%d%d",&k,&n);fac[0]=ifac[0]=1;
	for(int i=1;i<=n+k;i++)fac[i]=1ll*fac[i-1]*i%P,ifac[i]=pw(fac[i],P-2);
	for(int i=1;i<=k;i++)s[i+1]++,s[i+k+1]--;
	for(int i=1;i<=k+k;i++)s[i]+=s[i-1];
	for(int i=2;i<=k+k;i++)
	{
		int c=(s[i]+1)/2,ans=0;
		for(int j=0,d=1;j<=c&&j+j<=n;j++,d=P-d)ans=(ans+1ll*d*C(c,j)%P*C(n-2*j+k-1,k-1))%P;
		printf("%d\n",ans);
	}
	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
    ll H, W, N; cin >> H >> W >> N;
    map<pair<ll, ll>, ll> mp;

    for(int i=0; i<N; ++i){
        ll a, b; cin >> a >> b;
        for(int j=0; j<3; ++j){
            for(int k=0; k<3; ++k){
                if(0 < a-j && a-j <H-1 && 0 < b-k && b-k < W-1) mp[make_pair(a-j, b-k)]++;
            }
        }
    }

    vector<ll> ans(10, 0);
    ans[0] = (H-2)*(W-2);
    for(auto itr=mp.begin(); itr!=mp.end(); itr++){
        ++ans[itr->second];
        --ans[0];
    }

    for(int i=0; i<10; ++i) cout << ans[i] << endl;
}

Measured memory_bytes: 56448
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <cstring>
#define ARRAY_LEN(array) (sizeof(array) / sizeof(array[0]))
using namespace std;
typedef long long ll;
 
int main() {
  int N, M; cin >> N >> M;
  vector<vector<int>> bridge(N, vector<int>());
  for (int i=0; i<M; i++) {
    int a, b; cin >> a >> b; a--; b--;
    bridge[a].push_back(b); bridge[b].push_back(a);
  }

  bool flg = true;
  int result = 0;
  while (flg) {
    flg = false;
    for (int i=0; i<M; i++) {
      if (bridge[i].size() == 1) {
        result++;
        int j = bridge[i][0];
        bridge[i].erase(remove(bridge[i].begin(), bridge[i].end(), j), bridge[i].end());
        bridge[j].erase(remove(bridge[j].begin(), bridge[j].end(), i), bridge[j].end());
        flg = true;
      }
    }
  }
  cout << result << endl;
  return 0;
}

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

using namespace std;

int main(void) {
  int score_T = 0;
  int score_H = 0;
  string card_T = "";
  string card_H = "";
  int turn = 0;
  cin >> turn;
  for(int i = 0; i < turn; i++){
    cin >> card_T;
    cin >> card_H;
    if(card_T == card_H){
      score_T++;
      score_H++;
    }
    else if(card_T > card_H){
      score_T += 3;
    }
    else{
      score_H += 3;
    }
  }
  cout << score_T << " " << score_H << endl;
  return 0;
}



Measured memory_bytes: 3228
fun main(args: Array<String>) {
    abc143d()
}

fun abc143d() {
    val n = readLine()!!.toInt()
    val lines = readLine()!!.split(" ").map { it.toInt() }
        .sorted().toIntArray()

    var answer = 0
    for (bi in 0 until n) {
        var right = bi + 1
        for (ai in 0 until bi) {
            while (right < n && lines[right] < lines[ai] + lines[bi]) right++
            val left = bi + 1
            answer += right - left
        }
    }

    println(answer)
}


Measured memory_bytes: 35944
import java.util.*;
class Main{
  public static void main(String[] args){
    Scanner scan=new Scanner(System.in);
    long A=scan.nextInt();
    long B=scan.nextInt();
    long K=scan.nextInt();
    for(int i=0;i<K;i++){
      if(i%2==0){
        if(A%2!=0){
          A--;
        }
          B+=A/2;
          A/=2;
      }
      else{
        if(B%2!=0){
          B--;
        }
          A+=B/2;
          B/=2;
      }
    }
    System.out.println(A+" "+B);
  }
}

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

int mp[15000000];
int Hash(string s) {
	int cnt = 0, t = 1;
	rep(i, s.size()) {
		cnt += s[i]*t;
		t *= 3;
	}
	return cnt;
}
int main() {
	int n, m;
	while (scanf("%d%d", &n, &m), n) {
		memset(mp, 0, sizeof(mp));
		string in(n, 0);
		rep(i, 3) {
			int len; scanf("%d", &len);
			rep(j, len) {
				int a; scanf("%d", &a);
				in[--a] = i;
			}
		}
		queue<string>que;
		mp[Hash(in)] = 1;
		que.push(in);
		while (!que.empty()) {
			string u = que.front(); que.pop();
			if (u == string(n, 0) || u == string(n, 2)) {
				printf("%d\n", mp[Hash(u)] - 1);
				goto g;
			}
			if (mp[Hash(u)] > m)continue;
			rep(k, 2)rep(t, 2) {
				int i, j;
				if (t) { i = k, j = k + 1; }
				else { i = k + 1; j = k; }
				int fi = u.rfind(i, n - 1), fj = u.rfind(j, n - 1);
				if (fi == -1 || fi < fj)continue;
				string v = u;
				v[fi] = j;
				if (!mp[Hash(v)]) {
					mp[Hash(v)] = mp[Hash(u)] + 1;
					que.push(v);
				}
			}
		}
		puts("-1");
	g:;
	}
}

Measured memory_bytes: 61860
#include <bits/stdc++.h>
#define rep(i, a) for(int i = 0; i < a; i++)
#define all(v) v.begin(), v.end()
#define dcout cout << fixed << setprecision(15)
#define arep(i, a) for(auto i : a)
#define F first
#define S second
#define VE vector<int>
#define pb(x) push_back(x)
#define MOD 1000000007
#define INF 10000000000
#define int long long
#define KETA(n) floor(log10(n) + 1)
using namespace std;
signed main() {
    string s, t;
    cin >> s >> t;
    t.pop_back();
    if(s == t)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n,m; cin>>n>>m;
    if(n>=m){cout<<0<<endl; return 0;}
    vector<int> x(m);
    for(int i=0; i<m; i++) cin>>x.at(i);
    sort(x.begin(),x.end());
    vector<int> l(m-1);
    for(int i=0; i<m-1; i++) l.at(i)=x.at(i+1)-x.at(i);
    sort(l.begin(),l.end());
    int ans=0;
    for(int i=0; i<m-n; i++) ans+=l.at(i);
    cout<<ans<<endl;
}


Measured memory_bytes: 1024
N = int(input())
A = [int(input()) for _ in range(N)]

A_sort = sorted(A, reverse=True)
A_1st = A_sort[0]
A_2nd = A_sort[1]

for a in A:
    if a == A_1st:
        print(A_2nd)
    else:
        print(A_1st)

Measured memory_bytes: 14108
#include <iostream>
#include <stdio.h>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <queue>
#include <stack>
#include <functional>
#include <list>
#include <utility>
#include <map>
#include <vector>
using namespace std;

typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,x) for(int i=1;i<=x;i++)
#define rrep(i,x) for(int i=x-1;i>=0;i--)
#define rrep1(i,x) for(int i=x;i>0;i--)
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define mp1(a,b,c) P1(a,P(b,c))
#define get_arsize(a) (sizeof(a)/sizeof(a[0]))
const ll mod = 1000000007;
const double eps = 1e-10;
const int MAX = 200000;

int main() {
  // three patterns
  char c;
  // 今回見ていたあまりが*10されて、次の1桁目がくっついて、13で割ったあまりの場合の数になる。
  // "非決定性有限オートマトンの場合は、ノードの長さだけの配列を用意しておいて、各配列の要素がそのターンにその配列を踏む場合の数"
  // 2次元配列が使える(高々数MB)
  int dp[13] = {};
  int tmp[13] = {};
  // 読み取り0文字目のとき、0とみなす。
  // 13で割ったあまりが0となる場合の数が1で、他は0。
  dp[0] = 1;
  int i = 0;
  while (true) {
    c = cin.get();
    if (c == '\n') {
      cout << dp[5] << endl;
      return 0;
    }
    rep(k,13) {
      tmp[k] = dp[k];
      dp[k] = 0;
    }
    if (c =='?') { // 現在のkの状態、0~12が考えられる状態から、j(0〜9)が入ってきたときの遷移をする。
      rep(k,13) {
        rep(j,10) {
          dp[(k * 10 + j) % 13] += tmp[k];
          dp[(k * 10 + j) % 13] %= mod;
        }
      }
    } else { // 現在のkの状態、0~12が考えられる状態から、numが入ってきたときの遷移をする。
      int num = c - '0';
      rep(k,13) {
        dp[(k * 10 + num) % 13] += tmp[k];
        dp[(k * 10 + num) % 13] %= mod;
      }
    }
    i++;
  }
  return 0;
}

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

using namespace std;
using ll = long long int;

ll calc(int a, int n){
  ll temp = 1;
  for(int i = 0;i < n;i++){
    temp *= a;
  }    
    return temp;
}

int main(void){
  int a, b;
  cin >> a >> b;
  ll ans = 1;
  
  ans *= b;
  ans *= calc(b-1, a-1);
  
  cout << ans << endl;
  
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<math.h>
#include<set>
#include<vector>
#include<map>
#include<functional>
#include<iomanip>
#include<queue>
#include<random>
#include<numeric>
#include<string>
#include<cstring>
typedef long long ll;
typedef long double ld;
using namespace std;
ll dx[] = { 0,0,1,-1 };
ll dy[] = { 1,-1,0,0 };

ll gcd(ll a, ll b) {
	if (a<b) { return gcd(b, a); }
	else if (a%b) { return gcd(b, a%b); }
	else { return b; }
}
int main() {
	ll A, B, C;
	cin >> A >> B >> C;
  	string ans="NO";
	for(ll i=1; i<=100000; i++){
      if(A*i%B==C)
        ans="YES";
    }
  cout<<ans<<endl;
}







Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10 ** 7)

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N, D, A = lr()
XH = [lr() for _ in range(N)]
XH.sort()

over = [N] * N # over[i]はi番目のモンスターを攻撃した時影響のないモンスターの最小値（最大はNで対象なし）
cur = 1
for i in range(N):
    while cur < N and XH[i][0] + D + D >= XH[cur][0]:
        cur += 1
    over[i] = cur

damage = 0 # 今までの累計のダメージ数　(影響のないダメージは引く)
reset = [0] * (N+1) # これ以降関係のないダメージ
answer = 0
for i in range(N):
    x, h = XH[i]
    damage -= reset[i]
    h -= damage
    if h > 0:
        time = (h+A-1)//A
        answer += time
        damage += A * time
        reset[over[i]] += A * time

print(answer)


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

#define ll long long int
#define f(i,g,n) for(int i=g;i<=n;i++)

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

	ll n,res=0;
	cin>>n;
	ll A[n]={0},B[n-1];
	f(i,0,n-2)
		cin>>B[i];
	A[0] = B[0];
	f(i,0,n-3)
		A[i+1] = min(B[i],B[i+1]);
	A[n-1] = B[n-2];
	f(i,0,n-1)
		res += A[i];
	cout<<res<<"\n";

	return 0;
}

Measured memory_bytes: 256
#include <set>
#include <map>
#include <queue>
#include <ctime>
#include <cmath>
#include <cstdio>
#include <vector>
#include <string>
#include <cctype>
#include <bitset>
#include <cstring>
#include <cstdlib>
#include <utility>
#include <iostream>
#include <algorithm>
#define REP(i,a,b) for(int i=(a);i<=(b);i++)
#define PER(i,a,b) for(int i=(a);i>=(b);i--)
#define RVC(i,S) for(int i=0;i<(S).size();i++)
#define RAL(i,u) for(int i=fr[u];i!=-1;i=e[i].next)
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;

template<class T> inline
void read(T& num) {
    bool start=false,neg=false;
    char c;
    num=0;
    while((c=getchar())!=EOF) {
        if(c=='-') start=neg=true;
        else if(c>='0' && c<='9') {
            start=true;
            num=num*10+c-'0';
        } else if(start) break;
    }
    if(neg) num=-num;
}
/*============ Header Template ============*/

int f[5005][5005];
int g[5005];
int ai[5005];

int main() {
    int n,m;
    cin >> n >> m;
    REP(i,1,n) cin >> ai[i],ai[i]=min(ai[i],m);
    f[1][0]=1;
    REP(i,2,n)
    {
        memcpy(f[i],f[i-1],sizeof(f[i-1]));
        REP(j,ai[i-1],m) f[i][j]|=f[i-1][j-ai[i-1]];
    }
    g[0]=1;int cnt=0;
    PER(i,n,1)
    {
        if(i<n)
        {
            PER(j,m,ai[i+1]) g[j]|=g[j-ai[i+1]];
        }
        int ps=m-1, fl=0;
        REP(j,0,m-1) if(f[i][j])
        {
            while(ps && (!g[ps] || j+ps>=m)) ps--;
            if(ps>=0 && g[ps] && j+ps<m && j+ps>=m-ai[i]) fl=1;
        } cnt+=fl;
    }
    printf("%d\n",n-cnt);
}


Measured memory_bytes: 98048
import java.util.*;

public class Main {

    public static void main(String[] args) {
	    // write your code here
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        ArrayList<Integer> last = new ArrayList<>();

        Parent:for(int i = 0; i < n; i++) {
            int k = sc.nextInt();
            ArrayList<Integer> list = new ArrayList<>();
            for(int index = 0; index < k; index++) {
                if (i == 0) {
                    last.add(sc.nextInt());
                } else {
                    list.add(sc.nextInt());
                    if (index == k - 1) {
                        ArrayList<Integer> mastered = new ArrayList<>();
                        for (int inner = 0; inner < last.size(); inner++) {
                            int value = last.get(inner);
                            if (list.contains(value)) {
                                mastered.add(value);
                            }
                        }
                        last = mastered;
                        if (last.size() == 0) {
                            break Parent;
                        }
                    }
                }
            }
        }

        // 出力
        System.out.println(last.size());
    }
}

Measured memory_bytes: 23892
#include <bits/stdc++.h>
#include <string.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for(int i = m; i < n; i++) 
#define mod 1000000007
#define pi 3.1415926535
typedef long long ll;


int main(){
    int N;
    cin>>N;
    vector<int>a(N);
    int sum=0;
    rep(i,N){
        cin>>a[i];
        sum+=a[i];
    }
    double mi=100;
    int ans;
    double avg=(double)sum/N;
    rep(i,N){
        if(fabs((double)a[i]-avg)<mi){
            mi=fabs((double)a[i]-avg);
            ans=i;
        }
    }
    cout<<ans<<endl;
    return 0;
}

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

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


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

int main() {
	int a,b;
	long int ans;
	cin>>a>>b;
            if(b<10)
              {
                 ans=a*10+b;
              }
            else if(b==100)
              ans=a*1000+b;
            else
               ans=a*100+b;
            int x=sqrt(ans);   
            if(x*1l*x==ans)
               cout<<"Yes";
            else
              cout<<"No";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define N 801
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> PP;
int h,w;
string mp[N];

struct dat{
  int y,x,K1,K2,cost;
  bool operator < (const dat &A)const{
    if(cost!=A.cost) return cost>A.cost;
    if(A.K1!=K1) return K1<A.K1;
    return K2<A.K2;
  }
};

int dx[] ={0,0,1,-1};
int dy[] ={1,-1,0,0};
PP D[N][N];
bool used[N][N];
int bfs(int y,int x,int sK){

  for(int i=0;i<N;i++)
    for(int j=0;j<N;j++) D[i][j] = PP(1e9,P(1e9,1e9));
  
  priority_queue<dat>Q;
  Q.push((dat){y,x,sK,0,1});  
  D[y][x] = PP(1,P(-sK,0));

  while(!Q.empty()){
    dat t = Q.top();Q.pop();
    y = t.y;
    x = t.x;
    int K1 = t.K1;
    int K2 = t.K2;
    int cost = t.cost;
    if(used[y][x] )continue;
    used[y][x] = 1;
    if(D[y][x] < PP(cost,P(-K1,-K2)))continue;
    //cout<<y<<" "<<x<<" "<<K1<<" "<<K2<<" "<<cost<<endl;
    
    for(int i=0;i<4;i++){
      int nx = x+dx[i];
      int ny = y+dy[i];
      int nK1 = K1-1;
      int nK2 = K2;
      int ncost = cost;
      if(nx<0||ny<0||nx>=w||ny>=h){return cost;}
      if(nK1 <  0) ncost++,nK1 = sK-1,nK2 += sK;
      if(mp[ny][nx] == '#') nK2--;
      if(nK2<0) nK1 = nK2 = sK-1,ncost+=2 - (cost==1);
      PP tmp = PP(ncost,P(-nK1,-nK2));
      if(D[ny][nx]<= tmp)continue;
      Q.push((dat){ny,nx,nK1,nK2,ncost});
      D[ny][nx] = tmp;
    }      
  }
  assert(0);
}

int main(){
  int K;
  cin>>h>>w>>K;

  for(int i=0;i<h;i++)cin>>mp[i];
  
  for(int i=0;i<h;i++)
    for(int j=0;j<w;j++)
      if(mp[i][j] == 'S')   cout<<bfs(i,j,K)<<endl;
  return 0;
  
}


Measured memory_bytes: 9660
#include <iostream>

int main(void){
    int s = 0;
    while(true){
        char c = getchar_unlocked();
        if(c == '\0' or c == '\n') break; 
        s += c - '0';
    }
    if(s % 9 == 0) std::cout << "Yes\n";
    else std::cout << "No\n";
    
    return 0;
}

Measured memory_bytes: 3640
using System;
using System.Linq;

namespace atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            B.GoodDistance();
        }
    }

    class B
    {
        public static void GoodDistance()
        {
            int[] num = Input.getIntArray();
            int n = num[0];
            int d = num[1];
            int[,] point = new int[n,d];
            for(int i=0; i<n; i++)
            {
                int[] temp = Input.getIntArray();
                for(int j=0; j<d; j++)
                {
                    point[i,j] = temp[j];
                }
            }

            int cnt =0;
            for(int i=0; i<n; i++)
            {
                for(int j=i+1; j<n; j++)
                {
                    double route =0;
 
                    for(int k=0; k<d; k++)
                    {
                        double tmp = Math.Pow(Math.Abs(point[i,k]-point[j,k]),2);
                        route += tmp;
                    }
                    
                    double result = Math.Sqrt(route);
                    if(route == Math.Pow(Math.Floor(result),2))
                    {
                        cnt ++;
                    }
                }
            }

            Output.writeInt(cnt);
        }
    }
  
    class Input
    {
        public static int getInt()
        {
            int i = int.Parse(Console.ReadLine());
            return i;
        }

        public static string getString()
        {
            string s = Console.ReadLine();
            return s;
        }
        public static int[] getIntArray()
        {
            string[] s = Console.ReadLine().Split(' ');
            int[] num = s.Select(x=>int.Parse(x)).ToArray();
            return num;
        }
    }

    class Output
    {
        public static void writeInt(int i)
        {
            Console.WriteLine(i);
        }
    }
}


Measured memory_bytes: 13396
#include <stdio.h>
#include <iostream>
#include <vector>
#include <list>
#include <cmath>
#include <fstream>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <iterator>
#include <cstdlib>

using namespace std;

#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) (EQ((a).real(),(b).real()) && EQ((a).imag(),(b).imag()))

typedef complex<double> P;
typedef long long ll;

const int MAX_SIZE = 10000;
const int MAX_PRIME = 1000000;


int prime[MAX_PRIME+1];
bool isPrime[MAX_PRIME+1];
int p;

void erats(){
	// primeツδ環スツトツづーツ渉可甘コツ可サ
	fill(isPrime,isPrime+MAX_PRIME,true);
	p = 0;
	isPrime[0] = isPrime[1] = false;

	for(int i = 2; i <= MAX_PRIME; i++){
		if(isPrime[i]){
			prime[p++] = i;
		}
		else
			continue;
		// ツづ督づゥツつ「ツづ可つゥツつッツづゥ
		for(int j = 2*i; j <= MAX_PRIME; j+=i){
			isPrime[j] = false;
		}
	}
}

int main(){

	int N,P;
	erats();
	while(cin>>N>>P&&!(N==-1&&P==-1)){
		int *it = upper_bound(prime,prime+p,N);
		int prv=it-prime;
		int init=prv;
		vector<int> v;
		for(int i = init; i <= init+50; i++){
			for(int j = i; j <= init+50; j++){
				v.push_back(prime[i]+prime[j]);
			}
		}
		sort(v.begin(),v.end());
		cout<<v[P-1]<<endl;
	}

	return 0;
}

Measured memory_bytes: 2204
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    //val map = mutableMapOf<String, Int>()
    val map = hashMapOf<String, Int>()
    for (i in 0 until n) {
        val str = readLine()!!
        map[str] = (map[str] ?: 0) + 1
    }
    val result = map.toList().sortedByDescending { it.second }
    var max = -1
    var index = 0
    var maxlist = mutableListOf<String>()
    while (true) {
        if (index >= result.count()) {
            break
        }
        if (max == -1 || max == result[index].second) {
            max = result[index].second
            maxlist.add(result[index].first)
        } else {
            break
        }
        index += 1
    }
    print(maxlist.sorted().joinToString("\n"))
}

Measured memory_bytes: 87744
#include "bits/stdc++.h"
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define mFOR(i, a, b) for (int i = a; i > b; i--)
#define MP make_pair
#define PB push_back
#define ALL(v) v.begin(), v.end()
#define N 100007
#define INF 1000000007
using namespace std;

typedef long long ll;

ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll fceil(ll a, ll b) { return (a % b == 0 ? a / b : a / b + 1); }

int n, a[15] = {}, x[15][15] = {}, y[15][15] = {};
int is_honest[15] = {};
int max_honest(int pos)
{
   int case0 = -1, case1 = -1, tmp[15];
   bool contra = true;
   if (pos == n)
   {
      int num = 0;
      FOR(i, 0, n)
      {
         num += is_honest[i];
      }
      return num;
   }
   FOR(i, 0, a[pos])
   if (is_honest[x[pos][i] - 1] >= 0 && is_honest[x[pos][i] - 1] != y[pos][i])
   {
      contra = false;
      break;
   }

   memcpy(tmp, is_honest, sizeof(tmp));
   if (is_honest[pos] <= 0)
   {
      is_honest[pos] = 0;
      case0 = max_honest(pos + 1);
      memcpy(is_honest, tmp, sizeof(tmp));
   }
   if (is_honest[pos] != 0 && contra)
   {
      is_honest[pos] = 1;
      FOR(i, 0, a[pos])
      is_honest[x[pos][i] - 1] = y[pos][i];
      case1 = max_honest(pos + 1);
      memcpy(is_honest, tmp, sizeof(tmp));
   }
   // else if(is_honest[pos] == -1)
   // {
   //    memcpy(tmp, is_honest, sizeof(tmp));
   //    is_honest[pos] = 0;
   //    case0 = max_honest(pos + 1);
   //    if (contra)
   //    {
   //       FOR(i, 0, a[pos])
   //       is_honest[x[pos][i] - 1] = y[pos][i];
   //       is_honest[pos] = 1;
   //       case1 = max_honest(pos + 1);
   //    }
   //    memcpy(is_honest, tmp, sizeof(tmp));
   // }
   return max(case0, case1);
}

int main()
{
   cin >> n;
   FOR(i, 0, n)
   {
      is_honest[i] = -1;
      cin >> a[i];
      FOR(j, 0, a[i])
      {
         cin >> x[i][j] >> y[i][j];
      }
   }

   cout << max_honest(0) << endl;

   return 0;
}


Measured memory_bytes: 256
N = int(input())
li = list(map(int,input().split()))

def BubbleSort(A):
    count = 0
    for i in range(len(A)):
        for j in reversed(range(i+1,len(A))):
            if A[j]<A[j-1]:
                #入れ替え
                a = A[j]
                b = A[j-1]
                A[j-1] = a
                A[j] = b
                count+=1
    return [A,count]

result = BubbleSort(li)    

print(" ".join(list(map(str,result[0]))))
print(result[1])


Measured memory_bytes: 5604
package main

import (
	"fmt"
)

func main() {
	var h, w, k int
	fmt.Scan(&h, &w, &k)

	s := make([]string, h)
	for i := 0; i < h; i++ {
		fmt.Scan(&s[i])
	}

	const inf int = 1e18
	ans := inf
	for bits := 0; bits < 1<<(h-1); bits++ {
		ok := true
		hc := popcount(bits)
		wc := 0
		gs := make([]int, hc+1)
		for j := 0; j < w; j++ {
			cs := make([]int, hc+1)
			gid := 0
			gok := true
			for i := 0; i < h; i++ {
				p := int(s[i][j] - '0')
				cs[gid] += p
				gs[gid] += p
				if k < cs[gid] {
					ok = false
					wc = inf
					break
				}
				if k < gs[gid] {
					gok = false
				}
				if bits>>i&1 == 1 {
					gid++
				}
			}
			if !gok {
				gs = cs
				wc++
			}
		}
		if ok {
			ans = min(ans, hc+wc)
		}
	}

	fmt.Println(ans)
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func popcount(n int) int {
	c := 0
	for n > 0 {
		if n&1 == 1 {
			c++
		}
		n >>= 1
	}
	return c
}


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

int countAB(char s[]){
  int cnt=0;
  for(uint i=0;i<strlen(s)-1;i++){
    if(s[i]=='A'&&s[i+1]=='B') cnt++;
  }
  return cnt;
}

int N;
char S[100000][10];
int main(void){
  cin>>N;
  int acnt=0;
  int bcnt=0;
  int dcnt=0;
  int cnt=0;
  for(int i=0;i<N;i++){
    cin>>S[i];
    cnt+=countAB(S[i]);
    if(S[i][strlen(S[i])-1]=='A') acnt++;
    if(S[i][0]=='B') bcnt++;
    if(S[i][0]=='B'&&S[i][strlen(S[i])-1]=='A') dcnt++;
  }
  int _cnt=0;
  if(acnt>0&&bcnt>0&&acnt==dcnt&&bcnt==dcnt) _cnt-=1;
  else{
    if(acnt>N-1) acnt=N-1;
    if(bcnt>N-1) bcnt=N-1;
  }
  if(acnt<bcnt) _cnt+=acnt;
  else          _cnt+=bcnt;
  cout<<cnt+_cnt<<endl;
  return 0;
}


Measured memory_bytes: 384
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import numpy as np
import statistics
from statistics import mean, median,variance,stdev
import math

def main():
	N = int(input())
	
	DP = [i for i in range(100010)]
	
	for i in range(1, 100001):
		for j in range(1, i):
			step = 6**j
			if step > i:
				break
			tmp = 1 + DP[i-step]
			DP[i] = min(DP[i], tmp)
			
	for i in range(1, 100001):
		for j in range(1, i):
			step = 9**j
			if step > i:
				break
			tmp = 1 + DP[i-step]
			DP[i] = min(DP[i], tmp)
	
	print(DP[N])
			
	
if __name__ == "__main__":
	main()


Measured memory_bytes: 23932
/*
     ॐ त्र्यम्बकं यजामहे सुगन्धिं पुष्टिवर्धनम् |
     उर्वारुकमिव बन्धनान्मृत्योर्मुक्षीय माऽमृतात् ||
*/

#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 int            long long int
#define F              first
#define S              second
#define pb             push_back
#define si             set <int>
#define vi             vector <int>
#define pii            pair <int, int>
#define vpi            vector <pii>
#define vpp            vector <pair<int, pii>>
#define mii            map <int, int>
#define mpi            map <pii, int>
#define spi            set <pii>
#define endl           "\n"
#define sz(x)          ((int) x.size())
#define all(p)         p.begin(), p.end()
#define double         long double
#define que_max        priority_queue <int>
#define que_min        priority_queue <int, vi, greater<int>>
#define bug(...)       __f (#__VA_ARGS__, __VA_ARGS__)
#define print(a)       for(auto x : a) cout << x << " "; cout << endl
#define print1(a)      for(auto x : a) cout << x.F << " " << x.S << endl
#define print2(a,x,y)  for(int i = x; i < y; i++) cout<< a[i]<< " "; cout << endl

inline int power(int a, int b)
{
     int x = 1;
     while (b)
     {
          if (b & 1) x *= a;
          a *= a;
          b >>= 1;
     }
     return x;
}

typedef tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update> Set;

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

const int N = 200005;
int a[N], n, m, k;

void solve()
{
     string s, t; cin >> s >> t;
     t.pop_back();
     if (t == s)
          cout << "Yes";
     else
          cout << "No";

}

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


     cout << setprecision(9) << fixed;
     clock_t z = clock();
     solve();
     cerr << "Run Time : " << ((double)(clock() - z) / CLOCKS_PER_SEC);

     return 0;
}

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

int main(){
    int m;
    cin >> m ;
    if(m >= 1800){
        cout << '1' << endl;
    }else if(m >= 1600){
        cout << '2' << endl;
    }else if(m >= 1400){
        cout << '3' << endl;
    }else if(m >= 1200){
        cout << '4' << endl;
    }else if(m >= 1000){
        cout << '5' << endl;
    }else if(m >= 800){
        cout << '6' << endl;
    }else if(m >= 600){
        cout << '7' << endl;
    }else if(m >= 400){
        cout << '8' << endl;
    } 
}


Measured memory_bytes: 3628
"""
~~ Author : Bhaskar
~~ Dated : 16~05~2020
"""

import sys
INT_MAX = sys.maxsize
INT_MIN = -(sys.maxsize)-1
sys.setrecursionlimit(10**7)
mod = 1000000007


def IOE():
    sys.stdin = open("input.txt", "r")
    sys.stdout = open("output.txt", "w")


def main():
    s = sys.stdin.readline().replace("\n", "")
    if int(s[-1]) in [2, 4, 5, 7, 9]:
        print("hon")
    elif int(s[-1]) in [0, 1, 6, 8]:
        print("pon")
    else:
        print("bon")


if __name__ == "__main__":
    try:
        IOE()
    except:
        pass
    main()


Measured memory_bytes: 61748
#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 sum_A = 0,sum_B = 0,mini = 10000,diff = 0;
    for (int i = 0; i < N - 1; i++){
        sum_A += vec.at(i);
        sum_B = 0;
        for (int j = i + 1; j < N; j++){
            sum_B += vec.at(j);
        }
        diff = abs(sum_A - sum_B);
        mini = min(mini,diff);
    }
    cout << mini << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
  int n; cin >> n;
  int a[n+1];
  for(int i=1;i<=n;i++) cin >> a[i];
  int idx=1;
  for(int t=1;t<=n;t++){
    if(a[idx]==2){
      cout << t << endl;
      return 0;
    }
    idx=a[idx];
  }
  cout << -1 << endl;
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <limits>
#include <algorithm>
using namespace std;
#pragma warning (disable: 4996)

template<typename Type> class RangeMin {
private:
	int size_;
	std::vector<Type> dat;
public:
	RangeMin() : size_(0), dat(std::vector<Type>()) {};
	RangeMin(int size__) {
		for (size_ = 1; size_ < size__; ) size_ <<= 1;
		dat.resize(size_ << 1, std::numeric_limits<Type>::max());
	}
	template<class T>
	RangeMin(T begin_, T end_) {
		int n = end_ - begin_;
		for (size_ = 1; size_ < n; size_ <<= 1); dat.resize(size_ << 1, std::numeric_limits<Type>::max());
		for (int i = 0; i < n; i++) dat[i + size_] = *(begin_ + i);
		for (int i = size_ - 1; i > 0; i--) dat[i] = std::min(dat[i << 1], dat[(i << 1) + 1]);
	}
	inline unsigned size() { return size_; }
	inline void update(int i, Type x) {
		i += size_; dat[i] = x;
		while (i > 1) {
			i >>= 1;
			dat[i] = std::min(dat[i << 1], dat[i << 1 | 1]);
		}
	}
	inline Type query(int l, int r) {
		Type ret = std::numeric_limits<Type>::max();
		l += size_; r += size_;
		while (l != r) {
			if (l & 1) ret = std::min(ret, dat[l++]); l >>= 1;
			if (r & 1) ret = std::min(ret, dat[--r]); r >>= 1;
		}
		return ret;
	}
};

long long N, M, A[5009], B[5009][209], P[5009][5009], INF = 10000000000LL;
RangeMin<long long>X;

void dfs(int cl, int cr) {
	if (cl > cr) return;

	long long E = X.query(cl, cr + 1);
	long long X = INF - (E / 100000LL), Y = E % 100000LL;
	P[cl][Y] += X;
	P[Y + 1][Y] -= X;
	P[cl][cr + 1] -= X;
	P[Y + 1][cr + 1] += X;
	dfs(cl, Y - 1);
	dfs(Y + 1, cr);
}

int main() {
	scanf("%lld%lld", &N, &M);
	for (int i = 1; i <= N - 1; i++) scanf("%lld", &A[i]);
	for (int i = 1; i <= N; i++) {
		for (int j = 1; j <= M; j++) scanf("%lld", &B[i][j]);
	}
	for (int t = 1; t <= M; t++) {
		X = RangeMin<long long>(N + 2);
		for (int i = 1; i <= N; i++) X.update(i, (INF - B[i][t]) * 100000LL + i);
		dfs(1, N);
	}
	for (int i = 1; i <= N + 1; i++) {
		for (int j = 1; j <= N + 1; j++) P[i][j] += P[i][j - 1];
	}
	for (int i = 1; i <= N + 1; i++) {
		for (int j = 1; j <= N + 1; j++) P[i][j] += P[i - 1][j];
	}

	long long ans = 0;
	for (int i = 1; i <= N; i++) {
		long long dst = 0;
		for (int j = i; j <= N; j++) {
			ans = max(ans, P[i][j] - dst);
			dst += A[j];
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 204668
#include<iostream>
#include<cstdio>
#include<cstring>
#include<map>
std::map<int,int> G;
int n,m;
bool check()
{
	
	scanf("%d",&n);
	for(int x;n--;)
	{
		scanf("%d",&x);
		G[x]=G[x]+1;
	}
	scanf("%d",&m);
	for(int x;m--;)
	{
		scanf("%d",&x);
		if(G[x]==0)return 0;
		G[x]=G[x]-1;;
	}
	return 1;
}
int main()
{
	if(check())printf("YES\n");
	else printf("NO\n");
	return 0;
}


Measured memory_bytes: 9728