akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <cstring>
#include <queue>
#include <map>
#define pb push_back
using namespace std;
typedef pair<int,int> pii;
typedef long long int lli;

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

int h,w;
int maze[55][55];
int vis[55][55];

int main(void){
  cin>>h>>w;
  char c;
  int res=0;
  for(int i=1;i<=h;i++){
    for(int j=1;j<=w;j++){
      cin>>c;
      if(c=='.') {
	vis[i][j]=0;
	maze[i][j]=1;
	res++;
      }
      else{
	maze[i][j]=-1;
	vis[i][j]=-1;
      }
    }
  }
  for(int i=0;i<=w+1;i++){
    vis[0][i]=-1;
    vis[h+1][i]=-1;
  }
  for(int i=0;i<=h+1;i++){
    vis[i][0]=-1;
    vis[i][w+1]=-1;
  }
  
  pii p;
  p.first=1;p.second=1;
  vis[1][1]=1;
  queue<pii> q;
  q.push(p);
  int x,y;
  while(q.size()){
    p=q.front(); q.pop();
    //vis[p.first][p.second]=true;
    
    for(int i=0;i<4;i++){
      x=p.first+dx[i];y=p.second+dy[i];
      if(vis[x][y]==0) {
	q.push(pii(x,y));
	vis[x][y]=vis[p.first][p.second]+1;
      }
    }
  }/*
  for(int i=1;i<=h;i++){
    for(int j=1;j<=w;j++){
      printf("%2d",vis[i][j]);
    }printf("\n");
    }*/
  if(vis[h][w]==0) cout<<-1<<endl;
  else cout<<res-vis[h][w]<<endl;
  return 0;
}


Measured memory_bytes: 256
use std::io::{stdin, Read, StdinLock};
use std::str::FromStr;
use std::vec::Vec;
use std::{vec, cmp, num};


struct Scanner<'a> {
    cin: StdinLock<'a>,
}

impl<'a> Scanner<'a> {
    fn new(cin: StdinLock<'a>) -> Scanner<'a> {
        Scanner {cin: cin}
    }

    fn read1<T: FromStr>(&mut self) -> Option<T> {
        let token = self.cin.by_ref().bytes().map(|c| c.unwrap() as char)
                    .skip_while(|c| c.is_whitespace())
                    .take_while(|c| !c.is_whitespace())
                    .collect::<String>();
        token.parse::<T>().ok()
    }

    fn read<T: FromStr>(&mut self) -> T {
        self.read1().unwrap()
    }
}

// create Vec<char> from String
#[allow(dead_code)]
fn to_chars(s: String) -> vec::Vec<char> {
    let mut cs = s.chars();
    let mut res = vec::Vec::new();
    while let Some(c) = cs.next() {
        res.push(c);
    }
    res
}

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin);
    let a: i32 = sc.read();
    let b: i32 = sc.read();
    let c: i32 = sc.read();
    let ans = cmp::min(a + b, cmp::min(b + c, c + a));
    println!("{}", ans);
}

Measured memory_bytes: 4352
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <limits.h>
using namespace std;

int main()
{
    int n, k;
    cin >> n >> k;
    int a[n];
    for (int i = 0;i<n;i++)
    {
        cin >> a[i];
    }
    int dp[n];
    for (int i = 0;i<n;i++)
    {
        dp[i] = INT_MAX;
    }

    dp[0]=0;

    for (int i = 1;i<n;i++)
    {
        for (int j = 0;j<k;j++)
        {
            if (i-j-1>=0)
            {
                dp[i]= min( dp[i-j-1]+abs(a[i]-a[i-j-1]),dp[i] );
            }

        }
    }
    cout << dp[n-1] << endl;

}


Measured memory_bytes: 1024
/**
 *      ABc 49 B
 *      author  : kyomukyomupurin
 *      created : 2018-09-18 22:32:10
**/

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int H, W; cin >> H >> W;
    string C[H];
    for (auto i = 0; i < H; ++i) {
        cin >> C[i];
    }
    for (auto i = 0; i < H; ++i) {
        cout << C[i] << '\n';
        cout << C[i] << '\n';
    }
    return 0;
}

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

#define REP(i,n) for(int i=0;i<(n);i++)
#define REAP(i,a,n) for(int i=(a);i<(n);i++)
#define YES cout<<"Yes"<<endl
#define NO cout<<"No"<<endl
#define fr first
#define sc second
#define pb push_back
#define All(v) v.begin(),v.end()
typedef long long ll;

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

    int n,k;
    cin >> n >> k;

    int h;
    int cou=0;
    REP(i,n){
        cin >> h;
        if(h>=k)cou++;
    }
    cout << cou << endl;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    char[] ss;
    int st_x;
    int st_y;
    ArrayList<Integer> xs;
    ArrayList<Integer> ys;

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

    private void read() {
        Scanner sc = new Scanner(System.in);
        ss = sc.nextLine().toCharArray();
        st_x = sc.nextInt();
        st_y = sc.nextInt();
    }

    private void solve() {
        xs = new ArrayList<>();
        ys = new ArrayList<>();
        int st = 0;
        while (st < ss.length && ss[st++] == 'F');
        if (st != ss.length)
            st--;
        st_x -= st;
        boolean flg = false;
        int val = 0;
        for (int i = st; i < ss.length; i++) {
            if (ss[i] == 'T') {
                if (flg) {
                    ys.add(val);
                }
                else {
                    xs.add(val);
                }
                flg = !flg;
                val = 0;
            }
            else
                val++;
        }
        if (st != ss.length) {
            if (flg) {
                ys.add(val);
            } else {
                xs.add(val);
            }
        }

//        System.out.println("x");
//        for (int i: xs)
//            System.out.println(i);
//        System.out.println("y");
//        for (int i: ys)
//            System.out.println(i);
        boolean[] xDp = dp(xs);
        boolean[] yDp = dp(ys);
        if (st_x + 8001 >= 0 && xDp[st_x + 8001] && yDp[st_y + 8001])
            System.out.println("Yes");
        else
            System.out.println("No");
    }

    boolean[] dp(ArrayList<Integer> ls) {
        int n = ls.size();
        boolean[] ret = new boolean[16002];
        boolean[] ret2 = new boolean[16002];
        ret[8001] = true;
        for (int i = 0; i < n; i++) {
            Arrays.fill(ret2, false);
            int t = ls.get(i);
            for (int j = 0; j < ret.length; j++) {
                if (j - t >= 0 && j - t < ret.length)
                    ret2[j] |= ret[j - t];
                if (j + t >= 0 && j + t < ret.length)
                    ret2[j] |= ret[j + t];
            }
            boolean[] tmp = ret2;
            ret2 = ret;
            ret = tmp;
        }
        return ret;
    }
}


Measured memory_bytes: 24916
#include<bits/stdc++.h>
using namespace std;
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define SZ(x) ((int)(x).size())
#define debug(x) cerr << #x << ": " << x << '\n'
#define INF 999999999
typedef long long int Int;
typedef pair<int,int> P;
using ll = long long;
using VI = vector<int>;

int main(){
  Int a,b,x;cin >> a >> b >> x;
  Int ans = 0;
  if(a!=0) ans = b/x - (a-1)/x;
  else ans = b/x+1;
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int64_t n,T;
  cin>>n>>T;
  vector<int64_t> t(n);
  for(int i=0;i<n;i++){
    cin>>t.at(i);
  }
  if(n==1){
    cout<<T;
  }
  else{
  int x=0;
  for(int i=0;i<n-1;i++){
    x+=min(T,(t.at(i+1)-t.at(i)));
  }
  x+=T;
  cout<<x;
  }
}

Measured memory_bytes: 1792
#include <stdio.h>
int main(void){
    int a[256];
    scanf("%d %d %d %d %d %d",&a[1],&a[2],&a[3],&a[4],&a[5],&a[0]);
    if (a[0] >= a[5] - a[1]){
        printf("Yay!");
    }else {
        printf(":(");
    }
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, a, b) for(int i = a; i < b; i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fi first
#define se second
#define debug(x) cerr <<__LINE__<< ": " <<#x<< " = " << x << endl
#define debug_vec(v) cerr<<__LINE__<<": "<<#v<<" = ";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

void solve() {
    int n, r;
    cin >> n >> r;
    if (n >= 10) {
        cout << r << endl;
    } else {
        cout << r + 100 * (10 - n) << endl;
    }
}

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


Measured memory_bytes: 3628
#include <iostream>

const int MAX = 1e5;

long long a[MAX];
long long b[MAX];

long long f(long long n, long long x) {
	if (n == 0) {
		if (x <= 0) {
			return 0;
		} else {
			return 1;
		}
	} else if (x <= 1 + a[n - 1]) {
		return f(n - 1, x - 1);
	} else {
		return b[n - 1] + 1 + f(n - 1, x - 2 - a[n - 1]);
	}
}

int main() {
	long long n;
	long long x;
	scanf("%lld %lld", &n, &x);
	a[0] = 1;
	b[0] = 1;
	for (long long i = 1; i < n; i++) {
		a[i] = a[i-1] * 2 + 3;
		b[i] = b[i-1] * 2 + 1;
	}
	printf("%lld\n", f(n, x));
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#define FALSE 0
#define TRUE 1
int a[20];
int n;
int solve(int, int);
int main(){
  int i,j,q,m[200];
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
      }
  scanf("%d",&q);
  for(j=0;j<q;j++){
    scanf("%d",&m[j]);
  }
  for(j=0;j<q;j++){
    if(solve(0,m[j]))printf("yes\n");
    else printf("no\n");
  }
  return 0;
}
int solve(int i,int m){
  if(m==0)return TRUE;
  if(i>=n)return FALSE;
  if(solve(i+1,m)||solve(i+1,m-a[i]))return TRUE;
  else return FALSE;
}



Measured memory_bytes: 2108
#include<stdio.h>
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int count,max=0,i,j;
    char s[1000];
    scanf("%s",s);
    for(i=0;i<strlen(s);i++)
    {
        count=0;
        if(s[i]=='A'||s[i]=='T'||s[i]=='C'||s[i]=='G')
        {
            for(j=i;;j++)
            {
                if(s[j]=='A'||s[j]=='T'||s[j]=='C'||s[j]=='G')
                    count++;
                else
                    break;
            }
            if(count>max)
                max=count;
        }
    }
    cout<<max<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main( void ) {
	int n, y, m, d, tmp;

	for ( scanf( "%d", &n ); n--; printf( "%d\n", 196470 - tmp ) ) {
		scanf( "%d %d %d", &y, &m, &d );
		y--;
		m--;
		d--;

		tmp = y / 3 * 590 + y % 3 * 195 + d;
		if ( ( y + 1 ) % 3 )
			tmp += m / 2 * 39 + m % 2 * 20;
		else
			tmp += m * 20;
	}

	return 0;
}

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

int a[100010];

int main() {
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%d", &a[i]);
    }
    sort(a, a + n);
    int res = 0;
    for (int i = 0; i < n; i++) {
        int num = a[i], cnt = 0;
        while (i < n && a[i] == num) {
            cnt++;
            i++;
        }
        i--;
        if (cnt % 2 == 1) {
            res++;
        }
    }
    cout << res << endl;
    return 0;
}

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

#define REP(i, a, b) for(int i = a; i <= b; i ++)
#define REPG(i, x) for(int i = head[x]; i; i = g[i].nxt)

#define clr(x, y) memset(x, y, sizeof(x));

using namespace std;

typedef long long LL;
typedef double LF;

LL Max(LL a, LL b){return a > b ? a : b;}
LL Min(LL a, LL b){return a < b ? a : b;}
LL abs(LL x){return x > 0 ? x : -x;}

const int MAXN = 515;

LL c[MAXN], s[MAXN], f[MAXN];

inline LL read(){
	LL r = 0, z = 1; char ch = getchar();
	while(ch < '0' || ch > '9'){if(ch == '-') z = -1; ch = getchar();}
	while(ch >= '0' && ch <= '9'){r = r * 10 + ch - '0'; ch = getchar();}
	return r * z;
}

void work(){
	LL n = read();
	for(int i = 1; i < n; i ++){
		c[i] = read(), s[i] = read(), f[i] = read();
	}
	for(int i = 1; i <= n; i ++){
		LL ans = s[i]; int tmp = i;
		while(tmp != n){
			ans += c[tmp]; tmp ++; if(tmp == n) break;
			if((ans - s[tmp]) % f[tmp] == 0 && ans >= s[tmp]) continue;
			else {
				if(ans < s[tmp]){ans = s[tmp]; continue;}
				else {
					ans = ((ans - s[tmp]) / f[tmp] + 1) * f[tmp] + s[tmp];
				}
			}
		}
		printf("%lld\n", ans);
	}
}

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


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

/* メモリ食い過ぎ注意 */
#define int long long

typedef long long ll;

ll gcd(ll a, int b)
{
    if (a < b)
        gcd(b, a);
    if (b == 0)
        return a;
    int r;
    while ((r = a % b))
    {
        a = b;
        b = r;
    }
    return b;
}

/* define const */
const ll INF = (1ll << 60);
const ll MOD = (ll)1e9 + 7;
/* end defineing */

signed main()
{
    int n;
    int a[100];
    cin >> n;
    for (int i = 0; i < n; i++)
        cin >> a[i];

    sort(a, a + n);

    cout << a[n - 1] - a[0] << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
using ll = long long;

int n, a;
ll sum;
std::map<ll, ll> m;
std::vector<ll> vec;

int main() {
    std::cin >> n;
    vec.assign(n, 0);
    for (int i = 0; i < n; i++) {
        std::cin >> a;
        vec[i] = a;
        m[a]++;
    }
    
    for (auto r: m) {
        sum += r.second * (r.second-1) / 2;
    }
    for (int i = 0; i < n; i++) {
        ll u = m[vec[i]];
        ll p = (sum-(u*(u-1)/2));
        u--;
        ll x = p + (u*(u-1)/2);
        std::cout << x << std::endl;
        
        
    }
}


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

int main() {
  int a, b, c, k;
  std::cin >> a >> b >> c >> k;

  const auto maxsum = [a, b, c, k]() {
    const auto p = std::pow(2, k);
    if (a < c && b < c)
      return a + b + p * c;
    else if (a < b)
      return a + p * b + c;
    else
      return p * a + b + c;
  }();

  std::cout << maxsum << std::endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
using namespace std;
signed main() {
    string s,t;
    cin>>s>>t;
    vector<vector<int>> a(26),b(26);
    for (int i = 0; i < s.size(); ++i) {
        a[s[i]-'a'].emplace_back(i);
        b[t[i]-'a'].emplace_back(i);
    }
    for (int i = 0; i < 26; ++i) {
        if(a[i]!=b[i]){
            for (int j = 0; j < 26; ++j) {
                if(a[i]==b[j])swap(a[i],a[j]);
            }
        }
    }
    for (int i = 0; i < 26; ++i) {
        if(a[i]!=b[i]){
            for (int j = 0; j < 26; ++j) {
                if(a[i]==b[j])swap(a[i],a[j]);
            }
        }
    }
    for (int i = 0; i < 26; ++i) {
        if(a[i]!=b[i]){
            for (int j = 0; j < 26; ++j) {
                if(a[i]==b[j])swap(a[i],a[j]);
            }
        }
    }
    for (int i = 0; i < 26; ++i) {
        if(a[i]!=b[i]){
            for (int j = 0; j < 26; ++j) {
                if(a[i]==b[j])swap(a[i],a[j]);
            }
        }
    }
    for (int i = 0; i < 26; ++i) {
        if(a[i]!=b[i]){
            for (int j = 0; j < 26; ++j) {
                if(a[i]==b[j])swap(a[i],a[j]);
            }
        }
    }
    for (int i = 0; i < 26; ++i) {
        if(a[i]!=b[i]){
            for (int j = 0; j < 26; ++j) {
                if(a[i]==b[j])swap(a[i],a[j]);
            }
        }
    }
    for (int i = 0; i < 26; ++i) {
        if(a[i]!=b[i]){
            for (int j = 0; j < 26; ++j) {
                if(a[i]==b[j])swap(a[i],a[j]);
            }
        }
    }
    if(a==b)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 4744
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define N 2*10e5
#define precise cout<<fixed<<setprecision(10)
#pragma GCC optimize("O0")
#pragma GCC optimize ("Ofast")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize ("-ffloat-store")
#define rep(i,a,b) for(int i=a;i<b;i++)
#define min3(a,b,c) min(a,min(b,c))
#define nl cout<<"\n";
#define all(v) v.begin(),v.end()
#define F first
#define S second
typedef long long ll;
typedef vector<long long> vl;
typedef vector<pair<long,long>> vp;
void get(ll arr[],ll n){for(ll i=0;i<n;i++) cin>>arr[i];}
ll gcd(ll a,ll b);
ll binpow(ll a,ll b);
void solve()
{
    ll a;
    cin>>a;
    cout<<a+ a*a +a*a*a;
}
int main()
{
 	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll t;
	t=1;
	//cin>>t;
	while(t--)
	{
	 	solve();
	}
	//cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}
ll binpow(ll a, ll b) {
   ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}
ll gcd(ll a,ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}


Measured memory_bytes: 3648
#!/usr/bin/env python3
n = int(input()) 
w = [input() for _ in range(n)]
if len(set(w)) < n:
    print("No")
else:
    for i in range(n - 1):
        if w[i][-1] != w[i + 1][0]:
            print("No")
            exit()
    print("Yes")


Measured memory_bytes: 3060
def solve(n, ds):
    if n >= 24: return 0
    if max([ds.count(v) for v in range(13)]) >= 3:
        return 0
    if ds.count(0) > 0: return 0
    if ds.count(12) > 1: return 0
    if n >= 12: return 1
    
    res = 0
    for mask in range(1<<n):
        pos = ds[::]
        s = 24
        for i in range(n):
            if mask & 1<<i:
                pos[i] = 24 - pos[i]
        pos.append(0)
        for i in range(len(pos)):
            for j in range(i):
                s = min(s, abs(pos[i] - pos[j]), 24 - abs(pos[i] - pos[j]))
        res = max(res, s)
    return res

n = int(input())
ds = list(map(int, input().split()))
print(solve(n, ds))

Measured memory_bytes: 3064
#include <iostream>

using namespace std;

int main(){
  int a, b;
  std::cin >> a >> b;
  if( a < b ){
    for(int i=0; i<b; i++){
      std::cout << a;
    }
  }else{
    for(int i=0; i<a; i++){
      std::cout << b;
    }
  }
  std::cout  << '\n';
  return 0;
}


Measured memory_bytes: 888
<?php
    $n = 0;
    $i = 0;
    $j = 0;
    $k = 0;
    $a = 0;
    $b = 0;
    $c = 0;
    $count = 0;
    $sticks = [];
    
    $n = sscanf(fgets(STDIN), "%d")[0];
    $sticks = explode(" ", fgets(STDIN));
    for($i=0; $i<$n-2; $i++){
        $a = (int)$sticks[$i];
        for($j=$i+1; $j<$n-1; $j++){
            $b = (int)$sticks[$j];
            for($k=$j+1; $k<$n; $k++){
                $c = (int)$sticks[$k];
                if ( ($a != $b && $b != $c && $c != $a) && ($a + $b > $c && $b + $c > $a && $c + $a > $b) ){
                    $count++;
                }
            }
        }
    }
    printf("$count");
?>

Measured memory_bytes: 16128
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i) = 0; (i) < (n); ++(i))
#define rrep(i,n) for(int (i) = (n) - 1; (i) >= 0; --(i)) //Reversi rep
#define nfor(i,a,b) for(int (i) = (a); (i) < (b); ++(i)) //Natural for
#define rfor(i,a,b) for(int (i) = (b); (i) >= (a); --(i)) //Reversi for
#define mod (1000000007)
#define YES cout << "YES" << endl;
#define Yes cout << "Yes" << endl;
#define NO cout << "NO" << endl;
#define No cout << "No" << endl;

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

Measured memory_bytes: 256
import java.io.*;

class Main {
	public static void main(String[] args){
		try {
			BufferedReader br =new BufferedReader(new InputStreamReader(System.in));
			

			 while(true){
			 String[] line = br.readLine().split(" ");
			int H = Integer.parseInt(line[0]);
			int W = Integer.parseInt(line[1]);
			if(H == 0 && W == 0) break;
			 for(int a = 1; a <= H; a++){
			 		for(int b = 1; b <=W; b++){
			 			if(a == 1 || a == H || b ==1 || b == W){
		 	   				System.out.print("#");
		 	   			} else{
		 	   				System.out.print(".");
		 	   			}
		 	   		}
	 	   			System.out.print("\n");	
	 	   	 }
	 	   	System.out.print("\n");
	 	   	}
	 	   	} catch(Exception e){
	 	}
	 }
}

Measured memory_bytes: 35264
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define intarr(arr, n)  ll arr[n];  for (ll i = 0; i < n; i++)  cin >> arr[i]
#define inpvec(vec,n) for(ll i=0;i<n;i++){ll var;cin>>var;vec.push_back(var);}
#define ff first
#define ss second
#define pb push_back
#define mkp make_pair
#define vec vector<ll>
#define pi pair<ll,ll>
#define changeline cout<<endl
#define loop(i,a,b) for(ll i=a;i<b;i++)
#define rev(i,a,b) for(ll i=a;i>=b;i--)
#define all(v) v.begin(),v.end()
#define mod2 998244353
#define NO cout << "NO" <<endl
#define YES cout << "YES" <<endl
#define mem(arr,val) memset(arr,val,sizeof(arr));
const ll mod=1e9+7;
#define piii 3.14159265358979323846264338327950
#define print(a, n, m)     for (ll i = n; i < m; i++) {  cout << a[i] << " "; }  cout << endl
#define con continue

bool prime(ll n) 
{ 
    if (n <= 1)  return false; 
    if (n <= 3)  return true; 
    if (n%2 == 0 || n%3 == 0) return false; 
  
    for (ll i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false; 
  
    return true; 
}
bool subsequence_checker(string str1, string str2, ll m, ll n) 
{ 
    if (m == 0) return true; 
    if (n == 0) return false; 
    if (str1[m-1] == str2[n-1]) 
        return subsequence_checker(str1, str2, m-1, n-1); 
    return subsequence_checker(str1, str2, m, n-1); 
}
bool cmp(const pair<int,int> &a,  const pair<int,int> &b) 
{ 
    if(a.ff == b.ff)
        return a.ss>b.ss;
    return (a.ff < b.ff); 
} 

//////////////////////////////////////////////////// Lets Do It ////////////////////////////////////////////////////////

void solve(){

    ll n ;
    cin>>n;

    vec a;
    inpvec(a,n);

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

    ll ans = 0;
    if(n%2==0){
        ans+=a[0];
        loop(i,1,(n+1)/2)
        {
            ans+= 2*a[i];
        }
        cout<<ans; return;
   }

   ans = a[0] ; ll r = (n+1)/2;
   
   ll i = 1;

   for( ; i<r-1 ; i++ ){    
        ans+= 2*a[i];
   }
   ans+=a[i];

   cout<<ans;
    return;
}
 
 
int main()
{
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
    IOS;
    ll t;
    //cin>>t;
    t=1;

    while(t--){
        solve();
       // cout<<endl;
    }

    cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
    return 0;
} 

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

int n, l;

int main(){
    cin >> n >> l;
    string stuff[n];
    for (int i=0; i<n; i++){
        cin >> stuff[i];
    }
    sort(stuff,stuff+n);
    for (int i=0; i<n; i++){
        cout << stuff[i];
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <cstdio>
#include <string>
#include <algorithm>
using namespace std;

struct City{
	int index;
	int prefecture;
	long long year;
	int num;

	City(int input_index, int input_prefecture, long long input_year){
		index = input_index;
		prefecture = input_prefecture;
		year = input_year;
	}

	int getPrefecture(){
		return prefecture;
	}
	
	void setNum(int input_num) {
		num = input_num;
	}

	void print(){
		cout << setfill('0') << setw(6) << prefecture;
		cout << setfill('0') << setw(6) << num << endl;
	}
};

bool cmpPrefecture(const City &a, const City &b){
	return a.prefecture < b.prefecture;
}

bool cmpYear(const City &a, const City &b){
	return a.year < b.year;
}

bool cmpIndex(const City &a, const City &b){
	return a.index < b.index;
}

int main(void){
	int N, M;
	cin >> N >> M;
	vector<City> city;
	for(int index=0; index < M; index++){
		int P;
		long long Y;
		cin >> P >> Y;
		city.push_back(City(index, P, Y));
	}
	stable_sort(city.begin(), city.end(), cmpYear);
	stable_sort(city.begin(), city.end(), cmpPrefecture);
	int tmp = -1, count = 1;
	for(int index = 0; index < M; index++){
		if(tmp != city[index].getPrefecture()){
			tmp = city[index].getPrefecture();
			count = 1;
		}
		city[index].setNum(count++);
	}
	stable_sort(city.begin(), city.end(), cmpIndex);
	for (City itr : city){
		itr.print();
	}
	return 0;
}


Measured memory_bytes: 6896
for e in iter(input, "0 0"):
    H, W = [int(x) for x in e.split()]
    for i in range(H):
        if i % 2 == 0:
            [print("#", end="") if x % 2 == 0 else print(".", end="") for x in range(W)]
            print()
        else:
            [print(".", end="") if x % 2 == 0 else print("#", end="") for x in range(W)]
            print()
    print()



Measured memory_bytes: 7012
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<limits>
#include<sstream> 
#include<unordered_map>      

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;

const int inf = numeric_limits<int>::max() /4;
const ll linf = numeric_limits<ll>::max() /4;
const ull ulinf = numeric_limits<ull>::max()/4;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int dx8[8]={-1,0,1,-1,1,-1,0,1};
const int dy8[8]={-1,-1,-1,0,0,1,1,1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define umap(i,j) unordered_map<i,j>
#define P(p) cout<<(p)<<endl
#define PS(p) cout<<(p)<< " "
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.end(), v.begin());
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - a) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define ub(a,n,k) (upper_bound(a,a+n,k) - a) 
#define vub(a,k)  (upper_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

vector<string> split(const string &str, char sep){
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}

//ll ncr[100][100];
//ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

//ll npr[100][100]={};
//ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

//ll nHr(int n,int r){ret nCr(n+r-1,r);}

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



int main(){
    int a,b,x;
    cin >> a >> b >> x;
    if(x-a <= b && x >= a)YES;
    else NO;
    
	

	return  0;
}



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

using namespace std;

bool operator<(const pair<int,int> &p1,const pair<int,int> &p2){
    return p1.second>p2.second;
}

int main(){
    int n,a,b;    
    int res=0;
    vector<int> g[10001];
    
    scanf("%d",&n);
    for(int i=0;i<n-1;i++){
        scanf("%d%d",&a,&b);
        g[a].push_back(b);
        g[b].push_back(a);
    }

    vector<pair<int,int> > vp(n);
    for(int i=0;i<n;i++){
        vp[i] = make_pair(i+1,g[i+1].size());
    }

    sort(vp.begin(),vp.end());

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

    sort(c.begin(),c.end(),greater<int>());
        
    vector<int> d(n);

    for(int i=0;i<n;i++){
        d[i] = -1;
    }
    
    int ii=0;
    priority_queue<pair<int,int>,vector<pair<int, int> > > q;
    q.push(vp[0]);
    while(!q.empty()){
        pair<int ,int> p = q.top(); q.pop();
        
        if(d[p.first-1]!=-1)
            continue;
        
        for(auto itr=g[p.first].begin();itr!=g[p.first].end();itr++){
            q.push(make_pair(*itr,g[*itr].size()));
        }

        d[p.first-1] = c[ii];
        ii++;
    }

    for(int i=1;i<=n;i++){
        for(auto itr=g[i].begin();itr!=g[i].end();itr++){
            if(d[i-1]<d[*itr-1])
                res+=d[i-1];
            else
                res+=d[*itr-1];            
        }
    }
    res/=2;

    printf("%d\n",res);
    for(int i=0;i<n;i++)
        printf("%d ",d[i]);
    
    printf("\n");
    return 0;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
int64_t INF = 1000000000000000;
int64_t MAXN = 100010;
int64_t N, Q, K, a, b, c, x, y;
vector<vector<pair<int64_t, int64_t>>> Graph(MAXN);
vector<int64_t> Color(MAXN, 0), D(MAXN, INF); // 各点を無限大にする。

void dijkstra()
{
  priority_queue<pair<int64_t, int64_t>, vector<pair<int64_t, int64_t>>, greater<pair<int64_t, int64_t>>> PQ;

  D.at(K) = 0; // 始点を0とする。
  PQ.push(make_pair(0, K));
  Color.at(K) = 1; // グレーの状態に

  while (!PQ.empty())
  {
    pair<int64_t, int64_t> f = PQ.top();
    PQ.pop();
    int64_t u = f.second; // 未決定の中で、最短経路の頂点
    Color.at(u) = 2;      // 決定済とする
    if (D.at(u) < f.first)
      continue;
    for (int i = 0; i < Graph.at(u).size(); i++)
    {
      int64_t v = Graph.at(u).at(i).first; // uからの辺の終点
      if (Color.at(v) == 2)
        continue;
      if (D.at(v) > D.at(u) + Graph.at(u).at(i).second) // uを経由した場合の距離
      {
        D.at(v) = D.at(u) + Graph.at(u).at(i).second;
        PQ.push(make_pair(D.at(v), v)); // 頂点vの暫定での距離、頂点vをペアにする
        Color.at(v) = 1;                // グレーにする
      }
    }
  }
}

int main()
{
  cin >> N;
  for (int i = 0; i < N - 1; i++)
  {
    cin >> a >> b >> c;
    Graph.at(a).push_back(make_pair(b, c));
    Graph.at(b).push_back(make_pair(a, c));
  }
  cin >> Q >> K;
  vector<pair<int64_t, int64_t>> vp(Q);
  for (int i = 0; i < Q; i++)
  {
    cin >> x >> y;
    vp.at(i) = make_pair(x, y);
  }
  dijkstra();
  for (auto p : vp)
  {
    tie(x, y) = p;
    cout << D.at(x) + D.at(y) << endl;
  }
}


Measured memory_bytes: 13424
#include <iostream>

using namespace std;

int main(){
   
    char a, b;
    cin >> a >> b;

    if(a == 'H'){
        if(b == 'H'){
            cout << 'H' << endl;
        }else{
            cout << 'D' << endl;
        }
    }else{
        if(b == 'H'){
            cout << 'D' << endl;
        }else{
            cout << 'H' << endl;
        }
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  string S;
  cin>>S;
  string ans1, ans2;
  bool gyaku = false;
  int Q;
  cin>>Q;
  int query, x;
  char c;
  for(int i=0;i<Q;++i) {
    cin>>query;
    if(query==1) gyaku ^= 1;
    else {
      cin>>x>>c;
      if(gyaku) {
        if(x==1) ans2.push_back(c);
        else ans1.push_back(c);
      }
      else {
        if(x==1) ans1.push_back(c);
        else ans2.push_back(c);
      }
    }
  }
  string ans;
  if(gyaku) {
    reverse(S.begin(), S.end());
    reverse(ans2.begin(), ans2.end());
    ans = ans2+S+ans1;
  }
  else {
    reverse(ans1.begin(), ans1.end());
    ans = ans1+S+ans2;
  }
  cout<<ans<<endl;
}



Measured memory_bytes: 4320
#include<bits/stdc++.h>
#define int long long
#define P pair<int,int>
#define PP pair<int,P>
#define F first
#define S second
#define f(i,n) for(int i=0;i<(n);i++)
#define INF LLONG_MAX/3
#define eps LDBL_EPSILON
#define mod (int)(1000000007)
#define pie 3.141592653589793238462643383279
#define Bpri priority_queue
#define Spri priority_queue<P,vector<P>,greater<P>>
using namespace std;
PP dp[100010];
int mypow(int a,int b,int c){
	if(b==0) return 1;
	if(b%2) return mypow(a,b-1,c)*a%c;
	int d=mypow(a,b/2,c);
	return d*d%c;
}
int mutu(int a){
	while(a%3) a+=mod;
	return a;
}
signed main(){
	string s;
	cin>>s;
	dp[0]=PP(0,P(0,0));
	int z=0;
	f(i,s.size()){
		if(s[i]=='?')z++;
	}
	f(i,s.size()){
		dp[i+1]=dp[i];
		if(s[i]=='A')dp[i+1].F+=mypow(3,z,mod);
		else if(s[i]=='B')dp[i+1].S.F+=dp[i].F;
		else if(s[i]=='C')dp[i+1].S.S+=dp[i].S.F;
		else{
			dp[i+1].F+=mypow(3,z-1,mod);
			dp[i+1].S.F+=mutu(dp[i].F)/3;
			dp[i+1].S.S+=mutu(dp[i].S.F)/3;
		}
		dp[i+1].F%=mod;
		dp[i+1].S.F%=mod;
		dp[i+1].S.S%=mod;
	}
	cout<<dp[s.size()].S.S%mod<<endl;
    return 0;
}


Measured memory_bytes: 2816
#include<bits/stdc++.h>
using namespace std;
int main(){
    int H, W, tmp, h, w;    
    cin >> H >> W;
    vector<string> map(H);
    char ans[H][W];
 
     int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
     int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

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

    for(int i=0;i<H;i++){
	for(int j=0;j<W;j++){
	    if(map[i][j] =='#')
		continue;
	    tmp = 0;
	    for(int k=0; k<8; k++){
		h=i+dy[k];
		w=j+dx[k];

		if(w<0 || w>=W || h<0 || h>=H)
		    continue;

		if(map[h][w]=='#')
		    tmp ++;
		
	    }
	    map[i][j] = tmp+'0';		
	}
    }

    for(int i=0; i<H; i++)
	cout << map[i]<<endl;

}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
const ll MAX = 1001001;
const ll MOD = 1000000007;
int main()
{
    ll n;
    cin >> n;
    vector<P> a;
    rep(i, n)
    {
        ll x, y;
        cin >> x >> y;
        ll X = x;
        x = x - y;
        y += X;
        a.push_back(P(x, y));
    }
    sort(a.begin(), a.end());
    ll now = abs(a[n - 1].first - a[0].first);
    rep(i, n)
    {
        swap(a[i].first, a[i].second);
    }
    sort(a.begin(), a.end());
    now = max(now, abs(a[n - 1].first - a[0].first));

    cout << now << endl;
}

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

int main()
{
	int nNum = 0;
	cin >> nNum;
	int nArrIn[100] = { 0 };
	for (int i = 0; i < nNum; ++i)
	{
		cin >> nArrIn[i];
	}
	//Bubble
	int nCount = 0;
	for (int i = 0; i < nNum - 1; ++i)
	{
		for (int j = nNum - 1; j >= i + 1; --j)
		{
			if (nArrIn[j] < nArrIn[j - 1])
			{
				swap(nArrIn[j - 1], nArrIn[j]);
				++nCount;
			}
		}
	}
	for (int i = 0; i < nNum - 1; ++i)
	{
		cout << nArrIn[i] << " ";
	}
	cout << nArrIn[nNum - 1] << endl;
	cout << nCount << endl;
	return 0;
}


Measured memory_bytes: 3080
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
template<class T> bool INRANGE(T x,T a,T b) { return a<=x&&x<=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;
}

#define REP(i,n) for(int i=0;i<(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(v) (v).begin(),(v).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
                      << " " << __FILE__ << endl;


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


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


    vi f {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};


    int N, M;
    cin >> N >> M;

    vi A(M);
    REP(i,M) {
        cin >> A[i];
    }

    sort(ALL(A),greater<>());

    const ll INF = 1LL << 60;
    const int MAX = 10001;
    ll dp[MAX];
    REP(i,MAX) dp[i] = -INF;
    dp[0] = 0;

    FOR(i,1,MAX){
        for (int a : A) if (i-f[a] >= 0) chmax(dp[i], dp[i-f[a]] + 1);
    }

    ll itr = N;
    string ans;
    while (itr > 0){
        for (int a : A) if (dp[itr] == dp[itr-f[a]]+1 and itr-f[a] >= 0){
            ans += (char)('0'+a);
            itr -= f[a];
            break;
        }
    }


    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 384
//url:
//problem name: Brick Break

#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); ++i)
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;}
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<long long,long long>;
using veci = vector<int>;
using vecl = vector<long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;

int main() {
    int N,M;
    cin >> N >> M;
    vecveci G(N);
    veci ans(N);
    REP(i,M) {
        int a,b; cin >> a >> b;
        a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    veci dist(N,-1);
    dist[0] = 0;
    queue<int> que;
    que.push(0);
    while(!que.empty()) {
        int v = que.front();
        que.pop();
        for(int w: G[v]) {
            if(dist[w] != -1) continue;
            dist[w] = dist[v]+1;
            ans[w] = v;
            que.push(w);
        }
    }
    bool ok = true;
    for(int d:dist) if(d == -1) ok = false;
    if(ok) {
        cout << "Yes" << endl;
        for(int i = 1; i < N; i++) cout << ans[i]+1 << endl;
    } else cout << "No" << endl;
}

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

int main(){
    int h,w;
    for (;;) {
        scanf("%d %d",&h,&w);
        if (h==0) break;
        for (int i=0;i<w;i++) printf("#");
        printf("\n");
        for (int j=0;j<h-2;j++) {
            for (int i=0;i<w;i++) {
                printf("%c",(i==0 || i==w-1)?'#':'.');
            }
            printf("\n");
        }
        for (int i=0;i<w;i++) printf("#");
        printf("\n\n");
    }
    return 0;
}



Measured memory_bytes: 3152
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define RREP(i, n) for (int i = (int)n - 1; i >= 0; --i)
#define FOR(i, s, n) for (int i = s; i < (int)n; ++i)
#define RFOR(i, s, n) for (int i = (int)n - 1; i >= s; --i)
#define ALL(a) a.begin(), a.end()
#define IN(a, x, b) (a <= x && x < b)
template<class T>inline void out(T t){cout << t << "\n";}
template<class T,class... Ts>inline void out(T t,Ts... ts){cout << t << " ";out(ts...);}
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;}
constexpr int INF = 1e18;

signed main(){
	int N,K,C;
	cin >> N >> K >> C;
	string s;
	cin >> s;
	vector<pair<int,int>>l(N + 1),r(N + 1);
	l[0].second = -INF;
	r[0].second = INF;
	REP(i,N){
		if(s[i] == 'x')l[i + 1] = l[i];
		else{
			if(l[i].second + C < i){
				l[i + 1] = {l[i].first + 1,i};
			}else{
				l[i + 1] = l[i];
			}
		}
		if(s[N - i - 1] == 'x')r[i + 1] = r[i];
		else{
			if(r[i].second - C > N - i - 1){
				r[i + 1] = {r[i].first + 1,N - i - 1};
			}else{
				r[i + 1] = r[i];
			}
		}
	}
	REP(i,N){
		if(s[i] == 'x')continue;
		int day = l[i].first + r[N - i - 1].first;
		if(l[i].second + C >= r[N - i - 1].second)--day;
		if(day < K)out(i + 1);
	}
}

Measured memory_bytes: 8068
#include<bits/stdc++.h>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<iostream>
#define ios   ios_base::sync_with_stdio(false);  cin.tie(0);    cout.tie(0);
typedef  long long int ll;
using namespace std;
const int M=1e9+7;
const int N=1e5+5;
#define fi first
#define se second
#define pb push_back
int main()
{
    string s;cin>>s;
    ll ans=0;
    ll n=s.length()-1;
    while(n>=0)
    {
        ll g=s[n]-'0';
       ans+=g;
       --n;
    }
    if(ans%9)
    cout<<"No"<<endl;
    else
    cout<<"Yes"<<endl;
}

Measured memory_bytes: 3744
#!/usr/bin/ruby
# -*- coding: utf-8 -*-
=begin
ALDS1_2-D

Sort I - Shell Sort

=end

class Sort
  def initialize(f)
    @cnt=0
    @n=f.length
    @a = Array.new(@n,0)
    0.upto(@n).each{|i| @a[i] = f[i]}
  end

  def insertionSort(g)
    g.upto(@n-1){|i|
      v = @a[i]
      j = i - g
      while j >= 0 and @a[j] > v do
        @a[j+g] = @a[j]
        j = j - g
        @cnt +=1
        @a[j+g] = v
      end
    }
  end

  def shellSort()
    m = (Math.log(2*@n+1) / Math.log(3)).to_i
    gx = Array.new(m,0)
    1.upto(m){|i| gx[i-1] = (3**i - 1)/2 }
    g = gx.reverse

#    g = [121, 40, 13, 4, 1]
#    m = g.length
    puts m
    puts g.map{|x| x.to_s}.join(" ")

    0.upto(m-1) {|i|
      insertionSort(g[i])
    }
    puts @cnt
    @a
  end

end

class Main
  def initialize()
    #fh = open("x.txt")
    fh = STDIN
    n = fh.gets.chomp.to_i
    f = Array.new(n,0)
    0.upto(n-1).each{|i|
      f[i] = fh.gets.chomp.to_i }

    abort if f.length != n
    st = Sort.new(f)
    g = st.shellSort()
    g.each{|x| puts x.to_s}

  end
end

if $0==__FILE__ then
  Main.new()
end

Measured memory_bytes: 24632
#include<vector>
#include<iostream>
#include<set>
#include<map>
#include<unordered_map>
#include<string.h>
#include<algorithm>
#include<stdlib.h>
#include<queue>
#include<cmath>
#include<unordered_set>
#include<numeric>
using namespace std;

typedef long long ll;

#define FOR(i,n) for(int i=0;i<n;i++)
#define out(a) for(auto i:a)cout<<i<<" ";
#define outl(a) for(auto i:a)cout<<i<<endl;

vector<vector<ll> >tree;

int n,m;
vector<vector<int> >g;
vector<bool>visited;
vector<int>path;
set<int>InThePath;
int start;

bool dfs(int node,int last){
    //cout<<last<<" -> "<<node<<endl;
    visited[start]=1;
    visited[node]=1;
    bool ok=1;
    for(int i=0;i<g[node].size();i++){
        if(g[node][i]==last)continue;
        if(g[node].size()==2&&last!=node&&visited[g[node][i]]&&g[node][i]==start){
            return 1;
        }
        if(!visited[g[node][i]]){
            if(dfs(g[node][i],node)){
                path.push_back(node);
                InThePath.insert(node);
                return 1;
            }
        }
    }
    for(int i=0;i<g[node].size();i++){
        if(!visited[g[node][i]]){
            ok=0;
        }
    }
    // cout<<"J"<<" "<<node<<endl;
    if(ok){path.push_back(node);InThePath.insert(node);
    }
    return ok;
}

int main(){
    cin>>n>>m;
    g.resize(n);
    visited.resize(n,false);
    for(int i=0;i<m;i++){
        int a,b;
        cin>>a>>b;
        a--,b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    vector<pair<int,int> >vec;
    for(int i=0;i<n;i++){
        vec.push_back(make_pair(g[i].size(), i));
    }
    sort(vec.begin(),vec.end());
    for(auto v:vec){
        int i=v.second;
        if(g[i].size()>1){
            start=i;
            path.clear();
            FOR(i,n)visited[i]=0;
            if(dfs(g[i][0],start)&&visited[g[i][1]]){
                bool ok=1;
                for(int j=0;j<g[i].size();j++)
                    if(InThePath.find(g[i][j])==InThePath.end()){
                        ok=0;
                        break;
                    }
                if(ok){
                    break;
                }
            }
        }
        if(g[i].size()==1){
            start=i;
            path.clear();
            FOR(i,n)visited[i]=0;
            if(dfs(g[i][0],i)){
                
                break;
            }
        }
        InThePath.clear();
    }
    path.push_back(start);
    cout<<path.size()<<endl;
    for(int i=0;i<path.size();i++)cout<<path[i]+1<<" ";
    cout<<endl;
    return 0;
}

Measured memory_bytes: 18420
#include<iomanip>
#include <string>
#include<iostream>
#include<vector>
#include <bits/stdc++.h>
#include <stdio.h>
#include <numeric>
#include<math.h>
#include <ctype.h>
#include <algorithm> // sort
#include <map> // pair
using namespace std;
#define nin(n) int n; cin >> n;
#define kin(k) int k; cin >> k;
const int INF = 1001001001;
int main(){
  int n;cin >> n;
  long long h[100010][3];
  for(int i=0;i<n;i++){
    for(int j=0;j<3;j++){
      int tmp;
      cin >> tmp;
      h[i][j]=tmp;
    }
  }
 long long dp[10010][3];
 for(int i=0;i<10010;i++){
   for(int j=0;j<3;j++){
     dp[i][j]=0;
   }
 }
  for(int i=0;i<n;i++){
    for(int j=0;j<3;j++){
      for(int k=0;k<3;k++){
        if(j==k) continue;
        dp[i+1][k]=max(dp[i+1][k],dp[i][j]+h[i][k]);
      }
    }
  }
  long long res = 0;
    for (int j = 0; j < 3; ++j){ 
      res=max(res, dp[n][j]);
    }
  
    cout << res << endl;
}

Measured memory_bytes: 2816
#ifndef BZ
#pragma GCC optimize "-O3"
#endif
#include <bits/stdc++.h>

#define FASTIO
#define ALL(v) (v).begin(), (v).end()
#define rep(i, l, r) for (int i = (l); i < (r); ++i)

#ifdef FASTIO
#define scanf abacaba
#define printf abacaba
#endif

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

using namespace std;


/*
ll pw(ll a, ll b) {
	ll ans = 1; while (b) {
		while (!(b & 1)) b >>= 1, a = (a * a) % MOD;
		ans = (ans * a) % MOD, --b;
	} return ans;
}
*/

const int MAXN = 120000;

int n;
int a, b;

vector<int> eds[MAXN];

ll dp[MAXN][2];
const ll MOD = 1e9 + 7;

void dfs1(int v, int p) {
	dp[v][0] = dp[v][1] = 1;
	for (int u: eds[v]) {
		if (u == p)
			continue;
		dfs1(u, v);
		dp[v][1] = (dp[v][1] * dp[u][0]) % MOD;
		dp[v][0] = (dp[v][0] * (dp[u][0] + dp[u][1])) % MOD;
	}
}

int main() {
#ifdef FASTIO
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#endif
	cin >> n;
	for (int i = 0; i < n - 1; ++i) {
		int a, b;
		cin >> a >> b;
		--a, --b;
		eds[a].push_back(b);
		eds[b].push_back(a);
	}
	dfs1(0, -1);
	ll ans = (dp[0][0] + dp[0][1]) % MOD;
	cout << ans << "\n";
	return 0;
}




Measured memory_bytes: 11264
import java.util.*;
import java.io.*;
import java.math.BigDecimal;

public class Main {	

	private static void solve(){
		//Implement solution here.
		int X = ni();
		int Y = ni();
		int Z = ni();
		System.out.println(Z + " " + X + " " + Y);
	}

	//Switch input source (stdin/file)
	private static BufferedReader br;
	public static void main(String[] args){
		br = new BufferedReader(new InputStreamReader(System.in));
		String debugDataPath = System.getenv("DD_PATH");        
		if(debugDataPath != null){
			try{
				br = new BufferedReader(new InputStreamReader(new FileInputStream(new File(debugDataPath))));
			}catch(Exception e){
				throw new RuntimeException(e);
			}
		}
		boolean hasNext = true;
		while(hasNext){
			solve();	
			try{
				br.mark(1);
				if(br.read() > 0){
					br.reset();			
					System.out.println("---");
				} else {
					hasNext = false;
				}
			}catch(Exception e){
				throw new RuntimeException(e);
			} 
		}
	}

	//Input read utility
	private static StringTokenizer tokenizer = null;
	public static String next() {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(br.readLine());
			} catch (Exception e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}
	//Get next single int
	private static int ni() {
		return Integer.parseInt(next());
	}
	//Get next single long
	private static long nl() {
		return Long.parseLong(next());
	}
	//Get next single double
	private static double nd() {
		return Double.parseDouble(next());
	}
	//Get next int array from one line
	private static int[] na(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = ni();
		return a;
	}
	//Get next char array from one line
	private static char[] ns() {
		return next().toCharArray();
	}
	//Get next long array from one line
	private static long[] nal(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = nl();
		return a;
	}
}

Measured memory_bytes: 21204