akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using ll = long long;
using namespace std;
const int INFint = 2e9+1;
const ll INFll = 2e18+1;

int main(){
  int A,B,Q;
  cin>>A>>B>>Q;
  vector<ll> 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];
  }
  sort(s.begin(),s.end());
  sort(t.begin(),t.end());

  for(int i(0);i<Q;i++){
    ll mt,ht,mz,hz;
    auto mti = lower_bound(t.begin(),t.end(),x[i]);
    if(mti == t.end()){
      mt = (ll)1e18;
      ht = *(mti-1);
    }else{
      mt = *mti;
      if(mti == t.begin()) ht = -1e18;
      else ht = *(mti-1);
    }
    
    auto mzi = lower_bound(s.begin(),s.end(),x[i]);
    if(mzi == s.end()){
      mz = (ll)1e18;
      hz = *(mzi-1);
    }else{
      mz = *mzi;
      if(mzi == s.begin()) hz = -1e18;
      else hz = *(mzi-1);
    }


    //cout << mt << " " << mz <<" "<<ht<<" " << hz<< endl;
    ll tmp1(max(mt,mz)-x[i]),tmp2(x[i]-min(ht,hz)),tmp3(mt-x[i]+x[i]-hz+min(mt-x[i],x[i]-hz)),tmp4(mz-x[i]+x[i]-ht+min(mz-x[i],x[i]-ht));
    //cout << tmp1 <<" "<< tmp2 <<" "<< tmp3 <<" "<< tmp4 << endl;
    cout << min({tmp1,tmp2,tmp3,tmp4}) << endl;
  }
  return 0;
}


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

#define ll long long
#define vecll vector<long long>
#define vec2ll vector<vector<long long>>
#define vecbool vector<bool>
#define vecpairll vector<pair<long long,long long>>
#define forll(s,a,b) for(long long s = a;s < b;s++)
#define forllde(s,a) for(long long s = a;s > 0;s--)


int main()
{
  ll c=0;
  string s;
  cin >> s;
  vecll l(s.size() + 1, 0);
  vecll r(s.size() + 1, 0);
  forll(i, 1, s.size() + 1){
	if (s[i-1] == '<')
	  l[i] = l[i-1] + 1;
  }
  for (int i=s.size() - 1; i>=0; i--){
	if (s[i] == '>')
	  r[i] = r[i + 1] + 1;
  }
  forll(i, 0, s.size() + 1)
	c += max(l[i], r[i]);
  cout << c << endl;
}

Measured memory_bytes: 8708
package main

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

func main() {
        fmt.Println(run(os.Stdin))
}

func run(in io.Reader) string {
        sc := bufio.NewScanner(in)

        sc.Scan()
        n, err := strconv.Atoi(sc.Text())
        if err != nil {
                panic(err)
        }

        sc.Scan()
        arrs := strings.Split(sc.Text(), " ")
        arr := make([]int, n)
        for i, v := range arrs {
                if arr[i], err = strconv.Atoi(v); err != nil {
                        panic(err)
                }
        }

        return insertionSort(n, arr)
}

func insertionSort(n int, arr []int) string {
        buf := new(bytes.Buffer)

        print(buf, arr, n != 1)

        for i := 1; i < n; i++ {
                v := arr[i]
                j := i - 1
                for ; j >= 0 && arr[j] > v; j-- {
                        arr[j+1] = arr[j]
                }
                arr[j+1] = v
                print(buf, arr, i < n-1)
        }

        return buf.String()
}

func print(b io.Writer, arr []int, nl bool) {
        for i, v := range arr {
                if i > 0 {
                        fmt.Fprintf(b, " ")
                }
                fmt.Fprintf(b, "%d", v)
        }
        if nl {
                fmt.Fprintf(b, "\n")
        }
}



Measured memory_bytes: 1412
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int a=sc.nextInt();
		String op=sc.next();
		int b=sc.nextInt();
		if(op.equals("+")){
			System.out.println(a+b);
		}
		else{
			System.out.println(a-b);
		}
	}
}

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

using namespace std;

typedef long long int ll;

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(a) a.begin(), a.end()
#define sz(a) (ll)(a.size())
#define endl "\n"

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    
    ll N;
    ll ans = 0;

    cin >> N;

    for(ll i=0; i<N; i++)
    {
        ll a;
        cin >> a;

        ans = __gcd(ans, a);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
//header{{{
#include<bits/stdc++.h>
  
using namespace std;
 
#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define setout(n,x) setw(n) << setfill(x)
#define Fixed fixed << setprecision(10)
#define int long long
using pii = pair<int,int>;
constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod = 1e9+7; 
 
int gcd(int a,int b){ return b ? gcd(b,a % b) : a;}
int lcm(int a,int b){ return a / gcd(a,b) * b;}
//}}}

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int a,b;
	cin >> a >> b;
	if(a < 10 && b < 10) cout << a * b << '\n';
	else cout << -1 << '\n';	
	return 0;
}


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

int main(){
  int N;
  int a[4];
  cin>>N;
  for(int i=0;i<4;i++){
    a[i]=N%10;
    N=N/10;
  }
  if((a[0]==a[1]&&a[1]==a[2])||(a[3]==a[2]&&a[1]==a[2])){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
}

Measured memory_bytes: 256
import sys
import math

def str_input():
    S = raw_input()
    if S[len(S)-1] == "\r":
        return S[:len(S)-1]
    return S

def float_to_str(num):
    return str("{:.10f}".format(num))

x1, y1, x2, y2 = map(float, str_input().split())

dx = x2 - x1
dy = y2 - y1
print float_to_str(math.sqrt(dx*dx + dy*dy))

Measured memory_bytes: 6468
/*
 * zyrch - Rupanshu Yadav
 */
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <fstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <utility>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <cassert>
#include <sstream>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef double db;
typedef string str;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<ld> vd;
typedef vector<str> vs;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL) 

#define forn(i,a,b) for (int i = (a); i < ll(b); ++i)
#define fo(i,a) forn(i,0,ll(a))
#define rforn(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define ro(i,a) rforn(i,0,a)
#define trav(a,x) for (auto& a: x)

#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define rsz resize
#define ins insert

#define mp make_pair
#define pb push_back
#define eb emplace_back
#define f first
#define s second

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

const ll INF = 1e18;

ll mod = 1000000007;
inline ll fast_expo(ll base,ll power,ll modulo=mod){
    base%=modulo;
    if (base<0) base+=modulo;
    ll x=base,cnt=power,ans=1;
    while(cnt){
        if (cnt&1) ans=(ans*x)%modulo;
        x=(x*x)%modulo;
        cnt>>=1;
    }
    return ans;
}

ll takemod(ll a, ll mo){
	a %= mo;
	if(a < 0) a+=mo;
	return a;
}

// if mod is prime
ll modinv(ll a, ll mo){
	return takemod(fast_expo(takemod(a,mo), mo-2, mo), mo);
}

//=========================CODE STARTS HERE=============================//

int main() {
	fast_cin();
	ll x;
	ll n;
	cin >> n;
	vl arr(n + 1, 0);
	fo(i, n - 1) {
		cin >> x;
		arr[x]++;
	}
	
	fo(i, n){ 
		cout << arr[i + 1] << " ";}
	
	
	return 0; 
}


Measured memory_bytes: 4748
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define len(v) ll(v.size())
#define fi first
#define se second

template <class T>
void cout_vec(const vector<T> &vec){
  for(auto itr:vec) cout<<itr<<' ';
  cout<<endl;
}

template <class T>
void cout_vec2(const vector<vector<T>> &vec){
  rep(i,vec.size()){
    rep(j,vec[i].size()){
      cout<<vec[i][j]<<' ';
    }
    cout<<endl;
  }
}

typedef pair<ll,ll> P;
const ll mod=1e9+7;
const ll inf=1e15;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n,k,x,y;
  cin>>n>>k>>x>>y;
  int now=0;
  rep(i,n){
   if(i<k) now+=x;
   else now+=y;
  }
  cout<<now<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define chmin(a,b) a=min(a,b)
using namespace std;
const int INF = 1e7;

struct edge{
  int to, cap, cost, rev;
  edge(int a,int b,int c,int d):to(a),cap(b),cost(c),rev(d){}
};
typedef vector< vector<edge> > graph;

void add_edge(graph &g, int s, int t, int cap, int cost){
  g[s].push_back(edge(t,cap,cost,g[t].size()));
  g[t].push_back(edge(s,0,-cost,g[s].size()-1));
}

int Optimize(int digit, int alpha, const vector<int> &cost){
  graph g(38);
  for(int i=0;i<10;i++){
    for(int j=0;j<26;j++){
      if(cost[j*10+i]!=INF){
	add_edge(g,i+1,j+11,1,cost[j*10+i]);
      }
    }
  }

  int base = 0;
  for(int i=0;i<10;i++){
    add_edge(g,0,i+1,100,0);
    if( (digit>>i)&1 )add_edge(g,0,i+1,1,-INF), base += INF;
  }

  for(int i=0;i<26;i++){
    add_edge(g,i+11,37,100,0);
    if( (alpha>>i)&1 )add_edge(g,i+11,37,1,-INF), base += INF;
  }

  int res = INF, sum = 0;
  vector<int> prevv(38),preve(38);
  for(;;){
    vector<int> d(38,INF), inQ(38,0);
    queue<int> q;
    d[0] = 0; q.push(0); inQ[0] = 1;

    while(q.size()){
      int v = q.front(); q.pop(); inQ[v] = 0;

      for(int i=0;i<(int)g[v].size();i++){
	edge &e = g[v][i];
	if(e.cap > 0 && d[e.to] > d[v] + e.cost){
	  d[e.to] = d[v] + e.cost;
	  if(!inQ[e.to])q.push(e.to), inQ[e.to] = 1;
	  prevv[e.to] = v;
	  preve[e.to] = i;
	}
      }
    }

    if(d[37] == INF)break;

    sum += d[37];
    chmin(res, sum + base);
    for(int v=37;v!=0;v=prevv[v]){
      edge &e = g[prevv[v]][preve[v]];
      e.cap--;
      g[v][e.rev].cap++;
    }
  }

  return res;
}

int main(){
  int n,m;

  scanf("%d",&n);
  vector<int> door(260,0), card(260,INF);
  for(int i=0;i<n;i++){
    char a; int b;
    scanf(" %c %d",&a,&b);
    door[(int)(a-'A')*10+b] = 1;
  }

  scanf("%d",&m);
  for(int i=0;i<m;i++){
    char c; int d,e;
    scanf(" %c %d%d",&c,&d,&e);
    card[(int)(c-'A')*10+d] = min(card[(int)(c-'A')*10+d], e);
  }

  int ans = INF;
  for(int digit=0;digit<(1<<10);digit++){
    int alpha = 0;
    for(int i=0;i<10;i++){
      if( ((digit>>i)&1) == 0){
	for(int j=0;j<26;j++){
	  alpha |= door[j*10 + i]<<j;
	}
      }
    }
    ans = min(ans,Optimize(digit,alpha,card));
  }
  
  if(ans==INF)puts("-1");
  else printf("%d\n",ans);
}

Measured memory_bytes: 1200
import sys
S=input()
S_bef=S[0:int((len(S)-1)/2)]
S_aft=S[int((len(S)+3)/2)-1:]
if S==S[::-1]:
  if S_bef==S_bef[::-1]:
    if S_aft==S_aft[::-1]:
      print("Yes")
      sys.exit()
print("No")

Measured memory_bytes: 3060
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>

#define int long long
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(a) (a).begin(), (a).end()
#define PB push_back
#define MP make_pair
#define FST first
#define SND second
#define SZ(a) (signed)((a).size())
#define EACH(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())

using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;

const int MOD = 1000000007;
const char ENDL = '\n';

#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")"  << " " << __FILE__ << endl;

signed main(void) {
    ios::sync_with_stdio(false);
    cout.setf(ios::fixed, ios::floatfield);
    cout.precision(10);
    cin.tie(0);

    VI a(3);
    REP(i,3){
        cin >> a[i];
    }

    SORT(a);
    a.erase(unique(ALL(a)),a.end());

    cout << a.size() << ENDL;
    
    return 0;
}

Measured memory_bytes: 256
import itertools
N,Ma,Mb=map(int,input().split())

abclist=[]
sum_a=sum_b=0
for _ in range(N):
  a,b,c=map(int,input().split())
  sum_a+=a
  sum_b+=b
  abclist.append((a,b,c))
#print(abclist)

dp=[[[float("inf")]*(sum_b+1) for _ in range(sum_a+1)] for _ in range(N+1)]
dp[0][0][0]=0
for i in range(1,N+1):
  a,b,c=abclist[i-1]
  for j in range(sum_a+1):
    for k in range(sum_b+1):
      dp[i][j][k]=dp[i-1][j][k]
      if j-a>=0 and k-b>=0:
        dp[i][j][k]=min(dp[i][j][k],dp[i-1][j-a][k-b]+c)
        
#print(dp[N])
Ma_orig=Ma
Mb_orig=Mb
answer=float("inf")
while Ma<=sum_a and Mb<=sum_b:
  answer=min(answer,dp[N][Ma][Mb])
  Ma+=Ma_orig
  Mb+=Mb_orig
  
if answer==float("inf"):
  print(-1)
else:
  print(answer)

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

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

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

    vector<long long int> a(n);
    for(int i=0; i<n; i++){
        cin >> a[i];
    }
    sort(a.begin(),a.end());

    long long int x = a[0];
    for(int i=0; i<n; i++){
        x = gcd(x, a[i]);
    }

    if(k > a[n-1] || (a[n-1] - k) % x != 0) cout << "IMPOSSIBLE" << endl;
    else cout << "POSSIBLE" << endl;
    return 0;
}

Measured memory_bytes: 4004
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(void){
  int i,j;
  int n,a=0,b=0,c=0;
  char s[10];
  scanf("%s",s);
  for(i=0;i<3;i++){
    if(s[i]=='a') a++;
    if(s[i]=='b') b++;
    if(s[i]=='c') c++;
  }
  if(a==1 && b==1 && c==1)
    printf("Yes\n");
  else
    printf("No\n");
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int n,a[57],cnt[57],b[57],now=0;
void dfs(int pos)
{
	if (pos>n)
	{
		for (int i=1;i<=n;i++)
			b[i]=a[i];
		sort(b+1,b+n+1);
		int res=30;
		for (int i=1;i<n;i++)
			res=min(res,b[i+1]-b[i]);
		res=min(res,min(b[n]-b[1],24-b[n]+b[1]));
		now=max(now,res);
	} else
	{
		if (a[pos]!=0&&a[pos]!=12)
		{
			a[pos]=24-a[pos];
			dfs(pos+1);
			a[pos]=24-a[pos];
		}
		dfs(pos+1);
	}
}
int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	memset(cnt,0,sizeof(cnt));
	++cnt[0];
	for (int i=1;i<=n;i++)
		++cnt[a[i]];
	++n;
	a[n]=0;
	for (int i=0;i<=12;i++)
	{
		if ((i==0||i==12)&&cnt[i]>1)
		{
			cout << 0 << endl;
			return 0;
		}
		else if (cnt[i]>2)
		{
			cout << 0 << endl;
			return 0;
		}
	}
	dfs(1);
	printf("%d\n",now);
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <numeric>

using namespace std;
typedef long long ll;

int main(){

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

  for (int i = 0; i < 5; i++){
    for (int j = i + 1; j < 5; j++){
      if ((a[j] - a[i]) > a[5]){
        cout << ":(" << endl;
        return 0;
      }
    }
  }

  cout << "Yay!" << endl;

  return 0;
}


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

using namespace std;

int main(){
    int w, n, a, b;
    vector<pair<int, int>> h_lines;
    cin >> w >> n;
    vector<int> res(w+1);
    while(scanf("%d,%d",&a,&b)+1){
     h_lines.push_back(pair<int, int>(a,b));   
    }
    
    
    for (int i = 1; i <= w; ++i){
        int where = i;
        for (auto line:h_lines){
            if (line.first == where){
                where = line.second;
            } else if (line.second == where){
                where = line.first;
            }
        }
        res[where] = i;
    }
    
    for (auto itr = res.begin()+1; itr != res.end(); ++itr){cout << *itr << "\n";}
    
 return 0;   
}

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

typedef long long int int64;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))

void run(void){
  int a,b,c,d;
  scanf("%d%d%d%d",&a,&b,&c,&d);
  printf("%d\n",(a-c)*(b-d));
}

int main(void){
  run();
  return 0;
}

Measured memory_bytes: 128
N,K=map(int, input().split())
P=998244353
S=[tuple(map(int,input().split())) for _ in range(K)]

f=[0]*(10**6)
f[0]=1
for i in range(N):
  for l, r in S:
    f[i+l] += f[i]
    f[i+l]%=P
    f[i+r+1]-=f[i]
    f[i+r+1]%=P
  if i:
    f[i+1]+=f[i]
  f[i]%=P
print(f[N-1])

Measured memory_bytes: 29336
def z_algo(S):
    N = len(S)

    A = [0] * N
    A[0] = N
    i = 1
    j = 0

    while i < N:
        while i + j < N and S[j] == S[i + j]:
            j += 1
        if not j:
            i += 1
            continue
        A[i] = j
        k = 1
        while N - i > k < j - A[k]:
            A[i + k] = A[k]
            k += 1
        i += k
        j -= k
    return A


N = int(input())
S = input()

ans = 0
for i in range(N):
    A = z_algo(S[i:])
    for idx, ls in enumerate(A):
        if idx - ls >= 0:
            ans = max(ans, ls)

print(ans)


Measured memory_bytes: 49756
#include <iostream>
#include <string>
#include <iomanip>
#include <math.h>
#include <vector>
#include <map>

using namespace std;

int main()
{
  string S;
  cin >> S;

  for (int i = 0; i < (int)S.size()-1; ++i)
  {
    if (S[i] == S[i + 1])
    {
      cout << "Bad" << endl;
      return 0;
    }
  }
  cout << "Good" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/range/irange.hpp>
#include <boost/range/adaptors.hpp>

using namespace std;
using namespace boost;
using namespace boost::adaptors;
using uint = unsigned int;
using ll = long long int;
using ull = unsigned long long int;

int main() {
    string s;
    cin >> s;
    ll a, z;
    for (auto &&i: irange(0LL, (ll)s.size())|reversed){
        if (s.at(i) == 'A') a = i;
    }
    for (auto &&i: irange(0LL, (ll)s.size())){
        if (s.at(i) == 'Z') z = i;
    }
    cout << z - a + 1 ;
    return 0;
}

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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod =(1e9)+7;
using P = pair<ll,ll>;

int main(){
    ll n;cin >>n;
    vector<ll>a(n);
    for (int i = 0; i < n; ++i) {
        cin>>a[i];
        a[i]--;
    }
    ll ans=0;
    for (int i = 0; i < n; ++i) {
        if(a[a[i]]==i)ans++;
    }
    cout <<ans/2 <<endl;
    return 0;
}



Measured memory_bytes: 1024
# -*- coding: utf-8 -*-
# keyence2020/keyence2020_c
import sys

s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in list(ss)]
ss2nnn = lambda ss: [s2nn(s) for s in list(ss)]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [i2s() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

def main():
    N, K, S = i2nn()
    if S == 10**9:
        print(*([S] * K + [S-1] * (N - K)))
    else:
        print(*([S] * K + [S+1] * (N - K)))
    return

main()


Measured memory_bytes: 5844
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#include <cstring>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int, int>> vpii;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
typedef vector<vector<ll>> vvll;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define irep(it, stl) for (auto it = stl.begin(); it != stl.end(); it++)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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;
}
struct io
{
    io()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
};
const int INF = INT_MAX;
const ll LLINF = 1LL << 60;
const ll MOD = 1000000007;
const double EPS = 1e-9;

signed main() {
    
    ll n;
    cin >> n;
    vll a(n);
    rep (i, n) cin >> a[i];
    
    rep (i, n) {
        if (a[i] % 2 == 0 && a[i] % 3 != 0) {
            if (a[i] % 5 != 0) {
                cout << "DENIED";
                return 0;
            }
            
        }
    }
    
    
    cout << "APPROVED";

}


Measured memory_bytes: 3636
import std.stdio;
import std.array;
import std.string;
import std.conv;
import std.algorithm;
import std.typecons;
import std.range;
import std.random;
//import std.math;
import std.container;
import std.numeric;
import std.bigint;
import core.stdc.stdlib;


alias Tuple!(int, "lower", int, "upper") bound;
int N, K;
int[][] adj;
bound[] nums;
int[] ans;


bound bfs(int node, int prev, bound b) {
  if (nums[node].lower != int.min &&
      b.lower != int.min &&
      (b.lower > nums[node].upper ||
       b.upper < nums[node].lower ||
       abs(b.upper%2) != abs(nums[node].upper%2))) {
    //writeln(node, " ", b, " ", nums[node]);
    //writeln(nums);
    writeln("No");
    exit(0);
  }
  nums[node].lower = max(nums[node].lower, b.lower);
  nums[node].upper = min(nums[node].upper, b.upper);

  foreach (child; adj[node]) {
    if (child == prev) continue;
    auto ret_b = bfs(child, node, bound(nums[node].lower-1, nums[node].upper+1));
    if (nums[node].lower != int.min &&
        ret_b.lower != int.min &&
        (ret_b.lower > nums[node].upper+1 ||
         ret_b.upper < nums[node].lower-1 ||
         abs(ret_b.upper%2) == abs(nums[node].upper%2))) {
      //writeln(child, " ", ret_b, " ", nums[node]);
      //writeln(nums);
      writeln("No");
      exit(0);
    }
    nums[node].lower = max(nums[node].lower, ret_b.lower-1);
    nums[node].upper = min(nums[node].upper, ret_b.upper+1);
  }
  return nums[node];
}


void dfs(int node, int prev, int prev_n) {
  if (nums[node].lower == nums[node].upper)
    ans[node] = nums[node].lower;
  else if (prev_n + 1 <= nums[node].upper)
    ans[node] = prev_n + 1;
  else
    ans[node] = prev_n - 1;

  foreach (child; adj[node])
    if (child != prev)
      dfs(child, node, ans[node]);
}

void main() {
  N = readln.chomp.to!int;
  adj = new int[][](N);
  foreach (i; 0..N-1) {
    auto input = readln.split.map!(to!int);
    adj[input[0]-1] ~= input[1]-1;
    adj[input[1]-1] ~= input[0]-1;
  }
  K = readln.chomp.to!int;
  nums = new bound[](N);
  foreach (i; 0..N) nums[i] = bound(int.min, int.max);
  int root;
  foreach (i; 0..K) {
    auto input = readln.split.map!(to!int);
    nums[input[0]-1] = bound(input[1], input[1]);
    root = input[0]-1;
  }

  bfs(root, -1, bound(int.min, int.max));

  ans = new int[](N);
  dfs(root, -1, nums[root].lower);
  "Yes".writeln;
  ans.each!(writeln);
}


Measured memory_bytes: 32380
# ABC103 B-StringRotation
S = [s for s in input()]
T = input()
S_ = []
S_Jugde = ""

for i in range(len(S)):
    S_ = S[:]
    for j in range(len(S)-1):
        if j == 0:
            S[0] = S_[len(S)-1]
        S[j+1] = S_[j]

        if j == len(S)-2:
            S_Jugde = "".join(S)
            if S_Jugde == T:
                print("Yes")
                exit()
print("No")

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

#define ll long long int 
ll mod=1e9+7;

// vector<int> g[200005];
// int vis[200005];
// queue<int> q;
// int level[200005];

// void dfs(int i)
// {
//     vis[i] = 1;
//     for(int j=0;j<g[i].size();j++)
//     {
//         int child = g[i][j];
//         if(vis[child] == 0)
//         {
//             dfs(child);
//         }
//     }
// }

// void bfs(int i)
// {
//     vis[i] = 1;
//     while(!q.empty())
//     {
//         int top = q.front();
//         int len_adj = g[top].size();
//         int j;
//         for(j=0;j<len_adj;j++)
//         {
//             int v = g[top][j];
//             if(vis[v]==0)
//             {
//                 vis[v]=1;
//                 q.push(v);
//                 level[v] = level[top] + 1;
//             }
//         }   
//         q.pop();
//     }
// }

ll modular_exponentiation(ll base, ll power)
{
    ll ans = 1;
    base = base % mod;
    while (power > 0)
    {
        if (power & 1)
        {
            ans = (ans * base) % mod;
        }

        power /= 2;
        base = (base * base) % mod;
    }
    return ans;
}

int main()
{
    /* Faster input ouput */
    // ios_base::sync_with_stdio(false);
    // cin.tie(NULL);
    // cout.tie(NULL);

    /* To read input from a file and output to a file */
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
    
    int t = 1;
    // cin >> t;
    while(t--)
    {        
        ll n,i,j;
        cin >> n;
        // ll arr[n];
        ll ans = 0;

        for(i=1;i<=n;i++)
        {
            if(i % 3 != 0 && i%5 != 0)
            {
                ans += i;
            }
            
        }

        cout << ans << '\n';
    }

    
    
}

Measured memory_bytes: 3636
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define swap(type,a,b) do{type t=a;a=b;b=t;}while(0);
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define ll long long
#define INF 100000000
#define FOR(i,a,n) for(i=a;i<n;i++)
int comp(const void* a,const void* b){
	return *(int*)a-*(int*)b;
}
void fill(int a[],int b,int c){
	int i;
	FOR(i,0,b) a[i]=c;
	return;
}
char str[101];
char s[101];
int len;
int solve(char c){
	int flag=0,cnt=0,i;
	while(1){
		flag=1;
		for(i=0;s[i+1]!='\0';i++){
			if(s[i]!=c||s[i+1]!=c) flag=0;
			if(s[i+1]==c) s[i]=c; 
		}
		if(flag) break;
		s[i]='\0',cnt++;
	}
	return cnt;
}
int main(void)
{
	int res=INF,t,i;
	scanf("%s",str);
	len=strlen(str);
	FOR(i,0,26){
		strcpy(s,str);
		t=solve('a'+i);
		res=MIN(res,t);
	}
	printf("%d\n",res);
	return 0;
}
    

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

int N,A[100];

inline void Initial() {
  std::ios::sync_with_stdio(false);
  cout.tie(0); cin.tie(0);
}
inline void Input() {
  cin>>N;
  for (int i=0; i<N; i++) {
    cin>>A[i];
  }
}
inline void Output() {
  for (int i=0; i<N; i++) {
    if (i) {
      cout<<" "<<flush;
    }
    cout<<A[i]<<flush;
  }
  cout<<endl;
}
inline void InsertionSort() {
  Output();
  for (int i=1; i<N; i++) {
    int storage=A[i];
    int j=i-1;
    while (j>=0 and A[j]>storage) {
      A[j+1]=A[j];
      j--;
    }
    A[j+1]=storage;
    Output();
  }
}
int main() {
  Initial(),Input(),InsertionSort();
  return 0;
}


Measured memory_bytes: 3192
#include <iostream>
#include <string>
#include <cmath>
using namespace std;


int main()
{
	string a, b;

	cin >> a >> b;
	string s = a + b;
	int n = stoi(s);

	double r = sqrt(n);
	double decimalPart = r - (int)r;
	if (decimalPart == 0.0)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;

    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#define ll long long
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define endl "\n"
#define pi 3.14159265358979323846264338327950288
#define MODD 1000000000000000000
#define INF -100000000000000
#define ordered_set tree<pair< ll int ,ll  int>, null_type,less<pair<ll int, ll int>>, rb_tree_tag,tree_order_statistics_node_update> 
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
using namespace std;
#define lld long double
using namespace __gnu_pbds; 
int main()
{
    fast;
   // #ifndef ONLINE_JUDGE
   // freopen("input.txt", "r", stdin);
   // freopen("output.txt", "w", stdout);
   // #endif
    lld a,b;
    lld  ans=1 ;  
    lld MOD=1000000000000000000;
    
cin>>a>>b;
    
    ans=a*b;
    cout<<(ll int)(ans)<<endl;
}


Measured memory_bytes: 3800
H1, M1, H2, M2, K = [int(s) for s in input().split()]
if H2 < H1:
    H2 += 24
elif H2 == H1 and M1 > M2:
    H2 += 24
print(int(H2 * 60 + M2 - (H1 * 60 + M1) - K))


Measured memory_bytes: 9140
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main() {
	ll n,weight;
	cin>>n>>weight;
	ll w[n],v[n],i,j;
	for(i=0;i<n;i++) cin>>w[i]>>v[i];
	ll dp[n+1][weight+1];
	for(i=0;i<=n;i++) dp[i][0]=0; //value = 0
	for(i=0;i<=n;i++) {
		for(j=1;j<=weight;j++) {
			if(i==0) {
				dp[i][j]=0;
				continue;
			}
			if(w[i-1]>j) {
				dp[i][j]=dp[i-1][j];
			}
			else {
				dp[i][j]=max(dp[i-1][j],v[i-1]+dp[i-1][j-w[i-1]]);
			}
		}
	}
	cout<<dp[n][weight]<<"\n";
}

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

int main() {
    int N, K;

    cin >> N >> K;

    int sum = 0;
    for (int i = 0; i < N; i++) {
        int x, y;

        cin >> x;
        y = max(K - x, x - K);

        if (x < y) {
            sum += (2 * x);
        }
        else {
            sum += (2 * y);
        }

    }
    cout << sum;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef vector<ll> vl;
#define inf 1000000000
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define rep1(i, a, b) for(int i =a; i >=b; i--)
#define f first
#define ss second
#define pb push_back


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

int n, x;

cin >> n;

if(n>=15){
    cout << n*800 - 200*(n/15) << endl;
}
else cout << n*800;


return 0;}


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

signed main(){
    // cout << fixed << setprecision(10) << flush;

    int n;
    cin >> n;

    int tempn = n;
    int d = 0;
    while(tempn != 0){
        d += tempn % 10;
        tempn /= 10;
    }
    if(n % d == 0) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 3636
#define _USE_MATH_DEFINES
#include <cmath>
#include <iostream>
#include <iomanip>
#include <limits>
#include <vector>
#include <algorithm>

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;

int main() {
	int s;
	cin >> s;
	vector<long long> a(s);
	rep(i, s) { cin >> a[i]; }
	long long c=0;
	rep(i, s) { c += a[i]; }
	sort(a.begin(), a.end());
	cout << a[0] << " " << a[a.size()-1] << " " << c<<"\n";
	return 0;
}



Measured memory_bytes: 3164
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << #x << " = " << x << endl;


#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 60


int main(){
  int n,m,k;
  int a[SIZE],b[SIZE];

  scanf("%d%d%d",&n,&m,&k);
  for(int i=0;i<n;i++) scanf("%d",a+i);
  for(int i=0;i<n;i++) scanf("%d",b+i);
  

  
  ll ans = 0;
  
  for(int i=1;i<(1<<n);i++){
    if(__builtin_popcount(i) > k) continue;
    
    vector<pair<int,int> > vec;
    
    for(int j=0;j<n;j++){
      if(i & (1<<j)) vec.push_back({a[j],b[j]});
    }
    sort(vec.begin(),vec.end(),greater<pair<int,int> >());

    ll calc = 0;
    int t = m;
    for(int j=0;j<vec.size();j++){
      calc += vec[j].first * min(t,vec[j].second);
      t -= min(t,vec[j].second);
    }
    
    ans = max(ans,calc+t);
  }

  printf("%lld\n",ans);
  
  return 0;
}

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

int main(){
    vector<int> data(3);
    for(int i=0; i<data.size(); i++) cin >> data.at(i);
    sort(data.begin(), data.end());
    int ans = data.at(2)*10 + data.at(1) + data.at(0);
    cout << ans << endl;

}

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

#define watch(x) cerr << (#x) << ": " << (x) << endl

typedef long long LL;

const int N = 2007;
int n;
pair<int, int> a[N];

LL dp[N][N];

int main() {

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> n;
    for(int i = 0; i < n; ++i) {
        cin >> a[i].first;
        a[i].second = i;
    }
    
    sort(a, a+n);
    reverse(a, a+n);

    for(int i = 0; i < n; ++i) {
        LL x, ind; tie(x, ind) = a[i];
        for(int j = 0; j <= i; ++j) {
            LL left = j, right = n-1-i+j;
            dp[i+1][j+1] = max(dp[i+1][j+1], dp[i][j] + x*abs(ind-left));
            dp[i+1][j] = max(dp[i+1][j], dp[i][j] + x*abs(ind-right));
        }
    }

    LL ans = 0;
    for(int j = 0; j <= n; ++j) {
        ans = max(ans, dp[n][j]);
    }

    cout << ans << '\n';
    
    return 0;
}


Measured memory_bytes: 26260
#include<stdio.h>
int main()
{
	int k;
	long a,b,i;

	scanf("%ld%ld%d",&a,&b,&k);

	if(b-a<2*k){
		for(i=a;i<=b;i++)
			printf("%ld\n",i);
		return 0;
	}
	for(i=a;i<a+k;i++)
		printf("%ld\n",i);
	for(i=b-k+1;i<=b;i++)
		printf("%ld\n",i);
	return 0;
}

Measured memory_bytes: 128
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
using namespace std;

#define MAXN ((int)1e5+5)

int d[MAXN];
int dp[MAXN];
	
int main()
{
	ios_base::sync_with_stdio(false);cin.tie(0);

	int n;
	cin >> n;
	for (int i = 0; i < n; ++i)
	{
		cin >> d[i];
		dp[i] = INT_MAX;
	}
	dp[0] = 0;

	for (int i = 0; i < n-1; ++i)
	{
		if(dp[i] == INT_MAX) continue;
		dp[i+1] = min(dp[i+1] , dp[i] + abs(d[i] - d[i+1]));
		dp[i+2] = min(dp[i+2] , dp[i] + abs(d[i] - d[i+2]));
	}

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


Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int d = sc.nextInt();
		
		int time = 0;
		for (int i = 0; i <= 100; i++) {
			if (a <= i && c <= i && i < b && i < d) time++;
		}
		
		System.out.println(time);
		
		sc.close();
	}
}




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

using namespace std;
using ll = long long;

#define INF (1LL << 60)

#define REP(i,m,n) for(ll (i)=(m),i##_len=(n);(i)<(i##_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define _PR(x) cout << (x) << endl
#define _PS(x) cout << (x) << " "
#define SZ(x) ((int)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define pb push_back

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

    ll ans = N / (A + B);
    ans = ans * A + MIN(N%(A+B),A);
    _PR(ans);

    return 0;
}

/*



*/

Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

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

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

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

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

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

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

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

fn main() {
    input!{
        x: u64,
        y: u64,
    }
    println!("{}", if x + y < 10 { (x + y).to_string()} else { "error".to_string() });
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define f first
#define s second
#define go ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
/*bool sortbysec(const pair<int,int> &a,
              const pair<int,int> &b)
{
    return (a.second < b.second);
} */
int main()
{
     ll t;
     ll ac=0,tle=0,re=0,wa=0;
     cin>>t;
     while(t--)
     {
        string str;
        cin>>str;
        if(str=="AC")
            ac++;
        else if(str=="TLE")
            tle++;
        else if(str=="RE")
            re++;
        else
            wa++;
     }
     cout<<"AC x "<<ac<<endl;
     cout<<"WA x "<<wa<<endl;
     cout<<"TLE x "<<tle<<endl;
     cout<<"RE x "<<re<<endl;

}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define IOS                                                                    \
  ios::sync_with_stdio(0);                                                     \
  cin.tie(0);                                                                  \
  cout.tie(0)
#define pb push_back
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
using namespace std;
using ll = long long;
using vi = vector<int>;
using pii = pair<ll, ll>;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
ll bpow(ll b, ll p, ll m = 1000000007LL) {
  ll rt = 1;
  for (; p; p >>= 1, b = b * b % m)
    if (p & 1)
      rt = rt * b % m;
  return rt;
}
int main() {
  IOS;
  string n;
  cin >> n;
  int sum = 0;
  for (int i = 0; i < n.size(); i++)
    sum = (sum + n[i] - '0') % 9;
  if (sum == 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 3732
from sys import stdin

n,x = [int(x) for x in stdin.readline().rstrip().split()]
p = [1]
t = [1]
for i in range(1,n+1):
    p.append(p[i-1]*2+1)
    t.append(t[i-1]*2+3)

def f(n,x):
    if n == 0:
        return 1 if x == 1 else 0
    elif x == 1:
        return 0
    elif 1 < x <= 1 + t[n-1]:
        return f(n-1,x-1)
    elif x == t[n-1] + 2:
        return p[n-1] + 1
    elif t[n-1]+2 < x <= 2*t[n-1]+2:
        return f(n-1,x-2-t[n-1]) + p[n-1] + 1
    else:
        return 2*p[n-1]+1

print(f(n,x))

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

INF = float('inf')
dp = [INF for i in range(n+1)]

dp[0] = 0
for i in range(n+1):
    for j in range(7):
        if i >= 6 ** j:
            dp[i] = min(dp[i], dp[i-6**j]+1)
    for j in range(6):
        if i >= 9 ** j:
            dp[i] = min(dp[i], dp[i-9**j]+1)

print(dp[n])

Measured memory_bytes: 3864
#include <bits/stdc++.h>
using ll = long long;
#define FOR(i, k, n) for(ll i = (k); i < (n); i++)
#define FORe(i, k, n) for(ll i = (k); i <= (n); i++)
#define FORr(i, k, n) for(ll i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for(ll i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;

const int INF = 1001001001;

int main(void){
  int a, b;
  cin >> a >> b;
  if(a*b%2) cout << "Odd" << endl;
  else cout << "Even" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define INF 1e18
#define PI 3.14159265358979

using namespace std;

// 解答1
int main(void){
  int n, m;
  cin >> n >> m;
  vector<ll> a(n);
  for (int i = 0; i < n; i++){
    cin >> a[i];
  }
  sort(a.begin(), a.end());


  vector<pair<ll, ll>> b(m);
  for (int i = 0; i < m; i++){
    cin >> b[i].second >> b[i].first;
  }
  sort(b.begin(), b.end());

  int id_m = m - 1;
  for (int i = 0; i < n; i++){
    if (a[i] < b[id_m].first){
      a[i] = b[id_m].first;
      b[id_m].second--;
    }
    else 
      break;

    if (b[id_m].second == 0)
      id_m--;
    if (id_m < 0)
      break;
  }
  ll sum = 0;

  for (int i = 0; i < n; i++){
    sum += a[i];
  }

  cout << sum << endl;



  return 0;
}

// 解答2

// どこが遅いのかわからんけどTLEした
/*
int main(void){
  int n, m;
  cin >> n >> m;
  vector<ll> a(n);
  for (int i = 0; i < n; i++){
    cin >> a[i];
  }
  sort(a.begin(), a.end());


  vector<pair<ll, ll>> b(m);
  for (int i = 0; i < m; i++){
    cin >> b[i].second >> b[i].first;
  }
  sort(b.begin(), b.end());

  int id = n;
  for (int i = m - 1; i > -1; i--){
    int left = -1, right = id, mid;
    while (left + 1 < right){
      mid = (left + right)/2;
      if (a[mid] < b[i].first)
        left = mid;
      else
        right = mid;
    }
    if (left + 1 > b[i].second){
      for (int j = 0; j < left + 1 - b[i].second ; j++){
        a[j] = a[j + b[i].second];
      }
      for (int j = left + 1 - b[i].second; j < left + 1; j++){
        a[j] = b[i].first;
      }
      id = left + 1 - b[i].second;
    }
    else {
      for (int j = 0; j < left + 1; j++){
        a[j] = b[i].first;
      }
      break;
    }
  }

  ll sum = 0;

  for (int i = 0; i < n; i++){
    sum += a[i];
  }

  cout << sum << endl;


  return 0;
}
*/


Measured memory_bytes: 2688
#include <iostream>
using namespace std;
 
int main() {
    //入力を受け取る
    int D, T, S;
    cin >> D >> T >> S;
 
    //高橋君の移動時間を計算する
    double time = (double)D / S;
 
    //Tとtimeの大小関係に応じて出力をする
    if (T >= time) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3048
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
import java.util.concurrent.atomic.AtomicLong;

public class Main {
    public static void main(final String[] args) {
        final Scanner scanner = new Scanner(System.in);
        final int n = scanner.nextInt();
        final long[] array = new long[n + 1];

        for (int i = 0; i < n; i++) {
            array[i + 1] = array[i] + scanner.nextInt();
        }

        final Map<Long, AtomicLong> map = new HashMap<>();

        for (final long value : array) {
            map.computeIfAbsent(value, e -> new AtomicLong())
                    .incrementAndGet();
        }

        final long answer = map.values().stream()
                .map(e -> e.get() * (e.get() - 1) / 2)
                .mapToLong(Long::longValue)
                .sum();

        System.out.println(answer);
    }
}


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

using namespace std;

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

    int a,b;
    cin>>a>>b;
    if(a<10&&b<10)cout<<a*b;
    else cout<<-1;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int mxn = 110;
int ar[mxn];
int main()
{
	ios_base::sync_with_stdio(0);
  	cin.tie(0);
  	cout.tie(0);
	int n , x;
	cin>>n>>x;
	for(int i = 0; i < n; i++)
		cin>>ar[i];	
	sort(ar , ar+n);
	int cnt = 0;
	long long sum = 0;
	for(int i = 0; i < n; i++)
	{
		if(x >= ar[i])
		{
			cnt ++;
			x -=ar[i];
		}
		sum +=ar[i];
	}
	if(cnt==n && x > 0) cnt -=1;
	cout<<max(0 , cnt)<<endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <set>
#include <iostream>
#include <stack>
#include <vector>
#include <string>
#include <map>
#include <cmath>
#include <queue>
#include <random>
#include <chrono>
using namespace std;

int n, m;

typedef pair<int, int> pii;
typedef long long LL;

const int maxn = 2005;
pair<int, pii> p[maxn];
LL X;

int fa[maxn];

int Find(int x){
    return x == fa[x] ? x : fa[x] = Find(fa[x]);
}

void init(int n){
    for(int i = 1;i <= n;i++){
        fa[i] = i;
    }
}

int Union(pair<int, pii> edge){
    int x = edge.second.first;
    int y = edge.second.second;
    int fx = Find(x);
    int fy = Find(y);
    if(fx == fy)
        return 0;
    else{
        fa[fx] = fy;
        return edge.first;
    }
}

const LL mod = 1e9 + 7;

int main(){
    cin >> n >> m;
    cin >> X;
    for(int i = 1;i <= m;i++){
        scanf("%d%d%d", &p[i].second.first, &p[i].second.second, &p[i].first);
    }
    sort(p + 1, p + 1 + m);
    if(n <= 2){
        cout << 0 << endl;
        return 0;
    }
    LL ans1 = 1, ans2 = 1;
    for(int i = 2;i <= m;i++){
        init(n);        
        LL ans = 0;
        ans += Union(p[1]);
        ans += Union(p[i]);
        for(int j = 1;j <= m;j++){
            if(j == 1 or j == i)
                continue;
            ans += Union(p[j]);
        }
        if(ans < X){
            continue;
        }
        if(ans == X){
            ans1 = ans1 * 2 % mod;
            continue;
        }
        if(ans > X){
            ans2 = ans2 * 2 % mod;
        }
    } 
    ans1 = (ans1 + mod - 1) % mod;
    ans1 = (ans1 * ans2) % mod;
    ans1 = (ans1 * 2) % mod;
    cout << ans1 << endl;
    return 0;
}


Measured memory_bytes: 256
// VU TRUONG AN
#include <bits/stdc++.h>
#define F first
#define S second
#define maxn 200005
#define MOD 1000000007
#define mp make_pair
#define pb push_back
#define pi acos(-1)
#define bit(p,x) ((x>>p) & 1)
#define Task "CF"
using namespace std;

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

const int base = 100003;
const long long MM = 1ll * MOD * MOD;

int n,m;

long long ans = 0;

void Solve(){
    cin >> n;
    for(int i = 1;i <= n;++i){
        int pos = n / i;
        long long res = 1ll * pos * (pos + 1) / 2;
        ans += res * i;
    }
    cout << ans;
}


int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen(Task".inp", "r", stdin);
    freopen(Task".out", "w", stdout);
#endif
    int test = 1;
//    cin >> test;
    while(test--)
        Solve();
}


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

int main(){
  int n,W;
  cin>>n>>W;
  ll dp[200005];
  rep(i,n){
    ll w,v;
    cin>>w>>v;
    for(int j = W;j >= w;j--){
      dp[j] = max(dp[j-w]+v,dp[j]);
    }
  } 
  cout << dp[W] << endl;
}

Measured memory_bytes: 1024
#include<stdio.h>
int main()
{
    int a,b,h,area;
    scanf("%d",&a);
    scanf("%d",&b);
    scanf("%d",&h);
    if(1<=a<=100 && 1<=b<=100 && 1<=h<=100 && h%2==0)
    {
        area=(a+b)*h/2;
        printf("%d\n",area);
    }
    return 0;
}


Measured memory_bytes: 128