akhauriyash/Code-Regression huggingface dataset:
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    use std::collections::HashMap;
    let n: u64 = read();
    let mut k: u64 = read();
    let a: Vec<usize> = (0..n).map(|_| read()).map(|x: usize| x - 1).collect();
    let mut set = HashMap::new();
    set.insert(0, 0);
    let mut p: usize = 0;
    let mut count: u64 = 0;
    let dist: u64;
    let start: usize;
    loop {
        count += 1;
        if count == k {
            println!("{}", a[p]+1);
            return;
        }
        let i = set.get(&(a[p]));
        if i.is_some() {
            dist = count - i.unwrap();
            start = a[p];
            break;
        } else {
            set.insert(a[p], count);
        }
        p = a[p];
    }

    k -= count - dist;
    k %= dist;
    let mut goal: usize = start;
    for _ in 0..k {
        goal = a[goal];
    }
    println!("{}", goal + 1);
}


Measured memory_bytes: 10176
# min(A): リストAの最小値を返す
# A.index(min(A)): リストAの最小値のindexを返す
# リストのスライス A[start:stop]でstart <= i < stopの値を返す．stopの値は含まれない
def SelectionSort(N, A):
   count = 0 # 交換回数カウント変数
   for i in range(0, N-1):
      minj = i
      for j in range(i+1, N): # 未ソート部分から最後まで
         if A[j] < A[minj]:
            minj = j # 最小値のindexを変更
      # print('Before: ', *A)
      if A[minj] < A[i]:
         A[i], A[minj] = A[minj], A[i]
         count+=1
      # print(' After: ', *A)
   return A, count

N = int(input())
A = list(map(int, input().split())) # 「1 2 3…」のような配列入力
ans, count = SelectionSort(N, A)
print(*ans)
print(count)


Measured memory_bytes: 5608
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rrep(i,a,b) for(int i=(int)(a);i>=(int)(b);--i)
#define fore(i,a) for(auto &i:a)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define isin(i,a,b) ((a) <= (i) && (i) < (b))
#define uni(a) (a).erase(unique(all(a)),(a).end())
#define fi first
#define se second
#define pb push_back
#define sz(a) (int)(a).size()
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll  = long long;
using unit= unsigned;
using ull = unsigned long long;
using P   = pair<int,int>;
using vi  = vector<int>;
using vl  = vector<ll>;
using vvi = vector<vi>;
using vp  = vector<P>;
void _main(); int main(){ cin.tie(0); ios::sync_with_stdio(false); _main(); }
template<class T>void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T>void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T>void POSS(T condition){ if(condition) cout << "POSSIBLE" << endl; else cout << "IMPOSSIBLE" << endl; }
template<class T>void Poss(T condition){ if(condition) cout << "Possible" << endl; else cout << "Impossible" << endl; }
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; }
template<class T>T gcd(T a, T b){ if (b==0){ return a; }else{ return gcd(b, a%b); }}
template<class T>T lcm(T a, T b){ return a / gcd(a, b) * b; }
constexpr double eps = 1e-10;
constexpr int inf = INT_MAX / 2;
constexpr ll infl = 1LL << 60;

void _main() {
  int N;
  cin >> N;
  vi d(N);
  rep(i, 0, N) cin >> d[i];
  sort(all(d));

  int med = N / 2;
  int ans = d[med] - d[med-1];
  cout << ans << endl;
}

Measured memory_bytes: 640
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
using namespace std;
#define MAX1 100000
#define MAX2 1000
#define WHITE 0 
#define BLACK 1
#define INFTY (1<<30)

class Node{
    public:
        int t,w;
        Node(){}
        Node(int t,int w):t(t),w(w){}
};

int n;
vector<Node> child[MAX1];
int d[MAX1],color[MAX1];

void bfs(int s){
    color[s]=BLACK;
    for(int i=0;i<child[s].size();i++){
        Node a=child[s][i];
        if(color[a.t]==BLACK) continue;
        else{
            d[a.t]=d[s]+a.w;
            bfs(a.t);
        }
    }
    
}

int findmax(){
    int k=0,x;
    for(int i=0;i<n;i++){
        if(d[i]>k){
            k=d[i];
            x=i;
        }
    }
    return x;
}

int solve(){
    int k=0;
    for(int i=0;i<n;i++){
        if(d[i]>k) k=d[i];
    }
    return k;
}

void reset(){
    for(int i=0;i<n;i++){
        d[i]=0;
        color[i]=WHITE;
    }
}

int main(){
    cin>>n;
    int s,t,w;

    for(int i=0;i<n-1;i++){
        cin>>s>>t>>w;
        child[s].push_back(Node(t,w));
        child[t].push_back(Node(s,w));
    }

    reset();
    bfs(0);

    int start = findmax();
    reset();
    bfs(start);
    cout<<solve()<<endl;
    
    return 0;
    
}


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

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    for(int i = 0; i < N; i++){
        cin >> A.at(i);
    }

    int res = 0;
    bool flag = false;

    while(1){
        for(int i = 0; i < N; i++){
            if(A.at(i) % 2 == 0) A.at(i) /= 2;
            else flag = true;
        }
        if(flag) break;
        else res += 1;
    }

    cout << res << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int d_num(int n) {
    int res = 0;
    while (n > 0) {
        res++;
        n = n / 10;
    }
    return res;
}


int pow_m (int a, int b) {
    int res = 1;
    for (int i=0;i < b; i++) {
        res *= a;
    }
    return res;
}

 int main() {
    int n;
    cin >> n;
    int ans = 0;
    for (int i= 1;i < d_num(n); i++) {
        if (i % 2 == 1) {
            ans += 9 * pow_m(10 , i - 1);
        }
    }
    //cout << ans << endl;
    if (d_num(n) % 2 == 1) {
        ans += n - pow_m(10 , d_num(n) -1) + 1;
    }
    
    cout << ans << endl;


} 



Measured memory_bytes: 256
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys,collections,itertools,re,math,fractions,decimal,random,array,bisect,heapq

# decimal.getcontext().prec = 50
# sys.setrecursionlimit(10000)
# MOD = 10**9 + 7

def solve(f):
    n = f.read_int()
    d = [float('inf')] * n
    d[1] = 1

    que = [(1, 1)]     # (min_dist, vertex)
    heapq.heapify(que)

    while len(que) > 0:
        dist, v0 = heapq.heappop(que)
        if d[v0] < dist: continue

        v1 = (v0*10) % n
        if d[v1] > d[v0]:
            d[v1] = d[v0]
            heapq.heappush(que, (d[v1], v1))

        v2 = (v0+1) % n
        if d[v2] > d[v0] + 1:
            d[v2] = d[v0] + 1
            heapq.heappush(que, (d[v2], v2))

    return d[0]


class Reader(object):
    def __init__(self, filename=None):
        self.file = open(filename) if filename is not None else None
        self.case = 1

    def __readline(self):
        return self.file.next().strip() if self.file else raw_input()

    def next_case(self):
        self.file.next()
        self.case += 1

    def read_int(self): return int(self.__readline())
    def read_float(self): return float(self.__readline())
    def read_long(self): return long(self.__readline())
    def read_decimal(self): return decimal.Decimal(self.__readline())
    def read_str(self): return self.__readline()

    def read_int_list(self): return map(int, self.__readline().split())
    def read_float_list(self): return map(float, self.__readline().split())
    def read_long_list(self): return map(long, self.__readline().split())
    def read_decimal_list(self): return map(decimal.Decimal, self.__readline().split())
    def read_str_list(self): return self.__readline().split()

if __name__ == '__main__':
    filename = sys.argv[1] if len(sys.argv) > 1 else None
    f = Reader(filename)
    if f.file:
        while True:
            print "Case #%d\n"%f.case, solve(f)
            try:
                f.next_case()
            except StopIteration:
                break
    else:
        print solve(f)


Measured memory_bytes: 10008
import java.util.*;

public class Main{

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

        String s = sc.next();
        char[] c = s.toCharArray();
        sc.close();

        int w = 0;
        int gcnt = 0;
        int pcnt = 0;

        for(int i = 0; i < c.length; i++){
            if(pcnt == gcnt){
                if(c[i] == 'p')
                    w--;
                else{
                }
                gcnt++;
            } else if(pcnt < gcnt){
                if(c[i] == 'p'){
                } else{
                    w++;
                }
                pcnt++;
            }
        }
        System.out.println(w);
    }
}

Measured memory_bytes: 26916
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
#define ll          long long
#define endl        "\n"
#define si(a)       scanf("%d",&a)
#define si2(a,b)    scanf("%d%d",&a,&b)
#define sl(a)       scanf("%lld",&a)
#define sl2(a,b)    scanf("%lld%lld",&a,&b)
#define pb          push_back
#define mk          make_pair
#define loop(n)     for(int i=0; i<n; i++)
#define FOR(a,b)    for(int i=a; i<=b; i++)
#define sz          size()
#define ff          first
#define ss          second
#define mem(a,val)  memset(a, val, sizeof(a))
#define md          1000000007
#define pi          acos(-1.0)

ll a[200010], m[1000005];
int main()
{
    ll t,n,i,j,k,l,r,mn=0, mx=1;
    cin>>n;
    ll cnt=0;
    for(int i=0; i<n; i++)
    {
        cin>>a[i]; m[a[i]]++;
    }

    ll f =0;
    for(int i=0; i<n; i++)
    {
        f=0;
        if(m[a[i]]>1) continue;
        for(ll j=1; j*j<=a[i]; j++)
        {

            if(a[i]%j==0)
            {
                if(m[j]>0 && j!=a[i]) f=1;

                ll p=a[i]/j;
                if(m[p]>0 && p!=a[i]) f=1;
            }
        }
        //cout<<a[i]<<" "<<f<<endl;
        if(f==0) cnt++;
    }
  cout<<cnt;
}


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


int main(){
   int y,m,d;
   char a,b;
   cin>>y>>a>>m>>b>>d;
   cout<<(m<=4?"Heisei":"TBD")<<endl;
   return 0;
}

   


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

using namespace std;

void solve()
{
    string S;
    cin >> S;
    int i = 1;
    int n = S.length();
    for(int i = 1; i < n; i++){
        string subS = S.substr(0, n-i);
        int m = subS.length();
        if(m % 2 != 0) continue;
        if(subS.substr(0, m / 2) == subS.substr(m/2, m/2)) {
            cout << m << endl;
            return;
        }
    }
    
    return;
}

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

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <queue>
#include <map>
using namespace std;
typedef long long ll;
const int INF = 1<<30; 
const int MOD = 1e9 + 7;
const int dy[] = {1, 0, -1, 0};
const int dx[] = {0, 1, 0, -1};
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b, c;
    cin >> a >> b >> c;
    if(a + b == c || b + c == a || c + a == b) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}



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

using namespace std;
using ll = long long;
using edge = struct { int to; ll cost; };

#define mod 1000000007
#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(a) (a).begin(), (a).end()
#define INF (1 << 29)

long long combination[10001][10001];

//void initC(int n);
//long long gcd(long long a, long long b);
//long long lcm(long long a, long long b);

void solve()
{
    int n, m;
    cin >> n >> m;
    map<int, pair<bool, int>> map;
    REP(i, m) {
        int p;
        string s;
        cin >> p >> s;
        if(map.find(p) == map.end()) map[p] = make_pair(false, 0);
        if(s == "AC") map[p].first = true;
        if(s == "WA" && !(map[p].first)) map[p].second++;
    }
    int ac = 0, wa = 0;
    for(auto x : map) {
        if(x.second.first) {
            ac++;
            wa += x.second.second;
        }
    }
    cout << ac << " " << wa << "\n";
}

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


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

int main() {
  string S, T;
  cin >> S >> T;
  int ans = 1000;
  for(int i = 0; i < S.size() - T.size() + 1; i++) {
    int count = 0;
    for(int j = i; j < i + T.size(); j++) {
      if(S.at(j) != T.at(j - i)) {
        count++;
      }
    }
    if(count < ans) {
      ans = count;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3588
// luogu-judger-enable-o2
#include<bits/stdc++.h>
#define reg register
#define ll long long
#define inf 0x3f3f3f3f3f3f3f3fll
#define next liuyifan_next
using namespace std;
const ll p=1e9+7;
ll n,m,g[10000005],f[10000005],pow2[10000005],x,y,ans;
inline ll add(reg ll x,reg ll y) 
{
    return (x+=y)>p?x-p:x;
}
int main()
{
    cin>>n>>m;
    f[0]=pow2[0]=1; 
    for(reg ll i=1;i<=m;i++)pow2[i]=(pow2[i-1]<<1)%p; 
    for(reg ll i=1;i<=m;i++)
	{
		cin>>x>>y;
		x--;
		y--;
		g[x]|=(1<<y);
	} 
    for(reg ll s=1;s<1<<n;s++)
	if((s&1)==(s>>1&1))
    for(reg ll u=s;u;u=u-1&s) 
	if((u&1)==(u>>1&1)) 
    {
        ans=1;
        for(reg ll i=0;i<n;i++) 
		if(s>>i&1) 
        {
            if(u>>i&1)ans=ans*pow2[__builtin_popcount(g[i]&(s^u))]%p;
            else ans=ans*(pow2[__builtin_popcount(g[i]&u)]-1)%p; 
        }
        f[s]=add(f[s],f[s^u]*ans%p); 
    }
    cout<<(pow2[m]-f[(1<<n)-1]+p)%p<<endl;
    return 0;
}

Measured memory_bytes: 4352
import sys

N, M = map(int, input().split())
scs = [tuple(map(int, input().split())) for _ in range(M)]

anss = [-1] * N
for s, c in scs:
    s -= 1
    if anss[s] != -1 and anss[s] != c:
        print(-1)
        sys.exit()
    if N >= 2 and s == 0 and c == 0:
        print(-1)
        sys.exit()
    anss[s] = c

for i in range(N):
    if anss[i] == -1:
        if N >= 2 and i == 0:
            anss[i] = 1
        else:
            anss[i] = 0

print(''.join(map(str, anss)))


Measured memory_bytes: 3064
///  ||====================================================================||
///  ||                Name: Ezaz Hossain                                  ||
///  ||                CodeChef: harith_0                                  ||
///  ||                NIT Durgapur                                        ||
///  ||====================================================================||

#include<bits/stdc++.h>
#define ll long long int
#define mod 1000000007
#define MAX 10003
#define pb push_back
// #define mp make_pair
#define F first
#define S second
#define mem(x,y) memset(x,y,sizeof(x))
#define lcm(a,b) (a*b)/__gcd(a,b)
#define set_bit_count(x) __builtin_popcount(x)
#define str_rev(str) reverse(str.begin(),str.end())
#define loop(i,x,y) for(ll i=x;i<y;i++)
#define rloop(i,x,y) for(ll i=x-1;i>=y;i--)
#define fastio ios_base::sync_with_stdio(false); cout.tie(NULL);
using namespace std;
int main()
{
    ll k,a,b;
    cin>>k>>a>>b;
    if(a>b)
        swap(a,b);
    ll div=a/k;
    if((div*k)==a)
        cout << "OK" << endl;
    else if((div+1)*k<=b)
        cout << "OK" << endl;
    else
        cout << "NG" << endl;
}

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

int main() {
    int m, d;
    cin >> m >> d;
    int day = 22;
    int d10 = day/10, d1 = day%10;
    int ans = 0;
    while (day <= d) {
        if (d10 >= 2 && d1 >=2 && d10*d1 <= m) ans++;
        day++;
        d10 = day/10;
        d1 = day%10;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <list>
#include <queue>
#include <algorithm>
#define rep(i, n) for(i = 0; i < (n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define MOD 1000000007
#define PI 3.14159265358979323846
#define INF 1 << 30

using namespace std;
typedef long long ll;
typedef pair<int, int> pp;

int main(void) {
	int num, i;
	ll ans = 0;
	cin >> num;
	vector<ll> d(num);
	rep(i, num)
		cin >> d[i];
	sort(d.begin(), d.end(), greater<ll>());
	queue<ll> que;
	rep(i, num) {
		que.push(d[i]);
		que.push(d[i]);
	}
	que.pop();
	rep(i, num - 1) {
		ans += que.front();
		que.pop();
	}
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 8008
x, y = map(int, input().split())
a = [1, 3, 5, 7, 8, 10, 12]
b = [4, 6, 9, 11]
c = [2]
if (x in a and y in a) or (x in b and y in b) or (x in c and y in c):
  print("Yes")
else:
  print("No")
  

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i = 0; i < (n); i++)
 
int main() {
	string S;
  	cin >> S;
  	if(S[0]==S[1]&&S[1]==S[2]){
    cout << "No";
    }else{
    cout << "Yes" << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define SORT(x) sort(x.begin(),x.end())
#define ALL(x) x.begin(),x.end()
#define rep(i, n) for(int i = 0; i < n; i++)
#define reps(i, m, n) for(int i = m; i < n; i++)
#define repr(i, m, n) for(int i = m; i >= n; i--)
#define INF 1000000007 //1000000000000000003
#define PI (acos(-1))
#define MOD 1000000007
using namespace std;
typedef long long ll;



void Main(){

  int N;
  cin >> N;

  cout<< N*N*N <<"\n";

}


//-----------------------------------
int main(){
  cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
}
//-----------------------------------


Measured memory_bytes: 256
#include <cstdio>
#include <array>
#include <algorithm>
#include <numeric>

int main()
{
    std::array<int, 200005> d;
    std::array<int, 200005> dm;
    int n;

    scanf("%d", &n);
    for (int i = 0; i < n; ++i)
    {
        scanf("%d", &d[i]);
        dm[i] = d[i] - (i + 1);
    }
    std::sort(dm.begin(), dm.begin()+n);
    int b = dm[n / 2];

    int min = 1 << 30;

    long long sum = 0;
    for (int i = 0; i < n; ++i)
    {
        sum += std::abs(d[i] - (b + i + 1));
    }

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


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

#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef complex<double> point;
#define xx real()
#define yy imag()

#define REP(i, a, b) for(int i = (a); i < (int)(b); i++)
#define REPN(i, a, b) for(int i = (a); i <= (int)(b); i++)
#define FA(it, x) for(__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define SZ(x) (int)(x).size()
#define BE(x) (x).begin(), (x).end()
#define SORT(x) sort(BE(x))
#define _1 first
#define _2 second

#define x1 gray_cat_x1
#define y1 gray_cat_y1

template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

#define file "I1"

const double EPS = 1e-9;
const double PI = acos(-1.);
const int INF = 1e9;
const ll MOD = 1e9 + 7;

const int MAXN = 1e5 + 5;

char s[MAXN], t[MAXN];
int n, m;

bool check(int d) {
	for(int i = 0; i < d; i++) {
		if (s[n / d * i] != t[m / d * i]) {
			return false;
		}
	}
	return true;
}

void solve(){
	scanf("%d%d%s%s", &n, &m, &s[0], &t[0]);
	int g = gcd(n, m);
	/*for(int d = g; d >= 1; d--) {
		if (g % d == 0) {
			int fl = 0;
			for(int i = 0; i < d; i++) {
				if (s[n / d * i] != t[m / d * i]) {
					fl = 1;
					break;
				}
			}
			if (!fl) {
				printf("%lld\n", (ll) n / (ll)d * (ll) m);
				return;
			}
		}
	}*/
	if (check(g)) {
		printf("%lld\n", (ll) n / (ll)g * (ll) m);
		return;
	}
	printf("-1\n");
}   

int main(){

    //freopen(file".in", "r", stdin); freopen(file".out", "w", stdout);
    int t = 1;
    //cin >> t;
    while(t--){
        solve();    
    }
}


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



int main() {
	int n,k;
	cin>>n>>k;
	int a[n];
	bool dp[k+1];
	//for(int i=0;i<=k;i++)	dp[i]=false;
	for(int i=0;i<n;i++)	cin>>a[i];
	//for(int i=0;i<n;i++)	dp[a[i]]=true;
	dp[0]=false;
	for(int i=1;i<=k;i++){
	    dp[i]=false;
		for(int j=0;j<n;j++){
			if((i-a[j])>=0 && !dp[i-a[j]])
			    dp[i]=true;
			    
		}
		//dp[i]=!dp[i];
		//cout<<dp[i]<<" ";
	}
	dp[k]?cout<<"First" : cout<<"Second";
	return 0;
}

Measured memory_bytes: 384
#include <stdio.h>

int main(void)
{
	int a, b, c;
	
	scanf("%d %d %d", &a, &b, &c);
	
	if (a + b == 1 || a + b + c == 0){
		printf("Close\n");
	}
	else {
		printf("Open\n");
	}
	
	return (0);
}

Measured memory_bytes: 584
#include<bits/stdc++.h>
using namespace std;
long long int dp[100001];
int main()
{
    long long int n,k;
    cin>>n>>k;
    
    long long int h[n+1];
    h[0]=0;
    for(long long int i=1;i<=n;i++)
    {
        cin>>h[i];
    }
    //  dp[n+1];
    dp[1]=0;
    dp[0]=0;
    
    for(long long int i=2;i<=k;i++)
    {
        dp[i]=dp[i-1] + abs(h[i]-h[i-1]);
        for(long long int j=2;j<i;j++)
        {
        dp[i]=min(dp[i-j]+abs(h[i]-h[i-j]),dp[i]);
        // curr=dp[i];
        }
    }
    
    // cout<<dp[n];
    
    for(long long int i=k+1;i<=n;i++)
    {
        dp[i]=dp[i-1] + abs(h[i]-h[i-1]);
        for(long long int j=2;j<=k;j++)
        {
        dp[i]=min(dp[i-j]+abs(h[i]-h[i-j]),dp[i]);
        // curr=dp[i];
        }
    }
    
    cout<<dp[n];
    
    
}

Measured memory_bytes: 1792
N = int(input())
clis = [];slis =[];flis = []
for i in range(N-1):
    c,s,f = map(int,input().split())
    clis.append(c);slis.append(s);flis.append(f)
for i in range(N):
    count=0
    for i2 in range(N-i-1):
        c=clis[i+i2];s=slis[i+i2];f=flis[i+i2]
        if count <= s:
            count=s+c
        elif (count-s)%f ==0:
            count = count+c
        else:
            count = count + c+f-count%f
    print(count)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){return o<<"("<<p.fs<<","<<p.sc<<")";}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){o<<"sz = "<<vc.size()<<endl<<"[";for(const T& v:vc) o<<v<<",";o<<"]";return o;}
int N,M;
const int MN=100000;
vector<int> G[MN];
bool vis[MN];
int col[MN];
bool dfs(int v,int c){
	if(vis[v]&&col[v]!=c) return 0;
	if(vis[v]) return 1;
	vis[v]=1;
	col[v]=c;
	bool ret = 1;
	for(int u:G[v]){
		bool b=dfs(u,c^1);
		if(!b) ret=0;
	}
	return ret;
}
int main(){
	cin>>N>>M;
	rep(i,M){
		int a,b;
		cin>>a>>b;
		a--,b--;
		G[a].pb(b);
		G[b].pb(a);
	}
	long long A=0,B=0,X=0;
	rep(i,N) if(!vis[i]){
		bool isbip = dfs(i,0);
		if(isbip && G[i].empty()) X++;	//isol
		else if(isbip) A++;
		else B++;
	}
	cout<<2*A*A+B*B+2*A*B+2*N*X-X*X<<endl;
}


Measured memory_bytes: 10112
#include<iostream>
using namespace std;
int main(){
    int n,m,t;
    cin >> n >> m >> t;
    int a[150];
    for(int i = 0;i < n;i++)cin >> a[i];
    
    int loss = m;//begin and end
    for(int i = 0;i < n-1;i++){
        loss += min(2 * m, a[i+1] - a[i]);
    }

    loss += min(m, t - a[n-1]);

    cout << t - loss << endl;
}

Measured memory_bytes: 3104
#include <iostream>
#include <cstring>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <math.h>
#include <string>
#include <map>
#include <cstdlib>
using namespace std;

typedef long long ll;
int euclidean_gcd(int a, int b)
{
    if(a<b) swap(a, b);
    ll r;
    while((r=a%b)!=0){
        a=b;
        b=r;
    }

    return b;
}

int main()
{
    int N, X;
    cin >> N >> X;
    vector<int> x(N);
    for(int i=0; i<N; i++){
        cin >> x[i];
    }
    if(N==1){
        cout << abs(x[0]-X) << endl;
        return 0;
    }
    int ans=euclidean_gcd(abs(x[0]-X), abs(x[1]-X));
    for(int i=2; i<N; i++){
        ans=euclidean_gcd(ans, abs(x[i]-X));
    }
    cout << ans << endl;
    

    return 0;
}

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

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

using namespace std;
using lint=long long;

const double PI=acos(-1);

double SIN[200000];

double area(int i,int j){if(j-i<0) printf("!! i = %d, j = %d\n",i,j); return 2*SIN[i]*SIN[j]*SIN[j-i]; }

int main(){
	int n;
	lint k; scanf("%d%lld",&n,&k);

	rep(i,n) SIN[i]=sin(PI*i/n);

	double lo=0,hi=1.3;
	rep(_,35){
		double mi=(lo+hi)/2;

		lint cnt=0;
		for(int i=1;i<n-1;i++){
			int lo2=i,hi2=(n+i)/2+1;
			while(hi2-lo2>1){
				int mi2=(lo2+hi2)/2;
				if(area(i,mi2)<mi) lo2=mi2;
				else               hi2=mi2;
			}

			int l=lo2;
			int r=n-(l-i);
			cnt+=(l-i)+(n-r)-(l==r?1:0);
		}
		cnt=cnt*n/3;

		if(cnt<k) lo=mi;
		else      hi=mi;
	}
	printf("%.15f\n",lo);

	return 0;
}


Measured memory_bytes: 768
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <list>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <limits>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <numeric>
#include <unordered_set>
#include <unordered_map>
#include <chrono>
#include <random>
#include <bits/stdc++.h>
 
using namespace std;
 
#define ll long long
#define PI 3.14159265358979323846
#define min(a,b) ((a<b)?(a):(b))
#define max(a,b) ((a<b)?(b):(a))
#define abs(a) ((a>0)?a:-(a))
#define pii pair<int,int>

const double eps = (double)1e-6;
const int maxn = 2e5+5;
const ll mod = 1e9+7;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

map<ll,ll> memo;

ll solve(ll h) {
    if (h == 1) return 1;
    if (memo.find(h) != memo.end()) return memo[h];
    memo[h] = 2*solve(h/2)+1;
    return memo[h];
}

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

    ll h; cin >> h;
    cout << solve(h) << endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cstdlib>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

// 入力
int N;
long long a[100010][3]; // a[i], b[i], c[i] をそれぞれまとめて a[i][0], a[i][1], a[i][2] にしてしまう

// DP テーブル
long long dp[100010][3];

int main() {
    int N; cin >> N;
    for (int i = 0; i < N; ++i) for (int j = 0; j < 3; ++j) cin >> a[i][j];

    // 初期化は既に 0 に初期化される
    // 初期条件も既に 0 で OK

    // ループ
    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < 3; ++j) {
            for (int k = 0; k < 3; ++k) {
                if (j == k){
                  continue;
                }
                dp[i+1][k]=max(dp[i + 1][k], dp[i][j] + a[i][k]);
            }
        }
    }

    // 答え
    long long res = 0;
    for (int i = 0; i < 3; ++i) res=max(res, dp[N][i]);
    cout << res << endl;
}


Measured memory_bytes: 4992
# -*- coding: utf-8 -*-

import sys

while True:
    w, h = map(int, sys.stdin.readline().split( " " ) )
    if w == 0 and h == 0:
        break
    table = []
    for i in range(h):
        table.append( sys.stdin.readline() )

    dp = [[0 for i in range(w + 1)] for j in range(h + 1)]
    for i in range( h ):
        for j in range( w ):
            if '0' <= table[ i ][ j ] <= '9' :
                val = ord( table[ i ][ j ] ) - ord( '0' )
                dp[ i + 1 ][ j + 1 ] = max( dp[ i ][ j + 1 ], dp[ i + 1 ][ j ] ) * 10 + val
    print max( [ max( dp[ i ] ) for i in range( h + 1 ) ] )

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

using namespace std;

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

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

const int inf = 0x3f3f3f3f;
const LL infLL = 0x3f3f3f3f3f3f3f3fLL;

const int maxn = 100000 + 5;

int n;
int a[maxn];
int f[maxn][2];

int main() {
  scanf("%d", &n);
  For(i, 1, n) scanf("%d", &a[i]);
  f[1][0] = f[1][1] = true;
  For(i, 2, n) rep(j, 2) {
    rep(k, 2) if (f[i - 1][k] && (a[i] - j) >= (a[i - 1] - k)) f[i][j] = true;
  }
  puts(f[n][0] || f[n][1] ? "Yes" : "No");

  return 0;
}

Measured memory_bytes: 1408
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

int main(){
	int N;
	long long K;
	cin >>N>>K;
	vector<pair<int,int>> V(N);
	
	for(int i=0;i<N;i++){
		int a,b;
		cin >>a>>b;
		V[i]=make_pair(a,b);
	}
	sort(V.begin(),V.end());
	int ans;
	long long count=0;
	for(int i=0;i<N;i++){
		count+=V[i].second;
		if(count>=K){
			ans=V[i].first;
			break;
		}
	}
	cout<<ans;
}

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

int main(){
  int n,i;
  cin>>n;
  int L[n];
  for(i=0;i<n;i++)cin>>L[i];
  sort(L,L+n);
  int sum=0;
  for(i=0;i<n-1;i++){
    sum+=L[i];
  }
  if(sum<=L[n-1])cout<<"No";
  else cout<<"Yes";
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        // int n = Integer.parseInt(sc.next());
        String s = sc.next();

        int ans = 0;
        int tmp = 0;
        for (int i = 0; i < s.length(); i++) {
            if (s.substring(i, i + 1).equals("A") || s.substring(i, i + 1).equals("T")
                    || s.substring(i, i + 1).equals("G") || s.substring(i, i + 1).equals("C")) {
                tmp++;
                ans = Math.max(tmp, ans);
            } else {
                ans = Math.max(tmp, ans);
                tmp = 0;
            }
        }
        System.out.println(ans);
        sc.close();
    }
}

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

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

    int ans = 0;
    for (int i = 1; i <= N; ++i) {
        const std::string s = std::to_string(i);
        int sum = 0;
        for (size_t j = 0; j < s.size(); ++j) {
            sum += (s[j] - '0');
        }

        if (A <= sum && sum <= B) {
            ans += i;
        }
    }

    std::cout << ans << std::endl;

    return 0;
}


Measured memory_bytes: 256
//***The night is the darkest just before the dawn***
 
#include<bits/stdc++.h>
using namespace std;
 
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define ll long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i,n) for(i=0;i<n;i++)
#define forn(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define for1(i, n) for (ll i = 1; i <= (ll)(n); ++i)
#define ford(i, n) for (ll i = (ll)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (ll i = (ll)(a); i <= (ll)(b); ++i)
#define fora(it,x) for(auto it:x)
#define PI 3.14159265
#define sync ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define endl "\n"
 
typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef long double ld;
 
template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

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

	if((s[2]==s[3])&&(s[4]==s[5])) cout<<"Yes";
	else cout<<"No";
}

Measured memory_bytes: 256
import math

def get_nearest_bin(x):
	if x <= 1:
		return x
	y = x
	i=0
	while y !=0:
		y = y >> 1
		i += 1
	return (x >> (i-1) ) << (i-1)

def func(x):
	if x <= 3:
		return {0:0,1:1,2:3,3:0}[x]
	
	nearest_bin = get_nearest_bin(x)

	if ((x-nearest_bin + 1) %2) == 0:
		ans = 0
	else:
		ans = nearest_bin

	return ans ^ func(x - nearest_bin)


A,B = map(int,input().split())

if A == B:
	print(A)

elif A == 0:
	print(func(B))
else:
	print(func(A-1)^func(B))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define repr(i, n) for (int i = (int)n - 1; i >= 0; --i)
#define ALL(a) (a).begin(), (a).end()
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<ll, ll>;
const int dx[] = {0, 1, -1, 0};
const int dy[] = {1, 0, 0, -1};
const ll mod = 1e9 + 7;
const ll INF = 1e9;
const ll LINF = 1LL << 60;
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);
  //////////////////////////////////////
  ll n;
  cin >> n;
  vector<ll> a(n), cnt, mins;
  rep(i, n) cin >> a[i];
  ll ans = 1000;
  rep(i, n - 1) {
    ll stock = 0;
    if (a[i] < a[i + 1]) stock = ans / a[i];
    ans += (a[i + 1] - a[i]) * stock;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3620
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
#pragma GCC optimize("unroll-loops")
//#pragma warning(disable : 4996)

#ifdef _MSC_VER
#include <intrin.h>
#define __builtin_popcount __popcnt
#define __builtin_popcountll __popcnt64
#endif

#include <limits.h>
#include <math.h>
#include <time.h>

#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <complex>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, m, n) for (int i = m; i < n; ++i)
#define FORR(i, m, n) for (int i = m - 1; i >= n; --i)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v, n) reverse(v, v + n);
#define VREVERSE(v) reverse(v.begin(), v.end())
#define ll long long
#define print(x) cout << (x) << '\n'
#define pe(x) cout << (x) << " "
#define DEBUG(x) cout << #x << ": " << x << endl
#define lb(v, n) lower_bound(v.begin(), v.end(), (n))
#define ub(v, n) upper_bound(v.begin(), v.end(), (n))
#define int long long
#define double long double
#define all(x) (x).begin(), (x).end()
#define print_space(v) REP(i, v.size()) cout << v[i] << ((i == v.size() - 1) ? "\n" : " ")
template <typename T1, typename T2> inline void chmin(T1& a, T2 b) {
	if (a > b) a = b;
}
template <typename T1, typename T2> inline void chmax(T1& a, T2 b) {
	if (a < b) a = b;
}
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef array<int, 3> arr3;
std::random_device rd;
std::mt19937 mt(rd());
constexpr ll MOD = 1e9 + 7;
constexpr int MAX = 500050;
const double pi = acos(-1);
constexpr double EPS = 1e-10;
constexpr ll LINF = 1e18 + 1;
constexpr int INF = 1e9 + 1;


vector<int>make(vector<int>v) {
	vector<int>ret(60);
	int N = v.size();
	REPR(j, 60) {
		ll tmp = 0;
		REP(i, N) {
			if (v[i] & (1LL << j)) {
				ret[j]=(v[i]);
				tmp = v[i];
				break;
			}
		}
		REP(i, N) {
			if (v[i] & (1LL << j)) {
				v[i] ^= tmp;
			}
		}
	}
	return ret;
}
bool canmake(int x, vector<int>&v) {
	vector<int>s = make(v);
	ll ret = 0;
	int n = s.size();
	REPR(j, 60) {
		if ((x>>j&1)!=(ret>>j&1)) {
			ret ^= s[j];
		}
	}
	return ret == x;
}
void solve() {
	int N; cin >> N;
	vector<int>A(N);
	REP(i, N)cin >> A[i];
	string S; cin >> S;
	vector<int>canuse;
	REPR(i, N) {
		if (S[i] == '0')canuse.push_back(A[i]);
		else {
			if (!canmake(A[i], canuse)) {
				//print(A[i]);
				//print_space(canuse);
				//print_space(make(canuse));
				print(1); return;
			}
		}
	}
	print(0);
}



signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int q;
	cin >> q;
	while (q--)
	solve();
}



Measured memory_bytes: 3564
N = gets.to_i

vs = []
(N+1).times {
  vs << []
}

(N-1).times {
  u,v,w = gets.split.map {|x| x.to_i}
  #puts "#{u} #{v} #{w}"
  vs[u] << [v,w]
  vs[v] << [u,w]
}

i = 0
while vs[i].size != 1
  i += 1
end

# BFS
vis = Array.new(N+1, -1)

que = [i]
vis[i] = 0
while (que.size() > 0)
  j = que.pop
  #puts j
  vs[j].each { |s|
    k = s[0]
    if vis[k] < 0
      vis[k] = vis[j] + s[1]
      que.push(k)
    end
  }
end


N.times { |i|
  puts vis[i+1] % 2
}


Measured memory_bytes: 29308
#include<iostream>
#include<cmath>
#include<numeric>
#include<functional>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<iomanip>
#include<queue>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<n;i++)
#define ll long long
#define INF 2147483647
using namespace std;
using Graph=vector<vector<int>>;

int main(){
  int n,ans=0; cin>>n;
  int a[n],moto[n];
  rep(i,n){
    cin>>a[i];
    moto[i]=a[i];
  }
  sort(a,a+n);
  map<int,int> mp;
  rep(i,n){
    mp[a[i]]=i;
  }
  rep(i,n){
    moto[i]=mp[moto[i]];
  }
  rep(i,n){
    if((moto[i]-i)%2!=0){
      ans++;
    }
  }
  cout<<ans/2;
}

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

struct Card {
  char suit, value;
};

void bobbule(vector<Card> &A, int N) {
  for ( int i = 0; i < N; i++ ) {
    for ( int j = N - 1; j >= i + 1; j-- ) {
      if ( A.at(j).value < A.at(j - 1).value ) {
        swap(A.at(j), A.at(j - 1));
      }
    }
  }
}

void selection(vector<Card> &A, int N) {
  for ( int i = 0; i < N; i++ ) {
    int minj = i;
    for ( int j = i; j < N; j++ ) {
      if ( A.at(j).value < A.at(minj).value ) minj = j;
    }
    swap(A.at(i), A.at(minj));
  }
}

void print(vector<Card> &A, int N) {
  for ( int i = 0; i < N; i++ ) {
    if ( i > 0 ) cout << " ";
    cout << A.at(i).suit << A.at(i).value;
  }
  cout << endl;
}

// バブルソートと選択ソートの結果を比較
bool isStable(vector<Card> &b, vector<Card> &s, int N) {
  for ( int i = 0; i < N; i++ ) {
    if ( b.at(i).suit != s.at(i).suit ) return false;
  }
  return true;
}

int main() {
  int N;
  char ch;
  
  cin >> N;
  vector<Card> A(N), B(N);
  for ( int i = 0; i < N; i++ ) {
    cin >> A.at(i).suit >> A.at(i).value;
    B.at(i) = A.at(i);
  }
  
  bobbule(A, N);
  selection(B, N);
  
  print(A, N);
  cout << "Stable" << endl;
  print(B, N);
  if ( isStable(A, B, N) ) {
    cout << "Stable" << endl;
  } else {
    cout << "Not stable" << endl;
  }
  
  return 0;
}


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

int main() {
	
	long long A, B, N;
	
	cin >> N >> A >> B;
	
	if(B<A){
		cout << "0" << endl;
	}else{
		long long min = (N-1)*A + B;
		long long max = (N-1)*B + A;
		
		long long ans = max-min+1;
		
		if(ans < 0) ans = 0;
		
		cout << ans << endl;
	}
	
	return 0;
}

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

using namespace std;

int main()
{
  int testcase = 1;
  int N, B;
  while(scanf("%d %d", &N, &B), N) {
    vector< int > g[100000];
    for(int i = 1; i < N; i++) {
      int P;
      scanf("%d", &P);
      --P;
      g[P].emplace_back(i);
      g[i].emplace_back(P);
    }

    printf("Case %d:\n", testcase++);

    if(N <= 2) {
      if(N == 1) cout << 1 << endl;
      else if(B == 1) cout << 2 << endl << 2 << endl;
      else cout << 1 << endl << 1 << endl;
      continue;
    }

    int root;
    for(int i = 0; i < N; i++) {
      if(g[i].size() >= 2) root = i;
    }

    vector< int > sz(N), dep(N), ans(N);

    function< void(int, int) > dfs1 = [&](int idx, int par)
    {
      int depmax = 1, size = 0;
      for(auto &to : g[idx]) {
        if(to != par) {
          dfs1(to, idx);
          if(depmax < dep[to]) depmax = dep[to], size = sz[to];
          else if(depmax == dep[to]) size += sz[to];
        }
      }
      if(size + 1 <= B) {
        sz[idx] = size + 1;
        dep[idx] = depmax;
      } else {
        sz[idx] = 1;
        dep[idx] = depmax + 1;
      }
    };


    function< void(int, int, int, int) > dfs2 = [&](int idx, int pardep, int parsz, int par)
    {
      map< int, int > vs;
      if(~par) vs[pardep] += parsz;
      for(auto &to : g[idx]) {
        if(to != par) vs[dep[to]] += sz[to];
      }
      const auto latte = prev(vs.end());
      if(latte->second + 1 <= B) ans[idx] = latte->first;
      else ans[idx] = latte->first + 1;

      for(auto &to : g[idx]) {
        if(to != par) {
          if(vs.find(dep[to]) == latte) {
            if(latte->second - sz[to] == 0) {
              assert(begin(vs) != latte);
              const auto malta = prev(latte);
              if(malta->second + 1 <= B) dfs2(to, malta->first, malta->second + 1, idx);
              else dfs2(to, malta->first + 1, 1, idx);
            } else {
              if(latte->second - sz[to] + 1 <= B) dfs2(to, latte->first, latte->second - sz[to] + 1, idx);
              else dfs2(to, latte->first + 1, 1, idx);
            }
          } else {
            if(latte->second + 1 <= B) dfs2(to, latte->first, latte->second + 1, idx);
            else dfs2(to, latte->first + 1, 1, idx);
          }
        }
      }
    };

    dfs1(root, -1);
    dfs2(root, 1, 0, -1);

    for(int i = 0; i < N; i++) {
      printf("%d\n", ans[i]);
    }

  }

}

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

int main() {
  int num;
  cin >> num;
  int original_num;
  original_num = num;
  int sum = 0;

  while (true) {
    sum += num % 10;
    if (num < 10) {
      break;
    }
    num /= 10;
  }

  if (original_num % sum == 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include <sstream>
#include <fstream>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <stack>
#include <map>
#include <string>
#include <queue>
#include <bitset>
using namespace std;

#define int long long
#define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i)
#define FORD(i, a, b) for (int i = (a), _b = (b); i >= _b; --i)
#define REP(i, a) for (int i = 0, _a = (a); i < _a; ++i)
#define REPD(i,n) for(int i = (n)-1; i >= 0; --i)

#define DEBUG(X) { cerr << #X << " = " << (X) << endl; }
#define PR(A, n) { cerr << #A << " = "; FOR(_, 1, n) cerr << A[_] << ' '; cerr << endl; }
#define PR0(A, n) { cerr << #A << " = "; REP(_, n) cerr << A[_] << ' '; cerr << endl; }

#define sqr(x) ((x) * (x))
#define ll long long
#define double long double
typedef pair<int, int> II;
#define PI (2 * acos((double)0))
#define __builtin_popcount __builtin_popcountll
#define SZ(x) ((int)(x).size())
#define ALL(a) (a).begin(), (a).end()
#define MS(a,x) memset(a, x, sizeof(a))
#define next ackjalscjaowjico
#define prev ajcsoua0wucckjsl
#define y1 alkscj9u20cjeijc
#define left lajcljascjljl
#define right aucouasocjolkjl
#define y0 u9cqu3jioajc

#define TWO(X) (1LL<<(X))
#define CONTAIN(S,X) ((S) & TWO(X))

double safe_sqrt(double x) { return sqrt(max((double)0.0, x)); }
int GI(int& x) { return scanf("%lld", &x); }

const int MN = 100111;
int n, a[MN];

bool check(int mid) {
    int cur = a[mid];
    FOR(i,1,n) if (i != mid) {
        if (a[i] > 2*cur) return 0;
        cur += a[i];
    }
    return 1;
}

int32_t main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout << (fixed) << setprecision(9);
    while (cin >> n) {
        FOR(i,1,n) cin >> a[i];
        sort(a+1, a+n+1);

        int l = 1, r = n, res = n;
        while (l <= r) {
            int mid = (l + r) >> 1;
            if (check(mid)) res = mid, r = mid - 1;
            else l = mid + 1;
        }
        cout << n - res + 1 << endl;
    }
    return 0;
}


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

int main() {
    string s;
    cin >> s;
    int cnt = 0;

    for (int i = 0; i < s.length()/2; ++i) {
        if (s[i] != s[(s.length()-1) - i]) {
          cnt++;
        }
    }

    cout << cnt << endl;
}

Measured memory_bytes: 256
//R<3S
#include <bits/stdc++.h>
#define DECIMAL(n)  std::cout << std::fixed;std::cout << std::setprecision(n);
#define FAST std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define hell 1000000007
#define PI 3.14159265358979323844
#define mp make_pair
#define pb push_back
#define fi first 
#define se second
#define ALL(v) v.begin(), v.end()
#define SORT(v) sort(ALL(v))  
#define REVERSE(v) reverse(ALL(v))
#define endl "\n"
#define vecmax(v) max_element(all(v))
#define vecmin(v) min_element(all(v))
#define GCD(m,n) __gcd(m,n)
#define LCM(m,n) m*(n/GCD(m,n))
#define inputarr(a,n) for(int i=0;i<n;++i) cin>>a[i]
#define initarr(a,n,x) for (int i=0;i<n;++i) a[i]=x
#define rep(i, n)    for(int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(int i = a; i <= (n); ++i)
#define repD(i, a, n)  for(int i = a; i >= (n); --i)
#define trav(x) for(auto i : x)
#define sz(a) (int)a.size()
#define sl(a) (int)a.length()
#define invect(data,n) for(int i = 0;i<n;i++){int tmp;cin>>tmp;data.pb(tmp);}
#define inset(data,n) for(int i = 0;i<n;i++){int tmp;cin>>tmp;data.insert(tmp);}
#define ll long long
#define int unsigned long long
#define ld long double 
#define pii std::pair<int, int> 
#define pll std::pair<ll, ll>  
#define vi vector<int>  
#define vl vector<ll>
#define vvi vector<vi > 
#define vii vector<pii >
#define mii map<int,int>
#define mll map<ll,ll>
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl


using namespace std;

void solve()
  {
    int n;
    cin>>n;int sum=0;
    repA(i,1,n)
    repA(j,1,n)
    repA(k,1,n)
    sum+=GCD(i,GCD(j,k));
    cout<<sum;

  }



signed main()
{
   FAST

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


   return 0;
}


Measured memory_bytes: 3604