akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
	ll n; cin >> n;
	string s; cin >> s;
	ll q; cin >> q;
	vector<ll> ks(q);
	for (int i = 0; i < q; ++i) cin >> ks[i];
	for (auto k : ks) {
		ll ans = 0;
		ll d = 0;
		ll m = 0;
		ll cnt = 0;
		for (int i = 0; i < n; ++i)
		{
			if (i >= k) {
				if (s[i-k] == 'D') {
					cnt -= m;
					d--;
				}
				else if (s[i-k] == 'M') {
					m--;
				}
			}

			if (s[i] == 'D') d++;
			else if (s[i] == 'M') {
				m++;
				cnt += d;
			}
			else if (s[i] == 'C') ans += cnt;
		}

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

Measured memory_bytes: 1412
#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>
#include <algorithm>
#include <map>
#include <tuple>
using namespace std;

typedef long long ll;

const ll lim = 50;

vector<vector<bool> > g(lim,vector<bool> (lim,false));
vector<ll> a(lim);
vector<ll> b(lim);
vector<bool> al(lim);
ll N;

void dfs(ll v){
    al[v] = true;
    for(ll v2 = 0;v2 < N;v2++){
        if(al[v2] == true || g[v][v2] == false){
            continue;
        }
        dfs(v2);
    }
}

int main(void){
    ll M;
    cin >> N >> M;
    for(ll i = 0;i < M;i++){
        cin >> a[i] >> b[i];
        a[i]--,b[i]--;
        g[a[i]][b[i]] = g[b[i]][a[i]] = true;
    }

    ll ans = 0;
    for(ll i = 0;i < M;i++){
        g[a[i]][b[i]] = g[b[i]][a[i]] = false;
        // 未訪問にする
        for(ll j = 0;j < N;j++){
            al[j] = false;
        }
        dfs(0);
        bool bri = false;
        for(ll j = 0;j < N; j++){
            if(al[j] == false){
                bri = true;
            }
        }
        if(bri){
            ans++;
        }
        g[a[i]][b[i]] = g[b[i]][a[i]] = true;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
function Main(input){
  var inputArray = input.split(' ');
  var N = Number(inputArray[0]);  //作りたい個数
  var X = Number(inputArray[1]);   //1回で作れる最大数
  var T = Number(inputArray[2]);  //1回にかかる時間
  console.log(Math.ceil(N/X)*T);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8").trim());

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

#define _GLIBCXX_DEBUG

//vector<int> A(M), B(M);
//vector<vector<char>> answer(N, vector<char>(N, '-'));

int main() {
  int n, r, ans;
  
  cin >> n >> r;
  
  ans = r;
  if(n < 10)
    ans += 100*(10-n);
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 256
#入力の高速化
import sys
input = sys.stdin.readline

# ユニオンファインド
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


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

UF=UnionFind(n)

for a,b in g:
    a-=1
    b-=1
    UF.union(a,b)

ans=UF.group_count()-1
print(ans)


Measured memory_bytes: 90340
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
#define rep(i,n) for (int i=0; i<(int)(n); ++i)
#define rep0(i,n) for (int i=0; i<=(int)(n); ++i)
#define rep1(i,n) for (int i=1; i<=(int)(n); ++i)
#define rrep(i,n) for (int i=(int)(n)-1; i>=0; --i)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using Graph = vector<vi>;
using llGraph = vector<vl>;
using vb = vector<bool>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int MOD = 1e9+7;
const int MOD2 = 998244353;
const double EPS = 1e-9;

template<typename T>
struct is_vector : false_type{};

template<typename T>
struct is_vector<vector<T>> : true_type{};

template<typename T>
ostream &operator << (ostream &ostr, const vector<T> &vec) {
  if (vec.empty()) {
    return ostr;
  }
  ostr << vec.front();
  for (auto itr = ++vec.begin(); itr != vec.end(); ++itr) {
    if (is_vector<T>()) ostr << "\n" << *itr;
    else ostr << ' ' << *itr;
  }
  return ostr;
}

template<typename T>
bool CompareBySecond(pair<T, T> a, pair<T, T> b) {
  if (a.second != b.second) {
    return a.second < b.second;
  } else {
    return a.first < b.first;
  }
}

template<typename T>
T GCD(T a, T b) {
  T c = a % b;
  while (c != 0) { a = b; b = c; c = a % b; }
  return b;
}


/* -------- <templates end> -------- */


void solve() {
  int n; cin >> n;
  llGraph G(n, vl(3));
  rep(i,n) rep1(j,2) cin >> G[i][j];
  rep(i,n) G[i][0] = G[i][1] + G[i][2];
  sort(RALL(G));
  ll ans = 0;
  rep(i,n) {
    if (i%2 == 0) ans += G[i][1];
    else ans -= G[i][2];
  }
  cout << ans << endl;
}


/* -------- <programs end> -------- */


int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(12);
  solve();
  return 0;
}


Measured memory_bytes: 5760
#include <bits/stdc++.h>
#define rep(i, n) for (ll(i) = 0; (i) < (n); (i)++)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
const ll INF = 99999999999999;
const ll MOD = 1000000007;
ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
using namespace std;
template <class T>
bool contain(const std::string &s, const T &v)
{
    // contain(to_string(N), '3')
    return s.find(v) != std::string::npos;
}

int main()
{
    int n, m;
    cin >> n >> m;
    vector<tuple<int, int, int>> a;
    vector<string> ans(m);
    rep(i, m)
    {
        int p, y;
        cin >> p >> y;
        a.emplace_back(p, y, i);
    }
    sort(all(a));
    int p = get<0>(a[0]);
    int num = 1;
    rep(i, m)
    {
        string s = "";
        rep(j, 6 - to_string(get<0>(a[i])).size())
        {
            s += "0";
        }
        s += to_string(get<0>(a[i]));

        if (get<0>(a[i]) == p)
        {
            rep(j, 6 - to_string(num).size())
            {
                s += "0";
            }
            s += to_string(num);
            num++;
        }
        else
        {
            p = get<0>(a[i]);
            num = 1;
            rep(j, 6 - to_string(num).size())
            {
                s += "0";
            }
            s += to_string(num);
            num++;
        }
        ans[get<2>(a[i])] = s;
    }
    rep(i, m) cout << ans[i] << endl;
    return 0;
}

Measured memory_bytes: 9716
#include<stdio.h>

#define INFTY (1<<21)
#define MAX 100
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n, M[MAX][MAX];

int dijkstra(){
  int u, minv;
  int d[MAX], color[MAX];

  for(int i = 0; i < n; i++){
    d[i] = INFTY;
    color[i] = WHITE;
  }

  d[0] = 0;
  color[0] = GRAY;
  while(1){
    minv = INFTY;
    int u = -1;
    for(int i = 0; i < n; i++){
      if(minv > d[i] && color[i] != BLACK){
	u = i;
	minv = d[i];
      }
    }
    if(u == -1)break;
    color[u] = BLACK;
    for(int v = 0; v < n; v++){
       if(color[v] != BLACK && M[u][v] != INFTY){
	 if (d[v] > d[u] + M[u][v]){
	   d[v] = d[u] + M[u][v];
	   color[v] = GRAY;
	 }
       }
    }
  }
  for(int i = 0; i < n; i++){
    printf("%d %d\n",i,(d[i] == INFTY ? -1 : d[i]));
  }
}

int main(){
  
  scanf("%d",&n);
  for(int i = 0; i < n; i++){
    for(int j = 0; j < n; j++){
      M[i][j] = INFTY;
    }
  }

  int k, c, u, v;
  for(int i = 0; i < n; i++){
    scanf("%d%d",&u,&k);
    for(int j = 0; j < k; j++){
      scanf("%d%d",&v,&c);
      M[u][v] = c;
    }
  }
  
  dijkstra();

  return 0;
}



Measured memory_bytes: 2112
def main():
  n=int(input())
  ans=''
  if n==0:
    print(0)
  else:
    while n!=0:
      if n%2==0:
        ans='0'+ans
      else:
        ans='1'+ans
        n-=1
      n=n//(-2)
  print(ans)
if __name__=='__main__':
  main()

Measured memory_bytes: 2940
#include <stdio.h>
#include <math.h>
int f(int n) {
	if (!n) return 1;
	return f(n-1)+n;
}
int main() {
	int n;
	while(scanf("%d", &n) != EOF) {
		printf("%d\n", f(n));
	}
	return 0;
}

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

int main() {
	ll N;
	cin >> N;
	
	vector<ll> a(N);
	vector<ll> b(N);
	for(ll i=0;i<N;i++){
		cin >> a.at(i)>>b.at(i);
	}
	ll count =0;
	for(ll i=N-1;i>=0;i--){
		if(b.at(i)!=1 && (a.at(i)+count)%b.at(i)!=0){
			count+=b.at(i)-(a.at(i)+count)%b.at(i);
		}
	}
	cout<<count<<endl;
}

Measured memory_bytes: 1792
class SegmentTree:
    _op = None
    _e = None
    _size = None
    _offset = None
    _data = None

    def __init__(self, size, op, e):
        self._op = op
        self._e = e
        self._size = size
        t = 1
        while t < size:
            t *= 2
        self._offset = t - 1
        self._data = [0] * (t * 2 - 1)

    def build(self, iterable):
        op = self._op
        data = self._data
        data[self._offset:self._offset + self._size] = iterable
        for i in range(self._offset - 1, -1, -1):
            data[i] = op(data[i * 2 + 1], data[i * 2 + 2])

    def update(self, index, value):
        op = self._op
        data = self._data
        i = self._offset + index
        data[i] = value
        while i >= 1:
            i = (i - 1) // 2
            data[i] = op(data[i * 2 + 1], data[i * 2 + 2])

    def query(self, start, stop):
        def iter_segments(data, l, r):
            while l < r:
                if l & 1 == 0:
                    yield data[l]
                if r & 1 == 0:
                    yield data[r - 1]
                l = l // 2
                r = (r - 1) // 2
        op = self._op
        it = iter_segments(self._data, start + self._offset,
                           stop + self._offset)
        result = self._e
        for v in it:
            result = op(result, v)
        return result


N, K, *A = map(int, open(0).read().split())
st = SegmentTree(300000 + 1, max, 0)

for a in A:
    st.update(a, st.query(max(a - K, 0), min(a + K + 1, 300000 + 1)) + 1)

print(st.query(0, 300000 + 1))


Measured memory_bytes: 123708
import java.util.*

private fun readStrings() = readLine()!!.split(" ")
private fun readInts() = readStrings().map { it.toInt() }

private inline fun <T, R> Collection<T>.scanIndexed(initial: R, operation: (Int, R, T) -> R): List<R> {
    val result = ArrayList<R>(size)
    var prevResult = initial
    forEachIndexed { index, element ->
        val elementResult = operation(index, prevResult, element)
        result.add(elementResult)
        prevResult = elementResult
    }
    return result
}

private inline fun <T> Iterable<T>.scanIndexed1(operation: (Int, T, T) -> T): List<T>
        = drop(1).scanIndexed(first(), operation)

private inline fun <T> Iterable<T>.scan1(operation: (T, T) -> T): List<T>
        = scanIndexed1 {i, list, elem -> operation(list, elem)}

fun main(args: Array<String>) {
    val N = readInts()[0]
    val a = readInts().map{ it.toLong() }
    println(
            (listOf(0L, 0L) + a)
            .scan1 { a, b -> a + b }
            .groupBy { it }.map { it.value.size.toLong() }
            .map { it * (it - 1L) / 2L }
            .sum()
    )
}

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

using namespace std;

#define ll long long 
#define ld long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mkp make_pair
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define ff first
#define ss second
#define endl "\n"
#define MOD 1000000007
#define MOD1 998244353
#define inf LLONG_MAX

ll GCD(ll x,ll y){if(y==0)return x;return GCD(y,x%y);}
ll LCM(ll x,ll y){return (x*y)/(GCD(x,y));}
ll LOGK(ll x,ll k){if(x>=k)return 1+LOGK(x/k,k);return 0;}
ll MPOW( ll a, ll b, ll m) { if(b==0) return 1; ll x=MPOW(a,b/2,m); x=(x*x)%m; if(b%2==1) x=(x*a)%m; return x;}
ll MINV(ll a,ll m) {return MPOW(a,m-2,m);}

class pnc{
  ll FACT_MAX,MODU;
  vector<ll> fact;
public:
  pnc( ll n, ll m) { FACT_MAX = n; fact.resize(FACT_MAX); MODU = m; MFACT_INIT(MODU);}
  void MFACT_INIT( ll m) { fact[0]=1; for(ll i=1;i<FACT_MAX;++i) fact[i]=(i*fact[i-1])%MODU;}
  ll MFACT( ll n) { return fact[n];}
  ll PERM( ll n, ll r) { return (fact[n]*::MINV(fact[n-r],MODU))%MODU;}
  ll COMB( ll n , ll r) { return (PERM(n,r)*::MINV(fact[r],MODU))%MODU;}
};

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

    ll test=1;
    //cin>>test;
    while(test--)
    {
        ll n;
        cin>>n;

        ll a[n];
        ll b[n];

        for(ll i=0;i<n;i++)
        cin>>a[i]>>b[i];

        sort(a,a+n);
        sort(b,b+n);

        if(n%2)
        {
            ll mn=a[n/2];
            ll mx=b[n/2];

            cout<<mx-mn+1;
        }
        else
        {
            ll mn=(a[n/2]+a[n/2-1]);
            ll mx=(b[n/2]+b[n/2-1]);

            cout<<(mx-mn)+1;
        }
        
    }
}

Measured memory_bytes: 6720
#include <bits/stdc++.h>
using namespace std;
#define N 200010
#define fi first
#define se second
#define CINSPEED ios::sync_with_stdio(false),std::cin.tie(0),std::cout.tie(0)

typedef long long ll;
ll c[N];

ll max(ll a,ll b)
{
    return a > b ? a: b;
}

void solved()
{
    int n,d,a;
    cin >> n >> d >> a;
    vector< pair<int,int> > Monster(n);
    for(int i = 0;i < n;i++)
    {
        cin >> Monster[i].fi >> Monster[i].se;
    }
    sort(Monster.begin(),Monster.end());
    int j = 0;
    ll ans = 0;
    for(int i = 0;i < n;i++)
    {
        while(j < n &&Monster[j].fi <= Monster[i].fi + 2 * d )
        j++;

        ll need = max((Monster[i].se - c[i] * a + a - 1) / a,0);
        ans += need;
        c[i] += need;
        c[j] -= need;
        c[i + 1] += c[i];
    }
    cout << ans <<"\n";
}

int main()
{
    CINSPEED;
    solved();
#ifdef LOCAL
    system("pause");
#endif
    return 0;    
}

Measured memory_bytes: 3328
n, m = map(int, input().split())
W, V = [], []
for i in range(n):
    w, v = map(int, input().split())
    W.append(w)
    V.append(v)
A = [0 for j in range(m+1)]
for i in range(n):
    B = []
    for j in range(W[i]):
        B.append(A[j])
    for j in range(W[i], m+1):
        B.append(max(A[j], A[j-W[i]]+V[i]))
    A = B
print(A[m])


Measured memory_bytes: 111976
#include<bits/stdc++.h>
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define rep(i,n) for(int i = 0;  i < n ; ++i)
#define REP(i,a,b) for(int i = a ; i <= b ; ++i)
#define s(n) scanf("%d",&n)
#define rev(i,n) for(int i = n ; i >= 0 ; --i)
#define REV(i,a,b) for(int i = a ; i >= b ; --i)
#define miN(a,b) (((a)<(b))?(a):(b))
#define sc(n) scanf("%c",&n)
#define tr(c,i) for(typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define INF 1000000000
#define pii pair<long long int,long long int>
#define pb(a) push_back(a)
typedef long long ll;
using namespace std;
void pre(){}
void solve(){
    string s;cin>>s;
    if(s=="ABC"){
        cout<<"ARC"<<"\n";
    }else{
        cout<<"ABC"<<"\n";
    }
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    pre();
    long long int num = 1;
    //cin>>num;
    for(long long int i=0;i<num;i++){
       // cout<<"Case #"<<i+1<<" :";
       	solve();
    }   
}




Measured memory_bytes: 3648
#include <cstdio>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdlib>

#include <numeric>

#include <map>

#include <memory>

using namespace std;

typedef long long LL;

int n, m, s, ans;
int a[2222];

int main() {

   cin >> n >> m;
   for (int i =1; i <= n; ++i) {
       cin >> a[i];
       s+=a[i];
   }
   for (int i = 1; i <=n; ++i) {
       if (a[i] * 4 * m >= s) ++ans;
   }
   if (ans >= m) cout<< "Yes";
   else cout << "No";
}

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

int b[110][110];
int dp[110][110];

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

	for (int i = 0; i < 110; i++) {
		for (int j = 0; j < 110; j++) {
			b[i][j] = -1;
		}
	}

	int n = 0;
	string s;
	while (cin >> s) {
		int j = 0, m = s.size(), idx = 0;
		while (j < m) {
			string ss;
			while (j < m && s[j] != ',') ss += s[j++];
			j++;
			b[n][idx++] = atoi(ss.c_str());
		}
		n++;
	}

	dp[0][0] = b[0][0];
	for (int i = 0; i < n - 1; i++) {
		for (int j = 0; j < n; j++) {
			if (b[i][j] == -1) continue;
			for (int d = -1; d <= 1; d++) {
				if (i < n / 2 && d == -1 || n / 2 <= i && d == 1) continue;
				if (0 <= j + d && j + d < n && b[i + 1][j + d] != -1) {
					dp[i + 1][j + d] = max(dp[i + 1][j + d], dp[i][j] + b[i + 1][j + d]);
				}
			}
		}
	}

	cout << dp[n - 1][0] << endl;;
}

Measured memory_bytes: 1288
def solve():
    n, T = map(int, input().split())
    ans = 10000
    for _ in range(n):
        c, t = map(int, input().split())
        if t <= T:
            ans = min(c, ans)
    if ans == 10000:
        print('TLE')
    else:
        print(ans)


if __name__ == '__main__':
    solve()


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

int main(void){
    int n; cin >> n;
    set<int>d;
    for(int i=0;i<n;i++){
        int tmp; cin >> tmp;
        d.insert(tmp);
    }
    int ans = d.size();
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
H, W, N = map(int, input().split(" "))
arr = [[0 for i in range(H)] for j in range(W)]
# print(arr)
for i in range(N):
  x, y, a = map(int, input().split(" "))
  if a == 1:
    for j in range(x):
      for k in range(W):
        arr[k][j] = 1
  elif a == 2:
    for j in range(x, H):
      for k in range(W):
        arr[k][j] = 1
        
  elif a == 3:
    for j in range(H):
      for k in range(y):
        arr[k][j] = 1
  else:
    for j in range(H):
      for k in range(y, W):
        arr[k][j] = 1

count = 0
for i in arr:
  count += i.count(0)
print(count)

Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
const int inf=1e8;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
int main(){
	int n;
	cin>>n;
	int a,d;
	cin>>a>>d;
	int m;
	cin>>m;
	vvi in(m,vi(3));
	rep(i,m)rep(j,3)cin>>in[i][j];
	int q;
	cin>>q;
	
	for(int i=m-1;i>=0;i--)if(in[i][0]==0&&in[i][1]<=q&&q<=in[i][2]){
		q=in[i][2]-q+in[i][1];
	}
	int out=a+d*(q-1);
	rep(i,m){
		if(in[i][0]==1){if(in[i][1]<=q&&q<=in[i][2])out++;}
		else if(in[i][0]==2){if(in[i][1]<=q&&q<=in[i][2])out/=2;}
		else if(in[i][1]<=q&&q<=in[i][2]){
			q=in[i][2]-q+in[i][1];
		}
	}
	cout<<out<<endl;
	
}

Measured memory_bytes: 11232
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)

int main(){
  int N;
  cin >> N;
  if(N <= 999){
    cout << "ABC" << endl;
  }
  else{
    cout << "ABD" << endl;
  }
}


Measured memory_bytes: 256
S = input()
#S = "19?04??????451??" * (10 ** 5 // 5)
mod = 10 ** 9 + 7
dp = [[0 for _ in range(13)] for _ in range(len(S))]
if S[0] == "?":
  for i in range(10):
    dp[0][i] = 1
else:
  dp[0][int(S[0])] = 1
#print(dp)
for i in range(len(S) - 1):
  if S[i + 1] == "?":
    for j in range(13):
      for k in range(10):
        dp[i + 1][(j * 10 + k) % 13] += dp[i][j] % mod
  else:
    for j in range(13):
      dp[i + 1][(j * 10 + int(S[i + 1])) % 13] += dp[i][j] % mod
#print(dp)
print(dp[len(S) - 1][5] % (10 ** 9 + 7))

Measured memory_bytes: 65884
#include<bits/stdc++.h>
using namespace std;
int s,a1,a2;
int main(){
	cin>>s;
	a1=s%100;
	a2=s/100;
	if((1<=a1&&a1<=12)&&(1>a2||a2>12))cout<<"YYMM";else
	if((1>a1||a1>12)&&(1<=a2&&a2<=12))cout<<"MMYY";else
	if((1<=a1&&a1<=12)&&(1<=a2&&a2<=12))cout<<"AMBIGUOUS";else
	if((1>a1||a1>12)&&(1>a2||a2>12))cout<<"NA";
	return 0;
}

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

int main(){
  while (true) {
    int a, b;
    string op;
    cin >> a >> op >> b;
    
    if (op == "+") {
      cout << a+b << endl;
    }
    
    if (op == "-") {
      cout << a-b << endl;
    }
    
    if (op == "*") {
      cout << a*b << endl;
    }
    
    if (op == "/") {
      cout << a/b << endl;
    }
    
    if (op == "?") {
      break;
    }
  }
}


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

#define ll long long

using namespace std;

//memset(dp, 0, sizeof(dp));

void work(int T) {
	int n, q;
	cin >> n;
	vector<ll> a(n);
	for(int i = 0; i < n; i++) {
		cin >> a[i];
	}
	ll sum = 0;
	unordered_map<int, ll> m;
	for(auto &i : a) {
		m[i]++;
		sum += i;
	}
	cin >> q;
	for(int i = 0; i < q; i++) {
		ll b, c;
		cin >> b >> c;
		if(m.count(b)) {
			m[c] += m[b];
			sum -= m[b] * b;
			sum += m[b] * c;
			m[b] = 0;
		}
		cout << sum << endl;
	}
	return;
}

int main() {
	ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.precision(10);
    cout << fixed;
	// int t;
	// for(cin >> t; t > 0; t--) {
		// work(t);
	// }
	work(0);
	return 0;
};

Measured memory_bytes: 7600
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rrep(i,n) for(int (i)=((n)-1);(i)>=0;(i)--)
#define itn int
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
const long long INF = 1LL << 60;
const int MOD = 1000000007;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
signed main(void){
    int n,x,y; cin>>n>>x>>y;
    vector <tuple<int,int,int>> data(n);
    rep(i,n) {int a,b,c; cin>>a>>b>>c; data[i] = make_tuple(a,b,c);}
    vector<vector<vector<int>>> dp (50, vector<vector<int>>(510, vector<int>(510, INF)));
    dp[0][0][0] = 0;
    rep(i,n){
        for(int j=i;j>=0;j--){
            for(int k=0;k<=400;k++){
                for(int l=0;l<=400;l++){
                    if(dp[j][k][l] == INF) continue;
                    chmin(dp[j+1][get<0>(data[i]) + k][get<1>(data[i]) + l],dp[j][k][l] + get<2>(data[i]));
                }
            }
        }
    }
    int ans = INF;
    int multiply = 2;
    int nowx=x, nowy=y;
    while(nowx<=409&&nowy<=409){
        rep(i,n+5) chmin(ans, dp[i][nowx][nowy]);
        nowx = x*multiply, nowy = y*multiply;
        multiply++;
    }
    if(ans == INF) cout<<-1<<endl;
    else cout<<ans<<endl;
}


Measured memory_bytes: 104960
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<array>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<functional>
#include<limits>
#include<list>
#include<map>
#include<numeric>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<unordered_map>
#include<queue>
#include<vector>
using namespace std;

//#define int long long
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define dump(o) {cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) {cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
const int MOD = 1e9 + 7;

signed main() {
	int a[] = { 6000,4000,3000,2000 };
	rep(i, 0, 4) {
		int t, n; cin >> t >> n;
		cout << a[t - 1] * n << endl;
	}
	return 0;
}

Measured memory_bytes: 3084
#include<stdio.h>
#include<stdlib.h>
#include<algorithm>
#include<bitset>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<functional>
#include<list>
#include<map>
#include<iomanip>
#include<iostream>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<vector>
#include<algorithm>
#include<memory.h>
using namespace std;
int main(){
	long long n,a[100005],ans=0;
	memset(a,0,sizeof(a));
	cin>>n;
	ans=n;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	sort(a+1,a+1+n);
	for(int i=1;i<=n;i++){
		if(a[i]==a[i+1]){
			ans-=2;
			i++;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include "iostream"
#include "vector"
#include "string"
#include "algorithm"
#include "math.h"
#include "cstring"
#include "stack"
#include "queue"

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<vector<ll> > mat;

const ll mod = 1e9 + 7;

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

  ll ans[100100];
  memset(ans, -1, sizeof(ans));
  ans[0] = 1;
  ans[1] = 1;
  ll a[100100];
  for (ll i = 0; i < m; i++)
  {
    cin >> a[i];
    ans[a[i]] = 0;
  }
  for (int i = 2; i <= n; i++)
  {
    if (ans[i] == -1)
    {
      ans[i] = ans[i - 1] + ans[i - 2];
      ans[i] %= mod;
    }
  }
  cout << ans[n] << "\n";
}


Measured memory_bytes: 1792
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<cctype>
#include<complex>
#include<iostream>
#include<sstream>
#include<algorithm>
#include<functional>
#include<utility>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>
 
using namespace std;
const int dx[] = {1,0,-1,0},dy[] = {0,1,0,-1};
#define INF 1e+9
#define EPS 1e-9
#define rep(i,j) for(int i = 0; i < (j); i++)
#define reps(i,j,k) for(int i = j; i < (k); i++)
typedef long long ll;
bool check(int data[],int bef[],int n){
    rep(i,n){
        if(data[i] != bef[i])return false;
    }
    return true;
}
int main(){
    int n;
    while(scanf("%d",&n),n){
        int data[12800]={0};
        int bef[12800]={0};
        rep(i,n){
            scanf("%d",&data[i]);
        }
        int ans=0;
        while(true){
            if(check(data,bef,n)){
                printf("%d\n",--ans);
                rep(i,n-1){
                    printf("%d ",data[i]);
                }
                printf("%d\n",data[n-1]);
                break;
            }
            ans++;
            rep(i,n)bef[i] = data[i];
            int memo[12800]={0};
            rep(i,n){
                if(memo[bef[i]])data[i] = memo[bef[i]];
                else{
                    int cnt = 0;
                    rep(j,n)if(data[i] == bef[j])cnt++;
                    memo[data[i]] = cnt;
                    data[i] = cnt;
                }
            }
        }
    }
    return 0;
}

Measured memory_bytes: 1344
//ほぼstandard answer
#include<iostream>
using namespace std;
 
class Cube{
public:
  int f[6];
  Cube(){} 
  void roll_z(){ roll(1, 2, 4, 3);} //横向き
  void roll_y(){ roll(0, 2, 5, 3);} //サイコロの番号は+1
  void roll_x(){ roll(0, 1, 5, 4);}
  void roll(int i, int j, int k, int l){
    int t = f[i]; f[i] = f[j]; f[j] = f[k]; f[k] = f[l]; f[l] = t;
  }
  /*前回載せた void move(char ch) いらない*/
};
 
int getRight( Cube c1, int f1, int f2 ){ //what is the right face
  for(int i = 0; i < 6; i++){
    for ( int j = 0; j < 4; j++ ){
      if ( c1.f[0] == f1 && c1.f[1] == f2 ) return c1.f[2];
      c1.roll_z(); //違ったら横に回転してf[1]変えてみよか(前面)
    }
    if ( i % 2 == 0 ) c1.roll_y();
    /*i%2==0 に意味はないんちゃう？
      3回ずつ2方向回転*/
    else c1.roll_x();
  }
  return -1;
}
 
int main(){
  Cube c; 
  int f1,f2; //question
  //f1 -> up    f2 -> front
   
  for ( int i = 0; i < 6; i++ ) cin >> c.f[i]; //define each face 
  int q; cin >> q; //the number of questions
   
  for ( int i = 0; i < q; i++ ){
    cin >> f1 >> f2;
    cout << getRight(c, f1, f2) << endl;
  }
   
  return 0;
}


Measured memory_bytes: 3108
def solve():
    N = int(input())
    H = map(int, input().split())
    min_h = 0
    ret = True
    for h in H:
        if min_h > h:
            ret = False
            break
        min_h = max(min_h, h-1)
    print('Yes' if ret else 'No')

solve()

Measured memory_bytes: 11152
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<ll,ll> ii;
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define FOR(i,j,n,m) for(int i=j;i<n;i+=m)
#define RST(i,n) memset(i,n,sizeof i)
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(),a.end()
#define F first
#define S second
#define pb push_back
#define pob pop_back
#define MP make_pair
#ifdef cold66
#define debug(...) do{\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<" ,";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.F<<","<<_p.S<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#endif // cold66
//}

template<class T> inline bool chkmax(T &a, const T &b) { return b > a ? a = b, true : false; }
template<class T> inline bool chkmin(T &a, const T &b) { return b < a ? a = b, true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;

const ll MAXn=55,MAXlg=__lg(MAXn)+2;
const ll MOD=1000000007;
const ll INF=(ll)1e18;

char d[MAXn][MAXn];
ll n,m;
ll dx[]={1,0,0,-1};
ll dy[]={0,1,-1,0};
bool chk(ll x,ll y){
  if(x<0 || x>=n || y<0 || y>=m) return true;
  else return false;
}
int main(){
  IOS();
  cin>>n>>m;
  bool fg=true;
  REP(i,n)REP(j,m) cin>>d[i][j];
  REP(i,n)REP(j,m){
    if(d[i][j]=='.')  continue;
    else{
      bool ok=false;
      REP(k,4){
        if(chk(i+dx[k],j+dy[k])) continue;
        if(d[i+dx[k]][j+dy[k]]=='#') ok=true;
      }
      if(!ok) fg=false;
    }
  }
  if(fg) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}


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

const ll INF = 1e18;
const int MAXN = 2500;
struct edge{
	int to;
	int cost;
};

vector<ll> d;

// sを始点とした全頂点の最短経路長（ベルマンフォード）
// sからtに到達不可ならば d[t] = INF
// 負閉路が存在するときtrueを返す
bool bellman_ford(int s, vector<vector<edge>> &to){
	int n = to.size();
	d = vector<ll>(n, INF);
	d[s] = 0;
	
	rep(i,n){
		rep(v,n){
			for(edge e : to[v]){
				if(d[v] != INF && d[e.to] > d[v] + e.cost){
					d[e.to] = d[v] + e.cost;
					if(i == n-1) return true;
				}
			}
		}
	}
	return false;
}

vector<bool> from1(MAXN,false);
vector<bool> toN(MAXN,false);
vector<vector<int>> to(MAXN), from(MAXN);

void dfsfrom1(int v){
	if(from1[v]) return;
	from1[v] = true;
	for(auto child : to[v]) dfsfrom1(child);
	return;
}

void dfstoN(int v){
	if(toN[v]) return;
	toN[v] = true;
	for(auto parent : from[v]) dfstoN(parent);
	return;
}


int main(){
	
	int n,m,p;
	cin >> n >> m >> p;
	
	
	vector<tuple<int,int,int>> edges;
	rep(i,m){
		int a,b,c;
		cin >> a >> b >> c;
		--a; --b;
		edges.push_back(make_tuple(a,b,c));
		to[a].push_back(b);
		from[b].push_back(a);
	}
	
	dfsfrom1(0);
	dfstoN(n-1);
	
	
	vector<vector<edge>> to2(n);
	rep(i,m){
		int a = get<0>(edges[i]);
		int b = get<1>(edges[i]);
		int c = get<2>(edges[i]);
		if(from1[a] && from1[b] && toN[a] && toN[b]){
			to2[a].push_back(edge{b, -(c-p)});
		}
	}

	bool existloop = bellman_ford(0,to2);
	
	if(existloop) cout << -1 << endl;
	else cout << max(-d[n-1],0ll) << endl;
	
	return 0;
}


Measured memory_bytes: 768
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
template <class T> inline void chmin(T &a, const T& b) { if (b < a) a = b; }
template <class T> inline void chmax(T &a, const T& b) { if (b > a) a = b; }
/* clang-format on */

int main() {
#ifdef DEBUG
  ifstream cin("in.txt");
#endif
  vector<int> a(5);
  for (int i = 0; i < 5; i++) cin >> a[i];
  vector<int> ind(5);
  iota(ind.begin(), ind.end(), 0);
  int res = 1 << 25;
  do {
    int tm = 0;
    for (int i : ind) {
      int x = a[i];
      tm = (tm + 9) / 10 * 10;
      tm += x;
    }
    res = min(res, tm);
  } while (next_permutation(ind.begin(), ind.end()));
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int n,m,k;
int t=0;
int main()
{
	cin >>n>>m>>k;
	for (int i=min(n,m);i>0;i--)
	{
		if (n%i==0 && m%i==0)
		{
			t++;
			if (t==k)
			{
				cout <<i;
				return 0;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
#define SORT(c) sort((c).begin(),(c).end())
#define dbug(x) cout<<#x<<"="<<x<<endl
#define m0(x) memset(x,0,sizeof(x))
#define rep(i, n) for(int i = 0; i < n; i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define reps(i, m, n) for(int i = m; i < n; i++)
#define reprs(i, m, n) for(int i = n; i >= m; i--)
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<ll, ll> pl;
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
  for(T& x: vec) is >> x;
  return is;
}


int main(){

  int N;
  cin >> N;

  ll A[N];

  ll ct=0;
  rep(i,N){
    cin>>A[i];
    ct+=A[i];
  }
  ll ans[N];

  ll sum=0;
  int x=0;
  while(x<N){
    sum+=A[x];
    x+=2;
  }

  ans[0]=sum*2-ct;

  reps(i,1,(N/2)+1){
    sum=sum-A[(2*i)-2]+A[(2*i)-1];

    ans[2*i]=sum*2-ct;
  }

  sum=sum-A[N-1]+A[0];
    ans[1]=sum*2-ct;

  reps(i,1,(N/2)){
      sum=sum-A[(2*i)-1]+A[(2*i)];

      ans[(2*i)+1]=sum*2-ct;
  }

  rep(i,N){
    std::cout << ans[i] << " ";
  }

  return 0;
}


Measured memory_bytes: 2816
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
using namespace std;
typedef long long ll;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

#define EPS (1e-7)
#define INF (1e15)
#define PI (acos(-1))
#define MOD 1000000007

#define REP(i,n) for(int i=0;i<n;i++)
#define REPS(i,f,n) for(int i=(f);i<(n);i++)
#define EACH(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)

#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define arrdump(n,a) for(int i=0;i<n;i++) {cout<<((i>0)? " ":"")<<a[i];}cout<<"\n";


typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int dy4[]={0, 0, 1, -1};
int dx4[]={1, -1, 0, 0};
int dx8[]={0, 0, 1, -1, 1, 1, -1, -1};
int dy8[]={1, -1, 0, 0, 1, -1, -1, 1};

// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_3_C&lang=jp

struct Node
{
    int key;
    Node *prev, *next;
};

Node *nil;

static void insert(int key) {
    Node* x = (Node*)malloc(sizeof(Node));
    x->key = key;
    x->next = nil->next;
    x->prev = nil;
    nil->next->prev = x;
    nil->next = x;
}

static void deleteNode(Node* node) {
    if (node == nil) return;
    node->next->prev = node->prev;
    node->prev->next = node->next;
    free(node);
}

static Node* searchNode(int key) {
    Node* cur = nil->next;
    while(cur != nil && cur->key != key) {
        cur = cur->next;
    }
    return cur;
}

static void deleteKey(int key) {
    deleteNode(searchNode(key));
}

static void deleteFirst() {
    deleteNode(nil->next);
}

static void deleteLast() {
    deleteNode(nil->prev);
}

static void init() {
    nil = (Node*)malloc(sizeof(Node));
    nil->next = nil;
    nil->prev = nil;
}

static void print() {
    Node *cur = nil->next;
    int i = 0;
    while(cur != nil) {
        if (i) cout << " ";
        i++;
        cout << cur->key;
        cur = cur->next;
    }
    cout << "\n";
}

int main() {
    init();
    int n; cin >> n;
    char str[50];
    int key;

    REP(i, n) {
        scanf("%s%d", str, &key);
        string com = string(str);
        if (com == "insert") insert(key);
        if (com == "delete") deleteKey(key);
        if (com == "deleteFirst") deleteFirst();
        if (com == "deleteLast") deleteLast();
    }
    print();

    return 0;
}



Measured memory_bytes: 34528
while True:
    w, h = map(int, input().split())
    if not w:
        break
    district = [[0] * w for _ in range(h)]

    district[0] = [(1, 0, 0, 0)] * w

    for i in range(1, h):
        row = district[i]
        row[0] = (0, 1, 0, 0)
        for j in range(1, w):
            left, under = row[j - 1], district[i - 1][j]
            row[j] = tuple(map(lambda x: x % 100000, (left[0] + left[2], under[1] + under[3], left[1], under[0])))

    print(sum(district[-1][-1]) % 100000)

Measured memory_bytes: 9164
N = int(input())
H = [int(_) for _ in input().split()]
flag = True

if N == 1:
    print("Yes")
else:
    for i in range(1, N):
        if H[i-1] <= H[i]:
            continue
        elif H[i-1] == H[i]+1:
            H[i] += 1
        else:
            flag = False
            break

    print("Yes" if flag else "No")

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

using ll = long long;

bool is_all_same(const string &s) {
  for (int i = 1; i < s.size(); i++) {
    if (s.at(0) != s.at(i)) {
      return false;
    }
  }
  return true;
}

int solve(const string &s) {
  char pre_char = '+';
  int num_of_same_char = 0;
  int num_to_rewrite = 0;
  for (char c : s) {
    if (c == pre_char) {
      num_of_same_char++;
      if(num_of_same_char % 2 == 0) {
        num_to_rewrite++;
      }
    } else {
      pre_char = c;
      num_of_same_char = 1;
    }
  }
  return num_to_rewrite;
}

int main() {
  string S;
  cin >> S;
  int K;
  scanf("%d", &K);

  if(is_all_same(S)) {
    printf("%lld", (ll)S.size() * (ll)K / 2LL);
    return 0;
  }
  
  string SS = S + S;

  int first = solve(S);
  int second = solve(SS);
  int diff = second - first;

  if (K == 1) {
    printf("%d", first);
  } else {
    printf("%lld", (ll)first + ((ll)diff * (ll)(K - 1)));
  }

  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<type_traits>
#include<math.h>
#include<fstream>
#include<set>
using namespace std;
typedef long long ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define out(str) cout << str << endl
#define ALL(a) (a).begin(),(a).end()
#define INF (1<<29)

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

int ans=1,N,X,now=0,A;

int main(){
    cin>>N>>X;
    rep(i,N){
        cin>>A;
        now+=A;
        if(now<=X)ans++;

    }
    out(ans);
    
}


Measured memory_bytes: 256
#include <stdio.h>

#define M 500001

int hp,tree[M];

void Max_retu(int x){
  int R,L,change,s;
  L=2*x;
  R=2*x+1;
  
  if(L<=hp && tree[x]<tree[L]){
    s=L;
  }
  else s=x;
  if(R<=hp && tree[s]<tree[R]){
    s=R;
  }
  if(s!=x){
    change=tree[x];
    tree[x]=tree[s];
    tree[s]=change;
    Max_retu(s);
  }
}


int main(){
  int i;

  scanf("%d",&hp);

  for(i=1;i<=hp;i++){
    scanf("%d",&tree[i]);
  }

  for(i=hp/2;i>=1;i--){
    Max_retu(i);
  }

  for(i=1;i<=hp;i++){
    printf(" %d",tree[i]);
  }
  printf("\n");

  return 0;
}
      



Measured memory_bytes: 3696
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define PI 3.141592653589793
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, a, n) for (int i = a; i < (n); i++)
#define rrep(i, n, k) for (int i = (n); i >= (k); i--);
#define all(x) (x).begin(), (x).end()
#define vi vector<int>
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T>vector<T> make_vector(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto make_vector(size_t a, Ts... ts){return vector<decltype(make_vector<T>(ts...))>(a, make_vector<T>(ts...));}
const int inf = 6e18;
const int mod = 1e9 + 7;

signed main() {
    int N;
    cin >> N;
    int ans = 0;
    map<pair<char, char>, int> check;
    for (int i = 1; i <= N; i++) {
        string temp = to_string(i);
        check[{temp[0], temp[temp.length() - 1]}]++;
    }
    for (int i = 1; i <= N; i++) {
        string temp = to_string(i);
        ans += check[{temp[temp.length() - 1], temp[0]}];
    }
    cout << ans << endl;
}


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

// one-based numbering
template<class T> struct Fenwick {
    vector<T> bit; int N;
    Fenwick(int n) {
        N = n;
        bit.resize(n+1, 0);
    }
    void add(int a, T w) {
        for (int x = a; x <= N; x += x & -x) bit[x] += w;
    }
    T sum(int a) {
        T ret = 0;
        for (int x = a; x > 0; x -= x & -x) ret += bit[x];
        return ret;
    }
};

int main() {
    long long n; cin >> n;
    vector<long long> two(n+1, 1);
    for (long long i = 0; i < n; i++) {
        two[i+1] = two[i] * 2 % mod;
    }
    long long ans = (two[n] - 1) * n % mod; // all
    map<int, int> xmap, ymap, ycompress;
    vector<pair<int, int>> xy;
    for (int i = 0; i < n; i++) {
        int x, y; cin >> x >> y;
        xy.emplace_back(x, y);
        xmap[x]++; ymap[y]++;
    }

    {   // x
        long long cnt = 0;
        for (auto it: xmap) {
            auto num = it.second;
            ans += mod - ((two[cnt] - 1) * num) % mod;
            cnt += num;
            ans += mod - ((two[n-cnt] - 1) * num) % mod;
            ans %= mod;
        }
    }

    {   // y
        long long cnt = 0;
        int number = 1;
        for (auto it: ymap) {
            auto num = it.second;
            ans += mod - ((two[cnt] - 1) * num) % mod;
            cnt += num;
            ans += mod - ((two[n-cnt] - 1) * num) % mod;
            ans %= mod;
            ycompress[it.first] = number++;
        }
    }

    {   // up
        sort(xy.begin(), xy.end());
        Fenwick<int> f(ycompress.size());
        int xprev = xy.front().first;
        for (int i = 0; i < n; i++) {
            if (xprev != xy[i].first) {
                for (int j = i-1; j >= 0; j--) {
                    if (xprev != xy[j].first) break;
                    f.add(ycompress[xy[j].second], 1);
                }
                xprev = xy[i].first;
            }
            int yc = ycompress[xy[i].second];
            int s = f.sum(yc-1);
            int t = f.sum(f.N) - f.sum(yc);
            ans += two[s] + two[t] - 2;
            ans %= mod;
        }
    }

    {   // down
        reverse(xy.begin(), xy.end());
        Fenwick<int> f(ycompress.size());
        int xprev = xy.front().first;
        for (int i = 0; i < n; i++) {
            if (xprev != xy[i].first) {
                for (int j = i-1; j >= 0; j--) {
                    if (xprev != xy[j].first) break;
                    f.add(ycompress[xy[j].second], 1);
                }
                xprev = xy[i].first;
            }
            int yc = ycompress[xy[i].second];
            int s = f.sum(yc-1);
            int t = f.sum(f.N) - f.sum(yc);
            ans += two[s] + two[t] - 2;
            ans %= mod;
        }
    }

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

Measured memory_bytes: 32240
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i > (b); i--)
#define ALL(a) (a).begin(), (a).end()

int main() {
    string s;
    cin >> s;
    cout << s[0] << s.length() - 2 << s[s.length() - 1] << endl;
    return 0;
}

Measured memory_bytes: 256
#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<vector>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#define LL long long int
#define REP(i,n) for (int i = 1; i <= (n); i++)
#define Redge(u) for (int k = h[u],to; k; k = ed[k].nxt)
#define cls(s,v) memset(s,v,sizeof(s))
#define mp(a,b) make_pair<int,int>(a,b)
#define cp pair<int,int>
using namespace std;
const int maxn = 100005,maxm = 100005,INF = 0x3f3f3f3f;
inline int read(){
	int out = 0,flag = 1; char c = getchar();
	while (c < 48 || c > 57){if (c == '-') flag = 0; c = getchar();}
	while (c >= 48 && c <= 57){out = (out << 1) + (out << 3) + c - 48; c = getchar();}
	return flag ? out : -out;
}
int main(){
	int x = read();
	if (x <= 599) puts("8");
	else if (x <= 799) puts("7");
	else if (x <= 999) puts("6");
	else if (x <= 1199) puts("5");
	else if (x <= 1399) puts("4");
	else if (x <= 1599) puts("3");
	else if (x <= 1799) puts("2");
	else puts("1");
	return 0;
}

Measured memory_bytes: 3632
/*
[abc101] C - Minimization
*/

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;

const int MAX_N = 100000;

int N, K;
int a[MAX_N];

ll solve() { return (N - 1 + K - 1 - 1) / (K - 1); }

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

    cout << solve() << endl;

    return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <stack>
#include <cstdlib>
using namespace std;

int main() {
    string in;
    int l,r;
    stack<int> st;
    while(cin>>in){
        if (in == "+") {
            r = st.top();
            st.pop();
            l = st.top();
            st.pop();
            st.push(l+r);
        } else if (in == "-") {
            r = st.top();
            st.pop();
            l = st.top();
            st.pop();
            st.push(l-r);
        } else if (in == "*") {
            r = st.top();
            st.pop();
            l = st.top();
            st.pop();
            st.push(l*r);
        } else {
            st.push(atoi(in.c_str()));
        }
    }
    cout<<st.top()<<endl;
    return 0;
}



Measured memory_bytes: 3152