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

int a[11];
bool ok = false;

void solve(int i, vector<int> x, vector<int> y) {
    if(i >= 10) {
        bool tmp = true;

        rep(j, x.size()-1) {
            if (x[j] > x[j+1]) tmp = false;
        }
        rep(j, y.size()-1) {
            if (y[j] > y[j+1]) tmp = false;
        }

        ok |= tmp;
        return;
    }

    x.push_back(a[i]);
    solve(i+1, x, y);
    x.pop_back();
    y.push_back(a[i]);
    solve(i+1, x, y);
    y.pop_back();

    return;
}

int main() {
    int n;
    cin >> n;
    rep(i, n) {
        rep(j, 10) cin >> a[j];
        ok = false;
        vector<int> x, y;
        solve(0, x, y);
        cout << (ok ? "YES" : "NO") << endl;
    }
    return 0;
}



Measured memory_bytes: 3072
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FOR(i,a,b) for(int i=(a); i<=(b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define chmin(a,b) if((a)>(b)) (a)=(b);
#define chmax(a,b) if((a)<(b)) (a)=(b);
#define vi vector<int>
#define pii pair<int,int>
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define pb push_back
#define pf push_front
int gcd(int a,int b){/*a>=0,b>=0,￢(a=b=0)*/
  while(min(a,b)>0){if(a<b)swap(a,b);a%=b;}return max(a,b);
}
int dx[]={0,1,0,-1,1,-1,-1,1};
int dy[]={1,0,-1,0,1,1,-1,-1};
const int MOD = 1e9+7;
const int INF = 1e18+10;

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

signed main(){
  int a,b,n;
  cin>>a>>b>>n;
  int x=b-1;
  int ans=-1;

  if(b-1>=n) ans=(a*n)/b;
  else {
    x=n-n%b-1;
    if(n%b==b-1) x=n;
    ans=(a*x)/b-a*(x/b);
  }
  cout<<ans<<endl;
  return 0;

}

// signed main(){
//   int n,m,q;
//   cin>>n>>m>>q;
//   vi a(q),b(q),c(q),d(q);
//   rep(i,q) cin>>a[i]>>b[i]>>c[i]>>d[i];

//   int ans=0;

//   rep(bit,(1<<10)){
//     int tmp=bit;
//     vi a;
//     rep(i,n)


//   }


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

Measured memory_bytes: 3584
import numpy as np

def main():
    s = input()
    n = int(s.split()[0])
    k = int(s.split()[1])
    q = int(s.split()[2])

    score = np.ones(n + 1) * (k)
    score = score - q

    for _ in range(q):
        answer = input()
        score[int(answer)] = score[int(answer)] + 1

    for i in range(1, len(score)):
        if score[i] > 0:
            print('Yes')
        else:
            print('No')


if __name__ == '__main__':
    main()

Measured memory_bytes: 14008
n = int(input())


def main():
    for x in range(1, n + 1):
        if (x * 108 // 100) == n:
            return x
    else:
        return -1


if __name__ == "__main__":
    v = main()
    if v == -1:
        print(':(')
    else:
        print(v)
        

Measured memory_bytes: 2940
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
typedef long double ld;
const int MAXN = 3100;
const ld PI = acos (-1.0);

int N;
ld L;
ld v[MAXN];

int main()
{
    ios_base::sync_with_stdio(0);

    cin >> N >> L;
    for (int i = 0; i < N; i++)
    {
        cin >> v[i];
        v[i] *= 2 * PI / L;
    }

    ld xans = 0, yans = 0;
    for (int i = 0; i < N; i++)
    {
        for (int j = i + 1; j < N; j++)
        {
            ld x = (v[i] + v[j]) / 2.;
            ld y = (v[i] + v[j]) / 2. + PI;
            if (y > 2 * PI) y -= 2 * PI;

            int nc = (j - i - 1);
            int nd = (N - 2 - nc);

            xans += nc * cos (y);
            yans += nc * sin (y);

            xans += nd * cos (x);
            yans += nd * sin (x);
        }
    }

    ll ov = N * (ll) (N - 1) * ((ll) N - 2);
    ov /= 6;
    xans /= ov;
    yans /= ov;

    cout << fixed << setprecision(10);
    cout << xans << " " << yans << "\n";
}

Measured memory_bytes: 512
#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;

// 最小公倍数を求める
int euqlid (int a, int b){
  int temp;
  temp = a % b;
  if(temp == 0)return b;
  return euqlid(b,temp);
}
ll conbination(ll a,ll b){
  ll u = 1;
  ll d = 1;
  while(b != 0){
    u *= a;
    d *= b;
    a--;
    b--;
  }
  return u / d;
}
int strtoint(char s){
  return (int(s-'0'));
}
int fact(int n){
  if(n == 1)return 1;
  return n * fact(n-1);
  }



int main(){
  int n,m;
  cin >> n >> m;
  int p[m];
  string s[m];
  rep(i,m){
    cin >> p[i] >> s[i];
    p[i]--;
  }
  bool AC[n];
  rep(i,n)AC[i] = false;
  int WA[n];
  rep(i,n)WA[i] = 0;
  int pen = 0;
  int cor = 0;
  rep(i,m){
    if(AC[p[i]] == true)continue;
    if(s[i] == "AC"){
      AC[p[i]] = true;
      cor++;
      pen += WA[p[i]];
    }
    else if(s[i] == "WA")WA[p[i]]++;
  }
  cout << cor << " " << pen << endl;
  return 0;
}

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

int main(int argc, char const *argv[])
{
	int x,a;
	cin>>x>>a;
	if (x<a)
	{
		cout<<"0\n";
	}
	else
	{
		cout<<"10\n";
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define vi               vector<int>
#define pb(x)            push_back(x)
#define all(x)           x.begin(), x.end()
#define sortall(x)       sort(all(x))
#define sortrev(x)       sort(all(x), greater<int>())
#define debug(x)         cout << '>' << #x << ':' << x << endl;
#define int              long long
#define ld               long double
#define endl 			 "\n";
#define mp 				 make_pair
#define pii 			 <int, int>
#define lb 				 lower_bound
#define ub				 upper_bound
const int mod = 1000000007;
using namespace std;
// const int N = 1e5 + 5; 
// int n;
// int a[N];

int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int t;
t = 1;
// cin >>t;
while(t--){
int n;cin >>n;
cout << n + pow(n,2) + pow(n,3) <<endl;









}
return 0;
}

Measured memory_bytes: 4328
#include<bits/stdc++.h>
using namespace std;
int a[200005];
bool cmp(int a,int b){
	return a>b;
}
int main(){
	int n,x,k;
	cin>>n>>k;
	map<int,int> mymap;
	for(int i=1;i<=n;i++){
		cin>>x;
		a[x]++;
	}
	sort(a,a+200001,cmp);
	int ans=0,cnt=0;
	for(int i=0;i<=200000;i++){
		if(cnt>=k)break;
		ans+=a[i];
		cnt++;
	}
	cout<<n-ans<<endl;
	return 0;
}

Measured memory_bytes: 1024
from collections import defaultdict
from heapq import heappush, heappop

N,M = map(int,input().split())
d = defaultdict(list)

for _ in range(N):
  a,b = map(int,input().split())
  d[a].append(b)
  
h = []
res = 0

for a in range(1,M + 1):
  for b in d[a]:
    heappush(h,-b)
  if len(h) > 0:
    c = heappop(h)
    res -=c
    
print(res)

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

int main(){
    
    long int X,Y;
    cin>>X>>Y;
    if(X*Y>0){
        if(X<=Y) cout<<Y-X<<endl;
        else cout<<2+X-Y<<endl;
    }
    else if(X*Y<0) cout<<abs(abs(X)-abs(Y))+1<<endl;
    else if(X==0){
        if(Y>=0) cout<<Y<<endl;
        else cout<<abs(Y)+1<<endl;
    }
    else{
        if(X>0) cout<<abs(X)+1<<endl;
        else cout<<abs(X)<<endl;
    }
}


Measured memory_bytes: 256
/* Dsingh_24 */

#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define	endl		'\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)	for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define ios	    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;

#define N  100005

int main()
{
	ios
	ll n,i,j;
	cin>>n;
	ll ans=0,a[n+1];
	for(i=0;i<n;i++){
		cin>>a[i];
		ans^=a[i];
	}
	for(i=0;i<n;i++)
		cout<<(a[i]^ans)<<" ";

	return 0;
}

Measured memory_bytes: 5208
"""Counting Sort."""

def countingSort(A, n):
    """Sort the elements of list A with Counting Sort algorithm.

    n is the length of A.
    The elements of A are intergers between 0 and 10000, inclusive.
    B is the output list where the sorted elements will be arranged.
    
    Print the elements of B in a line separated by a space character.
    """

    C = [0 for i in range(10001)]

    for i in A:
        C[i] += 1

    for i in range(1, 10001):
        C[i] += C[i - 1]

    B = [0 for i in range(n + 1)]
    
    for i in A[::-1]:
        B[C[i]] = i
        C[i] -= 1

    print(*B[1:])


import sys

n = int(sys.stdin.readline())

A = list(map(int, sys.stdin.readline().split()))

countingSort(A, n)

Measured memory_bytes: 232756
#include<bits/stdc++.h>
using namespace std;
vector<int> dp(100001,-2);
int path(vector<vector<int> > &v,int n)
{
  if(n==0)
  {
    return -1;
  }
  if(dp[n]!=-2)
    return dp[n];
  vector<int> t;
  for(int i=0;i<v[n].size();i++)
  {
    if(dp[v[n][i]]==-2)
      dp[v[n][i]]=path(v,v[n][i]);
    t.push_back(dp[v[n][i]]);
  }
  int max=t[0];
  for(int i=1;i<t.size();i++)
    if(max<t[i])
      max=t[i];
  dp[n]=1+max;
  return dp[n];
}
int main()
{
  int n,m;cin>>n>>m;
  vector<vector<int> > v(n+1);
  for(int i=0;i<m;i++)
  {
    int x,y;cin>>x>>y;
    vector<int> t=v[x];
    t.push_back(y);
    v[x]=t;
  }
  vector<int> t;
  t.push_back(0);
  v[0]=t;
  for(int i=1;i<=n;i++)
    (v[i]).push_back(0);
  for(int i=1;i<=n;i++)
  	path(v,i);
  int max=dp[1];
  for(int i=2;i<=n;i++)
    if(dp[i]>max)
      max=dp[i];
  cout<<max<<endl;
  return 0;
}

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

#define pb emplace_back
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define REP(i,n) for(int _n=n, i=0;i<_n;++i)
#define FOR(i,a,b) for(int i=(a),_b=(b);i<=_b;++i)
#define FORD(i,a,b) for(int i=(a),_b=(b);i>=_b;--i)
#define trav(a, x) for (auto& a : x)
using ull = uint64_t;
using ll = int64_t;
using PII = pair<int, int>;
using VI = vector<int>;
#define INF (1ll<<60)

string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string) s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B> string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; }
template <typename A> string to_string(A v) {
bool first = true; string res = "{";
for (const auto &x : v) { if (!first) { res += ", "; } first = false; res += to_string(x); }
res += "}"; return res; }
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H); debug_out(T...); }
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

int main() {
    ios::sync_with_stdio(false), cin.tie(0);
    int N, M;
    cin >> N >> M;
    vector<vector<PII>> G(N+2, vector<PII>());
    REP(i, M) {
        int x, y, w;
        cin >> x >> y >> w;
        G[x].pb(y, w);
        G[y].pb(x, w);
    }
    set<PII> used;
    FOR(s, 1, N) {
        VI prev(N+2, 0), dist(N+2, INT_MAX);
        priority_queue<PII, vector<PII>, greater<PII>> PQ;
        PQ.push({s, 0});
        dist[s] = 0;
        while (!PQ.empty()) {
            auto p = PQ.top();
            PQ.pop();
            int v = p.first;
            if (p.second > dist[v]) continue;
            for (auto u : G[v]) {
                if (dist[v] + u.second < dist[u.first]) {
                    dist[u.first] = dist[v] + u.second;
                    PQ.push({u.first, dist[v] + u.second});
                    prev[u.first] = v;
                }
            }
        }
        // debug(prev);
        FOR(i, 1, N) {
            if (prev[i] == 0) continue;
            used.insert({min(i, prev[i]), max(i, prev[i])});
        }
    }
    cout << M - used.size() << endl;
}

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

int main()
{
  int n;
  cin>>n;
  int w;
  cin>>w;
  int wt[n];
  long long int v[n];
  for(int i=0;i<n;i++)
  {
    cin>>wt[i]>>v[i];
  }
  long long int dp[n][w+1];
  for(int i=0;i<n;i++)
  {
    for(int j=0;j<=w;j++)
    {
      dp[i][j]=0;
    }
  }
  for(int j=0;j<=w;j++)
  {
    if(j>=wt[0])
    dp[0][j]=v[0];
    else
      dp[0][j]=0;
  }
  for(int i=1;i<n;i++)
  {
    for(int j=0;j<=w;j++)
    {
      if(wt[i]<=j)
      {
        dp[i][j]=max(dp[i-1][j-wt[i]]+v[i],dp[i-1][j]);
      }
      else
      {
        dp[i][j]=dp[i-1][j];
      }
    }
  }
  long long int ans=INT_MIN;
  for(int i=0;i<n;i++)
  {
    for(int j=0;j<=w;j++)
    {
      //cout<<dp[i][j]<<" ";
      ans=max(ans,dp[i][j]);
    }
    //cout<<"\n";
  }
  cout<<ans<<"\n";
  return 0; 
}

Measured memory_bytes: 78336
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define f(z) for(int i=1;i<=z;i++)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define vi vector<int>
#define pb push_back
#define si set<int>
#define mod  1000000007
#define cl(n,m) (n-1)/m  + 1 ;
#define T() int TT; cin>>TT; while(TT--)
#define P pair<int,int>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
const int  N = 1e5 + 5;

signed main(){
	char x ,y ;
	cin >> x>>y ;
	if( x> y) cout <<">" ;
	else if ( x==y ) cout <<"="  ;
	else cout<< "<" ;
}

Measured memory_bytes: 256
N , K = map(int , input().split())
R , S , P = map(int , input().split())
T = input()

dic = {"r":"p" , "s":"r" , "p":"s"}
ANS = []

for i in range(N):
    ANS.append(dic[T[i]])
    
ans = "".join(ANS)

for i in range(K , N):
    if ans[i] == ans[i-K]:
        ans = ans[:i] + "X" + ans[i+1:]
        
point = ans.count("r")*R + ans.count("s")*S + ans.count("p")*P

print(point)

Measured memory_bytes: 4336
n, p = (int(i) for i in input().split());

s = input();

if p == 2 or p == 5:
    res = 0;
    for i in range(len(s)):
        if int(s[i]) % p == 0:
            res += i + 1;
    print(res);
    exit(0);

h = [0 for i in range(len(s) + 1)];
st = 1;

for i in range(len(s) - 1,-1,-1):
    #print(i);
    h[i] = (st * int(s[i]) + h[i + 1]) % p;
    st = (st * 10) % p;

#print(h);

h.sort();

#print(h);

i = 0;
res = 0;

while i <= n:
    j = i;
    while j + 1 <= n and h[i] == h[j + 1]:
        j += 1;
    l = j - i + 1;
    res += (l * (l - 1)) // 2;
    i = j + 1;

print(res);


Measured memory_bytes: 12092
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int a,b; cin>>a>>b;
    
    long long c; cin>>c;
    int i,j;
    bool can=false;
    for(i=1; i<=b;i++){
        for(j=0;j<=a;j++){
            if(a*i==b*j+c) can=true;
        }
    }
    (can) ? cout<<"YES": cout<<"NO";
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define hackcyborg shresth_walia
#define ll  long long
#define ld  long double
#define pb push_back
#define mod 1000000007
#define M_PI 3.141592653589
#define IO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define int long long
ll binpow(ll a,ll b,ll m=mod) {
    a %= m;
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}
main()
{
     IO
     ll a;
     cin>>a;
     cout<<(a+(a*a)+(a*a*a));
}


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

namespace program
{
    class Program
    {
        static void Main()
        {
          int[] a = Input.ScanIntArray();
          int res=0;
          for(int i=0;i<=a[0];i++)
            for(int k=0;k<=a[0];k++)
              if(a[1]-i-k>=0 && a[1]-i-k<=a[0]) res++;
          Console.WriteLine(res);
        }
    }

    static class Input
    {
        static public int ScanInt() { return int.Parse(Console.ReadLine()); }
        static public uint ScanUint() { return uint.Parse(Console.ReadLine()); }
        static public long ScanLong() { return long.Parse(Console.ReadLine()); }
        static public ulong ScanUlong() { return ulong.Parse(Console.ReadLine()); }
        static public int[] ScanIntArray() { return Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); }
        static public uint[] ScanUintArray() { return Console.ReadLine().Split(' ').Select(x => uint.Parse(x)).ToArray(); }
        static public long[] ScanLongArray() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray(); }
        static public ulong[] ScanUlongArray() { return Console.ReadLine().Split(' ').Select(x => ulong.Parse(x)).ToArray(); }

        static public string ScanStr() { return Console.ReadLine(); }
        static public string[] ScanStrArray() { return ScanStr().Split(' '); }
    }

    static class MyMath
    {
        public static int GCD(int a, int b)
        {
            Func<int, int, int> gcd = null;
            gcd = (x, y) => y == 0 ? x : gcd(y, x % y);
            return a > b ? gcd(a, b) : gcd(b, a);
        }
        public static ulong GCD(ulong a, ulong b)
        {
            Func<ulong, ulong, ulong> gcd = null;
            gcd = (x, y) => y == 0 ? x : gcd(y, x % y);
            return a > b ? gcd(a, b) : gcd(b, a);
        }
        public static int LCM(int a, int b)
        {
            return a * b / GCD(a, b);
        }
        public static ulong LCM(ulong a, ulong b)
        {
            return a * b / GCD(a, b);
        }
    }
}


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

typedef long long ll;

const long long MOD = 1000000007;
long long modpow(long long a, long long n, long long m)
{
    long long ans = 1;
    while (n)
    {
        if (n & 1)
        {
            ans = (ans * a) % m;
        }
        a = (a * a) % m;
        n >>= 1;
    }
    return ans;
}
long long combi(long long n, long long a)
{
    long long ans = 1, ans1 = 1;
    for (long long i = n - a + 1; i <= n; i++)
    {
        ans *= i % MOD;
        ans %= MOD;
    }

    for (long long i = 2; i <= a; i++)
        ans1 = (ans1 * i) % MOD;
    ans1 = modpow(ans1, MOD - 2, MOD);
    return ((ans % MOD) * ans1) % MOD;
}

void dfs(string s, char mx, ll N)
{
    if (s.length() == N)
    {
        cout << s.c_str() << endl;
    }
    else
    {
        for (char c = 'a'; c <= mx; c++)
        {
            dfs(s + c, ((c == mx) ? (char)(mx + 1) : mx), N);
        }
    }
}

int bfs(int a, int b, int h, int w, char tmp[][101])
{
    int ans[101][101] = {0};
    char c[101][101] = {0};
    queue<pair<int, int>> s;

    for (int i = 0; i <= h; i++)
    {
        for (int j = 0; j <= w; j++)
        {
            c[i][j] = tmp[i][j];
        }
    }

    s.push(make_pair(a, b));

    while (s.size() > 0)
    {

        pair<int, int> tmp = s.front();
        s.pop();
        c[tmp.first][tmp.second] = '#';
        for (int i = -1; i <= 1; i++)
        {
            for (int j = -1; j <= 1; j++)
            {
                if (tmp.first + i < 1 || tmp.first + i > h)
                {
                    continue;
                }
                if (tmp.second + j < 1 || tmp.second + j > w)
                {
                    continue;
                }
                if (i != 0 && j != 0)
                {
                    continue;
                }
                if (i == 0 && j == 0)
                {
                    continue;
                }
                if (c[tmp.first + i][tmp.second + j] == '#')
                {
                    continue;
                }
                c[tmp.first + i][tmp.second + j] = '#';
                if (ans[tmp.first + i][tmp.second + j] == 0)
                {
                    ans[tmp.first + i][tmp.second + j] = ans[tmp.first][tmp.second] + 1;
                }
                else
                {
                    ans[tmp.first + i][tmp.second + j] = min(ans[tmp.first + i][tmp.second + j], ans[tmp.first][tmp.second] + 1);
                }
                s.push(make_pair(tmp.first + i, tmp.second + j));
            }
        }
    }

    int asd = 0;

    for (int i = 1; i <= h; i++)
    {
        for (int j = 1; j <= w; j++)
        {
            asd = max(a, ans[i][j]);
        }
    }

    return asd;
}

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

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

int main()
{
    ll a, b, c, d;
    cin >> a >> b >> c >> d;

    ll tmpC = (b/c)-(a-1)/c;
    ll tmpD = (b/d)-(a-1)/d;

    ll tmpCD = (b/lcm(c, d))-(a-1)/(lcm(c, d));

    cout << (b-a+1) - tmpC - tmpD + tmpCD << endl;;
    return 0;
}

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

int main(){
	int n,k;
	cin>>n>>k;
	vector<int>p(n);
	rep(i,n)cin>>p[i];
	sort(p.begin(),p.end());
	long long int sum=0;
	rep(i,k){
		sum+=p[i];
	}
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define int long long
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;


template<class T,class U>
void chmax(T& a,U b){
	if(a<b)
		a=b;
}
 
template<class T,class U>
void chmin(T& a,U b){
	if(b<a)
		a=b;
}


//vector<pair<int,int>> pairs;  pairs[i] = make_pair(value, value);
//sort(a.begin(),a+index_number);

//cin>>  cout<<'\n'

/*
vector<int> vec(100,-1);全ての値に-1をセット
vector<std::vector<int>> vec{{ 1, 2, 3 },{ 4, 5, 6 }};
vec.size() vec[i].size()
vec.emplace_back(20);追加
*/

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int n;
    int sum = 0;
    vector<int> w;

    int pre = 0;

    cin >> n;

    for(int i = 0;i < n;i++){
        int value;
        cin >> value ;

        sum += value;
        w.push_back(value + pre);
        pre = w[i];
    }

    int ans = 200;
    for(int value : w){
        int m = sum-value -value; 
        m = m > 0 ? m : -m;
        if(ans > m){
             ans = m;
        }
    }




    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
//         Jai Saraswati Maa       Om Namah Shivaay        Jai Bhawani
// You have to work hard and keep coding till you get correct output never quit! :-)
// May the force be with you
// Ganpatai Bappa Morya! Mangal Murti Morya!
#include<bits/stdc++.h>
#define sc(x) scanf("%d",&x);
#define scc(x,y) scanf("%d %d",&x,&y);
#define sccc(x,y,z) scanf("%d %d %d",&x,&y,&z);
#define sl(x) scanf("%lld",&x);
#define sll(x,y) scanf("%lld %lld",&x,&y);
#define slll(x,y,z) scanf("%lld %lld %lld",&x,&y,&z);
#define pf(x) printf("%d",x);
#define pfn(x) printf("%d\n",x);
#define pl(x) printf("%lld",x);
#define pln(x) printf("%lld\n",x);
int main()
{
    int n;
    sc(n)
    if(n%10==9)
    {
        printf("Yes");
        return 0;
    }
    if((n/10)%10==9)
    {
        printf("Yes");
        return 0;
    }
    printf("No");
  return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.io.Reader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.Collections;
import java.util.ArrayDeque;
import java.util.List;
import java.util.Queue;
import java.util.StringTokenizer;

/**
 * The Java template file for AtCoder online judge.
 */
public class Main {

  private static FastScanner scanner;
  private static PrintWriter printer;

  public static void solve() {
    int n = scanner.nextInt();
    double[] probHeads = new double[n];
    for (int i = 0; i < n; i++) {
      probHeads[i] = scanner.nextDouble();
    }
    // dp[i][j] - probability of using i coins with j heads
    double[][] dp = new double[n + 1][n + 1];
    dp[0][0] = 1.0;
    for (int i = 1; i <= n; i++) {
      double probH = probHeads[i - 1];
      double probT = 1 - probH;

      for (int j = i; j >= 0; j--) {
        dp[i][j] += (j == 0 ? 0 : dp[i - 1][j - 1] * probH);
        dp[i][j] += dp[i - 1][j] * probT;
      }
    }
    double result = 0.0;
    for (int heads = 0; heads <= n; heads++) {
      int tails = n - heads;
      if (heads > tails) {
        result += dp[n][heads];
      }
    }
    printer.println(result);
  }

  public static void main(String[] args) {
    scanner = new FastScanner();
    printer = new PrintWriter(System.out);
    solve();
    printer.flush();
  }

  private static class FastScanner {
    BufferedReader br;
    StringTokenizer st;

    public FastScanner(Reader in) {
      br = new BufferedReader(in);
    }

    public FastScanner() {
      this(new InputStreamReader(System.in));
    }

    public String next() {
      while (st == null || !st.hasMoreElements()) {
        try {
          st = new StringTokenizer(br.readLine());
        } catch (IOException e) {
          e.printStackTrace();
        }
      }
      return st.nextToken();
    }

    public int nextInt() {
      return Integer.parseInt(next());
    }

    public long nextLong() {
      return Long.parseLong(next());
    }

    public double nextDouble() {
      return Double.parseDouble(next());
    }

    public String nextLine() {
      String str = "";
      try {
        str = br.readLine();
      } catch (IOException e) {
        e.printStackTrace();
      }
      return str;
    }

    public int[] readIntArray(int size) {
      int[] ret = new int[size];
      for (int i = 0; i < size; i++) {
        ret[i] = nextInt();
      }
      return ret;
    }
  }
}


Measured memory_bytes: 131924
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;

int main(){
  int N;
  string name;
  string old_name[110];
  
  cin >> N;
  cin >> name;
  for(int i = 0 ; i < N ; i++){
    cin >> old_name[i];
  }
  
  int ans = 0;
  
  for(int i = 0 ; i < N ; i++){
    bool f = false;
    for(int j = 1 ; j <= old_name[i].size()/(name.size()-1) ; j++){
      for(int k = 0 ; k < old_name[i].size() ; k++){
	string t = "";
	for(int l = k ; ; l += j){
	  if(t.size() == name.size() || old_name[i].size() < l) break;
	  t += old_name[i][l];
	}
	if(t == name){
	  ans++;
	  f = true;
	}
	if(f) break;
      }
      if(f) break;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 1240
L,R = map(int,input().split())
sa = R - L
ans = 2020
if sa > 2019:
	print("0")
else:
	for i in range (L,R):
		for j in range (i+1,R+1):
			tmp = (i * j) % 2019
			if ans > tmp:
				ans = tmp
	print(ans)

Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
#include<cstdlib>

using namespace std;

int N;
long long int a[2*100000];

int main(){
    long long int suml = 0;
    long long int sumr = 0;
    cin >> N;
    for(int i = 0; i < N; i++){
        cin >> a[i];
        sumr += a[i];
    }
    long long int ans = 2000000000;
    for(int i = 0; i < N-1; i++){
        suml += a[i];
        sumr -= a[i];
        ans = min(ans, llabs(sumr-suml));
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 1792
n, k = map(int, input().split())
if k > (n - 1) * (n - 2) // 2:print(-1)
else:
    m = (n - 1) * (n - 2)  // 2 - k
    print(n + m - 1)
    for i in range(2, n + 1):
        print(1, i)
    cnt = 0
    for i in range(2, n + 1):
        if cnt >= m:
            break
        for j in range(2, i):
            if cnt >= m:
                break
            print(i, j)
            cnt += 1

Measured memory_bytes: 9308
#include<stdio.h>
#define SIZE 200
int main()
{
  char c[SIZE];
  int i,sl;
  for(i=0;;i++)
    {
      scanf("%c",&c[i]);
      if(c[i]=='\n')
	{
	  sl=i;
	  break;
	}
      else if((c[i]>='a')&&(c[i]<='z')) c[i]-='a'-'A';
    }
  for(i=0;i<sl;i++) printf("%c",c[i]);
  printf("\n");
  return 0;
}

Measured memory_bytes: 520
f = gets.split
commands = gets.rstrip.each_char

commands.each do |c|
	case c
	when ?E
		f[0], f[2], f[5], f[3] = f[3], f[0], f[2], f[5]
	when ?N
		f[0], f[1], f[5], f[4] = f[1], f[5], f[4], f[0]
	when ?S
		f[0], f[1], f[5], f[4] = f[4], f[0], f[1], f[5]
	when ?W
		f[0], f[2], f[5], f[3] = f[2], f[5], f[3], f[0]
	end
end

puts f[0]

Measured memory_bytes: 8636
sd = input()
t = input()

n = len(sd)
m = len(t)

for i in range(n - m, -1, -1):
    a = sd[i:i + m]
    ok = True
    for j in range(m):
        if a[j] != "?" and a[j] != t[j]:
            ok = False
            break

    if ok:
        print(sd[:i].replace("?", "a") + t + sd[i + m:].replace("?", "a"))
        exit()

print("UNRESTORABLE")

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

int main(){
  int n;
  cin >> n;
  while(n!=0){
    vector<int> a(n);
    for(int i=0;i<n;i++) cin >> a.at(i);

    vector<int> s(n+1);
    s.at(0) = 0;
    for(int i=1;i<n+1;i++) s.at(i) = s.at(i-1)+a.at(i-1);

    int ans=a.at(0);
    for(int i=1;i<n+1;i++){
      for(int j=0;j<i;j++){
        ans = max(s.at(i)-s.at(j),ans);
      }
    }

    cout << ans << endl;

    cin >> n;
  }
}



Measured memory_bytes: 3112
A, B, C, X = map(int, [input() for i in range(4)])
ans = 0
for a in range(A + 1):
    for b in range(B + 1):
        for c in range(C + 1):
            if a * 500 + b * 100 + c * 50 == X:
                ans += 1
print(ans)


Measured memory_bytes: 39664
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <climits>
#include <numeric>
#include <cmath>
#include <queue>
#include <sstream>
#include <string.h>

using namespace std;
typedef long long ll;

int main()
{
  vector<int> v(2);
  cin >> v[0] >> v[1];
  
  int res = 0;
  sort(v.begin(), v.end(), greater<>());
  
  res += v[0];
  v[0]--;
  
  sort(v.begin(), v.end(), greater<>());
  res += v[0];
  
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.*;

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 answer = 0;
		
		if(a==b) answer = c;
		if(a==c) answer = b;
		if(b==c) answer = a;

		System.out.println(answer);


		
	}
}

Measured memory_bytes: 22740
n, k = map(int, input().split())

a = [0] * n

for i in range(k):
    d = int(input())
    t = list(map(int, input().strip().split()))

    for j in range(len(t)):
        a[t[j]-1] = 1

#print(a)
print(a.count(0))

Measured memory_bytes: 9184
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

ll dp[55][2];

int main(){
  int N, P;
  cin >> N >> P;
  dp[0][0] = 1;

  rep(i,N){
    int a;
    cin >> a;
    dp[i+1][0] = dp[i][0];
    dp[i+1][1] = dp[i][1];
    if(a%2==0){
      dp[i+1][0] += dp[i][0];
      dp[i+1][1] += dp[i][1];
    }else{
      dp[i+1][1] += dp[i][0];
      dp[i+1][0] += dp[i][1];
    }
  }
  
  cout << dp[N][P] << endl;
  
  return 0;
}



Measured memory_bytes: 256
N,M = map(int,input().split())
AC = [0 for _ in range(N)]
WA = [0 for _ in range(N)]

for _ in range(M):
    p,S = input().split()
    p = int(p)-1
    if not AC[p]:
        if S == 'AC':
            AC[p] = 1
        else:
            WA[p] += 1
    else:
        continue
WAcount = 0
for i in range(N):
    if AC[i]:
        WAcount += WA[i]
print(sum(AC),WAcount)

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

using namespace std;

long long c[100005], cs[100005], n, k, temp, addi, dedu, finans;
const long long mod = 1000000007;

long long powermod(long long a, long long b) {
	long long ans = 1;
	a %= mod;
	while (b) {
		if (b & 1) ans = (ans * a) % mod;
		a = (a * a) % mod;
		b >>= 1;
	}
	return ans;
}

long long divi(long long q, long long d) {
	long long temp = 1;
	temp = (q * powermod(d, mod - 2)) % mod;
	return temp;
}

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> n >> k;
	if (k > 2) {
		for (int i=0; i<k-1; i++) c[i] = 1;
		for (int i=k-1; i<=n; i++) {
			c[i] = (c[i - 1] * i) % mod;
			c[i] = divi(c[i], i - k + 2);
		}
	}
	else for (int i=0; i<=n; i++) c[i] = 1;
	long long a[n];
	for (int i=0; i<n; i++) cin >> a[i];
	sort (a, a + n);
	cs[k - 2] = c[k - 2];
	for (int i=k-1; i<=n; i++) cs[i] = (cs[i - 1] + c[i]) % mod;
	for (int i=k - 1; i<n; i++) {
		addi += cs[i - 1] * a[i];
		addi %= mod;
	}
	for (int i=0; i<= n-k; i++) {
		dedu += cs[n - 2 - i] * a[i];
		dedu %= mod;
	}
	finans = (addi + mod - dedu) % mod;
	cout << finans << endl;
}

Measured memory_bytes: 2176
#include <stdio.h>
int main()
{
  int a, b;
  char S[4];
  scanf("%d", &a);
  scanf("%d", &b);
  if (a == 1 && b == 2)
    printf("3\n");
  else if (a == 1 && b == 3)
    printf("2\n");
  else if (a == 2 && b == 3)
    printf("1\n");
  else if (a == 2 && b == 1)
    printf("3\n");
  else if (a == 3 && b == 1)
    printf("2\n");
  else if (a == 3 && b == 2)
    printf("1\n");

  return 0;
}


Measured memory_bytes: 128
import java.util.*; import java.io.*; import java.math.*;
public class Main{
	static void solve(){//Here is the main function
		ArrayList<Integer> one = nextIntArray();
		int N = one.get(0);
		int K = one.get(1);
		int output = 0;
		while(N > 0){
			output++;
			N /= K;
		}
		myout(output);
	}
	//Method addition frame start



	//Method addition frame end

	//Don't have to see. start------------------------------------------
	static class InputIterator{
		ArrayList<String> inputLine = new ArrayList<String>(1024);
		int index = 0; int max; String read;
		InputIterator(){
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			try{
				while((read = br.readLine()) != null){
					inputLine.add(read);
				}
			}catch(IOException e){}
			max = inputLine.size();
		}
		boolean hasNext(){return (index < max);}
		String next(){
			if(hasNext()){
				return inputLine.get(index++);
			}else{
				throw new IndexOutOfBoundsException("There is no more input");
			}
		}
	}
	static HashMap<Integer, String> CONVSTR = new HashMap<Integer, String>();
	static InputIterator ii = new InputIterator();//This class cannot be used in reactive problem.
	static PrintWriter out = new PrintWriter(System.out);
	static void flush(){out.flush();}
	static void myout(Object t){out.println(t);}
	static void myerr(Object t){System.err.print("debug:");System.err.println(t);}
	static String next(){return ii.next();}
	static boolean hasNext(){return ii.hasNext();}
	static int nextInt(){return Integer.parseInt(next());}
	static long nextLong(){return Long.parseLong(next());}
	static double nextDouble(){return Double.parseDouble(next());}
	static ArrayList<String> nextStrArray(){return myconv(next(), 8);}
	static ArrayList<String> nextCharArray(){return myconv(next(), 0);}
	static ArrayList<Integer> nextIntArray(){
		ArrayList<String> input = nextStrArray(); ArrayList<Integer> ret = new ArrayList<Integer>(input.size());
		for(int i = 0; i < input.size(); i++){
			ret.add(Integer.parseInt(input.get(i)));
		}
		return ret;
	}
	static ArrayList<Long> nextLongArray(){
		ArrayList<String> input = nextStrArray(); ArrayList<Long> ret = new ArrayList<Long>(input.size());
		for(int i = 0; i < input.size(); i++){
			ret.add(Long.parseLong(input.get(i)));
		}
		return ret;
	}
	static String myconv(Object list, int no){//only join
		String joinString = CONVSTR.get(no);
		if(list instanceof String[]){
			return String.join(joinString, (String[])list);
		}else if(list instanceof ArrayList){
			return String.join(joinString, (ArrayList)list);
		}else{
			throw new ClassCastException("Don't join");
		}
	}
	static ArrayList<String> myconv(String str, int no){//only split
		String splitString = CONVSTR.get(no);
		return new ArrayList<String>(Arrays.asList(str.split(splitString)));
	}
	public static void main(String[] args){
		CONVSTR.put(8, " "); CONVSTR.put(9, "\n"); CONVSTR.put(0, "");
		solve();flush();
	}
	//Don't have to see. end------------------------------------------
}


Measured memory_bytes: 32928
#include <cstdio>

#define abs(a) (a < 0 ? -(a) : a)

int main()
{
  int a, b, c, d;
  scanf("%d %d %d %d", &a, &b, &c, &d);
  puts(abs(a - c) <= d || abs(a - b) <= d && abs(b - c) <= d ? "Yes" : "No");
  return 0;
}

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

int main() {
    while(true) {
        int a, b;
        cin >> a >> b;
        if(a == 0 && b == 0) return 0;
        for(int i = 0; i < a; i++) {
            for(int j = 0; j < b; j++) {
                cout << "#";
            }
            cout << endl;
        }
        cout << endl;
    }
}



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

int main() {

  int H,W,K;
  cin >> H >> W >> K;
  char c[H][W];
  int all_black = 0;
  for(int h=0; h < H; h++){
    for(int w=0; w < W; w++){
      cin >> c[h][w];
      if(c[h][w] == '#'){
        all_black +=1;
      }
    }
  }

  int ans = 0;
  for(int row_h = 0; row_h < (1<<H); row_h++){
    for(int col_w = 0; col_w < (1<<W); col_w++){
      int black = 0;
      for(int i=0; i<H; i++){
        for(int j=0; j<W; j++){
          if(c[i][j]=='#'){
            if(row_h & (1<<i) || col_w & (1<<j)){
              black +=1;
            }
          }
        }
      }
      if(black + K == all_black){
        ans += 1;
      }
    }
  }

  cout << ans << endl;

return 0;
}

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;

#define mem(x, y) memset(x, y, sizeof(x))
#define mp make_pair
#define pb push_back

int main() {
    ll N, tmp;
    ll A[200001];
    mem(A, 0);
    cin >> N;

    for(ll i = 0; i < N - 1; i++) {
        cin >> tmp;
        A[tmp-1] += 1;
    }

    for(ll i = 0; i < N; i++) {
        cout << A[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 5196
import sys
input = sys.stdin.readline


def main():
    N, M = [int(x) for x in input().split()]
    X = [int(x) for x in input().split()]
    X.sort()
    Y = []
    for i in range(M - 1):
        Y.append(X[i + 1] - X[i])
    Y.sort()

    i = 0
    while Y and i < N - 1:
        i += 1
        Y.pop()
    print(sum(Y))










if __name__ == '__main__':
    main()



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

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

    int N, M; cin >> N >> M;
    vector<int> P(M), Y(M);
    vector<vector<int>> city(N);
    for (int i = 0; i < M; i++) {
        cin >> P[i] >> Y[i]; P[i]--;
        city[P[i]].push_back(Y[i]);
    }

    for (int i = 0; i < N; i++)
        sort(city[i].begin(), city[i].end());

    for (int i = 0; i < M; i++) {
        int j = lower_bound(city[P[i]].begin(),
                            city[P[i]].end(),
                            Y[i])
              - city[P[i]].begin();
        cout << setw(6) << setfill('0') << P[i] + 1;
        cout << setw(6) << setfill('0') << j + 1 << "\n";
    }
}

Measured memory_bytes: 7808
import sys
imput =sys.stdin.readline

p = 10**9 + 7

N,M =map(int,input().split())
lis = [0]*N

for _ in range(M):
    i = int(input())-1
    lis[i] = -1


if lis[0]!=-1:
    lis[0] =1
if N != 1:
    if lis[1]!=-1:
        lis[1] =1 + max(0,lis[0])

for i in range(N-2):
    i += 2
    if lis[i]!=-1:
        lis[i]= (max(0,lis[i-1])+max(0,lis[i-2]))%p

print(max(0,lis[-1]))

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

#define int long long
#define ff first
#define ss second
#define endl '\n'
#define ii pair<int, int>
#define DESYNC ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define pb push_back
#define vi vector<int>
#define vii vector< ii >
#define EPS 1e-9
#define INF 1e18
#define ROOT 1

using namespace std;

inline int mod(int n){ return (n%1000000007); }

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

int32_t main(){
	DESYNC;
	int n = 3;
	int v[n];
	for(int i=0; i<n; i++) cin >> v[i];
	sort(v, v+n);
	int ans = 0;
	for(int i=1; i<n; i++) ans += (v[i] - v[i-1]);
	cout << ans << endl;
}



Measured memory_bytes: 256
h,w = map(int,input().split())
grid = [list(input()) for i in range(h)]
grid[0][0] = 1
mod = 10**9+7
for i in range(h):
  for j in range(w):
    if i == j == 0:
      continue
    if grid[i][j] == "#":
      grid[i][j] = 0
    elif i == 0:
      grid[i][j] = grid[i][j-1]
    elif j == 0:
      grid[i][j] = grid[i-1][j]
    else:
      grid[i][j] = (grid[i-1][j]+grid[i][j-1])%mod
print(grid[-1][-1])


Measured memory_bytes: 103516
#include <bits/stdc++.h>
using namespace std;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
void solve(){
    string val;
    cin >> val ;
    // debug(val);
    long long sum = 0;
    for(int i:val){
        sum = sum + i -48;
        // debug(i);
    }
    // debug(sum);
    if(sum%9==0)
        cout<<"Yes"<<"\n";
    else
        cout<<"No"<<"\n";
}
int main(){
int t;
// cin>>t;
t = 1;
while(t-->0)
    solve();
return 0;
}

Measured memory_bytes: 3672
#n,k分ける
n,k=map(int, input().split())
#Aで数えるなら
A=list(map(int, input().split()))
count=0
#ｎ人いてて、ｋより高い人を抽出
for i in range(n):
    if A[i]>=k:
        count+=1
print(count)

Measured memory_bytes: 11908
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
// #pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define mp make_pair
#define pi pair<int,int>
#define pl pair<long long int,long long int>
#define pb push_back
#define fi first
#define se second
#define len(a) (int)(a).length()
#define sz(a) (int)(a).size()

using namespace std;

int n;
double x, p[3000], dp[3000][3000];

int main ()
{
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	cin >> n;
	for (int i=0; i<n; ++i)
		cin >> p[i];
	dp[0][0] = 1 - p[0];
	for (int i=1; i<n; ++i)
		dp[i][0] = dp[i-1][0] - dp[i-1][0] * (p[i]);
	dp[0][1] = p[0];
	for (int i=0; i<n; ++i)
		for (int j=i+2; j<=n; ++j)
			dp[i][j] = 0;
	for (int i=1; i<n; ++i)
		for (int j=1; j<=n; ++j)
			dp[i][j] = (dp[i-1][j-1] - dp[i-1][j]) * p[i] + dp[i-1][j];
	x = 0;
	for (int i=(n+1)/2; i<=n; ++i)
		x += dp[n-1][i];
	printf("%.10f\n", x);
	return 0;
}


Measured memory_bytes: 70528
while True:
    try:
        figmap = [[0]*12 for _ in range(12)]
        for i in range(8):
            instr = input()
            for j in range(8):
                figmap[i][j+1] = int(instr[j])
        outi = outj = 0
        flag = True
        for i in range(12):
            for j in range(12):
                if figmap[i][j] == 1 and flag:
                    outi = i; outj = j
                    flag = False
        if figmap[outi+1][outj] * figmap[outi][outj+1] * figmap[outi+1][outj+1] == 1: print("A")
        if figmap[outi+1][outj] * figmap[outi+2][outj] * figmap[outi+3][outj] == 1: print("B")
        if figmap[outi][outj+1] * figmap[outi][outj+2] * figmap[outi][outj+3] == 1: print("C")
        if figmap[outi+1][outj] * figmap[outi+1][outj-1] * figmap[outi+2][outj-1] == 1: print("D")
        if figmap[outi][outj+1] * figmap[outi+1][outj+1] * figmap[outi+1][outj+2] == 1: print("E")
        if figmap[outi+1][outj] * figmap[outi+1][outj+1] * figmap[outi+2][outj+1] == 1: print("F")
        if figmap[outi+1][outj] * figmap[outi][outj+1] * figmap[outi+1][outj-1] == 1: print("G")

        input()
    except EOFError: break

Measured memory_bytes: 7652
package main

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

var scanner = bufio.NewScanner(os.Stdin)

func nextInt() (int, error) {
	return strconv.Atoi(nextString())
}

func nextString() string {
	scanner.Scan()
	return scanner.Text()
}

func stringifyArray(arr []int) string {
	return strings.TrimRight(fmt.Sprintf("%+v", arr)[1:], "]")
}

func dropEmptyTasks(names []string, time []int) ([]string, []int) {
	namesNew := []string{}
	timeNew := []int{}
	for i := range time {
		if time[i] > 0 {
			namesNew = append(namesNew, names[i])
			timeNew = append(timeNew, time[i])
		}
	}
	return namesNew, timeNew
}

func main() {
	scanner.Split(bufio.ScanWords)

	n, _ := nextInt()
	q, _ := nextInt()

	names := make([]string, n)
	time := make([]int, n)

	for i := 0; i < n; i++ {
		names[i] = nextString()
		time[i], _ = nextInt()
	}

	currentTask := 0
	currentTime := 0
	for {
		if time[currentTask] > 0 {
			if time[currentTask] > q {
				currentTime += q
				time[currentTask] -= q
			} else {
				currentTime += time[currentTask]
				time[currentTask] = 0
			}

			if time[currentTask] == 0 {
				fmt.Println(names[currentTask], currentTime)
			}
		}

		hasNonzeroProcess := false
		for i := 0; i < len(names); i++ {
			if time[i] > 0 {
				hasNonzeroProcess = true
				break
			}
		}
		if !hasNonzeroProcess {
			break
		}
		currentTask = (currentTask + 1) % len(names)

		if currentTask == 0 {
			names, time = dropEmptyTasks(names, time)
		}
	}

	// fmt.Println(names, time, q)
}



Measured memory_bytes: 6948
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

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

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

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

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

fn check(a: Vec<u32>) -> String {
    let mut ans = "APPROVED";
    for i in 0..a.len() {
        if a[i] % 2 == 0 {
            if a[i] % 3 != 0 && a[i] % 5 != 0 {
                ans = "DENIED";
                break;
            }
        }
    }
    ans.to_string()
}

fn main() {
    input! {n: u32, a: [u32; n]}
    println!("{}", check(a));
}


Measured memory_bytes: 4352
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <limits>
#include <fstream>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int a, b;
  cin >> a >> b;
  cout << max(a + b , max ( a - b, a * b) ) << endl;
  return 0;
}

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

def swap(a, b):
    if a < b:
        return (a, b)
    else:
        return (b, a)

def gcd(a, b):
    while a > 0:
        r = b % a
        b = a
        a = r

    return b

print(gcd(*swap(*get_input())))



Measured memory_bytes: 5596