akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
using namespace std;
int ans = 0;
int main()
{
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    if(a*500+b*100+c*50<c) {cout << 0<<endl;return 0;} //增加效率
    for(int i = 0;i <= a;i++)
    {
        if(i*500>d) {cout<<ans<<endl;return 0;} //500的价值都大于到了，那加上后边的肯定也大于了,直接结束程序。
        for(int j = 0;j <= b;j++)
        {
            if(j*100+i*500>d) break; //原理和上面一样，但不是结束程序.
            for(int k = 0;k <= c;k++)
            {
                if(i*500+j*100+k*50==d){ans++;break;} //一样的.
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<ctype.h>
#define MAX 1000
int top=0;
void push(int);
int pop();
int a[MAX];
int main(){
  
  int a;
  char s[100];

  while( scanf("%s", s) != EOF ){
    if ( s[0] == '+' ){
      push(pop()+pop());

    } else if ( s[0] == '-' ){
      int g=pop(),h=pop();
      
      push(h-g);

    } else if ( s[0] == '*' ){
      push(pop()*pop());

    } else {
      a = atoi(s);
      push(a);

    }
  }
  printf("%d\n",pop());
  return 0;
}
void push(int x){
  top++;
  a[top]=x;
}
int pop(){
  top--;
  return a[top+1];
}



Measured memory_bytes: 2104
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<vector>
#include<functional>
#include<algorithm>
#include<stdlib.h>
#include<string.h>
#include<cmath>
#include<set>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(ll i=a;i<b;i++)
bool d[12][12];
int main() {
	ll N, K, ans = 1e13;
	scanf("%lld%lld", &N, &K);
	vector<ll> h(N);
	rep(i, 0, N)scanf("%d", &h[i]);
	rep(i, 0, 1 << N) {
		ll cost = 0, c = 0, m = 0;
		rep(i2, 0, N) {
			if (i & (1 << i2)) {
				c++;
				if (m >= h[i2]) {
					cost += ++m - h[i2];
				}
				else m = h[i2];
			}
			else if (m < h[i2])m = h[i2], c++;
		}
		if(c == K)ans = min(ans, cost);
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
Spyder Editor

This is a temporary script file.
"""

#a,b,c=map(int,input().split())
import sys
n=int(input())
s=input()
if n%2==1:
    print("No")
    sys.exit()
p=s[0:int(n/2)]
if p+p==s:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 38256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<ll>;
using vii = vector<vi>;
using Pll = pair<ll, ll>;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
const int MOD = 1000000007;
template<class T> void print(const T& t){ cout << t << endl; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
  ll x;
  cin >> x;
  bool z = false;
  for (ll a = 1; a > 0; a++){
    ll a5 = a * a * a * a * a;
    if (a5 <= x){
      for (ll b = 0; a5-b*b*b*b*b <= x;b--){
        ll b5 = b * b * b * b * b;
        if(a5-b5==x){
          cout << a << " " << b << endl;
          goto OUT;
        }
      }
    }
    else if(a5>x){
      for (ll b = 1; a5 - b * b * b * b * b >= x;b++){
        ll b5 = b * b * b * b * b;
        if(a5-b5==x){
          cout << a << " " << b << endl;
          goto OUT;
          z = true;
        }
      }
    }
  }
  OUT:
    return 0;
}

Measured memory_bytes: 3636
(eval-when (:compile-toplevel :load-toplevel :execute)
  (defparameter OPT
    #+swank '(optimize (speed 3) (safety 2))
    #-swank '(optimize (speed 3) (safety 0) (debug 0)))
  #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))
                 (shadow :run)
                 (use-package :fiveam)))
#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)

;; BEGIN_INSERTED_CONTENTS
(defmacro define-int-types (&rest bits)
  `(progn
     ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "UINT~A" b)) () '(unsigned-byte ,b))) bits)
     ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "INT~A" b)) () '(signed-byte ,b))) bits)))
(define-int-types 2 4 7 8 15 16 31 32 62 63 64)

(defmacro println (obj &optional (stream '*standard-output*))
  `(let ((*read-default-float-format* 'double-float))
     (prog1 (princ ,obj ,stream) (terpri ,stream))))

(defconstant +mod+ 1000000007)

;; Hauptteil

(defun main ()
  (declare #.OPT)
  (let* ((n (read))
         (as (make-array n :element-type 'uint32)))
    (dotimes (i n)
      (setf (aref as i) (parse-integer (read-line) :junk-allowed t)))
    (let ((sum 0))
      (declare (uint32 sum))
      (labels ((skip-zero (i)
                 (cond ((= i n))
                       ((zerop (aref as i)) (skip-zero (1+ i)))
                       (t (traverse i 0))))
               (traverse (i res)
                 (declare (uint32 i res))
                 (cond ((= i n)
                        (incf sum (floor res 2)))
                       ((zerop (aref as i))
                        (incf sum (floor res 2))
                        (skip-zero i))
                       (t (traverse (1+ i) (+ res (aref as i)))))))
        (skip-zero 0))
      (println sum))))

#-swank(main)


Measured memory_bytes: 54248
#include <bits/stdc++.h>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
//using namespace __gnu_pbds;

#define LL       long long
#define DS       pair<LL, LL>
#define READ(f)  freopen(f, "r", stdin)
#define WRITE(f) freopen(f, "w", stdout)

const int N = 3e5 + 5;
const int MOD = 1e9 + 7;
const double PI = 2 * acos(0.0);
//template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

map<int, int> mop, what;

int main() {
    //ios::sync_with_stdio(false);
    //cin.tie(0);
    int n, m;
    scanf("%d %d", &n, &m);
    for (int i = 0; i < m; i++) {
        int x, y;
        scanf("%d %d", &x, &y);
        if (mop[x] && what[x] != y) {
            puts("-1");
            return 0;
        }
        mop[x] = 1;
        what[x] = y;
    }
    string ans = "";
    for (int i = 1; i <= n; i++) {
        if (i == 1 && mop[i] && what[i] == 0 && n > 1) {
            puts("-1");
            return 0;
        }
        if (mop[i] == 0) {
            if (i == 1 && n > 1) {
                ans += "1";
            } else {
                ans += "0";
            }
        } else {
            ans += (char)(what[i] + '0');
        }
    }
    cout << ans << '\n';
    return 0;
}


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

using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    cout << ((n >= 30) ? "Yes" : "No") << '\n';
    return 0;
}

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

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    rep (i, n) {
        cin >> a[i];
    }
    sort(all(a));
    if (n == 2) {
        cout << a[1] << " " << a[0] << endl;
        exit(0);
    }
    int m = a[a.size() - 1];
    auto it = upper_bound(all(a), m/2);
    int f = *it;
    int b = (distance(a.begin(), it) == 0 ? m :*(--it));
    int p = (f - m / 2.0 > m / 2.0 - b ? b : f);
    cout << m << " " << p << endl;
}


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

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

	char arr[n][m];
	for (int i=0;i<n;i++)
		for (int j=0;j<m;j++) cin>>arr[i][j];

	int nm=n*m;
	int dist[nm+1][nm+1];
	for (int i=0;i<=nm;i++)
		for (int j=0;j<=nm;j++)dist[i][j]=INT_MAX;

	for (int i=0;i<=nm;i++)
			dist[i][i]=0;

	int dirx[]={1,-1,0,0};
	int diry[]={0,0,1,-1};

	for (int i=0;i<n;i++){
		for (int j=0;j<m;j++){
			if (arr[i][j]=='#') continue;
			for (int dir=0;dir<4;dir++){
				int newx = i+dirx[dir];
				int newy = j+diry[dir];
				if (newx>=0 && newy>=0 && newx<n && newy<m && arr[newx][newy]!='#'){
						dist[m*i+j+1][m*newx+newy+1]=1;
				}
			}
		}
	}

	for (int k=1;k<=nm;k++)
	for (int i=1;i<=nm;i++)
	for (int j=1;j<=nm;j++){

		dist[i][j] = min(dist[i][k]+dist[k][j],dist[i][j]);

	}

	int ans=0;

	for (int i=1;i<=nm;i++){
		for (int j=1;j<=nm;j++){
			if (dist[i][j]==INT_MAX) continue;
			ans=max(ans,dist[i][j]);
		}
	}

	cout<<ans<<'\n';
}


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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = (n)-1; i >= 0; i--)
#define ll long long

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

int main(){
  int n;cin>>n;
  vector<ll>a(n), b(n),c(n);
  rep(i,n)cin>>a[i]>>b[i]>>c[i];

  vector<vector<ll>> dp(n+1, vector<ll>(3, 0));

  rep(i, n){
    dp[i+1][0] = a[i] + max(dp[i][1], dp[i][2]);
    dp[i+1][1] = b[i] + max(dp[i][0], dp[i][2]);
    dp[i+1][2] = c[i] + max(dp[i][0], dp[i][1]);
  }

  cout<<max<ll>( { dp[n][0], dp[n][1], dp[n][2] } )<<endl;
//rep(i, 3)cout<<dp[n][i]<<' ';cout<<endl;

  return 0;
}

Measured memory_bytes: 8064
#include <bits/stdc++.h>
using namespace std;
#define fast() ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define lp(i, n) for(int i = 0; i < n; i++)
#define rlp(i, n) for(int i = n-1; i >= 0; i--)
#define loop(i, a, b) for(int i = a; i <= b; i++)
#define rloop(i, a, b) for(int i = a; i >= b; i--)
#define mem(a, val) memset(a, val, sizeof a);
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define test int t; cin>> t; while(t--)
#define ll long long
#define ld long double
#define mp_ make_pair
#define pb push_back
#define sz(s) (int)s.size()
const int N = 1e3 + 3;
const int inf = 1e9+1;
const ll OO = 1e18;
const int mod = 1e9 + 7;
const double pi = 3.141592653;
typedef pair<int,int> pii;
typedef vector<int> vi;

int main()
{
    ll a, b, c, d;
    cin>> a >> b >> c >> d;
    cout<< max(a * c, max(a * d, max(b * c, b * d)));
    return 0;
}


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

int main()
{
    int n;
    cin >> n;
    vector<pair<int, int>> nums(n);
    for(int i = 0; i < n; i++)
    {
        cin >> nums[i].first >> nums[i].second;
    }
    sort(nums.begin(), nums.end());
    int ans = 0;
    ans += nums[n - 1].first - nums[0].first + 1; // 最小と最大の間の個数
    ans += nums[0].first - 1; // 数列の最大の数値までの個数
    ans += nums[n - 1].second;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4052
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i< (n);i++)
using namespace std;
typedef long long ll;
const ll MOD = (1e+9)+7;

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
 
  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};
// combination mod prime
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&feature=youtu.be&t=1619
struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};


int main(){
    int n,k;cin>>n>>k;
    mint ans;
    k = min(n,k);
    combination c(n);
    for(int i = 0; i <= k; i++){
        ans += c(n,i) * c(n-1,n-i-1);
    }
    cout<<ans.x<<endl;
    return 0;
}

Measured memory_bytes: 3328
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
const double PI = 3.141592653589793238;
const double EPS = 1e-10;
ll dp[101][101][301];
ll w[100], v[100];
int main() {
	ll N, W;
	cin >> N >> W;
	for (int i = 0; i < N; i++) {
		cin >> w[i] >> v[i];
	}
	for (int i = 0; i < N; i++) {
		for (int j = 0; j <= i; j++) {
			for (int k = 0; k <= 3 * j; k++) {
				dp[i + 1][j][k] = max(dp[i + 1][j][k], dp[i][j][k]);
				dp[i + 1][j + 1][k + (w[i] - w[0])] = max(dp[i + 1][j + 1][k + (w[i] - w[0])], dp[i][j][k] + v[i]);
			}
		}
	}
	ll ans = 0;
	for (int i = 1; i <= N; i++) {
		if (W < w[0] * i) break;
		for (int j = 0; j <= min(3LL * i, W - w[0] * i); j++) {
			ans = max(ans, dp[N][i][j]);
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 22272
#include <bits/stdc++.h>
#define int long long
#define rep(i, a, n) for(int (i) = (int)(a);(i) < (int)(n);++(i))
#define repe(i, a, n) for(int (i) = (int)(a);(i) <= (int)(n);++(i))
#define repif(i, a, x) for(int (i) = (int)(a);(x);++(i))
#define repr(i, a, n) for(int (i) = ((int)(a)-1);(i) >= (int)(n);--(i))
#define reper(i, a, n) for(int (i) = (int)(a);(i) >= (int)(n);--(i))
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define SIZE(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()
#define RNG(x, a, n) &((x)[a]), &((x)[n])
#define ADD(a, b) ((((a+MOD)%MOD)+((b+MOD)%MOD))%MOD)
#define MUL(a, b) ((((a)%MOD)*((b)%MOD))%MOD)
#define CEIL(x) ((int)ceil(((double)x)))
#define POW(x, y) ((int)pow(x, y))
#define UNIQUE(x) (x).erase(unique(ALL((x))), (x).end())
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define yes cout << "yes" << endl;
#define no cout << "no" << endl;
#define fcout cout << fixed << setprecision(10)
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define PI (acos(-1))
#define EPS (1e-10)
#define INF LLONG_MAX
#define MOD 1000000007
using namespace std;
using VI = vector<int>;
using PII = pair<int, int>;
using VPII = vector<PII>;
template<typename T, typename C> using PQ = priority_queue<T, vector<T>, C>;
using Complex = complex<double>;


struct UF {
	int n, num;
	VI r, p, s;
	UF(){}
	UF(int sz) : n(sz), num(sz), r(sz, 1), p(sz, 0), s(sz, 1){ iota(ALL(p), 0); }
	int find(int x){
		return (x == p[x] ? x : p[x] = find(p[x]));
	}
	bool same(int x, int y){
		return find(x) == find(y);
	}
	void unite(int x, int y){
		x = find(x), y = find(y);
		if(x == y) return;
		if(r[x] < r[y]) swap(x, y);
		r[x] += r[y];
		p[y] = x;
        s[x] += s[y];
		num--;
	}
	int rank(int x){
		return r[find(x)];
	}
	int count() const{
		return num;
	}
    int size(int x){
        return s[find(x)];
    }
};


int N, M;
int A[100010], B[100010];
UF uf;
int ans[100010];


signed main(){
    cin >> N >> M;
    rep(i, 0, M) cin >> A[i] >> B[i], A[i]--, B[i]--;

    uf = UF(N);

    ans[M-1] = N*(N-1)/2;
    repr(i, M, 1){
        if(uf.same(A[i], B[i])) ans[i-1] = ans[i];
        else {
            int s1 = uf.size(A[i]);
            int s2 = uf.size(B[i]);
            ans[i-1] = ans[i]-s1*s2;
            uf.unite(A[i], B[i]);
        }
    }

    rep(i, 0, M) cout << ans[i] << endl;

    return 0;
}

Measured memory_bytes: 6016
#include<bits/stdc++.h>
using namespace std;
int main()
{
int a[5],ans=0;
for(int i=0;i<3;i++) cin>>a[i];
sort(a,a+3);
for(int i=1;i<3;i++) ans+=(a[i]-a[i-1]);
cout<<ans<<endl;


}

Measured memory_bytes: 256
ii = lambda:int(input())
mi = lambda:list(map(int,input().split()))
ix = lambda x:list(input() for _ in range(x))
mix = lambda x:list(mi() for _ in range(x))
iix = lambda x:list(int(input()) for _ in range(x))
##########
def main(a,b):
    return a + b if b % a == 0 else b - a

a,b = mi()
print(main(a,b))

Measured memory_bytes: 3064
// Problem : D - Alter Altar
// Contest : AtCoder - AtCoder Beginner Contest 174
// URL : https://atcoder.jp/contests/abc174/tasks/abc174_d
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include<bits/stdc++.h>
#include<set>
#include<map>
#include<bitset>
#define rep(i,a,b)  for(i=a;i<b;i++)
#define Sort(a)	sort(a.begin(),a.end())
#define rev(a)	reverse(a.begin(),a.end())
#define all(a)	(a).begin(),(a).end()
#define vll vector<long long int>
#define lli long long int
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define db double
#define M 1000000007
#define pi 3.1415926535897932384626433832795028841971
#define INF 1e18

#define MAX 200005

using namespace std;
lli min(lli a,lli b){return a<b?a:b;}
lli min(lli a,lli b,lli c){a=min(a,b);a=min(a,c);return a;}
lli max(lli a,lli b){return a>b?a:b;}
lli max(lli a,lli b,lli c){a=max(a,b);a=max(a,c);return a;}
lli dsum(lli n){lli ans=0;while(n){ans+=(n%10);n/=10;}return ans;}
lli power(lli a,lli b){lli res=1;while(b){if(b&1) res=res*a;a=a*a;b>>=1;}return res;}
lli power(lli a,lli b,lli m){if(b==0)	return 1;if(b==1)	return a%m;lli res=1;a=a%m;while(b){if(b&1){res=(res*a)%m;}a=((a%m)*(a%m))%m;b>>=1;}return res;}
lli Ceil(lli a,lli b){lli res=a/b;if(a%b!=0)	res++;return res;}

template<typename T>istream &operator>>(istream &is, vector<T> &v) { for (T &t : v) is >> t; return is; }
template<typename T>ostream &operator<<(ostream &os, const vector<T> &v) { for (const T &t : v) {os << t <<" ";} os << '\n'; return os; }

lli dxx[]={1,1,0,-1,-1,-1,0,1};
lli dyy[]={0,1,1,1,0,-1,-1,-1};
lli dx[]={1,0,-1,0};
lli dy[]={0,1,0,-1};

struct pll{
	lli x,y;
};
bool comp(pll a,pll b){
	if(a.x==b.x)	return a.y<b.y;
	else	return a.x<b.x;
}
void solve(lli the)
{
	char ch;
	db aa,bb,cc,dd,xx;
	string s1,s2,s3,str;
    lli i,j,k,a,b,c,d,n,m,l,r,x,y,z,low,high,mid,sum=0,ans=0,temp,t;
    cin >> n;
    cin >> s1;
    a=0;b=0;
    for(i=0;i<n;i++){
    	if(s1[i]=='W')	a++;
    	else	b++;
    }
    low=0;high=n-1;
    while(low<b && high>=n-a){
    	if(s1[high]=='W')	high--;
    	else if(s1[low]=='R')	low++;
    	else{
    		ans++;
    		swap(s1[low],s1[high]);
    	}
    }
    cout << ans;
    
    
}















int main()
{
	long long int t=1,c=1;
	// scanf("%lld",&t);
	while(t--){
		solve(c);
		c++;
	}
	return 0;
}
/* UJJWAL KESHRI */

Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007

int main()
{
  string s,t;

  cin>>s>>t;

  int m=s.size();
  int n=t.size();

  if(s==t)
    cout<<s<<"\n";
  else
  {
      int dp[m+1][n+1];

      for(int i=0;i<=m;i++)
      {
          for(int j=0;j<=n;j++)
          {
              if(i==0||j==0)
                 dp[i][j]=0;
              else if(s[i-1]==t[j-1])
                dp[i][j]=1+dp[i-1][j-1];
              else
                dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
          }
      }
      int index=dp[m][n];
      int i=m,j=n;
      char q[index+1];
      int r=index-1;

    while(i>0&&j>0)
    {
      if(s[i-1]==t[j-1])
      {
          q[r--]=s[i-1];
          i--; j--;
      }
      else if(dp[i][j-1]>dp[i-1][j])
           j--;
      else
        i--;
    }
    q[index]='\0';
    cout<<q<<"\n";
  }
    return 0;
}


Measured memory_bytes: 35456
func readArrayInt() -> [Int] {
    readLine()!.split(separator: " ").map({Int($0)!})
}

// input
var line = readArrayInt()
let (N, M, X) = (line[0], line[1], line[2])
var C: [Int] = []
var A: [[Int]] = []
(1...N).forEach({ _ in
    line = readArrayInt()
    C.append(line[0])
    var row: [Int] = []
    (1...M).forEach({row.append(line[$0])})
    A.append(row)
})

// main
func allAchived(_ bits: Int) -> Bool {
    var achieved = Array(repeating: 0, count: M)
    (0..<N).forEach({ place in
        if ((1 << place & bits) > 0) {
            for (i, value) in A[place].enumerated() {
                achieved[i] += value
            }
        }
    })
    for i in 0..<M {
        if (achieved[i] < X) {
            return false
        }
    }
    return true
}

func cost(_ bits: Int) -> Int {
    var cost = 0
    (0..<N).forEach({ place in
        if ((1 << place & bits) > 0) {
            cost += C[place]
        }
    })
    return cost
}

var ans = -1
(1..<(1 << N)).forEach { bits in
    if (allAchived(bits)) {
        ans = ans < 0 ? cost(bits) : min(cost(bits), ans)
    }
}

print(ans)


Measured memory_bytes: 8308
#include <iostream>
#include <map>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;
int main() {
   int n,key=1;
   cin >> n;
   int arr[200009];
   for(int i=0;i<n;i++){
       cin >>arr[i];
   }

   for(int i=0;i<n;i++){
       if(arr[i] == key) key++;
   }
   if(key==1)cout <<-1<<"\n";
   else cout <<n-key+1;
   return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef  long long int     ll;
typedef  vector<int>       vi;
typedef  pair<int,int>     pii;
//#define  int               ll
#define  F                 first
#define  S                 second
#define  pb                push_back
#define  mp                make_pair 
#define  si(x)             (int)x.size()
#define  all(x)            x.begin(),x.end()
#define  minv(m,n)         *min_element(m,n)      
#define  maxv(m,n)         *max_element(m,n)
#define  mem(a,x)          memset(a,x,sizeof(a))
#define  rep(i,n)          for(int i=0; i<n;i++)
#define  prs(x)            fixed <<setprecision(x)
#define  w(ttz)            int ttz;cin>>ttz;while(ttz--)
#define  show(a)           for(auto x:a){cout<<x<<" ";}cout<<endl;
#define  mod               100000007
void iosbase(void);

int main() 
{   
  	iosbase();
  	int n , k;
  	cin>>n>>k;
  	int a[n];
  	rep(i , n)
  	cin>>a[i];
  	sort(a , a+n);
  	int ans=0;
  	rep(i , k)
  	{
  		ans=ans+a[i];
  	}
  	cout<<ans<<endl;


}


void iosbase(void){
ios::sync_with_stdio(false);
cin.tie(nullptr);cout.tie(nullptr);
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
#endif 
}

Measured memory_bytes: 3652
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE ScopedTypeVariables #-}
import qualified Data.ByteString.Lazy.Char8 as B
import Data.Maybe
import qualified Data.IntMap as IM
import qualified Data.IntSet as IS
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
import qualified Data.Vector as V
import qualified Data.Vector.Mutable as VM
import Control.Monad
import Control.Monad.ST
import Data.List
import Debug.Trace

solve :: Int -> Int -> [Int] -> [(Int,Int)] -> Int
solve n m ps xys = runST act where

  act = do
    grp <- uftInit (n+1)
    mapM_ (uncurry (uftMerge grp)) xys
    vec <- VM.replicate (n+1) ([], [])
    forM_ (zip [n,n-1..1] (reverse ps)) $ \(i,p) ->
      uftRoot grp i >>= VM.modify vec (\(is, ps) -> (i:is, p:ps))
    foldl' (op vec) (return 0) [1..n] where
      op vec msum j = do
        sum <- msum
        (is, ps) <- VM.read vec j
        return $ sum + IS.size (IS.intersection (IS.fromDistinctAscList is)
                                                (IS.fromList ps))

uftInit :: Int -> ST s (VUM.MVector s Int)
uftInit size = do
  vec <- VUM.new size
  forM_ [0..size-1] $ \i -> VUM.write vec i i
  return vec

uftMerge :: VUM.MVector s Int -> Int -> Int -> ST s ()
uftMerge vec x y = do
  rx <- uftRoot vec x
  ry <- uftRoot vec y
  if rx == ry then return ()
              else VUM.write vec rx ry

uftRoot :: VUM.MVector s Int -> Int -> ST s Int
uftRoot vec x = do
  y <- VUM.read vec x
  if x == y then return x
            else uftRoot vec y >>= vum_write_ret vec x

vum_write_ret :: VUM.Unbox a => VUM.MVector s a -> Int -> a -> ST s a
vum_write_ret vec i a = VUM.write vec i a >> return a

readBInt :: B.ByteString -> Int
readBInt = fst . fromJust . B.readInt

tmain :: B.ByteString -> Int
tmain cont =
  let remLines0 = map B.words (B.lines cont)
      [bs_n,bs_m]:remLines1 = remLines0
      n = readBInt bs_n
      m = readBInt bs_m
      line2:remLines2 = remLines1
      ps = map readBInt line2
      xys = map (\[x1,x2] -> (readBInt x1,readBInt x2)) remLines2
  in solve n m ps xys

outAnswer :: Int -> IO ()
outAnswer = putStrLn . show

main :: IO ()
main = outAnswer . tmain =<< B.getContents


Measured memory_bytes: 51580
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<tuple>
#define int long 
using namespace std;

signed main() {
	int N;
	cin >> N;
	cout << N * 800 - N / 15 * 200 << endl;
}

Measured memory_bytes: 256
from collections import deque
H, W, M = map(int, input().split())
bomb = []
counth = [0 for k in range(H)]
countw = [0 for k in range(W)]
for k in range(M):
  h, w = map(int, input().split())
  h -= 1
  w -= 1
  bomb.append(h+ w*H)
  counth[h] += 1 
  countw[w] += 1

counth = deque(counth)
countw = deque(countw)

maxh = max(counth)
maxw = max(countw)
index_h = deque([])
index_w = []
for k in range(H):
  h = counth.popleft()
  if h == maxh:
    index_h.append(k)
for k in range(W):
  w = countw.popleft()
  if w == maxw:
    index_w.append(k)

ans = maxh + maxw - 1
lenh = len(index_h)
lenw = len(index_w)

if lenh*lenw > M:
  ans += 1
else:
  bomb.sort()
  bomb = deque(bomb)
  kouho = []
  for i in range(lenh):
    h = index_h.pop()
    for j in range(lenw):
      w = index_w[j]
      kouho.append(h+ H*w)
  kouho.sort()
  kouho = deque(kouho)
  B = bomb.popleft()
  K = kouho.popleft()
  while True:
    if B > K:
      ans += 1
      break
    elif B == K:
      if len(kouho) == 0:
        break
      else:
        K = kouho.popleft()
      if len(bomb) == 0:
        ans += 1
        break
      else:
        B = bomb.popleft()
    else:
      if len(bomb) == 0:
        ans += 1
        break
      else:
        B = bomb.popleft()
print(ans)



Measured memory_bytes: 151324
use proconio::input;

fn main() {
    input! {
        n: usize,
        a: [i64; n],
    };
    let mut s = 0;
    let mut m = 1_000_i64;
    for i in 0..n {
        m += a[i] * s;
        s = 0;
        if i + 1 < n {
            if a[i] < a[i + 1] {
                s = m / a[i];
                m -= s * a[i];
            }
        }
    }
    let ans = m;
    println!("{}", ans);
}


Measured memory_bytes: 2172
import sys

def solve():
    N, Q = map(int, sys.stdin.readline().split())

    p = FenwickTree(N + 1)
    q = FenwickTree(N + 1)

    for qi in range(Q):
        query = sys.stdin.readline().rstrip()

        if query[0] == '0':
            c, s, t, x = map(int, query.split())
            s -= 1
            p.add(s, -s*x)
            p.add(t, t*x)
            q.add(s, x)
            q.add(t, -x)
        else:
            c, s, t = map(int, query.split())
            s -= 1

            res = p.get_sum(t) + q.get_sum(t)*t
            res -= p.get_sum(s) + q.get_sum(s)*s

            print(res)

class FenwickTree:
    def __init__(self, size):
        self.n = size
        self.data = [0]*(size + 1)

    def add(self, i, x):
        i += 1

        while i <= self.n:
            self.data[i] += x
            i += i & (-i)

    def get_sum(self, r):
        res = 0

        while r > 0:
            res += self.data[r]
            r -= r & (-r)

        return res

if __name__ == '__main__':
    solve()

Measured memory_bytes: 13900
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <string>
#include <cstdio>
#include <queue>
#include <list>
using namespace std;


//?°???\???????????????public?????????
class Node {
public:
  int id;
  int parent;
  int depth;
  string type;
  int degree;
  vector<int> c;
public:

  Node(int id, vector<int> c): id(id), c(c)
  {
    depth = degree = parent = -1;
  }
  void print();
};

void Node::print(){
  if(parent == -1)  type = "root";
  else if(!c.size()) type = "leaf";
  else              type = "internal node";
  printf("node %d: parent = %d, depth = %d, %s, [", id, parent, depth, type.c_str());
  for(int i=0;i<(int)c.size();i++){
    printf("%d", c[i]);
    if(i != (int)c.size()-1){
      printf(", ");
    }
  }
  printf("]\n");
}

int search(vector<Node> &v, int id, int depth){
  v[id].depth = depth;
  for(int i=0;i<v[id].c.size();i++){
    search(v, v[id].c[i], depth+1);
  }
}

bool asc(const Node &right, const Node &left){return right.id < left.id;}

int main(void){
  int n;
  cin >> n;
  vector<Node> nodes;

  //??\?????¨
  for(int i=0;i<n;i++){
    int id, t; cin >> id >> t;
    vector<int> v(t);
    for(int j=0;j<t;j++)
      cin >> v[j];
    Node node(id, v);
    nodes.push_back(node);
  }

  sort(nodes.begin(), nodes.end(), asc);

  //????????¨
  for(int i=0;i<n;i++){
    for(int j=0;j<nodes[i].c.size();j++){
      nodes[nodes[i].c[j]].parent = nodes[i].id;
    }
  }
  for(int i=0;i<n;i++){
    if(nodes[i].parent == -1){
      search(nodes, i, 0);
    }
  }

  //????????¨
  for(int i=0;i<n;i++){
    nodes[i].print();
  }

  return 0;
}

Measured memory_bytes: 17036
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
typedef vector<int> VI;
ll mm=1000000000;ll MM=mm+7;
#define rep(i, n) for(int i=0;i<n;i++)
#define PI 3.141592653589793




int main(){
   int n,k;
   cin >> n >> k;
   if(n>=2*k-1)cout << "YES" << endl;
   else cout << "NO" << endl;

}

Measured memory_bytes: 3608
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
  string w;
  cin >> w;
  int cnt = 0;
  bool flag = true;
  for (int i=0;i<w.size();i++) {
    for (int j = 0; j < w.size(); j++) {
      if (w[i] == w[j]) cnt++;
    }

    if (cnt % 2 != 0) {
      flag = false;
      break;
    }
    cnt=0;
  }

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


Measured memory_bytes: 256
#ifndef _WIN32
#include<iostream>
#endif

#include<iomanip>
#include<vector>
#include<string>
#include<queue>
#include<stack>
#include<algorithm>
#include<set>
#include<map>
using namespace std;
#define FOR(i,bg,ed) for(int i=(bg);i<(ed);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

typedef long long LL;
template<typename T>
bool chmin(T &l, T& r){
	bool f = l>r; if (f)l = r; return f;
}
template<typename T>
bool chmax(T &l, T& r){
	bool f = l<r; if (f)l = r; return f;
}
typedef vector<int> V;
typedef vector<V> VV;
typedef pair<int, LL> P;

int main(){
	LL N, M;
	while (cin >> N >> M,N+M){
		vector<LL> d(11);
		REP(i, N){
			int a, b;
			cin >> a >> b;
			d[b] += a;
		}
		REP(_, 11){
			int i = 10 - _;
			LL cost = min(d[i], M);
			M -= cost;
			d[i] -= cost;
		}
		LL res = 0;
		REP(i, 11){
			res += d[i] * i;
		}
		cout << res << endl;
	}

	return 0;
}

Measured memory_bytes: 3048
N = gets.to_i
A = gets.split.map(&:to_i)

n = N
f = A.count{ |a| a % 4 == 0 }
e = A.count{ |a| a % 2 == 0 }
o = N - e
t = e - f

ans = "Yes" if f >= o / 2
ans = "Yes"

b = Array.new(N+1)
b[0] = 4

1.upto N do |i|
  
  if b[i-1] % 4 == 0
    if o > 0
      o -= 1
      b[i] = 1
    elsif e > 0
      e -= 1
      b[i] = 2
    else
      f -= 1
      b[i] = 4
    end
  elsif b[i-1] % 4 == 2
    if e > 0
      e -= 1
      b[i] = 2
      elsif f > 0
      f -= 1
      b[i] = 4
    else
      ans = "No"
      break
    end
  else
    if f > 0
      f -= 1
      b[i] = 4
    else
      ans = "No"
      break
    end
  end
end
    
puts ans

Measured memory_bytes: 9356
#include <iostream>
using namespace std;
 
int main(){
    int a,b,c,k;
    cin >> a >> b >> c >> k;
    int ans = 0;
    if(a >= k){
        cout << k << endl;
    }
    else{
        k -= a; ans += a;
        if(b >= k ){
            cout << ans << endl;
        }
        else{
            k -= b;
                cout << ans-k << endl;
        }
    }
    return 0;

}

Measured memory_bytes: 3636
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class Main {
    private static final int MOD = 1_000_000_007;

    public static void main(String[] args) {
        final Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        final int n = in.nextInt();
        final int k = in.nextInt();
        for (int i = 1; i <= k; ++i) {
            System.out.println((c(k - 1, i - 1) * c(n - k + 1, i)) % MOD);
        }
    }

    public static long A(int n, int m) {
        long result = 1;
        for (int i = m; i > 0; i--) {
            result *= n;
            n--;
            result %= MOD;
        }
        return result;
    }

    private static long c(int n, int k) {        
        return A(n, k) * BigInteger.valueOf(A(k, k)).modInverse(BigInteger.valueOf(MOD)).longValue() % MOD;
    }
}

Measured memory_bytes: 31704
# coding: utf-8
import queue
while 1:
    w,h=map(int,input().split())
    if w==0:
        break
    field=[]
    for i in range(h):
        field.append(list(input()))
    B=0
    W=0
    for i in range(h):
        for j in range(w):
            if field[i][j]=='.':
                q=queue.Queue()
                q.put((i,j))
                check=set()
                d=0
                while not q.empty():
                    y,x=q.get()
                    if field[y][x]=='.':
                        field[y][x]='#'
                        d+=1
                    elif field[y][x]=='W':
                        check.add('W')
                        continue
                    elif field[y][x]=='B':
                        check.add('B')
                        continue
                    else:
                        continue
                    if 0<=y+1<h and 0<=x<w:
                        q.put((y+1,x))
                    if 0<=y-1<h and 0<=x<w:
                        q.put((y-1,x))
                    if 0<=y<h and 0<=x+1<w:
                        q.put((y,x+1))
                    if 0<=y<h and 0<=x-1<w:
                        q.put((y,x-1))
                if len(check)==2:
                    pass
                elif 'B' in check:
                    B+=d
                elif 'W' in check:
                    W+=d
    print(B,W)


Measured memory_bytes: 7008
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int N;
    cin>>N;
    long long ans;
    ans=0;
    for(int i=1;i<=N;i++){
        if(i%3!=0&&i%5!=0){
            ans+=i;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3624
#include "bits/stdc++.h"
using namespace std;
using ll     = long long;
using pii    = pair<int, int>;
using pll    = pair<ll, ll>;
using vi     = vector<int>;
using vl     = vector<ll>;
using vvi    = vector<vi>;
using vvl    = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}
template <class C>
void print(const C &c, std::ostream &os = std::cout) {
    std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, " "));
    os << std::endl;
}

int main() {
    int n, m;
    cin >> n >> m;
    vvl edges(n);
    deque<int> ret;
    vector<bool> used(n, false);
    for (int i = 0; i < m; ++i) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        edges[a].push_back(b);
        edges[b].push_back(a);
        if (i == 0) {
            ret     = {a, b};
            used[a] = used[b] = true;
        }
    }
    while (true) {
        int c       = ret.back();
        bool append = false;
        for (auto &v : edges[c]) {
            if (!used[v]) {
                ret.push_back(v);
                used[v] = true;
                append  = true;
                break;
            }
        }
        if (!append)
            break;
    }
    while (true) {
        int c       = ret.front();
        bool append = false;
        for (auto &v : edges[c]) {
            if (!used[v]) {
                ret.push_front(v);
                used[v] = true;
                append  = true;
                break;
            }
        }
        if (!append)
            break;
    }
    cout << ret.size() << "\n";
    for (auto &r : ret) {
        cout << r + 1 << " ";
    }
    cout << endl;
    return 0;
}

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

const int N=1e5+50;
LL n,m;
char S[N],T[N];

inline LL read(){
    LL x=0,f=1;char ch=getchar();
    for(;!isdigit(ch);ch=getchar())if(ch=='-')f=-1;
    for(;isdigit(ch);ch=getchar())x=(x<<3)+(x<<1)+ch-'0';
    return x*f;
}
LL gcd(LL x,LL y){ return (y ? gcd(y,x%y) : x); }
LL LCM(LL x,LL y){ return x/gcd(x,y)*y; }

int main(){
	n=read(),m=read();
	scanf("%s%s",S,T);
	for(LL i=0;i<n;++i)if(i*m%n==0){
		LL j=i*m/n;
		if(S[i]!=T[j])return puts("-1")*0;
	}
	printf("%lld\n",LCM(n,m));
	return 0;
}

Measured memory_bytes: 384
import sys
readline = sys.stdin.readline

def main():
  N = int(readline())
  line = readline().split()
  R = {}
  L = {}
  for i in range(N):
    r = int(line[i]) + i + 1
    l = i + 1 - int(line[i])
    if r in R:
      R[r] += 1
    else:
      R[r] = 1
    if l in L:
      L[l] += 1
    else:
      L[l] = 1
  cnt = 0
  for i in R:
    if i in L:
      cnt += R[i] * L[i]
  print(cnt)
  
if __name__ == '__main__':
  main()

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


/* macro */
#define rep(i,a,b) for(int i=a;i<b;i++)
#define revrep(i,a,b) for(int i = a; i > b; i--)
#define int long long
#define exist(s,e) ((s).find(e)!=(s).end())
#define all(v) (v).begin(), (v).end()
#define each(s,itr) for(auto (itr) = s.begin(); (itr) != s.end(); (itr)++)
#define sum(v) accumulate(all(v), (0LL))
#define Sort(v) sort(all(v))


/* constant */
const int inf = 100100100100100100;
const int mod = 998244353;
int dx[8]={1,0,-1,0,-1,1,-1,1};
int dy[8]={0,1,0,-1,-1,-1,1,1};


/* io_method */
int input(){int tmp;cin >> tmp;return tmp;}
string raw_input(){string tmp;cin >> tmp;return tmp;}
string readline(){string s;getline(cin, s);return s;}
template<class T> void printx(T n){cout << n;}
template<class T, class U> void printx(pair<T, U> p){cout << "(" << p.first << "," << p.second << ")";}
template<class T> void printx(vector<T> v){cout << "{";rep(i,0,v.size()){printx(v[i]);if(i != v.size()-1)printx(",");}cout << "}";}
template<class T> void print(T n){printx(n);cout << endl;}
template<class T> void print(set<T> s){cout << "{";each(s, e){if(e != s.begin()) printx(",");printx(*e);}cout << "}" << endl;}
template<class T, class U> void print(map<T, U> mp){cout << "{";each(mp, e){cout << "(" << e -> first << "," << e -> second << ")";}cout << "}" << endl;}


/* general_method */
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
vector<int> cs(vector<int> arr){vector<int> tmp;if(arr.size() == 0) return tmp;tmp.push_back(arr[0]);rep(i,1,arr.size()){tmp.push_back(tmp.back() + arr[i]);}return tmp;}

/* math_library */
int gcd(int a, int b){ if(b == 0) return a; return gcd(b, a % b);}
int lcm(int a, int b){ return a * b / gcd(a,b);}
int ceil(int a, int b){ if(a % b == 0) return a/b; else return a/b + 1;}
int digitlen(int n){int t = n;int cnt = 0;while(t){cnt++;t /= 10;}return cnt;}
bool isprime(int n){
    if(n < 2) return false;
    if(n % 2 == 0 || n % 3 == 0 || n % 5 == 0) return false;
    
    for(int i = 7; i * i < n + 1; i += 2){
        if(n % i == 0) return false;
    }
    return true;
}

int mod_pow(int x, int n, int m){
    if(n== 0) return 1;
    int res = mod_pow(x*x%m,n/2,m);
    if(n&1) res = res*x%m;
    return res;
}


int digitsum(int n){
    int ret = 0;
    while(n){
        ret += n % 10;
        n /= 10;
    }
    return ret;
}



/* main */



signed main(){

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

    int a, b; cin >> a >> b;

    string s;
    string t;
    cin >> s >> t;

    if(s[0] != t[0]){
        print(-1);
        return 0;
    }

    int l = lcm(a,b);

    int x = l / b;
    int y = l / a;

    while(x < a && y < b){
      
        if(s[x] != t[y]){
            print(-1);
            return 0;
        }
        x += l/b;
        y += l/a;
    }
    

    print(l);



    

    

    

    
   
    
    

    








}   

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

bool is_palindrome(string s){
    string t(s.rbegin(),s.rend());
    return t==s;
}
int main()
{
    string s;
    cin >>s;
    int n = s.size();
    if(is_palindrome(s)&& is_palindrome(s.substr(0,n/2)) && is_palindrome(s.substr(n/2+1))){
        cout << "Yes"<< endl;
    }
    else cout << "No" << endl;
    return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pt(sth) cout << sth << "\n"
#define chmax(a, b) {if(a<b) a=b;}
#define chmin(a, b) {if(a>b) a=b;}
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
static const ll INF=1e18;
static const ll MOD=1e9+7;
static const ll MAX=101010;

/*
 for(i=0; i<N; i++)
   cin >> a[i];
*/


int main(void) {
  ll i, j, k, l;
  ll H, W, K;
  cin >> H >> W >> K;
  string s[333];
  ll a[333][333]={};
  
  for(i=0; i<H; i++) cin >> s[i];
  
  vector<ll> v[333];
  for(i=0; i<H; i++) {
    for(j=0; j<W; j++) {
      if(s[i][j]=='#')
        v[i].push_back(j);
    }
  }
  
  ll clr=1;
  for(i=0; i<H; i++) {
    ll t=0;
    
    if(v[i].empty()) continue;
    
    for(j=0; j<(ll)v[i].size()-1; j++) {
      ll u=v[i][j];
      while(t<=u) {
        a[i][t]=clr;
        t++;
      }
      clr++;
    }
    
    for(j=t; j<W; j++) a[i][j]=clr;
    
    clr++;
  }
  
  for(i=0; i<H; i++) {
    if(a[i][0]!=0) continue;
    
    ll key=-1;
    for(k=i+1; k<H; k++) {
      if(a[k][0]) {
        key=k;
        break;
      }
    }
    
    for(k=i-1; k>=0; k--) {
      if(a[k][0]) {
        key=k;
        break;
      }
    }
    
    for(j=0; j<W; j++) {
      a[i][j]=a[key][j];
    }
    
  }
  
  
  
  for(i=0; i<H; i++) {
    for(j=0; j<W; j++) {
      cout << a[i][j] << " ";
    }
    pt("");
  }
  
  
}




Measured memory_bytes: 2944
object Main extends App {
	val x = scala.io.StdIn.readLine.toList
	
	def head(x: List[Char]): List[Char] = {
		x match {
			case x::rest => rest
			case _ => List()
		}
	}

	def match2(x: List[Char]): Boolean = {
		var temp = x;
		var y :List[Char] = List()
		val size = x.size

		for(i<- 0 until size){
			if(! y.contains(x(i))){
				y = x(i) :: y
				temp = head(temp) 
			}else{
				return true
			}
		}
		return false
	}

	if(match2(x)){
		println("no")
	}else{
		println("yes")
	}

}

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

# define F first
# define S second
# define mp make_pair
# define pii pair<int,int>

# define long long long
# define pb push_back
# define sz(a) (int)(a.size())

# define y1     tipa_y1
# define left   tipa_left
# define right  tipa_right

const int Mod = (int)1e9 + 7;
const int MX = 1073741822;
const long MXLL = 4611686018427387903;
const int Sz = 1110111;

using namespace std;

inline void Read_rap () {
  ios_base :: sync_with_stdio(0);
  cin.tie(0);
}
int n, m;

long x[Sz], y[Sz];

inline long calc () {
  long res = 0;
  for (int i = 1;i <= n;i ++) {
    for (int j = i + 1;j <= n;j ++) {
      for (int k = 1;k <= m;k ++) {
        for (int l = k + 1;l <= m;l ++) {
          res = (res + (abs (x[i] - x[j]) * abs(y[k] - y[l]))) % Mod;
        }
      }
    }
  }
  return res;
}

int main()
{
  Read_rap ();

  cin >> n >> m;
  for (int i = 1;i <= n;i ++) cin >> x[i];
  for (int i = 1;i <= m;i ++) cin >> y[i];
  sort (x + 1, x + n + 1);
  sort (y + 1, y + m + 1);
  
  long sum1 = 0, sum2 = 0;
  for (int i = 1;i <= n;i ++) {
    sum1 = (sum1 + (i - 1) * x[i]) % Mod;
    sum1 = (sum1 - ((n - i) * x[i]) % Mod + Mod) % Mod;
  }
  for (int i = 1;i <= m;i ++) {
    sum2 = (sum2 + (i - 1) * y[i]) % Mod;
    sum2 = (sum2 - ((m - i) * y[i]) % Mod + Mod) % Mod;
  }              
  long ans = (sum1 * sum2) % Mod;

  cout << ans;

  return 0;
}









// Coded by Z...


Measured memory_bytes: 3072
import sys
import socket

hostnames = ['N551J', 'F551C', 'X553M']
input_file = 'd1.in'
# if socket.gethostname() in hostnames:
#     sys.stdin = open(input_file)


def read_int_list():
    return list(map(int, input().split()))


def read_int():
    return int(input())


def read_str_list():
    return input().split()


def read_str():
    return input()


M = 10 ** 9 + 7
def solve():
    n, k = read_int_list()
    res = 0
    for i in range(k, n + 2):
        start = i * (i - 1) // 2
        stop = i * (n + n - i + 1) // 2
        res += stop - start + 1
        res %= M
    return res


def main():
    res = solve()
    print(res)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9872
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<climits>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<numeric>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i = m; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a)  (a).rbegin(),(a).rend()
#define PI 3.14159265359
#define MOD 1000000007
typedef long long LL;

template<class T> inline void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> inline void chmin(T& a, T b) { if (a > b) { a = b; } }
template<class T> void print_vector(vector<T> vec) {
	cout << "[ ";
	for (int i = 0; i < vec.size(); i++) {
		cout << vec[i] << " ";
	}
	cout << "]" << endl;
}
template<class T> void print_pair_vector(vector<pair<T, T> > vec) {
	cout << "[ ";
	for (int i = 0; i < vec.size(); i++) {
		cout << "(" << vec[i].first << "," << vec[i].second << ") ";
	}
	cout << "]" << endl;
}

const int INF = 1 << 30;

int main(void) {
	LL A, B, C;
	cin >> A >> B >> C;

	int ans = -1;
	if (B >= C or A+B >= C) {
		ans = B + C;
	}
	else {
		ans = B + B + A;
		if (C-B-A >= 1) {
			ans++;
		}
	}

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



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double lb;
#define REP(i,j,n) for (int i=j;i<(n);i++)
#define RREP(i,n) for (int i = n; 0<i;i--)
#define print(out) cout<< out  << "\n";
#define mod 1000000007
const int INF = 1e8;

int main(){
  
  int N,cnt=0;string S;cin>>N>>S;
  char s='1';
  REP(i,0,N){
    if(S.at(i)!=s){
      cnt++;
      s=S.at(i);
    }
  }
  print(cnt)
}


Measured memory_bytes: 512
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define p(s) cout<<(s)<<endl
#define REP(i,n,N) for(int i=n;i<N;i++)
#define RREP(i,n,N) for(int i=N-1;i>=n;i--)
#define CK(n,a,b) ((a)<=(n)&&(n)<(b))
#define F first
#define S second
typedef long long ll;
using namespace std;
const int inf = 1e9+7;

int N,M;
int a[1010],b[1010],c[1010];
int d[110][110];
int main(){
    cin>>N>>M;
    REP(i,0,N){
        REP(j,0,N){
            if(i==j) d[i][j]=0;
            else d[i][j]=inf;
        }
    }
    REP(i,0,M){
        cin>>a[i]>>b[i]>>c[i];
        a[i]--;b[i]--;c[i];
        d[a[i]][b[i]]=c[i];
        d[b[i]][a[i]]=c[i];
    }
    REP(k,0,N){
        REP(i,0,N){
            REP(j,0,N){
                d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
            }
        }
    }
    int ans=M;
    REP(i,0,M){
        bool ok=false;
        REP(j,0,N){
            if(d[j][a[i]]+c[i]==d[j][b[i]]) ok=true;
        }
        ans-=ok;
    }
    p(ans);
    return 0;
}

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

int main(void)
{
	int W, H, x, y;
	cin >> W >> H >> x >> y;
	long long area = 1LL * W * H;
	int a = 0;
	if (x + x == W && y + y == H) a = 1;
	cout << area / 2;
	if (area % 2) cout << ".5";
	cout << " " << a << endl;
	return 0;
}


Measured memory_bytes: 256