akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<limits>
#include<sstream> 
#include<unordered_map>      

using namespace std;

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

const int inf = numeric_limits<int>::max() >> 2;
const ll linf = numeric_limits<ll>::max() >> 2;
const ull ulinf = numeric_limits<ull>::max() >> 2;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int dx8[8]={-1,0,1,-1,1,-1,0,1};
const int dy8[8]={-1,-1,-1,0,0,1,1,1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define umap(i,j) unordered_map<i,j>
#define P(p) cout<<(p)<<endl
#define PS(p) cout<<(p)<< " "
#define PN cout << endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i = (n-1); i >= (int)(m); i--)
#define inrep(n,a) for(int i = 0; i < (int)(n); i++)cin >> a[i];
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end())
#define rvsort(v,c) sort(v.begin(), v.end(), greater<c>()) 
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - (a)) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define ub(a,n,k) (upper_bound(a,a+n,k) - (a)) 
#define vub(a,k)  (upper_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

/*
ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
*/

/*
vector<string> split(const string &str, char sep){
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}
*/

/*
ll ncr[100][100];
ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

ll npr[100][100]={};
ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

ll nHr(int n,int r){ret nCr(n+r-1,r);}
*/

///////////////////////////////////////////////////////////////////////////

ll n;

int main(){

   
    cin >> n;

    ll ans = n-1;
    rep(i,2,sqrt(n)+1){
	if(n % i == 0){
	    ans = min(ans,(i-1) + (n/i)-1);
	}
    }

    P(ans);
    return  0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod=1e9+7;

int main(){
    int N, K, ans;
    cin >> N >> K;
    ans = N - K;
    if(K==1){
        cout << 0;
    }else{
        cout << ans;
    }
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
using namespace std;
int v[100000+5];
int main() {
    int n;
    scanf("%d",&n);
    for (int i = 1; i <=n; ++i) {
        scanf("%d",&v[i]);
    }
    sort(v+1,v+1+n);
    if(n%2==0)
            printf("%d\n",v[n/2+1]-v[n/2]);
    else
        printf("0\n");
    //std::cout << "Hello, World!" << std::endl;
    return 0;
}

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

int main(){
  string S;
  bool b=1;
  char c;
  ll K;
  cin >> S >> K;
  for(int i=0;i<K;++i){
    if(S.at(i)!='1'){
      c = S.at(i);
      b=0; break;
    }
  }
  if(b){
    cout << '1' << endl;
  }else{
    cout << c << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,l,r) for (int i=l;i<=r;i++)
using namespace std;
typedef unsigned long long ull;
map<pair<ull,ull>,int > mp;
int n;
char s[55];
ull ans;
int main(){
	scanf("%d%s",&n,s);
	rep(i,0,(1<<n)-1){
		ull a=0,b=0;
		rep(j,0,n-1) if (i&(1<<j)) a=a*233+s[j];
		for (int j=n-1;j>=0;j--) if ((i&(1<<j))==0) b=b*233+s[j];
		mp[make_pair(a,b)]++;
	}
	rep(i,0,(1<<n)-1){
		ull a=0,b=0;
		rep(j,0,n-1) if (i&(1<<j)) a=a*233+s[j+n];
		for (int j=n-1;j>=0;j--) if ((i&(1<<j))==0) b=b*233+s[j+n];
		ans+=mp[make_pair(b,a)];	
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 33024
#include <bits/stdc++.h>
#define INF 2000000000
using namespace std;
typedef long long ll;
int read(){
    int f = 1, x = 0;
    char c = getchar();
    while(c < '0' || c > '9'){if(c == '-') f = -f; c = getchar();}
    while(c >= '0' && c <= '9')x = x * 10 + c - '0', c = getchar();
    return f * x; 
}
ll a, b, n;
void init(){
    cin >> a >> b >> n;
}
void solve(){
    if (n >= b - 1){
        cout << (a * (b - 1) / b) << endl;
    }else {
        cout << (a * n / b) << endl;
    }
}
int main(){
    init();
    solve();
    return 0;
}

Measured memory_bytes: 3636
using System;
using System.Linq;
using System.Collections.Generic;

class P
{
    static void Main()
    {
        int[] WHN = Console.ReadLine().Split().Select(int.Parse).ToArray();
        int xuplim = WHN[0];
        int xdnlim = 0;
        int yuplim = WHN[1];
        int ydnlim = 0;
        int[][] xyas = new int[WHN[2]][].Select(_ => Console.ReadLine().Split().Select(int.Parse).ToArray()).ToArray();

        foreach (int[] xya in xyas)
        {
            switch (xya[2])
            {
                case 1:
                xdnlim = Math.Max(xdnlim,xya[0]);
                break;
                case 2:
                xuplim = Math.Min(xuplim, xya[0]);
                break;
                case 3:
                ydnlim = Math.Max(ydnlim, xya[1]);
                break;
                case 4:
                yuplim = Math.Min(yuplim, xya[1]);
                break;
            }
        }
        Console.WriteLine(Math.Max((xuplim - xdnlim),0) * Math.Max((yuplim - ydnlim), 0));

    }
}

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

#define int long long
using namespace std;
#define rep(i, n) for(int i=0;i<(n);++i)
typedef pair<int, int> pii;
const int INF = 1l << 60;
#define u_b upper_bound
#define l_b lower_bound

int N, K;
int A[550];

int B[550];

bool f(int x) {
    int bsum = 0;
    rep(i, N) {
        B[i] = A[i] / x * x - A[i];
        bsum += B[i];
    }
    if (bsum % x != 0)return false;
    sort(B, B + N);


    int tmp = -bsum / x;
    if (x == 5)cerr << tmp << endl;
    int psum = 0;
    rep(j, tmp) {
        B[j] += x;
        psum += B[j];
        if (x == 5)cerr << j << " " << bsum << endl;
        if (psum > K)return false;
    }
    if (x == 5)cerr << bsum << endl;
    return true;
}

signed main() {
    cin >> N >> K;
    int s = 0;
    rep(i, N) {
        cin >> A[i];
        s += A[i];
    }

    f(5);

    for (int i = 1; i * i <= s; ++i) {
        if (s % i != 0)continue;
        if (f(s / i)) {
            cout << s / i << endl;
            return 0;
        }
    }
    for (int i = sqrt(s); i >= 1; --i) {
        if (s % i != 0)continue;
        if (f(i)) {
            cout << i << endl;
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 256
N = int(input())
H = list(map(int, input().split()))
         
# N = 4
# H = [10,30,40,20]
         
table = [0]*N
flag = [[False]*N]

for i in range(1, N):
#     print(i)
    if i == 1:
        table[i] = table[i-1] + abs(H[i-1]-H[i])
    else:
        table[i] = min(
            table[i-2] + abs(H[i-2]-H[i]),
            table[i-1] + abs(H[i-1] - H[i])
        )
#     print(table)

print(table[-1])

Measured memory_bytes: 52208
#include <stdio.h>
#include <string.h>

int main(void) {
	int n, i;
	int ayaneru = 0, asumisu = 0;
	char tomatu[128], sumipe[128];
	if (scanf("%d", &n) != 1) return 1;
	for (i = 0; i < n; i++) {
		int mareitaso;
		if (scanf("%127s%127s", tomatu, sumipe) != 2) return 1;
		mareitaso = strcmp(tomatu, sumipe);
		if (mareitaso > 0) ayaneru += 3;
		else if (mareitaso < 0) asumisu += 3;
		else ayaneru++, asumisu++;
	}
	printf("%d %d\n", ayaneru, asumisu);
	return 0;
}



Measured memory_bytes: 2136
/*
#pragma GCC optimize("O2")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,sse,sse2,fma,tune=native")
//*/
#include <bits/stdc++.h>

using namespace std;

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

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

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

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

int n;
int a[maxn];
int b[maxn];

set < pii > st;

int32_t main(){
    migmig
    cin >> n;
    for(int i = 0 ; i < n ; i ++)
        cin >> b[i];
    for(int i = 0 ; i < n ; i ++)
        cin >> a[i],st.insert({a[i] , i});
    int cnt = 0;
    int ans = 0;
    while(cnt!=n){
        int mx = (*st.rbegin()).second;
        st.erase((*st.rbegin()));
        if(a[mx] == b[mx]){
            cnt++;
            continue;
        }
        if(a[mx] < (a[(mx-1 + n)%n] + a[(mx+1)%n]))
            dokme(-1);
        if(b[mx] >= (a[(mx-1 + n)%n] + a[(mx+1)%n])){
            a[mx] -= b[mx];
            if(a[mx] < (a[(mx-1 + n)%n] + a[(mx+1)%n]))
                dokme(-1);
            ans += a[mx] / (a[(mx-1 + n)%n] + a[(mx+1)%n]);
            a[mx]%= (a[(mx-1 + n)%n] + a[(mx+1)%n]);
            a[mx]+=b[mx];
        }
        else{
            ans += a[mx] / (a[(mx-1 + n)%n] + a[(mx+1)%n]);
            a[mx]%= (a[(mx-1 + n)%n] + a[(mx+1)%n]);
        }
        st.insert({a[mx] , mx});
    }
    cout << ans;
    return(0);
}

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


vector<pair<long long, long long>> primeFactarizor(long long n) {
  long long s = floor(sqrt(n));

  vector<pair<long long, long long>> out;
  for (int i = 2; i <= s; i++) {
    long long r = 0;
    while(n % i == 0) {
      r++;
      n /= i;
    }
    out.push_back({i, r});
  }

  if (n > s) {
    out.push_back({n, 1});
  }

  return out;
}

long long div2(long long n) {
  long long out = 0;
  long long a = 2;
  while(true) {
    if (n <= 1) break;
    out += n / a;
    n /= a;
  }
  return out;
}

long long div5(long long n) {
  long long out = 0;
  long long a = 5;
  while(true) {
    if (n <= 1) break;
    out += (n / a) / 2;
    n /= a;
  }
  return out;
}

void solver() {
  long long n;
  cin >> n;

  //vector<pair<long long, long long>> primes = primeFactarizor(n);
  if (n % 2 != 0) {
    cout << 0 << "\n";
    return;
  }

  long long ans2 = div2(n);
  long long ans5 = div5(n);
  cout << min(ans2, ans5) << "\n";

  //for (int i = 0; i < primes.size(); i++) {
  //  cout << primes[i].first << " " << primes[i].second << "\n";
  //}
}

int main() {
  solver();
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long l;
using namespace std;
l in[100][3];
vector<pair<l,l> > d;

int main()
{
    l i,j,n,m=0,a,b;
    cin>>n;
    for(i=0;i<n;i++)
    {
        cin>>in[i][0]>>in[i][1];
        for(j=0;j<i;j++)
        {
            int t1=in[i][0]-in[j][0],t2=in[i][1]-in[j][1];
            if(t1<0)t1=0-t1,t2=0-t2;
            if(t1==0&&t2<0)t2=0-t2;
            d.push_back({t1,t2});
        }
    }
    sort(d.begin(),d.end());l t=1;
    for(i=0;i<n*(n-1)/2;i++)
    {
        if(d[i].first==d[i+1].first&&d[i].second==d[i+1].second)t++;
        else t=1;
        m=max(m,t);
    }
    cout<<n-m;
}


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

int main(){
    string s;
    cin >> s;
    for(int i = 0;i+1 < s.size();i++){
        if(s[i] == s[i+1]){
            cout << i+1 << " " << i+2 << endl;
            return 0;
        }
    }
    for(int i = 0;i+2 < s.size();i++){
        if(s[i] == s[i+2]){
            cout << i+1 << " " << i+3 << endl;
            return 0;
        }
    }
    cout << -1 << " " << -1 << endl;
}

Measured memory_bytes: 512
n,m=map(int,input().split())
a=[int(input()) for i in range(m)]
mod=10**9+7
dp=[0]*(n+1)
dp[0]=1

a=set(a)
for i in range(1,n+1):
    if i in a:
        dp[i]=0
    elif i==1:
        dp[i]=1
    else:
        dp[i]=(dp[i-1]+dp[i-2])%mod
print(dp[-1])


Measured memory_bytes: 13984
#define _USE_MATH_DEFINES
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <clocale>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i, s, n) for(int i = (s), i##_len=(n); i < i##_len; ++i)
#define FORS(i, s, n) for(int i = (s), i##_len=(n); i <= i##_len; ++i)
#define VFOR(i, s, n) for(int i = (s); i < (n); ++i)
#define VFORS(i, s, n) for(int i = (s); i <= (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) FORS(i, 0, n)
#define VREP(i, n) VFOR(i, 0, n)
#define VREPS(i, n) VFORS(i, 0, n)
#define RFOR(i, s, n) for(int i = (s), i##_len=(n); i >= i##_len; --i)
#define RFORS(i, s, n) for(int i = (s), i##_len=(n); i > i##_len; --i)
#define RREP(i, n) RFOR(i, n, 0)
#define RREPS(i, n) RFORS(i, n, 0)
#define ALL(v) (v).begin(), (v).end()
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v), greater<decltype(v[0])>())
#define SZ(x) ((int)(x).size())
#define REV(x) reverse(ALL(x))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end())

using ld = long double;
using ll = long long;
using ui = unsigned int;
using ull = unsigned long long;
using Pi_i = pair<int, int>;
using Pll_ll = pair<ll, ll>;
using VB = vector<bool>;
using VC = vector<char>;
using VD = vector<double>;
using VI = vector<int>;
using VLL = vector<ll>;
using VS = vector<string>;
using VSH = vector<short>;
using VULL = vector<ull>;

const int MOD = 1000000007;
const int INF = 1000000000;
const int NIL = -1;
const double EPS = 1E-10;

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


ll gcd(ll a, ll b){
    if(!b) return a;
    if(a % b) return gcd(b, a % b);
    return b;
}

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

int gcd(int a, int b){
    if(!b) return a;
    if(a % b) return gcd(b, a % b);
    return b;
}

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

int main(){
    int N, M; cin >> N >> M;
    string S, T; cin >> S >> T;
    int g(gcd(N, M)); ll l(lcm(N, M));
    int n(N/g), m(M/g);
    bool okay(true);
    REP(i, g){
        int a(i*n), b(i*m);
        if(S[a] != T[b]) okay = false;
    }
    cout << (okay ? l : -1) << endl;
    return 0;
}


Measured memory_bytes: 512
#include <stdio.h>

int main(void) {
	int i, n, a, cnt = 0;
	
	scanf("%d", &n);
	
	for (i = 0; i < n; i++) {
		scanf("%d", &a);
		while (a % 2 == 0) {
			cnt += 1;
			a /= 2;
		}
	}
	
	printf("%d\n", cnt);
	
	return 0;
}

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

int main() {
	int A, B, C, D, E, i=0, t=0;
	// A=もともとの肉の温度,B=目的の肉の温度
	cin >> A;
	cin >> B;
	cin >> C;
	cin >> D;
	cin >> E;

	for (i = A; i <= B; i++) {
		if (i < 0) {
			t += C;
		}
		else if (i == 0) {
			t += D;
		}
		else if (i > 0) {
			t += E;
		}
	}

	if (A > 0) {
		t -= E;
	}
	cout << t << endl;
	return 0;
}


Measured memory_bytes: 3088
#include <iostream>
#include <vector>
#include <stack>
using namespace std;
using ll = long long;

struct UnionFind{
        vector<int> p;
        vector<int> size;
        vector<int> rank;

        UnionFind(int n=0) : p(n),size(n,1),rank(n,1){
                for(int i=0;i<n;++i) p.at(i) = i;
        }

        void Unite(int x, int y){
                x = Root(x); y = Root(y);
                if(x==y) return;
                if(rank.at(x)<rank.at(y)){
                        p.at(x) = y;
                        size.at(y) += size.at(x);
                }else{
                        p.at(y) = x;
                        size.at(x) += size.at(y);
                        if(rank.at(x)==rank.at(y)) ++rank.at(x);
                }
        }

        int Size(int x){
                x = Root(x);
                return size.at(x);
        }

        int Rank(int x){
                x = Root(x);
                return rank.at(x);
        }

        int Root(int x){
                return p.at(x)==x ? x : p.at(x) = Root(p.at(x));
        }
};


int main(){
        int n,m,i,a,b;
        ll cnt;
        cin >> n >> m;
        stack<pair<int,int>> st;
        UnionFind uf(n);
        for(i=0;i<m;++i){
                cin >> a >> b;
                --a; --b;
                st.push({a,b});
        }
        stack<ll> ans;
        cnt = (ll)n*(ll)(n-1)/2;
        while(!st.empty()){
                ans.push(cnt);
                a = st.top().first;
                b = st.top().second;
                st.pop();
                if(uf.Root(a)!=uf.Root(b)) cnt -= uf.Size(a)*uf.Size(b);
                uf.Unite(a,b);
        }
        while(!ans.empty()){
                cout << ans.top() << endl;
                ans.pop();
        }
        return 0;
}

Measured memory_bytes: 5416
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<cstdio>

using namespace std;

#define REP(i,n) for(int i=0;i<int(n);i++)
#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
typedef long long ll;
typedef pair<int,int> P;

int a[2030],c[110];

int main(void){
	          int i;

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

	          int N;
	          string s;
	          cin >> N >> s;

	          int ans=0;
	          for(i=0;i<N;i++){
	        	  if(i==N-1) break;
	        	  if((s[i]=='O' && s[i+1]=='X') || (s[i]=='X' && s[i+1]=='O')){
	        		  ans++;
	        		  i++;
	        	  }
	          }

	          cout << ans << endl;

	          return 0;
}



Measured memory_bytes: 3356
#include <cstdio>
#include <algorithm>
#include <stack>
#include <queue>
#include <deque>
#include <vector>
#include <string>
#include <string.h>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <map>
#include <set>
#include <iostream>
#include <sstream>
#include <numeric>
#include <cctype>
#include <bitset>
#include <cassert>
#include <random>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define gep(i,g,j) for(int i = g.head[j]; i != -1; i = g.e[i].next)
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcount
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define df(x) int x = in()
#define dame { puts("-1"); return 0;}
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,vector<T>,greater<T> >
#define bn(x) ((1<<x)-1)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
inline void priv(vi a) { rep(i,sz(a)) printf("%d%c",a[i],i==sz(a)-1?'\n':' ');}
template<typename T>istream& operator>>(istream&i,vector<T>&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(vector<T>&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>ostream& operator<<(ostream&o,vector<T>&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>ostream& operator<<(ostream&o,pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
const ll LINF = 1e18;
const double eps = 1e-10;

const int M = 17, MX = 1<<M;
vi to[MX];
int t[MX];
int ans;

int dfs(int v, int p=-1) {
  int a = 0, b = 0;
  rep(i,sz(to[v])) {
    int u = to[v][i];
    if (u == p) continue;
    int r = dfs(u,v);
    b |= a&r;
    a |= r;
  }
  a |= t[b]-1; ++a;
  return a;
}

int main() {
  int n;
  scanf("%d",&n);
  rep(i,n-1) {
    int a,b;
    scanf("%d%d",&a,&b);
    --a; --b;
    to[a].pb(b);
    to[b].pb(a);
  }
  rep(i,M) for (int j = 1<<i>>1; j < (1<<i); ++j) t[j] = 1<<i;
  int x = dfs(0);
  int ans = -1;
  while (x) ++ans, x >>= 1;
  cout<<ans<<endl;
  return 0;
}































Measured memory_bytes: 11264
#include<iostream>
using namespace std;
int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    if(a+b==c||b+c==a||c+a==b)
    {
        cout<<"Yes";
    }
    else
    {
        cout<<"No";
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 1000000007
#define rep(i, N) for(ll i = 0; i < N; i++)
#define rep2(i, j, k) for(ll i = j; i < k; i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define print(x) cout << x << "\n"
#define print2(x, y) cout << x << " " << y << "\n"
#define printv(vec) rep(lp, vec.size()) cout << vec[lp] << " "; print(""); 
#define ALL(v) v.begin(), v.end()
#define SUM(v) accumulate(ALL(v), 0)
#define MAX(v) *max_element(ALL(v))
#define MIN(v) *min_element(ALL(v))
#define SORT(v) sort(ALL(v))
#define REV(v) reverse(ALL(v))
typedef long long ll;
using namespace std;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vs = vector<string>;

const int mod = 998244353;
class mint {
public:
    ll x;
    mint(ll x = 0) : x((x % mod + mod) % mod) {}
    mint operator-() const { 
      return mint(-x);
    }
    mint& operator+=(const mint& a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint& a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const  mint& a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint& a) const {
        mint res(*this);
        return res += a;
    }
    mint operator-(const mint& a) const {
        mint res(*this);
        return res -= a;
    }
    mint operator*(const mint& a) const {
        mint res(*this);
        return res *= a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }
    mint inv() const {
        return pow(mod - 2);
    }
    mint& operator/=(const mint& a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint& a) const {
        mint res(*this);
        return res /= a;
    }
    friend ostream& operator<<(ostream& os, const mint& m){
        os << m.x;
        return os;
    }
};

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

void Main(){

	ll N, X, M;
	cin >> N >> X >> M;
	
	vl acc(1);
	map<ll, ll> mp;
	ll ans = 0;

	rep(i, N){

		if(mp[X]){
			if(X == 0){
				print(ans);
				return;
			}
			ll bef = mp[X];
			ll loop = i - bef;
			ll cnt = (N - i) / loop;
			ll accs = acc[i] - acc[i - loop];
			ll mod = (N - i) % loop;
			ans = (ans + accs * cnt + acc[bef + mod] - acc[bef]);
			/*
			printv(acc);
			print(loop);
			print(cnt);
			print(bef);
			print(accs);
			print(mod);
			*/
			break;
		}

		mp[X] = i;
		ans += X;
		acc.push_back(acc[i] + X);
		X = (X * X) % M;
	}

	print(ans);	

}

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





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

#define ll long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define dbg(x) cerr << #x << ": " << x << endl;
#define dbg2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define dbg3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define dbgB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

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

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }

template<typename T>
void printA(vector<T> &printArray, char between = ' ') {
   int paSize = printArray.size();
   for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
   if (between != '\n') {cerr << endl;}
}

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

int N, W;
int v[111], w[111];
int dp[111][111111];

int main() {
   cin >> N >> W;
   rep (i, N) {
      cin >> v[i] >> w[i];
   }

   rep (i, N) {
      for (int j = 0; j <= W; j++) {
         dp[i+1][j] = max(dp[i+1][j], dp[i][j]);
         if (j + w[i] <= W) {
            dp[i+1][j+w[i]] = max(dp[i+1][j+w[i]], dp[i][j]+v[i]);
         }
      }
   }

   cout << dp[N][W] << endl;

   return 0;
}


Measured memory_bytes: 7416
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <string>
#include <bitset>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define fin(ans) cout<<(ans)<<endl
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p,q)
#define pb(n) push_back(n)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define Sort(a) sort(a.begin(),a.end())
#define Rort(a) sort(a.rbegin(),a.rend())
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;}
const int P = 1000000007;
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;


int main(void){
  ios::sync_with_stdio(false);cin.tie(0);
  ///
  int n;
  string s;
  cin >> n;
  cin >> s;
  int ans=n;
  rep(i,n-1){
    if(s[i]==s[i+1]) ans--;
  }
  cout << ans << endl;
  ///
  return 0;
}

Measured memory_bytes: 512
#include <stdio.h>

int search(int *S,int t, int n){
    int i;
    for (i = 0;i < n;i++)
        if (S[i] == t) return 1;
    return 0;
}

int main(){
    int n, q, S[10000], T[500], i, j, c = 0;
    scanf("%d", &n);
    for (i = 0;i < n;i++) scanf("%d", S + i);
    scanf("%d", &q);
    for (i = 0;i < q;i++) scanf("%d", T + i);
    for (i = 0;i < q;i++)
        c += search(S, T[i], n);
    
    printf("%d\n", c);
    return 0;
}

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

int main(){
  int n,m,i,j,st,sh,sa,bt,bh;
  int taro[101],hanako[101];
  cin >> n >> m;

  while(n!=0||m!=0){
    st=0;sh=0;bt=-1;bh=-1;
    for(i=0;i<n;i++){
      cin >> taro[i];
      st+=taro[i];
    }
    for(i=0;i<m;i++){
      cin >> hanako[i];
      sh+=hanako[i];
    }
    sa=st-sh;
    for(i=0;i<n;i++){
      for(j=0;j<m;j++){
	if((taro[i]-hanako[j])*2==sa){
	  if(bt==-1){
	    bt=i;
	    bh=j;
	  }else{
	    if(taro[bt]+hanako[bh]>taro[i]+hanako[j]){
	      bt=i;
	      bh=j;
	    }					     
	  }
	}
      }
    }
    if(bt==-1) cout << -1 << endl;
    else cout << taro[bt] << " " << hanako[bh] << endl;
    cin >> n >> m;
  }
  return 0;
}

Measured memory_bytes: 1160
#include<cstdio>
#include<math.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<set>
#include<cstring>
 
 
using namespace std;
#define int long long int
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1001001001
#define LLINF 1001001001001001001
#define mp make_pair
#define pb push_back

int N,M;
int S,T;
int ans=0;
int MOD=1000000007;
struct dijkstra_normal{
    int V;
    int *d;
    int *d3;
    vector<pair<int,int> > *edges;
    priority_queue< pair<int,int> , vector< pair<int,int> >, greater< pair<int,int> > > q;
    dijkstra_normal(int N): V(N){
        d=new int[N];
        d3=new int[N*3];
        edges=new vector<pair<int,int> > [N];
        rep(i,N){
            d[i]=LLINF;
            d3[i]=LLINF;d3[i+N]=LLINF;d3[i+2*N]=LLINF;
        }
    }
    void push(int a,int b, int c){
        edges[a].pb( mp(b,c) );
    }
    int *solve(int start){
        q.push(mp(0,start));
        while(!q.empty()){
            pair<int,int> p=q.top();q.pop();
            int now=p.second;int cost=p.first;
            //if(d[now]<=cost)continue;
            if(d3[now+(cost%3)*N]<=cost)continue;
            d3[now+(cost%3)*N]=cost;
            rep(e,edges[now].size()){
                int to=edges[now][e].first;int cst=edges[now][e].second;
                if(d[to]>cost+cst){
                    d[to]>cost+cst;
                    q.push(mp(cost+cst,to));
                }
            }
        }
        return d3;
    }
    vector<int> return_not_use(){
        delete[] edges;
        delete[] d;
    }
};
vector< int> edges[100005];
signed main(){
    scanf("%lld %lld",&N,&M);
    dijkstra_normal dijk(N);
    rep(i,M){
        int a,b;
        scanf("%lld %lld",&a,&b); a--;b--;
        edges[a].pb(b);
        dijk.push(a,b,1);
    }
    scanf("%lld %lld",&S,&T);S--;T--;
    /*rep(i,N){
        vector<int> q1;
        q1.pb(i);
        rep(j,3){
            vector<int> q2;
            rep(cnt,q1.size()){
                int p=q1[cnt];
                rep(e,edges[p].size()){
                    q2.pb(edges[p][e]);
                }
            }
            sort(q2.begin(), q2.end());
            q2.erase(unique(q2.begin(), q2.end()), q2.end());
            q1=q2;
        }
        rep(cnt,q1.size()){
            int p=q1[cnt];
            dijk.push(i,p,1);
        }
    }*/
    int *ans=dijk.solve(S);
    if(ans[T]<LLINF&&ans[T]%3==0)printf("%lld\n",ans[T]/3);
    else printf("-1\n");
}


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

#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
const ll MOD = 1e9+7;

int main() {
    int X,A,B; cin>>X>>A>>B;
    cout<<(X-A)%B<<endl;
    return 0;
}

Measured memory_bytes: 256
Scanf.scanf "%d %d" (fun a b ->
    let rec gcd a b = if b = 0 then a else gcd b (a mod b) in

    let rec loop rest i acc =
        if rest = 1 then acc else
            if i * i > rest then acc + 1 else
                if rest mod i > 0 then loop rest (i + 1) acc else
                    let rec loop2 rest =
                        if rest mod i = 0 then loop2 (rest / i) else rest
                    in
                    loop (loop2 rest) (i + 1) (acc + 1)
    in
    loop (gcd a b) 2 1 |> Printf.printf "%d\n"
)

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


int main(){
    ll X,Y;
    cin >> X >> Y;
    ll cnt = 0;
    ll cur = X;
    while(cur <= Y){
        cur *= 2;
        cnt++;
    }
    cout << cnt << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 2000000000
using namespace std;
typedef long long ll;
int read(){
    int f = 1, x = 0;
    char c = getchar();
    while(c < '0' || c > '9'){if(c == '-') f = -f; c = getchar();}
    while(c >= '0' && c <= '9')x = x * 10 + c - '0', c = getchar();
    return f * x; 
}
int n, p;
char s[200005];
unordered_map<int, int> mp;
int poww(int a, int b){
    int res = 1;
    while (b > 0){
        if (b & 1) res = 1ll * res * a % p;
        a = 1ll * a * a % p, b >>= 1;
    }
    return res;
}
void init(){
    n = read(), p = read();
    scanf("%s", s);
}
void solve(){
    ll ans = 0;
    if (p == 2){
        for (int i = 0; i < n; ++i)
            if ((s[i] - '0') % 2 == 0)
                ans += 1ll * i + 1;
    }else if (p == 5){
        for (int i = 0; i < n; ++i)
            if ((s[i] - '0') % 5 == 0)
                ans += 1ll * i + 1;
    }else {
        int pinv = poww(10, p - 2);
        mp[0] = 1;
        int h = 0;
        for (int i = 0, acc = 1; i < n; ++i){
            acc = 1ll * acc * pinv % p;
            h = 10ll * h % p;
            h = (h + s[i] - '0') % p;
            int hh = 1ll * acc * h % p;
            if (mp.count(hh)) ans += mp[hh], mp[hh] += 1;
            else mp[hh] = 1;
        }
    }
    printf("%lld\n", ans);
}
int main(){
    init();
    solve();
    return 0;
}

Measured memory_bytes: 896
/*
    Author:zeke
    
    pass System Test!
    GET AC!!
*/
#include <iostream>
#include <queue>
#include <vector>
#include <iostream>
#include <vector>
#include <string>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <map>
#include <iomanip>
#include <utility>
#include <stack>
#include <bitset>
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rep3(var, min, max) for (ll(var) = (min); (var) < (max); ++(var))
#define repi3(var, min, max) for (ll(var) = (max)-1; (var) + 1 > (min); --(var))
#define Mp(a, b) make_pair((a), (b))
#define F first
#define S second
#define Icin(s) \
    ll(s);      \
    cin >> (s);
#define Scin(s) \
    ll(s);      \
    cin >> (s);
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef vector<V> VV;
typedef vector<P> VP;
ll mod = 1e9 + 7;
ll MOD = 1e9 + 7;
ll INF = 1e18;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    V vec(4);
    rep(i,4)cin>>vec[i];
    sort(all(vec));
    if(vec[0]==1&&vec[1]==4&&vec[2]==7&&vec[3]==9){
        cout<<"YES"<<endl;
    }else{
        cout<<"NO"<<endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define f first
#define s second
#define mp make_pair
#define sz size()
#define ll long long
int n;
bool was[3010][3010];
ll dp[3010][3010];
int a[3010];
ll calc(int l, int r) {
	if(l > r) return 0;
	if(l == r) return a[r];
	if(was[l][r]) return dp[l][r];
	was[l][r] = 1;
	dp[l][r] = max(a[l] - calc(l + 1, r), a[r] - calc(l, r - 1)); // max(áåð¸ì ïåðâûé, áåð¸ì ïîñë.)
//	cout << "podotrezok " << l << ' ' << r << " answer is " << dp[l][r] << '\n';
	return dp[l][r];
}
int main() {
	scanf("%d", &n);
	for(int i = 1; i <= n; ++i) scanf("%lld", a + i);
	ll ans = calc(1, n);
	printf("%lld", ans);
	return 0;
}

Measured memory_bytes: 80000
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>

#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 FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

int main(){


    string s1,s2;
    cin >> s1 >> s2;
    //cout << s1 << s2 << endl;
    int tmp = s1.length();

    vector<int> a(s1.length()),b(s2.length());

    for(int i = 0;i < s1.length()-1;i++){
        a[i]=s1[i+1]-s1[i];
    }
    a[s1.length()-1]=s1[0]-s1[s1.length()-1];
    for(int i = 0;i < s2.length()-1;i++){
        b[i]=s2[i+1]-s2[i];
    }
    b[s1.length()-1]=s2[0]-s2[s1.length()-1];
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());

    
    for(int i = 0;i < s1.length();i++){
        if(a[i] != b[i]){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);
//cin.tie(0);
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> plpl;
typedef tuple<ll,ll,ll> tl;
ll mod=1000000007;
ll mod2=998244353;
ll inf=1000000000000000000;
double pi=2*acos(0);
#define rep(i,m,n) for(int i=m;i<n;i++)
#define rrep(i,n,m) for(int i=n;i>=m;i--)
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
ll lmax(ll a,ll b){
    if(a<b)return b;
    else return a;
}
ll lmin(ll a,ll b){
    if(a<b)return a;
    else return b;
}
int main(){
    int n,k;cin>>n>>k;
    int a[n+1];
    vector<int> v[n+1],w[n+1];
    rep(i,1,n+1){
        cin>>a[i];
        
        if(i>1){
            v[i].push_back(a[i]);
            w[a[i]].push_back(i);
        
        }
    }
    int ans=0;
    if(a[1]!=1){
        a[1]=1;
        ans++;
    }
    queue<int> q;
    int d[n+1];
    int cnt[n+1];
    fill(cnt,cnt+n+1,0);
    fill(d,d+n+1,-1);
    rep(i,1,n+1){
        if(w[i].size()==0){
            q.push(i);
            d[i]=0;
        }
    }
    while(q.size()>0){
        int now=q.front();q.pop();
        if(now==1)continue;
        if(d[now]==k-1){
            if(a[now]!=1){
                ans++;
                d[a[now]]=max(d[a[now]],0);
                cnt[a[now]]++;
                if(cnt[a[now]]==w[a[now]].size()){
                    q.push(a[now]);
                }
            }
        }
        else{
            d[a[now]]=max(d[a[now]],d[now]+1);
            cnt[a[now]]++;
            if(cnt[a[now]]==w[a[now]].size())q.push(a[now]);
        }
    }
    cout<<ans<<endl;
    //rep(i,1,n+1)cout<<d[i]<<endl;
}


Measured memory_bytes: 12416
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n); i >= 0; i--)
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define ALL(obj) begin(obj), end(obj)
using namespace std;
using llong = long long;

const int INF = 100100100;
const int MOD = 1e9 + 7;

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

    int A, B;
    cin >> A >> B;
    if (A == B) {
        cout << A + B << endl;
    } else {
        cout << max(A, B) + max(A, B) - 1 << endl;
    }

    return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.TreeSet;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String s = br.readLine();
		String t = br.readLine();
		br.close();

		List<TreeSet<Integer>> list = new ArrayList<>(26);
		for (int i = 0; i < 26; i++) {
			list.add(new TreeSet<>());
		}

		int n = s.length();
		for (int i = 0; i < n; i++) {
			int k = s.charAt(i) - 'a';
			list.get(k).add(i);
			list.get(k).add(i + n);
		}

		long base = 0;
		int idx = -1;
		for (int i = 0; i < t.length(); i++) {
			int k = t.charAt(i) - 'a';
			Integer j = list.get(k).higher(idx);
			if (j == null) {
				System.out.println(-1);
				return;
			}
			idx = j;
			if (idx >= n) {
				base += n;
				idx -= n;
			}
		}
		System.out.println(base + idx + 1);
	}
}


Measured memory_bytes: 39632
#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(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int inf = 1001001001;
const int mod = 1000000007;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, m;
	cin >> n >> m;
	vector<int> k(m), p(m);
	vector<vector<int>> s(m);
	rep(i, m) {
		cin >> k[i];
		rep(j, k[i]) {
			int ns;
			cin >> ns;
			ns--;
			s[i].emplace_back(ns);
		}
	}
	rep(i, m) cin >> p[i];
	int ans = 0;
	rep(bit, (1 << n)) {
		int tmp = 0;
		rep(i, m) {
			int cnt = 0;
			rep(j, k[i]) {
				if (bit & (1 << s[i][j])) cnt++;
			}
			if (cnt % 2 == p[i]) tmp++;
		}
		if (tmp == m) ans++;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <unordered_map>

using namespace std;
typedef long long int ll;
typedef pair<ll, int> P;
const int INF=100;

int f[11], n;
ll p10[11];
int d[2][3628801];
int a[10], a1[10], a2[10], ct[10];
int a2v; ll a2c;

void fac(){
	f[0]=1, p10[0]=1;
	for(int i=1; i<=n; i++){
		f[i]=f[i-1]*i;
		p10[i]=p10[i-1]*10;
    }
}

void swp(int x, int y){
	a2c=a2c+(ll)(a2[y]-a2[x])*p10[x]+(ll)(a2[x]-a2[y])*p10[y];
	swap(a2[x], a2[y]);
	int c1=0, c2=0;
	for(int k=x+1; k<y; k++){
		if(a2[k]<a2[x]) c1++;
		if(a2[k]<a2[y]) c2++;
	}
	if(a2[x]<a2[y]) a2v=a2v-f[n-1-y];
	else a2v=a2v+f[n-1-x];
	a2v=a2v+(ct[y]+c1-ct[x])*f[n-1-x]+(ct[x]-c2-ct[y])*f[n-1-y];
	for(int k=x+1; k<y; k++){
		if(a2[x]<a2[k] && a2[y]>a2[k]){
			a2v-=f[n-1-k];
		}else if(a2[x]>a2[k] && a2[y]<a2[k]){
			a2v+=f[n-1-k];
		}
	}
}

int main()
{
	cin>>n;
	for(int i=0; i<n; i++){
		cin>>a[i]; a[i]--;
	}
	fac();
	for(int t=0; t<2; t++){
		ll ac=0; int aval=0;
		if(t==0){
			for(int i=0; i<n; i++){
				ac+=((ll)a[i])*p10[i];
				int ct=a[i];
				for(int j=0; j<i; j++){
					if(a[j]<a[i]) ct--;
				}
				aval+=(ct*f[n-1-i]);
			}
			if(aval==0){
				cout<<0<<endl;
				return 0;
			}
		}else{
			for(ll i=0; i<n; i++){
				ac+=(i*p10[i]);
			}
		}
		queue<ll> que;
		fill(d[t], d[t]+f[n], INF);
		d[t][aval]=0;
		que.push(ac);
		while(!que.empty()){
			ll a1c=que.front(); que.pop();
			ll a1c1=a1c;
			for(int i=0; i<n; i++){
				a1[i]=a1c1%10;
				a1c1/=10;
			}
			int a1v=0;
			for(int i=0; i<n; i++){
				ct[i]=a1[i];
				for(int j=0; j<i; j++){
					if(a1[j]<a1[i]) ct[i]--;
				}
				a1v+=(ct[i]*f[n-1-i]);
			}
			int d1=d[t][a1v];
			if(d1==4) break;
			for(int i=1; i<n-1; i++){
				for(int j=0; j<n; j++) a2[j]=a1[j];
				a2v=a1v; a2c=a1c;
				for(int j=1; (i-j>=0 && i+j<n); j++){
					swp(i-j, i+j);
					if(d[t][a2v]==INF){
						d[t][a2v]=d1+1;
						if(t==0 && a2v==0){
							cout<<d[t][a2v]<<endl;
							return 0;
						}
						que.push(a2c);
					}
				}
			}
			for(int i=0; i<n-1; i++){
				for(int j=0; j<n; j++) a2[j]=a1[j];
				a2v=a1v; a2c=a1c;
				for(int j=0; (i-j>=0 && i+j+1<n); j++){
					swp(i-j, i+j+1);
					if(d[t][a2v]==INF){
						d[t][a2v]=d1+1;
						if(t==0 && a2v==0){
							cout<<d[t][a2v]<<endl;
							return 0;
						}
						que.push(a2c);
					}
				}
			}
		}
	}
	int ans=INF;
	for(int i=0; i<f[n]; i++){
		ans=min(ans, d[0][i]+d[1][i]);
	}
	if(ans==INF){
		cout<<9<<endl;
	}else{
		cout<<ans<<endl;
	}
	return 0;
}


Measured memory_bytes: 33184
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi =vector<vi>;

int main(){
  ll A,B,C,K;
  cin >> A >> B >> C >> K;
  ll D =A+B;
  ll E =K-D;
  if(A >= K) cout << K << endl;
  else if(D >= K&&K> A) cout << A << endl;
  else if(K > D) cout << A-E << endl;
}

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

int main()
{
	int A,B,C,D,E,F;
	char a,b;
	cin>>a>>b;
	A=1;
	B=2;
	C=3;
	D=4;
	E=5;
	F=6;
	if(a<b) cout<<'<'<<endl;
	if(a>b) cout<<'>'<<endl;
	else if(a==b)cout<<'='<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>



int main() {
    int n, a, b, rez = 0;
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
        scanf("%d%d", &a, &b);
        rez += b - a + 1;
    }
    printf("%d", rez);
    return 0;
}


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

using namespace std;

int main(int argc, char *argv[]) {
	int n;
	cin >> n;
	string s[n];
	for (int i = 0; i < n; i++) {
		cin >> s[i];
	}
	
	for (int i = 0; i < n; i++) {
		sort(s[i].begin(), s[i].end());
	}
	sort(s, s + n);
	long ans = 0;
	long count = 1;
	for (int i = 1; i < n; i++) {
		if (s[i] == s[i-1]) {
			count += 1;
		} else {
			ans += count * (count-1) / 2;
			count = 1;
		}
	}
	ans += count * (count-1) / 2l;

	cout << ans << endl;
}

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


#define f(i,a,b) for(int i=(int)(a);i<=(int)(b);i++)
#define char_f(i,a) for(int i=(int)(a);(char)s[i]!='\0';i++)
#define rf(i,a,b) for(int i=(int)(a);i>=(int)(b);i--)
#define llf(i,a,b) for(long long int i=(long long int)(a);i<=(long long int)(b);i++)
#define llrf(i,a,b) for(long long int i=(long long int)(a);i>=(long long int)(b);i--)



#define ll long long
#define fi first
#define se second
#define pb push_back
#define pop pop_back
#define mem(ara) memset((ara),0,sizeof(ara))
#define memn(ara) memset((ara),-1,sizeof(ara))
#define bb begin()
#define ee end()
#define em emplace
#define eb emplace_back





#define si set<int>
#define sd set<double>
#define sll set<long long int>
#define ss set<string>
#define sc set<char>

#define pii pair<int,int>
#define pli pair<long long int,int>
#define pil pair<int,long long int>
#define pll pair<long long int,long long int>
#define pci pair<char,int>
#define pic pair<int,char>
#define pcl pair<char,long long int>
#define plc pair<long long int,char>

#define pss pair<string,string>
#define pcc pair<char,char>

#define pis pair<int,string>
#define psi pair<string,int>
#define pls pair<long long int,string>
#define psl pair<string,long long int>
#define pdd pair<double,double>
#define pcs pair<char,string>
#define psc pair<string,char>



#define vi  vector<int>
#define vll vector<long long int>
#define vd vector<double>
#define vs vector<string>
#define vc vector<char>
#define vii vector<pii>



#define mod 1000000007
#define mx (1<<30)-1
#define llmx (1ll<<62)
#define n_size 100005
#define g_size 10000005
double PI=acos(-1);
#define eps 1e-9



///unsigned int uMAX=4294967295;
///unsigned ll int ullMAX=18446744073709551615;





int arr[g_size];



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

	int n,m,T,res;

	int maxi=-mx,mini=mx,count=0;

	int i,j,k;

	bool flag;

	string s1,s2;

	char s[100000];

	int ara[n_size],ara2[n_size];

	cin>>s1;

	if(s1[0]=='1') count++;
	if(s1[1]=='1') count++;
	if(s1[2]=='1') count++;

	cout<<count<<endl;



}


Measured memory_bytes: 256