akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define pb push_back
using namespace std;
const int maxn=100005;
const int logn=20;

int n,q,l;
int dep[maxn];
int up[maxn][logn];
vector<int>G[maxn];

void dfs(int u,int p) {
    dep[u]=dep[p]+1;
    up[u][0]=p;
    for (int i=0;i<l;i++) up[u][i+1]=up[up[u][i]][i];
    for (int v:G[u])
        if (v!=p) dfs(v,u);
}

int lca(int u,int v) {
    if (dep[u]<dep[v]) swap(u,v);
    for (int i=l;i>=0;i--) {
        if (dep[up[u][i]]>=dep[v]) u=up[u][i];
        if (u==v) return u;
    }
    for (int i=l;i>=0;i--)
        if (up[u][i]!=up[v][i]) {
            u=up[u][i];
            v=up[v][i];
        }
    return up[u][0];
}

int main() {
    cin>>n;
    for (int i=0;i<n;i++) {
        int m; cin>>m;
        for (int j=0;j<m;j++) {
            int v; cin>>v;
            G[i].pb(v);
        }
    }
    while ((1<<l)<n) ++l;
    dfs(0,0);
    cin>>q;
    for (int i=0;i<q;i++) {
        int u,v; cin>>u>>v;
        cout<<lca(u,v)<<'\n';
    }
}



Measured memory_bytes: 21452
fun main(args: Array<String>) {
    val line = readLine()!!.trim()
    var (a, b, c) = line.split(" ").map {it.toInt()}

    var d = a
    a = b
    b = d

    d = a
    a = c
    c = d

    println("${a} ${b} ${c}")
}


Measured memory_bytes: 36112
A,B,C=map(int,input().split())
a=0
for i in range(10**3):
    if A%2==0 and B%2==0 and C%2==0:
        a+=1
        A,B,C=(B+C)//2,(A+C)//2,(A+B)//2
    else:
        print(a)
        break
else:
    print(-1)


Measured memory_bytes: 9116
#include"bits/stdc++.h"
#include<boost/multi_array.hpp>
#include<boost/optional.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptors.hpp>
using namespace std;
namespace adaptor = boost::adaptors;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
typedef long long ll;

void Main()
{
	string s;
	cin >> s;
  	string t = "";
  	for(int i; i<s.size(); i++){
  		if (s[i] == 'B'){
    		if(!t.empty()){
            	t.erase(t.size()-1);
            }
        }
		else{
  			t += s[i];
        }
    }
	cout << t << endl;
  	return;
}

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

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

#define ll long long

using namespace std;
const int MX = 200'000 + 5; // check bounds!

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

    bool same = true;
    for (int i = 1; i < s.size(); ++i) {
        if (s[i] != s[0]) {
            same = false;
            break;
        }
    }
    if (same) {
        cout << (k * s.size()) / 2;
        exit(0);
    }

    ll sol = 0, last = 0, first = 0;
    for (int i = 0; i < s.size(); ++i) {
        int j = i;
        for (; j < s.size(); ++j) {
            if (s[i] != s[j])
                break;
        }
        last = (j - i);
        if (first == 0)
            first = last;
        sol += (j - i) / 2;
        i = j - 1;
    }
    sol *= k;
    if (s[0] == s[s.size() - 1] && last % 2 && first % 2) {
        sol += k - 1;
    }

    cout << sol;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <set>
#include <deque>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <memory>
#include <iomanip>
#include <functional>
#include <new>
#include <algorithm>
#include <cmath>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <climits>
#include <cctype>
#include <ctime>

using namespace std;

#define REP(i, n) for(i = 0; i < n; i++)
#define sz(n) n.size()

int i, n, r, c;

void shuffle(vector<int>& v, int c) {
    deque<int> b(v.begin(), (v.begin() + (sz(v) / 2)));
    deque<int> a(v.begin() + sz(v) / 2, v.end());

    vector<int> nova;

    while(1) {
        for(int x = 0; x < c && a.size() > 0; x++) {
            nova.push_back(a.front());
            a.pop_front();
        }
        for(int x = 0; x < c && b.size() > 0; x++) {
            nova.push_back(b.front());
            b.pop_front();
        }
        if(a.empty() && b.empty()) break;
    }
    v = nova;
}
int main() {
    while(~scanf("%d%d", &n, &r)) {
        vector<int> v(n);
        REP(i, n) { v[i] = i; }
        REP(i, r) {
            scanf("%d", &c);
            shuffle(v, c);
        }
        cout << v[v.size() - 1] << endl;
    }
    return 0;
}

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

int main(){
    int n;
    cin >> n;
    map<ll, ll> m;
    ll ans = 0;
    vector<ll> a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }

    for(int i = 0; i < n; i++){
        m[a[i]+i]++;
    } 
    for(int i = 0; i < n; i++){
        ans += m[i-a[i]];
    }
    cout << ans << endl;
}

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

using namespace std;
using ll = long long;

constexpr ll MOD = 1000000007LL;

string k;
int d;
int n;

ll dp[10005][105][2];

ll solve(int index, int total, bool skip) {
  if (index == n) {
    return (total == 0) ? 1LL : 0LL;
  }
  ll& res = dp[index][total][skip];
  if (res != -1LL) {
    return res;
  }
  int cur = k[index] - '0';
  res = 0;
  for (int i = 0; i < 10; i++) {
    bool stop = skip && (i > cur);
    if (stop) {
      break;
    }
    bool keepSkip = skip && (i == cur);
    res = (res + solve(index + 1, (total + i) % d, keepSkip)) % MOD;
  }
  return res;
}

int main() {
  fill(&dp[0][0][0], &dp[0][0][0] + 10005 * 105 * 2, -1LL);
  cin >> k >> d;
  n = k.size();
  ll res = MOD - 1;
  int cur = k[0] - '0';
  for (int i = 0; i < cur; i++) {
    res = (res + solve(1, i % d, false)) % MOD;
  }
  res = (res + solve(1, cur % d, true)) % MOD;
  cout << res << '\n';
  return 0;
}


Measured memory_bytes: 17664
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <iomanip>

#define int long long int
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )

using namespace std;

typedef pair<int, int> P;

const int INF = 1e15;
const int MOD = 1e9+7;

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

    int n, m;
    cin >> n >> m; 
    vector<vector<int>> edge(n + 1, vector<int>());
    rep(i, m){
        int a, b;
        cin >> a >> b;
        edge[a].push_back(b);
        edge[b].push_back(a);
    }

    int q;
    cin >> q;
    vector<int> v(q), d(q), c(q);
    rep(i, q) cin >> v[i] >> d[i] >> c[i];
    reverse(ALL(v));
    reverse(ALL(d));
    reverse(ALL(c));

    vector<vector<int>> dp(n + 1, vector<int>(11));
    rep(i, q){
        stack<P> st;
        st.emplace(v[i], d[i]);

        while(not st.empty()){
            int u = st.top().first;
            int dd = st.top().second;
            st.pop();

            bool marked = false;
            for(int j = dd; j <= 10; j++){
                if(dp[u][j] != 0){
                    marked = true;
                }
            }
            if(marked){
                continue;
            }
            dp[u][dd] = c[i];

            for(int w : edge[u]){
                st.emplace(w, dd - 1);
            }
        }
    }

    for(int i = 1; i <= n; i++){
        int ans = 0;
        rep(j, 11){
            if(dp[i][j] != 0){
                ans = dp[i][j];
                break;
            }
        }
        cout << ans << endl;
    }

    return 0;
}


Measured memory_bytes: 22180
n, m = map(int, input().split())
sc = []
for i in range(m):
    sc.append(list(map(int, input().split())))
ans = 0
s = set()
keta = set()
for i in range(m):
    preans = sc[i][1]*(10**(n-sc[i][0]))
    if sc[i][0] in keta and preans not in s:
        print(-1)
        break
    elif sc[i][0]  not in keta:
        ans += preans
        s.add(preans)
        keta.add(sc[i][0])
else:
    if n == 1 and m == 0:
        print(0)
    elif 1 not in keta:
        print(ans + 10**(n-1))
    elif len(str(ans)) == n:
        print(ans)
    else:
        print(-1)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) x.begin(),x.end()
using namespace std;

using ll = long long;

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

    int n;
    string s;
    cin >> n >> s;
    string ns;
    rep(i, n) {
        ns.push_back(s[i]);
        if(s[i] == s[i+1]) ns.pop_back();
    }
    cout << ns.size() << endl;
    return 0;
}

Measured memory_bytes: 3768
#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <deque>
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  
#include <chrono>
#include <random>
#include <time.h>
#include <fstream>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define endl "\n"
#define all(c) begin(c),end(c)
using namespace std;
int in() {int x;scanf("%d",&x);return x;}
ll lin() {ll x;scanf("%lld",&x);return x;}
void print(vec v){for(auto e:v)cout<<e<<" ";cout<<endl;}
void print(vecll v){for(auto e:v)cout<<e<<" ";cout<<endl;}
void print(map<int,int> mp){for(auto e:mp)cout<<e.first<<" "<<e.second<<endl;cout<<endl;}


#define INF 1e9+7
#define LLINF 1e18+7
const ll MOD=1e9+7;
const int N=1000000;



main(){
    int n=in();
    map<int,int> mp;
    vector<string> v;
    rep(i,n){
        string s;
        cin>>s;
        v.pb(s);
        for(auto c:s){
            mp[c]++;
        }
    }
    for(auto e:mp){
        int c=e.first;
        int mi=INF;
        for(auto s:v){
            int cnt=0;
            for(auto d:s){
                if(d==c)cnt++;
            }
            mi=min(mi,cnt);
        }
        rep(i,mi)cout<<(char)e.first;
    }
}

Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


def segfunc(x, y):
    # 求めたい値を算出するためのロジックを書く
    return max(x, y)


class SegmentTree:
    # ide_ele は単位元。初期値
    def __init__(self, init_val, ide_ele):
        self.n = len(init_val)
        self.ide_ele = ide_ele
        self.num = 2 ** (self.n - 1).bit_length()
        self.seg = [self.ide_ele] * 2 * self.num
        for i in range(self.n):
            self.seg[i + self.num - 1] = init_val[i]

        for i in range(self.num - 2, -1, -1):
            self.seg[i] = segfunc(self.seg[2 * i + 1], self.seg[2 * i + 2])

    # 0-indexed
    def update(self, k, x):
        k += self.num - 1
        self.seg[k] = x
        while k:
            k = (k - 1) // 2
            self.seg[k] = segfunc(self.seg[k * 2 + 1], self.seg[k * 2 + 2])

    # 0-indexed
    # 半開区間 pからq - 1 までが担当範囲
    # [p, q)
    def query(self, p, q):
        if q <= p:
            return self.ide_ele
        p += self.num - 1
        q += self.num - 2
        res = self.ide_ele
        while q - p > 1:
            if p & 1 == 0:
                res = segfunc(res, self.seg[p])
            if q & 1 == 1:
                res = segfunc(res, self.seg[q])
                q -= 1
            p = p // 2
            q = (q - 1) // 2
        if p == q:
            res = segfunc(res, self.seg[p])
        else:
            res = segfunc(segfunc(res, self.seg[p]), self.seg[q])
        return res


def main():
    N, K = [int(x) for x in input().split()]
    A = [int(input()) for _ in range(N)]

    init_val = [0] * 300002
    s = SegmentTree(init_val, 0)

    ma = max(A)
    for a in A:
        ans = s.query(max(0, a - K), min(ma, a + K) + 1)
        s.update(a, ans + 1)
    print(s.query(0, ma + 1))


if __name__ == '__main__':
    main()


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

int n;
int T[1024];
int E[1024];

int main() {
  for(;;) {
    scanf("%d", &n);
    if( n == 0 ) break;
    for(int i = 0; i < n; ++i) {
      scanf("%d", &E[i]);
    }
    double bH = 1e10;
    int bS, bA, bC; 
    for(int S = 0; S < 16; ++S) {
      for(int A = 0; A < 16; ++A) {
        for(int C = 0; C < 16; ++C) {
          for(int i = 0; i < 256; ++i) T[i] = 0;
          int R = S;
          double H = 0.0;
          for(int k = 0; k < n; ++k) {
            R = (A * R + C) % 256;
            int t = (E[k] + R) % 256;
            T[t] += 1;
          }
          for(int k = 0; k < 256; ++k) {
            if( T[k] == 0 ) continue;
            double t = (double)T[k] / n;
            H -= t * log(t);
          }
          if( bH - H > 0.00000000001 ) {
            bH = H;
            bS = S;
            bA = A;
            bC = C;
          }
          if( bH < 0.000000001 ) break;
        }
      }
    }
    printf("%d %d %d\n", bS, bA, bC);
  }            
  
  return 0;
}

Measured memory_bytes: 3412
N = int(input())
S = input()

# 0~25
alph = [chr(i) for i in range(65, 65+26)]

new_string = []
for c in S:
  idx = alph.index(c) + N
  if idx >= 26:
    idx -= 26
  new_string.append(alph[idx])

print("".join(new_string))

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
using ll= long long;
using ld=long double;
int main()
{
   ll n;
   cin>>n;
  ll a[n],b[n],c[n];
  for(ll i=0;i<n;i++)
	cin>>a[i]>>b[i]>>c[i];
  ll dpa[n],dpb[n],dpc[n];
  dpa[0]=a[0];
  dpb[0]=b[0];
  dpc[0]=c[0];
  for(ll i=1;i<n;i++)
  {
	dpa[i]=a[i]+max(dpb[i-1],dpc[i-1]);
    dpb[i]=b[i]+max(dpa[i-1],dpc[i-1]);
    dpc[i]=c[i]+max(dpa[i-1],dpb[i-1]);
  }
  cout<<max(dpa[n-1],max(dpb[n-1],dpc[n-1]));
}

Measured memory_bytes: 8272
#include<bits/stdc++.h>
using namespace std;
#define ll long long
typedef pair<ll, ll> pii;

int main() {
    int x;
    cin>>x;
    double l=x;
    double a=l*l*l/27;
    cout<<setprecision(10)<<a;
    
	return 0;
}

Measured memory_bytes: 256
import itertools
n = int(input())
a = [3,5,7]
b = list(itertools.product(a,a,a)) + list(itertools.product(a,a,a,a)) + list(itertools.product(a,a,a,a,a)) + list(itertools.product(a,a,a,a,a,a)) + list(itertools.product(a,a,a,a,a,a,a)) + list(itertools.product(a,a,a,a,a,a,a,a)) + list(itertools.product(a,a,a,a,a,a,a,a,a))
ans = 0
for i in range(len(b)):
    sb = set(b[i])
    if len(sb) == 3 and 3 in sb and 5 in sb and 7 in sb:
        c = ''.join(map(str,b[i]))
        c = int(c)
        if c <= n:
            ans +=1
        else:
            break
print(ans)

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

int main() {
  int k, n;
  cin >> k >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  a.push_back(a[0]+k);
  int l = 0;
  rep(i, n) {
    l = max(l, a[i+1] - a[i]);
  }
  int ans = k-l;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 4828
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
int main(){
  int n;
  cin >> n;
  if(n == 1){
    cout << "Hello World" << endl;
  }
  else{
    int a,b;
    cin >> a >> b;
    cout << a + b << endl;
  }
}

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

int main() {
    int t=1;
    //cin >> t;
    while(t--){
        ll n,i,j,cnt=0;
        cin >> n;
        for(i=1;i<=n;i++){
            for(j=1;j<=n;j++){
                if(i*j<n && i==j){
                    cnt+=1;
                }
                else if(i*j<n){
                    cnt+=1;
                }
                if(i*j>=n){
                    break;
                }
            }
        }
        cout << cnt << endl;
    }
}

Measured memory_bytes: 3672
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using Graph = vector<vector<int>>;
const int INF = 1e9 + 1;
const ll LLINF = 1e18;
const int MOD = 1e9 + 7;

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

    char C;
    cin >> C;
    cout << (char)(C + 1) << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;
#define rep(i,n) for(int i = 0; i<(int)(n);i++)
#define rep1(i,n) for(int i = 1; i<=(int)(n); i++)

int main (void){

    int n ;

    cin >> n;

    int a[n];
    int index[n];

    rep(i,n){
        cin >> a[i];
    }

    rep(i,n){
        index[a[i]] = i;
    }
    
    rep1(i,n){
        cout<<index[i]+1<<" ";
    }

    return 0;
}


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

int multiplicityOfDivisor(long long number, long long divisor) {
  int multiplicity = 0;
  while (number % divisor == 0) {
    number /= divisor;
    ++multiplicity;
  }
  return multiplicity;
}

void solve() {
  int N;
  cin >> N;
  vector<long long> numbers(N);
  for (int i = 0; i < N; ++i) {
    string s;
    cin >> s;
    const int pos = s.find(".");

    if (pos == -1) {
      numbers[i] = stoll(s) * 1000000000LL;
    } else {
      // Before "."
      long long before = stoll(s.substr(0, pos)) * 1000000000LL;
      // After "."
      string after_string = s.substr(pos + 1);
      long long after = 0;
      long long multiplier = 100000000LL;
      for (int j = 0; j < after_string.size(); ++j) {
        after += (after_string[j] - '0') * multiplier;
        multiplier /= 10;
      }
      numbers[i] = before + after;
    }
  }

  // numberOfElementsWithMultiplicity[i][j] = number of elements
  // that have exactly i as multiplicity for 2, and j as multiplicity for 5.
  long long answer = 0;
  vector<vector<int>> numberOfElementsWithMultiplicity(50, vector<int>(20, 0));
  for (int i = 0; i < N; ++i) {
    const int multiplicity_2 = multiplicityOfDivisor(numbers[i], 2);
    const int multiplicity_5 = multiplicityOfDivisor(numbers[i], 5);

    // Other element should have at least this multiplicity.
    const int target_multiplicity_2 = 18 - multiplicity_2;
    const int target_multiplicity_5 = 18 - multiplicity_5;

    // Query.
    for (int j = max(0, target_multiplicity_2); j < 50; ++j) {
      for (int k = max(0, target_multiplicity_5); k < 20; ++k) {
        answer += numberOfElementsWithMultiplicity[j][k];
      }
    }

    // Update "hash table".
    ++numberOfElementsWithMultiplicity[multiplicity_2][multiplicity_5];
  }
  cout << answer << endl;
}

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

Measured memory_bytes: 4764
N, M = map(int, input().split())

N, M = min(N, M), max(N, M)
if (N == 1 and M == 1):
    print(1)
elif (N == 1 and M > 1):
    print(M - 2)
else:
    print((N - 2) * (M - 2))


Measured memory_bytes: 38384
#include "bits/stdc++.h"
using namespace std;

vector<int> Eratosthenes(int n){
    bool dp[n]; //falseなら素数
    for(int i = 0; i < n; i++) dp[i] = false;
    dp[0] = dp[1] = true;
    vector<int> prime;
    for(int i = 2; i < n; i++){
        if(dp[i]) continue;
        prime.push_back(i);
        for(int j = i * 2; j < n; j += i){
            dp[j] = true;
        }
    }

    return prime;
}

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

    int n;
    cin >> n;
    vector<int> a = Eratosthenes(55555);
    for(int i = 0; i < a.size(); i++){
        if(a[i] % 5 == 1){
            cout << a[i] << " ";
            n--;
        }
        if(n <= 0) break;
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <math.h>
using namespace std;
typedef long long ll;

int main() {
	ll n, ans;
	cin >> n ;
	vector<ll> v(5,0);
	cin >> v[0];
	ll m = v[0];
	
	for (int i = 1;i < 5;++i){
		cin >> v[i];
		m = min(m,v[i]);
	}
	
	ans = 5 + n/m;
	if (n % m == 0){
		ans -= 1;
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(int argc, char **argv)
{
    int a, b;
    scanf("%d %d", &a, &b);

    if (a == b) {
        puts("Draw");
        return 0;
    }
    if (a == 1) {
        a = 999;
    }
    if (b == 1) {
        b = 999;
    }
    if (a > b) {
        puts("Alice");
    } else {
        puts("Bob");
    }
    return 0;
}

Measured memory_bytes: 128
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define vi vector<int>
#define pb push_back
#define INF 999999999
//#define INF (1LL<<59)

#define MAX_V 10000
vector<int> G[MAX_V];

vector<int> topologicalSort(vector<int> in_deg){
    stack<int> st;
    vector<int> list;
    int v = in_deg.size();
    
    rep(i,v)if(in_deg[i]==0)st.push(i);
    
    while(st.size()){
        int q = st.top();
        st.pop();
        list.pb(q);
        
        rep(i,G[q].size()){
            int to = G[q][i];
            in_deg[to]--;
            if(in_deg[to]==0)st.push(to);
        }
    }
    
    if(list.size()!=v){/*????????????*/}

    return list;
}

int main(){
    int v,e;
    cin>>v>>e;
    vector<int> in_deg(v,0);
    
    rep(i,e){
        int s,t;
        cin>>s>>t;
        in_deg[t]++;
        G[s].pb(t);
    }
    vector<int> list = topologicalSort(in_deg);
    
    rep(i,list.size())cout<<list[i]<<endl;

}

Measured memory_bytes: 3816
from collections import deque
import math

n,m,p = map(int, input().split())
dist  = []
edge1 = [[] for _ in range(n)]
edge2 = [[] for _ in range(n)]  # rev_edge
for _ in range(m):
    u,v,c = map(int, input().split())
    u -= 1
    v -= 1
    dist.append((u,v,(c-p)*-1))
    edge1[u].append(v)
    edge2[v].append(u)   

def dfs(edges, s):
    stack = deque([s])
    used  = {s}
    while stack:
        x = stack.pop()
        for y in edges[x]:
            if y not in used:
                used.add(y)
                stack.append(y)
    return used


def bfs(edges, s):
    queue = deque([s])
    used  = {s}
    while queue:
        x = queue.popleft()
        for y in edges[x]:
            if y in used:
                continue
            used.add(y)
            queue.append(y)
    return used
    

def bellman(dist):  #負辺があるケースでの、スタートからゴールへの最短路を求めるアルゴ。
    cost = [float("inf")] * n
    cost[0] = 0
    for _ in range(n): #頂点の個数の分だけ回る
        updated = False
        for u,v,c in dist: #辺の個数の分だけ回る
            if cost[u] + c < cost[v]:
                cost[v] = cost[u] + c
                updated = True                
    #収束しない場合は負閉路があるため無限に小さくできる。
    if updated==True:
        return -1
    else:
        return max(0, cost[n-1]*-1)     
    
use = bfs(edge1, 0) & bfs(edge2, n-1)
dist2 = [(a,b,c) for a,b,c in dist if a in use and b in use]
print(bellman(dist2))

Measured memory_bytes: 5348
#include <iostream>
#include <vector>
using namespace std;
typedef long long int ll;

int main(){
	int n; cin >> n;
	int sum=0;
	int cp=0;
	for(int i=1;;i++){
		sum+=i;
		cp=i;
		if(sum>=n)break;
	}
	for(int i=1;i<=cp;i++){
		if(n!=sum-i)cout << i << endl;
	}
}

Measured memory_bytes: 256
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let v = read_vec::<i64>();
    let (a, b) = (v[0], v[1]);
    let ans = vec![a + b, a - b, a * b].into_iter().max().unwrap();
    println!("{}", ans);
}

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()
}


Measured memory_bytes: 2144
import java.util.*;

class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        
        int W = sc.nextInt();
        int H = sc.nextInt();
        int x = sc.nextInt();
        int y = sc.nextInt();

        System.out.printf("%f ",((double)W*(double)H)/2);
        if(2*x==W && 2*y==H) {
            System.out.println("1");
        } else {
            System.out.println("0");
        }
        
    }
}

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

using namespace std;
int main(){
    string s, t;
    cin>>s>>t;
    int n=s.length(),ans=0;
    for(int i=0;i<n;i++){
        if(s[i]!=t[i])ans++;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3468
#include<iostream>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<string>

using namespace std;

double dp[310][310][310]; int N;

double dfs(int a, int b, int c){
  if(dp[a][b][c] != -1){ return dp[a][b][c];}
  if(a == 0 && b == 0 && c == 0){ return 0.0;}
  
  double res = 0.0;
  
  if( a > 0){ res += dfs(a-1,b,c)* a;}
  if( b > 0){ res += dfs(a+1,b-1,c)* b;}
  if( c > 0){ res += dfs(a,b+1,c-1) * c;}
  
  res += N; res /= (a + b + c);
  
  return dp[a][b][c] = res;}
     
int main(){
  cin >> N; 
  int cnt1 = 0; int cnt2 = 0; int cnt3 = 0;
 for(int i = 0; i < N; i++){ int a; cin >> a;
   if(a == 1){ cnt1++;}
   else if( a == 2){ cnt2++;}
   else if( a == 3){ cnt3++;}
                           }
  
  for(int i = 0; i < 310; i++){
    for(int j = 0; j < 310; j++){
      for(int k = 0; k < 310; k++){
        dp[i][j][k] = -1;}}}
  
  cout << setprecision(10) << dfs(cnt1,cnt2,cnt3) << endl; return 0;}

Measured memory_bytes: 233088
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<cstring>
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(n) rep(i,n)
#define all(n) n.begin(),n.end()

const int MAXN = 100;

int c[MAXN * 2 + 10], next[MAXN * 2 + 10];

int main()
{
    int n, m, k; cin >> n >> m;
    REP(n * 2)c[i] = i + 1;

    REP(m)
    {
        cin >> k;
        if(k == 0)
            rep(j,n){ next[j * 2] = c[j]; next[j * 2 + 1] = c[n + j];}
        else
        {
            rep(j,k) next[2 * n - k + j] = c[j];
            rep(j,2 * n - k)next[j] = c[j + k];
        }
        rep(j,n * 2) c[j] = next[j];
    }
    REP(n * 2) cout << c[i] << endl;
    return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define rep(i, n) ;for (int i = 0;i < (int)(n);i++)
#define rep2(i, s, n) ;for (int i = s; i < (int)(n);i++)
#define ALL(vec)  (vec).begin(),(vec).end()
#define pi 3.1415926535897932384626433832795
#define MAX_INF 9223372036854775807
#define MIN_INF (922337203685477587+1)
#define sosuu 1000000007

int main() {
  int N;
  cin >> N;
  int ans=0,high[N];
  int sum=0;
  rep(i, N){
    cin >> high[i];
    sum+=high[i];
  }
  int l=0;
  
  while(sum!=0){
    
  rep(i, N){
    if(high[i]!=0){}
    else if(i!=0&&i!=N-1){
      if(high[i]!=high[i-1]){
        l=0;
      rep2(j, i, N){
      l+=high[j];
      }
        if(l!=0)
          ans++;
      }
    }
  }
    
   rep(i, N){
    if(high[i]!=0){
    high[i]--;
      sum--;
    }
   }
    
    
  ans++;
    
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
import sys
readline = sys.stdin.buffer.readline

n = int(readline())
c = 1
r = 0
p = 0
a = True
for i, j in enumerate(readline().split()):
  if c != int(j):
    continue
  else:
    a = False
    c += 1
    r += i - p
    p = i + 1
if a:
  print(-1)
else:
  print(r + n - p)

Measured memory_bytes: 13944
#include "bits/stdc++.h"

using namespace std;

#define ll             long long int
#define eb             emplace_back

static const int maxn = 4e5 + 5;
static const ll mod = 1e9 + 7;

int main()
{
      ios_base::sync_with_stdio(false);
      cin.tie(nullptr);
      cout.tie(nullptr);
      cout << fixed << setprecision(12);


      int n;
      cin >> n;
      map <string, int> Map;
      ll ans = 0;
      for (int i = 1; i <= n; i++)
      {
            string s;
            cin >> s;
            sort(s.begin(), s.end());
            ans += Map[s];
            Map[s]++;
      }
      cout << ans << endl;

}


Measured memory_bytes: 11264
import itertools

while 1:
    A = input().split()

    n = int(A[0])
    if n == 0:
        break
    m = int(A[1])
    C = [int(i) for i in input().split()]
    comb = itertools.combinations(C, 2)
    rsl = 0
    flg = 0
    for i in comb:
        tmp = i[0] + i[1]
        if tmp <= m and tmp > rsl:
            rsl = tmp
            flg = 1

    if flg == 0: print("NONE")
    else: print(rsl)


Measured memory_bytes: 5784
#include <bits/stdc++.h>
#define REP(i, a, n) for (int i = (a); i < (int)(n); ++i)
#define REPC(i, a, n) for (int i = (a); i <= (int)(n); ++i)
#define ALL(t) t.begin(), t.end()
#define RALL(t) t.rbegin(), t.rend()
#define MATINIT(type, row, col, init) \
  vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
using namespace std;
using LL = long long;
using ULL = unsigned long long;
template <class T>
using VEC = std::vector<T>;
template <class T>
using MAT = std::vector<std::vector<T>>;
void DUMP() { cerr << endl; }
template <class Head, class... Tail>
void DUMP(Head &&head, Tail &&... tail) {
  cerr << head << ", ";
  DUMP(std::move(tail)...);
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec) {
  os << "{";
  for (auto v : vec) os << v << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, map<T1, T2> &m) {
  os << "{";
  for (auto p : m) os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
  os << "[" << p.first << " " << p.second << "]";
  return os;
}

int main() {
  LL K, A, B;
  cin >> K >> A >> B;
  LL first = A - 1;
  LL remain = K - first;
  LL ans = 0;
  if (B - A <= 2) {
    ans = K + 1;

  } else {
    DUMP("HI");
    if (remain % 2 == 0) {
      LL num = remain / 2;
      ans = (num - 1) * (B - A) + B;
    } else {
      LL num = remain / 2;
      ans = (num - 1) * (B - A) + B + 1;
    }
  }
  DUMP(first, remain);
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cassert>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
struct Edge
{
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w) {}
};
//using Graph = vector<vector<Edge>>;
using Graph = vector<vector<int>>;

const long long INF = 1LL << 60;
const int INT_INF = 1000000000;
const double PI = acos(-1.0);

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

bool isPrime(long long num)
{
  if (num < 2)
    return false;
  else if (num == 2)
    return true;
  else if (num % 2 == 0)
    return false;

  double sqrtNum = sqrt(num);

  for (int i = 3; i <= (int)sqrtNum; i++)
  {
    if (num % i == 0)
      return false;
  }

  return true;
}

vector<int> Eratosthenes(const int N)
{
  vector<bool> is_prime(N + 1);
  for (int i = 0; i <= N; i++)
  {
    is_prime[i] = true;
  }
  vector<int> P;
  for (int i = 2; i <= N; i++)
  {
    if (is_prime[i])
    {
      for (int j = 2 * i; j <= N; j += i)
      {
        is_prime[j] = false;
      }
      P.emplace_back(i);
    }
  }
  return P;
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N;
  cin >> N;
  vector<int> prime = Eratosthenes(55555);
  vector<int> ans;
  int cnt = 0;
  int idx = 1;
  while (cnt < N)
  {
    if ((prime[idx] - 1) % 5 == 1)
    {
      ans.push_back(prime[idx]);
      cnt++;
    }
    idx++;
  }
  for (auto &it : ans)
    cout << it << " ";
  cout << endl;
}

// 1引いた数の5のmodが等しいものを詰めていけば絶対に5の倍数になるはず


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int gcd(long long a,long long b)
{
    if(b==0)
        return a;
    return 
        gcd(b,a%b);
}
int main()
{
	long long a,b;
	cin>>a>>b;
    cout<<a/gcd(a,b)*b;
    return 0;
}

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

int main(){
  int N; cin >> N;
  int result=0;
  int v[100],c[100];
  for(int i=0; i<N; i++) cin >> v[i];
  for(int i=0; i<N; i++) cin >> c[i];
  
  for(int i=0; i<N; i++) result+=max(0,v[i]-c[i]);
  
  cout << result << endl;
}

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

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int MOD = 1000000007;
const int INF = 2147483647;

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

//myfuncs
//素数判定
template<class T> inline T isPrime(T x) {
    bool ret = true;
    if (x < 2) {
        ret = false;
    }
    for (LL i = 2; i <= sqrt(x); i++) {
        if (x%i == 0) {
            ret = false;
        }
    }
    return ret;
}

//Union FInd
struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

//main code

int main(int argc, char const* argv[])
{
    int q;
    cin >> q;
    vector<int> sum(100001,0);
    int sum_prime = 0;
    for (int i = 1; i < 100001; i+=2) {
        if (isPrime(i) and isPrime((i+1)/2)) {
            sum_prime++;
        }
        sum[i] = sum_prime;
    }
    for (int i = 0; i < q; i++) {
        int l,r;
        cin >> l >> r;
        if (l == 1) {
            cout << sum[r] - sum[l] << endl;
        }
        else {
            cout << sum[r] - sum[l-2] << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 1024
using System;

class Program {
  static void Main(string[] args) {
    string SA = Console.ReadLine().Trim();
    string SB = Console.ReadLine().Trim();
    string SC = Console.ReadLine().Trim();
    int turn = 'a';

    while(turn >= 'a' && turn <= 'c') {
      switch(turn) {
      case 'a':
        if(SA.Length == 0) turn = 'A';
        else {
          turn = Convert.ToChar(SA.Substring(0,1));
          SA = SA.Remove(0,1);
        }
        break;
      case 'b':
        if(SB.Length == 0) turn = 'B';
        else {
          turn = Convert.ToChar(SB.Substring(0,1));
          SB = SB.Remove(0,1);
        }
        break;
      case 'c':
        if(SC.Length == 0) turn = 'C';
        else {
          turn = Convert.ToChar(SC.Substring(0,1));
          SC = SC.Remove(0,1);
        }
        break;
      }
    }

    Console.WriteLine(Convert.ToChar(turn));
  }
}


Measured memory_bytes: 11220
// #pragma GCC optimize(3, "Ofast", "inline")
#include <bits/stdc++.h>
#define String std::string
#define fi first
#define se second
#define mp std::make_pair
#define Pair std::pair<int, int>
#define Map std::map< int, int >
#define Vector std::vector<int>
 
using std::cin;
using std::cout;
using std::endl;
 
typedef long long ll;
typedef unsigned long long ull;
 
const int N = 100000 + 5;
const int M = 1000 + 5;
const int K = 1e7 + 5;
const int MOD = 1e9 + 7;
const int inv2 = 500000004;
const int LOG = 40;
const ull BASE = 19260817;
const int dx[] = { 0, 1, -1, 0, 1, -1, 1, -1 };
const int dy[] = { 1, 0, 0, -1, 1, -1, -1, 1 };
// const double PI = acos(-1);
const double PI = 3.14159;

template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }
 
template<class T>
inline T readT() {
    T res = 0, f = 1;
    char ch = getchar();
    for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1;
    for (; isdigit(ch); ch = getchar()) res = (res << 1) + (res << 3) + ch - '0';
    return res * f;
}
#define read readT<int>

namespace Comb{
const int N = 10 + 5;
inline void exgcd(ll a, ll b, ll &g, ll &x, ll &y) {
    if (!b) g = a, x = 1, y = 0;
    else exgcd(b, a % b, g, y, x), y -= x * (a / b);
}
 
inline ll inv(ll a) {
    ll g, res, tmp;
    exgcd(a, MOD, g, res, tmp);
    return ((res % MOD) + MOD) % MOD;
}
 
ll f[N], invFact[N];
 
inline void prepare() {
    f[0] = 1;
    int n = 200000;
    for (int i = 1; i <= n; i++) f[i] = f[i - 1] * i % MOD;
    invFact[n] = inv(f[n]);
    for (int i = n - 1; i >= 1; i--) invFact[i] = invFact[i + 1] * (i + 1) % MOD;
}
 
inline ll C(int n, int m) {
    if (!m) return 1;
    if (n == m) return 1;
    if (m > n) return 0;
    if (m < 0) return 0;
    return f[n] * invFact[m] % MOD * invFact[n - m] % MOD;
}
}

int n, h[N * 2], k;

int main() {
    cin >> n >> k;
    for (int i = 1; i <= n; i++) scanf("%d", &h[i]);
    std::sort(h + 1, h + n + 1, std::greater<int>());
    ll ans = 0;
    for (int i = k + 1; i <= n; i++) {
        ans += h[i];
    }
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 1024
#!/usr/bin/env python3
import sys
INF = float("inf")


def solve(N: int, Z: int, W: int, a: "List[int]"):
    if N == 1:
        print(abs(a[0]-W))
    else:
        print(max(abs(a[-1]-a[-2]), abs(a[-1]-W)))
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    Z = int(next(tokens))  # type: int
    W = int(next(tokens))  # type: int
    a = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, Z, W, a)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3316
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

struct UFTree(T)
{
    struct Node
    {
        T parent;
        T rank = 1;
    }

    ///
    T min_size, max_size;

    ///
    this(T n)
    {
        nodes.length = n;
        sizes.length = n;
        foreach (i, ref node; nodes) {
            node = Node(i.to!T);
            sizes[i] = 1;
        }

        min_sizes.length = n + 1;
        min_sizes[1] = n;
        min_size = 1;
        max_size = 1;
    }

    ///
    bool unite(T a, T b)
    {
        a = root(a);
        b = root(b);

        if (a == b) return false;

        auto a_size = sizes[a];
        auto b_size = sizes[b];
        --min_sizes[a_size];
        --min_sizes[b_size];
        ++min_sizes[a_size + b_size];
        foreach (nxt_size; min(a_size, b_size)..min_sizes.length) if (min_sizes[nxt_size] != 0) {
            min_size = nxt_size.to!T;
            break;
        }
        max_size = max(max_size, a_size + b_size);

        if (nodes[a].rank < nodes[b].rank) {
            sizes[a] += sizes[b];
            nodes[b].parent = a;
        } else {
            sizes[b] += sizes[a];
            nodes[a].parent = b;
            if (nodes[a].rank == nodes[b].rank) ++nodes[b].rank;
        }

        return true;
    }

    ///
    bool is_same(T a, T b)
    {
        return root(a) == root(b);
    }

    ///
    T size(T i)
    {
        return sizes[root(i)];
    }

private:
    Node[] nodes;
    T[] sizes;
    T[] min_sizes;

    T root(T i)
    {
        if (nodes[i].parent == i) return i;

        return nodes[i].parent = root(nodes[i].parent);
    }
}

///
UFTree!T uftree(T)(T n)
{
    return UFTree!T(n);
}

void main()
{
    auto nm = readln.split.to!(long[]);
    auto N = nm[0];
    auto M = nm[1];
    long[] as, bs;
    foreach (_; 0..M) {
        auto ab = readln.split.to!(long[]);
        as ~= ab[0]-1;
        bs ~= ab[1]-1;
    }

    auto uft = uftree(N);
    auto r = N * (N-1) / 2;
    long[] rs;
    foreach_reverse (i; 0..M) {
        rs ~= r;
        auto a = as[i];
        auto b = bs[i];
        if (uft.is_same(a, b)) continue;
        r -= uft.size(a) * uft.size(b);
        uft.unite(a, b);
    }
    foreach_reverse (rr; rs) writeln(rr);
}

Measured memory_bytes: 9724
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

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

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

// Self settings
// clang-format off
#define MAX_N 100000
#define REP(i, N) for (int i = 0; i < (int)(N); ++i)
#define SLN(i,N) (i == N-1 ? "\n" : " ")
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
const ll MOD = 1e9+7;
const ll INF = 1LL << 60;
const int inf = 1 << 31;
// clang-format on

int cnt_divisor(int n)
{
  int cnt = 0;
  for (int i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      cnt++;
      if (n / i != i) cnt++;
    }
  }
  return cnt;
}

int main(void)
{
  int N;
  cin >> N;
  int cnt = 0;
  for (int i = 1; i <= N; i += 2) {
    if (cnt_divisor(i) == 8) cnt++;
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
const int MOD = 1e9 + 7;
typedef long long lint;
const int INF = 1e7;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repi(i, k, n) for (int i = (k); i < (int)(n); ++i)
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define all(x) (x).begin(), (x).end()
#define pb push_back
int main()
{
    string s;
    cin >> s;
    int a = s[0] - '0';
    a *= 10;
    a += s[1] - '0';
    int b = s[2] - '0';
    b *= 10;
    b += s[3] - '0';
    if (a > 0 && a < 13 && b > 0 && b < 13)
    {
        cout << "AMBIGUOUS" << endl;
    }
    else if (b > 0 && b < 13)
    {
        cout << "YYMM" << endl;
    }
    else if (a > 0 && a < 13)
    {
        cout << "MMYY" << endl;
    }else{
        cout << "NA" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h> 
#define INFTY 1000000000

int c;

void merge(int S[], int left, int mid, int right){

	int n1 , n2;
	int i , j , k;
	
	n1 = mid - left;
	n2 = right - mid;
	
	int L[n1] , R[n2];
	
	for( i = 0; i < n1; i++ ){
		L[i] = S[left + i];
	}
	for( i = 0; i < n2; i++ ){
		R[i] = S[mid + i];
	}
	
	L[n1] = R[n2] = INFTY;
	
	i = 0;
	j = 0;
	
	for ( k = left; k < right; k++ ){
		
		c++;
		
		if( L[i] <= R[j] ){
			S[k] = L[i];
			i++;
		}else{
			S[k] = R[j];
			j++;
		}
	}
}

void mergeSort(int S[], int left, int right){
	
	int mid;
	
	if ( left+1 < right ){
		
		mid = (left + right)/2;
		mergeSort(S, left, mid);
		mergeSort(S, mid, right);
		merge(S, left, mid, right);
		
	}
	
}

int main( void ){
	
	int n;
	int S[500000];
	int i;
	
	c = 0;

	scanf( "%d" , &n );
	
	for( i = 0; i < n; i++ ){
		scanf( "%d" , &S[i] );
	}
	
	mergeSort(S, 0, n);
	
	for( i = 0; i < n; i++ ){
		if( i != 0 ){ printf( " " ); }
		printf( "%d" , S[i] );
	}
	
	printf( "\n%d\n" , c );
	
}


Measured memory_bytes: 5612
h,w,d=map(int,input().split())
a=[list(map(int,input().split()))for i in range(h)]
num=[[]for i in range(h*w+1)]
num[0]=([0,0])
for i in range(h):
  for j in range(w):
    num[a[i][j]].extend([i,j])
cumsum=[0]*(h*w+1)
for i in range(d,h*w+1):
  x1,y1=num[i]
  x2,y2=num[i-d]
  cumsum[i]+=cumsum[i-d]+abs(x1-x2)+abs(y1-y2)
Q=int(input())
for _ in range(Q):
  x,y=map(int,input().split())
  print(cumsum[y]-cumsum[x])

Measured memory_bytes: 22136
#include <bits/stdc++.h>
using namespace std;
 
typedef long long int ll;
typedef long double ld;
typedef unsigned long long int ull;
 
#define FOR(i,vv,n) for(ll i=vv;i<n;i++)
#define FORR(i,n,vv) for(ll i=n-1;i>=vv;i--)
#define ve vector 
#define maxe(v) *max_element(v.begin(),v.end())
#define mine(v) *min_element(v.begin(),v.end())
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mp make_pair
#define M 1000000007
#define precise cout.precision(18)
// #define f first
// #define s second



int main(){
 
	// #ifndef ONLINE_JUDGE
 //    // for getting input from input.txt
 //    freopen("input.txt", "r", stdin);
 //    // for writing output to output.txt
 //    freopen("output.txt", "w", stdout);
	// #endif
    FAST

char c;
cin>>c;
cout<<(char)(c+1);


return 0;
}
 

Measured memory_bytes: 256
// 🐋💭
import Foundation

func readInts() -> [Int] {
    return readLine()!.split(separator: " ").map { Int($0)! }
}

func readInt() -> Int {
    return Int(readLine()!)!
}

func readDoubles () -> [Double] {
    return readLine()!.split(separator: " ").map { Double($0)! }
}

func readDouble() -> Double{
    return Double(readLine()!)!
}

func readLines() -> [String] {
    return readLine()!.map { String($0) }
}
///最大公約数を返す
func gcd(_ m:Int, _ n:Int) -> Int {
    if n == 0 {return m}
    return gcd(n, m % n)
}

///最大公約数を返す
func gcd(_ array: [Int]) -> Int {
    var value = array[0]
    if array.count > 1 {
        for i in 1..<array.count {
            value = gcd(value, array[i])
        }
    }
    return value
}

///最小公倍数を返す
func lcm(_ m:Int, _ n:Int) -> Int {
    return m * n / gcd(m, n)
}

///素数判定(試し割り)
func isPrime(_ x:Int) -> Bool {
    if x <= 1 || x % 2 == 0 { return false }
    if x == 2 { return true }
    for i in stride(from: 3, to: Int(ceil(sqrt(Double(x)))), by: 2){
        if x % i == 0 {
            return false
        }
    }
    return true
}

//https://program-life.com/669
///実行速度の計測
func exectionTime(action: () -> Void) {
    let startDate = Date()
    action()
    let endDate = Date()
    print(endDate.timeIntervalSince(startDate))
}

//https://riptutorial.com/ja/swift/example/14738/インデックスを知らずに配列から要素を削除する
extension Array where Element: Equatable {
    
    mutating func remove(_ element: Element) {
        _ = firstIndex(of: element).flatMap {
            self.remove(at: $0)
        }
    }
}

func binarySearch(rifgt:Int, key:Int, ary:[String]) -> Int{
    var left = 0
    var right = rifgt
    
    while abs(right - left) > 1 {
        let mid = left + (right - left) / 2
        
        if Int(ary[mid])! < key {
            left = mid
            
        } else {
            right = mid
        }
    }
    return left
}

func arrangement (prev:String, ary:[String], returnVal:[String]) -> [String] {
    var returnVal = returnVal
    if ary.count == 0 {
        returnVal.append(prev)
        return returnVal
    }
    
    for s in ary {
        let wprev = prev + s
        var wary = ary
        wary.remove(s)
        returnVal = arrangement(prev: wprev, ary: wary, returnVal: returnVal)
    }
    return returnVal
}
// https://algo-logic.info/divisor/
/// 約数の配列を返す
func divisor(_ n:Int) -> [Int] {
    var ret = [Int]()
    var i = 1
    while i * i <= n {
        if n % i == 0 {
            ret.append(i)
            if i * i != n {
                ret.append(n / i)
            }
        }
        i += 1
    }
    return ret.sorted()
}

func main() {
    let input = readInts()
    let(D, T, S) = (input[0], input[1], input[2])
    //＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿入力
    
    print(T * S < D ? "No": "Yes")
    
}
main()



Measured memory_bytes: 13668