akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PLL = pair<ll, ll>;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repn(i,n) for(int i = 0; i <= (int)(n); i++)
#define srep(i,l,n) for(int i = l; i < (int)(n); i++)
#define srepn(i,l,n) for(int i = l; i <= (int)(n); i++)
#define drep(i,n) for(int i = (int)(n-1); i >= 0; i--)
#define drepn(i,n) for(int i = (int)(n); i >= 0; i--)
#define size(s) (int)s.size()
#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<class T = int> using V = vector<T>;
template<class T = int> using VV = vector<V<T>>;
bool isIn(int i, int j, int h, int w) {return i >= 0 && i < h && j >= 0 && j < w;}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void err() {cout << -1 << endl;}
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define ep emplace_back

const int MOD = 1000000007;
const int INF = 1e9;

#define PI acos(-1);
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};

template <class T>
struct RMQ {
    const T INF = numeric_limits<T>::max();
    int n;
    vector<T> dat;
    RMQ(int n_) : n(), dat(n_*4, INF) {
        int x = 1;
        while(n_ > x) {
            x *= 2;
        }
        n = x;
    }

    void update(int i, T x) {
        i += n-1;
        dat[i] = x;
        while(i > 0) {
            i = (i-1)/2;
            dat[i] = min(dat[i*2+1], dat[i*2+2]);
        }
    }

    T query(int a, int b) {
        return query_sub(a, b, 0, 0, n);
    }

    T query_sub(int a, int b, int k, int l, int r) {
        if(r <= a || b <= l) return INF;
        else if(a <= l && r <= b) return dat[k];
        else {
            T vl = query_sub(a, b, k*2+1, l, (l+r)/2);
            T vr = query_sub(a, b, k*2+2, (l+r)/2, r);
            return min(vl, vr);
        }
    }
};

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

    int n;
    cin >> n;
    RMQ<int> bit(n);
    int q;
    cin >> q;
    while(q--) {
        int c, x, y;
        cin >> c >> x >> y;
        if(c == 0){
            bit.update(x, y);
        }else{
            cout << bit.query(x, y+1) << endl;
        }
    }
}


Measured memory_bytes: 4420
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a,b;
    cin>>a>>b;
    int min = (a<=b)? a: b;
    int max = (a>=b)? a: b;
    int r;
    do{
        r = max%min;
        max = min;
        min = r;
    }while(r!=0);
     cout<<max<<endl;
    
     return 0;
}



Measured memory_bytes: 3180
import math as mt
import sys, string
from collections import Counter, defaultdict
input = sys.stdin.readline

# input functions
I = lambda : int(input())
M = lambda : map(int, input().split())
ARR = lambda: list(map(int, input().split()))

def isTriangle(a, b, c):
    if a + b > c and b + c > a and a + c > b:
        return 1
    return 0

def allDiff(a, b, c):
    if a != b and b != c and a != c:
        return 1
    return 0 

def main():
    n = I()
    arr = ARR()
    ans = 0
    for i in range(0,n-2):
        for j in range(i+1,n-1):
            for k in range(j+1,n):
                if allDiff(arr[i], arr[j], arr[k]) and isTriangle(arr[i], arr[j], arr[k]):
                    ans+=1
    
    
    print(ans)

main()

Measured memory_bytes: 10000
#include<bits/stdc++.h>
using namespace std;
int num,n,m,w,k;
long long ans=0;
string x;
void func(int a,int b,int c){
	string temp="";
	for(int i=0;i<num;i++)
		temp+='0';
	if(b==999){
		for(int i='1';i<='9';i++){
			temp[a]=i;
			if(temp<=x)
				ans++;
		}
		return;
	}
	else if(c==999){
		for(int i='1';i<='9';i++)
			for(int j='1';j<='9';j++){
				temp[a]=i;
				temp[b]=j;
				if(temp<=x)
					ans++;
			}
		return; 
	}
	for(int i='1';i<='9';i++)
		for(int j='1';j<='9';j++)
			for(int f='1';f<='9';f++){
				temp[a]=i;
				temp[b]=j;
				temp[c]=f;
				if(temp<=x)
					ans++;
			}
	return;
}
int main(){
	cin>>x>>k;
	num=x.size();
	if(k==1){
		for(int i=0;i<num;i++)
			func(i,999,999);
		cout<<ans;
		return 0;
	}
	else if(k==2){
		for(int i=1;i<num;i++)
			for(int j=0;j<i;j++)
				func(j,i,999);
		cout<<ans;
		return 0;
	}
	for(int i=2;i<num;i++)
		for(int j=1;j<i;j++)
			for(int f=0;f<j;f++)
				func(f,j,i);
	cout<<ans;
	return 0; 
}

Measured memory_bytes: 256
n = gets.chomp.to_i
a = gets.chomp.split(" ").map(&:to_i)
s = a.inject(:+)
tmp = 0
1.step(n-2, 2) do |i|
    tmp += a[i]
end
ans = [s-2*tmp]

(n-1).times do |i|
    ans << 2 * a[i] - ans[i]
end

puts ans.join(" ")

Measured memory_bytes: 15236
#include<bits/stdc++.h>
using namespace std;
int n;
int f[130],a[130];
string st;
int main()
{
	cin>>n;
	memset(f,120,sizeof(f));
	for(int i=1; i<=n; i++)
	{
		cin>>st;
		memset(a,0,sizeof(a));
		for(int j=0; j<st.size(); j++)
		a[st[j]]++;
		for(int j=97; j<=122; j++)
		f[j]=min(a[j],f[j]);
	}
	for(int i=97; i<=122; i++)
	{
		for(int j=1; j<=f[i]; j++)
		cout<<char(i);
	}
	return 0;
}

Measured memory_bytes: 256
import itertools
import numpy as np

N, M = map(int, input().split())
X = [[] for _ in range(M)]
for i in range(M):
    X[i] = list(map(int, input().split()))
permutations_list = list(itertools.permutations([i for i in range(N-1)]))

count = 0
for i in range(len(permutations_list)):
    x = np.argsort(permutations_list[i])
    if [1, x[0]+2] not in X and [x[0]+2, 1] not in X:
        count += 1
        continue
    for j in range(N-2):
        pair = [x[j]+2, x[j+1]+2]
        reverse = list(reversed(pair))
        if pair not in X and reverse not in X:
            count += 1
            break
print(len(permutations_list) -count)

Measured memory_bytes: 12532
#include <bits/stdc++.h>
// statics
using namespace std;
using int64 = int_fast64_t;
using PAIR = pair<int64, int64>;
constexpr int INF = 1 << 30;
constexpr int64 LINF = 1LL << 60;
constexpr int MOD = 1e9 + 7;
constexpr int MAX_N = 3e5 + 1;

// init/input
#define int int64
#define INIT ios::sync_with_stdio(false);cin.tie(0);
#define VAR(type, ...) type __VA_ARGS__;MACRO_VAR_Scan(__VA_ARGS__);
template<typename T> void MACRO_VAR_Scan(T &t) {cin>>t;}
template<typename First, typename...Rest> void MACRO_VAR_Scan(First &first, Rest&...rest) {cin>>first;MACRO_VAR_Scan(rest...);}
#define VEC(type, c, n) vector<type> c(n);for(auto &&i:c)cin>>i;

// out
#define OUT(dist) cout<<(dist);
#define FOUT(n, dist) cout<<fixed<<setprecision(n)<<(dist);
#define SP cout<<" ";
#define BR cout<<endl;
#define zero(n) cout<<setfill('0')<<right<<setw(n)
#define debug(x) cerr<<#x<<":"<< (x);BR;

// utility
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EACH(i, a) for(auto &&i:(a))
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RFOR(i, a, b) for(int i=(b)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<(n);++i)
#define RREP(i, n) for(int i=(n)-1;i>=0;--i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}

signed main() {
  INIT;
  VAR(int,n);
  int ans = 0;
  vector<PAIR> d(n);
  REP(i,n){
    VAR(int,a,b);
    d[i] = make_pair(a,b);
  }
  sort(ALL(d));

  cout<<d.back().first+d.back().second<<endl;
  
  
  return 0;
}


Measured memory_bytes: 1792
N,M = map(int, input().split())
S = input()
T = input()
from fractions import gcd

# 15, 9
# 3$BJ8;z$:$D8+$F$$$/!"(B5$BJ8;z$:$D8+$F$$$/(B
LEN = N*M // gcd(N,M) # 45
p = LEN // N # 3
q = LEN // M # 5
lcm = p*q//gcd(p,q)

for i in range(0, LEN//lcm):
    if S[i*q] != T[i*p]:
        print(-1)
        exit()
print(LEN)


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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define ll long long
#define pii pair<int,int>
#define all(x) begin(x), end(x)
#define loop(i,n) for(int i=0; i<n; i++)
#define rep(i,a,b,c) for(int i=a; i<b; i+=c)
#define brep(i,a,b,c) for(int i=a; i>b; i-=c)
#define tc(t) int t; cin>>t; while(t--)
#define sz(v) int((v).size())
#define pb push_back


using namespace std;

void __print(int x) {cout << x;}
void __print(long x) {cout << x;}
void __print(long long x) {std::cout << x;}
void __print(unsigned x) {std::cout << x;}
void __print(unsigned long x) {std::cout << x;}
void __print(unsigned long long x) {std::cout << x;}
void __print(float x) {std::cout << x;}
void __print(double x) {std::cout << x;}
void __print(long double x) {std::cout << x;}
void __print(char x) {cout << '\'' << x << '\'';}
void __print(const char *x) {cout << '\"' << x << '\"';}
void __print(const string &x) {cout << '\"' << x << '\"';}
void __print(bool x) {cout << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cout << '{'; __print(x.first); cout << ','; __print(x.second); cout << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cout << '{'; for (auto &i : x) cout << (f++ ? "," : ""), __print(i); cout << "}";}
void _print() {cout << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cout << ", "; _print(v...);}
template <typename T> inline void inp(T &any) {cin >> any;} template <typename T, typename... U>inline void inp(T &a, U &...b) {cin >> a; inp(b...);}
#define rin(args...) ll args; inp(args);
#ifndef ONLINE_JUDGE
#define debug(x...) cout << "[" << #x << "] = ["; _print(x)
#define matdeb(mat,row,col) cout << #mat << "::" << endl; printmat(mat,row,col); printpartition;
#define debugv(v,n) cout << #v << ":" << endl; printv(v,0,n-1); printpartition;
#else
#define debug(x...)
#define matdeb(mat,row,col)
#define debugv(v,n)
#endif

const int maxm = 1000000000 + 7;

const ll MOD = 1e9 + 7;
const int INF = 55;
ll dp [INF] [INF * INF];

double startTime;
double getCurrentTime() {
    return ((double)clock() - startTime) / CLOCKS_PER_SEC;
}


//----------->CODE BEGINS --------------->



int main()
{

#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    IOS;

   int n;
   cin>>n;

   vector<int>a(n);

   int alice=0, bob=0;

   loop(i,n)
   {
    cin>>a[i];
   }


   sort(all(a));
   reverse(all(a));

   rep(i,0,n,2)
   {
     alice += a[i];
   }

   rep(i,1,n,2)
   {
     bob += a[i];
   }

   cout<<alice-bob<<endl;


}


Measured memory_bytes: 3676
import sys
sys.setrecursionlimit(10 ** 6)

N, M, Q = map(int, input().split())
abcd = [list(map(int, input().split())) for i in range(Q)]
A = []
def rec(itr, lst):
    if itr == N:
        res = 0
        for a, b, c, d in abcd:
            if A[b-1] - A[a-1] == c:
                res += d
        return res
    else:
        res = 0
        for i in range(lst, M):
            A.append(i)
            res = max(res, rec(itr + 1, i))
            A.pop()
        return res
print(rec(0, 0))


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

public class MainClass
{
	public const long Giri = 1000000007;

	public static void Main(string[] args)
	{
		var p = Input().ToInt();
		int five = 0;
		int seven = 0;
		foreach(var i in p)
		{
			if(i == 5) five++;
			else if(i == 7) seven++;
			else
			{
				Console.WriteLine("NO");
				return;
			}
		}
		if(five == 2 && seven == 1)
			Console.WriteLine("YES");
		else
			Console.WriteLine("NO");
		

	}
	
	static long GCD(long a, long b)
	{
		var v = new[] { a, b };
		while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; }
		return v[0];
	}
	public static string[] Input() { return Console.ReadLine().Split(' '); }
	public static int Clamp(int val, int max, int min = 0) { return Math.Min(max, Math.Max(min, val)); }
}

public static class Smarter
{
	public static int ToInt(this string str) { return int.Parse(str); }
	public static long ToLong(this string str) { return long.Parse(str); }
	public static int[] ToInt(this string[] str)
	{
		var r = new int[str.Length];
		for(int i = 0; i < str.Length; i++) r[i] = str[i].ToInt();
		return r;
	 }
}


Measured memory_bytes: 13140
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <set>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

using namespace std;
typedef long long int lli;

//dp[i][j]. 偶奇でi番目までで部分和j-2550になる通り数
lli dp[2][5100];

int main(){
	lli N,A;
	cin>>N>>A;
	lli x[50];
	rep(i,50){
		cin>>x[i];
		x[i]-=A;
	}
	dp[1][2550]=1;
	
	rep(i,N){
		lli t=(i&1);
		rep(j,5000) dp[t][j]=dp[t^1][j]+dp[t^1][j-x[i]];
	}
	
	cout<<dp[(N-1)&1][2550]-1;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); i++) 
#define all(v) begin(v),end(v)
using ll = long long;

int main() {
  int h,w;cin>>h>>w;
  vector<vector<char>> s(h,vector<char>(w));
  rep(i,h)rep(j,w)cin>>s[i][j];
  rep(i,h)rep(j,w){
    if(s[i][j]=='.'){
      s[i][j]='0';
      for(int dx=-1;dx<=1;dx++){
        for(int dy=-1;dy<=1;dy++){
          int nx=i+dx,ny=j+dy;
          if(0<=nx&&nx<h&&0<=ny&&ny<w){
          if(s[nx][ny]=='#')s[i][j]++;
          }
        }
      }
    }
  }
    rep(i,h)rep(j,w){
      cout<<s[i][j];
      if(j==w-1)cout<<endl;
    }
  }

Measured memory_bytes: 3536
#define M 1000000
n[M];main(i,j){n[0]=0;n[1]=-1;for(i=2;i<M;i++)if(!n[i])for(j=i*2;j<M;j+=i)n[j]=-1;for(i=1;i<M;i++)n[i]+=n[i-1]+1;for(;~scanf("%d",&i);printf("%d\n",n[i]));return 0;}

Measured memory_bytes: 0
#include"bits/stdc++.h"
using namespace std;
using ll=long long;
template<class T=ll>inline T in(istream&is=cin){T ret;is>>ret;return ret;}
template<class T>inline auto vec2(typename vector<T>::size_type h,typename vector<T>::size_type w,T v=T()){return vector<vector<T>>(h,vector<T>(w,v));}
template<class RandomAccessIterator>inline void psortb(RandomAccessIterator first,RandomAccessIterator last){using P=pair<decltype(first->first),decltype(first->second)>;sort(first,last,[](const P&p1,const P&p2){return p1.second<p2.second||(p1.second==p2.second&&p1.first<p2.first);});}

int main()
{
    ll n=in(),d=in();
    ll cnt=0;
    for(ll i=0;i<n;++i){
        ll x=in(),y=in();
        if(x*x+y*y<=d*d)++cnt;
    }
    cout<<cnt<<endl;
}


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

typedef long long ll;
ll n, k, cnt, s, a[5005];
int main()
{
	ll i, j;
	cin >> n >> k;
	for (i = 0; i < n; i++) {
		scanf ("%lld", &a[i]);
	}
	sort(a, a + n);
	for (i = n - 1; i >= 0; i--) {
		if (s + a[i] >= k) {
			cnt = 0;
		} else {
			s += a[i];
			cnt++;
		}
	}
	cout << cnt;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<string>
#include<utility>
#include<numeric>
#include<algorithm>
#include<cmath>
#include<climits>
using namespace std;

using ll = long long;

class Stream{
public:
    Stream(){

    }
    //配列以外の入力を受け取る
    void read(){

    }
    template<typename First, typename... Rest>
    void read(First& first, Rest&... rest){
        cin >> first;
        read(rest...);
    }
    template<typename T>
    vector<T> read_vec(size_t n){
        vector<T> tmp(n);
        for(size_t i = 0; i < n; i++){
            cin >> tmp[i];
        }
        return tmp;
    }
    //配列を区切って出力する
    template<typename T>
    void write_vec(vector<T>& v, char divider){
        for(size_t i = 0; i < v.size(); i++){
            cout << v[i] << divider;
        }
    }
};

int main(){
    Stream io;

    ll H, W;
    io.read(H, W);
    ll ans;
    if(H % 3 == 0 || W % 3 == 0) ans = 0;
    else ans = min(H, W);
    for(ll i = 1; i < H; i++){
        multiset<ll> S;
        S.insert(i * W);
        S.insert(W / 2 * (H - i));
        S.insert((W - W / 2) * (H - i));
        ans = min(ans, *S.rbegin() - *S.begin());
    }
    for(ll i = 1; i < W; i++){
        multiset<ll> S;
        S.insert(i * H);
        S.insert(H / 2 * (W - i));
        S.insert((H - H / 2) * (W - i));
        ans = min(ans, *S.rbegin() - *S.begin());
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 3632
# 最小公倍数(mathは3.5以降) fractions
# 参考　https://note.nkmk.me/python-gcd-lcm/

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y) # 「//」はフロートにせずにintにする
def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

# 初期入力
from functools import reduce
import fractions #(2020-0405  fractions→math)
import sys
input = sys.stdin.readline
A,B,C,D = (int(x) for x in input().split())

c_multi_B =B // C #Cの倍数
d_multi_B =B // D #Dの倍数
least_common_multi =lcm(C,D)
cd_common_multi_B =B //least_common_multi

c_multi_A =(A -1) // C #Cの倍数
d_multi_A =(A -1) // D #Dの倍数
least_common_multi =lcm(C,D)
cd_common_multi_A =(A -1)//least_common_multi

#A以上、B以下
all =B -A +1

ans =all - (c_multi_B -(c_multi_A )) -(d_multi_B -(d_multi_A )) + cd_common_multi_B -cd_common_multi_A
print(ans)

Measured memory_bytes: 5384
#include <stdio.h>

int main(void)
{
    int n, number, i, j;
    char mark;
    int card[4][13] = {0};

    scanf("%d", &n);
    for (i = 0; i < n; i++)
    {
        scanf(" %c %d", &mark, &number);
        if (mark == 'S')
        {
            card[0][number - 1] = 1;
        }
        else if (mark == 'H')
        {
            card[1][number - 1] = 1;
        }
        else if (mark == 'C')
        {
            card[2][number - 1] = 1;
        }
        else if (mark == 'D')
        {
            card[3][number - 1] = 1;
        }
    }
    for (i = 0; i < 4; i++)
    {
        for (j = 0; j < 13; j++)
        {
            if (card[i][j] == 0)
            {
                if (i == 0)
                {
                    printf("S %d\n", j + 1);
                }
                else if (i == 1)
                {
                    printf("H %d\n", j + 1);
                }
                else if (i == 2)
                {
                    printf("C %d\n", j + 1);
                }
                else if (i == 3)
                {
                    printf("D %d\n", j + 1);
                }
            }
        }
    }
    return 0;
}


Measured memory_bytes: 2716
#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
int main(void){
    char s[20], str[20];
    scanf("%s", s);
    strcpy(str, s);
    
    int n = 0;
    while(s[n]){
        str[n] = tolower(str[n]);
        n++;
    }
    n--;
    
    int flag = 2;
    
    if(s[0] != 'A'){
        flag = 0;
    }else{
        s[0] = 'a';
    }
    
    int i;
    for(i = 2; i <= n - 1; i++){
        if(s[i] == 'C'){
            flag /= 2;
            s[i] = 'c';
        }
    }
    if(flag == 2){
        flag = 0;
    }
    
    if(strcmp(s, str)){
       flag = 0; 
    }
    
    if(flag){
        cout << "AC" << endl;
    }else{
        cout << "WA" << endl;
    }
    
    return 0;
}


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

int main(){
  int Ndet0,Ndet1,Ntox1;
  cin >> Ndet0 >> Ndet1 >> Ntox1;
  
  int ans= (Ndet0+ Ndet1 >= Ntox1) ? Ndet1+ Ntox1
                                   : Ndet1+ (Ndet0+ Ndet1)+ 1;

  cout << ans << endl;
}

Measured memory_bytes: 3632
from collections import deque

N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = input()

hands = deque()
score = 0
for i in range(N):
    hand = {'r': 'p', 's': 'r', 'p': 's'}[T[i]]

    if len(hands) == K:
        last = hands[0]
        if last == hand:
            hand = '*'
        hands.popleft()
    hands.append(hand)

    score += {'r': R, 's': S, 'p': P}.get(hand, 0)
print(score)

Measured memory_bytes: 43244
a, b, k = map(int, input().split())
s = set()
l = range(a, b+1)

if len(l) <= k:
    for i in l:
        print(i)
else:
    for j in l[:k]:
        s.add(j)
    
    for j in l[len(l)-k:]:
        s.add(j)

    m = sorted(list(s))
    for i in m:
        print(i)


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

#pragma GCC optimize("Ofast","unroll-loops","omit-frame-pointer","inline") //Optimization flags
#pragma GCC option("arch=native","tune=native","no-zero-upper") //Enable AVX
#pragma GCC target("avx2") //Enable AVX

using namespace std;

#define F first
#define S second 

#ifdef __debug_leywar
#include <debug/debugger.h>
#else
#define db(...) ;
#endif

int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
  
    int n ; 
    cin >> n ; 

    long long ans = 7 ; 
    bool sol = false ; 

    for( int i = 1 ; i <= 1'000'000 ; i++ )
    {
        ans %= n  ; 
        if( ans == 0 )
        {
            ans = i ; 
            sol = true ; 
            break ; 
        }

        ans = ( ans * 10 ) + 7 ; 
    }

    cout << ( sol ? ans : (long long)-1 ) ;

    return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define boost std::ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)

using namespace std;
using LL = long long;

constexpr int MAXN = 505;
constexpr LL M = 998244353;

template <typename T>
inline void read(T &x) {
    int f = 1;
    x = 0;
    char ch = getchar();
    while (!isdigit(ch)) f = (ch == '-') ? -1 : 1, ch = getchar();
    while (isdigit(ch)) x = x * 10 + ch - 48, ch = getchar();
    x *= f;
}

vector<LL> vec;
int C, k;

inline void search(LL pre, int cnt) {
    if (cnt >= 11) return;
    if (pre % 10 != 0) vec.emplace_back(pre * 10 + pre % 10 - 1);
    vec.emplace_back(pre * 10 + pre % 10);
    if (pre % 10 != 9) vec.emplace_back(pre * 10 + pre % 10 + 1);

    if (pre % 10 != 0) search(pre * 10 + pre % 10 - 1, cnt + 1);
    search(pre * 10 + pre % 10, cnt + 1);
    if (pre % 10 != 9) search(pre * 10 + pre % 10 + 1, cnt + 1);
}

int main() {
    //freopen("test.out", "w", stdout);
    boost;
    cin >> k;
    for (int i = 1; i <= 9; i++) vec.emplace_back(i);
    for (int i = 1; i <= 9; i++) search(i, 2);
    sort(vec.begin(), vec.end());
    //cout << vec.size() << endl;
    //  for (int i = 0; i < vec.size() / 100; i++) {
    //      cout << vec[i] << " ";
    //  }
    cout << vec[k - 1] << endl;
    return 0;
}

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

typedef string::const_iterator State;
#define inRange(x,a,b) (a <= x && x <= b)

int expression(State &begin);
int term(State &begin);
int factor(State &begin);
int number(State &begin);

int mod;
bool ng = false;

int modpow(int a, int b){
    if(b == 0)  return 1;

    if(b % 2 == 0){
        int d = modpow(a, b/2);
        return (d*d) % mod;
    }else{
        return (a%mod * modpow(a, b-1)) % mod;
    }
}

int expression(State &begin){
    int ret = term(begin);
    while(true){
        if(*begin == '+'){
            begin++;
            ret = (ret+term(begin))%mod;
        }else if(*begin == '-'){
            begin++;
            ret = (ret-term(begin)+mod)%mod;
        }else{
            break;
        }
    }
    return ret;
}

int term(State &begin){
    int ret = factor(begin);
    while(true){
        if(*begin == '*'){
            begin++;
            ret = (ret * factor(begin))%mod;
        }else if(*begin == '/'){
            begin++;
            int divide = factor(begin);
            if(divide == 0)  ng = true, divide = 1;
            int inv = modpow(divide, mod-2);
            ret = (ret * inv)%mod;
        }else{
            break;
        }
    }
    return ret;
}

int factor(State &begin){
    if(*begin == '('){
        begin++;
        int ret = expression(begin);
        begin++;    // ')'
        return ret;
    }
    return number(begin);
}

int number(State &begin){
    int ret = 0;
    while(inRange(*begin, '0', '9')){
        ret *= 10;
        ret += *begin-'0';
        begin++;
    }
    return ret;
}

int main(){
    string s;
    while(getline(cin, s), s != "0:"){
        ng = false;
        string t = "";
        int cur = 0;
        while(s[cur] != ':')    cur++;
        mod = stoi(s.substr(0, cur));
        cur++;
        while(cur < s.length()){
            if(s[cur] != ' ')   t += s[cur];
            cur++;
        } 
        State begin = t.begin();
        int ans = expression(begin);
        if(ng){
            cout << "NG" << endl;
        }else{
            cout << t << " = " << ans << " (mod " << mod << ")" << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3200
#include <bits/stdc++.h>
#define rep(i,a,b) for(ll i=ll(a);i<ll(b);i++)
#define irep(i,a,b) for(ll i=ll(a);i>=ll(b);i--)
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; }
#define pb push_back
#define mp make_pair
#define F .first
#define S .second 
using ll=long long;
using ld=long double;
const ll INF = 1LL<<60;
const ll mod=1e9+7;
using namespace std;
ll GCD(ll a, ll b) { return b ? GCD(b, a%b) : a; }
 
ll a[110000];
ll b[110000];
int main(){
    ll n,k;
    cin>>n>>k;
    ll x=1;
    ll cnt=0;
    while(n>=x){x*=k;cnt++;}
    cout<<cnt;
    
}

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

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<string> vs;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vll = vector<vl>;
using vpll = vector<pll>;
struct Edge {
	ll to;
 	ll cost;
 };
using Graph = vector<vector<Edge>>;

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
/***** define constant start *******/
const ll MOD = 1000000007;
const double PI = 3.1415926535897932;
const ll INF = LLONG_MAX;
string abc = "abcdefghijklmnopqrstuvwxyz";
string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const ll MAX = 10000000;
/****** define constant end ********/
/****** define variable start ******/
string s;
/******* define variable end *******/
int solve() {
	cin >> s;
	if(s =="ABC"){
		cout<<"ARC"<<endl;
	}else{
		cout <<"ABC"<<endl;
	}
	return 0;
}

int main() {
	//clock_t start = clock();
	cout << std::fixed << std::setprecision(10);
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int end_solve = solve();
	/*
	clock_t end = clock();
	const double time = static_cast<double>(end - start) / CLOCKS_PER_SEC *
	1000.0; printf("time %lf[ms]\n", time);
	*/

	return end_solve;
}


Measured memory_bytes: 3644
import sys
MX = 10**5
def main():
    data = map(int, sys.stdin.buffer.read().split())
    N = next(data)

    H = min(N + 1, 1 << 10)
    dp = [None] * H
    dp[0] = [0] * (MX + 1)
    IV, IW = [], []
    i = 1
    for v, w in zip(data, data):
        if i < H:
            dpi = dp[i >> 1][:]
            dp[i] = dpi
            for j in range(MX, w - 1, -1):
                dpi[j] = max(dpi[j], dpi[j - w] + v)
        else:
            IV.append(v)
            IW.append(w)
        i += 1
        if i > N:
            break

    Q = next(data)
    for v, L in zip(data, data):
        if v < H:
            print(dp[v][L])
            continue

        item_values = []
        item_weights = []
        while v >= H:
            item_values.append(IV[v - H])
            item_weights.append(IW[v - H])
            v >>= 1

        l = len(item_values)
        V = [0] * (1 << l)
        W = [0] * (1 << l)
        ans = dp[v][L]
        for i in range(1, 1 << l):
            msb = i & (-i)
            msbb = msb.bit_length() - 1
            wi = W[i - msb] + item_weights[msbb]
            W[i] = wi
            if wi <= L:
                vi = V[i - msb] + item_values[msbb]
                ans = max(ans, vi + dp[v][L - wi])
                V[i] = vi
        print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 921876
#include <bits/stdc++.h>
using namespace std;
#define rep2(i,m,n) for (int i = (m); i < (n); ++i)
#define rep(i,n) rep2(i,0,n)
typedef long long int ll;
typedef long double ld;
typedef pair<int, int> P;
template<typename T> struct V : vector<T> { using vector<T>::vector; };
V() -> V<int>;
V(size_t) -> V<int>;
template<typename T> V(size_t, T) -> V<T>;
template<typename T> vector<T> make_vec(size_t n, T a) { return vector<T>(n, a); }
template<typename... Ts> auto make_vec(size_t n, Ts... ts) { return vector<decltype(make_vec(ts...))>(n, make_vec(ts...)); }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << ' '; return os; }
struct fast_ios { fast_ios(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
const int INF = 1<<30;
const ll LINF = 1LL<<61;

int main()
{
    string s;
    cin >> s;
    if(s == "RSR") cout << 1 << endl;
    else cout << count(s.begin(), s.end(), 'R') << endl;
    //cout << s << endl;
    return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
    #include <math.h>
 
    using namespace std;
    typedef long long ll;
    typedef unsigned long long ull;
    # define M_PI  3.14159265358979323846
 
 
    const int M=1e9+7;
    long long mod(long long x){
        return ((x%M + M)%M);
    }
    long long add(long long a, long long b){
        return mod(mod(a)+mod(b));
    }
    long long mul(long long a, long long b){
        return mod(mod(a)*mod(b));
    }
 
    ll modPow(ll a, ll b){
        if(b==0)
            return 1LL;
        if(b==1)
            return a%M;
        ll res=1;
        while(b){
            if(b%2==1)
                res=mul(res,a);
            a=mul(a,a);
            b=b/2;
        }
        return res;
    }
 
    void solve (){
        int n;
        n=5;
        vector<int>a(n);
        vector<int>b(n);
        for(int i=0;i<n;i++){
            cin>>a[i];
            b[i]=i;
        }
        int mini=1e9;
        while(next_permutation(b.begin(),b.end())){
            vector<int>order(n);
            for(int i=0;i<n;i++){
                for(int j=0;j<n;j++){
                    if(i==b[j])
                        order[i]=a[j];
                }
            }
            int total=0;
            for(int i=0;i<n;i++){
                if(i==0)
                    total+=order[i];
                else{
                    while(total%10!=0)
                        total++;
                    total+=order[i];
                }
            }
            mini=min(mini,total);
        }
        cout<<mini;
    }
    int main(){
        ios::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
        cout<<fixed;
        cout<<setprecision(10);
//        freopen("timber_input.txt", "r", stdin);
//        freopen("timber_output.txt", "w", stdout);
        int t=1;
        // cin>>t;
        for(int i=1;i<=t;i++){
//            cout<<"Case #"<<i<<": ";
            solve();
        }
        return 0;
    }

Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
#define LL long int
#define ULL unsigned long int
#define LD long double

LL MOD = 1000000007;


int main(void){
    int a;
    cin >> a;
    cout << a + a*a + a*a*a << endl;

    return 0;
}

Measured memory_bytes: 3636
# -*- coding:utf-8 -*-

def solve():
    S = input()
    T = ""
    while True:
        if S == "":
            break
        
        if S[-5:] == "dream":
            S = S[:-5]
        elif S[-7:] == "dreamer":
            S = S[:-7]
        elif S[-5:] == "erase":
            S = S[:-5]
        elif S[-6:] == "eraser":
            S = S[:-6]
        else:
            print("NO")
            return
    print("YES")

if __name__ == "__main__":
    solve()


Measured memory_bytes: 3188
/*
**   Contest : AtCoder Beginner Contest 127
**   Problem : C - Prison
**
**    Author : Dhiraj Govindvira
**      Date : 24-Jun-2020 ~ Wednesday
**      Time : 08:33:15 PM
*/

#if __has_include("D:/dhiraj/Programming/debug.h")
    #include "D:/dhiraj/Programming/debug.h"
#else
    #include <bits/stdc++.h>
    using namespace std;
    #define d(...) 11
    #define cerr if(0) cerr
#endif

// Macro --------------------------------------------------------------------

#define ll                  long long int
#define loop(i,s,e)         for(ll i=(s); i<(e); i++)
#define rloop(i,s,e)        for(ll i=(s); i>=(e); i--)
#define iter(it,var)        for(auto it=var.begin(); it!=var.end(); it++)
#define riter(it,var)       for(auto it=var.rbegin(); it!=var.rend(); it++)
#define all(x)              x.begin(),x.end()
#define rall(x)             x.rbegin(),x.rend()
#define endl                '\n'

// Template -----------------------------------------------------------------

// multiple input
template <typename... T> 
inline void inp(T&... args) {
    ((cin>>args), ...);
}
// scan vector
template <typename T> 
inline istream &operator>>(istream &in, vector<T> &a) {
    for(auto &x : a) in >> x;
    return in;
}
// scan pair
template <typename T, typename U> 
inline istream &operator>>(istream &in, pair<T,U> &a) {
    in >> a.first >> a.second; 
    return in;
}

// Solve --------------------------------------------------------------------

void solve(ll &T)
{
    ll n, m;
    cin>>n>>m;

    ll l = 1, r = n;
    while(m--)
    {
        ll x, y;
        cin>>x>>y;
        l = max(l,x);
        r = min(r,y);
    }
    cout<<max(0ll,(r-l+1))<<endl;
}

// Main ---------------------------------------------------------------------

int main()
{
    #ifdef Dhiraj
        freopen("D:/dhiraj/Programming/i1.txt","r",stdin);
        freopen("D:/dhiraj/Programming/o1.txt","w",stdout);
    #endif

    ios::sync_with_stdio(false);
    cin.tie(0);

    int t = 1;
    loop(i,1,t+1)
    {
        cerr<<"Case #"<<i<<"\n";
        solve(i);
    }
    return 0;
}

Measured memory_bytes: 3648
-module('Main').
-export([main/1]).

gcd(A, 0) -> A;
gcd(A, B) -> gcd(B, A rem B).

dfs(_A, _B, [], Sum) -> Sum;
dfs(A, B, [C | Ls], Sum) ->
    dfs(A, B, Ls, Sum + gcd(gcd(A, B), C)).

solve() ->
    [K] = input("~d"),
    Ls = lists:seq(1, K),
    Sum = lists:sum([dfs(A, B, Ls, 0) || A <- Ls, B <- Ls]),
    io:format("~B~n", [Sum]),
    ok.

main(_) ->
    solve(),
    halt().

input(Pat) ->
    {ok, L} = io:fread("", Pat),
    L.


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

int main(){

    int N;
    cin >> N;
    long A[N];
    for(int i=0; i<N; i++){
        cin >> A[i];
    }
    sort(A,A+N,std::greater<int>());
    queue <long>  que;

    long long ans=0;

    for(int i=0; i<N-1; i++){

        if(i==0){
            que.push(A[0]);
        }else{
            que.push(A[i]);
            que.push(A[i]);
        }

        ans += (long long) que.front();
        que.pop();

    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 6572
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define int ll
#define rep(i,n) for(int i=0;i<n;i++)
#define all(in) in.begin(), in.end()
#define INF (sizeof(int) == 4 ? (int)1e9:(int)1e18)
#define EPS 0.0000000001
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
using ld  = long double;
using pii = pair<int,int>;
using piii = pair<int,pii>;
int W,H;
int dx[]={0,0,1,-1}, dy[]={1,-1,0,0};
bool valid(int x,int y){return (0<=x&&x<W)&&(0<=y&&y<H);}
template<class T, class Func = function<T(T,T)>>
class CumulativeSum{
public:
    vector<T>sum;
    T e;
    CumulativeSum(const vector<T>v,T e,const Func& f = [](T a, T b){return a + b;}) : sum(v.size()),e(e){
        copy(v.begin(),v.end(),sum.begin());
        T past = 0;
        for(auto & itr : sum){
            itr = f(itr,past);
            past = itr;
        }
    }
    //[l,r)
    auto query(int l, int r, const Func& f = [](T a,T b){return a - b;}){
        if(r > 0) return f(sum[r - 1],(l == 0 ? 0 : sum[l - 1]));
        else return e;
        
    }
};
signed main(){
    constexpr int inf = (1LL << 60);
    int N; cin >> N;
    vector<int>v(N);
    for(auto&e : v)  cin >> e;
    CumulativeSum<int> csum(v,0LL);
    auto dp = vectors(N,N + 1,N + 1, inf);
    for(int i = 0; i < v.size(); ++i){
        dp[0][i][i+1] = v[i];
        dp[1][i][i+1] = 0;
    }
    function<int(int,int)>solve = [&](int l, int r) {
        if(r - l == 1) return csum.query(l,r);
        if(dp[0][l][r] != inf) return dp[0][l][r] + csum.query(l,r);
        int minans = inf;
        for(int i = l + 1; i < r; ++i){
            minans = min(minans, solve(l,i) + solve(i,r));
        }
        dp[0][l][r] = minans;
        
        return minans + csum.query(l,r);
    };
    int res = solve(0,v.size());
    
    cout << res - accumulate(v.begin(),v.end(),0LL) << endl;
}


Measured memory_bytes: 509184
nkq = input().split()
n = int(nkq[0])
k = int(nkq[1])
q = int(nkq[2])
count_ans = [0 for i in range(n)]
for i in range(q):
	count_ans[int(input())-1] += 1

require_ans = q-k+1
for i in range(n):
	if count_ans[i] < require_ans:
		print('No')
	else:
		print('Yes')

Measured memory_bytes: 4732
import sys

L, R = map(int, input().split())
if L + (673 - L % 673) <= R or L % 673 == 0:
  if L + (3 - L % 3) <= R or L % 3 == 0:
    print(0)
    sys.exit()
ans = 2019
a = L % 2019
b = R % 2019
for i in range(a, b):
  for j in range(i+1, b+1):
    ans = min(ans, i * j % 2019)
print(ans)

Measured memory_bytes: 3064
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_tuple(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


def read_col(H):
    '''
    H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) #一列の場合
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return tuple(map(list, zip(*ret)))


def read_matrix(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return ret
    # return [list(map(int, read().split())) for _ in range(H)] # 内包表記はpypyでは遅いため


MOD = 10**9 + 7
INF = 2**31  # 2147483648 > 10**9
# default import
from collections import defaultdict, Counter, deque
from operator import itemgetter
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right  # , insort_left, insort_right

# https://atcoder.jp/contests/abc121/tasks/abc121_d

# xorとは繰り上がりのない足し算である

# f(A,B)=f(0,B)-f(0,A-1)
# f(0,i)をどうやって高速に求めるか？
# 各桁独立、ibit目に登場した1の数の偶奇でわかる
# しかも4つごとに周期が存在する(4*n -1 のときはかならず0になるのでこれを利用できる)


def f(x):
    start = x // 4 * 4
    ret = 0
    for i in ra(start, x + 1):
        ret ^= i
    return ret


A, B = read_ints()
# print(f(B), f(A - 1))
print(f(B) ^ f(A - 1))


Measured memory_bytes: 38384
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define ll long long
#define db long double
#define ii pair<int,int>
#define vi vector<int>
#define fi first
#define se second
#define sz(a) (int)(a).size()
#define all(a) (a).begin(),(a).end()
#define pb push_back
#define mp make_pair
#define FN(i, n) for (int i = 0; i < (int)(n); ++i)
#define FEN(i,n) for (int i = 1;i <= (int)(n); ++i)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repv(i,a,b) for(int i=b-1;i>=a;i--)
#define SET(A, val) memset(A, val, sizeof(A))
typedef tree<pair<ll,int> ,null_type,less<pair<ll,int> >,rb_tree_tag,tree_order_statistics_node_update>ordered_set ;
// order_of_key (val): returns the no. of values less than val
// find_by_order (k): returns the kth largest element.(0-based)
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
const int N=200005;
ll a[N],pre[N];
ordered_set s;
int main()
{
  std::ios::sync_with_stdio(false);
  cin.tie(NULL) ; cout.tie(NULL) ;
  int n;
  ll k;
  cin>>n>>k;
  rep(i,1,n+1) cin>>a[i],pre[i]=a[i]+pre[i-1];
  ll ans=0;
  rep(i,1,n+1)
    {
      s.insert(mp(pre[i-1]-k*i+k,i));
      ll curr=pre[i]-k*i;
      ans+=s.order_of_key(mp(curr+1,0));
    }
  cout<<ans<<endl;
  return 0 ;
}


Measured memory_bytes: 15872
import java.util.*;
public class Main{
public static void main(String[]args){
Scanner sc=new Scanner(System.in);
  int n=sc.nextInt();
  int m=sc.nextInt();
  int a=0;
  for(int i=0;i<n;i++){
    int po=sc.nextInt();
  a+=Math.min(po,m-po);
  }
  System.out.println(a*2);
}
}

Measured memory_bytes: 22612
#include <stdio.h>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>

//#include <tuple>

//#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define ll long long
#define pb push_back

unsigned GetDigit(unsigned num)
{
  return log10(num)+1;
}

// 桁の合計を求める
long sumDigit(long N){
  // 桁数を求める
  int a = GetDigit(N);
  int sum = 0;
  // cout << a << endl;
  rep(i, a){
    sum += N%10;
    N /= 10;
  }
  return sum;
}

int main() {
  long N;
  cin >> N;
  int n = sumDigit(N);

  if(N%n == 0) cout << "Yes" << endl;
  else cout << "No" << endl;
  
}


Measured memory_bytes: 512
N = int(input())
S = input()


def z_algorithm(s):
    n = len(s)
    lcpls = [0] * n  # Longest common prefix lengths
    lcpls[0] = n

    l = r = 1
    while l < n:
        while (r < n) and (s[r - l] == s[r]):
            r += 1

        if l == r:
            l += 1
            r += 1
            continue

        lcpls[l] = r - l

        k = 1
        while (l + k < r) and (lcpls[k] < r - l - k):
            lcpls[l + k] = lcpls[k]
            k += 1
        l += k

    return lcpls


ans = 0
for i in range(N):
    ns = S[i:]
    z_array = z_algorithm(ns)
    v_array = [min(i, z) for i, z in enumerate(z_array)]
    ans = max(ans, max(v_array))


print(ans)


Measured memory_bytes: 61788
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll gg=26;
	string res="";

/*ll pw26(ll n){

    ll k=26;
    while(1){

        if(k*26>n)
            break;
        k*=26;
    }
    return k;
}*/
void solve(ll n){

    if(n<=26){
        if(n==26)
            res='z'+res;
        else
            res=char(96+n)+res;

        return;
    }

	ll mod=n%gg;
	if(mod==0)
		res='z'+res;
	else
		res=char(96+(n%26))+res;

    /*if(mod==0){
        n=n-pw26(n);
        solve(n);
    }
	else{
        n=n-mod;
	    solve(n/26);
	}*/
	n-=mod;
	n/=26;
	if(mod==0)
        n--;
	solve(n);
}
int main(){

	ll n; cin>>n;
	/*n=0;
	for(ll i=1;;i++){
        if(n+pow(gg,i)>1000000000000001)
            break;
        n=n+pow(gg,i);
	}
	cout<<n<<endl;*/
	solve(n);
	cout<<res;
}


Measured memory_bytes: 3544
#include <bits/stdc++.h>
       
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main() {
  int N;
  cin >> N;
  map<string, int> h;
  for (int i = 0; i < (int)N; ++i) {
    string S;
    cin >> S;
    h[S] += 1;
  }
  int m = 0;
  for (auto& p : h) chmax(m, p.second);

  set<string> ans;
  for (auto& p : h)
    if (p.second == m) ans.insert(p.first);

  for (string s : ans) cout << s << endl;

  return 0;
}


Measured memory_bytes: 34560
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
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 int INF=1001001001;
vector<pair<int64_t,int64_t>>prime_factorize(int64_t x){
  vector<pair<int64_t,int64_t>>p;
  for(int64_t i=2;i*i<=x;i++){
    int cnt=0;
    if(x%i==0){
    while(x%i==0){cnt++;x/=i;}
    p.push_back(make_pair(i,cnt));
    }
  }
  if(x!=1){p.push_back(make_pair(x,1));}
  return p; 
}

int main() {
  double N;
  cin>>N;
  vector<double>a(N);
  double sum=0;
  for(int i=0;i<N;i++){
    cin>>a[i];
    sum+=a[i];
  }
  double m=sum/N;
  double dis=9999999;
  for(int i=0;i<N;i++){
    if(dis>abs(a[i]-m)){dis=abs(a[i]-m);}
  }
  for(int i=0;i<N;i++){
    if(abs(a[i]-m)==dis){cout<<i<<endl;return 0;}
  }
  return 0;
}

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

using namespace std;

int main()
{
    long long n, i, k;
    string S;
    cin >> n >> k >> S;
    for(i=0; i<n; i++)
    {
        if(i!=k-1) cout << S[i];
        else
        {
            if(S[i]=='A') cout << 'a';
            if(S[i]=='B') cout << 'b';
            if(S[i]=='C') cout << 'c';
        }
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 256
N,x,*a = map(int, open(0).read().split())

if sum(a) == x:
  print(N)
  exit()
  
cnt = 0
for i, a_ in enumerate(sorted(a)):
  x -= a_
  if 0 <= x:
    cnt += 1
  else:
    break
print([cnt,cnt-1][0<x])

Measured memory_bytes: 3060
MOD_NUM = 1000000007
N, M = map(int, input().split())
alist = [int(input()) for _ in range(M)]
cases = [1] + [0 for _ in range(N)]
for a in alist:cases[a] = None

for i in range(1,N+1):
  if cases[i] is None:continue
  if cases[i-1] is not None:cases[i] += cases[i-1] 
  if i >= 2 and cases[i-2] is not None: cases[i] += cases[i-2]
print(cases[-1]%MOD_NUM)  

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

#define ll long long

const int maxn = 350;

int N,K;
double sum=0;

int main(){
    cin>>N>>K;
    FOR(i,1,N){
        int t=1,cnt=0;
        while(i*t<K)t*=2,cnt++;
        //cout<<t*i<<endl;
        sum+=1/((double)t*(double)N);
    }
    printf("%.12lf\n",sum);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int , int> P;
typedef pair<ll, ll> PL;
const int INT_INF = 2147483646;
const ll LL_INF = 9223372036854775807;

bool SecondCompare(const pair<int,int> &a,const pair<int,int> &b)
{
       return a.second<b.second;
}
 
bool SecondCompareDes(const pair<int,int> &a,const pair<int,int> &b)
{
       return a.second>b.second;
}
 
ll n,h,w;
ll a,b;
string s;
ll ans;
int main(){
    cin >> n >> h >> w;
    for(int i = 0; i < n; i++){
           cin >> a >> b;
           if(a >= h && b >= w)     ++ans;
    }
    cout << ans << endl;
}

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

constexpr int64_t INF = 1e18;
constexpr int D = 365;
constexpr int N = 26;
int c[N];
int s[D][N];
int last[N];
int t[D];

void input() {
	int _d; cin >> _d;
	for(int i = 0; i < N; ++i) {
		cin >> c[i];
		last[i] = -1;
	}
	for(int i = 0; i < D; ++i) {
		for(int j = 0; j < N; ++j) {
			cin >> s[i][j];
		}
	}
}

void greedy() {
	for(int i = 0; i < D; ++i) {
		int64_t loss = 0;
		for(int j = 0; j < N; ++j) {
			loss += c[j] * (i - last[j]);
		}
		int64_t maxi = -INF;
		int midx = 0;
		for(int j = 0; j < N; ++j) {
			int64_t los = loss - c[j] * (i - last[j]);
			if(s[i][j] - los > maxi) {
				maxi = s[i][j] - los;
				midx = j;
			}
		}
		last[midx] = i;
		t[i] = midx;
	}
}

int64_t calc() {
	for(int i = 0; i < D; ++i) {
		cin >> t[i];
		--t[i];
	}
	int64_t ans = 0;
	for(int i = 0; i < D; ++i) {
		last[t[i]] = i;
		ans += s[i][t[i]];
		for(int j = 0; j < N; ++j) {
			int64_t loss = c[j] * (i - last[j]);
			ans -= loss;
		}

	}
}

void output() {
	for(int i = 0; i < D; ++i) {
		cout << t[i] + 1 << '\n';
	}
}

int main() {
	input();
	greedy();
	output();
	return 0;
}


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

int main()
{
  vector<int> a(4);
  cin >> a[0] >> a[1] >> a[2] >> a[3];
  sort(begin(a), end(a));
  cout << (a[0] == 1 && a[1] == 4 && a[2] == 7 && a[3] == 9 ? "YES" : "NO") << endl;
}


Measured memory_bytes: 888