akhauriyash/Code-Regression huggingface dataset:
#pragma region head
#include <bits/stdc++.h>

#include <atcoder/all>
using namespace atcoder;
using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using pi = pair<int, int>;
using pll = pair<ll, ll>;
template <class T>
using vv = vector<vector<T>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rrep(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define rrepi(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define bit(n) (1LL << (n))
template <class T>
inline bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, const T &b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}
const int INF = 1002003004;
const ll LINF = 1002003004005006007ll;
struct preprocess {
    preprocess() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} ____;
#pragma endregion head

#pragma region library
#pragma endregion library

int main() {
    int n, q;
    cin >> n >> q;
    fenwick_tree<ll> fw(n);
    rep(i, n) {
        int a;
        cin >> a;
        fw.add(i, a);
    }
    while (q--) {
        int c, a, b;
        cin >> c >> a >> b;
        if (c) {
            cout << fw.sum(a, b) << '\n';

        } else {
            fw.add(a, b);
        }
    }
}

Measured memory_bytes: 8256
#include <bits/stdc++.h>
#define cina(a, n) for (int i = 0; i < n; ++i){ cin >> a[i]; }
#define ll long long

using namespace std;

int main () {
	
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	int k;
	string s;
	cin >> k >> s;
	int n = s.length();
	if (k >= n) {
		cout << s;
		return 0;
	}
	for (int i = 0; i < k; ++i) {
		cout << s[i];
	}
	if (n > k) {
		cout << "...";
	}

	return 0;
}

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

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

bool is_prime(ll n) {
    if (n == 2) return true;

    for (ll i = 2; i * i <= n; ++i) {
        if (n % i == 0) {
            return false;
        }
    }

    return true;
}

int main() {

    ll a, b; cin >> a >> b;

    set<ll> acd;
    set<ll> bcd;

    for (ll i = 1; i * i <= a; ++i) {
        if (a % i == 0) {
            acd.insert(i);
            acd.insert(a / i);
        }
    }

    for (ll i = 1; i * i <= b; ++i) {
        if (b % i == 0) {
            bcd.insert(i);
            bcd.insert(b / i);
        }
    }

    vector<ll> cd;

    for (auto t : acd) {
        if (bcd.count(t) != 0) {
            cd.push_back(t);
        }
    }

    ll ans = 0;

    for (auto t : cd) {
        if (t == 1) {
            ++ans;
            continue;
        }

        if (is_prime(t)) ++ans;
    }

    cout << ans << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
const double PI=acos(-1);

template<typename T>
istream& operator>> (istream& is, vector<T> &vec){
    for(T& x: vec) is >> x;
    return is;
}

int main(){
    ll x; cin >> x;
    if(400 <= x && x <= 599) cout << 8 << endl;
    else if(600 <= x && x <= 799) cout << 7 << endl;
    else if(800 <= x && x <= 999) cout << 6 << endl;
    else if(1000 <= x && x <= 1199) cout << 5 << endl;
    else if(1200 <= x && x <= 1399) cout << 4 << endl;
    else if(1400 <= x && x <= 1599) cout << 3 << endl;
    else if(1600 <= x && x <= 1799) cout << 2 << endl;
    else cout << 1 << endl;
    return 0;
}

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

#define rep(i, n) REP(i, 0, n)
#define repr(i, n) for (int i = (n); i >= 0; i--)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;

int main()
{
    int n;
    cin >> n;
    double ans = 0;
    rep(i, n)
    {
        double x;
        string u;
        cin >> x >> u;
        if (u == "JPY")
            ans += x;
        else
            ans += 380000 * x;
    }

    OP(ans);

    return 0;
}

Measured memory_bytes: 256
n,ma,mb=map(int,input().split())
dp=[[[10**4 for _ in range(401)] for __ in range(401)] for ___ in range(n+1)]
for i in range(n+1):
    dp[i][0][0]=0
for i in range(n):
    a,b,c=map(int,input().split())
    for j in range(401):
        for k in range(401):
            if j>=a and k>=b:
            	dp[i+1][j][k]=min(dp[i][j][k],dp[i][j-a][k-b]+c)
            else:
                dp[i+1][j][k]=dp[i][j][k]
ans=float("INF")
for j in range(1,401):
    for k in range(1,401):
        if ma*k==mb*j:
            ans=min(ans,dp[n][j][k])
if ans==10**4:
    print(-1)
else:
    print(ans)

Measured memory_bytes: 127960
h, w = map(int, input().split())
n = int(input())
l = list(map(int, input().split()))
temp = []
for i in range(n):
    for j in range(l[i]):
        temp.append(i+1)

ans = [[0 for x in range(w)] for y in range(h)]

tt = 0
for i in range(h):
    if i % 2 == 0:
        for j in range(w):
            ans[i][j] = temp[tt]
            tt+=1
    else:
        for j in range(w-1, -1, -1):
            ans[i][j] = temp[tt]
            tt+=1

for i in range(h):
    for j in range(w):
        print(ans[i][j], end=' ')
    print()


Measured memory_bytes: 9624
def is_sorted(A):
    return sorted(A) == A

def f(n,A):
    if is_sorted(A):
        return True
    for i in range(n):
        for j in range(i):
            B = A[:]
            B[i],B[j] = B[j],B[i]
            if is_sorted(B):
                return True
    return False

n = int(input())
A = [int(x) for x in input().split()]
print("YES" if f(n,A) else "NO")



Measured memory_bytes: 3060
#include <stdio.h>

int calc_digit(int c)
{
    int d;
    
    d = 0;
    do{
        c /= 10;
        d++;
    } while(c != 0);
    return d;
}

int main(){
    int i;
    int a, b;
    int ret;

    for(i = 0; i < 200; i++){
        ret = scanf("%d %d", &a, &b);
        if(ret != EOF){
            printf("%d\n", calc_digit(a + b));
        }else{
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 596
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
#define show(obj) {for(auto x:obj)cout<<x<<' ';cout<<endl;}
#define line "----------"
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> LP;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

int main(){
	int N, K;
	cin >> N >> K;
	vector<int> V(N);
	rep(i,N)cin >> V[i];
	int ans = 0;
	for(int l = -1; l < N; ++l){
		for(int r = N; r > l; --r){
			vector<int> ac;
			//cout << l << ' ' << r << endl;
			rep(i,N){
				if(i <= l || r <= i)ac.push_back(V[i]);
			}
			int rest = K - ac.size();
			if(rest < 0)continue;
			sort(all(ac));
			while(rest > 0 && ac.size() > 0){
				if(ac[0] < 0)ac.erase(ac.begin());
				--rest;
			}
			int e_sum = 0;
			for(auto x:ac)e_sum += x;
			ans = max(ans, e_sum); 
		}
	}
	cout << ans << endl;
	return 0;
}


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

int main() {
  int a, b, c;
  std::cin >> a >> b >> c;
  if (a == b) {
    std::cout << c << std::endl;
  } else if (b == c) {
    std::cout << a << std::endl;
  } else {
    std::cout << b << std::endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <stack>
#include <vector>
#include <algorithm>
#include <set>
#include <deque>
#include <utility>
#include <chrono>
#include <sstream>
#include <iomanip>
using namespace std;
#define MOD 1000000007
#define PI 3.14159265358979
#define rep(i, n) for (int (i) = 0; (i) < (int)(n); (i)++)
#define rer(i, l, r) for (int (i) = (int)(l); (i) <= (int)(r); (i)++)
#define reu(i, l, r) for (int (i) = (int)(l); (i) < (int)(r); (i)++)
#define each(i, v) for (auto i : v)
#define D(x) cout << x << endl
#define d(x) cout << x
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pub(x) push_back(x)
#define pob() pop_back()
#define puf(x) push_front(x)
#define pof() pop_front()
#define mp(x, y) make_pair((x), (y))
#define fi first
#define se second
#define setp(x) setprecision(x)
#define mset(m, v) memset(m, v, sizeof(m))
static const int INF = 0x3f3f3f3f;
static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
typedef long long ll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> pii;
typedef pair<long, long> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
template<typename T, typename U> inline void amin(T &x, U y) { if (y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if (x < y) x = y; }

//static const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
#define int ll

signed main() { 
        int n, W;
        cin >> n >> W;
        vi w(n);
        int vv;
        vi v0, v1, v2, v3;
        cin >> w[0] >> vv;
        v0.pub(vv);
        reu(i, 1, n) {
                cin >> w[i] >> vv;
                w[i] -= w[0];
                if (w[i] == 0) v0.pub(vv);
                else if(w[i] == 1) v1.pub(vv);
                else if(w[i] == 2) v2.pub(vv);
                else v3.pub(vv);
        }
        int s = w[0];
        sort(rall(v0)); rep(i, v0.size() - 1) v0[i + 1] += v0[i];
        sort(rall(v1)); rep(i, v1.size() - 1) v1[i + 1] += v1[i];
        sort(rall(v2)); rep(i, v2.size() - 1) v2[i + 1] += v2[i];
        sort(rall(v3)); rep(i, v3.size() - 1) v3[i + 1] += v3[i];
        int ans = -1; 
        rep(i, v0.size() + 1) rep(j, v1.size() + 1) rep(k, v2.size() + 1) rep(l, v3.size() + 1) {
                if (i * s + j * (s + 1) + k * (s + 2) + l * (s + 3) <= W) {
                        amax(ans, (i - 1 >=0 ? v0[i - 1] : 0) + (j - 1 >= 0 ? v1[j - 1] : 0) + (k - 1 >= 0 ? v2[k - 1] : 0) + (l - 1 >= 0 ? v3[l - 1] : 0));
                }
        }
        cout << ans << endl;
        return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <functional>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

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

int main() {
    int a, b;
    cin >> a >> b;

    int c;
    if (b < 10) c = a*10 + b;
    else if (10 <= b && b < 100) c = a*100 + b;
    else if (b == 100) c = a*1000 + b;

    REP(i, 317) {
        if (i*i == c) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define rep(i,n) for(int i=0;i<(int)(n);i++)
constexpr int INF = numeric_limits<int>::max()/2;
constexpr long long LINF = numeric_limits<long long>::max()/3;
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
template<typename T> ostream& operator<<(ostream& os,const set<T>& st){ os<<"{"; for(T v:st) os<<v<<","; os <<"}"; return os; }
template<typename T,typename U> inline void chmax(T &x,U y){ if(y>x) x = y; }
template<typename T,typename U> inline void chmin(T &x,U y){ if(y<x) x = y; }
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
//constexpr double eps = 1e-14; 
constexpr double eps = 1e-10; 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/

int main(){
    ll d,n;
    cin >> d >> n;
    if(d==0){
        ll ans = 0;
        for(int i=0;i<n;i++){
            ans += 1;
            if(ans%100==0){
                i--;
                continue;
            }
        }
        cout << ans << endl;
    }else if(d==1){
        ll ans = 0;
        for(int i=0;i<n;i++){
            ans+=100;
            if(ans%10000==0){
                i--;
                continue;
            }
        }
        cout << ans << endl;
    }else if(d=-2){
        ll ans = 0;
        for(int i=0;i<n;i++){
            ans += 10000;
            if(ans%1000000==0){
                i--;
                continue;
            }
        }
        cout << ans << endl;
    }
}


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

const int MAX = 10000;

int main() {
	int x, y;

	cin >> x >> y;
	if (x < y) {
		swap(x, y);
	}
	while (x % y) {
		int temp = y;
		y = x % y;
		x = temp;
	}

	cout << y << endl;

	return 0;
}

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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define LCM(a, b) (a) / __gcd((a), (b)) * (b)
#define CEIL(a, b) (a)/(b)+(((a)%(b))?1:0)
#define log_2(a) (log((a)) / log(2))
#define ln '\n'

using namespace std;
using LL = long long;
using ldouble = long double;
using P = pair<int, int>;
using LP = pair<LL, LL>;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1e9 + 7;
static const int SIZE = 200005;

const int dx[] = {0, -1, 1, 0};
const int dy[] = {-1, 0, 0, 1};

vector<LL> Div(LL n) {
    vector<LL> ret;
    for(LL i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.pb(i);
            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}

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

    int N;
    cin >> N;
    int cnt[SIZE] = {};
    for(int i = 1; i < N; ++i) {
        int a;
        cin >> a;
        cnt[a]++;
    }

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



Measured memory_bytes: 4396
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }
#define dump(x) cerr<<#x<<": "<<x<<endl;
#define bit(k) (1LL<<(k))
typedef long long ll;
typedef pair<int, int> i_i;
typedef pair<ll, ll> l_l;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 >& p) {
  os << "{" <<p.first << ", " << p.second << "}";
  return os;
}
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; }

const int INF = (ll)1e9;
const ll INFLL = (ll)1e18+1;
const ll MOD = (ll)1e9+7;
const double PI = acos(-1.0);
/*
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const string dir = "DRUL";
*/

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

    ll N, K, S;
    cin >> N >> K >> S;
    if(N == K){
        rep(i,N){
            cout << S << " ";
        }
        cout << endl;
        return 0;
    }
    if(S == 1){
        rep(i,N){
            if(i < K){
                cout << 1 << " ";
            }
            else{
                cout << 2 << " ";
            }
        }
        return 0;
    }
    rep(i,K+1){
        if(i&1){
            cout << S / 2 << " ";
        }
        else{
            cout << S - S / 2 << " ";
        }
    }
    rep(i,N-K-1){
        cout << (S + 1)%INF + 1 << " ";
    }
    cout << endl;
}

Measured memory_bytes: 1280
A, B, C, D = map(int, input().split())

lifeT = A
lifeA = C
hitT = B
hitA = D
while 1:
    lifeA -= hitT
    if lifeA <= 0:
        print('Yes')
        break
    lifeT -= hitA
    if lifeT <= 0:
        print('No')
        break

Measured memory_bytes: 8992
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
typedef vector<int> vi;
typedef queue<int> qi;
typedef long long ll;
typedef pair<int, int> pii;
typedef double db;
const int N = 1e5 + 5;
struct edge
{
	int y, nxt;
}e[N * 4];
int p[N], ans[N];
int eid;

void add(int x, int y)
{
	e[eid] = edge{y, p[x]}; p[x] = eid ++;
}
void bfs()
{
	qi q;
	ans[1] = -1;
	q.push(1);
	while (q.size())
	{
		int x = q.front(); q.pop();
		for (int i = p[x]; ~i; i = e[i].nxt)
		{
			int y = e[i].y;
			if(ans[y]) continue;
			ans[y] = x;
			q.push(y);
		}
	}
}
int main()
{
	int n, m; scanf("%d%d", &n, &m);
	memset(p, -1, sizeof(p));
	for (int i = 1; i <= m; ++ i)
	{
		int x, y; scanf("%d%d", &x, &y);
		add(x, y);
		add(y, x);
	}
	for (int i = 1; i <= n; ++ i)
		if(p[i] == -1)
		{
			puts("No");
			return 0;
		}
	bfs();
	puts("Yes");
	for (int i = 2; i <= n; ++ i) printf("%d\n", ans[i]);
	return 0;
}


Measured memory_bytes: 7728
#include<bits/stdc++.h>
#define Tp template<typename Ty>
#define Ts template<typename Ty,typename... Ar>
#define Reg register
#define RI Reg int
#define Con const
#define CI Con int&
#define I inline
#define W while
#define N 3000
#define DB double
using namespace std;
int n,l,a[N+5];const DB pi=acos(-1);
struct Point
{
	DB x,y;I Point() {x=y=0;}I Point(Con DB& a):x(cos(2*pi*a/l)),y(sin(2*pi*a/l)){}
	I Point(Con DB& a,Con DB& b):x(a),y(b){}
	I Point operator + (Con Point& t) Con {return Point(x+t.x,y+t.y);}
	I Point operator * (Con DB& t) Con {return Point(x*t,y*t);}
}ans;
int main()
{
	RI i,j;for(scanf("%d%d",&n,&l),i=1;i<=n;++i) scanf("%d",a+i);
	for(sort(a+1,a+n+1),i=1;i<=n;++i) for(j=i+1;j<=n;++j)
		ans=ans+Point((a[i]+a[j])/2.0)*(1.0*(n-2-(j-i-1)*2)/(n-2));
	return ans=ans*(6.0/n/(n-1)),printf("%.10lf %.10lf",ans.x,ans.y),0;
}

Measured memory_bytes: 384
using System;
using System.Linq;

class Program
{
    static void Main()
    {
        string []marks = new string[]{"S", "H", "C", "D"};
        int [,]cards = new int[4, 13];
        
        var cards_num = int.Parse(Console.ReadLine());
        
        for(int i = 0; i < cards_num; i++){
            var arr = Console.ReadLine().Split(' ').ToArray();
            var num = int.Parse(arr[1]) - 1;
            var first_index = 3;
            
            if(arr[0].Equals(marks[0])){
                first_index = 0;
            }else if(arr[0].Equals(marks[1])){
                first_index = 1;
            }else if(arr[0].Equals(marks[2])){
                first_index = 2;
            }
            
            cards[first_index, num] = 1;
        }
        
        for(int i = 0; i < 4; i++){
            for(int l = 0; l < 13; l++){
                if(cards[i, l] == 0){
                    Console.WriteLine(marks[i]+" "+(l+1));
                }
            }
        }
        
    }
}


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

int main() {
    string s, t; cin >> s >> t;
    vector<vector<int> > A(50);
    ll ssize = s.size();
    rep(i, ssize){
        int a = s[i] - 'a';
        A[a].push_back(i);
    }

    ll ans = 0;
    int tsize = t.size();
    int now = 0;
    ll cnt = 1;
    rep(i, tsize){
        int b = t[i] - 'a';
        if(A[b].size() == 0){
            cout << -1 << endl;
            return 0;
        }
        int x = lower_bound(A[b].begin(), A[b].end(), now) - A[b].begin();
        if(x != A[b].size()){
            int k = A[b][x];
            ans += k-now + 1;
            now = k+1;
        } else {
            ans = ssize * cnt;
            cnt++;
            now = 0;
            i--;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 4236
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
	string S, T;
	cin >> S >> T;
	int N = S.size();
	bool ok = false;
	for (int i = 0; i < N; ++i) {
		S = S.substr(1) + S[0];
		if (S == T) ok = true;
	}
	cout << (ok ? "Yes" : "No") << endl;
	return 0;
}

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

using namespace std;

#define int long long
#define all(v) (v).begin(), (v).end()
#define resz(v, ...) (v).clear(), (v).resize(__VA_ARGS__)
#define reps(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)

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

using Pi = pair<int, int>;
using Ti = tuple<int, int, int>;
using vint = vector<int>;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

using ull = unsigned long long;
struct RollingHash {
  string s;
  ull base, mod;
  vector<ull> hashed, power;
  RollingHash(const string& s):s(s), base(9973ll), mod(999999937ll){
    int sz = s.size();
    hashed.resize(sz+1, 0);
    power.resize(sz+1, 0);
    power[0] = 1;
    for(int i = 0; i < sz; i++) {
      power[i+1] = power[i]*base%mod;
      hashed[i+1] = (hashed[i]*base%mod+s[i])%mod;
    }
  }
  ull get(int l, int r) {
    return (hashed[r]-hashed[l]*power[r-l]%mod+mod)%mod;
  }
  ull concat(ull h1, ull h2, int len) {
    return (h1*power[len]%mod+h2)%mod;
  }
  ull rehash(int l, int r, int i, char c) {
    if(i < l || r <= i) return get(l, r);
    //cout << r-l << " " << s.substr(l, r-l) << " " << s.substr(l, i-l) << endl;
    ull h = get(l, i);
    //cout << l << " " << r << " " << i << " " << c <<  " " << h << endl;
    h = (h*base%mod + c)%mod;
    return concat(h, get(i+1, r), r-(i+1));
  }
};

signed main()
{
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  string s;
  cin >> s;
  RollingHash rh(s);

  int q;
  cin >> q;
  while(q--) {
    int l, r, t;
    cin >> l >> r >> t;
    --l;
    if(rh.get(l, r-t) == rh.get(l+t, r)) {
      cout << "Yes" << endl;
      continue;
    }
    int lb = 0, ub = r-l+1;
    while(lb+1 < ub) {
      int mb = (lb+ub)/2;
      //assert(l+t+mb <= s.size());
      if(l+t+mb <= (int)s.size() && rh.get(l, l+mb) == rh.get(l+t, l+t+mb)) lb = mb;
      else ub = mb;
    }
    //cout << rh.get(l, l+lb) << " " << rh.get(l+t, l+t+lb) << endl;
    //cout << lb << " " << s[l+lb] << " " << s[l+t+lb] << endl;
    //cout << rh.rehash(l, r-t, l+lb, s[l+lb]) << " " << rh.get(l, r-t) << endl;
    //cout << rh.rehash(l+t, r, l+t+lb, s[l+lb]) <<  " " << rh.get(l+t, r) << endl;
    if((rh.rehash(l, r-t, l+lb, s[l+t+lb]) == rh.rehash(l+t, r, l+lb, s[l+t+lb])) ||
       (rh.rehash(l, r-t, l+t+lb, s[l+lb]) == rh.rehash(l+t, r, l+t+lb, s[l+lb]))) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 4852
#include <bits/stdc++.h>
#define fi first
#define se second
#define eb emplace_back
#define all(v) (v).begin(), (v).end()
#define rmin(r, x) r = min(r, x);
#define rmax(r, x) r = max(r, x);
#define ends ' '
#define endl '\n'
#define fastio ios_base::sync_with_stdio(0), cin.tie(0)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int maxh = 2e5 + 10;
const int maxw = 2e5 + 10;

int h, w;
int a[maxh], b[maxh], d[maxw];
priority_queue<pii> pq;
set<pii> st;

int main(void) {
    fastio;
    cin >> h >> w;
    for(int i = 1; i <= h; ++i) cin >> a[i] >> b[i];
    for(int i = 1; i <= w; ++i) {
        pq.push({-d[i], i});
        st.insert({i, d[i]});
    }
    for(int i = 1; i <= h; ++i) {
        auto it = st.lower_bound(pii(a[i], -1));
        pii la = pii(-1, -1);
        while(it != st.end() && it->fi <= b[i]) {
            la = *it;
            d[it->fi] = -1;
            it = next(it);
            st.erase(prev(it));
        }
        if(la.fi != -1) {
            int j = b[i] + 1;
            if(j <= w && (d[j] == -1 || la.se + (j - la.fi) < d[j])) {
                d[j] = la.se + (j - la.fi);
                pq.push({-d[j], j});

                it = st.lower_bound(pii(j, -1));
                if(it != st.end() && it->fi == j)   st.erase(it);
                st.insert({j, d[j]});
            } 
        }
        while(!pq.empty() && d[pq.top().se] != -pq.top().fi)    pq.pop();
        if(pq.empty()) {
            cout << -1 << endl;
            continue;
        }
        cout << -pq.top().fi + i << endl;
    }
    return 0;
}


Measured memory_bytes: 16628
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#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 T1, typename T2> T1 pow_(T1 a, T2 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; if (a >= mod) a -= mod; }


void solve();

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

int n, m, q;
vector<int> a, b, c, d;
ll ans = 0;

void dfs(vector<int> A) {
  // cerr << A << endl;
  if (sz(A) == n) {
    ll sum = 0;
    rep(i, q) {
      if (A[b[i]] - A[a[i]] == c[i]) sum += d[i];
    }
    chmax(ans, sum);
    return;
  }
  rep3(i, (sz(A) == 0 ? 1 : A.back()), m + 1) {
    A.eb(i);
    dfs(A);
    A.pop_back();
  }
}
void solve() {
  cin >> n >> m >> q;
  a.resize(q); b.resize(q); c.resize(q); d.resize(q);
  rep(i, q) {
    cin >> a[i] >> b[i] >> c[i] >> d[i];
    a[i]--; b[i]--;
  }
  vector<int> A;
  dfs(A);
  cout << ans << endl;
}


Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
//INSERT ABOVE HERE
signed main(){
  Int n,k;
  cin>>n>>k;
  vector<set<Int> > vs(k);
  for(Int i=0;i<k;i++){
    Int c;
    cin>>c;
    for(Int j=0;j<c;j++){
      Int x;
      cin>>x;
      vs[i].emplace(x-1);
    }
  }
  Int r;
  cin>>r;
  vector<Int> cnt(n,0);
  for(Int i=0;i<r;i++){
    Int x,y;
    cin>>x>>y;
    x--;y--;
    for(Int j=0;j<k;j++){
      if(vs[j].count(x)&&vs[j].count(y)){
	cnt[x]=1;
	cnt[y]=1;
      }
    }
  }
  
  Int ans=0;
  for(Int i=0;i<n;i++) if(cnt[i]) ans++;
  cout<<ans<<endl;
  return 0;
}



Measured memory_bytes: 3112
//#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"

#define rep(i,n) for(ll (i)=0;(i)<(ll)(n);(i)++)
#define all(x) (x).begin(),(x).end()

#define MOD 1000000007LL
#define INF (1LL<<60LL)
#define int long long
#define MAX_N (100001)
typedef long long ll;

using namespace std;

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int k, n; cin >> k >> n;
	vector<int> v(n);
	rep(i, n)cin >> v[i];
	//sort(all(v));
	int ans = v[n-1]-v[0];
	rep(i, n-1) {
		ans = min(ans, k - (v[i + 1] - v[i]));
	}
	cout << ans << endl;
}

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

int main(void){
    int n,c,k;
    cin >> n >> c >> k;
    vector<int> vec(n);
    for(int i=0;i<n;i++) cin >> vec.at(i);
    sort(vec.begin(),vec.end());

    int bus=0,people=0;
    for(int i=0;i<n;){
        //cout << vec.at(i) << endl;
        //if(i==n-1){bus++; break;}   //最終乗客=第一乗客のときは専用バスあげて終了

        int p0 = vec.at(i); //第一乗客の時刻
        while(vec.at(i)-p0<=k && people<c){
            if(i==n-1){i++; break;} //for条件から追い出し終了
            people++;   //人乗せる
            i++;        //時間送る
        }
        bus++;
        people = 0;
    }

    cout << bus << endl;
}

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

ll fun(ll i,ll sz, ll n, ll w, vector<vector<ll>> wv, vector<vector<ll>> dp)
{
    if(i==sz)
    {
        return 0;
    }
    if(n<0)
    {
        return 0;
    }
    if(dp[i+1][n+1]>0)  return dp[i+1][n+1];
    int a=  (fun(i+1,sz,n-wv[i][0],w,wv,dp)+wv[i][1]);
    int b=fun(i+1,sz,n,w,wv,dp);
    dp[i+1][n+1]=max(a,b);
    return dp[i+1][n+1];
}

int main()
{
    ll n,w;
    cin>>n>>w;
    vector<vector<ll>> wv(n,vector<ll> (2,0));
    for(int i=0;i<n;i++)
    {
        cin>>wv[i][0]>>wv[i][1];
    }
    vector<vector<ll>> dp(n+1,vector<ll> (w+1,0));
    for(int i=1;i<n+1;i++)
    {
        for(int j=1;j<w+1;j++)
        {
            if(j-wv[i-1][0]>=0)
                dp[i][j]=max(dp[i-1][j],wv[i-1][1]+dp[i-1][j-wv[i-1][0]]);
            else
                dp[i][j]=dp[i-1][j];
            // cout<<dp[i][j]<<" ";
        }
        // cout<<endl;
    }
  
    cout<<dp[n][w]<<endl;
}

Measured memory_bytes: 83092
import java.util.Scanner;
import java.util.StringTokenizer;

/**
 * Affine Cipher
 */
public class Main {

	static final int[] alpha = {1, 3, 5, 7, 9, 11, 15, 17, 19, 21, 23, 25};
	static final int beta = 26;
	static final char[][] hint = {{'t', 'h', 'i', 's'}, {'t', 'h', 'a', 't'}};

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();

		sc.nextLine();
		for (int i = 0; i < n; i++) {
			String s = sc.nextLine();
			int[] c = cipher(s);
			char[] d = new char['z' + 1];
			for (char j = 'a'; j <= 'z'; j++) {
				d[(char) (((c[0] * (j - 'a') + c[1]) % 26) + 'a')] = j;
			}
			StringBuilder sb = new StringBuilder();
			for (int j = 0; j < s.length(); j++) {
				if (s.charAt(j) == ' ') {
					sb.append(' ');
				} else {
					sb.append(d[s.charAt(j)]);
				}
			}
			System.out.println(sb.toString());
		}
	}

	static int[] cipher(String s) {

		StringTokenizer st = new StringTokenizer(s);

		int[] ret = new int[2];

		while (st.hasMoreTokens()) {

			String w = st.nextToken();

			if (w.length() == 4) {
				outer:
				for (int a = 0; a < alpha.length; a++) {
					for (int b = 0; b < beta; b++) {
						String thi = "";
						String tha = "";
						for (int i = 0; i < hint[0].length; i++) {
							thi += (char) (((alpha[a] * (hint[0][i] - 'a') + b) % 26) + 'a');
							tha += (char) (((alpha[a] * (hint[1][i] - 'a') + b) % 26) + 'a');
						}
						if (w.equals(thi) || w.equals(tha)) {
							ret[0] = alpha[a];
							ret[1] = b;
							break outer;
						}
					}
				}
			}
		}

		return ret;
	}
}

Measured memory_bytes: 44620
#include <bits/stdc++.h>
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define ALL(v) v.begin(), v.end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define INF 1e9
using namespace std;
typedef long long ll;
static const ll MOD = 1000000007LL;

signed main() {
  // std::ifstream in ("input.txt"); std::cin.rdbuf(in.rdbuf());
  int n, d;
  cin >> n >> d;
  cout << (n - 1) / (2 * d + 1) + 1 << endl;
}



Measured memory_bytes: 256
#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 riverse(v) reverse((v).begin(), (v).end())
using vi = vector<int>;
using vs = vector<string>;
using vvi = vector<vi>;
using vll = vector<ll>;
const int 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 N;
    cin >> N;
    vi a(N);
    rep(i, N) cin >> a[i];
    int sa = 0;
    int ans = 0;
    rep(i, N) {
        if (a[i] == i + 1 - sa) continue;
        else {
            sa++;
            ans++;
        }
    }
    if (ans >= N) cout << -1 << endl;
    else cout << ans << endl;
}

Measured memory_bytes: 1024
S = gets.chomp.chars
T = gets.chomp.chars

def max(a, b) a > b ? a : b end

match = 0
0.upto(S.length - T.length) do |i|
  m = 0
  (T.length).times do |j|
    m += 1 if S[i+j] == T[j]
  end
  match = max(match, m)
end

print(T.length - match)

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

using namespace std;

using ll = long long;
using P = pair<ll,ll>;

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

#define all(x) (x).begin(), (x).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define chmin(x,y) (x=min(x,y))
#define chmax(x,y) (x=max(x,y))

//ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
int dx[4] = {1,0,-1,0};
int dy[4] = {0,1,0,-1};

const ll mod = 1e9 + 7;
const ll IMF = 1LL<<29;
const double PI = 3.14159265358979323846;


      

int dp[100005][2];

int main(){
        string s;
        cin >> s;
        int n = s.size();
        dp[0][0] = 1;
        for(int i = 0; i < n; i++){
                {//a+b = 0
                        if(s[i] == '0'){
                                dp[i+1][0] = dp[i][0];
                                dp[i+1][1] = dp[i][1];
                        }
                        else{
                                dp[i+1][1] = (dp[i][0] + dp[i][1]) % mod;
                        }
                }
                {//a+b = 1
                        if(s[i] == '0'){
                                (dp[i+1][1] += dp[i][1]*2 % mod) %= mod;
                        }
                        else{
                                (dp[i+1][0] += dp[i][0]*2 % mod) %= mod;
                                (dp[i+1][1] += dp[i][1]*2 % mod) %= mod;
                        }
                }
        }

        int ans = (dp[n][0] + dp[n][1]) % mod;
        cout << ans << endl;
        return 0;
}



Measured memory_bytes: 1280
import sys
from heapq import heapify, heappop, heappush

read = sys.stdin.read
readline = sys.stdin.readline

N, *a = map(int, read().split())
heap = [-i for i in a]
heapify(heap)
answer = 0
while True:
    if -heap[0] + answer < N:
        break
    i = -heappop(heap) + answer
    cnt = (i + 1) // (N + 1)
    i -= answer + cnt * (N + 1)
    answer += cnt
    heappush(heap, -i)
print(answer)


Measured memory_bytes: 3064
"use strict";
    
const main = arg => {
    const times = arg.split("\n").map(n=>parseInt(n));
    let min = 10;
    let sum = 0;
    
    for(let i=0; i<5; i++) {
        let digitOne = times[i] % 10;
        sum += parseInt(times[i]);
        
        if(10 - digitOne !== 10) {
            sum += 10 - digitOne;
        }
        
        if(10 - digitOne !== 10 && digitOne < min) {
            min = digitOne;
        }
    }

    console.log(parseInt(sum - (10 - min)));
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 7372
#include <bits/stdc++.h>
typedef long long ll;
int bits[20];
ll power[20];
using namespace std;
int bit;
int check(ll t)
{
	int last, now;
	bit = 0;
	while(t)
	{
		bits[bit] = t % 10;
		t /= 10;
		bit++;
	}
	for(bit--; bit >= 1; bit--)
	{
		if(abs(bits[bit] - bits[bit - 1]) > 1)
			return bits[bit] - bits[bit - 1];
	}
	return 0; 
}
int main()
{
	int k;
	scanf("%d", &k);
	power[0] = 1;
	for(int i = 1; i <= 18; i++)
	{
		power[i] = power[i - 1] * 10;
	}
	ll temp = 1;
	int add = 1;
	for(int i = 0; i < k; i++)
	{
		int t;
		while(t = check(temp))
		{
			if(t > 0)
			{
				temp /= power[bit - 1];
				temp *= power[bit - 1];
				temp += (bits[bit] - 1) * power[bit - 1];
			}
			else
			{
				temp /= power[bit];
				temp++;
				temp *= power[bit];
				temp += bits[bit] * power[bit - 1];
			}
		}
		temp++;
	}
	printf("%lld", temp - 1);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i,a,b) for (int i = (a); i < (b); i++ )
typedef pair<int,int> P;
typedef long long ll;
const int INF = 100000000;
const double PI=3.14159265358979323846;

int main (){
    ll N, M;
    cin >> N >> M;;
    vector<vector<ll>> A(M,vector<ll>(2));
    rep(i,0,M) {
        cin >> A[i][0] >> A[i][1];
    }

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

    ll tmp = INF;

    ll ans = 0;

    rep(i,0,M-1) {
        if (A[i][1]<tmp) {
            tmp = A[i][1];
        }
        if (A[i+1][0]>=tmp) {
            ans++;
            tmp = INF;
        }

    }
    ans++;

    cout << ans << endl;

}





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

typedef long long int ll;
ll powk(ll a, ll n = 2){
    ll r = 1;
    for(ll i = 0;i < n;i++){
        r *= a;
    }

    return r;
}


int main()
{
    ll n;
    cin >> n;
    ll ans = 0;
    for(ll i = 1;i * i <= n;i++){
        if(n % i == 0){
            ans = n / i;
        }
    }

    string s = to_string(ans);

    cout << s.size();

    return 0;
}

Measured memory_bytes: 256
<?php
list($N, $M, $Q) = array_map(function ($n) {
    return (int)$n;
}, explode(' ', fgets(STDIN)));

$pair = [];
for ($i = 0; $i < (int)$Q; $i++) {
    list($a, $b, $c, $d) = array_map(function ($n) {
        return (int)$n;
    }, explode(' ', fgets(STDIN)));
    // if ($c < $b - $a) {
    $pair[$i] = [$a, $b, $c, $d];
    // }
}

$ans = 0;
dfs([0, 1], $ans);
echo $ans;

function dfs($A, &$ans) {
    $copy_A = $A;
    global $N, $M, $pair;
    if (count($copy_A) === $N + 1) {
        $point = 0;
        foreach ($pair as [$a, $b, $c, $d]) {
            $point += $copy_A[$b] - $copy_A[$a] === $c ? $d : 0;
            $ans = max($ans, $point);
        }
    } else {
        for ($i = $copy_A[count($copy_A) - 1]; $i <= $M; $i++) {
            $copy_A[] = $i;
            $ans = max($ans, dfs($copy_A, $ans));
            array_pop($copy_A);
        }
    }
    return $ans;
}

Measured memory_bytes: 16204
#include <vector>
#include <bitset>
#include <map>
#include <queue>
#include <climits>
#include <algorithm>
#include <iostream>
#include <cmath>
#include <set>
using namespace std;

int dy[] = {0, 0, 1, -1};
int dx[] = {1, -1, 0, 0};

int n;
vector<vector<vector<int> > > to;
vector<bool> isToZero;

int dfs(int curr, bitset<24> bs, int toZeroNum){
    if(bs.count() == n){
        if(isToZero[curr])
            return 1;
        else
            return 0;
    }
    if(isToZero[curr]){
        -- toZeroNum;
        if(toZeroNum == 0)
            return 0;
    }

    int ret = 0;
    for(int i=0; i<4; ++i){
        unsigned j = 0;
        while(j < to[curr][i].size() && bs[to[curr][i][j]])
            ++ j;
        if(j < to[curr][i].size()){
            j = to[curr][i][j];
            bs[j] = true;
            ret += dfs(j, bs, toZeroNum);
            bs[j] = false;
        }
    }

    return ret;
}

int main()
{
    for(;;){
        int w, h;
        cin >> w >> h;
        if(w == 0)
            return 0;

        n = 1;
        vector<int> y(1), x(1);
        vector<vector<int> > grid(h, vector<int>(w));
        for(int i=0; i<h; ++i){
            for(int j=0; j<w; ++j){
                cin >> grid[i][j];
                if(grid[i][j] == 1){
                    y.push_back(i);
                    x.push_back(j);
                    grid[i][j] = n;
                    ++ n;
                }else if(grid[i][j] == 2){
                    y[0] = i;
                    x[0] = j;
                    grid[i][j] = 0;
                }else{
                    grid[i][j] = -1;
                }
            }
        }

        to.assign(n, vector<vector<int> >(4, vector<int>(0)));
        isToZero.assign(n, false);
        int toZeroNum = 0;
        for(int i=0; i<n; ++i){
            for(int j=0; j<4; ++j){
                int y1 = y[i] + dy[j];
                int x1 = x[i] + dx[j];
                while(0 <= y1 && y1 < h && 0 <= x1 && x1 < w){
                    if(grid[y1][x1] != -1){
                        int k = grid[y1][x1];
                        if(k == 0){
                            isToZero[i] = true;
                            ++ toZeroNum;
                        }else
                            to[i][j].push_back(k);
                    }
                    y1 += dy[j];
                    x1 += dx[j];
                }
            }
        }

        cout << dfs(0, 1, toZeroNum) << endl;
    }
}

Measured memory_bytes: 924
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
const int N=1e6+5;

int n,ans;
int nxt[N][26],pre[N];
int co[N];
string s[N];
vector<int> v;
bool is_end[N];

int main()
{
	cin>>n;
	int cnt=1;
	for(int i=0;i<n;i++)
	{
		cin>>s[i];
		reverse(s[i].begin(),s[i].end());
		int node=1;
		for(int j=0;j<s[i].size();j++)
		{
			if(!nxt[node][s[i][j]-'a'])
				nxt[node][s[i][j]-'a']=++cnt,co[cnt]=s[i][j]-'a';
			pre[nxt[node][s[i][j]-'a']]=node;
			node=nxt[node][s[i][j]-'a'];
		}
		v.pb(node);
		is_end[node]=1;
	}
	
	for(int i=0;i<v.size();i++)
	{
		int suffix=0;
		for(int j=v[i];j;j=pre[j])
		{
			for(int k=0;k<26;k++)
				if(suffix>>k&1 && is_end[nxt[j][k]]) ans++;
			suffix|=1<<co[j];
		}
	}
	cout<<ans-n<<'\n';
	
	return 0;
}

Measured memory_bytes: 146368
import java.util.Scanner
object Main {
  def main(args: Array[String]): Unit = {
    val sc: Scanner = new Scanner(System.in)
    val N = sc.nextInt()
    val M = sc.nextInt()
    var sum = 0
    var minV = 1 << 30
    for (i <- 0 until M) {
      val x = sc.nextInt()
      minV = math.min(minV, x)
      sum += math.max(N - x, 0)
      sc.nextInt()
    }
    sum -= N - minV
    println(sum)
  }
}

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

#define ll long long
const int N = 1000100;
char s[N];

int main() {
	 scanf("%s", s+1);
	 int now = 0, n = strlen(s+1), sum = 0, ans = 0;
	 for(int i = 1; i <= n; ++i) {
	 	now ^= 1;
	 	if(s[i] - '0' != now) ++ans;
	 }
	 now = 1;
	 for(int i = 1; i <= n; ++i) {
	 	now ^= 1;
	 	if(s[i] - '0' != now) ++sum;
	 }
	 printf("%d\n", min(ans, sum));
}

Measured memory_bytes: 384
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		
		Scanner in = new Scanner(System.in);
		
		String S = in.next();
		String T = in.next();
		
		if (T.substring(0,T.length()-1).equals(S)) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
		
	}
	
}


Measured memory_bytes: 35600
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

int main() {
#ifdef LOCAL_DEFINE
    freopen("test.in","r",stdin);
#else
    cin.sync_with_stdio(0); cin.tie(0);
#endif
	int n, h, w;
	cin >> n >> h >> w;
	cout << (n - h + 1) * (n - w  + 1) << '\n';
#ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * (double) clock() / CLOCKS_PER_SEC << " s.\n";
#endif
}


Measured memory_bytes: 256
from bisect import bisect_right

A, B, Q = map(int, input().split())
INF = 10**18
s = [-INF]
t = [-INF]
for _ in range(A):
    s.append(int(input()))
s.append(INF)
for _ in range(B):
    t.append(int(input()))
t.append(INF)
x = list(map(int, (input() for _ in range(Q))))
for y in x:
    i = bisect_right(s, y)
    j = bisect_right(t, y)
    # ans = INF
    # for S in [s[i - 1], s[i]]:
    #     for T in [t[j - 1], t[j]]:
    #         d1, d2 = abs(S - y) + abs(T - S), abs(T - y) + abs(S - T)
    #         ans = min(ans, d1, d2)
    ans = min(
        max(abs(s[i] - y), abs(t[j] - y)),
        max(abs(s[i - 1] - y), abs(t[j - 1] - y)),
        2 * min(abs(s[i] - y), abs(t[j - 1] - y)) + max(abs(s[i] - y), abs(t[j - 1] - y)),
        2 * min(abs(s[i - 1] - y), abs(t[j] - y)) + max(abs(s[i - 1] - y), abs(t[j] - y))
    )
    print(ans)

Measured memory_bytes: 16156
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define y_n(ans) cout<<(ans?"YES":"NO")<<endl;

int main() {
    long long a, v, b, w, t;
    cin >> a >> v >> b >> w >> t;
    long long dist = abs(a - b);
    bool ans;
    if (w >= v) {
        ans = false;
    } else if ((v - w) * t < dist) {
        ans = false;
    } else {
        ans = true;
    }
    y_n(ans);
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a, b; cin >> a >> b;
  cout << ((a*b)&1 ? "Odd" : "Even") << "\n";
  return 0;
}


Measured memory_bytes: 3576
n = int(input())
sp = [list(input().split()) for _ in range(n)]
for i in range(1, n+1):
    sp[i-1].append(i)
for i in range(n):
    sp[i][1] = int(sp[i][1])

a = sorted(sp, key=lambda x: (x[0], -x[1]))

for i in range(n):
    print(a[i][2])

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <map>
#include <deque>
#include <string.h>
using namespace std;

#define REP(i,n) for(int i = 0; i < n; i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;
typedef pair<string,string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pi> vpi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

double EPS = 1e-9;
int INFi = 1000000005;
long long INFll = 1000000000000000005ll;
double PI = acos(-1);
int dirx[8] = {-1,0,0,1,-1,-1,1,1};
int diry[8] = {0,1,-1,0,-1,1,-1,1};
ll MOD = 1000000007;

int N;
const int MAX_N = 100000;
int A[MAX_N];

int main(){
  cin >> N;
  int s = 0;
  REP(i, N) {
    cin >> A[i];
    if(A[i] % 2 == 1) s++;
  }

  if(s % 2 == 1) cout << "NO" << endl;
  else cout << "YES" << endl;

  return 0;
}



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

using namespace std;
const int INF = 2e9;
int _w;

int calc( int a, int b ) {
	if( b < a ) return INF;
	else return b-a;
}

int main() {
	int x, y;
	cin >> x >> y;
	int ans = calc(x, y);
	ans = min(ans, calc(x, -y) + 1);
	ans = min(ans, calc(-x, y) + 1);
	ans = min(ans, calc(-x, -y) + 2);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256