akhauriyash/Code-Regression huggingface dataset:
#include"bits/stdc++.h"
#include<boost/multi_array.hpp>
#include<boost/optional.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptors.hpp>
using namespace std;
namespace adaptor = boost::adaptors;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
typedef long long ll;
typedef pair<int,int> pii;

void Main()
{
	int N;
  	cin >> N;
    vector<pii> V(N);
    rep(i,N) cin >> V[i].second >> V[i].first;
    
	sort(V.begin(),V.end());
	bool check = true;
    int sumA = 0;
    
    rep(i,N){
    	sumA += V[i].second;
		if(sumA > V[i].first){ //NG
        	check = false;
            break;
        }
    }
    if(check){ puts("Yes"); }
    else { puts("No"); }
	return;
}

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


Measured memory_bytes: 1792
#include<iostream>
#include<string>
#include<math.h>

using namespace std;

int main(void){
	int a, b, res, tax8;

	cin >> a >> b;

	if(a < 0 || b < 0){
		cout << -1 << endl;
		return 0;
	}

	res = b * 10;
	for(res = b * 10; res < (b + 1) * 10; ++res){
		tax8 = res * 8 / 100;
		if(tax8 == a){
			goto end;
		}
	}

	res = -1;
end:
	cout << res << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <unordered_map>
#include <string>
#include <cmath>
#include <set>
#include <cmath>
using namespace std;



void solve()
{
	int n;
	cin >> n;

	long long da = 0, db = 0, dc = 0;

	for (int i = 0; i < n; i++)
	{
		long long a, b, c;
		cin >> a >> b >> c;

		long long ta, tb, tc;
		ta = max(db, dc) + a;
		tb = max(da, dc) + b;
		tc = max(da, db) + c;
		da = ta;
		db = tb;
		dc = tc;
	}
	cout << max(max(da, db), dc);
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	//freopen("file.in", "r", stdin);//freopen("file.out", "w", stdout);

	int t = 1;
	//cin >> t;
	while (t--)
	{
		solve();
	}
	return 0;
}

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

using namespace std;

int N, K;
char D[11];
bool flag;

void solve() {
    for(int i = N; i < 100000; i++) {
        //数値を文字列に
        int num = i;
        string str = "";
        while(num){
            char x = '0'+num % 10;
            str.push_back(x);
            num /= 10;
        }
        reverse(str.begin(),str.end());

        flag = true;
        for(int j = 0; j < str.size(); j++) {
            for(int k = 0; k < K; k++) {
                if(str[j] == D[k]) flag = false; 
            }
        }
        if(flag) {
            cout << i << endl;
            return;
        }
    }
}

int main() {
    cin >> N >> K;
    for(int i = 0; i < K; i++) cin >> D[i];
    solve();
}



Measured memory_bytes: 256
#include <iostream>
#include <array>
#include <map>
#include <algorithm>
#include <cmath>
#include <vector>
#include <fstream>
#include <string>
#include <random>
#include <queue>
#include <iomanip>
#include <functional>
#include <climits>
#include <tuple>
#include <unordered_map>
#include <limits>
#include <functional>
#include <cassert>
#include <numeric>
#include <bitset>
#include <set>

#define FOR(x,n) for(int x = 0; x < n; x++)
#define INPUT(x) scanf("%d",&x)
#define PUT(x) printf("%d\n",x)
#define DPUT(x) printf("%.15lf\n",x)
#define GET(x,y) std::get<x>(y)
#define CHMAX(x,y) x = std::max(x,y)
#define CHMIN(x,y) x = std::min(x,y)
#define SP_END (i != n - 1 ? ' ' : '\n') ;

using namespace std;

using ll = long long int;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vll = std::vector<ll>;
using vpll = std::vector<pll>;
using vpii = std::vector<pii>;
using vi = std::vector<int>;
using vvi = std::vector<vi>;
using vvpii = std::vector<vpii>;
using vch = std::vector<char>;
using vvch = std::vector<vch>;
using tiii = std::tuple<int, int, int>;

const ll mod197 = 1000000007LL;
const ll INF = 10000000000LL;

const double PI11 = 3.14159265359;

const int dis[5] = { 0,1,0,-1,0 };

const int disD[4] = { 0,1,1,0 };
const int disLD[3] = { 0,1,0 };

const char disC[4] = { 'U','D','R','L' };
const char disY[4] = { -1,1,0,0 };
const char disX[4] = { 0,0,1,-1 };

//最大公約数
ll gcd(ll a, ll b) {
	if (a%b == 0)
		return b;
	return gcd(b, a%b);
}

char field[100][100] = {};

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

	if (A == 1) {
		//N段必要か？
		int N = (B + 49) / 50;
		int M = B % 50;

		cout << 2 * N << " 100" << endl;

		for (int i = 0; i < 2 * N; i++) {
			for (int j = 0; j < 100; j++) {
				field[i][j] = '.';
				if (i % 2 == 0 && j % 2 == 1 && B > 0) {
					B--;
					field[i][j] = '#';
				}
			}
		}

		for (int i = 0; i < 2 * N; i++) {
			for (int j = 0; j < 100; j++) {
				cout << field[i][j];
			}
			cout << endl;
		}

	}
	else if (B == 1) {
		int N = (A + 49) / 50;
		int M = A % 50;

		cout << 2 * N << " 100" << endl;

		for (int i = 0; i < 2 * N; i++) {
			for (int j = 0; j < 100; j++) {
				field[i][j] = '#';
				if (i % 2 == 1 && j % 2 == 1 && A > 0) {
					A--;
					field[i][j] = '.';
				}
			}
		}

		for (int i = 0; i < 2 * N; i++) {
			for (int j = 0; j < 100; j++) {
				cout << field[i][j];
			}
			cout << endl;
		}
	}
	else {
		A--;
		B--;

		int N = (B + 49) / 50;
		cout << 2 * ((B + 49) / 50) +  2 * ((A + 49) / 50) << " 100" << endl;

		for (int i = 0; i < 2 * N; i++) {
			for (int j = 0; j < 100; j++) {
				field[i][j] = '.';
				if (i % 2 == 0 && j % 2 == 1 && B > 0) {
					B--;
					field[i][j] = '#';
				}
			}
		}

		for (int i = 0; i < 2 * N; i++) {
			for (int j = 0; j < 100; j++) {
				cout << field[i][j];
			}
			cout << endl;
		}


		N = (A + 49) / 50;

		for (int i = 0; i < 2 * N; i++) {
			for (int j = 0; j < 100; j++) {
				field[i][j] = '#';
				if (i % 2 == 1 && j % 2 == 1 && A > 0) {
					A--;
					field[i][j] = '.';
				}
			}
		}

		for (int i = 0; i < 2 * N; i++) {
			for (int j = 0; j < 100; j++) {
				cout << field[i][j];
			}
			cout << endl;
		}

	}



	return 0;
}


Measured memory_bytes: 256
import java.util.*;
class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        if(n>m) {
            int t = n;
            n = m;
            m = t;
        } 
        if(n==1 && m == 2) {
            System.out.println(3);    
        }else if(n == 1 && m == 3) {
            System.out.println(2);
        }else {
        System.out.println(1);
    }
    }
}

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

#pragma warning(disable:4996)
using namespace std;



int main() {
	int N;cin>>N;
	map<string,map<int,int>>mps;
	for (int i = 0; i < N; ++i) {
		string st;cin>>st;
		int d;cin>>d;
		mps[st][d]++;
	}
	for (auto m : mps) {
	}
	int M;cin>>M;
	int k=-1;
	bool ok=true;
	for (int i = 0; i < M; ++i) {
		string st;cin>>st;
		auto it=mps[st].upper_bound(k);
		if (it == mps[st].end()) {
			ok=false;
		}
		else {
			k = it->first;
			it->second--;
			if (it->second == 0) {
				mps[st].erase(it);
			}
		}
	}
	if (ok) {
		cout<<"Yes"<<endl;
	}
	else {
		cout<<"No"<<endl;
	}
	return 0;
} 


Measured memory_bytes: 25096
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long ll;
const int MAXN = 2e5 + 5;
const int mod = 1e9 + 7;

int main(void)
{
	int n,d;
	scanf("%d%d",&n,&d);
	ll ans=0;
	for(int i=d; i<=n+1; ++i)
	{
		ll l = (ll)i*(i-1)/2;
		ll r = (ll)n*i - l;
		ans += r-l+1;
		ans %= mod;
	}
	printf("%lld",ans);
	return 0;
}

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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

template<typename H> bool chmin(H& v1, const H v2) { if (v1 > v2) { v1 = v2; return true; } return false; }
template<typename H> bool chmax(H& v1, const H v2) { if (v1 < v2) { v1 = v2; return true; } return false; }
template<typename H> void read(H& head) { cin >> head; }
template<typename H, typename ...T> void read(H& head, T& ...tail) { cin >> head; read(tail...); }
template<typename H> void print(H head) { cout << head << '\n'; }
template<typename H, typename ...T> void print(H head, T ...tail) { cout << head << " "; print(tail...); }

int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin.exceptions(cin.failbit);

	string s; cin >> s;
	int ans = 0;
	rep(i, 0, sz(s) - 1) if (s[i] != s[i + 1]) ans++;
	cout << ans << endl;
}


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

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

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

	vector <vector <int>>dp(n,vector<int> (3));

	dp[0][0]=arr[0][0];
	dp[0][1]=arr[0][1];
	dp[0][2]=arr[0][2];

	for(int i=1;i<n;i++)
	{
		dp[i][0]=arr[i][0]+max(dp[i-1][1],dp[i-1][2]);
		dp[i][1]=arr[i][1]+max(dp[i-1][0],dp[i-1][2]);
	    dp[i][2]=arr[i][2]+max(dp[i-1][0],dp[i-1][1]);
	}

    cout<<max({dp[n-1][0],dp[n-1][1],dp[n-1][2]})<<endl;

	return 0;
}


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

#ifdef _DEBUG
#define debug(x) cerr << "line: " << __LINE__ << ", func: " << __func__ << " ->  " << #x << " = " << x << endl
#else
#define debug(x)
#endif

#define all(s) begin(s), end(s)
#define rall(s) rbegin(s), rend(s)
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = ((a)-1); i >= (b); i--)
#define pb push_back
#define sz(a) int((a).size())
#define put(a) ((cout) << (a) << (endl))

using namespace std;

using ll = long long;
using ull = unsigned long long;
using i_i = pair<int, int>;
using ll_ll = pair<ll, ll>;
using d_ll = pair<double, ll>;
using ll_d = pair<ll, double>;
using d_d = pair<double, double>;

static constexpr ll LL_INF = 1LL << 60;
static constexpr int I_INF = 1 << 28;
static constexpr double PI = static_cast<double>(3.14159265358979323846264338327950288);
static constexpr double EPS = numeric_limits<double>::epsilon();

static map<type_index, const char* const> scanType = {
    {typeid(int), "%d"}, {typeid(ll), "%lld"}, {typeid(double), "%lf"}, {typeid(char), "%c"}};

template <class T> static void scan(vector<T>& v);
[[maybe_unused]] static void scan(vector<string>& v, bool isWord = true);
template <class T> static inline bool chmax(T& a, T b);
template <class T> static inline bool chmin(T& a, T b);
template <class T> static inline T gcd(T a, T b);
template <class T> static inline T lcm(T a, T b);
template <class A, size_t N, class T> static void Fill(A (&arr)[N], const T& val);

int main(int argc, char* argv[]) {
  long long N;
  scanf("%lld", &N);
  long long M;
  scanf("%lld", &M);
  std::vector<long long> A(N);
  priority_queue<ll> q;
  for (int i = 0; i < N; i++) {
    scanf("%lld", &A[i]);
    q.push(A[i]);
  }

  rep(i, 0, M) {
    ll price = q.top();
    q.pop();
    q.push(price / 2);
  }

  ll ans = 0;
  while (!q.empty()) {
    ll price = q.top();
    q.pop();
    ans += price;
  }
  put(ans);
  return 0;
}

template <class T> static void scan(vector<T>& v) {
  auto tFormat = scanType[typeid(T)];
  for (T& n : v) {
    scanf(tFormat, &n);
  }
}

static void scan(vector<string>& v, bool isWord) {
  if (isWord) {
    for (auto& n : v) {
      cin >> n;
    }
    return;
  }

  int i = 0, size = v.size();
  string s;
  getline(cin, s);

  if (s.size() != 0) {
    i++;
    v[0] = s;
  }

  for (; i < size; ++i) {
    getline(cin, v[i]);
  }
}

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

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

template <class T> inline T gcd(T a, T b) { return __gcd(a, b); }

template <class T> inline T lcm(T a, T b) { return (a * b) / gcd(a, b); }

template <class A, size_t N, class T> void Fill(A (&arr)[N], const T& val) {
  std::fill((T*)arr, (T*)(arr + N), val);
}


Measured memory_bytes: 2168
from heapq import heappop, heappush, heapify

n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)

q = [-a[0]]
ans = 0

for i in range(1, n):
    x = -heappop(q)
    ans += x
    heappush(q, -a[i])
    heappush(q, -a[i])

print(ans)


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

int main() {
	int n;cin>>n;
	vector<int> v(n);
	vector<pair<int,int>> c1(100001),c2(100001);
	for(int i=0;i<100001;i++){
		c1[i]=make_pair(0,i);
		c2[i]=make_pair(0,i);
	}

	for(int i=0;i<n;i++){
		cin>>v[i];
		if(i%2){
			c1[v[i]].first++;
		}else{
			c2[v[i]].first++;
		}
	}
	sort(c1.begin(),c1.end());
	sort(c2.begin(),c2.end());
	int ans;
	if(c1[100000].second!=c2[100000].second){
		ans=n-c1[100000].first-c2[100000].first;
	}else{
		ans=n-c1[100000].first-c2[99999].first;
		int ans2=n-c1[99999].first-c2[100000].first;
		if(ans>ans2)ans=ans2;
	}
	cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 2176
package main

import (
	"fmt"
	"math"
)

var N int

func main() {
	fmt.Scan(&N)
	fmt.Println(N * (N + 1) / 2)
}

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

func lcm(x, y int) int {
	return (x / gcd(x, y)) * y
}

func gcd(x, y int) int {
	if x%y == 0 {
		return y
	} else {
		r := x % y
		return gcd(y, r)
	}
}

func combination(x, y int) int {
	return permutation(x, y) / permutation(y, y)
}

func permutation(x, y int) int {
	var ans int = 1
	for i := x - y; 0 < i; i-- {
		ans *= i
	}
	return ans
}

func max(x ...int) int {
	var res int = x[0]
	for i := 1; i < len(x); i++ {
		res = int(math.Max(float64(x[i]), float64(res)))
	}
	return res
}

func min(x ...int) int {
	var res int = x[0]
	for i := 1; i < len(x); i++ {
		res = int(math.Min(float64(x[i]), float64(res)))
	}
	return res
}
func pow(x, y int) int { return int(math.Pow(float64(x), float64(y))) }
func abs(x int) int    { return int(math.Abs(float64(x))) }
func floor(x int) int  { return int(math.Floor(float64(x))) }
func ceil(x int) int   { return int(math.Ceil(float64(x))) }

type XY struct {
	x int
	y int
}

type SortBy [][]int

func (a SortBy) Len() int      { return len(a) }
func (a SortBy) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a SortBy) Less(i, j int) bool {
	return a[i][1] < a[j][1]
}


Measured memory_bytes: 512
#include<stdio.h>
int main()
{
    int n,k,x,y,i,j,m,t;
    scanf("%d\n%d\n%d\n%d",&n,&k,&x,&y);
    if(n>k){
    i=(n-k);
    j=x*k;
    m=i*y;
    t=j+m;

    printf("%d",t);
    }
    else
        printf("%d",n*x);

    return 0;

}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define REP(i, n) for (int (i) = 0; (i) < (int)(n); i++) 
#define FOR(i, a, b) for(int (i) = a; (i) < (int)b; i++)
#define RREP(i, n) for(int (i)=((int)(n)-1); (i)>=0; i--)
#define RFOR(i, a, b) for(int (i) =((int)(b)-1); (i)>=0; i--)
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define F first
#define S second

using namespace std ;
typedef long long ll;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef pair<int, int> pint;

int main()
{
  int n ;
  cin >> n ;
  vector<int> num(n) ;
  vector<int> sa(n,0) ;
  
  REP(i,n){
    cin >> num.at(i) ;
  }
  
  REP(i,n){
    REP(j,n){
      if(abs(sa.at(i))<abs(num.at(i)-num.at(j))){
        sa.at(i) = abs(num.at(i)-num.at(j)) ;
      }
    }
  }
  
  sort(ALL(sa)) ;
     
  cout << sa.at(n-1) <<endl ;

  return 0 ;
}




Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <utility>
#include <map>
#include <vector>
#include <cstring>
#include <climits>
#include <queue>
#include <cmath>
#include <iomanip>
#include <set>
#include <bitset>

using namespace std;

typedef long long LL;
typedef pair<int, int> pii;

int main() {
	ios::sync_with_stdio(false);
	LL N;
	cin >> N;
	LL tmp = N;
	LL p = 1;
	while (true) {
		if (N > (LL)pow(26LL, p)) {
			N -= (LL)pow(26LL, p);
			p++;
		} else {
			break;
		}
	}
	N--;
	string ans = "";
	for (LL i = p; i >= 1; i--) {
		LL cur = (LL)pow(26LL, i - 1);
		int num = N / cur;
		ans += (char)('a' + num);
		N -= (num) * cur;
	}
	cout << ans << endl;
}

Measured memory_bytes: 4060
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

using namespace std;
typedef long long int ll;

int main()
{
	string str;
	cin >> str;
	bool ans = true;
	for (int i = 1; i <= str.size(); i++) {
		if (i % 2 == 0 && str[i - 1] == 'R') {
			ans = false;
		}
		if (i % 2 == 1 && str[i - 1] == 'L') {
			ans = false;
		}
	}
	if (ans == true) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}

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

const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

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

int main(){
    int n;
    cin >> n;
    vi h(n+5);
    rep(i, n) cin >> h[i];
    vi dp(n+5, INF);
    dp[0] = 0;
    rep(i, n) {
        dp[i+1] = min(dp[i+1], dp[i]+abs(h[i]-h[i+1]));
        dp[i+2] = min(dp[i+2], dp[i]+abs(h[i]-h[i+2]));
    }
    cout << dp[n-1] << endl;
    return 0;
}


Measured memory_bytes: 4008
N, M=map(int, input().split())
a=[0]*(M+1)

for i in range(N):
  temp=list(map(int, input().split()))
  k=len(temp)
  for j in range(1, k):
    a[temp[j]]+=1
    
counter=0
for i in range(1, M+1):
  if a[i]==N:
    counter+=1
    
print(counter)

Measured memory_bytes: 3064
h,w=map(int,input().split())
a=[list(input()) for i in range(h)]
dx=((0,1),(0,-1),(1,0),(-1,0))
flag=True
for i in range(h):
    for j in range(w):
        cnt=0
        if a[i][j]=="#":
            for y,x in dx:
                if 0<=i+y<=h-1 and 0<=j+x<=w-1 and a[i+y][j+x]=="#":
                    cnt+=1
            if cnt==0:
                flag=False
print("Yes" if flag else "No")

Measured memory_bytes: 3064
#include <stdio.h>
#include <iostream>

int main(void)
{
  int a[3];
  for (int i = 0; i < 3; ++i)
  {
    scanf("%d", &a[i]);
  }
  int sum = a[0] + a[1] + a[2];

  int max = a[0];
  a[1] > max ? max = a[1] : max = max;
  a[2] > max ? max = a[2] : max = max;
  printf("%d", sum - max);

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
const int MOD = 1e9 + 7;
const int INF = 2e9;
#define pb push_back
#define mp make_pair
#define mt make_tuple
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(){
    int a, b, c;
    cin >> a >> b >> c;
    if(a%2==1 || b%2==1 || c%2==1){
        cout << 0 << endl;
        return 0;
    }
    if(a==b && a==c){
        cout << -1 << endl;
        return 0;
    }
    int ans = 0;
    while(a%2==0 && b%2==0 && c%2==0){
        ans++;
        int tmpa, tmpb, tmpc;
        tmpa = b / 2 + c / 2;
        tmpb = c / 2 + a / 2;
        tmpc = a / 2 + b / 2;
        a = tmpa;
        b = tmpb;
        c = tmpc;
    }
    cout << ans << endl;
}

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

int main() {
	int n, a, b, c, x;
	while (cin >> n >> a >> b >> c >> x, n) {
		int time = 0;
		for (int i = 0; i < n; ++i) {
			int y; cin >> y;
			while (time <= 10001 && x != y) {
				x = (a*x + b) % c; time++;
			}
			x = (a*x + b) % c; time++;
		}
		if (time-1 > 10000)cout << "-1" << endl;
		else cout << time-1 << endl;
	}
}

Measured memory_bytes: 2940
// Math = ♥️

#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 ll long long
#define ld long double
typedef pair<ll, ll> ii;
typedef vector<ll> vi;
typedef vector<bool> vb;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<vii> vvii;
#define pq priority_queue
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(), (c).end()
#define sz(c) ((ll)c.size())
// #define ordered_set                            \
//     tree<ll, null_type, less<ll>, rb_tree_tag, \
//          tree_order_statistics_node_update>

int main(void) {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll a;
    cin >> a;
    cout << (a) + (a * a) + (a * a * a) << "\n";
}


Measured memory_bytes: 3608
#include<bits/stdc++.h>
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define pb push_back
#define MOD 1000000007
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define FOR(a,n) for(int i=a;i<n;++i)
#define arrin(n) for(int i=0; i < n; ++i) cin>>arr[i];
#define arrout(n) for(int i=0; i < n; ++i) cout<<arr[i]<<" ";cout<<nl;
#define nl "\n"
#define mp make_pair
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
using namespace std;

int arr[100][100];

int main(){  
	fastio();
  int n,m;
  cin>>n>>m;
  string inp[n];
  for(int i=0;i<n;i++){
    cin>>inp[i];
    for(int j=0;j<m;j++){
      if(inp[i][j]=='#'){
        arr[i][j]+=1;
        arr[i][j+1]+=1;
        arr[i][j+2]+=1;
        arr[i+1][j]+=1;
        arr[i+1][j+1]+=1;
        arr[i+1][j+2]+=1;
        arr[i+2][j]+=1;
        arr[i+2][j+1]+=1;
        arr[i+2][j+2]+=1;
      }
    }
  }
   for(int i=0;i<n;i++){
    for(int j=0;j<m;j++){
      if(inp[i][j]=='#'){
        cout<<'#';
      }
      else cout<<arr[i+1][j+1];
    }
    cout<<nl;
  }


  return 0;
}	



  

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

using namespace std;

//----------------------- Print Function ----------------------//

inline void print() {
    cout << endl;
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest) {
    cout << first << ' ';
    print(rest...);
}

//------------------------- Libraries -------------------------//

//--------------------------- Solve ---------------------------//

void solve() {
    long long N, M; cin >> N >> M;
    long long ans;
    if (N == 1 && M == 1) ans = 1;
    else if (N == 1) ans = M - 2;
    else if (M == 1) ans = N - 2;
    else ans = (N-2) * (M-2);
    cout << ans << '\n';
}

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

    solve();

    return 0;
}

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

int main() {
	int N, M;
	cin >> N >> M;
	vector<int> A(M);
	rep(i, M) cin >> A.at(i);

	int sum = 0;
	rep(i, M) sum += A.at(i);

	if(N >= sum)
		cout << N - sum << endl;
	else
		cout << -1 << endl;


	return 0;
}

Measured memory_bytes: 3640
#include<cstdio>
#include<cstring>
inline int geti()
{
	int x,f=1;char c;
	while((c=getchar())<'0'||c>'9') if(c=='-') f=-1;
	x=c-'0';
	while((c=getchar())>='0'&&c<='9') x=x*10+c-'0';
	return x*f;
}

const int NN=100000,NK=1000;
int x[NN+5],y[NN+5],y1[3*NK+5],n,k,cnt,Max;
bool c[NN+5];
char op;

int main()
{
	n=geti();k=geti();
	for(int i=1;i<=n;i++)
	{
		x[i]=geti()%(2*k);
		y[i]=geti()%(2*k);
		scanf("%c",&op);
		c[i]=(op=='W');
	}
	for(int i=0;i<=k;i++)
	{
		cnt=0;
		memset(y1,0,sizeof(y1));
		for(int j=1;j<=n;j++)
		{
			int q=(x[j]>=i&&x[j]<i+k),
			p=(y[j]>=0&&y[j]<k);
			if(q^p==c[j])
			{
				cnt++;
				y1[y[j]]++;
			}
			else
				y1[y[j]]--;
		}
		for(int j=0;j<=k;j++)
		{
			if(cnt>Max) Max=cnt;
			if(n-cnt>Max) Max=n-cnt;
			if(j!=k)
				cnt=cnt-y1[j]-y1[k+j];
		}
	}
	printf("%d\n",Max);
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
signed main(){
    int n;
    cin>>n;
    long long a[n+2],sum=0;
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    for(int i=1;i<n;i++){
        if(a[i]>a[i+1]){
            sum+=a[i]-a[i+1];
            a[i+1]=a[i];
        }
    }
    cout<<sum<<"\n";
    return(0);
}

Measured memory_bytes: 5180
import java.io.*;

public class Main {
    public static void main(String[] args)throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String num = br.readLine();
        String[] cou = num.split(" ",0);

        int[] out = new int[3];

        for(int i = 0; i < cou.length; i++){
            out[i] = Integer.parseInt(cou[i]);
        }

        String j;
        if(out[0]+out[1] == out[2]){
            j = "Yes";
        }else if(out[0]+out[2] == out[1]){
            j = "Yes";
        }else if(out[1]+out[2] == out[0]){
            j = "Yes";
        }else{
            j = "No";
        }

        System.out.println(j);
    }
}


Measured memory_bytes: 23124
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
using namespace std;

int main() {
    int n, tp = 0, hp = 0;
    cin >> n;
    REP(i, n) {
        string t, h;
        cin >> t >> h;
        if (t == h) {tp++; hp++;}
        else if (t > h) tp += 3;
        else hp += 3;}
    cout << tp << " " << hp << endl;
}

Measured memory_bytes: 3164
S = input()

a = int(S[0:4])
b = int(S[5:7])
c = int(S[8:10])

if a < 2019:
    print("Heisei")
elif a == 2019:
    if b <= 4:
        print("Heisei")
    else:
        print("TBD")
else:
    print("TBD")

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

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define rep(i, n) repd(i, 0, n)

using namespace std;

using ll = long long;
using ul = unsigned long long;
using ld = long double;
ll mod = 1000000007;

int main() {
    ll a;
    cin >> a;
    cout << a + a * a + a * a * a << endl;
    return 0;
}



Measured memory_bytes: 3608
#![allow(unused_imports)]
#![allow(dead_code)]

use proconio::input;
use std::collections::*;

fn main() {
    input! {
        n:usize,
        a:[i128;n],
    }
    let mut ans = 1;
    let max: i128 = 1000000000000000000;
    for i in 0..n {
        if a[i] == 0 {
            println!("{}", 0);
            return;
        }
    }
    for i in 0..n {
        ans *= a[i];
        if ans > max {
            ans = -1;
            break;
        }
    }
    println!("{}", ans);
}

Measured memory_bytes: 5360
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		int k = Integer.parseInt(sc.next());
		int max = 0;
		int gcd = 0;
		for (int i = 0; i < n; i++) {
			int a = Integer.parseInt(sc.next());
			max = Math.max(max, a);
			gcd = gcd(gcd, a);
		}
		if (k <= max && k % gcd == 0)
			System.out.println("POSSIBLE");
		else
			System.out.println("IMPOSSIBLE");
	}
	static int gcd(int a, int b) {
		if(b == 0) return a;
		return gcd(b, a%b);
	}
}

Measured memory_bytes: 47012
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VRSORT(v) sort(v.rbegin(), v.rend());//vectorの降順ソート
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

int n;

bool isfind(string s, string pat){
    if(s.find(pat) != string::npos) return true;
    else return false;
}

int dfs(int i, string s){
  if(i==10){
    if(isfind(s,"3") && isfind(s,"5") && isfind(s,"7") && stoll(s) <= n) return 1;
    else return 0;
  }
  
  int ans = 0;
  
  if(s.back() == '0') ans+= dfs(i+1,s+"0");
  
  ans += dfs(i+1,s+"3");
  ans += dfs(i+1,s+"5");
  ans += dfs(i+1,s+"7");
  
  return ans;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n;
  cout << dfs(0,"0") << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdlib.h>
#include <algorithm>

using namespace std;

int main(int argc, char **argv)
{
	int *array, tmp;
	
	for(int i = 0; i < 2; i++){
		array = (int *)calloc(3, sizeof(int));
		if(i == 1){
			cout << " ";
		}
		for(int j = 0; j < 10; j++){
			cin >> tmp;
			if(array[0] < tmp){
				array[0] = tmp;
				sort(array, array+3);
			}
		}
		cout << (array[0]+array[1]+array[2]);
	}
	cout << endl;
	
	return 0;
}

Measured memory_bytes: 0
N = int(input())
V = [int(i) for i in input().split()] 
C = [int(i) for i in input().split()] 

ans = []

for i in range(1<<N):
    X = 0
    Y = 0
    for j in range(N):
        if ((i >> j) & 1) == 1:
            X += V[j]
            Y += C[j]
    ans.append(X-Y)

print(max(ans))

Measured memory_bytes: 114396
nums = list(map(int, input().split()))
n = nums[0]
k = nums[1]

def absolute(n,k):
    return abs(n-k)

x = absolute(n, k)
if n % k == 0:
    print(0)
elif n < x:
    print(n)
else:
    while absolute(x, k) < x:
        x = x % k
        x = absolute(x, k)

    print(x)



Measured memory_bytes: 3060
#include <iostream>
using namespace std;
int DP[3001][3001];
int toS[3001];
int fun[3001],tim[3001];
int main() {
	int N,T,S;
	cin >> N >> T >>S;
	int NB=T-S;
	for(int i=1;i<=N;i++){
	cin >> fun[i] >> tim[i];
		for(int j=0;j<=S;j++){
			if(j-tim[i]>=0)
		DP[i][j]=DP[i-1][j-tim[i]]+fun[i];
		DP[i][j]=max(DP[i-1][j],DP[i][j]);
		}
		
	}
	for(int i=1;i<=N;i++)
	toS[i]=DP[i][S];
	for(int i=0;i<=3000;i++)
		for(int j=0;j<=3000;j++)
			DP[i][j]=0;
	for(int i=1;i<=N;i++){
		for(int j=0;j<=NB;j++){
			if(j-tim[N-i+1]>=0)
		DP[i][j]=DP[i-1][j-tim[N-i+1]]+fun[N-i+1];
		DP[i][j]=max(DP[i-1][j],DP[i][j]);
		}
	}
	int	maxer=0;
	for(int i=0;i<=N;i++)
	maxer=max(maxer,toS[i]+DP[N-i][NB]);
	
	cout << maxer << endl;
	
	return 0;
}

Measured memory_bytes: 36380
#include<bits/stdc++.h>
using namespace std;
const int N=1E5+7;
typedef long long ll;
const ll mod=998244353;
ll arr[N];
ll ksm(ll x,ll y){
    ll res=1;
    while(y){
        if(y&1)res=res*x%mod;
        x=x*x%mod;
        y>>=1;
    }
    return res%mod;
}

int main()
{
    ll n;
    cin>>n;
    ll x,s=0;
    ll  sum=1;
    for(ll i=1;i<=n;i++){
        cin>>x;
        if(i==1&&x!=0) sum=0;
        arr[x]++;
        s=max(s,x);
    }
    for(ll i=s;i>=0;i--){
        if(arr[i]==0){
            sum=0;
        }
        if(i>1) {
            sum=sum*ksm(arr[i-1],arr[i])%mod;
        }
    }
    if(arr[0]!=1) sum=0;
    cout<<sum%mod<<endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
typedef vector<int> vi;
typedef vector<double> vd;
 
double mypow(double b ,int e){
      if(e == 0) return 1;
      if(e%2==0)
            return mypow( b*b, e/2 );
      else
            return mypow( b*b, e/2 ) * b;
}
 
int main(){
 
 
      int N,M,L; cin >> N >> M >> L ;
      if(N==1){
            cout << 1.0 << endl;
            return 0;
      }
      vector<vd> prob(N,vd(M+1,0.0));
      vector<vd> dist(N,vd(M+1,0.0));
 
      vd p(N),t(N),v(N);
      for(int i=0; i<N; i++) cin >> p[i] >> t[i] >> v[i];
 
      // PRE PROCESS
      for(int i=0; i<N; i++){
            dist[i][0] = (double)L / v[i];
            for(int j=1; j<=M; j++){
                  dist[i][j] = dist[i][j-1] + t[i];
            }
      }
      for(int i=0; i<N; i++)
            prob[i][0] = mypow((100-p[i])/100,M);
      for(int i=0; i<N; i++){
            for(int j=1; j<=M; j++){
                  if(p[i] != 100)
                        prob[i][j] = (prob[i][j-1] * (p[i]/100)) / ((100-p[i])/100);
                  else
                        prob[i][j] = 1.0;
            }
      }
      double comb = 1;
      for(int j=1; j<=M; j++){
            comb = comb * (M - j + 1) / j; 
            for(int i=0; i<N; i++){
                  prob[i][j] *= comb;
            }
      }
       
      vector<vd> sum = prob;
      for(int i=0; i<N; i++){
            for(int j=M-1; j>=0; j--){
                  sum[i][j] += sum[i][j+1];
                  if(sum[i][j] > 1) sum[i][j] = 1;
            }
      }
 
      vector<vd> ans = prob;
      for(int i=0; i<N; i++){
            for(int j=0; j<=M; j++){
                  for(int k=0; k<N; k++){
                        if(i==k) continue;
                        int id = upper_bound(dist[k].begin(),dist[k].end(), dist[i][j]) - dist[k].begin();
                        if(id > M) ans[i][j] = 0.0;
                        else       ans[i][j] *= sum[k][id];
 
                  }
            }
      }
 
      for(int i=0; i<N; i++){
            double tmp = 0.0;
            if(p[i] == 100) tmp = ans[i][M];
            else
                  for(int j=0; j<=M; j++)
                        tmp += ans[i][j];
            if(tmp > 1) tmp = 0;
            printf("%.10f\n",tmp);
      }
                         
}

Measured memory_bytes: 3440
#include<stdio.h>
int S[100000];
int ct = 0;
int main() {
	int T[50000];
	int n, q,i;

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

	scanf("%d", &q);
	for (i = 0; i < q; i++) {
		scanf("%d", &T[i]);
	}
	for (i = 0; i < q; i++) {
		binarySearch(T[i],n);
	}
	printf("%d\n", ct);

	return 0;
}

int binarySearch(key, n) {
	int left,right,mid;
	
	left = 0;
	right = n;
	while (left < right) {
		mid = (left + right) / 2;
		if (key == S[mid]) {
			ct++;
			return mid;
		}
		if (key > S[mid]) {
			left = mid + 1;
		}
		else if (key < S[mid]) {
			right = mid;
		}
	}
	return NULL;
}


Measured memory_bytes: 2284
#include <iostream>  
#include <stdio.h>  
#include <stdlib.h>  
#include<string.h>  
#include<algorithm>  
#include<math.h>  
#include<queue>  
using namespace std;  
typedef long long ll;  
const int maxn=10010,INF=99999999;  
int ip,n,m,head[maxn],dis[maxn],jl[maxn];  
bool vis[maxn];  
struct data  
{  
    int next,to,d,w;  
} tu[maxn*maxn];  
  
void init()  
{  
    ip=0;  
    memset(head,-1,sizeof(head));  
}  
  
void add(int a,int b,int d,int w)  
{  
    tu[ip].to=b,tu[ip].d=d,tu[ip].w=w,tu[ip].next=head[a],head[a]=ip++;  
}  
  
void spfa()  
{  
    for(int i=1; i<=n; i++)  
        dis[i]=jl[i]=INF;  
    dis[1]=0;  
    jl[1]=0;  
    memset(vis,0,sizeof(vis));  
    queue<int>q;  
    q.push(1);  
    while(!q.empty())  
    {  
        int t=q.front();  
        q.pop();  
        vis[t]=0;  
        for(int k=head[t]; k!=-1; k=tu[k].next)  
        {  
            int d=tu[k].d,v=tu[k].to,w=tu[k].w;  
            if(dis[t]+d<dis[v])  
            {  
                jl[v]=w;///??最小花?  
                dis[v]=dis[t]+d;  
                if(!vis[v])  
                {  
                    vis[v]=1;  
                    q.push(v);  
                }  
            }  
            else if(dis[t]+d==dis[v]&&w<jl[v])///??最小花?  
                jl[v]=w;  
        }  
    }  
    int ans=0;  
    for(int i=1; i<=n; i++)  
        ans+=jl[i];  
    printf("%d\n",ans);  
}  
  
  
int main()  
{  
    while(~scanf("%d%d",&n,&m)&&m+n)  
    {  
        init();  
        while(m--)  
        {  
            int a,b,d,w;  
            scanf("%d%d%d%d",&a,&b,&d,&w);  
            add(a,b,d,w);  
            add(b,a,d,w);  
        }  
        spfa();  
    }  
    return 0;  
}

Measured memory_bytes: 4032
import java.io.*;
public class Main{
  public static void main(String[] args){
    try{
      BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
      char[] N = bf.readLine().toCharArray();
      boolean flag = N[1] == N[2] && (N[0] == N[1] || N[3] == N[1]);
      System.out.println(flag ? "Yes" : "No");
    } catch(IOException e){}
  }
}
    

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

int main()
{
    int X , Y, Z;
    cin >> X >> Y >> Z;
    int ans;
    for (int i = 0;; i++)
    {
        if( Y*i+Z*(i+1) > X){
            ans = i - 1;
            break;
        }
    }
    cout << ans << endl;

    return 0;
}

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

using namespace std;

int main() {
    int h, w, n, x, y;
    scanf("%d %d %d\n%d %d", &h, &w, &n, &x, &y);
    char s[n+1], t[n+1];
    scanf("\n%s\n%s", s, t);
    int limits[] = {0, 0, 0, 0}; //limitsは危険区域
    char taka[] = "LRUD", ao[] = "RLDU";
    for (int i=n-1; i>=0; i--) {
        for (int j=0; j<4; j++)
            if (s[i] == taka[j])
                limits[j] += 1;
        if (limits[0] + limits[1] >= w || limits[2] + limits[3] >= h) {
            printf("NO\n");
            return 0;
        }
        if (i > 0) 
            for (int j=0; j<4; j++)
                if (t[i-1] == ao[j] && limits[j] > 0)
                    limits[j] -= 1;
    }
    if (limits[0] < y && y < w - limits[1] + 1 && limits[2] < x && x < h - limits[3] + 1)
        printf("YES\n");
    else
        printf("NO\n");
    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;

int main() {
    int n, ma, mb;
    cin >> n >> ma >> mb;
    vector<vector<int>> v1(401, vector<int>(401, 0x3f3f3f3f));
    vector<vector<int>> v2(401, vector<int>(401, 0x3f3f3f3f));
    v1[0][0] = 0;
    for (int i = 0; i < n; i++) {
        int a, b, c;
        cin >> a >> b >> c;
        v2 = v1;
        for (int x = 0; x + a <= 400; x++) {
            for (int y = 0; y + b <= 400; y++) {
                v2[x + a][y + b] = min(v2[x + a][y + b], v1[x][y] + c);
            }
        }
        v1 = v2;
    }
    int res = 0x3f3f3f3f;
    for (int i = 1; i * ma <= 400 && i * mb <= 400; i++) {
        res = min(res, v1[i * ma][i * mb]);
    }
    cout << (res == 0x3f3f3f3f ? -1 : res) << endl;
}


Measured memory_bytes: 4920
import java.util.Arrays;
import java.util.Scanner;

fun main (args : Array<String>) {
  val input = Scanner(System.`in`)
  
  while (input.hasNext()) {
    val N = input.nextInt()
    val L = IntArray(N)
    
    for (i in L.indices) {
      L[i] = input.nextInt()
    }
    
    Arrays.sort(L)
    
    var count = 0
    for (i in 0..L.lastIndex) {
      for (j in (i + 1)..L.lastIndex) {
        for (k in (j + 1)..L.lastIndex) {
          if (L[i] != L[j] && L[j] != L[k]) {
            if (L[i] + L[j] > L[k] && L[j] - L[i] < L[k]) {
              ++count
            }
          }
        }
      }
    }
    
    println(count)
  }
}

Measured memory_bytes: 40668
#include <bits/stdc++.h>
#include <stdio.h>
#include <math.h>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
#define rep(i, n) for(int i=0;i<n;i++)

int main(){
 string s;
  cin >>s;
  int num=s.size();
  int c=s.at(0)-48;
  bool a=true;
  for(int i=1;i<num;i++){
    if(s.at(i)!='9') a=false;
  }
  if(a) cout << c+9*(num-1) <<endl;
  else cout << c-1+9*(num-1) <<endl;
    
  
}
  

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

int main() {
  int n, a, b; cin >> n >> a >> b;
  string s; cin >> s;
  int cntA = 0, cntB = 0;
  for(int i = 0; i < n;i++){
    if(s.at(i) == 'a' && cntA+cntB <a+b){
      cout << "Yes" << endl;
      cntA++;
    }
    else if(s.at(i) =='b' && cntA+cntB <a+b &&
            cntB<b){
      cout << "Yes" << endl;
      cntB++;
    }
    else{
      cout << "No" << endl;
    }
  }
  
}


Measured memory_bytes: 3720
a = []
b = []
c = []

i = 0
j = 0
k = 0

a = input()
b = input()
c = input()

check = 'a'

while i < 101:
    if   check == 'a':
         if  len(a) <= i:
             print('A')
             break
         check = a[i]
         i = i + 1
    elif check == 'b':
         if  len(b) <= j:
             print('B')
             break
         check = b[j]
         j = j + 1
    elif check == 'c':
         if  len(c) <= k:
             print('C')
             break
         check = c[k]
         k = k + 1
    else:
         break

Measured memory_bytes: 3064
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define EPS (1e-9)
#define INF (1e17)
#define PI (acos(-1))
//const double PI = acos(-1);
//const double EPS = 1e-15;
//long long INF=(long long)1E17;
#define i_7 (long long)(1e9+7)
//#define i_7 998'244'353
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
long long po(long a, long b){
    if(b==0){
        return 1;
    }
    
    long long z = po(a,b/2);
    z = mod(z*z);
    if(b%2!=0){
        z = mod(a*z);
    }
    return z;
}
 
bool prime_(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=std::sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}
 
long long gcd_(long long a, long long b){
  if(a<b){
    std::swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd_(b,a%b);
  }
}
 
long long lcm_(long long x, long long y){
  return (x/gcd_(x,y))*y;
}
 
//using namespace std;
//using namespace boost::multiprecision;
//using namespace __gnu_pbds;

int main(){
  using namespace std;
  int n;
  cin>>n;
  long long a[n];
  long long s = 0;
  long long cnt[100010] = {};
  REP(i, n) cin>>a[i];
  REP(i, n) s += a[i];
  REP(i, n) cnt[a[i]] += 1;
  int q;
  cin>>q;
  REP(_, q){
    long long b, c;
    cin>>b>>c;
    long long temp = cnt[b];
    s += c * temp;
    s -= b * temp;
    cnt[c] += temp;
    cnt[b] -= temp;
    cout << s << endl;
  }
  return 0;
}


Measured memory_bytes: 5084
#include<bits/stdc++.h>
using namespace std;
typedef complex<double> P;
double eps=1e-6;
double PI=acos(-1);
 
P getCrossPoint(P a,P b,P c,P d){
  a-=d;b-=d;c-=d;
  return d+a+(b-a)*imag(a/c)/imag(a/c-b/c);
}
 
bool isParallel(P a,P b,P c,P d){
  return (abs(imag( (b-a)*conj(d-c) ) )<eps);
}
 
int lcm(int a,int b){
  return a/ __gcd(a,b) * b;
}
 
int n;
 
int main(){
  while(1){
    cin>>n;
    if(n==0)break;
     
    double R=1.0/sqrt(3.0);
    P a=P(R,0);
    P b=P(R-0.5*sqrt(3.0),0.5);
     
    double lc=lcm(n,3);
    double ti=2.0*PI/lc;
 
    P c=a,d=b;
 
    if(lc==3){
      printf("0.433013\n");
      continue;
    }
     
    double T=1e9;
    for(int i=1;i<=lc/3;i++){
      c=a*P(cos(ti*i),sin(ti*i));
      d=b*P(cos(ti*i),sin(ti*i));
      if(!isParallel(a,b,c,d)){
        P target=getCrossPoint(a,b,c,d);
        double k=min(abs(target-a),abs(target-b));
        if(k>eps)T=min(T,k);
      }

      //      if(i==2)i=lc/3-2;
    }
    double ans=T*R*0.5;
    printf("%.8f\n",ans*lc);
  }
}

Measured memory_bytes: 1212
from time import time
import random


def main():
    random.seed(0)

    now = time()

    MAX = 26

    d = int(input())
    c = list(map(int, input().split()))
    s = [list(map(int, input().split())) for _ in range(d)]
    t = []
    for row in s:
        mxi = 1
        mx = 0
        for i, e in enumerate(row, 1):
            if e > mx:
                mx = e
                mxi = i

        t.append(mxi)

    last = [0] * MAX

    score = 0
    for day, e in enumerate(t, 1):
        score += s[day-1][e-1]
        last[e-1] = day

        for ec, elast in zip(c, last):
            score -= ec * (day - elast)

    d_li = []
    for i in range(1, d + 1):
        ln = (-(i - d // 2) ** 2 + d ** 2 // 4) // 500
        d_li += [i] * ln

    di_max = len(d_li) - 1

    c_sum = sum(c)
    c_li = []
    for i, e in enumerate(c, 1):
        c_li += [i] * e

    while time() - now <= 1.85:
        prev_score = score

        di = random.randint(0, di_max)
        ed = d_li[di]
        qi = random.randint(0, c_sum - 1)
        eq = c_li[qi]

        q_old = t[ed-1]
        d_prev = {q_old: 0, eq: 0}

        c_old = c[q_old-1]
        c_new = c[eq-1]

        for day, e in enumerate(t, 1):
            if e in d_prev.keys():
                d_prev[e] = day

            score += c_old * (day - d_prev[q_old])
            score += c_new * (day - d_prev[eq])

        score -= s[ed-1][q_old-1]
        score += s[ed-1][eq-1]

        t[ed-1] = eq

        d_prev = {q_old: 0, eq: 0}

        for day, e in enumerate(t, 1):
            if e in d_prev.keys():
                d_prev[e] = day

            score -= c_old * (day - d_prev[q_old])
            score -= c_new * (day - d_prev[eq])

        if prev_score > score:
            t[ed-1] = q_old
            score = prev_score

    print(*t, sep="\n")


if __name__ == "__main__":
    main()


Measured memory_bytes: 80940
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod 1000000007
#define MAX 100000
void inarray(int a[], int n){
    for(int i = 0; i < n; i++) cin >> a[i];
}

int main(){
    int k,n; cin >> k >> n;
    int a[n]; inarray(a,n);
    int ma = k-a[n-1]+a[0];
    for(int i = 1; i < n; i++){
        ma = max(a[i]-a[i-1], ma);
    }
    cout << k - ma << endl;
    return 0;
}

Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AOJ
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                int n = int.Parse(Console.ReadLine());
                if (n == 0)
                    break;

                int[] numArr = Console.ReadLine().Split().Select(e => int.Parse(e)).ToArray();

                Solve(numArr);
            }
        }

        static void Solve(int[] arr)
        {
            int result = 0;

            Dictionary<int, int> counter = new Dictionary<int, int>();
            while (true)
            {
                foreach (int n in arr)
                {
                    if (counter.ContainsKey(n))
                    {
                        counter[n]++;
                    }
                    else
                    {
                        counter[n] = 1;
                    }
                }

                if (counter.All(e => e.Key == e.Value))
                    break;

                for (int i = 0; i < arr.Count(); i++)
                {
                    arr[i] = counter[arr[i]];
                }

                result++;
                counter.Clear();
            }

            Console.WriteLine(result);

            for (int i = 0; i < arr.Count(); i++)
            {
                Console.Write(arr[i]);

                if (i != arr.Count() - 1)
                    Console.Write(" ");
            }

            Console.WriteLine();
        }
    }
}

Measured memory_bytes: 6548