akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>

int main(){
  int x,y,z,a,b,c;

  scanf("%d%d",&x,&y);
  
  if(x > y) {
    a = x;
    b = y;
  }
  else{
    a = y;
    b = x;
  }

  c = a % b;
  while(c != 0){
  a = b;
  b = c;
  c = a % b;
  }
  z = b;
  
  printf("%d\n",z);

  return 0;
}
  



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

int main()
{
  string s; cin >> s;
  int q; cin >> q;
  vector<deque<char>> dq(2);
  int st = 0;
  rep(i, q) {
    int t; cin >> t;
    if (t == 1) {
      st ^= 1;
    } else {
      int f; cin >> f;
      char c; cin >> c;
      if (f == 1) {
        if (st) dq[1].push_back(c);
        else dq[0].push_front(c);
      } else {
        if (st) dq[0].push_front(c);
        else dq[1].push_back(c);
      }
    }
  }
  if (st) {
    reverse(dq[0].begin(), dq[0].end());
    reverse(dq[1].begin(), dq[1].end());
    reverse(s.begin(), s.end());
    for (auto c:dq[1]) cout << c;
    cout << s;
    for (auto c:dq[0]) cout << c;
  } else {
    for (auto c:dq[0]) cout << c;
    cout << s;
    for (auto c:dq[1]) cout << c;
  }
  cout << endl;

  return 0;
}


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

typedef ostringstream OSS;
typedef istringstream ISS;

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

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef vector<double> VD;
typedef vector<VD> VVD;
typedef vector<string> VS;
typedef vector<VS> VVS;
typedef vector<bool> VB;
typedef vector<VB> VVB;
typedef vector<PII> VPII;

#define fst first
#define snd second
// #define Y first
// #define X second
#define MP make_pair
#define PB push_back
#define EB emplace_back 
#define ALL(x) (x).begin(),(x).end()
#define RANGE(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))
#define DUMP( x ) cerr << #x << " = " << ( x ) << endl
#define rep(i, N) for (int i = 0; i < (N); i++)
#define rep2(i, j, N, M) rep(i, N) rep(j, M)
#define rep3(i, j, k, N, M, L) rep(i, N) rep(j, M) rep(k, L)
#define REP(i, init, N) for (int i = (init); i < (N); i++)

template < typename T > inline T fromString(const string &s) { T res; ISS iss(s); iss >> res; return res; };
template < typename T > inline string toString(const T &a) { OSS oss; oss << a; return oss.str(); };

const int INF = 0x3f3f3f3f;
const LL INFL = 0x3f3f3f3f3f3f3f3fLL;
const double DINF = 0x3f3f3f3f;
const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};

int N, M;
VD ls, as, bs;

double distance(int i, int j) {
    double l = ls[i] - ls[j];
    double a = as[i] - as[j];
    double b = bs[i] - bs[j];

    return l * l + a * a + b * b;
}

double solve() {
    double ans = 0;

    for (LL p = 0; p < 1LL << N; p++) {
        if (__builtin_popcount(p) != M) continue;

        double sum = 0;
        rep(i, N) REP(j, i + 1, N) {
            if (!(1 << i & p)) continue;
            if (!(1 << j & p)) continue;

            sum += distance(i, j);
        }
        ans = max(ans, sum);
    }

    return ans;
}

int main(void) {
    while (cin >> N >> M, N) {
        ls = VD(N);
        as = VD(N);
        bs = VD(N);
        rep(i, N) {
            cin >> ls[i] >> as[i] >> bs[i];
        }

        printf("%.9f\n", solve());

        return 0;
    }

	return 0;
}

Measured memory_bytes: 1244
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
#include<stdio.h>
#include <cstdint>
#include <stdlib.h> 
#include <time.h>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define rrep(i,n) REP(i,1,n+1)
#define all(a) a.begin(), a.end()
#define fi first
#define se second
#define RNG(x, a, n) &((x)[a]), &((x)[n])
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
typedef long long ll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> PII;
typedef vector<ll> Vl;
typedef vector<int> VI;
typedef tuple<int, int, int> TT;
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define rall(v) v.rbegin(), v.rend()
#define dmp(x,y) make_pair(x,y)
#define dmt(x, y, z) make_tuple(x, y, z)
#define pb(x) push_back(x)
#define pf(x) push_front(x)
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;
const long double PI = (acos(-1));
const long double EPS = 0.0000000001;


vector<pair<int, int>> G[200000];    // 辺 G[i] = P(j, w): i番目の頂点からj番目の頂点へコストwの辺をはる
int d[200000];    // d[i]: i番目の頂点の色(d[i]=0:無色, d[i]=1:白, d[i]=2:黒)

// dfs(u, s): 頂点uの処理(s=0なら白色に塗る, s=1なら黒色に塗る)
void dfs(int u, int s) {
    if (s == 0)d[u] = 1;
    else d[u] = 2;
    // 隣接した頂点が無色ならその頂点に移動して、適した色を塗る
    rep(i, G[u].size()) {
        pair<int, int> p = G[u][i];    // p = (p.first, p.second) = (行先の頂点番号, コスト)
        if (d[p.first] != 0)continue;   // 無色でなければ移動しない
        dfs(p.first, (s + p.second) % 2);    // コストが奇数なら今いる頂点と違う色、偶数なら同じ色で塗る
    }
    return;   // 隣接する頂点を塗り終わったらreturn
}

signed main() {
    int n; cin >> n;
    rep(i, n - 1) {
        int u, v, w; cin >> u >> v >> w;
        G[u].pb(make_pair(v, w));
        G[v].pb(make_pair(u, w));
    }

    // 頂点1からdfsする(頂点1は白色に塗る)
    // dfsはどこの頂点から始めてもいいし何色(白か黒)で始めてもいい
    dfs(1, 0);
    rrep(i, n)cout << d[i] - 1 << endl;
    return 0;
}

Measured memory_bytes: 10752
n,k=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
dp=[0]*(k+1)
for i in range(a[0]):
    dp[i]="s"
for u in a:
    dp[u]="f"
for i in range(a[0]+1,k+1):
    if dp[i]==0:
        for u in a:
            if i<u:
                continue
            else:
                if dp[i-u]=="s":
                    dp[i]="f"
                    break
        else:
            dp[i]="s"
if dp[k]=="f":
    print("First")
else:
    print("Second")

Measured memory_bytes: 44132
#include <iostream>
using namespace std;
int main(){
    int a, b, c; //a:１ログインでもらえるコイン数, b:７日間連続でログインしたらもらえるコイン数, c:欲しいコイン数
    cin >> a >> b >> c;
    int ans = 0; //回数カウンタ
    int d = 0; //枚数カウンタ
    while(d < c){
        ans++;
        d += a;
        if(ans%7 == 0){
            d += b;
        }
    }

    cout<<ans<<endl;

    return 0;
    }


Measured memory_bytes: 3116
//============================================================================
// Name        : JOI.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <math.h>
#include <stdio.h>
#include <vector>
using namespace std;
typedef long long ll;
int a,b,c;
int main(){
	cin>>a>>b>>c;


	int X=a;
	X=max(X,b);
	X=max(X,c);
	if(a+b+c-X==X)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;

	return 0;
}


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

using namespace std;

int main(){
    int K, X;
    cin >> K >> X;
    if (K < 2){
        cout << X << endl;
        return 0;
    }
    int minX = X - (K - 1);
    int maxX = X + (K - 1);
    for (int i = minX; i <= maxX; i++){
        cout << i <<" ";
    }
    cout << endl;
}

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

ll MAX_LUNLUN = 3234566667;
int n;

int main()
{
    cin >> n;
    
    queue<ll> que;
    rep(i, 9) que.push(i + 1);
    ll x = 0, cnt = 0;;
    while(cnt < n)
    {
        x = que.front();
        que.pop();
        for(int i = max((x % 10) - 1, 0LL); i <= min((x % 10) + 1, 9LL); i++)
        {
            que.push(10 * x + i);
        }
        cnt++;
    }
    cout << x << endl;
    
    return 0;
}


Measured memory_bytes: 1792
# D Patisserie
import itertools as itl
#入力を取得
N,M=map(int,input().split())
check=M+10 if M+10<=N else N
xyz_list,x_list,y_list,z_list=[],[],[],[]
for i in range(N):
    xyz_list.append(input().split())
    
var_list=[x for x in itl.product([-1,1],repeat=3)]
sum_list=[]
for i in var_list:
    sort_list=[0,]*N
    for j in range(N):
        sort_list[j]=int(xyz_list[j][0])*i[0]+ int(xyz_list[j][1])*i[1]+ int(xyz_list[j][2])*i[2]
    sort_list.sort(reverse=True)
    sum_=0
    for j in range(M):
        sum_+=sort_list[j]
    sum_list.append(sum_)
    
sum_list.sort(reverse=True)
print(sum_list[0])

Measured memory_bytes: 3444
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

x = int(readline())
for i in range(-118, 119):
    for j in range(-119, 118):
        a = i ** 5 - j ** 5
        b = j ** 5 - i ** 5
        if x == a:
            print(i, j)
            exit()
        if x == b:
            print(j, i)
            exit()


Measured memory_bytes: 9192
n=int(input())
s=input()

from collections import Counter

ans = s.count("R") * s.count("G") * s.count("B")

for step in range(1,n//2+2):
    for start in range(n):
#         print(start,step,start+2*step,n)
        if start+2*step>=n:
#             print("out!")
            break
        ans-=len(set((s[start], s[start+step],s[start+2*step])))==3
print(ans)

Measured memory_bytes: 74676
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>
using namespace std;

typedef long long int ll;
const int MAX_N = 100010;
struct UnionFind {
    int node[MAX_N];
    UnionFind() {}
    void init() {
        memset(node, -1, sizeof(node));
    }

    int find(int x) {
        return (node[x] < 0 ? x : node[x] = find(node[x]));
    }

    bool same(int x, int y) {
        return find(x) == find(y);
    }

    int size(int x) {
        return -node[find(x)];
    }

    void unite(int x, int y) {
        x = find(x), y = find(y);
        if(same(x, y)) return;
        // y を x に統合
        node[x] += node[y];
        node[y] = x;
    }
};

struct Query {
    // q: mark -> 0, query -> 1
    int q, v;
    Query() {}
    Query(int a, int b) : q(a), v(b) {}
};

vector< vector<int> > G;
int N, Q, mark[100010], parent[100010];
Query qs[100010];
UnionFind uf;

int main() {
    while(1) {
        // init
        uf.init();
        memset(mark, 0, sizeof(mark));
        memset(parent, -1, sizeof(parent));
        G.clear();

        scanf("%d%d", &N, &Q);
        if(N == Q && Q == 0) break;
        G.resize(N);

        for(int i=1; i<N; i++) {
            int par; scanf("%d", &par); par--;
            G[par].push_back(i);
            parent[i] = par;
        }

        for(int i=0; i<Q; i++) {
            char mode; int v;
            scanf(" %c%d", &mode, &v); v--;
            qs[i] = Query(mode == 'Q', v);
            if(mode == 'M') mark[v]++;
        }

        for(int i=1; i<N; i++) {
            if(!mark[i]) {
                uf.unite(parent[i], i);
            }
        }

        ll ans = 0;
        for(int i=Q-1; i>=0; i--) {
            // mark
            if(qs[i].q == 0) {
                if(--mark[qs[i].v] == 0) {
                    int par = parent[qs[i].v];
                    if(par < 0) continue;
                    uf.unite(par, qs[i].v);
                }
            }
            // query
            else {
                ans += uf.find(qs[i].v) + 1;
            }
        }
        printf("%lld\n", ans);
    }
    return 0;
}


Measured memory_bytes: 9912
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <cstring>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <regex>
#include <vector>

#define fix(n)          cout<<fixed<<setprecision(n)
#define rep(i,n)        for (int i = 0; i < (n); ++i)
#define all(a)          (a).begin(), (a).end()
#define sort(a)         sort(all(a))
#define uniq(a)         sort(a);(a).erase(unique(all(a), (a).end())
#define reverse(a)      reverse(all(a))
#define ctos(c)         string(1, (c))
#define out(d)          cout << (d)
#define outl(d)         std::cout<<(d)<<"\n"
#define YES()           cout << "YES" << endl
#define NO()            cout << "NO" << endl
#define Yes()           cout << "Yes" << endl
#define No()            cout << "No" << endl
#define ceil(x, y)      ((x + y - 1) / (y))
#define debug(x)        cerr << #x << ": " << (x) << '\n'
#define debug2(x, y)    cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v)          for (size_t _ = 0; _ < v.size(); ++_){ cerr << #v << "[" << _ << "] : " << v[_] << '\n'; }
#define pb              push_back
#define fst             first
#define int             long long

using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;

const ll MOD = 1000000007; // 10^9 + 7
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

bool isReversible(string s) {
  string t = s;
  reverse(t);
  return s == t;
}

void solve() {
  string s; cin >> s;

  if (!isReversible(s)) {
    No();
    return;
  }

  int n = s.size();
  if (isReversible(s.substr(0, (n-1)/2)) && isReversible(s.substr((n+1)/2))) Yes();
  else No();
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  srand((unsigned)time(NULL));
  fix(12);

  solve();
}


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

using namespace std;

typedef long long ll;

int main()
{
    ios_base::sync_with_stdio(0);
    ll n;
    cin >> n;
    if (n % 2 == 1)
    {
        cout << "0";
        return 0;
    }
    ll il2 = 0, p2 = 2;
    while (p2 <= n)
    {
        il2 += n / p2;
        p2 *= 2;
    }
    ll il5 = 0, p5 = 5;
    while (p5 * 2 <= n)
    {
        il5 += n / ((ll) 2 * p5);
        p5 *= 5;
    }
    cout << min(il2, il5);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,t,x,y;
int main(){
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>t>>x>>y;
        if((x+y<=t&&(t-x-y)%2==0)==0){
            cout<<"No";
            return 0;
        }
    }
    cout<<"Yes";
    return 0;
}

Measured memory_bytes: 256
import math

def A():
    x, a, b = [int(x) for x in input().split()]
    if abs(x-a) < abs(x-b):
        print('A')
    else:
        print('B')
def B():
    S = input()
    alphabet = [False for x in range(26)]
    for char in S:
        i = ord(char) - ord('a')
        alphabet[i] = True
    printed = False
    for i in range(len(alphabet)):
        if alphabet[i] == False:
            print(chr(ord('a')+i))
            printed = True
            break
    if printed == False:
        print("None")
def C():
    num = sorted([1] + [pow(6, x+1) for x in range(6)] + [pow(9, x+1) for x in range(5)])
    n = int(input())
    stack = [(n, 0)]
    memo = {}
    _min = 999999

    cost = {}

    while len(stack) > 0:
        node = stack.pop()
        for k in num:
            if node[0] >= k:
                ans = (node[0] - k, node[1] + 1)
                if ans[0] == 0:
                    _min = min(_min, ans[1])
                else:
                    if str(ans[0]) in memo and memo[str(ans[0])] <= ans[1]:
                        pass
                    else:
                        stack.append(ans)
                        memo[str(ans[0])] = ans[1]
    print(_min)

def E():
    n, m = [int(x) for x in input().split()]
    P = [[] for i in range(n)]
    for j in range(m):
        p, y = [int(x) for x in input().split()]
        P[p-1].append([y, ('000000'+str(p))[-6:], j])

    for i in range(n):
        P[i] = sorted(P[i], key=lambda x:x[0])
        for j in range(len(P[i])):
            P[i][j][1] += (('000000'+str(j+1))[-6:])
    P = [e for inner_list in P for e in inner_list]
    P = sorted(P, key=lambda x:x[2])
    for p in P:
        print(p[1])
C()


Measured memory_bytes: 17168
#include <bits/stdc++.h>
#define prt_cs                  printf("Case %lld: ",cs)
#define sqr(x)                  (x)*(x)
#define ms(a,b)                 memset(a, b, sizeof(a))
#define db                      double
#define ll                      long long int
#define MOD                     100000007
#define PI                      2*acos(0.0)
#define pii                     pair< int, int >
#define READ                    freopen("in.txt","r",stdin)
#define WRITE                   freopen("out.txt","w",stdout)
#define gcd(a, b)               __gcd(a, b)
#define lcm(a, b)               (((a)*(b))/gcd(a,b))
#define MAX                     100005

using namespace std;

ll W[101],v[101],dp[101][MAX];

ll solve(ll idx,ll n,ll w)
{
//    if(w<0)return -MOD;
    if(idx==n)
    {
        return 0;
    }
    if(dp[idx][w]!=-1)return dp[idx][w];
    ll ans=0,r1=-MOD,r2=-MOD;
    if(w-W[idx]>=0)
    {
        r1=v[idx]+solve(idx+1,n,w-W[idx]);
    }
    r2=solve(idx+1,n,w);
    ans=max(r1,r2);
    return dp[idx][w]=ans;
}

int main()
{
//    READ;
//    WRITE;
    ms(dp,-1);
    ll n,w;
    scanf("%lld %lld",&n,&w);
    for(int i=0;i<n;i++)
    {
        scanf("%lld %lld",&W[i],&v[i]);
    }
    ll ans=solve(0,n,w);
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 79104
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <numeric>
#include <queue>
#include <map>

template <class T, class U>
inline bool chmin(T &lhs, const U &rhs) {
  if (lhs > rhs) {
    lhs = rhs;
    return true;
  }
  return false;
}

template <class T, class U>
inline bool chmax(T &lhs, const U &rhs) {
  if (lhs < rhs) {
    lhs = rhs;
    return true;
  }
  return false;
}

// [l, r) from l to r
struct range {
  struct itr {
    int i;
    constexpr itr(int i_): i(i_) { }
    constexpr void operator ++ () { ++i; }
    constexpr int operator * () const { return i; }
    constexpr bool operator != (itr x) const { return i != x.i; }
  };
  const itr l, r;
  constexpr range(int l_, int r_): l(l_), r(std::max(l_, r_)) { }
  constexpr itr begin() const { return l; }
  constexpr itr end() const { return r; }
};

// [l, r) from r to l
struct revrange {
  struct itr {
    int i;
    constexpr itr(int i_): i(i_) { }
    constexpr void operator ++ () { --i; }
    constexpr int operator * () const { return i; }
    constexpr bool operator != (itr x) const { return i != x.i; }
  };
  const itr l, r;
  constexpr revrange(int l_, int r_): l(l_ - 1), r(std::max(l_, r_) - 1) { }
  constexpr itr begin() const { return r; }
  constexpr itr end() const { return l; }
};

int main() {
  int N, M;
  std::cin >> N >> M;
  std::vector<int> A(M), B(M);
  std::vector<std::vector<int>> graph(N);
  for (int i: range(0, M)) {
    std::cin >> A[i] >> B[i];
    --A[i]; --B[i];
    graph[A[i]].push_back(B[i]);
    graph[B[i]].push_back(A[i]);
  }
  std::queue<std::pair<int, int>> que;
  que.emplace(0, -1);
  std::vector<int> dist(N, N + 1);
  dist[0] = 0;
  std::vector<int> ans(N);
  while (!que.empty()) {
    auto [u, p] = que.front();
    que.pop();
    ans[u] = p;
    for (int v: graph[u]) {
      if (chmin(dist[v], dist[u] + 1)) {
        que.emplace(v, u);
      }
    }
  }
  std::cout << "Yes\n";
  for (int i: range(1, N)) {
    std::cout << ans[i] + 1 << '\n';
  } 
  return 0;
}


Measured memory_bytes: 12324
import java.util.Scanner;

fun main (args : Array<String>) {
  val input = Scanner(System.`in`)
  
  while (input.hasNext()) {
    val N = input.nextInt()
    val R = input.nextInt()
    
    if (N >= 10) {
      println(R)
    } else {
      println(R + 100 * (10 - N))
    }
  }
}

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

using namespace std;

int main() {
	int N, H;

	cin >> N >> H;
	vector<pair<int, int>> swords(N);

	int a_max = 0;
	for (int i = 0; i < N; i++) {
		cin >> swords[i].second >> swords[i].first;
		a_max = max(a_max, swords[i].second);
	}
	
	sort(swords.begin(), swords.end());
	auto ite2 = lower_bound(swords.begin(), swords.end(), make_pair(a_max, a_max));
	int b_max = swords[ite2 - swords.begin()].first;
	swords.erase(ite2);
	auto ite1 = lower_bound(swords.begin(), swords.end(), make_pair(a_max + 1, 0));

	int ans = 0, i;
	i = ite1 - swords.begin();
	while(swords.size() > i)
	{
		H -= swords[swords.size()-1].first;
		swords.pop_back();
		ans++;
		if (H <= 0) {
			cout << ans << endl;
			return 0;
		}
	}

	while (H > b_max) {
		H -= a_max;
		ans++;
	}
	ans++;

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); ++i)
typedef long long ll;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
const ll INF = 1LL << 60;

int main(){
	int a, b, k; cin >> a >> b >> k;
	set<int> st;
	for(int i = a; i < a+k; ++i){
		if(i <= b)st.insert(i);
	}
	for(int i = b; i > b - k; --i){
		if(i >= a)st.insert(i);
	}
	for(auto itr : st){
		cout << itr << endl;
	}
}


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

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

    int cost1 = 0;
    int cost2 = 0;
    for (int i = 0; i < m; ++i) {
        if (a[i] > x) cost1++;
        else cost2++;
    }

    int ans = min(cost1, cost2);
    cout << ans;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	int a,b;
	cin>>a>>b;
	if((a>b&&b!=1)||(a==1&&b!=1))cout<<"Alice"<<endl;
	else if((a<b&&a!=1)||(b==1&&a!=1))cout<<"Bob"<<endl;
	else cout<<"Draw"<<endl;
}


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

using namespace std;
const int INF = 1e9;

int main() {
    int N, Ma, Mb; cin >> N >> Ma >> Mb;
    int dp[N + 1][1001][1001];
    for (int i = 0; i <= N; i++) {
        for (int j = 0; j <= 1000; j++) {
            for (int k = 0; k <= 1000; k++) {
                dp[i][j][k] = INF;
            }
        }
    }
    dp[0][0][0] = 0;

    for (int i = 1; i <= N; i++) {
        int a, b, c; cin >> a >> b >> c;
        for (int j = 0; j <= 1000; j++) {
            for (int k = 0; k <= 1000; k++) {
                if (j - a >= 0 && k - b >= 0) {
                    dp[i][j][k] = min(dp[i - 1][j][k], dp[i - 1][j - a][k - b] + c);
                } else dp[i][j][k] = dp[i - 1][j][k];
            }
        }
    }

    int ans = INF;
    for (int j = 1; j <= 1000; j++) {
        for (int k = 1; k <= 1000; k++) {
            if (j*Mb == k*Ma) ans = min(ans, dp[N][j][k]);
        }
    }

    if (ans == INF) ans = -1;
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 160768
using System;

namespace ConsoleApp3
{
	class Program
	{
		static void Main(string[] args)
		{
			var input = Console.ReadLine().Split(' ');
			ulong a = ulong.Parse(input[0]);
			ulong b = ulong.Parse(input[1]);
			ulong c = ulong.Parse(input[2]);
			ulong d = ulong.Parse(input[3]);

			// A ~ B の範囲で C または D で割り切れる数を除けばいい
			var countC = b / c - (a - 1) / c;
			var countD = b / d - (a - 1) / d;
			ulong lcm = Lcm(c, d);
			var countCD = b / lcm - (a - 1) / lcm;

			var count = b - a + 1 - (countC + countD - countCD);
			Console.WriteLine(count);
		}

		static ulong Lcm(ulong a, ulong b)
		{
			return a * b / Gcd(a, b);
		}

		static ulong Gcd(ulong a, ulong b)
		{
			if (a < b)
			{
				return Gcd(b, a);
			}

			while(b != 0)
			{
				var remainder = a % b;
				a = b;
				b = remainder;
			}
			return a;
		}
	}
}


Measured memory_bytes: 13140
/*
ID: wangjun30
LANG: C++11
TASK:
*/
#include<iostream>
#include<algorithm>
#include<array>
#include<unordered_map>
#include<map>
#include<set>
#include<list>
#include<stack>
#include<unordered_set>
#include<vector>
#include<bitset>
#include<queue>
#include<iomanip>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<climits>
//#include<fstream>
#define int long long
using namespace std;
//ifstream cin(".in");
//ofstream cout(".out");
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	set<string> S;
	int n;
	cin>>n;
	for(int i=1;i<=n;i++){
		string str;
		cin>>str;
		S.insert(str);
	}
	cout<<S.size();
	return 0;
}

Measured memory_bytes: 19248
n = int(input())
a = [[int(input())-1, False] for _ in range(n)]
a[0][1] = True
now = 0
cnt = 0
while True:
    now = a[now][0]
    if a[now][1]:
        print(-1)
        break
    a[now][1] = True
    cnt += 1
    if now == 1:
        print(cnt)
        break

Measured memory_bytes: 16372
#include<cstdio>
#include<cstring>
char str[100010];
int length,ans;
int main(){
	scanf("%s",str);
	length=strlen(str);
	ans=length/2;
	for(int i=0;i<length;i++) if(str[i]=='p') ans--;
	printf("%d",ans);
	return 0;
}

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

int main()
{
    long long A, B;
    cin >> A >> B;

    if ((A + B) % 2 == 0)
    {
        cout << (A + B) / 2 << endl;
    }
    else
    {
        cout << "IMPOSSIBLE" << endl;
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
void fastIO(){
  ios_base::sync_with_stdio(0); cin.tie(0);
}


int main(){
  string s,ans;
  cin>>s;
  bool a = s[0]==s[1]||s[1]==s[2]||s[2]==s[3];
  a?cout<<"Bad":cout<<"Good";
}








Measured memory_bytes: 256
import java.util.*;
import java.lang.*;
import java.io.*;


public class Main {
    static final int MOD = 1_000_000_007;
    public static long addMod(long a, long b){
    	long tmp = (a+b)%MOD;
    	return tmp>=0 ? tmp : tmp+MOD;
    }
    public static long subMod(long a, long b){
    	return addMod(a,-b);
    }
    public static long multMod(long a, long b){
    	long tmp = (a*b)%MOD;
    	return tmp>=0 ? tmp : tmp+MOD;
    }
    public static long powerMod(long a, long x){ //calculate a^x
        if(x<0)return 0;
        if(x==0)return 1;
        if(x%2==0) return (powerMod(a,x/2)*powerMod(a,x/2)) % MOD;
        return (a*powerMod(a,x-1)) % MOD;
    }
    public static long inverseMod(long a){
        return powerMod(a,MOD-2);
    }
    public static long divMod(long a, long b){
    	return multMod(a, inverseMod(b));
    }
    
    public static long solve(String S){
        int L = S.length();
        long[] Anum = new long[L];
        long[] ABnum = new long[L];
        long[] ABCnum = new long[L];
        Anum[0] = (S.charAt(0)=='A' || S.charAt(0)=='?') ? 1 : 0;
        ABnum[0]=0; ABCnum[0]=0;
        long strs = (S.charAt(0)=='?') ? 3 : 1;
        for(int l=1;l<L;l++){
        	char lth = S.charAt(l);
        	if(lth=='A'){
        	    Anum[l]  = addMod(Anum[l-1],strs);
        	    ABnum[l] = ABnum[l-1];
        	    ABCnum[l]= ABCnum[l-1];
        	}else if(lth=='B'){
        	    Anum[l]  = Anum[l-1];
        	    ABnum[l] = addMod(ABnum[l-1],Anum[l-1]);
        	    ABCnum[l]= ABCnum[l-1];
        	}else if(lth=='C'){
        	    Anum[l]  = Anum[l-1];
        	    ABnum[l] = ABnum[l-1];
        	    ABCnum[l]= addMod(ABCnum[l-1],ABnum[l-1]);
        	}else{
        	    Anum[l]  = addMod(multMod(3,Anum[l-1]),strs);
        	    ABnum[l] = addMod(multMod(3,ABnum[l-1]),Anum[l-1]);
        	    ABCnum[l]= addMod(multMod(3,ABCnum[l-1]),ABnum[l-1]);
        	    strs = multMod(strs,3);
        	}
        }
        return ABCnum[L-1];
    }
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        System.out.println(solve(S));
    }
}

Measured memory_bytes: 28920
#include<bits/stdc++.h>
#define LL long long
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPA(i,n) for(int i=1;i<(n);++i)
#define foreach(i, n) for(auto &i:(n))
#define PII pair<int,int>
#define PLI pair<long long, int>
#define PLL pair<long long, long long>
#define PDD pair<double, double>
#define MOD ((int)1e9 + 7)
#define INF ((int)1e9)
#define INFLL ((LL)1e18)
#define ALL(x) (x).begin(),(x).end()
#define ctoi(x) (x - 'a') 
#define CTOI(x) (x - 'A')
#define BIT(x) (1 << (x))
using namespace std;

LL modinv(LL a){
    LL b = MOD, u = 1, v = 0;
    while(b){
        LL t = a / b;
        a -= t * b;swap(a, b);
        u -= t * v;swap(u, v);
    }
    u%=MOD;
    if(u < 0) u += MOD;
    return u;

}

LL exp(LL a, LL b){
    LL sum = a;
    LL res = 1;
    while(b){
        if(b&1){
            res = (res * sum)%MOD;
        }
        sum = (sum * sum) % MOD;
        b>>=1;
    }
    return res;
}

int main(){
    int N, D;
    cin >> N >> D;
    vector<vector<int> > line(N, vector<int>(D));
    foreach(i, line){
        foreach(j, i)cin>>j;
    }
    int ans = 0;
    REP(i, N){
        REP(j, i){
            int sum = 0;
            REP(k, D){
                int d = (line[i][k] - line[j][k]);
                sum += d * d;
            }
            int d = sqrt((double)sum);
            if(sqrt((double)sum)-d<0.0001)++ans;
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
'use strict'
function main(inp) {
  inp = inp.trim().split('\n')
  const N = Number(inp.shift())
  inp = inp[0].split(' ').map(n => Number(n));

  let ans = 0
  for (let i = 0; i < N; i++) {
    for (let j = i + 1; j < N; j++) {
      ans += inp[i] * inp[j]
    }
  }
  console.log(ans)
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 21064
#include <bits/stdc++.h>
#define INF 1000000000
#define LINF 1000000000000000000
#define MOD 1000000007
#define mod 998244353
#define INF63 1061109567
#define INF127 9187201950435737471
#define UINF 18446744073709551615
#define F first
#define S second
#define ll long long
using namespace std;
ll n,x,t;
int main(){
	cin>>n>>x>>t;
	cout<<(n+x-1)/x*t<<endl;
	return 0;
}

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

using namespace std;
#define ll long long
#define ld long double
#define  P pair<ll,ll>
#define FOR(i,n,m) for(ll i=n; i<(ll)m;i++)
#define FORr(i,n,m) for(ll i=n; i>=(ll)m; i--)
#define FORm(i,m) for(auto i=m.begin();i!=m.end();i++)
#define VEC2(x,a,b) vector<vector<ll>> x = vector<vector<ll>>(a,vector<ll>(b,0))
#define sortAl(v) sort(v.begin(),v.end())
#define sortAlr(v) sort(v.begin(),v.end()); reverse(v.begin(),v.end())
#define cinv(v,n,m) FOR(i,n,m) cin>>v.at(i)
#define coutv(v,n,m) FOR(i,n,m) cout<<v.at(i) <<" "; cout<<endl
#define cout(n) cout<<fixed<<setprecision(n)
//計算量はsqrt(N)
template<typename T>
vector<T> Divisors(T n)
{
    vector<T> result;

    T boundary = sqrt(n);

    for (T i = 1; i <= boundary; i++) {
        if (n % i == 0) {
            result.push_back(i);
            if(i != (n / i) && i * i != n)
                result.push_back(n/i);
        }
    }
    sort(result.begin(),result.end());
    return result;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    map<ll,ll> mp;
    ll n;
    cin>>n;
    FOR(i,2,n+1){
      vector<ll> v = Divisors(i);
      ll div=i;
      FOR(j,1,v.size()){
        while(div%v[j]==0){
          div/=v[j];
          mp[v[j]]++;
        }
      }
    }
    mp[1]=0;
    map<ll,ll> ans;
    FORm(i,mp){
      if(i->second>=74){
        ans[75]++;
      }
      if(i->second>=24){
        ans[25]++;
      }
      if(i->second>=14){
        ans[15]++;
      }
      if(i->second>=4){
        ans[5]++;
      }
      if(i->second>=2){
        ans[3]++;
      }
//      cout<< i->first << " "<<i->second<<endl;
    }

    ll res=0;
    res+= ans[75];
    res+= ans[25] * max((ll)0,ans[3]-1);
    res+= ans[15] * max((ll)0,ans[5]-1);
    res+= (ans[5] * max((ll)0,ans[5]-1) * max((ll)0,ans[3]-2))/2;
    cout<<res<<endl;

}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
#include<list>
#include<set>
#include<cstring>
using namespace std;
long long int mod = 1e9 + 7;
int inf = 1e9;

int main() {
  int n, k; cin >> n >> k;
  vector<int> h(n);
  for(int i=0; i<n; i++) cin >> h[i];

  vector<int> c(n+k+1, inf);
  c[0] = 0;
  for(int i=0; i<n; i++) {
    for(int j=1; j<=k; j++) {
      if(i+j < n) {
        c[i+j] = min(c[i+j], c[i] + abs(h[i]-h[i+j]));
      }
    }
  }

  cout << c[n-1] << endl;

  return 0;
}



//EOF


Measured memory_bytes: 1024
#include <iostream>
using namespace std;
int main(void){
    int H,W;
    while (true) {
        cin >> H >> W;
        if (H == 0 && W == 0){break;}
        for(int i = 0; i < H; i++){
            for(int j = 0; j < W; j++){
            cout << '#';
            }
        cout << endl;    
        }
        cout << endl;
    }
   
}


Measured memory_bytes: 3076
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
using namespace std;
#define int long long
#define pb push_back
#define pi pair <int, int> 

int n, k, a[200100];
unordered_set <int> s;
map <int, int> mp;
vector <pi> v;
int32_t main() {
	int ans = 0;
	cin >> n >> k;
	for(int i = 0; i < n; ++i) {
		cin >> a[i];
		s.insert(a[i]);
	}
	if (s.size() <= k) {
		cout << 0;
	}
	else {
		for(int i = 0; i < n; ++i) mp[a[i]]++;
		for(auto it: mp) {
			v.pb(it);
		}
		sort(v.begin(), v.end(), [](pi i, pi j) {
			return i.second < j.second;
		});
		for(int i = 0; i < s.size()-k; ++i) {
			ans += v[i].second;
		}
		cout << ans;
	}
}

Measured memory_bytes: 30444
from collections import defaultdict
import math


def kari():
    map(int, input().split())
    list(map(int, input().split()))
    math.ceil()

def main():
    num = int(input())
    data = [input() for i in range(num)]
    count = 0
    for i in range(num):
        count += data[i].count('AB')

    count_a, count_b, ryouhou = 0, 0, 0
    for i in range(num):
        if data[i][0] == 'B' and data[i][-1] == 'A':
            ryouhou += 1
        elif data[i][0] == 'B':
            count_b += 1
        elif data[i][-1] == 'A':
            count_a += 1

    # print(count, count_a, count_b, ryouhou)

    if count_a > 0 and count_b > 0:
        count_a -= 1
        count_b -= 1
        count += ryouhou + 1 + min(count_a, count_b)
    elif count_a > 0 or count_b > 0:
        count += ryouhou
    else:
        count += max(0, ryouhou - 1)


    # count += min(count_a, count_b)
    print(count)


if __name__ == '__main__':
    main()



Measured memory_bytes: 45784
#include <bits/stdc++.h>
using namespace std;
 
int a,b,c;
int f[100];
 
int main() 
{
	memset(f,0,sizeof(f));
    cin>>a>>b>>c;
    int j=a%b;
    while (1)
    {
        if (j==c)
        {
            printf("YES");
            return 0;
        }
        if (f[j])
        {
            printf("NO");
            return 0;
        }else f[j]=1;
        j=(j+a)%b;
    }
}

Measured memory_bytes: 384
#include <iostream>
#include <queue>
#define REP(i,n) for(int i=0; i<(int)(n); i++)

#include <set>
#include <cstdio>
inline int getInt(){ int s; scanf("%d", &s); return s; }

using namespace std;

int p[50][50];
int m[50][50];

int dp[50][50][50];
int cand[50][50][50];

int main(){
  const int n = getInt();
  const int d = getInt();

  REP(i,n) REP(j,d)
    p[i][j] = getInt();

  REP(i,d){
    int mn = 100000;
    REP(j,n) mn = min(mn, p[j][i]);
    REP(j,n) if(mn == p[j][i]) m[j][i] = 1;
  }

  const int MAX = 100000 * 100;
  REP(i,50) REP(j,50) REP(k,50) dp[i][j][k] = MAX;

  REP(i,n) if(m[i][0]) dp[0][0][i] = p[i][0];

  REP(i,d-1) REP(j,d) REP(k,n) if(dp[i][j][k] != MAX){
    REP(l,n) if(m[l][i + 1]){
      const int next = j + (k == l ? 0 : 1);
      dp[i + 1][next][l] = min(dp[i + 1][next][l], dp[i][j][k] + p[l][i + 1]);
    }
  }

  int ansl = MAX;
  int ans  = MAX;
  vector<int> ansp;

  REP(i,d) REP(j,n){
    if(dp[d - 1][i][j] < ans ||
       (dp[d - 1][i][j] == ans && i < ansl)){
      ans = dp[d - 1][i][j];
      ansl = i;
      ansp.clear(); ansp.push_back(j);
    }else if(dp[d - 1][i][j] == ans && i == ansl){
      ansp.push_back(j);
    }
  }

  REP(i,ansp.size())
    cand[d - 1][ansl][ansp[i]] = 1;

  for(int i = d - 2; i >= 0; i--){
    REP(j,d) REP(k,n) if(dp[i][j][k] != MAX){
      REP(l,n) if(m[l][i + 1]){
        const int next = j + (k == l ? 0 : 1);
        if(dp[i + 1][next][l] == dp[i][j][k] + p[l][i + 1] &&
           cand[i + 1][next][l]){
          cand[i][j][k] = 1;
        }
      }
    }
  }

  printf("%d %d\n", ans, ansl);

  int prev = 0;
  int cnt  = 0;
  REP(i,d){
    REP(j,n){
      if((i == 0 || prev == j) && cand[i][cnt][j]){
        printf("%d\n", j + 1);
        prev = j;
        break;
      }else if(cand[i][cnt + 1][j]){
        printf("%d\n", j + 1);
        prev = j;
        cnt = cnt + 1;
        break;
      }
    }
  }

  return 0;
}

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

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


Measured memory_bytes: 3988
#include <bits/stdc++.h>
#define ri register
#define int long long
#define E (n+1)
using namespace std; const int N=200010;
inline int read()
{
    int s=0, w=1; ri char ch=getchar();
    while(ch<'0'||ch>'9') { if(ch=='-') w=-1; ch=getchar(); }
    while(ch>='0'&&ch<='9') s=(s<<3)+(s<<1)+(ch^48), ch=getchar();
    return s*w;
}
int n,K,L;
struct Uni
{
    int f[N],siz[N];
    inline int Find(int x) { return f[x]^x?f[x]=Find(f[x]):x; }
    inline void Init()
    {
        for(ri int i=1;i<=n;i++) f[i]=i, siz[i]=1;
    }
    inline void Merge(int u,int v)
    {
        int fx=Find(u), fy=Find(v);
        if(fx==fy) return;
        f[fy]=fx, siz[fx]+=siz[fy];
    }
}A,B;
map<int,int> Q;
const int Hsh=1e6;
signed main()
{
    n=read(), K=read(), L=read();
    A.Init(), B.Init();
    for(ri int i=1;i<=K;i++)
    {
        int u,v;
        u=read(), v=read();
        A.Merge(u,v);
    }
    for(ri int i=1;i<=L;i++)
    {
        int u,v;
        u=read(), v=read();
        B.Merge(u,v);
    }
    for(ri int i=1;i<=n;i++) Q[Hsh*A.Find(i)+B.Find(i)]++;
    for(ri int i=1;i<=n;i++) printf("%lld ",Q[Hsh*A.Find(i)+B.Find(i)]);
    puts("");
    return 0;
}

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second

using vint=vector<int>;
using pint=pair<int,int>;
using vpint=vector<pint>;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

template<class A,class B>
ostream& operator<<(ostream& ost,const pair<A,B>&p){
    ost<<"{"<<p.first<<","<<p.second<<"}";
    return ost;
}

template<class T>
ostream& operator<<(ostream& ost,const vector<T>&v){
    ost<<"{";
    for(int i=0;i<v.size();i++){
        if(i)ost<<",";
        ost<<v[i];
    }
    ost<<"}";
    return ost;
}

signed main(){
    int N,A,B;
    scanf("%lld%lld%lld",&N,&A,&B);
    cout<<min(A*N,B)<<endl;
    return 0;
}

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

#include <cstdlib>  // abs() for integer 絶対値求めやつ

#include <cmath>    // abs() for float, and fabs()

#include <algorithm>
#include <vector>
#define rep(i,n) for(int i = 0; i< (n);i++)

#define sort(a) sort((a).begin(),(a).end());

#define che(a,string) cout<<string<<":"<<(a)<<endl;

#define ch(a,string) cout<<string<<":"<<(a)<<" ";

using namespace std;

typedef pair<int,int> p;

int main(){
	vector<string> A(3);
	rep(i,3){
		cin>>A[i];
	  }  
	  cout<<A[0][0]<<A[1][1]<<A[2][2]<<endl;
	  
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>

using namespace std;

typedef long long ll;

const ll MOD = 3006703054056749LL;

struct Modint {
  ll val;
  
  Modint (ll _val = 0)
    : val(_val % MOD) {}

  Modint operator+ (Modint other) const {
    return Modint(val + other.val);
  }

  void operator+= (Modint other) {
    val += other.val;
    val %= MOD;
  }

  Modint operator- () const {
    return Modint(MOD - val);
  }

  Modint operator- (Modint other) const {
    return Modint(val + MOD - other.val);
  }

  void operator-= (Modint other) {
    val += MOD - other.val;
    val %= MOD;
  }

  Modint operator* (Modint other) const {
    return Modint(val * other.val);
  }

  void operator*= (Modint other) {
    val *= other.val;
    val %= MOD;
  }

  bool operator== (Modint other) const {
    return val == other.val;
  }

  bool operator!= (Modint other) const {
    return val != other.val;
  }
};

ostream& operator<< (ostream& out, Modint p) {
  out << p.val;
  return out;
}

const int MAX_N = 2e5 + 5;
const Modint BASE (231);

ll ans;
string s [MAX_N];
vector<int> rewards [MAX_N];
map<ll, int> fst;

bool has (const set<pair<char, int>> &exist, char val) {
  auto lb = exist.lower_bound(make_pair(val, -1));
  if (lb == exist.end()) return false;
  return lb->first == val;
}

void proc (int idx) {
  int n = s[idx].size();
  set<pair<char, int>> exist;
  for (int i = 0; i < n; i++) {
    exist.insert(make_pair(s[idx][i], i));
  }

  Modint hsh (0);
  if (fst.count(hsh.val)) {
    int udx = fst[hsh.val];
    for (int c = 0; c < 26; c++) {
      if (has(exist, c + 'a')) {
        ans += rewards[udx][c];
      }
    }
  }

  for (int i = n - 1; i > 0; i--) {
    hsh *= BASE;
    hsh += Modint(s[idx][i]);
    exist.erase(make_pair(s[idx][i], i));

    if (fst.count(hsh.val)) {
      int udx = fst[hsh.val];
      for (int c = 0; c < 26; c++) {
        if (has(exist, c + 'a')) {
          ans += rewards[udx][c];
        }
      }
    }
  }

  if (!fst.count(hsh.val)) {
    fst[hsh.val] = idx;
    rewards[idx] = vector<int> (26, 0);
  }
  rewards[fst[hsh.val]][s[idx][0] - 'a']++;
}

int main () {
  ios::sync_with_stdio(false);

  int n;
  cin >> n;

  vector<pair<int, int>> lengths;
  for (int i = 0; i < n; i++) {
    cin >> s[i];
    lengths.push_back(make_pair((int) s[i].size(), i));
  }

  sort(lengths.begin(), lengths.end());

  for (auto pr : lengths) {
    proc(pr.second);
  }

  cout << ans << endl;
}


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

int main() {
  char a, b;
  cin >> a >> b;
  if (a == 'H' && b == 'H') {
    cout << "H" << endl;
  }
  else if (a == 'H' && b == 'D') {
    cout << "D" << endl;
  }
  else if (a == 'D' && b == 'H') {
    cout << 'D' << endl;
  }
  else {
    cout << 'H' << endl;
  }
}


Measured memory_bytes: 256
Module Module1

    Sub Main()
        'let
        Dim S = Console.ReadLine()
        Dim K As Long = Console.ReadLine()
        Dim tmp = S.Replace("1", "")

        'var
        Dim i As Long = 0

        Do While i < Len(S)
            If S(i) <> "1" Then Exit Do
            i = i + 1
        Loop

        If K - 1 < i Then
            Console.WriteLine(1)
        Else
            Console.WriteLine(tmp(0))
        End If

    End Sub

End Module

Measured memory_bytes: 22736
#include <bits/stdc++.h>
using namespace std;
#define anuj ios_base::sync_with_stdio(false);cin.tie(NULL)
#define fo(i,n) for(int i=0;i<n;i++)
#define Fo(i,k,n) for(int i=k;i<n;i++)
#define ll long long int
#define si(x)	scanf("%d",&x)
#define sl(x)	scanf("%I64d",&x)
#define ss(s)	scanf("%s",s)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define clr(x) memset(x, 0, sizeof(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define endl '\n'
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pll;
typedef vector<int>		vi;
typedef vector<ll>		vl;
typedef vector<pii>		vpii;
typedef vector<pll>		vpll;
typedef vector<vi>		vvi;
typedef vector<vl>		vvl;
const int mod = 1000000007;
const int N = 2e5;
const int LG = 20;
int a[N];

int main(){
	anuj;

	string s,t;
	cin >> s >> t;

	int m=s.length(),n=t.length();

	int dp[m+1][n+1];
	fo(i,m+1) dp[i][0]=0;
	fo(i,n+1) dp[0][i]=0;

	Fo(i,1,m+1)
		Fo(j,1,n+1){
			if(s[i-1]==t[j-1])
				dp[i][j]=1+dp[i-1][j-1];
			else
				dp[i][j]=max(dp[i][j-1],dp[i-1][j]);
		}


	string req="";
	int i=m,j=n;

	while(i>0 && j>0){
		if(s[i-1]==t[j-1]){
			req.push_back(s[i-1]);
			i--;
			j--;
		}
		else if(dp[i-1][j]>dp[i][j-1])
			i--;
		else
			j--;

	}	

	reverse(req.begin(),req.end());
	cout << req;

}


Measured memory_bytes: 35456
#include<iostream>
const char vow[]={'a','e','i','o','u'};
int main()
{
    char tin;
    std::cin>>tin;
    for(int i=0;i<5;i++){
        if(tin==vow[i]) {
            std::cout<<"vowel";
            return 0;
        }
    }
    std::cout<<"consonant";
    return 0;
}

Measured memory_bytes: 256
N, K = map(int, input().split())
a_list = list(map(int, input().split()))

ans = 0
mod = 10 ** 9 + 7

for i in range(N):
    for j in range(i + 1, N):
        if a_list[i] > a_list[j]:
            ans += K
            ans %= mod

for i in range(N):
    cnt = 0
    for j in range(N):
        if a_list[i] > a_list[j]:
            cnt += 1
    ans += cnt * K * (K - 1) // 2
    ans %= mod
print(ans)


Measured memory_bytes: 3188
using System;

namespace ABC122
{
    class C
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');

            int N = int.Parse(input[0]);
            int Q = int.Parse(input[1]);

            string S = Console.ReadLine();

            int[] a = new int[S.Length];
            int[] s = new int[S.Length + 1];
            int count = 0;
            a[0] = 0;
            s[0] = 0;

            for (int i = 1; i < S.Length; i++)
            {
                if (S[i - 1] == 'A' && S[i] == 'C') { count++; }
                a[i] = count;
                s[i] += a[i - 1];
            }
            s[S.Length] += a[S.Length - 1];

            int l = 0;
            int r = 0;
            int[] res = new int[Q];
            for (int i = 0; i < Q; i++)
            {
                input = Console.ReadLine().Split(' ');
                l = int.Parse(input[0]);
                r = int.Parse(input[1]);

                res[i] = s[r] - s[l];
            }

            foreach (var item in res) { Console.WriteLine(item); }
        }
    }
}


Measured memory_bytes: 17792
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1LL << 60;
ll MOD = 1e9 + 7;

int N, M;
struct parent {
    int p;
    int cnt;
};
vector<parent> par;

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

void unite(int x, int y) {
    x = root(x);
    y = root(y);
    if (x != y) {
        par[y].cnt += par[x].cnt;
        par[x].p = y;
    }
}

int main() {
    int a, b;
    cin >> N >> M;
    par.resize(N);
    for (int i = 0; i < N; i++) {
        par[i].p = i;
        par[i].cnt = 1;
    }
    for (int i = 0; i < M; i++) {
        cin >> a >> b;
        a--, b--;
        unite(a, b);
    }
    int cnt_max = 0;
    for (int i = 0; i < N; i++) {
        cnt_max = max(cnt_max, par[i].cnt);
    }
    cout << cnt_max << endl;
    return 0;
}

Measured memory_bytes: 4780
#include<stdio.h>
    #include<string.h>
    char a[5],b[5];
    int main()
    {	int i,j;
    	int flag = 0;
    	
    	while(~scanf("%s%s",a,b))
    	{
    		
    			if(a[0]==b[2]&&a[1]==b[1]&&a[2]==b[0])
    			{
    				printf("YES\n");
    			}
    			else
    			{
    				printf("NO\n");
    			}
    	}
    	return 0;
    }

Measured memory_bytes: 128
package main

import (
	"fmt"
	"log"
)

func main() {
	var n int
	if _, err := fmt.Scan(&n); err != nil {
		log.Fatal(err)
	}

	var args []int
	for i := 0; i < n; i++ {
		var x int
		if _, err := fmt.Scan(&x); err != nil {
			log.Fatal(err)
		}
		args = append(args, x)
	}

	var execCnt int
	MainLoop:
	for {
		for _, val := range args {
			if val % 2 == 1 {
				break MainLoop
			}
		}

		for i := 0; i < n; i++ {
			args[i] = args[i] / 2
		}
		execCnt++
	}

	fmt.Println(execCnt)
}


Measured memory_bytes: 512
#include <stdio.h>

int main() {
    
    char s[17];
    char c[17] = "CODEFESTIVAL2016";
    int i,count;
    
    scanf("%s\n", s);
    
    count = 0;
    
    for (i = 0; i < 16; i++) {
        if (s[i] != c[i]) {
            count++;
        }
    }
    
    printf("%d\n", count);
    
    return 0;
    
}

Measured memory_bytes: 128