akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
import java.io.PrintWriter;

public class Main{
	static int[] c=new int[26];
	static int[] lastD=new int[26];
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int d=sc.nextInt();
		for(int i=0; i<26; i++){
			c[i]=sc.nextInt();
		}
		int[][] s=new int[d][26];
		for(int i=0; i<d; i++){
			for(int j=0; j<26; j++){
				s[i][j]=sc.nextInt();
			}
		}
		int maxSati=-Integer.MAX_VALUE/2;
		int maxInd=-1;
		//j:何日目
		for(int j=0; j<d; j++){
			//i:どの大会をやるか
			for(int i=1; i<=26; i++){
				int sati=0;
				lastD[i-1]=j+1;
				sati+=s[j][i-1];
				sati-=subSati(j+1);
				lastD[i-1]=0;
				if(maxSati<sati){
					maxSati=sati;
					maxInd=i;
				}
			}
			System.out.println(maxInd);
			lastD[maxInd-1]=j+1;
			maxSati=-1000000;
			maxInd=-1;
		}
	}
	static int subSati(int d){
		int ret=0;
		for(int i=0; i<26; i++){
			ret+=c[i]*(d-lastD[i]);
		}
		return ret;
	}
}


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

using namespace std;



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

	int n, i, j, k;
	long double x, s;
	string ss;

	cin >> n;
	s = 0;
	while (n--) {
		cin >> x >> ss;
		if (ss == "JPY") s += x;
		else s += 380000.0 * x;
	}

	cout << setprecision(10) << fixed << s << "\n";

	return 0;
}

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

/*連結リストの作成*/
struct node{
  unsigned int key;
  struct node *next;
  struct node *prev;
};

typedef struct node *NodePointer;

NodePointer nil;

NodePointer listSearch(unsigned int key){
  NodePointer x=nil->next;
  while(x!=nil && x->key!=key){
    x = x->next;
  }
  return x;
}

void init(){
  nil = malloc(sizeof(struct node));
  nil->next = nil;
  nil->prev = nil;
}

void printList(){
  NodePointer cur = nil->next;
  int isf = 1;
  while(1){
    if ( cur == nil ) break;
    if ( isf == 0)
      printf(" ");
    printf("%d", cur->key);
    cur = cur->next;
    isf = 0;
  }
  printf("\n");
}

void deleteNode(NodePointer t){
  t->prev->next=t->next;
  t->next->prev=t->prev;
}

void deleteFirst(){
  NodePointer t = nil->next;
  if ( t == nil ) return;
  deleteNode(t);
}

void deleteLast(){
  NodePointer t = nil->prev;
  if ( t == nil ) return;
  deleteNode(t);
}

void delete(unsigned int key){
  NodePointer x;
  x=listSearch(key);
  if(x==nil) return;
  deleteNode(listSearch(key));
}


void insert(unsigned int key){
  NodePointer x;
  x = malloc(sizeof(struct node));
  x->key = key;
  x->next=nil->next;
  nil->next->prev=x;
  nil->next=x;
  x->prev=nil;
  
}

int main(){
  unsigned int key;
  int n, i;
  int size = 0;
  char com[20];
  int np = 0, nd = 0;
  scanf("%d", &n);
  init();
  for ( i = 0; i < n; i++ ){
    scanf("%s%d", com, &key);
    if ( com[0] == 'i' ) {insert(key); np++; size++;}
    else if ( com[0] == 'd' )
      {
	if (strlen(com) > 6)
	  {
	    if ( com[6] == 'F' ) deleteFirst();
	    else if ( com[6] == 'L' ) deleteLast();
	  }
	else
	  {
	    delete(key); nd++; 
	  }
	size--;
      }
  }

  printList();
  return 0;
}



Measured memory_bytes: 36084
import heapq

def solve(n, v):
    q = []
    for i in range(n):
        heapq.heappush(q, v[i])
    for i in range(n-1):
        x = heapq.heappop(q)
        y = heapq.heappop(q)
        heapq.heappush(q, (x+y)/2)
    return heapq.heappop(q)

n = int(input())
v = list(map(int, input().split()))
print(solve(n, v))

Measured memory_bytes: 3060
import static java.lang.System.*;
import java.util.*;

class UnionFind {
    int[] par;
    int[] num;

    UnionFind(int n) { 
    	par = new int[n];
    	num = new int[n];
        for(int i = 0; i < n; i++) {
        	par[i] = i;
        	num[i] = 1;
        }
    }

    int root(int x) {
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) {
        int rx = root(x); 
        int ry = root(y);
        if (rx == ry) return; 

        par[rx] = ry;
        num[ry] += num[rx];
    }

    boolean same(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }

    int getNum(int n) {
    	return num[root(n)];
    }
}

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(in);

        int n = sc.nextInt();
		int m = sc.nextInt();

		UnionFind uf = new UnionFind(n);
		for(int i = 0; i<m; i++) {
			int x = sc.nextInt()-1;
			int y = sc.nextInt()-1;
			int z = sc.nextInt();
			uf.unite(x, y);
		}
		
		HashSet<Integer> set = new HashSet<Integer>();
		for(int i=0; i<n; i++) set.add(uf.root(i));
		
        out.println(set.size());
    }
}


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

using namespace std;

#ifndef ONLINE_JUDGE
  #define pr_vars(...) do { cerr << "DEBUG: line "<< __LINE__ << ": " << __PRETTY_FUNCTION__ << ":  "; \
                            pr_var(split(#__VA_ARGS__, ',').begin(), __VA_ARGS__); } while(0)
#else
  __attribute__ ((constructor)) static void fast_cin() { ios_base::sync_with_stdio(false); cin.tie(0); }
  #define pr_vars(...) do { } while(0)
#endif /* ONLINE_JUDGE */

using ll = int64_t;
using ull = uint64_t;
using mp = pair<ll, ll>;
using mt = tuple<ll, ll, ll>;    // unpack: tie(ll, ll, ll) = mt;

template<typename T, typename R>
istream &operator>> (istream &fin, pair<T, R> &p) { fin >> p.first >> p.second; return fin; }

template<typename T, typename R>
ostream &operator<< (ostream &fout, const pair<T, R> &p)
{ fout << "{" << p.first << ", " << p.second << "} "; return fout; }

template<typename T> ostream &operator<< (ostream &fout, const vector<T> &vec)
{ for (size_t i = 0; i < vec.size(); i++) fout << vec[i] << ' '; return fout; }

template<typename T> ostream &operator<< (ostream &fout, const deque<T> &vec)
{ for (size_t i = 0; i < vec.size(); i++) fout << vec[i] << ' '; return fout; }

template<typename T> ostream &operator<< (ostream &fout, const list<T> &vec)
{ for (auto i: vec) fout << i << ' '; return fout; }

template<typename T> istream &operator>> (istream &fin, vector<T> &vec)
{ for (size_t i = 0; i < vec.size(); i++) fin >> vec[i]; return fin; }

vector<string> split(const string &s, char c) { vector<string> v; ull st = 0, fn = 0, lvl = 0;
for ( ; fn < s.size(); fn++ ) { if (s[fn] == c && lvl == 0) { v.push_back(s.substr(st, fn - st)); st = fn + 1; }
if (s[fn] == '(') { lvl++; } if (s[fn] == ')') { lvl--; } } v.push_back(s.substr(st, fn - st)); return v; }

void pr_var(vector<string>::iterator it) { (void) it; cerr << endl; }
template<typename T, typename... Args> void pr_var(vector<string>::iterator it, T a, Args... args)
{ cerr << *it << "=" << a << "  "; pr_var(++it, args...); }

ll div_ceil(ll n, ll d) { ll res = n / d; if (res >= 0) res += n % d ? 1 : 0; return res; }
ll gcd(ll a, ll b) { a = llabs(a); b = llabs(b); while (a && b) a > b ? a %= b : b %= a; return a + b; }
ll lcm(ll a, ll b) { ll c = gcd(a, b); return c == 0 ? 0 : llabs(a / c * b); }

#define setp(a) fixed << setprecision(a)
const double PI = acos(-1.0);
constexpr double EPS = 1e-6;
constexpr ll INF = numeric_limits<ll>::max();
constexpr ll MOD = 1e9 + 7;

#define FOR(i, n) for (ll i = 0; i < (n); i++)
int main()
{
    ll n; cin >> n;
    vector<ll> a(n + 1); cin >> a;
    vector<ll> b(n); cin >> b;
    ll res = 0;
    for (ll i = n - 1; i >= 0; i--) {
        ll cnt = min(a[i + 1], b[i]);
        a[i + 1] -= cnt;
        b[i] -= cnt;
        res += cnt;
        cnt = min(a[i], b[i]);
        a[i] -= cnt;
        b[i] -= cnt;
        res += cnt;
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 1792
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace tes
{
	class contest
	{
		static void Main(string[] args)
		{
			string input = Console.ReadLine();
			string output = "";
			
			for(int i=0; i<input.Length; i++)
			{
				if(input[i] == 'B')
				{
					if(output.Length > 0) output = output.Substring(0,output.Length-1);
				}
				else output += input[i];
			}

            Console.WriteLine(output);
            
		}

	}
}

Measured memory_bytes: 2648
use std::vec::Vec;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

fn read_touple<T: std::str::FromStr + Copy>() -> (T, T) {
  let v: Vec<T> = read_vec();
  assert_eq!(v.len(), 2);
  (v[0], v[1])
}

fn main() {
   let (n, m) = read_touple::<usize>();
   let h: Vec<usize> = read_vec();
   let mut v = vec![vec![]; n];
   for _ in 0..m {
    let (a, b) = read_touple::<usize>();
    v[a-1].push(b-1);
    v[b-1].push(a-1);
   }

   let mut ans = 0;
   for i in 0..n {
     let now = h[i];
     ans += 1;
     for &j in &v[i] {
        if h[j] >= now {
          ans -= 1;
          break;
        }
     }
   }

   println!("{}", ans);
}


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

	int main()
{

	// 変数
	int a,b,c,ba,cb;
	
	// 入力
	cin >> a >> b >> c;
	
	ba = b - a;
	cb = c - b;
	
	if (ba == cb) {
		cout << "YES" << endl;
	}
	
	else {
		cout << "NO" << endl;
	}
	
    return 0;
}

Measured memory_bytes: 256
x, y = gets.chomp.split(" ").map(&:to_i)
  a = [1,3,5,7,8,10,12]
  b = [4,6,9,11]
  c = [2]
  if a.include? (x)
    if a.include? (y)
      puts 'Yes'
    else
      puts 'No'
    end
  elsif b.include? (x)
    if b.include? (y)
      puts 'Yes'
    else
      puts 'No'
    end
  elsif c.include? (x)
    if c.include? (y)
      puts 'Yes'
    else
      puts 'No'
    end
  end


Measured memory_bytes: 1788
#include<bits/stdc++.h>
#include<iomanip>
#include<numeric>

using namespace std;
using ll = long long;
constexpr int mo = 1e9+7;
constexpr int  mod = mo;
constexpr int inf = 1<<30;
constexpr ll infl = 1ll<<60;
constexpr int mo2 = 998244353;
int main(){
    int n,m;
    cin>>n>>m;
    vector<int> ke(m);
    vector<int> open(1<<n,inf);
    for(int i=0;i<m;++i){
        int a,b;
        cin>>a>>b;
        int lock = 0;
        for(int j=0;j<b;++j){
            int box;cin>>box;
            box--;
            lock |= 1<<box;
        }
        open[lock] = min(open[lock],a);
        ke[i] = lock;
    }
    vector<ll> dp(1<<n,infl);
    dp[0] = 0ll;
    for(int mask=0;mask<1<<n;++mask){
        for(int i=0;i<m;++i){
            if(dp[mask] != inf)dp[mask|ke[i]] = min(dp[mask|ke[i]],dp[mask] + open[ke[i]]);
        }
    }
    
    ll ret =dp[(1<<n)-1]; 
    if(ret == infl) cout << -1 << endl;
    else cout << ret << endl;
    return 0;
}



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

int main(){
  string s;
  cin >> s;
  int i;
  int x;
  x=700;
  for(i=0;i<3;i++){
    if(s.at(i)=='o'){
      x+=100;
    }
  }
      cout << x << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;
class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int max = 0;
    int min = 123;
    int input;
    for(int i = 0; i < 5; i++){
      input = sc.nextInt();
      max = Math.max(max,input);
      min = Math.min(min,input);
    }
    int k = sc.nextInt();
    if(k >= max - min){
      System.out.println("Yay!");
    }else{
      System.out.println(":(");
    }
  }
}

Measured memory_bytes: 21844
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Atcoder
{
    class Atcoderrrrrrr
    {
        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split(' ');
            int N = int.Parse(s[0]);
            int X = int.Parse(s[1]);

            List<int> Donut = new  List<int>();
            for(int i=0;i<N;i++){
                Donut.Add(int.Parse(Console.ReadLine()));
            }
            Console.WriteLine(
                (X-Donut.Sum())/Donut.Min() + Donut.Count()
            );
        }
    }
}


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

void doRoutine() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    srand(322179);
#ifdef LOCAL
    freopen("/home/max/alg/clion_main/input.txt", "rt", stdin);
    freopen("/home/max/alg/clion_main/output.txt", "wt", stdout);
#endif
}

#define DBG(VAR) cerr << #VAR << ": " << VAR << endl

#define all(x) x.begin(), x.end()
#define vb vector<bool>
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define fi first
#define se second
#define pb push_back
#define vc vector
#define $ make_pair

#ifndef LOCAL
#define cerr if(0) cerr
#define DBG(...) (true)
#endif

#define D double
#define CD complex<D>
#define ll long long

// ----------------------------- CODE NOW ------------------------


const int MAXN = 1005;
int a[MAXN][MAXN];
int n;



signed main() {
    doRoutine();

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

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

    int d = 0;
    set<pii> st;
    for (int i = 0; i < n; ++i) {
        if (cur[cur[i]] == i && i < cur[i]) {
            st.insert({i, cur[i]});
        }
    }

    int cnt = 0;
    while (cnt < n * (n - 1) / 2 && !st.empty()) {
        set<pii> new_st;
        for (auto e : st) {
            ++ptr[e.fi];
            if (ptr[e.fi] < n - 1) {
                cur[e.fi] = a[e.fi][ptr[e.fi]];
            }
            ++ptr[e.se];
            if (ptr[e.se] < n - 1) {
                cur[e.se] = a[e.se][ptr[e.se]];
            }

            if (ptr[e.fi] < n - 1 && cur[cur[e.fi]] == e.fi) {
                new_st.insert({e.fi, cur[e.fi]});
            }
            if (ptr[e.se] < n - 1 && cur[cur[e.se]] == e.se) {
                new_st.insert({e.se, cur[e.se]});
            }
        }
        cnt += st.size();
        st = new_st;
        ++d;
    }

    if (cnt == n * (n - 1) / 2) {
        cout << d << endl;
    }
    else {
        cout << -1 << endl;
    }

    return 0;
}

Measured memory_bytes: 4224
#include <stdio.h>
#include <stdlib.h>

int main()
{
	int i, j, N, A[101], max = 0;
	scanf("%d", &N);
	for (i = 1; i <= N; i++) scanf("%d", &(A[i]));
	for (i = 1; i < N; i++) {
		for (j = i + 1; j <= N; j++) if (abs(A[i] - A[j]) > max) max = abs(A[i] - A[j]);
	}
	printf("%d\n", max);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 1736
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

int main()
{
	int n;
	int a, b = -1;
	int count = 0;
	
	
	std::cin >> n;
	std::vector<int> P;
	std::vector<int> Q;
	std::vector<int> V;

	for (int i = 0; i < n; i++)
	{
		int p;
		std::cin >> p;
		P.push_back(p);
		V.push_back(i + 1);
	}
	for (int i = 0; i < n; i++)
	{
		int p, q;
		std::cin >> q;
		Q.push_back(q);
	
	}

	do
	{
		bool flag = true;
		for (int i = 0; i < n; i++)
		{
			if (V.at(i) != P.at(i))
				flag = false; 
		}
		if (flag)
			a = count;
		flag = true;
		for (int i = 0; i < n; i++)
		{
			if (V.at(i) != Q.at(i))
				flag = false;
		}
		if (flag)
			b = count;
		count++;
	}while (std::next_permutation(V.begin(), V.end()));

	
	std::cout << abs(a - b) << '\n';
		

}

Measured memory_bytes: 256
while True:
    n, x = map(int, input().split())

    if n == 0 and x == 0:
        break

    ans = 0
    for i in range(1, n+1):
        for j in range(i+1, n+1):
            for k in range(j+1, n+1):
                if i + j + k == x:
                    ans += 1
    print(ans)


Measured memory_bytes: 5592
#[macro_use]
mod input {

use std;
use std::io;

const SPLIT_DELIMITER: char = ' ';

#[macro_export]
#[allow(unused_macros)]
macro_rules! input {
    ( $($x:expr ),*) => {
        {
            let temp_str = input_line_str();
            let mut split_result_iter = temp_str.split_whitespace();
                $(
                let buf_split_result = split_result_iter.next();
                let buf_split_result = buf_split_result.unwrap();
                    ($x) = buf_split_result.parse().unwrap();
                )*
        }
    };
}

#[allow(dead_code)]
pub fn input_line_str() -> String {
    let mut s = String::new();
    io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

#[allow(dead_code)]
pub fn p<T>(t: T)
where
    T: std::fmt::Display,
{
    println!("{}", t);
}

#[allow(dead_code)]
pub fn input_vector2d<T>(line: usize) -> Vec<Vec<T>>
where
    T: std::str::FromStr,
{
    let mut v: Vec<Vec<T>> = Vec::new();

    for _ in 0..line {
        let vec_line = input_vector();
        v.push(vec_line);
    }
    v
}

#[allow(dead_code)]
pub fn input_vector<T>() -> Vec<T>
where
    T: std::str::FromStr,
{
    let mut v: Vec<T> = Vec::new();

    let s = input_line_str();
    let split_result = s.split(SPLIT_DELIMITER);
    for z in split_result {
        let buf = match z.parse() {
            Ok(r) => r,
            Err(_) => panic!("Parse Error"),
        };
        v.push(buf);
    }
    v
}

#[allow(dead_code)]
pub fn str2vec(s: &str) -> Vec<char> {
    let mut v: Vec<char> = Vec::new();
    for c in s.chars() {
        v.push(c);
    }
    v
}
}

use input::*;

fn main() {
    let n: usize;
    input!(n);
    let v = input_vector::<f64>();
    let mut ans = 0.0;
    for z in v {
        ans += 1.0 / z;
    }
    p(1.0 / ans);
}

Measured memory_bytes: 4352
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ProCon
{
    class Program
    {
        static void Main(string[] args)
        {
            string inStr = Console.ReadLine();
            string ret = string.Empty;

            switch(inStr)
            {
                case "SUN":
                    ret = "7";
                    break;
                case "MON":
                    ret = "6";
                    break;
                case "TUE":
                    ret = "5";
                    break;
                case "WED":
                    ret = "4";
                    break;
                case "THU":
                    ret = "3";
                    break;
                case "FRI":
                    ret = "2";
                    break;
                case "SAT":
                    ret = "1";
                    break;
            }
            Console.WriteLine(ret);
        }
    }
}


Measured memory_bytes: 13152
s = input()
map = {'SSS': 0, 'SSR': 1, 'SRS': 1, 'RSS': 1, 'SRR': 2, 'RSR': 1, 'RRS': 2, 'RRR': 3}
for key in map.keys():
    if s == key:
        print(map[key])
        break

Measured memory_bytes: 9108
#include<bits/stdc++.h>
using namespace std;
namespace mine
{
    typedef long long ll;
    #define pr pair<int,int>
    #define FR first
    #define SE second
    #define MP make_pair
    #define PB push_back
    #define vc vector
    #define all(x) (x).begin(),(x).end()
    #define sz(x) ((int)(x).size())
    #define bin(x) (1ll<<(x))
    #define GG(x) if(x) {puts("error");exit(666);}
    #define fo(i,l,r) for(int i=(l),I=(r);i<=I;i++)
    #define fd(i,r,l) for(int i=(r),I=(l);i>=I;i--)
    ll qread()
    {
        ll ans=0,f=1;char c=getchar();
        while(c<'0' or c>'9') {if(c=='-')f=-1;c=getchar();}
        while('0'<=c and c<='9') ans=ans*10+c-'0',c=getchar();
        return ans*f;
    }
    void write(ll num)
    {
        if(num<0) putchar('-'),num=-num;
        if(num>=10) write(num/10);
        putchar('0'+num%10);
    }
    void write1(ll num){write(num);putchar(' ');}
    void write2(ll num){write(num);putchar('\n');}
    template<typename T> void chmax(T &x,const T y) {x=(x>y?x:y);}
    template<typename T> void chmin(T &x,const T y) {x=(x<y?x:y);}
    ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}

    const int INF=0x3f3f3f3f;
    const int MOD=998244353;
    inline int mm(const int x){return x>=MOD?x-MOD:x;}
    template<typename T> inline void add(T &x,const T y){x=mm(x+y);}
    inline ll qpower(ll x,ll e){ll ans=1;GG(e<0);while(e){if(e&1)ans=ans*x%MOD;x=x*x%MOD;e>>=1;}return ans;}
    ll invm(ll x){return qpower(x,MOD-2);}
    const int N=1e4+10;

    int a[N][30];
    int ask(int l,int r)
    {
        // printf("(%d,%d)\n",l,r);
        int lg=log2(r-l+1);
        return min(a[l][lg],a[r-bin(lg)+1][lg]);
    }
    void main()
    {
        int n=qread(),x=qread();
        memset(a,0x3f,sizeof a);
        fo(i,0,n-1) a[i][0]=qread();
        fo(j,1,20) fo(i,0,n-bin(j)) a[i][j]=min(a[i][j-1],a[i+bin(j-1)][j-1]);

        ll ans=1ll<<60;
        fo(k,0,n)//左移k格
        {
            ll now=0;
            fo(i,0,n-1)
            {
                if(i<k) now+=min( ask(0,i),ask(n-1-(k+1-i-1)+1,n-1) );
                else now+=ask(i-k,i);
            }
            chmin(ans,now+1ll*k*x);
        }
        write(ans);
    }
};//(ans+MOD)%MOD
signed main()
{
    srand(time(0));
    mine::main();
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
#define N 2005
#define ll long long
#define pb push_back
#define x first
#define y second
#define all(v) v.begin(),v.end()
using namespace std;
ll n;
vector< pair< ll , ll > > ar;
ll dp[N][N];
ll rec(ll l, ll r){
    if(l>r)return 0;
    if(dp[l][r]!=-1)return dp[l][r];
    int in = l-1 + n - r;
    return dp[l][r] = max(rec(l+1,r)+(ar[in].x*(abs(ar[in].y-l))), rec(l,r-1)+(ar[in].x*(abs(ar[in].y-r))) );
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin>>n;
    ar.resize(n);
    for(int i=0;i<n;i++){
        cin>>ar[i].x;
        ar[i].y = i;
    }
    sort(all(ar));
    reverse(all(ar));
    memset(dp,-1,sizeof(dp));
   cout<< rec(0,n-1);
    
    
    return 0;
}


Measured memory_bytes: 35228
def main():
    from itertools import accumulate
    N, Q = (int(i) for i in input().split())
    S = [s for s in input()]
    A = [0]*N
    for i in range(1, N):
        if S[i-1] == "A" and S[i] == "C":
            A[i] += 1
    acc = list(accumulate([0] + A))

    for _ in range(Q):
        le, ri = (int(i) for i in input().split())
        ans = acc[ri] - acc[le-1]
        if 0 < le and S[le-2] == "A" and S[le-1] == "C":
            ans -= 1
        print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 87636
def BubbleSort(A):
    n = len(A)
    ans = 0
    for i in range(n):
        for j in range(n-1, i, -1):
            if A[j] < A[j-1]:
                A[j], A[j-1] = A[j-1], A[j]
                ans += 1
    print(' '.join([str(i) for i in A]))
    print(ans)

_ = input()
BubbleSort([int(i) for i in input().split()])


Measured memory_bytes: 5608
def fac(n):  #nは2以上
    a=[]
    t=n
    if t%2==0:
        count=0
        while t%2==0:
            count+=1
            t//=2
        a.append([2,count])

    for i in range(3,n+1,2):
        if i*i>n:
            break
        if t%i==0:
            count=0
            while t%i==0:
                count+=1
                t//=i
            a.append([i,count])

    if t!=1:
        a.append([t,1])
    
    return a


from sys import stdin
def main():
    #入力
    readline=stdin.readline
    n=int(readline())
    li=fac(n)
    ans=0
    for i in range(len(li)):
        p=li[i][0]
        cnt=1
        while li[i][1]>=cnt:
            ans+=1
            n//=(p**cnt)
            li[i][1]-=cnt
            cnt+=1

    print(ans)

if __name__=="__main__":
    main()

Measured memory_bytes: 9276
using System;
using System.Collections.Generic;

namespace CSharp
{
    class Program
    {
        static void Main()
        {
            var c = new Dictionary<char, char>()
            {
                {'A', 'T'},
                {'T', 'A'},
                {'G', 'C'},
                {'C', 'G'}
            };

            var b = Console.ReadLine().ToCharArray();

            Console.WriteLine(c[b[0]]);
        }
    }
}


Measured memory_bytes: 13152
import bisect
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

A.sort()
C.sort()
ans = 0
for i in range(N):
    #print(bisect.bisect_left(A, B[i]), bisect.bisect_right(C, B[i]))
    ans += bisect.bisect_left(A, B[i])*(N-bisect.bisect_right(C, B[i]))
print(ans)

Measured memory_bytes: 23232
initial=list( map(int,input().split()))
change=initial

def East(a,b,c,d,e,f):
    return [d, b, a, f, e, c]

def West(a,b,c,d,e,f):
    return [c, b, f, a, e, d]

def South(a,b,c,d,e,f):
    return [e, a, c, d, f, b]

def North(a,b,c,d,e,f):
    return [b, f, c, d, a, e]



a=input()

for idx in range(0, len(a)):
    if a[idx]=="E":
        change=East(*change)
    elif a[idx]=="W":
        change=West(*change)
    elif a[idx]=="S":
        change=South(*change)
    elif a[idx]=="N":
        change=North(*change)
print(change[0])


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

int main(){
    int n;
    string s;
    cin >> n;
    cin >> s;
    int ans = 0;
    for(int i = 0; i < n-2; i++){
        if(s[i] == 'A' && s[i+1] == 'B' && s[i+2] == 'C') ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
	int n, k;
	char s[50];

	scanf("%d %d", &n, &k);
	scanf("%s", s);
	for (int i = 0; i < n; i++) {
		if (i == k - 1) {
			switch (s[i]) {
			case 'A':	s[i] = 'a';		break;
			case 'B':	s[i] = 'b';		break;
			case 'C':	s[i] = 'c';		break;
			}
		}
	}
	printf("%s", s);
	return 0;
}

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

int main()
{
    int t;
    int a,b;
    cin>>t>>a>>b;
    int bb[3];
    for(int i=0;i<3;i++)bb[i]=0;
    for(int i=0;i<t;i++)
    {
        int r;
        cin>>r;
        if(r<=a)bb[0]++;
        else
        if(r>a&&r<=b)bb[1]++;
        else
        bb[2]++;
        
    }
    int ans=0;
    ans=min(bb[0],min(bb[1],bb[2]));
    cout<<ans<<endl;
    
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<int> d(n);
  int i,j;
  int cnt = 0;
  for(i=0;i<n;i++) cin >> d[i];
  for(i=0;i<n-1;i++){
    for(j=i+1;j<n;j++){
      cnt += d[i]*d[j];
    }
  }
  cout << cnt << "\n";
  return 0;
}

Measured memory_bytes: 3648
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using static System.Console;
using static System.Math;

namespace abc167A
{
  public class MainClass
  {
    public static void Main(string[] args)
    {
      long[] inputs = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
      long N = inputs[0];
      long M = inputs[1];
      long X = inputs[2];
      long ans = 1001001001,now = 0;
      long[] C = new long[N];
      long[] sum = new long[M];
      long[,] A = new long[N, M];
      bool ok = true;
        
      for(int i = 0; i < N; i++){
        inputs = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
        C[i] = inputs[0];
        for(int j = 1; j < M + 1; j++){
          A[i,j-1] = inputs[j];
        }
      }
      for(int i = 0;i < Math.Pow(2,N); i++){
        ok = true;
        now = 0;
        Array.Clear(sum,0,sum.Length);
        for(int j = 0; j < N; j++){
          if((i>>j)%2 == 1){
            now += C[j];
            for(int k = 0; k < M; k++){
              sum[k] += A[j,k];
            }
          }
        }
        for(int k = 0; k < M; k++){
          if(sum[k] < X){ok = false;}
        }
        if(ok){ans = Math.Min(ans,now);}
    　}
      if(ans == 1001001001){Console.WriteLine(-1);}
      else{Console.WriteLine(ans);}
    }
  }
}

Measured memory_bytes: 28496
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define P pair<int,int>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000
#define MOD 1000000007
#define all(v) v.begin(),v.end()
#define pb push_back
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int kaijo[2000010];
struct edge{int to,cost;};
int gcd(int a,int b){
	if(b==0)return a;
	return gcd(b,a%b);
}
int lcm(int a,int b){
	return a/gcd(a,b)*b;
}
bool prime(int a){
	if(a==1)return false;
	for(int i=2;i*i<=a;i++){
		if(a%i==0)return false;
	}
	return true;
}
bool kosa(double ax,double ay,double bx,double by,double cx,double cy,double dx,double dy){
	double ta=(cx-dx)*(ay-cy)+(cy-dy)*(cx-ax);
	double tb=(cx-dx)*(by-cy)+(cy-dy)*(cx-bx);
	double tc=(ax-bx)*(cy-ay)+(ay-by)*(ax-cx);
	double td=(ax-bx)*(dy-ay)+(ay-by)*(ax-dx);
	return tc*td<0&&ta*tb<0;
}
void init_fact(){
	kaijo[0]=1;
	for(int i=1;i<=2000000;i++){
		kaijo[i]=kaijo[i-1]*i;
		kaijo[i]%=MOD;
	}
}
int modpow(int a,int b){
	if(b==0)return 1;
	if(b%2)return modpow(a,b-1)*a%MOD;
	int memo=modpow(a,b/2);
	return memo*memo%MOD;
}

int comb(int a,int b){
	if(!kaijo[0])init_fact();
	return kaijo[a]*modpow(kaijo[a-b],MOD-2)%MOD*modpow(kaijo[b],MOD-2)%MOD;
}
int inv(int x){
	x=modpow(x,MOD-2);
	return x;
}
int x,y;
signed main(){
	cin>>x>>y;
	if(2*y<x||2*x<y||(x+y)%3){
		cout<<0<<endl;
		return 0;
	}
	init_fact();
	int a=y-(x+y)/3,b=x-(x+y)/3;
	cout<<kaijo[a+b]*inv(kaijo[a])%MOD*inv(kaijo[b])%MOD<<endl;
	return 0;
}


Measured memory_bytes: 15872
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a,b,c,d;
	int e,f;
	cin >> a >> b >> c >> d;
	if(a>b){
		e=b;
	}else{
		e=a;
	}
	if(c>d){
		f=d;
	}else{
		f=c;
	}
	cout << e+f << endl;
}
		

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <iomanip>
#include <cmath>
using namespace std;

void solve(){
  int n, q; cin >> n >> q;
  vector<vector<int> > v(n + 1);
  vector<long long> ans(n + 1, 0), sr(n + 1, 0);
  vector<bool> visited(n + 1, false);
  for(int i = 0; i < n - 1; i++){
    int a, b; cin >> a >> b;
    v[a].push_back(b);
    v[b].push_back(a);
  }
  for(int i = 0; i < q; i++){
    int p, x; cin >> p >> x;
    sr[p] += x;
  }

  queue<int> qu;
  qu.push(1);
  ans[1] += sr[1];
  visited[1] = true;
  while(qu.size() > 0){
    int c = qu.front();
    qu.pop();
    for(int j = 0; j < v[c].size(); j++){
      int nx = v[c][j];
      if(visited[nx] == true) continue;
      qu.push(nx);
      ans[nx] += ans[c] + sr[nx];
      visited[nx] = true;
    }
  }

  for(int i = 1; i <= n; i++){
    if(i != 1) cout << " ";
    cout << ans[i];
  }
  cout << endl;
  return;
}

int main(){
  solve();
  return 0;
}


Measured memory_bytes: 17908
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;
typedef vector<vpll> vvpll;
#define mp make_pair
#define pb push_back
const ll x=100000000;
ll mx(ll a,ll b){if(a>=b) return a;return b;}
ll mn(ll a,ll b){if(a<b) return a;return b;}
ll dp[100005];
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    ll n;cin>>n;
    ll dpa=0,dpb=0,dpc=0;
    ll ta=0,tb=0,tc=0;
    for(ll i=0;i<n;i++){
        ll a,b,c;
        cin>>a>>b>>c;
        ta=mx(dpb,dpc)+a;
        tb=mx(dpa,dpc)+b;
        tc=mx(dpa,dpb)+c;
        dpa=ta;
        dpb=tb;
        dpc=tc;
    }
    cout<<mx(dpa,mx(dpb,dpc))<<endl;
    return 0;
}



Measured memory_bytes: 256
import kotlin.math.min

fun main() {
    var (a,b,c,k) = readLine()!!.split(" ").map { it.toInt() }
    val l = arrayOf(a,b,c)
    val arr = arrayOf(1,0,-1)
    var ans = 0L
    for(i in 0 until 3) {
        val num = min(k, l[i])
        ans += num * arr[i]
        k -= min(l[i], k)
        if(k <= 0)
            break
    }
    print(ans)
}

Measured memory_bytes: 36356
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

int main(){
    int n, d, x;
    cin >> n >> d >> x;

    int ans = x;
    for(int i = 0; i < n; i++){
        int a;
        cin >> a;
        for(int j = 0; j*a+1 <= d; j++){
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main() {
	//min(a,b)...a,bの小さいほう
	//max(a,b)...     大きいほう
	int a;
	int b;
	int c;
	//int d;
	int e;
	std::cin >> a;
	std::cin >> b;
	std::cin >> c;
	cout << (a - b) % c << "\n";
	std::cin >> e;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define sz(v)   ((int)(v).size())
#define  all(v)    ((v).begin()),((v).end())
#define  allr(v)    ((v).rbegin()),((v).rend())
#define   pb         push_back
#define   mp         make_pair
#define    clr(v,d)      memset( v, d ,sizeof(v))
#define     PI                       acos(-1)
typedef  long long     ll ;
typedef  unsigned long long ull;
const double eps= (1e-9);
using namespace std;
int dcmp(long double a,long double b){   return fabsl(a-b)<=eps ? 0: (a>b)? 1:-1  ;}
int getBit(ll num, int idx) {return ((num >> idx) & 1ll) == 1;}
int setBit1(int num, int idx) {return num | (1<<idx);}
ll setBit0(ll num, int idx) {return num & ~(1ll<<idx);}
ll flipBit(ll num, int idx) {return num ^ (1ll<<idx);}
void GO(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);}
int countNumBit1(int mask) {int ret=0; while (mask) 	{mask &= (mask-1);++ret;	}return ret;}
const int N=3000+5,mod=1e9+7;
string s;
int main(){
    GO();

    int T;
    T=1;
    while(T--){
        cin>>s;
        ll ans=0;
        for(int i=0;i<sz(s);i++){
            ans=(ans+(s[i]-'0'))%9;
        }
        if(ans==0) cout<<"Yes\n";
        else{
            cout<<"No\n";
        }

    }

}





























































































































































































Measured memory_bytes: 3704
#include <bits/stdc++.h>
using namespace std;
const long long MAXx = 1e7 + 10;
long long n, sum;
int main() {
	cin >> n;
	if (n < MAXx) {
		for (int i = 1; i <= n; i++)
			if (n % i == n /i)
				sum += i;
		return cout << sum,0;
		
	}
	for (long long i = 1; i * i <= n; i++)
		if (n % i == 0 && n / i != i) {
			sum += max(n/i, i) -1;
		}
	cout << sum;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, e) for(int (i) = 0; (i) < (e); ++(i))
#define FOR(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define ALL(c) (c).begin(), (c).end()
#define PRINT(x) cout << (x) << "\n"
using namespace std;
using ll = long long; using pint = pair<int, int>; using pll = pair<ll, ll>;
template<typename T> auto compare = [](T x, T y) -> bool{return (x < y);};
const int MOD = 1000000007;

signed main(){
    string A;
    cin >> A;
    ll len = A.length();
    map<char, ll> mp;
    for(auto a : A) mp[a]++;
    ll ans = len * (len - 1) / 2 + 1;
    for(auto p : mp){
        ans -= p.second * (p.second - 1) / 2;
    }
    PRINT(ans);
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c,d,x;
  cin >> x;
  a=x/1000;
  b=x/100-a*10;
  c=x/10-a*100-b*10;
  d=x%10;
  bitset<3> hate;
  vector<int> vec={b,c,d};
  for(int i=0;i<8;i++){
    bitset<3> s(i);
    int sum=a;
    for(int j=0;j<3;j++){
      if(s.test(j))
        sum+=vec.at(j);
      else
        sum-=vec.at(j);
    }
    if(sum==7){
      hate=s;
      break;
    }
  }
  cout << a;
  for(int i=0;i<3;i++){    
    if(hate.test(i))
      cout << '+';
    else
      cout << '-'; 
    cout << vec.at(i);
  }
  cout << "=7" << endl;
}

Measured memory_bytes: 256
import math
import sys

def getinputdata():

    # 配列初期化
    array_result = []
    
    data = input()

    
    array_result.append(data.split(" "))

    flg = 1

    try:


        while flg:

            data = input()

            array_temp = []

            if(data != ""):
                
                array_result.append(data.split(" "))

                flg = 1

            else:

                flg = 0
    finally:


        return array_result





arr_data = getinputdata()

s = arr_data[0][0]

mysum=0

for v in s:
    
    mysum+=int(v)
    
print(mysum)

Measured memory_bytes: 3064
#include <stdio.h>

int main(void) {
  int m,f,r,sum;
  do{
    scanf("%d %d %d",&m,&f,&r);
    sum=m+f;
    if((sum<m||sum<f)&&sum>-2)
      printf("F\n");
    else
      if(sum>=80)
	printf("A\n");
      else if(80>sum&&sum>=65)
	printf("B\n");
      else if(65>sum&&sum>=50||r>=50)
	printf("C\n");
      else if(50>sum&&sum>=30)
	printf("D\n");
      else if(30>sum&&sum>=0)
	printf("F\n");
  }while(m+f+r>-3);
  return 0;
}

Measured memory_bytes: 584
#include <stdio.h>
#include <iostream>
#include <vector>
#include <cassert>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <math.h>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <tuple>
#include <climits>
#include <sstream>
using namespace std;

int main()
{
    int n, tmp, ct = 0;

    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        cin >> tmp;
        if (tmp != i)
        {
            ct++;
        }
    }

    if (ct <= 2)
    {
        cout << "YES";
    }
    else
    {
        cout << "NO";
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pa pair<int,int>
#define maxn 100005
using namespace std;
priority_queue<pa>q;
vector<int>v[maxn];
int A,B,a[maxn];
bool used[maxn],has[maxn];
int main(){
	int n;scanf("%d",&n);for(int i=1;i<n;i++){
		scanf("%d%d",&A,&B);
		v[A].push_back(B);
		v[B].push_back(A);}
	int k;scanf("%d",&k);for(int i=0;i<k;i++){
		scanf("%d%d",&A,&B);
		a[A]=B;has[A]=1;q.push(pa(-B,A));}
	while(!q.empty()){
		B=-q.top().first,A=q.top().second;q.pop();
		used[A]=1;for(int i=0;i<(int)v[A].size();i++)
		if(!used[v[A][i]]&&has[v[A][i]]&&a[v[A][i]]!=B+1){puts("No");return 0;}
		else if(!used[v[A][i]]) used[v[A][i]]=1,a[v[A][i]]=B+1,q.push(pa(-B-1,v[A][i])),has[v[A][i]]=1;}
	puts("Yes");
	for(int i=1;i<=n;i++)printf("%d\n",a[i]);
	return 0;
}


Measured memory_bytes: 8308
n = int(input())
deck = input().split()

bd = list(deck)
for i in range(n):
    for j in reversed(range(i + 1, n)):
        if bd[j][1] < bd[j - 1][1]:
            bd[j], bd[j - 1] = bd[j - 1], bd[j]
print(' '.join(bd))
print('Stable')

sd = list(deck)
for i in range(n):
    mi = i
    for j in range(i, n):
        if sd[j][1] < sd[mi][1]:
            mi = j
    sd[i], sd[mi] = sd[mi], sd[i]
print(' '.join(sd))

if (bd == sd):
    print('Stable')
else:
    print('Not stable')


Measured memory_bytes: 5600
#include<bits/stdc++.h>
using namespace std;
long long a;
int main()
{
	cin >> a;
	long long f=1;
	for(int i=sqrt(a);i>0;i--) {
		if(a%i==0) {
			f=i;
			break;
		}
	}
	//cout << f<<endl;
	cout <<(f-1)+(a/f-1);
	return 0;
} 

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

int main(){
    int counter = 0;
    std::string s;
    std::cin>>s;

    if(s[0]=='1'){
        ++counter;
    }
    if(s[1]=='1'){
        ++counter;
    }
    if(s[2]=='1'){
        ++counter;
    }

    std::cout<<counter<<std::endl;
}

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

int main(){
	int a;cin>>a;
	int fi=a/100;
	int se=a%100;
	if(1<=fi&&fi<=12){
		if(1<=se&&se<=12)cout<<"AMBIGUOUS"<<endl;
		else cout<<"MMYY"<<endl;
	}else{
		if(1<=se&&se<=12)cout<<"YYMM"<<endl;
		else cout<<"NA"<<endl;
	}
}


Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;
using vl = vector<ll>;
using Map = map<ll,ll>;
using Tup = tuple<ll,ll,ll>;
using vvl = vector<vector<ll>>;
#define all(v) v.begin(), v.end()
#define prt(v) cout<<(v)<<"\n";
#define fl cout<<flush;
#define fi(v) get<0>(v)
#define se(v) get<1>(v)
#define th(v) get<2>(v)
#define endl '\n'
template <typename T> inline bool chmax(T &a, const T &b){if (a<b){a=b;return 1;}return 0;}
template <typename T> inline bool chmin(T &a, const T &b){if (a>b){a=b;return 1;}return 0;}
const ll INF=1LL<<60;
const ll MOD=1000000007;
const ll MOD2=998244353;
const ld pi=3.141592653589793238;

signed main(void){
    cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
    ll A;
    cin >> A;
    ll B;
    cin >> B;
    prt((A-1)*(B-1))

    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<n;i++)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define ALL(a) a.begin(),a.end()
int main()
{
    int N;
    cin >> N;
    string S,T,U;
    cin >> S >> T;
    REP(i,N){
        U += S[i];
        U += T[i];
    }
    cout << U << endl;
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Globalization;
using System.Diagnostics;
using static System.Console;
//using System.Numerics;
//using static System.Math;

class Program
{
    static void Main()
    {
        //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
        new Program().solve();
        Out.Flush();
    }
    Scanner cin = new Scanner();
    readonly int[] dd = { 0, 1, 0, -1, 0 }; //→↓←↑
    readonly int mod = 1000000007;


    void solve()
    {
        int fx = 0;
        var S = cin.next;
        int N = int.Parse(S);
        for (int i = 0; i < S.Length; i++)
        {
            fx += S[i] - '0';
        }
        if (N % fx == 0)
        {
            WriteLine("Yes");
        }
        else
        {
            WriteLine("No");
        }
    }

}

class Scanner
{
    string[] s; int i;
    char[] cs = new char[] { ' ' };
    public Scanner() { s = new string[0]; i = 0; }
    public string[] scan { get { return ReadLine().Split(); } }
    public int[] scanint { get { return Array.ConvertAll(scan, int.Parse); } }
    public long[] scanlong { get { return Array.ConvertAll(scan, long.Parse); } }
    public double[] scandouble { get { return Array.ConvertAll(scan, double.Parse); } }
    public string next
    {
        get
        {
            if (i < s.Length) return s[i++];
            string st = ReadLine();
            while (st == "") st = ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return next;
        }
    }
    public int nextint { get { return int.Parse(next); } }
    public long nextlong { get { return long.Parse(next); } }
    public double nextdouble { get { return double.Parse(next); } }
}

Measured memory_bytes: 11092
import java.math.BigDecimal;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        long A = Long.parseLong(scanner.next());
        double B = Double.parseDouble(scanner.next());
        scanner.close();

        BigDecimal num = BigDecimal.valueOf(A);
        num = num.multiply(BigDecimal.valueOf(B));
        num = num.setScale(0, BigDecimal.ROUND_DOWN);

        System.out.println(num.toString());
    }
}


Measured memory_bytes: 27328
// ABC120_A
#include <iostream>
#include <string>
#include <vector>
#include <iterator>
#include <tuple>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <stack>
#include <queue>
#include <algorithm>
#include <functional>  // std::greater<T>()
#include <utility>  // std::swap()
#include <numeric>  // accumulate(ALL(vec), 0)  0 は初期値
#include <bitset>  // static_cast<std::bitset<8>>
#include <sstream>  // std::stringstream
#include <cmath>
#include <climits>  // INT_MIN
#include <cctype>  // std::isdigit()
#include <iomanip>  // std::setprecision()
using namespace std;
using ll = long long;

#define REP(i, n) for (ll i=0; i < n; i++)  // 0 ~ n-1
#define MIN(vec) min_element(vec.begin(), vec.end())  // イテレータのため、値を取り出すときは * を先頭につける
#define MAX(vec) max_element(vec.begin(), vec.end())
#define IDX(vec, element_iter) distance((vec).begin(), element_iter)
#define SUM(vec) accumulate(vec.begin(), vec.end(), 0LL)  // 0 は初期値
#define pll pair<ll, ll>
#define F first
#define S second

int main() {
    // input(sunippets: inpv, inpn)
    ll A, B, C;
    cin >> A >> B >> C;
    
    // calculation
    cout << (B/A-C > 0 ? C: B/A) << "\n";
    
    return 0;
}

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

signed main() {

    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n){
        cin >> a[i];
    }
    
    vector<int> res;
    rep(bit, 1<<n){
        int sum = 0;
        rep(j, n){
            if(bit & (1 << j)){
                sum += a[j];        
            }
        }
        res.push_back(sum);
    }
    sort(all(res));
    
    int q;
    cin >> q;
    rep(i, q){
        int m;
        cin >> m;
        auto it = lower_bound(all(res), m);
        if(it != res.end() && *it == m){
            cout << "yes" << endl;
        }
        else{
            cout << "no" << endl;
        }
    }
    
    return 0;
}



Measured memory_bytes: 11064
#include <iostream>

using namespace std;

int main()
{
    int a , b ;
    cin>>a>>b;
    if(a>=13)
        cout<<b;
    else if(a>=6 && a<=12)
        cout<<b/2;
    else if(a<=5)
        cout<<0<<endl;
    return 0;
}


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

int main() {
  ll Q, H, S, D; cin >> Q >> H >> S >> D;
  H = min(H, 2*Q);
  S = min(S, 2*H);
  D = min(D, 2*S);
  ll N; cin >> N;

  cout << N/2*D + (N%2)*S << endl;
  return 0;
}


Measured memory_bytes: 256
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
from itertools import product
def main():
    n, m = map(int, input().split())
    light_bulbs = {i: [] for i in range(m)}
    for i0 in range(m):
        data = tuple(map(int, input().split()))
        light_bulbs[i0]= data[1:]
    p = tuple(map(int, input().split()))

    pat = tuple(product((0, 1), repeat=n))
    res = 0
    for pate in pat:
        light_on = 0
        for i, bulb in enumerate(light_bulbs.values()):
            turned_switch = 0
            for bulb_switch in bulb:
                turned_switch += pate[bulb_switch - 1]
            if turned_switch % 2 == p[i]:
                light_on += 1
        if light_on == m:
            res += 1
    print(res)

if __name__ == '__main__':
    main()

Measured memory_bytes: 71468
package main

import "fmt"

func main() {
  var n int
  fmt.Scan(&n)
  a := make([]int, n)
  for i := range a {
    fmt.Scan(&a[i])
  }
  countA := 0
  for {
    countB := 0
    for i, b := range a {
      if b%2 == 0 {
        countB++
        a[i] = b / 2
        continue
      }
      break
    }
    if countB == len(a) {
      countA++
      continue
    }
    break
  }
  fmt.Println(countA)
}

Measured memory_bytes: 512
#include <stdio.h>

int main(void)
{
  int a, b, i;
  int coins = 0;

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

  for(i = 0; i < 2; i++){
    if(a >= b){
      coins += a;
      a--;
    } else{
      coins += b;
      b--;
    }
  }

  printf("%d", coins);
}

Measured memory_bytes: 128