akhauriyash/Code-Regression huggingface dataset:
//Name: Saizo
//Level: 1
//Category: やるだけ
//Note:

/**
 * 入力を舐めながら、増加と減少それぞれについて最大値を管理する。
 *
 * オーダーは O(N)。
 */
#include <iostream>
#include <algorithm>

using namespace std;

bool solve() {
    int N;
    if(!(cin >> N)) return false;

    int prev = 0;
    int ansup = 0, ansdown = 0;
    for(int i = 0; i < N; ++i) {
        int h;
        cin >> h;
        if(i > 0) {
            const int d = h - prev;
            if(d > 0) ansup = max(ansup, d);
            else ansdown = max(ansdown, -d);
        }
        prev = h;
    }
    cout << ansup << ' ' << ansdown << endl;
    return true;
}

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

    int T;
    cin >> T;
    while(T--) solve();
    return 0;
}

Measured memory_bytes: 1196
#include <bits/stdc++.h>
using namespace std;
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; }
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MOD (1000000007)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1}; // 移動方向

int n,m;
int a[5001], b[5001];

void input(){
    cin >> n >> m;
    for(int i=0;i<m;i++){
        cin >> a[i] >> b[i];
        a[i]--;
        b[i]--;
    }
}

struct UnionFind{
  vector<int> par,r;

  UnionFind(int N){
  	par.resize(N);
  	r.resize(N);
  	init(N);
  }

  void init(int N){
    for(int i = 0; i < N; i++) par[i] = i;
    for(int i = 0; i < N; i++) r[i] = 0;
  }

  int find(int x){
    if(par[x] == x) return x;
    else return find(par[x]);
  }

  void unite(int x,int y){
    x = find(x);
    y = find(y);
    if(r[x] < r[y]){
      par[x] = y;
    }else{
      par[y] = x;
      if(r[x] == r[y]) r[x]++;
    }
  }

  bool same(int x,int y){
  	return find(x) == find(y);
  }
};

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    input();
    int cnt = 0;
    for(int i=0;i<m;i++){ //どこの辺を切るか
        UnionFind tree(n);
        for(int j=0;j<m;j++){
            if(i!=j && !tree.same(a[j], b[j])) tree.unite(a[j], b[j]); //i==jのとき連結しない
        }
        vector<int> rec;
        for(int j=0;j<n;j++){
             if(tree.par[j] == j) rec.push_back(tree.par[j]);
        }
        if(rec.size() > 1) cnt++;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
let f g s = let a = String.(Array.init (length s) @@ get s) in Array.(sort g a; String.init (length a) @@ get a)
let s = f compare @@ read_line ()
let t = f (fun x y -> compare y x) @@ read_line ()
let _ = print_endline @@ if s < t then "Yes" else "No"

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

int main() {
  int n, m; cin >> n >> m;
  vector<int> s(m), c(m);
  rep(i, m) cin >> s[i] >> c[i];
  for (int i = 0; i < 1000; i++) {
    string x = to_string(i);
    bool ok = x.size() == n;
    rep(j, m) {
      ok &= x[s[j] - 1] == c[j] + '0';
    }
    if (ok) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> d(n);
  
  for(int i = 0; i < n; i++) {
  	cin >> d.at(i);
  }
  
  sort(d.begin(), d.end());
  
  cout << d.at(n/2) - d.at(n/2 -1) << endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main(void){
  int n,x,m,a=0,b=1001;
  cin>>n>>x;
  for(int i=0; i<n; i++){
      cin>>m;
      a=a+m;
      b=min(b,m);
  }
  if(a==x) cout<<n<<endl;
  else cout<<n+((x-a)/b)<<endl;
       return 0;
    
}
   



Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define all(x) (x).begin(), (x).end()
#define in(x, l, r) (ll)(l) <= (x) && (x) < (ll)(r)

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

Measured memory_bytes: 3620
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }

void _main() {
  int ab, bc, ca;
  cin >> ab >> bc >> ca;

  int ans = (ab * bc) / 2;
  cout << ans << "\n";
}

Measured memory_bytes: 256
x1, y1, x2, y2 = map(int, input().split())

x4 = x1 + y1 - y2
y4 = y1 - x1 + x2
x3 = x2 + y1 - y2
y3 = y2 - x1 + x2
print(x3, y3, x4, y4)

Measured memory_bytes: 2940
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

H, W = map(int, input().split())

grid = [[v for v in input()[:-1]] for _ in range(H)]

Q = []
cnt = 0
for i in range(H):
    for j in range(W):
        if grid[i][j] == "#":
            Q.append([i, j])
            cnt += 1

DX = [-1, 1, 0, 0]
DY = [0, 0, -1, 1]
d = 0
while cnt < H*W:
    d += 1
    tmp = []
    for sx, sy in Q:
        for x, y in zip(DX, DY):
            new_x = sx+x
            new_y = sy+y
            if 0 <= new_x < H and 0 <= new_y < W:
                if grid[new_x][new_y] == ".":
                    grid[new_x][new_y] = "#"
                    tmp.append([new_x, new_y])
                    cnt += 1
            else:
                continue
    Q = tmp

print(d)


Measured memory_bytes: 172692
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include <deque>
#include <set>
using namespace std;
#define MOD 1000000007
#define MOD2 2000000014
#define LONG long long
long long kaizyo(int N);
long long P(int N, int M);
long long pow(int a, int n) {
	long long result = 1;
	for (int i = 0; i < n; i++) {
		result *= a;
		result = result % MOD;
	}
	return result;
}
int main()
{
	int N;
	cin >> N;

	vector<LONG>A(N);
	LONG sum = 0;
	LONG sum2 = 0;
	int b = 0;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
		sum += A[i];
		sum2 += ((A[i] * A[i])) % MOD2;
	}
	sum = sum % MOD2;
	sum = (sum * sum)%MOD2;
	sum2 = sum2 % MOD2;
	if (sum < sum2) {
		sum += MOD2;
	}



	LONG result = ((sum - sum2)/2);
	cout << result % MOD;
	return 0;
}
long long kaizyo(int N) {
	long long result = 1;
	for (int i = 2; i <= N; i++) {
		result *= i;
		result = result % MOD;
	}
	return result;
}
long long P(int N, int M) {
	long long result = 1;
	for (int i = (N - M + 1); i <= N; i++) {
		result *= i;
		result = result % MOD;
	}
	return result;
}


Measured memory_bytes: 4844
#include <bits/stdc++.h>
using namespace std;
#define __ <<" "<<
#define ___ <<" "
#define bash push_back
#define ALL(x) x.begin(),x.end()
#define int long long

struct IoSetup {
    IoSetup() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout <<fixed<<setprecision(12);
        cerr <<fixed<<setprecision(12);
    }
}IoSetup;

typedef long long ll;
typedef pair < int , int >  pii;
static constexpr const signed int INF = 0x3f3f3f3f;
static constexpr const signed long long LINF = 0x3f3f3f3f3f3f3f3fLL;
static constexpr const signed int SMOD = 1000000007;
static constexpr const signed int NMOD = 998244353;
static constexpr const signed int dx[]={1,0,-1,0,1,1,-1,-1};
static constexpr const signed int dy[]={0,-1,0,1,-1,1,-1,1};

inline bool inside(int x,int y,int w,int h){return (x>=0 && y>=0 && x<w && y<h);}
template<class T>bool chmax(T &a, const T &b){return(a=max(a,b))==b;}
template<class T>bool chmin(T &a, const T &b){return(a=min(a,b))==b;}
inline int qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}

int n;
int m;
int a[100100];
ll t = 1, s;;
signed main() {

    cin >> n >> m;

    for(int i = 0; i < n; i++) {
        cin >> a[i];
        if(!i) s = a[i];
        t = t/__gcd(t, a[i]/2)*a[i]/2;
        s = __gcd(s, a[i]);
    }

    cout << m/t - m/(t/__gcd(t, s)*s) << endl;
    
    return 0;
}



Measured memory_bytes: 1024
class UnionFind():
    def __init__(self,n):
        self.n=n
        self.par=[i for i in range(n)]
        self.size=[1]*n
    def find(self,x):
        if x==self.par[x]:
            return self.par[x]
        else:
            self.par[x]=self.find(self.par[x])
            return self.par[x]
    def unite(self,x,y):
        x=self.find(x)
        y=self.find(y)
        if x==y:
            return
        if self.size[x]>self.size[y]:
            self.size[x]+=self.size[y]
            self.par[y]=x
        else:
            self.size[y]+=self.size[x]
            self.par[x]=y

import sys
input=sys.stdin.buffer.readline
n=int(input())

x_list=[]
y_list=[]

for i in range(n):
    x,y=map(int,input().split())
    x_list.append((x,i))
    y_list.append((y,i))
x_list.sort()
y_list.sort()
edges=[]

for i in range(1,n):
    edges.append((x_list[i][0]-x_list[i-1][0],x_list[i][1],x_list[i-1][1]))

    edges.append((y_list[i][0]-y_list[i-1][0],y_list[i][1],y_list[i-1][1]))

edges.sort()
uf=UnionFind(n)
ans=0
for e in edges:
    wt=e[0]
    x=e[1]
    y=e[2]
    if uf.find(x)==uf.find(y):
        continue
    ans+=wt
    uf.unite(x,y)
print(ans)



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

int main()
{
	int N;
	cin >> N;
	vector<int> A(N + 2, 0);
	for (int i = 0; i < N; i++) {
		cin >> A[i + 1];
	}
	int res = 1, last = -1;
	for (int i = 0; i < N + 2; i++) {
		if (A[i] == 0) {
			res = max(res, i - last);
			last = i;
		}
	}
	cout << res << endl;
	return 0;
}



Measured memory_bytes: 3096
import java.util.*;
 
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] si = new int[n];
		int sum = 0;
		for(int i=0; i<n; i++){
			si[i] = sc.nextInt();
			sum += si[i];
		}
		
		if(sum%10 != 0){
			System.out.println(sum);
			return;
		}else{
			Arrays.sort(si);
			for(int i=0; i<n; i++){
				if(si[i]%10 != 0){
					System.out.println(sum-si[i]);
					return;
				}
			}
		}
		System.out.println(0);
		return;
	}
}

Measured memory_bytes: 21844
def amida(n,m,s,l)
  a=Array.new(n) {|i| i+1}
  l.each do |i|
    i.each_with_index do |j,id|
      a[id],a[id+1]=a[id+1],a[id] if j==1
    end
  end
  return a[s-1]==m ? true : false
end

loop do
  break if gets.chomp=="0"
  n,m,s,d,l=$_.to_i,gets.to_i,gets.to_i,gets.to_i,[]
  d.times do
    l<<gets.chomp.split("").map(&:to_i)
  end
  if amida(n,m,s,l) then puts 0
  else
    bf=false
    ll= Marshal.load(Marshal.dump(l))
    l.each_with_index do |i, idi|
      i.each_with_index do |j, idj|
        if j==1 then
          ll[idi][[0,idj-1].max]=1
          ll[idi][idj]=1
          ll[idi][[n-2,idj+1].min]=1
        end
      end
    end
    ll.each_with_index do |i, idi|
      i.each_with_index do |j, idj|
        if j==0 then
          l3= Marshal.load(Marshal.dump(l))
          l3[idi][idj]=1
          puts "#{idi+1} #{idj+1}" if bf=amida(n,m,s,l3)
        end
        break if bf
      end
      break if bf
    end
    puts 1 unless bf
  end
end

Measured memory_bytes: 9068
/*input
1 100
*/
 

#include <bits/stdc++.h>

using namespace std;

#define ld long double
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define vpll vector < pair<long long,long long> >
#define fill(a,val)  memset(a,val, sizeof (a))
#define sort_unique(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define mp make_pair
#define pb push_back
#define f first
#define se second
#define all(cont) cont.begin(), cont.end()
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MAX   1e9
#define MIN  -1e9
typedef map<long long int, long long int> mpi;
typedef set<long long int> seti;
typedef multiset<long long int> mseti;
typedef priority_queue<long long int> pq;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define rep(i, n)    for(long long int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(ll i = a; i <= (n); ++i)
#define repD(i, a, n)  for(ll i = a; i >= (n); --i)
#define trav(a, x) for(auto& a : x)
#define tr(c,i) for(typeof((c).begin() i = (c).begin(); i != (c).end(); i++)
#define repn(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define PI 3.14159265
#define dbg(x) cerr << "\n" << (#x) << " = " << (x) << endl ;
//#define cerr if(false)cerr
 
#define mod 998244353
 
struct node{
    ll val;
};
struct Interval {int start, end;};
bool compare(struct node n1, struct node n2) {
    return (n1.val < n2.val);
}

 
 
 
int main() 
{
	ll k; ll x; cin>>k>>x;
	map <ll,ll> m;
	ll l=x-k; ++l; ll r=x+k; --r;
	while(l<=r && l>=-1000000 && l<=1000000){cout<<l<<" "; ++l;}
	cout<<endl;
	return 0;  
}






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

int main() {
    int n;
    cin >> n;
    vector<int> flag(100);
    for ( int i = 1; i <= n; i++)
    {
        int d;
        cin >> d;
        flag[d-1] = 1;
    }
    int out = 0;
    for(int i = 0; i <100; i++)
    {
        out += flag[i];
    }
    cout << out << endl;
}

Measured memory_bytes: 3624
#!/usr/bin/env python3
import sys

YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(S: str):
    if S=='AAA' or S=='BBB':
        print('No')
    else:
        print('Yes')
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    solve(S)

if __name__ == '__main__':
    main()


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

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

    int n;
    cin >> n;
    string w[n];
    set<string> set_w{};
    for (int i = 0; i < n; ++i) {
        cin >> w[i];
        set_w.insert(w[i]);
    }

    if (set_w.size() != n) {
        cout << "No" << '\n';
        return 0;
    }
    char last_char = '0';
    for (const string &s: w) {
        if (last_char == '0') {
            last_char = s[s.length() - 1];
        } else if (last_char != s[0]){
            cout << "No" << '\n';
            return 0;
        } else {
            last_char = s[s.length() - 1];
        }
    }

    cout << "Yes" << '\n';

    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cerr << #x << ": " << x << endl
#define debug2(x, y) debug(x), debug(y)
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sq(x) ((x) * (x))

template<class T> T gcd(T a, T b){ return ((b == 0) ? a : gcd(b, a % b)); }

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	int x;
	cin >> x;
	if(x >= 30) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


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

const ll MOD = 1e9+7;

int main(){
	ll n;
	cin>>n;
	ll s[n];
	for(int i=0;i<n;i++)cin>>s[i];
	ll res = 0;
	sort(s,s+n);
	for(int i=0;i<n;i++){
		res += s[i];
	}
	if(res%10!=0){
		cout<<res<<endl;
		return 0;
	}
	int cnt=0;
	for(int i=0;i<n;i++){
		if(s[i]%10!=0){
			res -= s[i];
			cout<<res<<endl;
			return 0;
		}else{
			cnt++;
		}
	}
	if(cnt==n)cout<<0<<endl;
	/*ll tmp=0;
	for(int i=0;i<pow(2,n);i++){
		tmp=0;
		for(int j=0;j<n;j++){
			if((1&i>>j)==1)tmp+=s[j];
		}
		//cout<<tmp<<endl;
		if(tmp%10!=0)res=max(res,tmp);
	}*/


}


Measured memory_bytes: 256
MOD = 10 ** 9 + 7
N, M = map(int, input().split())


fact = [1] * (M+1)
for i in range(2, M+1): fact[i] = i * fact[i-1] % MOD

invfact = [1] * (M+1)
invfact[M] = pow(fact[M], MOD-2, MOD)
for i in range(M, 1, -1):
	invfact[i-1] = invfact[i] * i % MOD

def permute(n, k):
	return fact[n] * invfact[n - k] % MOD

def choose(n, k):
	return permute(n, k) * invfact[k] % MOD

total = pow(permute(M, N), 2, MOD)
add = -1

for i in range(1, N+1):
	total = (total + add * choose(N, i) * permute(M, i) * pow(permute(M-i, N-i), 2, MOD)) % MOD
	add *= -1

print(total)


Measured memory_bytes: 95392
#include <iostream>
#include <map>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>
#include <stack>
using namespace std;

int main() {
	int N; cin >> N;
	vector<int>P(N);
	for (int i = 0; i < N; i++) {
		cin >> P.at(i);
	}
	sort(P.begin(), P.end());
	int const M = N / 2;
	N /= 2;
	N--;
	int const ans = P.at(M) - P.at(N);
	cout << ans << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <stdio.h>
using namespace std;

void swap(int *x,int *y){
int temp;
temp=*x;
*x=*y;
*y=temp;
}

int main() {
    int a, b, c;
    cin >> a;
    cin >> b;
    cin >> c;
    if (a > b)swap(&a, &b);
    if (b > c)swap(&b, &c);
    if (a > b)swap(&a, &b);
    printf("%d %d %d\n", a, b, c);
    return 0;
}


Measured memory_bytes: 3212
#include <bits/stdc++.h>
#include <fstream>
#define inputtxt() std::ifstream in("input.txt"); std::cin.rdbuf(in.rdbuf())
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define foreach(e, v) for (auto e : v)
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
#define collect(arr, size) rep(i,size) cin >> arr[i];

int main(){
    int N,Q; string S;
    cin >> N >> Q >> S;
    vector<int> ACs(N+1);
    ACs[0] = 0; ACs[1] = 0;
    reps(i,1,N){
        if(S[i-2]=='A' && S[i-1]=='C'){
            ACs[i] = ACs[i-1] + 1;
        }else{
            ACs[i] = ACs[i-1];
        }
    }
    rep(q,Q){
        int l,r; cin >> l >> r;
        cout << ACs[r]-ACs[l] << endl;
    }
    return 0;
}

Measured memory_bytes: 1408
#include <iostream>

using namespace std;

long long N, A, B;
const long long MOD = 1000000007; 

long long modPow(long long a, long long n) {
	if (n == 0) return 1;
  	if (n % 2 == 0) {
    	return modPow(a, n / 2) * modPow(a, n / 2) % MOD;
    } else {
 		return modPow(a, n - 1) * a % MOD;   
    }
}

long long combo (long long n, long long a) {
	long long c = 1;
  	for (int i = 0; i < a; i++) {
    	c *= n - i;
      	c %= MOD;
      	c *= modPow(a-i, MOD - 2);
      	c %= MOD;
    }
  
  	return c % MOD;
}

int main() {
	cin >> N >> A >> B;
  	long long nComb = modPow(2, N) - 1;

  	long long aComb = combo(N, A);
  	long long bComb = combo(N, B);
  	printf("%lld",  (nComb - aComb - bComb + MOD + MOD) % MOD);
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<bitset>
#include<string>
#include<cmath>
#include<algorithm>
#include<stack>
#include<list>
#include<queue>
#include<map>
using namespace std;
#define rep(i,x) for(int i=0;i<x;i++)
int INF=1e9;
const long long mod=1e9+7;

int main(){
  int n,k; cin>>n>>k;
  if(k==1){
    cout<<0<<endl;
  }
  else{
    cout<<n-k<<endl;
  }
  return 0;
}

Measured memory_bytes: 892
n, a, b, c = map(int, input().split())
lst = [int(input()) for _ in range(n)]
target_lst = [a,b,c]

def nsin(X,n):
    if int(X/n):
        return nsin(int(X/n), n) +str(X%n)
    return str(X%n)

min_ans = 10 ** 100
for i in range(4**len(lst)):
    a = nsin(i,4)
    if len(a) < len(lst):
        a = '0' * (len(lst)-len(a)) + a
    a_lst,b_lst,c_lst = [], [], []
    for k, j in enumerate(a):
        if int(j) == 1:
            a_lst.append(lst[k])
        elif int(j) == 2:
            b_lst.append(lst[k])
        elif int(j) == 3:
            c_lst.append(lst[k])
    if a_lst == [] or b_lst == [] or c_lst == []:
        ans = 10**100
    else:
        a_pt = abs(target_lst[0]-sum(a_lst)) + (len(a_lst) - 1) * 10
        b_pt = abs(target_lst[1]-sum(b_lst)) + (len(b_lst) - 1) * 10
        c_pt = abs(target_lst[2]-sum(c_lst)) + (len(c_lst) - 1) * 10
        ans = a_pt + b_pt + c_pt
    if min_ans > ans:
        min_ans = ans
        
print(min_ans)

Measured memory_bytes: 3064
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda:sys.stdin.readline().rstrip()
def resolve():
    n=int(input())
    XY=[None]*n
    for i in range(n):
        a=int(input())
        S=[None]*a
        for j in range(a):
            S[j]=tuple(map(int,input().split()))
        XY[i]=S

    ans=0
    for U in range(1<<n):
        flag=True
        for i in range(n):
            if((U>>i)&1==0): continue
            for x,y in XY[i]:
                x-=1
                if((U>>x)&1)!=y:
                    flag=False
        if(flag):
            ans=max(ans,bin(U).count('1'))

    print(ans)
resolve()

Measured memory_bytes: 41580
#include<bits/stdc++.h>
//#define int long long
#define loop(i, a, b) for(int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
#define all(a) (a).begin(),(a).end()
using namespace std;
const int MOD = 1e9 + 7, INF = 1e9;
using vi = vector <int>;
using vvi = vector <vi>;
//g++ -std==c++14
 
int main(){
    int h, w;
    cin >> h >> w;
    char yoko[26];
    rep(i, 26)yoko[i] = 'A' + i;
    string s_in;
    string ans = "";
    rep(i, h)rep(j, w){
        cin >> s_in;
        if(s_in == "snuke"){
            ans += yoko[j];
            ans += to_string(i + 1);
        }
    }
    cout << ans << endl;
}

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


int main(){
    int N,M;
    cin >> N >> M;
    vector<int> problems(N);
    vector<int> penalty(N);
    int AC = 0;
    int WA = 0;
    rep(i,M){
        int p;
        string S;
        cin >> p >> S;
        p--;                    // 0-based index
        bool isAC = problems[p];

        if (!(isAC)) {
            if (S == "AC"){
                AC ++;
                problems[p] = 1;
                WA += penalty[p];
            } else {
                penalty[p]++;
            }
        }
    }  
    cout << AC << " " << WA << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main(){
  string S;
  int A[26]={0};
  int f=0;
  cin>>S;
  for(int i=0;i<S.size();i++) A[S[i]-'a']++;
  for(int i=0;i<S.size();i++){
    if(A[i]!=0&&A[i]!=1){
      f=1;
      break;
    }
  }
  cout<<(f?"no":"yes")<<endl;
}

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

using namespace std;

static const int N = 100;
int n, m[N][N];


int main()
{
	cin >> n;

	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < n; ++j) m[i][j] = 0;
	}

	for (int i = 0; i < n; ++i) {
		int u, d; cin >> u >> d;
		for (int j = 0; j < d; ++j) {
			int v; cin >> v;
			m[u - 1][v - 1] = 1;
		}
	}

	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < n; ++j){
			if (j) cout << " ";
			cout << m[i][j];
		}
		cout << endl;
	}

}

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

int main() {
    int x;
    cin >> x;
    for (int a = -118; a < 120; a++) {
        for (int b = -118; b < 120; b++) {
            if (pow(a,5) - pow(b,5) == x) {
                printf("%d %d\n", a, b);
                goto end;
            }
        }
    }
    end:
    return 0;
}

Measured memory_bytes: 4148
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define ULL unsigned long long
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define pll pair<LL,LL>
#define x first
#define y second
#define pi acos(-1)
#define sqr(x) ((x)*(x))
#define pdd pair<double,double>
#define MEMS(x) memset(x,-1,sizeof(x))
#define MEM(x) memset(x,0,sizeof(x))
#define less Less
#define EPS 1e-4
#define arg ARG
#define cpdd const pdd
#define rank Rank
#define KK 500
#define N 100005
int dp[100005][2];
vector<int> v[100005];
void dfs(int x,int f){
    dp[x][1]=0;
    dp[x][0]=0;
    for(auto it:v[x]){
        if(it!=f){
        dfs(it,x);
        dp[x][0]=max(dp[x][0]+dp[it][0],dp[x][1]+dp[it][1]+1);
        dp[x][1]+=dp[it][0];
        }
    }
}
int main(){
    int n;
    scanf("%d",&n);
    if(n%2==1){
        printf("First\n");
        return 0;
    }
    else{
        for(int i = 1;i<n;i++){
            int x,y;
            scanf("%d %d",&x,&y);
            v[x].pb(y);
            v[y].pb(x);
        }
        dfs(1,0);
        if(dp[1][0]==n/2){
            printf("Second\n");
        }
        else{
            printf("First\n");
        }
    }
}
/*
1-n 0
2-n 1
3-n 2
-3 0
-2 1
-1 2
0 3
*/
/*
1 0
2 -10  01
3 -20 -1 1 0 2


*/
/*

k*cnt[i]-k*cnt[j]=i-j;
k*cnt[i]-i=k*cnt[j]-j
1 2 3 4 5
1 2 3 4 5 6
1 2 3 4 5    3
1 2 3 5 6    4 
1 2 3 4 6
3
0 1 2
0 2 2.5

1 2 3 4 5
1 2 3 4 5
1 3
1 4
1
*/
/*
AC
AGCG
AGCGU
AT
*/

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

int main(){
    string s; cin >> s;
    reverse(s.begin(), s.end());
    //cout << "reverese is " << s << endl;
    int now=0;
    while(now<s.size()-1){
        bool judge=false;
        if (s.substr(now, 5)=="maerd" || s.substr(now, 5)=="esare"){
            now+=5;
            judge=true;
        } else if (s.substr(now, 7)=="remaerd"){
            now+=7;
            judge=true;
        } else if (s.substr(now, 6)=="resare"){
            now+=6;
            judge=true;
        }
        //cout << "now is " << now << endl;
        if (!judge) break;
    }
    if (now==s.size()) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<cmath>

int main(){
  int A,B,C;
  int res = 0;
  std::cin >> A >> B >> C;
  
  if(A+B>=C){
    res = B+C;
  }else{
    res = B*2+std::min(C-B,A)+1;
  }
  
  std::cout << res << std::endl;
  return 0;
}

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

using namespace std;

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

typedef long long ll;
typedef unsigned long long ull;

ll i,j,k,n,t,a[100003];
ll ma,mi;

int main(){
	scanf("%lld", &n);
	for(i=0;i<n;i++)
		scanf("%lld", a+i);
	if(a[n-1]>2){
		puts("-1");
		return 0;
	}
	mi = 2;
	ma = 3;
	for(i=n-2;i>=0;i--){
		if(a[i]!=a[i+1]){
			j = mi/a[i];
			if(mi%a[i]>0)
				j +=1;
			j*=a[i];
			if(j>ma){
				puts("-1");
				return 0;
			}
			mi = j;
			if(mi+a[i]-1>ma)
				ma=mi+a[i]-1;
			else
				ma += a[i]-1-ma%a[i];
		}
	}
	printf("%lld %lld\n", mi, ma);
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define sz(arr) (int)arr.size()

using namespace std;

int main() {
  string A, x, C;
  cin >> A >> x >> C;

  string out = "";
  out += A.at(0);
  out += x.at(0);
  out += C.at(0);
  cout << out << endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<math.h>
int main()
{
	int a, b, c, d, e, f, g, h, i, p;
	char z[4];
	for (i = 0; i < 4; i++)scanf("%c", &z[i]);
	if (z[0] == z[1] && z[1] == z[2] && z[2] == z[3])printf("No\n");
	else if (z[0] == z[1] && z[2] == z[3] || z[0] == z[2] && z[1] == z[3] || z[0] == z[3] && z[1] == z[2])printf("Yes\n");
	else printf("No\n");

	return 0;
}

Measured memory_bytes: 128
if __FILE__ == $0
  line = gets
  words = line.split
  wordCount = Hash.new(0)
  words.each do |w|
    wordCount[w] += 1
  end
  hinsyutu = wordCount.sort_by{|key, value| -value}[0][0]
  most_length = words.max_by{|w| w.length}
  puts "#{ hinsyutu } #{ most_length }"
end

Measured memory_bytes: 6112
#include<cstdio>
#include<vector>
#include<string>
#include<iostream>

using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int a;
  string s;
	
  cin>>a;
  cin.ignore(); //改行読み飛ばし
  getline(cin,s);
  
  if(a>=3200){
    cout<<s<<"\n";
  }
  else{
    cout<<"red"<<"\n";
  }
	
  return 0;
}

Measured memory_bytes: 256
import qualified Data.IntMap as M

main :: IO ()
main = do
  n <- readLn :: IO Int
  ns <- map read . words <$> getLine :: IO [Int]
  let m = makeMap $
          filter (\a -> a >= 0 && a <= 100000) $
          concatMap (\a -> [a-1, a, a+1]) ns
--  print m
  print $ solve m

makeMap :: [Int] -> M.IntMap Int
makeMap = foldr (\a b ->
                 case M.lookup a b of
                   Nothing -> M.insert a 1 b
                   Just k -> M.insert a (k+1) b) M.empty

solve :: M.IntMap Int -> Int
solve m = snd $
          M.foldWithKey (\k a (k', b) ->
                            if b < a
                            then (k, a)
                            else (k', b)) (-1, -1) m


Measured memory_bytes: 34172
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<algorithm>
#include<map>
#include<set>
#include<cmath>
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;

int gcd(int x, int y) {
	if (y % x == 0) return x;
	else return gcd(y % x, x);
}

int main() {
	string s;
	cin >> s;
	if (s[0] == '7' || s[1] == '7' || s[2] == '7') {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}


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

using namespace std;

int main (void) {
  int A, B, C;
  cin >> A >> B >> C;
  int cand1 = abs(A-B);
  int cand2 = abs(B-C);
  int cand3 = abs(C-A);
  int ans1 = cand1 + cand2;
  int ans2 = cand2 + cand3;
  int ans3 = cand3 + cand1;
  int ans = min(ans1, min(ans2, ans3));
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
import sys
input = lambda: sys.stdin.readline().rstrip()

def main():
    x, k, d = map(int, input().split())
    x = abs(x)
    cnt = x // d
    point = x % d
    if x == 0:
        if k % 2 == 0:
            point = 0
        else:
            point = d
    else:
        # 最小値まで行く回数がKより多い場合
        if cnt > k:
            point = x - k * d
        # Kより少ないときは
        else:
            # もう一回移動して最小値を確かめる
            if point == 0:
                if (k - cnt) % 2 == 0:
                    point = 0
                else:
                    point = d
                print(point)
                exit()
            else:
                if abs(point - d) < abs(point):
                    point = point - d
                    cnt += 1
            # k-cntが偶数の時はそのまま、奇数の時は一回逆方向にdだけ進む
            if (k - cnt) % 2 == 0:
                pass
            else:
                point = min(abs(point - d), abs(point + d))
    print(abs(point))

if __name__ == '__main__':
    main()


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

#define int long long
#define ct(n) cout << n << endl;
#define cts(n) cout << n << " ";
#define cte cout << endl;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define repo(i,o,n) for(int i=o;i<n;i++)
#define repm(i,n) for(int i=n-1;i>=0;i--)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end());
#define vdelete(v) (v).erase(unique(all(v)), (v).end());
#define vcopy(v1,v2) copy((v1).begin(), (v1).end(), back_inserter((v2)));
#define pb(n) push_back(n);

char c[2][3];

main() {
    rep(i,2) rep(j,3) cin >> c[i][j];
    if (c[0][0] == c[1][2] && c[0][1] == c[1][1] && c[0][2] == c[1][0]) ct("YES")
    else ct("NO")
}









Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
typedef long long ll;

int dim(ll a){
  int count=1;
  while(a>9){
    a=a/10;
    count++;
  }
  return count;
}//桁数を返す

int minrev(int a,int b){
  if(a>b){
    return a;
  }
  else{
    return b;
  }
}

int main(){
  ll N,a,b;
  int min=50000;
  scanf("%lld",&N);
  int num=0;
  for(int i=sqrt(N);i>0;i--){
    a=i;
    b=N/a;
    if(a*b==N){
      num=minrev(dim(a),dim(b));
      if(num<min){
      //printf("%lld %lld\n",a,b);
      //printf("%d %d\n",dim(a),dim(b));
      min=num;
      }
    }
  }
  printf("%d",min);
}

Measured memory_bytes: 128
n = int(input())
restaurants = []
for i in range(n):
    s, p = list(input().split())
    restaurants.append([s, int(p), i + 1])
restaurants.sort(key=lambda x: x[1], reverse=True)
restaurants.sort(key=lambda x: x[0])
for i in range(n):
    print(restaurants[i][2])

Measured memory_bytes: 62816
#include <algorithm>
#include <iostream>
#include <vector>
#include <numeric>
#include <string>
#include <stdio.h>
#include <set>
#include <iomanip>
using namespace std;
 
int main(){
    int N;
    cin >> N;
    if (N%1000!=0){
        cout << (N / 1000 + 1) * 1000 - N  << endl;
    }else{
        cout << 0 << endl;
    }
    return 0;
}

Measured memory_bytes: 3632
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<queue>

using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int> >;
using pii = pair<int, int>;
using ppi = pair<pii, int>;

int f_dir[2][4] = {{-1, 0, 1, 0}, {0, 1, 0, -1}}; //↑→↓←
int e_dir[2][8] = {{-1, -1, -1, 0, 0, 1, 1, 1}, {-1, 0, 1, -1, 1, -1, 0, 1}};
bool is_in_field(int y, int x, int h, int w){
  return (y >= 0 && y < h && x >= 0 && x < w);
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int ti = clock();
  // start-----------------------------------------------
  string s; cin >> s;
  int a = 0;
  int m = 0;
  if(s[0] == 'R'){
    a++;
  }
  m = max(a, m);
  if(s[1] == 'R'){
    a++;
  }
  else a = 0;
  m = max(a, m);
  if(s[2] == 'R'){
    a++;
  }
  else a = 0;
  m = max(a, m);

  cout << m << endl;
  // end-----------------------------------------------
  // cerr << 1.0 * (clock() - ti) / CLOCKS_PER_SEC << endl;
}


Measured memory_bytes: 3684
#pragma once
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <numeric>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1000000007;
const int MAX_V = 201;
int now = 0;
int deco[1000];

int c[30];
ll dp[52][2510];
void Solve() {
	int n;
	cin >> n;
	ll res = 0;
	for (size_t i = 1; i <= n; i++)
	{
		res += i;
	}
	cout << res << endl;
}
int main() {
	Solve();
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second

const int N=3700000;
const int INF=123456789;

int f[11];
int dp[2][N];

inline int get_idx(const vector<int> &a)
{
    int n = a.size();
    int ret=0;
    vector<bool> use(n,false);
    rep(i,n)
    {
        int ct=0;
        rep(j,a[i])if(!use[j]) ++ct;

        ret += ct*f[n-1-i];

        use[a[i]]=true;
    }
    return ret;
}

inline vector<int> get_vec(int n, int idx)
{
    vector<int> ret(n);
    vector<bool> use(n,false);
    rep(i,n)
    {
        int s = idx/f[n-1-i];
        int j=0,ct=0;
        while(1)
        {
            if(!use[j])
            {
                ++ct;
                if(ct==s+1) break;
            }
            ++j;
        }

        use[j]=true;
        ret[i]=j;
        idx -= s*f[n-1-i];
    }
    return ret;
}

int main()
{
    f[0]=1;
    for(int i=1; i<=10; ++i) f[i] = f[i-1]*i;

    int n;
    cin >>n;
    vector<int> a(n);
    rep(i,n)
    {
        cin >>a[i];
        --a[i];
    }

    rep(d,2)
    {
        int start = d?get_idx(a):0;
        fill(dp[d],dp[d]+N,INF);
        dp[d][start]=0;
        queue<int> que;
        que.push(start);
        while(!que.empty())
        {
            int now = que.front();
            que.pop();

            vector<int> x = get_vec(n,now);
            rep(i,n)for(int j=i+1; j<=n; ++j)
            {
                reverse(x.begin()+i, x.begin()+j);

                int nx = get_idx(x);
                if(dp[d][nx]>dp[d][now]+1)
                {
                    dp[d][nx] = dp[d][now]+1;
                    if(dp[d][nx]<4) que.push(nx);
                }

                reverse(x.begin()+i, x.begin()+j);
            }
        }
    }

    int ans=9;
    rep(i,N)if(dp[0][i]<INF && dp[1][i]<INF) ans=min(ans,dp[0][i]+dp[1][i]);

    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 32300
int_list = list(map(int, input().split()))

if (int_list[0] - int_list[4]) >= int_list[2] and int_list[2] >= int_list[4]:
    if (int_list[1] - int_list[4]) >= int_list[3] and int_list[3] >= int_list[4]:
        print("Yes")
    else:
        print("No")
else:
    print("No")



Measured memory_bytes: 5596
#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#include<map>

#define PI 3.1415926535
using namespace std;

int main()
{
	string N;
	cin >> N;
	
	for(int n = 0; n < N.length(); n++){
		if(N.substr(n,1) == "7"){
			cout << "Yes" << endl;
			return 0;
		}
	}
 
	cout << "No" << endl;
	return 0;

}

Measured memory_bytes: 3596
#include "bits/stdc++.h"

using namespace std;

const int N = (int) 2e5 + 10;

int n;
int a[N];

int main(void) {
  cin >> n;
  int mx = 0, ndmx = 0;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    if (a[i] >= ndmx) {
      ndmx = a[i];
    }
    if (ndmx >= mx) {
      swap(ndmx, mx);
    }
  }
  for (int i = 1; i <= n; i++) {
    cout << (mx == a[i] ? ndmx : mx) << "\n";
  }
  return 0;
}



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

template<typename T>
T get_value(std::istream& is);

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

  string s;
  cin >> s;
  
  for (auto i{0}; i < s.size(); i += 2)
    cout << s[i];
  cout << '\n';

  return 0;
}

template<typename T>
inline T get_value(std::istream& is)
{
  T v;
  is >> v;
  return v;
}


Measured memory_bytes: 592
#include<iostream>
#include<map>
#include<string>
#include<algorithm>
using namespace std;

int main()
{
    multimap<string,int> m;                  //通常のmapはkeyに対して1つの値を持つ。multimapになると、keyにいくつもの値を持たせることが出来る。
    int n, q, x;
    string k, s;

    cin >> n;

    for( int i = 0; i < n; i++ )
    {
        cin >> q >> k;

        if( q == 0 )
        {
            cin >> x;
            m.insert( make_pair( k, x ) );
        }
        else if( q == 1 )
        {
            multimap<string,int>::iterator itr = m.find(k);
            if( itr != m.end() )
            {
                for(; itr != m.upper_bound(k); itr++ )
                    if( itr -> first == k )
                        cout << itr -> second << endl;
            }
        }
        else if( q == 2 )
            m.erase(k);
        else
        {   
            cin >> s;
            multimap<string,int>::iterator l = m.lower_bound(k), r = m.upper_bound(s);
            for( ; l != r; l++ )
                cout << l -> first << " " << l -> second << endl;                   // mapのkeyと対応する値にアクセスする場合、アロー演算子を用いる
        }                                                                               // (*l).first, (*l).secondというアクセス方法もある

    }
    return 0;
}


Measured memory_bytes: 24876
//====== begin of bisma c++ template===========
#include<bits/stdc++.h>
#include <assert.h>
using namespace std;
#define rep(a,b,c) for(int a=b;a<=c;a++)
#define repn(a,b,c) for(int a=b;a>=c;a--)
#define ll long long 
#define sum(a,b) a=a+b
#define mem(a, b) memset(a, (b), sizeof(a))


//=======binarysearch===========
int bs(vector<long long>&a,int que){
 auto it=lower_bound(a.begin(),a.end(),que);
 if(*it==que){
    return it-a.begin();
 }
 return -1;
}
//========binarysearch=========



//=======SUBSET WITH BRUTEFORCE=============
void subsets(string S, int n) {
     int nSub = 1<<n; 
     for(int i=0; i<nSub; i++){
     	  cout<<"{ ";//optional
          for(int k=0; k<n; k++){
               //if the k-th bit is set
               if( (1<<k) & i){
                    cout<<S[k]<<" ";
               } 
          }
          cout<<"}\n"; //optional
     }
}
//======SUBSET WITH BRUTE FORCE================


//======permuatate all ==================
void permutate(){
int n,x;
cin>>n;

vector<int> permutation;
for (int i = 0; i < n; i++) {
	cin>>x;
permutation.push_back(x);
}
do {
 rep(i,0,n-1) cout<<permutation[i];
 cout<<endl;
} while (next_permutation(permutation.begin(),permutation.end()));

}
//====permuatate all======================


//====check prime =========================

bool prime(ll x){
	ll ans=0;

	if(x==1){
		return false;
	}

	for(ll i=2;i<=sqrt(x);i++){
		if(x % i == 0){
			return false;
		}
	}

	return true;
}
//===check prime ========================


//======= the end of bisma c++ template ============


int main(){

string s;

cin>>s;

ll sum=0;

rep(i,0,s.size()-1) sum=sum+(ll)s[i]-'0';

ll ans=stoi(s);


if(ans%sum==0){

	cout<<"Yes";
}else{
	cout<<"No";
}
	
return 0;
}


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

#ifdef LOCAL
#include "../../dump.hpp"
#else
#define dump(...)
#endif

#define rep(i,n) for(ll i=0,i##_cond=(n);i<i##_cond;++i)
#define FOR(i,a,b) for(ll i=(a),i##_cond=(b);i<i##_cond;++i)
#define ROF(i,a,b) for(ll i=(a)-1,i##_cond=(b);i>=i##_cond;--i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend() //sortで大きい順
#define UNIQUE(v) v.erase(unique(all(v)),v.end())
#define SUM(a) accumulate(all(a),0)
#define sz(x) ((ll)(x).size())
#define pb push_back
#define fst first
#define snd second
#define mp make_pair

typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<ll,ll> pii;

const ll inf = 1ll<<62;
const ll mod = 1e9+7;

int main(){
#define int ll
  int n,m; cin >> n >> m;
  vi x(n);
  int a,b;
  rep(i,m){
    cin >> a >> b;
    a--; b--;
    x[a] = (x[a] + 1) % 2;
    x[b] = (x[b] + 1) % 2;
  }
  if(all_of(all(x),[](int z){return z == 0;})) cout << "YES\n";
  else cout << "NO\n";
}

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

using namespace std;

using ll = long long;

int main() {
    int K;
    cin >> K;
    ll s = 0;
    for (int i = 1; i <= K; i++)
        for (int j = 1; j <= K; j++)
            for (int k = 1; k <= K; k++)
                s += gcd(gcd(i, j), k);
    cout << s << endl;
}


Measured memory_bytes: 3636
/* #                          */

#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <deque>
#include <map>
#include <iomanip>
#include <cassert>
#include <cstdio>
#include <cmath>
#include <cstdint>
#include <cstring>
//#pragma warning(disable:4996)

using namespace std;


/** Type Define **/
typedef long long int           ll;
typedef pair<int, int>          pii;
typedef pair<ll, ll>            pll;
typedef vector<string>          vs;
typedef vector<bool>            vb;
typedef vector<int>             vi;
typedef vector<long long>		vl;
typedef vector<vi>              vvi;
typedef vector<vl>				vvl;
typedef vector<char>            vch;
#define		it(x)  x.begin() 
#define		all(x)  x.begin(), x.end()
#define		pb(x)   push_back(x)
constexpr int           inf = 0x3f3f3f3f;
constexpr long long 	INF = 9123456789123456789;
constexpr long long     MOD = 1000000007LL;
/*************************************************/

int main() {
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(12);
    cin.tie(nullptr);
    
    int n;
    cin >> n;
    vi a(n);
    bool ans(true);

    for (auto& x : a) {
        cin >> x;
        if (x & 1) continue;
        else {
            if (x % 3 == 0 || x % 5 == 0);
            else ans = false;
        }
    }

    if (ans)    cout << "APPROVED\n";
    else        cout << "DENIED\n";


    return 0;
}

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

char S[222222];

//	0	1	2	3	4	5	6	7	8
//	0	1	1	2	3	3	4	5	5
int main(){
	scanf("%s",S);
	int len=strlen(S);
	int i=0,j=0,ans=0;
	int fwd=0;
	while(i<len){
		//cerr<<i<<endl;
		while(S[i]==S[j]&&i<len){
			i++;
		}		
		int num=i-j;
		if(fwd){
			num--;
			ans++;
		}
		ans+=2*(num/3);
		if(num%3) ans++;
		if(num%3==2) fwd=1; else fwd=0;
		//cerr<<i<<"\t::\t"<<ans<<endl;
		j=i; 
	}

	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 384
#include<iostream>
using namespace std;
 
int main(){
    int n;
    cin >> n;
 
    int c[n], s[n], f[n];
    c[n-1] = s[n-1] = f[n-1] = 0;
    for(int i = 0; i < n-1; i++)  cin >> c[i] >> s[i] >> f[i];
 
    for(int i = 0; i < n-1; i++){
        int ans = 0;
        for(int j = i; j < n-1; j++){
            if(ans <= s[j])  ans = s[j];
            else            ans = (ans-s[j]+f[j]-1)/f[j]*f[j] + s[j];
            ans += c[j];
        }
        cout << ans << endl;
    }
 
    cout << 0 << endl;
 
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main()
{
	int i=0,j,a[1000],b[1000],ans[1000];
	char op[1000];
	while(1){
		scanf("%d %c %d",&a[i],&op[i],&b[i]);
		if(op[i]=='?')break;
		switch(op[i]){
		case'+':ans[i]=a[i]+b[i];break;
		case'-':ans[i]=a[i]-b[i];break;
		case'*':ans[i]=a[i]*b[i];break;
		case'/':ans[i]=a[i]/b[i];break;
		}
		i++;
	}
	for(j=0;j<i;j++)
	{
		printf("%d\n",ans[j]);
	}
	return 0;
}

Measured memory_bytes: 612
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int al[26]={},n=0;
    //string s;
    char c;
    
    while(cin>>c){
      //  cin>>c;
       if(c<=90 && c>=65) n = c -'A';
       else n = c - 'a';
       
        al[n]++;
        
    }
    
    for(int i=0;i<26;i++){
        cout<<char(i+'a')<<" "<<":"<<" "<<al[i]<<endl;
    }
    
    return 0;
    
}


Measured memory_bytes: 3092
#include <stdio.h>

typedef struct {
	int key, id;
} data;

void merge_sort(data x[], int n)
{
	static data y[500001] = {};
	if (n <= 1) return;
	merge_sort(&(x[0]), n/2);
	merge_sort(&(x[n/2]), (n+1)/2);
	
	int i, p, q;
	for (i = 0, p = 0, q = n/2; i < n; i++) {
		if (p >= n/2) y[i] = x[q++];
		else if (q >= n) y[i] = x[p++];
		else y[i] = (x[p].key < x[q].key)? x[p++]: x[q++];
	}
	for (i = 0; i < n; i++) x[i] = y[i];
}

void add_BIT(int N, int BIT[], int i, int k)
{
	while (i <= N) {
		BIT[i] += k;
		i += (i & -i);
	}
}

int sum_BIT(int BIT[], int r)
{
	int sum = 0;
	while (r > 0) {
		sum += BIT[r];
		r -= (r & -r);
	}
	return sum;
}

int main()
{
	int i, N, Q, c[500001], l[500001], r[500001];
	scanf("%d %d", &N, &Q);
	for (i = 1; i <= N; i++) scanf("%d", &(c[i]));
	for (i = 1; i <= Q; i++) scanf("%d %d", &(l[i]), &(r[i]));
	
	data d[500001];
	for (i = 0; i < Q; i++) {
		d[i].key = l[i+1];
		d[i].id = i + 1;
	}
	merge_sort(d, Q);
	
	int k, right[500001], p[500001];
	for (i = 1; i <= N; i++) {
		right[i] = N + 1;
		p[i] = 0;
	}
	for (i = N, k = d[0].key; i >= k; i--) {
		if (p[c[i]] != 0) right[i] = p[c[i]];
		p[c[i]] = i;
	}
	
	int BIT[500001] = {}, ans[500001];
	for (i = 1; i <= N; i++) if (p[i] != 0) add_BIT(N, BIT, p[i], 1);
	for (i = 0; i < Q; i++) {
		for (; k < d[i].key; k++) {
			add_BIT(N, BIT, k, -1);
			if (right[k] != N + 1) add_BIT(N, BIT, right[k], 1);
		}
		ans[d[i].id] = sum_BIT(BIT, r[d[i].id]);
	}

	for (i = 1; i <= Q; i++) printf("%d\n", ans[i]);
	fflush(stdout);
	return 0;
}

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

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define ALL(v) (v.begin(),v.end())
#define COUT(x) cout<<(x)<<'\n'

int main(){
    int n;
    cin >> n;
    vector<ll> a(200010,0);
    ll t;
    REP(i,n-1){
        cin >> t;
        a[t]++;
    }
    FOR(i,1,n+1){
        COUT(a[i]);
    }
    return 0;
}

Measured memory_bytes: 4836