akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include<stdio.h>
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include<stack>
#include <queue>
#include<map>
#include <set>
#include<math.h>
using namespace std;
#define int long long
#define ll long long
#define rep(i,n) for(ll i=0;i<n;++i)
#define loop(i,m,n) for(ll i=m;i<n;++i)
#define ggr getchar(); getchar();return 0;
#define pie 3.141592653589793238462643383279
#define elif else if
#define P pair<ll,ll>
const int inf = 1000000007;
int bin(int bina) {
	int ans = 0;
	for (int i = 0; bina > 0; i++)
	{
		ans = ans + (bina % 2) * pow(10, i);
		bina = bina / 2;
	}
	return ans;
}
bool prime(int n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n % i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
int kai(int x) {
	if (x == 0)return 1;
	return kai(x - 1) * x % inf;
}
int mod_pow(int x, int y, int mod) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % mod;
		}
		x = x * x % mod;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	return kai(x)* mod_pow(kai(x - y), inf - 2, inf) % inf * mod_pow(kai(y), inf - 2, inf) % inf;
}
struct union_find {
	int par[200010], size_[200010];
	void init(int x) {
		rep(i, x) { par[i] = i; size_[i] = 1; }
	}
	int find(int x) {
		if (par[x] == x)return x;
		return par[x] = find(par[x]);
	}
	void unite(int x, int y) {
		x = find(x); y = find(y);
		if (x == y)return;
		if (size_[x] < size_[y]) {
			par[x] = y;
			size_[y] += size_[x];
		}
		else {
			par[y] = x;
			size_[x] += size_[y];
		}
	}
};
struct edge { int to, cost; };

signed main() {
	double a, b, s, d;
	cin >> a >> b >> s >> d;
	cout << (a*b) / 2 << ' ';
	if (s * 2 == a && d * 2 == b) {
		cout << 1 << endl;
	}
	else {
		cout << 0 << endl;
	}
}



Measured memory_bytes: 256
#include <stdio.h>
int main()
{
    int n,x,i,j,k;
    while (1)
    {
        scanf("%d",&n);
        scanf("%d",&x);
        if(n == 0 && x == 0)break;
        int r = 0 ;

        for ( i = 1; i <= n-2; i++)
        {
            for(j = i+1;j<=n-1;j++){
                for(k = j+1;k<=n;k++){
                    if(i + j + k == x)r++;
                  // printf("%d %d %d\n",i,j,k);
                }
            }
        }
        
     printf("%d\n",r);
    }
    
    return 0;
}


Measured memory_bytes: 2028
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define pli pair<ll, int>
#define pil pair<int, ll>
#define pll pair<ll, ll>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define endl '\n'
const int inf = 1000000007;
const ll INF = 1e18;
// int mod = 998244353;
int mod = 1000000007;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
template<typename T, typename U> T pow_(T a, U b) { return b ? pow_(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, ll b, ll _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T, class U> ostream& operator << (ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<class T> ostream& operator << (ostream& os, const vector<T>& vec) { rep(i, sz(vec)) { if (i) os << " "; os << vec[i]; } return os; }
template<typename T> inline istream& operator >> (istream& is, vector<T>& v) { rep(j, sz(v)) is >> v[j]; return is; }
template<class T, class T2> inline void add(T &a, T2 b) { (a += b % mod) %= mod; if (a < 0) a += mod; }
template<class T> void operator += (vector<T>& v, vector<T> v2) { rep(i, sz(v2)) v.eb(v2[i]); }

void solve();

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout << fixed << setprecision(12); // debuged
  int T;
  T = 1;
  while (T--) solve();
}

void solve() {
  string s;
  cin >> s;
  rep(i, sz(s)) {
    if (i % 2 == 0) {
      if (s[i] == 'L') {
        cout << "No" << endl;
        return;
      }
    } else {
      if (s[i] == 'R') {
        cout << "No" << endl;
        return;
      }
    }
  }
  cout << "Yes" << endl;
}


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

string Wtolower(string S){
    string T = S;
    for(int i=0;i<S.size();i++){
        T[i]=tolower(S[i]);
    }
    return T;
}

int main(){
    string W;
    string t;
    cin>>W;
    W=Wtolower(W);
    int Num=0;
    while(1){
        cin>>t;
        if(t=="END_OF_TEXT")break;
        t=Wtolower(t);
        if(t==W)Num+=1;
    }
    cout<<Num<<endl;
    return 0;
}


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

using namespace std;

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

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

istream& operator>> (istream& in, pii& b) {
    in >> b.first >> b.second;
    return in;
}

ostream& operator<< (ostream& out, const pii& b) {
    out << "{" << b.first << ", " << b.second << "}";
    return out;
}

template <typename T1, typename T2> inline bool chkmin(T1 &x, const T2 &y) {if (x > y) {x = y; return 1;} return 0;}
template <typename T1, typename T2> inline bool chkmax(T1 &x, const T2 &y) {if (x < y) {x = y; return 1;} return 0;}


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

const ld PI = acos(-1);

#define time clock() / (double) CLOCKS_PER_SEC

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

mt19937 gen(chrono::high_resolution_clock::now().time_since_epoch().count());

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    int cnt = 0;
    for (int i = 0; i < n; i++) {
        int x, y;
        cin >> x >> y;
        if (x == y) {
            cnt++;
            if (cnt == 3) {
                cout << "Yes\n";
                return 0;
            }
        } else {
            cnt = 0;
        }
    }
    cout << "No\n";
}
/*

*/

Measured memory_bytes: 3652
#include <bits/stdc++.h>
#pragma GCC diagnostic ignored "-Wunused-result"
#define int long long
using namespace std;

#define fin(i,n) for (int i = 0; i < n; i++)
#define fin2(i,a,b) for (int i = a; i < b; i++)
#define ford(i,n) for (int i = n-1; i >= 0; i--)
#define ford2(i,a,b) for (int i = a-1; i >= b; i--)
 
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define MOD 1000000007
#define PI 3.1415926535897932384626
#define EXP1 2.718281828459045
#define BIG 1000000000000000000

#define sl(n) scanf("%lld", &n)
#define sll(n,m) scanf("%lld %lld", &n, &m)
#define slll(n,m,k) scanf("%lld %lld %lld", &n, &m, &k)
#define sllll(n,m,k,o) scanf("%lld %lld %lld %lld", &n, &m, &k, &o)
#define sd(n) scanf("%lf", &n)
#define sdd(n,m) scanf("%lf %lf", &n, &m)
#define sddd(n,m,k) scanf("%lf %lf %lf", &n, &m, &k)
#define sc(c) scanf(" %c", &c)
#define ss(s) scanf("%s", s)
#define sal(t,n) fin(iz,n) { scanf("%lld", &t[iz]); }
#define sad(t,n) fin(iz,n) { scanf("%lf", &t[iz]); }
#define gl(t) scanf(" %[^\n]", t);

#define pc(n) printf("%c\n", n)
#define ps(s) printf("%s\n", s)
#define pss(s) printf("%s\n", s.c_str())
#define pl(n) printf("%lld\n", n)
#define pll(n,m) printf("%lld %lld\n", n, m)
#define plll(n,m,k) printf("%lld %lld %lld\n", n, m, k)
#define pd(n) printf("%lf\n", n)
#define pdd(n,m) printf("%lf %lf\n", n, m)
#define pal(t,n) fin(rz,n) { printf("%lld ", t[rz]); } printf("\n")
#define pad(t,n) fin(rz,n) { printf("%lf ", t[rz]); } printf("\n")

#define chmin(x, v) x = min(x, v)
#define chmax(x, v) x = max(x, v)
 
#define OK ps("OK")
#define OK1 ps("OK1")
#define OK2 ps("OK2")

#define ll int
#define vl vector<ll>
#define vvl vector<vl>
#define vvvl vector<vvl>

#define dll pair<ll, ll>
#define vdll vector<dll>
#define vvdll vector<vdll>

#define vb vector<bool>
#define vvb vector<vb>
#define vd vector<double>
#define vvd vector<vd>
#define vc vector<char>
#define vvc vector<vc>

#define all(v) v.begin(), v.end()
#define vlen(v) (int)(v.size())
#define pb push_back
#define fi first
#define se second

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

    int n;
    cin >> n;
    vector<double> dp(n+1), tmp(n+1);
    dp[0] = 1.0;
    fin(i, n) {
        double p; cin >> p;
        tmp.assign(n+1, 0);
        fin(j, i+1) {
            tmp[j] += (1-p)*dp[j];
            tmp[j+1] += p*dp[j]; 
        }
        dp = tmp;
    }
    double rep = 0.0;
    fin2(i, (n+1)/2, n+1) {
        rep += dp[i];
    }
    cout << fixed << setprecision(9);
    cout << rep << '\n';
}

Measured memory_bytes: 256
N,K=map(int,input().split())
A=list(map(int,input().split()))
Nlist=[0]*(10**5+1)
P=10**9+7
Nlist[1]=1
for i in range(1, 10**5):
    Nlist[i+1]=(Nlist[i]*(i+1))%P
Ninv=[1]*(10**5+1)
Ninv[-1]=pow(Nlist[-1], P-2,P)
for i in range(0,10**5):
    Ninv[-1-i-1]=(Ninv[-1-i]*(10**5-i))%P
for i in range(N):
    A[i]=[A[i], i]
A.sort()
ans=0
for i in range(K-1,N):
    if A[i][0]>=0:
        ans+=(A[i][0]*Nlist[i]*Ninv[K-1]*Ninv[i-K+1])%P
    else:
        ans+=(A[i][0]*Nlist[i]*Ninv[K-1]*Ninv[i-K+1])%P-P
for i in range(0,N-K+1):
    if A[i][0]>=0:
        ans-=(A[i][0]*Nlist[N-i-1]*Ninv[K-1]*Ninv[N-i-K])%P
    else:
        ans-=(A[i][0]*Nlist[N-i-1]*Ninv[K-1]*Ninv[N-i-K])%P-P
print(ans%P)

Measured memory_bytes: 27868
read N
mountains=()
for i in $( seq 0 $(( N - 1 )) ); do
  read height
  mountains=("${mountains[@]}" $height)
done

GOV=1
for i in $( seq 1 $(( N - 1)) ); do
  for j in $( seq 0 $(( i - 1 )) ); do
    if [ ${mountains[$i]} -lt ${mountains[$j]} ]; then
      break
    elif [ $j -eq $(( i - 1 )) ]; then
      GOV=$(( GOV + 1 ))
    fi
  done
done

echo $GOV

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

result = ["a"]
alph = "abcdefghijklmn"

def gen(w):
    ret = []
    s = len(set(w))
    for ch in alph[:s+1]:
        ret.append(w+ch)
    return ret

i = 0
w = result[i]
while len(w) <= N:
    w = result[i]
    result.extend(gen(w))
    i += 1
    if len(w) == N:
        print(w)


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

int main() {
  string S;
  cin >> S;
  reverse(S.begin(), S.end());
  int idx = 0;
  while (idx < S.size()) {
    if (S.substr(idx, 5) == "maerd" || S.substr(idx, 5) == "esare") {
      idx += 5;
    } else if (S.substr(idx, 6) == "resare") {
      idx += 6;
    } else if (S.substr(idx, 7) == "remaerd") {
      idx += 7;
    } else {
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
}


Measured memory_bytes: 512
#define _USE_MATH_DEFINES
#include<iostream>
#include<cstring>
#include<string>
#include<cmath>
#include<vector>
#include<algorithm>
#include<iterator>
#include<sstream>
#include<iomanip>
#include<map>
#include<queue>
#include<deque>
#include<fstream>
#include<random>

#define rep(i, n) for (ll i = 0; i < n; i++) 
#define rrep(i, n) for(ll i = n-1; i>=0; i--)
#define range(i, n, m) for (ll i = n; i < m; i++) 
#define rrange(i, n, m) for (ll i = n - 1; i => m; i--) 
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define vl vector<ll>
#define vvl vector<vector<ll> >
#define vp vector<pair<ll, ll> >
#define vvp vector<vector<pair<ll, ll> > >
#define First first
#define Second second.first
#define Third second.second
//#define MOD 998244353
#define MAX 100000

typedef long long int ll;
typedef unsigned long long int ull;

using namespace std;

template<class T> inline bool chmax(T & a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T & a, T b) { if (a > b) { a = b; return true; } return false; }

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

	string S, T;
	cin >> S >> T;

	map<char, vl> SSTR;

	rep(i, S.size()) {
		SSTR[S[i]].pb(i);
	}

	ll len = S.size();
	ll cnt, dst, n;
	cnt = dst = n = 0;
	n = -1;

	rep(i, T.size()) {
		if (SSTR.count(T[i]) == 0) {
			cout << -1 << endl;
			return 0;
		}
		ll nn = 0;
		ll min = len;
		if (SSTR[T[i]].front() > n) {
			nn = SSTR[T[i]].front();
			min = nn - n;
		}
		else if(SSTR[T[i]].back() <= n){
			nn = SSTR[T[i]].front();
			min = nn - n + len;
		}
		else {
			ll size = SSTR[T[i]].size();
			ll c = size / 2;
			ll l, r;
			r = len;
			l = 0;
			size /= 4;
			while ((r - l) != 1) {
				if (SSTR[T[i]][c] > n) {
					chmin(r, c);
					if (chmin(min, SSTR[T[i]][c] - n)) {
						nn = SSTR[T[i]][c];
					}
					c -= size;
				}
				else {
					chmax(l, c);
					c += size;
				}
				size /= 2;
				if (size == 0)size = 1;
			}
		}

		n = nn;
		cnt += min;
	}

	cout << cnt << endl;


	return 0;
}



Measured memory_bytes: 1736
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<numeric>
#include<cmath>
#include<queue>
#include<stack>
#include<list>
#include<unordered_map>
#include<unordered_set>
#include<cctype>
#include<iomanip>
#include<limits>
#include<bitset>

using namespace std;
typedef long long int ll; typedef pair<int, int> P;
const ll mod = 1e9 + 7;
const int inf = 1e9 + 7;
const ll linf = 1LL << 60;
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define REP(i,m,n) for(int i=(m);i<(int)n;i++)
#define all(a) (a).begin(),(a).end()
#define allg(a) (a).begin(),(a).end(),greater<>()
#define SUM(a) accumulate((a).begin(),(a).end(),0)
#define d10 std::setprecision(10)
#define d20 std::setprecision(20)
#define sz size()
using str = string;
const double PI = 3.14159265359;
ll gcd(ll a, ll b) { ll t; while (b != 0) { t = a % b; a = b; b = t; }return a; }
int gcd(int a, int b) { int t; while (b != 0) { t = a % b; a = b; b = t; }return a; }
ll recfact(ll start, ll n) {
	ll i;
	if (n <= 16) {
		ll r = start;
		for (i = start + 1; i < start + n; i++) r = r * i % mod;
		return r % mod;
	}
	i = n / 2;
	return recfact(start, i) % mod * recfact(start + i, n - i) % mod;
}
ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
}
ll fct(ll n) { return recfact(1, n); }
ll ncm(ll n, ll m) {
	if (n < m)return 0;
	ll x = (fct(n) % mod / (fct(m) * fct(n - m)) % mod) % mod;
	return x;
}
bool isincluded(char x, string str) {
	bool f = 0;
	for (size_t i = 0; i < str.size(); i++) {
		if (str.at(i) == x)f = 1;
	}
	return f;
}
int ctoi(char c) {
	if ('0' <= c && c <= '9') {
		return c - '0';
	}
	return 0;
}




int main(void) {
	str s; cin >> s;
	int n = s.sz;
	int tmp, ans = n;
	rep(i, n) {
		if (s[i] != s[i + 1]) {
			tmp = max(i + 1, n - 1 - i);
			ans = min(ans, tmp);
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <cstring>
#include <utility>
#include <numeric>

using namespace std;

const int MOD = 1e9 + 7;

long long powMod(int a, int n){
    if(n == 0){
        return 1;
    }
    if(n % 2 == 0){
        long long temp = powMod(a, n / 2);
        return (temp * temp) % MOD;
    }

    else{
        long long temp = powMod(a, n / 2);
        return (((temp * temp) % MOD) * a) % MOD;
    }
}

int main(){

    int N;
    cin >> N;

    long long ans = 0;

    long long temp1 = powMod(10, N);
    long long temp2 = (2 * powMod(9, N)) % MOD;
    long long temp3 = powMod(8, N);
    ans = (temp1 + temp3) % MOD;
    ans = (ans - temp2 + MOD) % MOD;

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3632
n = int(input())
h = list(map(int, input().split()))

count = 1

for i in range(1, n): #判定する旅館
    tmp = 0
    for j in range(i): #高さを判定
        if h[j] <= h[i]:
            tmp += 1
    if tmp == i:
        count += 1

print(count)

Measured memory_bytes: 3060
#  D -Lamp
h,w=map(int,input().split())
g=[input() for i in range(h)]
l=[[0]*w for i in range(h)]
r=[[0]*w for i in range(h)]
u=[[0]*w for i in range(h)]
o=[[0]*w for i in range(h)]

for i in range(h):
    if g[i][0]=='.':
        l[i][0]=1

for i in range(h):
    for j in range(w-1):
        if g[i][j+1]=='.':
            l[i][j+1]=l[i][j]+1
        elif g[i][j+1]=='#':
            l[i][j+1]=0

for i in range(h):
    if g[i][w-1]=='.':
        r[i][w-1]=1

for i in range(h):
    for j in range(w-1,0,-1):
        if g[i][j-1]=='.':
            r[i][j-1]=r[i][j]+1
        elif g[i][j-1]=='#':
            r[i][j-1]=0

for i in range(w):
    if g[0][i]=='.':
        u[0][i]=1

for i in range(w):
    for j in range(h-1):
        if g[j+1][i]=='.':
            u[j+1][i]=u[j][i]+1
        elif g[j+1][i]=='#':
            u[j+1][i]=0

for i in range(w):
    if g[h-1][i]=='.':
        o[h-1][i]=1

for i in range(w):
    for j in range(h-1,0,-1):
        if g[j-1][i]=='.':
            o[j-1][i]=o[j][i]+1
        elif g[j-1][i]=='#':
            o[j-1][i]=0

ans=0
for i in range(h):
    for j in range(w):
        ans=max(ans,l[i][j]+r[i][j]+u[i][j]+o[i][j]-3)

print(ans)


Measured memory_bytes: 181252
#include <bits/stdc++.h>
#define l_ength size
const int inf = (1<<30);
const int mod = 1000000007; // 998244353
using ll = long long;
using namespace std;

int main(){
	ll a, b, c, k; cin >> a >> b >> c >> k;
	if( k <= a + b ) cout << min(k, a) << endl;
	else cout << a-min(c, k-(a+b)) << endl;
}

Measured memory_bytes: 3564
N = int(input())
A = list(map(int, input().split()))

# even is +
now = 0
even_count = 0
for i, a in enumerate(A):
    now += a
    if i % 2 == 0 and now <= 0:
        even_count += 1 - now
        now = 1
    elif i % 2 == 1 and now >= 0:
        even_count += abs(-1 - now)
        now = -1

# odd is +
now = 0
odd_count = 0
for i, a in enumerate(A):
    now += a
    if i % 2 == 0 and now >= 0:
        odd_count += abs(-1 - now)
        now = -1
    elif i % 2 == 1 and now <= 0:
        odd_count += 1 - now
        now = 1
print(min(even_count, odd_count))


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

int32_t main()
{
    int n;cin>>n;
    int arr[n];
    unordered_map<int,int>mp;

    int sum=0;
    for(int i=0;i<n;i++){
        cin>>arr[i];
        mp[arr[i]]++;
        sum+=arr[i];
    }
    int q;
    cin>>q;
    int u,v;
    while(q--){
        cin>>u>>v;
        int x=mp[u];
        mp.erase(u);
        sum=sum-x*u+x*v;
        cout<<sum<<endl;
        mp[v]=mp[v]+x;
    }
    return 0;
}

Measured memory_bytes: 7432
S = input()
T = input()
q = int(input())

SS = [0]
TT = [0]
for i in S:
    if i=="A":
        SS.append(1+SS[-1])
    else:
        SS.append(2+SS[-1])
for i in T:
    if i=="A":
        TT.append(1+TT[-1])
    else:
        TT.append(2+TT[-1])

for i in range(q):
    a,b,c,d = map(int,input().split())
    if (SS[b]-SS[a-1])%3 == (TT[d]-TT[c-1])%3:
        print("YES")
    else:
        print("NO")

Measured memory_bytes: 55336
#include <cstdio>
#include <set>
#include <string>
using namespace std;
set<string>se;
int n;
string s;
char p[100000];
int main(){
	scanf("%d",&n);
	for(int i=0;i<n;++i){
		scanf("%s",p);
		s=string(p);
		se.insert(s);
	}
	printf("%d\n",se.size());
	return 0;
}


Measured memory_bytes: 19012
#include<bits/stdc++.h>
using namespace std;
template<class S, class T> inline S max_L(S a,T b){
  return a>=b?a:b;
}
inline void rd(int &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(int x){
  char f[10];
  int m=0, s=0;
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
int main(){
  int A, B, W, res;
  rd(W);
  rd(A);
  rd(B);
  if(A > B){
    swap(A, B);
  }
  res =max_L(0, B-A-W);
  wt_L(res);
  wt_L('\n');
  return 0;
}
// cLay varsion 20190721-1

// --- original code ---
// {
//   int W, A, B, res;
//   rd(W,A,B);
//   if(A > B) swap(A, B);
//   res = max(0, B-A-W);
//   wt(res);
// }


Measured memory_bytes: 256
#include <float.h>
#include <inttypes.h>
#include <limits.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <math.h>
#ifdef __cplusplus
#include <bits/stdc++.h>
#endif

char buf[2097152];
int bufl;
inline char bufr(void){
	return buf[bufl++];
}

#define getchar bufr

void rsort_d32(void *base, const int count){
	int32_t *a=base;
	int32_t *b=malloc(count*sizeof(int32_t));
	int c[0x100];
	memset(c, 0, sizeof(c)); for(int i=0; i<count; i++){ c[(a[i]>>(0<<3))&0xFF]++; } for(int i=1; i<0x100; i++) c[i]+=c[i-1]; for(int i=count-1; i>=0; i--){ b[--c[(a[i]>>(0<<3))&0xFF]]=a[i]; }{void *t=a; a=b; b=t;}
	memset(c, 0, sizeof(c)); for(int i=0; i<count; i++){ c[(a[i]>>(1<<3))&0xFF]++; } for(int i=1; i<0x100; i++) c[i]+=c[i-1]; for(int i=count-1; i>=0; i--){ b[--c[(a[i]>>(1<<3))&0xFF]]=a[i]; }{void *t=a; a=b; b=t;}
	memset(c, 0, sizeof(c)); for(int i=0; i<count; i++){ c[(a[i]>>(2<<3))&0xFF]++; } for(int i=1; i<0x100; i++) c[i]+=c[i-1]; for(int i=count-1; i>=0; i--){ b[--c[(a[i]>>(2<<3))&0xFF]]=a[i]; }{void *t=a; a=b; b=t;}
	memset(c, 0, sizeof(c)); for(int i=0; i<count; i++){ c[(a[i]>>(3<<3))+0x80]++; } for(int i=1; i<0x100; i++) c[i]+=c[i-1]; for(int i=count-1; i>=0; i--){ b[--c[(a[i]>>(3<<3))+0x80]]=a[i]; }{void *t=a; a=b; b=t;}
	free(b);
}
int32_t nextint(void){ char c=getchar(); while(c!='-'&&(c<'0'||'9'<c)) c=getchar(); int s=0; if(c=='-'){s=1;c=getchar();} uint32_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar(); } return s?-x:x; }

#define P 1000000007

int k[100001];
int rk[100001];

int getk(int a, int x){
	if(x==1) return a;
	int b = getk(a, x/2);
	b = ((long)b)*b%P;
	if((x&1)==0){
		return b;
	}else{
		return ((long)b)*a%P;
	}
}
 
int comb(int a, int b){
	if(a<b) return 0;
	return ((long)k[a])*rk[b]%P*rk[a-b]%P;
}

void comb_init(int n){
	k[0]=1;
	for(int i=1; i<=n; i++){
		k[i]=k[i-1]*((long)i)%P;
	}	
	rk[n]=getk(k[n], P-2);
	for(int i=n-1; i>=0; i--){
		rk[i]=((long)rk[i+1])*(i+1)%P;
	}
}

int a[100000];
int main(void){
	read(STDIN_FILENO, buf, sizeof(buf));
	int n=nextint();
	int k=nextint();
	for(int i=0; i<n; i++){
		a[i]=nextint();
	}
	rsort_d32(a, n);
	comb_init(n);
	long ans=0;
	for(int i=0; i<=n-k; i++){
		int c = comb(n-i-1, k-1);
		ans=((long)(a[n-i-1]-a[i])*c%P+ans+P)%P;
	}
	printf("%ld\n", ans);
}


Measured memory_bytes: 2424
#include <bits/stdc++.h>
using namespace std;
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;
}
typedef long long int ll;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define endl "\n"
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, k;
    cin >> n >> k;
    ll num = n / k;
    ll ans = llabs(num * k - n);
    chmin(ans, llabs((num + 1) * k - n));
    chmin(ans, llabs(max((num - 1), 0LL) * k - n));
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  int n, x;
  cin >> n >> x;
  int a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a,a+n);

  ll sum = 0, rec = 0;
  for (int i = 0; i < n; i++) {
    sum += a[i];
    if (sum >= x) {
      sum == x ? (rec = i + 1) : (rec = i);
      break;
    }
    if (sum < x && i == n - 1) {
      rec = i;
    }
  }

  cout << rec << endl;
}

Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

from collections import Counter

a1, b1 = map(int, readline().split())
a2, b2 = map(int, readline().split())
a3, b3 = map(int, readline().split())
counter = sorted(list(Counter([a1, a2, a3, b1, b2, b3]).values()))
if counter == [1, 1, 2, 2]:
    print('YES')
else:
    print('NO')


Measured memory_bytes: 3316
import Text.Printf

main :: IO()
main = getContents >>= mapM_ ((\[x, y] -> printf "%.3f %.3f\n" x y) . cramer) . (mapMap read . wordsLines)

cramer :: [Double] -> [Double]
cramer [a, b, p, c, d, q] = map ((+ 1e-5) . (/ (a * d - b * c))) [p * d - b * q, a * q - p * c]

wordsLines :: String -> [[String]]
wordsLines = map words . lines

mapMap :: (a -> b) -> [[a]] -> [[b]]
mapMap f = map (map f)


Measured memory_bytes: 4448
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i, n) for (int i = 0; i < ((int)(n)); i++) // 0-indexed昇順

int main()
{
  string s;
  cin >> s;
  string t;
  copy(s.begin(), s.end(), back_inserter(t));
  reverse(begin(t), end(t));

  if (s == t) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
	int A,B,K;
	int i,mem;
	
	scanf("%d %d %d",&A,&B,&K);
	
	for(i=0;i<K;i++){
		if(i%2==0){
			
			if(A%2==1){
				A--;
			}
			
			mem=A/2;
			
			if(A%2==1){
				mem++;
			}
			
			A=mem;
			B+=mem;
			
		}else{
			
			if(B%2==1){
				B--;
			}
			
			mem=B/2;
			
			if(B%2==1){
				mem++;
			}
			
			B=mem;
			A+=mem;
			
		}
	}
	
	printf("%d %d",A,B);
	
	
	return 0;
}

Measured memory_bytes: 128
s = gets.chomp.to_i
ary = [s]

tmp = s + 0
count = 1
while true
  count += 1
  if tmp % 2 == 0
    tmp /= 2
  else
    tmp = tmp * 3 + 1
  end
  if ary.find {|item| item == tmp}
    puts count
    break
  end
  ary << tmp
end


Measured memory_bytes: 1788
import sys

class Node:
    __slots__ = ['key', 'left', 'right']
    def __init__(self, key):
        self.key = key
        self.left = None
        self.right = None

class BST:
    def __init__(self):
        self.root = None
    def insert(self, key):
        x = self.root
        y = None
        z = Node(key)
        while x != None:
            y = x
            x = x.left if z.key < x.key else x.right
        if y == None: self.root = z
        else:
            if z.key < y.key: y.left = z
            else: y.right = z
    def print_tree(self):
        def inorder(node):
            if node:
                inorder(node.left)
                print('',node.key, end='')
                inorder(node.right)
        def preorder(node):
            if node:
                print('',node.key, end='')
                preorder(node.left)
                preorder(node.right)
        inorder(self.root)
        print()
        preorder(self.root)
        print()

tree = BST()
input()
for e in sys.stdin:
    if e[0] == 'i': tree.insert(int(e[7:]))
    else:
        tree.print_tree()


Measured memory_bytes: 53988
n = input()
k = int(input())
dp0 = [[0]*(k+1) for _ in range(len(n)+1)]
dp1 = [[0]*(k+1) for _ in range(len(n)+1)]
dp0[0][0] = 1
for i in range(len(n)):
    for j in range(k+1):
        if int(n[i]) == 0:
            dp0[i+1][j] += dp0[i][j]
        if int(n[i]) > 0:
            dp1[i+1][j] += dp0[i][j]
            if j < k:
                dp0[i+1][j+1] += dp0[i][j]
                dp1[i+1][j+1] += dp0[i][j]*(int(n[i])-1)
        if j < k:
            dp1[i+1][j+1] += dp1[i][j]*9
        dp1[i+1][j] += dp1[i][j]
print(dp0[len(n)][k]+dp1[len(n)][k])

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

#define forn(i,n) for(int i=0;i<(int)(n);i++)
#define si(c) ((int)(c).size())
#define forsn(i,s,n) for(int i = (int)(s); i<((int)n); i++)
#define dforsn(i,s,n) for(int i = (int)(n)-1; i>=((int)s); i--)
#define all(c) (c).begin(), (c).end()
#define D(a) cerr << #a << "=" << a << endl;
#define pb push_back
#define eb emplace_back
#define mp make_pair

#ifdef LOCAL
#define i64 "%lld"
#else
#define i64 "%I64d"
#endif

typedef long long int ll;
typedef vector<int> vi;
typedef pair<int,int> pii;

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

    ll n,x; cin >> n >> x;
    ll ans = 0;
    while (true) {
        x = min(x, n-x);
        if (n == 0 || x == 0) break;
        ll it = (n - 2*x) / x;
        if (it == 0) it = 1;
//        cerr << n << ' ' << x << endl;
//        D(it);

        ans += it*3*x;
        n -= it*x;
    }
    
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdbool.h>
#define N 8
#define F -1
#define NF 1
int r[N],c[N],ds[2*N-1],dg[2*N-1];
bool x[N][N];
void initialize(){
  int i;
  for(i=0;i<N;i++){
    r[i]=F;
    c[i]=F;
  }
  for(i=0;i<2*N-1;i++){
    ds[i]=F;
    dg[i]=F;
  }
}
/*void in(){
  int i,j,k,r,c;
  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      x[i][j]=false;
    }
  }
  scanf("%d",&k);
  for(i=0;i<k;i++){
    scanf("%d%d",&r,&c);
    x[r][c]=true;
  }
  }*/
void print(){
  int i,j;
  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      if(x[i][j]){
        if(r[i]!=j)return;
      }
    }
  }
  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      if(r[i]==j)printf("Q");
      else printf(".");
    }
    printf("\n");
  }
}
void recu(int i){
  int j;
  if(i==N){
    print();
    return;
  }
  for(j=0;j<N;j++){
    if(c[j]==NF || ds[i+j]==NF || dg[i-j+N-1]==NF)continue;
    r[i]=j;
    c[j]=ds[i+j]=dg[i-j+N-1]=NF;
    recu(i+1);
    r[i]=c[j]=ds[i+j]=dg[i-j+N-1]=F;
  }
}
int main(){
  initialize();
  int i,j,k,r,c;
  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      x[i][j]=false;
    }
  }
  scanf("%d",&k);
  for(i=0;i<k;i++){
    scanf("%d%d",&r,&c);
    x[r][c]=true;
  }
  recu(0);
  return 0;
}



Measured memory_bytes: 2112
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

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

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

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

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

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

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
fn adjacent4(x: usize, y: usize, sx: usize, sy: usize) -> Vec<(usize, usize)> {
    [(-1, 0), (1, 0), (0, -1), (0, 1)]
        .into_iter()
        .filter_map(|&(dx, dy)| {
            let nx = x as isize + dx;
            let ny = y as isize + dy;
            if nx >= 0 && nx < sx as isize && ny >= 0 && ny < sy as isize {
                Some((nx as usize, ny as usize))
            } else {
                None
            }
        })
        .collect()
}

#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
fn main() {
    input! {
        n: usize,
        m: usize,
        c: isize,
        b: [isize; m],
        a: [[isize; m]; n],
    }
    let mut count = 0;
    for i in 0..n {
        let mut ret = 0;
        for j in 0..m {
            ret += a[i][j] * b[j];
        }
        if ret + c > 0 {
            count += 1;
        }
    }
    println!("{}", count);
}


Measured memory_bytes: 4352
#include <iostream>
#include <bits/stdc++.h>
#define ll long long
#define inf 100000000
#define mod 1000000007
#define ld long double
#define point complex<long double>
#define pi  acos(-1)
#define IO                    \
	ios_base::sync_with_stdio(false); \
	cin.tie(NULL);                    \
	cout.tie(NULL);
using namespace std;
int main(){
int n;
cin>>n;
ll arr[n+1];
for(int i=1;i<=n;i++)
{
	cin>>arr[i];
}
vector<int>vec;
vector<int>::iterator it;
for(int i=1;i<=n;i++)
{
	ll cur=arr[i];
	if(vec.size()==0)
	{
		vec.push_back(cur);
		continue;
	}
	it=lower_bound(vec.begin(),vec.end(),cur);
	if(it==vec.begin())
	{
		vec.insert(vec.begin(),cur);
	}
	else 
	{
		it--;
		*it=cur;
	}
	
}
cout<<vec.size()<<endl;
    return 0;
}


Measured memory_bytes: 1660
a, b, k = gets.chop.split

a = a.to_i
b = b.to_i
k = k.to_i

if a >= k
  a -= k
  remain = 0
else
  remain = k - a
  a = 0
end

if b >= remain
  b -= remain
else
  b = 0
end

puts "#{a} #{b}"

Measured memory_bytes: 1788
from sys import stdin
input = stdin.readline


def main():
  N = int(input())
  A = list(map(int, input().split()))

  order = []
  for i in range(N):
    order.append((i+1, A[i]))
  order = sorted(order, key=lambda x: x[1])
  for i in range(N-1):
    print(order[i][0], end=' ')
  print(order[N-1][0])


if(__name__ == '__main__'):
  main()


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

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

int ok[200010] = {0};
int ok_cnt = 0;

signed main(){

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

    queue<ll> q;
    rep(i,n){
        if(b[i] > b[(i-1+n)%n] + b[(i+1)%n] && b[i] != a[i]){
            q.push(i);
        }
    }
    // while(q.size()){
    //     cerr << q.front() << endl;
    //     q.pop();
    // }

    int ans = 0;
    while(q.size()){
        ll i = q.front();
        q.pop();

        if((b[i]-a[i])%(b[(i-1+n)%n] + b[(i+1)%n]) == 0){
            ans += (b[i]-a[i])/(b[(i-1+n)%n] + b[(i+1)%n]);
            b[i] = a[i];
        }else{
            ll k = (b[i]-1)/(b[(i-1+n)%n] + b[(i+1)%n]);
            ans += k;
            b[i] -= k*(b[(i-1+n)%n] + b[(i+1)%n]);
        }

        if(b[(i-1+n)%n] > b[(i-2+n)%n] + b[i] && b[(i-1+n)%n] != a[(i-1+n)%n])q.push((i-1+n)%n);
        if(b[(i+1)%n] > b[i] + b[(i+2)%n] && b[(i+1)%n] != a[(i+1)%n])q.push((i+1)%n);

        
        // ll k = (b[i]-a[i])/(b[(i-1+n)%n] + b[(i+1)%n]);
        // b[i] -= k*(b[(i-1+n)%n] + b[(i+1)%n]);
        // ans += k;
        // if(a[i] == b[i])ok_cnt++;

        // if(b[(i-1+n)%n] - b[(i-2+n)%n] - b[i] >= a[(i-1+n)%n])q.push((i-1+n)%n);
        // if(b[(i+1)%n] - b[i] - b[(i+2)%n] >= a[(i+1)%n])q.push((i+1)%n);
    }
    // rep(i,n)cerr << a[i] << " ";cerr << endl;
    // rep(i,n)cerr << b[i] << " ";cerr << endl;
    // if(ok_cnt != n)cout << -1 << endl;
    // else cout << ans << endl;

    rep(i,n){
        if(a[i] != b[i]){
            cout << -1 << endl;
            return 0;
        }
    }
    cout << ans << endl;



   
    

    return 0;
}

// g++ -std=c++14 code1.cpp
// rm -r -f test;oj dl https://cf17-final-open.contest.atcoder.jp/tasks/cf17_final_a
// rm -r -f test;oj dl http://agc037.contest.atcoder.jp/tasks/agc037_a


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

int main() {
    string s;
    cin >> s;
    
    vector<int> q;
    for (char ch : s) {
        if (ch == '0') q.push_back(0);
        if (ch == '1') q.push_back(1);
        if (ch == 'B') if (!q.empty()) q.pop_back();
    }
    
    for (int x : q) cout << x;
    cout << endl;
}

Measured memory_bytes: 256
def main():
    N, M = [int(i) for i in input().split()]
    
    if(N == 1 and M == 1):
        print(1)
    elif(N == 1):
        print(M - 2)
    elif(M == 1):
        print(N - 2)
    else:
        print(N*M - (N*2 + M*2 - 4 ))
    
if __name__=="__main__":
    main()

Measured memory_bytes: 3060
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef long double ld;
const ll INF = 1e+14;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
 
void Yes(){
	cout<<"Yes"<<endl;
	exit(0);
}
 
void No(){
	cout<<"No"<<endl;
	exit(0);
}

int main(){
  
  string s;
  cin>>s;
  int n=s.size();
  ll ans,bit;
  
  for (bit=0; bit<(1<<n-1); bit++){
    
    ll m=s[0]-'0';
    
    for (int i=0;i<n-1;i++){
      if (bit& (1<<i)){
        ans+=m;
        m=s[i+1]-'0';
      }
      else
        m=m*10+s[i+1]-'0';
    }
    ans+=m;
  }
  
  cout<<ans<<endl;
}

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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
typedef long long ll;


int main() {
    int N,M;
    cin >> N >> M;
    if(N%2 == 1){
        REP(i,M){
            cout << i+1 << " " << N-i << endl;
        }

    }else{
        int sa = N-1;
        int c = 0;
        REP(i,M){
            if(sa==N/2 || sa==N/2-1){
                c = 1;
            }
            cout << i+1 << " " << N-i-c << endl;
            sa -= 2;
        }
    }
    return 0;
}

Measured memory_bytes: 3636
import collections
S = input()

table = collections.defaultdict(int)
for x in S:
    table[x] += 1

N = False
W = False
E = False
S = False

if table["N"] > 0:
    N = True
if table["W"] > 0:
    W = True
if table["E"] > 0:
    E = True
if table["S"] > 0:
    S = True


if (N and S) or ((N or S) == False):
    if (E and W) or ((E or W) == False):
        print("Yes")
        exit(0)
print("No")


Measured memory_bytes: 3444
const input = require('fs').readFileSync('/dev/stdin', 'UTF-8');

const calculator = input => {
  const [a, b] = input.split(' ').map(Number);

  const d = Math.floor(a / b);
  const r = a % b;
  const s = (a / b).toFixed(8);

  console.log([d, r, s].join(' '));
};

calculator(input);



Measured memory_bytes: 15392
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define ve vector

int main(){
    ll n, k;
    cin >> n >> k;
    ve<P> dt(n);
    ve<ll> fl(n,0);
    rep(i,n) {
        cin >> dt[i].second >> dt[i].first;
        dt[i].second--;
    }
    sort(dt.rbegin(), dt.rend());
    ll ans = 0;
    ll cnt = 0;
    ve<P> kouho;
    rep(i,k){
        ans += dt[i].first;
        if(fl[dt[i].second] == 0) cnt++;
        else kouho.push_back(dt[i]);
        fl[dt[i].second] += 1;
    }
    ans += cnt*cnt;
    ve<ll> x;
    x.push_back(ans);
    ll i = k;
    while(i<n && !kouho.empty()){
        if(fl[dt[i].second] != 0){
            i++;
            continue;
        }
        sort(kouho.rbegin(), kouho.rend());
        ans -= cnt*cnt;
        ans -= kouho[kouho.size()-1].first;
        kouho.pop_back();
        cnt++;
        ans += cnt*cnt;
        ans += dt[i].first;
        fl[dt[i].second] = 1;
        x.push_back(ans);
        i++;
    }
    sort(x.rbegin(), x.rend());
    cout << x[0] << endl;
    return 0;
}


Measured memory_bytes: 6480
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=1;i<=n;i++)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
using namespace std;
 
int main(){
    int n,l;
    cin>>n>>l;
    vector<string> v(n);
    for(int i=0;i<n;i++) cin >> v[i];
    sort(v.begin(),v.end());
    for(int i=0;i<n;i++) cout << v[i];
    cout << "\n";
    
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define mod 1000000007
#define FS fixed<<setprecision(15)
using namespace std;
typedef long long ll;
template<class T> using V=vector<T>;
using Graph = vector<vector<int>>;
using P=pair<ll,ll>;
typedef unsigned long long ull;
typedef long double ldouble;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

const ll INF=1e18;
//abc166b

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    int n,k;
    cin>>n>>k;
    V<int> a(n,0);
    rep(i,k){
        int d;
        cin>>d;
        rep(j,d){
            int b;
            cin>>b;
            b--;
            a[b]++;
        }
    }
    int ans=0;
    rep(i,n){
        if(a[i]==0) ans++;
    }
    cout<<ans<<endl;
}
//ペナルティ出しても焦らない　ACできると信じろ！！！
//どうしてもわからないときはサンプルで実験　何か見えてくるかも
//頭で考えてダメなら紙におこせ！！
/*
V,P(大文字)使用不可
乗算などの際にオーバーフローに注意せよ！
(適切にmodをとれ　にぶたんで途中で切り上げろ)
制約をよく読め！
(全探索できるなら全探索しろ)
stringの計算量(扱い)注意
コーナー注意！(特に数値が小さいものについては要検証)
N行出力のときは'\n'
グリッド上では行先が範囲内におさまるかif文で確認(RE注意)
if文ではちゃんと比較演算子==を使え(=でもエラー出ない)
配列(vector)の大きさが0か1以上かで場合分けせよ(RE注意)
(vector<int> a(m)でm==0というものはできない)
modはなるべく最後に取れ！
*/

Measured memory_bytes: 3648
from collections import deque
import copy
 
def main():
  H, W = map(int, input().split())
  M = [['#' == x for x in input()] for _ in range(H)]
  que = deque([(i, j) for i in range(H) for j in range(W) if M[i][j]])
  ans = 0
  while True:
    ans += 1
    qq = deque()
    while que:
      nh, nw = que.popleft()
      if nw < W-1 and not M[nh][nw+1]:
        qq.append((nh,nw+1))
        M[nh][nw+1] = True
      if nw > 0 and not M[nh][nw-1]:
        qq.append((nh,nw-1))
        M[nh][nw-1] = True
      if nh < H-1 and not M[nh+1][nw]:
        qq.append((nh+1,nw))
        M[nh+1][nw] = True
      if nh > 0 and not M[nh-1][nw]:
        qq.append((nh-1,nw))
        M[nh-1][nw] = True
    if qq:
      que = copy.copy(qq)
    else:
      break
  print(ans-1)
  
if __name__ == "__main__":
  main()

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

#define fi first
#define se second
#define pb push_back
 
#define limit (int) (2e5 + 5) 
#define mod (long long int) (1e9 + 7)
 
using namespace std;
using lli = long long int;
using ulli = unsigned long long int;
using ld = long double;

int p[5005],c[5005];
bool visited[5005] = {};

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    int n,k;
    cin >> n >> k;

    for (int i = 1; i <= n; ++i)
    {
        cin >> p[i];
    }

    for (int i = 1; i <= n; ++i)
    {
        cin >> c[i];
    }

    lli ans = LLONG_MIN,temp,s;

    vector<int> v;
    int ck,ps;

    for (int i = 1; i <= n; ++i)
    {
        if(visited[i]) continue;
        s = 0;
        int ci = i;
        v.clear();
        while(!visited[ci])
        {
            visited[ci] = true;
            v.pb(ci);
            s += c[ci];
            ci = p[ci];
        }

        ps = v.size();

        // for(auto e:v)
        //     cout << e;
        // cout << "\n";

        temp = 0;
        if (s < 0)
        {
            ck = min(k,ps);
        } else {

            if (k > ps)
            {
                ck = ps + k%ps;
                temp = (k/ps - 1)*s;
            } else {
                ck = k;
            }
        }

        // cout << ck << " " << temp << "\n";

        lli sum;

        for (int j = 0; j < ps; ++j)
        {
            sum = 0;
            for (int k = 0; k < ck; ++k)
            {
                sum += c[v[(j+k)%ps]];
                ans = max(ans,sum+temp);
            }
        }
    }

    cout << ans;

    return 0;

}














Measured memory_bytes: 3676
#include <iostream>
#include <vector>
#include <math.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)

int main(){
    ll a, b, c; cin >> a >> b >> c;
    ll d = c-a-b;
    if(d > 0 && (d*d) > (4*a*b)) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9 + 7;

int main() {
	ll T1, T2;
	cin >> T1 >> T2;
	ll A1, A2;
	cin >> A1 >> A2;
	ll B1, B2;
	cin >> B1 >> B2;
	if (A1 > B1) {
		swap(A1, B1);
		swap(A2, B2);
	}
	ll diff = A1 * T1 + A2 * T2 - (B1*T1 + B2 * T2);
	if (diff < 0) {
		cout << 0 << endl;
	}
	else if (diff == 0) {
		cout << "infinity" << endl;
	}
	else {
		ll tot = (B1 - A1)*T1;
		ll cnt = 1 + tot / diff * 2;
		if (tot >= diff && tot%diff == 0) cnt--;
		cout << cnt << endl;
	}
}


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

using namespace std;
int main(void){
    // Your code here!
	int a,b,c;
	
	cin>>a>>b>>c;
	if(a==b) cout<<c<<endl;
	else if (a==c) cout<<b<<endl;
	else if(b==c)cout<<a<<endl;
}


Measured memory_bytes: 256
low,high = list(map(int,input().split()))
min_number = 2018
for i in range(low,high):
    for j in range(i+1,high+1):
        A = i * j % 2019
        if A < min_number:
            min_number = A
        if min_number == 0:
            print(0)
            exit()
print(min_number)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(v) v.begin(), v.end()
#define pb push_back
#define INF 1e9
#define MOD 1000000007
using namespace std;

ll gojo(ll n){
    return n*n*n*n*n;
}

ll gojosa(ll n){
    return n*n*n*n
    +n*n*n*(n-1)
    +n*n*(n-1)*(n-1)
    +n*(n-1)*(n-1)*(n-1)
    +(n-1)*(n-1)*(n-1)*(n-1);
}

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

    ll  ansa,ansb;

    for (ll a = 1; a*a*a*a*a <= x; a++)
    {
        for (ll b = -a; b < a; b++)
        {
            if(a*a*a*a*a-b*b*b*b*b==x){
                ansa=a;
                ansb=b;
                goto end;
            }
        }
        
    }

    for (ll a = 1; gojosa(a) <= x; a++)
    {
        for (ll b = 0; b < a; b++)
        {
            if(a*a*a*a*a-b*b*b*b*b==x){
                ansa=a;
                ansb=b;
                goto end;
            }
        }
        
    }
    
    end:
    cout<<ansa<<" "<<ansb<<endl;
    
    return 0;
}

Measured memory_bytes: 3632