akhauriyash/Code-Regression huggingface dataset:
while 1:
	n=input()
	if n==0:break
	a=[0]*n
	c=raw_input()
	b=0
	for i in range(100):
		if c[i]=="M":
			a[i%n]+=1
		elif c[i]=="S":
			b+=1+a[i%n]
			a[i%n]=0
		else:
			a[i%n]+=1+b
			b=0
	print " ".join(map(str,sorted(a))),b

Measured memory_bytes: 4232
#include<iostream>
using namespace std;
int r, c, g[105][105], a[105], s;
main() {
	cin >> r >> c;
	for (int i = 0; i < r; i++) for (int j = 0; j < c; j++) cin >> g[i][j];
	for (int i = 0; i < r; i++) {
		s = 0;
		for (int j = 0; j < c; j++) {
			cout << g[i][j] << " ";
			s += g[i][j];
			a[j] += g[i][j];
		}
		a[c] += s;
		cout << s << endl;
	} 
	for (int i = 0; i <= c; i++) {
		if (i) cout << " ";
		cout << a[i];
	}
	cout << endl;
}



Measured memory_bytes: 3096
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
typedef long long ll;
struct edge { ll s, t, x; };
typedef pair<ll, ll> P;
typedef pair<ll,P> event;
const ll MAX = 510000;
const ll MOD = 1000000007;
#define INF (ll)100000000000000
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

// a^{-1} mod を計算する
long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}

int main() {
  ll N;
  cin>>N;
  vector<ll>C(N);
  rep(i,N){cin>>C[i];}
  sort(C.begin(),C.end());
  ll g=modpow(4ll,N-1ll,MOD);
  ll ans=0ll;
  rep(i,N){
    ll p=g*C[i];
    p%=MOD;
    p*=(N+1ll-i);
    p%=MOD;
    ans+=p;
    ans%=MOD;
  }
  cout<<ans;
  
}



Measured memory_bytes: 4844
#include<iostream>
#include<math.h>
#include<bits/stdc++.h>
#define ll long long int
#define hell 1000000007LL
using namespace std;
ll power(ll x, ll y, ll z){ 
    if(y==0)
     return 1;
    else
    {
        ll p=power(x,y/2,z);
        if(y%2==0)
         return (p*p)%z;
        else
        return (x*((p*p)%z))%z;
    }}
ll gcd(ll x,ll y)
{
    if(y==0)
     return x;
    else
    return gcd(y,x%y);
}
ll po(ll x)
{
    ll c=0;
    while(x>0)
    {
        x=x&(x-1);
        c++;
    }
    return c;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(20);
    ll n,x;
    cin>>n>>x;
    ll a[n];
    for(int i=0;i<n;i++)
    cin>>a[i];
    ll y=0,c=1;
    for(int i=0;i<n;i++)
    {
        y=y+a[i];
        if(y<=x)
        c++;
    }
    cout<<c;}

Measured memory_bytes: 3612
# AOJ 0502: Dice
# Python3 2018.6.29 bal4u

d = { "North":1, "East":2, "West":3, "South":4, "Right":5, "Left":6 }

rot = ((0,1,2,3,4,5,6),(0,2,6,3,4,1,5),(0,4,2,1,6,5,3),(0,3,2,6,1,5,4), \
       (0,5,1,3,4,6,2),(0,1,3,5,2,4,6),(0,1,4,2,5,3,6))

import sys
while True:
	n = int(input())
	if n == 0: break
	dice = [[j for j in range(7)] for i in range(2)]
	ans = 1
	for i in range(n):
		j = d[input().strip()]
		for k in range(1, 7): dice[1-(i&1)][k] = dice[i&1][rot[j][k]]
		ans += dice[1-(i&1)][1]
	print(ans)


Measured memory_bytes: 5636
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e16;
const ll mod = 1000000007;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)

int main() {
  ll l, r, d; cin >> l >> r >> d;
  cout << r/d - (l-1)/d << endl;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define PI 3.14159265359
#define INF 1000100100
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define P pair<ll, ll>
#define PP pair<P,P>
using namespace std;
 
vector<int> divisor(int a){
    vector<int> res;
    for(int i=2; i<=sqrt(a); i++){
        if(a%i==0){
            res.push_back(i);
            if(i!=a/i) res.push_back(a/i);
        }
    }
    res.push_back(a);
    sort(all(res));
    return res;
}


int main(){
    int n,k; cin >> n >> k;
    vector<int> a(n);
    int sum=0;
    rep(i,n){
        cin >> a[i];
        sum+=a[i];
    }

    vector<int> p=divisor(sum);
    reverse(all(p));

    rep(i,p.size()){
        vector<int> moda;
        rep(j,n){
            if(a[j]%p[i]) moda.push_back(a[j]%p[i]);
        }
        int ms=moda.size();
        /*if(!ms){
            cout << p[i] << endl;
            return 0;
        }*/
        sort(all(moda));
        vector<ll> rmoda(ms+1);
        rmoda[0]=0;
        rep(j,ms) rmoda[j+1]=p[i]-moda[j]+rmoda[j];
        ll now=0;
        rep(j,ms){
            now+=moda[j];
            if(now==rmoda[ms]-rmoda[j+1]){
                if(now<=k){
                    cout << p[i] << endl;
                    return 0;
                }
                break;
            }
            else if(now>rmoda[ms]-rmoda[j+1]) break;
        }
    }
    cout << 1 << endl;
return 0;
}


Measured memory_bytes: 256
n,m=[int(x) for x in input().rstrip().split()]

l=-float('inf')
r=float('inf')
for i in range(m):
  L,R=[int(x) for x in input().rstrip().split()]
  if l<L:
    l=L
  if R<r:
    r=R
if l<=r:
  print(r-l+1)
else:
  print(0)



Measured memory_bytes: 3060
#include <algorithm>
#include <iomanip>
#include <iostream>

#define VARIABLE(x) cerr << #x << "=" << x << endl
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)

const int INF = 10000000;
using namespace std;
typedef long long  ll;
const int MAX = 10000;
typedef pair<int, int> P;
/** Problem0197 : Greatest Common Divisor : Euclidean Algorithm **/
int main()
{
	int a, b;
	
	while (cin >> a >> b, a!=0 && b!=0) {
		int i=0;
		while (1) {
			if (a < b)
				swap(a, b);
			a = a%b;
			i++;
			
			if (a==0)
				break;
			
		}
		cout << b << " " << i << endl;
	}
}

Measured memory_bytes: 1160
import sys

n = int( sys.stdin.readline() )

i = 0
while i < n:
    i = i+1
    x = i
    if x%3 == 0 or str(x).find( "3" ) > -1:
        sys.stdout.write( " " + str(i) )
        continue
print

sys.exit(0)

Measured memory_bytes: 6428
#include <bits/stdc++.h>
using namespace std;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    string s;
    cin>>s;
    if(s[1]=='B') cout<<"ARC\n";
    else cout<<"ABC\n";
    return 0;
}

Measured memory_bytes: 3640
#include "bits/stdc++.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/2
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr<<#x<<": "<<x<<endl
#define debug_vec(v) cerr<<#v<<":";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
/*----------------------------------------------------------------*/

// int MOD = 998244353;
int MOD = 1000000007;

/*----------------------------------------------------------------*/
signed main(){
   
    int t[2],a[2],b[2];
	
	rep(i,2)cin >> t[i];
	rep(i,2)cin >> a[i];
	rep(i,2)cin >> b[i];


	int sa[2];
	rep(i,2)sa[i] = t[i]*(a[i]-b[i]);

	if(sa[0]+sa[1] == 0){
		cout << "infinity" << endl;
		return 0;
	}

	if((sa[0]>0&&sa[1]>0) || (sa[0]<0&&sa[1]<0)){
		cout << 0 << endl;
		return 0;
	}

	ll ok = 0;  //解が存在する値
    ll ng = INF-1;//解が存在しない値 
	ll ans1 = 0;
    while(abs(ok-ng)>1){
        ll mid = (ok+ng)/2;
		int dif0 = (mid-1)*(sa[0]+sa[1]);
		int dif1 = (mid-1)*(sa[0]+sa[1])+sa[0];
		// cerr << mid << " " << dif0 << " " << dif1 << endl;
        if(dif1==0 || (dif1>0&&dif0<0) || (dif1<0&&dif0>0)){
            ok = mid;
        }else{
            ng = mid;
        }
    }
	ans1 = ok;
	ok = 0;
	ng = INF-1;
	ll ans2 = 0;
    while(abs(ok-ng)>1){
        ll mid = (ok+ng)/2;
		int dif0 = (mid-1)*(sa[0]+sa[1]);
		int dif1 = (mid-1)*(sa[0]+sa[1])+sa[0];
		int dif2 = (mid-1)*(sa[0]+sa[1])+sa[0]+sa[1];
        if((dif1>0&&dif2<0) || (dif1<0&&dif2>0)){
            ok = mid;
        }else{
            ng = mid;
        }
    }
	ans2 = ok;

	cout << max(0LL,(ans1-1)) + ans2 << endl;
	cerr << ans1 << endl;
	cerr << ans2 << endl;

	int cnt1= 0;
	int cnt2= 0;
	int dif = 0;
	rep(i,300){
		if(dif+sa[0]==0 || (dif>0&&dif+sa[0]<0) || (dif<0&&dif+sa[0]>0)){
			cnt1++;
		} 
		if(dif+sa[0]+sa[1]==0  || (dif+sa[0]+sa[1] >0&&dif+sa[0]<0) || (dif+sa[0]+sa[1] <0&&dif+sa[0]>0)){
			cnt2++;
		} 
		dif += sa[0] + sa[1];
	}
	cerr << cnt1 << " "<< cnt2 << endl;


	
	return 0;
}
/*----------------------------------------------------------------*/

// g++ -std=c++14 code1.cpp
// sudo pip3 install --upgrade online-judge-tools
// rm -r -f test;oj dl https://code-festival-2018-quala.contest.atcoder.jp/tasks/code_festival_2018_quala_c
// rm -r -f test;oj dl https://ddcc2020-qual.contest.atcoder.jp/tasks/ddcc2020_qual_b
// rm -r -f test;oj dl https://sumitrust2019.contest.atcoder.jp/tasks/sumitb2019_b

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define int long long
using namespace std;
typedef vector<int>vec;
typedef vector<vec>mat;
const int M=1000000007;
mat mul(mat A,mat B){
    mat C(A.size(),vec(B[0].size()));
    for(int i=0;i<A.size();i++){
        for(int j=0;j<B[0].size();j++){
            for(int k=0;k<A[0].size();k++){
                C[i][j]=(C[i][j]+A[i][k]*B[k][j])%M;
            }
        }
    }
    return C;
}
 
mat matpow(mat A,int k){
    mat B(A.size(),vec(A.size()));
    for(int i=0;i<A.size();i++)B[i][i]=1;
    while(k){
        if(k&1)B=mul(B,A);
        A=mul(A,A);
        k>>=1;
    }
    return B;
}
 
int sol(int n){
    mat A(2,vec(2));
    A[0][0]=1;A[0][1]=1;
    A[1][0]=1;A[1][1]=0;
    A=matpow(A,n);
    return A[1][0];
}

void out(int x,int y){
    cout<<(sol(x+1)*sol(y+1))%M<<endl;
    exit(0);
}

signed main(){
    int K;
    cin>>K;
    int l=0,r=(1e9)*4;
    while(l<r){
        int mid=(l+r)/2;
        if(mid*(mid+1)>=K)r=mid;
        else l=mid+1;
    }
    l--;
    int cnt=0;
    K-=l*(l+1);
    int x=r*2-1,p=0;
    if(K>r)K-=r,x++,p++;
    int y=1;
    while(x>=y){
        cnt++;
        if(cnt==K)out(x,y);
        x-=2;y+=2;
    }
    x+=2;
    y-=2;
   // cout<<r<<endl;
   // cout<<x<<' '<<y<<endl;
    if(!p){
        if((x==r+1&&y==r-1))x--,y++;
        else x++,y--;
    }
    else{
        if(x==y+x/2)x++,y--;
        else x--,y++;
    }
    //cout<<x<<' '<<y<<endl;

    while(1){
        cnt++;
        if(cnt>=2000000000)exit(1);
        if(cnt==K)out(x,y);
        x+=2;y-=2;
    }
    //cout<<K<<' '<<l<<endl;
}


Measured memory_bytes: 3156
function main(input) 
{
    input = input.split("\n");
    var colour = input[0].split(" ");
    var numbers = input[1].split(" ").map(Number);
    if (colour[0] == input[2])
    {
        numbers[0]--;
    }
    if (colour[1] == input[2])
    {
        numbers[1]--;
    }

    console.log("%d %d", numbers[0], numbers[1]);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7372
word = input()
text = ''
line = input()
while(line != 'END_OF_TEXT'):
    text = text +' '+ line.lower()
    #print(text)
    line = input()

token = text.split()
count = 0
for _ in token:
    #print(_)
    if (_ == word):
        count += 1
        #print(count)

print(count)



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

int	main() {
	int N;
	cin >>N;
	vector<bool> s(N+1, false);
	for (int i=0; i<N; i++) {
		char c;
		cin >>c;
		if ('o'==c)
			s.at(i)=true;
	}
	s.at(N)=s.at(0);
	vector<int> A(N+2, 0);
	A.at(0)=1;
	A.at(1)=0;
	for (int i=1; i<=N; i++) {
		if (s.at(i)) {
			if (A.at(i-1)==A.at(i))
				A.at(i+1)=1;
			else
				A.at(i+1)=0;
		} else {
			if (A.at(i-1)==A.at(i))
				A.at(i+1)=0;
			else
				A.at(i+1)=1;
		}
	}
	if((A.at(0)==A.at(N))&&(A.at(1)==A.at(N+1))) {
		for (int i=0; i<N; i++) {
			if (0==A.at(i))
				cout <<'W';
			else
				cout <<'S';
		}
		cout <<endl;
		return 0;
	}
	A.at(0)=0;
	A.at(1)=0;
	for (int i=1; i<=N; i++) {
		if (s.at(i)) {
			if (A.at(i-1)==A.at(i))
				A.at(i+1)=1;
			else
				A.at(i+1)=0;
		} else {
			if (A.at(i-1)==A.at(i))
				A.at(i+1)=0;
			else
				A.at(i+1)=1;
		}
	}
	if((A.at(0)==A.at(N))&&(A.at(1)==A.at(N+1))) {
		for (int i=0; i<N; i++) {
			if (0==A.at(i))
				cout <<'W';
			else
				cout <<'S';
		}
		cout <<endl;
		return 0;
	}
	A.at(0)=0;
	A.at(1)=1;
	for (int i=1; i<=N; i++) {
		if (s.at(i)) {
			if (A.at(i-1)==A.at(i))
				A.at(i+1)=1;
			else
				A.at(i+1)=0;
		} else {
			if (A.at(i-1)==A.at(i))
				A.at(i+1)=0;
			else
				A.at(i+1)=1;
		}
	}
	if((A.at(0)==A.at(N))&&(A.at(1)==A.at(N+1))) {
		for (int i=0; i<N; i++) {
			if (0==A.at(i))
				cout <<'W';
			else
				cout <<'S';
		}
		cout <<endl;
		return 0;
	}
	A.at(0)=1;
	A.at(1)=1;
	for (int i=1; i<=N; i++) {
		if (s.at(i)) {
			if (A.at(i-1)==A.at(i))
				A.at(i+1)=1;
			else
				A.at(i+1)=0;
		} else {
			if (A.at(i-1)==A.at(i))
				A.at(i+1)=0;
			else
				A.at(i+1)=1;
		}
	}
	if((A.at(0)==A.at(N))&&(A.at(1)==A.at(N+1))) {
		for (int i=0; i<N; i++) {
			if (0==A.at(i))
				cout <<'W';
			else
				cout <<'S';
		}
		cout <<endl;
		return 0;
	}
	cout <<-1 <<endl;
	return 0;
};


Measured memory_bytes: 768
# -*- coding: utf-8 -*-

import sys
from itertools import accumulate

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

def divisors(N: int) -> set:
    from math import sqrt

    s = {1, N}
    for i in range(2, int(sqrt(N))+1):
        if N % i == 0:
            s.add(i)
            s.add(N // i)
    return s

def check(n, k):
    if k == 1:
        return False
    while n >= k:
        if n % k == 0:
            n //= k
        else:
            n %= k
    return n == 1

N = INT()

divs = divisors(N) | divisors(N-1)

ans = 0
for k in divs:
    if check(N, k):
        ans += 1
print(ans)


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

int main() {
  int H, W;
  while (true) {
    cin >> H >> W;
    if (H == 0 && W == 0) return 0;
    for (int h = 0; h < H; h++) {
      for (int w = 0; w < W; w++) {
        if (h == 0 || h == H - 1 || w == 0 || w == W - 1) cout << '#';
        else cout << '.';
      }
      cout << endl;
    }
    cout << endl;
  }
}

Measured memory_bytes: 1152
#include<iostream>
#include<string>
using namespace std;
#define MAX_N 500000
#define INF 2139062143
int x[MAX_N][4], cnt;//num,left,right
int n, a; string S;
void inorder(int u) {
	if (u == -1) { return; }
	inorder(x[u][1]);
	cout << ' ' << x[u][0];
	inorder(x[u][2]);
}
void preorder(int u) {
	if (u == -1) { return; }
	cout << ' ' << x[u][0];
	preorder(x[u][1]);
	preorder(x[u][2]);
}
int Next(int a1) {
	a1 = x[a1][2];
	while (x[a1][1] != -1) {
		a1 = x[a1][1];
	}
	return a1;
}
int main() {
	int root = -INF; cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> S;
		if (S == "delete") {
			cin >> a; int v = root;
			while (true) {
				if (a == x[v][0]) { a = v; goto D1; }
				if (a < x[v][0]) {
					if (x[v][1] == -1) { goto C1; } v = x[v][1];
				}
				if (a > x[v][0]) {
					if (x[v][2] == -1) { goto C1; } v = x[v][2];
				}
			}
		C1:; D1:;
			int Y = a, X = 0, Z = 0;
			if (x[a][1] != -1 && x[a][2] != -1) { Y = Next(a); }
			if (x[Y][1] != -1) {
				X = x[Y][1];
			}
			else { X = x[Y][2]; }
			if (X != -1) {
				x[X][3] = x[Y][3];
			}
			if (x[Y][3] == -1) { root = X; }
			else if (Y == x[x[Y][3]][1]) { x[x[Y][3]][1] = X; }
			else { x[x[Y][3]][2] = X; }
			if (Y != a) {
				x[a][0] = x[Y][0];
			}
		}
		if (S == "print") {
			inorder(root); cout << endl;
			preorder(root); cout << endl;
		}
		if (S == "find") {
			cin >> a; int v = root;
			while (true) {
				if (a == x[v][0]) { cout << "yes" << endl; goto D; }
				if (a < x[v][0]) {
					if (x[v][1] == -1) { goto C; } v = x[v][1];
				}
				if (a > x[v][0]) {
					if (x[v][2] == -1) { goto C; } v = x[v][2];
				}
			}
		C:; cout << "no" << endl; D:;
		}
		if (S == "insert") {
			cin >> a; int P = -1;
			if (root == -INF) { root = cnt; }
			else {
				int v = root;
				while (true) {
					if (a < x[v][0]) {
						if (x[v][1] == -1) { x[v][1] = cnt; P = v; goto E; }
						v = x[v][1]; P = v;
					}
					else {
						if (x[v][2] == -1) { x[v][2] = cnt; P = v; goto E; }
						v = x[v][2]; P = v;
					}
				}
			E:;
			}
			x[cnt][0] = a; x[cnt][1] = -1; x[cnt][2] = -1; x[cnt][3] = P; cnt++;
		}
	}
	return 0;
}

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

int main(){
  int n;
  cin >> n;
  string ans = "No";
  
  for(int i = 1; i <=3; i++){
    if (n%10 == 7){
      ans = "Yes";
      break;
    }
    else n /= 10;
  }
  
  cout << ans << endl;
  
}


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

long long a[1005] , b[1005] , c[1005];

int main()
{
	long long x , y , z , k;
	
	cin >> x >> y >> z >> k;
	
	for(int i = 1 ; i<=x ; i++)
		cin >> a[i];
		
	for(int i = 1 ; i<=y ; i++)
		cin >> b[i];
		
	for(int i = 1 ; i<=z ; i++)
		cin >> c[i];
		
	sort(a+1 , a+x+1);
	sort(b+1 , b+y+1);
	sort(c+1 , c+z+1);
	
	vector<long long> ans , v;
	
	for(int i = 1 ; i<=x ; i++)
		for(int j = 1 ; j<=y; j++)
			v.push_back(a[i]+b[j]);
			
	sort(v.begin() , v.end());
	
	for(int i = v.size()-1 , l = 1 ; l<=k && i>=0 ; i-- , l++)
	{
		for(int j = z ; j>=1 ; j--)
		{
			ans.push_back(v[i]+c[j]);
		}
	}
	
	sort(ans.begin() , ans.end());
	
	for(int i = ans.size()-1 , l = 1 ; i>=0 && l<=k ; i-- , l++)
		cout << ans[i] << endl;
	return 0;
}

Measured memory_bytes: 43364
#include<iostream>
using namespace std;
int main()
{
    int S;
    cin>>S;
    int A=S/100;
    int B=S%100;
    if(((A>=1)&&(A<=12))&&((B>=1)&&(B<=12)))
    {
        cout<<"AMBIGUOUS"<<endl;
    }
    else
    {
        if((A>=1)&&(A<=12))

        {
            cout<<"MMYY"<<endl;
        }
        else if((B>=1)&&(B<=12))

        {
            cout<<"YYMM"<<endl;
        }
        else
        {
            cout<<"NA"<<endl;
        }
    }
    return 0;
}


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

using namespace std;

int main() {
    long long n, m;
    string sn, sm;
    cin >> n >> m >> sn >> sm;
    long long lcm = n * m / __gcd(n, m);
    map<long long, char> mp1, mp2;

    for (long long i = 1, j = 0; j < sn.size(); i += lcm / n, j++)
        mp1[i] = sn[j];
    for (long long i = 1, j = 0; j < sm.size(); i += lcm / m, j++)
        mp2[i] = sm[j];

    for (auto &x : mp1)
        if (mp2[x.first] && mp2[x.first] != x.second)
            return cout << -1 << "\n", 0;

    cout << lcm << "\n";
    return 0;
}

Measured memory_bytes: 15616
#!/usr/bin/env python3
# Generated by https://github.com/kyuridenamida/atcoder-tools
from typing import *
import itertools
import math
import sys

INF = float('inf')
YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(S: str, T: str):
    return [NO, YES][S == T[:-1]]


def main():

    sys.setrecursionlimit(10 ** 6)

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    T = next(tokens)  # type: str
    print(solve(S, T))


if __name__ == '__main__':
    main()


Measured memory_bytes: 70292
#include <bits/stdc++.h>
#define int long long
using namespace std;

constexpr int INF = 1e18;

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

  vector<int> a(M), b(M);
  vector<int> c[1010];
  for (int i = 0; i < M; i++) {
    cin >> a[i] >> b[i];
    c[i].resize(b[i]);
    for (int j = 0; j < b[i]; j++) {
      cin >> c[i][j];
    }
  }

  static int dp[1 << 12][1010];
  for (int i = 0; i < (1 << 12); i++) {
    for (int j = 0; j < 1010; j++) {
      dp[i][j] = INF;
    }
  }

  dp[0][0] = 0;

  for (int i = 0; i < M; i++) {
    for (int bit = 0; bit < (1 << N); bit++) {
      int mask = 0;
      for (int j = 0; j < b[i]; j++) {
        mask = mask | (1 << (c[i][j] - 1));
      }
      dp[bit][i + 1] = min(dp[bit][i + 1], dp[bit][i]);
      dp[bit | mask][i + 1] = min(dp[bit | mask][i + 1], dp[bit][i] + a[i]);
      dp[bit | mask][i + 1] = min(dp[bit | mask][i + 1], dp[bit | mask][i]);
    }
  }

  if (dp[(1 << N) - 1][M] == INF) {
    cout << -1 << endl;
    return 0;
  }

  cout << dp[(1 << N) - 1][M] << endl;
  return 0;
}

Measured memory_bytes: 32768
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		int a = sc.nextInt();
		
		if (x < a) {
			System.out.println(0);
		} else {
			System.out.println(10);
		}
	}
}

Measured memory_bytes: 23636
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <bitset>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <utility>
#include <set>
#include <map>
#include <tuple> 
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <list>
using namespace  std;
using ll = long long;
using P = pair<ll, ll>;
#define REP(i, n) for(long long (i)=0, i_bound = (long long)(n); (i)<i_bound; ++i)
#define FOR(i, a, b) for(long long (i)=(a); (i)<(b); ++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
const long long MOD = static_cast<long long>(1e9) + 7LL;
const long long INF = 1234567891234567890LL;
int main(){
    cin.tie(0);
    cout.sync_with_stdio(false);
    int a, b, c, d;
    cin>>a>>b>>c>>d;
    if(a!=c) cout << 1 << endl;
    else cout << 0 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
static const int INF = 2000000000;
int N, A[300002], diff;

void update(int i, int v){
  int d1 = 0, d2 = 0;
  if ( A[i-1] > A[i] ) d1++;
  if ( A[i] > A[i+1] ) d1++;
  A[i] = v;
  if ( A[i-1] > A[i] ) d2++;
  if ( A[i] > A[i+1] ) d2++;
  diff += (d2 - d1);
}

int solve(){
  int a, b, q, v1, v2;
  diff = 0;
  for ( int i = 1; i <= N; i++ ) {
    if ( A[i-1] > A[i] ) diff++;
  }

  if ( diff == 0 ) return 0;
  cin >> q;
  for ( int i = 1; i <= q; i++ ){
    cin >> a >> b;
    v1 = A[a];
    v2 = A[b];
    update(a, v2);
    update(b, v1);
    if ( diff == 0 ) return i;
  }

  return -1;
}

int main() {
  cin >> N;
  for ( int i = 1; i <= N; i++ ) cin >> A[i];
  A[0] = -INF;
  A[N+1] = INF;
  cout << solve() << endl;
  return 0;
}



Measured memory_bytes: 4296
#include <bits/stdc++.h>
using namespace std;
int ans;
int n,len;
void dfs(int num3,int num5,int num7,int sum){
    if(num3 + num5 + num7 == 0){
        if(sum <= n) ans++;
        return;
    }
    if(num3 > 0){
        dfs(num3-1,num5,num7,sum*10+3);
    }
    if(num5 > 0){
        dfs(num3,num5-1,num7,sum*10+5);
    }
    if(num7 > 0){
        dfs(num3,num5,num7-1,sum*10+7);
    }
}
int main(){
    scanf("%d",&n);
    int tmp = n;
    while(tmp){
        len++;
        tmp /= 10;
    }
    for(int i = 1; i <= len - 2; i++){
        for(int j = 1; j + i <= len - 1; j++){
            for(int k = 1; k + j + i <= len; k++){
                dfs(i,j,k,0);
            }
        }
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main( void ) {
	int n, y, m, d;

	for ( scanf( "%d", &n ); n--; scanf( "%d %d %d", &y, &m, &d ), y--, m--, printf( "%d\n", 196470 - y / 3 * 590 - y % 3 * 195 - m * 20 + ( ( y + 1 ) % 3 ? m / 2 : 0 ) - d + 1 ) ) ;

	return 0;
}

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

void trace(int A[], int N){
  for(int i = 0; i < N; i++){
    if(i > 0)
      cout << " ";
    cout << A[i];
  }
  cout << endl;
}

void insertionSort(int A[], int N){
  int v,i,j;
  for(i = 1; i < N; i++){
    j = i - 1;
    v = A[i];
    while(j >= 0 && A[j] > v){
      A[j + 1] = A[j];
      j--;
    }
    A[j + 1] = v;
    trace(A, N);
  }
}

int main(){
  int N, j;
  int A[100];
  cin >> N;
  for(int i = 0; i < N; i++)
    cin >> A[i];

  trace(A, N);
  insertionSort(A, N);


 return 0; 
    
}



Measured memory_bytes: 3084
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=1000000007;
const double PI=3.14159265358979;
const ll INF= pow(10,18);
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";

ll n,x;
vl a(51,1),p(51,1);

ll f(ll n,ll x){
  if(n==0&&x==0){
    return 1;
  }
  else{
    if(x==0){
      return 0;
    }
    else if(0<x&&x<=a[n-1]){
      return f(n-1,x-1);
    }
    else if(x==a[n-1]+1){
      return p[n-1]+1;
    }
    else if(a[n-1]+1<x&&x<=2*a[n-1]+1){
      return p[n-1]+f(n-1,x-2-a[n-1])+1;
    }
    else
      return p[n];
  }
}

int main() {
  cin >> n >> x;
  FOR(i,1,n+1){
    a[i]=2*a[i-1]+3;
    p[i]=2*p[i-1]+1;
  }
  cout << f(n,x-1) << endl;
}

Measured memory_bytes: 256
import sys
w=""
a=[]
while (w!="0 0"):
    w=input()
    a.append(w)
a.pop()
for st in a:
    b=st.split()
    h=int(b[0])
    w=int(b[1])
    for i in range(h):
        for j in range(w):
            sys.stdout.write("#")
        sys.stdout.write("\n")
    sys.stdout.write("\n")

Measured memory_bytes: 6308
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1
from operator import mul
from functools import reduce

def cmb(n, r):
  if not n >= r:return 0
  r = min(n-r, r)
  if r == 0:
      return 1
  over = reduce(mul, range(n, n - r, -1))
  under = reduce(mul, range(1, r + 1))
  return over // under


n,m = map(int,input().split())
print(cmb(n,2)+cmb(m,2))


Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
#define ld long double
#define ll long long int
#define ull unsigned long long int
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define all(a) (a).begin() (a).end()
 
int main(){
	int x,y,a,b,c;
	cin >>x>>y>>a>>b>>c;
        ll app[a], org[b], ext[c];
	for(int i = 0 ; i < a ; i++)cin>>app[i];
	for(int j = 0 ; j < b ; j++)cin>>org[j];
	for(int i = 0 ; i < c ; i++)cin>>ext[i];
	sort(app, app+a,greater<int>());
	sort(org, org+b,greater<int>());
	sort(ext, ext+c,greater<int>());
 
        long long int ans =0;
	ll sol[x+y];
	memset(sol,0,sizeof(sol));
	for(int i = 0; i <min(a,x); i++)
		sol[i]=app[i];
	for(int i = min(a,x); i <min(a,x)+min(b,y);i++)
		sol[i]=org[i-min(a,x)];
	sort(sol,sol+x+y,greater<int>());
	int i = x+y-1;
	int j = 0;
        
	while(j<c && i>=0){
		if(sol[i] < ext[j]){
			sol[i] = ext[j];
			j++;i--;
		}
		else break;
	}
	for(int i = 0 ; i < x+y; i++){
		ans+=sol[i];
	}
	cout<<ans<<"\n";
return 0;
}

Measured memory_bytes: 3968
#include <bits/stdc++.h>
using namespace std;
#define int long long
int n,a[100005],hz[100005];
char s[100005];
int max(int x,int y)
{
	return x>y?x:y;
}
signed main()
{
	scanf("%lld",&n);
	for(int i=1;i<n;++i)
	{
		scanf("%lld",&a[i]);
		scanf(" %c",&s[i]);
	}
	scanf("%lld",&a[n]);
	s[0]='+';
	int ans=0;
	for(int i=1;i<=n;++i)
	{
		if(s[i-1]=='+')ans+=a[i];
		else ans-=a[i];
	}
	hz[n]=a[n];
	for(int i=n-1;i>=1;--i)hz[i]=hz[i+1]+a[i];
	int now=0;
	for(int i=1;i<=n;++i)
	{
		if(s[i-1]=='+')now+=a[i];
		if(s[i-1]=='-')
		{
			now-=a[i];
		  int hh=now;
			int j=i;
			while(j<n&&s[j]!='-')
			{
				hh-=a[j+1];
				j++;
			}
			if(j>=n)break;
			hh+=hz[j+1];
			ans=max(ans,hh);
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 1920
program ec12;
var 
	n,m,i,j,max,min:longint;
	a:array[1..301,1..301] of longint;
	vis,step:array[1..301] of longint;
	vis1:array[1..301] of boolean;
begin 
	readln(n,m);
	for i:=1 to n do 
	for j:=1 to m do 
	read(a[i,j]);
	min:=n;
	for i:=1 to n do 
	step[i]:=1;
	fillchar(vis1,sizeof(vis1),true);
	while true do 
	begin 	
		fillchar(vis,sizeof(vis),0);
		for i:=1 to n do 
		inc(vis[a[i,step[i]]]);
		max:=1;
		for i:=2 to m do 
		begin 	
			if vis[max]<vis[i] then 
			max:=i;
		end;
		if vis[max]<min then 
		min:=vis[max];
		vis1[max]:=false;
		for i:=1 to n do 
		begin 
			while (not vis1[a[i,step[i]]]) and (step[i]<=m) do
			inc(step[i]);
			if step[i]>m then 
			begin 
				writeln(min);
				halt;
			end;
		end;
	end;
	writeln(min);
end. 

Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
#include<climits>
#include<vector>
#include<utility>//pair
#include<cmath>//abs,sqrt
#include<cstring>
#include<map>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define prin(arg) cout<<arg<<"\n"
#define prin2(arg1,arg2) cout<<arg1<<" "<<arg2<<"\n"
#define fill(arg,n) memset(arg,n,sizeof(arg))
using namespace std;
typedef long long ll;
typedef pair<int,int> pi;
const int INF=1e+9;
const ll INFLL=1e+17;
int main(){
  int n;
  ll T;
  cin>>n>>T;
  ll t[200010];
  rep(i,n) cin>>t[i];
  ll res=0;
  rep(i,n-1){
    if(t[i+1]-t[i]>T){
      res+=T;
    }
    else{
      res+=t[i+1]-t[i];
    }
  }
  res+=T;
  prin(res);
      


  

  return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#include<set>
#define ll long long 
#include <string>
using namespace std;

int main()
{
	ll int x,d;
	cin>>x;
	ll int s=0;
	d=x/500;
	s+=d*1000;
	x=x%500;
	d=x/5;
	s+=d*5;
	x=x%5;
	cout<<s<<endl;
	
}
	
 


Measured memory_bytes: 384
import math
import copy
import fractions
import numpy as np
from functools import reduce

# ===FUNCTION===

def getInputNum():
    inputNum = int(input())
    return inputNum

def getInputListInt():
    outputoData = []
    inputData = input().split()
    outputData = [int(n) for n in inputData]

    return outputData

def getSomeInputInt(n):
    outputDataList = []
    for i in range(n):
        inputData = int(input())
        outputDataList.append(inputData)

    return outputDataList

def getSomeInputListInt(n):
    inputDataList = []
    outputDataList = []
    for i in range(n):
        inputData = input().split()
        inputDataList = [int(n) for n in inputData]
        outputDataList.append(inputDataList)

    return outputDataList

# ===CODE===

n, = map(int, input().split())
data = getInputListInt()

gcdNormal = np.zeros(n)
gcdReverse = np.zeros(n)

ans = 0

for i in range(1, n):
    if i==1:
        ans = fractions.gcd(data[i-1], data[i])
        gcdNormal[i] = ans
        gcdNormal[0] = data[0]
    else:
        gcdans = fractions.gcd(ans, data[i])
        ans = min(ans, gcdans)
        gcdNormal[i] = ans

ans = 0

for i in range(n-2, -1, -1):
    if i==n-2:
        ans = fractions.gcd(data[i], data[i+1])
        gcdReverse[i] = ans
        gcdReverse[i+1] = data[i+1]
    else:
        gcdans = fractions.gcd(ans, data[i])
        ans = min(ans, gcdans)
        gcdReverse[i] = ans

ans= 0
for i in range(n):
    if i ==0:
        ans = max(ans, gcdReverse[1])
    elif i == n-1:
        ans = max(ans, gcdNormal[n-2])
    else:
        ans = max(ans, fractions.gcd(gcdNormal[i-1], gcdReverse[i+1]))

print(int(ans))

Measured memory_bytes: 24104
#include<bits/stdc++.h>
using namespace std;
const int maxn=3e5+10,mod=1e9+7;
void plusle(int &a,int b){a+=b;if(a>=mod)a-=mod; return;}
void minun(int &a,int b){a-=b; if(a<0)a+=mod; return;}
int add(int a,int b) {a+=b;return a>=mod?a-mod:a;}
int sub(int a,int b) {a-=b;return a<0?a+mod:a;}
int mul(int a,int b) {return (int)((long long)a*b%mod);}
int power(int a,int b) {int res=1;while (b>0) {if (b&1) {res=mul(res,a);}a=mul(a,a);b>>=1;}return res;}
int n,ans=1,dep;
bool d[maxn];
char s[maxn];
vector<char> st;

int main(){
    scanf("%d%s",&n,s+1);
    for(int i=1;i<=2*n;i++){
        if(st.empty()){
            if(s[i]!='B')return !printf("0");
            st.push_back('B');
            dep++;
            continue;
        }
        if(s[i]!=st.back()){
            st.push_back(s[i]);
            dep++;
            continue;
        }
        ans=mul(ans,dep);
        dep--;
        st.pop_back();
    }
    for(int i=2;i<=n;i++)
        ans=mul(ans,i);
    printf("%d\n",st.empty()?ans:0);
}
/*
    Good Luck
        -Lucina
*/


Measured memory_bytes: 768
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {

		Scanner sc=new Scanner(System.in);

		int n=sc.nextInt();
		
		int[] a=new int[n];
		
		for(int i=0;i<n;i++) {
			a[i]=sc.nextInt();
		}
		
		//偶数を正とする
		long counter=0;
		
		long sum=0;
		
		for(int i=0;i<n;i++) {
			
			sum+=a[i];
			
			if(i%2==0 && sum<=0) {
				
				//-aだったら+1の操作をa回で0になり
				//正にするならそこからさらに+1
				
				counter+=Math.abs(sum)+1;
				sum=1;
				
			}else if(i%2==1 && sum>=0){
				
				//+aだったらa回の-1と1回の-1でマイナス
				counter+=sum+1;
				sum=-1;
				
			}
			
			
		}
		
		long counter1=0;
		long sum1=0;
		
		
		
		//奇数を正
		for(int i=0;i<n;i++) {
			
			sum1+=a[i];
			
			if(i%2==0 && sum1>=0) {
				
				//+aだったらa回の-1と1回の-1でマイナス
				counter1+=sum1+1;
				sum1=-1;
				
			}else if(i%2==1 && sum1<=0){
				//-aだったら+1の操作をa回で0になり
				//正にするならそこからさらに+1
				
				counter1+=Math.abs(sum1)+1;
				sum1=1;
			}
			
			
		}
		
		
		System.out.println(Math.min(counter,counter1));


	}
	
	
}


Measured memory_bytes: 49796
#include <bits/stdc++.h>
#define M 1000005
#define mod 1000000007
#define inv2 500000004ll
#define PB push_back
#define MP std::make_pair
#define FI first
#define SE second
typedef long long ll;
int n, A[M], B[M], F[M], invF[M], col[M], S[M];
ll fac[M], fac_inv[M], inv[M];
std::vector <int> Vec[M];
int read() {
	char c = getchar(); int ans = 0;
	while (c < '0' || c > '9') c = getchar();
	while (c >= '0' && c <= '9') ans = ans * 10 + c - '0', c = getchar();
	return ans;
}
void Write(int x) {
	if (x < 10) putchar(x + '0');
	else Write(x / 10), putchar(x % 10 + '0');
}
int Add(int x, int y) {return (x += y) >= mod ? x - mod : x;}
void add(int &x, int y) {if ((x += y) >= mod) x -= mod;}
ll invs(int x) {return x == 1 ? 1 : (mod - mod / x) * invs(mod % x) % mod;}
void init_mod(int n) {
	fac[0] = 1;
	for (int i = 1; i <= n; i++) fac[i] = fac[i - 1] * i % mod; fac_inv[n] = invs(fac[n]);
	for (int i = n; i; i--) fac_inv[i - 1] = fac_inv[i] * i % mod;
	for (int i = 1; i <= n; i++) inv[i] = fac[i - 1] * fac_inv[i] % mod;
}
namespace BIT {
	#define lowbit(x) (x & -x)
	int X[M];
	void Insert(int x, int y) {while (x <= n) add(X[x], y), x += lowbit(x);}
	int query(int x) {int ans = 0; while (x) add(ans, X[x]), x -= lowbit(x); return ans;}
	#undef lowbit
}
int solve(int l, int r, int id) {
	F[l] = invF[l] = 1; ll ans = 0;
	for (int i = l + 1; i <= r; i++)
		F[i] = F[i - 1] * (B[i] - 1ll) % mod * inv[B[i]] % mod,
		invF[i] = invF[i - 1] * inv[B[i] - 1] % mod * B[i] % mod;
	for (auto i : Vec[id]) ans = (ans + (ll)BIT::query(i - 1) * F[i]) % mod, BIT::Insert(i, invF[i]);
	for (auto i : Vec[id]) BIT::Insert(i, mod - invF[i]);
	for (auto i : Vec[id]) ans = (ans - (ll)BIT::query(n - i) * invF[i]) % mod, BIT::Insert(n + 1 - i, F[i]);
	for (auto i : Vec[id]) BIT::Insert(n + 1 - i, mod - F[i]);
	return ans;
}
ll calc() {
	ll ans = 0;
	for (int i = 1; i <= n; i++)
		ans += i - 1 - BIT::query(A[i]), BIT::Insert(A[i], 1);
	return ans;
}
int main() {
	n = read(); ll tmp = 1, ans = 0; init_mod(n);
	for (int i = 1; i <= n; i++) ++B[A[i] = read()];
	for (int i = n; i; i--) ans += B[i] * (B[i] - 1ll) / 2, B[i] += B[i + 1];
	for (int i = 1; i <= n; i++) tmp = tmp * (B[i] -= (n - i)) % mod;
	if (tmp == 0) return putchar('0'), 0; if (B[1] != 1) S[++*S] = 1;
	for (int i = 1; i <= n; i++) if (B[i] == 1) S[++*S] = i; S[++*S] = n + 1;
	for (int i = 1; i < *S; i++) std::fill(col + S[i], col + S[i + 1], i);
	for (int i = 1; i <= n; i++) Vec[col[A[i]]].PB(A[i]);
	for (int i = 1; i < *S; i++) ans += solve(S[i], S[i + 1] - 1, i);
	ans = (ans + 2 * calc()) % mod * tmp % mod * inv2 % mod;
	return Write((ans + mod) % mod), 0;
}


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

using namespace std;

int MOD = 1e9+7;
int MAXN = 1e6;

int main() {
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	#if LOCAL
	freopen("b.in", "r", stdin);
	#endif
    int N;
	cin>>N;
    vector<int> A,prev(MAXN,-1);
    int last = -1;
    for(int i=0;i<N;i++) {
        int next;
        cin>>next;
        if(next==last)continue;
        A.push_back(next);
        last = next;
    }
    N = A.size();
    vector<long long> DP(N,0);
    DP[0]=1;
    prev[A[0]]=0;
    for(int i=1;i<N;i++) {
        DP[i]=DP[i-1];
        if(prev[A[i]]!=-1) {
            DP[i]=(DP[i]+DP[prev[A[i]]])%MOD;
        }
        prev[A[i]]=i;
    }
    //for(int i=0;i<N;i++) {
     //   cout<<"AUT: "<<A[i]<<", DOUT: "<<DP[i]<<endl;
    //}
    cout<<DP[N-1]<<endl;
	return 0;
}

Measured memory_bytes: 6644
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=(n-1);i>=0;i--)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(a-1);i>=(b);i--)
#define all(x) (x).begin(), (x).end()
const int INF = 1e18;
const int MOD = 1e9+7;
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef string str;
typedef vector<str> vstr;
void print() {cout<<endl;}template<class Head,class...Tail>void print(Head&&head,Tail&&...tail){cout<<head;if(sizeof...(tail)!=0)cout<<" ";print(forward<Tail>(tail)...);}template<class T>void print(vector<T>&vec){for(auto&a:vec){cout<<a;if(&a!=&vec.back())cout<<" ";}cout<<endl;}template<class T>void print(vector<vector<T>>&df){for(auto&vec:df){print(vec);}}
template<class T=int>T in() {T x;cin>>x;return(x);}
template<class T=int>vector<T> input_to_vector(int n) {vector<T>x;rep(i,n){T a;cin>>a;x.push_back(a);}return(x);}

signed main(){
    int n = in();
    vint P = input_to_vector(n);
    rep(i, n) {
        int a = in();
        P.push_back(a);
    }
    sort(all(P));
    P[n-1] = P[n-1] / 2;
    int ans = 0;
    rep(i, n){
        ans += P[i];
    }
    print(ans);
}

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



int main(void){
    

    int A,B;
    
    cin >> A >> B;
    
    for(int i = 0; i < 2000;i++){
        //cout << i <<":"<<0.08*i<<":"<<0.1*i<<endl;
        if(int(i*0.08) == A && int(i*0.1) == B){
            cout << i << endl;
            return 0;
        }
        
    }
    
    cout << -1 << endl;
    return 0;    
}

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

int main() {
	int a, b, c, d, e, k;
	cin >> a >> b >> c >> d >> e >> k;
	
	if(e-a <= k){
		cout << "Yay!" << "\n";
	}
	else{
		cout << ":(" << "\n";
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <utility>
#include <map>
#include <list>
#include <climits>
#include <set>
#include <deque>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>

// #define cerr if(false)cerr
#define watch(x) cerr << "> " << #x << ": " << x << "\n";

using namespace std;

template <typename T>
std::ostream &operator <<(std::ostream &out, vector<T> &v) {
	for (typename vector<T>::size_type i = 0; i < v.size(); ++i)
		out << v[i] << " ";
	out << "\n";
    return out;
}
template <typename T, typename N>
std::ostream &operator <<(std::ostream &out, vector<pair<T, N> > &v) {
	for (size_t i = 0; i < v.size(); ++i)
		out << "(" << v[i].first << ", " << v[i].second << ") ";
	out << "\n";
    return out;
}
template <typename T>
std::ostream &operator <<(std::ostream &out, vector<vector<T> > &v) {
	for (size_t i = 0; i < v.size(); ++i) {
		for (size_t j = 0; j < v[i].size(); ++j) {
			out << v[i][j] << " ";
		}
		out << "\n";
	}
   	return out;
}

int main() {

	std::ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	int n, k;
	cin >> n >> k;

	set<int> unique;
	map<int, int> occs;
	int b;	
	for (int i = 0; i < n; ++i) {
		cin >> b;
		unique.insert(b);
		++occs[b];
	}

	if (unique.size() <= k) {
		cout << "0\n";
	} else {
		vector<int> count;
		for (auto it = occs.begin(); it != occs.end(); ++it) {
			count.push_back(it->second);
		}

		sort(count.begin(), count.end());
		int curr = unique.size();
		int ans = 0;
		int i = 0;
		while (curr > k) {
			ans += count[i];
			--curr;
			++i;
		}	

		cout << ans << "\n";
	}

	return 0;

}

Measured memory_bytes: 20216
#define _CRT_SECURE_NO_WARNINGS
#include<utility>
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<cmath>
#include<ctime>
#include<functional>
#include<random>

#define mp make_pair
#define X first
#define Y second
using namespace std;
typedef long long ll;
typedef long double ld;


mt19937 gen;


int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    string s;  cin >> s;
    string y = "2018";
    for(ll i = 0 ;i < 4; i++) s[i] = y[i];
    cout << s;
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast,inline,unroll-loops,fast-math")
#include <iostream>
#include <algorithm>
#include <cstdio>
using namespace std;

int main(void)
{
    int a, b;

    cin >> a >> b;
    cout << max(0, a - b * 2) << endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] x = new int[n];
    int[] y = new int[n];
    for(int i=0;i<n;i++){
      x[i] = sc.nextInt();
      y[i] = sc.nextInt();
    }
    double kumi=1;
    for(int i=n;i>0;i--){
      kumi*=i;
    }
    double loads=0;
    for(int j=n-1;j>0;j--){
      loads+=j;
    }
    double count = kumi*(n-1)/loads;
    double ans=0;
    for(int i=0;i<n;i++){
      for(int j=i+1;j<n;j++){
         ans += (Math.sqrt(Math.pow(Math.abs(x[i]-x[j]),2)+Math.pow(Math.abs(y[i]-y[j]),2)))/kumi;
      }
    }
    ans*=count;
    System.out.println(ans);
    }
  }

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

struct edge {
  int id;
  int to;
};

int main() {
  int n;
  cin >> n;
  vector<edge> tree[n+1];
  vector<int> color(n, 0);

  for ( int i = 1; i < n; i++ ) {
    int a, b;
    cin >> a >> b;
    tree[a].push_back({i, b});
    tree[b].push_back({i, a});
  }

  queue<int> que;
  que.push(1);
  int k = 0;
  while ( !que.empty() ) {
    int v = que.front();
    que.pop();
    k = ( tree[v].size() > k ) ? tree[v].size() : k;

    int used_color;
    for ( int i = 0; i < tree[v].size(); i++ ) {
      if ( color[tree[v][i].id] != 0 ) {
        used_color = color[tree[v][i].id];
      }
    }

    int now_color = 1;
    for ( int i = 0; i < tree[v].size(); i++ ) {
      if ( color[tree[v][i].id] != 0 ) { continue; }
      if ( now_color == used_color ) { now_color++; }
      color[tree[v][i].id] = now_color++;
      que.push(tree[v][i].to);
    }
  }

  cout << k << endl;
  for ( int i = 1; i < n; i++ ) {
    cout << color[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 9608
// D - Sum of Large Numbers
#include <bits/stdc++.h>
using namespace std;

int main(){
	long long ans = 0, MOD = 1'000'000'007;
	int N,K; cin>>N>>K;
	vector<long long> cnt(N+2); // [0,N] の N+1 個の累積和
	for(int i=0; i<=N; ++i) cnt[i+1] += cnt[i] + i;
	for(int k=K; k<=N+1; ++k) // k:[0,N+1] k 個選択時の値の種数(max-min+1)
		ans = (ans + (cnt[N+1] - cnt[N+1-k]) - cnt[k] + 1) % MOD;
	cout<< ans <<endl;
}

Measured memory_bytes: 4668
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

struct node
{
  unsigned int key;
  struct node *next;
  struct node *prev;
};

typedef struct node *NodePointer;

NodePointer nil;

NodePointer listSearch(int key)
{
  NodePointer cur;
  cur = nil->next;
  while (cur != nil && cur->key != key)
    cur = cur->next;
  return cur;
}

void init()
{
  nil = malloc(sizeof(struct node));
  nil->next = nil;
  nil->prev = nil;
}

void printList()
{
  NodePointer cur = nil->next;
  int isf = 1;
  while (1)
  {
    if (cur == nil)
      break;
    if (isf == 0)
      printf(" ");
    printf("%d", cur->key);
    cur = cur->next;
    isf = 0;
  }
  printf("\n");
}

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

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

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

void delete (int key)
{
  deleteNode(listSearch(key));
}

void insert(int key)
{
  NodePointer x;
  x = malloc(sizeof(struct node));
  x->key = key;
  x->next = nil->next;
  nil->next->prev = x;
  nil->next = x;
  x->prev = nil;
}

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

  printList();
  return 0;
}



Measured memory_bytes: 33040
// ref. https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

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

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

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

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

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

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

fn main() {
    input!{
        n: usize,
        s: String,
    }

    let mut converted: Vec<char> = s.chars().collect();
    let mut result: String = converted[0].to_string();
    let mut last_char = converted[0];

    for i in 1..n{
        if last_char != converted[i] {
            last_char = converted[i];
            result.push(converted[i]);
        };
    }

    println!("{}", result.len());
}


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

string ans;

int d[4];

bool dfs(int num,int sum,string fomu){
  if(sum == 7 && num == 4){
    ans = fomu + "=7";
    return true;
  }
  else if(num == 4)return sum == 7;

  if(dfs(num+1,sum+d[num],fomu + "+" + to_string(d[num])))return true;
  if(dfs(num+1,sum-d[num],fomu + "-" + to_string(d[num])))return true;



  return false;
}

int main(){
  int S;
  cin >> S;
  for(int i = 3;i > -1;i--){
    d[i] = S % 10;
    S /= 10;
  }


  string str = to_string(d[0]);

  dfs(1,d[0],str);

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256