akhauriyash/Code-Regression huggingface dataset:
/*
  GOOD is not Enough
  You've got to be GREAT.
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
// #include<boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;
using namespace __gnu_pbds;
using namespace std;
#define int long long
#define mod 1000000007
#define FAST ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define f(i,n) for(int i=0;i<n;i++)
#define fp(i,k,n) for(int i=k;i<=n;i++)
#define fr(i,k,n) for(int i=k;i>=n;i--)
#define pb push_back
#define pii pair<int,int>
#define dbg(x) cout << (#x) << " is " << (x) << '\n' 
#define F first
#define S second
#define all(a) a.begin(),a.end()
typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;


void solve()
{ 
  int a,b,n;
  cin >> a>>b>>n;
  int ans=0;
  int x=0;
  x=min(n,b-1);
  cout << (a*x)/b << '\n';
  return;
}

signed main()
{
  FAST
  int T=1;
  // cin >> T;
  while(T--)
  {
    solve();
  }
  return 0;
}

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

//using namespace--------------------------------------------------------------------------------------------------------------
using namespace std;

//define-----------------------------------------------------------------------------------------------------------------------
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define FOR(i, s, n) for(int i = s; i < (int)n; i++)
#define per(i, n) for(int i = n; i >= 0; i--)
#define ROF(i, s, n) for(int i = s; i >= (int)n; i--)
#define FORIT(i, A) for (auto i : A)
#define PRINT(x) cout << (x) << "\n"
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define EACH(i, n) for (__typeof((n).begin()) i = (n).begin(); i != (n).end(); ++i)
#define SZ(a) int((a).size())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define INF 1 << 25
#define CLR(a) memset((a), 0 ,sizeof(a))
#define dump(x) cerr << #x << " = " << (x) << "\n";
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << "\n";
#define sq(n) (n) * (n)

//typedef----------------------------------------------------------------------------------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned int uint;
typedef unsigned long long ull;

//const------------------------------------------------------------------------------------------------------------------------
const double EPS = 1e-10;
const double PI = acos( -1.0 );

//global-----------------------------------------------------------------------------------------------------------------------
int n;
VI a;
int ans;
//function---------------------------------------------------------------------------------------------------------------------
int main() {
	while ( scanf( "%d", &n ) ) {
		if ( !n ) {
			return 0;
		}
		ans = n + 1;
		bool check = false;
		a.resize( n );
		rep( i, n ) {
			scanf( "%d", &a[ i ] );
			if ( !a[ i ] ) {
				ans--;
			}
			if ( a[ i ] >= 2 ) {
				check = true;
			}
		}
		if ( check ) {
			printf( "%d\n", ans );
		}
		else {
			printf( "NA\n" );
		}
	}
	return 0;
}

Measured memory_bytes: 1328
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;

#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=b-1LL;i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;

#define MOD 1000000007

int main() {
  ll n,m;
  cin>>n>>m;
  vector<pair<ll,ll> > v;
  rep(i,0,n){
    ll a,b;
    cin>>a>>b;
    v.pb(mp(b,a));
  }
  sort(all(v));
  ll mn = 5000000000000000000LL;
  rep(i,0,n){
    rep(j,0,n){
      ll x1 = min(v[i].se,v[j].se);
      ll x2 = max(v[i].se,v[j].se);
      ll index1 = 0;
      ll index2 = 1;
      while(1){
        ll y1 = v[index1].fi;
        ll y2 = v[index2].fi;
        ll c = 0;
        rep(k,0,n){
          ll x = v[k].se;
          ll y = v[k].fi;
          if(x1<=x&&x<=x2&&y1<=y&&y<=y2){
            c++;
          }
        }
        if(c<m){
          index2++;
          if(index2>=n){
            break;
          }
        }
        else{
          mn = min(mn,(x2-x1)*(y2-y1));
          index1++;
          if(index1>=n){
            break;
          }
        }
      }
    }
  }
  printf("%lld\n",mn);
  return 0;
}






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

using namespace std;
#define FOR(i,m,M) for(int i = m;i<M;i++)
int main()
{
	int N;
	int res = 0;
	cin >> N;
	int L[2000];

	FOR(i,0,N)
	{
		cin >> L[i];
	}
	sort(L, L + N);

	FOR(i, 0, N)
	{
		FOR(j, i+1, N)
		{
			FOR(k, j+1, N)
			{
				//if (L[i] < L[j] + L[k] && L[j] < L[i] + L[k] && L[k] < L[i] + L[j])
				if (L[k] < L[i] + L[j])
				{
					res ++;
					//break;
				}
			}
		}
	}
	cout << res << endl;
}

Measured memory_bytes: 256
s = list(input())

num_g, num_p = 0, 0
score = 0
for x in s:
    if x == 'g':
        if num_g - num_p > 0:
            score += 1
            num_p += 1
        else:
            score = score
            num_g += 1
    elif x == 'p':
        if num_g - num_p > 0:
            score = score
            num_p += 1
        else:
            score -= 1
            num_g += 1

print(score)


Measured memory_bytes: 71988
from collections import deque


class UnionFind:
    """素集合を木構造として管理する"""
    def __init__(self, n):
        self.parent = [-1] * n
        self.cnt = n

    def root(self, x):
        """要素xの根を求める"""
        if self.parent[x] < 0:
            return x
        else:
            self.parent[x] = self.root(self.parent[x])
            return self.parent[x]

    def merge(self, x, y):
        """要素xを含む集合と要素yを含む集合を統合する"""
        x = self.root(x)
        y = self.root(y)
        if x == y:
            return
        if self.parent[x] > self.parent[y]:
            x, y = y, x
        self.parent[x] += self.parent[y]
        self.parent[y] = x
        self.cnt -= 1

    def is_same(self, x, y):
        """要素x, yが同じ集合に属するかどうかを求める"""
        return self.root(x) == self.root(y)

    def get_size(self, x):
        """要素xを含む集合の要素数を求める"""
        return -self.parent[self.root(x)]


n, m = map(int, input().split())
info = [list(map(int, input().split())) for i in range(m)]

if m % 2 == 1:
    print(-1)
    exit()

uf = UnionFind(n)
tree = [[] for i in range(n)]
out_deg = [0] * n
ans = []
for u, v in info:
    u, v = u - 1, v - 1
    if uf.is_same(u, v):
        ans.append((u + 1, v + 1))
        out_deg[u] += 1
    else:
        uf.merge(u, v)
        tree[u].append(v)
        tree[v].append(u)
        
root = 0
q = deque([root])
par = {0: -1}
topo = []
while q:
    v = q.popleft()
    topo.append(v)
    for nxt_v in tree[v]:
        if nxt_v in par:
            continue
        par[nxt_v] = v
        q.append(nxt_v)
        
while topo:
    v = topo.pop()
    if v == 0:
        break
    if out_deg[v] % 2 == 1:
        out_deg[v] += 1
        ans.append((v + 1, par[v] + 1))
    else:
        out_deg[par[v]] += 1
        ans.append((par[v] + 1, v + 1))

for res in ans:
    print(*res)

Measured memory_bytes: 124420
# -*- coding: utf-8 -*-
N = input()
if int(N) < 10:
    print(N)

elif all(map(lambda x: x == '9', N[1:])):
    print(sum(int(n) for n in N))

else:
    str_n = str(N)
    print(9 * (len(str_n) - 1) + int(str_n[0]) - 1)







Measured memory_bytes: 38384
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<bitset>
#include<unordered_map>
#include <climits>
#include<fstream>
using namespace std;
//---------------------------------------------------
//library zone!!!!!
typedef long long ll;
typedef long double ld;
#define rep(i,j) for(ll i=0;i<(long long)(j);i++)
#define all(a) (a).begin(),(a).end()
const ll Mod = 1000000007;
struct P {
	ll pos, cost;
};
bool operator<(P a, P b) { return a.cost < b.cost; }
bool operator>(P a, P b) { return a.cost > b.cost; }
struct B {
	ll to, cost;
};
struct E {
	ll from, to, cost;
};
bool operator<(E a, E b) {
	return a.cost < b.cost;
}
struct H {
	ll x, y;
};
bool operator<(H a, H b) {
	if (a.x != b.x) return a.x < b.x;
	return a.y < b.y;
}
bool operator>(H a, H b) {
	if (a.x != b.x) return a.x > b.x;
	return a.y > b.y;
}
bool operator==(H a, H b) {
	return a.x == b.x&&a.y == b.y;
}
bool operator!=(H a, H b) {
	return a.x != b.x || a.y != b.y;
}
ll gcd(ll i, ll j) {
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcd(j%i, i);
}
ld mod_pow(ld x, ll n, ll p) {
	ld res = 1;
	while (n > 0) {
		if (n & 1) res = res * x;
		x = x * x;
		n >>= 1;
	}
	return res;
}//x^n%p
const ll Inf = 3023372036854775807;
const int inf = 1500000000;
#define int long long
//----------------------------------------------------
signed main() {
	int a[3];
	cin>>a[0]>>a[1]>>a[2];
	sort(a,a+3);
	cout<<a[0]*a[1]/2<<endl;
	
}


Measured memory_bytes: 256
/*
Though leaves are many , the root is one.
Through all the lying days of my youth
I swayed my leaves and flowers in the sun.
Now I may wither into the truth.
	  	  	- William Butler Yeats
*/
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
//#pragma GCC target("avx,tune=native")
#include<bits/stdc++.h>
#pragma comment("-Wl,--stack=1024000000")
//#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
const int inf=0x3f3f3f3f;
const double eps=1e-6;
const int mod=1000000007;
typedef long long ll;
#ifndef LOCAL
#define cerr if(0)cout
#define eprintf(...) 0
#else
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#endif
inline string getstr(string &s,int l,int r){string ret="";for(int i=l;i<=r;i++)ret.push_back(s[i]);return ret;}
int modpow(int x,int y,int md=mod){int ret=1;do{if(y&1)ret=(ll)ret*x%md;x=(ll)x*x%md;}while(y>>=1);return ret;}
int a[]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
int n;
int main(){
	cin>>n;
	cout<<a[n-1]<<endl;
	return 0;
}

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

int main(){
  int i,slen,joi,ioi;
  char str[10001];

  while(scanf("%s",str)!=EOF){
    for(i=strlen(str)-1,joi=0,ioi=0;i>1;i--){
      if(str[i]=='I'&&str[i-1]=='O'){
	if(str[i-2]=='J'){
	  joi++;
	}else if(str[i-2]=='I'){
	  ioi++;
	}
      }
    }
    printf("%d\n%d\n",joi,ioi);
  }
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
int main() {
  ll n;
  cin>>n;
  if(n==1)cout<<"Hello World"<<endl;
  else{
    ll a,b;
    cin>>a>>b;
    cout<<a+b<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
n, m = gets.split.map(&:to_i)
graph = Array.new(n) { [] }

m.times do
  a, b = gets.split.map(&:to_i)
  graph[a - 1] << b - 1
  graph[b - 1] << a - 1
end

queue = [0]
answer = [0]

until queue.empty?
  current = queue.shift
  graph[current].each do |to|
    next if answer[to]

    answer[to] = current + 1
    queue << to
  end
end

puts 'Yes'
puts answer[1...n]


Measured memory_bytes: 33224
import java.util.Scanner;

public class Main {

    public static void main(String[] args) throws Exception {

    	Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int K = scanner.nextInt();
        int lag[] = new int[N];
        int sum = 0;
        int ave = 0;
        for(int i = 0; i < N; i++){
        	lag[i] = scanner.nextInt();
           	sum += lag[i];
        }
        scanner.close();
        ave = sum / K;
        for (int j = ave;;j++) {
            if(isPossible(K ,j,lag)){
            	System.out.println(j);
            	break;
            }
        }
    }
    //x の車両に y　kgずつz の荷物を詰めるかどうか
    static boolean isPossible(int x,int y, int[] z){
    	int sum=0;
    	int carIndex=0;
    	for(int a=0; a < z.length;a++) {
    		if(sum +z[a] <= y){
    			sum +=z[a];

    		} else {
    			carIndex++;
    			if((z[a] > y) || (carIndex == x)){
    				return false;
    			}
    			sum=z[a];
    		}
    	}
    	return true;
    }
}


Measured memory_bytes: 70728
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<cmath>
#include<string>
#include<bitset>
#include <sstream>
#include<queue>
#include<set>
#include<iomanip>
#define rep(i,n) for(ll i=0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

int main()
{
    int n;
    cin>>n;
    vector< vector<P> > x(n);
    rep(i,n)
    {
        int a;
        cin>>a;
        rep(j,a)
        {
            P p;
            cin>>p.first>>p.second;
            x[i].push_back(p);
        }
    }
    int ans=0;
    for(ll bit=0;bit<(1<<n);bit++)
    {
        bool flag=true;
        int ta=0;
        vector<int> judge(n,-1);
        rep(i,n)
        {
            if(bit &(1<<i))
            {
                judge[i]=1;
                ta++;
            }
            else
            {
                judge[i]=0;
            }
        }
        rep(i,n)
        {
            if(judge[i]==1)
            {
                for(auto itr:x[i])
                {
                    if(judge[itr.first-1]!=itr.second)flag=false;
                }
            }
        }
        if(flag)
        {
            ans=max(ans,ta);
        }
        
        
    }
    cout<<ans;
}

Measured memory_bytes: 888
(defun solver ()
  (let* ((O (string (read))) (E (string (read)))
         (O-len (length O)) (E-len (length E)))
    (cond ((> O-len E-len)
           (loop for i from 0 to (1- E-len) do
                 (format t "~(~A~A~)" (char O i) (char E i)))
           (format t "~(~A~)~%" (char O E-len)))
          ((< O-len E-len)
           (loop for i from 0 to (1- O-len) do
                 (format t "~(~A~A~)" (char O i) (char E i)))
           (format t "~(~A~)~%" (char E O-len)))
          (t
            (loop for i from 0 to (1- O-len) do
                  (format t "~(~A~A~)" (char O i) (char E i)))
            (format t "~%")))))

(solver)

Measured memory_bytes: 14948
#include <bits/stdc++.h>
#include <bitset> 
using namespace std;
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define de(x) cout<<#x<<" = "<<x<<"\n"
#define dd(x) cout<<#x<<" = "<<x<<" "
#define mes(p) memset(p,0,sizeof(p))
#define all(x) x.begin(),x.end()
#define rson mid+1,r,rt<<1|1
#define sz(x) (int)x.size()
#define lson l,mid,rt<<1
#define mp make_pair 
#define pb push_back
#define ls (rt<<1)
#define se second
#define rs (ls|1)
#define fi first
typedef pair <int ,int > pi;
typedef vector <int > vi;
typedef long long ll;
const int maxn=2e6+5;
const int mod= 1e9+7;

int main(){
	ios_base::sync_with_stdio(0);
    cin.tie(0);
    int a , b;
    cin >> a>> b;
    if(a < 10 && b < 10 ) cout << a * b;
    else cout << -1;
	return 0; 
}


Measured memory_bytes: 256
## coding: UTF-8
N = int(input())

ans = [0] * (10**4+10)
for x in range(1, 101):
    for y in range(1, 101):
        for z in range(1, 101):
            #print(x, y, z)
            p = x*x + y*y + z*z + x*y + y*z + z*x
            if(p < 10**4+10):
                ans[p] += 1

#print(ans[:30])
for i in range(N):
    print(ans[i+1])


Measured memory_bytes: 74856
#include <stdio.h>
#define MAX_S 10

int main(){
    int i;
    char s[MAX_S+1], t[MAX_S+1];
    int t_num=0;        //次に打ち込む場所
    
    scanf("%s", s);
    for (i=0; s[i]!='\0'; i++){
        if (s[i] == '0')
            t[t_num++] = '0';
        else if (s[i] == '1')
            t[t_num++] = '1';
        else if (s[i] == 'B')
            if (t_num > 0) t_num--;
    }
    
    for (i=0; i<t_num; i++)
        printf("%c", t[i]);
    printf("\n");
    return 0;
}


Measured memory_bytes: 128
n, m = map(int, input().split())
dl = []
for i in range(n):
  d = list(map(int, input().split()))
  dl.append(d)
dl.sort(key=lambda x: x[0])
rm = m
mc = 0
for i in range(n):
  if dl[i][1] >= rm:
    mc += rm * dl[i][0]
    break
  else:
    mc += dl[i][0] * dl[i][1]
    rm -= dl[i][1]
print(mc)


Measured memory_bytes: 29024
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 1000000007;
typedef long long LL;

struct Edge {
  int u, v;
  LL cost;
  Edge(int a, int b, LL c) : u(a), v(b), cost(c) {}
  bool operator<(const Edge& e) { return cost < e.cost; }
};

struct UnionFindTree {
  std::vector<int> data;

  UnionFindTree(int size) : data(size, -1) { }
  bool Unite(int x, int y) {
    x = Root(x); y = Root(y);
    if (x != y) {
      if (data[y] < data[x]) std::swap(x, y);
      data[x] += data[y];
      data[y] = x;
    }
    return x != y;
  }
  bool IsSameRoot(int x, int y) {
    return Root(x) == Root(y);
  }
  int Root(int x) {
    return data[x] < 0 ? x : data[x] = Root(data[x]);
  }
  int Size(int x) { return -data[Root(x)]; }
};

LL kruskal(int V, vector<Edge>& es) {
  UnionFindTree tree(V);
  LL total_dist = 0LL;

  sort(es.begin(), es.end());  // if you need max cost, use sort(es.rbegin(), es.rend()).
  for (const Edge& e : es) {
    if (!tree.IsSameRoot(e.u, e.v)) {
      tree.Unite(e.u, e.v);
      total_dist += e.cost;
    }
  }
  return total_dist;
}

int main() {
  int N; cin >> N;
  vector<Edge> es;
  vector<pair<int, int>> xs(N), ys(N);
  for (int i = 0; i < N; ++i) {
    cin >> xs[i].first >> ys[i].first;
    xs[i].second = i;
    ys[i].second = i;
  }

  sort(xs.begin(), xs.end());
  sort(ys.begin(), ys.end());

  for (int i = 1; i < N; ++i) {
    es.push_back(Edge(xs[i-1].second, xs[i].second, xs[i].first - xs[i-1].first));
    es.push_back(Edge(ys[i-1].second, ys[i].second, ys[i].first - ys[i-1].first));
  }

  cout << kruskal(N, es) << endl;
}


Measured memory_bytes: 8048
#include <iostream>
using namespace std;
int main()
{
    unsigned long long int h,w;
    cin >> h >> w;
    if(h == 1 || w == 1)
    {
        cout << 1;
    }
    else if(h % 2 == 0)
    {
        cout << w * (h / 2);
    }
    else if(w % 2 != 0)
    {
        cout << w * (h / 2) + w / 2 + 1;
    }
    else
        cout << w * (h / 2) + w / 2;
}


Measured memory_bytes: 256
#gcdは3.4.3だとfractionsにある
from fractions import gcd
import math

from math import factorial as f

from math import ceil,floor,sqrt


import bisect
import re
import heapq


from copy import deepcopy
import itertools

from sys import exit

ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))


def main():
    s,t = input().split()
    a,b = mi()
    u = input()

    if s == u:
        a-=1
    elif t == u:
        b-=1

    print(a,b)



main()


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

int main(){
    int x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;

    int x = x2 - x1;
    int y = y2 - y1;

    cout << x2 - y << " " << y2 + x << " " << x1 - y << " " << y1 + x << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<math.h>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<string>
#include<complex>
#include<unordered_map>

#define INF 1000000000ll
#define MOD 1000000007ll
#define EPS 1e-8

#define REP(i, m) for(long long i = 0; i < m; ++i)
#define FOR(i, n, m) for(long long i = n; i < m; ++i)
#define ALL(v) v.begin(), v.end()
#define pb push_back

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

int main() {
	ios::sync_with_stdio(false);
	vector<int> cnt(26,0);
	string s;
	cin>>s;
	REP(i,s.size()) ++cnt[s[i]-'a'];
	char res='.';
	REP(i,26) {
		if(cnt[i]==0) {
			res='a'+i;
			break;
		}
	}
	if(res=='.') cout<<"None"<<endl;
	else cout<<res<<endl;
}


Measured memory_bytes: 512
#include <cstdio>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <cassert>
#include <numeric>
#include <functional>
#pragma warning(disable:4996) 

typedef long long ll;
typedef unsigned long long ull;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF  9223300000000000000
#define LINF2 1223300000000000000
#define LINF3 1000000000000
#define INF 2140000000
//const long long MOD = 1000000007;
const long long MOD = 998244353;

using namespace std;

char str[305];

ll dp[305][305][305];

void solve()
{
    int K;
    scanf("%s%d", str, &K);
    int n = strlen(str);
    int i, j, k;
    vector<int> a;
    int cnt = 0;
    for (i = 0; i < n; i++) {
        if (str[i] == '1') {
            cnt++;
        }
        else {
            a.push_back(cnt);
            cnt = 0;
        }
    }
    a.push_back(cnt);
    int siz = (int)a.size();
    int sum = 0;
    for (i = 0; i < siz; i++) {
        sum += a[i];
    }
    if (K > sum) {
        K = sum;
    }

    dp[0][0][0] = 1;
    for (i = 0; i < siz; i++) {
        for (j = 0; j <= K; j++) {
            for (k = 0; k <= j; k++) {
                if (dp[i][j][k] == 0) continue;

                int lim0 = MAX(0, a[i] - k);
                int lim1 = a[i] + (K - j);
                int p;
                for (p = lim0; p <= lim1; p++) {
                    int j2 = j, k2 = k;
                    if (p < a[i]) {
                        int diff = a[i] - p;
                        k2 = k - diff;
                    }
                    if (p > a[i]) {
                        int diff = p - a[i];
                        j2 += diff;
                        k2 += diff;
                    }
                    dp[i + 1][j2][k2] = (dp[i + 1][j2][k2] + dp[i][j][k]) % MOD;
                }
            }
        }
    }

    ll ans = 0;
    for (i = 0; i <= K; i++) {
        ans = (ans + dp[siz][i][0]) % MOD;
    }
    printf("%lld\n", ans);

    return;
}


int main(int argc, char* argv[])
{
#if 1
    solve();
#else
    int T;
    scanf("%d", &T);
    int t;
    for(t=0; t<T; t++) {
        //printf("Case #%d: ", t+1);
        solve();
    }
#endif
    return 0;
}


Measured memory_bytes: 57588
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define fi first
#define se second
#define pb push_back

vector<ll> finddivisor(ll x){//整数xの約数が入ったvectorを返すよ(xを含む)  
    vector<ll> divisor;
    for(ll i=1; (i*i)<=x ;i++)
    {
        if(x%i==0){
            divisor.push_back(i);
            if(i*i!=x){
                divisor.push_back(x/i);
            }//約数はペアを持つことを利用

        }
    }
    sort(divisor.begin(),divisor.end());
    //divisor.push_back(x);
    return divisor;
}

signed main(){
    ll n,sum;
    cin >> n;
    vector<ll> v;
    v=finddivisor(n);

    for(int i=0;i<v.size();i++)
    {
        if(v.at(i)==1){
            continue;
        }
        if(n/(v.at(i)-1) == n%(v.at(i)-1)){
            sum+=v.at(i)-1;
        }
        
    }
    cout << sum << endl;
}



Measured memory_bytes: 384
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
#define rep(i,a,b) for (int i = (a); i < (b); i++)
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef complex<double> com;
const int mod = 1e9 + 7;
const int MOD = 998244353;
const int inf = 2e9;



int main() {
	int a, b; cin >> a >> b;
	if (a < 6) printf("0");
	else if (a < 13) printf("%d", b / 2);
	else printf("%d", b);
	return 0;
}


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

using namespace std;

int main(int argc, const char *argv[])
{
  int n;
  cin >> n;
  
  vector<int> v(n);
  int max_n = -1, max_n2 = -1;
  for (int i = 0; i < n; i++) {
    cin >> v[i];
    if (max_n < v[i]) {
      max_n = v[i];
    } else if (max_n2 < v[i]) {
      max_n2 = v[i];
    }
  }

  for (auto a : v) {
    if (max_n == a) {
      cout << max_n2 << "\n";
    } else {
      cout << max_n << "\n";
    }
  }
  return 0;
}

Measured memory_bytes: 2432
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
using namespace std;
typedef long long ll;//注意要开long long
namespace doit{
    inline ll read(){
        ll x=0,p=1;
        char c;
        c=getchar();
        while(c<'0'||c>'9'){
            if(c=='-')
                p=-1;
            c=getchar();
        }
        while(c>='0'&&c<='9'){
            x=x*10+c-'0';
            c=getchar();
        }
        return x*p;
    }
    inline int figure(ll n){
        int len=0;
        while(n){
            n/=10;
            len++;
        }
        return len;
    }
    inline void put(){
        ll n,ans;
        n=read();
        for(register int i=sqrt(n);i>=1;i--)//从sqrt(N)开始找
            if(n%i==0){
                ans=n/i;//就为最优解
                break;
            }
        std::cout<<figure(ans)<<"\n";//输出位数就OK了
    }
}
int main(){
    ios::sync_with_stdio(false);
    doit::put();
}

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

using namespace std;

int n, k;
int a[200005];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> k >> n;
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
    }
    int Ans = a[n] - a[1];
    for (int i = 2; i <= n; i++)
    {
        Ans = min(Ans, k - (a[i] - a[i - 1]));
    }
    cout << Ans;
    return 0;
}


Measured memory_bytes: 1024
#ABC_085_C_Otoshidama.py
N,Y = list(map(int, input().split()))
x=-1
y=-1
z=-1
for a in range(N+1): #number of 10000yen
	for b in range(N+1-a): #number of 5000yen
		c=N-a-b #number of 1000yen
		sum=10000*a + 5000*b + 1000*c
		if sum == Y:
			x=a
			y=b
			z=c
print(x,y,z)

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

int main(){
	string str;
	getline(cin,str);
	for(unsigned int i = 0;i < str.size() ;i++){
		if(str[i]=='a' && str[i+1]=='p' && str[i+2]=='p' && str[i+3]=='l' && str[i+4]=='e'){
			if(i+3 >= str.size()) break;
			else{
				str[i] = 'p';
				str[i+1] = 'e';
				str[i+2] = 'a';
				str[i+3] = 'c';
				str[i+4] = 'h';
			}
		}
		else if(str[i]=='p' && str[i+1]=='e' && str[i+2]=='a' && str[i+3]=='c' && str[i+4]=='h'){
			if(i+3 >= str.size()) break;
			else{
			str[i] = 'a';
			str[i+1] = 'p';
			str[i+2] = 'p';
			str[i+3] = 'l';
			str[i+4] = 'e';
			}
		}
	}
	cout << str << endl;
	return 0;
}

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

int main() {
  int n,ans,way;
  cin >> n;
  vector<int> a(n);
  for(int i=0;i<n;i++){
    cin >> a.at(i);
  }
  
  ans = 0;
  for(int i=0;i<n;i++){
    for(int j=i+1;j<n;j++){
      way = a.at(i) - a.at(j);
      way = max(way,-way);
      ans = max(way,ans);
    }
  }
  
  cout << ans << endl;
  
  return 0;
}


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

typedef long long int ll;
typedef unsigned long long int ull;
#define rep(i,n) for(auto i=0;i<(n);i++)

using namespace std;



int main() {
    vector<ll> v;
    rep(i, 3){
        ll x;
        cin >> x;
        v.push_back(x);
    }

    rep(times, 1e5){
        sort(v.begin(), v.end());

        if(v[0] == v[1] && v[1] == v[2]){
            cout << times << endl;
            break;
        }
        if(v[0]+2 <= v[1]){
            v[0] += 2;
            continue;
        }

        if(v[0]+1 <= v[1]){
            v[0] += 2;
            continue;
        }
        if(v[1]+1 <= v[2]){
            v[0]++;
            v[1]++;
        }

    }
    


    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

const int inf = 999999999;
const double pi = acos(-1);

#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}

///////////////////////////////////////////////////////////////////////////
pair<ull,ull> p[100005] = {};

int main(){
	int n;
	cin >> n;
	ull cnt = 0;

    rep(i,0,n)cin >> p[n-1-i].first >> p[n-1-i].second;
    
	rep(i,0,n){
       ull a = p[i].first,b = p[i].second;
       //cout << a+cnt << " " << b <<  " " ;
       if( a+cnt < b && 0){
            cnt += b-a-cnt;
       }else{
            if((a+cnt)%b != 0){
                
                cnt += b-((a+cnt)%b);  
            }
       } 
       //cout << cnt << endl;
	}

	cout <<cnt << endl;
	
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define INF INT_MAX
#define MOD 1000000007
#define fcout cout << fixed << setprecision(15)
#define priority_queue pque;
typedef long long ll;
typedef pair<int, int> P;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a * b / gcd(a, b);};
int mod(int a,int b){return (a+b-1)/b;};
int month[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){std::fill( (T*)array, (T*)(array+N), val );};
template<class T>inline bool chmax(T& a,T b){if(a < b){a=b;return true;}return false;};
template<class T>inline bool chmin(T& a,T b){if(a > b){a=b;return true;}return false;};



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

  int a;
  cin >> a;
 
  cout << (double)((int)(a/2) + int(a%2))/a;
  return 0;
}


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

int main(){
  string s;
  cin >> s;
  bool ans=true;
  if(s[0]!='A'){
    ans=false;
  }
  int c=-1;
  for(int i=0;i<s.length();i++){
    if(s[i]=='C'){
      if(c!=-1){
        ans=false;
      }
      else{
        c=i;
        if(!(2<=c && c<=s.length()-2)){
          ans=false;
        }
      }
    }
  }
  if(c==-1){
    ans=false;
  }
  for(int i=0;i<s.length();i++){
    if(i==0 || i==c){
      continue;
    }
    else{
      if(!(int('a')<=int(s[i]) && int(s[i])<= int('z'))){
        ans=false;
      }
    }
  }
  if(ans){
    cout << "AC" << endl;
  }
  else{
    cout << "WA" << endl;
  }
}

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

#define FASTIO ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define  ll long long
#define sc second
#define fr first
const int nax = 1e6+5;
const int mod = 1e4+7;
using namespace std;
typedef pair<double,double> pi;
typedef tuple<int,int,int> tu;


signed main()
{
	FASTIO;
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	freopen("error.txt" , "w" , stderr);
    #endif
	int n;
	cin >> n;
	string s;
	cin >> s;
	int c0=0,c1=0;
	for(int i=0;i<n;i++)
	{
		if(s[i] == 'R')
			c0++;
		else
			c1++;
	}

	if(c0==0 || c1 == 0)
	{
		cout << 0 << "\n";
		return 0;
	}

	int cnt=0;
	for(int i=0;i<c0;i++)
	{
		if(s[i] == 'R')
			cnt++;
	}

	cout << c0-cnt << "\n";

}



Measured memory_bytes: 3748
#include<bits/stdc++.h>
#define MAX 100005
using namespace std;

int n;
long long ans, ans2, ans3, a[200002], c, d;

int main(){
  cin >> n >> c >> d;
  ans2 = c;
  ans3 = d;
  for(int i = 0; i < n - 1; i++){
    cin >> a[i * 2] >> a[i * 2 + 1];
    ans2 += a[i * 2];
    ans3 += a[i * 2 + 1];
    if(max(a[i * 2], a[i * 2 + 1]) < max(c, d)){
      swap(a[i * 2], c);
      swap(a[i * 2 + 1], d);
    }
  }
  sort(a, a + 2 * n - 2);
  for(int i = 0; i < n - 2; i++)
    ans += a[i];
  ans += min(c + d, a[n - 2] + a[n - 1]);
  cout << min(ans, min(ans2, ans3));
  return 0;
}


Measured memory_bytes: 1792
package main
import "fmt"

func main() {
  var (
    N int
    A int
  )
  fmt.Scan(&N)
  fmt.Scan(&A)

  fiveHund := N / 500
  remain := N - fiveHund * 500
  
  if (remain <= A) {
    fmt.Println("Yes")
  } else {
    fmt.Println("No")
  }

}


Measured memory_bytes: 512
n, m = map(int,input().split())

odd = 0
even = 0

minimum_number = 0
maximum_number = 0

for i in range(m):
    number = i + 1
    if number % 2 == 1:
        minimum_number = 1 + odd
        maximum_number = (1+m) - odd
        odd += 1
    else:
        minimum_number = m + 2 + even
        maximum_number = 2 * m + 1 - even
        even += 1
    print("{} {}".format(minimum_number, maximum_number))


Measured memory_bytes: 9236
def myAnswer(S:list) -> int:
   N = len(S)+1
   ans = [0]*N
   for i in range(len(S)-1,-1,-1):
      if(S[i] == ">"):
         ans[i] = ans[i+1]+1
   # print(ans)
   for i in range(len(S)):
      if(S[i]== "<"):
         if(ans[i] >= ans[i + 1]):
            ans[i + 1] = ans[i]+1
   # print(ans)
   return sum(ans)
def modelAnswer(S:list) -> int:
   l = [0 for i in range(len(S)+1)]
   for n,s in enumerate(S):
      if(s == "<"):
         l[n+1] = l[n] + 1
   for n,s in enumerate(S[::-1]):
      if(s == ">"):
         tmp = l[len(S) - n] + 1
         if (tmp > l[len(S) - n - 1]):
            l[len(S) -n - 1] = tmp
   return sum(l)
def main():
   S = list(input())
   print(myAnswer(S[:]))
if __name__ == '__main__':
   main()

Measured memory_bytes: 30652
N = int(input())
list_a = [int(x) for x in input().split(' ')]

# sum_a = sum(list_a) % (10**9+7)
# sum_a2 = sum([(x**2) % (10**9+7) for x in list_a])
sum_a = sum(list_a)
sum_a2 = sum([x**2 for x in list_a])

print(((sum_a ** 2 - sum_a2) // 2) % (10**9+7))


Measured memory_bytes: 31320
#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 <cctype>
#include <string>
#include <cmath>

using namespace std;

typedef long long ll;

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

ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }

const int mod = 1000000007;
const int INF = 1001001001;

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

    b = n / a;

    ll ans = (a-1) + (b-1);
    cout << ans << endl;
}

Measured memory_bytes: 256
//Coded by Abhijay Mitra
#include <iostream>
#include <stdlib.h>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <numeric>
#include <vector>
#include <iterator> 
#include <map>
#include <set>
#include <climits>
#include <queue>
#include <cmath>
#include <stack>
#include <cctype>
#include <bitset>
// #include <bits/stdc++.h>
#define double long double
#define int long long int
#define ll int
#define ibs ios_base::sync_with_stdio(false)
#define cti cin.tie(0)
#define bp __builtin_popcount
#define pb emplace_back
#define koto_memory(a) cout<<(sizeof(a)/1048576.0)<<" MB";
#define res(v) sort(all(v)),v.erase(unique(all(v)), v.end());
#define timer cerr << "Time elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \n";
#define deb(x) cout<<"\n["<<#x<<" = "<<x<<"]\n";
using vi = std::vector<int>;
using vvi = std::vector<vi>;
using pii = std::pair<int,int>;
using vpii = std::vector<pii>;
using vvpii = std::vector<vpii>;
#define mp         make_pair
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define per(i,b,a) for (int i = b; i >= a; i--)
#define all(x)     x.begin(), x.end()
using namespace std;
const int N=2e6+10;
const int inf = /*0x3f3f3f3f*/1e18+10;
// const ll M = 998244353 ; // Mulo
// const int M = 1e9+7 ; // Mulo
const double Pi = 3.14159265;
#define F first
#define S second
int n,z,cnt;double tmp;
void solve(){
	cin>>n;map<pii,int>m;
	rep(i,1,n){
		cin>>tmp;int c1=0,c2=0;
		z=llround(tmp*1e9);
		while((z%2)==0)z/=2,c1++;
		while((z%5)==0)z/=5,c2++;
		m[mp(c1,c2)]++;
	}
	for(auto i:m)
		for(auto j:m){
			if(i<j){
				if(i.F.F+j.F.F>=18 and i.F.S+j.F.S>=18)cnt+=i.S*j.S;
			}
			if(i==j){
				if(i.F.F+j.F.F>=18 and i.F.S+j.F.S>=18)cnt+=i.S*(j.S-1)/2;
			}
		}
	cout<<cnt;
}
int32_t main()
{
  ibs;cti;
  solve();return 0;
  /*,cout<<"\n"*/;
  // cout<<"\n";
  int xx=0;
  int t;cin>>t;while(t--){/*xx++;cout<<"Case "<<xx<<":\n"*/;solve();cout<<"\n";}
  return 0;
}

Measured memory_bytes: 3736
local n=io.read("n")

local function f(a,b)
    return math.max(#tostring(a),#tostring(b))
end

local minf=10^10+1
for i=1,math.sqrt(n) do
    if n%i==0 then
        minf=math.min(minf, f(i,n//i))
    end
end
print(minf)

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

int main(){
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  string s;
  cin>>s;
  int g=0;
  int f=0;
  int h=0;
  if(s[0]=='A'){
    g=1;
  }
  for(int i=0;i<s.length();i++){
    if(s[i]>=92){
      h++;
    }
  }
  for(int i=2;i<s.length()-1;i++){
    if(s[i]=='C'){
      f=1;
      i=s.length();
    }
  }
  if(f && h==s.length()-2 && g){
    cout<<"AC";
  }else{
    cout<<"WA";
  }
  
  
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define rep(i,n) for(int i=0;i<n;i++)
#define dev 1000000007 /* 10^9+7 */
string s;
vector<char>ans(4);
int n[4];
bool dfs(int i,int sum){
    if(i==3)return sum==7;
    if(dfs(i+1,sum+n[i+1])){
    	ans[i]='+';
    	return true;
    }
    if(dfs(i+1,sum-n[i+1])){
        ans[i]='-';
        return true;
    }
    return false;
}
signed main(){
    cin>>s;
    rep(i,4)n[i]=s[i]-'0';
    dfs(0,n[0]);
    cout<<n[0]<<ans[0]<<n[1]<<ans[1]<<n[2]<<ans[2]<<n[3]<<"=7"<<endl;
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Math;
using static System.Console;
using System.Text;

class Program
{
    static void Main(string[] args)
    {
        solve();
    }
    static Scanner cin;
    static int N, M;
    static Dictionary<int, List<int>> G;
    static void input()
    {
        cin = new Scanner();
        N = cin.nextInt() - 1;
        M = cin.nextInt() - 1;
        G = new Dictionary<int, List<int>>();
        for(int i = 0; i <= M; i++)
        {
            int a = cin.nextInt() - 1;
            int b = cin.nextInt() - 1;

            if (!G.ContainsKey(a))
                G.Add(a, new List<int>());
            G[a].Add(b);

            if (!G.ContainsKey(b))
                G.Add(b, new List<int>());
            G[b].Add(a);
        }
    }
    static void solve()
    {
        input();
        Queue<int> q = new Queue<int>();
        foreach (var i in G[0])
            q.Enqueue(i);

        foreach(var v in q)
        {
            foreach(var u in G[v])
            {
                if(u == N)
                {
                    WriteLine("POSSIBLE");
                    return;
                }
            }
        }
        WriteLine("IMPOSSIBLE");
    }
    class Scanner
    {
        string[] s;
        int i;

        char[] cs = new char[] { ' ' };

        public Scanner()
        {
            s = new string[0];
            i = 0;
        }
        
        public string next()
        {
            if (i < s.Length) return s[i++];
            string st = Console.ReadLine();
            while (st == "") st = Console.ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            if (s.Length == 0) return next();
            i = 0;
            return s[i++];
        }

        public int nextInt()
        {
            return int.Parse(next());
        }

        public int[] ArrayInt(int N, int add = 0)
        {
            int[] Array = new int[N];
            for(int i = 0; i < N; i++)
            {
                Array[i] = nextInt() + add;
            }
            return Array;
        }

        public long nextLong()
        {
            return long.Parse(next());
        }

        public long[] ArrayLong(int N, long add = 0)
        {
            long[] Array = new long[N];
            for(int i = 0; i < N; i++)
            {
                Array[i] = nextLong() + add;
            }
            return Array;
        }

        public double nextDouble()
        {
            return double.Parse(next());
        }

        public double[] ArrayDounble(int N, int add = 0)
        {
            double[] Array = new double[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextDouble() + add;
            }
            return Array;
        }
    }
}

Measured memory_bytes: 48572
// Author:: MUKUL KUMAR RAI
// Institution:: Jalpaiguri Government Engineering College
//If you are not doing well now just stick to it and learn new things one day you will be...
//Compete with yourself 
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
#define ld long double
#define fi first
#define se second
#define pb push_back
///*template{{{
#define sz(x) (ll)x.size()
#define all(x) (x.begin(),x.end())
#define trav(a,x) for(auto &a:x)
#define fr(i,a,b)  for(ll i=a;i<=b;i++)
#define fr1(i,a)   for(ll i=0;i<a;i++)
#define frr(i,a,b) for(ll i=b;i>=a;i--)
#define frr1(i,a)   for(ll i=a-1;i>=0;i--)
#define sorta(a,n) sort(a,a+n)
#define sortd(a,n) sort(a,a+n,greater<ll>())
#define sortva(a) sort(a.begin(),a.end())
#define sortvd(a) sort(a.begin(),a.end(),greater<ll>())
#define tc(t) while(t--)
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);
using vi= vector<ll>;
using vvi= vector<vi>;
using vb =vector<bool>;
using vc =vector<char>;
using vs =vector<string>;
using vld =vector<ld>;
using pii =pair<ll,ll>;
using psi =pair<string,ll>;
using pci =pair<char,ll>;
using vpii =vector<pii>;
//}}}template*/
ll mod=1e9+7;
ll const maxn=1e3;
ll const inf=1e18;
bool ss(const pair<ll,ll> &a, const pair<ll,ll> &b) { 
    return a.first*b.second+a.second<b.first*a.second+b.second;
}
ll add(ll a,ll b){
    return ((a%mod)+(b%mod))%mod;
}
ll mul(ll a,ll b){
    return ((a%mod)*(b%mod))%mod;
}
ll powm(ll x,ll n,ll M)
{
    ll result=1;
    while(n>0)
    {
        if(n % 2 ==1)
            result=(result * x)%M;
        x=(x*x)%M;
        n=n/2;
    }
    return result;
}
ll modinverse(ll a, ll m){
    return powm(a,m-2,m);
}
bool prime(ll x){
    if(x<=1)return false;
    for(int i=2;i<=sqrt(x);i++)if(x%i==0)return false;
    return true;
}
ll divisor(ll x){
    ll cnt=0;
    for(int i=1;i<=sqrt(x);i++){
        if(x%i==0){
            if(i!=x/i)cnt+=2;
            else cnt+=1;
        }
    }
    return cnt;
}
vector<ll> sieve(ll n) {     
    bool prim[n+1]; 
    memset(prim, true, sizeof(prim)); 
  
    for (ll p=2; p*p<=n; p++) {
        if (prim[p] == true) { 
            for (int i=p*p; i<=n; i += p) 
                prim[i] = false; 
        } 
    }
    vector<ll>v;
    for(int i=2;i<=n;i++)if(prim[i])v.push_back(i);
    return v; 
}
// vvi adj(maxn);
// vb vis(maxn,false);
// ll ans;
// ll dfs(ll u,ll x){
//     vis[u]=true;
//     for(auto v:adj[u]){
//         if(!vis[v]){
//             ans++;
//             if(ans==x)return v;
//             dfs(u,x);
//         }
//     }
//     return -1;
// }
ll fact(ll x){
    ll ans=1;
    fr(i,1,x)ans*=i;
    return ans;
}
ll ncr(ll n,ll r){
    if(r>n)return 0;
    ll ans=fact(n);
    ans/=fact(r);
    ans/=fact(n-r);
    return ans;
}
int main(){
    
    fio;

    ll n;
    cin>>n;
    ll ans=inf;
    for(ll i=1;i<=sqrt(n);i++){
        if(n%i==0){
            if(i!=n/i){
                ll x=min(i,n/i);
                ll y=max(i,n/i);
                y-=x;
                x--;
                x*=2;
                ans=min(ans,x+y);
            }
            else ans=min(ans,2*(i-1));
        }
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<algorithm>
#include<list>
#include <string>
using namespace std;
 
int main(){
    int n,count=0,a;
    cin >> n;
    count = 0;
    for(int i = 0; i < n;i++){
        cin >> a;
        if(a%2!=0)count++;
    }
    string ans ="YES";
    if(count%2!=0)ans ="NO";
    
    cout << ans << endl;
    
    return 0;
 
    
}

Measured memory_bytes: 256
import numpy as np
N = int(input())
p = np.array(list(map(int, input().split())))
v = np.arange(1, N + 1)
# print('p v --', p, v, p == v, np.count_nonzero(p == v))
count = 0
ans = 0
for i in p == v:
    if i:
        count += 1
    else:
        ans += (count + 1) // 2
        count = 0
else:
    ans += (count + 1) // 2

print(ans)


Measured memory_bytes: 25436
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <vector>
#include <deque>
#include <math.h>
#include <map>
#include <bitset>
#include <queue>
#include <list>1
#include <utility>

//#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using ld = long double;
using p = pair<int, int>;
using Graph = vector<vector<char>>;
#define rep(i,n)  for(int i = 0; i < n ; i++)
int dx[4]{ -1,0,1,0 };
int dy[4]{ 0,1,0,-1 };

long gcd(long x, long y) { return (x % y) ? gcd(y, x % y) : y; }
int main()
{
	int K;
	cin >> K;
	ll  ans = 0;
	for (int i = 1; i <= K; i++)
	{
		for (int j = 1; j <= K; j++)
		{
			for (int k = 1; k <= K; k++)
			{
				ll a = gcd(j, k);
				ll b = gcd(i, a);
				ans += b;
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 3636
#include <iostream>
#include <stdio.h>
#include <sstream>
#include <vector>
using namespace std;

#define ll long long
#define fi first
#define se second
#define mp make_pair

#define abs(N) ((N>0)?N:-1*N)
#define min(A,B) ((A>B)?B:A)
#define max(A,B) ((A<B)?B:A)
#define print(S) (cout << S)
#define println(S) (cout << S << endl)

void vdump(vector<int> v){
  for (auto itr = v.begin(); itr != v.end(); ++itr)
  {
    print(*itr);
  }
  println("");
}

int main(int argc, char const *argv[])
{
	int N;
	cin >> N;
	if(N<105){
		println("0");return 0;
	}
	if(N<135){
		println("1");return 0;
	}
	if(N<165){
		println("2");return 0;
	}
	if(N<189){
		println("3");return 0;
	}
	if(N<195){
		println("4");return 0;
	}
	println("5");


	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define check(a,b) if(a.at(j+b) =='#') count++

int main(){
  int H, W, count;
  string prev, row, next;
  cin >> H >> W >> next;
  for (int i=0; i<H; i++){
    prev = row; row = next;
    cin >> next;
    for(int j=0; j<W; j++){
      if(row.at(j) == '#') continue;
      count = 0;
      if(i >= 1){
        if(j-1 >= 0) check(prev,-1);
        check(prev,0);
        if(j+1 < W) check(prev,1);
      }
      if(j-1 >= 0) check(row,-1);
      if(j+1 <W) check(row,1);
      if(i <= H-2){
        if(j-1 >= 0) check(next,-1);
        check(next,0);
        if(j+1 < W) check(next,1);
      }
      row.at(j) = to_string(count).at(0);
    }
    cout << row << endl;
  }
}

Measured memory_bytes: 256
N,M = map(int,input().split())
AB = []*N
AB = [list(map(int,input().split())) for i in range(N)]
    
AB.sort(key = lambda x:x[0])

cost = 0
count = M
i = 0

while count > 0 :
    if count >= AB[i][1]:
        count -= AB[i][1]
        cost += AB[i][1]*AB[i][0]
        i += 1
    else:
        cost += AB[i][0]*count
        count == 0
        break
    
print(cost)

Measured memory_bytes: 29024
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
using namespace std;
 
int cont = 0 , f[101][101] , h , w;
string s[101];
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
 
void dfs(int x,int y,char k){
  f[x][y]=0;
  for(int i=0;i<4;i++){
      int nx = x + dx[i] , ny = y + dy[i];
      if(nx>=0&&nx<h&&ny>=0&&ny<w&&f[nx][ny]&&k==s[nx][ny])dfs(nx,ny,k);
  }
}
  
  
int main(){
  while(cin>>h>>w && h||w){
    cin.ignore();
    for(int i = 0;i <= h;i++){
      for(int j = 0;j <= w;j++){
        f[i][j]=1;
      }
    }
    for(int i = 0;i < h;i++){
      cin>>s[i];
    }
    char k;
    for(int i = 0;i < h;i++){
      for(int j = 0;j < w;j++){
        if(f[i][j]){
          k = s[i][j];
          dfs(i,j,k);
          cont++;
        }
      }
    }
    cout<<cont<<endl;
    cont = 0;
  }
}
 

Measured memory_bytes: 0