akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <chrono>
#include <cstring>
#include <functional>
#include <iostream>
#include <istream>
#include <map>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <iostream>
#include <iomanip>
#include <math.h>
#include <cmath>
#include <array>
#include <complex>

#define endl '\n'

using namespace std;

class Trie {
public:

    vector<vector<int>> go;
    vector<int> fin, parent;

    Trie() {
        new_node();
    }

    int new_node() {
        go.push_back(vector<int>(26));
        fin.push_back(0);
        parent.push_back(0);
        return fin.size() - 1;
    }

    void push(string &s) {
        int u = 0;

        for (auto x : s) {
            int p = x - 'a';

            if (go[u][p] == 0) {
                int r = new_node();
                go[u][p] = r;
                parent[r] = u;
            }

            u = go[u][p];
        }

        fin[u] = 1;
    }

    long long solve(int s = 0) {
        long long res = 0;

        if (fin[s]) {
            vector<bool> freq(26);
            int p = s, u, d = 0;

            do {
                u = p; p = parent[p]; ++d;

                for (int i = 0; i < 26; ++i) {
                    if (go[p][i] == u)
                        freq[i] = true;

                    if (d >= 2 && freq[i] && go[p][i] && fin[go[p][i]]) {
                        res++;
                    }

                }
            } while (p != 0);
        }

        for (int i = 0; i < 26; ++i) {
            if (go[s][i])
                res += solve(go[s][i]);
        }

        return res;
    }
};

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

    int n; cin >> n;

    Trie t;

    for (int i = 0; i < n; ++i) {
        string s; cin >> s;
        reverse(s.begin(), s.end());
        t.push(s);
    }

    long long res = t.solve();

    cout << res << endl;

    return 0;
}


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


int main() {
    string s;
    cin>>s;
    char op,l;
    op=s[0];
    int count=0;
    for (int i = 1; i < s.length(); ++i) {
        l=s[i];
        if(op!=l)count++;
        op=l;
    }
    cout<<count<<endl;
    return 0;
}

Measured memory_bytes: 512
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		String line = sc.next();

		int linelen = line.length();
		int seaC = -1;
		//boolean f = true;
		String ans = "WA";

		if(line.substring(0, 1).equals("A")) {
			//System.out.println("Aふくまれている");


			for(int i = 2; i < linelen; i++) {
				if(line.substring(i,i+1).equals("C")) {
					//System.out.println("Cが含まれている："+(i+1)+"番目");
					seaC = i;
				}
			}
			if(seaC == linelen-1) {
				seaC = -1;
			}

			if(0 < seaC) {
			line = line.replaceFirst("A", "a");
			line = line.replaceFirst("C", "c");
			//System.out.println(line);

			ans = "AC";

			for(int i = 1; i < linelen; i++) {
				if(Character.isUpperCase(line.charAt(i))) {
					//System.out.println("大文字が含まれます");
					ans = "WA";
					break;
				}
			}

			}

		}
		System.out.println(ans);

		sc.close();
	}

}


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

const int MAX = 510000;
const int MOD = 1000000007;
const int MAX_N = 200000;



int main(int argc, const char * argv[]) {
  ll N; cin >> N;
  ll ans=0;
  vector<ll> A(N);
  for(ll i=0;i<N;i++){
    cin >> A[i];
  }
  vector<ll> S(N+1);
  S[0]=0;
  for(ll i=0;i<N;i++){
    S[i+1]=S[i]+A[i];
  }

  map<ll,ll> MAP;
  for(ll i=0;i<=N;i++){
    ans+=MAP[(S[i])];
    MAP[(S[i])] += 1 ;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 15872
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define pqueue priority_queue
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  string S, T;
  cin>>S>>T;
  sort(S.begin(), S.end());
  sort(T.begin(), T.end(), greater<char>());
  if(S<T) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}



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

using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
	REP(i, v.size()) { if (i)os << " "; os << v[i]; }return os;
}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
	REP(i, v.size()) { if (i)os << endl; os << v[i]; }return os;
}

const ll INF = 1LL << 60;
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int main() {
	ll d, n;

	cin >> d >> n;

	if (d == 0) {
		if (n == 100) {
			cout << 101 << endl;
		}
		else {
			cout << n << endl;
		}
	}
	else if (d == 1) {
		if (n == 100) {
			cout << 10100 << endl;
		}
		else {
			cout << n * 100 << endl;
		}
	}
	else {
		if (n == 100) {
			cout << 1010000 << endl;
		}
		else {
			cout << n * 10000 << endl;
		}
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define repb(i,n,b) for (ll i = b; i < (ll)(n); i++)
#define rep(i,n) repb(i,n,0)
ll dp[3001][3001][4];
ll gds[3001][3001];
int main(){
	ll R,C,K;
	cin>>R>>C>>K;
	rep(i,K){
		ll r,c,v;
		cin>>r>>c>>v;
		gds[r-1][c-1]=v;
	}
	rep(i,3){
		dp[0][0][i]=gds[0][0];
	}
	dp[0][0][3]=0;
	repb(c,C,1){
		rep(i,3){
			dp[0][c][i]=max(dp[0][c-1][i+1]+gds[0][c],dp[0][c-1][i]);
		}
		dp[0][c][3]=dp[0][c-1][3];
	}
	repb(r,R,1){
		rep(i,3){
			dp[r][0][i]=gds[r][0]+dp[r-1][0][0];
		}
		dp[r][0][3]=dp[r-1][0][0];
	}
	repb(r,R,1){
		repb(c,C,1){
			rep(i,3){
				dp[r][c][i]=max(max(dp[r][c-1][i+1]+gds[r][c],dp[r][c-1][i]),dp[r-1][c][0]+gds[r][c]);
			}
			dp[r][c][3]=max(dp[r][c-1][3],dp[r-1][c][0]);
		}
	}
	cout<<dp[R-1][C-1][0]<<endl;
}


Measured memory_bytes: 355072
// includes {{{
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<random>
#include<cassert>
#include<bitset>
#include<cstdlib>
// #include<deque>
// #include<multiset>
// #include<cstring>
// #include<bits/stdc++.h>
// }}}
using namespace std;
using ll = long long;


int main() {
  std::ios::sync_with_stdio(false), std::cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<int> a(2 * n);
  for(int i = 0; i < 2 * n; i++) cin >> a[i];
  sort(begin(a), end(a));
  int ok = n, ng = -1;

  while(abs(ok - ng) > 1) {
    int mid = (ok + ng) >> 1;
    bool flag = 1;
    for(int i = mid * 2, j = 2 * n - 1; i < 2 * n; i++, j--) {
      flag &= a[i] + a[j] >= m;
    }
    if(flag) ok = mid; else ng = mid;
  }

  int ans = 0;
  for(int i = 0, j = ok * 2 - 1; i < ok * 2; i++, j--) {
    ans = max(ans, a[i] + a[j]);
  }
  for(int i = ok * 2, j = 2 * n - 1; i < 2 * n; i++, j--) {
    ans = max(ans, a[i] + a[j] - m);
  }

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


Measured memory_bytes: 1024
#include <iostream>
using namespace std;
int main()
{
   int a,b;cin>>a>>b;
   if(a<6)
   cout<<0<<endl;
   else if(a>=6 && a<13)
   cout<<(b/2)<<endl;
   else
   {
       cout<<b<<endl;
   }
   return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstring>
#include <iomanip>
#include <queue>
#include <list>

using namespace std;

typedef unsigned uint;
typedef long long ll;
typedef unsigned long long ull;
const int inf = 1ULL << 31 - 1;
const ll linf = 1ULL << 63 - 1;
const string nilstr("");

char encode(char c) {
    return c >= 'A' && c <= 'Z' ? c - 'A' : c - 'a' + (char) 26;
}

char decode(char i) {
    return i < 26 ? i + 'A' : i - (char) 26 + 'a';
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    vector<int> x;
    x.push_back(abs(a - b));
    x.push_back(abs(a - c));
    x.push_back(abs(b - c));
    sort(x.begin(), x.end());
    cout << x[0] + x[1] << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define Tp template<typename Ty>
#define Ts template<typename Ty,typename... Ar>
#define Reg register
#define RI Reg int
#define Con const
#define CI Con int&
#define I inline
#define W while
#define N 200000
#define SZ 1000000
using namespace std;
int n,id[N+5],p[N+5];string s[N+5];
class Trie
{
	private:
		int Nt,g[30];struct node {int S[30],C[30];}O[SZ+5];
	public:
		I Trie() {Nt=1;}I int Ins(string s)
		{
			RI i,j,x=1,y=1,t,l=s.length();for(i=0;i^l;++i) ++g[s[i]&31];for(i=l-1;~i;--i)
			{
				for(j=1;j<=26;++j) g[j]&&++O[x].C[j];--g[t=s[i]&31];
				!O[x].S[t]&&(O[x].S[t]=++Nt),y=x,x=O[x].S[t];
			}return y;
		}
		I int Qry(CI x,CI v) {return O[x].C[v]-1;}
}T;
int main()
{
	RI i,x;ios::sync_with_stdio(false),cin>>n;for(i=1;i<=n;++i) cin>>s[i],p[i]=T.Ins(s[i]);
	long long t=0;for(i=1;i<=n;++i) t+=T.Qry(p[i],s[i][0]&31);return printf("%lld\n",t),0;
}

Measured memory_bytes: 245028
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <random>
#include <tuple>
#include <iomanip>
#include <cstring>

using namespace std;

typedef long long ll;
//typedef pair<int,int> Pint;
//typedef pair<ll, ll> P;
typedef pair<ll, pair<ll, ll>> P;
//typedef tuple<int,int,int> T;
typedef vector<ll> vec;
typedef vector<vec> mat;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define revrep(i, n) for(ll i = (n-1); i >= 0; i--)
#define pb push_back
#define f first
#define s second
const ll INFL = 1LL << 60;//10^18 = 2^60
const int INF = 1 << 30;//10^9
const ll MOD = 1e9 + 7;
//const ll MOD  = 998244353;
vector<ll> dy = {0, 0, 1, -1, 1, 1, -1, -1, 0};
vector<ll> dx = {1, -1, 0, 0, 1, -1, 1, -1, 0};

ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}
ll pow_long(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2) res *= x;
    x *= x;
    k /= 2;
  }
  return res;
}
ll pow_mod(ll x, ll k){
  x %= MOD; x += MOD; x %= MOD;
  ll res = 1;
  while(k > 0){
    if(k % 2){
      res *= x; res %= MOD;
    }
    x *= x; x %= MOD;
    k /= 2;
  }
  return res;
}
ll inverse(ll x){return pow_mod(x, MOD - 2);};

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

//最小公倍数
ll lcm(ll x, ll y){return x / gcd(x, y) * y;};

//コンビネーション
const int MAXcomb = 200010;
ll fac[MAXcomb], finv[MAXcomb], inv[MAXcomb];
//facはn!,finvは1/n!
//invは逆元
void COMinit(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < MAXcomb; i++){
        fac[i] = fac[i-1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
        finv[i] = finv[i-1] * inv[i] % MOD;
    }
}
ll comb(int n, int k){
    if(n < k) return 0;
    if(n < 0 || k < 0) return 0;
    return fac[n] * finv[k] % MOD * finv[n-k] % MOD;
}

ll dp[210][210];

int main(){

  ll N;
  cin >> N;
  vector<char> C(N);
  rep(i, N) cin >> C[i];
  dp[0][0] = 1;
  for(ll i = 1; i <= N; i++){
    if(C[i-1] == '-'){
      for(ll j = 0; j <= N; j++){
        dp[i][j] += dp[i-1][j];
      }
    }else if(C[i-1] == 'U'){
      for(ll j = 0; j <= N; j++){
        dp[i][j] += dp[i-1][j] * j;
        if(j >= 1) dp[i][j] += dp[i-1][j-1];
        dp[i][j] %= MOD;
      }
    }else{
      for(ll j = 0; j <= N; j++){
        dp[i][j] += dp[i-1][j+1] * (j+1) * (j+1);
        dp[i][j] += dp[i-1][j] * j;
        dp[i][j] %= MOD;
      }
    }
  }
  cout << dp[N][0] << endl;

}



Measured memory_bytes: 3468
N = int(input())
DG = {}
node_ls = []
is_visited = {}
#有効グラフをdictで管理することにする
for _ in range(N):
    tmp = input().split()
    node_id = tmp[0]
    node_ls.append(node_id)
    is_visited[node_id] = False
    adj_num = int(tmp[1])#各頂点の次元が入っている
    if adj_num != 0:
        DG[node_id] = tmp[2:]
    else:
        DG[node_id] = []


d = {}#最初に発見したときの時刻を記録
f = {}#隣接リストを調べ終えたときの完了時刻を記録
t = 1

def dfs(node):
    global t
    #終了条件
    if is_visited[node]:
        return

    is_visited[node] = True
    d[node] = t
    t += 1
    for no in DG[node]:
        dfs(no)
    f[node] = t
    t += 1

for node in node_ls:
    dfs(node)

#print(d,f)
for node in node_ls:
    print(node, d[node], f[node])



Measured memory_bytes: 5716
from collections import deque

K = int(input())

G = [((10*i % K, 0), ((i+1) % K, 1)) for i in range(K)]
s = 1

dist = [10**9] * K
S = deque([s])
T = deque()
dist[s] = 0

d = 0
while S:
    while S:
        v = S.popleft()
        for w, c in G[v]:
            if d+c < dist[w]:
                dist[w] = d+c
                if c:
                    T.append(w)
                else:
                    S.append(w)
    S, T = T, S
    d += 1

print(dist[0]+1)

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

using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define FOR(k,m,n) for(ll (k)=(m);(k)<(n);(k)++)
#define REP(i,n) FOR((i),0,(n))
#define WAITING(str) int str;std::cin>>str;
#define DEBUGING(str) cout<<str<<endl

constexpr int INF = (1 << 30);
constexpr ll INFL = (1ll << 60);
constexpr ll MOD = 1000000007;// 10^9+7

vector<vector<ll>> make_dp(const int H, const int W)
{
	vector<vector<ll>> dp(H, vector<ll>(W, 0));

	// init
	REP(i, 10)dp[0][i%W]++;

	// dp
	REP(i, H - 1)REP(j, W)REP(k, 10)
	{
		dp[i + 1][(j + k) % W] = (dp[i + 1][(j + k) % W] + dp[i][j]) % MOD;
	}
	return dp;
}

ll summerize(const vector<vector<ll>>& dp, const string& K)
{
	const int D = dp[0].size();
	ll res = 0;
	ll odd = 0;
	REP(i, K.size() - 1)
	{
		REP(j, K[i] - '0')
		{
			ll tmp = (odd + j) % D;
			tmp = (D - tmp) % D;
			res = (res + dp[i + 1][tmp]) % MOD;
		}
		odd = (odd + K[i] - '0') % D;
	}
	REP(i, K.back() - '0' + 1)if((odd + i) % D == 0)res++;
	res = (res - 1 + MOD) % MOD;
	return res;
}

//メイン関数
int main()
{
	string K;
	int D;
	cin >> K >> D;

	auto dp = make_dp(K.size(), D);
	reverse(dp.begin(), dp.end());
	cout << summerize(dp, K) << endl;
	cin >> K;

	return 0;
}


Measured memory_bytes: 8448
import java.util.*;
import java.math.*;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long x = sc.nextLong();

    long n = x/500;

    long m = (x-(n*500))/5;

    System.out.println(n*1000+m*5);
  }

}


Measured memory_bytes: 23124
def resolve():
    n = int(input())
    ppp = list(map(int, input().split()))
    ans = 0
    for i in range(1,n-1):
        c = 0
        if ppp[i] > ppp[i-1]:
            c += 1
        if ppp[i] > ppp[i+1]:
            c += 1
        if c == 1:
            ans += 1
    print(ans)
resolve()

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

#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
#define e_b emplace_back
#define all(x) (x).begin(),(x).end()
#define uniq(x) ((x).erase(unique(all(x)),(x).end()))
#define sz(x) ((int)(x).size())

#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)

#ifdef LOCAL//compile with -DLOCAL
#define debug(x) cerr<<"LINE"<<__LINE__<<" : "<<#x<<" = "<<(x)<<endl
#define debug_vec(x) cerr<<"LINE"<<__LINE__<<" : "<<#x<<" = ";\
  rep(i,sz(x)){cerr<<x[i]<<" ";}cerr<<endl
#define debug_mat(x) cerr<<"LINE"<<__LINE__<<" : "<<#x<<" = "<<endl;\
  rep(i,sz(x)){rep(j,sz(x[i])){cerr<<x[i][j]<<" ";}cerr<<endl;}cerr<<endl
#else
#define debug(x) void(0)
#define debug_vec(x) void(0)
#define debug_mat(x) void(0)
#endif

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


int main(){
  ios_base::sync_with_stdio(false);cin.tie(0);
  int N;
  cin >> N;
  vector<ll> T(N);
  rep(i,N)  cin >> T.at(i);

  ll ans=1;
  rep(i,N)  ans=lcm(ans,T.at(i));
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3664
#include <iostream>
#include <algorithm>
#include <cmath>
#include <functional>
#include <string>
#include <vector>
#include <set>
using namespace std;

#define int long long
#define rep(n, i) for (int i = 0; i < n; i++)
#define rep2(m, n, i) for (int i = m; i < n; i++)
#define rep_r(n, i) for (int i = n - 1; i >= 0; i--)

const int INF = 1LL << 60;
const int MOD = 1e9 + 7;

signed main() {
    int n;
    cin >> n;
    if (n == 1) {
        cout << "Hello World" << endl;
        return 0;
    }
    int a, b;
    cin >> a >> b;
    cout << a + b << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a[200001];
int root(int x)
{
  if(a[x]==x) 
    return x;
  else 
    return a[x]=root(a[x]);
}
int unite(int x,int y)
{
  x=root(x);
  y=root(y);
  if(x!=y) 
    a[x]=y;
}

int main()
{
int n,m,x,y,z,ans=0;
cin>>n>>m;
  for(int i=0;i<n;i++) 
    a[i+1]=i+1;
  for(int i=0;i<m;i++) 
    cin>>x>>y>>z,unite(x,y);
  for(int i=0;i<n;i++) 
    if(a[i+1]==i+1) 
      ans++;
cout<<ans<<endl;
return 0;
}

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

using namespace std;

const int maxn=1e5+5;

typedef long long ll;

typedef pair<int,int> P;

P a[maxn];

priority_queue<int> q; 

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n,m;
	cin>>n>>m;
	ll ans=0;
	for(int i=0;i<n;i++){
		cin>>a[i].first>>a[i].second;
	}
	
	sort(a,a+n);
	int j=0;
	for(int i=1;i<=m;i++){
		for(;j<n;j++){
			if(a[j].first>i){
				break;
			}
			q.push(a[j].second);
		}
		if(!q.empty()){
			ans+=q.top();
			q.pop();
		}		
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1660
from sys import *

maxnum = 60000
primes = [True]*maxnum
primes[0] = primes[1] = False
for i in xrange(maxnum):
    if i >= maxnum**0.5 : break
    if not primes[i]: continue
    for j in xrange(i*2,maxnum,i): primes[j] = False

for s in stdin:
    d = int(s)
    for i in reversed(xrange(2,d)):
        if primes[i]: print i,; break
    for i in xrange(d+1,maxnum):
        if primes[i]: print i;break

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

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

const string YES = "Yes";
const string NO = "No";

void solve(std::string S)
{
    if (S[0] == S[1] && S[1] == S[2])
        cout << NO << endl;
    else
        cout << YES << endl;
}

int main()
{
    std::string S;
    std::cin >> S;
    solve(S);
    return 0;
}


Measured memory_bytes: 384
#![allow(unused_imports)]

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

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

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

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

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

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

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

use std::{i32, i64, u32, u64, usize, f64};
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::io::{stdout, Write, BufWriter};
use std::mem::{swap};

fn main() {
    input! {
        n: usize,
        hs: [usize; n],
    }
    let mut ans = 0usize;
    solve(&mut ans, &hs);
    println!("{}", ans);
}

fn solve(ans: &mut usize, hs: &[usize]) {
    if let Some(&m) = hs.iter().min() {
        *ans += m;
        let hss: Vec<_> = hs.iter().map(|h| h - m).collect();
        for hs in hss.split(|&h| h == 0) {
            solve(ans, hs);
        }
    }
}


Measured memory_bytes: 4352
#include <stdio.h>

typedef struct {
	int key, id;
} data;

void merge_sort(data x[], int n)
{
	static data y[301] = {};
	if (n <= 1) return;
	merge_sort(&(x[0]), n/2);
	merge_sort(&(x[n/2]), (n+1)/2);
	
	int i, p, q;
	for (i = 0, p = 0, q = n/2; i < n; i++) {
		if (p >= n/2) y[i] = x[q++];
		else if (q >= n) y[i] = x[p++];
		else y[i] = (x[p].key < x[q].key)? x[p++]: x[q++];
	}
	for (i = 0; i < n; i++) x[i] = y[i];
}

int main()
{
	int i, N, K, H[301];
	data d[301];
	scanf("%d %d", &N, &K);
	for (i = 1, d[0].key = 0; i <= N; i++) {
		scanf("%d", &(H[i]));
		d[i].key = H[i];
	}
	merge_sort(d, N + 1);
	
	int j, k;
	const long long sup = (long long)1 << 60;
	long long dp[2][301][301] = {}, min[2][301];
	for (k = 0; k <= N; k++) {
		if (d[k].key == H[1]) dp[1][0][k] = H[1];
		else dp[1][0][k] = sup;
		dp[1][1][k] = d[k].key;
	}
	for (i = 2; i <= N; i++) {
		for (j = 0; j <= K && j <= i; j++) for (k = 0; k <= N; k++) dp[i%2][j][k] = sup;
		for (j = 0; j <= K && j < i; j++) {
			for (k = 1, min[0][0] = dp[1-i%2][j][0]; k <= N; k++) min[0][k] = (min[0][k-1] < dp[1-i%2][j][k] - d[k].key)? min[0][k-1]: dp[1-i%2][j][k] - d[k].key;
			for (k = N - 1, min[1][N] = dp[1-i%2][j][N]; k >= 0; k--) min[1][k] = (min[1][k+1] < dp[1-i%2][j][k])? min[1][k+1]: dp[1-i%2][j][k];
			for (k = 0; k <= N; k++) {
				if (d[k].key == H[i]) {
					if (dp[i%2][j][k] > min[0][k] + d[k].key) dp[i%2][j][k] = min[0][k] + d[k].key;
					if (dp[i%2][j][k] > min[1][k]) dp[i%2][j][k] = min[1][k];
				}
				if (dp[i%2][j+1][k] > min[0][k] + d[k].key) dp[i%2][j+1][k] = min[0][k] + d[k].key;
				if (dp[i%2][j+1][k] > min[1][k]) dp[i%2][j+1][k] = min[1][k];
			}
		}		
	}
	
	long long ans = sup;
	for (j = 0; j <= K; j++) for (k = 0; k <= N; k++) if (ans > dp[N%2][j][k]) ans = dp[N%2][j][k];
	printf("%lld\n", ans);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 3160
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define REVERSE(a) reverse(a.begin(), a.end())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define int long long
#define INF 1000000000000000000
using namespace std;

#define ANS(f) if(f) cout << "YES" << endl; else cout << "NO" << endl;

typedef vector<int> vec;
typedef vector<vec> mat;
typedef pair<int, int> Pii;

template<typename T>
void readv(vector<T> &a){ REP(i, a.size()) cin >> a[i]; }
void readi(vector<int> &a){ REP(i, a.size()){cin >> a[i]; a[i]--;} }
void debug(mat m){REP(i, m.size()){ REP(j, m[0].size()){ cout << m[i][j] << ","; } cout << endl; }}

signed main(){

    int nCr[51][51];
    REP(i, 51){
        nCr[i][0] = 1;
        nCr[i][i] = 1;
    }
    FOR(i, 1, 51){
        FOR(j, 1, i){
            nCr[i][j] = nCr[i - 1][j - 1] + nCr[i - 1][j];
        }
    }

    int N, A, B; cin >> N >> A >> B;
    vec v(N); readv(v);
    SORT(v);
    REVERSE(v);

    double ave;
    int comb = 0;
    if(v[A - 1] == v[0]){
        ave = (double)v[0];
        int n = A;
        while(n < N && v[n] == v[0]) n++;
        FOR(i, A, min(B, n) + 1) comb += nCr[n][i];
    }else{
        int cnt0 = 0, cnt1 = 0;
        REP(i, N){
            if(v[i] > v[A - 1]) cnt0++;
            if(v[i] == v[A - 1]) cnt1++;
        }
        REP(i, A) ave += (double)v[i];
        ave /= A;
        comb = nCr[cnt1][A - cnt0];
    }
    cout << setprecision(15) << ave << endl;
    cout << comb << endl; 
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <math.h>
#include <sstream>

using namespace std;

int main()
{
  string S;
  cin >> S;
  int n = S.size();

  bool success = true;
  
  if (S[0] != 'A') success = false;
  
  string T = S.substr(2, n - 3);
  int cnt = count(T.begin(), T.end(), 'C');
  if (cnt != 1) success = false;
  auto it = find(T.begin(), T.end(), 'C');
  int Cidx = 2 + distance(T.begin(), it);

  for (int i = 0; i < n; ++i) {
    if ('A' <= S[i] and S[i] <= 'Z') {
      if (i != 0 and i != Cidx) {
	success = false;
      }
    }
  }

  if (success) cout << "AC" << endl;
  else cout << "WA" << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <utility>
#include <set>
#include <map>
#include <vector>
#include <queue>
#define LL long long
#define PII pair<int, int>
#define f first
#define s second
using namespace std;
const int MAXN = 200005;

LL qpow(LL a, LL pw, LL mod) {
    LL res = 1;
    while (pw) {
        if (pw & 1) res = res * a % mod;
        pw >>= 1;
        a = a * a % mod;
    }
    return res;
}

string s;
LL n, mod, pw[MAXN], inv[MAXN], suff[MAXN];

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

    cin >> n >> mod >> s;

    if (mod == 2 || mod == 5) {
        LL ans = 0;
        for (int i = 0; i < n; i++) {
            if ((s[i] - '0') % mod == 0) {
                ans += i + 1;
            }
        }
        cout << ans << '\n';
        return 0;
    }

    pw[0] = inv[0] = 1;
    for (int i = 1; i < MAXN; i++) {
        pw[i] = pw[i - 1] * 10 % mod;
        inv[i] = qpow(pw[i], mod - 2, mod);
    }

    map<LL, int> cnt;
    for (int i = n - 1; i >= 0; i--) {
        suff[i] = (suff[i + 1] + pw[n - i - 1] * (s[i] - '0')) % mod;
        cnt[suff[i]]++;
    }

    LL mulf = 1, addf = 0, ans = 0;
    for (int i = n - 1; i >= 0; i--) {
        LL tgt = (-addf * qpow(mulf, mod - 2, mod) % mod + mod) % mod;
        ans += cnt[tgt];

        cnt[suff[i]]--;
        mulf = mulf * inv[1] % mod;
        addf = ((addf - (s[i] - '0')) * inv[1] % mod + mod) % mod;
    }

    cout << ans << '\n';
}


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

using namespace std;

#define FOR(i, a, b) for (int i=(a);i<(b);++i)
#define ROF(i, a, b) for (int i=(b)-1;i>=(a);--i)
#define REP(i, n) for (int i=0;i<(n);++i)
#define PRE(i, n) for (int i=(n)-1;i>=0;--i)
#define FOREACH(a, v) for(auto a : v)

#define ALL(a) (a).begin(),(a).end()
#define DEBUG(x) cerr<<#x<<": "<<x<<endl
#define INFILE() freopen("in0.txt","r",stdin)
#define OUTFILE()freopen("out0.txt","w",stdout)

#define INF INT_MAX/3
#define eps 1e-14

#define ll long long
using vint = vector<int>;

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

int main() {
    ll N, M;
    cin >> N >> M;
    if (N == 1 && M == 1) {
        cout << 1 << endl;
    } else if (N == 1) {
        cout << M - 2 << endl;
    } else if (M == 1) {
        cout << N - 2 << endl;
    } else {
        cout << (N - 2) * (M - 2) << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
int main()
{
    long long a,b;
    char c;
    scanf("%lld",&a);
    getchar();
    scanf("%c",&c);
    getchar();
    scanf("%lld",&b);
    if(c=='+')
        printf("%lld\n",a+b);
    else
        printf("%lld\n",a-b);
    return 0;
}


Measured memory_bytes: 128
package main

import "fmt"

func main() {
	var n, m int
	_, _ = fmt.Scan(&n)
	_, _ = fmt.Scan(&m)
	okqs := make([]bool, n)
	ngqs := make([]int, n)
	for i := 0; i < m; i++ {
		var p int
		_, _ = fmt.Scan(&p)
		p--
		var s string
		_, _ = fmt.Scan(&s)
		if !okqs[p] {
			if s == "AC" {
				okqs[p] = true
			} else {
				ngqs[p]++
			}
		}
	}
	ok := 0
	ng := 0
	for i, v := range okqs {
		if v {
			ok++
			ng += ngqs[i]
		}
	}
	res := fmt.Sprintf("%d %d", ok, ng)
	fmt.Println(res)
}


Measured memory_bytes: 5504
/*

    author : s@if

*/

#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define 		NIL 			-1
#define		 	fi	 		    first
#define 		sec 			second
#define 		MAX 			INT_MAX
#define			INF 			1e9
#define 		ll 			    long long
#define 		PI 			    acos(-1.0)
#define			MOD 			1000000007
#define 		PLL 			pair<ll,ll>
#define 		PII			    pair<int,int>
#define 		ull 			unsigned long long
#define 		For(i,a,b) 		for(int i=a;i<=(int)b;i++)
typedef tree<int, null_type, less<int>, rb_tree_tag,
            tree_order_statistics_node_update> new_data_set;

//*find_by_order(k)  gives the kth element;
//order_of_key(item)   gives the index(number of element strictly less than item) of item;


inline int in() {int x; scanf("%d", &x); return x; }
bool Check(int N , int pos)	{	return (bool) (N & (1<<pos));}
int Set(int N, int pos) {	return N = N | (1<<pos);}

int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};    // King's move
int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};
int hx[]={-2,-2,-1,+1,+2,+2,-1,+1};    // Knight's move
int hy[]={+1,-1,+2,+2,-1,+1,-2,-2};
int dx[]={+1,-1,+0,+0};
int dy[]={+0,+0,+1,-1};

const int MAXN = (int)2e5+9;


int main()
{
/*	freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);  */

    int i,j,k,l,m,n,p,q,x,y,u,v,r,tc,t;

    cin>>n;
    
    cout<<n/2+n%2<<endl;

    return 0;
}

// read the question correctly (is y a vowel? what are the exact constraints?)
// look out for SPECIAL CASES (n=1?) and overflow (ll vs int?)


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

int main() {
  int n;
  cin >> n;
  vector<int> p(n);
  rep(i, n) { cin >> p[i]; }

  int result = 0;
  int m = n;
  rep(i, n) {
    m = min(m, p[i]);
    if (m == p[i]) {
      result++;
    }
  }
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>

int main(void){

  int m,d;
  scanf("%d %d", &m, &d);
  int count = 0;
  for (int i = 4; i <= m; i++) {
    for (int j = 2; j <= d/10; j++) {
      if (i%j == 0 && j*10+(i/j) <= d && (i/j) >= 2 && (i/j) <= 9) {
        count++;
      }
    }
  }
  printf("%d\n", count);

  return 0;
}

Measured memory_bytes: 128
class _Node {
  constructor(key, left = null, right = null) {
    this.key = key;
    this.left = left;
    this.right = right;
  }
}

class BinaryTree {
  constructor() {
    this.root = null;
  }

  static get Node() { return _Node; }

  insert(key) {
    this.root = new BinaryTree.Node(key);
    this.insert = (key) => {
      let x = this.root, y;
      let newNode = new BinaryTree.Node(key);
      while (x !== null) {
        y = x;
        x = x[key < x.key ? 'left' : 'right'];
      }
      y[key < y.key ? 'left' : 'right'] = newNode;
    }
  }

  printByIneorder() {
    let str = '';
    const innerFunc = (n) => {
      if (n === null) return;
      innerFunc(n.left);
      str += ` ${n.key}`;
      innerFunc(n.right);
    }
    innerFunc(this.root);
    console.log(str);
  }

  printByPreorder() {
    let str = '';
    const innerFunc = (n) => {
      if (n === null) return;
      str += ` ${n.key}`;
      innerFunc(n.left);
      innerFunc(n.right);
    }
    innerFunc(this.root);
    console.log(str);
  }

  print() {
    this.printByIneorder();
    this.printByPreorder();
  }
}

(function main(){
  const lines = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n');
  const n = Number(lines.shift());

  const tree = new BinaryTree();
  lines.forEach(function(cmd) {
    switch(cmd.charAt(0)) {
    case 'i': tree.insert(Number(cmd.split(' ')[1])); break;
    default: tree.print();
    }
  });
})();



Measured memory_bytes: 198344
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pa = pair<ll, ll>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
const ll MOD = 1e9 + 7;
const ll INF = 1e14;
const long double EPS = 1e-11;

#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (int i = (l); i < (r); i++)
#define reper(i, l, r) for (int i = (r)-1; i >= (l); i--)

void init() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
}
//--------------------------------------------------------------------------------//

int main() {
    init();
    ll N;
    cin >> N;
    vector<string> s(N);
    vl t(N);
    rep(i, N) {
        cin >> s[i] >> t[i];
    }

    string x;
    cin >> x;
    ll index;
    rep(i, N) {
        if (s[i] == x) {
            index = i + 1;
        }
    }
    ll ans = 0;
    repe(i, index, N) ans += t[i];
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[9]={1,0,-1,0,1,1,-1,-1,0};
const ll dx[9]={0,-1,0,1,1,-1,1,-1,0};
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;
}

const int mod = MOD9;
const int max_n = 200005;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
 
  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
}comb(max_n);
int main(){
    ll n,s;cin >> n >>s;
    vl a(n);rep(i,n)cin >> a[i];
    vector<vector<mint>> dp(n+1,vector<mint>(s+1,0));
    dp[0][0]=1;
    rep(i,n){
        rep(j,s+1){
            if(j+a[i]<=s)dp[i+1][j+a[i]]+=dp[i][j];
            dp[i+1][j]+=dp[i][j];
        }
        dp[i+1][0]+=1;   
    }
    mint ans=0;
    rep(i,n+1){
        ans+=dp[i][s];
    }
    cout << ans <<endl;
}   

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

int main()
{
    ll h, w;
    cin >> h >> w;

    vector<string> s(h);
    rep(i, h) {
        cin >> s[i];
    }

    ll x[] = {-1, 0, 1, -1, 1, -1, 0, 1 };
    ll y[] = {1, 1, 1, 0, 0, -1, -1, -1 };

    rep(i, h){
        rep(j, w){
            if (s[i][j] == '.'){
                ll cnt = 0;
                rep(ii, 8){
                    ll xi = j + x[ii];
                    ll yi = i + y[ii];
                    if ( xi < 0 || xi >= w || yi < 0 || yi >= h){
                        continue;
                    }
                    if(s[yi][xi] == '#'){
                        cnt++;
                    }
                }
                s[i][j] = to_string(cnt)[0];
            }
        }
    }

    rep(i, h){
        cout << s[i] << endl;
    }


    return 0;
}


Measured memory_bytes: 3664
#include <bits/stdc++.h>    
using namespace std;
 
#define CIN1(a) long long a;cin >> a;
#define CIN2(a,b) long long a,b;cin >> a >> b;
#define CIN3(a,b,c) long long a,b,c;cin >> a >> b >> c;
#define rep(i,n) for(int i=0,i##_len=(n); i<i##_len; ++i)

long long dfs(long long,int);
int n;
int main(){
    cin >> n;
    cout << dfs(0,0) << endl;
}

long long dfs(long long x,int check){
    if (x>n) return 0;
    else{
        long long tmp = (check==7)?1:0;
        return tmp+
               dfs((x<<3)+(x<<1)+3,check|1)+ 
               dfs((x<<3)+(x<<1)+5,check|1<<1)+ 
               dfs((x<<3)+(x<<1)+7,check|1<<2);
    }
}

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

signed main(void)
{
	string s[3], ans;
	int d = 'a' - 'A';
	rep(i, 3)
	{
		cin >> s[i];
		ans += s[i][0] - d;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define bit(n) (1<<(n))
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template < typename T > string tost( const T& n ) { ostringstream stm; stm << n; return stm.str();}
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;}
int const INF = 1001001001;


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

string S;
cin >> S;
S = "0" + S;
int N = S.size();

int dp[N+5][2];

dp[0][0] = 0;
dp[0][1] = 1;

rep(i,N-1) {
    int D = S[i+1] - '0';
    dp[i+1][0] = min(dp[i][0] + D, dp[i][1] + 10-D);
    dp[i+1][1] = min(dp[i][0] + D+1, dp[i][1] + 9-D);
}
cout << dp[N-1][0] << endl;
return 0;
}

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

int main() {
    string s;
    cin >> s;
    ll a = s[0] - '0';
    ll b = s[1] - '0';
    ll c = s[2] - '0';
    ll d = s[3] - '0';
    if (a + b + c + d == 7) cout << a << "+" << b << "+" << c << "+" << d << "=" << "7";
    else if (a + b + c - d == 7) cout << a << "+" << b << "+" << c << "-" << d << "=" << "7";
    else if (a + b - c + d == 7) cout << a << "+" << b << "-" << c << "+" << d << "=" << "7";
    else if (a + b - c - d == 7) cout << a << "+" << b << "-" << c << "-" << d << "=" << "7";
    else if (a - b + c + d == 7) cout << a << "-" << b << "+" << c << "+" << d << "=" << "7";
    else if (a - b + c - d == 7) cout << a << "-" << b << "+" << c << "-" << d << "=" << "7";
    else if (a - b - c + d == 7) cout << a << "-" << b << "-" << c << "+" << d << "=" << "7";
    else if (a - b - c - d == 7) cout << a << "-" << b << "-" << c << "-" << d << "=" << "7";
}


Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#include<string>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
const int MAXN= (int)1e5+10;
const ll MOD = (ll)1e9+7;
ll fac[MAXN]; 
ll power(ll a,ll b){
	ll re=1;
	while(b){
		if(b&1)re=re*a%MOD;
		a=a*a%MOD;
		b>>=1;
	}
	return re;
}
ll C(int m,int n){
	return fac[n]*power(fac[m],MOD-2)%MOD*power(fac[n-m],MOD-2)%MOD;
}
ll ans[MAXN];
int a[MAXN];
int mark[MAXN];
int main()
{	
	int n;
	scanf("%d",&n);
	fac[0]=1;
	for(int i=1;i<=n+1;i++)fac[i]=fac[i-1]*i%MOD;
	//printf("%lld\n",C(2,4));
	int x1,x2;
	for(int i=1;i<=n+1;i++){
		scanf("%d",&a[i]);
		if(mark[a[i]]!=0){
			x1=mark[a[i]];
			x2=i;
		}
		mark[a[i]]=i;
		ans[i]=C(i,n+1);
	}
	int num=x1-1+(n-x2+1);
	for(int i=0;i<=num;i++){
		ans[i+1]-=C(i,num);
		ans[i+1]=((ans[i+1]%MOD)+MOD)%MOD;
	}
	for(int i=1;i<=n+1;i++)printf("%lld\n",ans[i]);
	return 0;
}

Measured memory_bytes: 3584
package main
 
import (
	"fmt"

)
 
func main() {
	var n int
  	fmt.Scan(&n)
	var x float64
  	var u string
  	
	sum := 0.0
	for i := 0; i < n; i++ {
	    fmt.Scan(&x,&u)
	    if u == "JPY" {
	    	sum += x
	    } else {
	    	sum += x * 380000
	    }
	}
	fmt.Println(sum)
}

Measured memory_bytes: 512
def gcd(m, n):
    while n:  # nが0になるまで繰り返す
        m, n = n, m % n
    return m


n = int(input())  # n体のモンスター
a = list(map(int, input().split()))  # それぞれの体力

g = gcd(a[0], a[1])  # 最大公約数を求める
for i in range(2, n):
    g = gcd(g, a[i])  # 最初のgは1つ目と2つ目の要素の最大公約数がすでに入っている

print(g)


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

int main() {
	ll n;
	cin>>n;
	
	if(n%2==1){
		cout<<0<<endl;
	}else{
		ll count=0;
		n=n/10;
		count+=n;
		while(1){
			n=n/5;
			if(n==0)break;
			count+=n;
			
		}
		cout<<count<<endl;
	}
}


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <string>
using namespace std;
typedef long long ll;
#define rep(i,s,n)for(ll i=s;i<n;i++)
#define repe(i,s,n)for(ll i=s;i<=n;i++)
#define rep_r(i,s,n)for(ll i=n-1;i>=s;i--)
#define repe_r(i,s,n)for(ll i=s;i<=n;i++)
static const ll MOD = 1e9 + 7;
static const ll MAX_L = (ll)1 << 62;

ll a[100001] = {};
ll c[100][100] = {};

int main() {
	ll h, w, n; cin >> h >> w >> n;
	rep(i, 0, n)cin >> a[i];

	bool r = true;
	ll H = 0, W = 0;
	rep(i, 0, n) {
		rep(j, 0, a[i]) {
			c[H][W] = i + 1;
			if (r) {
				W++;
			}
			else {
				W--;
			}

			if (W >= w) {
				r = false;;
				H++;
				W--;
			}
			else if (W < 0) {
				r = true;
				H++;
				W++;
			}
		}
	}

	rep(i, 0, h) {
		rep(j, 0, w) {
			cout << c[i][j];
			if (j != w - 1)cout << " ";
			else cout << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 384
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

int n;
vector <int> v[100000];

vector <int> calc(int x) {
    int p = -1, num = 1, i;
    vector <int> w;
    
    while (1) {
        int nx = -1, next = num++;
        
        for (i = 0; i < v[x].size(); i++) {
            int y = v[x][i];
            
            if (y == p) continue;
            
            if (v[y].size() == 1) {
                w.push_back(num++);
            } else {
                nx = y;
            }
        }
        
        w.push_back(next);
        
        if (nx == -1) {
            swap(w[n - 2], w[n - 1]);
            break;
        } else {
            p = x;
            x = nx;
        }
    }
    
    return w;
}

int main() {
    int p = -1, q = -1, i, j;
    vector <int> ans1, ans2;
    
    scanf("%d", &n);
    
    for (i = 0; i < n - 1; i++) {
        int x, y;
        
        scanf("%d %d", &x, &y);
        
        x--;
        y--;
        
        v[x].push_back(y);
        v[y].push_back(x);
    }
    
    if (n == 2) {
        puts("1 2");
        return 0;
    }
    
    for (i = 0; i < n; i++) {
        int c = 0, z;
        
        if (v[i].size() == 1) continue;
        
        for (j = 0; j < v[i].size(); j++) {
            int x = v[i][j];
            
            if (v[x].size() == 1) {
                z = x;
            } else {
                c++;
            }
        }
        
        if (c > 2) {
            puts("-1");
            return 0;
        }
        
        if (c <= 1) {
            if (p == -1) {
                p = z;
            } else {
                q = z;
            }
        }
    }
    
    if (q == -1) q = p;
    
    ans1 = calc(p);
    ans2 = calc(q);
    
    for (i = 0; i < n; i++) {
        if (ans1[i] != ans2[i]) {
            if (ans1[i] > ans2[i]) swap(ans1, ans2);
            break;
        }
    }
    
    for (i = 0; i < n; i++) {
        if (i > 0) putchar(' ');
        printf("%d", ans1[i]);
    }
    puts("");
    
    return 0;
}


Measured memory_bytes: 7544
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <cassert>
#include <memory>
#include <stack>
#include <set>
#include <map>

#define INF 1000000000
#define MOD 1000000007
typedef long long ll;
typedef unsigned long long ull;
using namespace std;

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

  int a,b,c; cin>>a>>b>>c;
  int M = max(a, max(b,c));
  int sum = a + b + c;

  int ans;
  if((M & 1) == (sum & 1)) {
    ans = (3 * M - sum) / 2;
  } else {
    ans = (3 * (M + 1) - sum) / 2;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_map>
#include<fstream>
#include<list>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<double,ll> pdl;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;

vector<ll> a;
vector<ll> A;
ll n,x;

ll count(ll i){
    ll count=A[i];
    ll r=1;
    for(ll t=0;t<n;t++){
        if(t%(i+1)==0){r++;}
        count+=(2*r-1)*a[t];
    }
    return count+x*n;
}



int main(){
    cin>>n>>x;
    a.resize(n);
    for(int i=0;i<n;i++){cin>>a[n-1-i];}
    A.resize(n);
    A[0]=2*a[0]+x;
    for(ll i=1;i<n;i++){
        A[i]=2*a[i]+A[i-1]+x;
    }
    ll l=0,r=n;
    while(r-l>10){
        ll m=l+(r-l)/2;
        ll d=m+1;
        if(count(m)>count(d)){l=d;}
        else{r=d;}
    }
    ll ans=E;
    for(ll i=l;i<r && i<n;i++){
        ans=min(ans,count(i));
    }
    cout<<ans<<endl;
    
    
    return 0;
}


Measured memory_bytes: 3328