akhauriyash/Code-Regression huggingface dataset:
s = int(input())

A = [s]
n = (s/2 if s%2==0 else 3*s+1)
ans = 1

while n not in A:
    ans +=1
    A.append(n)
    n = (n/2 if n%2==0 else 3*n+1)

print(ans+1)

Measured memory_bytes: 2940
import sys
from collections import defaultdict

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n, p = na()
s = ns()

if p != 2 and p != 5:
    a = []
    t = 1
    for i in range(n-1, -1, -1):
        a.append((ord(s[i])-ord("0")) * t % p)
        t = t * 10 % p
    cum = [0]
    for v in a:
        cum.append((cum[-1] + v) % p)

    dic = defaultdict(int)
    ans = 0
    for v in cum:
        ans += dic[v]
        dic[v] += 1
    print(ans)
elif p == 2:
    ans = 0
    for i in range(n):
        if (ord(s[i]) - ord("0")) % 2 == 0:
            ans += i+1
    print(ans)
else:
    ans = 0
    for i in range(n):
        if (ord(s[i]) - ord("0")) % 5 == 0:
            ans += i+1
    print(ans)


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

int main(){
  int N;
  std::cin >> N;
  std::string S;
  std::cin >> S;

  int max = 0;
  int num = 0;
  for (int i = 0; i < N; ++i) {
    if ( S[i] == 'I' ) ++num;
    else if ( S[i] == 'D' ) --num;

    if ( max <= num ) max = num;
  }
  std::cout << max << std::endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define repp(i,m,n) for(lint (i)=(m);(i)<(n);(i)++)
#define repm(i,n) for(lint (i)=(n-1);(i)>=0;(i)--)
#define INF (1ll<<60)
#define all(x) (x).begin(),(x).end()
const lint MOD =1000000007;
const lint MAX = 1000000;
using Graph =vector<vector<lint>>;
typedef pair<lint,lint> P;
 
 
lint fac[MAX], finv[MAX], inv[MAX];
 
void COMinit() 
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (lint i = 2; i < MAX; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
long long COM(lint n, lint k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
 
lint primary(lint num)
{
    if (num < 2) return 0;
    else if (num == 2) return 1;
    else if (num % 2 == 0) return 0;
 
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return 0;
        }
    }
 
    return 1;
}
   long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
    lint lcm(lint a,lint b){
        return a/__gcd(a,b)*b;
    }
     lint gcd(lint a,lint b){
        return __gcd(a,b);
    } 
  
  int main(){      
    lint n,k;
    cin>>n>>k;
    set<lint>st;
    rep(i,k){
        lint d;
        cin>>d;
        rep(j,d){
                lint x;
                cin>>x;
                st.emplace(x);
        }
    }
    cout<<n-st.size();
  }
          
  

Measured memory_bytes: 3752
#include <iostream>
#include <cmath>
#include <vector>
#include <bitset>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <climits>
#include <set>
#include <map>
#include <iomanip>
#include <cassert>
#include <functional>
#include <cstring>

using namespace std;

#define mp make_pair
#define FOR(i, a, b) for(int (i)=a;(i)<(b);++(i))
#define rep(i, n)  FOR(i,0,n)
#define FFOR(i, a, b) for(int (i)=a;(i)>(b);--(i))
#define rrep(i,n) FFOR(i,0,n)
#define vsort(v) sort((v).begin(), (v).end());					//小さい順
#define rvsort(v) sort(v.begin(), v.end(),greater<>());		//大きい順
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define all(c) (c).begin(),(c).end()
#define ll long long
#define lb long double
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vs vector<string>
#define vc vector<char>
#define vvc vector<vector<char>>
#define Print(p) cout<<(p)<<endl
#define F first
#define S second
#define pb push_back
#define mod 1000000007LL
#define INF 123456789012345
typedef pair<int, int> P;
typedef pair<int, P> PP;

const int maxn =1e5 + 10;


int main() {

	int x; cin >> x;
	int ans = 1;

	FOR(i,2,x)
	{
		int con = i*i;
		while(con <= x)
		{
			ans = max(ans,con);
			con *= i;
		}
	}
	

	cout << ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <iomanip>

using namespace std;

int main(void){
    double r=0.0;
    cin >> r;
    std::cout << std::fixed;
    cout << setprecision(8) << r*r*M_PI << " " << setprecision(8) << 2*M_PI*r << endl;
}


Measured memory_bytes: 3288
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
#define rep(i,a,n)	for(int i=a;i<n;i++)
int main(){
	int a,b;
	cin>>a>>b;
	int c=a+b;
	if(c>=24){
		c-=24;
	}
	cout<<c<<endl;
	
}

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

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i)
#define rrepLRE(i, l, r) for (ll i = (l); i >= (r); --i)
#define Sort(v) sort(v.begin(), v.end())
#define rSort(v) sort(v.rbegin(), v.rend())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

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

/* Macros reg. ends here */

const ll INF = 1LL << 50;

int main() {
  // ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);

  ll n, k, q;
  cin >> n >> k >> q;

  vll as(n);
  rep(i, n) cin >> as[i];

  ll ans = INF;
  repLRE(ii, k - 1, n - 1) {
    ll m = INF;
    repLRE(j, ii - k + 1, ii) chmin(m, as[j]);

    priority_queue<ll, vll, greater<ll>> pq;
    multiset<ll> cur;
    rep(i, n) {
      if (as[i] >= m)
        cur.insert(as[i]);
      else {
        if ((ll)cur.size() >= k) {
          auto itr = cur.begin();
          rep(_, (ll)cur.size() - k + 1) {
            pq.emplace(*itr);
            itr++;
          }
        }
        cur.clear();
      }
    }

    if ((ll)cur.size() >= k) {
      auto itr = cur.begin();
      rep(_, (ll)cur.size() - k + 1) {
        pq.emplace(*itr);
        itr++;
      }
    }

    if ((ll)pq.size() >= q) {
      ll M = 0;
      rep(_, q) {
        chmax(M, pq.top());
        pq.pop();
      }
      assert(M >= m);
      chmin(ans, M - m);
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3736
#include<stdio.h>
int main()
{
  int H,W;
  while(1){
    scanf("%d%d",&H,&W);
    if(H==0 && W==0) break;
    int i,j;
    for(i=0;i<H;i++){
      for(j=0;j<W;j++)
	printf("#");
      printf("\n");
    }
    printf("\n");
  }
  return 0;
}

Measured memory_bytes: 572
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <math.h>
typedef long long ll;
char lowcmp[26]="abcdefghijklmnopqrstuvwxyz";
char upcmp[26]="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
long long mod=1000000007;

long long max(long long A,long long B){
    return A>B?A:B;
}

long long min(long long A,long long B){
    return A<B?A:B;
}

void swap(long long *A,long long *B){
    long long T;
    T=*A;
    *A=*B;
    *B=T;
}

int main(void){
    int n,h,w;
    scanf("%d%d%d",&n,&h,&w);
    printf("%d\n",(n-h+1)*(n-w+1));
    return 0;
}


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

#define var auto
#define long long long
#define ll long
#define Max std::max
#define Min std::min
#define Abs std::abs
using namespace std;

int main(){
	int n;
	cin >> n;
	map<string, int> count{};
	for (size_t i = 0; i < n; i++)
	{
		string s;
		cin >> s;
		count[s]++;
	}
	var max = 0;
	for (auto& i : count)
	{
		max = Max(max, i.second);
	}
	vector<string> res{};
	for (auto& i : count)
	{
		if (i.second == max) res.push_back(i.first);
	}
	sort(res.begin(), res.end());
	for (auto& i : res)
	{
		cout << i << endl;
	}
}


Measured memory_bytes: 26868
#include<stdio.h>
#include<vector>
#define Max 2*100002
using namespace std;

vector<int>vec[Max];
int node[Max];
long long int result[Max];
bool vis[Max];

void dfs(int src,int val){
	vis[src] = true;
	result[src] = val+node[src];
	int i;
	for(i=0;i<vec[src].size();i++){
		if(vis[vec[src][i]] == false){
			dfs(vec[src][i],val+node[src]);
		}
	}

}



int main(){
	int n,q,i,x,y;
	scanf("%d%d",&n,&q);
	for(i=0;i<n-1;i++){
		scanf("%d%d",&x,&y);
		vec[x].push_back(y);
		vec[y].push_back(x);
		node[i+1] = 0;
	}

	for(i=0;i<q;i++){
		scanf("%d%d",&x,&y);
		node[x] += y;
	}

	dfs(1,0);
	for(i=1;i<=n;i++){
		printf("%lld ",result[i]);
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 25216
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;
//inline int in() { int x; scanf("%d",&x); return x;}
inline ll in() { ll x; cin >> x; return x; }
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
const int MX = 200005;

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
map<ll, ll> prime_factor(ll n) {
  map<ll, ll> ret;
  for(ll i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if (n != 1) ret[n] = 1;
  return ret;
}

vector<int> to[2505];
vector<int> rto[2505];
bool reachablefrom1[2505];
bool reachableToN[2505];
bool ok[2505];

void dfs(int v) {
  if (reachablefrom1[v]) return;
  reachablefrom1[v] = true;
  for (int u : to[v]) {
    dfs(u);
  }
}
void rdfs(int v) {
  if (reachableToN[v]) return;
  reachableToN[v] = true;
  for (int u : rto[v]) {
    rdfs(u);
  }
}

int main() {
  ll n = in();
  string s; cin >> s;
  ll ans = n;
  rep(i, n-1)
    if (s[i] == s[i+1])
      ans--;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 640
#include <iostream>

using namespace std;

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

int main() {
	//A以上B以下のC,D,CとDの最小公倍数の倍数の個数を個数を求め、(B-A + 1) - (N_C N_D - N_CD)
	long long A, B, C, D;

	cin >> A >> B >> C >> D;

	long long N_C = B / C - (A - 1) / C;
	long long N_D = B / D - (A - 1) / D;
	long long N_CD = B  / ((C * D)/gcd(C,D)) - (A - 1) / ((C * D)/gcd(C,D));


	long long ans = (B - A + 1) - (N_C + N_D - N_CD);

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules! parse_line {
    ( $t:ty ) => (
        {
            let mut line = String::new();
            ::std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            iter.next().unwrap().parse::<$t>().unwrap()
        }
    );

    ( $( $t:ty), +) => (
        {
            let mut line = String::new();
            ::std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            ( $(iter.next().unwrap().parse::<$t>().unwrap()),* )
        }
    );
}

#[allow(unused_macros)]
macro_rules! read_line {
    () => (
        {
            let mut line = String::new();
            ::std::io::stdin().read_line(&mut line).unwrap();
            line.pop();
            line
        }
    )
}

#[allow(unused_macros)]
macro_rules! parse_vec {
    ( $t:ty ) => (
        {
            let mut line = String::new();
            ::std::io::stdin().read_line(&mut line).unwrap();
            let iter = line.split_whitespace();
            iter.map(|v| v.parse::<$t>().unwrap()).collect::<Vec<_>>()
        }
    )
}

fn solve (lqs: Vec<(u64, u64)>) -> Vec<u64> {
    let mut pmap = vec![true; 100001];
    pmap[0] = false;
    pmap[1] = false;

    for i in 0..100001 {
        if pmap[i] == false { continue; }

        for k in 2.. {
            if i*k > 100000 { break; }
            pmap[i*k] = false;
        }
    }

    let mut nmap = vec![0u64; 100001];
    let mut acc = 0;
    for i in 0..100001 {
        acc += if pmap[i] && pmap[(i+1)/2] {1} else {0};
        nmap[i] = acc;
    }

    lqs.iter().map(|&(l, q)| nmap[q as usize] - nmap[l as usize] + {if pmap[l as usize] && pmap[(l as usize +1)/2] {1} else {0}}).collect()
}

fn main() {
    let t = parse_line!(usize);


    let ans = (0..t).map(|_| parse_line!(u64, u64)).collect();

    for a in solve(ans) {
        println!("{}", a);
    }
}

#[test]
fn solve_test() {
    assert_eq!(solve(vec![(3,7)]), vec![2]);
    assert_eq!(solve(vec![(13,13), (7,11), (2017,2017)]), vec![1,0,1]);
}


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

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

  ll N; cin >> N;
  ll X; cin >> X;
  ll D; cin >> D;

  if (D == 0) {
    if (X == 0) cout << 1 << '\n';
    else cout << (N + 1) << '\n';
    return 0;
  }

  if (D < 0) {
    D *= -1; X *= -1;
  }

  map<ll, vector<pair<ll, ll>> > mp;
  for (ll i = 0; i < N + 1; i++) {
    ll l = i * (i - 1) / 2;
    ll r = N * i - i * (i + 1) / 2;
    ll g = ((i * X) % D + D) % D;
    mp[g].emplace_back(i * X + l * D, i * X + r * D);
  }

  ll ans = 0;
  for (auto p: mp) {
    auto a = p.second;
    int m = a.size();

    vector<pair<ll, ll>> s;
    for (ll i = 0; i < m; i++) {
      ll l = (a[i].first - p.first) / D;
      ll r = (a[i].second - p.first) / D + 1;
      s.emplace_back(l, +1);
      s.emplace_back(r, -1);
    }
    sort(s.begin(), s.end());

    ll cnt = 0, pre = -1e18;
    for (auto e: s) {
      ll len = e.first - pre;
      if (cnt) ans += len;
      cnt += e.second;
      pre = e.first;
    }
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 22144
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std ;
#define int long long
#define fi first
#define se second
#define pb push_back
#define pii pair<int, int>
#define mod 1000000007

typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

int n ;
int arr[500005] ;
string str1,str2 ;

void solve()
{
    cin >> str1 >> str2 ;
    int ans = str2.size() ;
    for(int i=0 ; i<str1.size()-str2.size()+1 ; i++)
    {
        int cnt = 0 ;
        for(int j=0 ; j<str2.size() ; j++)
        {
            if(str1[i+j]!=str2[j])
                cnt++ ;
        }
        ans = min(ans,cnt) ;
    }
    cout << ans ;
}
int32_t main()
{
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	int tt = 1;
	//cin >> tt ;
	while(tt--)
	{
	     solve() ;
	}
}


Measured memory_bytes: 3608
import sys

import bisect

# from collections import Counter, deque, defaultdict
# import copy
# from heapq import heappush, heappop, heapify
# from fractions import gcd

# import itertools

# from operator import attrgetter, itemgetter
# import math

# import numpy as np

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n, k = list(map(int, readline().split()))
    x = list(map(int, readline().split()))

    ans = INF

    for i in range(n - k + 1):
        left = i
        right = left + k - 1

        temp = min(abs(x[left]) + abs(x[right] - x[left]), abs(x[right]) + abs(x[left] - x[right]))
        ans = min(ans, temp)

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 58736
#include <cstdio>
#include <iostream>

using namespace std;

int main(int argc, char const *argv[])
{
	int n, m;
	cin >> n >> m;
	int a[n][m];
	int b[m];
	int c = 0;

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

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

	for (int i = 0; i < n; ++i){
		for (int j = 0; j < m; ++j){
			c += a[i][j] * b[j];
		}
		printf("%d\n", c);
		c = 0;
	}

	return 0;
}

Measured memory_bytes: 1184
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define MOD 1000000007
using namespace std;

int dp[4001],n,a,b,c,i;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int a,b,i;
    cin >> a >> b;
    if(a<b) {
        for(i=0;i<b;i++) cout << a;
    } else {
        for(i=0;i<a;i++) cout << b;
    }
    cout << "\n";
    return 0;
}



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

// template {{{
#define  range(i, l, r) for (int i = (int)(l); i < (int)(r); (i) += 1)
#define rrange(i, l, r) for (int i = (int)(r) - 1; i >= (int)(l); (i) -= 1)

#define  whole(f, x, ...) ([&](decltype((x)) container) { return (f)(  begin(container),  end(container), ## __VA_ARGS__); })(x)
#define rwhole(f, x, ...) ([&](decltype((x)) container) { return (f)( rbegin(container), rend(container), ## __VA_ARGS__); })(x)

#define debug(x) cerr << "(" << __LINE__ << ")" << #x << ": " << (x) << endl

using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;

// constexpr i32 mod   = 998244353;
constexpr i32 mod   = 1e9 + 7;
constexpr i32 inf   = 1001001001;
constexpr i64 infll = 1001001001001001001ll;

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

struct IoSetup { IoSetup(int x = 15){ cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(x); cerr << fixed << setprecision(x); } } iosetup;

template <typename T = i64> T input() { T x; cin >> x; return x; }

template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { range(i, 0, v.size()) { os << v[i] << (i + 1 != v.size() ? " " : ""); } return os; }
template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; }

template <typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }

template <typename T> vector<T> make_vector(size_t a, T b) { return vector<T>(a, b); }
template <typename... Ts> auto make_vector(size_t a, Ts... ts) { return vector<decltype(make_vector(ts...))>(a, make_vector(ts...)); }

template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
// }}}

void solver() {
    i64 A = input(), B = input(), N = input();
    i64 x = min(B - 1, N);

    cout << (A * x / B) - A * (x / B) << endl;
}

signed main(int argc, char *argv[]) {
    solver();
}


Measured memory_bytes: 3652
use std::collections::HashMap;

#[allow(unused_macros)]
macro_rules! scan {
    () => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().to_string()
        }
    };
    (;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().split_whitespace().map(|s| s.to_string()).collect::<Vec<String>>()
        }
    };
    (;;$n:expr) => {
        {
            (0..$n).map(|_| scan!()).collect::<Vec<_>>()
        }
    };
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty;;$n:expr) => {
        (0..$n).map(|_| scan!($t;;)).collect::<Vec<_>>()
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
                    scan!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
                    scan!($($t),*)
        ).collect::<Vec<_>>()
    };
}

fn main() {
    let _ = scan!(usize);
    let vs = scan!(usize;;);

    let mut m = HashMap::new();
    for v in vs {
        let val = m.entry(v).or_insert(0);
        *val += 1;
        if *val == 3 {
            *val = 1;
        }
    }

    let mut num1 = 0;
    let mut num2 = 0;
    for (_, num) in m {
        if num == 1 {
            num1 += 1;
        } else {
            num2 += 1;
        }
    }
    if num2 % 2 == 0 {
        println!("{}", num1 + num2)
    } else {
        println!("{}", num1 + num2 - 1)
    }
}


Measured memory_bytes: 12540
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Runtime.Remoting.Contexts;
class Simple {
    private int N;
    void Solve() {
        //input
        N = io.Int;
        //cal
        Func <int, int> f = (n) => n * (2 + (n - 1)) / 2;
        for(int i = 1; ; ++i) {
            if(f(i) >= N) {
                //ret
                Console.WriteLine(i);
                return;                
            }
        }
    }
    SimpleIO io = new SimpleIO();
    public static void Main(string[] args) => new Simple().Stream();
    private void Stream() {
        //var exStdIn = new System.IO.StreamReader("stdin.txt");
        //System.Console.SetIn(exStdIn);
        Solve();
        io.Flush();
    }
}
class SimpleIO {
    string[] _nextBuffer;
    int _bufferCnt;
    char[] cs = new char[] {' ', '"', ','};
    StreamWriter sw = new StreamWriter(Console.OpenStandardOutput()) {AutoFlush = false};
    public SimpleIO() {
        _nextBuffer = new string[0];
        _bufferCnt = 0;
        Console.SetOut(sw);
    }
    public string Next() {
        if(_bufferCnt < _nextBuffer.Length) return _nextBuffer[_bufferCnt++];
        var st = Console.ReadLine();
        while(st == "") st = Console.ReadLine();
        if(st != null) _nextBuffer = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        else st = "";
        _bufferCnt = 0;
        return _nextBuffer[_bufferCnt++];
    }
    public string String => Next();
    public char Char => char.Parse(String);
    public int Int => int.Parse(String);
    public long Long => long.Parse(String);
    public double Double => double.Parse(String);
    public void Flush() { Console.Out.Flush(); }
}
static class NumericEx {
    public static string pad0 <T>(this T v, int n) { return v.ToString().PadLeft(n, '0'); }
    public static double RoundOff(this double v, int n) { return Math.Round(v, n - 1, MidpointRounding.AwayFromZero); }
    public static bool Odd(this int v) { return v % 2 != 0; }
    public static bool Odd(this long v) { return v % 2 != 0; }
    public static void REP(this int v, Action <int> act) {
        for(int i = 0; i < v; ++i) act(i);
    }
    public static void REPR(this int v, Action <int> act) {
        for(int i = v - 1; i >= 0; --i) act(i);
    }
}


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

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

  int cnt = 0;
  for (int i = 2; i < S.size(); ++i) if (S.at(i - 2) == 'A' && S.at(i - 1) == 'B' && S.at(i) == 'C') cnt++;
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n,a[100009],dp[100009],k;
int main() {
    cin>>n>>k;
    for(int i=1;i<=n;i++){
        cin>>a[i];
         if(i>=2){
         dp[i]=abs(a[i]-a[i-1])+dp[i-1];
            for(int j=1;j<=k;j++){
                    if((i-j)==0)break;
                dp[i]=min(abs(a[i]-a[i-j]) +dp[i-j],dp[i]);
            }
         }
    }
    cout<<dp[n]<<endl;
}


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

int main() {
    int H, W;
    cin >> H >> W;
    string S[H];
    for(int i = 0; i < H; i++) cin >> S[i];

    for (int i = 0; i < H; i++)
    {
        for (int j = 0; j < W; j++)
        {
            int count = 0;

            if(i != 0 ) {
               if(S[i-1][j] == '#') count++;
            }
            if(i != H-1) {
                if(S[i+1][j] == '#') count++;
            }
            if(j != 0) {
                if(S[i][j-1] == '#') count++;
            }
            if(j != W-1) {
                if(S[i][j+1] == '#') count++;
            }
            if(i != 0 && j != 0) {
                if(S[i-1][j-1] == '#') count++;
            }
            if(i != H-1 && j != 0) {
                if(S[i+1][j-1] == '#') count++;
            }
            if(i != 0 && j != W-1) {
                if(S[i-1][j+1] == '#') count++;
            } 
            if(i != H-1 && j != W-1) {
                if(S[i+1][j+1] == '#') count++;
            }
            if(S[i][j] != '#'){
                string s = to_string(count);
                S[i][j] = s[0];
            }
            
        }
    }

    for (int i = 0; i < H; i++)
    {
        cout << S[i] << endl;
    }
    
}

Measured memory_bytes: 3696
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		// TODO 自動生成されたメソッド・スタブ
		BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
		String[] matrixFormat = (input.readLine()).split("\\s");

		int n = Integer.parseInt(matrixFormat[0]);
		int m = Integer.parseInt(matrixFormat[1]);
		int l = Integer.parseInt(matrixFormat[2]);

		int[][] matrixA = new int[n][m];
		int[][] matrixB = new int[m][l];
		long[][] matrixC = new long[n][l];

		String[] dataMatrixA = null;
		for (int i = 0; i < n; i++) {
			dataMatrixA = (input.readLine()).split("\\s");
			for (int j = 0; j < m; j++) {
				matrixA[i][j] = Integer.parseInt(dataMatrixA[j]);
			}
		}

		String[] dataMatrixB = null;
		for (int k = 0; k < m; k++) {
			dataMatrixB = (input.readLine()).split("\\s");
			for (int h = 0; h < l; h++) {
				matrixB[k][h] = Integer.parseInt(dataMatrixB[h]);
			}
		}

		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				for (int k = 0; k < l; k++) {
					matrixC[i][k] += (matrixA[i][j] * matrixB[j][k]);
				}
			}
		}

		for (int i = 0; i < n; i++) {
			for (int j = 0; j < l; j++) {
				if (j > 0) {
					System.out.print(" ");
				}
				System.out.print(matrixC[i][j]);
			}
			System.out.println();
		}
	}
}



Measured memory_bytes: 33272
'use strict'

class Main {
  solve() {
    console.log({ 'A': 'T', 'T': 'A', 'G': 'C', 'C': 'G' }[input.nextLine()]);
  }
}

class Input {
  constructor() {
	this.cursor = 0;
	this.inputAll();
  }

  inputAll() {
	this.data = (require("fs").readFileSync("/dev/stdin", "utf8")).split('\n');
	return this.data;
  }

  /* 1行 or 複数行文字列 */
  nextLine(n) {
	if (n) {
	  const ret = this.data.slice(this.cursor, this.cursor + n);
	  this.cursor += n;
	  return ret;
	}
	return this.data[this.cursor++];
  }
  /* 一行文字配列 */
  nextStrArr() { return this.nextLine().split(' '); } 
  /* 一行整数配列 */
  nextIntArr() { return this.nextStrArr().map((e) => parseInt(e)); }
  /* 一行浮動小数点配列 */
  nextFloatArr() { return this.nextStrArr().map((e) => parseFloat(e)); }
  /* 複数行整数配列 */
  nextIntLine(n) { return this.nextLine(n).map((e) => parseInt(e)) }
  /* 複数行浮動小数点配列 */
  nextFloatLine(n) { return this.nextLine(n).map((e) => parseFloat(e)) }
  /* 複数行文字列二次元配列 */
  nextStrRange(n) { return this.nextLine(n).map((line) => line.split(' ')); }
  /* 複数行整数二次元配列 */
  nextIntRange(n) {
	return this.nextLine(n).map((line) => line.split(' ').map((e) => parseInt(e)));
  }
  /* 複数行浮動小数点数二次元配列 */
  nextFloatRange(n) {
	return this.nextLine(n).map((line) => line.split(' ').map((e) => parseFloat(e)));
  }
} 
const input = new Input();
(new Main()).solve();


Measured memory_bytes: 7372
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
 
#define rep(i, n) REP(i, 0, n)
#define REP(i, x, n) for(int i = x; i < n; i++)

int N, M;
vector<string> a, b;

// 含まれていたらtrue
bool judge(int start_i, int start_j)
{
    rep(i, M)
    {
        rep(j, M)
        {
            if (a[(start_i + i)][j + start_j] != b[i][j]) return false;
        }
    }
    return true;
}

int main()
{
    string temp;
    cin >> N >> M;
    rep(i, N)
    {
        cin >> temp;
        a.push_back(temp);
    }
    rep(i, M)
    {
        cin >> temp;
        b.push_back(temp);
    }
    
    string res = "No";
    // calc
    rep(i, N - M + 1)
    {
        rep(j, N - M + 1)
        {
            if (judge(i, j)) res = "Yes";
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <cmath>
#include <string>
#include <bitset>
#include <functional>
#include <set>
#include <map>
#include <array>

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define fst first
#define snd second
#define pb push_back
#define ALL(obj) (obj).begin(), (obj).end()
#define debug(x) cout << #x << ": " << x << endl
const int MOD = 1000000007;
const int INF = 100100100;
const double EPS = 0.000000001;

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

bool pairCompare(const P& pair1, const P& pair2) {
    return pair1.second > pair2.second;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  string s;
  int count0;
  cin >> s;
  n = s.size();
  REP(i, n){
    if(s[i] == '0') count0++;
  }
  int ans = min(count0, (n - count0));
  cout << 2 * ans << endl;
  return 0;
}


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

const int mod=1e9+7;

void add(int& a,int b)
{
   a=(a+b)%mod;
}

int main()
{
   int N,M; cin>>N>>M;
   vector<int> a(N),b(M);
   for(int i=0;i<N;i++) cin>>a[i];
   for(int i=0;i<M;i++) cin>>b[i];

   vector<vector<int>> dp(N+1,vector<int>(M+1));
   for(int j=0;j<=M;j++) dp[0][j]=1;
   for(int i=0;i<=N;i++) dp[i][0]=1;
   for(int i=0;i<N;i++) for(int j=0;j<M;j++){
      if(a[i]==b[j]) add(dp[i+1][j+1],dp[i][j]);
      add(dp[i+1][j+1],dp[i+1][j]);
      add(dp[i+1][j+1],dp[i][j+1]);
      add(dp[i+1][j+1],mod-dp[i][j]);
   }
   cout<<dp[N][M]<<endl;
   return 0;
}

Measured memory_bytes: 16000
<?php
  fscanf(STDIN, "%d", $d);

$cc = fgets(STDIN);
$c = explode(' ', $cc);

foreach ($c as &$value) {
    $value = (int) $value;
}
unset($value);

$cckey1 =  array_keys($c, max($c));
$ckey1 = $cckey1[0];
$c[$ckey1] = 0;
$cckey2 =  array_keys($c, max($c));
$ckey2 = $cckey2[0];
$c[$ckey2] = 0;
$cckey3 =  array_keys($c, max($c));
$ckey3 = $cckey3[0];

  for($i = 0; $i < $d; $i++) {
$aa = fgets(STDIN);
$a = explode(' ', $aa);

foreach ($a as &$value) {
    $value = (int) $value;
}
unset($value);
    
    if(($i % 4) === 0) {
      echo (1 + (int) $ckey1).PHP_EOL;
      continue;
    }
    if(($i % 4) === 1) {
      echo (1 + (int) $ckey2).PHP_EOL;
      continue;
    }
    if(($i % 4) === 2) {
      echo (1 + (int) $ckey3).PHP_EOL;
      continue;
    }
    $key =  array_keys($a, max($a));
    echo (1 + (int) $key[0]).PHP_EOL;
    unset($a);
    unset($aa);
  }

Measured memory_bytes: 16312
#include <stdio.h>

int main()
{
  int a,b,c,x;
  scanf("%d%d%d%d",&a,&b,&c,&x);
  int i,j,k,counter;
  i = 0;
  counter = 0;
  while (i <= a)
  {
    j = 0;
    while (j <= b)
    {
      k = 0;
      while (k <= c)
      {
        if (x == 500*i+100*j+50*k)
        {
          counter++;
        }
        k++;
      }
      j++;
    }
    i++;
  }
  printf("%d",counter);
}

Measured memory_bytes: 256
X, K, D = map(int, input().split())

X = abs(X)

a = X // D
d1 = X - (D * a)
d2 = X - (D * (a + 1))
 
if a >= K:
    ans = X - (D * K)
else:
    if (a % 2) ^ (K % 2) == 0:
        ans = d1
    else:
        ans = d2
 
print(abs(ans))


Measured memory_bytes: 9100
N = int(input())
S = [0]*N
sT = [0]*N
T = [0]*N
for i in range(N):
    S[i],sT[i] = map(str,input().split())
X = input()

for i,st in enumerate(sT):
    T[i] = int(st)

j = S.index(X)
ans = sum(T[j+1:])
print(ans)

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

#define INF (int)1e9+7
#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>=b;--i)
#define vi vector<int>
#define vl vector<ll>
#define vii vector<vector<int>>
#define vll vector<vector<long long>>
#define pii pair<int,int>
#define pll pair<long,long>
#define vpii vector<pii>
#define vpll vector<pll>
#define N 100005
#define pb push_back
#define mp make_pair
#define PI 3.1415926535897932384626433832795



ll binPowM(ll a,ll b, ll m)
{ 
  ll ans=1;
  while(b>0)
  {
    if(b&1)ans=ans*a%m;
    a=a*a%m;
    b>>=1;
  }
return ans%m;
}
ll f(ll x,ll y,ll a)
{
  return (a&x)*(a&y);
}

int main()
{
ll n,m;
cin>>n>>m;
vector<ll>h(n+1);
for(int i=1;i<=n;i++)
{
    cin>>h[i];
}
vector<ll>a[n+1];
for(int i=1;i<=m;i++)
{
    ll x,y;
    cin>>x>>y;
    
    a[x].push_back(y);
    a[y].push_back(x);
}
ll cnt=0;
for(int i=1;i<=n;i++)
{
    ll ans=h[i];
    ll flag=0;
    for(int j=0;j<a[i].size();j++)
    {
       if(ans<=h[a[i][j]])
       {
           flag=1;
           break;
       }
    }
    if(!flag)cnt++;
}
cout<<cnt<<"\n";
  return 0;
}





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

typedef long long int   ll;
#define cases           int t;cin>>t;while(t--)
#define FIO             ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define scan(n)         scanf("%d",&n)
#define pb              push_back
#define vi              vector<int>
#define ii              pair<int,int>

using namespace std;

int main(){
    ll n,m;cin>>n>>m;
    ll ar[n];
    for(ll i=0;i<n;i++)cin>>ar[i];
    vector<ll> adj[n];
    for(ll i=0;i<m;i++){
        ll a,b;
        cin>>a>>b;
        a--;b--;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    ll cnt=0;
    for(ll i=0;i<n;i++){
        if(adj[i].empty()){
            cnt++;
            continue;
        }
        ll h=ar[i];
        bool ch=true;
        for(ll j=0;j<adj[i].size();j++){
            if(h<=ar[adj[i][j]]){
                ch=false;
                break;
            }
        }
        if(ch)cnt++;
    }
    cout<<cnt<<endl;
}


Measured memory_bytes: 10244
#include<algorithm>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<iomanip>
#include<iostream>
#include<queue>
#include<set>
#include<string>
#include<utility>
#include<vector>

using namespace std;
 
typedef long long ll;

#define MP make_pair
#define F first
#define S second

int main(){
	ll n;
  	cin >> n;
    cout << (ll)(n/500)*1000+(ll)(n%500/5)*5 << endl;
	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mp(a,b)   make_pair(a,b)
#define ll        long long
#define mp(a,b)   make_pair(a,b)
#define si(n)     scanf("%d",&n)
#define sl(n)     scanf("%lld",&n)
#define pi(n)     printf("%d\n",n)
#define pl(n)     printf("%lld\n",n)
#define           newline cout << endl;
#define           ff first
#define           ss second
#define           pii pair<int, int>
#define           pll pair<ll, ll>
using namespace std;

template<typename S, typename T> 
ostream& operator<<(ostream& out,pair<S,T> const& p){out<<'('<<p.ff<<", "<<p.ss<<')';return out;}

template<typename T>
ostream& operator<<(ostream& out,vector<T> const& v){
int l=v.size();for(int i=0;i<l-1;i++)out<<v[i]<<' ';if(l>0)out<<v[l-1];return out;}

template<typename T>
void trace(const char* name, T&& arg1){cout<<name<<" : "<<arg1<<endl;}

template<typename T, typename... Args>
void trace(const char* names, T&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');cout.write(names, comma-names)<<" : "<<arg1<<" | ";trace(comma+1,args...);}

int find(int a,int b,int c){
  int k1 =a*10+b;
  return k1+c;
}

int main(){
  //clock_t tStart = clock();
  int a,b,c;
  cin >> a >> b >> c;
  int k1 = -1;
  int k2 = find(a,b,c);
  k1 =  max(k1,k2);
  
  k2 = find(b,c,a);
  k1 =  max(k1,k2);
  
  k2 = find(c,a,b);
  k1 =  max(k1,k2);
  
  k2 = find(a,c,b);
  k1 =  max(k1,k2);
  
  k2 = find(b,a,c);
  k1 =  max(k1,k2);
  
  k2 = find(c,b,a);
  k1 =  max(k1,k2);
  
  cout << k1 << endl;
  //printf("Time taken: %.2fs\n", (double)(clock() - tStart)/CLOCKS_PER_SEC);
  return 0;
}

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

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


	int a,b,c,k;
	cin>>a>>b>>c>>k;
	vector<int> x = {a,b,c};
	vector<int> y = {1,0,-1};
	int ans = 0;
	int ptr = 0;
	while( k >  0){
		if( k > x[ptr] ){
			k -= x[ptr];
			ans += x[ptr] * y[ptr];
		}else{
			ans += k * y[ptr];
			break;
		}
		++ptr;
	}
	cout<<ans<<'\n';

	return 0;
}


Measured memory_bytes: 3640
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>

using namespace std;

int main(){

    int a,b,d;
    while(cin>>a>>b>>d&&!(a==0&&b==0&&d==0)){
        // ax+by=d
        bool isSwap=false;
        if(a>b){
            swap(a,b);
            isSwap=true;
        }
        // ツ堕スツつ「ツ陛サツづーツ催妥・ツづ慊づ篠敖づづつィツつュ
        int y=(d/b)+(d%b!=0);
        int x=0;
        int sum=b*y+a*x;
        int ox,oy;
        ox=oy=100000000;
        while(1){
            if(sum>d){
                y--;
                sum-=b;
            }
            else if(sum<d){
                x++;
                sum+=a;
            }
            else if(sum==d)
                break;
            if(y<0)break;
        }
        if(y>=0){
            ox=x;oy=y;
        }
        // ツ渉ャツつウツつ「ツ陛サツづ可湘ヲツつケツづつ「ツつュ.ツ湘ヲツつケツづゥツ青篠づ債禿シツづェツ妥鳴つヲツづゥ
        // ツ催渉可づ債債カツづ餌ツづーツつィツつュ
        int lw=0;
        int rw=d;
        // ツ暗ェツ度ツ個サツづェツつスツ重ツつウツづ個債キツづ債格ツ納ツつオツづつィツつュ
        set<int> appearedDiff;
        while(1){
            if(appearedDiff.find(lw-rw)!=appearedDiff.end()){
                break;
            }
            appearedDiff.insert(lw-rw);
            if(lw==rw){
                break;
            }
            else if(lw<rw){
                lw+=a;
            }
            else
                rw+=b;
        }
        if(lw==rw){
            int x=lw/a;
            int y=(rw-d)/b;
            if(x+y<ox+oy||((x+y)==(ox+oy)&&(lw+rw)<(ox*a+oy*b))){
                ox=x;oy=y;
            }
        }
        lw=d;rw=0;
        appearedDiff.clear();
        while(1){
            if(appearedDiff.find(lw-rw)!=appearedDiff.end()){
                break;
            }
            appearedDiff.insert(lw-rw);
            if(lw==rw){
                break;
            }
            else if(lw<rw){
                lw+=a;
            }
            else
                rw+=b;
        }
        if(lw==rw){
            int x=(lw-d)/a;
            int y=(rw)/b;
            if(x+y<ox+oy||((x+y)==(ox+oy)&&(lw+rw)<(ox*a+oy*b))){
                ox=x;oy=y;
            }
        }
        if(isSwap)
            cout<<oy<<" "<<ox<<endl;
        else
            cout<<ox<<" "<<oy<<endl;
    }

    return 0;
}

Measured memory_bytes: 2084
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
const int maxn =2e5+10;
const int mod=1e9+7;
int f[maxn];

int find1(int x)
{
    if(x==f[x])
        return x;
    else
        return f[x]=find1(f[x]);
}

void add(int x,int y)
{
    int t1=find1(x),t2=find1(y);
    f[t1]=t2;
}



int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    for(int i=1;i<maxn;i++)
        f[i]=i;
    int n;
    cin>>n;
    int m;
    cin>>m;
    while(m--)
    {
        int a,b;
        cin>>a>>b;
        add(a,b);

    }
    int ans=0;
    map<int,int>mp;
    for(int i=1;i<=n;i++)
    {
        mp[find1(i)]++;
        ans=max(ans,mp[find1(i)]);
    }
    cout<<ans<<'\n';






}


Measured memory_bytes: 13760
#include <iostream>
using namespace std;
int main(void){
    int n,kumachan=0;
    cin>>n;
    int h=n;
    while(h){
        kumachan+=h%10;
        h=h/10;
        
    }
    if(n%kumachan==0){
        cout<<"Yes"<<endl;
    }else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
string s;
int num[100005];
int main()
{
	cin>>s;
	for(int i=1;i<s.size();i++){
		if(s[i-1]!=s[i]&&s[i]=='L'){
			int l=i-1,r=i;
			while(l>=0&&(l==i-1||s[l]==s[l+1]))num[i-1+(i-l-1)%2]++,l--;
			while((r==i||s[r]==s[r-1])&&r<s.size())num[i-(r-i)%2]++,r++;
		}
	}
	for(int i=0;i<s.size();i++)
		cout<<num[i]<<" ";
	return 0;
}

Measured memory_bytes: 1024
n, s = map(int, input().split())
a = list(map(int, input().split()))
mod = 998244353

dp = [[0 for _ in range(s + 1)] for j in range(n + 1)]
dp[0][0] = 1

ans = 0
for i in range(n):
    for j in range(s + 1):
        dp[i + 1][j] += dp[i][j]
        if j >= a[i]:
            if j == a[i]:
                dp[i + 1][j] += i + 1
            else:
                dp[i + 1][j] += dp[i][j - a[i]]
    ans += dp[i + 1][s]
    ans %= mod
print(ans)


Measured memory_bytes: 942628
#include <bits/stdc++.h> 
#include <atcoder/all>
#define rep(i, n) for(long long int i = 0; i < n; i++)
#define _rep(i, m, n) for(long long int i = m; i < n; i++)
using namespace std;
using namespace atcoder;
typedef long long ll;
typedef pair<int, int> P;
const ll mod = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
string Yes[2] = {"Yes", "No"};

using Graph = vector<vector<int>>;
Graph G;

/*------------------------------------------------------------------*/


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

    int n, m; cin >> n >> m;
    dsu DSU(n);
    rep(i, m){
        int a, b; cin >> a >> b;
        a--, b--;
        DSU.merge(a, b);
    }
    set<int> se;
    rep(i, n){
        se.insert(DSU.leader(i));
    }
    cout << se.size() - 1 << endl;
}


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

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

  int n;
  cin >> n;
  
  int sum = 0, poss = 1;
  vector<vector<pair<int, int>>> a(2);
  for (int i = 0; i < n; ++i) {
    int mn = 0, cnt = 0;
    string s;
    cin >> s;

    for (auto j : s) {
      if (j == ')') --cnt;
      else ++cnt;
      mn = min(mn, cnt);
    }
    
    if (mn >= 0 && cnt >= 0) sum += cnt;
    else if (mn + cnt >= 0) a[0].emplace_back(mn, cnt);
    else a[1].emplace_back(mn, cnt);
  }

  sort(a[0].begin(), a[0].end(), greater<pair<int, int>>());
  sort(a[1].begin(), a[1].end(), [&](auto l, auto r) {
      return l.first + r.second < l.second + r.first;
  });
  
  for (int b = 0; b < 2; ++b) {
    for (int i = 0; i < (int)a[b].size(); ++i) {
      if (a[b][i].first + sum < 0) poss = 0;
      sum += a[b][i].second;
    }
  }

  cout << ((poss && sum == 0) ? "Yes" : "No") << '\n';
}


Measured memory_bytes: 7424
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(){

	int n;
	while(cin>>n&&n!=0){
		int sum=0;
		for(int i = 0; i < n/4; i++){
			int tmp;
			cin>>tmp;
			sum+=tmp;
		}
		cout << sum << endl;
	}

	return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<vector>
#include<set>
#include<algorithm>

using namespace std;

struct Graph{
  vector< vector<int> > edge;
  vector<bool> visited;
  vector<int> lowest, parent, prenum;
  int timer;

  Graph(int n) : edge(n), visited(n, false), lowest(n), parent(n, -1), prenum(n){
    timer = 1;
  }

  void dfs(int now, int prev){
    lowest[now] = prenum[now] = timer;
    timer++;
    visited[now] = true;

    for(auto next:edge[now]){
      if(!visited[next]){ //next = 子供
        parent[next] = now;
        dfs(next, now);
        lowest[now] = min(lowest[now], lowest[next]);
      }
      else if(next != prev){ //BackEdge next = 親戚
        lowest[now] = min(lowest[now], prenum[next]);
      }
    }
  }

  void bridge(){
    dfs(0,1);

    set< pair<int, int> > bridge;
    for(int i = 0; i < prenum.size(); i++){
      if(i == 0) continue;
      if(prenum[parent[i]] < lowest[i]) bridge.insert({min(i, parent[i]), max(i, parent[i])});
    }
    for(auto b:bridge){
      cout << b.first << " " << b.second << endl;
    }
  }
};

int main(){
  int v, e;
  cin >> v >> e;
  Graph G = (v);
  for(int i = 0; i < e; i++){
    int s,t;
    cin >> s >> t;
    G.edge[s].push_back(t);
    G.edge[t].push_back(s);
  }
  G.bridge();
  return 0;
}



Measured memory_bytes: 4308
nStone = int(input())
heights = list(map(int, input().split()))
paths, weights = {}, {}
for i in range(1, nStone + 1):
    paths[i] = float("inf")
    weights[i] = heights[i - 1]

paths[1] = 0

for node in range(1, nStone + 1):
    weight = paths[node]

    try:
        cost1 = abs(weights[node] - weights[node + 1])
        if cost1 + weight < paths[node + 1]:
            paths[node + 1] = cost1 + weight

        cost2 = abs(weights[node] - weights[node + 2])
        if cost2 + weight < paths[node + 2]:
            paths[node + 2] = cost2 + weight
    except KeyError:
        None
print(paths[nStone])


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

int main() {
  ll a, b, k;
  cin >> a >> b >> k;
  ll A, B;
  if(a+b<=k) {
    A=0;  B=0;
  }
  else if(a<=k) {
    A=0;  B=b-k+a;
  }
  else {
    A=a-k; B=b;
  }

  cout << A << " " << B << endl;
}

Measured memory_bytes: 256