akhauriyash/Code-Regression huggingface dataset:
class BITree:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)
 
    def total(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s
 
    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i
N=int(input())
A=[int(input())*(10**5)-i for i in range(N)]
#追加削除
#二分検索
B=[0]+sorted(list(set([i for i in A])))
M=len(B)
D=dict()
for i in range(M):
    D[B[i]]=i
#print(B)
S=BITree(M)
def search(X):
    Y=D[X]
    tmp=S.total(Y)
    if tmp!=S.total(Y-1):
        return Y
    left=0
    right=Y-1
    mid=(left+right)//2
    while(left<=right):
        mid=(left+right)//2
        if S.total(mid)<tmp:
            left=mid+1
        else:
            right=mid-1
    return left
for i in range(N):
    #print([S.total(i+1)-S.total(i) for i in range(M)])
    #print([S.total(i) for i in range(M+1)])
    tmp2=search(A[i])
    if tmp2==0:
        S.add(D[A[i]],1)
    else:
        S.add(D[A[i]],1)
        S.add(tmp2,-1)
print(S.total(M))

Measured memory_bytes: 66896
#include<cstdio>
#define BIG 10001
int n,ans;
int now,last;
int main() {
	scanf("%d",&n);
	for(int i=1;i<=n;i++) {
		last=now;
		scanf("%d",&now);
		if(now==last)
			ans++,now=BIG;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 128
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner scan =new Scanner(System.in);
        int a = scan.nextInt();
        int b = scan.nextInt();
        if((a*b) % 2 == 0){
            System.out.println("Even");
        }
        else{
            System.out.println("Odd");
        }
    }
}


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

using namespace std;

int main()
{
  		  int a,b,c;

          cin>>a>>b>>c;

          int ans;

          ans = b+c-a;

          if(ans <=0)
          {
              cout<<0<<endl;
          }
          else
          {
              cout<<ans<<endl;
          }
}

Measured memory_bytes: 256
/*
Though leaves are many , the root is one.
Through all the lying days of my youth
I swayed my leaves and flowers in the sun.
Now I may wither into the truth.
	  	  	- William Butler Yeats
*/
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
//#pragma GCC target("avx,tune=native")
#include<bits/stdc++.h>
//#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
const int inf=0x3f3f3f3f;
const double eps=1e-6;
const int mod=1000000007;
typedef long long ll;
#ifndef LOCAL
#define cerr if(0)cout
#endif
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
inline string getstr(string &s,int l,int r){string ret="";for(int i=l;i<=r;i++)ret.push_back(s[i]);return ret;}
int modpow(int x,int y,int md=mod){if(y==0)return 1;int ret=modpow(x,y>>1,md);ret=(ll)ret*ret%md;if(y&1)ret=(ll)ret*x%md;return ret;}
int n,m;
vector<int>to[606];
double dp[606];
double solve(pair<int,int>ban){
	for(int i=1;i<=n;i++)dp[i]=0.0;
	for(int i=n-1;i>=1;i--){
		vector<pair<int,int> >dat;
		double sum=0.0;int cnt=0;
		for(int j=0;j<to[i].size();j++){
			if(make_pair(i,to[i][j])==ban)continue;
			sum+=dp[to[i][j]];cnt++;
		}
		if(cnt==0){
			dp[i]=1e9;continue;
		}
		sum/=(double)cnt;
		dp[i]=sum+1.0;
		
	}
	return dp[1];
}
int main(){
	cin>>n>>m;
	for(int i=1;i<=m;i++){
		int s,t;cin>>s>>t;
		to[s].push_back(t);
	}
	for(int i=1;i<=n;i++)dp[i]=0.0;
	vector<pair<int,int> >can_erase;
	for(int i=n-1;i>=1;i--){
		vector<pair<int,int> >dat;
		double sum=0.0;
		pair<double,int>Max(-1e9,-1);
		for(int j=0;j<to[i].size();j++){
			sum+=dp[to[i][j]];Max=max(Max,make_pair(dp[to[i][j]],to[i][j]));
		}
		sum/=(double)to[i].size();
		if(to[i].size()>1){
			can_erase.push_back(make_pair(i,Max.second));
		}
		dp[i]=sum+1.0; 
	}
	double ans=dp[1];
	for(auto p:can_erase){
		ans=min(ans,solve(p));
	}
	printf("%.12lf\n",ans);
	return 0;
}

Measured memory_bytes: 1408
//https://atcoder.jp/contests/abc150/tasks/abc150_a
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll k;
	cin>>k;
	ll x;
	cin>>x;
	if((k*500)>=x)
	{
		cout<<"Yes"<<"\n";
	}
	else
	{
		cout<<"No"<<"\n";
	}
	return 0;
}


Measured memory_bytes: 3608
/*
How to lambda
  ex) sort(ALL(cont),[](dat a,dat b){return a.l<b.l;});
lower_bound/upper_bound
  1 2 2 2 3 3 
    ^lb   ^ub */
#include <bits/stdc++.h>
#define BR "\n"
#define REP(i,n) for(int (i)=0;(i)<(n);++(i))
#define ALL(cont) begin(cont),end(cont)
#define AS_MOD(a,b) ((((a) % (b) ) + (b)) % (b))
#define FEACH(it,cont) for(auto (it) = begin(cont); it!=end(cont);++it)
#define FEACHR(it,cont) for(auto (it) = rbegin(cont); it!=rend(cont);++it)
#define pb push_back
#define pob pop_back
#define fi first
#define se second
#define getll() ([](){ll s;scanf("%lld", &s);return s;})()
#define getld() ([](){ld s;scanf("%Lf", &s);return s;})()
#define prl(P) printf("%lld", P)
#define prd(P) printf("%.10Lf", P)
#define pr(P) printf(P)
#define assign_if_greater(V, T) V=max(V,T)
using namespace std;
typedef long long ll;
typedef long double ld;
int A,B,Q;
ll As[100000];
ll Bs[100000];
ll INF=(ll)1000*1000*1000*1000;
int main() {

  scanf("%d%d%d", &A, &B, &Q);
  REP(i,A)
    As[i]=getll();
  REP(i,B)
    Bs[i]=getll();
  REP(i,Q) {
    ll x=getll();
    ll* ita=lower_bound(As, As+A, x);
    ll* itb=lower_bound(Bs, Bs+B, x);
    ll ans=INF;
    vector<ll> alis,blis;
    if (ita!=As+A) {
      alis.pb(*ita);
    }
    if (itb!=Bs+B) {
      blis.pb(*itb);
    }
    if (ita!=As) {
      ita--;
      alis.pb(*ita);
    }
    if (itb!=Bs) {
      itb--;
      blis.pb(*itb);
    }
    for(ll a:alis)
      for(ll b:blis) {
        ans = min(ans,abs(a-x)+abs(b-a));
        ans = min(ans,abs(b-x)+abs(b-a));
      }
    printf("%lld\n",ans);
  }


  return 0;
}


Measured memory_bytes: 2816
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Diagnostics;

class Myon
{
    public Myon() { }
    public static int Main()
    {
        new Myon().calc();
        return 0;
    }

    Scanner cin;
    Func cin2;
    void calc()
    {
        cin = new Scanner();
        cin2 = new Func();
        int[] a=cin.ArrayInt(2,0);
        int ans=0;
      for(int i=1;i<=a[0];i++)
      {
        for(int j=10;j<=a[1];j++)
        {
          int d1=j/10;
          int d2=j%10;
          
          if(i==d1*d2&&d1>=2&&d2>=2){ans++;}
        }
      }
      Console.WriteLine(ans);
        
    }
}



class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}

class Answer
{
    public void Int2DArrayAns(int[,]x,char c)
    {
        for(int i=0;i<x.GetLength(0);i++)
        {
            for(int j=0;j<x.GetLength(1)-1;j++)
            {
                Console.Write(x[i,j]);
                Console.Write(c);
            }
            Console.WriteLine(x[i,x.GetLength(1)-1]);
        }
    }
    public void Char2DArrayAns(char[,]x,char c)
    {
        for(int i=0;i<x.GetLength(0);i++)
        {
            for(int j=0;j<x.GetLength(1)-1;j++)
            {
                Console.Write(x[i,j]);
                Console.Write(c);
            }
            Console.WriteLine(x[i,x.GetLength(1)-1]);
        }
    }
}

class Func
{
    public long GCDLong(long a, long b)
    {
        while(a!=0)
        {
          long t=a;
          a=b%a;
          b= t;
        }
      
        return b;        
    }
}

Measured memory_bytes: 11220
S=[]
for char in input():
  S.append(char)
#route 1
C1=0
for i in range(len(S)):
  if i%2==0:
    if S[i]=='1':
      C1+=1
  else:
    if S[i]=='0':
      C1+=1

#route 2
C2=0
for n in range(len(S)):
  if n%2==0:
    if S[n]=='0':
      C2+=1
  else:
    if S[n]=='1':
      C2+=1

if C2>=C1:
  print(C1)
else:
  print(C2)

Measured memory_bytes: 3956
#include<iostream>
using namespace std;
int main(){
  int n[101];
  int i;
  int num;
  cin >> num;
  for(i=0;i<num;i++) cin >> n[i];
  cout << n[num-1];
  for(i=1;i<num;i++) cout <<" "<< n[num-i-1];
  cout << endl;
  return 0;
}



Measured memory_bytes: 3108
#include<bits/stdc++.h>
#define inf 200000000
using namespace std;
int r,c,n,top;
int check(int x,int y)
{
	if (y==0) return inf+x;
	if (x==r) return 2*inf+y;
	if (y==c) return 3*inf-x;
	if (x==0) return 4*inf-y;
	return 0;
}
pair<int,int> st[200010];
map<int,int>mp;
unsigned long long num[200010];
int go[200010];
int main()
{
	scanf("%d%d%d",&r,&c,&n);
	for (int i=1;i<=n;i++)
	{
		int x1,y1,x2,y2;scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
		int p1=check(x1,y1),p2=check(x2,y2);
		if ((!p1)||(!p2)) continue;
		st[++top]=make_pair(p1,p2);
		mp[p1]=0;mp[p2]=0;
	}
	int tp=0;for (map<int,int>::iterator it=mp.begin();it!=mp.end();it++) it->second=++tp;
		
	for (int i=1;i<=top;i++)
	{
		int l=mp[st[i].first],r=mp[st[i].second];
		if (l>r) swap(l,r);
		num[l]=num[r]=(unsigned long long)rand()*rand()*rand()*rand()+(unsigned long long)rand()*rand()+rand();
		go[r]=l;
	}
	for (int i=1;i<=tp;i++)
	{
		num[i]^=num[i-1];
		if ((go[i])&&(num[i]^num[go[i]-1])) {puts("NO");return 0;}
	}
	puts("YES");
}
		
		
		
		
		
		
		
		
		
		
		
		
		

Measured memory_bytes: 12800
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
using lint = long long;

int main()
{
    string S;
    cin >> S;
    int count = 0;
    int C = 0;
    for (auto c : S) {
        if (c - 'a' < 0 || c - 'a' > 25)
            count++;
        if (c == 'C') C++;
    }
    if (count == 2 && S[0] == 'A' && C == 1 && S[S.length()-1] != 'C' && S[1] != 'C') cout << "AC" << endl;
    else cout << "WA" << endl;
}


Measured memory_bytes: 256
// Problem : C - Repsept
// Contest : AtCoder - AtCoder Beginner Contest 174
// URL : https://atcoder.jp/contests/abc174/tasks/abc174_c
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

//#pragma GCC optimize "trapv"//  WA to RE int!!
#include <bits/stdc++.h>
#define FOR(i,n) for(int i=0;i<n;i++)
#define FORR(i,n) for(int i=n;i>=0;i--)
#define pb push_back
#define vlli vector<int>
#define slli set<int>
#define mlli map<int,int>
#define plii pair< int,int >
#define int long long int 
#define test int tt1234; cin>>tt1234;while(tt1234--)
#define endl "\n"
#define SI(a,n) int a[n];FOR(i,n) cin>>a[i];
#define input(a,n) int n;cin>>n; SI(a,n)
#define all(zz) zz.begin(),zz.end()
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define error(x) cerr << #x <<" is " << x << endl;
#define Error(a,b) cerr<<"( "<<#a<<" , "<<#b<<" ) = ( "<<(a)<<" , "<<(b)<<" )\n";
#define precision(x) cout<<fixed<<setprecision(x);
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define present(container, element) (container.find(element)!=container.end())
#define fint fast;test
#define set(a,x) memset(a,x,sizeof(a))
#define L(x)	((x)<<1)
#define R(x)	(((x)<<1)+1)
#define ft first
#define se second
#define MOD 1000000007
using namespace std;
template<typename... T> void rd(T&... args) { ((cin >> args), ...); }
template<typename... T> void pp(T... args) { ((cout << args << " "), ...); cout<<"\n"; }
int digit(int num)
{
	int count=0;
	while(num){
		count++;
		num/=10;
	}
	return count;
}
void solve(){
	int n;
	rd(n);
	vector<bool>rem(n+1,false);
	queue<pair<int,int>>q;
	q.push({7%n,1})	;
	rem[7%n]=1;
	while(q.size()){
		int num=q.front().ft;
		int R=q.front().se;
		q.pop();
		if(num==0){
			pp(R);
			return ;
		}
		int new_num=(((num%n)*(10%n))%n+(7%n))%n;
		if(rem[new_num])continue;
		else q.push({new_num,R+1}),rem[new_num]=1; 				
	}
	pp(-1);
	return;	
}


int32_t main() {
    // fint{
    	fast;
    	solve();
    // }
    return 0;
}


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

int main(){
    string a;
    cin >> a;
    int count =0;
    if (a[0]=='1'){
        count++;
    }
    if (a[1]=='1'){
        count++;
    }
    if (a[2]=='1'){
        count++;
    }
    
    cout << count << endl;
    
}

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

int main() {
  int N, M = 0;
  cin >> N;
  string S;
  map<string, int> MA;
  while (cin >> S) M = max(M, ++MA[S]);
  for (auto ma : MA) if (ma.second == M) cout << ma.first << "\n";  
}

Measured memory_bytes: 25216
#include <stdio.h>
#include <iostream>
#include <vector>
#include<algorithm>
using namespace std;

int main()
{
	int K, S;
	cin >> K >> S;

	int x, y, z;
	int64_t t = 0;

	for (x = 0; x <= K; x++)
		{
			for (y = 0; y <= K && y <= S - x; y++)
			{
				{int z = S - x - y;
				if (0 <= z && z <= K)
					t++;
				}
				if (x + y >= S)
					break;
				z = 0;
			}
			if (x >= S)
				break;
			y = 0;
		}

		cout << t << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const string ln = "\n";
constexpr int INF = 1001001001;
constexpr int MOD = 1000000007;

vector<ll> d(1000000);
void prep() {
  for (int x = 1; x <= 200; x++) {
    for (int y = 1; y <= 200; y++) {
      for (int z = 1; z <= 200; z++) {
        ll v = x * x + y * y + z * z + x * y + y * z + z * x;
        if (v > 1000000) continue;
        d[v]++;
      }
    }
  }
}

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

  ll n;
  cin >> n;

  prep();

  for (int i = 1; i <= n; i++) {
    cout << d[i] << ln;
  }

  return 0;
}

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

const int maxN=1e5+2;

int n;
int v[maxN];

int dp[maxN];

int main(){
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>v[i];
    }

    dp[1]=0;
    dp[2]=abs(v[2]-v[1]);
    for(int i=3;i<=n;i++){
        int val=dp[i-1]+abs(v[i]-v[i-1]);
        val=min(val,dp[i-2]+abs(v[i]-v[i-2]));
        dp[i]=val;
    }

    cout<<dp[n];

    return 0;
}

Measured memory_bytes: 1024
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String[] s = new String[n];
        long m = 0;
        long a = 0;
        long r = 0;
        long c = 0;
        long h = 0;
        for (int i = 0; i < n; i++) {
            s[i] = sc.next();
        }
        for (int i = 0; i < n; i++) {
            if (s[i].charAt(0) == 'M')
                m++;
            if (s[i].charAt(0) == 'A')
                a++;
            if (s[i].charAt(0) == 'R')
                r++;
            if (s[i].charAt(0) == 'C')
                c++;
            if (s[i].charAt(0) == 'H')
                h++;
        }
        System.out.println(m * a * r + m * a * c + m * a * h + m * r * c + m * r * h + m * c * h + a * r * c + a * r * h
                + a * c * h + r * c * h);
    }
}


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

//Function Macros:
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define all(v) (v).begin(), (v).end()
#define setpre(n) cout << fixed << setprecision(n)

//Type Definitions:
typedef long long ll;
typedef unsigned long long ull;

//Constants:
const int INF = 2e9;
const int MOD = 1e9 + 7;

//Global Variables:

//Prototype Declarations:
int gcd(int, int);

//================ Main Loop ================
int main() {
    vector<int> a(9);
    rep(i, 9) {
        cin >> a[i];
    }
    int n;
    cin >> n;
    int b;
    vector<bool> flg(9, false);
    rep(i, n) {
        cin >> b;
        rep(j, 9) {
            if(a[j] == b) flg[j] = 1;
        }
    }

    if((flg[0] && flg[1] && flg[2]) || (flg[3] && flg[4] && flg[5]) || (flg[6] && flg[7] && flg[8]) || (flg[0] && flg[3] && flg[6]) || (flg[1] && flg[4] && flg[7]) || (flg[2] && flg[5] && flg[8]) || (flg[0] && flg[4] && flg[8]) || (flg[2] && flg[4] && flg[6])) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}
//===========================================

//Functions:
int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define INF 9223372036854775807LL
#define mod 1000000007
#define SYOU(x) setprecision(x+1)
#define abs(x,y) (max(x,y)-min(x,y))
#define lol long long
#define mp make_pair
#define fi first
#define se second
using namespace std;
lol mem[100010];
signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,m;
    cin >>n>>m;
    bool no=false;
    int s[10],c[10];
    for(int i=0;i<m;i++){
	cin >>s[i]>>c[i];
	if(s[i]==1&&c[i]==0) no=true;
    }
    if(no){
	if(n!=1){
	cout <<"-1\n";
	return (0);
	}
    }
    int ans[10]={};
    bool ka[10]={};
    bool a=false;
    for(int i=0;i<m;i++){
	if(ka[s[i]]){
	    if(ans[s[i]]!=c[i]) a=true;
	}
	ans[s[i]]=c[i];
	ka[s[i]]=true;
    }
    if(a) cout <<"-1";
    else{
	if((ka[1]==false)&&ans[1]==0&&n!=1) ans[1]=1;
	for(int i=1;i<=n;i++) cout <<ans[i];
    }
    cout <<'\n';
    return (0);
}


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

using i64 = long long int;

const i64 MOD = 1000000007;

i64 repeated_squaring(i64 x, i64 n) {
    i64 res = 1;
    while (n > 0) {
        if (n & 1)
            res = res * x % MOD;
        x = x * x % MOD;
        n >>= 1;
    }
    return res;
}

int main(){
    i64 m, n;
    cin >> m >> n;
    cout << repeated_squaring(m, n) << endl;

    return 0;
}



Measured memory_bytes: 3092
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<unordered_map>
#include<random>
#include<array>
#include<cassert>
#include <atcoder/fenwicktree>
using namespace std;
#define INF ((1<<30)-1)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()




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

	int n, q;
	cin >> n >> q;
	atcoder::fenwick_tree<int64_t> fenwick(n);
	rep(i, n) {
		int a;
		cin >> a;
		fenwick.add(i, a);
	}

	rep(i, q) {
		int t;
		cin >> t;
		if (t == 0) {
			int p, x;
			cin >> p >> x;
			fenwick.add(p, x);
		}
		else {
			int l, r;
			cin >> l >> r;
			cout << fenwick.sum(l, r) << endl;
		}
	}


	return 0;
}


Measured memory_bytes: 8244
#pragma GCC optimize("O3")
#pragma GCC target("avx")
#include <iostream>
#include <vector>
using namespace std;
#define int long long
#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define FORR(i, a, b) for (int i = (b - 1); i >= (a); i--)
#define ALL(a) begin(a), end(a)
#define let const auto
int scan() {
  int result = 0;
  while (true) {
    auto k = getchar_unlocked();
    if (k < '0' || k > '9') return result;
    result = 10 * result + k - '0';
  }
}

signed main() {
  let n = scan();
  let m = scan();
  //電球mがつながっているswitch番号(0から)
  auto S = vector<vector<int>>(m);
  REP(i, m) {
    let k = scan();
    S[i] = vector<int>(k);
    REP(j, k) S[i][j] = scan() - 1;
  }
  auto P = vector<int>(m);
  REP(i, m) P[i] = scan();
  //全探索すればいい
  auto ans = 0;
  REP(i0, 2) {
    REP(i1, 2) {
      REP(i2, 2) {
        REP(i3, 2) {
          REP(i4, 2) {
            REP(i5, 2) {
              REP(i6, 2) {
                REP(i7, 2) {
                  REP(i8, 2) {
                    REP(i9, 2) {
                      auto ok = true;
                      vector<int> F = {i0, i1, i2, i3, i4, i5, i6, i7, i8, i9};
                      REP(mi, m) {
                        auto num = 0;
                        for (auto s : S[mi]) {
                          if (F[s]) num += 1;
                        }
                        if (P[mi] != num % 2) {
                          ok = false;
                          break;
                        }
                      }
                      if (ok) ans += 1;
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
  ans = ans >> (10 - n);
  cout << ans << endl;
}


Measured memory_bytes: 256
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

MAX = 100010
ps = [True] * MAX
ps[0] = ps[1] = False

def prime():
    for i in range(2, MAX):
        if ps[i]:
            j = 2 * i
            while j < MAX:
                ps[j] = False
                j += i

cs = [0] * MAX
def cnt():
    for i in range(1, MAX):
        if i % 2 == 1 and ps[i] and ps[(i + 1) // 2]:
            cs[i] = cs[i - 1] + 1
        else:
            cs[i] = cs[i - 1]

prime()
cnt()

Q = int(input())

for i in range(Q):
    l, r = map(int, input().split())
    print(cs[r] - cs[l - 1])

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

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

    int H, W;
    cin >> H >> W;

    map<int, int> candidates;
    map<int, int> moves;

    rep(i, W) {
        candidates[i] = i;
    }
    moves[0] = W;

    rep(i, H) {
        int A, B;
        cin >> A >> B;
        A--;

        int r = -1;
        while (true) {
            auto it = candidates.lower_bound(A);
            if (it == candidates.end() || it->first > B) break;

            r = max(r, it->second);
            int t = it->first - it->second;
            moves[t]--;
            if (moves[t] == 0) {
                moves.erase(t);
            }
            candidates.erase(it);
        }
        if (r != -1 && B != W) {
            moves[B - r]++;
            candidates[B] = r;
        }

        if (moves.size() == 0) {
            cout << -1 << "\n";
        } else {
            cout << moves.begin()->first + (i + 1) << "\n";
        }
    }
    cout << flush;

    return 0;
}


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

#define int long long
#define fast_io(); ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define loop(i,a,b) for(int i=a;i<b;i++)
#define all(x) x.begin(),x.end()
#define us unordered_set
#define um unordered_map
#define ms multiset
#define mm multimap
#define pb push_back
#define pf push_front
#define ins insert
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define _max max_element
#define _min min_element
#define tc(T) int T; cin>>T; while(T--)
#define q(q) int q; cin>>q; while(q--)
#define pi 3.1415926535897932384626433832
const int pinf=((int)2e18);
const int ninf=((int)-2e18);
const int mod=1000000007;

using namespace std;

int power(int x,int n,int M)
{
    if(n==0)
        return 1;
    else if(n%2 == 0)
        return power((x*x)%M,n/2,M);
    else
        return (x*power((x*x)%M,(n-1)/2,M))%M;
}

bool vowel(char c)
{
    return(c=='a' or c=='e' or c=='i' or c=='o' or c=='u' or c=='A' or c=='E' or c=='I' or c=='U' or c=='O');
}

int32_t main()
{
    fast_io();

    //FILE *fptr1=freopen("in.txt","r",stdin);
    //FILE *fptr2=freopen("out.txt","w",stdout);

    /*   g++ -o d A.cpp  
         ./d
    */

    int a,b;
    cin>>a>>b;
    if(a>9 or b>9)
    {
        cout<< "-1";
        return 0;
    }

    cout<<a*b;

    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#include <iostream>
#include <string>

#include <boost/algorithm/searching/knuth_morris_pratt.hpp>

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep2(i, s, e) for (int i = (s); i < (int)(e); ++i)
using namespace std;
using ll = long long;

vector<int> kmp_search(const string &s, const string &t, const vector<int> &kmp) {
  // ret[i] == true なら s[i:] starts with t
  vector<int> ret(s.size(), false);

  int m = 0;
  int i = 0;
  while (m + i < s.size()) {
    if (t[i] == s[m + i]) {
      i++;
      if (i == t.size()) {
        ret[m] = true;
        m += i - kmp[i - 1] - 1;
        if (i >= 0) {
          i = max(0, kmp[i - 1]);
        }
      }
    } else {
      m += i - kmp[i];
      if (i > 0) {
        i = kmp[i];
      }
    }
  }
//  cout << s << endl;
//  for (const auto &r : ret) {
//    cout << r;
//  }
//  cout << endl;
//  for (const auto &k : kmp) {
//    cout << k << " ";
//  }
//  cout << endl;
  return ret;
}

int solve(const string &s, const string &t, int ls, int lt) {
  // https://ja.wikipedia.org/wiki/クヌース–モリス–プラット法
  vector<int> kmp(lt + 2, 0);
  kmp[0] = -1;
  kmp[1] = 0;
  {
    int i = 2;
    int j = 0;
    while (i < lt) {
      if (t[i - 1] == t[j]) {
        kmp[i] = j + 1;
        i++;
        j++;
      } else if (j > 0) {
        j = kmp[j];
      } else {
        kmp[i] = 0;
        i++;
      }
    }
  }

  int ret = 0;
  vector<int> matches = kmp_search(s, t, kmp);
  vector<bool> seen(ls, false);

  int i = -1;
  while (++i < ls) {
    while (i < matches.size() && !matches[i]) i++;
    if (i > ls) break;
    if (seen[i]) continue;

    int j = 0;
    while (matches[i + j * lt]) {
      if (i + j * lt < ls) seen[i + j * lt] = true;
      if (j * lt >= ls) return -1;
      j += 1;
    }
    ret = max(ret, j);
  }
  return ret;
}

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

  int ls, lt;
  ls = s.size();
  lt = t.size();

  do {
    s += s;
  } while (s.size() < t.size() * 3);
  int ret = solve(s, t, ls, lt);
  cout << ret << endl;
}


Measured memory_bytes: 14900
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define rrep(i, a, b) for (int i = (a); i < (b); ++i)
#define PI acos(-1)
#define pcnt __builtin_popcountll
#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define sz(x) (int)(x).size()
#define v(T) vector<T>
#define vv(T) v(v(T))
#define fi first
#define se second

using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using LP = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using tl = tuple<ll, ll, ll>;

template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) {if (a > b) { a = b; return true; } return false; }

ll INF = 1001001001;
ll LINF = 1001001001001001001ll;

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

    ll n, k; cin>>n>>k;
    vl as(n); cin>>as;
    sort(rng(as));
    ll ans = 0;
    rep(i, k) ans += as[i];
    cout<<ans<<endl;
}

Measured memory_bytes: 3664
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007 

int main() {
	string s;
	cin>>s;
	ll ans=15-s.size();
	for(ll i=0;i<s.size();i++){
		if(s[i]=='o'){
			ans++;
		}
	}
	cout << (ans>=8?"YES":"NO");

	// your code goes here
	return 0;
}

Measured memory_bytes: 384
N = int(input())
L = []
for i in range(N):
  Data = list(map(int, input().split()))
  L.append([Data[0] + Data[1], Data[0], Data[1]])

L.sort(reverse = True)

Taka = 0
Aoki = 0

for i in range(N):
  if i % 2 == 0:
    Taka += L[i][1]
  else:
    Aoki += L[i][2]

print(Taka - Aoki)

Measured memory_bytes: 61784
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn read_vec2<T: std::str::FromStr>(n: usize) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

fn read_col<T: std::str::FromStr>(n: usize) -> Vec<T> {
    (0..n).map(|_| read()).collect()
}

fn main() {
    let s: String = read();
    let cv: Vec<char> = s.chars().rev().collect();
    let mut dp: Vec<Vec<u64>> = vec![vec![0; 13]; 100001];
    let l: usize = s.len();
    let rs: Vec<u64> = vec![1, 10, 9, 12, 3, 4];

    dp[0][0] = 1;
    for i in 0..l {
        let c = cv[i];
        let r = rs[i % 6];

        if c == '?' {
            for n in 0..10 {
                let dif = ((n * r) % 13) as usize;
                for j in 0..13 {
                    dp[i + 1][(j + dif) % 13] += dp[i][j];
                }
            }
        } else {
            let n = (c as u64) - 48;
            let dif = ((n * r) % 13) as usize;
            for j in 0..13 {
                dp[i + 1][(j + dif) % 13] += dp[i][j];
            }
        }
        for j in 0..13 {
            dp[i + 1][j] %= 1000000007;
        }
    }
    println!("{}", dp[l][5]);
}


Measured memory_bytes: 18812
s=input()
flg=0
while len(s)>0:
  f1=s[-5:]
  f2=s[-6:]
  f3=s[-7:]
  if f3 == 'dreamer':
    s=s[:-7]
  elif f2 =='eraser':
    s=s[:-6]
  elif f1 =='dream' or f1 =='erase':
    s=s[:-5]
  else:
    print('NO')
    flg=1
    break
if flg==0:
  print('YES')

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

inline long long read(){
	long long s = 0, w = 1;
	char ch = getchar();
	while (ch < '0' || ch > '9'){
		if (ch == '-') w = -1;
		ch = getchar();
	}
	while (ch >= '0' && ch <= '9'){
		s = s * 10 + ch - '0';
		ch = getchar();
	}
	return s * w;
}
long long n, k, ans;
int main(){
	n = read(), k = read();
	while (n != 0){
		ans++;
		n = n / k;
	}
	cout << ans;
	return 0;
}


Measured memory_bytes: 256
require 'pp'

h1, m1, h2, m2, k = gets.split.map(&:to_i)

if (m2 - m1) < 0
    m = m2 - m1 + 60
    h2 -= 1
    h = h2 - h1
else
    m = m2 - m1
    h = h2 - h1
end

puts h * 60 + m - k


Measured memory_bytes: 14576
import sys 
from collections import Counter
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N = int(readline())
A = list(map(int,readline().split()))
X = [0]*N
Y = [0]*N
for i in range(N):
    X[i] = (i+1) + A[i]
    Y[i] = (i+1) - A[i]  
cnt = Counter(Y)
ans = 0
for i in range(N):
    ans += cnt[X[i]] 
    cnt[Y[i]] -= 1
print(ans)

Measured memory_bytes: 50644
from sys import stdin, stdout

int_in = lambda: int(stdin.readline())
arr_in = lambda: [int(x) for x in stdin.readline().split()]
mat_in = lambda rows: [arr_in() for y in range(rows)]
str_in = lambda: stdin.readline().strip()
out = lambda o: stdout.write("{}\n".format(o))
arr_out = lambda o: out(" ".join(map(str, o)))
bool_out = lambda o: out("YES" if o else "NO")
tests = lambda: range(1, int_in() + 1)
case_out = lambda i, o: out("Case #{}: {}".format(i, o))


def solve(h1, m1, h2, m2, k):
    sleep_at = h2 * 60 + m2
    wake_at = h1 * 60 + m1
    return sleep_at - wake_at - k


if __name__ == "__main__":
    h1, m1, h2, m2, k = arr_in()
    out(solve(h1, m1, h2, m2, k))

Measured memory_bytes: 79664
n, m = map(int, input().split())
A = list(map(int, input().split()))

A = [a * (-1) for a in A]
import heapq
heapq.heapify(A)

for _ in range(m):
    a = heapq.heappop(A) * (-1)
    heapq.heappush(A, a // 2 * (-1))

print(abs(sum(A)))


Measured memory_bytes: 14224
#include <bits/stdc++.h>
#include<string.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define fr(i,s,e) for(i=s;i<e;i++)
#define rf(i,s,e) for(i=s-1;i>=e;i--)
#define pb push_back
#define eb emblace_back
#define mp make_pair
#define ff first
#define ss second
#define int   long long
#define ll   long long
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define vl vector<long long>
#define inf (1LL<<61)
#define vi vector<int> 
#define vii vector< vector<int> >
#define vll vector< vector<long long> >
#define vpi vector< pair<int,int> >   
#define vpl vector< pair<ll,ll> >   
#define viii vector< vector<vector<int> > >
typedef pair<pair<int, int>,int> P;
#define cd complex<double>
#define PI 4*atan(1)
#define mod 1000000007
#define pi 3.14159265358979323846//20 decimals
#define ld long double
#define double long double
int gcd(int a,int b)
{
    if(b==0)return a;
    return gcd(b,a%b);
}
int32_t main()
{
    IOS;
       int n;
    cin>>n;
    vi v(n);
    map<int,int> mo,me;
    for(int i=0;i<n;i++)
    {
    	cin>>v[i];
    	if(i%2==0)
    		me[v[i]]++;
    	else
    		mo[v[i]]++;
    }
    pair<int,int> a1[2],a2[2];
   	a1[0].ff=a2[0].ff=a1[1].ff=a2[1].ff=0;
   	a1[0].ss=a2[0].ss=a1[1].ss=a2[1].ss=0;
    for(auto it:mo)
    {
    	if(a1[0].ff<it.ss)
    	{
    		a1[1]=a1[0];
    		a1[0].ff=it.ss;
    		a1[0].ss=it.ff;
    	}
    	else
    	{
    		if(a1[1].ff<it.ss)
    		{
    			a1[1].ff=it.ss;
    			a1[1].ss=it.ff;
    		}
    	}
    }
    for(auto it:me)
    {
    	if(a2[0].ff<it.ss)
    	{
    		a2[1]=a2[0];
    		a2[0].ff=it.ss;
    		a2[0].ss=it.ff;
    	}
    	else
    	{
    		if(a2[1].ff<it.ss)
    		{
    			a2[1].ff=it.ss;
    			a2[1].ss=it.ff;
    		}
    	}
    }
    int ans=n;
    for(int i=0;i<2;i++)
    {
    	for(int j=0;j<2;j++)
    	{
    		if(a1[i].ss!=a2[j].ss)
    		{
    			//trace4(a1[i].ff,a1[i].ss,a2[j].ff,a2[j].ss);
    			ans=min(ans,n-a1[i].ff-a2[j].ff);
    		}
    	}
    }
    cout<<ans;
    return 0;

}

Measured memory_bytes: 7296
#include <iostream>
#include <list>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <algorithm>
#include <cmath>
#include <string>
using namespace std;
typedef long long lli;
typedef vector<lli> vll;
typedef vector<bool> vbl;
typedef vector<vector<lli> > mat;
typedef vector<vector<bool> > matb;
typedef vector<string> vst;
typedef pair<lli,lli> pll;
typedef pair<double,double> pdd;

lli n,t;
lli l,r;
vll a;

int main(){
    cin >> n >> t;
    a = vll(t+1);
    for(lli i = 0;i < n;i++){
        cin >> l >> r;
        a[l]++;
        a[r]--;
    }
    for(lli i = 0;i < t;i++) a[i+1] += a[i];
    cout << *max_element(a.begin(),a.end()) << endl;
    return 0;
}

Measured memory_bytes: 3616
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define MAXN 100000000
int x,y,h,w,n;
long long ans[17],base=int(1e9)+7, zero, node[MAXN], tot;
int main() {
    scanf("%d%d%d", &h, &w, &n);
    zero=1ll*(h-2)*(w-2);
    while (n--) {
        scanf("%d%d", &x, &y);
        for(int i=0;i<3;i++) 
			for(int j=0;j<3;j++)
                if (1<=x-i&&x-i<=h-2&&1<=y-j&&y-j<=w-2)
                    node[tot++]=MAXN*(x-i)+(y-j);
    }
    sort(node, node+tot);
    for (int i = 0, cnt = 1; i<tot; i++) {
        if(node[i]==node[i+1]) 
			cnt++;
        else 
			ans[cnt]++, cnt=1, zero--;
    }
    printf("%lld\n",zero);
    for (int i=1;i<10;i++)
		printf("%lld\n", ans[i]);
    return 0;
}

Measured memory_bytes: 8448
#include <stdio.h>
int main(void)
{
    int i, j;
    char str[300000];
    char str2[300000];
    
    scanf("%s", str);
    scanf("%s", str2);
    
    i = 0;
    j = 0;
    while (str[i])
    {
        if (str[i] != str2[i])
        {
            str[i] = str2[i];
            j++;
        }
        i++;
    }
    printf("%d", j);
}

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

#define mod 1000000007
#define SIZE 10000000

vector<int>prime;

bool marked[SIZE];
int p[SIZE];
int e[SIZE];

bool isPrime(int n) {
  if (n < 2) return false;
  if (n == 2) return true;
  if (n % 2 == 0) return false;
  return marked[n] == false;
}

void sieve(int n) {
    int sqrtn = (int)sqrt(n);
  for (int i = 3; i <= sqrtn; i+=2) {
    if (marked[i] == false) {
      for (int j = i * i; j <= n; j += i + i) {
        marked[j] = true;
      }
    }
  }
}


int main(){

    int n;

    cin>>n;

    sieve(n);

    if(n>=2) prime.push_back(2);

    for(int i=3;i<=n;i=i+2){
        if(isPrime(i)) prime.push_back(i);
    }


    int p = prime.size();

    //cout<<p<<"\n";

    long long fac = 1;

    for(int i=0;i<p;i++){
        //cout<<prime[i]<<" : ";
        long long sum = 1;
        long long pow = 1;
        for(long long j=1;pow*prime[i]<=n;j++){
            pow = pow*prime[i];
            //cout<<"("<<pow<<") ";
            long long k = n/pow;
            sum = sum + k;
            //cout<<k<<" "<<sum;
        }


        fac = ((fac % mod) * (sum % mod))%mod ;

        //cout<<" "<<fac<<"\n";

    }

    cout<<fac<<"\n";


}


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



int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    int n; cin >> n;
    string s, t; cin >> s >> t;
    for (int i = 0; i < n; i++) {
        string r = s + t.substr(n-i);
        //cout << r << ' ' << r.substr(r.size()-n) << '\n';
        if (t == r.substr(r.size() - n)) {
            cout << n + i << '\n';
            return 0;
        }
    }
    cout << 2*n << '\n';

    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h> 
#define fo(i,a,b) for(i=a;i<=b;i++)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define min(a,b) (a<b?a:b)
#define max(a,b) (a>b?a:b)
typedef long long ll;
using namespace std;
const int maxn=1e6+5,mo=998244353;
int i,j,n,m,ji[maxn],re,ni[maxn],ans;
int calc(int n,int m){
	return (ll)ji[n]*ni[m]%mo*ni[n-m]%mo; 
}
int qs(int x,int y){
	int s=1;
	for(;y;y>>=1,x=(ll)x*x%mo) if (y&1) s=(ll)s*x%mo;
	return s;
}
int main(){
	scanf("%d%d",&n,&m);
	if (n<m) swap(n,m);
	ji[0]=ji[1]=ni[0]=1;
	fo(i,2,n+m) ji[i]=(ll)ji[i-1]*i%mo;
	ni[n+m]=qs(ji[n+m],mo-2);
	fd(i,n+m,2) ni[i-1]=(ll)ni[i]*i%mo;
	re=499122177;
	fo(i,1,m) (ans+=(ll)calc(n+m-(i<<1),m-i)*calc(i<<1,i)%mo)%=mo;
	ans=((ll)ans*re%mo*qs(calc(n+m,n),mo-2)%mo+n)%mo;
	printf("%d\n",ans);
}

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

int main()
{
    int n;
    int ar[100];
    cin>>n;
    int temp=n;
    int i=0;
    long long ans=0;
    while(n>0)
    {
       ar[i]=n%10;
       n=n/10;
       ans+=ar[i];
       i++;
    }
    if(temp%ans==0)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<int,int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const LL mod=1000000007;
const LL LINF=1LL<<60;
const int INF=1<<30;
int dx[]={1,0,1,-1,1,-1,-1,0};
int dy[]={0,1,1,-1,-1,1,0,-1};



int main(){
    int n,k;cin >> n >> k;
    vector<int> h(n);
    for (int i = 0; i < n; i++) {
        cin >> h[i];
    }
    sort(RALL(h));
    LL ans = 0;
    for (int i = k; i < n; i++) {
        ans += h[i];
    }
    cout << ans << endl;
    return 0;
}


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

int main() {
  int a,b;
  cin >> a >> b;
  if ((a+b)%2==0){
  	cout << (a+b)/2 <<endl;
  }
  else{
  	cout << ((a+b)/2)+1 << endl;
  }
  
  return 0;
}


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

#define EPS (1e-10)
#define rep(i, a, b) for (int i = a; i < (int)(b); ++i)
#define rrep(i, a, b) for (int i = b - 1; i >= (int)(a); --i)

using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vd = vector<double>;
using vvi = vector<vi>;

constexpr int MOD = 1000000007;

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

    int x, y, a, b, c;
    cin >> x >> y >> a >> b >> c;

    vi p(a), q(b), r(c);
    rep(i, 0, a) { cin >> p[i]; }
    rep(i, 0, b) { cin >> q[i]; }
    rep(i, 0, c) { cin >> r[i]; }

    // O(alog(a))
    sort(p.begin(), p.end());
    // O(blog(b))
    sort(q.begin(), q.end());

    priority_queue<int> queue;
    rep(i, a - x, a) { queue.push(-p[i]); }
    rep(i, b - y, b) { queue.push(-q[i]); }

    // O(c(log(a) + log(b)))
    rep(i, 0, c) {
        int x = -queue.top();
        if (r[i] > x) {
            queue.pop();
            queue.push(-r[i]);
        }
    }

    ll ans = 0;
    while (!queue.empty()) {
        ans -= queue.top();
        queue.pop();
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2552
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace test1
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split(' ');
            var a = int.Parse(input[0]);
            var b = int.Parse(input[1]);

            var menseki = a * b;
            var syu = (a + b) * 2;

            Console.WriteLine("{0} {1}", menseki, syu);
        }
    }
}

Measured memory_bytes: 5624
N,A,B = map(int,input().split())
if (max(A,B)-min(A,B))%2==0:
    cnt = (max(A,B)-min(A,B))//2
else:
    cnt1 = min(max(A,B)-1,N-min(A,B))
    cnt2 = min(A,B)+(max(A,B)-min(A,B)-1)//2
    cnt3 = N-max(A,B)+1+(max(A,B)-min(A,B)-1)//2
    cnt = min(cnt1,cnt2,cnt3)
print(cnt)

Measured memory_bytes: 38384
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

long[10^^5] HS, MEMO;

void main()
{
    auto N = readln.chomp.to!int;
    foreach (i, h; readln.split.to!(long[])) HS[i] = h;

    MEMO[0..N] = -1;

    long solve(int i) {
        if (MEMO[i] != -1) return MEMO[i];
        if (i == N-1) return 0;
        if (i == N-2) return MEMO[i] = solve(i+1) + abs(HS[i] - HS[i+1]);
        return MEMO[i] = min(solve(i+1) + abs(HS[i] - HS[i+1]), solve(i+2) + abs(HS[i] - HS[i+2]));
    }

    writeln(solve(0));
}

Measured memory_bytes: 11812
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;



map<vector<int>, int>perm_mp;
int main() {

	{
		vector<int>perms(4);
		std::iota(perms.begin(), perms.end(), 0);
		int k = 0;
		do {
			perm_mp[perms] = k++;
		} while (next_permutation(perms.begin(), perms.end()));
	}
	int N, K; cin >> N >> K;
	vector<vector<int>>fs = vector<vector<int>>(N, vector<int>(4));
	for (int i = 0; i < N; ++i) {
		for (int j = 0; j < K; ++j) {
			cin >> fs[i][j];
		}
	}
	vector<vector<int>>priority_dates(24, vector<int>(N));
	{
		vector<int>perms(4);
		std::iota(perms.begin(), perms.end(), 0);
		int k = 0;
		do {
			vector<int>v(N);
			std::iota(v.begin(), v.end(), 0);
			for (int j = 3; j >= 0; --j) {
				std::stable_sort(v.begin(), v.end(), [&](const int a, const int b) {
					return fs[a][perms[j]] > fs[b][perms[j]];
				});
			}
			for (int i = 0; i <v.size() ;++i){
				priority_dates[k][v[i]] = i;
			}
			k++;
		} while (next_permutation(perms.begin(), perms.end()));
	}
	int D; cin >> D;
	vector<vector<int>>edges(N);
	vector<int>come_nums(N);
	for (int i = 0; i < D; ++i) {
		int a, b; cin >> a >> b; a--; b--;
		edges[a].push_back(b);
		come_nums[b]++;

	}
	map<int, int>change_prioritys;
	{
		vector<int>es(4);
		for (int j = 0; j < K; ++j) {
			cin >> es[j];
			es[j]--;
		}
		for (int j = K; j < 4; ++j)es[j] = j;
		change_prioritys[0] = perm_mp[es];
	}
	{
		int R; cin >> R;
		for (int i = 0; i < R; ++i) {
			int m; cin >> m;
			vector<int>es(4);
			for (int j = 0; j < K; ++j) {
				cin >> es[j];
				es[j]--;
			}
			for (int j = K; j < 4; ++j)es[j] = j;
			change_prioritys[m] = perm_mp[es];
		}
	}
	vector<priority_queue<int>>que;
	vector<set<pair<int, int>>>sets(24);
	for (int i = 0; i < N; ++i) {
		if (!come_nums[i]) {
			for (int j = 0; j < 24; ++j) {
				sets[j].emplace(priority_dates[j][i], i);
			}
		}
	}
	int prio_id = -1;
	for (int i = 0; i < N; ++i) {
		if (change_prioritys.find(i) != change_prioritys.end())
			prio_id = change_prioritys[i];

		int task = sets[prio_id].begin()->second;
		for(int j = 0; j < 24; ++j) {
			sets[j].erase(make_pair(priority_dates[j][task], task));
		}
		for (auto e : edges[task]) {
			come_nums[e]--;
			if (come_nums[e] == 0) {
				for (int j = 0; j < 24; ++j) {
					sets[j].emplace(priority_dates[j][e], e);
				}
			}
		}
		cout << task+1 << endl;
	}

	return 0;
}

Measured memory_bytes: 70500
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
  cin>>n;
 set<string> s;
  while(n--){
    string s1;
    cin>>s1;
    s.insert(s1);
  }
  cout<<s.size()<<"\n";  
  return 0;
}


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

using namespace std;

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

typedef pair<int,int> ii;

long long n,a[200005],ans;

int main(){
    cin.tie(0),ios::sync_with_stdio(0);
    cin >> n;
    for(int i = 1;i<=n;i++)
        cin >> a[i];
    if(a[1]!=0){
        cout<<"-1";
        return 0;
    }
    int check1=1;
    for(int i = 2;i<=n;i++){
        if(a[i]>a[i-1]+1) {cout<<"-1"; return 0;}
        if(a[i]==a[i-1]+1) ans++;
        else ans+=a[i];
    }
    cout<<ans;
}


Measured memory_bytes: 1792
/* ex5_3 KitamoriFumiya */
#include<stdio.h>

// マス目を圧縮して、そのマス目を出力する関数
void compression(int height, int width, char matrix[height][width]){
	int row[height], col[width], i, j; // row[height](列に#が含まれているときに1を格納する配列),col[width](行に#が含まれているときに1を格納する配列),i,jをint型の変数として宣言
	
	// i行目に#が含まれていたらrowのi番目に1を記録
	for(i = 0; i < height; i++){
		row[i] = 0; // row[i]は初め0にしておく
		for(j = 0; j < width; j++){
			if(matrix[i][j] == '#'){
				row[i] = 1;
				break; // 記録したらループを抜け出す
			}
		}
	}
	
	// j行目に#が含まれていたらcolのj番目に1を記録
	for(j = 0; j < width; j++){
		col[j] = 0; // col[j]は初め0にしておく
		for(i = 0; i < height; i++){
			if(matrix[i][j] == '#'){
				col[j] = 1;
				break; // 記録したらループを抜け出す
			}
		}
	}
	
	// 1つでも#のある行と列を出力する
	for(i = 0; i < height; i++){
		// まず、i番目の行に#が含まれているかを判定
		if(row[i] == 1){
			for(j = 0; j < width; j++){
				// つぎに、j番目の列に#が含まれているかを判定し、含まれていたらmatrix[i]j[]を出力
				if(col[j] == 1){
					printf("%c", matrix[i][j]);
				}
			}
			printf("\n"); // 1行分を出力したら改行する
		}
	}
}

int main(void){
	int height, width, i, j; // height(行数),width(列数),i,jをint型の変数として宣言
	scanf("%d %d", &height, &width); // height,widthを入力
	char matrix[height][width]; // matrix[height][width](height行width列のマス目)を二次元配列の文字列として宣言
	// マス目の各要素を入力
	for (i = 0; i < height; i++){
		for (j = 0; j < width; j++){
			scanf(" %c", &matrix[i][j]);
		}
	}
	
	compression(height, width, matrix);
	
	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
int main(void){
int a,b,c,k;
  scanf("%d %d %d",&a,&b,&c);
  scanf("%d",&k);
  for(;;){
    if(a>=b&&a>=c){c=c*2; k--;}
      else if(b>=a&&b>=c){b=b*2; k--;}
  		else if(c>=a&&c>=b){c=c*2; k--;}
  if(k==0){break;}
}
  printf("%d",a+b+c);
return 0;
}

Measured memory_bytes: 128