akhauriyash/Code-Regression huggingface dataset:
// ref: https://drken1215.hatenablog.com/entry/2019/03/03/224600

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

typedef int64_t int64;
typedef uint32_t uint;
typedef uint64_t uint64;

using namespace std;

//---

template <typename T>
inline void print(const T& rhs){ std::cout<<" = "<<rhs<<std::endl; }
template <typename T>
inline void print(const std::vector<T>& rhs){
    std::cout<<" = [ ";
    for(uint i=0; i<rhs.size(); ++i){ std::cout<<rhs[i]<<' '; }
    std::cout<<"]"<<std::endl;
}
template <typename T>
inline void print(const std::vector<std::vector<T>>& rhs){
    std::cout<<" = "<<std::endl;
    std::cout<<"[[ ";
    for(uint p=0; p<rhs.size(); ++p){
        if(p!=0){ std::cout<<" [ "; }
        for(uint q=0; q<rhs[p].size(); ++q){
            std::cout<<rhs[p][q]<<' ';
        }
        if(p!=rhs.size()-1){ std::cout<<"]"<<std::endl; }
    }
    std::cout<<"]]"<<std::endl;
}
template <typename TL, typename TR>
inline void print(const std::vector<std::pair<TR,TL>>& rhs){
    std::cout<<" = [";
    uint i=0;
    for(; i<rhs.size()-1; ++i){ std::cout<<"[f: "<<rhs[i].first<<", s: "<<rhs[i].second<<"], "; }
    std::cout<<"[f: "<<rhs[i].first<<", s: "<<rhs[i].second<<"]]" << endl;
}
#define printn(var) {printf("%s", #var);print(var);}
#define printn_all(var) {printf("%s(%d): ", __func__, __LINE__);printf("%s", #var);print(var);}

//---

class unionFind_size{
 private:
    vector<int> par; // parent
 public:
    unionFind_size(uint size): par(size, -1) {}
    ~unionFind_size(){}
    
    int root(int rhs){
        if( par[rhs] < 0 ){ return rhs;
        }       else      { return par[rhs] = root(par[rhs]); }
    }
    
    bool unite(int lhs, int rhs){
        int rL = root(lhs);
        int rR = root(rhs);
        if(rL==rR){ return false; }
        if(par[rL]>par[rR]){ swap(rL, rR); }
        par[rL] += par[rR];
        par[rR] = rL;
        return true;
    }
    
    bool same(int lhs, int rhs){
        return root(lhs)==root(rhs);
    }
    
    int size(int rhs){
        return -par[root(rhs)];
    }
};

int main(){
    int64 N, M; cin >> N >> M;
    vector<int> vA(M), vB(M);
    for(int i=0; i<M; ++i){ cin >> vA[i] >> vB[i]; --vA[i]; --vB[i]; }
    reverse(vA.begin(), vA.end());
    reverse(vB.begin(), vB.end());
//    for(int i=M-1; i>=0; --i){ cin >> vA[i] >> vB[i]; --vA[i]; --vB[i]; }
    
    unionFind_size uf(N);
//    vector<int64> vAns(M);
    vector<int64> vAns;
    int64 cur = N*(N-1)/2;
    for(int i=0; i<M; ++i){
        vAns.push_back( cur );
//        vAns[i] = cur;
        
        if(uf.same(vA[i], vB[i])){ continue; }
        
        int a = uf.size(vA[i]);
        int b = uf.size(vB[i]);
        cur -= a * b;
        
        uf.unite(vA[i], vB[i]);
    }
    
    reverse(vAns.begin(), vAns.end());
    for(int i=0; i<M; ++i){ cout << vAns[i] << endl; }
//    for(int i=M-1; i>=0; --i){ cout << vAns[i] << endl; }
    return 0;
}


Measured memory_bytes: 3444
// -- telegram @rentixous --
// -- keep calm and slava ukraini --
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N = 2e5+1488;
ll cnt[N+N+N+N+N];
ll a[N];
signed main(){
    cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);
    ll n;
    cin >> n;
    for(ll i = 0;i<n;i++){
        cin >> a[i];
        cnt[a[i]]++;
    }
    ll rs=0;
    for(ll i = 0;i<n;i++){
        bool ok=1;
        for(ll j = 1;j*j<=a[i]&&ok;j++){
            if(a[i]%j) continue;
            cnt[a[i]]--;
            if(cnt[j]||cnt[a[i]/j]) ok=0;
            cnt[a[i]]++;
        }
        if(ok) rs++;
    }
    cout<<rs;
}

Measured memory_bytes: 12980
'''
https://atcoder.jp/contests/sumitrust2019/tasks/sumitb2019_d
'''

def main():
    n = int(input())
    s = input()
    ans = 0
    for i in range(1000):
        pas = format(i, '03d')
        k, cnt = 0, 0
        for j in pas:
            if j in s[k:]:
                cnt += 1
                k += s[k:].index(j) + 1
        if cnt == 3:
            ans += 1
    print(ans)


    
if __name__ == '__main__':
    main()


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

int main()
{
  int n, k, sum = 0, tmp;
  std::vector<int> l;
  std::cin >> n >> k;
  for (int i = 0; i < n; i++)
  {
    std::cin >> tmp;
    l.push_back(tmp);
  }

  std::sort(l.begin(), l.end(), std::greater<int>());
  std::vector<int>::iterator itr;
  itr = l.begin();
  for (int i = 0; i < k; i++)
  {
    sum += *itr;
    itr++;
  }

  std::cout << sum << std::endl;
  return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
constexpr ll mod=1000000007;
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;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
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 (a>b) { a=b; return 1; } return 0; }
int main(){
V<int> dat={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
int n;
cin>>n;
cout<<dat[n-1]<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
using ll=long long;
static const ll mod = 1e9 + 7;
static const ll INF = 1LL << 50;
using namespace std;

struct UF {
	vector<int>par;//親
	vector<int>Rank;//木の深さ

            UF(int n){init(n);}

	//初期化
	void init(int n) {
		par.resize(n); Rank.resize(n);
		for (int i = 0; i < n; i++) {
			par[i]= i;
			Rank[i] = 0;
		}
	}

	//木の根を求める
	int find(int x) {
		if (par[x] == x) {
			return x;
		}
		else {
			return par[x] = find(par[x]);
		}
	}

	//xとyの属する集合を併合
	void unite(int x, int y) {
		x = find(x);
		y = find(y);
		if (x == y)return;//すでに同じ集合に属している

		if (Rank[x] < Rank[y]) {//高さが小さい方を下に
			par[x] = y;
		}
		else {
			par[y] = x;
			if (Rank[x] == Rank[y])Rank[x]++;//同じだとrankが変わらないままになるので増やす（それ以外は大きい方のrankが採用される）
		}
	}

	//xとyが同じ集合に属するかを判定
	bool same(int x, int y) {
		return find(x) == find(y);
	}
};

int main() {
	int a,b;
    cin>>a>>b;
    if(a<=5)cout<<0<<endl;
    else if(a>=13)cout<<b<<endl;
    else cout<<b/2<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.io.*;

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

        Scanner scan = new Scanner(System.in);
        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
        
		int n= scan.nextInt();
		int m = scan.nextInt();
        
        out.println(n == m ? "Yes" : "No");
        out.close();
        
    }
}

Measured memory_bytes: 35684
/*
    @uthor: Varun Mishra
    "varun21999" ->  Codechef, Codeforce, Hackerrank, Hackerearth;
*/
//#include<boost/multiprecision/cpp_int.hpp>
//using boost::multiprecision::cpp_int;
#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 int
#define ull            unsigned int
#define ld             long double
#define pb             push_back
#define pa             pair<int,int>
#define ppa            pair<pair<int,int>,int>
#define pap            pair<int,pair<int,int>>
#define v1d            vector<int>
#define v2d            vector<vector<int> >
#define vpa            vector<pair<int,int>>
#define M              1000000007
#define MN             LLONG_MIN
#define MX             LLONG_MAX
#define ff             first
#define ss             second
#define endl           "\n"
#define v1s            vector<string>
#define all(v)         v.begin(),v.end()
#define S(v)           sort(v.begin(),v.end())
#define RS(v)          sort(v.rbegin(),v.rend())
#define R(v)           reverse(v.begin(),v.end())
#define mxpq(T)        priority_queue <T>
#define mnpq(T)        priority_queue<T,vector<T>,greater<T>>
#define T              int tc;cin>>tc;while(tc--)
#define p2d(v)         for(auto a:v){for(auto b:a)cout<<b<<" ";cout<<endl;}
#define p1d(v)         for(auto a:v)cout<<a<<" ";cout<<endl;
#define ppd(v)         for(auto a:v)cout<<a.ff<<" "<<a.ss<<endl;
#define forIloop(i,n)  for(auto i=0;i<n;i++);
#define forDloop(i,n)  for(auto i=n-1;i>=0;i--);
#define qqq 400005
#define isEven(n)  (!n & 1);
const int MOD = 1e9 + 7;
// bool isEven(int n){
//     return (!(n & 1));
// }
// int popcount(int num){
//     num = num - ((num >> 1) & 0x55555555);
//     num = (num & 0x33333333) + ((num >> 2) & 0x33333333);
//     return ((num + (num >> 4) & 0xF0F0F0F) * 0x1010101) >> 24;
// }
// int powerOfTwo(int n){
//     return 1 << n;
// }

// int arr[1000001];
// bool temet = false;


void codeforce2(){
    int n,k; cin>>n>>k;
  int ans = 0;
  if(n<k){
    ans = min(n, abs(n-k));
  }
  else if(n%k==0){
    ans = 0;
  }
  else{
    int x = n/k;
    n = n - (x*k);
    ans = min(n, abs(n-k));
  }
  cout << ans << endl;

    return;
}




int32_t main(){

    cout<<fixed<<setprecision(16);
    cin.sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    
    /*#ifndef _DEBUG
     freopen("input.txt",  "r",  stdin);
     freopen("output.txt", "w", stdout);
    #endif*/
    //auto start = high_resolution_clock::now();

    // Lucario();
    //codeforceContest();
    //hackerEarth();
    //codeChef();

    // T{
    //     codeforce2();
    // }
    codeforce2();

   /* auto stop = high_resolution_clock::now();
    auto duration = duration_cast<seconds>(stop - start);
    cout << "Time: "<<duration.count()<<endl;*/
    return 0;
}

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

int main(void){
	int n = 0;
	int x = 0;
	int count = 0;
	cin >> n >> x;
	while(!(n == 0 && x == 0)){
		count = 0;
		for(int i = 1; i <= n; i++){
			for(int j = 1; j <= n; j++){
				for(int k = 1; k <= n; k++){
					if((i + k + j) == x){
						if(!(i == j || j == k || i == k) && (i < j && j < k)){
							count++;
						}
					}
				}
			}
		}
		cout << count << endl;
		cin >> n >> x;
	}
	return 0;
}

Measured memory_bytes: 1160
#include <functional>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;

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

    string s;
    cin >> s;

    vector <int> ans(s.size(), 0);

    int c = 0;
    for (int i = 0; i < s.size(); i++) {
        if (s[i] == 'R') {
            c++;
        } else {
            if (c) {
                if (c % 2 == 1) {
                    ans[i-1] += c/2 + 1;
                    ans[i] += c/2;
                } else {
                    ans[i-1] += c/2;
                    ans[i] += c/2;
                }
                c = 0;
            }
        }
    }

    c = 0;
    for (int i = s.size() - 1; i >= 0; i--) {
        if (s[i] == 'L') {
            c++;
        } else{
            if (c) {
                if (c % 2 == 1) {
                    ans[i+1] += c/2 + 1;
                    ans[i] += c/2;
                } else {
                    ans[i+1] += c/2;
                    ans[i] += c/2;
                }
                c = 0;
            }
        }
    }

    for (int a : ans) cout << a << " ";
    cout << "\n";
    return 0;
}

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

using namespace std;

typedef long long LL;
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)

int calc(int x){
	int a = 0;
	while(x){
		a += x%10;
		x /= 10;
	}
	return a;
}

int main(){
	int N; cin >> N;
	int ans = 123456789;
	repp(i,1,N){
		ans = min(ans,calc(i)+calc(N-i));
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <cstdio>
long long n, x, s, d, a[100005];
int main() {
	scanf("%d%d%d", &n, &x, &a[0]);
	for (int i=1; i<n; i++) {
		scanf("%d", &a[i]);
		d = a[i] + a[i-1] - x;
		if (d>0) a[i] -= d, s += d;
		if (a[i]<0) a[i] = 0;
	}
	printf("%lld", s);
	return 0;
}

Measured memory_bytes: 896
N = int(input())
A = list(map(int,input().split()))
A.sort()
p = 0
ans = -A[0]
for i in range(1,N-1):
    if A[i] < 0:
        p += 1
        ans -= A[i]
    else:
        ans += A[i]
ans += A[-1]
print(ans)
for i in range(p+1,N-1):
    print(A[p],A[i])
    A[p] -= A[i]
for i in range(p+1):
    print(A[-1],A[i])
    A[-1] -= A[i]


Measured memory_bytes: 85700
#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const double PI=3.14159265358979323846;
const int64_t waru = 1000000007;
using in = int64_t;

int main(){
int a,b;
  cin>>a>>b;
if(a!=1 && b!=1) cout<<1<<endl;
  else if(a!=2 && b!=2) cout<<2<<endl;
  else cout<<3;
}

Measured memory_bytes: 256
/*@shutoshsuman99*/
#include<bits/stdc++.h>
using namespace std;
#include<cstdio>
#define pi 3.141592653589
#define pb push_back
#define ld long double
#define rem 1000000007
#define rem1 998244353
#define inf 1e18+1e17
#define F first
#define S second
#define pii pair<long long,long long>
#define p_q priority_queue <ll, vector<ll>, greater<ll> >
#define m_sp multiset <pair <ll,ll> > 
#define el "\n"
#define sp " "
typedef long long ll;
ll Pow(ll x,ll y,ll m) 
{ if (y == 0) return 1; ll p = Pow(x, y/2, m) % m; 
p = (p * p) % m;return (y%2 == 0)? p : (x * p) % m; } 
main()
{ 
	// fast io
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);ll i;
	ll n,m,sum=0;
	cin>>n>>m;
	vector <ll> a(n);
	vector < pair<ll,ll> > v;
	for(i=0;i<n;i++)
	cin>>a[i],sum+=a[i];
	sort(a.begin(),a.end());
	for(i=0;i<m;i++)
	{
		ll b,c;
		cin>>b>>c;
		v.push_back({c,b});
	}
	ll j=0;
	sort(v.begin(),v.end());
	for(i=m-1;i>=0;i--)
	{
		ll cnt=0;
		while(j<n&&a[j]<v[i].first&&cnt<v[i].second)
		{
			sum-=a[j];
			sum+=v[i].first;
			cnt++;
			j++;
		}
	}
	cout<<sum<<el;
}

Measured memory_bytes: 3188
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdlib>
#include<queue>
#include<set>
#include<cstdio>

using namespace std;

#define ll long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define P pair<int, int>

typedef vector<int> vec;
typedef vector<vec> mat;

const ll mod = 1000000007;

mat mul(mat &A, mat &B){
    mat C(A.size(), vec(B[0].size()));
    for (int i = 0; i < A.size(); i++){
        for (int k = 0; k < B.size(); k++){
            for (int j = 0; j < B[0].size(); j++){
                C[i][j] = (C[i][j] + A[i][k] * B[k][j]) % mod;
            }
        }
    }
    return C;
}

mat pow(mat A, ll n){
    mat B(A.size(), vec(A.size()));
    for (int i = 0; i < A.size(); i++){
        B[i][i] = 1;
    }
    while(n > 0){
        if(n & 1) B = mul(B, A);
        A = mul(A, A);
        n >>= 1;
    }
    return B;
}

int main(){
    int n, l;
    cin >> n >> l;
    int sm = 0;
    int ans = 1000000;
    rep(i, n){
        sm += l + i;
    }
    // cout << sm << endl;
    rep(i, n){
        int sm_ = 0;
        rep(j, n){
            if(i == j) continue;
            sm_ += l + j;
        }
        if(abs(ans - sm) > abs(sm_ - sm)) ans = sm_;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3632
import java.util.*;
public class Main {
	public static void main(String[] args){
	  Scanner sc = new Scanner(System.in);
      int month = sc.nextInt();
      int day = sc.nextInt();
      int count = 0;
      
      for (int i = 22; i <= day; i++) {
         String[] s = String.valueOf(i).split("");
         int day1 = Integer.parseInt(s[0]);
         int day2 = Integer.parseInt(s[1]);
         if (day1 >= 2 && day2 >= 2) {
            int ans = day1 * day2;
            for (int j = 1; j <= month; j++) {
               if (ans == j) {
                  count++;
               }
            }
         }
      }
      
      System.out.println(count);
	}
}

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

int main() {
  vector<vector<int>> s(3, vector<int>(3));
  // 入力 (2重ループを用いる)
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      cin >> s.at(i).at(j);
    }
  }
  int N;
  cin >>N;
  vector<vector<int>> count(3, vector<int>(3));
  for(int i=0;i<N;i++){
    int b;
    cin >> b;
      for(int j=0;j<3;j++){
          for(int k=0;k<3;k++){
		if(s.at(j).at(k)==b) count.at(j).at(k)+=1;
			}
		}
	}
       if(count.at(0).at(0)>=1 && count.at(0).at(1)>=1 && count.at(0).at(2)>=1) cout<<"Yes"<<endl;
  else if(count.at(0).at(0)>=1 && count.at(1).at(0)>=1 && count.at(2).at(0)>=1) cout<<"Yes"<<endl;
  else if(count.at(0).at(0)>=1 && count.at(1).at(1)>=1 && count.at(2).at(2)>=1) cout<<"Yes"<<endl;
  else if(count.at(0).at(1)>=1 && count.at(1).at(1)>=1 && count.at(2).at(1)>=1) cout<<"Yes"<<endl;
  else if(count.at(0).at(2)>=1 && count.at(1).at(1)>=1 && count.at(2).at(0)>=1) cout<<"Yes"<<endl;
  else if(count.at(0).at(2)>=1 && count.at(1).at(2)>=1 && count.at(2).at(2)>=1) cout<<"Yes"<<endl;
  else if(count.at(1).at(0)>=1 && count.at(1).at(1)>=1 && count.at(1).at(2)>=1) cout<<"Yes"<<endl;
  else if(count.at(2).at(0)>=1 && count.at(2).at(1)>=1 && count.at(2).at(2)>=1) cout<<"Yes"<<endl;
  else cout << "No"<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<random>
#include<ctime>
#include<cstdlib>
#include<unordered_map>
using namespace std;

signed main() {
	int n, a, b; cin >> n >> a >> b;
	cout << min(n*a, b) << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <cmath>
#include <iostream>
#include <numeric>
#include <unordered_map>
#include <vector>

const int mod = 1e9 + 7;

int num_factor(int n)
{
    int cnt = 0;
    for (int i = 1; i <= n; i++) {
        if (n % i == 0) {
            cnt++;
        }
    }

    return cnt;
}

int main()
{
    int n;
    std::cin >> n;

    int count = 0;
    for (int i = 1; i <= n; i += 2) {
        if (num_factor(i) == 8) {
            count++;
        }
    }

    std::cout << count << std::endl;
}


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

int main () {
	int N, L;
	vector <string> S;
	cin >> N >> L;
	for (int i=0; i<N; i++) {
		string tmp;
		cin >> tmp;
		S.push_back (tmp);
	}
	sort (S.begin (), S.end());
	for (int i=0; i<N; i++)
		cout << S.at (i);
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int L=500005,M=500005;
typedef long long ll;
const int base=10;
struct BigInt{
    int a[M];
    int len;
    BigInt(){}
    BigInt(char *s){
        memset(a,0,sizeof a);
        len=strlen(s+1);
        for(int i=len;i>=1;i--)
            a[i]=s[len-i+1]-'0';
    }
};
int ans;
void operator +=(BigInt& x,int y){
    x.a[1]+=y;
    ans+=y;
    for(int i=1;i<=x.len;i++){
        if(x.a[i]>=base){
            if(i==x.len)
                x.len++;
            ans-=x.a[i];
            ans-=x.a[i+1];
            x.a[i+1]++;
            x.a[i]-=base;
            ans+=x.a[i];
            ans+=x.a[i+1];
        }
        else
            break;
    }
}
BigInt operator *(BigInt x,int y){
    int r=0;
    for(int i=1;i<=x.len;i++){
        x.a[i]*=y;
        x.a[i]+=r;
        if(x.a[i]>=base){
            r=x.a[i]/base;
            x.a[i]%=base;
        }
        else
            r=0;
    }
    x.len++;
    x.a[x.len]+=r;
    while(x.len>0&&x.a[x.len]==0)
        x.len--;
    return x;
}
int sum(BigInt x){
    int res=0;
    for(int i=1;i<=x.len;i++){
        res+=x.a[i];
    }
    return res;
}
char s[L];
int main()
{
    //freopen("z.in","r",stdin);
    scanf("%s",s+1);
    BigInt x(s);
    x=x*9;
    ans=sum(x);
    for(int k=1;;k++){
        x+=9;
        //if(k%10000==0)
        //    puts("!");
        if(ans<=9*k){
            printf("%d\n",k);
            return 0;
        }
    }
}



Measured memory_bytes: 8448
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#define REP(i,n) for(int i = 0;i < (n);i++)
#define pb push_back
using namespace std;
const int INF = 1e9;
typedef long long ll;

int main(){
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  a += b;
  c += d;

  if(a == c)
    cout << "Balanced" << endl;
  else if(a > c)
    cout << "Left" << endl;
  else
    cout << "Right" << endl;
  return 0;
}


Measured memory_bytes: 256
n=int(input())
from fractions import Fraction
import math
t=[[int(i)for i in input().split()]for i in range(n)]
dp=[0]*n
dp[0]=1
for i in range(1,n):
    dp[i]=math.ceil((max(Fraction(t[i-1][0],t[i][0]),Fraction(t[i-1][1],t[i][1]))*dp[i-1]))
print(dp[-1]*(t[n-1][0]+t[n-1][1]))

Measured memory_bytes: 5944
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <functional>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main(void){
    int n, m;
    cin >> n >> m;
    string s(n, '*');
    REP(i,m){
        int c, x;
        cin >> c >> x;
        c--;
        char d = '0' + x;
        if (s[c] == '*') s[c] = d;
        else if (s[c] != d){
            cout << -1 << endl;
            return 0;
        }
    }
    if (n == 1){
        if (s[0] == '*') s[0] = '0';
        cout << s << endl;
        return 0;
    }
    REP(i,n){
        if (s[i] == '*'){
            if (i == 0) s[i] = '1';
            else s[i] = '0';
        }else if (i == 0 && s[i] == '0'){
            cout << -1 << endl;
            return 0;
        }
    }
    cout << s << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
const ll inf=1e18;
const int MAXN=4e5+5;
int a[MAXN];
ll g[MAXN][65];
int pos[MAXN];
ll n,m;
int main(){
	scanf("%lld%lld",&n,&m);
	for (int i=0;i<n;i++) scanf("%d",&a[i]),a[i+n]=a[i];
	for (int i=0;i<2*n;i++) pos[i]=-1;
	for (int i=0;i<2*n;i++){
//		if (i==5) cout<<pos[a[i]]<<" "<<a[i]<<endl;
		if (pos[a[i]]!=-1){
//			cout<<i<<"-<"<<pos[a[i]]<<" "<<a[i]<<endl;
			g[pos[a[i]]][0]=i-pos[a[i]]+1;
			pos[a[i]]=i;
		}
		else pos[a[i]]=i;
	}
	for (int i=0;i<n;i++){
		if (g[i][0]==0) g[i][0]=n*m+1;
//		cout<<i<<" "<<g[i][0]<<endl;
	}
	for (int k=1;k<=60;k++){
		for (int i=0;i<n;i++){
			g[i][k]=min(n*m+1,g[i][k-1]+g[(i+g[i][k-1])%n][k-1]);
		}
	}
	ll now=0;
	for (int k=60;k>=0;k--){
//		cout<<now<<" "<<g[now%n][k]<<endl;
		if (now+g[now%n][k]<n*m) now+=g[now%n][k];
//		cout<<k<<" "<<now<<endl;
	}
//	cout<<endl<<now<<endl;
	for (ll i=now;i<n*m;i++){
//		cout<<i<<endl;
		ll x=i%n;
		if (x+g[x][0]<=n) i=i+g[x][0]-1;
		else printf("%d ",a[x]);
	}
	printf("\n");
	return 0;
}


Measured memory_bytes: 206464
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
using namespace std;

int main() {
	int n;
	bool switch_a = true;
	int sum_a = 0,sum_b=0;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++) cin >> a[i];

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

	for (int i = n-1; i >= 0 ; i--) {
		if (switch_a){
			sum_a += a[i];
			switch_a = false;
		}
		else {
			sum_b += a[i];
			switch_a = true;
		}
	}

	cout << sum_a - sum_b << endl;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Stream;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.nextLine());
        String[] sa = sc.nextLine().split(" ");
        int[] ia = Stream.of(sa).mapToInt(Integer::parseInt).toArray();

        int rs = 0;
        int rb = 0;
        List<Integer> li = new ArrayList<>();
        for(int i = 0; i < ia.length; i++) {
           li.add(abs(ia, N, i));
        }

        System.out.println(li.stream().map(Math::abs).sorted().findFirst().get());
    }
    private static int abs(int[] ia, int N, int i) {
        int rs = 0;
        int rb = 0;
        for(int y = 0; y < i+1 ; y++) {
            rs += ia[y];
        }
        for (int k = i+1; k < N; k++) {
            rb += ia[k];
        }
        return rb - rs;
    }
}

Measured memory_bytes: 29140
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;

int main() {
	int N, T; cin >> N >> T;
	vector<int>t(N);
	for (int i = 0; i < N; i++) cin >> t[i];

	long long last = 0;
	long long ans = 0;
	for (int i = 1; i < N; i++) {
		last = max(t[i], t[i - 1] + T);

		if (last > t[i])ans += t[i] - t[i - 1];
		else ans += min(t[i] - t[i-1], T);
	}

	cout << ans + T << endl;

	return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
int main()
{
	int a,b,c,coin=0,i;
	scanf("%d%d%d",&a,&b,&c);
	for(i=1;;i++){
		coin=coin+a;
		if(i%7==0){
			coin=coin+b;
		}
		if(coin>=c){
			break;
		}
	}
		printf("%d\n",i);
	return 0;
}



Measured memory_bytes: 2052
import math

n = int(input())

ans = 0
for i in range(1, n+1):
    if i % 2 != 0:
        prime_num = 0
        for j in range(1, n+1):
            if i % j == 0:
                prime_num += 1
        if prime_num == 8:
            ans += 1

print(ans)

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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using edge = pair<ll, P>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
using Graph = vector<vector<ll>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    int N, K;
    cin >> N >> K;
    deque<int> queue;
    rep(i, N) {
        int v;
        cin >> v;
        queue.push_back(v);
    }
    ll ans = 0;
    rep(i, min(K + 1, N + 1)) {
        rep(j, min(N-i+1, K-i+1)) {
            int remain = K - i - j;
            deque<int> que;
            copy(queue.begin(), queue.end(), back_inserter(que));
            vector<int> tmp;
            rep(a, i) {
                tmp.push_back(que.front());
                que.pop_front();
            }
            rep(a, j) {
                tmp.push_back(que.back());
                que.pop_back();
            }
            sort(tmp.begin(), tmp.end());
            ll num = 0;
            for (int q : tmp) {
                if (q <= 0 && remain >= 1) {
                    remain --;
                    continue;
                }
                num += q;
            }
            ans = max(ans, num);
            remain += j;
        }
    }
    cout << ans << endl;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
}


Measured memory_bytes: 256
n, a, b=gets.strip.split.map(&:to_i)
h = readlines.map {|line| line.strip.to_i }
c=a-b

ok=h.max
ng = 0

while ok-ng > 1
  mid = ((ok+ng)/2.to_f).to_i
  remains = h.map {|e| e-b*mid }.select {|e| e>0 }
  if remains.length.zero?
    ok = mid
    next
  end

  if mid >= remains.map {|e| (e/c.to_f).ceil }.inject(:+)
    ok = mid
  else
    ng = mid
  end
end

p ok


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

#define fs first
#define sc second
#define pb emplace_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

signed main() {
  string s;
  int a, b, c, d, e;

  cin >> a >> b;
  cout << (b - a) * 2 + a << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <sstream>
using namespace std;
int main()
{
    long long int x=0,x1=0,x2=0;
    cin>>x;
    if(x>=500 && x%500==0)
    {
        cout<<(x/500)*1000;
    }
    else if(x>=500 && x%500!=0)
    {
        x1=x/500;
        x2=x-(x1*500);
        x2=x2/5;
        cout<<(x1*1000)+(x2*5);
    }
    else
    {
        x1=x/5;
        cout<<x1*5;
    }

}




Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n = read();
    let mut flag = true;
    for _ in 0..n {
        let n: u32 = read();
        if (n % 2 == 0) && ((n % 3 != 0) && (n % 5 != 0)) {
            flag = false
        }
    }
    let ans = if flag == true { "APPROVED" } else { "DENIED" };
    println!("{}", ans);
}


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

#define loop(i, n) for(int i = 0; i < n; i++)
#define sloop(i, s, n) for (int i = s; i < n; i++)
#define rloop(i, n) for (int i = n - 1; i >= 0; i--)

using namespace std;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    long long int n, ans = 0;
    cin >> n;
    if(n == 1) {
        cout << 0 << endl;
        return 0;
    }
    n--;
    ans = (n*(n+1))/2ll;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3632
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int K = sc.nextInt();
        long sum = 0;
        
        for (int i = 1; i <= K; i++) {
            for (int j = 1; j <=K; j++) {
                for (int m = 1; m<=K; m++) {
                    sum+=gcd(gcd(i, j), m);
                }
            }
        }
        
        System.out.println(sum);
        sc.close();
    }
    private static long gcd(long m, long n) {
        if(m < n) return gcd(n, m);
        if(n == 0) return m;
        return gcd(n, m % n);
    }
}

Measured memory_bytes: 36180
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
#include <map>
#include <cmath>
#include <iomanip> 
#include <bits/stdc++.h>
using namespace std;
const int dx[4]={0,0,1,-1};
const int dy[4]={1,-1,0,0};
double pi=3.14159265358979323846264338;


int h,w,k;
int x1,x2,z,y2;
string arr[6000001];
int arr2[4];
int clf,crg;
int main() {
	clf=-1;crg=-1;
	cin>>h>>w>>k;
	
	cin>>x1>>x2>>z>>y2;
	for(int i=1;i<=h;i++)cin>>arr[i];
	long long dis=0;
	queue<pair<int,int>>que;
	map<pair<int,int>,int>map;
	map.insert(pair<pair<int,int>,int>(make_pair(x1,x2-1),0));
	arr[x1][x2-1]='@';
	que.push(make_pair(x1,x2-1));
	while(!que.empty()){
		auto cur=que.front();
		que.pop();
      	//int ind=1;
		int lf=cur.first;
		int rg=cur.second;
      	arr[lf][rg]='@';
		for(int i=0;i<4;i++){
			for(int j=1;j<=k;j++){
				int llf=lf+j*dx[i];
				int rrg=rg+j*dy[i];
				if(llf<1||llf>h||rrg<0||rrg>w-1)break;
				if(arr[llf][rrg]=='@')break;
              	if(arr[llf][rrg]=='b')continue;
              	//else cout<<llf<<" "<<rrg<<" "<<arr[llf][rrg]<<endl;
				if(llf==z&&rrg+1==y2){
                  //	cout<<lf<<" "<<rg<<" "<<llf<<" "<<rrg<<endl;
                  	
					cout<<map[cur]+1<<endl;
					return 0;
				}
				arr[llf][rrg]='b';
				que.push(make_pair(llf,rrg));
				map.insert(pair<pair<int,int>,int>(make_pair(llf,rrg),map[cur]+1));
			}
		}
	}
	cout<<"-1"<<endl;
	
	
  return 0;
}


Measured memory_bytes: 229060
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int pn[6000], l = 0;
void push(int k) { pn[l] = k; l++; }
void mpn() {
	push(2);
	for (int i = 3; i <= 55555; i += 2) {
		bool flag = true;
		for (int j = 0; j < l; j++) {
			if (i%pn[j] == 0)flag = false;
		}
		if (flag)push(i);
	}
}
int main() {
	mpn();
	vector<int>a;
	for (int i = 0; i < l; i++) {
		if (pn[i] % 5 == 1)a.push_back(pn[i]);
	}
	int k; cin >> k;
	for (int i = 0; i < k; i++) {
		if (i)cout << ' ';
		cout << a[i];
	}
	cout << endl;
}

Measured memory_bytes: 256
import sys
def main():
    input=sys.stdin.readline
    S=input().strip()
    dp=[[0,0] for i in range(len(S)+1)]
    dp[0][1]=1
    for i in range(1,len(S)+1):
        for j in (0,1):
            if j==0:
                dp[i][0]=min(dp[i-1][0]+int(S[i-1]),dp[i-1][1]+10-int(S[i-1]))
            elif j==1:
                dp[i][1]=min(dp[i-1][0]+int(S[i-1])+1,dp[i-1][1]+10-int(S[i-1])-1)

    print(dp[len(S)][0])

if __name__=="__main__":
    main()

Measured memory_bytes: 134532
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <stdio.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int ans[4];
string S[4] = {"AC", "WA", "TLE", "RE"};

int main(){
  int N; cin >> N;
  for (int i = 0; i < N; i++){
    string T; cin >> T;
    for (int j = 0; j < 4; j++){
      if (S[j] == T) ans[j]++;
    }
  }

  for (int i = 0; i < 4; i++){
    cout << S[i] << " x " << ans[i] << endl;
  }

  return 0;
}


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

#define ll long long
#define pu push
#define pb push_back
#define ull unsigned long long
#define set_pre setprecision
#define cl clear
#define fi first
#define se second
#define For(i,a,b) for(int i = a; i <= b; i++)
#define Fors(i,a,b) for(int i = a; i < b; i++)

typedef pair<char, int> ii;
typedef vector<ii> vii;
typedef vector<vii> vvii;
typedef vector<int> vi;
typedef vector<vi> vvi;

const int maxn = 1e6 + 7;
const int oo = 1e9 + 7;
const int mod = 1e9 + 7;
const int max_dsk = 3e5 + 7;
const int maxc_IT = 4 * maxn;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;
    cin >> n;
    int x = n / 2;
    if(n % 2 == 1) x++;
    cout << fixed << setprecision(10) << (double)x / n << endl;
}


Measured memory_bytes: 256
import numpy as np
n,k = map(int,input().split())
a = np.array(list(map(int,input().split())))


af = [0]*n
al = [0]*n

for i in range(n):
    b = a[i+1:]
    af[i] = len(b[b < a[i]])
    al[i] = len(a[a < a[i]])
s = 0

for i in range(n):
    s += al[i] * (k**2 - k*(k+1)//2) + af[i] * k
    s %= 1000000007
print(s)


Measured memory_bytes: 12428
import java.util.*;class Main{public static void main(String[]z){for(Scanner s = new Scanner(System.in);s.hasNext();){String d=""+s.nextDouble()/s.nextDouble();int r = 0,n=s.nextInt(),i=0;for(d=d.substring(d.indexOf('.')+1);i<n&&i<d.length();)r+=d.charAt(i++)-'0';System.out.println(r);}}}

Measured memory_bytes: 12000
// ==============================================
// Library
// ==============================================
#define _CRT_SECURE_NO_WARNINGS

// When you are using the gcc compiler, you need only the following lines.
// #include <bits/stdc++.h>

// When you are using other compilers, you need the following line instead.
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>

using namespace std;

// competitive macro
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b) - 1; i >= (a); i--)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i ,n) for (int i = (n) - 1; i >= 0; i--)
#define LL long long
#define ULL unsigned long long

// If you use this function, "cin" speeds up.
// However, you can not mix "cin" and "scanf", "cout" and "printf".
void fastIOS()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
}
// ==============================================
// ==============================================

int main()
{
	fastIOS();

	ULL x;
	cin >> x;

	ULL n = (x / 11) * 2;
	x = x % 11;

	if (x != 0)
	{
		if (x <= 6)
			n += 1;
		else
			n += 2;
	}

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

Measured memory_bytes: 256
import sys
def input():
    return sys.stdin.readline()[:-1]
from fractions import gcd
div = 10**9 + 7

def main():
    N = int(input())
    A = list(map(int, input().split()))
    sA = list(set(A))

    val = 1
    def lcm(a, b):
        ret = gcd(a, b)
        ret = a*b//ret
        return ret

    val = sA[0]
    for a in sA[1:]:
        val = lcm(val, a)

    B = [val//a for a in A]
    sumB = sum(B)
    sumB %= div

    print(sumB)

if __name__ == '__main__':
    main()  

Measured memory_bytes: 264784
#include <iostream>
#include <cctype>

int main() {
    std::string s{};
    std::getline(std::cin, s);
    for(auto& c : s) {
        if(isalpha(c)) {
            c = islower(c) ? toupper(c) : tolower(c);
        }
    }
    std::cout << s << std::endl;
}



Measured memory_bytes: 3172
#include<algorithm>
#include <iostream>
#include<cstdio>
#include<cmath>
#include<iomanip>
#include<string>
#include<cstdlib>
#include<ctime>
#include<vector>
#include<map>
using namespace std;

int main(){

    int n,k;
    cin>>n>>k;

    int cnt=1;
    int rest=n;

    while(rest>=k){
        rest=rest/k;
        cnt+=1;
    }

    cout<<cnt<<endl;

return 0;
}


Measured memory_bytes: 256
H, W = map(int, input().split())
sx, sy = map(int, input().split())
sx -= 1; sy -= 1
tx, ty = map(int, input().split())
tx -= 1; ty -= 1

S = [input() for _ in range(H)]


dxy = [(-1, 0), (0, -1), (1, 0), (0, 1)]
dist = {}
next_points = set([(sx, sy)])
def bfs(d):
    global dist, next_points
    stack = list(next_points)
    next_points = set()
    while stack:
        x, y = stack.pop()
        if (x, y) in dist and dist[(x, y)] < d:
            continue
        dist[(x, y)] = d
        count = 0
        for dx, dy in dxy:
            xx = x + dx; yy = y + dy
            if 0 <= xx < H and 0 <= yy < W and S[xx][yy] == '.':
                count += 1
                if (xx, yy) not in dist:
                    dist[(xx, yy)] = d
                    stack.append((xx, yy))
        
        if count < 4:
            for dx in range(-2, 3):
                xx = x + dx
                for dy in range(-2, 3):
                    yy = y + dy
                    if (xx, yy) not in dist and 0 <= xx < H and 0 <= yy < W \
                            and S[xx][yy] == '.':
                        next_points.add((xx, yy))

d = 0
while (tx, ty) not in dist:
    bfs(d)
    d += 1
    if len(next_points) == 0:
        if (tx, ty) in dist:
            print(dist[(tx, ty)])
        else:
            print(-1)
        quit()

print(dist[(tx, ty)])

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

ll gcd(ll a, ll b){return b!=0 ? gcd(b, a%b) : a;}
ll lcm(ll a, ll b){return a / gcd(a, b) * b;}

int bitCount(int bits) {
    int cnt = 0;
    for(uint mask = 1; mask != 0; mask<<=1) {
        if( (bits & mask) != 0 )
            ++cnt;
    }
    return cnt;
}

int main(){
	int n, m;
	cin >> n >> m;
	
	vector<vector<int>> s(m, vector<int>());
	for(int i = 0; i < m; ++i){
		int k;
		cin >> k;
		for(int j = 0; j < k; ++j){
			int ss;
			cin >> ss;
			s[i].push_back(ss);
		}
	}
	
	vector<int> p(m);
	for(int i = 0; i < m; ++i){
		cin >> p[i];
	}
	
	int count = 0;
	for(int i = 0; i < (1 << n); ++i){
		bool fail = false;
		for(int j = 0; j < m; ++j){
			int bit = 0;
			for(int k = 0; k < s[j].size(); ++k){
				bit |= 1 << (s[j][k] - 1);
			}
			bit = i & bit;
			if(bitCount(bit) % 2 != p[j]) fail = true;
		}
		if(!fail) count++;
	}
	cout << count << endl;
	return 0;
}



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

// clang-format off
#define fs first
#define sc second
#define pb emplace_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define debug(x) cerr << "(" << __LINE__ << ")" << #x << ": " << x << endl

#define rep(i, n) for (int i = 0; i < (int)(n); ++(i))
#define reps(i, n) for (int i = 1; i <= (int)(n); ++(i))
#define rrep(i, n) for (int i = (int)(n) - 1; i >= 0; --(i))
#define rreps(i, n) for (int i = (int)(n); i > 0; --(i))

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

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

using int32 = int;
using int64 = long long;

constexpr int mod     = 1e9 + 7;
constexpr int32 inf   = 1001001001;
constexpr int64 infll = 1001001001001001001ll;
constexpr int dx[]    = {0, -1, 1, 0, -1, 1, -1, 1},
              dy[]    = {-1, 0, 0, 1, -1, -1, 1, 1};
const string YES = "YES", NO = "NO", Yes = "Yes", No = "No", yes = "yes", no = "no";

template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { os << v[0]; for (int i = 1; i < v.size(); ++i) os << " " << v[i]; 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.fs << " " << p.sc; return os; }
template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.fs >> p.sc; return is; }

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

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

template <typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template <typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(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); }
// clang-format on

void solver() {
    int N = input();

    double ans = 0;
    double btc_rate = 380000.0;
    range(i, 0, N) {
        double x = input<double>();
        string u = input<string>();

        if (u == "JPY") {
            ans += x;
        } 
        else {
            ans += btc_rate * x;
        }
    }

    cout << ans << endl;
}

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



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

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

vs dfs(vs map, int nx, int ny) {
	map[nx][ny] = '0';
	for (int i=0; i<12; i++) {
		if (nx+dx[i]>=0&&nx+dx[i]<8&&
				ny+dy[i]>=0&&ny+dy[i]<8&&
				map[nx+dx[i]][ny+dy[i]]=='1') {
			map = dfs(map, nx+dx[i], ny+dy[i]);
		}
	}
	return map;
}

int main() {
	int n; cin >> n;
	for (int i=0; i<n; i++) {
		vs map(8);
		for (int j=0; j<8; j++) cin >> map[j];
		int x, y;
		cin >> x >> y;
		map = dfs(map, y-1, x-1);
		cout << "Data " << i+1 << ":" << endl;
		for (int j=0; j<8; j++) cout << map[j] << endl;
	}
}

Measured memory_bytes: 1232
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;
typedef pair<int, int> pint;
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s; cin>>s;
    string t; cin>>t;
    Int ans=LINF;
    for(int i=0; i<=(int)s.size()-(int)t.size(); i++){
      Int tmp=0;
      for(int j=0; j<(int)t.size(); j++){
        if(s[i+j]!=t[j]) tmp++;
      }
      ans=min(ans,tmp);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int a[N];
int main() {
	int n,sum=0;
	scanf("%d",&n);
	for(int i=0;i<n;i++) scanf("%d",&a[i]);
	sort(a,a+n);
	stack<int>q;
	while(!q.empty()) q.pop();
	q.push(a[0]);
	for(int i=1;i<n;i++) {
		if(q.empty()) {
			q.push(a[i]);
			continue;
		}
		int p=q.top();
		if(p==a[i]) q.pop();
		else q.push(a[i]);
	} 
	printf("%d\n",(int)q.size());
	return 0;
} 

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


typedef long long ll;
ll N, M, sum;

int main ()
{
    cin >> N >> M;
    sum = 0;

    for(int i = 0; i < M; i++)
    {
        ll A;
        cin >> A;
        sum += A;
    }
    if(N >= sum) cout << N - sum << endl;
    else cout << -1 << endl;

}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
#define eps 1e-6
#define rep(i,n) for(int i=0;i<n;++i)
#define rep2(i,n) for(int i=1;i<=n;i++)
#define snc(a,b,c) ((a)?(b):(c))
#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl;
#define No cout<<"No"<<endl;
#define ins insert
#define pb push_back
using namespace std; 

int main(){
  int a;
  cin >> a;
  cout << a/3 << endl;
    return 0;
}


Measured memory_bytes: 256
A,B,C,X,Y=map(int,input().strip().split())

ans=A*X+B*Y
Z=0
while max(X,Y)*2>=Z:
    x=max(0,X-(Z//2))
    y=max(0,Y-(Z//2))
    ans=min(ans,A*x+B*y+C*Z)
    Z+=2
print(ans)

Measured memory_bytes: 9120