akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    vector<int> a(n+1);
    vector<int> b(n);
    for(int i=0;i<n+1;i++){
        cin>>a[i];
    }
    for(int i=0;i<n;i++){
        cin>>b[i];
    }
    long long ans=0;
    for(int i=0;i<n;i++){
        ans+=min(b[i],a[i]);
        b[i]-=min(b[i],a[i]);
        ans+=min(b[i],a[i+1]);
        a[i+1]-=min(b[i],a[i+1]);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>

int main(void){
  
  int sum,sum1,month,in,out,sign;
  while(1){
    month=0;
    sign=0;
    sum1=0;
    scanf("%d",&sum);
    if(sum==0)
      break;
    while(1){
      scanf("%d %d",&in,&out);
      sum1+=in-out;
      month++;
      if(sum1 >=sum && sign==0){
	sign=month;
      }
      if(month == 12){
	break;
      }
    }
    if(sign!=0)
      printf("%d\n",sign);
    else
      printf("NA\n");
  }
  return 0;
}

Measured memory_bytes: 612
#include<bits/stdc++.h>
using namespace std;
int n,k,f[2005][2005],s[2005][2005],t;
int S(int i,int j)
{
    return i>=0&&j>=0?s[min(t-1,i)][min(t-1,j)]:0;
}
int get(int i,int j)
{
    return S(i,j)-S(i,j-k)-S(i-k,j)+S(i-k,j-k);
}
int main()
{
    cin>>n>>k;
    t=k*2;
    string st;
    for(int i=0,x,y; i<n; i++)
    {
        cin>>x>>y>>st;
        if(st=="B")x+=k;
        f[x%t][y%t]++;
    }
    for(int i=0; i<t; i++)
        for(int j=0; j<t; j++)
            s[i][j]=S(i,j-1)+f[i][j];
    for(int i=0; i<t; i++)
        for(int j=0; j<t; j++)
            s[i][j]+=S(i-1,j);
    int ans=0;
    for(int i=0; i<t; i++)
        for(int j=0; j<t; j++)
            ans=max(ans,get(i,j)+get(i-k,j-k)+get(i-k,j+k)+get(i+k,j-k)+get(i+k,j+k)+get(i+t,j)+get(i,j+t));
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 31616
def main():
    import sys
    def input():
        return sys.stdin.readline()[:-1]
    S=input()
    T=input()
    a=len(S)
    n=0
    for i in range(a):
        if S[i]!=T[i]:
            n+=1
    print(n)
if __name__ == '__main__':
    main()



Measured memory_bytes: 9432
#include<bits/stdc++.h>
using namespace std;
int n,ri,le;
struct node{
	int x,y;
}a[1000005];
int tot;
char s[1000005];
int cmp(node a,node b){
	return a.x-a.y>b.x-b.y;
}
int main(){
	//n=read();
	int i,j;
	scanf("%d",&n);
	for(i=1;i<=n;i++){
		int l=0,r=0;
		scanf("%s",s+1);
		for(j=1;s[j];j++)
			if(s[j]=='(')l++;
			else if(s[j]==')'){
				if(l)l--;
				else r++;
			}
		if(!l&&r)ri+=r;
		else if(l&&!r)le+=l;
		else if(l&&r)a[++tot]=(node){l,r};	
	}
	sort(a+1,a+1+tot,cmp);
	for(int i=1;i<=tot;i++){
		if(le<a[i].y)
			return puts("No"),0;
		le-=a[i].y-a[i].x;
	}
	if(le!=ri)puts("No");
	else puts("Yes");
	return 0;
}

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

#define MaxN 100005
#define INF 2140000000
using namespace std;

int N,X,Size=0,P[MaxN],Ans=0;



int main()
{
    cin>>N;
    for(int i=1;i<=N;i++)
    {
        cin>>P[i];
        if(P[i]==i)
            Ans++;
    }
    for(int i=1;i<N;i++)
        if(P[i]==i&&P[i+1]==i+1)
            Ans--,P[i]=0,P[i+1]=0;
    cout<<Ans;
    return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>

using namespace std;


void green_bin()
{
  int n;
  cin >> n;
  map<string, int> S;
  for (int i = 0; i < n; ++i) 
  {
    string s;
    cin >> s;
    sort(s.begin(), s.end());
    S[s]++;
  }

  long long int ana_num = 0;
  for (auto value : S)
    for (int cnt = value.second - 1; cnt > 0; --cnt) 
      ana_num += cnt;
 
  cout << ana_num << "\n";
}


void alchemist()
{
  int n;
  cin >> n;
  vector<int> v(n);
  for (int i = 0; i < n; ++i) cin >> v[i];

  sort(v.begin(), v.end());

  double v_sum = v[0];
  for (int i = 1; i < n; ++i) v_sum = (v_sum + v[i]) / 2;

  cout << v_sum << "\n";
}


void lower_atc()
{
  int n;
  cin >> n;
  vector<int> h(n);
  for (int i = 0; i < n; ++i) cin >> h[i];

  int tmp = 0, v_max = 0;
  for (int i = 0; i < n; ++i)
  {
    if ((i != n - 1) && h[i] >= h[i + 1]) ++tmp;
    else
    {
      v_max = max(v_max, tmp);
      tmp = 0;
    }
  }

  cout << v_max << "\n";
}


void maximal_value()
{
  int n;
  cin >> n;
  vector<int> b(n - 1);
  for (int i = 0; i < n - 1; ++i) cin >> b[i];

  vector<int> a(n);
  for (int i = 0; i < n; ++i)
  {
    if (i == 0)          a[i] = b[i];
    else if (i == n - 1) a[i] = b[i - 1];
    else                 a[i] = min(b[i - 1], b[i]);
  }

  cout << accumulate(a.begin(), a.end(), 0) << "\n";
}


int main()
{
  green_bin();
  //alchemist();
  //lower_atc();
  //maximal_value();
}


Measured memory_bytes: 11136
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>	// upper_bound(A, A+N, num), lower_bound(A, A+N, num)
#include <functional>
#include <string>
#include <sstream>
#include <complex>
#include <vector>		// V[i],  push_back(x), pop_back(), insert(index, x), erase(index), sort(v.begin(), v.end(), greater<int>())
#include <list>			// push_front(x), push_back(x), pop_front(), pop_back(), insert(index, x)
#include <queue>		// push(x), front(), pop()
#include <deque>
#include <stack>		// push(x), top(), pop()
#include <map>			// M[key],  insert(key, val), erase(key), find(key), 
#include <set>			// insert(key), erase(key), find(key)

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

#define PI 3.141592653589793)
#define MOD 1000000007
#define REP(i, n) for(int i = 0; i < n; i++)

int N, A, B;
int h[100001];

bool enough(int t) {
	ll cnt = 0LL;
	for (int i = 0; i < N; i++) {
		ll top = (ll)h[i] - (ll)B*t;
		if (top <= 0) continue;
		cnt += top / (A - B);
		if (top % (A - B)) cnt++;
	}
	return cnt <= (ll)t;
}

void solve() {
	cin >> N >> A >> B;
	for (int i = 0; i < N; i++) cin >> h[i];

	int lb = 0, ub = 1000000001;	
	while (ub - lb > 1) {
		int mid = (lb + ub) / 2;
		if (enough(mid)) ub = mid;
		else lb = mid;
	}
	cout << ub << endl;
}

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

Measured memory_bytes: 640
#include <iostream>
#include <math.h>

using namespace std;

int main()
{
	long A, B, tmp, r;
	long x, Y;
	cin >> A >> B;
	x = A * B;
	if (A < B) {
		tmp = A;
		A = B;
		B = tmp;
	}

	/* ユークリッドの互除法 */
	r = A % B;
	while (r != 0) {
		A = B;
		B = r;
		r = A % B;
	}
	Y = x / B;
	cout << Y << endl;
	return 0;
}


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

#define all(x) (x).begin(), (x).end()
#define szof(x) int32_t((x).size())
#define str(x) to_string(x)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;

const ll MOD = 1e9 + 7;
const ll MOD998 = 998244353;
const int INF = 1e9;
const ll LLINF = 1e18;

mt19937_64 rng((uint) chrono::steady_clock::now().time_since_epoch().count());

template <class T>
T rnd(T l, T r) {
	return uniform_int_distribution<T>(l, r)(rng);
}

void run() {
	string n;
	cin >> n;
	for (auto &ch : n) {
		ch -= '0';
	}
	int d;
	cin >> d;
	int k = szof(n);
	vector<vector<vector<int>>> dp(k + 1, vector<vector<int>>(d, vector<int>(2)));
	dp[0][0][0] = 1;
	auto add = [](int &x, int y) {
		x += y;
		if (x >= MOD) {
			x -= MOD;
		}
	};
	for (int l = 1; l <= k; l++) {
		for (int rem = 0; rem < d; rem++) {
			for (int digit = 0; digit < 10; digit++) {
				if (digit < n[l - 1]) {
					add(dp[l][(rem + digit) % d][1], dp[l - 1][rem][0]);
					add(dp[l][(rem + digit) % d][1], dp[l - 1][rem][1]);
				} else if (digit == n[l - 1]) {
					add(dp[l][(rem + digit) % d][0], dp[l - 1][rem][0]);
					add(dp[l][(rem + digit) % d][1], dp[l - 1][rem][1]);
				} else {
					add(dp[l][(rem + digit) % d][1], dp[l - 1][rem][1]);
				}
			}
		}
	}
	cout << ((dp[k][0][0] + dp[k][0][1]) % MOD + MOD - 1) % MOD << "\n";
}

int32_t main() {
	ios::sync_with_stdio(0); cin.tie(0);
	cout.precision(10); cout << fixed;
	int tests = 1;
	// cin >> tests;
	while (tests--) {
		run();
	}
	cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << "s.\n";
	return 0;
}


Measured memory_bytes: 55424
// a template for main.cpp
#include <bits/stdc++.h>
#define ll long long
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string a = "ARC", b  = "ABC";
    string s;
    cin >> s;
    if (s == a) cout << b;
    else cout << a;
    cout << endl;
}


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

int main(){
    int n;
    cin >>n;
    bool flag=false;
    for(int i=1; i<10; i++){
        int a=n/i;
        if(a*i==n&&a<10){
            cout << "Yes";
            flag=true;
            break;
        }
    }
    if(!flag)cout << "No";
    cout << endl; 
}

Measured memory_bytes: 256
object Main extends App {
  @scala.annotation.tailrec
  def loop(n: Int, s: String, t: String): Int =
    if (n == 0 || s == t) n else loop(n - 1, s.tail, t.init)

  val sc = new java.util.Scanner(System.in)
  val N = sc.nextInt()
  val s, t = sc.next()
  println(N * 2 - loop(N, s, t))
}


Measured memory_bytes: 55196
#pragma region Macros
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i, n) for(int i=(n); i>=0; --i)
#define FOR(i, n, m) for(int i=(m), i##_len=(n); i<i##_len; ++i)
#define EACH(i, v) for(const auto& i : v)
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<class Value>using vec = vector< Value >;
using ll = long long;
using P = pair< long long, long long >;
#define fi first
#define se second
#define el endl
#pragma endregion
void Main();

int main(){
    std::cin.tie(nullptr);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}

bool f(string& S, int n){
    bool ret = true;
    REP(i, n){
        if(S[i] != S[i+n]){
            ret = false;break;
        }
    }
    return ret;
}

void Main(){
    int N;
    cin >> N;
    map<int, int> mp;
    REP(i, N){
        int a;
        cin >> a;
        mp[a-1]++;
        mp[a]++;
        mp[a+1]++;
    }
    int mx=0, mx_i=0;
    EACH(i, mp){
        if(chmax(mx, i.se)){
            //mx_i = 
        }
    }
    cout << mx << el;
}



Measured memory_bytes: 7924
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define pb push_back
#define N 200100
#define mod 1000000007
#define MOD 998244353
#define fn(i,n) for(int i=0;i<n;i+=1)
#define rep(i,l,r) for(int i=l;i<=r;i+=1)
#define INF 100000000000000000
#define pii pair<int,int>
#define speed ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
int a[N];
int b[N];
int c[N];
signed main()
{
    
    speed
    map<int,int> m1,m2;
    int n;cin>>n;
    rep(i,1,n){
    	cin>>a[i];
    	m1[i-a[i]]+=1;
    	m2[i+a[i]]+=1;
    }
    int ans=0;
    for(auto it:m1){
    	ans+=it.second*(m2[it.first]);
    }
    cout<<ans<<endl;




    

 
    return 0;
}

Measured memory_bytes: 39500
N,T = map(int, input().split())
t = list(map(int, input().split()))
total = 0 

for i in range(N-1):
    if t[i+1] - t[i] < T:
        total += t[i+1] - t[i]
    else:
        total += T
total += T
print(total)

Measured memory_bytes: 25196
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
using namespace std;

signed main() {
	int H, W, h, w, ans;
	cin >> H >> W;
	cin >> h >> w;
	ans = H * W - (h*W + w * H - h * w);
	cout << ans << endl;
}

Measured memory_bytes: 256
#dt = {} for i in x: dt[i] = dt.get(i,0)+1
import sys
input = sys.stdin.readline
ipnl = lambda n: [int(input()) for _ in range(n)]
inp = lambda :int(input())
ip = lambda :[int(w) for w in input().split()]

n = inp()
x = ip()
ans = [0]*n
no = x[0]
for i in range(1,n):
    no = x[i]^no
for i in range(n):
    ans[i] = x[i]^no
print(*ans)

Measured memory_bytes: 96212
import heapq
def dijkstra_heap(s):
    d = [float("inf")]*n
    used = [True] * n
    d[s] = 0
    used[s] = False
    edgelist = []
    for e in edge[s]:
        heapq.heappush(edgelist,e)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        if not used[minedge[1]]:
            continue
        v = minedge[1]
        d[v] = minedge[0]
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,[e[0]+d[v],e[1]])
    return d
n = int(input())
edge = [[] for i in range(n)]
for i in range(n-1):
    x,y,z = map(int,input().split())
    edge[x-1].append([z,y-1])
    edge[y-1].append([z,x-1])
Q,K = map(int,input().split())
L = dijkstra_heap(K-1)
query = []
for i in range(Q):
  query.append(list(map(int,input().split())))
for i in range(Q):
  print(L[query[i][0]-1]+L[query[i][1]-1])

Measured memory_bytes: 74124
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <set>
#include <stack>
#include <bitset>
#include <map>
#include <ctime>


#ifndef M_PI
#define M_PI 3.141592653589
#endif
#define int long long
#define double long double
#define f(variable, start, end) for (int variable = start; variable < end; ++variable)
#define be(a) a.begin(), a.end()
#define no cout << "NO\n"
#define yes cout << "YES\n"
#define nor cout << "NO\n"; return
#define yesr cout << "YES\n"; return
#define vi vector<int>
#define vvi vector<vector<int>>
#define vp vector<pair<int, int>>


using namespace std;


template<typename T, typename E>
vector<T> &operator>>(vector<T> &v, E a) {
    v.push_back(a);
    return v;
}

//pair output
template<typename E>
ostream &operator<<(ostream &os, pair<E, E> &t) {
    os << t.first << ' ' << t.second;
    return os;
}

//"map" pair output
template<typename E>
ostream &operator<<(ostream &os, pair<const E, E> &t) {
    os << t.first << ' ' << t.second;
    return os;
}

//vector output
template<typename T>
ostream &operator<<(ostream &os, vector<T> &vec) {
    for (T i : vec) {
        os << i << ' ';
    }
    return os;
}

//2 dimensional vector output
template<typename T>
ostream &operator<<(ostream &os, vector<vector<T> > &vec) {
    for (vector<T> i : vec) {
        os << i << '\n';
    }
    return os;
}

//vector<pair<T, E>> output
template<typename T, typename E>
ostream &operator<<(ostream &os, vector<pair<T, E>> &vec) {
    for (pair<T, E> i : vec) {
        os << i.first << ' ' << i.second << '\n';
    }
    return os;
}


int32_t main() {
    cin.tie(NULL);
    cout.tie(NULL);
    cout.setf(ios::fixed);
    cout.precision(10);
    ios_base::sync_with_stdio(false);
#ifdef TIME
    int32_t start = clock();
#endif

    int a;
    cin >> a;
    cout << a + a * a + a * a * a;

#ifdef TIME
    cout << "\ntime: " << (clock() - start) / (CLOCKS_PER_SEC * 1.0);
#endif

    return 0;
}

Measured memory_bytes: 3648
S = input()

if len(S) % 2 != 0:
  print("No")
  exit(0)

for i in range(len(S) // 2):
  s = S[2 * i: 2 * (i + 1)]
  if s != "hi":
    print("No")
    exit(0)
    
print("Yes")

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

#define ll long long int
#define mp make_pair
#define ff first
#define ss second
#define fr(i,l,r) for (long long int i = l; i < r; ++i)
#define frr(i,l,r) for (long long int i = r; i >= l; --i) 
#define sortarr sort(arr,arr+n) //sorts array in asc order
#define sortarr_r sort(arr, arr+n, greater<long long int>()) //sorts array in desc order
#define make_set set<long long int>s //Set arranges in asc order
#define make_set_r set<long long int, greater <long long int>>s ////Set arranges in desc order
#define make_vector vector<long long int>v; 
#define pb push_back


// string size = str.size()

// stack <int> s; 
// queue <int> gquiz; 
// __gcd(m, n) 

// ll arr[10e5 + 5];
// char arr[10e5 + 5];


bool compare(string &s1,string &s2) 
{ 
    return s1.size() < s2.size(); 
} 
void yes()
{
    cout << "YES" << endl;
}
void no()
{
    cout << "NO" << endl;
}


int main(void)
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    ll t;
    // cin >> t;
    // while(t--)
    // {
        ll n,m;
        cin >> n >> m;
        cout << (n * (n-1))/2 + (m * (m-1))/2 << endl;
    // }
    return 0;
}   

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

int main()
{
	int a, b;
	cin >> a >> b;

	auto temp = b;
	if (b < 10)
	{
		temp += a * 10;
	}
	else if (b < 100)
	{
		temp += a * 100;
	}
	else
	{
		temp += a * 1000;
	}

	string result = "No";
	for (auto i = 1; i < 400; ++i)
	{
		if (i * i == temp)
		{
			result = "Yes";
			break;
		}
	}

	cout << result << endl;

	return 0;
}


Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    b = input()

    if b == "A":
        print("T")
    elif b == "T":
        print("A")
    elif b == "C":
        print("G")
    else:
        print("C")


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 2940
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>

using namespace std;

const int MAXN = 100000 + 1000;

int n;
int f[MAXN], h[MAXN];
vector<int> edg[MAXN];

void dfs(int x, int fa)
{
	f[x] = 0;
	for(int i = 0; i < edg[x].size(); i++)
		if(edg[x][i] != fa)
		{
			int y = edg[x][i];
			dfs(y, x);
			f[x] ^= (f[y] + 1);
		}
}

int main()
{
	ios::sync_with_stdio(false);
	// freopen("1.in", "r", stdin);
	// freopen("1.out", "w", stdout);

	cin >> n;
	for(int i = 1; i <= n - 1; i++)
	{
		int x, y;
		cin >> x >> y;
		edg[x].push_back(y);
		edg[y].push_back(x);
	}
	dfs(1, 0);
	cout << (f[1] ? "Alice" : "Bob") << endl;

	return 0;
}


Measured memory_bytes: 13952
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> ii;
typedef vector<int>   vi;
typedef vector<long long> vll;
typedef vector<pair<int,int> > vii;
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define pq priority_queue
#define mii map<int,int>
#define sf1(x) scanf("%d",&x)
#define sf2(x,y) scanf("%d %d",&x,&y)
#define sf3(x,y,z) scanf("%d %d %d",&x,&y,&z)
int inf = (1e9) + 7;
int mod = 998244353;


vi v;
int n;
ll s(int idx, ll acc){
    if(idx == n and !(acc % 2))
        return 1;
    if(idx == n)
        return 0;

    ll aux = 0;

    for (int i = -1; i < 2; ++i)
    {
        aux += s(idx+1,acc * (v[idx]+i));
    }

    return aux;

}


int main(){


    ll ans = 0;

    sf1(n);

    int x;
    for (int i = 0; i < n; ++i)
    {
        sf1(x);
        v.pb(x);
    }

    printf("%lld\n",s(0,1LL));

}   

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

int main() {
	int n, i, C=0;
	double min, t, h[1000], a;

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


	min = fabs(a - (t - h[0] * 0.006));
	for (i = 0;i < n;i++) {
		if (min > fabs(a-(t - h[i] * 0.006))) {
			min = fabs(a-(t - h[i] * 0.006));
			C = i;
		}
	}

	printf("%d\n", C + 1);

	return 0;
}

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

int main(){

    string W;
    string word;
    int count=0;

    cin >> W;
    while(1){
        cin >> word;
        if(word=="END_OF_TEXT") {
            break;
        }else{
            for(int i=0; i<word.size(); i++){
                word[i] = tolower(word[i]);
            }
            if (word==W) count++;
        }
    }
    cout << count <<endl;
    return 0;
}


Measured memory_bytes: 3216
N = int(input())
A = list(map(int, input().split()))
ans = 0
flag = True
while flag:
    flag = False
    for i in range(N):
        if A[i] >= N:
            count = A[i] // N
            ans += count
            for j in range(N):
                A[j] += count
            A[i] -= count
            A[i] %= N
            flag = True

print(ans)


Measured memory_bytes: 41452
c = [list(map(int,input().split())) for i in range(3)]
x = [0] * 3
y = [0] * 3
for i in range(3):
    y[i] = c[0][i] - x[0]
for i in range(3):
    x[i] = c[i][0] - y[0]

flag = True
for i in range(3):
    for j in range(3):
        if x[i] + y[j] != c[i][j]:
            flag = False
if flag:
    print("Yes")
else:
    print("No")

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

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define ALL(x) (x).begin(), (x).end()

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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1e15;
const ll MOD = 1e9 + 7;

ll dp[60][510][510];

int main() {
  ll n, ma, mb;
  cin >> n >> ma >> mb;
  vector<ll> a(n), b(n), c(n);
  REP(i, n) cin >> a[i] >> b[i] >> c[i];

  REP(i, 50) REP(j, 500) REP(k, 500) { dp[i][j][k] = INF; }

  dp[0][0][0] = 0;
  REP(i, n) REP(j, 500) REP(k, 500) {
    if (dp[i][j][k] >= INF) continue;
    chmin(dp[i + 1][j][k], dp[i][j][k]);
    chmin(dp[i + 1][j + a[i]][k + b[i]], dp[i][j][k] + c[i]);
  }

  ll ans = INF;
  FOR(j, 1, 500) FOR(k, 1, 500) {
    if (j * mb == k * ma) {
      chmin(ans, dp[n][j][k]);
    }
  }
  if (ans == INF)
    cout << -1 << endl;
  else
    cout << ans << endl;
  return 0;
}

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

int main() {
  int n, m;
  cin >> n >> m;
  vector< vector<ll> > a(n, vector<ll>(3));
  for (int i = 0; i < n; i++) {
    cin >> a[i][0] >> a[i][1] >> a[i][2];
  }
  ll ans = 0;
  for (int b = 0; b < 8; b++) {
    vector<ll> can;
    for (int i = 0; i < n; i++) {
      ll s = 0;
      for (int k = 0; k < 3; k++) {
        if ((1<<k)&b) {
          s += a[i][k];
        } else {
          s -= a[i][k];
        }
      }
      can.push_back(s);
    }
    sort(can.begin(), can.end(), greater<ll>());
    ll cansum = 0;
    for (int i = 0; i < m; i++) {
      cansum += can[i];
    }
    ans = max(ans, cansum);
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 256
#include<algorithm>
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<map>
#include<vector>
using namespace std;
const int maxn = 112345;
int n,cnt,ans;
bool vis[maxn];
map<string,int> mp;
vector<int> G[maxn];
void init()
{
	for(int i=0;i<maxn;i++)
		G[i].clear();
	mp.clear();
	memset(vis,0,sizeof(vis));
	cnt=ans=0;
}
int get_ID(string s)
{
	if(!mp.count(s))
		return mp[s]=++cnt;
	else
		return mp[s];
}
void dfs(int u)
{
	vis[u]=1;
	if(G[u].size()==0) ans++;
	for(int i=0;i<G[u].size();i++)
	{
		int v=G[u][i];
		if(!vis[v])
		{
			dfs(v);
		}
	}
}
int main()
{
	string s;
	while(~scanf("%d",&n)&&n)
	{
		init();
		for(int i=0;i<n;i++)
		{
			cin>>s;
			int last=0,now=0;
			while(now<s.size())
			{
				int t,v;
				if(s[now]==':')
				{
					v=get_ID(s.substr(last,now-last));
					last=++now;
				}
				if(s[now]==','||s[now]=='.')
				{
					t=get_ID(s.substr(last,now-last));
					G[v].push_back(t);
					last=++now;
				}
				now++;
			}
		}
		dfs(1);
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 4152
#include <bits/stdc++.h>
using namespace std;
#define ll long long int 
int main()
{
    ll n;
    cin >>n;
    vector<ll> arr;
    ll sum=0;
    for(ll i =0;i<n;i++)
    {
        ll temp;
            cin >> temp;
        sum+=temp;
        arr.push_back(temp);
    }
    float mean=float(sum)/n;
    //cout << mean;
    if(mean >=0)
    {

    mean+=0.5;
    }
    else
    {
        mean-=0.5;
    }
    ll intmean=int(mean);
    //cout << intmean;
    ll ans=0;
    for(ll i=0;i<n;i++)
    {
        ll tmp=abs(arr[i]-intmean);
        tmp*=tmp;
        ans+=tmp;
        
    }
    cout << ans;

    

}


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

#define PI 3.141592653589
#define ll long long int
#define ld long double
#define vi vector<int>
#define vl vector<ll>
#define ii pair<int,int>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define pll pair<ll,ll>
#define vv vector
#define all(v) (v).begin(),(v).end()
ll MOD=998244353;
ll power(ll a, ll b){//a^b
    ll res=1;
    a=a%MOD;
    while(b>0){
        if(b&1){res=(res*a)%MOD;b--;}
        a=(a*a)%MOD;
        b>>=1;
    }
    return res;
}
ll fermat_inv(ll y){return power(y,MOD-2);}
ll gcd(ll a, ll b){return (b==0)?a:gcd(b,a%b);}
ll min(ll a,ll b){return (a>b)?b:a;}
ll max(ll a,ll b){return (a>b)?a:b;}
bool prime[1000001];
vi primes;
void SieveOfEratosthenes(int n) 
{ 
    memset(prime, true, sizeof(prime)); 
    for (int p=2; p*p<=n; p++) 
    { 
        if (prime[p] == true) 
        { 
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
    for(int p=2;p<1000001;p++)
        if(prime[p])
            primes.pb(p);
}
ll fact[100010];
ll finv[100010];
void factorial(int n){
    fact[0]=1;
    finv[0]=1;
    for(int i=1;i<=n;i++)
        fact[i]=fact[i-1]*i,fact[i]%=MOD,finv[i]=fermat_inv(fact[i]);
}
ll ncr(ll n,ll r)
{
    if(n<r)
        return 0;
    else{
        ll x=finv[r]*finv[n-r]%MOD;
        return fact[n]*x%MOD;
    }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif

    int te=1;
    //cin>>te;
    //SieveOfEratosthenes(1000000);
    //factorial(100005);
    while(te--){
        int n,k;
        cin>>n>>k;
        ii seg[k];
        for(int i=0;i<k;i++)
            cin>>seg[i].ff>>seg[i].ss;
        ll dp[n+1]={0};
        dp[0]=1,dp[1]=-1;
        for(int i=0;i<n;i++){
            if(i)
                dp[i]+=dp[i-1];
            dp[i]%=MOD;
            for(int j=0;j<k;j++){
                dp[min(n,i+seg[j].ff)]+=dp[i];
                dp[min(n,i+seg[j].ff)]%=MOD;
                dp[min(n,i+seg[j].ss+1)]-=dp[i]-MOD;
                dp[min(n,i+seg[j].ss+1)]%=MOD;
            }
        }
        //for(int i=0;i<n;i++)
          //  cout<<dp[i]<<' ';
        cout<<dp[n-1];
    }
}

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

#define smin(X, Y) ((X) < (Y) ? (X) : (Y))
int n, mn = (1<<30), k;
long long s;

int main(){
    cin >> n;
    for (int i=1, x; i<=n; i++){
        cin >> x;
        if (x < 0) x = -x, k++;
        s += x;
        mn = smin(mn, x);
    }
    if (k & 1) s -= 2*mn;
    cout << s;
    return 0;
}


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

int divn(int n){
  int memo[n+1]={0}; int ans=1,x=n;
  
  for(int i=2;i<=n;i++){
    while(x%i==0){
      x/=i; memo[i]++;
    }
  }
  for(int i=2;i<n+1;i++)ans*=memo[i]+1;
  return ans;
}

int main(){
  int n,ans=0;
  cin>>n;
  
  rep(i,n){
    if(i%2==1&&divn(i)==8)ans++;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < n; i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
typedef long long ll;

int main() {
    string S; cin >> S;
    
    int white[S.size()] = {}, black[S.size()] = {};
    white[0] = (S[0] == 'W');
    black[0] = (S[0] == 'B');
    REP(i, 1, S.size()) {
        white[i] = white[i - 1] + (S[i] == 'W');
        black[i] = black[i - 1] + (S[i] == 'B');
    }

    ll ans = 0;
    REP(i, 0, S.size()) {
        if (S[i] == 'W') continue;
        if (white[S.size() - 1] - white[i] > 0) {
            ans += S.size() - i - 1 - (black[S.size() - 1] - black[i]);
        }
    }
    cout << ans << endl; 
    return 0;
}

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

using namespace std;

using ll = long long;

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

    ll n, m;
    cin >> n >> m;
    if (n == 1 && m == 1) cout << "1\n";
    else if (n == 1) cout << m - 2 << '\n';
    else if (m == 1) cout << n - 2 << '\n';
    else cout << (n - 2) * (m - 2) << '\n';

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include <map>
#include <cmath>
#include <string>
using namespace std;

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


ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll c, ll d) { return c / gcd(c, d) * d; }

int main() {
  int n, m, c;
  cin >> n >> m >> c;

  vector<int> b(m);
  rep(i, m) cin >> b[i];

  int a[n][m]; int count = 0;
  bool ans[n];
  rep(i, n) {
    int sum = 0;
    rep(j, m) {
        cin >> a[i][j];
        sum += a[i][j] * b[j];
    }
    sum += c;
    if (sum > 0)
    {
        ans[i] = true;
        count++;
    }
    else ans[i] = false;
  }
  
  cout << count << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
 
using namespace std;
 
const int maxn = 1e5 * 3 + 20;
long long int n, a[maxn], ans;
 
int main()
{
    cin >> n;
    for (int i = 0; i < 3 * n; i++)\
        cin >> a[i];
    sort (a , a + (3 * n)); 
    reverse(a , a + (n * 3));
    for (int i = 0; i < n; i++)
        ans += a[i * 2 + 1];
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2688
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl

ll n,cnt,ans,a[ohara],b,c,d,tmp,tmpp,m,h,w,x,y,sum,pos,k;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

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

    cin>>k;
    rep(i,k)cin>>a[i];
    if(a[k-1]!=2)Cout(-1);
    else{
        reverse(a,a+k);
        ll now=2,noww=2;
        rrep(i,0,k){
                tmp=now/a[i];
                if(now%a[i]!=0){
                tmp++;
                }
                now=tmp*a[i];
        }
        rrep(i,0,k){
                tmp=noww/a[i];
                noww=tmp*a[i]+a[i]-1;
        }
        reverse(a,a+k);
        ans=now;
        rep(i,k){
            ans=(ans/a[i])*a[i];
        }
        if(ans!=2)Cout(-1);
        else{
            ans=noww;
            rep(i,k){
                ans=(ans/a[i])*a[i];
            }
            if(ans!=2)Cout(-1);
            else cout<<now<<" "<<noww<<"\n";
        }
    }
    return 0;
}


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

#include<cstdio>
#define r(i,n) for(int i=0;i<n;i++)


int main(void){
  double t,x;
  cin>>t>>x;
  cout<<t/x<<endl;


return 0;}


Measured memory_bytes: 256
N=int(input())
flag=True
nums=list(map(int, input().split()))
for x in nums:
  if x%2:
    continue
  else:
    if x%3==0 or x%5==0:
      continue
    else:
      flag=False
      break
if flag:
  print("APPROVED")
else:
  print("DENIED")
  

Measured memory_bytes: 2940
N=int(input())
S = input()

#違反している黒と白の数数えて
#少ない方で置き換える

answer = 0

#まず一番左の黒のいちを見つける
left_black = -1
right_white = -1

for i in range(N):
    if S[i]=='#':
        if S.count('#')==N-i:
            break
        left_black = i
        break

for i in reversed(range(N)):
    if S[i]=='.':
        right_white = i
        break

# print(right_white)



# print(left_black)
#left_blackが-1かN-1なら自動的に0


if left_black!=-1 and left_black!=N-1:
    S2 = S[left_black:right_white+1]
    length = len(S2)
    #どこまで全て白で塗るか決める
    white_black_sa = [0]*length
    if S2[0]=='.':
        white_black_sa[0] = 1
    else:
        white_black_sa[0] = -1

    for i in range(1,length):
        if S2[i]=='.':
            white_black_sa[i]=white_black_sa[i-1]+1
        else:
            white_black_sa[i]=white_black_sa[i-1]-1
    
    sa_max_idx = white_black_sa.index(max(white_black_sa))
    # print(S2)
    # print(S2[:sa_max_idx])
    # print(S2[sa_max_idx+1:])
    black_disc = S2[:sa_max_idx].count('#')
    white_disc = S2[sa_max_idx+1:].count('.')
    # print(white_black_sa)
    # print(white_disc,black_disc)
    answer = black_disc + white_disc





print(answer)





Measured memory_bytes: 42720
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define veci vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define vec2(a,b) vector<vec>(a,vec(b))
#define vec2ll(a,b) vector<vec>(a,vecll(b))
#define vec3(a,b,c) vector<vector<vec>>(a,vec2(b,c))
#define vec3ll(a,b,c) vector<vector<vecll>>(a,vec2ll(b,c))
#define fi first
#define se second
#define all(c) begin(c),end(c)
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))


using namespace std;
int in() {int x;cin>>x;return x;}
ll lin() {ll x;cin>>x;return x;}
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;}
template<class T> inline void print(pair<T,T> p){cout<<"("<<p.first<<","<<p.second<<") ";}
//template<class T> inline void print(vector<pair<T,T>> v){for(auto e:v)print(e); cout<<endl;}
//template<class T> inline void print(T v){for(auto e:v)cout<<e<<" ";cout<<endl;}
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
    for(T& x:vec) is >> x;
    return is;
}
const ll mod=1e9+7;


int main()
{
    ll n,k;
    cin >> n >> k;
    ll p=n%k;
    ll q=abs(p-k);
    cout << min(p,q) << endl;
    return 0;
} 


Measured memory_bytes: 256
#include <iostream>

#define max(a, b) (a > b ? a : b)
#define max_3(a, b, c) max(a, max(b, c))
using namespace std;

int main()
{
    int A, B, C;
    cin >> A >> B >> C;

    int answer = max_3(A*10 + B + C, A + B*10 + C, A + B + C*10);
    cout << answer << "\n";

    return 0;
}


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

using namespace std;

int main()
{
  int a[5];
  for(int i  = 0 ; i< 5; i++)
  {
    cin>>a[i];
  }
  for(int i = 0 ; i< 5; i++)
  {
    if(a[i] == 0)
    {
      cout<<i+1<<endl;
      break;
    }
  }
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define DEBUG
#define PI 3.141592653589793238462643383279
 
#define _GLIBCXX_DEBUG
#ifdef DEBUG
#define s(...) show(__VA_ARGS__);
#define sl(...) show(__VA_ARGS__);cout<<endl;
#else
#define s(...)
#define sl(...)
#endif
void show() {}
template <class Head,class... Args>void show(Head t,Args... args){std::cout<<t<<" ";show(args...);}
#define REP(i, n) for(ll i = 0; i < n; i++)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define REP1(i, n) for(ll i = 1; i <= n; i++)
#define REPR1(i, n) for(ll i = n; i >= 1; i--)
#define FOR1(i, m, n) for(ll i = m; i <= n; i++)
const ll INF = LLONG_MAX;
const ull MOD = 1000000007;
#define VEC(type,A,N) vector<type> A(N)
#define VECi(type,A,N,i) vector<type> A(N,i)
#define VEC2(type,A,N,M) vector<vector<type>> A(N,vector<type>(M))
#define VEC2i(type,A,N,M,i) vector<vector<type>> A(N,vector<type>(M,i))
#define ALL(v) v.begin(), v.end()
ll frac(ll k){
    int s = 1;
    for (ll i=1; i<=k; ++i)s *= i;
    return s;
}
ll gcd(ll a, ll b){
   if (a%b==0)return(b);
   else return(gcd(b, a%b));
}
ll lcm(ll a,ll b){
    return a*b/gcd(a,b);
}
ll antidiv(ll N,ll C,ll D){
    return N-floor(N/C)-floor(N/D)+floor(N/lcm(C,D));
}
vector<ll> yakusuu(ll N){
    vector<ll> ret;
    for (ll i = 1; i * i <= N; i++) {
        if (N % i == 0) {
            ret.push_back(i);
            if (i * i != N) ret.push_back(N / i);
        }
    }
    sort(ret.begin(), ret.end());
    return ret;
}
ll digitPoor(ll n)
{
    assert(INT_MAX == 2147483647);
    assert(n >= 0);

    if (n < 10)         return 1;
    if (n < 100)        return 2;
    if (n < 1000)       return 3;
    if (n < 10000)      return 4;
    if (n < 100000)     return 5;
    if (n < 1000000)    return 6;
    if (n < 10000000)   return 7;
    if (n < 100000000)  return 8;
    if (n < 1000000000) return 9;
    return 10;
}
struct p{
  ll x;
  bool b;
};
int main(){
    ll X;
    cin>>X;
    
    map<ll,ll> m;
    REP1(i,X){
        ll t;
        cin>>t;
        m[t]++;
    }
    
    ll cnt=0;
    for(auto v:m){
        if(v.first>v.second){
            cnt+=v.second;
        }else{
            cnt+=v.second-v.first;
        }
    }
    cout<<cnt;
    //cout<<fixed<<setprecision(32)<<m;
    //sort(ALL(C),[](auto& a, auto& b) {return a[2] < b[2];});
    //if(equal(D.begin(), D.end()-1, K.begin()))cout<<"Yes";else cout<<"No";
    cout<<endl;
    return 0;
}


Measured memory_bytes: 9536
def resolve():
    N,A,B,C = map(int,input().split())

    S=[input() for i in range(N)]
    ans =[]




    for i in range(N):
        s=S[i]
        if s =="AB":
            if A ==B ==0:
                print("No")
                return
            if A == B ==1 and C == 0 and i < N-1:
                if S[i+1] =="AC":
                    A+=1
                    B-=1
                    ans.append("A")
                else:
                    A-=1
                    B+=1
                    ans.append("B")
            elif A>B:
                A-=1
                B+=1
                ans.append("B")
            else:
                A+=1
                B-=1
                ans.append("A")

        elif s =="BC":
            if C ==B ==0:
                print("No")
                return
            if C == B ==1 and A == 0 and i < N-1:
                if S[i+1] =="AC":
                    C+=1
                    B-=1
                    ans.append("C")
                else:
                    C-=1
                    B+=1
                    ans.append("B")
            elif C>B:
                C-=1
                B+=1
                ans.append("B")
            else:
                C+=1
                B-=1
                ans.append("C")

        elif s =="AC":
            if C ==A ==0:
                print("No")
                return
            if C == A ==1 and B == 0 and i < N-1:
                if S[i+1] =="AB":
                    A+=1
                    C-=1
                    ans.append("A")
                else:
                    C+=1
                    A-=1
                    ans.append("C")
            elif C>A:
                C-=1
                A+=1
                ans.append("A")
            else:
                C+=1
                A-=1
                ans.append("C")


    print("Yes")
    print("\n".join(ans))







if __name__ == "__main__":
    resolve()

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

#define int long long
#define pb push_back
#define in insert
#define F first
#define S second
#define mod 1000000007
#define endl '\n'
#define all(x)  x.begin(),x.end()
#define w(x) int x;cin>>x; while(x-->0)
#define memset(a,b) memset(a,b,sizeof(a))
#define debug(x) cout << "[ " << #x  << " : " << x << " ]" << endl;

void fast()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
// #ifndef ONLINE_JUDGE
//     freopen("input.txt", "r", stdin);
//     freopen("output.txt", "w", stdout);
// #endif
}
/*
think fast
think simple
*/

void mysol()
{
    int a, b, c; cin >> a >> b >> c;
    cout << ((a + b - 1) / b)*c;
}

int32_t main()
{
    fast();
    // w(t)
    {
        mysol();
    }
    //cerr << sizeof(dp)*(1e-6) << " megabytes\n";
    return 0;
}


Measured memory_bytes: 3648
//#include <bits/stdc++.h>
//#include <stdio.h>
#include <iostream>
#include <cstdio>
#include <bitset>
#include <algorithm>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <string>
#include <string.h>
#include <cmath>
#include <utility>
#include <functional>
#include <map>
#include <set>
#include <cctype>
#include <fstream>

#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define RFOR(i, a, b) for (int i = (a); i >= (b); i--)
#define LFOR(i, a, b) for (long long int i = (a); i <= (b); i++)
#define LRFOR(i, a, b) for (long long int i = (a); i >= (b); i--)
#define MOD 1000000007
#define INF 1000000000			 //2000000000
#define LINF 1000000000000000000 //9000000000000000000
#define DINF 1000000000000000.0
#define PI 3.14159265358979
#define MAXI 7500000

//.size()はunsigned int　0-1をするとオーバーフローする

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

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

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

int main(void)
{
	while(1){
		int n;

		cin >> n;
		if(n==0){
			break;
		}
		int w, h, s, t;
		int d[101][101] = {};//w,h
		int x, y;
		int maxi = 0;
		int count = 0;

		cin >> w >> h;
		FOR(i,1,n){
			cin >> x >> y;
			d[x][y] = 1;
		}
		cin >> s >> t;

		FOR(i,1,w-s+1){
			FOR(j,1,h-t+1){
				count = 0;
				FOR(k, i, i + s - 1)
				{
					FOR(l,j,j+t-1){
						if(d[k][l]==1){
							count++;
						}
					}
				}
				maxi = max(maxi, count);
			}
		}

		cout << maxi << endl;
	}
}



Measured memory_bytes: 3036
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N,M;
    cin >> N >> M;
    vector<int> answers = vector<int>(N, 0);
    vector<int> wanswers = vector<int>(N, 0);

    int p,cn=0,wn=0;
    string S;
    for (int i = 0; i < M; i++)
    {
        cin >> p >> S;
        p--;
        if(S == "AC"){
            if(answers.at(p) == 0){
                answers.at(p) = 1;
                cn ++;
            }
        }else{
            if(answers.at(p) == 0){
                wanswers.at(p) ++;
            }
        }
    }

    for (int i = 0; i < N; i++)
    {
        if(answers.at(i)==1){
            wn += wanswers.at(i);
        }
    }
    
    cout << cn << ' ' << wn << endl;
}

Measured memory_bytes: 1024
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        s: String
    }
    println!("{}", s.chars().filter(|&c| c == '1').count())
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod 1000000007
int a[100005];
int main()
{
    char s[1005];
    cin>>s;
    int n=strlen(s);
    if(s[n-1]=='s')
        cout<<s<<"es"<<endl;
    else
        cout<<s<<"s"<<endl;
    return 0;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define ll long long
#define rep(i, n) for(int i=0; i<n; i++)
#define REP(i, n) for(int i=0; i<=n; i++)
#define repr(i, n) for(int i=n; i>0; i--)
#define REPR(i, n) for(int i=n; i>=0; i--)
const ll INF = 1LL<<60;
const int INT_INF = 1e9;
const ll MOD = 1e9+7;
template<class T> void puts(T x) { std::cout << x << std::endl; }
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; }
using namespace std;

string s;
int k;

int main() {
    cin >> s >> k;
    vector<string> ss;
    int N = s.length();

    for (int i = 0; i < N; i++) {
        for (int j = 1; j <= k; j++) {
            if (i + j <= N) {
                ss.emplace_back(s.substr(i, j));
                // cout << s.substr(i, j) << endl;
            }
        }
    }
    // cout << "---" << endl;
    sort(ss.begin(), ss.end());
    unique(ss.begin(), ss.end());
    // for (auto x: ss) cout << x << endl;
    cout << ss[k-1] << endl;
}


Measured memory_bytes: 1660
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>
#define ll long long

using namespace std;

long long MOD = 1000000007;

int main(){
    int N;
    cin >> N;
    int tmp=0;
    vector<vector<int>> vec1(0);
    vector<vector<int>> vec2(0);
    for(int i=0; i<N; i++){
        string S;
        cin >> S;
        int minl,l;
        minl=0;l=0;
        for(int j=0; j<(int)S.size(); j++){
            if(S[j]=='('){
                l++;
            }else{
                l--;
                minl=min(minl,l);
            }
        }
        if(minl>=0){
            tmp+=l;
        }else if(l>0){
            vec2.push_back({minl,l});
        }else{
            vec1.push_back({l-minl,l});
        }
    }

    sort(vec2.rbegin(),vec2.rend());
    sort(vec1.rbegin(),vec1.rend());
    auto it=vec2.begin();
    for(int i=0; i<(int)vec1.size(); i++){
        while(it!=vec2.end() && tmp+(*it)[0]>=0){
            tmp+=(*it)[1];
            it++;
        }
        if(tmp-vec1[i][0]+vec1[i][1]<0){
            cout << "No" << endl;
            return 0;
        }else{
            tmp+=vec1[i][1];
        }
    }
    if(tmp==0){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 30684
h, w = list(map(int, input().split()))
n = int(input())
A = list(map(int, input().split()))

import numpy as np
ans = np.zeros((h, w))

r = 0
c = 0
is_down = True
for i, a in enumerate(A):
    x = i + 1
    for _ in range(a):
        ans[r, c] = x
        if is_down:
            if r < h-1:
                r += 1
            else:
                c += 1
                is_down = False
        else:
            if r > 0:
                r -= 1
            else:
                c += 1
                is_down = True

for x in ans:
    print(' '.join(x.astype(int).astype(str)))


Measured memory_bytes: 27080
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <numeric>
#include <algorithm>
using namespace std;

int n;
int main() {
    while(cin >> n, n){
        vector<string> v;
        for(int i=0; i<n; ++i){
            string str; cin >> str;
            v.push_back(str);
        }
        int cnt=0, state=0;//0を床、1を台上とする
        for(int i=1; i<n; ++i){
            if((v[i]=="lu"&&v[i-1]=="ru")||(v[i]=="ru"&&v[i-1]=="lu")){
                if(state!=1){
                    cnt++; state=1;
                }
            }else if((v[i]=="ld"&&v[i-1]=="rd")||(v[i]=="rd"&&v[i-1]=="ld")){
                if(state!=0){
                    cnt++; state=0;
                }
            }
        }
        cout << cnt << endl;
    }
    return 0;
}


Measured memory_bytes: 3124