akhauriyash/Code-Regression huggingface dataset:
require 'pp'

# 空白区切の入力値を数値の配列で返却する
def gets_i_list()
  gets.chomp.split(" ").map(&:to_i)
end

N, K = gets_i_list
a_list = gets_i_list

type_count = a_list.uniq.size
count_hash = a_list.group_by(&:itself).map{|k,v| [k, v.count] }.to_h

if type_count <= K
  puts 0
  exit
end

count_list = count_hash.values.sort
puts count_list.slice(0,(type_count - K)).inject(:+)


Measured memory_bytes: 70224
/*
 * main.cpp
 *
 *  Created on: 2011/04/08
 *      Author: satoki
 *      5:09 ~ 6:03
 *      Wrong Answer : 2
 *      nÈºÌfð¢ÅÀ
 *      Runtime Error : 4
 *      PÂ½ßÉfðZbg
 */
#include <iostream>
#define MAX_iP 1000004 // 664,580 ÔÚÌf = 10,000,019
#define MAX_nP 78499 // ÔºÌÓ¡àßÄ (KvÈfÌ + 1) ðmÛ
using namespace std;

int iN;

// fe[u
bool bPrime[MAX_iP];
int iPrime[MAX_nP];
int nPrime;

void setPrime() {
  // fe[uðì¬
  int i, j;

  nPrime = 0;
  fill(bPrime, bPrime + MAX_iP, true);
  bPrime[0] = bPrime[1] = false;

  for (i = 2; i < MAX_iP; i++) {
    if (bPrime[i]) {
      iPrime[nPrime++] = i;
      for (j = 2; i * j < MAX_iP; j++) {
        bPrime[i * j] = false;
      }
      //if (nPrime == MAX_nP) break;
    }
  }
  //printf("nPrime = %d i = %d\n", nPrime, i);
}

void init() {
  setPrime();
}

bool input() {
  if (scanf("%d", &iN) == EOF) return false;
  return true;
}

int manage() {
  int i;
  for (i = 0; iPrime[i] <= iN; i++);
  return i;
}

int main() {
  init();
  while (1) {
    if (!input()) break;
    printf("%d\n", manage());
  }
  return 0;
}

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

int A[3][3];
bool ok[3][3];

int main(){
  for (int i=0;i<3;++i){
    for (int j=0;j<3;++j){
      cin >> A[i][j];
    }
  }
  int n;
  cin >> n;
  for (int i=0;i<n;++i){
    int b;
    cin >> b;
    for (int j=0;j<3;++j){
      for (int k=0;k<3;++k){
        if(A[j][k] == b) ok[j][k] = true;
      }
    }
  }
  //ここまででマルバツの配列に変換できた

  bool bingo = false;
  for (int i=0;i<3;++i){
    int cnt = 0;
    for (int j=0;j<3;++j) if(ok[i][j]) cnt++;
    if (cnt == 3) bingo = true;
  }
  for (int j=0;j<3;++j){
    int cnt = 0;
    for (int i=0;i<3;++i) if(ok[i][j]) cnt++;
    if (cnt == 3) bingo = true;
  }
  //ここまでで縦横
  int cnt = 0;
  for (int i=0;i<3;++i){
    if(ok[i][i]) cnt++;
    if (cnt == 3) bingo = true;
  }
  //ここまでで縦横斜め

  if (ok[0][2] && ok[1][1] && ok[2][0]) bingo = true;

  if (bingo) cout << "Yes" << endl;
  else cout << "No" << endl;
}

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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int  ,int > pii;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const ll maxn  = 3e6;
const ll mod =1e9+7;
const ld PI = acos((ld)-1);

#define pb push_back
#define endl '\n'
#define dokme(x) return(cout << x , 0);
#define migmig ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ms(x , y) memset(x , y , sizeof x);
#define file_init freopen("input.txt", "r+", stdin); freopen("output.txt", "w+", stdout);
ll pw(ll a, ll b, ll md = mod){ll res = 1;while(b){if(b&1){res=(a*res)%md;}a=(a*a)%md;b>>=1;}return(res);}

int n;
int p[maxn] , cur;
int ans[maxn];
int cyc[maxn];
int order[maxn];
vector < int > adj[maxn];
bool mark[maxn];
set < int > st;

void dfs1(int v = 1){
    if(mark[v]){
        cyc[v] = 1;
        while(order[cur]!=v)
            cyc[order[cur--]] = 1;
        return;
    }
    mark[v] = 1;
    order[++cur] = v;
    dfs1(p[v]);
}

void dfs(int v){
    set < int > st;
    for(auto u : adj[v]){
        if(ans[u] == -1)
            dfs(u);
        st.insert(ans[u]);
    }
    int mn = 0;
    for(;;mn++)
        if(!st.count(mn)){
            ans[v] = mn;
            break;
        }
}

bool chk(int v , int val){
    ans[v] = val;
    int pos = p[v];
    set < int > st;
    while(pos!=v){
        st.clear();
        for(auto u : adj[pos])
            st.insert(ans[u]);
        int mn = 0;
        for(;;mn++)
            if(!st.count(mn)){
                ans[pos] = mn;
                break;
            }
        pos = p[pos];
    }
    st.clear();
    for(auto u : adj[pos])
            st.insert(ans[u]);
    int mn = 0;
        for(;;mn++)
            if(!st.count(mn))
                return(mn == val);
}

int main(){
    migmig
    cin >> n;
    for(int i = 1; i <= n ; i ++)
        cin >> p[i] , adj[p[i]].pb(i);
    ms(ans , -1);
    dfs1();
    cur = 0;
    for(int i = 1 ; i <= n ; i ++)
        if(!cyc[i])dfs(i);
        else cur = i;
    for(auto u : adj[cur])
        if(!cyc[u])
            st.insert(ans[u]);
    int a = -1;
    int b = -1;
    int cnt = 0;
    for(;;cnt++){
        if(st.count(cnt))continue;
        if(a==-1)a = cnt;
        else{
            b = cnt;
            break;
        }
    }
    bool oke = 0;
    oke |= chk(cur , a);
    oke |= chk(cur , b);
    cout << ((oke)?"POSSIBLE" : "IMPOSSIBLE");
    return(0);
}

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

typedef long long ll;
int L, ML, MR, R, d;

// (a^d.b)^L . a^ML . b^MR . (a.b^d)^R
inline bool get(int pos) {
	return pos < (d + 1) * L ? pos % (d + 1) == d : (pos -= (d + 1) * L) < ML + MR ? pos >= ML : (pos - (ML + MR)) % (d + 1);
}

void solve(int n, int U, int l, int r, bool flip) {
	d = (n + U) / (n + 1);
	L = (d == 1 ? 0 : ((ll)d * n - U) / ((ll)d * d - 1));
	n -= d * L, U -= L;
	R = std::min(n, U / d);
	ML = n - R, MR = U - d * R;
	flip ? ({for (; r >= l; --r) putchar(66 - get(r));}) : ({for (; l <= r; ++l) putchar(65 + get(l));});
	putchar(10);
}

void work() {
	int A, B, l, r;
	scanf("%d%d%d%d", &A, &B, &l, &r);
	A <= B ? solve(A, B, l - 1, r - 1, false) : solve(B, A, A + B - r, A + B - l, true);
}

int main() {
	int T;
	for (scanf("%d", &T); T; --T) work();
	return 0;
} 

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

//#define int long long
#define reps(i,s,n) for(int (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define rept(i,n) rep(i,(n)+1)
#define repst(i,s,n) reps(i,s,(n)+1)
#define reprt(i,n,t) for(int (i)=(n);(i)>=(t);--(i))
#define repr(i,n) reprt(i,n,0)
#define each(itr,v) for(auto &(itr):(v))
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define tmax(x,y,z) max(x,max(y,z))
#define tmin(x,y,z) min(x,min(y,z))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln '\n'
#define bln(i,n) (((i)==(n)-1)?'\n':' ')
#define dbg(x) cout<<#x" = "<<(x)<<ln<<flush
#define dbga(x,n) {cout<<#x" : ";for(int (i)=0;i<(n);++i){cout<<((x)[i])<<(i==((n)-1)?'\n':' ')<<flush;}}
#define zero(a) memset(a,0,sizeof(a))
#define unq(a) sort(all(a)),a.erase(unique(all(a)),a.end())

typedef complex<double> P;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vst;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vector<int> > mat;

const ll inf = (ll)1e9+10;
const ll linf = (ll)1e18+10;
const ll mod = (ll)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
const double eps = 1e-10;

ll mop(ll a,ll b,ll m=mod) {ll r=1;a%=m;for(;b;b>>=1){if(b&1)r=r*a%m;a=a*a%m;}return r;}
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b) {return a*b/gcd(a,b);}
bool ool(int x,int y,int h,int w) {return((x<0)||(h<=x)||(y<0)||(w<=y));}
bool deq(double a,double b) {return abs(a-b)<eps;}

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;

template < typename T > std::string to_string( const T& n )
{
	std::ostringstream stm ;
	stm << n ;
	return stm.str() ;
}

// ━━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…
// .｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋
// ・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・

ll s, l = -1, r = linf;

// mまでの文字列の長さ
ll len(ll m) {
	if (m==0) return 0;
	ll f = 0, b = 0, fb = 0, nm = 0, le = 1, ri = 10, sz = 1;
	while (ri<=m) {
		ll tf = (ri-1)/3 - f, tb = (ri-1)/5 - b, tfb = (ri-1)/15 - fb;
		f += tf, b += tb, fb += tfb;
		nm += ((ri-le) - (tf+tb-tfb))*sz;
		le *= 10, ri *= 10, sz++;
		if (nm>linf) return linf;
	}
	ri = m;
	ll tf = ri/3 - f, tb = ri/5 - b, tfb = ri/15 - fb;
	f += tf, b += tb;
	nm += ((ri-le+1) - (tf+tb-tfb))*sz;
	double sum = 1.*f*4 + 1.*b*4 + 1.*nm;
	if (sum>linf) return linf;
	else return f*4 + b*4 + nm;
}

string mk(ll m) {
	string res;
	while (res.size()<=20+s) {
		if (m%15==0) res += "FizzBuzz";
		else if (m%3==0) res += "Fizz";
		else if (m%5==0) res += "Buzz";
		else res += to_string(m);
		m++;
	}
	return res;
}

signed main() {
	cin >> s;
	while (r-l>1) {
		ll m = (r+l)/2;
		if (len(m)<s) l = m;
		else r = m;
	}
	s -= len(l)+1;
	cout << mk(l+1).substr(s,20) << ln;
}


Measured memory_bytes: 3224
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (Scanner sc = new Scanner(System.in);) {
            solve(sc);
        }
    }

    public static void solve(Scanner sc) {
        String a = sc.next();
        System.out.println(a.contains("9") ? "Yes" : "No");
    }
}

Measured memory_bytes: 23124
/*
title:

url:
*/

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <functional>
#include <queue>
#include <limits>
#include <string>
#include <utility>
#include <cstring>
#include <map>

using namespace std;

#define REP(i, n) for (int i = 0; i < (n); i++)
#define INF 1000000007

typedef pair<int, int> pint;
typedef long long ll;

int main()
{
    int h, w;
    cin >> h >> w;
    int coin[h][w];
    int coin2[h][w];
    REP(i, h)
    {
        REP(j, w)
        {
            cin >> coin[i][j];
            coin2[i][j] = coin[i][j];
        }
    }
    int count = 0;
    REP(i, h - 1)
    {
        REP(j, w)
        {
            if (coin[i][j] % 2 == 1)
            {
                coin[i + 1][j]++;
                count++;
            }
        }
    }
    REP(i, w - 1)
    {
        if (coin[h - 1][i] % 2 == 1)
        {
            coin[h - 1][i + 1]++;
            count++;
        }
    }
    cout << count << endl;
    REP(i, h - 1)
    {
        REP(j, w)
        {
            if (coin2[i][j] % 2 == 1)
            {
                cout << i + 1 << " " << j + 1 << " " << i + 2 << " " << j + 1 << endl;
                coin2[i + 1][j]++;
            }
        }
    }
    REP(i, w - 1)
    {
        if (coin2[h - 1][i] % 2 == 1)
        {
            cout << h << " " << i + 1 << " " << h << " " << i + 2 << endl;
            coin2[h - 1][i + 1]++;
        }
    }
}

Measured memory_bytes: 4096
def main():
    N,P = map(int,input().split())
    S = input()[::-1]
    ans = 0
    if P == 2 or P == 5:
        for i,s in enumerate(S):
            if int(s) % P == 0:
                ans += N - i
    else:
        mods = [0] * P
        mods[0] = 1
        current = 0
        x = 1
        for s in S:
            current = (current + x * int(s)) % P
            ans += mods[current % P]
            mods[current % P] += 1
            x = x * 10 % P
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 41968
#include <functional>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;

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

    int n, k, r, s, p;
    cin >> n >> k >> r >> s >> p;

    string t;
    cin >> t;

    // r, s, p の順
    vector < vector <int> > dp(n, vector <int>(3));

    int ans = 0;
    for (int i = 0; i < n; i++) {
        if (i < k) {
            if (t[i] == 'r') dp[i][2] += p;
            if (t[i] == 's') dp[i][0] += r;
            if (t[i] == 'p') dp[i][1] += s;
        } else {
            if (t[i] == 'r') {
                dp[i][0] = max(dp[i - k][1], dp[i - k][2]);
                dp[i][1] = max(dp[i - k][0], dp[i - k][2]);
                dp[i][2] = max(dp[i - k][0], dp[i - k][1]) + p;
            } else if (t[i] == 's') {
                dp[i][0] = max(dp[i - k][1], dp[i - k][2]) + r;
                dp[i][1] = max(dp[i - k][0], dp[i - k][2]);
                dp[i][2] = max(dp[i - k][0], dp[i - k][1]);
            } else if (t[i] == 'p') {
                dp[i][0] = max(dp[i - k][1], dp[i - k][2]);
                dp[i][1] = max(dp[i - k][0], dp[i - k][2]) + s;
                dp[i][2] = max(dp[i - k][0], dp[i - k][1]);
            }
        }

        if (i + k >= n) {
            ans += max(dp[i][0], max(dp[i][1], dp[i][2]));
        }
    }

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

Measured memory_bytes: 5824
k, a, b = map(int, input().split())

if b <= a + 1:
	print(k + 1)
else:
	n = (k - (a - 1)) // 2
	r = (k - (a - 1)) % 2
	if r == 0:
		print(n * b - (n - 1) * a)
	elif r == 1:
		print(n * b - (n - 1) * a + 1)

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

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

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

  vector<int> dp(N + 1, 0);
  dp[1] = abs(H[1] - H[0]);
  for (int i = 2; i <= N; i++) {
    dp[i] =
        min(dp[i - 1] + abs(H[i] - H[i - 1]), dp[i - 2] + abs(H[i] - H[i - 2]));
  }

  // for (int i = 0; i < N + 1; i++) {
  //   cout << dp[i] << endl;
  // }
  cout << dp[N - 1] << endl;
  return 0;
}


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

using namespace std;

class Dice{
public:
  int x[24],t[2];
  Dice(){
    for(int i = 0 ; i < 4 ; i++){ x[i] = 0; }
    for(int i = 0 ; i < 2 ; i++){
      for(int j = 0 ; j < 8 ; j++){ x[j+i*8+4] = j/2+1; }
    }
    for(int i = 0 ; i < 4 ; i++){ x[i+20] = 5; }
  }
  char c(int a){
    switch(a){
    case 0:
      return 'r';
    case 1:
      return 'g';
    case 2:
      return 'y';
    case 3:
      return 'b';
    case 4:
      return 'w';
    case 5:
      return 'o';
    }
  }
  void U(){
    t[0] = x[4]; t[1] = x[5];
    x[4] = x[6]; x[5] = x[7];
    x[6] = x[8]; x[7] = x[9];
    x[8] = x[10]; x[9] = x[11];
    x[10] = t[0]; x[11] = t[1];
    t[0] = x[0]; x[0] = x[2];
    x[2] = x[3]; x[3] = x[1];
    x[1] = t[0];
  }
  void F(){
    t[0] = x[2]; t[1] = x[3];
    x[2] = x[13]; x[3] = x[5];
    x[13] = x[21]; x[5] = x[20];
    x[21] = x[8]; x[20] = x[16];
    x[8] = t[0]; x[16] = t[1];
    t[0] = x[6]; x[6] = x[14];
    x[14] = x[15]; x[15] = x[7];
    x[7] = t[0];
  }
  void R(){
    t[0] = x[1]; t[1] = x[3];
    x[1] = x[7]; x[3] = x[15];
    x[7] = x[21]; x[15] = x[23];
    x[21] = x[18]; x[23] = x[10];
    x[18] = t[0]; x[10] = t[1];
    t[0] = x[8]; x[8] = x[16];
    x[16] = x[17]; x[17] = x[9];
    x[9] = t[0];
  }
  void D(){
    t[0] = x[12]; t[1] = x[13];
    x[12] = x[18]; x[13] = x[19];
    x[18] = x[16]; x[19] = x[17];
    x[16] = x[14]; x[17] = x[15];
    x[14] = t[0]; x[15] = t[1];
    t[0] = x[20]; x[20] = x[22];
    x[22] = x[23]; x[23] = x[21];
    x[21] = t[0];
  }
  void B(){
    t[0] = x[0]; t[1] = x[1];
    x[0] = x[9]; x[1] = x[17];
    x[9] = x[23]; x[17] = x[22];
    x[23] = x[12]; x[22] = x[4];
    x[12] = t[0]; x[4] = t[1];
    t[0] = x[10]; x[10] = x[18];
    x[18] = x[19]; x[19] = x[11];
    x[11] = t[0];
  }
  void L(){
    t[0] = x[0]; t[1] = x[2];
    x[0] = x[19]; x[2] = x[11];
    x[19] = x[20]; x[11] = x[22];
    x[20] = x[6]; x[22] = x[14];
    x[6] = t[0]; x[14] = t[1];
    t[0] = x[4]; x[4] = x[12];
    x[12] = x[13]; x[13] = x[5];
    x[5] = t[0];
  }
  void print(){
    printf("..%c%c....\n",c(x[0]),c(x[1]));
    printf("..%c%c....\n",c(x[2]),c(x[3]));
    for(int i = 0 ; i < 2 ; i++){
      for(int j = 0 ; j < 8 ; j++){
        printf("%c",c(x[j+i*8+4]));
      }
      printf("\n");
    }
    printf("..%c%c....\n",c(x[20]),c(x[21]));
    printf("..%c%c....\n",c(x[22]),c(x[23]));
  }
};

int main(){
  Dice d;
  char ch;
  while(cin >> ch){
    if(ch == 'U'){ d.U(); }
    if(ch == 'F'){ d.F(); }
    if(ch == 'R'){ d.R(); }
    if(ch == 'D'){ d.D(); }
    if(ch == 'B'){ d.B(); }
    if(ch == 'L'){ d.L(); }
  }
  d.print();
  return 0;
}

Measured memory_bytes: 1136
#include <bits/stdc++.h>
#include <time.h>
#define int long long int
#define pb push_back
#define mem(a, x) memset(a, x, sizeof a)
#define all(a) a.begin(), a.end()
#define scnarr(a, n) for (int i = 0; i < n; ++i) cin >> a[i]
#define vi vector<int>
#define si set<int>
#define pii pair <int, int>
#define sii set<pii>
#define vii vector<pii>
#define mii map <int, int>
#define faster ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
using namespace std;
using namespace chrono;
/*
	----------------------------------------------------------------------
	Things to remember : check for coners n = 1, pass references instead
*/
/* -------------------------------Solution Sarted--------------------------------------*/

//Constants
const int MOD = 1000000007; // 1e9 + 7
const int MAXN = 1000005; // 1e6 +5
const int INF = 100000000000005; // 1e15 +5

void solve(){
	int a, b, c, d;
	cin >> a >> b >> c >> d;

	cout << max({a*c, a*d, b*c, b*d}) << endl;
	
}

signed main()
{
	faster;
#ifndef ONLINE_JUDGE
	freopen("ip.txt", "r", stdin);
	freopen("op.txt", "w", stdout);
#endif
	// int t; cin >> t; while(t--)
		solve();
	return 0;
}


//Author : Ankit Raj
//Problem Link :

/*Snippets*/
/*
sieve - prime factorization using sieve and primes in range
zpower - pow with mod
plate - Initial template
bfs 
dfs
fenwik - BIT
binary_search
segment_tree
*/
	

Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
typedef pair<int,int> P;
int H,W;
string s[50];
int memo[50][50][50][50];
bool vis[50][50][50][50];
int dx[2]={1,0},dy[2]={0,1};
vector<P> ps[26];
inline bool is(int x,int y){
	return 0<=x&&x<H&&0<=y&&y<W&&s[x][y]!='#';
}
int rec(int a,int b,int c,int d){	//(a,b)->(c,d)
	if(c+d-b-a==-1) return 0;
	if(!is(a,b)||!is(c,d)) return -1;
	if(a>c||b>d) return -1;
	if(vis[a][b][c][d]) return memo[a][b][c][d];
	vis[a][b][c][d]=1;
	int &val=memo[a][b][c][d];
	if(c+d-b-a==0){
		return val=0;
	}
	if(c+d-b-a==1){
		if(islower(s[a][b])&&s[a][b]-'a'==s[c][d]-'A') return val=1;
		else return val=0;
	}
	chmax(val,max(rec(a+1,b,c,d),rec(a,b+1,c,d)));
	if(islower(s[a][b])){
		int ch=s[a][b]-'a';
		for(P p:ps[ch]){
			int x=p.fs,y=p.sc;
			if(a<=x&&x<=c&&b<=y&&y<=d){
				int tmp=-1;
				rep(i,2) rep(j,2) chmax(tmp,rec(a+dx[i],b+dy[i],x-dx[j],y-dy[j]));
				int tmp2=-1;
				rep(i,2) chmax(tmp2,rec(x+dx[i],y+dy[i],c,d));
				if(tmp>=0&&tmp2>=0) chmax(val,1+tmp+tmp2);
			}
		}
	}
	return val;
}
int main(){
	while(true){
		cin>>H>>W;
		if(H==0) break;
		rep(i,26) ps[i].clear();
		rep(i,H) cin>>s[i];
		rep(i,H) rep(j,W) if(isupper(s[i][j])) ps[s[i][j]-'A'].pb(P(i,j));
		rep(a,H) rep(b,W) rep(c,H) rep(d,W) memo[a][b][c][d]=-1,vis[a][b][c][d]=0;
		int tmp=rec(0,0,H-1,W-1);
		if(tmp<0){
			puts("-1");
			continue;
		}
		cout<<tmp<<endl;
	}
}

Measured memory_bytes: 31756
#include <iostream>
#include <cstdio>
#include <vector>

using namespace std;

struct Node {
  int key;
  Node* parent;
  Node* left;
  Node* right;
  
  Node(int key = -1) : key(key), parent(nullptr), left(nullptr), right(nullptr) {};
};

static vector<Node> tree;

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

  tree.resize(h + 1);

  int k;
  for (int i = 1; i < tree.size(); i++) {
    cin >> k;
    tree[i].key = k;
  }

  int parent, left, right;
  for (int i = 1; i < tree.size(); i++) {
    parent = i / 2;
    if (parent != 0) {
      tree[i].parent = &tree[parent];
    }
    left = 2 * i;
    if (left < tree.size()) {
      tree[i].left = &tree[left];
    }
    right = 2 * i + 1;
    if (right < tree.size()) {
      tree[i].right = &tree[right];    
    }
  }

  for (int i = 1; i < tree.size(); i++) {
    auto& node = tree[i];
    printf("node %d: key = %d, ", i, node.key);
    if (node.parent) {
      printf("parent key = %d, ", node.parent->key);
    }
    if (node.left) {
      printf("left key = %d, ", node.left->key);
    }
    if (node.right) {
      printf("right key = %d, ", node.right->key);
    }
    printf("\n");
  }

  return 0;
}



Measured memory_bytes: 3240
#include <bits/stdc++.h>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (long long i = 0; i < n; i++)
#define RREP(i, n) for (long long i = n - 1; 0 <= i; i--)
#define FOR(i, start, end) for (long long i = start; i < end; i++)
#define RFOR(i, start, end) for (long long i = start - 1; 0 <= i; i--)
#define ALL(a) a.begin(), a.end()
#define MOD(a) a %= 1'000'000'007
using ll = long long;
using namespace std;
const int INF32       = 1'050'000'000;
const long long INF64 = 4'000'000'000'000'000'000;
const int MOD7        = 1'000'000'007;
const int MOD9        = 1'000'000'009;
template <class T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
void print() { std::cout << '\n'; }
template <class H, class... T> void print(H &&head, T &&... args) {
    std::cout << head;
    sizeof...(args) == 0 ? std::cout << "" : std::cout << ' ';
    print(std::forward<T>(args)...);
}
template <class T> void print(std::vector<T> &v) {
    for (int i = 0; i < v.size(); i++) {
        std::cout << v[i];
        i == v.size() - 1 ? std::cout << '\n' : std::cout << ' ';
    }
}
template <class T> void print(std::vector<std::vector<T>> &v) {
    for (int i = 0; i < v.size(); i++) {
        for (int j = 0; j < v[i].size(); j++) {
            std::cout << v[i][j];
            j == v[i].size() - 1 ? std::cout << '\n' : std::cout << ' ';
        }
    }
}

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

    ll N, X;
    cin >> N >> X;

    vector<ll> all(N + 1), paty(N + 1);
    paty[0] = 1;
    all[0]  = 1;
    FOR(i, 1, N + 1) {
        all[i]  = 2 * all[i - 1] + 3;
        paty[i] = 2 * paty[i - 1] + 1;
    }

    auto rec = [&](auto f, ll n, ll x) -> long long {
        if (n == 0)
            return x <= 0 ? 0 : 1;
        else if (x <= 1 + all[n - 1])
            return f(f, n - 1, x - 1);
        else
            return paty[n - 1] + 1 + f(f, n - 1, x - 2 - all[n - 1]);
    };
    print(rec(rec, N, X));

    return 0;
}

Measured memory_bytes: 256
using System;

public class B
{
  public static void Main()
  {
    int a, b, c, money;
    a = int.Parse(Console.ReadLine());
    b = int.Parse(Console.ReadLine());
    c = int.Parse(Console.ReadLine());
    money = int.Parse(Console.ReadLine());
    int count = 0;
    for(int i = 0; i <= a; i++)
    {
      for(int j = 0; j <= b; j++)
      {
        for(int k = 0; k <= c; k++)
        {
			if(i * 500 + j * 100 + k * 50 == money)count++;
        }
      }
    }
    Console.WriteLine(count);
  }
}

Measured memory_bytes: 11092
a,b,m = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
XYC = [list(map(int,input().split())) for i in range(m)]

kouho = (min(A)+min(B))
for i in range(m):
    kouho = min(kouho,A[XYC[i][0]-1] + B[XYC[i][1]-1] - XYC[i][2])

print(kouho)


Measured memory_bytes: 38488
N = int(input())
D = list(map(int, input().split()))
M = int(input())
T = list(map(int, input().split()))


def countNumber(LIST):
    cnt = {}
    for l in LIST:
        try:
            cnt[l] += 1
        except KeyError:
            cnt[l] = 1
    return cnt


countD = countNumber(D)
countT = countNumber(T)

flag = True
for i in countT.keys():
    try:
        if countD[i] < countT[i]:
            flag = False
    except KeyError:
        flag = False
        break

if flag:
    print('YES')
else:
    print('NO')

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

int main(){
    int H, W; cin >> H >> W;
    vector<string> A(H);
    for(string &s:A) cin >> s;

    vector<int> d_row;
    vector<int> d_col;

    for(int i=0; i<H; i++){
        int cr = 0;
        for(int j=0; j<W; j++) if(A[i][j]=='.') cr++;
        if(cr==W) d_row.push_back(i);
    }

    for(int i=0; i<W; i++){
        int cc = 0;
        for(int j=0; j<H; j++) if(A[j][i]=='.') cc++;
        if(cc==H) d_col.push_back(i);
    }

    for(int i=0; i<H; i++){
        if(find(d_row.begin(), d_row.end(), i)!=d_row.end()) continue;
        for(int j=0; j<W; j++){
            if(find(d_col.begin(), d_col.end(), j)!=d_col.end()) continue;
            cout << A[i][j];
        }
        cout << endl;
    }
    
    

    return 0;
}


Measured memory_bytes: 256
//
#define _USE_MATH_DEFINES
#include <vector>
#include <set>
#include <array>
#include <iostream>
#include <cstdio>
#include <cstdint>
#include <algorithm>
#include <numeric>
#include <bitset>
//
using ll = long long;
using namespace std;
#define rep(i,n) for(ll i=0;i<(n);++i)
inline void yes(bool cond) { cond ? puts("Yes") : puts("No"); }
template<typename Type> inline void chmin(Type& a, Type b) { if (a > b) a = b; }
template<typename Type> inline void chmax(Type& a, Type b) { if (a < b) a = b; }
template<typename Type> inline void sort(Type& arr) { std::sort(arr.begin(), arr.end()); }
template<typename Type> inline Type nth(vector<Type>& arr, size_t pos) { std::nth_element(arr.begin(), arr.begin() + pos, arr.end()); return arr[pos]; }
#define BIGP   1000000007
#define INF_I  std::numeric_limits<ll>::max()
#define INF_F  std::numeric_limits<float>::infinity()
#define PI  3.1415926535
//
#include <iomanip>
int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    ;

    ll A, B, H, M;
    cin >> A >> B >> H >> M;
    using ld = long double;
    ld hd = ld(H / ld(12.0) + ld(M) / (ld(60.0)* ld(12.0))) *ld(2.0) * ld(M_PI);
    ld md = ld(M / ld(60.0)) * ld(2.0) * ld(M_PI);
    ld ax = ld(A) * cos(hd);
    ld ay = ld(A) * sin(hd);
    ld bx = ld(B) * cos(md);
    ld by = ld(B) * sin(md);
    ld dx = ax - bx;
    ld dy = ay - by;
    ld len = sqrtl(dx * dx + dy * dy);
    cout << std::setprecision(16) << len;
    return 0;
}

Measured memory_bytes: 3488
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,d,a,h[200004],x[200004];
pair<ll,ll> peko[200004];
ll decr[200004],now;
ll ans=0;
int main(){
	cin>>n>>d>>a;
	for (ll i=1;i<=n;i++) cin>>peko[i].first>>peko[i].second;
	sort (peko+1,peko+1+n);
	for (ll i=1;i<=n;i++) x[i]=peko[i].first,h[i]=peko[i].second;
	for (ll i=1;i<=n;i++){
		if (now<h[i]){
			ll g=(h[i]-now+a-1)/a;
			ans+=g; 
			ll go=upper_bound(x+1,x+1+n,x[i]+2*d)-x;
			go--;
			decr[go]+=a*g;
			now+=a*g;
		}
		now-=decr[i];
	}
	cout<<ans;
}

Measured memory_bytes: 8064
#include <iostream>
#include <cstring>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <math.h>

using namespace std;

int main()
{
    int n, q;
    cin >> n >> q;
    char s[n+1];
    cin >> s;
    vector <int> vt;
    for(int i=0; i<n-1; i++){
        if(s[i]=='A' && s[i+1]=='C'){
            vt.push_back(i);
        }
    }
    int l, r;
    for(int i=0; i<q; i++){
        cin >> l >> r;
        l--;
        r--;
        auto iter1=lower_bound(vt.begin(), vt.end(), l);
        int m=iter1-vt.begin();//含まれないもの

        auto iter2=lower_bound(vt.begin(), vt.end(), r);
        int M=iter2-vt.begin();
        cout << M-m << endl;
    }
    return 0;
}

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

int main() {
	int N, x, ans = 0;
	cin >> N >> x;
	vector<int> a(N);
	for (int i = 0; i < N; ++i) cin >> a[i];
	sort(a.begin(), a.end());
	for (int i = 0; i < N; ++i) {
		if (x < a[i]) {
			x = 0;
			break;
		}
		else {
			x -= a[i];
			ans++;
		}
	}
	if (x > 0) ans--;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
using namespace std;
#define MOD 1000000007
#define f(i,n) for(int i=0;i<int(n);i++)
#define N 100010
vector<int>e[N];
bool used[N];
long long dp0[N];
long long dp1[N];

void dfs(int k) {
	used[k] = true;
	dp0[k] = 1;
	dp1[k] = 1;
	int sz = e[k].size();
	f(i, sz) {
		if (!used[e[k][i]]) {
			dfs(e[k][i]);
			dp1[k] = (dp1[k] * dp0[e[k][i]]) % MOD;
			dp0[k] = (dp0[k] * (dp0[e[k][i]] + dp1[e[k][i]])) % MOD;
		}
	}
	return;
}

int main() {
	int n;
	int x, y;
	long long ans;
	scanf("%d", &n);
	f(i, n-1) {
		scanf("%d %d", &x, &y);
		e[x - 1].push_back(y - 1);
		e[y - 1].push_back(x - 1);
	}
	dfs(0);
	ans = (dp0[0] + dp1[0]) % MOD;
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 11520
#d
n=int(input())

c=[[0]*9 for _ in range(9)]
for i in range(1,n+1):
    stri = str(i)
    head = int(stri[0])
    tail = int(stri[-1])
    if tail!=0:
        c[head-1][tail-1]+=1

print( sum(c[i][j] * c[j][i] for i in range(9) for j in range(9)) )

Measured memory_bytes: 40428
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+5;
int n,m,a[N],c[N],b[N],d[N],idx,h[N],ne[N<<1],e[N<<1],w[N<<1];
void add(int a,int b,int c){e[idx]=b;ne[idx]=h[a];w[idx] =c;h[a]=idx ++;}
bool vis[N],use[N];
int get(int x)
{
    return lower_bound(d+1,d+1+n,x)-d;
}
bool dfs(int u)
{
    vis[u]=true;
    int x=c[u];
    for(int i=h[u];~i;i=ne[i])
    {
        int v=e[i];
        if(!vis[v]&&dfs(v))
        {
            x^=1;use[w[i]]=true;
        }
    }
    return x;
}
int main()
{
    // scanf("%d%d",&n,&m);
    // for(int i = 0 ;i < N ;i ++) h[i] = -1 ;
    // for(int i=1;i<=n;i++)
    //     scanf("%d%d",&a[i],&b[i]),d[i]=a[i];
    // sort(d+1,d+1+n);
    // for(int i=1;i<=n;i++)
    //     a[i]=get(a[i]),c[a[i]]=b[i];
    // for(int i=n+1;i>=1;i--)
    //     c[i]^=c[i-1];
    // for(int i=1;i<=m;i++)
    // {
    //     int l,r;scanf("%d%d",&l,&r);
    //     l=get(l);
    //     r=upper_bound(d+1,d+1+n,r)-d -1;
    //     if(l<=r)
    //         add(l,r+1,i),add(r+1,l,i);
    // }
    for(int i = 0 ;i < N ;i ++) h[i] = -1 ;
    ios::sync_with_stdio(false) ;
    cin.tie(0) , cout.tie(0) ;
    cin >> n >> m ;
    for(int i = 1; i <= n ; i ++) cin >> a[i] >> b[i] , d[i] = a[i] ;
    sort(d + 1 , d + n + 1) ;
    for(int i = 1; i <= n ;i ++)
     c[get(a[i])] = b[i] ;
    for(int i = n + 1; i >= 1 ;i --) c[i] ^= c[i - 1] ;
    for(int i = 1; i <= m ;i ++)
     {
       int l , r ;
       cin >> l >> r ;
       l = get(l) , r = upper_bound(d + 1 , d + n + 1 , r) - d - 1 ;
       if(l <= r)
       add(l , r + 1 , i) , add(r + 1 , l , i) ;
     }
    // for(int i=1;i<=n+1;i++)
    //     if(!vis[i]&&dfs(i))
    // {
    //     cout << -1 << endl ;;return 0;
    // }
    // int ans=0;
    // for(int i=1;i<=m;i++)
    //     if(use[i]) ans++;
    // cout << ans << endl ;
    // for(int i=1;i<=m;i++)
    // if(use[i])
    //    cout << i << " " ;
    for(int i = 1; i <= n + 1 ;i ++)
     if(!vis[i] && dfs(i))
      {
        cout << -1 << endl ;
        return 0 ;
      }
      int ans =  0 ;
      for(int i = 1; i <= m ;i ++)
       if(use[i]) ans ++ ;
     cout << ans << endl ;
     for(int i = 1;i <= m ;i ++)
      if(use[i])
       cout << i << " " ;
}


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

int main(){
  int n,t;
  cin >> n >> t;
  int ans=100000000;
  bool ok=false;
  for(int i=0;i<n;++i){
    int cost,time;
    cin >> cost >> time;
    if(time<=t){
      ans=min(ans,cost);
      ok=true;
    }
  }
  if(ok){
    cout << ans << endl;
  }else{
    cout << "TLE" << endl;
  }
  return 0;
}


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

#define READALL(arr) for(auto &x : arr) { cin >> x; }
#define PRINTALL(arr) for(auto &x : arr) { cout << x << " "; } cout << endl;


int main()
{
	long long n,m; cin >> n >> m;
	string s,t; cin >> s >> t;
	long long l = ((n*m)/__gcd(n,m));
	long long a = l/n;
	long long b = l/m;
	long long check = ((a*b)/__gcd(a,b));
	
	long long i = 0;
	while((i/a)<s.length() && (i/b)<t.length())
	{
		if(s[i/a]!=t[i/b])
		{
			cout << -1 << "\n";
			return 0;
		}
		i+=check;
	}
	cout << l << "\n";
	return 0;
}


Measured memory_bytes: 512
// PROBLEM NAME ------>>> 
// PROBLEM LINK ------>>>  

//---------------------------------------------------------------------------------------------------------------

#include <bits/stdc++.h>
#define ll long long int 
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define TC ll t;cin>>t; for(ll z = 1;z<=t;z++)
#define bs binary_search
#define pll pair<ll,ll>
#define ppll pair<ll,pll>
#define vvll vector<vector<ll>>
#define sll stack<ll>
#define qll queue<ll>
#define vll vector<ll>
#define vpll vector<pll>
#define vc vector <char>
#define f first
#define s second
#define MOD 10e9 + 7
#define mxn 10e18
#define ln "\n"

using namespace std;

void solve()
{
    ll a,b,c,k;
    cin>>a>>b>>c>>k;
    ll ans = 0;
    ans += min(k,a);
    k -= ans;
    k -= min(k,b);
    ans -= min(k,c);
    cout<<ans<<ln;
}


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    return 0;
}

Measured memory_bytes: 3632
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
    using namespace std;
 
    int main(){
      int a[3];
      rep(i,3)cin >> a[i];
      sort(a,a+3);
      if(a[0]==a[1])cout << a[2] << endl;
      else cout << a[0] << endl;
      return 0;}

Measured memory_bytes: 256
s = str(input())
ans = 0
cnt = 1
lastright = 0
lis = []
for i in range(len(s)-1):
    if s[i] == s[i+1]:
        cnt += 1
    else:
        lis.append(cnt)
        cnt = 1
lis.append(cnt)
if s[0] == "<":
    lis.insert(0,0)
if s[-1] == ">":
    lis.append(0)
for i in range(len(lis)//2-1):
    if lis[2 * i + 1] <= lis[2 * (i + 1)]:
        lis[2 * i + 1] -= 1
    else:
        lis[2 * (i + 1)] -= 1
for num in lis:
    ans += (num * (num + 1))//2
print(ans)

Measured memory_bytes: 6300
n = int(input())
s = [input() for i in range(n)]

memo = {}
for i in range(n):
    if s[i] not in memo:
        memo[s[i]] = 1
    else:
        memo[s[i]] += 1

ans = []
cnt = 0
for i in memo:
    if memo[i] > cnt:
        ans = []
        cnt = memo[i]
        ans.append(i)
    elif memo[i] == cnt:
        ans.append(i)
    else:
        pass
ans = sorted(ans)
for string in ans:
    print(string)

Measured memory_bytes: 99252
#include<iostream>
#include<cstdio>
#include<algorithm>
#define ll long long
using namespace std;
int n,m,q,cnt,ans;
int main()
{
	int i,s,a,b,j,k;
	scanf("%d",&n);
	a=n%10;b=n/10;
	if(a==9 || b==9)printf("Yes");
	else printf("No");
	return 0;
}

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

int main(void) {
  int n, m, c;
  cin >> n >> m >> c;
  int b[m];
  for (int i = 0; i < m; i++) cin >> b[i];
  int count = 0;
  for (int j = 0; j < n; j++) {
    int ans = c;
    for (int i = 0; i < m; i++) {
      int a;
      cin >> a;
      ans += a * b[i];
    }
    if (ans > 0) count++;
  }
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 256
use std::io::Read;
use std::cmp::max;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

    println!("{}", answer);
}

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let n: usize = iterator.next().unwrap().parse().unwrap();

    let mut count: usize = 0;
    let mut prev: usize = 0;
    let mut answer: usize = 0;

    for _i in 0..n {
        let h: usize = iterator.next().unwrap().parse().unwrap();

        if h > prev {
            answer = max(answer, count);
            count = 0;
        } else {
            count += 1;
        }
        prev = h;
    }
    answer = max(answer, count);

    return format!("{}", answer);
}

#[test]
fn test() {
    assert_eq!(
        solve(
            r"5
10 4 8 7 3"
        ),
        "2"
    );
    assert_eq!(
        solve(
            r"7
4 4 5 6 6 5 5"
        ),
        "3"
    );
    assert_eq!(
        solve(
            r"4
1 2 3 4"
        ),
        "0"
    );
}


Measured memory_bytes: 6396
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl
#define Cerr(x) cerr<<(x)<<endl
#define fi first
#define se second
#define P pair<ll,ll> 
#define m_p make_pair

ll n,cnt,ans,a,b,c,d,tmp,tmpp,m,h,w,x,y,sum,pos,k;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s,t;
bool fl;
struct edge{int to,cost;};
map<ll,ll> mem;

//-------------------------↓↓↓↓↓↓------------------------

long long gcd(long long aaa,long long bbb){
    if(bbb==0){
        return aaa;
    }
    return gcd(bbb,aaa%bbb);
}
 
long long lcm(long long aaa,long long bbb){
    long long g = gcd(aaa,bbb);
    return aaa/g * bbb;
}

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

    cin>>n>>m>>s>>t;
    ans=lcm(n,m);
    rep(i,n){
        mem[i*(ans/n)+1]++;
    }
    rep(i,m){
        mem[i*(ans/m)+1]++;
    }

    rep(i,n){
        if(mem[i*(ans/n)+1]==2){
            tmp=i;
            tmpp=(i*(ans/n))/(ans/m);
            if(s[tmp]!=t[tmpp]){
                Cout(-1);
                return 0;
            }
        }
    }

    rep(i,m){
        if(mem[i*(ans/m)+1]==2){
            tmpp=i;
            tmp=(i*(ans/m))/(ans/n);
            if(s[tmp]!=t[tmpp]){
                Cout(-1);
                return 0;
            }
        }
    }

    Cout(ans);
    return 0;
}


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

int main() {
  int a, b, c;
  scanf("%d %d %d", &a, &b, &c);
  
  bool f = false;
  if (a == b && a != c)
    f = true;
  if (a == c && a != b)
    f = true;
  if (b == c && a != b)
    f = true;
  
  if (f)
    printf("Yes\n");
  else
    printf("No\n");

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define repk(i,m,n) for(int i=m;i<n;i++)
#define IOS ios::sync_with_stdio(false);cin.tie(0);
#define F first
#define S second
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef long double ld;
using namespace std;
const int MOD1=1e9+7;
const int MOD2=998244353;
const ll INF=2*1e18;
const ld PI=3.14159265358979323846;
int main()
{
    ll n;
    string s;
    cin>>n>>s;
    if(n>=s.size()) cout<<s;
    else
    {
        rep(i,n) cout<<s[i];
        cout<<"...";
    }
}


Measured memory_bytes: 3624
s = str(input())

i = 0
while i < len(s):      
    if s[i:i+11] == 'dreameraser':
        i += 11
    elif s[i:i+10] == 'dreamerase':
        i += 10
    elif s[i:i+7] == 'dreamer':
        i += 7
    elif s[i:i+5] == 'dream':
        i += 5
    elif s[i:i+6] == 'eraser':
        i += 6
    elif s[i:i+5] == 'erase':
        i += 5
    else:
        break
if i == len(s):
    ans = 'YES'
else:
    ans = 'NO'
print(ans)

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

    using namespace std;
    typedef long long ll;
    typedef unsigned long long ull;
    # define M_PI  3.14159265358979323846

    void solve(){
        long long a,b,n;
        cin>>a>>b>>n;
        cout<<(b/n - a/n +(a%n==0 ? 1:0));
    }
    int main(){
        ios::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
        cout<<fixed;
        cout<<setprecision(10);
        int t=1;
//        cin>>t;
        for(int i=1;i<=t;i++){
            solve();
        }
        return 0;
    }


Measured memory_bytes: 3624
#include <bits/stdc++.h>
#include <iomanip>
#include <math.h>
//#include <unistd.h>
//#include <stdio.h>
#define rep(i,x) for(ll i = 0;i<x;i++)
#define all(a) (a).begin(),(a).end()
using ll = long long;
using ld = long double;
using namespace std;
using dou = double;
const ll inf = 2147483647;
const ll INF = 1LL << 60;
const ld pi = 3.14159265358;
const ll mod = 1000000007;
typedef pair<ll,ll> P;
using graph = vector<vector<ll>>;
template<class T> inline bool chmax(T& a, T b){if(a < b){a = b; return true;}return false;}
template<class T> inline bool chmin(T& a, T b){if(a > b){a = b; return true;}return false;}
ll gcd(ll a,ll b){
    if(a < b)swap(a,b);
    if(a % b == 0)return b;
    else return gcd(b,a%b);
}
//素数判定O(sqrt(N))
bool isp(ll n){
    bool res = true;
    if(n == 1)return false;
    else{
        for(ll i = 2;i * i <= n;i++){
            if(n % i == 0){
                res = false;
                break;
            }
        }
        return res;
    }
}

ll fac[510000], finv[510000], inv[510000];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < 510000; i++){
        fac[i] = fac[i - 1] * i % mod;
        inv[i] = mod - inv[mod%i] * (mod / i) % mod;
        finv[i] = finv[i - 1] * inv[i] % mod;
    }
}

// 二項係数計算
ll nCk(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
//nのm乗をMODで割ったあまりO(logN)
ll modpow(ll n,ll m,ll MOD){
    ll res = 1;
    while(m){
        if(m & 1)res = (res * n) % MOD;
        m >>= 1;
        n *= n;
        n %= MOD;
    }
    return res;
}

//printf("%.10f\n", N);
/*  vector<ll> vec = {1,2,5,6,8,9,10};
    cout << binary_search(all(vec),5) << endl; -> true*/
/*
    vector<ll> vec = {1,2,5,6,8,9,10};
    auto n = upper_bound(all(vec),4);
    cout << *n << endl; -> 5*/

//    cout << fixed << setprecision(15);

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll N,M;
    cin >> N >> M;
    cout << modpow(N,M,mod) << endl;
}


Measured memory_bytes: 3220
N = int(input())
a = [int(i) for i in input().split()]

b = [0] * N
M = 0
ans = []
for i in range(N, 0, -1):
    count = a[i-1]
    x = 2
    while x * i <= N:
        count += b[x*i-1]
        x += 1
    if count % 2 == 1:
        b[i-1] = 1
        M += 1
        ans.append(i)


print(M)
print(*ans)



Measured memory_bytes: 14060
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef unsigned long long int ulli;
typedef long double ld;
#define S 5000005
#define M 1000000007
#define nl cout<<"\n";
#define er  cout<<"\n***********\n";
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define test lli t;  cin>>t; while(t--)
#define all(x) (x).begin(),(x).end()
#define sz(x) (lli)(x.size())
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define Y cout<<"Yes\n";
#define N cout<<"No\n";
#define print(x)                 cout<<#x<<": "<<x<<endl;
#define print2(x, y)             cout<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl;
#define print3(x, y, z)          cout<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl;
#define print4(a, b, c, d)       cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl;
#define print5(a, b, c, d, e)    cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl;
#define print6(a, b, c, d, e, f) cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl;

void solve()
{
    lli x,k,d;
    cin>>x>>k>>d;
    if(x<0) x=-1*x;
    lli mini = x/d;
    if(k<=mini)
    {
        // er
        x=x-k*d;

        cout<<x;
        return ;
    }

    k=k-mini;

    if(k%2==0)
    {
        x=x-mini*d;
    }
    else
    {
         x=(x-(mini+1)*d);
        
    }

    x=abs(x);


    cout<<x;

    




}
int main()
{
    fast
    #ifndef ONLINE_JUDGE
     freopen("inputa.txt", "r", stdin);
     freopen("outputa.txt", "w", stdout);
    #endif    
     
     // test
     {
          solve();
          nl
     }
}
//a+b=a?b+2?(a&b)
//__builtin_popcnt(number)
//cout<<fixed<<setprecision(8)<<output<<"\n";


Measured memory_bytes: 3636
#include <iostream>
#include <cmath>

using namespace std;

bool valid_board(int *board)
{
    for (int i = 0; i < 8; i++) {
        if (board[i] != -1)
            for (int j = i + 1; j < 8; j++)
                if (board[j] != -1) 
                    if (board[i] == board[j] || abs(i - j) == abs(board[i] - board[j]))
                        return false;
    }
    
    return true;
}

void print_board(int *board)
{
    for (int i = 0; i < 8; i++) {
        for (int j = 0; j < 8; j++)
            cout << (j == board[i] ? 'Q' : '.');
        cout << endl;
    }
}

void fix_board(int *board)
{
    int backtrack_list[8] = {};
    int new_board[8];
    bool backtrack = false;

    for (int i = 0; i < 8; i++)
        new_board[i] = board[i];

    for (int i = 0; i < 8; i++) {
        if (board[i] == -1) {
            int j;
            for (j = backtrack_list[i]; j < 8; j++) {
                new_board[i] = j;
                if (valid_board(new_board)) {
                    backtrack = false;
                    backtrack_list[i] = j + 1;
                    break;
                }
            }

            if (j == 8 || (backtrack && backtrack_list[i] == 8)) {
                backtrack_list[i] = 0;
                new_board[i] = -1;
                backtrack = true;
                i -= 2; // backtrack
            }
        } else if (backtrack)
            i -= 2; // backtrack
    }

    for (int i = 0; i < 8; i++)
        board[i] = new_board[i];
}

int main(void)
{
    int k;
    int board[8];

    for (int i = 0; i < 8; i++)
        board[i] = -1;
    
    cin >> k;
    for (int i = 0; i < k; i++) {
        int r, c;
        cin >> r >> c;
        board[r] = c;
    }

    fix_board(board);
    print_board(board);

    return 0;
}

Measured memory_bytes: 1152