akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
using namespace std;

int w, h;
int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};

void dfs(vector< vector<char> > &plane, int x, int y, int &ans){  
  plane[x][y] = '#';
  ans++;
  for(int i=0; i<4; i++){
    if(0 <= x+dx[i] && x+dx[i] < w && 0 <= y+dy[i] && y+dy[i] < h)
      if(plane[x + dx[i]][y + dy[i]] != '#')
        dfs(plane, x + dx[i], y + dy[i], ans);
  }
  
  return;
}

int main(){
  while(true){
    cin >> w >> h;
    if(w == 0)
      break;

    int sx, sy;
    vector< vector<char> > plane(w, vector<char>(h));
    for(int i=0; i<h; i++){
      for(int j=0; j<w; j++){
        cin >> plane[j][i];
        if(plane[j][i] == '@'){
          sx = j;
          sy = i;
        }
      }
    }

    int ans = 0;
    dfs(plane, sx, sy, ans);
    cout << ans << endl;
  }
  
  return 0;
}

Measured memory_bytes: 3148
N= int(input())
A = list(map(int,input().split()))

B = []
for i in range(N):
    B.append(A[i]-(i+1))
#print(B)
b= (sorted(B)[N//2])
#print(b)
ans = 0
for i in range(N):
    ans += abs(B[i]-b)
print(ans)

Measured memory_bytes: 30980
#include<iostream>
#include<vector>

using namespace std;

#define int long long

const int MOD = 1000000007;

signed main(){
	
	const int MAX = 401;
	
	int N, C;
	int sum = 0;
	vector<int> A, B;
	vector<vector<int>> dp, table(MAX, vector<int>(MAX));

	cin>>N>>C;

	A.resize(N);
	B.resize(N);

	dp.resize(N+1, vector<int>(C+1));

	for(int i = 0; i < N; i++){
		cin>>A[i];
	}

	for(int j = 0; j < N; j++){
		cin>>B[j];
	}
	
	for(int i = 0; i < MAX; i++) table[0][i] = 0;
	for(int i = 0; i < MAX; i++) table[i][0] = 1;
	
	for(int i = 1; i < MAX; i++){
		for(int j = 1; j < MAX; j++){
			table[i][j] = table[i][j-1] * i;
			table[i][j] %= MOD;
		}
	}
	
	for(int i = 1; i < MAX; i++){
		for(int j = 0; j < MAX; j++){
			table[i][j] += table[i-1][j];
			table[i][j] %= MOD;
		}
	}

	dp[0][0] = 1;

	for(int i = 0; i < N; i++){
		for(int j = C; j >= 0; j--){
			for(int k = j; k <= C; k++){
				dp[i+1][k] += dp[i][j] * (table[B[i]][k-j] - table[A[i]-1][k-j] + MOD)% MOD;
				dp[i+1][k] %= MOD;
			}
		}
	}

	cout<<dp[N][C]<<endl;

	return 0;
}


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

int main(){
  int N;
  cin >> N;
  vector<int> vec(N);
  for(int i=0; i<N; i++){
    cin >> vec.at(i);
  }
  sort(vec.begin(), vec.end());
  reverse(vec.begin(), vec.end());
  int others = 0;
  for(int j=1; j<N; j++){
    others = others + vec.at(j);
  }
  if(vec.at(0) < others){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

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

using namespace std;

#ifdef DEBUG_MODE
	#define DBG(n) n;
#else
	#define DBG(n) ;
#endif
#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int W = 0;W < (n);W++)cerr << v[W] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007

typedef long long ll;
typedef pair<ll,ll> P;
//ａをbで割る
long long mod_div(long long a,long long b){
	if(a % b == 0)return a/b;
	long long tmp = MOD - 2,c = b,ret = 1;
	while(tmp > 0){
		if(tmp & 1){
			ret *= c;ret %= MOD;
		}
		c *= c;c %= MOD;tmp >>= 1;
	}
	return a*ret%MOD;
}

#define MAX_K 2222*2222
vector<long long> kaijo(MAX_K);
long long combination(long long n, long long r){
    if(n < r || n < 0 || r < 0)
        return 0;
	if(kaijo[0] != 1){
		kaijo[0] = 1;
		for(long long i = 1;i < MAX_K;i++)kaijo[i] = (kaijo[i-1] * i) % MOD;
	}
    long long ret = kaijo[n];
	long long tmp = (kaijo[r] * kaijo[n-r]) % MOD;
    return mod_div(ret,tmp);
}

ll dp[2222][2222];

ll n,k;
ll dfs(ll a,ll b){
	if(dp[a][b] != -1){
		return dp[a][b];
	}
	ll ret = 0;
	if(a > 0){
		ret += dfs(a - 1, b);
		ret %= MOD;
	}
	if(b > a){
		ret += combination(a + b * (k - 1) - 1,k - 2) * dfs(a, b - 1) % MOD;
		ret %= MOD;
	}
	return dp[a][b] = ret;
}

int main(){

	REP(i,2222)REP(j,2222)dp[i][j] = -1;

	dp[0][0] = 1;
	cin >> n >> k;
	if(k == 1){
		cout << 1 << endl;
	}
	else{
		ll ans = 1;
		for(ll i = 1;i <= n;i++)ans = (ans * i) % MOD;
		cout << dfs(n,n)*ans%MOD << endl;
	}

	return 0;
}


Measured memory_bytes: 77568
import decimal
a,b,c,d=map(int,input().split())
n=int(input())
l=[a*4,b*2,c,d/2]
p=min(l)
q=min(l[:3])
print(int(decimal.Decimal(n)*decimal.Decimal(min(l))) if n%2==0 or p==q else int(decimal.Decimal(n-1)*decimal.Decimal(d/2)+q))

Measured memory_bytes: 5076
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <stack>
#include <cassert>
#include <string>
#include <cmath>
#include <iomanip>

using namespace std;
using ll = long long;
using ld = long double;

#define st first
#define nd second

const int MAXN = 1e6 + 5, inf = 1e9;
const ll INF = 1e18;
const ld PI = 3.1415926535897932384626433832795;

int ID[MAXN];
bool vis[MAXN];
vector<int> G[MAXN];
stack<int> topo;
int par[MAXN];

void dfs(int v)
{
    vis[v] = 1;
    for (int u : G[v])
    {
        if (vis[u]) continue;
        dfs(u);
    }
    topo.push(v);
}

void sortuj(int n)
{
    for (int i = 1; i <= n; i++)
    {
        if (!vis[i])
        {
            dfs(i);
        }
    }
}

void dfs1(int v) {
    vis[v] = 1;
    for (int u : G[v]) {
        if (vis[u]) {
            continue;
        }
        par[u] = v;
        dfs1(u);
    }
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout << setprecision(13) << fixed;

    //////////////////////////////////////////
    //////////////////////////////////////////

    int n, m;
    cin >> n >> m;
    for (int i = 1; i < n + m; i++) {
        int a, b;
        cin >> a >> b;
        G[a].push_back(b);
    }

    sortuj(n);

    for (int i = 1; i <= n; i++) {
        vis[i] = 0;
    }

    int num = 1;
    int root = topo.top();
    while (!topo.empty()) {
        int v = topo.top();
        topo.pop();
        ID[v] = num++;
        //cout << v << " ";
    }
    for (int i = 1; i <= n; i++) {
        sort(G[i].begin(), G[i].end(), [](int a, int b){
            return ID[a] < ID[b];
        });
    }

    dfs1(root);

    for (int i = 1; i<= n; i++) {
        cout << par[i] << "\n";
    }
}


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

 using namespace std;
 char str[1<<4];
 int main(){
 	int A , B;
   scanf("%d%d",&A,&B);
   scanf("%s",str+1);
   if(strlen(str+1) != A+B + 1){
    printf("No");
     return 0;
   }
   for(int i = 1 ; i <= A+B+1; ++i){
   		if(i <= A and (str[i] > '9' or str[i] < '0') ){
         	printf("No");
          return 0;
        }else if(i == A+1 and str[i] != '-'){
        	printf("No");
          return 0;
        }else if(i > A+1 and (str[i] > '9' or str[i] < '0')){
        	printf("No");
          	return 0;
        }
   }
   printf("Yes");
 }
   

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

using namespace std;

int main(void)
{
    int A, B, C, K;
    cin >> A >> B >> C >> K;

    if(K < A){
        cout << K << endl;
    }
    else if(K < A + B){
        cout << A << endl;
    }
    else{
        cout << A - (K - A - B) << endl;
    }

    return 0;
}

Measured memory_bytes: 3528
#define _USE_MATH_DEFINES
#include <iostream>
#include <algorithm>
#include <queue>
#include <stack>
#include <deque>
#include <climits>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
//#include <tuple>

#define INF INT_MAX>>1 
#define SIZE 100010
#define MOD 1000000007
#define rep(i, n) for(int i=0; i<(int)(n); i++)
#define rep2(i, from, to) for(int i=(from); i<(int)(to); i++)
#define all(obj) (obj).begin(), (obj).end()
#define lpair pair<ll, ll>
#define vint vector<ll>
#define vinput(name) for(int i=0; i<(int)(name.size()); i++) cin >> name[i];
#define voutput(name) for(int i=0; i<(int)(name.size()); i++) cout << name[i] << endl;
typedef long long ll;

using namespace std;

ll ans = 0;

int main(void){
	int n, k;  cin >> n>> k;
	vint p(n); vinput(p);
	double ma = 0;
	vector<double> pp(n);
	rep(i, n){
		pp[i] = (double)p[i]/2 + 0.5;
	}


	vector<double> sums(n);
	sums[0] = pp[0];
	rep2(i, 1, n){
		sums[i] = sums[i-1]+pp[i];
	}

	rep(i, n){
		if(i+k >= n) break;
		if(sums[i+k]-sums[i] > ma){
			ma = sums[i+k]-sums[i];
		}
	}
	if(n == k)ma = sums[n-1];
	printf("%.10lf", ma);
	return 0;
}

Measured memory_bytes: 4992
#include<stdio.h>
int main(){
  long long h,w,x,y;
  scanf("%lld %lld %lld %lld",&h,&w,&x,&y);
  printf("%lf %d\n",1.0*h*w/2,h==x*2&&w==y*2?1:0);
  return 0;
}


Measured memory_bytes: 128
import java.util.*;

public class Main{

    static int[][] M;
    static int[] R;
    static int[] C;

    public static void main(String[] args){

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        M = new int[n][n];
        R = new int[n];/*行 */
        C = new int[n];/*列*/

        for(int i = 0; i < n; i++){
            R[i] = sc.nextInt();
            C[i] = sc.nextInt();
        }
        //System.out.println("Integer.MAX_VALUE = "+Integer.MAX_VALUE);
        /*debug*///long startTime = System.currentTimeMillis(); 
        System.out.println(MCM(0, n-1));
        /*debug*///long endTime = System.currentTimeMillis();
        /*debug*///System.out.println("処理時間：" + (endTime - startTime) + " ms");
    }
    //static int j = 0;
    private static int MCM(int fr, int to){
      //System.out.println("loop:"+(++j));
        if(fr == to) return 0;
        if(M[fr][to] == 0){
            int min = Integer.MAX_VALUE;
            for(int i = fr; i < to; i++){
                int r = MCM(fr, i) + MCM(i+1, to) + (R[fr] * C[i] * C[to]);
                if(r < min) min = r;
            }
            M[fr][to] = min;
        }
        return M[fr][to];
    }
}


Measured memory_bytes: 27156
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  vector<char> c(9);
  for(int i=0;i<9;i++){
  	cin >> c.at(i) ;
  }
  
  for(int i=0;i<9;i++){
  	if(i==0 || i%4==0) cout<<c.at(i);
  }
  cout << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main{
	public static void main(String[] args){
		Scanner stdIn=new Scanner(System.in);
		int h,w,i,j,t=0;
		for(;;){
			h=stdIn.nextInt();
			w=stdIn.nextInt();
			if(h<1&&w<1)break;
			for(i=0;i<h;i++){
				for(j=0;j<w;j++){
					if(t!=0)System.out.print(".");
					else System.out.print("#");
					t=~t;
				}
				if(w%2==0)t=~t;
				System.out.println();
			}
			System.out.println();
			t=0;
		}
	}
}


Measured memory_bytes: 34580
#include<iostream>
#include<cmath>
#include<iomanip>
#include<algorithm>
using namespace std;
int main() {
	double A, B;
	double H, M;
	cin >> A >> B >> H >> M;
	double Aw, Bw;
	Bw = 6.0 * M;
	Aw = 30.0 * H + (Bw / 360.0)*30;
	double theta = 0;
	theta = min(abs(Aw - Bw), 360 - abs(Aw - Bw));
	cout << setprecision(12) << sqrt(pow(A,2)+pow(B,2)-2*A*B*cos(3.14159265358979*theta/180)) << endl;
	return 0;
}

Measured memory_bytes: 4224
#include <stdio.h>

int main(){
	int N,a[100];
	scanf("%d",&N);

	int i,min,max;
	for(i=0;i<N;i++){
		scanf("%d",&a[i]);
		if(i==0){
			min=a[i];
			max=a[i];
		}
		if(a[i]<min)min=a[i];
		if(a[i]>max)max=a[i];
	}
	printf("%d",max-min);
}

Measured memory_bytes: 128
package main

import (
	"bufio"
	"fmt"
	"os"
	"strings"
)

func main() {

	reader := bufio.NewReader(os.Stdin)
	tmp, _ := reader.ReadString('\n')
	tmp = strings.Trim(tmp, "\n")

	r := []rune(tmp)

	ans := r[0] + 1

	fmt.Printf("%s\n", string(ans))
}


Measured memory_bytes: 640
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve(args);
    }

    public void solve(String[] args) {
        MyScanner scanner = new MyScanner();
        int a = scanner.nextInt(); //人数
        int b = scanner.nextInt(); //宿泊日数
        int s = b-a; //余り

        int hight = 0;	// 個数用の変数。X個余ったはずなので、あらかじめ入れておく
//        int tmp;		// ループ用の変数

        // 合宿参加人数分のループ処理
        for(int i = 1; i <= s; i++) {
        	hight +=i;	//数字の受け取り
        }
        System.out.println(hight-b);

    }

    private class MyScanner {
        String[] s;
        int i;
        BufferedReader br;
        String reg = " ";
        MyScanner () {
            s = new String[0];
            i = 0;
            br = new BufferedReader(new InputStreamReader(System.in));
        }
        public String next() {
            try {
                if (i < s.length) return s[i++];
                String line = br.readLine();
                while (line.equals("")) {line = br.readLine();}
                s = line.split(reg, 0);
                i = 0;return s[i++];
            } catch (Exception e) {e.printStackTrace();}
            return null;
        }
        public int nextInt() {
            try {return Integer.parseInt(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        }
        public double nextDouble() {
            try {return Double.parseDouble(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        }
        public long nextLong()  {
            try {return Long.parseLong(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        }
    }
}


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

int calc_score(vector<int> &v, vector<int> &a, vector<int> &b, vector<int> &c, vector<int> &d) {
  const int q = a.size();
  int res = 0;
  for (int i = 0; i < q; i++) {
    if (v.at(b.at(i)) - v.at(a.at(i)) == c.at(i)) {
      res += d.at(i);
    }
  }
  return res;
}

int main() {
  int n, m, q, ans = 0;
  cin >> n >> m >> q;
  vector<int> a(q), b(q), c(q), d(q);
  for (int i = 0; i < q; i++) {
    cin >> a.at(i) >> b.at(i) >> c.at(i) >> d.at(i);
    a.at(i)--;
    b.at(i)--;
  }
  vector<int> v(n);
  while (!v.empty()) {
    while (v.size() < n) v.push_back(v.back());
    ans = max(ans, calc_score(v, a, b, c, d));
    int index = n - 1;
    v.at(index)++;
    while (index > 0 && v.at(index) == m) {
      v.pop_back();
      index--;
      v.at(index)++;
    }
    if (v.at(0) == m) break;
  }
  cout << ans << endl;
}


Measured memory_bytes: 3632
import java.util.*;

public class Main{
  public static void main(String[] args) {
    Scanner sc=new Scanner(System.in);
    int x=sc.nextInt();
    int y=sc.nextInt();
    int xans=0;
    int yans=0;

    if(x==1||x==3||x==5||x==7||x==8||x==10||x==12) xans=1;
    if(x==4||x==6||x==9||x==11) xans=2;
    if(x==2) xans=3;

    if(y==1||y==3||y==5||y==7||y==8||y==10||y==12) yans=1;
    if(y==4||y==6||y==9||y==11) yans=2;
    if(y==2) yans=3;

    if (xans==yans) {
      System.out.println("Yes");
    }else{
      System.out.println("No");
    }
  }
}


Measured memory_bytes: 20820
#include <cstdio>
#include <iostream>
#include <cmath>
using namespace std;
int main() {
    int yen, happyn1,happy5;
    cin >> yen;
    happyn1=yen/500*1000;
    happy5=(yen%500)/5*5;
    cout << happy5+happyn1;
    return 0;
}


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

#define debug(x) cout <<"DEBUG"<<" "<< #x << ":" << x << '\n'

// n回繰り返し
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順
#define rep1(i,n) for(int i = 1; i <= ((int)(n)); i++) // 1-indexed昇順
#define rrep(i,n) for(int i = ((int)(n)-1); i >= 0; i--)  // 0-indexed降順
#define rrep1(i,n) for(int i = ((int)(n)); i >= 1; i--)   // 1-indexed降順
#define all(x) (x).begin(),(x).end()

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vii;  // 2次元配列
typedef vector<ll> vll;
typedef vector<double> vd;
typedef pair<int, int> PII;

template<typename T>
using vec = vector<T>;
template<class T>
using maxheap = std::priority_queue<T>;
template<class T>
using minheap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template<class T,class U> inline bool chmax(T &a, const U &b){if(a<b){a=b;return 1;}return 0;}
template<class T,class U> inline bool chmin(T &a, const U &b){if(a>b){a=b;return 1;}return 0;}

const ld Pi = std::acos(-1.0L);
const ll infll = (1LL<<62)-1;
const int inf = (1<<30)-1;
const int mod = 1000000007;
// const int mod = 998244353;


/*FUNCs=================================================*/


/*MAIN==================================================*/
signed main(){
    int START_TIME = clock();
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化
    // cout << fixed << setprecision(15);

    /**
     * 全てのBを右端に寄せるための移動回数
     */
     ll cnt = 0;
     string s; cin >> s;

     int c = 0;
     rrep(i,s.size()) {
         if(s[i]=='B') {
             ++c;
             cnt += s.size() - c - i;
         }
     }

     cout << cnt << '\n';

    // printf("ExecutionTime: %d /ms\n",1000*(int)((clock()-START_TIME)/CLOCKS_PER_SEC));
}

Measured memory_bytes: 720
// SPDX-License-Identifier: Apache-2.0
// Copyright (C) 2020 Bjarni Dagur Thor Karason

#include <bits/stdc++.h>

using namespace std;

#define rep(i,a,b) for (__typeof(a) i=(a); i<(b); i++)
#define MP make_pair
#define PB push_back
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
#define INF 1000000000
#define PI 3.14159265359

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(nullptr);
    ll x;
    cin >> x;
    for (ll a = -120; a <= 120; a++) {
        for (ll b = -120; b <= 120; b++) {
            if (pow(a, 5) - pow(b, 5) == x) {
                cout << a << " " << b << endl;
                return 0;
            }
        }
    }

    return 0;
}


Measured memory_bytes: 3932
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <utility>
#include <algorithm>
#include <bitset>
#include <numeric>
#include <math.h>
#include <tuple>
#include <queue>
#include <set>

using namespace std;

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

    int N;
    
    cin >> N;
    
    vector<int> V(N);
    vector<int> C(N);

    for(int i = 0; i < N; i++){
        cin >> V[i];
    }

    for(int i = 0; i < N; i++){
        cin >> C[i];
    }

    int ans;
    ans = 0;

    for(int i = 0; i < N; i++){
        if(V[i] > C[i]){
            ans += (V[i] - C[i]);
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cmath>

int main(){
    double x1,x2,y1,y2;
    scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2);
    double x = pow(x1-x2,2);
    double y = pow(y1-y2,2);
    double distance = sqrt(x + y);
    printf("%.8lf\n",distance);

    return 0;
}


Measured memory_bytes: 2752
#include"bits/stdc++.h"
using namespace std;
using ll=long long;
using ull=unsigned long long;
constexpr auto inf=static_cast<ll>(1e18);
template<typename T=ll>inline T in(){T ret;cin>>ret;return ret;}
template<typename T=ll>inline auto vec2(size_t h,size_t w,T v=T()){return vector<vector<T>>(h,vector<T>(w,v));}
inline void setp(int n){cout<<fixed<<setprecision(n);}
inline void delnl(){cin.ignore(numeric_limits<streamsize>::max(),'\n');}

int main()
{
    ll n=in();
    for(ll i=0;i<50000;++i){
        if(static_cast<ll>(floor(1.08*i))==n){
            cout<<i<<endl;
            return 0;
        }
    }
    cout<<":("<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <set>
#include <cstdlib>
#include <deque>
#include <stack>

using namespace std;
const long long P = 1000000007;
const long long INF = 1LL << 60;

int main() {
  int n;
  cin >> n;
  vector<long long> v(n);
  for(int i = 0; i < n; i++) {
    cin >> v[i];
  }
  sort(v.begin(),v.end());
  int ans = 0;
  for(int i = 0; i < v.size();) {
    int tmp = v[i];
    int count = 0;
    int flag = 0;
    while(tmp == v[i]) {
      i++;
      count++;
      flag = 1;
    }
    if(flag) i--;
    
    if(tmp < count) { 
      ans += count-tmp;
    }else if(tmp > count) {
      ans += count;
    }
    i++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <set>
#include <cmath>
#include <queue>
using namespace std;

long long int k, ans = 0, id = 0;

void func(vector<int>& v, int num){
  if(num == 0){
    //for(int i = 0; i < v.size(); i++) cout << v[i]; cout << endl;
    id++;
    if(id == k){
      long long int ten = 1;
      for(int i = v.size() - 1; i >= 0; i--){
        ans += v[i] * ten;
        ten *= 10;
      }
    }
    return;
  }
  if(v.size() == 0){
    for(int i = 1; i <= 9; i++){
      v.push_back(i);
      func(v, num - 1);
      v.pop_back();
    }
    return;
  }
  int x = v[v.size() - 1];
  for(int i = 0; i <= 9; i++){
    if(abs(x - i) <= 1){
      v.push_back(i);
      func(v, num - 1);
      v.pop_back();
    }
  }
  return;
}

void solve(){
  cin >> k;
  vector<int> v;
  for(int i = 1; i <= 10; i++){
    func(v, i);
    if(ans != 0){
      cout << ans << endl;
      return;
    }
  }

  return;
}

int main(){
  solve();
  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
using namespace std;
typedef long long ll;
const double PI = acos(-1.0);
const double eps = 1e-6;
const int INF = 0x3f3f3f3f;

int main(){
	int a,b,c;
	scanf("%d %d %d",&a,&b,&c);
	if(a+b<c)	printf("No\n");
	else{
		printf("Yes\n");
	}

	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <cassert>
#include <climits>
#include <bitset>
#include <stack>
#include <queue>
#include <iomanip>
#include <limits>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string.h>
#include <tuple>
#include <time.h>

using namespace std;

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

long long int INF = 3e18;
double Pi = 3.1415926535897932384626;

vector<ll> G[500005];
vector<P> tree[500010];
priority_queue <ll> pql;
priority_queue <P> pqp;
//big priority queue
priority_queue <ll,vector<ll>,greater<ll> > pqls;
priority_queue <P,vector<P>,greater<P> > pqps;
//small priority queue
//top pop

int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,-1,1};
char dir[] = "DRUL";
//ll bit[500005];
//↓,→,↑,←


#define p(x) cout<<x<<endl;
#define el cout<<endl;
#define pe(x) cout<<(x)<<" ";
#define ps(x) cout<<fixed<<setprecision(25)<<x<<endl;
#define pu(x) cout<<(x);
#define pd(x) cerr<<"//"<<(x)<<endl;
#define re(i,n) for(i=0;i<n;i++);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define deba(x) cout<< #x << " = " << x <<endl


ll mod = 1000000007;
ll rui(ll number1,ll number2){
    if(number2 == 0){
        return 1;
    }else{
        ll number3 = rui(number1,number2 / 2);
        number3 *= number3;
        number3 %= mod;
        if(number2%2==1){
            number3 *= number1;
            number3 %= mod;
        }
        return number3;
    }
}
ll gcd(ll number1,ll number2){
    if(number1 > number2){
        swap(number1,number2);
    }
    if(number1 == 0 || number1 == number2){
        return number2;
    }else{
        return gcd(number2 % number1,number1);
    }
}
void YES(bool condition){
    if(condition){
        p("YES");
    }else{
        p("NO");
    }
    return;
}
void Yes(bool condition){
    if(condition){
        p("Yes");
    }else{
        p("No");
    }
    return;
}

ll n,m,num,sum,ans,a,b,c,d,e,g,h,w,i,j,k,ok,ng,l,q;
ll x[500005],y[500005],z[500005];
char s[500005],t[500005];
bool flag,dame;

ll  fact[1200005];
ll rfact[1200005];

void c3_init(){
    fact[0] = rfact[0] = 1;
    for(ll i=1; i<1200000; i++){
        fact[i] = (fact[i-1]*i) % mod;
        rfact[i] = rui(fact[i],mod - 2);
    }
}
ll c3(ll n,ll r){
    return (((fact[n] * rfact[r]) % mod) * rfact[n-r]) % mod;
}
 
int main(){
    cin >> x[0] >> x[1] >> x[2];
	sort(x,x+3);
	Yes(x[0] == x[1] && x[1] == x[2]);
	return 0;
}


Measured memory_bytes: 26496
N=int(input())
A=list(map(int,input().split()))
MOD=1000000007

ans=1
cnt=[3 if i==0 else 0 for i in range(N+1)]
for a in A:
    ans=ans*cnt[a]%MOD
    if ans==0:
        break
    cnt[a]-=1
    cnt[a+1]+=1

print(ans)

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

int main() {
  int A, B, c;
  cin >> A >> B;

  while (A >= B){
    A = A - B;
    c++;
  }
  
  if (A == 0){
    cout << c << endl;
  } else {
    cout << c+1 << endl;
  }
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int x[5];
  for(int i=0;i<5;i++){
    cin>> x[i];
  }
  for(int i=0;i<5;i++){
    if(x[i]==0){
      cout<< i+1 << endl;
    }
  }
}

Measured memory_bytes: 3584
#pragma region include
#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <tuple>
#include <bitset>

#include <queue>
#include <complex>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <fstream>
#include <random>
//#include <time.h>
#include <ctime>
#pragma endregion //#include
/////////
#define REP(i, x, n) for(int i = x; i < n; ++i)
#define rep(i,n) REP(i,0,n)
/////////
#pragma region typedef
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
#pragma endregion //typedef
////定数
const int INF = (int)1e9;
const LL MOD = (LL)1e9+7;
const LL LINF = (LL)1e18;
const double PI = acos(-1.0);
const double EPS = 1e-9;
/////////
using namespace::std;

void solve(){
	int H,W;
	cin >> H >> W;
	vector< vector<bool> > fld(H,vector<bool>(W));
	for(int h=0;h<H;++h){
		string str;
		cin >> str;
		for(int w=0;w<W;++w){
			if( str[w] =='#' ){
				fld[h][w] = true;
			}
		}
	}
	if( fld[0][0] == false ){
		cout << "Impossible" << endl;return;
	}
	for(int h=0;h<H;++h){
		for(int w=0;w<W;++w){
			if( fld[h][w] ){
				int res = 0;
				if( h+1<H ){res += fld[h+1][w];}
				if( w+1<W ){res += fld[h][w+1];}
				if( res != 1 ){
					if( h==H-1 && w==W-1 ) continue;//右下は停止
					cout << "Impossible" << endl;
					return;
				}

				int rev = 0;//逆方向もみる
				if( h>0 ){rev += fld[h-1][w];}
				if( w>0 ){rev += fld[h][w-1];}
				if( rev != 1 ){
					if( h==0 && w==0 ) continue;//左上は開始位置
					cout << "Impossible" << endl;
					return;
				}
			}
		}
	}
	cout << "Possible" << endl;
}

#pragma region main
signed main(void){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	
	
	solve();
}
#pragma endregion //main()


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const int MAX = 1000000;
long long fac[MAX], finv[MAX], inv[MAX];

void COMint(){
  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 r){
  if(n<r) return 0;
  if(n<0||r<0) return 0;
  return fac[n]*(finv[r]*finv[n-r]%MOD)%MOD;
}

int main(){
  int X,Y;
  cin >> X >> Y;
  COMint();
  if((X+Y)%3!=0){
    cout << 0 << endl;
    return 0;
  }
  int n = (X+Y)/3;
  int r = min(X-n,Y-n);
  cout << COM(n,r) << endl;
  return 0;
}






Measured memory_bytes: 23680
require 'pp'

n, a, teleportation = gets.chomp!.split(" ").map(&:to_i)
x_n = gets.chomp!.split(" ").map(&:to_i)

cost = 0
x_n.each_cons(2) do |x, y|
    walk = (y - x) * a
    if teleportation < walk
        cost += teleportation
    else
        cost += walk
    end
end

puts cost


Measured memory_bytes: 10732
#include<iostream>

using namespace std;
int sirabe(int);
int sagasu(int,int);

int n,m[101][101],k[101],fg,ans;

int main(){
	
	cin>>n;
	
	while(n!=0){
		
		for(int lop=0;lop<101;lop++){
			k[lop]=0;
			for(int lop2=0;lop2<101;lop2++){
				m[lop][lop2]=0;
			}
		}
		fg=0;
		ans=0;
		
		for(int lop=0;lop<n;lop++){
			cin>>m[lop][0];
			for(int lop2=1;lop2<m[lop][0]+1;lop2++){
				cin>>m[lop][lop2];
			}
		}
		
		cin>>k[0];
		for(int lop=1;lop<k[0]+1;lop++){
			cin>>k[lop];
		}
		
		/*cout<<"aaaaa"<<endl;
		for(int lop=0;lop<n;lop++){
			for(int lop2=0;lop2<m[lop][0]+1;lop2++){
				cout<<m[lop][lop2]<<' ';
			}
			cout<<endl;
		}
		
		for(int lop=1;lop<k[0]+1;lop++){
			cout<<k[lop]<<' ';
		}
		cout<<endl;*/
		
		for(int lop=0;lop<n;lop++){
			if(sirabe(lop)==1){
				if(fg==0){
					fg=1;
				}else{
					fg=2;
					break;
				}
			}
		}
		
		if(fg==0 || fg==2){
			cout<<-1<<endl;
		}else{
			cout<<ans+1<<endl;
		}
		
		
		cin>>n;
	}
	
	return 0;
}

int sirabe(int hito){
	
	/*for(int lop=1;lop<m[hito][0]+1;lop++){
		if(sagasu(m[hito][lop])==0){
			return 0;
		}
	}*/
	for(int lop3=1;lop3<k[0]+1;lop3++){
		
		if(sagasu(k[lop3],hito)==0){
			return 0;
		}
	}
	
	ans=hito;
	return 1;
}
	
int sagasu(int num,int hito2){
	
	/*for(int lop3=1;lop3<k[0]+1;lop3++){
		
		if(k[lop3]==num){
			
			return 1;
		}
		
	}*/
	for(int lop=1;lop<m[hito2][0]+1;lop++){
		if(num==m[hito2][lop]){
			return 1;
		}
	}
	
	return 0;
}

Measured memory_bytes: 3136
#include <stdlib.h>
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
using ll=long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
inline constexpr ll gcd(ll a,ll b){if(!a||!b)return 0;while(b){ll c=b;b=a%b;a=c;}return a;}
inline constexpr ll lcm(ll a,ll b){if(!a||!b)return 0;return a*b/gcd(a,b);}
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;
}
const long long INF=1LL << 60;
long long a,b;
long long dp[100200][110];
long long w[110],v[110];

static const double pi = 3.141592653589793;
int main(){
    int a,b;
    cin>>a>>b;
    bool f=true;
    vector<int> vec(b);
    rep(i,b){
        cin>>vec.at(i);
        if(vec.at(i)==a){
            f=false;
        }
    }
    if(f){
        cout<<a<<endl;
    }
    else{
        rep(i,101){
            bool f2=true;
            bool f3=true;
            rep(j,b){
                if((a-(i+1))==vec.at(j)){
                    f2=false;
                }
                if((a+(i+1))==vec.at(j)){
                    f3=false;
                }
            }
            if(f2){
                cout<<a-(i+1)<<endl;
                break;
            }
            if(f3){
                cout<<a+(i+1)<<endl;
                break;
            }
        }
    }
    
}



Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define _GLIBCXX_DEBUG
#define rep(i, c) for (int i = 0; i < (int)c; i++)
#define debug(x) cout << #x << " = " << x << endl
#define print(x) cout << x << endl;
const ll MOD = 1000000007;

int main()
{
    int N;
    cin >> N;
    N = N % 10;
    if (N == 3)
    {
        cout << "bon" << endl;
    }
    else if (N == 0 | N == 1 | N == 6 | N == 8)
    {
        cout << "pon" << endl;
    }
    else
    {
        cout << "hon" << endl;
    }
}


Measured memory_bytes: 3632
// Original: https://github.com/tanakh/competitive-rs
#[allow(unused_macros)]
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)*}
    };
}

#[allow(unused_macros)]
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)*}
    };

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

#[allow(unused_macros)]
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, bytes) => {
        read_value!($next, String).into_bytes()
    };

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

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

#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::HashMap;

fn main() {
    input!(n: usize, k: usize, vs: [i64; n]);

    let mut ans = 0;
    for left in 0..min(n, k) + 1 {
        for right in 0..min(n, k) + 1 - left {
            if k < left + right {
                continue;
            }
            let mut hand: Vec<i64> = vs.iter().take(left).cloned().collect();
            for i in 0..right {
                hand.push(vs[n - 1 - i]);
            }
            hand.sort_by(|x, y| y.cmp(&x));
            let rem = k - left - right;
            for _ in 0..rem {
                if let Some(x) = hand.pop() {
                    if x >= 0 {
                        hand.push(x);
                    }
                }
            }
            let sum = hand.iter().sum();
            ans = max(ans, sum);
        }
    }

    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <functional>
#include <ctime>
#include <cmath>
#include <limits>
#include <numeric>
#include <type_traits>
using namespace std;
using ll = long long;

unsigned euclidean_gcd(unsigned a, unsigned b) {
    if (a < b) return euclidean_gcd(b, a);
    unsigned r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

class UnionFind {
public:
    vector <ll> par;
    vector <ll> siz;
    UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    ll root(ll x) {
        while (par[x] != x) {
            x = par[x] = par[par[x]];
        }
        return x;
    }
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) {
        return root(x) == root(y);
    }

    ll size(ll x) {
        return siz[root(x)];
    }
};

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 modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}

int main() {
    ll n, m,k;
    cin >> n >> m >> k;
    vector<ll> p(n);
    p.at(0) = m;
    for (int i = 1; i < n; i++) {
        p.at(i) = p.at(i - 1) * (m - 1) % 998244353;
    }
    vector<ll> c(n);
    c.at(0) = 1;
    for (int i = 1; i < n; i++) {
        c.at(i) = c.at(i - 1) * (n - i) % 998244353 * modinv(i, 998244353) % 998244353;
    }
    ll ans = 0;
    for (int i = 0; i < k+1; i++) {
        ans += p.at(n - i - 1) * c.at(n - i - 1);
        ans %= 998244353;
    }
    cout << ans << endl;
}

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

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

  ll n, k; cin >> n >> k;
  vector<ll> bucket(100010);

  int a, b;
  rep(i, n) {
    cin >> a >> b;
    bucket[a] += b;
  }

  ll sum = 0;
  int ans = 0;
  for(int i = 1; i < 100010; ++i) {
    sum += bucket[i];
    if(sum >= k) {
      ans = i;
      break;
    }
  }

  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
const ll maxn = 2001;
const ll mof = 1e9+7;
ll dp[maxn][maxn];
ll s[maxn],t[maxn];
ll solve(int x,int y)
{
    if(dp[x][y]!=-1)
        return dp[x][y];
    if(s[x] == t[y])
    {
        dp[x][y] = (solve(x-1,y)+solve(x,y-1)) % mof;
    }else
    {
        dp[x][y] = (solve(x-1,y) + solve(x,y-1) - solve(x-1,y-1) + mof ) % mof;
    }
    return dp[x][y];
}
int main()
{
    int n,m;
    cin>>n>>m;
    memset(dp,-1,sizeof dp);
    for(int i=1;i<=n;++i)cin>>s[i],dp[i][0] = 1;
    for(int i=1;i<=m;++i)cin>>t[i],dp[0][i] = 1;
    dp[0][0] = 1;
    cout<<solve(n,m)<<endl;
}

Measured memory_bytes: 31872
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>

using namespace std;

int main(){
  int K;
  int X;
  cin >> K >> X;
  for(int i=X-K+1;i<=X+K-1;i++){
    cout << i << " ";
  }
  cout << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>

int main(){
	float x1,y1,x2,y2,x3,y3,x,y,r;
	float a1,b1,c1,a2,b2,c2;
	int n;
	int i;

	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%f %f %f %f %f %f",&x1,&y1,&x2,&y2,&x3,&y3);
		a1=2*(x2-x1);
		b1=2*(y2-y1);
		c1=x1*x1-x2*x2+y1*y1-y2*y2;
		a2=2*(x3-x1);
		b2=2*(y3-y1);
		c2=x1*x1-x3*x3+y1*y1-y3*y3;
		x=(b1*c2-b2*c1)/(a1*b2-a2*b1);
		y=(c1*a2-c2*a1)/(a1*b2-a2*b1);
		r=sqrt(pow(x-x1,2)+pow(y-y1,2));
		printf("%.3f %.3f %.3f\n",x,y,r);
	}
	return 0;
}

Measured memory_bytes: 656
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<string> vs;
typedef complex<double> pnt;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<pii, pii> pp;
typedef double ld;
typedef long double lld;
#define INF 0x3f3f3f3f // for int
#define LL_INF 0x3f3f3f3f3f3f3f3f // for ll
#define gl(x) getline(cin, (x))
#define sz(x) (int)(x.size())
#define af(x) x.begin(), x.end()
#define ms(x, y) memset(x, y, sizeof(x))
#define mpp make_pair
#define pb push_back
#define AUT auto
//coordinate compression:sort(val.begin(), val.end());
//		val.resize(unique(val.begin(), val.end()) - val.begin());
#define nl '\n'
typedef unsigned long long ull;
const int MOD = 1e9 + 7;
const lld pi = 3.14159265358979323846;

//remember to remove ios stuff if i use scanf

//printf("%05lld\n", x); --> print last 5 digits including 0's
//printf("%02d:%02d", h, m); --> time
ll gcd(ll a, ll b){return b == 0 ? a : gcd(b, a % b);}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
ll pwmd(ll b, ll exp) {
    ll ret = 1;
    while (exp > 0) {
        if (exp % 2 == 1) ret = (ret * b) % MOD;
        exp /= 2;
        b = (b * b) % MOD;
    }
    return ret;
}
//void RotateArr(int X) {
//    for (int n=0; n<X; n++) {
//        for (int i=0; i<N/2; i++) {
//            for (int j=0; j<N; j++) {
//                swap(a[i][j], a[N-i-1][j]);
//            }
//        }
//        for (int i=0; i<N; i++) {
//            for (int j=i+1; j<N; j++) {
//                swap(a[i][j], a[j][i]);
//            }
//        }
//    }
//}

/*
 * string input;
 *
 * stringstream ss(input);
 *- if the input contains '\n', separate lines with: string line; while (getline(ss, line))
 * - clear() to clear the stream
 * - >> : read smth from stringstream object ie. while (s >> word)
 */

struct pair_hash { //megabrain --> for unordered_set<pair<ll, ll>>
    //initialize the set with unordered_set<pair<ll, ll>, pair_hash>st
    inline std::size_t operator()(const std::pair<ll,ll> & v) const {
        return v.first*31+v.second;
    }
};
/* for dijkstra:
 * bool operator < (const E &other) const {
        return this->w > other.w;
    }
 */

string n; int tot;

void solve(int tc) {

    cin >> n;
    for (int i = 0; i < n.size(); i++) {
        tot += (n[i] - '0');
    }
    if (tot % 9 == 0) cout << "Yes" << nl;
    else cout << "No" << nl;

}

//you should really read the stuff at the bottom

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

    int tc = 1; //cin >> tc;
    for (int t = 0; t < tc; t++) solve(t);

    return 0;
}

/* stuff you should look for
	* int overflow, array bounds
	* special cases (n=1?)
	* do smth instead of nothing and stay organized
	* WRITE STUFF DOWN
	* DON'T GET STUCK ON ONE APPROACH
// Did you read the bounds?
// Did you make typos?
// Are there edge cases (N=1?)
// Are array sizes proper (scaled by proper constant, for example 2* for koosaga tree)
// Integer overflow?
// DS reset properly between test cases?
// Is using long longs causing TLE?
// Are you using floating points?
*/

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

using namespace std;
typedef long long ll;

const int MAXN = 1e5+2;
vector<int> A;
map<int, ll> B;
int N;
void solve(){
	cin>>N;
	A.resize(N);
	for (int i=0;i<N;i++){
		cin>>A[i];
	}
	sort(A.begin(), A.end());
	for (int i=0;i<N;i++){
		int u;
		cin>>u;
		auto it = lower_bound(A.begin(), A.end(), u);
		int idx = (int) (it-A.begin());
		B[u] += idx;
//		cout<<u<<' '<<idx<<' '<<B[u]<<endl;
	}
	ll cnt = 0;
	int Bmin = B.begin()->first;
	for (auto& it:B){  // here must use reference
//		cout<<it.first<<','<<it.second<<endl;
		cnt += it.second;
		it.second = cnt;
	}
	cnt = 0;
	for (int i=0;i<N;i++){
		int u;
		cin>>u;
		if (u > Bmin){
			auto it = B.lower_bound(u);
			it--;
			cnt += it->second;
//			cout<<u<<' '<<it->first<<','<<it->second<<endl;
		}
	}
	cout<<cnt<<endl;
}

int main(){
// 	freopen("in.txt","r",stdin);
// 	freopen("out.txt","w",stdout);
	std::ios::sync_with_stdio(false);

//	int TestCase;
//	cin>>TestCase;
//	for (int i=0;i<TestCase;i++){
		solve();
//	}

	return 0;
}



Measured memory_bytes: 6912
def lcs(s1_raw, s2_raw):
    dp = []
    for s2 in s2_raw:
        start = 0
        for i, cnt in enumerate(dp):
            index = s1_raw.find(s2, start) + 1
            if not index:
                break
            else:
                dp[i]  = min(cnt , index)
                start = cnt
        index = s1_raw.find(s2, start) + 1
        if index:
            dp.append(index)
    return len(dp)


if __name__ == "__main__":
    q = int(input())
    for _ in range(q):
        x = input()
        y = input()
        print(lcs(x, y))



Measured memory_bytes: 5612
#include<stdio.h>
  
int heap[2000000];
int size;
  
void max_heapify(int heap[], int i) {
    int l = 2 * i + 1;
    int r = 2 * i + 2;
    int largest;
  
    if (l <= size && heap[l] > heap[i]) {
        largest = l;
    } else {
        largest = i;
    }
    if (r <= size && heap[r] > heap[largest]) {
        largest = r;
    }
  
    if (largest != i) {
        int tmp = heap[i];
        heap[i] = heap[largest];
        heap[largest] = tmp;
        max_heapify(heap, largest);
    }
}
  
void insert(int k){
    int child = size;
    int parent = (child - 1) / 2;
  
    heap[size] = k;
  
    while(1){
        if(heap[parent] > heap[child] || child == 0)
            break;
        int tmp = heap[child];
        heap[child] = heap[parent];
        heap[parent] = tmp;
  
        child = parent;
        parent = (child - 1) / 2;
    }
  
    size++;
}
  
int extract_max(){
    int ret = heap[0];
    heap[0] = heap[size-1];
    size--;
    max_heapify(heap, 0);
    return ret;
}
  
int main(){
    char cmd[8];
    int k;
  
    while(1) {
        scanf("%s", cmd);
        if(cmd[0] == 'i'){
            scanf("%d", &k);
            insert(k);
        }else if(cmd[1] == 'x'){
            printf("%d\n", extract_max());
        }else{
            return 0;
        }
    }
}


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

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
#define rrep(i, m, n) for(int (i)=(m); (i)<(n);  (i)++)
#define erep(i, m, n) for(int (i)=(m); (i)<=(n); (i)++)
#define  rep(i, n)    for(int (i)=0; (i)<(n);  (i)++)
#define rrev(i, m, n) for(int (i)=(n)-1; (i)>=(m); (i)--)
#define erev(i, m, n) for(int (i)=(n); (i)>=(m); (i)--)
#define  rev(i, n)    for(int (i)=(n)-1; (i)>=0; (i)--)
#define vrep(i, c)    for(__typeof((c).begin())i=(c).begin(); i!=(c).end(); i++)
#define  ALL(v)       (v).begin(), (v).end()
#define mp            make_pair
#define pb            push_back
template<class T, class S> inline bool minup(T& m, S x){ return m>(T)x ? (m=(T)x, true) : false; }
template<class T, class S> inline bool maxup(T& m, S x){ return m<(T)x ? (m=(T)x, true) : false; }

const int    INF = 1000000000;
const ll     MOD = 1000000007LL;
const double EPS = 1E-12;

template<typename T> ostream& operator << (ostream& r, const vector<T> t){vrep(v,t)r<<*v<<(v+1==t.end()?"":" ");return r;}
template<typename T> ostream& operator << (ostream& r, const pair<vector<T>, int> p){int n=p.second;minup(n,p.first.size());rep(i,n-1)r<<p.first[i]<<' ';r<<p.first[n-1];return r;}
template<typename T> ostream& operator << (ostream& r, const pair<T*, int> p){int n=p.second-1;rep(i,n)r<<p.first[i]<<' ';return r<<p.first[n];}
template<typename T, size_t S> ostream& operator << (ostream& r, const T (&a)[S]){rep(i,S-1)r<<a[i]<<' ';return r<<a[S-1];}

string s;
vector<string> res;

int main()
{
  while(cin >> s){
    rev(i, s.size()) if(s[i] != ',' && s[i] != '.'){
      s.resize(i+1);
      break;
    }
    if(s.size() >= 3 && s.size() <= 6) res.pb(s);
  }

  cout << res << endl;

  return 0;
}

Measured memory_bytes: 1192
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define vi vector<int>
#define ff first
#define ss second
#define file_se_input  freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define pp long long int
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define pb push_back
#define mp make_pair
#define pi 3.141592653589793238
#define eb emplace_back
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define zip(i,a,b) for(int i=a;i<b;i++)
#define rzip(i,a,b) for(int i=a;i>=b;i--)
#define ll unsigned long long int
#define test int t;cin>>t; while(t--)
#define um unordered_map
#define en '\n'
#define us unordered_set
typedef pair<int, int>     pii;
typedef pair<char, int>    pci;
typedef pair<char, char>   pcc;
typedef vector<pii>       vii;
typedef long double ld;
#define all(v) v.begin(), v.end()
#define INF (1e18+5)
#define inf (1e9+5)
#define mod 1000000007


bool check_prime(long long n)
{
	int flag = 0;
	for (long long i = 2; i * i <= n; i++)
	{
		if (n % i == 0)
		{
			flag = 1;
			break;
		}
	}
	if (n == 1)
		return false;
	else if (flag == 0 || n == 2 || n == 3)
	{
		return true;
	}
	else
	{
		return false;
	}

}

int BE(int x, int n, int m) //function to calculate x raise to power n modulo m
{
	int result = 1;
	while (n > 0)
	{
		if (n % 2 == 1)
			result = result * x % m;
		x = x * x % m;
		n = n / 2;
	}
	return result;
}

int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(0);
#ifndef ONLINE_JUDGE
	if (fopen("input.txt", "r"))
	{
		freopen ("input.txt" , "r" , stdin);
		freopen ("output.txt" , "w" , stdout);
	}
#endif
	//_______________________________-code starts-_______________________________________________

	int n, m;
	cin >> n >> m;
	int x[m];
	zip(i, 0, m)  cin >> x[i];
	sort(x, x + m);
	vi v;
	zip(i, 1, m)
	{
		v.pb(x[i] - x[i - 1]);
	}
	sort(all(v));
	// zip(i, 0, v.size())
	// {
	// 	cout << v[i] << " ";
	// }
	// cout << en;
	int s = m - n; int
	ans = 0;
	zip(i, 0, s)
	{
		ans += v[i];
	}
	cout << ans << en;




	return 0;
}



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

int main(){
  int n;
  cin >> n;
  int ans = 0, tmp = 0;
  for (int i = 0; i < n; i ++) {
    int t; cin >> t;
    if (t == 0) {
      ans = max(ans, tmp);
      tmp = 0;
    } else {
      tmp ++;
    }
  }
  ans = max(ans, tmp);
  cout << ans + 1 << endl;
}


Measured memory_bytes: 3100