akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <math.h>
#include <iostream>
#include <stdlib.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define MOD (1000000007)
using namespace std;
 
int main(){
  int n,count=0;
  cin >> n;

  for(int i=1;i<=n;i++){
    if(((int)log10((double)i)+1)%2==1){
      count += 1;
    }
  }
  

  printf("%d\n",count);
  return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#define ff first
#define ss second
#define pb push_back
#define ll long long
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) a*(b/__gcd(a,b))
#define mkp(x,y) make_pair(x,y)
#define all(x) x.begin(),x.end()
#define test ll t;cin>>t;while(t--)
#define check(a) cout<<#a<<" = "<<a<<endl;
#define rep(i,a,b) for(ll i=a; (a<=b)?i<=b:i>=b; (a<=b)?i++:i--)
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fileio freopen("input.txt","r",stdin);freopen("output.txt","w",stdout)

const ll Mod = 1000000007LL;
const ll Inf = 2242545357980376863LL;
const int maxn = 1e5;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef vector<pii> vpi;
typedef map<int,int> mii;
typedef map<string,int> msi;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> oset;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> omset;


//////////////////////// Template Ends ///////////////////////////////////


int main(){
	int a; cin>>a;
	cout<<a+a*a+a*a*a;
	return 0;
}





Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1000000007;

int main(){
    string S;
    cin >> S;
    
    int ans = 0;
    bool flag = false;
    for(int i = 1; i < 4; i++){
        if(S[i-1] == S[i])
            flag = true;
    }
    if(flag)
        cout << "Bad" << "\n";
    else
        cout << "Good" << "\n";
    return 0;
} 


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef long double ld;
const ll MAX = 3000000;
const ll MOD = 1000000007;
ll n, a, b;

ll powerRet(ll m, ll p){
    if(p==0) return 1;
    if(p%2==0){
        ll temp = powerRet(m, p/2);
        return (temp * temp) % MOD;
    }
    return (m * powerRet(m, p-1)) % MOD;
}

ll comb(ll x, ll y){
    ll child = 1;
    ll mother = 1;
    for(ll i=0; i<y; i++){
        child = (child * (x-i)) % MOD;
        mother = (mother * (y-i)) % MOD; 
    }
    ll motherInv = powerRet(mother, MOD-2);
    return (child * motherInv) % MOD;
}

int main() {
    cin >> n >> a >> b;
    ll ans1 = (powerRet(2,n) - 1) % MOD;
    ll ans2 = comb(n,a);
    ll ans3 = comb(n,b);
    ll ans4 = (ans2 + ans3) % MOD; 
    ll ans = ans1-ans4;
    ans = (ans < 0) ? MOD + ans : ans;
    cout << ans << endl;
}

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

const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;

int n;
int d[300][300];
int a[300];

int calc(int v){
	queue<int>que;
	memset(a,-1,sizeof(a));
	a[v]=0;
	que.push(v);
	int Max=0;
	while(!que.empty()){
		int p=que.front();que.pop();
		rep(i,n){
			if(d[p][i]==1){
				if(a[i]!=-1){
					if(abs(a[i]-a[p])!=1){
						return -2;
					}
				}
				else{
					a[i]=a[p]+1;
					Max=max(Max,a[i]);
					que.push(i);
				}
			}
		}
	}
	return Max;
}
int main(){
	cin>>n;
	rep(i,n)rep(j,n)scanf("%1d",&d[i][j]);
	//~ rep(i,n)for(int j=i+1;j<n;j++){
		//~ if(d[i][j]==1){
			//~ cout<<i<<' '<<j<<endl;
		//~ }
	//~ }
	//~ return 0;
	int Max=-2;
	rep(i,n)Max=max(Max,calc(i));
	cout<<Max+1<<endl;
}

Measured memory_bytes: 512
N,T = map(int,input().split())
*A, = map(int,input().split())
m = [A[0]]*N
B = [0]*N
for i,a in enumerate(A[1:],1):
    m[i] = min(m[i-1],a)
    B[i] = a - m[i]
MB = max(B)
print(B.count(MB))

Measured memory_bytes: 14292
#include <iostream>

//二項係数 mod p
long long modinv(long long n, long long p) {
  long long a = p, u = 1, v = 0;
  while (a) {
    long long t = n / a;
    n -= t * a;
    std::swap(n, a);
    u -= t * v;
    std::swap(u, v);
  }
  u %= p;
  if (u < 0) u += p;
  return u;
}

long long ncr(long long n, long long r, long long p) {
  r = std::min(r, n - r);
  long long ans = 1;
  for (long long i = 0; i < r; i++) {
    ans *= (n - i) % p;
    ans %= p;
  }
  for (long long i = 0; i < r; i++) {
    ans *= modinv(i + 1, p);
    ans %= p;
  }
  return ans;
}

int main() {
  long long x, y, p = 1e9 + 7;
  std::cin >> x >> y;
  if ((x + y) % 3 > 0) std::cout << 0 << std::endl;
  else {
    long long move = (x + y) / 3;
    if (x < move || y < move) std::cout << 0 << std::endl;
    else std::cout << ncr(move, x - move, p) << std::endl;
  }
}

Measured memory_bytes: 384
//include
//------------------------------------------
#include <bits/stdc++.h>
using namespace std;
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef long long ll;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
// chmax chmin
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

ll f(ll b, ll n){
    ll res = 0;
    while(n){
        res += n%b;
        n /= b;
    }
    return res;
}

int main(void){
    ll n, s;
    cin >> n >> s;

    if(n == s){cout << n+1 << endl; return 0;}
    else{
        for(ll b=2; b*b<=n; b++)
            if(s == f(b,n)){cout << b << endl; return 0;}

        for(ll p=floor(sqrt(n)); p>0; p--){
            ll b = (n-s)/p + 1;
            if(b < 2) continue;
            if(s == f(b,n)){cout << b << endl; return 0;}
        }
    }

    cout << -1 << endl;

    return 0;
}

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

using namespace std;

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

	int ans = 0;
	for (int i = 0; i < n; i++) {
		if (i == a[a[i]]) {
			ans++;
		}
	}
	cout << ans / 2 << endl;

	return 0;
}

Measured memory_bytes: 640
n,k,q = map(int, input().split())
a = list(map(int, input().split()))

def parse(b):
    ret = []
    tmp = []
    for ai in a:
        if ai >= b:
            tmp.append(ai)
        else:
            if len(tmp) >= k:
                tmp.sort(reverse=True)
                for i in range(k-1,len(tmp)):
                    ret.append(tmp[i])
            tmp = []
    else:
        if len(tmp) >= k:
            tmp.sort(reverse=True)
            for i in range(k-1,len(tmp)):
                ret.append(tmp[i])
            tmp = []
    return ret

ans = 10**10

for b in set(a):
    lis = parse(b)
    if len(lis) < q:
        continue
    lis.sort()
    ans_tmp = lis[q-1] - lis[0]
    ans = min(ans, ans_tmp)

print(ans)

Measured memory_bytes: 47196
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<queue>
#include<cmath>
#include<set>
using namespace std;
typedef long long LL;
const int N=100010;
int n,m;
struct node
{
    int d;
    int p;
} a[N];
struct cmp
{
    bool operator() (int &x,int &y)
    {
        return a[x].p>a[y].p;
    }
};
priority_queue<int,vector<int>,cmp> q;
bool cmp(node x,node y)
{
    return x.d<y.d;
}
int main()
{
    scanf("%d%d",&n,&m);
    for(int i=1; i<=n; i++)
    {
        scanf("%d%d",&a[i].d,&a[i].p);
        if(a[i].d>m) a[i].d=0;
        else
        a[i].d=m-a[i].d+1;
    }
    sort(a+1,a+1+n,cmp);
    while(!q.empty()) q.pop();
    int x;
    LL ans=0;
    for(int i=1; i<=n; i++)
    {
        if(a[i].p>0)
        {
            q.push(i);
            ans+=a[i].p;
        }
        while(q.size()>a[i].d)
        {
            x=q.top();
            ans-=a[x].p;
            q.pop();
        }
    }
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 1660
//                   ********** YATIN KWATRA **********

// AC BAKSHI RABBA

#include <bits/stdc++.h>
#define ll                      long long 
#define ld                      long double
#define ull                     unsigned long long 
#define FIO                     ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl                    "\n"
#define fo(i,a,b)               for(int i = a; i<=b ; i++)
#define rfo(i,a,b)              for(int i = a; i>=b ; i--)
#define vii                     vector<int>
#define vll                     vector<ll>
#define pq                      priority_queue
#define uom                     unordered_map                
#define all(v)                  v.begin(),v.end()
#define mp                      make_pair
#define pb                      push_back
#define pob                     pop_back
#define ff                      first
#define ss                      second
#define pii                     pair<int,int> 
#define pll                     pair<long,long>
#define mll                     map<ll,ll>
#define mii                     map<int,int>
#define vvii                    vector<vii>
#define vvll                    vector<vll>
#define mod                     1000000007
#define pi                      3.1415926535897932384626433832795

using namespace std;

void INPUT() 
{  
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
}

/*
    
   -> Check For Overflows
   -> Out of Bounds
   -> Initialisations of global arrays and variables
   -> Its not Always Complex, Try to simplify
   -> write it down and try to solve
   -> Have Faith in urself and in ur approach
   -> If it seems totally out of reach, switch to next :)
   -> And Come Back later, if possible 
*/





void solve()
{ 
        ll n;
        cin >> n;
        
        vll v(n);
        
        fo(i,0,n-1) cin >> v[i];

        sort(all(v),greater<ll>());

        ll ans = 0LL;

        ans += v[0];

        ll left = n-2, val;
        int id;

        fo(i,1,n-1)
        {
          if(left>=2LL)
          {
            val = v[i]+v[i];
            ans += val;
            left--;
            left--;
          }
          else
          {
           if(left>0) ans += v[i];
            break;
          } 
     }
     
        cout << ans << endl;
       
}
int main() {
    
    FIO
    INPUT();
    
    int t;
    t = 1;
    //cin >> t;
    
    while(t--)
    {
       solve();
    }
    return 0;
}


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

using namespace std;

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

typedef long long ll;

const int Inf = 1e9;
const double EPS = 1e-9;

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

int lcm(int a, int b) {
    return a * b / gcd(a, b);
}

int bitCount(long bits) {
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
    return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, k;
    string s;
    cin >> n >> k >> s;
    int score = 0;
    rep (i, n - 1) {
        if (s[i] == s[i + 1]) score++;
    }
    cout << min(score + 2 * k, n - 1) << endl;
    
    return 0;
}



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

int main() {
  string STR;
  cin >> STR;
  int ans;
  if (STR=="SUN") ans=7;
  if (STR=="MON") ans=6;
  if (STR=="TUE") ans=5;
  if (STR=="WED") ans=4;
  if (STR=="THU") ans=3;
  if (STR=="FRI") ans=2;
  if (STR=="SAT") ans=1;
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <vector>

using namespace std;

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

    for (int i = 1; i <= 3; i++){
        if (A != i && B != i){
            cout << i << endl;
            break;
        }
    }
    
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<queue>
using namespace std;
int main() {
	priority_queue<int>que;
	int n, m;
	long long sum = 0;
	cin >> n >> m;
	vector<int>a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		que.push(a[i]);
	}
	while (m > 0) {
		//cout << que.top() << endl;
		int t=que.top();
		que.pop();
		t /= 2;
		que.push(t);
		m--;
	}
	for (int i = 0; i < n; i++) {
		sum += que.top();
		que.pop();
	}
	cout << sum << endl;
	
	system("pause");
}


Measured memory_bytes: 1392
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int d = a + b + c;
		if(d >= 22){
			System.out.println("bust");
		}else{
			System.out.println("win");			
		}
	}
}


Measured memory_bytes: 23252
N,K = map(int,input().split())

MOD = 10**9 + 7
A = [0] * (K + 1)

# 最大公約数がdの倍数の個数
for d in range(1, K + 1):
    A[d] = pow(K // d, N, MOD)

# ちょうどdになるためには
for d in range(K, 0, -1):
    # 2d,3d,...を引く
    for i in range(2, K // d + 1):
        A[d] -= A[d * i]

answer = sum(d * x for d, x in enumerate(A))
print(answer % MOD)

Measured memory_bytes: 11552
import java.awt.Point;
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner s = new Scanner(System.in);
    int n = s.nextInt();
    Point[] a = new Point[n];
    for (int i = 0; i < n; i++) {
      a[i] = new Point(s.nextInt(), s.nextInt());
    }

    double r = 0;

    for (int i = 0; i < n; i++) {
      for (int j = i + 1; j < n; j++) {
        r += a[i].distance(a[j]);
      }
    }
    System.out.println(r * 2 / n);
  }
}


Measured memory_bytes: 27168
#include <iostream>
#include <algorithm>
#include <fstream>
#include <vector>
#include <deque>
#include <assert.h>
#include <stack>
#include <set>
#include <map>
#include <stdio.h>
#include <string.h>
#include <utility>
#include <math.h>
#include <bitset>
#include <iomanip>
#include <complex>
#include <queue>
using namespace std;
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define IDX(vec, element_iter) distance((vec).begin(), element_iter)
#define print(x) cout<<(x)<<'\n'
#define print_vec(v) rep(i,v.size()){if(i!=0)cout<<" ";cout<<v[i];}cout<<'\n'
#define pe(x) cout<<(x)<<" "
#define DEBUG(x) cout<<#x<<": "<<x<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";rep(i,v.size())cout<<" "<<v[i];cout<<'\n'
#define pb push_back
#define mp make_pair
#define MOD 1000000007 //10^9+7
#define fi first
#define sc second
using ll=long long;
using pll=pair<ll,ll>;
using vll=vector<ll>;
using vvll=vector<vll>;
using vstr=vector<string>;

void solve() {
    ll x;
    cin >> x;
    if(x>=30) print("Yes");
    else print("No");
}

int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
	cout<<fixed<<setprecision(20);
    //int q; cin >> q;
	//while (q--)
		solve();
    return 0;
}

Measured memory_bytes: 3612
#include <iostream>
#include <vector>
#include <cmath>
#include <limits.h>
#include <utility>
#include <map>
#include <algorithm>
#include <set>
using namespace std;
using P = pair<int,int>;
using ll = long long;
const int MOD=1e9+7;
void modplus(int &a,int b){
    a+=b;
    a%=MOD;
}
ll eline(int a){
    if(a<=0)return 1ll;
    vector<vector<int>> dp(a,vector<int>(2,0));
    dp[0][0]=1;
    dp[0][1]=1;
    for(int i=1;i<a;i++){
        dp[i][0]=dp[i-1][0]+dp[i-1][1];
        dp[i][1]=dp[i-1][0];
    }
    return dp[a-1][0]+dp[a-1][1];
}
int main(){
    int h,w,g;
    cin>>h>>w>>g;
    g--;
    vector<vector<int>> dp(h+1,vector<int>(w,0));
    dp[0][0]=1;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            for(int l=-1;l<=1;l++){
                int from=j,to=j+l;
                if(from>to)swap(from,to);
                if(l==0){
                    modplus(dp[i+1][j],dp[i][j]*(eline(from-1)*eline(w-to-2)%MOD)%MOD);
                }else if(0<=j+l&&j+l<w){
                    modplus(dp[i+1][j+l],dp[i][j]*(eline(from-1)*eline(w-to-2)%MOD)%MOD);
                }
            }
        }
    }
    cout<<dp[h][g]<<endl;
}

Measured memory_bytes: 3612
#include<iostream>
using namespace std;
typedef long long ll;
int main(void)
{
    string s;
    ll cnt=0,ans=0;
    cin >> s;
    for(auto x:s)
    {
        if(x=='B') cnt++;
        else ans+=cnt;
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 640
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <tuple>
#include <vector>

using namespace std;
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;

#define INF (1e9)

int N;
vs A = {
    "aacd",
    "bbcd",
    "efgg",
    "efhh"};
vs B = {
    "aadee",
    "bbd.g",
    "ccffg",
    "..hij",
    "..hij"};
vs C = {
    ".aacdd",
    "b..c.e",
    "b..ffe",
    "gjj.kk",
    "g.il..",
    "hhil.."};
vs D = {
    ".aa",
    "b..",
    "b.."};
vs E = {
    ".aabbcc",
    "d.ee.ff",
    "dg..h..",
    "ig..h..",
    "i.jj.kk",
    "lm..n..",
    "lm..n.."};

int main() {
    cin >> N;

    if (N < 3) {
        cout << -1 << endl;
        return 0;
    }

    if (N == 3) {
        for (auto s : D) {
            cout << s << endl;
        }
        return 0;
    }

    if (N == 7) {
        for (auto s : E) {
            cout << s << endl;
        }
        return 0;
    }

    int a = 0, b = 0, c = 0;
    int M = N;
    if (N % 2 == 1) {
        b = 1;
        M -= 5;
    }

    if (M % 4 != 0) {
        c = 1;
        M -= 6;
    }
    a = M / 4;

    int sCol = 0;
    for (int i = 0; i < a; i++) {
        for (int j = 0; j < 4; j++) {
            int col = 0;
            for (; col < sCol; col++) {
                cout << ".";
            }
            cout << A[j];
            col += 4;
            for (; col < N; col++) {
                cout << ".";
            }
            cout << endl;
        }
        sCol += 4;
    }
    for (int i = 0; i < b; i++) {
        for (int j = 0; j < 5; j++) {
            int col = 0;
            for (; col < sCol; col++) {
                cout << ".";
            }
            cout << B[j];
            col += 5;
            for (; col < N; col++) {
                cout << ".";
            }
            cout << endl;
        }
        sCol += 5;
    }
    for (int i = 0; i < c; i++) {
        for (int j = 0; j < 6; j++) {
            int col = 0;
            for (; col < sCol; col++) {
                cout << ".";
            }
            cout << C[j];
            col += 6;
            for (; col < N; col++) {
                cout << ".";
            }
            cout << endl;
        }
        sCol += 6;
    }

    return 0;
}


Measured memory_bytes: 1280
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

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

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

    int n;
    cin >> n;
    vector<int> len(3);
    for(int i = 0; i < 3; ++i)  cin >> len[i];
    vector<int> l(n);
    for(int i = 0; i < n; ++i)  cin >> l[i];
    vector<vector<int>> st(3);
    function<int(int)> dfs = [&](int N) -> int{
        if(N == n){
            if(!st[0].size() || !st[1].size() || !st[2].size()) return INF;
            int res = 0;
            for(int i = 0; i < 3; ++i){
                int S = accumulate(st[i].begin(), st[i].end(), 0);
                res += 10 * (st[i].size() - 1);
                res += abs(S - len[i]);
            }
            return res;
        }
        int res = INF;
        for(int i = 0; i < 3; ++i){
            st[i].push_back(l[N]);
            chmin(res, dfs(N + 1));
            st[i].pop_back();
        }
        chmin(res, dfs(N + 1));
        return res;
    };
    cout << dfs(0) << endl;
}

Measured memory_bytes: 256
def get_input():
  return list(map(int, input().split(' ')))

(n, q) = get_input()

l = [[] for i in range(n)]

for _ in range(q):
  c = get_input()
  if c[0] == 0: # pushBack(t, x)
    l[c[1]].append(c[2])
  elif c[0] == 1: # dump(t)
    print(' '.join(map(str, l[c[1]])))
  elif c[0] == 2: # clear(t)
    l[c[1]] = []



Measured memory_bytes: 60544
//              +-- -- --++-- +-In the name of ALLAH-+ --++-- -- --+              \\

#include <bits/stdc++.h>

#define int ll

#define F first
#define S second
#define _sz(x) (int)x.size()

using namespace std ;
using ll = long long ;
using ld = long double ;
using pii = pair <int , int> ;

const int N = 5000 + 20 ;
int n , l[N] , r[N] , dp[2][N][2] , ord[N];

inline bool byLength (int i , int j) {
	return l[i] + r[i] > l[j] + r[j] ;
}

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

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

	if (!(n & 1)) n ++ ;

	int k = (n - 1) / 2 ;

	iota(ord , ord + n , 0) ;
	sort(ord , ord + n , byLength) ;

	memset(dp , 127 , sizeof dp) ;
	dp[0][0][0] = 0 ;

	for (int i = 0 ; i <= k ; i ++) {
		int nw = i & 1 , nxt = !nw ;

		memset(dp[nxt] , 127 , sizeof dp[nxt]) ;

		for (int j = 0 ; j <= k ; j ++) {
			for (int b = 0 ; b <= 1 ; b ++) {
				int ind = ord[i + j + b] , len = l[ind] + r[ind] ;

				if (i < k)
					dp[nxt][j][b] = min(dp[nxt][j][b] , dp[nw][j][b] + r[ind] + i * len) ;

				if (j < k)
					dp[nw][j + 1][b] = min(dp[nw][j + 1][b] , dp[nw][j][b] + l[ind] + j * len) ;

				if (b < 1)
					dp[nw][j][b + 1] = min(dp[nw][j][b + 1] , dp[nw][j][b] + k * len) ;
			}
		}
	}

	cout << dp[k & 1][k][1] << '\n' ;
}


Measured memory_bytes: 512
#include <algorithm>
#include <complex>
#include <cstdlib>
#include <ctime>
#include <time.h>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <numeric>
#include <limits>
#include <type_traits>
#include <locale>

using namespace std;
#define SAY_YES cout << "YES" << endl;
#define SAY_Yes cout << "Yes" << endl;
#define SAY_NO cout << "NO" << endl;
#define SAY_No cout << "No" << endl;
#define IFYES(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "YES" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "NO" << endl;  \
    }
#define IFYes(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "Yes" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "No" << endl;  \
    }
#define IFyes(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "yes" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "no" << endl;  \
    }
#define DEBUG_OUTPUT_ARRAY(XXX, ONE)                            \
    for (int i = 0; i < (ONE); i++)                             \
    {                                                           \
        cout << "DEBUG: i = " << i << " -> " << XXX[i] << endl; \
    }
#define DEBUG_OUTPUT_ARRAY2(XXX, ONE, TWO)                             \
    for (int i = 0; i < (ONE); i++)                                    \
    {                                                                  \
        cout << "<<< i = " << i << " >>>" << endl;                     \
        for (int j = 0; j < (TWO); j++)                                \
        {                                                              \
            cout << "DEBUG: j = " << j << " -> " << XXX[i][j] << endl; \
        }                                                              \
    }
#define DEBUG_OUTPUT_ARRAY2_BOX(XXX, ONE, TWO) \
    for (int i = 0; i < (ONE); i++)            \
    {                                          \
        cout << i << "  ";                     \
        for (int j = 0; j < (TWO); j++)        \
        {                                      \
            cout << XXX[i][j] << " ";          \
        }                                      \
        cout << endl;                          \
    }

typedef pair<long long int, long long int> pll;
typedef pair<long long int, pll> lpll;


const long long int mod = 998244353;
const long long int INF = 1e18;
const long double PI=3.14159265358979323; 
const long long int pl=1000000;

long long int A,B;


int main(){
    cout << fixed << setprecision(18);
    cin>>A>>B;
    cout<<A*B<<endl;

}




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

int main(){
	int N,zoro;
	scanf("%d",&N);
	int D[N][N];
	for (int i;i<N;i++){
		scanf("%d %d",&D[i][0],&D[i][1]);
		if (D[i][0]==D[i][1]){
			zoro++;
		} else zoro=0;
		if (zoro==3){
			printf("%s","Yes");
			exit(0);
		}
	}
	printf("%s","No");
	return 0;
}

Measured memory_bytes: 1764
def c_2d_plane_2n_points():
    N = int(input())
    R = [tuple([int(i) for i in input().split()]) for j in range(N)]
    B = [tuple([int(i) for i in input().split()]) for j in range(N)]

    red = sorted(R, key=lambda x: x[1], reverse=True)  # 赤い点の座標 (y 座標で降順ソート)
    blue = sorted(B)  # 青い点の座標 (x 座標で昇順ソート)
    ans = 0
    for x_b, y_b in blue:
        for x_r, y_r in red:
            # 注目している青い点より xy 平面で左下にある赤い点のうち、
            # 最も右上にある点とマッチさせるのが最適
            if x_b > x_r and y_b > y_r:
                ans += 1
                red.remove((x_r, y_r))  # もう選べないので削除
                break  # この青い点ももう選べないので終了
    return ans

print(c_2d_plane_2n_points())

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

int main(){
  string s;
  cin >>s;
  bool can = true;
  rep(i,s.size()){
    if(i%2!=0 && s[i]=='R') can = false;
    if(i%2==0 && s[i]=='L') can = false;
    if(!can) break;
  }
  if(can) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <climits>
#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <vector>
#include <sstream>
#include <typeinfo>
#include <fstream>

#define DIV 1000000007

using namespace std;

long long N, X;
long long A[100005];

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

	long long ans = 0;
	for(int i = 1; i < N; i++){
		long long sumi = A[i-1] + A[i];
		if(sumi > X){
			long long dec = sumi - X;
			ans += dec;
			A[i] -= dec;
			A[i] = max((long long)0, A[i]);
		}
	}
	cout << ans << endl;

}


Measured memory_bytes: 1024
n, q = [int(i) for i in input().split(" ")]

current = 0
queue = []
for _ in range(n):
    name, t = input().split(" ")
    t = int(t)
    if t <= q:
        current += t
        print("{} {}".format(name, current))
    else:
        current += q
        queue.append((name, int(t - q)))

while len(queue) > 0:
    nqueue = []
    for name, t in queue:
        if t <= q:
            t = int(t)
            current += t
            print("{} {}".format(name, current))
        else:
            current += q
            nqueue.append((name, int(t - q)))
    queue = nqueue

Measured memory_bytes: 10352
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class Program
{
    static void Main(string[] args)
    {
        //List<int> values = new List<int>(Console.ReadLine().Split(' ').Select(s => int.Parse(s)));
        //List<int> values = new List<int>();

        string input = Console.ReadLine();
        //int n = int.Parse(input.Split(' ')[0]);
        //int m = int.Parse(input.Split(' ')[1]);
        //int k = int.Parse(input.Split(' ')[2]);

        List<char> cc = new List<char>();
        cc.AddRange(input);

        while (cc.Count != 0)
        {
            char c = cc.First();
            cc.Remove(c);
            if(!cc.Remove(c))
            {
                Console.WriteLine("No"); return;
            }

        }
        Console.WriteLine("Yes"); return;



    }
}

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

#define all(x) (x).begin(), (x).end()
#define itn int
#define make_unique(x) sort((x).begin(), (x).end()); (x).erase(unique((x).begin(), (x).end()), (x).end())

using namespace std;

inline int nxt() {
	int x;
	cin >> x;
	return x;
}

const int N = 222222;
vector<int> a[N];
int cnt[N][2];

int main() {
	cin.sync_with_stdio(0);
	int n = nxt(), m = nxt();
	string s;
	cin >> s;
	for (int i = 0; i < m; ++i) {
		int u = nxt() - 1, v = nxt() - 1;
		a[u].push_back(v);
		a[v].push_back(u);
		cnt[u][s[v] - 'A'] += 1;
		cnt[v][s[u] - 'A'] += 1;
	}
	vector<char> used(n);
	vector<int> st;
	for (int i = 0; i < n; ++i) {
		if (!cnt[i][0] || !cnt[i][1]) {
			st.push_back(i);
			used[i] = 1;
		}
	}

	while (!st.empty()) {
		int v = st.back();
		st.pop_back();
		for (int x : a[v]) {
			if (!used[x]) {
				cnt[x][s[v] - 'A'] -= 1;
				if (!cnt[x][0] || !cnt[x][1]) {
					st.push_back(x);
					used[x] = 1;
				}
			}
		}
	}

	bool ok = false;
	for (int i = 0; i < n; ++i) {
		if (!used[i] && !a[i].empty()) {
			ok = true;
		}
	}
	puts(ok ? "Yes" : "No");

	return 0;
}


Measured memory_bytes: 13264
n = int(input())
min = 2000000
max = -2000000

nums = list(map(int,input().split()))
sum = 0

for i in range(n):
	sum += nums[i]
	
	if nums[i] < min:
		min = nums[i]
	if nums[i] > max:
		max = nums[i]

print(min,max,sum)

Measured memory_bytes: 8608
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int n;
    cin >> n;

    int a = n / 100;
    int b = (n - a * 100) / 10;
    int c = (n - a * 100) % 10;

    if (a == 1){
        a = 9;
    }
    else {
        a = 1;
    }

    if (b == 1){
        b = 9;
    }
    else {
        b = 1;
    }

    if (c == 1){
        c = 9;
    }
    else {
        c = 1;
    }
    cout << 100 * a + 10 * b + c << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main() {

	int x[5],f,i;

	for (i = 0; i <= 4; i++) {
		scanf("%d", &x[i]);
	}
	for (i = 0; i <= 4; i++) {
		if (x[i] == 0) {
			f = i + 1;
			break;
		}
	}
	printf("%d", f);

	return 0;

}

Measured memory_bytes: 1724
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define VIEW(x) do {cerr << #x << ": "; for(auto i : x) cerr << i << " "; cerr << endl;} while(0)
#define ALL(x) (x).begin(),(x).end()
template<class T>bool umax(T &a, const T &b) {if(a<b){a=b;return 1;}return 0;}
template<class T>bool umin(T &a, const T &b) {if(b<a){a=b;return 1;}return 0;}

template<typename A,size_t N,typename T> void FILL(A (&array)[N],const T &val){fill((T*)array,(T*)(array+N),val);}
template<typename T> void FILL(vector<T> &v, const T &x) {fill(v.begin(), v.end(), x);}
template<typename T> void FILL(vector<vector<T>> &v, const T &x) {for(auto &i:v)fill(i.begin(), i.end(), x);}

int main() {
  int n,k; cin >> n >> k;
  vector<int> x(n);
  rep(i,n) cin >> x[i];

  int ans = 400000000;
  rep(i, n-k+1) {
    // i : i+k-1
    int l = x[i], r=x[i+k-1];
    umin(ans, (r-l) + min(abs(l), abs(r)));
  }
  cout << ans << endl;
}


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

ll ways(ll n)
{
  return (n*(n-1))/2;
}

int main()
{

    int n;cin>>n;
    map<ll,ll> mp;
    ll arr[n+1],ans=0;
    set<int> s;
    for(int i=1;i<=n;i++) 
      {
        cin>>arr[i];
        s.insert(arr[i]);
        mp[arr[i]]++;
      }
      for(auto a:s)
      {
        ans+=ways(mp[a]);
      }
    for(int i=1;i<=n;i++)
    {
      cout<<ans-ways(mp[arr[i]])+ways(mp[arr[i]]-1)<<endl;
    }
    return 0;
}


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

void solve(long long N, long long a[]){
	bool flg = false;
	for (int i = 0 ; i <= N-1 ; i++) {
		if (a[i]%2 == 1) flg = true;
	}
	if (flg) {
		printf("first\n");
	}	else {
		printf("second\n");
	}
}

int main(){
	long long N;
	scanf("%lld",&N);
	long long a[N];
	for(int i = 0 ; i <= N-1 ; i++){
		scanf("%lld",&a[i]);
	}
	solve(N, a);
	return 0;
}


Measured memory_bytes: 1024
using System;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Collections.Generic;
using System.Diagnostics;
using System.Numerics;
using Enu = System.Linq.Enumerable;

public class Program
{
    const int Mod = (int)1e9 + 7;
    static void Add(ref long a, long b) { if ((a += b) >= Mod) a -= Mod; }

    public void Solve()
    {
        int N = Reader.Int(), C = Reader.Int();
        var A = Reader.IntArray(N);
        var B = Reader.IntArray(N);

        int Bmax = B.Max();
        var powSum = new long[Bmax + 1, C + 1];
        for (int x = 1; x <= Bmax; x++)
            for (long n = 0, p = 1; n <= C; n++, p = p * x % Mod)
                powSum[x, n] = (powSum[x - 1, n] + p) % Mod;

        var dp = new long[C + 1];
        dp[0] = 1;
        for (int i = 0; i < N; i++)
        {
            var nextdp = new long[C + 1];
            for (int sum = 0; sum <= C; sum++)
                for (int add = 0; sum + add <= C; add++)
                {
                    long v = (Mod + powSum[B[i], add] - powSum[A[i] - 1, add]) % Mod;
                    Add(ref nextdp[sum + add], dp[sum] * v % Mod);
                }
            dp = nextdp;
        }

        Console.WriteLine(dp[C] % Mod);
    }

}


class Entry { static void Main() { new Program().Solve(); } }
class Reader
{
    static TextReader reader = Console.In;
    static readonly char[] separator = { ' ' };
    static readonly StringSplitOptions op = StringSplitOptions.RemoveEmptyEntries;
    static string[] A = new string[0];
    static int i;
    static void Init() { A = new string[0]; }
    public static void Set(TextReader r) { reader = r; Init(); }
    public static void Set(string file) { reader = new StreamReader(file); Init(); }
    public static bool HasNext() { return CheckNext(); }
    public static string String() { return Next(); }
    public static int Int() { return int.Parse(Next()); }
    public static long Long() { return long.Parse(Next()); }
    public static double Double() { return double.Parse(Next()); }
    public static int[] IntLine() { return Array.ConvertAll(Split(Line()), int.Parse); }
    public static int[] IntArray(int N) { return Range(N, Int); }
    public static int[][] IntTable(int H) { return Range(H, IntLine); }
    public static string[] StringArray(int N) { return Range(N, Next); }
    public static string[][] StringTable(int N) { return Range(N, () => Split(Line())); }
    public static string Line() { return reader.ReadLine().Trim(); }
    public static T[] Range<T>(int N, Func<T> f) { var r = new T[N]; for (int i = 0; i < N; r[i++] = f()) ; return r; }
    static string[] Split(string s) { return s.Split(separator, op); }
    static string Next() { CheckNext(); return A[i++]; }
    static bool CheckNext()
    {
        if (i < A.Length) return true;
        string line = reader.ReadLine();
        if (line == null) return false;
        if (line == "") return CheckNext();
        A = Split(line);
        i = 0;
        return true;
    }
}

Measured memory_bytes: 5336
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
#define Nmax 200010
#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define RFOR(i,a,b) for(long long i = (b-1);i>=a;i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define RITR(itr,mp) for(auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<P> Graph;

int main() {
	ll N;
	cin >> N;
	int s[100]={},o=0;
	REP(i,50){
      	if(N==0)break;
		if(abs(N)%(ll)pow(2,i+1)!=0){
			s[i] = 1;
			N-=(ll)pow(-2,i);
          	o=i;
		}else s[i] = 0;
	}
	RREP(i,o+1) cout << s[i];
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
//agrawal117
//chahatagrawal117
#include<bits/stdc++.h>
#define endl '\n'
#define mod 1000000007
typedef long long int ll;
using namespace std;
#define MAX 100005
ll dp[MAX][11];
ll k;
vector<ll> v;
void solve(int i, int j,ll sum)
{
    if(i==0) {
    
            if(j-1>=0){
                sum++;
                if(sum==k){
                    v.push_back(j-1);
                    for(int x=0;x<v.size();x++) cout<<v[x];
                    exit(0);
                }
            }
            sum++;
            if(sum==k){
                v.push_back(j);
                for(int x=0;x<v.size();x++) cout<<v[x];
                exit(0);
            }
            sum++;
            v.push_back(j+1);
            for(int x=0;x<v.size();x++) cout<<v[x];
                exit(0);
            
        
    }
    if(j-1>=0)
    {
        ll ff=dp[i][j-1];
        if(sum+ff<k) sum+=ff;
        else{
            v.push_back(j-1);
            solve(i-1,j-1,sum);
        }
    }
    ll ff=dp[i][j];
        if(sum+ff<k) sum+=ff;
        else{
            v.push_back(j);
            solve(i-1,j,sum);
        }
        if(j+1<10)
        {
          ll ff=dp[i][j+1];
            if(sum+ff<k) sum+=ff;
            else{
                v.push_back(j+1);
                solve(i-1,j+1,sum);
            }  
        }
        
    
}

int main()
{
    cin>>k;
   if(k<=12) { cout<<k<<endl; return 0; }
   for(int i=0;i<10;i++) dp[0][i]=1;
   ll sum=9;
   for(int i=1;i<MAX;i++){
       for(int j=0;j<10;j++){
           ll val=dp[i-1][j];
           if(j-1>=0) {
               val+=dp[i-1][j-1];
           }
           if(j+1<10){
               val+=dp[i-1][j+1];
           }
           dp[i][j]=val;
           ll ff=sum;
           if(j!=0) sum+=dp[i][j];
           if(sum>=k) {
            //   cout<<i<<" "<<j<<endl;
            //   cout<<sum<<endl;
            //   cout<<ff<<endl;
               v.push_back(j);
               sum=ff;
                solve(i-1,j,sum);
           }
           
       }
   }
   
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(n); ++i)
#define repr(i, a, b) for (int i=a; i<(b); ++i)
#define reprev(i, n) for (int i=n-1; i>=0; --i)
#define reprrev(i, a, b) for (int i=b-1; i>=(a); --i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int dp[102][5][2];
// 前からI桁目までで、0じゃない数字がJ個ある
// N未満が確定して入れば1、Nと同じになりそうなら0

int main() {
    cout << fixed << setprecision(10);
    
    string S; cin >> S;
    int n = S.size();
    int K; cin >> K;
    dp[0][0][0] = 1;
    rep(i, n) rep(j, K+1) rep(k, 2) {
        rep(d, 10) {
            int nx = S[i] - '0';
            int ni = i+1, nj = j, nk = k;
            if (d != 0) {
                nj++;
            }
            if (k == 0) {
                if (d > nx) {
                    continue;
                }
                if (d < nx) {
                    nk = 1;
                }
            }
            dp[ni][nj][nk] += dp[i][j][k];
        }
    }
    int ans = dp[n][K][0] + dp[n][K][1];

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {
    return os << "(" << P.first << "," << P.second << ")"; }
template<class T> ostream& operator<<(ostream &os, vector<T> V) {
    os << "[ "; for(auto v : V) os << v << " "; return os << "]"; }
template<class T> ostream& operator<<(ostream &os, set<T> S){
    os << "{ "; for(auto s:S) os<<s<<" "; return os<<"}"; }
template<class T> ostream& operator<<(ostream &os, multiset<T> S){
    os << "{ "; for(auto s:S) os<<s<<" "; return os<<"}"; }
template<class L, class R> ostream& operator<<(ostream &os, map<L,R> M) {
    os << "{ "; for(auto m:M) os<<"("<<m.F<<":"<<m.S<<") "; return os<<"}"; }
    #define db(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << '\n'; }
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    cout.write(names, comma - names) << " : " << arg1 << " |"; __f(comma + 1, args...); }
#define rng(x) x.begin(), x.end()
#define pb push_back
#define F first
#define S second
#define el '\n'
 
typedef long long ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef vector<bool> vb;
 
/*-----------------------------Code begins----------------------------------*/

void solve(){
    string str; cin>>str;
    int sm = 0;
    for(char c : str) sm += (c - '0');

    if(sm%9 == 0){
        cout<<"Yes\n";
    }
    else{
        cout<<"No\n";
    }
}
 
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int T=1, tc = 1;
    // cin>>T; 
    while(T--){
        solve();
    }
    return 0; 
}

Measured memory_bytes: 3712
a = $<.map &:chomp

N = a[0].to_i

A = a[1..-1].map{|x| x.split(" ").map{|x| x.to_i}}

X = A[1..N]

Y = A[N..-1]

max = -Float::INFINITY
(0..1).to_a.repeated_permutation(10){|a|
	if a != [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
		k = []
		N.times{|n|
			k[n] = a.zip(A[n]).map{|s, t| s*t}.inject(:+)
		}
		
		l = 0
		N.times{|n|
			l += Y[n][k[n]]
		}
		
		if l > max
			max = l
		end
	end
}

print max

Measured memory_bytes: 1916
#include<stdio.h>
int main(void)
{
	int n = 1, x = 1, i, j, k, count = 0;
	while (n != 0 || x != 0)
	{
		scanf("%d %d", &n, &x);
		for (i = 1; i < n; i++)
		{
			for (j = i + 1; j < n; j++)
			{
				for (k = j + 1; k <= n; k++)
				{
					if (i + j + k == x)
					{
						count = count + 1;
					}
				}
			}
		}
		if ((n != 0) || (x != 0))
		{
			printf("%d\n", count);
		}
		count = 0;
	}
	return 0;
}


Measured memory_bytes: 2112
#include <bits/stdc++.h>
#define ri register int

using namespace std;

typedef long long ll;
using namespace std;
const int maxn = 1e5 + 10;

ll n, x;
struct node {
    ll b, l, r, val;
    void read() {
        scanf("%lld %lld %lld", &b, &l, &r);
        val = (x - b) * r + b * l;
    }
    bool operator < (const node &p) const {
        return val > p.val;
    }
} aoki[maxn];

ll calc(ll mid) {
    ll res = 0;
    int cnt1 = mid / x;
    int cnt2 = mid % x;
    for (int i = 1; i <= cnt1; ++i)
        res += aoki[i].val;
    if (cnt2 == 0) return res;
    ll sum = 0;
    for (ri i = 1; i <= n; ++i) {
        ll tmp = 0;
        if (cnt2 >= aoki[i].b) tmp = (cnt2 - aoki[i].b) * aoki[i].r + aoki[i].l * aoki[i].b;
        else tmp = cnt2 * aoki[i].l;
        if (i <= cnt1) sum = max(sum, res - aoki[i].val + tmp + aoki[cnt1 + 1].val);
        else sum = max(sum, res + tmp);
    }
    return sum;
}

int main() {
    scanf("%lld %lld", &n, &x);
    ll sum = 0;
    for (ri i = 1; i <= n; ++i) {
        aoki[i].read();
        sum += aoki[i].b * aoki[i].l;
    }
    sort(aoki + 1, aoki + 1 + n);

    ll l = 0, r = x * n;
    while (l < r) {
        ll mid = l + r >> 1;
        if (calc(mid) >= sum) r = mid;
        else l = mid + 1;
    }

    printf("%lld", l);
    return 0;
}


Measured memory_bytes: 3328
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#define LL long long
#define M 200020
using namespace std;
LL read(){
	LL nm=0,fh=1; char cw=getchar();
	for(;!isdigit(cw);cw=getchar()) if(cw=='-') fh=-fh;
	for(;isdigit(cw);cw=getchar()) nm=nm*10+(cw-'0');
	return nm*fh;
}
LL ans,sum0,sum1,sig;
LL n,m,fs[M],nt[M<<1],to[M<<1],col[M],f[M],sz[M],tmp;
LL fd(LL x){return x==f[x]?x:f[x]=fd(f[x]);}
void link(LL x,LL y){nt[tmp]=fs[x],fs[x]=tmp,to[tmp++]=y;}
void merge(LL x,LL y){x=fd(x),y=fd(y);if(x!=y) f[x]=y,sz[y]+=sz[x];}
bool check(LL x,LL now){
	if(col[x]) return col[x]==now; col[x]=now;
	for(LL i=fs[x];i!=-1;i=nt[i])
		if(!check(to[i],3-now)) return false;
	return true;
}
int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	n=read(),m=read(),memset(fs,-1,sizeof(fs));
	for(LL i=1;i<=n;i++) f[i]=i,sz[i]=1;
	for(LL i=1;i<=m;i++){
		LL x=read(),y=read();
		link(x,y),link(y,x),merge(x,y);
	}
	for(LL i=1;i<=n;i++) if(fd(i)==i&&sz[i]==1) sig++;
	for(LL i=1;i<=n;i++){
		if(fd(i)!=i||sz[i]==1) continue;
		if(check(i,1)) ans+=2,sum0++;
		else ans++,sum1++;
	}
	ans+=sig*((n<<1)-1)-sig*(sig-1);
	ans+=((sum0*(sum0-1))<<1);
	ans+=sum1*(sum0<<1)+sum1*sum1-sum1;
	printf("%lld\n",ans);
	return 0;
}

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

#define ull unsigned long long
#define ll long long
#define mod 1000000007
#define fi first
#define se second
#define pb push_back
#define mkp make_pair
#define PI acos(-1.0)
const int N=1e5 + 5;
const int M=1e5 + 5;


int main()
{
	ios_base::sync_with_stdio(false);
	int i,j,a,b;
	cin>>a>>b;
	char c1,c2,s[100][100];
	if(a<=b){
		c1='.';
		c2='#';
	}
	else{
		int t=a;
		a=b;
		b=t;
		c1='#';
		c2='.';	
	}
	for(i=0;i<100;i++){
		for(j=0;j<100;j++){
			s[i][j]=c1;
		}
	}
	a--;
	for(i=0;i<=97;i+=4){
		for(j=0;j<=97;j+=4){
			if(a==0) continue;
			s[i][j]=c2;
			s[i][j+1]=c2;
			s[i][j+2]=c2;
			s[i+1][j]=c2;
			s[i+1][j+2]=c2;
			s[i+2][j]=c2;
			s[i+2][j+1]=c2;
			s[i+2][j+2]=c2;
			a--;
			b--;
		}
	}
	for(i=99;i>=0;i-=2){
		for(j=0;j<100;j+=2){
			if(b==0) continue;
			s[i][j]=c2;
			b--;
		}
	}
	cout<<100<<" "<<100<<endl;
	for(i=0;i<100;i++){
		for(j=0;j<100;j++){
			cout<<s[i][j];
		}
		cout<<endl;
	}


		
	
		
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#define IO(i, o) freopen(i, "r", stdin), freopen(o, "w", stdout)

using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());

int a, b;

int main(){
	//IO("input.txt", "output.txt");
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> a >> b;
	cout << max(0, a - b * 2) << "\n";
	return 0;
}

Measured memory_bytes: 256