akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 100005;

int main() {
    int x; cin >> x;
    int ans = 1;
    for (int i = 2; i * i <= x; i++) {
        for (int j = 2; (int)pow(i,j) <= x; j++) {
            ans = max(ans,(int)pow(i,j));
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
s = input().rstrip()
n = len(s)
cnt = 0
right_cnt = [0] * n
left_cnt = [0] * n
direct = "R"
for i, item in enumerate(s):
    if direct == "R" and item == "R":
        cnt += 1
    elif direct == "R" and item == "L":
        right_cnt[i] = cnt
        cnt = 0
direct = "L"
for i, item in enumerate(s[::-1]):
    if direct == "L" and item == "L":
        cnt += 1
    elif direct == "L" and item == "R":
        left_cnt[n-1-i] = cnt
        cnt = 0
ans = [0] * n
for i, item in enumerate(right_cnt):
    if i == 0:
        continue
    even = item // 2
    odd = item - even
    ans[i] += even
    ans[i-1] += odd
for i, item in enumerate(left_cnt):
    if i == n-1:
        continue
    even = item // 2
    odd = item - even
    ans[i] += even
    ans[i+1] += odd
print(" ".join([str(item) for item in ans]))

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

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

const int mxn = 100005;
int arr[105], dp[2][mxn];

bool recur(int i, int stones, int n)
{
    if(stones < arr[0])
    {
        if(i == 0) return false;
        else return true;
    }
    if(dp[i][stones] != -1) return dp[i][stones];

    bool node;
    if(i == 0)
    {
        node = false;
        for(int i=0; i<n; i++)
        {
            if(arr[i] > stones) break;
            node |= recur(1,stones-arr[i],n);
        }
    }
    else
    {
        node = true;
        for(int i=0; i<n; i++)
        {
            if(arr[i] > stones) break;
            node &= recur(0,stones-arr[i],n);
        }
    }
    return dp[i][stones] = node;
}

int main()
{
    FASTIO
    memset(dp,-1,sizeof(dp));
    int n, k;
    cin >> n >> k;
    for(int i=0; i<n; i++) cin >> arr[i];
    recur(0,k,n);
    string ans = (dp[0][k]) ? "First" : "Second";
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 12160
#include<iostream>
#include<math.h>

using namespace std;

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

    bool flag=false;;

    if(abs(a-c)<=d){
        flag=true;
    }
    else{
        if(abs(b-a)<=d&&abs(b-c)<=d){
            flag=true;
        }
    }
    if(flag)cout<<"Yes";
    else cout<<"No";
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define mod 1000000007
#define inf 1e18
#define inp(arr,n) for(int i=0;i<n;i++) cin>>arr[i]
#define fr(i,a,b) for(int i=a;i<=b;i++)
using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int T=1;
    while (T--) {
        ll n;
        cin>>n;
        string s="";
        while(n!=0){
            ll r=n%26;
            if(r==0) r=26;
            char ch=(char)('a'+r-1);
            s.push_back(ch);
            n/=26;
            if(ch=='z') n--;
        }
        for(int i=s.length()-1;i>=0;i--) cout<<s[i];
        cout<<"\n";
    }
    return 0;
}

Measured memory_bytes: 3640
let mkls s =
  let len = String.length s in
  let rec f i ls =
    if i < 0 then List.sort_uniq Char.compare ls
    else f (i - 1) (s.[i] :: ls) 
  in
  f (len - 1) []

let solve ls = 
  let i2s c = Char.chr c |> Char.escaped in
  if List.length ls = 26 then "None"
  else
    let rec f c = function
      | [] -> i2s c
      | h :: t when Char.chr c <> h -> i2s c
      | _ :: t -> f (c + 1) t
    in
    f (Char.code 'a') ls

let () = mkls (read_line ()) |> solve |> print_endline

Measured memory_bytes: 5888
class Priority_queue
  def initialize(bool = true)
    if bool
      @ope = proc{|a, b|(a and b)? a > b : false}
    else
      @ope = proc{|a, b|(a and b)? a < b : false}
    end
    @heap = []
  end

  def <<(other)
    @heap.push(other)
    up
  end

  def gets
    result = @heap.shift
    @heap.unshift(@heap.pop)
    down
    return result
  end
  
  def up(key = @heap.size - 1)
    if @ope.call(@heap[key / 2], @heap[key])
      @heap[key / 2], @heap[key] = @heap[key], @heap[key / 2]
      down(key / 2)
      up(key / 2)
    end
  end

  def down(key = 0)
    if @ope.call(@heap[key], @heap[key * 2]) and @ope.call(@heap[key * 2 + 1], @heap[key * 2])
      @heap[key], @heap[key * 2] = @heap[key * 2], @heap[key]
      down(key * 2)
    elsif @ope.call(@heap[key], @heap[key * 2 + 1])
      @heap[key], @heap[key * 2 + 1] = @heap[key * 2 + 1], @heap[key]
      down(key * 2 + 1)
    end
  end
  def inspect
    @heap
  end
end
class Node
  include Comparable
  attr_reader :cost, :id
  def initialize(id, cost)
    @id = id
    @cost = cost
  end
  def <=>(other)
    @cost <=> other.cost
  end
end

def main
  n = gets.to_i
  array = Array.new
  n.times do
    array << gets.split(" ").map(&:to_i)[1..-1]
  end
  queue = Priority_queue.new
  minimum = Array.new(n, 1 / 0.0)
  minimum[0] = 0
  nowcost = 0
  position = 0
  while nowcost < minimum.max
    array[position][0].times do |i|
      queue << Node.new(array[position][1 + 2 * i], array[position][2 + 2 * i] + nowcost)
    end
    position = queue.gets
    while minimum[position.id] < position.cost
      position = queue.gets
    end
    position, nowcost = position.id, position.cost
    minimum[position] = nowcost
  end
  minimum.each_with_index{|item, idx|puts "#{idx} #{item}"}
end
main

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

using lint = long long;
#define BIT(i) (lint(1)<<i)

int main() {
    int N;
    lint K;
    cin >> N >> K;

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

    int d = 0;
    lint m = max(K, *max_element(A.begin(), A.end()));
    while (m > 0) {
        d++;
        m /= 2;
    }

    vector<int> num(d, 0), num_k(d, 0);
    for (int i = 0; i < d; i++) {
        if (K&BIT(i)) {
            num_k[i]++;
        }
        for (int j = 0; j < N; j++) {
            if (A[j]&BIT(i)) {
                num[i]++;
            }
        }
    }

    lint ans = 0;
    for (int i = 0; i < d; i++) {
        if (num_k[i] == 1) {
            lint cand = 0;
            for (int j = 0; j < i; j++) {
                if (num[j] > N/2) {
                    cand += BIT(j)*num[j];
                } else {
                    cand += BIT(j)*(N - num[j]);
                }
            }

            cand += BIT(i)*num[i];

            for (int j = i + 1; j < d; j++) {
                if (K&BIT(j)) {
                    cand += BIT(j)*(N - num[j]);
                } else {
                    cand += BIT(j)*num[j];
                }
            }

            ans = max(ans, cand);
        }
    }

    lint cand = 0; // K = 0 の場合
    for (int i = 0; i < d; i++) {
        cand += BIT(i)*num[i];
    }
    ans = max(ans, cand);

    cand = 0; // X = K の場合
    for (int i = 0; i < N; i++) {
        cand += K^A[i];
    }
    ans = max(ans, cand);

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

Measured memory_bytes: 1024
# n<3000, t<3000, a,b <3000
import sys

input = sys.stdin.buffer.readline

n, t = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(n)]
rAB = AB[::-1]
dp1 = [[0] * (t + 1) for _ in range(n + 1)]
dp2 = [[0] * (t + 1) for _ in range(n + 1)]

for i in range(n):
    ni = i + 1
    a, b = AB[i]
    for j in range(t + 1):
        nj = j + a
        if nj <= t:
            dp1[ni][nj] = max(dp1[i][j] + b, dp1[ni][nj])
        dp1[ni][j] = max(dp1[ni][j], dp1[i][j])
    c, d = rAB[i]
    for j in range(t + 1):
        nj = j + c
        if nj <= t:
            dp2[ni][nj] = max(dp2[i][j] + d, dp2[ni][nj])
        dp2[ni][j] = max(dp2[ni][j], dp2[i][j])

ans = 0
# i-1まで→先頭i個
# 後ろはn-(i+1)個
for i in range(n):
    for j in range(t):
        temp = AB[i][1]
        if i >= 1:
            temp += dp1[i][j]
        if n - i - 1 >= 1:
            temp += dp2[n - i - 1][t - 1 - j]
        ans = max(ans, temp)
print(ans)


Measured memory_bytes: 211532
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  int X[N];
  int max = 0;
  int min = 100;
  for(int i=0; i < N; ++i){
    int x;
    cin >> x;
    X[i] = x;
    if(max < x) max = x;
    if(min > x) min = x;
  }

  int r = 0;
  for(int i = min; i <= max; ++i){
    int sum = 0;
    for(int f = 0; f < N; ++f){
      int d = abs(i - X[f]);
      sum = sum + pow(d, 2);
    }
    if(r == 0){
      r = sum;
    }else if(r > sum){
      r = sum;
    }
  }
  
  cout << r;
  
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main()
{
    int n, arr[50], i, count=0, a[2], j=0;
    scanf("%d", &n);
    for(i=1; i<=n; i++)
    {
        scanf("%d", &arr[i]);
        if(i!=arr[i])
        {
            count++;
            a[j]=i;
            j++;

        }
    }
    if(count==2)
        printf("YES\n", a[0], a[1]);
    else if(count==0)
        printf("YES\n");
    else
        printf("NO\n");
}

Measured memory_bytes: 128
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#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>

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned long long ULL;

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

#define MP make_pair
#define EACH(i,c) for(auto i: c)
#define SORT(c) sort((c).begin(),(c).end())

#define ALL(a)  (a).begin(),(a).end()

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int N;
	cin >> N;
	int a = 1000 - (N % 1000);
	if((N % 1000) == 0) cout << 0 << endl;
	else cout << 1000 - (N % 1000) << endl;


	return 0;
}


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

using namespace std;

int N,M;
int X[100005],Y[100005];
int L[200005],R[200005],D[200005];

bool f;

vector<int> l[100005],r[100005];

void dfs(int x,int i){

  Y[i]=1;

  int n=l[i].size(); 

  for(int k=0; k<n; k++){
    int j=l[i][k];  
    if(Y[R[j]]==1&&X[R[j]]!=x+D[j]){
      f=1; return;
    }
    else X[R[j]]=x+D[j]; 
    if(Y[R[j]]==0) dfs(x+D[j],R[j]);
  } 

  n=r[i].size(); 

  for(int k=0; k<n; k++){
    int j=r[i][k]; 
    if(Y[L[j]]==1&&X[L[j]]!=x-D[j]){
      f=1; return;
    }
    else X[L[j]]=x-D[j]; 
    if(Y[L[j]]==0) dfs(x-D[j],L[j]);
  }

  return;

}

int main() {
  
cin>>N>>M;

for(int i=0; i<M; i++){
  
  scanf("%d %d %d",&L[i],&R[i],&D[i]);

  l[L[i]].push_back(i);  
  r[R[i]].push_back(i);

}

Y[1]=0; X[1]=0;

for(int i=1; i<=N; i++){

if(Y[i]) continue;
  dfs(X[i],i);

}

if(f) cout<<"No"<<endl;
else cout<<"Yes"<<endl;

}

Measured memory_bytes: 18304
Imports System.Collections.Generic
Imports System.Console
Imports System.Math  
Module Program
 	Sub Main()
        Dim input() As String = Console.ReadLine().Split(" ")
        Dim a As Integer = input(0)
        Dim b As Integer = input(1)
        Dim n As Integer = b - a + 1
        If (a<=0 and b>=0) or a=0 or b=0 Then
            Console.WriteLine("Zero")
            Exit Sub
        End If 
        If a>0 or n Mod 2 = 0 Then
            Console.WriteLine("Positive")
            Exit Sub
        End If 
        Console.WriteLine("Negative")
    End Sub
End Module


Measured memory_bytes: 11220
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define F  first
#define S  second
#define ff(i,n) for(i=0;i<n;i++)
ll bg = 100000007;
ll power(ll x,ll y)
{
	if(y==0)
		return 1;
	ll h=power(x,y/2)%bg;	
	h=(h*h)%bg;
	if(y%2==1)
	  return (x*h)%bg;
	else
	  return h%bg;  
}
ll modinv(ll m)
{
	return power(m,bg-2)%bg;
}
ll sum(ll i)
{
	ll s = (i*(i+1))/2;
	return s;
}
int main()
{ 
	ll t;
	t=1;
	while(t--)
	{
		ll i,n,m;
		cin>>n>>m;
		ll d = n*m;
		cout<<d;		
	}
	return 0;
}

Measured memory_bytes: 3644
using System;

namespace AtCoder
{
    class Program
    {
        static void Main()
        {
            int n = int.Parse(Console.ReadLine());
            string[] input = Console.ReadLine().Split(' ');
            string s = input[0];
            string t = input[1];
            string result = "";
            for (int i = 0; i < n; i++)
            {
                result += s[i];
                result += t[i];
            }
            Console.WriteLine(result);
        }
    }
}

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

#define int long long
using ll = long long;
using ld = long double;
using intpair = pair<int, int>;
const int MOD = 1e9 + 7;
inline int mod (ll a, int m = MOD) { return (a % m + m) % m; }
struct Fast {Fast(){cin.tie(0);ios::sync_with_stdio(0);}} fast;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define ceiv(a, b) ((ll)((a) + (b) - 1)/(ll)(b))

signed main(){
    string s, t;
    cin >> s >> t;
    int ans = 0;
    rep(i,s.length()){
        if(s[i] != t[i]) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3796
n = gets.to_i
if n <= 111
  p 111
elsif n <= 222
  p 222
elsif n <= 333
  p 333
elsif n <= 444
  p 444
elsif n <= 555
  p 555
elsif n <= 666
  p 666
elsif n <= 777
  p 777
elsif n <= 888
  p 888
elsif n <= 999
  p 999
end

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
 int main(){
   long a,b,n;cin>>a>>b>>n;
   long x=0,tmp;
   x=min(n,b-1);
   long ans=floor(a*x/b) - a*floor(x/b);
   cout <<ans<<endl;
 }

Measured memory_bytes: 3672
#include <iostream>
#include <array>
#include <algorithm>

using namespace std;

using ll = long long int;

int main(){
    
    ll N, M;
    array<ll, 64> X = {0};
    
    cin >> N >> M;
    for(ll i = 0; i < M; ++i){
        ll A, B;
        cin >> A >> B;
        X[A - 1] += 1;
        X[B - 1] += 1;
    }
    
    for(ll i = 0; i < N; ++i){
        cout << X[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
	//int t;
	//cin>>t;
	//for(int i=0;i<t;i++)
	//{
		int n,c=0,b=0,d,cnt=0;
		vector<int> a(5);
		for(int i=1;i<=5;i++)
		{
			cin>>a[i];
			if(a[i]==0){
				cout<<i<<endl;
				break;
			}
		}
	//}
}


Measured memory_bytes: 3600
from copy import deepcopy
H, W = map(int, input().split())
alist = [list(input()) for _ in range(H)]
acopy = deepcopy(alist)
counter = 0
for i in range(W):
    for a in alist:
        if a[i] == "#":
            break
    else:
        for a in acopy:
            a.pop(i - counter)
        counter += 1

for a in acopy:
    if "#" in a:
        print("".join(a))


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

using namespace std;

#define mod 1000000007
#define int int64_t
#define fio ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL)
#define endl "\n"

void solve()
{
    string s,t;
    cin>>s>>t;
    int n=s.size(),l=t.size();
    int ans=l;
    
    for(int i=0;i+l-1<n;i++)
    {
        int cnt=0;
        for(int j=0;j<l && i+j<n;j++)
        {
            if(t[j]!=s[i+j])
                cnt++;
        }
        ans=min(ans,cnt);
    }
    cout<<ans<<endl;
}

int32_t main()
{
    fio;
    int t;
    // cin>>t;
    t=1;
    while(t--)
        solve();
}

Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>

using namespace std;

int main()
{
    int n;
    vector<int> a;
    vector<int> aSorted;

    cin >> n;

    a.resize(n);
    aSorted.resize(n);

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

    sort(aSorted.begin(), aSorted.end(), greater<int>());

    int maxA = aSorted[0];
    int subMaxA = aSorted[1];

    for(int i = 0; i < n; ++i)
    {
        cout << (a[i] == maxA ? subMaxA : maxA) << endl;
    }
}


Measured memory_bytes: 3200
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author TM
 */


#include <bits/stdc++.h>

using namespace std;

class DSummerVacation {
public:
    void solve(std::istream &cin, std::ostream &cout) {
        int n, m;
        cin >> n >> m;
        map<int, vector<int>> ab_map;
        vector<vector<int>> ab_vec(n, vector<int>(2, 0));
        for (int i = 0; i < n; ++i) {
            int a, b;
            cin >> a >> b;
            ab_map[a].emplace_back(b);
        }
        priority_queue<int> candidates;
        vector<int> ans;
        for (int j = 1; j < m + 1; ++j) {
            for (const auto &item : ab_map[j]) {
                candidates.push(item);
            }
            if (candidates.size() == 0) continue;
            ans.emplace_back(candidates.top());
            candidates.pop();
        }
        cout << accumulate(ans.begin(), ans.end(), 0);
//        cout << 123;
    }
};


int main() {
    DSummerVacation solver;
    std::istream &in(std::cin);
    std::ostream &out(std::cout);
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 16892
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
using P = pair<int,ll>;
template <class T> void chmin(T &a, const T &b) noexcept { if (b < a) a = b; }
template <class T> void chmax(T &a, const T &b) noexcept { if (a < b) a = b; }
void print() { cout << "\n"; }
template <class T, class... Args>
void print(const T &x, const Args &... args) { cout << x << " "; print(args...);}
void debug_out() { cout << "\n"; }
template <class T, class... Args>
void debug_out(const T &x, const Args &... args) { cout << x << " "; debug_out(args...);}
#ifdef _DEBUG
  #define debug(...) debug_out(__VA_ARGS__)
#else
  #define debug(...) 
#endif

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  int n, m;
  cin >> n >> m;
  vector<P> a(n);
  rep(i,n) cin >> a[i].first >> a[i].second;
  sort(all(a));
  priority_queue<ll> que;
  int itr = 0;
  ll ans = 0;
  for (int i = 1; i <= m; ++i) {
    while (itr < n) {
      if (a[itr].first <= i) {
        que.push(a[itr].second);
        itr++;
      }
      else break;
    }
    if (!que.empty()) {
      ans += que.top(); que.pop();
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 2936
#include<stdio.h>

void call(int N) {
	int i = 1;
	int x;
	while (i <= N) {
		x = i;
		if (x % 3 == 0) {
			printf(" %d", i);
		}
		else {
			while (x) {
				if (x % 10 == 3) {
					printf(" %d", i);
					break;
				}
				else {
					x /= 10;
				}
			}
		}
		
		i++;
	}
	printf("\n");
}


int main() {
	int N;
	scanf("%d", &N);
	call(N);


	return 0;
}


Measured memory_bytes: 2712
import static java.lang.Math.*;
import static java.util.Arrays.*;
import java.util.*;
import java.io.*;
import java.math.BigInteger;

public class Main {
	public static void main(String[] args) {
		try {
			System.setIn(new FileInputStream("src/aoj0110/input.txt"));
			System.setOut(new PrintStream(new FileOutputStream("src/aojxxxx/result.txt")));
		} catch (FileNotFoundException e) {
		}
		new Main().run();
	}

	Scanner sc = new Scanner(System.in);

	void run() {
		for (; sc.hasNext();) {
			String str = sc.next();
			str = str.replace('+', '=');
			String[] ss = str.split("=");
			int ans = -1;
			for (int x = 0; x < 10; x++) {
				String A = ss[0].replace('X', (char) ('0' + x));
				String B = ss[1].replace('X', (char) ('0' + x));
				String C = ss[2].replace('X', (char) ('0' + x));

				if (new BigInteger(A).add(new BigInteger(B)).equals(new BigInteger(C))) {
					if (A.length() >= 2 && A.charAt(0) == '0' ||
						B.length() >= 2 && B.charAt(0) == '0' || 
						C.length() >= 2 && C.charAt(0) == '0') {
					}
					else {
						ans = x;
					}
				}
			}
			if (ans == -1)
				System.out.println("NA");
			else
				System.out.println(ans);

		}
	}
}

Measured memory_bytes: 12000
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int prime[1000005],vis[1000005],cnt = 0;
void init(){
    for(int i=2;i<=1e6;i++){
        if(!vis[i]){
            prime[cnt++] = i;
            for(int j=i;j<=1e6;j+=i){
                vis[j]=1;
            }
        }
    }
}
ll n,p;
map<ll,ll> mp;
map<ll,ll >::iterator it;
ll qpow(ll a,ll x){
    ll res = 1;
    while (x){
        if(x&1)
            res=res*a;
        a=a*a;
        x/=2;
    }
    return res;
}
int main(){
    ios::sync_with_stdio(false);
    init();
    cin>>n>>p;
    for(int i=0;i<cnt;i++){
        while (p%prime[i]==0) {
            p /= prime[i];
            mp[prime[i]]++;
        }
    }
    if(p!=1){
        mp[p]++;
    }
    ll ans = 1;
    for(it=mp.begin();it!=mp.end();it++){
        if(it->second>=n) {
            ans *= qpow(it->first,it->second/n);
        }
    }
    cout<<ans<<endl;
}



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

using namespace std;

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

// container util
#define all(x) (x).begin(), (x).end()

// typedef
typedef long long lint;
typedef unsigned long long ull;
typedef complex<long double> Complex;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;

// constant
const int MOD = (int)1e9 + 7;
const int INF = (int)1e18;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
const double pi = 3.14159265358979323846;

// conversion
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

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

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

  int a, b;
  cin >> a >> b;

  string s = "", t = "";

  rep(i, b) { s += to_string(a); }
  rep(i, a) { t += to_string(b); }

  if (s < t) {
    cout << s << endl;
  } else {
    cout << t << endl;
  }

  return 0;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
res = ["*"]*N
flag = True
for i in range(M):
    s, c = input().split()
    if s == "1" and c == "0":
        if N != 1:
            flag = False
    if res[int(s)-1] != "*" and res[int(s)-1] != c:
        flag = False
    res[int(s)-1] = c

if flag:
    if res[0] == "*":
        if N != 1:
            res[0] = "1"
    print("".join(x if x != "*" else "0" for x in res))
else:
    print(-1)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long int lli;
const lli M=998244353,N=2e5+5;
lli fact[N];

lli binpow(lli a,lli b) 
{
    if (b == 0) return 1;
    lli res = binpow(a,b/2);
    res= (res*res)%M;
    
    if(b%2) return (res*a)%M;
    return res;
}
 
lli inv(lli a)
{
    return binpow(a,M-2);
}

lli add(lli a, lli b)
{
	lli res = a + b;
	if(res >= M)
		return res - M;
	return res;
}
 
lli mul(lli a, lli b)
{
	lli  res = a * b;
	if(res >= M)
		return res % M;
	return res;
}
 
lli sub(lli a, lli b)
{
	return (a%M -b%M +M) %M;
}

void pre()
{
    fact[0]=1;
    for(int i=1;i<N;i++)
        fact[i] = mul(fact[i-1], i);
}

lli ncr(lli n, lli r)
{
    return mul(fact[n], inv(mul(fact[n-r], fact[r])));    
}

/*c(n-1,k1) part is straight forward: find k1 points to split the whole row.

In each of k1 + 1 segments, colors must be different. The 2 blocks at either side of each splitting point have same color.

m is for the first block of first segment, it can choose from all m colors. for the rest blocks of first segment, 
each one can only choose from m-1 colors since its color must be different from adjacent blocks.

for the first block of other segment, it has only 1 choice: the same as the last one of previous segment. 
the rest blocks of other segment are like that in the first segment, each has m-1 choices.*/

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    pre();
    lli n,m,k;
    cin>>n>>m>>k;
    lli i,cur,ans=0;
    
    for(i=0;i<=k;i++)
    {
        cur=ncr(n-1,i);
        cur=mul(cur,mul(m,binpow(m-1,n-1-i)));
        ans=add(ans,cur);
    }
    cout<<ans;
    return 0;
}

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

using namespace std;

/* g++ -g -fsanitize=address -lasan -std=c++11 -Dfoo_ */

/* freopen("input.txt", "rt", stdin); */
/* freopen("output.txt", "wt", stdout); */

#define ALL(c)          (c).begin(), (c).end()
#define ALLR(c)         (c).rbegin(), (c).rend()
#define FOR(i,a,b)      for (int i=(a); i < (b); ++i)
#define FORR(i,a,b)     for (int i=(a); i > (b); --i)
#define FOR_ALL(i,c)    for (__typeof((c).begin()) i=(c).begin();   \
                             i != (c).end(); ++i)
#define FOR_ALLR(i,c)   for (__typeof((c).rbegin()) i=(c).rbegin(); \
                             i != (c).rend(); ++i)
#define SZ(array)       (sizeof(array)/sizeof(array[0]))
#define lc(x)           (x<<1)     /* 2*x */
#define rc(x)           (x<<1 | 1) /* 2*x+1 */
#define lowbit(x)       (x & (-x)) /* 0b10100 -> 0b100 */

typedef long long       LL;
typedef map<int,int>    MII;
typedef pair<int,int>   PII;
typedef set<int>        SI;
typedef vector<bool>    VB;
typedef vector<double>  VD;
typedef vector<int>     VI;
typedef vector<string>  VS;

/* check if a key is in container C */
template <class C>
inline bool in_(const typename C::key_type& k, const C& A)
{ return A.find(k) != A.end(); }
inline bool in_(const string& s, const string& S)
{ return S.find(s) != string::npos; }

const int inf = 1e9;
const int mod = 1e9+7;
const int maxn = 2e3+3;

LL gcd(const LL a, const LL b)
{
    if (b == 0)
        return a;
    return gcd(b,a%b);
}

int main()
{
#ifdef foo_
    freopen("foo", "rt", stdin);
#endif
    ios::sync_with_stdio(false);
    LL a,b,c,d;
    while (cin >> a >> b >> c >> d) {
        const LL x = b/c - (a-1)/c;
        const LL y = b/d - (a-1)/d;
        const LL lcm = c*d/gcd(c,d);
        const LL z = b/lcm - (a-1)/lcm;
        const LL ans = b-a+1 - x - y + z;
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 256
//15-4 シルクロード
#include<iostream>
#include<fstream>
#include<stdio.h>
#include<math.h>
#include<time.h>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<set>
#include<stack>
#include<queue>
#include<cstdlib>
#include<algorithm>
#include<random>
#include<cassert>
using namespace std;
#define LL long long
#define INT_MIN -2147483648
#define INT_MAX 2147483647
#define LL_MIN -9223372036854775808
#define LL_MAX 9223372036854775807
#define segment_size 65536
#define ROOP() while(true)

int N,M;
int D[1000];
int C[1000];

int dp[1000][1000];

int move(int site, int day){
    if(dp[site][day]!=INT_MAX) return dp[site][day];
    if(site==N) return 0;
    int re = INT_MAX;
    if(N-site < M-day) re = min(re, move(site, day+1));
    re = min(re,move(site+1,day+1)+C[day]*D[site]);
    dp[site][day] = re;
    return re;
}

int main(){
    cin >> N >> M;
    for(int i=0; i<N; i++){
        cin >> D[i];
    }
    for(int i=0; i<M; i++){
        cin >> C[i];
    }
    for(int i=0; i<1000; i++){
        for(int j=0; j<1000; j++){
            dp[i][j] = INT_MAX;
        }
    }

    cout << move(0,0) << endl;

    return 0;
}



Measured memory_bytes: 7048
#include <stdio.h>

int int_sort(const void* a, const void* b) {
  return *( int * )a - *( int * )b;
}

int main(void) {
    	int i,j,k,n,q,t;
	int S[100000];
	int T[50000];
	int R[500];
	
	scanf("%d\n", &n);
	for(i=0;i<n;i++) {
		scanf("%d", &S[i]);
	}

	scanf("%d\n", &q);
	for(i=0;i<q;i++) {
		scanf("%d", &T[i]);
	}
	
	qsort((void*)S, n, sizeof(S[0]), int_sort);
	qsort((void*)T, q, sizeof(T[0]), int_sort);
	
	i=j=k=0;
	while(i<n&&j<q) {
		if(S[i] == T[j]) {
			R[k] = S[i];
			i++;j++;k++;
		} else if(S[i] > T[j]) {
			j++;
		} else if(S[i] < T[j]) {
			i++;
		}
	}
	printf("%d\n", k);

	return 0;
}


Measured memory_bytes: 2512
import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		List<Integer> list = new LinkedList<Integer>();
		while(sc.hasNext()){
			list.add(sc.nextInt()+sc.nextInt());
		}
		for(int i:list){
			System.out.println(i);
		}
	}
}

Measured memory_bytes: 11000
#include <bits/stdc++.h>
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")
//#pragma GCC optimization ("unroll-loops")
 
#define int long long 
#define pb push_back
#define all(s) s.begin(),s.end()
#define pii pair<int,int>
#define fr first
#define sc second
#define bst ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl "\n"

using namespace std;

const int N = 5e5 + 10, mod = 1e9 + 7, inf = 1e18 + 7, logn = 23;
const double pi = acos(-1);


void solve() {
	//soln
	int k;
	cin >> k;
	string s;
	cin >> s;
	for(int i = 0; i < min((int)s.size(), k); i++) {
		cout << s[i];
	}
	if(s.size() > k) {
		cout << "...";
	}
	cout << endl;
}
main() {
	bst;
	int t = 1;
	//cin >> t;
	while(t--) {
		solve();
	}
}


Measured memory_bytes: 3636
#include <iostream>
#include <set>

using namespace std;

int main() {
  set<string> s;
  int N;
  cin >> N;
  for (int i = 0; i < N; ++i) {
    string item;
    cin >> item;
    s.insert(item);
  }
  cout << s.size() << endl;
}

Measured memory_bytes: 19200
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;


public class Main{

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		while(s.hasNextLine()) {
			int purchaceCnt = s.nextInt();
			int canPackCnt = s.nextInt();
			if(purchaceCnt==0 && canPackCnt==0)
				return;
			s.nextLine();
			String[] values = s.nextLine().split(" ");
			Integer[] value = new Integer[values.length];
			for(int i=0 ; i<values.length ; i++){
				value[i] = new Integer(values[i]);
			}
			System.out.println(solve(purchaceCnt, canPackCnt, value));
		}
	}

	public static int solve(int purchaceCnt, int canPackCnt, Integer[] values) {
		int value = 0;
		int cnt=0;
		if(purchaceCnt >= canPackCnt){//無料にできる場合
			Arrays.sort(values, Collections.reverseOrder());
			for(int i=0 ; i<purchaceCnt ; i++) {
				cnt++;
				if(cnt==canPackCnt) {
					cnt = 0;
				}else {
					value += values[i].intValue();
				}
			}
		}else{
			Arrays.sort(values);
			for(int i=0 ; i<purchaceCnt ; i++) {
				value += values[i].intValue();
			}
		}
		return value;
	}
}

Measured memory_bytes: 56204
#include <iostream>
using namespace std;
int main()
{
   string s,t;
   cin>>s>>t;
   int i,y=0;
   for(i=0;i<s.size();i++)
   {
       if(s[i]==t[i])
       {
           continue;
       }
       else
       {
           y=1;
           break;
       }
   }
   if(y==0)
   {
       cout<<"Yes";
   }
   else
   {
       cout<<"No";
   }
}

Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = (1<<30)-1;
const ll INF = (1LL<<60)-1;
const ld EPS = 1e-10;
template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;};
template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;};

int main(){
    int N;
    cin >> N;
    ll A[3*N];
    rep(i, 3*N) cin >> A[i];
    ll L[N+1], R[N+1];
    priority_queue<ll, vector<ll>, greater<ll> > que1;
    L[0] = 0;
    rep(i, N){
        que1.push(A[i]);
        L[0] += A[i];
    }
    rep(i, N){
        que1.push(A[N+i]);
        L[i+1] = L[i]+A[N+i]-que1.top(); que1.pop();
    }
    priority_queue<ll> que2;
    R[N] = 0;
    rep3(i, N-1, 0){
        que2.push(A[2*N+i]);
        R[N] += A[2*N+i];
    }
    rep3(i, N-1, 0){
        que2.push(A[N+i]);
        R[i] = R[i+1]+A[N+i]-que2.top(); que2.pop();
    }
    ll ans = -INF;
    rep(i, N+1) chmax(ans, L[i]-R[i]);
    cout << ans << endl;
}

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

#define int long long int 

int32_t main()
{

  int a,b,c,k;
  cin>>a>>b>>c>>k;
  cout<< max({a,b,c})*pow(2,k)+(a+b+c-max({a,b,c}))<<endl;
}


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

using namespace std;
#define int long long int
#define vi vector<int>
#define vlli vector<long long int>
#define si set<int>
#define loop(i,k,n) for(int i=k;i<n;i++)
#define MOD 1000000007
#define r0 return 0
/*
//gcd in O(log(a))
int gcd(int a, int b)
{
    if (a == 0)
        return b;
    return gcd(b % a, a);
}
*/
/*
int gcd, x, y;

void extendedEuclid (int a, int b)
{
    if (b==0)
    {
        x=1;
        y=0;
        gcd=a;
        return;
    }
    extendedEuclid(b, a%b);
    int x1=y;
    int y1=x-(a/b)*y;
    x=x1;
    y=y1;
}

int nCr (int n, int r)
{
    int p=1, k=1, modInv;
    if (n-r<r)
        r=n-r;
    if (r!=0)
    {
        while (r)
        {
            p=(p*n)%MOD;
            k*=r;
            n--;
            r--;
        }
        extendedEuclid(k, MOD);
        modInv=(x+MOD)%MOD;
        p=(p*modInv)%MOD;
    }
    else
        p=1;
    return p;
}
*/
int n;
int a[100001],b[100001],c[100001];
int memo[100001][4];

int32_t main(void)
{
    int t=1;
    //cin>>t;
    while(t--)
    {
        //int n;
        cin>>n;
        for(int i=1;i<=n;i++)
            cin>>a[i]>>b[i]>>c[i];
        memo[1][1]=a[1];
        memo[1][2]=b[1];
        memo[1][3]=c[1];
        for(int i=2;i<=n;i++)
        {
            memo[i][1]=max(memo[i-1][2]+a[i],memo[i-1][3]+a[i]);
            memo[i][2]=max(memo[i-1][1]+b[i],memo[i-1][3]+b[i]);
            memo[i][3]=max(memo[i-1][1]+c[i],memo[i-1][2]+c[i]);
        }
        cout<<max(memo[n][1],max(memo[n][2],memo[n][3]));









    }
}



Measured memory_bytes: 5760
#include <iostream>
//#include <iomanip>
//#include <algorithm>
//#include <numeric>
//#include <queue>
//#include <stack>
//#include <math.h>
#include <vector>
//#include <string>
//typedef long long LL;
using namespace std;

int main(){
    int n;
    int k;
    vector<int> a;
    int tmp_a;
    int a_min;
    int idx;
    int ans;
    int tmp_cov;
    cin >> n >> k;
    for(int i=0; i<n; i++){
        cin >> tmp_a;
        a.push_back(tmp_a);
    }
    tmp_cov=k;
    ans=1;
    while(n>tmp_cov){
        tmp_cov+=k-1;
        ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 892
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>

using namespace std;
typedef long long ll;

int main(){
  int x; cin>>x;
  while(x>0){
    if(x%10==9){
      break;
    }
    x = x/10;
  }
  cout<<(x==0?"No":"Yes")<<endl;
}

Measured memory_bytes: 256
# region header
import sys, bisect, math, itertools, heapq, collections
from operator import itemgetter
# a.sort(key=itemgetter(i)) # i番目要素でsort
from functools import lru_cache
import copy
# @lru_cache(maxsize=None)
# sys.setrecursionlimit(10**8)
input = sys.stdin.readline
INF = float('inf')
mod = 10**9 + 7
eps = 10**-7
# endregion
# region input function


def inp():
    '''
    一つの整数
    '''
    return int(input())


def inpl():
    '''
    一行に複数の整数
    '''
    return list(map(int, input().split()))


def str_inp():
    '''
    文字列をリストとして読み込む
    '''
    return list(input()[:-1])

# endregion


class BinaryIndexedTree:
    def __init__(self, n):
        self.N = n
        self.bit = [0] * (n + 1)  # 1-index

    def sum(self, idx):
        """return sum(a[0]~a[idx])

        Args:
            idx (int): 1-index

        Returns:
            int: sum(a[0]+...+a[i])
        """
        res = 0
        while idx:
            res += self.bit[idx]
            idx -= idx & (-idx)
        return res

    def add(self, idx, x):
        """a[idx]+=x

        Args:
            idx (int): 1-index
            x (int): add value
        """
        while idx <= self.N:
            self.bit[idx] += x
            idx += idx & (-idx)


n, q = inpl()
c = inpl()
query = [inpl() + [i] for i in range(q)]
query.sort(key=itemgetter(1))
rightest = [-1] * (n + 1)
now_q = 0
Bit = BinaryIndexedTree(n)
ans = [0] * q

for i in range(n):
    if rightest[c[i]] != -1:
        Bit.add(rightest[c[i]] + 1, -1)
    rightest[c[i]] = i
    Bit.add(i + 1, 1)

    while now_q < q and query[now_q][1] == i + 1:
        ans[query[now_q][2]] = Bit.sum(query[now_q][1]) - Bit.sum(query[now_q][0] - 1)
        now_q += 1
print("\n".join(map(str, ans)))


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

#define ll long long
#define ld long double
#define ull unsigned long long
#define endl "\n"
#define MohamedMotaz ios::sync_with_stdio(0); cin.tie(0); ios_base::sync_with_stdio(0);
#define f(a, b, c) for(int a = b; a < c; a++)
using namespace std;
const ll mod = 1e9 + 7;



//ll fact[1000001]; ll inv[1000001];
//ll primes[100007];
//ll arr[1000007];
//ll modPower(ll b, ll p) {
//	if (p == 0)
//		return 1;
//
//	ll halfpow = modPower(b, p / 2);
//	ll toReturn = (halfpow * halfpow) % mod;
//	if (p % 2)
//		toReturn = (toReturn * b) % mod;
//
//	return toReturn;
//}
//
//ll fastPower(ll b, ll p) {
//	if (p == 0)
//		return 1;
//	ll ans = fastPower(b, p / 2);
//	ans = (ans * ans);
//	if (p % 2 != 0)
//		ans = (ans * b);
//	return ans;
//}
//ll GcdRecursive(ll a, ll b) {
//	if (b == 0) return a;
//	return GcdRecursive(b, a % b);
//}
//ll modLCM(ll a, ll b) {
//	ll val = GcdRecursive(a, b);
//	ll tmp = ((a % mod) * (b % mod)) % mod;
//	ll finalVal = ((tmp % mod) * (arr[val] % mod)) % mod;
//	return finalVal;
//
//}
//ll LCM(ll a, ll b) {
//	return (a * b) / GcdRecursive(a, b);
//}
//void move1step(ll& a, ll& b, ll q) { // a and b by reference
//	ll c = a - q * b;
//	a = b;
//	b = c;
//}
//ll GcdIterative(ll a, ll b) {
//	while (b) move1step(a, b, a / b);
//	return a;
//}
//
//void pre(ll n) {
//
//	fact[0] = 1;
//	inv[0] = 1;
//
//	for (ll i = 1; i <= n; i++) {
//		fact[i] = (i * fact[i - 1]) % mod;
//		inv[i] = modPower(fact[i], mod - 2);
//		arr[i] = modPower(i, mod - 2);
//	}
//}
//
//ll npr(ll n, ll r) {
//	return ((fact[n] * inv[n - r]) % mod);
//}
//
//ll ncr(ll n, ll r) {
//	return ((((fact[n] * inv[n - r]) % mod) * inv[r]) % mod);
//}
//
//void sieve(ll val) {
//	memset(primes, 1, sizeof primes);
//	primes[0] = primes[1] = false;
//	for (int i = 2; i <= val; i++) {
//		if (primes[i]) {
//			for (int j = i * i; j <= val; j += i) {
//				primes[j] = 0;
//			}
//		}
//	}
//
//}



int main()
{
    MohamedMotaz;
    
    ll a, b, sum = 0, tmp = 0; cin >> a >> b;
    vector<ll> v(a);
    f(i, 0, a) cin >> v[i], sum += v[i];
    sort(v.begin(), v.end(), greater<ll>());
    f(i, 0, b) tmp += v[i];
    ll counter = 0;

    f(i, 0, a) {
        ld calc = (1 / (4.0 * b));
        if (v[i] >= calc * sum) counter++;
    }


    if (counter >= b) cout << "Yes";
    else cout << "No";

    

   
}








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

int a[3001],n,u,v;
vector<int> e[3001];

bool dfs(int x)
{
	for(auto i:e[x])
		if(a[x]>a[i] && !dfs(i))
			return true;
	return false;
}

int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;++i)
		scanf("%d",a+i);
	for(int i=1;i<n;++i)
		scanf("%d%d",&u,&v),
		e[u].push_back(v),e[v].push_back(u);
	for(int i=1;i<=n;++i)
		if(dfs(i))printf("%d ",i);
}

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

int main() {
  int ans = 0;
  string n;
  cin >> n;
  for(int i = 0; i < n.size();i++){
    ans += (int)n[i] - 48;
  }
  if(ans % 9 == 0)cout << "Yes" <<endl;
  else cout << "No" <<endl;
}

Measured memory_bytes: 3692
#include "bits/stdc++.h"
#define ll long long
#define mk make_pair
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pil pair<int,ll>
#define pli pair<ll,int>
using namespace std;
const int MAXN=1e5+9;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	ll a,v,b,w,t;
	cin>>a>>v>>b>>w>>t;
	ll dist=abs(a-b);
	ll speed=v-w;
	ll dist_in_t=(speed*t);
	if(dist_in_t>=dist)
	{
		cout<<"YES"<<endl;
		return 0;
	}
	cout<<"NO"<<endl;
	return 0;
}

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

int main(){
    int arrSizeW, arrSizeL;

    std::cin >> arrSizeW >> arrSizeL;

    int arr[arrSizeL] = {0};

    int foodNum;
    int foodKind;

    for( int k = 0; k < arrSizeW; k++ ){
        std::cin >> foodNum;

        for( int i = 0; i < foodNum; i++ ){
            std::cin >> foodKind;
            for( int j = 0; j < arrSizeL; j++ ){
                if( foodKind - 1 == j ){
                    arr[j]++;
                }
            }
        }
    }



    int counter = 0;
    for( int l = 0; l < arrSizeL; l++ ){
        if( arr[l] == arrSizeW ){
            counter++;
        }
    }

    if( counter == 0 ){
        std::cout << counter << std::endl;
    }
    else{
        std::cout << counter << std::endl;
    }


    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
int a[20], b[20];
using namespace std;
int main(){
    int n, s=0;
    scanf("%d",&n);
    //while(scanf("%d %d", &a, &b)==2)
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    for(int i=0;i<n;i++){
        scanf("%d",&b[i]);
    }
    for(int i=0;i<n;i++){
        if(a[i]>b[i]){
            s=s+a[i]-b[i];
        }
    }
    printf("%d",s);
    return 0;
}


Measured memory_bytes: 256
n = gets.chomp.to_i
t_point = 0
h_point = 0
n.times do
    taro, hanako = gets.chomp.split
    if taro == hanako
        t_point += 1
        h_point += 1
    end
    if taro < hanako
        h_point += 3
    end
    if taro > hanako
        t_point += 3
    end
end
puts "#{t_point} #{h_point}"

Measured memory_bytes: 8796
#include<stdio.h>

void input(int);
void shori(int);

typedef struct{
  int num;
  int have;
  int flag;
  int hakken;
  int kanryou;
  int next[100];
} Data;

int cnt;
Data data[101];

int main(){
  
  int i, n;

  scanf("%d",&n);

  for(i = 1; i <= n; i++)input(i);

  cnt = 1;
  for(i = 1; i <= n; i++)if(data[i].flag == 0)shori(i);
  
  for(i = 1; i <= n; i++)printf("%d %d %d\n",i ,data[i].hakken, data[i].kanryou);
  
  return 0;  
}

void shori(int n)
{
  int i;
  
  data[n].hakken = cnt;
  data[n].flag = 1;
  cnt++;
  
  for(i = 0; i < data[n].have; i++)if(data[n].next[i] != n && data[data[n].next[i]].flag == 0)shori(data[n].next[i]);
  
  data[n].kanryou = cnt;
  cnt++;
}

void input(int n)
{
  int i;

  cnt = 0;
  
  scanf("%d%d",&data[n].num,&data[n].have);

  for(i = 0; i < data[n].have; i++)
    {
      scanf("%d",&data[n].next[cnt]);
      cnt++;
    }
  data[n].flag = 0;
  data[n].hakken = data[n].kanryou = -1;
}



Measured memory_bytes: 2144
n = int(input())
info = [[int(arg) for arg in input().split()] for _ in range(n)]
data = [[0]*10 for _ in range(3*4)]
for i in info:
    b, f, r, v = i
    data[3*(b-1)+f-1][r-1] += v

for i, d in enumerate(data):
    if i != 0 and i % 3 == 0:
        print('#'*20)
    print(' ' + ' '.join([str(i) for i in d]))


Measured memory_bytes: 5608
def kmpTable(w):
    lw = len(w)
    nx = [-1] * (lw + 1)
    j = -1
    for i in range(lw):
        while j >= 0 and w[i] != w[j]:
            j = nx[j]
        j += 1
        nx[i + 1] = j
    return tuple(nx)
def kmpSearch(s, w):
    ls = len(s)
    start = 0
    w_idx = 0
    ret = []
    nx = kmpTable(w)
    while start + w_idx < ls:
        if s[start + w_idx] == w[w_idx]:
            w_idx += 1
            if w_idx == len(w):
                ret.append(start)
                start = start + w_idx - nx[w_idx]
                w_idx = nx[w_idx]
        else:
            if w_idx == 0:
                start += 1
            else:
                start = start + w_idx - nx[w_idx]
                w_idx = nx[w_idx]
    return ret
T = input()
P = input()
ans = kmpSearch(T, P)

if ans:
    print(*ans, sep="\n")
#    print("\n".join(map(str, ans)))	



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

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

using ll = long long;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int INF = 1<<30;

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

int main() {
  int N;
  cin >> N;
  string s;
  cin>>s;
  vector<int> v(N);
  for(int i = 0; i < N; i++){
    if(i==0){
      if(s[i]=='.') v[i]=1;
      if(s[i]=='#') v[i]=0;
    }
    else{
      if(s[i]=='.') v[i]=v[i-1]+1;
      if(s[i]=='#') v[i]=v[i-1];
    }
  }
  int ans = INF;
  for(int i = 0; i <= N;i++){
    if(i==0)chmin(ans,v[N-1]);
    else chmin(ans,i-v[i-1]+v[N-1]-v[i-1]);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 1412
s = list(input())
k = int(input())
one_count = 0
stop_flag = 0

for i in s:
    if i != '1':
        if one_count >= k:
            print(1)
        else:
            print(i)
        stop_flag = 1
        break
    else:
        one_count += 1
        
if stop_flag == 0:
    if one_count >= k:
        print(1)
    else:
        print(0)

Measured memory_bytes: 3060
n, k = map(int, input().split())
# n, k = map(int, "2 6".split())
q = n // k #答え
mod = n % k #あまり

if q == 0:

    while True:
        nc = n
        n = n - k
        if n <= 0:
            if abs(n) < nc:
                print(abs(n))
                break
            else:
                print(nc)
                break
else:
    n1 = abs(n - (q * k))
    n2 = abs(n - ((q + 1) * k))
    if n1 < n2:
        print(n1)
    else:
        print(n2)


Measured memory_bytes: 3060
N = int(input())
H = list(map(int, input().split()))

result = 0
count = 0
before = 0
for i in range(N):
    now = H[i]
    if now <= before:
        count += 1
    else:
        if count > result:
            result = count
        count = 0
    before = now

if count > result:
    result = count

print(result)


Measured memory_bytes: 63856
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    long N = sc.nextLong();

    for(int i =0;i<1000;i++){
      for(int j =0;j<1000;j++){
        long ii = (long)Math.pow(i,5);
        long jj = (long)Math.pow(j,5);
        if(ii-jj==N){
          System.out.println(i +" "+j); 
          return; 
        }else if(ii+jj==N){
          System.out.println(i +" "+-j);
          return;   
        }
      }
    }


    // System.out.println(-1);  
  }
}





Measured memory_bytes: 38636