akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize (3)
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
#include<iostream>
#include<cstdio>
#include<cstring>
#include<iomanip>
#include<algorithm>
#include<unordered_map>
/*#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/hash_policy.hpp>
#include<ext/pb_ds/trie_policy.hpp>
#include<ext/pb_ds/priority_queue.hpp>*/
//#include<ext/rope>
#define ll long long
#define ull unsigned long long
#define INFI 2147483647
#define INFL 9223372036854775807
#define INFU 18446744073709551615
using namespace std;
//using namespace __gnu_pbds;
//using namespace __gnu_cxx;
const double PI=acos(-1.0);
const double eps=1e-6;
inline ll read()
{
    ll x=0,f=1;
    char ch=getchar();
    while(ch<'0' || ch>'9'){
        if(ch=='-') f=-1;
        ch=getchar();
    }
    while(ch>='0' && ch<='9'){
        x=x*10+ch-'0';
        ch=getchar();
    }
    return x*f;
}
template<typename T> void debug(T x)
{
    cout<<"value="<<x<<endl;
    return;
}
ll fpow(ll a,ll b,ll p)
{
    ll res=1;
    while(b){
        if(b&1) res=(res*a)%p;
        a=(a*a)%p;
        b>>=1;
    }
    return res;
}
signed main()
{
	//ios_base::sync_with_stdio(false);
    //cin.tie(0);
    //cout.tie(0);
	ll n=read();
	string s;
	cin>>s;
	bitset<200001>bit (s);
	//for(ll i=n-1;i>=0;i--) cout<<bit[i];
	//cout<<endl;
	ll more,les,cnt=0;
	for(ll i=0;i<=n-1;i++) if(s[i]=='1') cnt++;
	more=cnt+1;
	les=cnt-1;
	ll mod_more=0,mod_less=0;
	for(ll i=0;i<=n-1;i++){
        if(bit[i]==1){
            mod_more=(mod_more%more+fpow(2,i,more))%more;
            if(les!=0) mod_less=(mod_less%les+fpow(2,i,les))%les;
        }
	}
	for(ll i=n-1;i>=0;i--){
        ll ans=0;
        if(bit[i]==1){
            if(cnt==1) printf("0\n");
            else{
                ans=(mod_less-fpow(2,i,les)+les)%les;
                ll num=0;
                while(ans>0){
                    ans=ans%(__builtin_popcountll((unsigned ll)ans));
                    num++;
                }
                cout<<num+1<<endl;
            }
        }
        else{
            ans=(mod_more+fpow(2,i,more))%more;
            ll num=0;
            while(ans>0){
                ans=ans%(__builtin_popcountll((unsigned ll)ans));
                num++;
            }
            cout<<num+1<<endl;
        }
	}
	return 0;
}


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

using namespace std;

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

    int n,k[110];
    string s,t="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";

    while(1){
        cin>>n;

        if(n==0)break;

        for(int i=0;i<n;i++)cin>>k[i];

        cin>>s;
        int pos=0;//使うカギの番号

        for(int i=0;i<s.size();i++){
            if(s[i]>='a'&&s[i]<='z'){
                int p=s[i]-'a';
                p-=k[pos];
                if(p<0)p+=52;
                cout<<t[p];
            }
            else{
                int p=s[i]-'A'+26;
                p-=k[pos];
                if(p<0)p+=52;
                cout<<t[p];
            }
            pos++;
            pos%=n;
        }
        cout<<endl;
    }

}


Measured memory_bytes: 3176
#include <stdio.h>

void swap(int *a, int *b)
{
	int t;
	
	if (*a < *b){
		t = *a;
		*a = *b;
		*b = t;
	}
}

int main(void)
{
	int a, b, c;
	int t1, t2, t3;
	int sharp, obtuse, angle, tri;
	
	sharp = obtuse = angle = 0;
	while (scanf("%d%d%d", &a, &b, &c) != EOF){
		if (a < b){
			swap(&a, &b);
		}
		if (a < c){
			swap(&a, &c);
		}
		if (b < c){
			swap(&b, &c);
		}
		
//		printf("[%d %d %d]\n", a, b, c);
		
		if (a >= b + c){
			break;
		}
	
		if (a * a == b * b + c * c){
//printf("直角");
			angle++;
		}
		else if (a * a > b * b + c * c){
			obtuse++;
//printf("鈍角");
		}
		else {
//printf("鋭角");
			
			sharp++;
		}
	}
	
	while (scanf("%d%d%d", &a, &b, &c) != EOF);
	
	printf("%d %d %d %d\n", sharp + obtuse + angle,
							angle,
							sharp,
							obtuse);
	
	return (0);
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define fr first
#define sc second
#define ll  long long
#define mp make_pair
#define mod 1000000007

#define triplet pair<pair<int,int>,int>

using namespace std;

int a[100100];

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

    for(int i=0 ; i<n ;i ++){
        scanf("%d",&a[i]);
    }
    ll res = 0;
    for(int i=1 ;i <n ; i++){
        if(a[i] + a[i-1] > x){
            if(x < a[i-1]){
                res += a[i-1] - x;
                a[i-1] = x;
            }

            ll nw = max(x - a[i-1],0);

            res += a[i] - nw;
            a[i] = nw;
            if(a[i] + a[i-1] > x){
                nw = max(x - a[i],0);

                res += a[i-1] - nw;
                a[i-1] = nw;
            }
        }
    }
    cout<<res;
    return 0;
}


Measured memory_bytes: 768
import java.util.Scanner;
class Main {
	public static void main(String args[]){
		Scanner scan = new Scanner(System.in);
		while(scan.hasNext()){
			double a = scan.nextDouble();
			double sum = a;
			double tmp = a;
			for(int i=2;i<11;i++){
				if(i%2 == 0){
					tmp *= 2;
				}else{
					tmp /= 3;
				}
				sum += tmp;
			}
			System.out.printf("%.8f\n",sum);
		}
	}
}

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



int main() {

  int H, W;
  cin >> H >> W;

  vector<vector<char>> map(H, vector<char>(W)); 
  for(int i=0; i<H; i++){
    for(int j=0; j<W; j++){
      char c;
      cin >> c;
      map.at(i).at(j) = c; 
    }
  }

  //縦横逆になってる
  vector<vector<int>> count_tate(H, vector<int>(W));
  vector<vector<int>> count_yoko(H, vector<int>(W));

  for(int i=0; i<H; i++){
    vector<int> ls;
    int count = 0;
    for(int j=0; j<W; j++){
      if(map.at(i).at(j) == '#'){
        for(int k=0; k<ls.size(); k++){
          int l = ls.at(k);
          count_tate.at(i).at(l) = count;
        }
        count = 0;
        ls = {};
      }else if(j==W-1){
        count += 1;
        ls.push_back(j);
        for(int k=0; k<ls.size(); k++){
          int l = ls.at(k);
          count_tate.at(i).at(l) = count;
        }
        count = 0;
        ls = {};
        
      }else{
        count += 1;
        ls.push_back(j);
      }
    }
  }

//横----------------------------------------
  for(int i=0; i<W; i++){
    vector<int> ls;
    int count = 0;
    for(int j=0; j<H; j++){
      if(map.at(j).at(i) == '#'){
        for(int k=0; k<ls.size(); k++){
          int l = ls.at(k);
          count_yoko.at(l).at(i) = count;
        }
        count = 0;
        ls = {};
      }else if(j==H-1){
        count += 1;
        ls.push_back(j);
        for(int k=0; k<ls.size(); k++){
          int l = ls.at(k);
          count_yoko.at(l).at(i) = count;
        }
        count = 0;
        ls = {};
        
      }else{
        count += 1;
        ls.push_back(j);
      }
    }
  }


  int ans = 0;
  for(int i=0; i<H; i++){
    for(int j=0; j<W; j++){
      int sum = count_tate.at(i).at(j) + count_yoko.at(i).at(j);
      if(sum>ans) ans = sum;
    }
  }

  cout << ans-1 << endl;
  
}
  


Measured memory_bytes: 35712
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  if(a+b>c+d){
    cout<<"Left"<<endl;
  } else if(a+b<c+d){
    cout<<"Right"<<endl;
  } else {
    cout<<"Balanced"<<endl;
  }
}
  

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

int dp[1000005][2];

int main() {

  rep(i, 1000005) rep(j, 2) { dp[i][j] = 1001001001; }

  string S;
  cin >> S;
  reverse(S.begin(), S.end());
  // 最大桁を一つ追加
  S += '0';

  int N = S.size();
  dp[0][0] = 0;
  rep(i, N) rep(j, 2) {
    rep(a, 10) {
      int x = S[i] - '0';
      x += j;
      int b = a - x;
      int ni = i + 1;
      int nj = 0;
      if (b < 0) {
        b += 10;
        nj = 1;
      }
      dp[ni][nj] = min(dp[ni][nj], dp[i][j] + a + b);
    }
  }

  cout << dp[N][0] << endl;
}

Measured memory_bytes: 9220
#include<bits/stdc++.h>
using namespace std;
void rd(int &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
void wt_L(const char c[]){
  int i=0;
  for(i=0;c[i]!='\0';i++){
    putchar_unlocked(c[i]);
  }
}
int N, T, X, Y;
int main(){
  int Lj4PdHRW, t=0, x=0, y=0;
  rd(N);
  for(Lj4PdHRW=0;Lj4PdHRW<N;Lj4PdHRW++){
    rd(T);
    rd(X);
    rd(Y);
    t += abs(X-x) + abs(Y-y);
    if(t > T || (T-t)%2){
      wt_L("No");
      putchar_unlocked('\n');
      return 0;
    }
    t = T;
    x = X;
    y = Y;
  }
  wt_L("Yes");
  putchar_unlocked('\n');
  return 0;
}
// cLay varsion 20180108-2

// --- original code ---
// int N, T, X, Y;
// {
//   int t = 0, x = 0, y = 0;
//   rd(N);
//   rep(N){
//     rd(T,X,Y);
//     t += abs(X-x) + abs(Y-y);
//     if(t > T || (T-t)%2){
//       wt("No");
//       return 0;
//     }
//     t = T;
//     x = X;
//     y = Y;
//   }
//   wt("Yes");
// }


Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<vector>
#include<algorithm>
#include<utility>
using namespace std;
typedef pair<double, double> P;
static const int MAX_N = 100000;
static const double INF = 100000.0;

int N;
P A[MAX_N];

bool compare_y(P a, P b){
	return a.second < b.second;
}

double closest_pair(P *a, int n){
	if(n <= 1) return INF;
	int m = n / 2;
	double x = a[m].first;
	double d = min(closest_pair(a, m), closest_pair(a + m, n - m));
	inplace_merge(a, a + m, a + n, compare_y);

	vector<P> b;
	for(int i = 0; i < n; i++){
		if(fabs(a[i].first - x) >= d) continue;

		for(int j = 0; j < b.size(); j++){
			double dx = a[i].first - b[b.size() - j - 1].first;
			double dy = a[i].second - b[b.size() - j - 1].second;
			if(dy >= d) break;
			d = min(d, sqrt(dx * dx + dy * dy));
		}
		b.push_back(a[i]);
	}
	return d;
}

void solve(){
	sort(A, A + N);
	printf("%f\n", closest_pair(A, N));
}

int main(){
	scanf("%d", &N);
	for(int i = 0; i < N; i++){
		double x, y;
		scanf("%lf %lf", &x, &y);
		A[i] = make_pair(x, y);
	}
	solve();
	return 0;
}

Measured memory_bytes: 7388
local mmi, mma = math.min, math.max
local mab = math.abs
local n = io.read("*n")
local t = {}
for i = 1, n do
  t[i] = {io.read("*n")}
  t[i][2] = i
end
table.sort(t, function(a, b) return a[1] > b[1] end)
local dp = {}
for i = 1, n do
  local val, idx = t[i][1], t[i][2]
  dp[i] = {}
  for j = 1, i + 1 do
    -- j: left use count - 1
    dp[i][j] = 0
  end
  if i == 1 then
    dp[i][1] = val * (n - idx)
    dp[i][2] = val * (idx - 1)
  else
    for j = 1, i do
      -- dst: j
      dp[i][j + 1] = mma(dp[i][j + 1], dp[i - 1][j] + val * mab(idx - j))
      -- dst: n - (i - (j - 1)) + 1
      dp[i][j] = mma(dp[i][j], dp[i - 1][j] + val * mab(n - i + j - idx))
    end
  end
  -- print(table.concat(dp[i], " "))
end
local ret = 0
for i = 1, n + 1 do
  ret = mma(ret, dp[n][i])
end
print(ret)


Measured memory_bytes: 45400
#include<iostream>
#include<vector>
#include<queue>
#include<string>
#include<algorithm>
#include<map>
#include<cmath>
#include<cstring>
#include<iomanip>
#include<set>
using namespace std;

typedef long long ll;
typedef pair<int,int> P;
#define INF 1000000100
#define rep(i,n) for (int i=0;i<n;i++)

map<ll,ll> get_div_factor(ll A){
    map<ll,ll> mp;
    ll B=A;
    for(ll i=2;i<=sqrt(A);i++){
        while(B%i==0){
            B /= i;
            mp[i] += 1;
        }
    }
    if(B!=1) mp[B]++;
    return mp;
}

int main(){
    ll A,B;
    cin >> A >> B;
    map<ll,ll> mpa, mpb;
    mpa = get_div_factor(A);
    mpb = get_div_factor(B);
   
    ll ans=0;
    for(auto p:mpa){
        if(mpb[p.first]!=0) ans+=1;
    }
    ans+=1;
    cout << ans << endl;
}

Measured memory_bytes: 3180
#include<iostream>
#include<vector>

using namespace std;

int main(int argc, char* argv[])
{
    int num;
    int input;
    vector<int> inputs;
    cin >> num;
    for(int i=0;i<num;i++)
    {
        cin >> input;
        inputs.push_back(input);
    }
    for(int i=0;i<num;i++)
    {
        cout << inputs[num - 1 - i];
        if(i!=num-1)
        {
            cout << ' ';
        }
        else
        {
            cout <<endl;
        }
    }
}

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



int main(){
  string s;
  cin >>s;
  int l=s.size();
  vector<int> v={};
  for(int i=0;i<l;i++){
    if(s[i] == 'W'){
      v.push_back(i);
    }
  }
  long long int ans=0;
  int k=v.size();
  for(int i=0;i<k;i++){
    ans += v.at(i)-i;
  }
  cout << ans << endl;
}

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

''' "効率の良い" アルゴリズム

各文字について「最初の出現と最後の出現の間の切断位置」に1を、
そのほかに0を割り当てる:
(s) a b r a c a d a b r a
a: 0 1 1 1 1 1 1 1 1 1 1 0
b: 0 0 1 1 1 1 1 1 1 0 0 0
c: 0 0 0 0 0 0 0 0 0 0 0 0
d: 0 0 0 0 0 0 0 0 0 0 0 0
r: 0 0 0 1 1 1 1 1 1 1 0 0

合計を計算する:
+: 0 1 2 3 3 3 3 3 3 2 1 0

最大をとる:
3

ただし、2次元の表を作るのはまだ効率が悪いので、実際には次のようにする。
各位置について「その位置の文字が最初であって最後でないなら+1,
最後であって最初でないなら-1, さもなければ0」を割り当てる:

(s) a b r a c a d a b r a
    + + +           - - -
これは前後から「もう見た文字」以外をたどればよい。

手前から順に足していき、最大をとる:
max(1,2,3,3,3,3,3,3,2,1,0)
'''
n = int(input())
s = input()
point = [0 for _ in range(n)]

seen_forward = set()
for i, letter in enumerate(s):
    if letter not in seen_forward:
        point[i] += 1
        seen_forward.add(letter)

seen_backward = set()
for i, letter in reversed(list(enumerate(s))):
    if letter not in seen_backward:
        point[i] -= 1
        seen_backward.add(letter)

current_score, max_score = 0, 0
for p in point:
    current_score += p
    max_score = max(max_score, current_score)

print(max_score)


Measured memory_bytes: 3064
if __name__ == '__main__':
    n = int(input())
    s = list(input())
    
    #完成品の並びにする
    ss = sorted(s)
    
    cnt = 0
    #切り替わりの地点まで＝Wが見つかる部分まで
    if "W" in s:
        sind = ss.index("W")

        #sindまでに含まれるWの数？
        cnt = 0
        for i in range(sind):
            if s[i] == "W":
                cnt += 1

    print(cnt)


Measured memory_bytes: 12724
# -*- coding: utf-8 -*-
import sys
# ----------------------------------------------------------------
# Use Solve Function

def solve(lines):
    A,B,K = map(int, lines.pop(0).split(' '))
    x = min(A,B)
    res = []
    for i in range(x,0,-1):
        if A%i == 0 and B%i == 0:
            res.append(i)
    print(res[K-1])

lines = [x.strip() for x in sys.stdin.readlines()]                                                                                                            
                                                                                                                                                              
#                                                                                                                                                             
# solve !!                                                                                                                                                    
#                                                                                                                                                             
solve(lines) 

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

const double pi = 3.141592653589793238462643383279;
using namespace std;
using namespace __gnu_pbds;
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
 
 
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SQ(a) ((a)*(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
 
 
//repetition
//------------------------------------------
#define FOR(i,s,n) for(int i=s;i<(int)n;++i)
#define REP(i,n) FOR(i,0,n)
#define MOD 1000000007
 
 
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#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;
 
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)

const long double EPS = 1e-6, PI = acos((long double)-1);

//ここから編集

ll arr[101010];
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(7);


  ll N, X, M; cin >> N >> X >> M;

  vector<ll> v;
  v.push_back(X);

  arr[X] = 1;
  int cnt = 0;
  for(cnt=1; cnt<M; cnt++){
    X = (X*X)%M;
    if(arr[X] != 0) break;
    v.push_back(X);
    arr[X] = cnt+1;
  }
  /* cntは周期長を表す */
  ll k = arr[X];

  ll ans = 0;
  for(int i=0; i<k-1; i++){
    ans += v[i];
  }
  //cout << k << " " << ans << endl;
  N-=k-1;

  ll sum = 0;
  for(int i=k-1; i<v.size(); i++){
    sum += v[i];
  }

  /* cntはv.size()に等しい */
  if(cnt-k+1 == 1){
    ans += v[k-1] * N;
  }else{
    ans += sum * (N/(cnt-k+1));
    N %= (cnt-k+1);

    for(int i=k-1; i<k-1+N; i++) ans += v[i];
  }
  cout << ans << endl;



  return 0;
}

Measured memory_bytes: 4636
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>

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

typedef long long ll;

using namespace std;

const int INF = 1e9;
const int MOD = 1e9+7;
const double PI=3.14159265358979323846;

int main(){
  int N, K;
  cin >> N >> K;
  
  if(K>=N){
    cout << 0 << endl;
    return 0;
  }
  
  vector<ll> H(N);
  rep(i,N) cin >> H[i];
  sort(H.begin(),H.end(),greater<int>());
  
  ll ans=0;
  rep(i,N){
    if((i+1)<=K) continue;
    ans+=H[i];
  }
  cout << ans << endl;
}


Measured memory_bytes: 1792
#include<iostream>
#include<iomanip>

using namespace std;
int main()
{
    double w,h,x,y,a=0;
    cin >> w >> h >> x >> y;
    if((w/2)==x && (h/2)==y){
        a = 1;
    }

    cout << showpoint;
    cout << fixed;
    cout << setprecision(6);

    cout << 0.5*w*h << " " ;

    cout << noshowpoint;
    cout << setprecision(0);

    cout << a << endl;
    return 0;
}




Measured memory_bytes: 384
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
using LL = long long;
const LL LINF = 1e18;
const double EPS = 1e-10;
using namespace std;
#define COUT(v) cout<<(v)<<endl
#define CIN(n)  int(n);cin >> (n)
#define LCIN(n) LL(n);cin >> (n)
#define SCIN(n) string(n);cin >> (n)
#define YES(n) cout<<((n)? "YES" : "NO")<<endl
#define Yes(n) cout<<((n)? "Yes" : "No")<<endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) <<endl

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)

#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(obj) (obj).begin(),(obj).end()

#define P pair<LL,LL>
#define I vector<int>
#define pb(v) push_back(v)
#define V vector
#define rt return
#define rmsame(a) sort(ALL(a)),a.erase(unique(ALL(a)), a.end())
#define ENDL cout<<endl

typedef string::const_iterator State;
class PalseError {};
class Edge{
public:
    int from,to,value;
    Edge(LL a,LL b,LL c){
        from = a;
        to = b;
        value = c;
    }
    Edge(LL a,LL b){
        from = a;
        to = b;
    }
};


int main(){
    SCIN(str);SCIN(T);
    REP(a,str.size()){
        str.insert(str.begin(),str.back());
        str.pop_back();
        if(str == T){
            COUT("Yes");
            rt 0;
        }
    }
    Yes(str == T);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

const ll MOD=1e9+7;
const ll INF=1e18;

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

int main(){
    int n, m;
    while(cin>>n>>m, n){
        vector<int> maxs(n+10, 0), mins(n+10, 0);
        for(int i=0; i<m; i++){
            int s, k; cin>>s>>k;

            for(int j=0; j<k; j++){
                int c; cin>>c;
                c--;
                
                if(k==1) mins[c]+=s;

                maxs[c]+=s;
            }
        }

        int MIN=1e9, MAX=0;
        int minid, maxid;
        for(int i=0; i<n; i++){
            if(mins[i]<MIN){
                MIN=min(MIN, mins[i]);
                minid=i;
            }
            if(MAX<maxs[i]){
                MAX=max(MAX, maxs[i]);
                maxid=i;
            }
        }

        int MIN2=1e9, MAX2=0;
        for(int i=0; i<n; i++){
            if(mins[i]<MIN2 && i!=minid){
                MIN2=min(MIN2, mins[i]);
            }
            if(MAX2<maxs[i] && i!=maxid){
                MAX2=max(MAX2, maxs[i]);
            }
        }

        if(minid!=maxid) cout << MAX-MIN+1 << endl;
        else cout << max(MAX-MIN2+1, MAX2-MIN+1) << endl;
    }
}


Measured memory_bytes: 3168
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
#include<stack>
#include<cmath>
#include<iomanip>
#include<set>
#include<numeric>
#include<sstream>
#include<random>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
using pii = pair<int, int>;
const int inf = 1e9 + 7;
int dy[] = {0, 0, -1, 1, -1, 1, -1, 1};
int dx[] = {1, -1, 0, 0, -1, 1, 1, -1};
#define ceil(a, b) a / b + !!(a % b)

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    while (cin >> n && n) {
        int a[n + 1]; rrep(i, 1, n + 1) cin >> a[i]; a[0] = 0;
        int dp[n + 1]; dp[0] = 0;
        rrep(i, 1, n + 1) dp[i] = max(dp[i - 1] + a[i], a[i]);
        int larger = -inf;
        rrep(i, 1, n + 1) larger = max(larger, dp[i]);
        cout << larger << endl;
    }
}





Measured memory_bytes: 3076
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Scanner;

public class Main {


    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
    	Map<Integer, Integer> a = new HashMap<Integer, Integer>();
    	Map<Integer, Integer> b = new HashMap<Integer, Integer>();
    	int n=sc.nextInt();
    	for(int i=0;i<n/2;i++) {
    		int v=sc.nextInt();
    		if(a.containsKey(v))a.put(v, a.get(v)+1);
    		else a.put(v, 1);
    		v=sc.nextInt();
    		if(b.containsKey(v))b.put(v, b.get(v)+1);
    		else b.put(v, 1);
    	}
        //Map.Entry
        List<Entry<Integer, Integer>> list_entries = new ArrayList<Entry<Integer, Integer>>(b.entrySet());
        List<Entry<Integer, Integer>> list_entries2 = new ArrayList<Entry<Integer, Integer>>(a.entrySet());
        //Comparator(昇順)
        Collections.sort(list_entries, new Comparator<Entry<Integer, Integer>>() {
            public int compare(Entry<Integer, Integer> obj1, Entry<Integer, Integer> obj2) {
            	//昇順 return obj1.getValue().compareTo(obj2.getValue());
                 return obj2.getValue().compareTo(obj1.getValue());
            }
        });
        Collections.sort(list_entries2, new Comparator<Entry<Integer, Integer>>() {
            public int compare(Entry<Integer, Integer> obj1, Entry<Integer, Integer> obj2) {
            	//昇順 return obj1.getValue().compareTo(obj2.getValue());
                 return obj2.getValue().compareTo(obj1.getValue());
            }
        });
int ans=0;int number_a=0;
        for(Entry<Integer, Integer> entry : list_entries) {
           number_a=entry.getKey();
           ans+=n/2-entry.getValue();
           break;
        }
int ans2=0; int number_b=0;
        for(Entry<Integer, Integer> entry : list_entries2) {
            number_b=entry.getKey();
            ans2+=n/2-entry.getValue();
            break;
         }
        if(ans==0&&ans2==0&&number_a==number_b)System.out.println(n/2);
        else if(number_a!=number_b) System.out.println(ans+ans2);
        else {
        	int exans=0;int count=0;
            for(Entry<Integer, Integer> entry : list_entries) {
                if(count ==1) {
                	//number_a=entry.getKey();
                    exans+=n/2-entry.getValue();
                    break;
                }
                	count++;
             }
            int exans2=0;count=0;
            for(Entry<Integer, Integer> entry : list_entries2) {
                if(count ==1) {
                	//number_a=entry.getKey();
                    exans2+=n/2-entry.getValue();
                    break;
                }
                	count++;
             }
            System.out.println(Math.min(exans+ans2,ans+exans2));

        }
    }

}

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

int main(){
    int n;
    cin >> n;
    vector<int> b(n+1,-1);
    vector<int> ans;
    rep(i,n) cin >> b[i+1];
    rep(i,n){
        int can = -1;
        for(int j = 1; j <= n-i; j++){
            if(b[j] == j) can = j;
        }
        if(can == -1){
            cout << -1 << endl;
            return 0;
        } else {
            ans.push_back(can);
            b.erase(b.begin()+can);
        }
    }
    reverse(ans.begin(),ans.end());
    rep(i,n) cout << ans[i] << endl;
    return 0;
}

Measured memory_bytes: 256
#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet};

mod util {
    use std::io::stdin;
    use std::str::FromStr;
    use std::fmt::Debug;

    #[allow(dead_code)]
    pub fn line() -> String {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.trim().to_string()
    }

    #[allow(dead_code)]
    pub fn get<T: FromStr>() -> T
    where
        <T as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.trim().parse().unwrap()
    }

    #[allow(dead_code)]
    pub fn gets<T: FromStr>() -> Vec<T>
    where
        <T as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.split_whitespace()
            .map(|t| t.parse().unwrap())
            .collect()
    }
}

fn main() {
    let a: Vec<usize> = util::line()
        .chars()
        .map(|c| (c as u8 - 'a' as u8) as usize)
        .collect();

    let mut az: Vec<Vec<usize>> = Vec::new();

    let mut azset = HashSet::new();
    let mut v = Vec::new();

    for &c in a.iter().rev() {
        azset.insert(c);
        v.push(c);
        if azset.len() == 26 {
            az.push(v.iter().rev().cloned().collect());
            azset.clear();
            v.clear();
        }
    }

    let mut s = (0..26).find(|c| !azset.contains(&c)).unwrap();
    let mut ans = vec![s];

    for v in az.iter().rev() {
        let rest = v.iter()
            .skip_while(|&&c| s != c)
            .skip(1)
            .cloned()
            .collect::<HashSet<_>>();
        let next = (0..26).find(|c| !rest.contains(c)).unwrap();
        s = next;
        ans.push(s);
    }

    println!(
        "{}",
        ans.iter()
            .map(|&d| ('a' as u8 + d as u8) as char)
            .collect::<String>()
    );
}


Measured memory_bytes: 8444
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(int i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(int i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(int i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define uniq(x) (x).erase(unique((x).begin(), (x).end()), (x).end())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    string s;
    cin >> s;
    int cnt = 0;
    
    rep(i, s.length()) {
        if ((cnt == 0) && (s[i] == 'C')) {
            cnt++;
        }
        else if ((cnt == 1) && (s[i] == 'F')) {
            cnt++;
            break;
        }
    }
    
    cout << ((cnt == 2) ? "Yes" : "No") << endl;
    return 0;
}


Measured memory_bytes: 256
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include<bits/stdc++.h>
using namespace std;
#define rep(i,s,t) for(ll i = (ll)(s); i < (ll)(t); i++)
#define rrep(i,s,t) for(ll i = (ll)(s-1);(ll)(t) <= i; i--)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
constexpr ll INF = numeric_limits<ll>::max()/4;
constexpr ll n_max = 2e5+10;
#define int ll

template <typename A, typename B>
string to_string(pair<A, B> p);
string to_string(const string &s) {return '"' + s + '"';}
string to_string(const char *c) {return to_string((string) c);}
string to_string(bool b) {return (b ? "true" : "false");}
template <size_t N>
string to_string(bitset<N> v){
    string res = "";
    for(size_t i = 0; i < N; i++) res += static_cast<char>('0' + v[i]);
    return res;
}
template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for(const auto &x : v) {
        if(!first) res += ", ";
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}
template <typename A, typename B>
string to_string(pair<A, B> p){return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}

void debug_out() {cerr << endl;}
template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

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

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll a,b; cin >> a >> b;
    if(a + b == 15){
        cout << "+" << "\n";
        return 0;
    }
    if(a * b == 15){
        cout << "*" << "\n";
        return 0;
    }
    cout << "x" << "\n";
}

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

using namespace std;

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

//==================================

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

    string S, T;
    cin >> S >> T;
    int N = S.size();
    int M = T.size();

    vector<Vi> pos(26);
    for (int i = 0; i < N; i++) {
        int c = S[i] - 'a';
        pos[c].push_back(i);
    }

    ll ans = 0;
    ll prev = 0;
    bool ok = true;
    for (int i = 0; i < M; i++) {
        int c = T[i] - 'a';
        if (pos[c].size() == 0) {
            ok = false;
            break;
        }
        if (i == 0) {
            ans += pos[c][0];
            prev = ans;
            continue;
        }
        int idx = upper_bound(pos[c].begin(), pos[c].end(), prev) - pos[c].begin();
        if (idx == (int)pos[c].size()) {
            idx = pos[c][0];
            ans += N - prev + idx;
        }
        else {
            ans += pos[c][idx] - prev;
        }
        prev = ans % N;
    }

    if (!ok) {
        cout << -1 << endl;
    }
    else {
        cout << ans + 1 << endl;
    }

    return 0;
}

Measured memory_bytes: 1228
package main

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

var sc = bufio.NewReaderSize(os.Stdin, 1024*1024*1)

func main() {
	S := getStdin()
	A := S[0:2]
	B := S[2:]
	N, _ := strconv.Atoi(A)
	M, _ := strconv.Atoi(B)

	if (N >= 13 || N == 0) && (M >= 13 || M == 0) {
		fmt.Printf("NA\n")
	} else if (1 <= N && N <= 12) && (1 <= M && M <= 12) {
		fmt.Printf("AMBIGUOUS\n")
	} else if (1 <= N && N <= 12) && !(1 <= M && M <= 12) {
		fmt.Printf("MMYY\n")
	} else if !(1 <= N && N <= 12) && (1 <= M && M <= 12) {
		fmt.Printf("YYMM\n")
	} else {
		fmt.Printf("NA\n")
	}
}

func getStdin() string {
	return readLine()
}
func getStdinInt() int {
	str := getStdin()
	rtn, _ := strconv.Atoi(str)
	return rtn
}
func getStdinIntArr() []int {
	str := getStdin()
	list := strings.Split(str, " ")
	rtn := make([]int, len(list))
	for idx, val := range list {
		rtn[idx], _ = strconv.Atoi(val)
	}
	return rtn
}

func getStdinIntArr64() []int64 {
	str := getStdin()
	list := strings.Split(str, " ")
	rtn := make([]int64, len(list))
	for idx, val := range list {
		rtn[idx], _ = strconv.ParseInt(val, 10, 64)
	}
	return rtn
}

func readLine() string {
	buf := make([]byte, 0, 1024*1024*10)
	for {
		l, p, e := sc.ReadLine()
		if e != nil {
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}


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

int main()
{
string a,b,c; cin>>a>>b>>c;
int lenA = a.length(), lenB = b.length(), lenC = c.length();

if(a[lenA-1]==b[0] and b[lenB-1]==c[0])
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;
return 0;
}

Measured memory_bytes: 256
// ------------------------------------
// Date:2018/ 3/ 1
// Problem:ABC 056 NarrowRectanglesEasy b.cpp
//
// ------------------------------------

#include <bits/stdc++.h>

using namespace std;

#define EACH(i,a) for (auto&& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define debug(x) cerr << #x << ":" << x << endl

typedef long long ll;

static const int MOD = 1000000007;

int main()
{
  int W, a, b;
  cin >> W >> a >> b;
  cout << (abs(b - a) < W ? 0 : abs(b - a) - W) << endl;
  return 0;
}



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

int main(void)
{
    int N, M;
    cin >> N >> M;
    int L, R;
    int minRange = 1, maxRange = N;
    for (int i = 0; i < M; i++) {
        cin >> L >> R;
        minRange = max(minRange, L);
        maxRange = min(maxRange, R);
    }

    if (maxRange - minRange < 0) {
        cout << 0 << endl;
    }
    else {
        cout << maxRange - minRange + 1 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from collections import Counter # a = Counter(A).most_common()
#from itertools import accumulate #list(accumulate(A))

N, S = mi()

if not S % 2 and N * 4 >= S >= N * 2:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 61876
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<long long> vll;
typedef vector<pair<int,int>> vp;
typedef pair<int,int> pii;
#define INF (int)(1e9)
#define MAXX 1.1529215e+18
#define inf 999999
#define EPS (1e-7)
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,n) for(int i=1;i<=(int)(n);i++)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define ALL(a)  a.begin(),a.end()
#define RALL(a) a.begin(),a.end(),greater<int>()
#define ROT(a) a.begin(),a.begin()+1,a.end()
#define RROT(a) a.begin(),a.end()-1,a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
#define sz(a) a.size()
const ll MOD = 1e9+7;
const int MAX = 10000000;
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; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
//cout << 'H' << endl;
//next_permutation(ALL(p));
//typedef priority_que<int> pque;//これは大きい順
//typedef priority_que<int, vector<int>, greater<int>> pque;//これは小さい順


int main(){
	int a;
	scanf("%d",&a);
	char s[110];
	char t[110];
	scanf("%s%s",s,t);
	for(int i=0; i<a; i++){
		printf("%c%c",s[i],t[i]);
	}
	printf("\n");

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <stdio.h>
#include <stdlib.h>
using namespace std;

int main(int argc, char *argv[])
{
	int i, j;
    int n;
	int s_n = 0;
	int temp;
	char s[11];
	char now;

	cin >> s;
	n = atoi(s);

	for (i = 0; i < 11; i++) {
		if (s[i] == '\0') {
			break;
		} else {
		    for (j = 0; j < 10; j++) {
				if (s[i] == '0' + j)
					s_n += j;
			}
		}
	}

	if (n % s_n == 0)
		cout << "Yes" << "\n";
	else
		cout << "No" << "\n";

	return 0;
}

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

int main(){
  int N, M;
  cin >> N >> M;
  int L, R;
  int Lmax = 0;
  int Rmin = INF;
  rep(i, M){
    cin >> L >> R;
    Lmax = max(Lmax, L);
    Rmin = min(Rmin, R);
  }
  int res = max(Rmin - Lmax + 1, 0);
  cout << min(N, res) << endl;
}


Measured memory_bytes: 3632
# -*- coading: utf-8 -#-

A = raw_input()
B = A.split( )
C, D = int(B[0]), int(B[1])

if C == 1:
  if D == 1:
    print 'Draw'
  else:
    print 'Alice'
else:
  if D == 1:
    print 'Bob'
  else:
    if C > D:
      print 'Alice'
    elif C < D:
      print 'Bob'
    else:
      print 'Draw'


Measured memory_bytes: 2568
#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 <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
int n;
vector<int> g[150001];
bool used[150001];
double dp[150001];
int d[150001];
int s;
void dfs(int x){
    used[x]=1;
    int ct=g[x].size();
    if(x!=s) ct--;
    if(x==s || ct>0) dp[x]=1; 
    for(auto y:g[x]){
        if(!used[y]){
            d[y]=d[x]+1;
            dfs(y);
            dp[x]+=dp[y]/(double)ct;
        }
    }
}
double dp2[150001];
void dfs2(int x){
    used[x]=1;
    double sum=0;
    int ct=g[x].size()-1;
    if(x==s){
        for(auto y:g[x]){
            dp2[y]=1;
            dfs2(y);
        }
        return;
    }
    for(auto y:g[x]){
        if(used[y]) continue;
        sum+=dp[y]/(double)ct;
    }
    for(auto y:g[x]){
        if(used[y]) continue;
        dp2[y]=1+dp2[x]/(double)ct;
        dp2[y]+=(sum-dp[y]/(double)ct);
        dp2[y]+=(1-1/(double)ct);
        dfs2(y);
    }
}
int main()
{
    cin>>n;
  if(n==1){
    cout<<0<<endl; return 0;
  }
    for(int i=0; i<n-1; i++){
        int u, v; cin>>u>>v;  u--; v--;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    for(int i=0; i<n; i++){
        if(g[i].size()==1){
            s=i; break;
        }
    }
    dfs(s);
    fill(used, used+n, 0);
    dfs2(s);
    double ans[150001];
    for(int i=0; i<n; i++){
        if(i==s) ans[i]=dp[i];
        else{
            int ct=g[i].size();
            ans[i]=dp[i]/(double)ct*(double)(ct-1);
            ans[i]+=dp2[i]/(double)ct;
        }
    }
    for(int i=0; i<n; i++){
        printf("%.7lf\n", ans[i]);
    }
    return 0;
}

Measured memory_bytes: 18816
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int n, i, j, m;
    string xd;
    cin>>xd;
    n = xd.length();
    int ans = 0;
    for(i=0; i<=(n-1)/2; ++i){
        if(xd[i] != xd[n-1-i]){
            ans++;
        }
    }
    cout<<ans;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <climits>
#include <string.h>
#include <algorithm>

using namespace std;
#define fast ios::sync_with_stdio(false);cin.tie(0); cout.tie(0)
#define pb push_back
#define sz(s) (int)s.size()
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)

typedef long long ll;
typedef pair<ll, ll> pll;
const int N = 77;

ll n,s,b;

long long int f(long long int n, long long int b)
{
    if(n < b)
        return n;
    return f(n/b, b) + (n%b);
}
int main()
{
    long long int n,s;
    cin>>n>>s;
    long long int ans = LLONG_MAX;
    for (long long int b = 2; b*b - 1 < n; ++b)
    {
        if(f(n,b) == s)
            ans = min(ans, b);
    }
    
    // n = x*b + r where s = x + r, iterating over x till sqrt(n)
    
    for (long long int x = 1; x*x <= n; ++x)
    {
        long long int r = s - x;
        if(r < 0)
            break;
        long long int b = (n - r)/x;
        if(x < b && r < b && x*b + r == n)
            ans = min(ans, b);
    }
    if(n == s)
        ans = min(ans, n+1);
    if(ans == LLONG_MAX)
        ans = -1;
    cout<<ans<<"\n";
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
int main()
{
	int n;
	cin >> n;
	string s;
	vector<pair<string, int>>v;
	v.push_back(make_pair("AC", 0));
	v.push_back(make_pair("WA", 0));
	v.push_back(make_pair("TLE", 0));
	v.push_back(make_pair("RE", 0));
	for (int i = 0;i < n;i++)
	{
		cin >> s;
		if (s == "AC")
			v[0].second++;
		else if (s == "WA")
			v[1].second++;
		else if (s == "TLE")
			v[2].second++;
		else if (s == "RE")
			v[3].second++;
	}
	for (int i = 0;i < 4;i++)
	{
		cout << v[i].first << " " << "x" << " " << v[i].second;
		if (i < 3)
		{
			cout << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3600
#include<bits/stdc++.h>
using namespace std;
long long a,b,s,n,i;
int main()
{
	cin>>n;
	for(i=1;i<=n;i++)
	{
		cin>>a>>b;
		s+=b-a+1;
	}
	cout<<s;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<iomanip>
#include<map>
#include<queue>
#include<cmath>
#include<cstdio>

#define rep(i,n) for(int i=0; i<(n); ++i)
#define pai 3.1415926535897932384

using namespace std;
using ll =long long;
using P = pair<int,int>;

#define MOD 1000000007;

int main(int argc, const char * argv[]) {
    
    int N;
    ll A[200000];
    ll AA[200000];
    
    cin >> N;
    for(int i=0; i<N; i++){
        cin >> A[i];
        if(i==0) AA[i] = A[i];
        else AA[i] = (A[i] + AA[i-1]) % MOD;
    }
    
    ll Ans=0;
    for(int i=0; i<N; i++){
        Ans += (AA[i] * A[i]) % MOD;
        Ans = (Ans - A[i] * A[i]) % MOD;
        if(Ans < 0) Ans += MOD;
    }
    
    cout << Ans << endl;
    
    return 0;
}


Measured memory_bytes: 6292
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;

fn main() {
    input! {
        n: usize,
        m: usize,
        s: usize,
        uvab: [(Usize1, Usize1, usize, i64); m],
        cd: [(usize, i64); n],
    }
    let mut g = vec![vec![]; n];
    for (u, v, a, b) in uvab {
        g[u].push((v, a, b));
        g[v].push((u, a, b));
    }

    let inf = 1_000_000_000_000_000_000;
    let s = std::cmp::min(s, 2500);
    // let mut f = vec![vec![false; 2500 + 1]; n];
    let mut dp = vec![vec![inf; 2500 + 1]; n];
    dp[0][s] = 0;
    let mut q = std::collections::BinaryHeap::new();
    use std::cmp::Reverse;
    q.push((Reverse(0), 0, s));
    while let Some((t, v, s)) = q.pop() {
        let t = t.0;
        if dp[v][s] < t {
            continue;
        }
        for &(u, a, b) in &g[v] {
            if s >= a && t + b < dp[u][s - a] {
                dp[u][s - a] = t + b;
                q.push((Reverse(t + b), u, s - a));
            }
        }
        for i in 1.. {
            let s = s + i * cd[v].0;
            {
                let s = std::cmp::min(s, 2500);
                let t = t + i as i64 * cd[v].1;
                if t < dp[v][s] {
                    dp[v][s] = t;
                    q.push((Reverse(t), v, s));
                }
            }
            if s > 2500 {
                break;
            }
        }
    }
    for i in 1..n {
        println!("{}", dp[i].iter().filter(|&t| *t > 0).min().unwrap());
    }
}


Measured memory_bytes: 81236
n = int(input())
arr = [[int(i) for i in input().split()] for x in range(n)]

for i in range(n - 2, -1, -1):
    for j in range(2, -1, -1):
        q = -1
        if j == 0:
            arr[i][j] += max(arr[i + 1][1],arr[i+1][2])
        elif j == 2:
            arr[i][j] += max(arr[i + 1][1],arr[i+1][0])
        else:
            arr[i][j] += max(arr[i + 1][0], arr[i+1][2])

print(max(arr[0]))


Measured memory_bytes: 24352
#include <iostream>
#include <cstring>
using namespace std;
char s[101];
int k,x;
int main()
{
    cin >> k;
    cin.get();
    cin.getline(s,sizeof(s));
    x = strlen(s);
    for(int i = 0; i < min(k,x); ++i)
        cout << s[i];

    if(k < strlen(s))
        cout << "...";
    return 0;
}


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


int main() {
	string S;
	int n;
	cin >> S >> n;
	string ans;
	for(int i = 0; i < S.size(); i++){
		if(i % (n) == 0){
			ans += S[i ];
		}
	}
	cout << ans << endl;
}



Measured memory_bytes: 3596
n=int(input())
a=list(map(int,input().split()))
mulsum=[0]*n
cnt=0
cnt2=0
buf=0
cur=0
mulsum[0]=a[0]
for i in range(n-1):
    mulsum[i+1]=mulsum[i]+a[i+1]
#print(mulsum)
i=0
pm=[]
mp=[]
while i<n:#+-+-+-...の列を目指す
    if (mulsum[i]+buf)<=0:#a[i]+buf>0になるようbufを調整
        cur=mulsum[i]+buf
        buf=1-mulsum[i]
        cnt=cnt+(1-cur)
        #pm.append(1)
    else:
        i=i
        #pm.append(mulsum[i])
    if i==n-1:
        break
    if (mulsum[i+1]+buf)>=0:#a[i+1]+buf<0になるよう調整
        cur=mulsum[i+1]+buf
        buf=-1-mulsum[i+1]
        cnt=cnt+(1+cur)
        #pm.append(-1)
    else:
        i=i
        #pm.append(mulsum[i+1])
    i=i+2
#print(pm,cnt)
buf=0
i=0
while i<n:#-+-+-+...の列を目指す
    if (mulsum[i]+buf)>=0:#a[i]+buf<0になるようbufを調整
        cur=mulsum[i]+buf
        buf=-1-mulsum[i]
        cnt2=cnt2+(1+cur)
        #mp.append(-1)
    else:
        i=i
        #mp.append(mulsum[i])
    #print(buf,cnt2)
    if i==n-1:
        break
    if (mulsum[i+1]+buf)<=0:#a[i+1]+buf>0になるよう調整
        cur=mulsum[i+1]+buf
        buf=1-mulsum[i+1]
        cnt2=cnt2+(1-cur)
        #mp.append(1)
    else:
        i=i
        #mp.append(mulsum[i+1])
    i=i+2
    #print(buf,cnt2)
#print(mp,cnt2)
print(min(cnt,cnt2))


Measured memory_bytes: 63216
#include <iostream>
#include <algorithm>
#include <string>
#include <queue>
#include <cmath>
#include <map>
#include <iomanip>

using namespace std;
typedef long long  ll;

int main() {
	ll N, M;
	cin >> N >> M;
	if (N >= M) {
		cout << 0 << endl;
		return 0;
	}
	vector<ll> x(M);
	vector<ll> l(M - 1);
	for (ll i = 0; i < M; i++)
	{
		cin >> x[i];
	}
	sort(x.begin(), x.end());
	for (ll i = 0; i < M - 1; i++)
	{
		l[i] = x[i + 1] - x[i];
	}
	sort(l.begin(), l.end());
	reverse(l.begin(), l.end());
	ll ans = 0;
	for (ll i = 0; i < N - 1; i++)
	{
		ans += l[i];
	}
	cout << x[M - 1] - x[0] - ans << endl;
	return 0;
}

Measured memory_bytes: 1792