akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string>
#include <cstdio>
#include <vector>
#include <set>
#include <cassert>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <sstream>
#include <functional>
using namespace std;
/**==Info==
*Program:3
*Problem:Fennec VS. Snuke
*Date:2017-7-16
*Algorithm:BFS*/
vector<int> df;
vector<int> ds;
pair<int,int> roads[100005];
queue<int> q;
vector<int> nei[100005];

vector<int> bfs(int n,vector<int> nei[],int s){
	vector<int> d(n,0);
	q.push(s);
	d[s]=1;
	while(!q.empty()){
		int last=q.front();
		q.pop();
		for(int i=0;i<nei[last].size();i++){
			if(d[nei[last][i]]==0){
				d[nei[last][i]]=d[last]+1;
				q.push(nei[last][i]);
			}
		}
	}
	
	return d;
}

int main(){
	int n;
	cin>>n;
	for(int i=0;i<n-1;i++){
		int a,b;
		cin>>a>>b;
		a--;b--;
		roads[i]=(a>b?make_pair(b,a):make_pair(a,b));
		nei[a].push_back(b);
		nei[b].push_back(a);
	}
	
	
	df=bfs(n,nei,0);
	ds=bfs(n,nei,n-1);
	
	
	int fwin=0,swin=0;
	
	for(int i=0;i<n;i++){
		if(df[i]<=ds[i])fwin++;else swin++;
	}
	
	cout<<(fwin>swin?"Fennec":"Snuke");
	return 0;
}


Measured memory_bytes: 7424
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <limits>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x * x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

int main() {
	
	int a, b; cin >> a >> b;

	for (int i = 0; i < 100000; i++) {
		int x, y;
		x = i * 8 / 100;
		y = i / 10;

		if (x == a && y == b) {
			cout << i << endl;
			return 0;
		}
	}

	cout << "-1" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#define MAX 10000
#define NIL -1

struct N {int p,l,r;};
struct N T[MAX];
int n;

void preParse(int u){
  if(u==NIL){
    return;
  }
  printf(" %d",u);
  preParse(T[u].l);
  preParse(T[u].r);
}

void inParse(int u){
  if(u==NIL){
    return;
  }
  inParse(T[u].l);
  printf(" %d",u);
  inParse(T[u].r);
}

void postParse(int u){
  if(u==NIL){
    return;
  }
  postParse(T[u].l);
  postParse(T[u].r);
  printf(" %d",u);
}
int main(){
  int i,l,r,v,root;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    T[i].p=NIL;
  }

  for(i=0;i<n;i++){
    scanf("%d %d %d",&v,&l,&r);
    T[v].l=l;
    T[v].r=r;
    if(l!=NIL){
      T[l].p=v;
    }
    if(r!=NIL){
      T[r].p=v;
    }
  }
  for(i=0;i<n;i++){
    if(T[i].p==NIL){
      root=i;
    }
  }
  printf("Preorder\n");
  preParse(root);
  printf("\n");
  printf("Inorder\n");
  inParse(root);
  printf("\n");
  printf("Postorder\n");
  postParse(root);
  printf("\n");

  return 0;
}

Measured memory_bytes: 1856
#include <iostream>
#include <string>
#include <sstream>

void shf(std::string& C, int h)
{
	std::string temp = C.substr(h);
	std::string head = C.substr(0, h);

	C = temp + head;
}

int main()
{
	while (true)
	{
		std::string C;
		std::cin >> C;

		if (C == "-")
			break;

		int m;
		std::cin >> m;

		for (int n = 0; n < m; ++n)
		{
			int h;
			std::cin >> h;

			shf(C, h);
		}

		std::cout << C << std::endl;
	}

	return 0;
}


Measured memory_bytes: 3132
#include <iostream>
#include <string>
#include <map>
using namespace std;
map<string, int> table;
int main() {
	string word, frequent,longest;
	size_t N = 0; /*? ? ? frequent ? ? ? */
	while (cin >> word) 
	{
		table[word] += 1;
		if (table[word] > N)
		{
			N = table[word];
			frequent = word;
		}
		if (word.size() > longest.size())
			longest = word;
	}
	cout << frequent << ' ' << longest << endl;
}

Measured memory_bytes: 3000
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, e) for (int i = (int)(s); i <= (int)(e); i++)
#define printYesNo(is_ok) puts(is_ok ? "Yes" : "No");
#define SORT(v) sort(v.begin(), v.end());
#define RSORT(v) sort(v.rbegin(), v.rend());
#define REVERSE(v) reverse(v.begin(), v.end());

template <typename T>
void printlnVector(T v)
{
  rep(i, v.size())
  {
    cout << v[i] << endl;
  }
}

template <typename T>
void printVector(T v)
{
  rep(i, v.size())
  {
    cout << v[i] << " ";
  }
  cout << endl;
}

int main()
{
  int N;
  cin >> N;
  vector<long long> A(N);
  rep(i, N)
  {
    cin >> A[i];
  }
  long long ans = 0;
  if (N % 2 == 0)
  {
    RSORT(A);
    rep(i, N / 2 - 1)
    {
      ans += 2 * A[i];
    }
    ans += A[N / 2 - 1];
    SORT(A);
    rep(i, N / 2 - 1)
    {
      ans -= 2 * A[i];
    }
    ans -= A[N / 2 - 1];
  }
  else
  {
    long long score1 = 0, score2 = 0;
    RSORT(A);
    rep(i, (N - 1) / 2)
    {
      score1 += 2 * A[i];
    }
    SORT(A);
    rep(i, (N + 1) / 2 - 2)
    {
      score1 -= 2 * A[i];
    }
    score1 -= A[(N + 1) / 2 - 2];
    score1 -= A[(N + 1) / 2 - 1];

    SORT(A);
    rep(i, (N - 1) / 2)
    {
      score2 -= 2 * A[i];
    }
    RSORT(A);
    rep(i, (N + 1) / 2 - 2)
    {
      score2 += 2 * A[i];
    }
    score2 += A[(N + 1) / 2 - 2];
    score2 += A[(N + 1) / 2 - 1];
    ans = max(score1, score2);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1024
/**
*  author: Baibhav Kumar
*  created: 26.09.2020 18:00
**/

#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 0;i < n;i++) {
    cout << "ACL";
  }
  cout << endl;
  return 0;
}                                                                                               

Measured memory_bytes: 3608
#include<stdio.h>
#define FREE -1
#define NOT_FREE 1

int row[8]={FREE},col[8]={FREE},dpos[17]={FREE},dneg[17]={FREE},T[8][8];

void printBoard(void);

void recursive(int);

int main(){
  int k,i,r,c;
  scanf("%d",&k);
  for(i=0;i<k;i++){
    scanf("%d %d",&r,&c);
    T[r][c]=1;
  }
  recursive(0);
}

void printBoard(void){
  int i,j;
  for(i=0;i<8;i++){
    for(j=0;j<8;j++){
      if(T[i][j]){
	if(row[i]!=j){
	  return ;
	}
      }
    }
  }
  for(i=0;i<8;i++){
    for(j=0;j<8;j++){
      if(row[i]==j){
	printf("Q");
      }else{
	printf(".");
      }
    }
    printf("\n");
  }
}

void recursive(int i){
  int j;
  if(i==8){
    printBoard();
    return ;
  }

  for(j=0;j<8;j++){
    if(NOT_FREE == col[j] || NOT_FREE == dpos[i+j] || NOT_FREE == dneg[i-j+8-1]){
      continue;
    }
    row[i] = j;
    col[j] = dpos[i+j] = dneg[i-j+8-1] = NOT_FREE;
    recursive(i+1);
    row[i] = col[j] = dpos[i+j] = dneg[i-j+8-1] = FREE;
  }
}
  



Measured memory_bytes: 2104
from math import floor

def solve(X, D, lb, ub):
    # min abs(X + t * D) (lb <= t <= ub) (lb, ub, t are int)
    ts = [
        lb,
        ub,
        max(min(floor(-X / D), ub), lb),
        max(min(floor(-X / D) + 1, ub), lb),
    ]   
    return min([abs(X + t * D) for t in ts])

X, K, D = map(int, input().split())

y1 = X - K * D
y2 = X + K * D
if (y1 > 0 and y2 > 0) or (y1 < 0 and y2 < 0): # same sign
    print(min(abs(y1), abs(y2)))
else:
    if K % 2 == 0:
        ans = solve(X, D * 2, -(K // 2), +(K // 2))
    else:
        ans1 = solve(X + D, D * 2, -((K + 1) // 2), +((K - 1)) // 2)
        ans2 = solve(X - D, D * 2, -((K - 1) // 2), +((K + 1)) // 2)
        ans = min(ans1, ans2)
    print(ans)



Measured memory_bytes: 9184
#include<iostream>
using namespace std;
int main()
{
  int a, b, c;
  cin >> a >> b >> c;
  if(a >= b && a >= c)
    cout << 10 * a + b + c;
  if(b > a && b >= c)
    cout << 10 * b + a + c;
  if(c > a && c > b)
    cout << 10 * c + a + b;
  return 0;
}

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

const LLI mod = 1e9+7;

int main(){
  LLI N = 0;
  cin >> N;
  vector<LLI> A(N, 0);
  for(LLI n=0; n<N; n++){
    cin >> A[n];
  }

  LLI ans = 0;
  for (LLI i=0; i<60; i++){
    LLI zeros = 0, ones = 0;
    for(auto a:A){
      if((a>>i)&1) ones++;
      else zeros++;
    }
    LLI k = 1LL << i;
    k %= mod;
    k *= (zeros * ones) % mod;
    ans += k;
    ans %= mod;
  }
  cout << ans << endl;
}

Measured memory_bytes: 2560
def ok(a, b, hs, s):
    count = 0
    for h in hs:
        num, den = h-b*s, a-b
        if num < 0:
            continue
        count += (num+den-1)//den
    return count <= s

n, a, b = map(int, input().split())
hs = [int(input()) for _ in range(n)]

lo, hi = 0, 10**18
while(lo < hi):
    mi = (lo+hi)//2
    if(ok(a, b, hs, mi)):
        hi = mi
    else:
        lo = mi+1

print(lo)

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

/* メモリ食い過ぎ注意 */
#define int long long

typedef long long ll;

/* define const */
const ll INF = (1ll << 60);
const ll MOD = (ll)1e9 + 7;
/* end defineing */

int euclid(int a, int b)
{
    if (a < b)
        euclid(b, a);
    int r;
    while ((r = a % b))
    {
        a = b;
        b = r;
    }
    return b;
}

signed main()
{
    int n, X;
    vector<int> v;
    cin >> n >> X;
    for (int i = 0; i < n; i++)
    {
        int tmp;
        cin >> tmp;
        v.push_back(tmp);
    }
    sort(v.begin(), v.end());

    vector<int> sub;
    for (int i = 0; i < v.size(); i++)
    {
        sub.push_back(abs(X - v[i]));
    }

    int prev = sub[0];
    for (int i = 1; i < sub.size(); i++)
    {
        int tmp = euclid(prev, sub[i]);
        prev = tmp;
    }
    cout << prev << endl;
}


Measured memory_bytes: 2548
fn read_spc<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}

fn main() {
    remainder_reminder();
}

fn remainder_reminder() {
    let nk: Vec<i64> = read_spc();
    let n = nk[0];
    let k = nk[1];
    let mut m: i64 = 0;
       if k == 0 {
        m = n * n;
    } else {
        for b in 2..(n + 1) {
            let q = n / b;
            let r = n % b;
            m += q * max_i64(0, b - k) + max_i64(0, r - k + 1);
        }
    }
    println!("{}", m);
}

fn max_i64(n: i64, m: i64) -> i64 {
    let diff = n - m;
    match diff {
        diff if diff < 0 => m,
        _                => n
    }
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
int main(){
  int A,B,C;
  cin >> A >> B >> C;
  if(A==B&&B==C&&C==A&&A%2==0&&B%2==0&&C%2==0){
    cout << -1 << endl;
    return 0;
  }
  int counter=0;
  int tmpa,tmpb,tmpc;
  while(A%2==0 && B%2==0 & C%2==0){
    tmpa = A;
    tmpb = B;
    tmpc = C;
    A = (tmpb+tmpc)/2;
    B = (tmpa+tmpc)/2;
    C = (tmpa+tmpb)/2;
    counter++;
  }
  cout << counter << endl;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main()
{
  string s;
  int ans=0;
  cin>>s;
  if(s.size()>1)
    {
      for(int i=0;i<s.size()/2;i++)
	{
	  // cout<<"i= "<<i<<"  s-i-1="<<s.size()-1-i<<endl;
	  if(s[i]=='(')
	    {
	    if(s[s.size()-1-i]!=')')
	      ans++;
	    }
	  else if(s[i]==')')
	    {
	    if(s[s.size()-1-i]!='(')
	      ans++;
	    }
	  else if(s[i]!=s[s.size()-1-i])
	    ans++;
	}
    }
  if(s.size()%2!=0)
    if(s[s.size()/2]=='(' ||s[s.size()/2]==')')
      ans++;
      
cout<<ans<<endl;
}

Measured memory_bytes: 1180
N = int(input())

# dp = [0] * 100010
dp = []
for i in range(100010):
    dp.append(100000)

dp[0] = 0

for n in range(1, 100000 + 1):
    power = 1  # 1, 6, 36, 216
    while power <= n:
        dp[n] = min(dp[n], dp[n-power]+1)
        power *= 6

    power = 1  # 1, 9, 81, 729
    while power <= n:
        dp[n] = min(dp[n], dp[n-power]+1)
        power *= 9

print(dp[N])
# print(dp[:100])

Measured memory_bytes: 3864
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007;
vector<vector<double>>dp; // dp(i,j) probablity of coming j heads when i coins
vector<double>p;

double probhead(int n,int heads){

        if(dp[n][heads]!=-1){
            return dp[n][heads];
        }
        return dp[n][heads] = probhead(n-1,heads)*(1-p[n]) + probhead(n-1,heads-1)*p[n];

}
void solve(){
    int n;cin>>n;
    dp.resize(n+1,vector<double>(n+1,-1));
    p.resize(n+1);
    for(int i=1;i<=n;i++){
        cin>>p[i];
    }
    for(int i=0;i<=n;i++){
        dp[0][i]=0;
    }
    dp[0][0]=1;
    for(int i=1;i<=n;i++){
        dp[i][0] = dp[i-1][0]*(1-p[i]);
    }

    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            dp[i][j] = dp[i-1][j]*(1-p[i]) + dp[i-1][j-1]*p[i];
        }
    }

    double pr =0;
    for(int i=(n+1)/2;i<=n;i++){
          pr += dp[n][i];
    }
    cout<<pr<<"\n";

}

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

    cout.precision(10);
    int t=1;//cin>>t;
    while(t--){

        solve();
    }
    return 0;
}


Measured memory_bytes: 70656
S,T=[0],[0]
for k,c in enumerate(input()):S+=[S[-1]+1+(c=='B')]
for k,c in enumerate(input()):T+=[T[-1]+1+(c=='B')]
for _ in[0]*int(input()):
    a,b,c,d=map(int,input().split())
    print(['YES','NO'][(T[d]-T[c-1]-S[b]+S[a-1])%3>0])

Measured memory_bytes: 12256
N = int(input())
X = [int(i) for i in input().split()]

Y = sorted(X)
right_center = Y[N // 2]
left_center = Y[N // 2 - 1]
for i in X:
    if i < right_center:
        print(right_center)
    elif i > left_center:
        print(left_center)
    # 中央値がどちらも同じだった場合
    elif i == right_center:
        print(right_center)


Measured memory_bytes: 25224
function Main(input) {
    const firstNum = Number(input[0] + input[1]);
    const secondNum = Number(input[2] + input[3]);
    const isPossibleMonth = num => {
        return 1 <= num && num <= 12;
    };
    if (isPossibleMonth(firstNum) && isPossibleMonth(secondNum)) {
        console.log("AMBIGUOUS");
    } else if (isPossibleMonth(firstNum)) {
        console.log("MMYY");
    } else if (isPossibleMonth(secondNum)) {
        console.log("YYMM");
    } else {
        console.log("NA");
    }
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

int main() {
  string n;
  cin >> n;
  for (int i = 0; i < int(pow(2, 3)); i++) {
    vector<bool> op_plus(3, false);
    for (int j = 0; j < 3; j++) {
      op_plus[j] = bool(i & int(pow(2, j)));
    }
    int ans = n.at(0) - '0';
    for (int k = 1; k < 4; k++) {
      if (op_plus.at(k - 1)) {
        ans += n.at(k) - '0';
      } else {
        ans -= n.at(k) - '0';
      }
    }
    if (ans == 7) {
      cout << n.at(0);
      for (int l = 0; l < 3; l++) {
        if (op_plus.at(l)) {
          cout << "+";
        } else {
          cout << "-";
        }
        cout << n.at(l + 1);
      }
      cout << "=7" << endl;
      return 0;
    }
  }
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#define pb push_back
#define mp make_pair
using namespace std;
main()
{
    int a,b,i;
    cin>>a>>b;
    if(a>b)
        swap(a,b);
    for(i=1;i<=b;i++)
        cout<<a;
}

Measured memory_bytes: 3588
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 10**18
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

h,w,d = inm()
a = []
for i in range(h):
    a.append(inl())
t = [[] for i in range(d)]
for i in range(h):
    for j in range(w):
        x = a[i][j]
        t[x%d].append((x,i,j))
for i in range(d):
    t[i].sort()
#ddprint(t)
acc = [[0]*(len(t[i])+1) for i in range(d)]
for i in range(d):
    for j in range(1,len(t[i])):
        acc[i][j] = acc[i][j-1] + abs(t[i][j][1]-t[i][j-1][1]) \
                                + abs(t[i][j][2]-t[i][j-1][2])
#ddprint(acc)
q = inn()
for qq in range(q):
    l,r = inm()
    i = l%d
    j = l//d
    k = r//d
    if i==0:
        j -= 1
        k -= 1
    print(acc[i][k]-acc[i][j])


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

long sequence(long n, long* a)
{
  long i,sum,count1,count2;
  sum = 0;
  count1 = 0;
  for(i = 0; i < n; i++){
    sum += a[i];
    if(i % 2 == 1 && sum <= 0){
      count1 += (1-sum);
      sum = 1;
    }
    if(i % 2 == 0 && sum >= 0){
      count1 += sum+1;
      sum = -1;
    }
  }
  sum = 0;
  count2 = 0;
  for(i = 0; i < n; i++){
    sum += a[i];
    if(i % 2 == 1 && sum >= 0){
      count2 += sum+1;
      sum = -1;
    }
    if(i % 2 == 0 && sum <= 0){
      count2 += 1-sum;
      sum = 1;
    }
  }
  if(count1 < count2){
    return count1;
  }else{
    return count2;
  }
}

int main()
{
  long n,i,result;
  if(scanf("%ld", &n) < 1){
      exit(1);
  }
  long a[n];
  for(i = 0; i < n; i++){
    if(scanf("%ld", &a[i]) < 1){
      exit(1);
    }
  }
  result = sequence(n, a);
  printf("%ld\n",result);
  return 0;
}

Measured memory_bytes: 896
#include <iostream>
#include <algorithm>
 
#define int long long
 
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF (LLONG_MAX - 1e5)
 
using namespace std;
 
int N, A[200005];
 
signed main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
 
    cin >> N;
    REP(i, N) {
        cin >> A[i];
        A[i] -= i + 1;
    }
    sort(A, A + N);
 
    int b = A[N / 2];
 
    int ans = 0;
    REP(i, N) { ans += abs(A[i] - b); }
    cout << ans << endl;
 
    return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>

using namespace std;

int h,w,g4,g2,g1;
int cnt[27];
char s[109];

inline void ends()
{
	puts("No");
	exit(0);
}

int main()
{
	scanf("%d%d",&h,&w);
	for(int i=1;i<=h;i++)
	{
		scanf("%s",s+1);
		for(int i=1;i<=w;i++)
			cnt[s[i]-'a']++;
	}

	if(h&1)
		g2+=w/2;
	if(w&1)
		g2+=h/2;
	if((h&1) && (w&1))
		g1++;
	g4=(h*w-g2*2-g1)/4;

	for(int i=1;i<=g4;i++)
	{
		int p=0;
		while(cnt[p]<4 && p<26)p++;
		if(p==26)ends();
		cnt[p]-=4;
	}
	
	for(int i=1;i<=g2;i++)
	{
		int p=0;
		while(cnt[p]<2 && p<26)p++;
		if(p==26)ends();
		cnt[p]-=2;
	}

	if(g1)
	{
		for(int i=0;i<=25;i++)
			if(cnt[i]>=1)
			{
				puts("Yes");
				return 0;
			}
	}
	else
	{
		puts("Yes");
		return 0;
	}
	ends();
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define INF 1e9
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;


int main() {
	int n,x;
	cin>>n>>x;
	int a[n];
	rep(i,n) cin>>a[i];
	ll ans=0;
	rep(i,n-1){
		if(a[i]+a[i+1]>x){
			int tmp=a[i]+a[i+1]-x;
			if(tmp>a[i+1]){
				ans+=a[i+1];
				tmp-=a[i+1];
				a[i+1]=0;
				
				ans+=tmp;
			}
			else{
				ans+=tmp;
				a[i+1]-=tmp;
			}
		}
	}
	cout<<ans<<endl;
}

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

const double PI = 3.14159265358979323846;
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
//#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
//typedef pair<ll, ll> P;
typedef pair<ll, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

std::istream &operator>>(std::istream &in, set<int> &o) {
    ll a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
const int mod = 1000000007;
//const ll mod = 1e10;
typedef priority_queue<string, vector<string>, greater<string> > PQ_ASK;

#include <iostream>
#include <vector>

using namespace std;

class MatrixSum {
    vector<vector<ll>> sum;
    ll w, h;
public:
    MatrixSum(ll w, ll h) : w(w), h(h) {
        sum = vector<vector<ll>>(w, vector<ll>(h));
    }

    void add(ll x, ll y, ll value) {
        if (x == w || y == h) return;
        sum[x][y] += value;
    }

    ll get(ll x, ll y) {
        if (x == -1 || y == -1) {
            return 0;
        }
        if (x == sum.size() || y == sum[x].size()) {
            return 0;
        }
        return sum[x][y];
    }

    void setUp() {
        for (ll x = 0; x < sum.size(); x++) {
            for (ll y = 0; y < sum[x].size(); y++) {
                sum[x][y] += get(x - 1, y) + get(x, y - 1) - get(x - 1, y - 1);
            }
        }
    }

    ll getSum(ll xs, ll ys, ll xe, ll ye) {
        return get(xe, ye) - get(xs - 1, ye) - get(xe, ys - 1) + get(xs - 1, ys - 1);
    }

};

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

    MatrixSum ms(n, n);

    rep(i, m) {
        ll l, r;
        cin >> l >> r;
        l--;
        r--;

        ms.add(l, r, 1);
    }

    ms.setUp();

    rep(i, q) {
        ll l, r;
        cin >> l >> r;
        l--;
        r--;
        cout << ms.getSum(l, l, r, r) << endl;
    }


}





Measured memory_bytes: 2944
#include <stdio.h>

int main(void)

{

int a,b;

scanf("%d %d",&a,&b);

if(a>b) printf("a > b\n",a,b);

else if(a<b) printf("a < b\n",a,b);

if(a==b) printf("a == b\n",a,b);

return 0;

}

Measured memory_bytes: 580
#include <assert.h>
#include <ctype.h>
#include <errno.h>
#include <float.h>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <set>
#include <queue>
#include <limits>
#include <deque>
#include <locale>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <wchar.h>
#include <wctype.h>
#include <algorithm>
#include <bitset>
#include <map>
#include <iomanip>
#include <ios>
#include <iostream>
#include <vector>
#include <cwchar>
#include <cwctype>
#define mp make_pair
#define fs first
#define se second
#define memset(a,t) memset(a,t,sizeof(a))
#define all(v) v.begin(),v.end()
#define eprintf(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define MN 0LL
#define Mx 200000005
#define Mn -Mx
#define MX 20000000000000005
using namespace std;
int readint(){
	char c;
	while(c=getchar(),(c<'0'||c>'9')&&c!='-');
	bool flag=(c=='-');
	if(flag)c=getchar();
	int x=0;
	while(c>='0'&&c<='9'){
		x=x*10+c-48;
		c=getchar();
	}
	return flag?-x:x;
}
inline string tos(int x){
	string s;
	while(x) s=(char)(x%10+'0')+s,x/=10;
	return s;
}
long long n,a[100005],b[100005];
int main(){
	ios_base::sync_with_stdio(false);
	long long i,j,ans=0;
	cin>>n;
	for(i=0;i<n;i++) cin>>a[i]>>b[i];
	for(i=n-1;i>-1;i--){
		if((a[i]+ans)%b[i]!=0){
			long long t=b[i]-((ans+a[i])%b[i]);
//			for(j=0;j<=i;j++) a[j]+=t;
			ans+=t;
//			cout<<ans<<endl;
//			for(j=0;j<n;j++) cout<<a[j]<<" ";
//			cout<<endl;
		}
	}
	cout<<ans<<endl;
	return 0;
}


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

int main(){
  int H,i,*A;

  scanf("%d",&H);
  A = (int *)malloc(sizeof(int) * (1 +H));
  for(i = 1;i < H + 1;i++){
    scanf("%d",&A[i]);
  }

  for(i = 1;i < H + 1;i++){
    printf("node %d: key = %d, ",i,A[i]);
    if(i == 1) printf("left key = %d, right key = %d, ",A[i * 2],A[i * 2 + 1]);
    else{
      printf("parent key = %d, ",A[i / 2]);
      if(i * 2 <= H){
	printf("left key = %d, ",A[i * 2]);
      if(i * 2 + 1 <= H) printf("right key = %d, ",A[i * 2 + 1]);
      }
    }
    printf("\n");
  }
  
  free(A);
  return 0;
}




Measured memory_bytes: 2104
/*@author hussein zayed ;
    ___  ___
   |\  \|\  \
   \ \  \_\  \
    \ \   ___ \USSEIN
     \ \  \\ \ \
      \ \__\\ \_\
       \|__| \|__|
****************************************
*/

#include <bits/stdc++.h>
using namespace std;
#define fr for(int i=0;i<n;++i)
#define fr1 for(int i=1;i<=n;++i)
#define cinA for(int i=0;i<n;++i){cin>>arr[i];}
#define cinA1 for(int i=1;i<=n;++i){cin>>arr[i];}
#define coutA for(int i=0;i<n;++i){cout<<arr[i]<<" ";}
#define ll long long
#define lnarray sizeof(arr)/sizeof(*arr)
#define vi vector<int>
#define vs vector<string>
void Fast()
{
    ios_base :: sync_with_stdio( 0 ) ;
    cin.tie( 0 ) ;
    cout.tie( 0 ) ;
}
inline int RD()
{
    int i ;
    cin>>i;
    return i;
}

inline float RF()
{
    float i ;
    cin>>i;
    return i;
}

inline double RDO()
{
    double i ;
    cin>>i;
    return i;
}

inline string RS()
{
    string i ;
    cin>>i;
    return i;
}

inline ll RLL()
{
    ll i ;
    cin>>i;
    return i;
}

int cm[200000];

ll sumSet(ll n)
{
    return (1ll*n*(n+1))/2;
}
string s;


bool isPrime(int n)
{
    if(n==1)
        return false;
    for(int i=2; i*i<=n; ++i)
    {
        if(n%i==0)
            return false;
    }
    return true;
}
int sumDigit(int n){
int sum =0;
  while (n != 0)
    {
        sum+= + n % 10;
        n = n / 10;
    }
    return sum;
}

ll power2(int n){
  ll ans=(1<<n);
  return ans;
}

ll sumpow2(ll n){
 ll sum=(n*(n+1)*(2*n-1))/6;
 return sum;
}

int main(){
    Fast();
//freopen("output.txt" , "w" , stdout);
//freopen("wall.in" , "r" , stdin);
int n=RD(),a=RD(),b=RD();
int t=n*a;
cout<<min(t,b)<<"\n";

}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define pb push_back
#define IOS ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define Test int T;cin>>T;while(T--)
#define ls lower_bound
#define up upper_bound
#define bs binary_search
#define S second
#define F first
#define vi vector<int>  
#define pii pair<int,int>
#define vpi vector<pii>
#define vvi vector<vi>
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define m_n(v) *min_element(all(v))
#define m_x(v) *max_element(all(v))
#define ___(a) for(auto &i:a) cin>>i
/* 
#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;
*/
int power(int x, int y,int mod){
    int res = 1;
    while (y)
    {
        if (y & 1)
        res = (res*x)%mod;
        y = y>>1;
        x = (x*x)%mod;
    }
    return res;
}
int modInverse(int a, int m){
    int m0 = m;
    int y = 0, x = 1;

    if (m == 1)
      return 0;

    while (a > 1)
    {
        int q = a / m;
        int t = m;
        m = a % m, a = t;
        t = y;
        y = x - q * y;
        x = t;
    }
    if (x < 0)
       x += m0;

    return x;
}
int binomial(int n,int k){
    int res = 1;
    if ( k > n - k )
        k = n - k;

    for (int i = 0; i < k; ++i)
    {
        res *= (n - i);
        res /= (i + 1);
    }

    return res;
}
/*
vector<int> prime;
void sieve(){
    bool arr[300000]={0};
    prime.pb(2);
    for(int i=3;i<300000;i+=2){
        if(arr[i])continue;
        for(int j=i*i;j<300000;j+=i) arr[j]=1;
        prime.pb(i);
    }
}*/
//const int N=1e18+2;
const int mod = 1e9+7;
const int N= 1e5+9;

int32_t main() {
    IOS;
    int n;
    cin>>n;
    cout<<n+n*n+n*n*n;
    return 0;
}

Measured memory_bytes: 3608
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Math;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            A();
        }

        static void A()
        {
            var rDx = ReadSplitLong();
            var r = rDx[0];
            var D = rDx[1];
            var x = rDx[2];
            var nextYear = -1L;
            for (int i = 0; i < 10; i++)
            {
                if (nextYear == -1)
                    nextYear = (r * x) - D;
                else
                    nextYear = (r * nextYear) - D;

                Println(nextYear);
            }
        }

        static IEnumerable<int> Range(int start, int stop)
        {
            if (start < 0 || stop < 0 || start > stop || (start <= 0 && stop <= 0))
                return new List<int>();

            return Enumerable.Range(start, stop - start);
        }

        static bool IsDigit(string str)
        {
            var i = 0;
            return int.TryParse(str, out i);
        }

        static int DigitsSum(long num)
        {
            return num.ToString().Select(x => x.ToString()).Sum(int.Parse);
        }

        static int[] ToIntArray(string str)
        {
            return str.Select(x => x.ToString()).Select(int.Parse).ToArray();
        }

        static int Gcd(int a, int b) => b == 0 ? a : Gcd(b, a % b);

        static bool IsPrime(int x)
        {
            if (x <= 1 || (x != 2 && x % 2 == 0)) return false;
            if (x == 2) return true;

            for (int i = 3; i < x; i += 2)
                if (x % i == 0) return false;

            return true;
        }

        static string Read() => Console.ReadLine();
        static int ReadInt() => int.Parse(Read());
        static long ReadLong() => long.Parse(Read());

        static List<string> ReadSplit() => Read().Split().ToList();
        static List<int> ReadSplitInt() => Read().Split().Select(int.Parse).ToList();
        static List<long> ReadSplitLong() => Read().Split().Select(long.Parse).ToList();

        static void Print(object value) => Console.Write(value.ToString());
        static void Println(object value) => Console.WriteLine(value.ToString());

        static string Join<T>(IEnumerable<T> list) => string.Join("", list);
    }

    public static class MyExtensions
    {
        public static string Slice(this string str, int start = 0, int stop = 0)
        {
            if (start > str.Length || stop > str.Length || start < 0 || stop < 0)
                return "";

            if (stop == 0) stop = str.Length;
            return str.Substring(start, stop - start);
        }
    }
}



Measured memory_bytes: 11348
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>

using namespace std;

int main(void) {
	int n, a, b;
	cin >> n >> a >> b;
	int A = a * n;
	int B = b;
	if (A <= B) cout << A;
	else cout << B;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<int> a1(n), a2(n);
  for(int i=0;i<n;i++) cin >> a1[i];
  for(int i=0;i<n;i++) cin >> a2[i];
  int s = 0;
  for(int i=0;i<n;i++) s+= a1[i];
  int m=s+a2[n-1];
  int c=m;
  for(int i=n-2;i>=0;i--){
    c+=a2[i]-a1[i+1];
    m=max(m,c);
  }
  cout << m;
  return 0;
}

Measured memory_bytes: 384
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb emplace_back
#define INF (1e9+1)
//#define INF (1LL<<59)

int main(){
    int a,b;
    cin>>a>>b;
    cout<<(a+b)%24<<endl;
}

Measured memory_bytes: 764
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
using namespace std;
typedef long long ll;
#define rep(i,s,n)for(int i = s;i<n;i++)
#define repe(i,s,n)for(int i = s;i<=n;i++)

int main() {
	ll N, X; cin >> N >> X;
	ll m, minV = 1 << 21;
	rep(i, 0, N) {
		cin >> m;
		X -= m;
		minV = min(minV, m);
	}
	cout << N + X / minV << endl;
}

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

namespace ProgramingStudying2
{
    class Program
    {

        static void Main(string[] args)
        {
            var s = Console.ReadLine();
            var w = int.Parse(Console.ReadLine());
            var ans = "";

            for (int i = 0; i < s.Length; i += w)
            {
                ans += s[i];
            }
            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 27936
#include <bits/stdc++.h>
#define inf 1000000000
#define met(a,b) memset(a,b,sizeof a)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define pb push_back
#define mp make_pair
typedef long long ll;
using namespace std;
const int N = 1e5+5;
const int M = 4e2+50;
const ll mod = 1e9+7;
int n,m,k=0,x=0,y=0;
ll ans,sz[N],sum[N];
int vis[N],pre[N];
vector<int>edg[N];
void bfs(int p){
    queue<int>q;
    q.push(1);
    vis[1]=1;
    while(!q.empty()){
        int u=q.front();
        //printf("!!!%d\n",u);
        q.pop();
        bool flag=false;
        for(int v:edg[u]){
            if(!vis[v]){
                flag=true;
                vis[v]=1;
                q.push(v);
                if(!p)pre[v]=u,k++;
                else pre[u]=v,k++;
                break;
            }
        }
        if(!flag){
            if(p)x=u;
            else y=u;
            //printf("%d %d\n",x,y);
            break;
        }
    }
}
int main() {
    int op,u,v;
    scanf("%d%d",&n,&m);
    while(m--){
        scanf("%d%d",&u,&v);
        edg[u].pb(v);
        edg[v].pb(u);
    }
    bfs(0);
    bfs(1);
    printf("%d\n%d",k+1,y);
    while(x!=y){
        printf(" %d",pre[y]);
        y=pre[y];
    }
    //printf(" %d\n",x);
    return 0;
}


Measured memory_bytes: 8064
N, M = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
A = sorted(A, reverse=True)
B = sorted(B, reverse=True)
MOD = 10 ** 9 + 7
ia, ib = 0, 0
x = N * M - 1
ans = 1
for i in range(N * M, -1, -1):
    x = i
    if ia == N and ib == M:
        break
    elif ia < N and ib < M and A[ia] == x and B[ib] == x:
        ia += 1
        ib += 1
    elif ia < N and A[ia] == x:
        ans *= ib
        ans %= MOD
        ia += 1
    elif ib < M and B[ib] == x:
        ans *= ia
        ans %= MOD
        ib += 1
    else:
        ans *= ia * ib - (N * M - x)
        ans %= MOD

for i in range(1, x + 1):
    ans *= i
    ans %= MOD

print(ans)

Measured memory_bytes: 43372
#include<bits/stdc++.h>
#define FOR(i,m,n) for(int i=m;i<(n);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
const ll inf = INT_MAX;
const double eps = 1e-8;
const double pi = acos(-1.0);

// aにするのに必要な操作回数
int alpha_distance (char const al) {
  return (int)(('a' - al + 26) % 26);
}

// 操作をする
char roll (char const al, int num) {
  return (al + num - 'a') % 26 + 'a';
}

int main(void){
  string s;
  cin >> s;
  int k;
  cin >> k;
  REP (i, s.size()) {
    if (i == (int)s.size() - 1)
      cout << roll(s[i], k);
    else if (k >= alpha_distance(s[i])) {
      cout << roll(s[i], alpha_distance(s[i]));
      k -= alpha_distance(s[i]);
    } else {
      cout << s[i];
    }
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 512
# include <iostream>
# include <algorithm>
#include <array>
# include <cassert>
#include <cctype>
#include <climits>
#include <numeric>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <tuple>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
# include <chrono>
# include <random>
# include <limits.h>
# include <unordered_map>
# include <unordered_set>
# include <deque>
# include <cstdio>
# include <cstring>
#include <stdio.h>
#include<time.h>
#include <stdlib.h>
#include <cstdint>
#include <cfenv>
#include<fstream>

//#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
long long MOD = 1000000000 + 7;// ;//1000000000 + 7 998244353 924844033 1000000000 + 9;
constexpr long long INF = numeric_limits<LL>::max();
constexpr long long DINF = 1000000000000;
const double PI = acos(-1);
#define fir first
#define sec second
#define thi third
#define debug(x) cerr<<#x<<": "<<x<<'\n'
typedef pair<LL, LL> Pll;
typedef pair<double, double> Dll;
typedef pair<LL, pair<LL, LL>> Ppll;
typedef pair<LL, pair<LL, bitset<100001>>> Pbll;
typedef pair<LL, pair<LL, vector<LL>>> Pvll;
typedef pair<LL, LL> Vec2;
struct Tll { LL first, second, third; };
struct Fll { LL first, second, third, fourth; };
typedef pair<LL, Tll> Ptll;
#define rep(i,rept) for(LL i=0;i<rept;i++)
#define Rrep(i,mf) for(LL i=mf-1;i>=0;i--)
void YN(bool f) {
	if (f)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
}
void yn(bool f) {
	if (f)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}
struct Edge { LL to, cost; };
struct edge {
	LL from, to, cost;
};
vector<vector<Edge>>g;
vector<edge>ed;
vector<Pll>pv;
map<LL, LL>ma;
set<LL>st;
int di[4][2] = { { 0,1 },{ 1,0 },{ 0,-1 },{ -1,0 } };
LL n, m, k, p, q, w, h, s, t, ans, cnt, sum, a[210000], dp[3000][3000][4];
string str;
bool f[110000];
char c[3000][3000];
LL dfs(LL x, LL y, LL dir) {
	if (dp[x][y][dir] != -1)return dp[x][y][dir];
	if (y == w - 1 && dir == 0)dp[x][y][dir] = 0;
	else if (x == h - 1 && dir == 1)dp[x][y][dir] = 0;
	else if (y == 0 && dir == 2)dp[x][y][dir] = 0;
	else if (x == 0 && dir == 3)dp[x][y][dir] = 0;
	else {
		if (c[x + di[dir][0]][y + di[dir][1]] == '#')
			dp[x][y][dir] = 0;
		else
			dp[x][y][dir] = dfs(x + di[dir][0], y + di[dir][1], dir) + 1;
	}
	return dp[x][y][dir];
}
int main() {
	cin >> h >> w;
	rep(i, h) {
		rep(j, w) {
			cin >> c[i][j];
			rep(k, 4)dp[i][j][k] = -1;
		}
	}
	rep(i, h) {
		rep(j, w) {
			LL cur = 0;
			rep(k,4)
			cur+=dfs(i,j,k);
			if(c[i][j]!='#')
			ans = max(ans,cur+1);
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 194816
n, m = map(int, input().split())
ab = sorted([tuple(map(int, input().split())) for i in range(n)])

x = 0
res = 0
i = 0
while True:
    a, b = ab[i]
    if x + b >= m:
        res += (m - x) * a
        break
    else:
        res += b * a
        x += b
    i += 1

print(res)

Measured memory_bytes: 17752
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 10000000000000000


int main(){
	
	string S;
	cin>>S;
	
	if(S=="hi"||S=="hihi"||S=="hihihi"||S=="hihihihi"||S=="hihihihihi")cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)n; i++)
#define all(x) (x).begin(),(x).end()
typedef long long int ll;
using namespace std;
int main()
{
  string a;
  cin >> a;
  int n = stoi(a);
  int tmp = 0;
  REP(i, a.size()){
    tmp += a[i] - '0';
  }
  cout << ((n%tmp == 0)?"Yes":"No") << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int a[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  int n;
  cin >> n;
  cout << a[n-1] << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
int sosuu(int );
int main(){
  int i,j,n,key,c=0;
  int *a;
  
  scanf("%d",&n);

a=malloc(n*sizeof(int));

  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
  }

  for(i=1;i<n;i++){
    key=a[i];
    j=i-1;
    while(j>=0 && a[j]>key){
      a[j+1]=a[j];
      j--;
    }
    a[j+1]=key;
  }
  c+=sosuu(a[0]);
  for(i=1;i<n;i++){
    if (a[i]!=a[i-1]){
     c += sosuu(a[i]); 
    }
  }
  printf("%d\n",c);
  free(a);
  return 0;
}

int sosuu(int x){
  int i,j=0;
  if(x==1)return 0;
  for(i=2; i <= sqrt(x) ;i++){
    if(x%i==0)return 0;
  }
  return 1;
}

Measured memory_bytes: 628
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

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

/*----------macros----------*/

//output================
#define endl '\n'
#define fcout cout << fixed << setprecision(15)

//typedef===============
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;

//const number==========
constexpr ll INF9   = (ll)1e9 + 1;
constexpr ll INF18  = (ll)1e18 + 1;
constexpr ll MOD    = 1000000007;
constexpr ld PI     = 3.141592653589793L;

//member================
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second

//others================
#define all(x)          (x).begin(), (x).end()
#define rall(x)         (x).rbegin(), (x).rend()
#define rep(i, n)       for(int i = 0; (i) < (int)(n); (i)++)
#define rrep(i, n)      for(int i = n - 1; (i) >= 0 ; (i)--)
#define For(i, a, b)    for(int i = (a); (i) < (int)(b) ; (i)++)
#define CtoI(c)         int((c)) - int('0')

//functions=============
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

//vector<int> dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};
//vector<int> dx2 = { 1,1,0,-1,-1,-1,0,1 }, dy2 = { 0,1,1,1,0,-1,-1,-1 };



/*--------additional--------*/



/*----------main------------*/

int main() {
/*----------fastio----------*/
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
    std::ios::sync_with_stdio(false);
/*----------solve-----------*/

    int h, n; cin >> h >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    for(int i = 0; (h > 0 && i < n); i++){
        h -= a[i];
    }

    cout << (h > 0 ? "No" : "Yes") << endl;

return 0;
}

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

int main()
{
    int n, s[100005], q, t[50005];
    cin >> n;
    for(int i=0; i<n; i++)
        cin >> s[i];
    cin >> q;
    int count = 0;
    for(int i=0; i<q; i++)
    {
        cin >> t[i];
        if(*lower_bound(s, s+n, t[i])==t[i])
        {
            count++;
        }
    }
    cout << count << endl;
    return 0;
}

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

#define watch(x) cout << (#x) << " is " << (x) << endl
#define fr(i,n) for(int i=0; i<n; i++)
#define rep(i, st, en) for(int i=st; i<=en; i++)
#define repn(i, st, en) for(int i=st; i>=en; i--)
#define sq(a) (a*a)
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll mod = 1e9+7;


void solve(){
    int a, b, c, d;
    cin>>a>>b>>c>>d;
    int t1 = (c + b - 1)/b;
    int t2 = (a + d - 1)/d;
    if(t1 <= t2) cout<<"Yes";
    else cout<<"No";
}

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

    ll t = 1;
    //  cin>>t;
    while(t--){
        solve();
    }

    return 0;
}



Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define mp make_pair
#define met(a) memset(a,0,sizeof(a))
#define ll long long
using namespace std;
const int maxn = 2000010;
char s[100010];
int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    int i,j,m,n;
    cin>>m>>n;
    if(m>=n)
    cout<<m-n<<endl;
    else
        cout<<0<<endl;
    return 0;
}


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

struct edge {
	int to, cost;
};
class dijkstra {
	int V;
	int d[100002];
	priority_queue<P, vector<P>, greater<P>> que;
	void update(int s, vector<edge> G[]) {
		fill(d, d + V + 1, 100000000000ll);
		d[s] = 0;
		que.push(make_pair(0, s));
		while (!que.empty()) {
			P p = que.top();
			que.pop();
			int v = p.second;
			if (d[v] < p.first) continue;
			rep(i, G[v].size()) {
				edge e = G[v][i];
				if (d[e.to] > d[v] + e.cost) {
					d[e.to] = d[v] + e.cost;
					que.push(make_pair(d[e.to], e.to));
				}
			}
		}
	}

  public:
	dijkstra(int v, int s, vector<edge> G[]) {
		V = v;
		update(s, G);
	}
	int find(int e) {
		return d[e];
	}
};
int gcd(int a, int b) {
	if (a % b == 0)
		return b;
	else
		return gcd(b, a % b);
}
int lcm(int a, int b) {
	return a * b / gcd(a, b);
}
bool prime(int a) {
	if (a == 1) return false;
	for (int i = 2; i * i <= a; i++) {
		if (a % i == 0) return false;
	}
	return true;
}
class Union_Find {
  private:
	vector<int> t, s;

  public:
	Union_Find(int max_length) {
		rep(i, max_length + 1) {
			t.push_back(i);
			s.push_back(1);
		}
	}
	void Union(int x, int y) {
		if (same(x, y)) return;
		int tx = Find(x), ty = Find(y);
		if (s[tx] < s[ty]) {
			s[ty] += s[tx];
			t[tx] = ty;
		}
		else if (s[tx] > s[ty]) {
			s[tx] += s[ty];
			t[ty] = tx;
		}
		else if (tx > ty) {
			t[tx] = ty;
			s[ty] += s[tx];
		}
		else {
			t[ty] = tx;
			s[tx] += s[ty];
		}
	}
	int Find(int n) {
		if (t[n] == n)
			return n;
		else
			return t[n] = Find(t[n]);
	}
	bool same(int x, int y) {
		return Find(x) == Find(y);
	}
	int get_Size(int a) {
		return s[a];
	}
	int get_tree(int size){
		int cnt=1;
		vector<int> vec;
		rep(i,size){
			if(vec.size()==0)vec.push_back(Find(i+1));
			else{
				rep(j,vec.size()){
					if(vec[j]==Find(i+1))goto ioi;
				}
				vec.push_back(Find(i+1));
				cnt++;
				ioi:;
			}
		}
		return cnt;
	}
};
signed main() {
	int n,ans[100000];
	vector<P> vec[100012];
	cin>>n;
	fill(ans,ans+n,2);
	rep(i,n-1){
		int u,v,w;
		cin>>u>>v>>w;
		vec[u].push_back({v,w});
		vec[v].push_back({u,w});
	}
	queue<int> que;
	ans[0]=0;
	que.push(0);
	while(!que.empty()){
		int a=que.front();que.pop();
		rep(i,vec[a+1].size()){
			if(ans[vec[a+1][i].first-1]!=2)continue;
			if(vec[a+1][i].second%2==0&&ans[a]==0)ans[vec[a+1][i].first-1]=0;
			if(vec[a+1][i].second%2==0&&ans[a]==1)ans[vec[a+1][i].first-1]=1;
			if(vec[a+1][i].second%2==1&&ans[a]==0)ans[vec[a+1][i].first-1]=1;
			if(vec[a+1][i].second%2==1&&ans[a]==1)ans[vec[a+1][i].first-1]=0;
			que.push(vec[a+1][i].first-1);
		}
	}
	rep(i,n)cout<<ans[i]<<endl;
}


Measured memory_bytes: 8704
#include <iostream>
#include <string>
#include <boost/math/common_factor_rt.hpp>

using namespace std;
using Integer = long long;

int main () {
  Integer N, M;
  string S, T;

  cin >> N >> M >> S >> T;

  Integer l = boost::math::lcm(N, M);
  Integer g = boost::math::gcd(N, M);
  Integer N_ = N / g;
  Integer M_ = M / g;

  for (Integer d = 0; d < g; d++) {
    if (S.at(N_ * d) != T.at(M_ * d)) {
      cout << -1 << "\n";
      return 0;
    }
  }

  cout << l << "\n";
}


Measured memory_bytes: 512
from collections import deque

K = int(input())

while (K % 2 == 0):
    K = K // 2
while (K % 5 == 0):
    K = K // 5

if(K == 1):print("1")
else : 
    visited = [-1 for i in range(K)]
    queue = deque([])
    st = 1

    while True:
        visited[st] = 1
        queue.append(st)
        st = (10*st) % K
        if (st == 1) : break

    while queue:
        a = queue.popleft()
        if (visited[0] != -1) :break
        if (visited[(a+1) % K] == -1):
            st = (a+1) % K
            while True:
                visited[st] = visited[a] + 1
                queue.append(st)
                st = (10*st) % K
                if (st == ((a+1) % K)) : break
            if (visited[0] != -1) :break


    print(visited[0])

Measured memory_bytes: 8052