akhauriyash/Code-Regression huggingface dataset:
#include <tuple>
#include <iostream>
#include <vector>
#include <queue>
#include <utility>
using namespace std;

int main(){
  int N;
  cin >> N;
  vector<int> A(N), B(N);
  for(auto &a : A) cin >> a;
  for(auto &b : B) cin >> b;
  if(A == B){
    cout << 0 << endl;
    return 0;
  }
  priority_queue<pair<int,int>> pq;
  for(size_t i = 0; i < N; ++i){
    if(A[i] > B[i]){
      cout << -1 << endl;
      return 0;
    }
    if(B[i] > A[i])
      pq.emplace(B[i],i);
  }
  long long ans = 0;
  while(pq.size()){
    int b, i;
    tie(b,i) = pq.top();
    pq.pop();
    int nex = (i+1)%N, pre = (i+N-1)%N;
    int s = (B[nex]+B[pre]);
    if(b%s >= A[i]){
      int d = b/s;
      if(!d){
        cout << -1 << endl;
        return 0;
      }
      ans += d;
      B[i] %= s;
    }else{
      if((b-A[i])%s){
        cout << -1 << endl;
        return 0;
      }
      ans += (b-A[i])/s;
      B[i] = A[i];
    }
    if(B[i] != A[i])
      pq.emplace(B[i],i);
  }
  cout << ans << endl;
}


Measured memory_bytes: 3956
#include<bits/stdc++.h>
#define mod 1000000007
#define INF 1000000000000000005
#define F first
#define S second
#define LB lower_bound
#define UB upper_bound
#define vc vector
#define vll vector<long long>
#define pll pair<long long,long long> 
#define pb push_back
#define all(v) v.begin(),v.end()
#define T ll test;cin>>test; while(test--)
#define rep(i,a,n) for(ll i=a;i<(long long)n;++i)
#define repr(i,n,a) for(ll i=n;i>(long long)a;--i)
#define MAX 1000005
#define sz(x) (ll)x.size()
#define ins insert
#define mp make_pair
#define int  long long
typedef  long long ll;
typedef long double ld;
using namespace std;

inline int add(int a,int b){a+=b;if(a>=mod)a-=mod;return a;}
inline int sub(int a,int b){a-=b;if(a<0)a+=mod;return a;}
inline int mul(int a,int b){return (a*1ll*b)%mod;}
inline int power(int a,int b){int rt=1;while(b>0){if(b&1)rt=mul(rt,a);a=mul(a,a);b>>=1;}return rt;}
inline int inv(int a){return power(a,mod-2);}
ll dp[MAX];
ll h[MAX];
ll n,k;
ll solve(ll c)
{
	if(c==1) return dp[1]=0;
	if(c==0) return dp[0]=INT_MAX;
	if(dp[c]!=-1) return dp[c];
	ll ans=INF;
	for(ll i=1;i<=k;i++)
	{
		if(c-i>0) 
		{
			ans=min(ans,solve(c-i)+abs(h[c-i]-h[c]));
			//cout<<ans<<" "<<c-i<<" "<<c<<endl;
		}
	}
	return dp[c]=ans;	
}


signed  main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);
	cin>>n>>k;
	memset(dp,-1,sizeof(dp));
	rep(i,1,n+1) cin>>h[i];
	//ll val=solve(n);
	cout<<solve(n)<<endl;
	//rep(i,0,n+1) cout<<dp[i]<<" ";
	
}
   

Measured memory_bytes: 16836
S=input()
max=0
cnt=0
key=False
li=['A','C','G','T']
for i in S:
    for j in li:
        if i==j:
            key=True
            cnt+=1
            if max<cnt:
                max=cnt
            break
        else:
            key=False
    if key==False:
        cnt=0
print(max)

Measured memory_bytes: 3060
N = int(input())
result_list = []
for i in range(N):
	result_list.append(input())
count_ac = result_list.count("AC")
count_wa = result_list.count("WA")
count_tle = result_list.count("TLE")
count_re = result_list.count("RE")

print("AC x {}".format(count_ac))
print("WA x {}".format(count_wa))
print("TLE x {}".format(count_tle))
print("RE x {}".format(count_re))

Measured memory_bytes: 16284
#include <bits/stdc++.h>
using namespace std;
//#define endl '\n'
typedef long long ll;
ll oo = 0x3f3f3f3f3f3f3f3f;

int main()
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  
  string s, t;
  cin >> s >> t;
  
  vector<vector<int>> dp(s.length() + 1, vector<int>(t.length() + 1));
  
  for(int i = 1; i <= s.length(); ++i)
    for(int j = 1; j <= t.length(); ++j)
    {
      dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
      if(s[i-1] == t[j-1])
        dp[i][j] = max(dp[i][j], dp[i-1][j-1] + 1);
    }
  
  vector<char> ans;
  int i = s.length(), j = t.length();
  while(i != 0 && j != 0)
  {
  	if(dp[i][j] == dp[i-1][j-1] + 1 && s[i-1] == t[j-1])
    {
      ans.push_back(s[i-1]);
      i = i - 1;
      j = j - 1;
    }
    else if(dp[i][j] == dp[i-1][j])
      i = i - 1;
    else
      j = j - 1;
  }
  
  assert(dp[s.length()][t.length()] == (int)ans.size());
  
  if(ans.size())
  {
    for(int i = ((int)ans.size()) - 1; i >= 0; --i)
      cout << ans[i];
    cout << endl;
  }
  else
  {
  	cout << "";
  }
  
}


Measured memory_bytes: 35584
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<math.h>
#include<map>
#include<iomanip>
#include<functional>

using namespace std;
using  ull = unsigned long long int;

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

int main() {

	ull w, h,r;
	ull w1, w2, h1, h2;
	ull m = 9999999999999999999, tmp;
	cin >> h >> w;
	vector<ull>area(3);
	
	rep(i, 1, h) {
		area[0] = i*w;

		if ((h - i) % 2 == 0) h1 = h2 = (h - i) / 2;
		else {
			h1 = (h - i) / 2;
			h2 = 1 + (h - i) / 2;
		}

		if (w % 2 == 0)w1 = w2 = w / 2;
		else {
			w1 = w / 2;
			w2 = 1 + w / 2;
		}

		area[1] = w*h1;
		area[2] = w*h2;

		tmp = *max_element(area.begin(), area.end()) - *min_element(area.begin(), area.end());
		m = min(m, tmp);

		area[1] = w1*(h-i);
		area[2] = w2*(h-i);

		tmp = *max_element(area.begin(), area.end()) - *min_element(area.begin(), area.end());
		m = min(m, tmp);

		
	}

	r = h;
	h = w;
	w = r;

	rep(i, 1, h) {
		area[0] = i*w;

		if ((h - i) % 2 == 0) h1 = h2 = (h - i) / 2;
		else {
			h1 = (h - i) / 2;
			h2 = 1 + (h - i) / 2;
		}

		if (w % 2 == 0)w1 = w2 = w / 2;
		else {
			w1 = w / 2;
			w2 = 1 + w / 2;
		}

		area[1] = w*h1;
		area[2] = w*h2;

		tmp = *max_element(area.begin(), area.end()) - *min_element(area.begin(), area.end());
		m = min(m, tmp);

		area[1] = w1*(h-i);
		area[2] = w2*(h-i);

		tmp = *max_element(area.begin(), area.end()) - *min_element(area.begin(), area.end());
		m = min(m, tmp);


	}
	

	cout << m << endl;

	return 0;
}



Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
	int a,b,c,k;
	cin>>a>>b>>c>>k;
	int n=0;
	while(b<=a)
	{
		b*=2;
		n++;
	}
	while(b>=c)
	{
		c*=2;
		n++;
	}
	if(n>k)
		cout<<"No"<<endl;
	else if(n<=k)
		cout<<"Yes"<<endl;
	return 0;
}

Measured memory_bytes: 3632
#include <stdio.h>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef vector<vector<int>> v2int;
typedef vector<ll> vll;
typedef vector<vector<ll>> v2ll;
typedef list<int> liint;
typedef pair<int, int> pint;
const int INF = int(2e9);
const ll LINF = ll(2e9) * ll(2e9);
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b) { a > b ? : a = b; }
template<class T, class C> void chmin(T& a, C b) { a < b ? : a = b; }



int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int N, A;
 
    cin >> N >> A;
    vint x(N);
    rep(i, N) cin >> x[i];

    vector<v2ll> dp(N + 1, v2ll(N * A + 1, vll(N + 1, 0)));
    dp[0][0][0] = 1;
    rep(i, N) {
        rep(j, A * N + 1) {
            rep(k, N) {

                dp[i + 1][j][k] += dp[i][j][k];
                if (j + x[i] <= N * A) {
                    dp[i + 1][j + x[i]][k + 1] += dp[i][j][k] ;
                }

            }
        }
    }

    ll ans = 0;
    REP(i, 1, N* A + 1) {
        REP(j, 1, N + 1) {
            if (i % A == 0 && i / j == A && i % j == 0) {
                if (dp[N][i][j] == -1) continue;
               
                ans += dp[N][i][j] ;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 56192
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <utility>
#include <set>
#include <stack>
#include <climits>
#include <cmath>

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define rep1(i,n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
#define reps(i,s,n) for(int i=s, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define MEMSET(v, h) memset((v), h, sizeof(v))
typedef long long ll;
const char sp = ' ';


using namespace std;
int H, W, K;
int fiv2[11]={1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024};
bool out(int tate, int index){
    if(index==H-1) return true;
    int val=tate/fiv2[index]%2;
    if(val==1) return true;
    else return false;
}

int main(void){
    string S[10]; int mas[10][1000];
    cin>>H>>W>>K;
    rep(i, H){
        cin>>S[i];
    }
    rep(i, H) rep(j, W){
        mas[i][j]=S[i][j]-'0';
        //cout<<mas[i][j]<<sp;
    }
    rep(i, H) rep(j, W){
        if(i!=0) mas[i][j]+=mas[i-1][j];
        //cout<<mas[i][j]<<sp;
    }
    rep(i, H) rep(j, W){
        if(j!=0) mas[i][j]+=mas[i][j-1];
        //cout<<mas[i][j]<<sp;
    }
    ll Minim=2000;
    rep(tate, (int)pow(2, H-1)){
        
        
        bool possi=true;
        ll count=0;
        ll stat=0; ll pre=0;
        rep(i, H-1){
            if(out(tate, i)==true) count++;
        }
        //cout<<count<<"$"<<endl;
        rep(j, W){
            //cout<<out(tate, 0)<<sp<<out(tate, 1)<<endl;
            stat=0;
            bool over=false;
            rep(i, H){
                if(out(tate, i)==false) continue;
                ll kosu=mas[i][j];
                //cout<<kosu<<sp;
                if(stat!=0) kosu-=mas[stat-1][j];
                //cout<<kosu<<sp;
                if(pre!=0) kosu-=mas[i][pre-1];
                //cout<<kosu<<sp;
                if(pre!=0 && stat!=0) kosu+=mas[stat-1][pre-1];
                //cout<<kosu<<endl;
                if(kosu>K) over=true;
                stat=i+1;
            }
            if(over){
                //cout<<kosu<<endl;
                //cout<<stat<<","<<pre<<sp<<i<<","<<j<<endl;
                if(pre==j){/*cout<<j<<endl;*/possi=false; break;}
                count++; pre=j;
                //cout<<count<<"$$"<<endl;
                continue;
            }
        }
        if(possi) Minim=min(Minim, count);
        
       // cout<<Minim<<sp<<"#"<<sp<<tate<<endl;
        
        
    }
    cout<<Minim<<endl;
    return 0;
}


Measured memory_bytes: 256
/*Allah Vorosha*/
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define ull unsigned long long
#define pb push_back
#define n_p next_permutation
#define p_p prev_permutation
#define in insert
#define rev reverse
#define pf push_front
#define pob pop_back
#define uniq(v)         v.resize(distance(v.begin(),unique(v.begin(),v.end())))
#define all(x) (x).begin(),(x).end()
#define pof pop_front
#define ios ios_base::sync_with_stdio(0);cin.tie();cout.tie();
#define scn scanf
#define prt printf
#define rep(i, a, n) for(int i = a; i < n; i++)
#define mod 1000000007
#define yes cout << "YES\n"
#define no cout << "NO\n";
#define take for(auto &it : a) cin >> it;
#define out cout << a << "\n";
#define l_b lower_bound
#define u_b upper_bound
#define Max 100005
template<typename T> T mymax(T x, T y) {
    return (x > y ? x : y);
}

using namespace std;

const int N = 1e6 + 5;

void solve() {
    string s;
    cin >> s;
    int n = s.size();
    if(s[n - 1] == 's') {
        cout << s;
        cout << "es";
        return;
    }
    cout << s;
    cout << 's';
    return;
}

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


Measured memory_bytes: 3628
str = raw_input()
q = input()
for i in range(q):
    a = raw_input().split()
    if(a[0] == "print"):
        print(str[int(a[1]):int(a[2]) + 1])
    elif(a[0] == "reverse"):
        str = str[0:int(a[1])] + str[int(a[2]):int(a[1]):-1] + str[int(a[1])] + str[int(a[2]) + 1:]
    elif(a[0] == "replace"):
        str = str[0:int(a[1])] + a[3] + str[int(a[2]) + 1:]

Measured memory_bytes: 4248
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
using namespace std;
double ave;
int main() {
  int n;
  int a[103];

  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    ave += a[i];
  }

  ave /= n;
  int mini = 0;
  for (int i = 1; i < n; i++) {
    if (abs(a[i] - ave) < abs(a[mini] - ave)) mini = i;
  }

  cout << mini << endl;
  return 0;
}

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

long long int gcd(long long int a,long long  int b)
{
    if (a == 0)
        return b;
    return gcd(b % a, a);
}

// Function to return LCM of two numbers
long long int lcm(long long int a, long long int b)
{
    return (a*b)/gcd(a, b);
}

int main()
{

    long long int a,b;
    cin>>a>>b;
    cout<<lcm(a,b);

    return 0;

}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys


def solve(N: int, s: "List[int]"):
    s.sort()
    ans = sum(s)

    for i in s:
        if(ans%10 != 0):
            print(ans)
            exit()
        else:
            if(i%10 != 0):
                ans -= i
    if(sum(s) == ans and ans%10 == 0):
        print(0)
    else:
        print(ans)

    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    s = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, s)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <utility>
#include <cmath>
#include <functional>
#include <queue>
//#include <stack>
#include <climits>
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
#define put(a) cout<<a<<endl;
using namespace std;
typedef long long ll;
//typedef unsigned long long ull;
typedef pair<int, int> P;

int h,w;
int a[510][510];
int res[250000][4];

int euc(int a,int b){
    if(a%b==0){
        return b;
    }else if(b%a==0){
        return a;
    }else if(a>b){
        return euc(b,a%b);
    }else{
        return euc(a,b%a);
    }
}

int main() {
    cin >> h >> w;
    REP(i,h){
        REP(j,w){
            cin >> a[i][j];
        }
    }
    int cnt = 0;
    REP(i,h-1){
        REP(j,w){
            if(a[i][j]%2==1){
                res[cnt][0] = i+1;
                res[cnt][1] = j+1;
                res[cnt][2] = i+2;
                res[cnt][3] = j+1;
                a[i][j]--;
                a[i+1][j]++;
                cnt++;
            }
        }
    }
    REP(j,w-1){
        if(a[h-1][j]%2==1){
            res[cnt][0] = h;
            res[cnt][1] = j+1;
            res[cnt][2] = h;
            res[cnt][3] = j+2;
            a[h-1][j]--;
            a[h-1][j+1]++;
            cnt++;
        }
    }
    put(cnt);
    REP(i,cnt){
        cout << res[i][0] << " " << res[i][1] << " " << res[i][2] << " " << res[i][3] << endl;
    }
    return 0;
}


Measured memory_bytes: 6912
using System;
 
class Pencils {
  
  public static void Main(string[] args)
  {
    var input = int.Parse(Console.ReadLine());
    
    var result = GetCounter(input);
    
    Console.WriteLine(result); 
  }
  
  private static string GetCounter(int n){
    int lastDigit = n % 10;
    string result = null;
    
    switch (lastDigit){
      case 0:
      case 1:
      case 6:
      case 8:
        result =  "pon";
        break;
      case 2:
      case 4:
      case 5:
      case 7:
      case 9:
        result = "hon";
        break;
      case 3:
        result = "bon";
        break;
    }
    
    return result;
  }
}

Measured memory_bytes: 27320
/* ---------- STL Libraries ---------- */
// IO library
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>
#include <random>
#include <cstring>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>
#include <stack>

/* ---------- Namespace ---------- */
using namespace std;

/* ---------- Type ---------- */
using ll = long long;
#define int ll
#define P pair<ll, ll>

/* ---------- Constants  */
const double PI = 3.141592653589793238462643383279;
const ll MOD = 1e9 + 7;
const int INF = 1LL << 55;

/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */
signed main() {
    int N, K;
    cin >> N >> K;
    string str;
    cin >> str;
    string ret;

    for (int i = 0; i < N; i++) {
        if (i + 1 == K) ret += tolower(str[i]);
        else ret += str[i];
    }

    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 764
#include <bits/stdc++.h>
#include <math.h>
#define ALL(a)    a.begin(), a.end() 
#define rep(i, K, N)  for(long long int i = K; i < N; i++)
#define ll long long int
using namespace std;

int main() {
double N, K;cin >> N >> K;
double Ans = 0;

    rep(i, 1, N + 1){
    ll j = 0;

        while(i*pow(2, j) < K)j++;

    Ans += 1/(N*pow(2, j));
    }

cout << fixed << setprecision(12) << Ans;
}

Measured memory_bytes: 4240
import collections
n = int(input())
alist = list(map(int,input().split()))
adic = collections.Counter(alist)
A = [0,0]
for i in adic:
  if adic[i] > 1:
    A.append(i)
  if adic[i] > 3:
    A.append(i)
sortedA = sorted(A)
print(sortedA[-1]*sortedA[-2])

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

static const int MAX = 100;
static const int INFTY = (1<<21);
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n, M[MAX][MAX];

int prim(){
  int u, minv;
  int d[MAX], p[MAX], color[MAX];

  for(int i=0;i<n;i++){
    d[i] = INFTY;
    p[i] = -1;
    color[i] = WHITE;
  }

  d[0] = 0;

  while(1){
    minv = INFTY;
    u = -1;
    for(int i=0;i<n;i++){
      if(minv > d[i] && color[i] != BLACK){
        u=i;
        minv = d[i];
      }
    }
    if(u==-1)
      break;
    
    color[u] = BLACK;

    for(int v=0;v<n;v++){
      if(color[v] != BLACK && M[u][v]!=INFTY){
        if(d[v]>M[u][v]){
          d[v] = M[u][v];
          p[v] = u;
          color[v] = GRAY;
        }
      }  
    }
  }
  int sum = 0;
      for(int i=0;i<n;i++){
        if(p[i]!=-1) sum += M[i][p[i]];
      }
      return sum;
}

int main(){
  cin >> n;

  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      int e;
      cin >> e;
      M[i][j] = (e==-1)?INFTY :e;
    }
  }
  cout << prim() << endl;
  return 0;
}


Measured memory_bytes: 3120
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define int long long
#define MAX INT_MAX
#define MIN INT_MIN
#define ss second
#define ff first
const int mod = 1e9+7;

string lcs(string &a, string &b){
	int a_size = a.size();
	int b_size = b.size();
	int ac[2][b_size];
	memset(ac, 0, sizeof(ac));
	int trace[a_size][b_size];
	for(int i = 0; i < a_size; i++){
		for(int j = 0; j < b_size; j++){
			if(a[i] == b[j]){
				ac[i%2][j] = (j-1>=0?ac[((i%2) == 0)?1:0][j-1]:0) + 1;
				trace[i][j] = 1;
			}
			else if(ac[(i%2 == 0)?1:0][j] >= (((j-1)>=0)?ac[i%2][j-1]:0)){
				ac[i%2][j] = ac[(i%2 == 0)?1:0][j];
				trace[i][j] = 0;
			}
			else {
				ac[i%2][j] = (((j-1)>=0)?ac[i%2][j-1]:0);
				trace[i][j] = 2;
			}		
		}
	}
	string ans = "";
	for(int i = a_size-1, j = b_size-1; i >= 0 && j >= 0;){
			if(trace[i][j] == 0)
				i--;
			else if(trace[i][j] == 2)
				j--;
			else {
				ans = a[i] + ans;
				i--;
				j--;
			}
	}
	return ans;
}

int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	string a, b;
	cin >> a >> b;
	cout << lcs(a, b) << endl;
	return 0;
}


Measured memory_bytes: 70656
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import copy

n = int(input())
A = list(map(int,input().split()))

def solve(m, A):
    count = 0
    c = A[0]
    if m == 0 and c <= 0:
        c = 1
        count = abs(A[0]) + 1
    elif m == 1 and c >= 0:
        c = -1
        count = abs(A[0]) + 1

    for a in A[1:]:
        if c * (c+a) >= 0:
            count += abs(a+c) + 1
            c = -1 * c//abs(c);
        else:
            c += a
    return count

print(min(solve(0,A), solve(1,A)))


Measured memory_bytes: 15160
#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;++i)
#include<string>
using namespace std;
typedef long long ll;
typedef pair<int, int>P;
//max=({});
//条件式が真ならwhileの中身を回し続ける

bool flag[1050000];
const int INF = 1001001001;
const int di[] = { -1,0,1,0 };
const int dj[] = { 0,-1,0,1 };

int main() {
	int h, w;
	cin >> h >> w;
	vector<string>s(h);
	rep(i, h)cin >> s[i];
	int ans = 0;
	rep(si, h)rep(sj, w) {
		if (s[si][sj] == '#')continue;
		vector<vector<int>> dist(h, vector<int>(w, INF));
		queue<P>q;
		auto update = [&](int i, int j, int x) {
			if (dist[i][j] != INF)return;
			dist[i][j] = x;
			q.push(P(i, j));
		};
		update(si, sj, 0);
		while (!q.empty()) {
			int i = q.front().first;
			int j = q.front().second;
			q.pop();
			rep(dir, 4) {
				int ni = i + di[dir], nj = j + dj[dir];
				if (ni < 0 || ni >= h || nj < 0 || nj >= w)continue;
				if (s[ni][nj] == '#')continue;
				update(ni, nj, dist[i][j] + 1);
			}
		}
		rep(i, h)rep(j, w) {
			if (dist[i][j] == INF)continue;
			ans = max(ans, dist[i][j]);
		}
	}
	cout << ans << endl;
	return 0;
}


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


#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define intll int long long
const int INF = 1e9;
const int MOD = 1e9 + 7;

int main() {
  string s ;
  cin >> s ;
  string ans = "No";
  rep(i,3){
    if(s.at(i) == '7')
      ans = "Yes";
  }
  
  cout << ans ;


}


Measured memory_bytes: 3616
using System;
using System.IO;
using System.Linq;
using System.Text;

class Program{
    static void Main(string[] args){
        var arr = Console.ReadLine().Split();
        var n = int.Parse(arr[0]);
        var a = int.Parse(arr[1]);
        var b = int.Parse(arr[2]);
        var c = 0;
        var d = 0;
        var s = Console.ReadLine();
        var stringBuilder = new StringBuilder();
        for (int i = 0; i < n; i++){
            if(c < a + b){
                if (s[i] == 'a'){
                    stringBuilder.Append("Yes").AppendLine();
                    c++;
                    continue;}
                if (s[i] == 'b' && d < b){
                    stringBuilder.Append("Yes").AppendLine();
                    c++;
                    d++;
                    continue;}}
            stringBuilder.Append("No").AppendLine();}
        var answer = stringBuilder.ToString();
        var writer = new StreamWriter(Console.OpenStandardOutput()) {AutoFlush = false};
        Console.SetOut(writer);
        Console.WriteLine(answer);
        Console.Out.Flush();}}


Measured memory_bytes: 29420
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <map>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;++i)
#define mod 1000000007

ll s[100100]={0},t[100100]={0},c[100]={0};
ll buc[100100]={0};

ll bu[100100][40]={0};
int main(){
  ll n,C;
  cin >> n >>C;
  ll ans=0;
  rep(i,n){
    cin >> s[i] >> t[i] >> c[i];
    for(int j=s[i];j<=t[i];j++){
      if(bu[j][c[i]]!=0)continue;
      bu[j][c[i]]++;
      //cout << "bu[" << j <<"]["
      //<< c[i] <<"]" << endl;
    }
  }
  rep(i,100010){
    rep(j,40){
      buc[i]+=bu[i][j];
    }
  }
  rep(i,100010){
    ans=max(ans,buc[i]);
  }
  cout << ans << endl;
}


Measured memory_bytes: 33920
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#define llong long long
#define INF (__INT32_MAX__ / 2)
#define EPS 10e-8
#define MAX_N 100000

using namespace std;
typedef pair<int, int> ipair;
llong modulo(llong left, llong right) { return (left % right + right) % right; }

string s, t;
vector<int> pos[26];
int next_alph[MAX_N][26];

llong solve() {
    int cnt = 0;
    int cur_pos = 0;
    for(int i = 0; i < t.size(); ++i) {
        int next_pos = next_alph[cur_pos][t[i] - 'a'];

        if(next_pos == -1) return -1;
        if(next_pos < cur_pos)
            cnt++;
        
        if(i == t.size() - 1) {
            return s.size() * (llong)cnt + next_pos + 1;
        }

        cur_pos = next_pos + 1;
        if(cur_pos == s.size()) {
            ++cnt;
            cur_pos = 0;
        }
    }

}

int main(int argc, char **argv) {
    cin >> s >> t;

    for(int i = 0; i < s.size(); ++i)
        pos[s[i] - 'a'].push_back(i);
    
    for(int i = 0; i < s.size(); ++i)
        for(int ch = 0; ch < 26; ++ch) {
            if(pos[ch].size() == 0)
                next_alph[i][ch] = -1;
            else {
                vector<int>::iterator it = 
                    lower_bound(pos[ch].begin(), pos[ch].end(), i);
                if(it != pos[ch].end())
                    next_alph[i][ch] = *it;
                else
                    next_alph[i][ch] = pos[ch][0];
            }
        }

    cout << solve() << endl;
}

Measured memory_bytes: 11324
// Last Change: 06/01/2019 21:00:59.
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

namespace NS {
void LoopUntilZeroInpput() {
  int hogegegege = 0;
  while (cin >> hogegegege && hogegegege != 0) {
  }
}
} // namespace NS

int main() {
  int N;
  cin >> N;

  cout << 180 * (N - 2) << endl;

  //NS::LoopUntilZeroInpput();
}


Measured memory_bytes: 888
import java.io.IOException;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {
		new Main().run();
	}

	private void run() throws IOException {
		Scanner scanner = new Scanner(System.in);
		while (true) {
			int n = scanner.nextInt();
			int m = scanner.nextInt();
			if ((n | m) == 0)
				break;
			int[][] map = new int[n][n];
			for (int i = 0; i < n; i++) {
				for (int j = 0; j < n; j++) {
					map[i][j] = scanner.nextInt();
				}
			}
			int[][][] p = new int[4][m][m];
			for (int i = 0; i < m; i++) {
				for (int j = 0; j < m; j++) {
					p[0][i][j] = scanner.nextInt();
				}
			}
			for (int k = 1; k < 4; k++) {
				for (int i = 0; i < m; i++) {
					for (int j = 0; j < m; j++) {
						p[k][i][j] = p[k - 1][j][m - i - 1];
					}
				}
			}
			int ay = -1;
			int ax = -1;
			boolean flag = false;
			loop: for (int i = 0; i <= n - m; i++) {
				for (int j = 0; j <= n - m; j++) {
					boolean ff = false;
					a: for (int k = 0; k < 4; k++) {
						ff = true;
						boolean f = false;
						for (int y = 0; y < m; y++) {
							for (int x = 0; x < m; x++) {
								if (p[k][y][x] == -1)
									continue;
								else if (!f) {
									f = true;
									ay = i + y + 1;
									ax = j + x + 1;
								}
								if (p[k][y][x] != map[i + y][j + x]) {
									ff = false;
									continue a;
								}
							}
						}
						if (ff) {
							flag = true;
							break loop;
						}
					}

				}
			}
			System.out.println(flag ? ax + " " + ay : "NA");

		}
	}
}

Measured memory_bytes: 66376
#include<algorithm>
#include<iostream>
#include<vector>
#include<string>
#include<queue>
#include<stack>
#include<cmath>
#include<list>
#include<set>
#include<map>

using namespace std;
long long MOD = 1000000007LL;
template<class T>
T gcd(T x, T y) {
	return y ? gcd(y, x % y) : x;
}

template<class T>
vector<T> enum_div(T n) {
	vector<T> ret;
	for (T i = 1; i * i < n; ++i) {

		if (n % i == 0) {
			ret.push_back(i);

			if (i != 1 && i * i != n) {
				ret.push_back(n / i);
			}
		}
	}
	return ret;
}

template<class T>
map<T, int> prime_factorization(T n) {
	map<T, int> ret;

	for (long long i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			ret[i]++;
			n /= i;
		}
	}

	if (n != 1)ret[n] = 1;
	return ret;
}

template<class T>
long long C(T n, T r) {
	static map<pair<T, T>, long long> _map;
	if (n < r) return 0;

	if (n == r || r == 0) {
		_map[make_pair(n, r)] = 1ll;
	}
	else if (_map[make_pair(n, r)] == 0) {
		_map[make_pair(n, r)] = (C(n - 1, r) + C(n - 1, r - 1));
	}

	_map[make_pair(n, r)] %= MOD;
	return _map[make_pair(n, r)];
}

int main() {
	long long N, K;
	cin >> N >> K;
	if (K % 2 == 0) {
		long long a = N / K;
		long long b = (N + K / 2) / K;
		cout << a * a * a + b * b * b << endl;;
	}
	else {
		long long a = N / K;
		cout << a * a * a << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define _ << ' ' <<
using namespace std;
using ll = long long;

int g[8][8];
int sol;
int main()
{
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < m; ++i)
    {
        int a, b;
        cin >> a >> b;
        a--; b--;
        g[a][b] = g[b][a] = 1;
    }
    int a[8];
    iota(a, a + n, 0);
    do
    {
        bool good = true;
        for (int i = 1; i < n; ++i)
            if (!g[a[i]][a[i - 1]])
                good = false;
        if (good)
            sol++;
    } while (next_permutation(a + 1, a + n));
    cout << sol;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
#include <string>
using namespace std;
const int INF = 2000000005;
int a, b;
char m[105][105];
int wp1, wp2, bp1, bp2;
void wp(int, int);
void bp(int, int);
int main() {
	cin >> a >> b;
	for (int i = 0; i < 100; i++) {
		for (int j = 0; j < 100; j++) {
			if (i < 50) m[i][j] = '#';
			else m[i][j] = '.';
		}
	}
	int wc = 1;
	for (int i = 0; i < 49; i++) {
		for (int j = 0; j < 100; j+=2) {
			if (wc >= a) break;
			if (i % 2 ==0) {
				m[i][j] = '.';
				wc++;
			}
		}
		if (wc >= a) break;
	}
	int bc = 1;
	for (int i = 51; i < 100; i++) {
		for (int j = 0; j < 100; j+=2) {
			if (bc >= b) break;
			if (i % 2 == 0) {
			
				m[i][j] = '#';
				bc++;
			}
		}
		if (bc >= b) break;
	}
	cout << "100 100" << endl;
	for (int i = 0; i < 100; i++) {
		for (int j = 0; j < 100; j++) {
			cout << m[i][j];
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
using namespace std;
   
long long cnt;
int l;
int A[1000000];
int n;
vector<int> G;
   
//間隔gを指定した挿入ソート
void insertionSort(int A[], int n, int g){
  for ( int i = g; i < n; i++) {
    int v = A[i];
    int j = i - g;
    while( j >= 0 && A[j] > v ){
      A[j + g] = A[j];
      j -= g;
      cnt++;
    }
    A[j + g] = v;
  }
}
   
void shellSort(int A[], int n){
  // 数列G = {1, 4, 13, 40, 121, 364, 1093, ..}を生成
  for ( int h = 1; ; ) {
    if ( h > n ) break;
    G.push_back(h);
    h = 3*h + 1;
  }
   
  for ( int i = G.size()-1; i >= 0; i-- ){
    insertionSort(A, n, G[i]);
  }
}
   
int main() {
  cin >> n;
  for ( int i = 0; i < n; i++ ) scanf("%d", &A[i]);
  cnt = 0;
   
  shellSort(A, n);
   
  cout << G.size() << endl;
  for ( int i = G.size() - 1; i >= 0; i-- ){
    printf("%d", G[i]);
    if( i ) printf(" ");
  }
  printf("\n");
  printf("%d\n", cnt);
  for ( int i = 0; i < n; i++ ) printf("%d\n", A[i]);
   
  return 0;
}


Measured memory_bytes: 7172
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define ll long long
const ll inf=1e12;
#define maxn 1000005
using namespace std;
ll n,s;
ll p[maxn];
ll cal(ll b,ll n)
{
    if(n<b)
        return n;
    else
        return cal(b,floor(n/b))+n%b;
}
int main()
         {
             scanf("%lld%lld",&n,&s);
             if(n<s)
             {printf("-1\n");
             return 0;
             }
             if(n==s)
             {
                 printf("%lld\n",n+1);
                 return 0;
             }
             int m=sqrt(n*1.0);
             int flag=0;
             for(ll i=2;i<=m;i++)
                if(cal(i,n)==s)
             {printf("%lld\n",i);
        return 0;

         }
         ll ans=inf;


         for(ll i=1;i*i<=(n-s);i++)
        if((n-s)%i==0)

{
    ll b=(n-s)/i+1;
    if(cal(b,n)==s)
   ans=min(ans,b);


}
        if(ans!=inf)
            printf("%lld\n",ans);
            else
                printf("-1\n");
            return 0;
         }


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

class Program
{
    public static void Main()
    {
        int N = int.Parse(Console.ReadLine());
        int[] c = new int[26];
        for (int i = 0; i < 26; i++)
            c[i] = int.MaxValue;
        for(int i = 0; i < N; i++)
        {
            string s = Console.ReadLine();
            int[] ct = new int[26];
            for (int j = 0; j < s.Length; j++)
                ct[(int)(s[j] - 'a')]++;
            for (int j = 0; j < 26; j++)
                c[j] = Math.Min(c[j], ct[j]);
        }
        string r = "";
        for(int i = 0; i < 26; i++)
        {
            for (int j = 0; j < c[i]; j++)
                r += (char)(i + 'a');
        }
        Console.WriteLine(r);
    }
}

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

ll solve() {
    ll N;
    string S1, S2;
    cin >> N >> S1 >> S2;
    ll mod = 1000000007;
    ll ans = 1;
    int prev = 0;
    for ( int i = 0; i < N; i++ ) {
        if ( S1[i] == S2[i] ) {
            if ( prev == 0 ) {
                ans *= 3;
            } else if ( prev == 1 ) {
                ans *= 2;
            } else {
                ans *= 1;
            }
            prev = 1;
        } else {
            if ( prev == 0 ) {
                ans *= 6;
            } else if ( prev == 1 ) {
                ans *= 2;
            } else {
                ans *= 3;
            }
            prev = 2;
            i++;
        }
        ans %= mod;
    }
    return ans;
}

int main() {
    auto ans = solve();
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>

int main(int argc, const char * argv[]) {
    int i, n, s[1000];
    double m, a;
    
    while(1){
        scanf("%d", &n);
        if(n == 0){
            break;
        }
        m = 0;
        a = 0;
        for(i = 0; i < n; i++){
            scanf("%d", &s[i]);
            m += s[i];
        }
        m /= n;
        for(i = 0; i < n; i++){
            a += (s[i]-m) * (s[i]-m);
        }
        a = sqrt(a/n);
        printf("%f\n", a);
    }
    return 0;
}

Measured memory_bytes: 636
import math

x = int(input())

def is_prime(n):
    if n <= 1:
        return False

    i = 2
    max_n = int(math.sqrt(n))
    while i <= max_n:
        if n % i == 0:
            return False
        i += 1
    return True
    
def next_prime(n):
    while True:
        if is_prime(n):
            return n
        n += 1

print(next_prime(x))

Measured memory_bytes: 3060
#include <iostream>
#include <cstdint>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int, int>> vpii;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
typedef vector<vector<ll>> vvll;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define irep(it, stl) for (auto it = stl.begin(); it != stl.end(); it++)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define mes(a) cout << (a) << endl
#define dmes(a, b) cout << (a) << " " << (b) << endl
#define re0 return 0
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define rSort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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;
}
struct io
{
    io()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
};
const int INF = INT_MAX;
const ll LLINF = 1LL << 60;
const ll MOD = 1000000007;
const double EPS = 1e-9;

bool isPrime(ll x){
    ll i;
    if(x < 2)return 0;
    else if(x == 2) return 1;
    if(x%2 == 0) return 0;
    for(i = 3; i*i <= x; i += 2) if(x%i == 0) return 0;
    return 1;
}

ll gcd(ll a, ll b) {
    return b ? gcd(b, a%b) : a;
}

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

signed main(void)
{
    vll a(3);
    cin >> a[0] >> a[1] >> a[2];
    Sort(a);
    mes(a[0]+a[1]);
    
    
}

Measured memory_bytes: 3612
def distance(s, g):
	return abs(s[0]-g[0]) + abs(s[1]-g[1])

def searchpoint(student, lst):
	min = 1000000000
	ans = -1
	for i in range(0, len(lst)):
		tmp = distance(student, lst[i])
		if tmp < min:
			min = tmp
			ans = i + 1
	return ans

N, M = map(int, raw_input().split())
student = []
for i in range(0, N):
	student.append(map(int, raw_input().split()))
checkpoint = []
for i in range(0, M):
	checkpoint.append(map(int, raw_input().split()))
for i in range(0, N):
	print searchpoint(student[i], checkpoint)

Measured memory_bytes: 2696
#include<iostream>
#include<algorithm>
using namespace std;
int p[200000];

int main() {

	//C
	int n;
	cin >> n;
	int i;
	for (i = 0; i < n; i++) {
		cin >> p[i];
	}
	sort(p, p + n);
	for (i = 0; i < n-1; i++) {
		if (p[i] == p[i + 1]) {
			cout << "NO" << endl;
			return 0;
		}
	}
	cout << "YES" << endl;
	return 0;
	//D
	/*int n, k;
	cin >> n >> k;
	int i;
	for (i = 0; i < n; i++) {
		cin >> p[i];
	}
	int max = 0;
	int sum = 0;
	for (i = 0; i < k; i++) {
		sum = sum + p[i];
	}
	max = sum;
	for (i = k; i < n; i++) {
		sum = sum + p[i] - p[i - k];
		if (sum > max)max = sum;
	}
	//cout << max + k << endl;
	double f = (double)(((double)max +(double) k) / 2);
	printf("%.10f\n", f);
	//cout << (max + k) / 2 << endl;
	return 0;
	*/
}

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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;++A)
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

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

ll A[4];
ll i, j, k;
int main(){
    fornum(i,0,3){
        scanf("%lld", &A[i]);
    }
    sort(A, A + 3);
    if(A[0]==A[2]){
        printf("No");
    }else if(A[0]==A[1]||A[1]==A[2]){
        printf("Yes");
    }else{
        printf("No");
    }
    return 0;
}

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

using namespace std;

int main()
{
  long long a, b, x;
  
  scanf("%lld %lld %lld", &a, &b, &x);
  
  if (b == 0) printf("1\n");
  else if (a == 0) printf("%lld\n", b / x + 1);
  else printf("%lld\n", b / x - (a - 1) / x);
  
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<math.h>
#include<string>
#include <iomanip>
#include<deque>

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
const ll LINF = 1e18;
const int INF = 1e8;

using namespace std;


//マクロ定義
#define vvint(vec,n,m,l) vector<vector<int>> vec(n, vector<int>(m,l));	// lで初期化
#define vvll(vec,n,m,l) vector<vector<ll>> vec(n,vector<ll>(m,l));
#define vint vector<int>
#define pint pair<int,int>
#define rep(i,a) for(int i=0;i<(a);i++)
#define all(x) (x).begin(),(x).end()
#define debug system("pause")				//デバッグ用


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

	int a;
	cin >> a;
	cout << 48 - a << endl;

}

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

int main(){
	int z, k, s, ans=0;
	cin >> k >> s;
	for(int i=0; i<=k; i++){
		for(int j=0; j<=k; j++){
			z = s-i-j;
			if(0<=z && z<=k) ans++;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
////////////////////////////////////////////
///                                      ///
///        Template ver. 1.2. rapel      ///
/// Fear is Temporary, Regret is Forever ///
///          Must Try and Get AC         ///
///                                      ///
////////////////////////////////////////////
#include <stdio.h>
#include <iostream>
#include <sstream>
#include <iomanip>

#include <algorithm>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <utility>

#include <math.h>
#include <complex>

#include <assert.h>
#include <time.h>
#include <chrono>
#include <random>

#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <stack>
#include <list>
#include <bitset>

#define F first
#define S second
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define endl '\n'
using namespace std;

typedef long long ll;
typedef unsigned long long ull;

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

void desperate_optimization(int precision){
  	ios_base::sync_with_stdio(false);
  	cin.tie(0);
  	cout.tie(0);
  	cout.setf(ios::fixed);
  	cout.setf(ios::showpoint);
  	cout.precision(precision);
}

void hora(int tc) {
	ll a, b, n;
	cin>>a>>b>>n;
	ll x = min(n, b - 1);
	cout<<a * x / b - a * (x / b)<<endl;
}

int main(){
	desperate_optimization(10);
	int ntc = 1;
	//cin>>ntc;
	for(int tc = 1;tc <= ntc;tc++) hora(tc);
	return 0;
}


Measured memory_bytes: 3600
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int x = sc.nextInt();
		int[] a = new int[n];
		for(int i = 0;i<n;i++){
			a[i] = sc.nextInt();
		}
		Arrays.sort(a);
		int ans = 0;
		int po = 0;
		for(int i=0;i<n;i++){
			po = po + a[i];
			if(po<=x){
				ans++;
			}else{
				break;
			}
		}
		if(po < x){
			ans--;
		}
		System.out.println(ans);
		
;	}
}


Measured memory_bytes: 23124
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val H, W = sc.nextInt()
  val squares =
    Array.fill(W + 2)('X') +:
      Array.fill(H)('X' +: sc.next().toCharArray :+ 'X') :+
      Array.fill(W + 2)('X')

  val rounds = for (x <- -1 to 1; y <- -1 to 1 if !(x == 0 && y == 0)) yield x -> y
  for (i <- 1 to H; j <- 1 to W if squares(i)(j) != '#') {
    squares(i)(j) = (rounds.count { case (x, y) => squares(i + x)(j + y) == '#' } + '0').toChar
  }

  squares.collect {
    case line if !line.forall(_ == 'X') =>
      line.filterNot(_ == 'X').mkString
  }.foreach(println)
}


Measured memory_bytes: 55920
#include<bits/stdc++.h>
#define int long long
#define N 100005
using namespace std;
typedef pair<int,int> P;

int n, d;
int t[N], F[N];
bool A[N];
int C[N];

main(){

  cin>>n>>d;

  for(int i=0;i<n;i++) cin>>t[i]>>F[i];
  
  for(int i=0;i<n-1;i++)

    if(F[i]-1+F[i+1]-1 <= t[i+1]-t[i]) A[i]=true;

  A[n-1]=true;

  bool ans = true;
  
  if(F[0]-1 > t[0]) ans=false;

  for(int i=0;i<n-1;i++)

    if(t[i+1]-t[i] < abs(F[i]-F[i+1])) ans=false;
  
  
  int cnt=0;
  
  for(int i=0;i<n;i++){

    if(!A[i]) cnt++;
    else{
      
      cnt++;

      if(d<cnt) ans=false;

      cnt=0;      
    }
    
  }

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

    int anstime=0, ti, f;
    
    for(int i=n-1;i>=0;i--){

      if(A[i]){
	
	anstime += F[i]-1;

	f = F[i]-1;

	ti = t[i];
	
      }else{

	anstime += f + ti - t[i];
	
      }
      
    }

    cout<<anstime<<endl;
    
  }
  
}

Measured memory_bytes: 4644
import static java.lang.Math.*;
import static java.util.Arrays.*;
import java.util.*;
import java.io.*;

public class Main {

	void solve() {
		int N = sc.nextInt();
		int[] a = sc.nextIntArray(N);
		
		int ans = Integer.MAX_VALUE;
		for (int c = -100; c <= 100; c++) {
			int y = check(a, c);
			ans = Math.min(ans, y);
		}
		out.println(ans);
	}
	
	int check(int [] a, int c) {
		int res = 0;
		for (int x : a) res += (x - c) * (x - c);
		return res;
	}
	
	static void tr(Object... os) { System.err.println(deepToString(os)); }
	static void tr(int[][] as) { for (int[] a : as) tr(a); }

	void print(int[] a) {
		out.print(a[0]);
		for (int i = 1; i < a.length; i++) out.print(" " + a[i]);
		out.println();
	}

	public static void main(String[] args) throws Exception {
		new Main().run();
	}

	MyScanner sc = null;
	PrintWriter out = null;
	public void run() throws Exception {
		sc = new MyScanner(System.in);
		out = new PrintWriter(System.out);
		for (;sc.hasNext();) {
			solve();
			out.flush();
		}
		out.close();
	}

	class MyScanner {
		String line;
		BufferedReader reader;
		StringTokenizer tokenizer;

		public MyScanner(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream));
			tokenizer = null;
		}
		public void eat() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					line = reader.readLine();
					if (line == null) {
						tokenizer = null;
						return;
					}
					tokenizer = new StringTokenizer(line);
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
		}
		public String next() {
			eat();
			return tokenizer.nextToken();
		}
		public String nextLine() {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		public boolean hasNext() {
			eat();
			return (tokenizer != null && tokenizer.hasMoreElements());
		}
		public int nextInt() {
			return Integer.parseInt(next());
		}
		public long nextLong() {
			return Long.parseLong(next());
		}
		public double nextDouble() {
			return Double.parseDouble(next());
		}
		public int[] nextIntArray(int n) {
			int[] a = new int[n];
			for (int i = 0; i < n; i++) a[i] = nextInt();
			return a;
		}
	}
}

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

int main()
{
    int n,m,num=0;
    long long k;
    cin>>n>>m>>k;
    long long a[n+1],b[m+1];
    memset(a, 0, (n+1)*sizeof(a[0]));
    memset(b, 0, (m+1)*sizeof(b[0]));
    for(int i=0; i<n; i++)
    {
        cin>>a[i+1];
        a[i+1]+=a[i];
    }
    for(int i=0; i<m; i++)
    {
        cin>>b[i+1];
        b[i+1]+=b[i];
    }
    for(int i=0, j=m; i<=n; ++i)// iterate on all possible values of a & b and we start with zero to consider the case of reading all from b
    {
        if(a[i]>k)// if a alone exceeds the sum then break
            break;
        while(a[i]+b[j]>k)// start with the largest value of b possible and decrease until you reach
            --j;
        num=std::max(i+j, num);//use max to store the max value of all possible combinations
    }
    cout << num;
    return 0;
}

Measured memory_bytes: 6736
n = int(input())
a = list(map(int,input().split()))
cnt = 0

for i in range(n):
  tmp = a[i]
  for j in range(99**99):
    if tmp % 2 == 0:
      cnt += 1
      tmp //= 2
    else:
      break
      
print(cnt)
      

Measured memory_bytes: 4148
#include "bits/stdc++.h"

using namespace std;

typedef long long ll;

double Snuke(ll x) {
    ll tmp = 0, c = x;
    while(c) {
        tmp += c % 10;
        c /= 10;
    }
    return 1.0 * x / tmp;
}

int main() {
    int K;
    cin >> K;
    ll res = 0, x = 1;
    while(K--) {
        double t1, t2;
        while(true) {
            t1 = Snuke(res + x), t2 = Snuke(res + x * 10);
            if(t1 <= t2) break;
            x *= 10;
        }
        res += x;
        printf("%lld\n", res);
    }
    return 0;
}


Measured memory_bytes: 256