akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
  
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
 
#define FS              ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll              long long int
#define ld              long double
#define pb              push_back
#define bp              __builtin_popcount
#define sz              size()
#define ff              first
#define ss              second
#define vll             vector<ll>
#define vbool           vector<bool>
#define vpll            vector<pair<ll,ll>>
#define pll             pair<ll,ll>
#define vllv            vector<vector<ll>>
#define setpri(x)       cout<<setprecision(x)<<fixed;
#define all(v)          v.begin(),v.end()
#define allr(v)         v.rbegin(),v.rend()
#define yesr {cout<<"YES"<<endl;return;}
#define nor {cout<<"NO"<<endl;return;}
// getline (std::cin,name);
ll MOD=1e9+7;
ll ceil1(ll n,ll x){return (n-1)/x+(n>0);}

ll gcd(ll a,ll b){return __gcd(a,b);}
ll lcm(ll a,ll b){return (max(a,b)/gcd(a,b))*min(a,b);}

ll pow1(ll n,ll m ,ll mod=MOD );
ll pow2(ll n,ll k);

ll modinv(ll n,ll mod=MOD){  return pow1(n,mod-2,mod);}

bool func(pair<ll,ll> &a,pair<ll,ll> &b ){
        if(a.ff != b.ff)return a.ff < b.ff;
        return a.ss > b.ss;
}

ll const N=(ll)2e5+11;
ll const LG=(ll)log2(N)+1;


void solve(){
        ll i,j,k,l,n,m,x,y,z,r;
      
      vll a(5);
      n=5;
      cin>>m;
      ll tt=1e15;
      for(i=0;i<5;i++){
              cin>>a[i];
              tt=min(tt,a[i]);
      }
      ll ans=0;
      for(i=n-1;i>=0;i--){
              if(a[i]==tt){
                      ans=ceil1(m,tt);
                      ans+=n-1;
              }
      }
      cout<<ans<<endl;
      
        
        
}       
int main(){
        FS;
        
        ll i,j,k,n,m,x,y,z,q;
        q=1;
        // cin>>q;
        for(ll tc=1;tc<=q;tc++){
                // cout<<"Case #"<<tc<<": ";
                solve();
        }
        return 0;
}


ll pow1(ll n,ll m,ll mod){
        if(m==0)return 1;
        
        if(m%2==0)return pow1((n*n)%mod,m/2,mod);
    	
    	return (pow1((n*n)%mod,m/2,mod)*n)%mod;
}

ll pow2(ll n,ll k){
        ll ans=1;
            while(k>0){
                if(k%2==1)ans=ans*n;
                n=n*n;
                k/=2;
            }
            return ans;
}


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

#define PB(x) push_back(x)
#define MP(x,y) make_pair(x,y)

map<long long,long long> mp;
long long ty[5];
long long nty;
vector<long long> a[5];

main()
{
	long long n;
	long long w;
	scanf("%lld %lld",&n,&w);
	for(long long i=0;i<n;i++)
	{
		long long v;
		long long w;
		scanf("%lld %lld",&w,&v);
		if(mp[w]==0)
		{
			nty++;
			ty[nty]=w;
			mp[w]=nty;
			a[mp[w]].PB(v);
		}
		else
		{
			a[mp[w]].PB(v);
		}
	}
	for(long long i=1;i<=nty;i++)
		sort(a[i].begin(),a[i].end());
	long long ans=0;
	a[1].PB(0);
	a[2].PB(0);
	a[3].PB(0);
	a[4].PB(0);
	long long s1=0,s2=0,s3=0,s4=0;
	for(long long i=a[1].size()-1,ni=0;i>=0;i--,ni++)
	{
		long long all=0;
		long long wei=ni*ty[1];
		s1+=a[1][i];
		all=s1;
		if(wei>w)break;
		s2=0;
		ans=max(ans,all);
		for(long long j=a[2].size()-1,nj=0;j>=0;j--,nj++)
		{
			long long wei2=nj*ty[2];
			s2+=a[2][j];
			long long all2=s2;
			if(wei+wei2>w)break;
			s3=0;
			ans=max(ans,all+all2);
			for(long long k=a[3].size()-1,nk=0;k>=0;k--,nk++)
			{
				long long wei3=nk*ty[3];
				s3+=a[3][k];
				long long all3=s3;
				if(wei+wei2+wei3>w)break;
				s4=0;
				ans=max(ans,all+all2+all3);
				for(long long l=a[4].size()-1,nl=0;l>=0;l--,nl++)
				{
					long long wei4=nl*ty[4];
					s4+=a[4][l];
					long long all4=s4;
					if(wei+wei2+wei3+wei4>w)break;
					ans=max(ans,all+all2+all3+all4);
				}
			}
		}	
	}
	printf("%lld",ans);
}

Measured memory_bytes: 256
H, W = map(int, input().split())
S = [list(input()) for _ in range(H)]

# print(S)

INF = 10 ** 6

dp = [[INF] * W for i in range(H)]
if S[0][0] == ".":
    dp[0][0] = 0
else:
    dp[0][0] = 1

# print(dp)

for i in range(H):
    for j in range(W):
        if i == 0 and j == 0:
            continue

        if S[i][j] == "#":
            flip = 1
        else:
            flip = 0

        if i == 0:
            if S[i][j - 1] == "#":
                flip = 0
            dp[i][j] = dp[i][j - 1] + flip
        elif j == 0:
            if S[i - 1][j] == "#":
                flip = 0
            dp[i][j] = dp[i - 1][j] + flip
        else:
            flip1 = 0
            flip2 = 0
            if flip == 1 and (S[i - 1][j] == "."):
                flip1 = 1
            if flip == 1 and S[i][j - 1] == ".":
                flip2 = 1

            dp[i][j] = min(dp[i - 1][j] + flip1, dp[i][j - 1] + flip2)

print(dp[H - 1][W - 1])



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

readline = sys.stdin.buffer.readline
def readstr():return readline().rstrip().decode()
def readstrs():return list(readline().decode().split())
def readint():return int(readline())
def readints():return list(map(int,readline().split()))
def printrows(x):print('\n'.join(map(str,x)))
def printline(x):print(' '.join(map(str,x)))

n,k,s = readints()

printline([s]*k+[s%10**9+1]*(n-k))

Measured memory_bytes: 79756
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define FORL(i,x) for(int i=head[x];i;i=nxt[i])
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define PB push_back
#define MP make_pair
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;
	vector<int> a,b,c;
  int p,q,r;
	for(int i=0;i<N;i++) {
    cin >> p; 
    a.PB(p);
  }
  for(int i=0;i<N;i++) {
    cin >> q; 
    b.PB(q);
  }
  for(int i=0;i<N;i++) {
    cin >> r; 
    c.PB(r);
    }


  sort(ALL(a));
  sort(ALL(b));
  sort(ALL(c));

  long long ans = 0;

  FOR(i,0,N-1){
    auto it = lower_bound(ALL(a),b[i]);
    long long min = it-a.begin();
    it = upper_bound(ALL(c),b[i]);
    long long max = c.end()-it;
    ans += min*max;
    // cout << min << " " << max << endl;
  }

  cout << ans << endl;

}

Measured memory_bytes: 1784
using namespace std;

int main(void){
  int a,b,tmp;

  while(cin>>a>>b){
    if(a<b) swap(a,b);

    while(1){
      if(a%b==0) break;

      tmp = a%b;
      a = b;
      b = tmp;
    }
    cout<<b<<endl;
  }

  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int n,ans=0;
    cin >> n;
    vector<int> d(n);
    for (int i = 0; i < n; i++)
    {
        cin >> d.at(i);
    }

    sort(d.begin(), d.end());

    if (d.at(n/2-1) == d.at(n/2)){
        ans = 0;
    }
    else //if(d.at(n/2 != d.at(n/2+1))){
    {
        ans = d.at(n / 2 ) - d.at(n / 2-1);
    }

    cout << ans << endl;
}

Measured memory_bytes: 640
import java.util.Scanner;
public class Main
{
	public static void main(String[] args) 
	{
		Scanner in=new Scanner(System.in);
		for(;;)
		{
			double S1=0,S2=0;
			int angle1=0,angle2=0;
			int m1=in.nextInt();
			if(m1==0)
				return;
			for(int i=0;i<m1-1;i++)
			{
				double vi=in.nextInt();
				angle1+=vi;
				S1+=Math.sin(vi*Math.PI/180);
			}
			S1+=Math.sin((360-angle1)*Math.PI/180);
			int m2=in.nextInt();
			for(int i=0;i<m2-1;i++)
			{
				double vi=in.nextInt();
				angle2+=vi;
				S2+=Math.sin(vi*Math.PI/180);
			}
			S2+=Math.sin((360-angle2)*Math.PI/180);
			if(Math.abs(S1-S2)<1e-9)//1e-8=0.00000001
				System.out.println(0);
			else if(S1>S2)
				System.out.println(1);
			else if(S2>S1)
				System.out.println(2);
			
		}
	}
}

Measured memory_bytes: 12000
#include <cstdio>
#include <math.h>
#include <iostream>
using namespace std;

int solve(int n)
{
	int total = 0;
	for (int i = 1; i * i <= n ; i++)
	{
		if (n % i == 0)
		{
			total += i;
			if (i * i != n) total += n / i;
		}
	}
	total -= n;
	return total - n;
}

int main()
{
	int n;
	while (scanf("%d", &n) != EOF)
	{
		if (n == 0) return 0;
		int result = solve(n);
		if (result == 0)
			puts("perfect number");
		else if (result < 0)
			puts("deficient number");
		else if (result > 0)
			puts("abundant number");
	}
}

Measured memory_bytes: 0
#include <stdbool.h>
#include <stdio.h>

struct Card
{
    char suit;
    int value;
};

static void print(struct Card A[], int N)
{
    for (int i = 0; i < N; i++) {
        if (i > 0)
            printf(" ");
        printf("%c%d", A[i].suit, A[i].value);
    }
    printf("\n");
}

static void bubbleSort(struct Card A[], int N)
{
    for (int i = 0; i < N; i++) {
        for (int j = N - 1; j >= i + 1; j--) {
            if (A[j].value < A[j - 1].value) {
                struct Card tmp = A[j];
                A[j] = A[j - 1];
                A[j - 1] = tmp;
            }
        }
    }
}

static void selectionSort(struct Card A[], int N)
{
    for (int i = 0; i < N; i++) {
        int minj = i;
        for (int j = i + 1; j < N; j++) {
            if (A[j].value < A[minj].value) {
                minj = j;
            }
        }
        if (i != minj) {
            struct Card tmp = A[i];
            A[i] = A[minj];
            A[minj] = tmp;
        }
    }
}

static bool isStable(struct Card C1[], struct Card C2[], int N)
{
    for (int i = 0; i < N; i++) {
        if (C1[i].suit != C2[i].suit) {
            return false;
        }
    }

    return true;
}

int main()
{
    int N;
    struct Card C1[36], C2[36];

    scanf("%d", &N);

    for (int i = 0; i < N; i++) {
        scanf("%*c%c%d", &C1[i].suit, &C1[i].value);
        C2[i] = C1[i];
    }

    bubbleSort(C1, N);
    print(C1, N);
    printf("Stable\n");

    selectionSort(C2, N);
    print(C2, N);
    printf(isStable(C1, C2, N) ? "Stable\n" : "Not stable\n");
}


Measured memory_bytes: 2104
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>
using namespace std;

typedef long long LL;
typedef vector<int> VI;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i)
#define eprintf(...) fprintf(stderr, __VA_ARGS__)

template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }
template<class Iter> void rprintf(const char *fmt, Iter begin, Iter end) {
    for (bool sp=0; begin!=end; ++begin) { if (sp) putchar(' '); else sp = true; printf(fmt, *begin); }
    putchar('\n');
}

int N;
char S[111];

void MAIN() {
    scanf("%s", S);

    int n = count(S, S+6, '1');
    printf("%d\n", n);
}

int main() {
    int TC = 1;
//    scanf("%d", &TC);
    REP (tc, TC) MAIN();
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
void read(long long &x)
{
    char ch;bool ok;
    for(ok=0,ch=getchar();!isdigit(ch);ch=getchar())if(ch=='-')ok=1;
    for(x=0;isdigit(ch);x=x*10+ch-'0',ch=getchar());if(ok)x=-x;
}
#define rg register
const int maxn=110;
long long a,b,x,y,l,r,ans,ll,rr;
int aa[maxn],bb[maxn],lena,lenb,len,k;
int main()
{
    read(a),read(b);x=a,y=b;
    while(a)aa[++lena]=a&1,a>>=1;
    while(b)bb[++lenb]=b&1,b>>=1;
    for(rg int i=max(lena,lenb);i;i--)
	{
        if(aa[i]!=bb[i]){len=i;break;}
        x-=1ll*aa[i]<<(i-1);
        y-=1ll*bb[i]<<(i-1);
    }
    for(rg int i=len-1;i;i--)if(bb[i]){k=i;break;}
    l=x,r=(1ll<<(len-1))+(1ll<<k)-1;
    ll=(1ll<<(len-1))+x,rr=(1ll<<len)-1;
    if(ll>r)ans=r-l+1+rr-ll+1;
    else ans=rr-l+1;
    printf("%lld\n",ans);
}


Measured memory_bytes: 256
import itertools

D, G = map(int, input().split())
L = [list(map(int, input().split())) for _ in range(D)]

num = D #生成するビット数
bit_list = list(itertools.product([0, 1], repeat=num))
tmp = 10 ** 6

for bit in bit_list:
    count = 0
    num = 0
    for i in range(D):
        if bit[i] == 1:
            count += L[i][0] *(i+1) * 100 + L[i][1]
            num += L[i][0]
            
    if count >= G:
        tmp = min(num, tmp)
        
    else:
        for i in range(1, D+1):
            if bit[D-i] == 0:
                for j in range(L[D-i][0]):
                    count += (D-i+1) * 100
                    num += 1
                    if count >= G:
                        break
                break
                
        if count >= G:
            tmp = min(num, tmp)
            
print(tmp)

Measured memory_bytes: 3188
#include <cstdio>
#include <vector>
#include <algorithm>

#define rep(i, n) for(int i = 0; i < (n); ++i)

using namespace std;

int n, m;
int h[1500];
int w[1500];

int main(){
	while(scanf("%d%d", &n, &m), n){
		rep(i, n){
			scanf("%d", &h[i]);
		}
		rep(i, m){
			scanf("%d", &w[i]);
		}
		vector<int> a;
		rep(i, n){
			int s = 0;
			for(int j = i; j < n; ++j){
				s += h[j];
				a.push_back(s);
			}
		}
		vector<int> b;
		rep(i, m){
			int s = 0;
			for(int j = i; j < m; ++j){
				s += w[j];
				b.push_back(s);
			}
		}
		sort(b.begin(), b.end());
		int ans = 0;
		rep(i, a.size()){
			ans += upper_bound(b.begin(), b.end(), a[i]) - lower_bound(b.begin(), b.end(), a[i]);
		}
		printf("%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 20180
import std.algorithm;
import std.range;
import std.stdio;
import std.math;
import std.array;
import std.string;
import std.conv;
import std.typecons;

/// 数列の読み込み
auto readNums() {
	return readln().chomp.split.map!(to!int).array;
}

/// 数の読み込み
auto readNum() {
	return readNums.front;
}

/// 指定行数読み込み
auto readRows(size_t rows) {
	return generate(() => readln().chomp).take(rows).array;
}

void main() {
    enum P = 10 ^^ 9 + 7;
    const n = readNum();
    long r = 1;
    foreach(i; 1 .. n + 1) {
        r = r * i % P;
    }
    writefln("%s", r);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update

using namespace std;
using namespace __gnu_pbds;

//find_by_order gives kth-largest element
//order_of_key gives the number of items in the set that are strictly smaller!!

// OT.find_by_order(k-1)
// 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

#define db(x) cerr << #x << "=" << x << endl
#define db2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define db3(x, y, z) cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl
#define db4(x, y, z, w) cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << "," << #w << "=" << w << endl
#define ll long long
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define mp make_pair
#define X first
#define Y second
#define sz(x) (int)((x).size())
#define pii pair<int,int>
#define MOD (ll)(1e9 + 7)
#define rep(i, n)    for(int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(int i = a; i <= (n); ++i)
#define repD(i, a, n)  for(int i = a; i >= (n); --i)
#define trav(a, x) for(auto& a : x)
typedef vector<int> vi;
#define inf (ll)(1e18)
#define double long double
#define int long long

//////////////////////
// const int N = 316330;


int32_t main() {

    ios::sync_with_stdio(false);
    cin.tie(0); 
    cout.tie(0);
    cout.precision(17);
    cout << fixed;
    int n;
    cin >> n;

    vector<int> v(n);
    rep(i,n) 
        cin >> v[i];

    multiset<double> S;
    rep(i,n)
        S.insert(1.0 * v[i]);

    while(sz(S) != 1) {
        auto it = S.begin();
        double first = *it;
        it ++;
        double second = *it;

        S.erase(S.begin());
        S.erase(S.begin());

        S.insert((first + second) / 2);
    } 

    cout << *S.begin() << '\n';
}


Measured memory_bytes: 256
local S = io.read("*l")

local abc = "abcdefghijklmnopqrstuvwxyz"
local have_abc_s = {}
for i = 1, abc:len()  do
	have_abc_s[abc:byte(i)] = false
end

for i = 1, S:len() do
	have_abc_s[S:byte(i)] = true
end

local out = "None"
for i = 1, abc:len() do
	if not have_abc_s[abc:byte(i)] then
		out = abc:sub(i, i)
		break
	end
end

print(out)


Measured memory_bytes: 2676
#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 mochi=0, pre=0;
  sort(vec.begin(), vec.end());
  for (int i = 0; i < N; i++) {
    if (pre != vec.at(i))
      mochi++;
    pre = vec.at(i);
  }
  cout << mochi << endl;
}

Measured memory_bytes: 256
import math
def comb(n, r):
  if n >= r:
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
  else:
    return 0
N = int(input())
K = int(input())
A = []
ans = 0


for i in range(K):
  n = int(str(N)[0])
  dig = len(str(N)) - 1
  A.append([n, dig])
  N -= n * 10**dig
  if N == 0:
    break
#print(A)

for i in range(len(A)):
  if A[i][1] >= K-i:
    ans += comb(A[i][1], K-i) * 9 ** (K-i) 
#    print(ans)
  ans += (A[i][0]-1) * comb(A[i][1], K-i-1) * 9 ** (K-i-1)
#  print(ans)
if len(A) == K:
  ans += 1


print(ans)

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

#define debug(s) cout << s << endl
#define debug1(s, t) cout << s << " " << t << endl
#define debug2(s, t, u) cout << s << " " << t << " " << u << endl
#define printvec(v)       \
    for (auto &&i : v)    \
        cout << i << " "; \
    cout << endl
#define rep(n, i) for (int i = 0; i < n; i++)

using namespace std;
using i64 = long long;

struct Sieve
{
    vector<int> prime_list;

    vector<int> isprime;

    Sieve(int MAX) : prime_list(), isprime(MAX, true)
    {
        isprime[0] = false;
        isprime[1] = false;
        int nsqrt = ceil(sqrt(MAX) + 0.1);
        for (int p = 2; p < nsqrt; p++)
        {
            if (!isprime[p])
                continue;
            prime_list.push_back(p);
            for (int mult = p * p; mult < MAX; mult += p)
                isprime[mult] = false;
        }
        for (int p = nsqrt; p < MAX; p++)
        {
            if (isprime[p])
                prime_list.push_back(p);
        }
    }
};

// 素数と、その何乗かを返す
vector<pair<int, int>> prime_factorize(i64 a, vector<int> &prime_list)
{
    vector<pair<int, int>> res;
    for (auto &&prime : prime_list)
    {
        int counter = 0;
        while (a % prime == 0)
        {
            counter++;
            a /= prime;
        }
        res.push_back(make_pair(prime, counter));
    }
    if (a != 1)
        res.push_back(make_pair(a, 1));
    return res;
}

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

    Sieve es(1000000);

    auto pfactor = prime_factorize(n,es.prime_list);

    int ct = 0;

    for (auto &&pf : pfactor)
    {
        int a = pf.second;
        if (a==0) 
        {
            continue;
        }
        int m = 1;
        //debug(a);
        while (m*(m+1)<2*a)
        {
            m++;
        }
        if (m*(m+1)!=2*a)
        {
            m--;
        }
        //debug1(pf.first,m);
        ct += m;
    }
    
    cout << ct << endl;


    return 0;
}

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

int main()
{
  int n;
  scanf("%d",&n);
  static char M[600][600];
  for(int i=0;i<n;i++){
    scanf("%s",M[i]);
  }
  int A[600]={0},B[600]={0},C=0;
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      if(M[i][j]=='#'){
	A[i]++;
	B[j]++;
	C++;
      }
    }
  }
  int ans;
  if(C==0){
    ans=-1;
  }
  else{
    ans=3*n;
    int K=0;
    for(int j=0;j<n;j++){
      if(B[j]<n){
	K++;
      }
    }
    for(int i=0;i<n;i++){
      int c=n-A[i]+K;
      if(B[i]==0){
	c++;
      }
      ans=min(ans,c);
    }
  }
  printf("%d\n",ans);
  return 0;
}


Measured memory_bytes: 512
#include <cstdio>
#include <vector>
using namespace std;

#define si static inline
#define gcu getchar_unlocked
si int in() {
	int c, n = 0;
	bool minus = false;
	if ((c = gcu()) == '-')
		minus = true;
	else
		ungetc(c, stdin);
	while ((c = gcu()) >= '0' && c <= '9')
		n = 10 * n + (c - '0');
	return minus ? -n : n; }
#define pcu putchar_unlocked
si void out(int n) {
	static char buf[20];
	char *p = buf;
	bool minus = false;
	if(n < 0) minus = true, n *= -1;
	if (!n) *p++ = '0';
	else while (n) *p++ = n % 10 + '0', n /= 10;
	if (minus) *p++ = '-';
	while (p != buf) pcu(*--p); }
si void out(const char *s) {
	while (*s) pcu(*s++); }
template <typename head, typename... tail>
si void out(head&& h, tail&&... t) {
	out(h); out(move(t)...); }

typedef vector<int> v;
struct node { int p = -1, l = -1, r = -1, d = -1, h = -1;};
typedef vector<node> vn;

int depth(vn &n, int id)
{
	node &i = n[id];
	if (i.d > 0)
		return i.d;
	else if (i.p == -1)
		return 0;
	else {
		int d = 1 + depth(n, i.p);
		i.d = d;
		return d;
	}
}

int height(vn &n, int id)
{
	node &i = n[id];
	if (i.h > -1)
		return i.h;
	else if (i.l == -1 && i.r == -1) {
		i.h = 0;
		return 0;
	}
	i.h = max(i.l == -1 ? 0 : 1 + height(n, i.l),
			  i.r == -1 ? 0 : 1 + height(n, i.r));
	return i.h;
}

int main()
{
	int n = in();
	vn nodes(n);

	while (n--) {
		int id = in();
		node &i = nodes[id];
		i.l = in();
		i.r = in();
		if (i.l >= 0) nodes[i.l].p = id;
		if (i.r >= 0) nodes[i.r].p = id;
	}

	int i = 0;
	for (node &n: nodes) {
		int d = (n.l != -1) + (n.r != - 1);
		out("node ", i, ": parent = ", n.p, ", sibling = ",
			n.p == -1 ? -1 : nodes[n.p].r == i ? nodes[n.p].l : nodes[n.p].r,
			", degree = ", d, ", depth = ", depth(nodes, i), ", height = ", height(nodes, i),
			", ", n.p == -1 ? "root" : d ? "internal node" : "leaf",
			"\n");
		i++;
	}
}



Measured memory_bytes: 2632
N = int(input())
s = input().split()
a = [0]*8
flex = 0
for i in range(N):
    if int(s[i]) >=3200 : 
        flex = flex+1
    elif int(s[i]) >= 2800:
        a[7] = a[7]+1
    elif int(s[i])>=2400:
        a[6] = a[6]+1
    elif int(s[i])>=2000:
        a[5] = a[5]+1
    elif int(s[i]) >= 1600:
        a[4] = a[4]+1
    elif int(s[i])>=1200:
        a[3] = a[3]+1
    elif int(s[i])>=800:
        a[2] = a[2]+1
    elif int(s[i])>=400:
        a[1] = a[1] + 1
    else:
        a[0] = a[0]+1

cnt = 0
for i in range(8):
    if a[i] > 0:
        cnt = cnt+1
#print(a)
if  cnt !=  0:
    print(str(cnt)+" "+str(cnt+flex))
else:
    print(str(1)+" "+str(flex))

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#define N 505
using namespace std;
typedef long long ll;

ll n, mn=4e18, a[N][N], s[N][N], x[N][N], d[N][N];
int main() {
	ll i, j, k, tx;
	cin >> n;
	for(i=1; i<=n; i++) for(j=1; j<=n; j++) if(i!=j) scanf("%lld", &a[i][j]);
	for(i=1; i<=n; i++) for(j=1; j<=n; j++) s[i][j] = s[i-1][j] + s[i][j-1] - s[i-1][j-1] + a[i][j];
	for(i=1; i<=n; i++) for(j=1; j<=n; j++) x[i][j] = x[i-1][j] + x[i][j-1] - x[i-1][j-1] + (i<j ? a[i][j] : 0);
	for(i=1; i<=n; i++) {
		d[i][1] = x[i][i];
		for(j=2; j<=i; j++) {
			d[i][j] = 4e18;
			tx = x[i][i] - x[i][j-1] - x[j-1][i] + x[j-1][j-1];
			for(k=1; k<j; k++) {
				d[i][j] = min(d[i][j], d[j-1][k] + tx + s[i][k-1] - s[j-1][k-1]);
			}
		}
	}
	for(i=1; i<=n; i++) mn = min(mn, d[n][i]);
	cout << mn;
	return 0;
}

Measured memory_bytes: 8192
#include <chrono>

#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <time.h>
#include <random>
#include <string>
#include <cassert>
#include <vector>
#include <ostream>
#include <istream>
#include <stack>
#include <deque>
#include <queue>
#include <functional>

using namespace std;

#define int long long
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define pii pair<int, int>
#define ld long double

ostream& operator << (ostream &a, const vector<int> &b) {
    for (auto k : b) cout << k << " ";
    return a;
}

#ifdef LOCAL
    #define dbg(x) cout << #x << " : " << (x) << "\n";
    const int INF = 1e18;
//    const int mod = 2600000069;
//    const int p = 10;
//    const ld PI = 3.1415926535;
#else
    #define dbg(x)
    const int INF = 1e18;
//    const int mod = 2600000069;
//    const int p = 179;
//    const ld PI = 3.1415926535;
#endif

//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,sse3,sse4")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("fast-math")
//#pragma GCC target("avx2")
//#pragma GCC optimize("section-anchors")
//#pragma GCC optimize("profile-values,profile-reorder-functions,tracer")
//#pragma GCC optimize("vpt")
//#pragma GCC optimize("rename-registers")
//#pragma GCC optimize("move-loop-invariants")
//#pragma GCC optimize("unswitch-loops")
//#pragma GCC optimize("function-sections")
//#pragma GCC optimize("data-sections")

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    #ifdef LOCAL
    #else
//        freopen("capitals.in", "r", stdin);
//        freopen("capitals.out", "w", stdout);
    #endif
    int n;
    cin >> n;
    int ans = (n / 500) * 1000;
    n %= 500;
    ans += (n / 5) * 5;
    cout << ans;
}
/*

*/


Measured memory_bytes: 256
#include <iostream>
#include <stdlib.h>
#include <utility>
#include <math.h>
#include <stdexcept>
using namespace std;
int int_sort(const void*a,const void *b) {
    return *(  int *) b - *(int *) a;
    //qsort(b, a, sizeof(long long int), int_sort);
}
int main() {
    int n,sum=0,max=0;
    int a[100000]={};
    cin >> n ;
    cin>>a[0];
    max=a[0];
    for(int i=1;i<n;i++) {
        cin>>a[i];
        if(max<=a[i]){
            max=a[i];
        }
    }
    
    for(int i=0;i<n;i++)
        sum+=a[i];
    sum=sum-max;
    sum+=max/2;
    cout <<sum;
    return 0;
}
        
        
   



Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;

int a[100001];
int main(){
    int n,k;
    cin>>n>>k;
    int cur;
    rep(i,n){
        cin>>a[i];
        if(a[i]==1) cur=i;
    }
    int ans=0;
    ans=(n-2)/(k-1)+1;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 640
import Data.List

--         )   (
data P = P Int Int deriving (Show)

instance Semigroup P where
  (P l1 r1) <> (P l2 r2)
    | r1 < l2 = P (l1 + l2 - r1) r2
    | otherwise = P l1 (r1 + r2 - l2)

instance Monoid P where
  mempty = P 0 0

parseC :: Char -> P
parseC '(' = P 0 1
parseC ')' = P 1 0

parse :: String -> P
parse = mconcat . map parseC

calc :: [P] -> Bool
calc parens =
  l == 0 && r == 0
  where
    (rise, fall) = partition (\(P l r) -> l < r) parens
    riseP = mconcat $ sortOn (\(P l _) -> l) rise
    fallP = mconcat . reverse $ sortOn (\(P _ r) -> r) fall
    P l r = riseP <> fallP

main :: IO ()
main = do
  n <- read <$> getLine
  res <- fmap calc . sequenceA $ replicate n (fmap parse getLine)
  putStrLn $ if res then "Yes" else "No"

Measured memory_bytes: 259708
#include <iostream>
//#include <iomanip>
#include <string>
//#include <vector>
//#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
//using vll = vector<ll> ;
//using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;

//ll mod = 1000000007 ;
//long double pie = acos(-1) ;

//string yorn(bool a){if(a) return"Yes" ; return "No" ;}
//string YorN(bool a){if(a) return"YES" ; return "NO" ;}
ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void mysort(vector<long long> &a){sort(a.begin(),a.end()) ;}
//void myrev(vector<long long> &a){reverse(a.begin(),a.end()) ;}

int main(){
	int a,b ;
	cin >> a >> b ;
	string s,t ;
	cin >> s >> t ;
	ll g = gcd(a,b) ;
	ll l = lcm(a,b) ;
	for(ll i=0;i<g;i++){
		if(s.at(a/g*i)!=t.at(b/g*i)){
			cout << -1 << endl ;
			return 0 ;
		}
	}
	cout << l << endl ;
}


Measured memory_bytes: 512
#include<iostream>
#include<string>
#include<cstdlib>
#include<vector>
#include<algorithm>
#include<functional>


#define ll long long int

using namespace std;

int main() {
  int a[100000];
  int n,k;

  cin >> n >> k;
  int min = 1000000;
  int mini = -1;
  for(int i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] < min) {
      min = a[i];
      mini = i;
    }
  }
  int p = 1;
  if ((n-1)%(k-1) == 0) {
    p = 0;
  }
  cout << (n-1)/(k-1) + p << endl;

}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef pair<int, int> Pint;
typedef pair<int64_t, int64_t> Pll;

int main() {
    string S, T;
    cin >> S >> T;
    int s = S.size(), t = T.size(), beg = -1;
    if (s < t) {
        cout << "UNRESTORABLE" << endl;
        return 0;
    }
    for (int i = 0; i < s - t + 1; i++) {
        for (int j = i; j < t + i; j++) {
            if (S.at(j) == '?') {
                if (j == t + i - 1) {
                    beg = i;
                }
                continue;
            }
            if (S.at(j) != T.at(j - i)){
                break;
            }
            if (j == t + i - 1) {
                beg = i;
            }
        }
    }
    if (beg == -1) {
        cout << "UNRESTORABLE" << endl;
        return 0;
    }
    for (int i = beg; i < beg + t; i++) {
        S.at(i) = T.at(i - beg);
    }
    for (int i = 0; i < s; i++) {
        if (S.at(i) == '?') {
            S.at(i) = 'a';
        }
    }
    cout << S << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using ii=pair<ll,ll>;
using vi=vector<ll>;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define INF (ll)1e18
#define all(x) (x).begin(),(x).end()
#define print(a); for(auto x:a)cout<<x<<" "; cout<<"\n";
#define mset(a); memset(a,0,sizeof(a));

const ll N=1e5+5;
vector<vi>v(N);
bool vst[N];
ll color[N];
ll n,mx;

void dfs(ll a){
    ll cnt=1;
    for(auto u:v[a]){
        if(vst[u])continue;
        if(cnt==color[a])cnt++;
        color[u]=cnt++;
        vst[u]=true;
        dfs(u);
    }
}

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
    cin>>n;
    vi vv;
    for(int i=0;i<n-1;i++){
        ll a,b;cin>>a>>b;
        v[a].pb(b);
        v[b].pb(a);
        vv.pb(b);
    }
    color[1]=0;vst[1]=1;
    dfs(1);
    ll ans=0;
    for(int i=1;i<=n;i++)ans=max(ans,color[i]);
    cout<<ans<<"\n";
    for(int i=0;i<vv.size();i++)cout<<color[vv[i]]<<"\n";
}


Measured memory_bytes: 12140
import java.util.Scanner;


public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int x = sc.nextInt();
		int cost = 0;
		for(int i = 0 ; i < m ; i++) {
			int mi = sc.nextInt();
			if(mi < x) {
				cost++;
			}
		}
		int a = Math.min(cost,m - cost );
		System.out.println(a);
	}

}


Measured memory_bytes: 21840
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
using namespace std;
int co[10][1000] = { 0 };
int co1[10] = { 0 }, co2 = 0, co3 = 0;
int ans = 0, mi = 1000000007;
bool ho[10], roop = false;
int main() {
	int h, w, k1;
	cin >> h >> w >> k1;
	string s[10];
	for (int i = 0; i < h; i++) {
		cin >> s[i];
		for (int j = 0; j < w; j++) {
			if (s[i][j] == '1') {
				co[i][j]++;
			}
		}
	}
	for (int bit = 0; bit < (1 << (h - 1)); bit++) {
		for (int i = 0; i < h - 1; i++) {
			if (bit & (1 << i)) {
				ho[i] = 1;
			}
			else {
				ho[i] = 0;
				co3++;
			}
		}
		for (int k = 0; k < w; k++) {
			for (int j = 0; j < h; j++) {
				co1[co2] += co[j][k];
				if (j != h - 1 && ho[j] == false) {
					co2++;
				}
			}
			for (int l = 0; l <= co2; l++) {
				if (co1[l] > k1) {
					ans++;
					for (int reset = 0; reset < 10; reset++) {
						co1[reset] = 0;
					}
					if (ans > 3000) {
						roop = true;
						break;
					}
					k--;
				}
			}
			if (roop == true) {
				roop = false;
				break;
			}
			co2 = 0;
		}
		for (int reset = 0; reset < 10; reset++) {
			co1[reset] = 0;
		}
		if (ans + co3 < mi) {
			mi = ans + co3;
		}
		co3 = 0;
		ans = 0;
	}
	cout << mi << endl;
	return 0;
}

Measured memory_bytes: 256
/*######################################################
#########~~~~~####~~~~###~~##~~##~~##~~##~~##~~#########
#########~~##~~##~~##~~##~~~#~~##~~~#~~##~~##~~#########
#~~~~~~##~~~~~###~~~~~~##~~#~~~##~~#~~~##~~##~~##~~~~~~#
#########~~######~~##~~##~~##~~##~~##~~##~~##~~#########
#########~~######~~##~~##~~##~~##~~##~~###~~~~##########
######################################################*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#pragma comment(linker, "/stack:268435456")
#pragma GCC optimize("O3")
#define ll long long
#define str string
#define rtn return
#define endl '\n'
#define F first
#define S second
#define pb push_back
#define db long double
#define MOD 1000000007
#define INF 1e18
#define EPS 1e-15
#define pll pair <ll, ll>
#define vll vector<ll>
#define vpll vector<pll>
#define value_at find_by_order
#define index_of order_of_key
#define fill(a,v) memset(a,v,sizeof(a))
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i,n) for(ll i=0;i<n;++i)
#define per(i,n) for(ll i=n-1;i>=0;--i)
#define loop1(i,n) for (int i=1;i<=n;++i)
#define loop(i,begin,end) for (__typeof(end) i =(begin)-((begin)>(end));i!=(end)-((begin)>(end));i+=1-2*((begin)>(end)))
#define FAST_IO std::ios_base::sync_with_stdio(false);std::cin.tie(NULL);std::cout.tie(NULL)

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " = " << arg1 << '\n';
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " = " << arg1 << " |";
  __f(comma+1, args...);
}
#else
#define trace(...)
#endif


template<class T, class V> void remin(T &a, V b) { a > b ? a = b : a = a; }
template<class T, class V> void remax(T &a, V b) { a < b ? a = b : a = a; }
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

#define N 100005

ll dp[N], h[N], n;

int main() {
  FAST_IO;
  cin >> n;
  rep(i, n) cin >> h[i];
  rep(i, n) {
    if (i > 0) {
      dp[i] = dp[i - 1] + abs(h[i] - h[i - 1]);
    }
    if (i > 1) {
      remin(dp[i], dp[i - 2] + abs(h[i] - h[i - 2]));
    }
  }
  cout << dp[n - 1];
  rtn 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
typedef long long ll;

using namespace std;

int main()
{
	string s;
	int ans;
	int tmp;
	
	
	cin>>s;
	ans=s.length();
	for(int i=0;i<s.length()-1;i++)
	{
		if(s[i]!=s[i+1])
		{
			tmp = max(i+1,(int)s.length()-i-1);
			ans = min(ans,tmp);
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <queue>
#include <map>

using namespace std;



int main()
{
    map<string, string> ct;
    ct["rr"] = "rr";
    ct["rb"] = "gg";
    ct["rg"] = "bb";

    ct["gr"] = "bb";
    ct["gg"] = "gg";
    ct["gb"] = "rr";

    ct["br"] = "gg";
    ct["bg"] = "rr";
    ct["bb"] = "bb";
    
    for(;;) {
        string in;
        cin >> in;

        if ( in == "0" )
            break;

        std::map<string, bool> correct;
        correct[string(in.size(), 'r')] = true;
        correct[string(in.size(), 'g')] = true;
        correct[string(in.size(), 'b')] = true;

        int result_times = 0;

        queue<pair<int, string> > q;
        q.push( make_pair( 0, in ) );

        map<string, bool> memo;
        bool goal = false;

        // loop
        while( !q.empty() ) {
            int const times = q.front().first;
            string const s = q.front().second;
            q.pop();

            //cout << gtimes << endl;
            if ( correct[s] ) {
                goal = true;
                result_times = times;
                break;
            } 

            for( size_t i=0; i<s.size()-1; ++i ){
                string const pa = s.substr( i, 2 );
                string const t = s.substr( 0, i ) + ct[pa] + s.substr( i + 2 );

                if ( t == s )
                    continue;
                if ( memo[t] )
                    continue;

                memo[t] = true;

                q.push( make_pair( times + 1, t ) );
            }
        }

        // put
        if ( goal ) {
            cout << result_times << endl;
        } else {
            cout << "NA" << endl;
        }
    }
}

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

using namespace std;

int n,x;
int a[105];

int main()
{
    scanf("%d%d",&n,&x);
    for(int i=1;i<=n;i++){
        scanf("%d",&a[i]);
    }
    sort(a+1,a+n+1);
    int now=x;
    int ans=0;
    for(int i=1;i<n;i++){
        if(now-a[i]>=0)
            ans++;
        now-=a[i];
        if(now<=0)break;
    }
    if(now==a[n])ans++;
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
#define INF (1<<30)
#define LINF (lint)(1LL<<56)
#define endl "\n"
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
#define fi first
#define se second
typedef long long lint;
int dx[8]={1,1,0,-1,-1,-1,0,1};
int dy[8]={0,1,1,1,0,-1,-1,-1};

int main(void){
    string S,T;
    cin >> S >> T;
    int s=S.size(),t=T.size();
    lint dp[s+1][t+1]={};
    rep(i,s) rep(j,t){
        if(S[i]==T[j]) dp[i+1][j+1]=max(dp[i][j]+1,dp[i+1][j+1]);
        else dp[i+1][j+1]=max(dp[i+1][j],dp[i][j+1]);
    }
    string ans="";
    while(s>0 && t>0){
        if(dp[s][t]==dp[s-1][t]) s--;
        else if(dp[s][t]==dp[s][t-1]) t--;
        else ans=S[s-1]+ans,s--,t--;
    }
    cout << ans << endl;
}

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

	 
int main()
{
	int a, b, m; cin >> a >> b >> m;
	vector<int>ar, br;
	int mina = INT32_MAX, minb = INT32_MAX;
	while (a--) {
		int x; cin >> x; 
		if (x < mina)mina = x;
		ar.push_back(x);
	}
	while (b--) {
		int x; cin >> x;
		if (x < minb)minb = x;
		br.push_back(x);
	}
	int minm = INT_MAX;
	while (m--) {
		int j, k, l; cin >> j >> k >> l;
		minm = min(ar[j - 1] + br[k - 1] - l,minm);
	}
	cout << min(minm, (mina + minb)) << endl;
	return 0;
	}


Measured memory_bytes: 1400
N=int(input())

def num2alpha(num):
    if num<=26:
        return chr(64+num)
    elif num%26==0:
        return num2alpha(num//26-1)+chr(90)
    else:
        return num2alpha(num//26)+chr(64+num%26)
        
print(num2alpha(N).lower())


Measured memory_bytes: 9112
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a,long long b){
	if(b==0) return a;
	return gcd(b,a%b);
}
int main(){
	long long n,m;
	string s,t;
	cin>>n>>m;
	cin>>s;
	cin>>t;
//	string ans;
	long long G;
	if(n>m){
		G=n*m/gcd(n,m);
	}else{
		G=n*m/gcd(m,n);
	}
	if(s[0]!=t[0]){
		cout<<"-1"<<endl;
	}else{
		bool flag=false;
		int aans;
		for(int i=1;i<=1005;i++){
			flag=true;
			long long x=G*i/n;
			long long y=G*i/m;
			int k,j;
			k=j=0;
			while(k!=n&&j!=m){
				long long m;
				if(x*k+1<y*j+1){
					m=x*k+1;
					k++;
				}else if(x*k+1==y*j+1){
					m=x*k+1;
					if(s[k]!=t[j]){
						flag=false;
					}
					k++;
					j++;
				}else{
					m=y*j+1;
					j++;
				}
			}
			if(flag){
				aans=i;
				break;
			}
		}
		if(flag){
			long long res=G*aans;
			cout<<res<<endl;
		}else{
			cout<<"-1"<<endl;
		}
	}
	return 0;
} 

Measured memory_bytes: 512
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Globalization;
using System.Diagnostics;



class Myon
{
    public Myon() { }
    public static int Main()
    {
        new Myon().calc();
        return 0;
    }
    

    Scanner cin;

    

    void calc()
    {
        cin = new Scanner();
        int N = cin.nextInt();
        int[] A = new int[2 * N];
        for (int i = 0; i < N; i++)
        {
            A[i] = cin.nextInt() * 2;
        }
        for (int i = 0; i < N; i++)
        {
            A[i + N] = cin.nextInt() * 2 + 1;
        }
        Array.Sort(A);
        for (int i = 0; i < A.Length; i++)
        {
            A[i] %= 2;
        }
        long ans = 1;
        long mod = 1000000007;
        int tmp = 0;
        for (int i = 0; i < A.Length; i++)
        {
            if(A[i] == 0)
            {
                if(tmp > 0)
                {
                    ans *= tmp; ans %= mod;
                }
                tmp--;
            }
            else if(A[i] == 1)
            {
                if(tmp < 0)
                {
                    ans *= -tmp;
                    ans %= mod;
                }
                tmp++;
            }
        }
        Console.WriteLine(ans);
    }
    
}



class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}

Measured memory_bytes: 15812
//Author ::  ABHINAV3010 ::

#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define fast ios_base::sync_with_stdio(false)
typedef long long ll;
typedef pair<ll,ll> p;
ll mod=1000000007;
ll gcd(ll a,ll b)
{
    return (b==0)?a:gcd(b,a%b);
}
ll power(ll x, ll y, ll p=mod)
{ll res = 1;x = x % p;while (y > 0){if (y & 1){res = (res*x) % p;}y = y>>1;x = (x*x) % p;}return res;}
int main()
{
fast;
string s,t;
cin>>s>>t;
ll a,b;
cin>>a>>b;
string u;
cin>>u;
if(u==s)
{
    a--;
}else if(u==t)
{
    b--;
}
cout<<a<<" "<<b<<endl;
return 0;
}


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

int main(void)
{
    double r;

    cin >> r;

    cout << fixed << setprecision(6);
    cout << r * r * M_PI << " " << 2 * r * M_PI << endl;

    return (0);
}



Measured memory_bytes: 3240
#include <iostream>
#include <map>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
ll h, w, n, a, b, ans[11];
map<P, ll> mp;
int main(void){
    // Your code here!
    cin >> h >> w >> n;
    for (ll i = 0; i < n; i++){
        cin >> a >> b;
        for (ll j = 0; j < 3; j++){
            for (ll k = 0; k < 3; k++){
                if (a + j < 3 || a + j > h) continue;
                if (b + k < 3 || b + k > w) continue;
                mp[P(a + j, b + k)]++;
            }
        }
    }
    ans[0] = (h - 2) * (w - 2);
    for (auto itr = mp.begin(); itr != mp.end(); ++itr){
        ans[itr->second]++;
        ans[0]--;
    }
    for (ll i = 0; i < 10; i++) cout << ans[i] << endl;
}


Measured memory_bytes: 56448
def sum_value(n):
    n = str(n)
    sum = 0
    for i in range(len(n)):
        sum+=int(n[i])
    return sum

N = int(input())
A = int(N/2)
B = int(N/2) if N%2 == 0 else int(N/2)+1
menor = -1
for i in range(int(N/2)):
    menor = sum_value(A+i)+sum_value(B-i) if menor < 0 else min(sum_value(A+i)+sum_value(B-i), menor) 
print(menor)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
 	cin>>n;
  	int a[n],dp[n];
  	for(int i=0;i<n;i++) cin>>a[i];
  	dp[0]=0;
  	dp[1]=abs(a[1]-a[0]);
  	for(int i=2;i<n;i++) dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]));
  	cout<<dp[n-1];
 	return 0;
}

Measured memory_bytes: 1024
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] a){

		String str;
		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));

		try {
			while(null != ( str = bf.readLine() )){
				String[] arr = str.split(" ");
				long num1 = Long.parseLong(arr[0]);
				long num2 = Long.parseLong(arr[1]);
				long min_num = num1>num2 ? euclidean( num1, num2) : euclidean(num2, num1);
				long max_num = ( num1 / min_num ) * ( num2 / min_num ) * min_num;
				System.out.println(min_num + " " + max_num);
			}
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			try {
				bf.close();
			} catch (IOException e) {
			}
		}
	}

	private static long euclidean(long num1, long num2){
		if(num2 == 0){
			return num1;
		}
		long tmp_num = num1 % num2;
		return euclidean(num2, tmp_num);
	}
}

Measured memory_bytes: 9340
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int bgr(int idx) {}

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

  int n;
  cin >> n;

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

  sort(l.begin(), l.end());
  reverse(l.begin(), l.end());

  int ans = 0;
  for (int t = 0; t < n; t++) {
    for (int i = t + 1; i < n; i++) {
      for (int j = i + 1; j < n; j++) {
        int a = l[t];
        int b = l[i];
        int c = l[j];

        if(a < b + c && b < a + c && c < b + a) {
          ans++;
        }
      }
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256