akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cassert>
#include <stack>
#include <limits>
#include <array>
#include <unordered_map>
#include <unordered_set>
#include <memory>
#include <numeric>
//#include <tuple>

constexpr long long mod = static_cast<long long>(1e9 + 7);

struct Edge {
    int to;
    int w;
};

using Edges = std::vector<std::vector<Edge>>;

struct Memo {
    int parent;
    std::vector<std::pair<int, int>> childHeights;
};

int dfs(int i, const Edges& edges, std::vector<Memo>& memo) {
    memo[i].childHeights.reserve(edges[i].size());
    for(auto edge: edges[i]) {
        if(edge.to != memo[i].parent) {
            memo[edge.to].parent = i;
            memo[i].childHeights.push_back(std::make_pair(edge.to, edge.w + dfs(edge.to, edges, memo)));
        }
    }
    std::sort(begin(memo[i].childHeights), end(memo[i].childHeights), [](auto x, auto y){return x.second > y.second;});
    if(memo[i].childHeights.empty()) return 0;
    else return memo[i].childHeights[0].second;//std::max_element(begin(memo[i].childHeights), end(memo[i].childHeights), [](auto x, auto y){return x.second > y.second;})->second;
}

void dfs2(int i, const Edges& edges, std::vector<Memo>& memo, std::vector<int>& ans, int pHeight) {
    auto& childHeights = memo[i].childHeights;
    if(childHeights.size() == 0) {
        ans[i] = pHeight;
    } else if(childHeights.size() == 1) {
        ans[i] = std::max(pHeight, childHeights[0].second);
        for(auto edge: edges[i]) {
            if(edge.to != memo[i].parent) dfs2(edge.to, edges, memo, ans, pHeight + edge.w);
        }
    } else {
        std::sort(begin(childHeights), end(childHeights), [](auto x, auto y){return x.second > y.second;});
        ans[i] = std::max(pHeight, childHeights.front().second);
        for(auto edge: edges[i]) {
            if(edge.to != memo[i].parent) {
                if(edge.to == childHeights.front().first) dfs2(edge.to, edges, memo, ans, std::max(pHeight, childHeights[1].second) + edge.w);
                else dfs2(edge.to, edges, memo, ans, std::max(pHeight, childHeights[0].second) + edge.w);
            }
        }
    }
}

int main() {
    int n;
    std::cin >> n;
    Edges edges(n, std::vector<Edge>());
    while(--n) {
        int s, t, w;
        std::cin >> s >> t >> w;
        edges[s].push_back(Edge{t, w});
        edges[t].push_back(Edge{s, w});
    }

    std::vector<int> ans(edges.size(), 0);
    std::vector<Memo> memo(edges.size(), Memo{-1, std::vector<std::pair<int, int>>()});
    ans[0] = dfs(0, edges, memo);

    dfs2(0, edges, memo, ans, 0);

    for(auto val: ans)
        std::cout << val << "\n";
    std::cout << std::flush;

    return 0;
}



Measured memory_bytes: 5228
//by yjz
#include<bits/stdc++.h>
using namespace std;
#define FF first
#define SS second
#define PB push_back
#define MP make_pair
#define foreach(it,s) for(__typeof((s).begin()) it=(s).begin();it!=(s).end();it++)
#ifndef LOCAL
#define cerr if(0)cout
#endif
typedef long long ll;
const int mod=1e9+7;
//My i/o stream
struct fastio
{
	char s[100000];
	int it, len;
	fastio() {it=len=0;}
	inline char get()
	{
		if (it<len) return s[it++]; it=0;
		len=fread(s, 1, 100000, stdin);
		if (len==0) return EOF; else return s[it++];
	}
	bool notend()
	{
		char c=get();
		while (c==' '||c=='\n') c=get();
		if (it>0) it--;
		return c!=EOF;
	}
}_buff;
#define geti(x) x=getnum()
#define getii(x,y) geti(x),geti(y)
#define getiii(x,y,z) getii(x,y),geti(z)
#define puti(x) putnum(x),putchar(' ')
#define putii(x,y) puti(x),puti(y)
#define putiii(x,y,z) putii(x,y),puti(z)
#define putsi(x) putnum(x),putchar('\n')
#define putsii(x,y) puti(x),putsi(y)
#define putsiii(x,y,z) putii(x,y),putsi(z)
inline ll getnum()
{
	ll r=0; bool ng=0; char c; c=_buff.get();
	while (c!='-'&&(c<'0'||c>'9')) c=_buff.get();
	if (c=='-') ng=1, c=_buff.get();
	while (c>='0'&&c<='9') r=r*10+c-'0', c=_buff.get();
	return ng?-r:r;
}
template <class T> inline void putnum(T x)
{
	if (x<0) putchar('-'), x=-x;
	register short a[20]={}, sz=0;
	while (x) a[sz++]=x%10, x/=10;
	if(sz==0) putchar('0');
	for (int i=sz-1; i>=0; i--) putchar('0'+a[i]);
}
inline char getreal() {char c=_buff.get(); while (c<=32) c=_buff.get(); return c;}
ll qpow(ll x, ll k) {return k==0? 1: 1ll*qpow(1ll*x*x%mod,k>>1)*(k&1?x:1)%mod;}
char s[200111];
int main()
{
	scanf("%s", s);
	int n = strlen(s);
	ll ans = 0, lst = n-1;
	for (int i=0; i<n; i++)
	{
		if (s[i]=='B')
		{
			ans += lst-i;
			lst--;
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 384
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
#include<cassert>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
lint ma[300100],mi[300100],a[300100];
priority_queue<lint> q;
int main()
{
	int n;
	cin>>n;
	rep(i,n*3) cin>>a[i];
	lint su=0,out=-1234567890123456LL;
	rep(i,n) su+=a[i],q.push(-a[i]);
	ma[n]=su;
	REP(i,n,3*n){
		lint t=-q.top();
		if(t<a[i]){
			q.pop();q.push(-a[i]);
			su+=a[i]-t;
		}
		ma[i+1]=su;
	}
	su=0;
	REP(i,n*2,n*3) su+=a[i],q.push(a[i]);
	mi[n*2]=su;
	for(int i=n*2-1;i>=0;i--){
		lint t=q.top();
		if(t>a[i]){
			q.pop();q.push(a[i]);
			su+=a[i]-t;
		}
		mi[i]=su;
	}
	REP(i,n,n*2+1) out=max(out,ma[i]-mi[i]);
	cout<<out<<endl;
}


Measured memory_bytes: 9460
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i < n; i ++)
#define rep1(i, n) for (int i=1; i <= n; i ++)
using namespace std;
typedef pair<int, int> P;


int main() {
  int n;
  cin >> n;
  vector<int> ans(100005, -1);
  vector<vector<P> > to(100005, vector<P>());

  long long idx = 0;
  rep(i, n - 1) {
    int u, v, w;
    cin >> u >> v >> w;
    to[u].push_back(P(v, w % 2));
    to[v].push_back(P(u, w % 2));
  }
  queue<P> nodes;
  nodes.push(P(1, 0));
  while (!nodes.empty()) {
    const P node = nodes.front();
    nodes.pop();
    vector<P> tmp = to[node.first];
    int color = node.second;
    for (P next_node: tmp) {
      if (ans[next_node.first] != -1) continue;

      int next_color = (next_node.second + color) % 2;
      ans[next_node.first] = next_color;
      nodes.push(P(next_node.first, next_color));
    }
  }
  rep1(i, n) {
    cout << ans[i] << endl;
  }
  return 0;
}


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

using namespace std;
using ll = long long;

int main() {
    int x,y = 0;
    cin >> x >> y;

    for(int i = 0;i <= x;i++){
        if(i * 2 + (x - i) * 4 == y){
            cout << "Yes" << endl;
            return 0;
        }
    }

    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3636
import sys
def input(): return sys.stdin.readline().rstrip()
from collections import deque
def main():
    h,w=map(int,input().split())
    B=[[-1]*w for _ in range(h)]
    ans=0
    que=deque()
    for i in range(h):
        s=input()
        for j,ss in enumerate(s):
            if ss=="#":
                que.append((i,j))
                B[i][j]=0
    while que:
        qr,qc=que.popleft()
        for r,c in ((qr+1,qc),(qr-1,qc),(qr,qc+1),(qr,qc-1)):
            if r>=0 and r<=h-1 and c>=0 and c<=w-1 and B[r][c]==-1:
                B[r][c]=B[qr][qc]+1
                que.append((r,c))
    print(max([max(b) for b in B]))

if __name__=='__main__':
    main()

Measured memory_bytes: 82780
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N,K,x[100]={0},sum=0;
   cin>>N>>K;
  for(int i=0;i<N;i++){
    cin>>x[i];
    if(K/2>=x[i])
      sum+=x[i];
    else
      sum+=K-x[i];
  }
  cout<<2*sum<<endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
#define int int64_t
using namespace std;
main() {
    int X,Y,Z,K; cin>>X>>Y>>Z>>K;
    vector<int> A(X); for(auto& x:A) cin>>x;
    vector<int> B(Y); for(auto& x:B) cin>>x;
    vector<int> C(Z); for(auto& x:C) cin>>x;
    sort(A.rbegin(), A.rend());
    sort(B.rbegin(), B.rend());
    sort(C.rbegin(), C.rend());
    vector<int> xs;
    for(int x=0; x<X; ++x) {
        for(int y=0; y<Y; ++y) {
            for(int z=0; z<Z; ++z) {
                if((x+1)*(y+1)*(z+1) > K) break;
                xs.push_back(A[x]+B[y]+C[z]);
            }
        }
    }
    sort(xs.rbegin(), xs.rend());
    for(int k=0; k<K; ++k) cout<<xs[k]<<endl;
}

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

int main() 
{
  int N;
  cin >> N;
  string N_str = to_string(N);
  int count = 0;

  if (N_str[0] == N_str[1] && N_str[0] == N_str[2]) cout << "Yes" << endl;
  else if (N_str[1] == N_str[2] && N_str[1] == N_str[3]) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define print(x) cout << x << endl
#define ll unsigned long long int
using namespace std;
 
int main() {
	string t;
	cin >> t;
	int n = t.size();
	if(t.size() == 1)
		print("D");
	else {
		for(int i = 0; i < t.size(); i++) {
			if(t[i] == '?') {
				if(i == 0) {
					if(t[i+1] == 'D')
						t[i] = 'P';
					else
						t[i] = 'D';
				} else {
					if(t[i-1] == 'P')
						t[i] = 'D';
					else {
						if(i+1 < n) {
							if(t[i+1] == 'D')
								t[i] = 'P';
							else
								t[i] = 'D';
						} else {
							t[i] = 'D';
						}
					}
				}
			}
		}
		print(t);
	}
}

Measured memory_bytes: 3756
import java.util.Scanner;
class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		for(int i=0; i<n;i++){
			int a = scan.nextInt();
			int b = scan.nextInt();
			int c = scan.nextInt();
			if(a*a+b*b==c*c || b*b+c*c==a*a || c*c+a*a==b*b){
			System.out.println("YES");
			}else{
				System.out.println("NO");
			}
		}
	}
} 

Measured memory_bytes: 23376
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    vector<int> vec(n);
    vector<int> cnt(1e6+1,0);
    for(auto &e:vec)
    {
        cin>>e;
        cnt[e]++;
    }
    bool temp=true;
    for(int i=2;i<=1e6;i++)
    {
        int sum=0;
        for(int j=i;j<=1e6;j+=i)
        {
            sum+=cnt[j];
        }
        if(sum>1)
        {
            temp=false;
            break;
        }
    }
    int gcdval=0;
    for(auto &e:vec)
        gcdval=__gcd(e,gcdval);
    if(temp)
    {
        cout<<"pairwise coprime\n";
    }
    else if(gcdval==1)
    {
        cout<<"setwise coprime\n";
    }
    else
    {
        cout<<"not coprime\n";
    }
    return 0;
}

Measured memory_bytes: 11164
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using G = vector<vector<int>>;
    
int main(){
    ll n;
    cin >> n;

    ll num = n;
    int ans = 0;
    
    for(ll i=2; i*i<n; i++){
        int keta = 1, count = 0;
        while(num%i==0){
            count++;
            if(keta==count){
                ans++;
                count = 0;
                keta++;
            }
            num /= i;
        }
    }
    if (num!=1ll) ans++; 

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

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

int main() {
	int A, B, C, X;
	int number = 0;
	cin >> A >> B >> C >> X;
	for (int i = 0; i <= A; i++) {
		for (int j = 0; j <= B; j++) {
			for (int k = 0; k <= C; k++) {
				if (500 * i + 100 * j + 50 * k == X) {
					number++;
				}
			}
		}
	}
	cout << number << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    long[] a = new long[n];
    long[] s = new long[n];
    for(int i = 0;i < n;i++)a[i]=sc.nextLong();
    s[0]=a[0];
    for(int i = 1;i < n;i++)s[i]=s[i-1]+a[i];
    Arrays.sort(s);
    long ans = 0;
    long cnt = 1;
    for(int i = 0;i < n;i++)if(s[i]==0)ans++;
    for(int i = 0;i<n-1;i++){
      if(s[i]==s[i+1])cnt++;
      else{
        ans+= (cnt*(cnt-1))/2;
        cnt = 1;
      }
    }
    ans+=(cnt*(cnt-1))/2;
    System.out.println(ans);
  }
}


Measured memory_bytes: 91016
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include <array>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <queue>
#include <bitset>
#include <tuple>
#include <cmath>
#include <complex>
#include <algorithm>
#include <utility>
#include <regex>
#include <cstdint>
#include <numeric>
#include <functional>
#include <cassert>

using namespace std;
using ll = int64_t;
using ull = uint64_t;

constexpr ll INF = 1000000000;/* 1e+9a */

template< class C = ll>
class BIT{
   vector<C> bit;
public:
    explicit BIT(long long N) :bit(N+1) {}

    void add(int a, C w){
        for (int x = a; x < bit.size(); x += x & -x) {
            bit[x] += w;
        } // end x
    }

    C sum(int a){
        C ret = 0;
        for (int x = a; x > 0; x -= x & -x) {
           ret += bit[x];
        } // end x
        return ret;
    }
};


void solve(istream &cin) {
    ll N, M;
    cin >> N >> M;
    if(!cin) return;
    vector<pair<int , int>> lr;
    vector<vector<int>> dl(M+1);
    BIT<> sect(M);
    for (int i = 0; i < N; ++i) {
        int l, r;
        cin >> l >> r;
        lr.emplace_back(l, r);
        dl[r - l + 1].push_back(i);
    } // end i
    ll can = N;
    for (int i = 1; i <= M; ++i) {
        can -= dl[i].size();
        for (auto &&dd : dl[i]) {
            int l, r; tie(l, r) = lr[dd];
            sect.add(l, 1); sect.add(r+1, -1);
        } // end dd

        ll f = 0;
        for (int k = i; k <= M; k+=i) {
            f += sect.sum(k);
        } // end k
        cout << can + f << endl;

    } // end i

    
}

int main(int argc, char *argv[]) {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << setprecision(16) << scientific;
#ifdef DEBUG
    cerr << "DEBUG MODE" << endl;
    string test_cases = "test.txt";
    auto fs = fstream(test_cases, fstream::in);
    while(fs) {
        solve(fs);
    }
#else
    solve(cin);
#endif
    return 0;
}


Measured memory_bytes: 12400
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
#include<set>
#include<map>
#include<bitset>

using namespace std;
typedef long long ll;
#define i_7 (ll)(1E9+7)
#define i_5 (ll)(1E9+5)
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    else return c+i_7;
}
typedef pair<int,int> i_i;
typedef pair<ll,ll> l_l;
ll inf=(ll)1E12;/*10^12*/
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}

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


int main(){
    int n;cin>>n;
    char s[n][2*n];rep(i,0,n-1)cin>>s[i];
    rep(i,0,n-1)rep(j,0,n-1){
        s[i][j+n]=s[i][j];
    }
    int ans=0;
    rep(i,0,n-1){
        bool flag=true;
        rep(j,1,n-1){
            rep(k,0,j-1){
                if(s[j][k+i]!=s[k][j+i]){
                    flag=false;
                    break;
                }
            }
            if(!flag)break;
        }
        if(flag)ans++;
    }
    cout<<ans*n<<endl;
    
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <stdio.h>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <stack>
#include <queue>
#include <algorithm>
#include <string.h>
#include <string>
#include <math.h>
#include <iomanip>
using namespace std;

#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define pb push_back

typedef pair<int, int> pii;
typedef long long ll;
typedef unsigned long long ull;

const int mod = (int)1e9 + 7;
const int mod2 = 998244353;

ll exp(ll taban, ll us, ll md) {
    ll carpan = taban % md;
	if(carpan == 0) return 0;
    ll temp = us;
    ll res = 1;
    while(temp){
        if(temp % 2) res = (res*carpan) % md;
        temp /= 2;
        carpan = (carpan*carpan) % md;
    }
    return res;
}
 
ll ebob(ll a, ll b){
    if(!a)return b;
    return ebob(b%a, a);
}

ll ekok(ll a, ll b){
    return (a*b)/ebob(a, b);
}
ll mul(ll a, ll b, ll md){
	return a*b % md;
}
const int N = 1e5 + 5;
vector<ll> fact;
vector<ll> inv_fact;
void fact_init(int n){
	fact.resize(n+5);
	inv_fact.resize(n+5);
	fact[0] = inv_fact[0] = 1;
	for(int i = 1; i <= n; i++){
		fact[i] = (fact[i-1] * i) % mod;
		inv_fact[i] = exp(fact[i], mod-2, mod);
	}
}
ll komb(ll a, ll b){
	return fact[a] * (inv_fact[a-b] * inv_fact[b] % mod) % mod;
}
int main(){
    ios_base::sync_with_stdio(false); cin.tie(NULL);
	int n; string s; cin>>n>>s;
	if(s.length() <= n) cout<<s;
	else{
		for(int i = 0; i < n; i++) cout<<s[i];
		cout<<"...";
	}
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define optimize ios_base::sync_with_stdio(0) ; cin.tie(0) ; cout.tie(0) ;
#define ll long long
#define ld long double
#define lint __int128
#define vi vector<int>
#define pb push_back
#define lp(i,a,b) for(int i = a ; i <= b ; i ++)
#define rlp(i,a,b) for(int i = b ; i >= a ; i --)
#define a_sort(v) sort(v.begin(), v.end())
#define d_sort(v) sort(v.rbegin(), v.rend())
#define pii pair<int,int>
#define pi 3.14159265358979323846264338327950
using namespace std ;
// #define debug

const int MOD = 1E9 + 7 ;
const int N = 1E5 ;

int main() {
    #ifdef debug
    freopen("input.txt", "r", stdin) ;
    freopen("output.txt", "w", stdout) ;
    #endif // debug
    optimize

    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 ;
}



Measured memory_bytes: 3648
def f(y):

    if 1 <= y <=999:
        print(1000-y)
    elif 1000<= y <= 10000 :
        b = int(y / 100)
        c = int(str(b)[1])
        g = 9-c
        h = int(y/10)
        i = int(str(h)[2])

        if y %1000==0:
            print("0")
        elif y % 500==0 and y % 1000!=0:
            print("500")
        elif y % 100==0 and y % 500!=0:
            f = 10-c
            print(f*100)
        elif y % 10 ==0 and y % 100!=0:
            j =10-i
            print(g*100+j*10)
        elif y % 10!=0:
            k = int(str(y)[3])
            l = 9 - i
            m = 10-k
            print(g*100+l*10+m)


y = input()
x = f(int(y))






Measured memory_bytes: 9108
// Library
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

// TYPEDEFS
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;

// CONSTANTS
#define SZA 0
#define SZB 0

// MACRO
#define MAX(X, Y) (((X) > (Y))? (X) : (Y))
#define MIN(X, Y) (((X) < (Y))? (X) : (Y))
#define ABS(X) (((X) > 0)? (X) : -(X))
#define YN(X) ((X)? "Yes" : "No")
#define SWAP(T, X, Y) {T t; t = X; X = Y; Y = t;}

#define F first
#define S second
#define PB push_back
#define MP make_pair


// Global Tables

//ull gPreProcess[SZA][SZB];

// Functions

void Print2DVector(vector<vector<int>>& v)
{
    ull i, j; 
    for(i = 0; i < v.size(); i++)
    {
        for(j = 0; j < v[i].size(); j++)
        {
            cout << v[i][j];
            if(j == v[i].size()-1)
            {
                cout << endl;
            }
            else
            {
                cout << " ";
            }
        }
    }
}

void PrintVector(vi& v)
{
    ull i;
    for(i = 0; i < v.size(); i++)
    {
        cout << v[i];
        if(i == v.size()-1)
        {
            cout << endl;
        }
        else
        {
            cout << " ";
        }
    }
}

void PrintArr(int* a, ull N)
{
    ull i;
    for(i = 0; i < N; i++)
    {
        cout << a[i];
        if(i == N-1)
        {
            cout << endl;
        }
        else
        {
            cout << " ";
        }
    }
}

void PreProcessTables()
{
    ull i, j;
    for(i = 0; i < SZA; i++)
    {
        for(j = 0; j < SZB; j++)
        {
            break;
        }
        break;
    }
}

void TC(int t)
{
    string s;
    cin >> s;
    int val = 0;
    for(auto i:s)
    {
        val = (val + (i-'0'))%9;
    }
    cout << YN(val == 0) << endl;
}

// Main

int main(void)
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
 
    PreProcessTables();

    int T = 1, t;
    for(t = 1; t <= T; t++)
    {
        TC(t);
    }
    return 0;
}


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

const int64_t MOD = 998244353;
void add(int64_t& a, int64_t b){
    a = (a+b) % MOD;
}
void mul(int64_t& a, int64_t b){
    a = a*b % MOD;
}

vector<int64_t> fact, seq_inv, fact_inv;

void create_fact_mod(int num){
    fact[0] = fact[1] = 1;
    for(int i=2; i<=num; i++) fact[i] = fact[i-1] * i % MOD;
}

void create_seq_inv_mod(int num){
    seq_inv[0] = seq_inv[1] = 1;
    for(int i=2; i<=num; i++) seq_inv[i] = (MOD - MOD/i) * seq_inv[MOD%i] % MOD;
}

void create_fact_inv_mod(int num){
    fact_inv[0] = fact_inv[1] = 1;
    for(int i=2; i<=num; i++) fact_inv[i] = fact_inv[i-1] * seq_inv[i] % MOD;
}

void create_mod_tables(int num){
    fact.resize(num+1);
    seq_inv.resize(num+1);
    fact_inv.resize(num+1);
    create_fact_mod(num);
    create_seq_inv_mod(num);
    create_fact_inv_mod(num);
}

int64_t comb_mod(int n, int k){
    return fact[n] * fact_inv[n-k] % MOD * fact_inv[k] % MOD;
}

int64_t perm_mod(int n, int k){
    return fact[n] * fact_inv[n-k] % MOD;
}

int64_t power_mod(int64_t num, int64_t power){
    int64_t prod = 1;
    num %= MOD;
    while(power > 0){
        if(power&1) prod = prod * num % MOD;
        num = num * num % MOD;
        power >>= 1;
    }
    return prod;
}

int64_t extgcd(int64_t a, int64_t b, int64_t& x, int64_t& y){
    int64_t d = a;
    if(b != 0){
        d = extgcd(b, a%b, y, x);
        y -= (a/b) * x;
    }else{
        x = 1; y = 0;
    }
    return d;
}

int64_t inv_mod(int64_t a){
    int64_t x, y;
    extgcd(a, MOD, x, y);
    return (MOD + x%MOD) % MOD;
}


int main(){
    int N;
    string X;
    cin >> N >> X;
    vector<int64_t> pow2(N+1);
    pow2[0] = 1;
    for(int i=1; i<=N; i++) pow2[i] = pow2[i-1] * 2 % MOD;

    vector<int> divs;
    for(int d=1; d*d<=N; d++) if(N%d == 0){
        int d2 = N/d;
        if(d2%2) divs.push_back(d);
        
        if(d != d2 && d%2) divs.push_back(d2);
    }
    // if(N%2){
    //     divs.push_back(1);
    //     if(N > 1) divs.push_back(N);
    // }
    sort(divs.begin(), divs.end());

    vector<bool> dead(N+1);
    vector<int64_t> num(N+1);
    for(int i=0; i<N; i++){
        if(X[i] == '1'){
            for(int d : divs){
                if(dead[d]) continue;
                if(i >= d && X[i-d] == '0') continue;
                int64_t C = pow2[max(0, d-i-1)];
                add(num[d], C);
            }
        }
        for(int d : divs){
            if(i >= d && X[i-d] == X[i]) dead[d] = true;
        }
    }
    for(int d : divs) if(!dead[d]){
        add(num[d], 1);
    }
    for(int d : divs){
        for(int k=2*d; k<=N; k+=d) add(num[k], MOD - num[d]);
    }
    //for(int d : divs) cerr << d << " " << num[d] << endl;
    int64_t ans = 0;
    for(int d : divs){
        int64_t res = num[d] * d;
        if(true) mul(res, 2);
        add(ans, res);
    }
    cout << ans << endl;

    return 0;
}


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

int main(void)
{
    ll N,M;
    cin >> N >> M;

    if(M >= 2*N){
        pr(N+(M-2*N)/4);
    }else{
        pr(M/2);
    }
}

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

int n;
char name[10][25];
int w[10], s[10];

int per[10], used[10];
double bestscore;
int bestper[10];

void dfs(int dep) {
	int i;
	if ( dep == n ) {
		for(i = 0; i < n; i++ ) {
			int noww = 0;
			for(int j = i+1; j < n; j++ )
				noww += w[per[j]];
			if ( s[per[i]] < noww ) {
				return;
			}
		}
		double s1 = 0, s2 = 0;
		double score = 0;
		for(i = 0; i < n; i++ ) {
			s1 += (i+1)*w[per[i]];
			s2 += w[per[i]];
		}
		score = s1/s2;
		if ( score < bestscore ) {
			bestscore = score;
			for(i = 0; i < n; i++ )
				bestper[i] = per[i];
			return;
		}
	}
	
	for( i = 0; i < n; i++ ) {
		if ( used[i] == 0 ) {
			per[dep] = i;
			used[i] = 1;
			dfs(dep+1);
			used[i] = 0;
		}
	}
}
int main() {
	while(cin >> n) {
		if ( !n ) break;
		int i;
		bestscore = 252521833;
		for(i = 0; i < n; i++ )
			cin >> name[i] >> w[i] >> s[i];
		dfs(0);
		for(i = 0; i < n; i++ )
			cout << name[bestper[i]] << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include <iostream>

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

using namespace std;
using ll = long long;

int main()
{
    int D,G,p[10],c[10];
    cin>>D>>G;
    rep(i,D){
        cin>>p[i]>>c[i];
    }
    int ans=1e9;
    rep(mask,(1<<D)){
        int s=0,num=0,rest_max=-1;
        rep(i,D){
            if(mask&(1<<i)){
                s+=100*(i+1)*p[i]+c[i];
                num+=p[i];
            }else{
                rest_max=i;
            }
        }
        if(s<G){
            int s1 = 100*(rest_max+1);
            int need = (G-s+s1-1)/s1;
            if(need>=p[rest_max]){
                continue;
            }
            num+=need;
        }
        ans = min(ans,num);
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
  int N, K;
  ll S;
  cin >> N >> K >> S;
  ll MAX = 1e9;
  vector<ll> answer(N, 0);

  if (S != MAX) {
    for (int i = 0; i < K; i++) {
      answer[i] = S;
    }
    for (int i = K; i < N; i++) {
      answer[i] = MAX;
    }
  }
  else {
    for (int i = 0; i < K; i++) {
      answer[i] = S;
    }
    for (int i = K; i < N; i++) {
      answer[i] = 1;
    }
  }
  for (int i = 0; i < N - 1; i++) {
    cout << answer[i] << " ";
  }
  cout << answer.back() << endl;
  return 0;
}


Measured memory_bytes: 2048
n = int(input())
for i in range(1, n + 1):
  if i % 3 == 0:
    print(" {}".format(i), end = "")
  else:
    x = i
    while x:
      if x % 10 == 3:
        print(" {}".format(i), end = "")
        break
      x = x // 10
print()


Measured memory_bytes: 5868
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define sz(x) (int)((x).size())
#define debug(x) cout << #x << ":" << x << ' ';
#define debugg(x) cout << #x << ":" << x << ' ' << "\n";
#define endl "\n"
#define L(X) ((X)<<1)
#define R(X) (((X)<<1)|1)
#define M(X,Y) (((X)+(Y))>>1)

using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const long long int LLINF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-9;
const double PI = acos(-1);

template<typename T>   T max_self(T& a, T b) { if (a < b) a = b; return a; }
template<typename T>   T min_self(T& a, T b) { if (a > b) a = b; return a; }
template<typename T>   T add(T x, T y) { return ((x % MOD)  + (y % MOD)) % MOD;}
template<typename T>   T mul(T x, T y) { return ((x % MOD) * (long long)(y % MOD)) % MOD;}
template<typename T>   T sub(T x, T y) { return add(x, -y + MOD);}
template<typename T>   T gcd(T a, T b) { return b ? gcd(b, a % b) : a;}
template<typename T>   T lcm(T a, T b) { return a / gcd(a, b) * b;}
template<typename T>   vector<T> read(vector<T>& v, int n) {v.resize(n); for (auto &x : v)cin >> x;}
template<typename T>   void trav(vector<T> &v) {for (int i = 0 ; i < (int)v.size() ; ++i) {cout << v[i]; if (i != (int)v.size() - 1) cout << ' ';}}
int lg2(long long x)   {   return 64 - __builtin_clzll(x) - 1;	}
int lg2(int x)   {   return 32 - __builtin_clz(x) - 1;	}


//Variables Declaration
const int MAXN = 1e5 + 5;

ll dp[MAXN];

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

	memset(dp, 0x3f, sizeof(dp));

	int n, K;
	cin >> n >> K ;

	vector<ll> h(n + 1);

	for (int i = 1 ; i <= n ; ++i) {
		cin >> h[i];
	}

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

	cout  << dp[n] << endl;



	return 0;
}


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

int main(){
    long long n,k;
    cin >> n >> k;
    long long temp = k;
    for(long long i=1;;i++){
        if(n<temp){
            cout << i << endl;
            return 0;
        }
        temp*=k;
    }
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    public static void Main()
    {
        var N = Int32.Parse(Console.ReadLine());
        var A = Console.ReadLine().Split(' ').Select(x=>Decimal.Parse(x)).OrderBy(x=>x).ToArray();
        var ans = A[0];
        for (int i=1;i<N;++i)
        {
            ans = (ans + A[i]) / 2;
        }
        Console.WriteLine(ans);
    }
}


Measured memory_bytes: 13396
#include <iostream>
using namespace std;
int main()
{
	int a[6] = {0}, n, i, j;
	double t;
	cin >> n;
	for (i = 0; i < n; i++)
	{
		cin >> t;
		if (t < 165.0)		a[0]++;
		else if (t < 170.0)	a[1]++;
		else if (t < 175.0) a[2]++;
		else if (t < 180.0) a[3]++;
		else if (t < 185.0) a[4]++;
		else				a[5]++;
	}
	for (i = 1; i <= 6; i++)
	{
		cout << i << ":";
		for (j = 0; j < a[i-1]; j++)
		{
			cout << "*";
		}
		cout << endl;
	}
}

Measured memory_bytes: 0
#include  <iostream>
#include  <algorithm>
#include  <climits>
#include  <string>
#include  <vector>

using namespace std;

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

typedef long long ll;
const int MAX = INT_MAX;

int main()
{	
	int n, m;
	cin >> n >> m;
	vector<int> A(m);
	rep(i, m)  cin >> A[i];
	int sum = 0;
	rep(i, m)  sum += A[i];

	if (n - sum >= 0)  cout << n - sum << endl;
	else  cout << -1 << endl;
}

Measured memory_bytes: 3664
n, m = map(int, input().split())
ac = 0
wa = [0 for i in range(n + 1)]
al = [0 for i in range(n + 1)]
if m == 0:
  k = [0, 0]
  print(*k)
  exit()
for i in range(m):
  k = list(input().split())
  a = int(k[0])
  if al[a] == 1:
    continue
  elif al[a] == 0 and k[1] == "WA":
    wa[a] += 1
  elif al[a] == 0 and k[1] == "AC":
    ac += 1
    al[a] = 1
wan = 0
for i in range(n+1):
  if al[i] == 1:
    wan += wa[i]
lis = [ac, wan]
print(*lis)

Measured memory_bytes: 4784
#include<iostream>
#include<string>
using namespace std;
typedef long long int ll;

int main(){
	string s;
	int w;
	cin >> s;
	cin >> w;
	int n = s.length();
	string ans = "";
	for(int i = 0; i < n; i += w){
		ans += s[i];
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N = 50000;
const int INF = 1e8;
const int M = 20;

int dp[M+1][N+1];
unsigned int cnt;
vector<int> v;

int rec(int m,int n){
    if(dp[m][n] != -1){
        return dp[m][n];
    }

    if(!n){
        return 0;
    }

    if(m == v.size()){
        return INF;
    }

    if(v[m] > n){
        return dp[m][n] = rec(m+1,n);
    }else{
        return dp[m][n] = min(rec(m+1,n),rec(m,n-v[m])+1);
    }
}

/*int main(){
    int n,m;
    cin >> n >> m;

    v.resize(m);

    for(auto &t: v){
        cin >> t;
    }

    for(int i=0;i<=M;i++){
        for(int j=0;j<=N;j++){
            dp[i][j]=(j==0?0:INF);
        }
    }

    for(int i=0; i<m; i++){
        for(int j=0; j<=n; j++){
            if(j < v[i]){
                dp[i+1][j] = dp[i][j];
            }else{
                dp[i+1][j] = min(dp[i][j],dp[i+1][j-v[i]]+1);
            }
        }
    }

    cout << dp[m][n] << endl;
}*/

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

    v.resize(m);
    for(auto &t: v){
        cin >> t;
    }

    memset(dp,-1,sizeof(dp));

    cout << rec(0,n) << endl;
}

Measured memory_bytes: 7644
#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 1000000000
#define LINF 1000000000000000000
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define bit(n) (1LL<<(n))
using namespace std;

typedef pair<int, int> P;
typedef pair<long long, long long> LLP;

int main() {

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

    vector<vector<int>> edges(N + 1);

    rep(i,M) {
        int A, B;
        cin >> A >> B;
        edges[A].push_back(B);
        edges[B].push_back(A);
    }

    queue<int> que;
    que.push(1);

    vector<int> ans(N + 1, 0);

    while (!que.empty()) {
        int p = que.front(); que.pop();
        rep(i,edges[p].size()) {
            int q = edges[p][i];
            if (q != 1 && ans[q] == 0) {
                ans[q] = p;
                que.push(q);
            }
        }
    }

    for (int i = 2; i <= N; i++) {
        if (ans[i] == 0) {
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;
    for (int i = 2; i <= N; i++) cout << ans[i] << endl;
    
    return 0;
}

Measured memory_bytes: 10212
#include<stdio.h>
#include<cstdio>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<cmath>
#include<vector>

#include<stack>
#include<queue>
#include<time.h>
#include<set>
#include<map>
#include <iomanip>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i>b;i--)
#define vint vector<int> 
#define vvint vector<vint>
#define ct(a) cout<<a<<endl
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const ll mod = 998244353;


string S;

ll ans,P,Q,R;
queue<int>que;

int main() {

	cin >> P >> Q >> R;

	cout << min(min(P + Q, P + R), R + Q) << endl;


	return 0;
}

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

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

const int dr[4] = {-1, 0, 1, 0};
const int dc[4] = {0, 1, 0, -1};

struct StronglyConnectedComponents {
  int V;
  vector<vector<int>> G, rG;
  vector<int> vs, cmp;
  vector<bool> used, added;

  StronglyConnectedComponents(int V) : V(V) {
    used.assign(V, false), added.assign(V, false);
    G.resize(V), rG.resize(V);
    cmp.resize(V);
  }

  void add_edge(int from, int to) {
    G[from].push_back(to);
    rG[to].push_back(from);
  }

  void dfs(int s) {
    stack<int> stk;
    stk.push(s);
    while (not stk.empty()) {
      int v = stk.top();
      used[v] = true;
      bool pushed = false;
      for (int c : G[v]) if (not used[c]) stk.push(c), pushed = true;
      if (not pushed) {
        if (not added[v]) added[v] = true, vs.push_back(v);
        stk.pop();
      }
    }
  }

  void rdfs(int s, int k) {
    stack<int> stk;
    stk.push(s);
    while (not stk.empty()) {
      int v = stk.top(); stk.pop();
      used[v] = true;
      cmp[v] = k;
      for (int c : rG[v]) if (not used[c]) stk.push(c);
    }
  }

  int run() {
    fill(used.begin(), used.end(), false);
    fill(added.begin(), added.end(), false);
    vs.clear();
    for (int v = 0; v < V; v++) if (!used[v]) dfs(v);
    fill(used.begin(), used.end(), false);
    int k = 0;
    for (int i = vs.size() - 1; i >= 0; i--) if (not used[vs[i]]) rdfs(vs[i], k++);
    return k;
  }
};

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

  int V, E; cin >> V >> E;
  StronglyConnectedComponents scc(V);
  REP(_, E) {
    int f, t; cin >> f >> t;
    scc.add_edge(f, t);
  }
  scc.run();
  int Q; cin >> Q;
  REP(_, Q) {
    int x, y; cin >> x >> y;
    cout << (scc.cmp[x] == scc.cmp[y]) << endl;
  }
  return 0;
}

Measured memory_bytes: 4292
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).end()
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 int NM = 1e5+1;
vector<int> ab[NM];

//abc137_d
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,m;cin>>n>>m;
    rep(i,n){
        int a,b;cin>>a>>b;
        ab[a].push_back(b);
    }
    priority_queue<int> pq;
    ll ans = 0;
    for(int i=m-1; i>=0; i--){
        // i日目=(m-i)日で金がもらえる仕事が可能
        vector<int> t = ab[m-i];
        for(int u : t){
            pq.push(u);
        }
        if(!pq.empty()){
            ans += (ll)pq.top(); pq.pop();
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 5632
#include <iostream>
#include <algorithm>
#include<string>
#include<cmath>
#include<stack>
#include<queue>
using namespace std;


int main() {
	int n, a[2][810], ans, sum = 0, dif[810];
	cin >> n;
	for (int i = 0; i < 2; i++) {
		for (int j = 0; j < n; j++) {
			cin >> a[i][j];
		}
	}
	for (int i = 0; i < (n - 1); i++) {
		dif[i] = a[1][i] - a[0][i + 1];
		//cout << "difi" << dif[i] << '\n';
	}
	for (int i = 0; i < n; i++) {
		sum += a[1][i];
	}
	sum += a[0][0];
	ans = sum;
	//cout <<"花壇"<< sum << '\n';
	for (int i = 0; i < (n - 1); i++) {
		ans = max(ans, sum - dif[i]);
		sum -= dif[i];
		//cout <<i<<"回目"<< ans<<'\n';
	}
	if (n == 1) {
		ans = sum;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int mod = 1000000007;
const double PI = acos(-1);

int main()
{
	ll n;
	cin >> n;
	vector<ll> a(n);
	for (ll i = 0; i < n; i++) cin >> a[i];
	vector<ll> s(n);
	s[0] = a[0];
	for (int i = 1; i < n; i++) {
		s[i] = s[i - 1] + a[i];
	}

	ll ans = 0;
	for (ll i = 0; i < n - 1; i++) {
		ll delta = (a[i] % mod) * ((s[n - 1] - s[i]) % mod);
		delta %= mod;
		ans = (ans + delta) % mod;
	}
	cout << ans << endl;
}


Measured memory_bytes: 6360
import math
n, k = map(int, input().split())
p = 0
if k > n:
    for i in range(n):
        times = math.ceil(math.log2(k / (i + 1)))
        p += (1 / n) * (1 / 2) ** times
else:
    for i in range(k):
        times = math.ceil(math.log2(k / (i + 1)))
        p += (1 / n) * (1 - (1 / 2) ** times)
    p = 1 - p
print(p)


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

int main(){
    int N;
    cin >> N;
    vector<int> a(3*N);
    for (int i = 0; i < 3*N; i++)
    {
        cin >> a.at(i);
    }
    
    sort(a.begin(), a.end());
    reverse(a.begin(), a.end());

    long long sum = 0;
    for (int i = 1; i < 2*N; i+=2){
        sum += a.at(i);
    }
    
    cout << sum << endl;

    return 0;
}

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

int main(){
    int n,R[200000],min,ans;
    cin >> n;
    for ( int i = 0; i < n; i++ ) cin >> R[i];
    ans = R[1]-R[0];
    min = R[0];
    for ( int i = 1; i < n; i++ ){
        if(min>R[i]){
            if(ans < R[i] - min)ans = R[i] - min;
            min = R[i];
        }else if(min<=R[i]){
            if(ans < R[i] - min)ans = R[i] - min;
        }
    }
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 1940
import sys
stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)

def LI(): return list(map(int, stdin.readline().split()))
def LS(): return list(stdin.readline())

import math
a,b = LI()
tax8 = [i for i in range(math.ceil(100/8*a), int(100/8*(a+1)))]
tax10 = [i for i in range(math.ceil(100/10*b), int(100/10*(b+1)))]
# print(tax8,tax10)
c = max(tax8[0], tax10[0])
if c in tax8 and c in tax10:
    print(c)
else:
    print(-1)

Measured memory_bytes: 3188
/**
*
* Author: Mouhanad
* Lang: GNU C++14
*
**/
#include<bits/stdc++.h>
using namespace std;

#define F first
#define S second
#define ii pair < int , int >
#define LS pair < ll , string >
typedef long long ll;
const int inf = 1<<30;
const int N =100100;
int n , a[N] , q ;

int main ( ){
 int c , d ;
 cin >> c >> d ;
 if ( c >9 || d > 9 ) cout << -1 ;
 else cout << c*d ;
return 0 ;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define debug(x, y) cout << x<<" "<<y<<endl
#define gg cout <<"-------------QAQ---------------"<<endl
#define fi first
#define se second
#define pb push_back
#define SZ(x) ((int)x.size())
#define L(i,u) for (register int i=head[u]; i; i=nxt[i])
#define rep(i,a,b) for (register int i=(a); i<=(b); i++)
#define per(i,a,b) for (register int i=(a); i>=(b); i--)
using namespace std;
typedef long long ll;
typedef unsigned int ui;
typedef pair<int,int> Pii;
typedef vector<int> Vi;
template<class T> inline void read(T &x){
	x=0; char c=getchar(); int f=1;
	while (!isdigit(c)) {if (c=='-') f=-1; c=getchar();}
	while (isdigit(c)) {x=x*10+c-'0'; c=getchar();} x*=f;
}
template<class T> inline void umin(T &x, T y){x=x<y?x:y;}
template<class T> inline void umax(T &x, T y){x=x>y?x:y;}
const int N = 566666;
void FAST(){ios::sync_with_stdio(false);cin.tie(0);}

int ok(int x)
{
    return 100*x+10*x+x;
}
int main()
{
    FAST;
    int n;
    cin >> n;
    for(int i = 1; i <= 9; ++i)
    {
        if(n <= ok(i))
        {
            cout <<ok(i)<<"\n";
            return 0;
        }
    }
    return 0;
}














Measured memory_bytes: 256
class Combination:

    def __init__(self, n_max, mod=10**9+7):
        self.mod = mod
        self.modinv = self.make_modinv_list(n_max)
        self.fac, self.facinv = self.make_factorial_list(n_max)

    def __call__(self, n, r):
        return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod

    def make_factorial_list(self, n):
        # 階乗のリストと階乗のmod逆元のリストを返す O(n)
        # self.make_modinv_list()が先に実行されている必要がある
        fac = [1]
        facinv = [1]
        for i in range(1, n+1):
            fac.append(fac[i-1] * i % self.mod)
            facinv.append(facinv[i-1] * self.modinv[i] % self.mod)
        return fac, facinv

    def make_modinv_list(self, n):
        # 0からnまでのmod逆元のリストを返す O(n)
        modinv = [0] * (n+1)
        modinv[1] = 1
        for i in range(2, n+1):
            modinv[i] = self.mod - self.mod//i * \
                modinv[self.mod % i] % self.mod
        return modinv


def resolve():
    n, m, k = map(int, input().split())
    mod = 998244353
    c = Combination(n, mod)
    ans = 0
    for i in range(k + 1):
        ans += c(n - 1, i) * pow(m - 1, n - i - 1, mod)
    ans %= mod
    ans *= m
    ans %= mod
    print(ans)


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 97128
k = int(input())

import math
#from functools import reduce
#def gcd(*numbers):
#    return reduce(math.gcd, numbers)

total = 0
for a in range(1,k+1):
    for b in range(1,k+1):
        tmp = math.gcd(a,b)
        for c in range(1,k+1):
            total += math.gcd(tmp,c)
print (total)


Measured memory_bytes: 9064
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include<algorithm>
#include<string>
#include <map>
#include <queue>
#include <stack>
#include <set>

#define DIV 1000000007
using namespace std;
using ll = long long;

typedef struct {
	int parent = 0;
	int height = 1;
	ll mem = 1;
}node_t;
vector<node_t> node;

int root(int a) {
	if (node[a].parent == 0) return a;
	else {
		node[a].parent = root(node[a].parent);
		return node[a].parent;
	}
}

void unite(int root_a, int root_b) {
	int up, low;
	if (node[root_a].height >= node[root_b].height)
		up = root_a, low = root_b;
	else
		up = root_b, low = root_a;

	node[up].height = max(node[up].height, node[low].height + 1);
	node[low].parent = up;
	node[up].mem += node[low].mem;
}

int main(void) {
	ll N, M;
	cin >> N >> M;

	vector<pair<int, int>> bri(M);
	for (int i = 0; i < M; i++) {
		cin >> bri[i].first >> bri[i].second;
	}

	node = vector<node_t>(N + 1);
	vector<ll> ans(M);
	ans[M - 1] = N * (N - 1) / 2;
	for (int i = M - 1; i >= 1; i--) {
		ans[i - 1] = ans[i];
		int a = bri[i].first, b = bri[i].second;
		int art = root(a), brt = root(b);
		if (art == brt) continue;
		ll temp = node[art].mem * node[brt].mem;
		ans[i - 1] -= temp;
		unite(art, brt);
	}

	for (int i = 0; i < M; i++) {
		cout << ans[i] << endl;
	}

}


Measured memory_bytes: 4480
#include <cstdio>

int main(){
    int i,j,n,m,c,ret,sum,tmp;
    int b[20];
    scanf("%d %d %d",&n,&m,&c);
    for(i=0;i<m;i++){
        scanf("%d",b+i);
    }
    ret = 0;
    for(i=0;i<n;i++){
        sum = c;
        for(j=0;j<m;j++){
            scanf("%d",&tmp);
            sum += tmp*b[j];
        }
        if(sum>0)ret++;
    }
    printf("%d\n",ret);
    return 0;
}


Measured memory_bytes: 128
#include<iostream>
using namespace std;
int main(){
  int a,b;
  cin >> a >> b;
  if(a>b) {
    cout << "a > b" << endl;
  } else if(a<b) {
    cout << "a < b" << endl;
  } else {
    cout << "a == b" << endl;

  }
  return 0;
}


Measured memory_bytes: 3052
#include <bits/stdc++.h>
using namespace std;
long long n,m;
string s[100],t[100];
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
bool B[55][55];

int main(){
  cin >> n >> m;
  for(int i=0;i<n;i++){
    cin >> s[i];
  }
  for(int i=0;i<m;i++){
    cin >> t[i];
  }
  for(int i=0;i<=n-m;i++){
    for(int j=0;j<=n-m;j++){
      int cnt=0;
      if(s[i][j]==t[0][0]){
        for(int k=0;k<m;k++){
          for(int l=0;l<m;l++){
            if(s[k+i][l+j]==t[k][l]){
              cnt++;
            }
          }
        }
        if(cnt==m*m){
          cout << "Yes" << endl;
          return 0;
        }
      }
    }
  }
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <vector>
#include <iostream>
#include <set>
#include <queue>
#include <cstring>
#include <string>
#include <algorithm>
using namespace std;
#define mst(a,b) memset((a),(b),sizeof(a))
#define rush() int T;scanf("%d",&T);while(T--)
typedef long long ll;
ll a[100005],b[100005],c[100005],sum[100005],tmp,ans,n;
int main(){
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	for(int i=1;i<=n;i++)
		cin>>b[i];
	for(int i=1;i<=n;i++)
		cin>>c[i];
	sort(a+1,a+n+1);
	sort(b+1,b+n+1);
	sort(c+1,c+n+1);
	for(int i=1;i<=n;i++){
		sum[i]=sum[i-1]+(n-(upper_bound(c+1,c+n+1,b[i])-(c+1)));
	}
	b[n+1]=a[n]+3;
	for(int i=1;i<=n;i++){
		tmp=(upper_bound(b+1,b+n+2,a[i])-b);
		if(tmp>n)
			break;
		else 
			ans+=(sum[n]-sum[tmp-1]);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3328