akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<algorithm>
using namespace std;
int ans=0,sum=0,pp[262144],dp[262144],m,h,n,tr[5000005],cnt=0,hd[262144];
int ch[2][5000005];
const int mod=1e9+7;
int pos,v,rt,inv[262144];
int M(int x){return x>=mod?x-mod:x;}
int mypow(int a,int b)
{
	int ans=1;
	while(b)
	{
		if(b&1)ans=1ll*ans*a%mod;
		a=1ll*a*a%mod;
		b>>=1;
	}
	return ans;
}
void ins(int p,int l,int r)
{
	tr[p]=M(tr[p]+v);
	//printf("%d %d\n",tr[p],p);
	if(l==r)return;
	int mid=(l+r)/2;
	if(pos<=mid)ch[0][p]=++cnt,ins(cnt,l,mid);
	else ch[1][p]=++cnt,ins(cnt,mid+1,r);
}
int mrg(int x,int y,int p,int l,int r)
{
	//printf("#%d %d %d %d %d %d %d %d %d\n",x,y,p,inv[p],r,tr[ch[0][x]],tr[ch[1][y]],tr[3],tr[4]);
	if(x==0||y==0)return x+y;
	tr[x]=M(tr[x]+tr[y]);
	sum=(1ll*sum+1ll*tr[ch[0][x]]*tr[ch[1][y]]%mod*inv[p])%mod;
	sum=(1ll*sum+1ll*tr[ch[1][x]]*tr[ch[0][y]]%mod*inv[p])%mod;
	//printf("%d\n",sum);
	int mid=(l+r)/2;
	ch[0][x]=mrg(ch[0][x],ch[0][y],2*p,l,mid);
	ch[1][x]=mrg(ch[1][x],ch[1][y],2*p+1,mid+1,r);
	return x;
}
void dfs(int p)
{
	if(2*p>n)
	{
		hd[p]=++cnt;
		pos=pp[p]-m+1;
		v=1ll*dp[p]*dp[pp[p]]%mod;
		ins(hd[p],1,m);
		return;
	}
	else
	{
		dfs(2*p);
		dfs(2*p+1);
	}
	sum=0;rt=p;
	hd[p]=mrg(hd[2*p],hd[2*p+1],1,1,m);
	ans=(1ll*ans+1ll*sum*inv[p])%mod;
}
int main()
{
	scanf("%d",&h);
	n=(1<<h)-1;m=(1<<(h-1));
	dp[1]=1;inv[1]=1;
	for(int i=2;i<=n;i++)dp[i]=1ll*dp[i/2]*i%mod,inv[i]=mypow(dp[i],mod-2),inv[i]=1ll*inv[i]*inv[i]%mod*i%mod;
	for(int i=m;i<=n;i++)
	{
		scanf("%d",&pp[i]);
		pp[i]=m+pp[i]-1;
	}
	dfs(1);
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 32976
require 'prime'
$prime_array = []
Prime.each(999999) {|num|
	$prime_array.push(num)
}


def judge_prime_with_index(num)
	if $prime_array.include?(num)
		return $prime_array.index(num) + 1
	end
	
	return nil
end

while input = gets
	n = input.strip.to_i
	count = 0
	n.downto(2) {|num|
		result = judge_prime_with_index(num)
		if result != nil
			count = result
			break
		end
	}
	puts count
end

Measured memory_bytes: 6988
def main():
    N, K = map(int, input().split())
    cnt = [0] * (N + 1)
    for i in range(K):
        input()
        a = list(map(int, input().split()))
        for x in a:
            cnt[x] += 1
        
    # print(cnt)
    print(sum([1 for n in cnt[1:] if n == 0]))


if __name__ == '__main__':
    main()

Measured memory_bytes: 9196
#include<bits/stdc++.h>
using namespace std;
int dfs(int **graph,int sv,bool *visited,int n)
{
    bool all_visited = true;
    for(int i = 1; i <= n; i++)
    {
        if(!visited[i])
        {
            all_visited = false;
            break;
        }
    }
    if(all_visited)
        return 1;
    int total = 0;
    for(int i = 1; i <= n; i++)
    {
        if(graph[sv][i] && !visited[i])
        {
            visited[i] = true;
            total = total + dfs(graph,i,visited,n);
            visited[i] = false;
        }
    }
    return total;
}
int main()
{
    int n,m,i,j;
    cin>>n>>m;
    int **graph = new int*[n + 1];
    for(i = 0; i <= n; i++)
    {
        graph[i] = new int[n + 1];
        for(j = 0; j <= n; j++)
            graph[i][j] = 0;
    }
    for(i = 1; i <= m; i++)
    {
        int f,s;
        cin>>f>>s;
        graph[f][s] = 1;
        graph[s][f] = 1;
    }
    bool visited[n + 1] = {};
    visited[1] = true;
    cout<<dfs(graph,1,visited,n)<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < n; ++i)
#define repR(i, n) for(ll i = n; i >= 0; ++i)
#define FDS(i, n) for(ll i = 0; i < n; ++i)
#define FDSR(i, n) for(ll i = n; i >= 0; ++i)
#define FOR(i, m, n) for(ll i = m; i < n; ++i)
#define FORR(i, m, n) for(ll i = m;i >= n;--i)
#define VSORT(v) sort(v.begin(), v.end());
#define VREV(v) reverse(v.begin(), v.end());
#define INF 999999999
#define itn ll
#define ednl endl
using namespace std;
typedef long long ll;template<typename Typell>Typell G_C_D(Typell a, Typell b){if (a < 0) a = -a;if (b < 0) b = -b;while (b != 0) {a %= b;if (a == 0) return b;b %= a;}return a;}template<typename Typell>
Typell G_C_D(const std::vector<Typell> &list){Typell a = list[0];for (size_t i = 1; i < list.size(); ++i) {a = G_C_D(a, list[i]);}return a;}template<typename Typell>Typell L_C_M(Typell a, Typell b) {if( a == 0 && b == 0)return 0;return a / G_C_D(a, b) * b;}
template<typename Typell>Typell L_C_M(const std::vector<Typell> &list){Typell a = list[0];for (size_t i = 1; i < list.size(); ++i) {a = L_C_M(a, list[i]);}return a;}

int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	int N;
	cin>>N;
	vector<ll> A(N);
	vector<ll> B(N);
	
	FDS(i,N){
		cin>>A[i]>>B[i];
	}
	
	vector<pair<ll,ll>> sa;
	FDS(i,N)FDS(j,N){
		if(i==j)continue;
		sa.push_back(make_pair(A[j]-A[i],B[j]-B[i]));
 
	}
	int ans=N;
	FDS(i,sa.size()){
		ll x=sa[i].first,y=sa[i].second;
		int c=0;
		FDS(k,sa.size()){
			if(sa[k].first==x&&sa[k].second==y){
				c++;
			}
		}
		ans=min(ans,N-c);
		
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 384
//ｺｯwwｺｯwwｺｹｯwwwｺｯwwｺｹｯwwwｺｹｯｺｯwwwｺｯwwｺｯwwｺｹｯwwwｺｯwwｺｹｯwwwｺｹｯｺｯwwwｺｹｰｰｰｰｯ!!!wwwwwｺｯwwｺｯwwｺｹｯwwwｺｯwwｺｹｯwwwｺｹｯｺｯwwwｺｯwwｺｯwwｺｹｯwwwｺｯwwwｺｹｯwwwｺｹｯｺｯwwwｺｹｰｰｰｰｯ!!!wwwwwｺｹｯｺｯｯｺｰｰｰｰ!!!!!!wwwwwwwwwww
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        String yono = "No";
        if(s.charAt(1) == s.charAt(2)){
            if(s.charAt(0) == s.charAt(1) || s.charAt(2) == s.charAt(3)){
                yono = "Yes";
            }
        }
        System.out.println(yono);
    }
}

Measured memory_bytes: 35612
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)
#define all(x) x.begin(),x.end()

/*
 * 3 2 5
 * 2 2 5
 * 2 2 1
 * 1 2 1
 */

int N;
vector<i64> A;
int main(){
  cin >> N;
  A.resize(N);

  rep(i,0,N - 1){
    cin >> A[i];
  }
  i64 ans = A[0] - 1;
  i64 MAX = 1;

  auto div = [](i64 a,i64 b){
    return  a / b + min(a % b,1LL);
  };
  rep(i,1,N - 1){
    if(A[i] < MAX + 1) continue;
    if(MAX + 1 == A[i]){
      MAX++;
    }
    else{
      ans += div(A[i] - (MAX + 1),(MAX + 1));
    }
  }
  cout << ans << endl;
}
/*15
3=2=1
1
4=1
1
5=3=1
9=7=5=3=1
2
6=1
5
3
5
8
9
7
9
*/


Measured memory_bytes: 1024
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        BATCoder solver = new BATCoder();
        solver.solve(1, in, out);
        out.close();
    }

    static class BATCoder {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            String str = in.next();
            int n = str.length();
            int ans = 0;

            for (int i = 0; i < n; i++) {
                for (int j = i + 1; j <= n; j++) {
                    String sliced = str.substring(i, j);
                    boolean flg = true;
                    for (int k = 0; k < sliced.length(); k++) {
                        char c = sliced.charAt(k);
                        if (c != 'A' && c != 'C' && c != 'G' && c != 'T') {
                            flg = false;
                            break;
                        }
                    }
                    if (flg) {
                        ans = Math.max(ans, sliced.length());
                    }
                }
            }
            out.println(ans);
        }

    }
}



Measured memory_bytes: 22996
N = int(input())
H = list(map(int, input().split()))

for i in range(N):
    i += 1
    parent = i // 2
    left = i * 2
    right = i * 2 + 1
    t = "node {}: key = {}, ".format(i, H[i-1])
    
    if i > 1:
        t += "parent key = {}, ".format(H[parent-1])
    
    if left <= N:
        t += "left key = {}, ".format(H[left-1])
        
    if right <= N:
        t += "right key = {}, ".format(H[right-1])
    
    print(t)

Measured memory_bytes: 7636
#include "bits/stdc++.h"
using namespace std;


int main() {
	int n;
	cin >> n;
	vector<pair<string, int>> vec(n);
	for (int i = 0; i < n; i++) {
		cin >> vec.at(i).first >> vec.at(i).second;
	}

	int ans = 0;
	bool flag = false;
	string x;
	cin >> x;
	for (int i = 0; i < n; i++) {
		if (flag) {
			ans += vec.at(i).second;
		}
		if (x == vec.at(i).first) {
			flag = true;
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef vector<vector<int>> v2int;
typedef vector<ll> vll;
typedef vector<vector<ll>> v2ll;
typedef list<int> liint;
typedef pair<int, int> pint;
const int INF = int(2e9);
const ll LINF = ll(2e9) * ll(2e9);
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b) { a > b ? : a = b; }
template<class T, class C> void chmin(T& a, C b) { a < b ? : a = b; }



int main() {
    ll S;
    cin >> S;
    ll X1, Y1, X2, Y2, X3, Y3;
    X3 = 0;
    Y3 = 0;
    const ll C = 1000000000;
    if (S <= C) {
        X1 = 1;
        Y2 = S;
        Y1 = 0;
        X2 = 0;
    }
    else {
        ll add = 0;
        if ((S) % C != 0) add = 1;
        X1 = (add + (S) / C);
        Y2 = C;
        X2 = abs(S - X1 * Y2);
        Y1 = 1;
    }
    cout << X1 << " " << Y1 << " " << X2 << " " << Y2 << " " << X3 << " " << Y3 << " " << endl;
   
    return 0;
}

Measured memory_bytes: 256
#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 pq priority_queue
#define P pair<int,int>
#define P2 pair<int,P>
#define P3 pair<int,P2>
typedef long long ll; typedef long double ld;
using namespace std;
const int INF=1e9, MOD=1e9+7, around[]={0,1,1,-1,-1,0,-1,1,0,0};
const ll LINF=1e18;
const ld PI=abs(acos(-1));
ll a,b,x;

int main(){
	cin >> a >> b >> x;
	
	cout << (b/x+1) - ((a?a-1:0)/x+1*!!a) << endl;
	return 0;
}


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

int main() {
  long long n; cin >> n;
  vector<string> s(n);
  vector<long long> t(n);
  for(int i = 0; i < n; i++){
    cin >> s.at(i) >> t.at(i);
  }
  string x; cin >> x;
  long long ind;
  for(int i = 0; i < n; i++){
    if(s.at(i) == x){
      ind = i;
      break;
    }
  }
  long long out = 0;
  for(int i = ind + 1; i < n; i++){
    out += t.at(i);
  }
  cout << out;
}


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

int main() {
    int N, X; cin >> N >> X;
    int m[N];
    int sum = 0;
    int min_m = 1000;
    for (int i = 0; i < N; i++) {
        cin >> m[i];
        sum += m[i];
        min_m = min(min_m, m[i]);
    }
    cout << N + (X - sum) / min_m << endl;
}


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

#define FOR(i, a, b)  for (int i = (a); i < (b); i++)
#define FORd(i, a, b) for (int i = (a); i >= (b); i--)
#define REP(i, n) FOR(i, 0, n)
#define ll long long

using namespace std;

const int MAXN = 2010;
const int M = 1e9 + 7;

int add(int a, int b) {return ((ll) a + (ll) b) % (ll) M;}
int mul(int a, int b) {return ((ll) a * (ll) b) % (ll) M;}

int fak[MAXN], inv[MAXN];
int pick[MAXN][MAXN];
int dp[MAXN][MAXN];

int choose(int a, int b) {
  return mul(mul(inv[b], inv[a - b]), fak[a]);
}

void init() {
  fak[0] = 1;
  FOR(i, 1, MAXN) fak[i] = mul(fak[i - 1], i);

  REP(i, MAXN) {
    inv[i] = 1;
    int tr = fak[i];
    int b = M - 2;

    while (b) {
      if (b & 1) inv[i] = mul(inv[i], tr);

      b = (b >> 1);
      tr = mul(tr, tr);
    }
  }
  REP(i, MAXN) pick[i][0] = 1;
  FOR(i, 1, MAXN) {
    FOR(j, 1, MAXN) {
      pick[i][j] = add(pick[i][j - 1], choose(i, j));
    }
  }

  REP(i, MAXN) dp[0][i] = dp[i][0] = 1;

  FOR(i, 1, MAXN) {
    FOR(j, 1, MAXN) {
      dp[i][j] = add(dp[i - 1][j], pick[j - 1][min(j - 1, i)]);
    }
  }
  return;
}

int main() {
  ios_base::sync_with_stdio(false);

  init();

  int a, b;
  cin >> a >> b;

  int out = 0;
  REP(i, a + 1) {
    REP(j, b) {
      int c = b - j - 1;
      if (a - i - c < 0) continue;
      int tr = mul(choose(b - 1, j), dp[a - i - c][b - j - 1]);
      out = add(tr, out);
    }
  }
  cout << out << endl;

  return 0;
}


Measured memory_bytes: 31872
use std::ascii::AsciiExt;
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        n:usize,
        k:usize,
        s:chars,
    }
    let mut s = s;
    s[k-1] = s[k-1].to_ascii_lowercase();
    for i in 0..n{
        print!("{}",s[i]);
    }
    println!("");
}


Measured memory_bytes: 4352
D, G = map(int, input().split())
p = []
c = []
PC = [list(map(int, input().split())) for _ in range(D)]
PC = [0] + PC


def dfs(G, i):
    if i == 0:
        return 10**12
    n = min((G-1)//(100*i)+1, PC[i][0])
    #n = min(G//(100*i), PC[i][0])
    tmp = n*100*i
    if n == PC[i][0]:
        tmp += PC[i][1]
    if tmp < G:
        n += dfs(G-tmp, i-1)
    return min(n, dfs(G, i-1))

print(dfs(G, D))


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

int main() {
  int N;
  cin >> N;
  
  vector<int> B(N - 1);
  for (int i = 0; i < N - 1; i++) {
    cin >> B.at(i);
  }
  
  int sum = B.at(0);
  for (int i = 0; i < N - 2; i++) {
    sum += min(B.at(i), B.at(i + 1));
  }
  sum += B.at(N - 2);
  
  cout << sum << endl;
  
  return 0;
}

Measured memory_bytes: 256
n,q=map(int,input().split())
g=[[] for i in range(n)]
for i in range(n-1):
    a,b=map(int,input().split())
    g[a-1].append(b)
    g[b-1].append(a)
x=[0]*n
for i in range(q):
    p,X=map(int,input().split())
    x[p-1]+=X
from collections import deque
d=deque()
d.append(0)
y=[0]*n
while len(d)>=1:
    s=d.popleft()
    y[s]+=1
    for i in g[s]:
        if y[i-1]!=1:
            d.append(i-1)
            x[i-1]+=x[s]
print(*x)

Measured memory_bytes: 126152
import java.util.*;
class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        String t = s;
        t = t.replace(t.charAt(2), t.charAt(3));
        t = t.replace(t.charAt(4), t.charAt(5));
        if(t.equals(s)){
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b;
	cin>>a>>b;
	if((a+b)%3==0||a%3==0||b%3==0)
	cout<<"Possible"<<endl;
	else
	cout<<"Impossible"<<endl;
	return 0;
}

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

A = list(map(int, input().split()))

original_price = 0
buff = 0
for i in range(N):
    original_price += abs(A[i]-buff)
    buff = A[i]
original_price += abs(A[N-1])

res = original_price + abs(A[1]) - abs(A[0]) - abs(A[1]-A[0])
print(res)

for i in range(N-2):
    res = original_price + abs(A[i+2]-A[i]) - abs(A[i+1]-A[i]) - abs(A[i+2] - A[i+1])
    print(res)

res = original_price + abs(-A[N-2]) - abs(A[N-1]-A[N-2]) - abs(-A[N-1])
print(res)


Measured memory_bytes: 14048
#include <cstdio>
#include <iostream>

using namespace std;

int main()
{
  int i,x,y;
  while(1)
  {
    cin >> x >> y;
    if (x==0 && y==0)
      return 0;
    if (x<y)
      printf("%d %d\n", x, y);
    else
      printf("%d %d\n", y, x);
  }
  return 0;
}

Measured memory_bytes: 1144
#include <iostream>
#include <string>
#include <vector>
#include <map>

using namespace std;

#define rep(i, n) for(int i=0; i<(n); ++i)

int p, q;
vector<string> P, Q;

void countBracket(vector<int> &rcs, string &s){
    for(char c: s){
        switch(c){
            case '(': rcs[0]++; break;
            case ')': rcs[0]--; break;
            case '{': rcs[1]++; break;
            case '}': rcs[1]--; break;
            case '[': rcs[2]++; break;
            case ']': rcs[2]--; break;
            default: break;
        }
    }
}

vector<int> solve(){
    map<vector<int>, int> indent;
    vector<int> rcs(3, 0), res(q, -2);
    rep(i, p-1){
        countBracket(rcs, P[i]);
        indent[rcs] = P[i+1].find_first_not_of('.');
    }
    for(int r=1; r<=20; ++r){
        for(int c=1; c<=20; ++c){
            for(int s=1; s<=20; ++s){
                bool ok = true;
                for(auto x: indent){
                    rcs = x.first;
                    if(r * rcs[0] + c * rcs[1] + s * rcs[2] != x.second){
                        ok = false;
                        break;
                    }
                }
                if(!ok)continue;
                rcs = {0, 0, 0};
                rep(i, q){
                    int t = r * rcs[0] + c * rcs[1] + s * rcs[2];
                    if(res[i] == -2)res[i] = t;
                    else if(res[i] != t)res[i] = -1;
                    countBracket(rcs, Q[i]);
                }
            }
        }
    }
    return res;
}

int main(){
    while(cin >> p >> q, p|q){
        P.resize(p); Q.resize(q);
        rep(i, p)cin >> P[i];
        rep(i, q)cin >> Q[i];
        vector<int> ans(solve());
        rep(i, q)cout << ans[i] << (i != q-1? ' ': '\n');
    }
    return 0;
}

Measured memory_bytes: 1236
private fun readAtOnce(): List<String> = readLine()!!.split(" ")
private fun readInts(): List<Int> = readAtOnce().map(String::toInt)
private fun readLongs(): List<Long> = readAtOnce().map(String::toLong)
private fun zeroArray(size: Int): IntArray = IntArray(size) { 0 }
private fun Int.repeat(predicate: (Int) -> Unit) = repeat(this, predicate)

private class UnionFind(N: Int) {
    private val parent = Array(N) { -1 }
    private val rank = zeroArray(N)

    fun findRoot(x: Int): Int =
            if (parent[x] < 0) {
                x
            } else {
                parent[x] = findRoot(parent[x])
                parent[x]
            }

    fun unite(x: Int, y: Int) {
        val rootX = findRoot(x)
        val rootY = findRoot(y)
        if (rootX == rootY) return

        if (rank[rootX] < rank[rootY]) {
            parent[rootY] += parent[rootX]
            parent[rootX] = rootY
        } else {
            parent[rootX] += parent[rootY]
            parent[rootY] = rootX
            if (rank[rootX] == rank[rootY]) rank[rootX]++
        }
    }

    fun hasInSameGroup(x: Int, y: Int): Boolean = findRoot(x) == findRoot(y)

    fun groupSizeOf(belongs: Int) = -parent[findRoot(belongs)]
}

// heap
private val friends = zeroArray(100004)
private val blocking = Array(100004) { mutableListOf<Int>() }

fun main(args: Array<out String>) {
    val (N, M, K) = readInts()
    val unionFind = UnionFind(N + 1)
    M.repeat {
        val (A, B) = readInts()
        unionFind.unite(A, B)
        friends[A]++
        friends[B]++
    }
    K.repeat {
        val (C, D) = readInts()
        blocking[C].add(D)
        blocking[D].add(C)
    }

    (1..N)
            .map { n -> unionFind.groupSizeOf(n) - 1 - friends[n] - blocking[n].count { blocked -> unionFind.hasInSameGroup(blocked, n) } }
            .joinToString(separator = " ")
            .let(::println)
}

Measured memory_bytes: 90300
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()		//sort(all(vi S)) sort(all(string S))

typedef long long ll;
typedef vector<int> vi;
typedef set<int> seti;
typedef vector<string> vs;

const int MOD = 1e9+7;
const int inf = 1e9;

int main() {
	int H,W;
	cin>>H>>W;
	vs S(H);
	rep(i,H)cin>>S[i];
	rep(i,W+2)cout<<'#';
	cout<<endl;

	rep(i,H){
		cout<<'#'<<S[i]<<'#'<<endl;
	}

	rep(i,W+2)cout<<'#';
	cout<<endl;
}

Measured memory_bytes: 256
N, Y = map(int,input().split())
ans = []

for x in range(N+1):
    for y in range(N+1):
        z = N - x - y
        if 10000 * x + 5000 * y + 1000 * z == Y and z >= 0:
            ans = [x,y,z]
            break

if len(ans) == 0:
    print("-1 -1 -1")
else:
    print(str(ans[0]),str(ans[1]),str(ans[2]))


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

#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define repn(i, n) for(int (i) = 1; (i) <= (n); (i)++)
#define repr(i, n) for(int (i) = (n-1); (i) >= 0; (i)--)
#define all(x) (x).begin(), (x).end()
#define lint long long
#define ulint unsigned long long
#define fi first
#define se second
#define setpre(x) cout << fixed << setprecision(x)
#define ii(x) int x; cin >> (x)
#define ii2(x, y) int x, y; cin >> (x) >> (y)
#define ii3(x, y, z) int x, y, z; cin >> (x) >> (y) >> (z)
#define out(x) cout << (x) << endl
#define yn(x) cout << ((x)?("Yes"):("No")) << endl
#define YN(x) cout << ((x)?("YES"):("NO")) << endl
#define bit_c(x) __builtin_popcountll(x)

inline void logger(){ cout << endl; }
template<typename A, typename... B>
void logger(const A& a, const B&... b){
    cout << a << " , ";
    logger(b...);
}

typedef pair<lint, lint> P;
const lint MOD = 1000000007;
const lint MOD9 = 998244353;
const lint INF = MOD * MOD;
const int MAX = 2005;

/* ...o(^-^)o... */

int main(){
    lint x, y; cin>>x>>y; out((abs(x-y)<2)?"Brown":"Alice");
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, m, n) for(int i=(m); i<(n); ++i)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define Cout(x) cout << (x) << endl
#define Cout2(x, y) cout << (x) << " " << (y) << endl
#define dump(x) cerr << #x << " = " << (x) << endl;
#define forauto(i, a) for(auto i : a)cerr << i << " "; cerr << endl;
typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
const int inf = 1e9;
const double pi = acos(-1.0);

VI prime = { 2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97 };
int main() {
	int n; cin >> n;

	VI c(25);
	rep(i, 25) {
		int m = n, sum = 0;
		while (m / prime[i] != 0) {
			sum += m / prime[i];
			m /= prime[i];
		}
		c[i] = sum;
	}

	int ans = 0;

	//x^74
	rep(i, 25) {
		if (74 <= c[i])ans++;
	}

	//x^2 * y^24
	//x^4 * y^14
	rep(i, 25)rep(j, 25) {
		if (i != j) {
			if (2 <= c[i] && 24 <= c[j])ans++;
			if (4 <= c[i] && 14 <= c[j])ans++;
		}
	}

	//x^2 * y^4 * z^4
	rep(i, 25)rep(j, 25)rep(k, 25) {
		if (i != j && j != k && i != k && j < k) {
			if (2 <= c[i] && 4 <= c[j] && 4 <= c[k])ans++;
		}
	}

	Cout(ans);
}

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



int main(){
    int N;
    cin >> N;
    int t =N , c =0;
    while (t >0) c += t %10 , t /=10;

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define P pair<ll, ll>
#define Graph vector<vector<ll>>
#define fi first
#define se second
constexpr ll mod = 1000000007;
constexpr ll INF = (1ll << 60);
constexpr double pi = 3.14159265358979323846;
template <typename T>
inline bool chmax(T &a, T b){if (a < b){a = b;return 1;}return 0;}
template <typename T>
inline bool chmin(T &a, T b){if (a > b){a = b;return 1;}return 0;}

int main(){
    ll odd=0,even=0;
    ll k;cin>>k;
    for(ll i=1;i<=k;i++){
        if(i%2) odd++;
        else even++;
    }

    cout<<odd*even<<endl;
    return 0;
}

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

int main(int argc, char **argv)
{
  int no;
  char c;
  string bt;
  map<string, int> m;
  while (cin >> no >> c >> bt) {
    m[bt]++;
  }
  cout << m["A"] << endl;
  cout << m["B"] << endl;
  cout << m["AB"] << endl;
  cout << m["O"] << endl;
  return 0;
}

Measured memory_bytes: 1220
#include <bits/stdc++.h>
using namespace std;
 
int main() {
   int nunber = 0;
   cin >> nunber;
   int n = nunber % 10;
  
   if ( n == 2 ){
     cout << "hon" << endl;
   }
  else if ( n == 4 ){
     cout << "hon" << endl;
   }
  else if ( n == 5 ){
     cout << "hon" << endl;
   }
  else if ( n == 7 ){
     cout << "hon" << endl;
   }
  else if ( n == 9 ){
     cout << "hon" << endl;
   }
   else if ( n == 0 ){
     cout << "pon" << endl;
   }
   else if ( n == 1 ){
     cout << "pon" << endl;
   }
     else if ( n == 6 ){
     cout << "pon" << endl;
   }
   else if ( n == 8 ){
     cout << "pon" << endl;
   }
   else if ( n == 3){
     cout << "bon" << endl;
   }
}

Measured memory_bytes: 3624
import heapq


def dijkstra(adj_list, n):
    dist = [float("inf") for i in range(n)]
    visited = [False for _ in range(n)]
    parent = [-1 for _ in range(n)]
    start = 0
    dist[start] = 0
    dist_heap = []  # 距離が最小のノードをすぐに探せるようにするために使う。次のノードの候補を入れる。
    heapq.heappush(dist_heap, (dist[start], start))

    while len(dist_heap) > 0:
        cost, start = heapq.heappop(dist_heap)  # 一番近いノードがスタート地点となる
        visited[start] = True
        if dist[start] < cost:  # heapのコストが最短でなければ、distを更新する必要はない
            continue
        for end, weight in adj_list[start]:
            # startから出ているノードの距離を計算してheapqに入れる
            if not visited[end] and dist[start] + weight < dist[end]:
                dist[end] = dist[start] + weight
                parent[end] = start
                heapq.heappush(dist_heap, (dist[end], end))

    return parent, dist


def main():
    n = int(input())
    adj_list = []
    for _ in range(n):
        row = []
        line = input().split()
        dim = int(line[1])
        for i in range(dim):
            row.append((int(line[2 + i * 2]), int(line[2 + i * 2 + 1])))  # 番号, 重み
        adj_list.append(row)
    _, dist = dijkstra(adj_list, n)
    for i in range(n):
        print("{} {}".format(i, dist[i]))


if __name__ == "__main__":
    main()



Measured memory_bytes: 68812
n = int(input())
k = int(input())

num = 1

def ope_a(num_local):
    num_local = 2 * num_local
    return num_local

def ope_b(x):
    x = x + k
    return x

i = 0
while i < n:
    if ope_a(num) <= ope_b(num):
        num = ope_a(num)
        i += 1
    else:
        num = ope_b(num)
        i += 1

print(num)

Measured memory_bytes: 9136
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

int main() {
    int a,b,c,d,e;cin>>a>>b>>c>>d>>e;
    cout<<c*60+d-a*60-b-e<<endl;
    return 0;
}

Measured memory_bytes: 3628
//俯瞰と閃き
#include <iostream>
#include <string>
using namespace std;

int h, w;
string s[500];
bool red[500][500];
bool blue[500][500];

int main() {
	int i, j;
	
	cin >> h >> w;
	for (i = 0; i < h; i++) cin >> s[i];
	
	//型を作る(外側がきれいな形になりそう～と思うと閃きやすい)
	for (i = 1; i < h; i += 2) for (j = 0; j < w - 1; j++) red[i][j] = true;
	for (i = 0; i < h; i++) red[i][0] = true;
	for (i = 0; i < h; i += 2) for (j = 1; j < w; j++) blue[i][j] = true;
	for (i = 0; i < h; i++) blue[i][w - 1] = true;
	
	//#を作る
	for (i = 0; i < h; i++) {
		for (j = 0; j < w; j++) {
			if (s[i][j] == '.') continue;
			if (red[i][j]) blue[i][j] = true;
			else red[i][j] = true;
		}
	}
	
	//出力する
	for (i = 0; i < h; i++) { for (j = 0; j < w; j++) cout << ".#"[red[i][j]]; cout << endl; }
	cout << endl;
	for (i = 0; i < h; i++) { for (j = 0; j < w; j++) cout << ".#"[blue[i][j]]; cout << endl; }
	return 0;
}

Measured memory_bytes: 1664
n = int(input())
s = "SHCD"
used = [[0] * 13 for i in range(4)]
for i in range(n):
  a, b = input().split()
  used[s.find(a)][int(b) - 1] = 1
for i in range(4):
  for j in range(13):
    if used[i][j] == 0:
      print(s[i], j + 1)


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

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

#define m0(x) memset(x, 0, sizeof(x))
#define all(x) x.begin(), x.end()
#define rep(i, n) for(int i = 0; i < (n); i++)
#define asort(x) sort(all(x));
#define dsort(x, t) sort(x.begin(), x.end(), greater<t>());
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#define MINS(m, s) m.insert(mp(s, 1));
#define MFIN(m, s) m.find(s) != m.end()
#define INF (1 << 29)
const int mod = 1000000007;

int main() {
    string s, t, u;
    int a, b;
    cin >> s >> t >> a >> b >> u;
    if(u == s) {
        a--;
    } else {
        b--;
    }
    cout << a << " " << b << endl;
    return 0;
}

Measured memory_bytes: 3588
#include<iostream>
#include<iomanip>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<numeric>
#include<limits>
#include<bitset>
#include<functional>
#include<type_traits>
#include<queue>
#include<stack>
#include<array>
#include<random>
#include<utility>
#include<cstdlib>
#include<ctime>

using namespace std;

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep2(i, begin_i, end_i) for (int i = (int)begin_i; i < (int)end_i; i++)

long long INF = 1LL<<60;
long long dp[100010];
int h[100010];

int main(){
    string w;
    vector<int> alphabet(26);
    cin>>w;
    rep(i,w.size()){
        alphabet.at(w.at(i)-'a')++;
    }
    rep(i,26)
        if(alphabet.at(i)%2){
            printf("No\n");
            return 0;
            }
    printf("Yes\n");
    return 0;
}




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

signed main(){
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    sort(a.begin(),a.end());
    reverse(a.begin(),a.end());
    int ans = 1, cnt = 0;
    for(int i = 0; i < n; i++){
        if(a[i] != a[i - 1] && i != 0 && cnt % 2 == 1)
        cnt--;
        cnt++;
        if(cnt % 2 == 0)
        ans *= a[i];
        if(cnt == 4)
        break;
    }

    cnt == 4 ? cout << ans: cout << 0;
    cout << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s, t;
  cin >> s >> t;
  sort(s.begin(), s.end());
  sort(t.begin(), t.end());
  reverse(t.begin(), t.end());
  if(s<t) cout<<"Yes" << endl;
  else cout << "No" << endl;
  return 0;
}
  
  


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

using namespace std;

const int N = 1e5 + 5;

int a[N];

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", a + i);
  
  long long ans = a[0] - 1;
  long long price = 2;
  for (int i = 1; i < n; i++) {
    if (a[i] > price) {
      ans += (a[i] - 1) / price;
    } else {
      price = max(price, 1LL * a[i] + 1);
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 640
import java.util.Scanner;
class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int S = sc.nextInt();
        int h = S / 3600;
        int hn = S % 3600;
        int m = hn / 60;
        int s = hn % 60;
        System.out.println(h + ":" + m + ":" + s);
        
        sc.close();
    }
}


Measured memory_bytes: 26180
#include <bits/stdc++.h>
#include <vector>
#include <numeric>
#define PI 3.14159265358979323846
#define MAXINF (1e18L)
#define INF (1e9L)
#define EPS (1e-9)
#define MOD ((ll)(1e9+7))
#define REP(i, n) for(int i=0;i<int(n);++i)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define FIND(v,x) (binary_search(ALL(v),(x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v));reverse(ALL(v))
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define pb push_back
#define fi first
#define se second
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
template<class T> inline bool chmin(T& a, T b){return a>b ? a=b, true : false;}
template<class T> inline bool chmax(T& a, T b){return a<b ? a=b, true : false;}
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;

int main(void){
    string s;
    cin >> s;
    int K;
    cin >> K;
    int n = s.size();

    vector<string> l;
    REP(i, n){
        Rep(j, 1, min(n-i+1,6)){
            string ss = s.substr(i,j);  
            if(!FIND(l, ss))
                l.insert(lower_bound(ALL(l), ss), ss);
        }
    }
    SORT(l);
    pr(l[K-1]);

    // set<string> l;
    // REP(i, n){
    //     Rep(j, 1, min(n-i+1,6)){
    //         l.insert(s.substr(i,j));
    //     }
    // }
    // int it = 0;
    // for(auto&& ss : l){
    //     if(++it == K) pr(ss);
    // }
}

Measured memory_bytes: 1024
#include<iostream>
using namespace std;
int main(){
  int n,minj,count=0;
  int a[101]={};
  cin>>n;
  for(int i=0;i<n;i++)cin>>a[i];

  for(int i=0;i<n;i++){
      minj = i;
    for(int j=i;j<n;j++)
      if(a[j]<a[minj])
	minj = j;
    if(i!=minj){
      swap(a[i],a[minj]);
      count++;
    }
  }
    for(int i=0;i<n-1;i++)
      cout<<a[i]<<' ';
    cout<<a[n-1]<<endl<<count<<endl;
    return 0;
}

Measured memory_bytes: 1164
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>

int main(){
	char palavra1[200001], palavra2[200001];
	int cont=0;
	scanf("%s %s", palavra1, palavra2);
	
	for(int i=0; i < strlen(palavra1); ++i){
		if(palavra1[i]!= palavra2[i])
			cont++;

	}
	printf("%d\n", cont);

	return 0;
}

Measured memory_bytes: 2116
line = input().split(' ')
price = int(line[0])
equity = int(line[1])
max = int(line[2])

def getTimes(price, equity, max):
    real = int(equity / price)
    return min(real, max)

def min(a, b):
    if a <= b:
        return a
    else:
        return b

res = getTimes(price, equity, max)
print(res)

Measured memory_bytes: 3064
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define D()
#define INF 1000000000000
#define MOD 10000007
#define MAXR 100000
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define INITA(a,i,j,v) for(ll k=i;k<=j;k++){a[k]=v;}

int main() {
    ll n; cin >> n;
    vector<ll> a;
    ll num_minus = 0;
    ll absmin = 1e10;
    ll tot = 0;
    REP(i, n) {
        ll tmp; cin >> tmp;
        a.push_back(tmp);

        tot += abs(tmp);
        if (tmp < 0) {
            num_minus++;
        }
        if (abs(tmp) < absmin) {
            absmin = abs(tmp);
        }
    }

    if (num_minus % 2 == 0) {
        cout << tot << endl;
    } else {
        cout << tot - 2 * absmin << endl;
    }
    return 0;
}

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

#define PI 3.141592653589
#define ll long long int
#define ld long double
#define vi vector<int>
#define vl vector<ll>
#define ii pair<int,int>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define pll pair<ll,ll>
#define vv vector
int MOD=1e9+7;
ll power(ll a, ll b){//a^b
    ll res=1;
    a=a%MOD;
    while(b>0){
        if(b&1){res=(res*a)%MOD;b--;}
        a=(a*a)%MOD;
        b>>=1;
    }
    return res;
}
ll fermat_inv(ll y){return power(y,MOD-2);}
ll gcd(ll a, ll b){return (b==0)?a:gcd(b,a%b);}
ll min(ll a,ll b){return (a>b)?b:a;}
ll max(ll a,ll b){return (a>b)?a:b;}
bool prime[1000001];
vi primes;
void SieveOfEratosthenes(int n) 
{ 
    memset(prime, true, sizeof(prime)); 
    for (int p=2; p*p<=n; p++) 
    { 
        if (prime[p] == true) 
        { 
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
    for(int p=2;p<1000001;p++)
        if(prime[p])
            primes.pb(p);
}
ll fact[1001];
void factorial(int n){
    fact[0]=1;
    for(int i=1;i<=n;i++)
        fact[i]=fact[i-1]*i,fact[i]%=MOD;
}
ll ncr(ll n,ll r)
{
    if(n<r)
        return -1;
    else{
        ll x=fact[r]*fact[n-r]%MOD;
        return fact[n]*fermat_inv(x)%MOD;
    }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif

    int t=1;
    //cin>>t;
    //SieveOfEratosthenes(1000000);
    //factorial(1000);
    while(t--){
        string s;
        cin>>s;
        int n=s.size(),sum=0;
        for(int i=0;i<n;i++)
            sum+=s[i]-48;
        if(sum%9)
            cout<<"No";
        else cout<<"Yes";
    }
}

Measured memory_bytes: 3780
#include <stdio.h>

using namespace std;

int main(){
	int n,x;
	scanf("%d",&n);

	for(int i = 1; i<= n; i++)
	{
		if(i%3 == 0){
			printf(" %d",i);
		}else{
			x = i;
			do{
				if(x%10 == 3){
					printf(" %d",i);
					break;
				}
				x /=10;
			}while(x);
		}
	}
	printf("\n");
}



Measured memory_bytes: 2760
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<ll, int> P;
#define MOD (1000000007ll)
#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

int main(void){
	int n,i;
	ll ans=0ll,l,r;
	cin >> n;
	for(i=0; i<n; ++i){
		cin >> l >> r;
		ans += (r - l + 1ll);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip> //! for setprecision(10)
#include <math.h>
#include <algorithm>
#include <functional> 
#include <string>
#include <vector>

#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <utility>

using namespace std;

typedef long long LL;

#define dump(c) { for (auto it = c.begin(); it != c.end(); ++it) if (it == c.begin()) cout << *it; else cout << ' ' << *it; cout << endl; } 
#define rep(i,n) for (int i = 0; i < (n); ++i)

const int MOD = 1000000007;

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

    int N, K;
    cin >> N >> K;

    vector<int> x;
    x.reserve(N);
    int negCount = 0;
    rep(i, N) {
        int xin;
        cin >> xin;
        if (xin < 0) {
            ++negCount;
        }
        if (xin) {
            x.push_back(xin); 
        } else {
            --K; //! remove candle on 0
        }
    }
    N = x.size();
    if (K == 0) {
        cout << 0 << endl;
        return 0;
    }
    int posCount = N - negCount;

    int ans = 1000000000;

    //! Move negative side first
    for (int i = 1; i <= negCount; ++i) {
        int tmp = 0;
        if (K <= i) {
            tmp = -x[negCount-i];
        } else {
            if (N <= negCount+K-i-1) continue;
            tmp = -2 * x[negCount-i];
            tmp += x[negCount+K-i-1];
        }
        ans = min(ans, tmp);
    }

    //! Move positive side first
    for (int i = 1; i <= posCount; ++i) {
        int tmp = 0;
        if (K <= i) {
            tmp = x[negCount+i-1];
        } else {
            if (negCount-(K-i) < 0) continue;
            tmp = 2 * x[negCount+i-1];
            tmp -= x[negCount-(K-i)];
        }
        ans = min(ans, tmp);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#define LL long long
#define MOD 1000000007
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define print(a, n) for(LL e=0; e<n; e++) cout<<a[e]<<" "; cout<<endl
#define read(a, n) for(LL e=0; e<n; e++) cin>>a[e];
using namespace std;
  
int main()
{
	fastio;
	LL a, b, c, k;
	cin>>a>>b>>c>>k;

	LL ans = 0;
	ans += min(k, a);
	k -= a;
	k -= b;

	if(k>0)
		ans -= k;
	
	cout<<ans<<"\n";

	return 0;
}


Measured memory_bytes: 3612
#include <stdio.h>
int main(void){
 
    int H, W, i, j;
 
    while(1){
      
    scanf("%d %d",&H ,&W);
  
    if(H == 0 && W == 0)break;
 
    for(i = 0; i < H; i++){

    for(j = 0; j < W; j++){
        
        if(j % 2 == 1){
            
            if(i % 2 == 1){
                printf("#");
                
            }else{
                printf(".");
                
            }
        }else{
            
            if(i % 2 == 1){
                printf(".");
                
            }else{
                printf("#");
                
            }
        }
    }
    
    printf("\n");
  
    }
    
    printf("\n");
    
    }
    
  
 
    return 0;
      
    }



Measured memory_bytes: 2040
N, K = gets.split.map(&:to_i)
H = [Float::INFINITY] + gets.split.map(&:to_i)

dp = Array.new(N + 1)
dp[1] = 0

2.upto(N) do |i|
  min = Float::INFINITY

  (([1, i - K].max)..(i - 1)).each do |j|
    cost = dp[j] + (H[j] - H[i]).abs
    min = cost if min > cost
  end

  dp[i] = min
end

puts dp[N]


Measured memory_bytes: 13308
N,M,Q = gets.split.map(&:to_i)
xs = (0..N).map{ (0..N).map{ 0 } }

M.times{
  l,r = gets.split.map(&:to_i)  
  xs[l][r] += 1
}

#p xs

ys = (0..N).map{ |i|
  row = [0]
  (1..N).each{ |j|
    row << (row[-1] + xs[i][j])
  }
  row
}

#p ys
zs = (0..N).map{ |j|
  row = (0..N+1).map{ 0 }
  (0...N).each{ |ii|
    i = N-ii
    row[i] = row[i+1] + ys[i][j]
  }
  row
}
Q.times { |a|
  p,q = gets.split.map(&:to_i)  
  puts zs[q][p]
}

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

int main(){
	bool t=false;
	int x,y; cin>>x>>y;
	rep(i,x+1){
		if(y==i*2+4*(x-i)) t=true;
	}
	if(t) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}

Measured memory_bytes: 3576
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
int a[200005];
int main(){
	int n;
	scanf("%d", &n);
	for(int i=1;i<=n;i++){
		scanf("%d", &a[i]);
	}
	LL lo = -2e9, hi = 2e9;
	LL ans = 2e18;
	for(int i=0;i<100;i++){
		LL mid1 = lo+(hi-lo)/3;
		LL res1 = 0, res2 = 0;
		LL b = mid1;
 
		for(int i=1;i<=n;i++){
			res1 += abs(a[i]-(b+i));
		}
		LL mid2 = hi-(hi-lo)/3;
		b = mid2;
 
		for(int i=1;i<=n;i++){
			res2 += abs(a[i]-(b+i));
		}
		if(res1 <= res2){
			ans = min(ans, res1);
			hi = mid2;
		}
		else{
			ans = min(ans, res2);
			lo = mid1;
		}
	}
	printf("%lld\n", ans);
}

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

using namespace std;

typedef long long LL;
#define N 6000000

const LL mod=998244353;
LL n,m,p,fac[N],ifac[N],ans;

void upd(LL &x,LL y){
	x=(x+y%mod+mod)%mod;
}

LL inv(LL x){
	return x==1?1:(mod-mod/x)*inv(mod%x)%mod;
}

LL C(LL x,LL y){
	return x<y||y<0?0:fac[x]*ifac[y]%mod*ifac[x-y]%mod;
}

int main(){
	scanf("%lld%lld",&n,&m);
	p=(n+m)*3;
	fac[0]=1; for (LL i=1;i<=p;++i) fac[i]=fac[i-1]*i%mod;
	ifac[p]=inv(fac[p]); for (LL i=p-1;~i;--i) ifac[i]=ifac[i+1]*(i+1)%mod;
	for (LL i=m&1;i<=m;i+=2){
		LL p=(m*3-i)/2,sum=0;
		upd(sum,C(p+n-1,n-1));
		upd(sum,-i*C(p-m+n-1,n-1));
		upd(sum,-(n-i)*C(p-(m+1)+n-1,n-1));
		upd(ans,sum*C(n,i));
	}
	printf("%lld\n",ans);
	
	return 0;
}
			

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

#define ll long long
#define pii pair<int, int>
using namespace std;

int main() {
    vector<vector<int>> a(3, vector<int>(3));
    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
            cin >> a[i][j];
        }
    }
    int n;
    cin >> n;
    vector<vector<int>> b(3, vector<int>(3, 0));
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        for (int k = 0; k < 3; k++) {
            for (int l = 0; l < 3; l++) {
                if (a[k][l] == x)b[k][l] = 1;
            }
        }
    }
    bool ok = false;
    for (int i = 0; i < 3; i++) {
        int s = 0;
        for (int j = 0; j < 3; j++) {
            s += b[i][j];
        }
        if (s == 3)ok = true;
    }
    for (int i = 0; i < 3; i++) {
        int s = 0;
        for (int j = 0; j < 3; j++) {
            s += b[j][i];
        }
        if (s == 3)ok = true;
    }
    int s = 0;
    for (int i = 0; i < 3; i++) {
        s += b[i][i];
    }
    if (s == 3)ok = true;
    s = 0;
    for (int i = 0; i < 3; i++) {
        s += b[i][2 - i];
    }
    if (s == 3)ok = true;
    if (ok) {
        cout << "Yes";
    } else {
        cout << "No";
    }
}

Measured memory_bytes: 256
a = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]

k = int(input())

print(a[k-1])


Measured memory_bytes: 2940
N,K,C=gets.split.map(&:to_i)
S=gets.chop

l=*r=Array.new(N+2){0}
N.times.inject(0) do |s,i|
  l[i+1]=l[i]
  if s<=0 && S[i]==?o
    l[i+1]+=1
    C
  else
    s-1
  end
end
N.times.inject(0) do |s,i|
  r[N-i]=r[N-i+1]
  if s<=0 && S[N-i-1]==?o
    r[N-i]+=1
    C
  else
    s-1
  end
end

1.upto(N) do |i|
  p i if l[i-1]+r[i+1]<K
end


Measured memory_bytes: 6908
#pragma target("avx")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

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

  long long n,m,ans=0;
  cin >> n >> m;
  long long a[n],b[n];
  vector<long long> v[100005];
  for(int i=0;i<n;i++){
    cin >> a[i] >> b[i];
    a[i]--;
    v[a[i]].push_back(b[i]);
  }
  priority_queue<long long> que;
  for(int i=0;i<m;i++){
    for(size_t j=0;j<v[i].size();j++){
      que.push(v[i][j]);
    }
    if(!que.empty()){
      ans+=que.top();
      que.pop();
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 7296