akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
using namespace std;

int dx[8] = {1,1,0,-1,-1,-1,0,1};
int dy[8] = {0,-1,-1,-1,0,1,1,1};
map<vector<int>,int> m;
void remove(vector<int> &v, int a1, int a2){
    if(a1 > a2) swap(a1,a2);
    v.erase(v.begin()+a1);
    v.erase(v.begin()+a2-1);
}

void pr(vector<int> &f){
    for(int i=0;i<f.size();i++){
        cout << f[i];
        if(i%4 == 3) cout << endl;
    }
    cout << endl << endl;
}

int solve(vector<int> f){
    if(m.find(f) != m.end()) return m[f];
    vector<int> back;
    bool ended = true;
    int ret = 1 << 29;
    for(int i=0;i<f.size();i++){
        int x = i%4, y = i/4;
        for(int j=0;j<8;j++){
            int nx = x + dx[j];
            int ny = y + dy[j];

            if(!(0 <= nx && nx < 4 && 0 <= ny && ny < 5)){
                continue;
            }else{
                int ind = nx + ny*4;
                if(ind >= f.size()){
                    continue;
                }else if(f[ind] == f[i]){
                    ended = false;
                    back = f;
                    remove(f,i,ind);
                    ret = min(ret,solve(f));
                    f = back;
                }
            }
        }
    }
    if(ended){
        ret = min(ret, (int)f.size());
    }
    return m[f] = ret;
}

int main(){
    int n;
    vector<int> init(20);
    cin >> n;
    for(int i=0;i<n;i++){
        m.clear();
        for(int j=0;j<20;j++){
            cin >> init[j];
        }
        cout << solve(init) << endl;
    }
}

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

using namespace std;

#define YES cout << "YES" << endl;
#define NO  cout << "NO"  << endl;
#define Yes cout << "Yes" << endl;
#define No  cout << "No"  << endl;
 
#define INF INT_MAX
#define MOD 1000000007
#define PI  acos(-1)

using ll  = long long;
using ull = unsigned long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

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

int main(int argc, char *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    ll N, L;
    cin >> N >> L;

    vector<ll> a(N);
    rep (i, N) {
        cin >> a[i];
    }

    bool flag = false;
    ll index = 0;
    rep (i, N-1) {
        if (a[i]+a[i+1] >= L) {
            flag = true;
            index = i;
        }
    }

    if (flag) {
        cout << "Possible" << endl;
        rep (i, index) {
            cout << i+1 << endl;
        }
        for (ll i = N-1; i > index; i--) {
            cout << i << endl;
        }
    } else {
        cout << "Impossible" << endl;
    }
    return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define REP(i,a,b) for(int i=int(a);i<(int)b;++i)
#define Graph vector<vecctor<ll>>
#define pairs vector<pair<ll,ll>>
#define pb push_back



using namespace std;
using ll = long long;
const ll INF = 1e18;
const double PI = acos(-1);

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



int main(void)
{
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    
    int n;
    cin >> n;
    vector<ll>l(n);
    rep(i,n){
        cin >> l[i];
    }
    if(n <= 2){
        cout << 0 << endl;
        return 0;
    }
    ll ans = 0;
    for(int i = 0; i < n-2; ++i){
        for(int j = i+1;j < n-1; ++j){
            for(int k = j+1; k < n;++k){
                ll ma = max(max(l[i],l[j]),l[k]);
                if(2*ma < l[i]+l[j]+l[k]){
                    if(l[i] != l[k] && l[i] != l[j] && l[j] != l[k])ans ++;
                }
            }
        }
    }

    cout << ans << endl;
    return 0;

}


Measured memory_bytes: 3656
k = gets.to_i
a = []
for i in 1..k do
  a << i
end
a = a.combination(2).to_a.select {|as| (as[0]%2 == 0 && as[1]%2 != 0) || (as[0]%2 != 0 && as[1]%2 == 0)}
p a.count

Measured memory_bytes: 3964
import math
import queue
import bisect
import heapq
import time
import itertools

mod = int(1e9+7)

def swap(a,b):
    return (b,a)

def my_round(a,dig=0):
    p = 10 ** dig
    return (a * p * 2 + 1) // 2 / p

def gcd(a,b): #最大公約数
    if (a<b):
        a,b = swap(a,b)
    if (b==0):
        return a
    else:
        return gcd(b,a%b)

def lcm(a,b): #最小公倍数
    return a/gcd(a,b)*b

def divisors(a): # 約数列挙
    divisors = []
    for i in range(1,int(a**0.5)+1):
        if a%i==0:
            divisors.append(i)
            if i!=a//i:
                divisors.append(a//i)
    return divisors

def is_prime(a): #素数判定
    if a<2:
        return False
    elif a==2:
        return True
    elif a%2==0:
        return False
    sqrt_num = int(a**0.5)
    for i in range(3,sqrt_num+1,2):
        if a%i==0:
            return False
    return True

def prime_num(a): #素数列挙
    pn = [2]
    for i in range(3,int(a**0.5),2):
        prime = True
        for j in pn:
            if i%j==0:
                prime = False
                break
        if prime:
            pn.append(i)
    return pn

def prime_fact(a): #素因数分解
    sqrt = math.sqrt(a)
    res = []
    i = 2
    if is_prime(a):
        res.append(a)
    else:
        while a!=1:
            while a%i==0:
                res.append(i)
                a //= i
            i += 1
    return res

def main():
    n = int(input())
    if n < 1000:
        print('ABC')
    else:
        print('ABD')
    return

if __name__=='__main__':
    main()


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


int main() 
{
    unsigned long long  a, b, x;
    cin >> a >> b >> x;

    unsigned long long A = (a - 1) / x;
    unsigned long long B = b / x;

    unsigned long long  answer = B - A;

    if (a == 0)
        answer = B + 1;

    cout << answer;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <map>
#include <vector>
#include <utility>
#include <cmath>
#include <cstring>
#include <queue>
#include <time.h>
#include <algorithm>
#include <set>
using namespace std;
 
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<ll, ull> ipair;
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define sz size()
#define ln length()
#define rep(i,n) for(i=0;i<n;i++)
#define fu(i,a,n) for(i=a;i<=n;i++)
#define fd(i,n,a) for(i=n;i>=a;i--)
#define all(a)  a.begin(),a.end() 
#define gi(n) scanf("%d",&n)
#define gl(n) scanf("%lld",&n)
#define pi(n) printf("%d",n)
#define pl(n) printf("%lld",n);
#define pp printf(" ")
#define pn printf("\n")

ll adj[105][105];
ll col[10005];
ll n, m;
ll k;
void fill1(ll r, ll c, ll id, int ch) {
	if(r == n) {
		return;
	}
	if(col[id] == 0) {
		fill1(r, c, id + 1, ch);
		return;
	}
	adj[r][c] = id;
	col[id]--;
	ll nc, nr;
	if(ch == 0) {
		nc = c + 1;
		nr = r;
		if(nc >= m) {
			nc = m - 1;
			nr = r + 1;
			ch^=1;
		}
		fill1(nr, nc, id, ch);
	}
	else {
		nc = c - 1;
		nr = r;
		if(nc < 0) {
			nc = 0;
			nr = r + 1;
			ch^=1;
		}
		fill1(nr, nc, id, ch);
	}
}
int main() {
	gl(n);
	gl(m);
	gl(k);
	ll i;
	fu(i, 1, k) {
		gl(col[i]);
	}
	fill1(0, 0, 1, 0);
	ll j;
	rep(i, n) {
		rep(j, m) {
			pl(adj[i][j]);
			pp;
		}
		pn;
	}
	return 0;
}

Measured memory_bytes: 512
n,x = map(int, input().split())
A =list(map(int, input().split()))

ans = 0
for i in range(n-1):
    y =  A[i]+A[i+1]
    if y > x:
        r = y-x
        if A[i+1] >= r:
            A[i+1] -= r
            ans += r
        else:
            A[i+1] = 0
            A[i] -= (r-A[i+1])
            ans += r
print(ans)


Measured memory_bytes: 85000
_,*s=open(0);t="."
b=t*101;q=range(101);i=0
for s in s:
 a=[i];i+=1
 for x,y,z,c in zip(b,t+s,s,q):a+=min(c+(t>z<x),a[-1]+(t>z<y)),
 b,q=s,a[1:]
print(a[-2])

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define F first
#define S second
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int,int>;
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; }
ll gcd(ll a, ll b) { return b?gcd(b, a%b):a;}
ll lcm(ll a, ll b) { return a*b/gcd(a,b);}
ll MOD=1000000007;

int main(){
  string s,t;
  cin>>s>>t;
  int num=0;
  rep(i,3){
    if(s.at(i)==t.at(i)) num++;
  }
  cout<<num<<endl;
}

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}

int main2() {
  string T; cin >> T;
  const int N = T.size();

  REP(i, N) if (T[i] == '?') T[i] = 'D';
  cout << T << endl;
  // int ans = 0;
  // REP(i, N) if (T[i] == 'D') ans++;
  // REP(i, N-1) if (T[i] == 'P' && T[i+1] == 'D') ans++;
  // cout << ans << endl;
  return 0;
}

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}

Measured memory_bytes: 3760
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		while (true) {
			int n = sc.nextInt();
			if (n == 0) {
				break;
			}
			
			int pop[] = new int[61];
			for(int i = 0; i < 61; i++){
				pop[i] = 0;
			}
			
			for (int i = 0; i < n; i++) {
				pop[sc.nextInt()]++;
			}

			int pre_num = 0;
			long mati = 0;
			long sum = 0;
			for (int i = 0; i < pop.length; i++) {
				if(pop[i] == 0){continue;}
				for (int j = 0; j < pop[i]; j++) {
					mati += pre_num;
					sum += mati;
					pre_num = i;
				}
			}

			System.out.println(sum);
		}

	}
}

Measured memory_bytes: 12000
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<queue>
#define ll long long
#define rep(i,n) for(ll i=0;i<n;i++)
#define INF 1e9+7
using namespace std;
const int MOD = 1e9 +7;


int N,A,B,C,l[10];

int dfs(int n,int a,int b,int c){
    if(n==N){
        if(min(min(a,b),c) >0) return abs(a-A) +abs(b-B) +abs(c-C) -30;
        else return INF;
    }
    int ret0 =dfs(n+1,a,b,c);
    int ret1 =dfs(n+1,a+l[n],b,c)+10;
    int ret2 =dfs(n+1,a,b+l[n],c)+10;
    int ret3 =dfs(n+1,a,b,c+l[n])+10;
    return min(min(ret0,ret1),min(ret2,ret3));
}

int main(){
    cin >>N>>A>>B>>C;
    rep(i,N) cin >>l[i];
    cout <<dfs(0,0,0,0)<<endl;
    return 0;
}

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

int mask;

template<class T> struct Parser {
    typedef string::const_iterator State;

    T solve(const string &S) {
        State begin = S.begin();
        return equation(begin);
    }

    // <equation> ::= <formula> "=" <formula>
    T equation(State &begin) {
        T left = formula(begin);
        begin++;    // skip '='
        T right = formula(begin);
        return left == right;
    }

    // <formula> ::= <boolean> |
    // "-" <formula> |
    // "(" <formula> "*" <formula> ")" |
    // "(" <formula> "+" <formula> ")" |
    // "(" <formula> "->" <formula> ")"
    T formula(State &begin) {
        if (*begin == '(') {
            begin++;                    // skip '('
            T left = formula(begin);
            char op = *begin;
            begin++;                    // skip '*' or '+' or '-'
            if (op == '-') begin++;     // skip '>'
            T right = formula(begin);
            begin++;                    // skip ')'
            T ret = deduce(left, op, right);
            return ret;
        } else if (*begin == '-') {
            begin++;    // skip '-'
            return !formula(begin);
        } else {
            return boolean(begin);
        }
    }

    T deduce(T x, char op, T y) {
        if (op == '*') {
            return x and y;
        } else if (op == '+') {
            return x or y;
        } else {    // "->"
            return !x or y;
        }
    }

    // <boolean> ::= "T" | "F" |
    // "a" | "b" | "c" | "d" | "e" | "f" |
    // "g" | "h" | "i" | "j" | "k" |
    T boolean(State &begin) {
        T ret;
        if (*begin == 'T') {
            ret = 1;
        } else if (*begin == 'F') {
            ret = 0;
        } else {
            ret = (mask >> (*begin - 'a')) & 1;
        }
        begin++;
        return ret;
    }
};

void solve(string S) {
    // 恒等式とは，式に現れる変数がどのような値であっても成立する等式のことである．
    Parser<bool> ps;
    for (mask = 0; mask < (1 << 11); mask++) {
        if (!ps.solve(S)) {
            cout << "NO" << endl;
            return ;
        }
    }
    cout << "YES" << endl;
}

int main() {
    string S;
    while (cin >> S && S != "#") {
        solve(S);
    }
    return 0;
}


Measured memory_bytes: 3224
n = int(input())
ss = sorted([int(input()) for i in range(n)])
tss = sum(ss) # total ss
if tss % 10 != 0:
  print(tss)
else:
  for s in ss:
    x = tss - s
    if  x % 10 != 0:
      print(x)
      exit()
  print(0)

Measured memory_bytes: 9176
def calc0toN(a):
  if a % 2 == 0:
    if a % 4 == 0:
      return a
    else:
      return 1 ^ a
  else:
    if (a + 1) % 4 == 0:
      return 0
    else:
      return 1
A, B = map(int, input().split())
print(calc0toN(A - 1) ^ calc0toN(B))

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

using namespace std;

int main() {
    int N;

    cin >> N;

    vector<int> p, p_a;

    int num;

    for(int i = 0; i < N; i++) {
        cin >> num;
        p.push_back(num);
        p_a.push_back(num);
    }

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

    int counter = 0;

    for(int i = 0; i < N; i++) {
        if(p[i] != p_a[i]) {
            counter++;
        }
    }

    if(counter == 0 || counter == 2) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
using lli = long long int;
using pii = std::pair<lli, lli>;

int main(){
  lli n, d, a;
  std::cin >> n >> d >> a;
  std::vector<pii> xh(n);
  for (int i = 0; i < n; i++) {
    std::cin >> xh[i].first >> xh[i].second;
  }
  std::sort(xh.begin(), xh.end());
  // for (int i = 0; i < n; i++) {
  //   std::cout << xh[i].first << " " << xh[i].second << std::endl;
  // }
  lli ans = 0, pos = 0;
  lli sq[n + 10];
  lli sum[n + 10];
  for (int i = 0; i < n + 10; i++) sq[i] = sum[i] = 0;
  int div = std::sqrt(n) + 1;
  for (int i = 0; i < n; i++) {
    while(i < n and xh[i].second - (sum[i] + sq[i/div])<= 0)i++;
    if(i == n)break;
    lli hp = (xh[i].second - (sum[i] + sq[i/div]));
    lli times = hp/a;
    if(hp % a != 0)times++;
    lli damege = a*times;
    while(pos < n and xh[pos].first <= xh[i].first + 2*d)pos++;
    for (int j = i; i/div == j/div and j < pos; j++) sum[j] += damege;
    for (int j = i/div + 1; (j + 1)*div <= pos; j++) sq[j] += damege;
    for (int j = pos/div * div; i/div < pos/div and j < pos; j++) sum[j] += damege;
    ans += times;
  }
  std::cout << ans << std::endl;
  return 0;
}



Measured memory_bytes: 6528
def modinv(a,m):
    b, u, v = m, 1, 0
    while b:
        t = a//b
        a -= t*b
        a,b = b,a
        u -= t * v
        u,v = v,u
    u %= m
    return u


N_MAX = 10**6
MOD = 10**9 + 7
fac, finv, inv = [0]*N_MAX, [0]*N_MAX, [0]*N_MAX
def com_init():
    fac[0], fac[1] = 1, 1
    finv[0], finv[1] = 1, 1
    inv[1] = 1
    for i in range(2, N_MAX):
        fac[i] = fac[i - 1] * i % MOD
        inv[i] = MOD - inv[MOD%i] * (MOD // i) % MOD
        finv[i] = finv[i - 1] * inv[i] % MOD

def com(n, k):
    if n < k: return 0
    if n < 0 or k < 0: return 0
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD



def main():
    x, y = map(int, input().split()) 
    com_init()

    a3 = -x+2*y
    b3 = 2*x-y

    if a3%3 != 0 or b3%3 != 0:
        print(0) 
        return

    a = a3//3
    b = b3//3

    print(com(a+b, min(a,b)))

if __name__ == "__main__":
    main()

Measured memory_bytes: 121716
#include <iostream>
#include <string>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <iomanip>

using namespace std;

int main()
{
  int N, M, X, Y;
  cin >> N >> M >> X >> Y;

  int x_max = -101;
  for (int i = 0; i < N; ++i)
  {
    int x;
    cin >> x;
    if (x_max < x) x_max = x;
  }

  int y_min = 101;
  for (int i = 0; i < M; ++i)
  {
    int y;
    cin >> y;
    if (y_min > y) y_min = y;
  }

  if (x_max < y_min)
  {
    if (y_min > X && y_min <= Y)
    {
      cout << "No War" << endl;
      return 0;
    }
  }
  cout << "War" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

void solve() {
  int d, n;
  cin >> d >> n;
  if (d == 0) {
    if (n < 100) cout << n << endl;
    else cout << 101 << endl;
  } else if (d == 1) {
    if (n < 100) cout << n * 100 << endl;
    else cout << 10100 << endl;
  } else {
    if (n < 100) cout << n * 10000 << endl;
    else cout << 1010000 << endl;
  }
}

int main() {
  solve();
  return 0;
}

Measured memory_bytes: 3596
#include <stdio.h>
int main(void) {
	char s[100]={};
	scanf("%s",s);
	if(s[0]=='Y'&&s[1]=='A'&&s[2]=='K'&&s[3]=='I') {
		puts("Yes");
	} else {
		puts("No");
	}
	return 0;
}

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

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> ii;
typedef tuple<ll, ll, ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define REP(i,n) for (ll i = 0; i < n; ++i)
#define REPR(i,n) for (ll i = n-1; i >= 0; --i)
#define FOR(i,m,n) for (int i = m; i < n; ++i)
#define FORR(i,m,n) for (ll i = n-1; i >= m; --i)
#define FORE(x,xs) for (const auto& x : xs)
#define ALL(v) v.begin(), v.end()
#define rALL(v) v.rbegin(), v.rend()

const int MAX = 1e5+10;

int W, H;
vii lines;

ll solve() {
    sort(ALL(lines));
    ll ans = 0;
    int h = H+1, w = W+1;
    FORE (line, lines) {
        ll val = line.first, is_vertical = line.second;

        if (is_vertical) {
            ans += val * h;
            w--;
        } else {
            ans += val * w;
            h--;
        }
    }
    return ans;
}

int main() {
    cin >> W >> H;
    REP (i, W) {
        int p; cin >> p;
        lines.push_back(make_pair(p, 1));
    }
    REP (i, H) {
        int q; cin >> q;
        lines.push_back(make_pair(q, 0));
    }
    cout << solve() << endl;
}

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

#define pi 3.141592654
#define fix(n) cout << fixed << setprecision(n)

#define rep(i,a,b) for(int i=a;i<b;i++)
#define ren(i,a,b) for(int i=a;i>=b;i--)

#define si(d)  scanf("%d",&d)
#define sll(d) scanf("%lld",&d)
#define pin(d) printf("%d\n",d)
#define pln(d) printf("%lld\n",d)
#define nl 	   printf("\n")

#define ll long long
#define ull unsigned long long

#define mp make_pair
#define pb push_back
#define fi first
#define se second

#define vi vector<int>
#define pii pair<int,int> 
#define piii pair<pair<int,int>,int> 

#define chalne_de continue
int mod=1000000007;
const int N = 1000005;

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

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	//freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
	int a, b;
	cin >> a >> b;
	a += b;
	if ( a >= 10)
		cout << "error";
	else
		cout << a ;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main () {
    ios_base::sync_with_stdio(false);
    long long ans = 0;
    int N;
    string S;
    cin>>N>>S;
    int r = 0, g = 0, b = 0;
    for(int i=0;i<N;i++) {
        if (S[i] == 'R') r++;
        if (S[i] == 'G') g++;
        if (S[i] == 'B') b++;
    }
 
    int rgb = 0;
    for(int i=0;i<N;i++) {
        for(int j=0;j<N;j++) {
            int k = i + 2 * j;
            if (k >= N) break;
            if (S[i] != S[i + j] && S[i] != S[k] && S[i + j] != S[k]) rgb++;
        }
    }
    ans = (long long)r*g*b-rgb;
    cout<<ans<<"\n";
    return 0;
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
vector<long long>num;
int main(){
 long long numm,nummer,menge;
cin>>numm;
long long cmp=sqrt(numm);
cmp++;
for(int i=cmp;i>0;i--){
	if(numm%i==0){
		nummer=numm/i;
		cout<<nummer+i-2;
		return 0;
	}
	
}
cout<<numm-1;
 return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=2010,inf=1<<28;
struct data{
    int to,ne;
}a[N<<1];
int n,m,cnt=0,ans=0,maxx=0;
int h[N],d[N];
bool bo[N];
inline void add(int x,int y)
{
    a[++cnt].to=y;
    a[cnt].ne=h[x];
    h[x]=cnt;
    return;
}
inline void dfs1(int x,int fa,int y,int z)
{
    if(y>z) return;
    bo[x]=1,cnt++;
    for(int k=h[x];k;k=a[k].ne)
    {
        if(a[k].to==fa) continue;
        dfs1(a[k].to,x,y+1,z);
    }
    return;
}
inline void dfs2(int x,int fa)
{
    d[x]=0;
    for(int k=h[x];k;k=a[k].ne)
    {
        if(a[k].to==fa||bo[a[k].to]==0) continue;
        dfs2(a[k].to,x);
        maxx=max(maxx,d[a[k].to]+1+d[x]);
        d[x]=max(d[x],d[a[k].to]+1);
    }
    return;
}
int main()
{
    scanf("%d%d",&n,&m);
    for(int k=1;k<n;k++)
    {
        int x,y;
        scanf("%d%d",&x,&y);
        add(x,y);
        add(y,x);
    }
    if(m&1)
    {
        for(int k=1;k<=n;k++)
        {
            for(int i=h[k];i;i=a[i].ne)
            {
                if(a[i].to<k) continue;
                memset(bo,0,sizeof bo);
                cnt=maxx=0;
                dfs1(k,a[i].to,0,(m-1)/2);
                dfs1(a[i].to,k,0,(m-1)/2);
                dfs2(k,0);
                if(maxx<=m) ans=max(ans,cnt);
            }
        }
    }
    else
    {
        for(int k=1;k<=n;k++)
        {
            memset(bo,0,sizeof bo);
            cnt=maxx=0;
            dfs1(k,0,0,m/2);
            dfs2(k,0);
//            cout<<k<<" "<<cnt<<" "<<maxx<<endl;
            if(maxx<=m) ans=max(ans,cnt);
        }
    }
    printf("%d\n",n-ans);
    return 0;
}


Measured memory_bytes: 3876
K, N = map(int, input().split())
A = list(map(int, input().split()))
diff_list = []

min_dis = sum(A[:N])
for idx, a in enumerate(A):
    if idx < N-1:
        diff_list.append(A[idx+1]-a)
    else:
        diff_list.append(A[0]+K-A[-1])

print(K - max(diff_list))

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


int main() {
  int N; cin >> N;
  vector<int> P(N);
  rep(i, N) cin >> P[i];
  
  int min=P[0], ans=0;
  rep(i, N) {
    if(P[i] <= min) {
      ans++;
      min = P[i];
    }
  }
  cout << ans << endl;

}


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

using namespace std;

int h[1000006];
int dp[1000006];
int main() {
  int n, k;
  cin >> n;
  k = 2;
  for (int i = 0; i < n; i++) {
    cin >> h[i];
  }
  dp[n - 1] = 0;
  for (int i = n - 2; i >= 0; i--) {
    dp[i] = 1e9;
    for (int j = 1; j <= k && i + j < n; j++) {
      dp[i] = min(dp[i], abs(h[i + j] - h[i]) + dp[i + j]);
    }
  }
  cout << dp[0] << '\n';

  return 0;
}

Measured memory_bytes: 4736
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <limits.h>
#include <math.h>
#include <functional>
#include <bitset>

#define repeat(i,n) for (long long i = 0; (i) < (n); ++ (i))
#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i] << '\n'
#define debugArrayP(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i].first<< " " << x[i].second << '\n'

using namespace std;

typedef long long ll;
typedef pair<int,int> Pii;
typedef vector<int> vint;
typedef vector<ll> vll;
const ll INF = LLONG_MAX/10;
const ll MOD = 1e9+7;

struct edge{
  int src,dst,weight;
};

int main(){
  int L;cin>>L;
  vector<edge> E;
  int N=20;
  for(;N>1&&(1<<(N-1))>L;N--);
  repeat(i,N-1){
    E.push_back({(int)(i+1),(int)(i+2),0});
    E.push_back({(int)(i+1),(int)(i+2),1<<i});
  }
  int n=N-1;
  L-=1<<n;
  int l = 0;
  while(L>0){
    l += 1<<n;
    for(;n>=0&&(1<<n)>L;n--);
    E.push_back({n+1,N,l});
    L -= 1<<n;
  }
  cout << N << " " << E.size()<<endl;
  repeat(i,E.size()){
    cout << E[i].src << " " << E[i].dst << " " << E[i].weight<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
struct ban
{
    long long x, h;
};
bool operator<(const ban& a, const ban& b)
{
    return a.x < b.x;
}

int n;
long long d, aa;
ban a[N];

long long u;
long long q[N];

int main()
{
    scanf("%d%lld%lld", &n, &d, &aa);
    for (int i = 0; i < n; ++i)
        scanf("%lld%lld", &a[i].x, &a[i].h);
    long long yans = 0;
    sort(a, a + n);
    for (int i = 0; i < n; ++i)
    {
        int l = i, r = n - 1;
        int ans;
        while (l <= r)
        {
            int m = (l + r) / 2;
            if (a[m].x <= a[i].x + d * 2)
            {
                ans = m;
                l = m + 1;
            }
            else
                r = m - 1;
        }
        u -= q[i];
        if (u < a[i].h)
        {
            yans += ((a[i].h - u) / aa + !!((a[i].h - u) % aa));
            q[ans + 1] += ((a[i].h - u) / aa + !!((a[i].h - u) % aa)) * aa;
            u += ((a[i].h - u) / aa + !!((a[i].h - u) % aa)) * aa;
        }
    }
    printf("%lld\n", yans);
    return 0;
}


Measured memory_bytes: 4864
// #include"../bits/stdc++.h"
#include<bits/stdc++.h>
using namespace std;
int main() {
    int N, R;
    cin >> N >> R;
    if(N >= 10) {
        cout << R << endl;
    } else {
        cout << R + (100 * (10 - N)) << endl;
    }
}

Measured memory_bytes: 256
#include<stdio.h>

#define N 100005

struct Node{ int p, l, r;};
struct Node T[N];
 
void inorder(int);
void preorder(int);
void postorder(int);
 
int main(int argc,char *argv[]){
  int i, v,n;    
    scanf("%d", &n);
    for ( i = 0; i < n; i++ ) {
      T[i].p = T[i].l = T[i].r = -1;
    }
    for ( i = 0; i < n; i++ ){
      scanf("%d",&v);
      scanf("%d %d",&T[v].l,&T[v].r);   
      T[T[v].l].p = v;
      T[T[v].r].p = v;
    }
     
     
    printf("Preorder\n");
     for(i=0; i<n; i++){
     if(T[i].p == -1)
    preorder(i);
    }
    printf("\nInorder\n");
    for(i=0; i<n; i++){
      if(T[i].p == -1)
    inorder(i);
    }
    printf("\nPostorder\n");
    for(i=0; i<n; i++){ 
      if(T[i].p == -1)
    postorder(i);
    }
    printf("\n");
    
    return 0;  
}

void inorder(int u){
  if(u != -1){
    inorder(T[u].l);
    printf(" %d",u);   
    inorder(T[u].r); 
  }
}
void preorder(int u){
  if(u != -1){
    printf(" %d",u);  
    preorder(T[u].l);
    preorder(T[u].r);
  }
}

void postorder(int u){
  if(u != -1){
    postorder(T[u].l);
    postorder(T[u].r);
    printf(" %d",u);
  }
}

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

int main() {
  int N;
  cin >> N;
  
  vector<int> A(N);
  for (int i = 0; i < N; i++){
  	cin >> A.at(i);
  }
  int max = 0, next = 0, id = 0;
  
  for (int i = 0; i < N; i++){
    if (A.at(i) >= max) {
      next = max;
      max = A.at(i);
      id = i;
    }
    else if(A.at(i) >= next){
      next = A.at(i);
    }
  }
  
  for (int i = 0; i < N; i++){
    if (id == i){
      cout << next << endl;
    }
    else{
      cout << max << endl;
    }
  }
}

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

long long n, k;
vector<long long> p;

long double solve();

int main() {
  cout << fixed << setprecision(10);
  cin >> n >> k;
  p.resize(n);
  for(int i = 0; i < n; ++i) cin >> p[i];
  cout << solve() << endl;
  return 0;
}

long double solve() {
  long double res = 0, now = 0;
  for(int i = 0; i < n; ++i) {
    if(i >= k)
      now -= (long double)(long double)(p[i - k] + 1) *
             p[i - k] / 2 / p[i - k];
    now += (long double)(p[i] + 1) * p[i] / 2 / p[i];
    res = max(res, now);
  }
  return res;
}

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

typedef pair<int,int> P;
#define ll long long
#define ld long double
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define sz(x) ((int)(x).size())
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)

const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
int main()
{
  string s;cin >> s;
  for(auto &&i: s)
  {
    if(i=='7')
    {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  	
    

}

Measured memory_bytes: 3564
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;
using static AtCoderTemplate.MyLibrary;

namespace AtCoderTemplate
{
    class Program
    {
        static void Main (string[] args)
        {
            string[] str;

            while (true)
            {
                str = Console.ReadLine ().Split (' ');

                int x = int.Parse (str[0]);
                int y = int.Parse (str[1]);

                if (x == 0 && y == 0) break;

                if (x <= y) Console.WriteLine (x + " " + y);
                else Console.WriteLine (y + " " + x);
            }

        }
    }

    class MyLibrary
    {

        // 自作の関数
        public static int MyFunction (int n)
        {
            return 0;
        }
    }
}


Measured memory_bytes: 15892
#include<string.h>

int main(void){

	int i,j;
	int q;
	int x, y;

	char str[1000];
	char str2[10];
	char w[1000];
	char r;

	scanf("%s", str);
	scanf("%d", &q);

	/* ?????????strstr?????????????????????0???????????¨?????? */
	for(i=0; i<q; i++){
		scanf("%s", str2);

		if(strcmp(str2, "replace")==0){
			scanf("%d %d %s", &x, &y, w);
				for(j=x; j<=y; j++){
				str[j]=w[j-x];
			}								/* strstr???a???????????????b??????????????§????????? */
		}

	else if(strcmp(str2, "reverse")==0){
		scanf("%d %d",&x, &y);
			while(x<y){
				r=str[x];
				str[x]=str[y];
				str[y]=r;
				x++;
				y--;
			}								/* strstr???a???????????????b??????????????§???????????? */
		}

	else if(strcmp(str2, "print")==0){
		scanf("%d %d",&x,&y);
			for(j=x; j<=y; j++){
				printf("%c", str[j]);
			}								/* strstr???a???????????????b??????????????§???p????????? */
			printf("\n");
		}
	}

	return 0;
}

Measured memory_bytes: 576
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define ld long double
#define vec vector<ll>
#define ms multiset<ll>
#define f(i,x,n) for(int i=x;i<n;i++)
#define int long long
#define mod 1000000007
#define endl "\n"
void fastio()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
}
int32_t main()
{
	fastio();
	string s;
	cin>>s;
	int n=s.length();
	int dp[n+1][13];
	memset(dp,0,sizeof(dp));
	if(s[0]=='?')
	{
		f(i,0,10)
		{
			dp[0][i]=1;
		}
	}
	else
	{
		dp[0][s[0]-'0']=1;
	}
	f(i,1,n)
	{
		if(s[i]!='?')
		{
			f(j,0,13)
			{
				int k=s[i]-'0';
				int res=(j*10+k)%13;
				dp[i][res]=(dp[i][res]+dp[i-1][j])%mod;
			}
			// f(j,0,13)
			// {
			// 	dp[i][j]=(dp[i][j]+dp[i-1][j])%mod;
			// }
		}
		else
		{
			f(j,0,13)
			{
				f(k,0,10)
				{
					int res=(j*10+k)%13;
					dp[i][res]=(dp[i][res]+dp[i-1][j])%mod;
				}
			}
		}
	}
	// f(i,0,n)
	// {
	// 	f(j,0,13)
	// 	cout<<dp[i][j]<<" ";
	// 	cout<<endl;
	// }
	cout<<dp[n-1][5];
}

Measured memory_bytes: 10604
'use strict'

function Main(input) {

  input = input.trim().split('\n')
  const N = parseInt(input[0])
  const p = input[1].split(' ').map(s => parseInt(s))

  let count = 0
  let min = Infinity
  for(let i = 0; i < N; ++i) {
    if(p[i] < min) {
      min = p[i]
      count++
    }
  }
  console.log(count)

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

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

int main(){
	ll n;
	cin >> n;
	vector<int> a(0);
	rep(i, 26) rep(j, 16){
		a.push_back(i*4+j*7);
	}
	sort(a.begin(), a.end());
	int f = 0;
	rep(i, a.size()){
//		cout << a.at(i) << ' ';
		if(a.at(i) == n) f = 1;
	}
	if(f == 1){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
S = gets.chomp
T = S[0]!=?< ? '<'+S : S
s = p0 = 0
until p0 == T.size
	p1 = T.index('>', p0)||T.size
	p2 = T.index('<', p1)||T.size
	l, r = p1-p0, p2-p1
	s += l*(l+1) + r*(r+1) - 2*(l<r ? l : r)
	p0 = p2
end
p s/2


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

//#pragma GCC optimize("O3")
//#pragma GCC target("sse4")

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define ITER(it, a) for(__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a, value) memset(a, value, sizeof(a))

#define SZ(a) (int)((a).size())
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;

const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = (LL)INF * INF;

int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	//freopen("In.txt", "r", stdin);
	LL n, k;
	cin >> n >> k;
	if(k & 1)
	{
		cout << (n / k) * (n / k) * (n / k);
		return 0;
	}
	LL cntOdd = 0, cntEven = 0;
	k /= 2;
	FOR(i, 1, n + 1)
	{
		if(i % k == 0)
		{
			if((i / k) & 1)
				cntOdd++;
			else
				cntEven++;
		}
	}
	cout << cntOdd * cntOdd * cntOdd + cntEven * cntEven * cntEven;
	return 0;
}

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

int main() {
  char c;
  cin >> c;
  if((c=='a')||(c=='i')||(c=='u')||(c=='e')||(c=='o'))
    cout << "vowel" << endl;
  else
    cout << "consonant" << endl;
}


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

void push(int);
int pop();

int top;
int d[1000];

int main()
{
  
  char a[100];
  int b, c;

  top = 0;
  
  while(scanf("%s",a)!=EOF){
    if(a[0]=='-'){
      b = pop();
      c = pop();
      push(c-b);
    }
    else if(a[0]=='+'){
      b = pop();
      c = pop();
      push(b+c);
    }
    else if(a[0]=='*'){
      b = pop();
      c = pop();
      push(b*c);
    }
    else push(atoi(a));
  }

  printf("%d\n",pop());

  return 0;

}

void push(int a)
{
  d[++top] = a;
}

int pop()
{
  top--;
  return d[top+1];
}




Measured memory_bytes: 2052
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <iostream>
using namespace std;

typedef long long ll;
const int MOD = 1e9 + 7;
const int N = 1e5 + 5;
int x[N], y[N];
int dx[N], dy[N];
int n, m;

void add_mod(ll &a, ll b) {
	a += b;
	if (a >= MOD) a -= MOD;
}

void sub_mod(ll &a, ll b) {
	a -= b;
	if (a < 0) a += MOD;
}

int main() {
	scanf("%d%d", &n, &m);
	for (int i=1; i<=n; ++i) {
		scanf("%d", &x[i]);
	}
	for (int i=1; i<=m; ++i) {
		scanf("%d", &y[i]);
	}
	sort(x+1, x+n+1);
	sort(y+1, y+m+1);
	for (int i=1; i<n; ++i) {
		dx[i] = x[i+1]-x[i];
	}
	for (int i=1; i<m; ++i) {
		dy[i] = y[i+1]-y[i];
	}
	n--; m--;
	ll sx = 0, sy = 0;
	ll tmp = 0;
	for (int i=1; i<=n; ++i) add_mod(tmp, dx[i]);
	for (int i=n; i>=1; --i) {
		add_mod(sx, tmp);
		sub_mod(tmp, dx[i]);
	}
	tmp = sx;
	for (int i=2; i<=n; ++i) {
		sub_mod(tmp, (ll)(n-i+2)*dx[i-1]%MOD);
		add_mod(sx, tmp);
	}

	tmp = 0;
	for (int i=1; i<=m; ++i) add_mod(tmp, dy[i]);
	for (int i=m; i>=1; --i) {
		add_mod(sy, tmp);
		sub_mod(tmp, dy[i]);
	}
	tmp = sy;
	for (int i=2; i<=m; ++i) {
		sub_mod(tmp, (ll)(m-i+2)*dy[i-1]%MOD);
		add_mod(sy, tmp);
	}

	printf("%lld\n", sx*sy%MOD);
	return 0;
}


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

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>
#include<unordered_set>
#include<bitset>
#include<complex>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

int N;
int imos[100010];

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

	cin >> N;
	int A;
	rep(i, 0, N)
	{
		cin >> A;
		A++;
		imos[A - 1]++;
		imos[A + 2]--;
	}

	int ans = 0;
	rep(i, 1, 100005)
	{
		imos[i] += imos[i - 1];
		chmax(ans, imos[i]);
	}

	cout << ans << endl;

	return 0;
}

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

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

fn main() {
    let s: String = read();
    let t: String = s.chars().rev().collect::<_>();

    let mut n: usize = 0;
    for i in 0..s.len() { n += if s.as_bytes()[i] != t.as_bytes()[i] { 1 } else { 0 }; }
    println!("{}", n / 2);
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
  
int main() {
  string N;
  cin >> N;
  int K;
  cin >> K;
  vi dp(K+1,0);
  int b = 0;
  rep(ni,sz(N)) {
    int x = N[ni]-'0';
    vi dp2(K+1,0);
    // ok -> 0
    rep(k,K+1) {
      dp2[k] += dp[k];
    }
    // ok -> 1~9
    rep(k,K) {
      dp2[k+1] += dp[k] * 9;
    }
    // ? -> 
    if(b <= K) {
      rep(n,10) {
        if(n < x) {
          if(n==0) {
            dp2[b] += 1;
          } else if(b+1 <= K) {
            dp2[b+1] += 1;
          }
        }
      }
      if(x > 0) {
        b++;
      }
    }
    dp = dp2;
  }
  int ans = dp[K];
  if(b == K) {
    ans++;
  }
  cout << ans << endl;
  return 0;
}

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

int main() {
  //定義一覧
  int N;
  int A;
  int C = 0;
  int tmp;
  
  //入力
  cin >> N;
  //繰り返し
  for(int i = 0; i < N; i++){
  	//N個めの数字Aの入力
    cin >> A;
    while(A % 2 == 0){
      A /= 2;
      C += 1;
    }
    if(i == 0){
      tmp = C;
    }else if(tmp > C){
      tmp = C;
    }
    C = 0;
  }
  
  cout << tmp << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <climits>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <deque>
#define INF_INT (INT_MAX / 2)
#define INF_LONG (LONG_MAX / 2)
//#define DEBUG true
#define DEBUG false
using namespace std;

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

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

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

  ll count = 0;
  for(int i = 0; i < n; i++){
    if(a[i] < b[i]){
      count += (b[i] - a[i]) / 2;
    }
    else{
      count -= a[i] - b[i];
    }
  }

  if(count >= 0) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 384
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author hakamada
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        ABC109_1 solver = new ABC109_1();
        solver.solve(1, in, out);
        out.close();
    }

    static class ABC109_1 {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int A = in.nextInt();
            int B = in.nextInt();

            for (int i = 1; i <= 3; i++) {
                if (((A * B * i) % 2) != 0) {
                    out.println("Yes");
                    return;
                }
            }
            out.println("No");
        }

    }
}



Measured memory_bytes: 22228
import itertools
N, M, Q = map(int, input().split())
abcd = [list(map(int, input().split())) for _ in range(Q)]
M_chr = []
for i in range(1,M+1):
    M_chr.append(str(i))
As = list(itertools.combinations_with_replacement(M_chr, N))
pointA_max = 0
for i, A in enumerate(As):
    pointA = 0
    for i in range(Q):
        a = abcd[i][0]
        b = abcd[i][1]
        c = abcd[i][2]
        d = abcd[i][3]
        if int(A[b-1])-int(A[a-1]) == c:
            pointA = pointA + d
    if pointA_max < pointA:
        pointA_max = pointA
print(pointA_max)

Measured memory_bytes: 85000
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll> 
#define P pair<ll,ll>
#define rep(i,n) for(ll (i)=0; (i)<(n); ++(i))
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n,ans=0;cin>>n;
  for(ll i=1;i*i<=n;++i) {
    if((n-i)%i==0&&(n-i)/i>i) ans+=(n-i)/i;
  }
  print(ans);
  return 0;
}


Measured memory_bytes: 256
N, H = map(int,input().split())
a, b = [0 for i in range(N)], [0 for i in range(N)]
for i in range(N):
    a[i], b[i] = map(int,input().split())

a_max = max(a)
b.sort()
ans = 0
for i in range(N-1,-1,-1):
    if b[i] > a_max:
        H -= b[i]
        ans += 1
        if H <= 0:
            break
    else:
        ans += H // a_max
        if H%a_max != 0:
            ans += 1
        H = 0
        break

if H > 0:
    ans += H // a_max
    if H%a_max != 0:
        ans += 1

print(ans)


Measured memory_bytes: 11360
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
// 解説聞いた後にコーディングした
int main(void){
    int n, m, i, j;
    cin >> n >> m;
    vector<int> x(m), diff(m - 1);
    
    for (i = 0; i < m; i++) cin >> x.at(i);
    sort(x.begin(), x.end());

    for (i = 0; i < (m - 1); i++) diff.at(i) = (x.at(i + 1) - x.at(i));
    sort(diff.begin(), diff.end(), greater<int>() );

    for (i = 0; i < n - 1 && i < diff.size(); i++) diff.at(i) = 0;
    cout << accumulate(diff.begin(), diff.end(), 0) << endl;      
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
		using namespace std;
		
		typedef long long ll;
		#define pi 3.14159265 
		#define EPS 1e-8
		
		#define mod 1000000007
		#define fi first
		#define se second
		#define mp make_pair
		#define pb push_back
		#define endl "\n"

		const ll INF=(ll)2e18;
		
		long long binpow(long long a, long long b, long long m) {
		a %= m;
		long long res = 1;
		while (b > 0) {
			if (b & 1)
				res = res * a % m;
			a = a * a % m;
			b >>= 1;
		}
		return res;
		}
		
		int main()
		{
			 ios_base::sync_with_stdio(false);
			 cin.tie(NULL);
			
			ll n,k,c;
			cin>>n>>c>>k;
			string s;
			cin>>s;
			vector<ll> pref(n+1,0);
			vector<ll> suff(n+2,0);
			for(ll i=1;i<=n;i++)
			{
				
				if(s[i-1]=='o')
				{
					pref[i]=max(pref[i-1],pref[i]);
					if((i-k-1)>=0)
					{
						pref[i]=max(pref[i],pref[i-k-1]+1);
					}
				}
				else
					pref[i]=pref[i-1];
				pref[i]=max(pref[i],1LL);
			}
			for(ll i=n;i>0;i--)
			{
				
				if(s[i-1]=='o')
				{
					suff[i]=max(suff[i+1],suff[i]);
					if((i+k+1)<=n)
					{
						suff[i]=max(suff[i],suff[i+k+1]+1);
					}
				}
				else
					suff[i]=suff[i+1];
				suff[i]=max(suff[i],1LL);
			}
			for(ll i=1;i<=n;i++)
			{
				ll val1=0,val2=0;
				if((i-k-1)>=0)
					val1=pref[i-k-1];
				if((i+k+1)<=n)
					val2=suff[i+k+1];
				if(s[i-1]=='o')
				{
					if((pref[i-1]+suff[i+1])<c)
					{
						if((val1+val2+1)>=c)
							cout<<i<<endl;
					}
				}
			}
		}


Measured memory_bytes: 5012
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c;
  cin >> a >> b >> c;
  int i,sum=0;
  for(i=1;i<=b;i++){
    sum+=a%b;
    sum=sum%b;
    if(sum==c){
      cout << "YES";
      return 0;
    }
  }
  cout<< "NO";
}

Measured memory_bytes: 256
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    N = int(readline())

    ans = pow(10, N, MOD) - 2 * pow(9, N, MOD) + pow(8, N, MOD)
    print(ans % MOD)


if __name__ == '__main__':
    main()


Measured memory_bytes: 61708
#include<cstdio>
#include<string>
#include<iostream>
using namespace std;

int main(){
	while (1){
		int u = 1, d = 6, e = 3, w = 4, n = 5, s = 2;
		int ans = 1;
		int N;
		scanf("%d", &N);
		if (N == 0)return 0;
		for (int i = 0; i < N; i++){
			string dir;
			cin >> dir;
			int a;
			if (dir == "North"){
				a = u;
				u = s, s = d, d = n;
				n = a;
			}
			if (dir == "East"){
				a = u, u = w, w = d, d = e, e = a;
			}
			if (dir == "Right"){
				a = s, s = e, e = n, n = w, w = a;
			}
			if (dir == "Left"){
				a = s, s = w, w = n, n = e, e = a;
			}
			if (dir == "West"){
				a = u, u = e, e = d, d = w, w = a;
			}
			if (dir == "South"){
				a = u, u = n, n = d, d = s, s = a;
			}
			ans += u;
		}
		printf("%d\n", ans);
	}
}

Measured memory_bytes: 1252