akhauriyash/Code-Regression huggingface dataset:
#define _DEBUG
#include "bits/stdc++.h"
#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0,a1,a2,a3,a4,x,...) x
#define debug_1(x1) cout<<#x1<<": "<<x1<<endl
#define debug_2(x1,x2) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<endl
#define debug_3(x1,x2,x3) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<endl
#define debug_4(x1,x2,x3,x4) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<endl
#define debug_5(x1,x2,x3,x4,x5) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<", "#x5<<": "<<x5<<endl
#ifdef _DEBUG
#define debug(...) CHOOSE((__VA_ARGS__,debug_5,debug_4,debug_3,debug_2,debug_1,~))(__VA_ARGS__)
#else
#define debug(...)
#endif
#define rep(index,num) for(int index=0;index<(int)num;index++)
#define rep1(index,num) for(int index=1;index<=(int)num;index++)
#define brep(index,num) for(int index=(int)num-1;index>=0;index--)
#define brep1(index,num) for(int index=(int)num;index>0;index--)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=(ll)1e+18+1;
int INF=1e+9+1;
int main(){
	int M,N,A[2001];
	scan(N>>M);
	int sum=0;
	rep(i,N) scan(A[i]),sum+=A[i];
	int ans=0;
	rep(i,N) if(A[i]*4*M>=sum) ans++;
	if(ans>=M) prin("Yes");
	else prin("No");
	return 0;
}


Measured memory_bytes: 3548
#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <list>
#include <stack>
#include <string>
#include <functional>
#include <numeric>
#define _USE_MATH_DEFINES
#include <math.h>
#include <iomanip>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
using namespace std;
#define INT_MAX 2147483647
#define INT_MIN -2147483648
#define INF 100000000
#define _INF -100000000
#define INFLL (long long)1e14
#define _INFLL (long long)-1e14
#define Loop(i, n) for(int i = 0; i < (int)n; i++)
#define Loop1(i, n) for(int i = 1; i <= (int)n; i++)
#define Loopr(i, n) for(int i = (int)n - 1; i >= 0; i--)
#define Loopr1(i, n) for(int i = (int)n; i >= 1; i--)
#define bitmanip(m,val) static_cast<bitset<(int)m>>(val)
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef pair<int,int> P;

struct node {
	bool done;
	vi to, dist;
	int id, from;
	ll d;
	int depth;
	bool operator<(const node & another) const {
		return !(d != another.d ? d < another.d : id < another.id);
	}
};

class Prim {
public:
	vector<node> nodes;
	int n;
	Prim(vector<node> A) {
		n = A.size();
		nodes = A;
		priority_queue<node> pq;
		nodes[0].d = 0;
		pq.push(nodes[0]);
		while (pq.size()) {
			node focus = pq.top(); pq.pop();
			if (nodes[focus.id].done) continue;
			Loop(i, focus.to.size()) {
				int b = focus.to[i];
				if (!nodes[b].done && focus.dist[i] < nodes[b].d) {
					nodes[b].d = focus.dist[i];
					nodes[b].from = focus.id;
					nodes[b].depth = focus.depth + 1;
					pq.push(nodes[focus.to[i]]);
				}
			}
			nodes[focus.id].done = true;
		}
		return;
	}
	//sとtをつなぐパスの中で最もコストの大きい辺のコストを返す
	ll max_path_between(int s, int t) {
		ll ret = 0;
		while (nodes[s].depth > nodes[t].depth) {
			ret = max(ret, nodes[s].d);
			s = nodes[s].from;
		}
		while (nodes[s].depth < nodes[t].depth) {
			ret = max(ret, nodes[t].d);
			t = nodes[t].from;
		}
		while (s != t) {
			ret = max(ret, max(nodes[s].d, nodes[t].d));
			s = nodes[s].from;
			t = nodes[t].from;
		}
		return ret;
	}
};

int main() {
	int n, m; cin >> n >> m;
	vector<node> nodes(n);
	Loop(i, n) nodes[i] = { false,{},{}, i, -1, INFLL, 0 };
	Loop(i, m) {
		int s, t, d; cin >> s >> t >> d;
		s--; t--;
		nodes[s].to.push_back(t);
		nodes[s].dist.push_back(d);
		nodes[t].to.push_back(s);
		nodes[t].dist.push_back(d);
	}
	Prim prim(nodes);
	ll sum = 0;
	Loop(i, n) sum += prim.nodes[i].d;
	int q; cin >> q;
	Loop(i, q) {
		int s, t; cin >> s >> t;
		s--; t--;
		cout << sum - prim.max_path_between(s, t) << endl;
	}
	return 0;
}

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

void SOLVE(int* dice, int u, int f) {
    int around[4];
    switch(u) {
        case 0 : {
            around[0] = 1;   around[1] = 2;   around[2] = 4;   around[3] = 3;
            break;
        }
        case 1 : {
            around[0] = 0;   around[1] = 3;   around[2] = 5;   around[3] = 2;
            break;
        }
        case 2 : {
            around[0] = 0;   around[1] = 1;   around[2] = 5;   around[3] = 4;
            break;
        }
        case 3 : {
            around[0] = 0;   around[1] = 4;   around[2] = 5;   around[3] = 1;
            break;
        }
        case 4 : {
            around[0] = 0;   around[1] = 2;   around[2] = 5;   around[3] = 3;
            break;
        }
        case 5 : {
            around[0] = 1;   around[1] = 3;   around[2] = 4;   around[3] = 2;
            break;
        }
    }
    int index = 0;
    while(dice[f] != dice[around[index]])   ++index;
    index += 1;
    if(index < 4)   cout << dice[around[index]] << endl;
    else            cout << dice[around[0]] << endl;
}

int main(void) {
    int dice [6];
    int n;
    int u, f;
    int u_index, f_index;
    
    for(int i = 0; i < 6; ++i) {
        cin >> dice[i];
    }
    cin >> n;
    
    for(int i = 0; i < n; ++i) {
        cin >> u >> f;
        u_index = 0;
        f_index = 0;
        while(dice[u_index] != u)   ++u_index;
        while(dice[f_index] != f)   ++f_index;
        SOLVE(dice, u_index, f_index);
    }
    return 0;
}



Measured memory_bytes: 3108
using System;
using System.Collections.Generic;
using System.Linq;

public class Solution
{
    public static void Main()
    {
        var max = (long)1e7 + 1;
        var N = long.Parse(Console.ReadLine());
        var trinum = new long[max];
        for (int i = 1; i < trinum.Length; i++)
        {
            trinum[i] = trinum[i - 1] + i;
        }

        long sum = 0;
        for (long i = 1; i <= N; i++)
        {
            var r = N / i;
            sum += i * trinum[r];
        }

        Console.WriteLine(sum);
    }
}

Measured memory_bytes: 105656
#include <stdlib.h>
#include <cmath>
#include <cstdio>
#include <cstdint>
#include <string>
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
using namespace std;
using ll = long long;

int main(){
  ll N;
  cin >> N;

  ll ans=1000000000000;
  for(ll i=1;i<=sqrt(N);++i){
    if(N%i==0){
      ans=min(ans,i+N/i-2);
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3688
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <cstring>
#include <utility>
#include <vector>
#include <complex>
#include <valarray>
#include <fstream>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <random>

#define _overload(a, b, c, d, ...) d
#define _rep1(X, A, Y) for (int (X) = (A);(X) <= (Y);++(X))
#define _rep2(X, Y) for (int (X) = 0;(X) < (Y);++(X))
#define rep(...) _overload(__VA_ARGS__, _rep1, _rep2)(__VA_ARGS__)
#define rrep(X,Y) for (int (X) = Y-1;(X) >= 0;--(X))
#define all(X) (X).begin(),(X).end()
#define len(X) ((int)(X).size())
#define mod(n, m) (((n)%(m)+(m))%m)
#define fi first
#define sc second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
const int INFINT = 1 << 30;                          // 1.07x10^ 9
const ll INFLL = 1LL << 60;                          // 1.15x10^18
const double EPS = 1e-10;
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

const int MAX_N = 100000, MAX_M = 100000;
int N, M;
int x[MAX_M], y[MAX_M];

struct edge { int to, cost; };
const int MAX_V = MAX_N;

// Vの初期化を忘れない。
int V;
vector<edge> G[MAX_V];
int numOfIn[MAX_V];
int label[MAX_V];

bool dag() {
    for (int v = 0; v < V; ++v) {
        for (int i = 0; i < G[v].size(); ++i) {
            int u = G[v][i].to;
            ++numOfIn[u];
        }
    }
    memset(label, -1, sizeof(label));
    queue<int> que;
    for (int v = 0; v < V; ++v) {
        if (numOfIn[v] == 0) que.push(v);
    }

    int labelCount = 0;
    while (!que.empty()) {
        int v = que.front(); que.pop();
        label[v] = labelCount++;
        for (int i = 0; i < G[v].size(); ++i) {
            int u = G[v][i].to;
            --numOfIn[u];
            if (numOfIn[u] == 0) que.push(u);
        }
    }

    if (labelCount == V) return true;
    else return false;
}


int dp[MAX_N];

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

  cin >> N >> M;
  rep(i, M) cin >> x[i] >> y[i];
  V = N;

  rep(i, M) G[--x[i]].push_back((edge){--y[i], 1});

  dag();

  vector<Pii> vp;
  rep(i, N) vp.push_back(Pii(label[i], i));
  sort(all(vp));


  for (int i = 0; i < N; ++i) {
      int v = vp[i].sc;
      for  (int j = 0; j < G[v].size(); ++j) {
          int u = G[v][j].to;
          dp[label[u]] = max(dp[label[u]], dp[i] + 1);
      }
  }

  cout << dp[N-1] << endl;

  return 0;
}


Measured memory_bytes: 8568
#include<bits/stdc++.h>
using namespace std;
    static const double pi = 3.141592653589793;
 typedef pair<int64_t,int64_t> P;
#define rep(i, n) for (int i = 0; i < (n); i++)
 #define all(v) (v).begin(),(v).end()
 using ll = long long;

int main(){
ll N;
  double u;
  cin>>N;
  priority_queue<double, vector<double>, greater<double>>nabe;
  rep(i,N) {
    double o;
    cin>>o; 
    nabe.push(o);
  }  
  while(nabe.size()!=1)
  {
  double k,r;
    k=nabe.top();
nabe.pop();  
r=nabe.top();
    nabe.pop();
     u=(k+r)/2;
    nabe.push(u);
  }
  
  cout<<u;
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for(int i = 1, i##_len = (n); i < i##_len; ++i)
#define ALL(x) (x).begin(), (x).end()
#define PRINT(A) std::cout << (#A) << ":" << (A) << std::endl;

typedef long long int ll;
const int MOD = 1e9 + 7;
const int INF = 1e9;

using namespace std;

int main() {
  int N, C;
  cin >> N >> C;
  int D[C][C];
  REP(i, C) REP(j, C) cin >> D[i][j];
  int p[3][C] = {0};
  REP(i, 3) REP(j, C) p[i][j] = 0;
  REP(i, N) REP(j, N) {
    int c;
    cin >> c;
    c--;
    p[(i + j) % 3][c]++;
  }

  int ans = INF;
  REP(i, C) {
    REP(j, C) {
      if(i == j) continue;
      REP(k, C) {
        if(i == k || j == k) continue;
        int cc = 0;
        REP(l, C) cc += p[0][l] * D[l][i];
        REP(l, C) cc += p[1][l] * D[l][j];
        REP(l, C) cc += p[2][l] * D[l][k];
        ans = min(cc, ans);
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func Scan() string {
	sc.Scan()
	return sc.Text()
}

func iScan() int {
	n, _ := strconv.Atoi(Scan())
	return n
}

func fScan() float64 {
	n, _ := strconv.ParseFloat(Scan(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func SScan(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scan()
	}
	return a
}
func iSScan(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = iScan()
	}
	return a
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func sum(a []int) int {
	x := 0
	for _, v := range a {
		x += v
	}
	return x
}

var mod int = 1000000007

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	a, _ := iScan(), iScan()
	s := Scan()
	_, p := strconv.Atoi(s[:a])
	_, q := strconv.Atoi(s[a+1:])
	if p == nil && q == nil && string(s[a]) == "-" {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 1772
#include<bits/stdc++.h>
#define F first
#define S second
#define int long long
#define double long double
using namespace std;
typedef pair<int,int> P;
typedef pair<int,P> iP;
typedef pair<P,int> Pi;
typedef pair<P,P> PP;
double eps=1e-8;
int mod=1e9+7;
int inf=1LL<<55;

priority_queue<P,vector<P>,greater<P> > pq;

template <typename T>
int Count(const vector<T> &v, T l,T r){
  //counting [l,r]
  auto L = lower_bound(v.begin(), v.end(), l );
  auto R = upper_bound(v.begin(), v.end(), r );
  // [l,r) change upper -> lower
  return R-L;
}

signed main(){
  string s;
  cin>>s;
  if(s=="zyxwvutsrqponmlkjihgfedcba"){cout<<-1<<endl;return 0;}
  if(s.size()<26){
    bool used[256]={};
    char c;
    for(int i=0;i<s.size();i++)used[s[i]]=1;
    for(int i='a';i<='z';i++)
      if(!used[i]){
	c=i;
	break;
      }
    s+=c;

    cout<<s<<endl;
    return 0;
  }
  set<char> ss;
  int p=s.size()-1;
  bool f=1;
  while(f){
    for(int i=s[p]+1;f&&i<='z';i++)
      if(ss.count(i)){
	s=s.substr(0,p+1),s[p]=i;
	f=0;
      }
    ss.insert(s[p]);
    p--;
  }
  cout<<s<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll, ll> Pll;
#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
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; }

const int MOD = 1000000007;
const int INF = 1e9;

const int mod = 1000000007;
const int inf = 1e9;
#define PI acos(-1);
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};


int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    if(a[0]!=0) {
        cout << -1 << endl;
        return 0;
    }
    for(int i = 0; i < n-1; i++) {
        if(a[i+1] > a[i] + 1) {
            cout << -1 << endl;
            return 0;
        }
    }
    ll ans = 0;
    for(int i = 1; i < n; i++) {
        if(a[i] - a[i-1] == 1) ans++;
        else ans += a[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

import static java.lang.System.exit;

public class Main {

    public static void main(String[] args) {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        br.lines().forEach(s -> {
            List<String> list = Arrays.stream(s.split(" "))
                    .collect(Collectors.toList());

            int a = Integer.parseInt(list.get(0));
            String op = list.get(1);
            int b = Integer.parseInt(list.get(2));

            switch (op) {
                case "+":
                    System.out.println(a + b);
                    break;
                case "-":
                    System.out.println(a - b);
                    break;
                case "*":
                    System.out.println(a * b);
                    break;
                case "/":
                    System.out.println(a / b);
                    break;
                case "?":
                    exit(0);
                default:
                    break;
            }
        });
    }
}

Measured memory_bytes: 31044
#define LL long long
#include<cstdio>
using namespace std;
const LL N=1e18;
LL n,ans;
int main()
{
	scanf("%lld",&n);
	if (n%2)
	{
		puts("0");
		return 0;
	}
	for (LL i=10;i<=n&&i<=N;i*=5)
		ans+=n/i;
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<unordered_map>
using namespace std;
typedef long long ll;
int main() {
	string a[3];
	int b[3] = { 0,0,0 }, t = 0;
	cin >> a[0] >> a[1] >> a[2];
	while (9999999999999999999) {
		if (b[t] == a[t].size()) {
			cout << (char)(int)('A' + t) << endl;
			break;
		}
		int t2 = t;
		t = (int)a[t][b[t]] - 'a';
		b[t2]++;
	}
}

Measured memory_bytes: 256
main = input()
word = input()
temp = main
resultArray = []
final = len(word)
for j in range(len(main) - (len(word) - 1)):
    result = ''
    for i in range(len(word)):
        if main[j + i] == word[i]:
            result += '1'
        else:
            result += '0'
    resultArray.append(result)
for i in resultArray:
    if i.count('0') < final:
        final = i.count('0')
print(final)

Measured memory_bytes: 9228
#include <cstdio>
#include <cstdint>
#include <vector>
#include <algorithm>
#include <utility>
#include <numeric>
#include <set>
#include <map>
#include <string>
#include <iostream>
#include <cmath>

using namespace std;
typedef long long ll;
#define inf 10e17
#define rep(i,n) for(long long i=0; i<n; i++)
#define repr(i,n,m) for(long long i=m; i<n; i++)
#define mod 1000000007
#define sorti(x) sort(x.begin(), x.end())
#define sortd(x) sort(x.begin(), x.end(), std::greater<long long>())
#define debug(x) std::cerr << (x) << std::endl;
#define roll(x) for (auto&& itr : x) { cerr << (itr) << " "; }

template <class T> inline void chmax(T &ans, T t) { if (t > ans) ans = t;}
template <class T> inline void chmin(T &ans, T t) { if (t < ans) ans = t;}

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> c(m);
  rep(i, m) cin >> c[i];
  vector<vector<ll>> dp(m+10, vector<ll>(n+10, inf));
  dp[0][0] = 0;

  repr(i, m+1, 1) rep(j, n+10) {
    chmin(dp[i][j], dp[i - 1][j]);
    if (j + c[i - 1] <= n) {
      chmin(dp[i][j + c[i - 1]], dp[i][j] + 1);
    }
  }

  cout << dp[m][n] << endl;
}


Measured memory_bytes: 14952
#include <stdio.h>
int main(void){
	int a,i,c=0;
	scanf("%d",&a);
	for(i=1;i<10;i++){
		if((a%i==0)&&((a/i)<10))c=1;
	}
	c==1?printf("Yes"):printf("No");
	return 0;
}

Measured memory_bytes: 128
N = int(input())
A1 = [int(x) for x in input().split()]
A2 = [int(x) for x in input().split()]

A2total = sum(A2)
A1total = A1[0]
ans = A1total + A2total
total = ans
for i in range(1, N):
  total = total + A1[i] - A2[i - 1]
  ans = max(ans, total)
  
print(ans)

Measured memory_bytes: 38384
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define mod 1000000007 //1e9+7
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 1001

bool calc(){
  int n,m,a,h,p,q;
  pair<int,pair<int,int> > v[SIZE]; 

  scanf("%d%d%d",&n,&m,&a);

  if(n==0) return false;

  for(int i=0;i<m;i++){
    scanf("%d%d%d",&h,&p,&q);
    v[i] = {-h,{p,q} };
  }

  sort(v,v+m);

  for(int i=0;i<m;i++){
    if(a==v[i].second.first) a = v[i].second.second;
    else if(a==v[i].second.second) a = v[i].second.first;
  }
  
  printf("%d\n",a);
  
  return true;
}

int main(){
    
  while(calc());
  
  return 0;
}

Measured memory_bytes: 3240
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <typeinfo>
#include <utility>
#include <vector>
#include <array>
#include <chrono>
#include <random>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#define INIT std::ios::sync_with_stdio(false);std::cin.tie(0);
#define VAR(type, ...)type __VA_ARGS__;Scan(__VA_ARGS__);
template<typename T> void Scan(T& t) { std::cin >> t; }
template<typename First, typename...Rest>void Scan(First& first, Rest&...rest) { std::cin >> first; Scan(rest...); }
#define OUT(d) std::cout<<d;
#define FOUT(n, d) std::cout<<std::fixed<<std::setprecision(n)<<d;
#define SOUT(n, c, d) std::cout<<std::setw(n)<<std::setfill(c)<<d;
#define SP std::cout<<" ";
#define TAB std::cout<<"\t";
#define BR std::cout<<"\n";
#define ENDL std::cout<<std::endl;
#define FLUSH std::cout<<std::flush;
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define MAT(type, c, m, n) std::vector<std::vector<type>> c(m, std::vector<type>(n));for(auto& r:c)for(auto& i:r)std::cin>>i;
#define ALL(a) (a).begin(),(a).end()
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RFOR(i, a, b) for(int i=(b)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=(n)-1;i>=0;--i)
#define PAIR std::pair<int, int>
#define IN(a, x, b) (a<=x && x<=b)
#define IN2(a0, y, a1, b0, x, b1) (a0<=y && y<a1 && b0<=x && x<b1)
#define SHOW(d) {std::cout << #d << "\t:" << d << "\n";}
#define SHOWVECTOR(v) {std::cout << #v << "\t:";for(const auto& i : v){std::cout << i << " ";}std::cout << "\n";}
#define SHOWVECTOR2(v) {std::cout << #v << "\t:\n";for(const auto& i : v){for(const auto& j : i){std::cout << j << " ";}std::cout << "\n";}}
#define SHOWPAIRVECTOR2(v) {std::cout << #v << "\t:\n";for(const auto& i : v){for(const auto& j : i){std::cout<<'('<<j.first<<", "<<j.second<<") ";}std::cout << "\n";}}
#define SHOWPAIRVECTOR(v) {for(const auto& i:v){std::cout<<'('<<i.first<<", "<<i.second<<") ";}std::cout<<"\n";}
#define CHECKTIME(state) {auto start=std::chrono::system_clock::now();state();auto end=std::chrono::system_clock::now();auto res=std::chrono::duration_cast<std::chrono::nanoseconds>(end-start).count();std::cerr<<"[Time:"<<res<<"ns  ("<<res/(1.0e9)<<"s)]\n";}

//#define int ll
using ll = long long;
constexpr int INFINT = 1 << 30;
constexpr ll INFLL = 1LL << 60;
constexpr double EPS = 0.0000001;
constexpr int MOD = 1000000007;

signed main() {
	INIT;
	VAR(std::string, s);
	REP(i, s.size() - 1) {
		if (s[i] == s[i + 1]) {
			OUT(i + 1)SP OUT(i + 2)BR;
			return 0;
		}
	}
	REP(i, s.size() - 2) {
		if (s[i] == s[i + 2]) {
			OUT(i + 1)SP OUT(i + 3)BR;
			return 0;
		}
	}
	OUT(-1)SP OUT(-1)BR;
	return 0;
}

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

int main() {
  int r;
  string ans;
  cin >> r;
  if(r<1200){
    ans = "ABC";
  }else if(r<2800){
    ans = "ARC";
  }else{
    ans = "AGC";
  }
  cout << ans << endl;
}

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

#define rep2(x,fr,to) for(int x=(fr);x<(to);x++)
#define rep(x,to) for(int x=0;x<(to);x++)
#define repr(x,fr,to) for(int x=(fr);x>=(to);x--)
#define all(c) c.begin(),c.end()
#define sz(v) (int)v.size()

using namespace std;
typedef long long  ll; typedef vector<int> VI; typedef pair<int,int> pii; typedef vector<ll> VL; const int MD = 1e9 + 7;
void dbg(){cerr<<"\n";} template <class F,class ...S> void dbg(const F& f, const S&...s){cerr <<f <<": "; dbg(s...);}


int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n;
	cin >>n;
	
	ll lm[] = {MD, -MD, MD, -MD};
	
	rep(i, n){
		ll x, y;
		cin >>x >>y;
		lm[0] = min(lm[0], x+y);
		lm[1] = max(lm[1], x+y);
		lm[2] = min(lm[2], x-y);
		lm[3] = max(lm[3], x-y);
	}
	ll ans = max(lm[1] - lm[0], lm[3] - lm[2]);
	cout <<ans <<"\n";
	
	return 0;
}



Measured memory_bytes: 3656
#include<stdio.h>                                                                                  
#include<string.h>
#include<stdlib.h>

int main(void){
    unsigned long long int A;
    unsigned long long int B;
    unsigned long long int N;
    unsigned long long int C;
    unsigned long long int amari;
    unsigned long long int kakeru;
    unsigned long long int sum=0;
//    char *heap;

    scanf("%lld",&N);
    scanf("%lld",&A);
    scanf("%lld",&B);
 //   heap = (char *)malloc(N*sizeof(char));
   
   C = A+B;
   
   kakeru = N/C;
   amari = N%C;

   if(amari < A){ 
       amari = amari;
   }else{
       amari = A;
   }   
    sum = kakeru*A+amari;

   printf("%lld\n",sum);
   // printf("%s",heap);

  //  free(heap); 

    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
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; }
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MOD (1000000007)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

ll N,X;
vector<ll> x; 

void input(){
    cin >> N >> X;
    x.resize(N);
    for(int i=0;i<N;i++) cin >> x[i];
}

ll GCD(ll a, ll b) {
    if (b == 0) return a;
    else return GCD(b, a % b);
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    input();
    for(int i=0;i<N;i++){
        x[i] = llabs(x[i] - X);
    }
    ll ans = x[0];
    for(int i=1;i<N;i++){
        ans = GCD(ans, x[i]);
    }
    cout << ans << endl;
    return 0;
}

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

#define ll long long int
#define ld long double
#define u128 __int128 
#define ff first
#define ss second
#define pb push_back
#define PI 3.141592653589793

#define MOD 1000000007
#define N 100100
#define M 1000010

int n, m;
int a[N];

int main() 
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.precision(10);
	
	int n, m;
	cin >> n >> m;
	int a[m];
	ll ans = 0;
	vector<int> diff;
	
	for (int i = 0; i < m; ++i)
	{
		cin >> a[i];
	}
	sort(a, a + m);
	for (int i = 1; i < m; ++i)
	{
		diff.pb(a[i] - a[i - 1]);
		ans += a[i] - a[i-1];
	}
	// for(auto e : diff)
	// 	cout << e << " ";
	// cout << ans;
	sort(diff.begin(), diff.end(), greater<int>());

	for(int i = 0; i < n - 1 && i < diff.size(); ++i)
		ans -= diff[i];

	cout << ans;
	return 0;
}

Measured memory_bytes: 1276
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <climits>

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

	int a[100];

	for (int i = 0; i < N; ++i) {
		std::cin >> a[i];
	}
	
	int amax = *std::max_element(a, a+N);
	int amin = *std::min_element(a, a+N);

	int distance = amax - amin;
	
	std::cout << distance << std::endl;

	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>//printf("%.*f\n",*********);
#include<vector>//s.erase(n),vector
#include<algorithm>//next_permutation
#include<set>
#include<string>//char('a'=32+'A')
                //to_string,string,substr
#include<sstream>
#include<complex>
#include<time.h>
#include<random>
#include<cmath>//min,max
#include<math.h>
#include<queue>
#include<time.h>
#include<iomanip>
#include<locale>
#include<utility>//swap

#define rt "\n"
#define rep(i,n) for(int i=0;i<n;i++)
#define rop(i,n) for(int i=1;i<=n;i++)//start==1
#define drep(i,n) for(int i=n-1;0<=i;i--)
#define drop(i,n) for(int i=n;0<i;i--)//end==1
#define yes(ans) if(ans)cout<<"yes"<<rt;else cout<<"no"<<rt;
#define Yes(ans) if(ans)cout<<"Yes"<<rt;else cout<<"No"<<rt;
#define YES(ans) if(ans)cout<<"YES"<<rt;else cout<<"NO"<<rt;
#define Yay(ans) if(ans)cout<<"Yay!"<<rt;else cout<<":("<<rt;
#define sec(a,b,ans) if(ans)cout<<a<<rt;else cout<<b<<rt;
#define vcin(a,n) rep(i,n)cin>>a[i];//vcin(配列名),(繰り返し回数)
#define sort(s) sort(s.begin(),s.end())//昇順
#define reve(s) reverse(s.begin(),s.end())//反転
#define please return
#define AC 0
#define rapid_pleaseAC_fast cin.tie(0);ios::sync_with_stdio(false)
#define pi 3.1415926535897932384626//pi
#define nine 1000000000//10^9

using namespace std;
typedef vector<int> vint;
typedef long double ldouble;
typedef vector<string> vstr;
typedef vector<char> vchar;
typedef vector<double> vdou;
typedef vector<double> vdouble;
typedef long long int llint;
typedef pair<int, int> pint;
typedef pair<llint, llint> pllint;
typedef vector<llint> vllint;
typedef vector<pint> vpint;
typedef vector<pair<llint, llint>> vpllint;
typedef vector<vector<int>> vvint;
typedef vector<vector<char>> vvchar;
typedef vector<vector<double>> vvdouble;
typedef vector<vector<llint>> vvllint;
typedef vector<vector<string>> vvstr;
typedef vector<vector<bool>> vvbool;
typedef vector<vector<pint>> vvpint;
typedef vector<bool> vbool;

long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

long long LCM(long long a, long long b) {
	return a * b / GCD(a, b);
}

unsigned GetDigit(unsigned num) {
	return std::to_string(num).length();
}

int tow(int n) {//2のn乗
	if (n == 0)return 1;
	int x = tow(n / 2);
	x *= x;
	if (n % 2 == 1)x *= 2;
	return x;//@domino
}

int KETA(int n) { //Sum of Each Digit
	int sum = 0;
	while (n > 0) {
		sum += n % 10; n /= 10;
	}
	return sum;
}

unsigned ND(unsigned num) {//Number of Digits
	return std::to_string(num).length();//outmax=10
}

bool KIBN(string s) {
	rep(i, s.size() / 2) {
		if (s[i] != s[s.size() - 1 - i])return false;
	}
	return true;
}

/*

 (char)toupper(a[n])=文字列のn文字目を大文字で出力

  pow(a,b)=aのb乗

  */

bool ABC(int n) {
	if (0 < n && n < 13) {
		return true;
	}
	else {
		return false;
	}
}

int main(void) {
	rapid_pleaseAC_fast;

	string s;
	cin >> s;
	string t;
	int x = nine;
	rep(i, s.size() - 2) {
		int y = (s[i] - '0') * 100 
			+ (s[i + 1] - '0') * 10 
			+ (s[i + 2] - '0');
		if (abs(753 - y) < x) {
			x = abs(753 - y);
		}
	}
	cout << x << rt;

	please AC;
}
//参考：---

Measured memory_bytes: 256
n,k = map(int, input().split())
al = list(map(int, input().split()))

bit_cnts = [0]*41
for a in al:
    for i in range(41):
        if a&(1<<i) > 0:
            bit_cnts[i] += 1


dp_same = [-1]*42
dp_small = [-1]*42
dp_small[41] = -1
dp_same[41] = -1
for i in range(41,0,-1):
    curr_bit = i-1
    kbit = 0
    if k&(1<<curr_bit) > 0: kbit = 1
    if kbit == 0:
        dp_same[i-1] = dp_same[i] + pow(2,curr_bit)*bit_cnts[curr_bit]
        # dp_small[i-1] = dp_small[i] + pow(2,curr_bit)*bit_cnts[curr_bit]
        if dp_small[i] > -1:
            dp_small[i-1] = dp_small[i] + pow(2,curr_bit)*(n-bit_cnts[curr_bit])
            dp_small[i-1] = max(dp_small[i-1], dp_small[i] + pow(2,curr_bit)*(bit_cnts[curr_bit]))
    else:
        dp_same[i-1] = dp_same[i] + pow(2,curr_bit)*(n-bit_cnts[curr_bit])
        if dp_small[i] > -1:
            dp_small[i-1] = dp_small[i] + pow(2,curr_bit)*(n-bit_cnts[curr_bit])
            dp_small[i-1] = max(dp_small[i-1], dp_small[i] + pow(2,curr_bit)*(bit_cnts[curr_bit]))
        dp_small[i-1] = max(dp_small[i-1], dp_same[i]+pow(2,curr_bit)*(bit_cnts[curr_bit]))


ans = max(dp_same[0],dp_small[0])
print(ans+1)

Measured memory_bytes: 98608
#include <algorithm>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

typedef unsigned long ul;
typedef pair<ul, ul> P;
map<int, int> dp;
#define REP(i,n) for(int i=0;i<n;i++)

ul N, x;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N >> x;
    ul a[N];
    for(int i = 0; i < N; ++i) {
        cin >> a[i];
    }
    sort(a, a+N);
    int itr = 0;
    while(x >= a[itr]) {
      x -= a[itr];
      ++itr;
      if(itr == N) {
        if(x != 0) --itr;
        break;
      }
    }
    cout << itr << endl;


}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<stack>
#include<queue>
#include<vector>
#include<map>
#include<ctime>
using namespace std;
#define LL double
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sqr(x) (x)*(x)
const int MAX=1005;
const LL inf=1e30;
struct node
{
    int u,v;
    LL w;
}g[MAX*MAX];
int e,ans;
int vis[MAX],id[MAX],pre[MAX];
LL in[MAX],sum,res,gg[105][105];
void add(int u,int v,LL w)
{
    g[e].u=u; g[e].v=v; g[e++].w=w;
    //cout<<u<<"->"<<v<<" "<<w<<endl;
    gg[u][v]=w;
}
double ZL(int root,int n)
{
    int i,j,k,u,v,vn;
    res=0;
    while(1)
    {
        for(i=0;i<n;i++)
            in[i]=inf;
        for(i=0;i<e;i++)
        {
            u=g[i].u; v=g[i].v;
            if(g[i].w<in[v]&&u!=v)
            {
                pre[v]=u;
                in[v]=g[i].w;
            }
        }
        for(i=0;i<n;i++)
        {
            if(i!=root&&in[i]==inf)
                return false;
        }
        vn=0;
        memset(id,-1,sizeof(id));
        memset(vis,-1,sizeof(vis));
        in[root]=0;
        for(i=0;i<n;i++)
        {
            res+=in[i];
            v=i;
            while(vis[v]!=i&&id[v]==-1&&v!=root)
            {
                vis[v]=i;
                v=pre[v];
            }
            if(v!=root&&id[v]==-1)
            {
                for(u=pre[v];u!=v;u=pre[u])
                {
                    id[u]=vn;
                }
                id[v]=vn++;
            }
        }
        if(vn==0)
            break;
        for(i=0;i<n;i++)
        {
            if(id[i]==-1)
                id[i]=vn++;
        }
        for(i=0;i<e;i++)
        {
            v=g[i].v;
            g[i].u=id[g[i].u];
            g[i].v=id[g[i].v];
            if(g[i].u!=g[i].v)
            {
                g[i].w-=in[v];
            }
        }
        n=vn;
        root=id[root];
    }
    return res;
}
double a[105][105],len[105];
int main()
{
    int n,m,i,j,k;
    while(scanf("%d%d",&n,&m)!=EOF)
    {
        e=0;
        rep (i, m) {
            len[i] = 0;
            rep (j, n) {
                scanf ("%lf", &a[i][j]);
                len[i] += a[i][j] * a[i][j];
            }
            len[i] = sqrt(len[i]);
        }
        rep (i, m) {
            rep (j, m) {
                if (i == j) continue;
                double now = 0.0;
                rep (k, n) {
                    now += a[i][k] * a[j][k];
                }
                now /= len[i] * len[j];
                now = sqrt (1.0 - now * now);
                gg[j + 1][i + 1] = sqr(len[i] * now);
                add(j+1,i+1,gg[j+1][i+1]);
            }
            gg[0][i + 1] = sqr(len[i]);
            add(0,i+1,gg[0][i+1]);
            //gg[i + 1][0] = -1;
            //gg[i + 1][i + 1] = -1;
        }
        //for(int i=0;i<=m;i++)
            //for(int j=0;j<=m;j++)
                //printf("%d->%d %lf\n",i,j,gg[i][j]);
        printf("%.8f\n",ZL(0,m+1));
    }
    return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define ll long long int
#define yorn(f) cout<<((f)?"Yes":"No")<<endl
#define YORN(f) cout<<((f)?"YES":"NO")<<endl
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
int main()
{
    int x;
    cin >> x;
    if (x >= 1200) {
        cout << "ARC" << endl;
    }
    else {
        cout << "ABC" << endl;
    }
    return 0;
}

Measured memory_bytes: 3484
#include <algorithm>
#include <cstdint>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <cfloat>

using namespace std;

using lint=int64_t;
using uint=uint32_t;
using ulint=uint64_t;

template<class T>
using vector2d=vector<vector<T>>;

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

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

template <class T>
void OutVec(const vector<T>& vec){
  for(int i = 0; i < vec.size() - 1; ++i){
    cout<<vec[i]<<" ";
  }
  cout<<vec.back()<<endl;
}

template <class T>
void OutVec2d(const vector2d<T>& vec){
  for(auto v:vec){
    OutVec(v);
  }
}

int main(){
  cout << std::fixed << std::setprecision(16);
  cin.tie(nullptr);
  std::ios::sync_with_stdio(false);

  vector<int> a(5);
  for(int i=0;i<5;i++){
    cin>>a[i];
    if(a[i]==0){
      cout<<i+1<<endl;
      return 0;
    }
  }

  return 0;
}




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

#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define S(x) (int)(x).size()
#define L(x) (int)(x).length()
#define ld long double
#define mem(x,y) memset(x,y,sizeof x)

#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int , null_type , less<int> , rb_tree_tag , tree_order_statistics_node_update> ordered_set;

const int mod = 1e9+7;
const ll infl = 0x3f3f3f3f3f3f3f3fLL;
const int infi = 0x3f3f3f3f;

int state[100009];
void solve()
{
	ll n,x,m;
	cin>>n>>x>>m;
	ll ans=0;
	vector<int> v;
	int len=0;
	mem(state,-1);
	while(state[x]==-1 && n)
	{
		state[x]=len;
		v.pb(x);
		ans+=x;
		x=x*x%m;
		n--;
		len++;
	}
	ll temp=0;
	for(int i=state[x];i<len;i++) temp+=v[i];
	len = len-state[x];
	//cout<<temp<<'\n';
	ans+=temp*(n/len);
	n%=len;
	for(int i=0;i<n;i++) ans+=v[state[x]+i];
	cout<<ans<<'\n';
}
//12722645
//9999998970
//9999999756
//492443256176507
int main()
{
	IOS
	int t=1;
	//cin>>t;
	while(t--)
	{
		solve();
	}
}


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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;A++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////
#define MOD (ll)(1e9+7)
ll L, R;
ll bL[90], bR[90];
ll mk[90][2][2][2];
ll i, j, k,l, ans;


ll solve(ll p,ll a,ll b,ll c){
    if(p==-1){
        return 1;
    }
    if(mk[p][a][b][c]!=-1)
        return mk[p][a][b][c];

    ll ret = 0;
    // 0 0
    if(a==1||bL[p]==0){
        ret += solve(p - 1, a, bR[p] == 1 ? 1 : b, c);

        // 0 1
        if(c==1&&(b==1||bR[p]==1)){
            ret += solve(p - 1, a, b, c);
        }
    }
    
    // 1 1 
    if(b==1||bR[p]==1){
        ret += solve(p - 1, bL[p] == 0 ? 1 : a, b, 1);
    }

    mk[p][a][b][c] = ret % MOD;
    return ret % MOD;
}

int main(){
    scanf("%lld%lld", &L,&R);
    fornum(i,0,70){
        fornum(j,0,2){
            fornum(k,0,2){
                fornum(l,0,2){
                    mk[i][j][k][l] = -1;
                }
            }
        }
    }
    fornum(i,0,62){
        if(R&(1ll<<i)){
            bR[i] = 1;
        }
        if(L&(1ll<<i)){
            bL[i] = 1;
        }
    }

    printf("%lld", solve(60,0,0,0));
    return 0;
}

Measured memory_bytes: 256
#pragma GCC target("avx512f,avx512dq,avx512cd,avx512bw,avx512vl")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}

int main() {
	int n = ri();
	std::string s;
	std::cin >> s;
	int64_t res = 0;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < i; j++) {
			if (s[i] == s[j]) continue;
			for (int k = 0; k < j; k++) if (j - k != i - j && s[k] != s[i] && s[k] != s[j]) res++;
		}
	}
	printf("%" PRId64 "\n", res);
	return 0;
}


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

using namespace std;
typedef long long ll;

#define MOD (long long)(1e9+7)
#define INF (1LL<<60)
#define rep(i,n) for(ll i = 0; i < (n); i++)
#define rep1(i,n) for(ll i = 1; i <= (n); i++)

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;
}


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

// mod m におけるa の逆元
ll modinv(ll a, ll m) {
  ll b = m, u = 1, v = 0;
  while (b) {
    ll t = a / b;
    a -= t * b; swap(a, b);
    u -= t * v; swap(u, v);
  }
  u %= m;
  if (u < 0) u += m;
  return u;
}

// 素因数分解
vector<pair<ll, ll>> prim;
void pf(ll n)
{
  ll s = sqrt(n);
  ll r = 0;
  for(ll i = 2; i <= s; i++) {
    if((n % i) == 0) {
      r = 0;
      do {
	r++;
	n = n / i;
      } while((n % i) == 0);
      prim.push_back({i, r});
    }
  }
  if(n > s) {
    prim.push_back({n, 1});
  }
}

void solve()
{
  // ll N; cin >> N;
  // ll N, K; cin >> N >> K;
  // ll x, y, z; cin >> x >> y >> z;
  // ll a, b, c; cin >> a >> b >> c;
  string s; cin >> s;
  // vector<ll> a(N); rep(i, N) cin >> a[i];
  vector<ll> cnt(3, 0);
  bool ok = false;

  rep(i, s.size()) {
    cnt[s[i]-'a'] ++;
  }
  sort(cnt.begin(), cnt.end());
  //  rep(i, 3) cout << cnt[i] << " "; cout << endl;
  ok = (cnt[2] - cnt[0]) < 2;
  cout << (ok?"YES":"NO") << endl;
}


int main(void)
{
  // ll t; cin >> t; rep(i, t)
  solve();
}


Measured memory_bytes: 3772
n = int(input())

ans = 0
mod_base = [59049, 46656, 7776, 6561, 1296, 729, 216, 81, 36, 9, 6, 1]
mod_list = [59049, 46656, 7776, 6561, 1296, 729, 216, 81, 36, 9, 6, 1]
ans_list = [0 for _ in range(100000)]

for mod in mod_base:
	ans_list[mod - 1] = 1

for i in range(10000):
	if ans_list[n - 1] != 0:
		break
	new_mod_list = []
	for j in mod_list:
		for k in mod_base:
			if j + k <= 100000 and ans_list[j + k - 1] == 0:
				new_mod_list.append(j + k)
				ans_list[j + k - 1] = i + 2
	mod_list = sorted(new_mod_list, reverse=True)

print(ans_list[n - 1])

Measured memory_bytes: 5472
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define pb push_back
const int maxn = 10000;
const int INF32 = 1'050'000'000;
const long long INF64 = 4'000'000'000'000'000'000;
const int MOD7 = 1'000'000'007;
const int MOD9 = 1'000'000'009;
const int mod = MOD7;

void ERROR(int num) { printf("ERROR%d!\n",num); }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
int dx[8]={-1,0,1,0,1,1,-1,-1};
int dy[8]={0,-1,0,1,1,-1,1,-1};


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

    int K;
    cin >> K;
    int A, B;
    cin >> A >> B;
    
    int num = K;
    bool ok = 1;
    for(int num = K; num <= B; num+=K){
        if(num >= A && num%K==0){
            cout << "OK" << endl;
            ok = 0;
            break;
        }
    }

    if(ok){
        cout << "NG" << endl;
    }

   


}

Measured memory_bytes: 3664
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <utility>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;

typedef vector<int> vi;
typedef pair<int,int> ii;
#define sz(a) int((a).size())
#define all(c) (c).begin(), (c).end()

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

	int n;
	scanf("%d", &n);
	vi w(n+1), ps(n+1);
	for (int i = 1; i <= n; i++) {
		scanf("%d", &w[i]);
		ps[i] = w[i] + ps[i-1];
	}

	int best = ps[n];
	for (int i = 1; i < n; i++) {
		best = min(best, abs(ps[i] - (ps[n] - ps[i])));
	}
	printf("%d\n", best);
}


Measured memory_bytes: 256
program vjudge149349B;
var s:ansistring;
    i,t1,t2:longint;
begin
  readln(s);
  for i:=1 to length(s) do if s[i]='Z' then t2:=i;
  for i:=length(s) downto 1 do if s[i]='A' then t1:=i;
  writeln(t2-t1+1);
end.

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

int main(){
  int N;
  cin >>N;
  int h[N];
  for(int i=0;i<N;i++){
    cin >> h[i];
  }
  int a[N+1];
  a[0] = 0;
  a[1] = 20000;
  for(int i=0;i<N-1;i++){
    a[i+1] = min(a[i+1],a[i]+abs(h[i+1]-h[i]));
    a[i+2] = a[i] + abs(h[i+2]-h[i]);
  }
  cout << a[N-1] << endl;
}

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

static class Program
{
    static int[] Step(int[] A)
    {
        int N = A.Length;
        var S = new int[N];
        var E = new int[N];
        for (int i = 0; i < N; ++i)
        {
            ++S[Math.Max(i - A[i], 0)];
            ++E[Math.Min(i + A[i], N - 1)];
        }

        int cnt = 0;
        var B = new int[N];
        for (int i = 0; i < N; ++i)
        {
            cnt += S[i];
            B[i] = cnt;
            cnt -= E[i];
        }
        return B;
    }

    static int[] Solve(int N, int K, int[] A)
    {
        for (int i = 0; i < K; ++i)
        {
            A = Step(A);
            if (A[0] == N && A[N - 1] == N) { break; }
        }
        return A;
    }

    static void Main(string[] args)
    {
        var V = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
        var A = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
        Console.WriteLine(string.Join(" ", Solve(V[0], V[1], A)));
    }
}


Measured memory_bytes: 78796
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<int>;
using VL = vector<ll>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);--(i))
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
const long double pi = acos(-1);
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; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& input, vector<T>& v) { for (auto& elemnt : v)input >> elemnt; return input; }

int main() {
    init();
    int n, q; cin >> n >> q;
    vector<VI> g(n);
    FOR(i, 0, n - 1) {
        int a, b; cin >> a >> b;
        --a, --b;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    VL cnt(n);
    FOR(i, 0, q) {
        int p, x; cin >> p >> x;
        --p;
        cnt[p] += x;
    }

    vector<bool> ever(n);
    queue<int> bfs;
    ever[0] = true;
    bfs.push(0);
    while (!bfs.empty()) {
        int now = bfs.front(); bfs.pop();
        for (int to : g[now]) {
            if (ever[to])continue;
            ever[to] = true;
            cnt[to] += cnt[now];
            bfs.push(to);
        }
    }

    FOR(i, 0, n)cout << cnt[i] << (i == n - 1 ? "\n" : " ");
}

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

using namespace std;

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

	long long l = 0;
	long long r = 3234566667 + 100;
	long long ans = 0;

	while(r - l > 1) {
		long long mid = (l + r) / 2;

		long long t = mid;

		vector<int> bit;

		while(t) {
			bit.emplace_back(t % 10);
			t /= 10;
		}

		reverse(bit.begin(), bit.end());

		int m = bit.size();
				
		vector<vector<vector<long long> > > dp;
		
		dp.resize(m + 1);

		for(int i = 0; i <= m; ++i) {
			dp[i].resize(11);
		}

		for(int i = 0; i <= m; ++i) {
			for(int j = 0; j <= 10; ++j) {
				dp[i][j].resize(2);
			}
		}

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

		for(int i = 0; i < m; ++i) {
			for(int j = 0; j < 10; ++j) {
				for(int k = 0; k < 10; ++k) {
					if(abs(j - k) <= 1) {
						dp[i + 1][k][0] += dp[i][j][0];
						if(k < bit[i]) {
							dp[i + 1][k][0] += dp[i][j][1];
						}
						if(k == bit[i]) {
							dp[i + 1][k][1] += dp[i][j][1];
						}
					}
				}
			}

			for(int k = 1; k < 10; ++k) {
				if(k < bit[i]) {
					dp[i + 1][k][0] += dp[i][10][1];
				}
				if(k == bit[i]) {
					dp[i + 1][k][1] += dp[i][10][1];
				}
				dp[i + 1][k][0] += dp[i][10][0];
			}

			dp[i + 1][10][0] += dp[i][10][0] + dp[i][10][1];
		}

		int sum = 0;

		for(int i = 0; i < 11; ++i) {
			for(int j = 0; j < 2; ++j) {
				sum += dp[m][i][j];
			}
		}

		--sum;

		if(sum < k) {
			l = mid;
		} else {
			r = ans = mid;
		}
	}

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

Measured memory_bytes: 256