akhauriyash/Code-Regression huggingface dataset:
// #pragma GCC optimize("Ofast,unroll-loops")
// #pragma GCC target("avx,avx2,fma")

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

#define ll long long
#define ull unsigned long long
#define dd double
#define ld long double
#define sl(n) scanf("%lld", &n)
#define si(n) scanf("%d", &n)
#define sd(n) scanf("%lf", &n)
#define pll pair <ll, ll>
#define pii pair <int, int>
#define mp make_pair
#define pb push_back
#define all(v) v.begin(), v.end()
#define inf (1LL << 62)
#define loop(i, start, stop, inc) for(ll i = start; i <= stop; i += inc)
#define for1(i, stop) for(ll i = 1; i <= stop; ++i)
#define for0(i, stop) for(ll i = 0; i < stop; ++i)
#define rep1(i, start) for(ll i = start; i >= 1; --i)
#define rep0(i, start) for(ll i = (start-1); i >= 0; --i)
#define ms(n, i) memset(n, i, sizeof(n))
#define casep(n) printf("Case %lld:", ++n)
#define pn printf("\n")
#define pf printf
#define EL '\n'
#define fastio std::ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

const ll sz = 5005;
ll p[sz], c[sz], n, k, lev[sz];

ll dfs(ll u, ll lv)
{
    if(lv > k)
        return 0;

    if(lev[u] != -1) {
        ll cycLen = lv - lev[u], rest = k - lv + 1, now = u, mx = 0, val;

        ll sum = 0;
        for(ll i = 1; i <= cycLen && i <= rest; i++) {
            now = p[now], val = c[now];
            sum += val;

            mx = max(mx, sum);
        }
        if(sum <= 0) return mx;

        ll cycCnt = rest / cycLen, cycSum = sum;
        rest = rest % cycLen;

        sum = mx = 0, now = u;
        for(ll i = 1; i <= rest; i++) {
            now = p[now], val = c[now];
            sum += val;

            mx = max(mx, sum);
        }

        ll ret = cycSum*cycCnt + mx;

        if(cycCnt > 0) {

            sum = mx = 0, now = u;
            for(ll i = 1; i <= cycLen; i++) {
                now = p[now], val = c[now];
                sum += val;

                mx = max(mx, sum);
            }

            ret = max(ret, cycSum*(cycCnt-1) + mx);
        }

        return ret;
    }

    lev[u] = lv;

    ll nxt = p[u], val = c[nxt];
    return val + max(0LL, dfs(nxt, lv+1));
}

int main()
{
    cin >> n >> k;
    for1(i, n) sl(p[i]);
    for1(i, n) sl(c[i]);

    ll ans = -inf;

    for1(i, n) {
        ms(lev, -1);

        ans = max(ans, dfs(i, 1));
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3996
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define sqr(x) ((x)*(x))
#define mp make_pair
#define uint unsigned
inline char gc(){
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline int read(){
	int x = 0; char ch = gc(); bool positive = 1;
	for (; !isdigit(ch); ch = gc())	if (ch == '-')	positive = 0;
	for (; isdigit(ch); ch = gc())	x = x * 10 + ch - '0';
	return positive ? x : -x;
}
inline void write(int a){
    if(a>=10)write(a/10);
    putchar('0'+a%10);
}
inline void writeln(int a){
    if(a<0){
    	a=-a; putchar('-');
	}
	write(a); puts("");
}
const int N=200005;
int n,q,x,y,a[N];
ll sum[N],dp[N],ans;
#define lowbit(i) i&-i
struct BIT{
	ll c[N];
	void change(int pos,ll de){
		for(int i=pos;i<=n;i+=lowbit(i))c[i]=min(c[i],de);
	}
	ll ask(int pos){
		ll ans=4e18;
		for(int i=pos;i;i-=lowbit(i))ans=min(ans,c[i]);
		return ans;
	}
}T[2];
void insert(ll de,int pos){
	T[0].change(pos,de-pos);
	T[1].change(n-pos+1,de+pos);
}
int main(){
	n=read(); q=read(); x=read(); y=read();
	for(int i=1;i<=q;i++)a[i]=read();
	for(int i=2;i<=q;i++)sum[i]=sum[i-1]+abs(a[i-1]-a[i]);
	for(int i=1;i<=n;i++)T[0].c[i]=T[1].c[i]=4e18;
	insert(abs(x-a[1]),y);
	insert(abs(y-a[1]),x);
	ans=sum[q]+min(abs(x-a[1]),abs(y-a[1]));
	for(int i=1;i<q;i++){
		dp[i]=min(T[0].ask(a[i+1])+sum[i]+a[i+1],T[1].ask(n-a[i+1]+1)+sum[i]-a[i+1]);
		//if(i==3)cout<<dp[i]<<" "<<i<<" "<<T[0].ask(a[i+1])<<endl;
		//cout<<ans<<endl;
		ans=min(ans,dp[i]+sum[q]-sum[i+1]);
		insert(dp[i]-sum[i+1],a[i]);
	}
	cout<<ans<<endl;
}
/*
dp[i]=dp[j]+sum[i]-sum[j+1]+abs(a[i+1]-a[j])
*/

Measured memory_bytes: 7296
#define DEBUG 0
#include <bits/stdc++.h>
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template<class T>using numr=std::numeric_limits<T>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int INF = 1e9;
const ll LLINF = 1e16;
const ll mod = 1000000007;
const int mod2 = 998244353;
void debug_impl() { std::cerr << std::endl; }
template <typename Head, typename... Tail>
void debug_impl(Head head, Tail... tail) { std::cerr << " " << head; debug_impl(tail...); }
#if DEBUG
#define debug(...)\
    do {\
        std::cerr << std::boolalpha << "[" << #__VA_ARGS__ << "]:";\
        debug_impl(__VA_ARGS__);\
        std::cerr << std::noboolalpha;\
    } while (false)
#else
#define debug(...) {}
#endif

template < typename Container, typename Value = typename Container::value_type, std::enable_if_t<!std::is_same< Container, std::string >::value, std::nullptr_t> = nullptr>
std::istream& operator>> (std::istream& is, Container& v)
    { for (auto & x : v) { is >> x; } return is; }

template < typename Container, typename Value = typename Container::value_type, std::enable_if_t<!std::is_same< Container, std::string >::value, std::nullptr_t> = nullptr >
std::ostream& operator<< (std::ostream& os, Container const& v) {
os << "{";
    for (auto it = v.begin(); it != v.end(); it++)
        {os << (it != v.begin() ? "," : "") << *it;}
    return os << "}";
}

template< typename T >
T mod_pow(T x, T n, const T &p) {
  T ret = 1;
  while(n > 0) {
    if(n & 1) (ret *= x) %= p;
    (x *= x) %= p;
    n >>= 1;
  }
  return ret;
}

int main() {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    ll ans = mod_pow(10LL,n,mod);
    ans -= mod_pow(9LL,n,mod)*2;
    ans += mod_pow(8LL,n,mod);
    ans = (ans % mod + mod) % mod;
    cout << ans << endl;
}

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

namespace ABC061
{
    class C
    {
        static void Main(string[] args)
        {

            long[] input = Console.ReadLine().Split().Select(long.Parse).ToArray();

            long N = input[0];
            long K = input[1];

            long[] Count = new long[100000 + 10];
            for (int i = 0; i < N; i++)
            {
                input = Console.ReadLine().Split().Select(long.Parse).ToArray();
                long a = input[0];
                long b = input[1];

                Count[a] += b;
            }

            long bCount = 0;
            for (int i = 0; i < Count.Length; i++)
            {
                bCount += Count[i];
                if (K <= bCount) { Console.WriteLine(i); return; }
            }
        }
    }
}


Measured memory_bytes: 17456
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define rep1(i,n) for(int i = 1; i <= n; i++)
#define co(x) cout << x <<endl
#define cs(x) cout << x <<" "
#define ALL(a) (a).begin(),(a).end()
#define MOD 1e9+7
typedef long long ll;
using namespace std;

int main()
{
	int a, b, c;
	cin >> a >> b >> c;
	if (a + b + 1 >= c)co(b + c);
	else co(a + 2*b + 1);
	return 0;
}


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

int main(){
	int n;
  	cin>>n;
  	
  	long long int sum=0;
  
  	for(int i=0;i<=n;i++){
    	if(i%3==0) continue;
      	else if(i%5==0) continue;
      	else sum+=i;
    }
  	cout<<sum<<endl;
}  

Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define bit(n) (1<<(n))
#define ii(x) int x; cin >> (x)
#define ii2(x, y) int x, y; cin >> (x) >> (y)
#define ii3(x, y, z) int x, y, z; cin >> (x) >> (y) >> (z)
#define yn(x, ok, ng) cout << ((x)?(ok):(ng)) << endl
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
int const INF = 1001001001;

void ok() {
    cout << "Yes" << endl;
    exit(0);
}

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

int n,m,k;
cin >> n >> m >> k;
for(int i = 0; i <= n; ++i) {
    for(int j = 0; j <= m; ++j) {
        int s = (m-j)*i + (n-i)*j;
        if(s == k) ok();
    }
}
cout << "No" << endl;
return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout << #x << " = " << (x) << endl
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ')
#define showv2(v) rep(j,v.size()) showv(v[j])
#define showt(t,n) rep(i,n) printf("%d%c", t[i], i==n-1?'\n':' ')
#define showt2(t,r,c) rep(j,r) showt(t[j],c)
#define showvp(p) rep(i,p.size()) printf("%d %d\n", p[i].first, p[i].second);
#define printv(v) rep(i,v.size()) printf("%d\n", v[i])
#define printt(t,n) rep(i,n) printf("%d\n", t[i])
#define incl(v,x) find(rng(v),x)!=v.end()
#define incls(s,c) s.find(c)!=string::npos
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define bit(n,k) ((n>>k)&1) // nのk bit目
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
typedef vector<P> vp;
typedef vector<T> vt;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = (1<<30)-1;
const ll INFLL = (1LL<<62)-1;
#define dame { puts("No"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
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; }

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int64_t MOD=1000000007;
const long long INF = 1LL<<60;
const int64_t ZER=0LL;

int main() {
  int64_t N,K,ans=-1*INF; cin>>N>>K;
  vector<int64_t> P(N);
  rep(i,N) cin>>P.at(i);
  rep(i,N) P.at(i)--;
  vector<int64_t> C(N);
  rep(i,N) cin>>C.at(i);
  
  rep(i,N){
    vector<bool> seen(N,true);
    vector<int64_t> S,T;
    int64_t k=i,sum=0;
    while(seen.at(k)){
      seen.at(k)=false;
      S.push_back(C.at(k));
      sum+=C.at(k);
      k=P.at(k);
    }
    int64_t t=S.size(),r=K/t,q=K%t,MAX=-1*INF,NMAX,MAX2=-1*INF;
    rep(i,t){
      T.push_back(S.at(i));
      if(i>0) T.at(i)+=T.at(i-1);
      if(T.at(i)>MAX){
        MAX=T.at(i);
        NMAX=i+1;
      }
    }
      if(q<NMAX){
        rep(i,q) MAX2=max(MAX2,T.at(i));
        if(sum<0) ans=max(ans,MAX);
        else if(r==0) ans=max(ans,MAX2);
        else{
          auto temp=max(MAX+sum*max((r-1),ZER),max(MAX2+sum*r,sum*r));
          ans=max(ans,temp);
        }
      }
      else{
        if(sum<0) ans=max(ans,MAX);
        else ans=max(ans,MAX+sum*r);
      }
  }
  cout<<ans;
}


Measured memory_bytes: 3736
#include <map>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
#include <algorithm>
using namespace std;
#define INF 0x3f3f3f3f



int main()
{

	int i;
	std::ios::sync_with_stdio(false);
	long long x, n, m = pow(10, 9) + 7;
	while (cin >> n)
	{
		x = 1;
		for (i = 1; i <= n; i++)
		{
			x *= i;
			x = x%m;
		}
		cout << x << endl;
	}

	return 0;
}


Measured memory_bytes: 256
using System;

namespace AtCoderWorkspace
{
    public static class Class142_2
    {
        public static void Main(string[] args)
        {
            var inputs = Console.ReadLine().Split(' ');
            int n, k = 0;
            int.TryParse(inputs[0],out n);
            int.TryParse(inputs[1],out k);

            var talls = Console.ReadLine().Split(' ');
            
//            int[] tallValues = new int[n];
            int counter= 0;

            for (int i = 0; i < n; i++)
            {
                int temp;
                int.TryParse(talls[i],out temp);
                if (temp >= k)
                {
                    counter++;
                }
            }
            
            Console.WriteLine(counter.ToString());
        }
    }
}

Measured memory_bytes: 17632
#include <iostream>
#include <cstdint>

std::int64_t a[100000], b[100000];

int main() {
	int n;
	std::cin >> n;

	for (int i = 0; i < n; ++i)
		std::cin >> a[i] >> b[i];

	std::int64_t pushed = 0;
	for (int i = n - 1; i >= 0; --i) {
		std::int64_t tmp = (a[i] + pushed) % b[i];

		pushed += (tmp != 0 ? b[i] - tmp : 0);
	}

	std::cout << pushed << std::endl;
}

Measured memory_bytes: 1792
n = int(input())
if n % 2 == 0:
    a = [(i, n - i + 1) for i in range(1, n // 2 + 1)]
else:
    a = [(i, n - i) for i in range(1, n // 2 + 1)]
    a.append((n,))
ans = []
for i in range(len(a) - 1):
    for a1 in a[i]:
        for a2 in a[i+1]:
            ans.append((a1, a2))
if len(a) > 2:
    for a1 in a[0]:
        for a2 in a[len(a)-1]:
            ans.append((a1, a2))
print(len(ans))
for i in ans:
    print('{} {}'.format(i[0], i[1]))


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

using namespace std;

void nibutan(vector<long long> &da, long long n, long long &le, long long &ri) {
	if (ri - le == 1 || le == da.size() || ri == 0) {
		return;
	}
	long long x = (le + ri) / 2;
	if (n > da[x]) {
		le = x;
		nibutan(da, n, le, ri);
	}
	else {
		ri = x;
		nibutan(da, n, le, ri);
	}
}

long long minum(vector<long long> &t, vector<long long> &s, long long x, long long les, long long ris, long long let, long long rit) {
	vector<long long> da(4);
	vector<long long> inp = { les,let,ris,rit };
	for (int i = 0;i < 4;i++) {
		if (inp[i] == -1) {
			da[i] =100000000000;
			continue;
		}
		if (i % 2) {
			da[i] =t[inp[i]];
		}
		else {
			da[i] = s[inp[i]];
		}
	}
	long long ans = LLONG_MAX;
	for (int i = 0;i < 4;i++) {
		for (int j = 0;j < 4;j++) {
			if (i != j) {
				long long me = abs(da[i] - x) + abs(da[i] - da[j]);
				if ((i+j)%2) {
					ans = min(ans, me);
				}
			}
		}
	}
	return ans;
}

int main() {
	int a, b, q;
	cin >> a >> b >> q;
	vector<long long> s(a), t(b), x(q);
	for (int i = 0;i < a;i++) {
		cin >> s[i];
	}
	for (int i = 0;i < b;i++) {
		cin >> t[i];
	}
	for (int i = 0;i < q;i++) {
		cin >> x[i];
	}
	for (int i = 0;i < q;i++) {
		long long les = -1, let = -1, ris = a, rit = b, ans = 0;
		nibutan(s, x[i], les, ris);
		nibutan(t, x[i], let, rit);
		if (ris == a) {
			ris = -1;
		}
		if (rit == b) {
			rit = -1;
		}
		cout << minum(t, s, x[i], les, ris, let, rit) << endl;
	}
}

Measured memory_bytes: 3712
def insertion_sort(arr):
    print(" ".join(map(str, arr)))
    for i in range(1,len(arr)):
        j = i
        while arr[j] < arr[j-1] and j > 0:
            arr[j-1], arr[j] = arr[j], arr[j-1]
            j -= 1
        print(" ".join(map(str, arr)))

input()
arr = list(map(int, input().split()))
insertion_sort(arr)


Measured memory_bytes: 5600
#include <iostream>
#include <map>
#include <string>
 
int main(void){
    using namespace std;
    
    map<string, int> sentence;
    string maxFrequentSentence="";
    string maxCharacterSentence="";
    string inputSentence;
     
    /* Input */
    while( cin >> inputSentence )
    {
        /* CountUp Sentence*/
        if( sentence.count(inputSentence) != 0 )
        {
            sentence[inputSentence] = sentence[inputSentence] + 1;
        }
        else
        {
            sentence[inputSentence] = 1;
        }
         
        /* Update Max Characters Sentence */
        if( maxCharacterSentence.size() < inputSentence.size() )
        {
            maxCharacterSentence = inputSentence;
        }
         
        /* Update Max Frequent Sentence */
        if( sentence[maxFrequentSentence] < sentence[inputSentence] )
        {
            maxFrequentSentence = inputSentence;
        }
    }
     
    /* Output */
    cout << maxFrequentSentence << " " << maxCharacterSentence << endl;
  
    return 0;
}

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

int main()
{
		int n;
		cin>>n;
		ll min = 0;
		for(int i=1;i<n;i++)
		{
			min += ((n+i-1)/i)-1;
		}
		cout<<min<<"\n";	
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N;
    cin >> N;
    int A[N];
    int B[N]={0};
    for(int i=0; i<N; i++){
        cin >> A[i];
    }
    int div=2;
    int now = N;
    int sum=0;
    for(div=2; div<=(N/2)+1; div++){
        for(int i=now; i>N/div; i--){
            for(int j=1; j<div-1; j++){
                sum+=B[i*(j+1)-1];
            }
            B[i-1]=(sum%2!=A[i-1]);
            sum=0;
        }
        now=N/div;
    }
    sum=0;
    for(int i=1; i<N; i++){
        sum+=B[i];
    }
    B[0]=(sum%2!=A[0]);
    cout << sum+B[0] << endl;
    for(int i=0; i<N; i++){
        if(B[i]){
            cout << i+1 << " ";
        }
    }
    return 0;
}

Measured memory_bytes: 2432
import java.io.*;
import java.util.*;


class Main {

    // Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
    public static void main(String[] args) throws Exception {
        final Scanner sc = new Scanner(System.in);
        String S;
        S = sc.next();
        String T;
        T = sc.next();
        solve(S, T);
    }

    static void solve(String S, String T){
        int ans = 0;
        for (int i = 0; i<3; i++) {
            if(S.charAt(i) == T.charAt(i)) ans++;
        }

        System.out.println(ans);
    }
}


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

int main() {
    int n, m;
    cin >> n >> m;
    vector<int64_t> a(n), b(m);
    for (int i = 0; i < n; i++) {
        cin >> a.at(i);
    }
    for (int i = 0; i < m; i++) {
        cin >> b.at(i);
    }
    auto ans = convolution(a, b);
    for (int i = 0; i < n + m - 1; i++) {
        cout << ans[i];
        if (i == n + m - 2) {
            cout << endl;
        } else {
            cout << " ";
        }
    }
}


Measured memory_bytes: 27240
import sys
import  math
from statistics import *
from collections import *
from operator import itemgetter
"""
from fractions import gcd
def lcm(x, y):
    return (x * y) // gcd(x, y)
"""
stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

n = ni()
s = str(n)
f = sum([int(s[i]) for i in range(len(s))])
print('Yes' if n % f == 0 else 'No')

Measured memory_bytes: 5144
program water_bottle
  implicit none
  real(8), parameter :: pi = 3.14159265358979d0, rad2deg = 180.d0/pi
  integer :: a, b, x
  real(8) :: theta
  character(64) :: ans
  read(*,*) a, b, x
  if (a*a*b > 2*x) then
    theta = atan2(real(2*x,8),real(a*b*b,8))
  else if (a*a*b < 2*x) then
    theta = atan2(real(a*a*a,8),2.d0*real(a*a*b-x,8))
  else
    theta = atan2(real(b,8),real(a,8))
  end if
  write(ans,'(f32.16)') (0.5d0*pi-theta)*rad2deg
  write(*,'(a)') trim(adjustl(ans))
end program water_bottle

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

typedef pair<int, int> P;
const int INF = 10000000;

int main()
{
    int H, W;
    cin >> H >> W;
    int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};

    char maze[H][W];
    int dis[H][W];
    int wall = 0;

    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            cin >> maze[i][j];
            if (maze[i][j] == '#') {
                wall++;
            }
            dis[i][j] = INF;
        }
    }

    //bfs
    queue<P> que;
    que.push(P(0, 0));
    dis[0][0] = 0;

    while (que.size()) {
        P p = que.front(); que.pop();
        if (p.first == W - 1 && p.second == H - 1) break;
        for (int i = 0; i < 4; i++) {
            int nx = p.first + dx[i], ny = p.second + dy[i];
            if (nx >= 0 && nx < W && ny >= 0 && ny < H && maze[ny][nx] != '#' && dis[ny][nx] == INF) {
                que.push(P(nx, ny));
                dis[ny][nx] = dis[p.second][p.first] + 1;
            }
        }
    }

    if (dis[H - 1][W - 1] == INF) {
        cout << -1 << endl;
    }
    else {
        cout << (H * W) - wall - dis[H - 1][W - 1] - 1 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
n, y = gets.strip.split.map(&:to_i)
string = '-1 -1 -1'

catch Object do
  (n+1).times do |i|
    yen10 = 10000 * i
    (n - i + 1).times do |j|
      yen5 = 5000 * j
      k=n-i-j
      yen1 = 1000 * k
      if y == yen10 + yen5 + yen1 && n == i + j + k
        string = i.to_s + ' ' + j.to_s + ' ' + k.to_s
        throw Object
      end
    end
  end
end
puts string

Measured memory_bytes: 1788
#include<iostream>
using namespace std;
int main() {
    // ??¬???????????° ??????????£?????????????
    int official_house[4][3][10];
    // ?????????
    for (int i = 0; i < 4; i++) {
        for (int j = 0; j < 3; j++) {
            for (int k= 0; k < 10; k++) {
                official_house[i][j][k] = 0;
            }
        }
    }
    // ???????????°?????????????????°????????????
    int n;
    cin >> n;
    for (int it = 0; it < n; it++) {
        // ???????????????????????????
        int b,f,r,v;
        cin >> b >> f >> r >> v;
        official_house[b-1][f-1][r-1] += v;
    }
    // ???????????????
    for (int i = 0; i < 4; i++) {
        for (int j = 0; j < 3; j++) {
            for (int k= 0; k < 10; k++) {
                cout << " " << official_house[i][j][k];
            }
            cout << endl;
        }
        if (i != 3) {
            cout << "####################" << endl;
        }
    }
} 

Measured memory_bytes: 1160
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <string>
using namespace std;

int N;
int X[110], Y[110], H[110];
bool flag;

int main(){
	cin >> N;
	for (int i = 0; i < N; i++)
		cin >> X[i] >> Y[i] >> H[i];
	flag = false;
	for (int x = 0; x <= 100 && !flag; x++)
		for (int y = 0; y <= 100 && !flag; y++){
			int h = 0;
			flag = true;
			for (int i = 0; i < N; i++)
				if (H[i] > 0){
					if (h == 0)
						h = H[i] + abs(X[i] - x) + abs(Y[i] - y);
					else if (h != H[i] + abs(X[i] - x) + abs(Y[i] - y))
						flag = false;
				}
			for (int i = 0; i < N; i++)
				if (H[i] != max(h - abs(X[i] - x) - abs(Y[i] - y), 0))
					flag = false;
			if (h == 0)
				flag = false;
			if (flag)
				printf("%d %d %d\n", x, y, h);
		}
	assert(flag);
}

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

int main()
{    
    int N,A,B;

    scanf("%d",&N);
    if( N == 1 ){
        printf("Hello World\n");
        return 0;
    }

    scanf("%d",&A);
    scanf("%d",&B);
    printf("%d\n",A+B);
   
    return 0;
}

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

typedef struct{
	double x;
	double y;
}point;

int main()
{
	double x1, x2, x3, y1, y2, y3, xp, yp;
	while (cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> xp >> yp){
		vector<bool> vec(3, true);
		point points[] = { { x2 - x1, y2 - y1 }, { x3 - x2, y3 - y2 }, { x1 - x3, y1 - y3 } };
		point p_p[] = { { xp - x2, yp - y2 }, { xp - x3, yp - y3 }, { xp - x1, yp - y1 } };
		for (int i = 0; i < 3; i++){
			if (points[i].x * p_p[i].y - points[i].y * p_p[i].x > 0) vec[i] = false;
		}
		//cout << boolalpha << vec[0] << vec[1] << vec[2] << noboolalpha << endl;
		if (vec[0] * vec[1] * vec[2] || !(vec[0] + vec[1] + vec[2])) cout << "YES";
		else cout << "NO";
		cout << endl;
	}
}

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

int main(){
  int n;
  cin>>n;
  
  int count=0;
  for(int i=1;i<=n;i++){
    if(to_string(i).size()%2==1){
      count++;
    }
  }
  cout<<count<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner scanner = new Scanner(System.in);
		int a = scanner.nextInt();
		int b = scanner.nextInt();
		scanner.close();

		if (b * 2 < a) {
			System.out.println(a - b * 2);
		} else {
			System.out.println(0);
		}
	}
}


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

#define rep(i,n) for(ll i = 0; i < n; i++)
#define per(i,n) for(ll i = n-1; i >= 0; i--)
#define REP(i,n) for(ll i = 1; i < n; i++)
#define PER(i,n) for(ll i = n; i >= 1; i--)
#define sz(x) int(x.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define endl '\n'
#define fi first
#define se second
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vii = vector<vi>;
using vl = vector<ll>;
using vll = vector<vl>;
using vs = vector<string>;
using vb = vector<bool>;
using vc = vector<char>;
using vcc = vector<vc>;
using vP = vector<P>;
using vPP = vector<vP>;
using vPl = vector<Pl>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll &a, const ll &b){return ((a)+(b)-1)/b;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }



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

  int a, b;
  cin >> a >> b;
  cout << a*b << endl;
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
using namespace std;
const int MOD=1000000007;
const int nmax=3123;
int n;
ll dp[nmax],a[nmax],res;
char s[nmax];
int main(){
    scanf("%d",&n);
    scanf("%s",s+1);
    dp[1]=1;
    for(int i=2; i<=n; ++i){
        if(s[i-1]=='<'){
            for(int j=1; j<=i; ++j)a[j]=(a[j-1]+dp[j])%MOD;
            for(int j=1; j<=i; ++j)dp[j]=a[j-1];
        }
        else
        {
            for(int j=i-1; j>1; --j)a[j]=(a[j+1]+dp[j])%MOD;
            for(int j=i-1; j>0; --j){
                dp[j]+=a[j+1];
                dp[j]%=MOD;
            }
        }
    }
    for(int i=1; i<=n; ++i)res+=dp[i];
    res%=MOD;
    printf("%lld",res);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <limits>
#include <vector>
#include <map>
#include <cmath>
#include <limits>
#include <iomanip>
#include <queue>
#include <string.h>
#include <bitset>
#define ll long long int
#define ld long double
#define rep(i,n) for(int i = 0;i < n;i++)
#define rep1(i,n) for(int i = 1;i < n;i++)
#define co(x) cout << x << endl
#define cosp(x) cout << x << " "
#define all(x) x.begin(),x.end()
#define allr(x) x.begin(),x.end(),greater<int>()
#define P pair<ll,ll>
#define pb push_back
#define mp make_pair
#define MOD 1000000007
#define INF 1ll << 60
#define PI 3.14159265359

using namespace std;

int main(){
	ll n;
	ll s,t;
	cin >> n >> s >> t;
	if(n%12 == 0){
		cout << s << " " << t << endl;
	}
	else if(n%12 == 1){
		cout << s-t << " " << t << endl;
	}
	else if(n%12 == 2){
		cout << s-t << " " << s << endl;
	}
	else if(n%12 == 3){
		cout << -t << " " << s << endl;
	}
	else if(n%12 == 4){
		cout << -t << " " << s-t << endl;
	}
	else if(n%12 == 5){
		cout << -s << " " << s-t << endl;
	}
	else if(n%12 == 6){
		cout << -s << " " << -t << endl;
	}
	else if(n%12 == 7){
		cout << -(s-t) << " " << -t << endl;
	}
	else if(n%12 == 8){
		cout << t-s << " " << -s << endl;
	}
	else if(n%12 == 9){
		cout << t << " " << -s << endl;
	}
	else if(n%12 == 10){
		cout << t << " " << t-s << endl;
	}
	else if(n%12 == 11){
		cout << s << " " << -(s-t) << endl;
	}
	return 0;
}


Measured memory_bytes: 3120
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

using ll = long long;
const ll INF = 1e18L + 5;

vector<ll> pre; // preprocessing
// pre[mask] - score of group 'mask'
vector<ll> dp;

void rec(int i, const vector<int>& not_taken, ll score_so_far, int mask, int group) {
    if(i == (int) not_taken.size()) {
        dp[mask] = max(dp[mask], score_so_far + pre[group]);
        return;
    }
    rec(i + 1, not_taken, score_so_far, mask, group);
    rec(i + 1, not_taken, score_so_far, mask ^ (1 << not_taken[i]),
        group ^ (1 << not_taken[i]));
}

// O(2^n * n^2 + 3^n)

int main() {
    int n;
    scanf("%d", &n);
    vector<vector<ll>> in(n, vector<ll>(n));
    for(int i = 0; i < n; ++i) {
        for(int j = 0; j < n; ++j) {
            scanf("%lld", &in[i][j]);
        }
    }
    pre.resize(1 << n);
    // O(2^n * n^2)
    for(int mask = 0; mask < (1 << n); ++mask) {
        for(int i = 0; i < n; ++i) {
            if(mask & (1 << i)) {
                for(int j = i + 1; j < n; ++j) {
                    if(mask & (1 << j)) {
                        pre[mask] += in[i][j];
                    }
                }
            }
        }
    }
    // dp[mask] - best total score if we grouped rabbits from 'mask' already
    dp.resize(1 << n, -INF);
    dp[0] = 0;
    // O(2^n * n + 3^n)
    for(int mask = 0; mask < (1 << n); ++mask) {
        vector<int> not_taken;
        for(int i = 0; i < n; ++i) {
            if(!(mask & (1 << i))) {
                not_taken.push_back(i);
            }
        }
        rec(0, not_taken, dp[mask], mask, 0);
    }
    printf("%lld\n", dp[(1<<n)-1]);
}


Measured memory_bytes: 1280
import collections
a = int(input())
s = [input() for i in range(a)]
c = collections.Counter(s)
b = []
for myvalue in c.values():
    b.append(myvalue)

d = len(b)
ans = int(0)
for i in range(int(d)):
    if b[i] % 2 == 0:
        pass
    else:
        ans += 1
        
print(ans)
    


Measured memory_bytes: 24048
#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 < (b); ++i)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
struct Edge {
  ll to;
  ll cost;
};
int main() {
  int N, K;
  cin >> N >> K;
  vector<int> A(N);
  REP(i, N) cin >> A[i];
  int cnt = 1;
  int ans = 0;
  while (cnt < N) {
    cnt += K - 1;
    ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 640
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<stack>
#include<queue>
using namespace std;
int main()
{
	long long n, i;
	long long x, num, num1, num2, kk = 0, k;
	while (~scanf("%lld%lld", &n, &x))
	{
		if (n < 2) break;
		kk = 0;
		scanf("%lld", &num);
		if (num > x)
		{
			kk += (num - x);
			num = x;
		}
			
		
		num2 = num;
		for (i = 0; i < n - 1; i++)
		{
			scanf("%lld", &num1);
			if (num1 + num2 > x)
			{
				k = num1 + num2 - x;
				kk += k;
				if (k <= num1)
					num1 -= k;
				else
					num1 = 0;
			}
			num2 = num1;
		}
		printf("%lld\n", kk);
	}

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;



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

	string s, t;
	cin >> s >> t;
	int n = s.length(), i, j, k, ans = 0;
	for (i = 0; i < n; i++) {
		if (s[i] != t[i]) ans++;
	}
	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 3440
from sys import stdin
n = int(stdin.readline())
for i in range(1,n+1):
        x = i
        if x % 3 == 0 or x % 10 == 3:
            print('', i, end='')
            continue

        x //= 10
        while x != 0:
            if x % 10 == 3:
                print('', i, end='')
                break

            x //= 10
print()

Measured memory_bytes: 6748
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define double long double
#define pb push_back
#define endl '\n'
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
#define sz(a) (int)((a).size())
#define fuck() cout<<"--------"<<endl
#define see(x) cout<<#x<<" = "<<x<<endl
#define see2(x,y) cout<<#x<<" = "<<x<<"::"<<#y<<" = "<<y<<endl 
const int mod=1000000007;
typedef pair<int,int> pii;
const int N=1e5+5;
int nc2(int x){
	return x*(x-1)/2;
}
int32_t main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0);
	int n;
	cin>>n;
	int a[n];
	map<int,int>f;
	for(int i=0;i<n;i++){
		cin>>a[i];
		f[a[i]]++;
	}
	int ans=0;
	for(auto to:f){
		ans+=nc2(to.S);
	}
	// see(ans);
	for(int i=0;i<n;i++){
		int val=f[a[i]];
		if(val)cout<<ans-nc2(val)+nc2(val-1)<<endl;
		else cout<<ans<<endl;
	}
}

Measured memory_bytes: 11136
N, M, K = gets.split.map(&:to_i)
MOD = 998244353

result = 0

@fac = Array.new N+100
@inv = Array.new N+100
@finv = Array.new N+100

@fac[0] = @fac[1] = 1
@finv[0] = @finv[1] = 1
@inv[1] = 1

2.upto(N) do |i|
  @fac[i] = @fac[i-1] * i % MOD
  @inv[i] = (MOD - @inv[MOD % i] * (MOD / i)) % MOD
  @finv[i] = @finv[i - 1] * @inv[i] % MOD
end


def comb n, k
  raise if n < k 
  raise if n < 0 || k < 0
  return @fac[n] * (@finv[k] * @finv[n-k] % MOD ) % MOD
end

0.upto(K) do |k|
  result += M * comb(N-1, k) * (M-1).pow(N-1-k, MOD)
  result %= MOD
end

puts result

Measured memory_bytes: 19128
#include <bits/stdc++.h>
#define N 200010
using namespace std;
long long n,k,l,r,mid;
vector<long long> a,v;
bool check(long long x)
{
	long long ret=0,i;
	for(i=0;i<n;i++)
	{
		ret+=max((long long)0,a[i]-x/v[i]); 
	}
	if(ret<=k)
	{
		return true;
	}
	return false;
}
int main(){
	long long i,x;
	cin>>n>>k;
	for(i=0;i<n;i++)
	{
		cin>>x;
		a.push_back(x);
	}
	for(i=0;i<n;i++)
	{
		cin>>x;
		v.push_back(x);
	}
	sort(a.begin(),a.end());
	sort(v.begin(),v.end());
	reverse(v.begin(),v.end());
	l=0;
	r=2e12;
	while(l<r)
	{
		mid=(l+r)/2;
		if(check(mid))
		{
			r=mid;
		}
		else
		{
			l=mid+1;
		}
	}
	cout<<l<<endl;
	return 0;
}

Measured memory_bytes: 4848
# -*- coding: utf-8 -*-
from itertools import combinations
inf = 10**9
d,g = map(int, input().split())
pc = [list(map(int, input().split())) for _ in range(d)]

def score(comp):
    res = 0
    s = 0
    for i in comp:
        s += pc[i][1]
        s += pc[i][0]*100*(i+1)
        res += pc[i][0]

    if s>=g:
        return res

    for i in range(d-1,-1,-1):
        if i in comp:
            continue

        c = 0
        while c<pc[i][0]-1 and s<g:
            c += 1
            s += 100*(i+1)
        res += c

        if s>=g:
            return res
    return inf

res = inf
for r in range(d+1):
    for c in combinations(range(d),r):
        s = score(c)
        res = min(res, s)

print(res)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
 
#define pb push_back
#define fst first
#define snd second
#define INF 0x7fffffff
#define INFLL 0x7FFFFFFFFFFFFFFF
#define lenA(ar) sizeof(ar)/sizeof(*ar)
#define fill(a,c) memset(&a, c, sizeof(a))
#define fore(i,x,y) for(int i=x;i<y;i++)
#define foreI(i,x,y) for(int i=x-1;i>=y;i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define FIN ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define sl "\n";
#define ii pair<ll,ll>
#define mk make_pair
 
 
typedef long long ll;
typedef unsigned long long ull;
 
using namespace std;
string a,b;
const int MAXN = 3005;
ll dp[MAXN][MAXN];
int n,m;
string ans;
ll solve(int i,int j){
    if(i==n)return 0;
    if(j==m)return 0;
    ll &r = dp[i][j];
    if(r!=-1)return r;
    if(a[i]==b[j]){r=solve(i+1,j+1)+1;}
    else r=max(solve(i+1,j),solve(i,j+1));
    return r;
}
void build(int i,int j){
    if(i==n)return;
    if(j==m)return;
    ll answer = solve(i,j);
    if(a[i]==b[j]&&answer==solve(i+1,j+1)+1){ans.pb(a[i]);build(i+1,j+1);}
    else if(answer==solve(i+1,j)){build(i+1,j);}
    else if(answer==solve(i,j+1)){build(i,j+1);}
    return;
}
int main() {FIN;
   
    cin>>a>>b;
    n=a.size();
    m=b.size();
    memset(dp,-1,sizeof(dp));
    solve(0,0);
    build(0,0);
    cout<<ans<<sl;
    return 0;
}
 

Measured memory_bytes: 74440
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.IO;

namespace AtCoder
{
    class Program
    {
        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }

        static void Main(string[] args)
        {
            int[] values = ReadInts();
            int A = values[1];
            int B = values[2];
            Console.WriteLine(((B - A) & 1) == 0 ? "Alice" : "Borys");
        }
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;

#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define range(i,a,n) for(ll i=(a);i<(n);i++)

#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI 3.1415926535897932384

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

template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S acm(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
void YN(bool b){cout<<(b?"YES":"NO")<<"\n";}
void Yn(bool b){cout<<(b?"Yes":"No")<<"\n";}
void yn(bool b){cout<<(b?"yes":"no")<<"\n";}
int sgn(const double&r){return (r>EPS)-(r<-EPS);} // a>0  : sgn(a)>0
int sgn(const double&a,const double&b){return sgn(a-b);} // b<=c : sgn(b,c)<=0

ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s;a=0;} return os;}

struct UnionFind{
    vl par,dist;
    UnionFind(int x){par.assign(x,-1); dist.assign(x,0);}
    ll find(ll x){return par[x]<0?x:find(par[x]);}
    ll depth(ll x){return par[x]<0?0:depth(par[x])+dist[x];}
    bool same(ll x,ll y){return find(x)==find(y);}
    ll size(ll x){return -par[find(x)];}
    ll diff(ll x,ll y){return same(x,y)?depth(x)-depth(y):LINF;}
    void unite(ll x,ll y,ll k=0){
        k+=depth(y); k-=depth(x); k=-k;
        x=find(x); y=find(y);
        if(x==y)return;
        if(size(x)<size(y)){swap(x,y);k=-k;}
        par[x]+=par[y]; par[y]=x; dist[y]=k;
    }
};

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n,m,k;
	cin>>n>>m>>k;
	vl a(m),b(m),c(k),d(k);
	rep(i,m)cin>>a[i]>>b[i],a[i]--,b[i]--;
	rep(i,k)cin>>c[i]>>d[i],c[i]--,d[i]--;
	UnionFind u(n);
	rep(i,m)u.unite(a[i],b[i]);
	vl ans(n);
	rep(i,n)ans[i]=u.size(i)-1;
	rep(i,m){
		if(u.same(a[i],b[i])){
			ans[a[i]]--;
			ans[b[i]]--;
		}
	}
	rep(i,k){
		if(u.same(c[i],d[i])){
			ans[c[i]]--;
			ans[d[i]]--;
		}
	}
	puta(ans);
}


Measured memory_bytes: 7168
#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 MAX_N = 100005;
const ll MOD = 1e9+7;
ll dp[MAX_N][2];

int main()
{
	string L;
	cin >> L;
	int N = L.size();
	dp[0][0] = 2; dp[0][1] = 1;
	rep(i,N-1)
	{
		if (L[i+1] == '1')
		{
			dp[i+1][0] += dp[i][0] * 2;
			dp[i+1][0] %= MOD;
			dp[i+1][1] += dp[i][1] * 3 + dp[i][0];
			dp[i+1][1] %= MOD;
		}
		else
		{
			dp[i+1][0] += dp[i][0];
			dp[i+1][0] %= MOD;
			dp[i+1][1] += dp[i][1] * 3;
			dp[i+1][1] %= MOD;
		}
	}
	cout << (dp[N-1][0] + dp[N-1][1]) % MOD << endl;
	return 0;
}

Measured memory_bytes: 2048
n,m=map(int,input().split())
a = list(map(int,input().split()))
bc=[list(map(int,input().split())) for i in [0]*m]
a.sort()
bc.sort(key=lambda x: x[1], reverse=True)  
i=0
for b,c in bc:
    for j in range(i,min(n,i+b)):
        if a[j] < c:
            a[j] = c
            i+=1
        else:
            break
print(sum(a))

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

using namespace std;

int main(void){
  string s;
  long long a;
  cin >> s;
  for(int i = 0; i < s.length(); i++) a += (s[i] - '0');
  if(a % 9 == 0) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 3660
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
char maze[20][20];
int way[20][20];
int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};
int H,W;
queue<P> que;

int kazu(){
    
    int mis=0;
    
    
    while(que.size()){
        P p=que.front();
        que.pop();
        int y=p.first;
        int x=p.second;
        for(int i=0;i<4;i++){
            int ny=y+dy[i];
            int nx=x+dx[i];
            if(0<=ny&&ny<H&&0<=nx&&nx<W&&maze[ny][nx]=='.'&&way[ny][nx]==-1){
                que.push(P(ny,nx));
                way[ny][nx]=way[y][x]+1;
            }
        }
    }
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            int op=fabs(way[i][j]);
            mis=max(mis,op);
        }
    }
    return mis;
}
int main(){
    cin>>H>>W;
    int sai=0;
    for(int i=0;i<20;i++){
        for(int j=0;j<20;j++)way[i][j]=-1;
    }
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            cin>>maze[i][j];
        }
    }
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            
            if(maze[i][j]=='.'){
                que.push(P(i,j));
                for(int a=0;a<20;a++){
                    for(int b=0;b<20;b++)way[a][b]=-1;
                }
                way[i][j]=0;
                sai=max(sai,kazu());
            }
        }
    }
    cout<<sai<<endl;
}





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

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

    vector<array<int, 3> > input;
    for (int i = 0; i < n; i++) {
        int t1, t2, t3;
        cin >> t1 >> t2 >> t3;
        input.push_back({t1, t2, t3});
    }

    for (int i=1;i<n;i++) {
        int m0, m1, m2;
        m0 = max(input[i-1][1], input[i-1][2]);
        m1 = max(input[i-1][2], input[i-1][0]);
        m2 = max(input[i-1][0], input[i-1][1]);

        input[i][0] += m0;
        input[i][1] += m1;
        input[i][2] += m2;
    }

    cout << *max_element(input[n-1].begin(), input[n-1].end()) << endl;
    return 0;
}

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

int main(){
    int n; cin >> n;
    vector<string> s(n);
    vector<int> t(n);
    rep(i,n) cin >> s[i] >> t[i];
    string x; cin >> x;
    
    int ans = 0;
    bool b = false;
    rep(i,n){
        if(b) ans += t[i];
        if(s[i] == x){
            b = true;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String line = sc.nextLine();
    String data[] = line.split("");
    int sum = 0;
    for(int i = 0;i < data.length;i++){
      int num = Integer.parseInt(data[i]);
      sum += num;
    }
    if(sum % 9 == 0){
      System.out.println("Yes");
    }
    else{
      System.out.println("No");
    }
  }
}

Measured memory_bytes: 65968
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int a = input .nextInt();
        int b = input.nextInt();
        if (a < b) {
            System.out.println("a < b");
        }
        else if (a > b) {
            System.out.println("a > b");
        }
        else {
            System.out.println("a == b");
        }
    }
}


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

//関数
    //const long INF=1000000000000000;
    
//main関数
int main() {
    
    
    //入力
    long N;
    cin>>N;
    vector<long> P(N);
    for(int i=0;i<N;i++){
        cin>>P.at(i);
    }
    
    
    
    
    
    //計算
    
    vector<long> pos(N+1);
    for(int i=0;i<N;i++){
        pos.at(P.at(i))=i;
    }
    
    long still=1,tempstill=1;
    for(int k=2;k<=N;k++){
        if(pos.at(k-1)<pos.at(k)){
            tempstill++;
        }else{
            tempstill=1;
        }
        
        still=max(still,tempstill);
    }
    
    //出力
    cout<<N-still<<endl;
}

Measured memory_bytes: 3328
import java.util.*;

public class Main {
  public static int N;
  public static ArrayList<Long> list = new ArrayList<>();

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    N = sc.nextInt();
    dfs(0L);
    int count = 0;
    for (int i = 0; i < list.size(); i++) {
      long num = list.get(i);
      String s_num = Long.toString(num);
      if (num <= N && s_num.contains("3") && s_num.contains("5") && s_num.contains("7")) {
        count++;
      }
    }
    System.out.println(count);
  }

  public static void dfs(long n) {
    if (n >= 1000000000) {
      return;
    }
    list.add(n);
    dfs(n * 10 + 3);
    dfs(n * 10 + 5);
    dfs(n * 10 + 7);
  }
}


Measured memory_bytes: 25008