akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
using lli = long long;
#define rep(i,n) for(int i=0;i<n;i++)

const lli m = 2e5+10;
lli n, k;

int main(void){
	cin >> n >> k;
	vector<lli> c(m);
	rep(i, n){
		lli ai;
		cin >> ai;
		c[ai]++;
	}
	sort(c.begin(), c.end(), greater<lli>());
	lli ans = n;
	rep(i, k) ans-=c[i];
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 4828
// inputに入力データ全体が入る
function Main(input) {
    // 1行目がinput[0], 2行目がinput[1], …に入る
    input = input.split("\n");
    tmp0 = input[0].split(" ");
    X = Number(tmp0[0])
    A = Number(tmp0[1])

    if(X<A){
        console.log(0)
    }else{
        console.log(10)
    }
}
  //*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
// Main("6 2\n3\n5");

Measured memory_bytes: 21064
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<queue>
using namespace std;
#define int long  long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
typedef pair<int, int>P;
const int INF = 1e8;

signed main() {
	int N, K;
	cin >> N >> K;
	vector<int>A(N);
	rep(i, N)cin >> A[i];
	int ans = (N - 1 + K - 1 - 1) / (K - 1);
	cout << ans;
}

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

int main(){
  int w,d,x,ans;
  while(cin >> w >> d && (w|d)){
    vector<int> v[2];
    for(int i=0;i<w;i++){
      cin >> x;
      v[0].push_back(x);
    }
    for(int j=0;j<d;j++){
      cin >> x;
      v[1].push_back(x);
    }

    ans = 0;
    for(int i=0;i<v[0].size();i++){
      for(int j=0;j<v[1].size();j++){
	if(v[0][i] == v[1][j]){
	  ans += v[0][i];
	  v[0].erase(v[0].begin()+i);
	  v[1].erase(v[1].begin()+j);
	  i--;
	  break;
	}
      }
    }
    for(int i=0;i<v[0].size();i++) ans += v[0][i];
    for(int i=0;i<v[1].size();i++) ans += v[1][i];

    cout << ans << endl;
  }
}

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

#define rng(i, a, b) for (int i = int(a); i < int(b); i++)
#define rep(i, b) rng(i, 0, b)
#define gnr(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define per(i, b) gnr(i, 0, b)

using namespace std;

using ll = long long;
using P = pair<int, int>;

int main() {
  ll a, b, c, d;
  cin >> a >> b >> c >> d;
  ll res = max({a * c, a * d, b * c, b * d});
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 3632
a = gets.to_i # 500 
b = gets.to_i # 100 
c = gets.to_i #  50 
x = gets.to_i

ans = 0
(0..a).each{ |a_|
    (0..b).each{ |b_|
        (0..c).each{ |c_|
            ans += 1 if 500 * a_ + 100 * b_ + 50 * c_ == x
        }
    }
}

puts ans


Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 111111;
int L, N, T, p[MAXN];
int main(){
	cin>>N>>L>>T;
	int X, W, pos = 1;
	char fx;
	for(int i = 1;i <= N; i++){
		cin>>X>>W;
		if(W == 1){
			p[i] = (X + T) % L;
			pos += (X + T) / L;
		}
		else{
			if(T - X > 0){
				pos--;
				p[i] = L - (T - X) % L;
				if(p[i] == L)p[i] = 0;
				if((T - X) % L == 0)pos -= (T - X) / L - 1;
				else pos -= (T - X) / L;
			}
			else{
				p[i] = X - T;
			}
		}
		if(pos <= 0)pos += N;
		if(pos > N) pos -= N;
	}
	sort(p + 1, p + 1 + N);
	for(int i = 1;i <= N; i++){
		printf("%d\n", p[pos]);
		pos++;
		if(pos == N + 1)pos = 1;
	}
	return 0;
}
/*
4 20 9
7 2
9 1
12 1
18 1
*/ 

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

using namespace std;

#define pb push_back
#define mk make_pair
#define mod 1000000007
#define ff first
#define ss second

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

ll modpow(ll a, ll b){

    ll ans=1;
    while(b){
        if(b&1){
            ans=(ans*a)%mod;
        }
        a=(a*a)%mod;
        b=b/2;
    }
    return ans;
}

ll dp[3010][3010];
ll lst[3010][3010];

int main(){


    string a,b;
    cin>>a>>b;

    for(int i = 0; i < a.size(); i++) {
        for(int j = 0; j < b.size(); j++) {
            if(i) {
                if(dp[i][j] <= dp[i-1][j]) {
                    lst[i][j] = 0;
                    dp[i][j] = dp[i-1][j];
                }
            }
            if(j) {
                if(dp[i][j] <= dp[i][j-1]) {
                    lst[i][j] = 1;
                    dp[i][j] = dp[i][j-1];
                }
            }
            if(a[i] == b[j]) {
                if(i != 0 && j != 0) {
                    if(dp[i][j] <= dp[i-1][j-1] + 1) {
                        lst[i][j] = 2;
                        dp[i][j] = 1 + dp[i-1][j-1];
                    }
                }
                else {
                    dp[i][j] = 1;
                    lst[i][j] = 2;
                }
            }
        }
    }

    int st1 = a.size()-1;
    int st2 = b.size()-1;

    string s;

    while(st1 >= 0 && st2 >= 0) {
        if(lst[st1][st2] == 2) {
            s = s + a[st1];
            st1--;
            st2--;
        } else if(lst[st1][st2] == 1) {
            st2--;
        } else {
            st1--;
        }

    }

    reverse(s.begin(), s.end());

    cout<<s<<endl;


}


Measured memory_bytes: 141568
#include <iostream>
#include <vector>
#include <algorithm>

#define INF 1000000000
#define ALL(a) (a).begin(), (a).end()

using namespace std;
typedef long long ll;

int main()
{
  vector<vector<int>> vvi(600);
  int n, m, q;
  cin >> n >> m >> q;

  // vvi[l][i] := 左端lの区間の右端
  for (int i = 0; i < m; i++) {
    int l, r;
    cin >> l >> r;
    vvi[l].push_back(r);
  }
  for (int i = 1; i <= 500; i++) {
    vvi[i].push_back(INF);
    sort(ALL(vvi[i]));
  }

  for (int i = 0; i < q; i++) {
    ll ans = 0;
    int l, r; cin >> l >> r;

    //右端をl～rまで動かす
    for (int j = l; j <= r; j++) {
      //[j, r]に含まれる区間の個数を数える
      //INFになってしまったらvvi[j]の全要素が[j, r]に含まれる
      //memo[j][r] = [j, r]に含まれる区間の個数として、再利用する
      int idx = upper_bound(ALL(vvi[j]), r) - vvi[j].begin();
      if (vvi[j][idx] != INF) ans += idx;
      else ans += vvi[j].size() - 1;
    }
      cout << ans << endl;
  }
    return 0;
}


Measured memory_bytes: 2176
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define N 1000
int main(){
  int x;
  cin >> x;
  vector<int> d;
  d.push_back(1);
  for (int i=2; i<32; i++){
    int j= i;
    while(j < 1000){
      j *= i;
      d.push_back(j);
    }
  }
  sort(d.begin(), d.end());
  d.erase(unique(d.begin(), d.end()), d.end());

  vector<int>::iterator itr = d.end();
  while(itr != d.begin() && *itr > x){
    itr--;
  }
  cout << *itr << endl;
  return 0;
}

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

using namespace std;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define int long long
#define VI vector<int>
#define PII pair<int,int>
#define FI first
#define SE second

signed main() {
  IOS;
  int n, x,y,ans=0;
  cin >> n;
  PII xy[n];
  set<PII> s;
  FOR(i,0,n) {
    cin >> x >> y;
    xy[i] = {x,y};
    s.insert(xy[i]);
  }

  int p,q;
  FOR(i,0,n) {
    FOR(j,0,n) {
      if (i == j) continue;
      PII p = {xy[i].FI - xy[j].FI, xy[i].SE - xy[j].SE};
      int cnt = 0;
      FOR(k, 0, n) {
        PII p2 = {xy[k].FI + p.FI, xy[k].SE + p.SE};
        if (s.count(p2)) cnt++;
      }
      ans = max(ans, cnt);
    }
  }

  cout << n-ans << endl;
  return 0;
}

Measured memory_bytes: 256
#! /usr/bin/perl

use strict;
use warnings;

chomp(my $n500 = <>);
chomp(my $n100 = <>);
chomp(my $n50 = <>);
chomp(my $total = <>);

my $c50 = $total / 50;
my $c100 = 0;
my $c500 = 0;
while($n50 < $c50) {
    $c50 -= 2;
    $c100 ++;
}
while($n100 < $c100) {
    $c100 -= 5;
    $c500 ++;
}
my %seen;
xxx([ $c50, $c100, $c500]);

print scalar(keys %seen), "\n";

sub xxx {
    my $list = shift;
    my($c50, $c100, $c500) = @$list;

    return unless (0 <= $c50  && $c50 <= $n50 &&
       0 <= $c100 && $c100 <= $n100 &&
       0 <= $c500 && $c500 <= $n500);

    my $key = "$c50,$c100,$c500";
    return if $seen{$key};

    $seen{$key} = 1;
    if(2 <= $c50) {
        xxx([ $c50-2, $c100+1, $c500]);
    }
    if(10 <= $c50) {
        xxx([ $c50-10, $c100, $c500+1]);
    }
    if(5 <= $c100) {
        xxx([ $c50, $c100-5, $c500+1]);
    }
}


Measured memory_bytes: 768
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int n,minn=2147483647,maxx;
int main()
{
	scanf("%*d%d",&n);
	for(int i=1;i<=n;i++)
	{
		int l,r;
		scanf("%d%d",&l,&r);
		minn=min(minn,r);
		maxx=max(maxx,l);
	}
	if(minn>=maxx)printf("%d\n",minn-maxx+1);
	else printf("0\n");
	return 0;
}

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

using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> Vi;
typedef tuple<int, int, int> T;
#define FOR(i,s,x) for(int i=s;i<(int)(x);i++)
#define REP(i,x) FOR(i,0,x)
#define ALL(c) c.begin(), c.end()
#define DUMP( x ) cerr << #x << " = " << ( x ) << endl

int main() {
  // use scanf in CodeForces!
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  priority_queue<int> pque;
  while (true) {
    string command;
    cin >> command;
    if (command == "end") {
      break;
    } else if (command == "insert") {
      int k;
      cin >> k;
      pque.push(k);
    } else {
      cout << pque.top() << endl;
      pque.pop();
    }
  }
  return 0;
}

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

#define fast ios::sync_with_stdio(false);cin.tie(0); cout.tie(0);
#define pb push_back
#define sz(s) (int)s.size()
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i,n) for(int i=0;i<(int)n;i++)
#define for1(i,n) for(int i=1;i<=(int)n;i++)
#define ford(i, b, a) for (int i = (int)(b); i >= a; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<ll> vl;
const int N = (int)1e5+77;
const ll inf = (ll) 1e15+77;
const ll mod = (ll) 998244353;
const ld pi = acos(-1);

int main() {
    fast;
    ll n, W, w[101], v[101];
    cin >> n >> W;
    for1(i, n) cin >> w[i] >> v[i];
    vector<ll> dp(n * 1000 + 1, inf);
    dp[0] = 0;
    for1(i, n) {
        vector<ll> new_dp(n * 1000 + 1, inf);
        forn(j, n * 1000 + 1) {
            new_dp[j] = min(new_dp[j], dp[j]);
            if (j - v[i] >= 0) new_dp[j] = min(new_dp[j], dp[j - v[i]] + w[i]);
        }
        dp = new_dp;
    }
    int ans = 0;
    forn(i, n * 1000 + 1) if (dp[i] <= W) ans = max(ans, i);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1800
N, *LR = map(int, open(0).read().split())
L, R = LR[::2], LR[1::2]

L.sort(reverse=True)
R.sort()

ans = 0
cur = 0
for l, r in zip(L, R):
    ans = max(ans, cur + l, cur - r, cur + l - r)
    cur += l - r

print(2 * ans)

Measured memory_bytes: 25124
//#include<bits/stdc++.h>
#include<iostream>
#include<vector>
#include<set>
#include<algorithm>
 
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define fast() ios::base::sync_with_stdio(false); cin.tie(NULL);
typedef long long int ll;
//using ll = long long;
 
template<typename T>
inline T Abs(T a){return a < 0 ? -a : a; }
template<typename T>
inline T Max(T a, T b){return a < b ? b : a; }
template<typename T>
inline T Min(T a, T b){return a > b ? b : a; }
 
using namespace std;
 
int main(){
    //fast()
    
    int n; cin >> n;
    vector<string> name;
    set<string> name2;
    vector<int> votes;
    for(int i = 0; i < n; i++){
        string temp; cin >> temp;
        name.push_back(temp);
        name2.insert(temp);
    }

    sort(name.begin(), name.end());
    auto it = name2.begin();
    int max = -1;
    int i = 0;
    while(it != name2.end()){
        int temp = 0;
        for(; i < n; i++){
            if(*it == name[i]){
                temp++;
            }
            else{ break;}
        }
        max = Max<int>(max, temp);
        votes.push_back(temp);
        it++;
    }

    int length3 = votes.size();
    it = name2.begin();
    for(i = 0; i < length3; i++){
        if(votes[i] == max) cout << *it << '\n';
        it++;
    }

    return 0;
}

Measured memory_bytes: 25584
N = int(input())
A = list(map(int, input().split()))
r = 0
ans = 0
tmp = 0
for l in range(N):
    while r <  N  and tmp & A[r] == 0:
        tmp = tmp | A[r]
        r += 1
    ans += r - l
    tmp = tmp ^ A[l]
print(ans)

Measured memory_bytes: 24712
import math
import bisect
def Main(N, M, A):
    A.sort()
    wa = sum(A)
    thres = math.ceil(wa/(4*M))
    i = bisect.bisect_left(A, thres)
    return "Yes" if len(A)-i >= M else "No"
    

def main():
    N, M = map(int, input().split())
    A = list(map(int, input().split()))
    print(Main(N, M, A))

if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
#include <iostream>
using namespace std;
int main(void){
   int a,p,w,g,y,cou;
   cin>>a;
   p=w=g=y=cou=0; 
   char S[a];
   for(int i=0;i<a;i++){
       cin>>S[i];
   }
   for(int i=0;i<a;i++){
       if(S[i]=='P'){
           p++;
       }
       else if(S[i]=='W'){
           w++;
       }
       else if(S[i]=='G'){
           g++;
       }
       else if(S[i]=='Y'){
           y++;
       }
   }
   
       if(p!=0){
           cou++;
       }
       if(w!=0){
           cou++;
       }
       if(g!=0){
           cou++;
       }
       if(y!=0){
           cou++;
       }
   
   
   if(cou==3){
       cout<<"Three"<<endl;
   }
   else{
       cout<<"Four"<<endl;
   }
    
}


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

int main()
{
        int a, b;
        char op;

        while(1) {
                cin >> a >> op >> b;
                if (op == '?') break;

                if (op == '+') cout << a+b << endl;
                else if (op == '-') cout << a-b << endl;
                else if (op == '*') cout << a*b << endl;
                else if (op == '/') cout << a/b << endl;
        }

        return 0;
}

Measured memory_bytes: 3088
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <tuple>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <numeric>
#include <utility>
#include <iterator>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <ctime>
#include <cassert>
#include <random>
#include <cstring>


#define rep(i,n) for(int i=0;i<int(n);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back

using namespace std;
using ll = long long;

const ll mod = 1000000007;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int ddx[8]={-1,-1,0,1,1,1,0,-1};
int ddy[8]={0,1,1,1,0,-1,-1,-1};
bool debug=false;

/*---------------------------------------------------*/

int main(){
  string S;
  while(cin >> S){
    int ioi = 0, joi = 0;
    for(int i = 0; i < S.size() - 2; i++){
      if(S[i] == 'J' && S[i + 1] == 'O' && S[i + 2] == 'I') joi++;
      if(S[i] == 'I' && S[i + 1] == 'O' && S[i + 2] == 'I') ioi++;
    }
    cout << joi << endl;
    cout << ioi << endl;
  }
  return 0;
}


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

int main() {
  long int N, a1 = 0, a2, count = 0;
  cin >> N;
  for (int i = 0; i<N; i++){
    cin >> a2;
    if(a1 > a2) count += a1-a2;
    else a1 = a2;
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 3592
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <functional>
#include <array>
#include <map>
#include <queue>
#include <limits.h>
#include <set>
#include <stack>
#include <random>
#include <complex>
#include <unordered_map>
#define rep(i,s,n) for(int i = (s); (n) > i; i++)
#define REP(i,n) rep(i,0,n)
#define RANGE(x,a,b) ((a) <= (x) && (x) <= (b))
#define DUPLE(a,b,c,d) (RANGE(a,c,d) || RANGE(b,c,d) || RANGE(c,a,b) || RANGE(d,a,b))
#define INCLU(a,b,c,d) (RANGE(a,c,d) && (b,c,d))
#define PW(x) ((x)*(x))
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MODU 1000000007
#define bitcheck(a,b)   ((a >> b) & 1)
#define bitset(a,b)      ( a |= (1 << b))
#define bitunset(a,b)    (a &= ~(1 << b))
#define MP(a,b) make_pair((a),(b))
#define Manh(a,b) (abs((a).first-(b).first) + abs((a).second - ((b).second))
#define pritnf printf
#define scnaf scanf
#define itn int
#define PI 3.141592653589
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T &val) {
	std::fill((T*) array, (T*) (array + N), val);
}
pii Dir [] = {
	{ 1,0 },{ 0,1 }
};



signed main() {
	int n;

	scanf("%d", &n);
	vector<int> t(n);
	int sum = 0;
	REP(i, n) {
		scanf("%d", &t[i]);
		sum += t[i];
	}

	int k;
	scnaf("%d", &k);

	REP(i, k) {
		int a, b;
		scnaf("%d %d", &a, &b);
		printf("%d\n", sum + b - t[a-1]);
	}

	return 0;
}

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

l = [
  [len([n for n in range(1, N+1) if (str(n)[0]==str(i) and str(n)[-1]==str(j))])
     for j in range(1, 10)]
  for i in range(1, 10)
]

ans = 0
for i in range(9):
  for j in range(9):
    ans += l[i][j]*l[j][i]

print(ans)

Measured memory_bytes: 43484
#include <iostream>
#include <cstdio>
#include <cstring>
#define il inline
#define ri register
#define Size 550
#define yyb 1000000007
using namespace std;
int L[Size],dp[2][Size][Size],
	a1[Size],jc[Size],jv[Size],
	a[Size][Size];
il void prepare();
il int pow(int,int),c(int,int);
int main(){
	//freopen("in","r",stdin);
	prepare();
	int N,X;scanf("%d%d",&N,&X);
	for(int i(1);i<=N;++i)
		scanf("%d",&L[i]),++a1[L[i]];
	int now(0);dp[0][0][0]=1;
	for(int i(X),j,k,l;i;now^=1,--i)
		for(memset(dp[now^1],0,sizeof(dp[now^1])),j=0;j<=X;++j)
			for(k=i*j;k<=X;++k)
				for(l=0;l<=j&&i*l<=k;++l)
					dp[now^1][j][k]=(dp[now^1][j][k]+dp[now][j-l][k-i*l]
									 *1ll*jv[l]%yyb*a[k-j*(i-1)][a1[i]])%yyb;
	int ans(0);
	for(int i(0),j;i<=X;++i)
		for(j=i;j<=X;++j)
			ans=(ans+dp[now][i][j]*1ll*c(X-j+1,i)%yyb*jc[i]*(X-j&1?-1:1))%yyb;
	return printf("%d",(ans+yyb)%yyb),0;
}
il int c(int n,int r){
	if(n<0||r<0||n<r)return 0;
	return jc[n]*1ll*jv[r]%yyb*jv[n-r]%yyb;
}
il int pow(int x,int y){
	int ans(1);while(y){
		if(y&1)ans=ans*1ll*x%yyb;
		x=x*1ll*x%yyb,y>>=1;
	}return ans;
}
il void prepare(){
	for(int i(0),j;i<Size;++i)
		for(j=a[i][0]=1;j<Size;++j)
			a[i][j]=i*1ll*a[i][j-1]%yyb;
	for(int i(jc[0]=1);i<Size;++i)
		jc[i]=jc[i-1]*1ll*i%yyb;
	jv[Size-1]=pow(jc[Size-1],yyb-2);
	for(int i(Size-1);i;--i)
		jv[i-1]=jv[i]*1ll*i%yyb;
}


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

typedef long long ll;
using namespace std;

ll mod=1e9+7;

void io(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);    
    #ifdef LOCAL
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif
}
int m1 = 1e9, m2 = 1e9, ans = 1e9;
int main(){
    io();
    int a, b, m;
    cin >> a >> b >> m;
    int ar[a], br[b];
    for(int i = 0; i < a; i++) {
        cin >> ar[i];
        m2 = min(m2, ar[i]);
    }
    for(int i = 0; i < b; i++) {
        cin >> br[i];
        m1 = min(m1, br[i]);
    }
    for(int i = 0; i < m; i++) {
        int x, y, z;
        cin >> x >> y >> z;
        x--; y--;
        ans = min(ans, ar[x] + br[y] - z);
    }
    cout << min(m1 + m2, ans);



}


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

using namespace std;


//repetition
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define euc_dis(x, y) sqrt(x*x + y*y)

#define pb push_back
#define INF 999999999
#define MOD 1000000007
#define sp ' '


//typedef
typedef long long ll;
typedef pair<int, int> pint;
typedef pair<long, long> pll;
typedef map<int, int> mint;
typedef set<int> sint;
typedef vector<int> vint;
typedef vector<char> vchr;
typedef vector<long long> vll;
typedef vector<string> vstr;


ll mod(ll a, ll b){return (a%b+b)%b;}
ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void Judge(bool b){b?Yes():No();}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void JUDGE(bool b){b?YES():NO();}
ll powMod(ll a, ll b, ll c){ll ans=1; rep(i, b){ans=ans*a%c;} return ans;}
double distance(ll x1, ll y1, ll x2, ll y2){return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));}

template<typename T>
void ppp(T n){cout << n << endl;}
template<typename T>
void dpp(T n){cerr << n << endl;}
template<typename T>
void vpp(T a){rep(i,a.size()){cout << a[i] << endl;}}
template<typename T>
void vdp(T a){rep(i,a.size()){cerr << a[i];}cerr << endl;}

const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int ddx[8] = {1,0,-1,0,1,-1,-1,1};
const int ddy[8] = {0,1,0,-1,1,1,-1,-1};

int main(){

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

    int n;
    cin >> n;

    ll ans = 0;
    map<char, ll> mp;


    int patt[10][3] = {{0,1,2}, {0,1,3}, {0,1,4}, {0,2,3}, {0,2,4}, {0,3,4}, {1,2,3}, {1,2,4}, {1,3,4}, {2,3,4}};

    ll cnt[5] = {0};
    rep(i, n){
        string s;
        cin >> s;
        switch(s[0]){
            case 'M':
                cnt[0]++; break;
            case 'A':
                cnt[1]++; break;
            case 'R':
                cnt[2]++; break;
            case 'C':
                cnt[3]++; break;
            case 'H':
                cnt[4]++; break;

        }
    }

    rep(i, 10){
        ans += cnt[patt[i][0]] * cnt[patt[i][1]] * cnt[patt[i][2]];
    }

    ppp(ans);


    return 0;
}


Measured memory_bytes: 256
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstring>
#include <deque>
#include <forward_list>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;
typedef long long ll;
typedef bitset<16> BS;

const ll MOD = 1E+09 + 7;
const ll INF = 1E18;
const int MAX_N = 100;

int N;

int F[MAX_N + 1][5][2];
ll P[MAX_N + 1][11];

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

    cin >> N;

    for (int i = 1; i <= N; i++) {
        for (int j = 0; j < 5; j++) {
            for (int k = 0; k < 2; k++) {
                cin >> F[i][j][k];
            }
        }
    }

    for (int i = 1; i <= N; i++) {
        for (int j = 0; j <= 10; j++) {
            cin >> P[i][j];
        }
    }

    ll ans = -INF;
    for (int am = 0; am < 1 << 5; am++) {
        int shop[N + 1] = {};
        for (int i = 0; i < 5; i++) {
            if ((am >> i) & 1) {
                for (int j = 1; j <= N; j++) {
                    shop[j] += F[j][4 - i][0];
                }
            }
        }
        for (int pm = 0; pm < 1 << 5; pm++) {
            if (am == 0 && pm == 0)
                continue;
            int shop2[N + 1];
            memcpy(shop2, shop, sizeof(shop));
            for (int i = 0; i < 5; i++) {
                if ((pm >> i) & 1) {
                    for (int j = 1; j <= N; j++) {
                        shop2[j] += F[j][4 - i][1];
                    }
                }
            }
            ll res = 0;
            for (int i = 1; i <= N; i++) {
                res += P[i][shop2[i]];
            }
            ans = max(ans, res);
        }
    }

    /*
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            cout << "i = " << i << ", j = " << j << ", dp = " << dp[i][j] << "\n";
        }
    }
    */

    cout << ans << "\n";

    return 0;
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
int main(){
  int64_t X,Y,Z,K;
  cin>>X>>Y>>Z>>K;
  vector<int64_t>A(X);
  for(int i=0;i<X;i++)
    cin>>A.at(i);
   vector<int64_t>B(Y);
  for(int i=0;i<Y;i++)
    cin>>B.at(i);
   vector<int64_t>C(Z);
  for(int i=0;i<Z;i++)
    cin>>C.at(i);sort(A.begin(),A.end());sort(B.begin(),B.end());
  sort(C.begin(),C.end());reverse(A.begin(),A.end());
  reverse(B.begin(),B.end());reverse(C.begin(),C.end());
  vector<int64_t>D;
  for(int i=1;i<=X;i++)
    for(int j=1;j<=min(K/i,Y);j++)
      for(int k=1;k<=min((K/i)/j,Z);k++)
        D.push_back(A[i-1]+B[j-1]+C[k-1]);
  sort(D.begin(),D.end());reverse(D.begin(),D.end());
  for(int i=0;i<K;i++)
    cout<<D[i]<<endl;
    return 0;
}

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

const int MX = 1000000;
bool prime[MX];
int cnt[MX];

int main() {
    for (int i=0; i<MX; ++i) prime[i] = true;
    prime[0] = prime[1] = false;
    for (int i=2; i<MX; ++i) {
        if ( ! prime[i]) continue;
        for (int j=i; (long long)i*j<MX; ++j) {
            prime[i*j] = false;
        }
    }
    cnt[0] = 0;
    for (int i=1; i<MX; ++i) {
        cnt[i] = cnt[i-1] + prime[i];
    }
    int N;
    while (cin >> N) {
        cout << cnt[N] << endl;
    }
    return 0;
}

Measured memory_bytes: 6044
#include<bits/stdc++.h>
using namespace std;
int i,j,k,n,m;string s;double x,ans;
int main(){
	cin>>n;
	for(i=1;i<=n;i++){
		cin>>x>>s;
		if(s=="BTC")
			x*=380000.0;
		ans+=x;
	}
	printf("%lf",ans);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define mod 1000000007
#define trace(x) cerr<<#x<<": "<<x<<" "<<endl
#define tarce(x) cerr<<#x<<": "<<x<<" "<<endl
#define trace2(x, y) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z) cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define sa(a,n) for(int i =0 ; i<n ; i++) cin>>a[i]
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define pb push_back
#define inf 2e18
#define scan() int n; cin>>n ; int a[n]; for(int i = 0 ; i<n ; i++) cin>>a[i]
#define print(a,n) for(int i = 0 ; i < n ; i++) cout<<a[i]<<' '
#define mem(a,v) memset(a,v,sizeof(a))
#define pii pair<int,int>
#define mkp make_pair
using namespace std;
#define N 200005


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

        int n,m;
        cin >> n >> m;
        int ans=0;
        if(n>1)
         ans+=(n*(n-1))/2;
        if(m>1)
        ans+=(m*(m-1))/2;
        cout << ans << '\n';
        
        

}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
int m;
double n;
bool flag;
vector<int> t;
vector<int> u;
int main(){
  while(1){
    cin>>n;
    if(n==-1.0)break;
    t.clear();
    u.clear();
    flag=false;
    m=n;
    n-=m;
    for(int i=128;i>=1;i/=2){
      if(m<i){
	t.push_back(0);
      }else{
	m-=i;
	t.push_back(1);
      }
    }
    if(m!=0)flag=true;
    double j=0.5;
    for(int i=0;i<4;i++){
      if(n<j){
	u.push_back(0);
      }else{
	n-=j;
	u.push_back(1);
      }
      j*=0.5;
    }
    if(n!=0)flag=true;
    if(flag){
      cout<<"NA"<<endl;
    }else{
      for(int i=0;i<8;i++)cout<<t[i];
      cout<<'.';
      for(int i=0;i<4;i++)cout<<u[i];
      cout<<endl;
    }
  }
  return 0;
}

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

int n;
int h[100000];
bool f = 0, g = 1;

int main()
{
	cin >> n;

	for (int i = 0; i < n; i++)
		cin >> h[i];

	for (int i = 0; i < n - 1; i++) {
		if (h[i + 1] > h[i])
			f = 0;
		else if (h[i + 1] == h[i])
			continue;
		else if (h[i + 1] == h[i] - 1 && !f)
			f = 1;
		else {
			g = 0;
			break;
		}
	}

	if (g)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 768
t1, t2 = gets.split.map(&:to_i)
a1, a2 = gets.split.map(&:to_i)
b1, b2 = gets.split.map(&:to_i)
da1 = t1 * a1
db1 = t1 * b1
df1 = da1 - db1
da2 = t2 * a2
db2 = t2 * b2
df2 = da2 - db2

if df1 > 0
    df1 *= -1
    df2 *= -1
end

if df1 + df2 == 0
    puts "infinity"
elsif df1 + df2 < 0
    puts 0
else
    s = -1 * df1 / (df1 + df2)
    t = (-1 * df1) % (df1 + df2)
    if t == 0
        ans = s * 2
    else
        ans = s * 2 + 1
    end
end
puts ans

Measured memory_bytes: 3836
#include <iostream>
#include <string>

using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)

char a[51][51], b[51][51];
int n, m;

bool check_char(int xpos, int ypos)
{
  REP(i, m)
    REP(k, m)
      if(a[i + xpos][k + ypos] != b[i][k]) return false;
  return true;
}

int main()
{
  cin >> n >> m;
  REP(i, n)
    REP(k, n)
      cin >> a[i][k];
  REP(i, m)
    REP(k, m)
      cin >> b[i][k];
  bool flg = false;
  REP(i, n) {
    REP(k, n) {
      if(a[i][0] == b[0][0] && check_char(i, k)){
        flg = true;
        break;
      }
      if(flg) break;
    }
  }
  if(flg)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}


Measured memory_bytes: 256
EPS = 1e-9
class Point
  attr_accessor :x, :y 
  def initialize p
    @x = p[0]
    @y = p[1]
  end
end
def cross(p1,p2,p3,p4)
  a = (p4.y - p3.y)*(p4.x - p1.x) - (p4.x - p3.x)*(p4.y - p1.y)
  b = (p2.x - p1.x)*(p4.y - p1.y) - (p2.y - p1.y)*(p4.x - p1.x)
  c = (p2.x - p1.x)*(p4.y - p3.y) - (p2.y - p1.y)*(p4.x - p3.x)
  return nil if c.abs < EPS
  d = a / c
  e = b / c
  return nil if d < 0 || d > 1 || e < 0 || e > 1
  Point.new([(p2.x - p1.x) * d + p1.x, (p2.y - p1.y) * d + p1.y])
end
while gets
  break if $_.strip == "0 0 0 0"
  l1 = $_.split.map(&:to_f)
  l2 = gets.split.map(&:to_f)
  l3 = gets.split.map(&:to_f)
  p1 = Point.new(l1[0,2])
  p2 = Point.new(l1[2,2])
  p3 = Point.new(l2[0,2])
  p4 = Point.new(l2[2,2])
  p5 = Point.new(l3[0,2])
  p6 = Point.new(l3[2,2])

  c1 = cross(p1,p2,p3,p4)
  c2 = cross(p3,p4,p5,p6)
  c3 = cross(p5,p6,p1,p2)

  unless c1 && c2 && c3
    puts "kyo"
  else
    s = ((c2.x - c1.x)*(c3.y - c1.y) - (c2.y - c1.y)*(c3.x - c1.x)).abs / 2
    if (c2.x - c1.x).abs < EPS && (c2.y - c1.y).abs < EPS then puts "kyo"
    elsif s >= 1_900_000 then puts "dai-kichi"
    elsif s >= 1_000_000 then puts "chu-kichi"
    elsif s >= 100_000 then puts "kichi"
    else puts "syo-kichi"
    end
  end
end

Measured memory_bytes: 8728
import java.util.*;
class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] ary = new int[n+1];
        for(int i=1;i<n;i++){
            ary[sc.nextInt()] ++;
        }
        for(int i=1;i<n+1;i++){
            System.out.println(ary[i]);
        }
        }
        }


Measured memory_bytes: 63620
N = int(input())
a = list(map(int, input().split()))

a_map = {}
for _a in a:
    if _a not in a_map:
        a_map[_a] = 1
    else:
        a_map[_a] += 1
keys =list(a_map.keys())[::]
for k in keys:
    if a_map[k] < 2:
        a_map.pop(k)

candidates = []
for k in a_map.keys():
    num = a_map[k]
    for n in range(num//2):
        candidates.append([k, 2])

if len(candidates) < 2:
    print(0)
else:
    candidates.sort(key=lambda x: x[0], reverse=True)
    print(candidates[0][0] * candidates[1][0])


Measured memory_bytes: 17936
def sm(x):
    a = 0
    a += (x%10)
    a += (x//10)%10
    a += ((x//10)//10)%10
    a += (((x//10)//10)//10)%10
    a += ((((x//10)//10)//10)//10)%10
    return a
 
N, A, B = map(int,input().split())
ans = 0
for i in range(1, N+1):
    if A <= sm(i) <= B:
        ans += i
print(ans)

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

using namespace std;
using ll = long long;

//container util
#define SORT(c) sort((c).begin(),(c).end())
#define all(a) (a).begin(), (a).end()

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//print
#define pv(val) cerr << #val << '=' << (val) << endl

const int INF = 1e9;

int main(void){

	int N; cin >> N;

	vector<int> x(N);
	vector<int> y(N);

	REP(i,N) cin >> x[i] >> y[i];

	vector<int> idx(N);
	REP(i,N) idx[i] = i;
	int cnt = 1;
	REP(i,N){
		cnt *= (N-i);
	}

	double ans = 0.0;
	do{
		double sum = 0.0;
		FOR(i,1,N){
			int prev = idx[i-1];
			int now = idx[i];
			sum += sqrt(pow(x[prev]-x[now], 2) + pow(y[prev]-y[now], 2));
		}
		ans += sum;
	}while(next_permutation(all(idx)));

	ans /= cnt;
	printf("%.10f\n", ans);

	return 0;

}


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

int main () {
  string s;
  int a = 0, b = 0;

  cin >> s;
  for(char c: s) {
    if(c == '0') {
      a++;
    } else {
      b++;
    }
  }

  cout << min(a,b) * 2 << endl;

  return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<utility>
#include<set>
#include<stack>
#include<list>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cstring>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<cmath>
#include<cctype>


#define pb push_back
#define mp make_pair
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define ren(i,a,b) for(int i=a;i>=b;i--)
#define ff first
#define ss second
#define pll pair<long long int,long long int>
#define pii pair<int,int>
#define vll vector<long long int>
#define vii vector<int>
#define gi(n) scanf("%d",&n)
#define gll(n) scanf("%lld",&n)
#define gstr(n) scanf("%s",n)
#define gl(n) cin >> n
#define oi(n) printf("%d",n)
#define oll(n) printf("%lld",n)
#define ostr(n) printf("%s",n)
#define ol(n) cout << n
#define os cout<<" "
#define on cout<<"\n"
#define o2(a,b) cout<<a<<" "<<b
#define all(n) n.begin(),n.end()
#define present(s,x) (s.find(x) != s.end())
#define cpresent(s,x) (find(all(s),x) != s.end())
#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++)
using namespace std;

typedef unsigned long long int ull;
typedef long long int ll;
typedef long double ld;
typedef vector<vector<ll> > mat;

int main()
{ios_base::sync_with_stdio(false);
int n;
cin>>n;
int a[100005],ans=0;
rep(i,1,n)cin>>a[i];
rep(i,2,n-1)
{
	int x=min(min(a[i-1],a[i]),a[i+1]);
	int y=max(max(a[i-1],a[i]),a[i+1]);
	if(a[i]>x&&a[i]<y)ans++;
}
ol(ans);
return 0;
}



Measured memory_bytes: 256
n,m = map(int,input().split())
g = []
dp = [[float('inf')]*n for _ in range(n)]
for i in range(n):
    dp[i][i]=0
for _ in range(m):
    a,b,c = map(int,input().split())
    g.append((a-1,b-1,c))
    dp[a-1][b-1] = c
    dp[b-1][a-1] = c
for k in range(n):
    for i in range(n):
        for j in range(n):
            dp[i][j] = min(dp[i][j],dp[i][k]+dp[k][j])
# print(dp)
cnt = 0

for a,b,c in g:
    f = True
    for i in range(n):
        if dp[i][a]+c==dp[i][b]:
            f = False
            break
    if f:
        cnt += 1
print(cnt)

Measured memory_bytes: 69044
#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>

using namespace std;

void bfs(vector<vector<int>>& g, vector<int>& dist) {
    queue<int> q;
    vector<bool> visited(g.size(), false);
    q.push(1);
    dist[1] = 0;
    while (!q.empty()) {
        int idx = q.front();
        q.pop();
        visited[idx] = true;

        for (int i = 0; i < g[idx].size(); ++i) {
            int adj = g[idx][i];
            if (!visited[adj]) {
                q.push(adj);
                if (dist[adj] != -1)
                    dist[adj] = min(dist[adj], dist[idx] + 1);
                else
                    dist[adj] = dist[idx] + 1;
            }
        }
    }
}

int main() {
    int n;
    cin >> n;

    vector<vector<int>> g(n + 1);
    for (int i = 1; i <= n; ++i) {
        int u, k;
        cin >> u >> k;

        for (int j = 0; j < k; ++j) {
            int v;
            cin >> v;
            g[i].push_back(v);
        }
    }

    vector<int> dist(n + 1, -1);
    bfs(g, dist);

    for (int i = 1; i <= n; ++i)
        cout << i << ' ' << dist[i] << '\n';
}



Measured memory_bytes: 3208
n, k = map(int, input().split())
from collections import defaultdict as dd
dic = dd(lambda: 0)
for i in range(n):
  a, b = map(int, input().split())
  dic[a] += b

for key in sorted(dic.keys()):
  if k <= dic[key]:
    print(key)
    break
  else:
    k -= dic[key]

Measured memory_bytes: 50392
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstdio>
#include <iomanip>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <stdlib.h>
#include <set>
typedef long long ll;
using namespace std;

int main() {
	int a,b,c;
	cin>>a>>b>>c;
	if(a==b && a==c){
		cout<<1<<endl;
	}else if(a==b || a==c ||b==c){
		cout<<2<<endl;
	}else{
		cout<<3<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define PI 3.14159265358979323846264338327950L

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define INF 1000000000000 //10^12
#define MOD 10000007 //10^9+7
#define PB push_back

template<typename T, typename U, typename Comp=less<>>
bool chmax(T& xmax, const U& x, Comp comp={}) {
    if(comp(xmax, x)) {
        xmax = x;
        return true;
    }
    return false;
}

template<typename T, typename U, typename Comp=less<>>
bool chmin(T& xmin, const U& x, Comp comp={}) {
    if(comp(x, xmin)) {
        xmin = x;
        return true;
    }
    return false;
}

ll gcd(ll a, ll b){
    if(a % b == 0){
        return(b);
    }
    else{
        return(gcd(b, a % b));
    }
}

bool isPalindrome(string s){
    REP(i, s.length() / 2){
        if(s[i] != s[(s.length() - 1) - i]){
            return false;
        }
    }
    return true;
}

//scanf("%lld", &);
//cin >> ;
//cout << ans << endl;

ll N, M, i, j, k, l, tmp, ans, X, T;
ll D, x, y;
ll cnt;

int main(){
    string s;
    cin >> s;
    N = 0;

    for(int i = 0; i < s.length(); i++){
        N += s.at(i) - '0';
    }

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

    return 0;
}

Measured memory_bytes: 3692
#include "bits/stdc++.h"
using namespace std;
const int MAX = 700000;
const int MOD = 1000000007;

long long  fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
/*第二引数で第一引数を割ったときの切り上げの計算*/
long long int maxtime(long long int x, long long int y){
	return(x + y - 1) / y;

}
/*最大公約数*/
long long int lcm(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;

	if (number2 > number1) {
		m = number2;
		n = number1;
	}
	long long int s = -1;
	while (s != 0) {
		s = m % n;
		m = n;
		n = s;
	}
	return m;
}
/*最大公倍数*/
long long int gcd(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;
	return m / lcm(m, n) * n;
}
/*逆元計算*/
long long int  modinv(long long a, long long m) {
	long long int b = m, u = 1, v = 0;
	while (b) {
		long long int t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
// index が条件を満たすかどうか
vector<long long int >meguru;
bool isOK(int index, int key) {
	if (meguru[index] >= key) return true;
	else return false;
}
// 汎用的な二分探索のテンプレ
int binary_search(int key) {
	int left = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
	int right = (int)meguru.size(); // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()
	/* どんな二分探索でもここの書き方を変えずにできる！ */
	while (right - left > 1) {
		int mid = left + (right - left) / 2;

		if (isOK(mid, key)) right = mid;
		else left = mid;
	}
	/* left は条件を満たさない最大の値、right は条件を満たす最小の値になっている */
	return right;
}
long long modpow(long long a, long long n, long long mod) {
	long long res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}
long long int big[60][2] = {};

int main() {
	int k;
	cin >> k;
	long long int ans = 0;
	for (long long int i = 1; i <= k; i++) {
		for (long long int j = 1; j <= k; j++) {
			for (long long int l = 1; l <= k; l++){
				long long int  t = lcm(i, j);
				long long int  f = lcm(t, l);
				ans = ans + f;
			}
		}
	}
	cout << ans;
}

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

int main(){
	int n;
	int T[105]={};
	int N=0;
	cin>>n;
	for(int i=0;i<n;i++)
		N+=i;
	//cout<<N;
	for(int I=0;I<N;I++){
	int A,B,C,D;
	cin>>A>>B>>C>>D;
	if(C<D){
		T[B]+=3;
	}
	else if(C>D)T[A]+=3;
	else{
		T[A]++;T[B]++;
	}
	}
//	cout<<N;
	int P[105]={};
	for(int i=0;i<102;i++)
	{	P[i]=T[i];
	//cout<<P[i]<<endl;
	}
	for(int i=1;i<=n;i++)
		for(int j=n;j>i;j--)
		{if(T[j]>T[j-1]){int t=T[j];T[j]=T[j-1];T[j-1]=t;}}

	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
			{if(P[i]==T[j]){
				cout<<j<<endl;break;
		}}
		return 0;
}

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

int N;
vector<int> A;

int main(){
	cin >> N;
	A = vector<int>(N);
	for (int i = 0; i < N; i++)
	{
		cin >> A[i];
	}
	
	int first = 0;
	for (int i = 0; i < N; i++)
	{
		if(A[i] > A[first]) first = i;
	}
	int second = (first + 1) % N;
	for (int i = 0; i < N; i++)
	{
		if(i == first) continue;
		if(A[i] > A[second]) second = i;
	}
	
	for (int i = 0; i < N; i++)
	{
		if (i == first) {
			cout << A[second] << '\n';
		} else {
			cout << A[first] << '\n';
		}
	}
	cout << flush;
	return 0;
}

Measured memory_bytes: 2432
#include<bits/stdc++.h>
#define maxn 200010
using namespace std;
int head[maxn], nxt[maxn * 2], a[maxn * 2], in[maxn], out[maxn], mx[maxn];
int node[maxn], sum[maxn], edge, now, jump[maxn][20], val[maxn][20], dep[maxn];
void create(int u, int v)
{
	edge++; a[edge] = v; nxt[edge] = head[u]; head[u] = edge;
}
void dfs(int u, int fa)
{
	in[u] = ++now; jump[u][0] = fa; val[u][0] = u;
	dep[u] = dep[fa] + 1;
	for (int i = head[u]; i; i = nxt[i])
	{
		int v = a[i];
		if (v != fa)
		{
			mx[v] = max(v, mx[u]);
			dfs(v, u);
		}
	}
	out[u] = now;
}
int main()
{
	int n;
	scanf("%d", &n);
	for (int i = 1; i <= n - 1; i++)
	{
		int u, v;
		scanf("%d%d", &u, &v);
		create(u, v); create(v, u);
	}
	mx[1] = 1;
	dfs(1, 0);
	int tmp = 1, lg = 0;
	while (tmp <= n) {tmp *= 2; lg++;}
	for (int j = 1; j <= lg; j++)
		for (int i = 1; i <= n; i++)
		{
			int tmp = jump[i][j - 1];
			jump[i][j] = jump[tmp][j - 1];
			val[i][j] = max(val[i][j - 1], val[tmp][j - 1]);
		}
	for (int i = 2; i <= n; i++)
	{
		int u = i, cur_mx = 0;
		for (int j = lg; j >= 0; j--)
		{
			int tmp = jump[u][j];
			if (dep[tmp] <= 1) continue;
			if (max(cur_mx, val[u][j]) < mx[jump[tmp][0]])
			{
				cur_mx = max(cur_mx, val[u][j]);
				u = tmp;
			}
		}
		sum[in[u]]++; sum[out[u] + 1]--;
	}
	for (int i = 1; i <= n; i++)
		sum[i] += sum[i - 1];
	for (int i = 2; i <= n; i++)
		printf("%d ", sum[in[i]]);
	puts("");
	return 0;
}

Measured memory_bytes: 50816
using System;

namespace ABC070_C___Multiple_Clocks
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            long result = 1;
            for (int i = 0; i < N; i++)
            {
                var T = long.Parse(Console.ReadLine());
                result = T / GCD(T, result) * result;
            }
            Console.WriteLine(result);
        }
        static long GCD(long A, long B)
        {
            if (B > A) return GCD(B, A);
            while (B != 0)
            {
                var reminder = A % B;
                A = B;
                B = reminder;
            }
            return A;
        }
    }
}


Measured memory_bytes: 11092
/*-- ILSH  --*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define pb push_back 
#define pop pop_back
#define mp make_pair
#define vii vector < int >
#define vll vector < ll > 
#define dt cout<<"HERE\n";
#define pii pair < int , int >
#define pll pair < ll , ll >
#define vpi vector < pll >
#define vpl vector < pll >
#define fi first
#define se second 
#define sz size 
#define len length 

const ll inf=1e18+1e17;
const ll mod =1e9+7;
//const ll mod = 998244353;

ll modInverse(ll a,ll m){ll m0=m;ll y=0,x=1;if(m == 1)return 0;while(a> 1){ll q=a/m;ll t=m;m=a%m,a=t;t=y;y=x-q*y;x=t;}if(x<0)x+=m0;return x;}  
ll powm(ll a,ll b){a=a%mod;ll res=1;while(b){if(b&1)res=(res*a)%mod;a=(a*a)%mod;b>>=1;}return (res%mod);}


const ll N =5e5+5;



void solve(){
	string s,t;
	cin>>s>> t;
	ll n=s.len(),m=t.len();
	ll arr[n+1],brr[m+1];
	arr[0]=0;brr[0]=0;
	for ( int i=1;i<=n;i++)
		arr[i]=arr[i-1]+( s[i-1]=='A'?1:0);
	for ( int i=1;i<=m;i++)
		brr[i]=brr[i-1]+( t[i-1]=='A'?1:0);
	ll q;
	cin>>q;
	while ( q-- ){
		ll aa,bb,cc,dd;
		cin>>aa>>bb>>cc>>dd;
		aa--,cc--;
		ll a1=arr[bb]-arr[aa],a2=brr[dd]-brr[cc],b1=bb-aa-a1,b2=dd-cc-a2;
		ll cal1=b1*2+a1;
		ll cal2=b2*2+a2;
		cal1=cal1%3;
		cal2=cal2%3;
		if ( cal1==cal2)
			cout<<"YES\n";
		else
			cout<<"NO\n";
	}
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie( NULL);
	cout.tie(NULL);
	// #ifndef
	// 	freopen( "INPUT.txt", "r" , stdin);
	// 	freopen( "OUTPUT.txt","w", stdout);
	// #endif

	int t=1;

	//cin>>t;

	for ( int i=1;i<=t;i++){
   // 	cout<<"Case #"<<i<<": ";
    	solve();
 	}
}

Measured memory_bytes: 2512
import java.util.*;
import java.io.*;
import java.math.*;


import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;


public class Main{ 


    static long mod=1000000007;
    //  static int dx[]={1,-1,0,0};
    //  static int dy[]={0,0,1,-1};
    // static int dx[]={1,-1,0,0,1,1,-1,-1};
    // static int dy[]={0,0,1,-1,1,-1,1,-1}; 

public  static void main(String[] args)   throws Exception, IOException{

    
    Reader sc = new Reader(System.in);
    PrintWriter out=new PrintWriter(System.out);

//  int n=sc.nextInt();  
  // int n=sc.nextInt(), k=sc.nextInt();  
  // int s=sc.nextInt(), t=sc.nextInt(); 
    int n = sc.nextInt();
    int t = sc.nextInt();
    int end = t;
    long s=t;
    sc.nextInt();
    for( int i=1; i<n; i++ ){
       int x = sc.nextInt();
       if( x <= end) s+= x + t - end;
       else s += t;
    end = x + t;
    }

    out.println(s);
    out.flush();
}

static void db(Object... os){

    System.err.println(Arrays.deepToString(os));

}

static boolean validpos(int x,int y,int r, int c){
    
    return x<r && 0<=x && y<c && 0<=y;
    
}
 
static boolean bit(long x,int k){
    // weather k-th bit (from right) be one or zero
    return  ( 0 < ( (x>>k) & 1 )  )  ? true:false;
}

}







class Reader
{ 
    private BufferedReader x;
    private StringTokenizer st;
    
    public Reader(InputStream in)
    {
        x = new BufferedReader(new InputStreamReader(in));
        st = null;
    }
    public String nextString() throws IOException
    {
        while( st==null || !st.hasMoreTokens() )
            st = new StringTokenizer(x.readLine());
        return st.nextToken();
    }
    public int nextInt() throws IOException
    {
        return Integer.parseInt(nextString());
    }
    public long nextLong() throws IOException
    {
        return Long.parseLong(nextString());
    }
    public double nextDouble() throws IOException
    {
        return Double.parseDouble(nextString());
    }
}



Measured memory_bytes: 42608