akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)

int main() {
    int h, w, n;
    cin >> h >> w >> n;
    int maxedge = max(h, w);
    cout << (n + maxedge - 1) / maxedge << endl;
}

Measured memory_bytes: 256
def main():
    h,w=map(int,input().split())
    l=[list(map(int,input().split())) for _ in range(h)]
    ans=[]
    cnt=0
    for i in range(h):
        for j in range(w-1):
            if l[i][j]%2==1:
                l[i][j]-=1
                l[i][j+1]+=1
                cnt+=1
                ans.append([i+1,j+1,i+1,j+2])
    for i in range(h-1):
        if l[i][w-1]%2==1:
            l[i][w-1]-=1
            l[i+1][w-1]+=1
            cnt+=1
            ans.append([i+1,w,i+2,w])
    print(cnt)
    for i in ans:
        print(*i)
        
if __name__ == '__main__':
    main()

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

#define MAX 1000000

int n, H[MAX];

void maxHeap(int i) {
    int left = i * 2;
    int right = i * 2 + 1;
    
    if (left > n) return;
    
    int max = left;
    if (right <= n) max = H[left] >= H[right] ? left : right;
    max = H[i] >= H[max] ? i : max;
    
    if (max != i) {
        std::swap(H[i], H[max]);
        maxHeap(max);
    }
}

int main() {
    int key;
    
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
        scanf("%d", &key);
        H[i] = key;
    }
    
    for (int i = n/2; i >= 1; i--) {
        maxHeap(i);
    }
    
    for (int i = 1; i <= n; i++) {
        printf(" %d", H[i]);
    }
    printf("\n");
    
    return 0;
}



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

int main() {
  int n, a;
  cin >> n;
  cin >> a;
  
  if (n <= a) {
    cout << "Yes";
  }
  else if (n%500 <= a) {
    cout << "Yes";
  }
  else {
    cout << "No";
  }
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int a[20];
int x[20][20];
int y[20][20];

int max_t(int r,int l)
{
	if(r >= l){
		return r;
	}
	else{
		return l;
	}
}

int counter(int bit)
{
	if(bit == 0){
		return 0;
	}
	return counter(bit >> 1) + (bit & 1);
}

int main()
{
	int n;
	int max=0;
	int num;
	int flag = 0;
	cin >> n;

	for(int i=0;i<n;i++){
		cin >> a[i];
		for(int j=0;j<a[i];j++){
			cin >> x[i][j] >> y[i][j];
		}
	}

	//bitが立ってるところが正しいことを言っている人
	for(int bit=0;bit<(1<<n);bit++){
		for(int i=0;i<n;i++){
			if(!(bit & (1 << i))){
				continue;
			}
			for(int j=0;j<a[i];j++){
				if( ((bit >> x[i][j]-1)&1) ^ y[i][j] ){
					flag = 1;
					break;
				}
			}
		}
		if(flag == 0){
			num = counter(bit);
			max = max_t(max,num);
		}
		flag = 0;
	}

	cout << max << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
using namespace std;
long int mod = 1000000007;

long int mul(long int A, long int B){
	return (A * B) % mod;
}
long int pl(long int A, long int B){
	return (A + B) % mod;
}
long int mi(long int A, long int B){
	long int ans =  (A - B) % mod;
	if(ans < 0) ans += mod;
	return ans;
}

long int pow(long int P, long int N){
	if(N == 0) return 1;
	if(N == 1) return P;
	return pow(P*P,N / 2) * pow(P, N % 2);
}

long int dp[4][4][4][98];

int main(){
	long int N;
	cin >> N;
	for(int i=0;i<4;i++){
		for(int j=0;j<4;j++){
			for(int k=0;k<4;k++){
				if(i == 0 && j == 1 && k == 2) dp[i][j][k][0] = 0;
				else if(i == 0 && j == 2 && k == 1) dp[i][j][k][0] = 0;
				else if(i == 2 && j == 0 && k == 1) dp[i][j][k][0] = 0;
				else dp[i][j][k][0] = 1;
			}
		}
	}
	for(int n=1;n<=N-3;n++){
		for(int j=0;j<4;j++){
			for(int k=0;k<4;k++){
				long int sum0 = 0;
				long int sum1 = 0;
				long int sum2 = 0;
				long int sum3 = 0;
				for(int i=0;i<4;i++){
					sum0 = pl(sum0,dp[i][j][k][n-1]);
					sum3 = pl(sum3,dp[i][j][k][n-1]);
					if(!(i == 0 && k == 2) && !(i == 0 && j == 2) && !(j == 0 && k == 2) && !(j == 2 && k == 0)){
						sum1 = pl(sum1,dp[i][j][k][n-1]);
					}
					if(!(j == 0 && k == 1)){
						sum2 = pl(sum2,dp[i][j][k][n-1]);
					}
				}
				dp[j][k][0][n] = sum0;
				dp[j][k][1][n] = sum1;
				dp[j][k][2][n] = sum2;
				dp[j][k][3][n] = sum3;
			}
		}
	}
	long int ans = 0;
	for(int i=0;i<4;i++){
		for(int j=0;j<4;j++){
			for(int k=0;k<4;k++){
				ans = pl(ans,dp[i][j][k][N-3]);
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<climits>
#include<map>

#define MAX_V 1000000
#define INF 10000000
#define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); it++)

using namespace std;

typedef unsigned int uint;
typedef pair<int, uint> P;


uint encode(vector<int> vec){
    uint res=0;
    for (int i=0;i<vec.size();i++)
        res=(res<<4)+vec[i];
 
    return res;
}
 
vector<int> decode(uint a){
    vector<int> res;
    for (;a>0;a>>=4)res.push_back(a & 0xf);
 
	reverse(res.begin(),res.end());
	
    return res;
}
 
struct edge{uint to, cost; };
 
int V;
int c[10][10],ans;
map<uint,int>d;
 
void dijkstra(uint s){
	d.clear();
  priority_queue<P, vector<P>, greater<P> >que;
  d[s] = 0;
  que.push(P(0, s));
 
  while(!que.empty()){
 
    P p = que.top();
    que.pop();
    uint v = p.second;
    if(d[v] < p.first)continue;

    vector<int>tmp=decode(v);
  
    for(int i=0;i<V;i++){
      for(int j=i+1;j<V;j++){
			edge e;
			e.cost=c[tmp[i]][tmp[j]];
			swap(tmp[i],tmp[j]);
			e.to=encode(tmp);
 
      	if(!d.count(e.to) || d[e.to] > d[v]+e.cost){

      		d[e.to] = d[v]+e.cost;
      		que.push(P(d[e.to], e.to));
    	}
    	swap(tmp[i],tmp[j]);
      }
    }
  }
}
 
 
int main(void){
 
  cin >> V;
 
  for(int i=1;i<=V;i++){
    for(int j=1;j<=V;j++){
      cin >> c[i][j];
    } 
  }
	
 
  vector<int>v;
  for(int i=1;i<=V;i++)v.push_back(i);
 
  uint s=encode(v);
 
  dijkstra(s);
 
  ans=0;
  foreach(i,d)ans=max(ans,i->second);
  cout << ans << endl;
 
  return 0;
}

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

using namespace std;

int main(){
    string S;
    cin >> S;
    
    int len = S.length();
    
    map<char, int> count;
    for(int i = 0; i < len; ++i){
        count[S[i]]++;
    }
    
    char tmp = 'a';
    for(int i = 0; i < 26; ++i){
        char tmp = 'a';
        tmp += i;
        if(count[tmp] == 0) {cout << tmp << endl; return 0;}
    }
    cout << "None" << endl;
    
}

Measured memory_bytes: 512
//#define _GRIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
 
signed main() {
    string n;
    cin >> n;
    string t = n;
    reverse(t.begin(), t.end());
    if(n==t) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}
 

Measured memory_bytes: 256
arr = gets.chomp.split(" ").map(&:to_i)
count = 0
all_same = false
until all_same == true
  if arr.max - arr.min >= 2
    arr[arr.index(arr.min)] += 2
    count += 1
  elsif arr.max - arr.min >= 1
    if arr.select {|n| n == arr.min}.length == 2
      count += 1
      all_same = true
    else
      count += 2
      all_same = true
    end
  else
    all_same = true
  end
end
puts count

Measured memory_bytes: 1788
"""
5 2 4
100
90
82
70
65
"""

while True:
    m, nmin, nmax = map(int, input().split())
    if m == 0:
        break
    scores = [int(input()) for _ in range(m)]
    # print(scores)

    dif_score = [scores[0]-scores[1]]
    for i in range(1, m-1):
        dif_score.append(scores[i]-scores[i+1])

    dif_score = dif_score[nmin-1:nmax]

    # print(dif_score)

    max_dif_score = max(dif_score)

    ans = -1
    for i in range(len(dif_score)):
        if dif_score[i] == max_dif_score:
            ans = i

    print(ans+nmin)



Measured memory_bytes: 5636
/**
 *      ABC 90 B
 *      author  : kyomukyomupurin
 *      created : 2018-09-01 02:04:16
**/

#include <bits/stdc++.h>
using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int A, B; cin >> A >> B;
    int count = 0;

    for (int i = A; i <= B; ++i){
        string str = to_string(i);
        if (str[0] == str[4] && str[1] == str[3]){
            ++count;
        }
    }
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pl;
typedef vector<pl> vp;
#define fore(i,a,b) for(ll i=(ll)(a);i<=(ll)(b);++i)
#define rep(i,n) fore(i,0,(n)-1)
#define rfore(i,a,b) for(ll i=(ll)(b);i>=(ll)(a);--i)
#define rrep(i,n) rfore(i,0,(n)-1)
#define all(x) (x).begin(),(x).end()
const ll INF=1001001001;
const ll LINF=1001001001001001001;
const ll D4[]={0,1,0,-1,0};
const ll D8[]={0,1,1,0,-1,-1,1,-1,0};
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 ll MOD = 1000000007;

template< int mod >
struct ModInt {
  int x;

  ModInt() : x(0) {}

  ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}

  ModInt &operator+=(const ModInt &p) {
    if((x += p.x) >= mod) x -= mod;
    return *this;
  }

  ModInt &operator-=(const ModInt &p) {
    if((x += mod - p.x) >= mod) x -= mod;
    return *this;
  }

  ModInt &operator*=(const ModInt &p) {
    x = (int) (1LL * x * p.x % mod);
    return *this;
  }

  ModInt &operator/=(const ModInt &p) {
    *this *= p.inverse();
    return *this;
  }

  ModInt operator-() const { return ModInt(-x); }

  ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }

  ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }

  ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }

  ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }

  bool operator==(const ModInt &p) const { return x == p.x; }

  bool operator!=(const ModInt &p) const { return x != p.x; }

  ModInt inverse() const {
    int a = x, b = mod, u = 1, v = 0, t;
    while(b > 0) {
      t = a / b;
      swap(a -= t * b, b);
      swap(u -= t * v, v);
    }
    return ModInt(u);
  }

  ModInt pow(int64_t n) const {
    ModInt ret(1), mul(x);
    while(n > 0) {
      if(n & 1) ret *= mul;
      mul *= mul;
      n >>= 1;
    }
    return ret;
  }

  friend ostream &operator<<(ostream &os, const ModInt &p) {
    return os << p.x;
  }

  friend istream &operator>>(istream &is, ModInt &a) {
    int64_t t;
    is >> t;
    a = ModInt< mod >(t);
    return (is);
  }

  static int get_mod() { return mod; }
};

using modint = ModInt< MOD >;

void solve(long long N, long long X, std::vector<long long> S){
    sort(all(S),greater<ll>());
    vector<vector<modint>> dp(N+1,vector<modint>(100005));
    dp[0][X]=1;
    rep(i,N){
        modint p=modint(1)/modint(N-i);
        modint np=modint(1)-p;
        rep(j,100001){
            dp[i+1][j%S[i]]+=p*dp[i][j];
            dp[i+1][j]+=np*dp[i][j];
        }
    }
    modint ans;
    rep(i,100001)ans+=dp[N][i]*i;
    rep(i,N)ans*=i+1;
    cout<<ans<<endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    long long X;
    scanf("%lld",&X);
    std::vector<long long> S(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&S[i]);
    }
    solve(N, X, std::move(S));
}


Measured memory_bytes: 81144
#include <iostream>
#include <map>
#include <string>
using namespace std;
typedef long long ll;
ll n, m, a[10];
string str[10010], test[10];
map<ll, ll> mp;
map<ll, string> np;
bool jud[10010], h[10];
int main(void)
{
	mp[1] = 2, mp[2] = 5, mp[3] = 5, mp[4] = 4;
	mp[5] = 5, mp[6] = 6, mp[7] = 3, mp[8] = 7;
	mp[9] = 6;
	np[1] = "1", np[2] = "2", np[3] = "3", np[4] = "4", np[5] = "5";
	np[6] = "6", np[7] = "7", np[8] = "8", np[9] = "9";
	jud[0] = true;
	cin >> n >> m;
	for (ll i = 0; i < m; i++) cin >> a[i];
	for (ll i = 2; i <= n; i++)
	{
		if (i > 10) str[i - 10] = "9";
      	for (int j = 0; j < m; j++) h[j] = false;
		for (ll j = 0; j < m; j++)
		{
			if (i < mp[a[j]]) continue;
			if (!jud[i - mp[a[j]]]) continue;
			h[j] = true;
			test[j] = str[i - mp[a[j]]] + np[a[j]];
		}
		ll len = 0, num = -1;
		for (ll j = 0; j < m; j++)
		{
			if (!h[j]) continue;
			if (test[j].length() > len)
			{
				len = test[j].length();
				num = j;
			}
			else if (test[j].length() == len)
			{
				if (test[j] > test[num])
				{
					num = j;
				}
			}
		}
		if (num == -1) continue;
		str[i] = test[num];
		jud[i] = true;
	}
	for (ll i = 0; i < str[n].length(); i++) cout << str[n][i];
	cout << endl;
}


Measured memory_bytes: 44032
//#define _GLIBCXX_DEBUG

#include<bits/stdc++.h>
using namespace std;
const int INF= 1e9+5;
typedef long long ll;

int main(){
  string n;
  cin>>n;
  if(n[0]==n[2])cout<<"Yes"<<endl;
  else cout<<"No"<<endl;

}

Measured memory_bytes: 256
#!usr/bim/python
#! -*- coding: utf-8 -*-

n = raw_input()
n = int(n)
s = n + 0
h = 0
i = 8
while i >= 0:
    t = s / (10 ** i)
    h += t
    s -= t * (10 ** i)
    #print t,
    i -= 1

#print ""
#print h

if n % h == 0:
    print "Yes"
else:
    print "No"
    


Measured memory_bytes: 2568
I = lambda: map(int, input().split())
nums = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
minf = -float('inf')
n, _ = I()
*A, = sorted(I(), reverse = True)
digs = [0]*(n+1)+[-1]*9
for i in range(1, n+1):
    d = []
    for a in A :
        before = i-nums[a]
        d.append(minf if before < 0 else digs[before]+1)
    digs[i] = max(d)
ans = []
while n > 0:
    for a in A:
        if digs[n-nums[a]] == digs[n]-1:
            ans.append(a)
            n -= nums[a]
            break
print(*ans, sep = '')

Measured memory_bytes: 4340
N = int(input())
H = [int(x) for x in input().split(' ')]

current =H[0]
count = 0
maxCount = 0

for i in range(1,N):
    if H[i] <= H[i-1]:
        count += 1
    else:
        maxCount = max(maxCount, count)
        count = 0
maxCount = max(maxCount, count)

print(maxCount)

Measured memory_bytes: 14224
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;
typedef long long ll;

int main(){
	ios_base::sync_with_stdio(false);
	int n, m, d;
	cin >> n >> m >> d;
	vector<ll> a(m);
	for(int i = 0; i < m; ++i){ cin >> a[i]; }
	for(int i = 0; i < d; ++i){
		vector<ll> b(m);
		for(int j = 0; j < m; ++j){ cin >> b[j]; }
		ll mod = 1, x = 0;
		for(int j = 0; x <= n && j < m; ++j){
			if(b[j] < 0){ continue; }
			bool accept = false;
			for(int k = 0; k < a[j]; ++k){
				const ll t = mod * k + x;
				if(t <= n && t % a[j] == b[j]){
					const ll g = __gcd(mod, a[j]);
					mod *= a[j] / g;
					x = t % mod;
					accept = true;
					break;
				}
			}
			if(!accept){
				cout << -1 << endl;
				return 0;
			}
		}
		if(x > n){
			cout << -1 << endl;
			return 0;
		}
		const ll t = n / mod;
		if(t * mod + x <= n){
			n = t * mod + x;
		}else{
			n = (t - 1) * mod + x;
		}
	}
	cout << n << endl;
	return 0;
}

Measured memory_bytes: 1208
n = int(input())
s = list(input())

l = [[0, 0] for i in range(n + 1)]
for i in range(n):
    preB, preW = l[i]
    if s[i] == '#':
        l[i + 1] = [preB + 1, preW]
    else:
        l[i + 1] = [preB, preW + 1]

SUM_W = l[-1][1]
ans = 10 ** 10
for i, j in l:
    temp = i + SUM_W - j
    if temp < ans:ans = temp
print(ans)

Measured memory_bytes: 31424
#include<bits/stdc++.h>
#define de(x) cout<<#x<<"="<<x<<endl;
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define repd(i,a,b) for(int i=a;i>=(b);--i)
#define mt(a,b) memset(a,b,sizeof(a))
#define fi first
#define se second
#define inf 0x7f
#define pii pair<int,int>
#define pdd pair<double,double>
#define pdi pair<double,int>
#define mp(u,v) make_pair(u,v)
#define sz(a) a.size()
#define ull unsigned long long
#define ll long long
#define pb push_back
#define PI acos(-1.0)
const int mod = 1e9+7;
const int maxn = 1e3+5;
const double EPS = 1e-6;
using namespace std;
int gcd(int a,int b){
	return b==0?a:gcd(b,a%b);
}
int road[105][105];
int v[105][105];
int vis[105];
int n,m;
int dfs(int u){
	int ret=1;
	vis[u]=1;
	rep(i,1,n+1){
		if(!vis[i]&&road[u][i]){
			ret+=dfs(i);
		}
	}
	return ret;
}
int main()
{
	scanf("%d%d",&n,&m);
	mt(vis,0);
	rep(i,0,105)rep(j,0,105) road[i][j]=0,v[i][j]=0;
	int a,b;
	rep(i,0,m){
		scanf("%d%d",&a,&b);
		road[a][b]=road[b][a]=1;
	}
	int ans=0;
	rep(i,1,n+1){
		rep(j,1,n+1){
			if(v[i][j]||v[j][i]) continue;
			if(road[i][j]){
				road[i][j]=road[j][i]=0;
				v[i][j]=v[j][i]=1;
				mt(vis,0);
				int cnt=dfs(1);
//				de(i);
//				de(j);
//				de(cnt); 
				if(cnt!=n) ans++;
				road[i][j]=road[j][i]=1;
			}
		}
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 384
#!/usr/bin/python3
# -*- coding: utf-8 -*-
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

n = int(input())
if n == 1:
    print(0)
else:
    x_list = factorization(n)
    ans = 0
    for x in x_list:
        n = 2
        while True:
            if x[1] < (n * n + n) // 2:
                ans += n - 1
                break 
            n += 1

    print(ans)

Measured memory_bytes: 9492
#include<iostream>
#include<cassert>
#include<stdexcept>
#include<utility>
#include<functional>
#include<numeric>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<array>
#include<stack>
#include<queue>
#include<deque>
#include<vector>
#include<complex>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<string>
#include<bitset>
using namespace std;
using ll=long long;

int main(){
    int n;
    cin>>n;
    vector<string> s(n);
    for(int i=0;i<n;i++) cin>>s[i];
    int res=0;
    for(int i=0;i<n;i++){
        for(int j=0;j+1<s[i].size();j++){
            if(s[i][j]=='A' && s[i][j+1]=='B') res++;
        }
    }
    int a=0,b=0,c=0;
    for(int i=0;i<n;i++){
        if(s[i][0]=='B' && s[i].back()=='A') b++;
        else if(s[i].back()=='A') a++;
        else if(s[i][0]=='B') c++;
    }
    res+=max(b-1,0)+min(a,c);
    if((a>0 || c>0) && b>0) res++;
    cout<<res<<endl;

    
    return 0;
}

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

#include <algorithm>
using namespace std;
struct Fast {
    Fast() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} fast;

long long mod = 1000000007;

long long modpow(long long m, long long n) {
    if (n == 0) return 1;
    if (n % 2 == 0) {
        long long t = modpow(m, n / 2);
        return (t * t) % mod;
    } else {
        return (modpow(m, n - 1) * m) % mod;
    }
}

void yes() {
    cout << "Yes" << endl;
    exit(0);
}
void no() {
    cout << "No" << endl;
    exit(0);
}
#define REP(i, n) for (long long i = 0; i < (n); i++)

struct UnionFind {
    vector<int> parent, size;

    UnionFind(int n) {
        parent.resize(n, -1);
        size.resize(n, 1);
    }
    void unite(int x, int y) {
        if (same(x, y)) {
            return;
        }
        x = root(x);
        y = root(y);
        if (size[x] <= size[y]) {
            swap(x, y);
        }
        parent[y] = x;
        size[x] += size[y];
    }
    bool same(int x, int y) { return (root(x) == root(y)); }
    int root(int x) {
        while (parent[x] != -1) {
            x = parent[x];
        }
        return x;
    }
    int getsize(int x) { return size[root(x)]; }
};

long long n, m, q, ans = 0;
vector<int> a;
vector<int> b;
vector<int> c;
vector<int> d;
vector<int> A;
long long max1 = 0;
void dfs() {
    // REP(i, A.size()) { cout << A[i]; }
    // cout << endl;
    int mv;
    ans = 0;
    if (A.size() == n) {
        REP(i, q) {
            if (A[b[i]] - A[a[i]] == c[i]) {
                ans += d[i];
            }
        }
        if (max1 < ans) {
            max1 = ans;
        }
        return;
    }
    if (A.size() == 0) {
        mv = 1;
    } else {
        mv = A[A.size() - 1];
    }
    for (int i = mv; i <= m; i++) {
        A.push_back(i);
        dfs();
        A.pop_back();
    }
}

signed main() {
    cin >> n >> m >> q;
    a.resize(q);
    b.resize(q);
    c.resize(q);
    d.resize(q);
    REP(i, q) {
        cin >> a[i];
        a[i]--;
        cin >> b[i];
        b[i]--;
        cin >> c[i];
        cin >> d[i];
    }
    dfs();
    cout << max1 << endl;
}

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

using namespace std;

#define rep(i,m,n) for(int (i)=(int)(m);i<(int)(n);i++)
#define rep2(i,m,n) for(int (i)=(int)(n)-1;i>=(int)(m);i--)
#define REP(i,n) rep(i,0,n)
#define REP2(i,n) rep2(i,0,n)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define ll long long
#define ull unsigned long long
#define all(hoge) (hoge).begin(),(hoge).end()
#define en '\n'
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
typedef pair<ll, ll> P;
constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;
constexpr long long MOD = (ll) 1e9 + 7;
typedef vector<ll> Array;
typedef vector<Array> Matrix;
constexpr int loose = 0;
constexpr int tight = 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;
}

struct Edge {
	ll to, cap, rev;
	Edge(ll _to, ll _cap, ll _rev) {
	to = _to; cap = _cap; rev = _rev;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

void add_edge(Graph& G, ll from, ll to, ll cap, bool revFlag, ll revCap) {
	G[from].push_back(Edge(to, cap, (ll)G[to].size()));
	if (revFlag)G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}

void solve(){
	ll n, k;
	cin>>n>>k;
	Array h(n);
	REP(i,n) cin>>h[i];
	
	Array dp(n,INF);
	dp[0]=0;
	REP(i,n){
		rep(j,1,k+1){
			if(i+j>=n) break;
			chmin(dp[i+j],dp[i]+abs(h[i]-h[i+j]));
		}
	}
	cout<<dp[n-1]<<en;
}

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

    solve();
    return 0;
}

Measured memory_bytes: 1792
S = input()

dp = [[0 for _ in range(4)] for _ in range(len(S))]

dp[0][0] = 1
dp[1][1] = 1
for i in range(1, len(S)):

  # 直前1文字 次1文字
  if S[i-1] != S[i]:
    dp[i][0] = max(dp[i-1][0], dp[i-1][2]) + 1

  # 直前1文字 次2文字
  if i < len(S) - 1:
    dp[i+1][1] = max(dp[i-1][0], dp[i-1][2]) + 1

  # 直前2文字 次1文字
  dp[i][2] = max(dp[i-1][1], dp[i-1][3]) + 1

  # 直前2文字 次2文字
  if  2 <= i < len(S)-1 and (S[i-2] != S[i] or S[i-1] != S[i+1]):
    dp[i+1][3] =  max(dp[i-1][1], dp[i-1][3]) + 1


print(max(dp[-1]))
    



Measured memory_bytes: 51884
import sys
import copy

S = input()
nN = len(S)
nAns = [ 0 for i in range(nN)]
nAnsT = [ 0 for i in range(nN)]
nAnsR = [ 0 for i in range(nN)]

nCnt = S.count('RL')
nRLp = [ 0 for i in range(nCnt)]

nTmpP = 0
for i in range(nCnt):
  nTmp = S.find('RL',nTmpP)
  nRLp[i] = nTmp
  nTmpP = nTmp + 1

nCntE = S.count('LR')
nLRp = [ 0 for i in range(nCntE)]
nTmpP = 0
for i in range(nCntE):
  nTmp = S.find('LR',nTmpP)
  nLRp[i] = nTmp
  nTmpP = nTmp + 1
  
# print(nRLp)
# print(nLRp)

nTmpS = 0
for i in range(nCnt):
  nTmpR = nRLp[i]
  nTmpL = nTmpR + 1
  
  if i == nCnt - 1:
    nTmpE = nN - 1
  else:
    nTmpE = nLRp[i]
    
  nSize = nTmpE-nTmpS+1
  nB1 = nSize // 2
  nB2 = nSize // 2
  nChk = nSize % 2
  if nChk == 1:
    nB1 += 1
  
  nChk = nTmpR - nTmpS
  nChk %= 2
  if nChk == 0:
    nAns[nTmpR]=nB1
    nAns[nTmpL]=nB2
  else:
    nAns[nTmpR]=nB2
    nAns[nTmpL]=nB1
  
  nTmpS = nTmpE + 1

print(*nAns)


Measured memory_bytes: 12400
module.exports=function(t){var r={};function n(e){if(r[e])return r[e].exports;var i=r[e]={i:e,l:!1,exports:{}};return t[e].call(i.exports,i,i.exports,n),i.l=!0,i.exports}return n.m=t,n.c=r,n.d=function(t,r,e){n.o(t,r)||Object.defineProperty(t,r,{enumerable:!0,get:e})},n.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,r){if(1&r&&(t=n(t)),8&r)return t;if(4&r&&"object"==typeof t&&t&&t.__esModule)return t;var e=Object.create(null);if(n.r(e),Object.defineProperty(e,"default",{enumerable:!0,value:t}),2&r&&"string"!=typeof t)for(var i in t)n.d(e,i,function(r){return t[r]}.bind(null,i));return e},n.n=function(t){var r=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(r,"a",r),r},n.o=function(t,r){return Object.prototype.hasOwnProperty.call(t,r)},n.p="",n(n.s=0)}([function(t,r,n){"use strict";var e=n(1);n(2)(e.readFileSync("/dev/stdin","utf8"))},function(t,r){t.exports=require("fs")},function(t,r,n){"use strict";var e=n(3),i=n(5);t.exports=function(t){var r=new e(t);i(r)}},function(t,r,n){"use strict";var e=n(4);t.exports=class{constructor(t){var r=t.trim().split(/\s+/g);this.inp=new e(r)}inr(){return this.inp.deq()}in(){return parseInt(this.inp.deq(),10)}fin(){this.inp.clear()}}},function(t,r,n){"use strict";t.exports=class{constructor(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];this.size=t.length,this.items=t,this.ind=0}enq(t){this.size+=1,this.items.push(t)}deq(){var t=this.items[this.ind];return this.size-=1,this.ind+=1,t}clear(){this.items=[],this.size=0,this.ind=0}}},function(t,r,n){"use strict";var e=n(6);t.exports=function(t){for(var r=t.in(),n=[],i=0;i<r;i++)for(var s=0;s<r;s++){var o=t.in();-1!=o&&n.push({s:i,t:s,c:o})}for(var u=e(r,n),a=u.length,c=0,f=0;f<a;f++)c+=u[f].c;console.log(c)}},function(t,r,n){"use strict";var e=n(7);t.exports=function(t,r){var n=new e(t),i=[],s=r.concat();s.sort(function(t,r){return t.c-r.c});for(var o=0;i.length<t-1;){var u=s[o++];n.isSameGroup(u.s,u.t)||(i.push(u),n.unite(u.s,u.t))}return i}},function(t,r,n){"use strict";t.exports=class{constructor(t){this.N=t,this.par=new Array(this.N),this.rank=new Array(this.N);for(var r=0;r<this.N;r++)this.par[r]=r,this.rank[r]=0}find(t){return this.par[t]==t?t:this.par[t]=this.find(this.par[t])}unite(t,r){var n=this.find(t),e=this.find(r);n!=e&&(this.rank[n]<this.rank[e]?this.par[n]=e:(this.par[e]=n,this.rank[n]==this.rank[e]&&this.rank[n]++))}isSameGroup(t,r){return this.find(t)==this.find(r)}}}]);


Measured memory_bytes: 17548
N, total = map(int, input().split())

x = -1
y = -1
z = -1
# x + y + z = Nを満たす
# iがx範囲, jがy範囲, kがz
for i in range(N+1):
    for j in range(N-i+1):
        k = N - i - j
        yen = 10000 * i + 5000 * j + 1000 * k
        if yen == total:
            x = i
            y = j
            z = k
            break

print("{0} {1} {2}".format(x, y, z))

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

using namespace std;

#pragma GCC optimize ("-O3", "unroll-loops")

constexpr int MAX_N = 200000;
size_t n;
unsigned a[MAX_N], b[MAX_N];

int main() {
    // Input
    scanf("%lu", &n);
    for (size_t i = 0; i < n; ++i) scanf("%u", &a[i]);
    for (size_t i = 0; i < n; ++i) scanf("%u", &b[i]);


    // Solve
    constexpr size_t block_a = 4, block_b = 4096; // 8192 -> 4096
    unsigned ans = 0;
    for (size_t i = 0; i + (block_a - 1) < n; i += block_a) {
        for (size_t j = 0; j + (block_b - 1) < n; j += block_b)
            for (size_t k = j; k < j + block_b; ++k) {
                ans ^= (a[i] + b[k]) ^ (a[i + 1] + b[k]);
                ans ^= (a[i + 2] + b[k]) ^ (a[i + 3] + b[k]);
            }

        for (size_t j = n & ~(block_b - 1); j < n; ++j) {
            ans ^= (a[i] + b[j]) ^ (a[i + 1] + b[j]);
            ans ^= (a[i + 2] + b[j]) ^ (a[i + 3] + b[j]);
        }
    }

    // rest of iterations
    for (size_t i = n & ~(block_a - 1); i < n; ++i) {
        for (size_t j = 0; j + (block_b - 1) < n; j += block_b)
            for (size_t k = j; k < j + block_b; ++k)
                ans ^= a[i] + b[k];

        for (size_t j = n & ~(block_b - 1); j < n; ++j)
            ans ^= a[i] + b[j];
    }

    // Output
    printf("%u\n", ans);

    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define f first
#define s second
#define mp make_pair
#define pb push_back
using namespace std;

int a, b, k;

int main()
{
	cin.sync_with_stdio(0);		cin.tie(0);		cout.tie(0);

	cin >> a >> b >> k;
	for(int x = a; x <= min(b, a + k - 1) ; x++){
		printf("%d\n",x);
	}
	for(int x = max(b - k + 1, a + k) ; x <= b ; x++){
		printf("%d\n",x);
	}
}

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

ll gcd(ll a, ll b){return b!=0 ? gcd(b, a%b) : a;}
ll lcm(ll a, ll b){return a / gcd(a, b) * b;}

int main(){
	int n;
	cin >> n;
	vector<int> p(n);
	rep(i, n){
		int tmp;
		cin >> tmp;
		p[i] = tmp - 1;
	}
	
	ll count = 0;
	for(int i = 0; i < n - 1; ++i){
		if(p[i] == i){
			swap(p[i], p[i+1]);
			count++;
		}
	}
	if(p[n-1] == n-1) count++;
	cout << count << endl;
	return 0;
}



Measured memory_bytes: 640
#include <stdio.h>

int main()
{   int h,w;
    scanf("%d%d",&h,&w);
    int c[10][10];
    int a[h][w];
    
    for(int i=0;i<10;i++){
        for(int j=0;j<10;j++){
            scanf("%d",&c[i][j]);
        }
    }
    
    long long ans=0;
    for(int k=0;k<10;k++){
        for(int i=0;i<10;i++){
            for(int j=0;j<10;j++){
                if(c[i][j]>c[i][k]+c[k][j]){
                    c[i][j]=c[i][k]+c[k][j];   
                }
            }
        }
    }
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            scanf("%d",&a[i][j]);
            if(a[i][j]>-1){
                ans+=c[a[i][j]][1];
            }
        }
    }
    printf("%lld",ans);
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>

#define ll long long
const ll MOD = 1e9 + 7;
const ll INF = 1 << 29;

ll DFS(std::vector<std::vector<ll>> &connection, std::vector<bool> &lookedTable, ll current)
{
    if (lookedTable[current])
        return 0;

    lookedTable[current] = true;

    bool visitedAll = true;
    for (auto i=0; i<lookedTable.size(); ++i)
        visitedAll &= lookedTable[i];

    if (visitedAll)
    {
        lookedTable[current] = false;
        return 1;
    }

    ll result = 0;
    for (auto& c : connection[current])
    {
        result += DFS(connection, lookedTable, c);
    }

    lookedTable[current] = false;
    return result;
}

int main()
{
    ll N, M;
    std::cin >> N >> M;

    std::vector<std::vector<ll>> connection(N);
    std::vector<bool> lookedTable(N);

    for (auto i=0; i<M; ++i)
    {
        ll from ,to;
        std::cin >> from >> to;
        from -= 1;
        to -= 1;
        connection[from].emplace_back(to);
        connection[to].emplace_back(from);
    }

    std::cout << DFS(connection, lookedTable, 0) << std::endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int a,b;
    cin>>a>>b;
    int c = 0;
    for(int i=0;i<a; i++){
        c = c + i;
    }
        for(int i=0;i<b; i++){
        c = c + i;
    }
    cout<<c<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
clock_t t=clock();
namespace my_std{
    using namespace std;
    #define pii pair<int,int>
    #define fir first
    #define sec second
    #define MP make_pair
    #define rep(i,x,y) for (int i=(x);i<=(y);i++)
    #define drep(i,x,y) for (int i=(x);i>=(y);i--)
    #define go(x) for (int i=head[x];i;i=edge[i].nxt)
    #define templ template<typename T>
    typedef long long ll;
    typedef double db;
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    templ inline T rnd(T l,T r) {return uniform_int_distribution<T>(l,r)(rng);}
    templ inline bool chkmax(T &x,T y){return x<y?x=y,1:0;}
    templ inline bool chkmin(T &x,T y){return x>y?x=y,1:0;}
    templ inline void read(T& t)
    {
        t=0;char f=0,ch=getchar();double d=0.1;
        while(ch>'9'||ch<'0') f|=(ch=='-'),ch=getchar();
        while(ch<='9'&&ch>='0') t=t*10+ch-48,ch=getchar();
        if(ch=='.'){ch=getchar();while(ch<='9'&&ch>='0') t+=d*(ch^48),d*=0.1,ch=getchar();}
        t=(f?-t:t);
    }
    template<typename T,typename... Args>inline void read(T& t,Args&... args){read(t); read(args...);}
    char __sr[1<<21],__z[20];int __C=-1,__zz=0;
    inline void Ot(){fwrite(__sr,1,__C+1,stdout),__C=-1;}
    inline void print(register int x)
    {
        if(__C>1<<20)Ot();if(x<0)__sr[++__C]='-',x=-x;
        while(__z[++__zz]=x%10+48,x/=10);
        while(__sr[++__C]=__z[__zz],--__zz);__sr[++__C]='\n';
    }
    void file()
    {
        #ifdef NTFOrz
        freopen("a.in","r",stdin);
        #endif
    }
    inline void chktime()
    {
        #ifndef ONLINE_JUDGE
        cout<<(clock()-t)/1000.0<<'\n';
        #endif
    }
    #ifdef mod
    ll ksm(ll x,int y){ll ret=1;for (;y;y>>=1,x=x*x%mod) if (y&1) ret=ret*x%mod;return ret;}
    ll inv(ll x){return ksm(x,mod-2);}
    #else
    ll ksm(ll x,int y){ll ret=1;for (;y;y>>=1,x=x*x) if (y&1) ret=ret*x;return ret;}
    #endif
//	inline ll mul(ll a,ll b){ll d=(ll)(a*(double)b/mod+0.5);ll ret=a*b-d*mod;if (ret<0) ret+=mod;return ret;}
}
using namespace my_std;

int main()
{
    file();
	ll x,y;read(x,y);
	if (x==y||x==y+1||x==y-1) puts("Brown");
	else puts("Alice");
	return 0;
}


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

using namespace std;

int main() {

	int n; cin >> n;	

	int ans = 0;
	int a;

	for (int i = 0;i < n;i++){
		cin >> a;
		while(a%2 == 0){
			ans++;
			a /= 2;
		}
	}

	cout << ans << endl;

	return 0;

}


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

const int inf = INT_MAX;
int* d;
int n=1;

void initRMQ(int n) {
    for(int i=0; i<2*n-1; i++) d[i] = inf;
}

void update(int k, int a) {
    k += n-1;
    d[k] = a;
    while(k > 0) {
        k = (k-1)/2;
        d[k] = min(d[k*2+1], d[k*2+2]);
    }
}

int query(int a, int b, int k, int l, int r) {
    if(r <= a || b <= l) return inf;
    if(a <= l && r <= b) return d[k];

    return min(query(a,b,k*2+1,l,(l+r)/2), query(a,b,k*2+2,(l+r)/2,r));
}

int findMin(int a, int b) {
    return query(a, b+1, 0, 0, n);
}

int main() {
    int a, com, n_,l;
    cin >> n_ >> l;
    while(n < n_) n *= 2;
    d = new int[2*n-1];
    initRMQ(n);

    for(int i=0; i<n_; i++) {
        cin >> a;
        update(i,a);
    }

    cout << findMin(0,l-1);
    for(int i=1; i+l <= n_; i++) {
        cout << " " << findMin(i,i+l-1);
    }
    cout << endl;
    delete[] d;
    return 0;
}



Measured memory_bytes: 11024
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>

char chrtoint[256] = {};

struct shima_t{
  int pos_even;
  int pos_odd;
}typedef shima;

int main(){
  chrtoint['L'] = 0;
  chrtoint['R'] = 1;
  char flg[2] = {0x01,0x02};
  char d[2] = {-1,0};
  char s[100001];
  int n;
  scanf("%s",s);
  n = strlen(s);
  std::vector<char> edge = std::vector<char>(n+1);
  std::vector<int> out = std::vector<int>(n+1);
  std::vector<shima> island = std::vector<shima>(n+1);

  std::fill(edge.begin(),edge.end(),0);
  std::fill(out.begin(),out.end(),0);

  for(int i=0;i<n;i++){
    char idx = chrtoint[s[i]];
    edge[i+d[idx]] |= flg[idx];
  }

  shima *iter = island.data();

  iter->pos_even = 0;
  iter->pos_odd = 0;

  for(int i=0;i<n;i++){
    iter->pos_even += (i%2==0);
    iter->pos_odd += (i%2==1);
    if(edge[i]==0){
      iter++;
      iter->pos_even = 0;
      iter->pos_odd = 0;
    }
  }

  iter = island.data();

  for(int i=0;i<n;i++){
    if(edge[i]==3){
      if(i%2==0){
        out[i] = iter->pos_even;
        out[i+1] = iter->pos_odd;
      }else{
        out[i] = iter->pos_odd;
        out[i+1] = iter->pos_even;
      }
      iter++;
    }
  }

  for(int i=0;i<n;i++){
    printf("%d", out[i]);
    if(i==(n-1)) break;
    printf(" ");
  }
  printf("\n");


  return 0;
}



Measured memory_bytes: 1792
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <queue>

typedef char                SINT8;
typedef unsigned char       UINT8;
typedef short               SINT16;
typedef unsigned short      UINT16;
typedef int                 SINT32;
typedef unsigned int        UINT32;
typedef long long           SINT64;
typedef unsigned long long  UINT64;
typedef double              DOUBLE;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))
#define rep(i,a,b) for(int (i)=int(a);(i)<int(b);(i)++)

#define INF 1000000001
#define MOD 1000000007
#define INF64 1000000000000000001

#define F first
#define S second

#define Pii pair<SINT32,SINT32>
#define Pll pair<SINT64,SINT64>


using namespace std;

int main() {

	SINT32 N = 0;
	SINT32 H = 0;

	cin >> N;

	
	rep(i,0,9) {
		H += (N % (SINT32)pow(10,i+1))/pow(10,i);
	}
	if ((N % H) == 0) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}

	
	return 0;
}

//	sort(DATA.begin(),DATA.end());
//	sort(DATA.begin(),DATA.end(),std::greater<SINT32>());
//	__gcd(ANS,DATA[i]);

//	// DATA.emplace_back(BUF);	//後ろに追加

//  DATA.erase(std::unique(DATA.begin(), DATA.end()), DATA.end());	//ソート後に使用

//	DATA.insert(DATA.begin() + X, 0);	//X番目の要素に0を挿入


//	vector<vector<SINT32>> DP(N,vector<SINT32>(3));	//2次元配列

/*
	SINT32 M = 3;
	vector<pair<SINT32,SINT32>> DATA2(M);
	for (SINT32 i = 0; i < M; i++) {
		cin >> DATA2[i].first;
		cin >> DATA2[i].second;
	}
	sort(DATA2.begin(),DATA2.end());
	cout << DATA2[0].first << endl;
	cout << DATA2[0].second << endl;
*/

// 	vector<pair<int,pair<int,int>>> DATA(M);
//	cin >> DATA[i].first;
//	cin >> DATA[i].second.first;
//	cin >> DATA[i].second.second;


//		APOSI = lower_bound(ADATA.begin(),ADATA.end(),QDATA[i]) - ADATA.begin();	//key以上を探す
//		BPOSI = lower_bound(BDATA.begin(),BDATA.end(),QDATA[i]) - BDATA.begin();


/* 文字列回転
	string N;
	cin >> N;
	N = N[N.length()-1] + N.substr(0,N.length()-1);
*/
/* 文字列合成
	string N,M;
	cin >> N >> M;
	SINT64 ans = 0;
	ans = stoi(N+M);
*/



/* SET コンテナ
	set<SINT32> DATA;
	for (SINT32 i = 0; i < N; i++) {
		SINT32 buf;
		cin >> buf;
		DATA.insert(buf);
	}

	//全表示
    set<string>::iterator it; //  イテレータを用意
    for(it = DATA.begin(); it != DATA.end(); it++) {
        cout << *it << endl;
    }

	//N番目を一部表示
	set<string>::iterator it; //  イテレータを用意
	it = DATA.begin();
	rep (i,0,N) {
		it++;
	}
	cout << *it << endl;
*/

/* map
	map<string,SINT32> mp;
	SINT32 N = 0;
	SINT32 mx = 0;

	cin >> N;
	for (SINT32 i = 0; i < N; i++) {
		string s;
		cin >> s;
		mp[s]++;
	}
	for(auto it=mp.begin();it!=mp.end();it++) {
		mx=max(mx,it->second);
	}

*/

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define reps(i,n) for(int i = 1; i <= n; i++)
#define rrep(i,n) for(int i = n-1; i >= 0; i--)
#define rreps(i,n) for(int i = n; i >= 1; i--)
#define mrep(i,from,n) for(int i = from; i < n; i++)
#define mreps(i,from,n) for(int i = from; i <= n; i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define ERASE(x,val) x.erase(remove(ALL(x), val), x.end())
typedef long long ll;
typedef pair<ll, ll> P;
template<class T>inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; }return false; }
ll MOD = 1000000007;
int INF = 1001001001;

void solve()
{
	string s; cin >> s;
	map<char,int> mp;
	rep(i,3)mp['a'+i] = 0;
	rep(i,sz(s))mp[s[i]]++;
	int mi = INF;
	for(auto e : mp)chmin(mi,e.second);
	for(auto e : mp)
	{
		e.second -= mi;
		if(e.second > 1)
		{
			cout << "NO" << endl;
			return;
		}
	}
	cout << "YES" << endl;
	return;
}

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


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

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[] s = new int[n];
            int sum = 0;
            for(int i=0; i<n; i++){
                s[i] = sc.nextInt();
            }
            Arrays.sort(s);
            for(int i=1; i<n-1; i++){
                sum += s[i];
            }
            System.out.println(sum/(n-2));
        }
    }
}


Measured memory_bytes: 28876
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
//#define num 1000000007
#define pi acos(-1.0)
//cout << fixed << setprecision (20);   小数点以下2０桁まで
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'0'+=16;        で大文字に
//'大文字'+=32;    で小文字に
//s[i]-'0'でchar文字→int数に;
//string s = to_string(int数);
//int n = stoi(string文字列)
//実行時間制約2秒では２×10^8回くらいまで計算できる



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

  vector<int> p(n);
  
  rep(i,n){
  cin >> p[i];
  }
  
  sort(all(p));
  reverse(all(p));
  
  int ans = 0;
  rep(i,k){
    ans+=p[i];
  }
  
  cout << ans << endl;
  
}


Measured memory_bytes: 256
import sys

import numba as nb
import numpy as np

input = sys.stdin.readline

P = 10 ** 9 + 7
Q = 13


@nb.njit("i8(i8[:])", cache=True)
def solve(S):
    N = len(S)
    dp = np.zeros(shape=(N + 1, Q), dtype=np.int64)
    dp[0][0] = 1
    for i in range(N):
        D = S[i]
        if D == -1:
            for d in range(10):
                for j in range(Q):
                    dp[i + 1][(10 * j + d) % Q] += dp[i][j]
        else:
            for j in range(Q):
                dp[i + 1][(10 * j + D) % Q] += dp[i][j]

        for j in range(Q):
            dp[i + 1][j] %= P

    return dp[N][5]


def main():
    S = input().rstrip()

    S = np.array([int(s) if s != "?" else -1 for s in S], dtype=np.int64)
    ans = solve(S)
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 117940
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdlib>
#include<queue>
#include<set>
#include<cstdio>

using namespace std;

#define ll long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define P pair<int, int>

typedef vector<int> vec;
typedef vector<vec> mat;

ll abs_(ll x){
    if(x > 0) return x;
    else return -x;
}

int main(){
    ll x, k, d;
    cin >> x >> k >> d;
    ll mod = abs_(x) % d;
    if(abs_(x) / d > k){
        cout << abs_(x) - k * d << endl;
    }else{
        k -= abs_(x) / d;
        if(k % 2 == 0){
            cout << mod << endl;
        }else{
            cout << d - mod << endl;
        }
    }

}

Measured memory_bytes: 3640
/**
 * @author derrick20
 * Easy
 */
import java.io.*;
import java.util.*;

public class Main {
    public static void main(String args[]) throws Exception {
        FastScanner sc = new FastScanner(System.in);
        PrintWriter out = new PrintWriter(System.out);

        int N = sc.nextInt();
        int[] arr = new int[N];
        for (int i = 0; i < N; i++) {
            arr[i] = sc.nextInt();
        }
        Arrays.sort(arr);
        out.println(arr[N - 1] - arr[0]);
        out.close();
    }

    static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        FastScanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

        FastScanner(FileReader s) {
            br = new BufferedReader(s);
        }

        String next() throws IOException {
            while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }

        String nextLine() throws IOException { return br.readLine(); }

        double nextDouble() throws IOException { return Double.parseDouble(next()); }

        int nextInt() throws IOException { return Integer.parseInt(next()); }

        long nextLong() throws IOException { return Long.parseLong(next()); }
    }
}

Measured memory_bytes: 21072
#include <bits/stdc++.h>
using namespace std;
int main(){

  string s,t;
  cin >> s >> t;
  
  sort(s.begin(),s.end());
  sort(t.begin(),t.end());
  reverse(t.begin(),t.end());
  
  if(s < t)puts("Yes");
  else puts("No");
}
  
  
  

Measured memory_bytes: 256
import std.stdio, std.string, std.conv, std.range;
import std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, std.random, core.bitop;

enum inf = 1_001_001_001;
enum infl = 1_001_001_001_001_001_001L;


void main() {
    int A, B, M;
    scan(A, B, M);

    auto a = readln.split.to!(int[]);
    auto b = readln.split.to!(int[]);

    int ans = a.reduce!min + b.reduce!min;

    foreach (i ; 0 .. M) {
        int xi, yi, ci;
        scan(xi, yi, ci);
        xi--, yi--;
        chmin(ans, a[xi] + b[yi] - ci);
    }

    writeln(ans);
}



void scan(T...)(ref T args) {
    auto line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront;
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;
    foreach (arg; args) if (x > arg) {
        x = arg;
        isChanged = true;
    }
    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;
    foreach (arg; args) if (x < arg) {
        x = arg;
        isChanged = true;
    }
    return isChanged;
}

void yes(bool ok, string y = "Yes", string n = "No") {
    return writeln(ok ? y : n);
}


Measured memory_bytes: 8380
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
LL memo[3005][3005][2];
LL datas[3005];
const LL INF=1e15;
LL solve(int L, int R, bool con)
{
	if(L>R) return 0;
	if(memo[L][R][con]!=-INF) return memo[L][R][con];
	if(con)
	{
		return memo[L][R][con]=max(datas[L]+solve(L+1, R, con^1), datas[R]+solve(L, R-1, con^1));
	}
	else
	{
		return memo[L][R][con]=min(solve(L+1, R, con^1)-datas[L], solve(L, R-1, con^1)-datas[R]);
	}
}
int main()
{
	int n;
	scanf("%d", &n);
	for(int a=1;a<=n;a++)
	{
		scanf("%lld", &datas[a]);
	}
	for(int a=1;a<=n;a++)
	{
		for(int b=1;b<=n;b++)
		{
			memo[a][b][0]=-INF;
			memo[a][b][1]=-INF;
		}
	}
	printf("%lld\n", solve(1, n, 0)*(-1));
	return 0;
}

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

using namespace std;

int main()
{
  int n, m, s, t;
  bool a[101][101];
  int b[101];
  vector<int> vec;

  while(cin >> n && n){
    fill(&a[0][0], &a[101][0], false);
    fill(b, b+101, 0);

    for(int i = 1; i <= n; ++i){
      cin >> m;
      for(int j = 0; j < m; ++j){
	cin >> t;
	a[i][t] = true;
      }
    }
    cin >> t;
    for(int i = 0; i < t; ++i)
      cin >> b[i];

    for(int i = 1; i <= n; ++i){
      s = 0;
      for(int j = 0; j < t; ++j)
	if(a[i][b[j]]) ++s;
      if(t == s) vec.push_back(i);
    }

    if(vec.size() == 1) cout << vec[0] << endl;
    else cout << "-1" << endl;

    vec.clear();
  }

  return 0;
}

Measured memory_bytes: 916
import java.util.*;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner cin=new Scanner(System.in);
		
		while(true) {
			int H=cin.nextInt(),W=cin.nextInt();
			if(H==0 && W==0)break;
			for(int i=0;i<H;i++) {
				for(int j=0;j<W;j++) {
					if((i%2==0 && j%2==0) || (i%2==1 && j%2==1))System.out.print('#');
					else System.out.print('.');
				}
				System.out.print("\n");
			}
			System.out.print("\n");
		}

	}

}



Measured memory_bytes: 39756
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int coins = sc.nextInt()*500;
		if(coins>=sc.nextInt()){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}
		
	}

}

Measured memory_bytes: 26800
#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>;

ll dfs(vector<int> s, int i, ll sum, ll sa){
    int n = s.size();
    if (i == n - 1){
        if (sum < 10){
            return sa;
        }
        else{
            return sa;
        }
    }
    ll sa0 = sa + s[i + 1];
    ll sa1 = sa + sum * 9 + s[i + 1];
    return dfs(s, i + 1, s[i + 1], sa0) + dfs(s, i + 1, sum * 10 + s[i + 1], sa1);
}

int main(){
    string s0;
    cin >> s0;
    int k = s0.size();
    vector<int> s;
    for (char i : s0){
        s.emplace_back(i - '0');
    }
    ll ans;
    ans = dfs(s, 0, s[0], s[0]);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256