akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int h, w, k;
  cin >> h >> w >> k;
  vector<string> s(h);
  for (auto&& e : s) {
    cin >> e;
  }
  int res = 1e9;
  for (int bt = 0; bt < 1 << (h - 1); ++bt) {
    vector<int> p{0};
    for (int i = 1; i < h; ++i) {
      if (bt >> (i - 1) & 1) {
        p.push_back(i);
      }
    }
    p.push_back(h);
    int n = p.size() - 1;
    int cur = n - 1;
    int l = 0, r = 0;
    while (l < w) {
      vector<int> c(n);
      while (r < w) {
        for (int t = 0; t < n; ++t) {
          for (int i = p[t]; i < p[t + 1]; ++i) {
            c[t] += s[i][r] == '1';
	    if(c[t]>k)break;
          }
	  if(c[t]>k)break;
        }
        if (*max_element(begin(c), end(c)) > k) {
          break;
        }
        ++r;
      }
      if(l==r){
	cur=0x7fffffff;
	break;
      }
      l = r;
      cur += l < w;
    }
    res = min(res, cur);
  }
  cout << res << '\n';
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))

mod = int(1e+9 + 7)
L = [0, 0, 0]
pi = 1
for i in range(N):
  j = 0
  while L[j] != A[i]:
    j += 1
    if j == 3:
      break
  n = 0
  for k in range(3):
    if L[k] == A[i]:
      n += 1
  if j != 3:
    L[j] += 1
  pi *= n
  pi %= mod
print(pi)

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

int main(){
  int n;
  cin >> n;
  double a;
  int b;
  for(int i=n;i>=1;i--){
    a=sqrt(i);
    b=sqrt(i);
      if(a==b){
         cout << i << endl;
         break;
      }
  }
}

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

#define NREP() for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 0; i < n; i++)
#define ALL(x) (x).begin(), (x).end()
#define MSG(x) cout << x << endl;
#define IPT(x) ll t; cin >> t; x.push_back(t);
#define YN(x) x ? cout << "YES" << endl : cout << "NO" << endl;
#define Yn(x) x ? cout << "Yes" << endl : cout << "No" << endl;
#define yn(x) x ? cout << "yes" << endl : cout << "no" << endl;

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<string> vs;
typedef vector<string> vvs;

const static ll MOD = 1e9 + 7;

int main() {
    string s;
    cin >> s;

    ll r[100010] = {0};
    ll l[100010] = {0};

    // r-even
    ll cnt_r = 0;
    for (ll i = 0; i < s.length(); i += 2) {
        if (s.at(i) == 'R') cnt_r++;

        if ((s.at(i) == 'R' && s.at(i + 1) == 'L')
            || (i >= 1 && s.at(i - 1) == 'R' && s.at(i) == 'L')) {
            r[i] = cnt_r;
            cnt_r = 0;
        }
    }

    // r-odd
    cnt_r = 0;
    for (ll i = 1; i < s.length(); i += 2) {
        if (s.at(i) == 'R') cnt_r++;

        if ((s.at(i) == 'R' && s.at(i + 1) == 'L')
            || (i >= 1 && s.at(i - 1) == 'R' && s.at(i) == 'L')) {
            r[i] = cnt_r;
            cnt_r = 0;
        }
    }

    // l-even
    ll cnt_l = 0;
    for (ll i = s.length() - 1; i >= 0; i -= 2) {
        if (s.at(i) == 'L') cnt_l++;

        if ((i >= 1 && s.at(i - 1) == 'R' && s.at(i) == 'L')
            || (i + 1 <= s.length() - 1 && s.at(i) == 'R' && s.at(i + 1) == 'L')) {
            l[i] = cnt_l;
            cnt_l = 0;
        }
    }

    // l-odd
    cnt_l = 0;
    for (ll i = s.length() - 2; i >= 0; i -= 2) {
        if (s.at(i) == 'L') cnt_l++;

        if ((i >= 1 && s.at(i - 1) == 'R' && s.at(i) == 'L')
            || (i + 1 <= s.length() - 1 && s.at(i) == 'R' && s.at(i + 1) == 'L')) {
            l[i] = cnt_l;
            cnt_l = 0;
        }
    }

    for (ll i = 0; i < s.length(); i++) {
        cout << r[i] + l[i];
        cout << " ";
    }
    cout << endl;
}


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

int main() {
  int n;
  cin >> n;
  vector<int> a(n + 2, 0);
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  int tmp = 0;
  for (int i = 0; i <= n; i++) {
    tmp += abs(a[i] - a[i + 1]);
  }
  for (int i = 1; i <= n; i++) {
    int ans = tmp;
    ans -= abs(a[i - 1] - a[i]);
    ans -= abs(a[i] - a[i + 1]);
    ans += abs(a[i - 1] - a[i + 1]);
    cout << ans << endl;
  }
  return 0;
}

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

int main(){
	int i,j,k,a,b,c,g,s=0;
	
	cin>>a>>b>>c>>g;
	
	for(i=0;i<=a;i++)
	  for(j=0;j<=b;j++)
	    for(k=0;k<=c;k++){
	    	if(i*500+j*100+k*50==g){
	    		s++;
	    	}
	    }
	    cout<<s<<endl;
	    
	    return 0;
}

Measured memory_bytes: 256
n = int(input())
a = [int(i) for i in input().split()]
counter = 0
b = 1
while b == 1:
    for i in range(n):
        if a[i] % 2 == 0:
            a[i] = a[i] / 2
        else:
            b = 0
    counter += 1

print(counter-1)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#define rep2(i, m, n) for(int i=int(m); i<int(n); ++i)
#define drep2(i, m, n) for(int i=int(m-1); i>=int(n); --i)
#define rep(i, n) rep2(i, 0, n)
#define drep(i, n) drep2(i, n, 0)
#define all(a) a.begin(), a.end()
using ll = long long;
using ld = long double;
using V = vector<int>;
using Vll = vector<ll>;
using Vld = vector<ld>;
using Vbo = vector<bool>;
using VV = vector<V>;
using VVll = vector<Vll>;
using VVld = vector<Vld>;
using VVbo = vector<Vbo>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using Pld = pair<ld, ld>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
template<typename T> istream &operator>>(istream &is, vector<T> &v) { for (auto &e : v) is >> e; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << " "; return os; }
template<typename T> inline int count_between(vector<T> &a, T l, T r) { return lower_bound(all(a), r) - lower_bound(all(a), l); } // [l, r)
inline int Log2(ll x) { int k; for (k = 0; x > 0; ++k) x >>= 1; return k; } // number of binary digits
const int INF  = 1<<30;
const ll INFll = 1ll<<62;
const ld EPS   = 1e-10;
const int MOD  = int(1e9)+7;



template<typename T>
struct edge {
  int u, v; T a, b;
  edge(int u, int v, T a, T b) : u(u), v(v), a(a), b(b) {}
};

template<typename T>
using Edges = vector<edge<T>>;


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

  Edges<ll> G;
  for (int i = 0; i < m; ++i) {
    int u, v, a, b;
    cin >> u >> v >> a >> b;
    --u, --v;
    G.emplace_back(u, v, a, b);
    G.emplace_back(v, u, a, b);
  }

  Vll c(n), d(n);
  rep(i, n) cin >> c[i] >> d[i]; 

  const ll M = 5000;
  VVll dp(n, Vll(M+1, INFll));

  s = min(s, M);
  rep(i, s+1) dp[0][i] = 0;
  rep2(i, s+1, M+1) dp[0][i] = (ll(i)-s+c[0]-1) / c[0] * d[0];

  for (int i = 0; i < 2*n+1; ++i) {
    for (auto &e : G) 
      rep2(k, 0, M+1)
        if (k+e.a <= M) chmin(dp[e.v][k], dp[e.u][k+e.a] + e.b);
    rep(i, n) rep(k, M+1)  chmin(dp[i][k], dp[i][max(k-c[i], 0ll)] + d[i]);
  }
  
  rep2(i, 1, n) {
    cout <<  dp[i][0] << endl; 
  }
  return 0;
}


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

int main(){
  int m,mini,maxi;
  while(1){
    cin>>m>>mini>>maxi;
    if(m==0&&mini==0&&maxi==0)break;
    int p[205];
    for(int i=0;i<m;i++)cin>>p[i];
    int gap=-1,t;
    if(m==maxi)maxi--;
    for(int i=mini-1;i<maxi;i++){
      //cout<<i+1<<": "<<p[i]-p[i+1]<<endl;
      if(gap<=p[i]-p[i+1]){
	gap=p[i]-p[i+1];
	t=i+1;
      }
    }
    cout<<t<<endl;
  }
  
  return 0;
}

Measured memory_bytes: 3068
#include<bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

#define ll long long
//#define bint int1024_t
#define ld long double
#define vect vector<ll>
#define unmap unordered_map
#define pb push_back
#define F first
#define pll pair<ll,ll>
#define S second
#define pi 3.1415926536
#define mod int(1e9+7)
#define mp make_pair
//ios_base::sync_with_stdio(false);cin.tie(NULL);
#define testcases ll t; cin>>t; while(t--)

using namespace std;
//using namespace boost::multiprecision;
//using namespace __gnu_pbds;

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

    ll n;
    cin>>n;
    string ans;
    while(n)
    {
        ll rem = n%26-1,f=0;
        if(rem < 0) rem += 26,f=1;
        ans.pb('a'+rem);
        n/=26;
        if(f) n--;
    }
    reverse(ans.begin(),ans.end());
    cout<<ans;
    return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  int n;
  cin >> n;
  vector<int> h(n);
  rep(snip_i, n) cin >> h.at(snip_i);
  int ans = 0;
  while(1){
    bool end = true;
    vector<int> nx = h;
    rep(i, n){
      if(h.at(i) > 0){
        if(i == 0 || h.at(i-1) == 0){
          ans++;
          end = false;
        }
        nx.at(i)--;
      }
    }
    h = nx;
    if(end == true) break;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

typedef struct node{
  struct node *left;
  struct node *right;
  struct node *parent;
  int key;
}Node;
typedef Node *NodePointer;

NodePointer createNode(void);
void inorder(NodePointer);
void preorder(NodePointer);
void insert(int);
NodePointer find(int, NodePointer);
NodePointer root = NULL;

int main(){

  int i, n, x;
  char str[10];

  scanf("%d", &n);
  for(i = 0; i < n; i++){
    scanf("%s", str);
    if(str[0] == 'i'){
      scanf("%d", &x);
      insert(x);
    }else if(str[0] == 'p'){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }else if(str[0] == 'f'){
      scanf("%d", &x);
      if(find( x, root) == NULL){
	printf("no\n");
      }else{
	printf("yes\n");
      }
    }else{
      continue;
    }
  }

  return 0;
}

NodePointer createNode(void){

  NodePointer tree = malloc(sizeof(Node));
  tree->left = NULL;
  tree->right = NULL;
  tree->parent = NULL;
  tree->key = 0;

  return tree;
}

void insert(int key){

  NodePointer z = createNode();
  NodePointer x = root;
  NodePointer y = NULL;
  z->key = key;
  while(x != NULL){
    y = x;

    if(z->key < x->key){
      x = x->left;
    }else{
      x = x->right;
    }
  }

  z->parent = y;

  if(y == NULL){
    root = z;
  }else if(z->key < y->key){
    y->left = z;
  }else{
    y->right = z;
  }
}

void inorder(NodePointer T){

  if(T != NULL){
    inorder(T->left);
    printf(" %d",T->key);
    inorder(T->right);
  }
}

void preorder(NodePointer T){

  if(T != NULL){
  printf(" %d", T->key);
    preorder(T->left);
    preorder(T->right);
  }
}

NodePointer find(int k, NodePointer T){

  while(T != NULL && T->key != k){
    if(T->key > k){
      T = T->left;
    }else{
      T = T->right;
    }
  }
  return T;
}

Measured memory_bytes: 19364
ma = lambda :map(int,input().split())
lma = lambda :list(map(int,input().split()))
tma = lambda :tuple(map(int,input().split()))
ni = lambda:int(input())
yn = lambda fl:print("Yes") if fl else print("No")
ips = lambda:input().split()
import collections
import math
import itertools
import heapq as hq
import sys
L = ni()
S = bin(L)[2::]
S=S[::-1]
l=len(S)-1
ans = []
cnt=0
tmp=2**l
for i in range(l-1,-1,-1):
    ans.append((i+1,i+2,2**i));cnt+=1
    ans.append((i+1,i+2,0));cnt+=1
    if S[i]=="1":
        ans.append((i+1,l+1,tmp))
        cnt+=1
    tmp+=2**i*int(S[i])
print(l+1,cnt)
for u,v,w in ans:
    print(u,v,w)


Measured memory_bytes: 67104
#include<cstdio>
#include<algorithm>
using namespace std;
#define MAXN 100010
int Adj[2][MAXN],V[2][MAXN],nxt[2][MAXN],c[2];
int Adj1[MAXN],V1[MAXN*2],nxt1[MAXN*2],c1;
void AddEdge(int u,int v,int f)
{
	c[f]++;V[f][c[f]]=v,nxt[f][c[f]]=Adj[f][u];Adj[f][u]=c[f];
}
void AddEdge(int u,int v)
{
	c1++;V1[c1]=v,nxt1[c1]=Adj1[u];Adj1[u]=c1;
}
int a[2][MAXN],vis[MAXN],ans[MAXN];
int st[MAXN],r,n;
void dfs(int u,int f)
{
	for(int i=Adj[f][u];i;i=nxt[f][i])
		dfs(V[f][i],f);
	if(a[f][u]==1) st[++r]=u;
	while(r>1)
	{
		AddEdge(st[r],st[r-1]);
		AddEdge(st[r-1],st[r]);
		r-=2;
	}
}
void dfsans(int u,int val)
{
	vis[u]=1;
	ans[u]=val;
	for(int i=Adj1[u];i;i=nxt1[i])
		if(!vis[V1[i]])
			dfsans(V1[i],-val);
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		a[0][i]=a[1][i]=1;
	int p,rt1,rt2;
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&p);
		if(p==-1) rt1=i;
		else a[0][p]^=1,AddEdge(p,i,0);
	}
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&p);
		if(p==-1) rt2=i;
		else a[1][p]^=1,AddEdge(p,i,1);
	}
	for(int i=1;i<=n;i++)
		if(a[0][i]!=a[1][i])
		{
			printf("IMPOSSIBLE\n");
			return 0;
		}
	printf("POSSIBLE\n");
	dfs(rt1,0);
	r=0;
	dfs(rt2,1);
	for(int i=1;i<=n;i++)
		if(!vis[i])
			dfsans(i,1);
	for(int i=1;i<=n;i++)
		if(a[0][i]) printf("%d ",ans[i]);
		else printf("0 ");
	printf("\n");
}

Measured memory_bytes: 8576
S = list(input())

lst = [0] * 3
for s in S:
    if s == 'a':
        lst[0] += 1
    elif s == 'b':
        lst[1] += 1
    elif s == 'c':
        lst[2] += 1

if max(abs(lst[0] - lst[1]), abs(lst[1] - lst[2]), abs(lst[2] - lst[0])) >= 2:
    print ('NO')
else:
    print ('YES')

Measured memory_bytes: 3956
N = int(input())
A = list(map(int, input().split()))


def bubbleSort(li: list, n: int):
    count = 0
    for i in range(n-1):
        for j in reversed(range(i+1, n)):
            if li[j-1] > li[j]:
                li[j-1], li[j] = li[j], li[j-1]
                count += 1
    print(*li)
    print(count)


bubbleSort(A, N)



Measured memory_bytes: 5604
#include<bits/stdc++.h>
using namespace std;
  
int main(){
  
  string S;
  cin >> S;
  
  int i, size = S.size();
  for(i = 0; i < size; i++){
    
    if((i + 1) % 2 == 0 && !(S.at(i) == 'L' || S.at(i) == 'U' || S.at(i) == 'D')){
      
      cout << "No" << endl;
      return 0;
    }else if((i + 1) % 2 != 0 && !(S.at(i) == 'R' || S.at(i) == 'U' || S.at(i) == 'D')){
      cout << "No" << endl;
      return 0;      
    }
  }
  
  cout << "Yes" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
#define rep(i,n) for(int i=0;i<n;i++)

typedef int long long ll;
using namespace std;
typedef pair<int,int> P;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
const ll MOD=1e9+7;
static const int MAX = 100;
static const int INF = (1<<23);
template<class T> T gcd(T a, T b){return b? gcd(b,a%b) : a;}
template<class T> T lcm(T a,T b){return a / gcd(a,b)*b;}

int main(){
    int n;
    cin>>n;
    vector<int> v(n,0);
    rep(i,n-1){
        int a;
        cin>>a;
        v[a-1]++;
    }
    rep(i,n){
        cout<<v[i]<<endl;
    }




return 0;
}


Measured memory_bytes: 4052
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const ll mod = 1000000007;
const int INF = 1001001001;

int main(){
    ll a,b,c; cin >> a >> b >> c;
    if(a==b && b!=c){
        cout << "Yes" << endl;
    }else if(a==c && a!=b){
        cout <<"Yes" << endl;
    }else if(b==c && a!=b){
        cout << "Yes" << endl;
    }else{
        cout <<"No" << endl;
    }

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ll long long int
const int INF = 2147483647;
const ll MOD = 1000000007;

using namespace std;

ll idx[100001] = {};
int n;
multiset<ll> s, t;

int main() {
  cin >> n;
  REP(i, n) {
    int p;
    cin >> p;
    idx[p] = i + 1;
  }

  ll ans = 0;

  s.insert(0);
  s.insert(0);
  t.insert(n + 1);
  t.insert(n + 1);

  for (ll q = n; q > 0; q--) {
    auto y = -*(s.upper_bound(-idx[q]));
    auto x = y == 0 ? 0 : -*(s.upper_bound(-y));
    auto z = *(t.upper_bound(idx[q]));
    auto w = z == n + 1 ? n + 1 : *(t.upper_bound(z));

    ans += ((w - z) * (idx[q] - y) + (y - x) * (z - idx[q])) * q;

    s.insert(-idx[q]);
    t.insert(idx[q]);
  }

  cout << ans << endl;
}


Measured memory_bytes: 10368
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;

#define N 4000000
#define NIL -1

int key[N];
int parent[N];
int leftc[N];
int rightc[N];

int root=NIL;
void insert(int z){
  int x,y;
  
  y=NIL;
  x=root;

  while(x!=NIL){
    y=x;
    if(key[z]<key[x]) x=leftc[x];
    else x=rightc[x];
  }  
  
  parent[z]=y;

  if(y==NIL) root=z;
    
  else if(key[z]<key[y]) leftc[y]=z;
 
  else rightc[y]=z;
  
  
}

void inorderprint(int now){
  if(now!=NIL){
    inorderprint(leftc[now]);
    printf(" %d",key[now]);
    inorderprint(rightc[now]);
  }
}

void preorderprint(int now){
  if(now!=NIL){
    printf(" %d",key[now]);
    preorderprint(leftc[now]);
    preorderprint(rightc[now]);
  }
}



int main(){

  int n,i,j,data;
  int z=0;
  char str[10];

  for(i=0;i<N;i++){
    parent[i]=NIL;
    key[i]=NIL;
    rightc[i]=NIL;
    leftc[i]=NIL;
  }

  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%s",str);
    if(strcmp(str,"insert")==0) {
      scanf("%d",&data);
      key[z]=data;
      insert(z);
      z++;
    }
    else if(strcmp(str,"print")==0){
      inorderprint(root);
      cout <<endl;
      preorderprint(root);
      cout <<endl;
    }
  }

  return 0;
}

Measured memory_bytes: 61000
a, b, c, x = map(int, [input() for i in range(4)])
ans = 0
for i in range(a + 1):
  for j in range(b + 1):
    for k in range(c + 1):
      if i * 500 + j * 100 + k * 50 == x:
        ans += 1
print(ans)

Measured memory_bytes: 3060
#include <stdio.h>


int main () {
	int N, T;
	int count=1, sub_max=0, min;
	scanf ("%d %d", &N, &T);
	scanf ("%d", &min);
	for (int i=1; i<N; i++) {
		int tmp;
		scanf ("%d", &tmp);
		if (tmp<min)
			min = tmp;
		else if (tmp-min==sub_max)
			count++;
		else if (tmp-min>sub_max) {
			sub_max=tmp-min;
			count = 1;
		}
	}
	printf ("%d\n",count);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  string a, b, c;
  cin >> a >> b >> c;
  cout << (char) toupper(a[0]) << (char) toupper(b[0]) << (char) toupper(c[0]) << '\n';
  return 0;
}

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

using namespace std;

#define INF 1e9

int MOD=1e9+7;

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

    while(1){
        int m,t,p,r;
        cin>>m>>t>>p>>r;

        if(m==0)break;

        vector<pair<pair<long long,long long>,long long>> v(t);
        int wa[60][20]={};
        for(int i=0;i<t;i++){
            v[i].second=i+1;
        }

        for(int i=0;i<r;i++){
            int a,b,c,d;
            cin>>a>>b>>c>>d;
            b--;
            c--;

            if(d!=0)wa[b][c]++;
            else{
                v[b].first.first++;
                v[b].first.second+=a+wa[b][c]*20;
            }
        }
        for(int i=0;i<t;i++){
            v[i].first.second*=-1;
        }
        sort(v.begin(),v.end());
        reverse(v.begin(),v.end());
        for(int i=0;i<t;i++){
            cout<<v[i].second;
            if(i==t-1)cout<<endl;
            else if(v[i].first==v[i+1].first)cout<<"=";
            else cout<<",";
        }
    }
}


Measured memory_bytes: 3216
--https://www.lua.org/pil/11.4.html
local List = {}
function List.new ()
  return {first = 0, last = -1}
end

function List.pushleft (list, value)
  local first = list.first - 1
  list.first = first
  list[first] = value
end

function List.pushright (list, value)
  local last = list.last + 1
  list.last = last
  list[last] = value
end

function List.popleft (list)
  local first = list.first
  if first > list.last then return false end
  local value = list[first]
  list[first] = nil
  list.first = first + 1
  return value
end

function List.popright (list)
  local last = list.last
  if list.first > last then return false end
  local value = list[last]
  list[last] = nil
  list.last = last - 1
  return value
end

--------------------------------------------------------

local n,k=io.read("*n","*n")
local edge={}
for i=1,n do
    edge[i]={}
end
for i=1,n-1 do
    local a,b=io.read("*n","*n")
    edge[a][b]=false
    edge[b][a]=false
end

local pattern=k
local stack=List.new()
List.pushright(stack,1)

while true do
    local a=List.popright(stack)
    if not a then
        break 
    end
    local available_colors=k-1
    if a>1 then
        available_colors=available_colors-1
    end
    for b,_ in pairs(edge[a]) do
        if not edge[a][b] then
            edge[a][b]=true
            edge[b][a]=true
            List.pushright(stack,b)
            pattern=pattern*available_colors%1000000007
            available_colors=available_colors-1
        end
    end
end
print(pattern)

Measured memory_bytes: 12980
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
const double EPS = 1e-9;
#define INF (1LL<<60)
#define D double
#define fs first
#define sc second
#define int long long
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define RFOR(i,a,b) for(int i = (int)(b-1);i>=(int)(a);--i)
#define REP(i,n)  FOR(i,0,(n))
#define RREP(i,n) RFOR(i,0,(n))
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define RITR(itr,mp) for(auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x)  cout << #x << " = " << (x) << endl;
#define SP << " " << 
typedef pair<int,int> P;
typedef vector<int> vec;
typedef vector<vector<int>> mat;

void add(int &a, int b){
  a = ((a+b) % MOD + MOD) % MOD;
}

inline int mul(int a, int b) {
    add(a,0); add(b,0);
    #if !defined(_WIN32) || defined(_WIN64)
      return (int) ((long long) a * b % MOD);
    #endif
      unsigned long long x = (long long) a * b;
      unsigned xh = (unsigned) (x >> 32), xl = (unsigned) x, d, m;
      asm(
        "divl %4; \n\t"
        : "=a" (d), "=d" (m)
        : "d" (xh), "a" (xl), "r" (MOD)
      );
      return m;
}

inline int modpow(int a, long long b) {
  int res = 1;
  while (b > 0) {
    if (b & 1) {
      res = mul(res, a);
      }
      a = mul(a, a);
      b >>= 1;
  }
  return res;
}

inline int inv(int a) {
    a %= MOD;
    if (a < 0) a += MOD;
    int b = MOD, u = 0, v = 1;
    while (a) {
      int t = b / a;
      b -= t * a; swap(a, b);
      u -= t * v; swap(u, v);
    }
    assert(b == 1);
    if (u < 0) u += MOD;
    return u;
}
 
signed main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(20);
  
  int n,m;

  cin >> n >> m;

  vec k(n);
  mat s(m, vec(n, -1));

  REP(i,m){
    cin >> k[i];
    REP(j, k[i]){
      cin >> s[i][j];
      s[i][j]--;
    }
  }

  vector<int> p(m);
  REP(i, m) cin >> p[i];

  vector<bool> bit(n,0);

  int ans = 0;

  REP(i, modpow(2, n)){
    REP(j, n){
      bit[j] = (1 & i >> j);
    }

    bool f = true;
    REP(j, m) { 
      int tmp = 0;
      REP(l, s[j].size()){
        if(s[j][l] != -1 && bit[s[j][l]]) tmp++;
      }
      f &= (tmp % 2 == p[j]);
    }

    if(f) ans++;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define show(a, n) rep(i,n) {cout<<a[i]<<' ';} cout<<endl;

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

const int INF = 1 << 30;
const long long INFL = 1LL << 62;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 100010;

struct BIT {
    int n;
    vi bit;
    BIT(int num):bit(num+1,0){n=num;}
    void add(int i, int w){
        for(int x=i; x<=n; x+=x&-x) bit[x]+=w;
    }
    int sum(int i){
        int ret=0;
        for(int x=i; x>0; x-=x&-x) ret+=bit[x];
        return ret;
    }
    int sum(int l, int r){return sum(r)-sum(l);}
};

ll search(BIT &tree, ll n, ll find) {
	if(find < tree.sum(1)) return 0;
	if(find == 0) return 0;
	if(find > tree.sum(n)) return n + 1;
	ll left = 1, right = n;
	ll ret = n + 2;
	while(left <= right) {
		ll mid = (left + right) / 2;
		if(tree.sum(mid) >= find) {
			ret = min(mid, ret);
			right = mid - 1;
		}
		else {
			left = mid + 1;
		}
	}
	return ret;
}

void show_tree(BIT &tree, int n) {
	rep1(i, n) cout << tree.sum(i) << ' ';
	cout << endl;
}

int main() {
	ll n;
	cin >> n;
	ll p[N], pos[N];
	rep1(i, n) {
		cin >> p[i];
		pos[p[i]] = i;
	}
	BIT tree(n);
	ll ans = 0ll;
	tree.add(pos[n], 1);
	for(ll i = n - 1; i >= 1; i--) {
		ll j = pos[i];
		ll cur_sum = tree.sum(j);
		ll l2 = search(tree, n, cur_sum - 1);
		ll l1 = search(tree, n, cur_sum);
		ll r1 = search(tree, n, cur_sum + 1);
		ll r2 = search(tree, n, cur_sum + 2);
		ans += i * ((l1 - l2) * (r1 - j) + (r2 - r1) * (j - l1));
		tree.add(j, 1);
	}
	cout << ans << endl;
}


Measured memory_bytes: 2176
/*    ####################  */
/*   # I_LOVE_THUY_LINH #  */
/*  ####################  */
#include <bits/stdc++.h>
#define ll long long
#define db double
#define ld long double
#define ii pair<int,int>
#define pb push_back
#define vi vector<int>
#define vii vector<ii>
#define matrix vector<vector<ll>>
#define fir first
#define sec second
#define all(s) s.begin(),s.end()
#define rall(s) s.rbegin(),s.rend()
#define uni(a) (a).erase(unique(all(a)),(a).end())
#define sz(a) int((a).size())
#define ms(s,val) memset(s,val,sizeof(s))
#define bitcount(n) __builtin_popcountll(n)
#define getbit(s,k) ((s >> k)&1)
#define turnbit(s,k) (s | (1<<k))
#define offbit(s,k) (s & ~(1<<k))
#define flipbit(s,k) (s ^ (1<<k))
#define prec(n) fixed<<setprecision(n)
#define sqr(x) (ll)(x)*(ll)(x)
#define lcm(a,b) ((ll)a/__gcd((ll)a,(ll)b)*(ll)(b))
#define gcd(a,b) __gcd(a,b)
using namespace std;
const int INF = int(1e9);

int main(){
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int n;
    cin >> n;
    unordered_map<string,int> cnt;
    for (int i = 0; i < n; i++){
        string s;
        cin >> s;
        cnt[s]++;
    }
    int maxcnt = 0;
    for (auto it: cnt) maxcnt = max(maxcnt,it.sec);
    vector<string> ans;
    for(auto it: cnt)
        if (it.sec == maxcnt) ans.emplace_back(it.fir);
    sort(all(ans));
    for (string x: ans) cout << x << '\n';
    return 0;
}

Measured memory_bytes: 25284
fun main(args : Array<String>) {
    val n = readLine()!!.toInt()
    val s = readLine()!!

    if (n % 2 == 1) {
        println("No")
        return
    }

    val ss = s.take(n/2).repeat(2)
    println(if (ss == s) "Yes" else "No")
}

Measured memory_bytes: 33668
package main

import "fmt"

func main() {
	var h, w int
	var t string
	dy := []int{-1, 0, 1, 0}
	dx := []int{0, 1, 0, -1}
	fmt.Scan(&h, &w)

	s := make([][]string, h)
	for i := 0; i < h; i++ {
		fmt.Scan(&t)
		ws := make([]string, w)
		for j, v := range t {
			ws[j] = string(v)
		}
		s[i] = ws
	}
	for y := 0; y < h; y++ {
		for x := 0; x < w; x++ {
			if s[y][x] == "." {
				continue
			}
			b := false
			for k := 0; k < 4; k++ {
				if x+dx[k] < 0 || x+dx[k] >= w {
					continue
				}
				if y+dy[k] < 0 || y+dy[k] >= h {
					continue
				}
				if s[y+dy[k]][x+dx[k]] == "#" {
					b = true
					break
				}
			}
			if !b {
				fmt.Println("No")
				return
			}
		}
	}
	fmt.Println("Yes")
}

Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <utility>
#include <iomanip>
using namespace std;
typedef long long ll;

const ll MOD = 1e9+7;
ll dp[100003][2]; //i番目の桁までの総数、ただしj=1のときは最大値上回る危険
int main()
{
	ll ans=0;
	string l;
	cin>>l;
	int n=l.size();
	fill(dp[0],dp[100003],0);
	dp[0][1]=2;
	dp[0][0]=1;
	for(int i=1;i<n;i++)
	{
		if(l[i]=='0')
		{
			dp[i][0]=dp[i-1][0]*3;
			dp[i][0]%=MOD;
			dp[i][1]=dp[i-1][1];
		}else{
			dp[i][0]=dp[i-1][0]*3;
			dp[i][0]%=MOD;
			dp[i][1]=dp[i-1][1]*2;
			dp[i][1]%=MOD;
			dp[i][0]+=dp[i-1][1];
			dp[i][1]%=MOD;
		}
	}
	ans=dp[n-1][0]+dp[n-1][1];
	ans%=MOD;
	if(ans<0)
		ans+=MOD;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 2048
#include<iostream>
#include<algorithm>
using namespace std;
int p[100];
int x[3];
int main(){
  int n,a,b,ca=0,cb=0,c=0;
  cin>>n>>a>>b;
  for(int i=0;i<n;i++){
    cin>>p[i];
    if(p[i]<=a)
      ca++;
    else if(p[i]>b)
      cb++;
    else
      c++;
  }
  if(ca<=cb and ca<=c)
    cout<<ca<<endl;
  else if(c<ca and c<cb)
    cout<<c<<endl;
  else
    cout<<cb<<endl;
}

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

int main() {
	int N, K;
	cin >> N >> K;
	if (N % 2 == 1) {
		if (N / 2 + 1 >= K) {
			cout << "YES" << endl;
		}
		else {
			cout << "NO" << endl;
		}
	}
	else {
		if (N / 2 >= K) {
			cout << "YES" << endl;
		}
		else {
			cout << "NO" << endl;
		}
	}

}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <string>
#include <cctype>
#include <stack>
#include <queue>
#include <vector>
#include <cstdlib>
#include <list>
#define _USE_MATH_DEFINES
#include <math.h>

using namespace std;

int main() {

	double r;
	cin >> r;
	printf("%.6f %.6f\n" ,M_PI*r*r , M_PI * 2 * r);
	
	return 0;
}

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

int main(){
    int n, s[109], sm=0;
    vector<int> v;
    cin >> n;
    bool ans=true;
    for(int i=0;i<n;i++){
        cin >> s[i];
        sm += s[i];
        v.push_back(s[i]);
    }
    sort(v.begin(), v.end());
    for(int i=0;i<n;i++){
        if(sm%10!=0){
            ans=false;
            break;
        }
        if(v[i]%10!=0){
            ans=false;
            sm-=v[i];
        }
    }
    
    cout << (ans?0:sm) << endl;
}

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

const int N = 2e5 + 10;
int n, a[N], b[N], na[N], nb[N];

int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
    for (int i = 1; i <= n; i++) scanf("%d", &b[i]);
    int ans = 0;
    for (int i = 0; i <= 28; i++) {
        for (int j = 1; j <= n; j++)
            na[j] = a[j] & ((1 << (i + 1)) - 1), nb[j] = b[j] & ((1 << (i + 1)) - 1);
        sort(nb + 1, nb + n + 1);
        int t1 = 1 << i, t2 = 2 * t1, t3 = 3 * t1, t4 = 4 * t1;
        int now = 0;
        for (int j = 1; j <= n; j++) {
            now ^= (lower_bound(nb + 1, nb + n + 1, t2 - na[j]) - lower_bound(nb + 1, nb + n + 1, t1 - na[j])) & 1;
            now ^= (lower_bound(nb + 1, nb + n + 1, t4 - na[j]) - lower_bound(nb + 1, nb + n + 1, t3 - na[j])) & 1;
        }
        ans |= now << i;
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 3328
a,b,_,c,d,_,_=map(int,input().split())
e=0
if a%2+c%2+d%2>=2 and a>0 and c>0 and d>0:
    e=3
    a-=1
    c-=1
    d-=1
print((a//2)*2+b+(c//2)*2+(d//2)*2+e)

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

int main() {

	int n;
	cin >> n;
  
  	double o = n / 2 ;
  	
    if(n%2 == 1){
      o++;
      }
  	
	cout << fixed << setprecision(10) << o/n << endl;
  
	return 0;
 
}

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

int main(){
	while(1){
		int n,r,p,c;
		cin >> n >> r;
		if(n == 0 && r ==0)break;
		int s[n + 1];
		for(int i = 1; i <= n;++i){
		s[i] = i;
		}
		for(int j = 0; j < r;++j){
			cin >> p >> c;
			if(p == 1)continue;
			for(int k = 0;k < c;++k){
				s[0] = s[n + 2 - p - c];
				for(int l = 0;l < p + c - 2;++l){
					s[n + 2 - p - c + l] = s[n + 3 - p - c + l];
					}
				s[n] = s[0];
			}
		}
		  cout << s[n] << endl;

	}
	return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
int main(){
    string S; cin >> S;
    int count = 0;
    for(int i = 0; i < 3 ; i++){
        if(S.at(i) == '1'){
            count ++;
        }
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
using System;

public class Hello
{
    public static void Main()
    {
        string line;
        for (; (line = Console.ReadLine()) != null;)
        {
            var n = int.Parse(line.Trim());
            Console.WriteLine("{0} {1}", getPrime(n, -1), getPrime(n, 1));
        }
    }
    public static int getPrime (int n , int c)
    {
        var p = c;
        while (true)
        {
            if (IsPrime(n + p)) return n + p;
            else p += c;
        }
    }
    public static bool IsPrime(int n)
    {
        if (n < 2) return false;
        else if (n == 2) return true;
        else if (n % 2 == 0) return false; 
        double sqrtNum = Math.Sqrt(n);
        for (int i = 3; i <= sqrtNum; i += 2)
            if (n % i == 0) return false;
        return true;
    }
}

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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

map<ll, ll> prime_factorize(ll N) {
    map<ll, ll> res;
    for (ll i = 2; i * i <= N; ++i) {
        while (N % i == 0) {
            res[i]++;
            N /= i;
        }
    }
    if (N != 1) res[N] = 1;
    return res;
}

ll pow(ll x, ll y, ll mod) {
    if (y == 0) {
        return 1;
    }
    if (y % 2 == 0) {
        return pow(x * x % mod, y / 2, mod) % mod;
    } else {
        return x * pow(x, y - 1, mod) % mod;
    }
}


void Main() {
    ll N;
    cin >> N;
    vector<ll> A(N);
    rep(i, N) cin >> A[i];
    map<ll, ll> cnt;
    rep(i, N) {
        auto primes = prime_factorize(A[i]);
        for (P p : primes) {
            cnt[p.first] = max(p.second, cnt[p.first]);
        }
    }
    ll base = 1;
    for (P p : cnt) {
        base *= pow(p.first, p.second, MOD);
        base %= MOD;
    }
    ll ans = 0;
    rep(i, N) {
        ans += base * pow(A[i], MOD-2, MOD);
        ans %= MOD;
    }
    cout << ans << '\n';
}

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


Measured memory_bytes: 1024
def dfs(v,n,visited):
    all_visted=1
    for i in range(n):
        if visited[i]==0:
            all_visted=0
    if all_visted==1:
        return 1
    ret=0
    for i in range(n):
        if path[v][i]==0:
            continue
        if visited[i]==1:
            continue
        visited[i]=1
        ret+=dfs(i,n,visited)
        visited[i]=0
    return ret
n,m=map(int,input().split())
path=[[0]*n for i in range(n)]
for i in range(m):
    a,b=map(int,input().split())
    path[a-1][b-1]=1
    path[b-1][a-1]=1
visited=[0]*n
visited[0]=1
print(dfs(0,n,visited))


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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

#define EACH(i, a) for(auto&& i:a)
#define FOR(i,a,b) for(ll i = (a); i < (b); ++i)
#define RFOR(i,a,b) for(ll i = (b)-1; i >= (a); --i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define pb push_back
#define ALL(v) (v).begin(),(v).end()

const ll linf = 1e18;
const ll inf = 1e9;

template<class T>
istream& operator>>(istream& is, vector<T>& vec) {
    EACH(x,vec) is >> x;
    return is;
}

ll f(ll m) {
    return m * (m+1) / 2;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll A; cin >> A;
    ll l = 1, r = 1e6;
    REP(t, 50) {
        ll m = (l + r) / 2;
        if ( f(m) >= A ) {
            r = m;
        }
        else {
            l = m;
        }
    }
    ll L = r*2;
    if (r == 1) {
        cout << ")(" << endl;
    }
    else {
        ll x = A - f(r-1);
        string ans = "";
        REP(i, x) ans += ")";
        ans += "(";
        FOR(i, x, r) {
            ans += ")";
        }
        REP(i, r-1) {
            ans += "(";
        }
        cout << ans << endl;
    }
}

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

int main()
{
    int n,T,A,i,j,h=0;
    cin>>n;
    long long int arr[n];
    cin>>T>>A;
    for(i=0; i<n; i++)
        cin>>arr[i];
    double minD,diff,dif;
    minD=10000;
    for(i=0; i<n; i++)
    {
        dif=T-(0.006*arr[i]);
        diff=abs(dif-A);
        if(minD>diff){
            minD=diff;
            j=i;
        }
    }
    cout<<j+1<<endl;



    return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A,B;
  cin >> A ;
  cin >> B ;
  
  if (A == 1 && B == 2 || A == 2 && B == 1)
    cout << 3 <<endl;
    
  else if(A == 1 && B== 3 || A == 3 && B==1)
    cout << 2 <<endl;
  
  else
    cout << 1 <<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
 int main() {
     string s;
     cin>>s;
     if(s[0]=='A' && s[1]=='A' && s[2]=='A')
         cout<<"No"<<endl;
     else if(s[0]=='B' && s[1]=='B' && s[2]=='B')
         cout<<"No"<<endl;
     else cout<<"Yes"<<endl;
 return 0;
 }


Measured memory_bytes: 3168
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int md = 1e9 + 7;
int dp[41][1 << 18];

template < class T >
void add(T &a, T b){
    a += b;
    if(a >= md) a -= md;
}

int main(){
    int n, x, y, z;
    scanf("%d%d%d%d", &n, &x, &y, &z);
    int full = 1 << x + y + z + 1;
    dp[0][0] = 1;
    for(int i = 1; i <= n; i++){
        for(int mask = 0; mask < full; mask++){
            for(int j = 1; j <= 10; j++){
                int nxt = ((mask << j) | (1 << j)) & (full - 1);
                if((nxt & (1 << z)) && (nxt & (1 << y + z)) && (nxt & (1 << x + y + z)))
                    continue;
                add(dp[i][nxt], dp[i - 1][mask]);
            }
        }
    }
    int ans = 1;
    for(int i = 1; i <= n; i++) ans = (LL)ans * 10 % md;
    for(int mask = 0; mask < full; mask++){
        add(ans, md - dp[n][mask]);
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 41216
#include<stdio.h>
#include<algorithm>
using namespace std;
int b[310];
long long dp[310][310];
int sum[310];
int pow[10];
long long solve(int l,int r){
	if(l==r)return 0;
	if(~dp[l][r])return dp[l][r];
	long long ret=99999999999999LL;
	for(int i=l;i<r;i++){
		int L=sum[i+1]-sum[l];
		int R=sum[r+1]-sum[i+1];
		int c=0;
		long long cost=solve(l,i)+solve(i+1,r);
		while(L+R+c){
			cost+=(L%10)*(R%10);
			if(c+L%10+R%10>=10){
				c=1;
				cost++;
			}else c=0;
			L/=10;
			R/=10;
		}
		ret=min(ret,cost);
	}
	return dp[l][r]=ret;
}
int main(){
	int a;scanf("%d",&a);
	for(int i=0;i<a;i++)scanf("%d",b+i);
	for(int i=0;i<a;i++)sum[i+1]=sum[i]+b[i];
	for(int i=0;i<310;i++){
		for(int j=0;j<310;j++){
			dp[i][j]=-1;
		}
	}
	pow[0]=1;
	for(int i=1;i<10;i++)pow[i]=pow[i-1]*10;
	printf("%lld\n",solve(0,a-1));
}

Measured memory_bytes: 1804
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cctype>
#include<climits>
#include<string>
#include<bitset>
#include<cfloat>
#include<iomanip>
#include<numeric>

//#define int long long
#define repi(i,start,end) for(int (i)=(start),TemPNuM=(int)(end);(i)<TemPNuM;++(i))
#define rep(i,end) repi((i),0,(end))
#define rfor(x,v) for(auto& (x) : (v))
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define fsort(v,lambda) sort(all((v)),(lambda))
#define vin(v) rep(i,(v).size())cin >> (v)[i];
#define vpin(v) rep(i,(v).size())cin>>v[i].first>>v[i].second

using namespace std;
using ll =  long long;
using pint =  pair<int,int>;
using vint = vector<int>;
using vvint = vector<vint>;
using vpint = vector<pint>;

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; }
template<class T>void put_double(T a){if(cout.precision()!=12)cout<<setprecision(12);cout<<a<<endl;}
template<class T>void print(T a){cout << a << endl;}
//lambda: [](int x, int y){return x<y;}

signed main(void) {
    int k; cin >> k;
    ll ans = 0;
    rep(a, k) {
        rep(b, k) {
            rep(c, k) {
                ll g =  gcd(a + 1, b + 1);
                ans += gcd(g, c + 1);
            }
        }
    }
    print(ans);

    return 0;
}


Measured memory_bytes: 3676
#include <iostream>
using namespace std;
int main()
{
    int n,x;
    
     
    while(true){
         int d=0;
        cin>>n>>x;
        if(n==0 && x==0) break;

        for(int i=1;i<=n;i++)
	{
          for(int j=i+1;j<=n;j++)
          {
            for(int k=j+1;k<=n;k++)
	    {
                
		if((i+j+k)==x) d++;
		if((i+j+k)>x) break;
	    } 
           }
         } 
        cout<<d<<endl;
    } 
}

Measured memory_bytes: 3100
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810893364
#define PI 3.141592653589
typedef pair<int,int> PP;
typedef long long ll;
#define int ll
#define setdouble setprecision
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define GOODBYE do { cout << "0" << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl

signed main(void){
    int K,A,B;
    cin >> K >> A >> B;
    if(2>=B-A){
        cout << 1+K << endl;
    }else{
        K-=A-1;
        if(K<=0){
            cout << 1+K << endl;
            return 0;
        }
        int Ans=A;
        if(K%2==1){
            Ans+=1;
        }
        Ans+=(K/2)*(B-A);
        cout << Ans << endl;
    }
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
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 count=0;
  bool flg=true;
  while(flg){
    for(int i=0; i<N; i++){
      if(A.at(i)%2==0){
        A.at(i)/=2;
        continue;
      }
      else{
        flg=false;
        break;
      }
    }
    if(flg){
      count++;
    }
  }
  cout << count << endl;
}


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

int main()
{
  int i, a = 0, b= 0 ;
  string s;
  cin >> s;
  int l= s.size();
 
  
   for(i = 0; i < l; i+=2)
    {
     if(s[i]!= '0') a++;
    }

   for(i = 1; i < l; i+=2)
    {
     if(s[i]!= '1') b++;
    }

   int ans = a+b;
   if(ans <= l/2) cout << ans;
   else cout << l- ans;
}

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

vector<long> prime(long N){
    vector<long> p;
    vector<long> ret;
    for(long i=2;i<=N;i++){
        p.push_back(i); 
    }

    while(p.front()<=sqrt(N)){
        long a=p.front();
        ret.push_back(a);
        p.erase(p.begin());
        for(auto itr=p.begin();itr!=p.end();itr++){
            if(*itr%a==0){p.erase(itr);itr--;}
        }
    }
    for(auto i:p){
        ret.push_back(i);
    }
    return ret;
}

int main(){
	long x;cin >> x;
	vector<long> v=prime(x+100);
  	for(auto itr=v.end()-1;itr!=v.begin()-1;itr--){
    	if(x>*itr){
        	cout << *(itr+1);
          	return 0;
        }else if(x==*itr){
        	cout << *itr;
          	return 0;
        }
    }
  	return 0;
}


Measured memory_bytes: 1400
#include<bits/stdc++.h>
#include<iostream>
#include<stdio.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define fr(i,j,n)   for(long long i=j;i<(n);++i)
#define bk(i,j,n)   for(long long i=j;i>=n;--i)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define endl "\n"
#define MOD 1000000007
#define debug1(x) cout<<#x<<" "<<x<<endl;
#define debug2(x,y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<endl;
#define debug3(x,y,z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<endl;
#define srt(x) sort(x.begin(),x.end());
#define run ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ordered_set tree<ll , null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>

typedef long long ll;
ll modpower(ll a,ll b,ll c)
{
	ll res=1;
	while(b)
	{
		if(b&1LL)
			res=(res*a)%c;
		a=(a*a)%c;
		b>>=1;
	}
	return res;
}



int main()
{
    run;
    ll a,b,c;
    cin>>a>>b>>c;
    c-=(a+b);
    if(c<0)
    {
        cout<<"No";
        return 0;
    }
    ll p=4*a*b;
    ll i=c*c;
    if(i>p)
    {
        cout<<"Yes";
    }else{
    cout<<"No";}

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
//typedef tree <int,null_type,less <int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
// #include <ext/rope>
// using namespace __gnu_cxx;
typedef long long int ll;
typedef long double ld;
#define FAST                 \
    ios::sync_with_stdio(0); \
    cin.tie(0);              \
    cout.tie(0);
#define rep(g, i, n) for (ll g = i; g < n; g++)
#define rev(g, n, i) for (ll g = n - 1; g >= i; g--)
#define all(v) v.begin(), v.end()
#define pb push_back
#define mxe(v) *max_element(v.begin(), v.end())
#define mne(v) *min_element(v.begin(), v.end())
#define ve vector
#define lb lower_bound
#define ub upper_bound
#define bb break
#define cc continue
#define rem 1000000007
#define PI 3.141592653589793238462643383279502
ll power(ll x, ll y, ll p)
{
    ll res = 1; // Initialize result
    x = x % p;  // Update x if it is more than or
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1; // y = y/2
        x = (x * x) % p;
    }
    return res;
}
ll modInverse(ll n, ll p)
{
    return power(n, p - 2, p);
}
struct point
{
    ll x, y;
};
int main()
{
    FAST
    // freopen("input1.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    /*ll tests;
    cin>>tests;
    rep (gg,0,tests)
    {}*/
    ll n;
    cin>>n;
    ve <ll> arr(n);
    rep (i,0,n)
    {
        cin>>arr[i];
    }
    ll mn=arr[0];
    ll curr=1000;
    rep (i,0,n)
    {
        if (arr[i]>mn)
        {
            ll units=curr/mn;
            ll profit=(arr[i]-mn)*units;
            curr+=profit;
            mn=arr[i];
        }
        mn=min(arr[i],mn);
    }
    cout<<curr<<"\n";
}


Measured memory_bytes: 3656
#include <bits/stdc++.h>
#define ll long long int
#define booga cout << "booga" << endl
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
using namespace std;

void testcase(){

}

int main(int argc, char** argv){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n,a[100005],b[100005];
	cin >> n;
	for(int i{0};i < n+1;i++){
		cin >> a[i];
	}
	for(int i{0};i < n;i++){
		cin >> b[i];
	}
	ll ans = 0;
	
	for(int i{n-1};i >= 0;i--){
		if(b[i] >= a[i+1]){
			ans += a[i+1];
			b[i] -= a[i+1];
			a[i+1] = 0;
		}
		else{
			ans += b[i];
			a[i+1] -= b[i];
			b[i] = 0;
			
		}
		if(b[i] > 0){
			
			ans += min(a[i],b[i]);
			a[i] = max(0,a[i]-b[i]);
		}
	}
	cout << ans << "\n";
	return 0;
}



Measured memory_bytes: 1024
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
#define REP(i,a,b) for(int i=(a); i<(b); i++)
int main() {
	int n; scanf("%d", &n);
	switch(n%10) {
		case 2:
		case 4:
		case 5:
		case 7:
		case 9: puts("hon"); break;
		case 0:
		case 1:
		case 6:
		case 8: puts("pon"); break;
		case 3: puts("bon"); break;
	}
}


Measured memory_bytes: 1644