akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define FIN         ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ii          pair<int,int>
#define F           first
#define S           second
#define pb          push_back
#define all(x)      (x).begin(),(x).end()
#define rall(x)     (x).rbegin(),(x).rend()
#define fore(i,a,b) for(int i = a;i < b; i+= 1)
#define forr(i,a)   for(int i = a; i >= 0; i--)
#define fori(i,m)   for(auto i = m.begin(); i != m.end(); i++) 
#define w(t)        while(t--)
#define sz(s)       int(s.size())
#define cls(a,car)  memset(a,car,sizeof (a))
#define db(x)       cerr << #x << " is " << x << '\n'
#define FL          freopen("in", "r", stdin),freopen("out", "w", stdout);
#define EjecuteTime cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"
#define angle(x)    double(x * acos(-1) / 180.0)
using namespace std;
typedef long long   ll;
typedef vector<int> vi;
typedef vector<ii>  vii;
const int N = 2 * 1e5 + 5;
const ll mod = 1e9 + 7;
const double E = 1e-9;
//int dx[] = {1, 0}, dy[] = {0, 1};
//int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
//int dx[] = {2, 1, -1, -2, -2, -1, 1, 2}, dy[] = {1, 2, 2, 1, -1, -2, -2, -1};
// fflush(stdout)
// cout << flush
// a + b = a ^ b + 2 * (a & b)
string a, b;
int dp[3005][3005];
int f(int i, int j){
    if(i == sz(a) or j == sz(b))
        return 0;
    int &ans = dp[i][j];
    if(ans != -1)
        return ans;
    ans = 0;
    if(a[i] == b[j])
        ans += f(i + 1, j + 1) + 1;
    else
        ans += max(f(i + 1, j), f(i, j + 1));
    return ans;
}

void build(int i, int j){
    if(i == sz(a) or j == sz(b))
        return;
    int ans = f(i, j);
    if(a[i] == b[j] && ans == f(i + 1, j + 1) + 1){
        cout << a[i];
        build(i + 1, j + 1);
        return;
    }
    else{
        if(f(i + 1, j) == ans){
            build(i + 1, j);
            return;
        }else{
            build(i, j + 1);
            return;
        }
    }
}
int main(){
    //FL;
    FIN;
    cin >> a >> b;
    cls(dp, -1);
    f(0, 0);
    build(0, 0);
    EjecuteTime;
    return 0;
}       

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

int main (void)
{
    char S[101];
    char T[101];
    char tmp;
    int cnt;
    scanf("%s", S);
    scanf("%s", T);
    cnt = strlen(S);

    int i, j;
    for (i = 0; i < cnt; i++) {
        if (strcmp(S, T) == 0) {
            printf("Yes");
            return 0;
        }
        tmp = S[cnt - 1];
        for (j = cnt - 1; j > 0; j--) {
            S[j] = S[j - 1];
        }
        S[0] = tmp;
        //printf("%s\n", S);
    }
    printf("No");
    return 0;
}

Measured memory_bytes: 128
#include<iostream>
using namespace std;
int main(){
	int n;
	cin>>n;
	int a[100000];
	for(int i=1;i<=n;++i)
		a[i]=0;
	for(int i=1;i<=100;++i)
		for(int j=1;j<=100;++j)
			for(int k=1;k<=100;++k)
				++a[i*i+j*j+k*k+i*k+j*k+i*j];
	for(int i=1;i<=n;++i)
		cout<<a[i]<<endl;
	return 0;
}

Measured memory_bytes: 3856
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int K = sc.nextInt();
        int A = sc.nextInt();
        int B = sc.nextInt();
        
        int i = 0;
        int j = 0;
        boolean flg = true;
        
        while (true) {
            j = K * i;
            i++;
            if ( B < j ) {
                flg = false;
                break;
            } else if ( A <= j && j <= B ) {
                break;
            }
        }
        
        if (flg) {
            System.out.println("OK");
        } else {
            System.out.println("NG");
        }
        
    }
}


Measured memory_bytes: 35752
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;   
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define ld long double
#define dd double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define sz(a) (ll)(a.size())
typedef long long ll;
typedef unsigned long long ull;
typedef pair <ll, ll> pll;
typedef pair <int, int> pii;
typedef vector<pll> vplll;
ll mod = 1e9+7;
const ld PI = 2 * acos(0.0);
const vector<ll> dx = {1, -1, 0, 0};
const vector<ll> dy = {0, 0, 1, -1};
#define round(x, y) ((x + y - 1) / y)
#define ce(x, y) ((x + y - 1) / y)
#define amax(x, y) \
    if (y > x)     \
        x = y;
#define amin(x, y) \
    if (y < x)     \
        x = y;
#define lcm(x, y) ((x) * (y) / __gcd(x, y))
#define len(x) (ll) x.length()
#define sq(x) ((x) * (x))
#define cb(x) ((x) * (x) * (x))
const int N = 1e5;  // limit for array size
int n;  // array size
ll seg[4 * N];

void build(int ar[]) {  // build the tree
  for (int i = n - 1; i > 0; --i) seg[i] = max(seg[i<<1],seg[i<<1|1]);
}

void modify(int p, ll value) {  // set value at position p
  for (seg[p += n] = value; p > 1; p >>= 1) seg[p>>1] = max(seg[p], seg[p^1]);
}

ll query(int l, int r) {  // sum on interval [l, r)
  ll res = 0;
  for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
    if (l&1) res = max(res,seg[l++]);
    if (r&1) res = max(res,seg[--r]);
  }
  return res;
}
vector <pair<ll,pll>> v;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll a,b,c,t,m,k,q; 
    t = 1;
    // cin>>t;
    while(t--)
    {
        cin>>n;
        ll ar[n], br[n];
        for(int i=0;i<n;i++)
            cin>>ar[i];
        for(int i=0;i<n;i++)
        {
            cin>>br[i];
            v.pb(mp(ar[i],mp(br[i],i+1)));
        }
        sort(all(v));
        reverse(all(v));
        for(auto j: v)
        {
            pll y = j.ss;
            // cout<<j.ff<<" "<<y.ff<<" "<<y.ss<<endl;
            ll ans = query(y.ss,n);
            // cout<<ans<<" ";
            ans += br[y.ss-1];
            // cout<<ans<<"c"<<j.ff-1<<endl;;
            modify(y.ss-1,ans);
        }
        cout<<query(0,n)<<endl;
    }
    return 0;
}

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

// def
#define debug(x) cout << #x << ": " << x << endl
#define out(x) cout << x << endl
#define repeat(i, a, b) for (int i = (a); i < (b); i++)
#define revrepeat(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define revrep(i, n) for (int i = (n)-1; i >= 0; i--)
typedef long long ll;
typedef pair<int, int> P;
const int M = 1e9 + 7;
const int INF = 1e9;
const int MAX_V = 1000 + 5;
const int MAX_N = 1e5 + 5;

int main() {
    string s;
    cin >> s;
    int n = s.length();
    int ans = 0;
    rep(i, n / 2) {
        char a = s[i];
        char b = s[n - 1 - i];
        if (a != b) {
            ans += 1;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
//#include "boost/multiprecision/cpp_int.hpp"
//typedef boost::multiprecision::cpp_int LL;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2

ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
typedef pair<dd,dd> d_d;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fi first
#define se second
#define endl "\n"
#define SORT(v) sort(v.begin(),v.end())
#define ERASE(v) v.erase(unique(v.begin(),v.end()),v.end())
#define POSL(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define POSU(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
//template<class T>void max(T a,T b){if(a<b)return b;else return a;}
//template<class T>void min(T a,T b){if(a>b)return b;else return a;}
//template<class T>bool Max(T&a, T b){if(a < b){a = b;return 1;}return 0;}
//template<class T>bool Min(T&a, T b){if(a > b){a = b;return 1;}return 0;}

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


int main(){fastio
    ll n,k;cin>>n>>k;
    ll M=62;
    ll dp[n][n][M];memset(dp,0,sizeof(dp));
    rep(i,0,n-1)rep(j,0,n-1)cin>>dp[i][j][0];
    rep(x,1,M-1){
        rep(i,0,n-1)rep(j,0,n-1)rep(k,0,n-1){
            Add(dp[i][j][x],dp[i][k][x-1]*dp[k][j][x-1]);
        }
    }
    ll ep[n][n][M+1];memset(ep,0,sizeof(ep));
    rep(i,0,n-1)ep[i][i][0]=1;
    rep(keta,1,M){
        if(k&(1ll<<(keta-1))){
            rep(i,0,n-1)rep(j,0,n-1){
                rep(k,0,n-1)Add(ep[i][j][keta],ep[i][k][keta-1]*dp[k][j][keta-1]);
            }
        }else{
            rep(i,0,n-1)rep(j,0,n-1){
                ep[i][j][keta]=ep[i][j][keta-1];
            }
        }
    }
    
    ll ans=0;
    rep(i,0,n-1)rep(j,0,n-1){
        Add(ans,ep[i][j][M]);
    }
    cout<<ans<<endl;
    
    return 0;
}



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

string rever(string s) {
  string t(s.rbegin(), s.rend());
  return t;
}

int main() {
  string s, t, a, b, x, y;
  cin >> s;
  int n = s.size();
  t = rever(s);
  a = s.substr(0, (n-1)/2);
  b = rever(a);
  x = s.substr((n+1)/2);
  y = rever(x);
  if (s==t && a==b && x==y) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ll long long
using namespace std;

const ll P = 1000000007;
const long long INF = 1LL << 60;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

int main()
{
  cout << fixed << setprecision(10);
  int N,K;
  cin >> N >> K;
  vector<ll> A(N);
  rep(i,N) cin >> A[i];
  for(int i=K;i<N;i++)
  {
    if(A[i]>A[i-K])
    {
      cout << "Yes" << endl;
    }
    else
    {
      cout << "No" << endl;
    }
    
  }
  return 0;
}


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

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; }

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("Yes")
#define p_no() p("No")

const ll mod = 1e9 + 7;
const ll inf = 1e18;

template < typename T >
void vprint(T &V){
	for(auto v : V){
    	cout << v << " ";
	}
	cout << endl;
}

struct Machine{
    ll x;
    bool is_PC;

    Machine(ll a, bool b){
        x = a;
        is_PC = b;
    }

    bool operator<(const Machine &another) const
    {
        return x < another.x;
    }

    string ToString(){
        stringstream ss;
        ss << x << " " << is_PC;
        return ss.str();
    }
};

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

    // input
    ll N;
    cin >> N;

    // PC
    vector<ll> A(N);
    FOR(i, 0, N){
        cin >> A.at(i);
    }

    vector<ll> B(N);
    FOR(i, 0, N){
        cin >> B.at(i);
    }

    vector<Machine> C;
    FOR(i, 0, N){
        C.push_back(Machine(A[i], true));
        C.push_back(Machine(B[i], false));
    }
    sort(ALL(C));

    ll answer = 1;
    ll count = 0;

    for(auto machine : C){
        //p(machine.ToString());
        if(machine.is_PC){
            if(count>=0){
                count++;
            }else{
                // matching
                answer *= abs(count);
                count++;
                answer %= mod;
            }
        }else{
            if(count<=0){
                count--;
            }else{
                // matching
                answer *= abs(count);
                count--;
                answer %= mod;
            }
        }
    }

    p(answer);

    return 0;
}

Measured memory_bytes: 7408
#include<bits//stdc++.h>
using namespace std;
int main() {
	double n=0.5,m=6,n2=30;
	int a,b,n4,e=0;
	cin>>n4;
	for(int i=0;i<n4;i++){
		string d;
		cin>>d;
		d+=":";
		string h;
		e=0;
		for(int j=0;j<d.length();j++){
			if(d[j]==':'){
				if(e==0)
					a=atoi(h.c_str());
				else
					b=atoi(h.c_str());
				h="";
				e++;
			}
			else
				h+=d[j];
		}
		double n3,m3;
		n3=0;
		n3+=(a*n2+b*n);
		m3=0;
		m3+=b*m;
		double c=n3-m3;
		if(c<0)
			c=0-c;
		if(360-c<c){
			c=360-c;
		}
		if(c>=90&&c<=180)
			printf("safe\n");
		else if(c>=0&&c<30)
			printf("alert\n");
		else
			printf("warning\n");
	}
}

Measured memory_bytes: 3080
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<queue>
#define _USE_MATH_DEFINES
#include<math.h>
#include<cmath>
#include<ctime>
#include<map>
#include<typeinfo>
#define R(i, n) for(int i = 0;i < n; i++)
#define S(a) scanf("%d", &a)
#define S2(a, b) scanf("%d%d", &a, &b)
#define S3(a, b, c) scanf("%d%d%d", &a, &b, &c)
#define SL(a) scanf("%lld", &a)
#define SL2(a, b) scanf("%lld%lld", &a, &b)
#define SL3(a, b, c) scanf("%lld%lld%lld", &a, &b, &c)
#define SA(i, n, a) R(i, n) scanf("%d", &a[i])
#define SAL(i, n, a) R(i, n) scanf("%lld", &a[i])
#define SC(a) scanf("%c", &a)
#define P(a) printf("%d", a)
#define PL(a) printf("%lld", a)
#define PY printf("YES")
#define PN printf("NO")
#define Py printf("Yes")
#define Pn printf("No")
using namespace std;
using ll = long long;
using PR = pair<int, int>;
const ll MOD = 1e+9 + 7;
const int INF = 1e+9;
const double PI = acos(-1);

int main() {
	int x[5];
	R(i, 5) {
		int num;
		S(num);
		x[i] = num;
	}
	R(i, 5) {
		if (x[i] == 0) {
			P(i + 1);
			return 0;
		}
	}
}

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

using namespace std;


int main() {
	int h,w;

	cin >> h >> w;

	for(int y = 0; y < h; y++) {
		for(int x = 0; x < w; x++) {
			string str;
			cin >> str;
			if (str == "snuke") {
				cout << (char) (x + 'A') << y + 1 << endl;
			}
		}
	}

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <array>
#include <algorithm>

using namespace std;
const int MAX_N = 100;

int main() {
  int n;
  array <int, MAX_N> arr;

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

  reverse(arr.begin(), next(arr.begin(),n));

  for (int i = 0; i < n-1; ++i)
    {
      cout << arr[i] << " ";
    }

  cout << arr[n-1] <<endl;
}

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

int main() {
  int m;
  cin >> m;
  vector<ll> d(m), c(m);
  for (int i = 0; i < m; i++) cin >> d[i] >> c[i];
  ll r = 0;
  vector<ll> a;
  for (int i = 0; i < m; i++) {
    while (c[i] >= 2) {
      if (c[i] % 2 != 0) {
        a.push_back(d[i]);
        c[i]--;
      }
      if (d[i] < 5) {
        r += c[i] / 2;
        d[i] = d[i] * 2;
      } else {
        r += c[i];
        d[i] = (d[i] * 2) % 10 + 1;
      }
      c[i] /= 2;
    }
    a.push_back(d[i]);
  }
  while (a.size() >= 2) {
    r++;
    ll e1 = a[a.size() - 2], e2 = a[a.size() - 1];
    if (e1 + e2 < 10) {
      a.pop_back();
      a[a.size() - 1] = e1 + e2;
    } else {
      a[a.size() - 2] = 1;
      a[a.size() - 1] = (e1 + e2) % 10;
    }
  }
  cout << r << endl;
}


Measured memory_bytes: 37732
#include <stdio.h>
int main()
{
int a,b,x,y[8];
for(x=0;x<7;x++){
	scanf("%d %d",&a,&b);
	y[x]=a-b;
	
}

for (x=0;x<7;x++){
	printf("%d\n",y[x]);
}
	return 0;
}

Measured memory_bytes: 600
#include<stdio.h>
#include<stdlib.h>

int main(void){
    int A,B,C;
    int ans;

    scanf("%d",&A);
    scanf("%d",&B);
    scanf("%d",&C);

    if((A==B && B==C)||(A!=B&&B!=C&&A!=C)){
        printf("No");
    }else{
        printf("Yes");
    }

    return 0;
}

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

int main(void) {
  int A[31];
  int n, w, a, b;
  char ch;

  cin >> w >> n;
  for(int i=1; i<=w; i++) A[i]=i;
  
  for(int i=0; i<n; i++) {
    cin >> a >> ch >> b;    
    swap(A[a], A[b]);
  }

  for(int i=1; i<=w; i++)
    cout << A[i] << endl;
  
  return 0;
}

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

int main() {
  int N, D, M, T;
  cin >> N;
  multiset<int> S;
  while (N-- && cin >> D) S.insert(D);
  cin >> M;
  while (cin >> T) {
    if (!S.count(T)) return cout << "NO" << "\n", 0;
    S.erase(S.find(T));
  }
  cout << "YES" << "\n";
}

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

// ----------- define --------------
#define int long long
#define vi vector<int>
#define ii pair<int,int>
#define fi first
#define sc second
#define stoi stoll
#define popcnt __builtin_popcount
#define getBit(x, k) ((x >> k) & 1)
#define all(x) (x).begin(),(x).end()
// ---------------------------------

void Main() {
  string s;
  cin >> s;
  if (s.back() == 's') s += "es";
  else s += "s";
  cout << s << '\n';
}

signed main() {
#ifdef _DEBUG
  // freopen("in" , "r", stdin );
  cerr << "- ---- ------- <3 \n";
#endif
  cin.tie(0)->sync_with_stdio(0);
  int T = 1;
  // cin >> T;
  while (T--) Main();
}


Measured memory_bytes: 3652
#include<iostream>
using namespace std;
main()
{
	long a,b,c;cin>>a>>b>>c;
	long cnt=0;
	if(a==b&&b==c&&a%2==0)cout<<-1<<endl;
	else
	{
		for(;!(a%2||b%2||c%2);)
		{
			cnt++;
			long sto=c;
			c=(a+b)/2;
			long sto2=b;
			b=(a+sto)/2;
			a=(sto2+sto)/2;
		}
		cout<<cnt<<endl;
	}
}

Measured memory_bytes: 256
n=int(input())
s=tuple(input())

m=[[] for i in range(10)]
for i in range(n):
    m[int(s[i])].append(i)

yn=""
icnt=0
for i in range(0,1000):
    yn=""
    stri=format(i,"03d")
    stri=list(map(int,stri))
    if len(m[stri[0]])>0:
        m01=m[stri[0]][0]
    else:
        continue

    for ii in m[stri[1]]:
        if m01<ii:
            m02=ii
            yn="yes2"
            break
    if yn!="yes2":
        continue

    for ii in m[stri[2]]:
        if m02<ii:
            icnt+=1
            break

print(icnt)       
    

Measured memory_bytes: 4584
import math

def Koch(Px, Py, Qx, Qy, n) :
    if n == 0 :
        return
    else :
        Ax = (2 * Px + Qx) / 3
        Ay = (2 * Py + Qy) / 3
        Bx = (Px + 2 * Qx) / 3
        By = (Py + 2 * Qy) / 3
        Cx = Ax + (Bx - Ax) * math.cos(math.pi/3) - (By - Ay) * math.sin(math.pi/3) 
        Cy = Ay + (Bx - Ax) * math.sin(math.pi/3) + (By - Ay) * math.cos(math.pi/3)
        
        Koch(Px, Py, Ax, Ay, n-1)
        print(Ax, Ay)
        Koch(Ax, Ay, Cx, Cy, n-1)
        print(Cx, Cy)
        Koch(Cx, Cy, Bx, By, n-1)
        print(Bx, By)
        Koch(Bx, By, Qx, Qy, n-1)

n = int(input())
print(0, 0.00000000)
Koch(0.00000000, 0.00000000, 100.00000000, 0.00000000, n)
print(100.00000000, 0.00000000)


Measured memory_bytes: 5780
#include <bits/stdc++.h>
using namespace std;
#define LONGLONGMAX 9223372036854775807
#define LONGLONGMIN -9223372036854775807
#define INTMAX 32767
#define INTMIN -32767
#define ROUNDUP(divisor,dividend) (divisor + (dividend - 1)) / dividend
int r,g,b,n;
int main(){
  cin >> r >> g >> b >> n;
  int c=0;
  for (int i = 0; i <= n; i++) {
    for (int l = 0; l <= n; l++) {
      if((n-(i*r + l*g)) % b == 0 && (n-(i*r + l*g)) >= 0){
        c++;
      }
    }
  }
  cout << c << endl;
}


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

using namespace std;

typedef long long ll;

#define INF 1LL<<60

ll n;
ll s;

ll f(ll b, ll n) {
    if (n < b) {
        return n;
    } else {
        ll nn = floor((double) n / b);
        return f(b, nn) + (n % b);
    }
}

int main(int argc, char* argv[]) {
    cin >> n >> s;

    if (n == s) {
        cout << n + 1 << endl;
        return 0;
    }

    ll ans = INF;

    for (ll b = 2; b < sqrt(n) + 1; ++b) {
        if (f(b, n) == s) {
            ans = min(ans, b);
        }
    }

    ll d = n-s;

    for (ll i = 1; i < sqrt(d) + 1; ++i) {
        ll b = (n-s)/i + 1;

        if (f(b, n) == s) {
            ans = min(ans, b);
        }
    }

    if (ans == INF) {
        cout << -1 << endl;
    } else {
        cout << ans << endl;
    }

    return 0;
}


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

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned long long ULL;

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

#define MP make_pair
#define EACH(i,c) for(auto i: c)
#define SORT(c) sort((c).begin(),(c).end())

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

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

	set<string> s;

	REP(_, N){
		string t;
		cin >> t;
		s.insert(t);
	}

	cout << s.size() << endl;

	return 0;
}


Measured memory_bytes: 19140
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
//#define f(i,a,n) for(ll i=a;i<n;i++)
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll isPrime(int n) 
{ 
	// Corner cases 
	if (n <= 1) 
		return 1; 
	if (n <= 3) 
		return 2; 

	// This is checked so that we can skip 
	// middle five numbers in below loop 
	if (n % 2 == 0 || n % 3 == 0) 
		return 1; 

	for (int i = 5; i * i <= n; i = i + 6) 
		if (n % i == 0 || n % (i + 2) == 0) 
			return 1; 

	return 2; 
} 

ll fact(ll n){ll res = 1;for (ll i = 2; i <= n; i++)res = res * i,res%=1000000007; 
    return res; } 
 
 int gcd(int a, int b) 
{ 
    if (b == 0) 
        return a; 
    return gcd(b, a % b); 
} 
  
 
ll findlcm(ll arr[], int n) 
{ 
   
    ll ans = arr[0]; 
  
    
    for (int i = 1; i < n; i++) 
        ans = (((arr[i] * ans)) / 
                (gcd(arr[i], ans))); 
  
    return ans; 
} 
 
 
int main() 
{
    fast;
    ll t=1;
    //cin>>t;
    while(t--)
    {
      ll a,b,c;
      cin>>a>>b>>c;
      if(a+b+c<22)
      cout<<"win";
      else
      cout<<"bust";
    }
     
     
      
    return 0;
}


Measured memory_bytes: 3612
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#include<string>
#include<math.h>
 
using namespace std;
 
int main(){
    int A,B,K;
 
    cin >> A >> B >> K;
 
    for(int i = 0;i < K;i++){
        if(A & 1)A--;
        A /= 2;
        B += A;
        swap(A,B);
    }
  
  	if(K & 1)swap(A,B);
 
    cout << A << ' ' << B << endl;
 
    return 0;
}

Measured memory_bytes: 256
def I(): return int(input())
def MI(): return map(int, input().split())
def SI(): return input().rstrip()
from collections import defaultdict

#https://note.nkmk.me/python-union-find/

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

h,w=MI()
uf=UnionFind(h*w)
lis=[[0]*w for i in range(h)]
for i in range(h):
    s=SI()
    for j in range(w):
        if s[j]=="#":
            lis[i][j]=1
step=[[0,1],[0,-1],[-1,0],[1,0]]
for i in range(h):
    for j in range(w):
        for x,y in step:
            if not (0<=i+x<h and 0<=j+y<w):
                continue
            if lis[i][j]!=lis[i+x][j+y]:
                uf.union(w*i+j,w*(i+x)+(j+y))
ans=0
dic=defaultdict(lambda:[0,0])
for i in range(h):
    for j in range(w):
        dic[uf.find(w*i+j)][lis[i][j]==1]+=1
for p in dic.keys():
    ans+=dic[p][0]*dic[p][1]
print(ans)

            
            
                
                
    
        
    
            
            










            
            
                
                
    
        
    
            
            



Measured memory_bytes: 32192
import java.util.*;
import static java.lang.Math.*;
import java.math.BigInteger;

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

		// 入力
		long n = sc.nextLong();

        long result = n * (n - 1) / 2; 
		// 計算

		// 出力
		System.out.println(result);
	}

}


Measured memory_bytes: 21972
N,K = map(int,input().split(" "))
H = list(map(int,input().split(" ")))
#DPテーブル作成
dp = [10**10]*(N)

dp[0]=0

for i,hi in enumerate(H):
    if i ==0:
        continue
    s = i-K if i-K>=0 else 0
    dp[i] = min([dpk+abs(hi-hk) for dpk,hk in zip(dp[s:i],H[s:i])])
print(dp[-1])
#print(dp)

Measured memory_bytes: 13976
#include <bits/stdc++.h>
using namespace std;
template<class T> ostream& operator<<(ostream &os, vector<T> V) { os << "[ "; 
	for(auto v:V)os << v << " "; return os << "]";
}
template<class T> ostream& operator<<(ostream &os, set<T> S){ os << "{ "; 
	for(auto s:S) os<<s<<" ";  return os<<"}"; 
}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {
	return os<<"("<<P.first<<","<< P.second << ")";
}
template<class L, class R> ostream& operator<<(ostream &os, map<L,R> M) {
	os<<"{ ";for(auto m:M)os<<"("<<m.F<<":"<<m.S<<")";
	return os<<"}";
}
#define cerr cout
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...) 1
#endif
#define ll long long
#define ld long double
#define vll vector<ll>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define I insert 
#define pb push_back
#define F first
#define S second
#define endl "\n"
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define For(i,n) for(int i=0;i<(int)n;++i)
#define Rev(i,n) for(int i=(int)n-1;i>=0;--i)
#define Rep(i,n) for(int i=1;i<=(int)n;++i)
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef vector<pii> vpii;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)


const int N = 5e5 + 100;

bool isPeriod[2][N];
int lps[N];

void kmp(string &pat , int type){
	int len = 0; 
    lps[0] = 0; 
    int i = 1; 
    int m = pat.length();
    while (i < m) { 
        if (pat[i] == pat[len]) { 
            len++; 
            lps[i] = len; 
            i++; 
        } 
        else{ 
            if (len != 0) { 
                len = lps[len - 1]; 
            } 
            else 
            { 
                lps[i] = 0; 
                i++; 
            } 
        } 
    } 
    for(int i = 2 ;i <= m ; ++i){
    	if(lps[i-1] != 0 && (i%(i-lps[i-1]) == 0) ){
    		// trace(type , i);
    		// trace(type , isPeriod[type][i]);
    		if(type == 0)
    			isPeriod[type][i] = 1;
    		else
    			isPeriod[type][m-i+1] = 1;

    	}
    }



}

int main(){
	fio; cout<<fixed<<setprecision(25);	
	string w; cin >> w;
	char c = w[0];
	bool alleq = 1;
	for(auto it : w){
		if(it != c){
			alleq = 0;
			break;
		}
	}
	if(alleq){
		cout << w.size() << endl;
		cout << 1 << endl;
	}
	else{
		kmp(w , 0);
		if(!isPeriod[0][w.size()]){
			cout << 1 << endl;
			cout << 1 << endl;
			return 0;
		}
		reverse(all(w));
		kmp(w , 1);
		int cnt = 0;
		for(int i = 1; i < w.size(); ++i){

			if(!isPeriod[0][i] && !isPeriod[1][i+1]){
				++cnt;
			}
		}
		cout << 2 << endl;
		cout << cnt << endl;
	}










	return 0;
}


Measured memory_bytes: 3740
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
int main()
{
    string S; cin >> S;
    int a = 0, b = 0;
    for (int i = 0; i < S.size(); i++) {
        if (S[i] - '0' != i % 2) a++; else b++;
    }
    cout << min(a, b) << '\n';
    return 0;
}

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

int main() {
  int a, b, k;
  cin >> a >> b >> k;
  
  int count = 0;
  
  for(int i=100; i>0; i--) {
    if(a % i == 0 && b % i == 0) {
      count++;
    }
    if(count == k) {
      cout << i << endl;
      break;
    }
  }
}

Measured memory_bytes: 256
#include <stdio.h>

int main (){
	int n,l;
	int i,ans=0;
	scanf("%d %d",&n,&l);
	if(0<l){
		l++;
		n--;
	}else if(l<0 && (n+l)<=0){
		n--;
	}
	for(i=0;i<n;i++){
		ans+=l+i;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 128
#!/usr/bin/env python3

import sys, math, copy
# import fractions, itertools
import numpy as np
# import scipy

HUGE = 2147483647
HUGEL = 9223372036854775807
ABC = "abcdefghijklmnopqrstuvwxyz"

def main():
    n = int(input())
    an = list(map(int, input().split()))
    assert len(an) == n
    d = np.sum(an)
    if d % (n * (n + 1) // 2) > 0:
        return False
    k = d // (n * (n + 1) // 2)

    diffs = np.roll(np.array(an), -1) - np.array(an)
    diffs -= k
    if np.all(diffs <= 0) and np.all(diffs % n == 0):
        return True
    else:
        return False

print("YES" if main() else "NO")


Measured memory_bytes: 23224
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
#define erep(i,n) for(int i = 0;i<=n;i++)
#define rep1(i,n) for(int i = 1;i<n;i++)
#define erep1(i,n) for(int i = 1;i<=n;i++)
typedef long long ll;
#define vint vector<int>
#define vstring vector<string>
#define vll vector<ll>
#define vbool vector<bool>
#define INF 100000000

int main(){
  string a;
  cin >> a;
  if(a == "AAA" || a == "BBB") cout << "No" << endl; else cout << "Yes" << endl;
}

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

int main(){

    long N,M,X;
    cin >> N >> M >> X;
    long C[N],A[N][M];
    for(long i=0; i<N; i++){
        cin >> C[i];
        for(long j=0; j<M; j++){
            cin >> A[i][j];
        }
    }

    long money=0;
    long algo[M];

    long ans=-1;

    for(long count =0; count < 1<<(N); count++){
        //cout << "count all " << count << " " << (1<<(N)) << endl;

        money=0;
        for(int i=0; i<M; i++){
            algo[i]=0;
        }

        long buy[N];
        for(long i=0; i<N; i++){
            buy[i] = ( (count)/((1<<i)) )%2;
            //cout << "count i 2^i div buy[i] " << count << " " << i << " " << (2<<i) << " " << count/((1<<(i)))  << " " << buy[i] << endl;
         }
        /*cout << "buy: ";
        for(long i=0; i<N; i++){
            cout << buy[i] << " ";
        }
        cout << endl;*/

        for(long i=0; i<N; i++){
            money += C[i]*buy[i];
            for(int j=0; j<M; j++){
                algo[j] += A[i][j]*( buy[i] );
            }
        }

        bool flag=true;

        for(long i=0; i<M; i++){
            if( algo[i] < X){
                flag = false;
            }
        }

        if(flag){
            if(ans == -1){
                ans = money;
            }else{
                ans = min(ans,money);
            }
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define dump(x) cout << (x) << endl
typedef long long ll;
typedef pair<ll, ll> pl;
typedef pair<int, int> pi;
typedef vector<int> V;

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  if (a+b >= c) dump("Yes");
  else dump("No");
  return 0;
}


Measured memory_bytes: 256
n,k = map(int,input().split())
snack = [0 for _ in range(n)]
for _ in range(k):
  d = int(input())
  A = list(map(int,input().split()))
  for a in A:
    snack[a-1] += 1
ans = 0
for snk in snack:
  if snk == 0:
    ans += 1
print(ans)

Measured memory_bytes: 67516
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define rep( i, n, m ) for(int i = ( n ); i < ( m ); i++)
#define rep_d( i, n, m ) for(int i = ( n ) - 1; i >= ( m ); i--)
#define sort_asc( X ) sort(( X ).begin(), ( X ).end())
#define sort_desc( X ) sort(( X ).begin(), ( X ).end(), greater <>())

template <class T> bool chmax( T& a, T b );
template <class T> bool chmin( T& a, T b );
int* eratosthenes( int N );
bool bit_search( int pattern, int N );
template <class T> void cumulative_sum( T array, size_t N );

const ll INF = 1LL << 60;
const int k_mod = 1e9 + 7;

template <typename T, typename K> struct P {
	T a; K b;
};
typedef struct {
	vector <int> to;
	bool is_visited = false;
} node;
typedef struct {
	int to;
	int cost;
	P <int, int> change;
} edge;
int main( void ){
	int N; cin >> N;
	vector <ll> input( N ), vec( N );
	rep( i, 0, N ){
		cin >> input[ i ];
	}
	sort_asc( input );
	vec[ 0 ] = input[ 0 ];
	rep( i, 1, N ){
		vec[ i ] = vec[ i - 1 ] + input[ i ];
	}
	int cnt = 1;
	rep_d( i, N, 1 ){
		if (vec[ i - 1 ] * 2 >= vec[ i ] - vec[ i - 1 ]){
			cnt++;
		}
		else
			break;
	}
	cout << cnt << endl;
}

int* eratosthenes( int N ){
	int* prime_array = new int[ N + 1 ];
	int lim = N;
	prime_array[ 0 ] = 0;
	prime_array[ 1 ] = 0;
	rep( i, 2, N + 1 ){
		prime_array[ i ] = 1;
	}
	rep( i, 2, lim ){
		if (prime_array[ i ] == 0)
			continue;
		lim = N / i;
		for(int j = i * 2; j < N + 1; j += i){
			prime_array[ j ] = 0;
		}
	}
	return prime_array;
}
template <class T> void cumulative_sum( T array, size_t N ) {
	rep( i, 1, N + 1 ){
		array[ i ] += array[ i - 1 ];
	}
}
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;
}
bool bit_search( int pattern, int N ){
	int cnt = 0;
	rep( bit, 0, N ){
		if (pattern & ( 1 << bit )){
			cnt++;
		}
	}
	return true;
}


Measured memory_bytes: 1792
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define max0(a,b,c) max(max(a,b),c)
#define min0(a,b,c) min(min(a,b),c)
#define ft first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define all(v) (v).begin(),(v).end()
#define mod 1000000007
using namespace std;
using Graph = vector<vector<int>>;
typedef long long lint;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ldouble;
typedef vector<int> vec;
typedef vector<ll> lvec;
typedef vector<ull> ulvec;
typedef vector<double> dvec;
typedef vector<pair<int,int>> pvec;
typedef vector<pair<ll,ll>> plvec;
typedef vector<tuple<ll,ll,ll>> tvec;
typedef vector<string> svec;

int main(){
    vec a(3);
    int sum=0;
    rep(i,3){
        cin>>a[i];
        sum+=a[i];
    }
    if(sum>=22) cout<<"bust";
    else cout<<"win";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define optimizar_io ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;
int main(){
    long long x,y,cont=0; cin>> x >> y;
    while(x<=y){x*=2;cont++;}
    cout<<cont<<endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

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

		//????????¶?????\??????????????????
		Scanner scan = new Scanner(System.in);

		// TODO ?????????????????????????????????????????????
		//??????????????????
		ArrayList<Integer> list = new ArrayList<Integer>();
		//????????¶???????????????????????°??????????????????
		for(int i =0; i<10; i++){
			String stra = scan.next();
			int str = Integer.parseInt(stra);
			 list.add(str);
		}

		//????????????
		scan.close();

		//?????????
		Collections.sort(list);
		//??????
		System.out.println(list.get(9));
		System.out.println(list.get(8));
		System.out.println(list.get(7));

	}

}

Measured memory_bytes: 25992
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
using namespace std;

int main() {
	int N; cin >> N;
	vector<int> r(N);
	for (int i = 0; i < N; i++)
		cin >> r[i];
	sort(r.begin(), r.end());
	double ma = 0;
	for (int n = 3; n <= N; n++) {
		vector<int> a(r.end() - n, r.end());
		do {
			vector<double> x(n), y(n);
			for (int i = 0; i < n; i++) {
				x[i] = a[i] * cos(M_PI*2 / n * i);
				y[i] = a[i] * sin(M_PI*2 / n * i);
			}
			for (int t = 0; t < 30; t++) {
				int i = rand() % n;
				int j = (i + n - 1) % n, k = (i + 1) % n;
				double dx = x[k] - x[j], dy = y[k] - y[j];
				double _dx = dy, _dy = -dx;
				double r = sqrt(_dx * _dx + _dy * _dy);
				x[i] = _dx / r * a[i];
				y[i] = _dy / r * a[i];
			}
			double sum = 0;
			for (int i = 0; i < n; i++) {
				int j = (i + 1) % n;
				sum += x[i] * y[j] - y[i] * x[j];
			}
			ma = max(ma, sum);
		} while (next_permutation(a.begin() + 1, a.end()));
	}
	printf("%.15f\n", ma / 2);
}

Measured memory_bytes: 3656
X, N = list(map(int, input().split()))

if N == 0:
    print(X)
else:
    p = list(map(int, input().split()))
    nums = {i for i in range(0, 102)}
    nothings = nums - set(p)
    differences = {}
    for i in nothings:
        difference = abs(X - i)
        if difference in differences:
            differences[difference].append(i)
        else:
            differences[difference] = [i]
    ans = sorted(differences.items())
    print(min(ans[0][1]))

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

vector<int> graph[210];

bool memo[210] = {};

bool dfs(int i, int x){
  if(memo[i]) return false ;

  memo[i] = true;
  bool ans = false;;
  for(int j = 0;j < graph[i].size();j++){
    if(graph[i][j] == x){
      return true;
    }else{
      ans = ans | dfs(graph[i][j],x);
    }
  }

  return ans;
}

int main(){
  int n;
  cin >> n;
  int a,b;
  string s;

  for(int i = 0;i < n;i++){
    cin >> a >> s >> b;
    if(s == "lock"){
      graph[a].push_back(b+100);
    }else{
      graph[b+100].push_back(a);
    }
  }

  for(int i = 0;i < 210;i++){
    memset(memo,false,sizeof(memo));
    if(dfs(i,i)){
      cout << 1 << endl;
      return 0;
    }
  }

  cout << 0 << endl;
  return 0;

}


Measured memory_bytes: 3244
import sys

n,k=map(int,input().split())
a=list(map(int,input().split()))

if k==0:
    print(max(a))
    sys.exit()

def rf(mm):
    if mm==0:
        mm=1
    icnt=0
    for i in range(n):
        icnt+=(a[i]-1)//mm+1
    return icnt

asum=sum(a)
m=asum//(n+k)
um=asum
lm=1
for ii in range(60):
    if m==1:
        break
    if rf(m)<=(n+k) and rf(m-1)>(n+k):
        break
    if um-lm<5:
        break
    if rf(m)>(n+k):
        lm=m
        m=(um+lm)//2-1
    elif rf(m)<(n+k):
        um=m
        m=(um+lm)//2-1
    else:
        um=m-1
        m=(um+lm)//2-1
#    if rf(m)==(n+k) and um-lm<5:

if um<1:
    print(1)
    sys.exit()
    
for mi in range(um,max(0,lm-1),-1):
    if rf(mi)<=(n+k) and rf(mi-1)>(n+k):
        break

print(mi)



Measured memory_bytes: 104300
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <unordered_map>

#define REP(i, n) for (int i = 0; i < n; i++)
#define ll long long int

using namespace std;

int main()
{
  int a[20];
  int b[20];
  int c, n, m;

  cin >> n >> m >> c;
  int result = 0;
  REP(i, m)
  {
    cin >> b[i];
  }
  REP(i, n)
  {
    int sum = c;
    REP(j, m)
    {
      cin >> a[j];
      sum += a[j] * b[j];
    }

    if (sum > 0)
    {
      result++;
    }
  }

  cout << result << endl;
}

Measured memory_bytes: 888
s = int(input())
a = [s]
for i in range(10**6):
    if int(a[i]/2)*2 == a[i]:#偶数
        a.append(a[i]/2)
    else:
        a.append(a[i]*3 +1)

    if a[i+1] in a[0:i]:
        print(i+2)
        break

Measured memory_bytes: 3060
#include<iostream>
#include<vector>
#define vi vector<long long>
#define mod 1000000007
using namespace std;

vector<vi> adjlist;
bool visited[100003];
long long N;
long long x,y;
long long dp[100003][2]; 								// 0 la white, 1 la black

void DFS(long long u) {
	visited[u]=1;
	for(long long i=0;i<adjlist[u].size();i++) {
		long long v=adjlist[u][i];
		if(visited[v]==0) {
			
			DFS(v);
			
			dp[u][0]*=(dp[v][0]%mod + dp[v][1]%mod);
			dp[u][0]%=mod;
			
			dp[u][1]*=(dp[v][0]%mod);
			dp[u][1]%=mod;
		}
	}
}

main() {
	scanf("%d",&N);
	
	adjlist.assign(N,vi());
	
	for(long long i=0;i<N;i++) visited[i]=0;
	
	for(long long i=1;i<N;i++) {
		scanf("%d %d",&x,&y);
		adjlist[x-1].push_back(y-1);
		adjlist[y-1].push_back(x-1);
	}
	
	for(long long i=0;i<N;i++) dp[i][0]=dp[i][1]=1;
	
	DFS(0);
	
	printf("%d",(dp[0][0]+dp[0][1])%mod);
	return 0;
}

Measured memory_bytes: 11520
import sys
def input():
    return sys.stdin.readline()[:-1]

N = int(input())

a = list(map(int,input().split()))

from heapq import heappop,heappush

q = []
left_sum = 0

for i in range(N):
    heappush(q, a[i])
    left_sum+=a[i]

ls_list = [left_sum]

for i in range(N):
    heappush(q,a[i+N])
    b = heappop(q)
    left_sum-=b
    left_sum+=a[i+N]
    ls_list.append(left_sum)

q = []

right_sum = 0
for i in range(N):

    heappush(q, -a[3*N-i-1])
    right_sum+=a[3*N-i-1]

rs_list = [right_sum]

for i in range(N):
    heappush(q,-a[2*N-i-1])
    b = -heappop(q)
    right_sum-=b
    right_sum+=a[2*N-i-1]
    rs_list.append(right_sum)

rs_list = rs_list[::-1]

max_score = -10**27

for i in range(N+1):
    max_score = max(ls_list[i]-rs_list[i],max_score)

print(max_score)

Measured memory_bytes: 121156
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;
 
signed main() {
    int K, A, B; cin >> K >> A >> B;
    if(B - A <= 2) {
        cout << K + 1 << endl;
    }
    else {
        if(K < A) cout << K + 1 << endl;
        else {
            K -= A;
            if(K % 2 == 1) {
                int div = K / 2;
                int add = (div + 1) * B;
                int sub = div * A;
                cout << add - sub << endl;
            }
            else {
                int div = K / 2;
                int add = div * B + A + 1;
                int sub = div * A;
                cout << add - sub << endl;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 256
n = int(input())

data = dict()

for i in range(n):
    s = input()
    if s in data:
        data[s] += 1
    else:
        data.setdefault(s,1)
ans = sorted(data.items(),key=lambda x:x[1],reverse=True)
max_num = ans[0][1]
A = []
for item,i in ans:
    if i == max_num:
        A.append(item)
A.sort()

for item in A:
    print(item)

Measured memory_bytes: 45780
#include<stdio.h>
#define MAX 26
#define NIL -1
 
 
struct Node { int parent, leftChild, rightChild; };
Node T[MAX];
 
// root , left, right
void preOrder(int node) {
    if (node == NIL)
        return;
    printf(" %d", node);
    preOrder(T[node].leftChild);
    preOrder(T[node].rightChild);
}
 
// left, root, right
void inOrder(int node) {
    if (node == NIL){
        return;
    }
    inOrder(T[node].leftChild);
    printf(" %d", node);
    inOrder(T[node].rightChild);
}
 
//left, right, root
void postOrder(int node) {
    if (node == NIL){
        return;
    }
    postOrder(T[node].leftChild);
    postOrder(T[node].rightChild);
    printf(" %d", node);
}
 
void output(int root) {
    printf("Preorder\n");
    preOrder(root);
    printf("\nInorder\n");
    inOrder(root);
    printf("\nPostorder\n");
    postOrder(root);
    printf("\n");
}
 
int main() {
    int i, n, id, child_1, child_2, root;
 
    scanf("%d", &n);
    for (i = 0; i < n; i++)
        T[i].parent = NIL;
 
    for (i = 0; i < n; i++){
        scanf("%d %d %d", &id, &child_1, &child_2);
        T[id].leftChild = child_1;
        T[id].rightChild = child_2;
 
        if (child_1 != NIL)
            T[child_1].parent = id;
        if (child_2 != NIL)
            T[child_2].parent = id;
    }
 
    for (i = 0; i < n; i++) {
        if (T[i].parent == NIL) {
            root = i;
            break;
        }
    }
 
    output(root);
 
    return 0;
}

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

int R, C, K;
long long memo[3005][3005][10];
int grid[3005][3005];

bool exists(int r, int c)
{
	return (1 <= r && r <= R) && (1 <= c && c <= C);
}

long long dp(int r, int c, int rem)
{
	if(memo[r][c][rem] != -1)
		return memo[r][c][rem];
	
	memo[r][c][rem] = 0;
	if(r == R && c == C)
	{
		if(rem > 0 && grid[r][c] != 0)
			memo[r][c][rem] = grid[r][c];
			
		else
			memo[r][c][rem] = 0;
			
		return memo[r][c][rem];
	}
	
	else
	{
		if(exists(r + 1, c))
		{
			if(rem > 0 && grid[r][c] != 0)
				memo[r][c][rem] = max(memo[r][c][rem], dp(r + 1, c, 3) + grid[r][c]);
				
			else
				memo[r][c][rem] = max(memo[r][c][rem], dp(r + 1, c, 3));
		}
		
		if(exists(r, c + 1))
		{
			memo[r][c][rem] = max(memo[r][c][rem], dp(r, c + 1, rem));
			if(rem > 0 && grid[r][c] != 0)
				memo[r][c][rem] = max(memo[r][c][rem], dp(r, c + 1, rem - 1) + grid[r][c]);
		}
		
		return memo[r][c][rem];
	}
}

int main()
{
	scanf("%d%d%d", &R, &C, &K);
	
	for(int i = 1; i <= K; i++)
	{
		int ri, ci, vi;
		scanf("%d%d%d", &ri, &ci, &vi);
		grid[ri][ci] = vi;
	}
	
	for(int i = 1; i <= R; i++)
	{
		for(int j = 1; j <= C; j++)
		{
			for(int k = 0; k <= 3; k++)
				memo[i][j][k] = -1;
		}
	}
	
	printf("%lld", dp(1, 1, 3));
}


Measured memory_bytes: 743736
#include <bits/stdc++.h>
#include <atcoder/all>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n - 1); i >= 0; i--)
#define ALL(v) v.begin(), v.end()
using namespace std;
using namespace atcoder;
using P = pair<int, int>;
typedef long long ll;
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 dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main() {
  int n, m;
  cin >> n >> m;
  dsu d(n);
  rep(i, m){
    int a, b;
    cin >> a >> b;
    a--, b--;
    d.merge(a, b);
  }
  auto k = d.groups();
  cout << k.size() - 1 << endl;
}

Measured memory_bytes: 8868
/*input
33
ABCCABCBABCCABACBCBBABCBCBCBCABCB
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl
#define debug cout << "hi" << endl

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

const int MOD = 1e9 + 7;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int cnt = 0;
    int n; cin >> n;
    string s; cin >> s;
    for(int i = 0; i < n - 2; i++) if(s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C') cnt++;
    cout << cnt;

    return 0;
}

Measured memory_bytes: 256