akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> pll;	

#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define loop(i,a,b) for(ll i=a;i<b;i++)
#define test() ll t;cin>>t;for(ll test = 1;test<=t;test++)
#define f first
#define s second
#define pb push_back
#define nl cout<<"\n"
#define MOD(x) ((x%P)+P)%P
#define vec(v) loop(i,0,v.size()) cout<<v[i]<<" "; nl
const int N = 100005;
const ll P = 1000000007;
const double eps = 1e-6;

int main()
{
	fastio();

	string num;
	int d;
	cin>>num>>d;

	ll dp[d+1][2] = {};
	//dp[i][0] = mod i and loose;
	//dp[i][1] = mod i and tight;	

	dp[0][1] = 1;

	for(int i=0; i<num.size(); i++)
	{
		ll newdp[d+1][2] = {};
		int mx = num[i]-'0';
		for(int rem = 0; rem<d; rem++)
		{
			for(int add = 0; add<10; add++)
			{
				int next = (rem+add)%d;
				newdp[next][0] = MOD(newdp[next][0]+dp[rem][0]);
				if(add<mx)
					newdp[next][0] = MOD(newdp[next][0]+dp[rem][1]);
				else if(add==mx)
					newdp[next][1] = MOD(newdp[next][1]+dp[rem][1]);
			}
		}
		for(int i=0; i<d; i++)
		{
			dp[i][0] = newdp[i][0];
			dp[i][1] = newdp[i][1];
		}
	}
	cout<<MOD(dp[0][0]+dp[0][1]-1);
	//cerr << "\nTime elapsed : " << 1000 * clock() / CLOCKS_PER_SEC << " ms\n";
	return 0;
}

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

using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;

#define REP(i, n, m) for(ll i=n; i<(ll)m; ++i)
#define IREP(i, n, m) for(ll i=n-1; i>=m; --i)
#define rep(i, n) REP(i, 0, n)
#define irep(i, n) IREP(i, n, 0)
#define all(v) v.begin(), v.end()
#define vprint(v) for(auto e:v){cout<<e<<" ";};cout<<endl;
#define vvprint(vv) for(auto v:vv){vprint(v)};

ll pow_mod(ll n, ll m, ll mod=1000000007){
    ll a = 1;
    while(m>0){
        if(m&1) a = a*n % mod;
        n = n*n % mod;
        m >>= 1;
    }
    return a;
}

vvll matmul(vvll &A, vvll &B, ll mod){
    ll n = A.size();
    vvll C(n, vll(n, 0));
    rep(i, n) rep(j, n) rep(k, n){
        C[i][j] = (C[i][j] + (A[i][k]%mod) * (B[k][j]%mod) % mod) % mod;
    }
    return C;
}

vvll mat_pow_mod(vvll &A, ll m, ll mod=1000000007){
    ll n = A.size();
    vvll X(n, vll(n, 0));
    rep(i, n) rep(j, n) X[i][j] = A[i][j];
    vvll B(n, vll(n, 0));
    rep(i, n) B[i][i] = 1;
    while(m>0){
        if(m&1) B = matmul(B, X, mod);
        X = matmul(X, X, mod);
        m >>= 1;
    }
    return B;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(20);

    ll L, A, B, M;
    cin >> L >> A >> B >> M;

    ll m = A + B*(L-1);
    ll d = 0;
    ll t = m;
    while(t>0){
        ++d;
        t /= 10;
    }

    vll c(d+1, 0);
    REP(i, 1, d+1){
        ll p = 1;
        rep(j, i-1) p *= 10;
        ll m1 = min(p*10 - 1, m) - A;
        ll m2 = min(p - 1, m) - A;
        ll c1 = max(0ll, m1/B + (m1>=0? 1 : 0));
        ll c2 = max(0ll, m2/B + (m2>=0? 1 : 0));
        c[i] = c1 - c2;
    }
    vvll T(3, vll(3, 0));
    T[0][0] = T[1][1] = T[2][2] = 1;
    REP(i, 1, d+1){
        vvll R = {{pow_mod(10, i, M), 0, 0}, {1, 1, 0}, {0, B, 1}};
        vvll Q = mat_pow_mod(R, c[i], M);
        T = matmul(T, Q, M);
    }
    ll ans = ((A%M) * T[1][0] + T[2][0]) % M;
    cout << ans << endl;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#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 show(x) for(auto i: x){cout << i << " ";}
#define showm(m) for(auto i: m){cout << m.x << " ";}
typedef long long ll;
typedef pair<int, int> P;
ll gcd(int x, int y){ return y?gcd(y, x%y):x;}
ll lcm(ll x, ll y){ return (x*y)/gcd(x,y);}

long mod = 1000000007;
/* C++の構造体 メンバがpublicなclass */
typedef struct mint
{
    ll x;
    mint(ll x = 0) : x(x % mod) {} //コンストラクタ
    /* 演算子オーバーロード */
    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;
    }
} mint_t;

ll intpow(mint_t m, int n)
{
    if (n == 0) return 1;
    mint_t ans(1);
    while (n >= 1)
    {
        if ((n % 2) == 0){
            m *= m.x;
            n /= 2;
        }else {
            ans *= m.x;
            n -= 1;
        }
    }
    return ans.x;
}

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;
    cin >> n;
    vector<ll> a;
    rep(i, n){ ll tmp; cin >> tmp; a.push_back(tmp);}

    int bit_num[60] = {0};

    rep(i, n){
        rep(j, 60){
            if(a[i]>>j & 1) bit_num[j]++;
        }
    }

//    show(bit_num);

    mint ans = 0;
    mint mut = 1;
    rep(i, 60){
        mint plus = (mint)bit_num[i] * (mint)(n - bit_num[i]);
        plus *= mut;
        ans += plus;
        mut *= 2;
    }

    cout << ans.x << endl;

}



Measured memory_bytes: 6256
import java.util.Scanner;

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

        String a = sc.next().trim();
        String b = sc.next().trim();

        char[] left  = a.toCharArray();
        char[] right = b.toCharArray();

        boolean eq = false;

        for (int i = 0; i < left.length; i++) {
            if (equals(left, right)) {
                eq = true;
                break;
            } else {
                rotate(right);
            }
        }

        System.out.println((eq ? "Yes" : "No"));
    }

    private static void rotate(char[] ch) {
        char tmp = ch[0];

        for (int i = 0; i < ch.length - 1; i++) {
            ch[i] = ch[i + 1];
        }

        ch[ch.length - 1] = tmp;
    }

    private static boolean equals(char[] left, char[] right) {
        boolean res = true;

        for (int i = 0; i < left.length; i++) {
            if (left[i] != right[i]) {
                res = false;
                break;
            }
        }

        return res;
    }
}

Measured memory_bytes: 21972
<?php

ini_set('error_reporting', E_ALL & ~E_NOTICE);

fscanf(STDIN, "%d %d", $N, $T);
$A = explode(" ", trim(fgets(STDIN)));

$TTS = array();
$memo = array();
$maxProfit = 0;

$TTS[$N] = 0;

for ($i = $N-1; $i >= 0; $i--) {
    $TTS[$i] = max($TTS[$i+1], $A[$i]);
}

for ($i = 0; $i < $N; $i++) {
    $profit = $TTS[$i] - $A[$i];
    $memo[$profit][] = "1";
    $maxProfit = max($maxProfit, $profit);
}

echo count($memo[$maxProfit]) . PHP_EOL;


Measured memory_bytes: 74608
// デバッグ実行：Ctrl+F5

using System;
using System.Collections.Generic;
class Program
{
    static void Main(string[] args)
    {
        String line;
        line = Console.ReadLine();
        int N = int.Parse(line);
        List<int> Apples = new List<int>();
        for(int i = 0; i < N; i++)
        {
            line = Console.ReadLine();
            Apples.Add(int.Parse(line));
        }

        for(int i = 0; i < Apples.Count; i++)
        {
            if (Apples[i] % 2 == 1)
            {
                Console.WriteLine("first");
                return;
            }
        }


        Console.WriteLine("second");
    }
}

Measured memory_bytes: 16092
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <queue>
#include <vector>
#include <cstdlib>
#include <cmath>

typedef long long ll;

#define reps(i, s, e) for (ll i = s; i < e; ++i)
#define rep(i, n) reps(i, 0, n)
#define rreps(i, s, e) for (ll i = e-1; i >= s; --i)
#define rrep(i, n) rreps(i, 0, n)

// const ll LL_INF = 1LL<<60;

template <class T> inline void chmin(T& a, T b) {if (a > b) {a = b;}}
template <class T> inline void chmax(T& a, T b) {if (a < b) {a = b;}}

using namespace std;

struct Card {
    char c;
    ll x;
    Card(char _c=' ', ll _x=-1): c(_c), x(_x) {}
    void entry(char _c, ll _x) {
        c = _c;
        x = _x;
    }
};
inline bool operator< (const Card& c1, const Card& c2) {
    return c1.x < c2.x;
}
inline bool operator== (const Card& c1, const Card& c2) {
    return c1.x == c2.x;
}
inline ostream& operator<<(ostream& out, const Card& c)
{
    out << c.c << c.x;
    return out;
}

template<class T> inline void sw(T& a, T& b) {
    T tmp = a;
    a = b;
    b = tmp;
}

template<class T> inline void bubble_sort(vector<T>& a) {
    ll n = a.size();
    rep(i, n-1) {
        rreps(j, i+1, n) {
            if (a[j] < a[j-1]) {
                sw<T>(a[j], a[j-1]);
            }
        }
    }
}
template<class T> inline bool selection_sort(vector<T>& a) {
    ll n = a.size();
    bool stable = true;

    rep(i, n-1) {
        ll argmin = i;
        T tmp = a[i];
        bool flag = false;

        reps(j, i+1, n) {
            if (a[j] == tmp) flag=true;
            if (a[j] < a[argmin]) {
                argmin = j;
                if (flag) stable = false;
            }
        }
        if (argmin != i) {
            sw<T>(a[i], a[argmin]);
        }
    }
    return stable;
}
template<class T> inline void output(vector<T>& a) {
    ll n = a.size();
    rep(i, n) {
        cout << a[i];
        if (i != n-1) cout << " ";
        else cout << "\n";
    }
}


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

    vector<Card> a(n);
    rep(i, n) {
        char ch;
        ll x;
        cin >> ch >> x;
        a[i].entry(ch, x);
    }
    vector<Card> a2 = a;
    bubble_sort(a);
    output(a);
    cout << "Stable\n";

    bool stable = selection_sort(a2);
    output(a2);
    if (stable) cout << "Stable\n";
    else cout << "Not stable\n";
}


Measured memory_bytes: 3104
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstring>

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) unique(v.begin(), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
#define all(v) (v).begin(), (v).end()
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

ll N, X;
ll a[51], p[51];
ll F(ll N, ll X) {
    if(N == 0) {
        if(X <= 0) return 0;
        return 1;
    }
    if(X == 1) return 0;
    if(X <= 1 + a[N - 1]) return F(N - 1, X - 1);
    if(X <= 2 * a[N - 1] + 2) return p[N - 1] + 1 + F(N - 1, X - 2 - a[N - 1]);
    return 2 * p[N - 1] + 1;


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

    cin >> N >> X;
    a[0] = 1;
    p[0] = 1;
    rep(i, 1, N + 1) {
        a[i] = 2 * a[i - 1] + 3;
        p[i] = 2 * p[i - 1] + 1;
    }

    cout << F(N, X) << endl;

}


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

using namespace std;

int maxlen = 0, mode = 0;
map<string,int> mp;

int main()
{   
    string len_key, mode_key, s2;
    int m = 9;
    while( cin >> s2 )
    {
        mp[s2]++;
        if( mode < mp[s2] )
        {
            mode = mp[s2];
            mode_key = s2;
        }
        if( maxlen < s2.size() )
        {
            maxlen = s2.size();
            len_key = s2; 
        } 
    }

    cout << mode_key << ' ' << len_key << '\n';
    return 0;
}



Measured memory_bytes: 3204
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <queue>
#include <tuple>
#include <cstring>

#define INF 100000000

using namespace std;

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

    vector<int> p(m), q(m - 1);
    for (int i = 0; i < m; i++)
    {
        cin >> p[i];
    }
    if (n >= m)
    {
        cout << "0\n";
        return 0;
    }
    sort(p.begin(), p.end());
    /*for(int i = 0;i<m;i++)
    {
        cout <<  p[i] << " ";
    }
    cout << endl;
    */
    for (int i = 0; i < m - 1; i++)
    {
        q[i] = p[i + 1] - p[i];
        //cout << q[i] <<endl;
    }
    //p[n-1] = 0; //vectorのあまりを０に
    sort(q.begin(), q.end());
    for (int i = 0; i < n - 1; i++)
    {
        q[(m - 1) - 1 - i] = 0;
    }
    cout << accumulate(q.begin(), q.end(), 0) << endl;

    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <ctime>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <climits>
#include <queue>
#include <set>
#include <cmath>
#include <map>
#include <bitset>
#include <fstream>
#include <tr1/unordered_map>
#include <assert.h>

#define x first
#define y second
#define y0 Y0
#define y1 Y1
#define mp make_pair
#define pb push_back
#define DEBUG(x) cout << #x << " = " << x << endl;

using namespace std;

typedef long long LL;
typedef pair <int, int> pii;

template <typename T> inline int Chkmax (T &a, T b) { return a < b ? a = b, 1 : 0; }
template <typename T> inline int Chkmin (T &a, T b) { return a > b ? a = b, 1 : 0; }
template <typename T> inline T read ()
{
	T sum = 0, fl = 1; char ch = getchar();
	for (; !isdigit(ch); ch = getchar()) if (ch == '-') fl = -1;
	for (; isdigit(ch); ch = getchar()) sum = (sum << 3) + (sum << 1) + ch - '0';
	return sum * fl;
}

inline void proc_status ()
{
	ifstream t ("/proc/self/status");
	cerr << string (istreambuf_iterator <char> (t), istreambuf_iterator <char> ()) << endl;
}

const int MAXN = 3e5;
const int MOD = 1e9 + 7;

int N;
char S[MAXN + 5];
int F[MAXN + 5][3][3];

inline void ADD (int &a, int b) { if ((a += b) >= MOD) a -= MOD; }

inline void Solve ()
{
	F[0][0][0] = 1;
	for (int i = 0; i < N; ++i) for (int j = 0; j <= 1; ++j) 
		for (int k = 0; k <= 2; ++k) if (F[i][j][k])
		{
			if (S[i + 1] != '1')
			{
				if (k) ADD (F[i + 1][j][(k + 1) == 3 ? 1 : (k + 1)], F[i][j][k]);
				else ADD (F[i + 1][j][1], F[i][j][k]);
			}

			if (S[i + 1] != '0')
			{
				if (k) ADD (F[i + 1][j][k - 1], F[i][j][k]);
				else ADD (F[i + 1][j + 1][0], F[i][j][k]);
			}
		}

	int ans = F[N][1][0], sum = 1;

	for (int i = N; i >= 1; --i)
	{
		ADD (ans, (LL) sum * F[i][2][0] % MOD);
		if (S[i] == '?') sum = 2ll * sum % MOD;
	}

	cout << ans << endl;
}

inline void Input ()
{
	scanf("%s", S + 1);
	N = strlen (S + 1);
}

int main ()
{

#ifdef hk_cnyali
	freopen("E.in", "r", stdin);
	freopen("E.out", "w", stdout);
#endif

	Input ();
	Solve ();

	return 0;
}



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

int main() {
    int N;
    cin >> N;
    double sum = 0;
    for (int i = 0; i < N; ++i){
    	double a;
    	cin >> a;
    	sum += (1/a);
    }
    cout << setprecision(15) << (1/sum) << endl;

    return 0;
}

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

using namespace std;

int main() {
  int N, L;
  cin >> N >> L;
  vector<string> VS(N);
  for (int i = 0; i < N; i++) cin >> VS[i];
  sort(VS.begin(), VS.end());

  string answer = "";
  for (const string& s : VS) answer += s;
  cout << answer << "\n";

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
  int n;cin>>n;
  vector<int> a(n);
  for(int i = 0; n > i; i++){
    cin>>a[i];
  }
  sort(a.begin(),a.end(),greater<int>());
  int A = 0;
  int B = 0;
  for(int i = 0; n > i; i++){
    if(i%2){
      B += a[i];
    }else{
      A += a[i];
    }
  }
  cout << A-B << endl;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

def main():
    N = int(input())
    s = input().strip()
    t = input().strip()

    oh = True
    for i in range(N):
        ok = True
        for j in range(N-i):
            if s[i+j] != t[j]:
                ok = False
                break
        if ok:
            print(N+i)
            oh = False
            break
    if oh:
        print(2*N)

if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

#include <fstream>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <unordered_map>
#include <bitset>
#include <numeric>
#include <unordered_set>
#include <bitset>
#include <limits>
#include <random>
#include <complex>
#include <numeric>
#include <cstdlib>
#include <random>
#include <bits/stdc++.h>


using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
//typedef vector<ll> vec;
//typedef vector<vec> mat;

const ll mod=1000000007ll;
const ll inf=1000000000000000ll;

const ll MAX_N=100010;

ll a,b,c,Q;

ll minc(ll x){
  ll left=0,right=1000000000;
  while(right-left>1){
    ll mid=(left+right)/2;
    if(x<=mid*mid)right=mid;
    else left=mid;
  }
  return left;
}

int main(){

  cin>>Q;
  for(ll i=0;i<Q;i++){
    cin>>a>>b;
    c=minc(a*b);
//    cout<<"c is"<<c<<endl;
    if(a==b)cout<<(2*a-2)<<endl;
    else if(c*(c+1)>=a*b)cout<<(2*c-2)<<endl;
    else cout<<(2*c-1)<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

func main() {
	solve(os.Stdin, os.Stdout)
}

func solve(in io.Reader, out io.Writer) {
	var bs = NewBufScanner(in)
	var bw = NewBufWriter(out)
	defer bw.w.Flush()

	n := bs.IntScan()
	a1 := []int{}
	for len(a1) < n {
		a1 = append(a1, bs.IntScan())
	}
	a2 := []int{}
	for len(a2) < n {
		a2 = append(a2, bs.IntScan())
	}

	a1memo := memo(a1)
	a2memo := memo(a2)

	max := 0
	for i := 0; i < n; i++ {
		sum := a1memo[i]
		sum += a2memo[n-1]
		if i - 1 >= 0 {
			sum -= a2memo[i-1]
		}
		if max < sum {
			max = sum
		}
	}
	bw.Printf("%d\n", max)
}

func memo(a []int) []int {
	r := make([]int, len(a))
	r[0] = a[0]
	for i := 1; i < len(a); i++ {
		r[i] = a[i] + r[i-1]
	}
	return r
}

// BufScanner original scanner
type BufScanner struct {
	s *bufio.Scanner
}

// NewBufScanner constructer
func NewBufScanner(in io.Reader) *BufScanner {
	s := bufio.NewScanner(in)
	s.Buffer(make([]byte, 1024), 1e+9)
	s.Split(bufio.ScanWords)
	return &BufScanner{
		s: s,
	}
}

// Scan Scan Data
func (b *BufScanner) Scan() string {
	b.s.Scan()
	return b.s.Text()
}

// IntScan Scan Data
func (b *BufScanner) IntScan() int {
	v, err := strconv.Atoi(b.Scan())
	if err != nil {
		panic(err)
	}
	return v
}

// BufWriter original writer
type BufWriter struct {
	w *bufio.Writer
}

// NewBufWriter constructer
func NewBufWriter(out io.Writer) *BufWriter {
	w := bufio.NewWriter(out)
	return &BufWriter{
		w: w,
	}
}

// Printf Output file
func (b *BufWriter) Printf(format string, a ...interface{}) {
	fmt.Fprintf(b.w, format, a...)
}

Measured memory_bytes: 640
n, a, b, c, d = map(int, input().split())

s = input()
s = '#' +s

def check(s, a, b):
    return not "##" in s[a:b]


def solve(s,a,b,c,d):
    can_swap = "..." in s[b - 1:d + 2]
    can_reach_each = check(s, a, c) and check(s, b, d)
    if not can_reach_each:
        return False
    if (a < b and c < d) or (b < a and d < c):
        return True
    else:
        if can_swap:
            return True
        else:
            return False

if solve(s, a, b, c, d):
    print("Yes")
else:
    print("No")



Measured memory_bytes: 3636
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
#include<utility>
#include<queue>
#include<tuple>
#include<stdio.h>
#define rep(i, n) for(int i=0;i<n;i++)
using namespace std;

int main(){
	int a, b, c, d;
	cin>>a>>b>>c>>d;
	int f=0;
	while(f==0){
		c-=b;
		if(c<=0){
			f=1;
			break;
		}
		a-=d;
		if(a<=0){
			f=2;
			break;
		}
	}
	if(f==1){
		cout<<"Yes"<<endl;
	}
	else{
		cout<<"No"<<endl;
	}
	return 0;
}

Measured memory_bytes: 3624
#include<stdio.h>
int main()
{
  int A, B;
  int sum = 0;
  int i;
  
  scanf("%d %d", &A, &B);
  
  for(i = 0; i < 2; i++){
    if(A >= B){
     sum += A;
     A--;
   }else{
     sum += B;
     B--;
   }
  }
  
  printf("%d", sum);
  
  return 0;
}

  

Measured memory_bytes: 128
#include <iostream>

using namespace std ;

int main(void){
    int p[20],n,c=0;
    
    cin >> n;
    for(int i=0; i<n; i++){
        cin >> p[i];
    }

    for(int i=1; i<n-1; i++){
        if(p[i-1] > p[i] && p[i+1] < p[i]) c++;
        else if(p[i+1] > p[i] && p[i-1] < p[i]) c++;
    }
    cout << c << endl;
    return 0;
}


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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())

template<typename T>
T mod(T a, T b){
    return (a + b) % b;
}

template<typename T>
T gcd(T a, T b){
    if (b == 0) return a;
    return gcd(b, a % b);
}

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

// n を素因数分解
map<ll, ll> factor(ll n){
    map<ll, ll> mp;
    for (ll i = 2; i*i <= n; i++) {
        while (n % i == 0) {
            mp[i]++;
            n /= i;
        }
    }

    if (n > 1) {
        mp[n]++;
    }

    return mp;
}

// 文字列に "hoge" が含まれているか
// string str = "hogepiyo";
// if (str.find("hoge") != string::npos) {
//     cout << "文字列が含まれています" << endl;
// }

// char to string
// char c = 'a';
// string str = {c};

ll countAB(string str) {
    ll cnt = 0;
    while (str.find("AB") != string::npos) {
        cnt++;
        str = str.substr(str.find("AB")+1, str.size());
    }

    return cnt;
}


ll x = 0, y = 0, z = 0;
void checktype(string str) {
    if (str[0] == 'B' && str[str.length()-1] == 'A') {
        z++;
    } else if (str[str.length()-1] == 'A') {
        x++;
    }else if (str[0] == 'B') {
        y++;
    }
}

void solve(){
    ll N;
    cin >> N;

    vector<string> strs(N);
    ll cnt = 0;
    for (int i = 0; i < N; i++) {
        cin >> strs[i];
        cnt += countAB(strs[i]);
        checktype(strs[i]);
    }

    if (x == 0 && y == 0) {
        if (z >= 2) {
            cout << cnt + z - 1 << endl;
        } else {
            cout << cnt << endl;
        }
    } else {
        cout << cnt + min(x,y) + z << endl;
    }

    return;
}

int main(int argc, char const* argv[])
{
    solve();
    return 0;
}


Measured memory_bytes: 768
#include<cmath>
#include<iostream>
#include<cstdio>
#include<iomanip>
using namespace std;
int main() {
	int h, w;
	while (1) {
		cin >> h >> w;
		if (h == 0 && w == 0)break;
		for (int i = 0; i < w; i++)cout << "#"; cout << endl;
		for (int j = 0; j < h - 2; j++) {
			cout << "#";
			for (int k = 0; k < w - 2; k++)cout << ".";
			cout << "#" << endl;
		}
		for (int i = 0; i < w; i++)cout << "#"; cout << endl << endl;
	}
	return 0;
}

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

int main() {
    int a, b, c;
    bool poor = false;
    cin >> a >> b >> c;
    if (a == b && a != c) poor = true;
    if (a == c && a != b) poor = true;
    if (b == c && b != a) poor = true;

    cout << (poor ? "Yes" : "No") << endl;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
 double x[22]; 
double y[22];
 int main(){ 
double a,b; 
int now=1; 
while(~scanf("%lf,%lf",&a,&b)){ x[now]=a;
 y[now++]=b; } x[0]=x[now-1];
 x[now]=x[1];
 double S=0; 
for(int i=1;i<now;i++){ S+=(x[i+1]-x[i-1])*y[i];
 } 
if(S<0)S=-S; 
printf("%.8lf",S/2.0); 

} 


Measured memory_bytes: 2756
#include <stdio.h>
int main(void){
    int i,j,n,a[5000];
    long sum,max;
    
    while(1){
        scanf("%d",&n);
        if(n==0) break;
        for(i=0;i<n;i++){
            scanf("%d",&a[i]);
        }
        
        max=a[0];
        for(i=0;i<n;i++){
            sum=0;
            for(j=i;j<n;j++){
                sum+=a[j];
                if(max<sum) max=sum;
            }
        }
        printf("%ld\n",max);
        
    }
    
    return 0;
}

Measured memory_bytes: 616
import java.util.*;

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

		Scanner sc = new Scanner(System.in);
		
		int A = sc.nextInt();
		int B = sc.nextInt();

		if(A*B%2==0) System.out.println("No");
		else System.out.println("Yes");
	}
}

Measured memory_bytes: 23124
#include<iostream>
#include<algorithm>
using namespace std;
int N, W, H, S, T;
bool mas[100][100];
int rec(int& oldy, int& oldx){
  int cnt = 0;
  for(int i = 0 ; i < T ; i++ ){
    for(int j = 0 ; j < S ; j++ ){
      if(mas[oldy+i][oldx+j]) cnt++;
    }
  }
  return cnt;
}
int main(){
  while(cin >> N , N){
    fill_n(mas[0],10000,false);
    cin >> W >> H;
    while(N--){
      int x, y;
      cin >> x >> y;
      mas[y][x]++;
    }
    cin >> S >> T; //S:W T:H

    int ret = 0;
    for(int i = 0 ; i <= H - T + 1 ; i++ ){
      for(int j = 0 ; j <= W - S + 1 ; j++ ){
        ret = max( ret, rec( i, j) );
      }
    }
    cout << ret << endl;
  }
}

Measured memory_bytes: 1168
N, M = [int(n) for n in input().split()]
AB = [0 for _ in range(N)]

for i in range(N):
    AB[i] = [int(n) for n in input().split()]
AB = sorted(AB, key=lambda x: x[0])
# print(AB)
ans = 0
for i in range(len(AB)):
    while(M != 0 and AB[i][1] != 0):
        M -= 1
        AB[i][1] -= 1
        ans += AB[i][0]
print(ans)


Measured memory_bytes: 62496
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        ArrayList<String> ans = new ArrayList<>();
        while(sc.hasNext()){
            int pattern = 0;
            int n = sc.nextInt();
            for(int i = 0;i < 10;i++){
                for(int j = 0;j < 10;j++){
                    for(int k = 0;k < 10;k++){
                        for(int l = 0;l < 10;l++){
                            if(i + j + k + l == n) pattern++;
                        }
                    }
                }
            }
            ans.add("" + pattern);
        }
        for(int i = 0,size = ans.size();i < size;i++){
            System.out.println(ans.get(i));
        }
    }
}

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

#define ll   	long long
#define pb	    push_back
#define F   	first
#define S	    second
#define B   	begin()
#define E	    end()
#define FASTIO   ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);


using namespace std ;
map < int , bool > d ;
inline bool is_ok ( int x )
{
    while ( x )
    {
        if ( d[x%10] )
            return 0 ;
        x /= 10 ;
    }
    return 1 ;
}
int main()
{
    FASTIO ;
    int n , k ;
    cin >> n >> k ;
    for ( int i = 0 ; i < k ; i++ )
    {
        int x ;
        cin >> x ;
        d[x] = 1 ;
    }
    while ( !is_ok(n) )
        n++;
    cout << n ;
    return 0;
}



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

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

  int total = 0;
  int X = N;
    while (true) {
        total += X % 10;
        X /= 10;
        
        if (X < 10) {
            total += X;
            break;
        }
    }

    
  if (N % total == 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  
}


Measured memory_bytes: 256
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define INF 1000000000000000000
typedef pair<ll, ll> pll;

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

    int N;
    cin >> N;
    vector<ll> A(N), B(N);
    vector<pll> sum(N);
    vector<ll> taka, aoki;
    rep(i, N) {
        cin >> A[i] >> B[i];
        sum[i] = {A[i] + B[i], i};
    }

    sort(all(sum), [](pll a, pll b) { return a.first > b.first; });
    rep(i, N) {
        if (i % 2 == 0) {
            taka.push_back(sum[i].second);
        } else
            aoki.push_back(sum[i].second);
    }

    ll t = 0, a = 0;
    rep(i, taka.size()) { t += A[taka[i]]; }

    rep(i, aoki.size()) { a += B[aoki[i]]; }

    cout << t - a << endl;
}

Measured memory_bytes: 7440
N, Y = map(int, input().split())

num_10000 = 0
num_5000 = 0
num_1000 = 0

num_10000 = Y // 10000
Y -= num_10000 * 10000
num_5000 = Y // 5000
Y -= num_5000 * 5000
num_1000 = Y // 1000

num = num_10000 + num_5000 + num_1000
# i枚の10,000円を崩す
for i in range(0, num_10000 + 1):
    # i枚の内j枚を5,000円に崩す
    for j in range(0, i + 1):
        # k枚の5,000円を崩す
        for k in range(0, num_5000 + 1):
            res = (num_10000 - i)
            res += j * 2 + (num_5000 - k)
            res += (i - j) * 10 + k * 5 + num_1000
            if res == N:
                print(num_10000 - i, j * 2 + (num_5000 - k),
                      (i - j) * 10 + k * 5 + num_1000)
                exit(0)

print(-1, -1, -1)


Measured memory_bytes: 41196
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.IO;
using System.Text;
using System.Diagnostics;

class Program
{
    static void Main()
    {
        int[] ny = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        int x = 0, y = 0, z = 0;


        for(x = 0; x <= ny[0]; x++)
        {
            for(y = 0; x + y <= ny[0]; y++)
            {
                z = ny[0] - (x + y);
                int sum = 10000 * x + 5000 * y + 1000 * z;
                if(sum == ny[1])
                {
                    Console.WriteLine("{0} {1} {2}", x, y, z);
                    return;
                }
            }
        }
        Console.WriteLine("-1 -1 -1");
    }
}

Measured memory_bytes: 13268
#include <iostream>
#include <string>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <iomanip>
#include <queue>


using namespace std;

int main() {
    int N, ans = 0;
    cin >> N;

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

    int i = 0;
    while(i != 1){
        if (A[i] == true) {
            ans = -1;
            break;
        }
        else{
            ans++;
            A[i] = true;
            i = a[i] - 1;
        }
    }

    cout << ans;

    return 0;
}

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


int main()
{
	int a[3];
	for (int i = 0; i < 3; i++) {
		cin >> a[i];
	}
	sort(a, a+3);
	cout << a[0] + a[1] << endl;
    return 0;
}


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

int main()
{
    string s;
    cin >> s;
    int ans0 = 0, ans1 = 0;
    for (int i = 0; i < s.size(); ++i)
    {
        if (s[i] == '0') ++ans0;
        else ++ans1;
    }
    
    cout << min(ans0, ans1) * 2 << endl;
}

Measured memory_bytes: 512
function Main(input) {
    input = input.split("\n");
    var house_num = Number(input[0]);
    var houses = input[1].split(' ');
    var smallest = houses[0];
    var largest = 0;
    for(var i = 0; i < houses.length; i++){
        if(houses[i] > largest){
            largest = houses[i];
        }
        if(houses[i] < smallest){
            smallest = houses[i];
        }
    }
    var answer = largest - smallest;
    console.log(answer);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

  std::vector<int> v(4);
  for(int i=0;i<4;i++)
    cin>>v[i];
  sort(v.begin(), v.end());
  if(v[0]==1&&v[1]==4&&v[2]==7&&v[3]==9){
    cout<<"YES"<<endl;
  }else{
    cout<<"NO"<<endl;

  }

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
//for(int i = 0; i<n; i++)


int main()
{
    string a,b;cin>>a>>b;
    if(a.size() == b.size()){
        for(int i = 0; i < (int)a.size(); i++){
            if(a[i] == b[i]) continue;
            else if(a[i] > b[i]){
                cout << "GREATER" << endl;
                return 0;
            }else{
                cout << "LESS" << endl;
                return 0;
            }
        } 
        cout << "EQUAL" << endl;
        
    }else{
            cout << (a.size() > b.size()?"GREATER":"LESS")<<endl;
    }    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <numeric>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

#define IN(l, r, x) ((l) <= (x) && (x) < (r))

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

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

    vs32 a(n);
    rep (i, n) cin >> a[i];

    vs32 dp(n, 1);
    for (int i = n - 1; i >= 0; --i)
    {
        for (int j = i - 1; j >= 0; --j)
        {
            if (a[i] <= a[j] && a[j] <= a[i] + k)
            {
                dp[j] = max(dp[j], dp[i] + 1);
                break;
            }
        }
        for (int j = i - 1; j >= 0; --j)
        {
            if (a[i] - k <= a[j] && a[j] <= a[i])
            {
                dp[j] = max(dp[j], dp[i] + 1);
                break;
            }
        }
    }

    int ans = 0;
    rep (i, n) ans = max(ans, dp[i]);

    cout << ans << "\n";

    return 0;
}



Measured memory_bytes: 5516
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 10e15+9
#define MOD 1000000007
#define EPS 1e-10
#define MAX_N 100100
#define MAX_M 100100

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;
typedef pair<P, char> PC;

ll a, b;

int main(){
	cin >> a >> b;
	if (a*b <= 0){
		cout << "Zero" << endl;
	}
	else{
		if (a < 0 && b < 0){
			if ((a - b) % 2 == 0){
				cout << "Negative" << endl;
			}
			else{
				cout << "Positive" << endl;
			}
		}
		else{
			cout << "Positive" << endl;
		}
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define GET_MACRO(_1, _2, _3, NAME, ...) NAME
#define _repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define _rep(i,n) _repl(i,0,n)
#define rep(...) GET_MACRO(__VA_ARGS__, _repl, _rep)(__VA_ARGS__)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cout<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cout<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream &o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream &o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 1120000000

const string hoge = string(55,'z');

string test(const string &s, const string &t, int p){
  string ret(s);
  rep(i,p) if(ret[i]=='?') ret[i]='a';
  rep(i,t.size()){
    if(ret[i+p] == '?' || ret[i+p] == t[i]) ret[i+p] = t[i];
    else return hoge;
  }
  rep(i,t.size(), s.size()) if(ret[i]=='?') ret[i]='a';
  return ret;
}

int main(){
  string s,t;
  cin>>s>>t;

  string ans = hoge;
  rep(i,(int)s.size()-(int)t.size()+1){
    ans = min(ans, test(s,t,i));
  }

  if(ans == hoge) cout << "UNRESTORABLE" << endl;
  else cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;

const int N=100005;

int n;
char s[N];

int main(){
	scanf("%s",s); n=strlen(s);
	bool first=(n%2)^(s[0] == s[n-1]);
	printf("%s\n",(first ? "First" : "Second"));
	return 0;
}

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

from math import factorial

n, m = map(int, input().split())


def solve(m, n):
    if m > n:
        m, n = n, m
    if n - m > 1:
        return 0
    fct = factorial(m)
    if n - m == 1:
        return fct ** 2 * n
    else:  # n - m == 0
        return fct ** 2 * 2


mod = 10 ** 9 + 7
ans = solve(m, n) % mod
print(ans)


Measured memory_bytes: 4740
#include<bits/stdc++.h>
using namespace std;
int main() {
  vector<string> a={"Sunny","Cloudy","Rainy","Sunny"};
  string S;
  cin>>S;
  for(int i=0;i<3;i++) {
    if(S==a.at(i)) {
      cout<<a.at(i+1)<<endl;
      break;
    }
  }
  return 0;
}

Measured memory_bytes: 256
def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p

p = 10 ** 9 + 7
N = 10 ** 6
fact = [1, 1]
factinv = [1, 1]
inv = [0, 1]
 
for i in range(2, N + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)

s = int(input())
ans = 0
for j in range(1, s//3+1):
  n = s - 3*j + j -1
  r = j - 1
  ans += cmb(n, r, p)

print(ans % p)

Measured memory_bytes: 127552
def dist(x, y):
    return ((x[0] - y[0]) ** 2 + (x[1] - y[1]) ** 2) ** .5

N = int(input())
lst = []
for _ in range(N):
    lst.append([int(x) for x in input().split()])

d = 0
for i in range(N - 1):
    for j in range(i + 1, N):
        d += dist(lst[i], lst[j])

print(d * 2 / N)


Measured memory_bytes: 3064
# -*- coding: utf-8 -*-
"""
Created on Sun Apr 29 14:42:43 2018

@author: maezawa
"""

def print_array(g):
    ans = str(g[0])
    if len(g) > 1:
        for i in range(1,len(g)):
            ans += ' '+str(g[i]) 
    print(ans)

name=[]
time=[]
current_time = 0

n, q = list(map(int, input().split()))
for i in range(n):
    s = input().split()
    name.append(s[0])
    time.append(int(s[1]))
# =============================================================================
# print(n,q)
# print(name)
# print(time)
# =============================================================================
finished = []
fin_time = []
i=0
remain = n
while True:
    if time[i] <= q:
        current_time += time.pop(i)
        finished.append(name.pop(i))
        fin_time.append(current_time)      
        remain -= 1
        if remain == 0:
            break
        i = i%remain
    else:
        time[i] -= q
        current_time += q
        i = (i+1)%remain

for i in range(n):
    print("{} {}".format(finished[i], fin_time[i]))
        
    


Measured memory_bytes: 10912
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long int
#define rep(i, n) for(int i = 0; i < n; i++)
#define repp(i, n) for(int i = 1; i <= n; i++)
#define sort(v) sort((v).begin(), (v).end())
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define riverse(v) reverse((v).begin(), (v).end())
using vi = vector<int>;
using vs = vector<string>;
using vvi = vector<vi>;
using vll = vector<ll>;
const ll MOD = 1e9+7;
vi alphabet = {'a','b','c','d','e','f','g','h','i','j','k','l','m',
               'n','o','p','q','r','s','t','u','v','w','x','y','z'};

int main() {
    int H, W;
    cin >> H >> W;
    int white = 0;
    vector<vector<bool>> HW(H + 2, vector<bool>(W + 2, false));
    rep(i, H) {
        rep(j, W) {
            char x;
            cin >> x;
            if (x == '.') {
                HW[i + 1][j + 1] = true;
                white++;
            }
        }
    }
    vvi g(H+2, vi(W+2, -1));
    g[1][1] = 0;
    queue<pair<int, int>> visited;
    visited.push(mp(1, 1));
    while (!visited.empty()) {
        pair<int, int> p = visited.front();
        visited.pop();
        int x = p.first;
        int y = p.second;
        if (HW[x + 1][y] && g[x + 1][y] == -1) {
            g[x + 1][y] = g[x][y] + 1;
            visited.push(mp(x + 1, y));
        }
        if (HW[x - 1][y] && g[x - 1][y] == -1) {
            g[x - 1][y] = g[x][y] + 1;
            visited.push(mp(x - 1, y));
        }
        if (HW[x][y + 1] && g[x][y + 1] == -1) {
            g[x][y + 1] = g[x][y] + 1;
            visited.push(mp(x, y + 1));
        }
        if (HW[x][y - 1] && g[x][y - 1] == -1) {
            g[x][y - 1] = g[x][y] + 1;
            visited.push(mp(x, y - 1));
        }
    }
    if (g[H][W] != -1)cout << white - g[H][W] - 1 << endl;
    else cout << -1 << endl;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
#define EPS 1e-10
using namespace std;
typedef long long llong;
int mcxitoi(string s) {
	int sum = 0;
	int st = 1;
	for (int i = 0; i < s.size(); i++) {
		if (isdigit(s[i])) {
			st = s[i] - '0';
		}
		else if (isalpha(s[i])) {
			switch (s[i]) {
			case 'm':sum += 1000 * st; break;
			case 'c':sum += 100 * st; break;
			case 'x':sum += 10 * st; break;
			case 'i':sum += 1 * st; break;
			}
			st = 1;
		}
	}
	return sum;
}

string itomcxi(int z) {
	string res;
	for (int i = 3; i >= 0; i--) {
		if (z / (int)pow(10, i)) {
			if (z / (int)pow(10, i) != 1)res += to_string(z / (int)pow(10, i));
			switch (i) {
			case 3:res += 'm'; break;
			case 2:res += 'c'; break;
			case 1:res += 'x'; break;
			case 0:res += 'i'; break;
			}
		}
		z %= (int)pow(10, i);
	}
	return res;
}
int main() {
	int n;
	cin >> n;
	while (n--) {
		string s1, s2;
		cin >> s1 >> s2;
		cout << itomcxi(mcxitoi(s1) + mcxitoi(s2)) << endl;
	}
	return 0;
}

Measured memory_bytes: 3416
import sys

def match(a, b):
    for i in range(len(a)):
        if a[i] != '?' and b[i] != '?' and a[i] != b[i]:
            return False
    return True


Y=str(input())
T=str(input())
S = ''
if len(Y) < len(T):
    print('UNRESTORABLE')
    sys.exit()

if match(T,Y[-len(T):]):
    S = Y[:-len(T)] + T
    A = S.replace('?','a')
    print(A)
    sys.exit()
else:
    for i in range(len(Y) - len(T)):
        i += 1
        k = -(len(T)+i)
        if match(T, Y[k:-i]):
            S = Y[:k] + T + Y[-i:]
            A = S.replace('?','a')
            print(A)
            sys.exit()

print('UNRESTORABLE')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
//~ #include <ext/pb_ds/assoc_container.hpp>
//~ #include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//~ using namespace __gnu_pbds; 
#define mp make_pair
#define endl '\n'
typedef long long ll;
 
const int INF=1e9+5;
const ll lim=(ll)3e16;
const int N=2e5+5;
const int mod=1e9+7;	
const ll oo=1e18+5;

//~ typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

int main(){
	ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(0);
	int n;
	ll m;
	cin>>n>>m;
	vector<ll> a(n);
	for(ll& x:a) cin>>x;
	sort(a.begin(),a.end());
	ll low=-oo,high=oo;
	while(low+1!=high){
		ll mid=(low+high)>>1;
		ll cnt=0;
		for(int i=0;i<n;++i){
			if(a[i]<0){ // increase from right to left
				int left=i,right=n,midd=0;
				while(left+1<right){
					midd=(left+right)>>1;
					if(a[i]*a[midd]<=mid) right=midd;
					else left=midd;
				}
				cnt+=n-right;
			}
			else{ // increase form left to right 
				int left=i,right=n,midd=0;
				while(left+1<right){
					midd=(left+right)>>1;
					if(a[i]*a[midd]<=mid) left=midd;
					else right=midd;
				}
				cnt+=left-i;
			}
		}
		if(cnt<m) low=mid;
		else high=mid;
	}
	cout<<high<<endl;
	return 0;	
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a, b;
    cin >>a>>b;
    int ans = 0;
    if(a>b){
        ans += a;
        a--;
    }else{
        ans += b;
        b--;
    }
    if(a>b){
        ans += a;
        a--;
    }else{
        ans += b;
        b--;
    }
    cout << ans << endl;
}

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

int main(){
	#ifndef ONLINE_JUDGE
		freopen ("input.txt", "r", stdin);
		freopen ("output.txt", "w", stdout);
	#endif

    string s;
    cin>>s;
    if(s[0]=='R' && s[1]=='R' && s[2]=='R') cout<<"3";
    else if(s[0]=='R' && s[1]=='R' && s[2]!='R') cout<<"2";
    else if(s[0]=='R' && s[1]!='R' && s[2]=='R') cout<<"1";
    else if(s[0]!='R' && s[1]=='R' && s[2]=='R') cout<<"2";
    else if(s[0]=='R' && s[1]!='R' && s[2]!='R') cout<<"1";
    else if(s[0]!='R' && s[1]!='R' && s[2]=='R') cout<<"1";
    else if(s[0]!='R' && s[1]=='R' && s[2]!='R') cout<<"1";
    else cout<<'0';
    cout<<endl;
	return 0;
}

Measured memory_bytes: 3624
#include<stdio.h>
#include<stdlib.h>
#include<math.h>

int main(){

int num = 0;
int *data;
int i;
int k;
int count = 0;
int finalans = 0;

while(1){
  scanf("%d",&num);
  if(1 <= num && num <=10000){
    break;
  }
}

data = (int *)malloc(sizeof(int)*num);

for(i = 0;i < num;i++){
  scanf("%d",&data[i]);
if(data[i] > 2 && data[i] % 2 == 0){
  continue;
}
  for(k = 1;k <= sqrt(data[i]);k++){
   if(data[i] % k == 0){
    count++;
   }
}
if(count == 1){
  finalans++;
}
count = 0;
}

printf("%d",finalans);
printf("\n");
return 0;
}



Measured memory_bytes: 2124
import sys
from pprint import pprint

def solve(n, x, l):
    r = []
    for i in range(n):
        r.append((x[i] + l[i], x[i] - l[i]))

    pre_e = -1 * 10**9
    ans = 0
    for e, s in sorted(r):
        # print(e,s)
        # print("pre", pre)
        if  pre_e <= s:
            # print("remain")
            pre_e = e
            ans += 1
    print(ans)


if __name__ == '__main__':
    n = int(sys.stdin.readline().strip())
    x = [0] * n
    l = [0] * n
    for i in range(n):
        x[i], l[i] = map(int, sys.stdin.readline().strip().split(" "))
    solve(n, x, l)

Measured memory_bytes: 53340
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<pint> vpint;
#define mp make_pair
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)

void slove(int n){
	vector<int> v(86400);
	rep(i, 86400) v[i] = 0;//?????????
	rep(i, n){
		string s, e;
		cin >> s >> e;
		//?§???°?????????
		int start = 36000 * (s[0] - '0') + 3600 * (s[1] - '0') 
					+ 600 * (s[3] - '0') + 60 * (s[4] - '0')
					+ 10 * (s[6] - '0') + 1 * (s[7] - '0');
		int end = 36000 * (e[0] - '0') + 3600 * (e[1] - '0') 
					+ 600 * (e[3] - '0') + 60 * (e[4] - '0')
					+ 10 * (e[6] - '0') + 1 * (e[7] - '0');
		//printf("%d %d\n", start, end);
		for (int j = start; j < end ; ++j) v[j]++;//???????????????
	}
	int ans = 0;

	
	rep(i, 86400){
		ans = max(ans, v[i]);
	}
	
	//sort(all(v));
	//reverse(all(v));
	printf("%d\n", ans);
	return;
}
int main(void){
	rep(i, 100000000){
		int n; scanf("%d", &n);
		if(n == 0) break;
		slove(n);
	}
	return 0;
}

Measured memory_bytes: 3500
l=[i for i in input()]
n=len(l)

ans=1

for i in range(1,n-1):
  if l[i-1]==l[i]:
    l[i+1]=l[i]+l[i+1]
    l[i]=l[i-1]
  else:
    ans+=1

if l[n-2]!=l[n-1]:
  ans+=1
    
print(ans)

Measured memory_bytes: 8612