akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return 1;
    }
    return 0;
}
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define LLINF (1e18)
#define PI (acos(-1))
#define MOD (1000000007)
#define ALL(v) (v).begin(), (v).end()
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, 0};

//-------------------------------------

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin.ignore();
    while (true)
    {
        string s;
        getline(cin, s);
        if (s == ".")
        {
            break;
        }
        int n = s.size();
        stack<char> st;
        bool flg = true;

        for (int i = 0; i < n; i++)
        {
            if (s[i] == '(' || s[i] == '[')
            {
                st.push(s[i]);
            }
            if (s[i] == ')')
            {
                if (st.empty())
                {
                    flg = false;
                    break;
                }
                char tmp = st.top();
                st.pop();
                if (tmp != '(')
                {
                    flg = false;
                    break;
                }
            }
            if (s[i] == ']')
            {
                if (st.empty())
                {
                    flg = false;
                    break;
                }
                char tmp = st.top();
                st.pop();
                if (tmp != '[')
                {
                    flg = false;
                    break;
                }
            }
        }

        if (!st.empty())
        {
            flg = false;
        }

        if (flg)
        {
            cout << "yes" << endl;
        }
        else
        {
            cout << "no" << endl;
        }
    }
}


Measured memory_bytes: 3228
import java.io.BufferedReader
import java.io.InputStreamReader
import java.io.PrintWriter
import java.util.*
import kotlin.math.abs

val br = BufferedReader(InputStreamReader(System.`in`))
val out = PrintWriter(System.out)

fun main() {
    br.use { out.use {
        solve()
        out.flush()
    } }
}

fun solve() {
    val a = br.readLine()!![0]
    val ans = if (a.isLowerCase()) 'a' else 'A'
    out.println(ans)
}

fun readInteger() = Integer.parseInt(br.readLine())
fun readLong() = java.lang.Long.parseLong(br.readLine())
fun readStringList() = br.readLine()!!.split(' ')
fun readIntegerList() = readStringList().map(Integer::parseInt)
fun readLongList() = readStringList().map(java.lang.Long::parseLong)
fun readDoubleList() = readStringList().map(java.lang.Double::parseDouble)


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

int main(){
  int h,w;
  cin >> h >> w;
  vector<vector<int>> c(10,vector<int>(10,0));
  rep(i,10)rep(j,10)cin >> c[i][j];
  vector<vector<int>> a(h,vector<int>(w));
  rep(i,h)rep(j,w)cin >> a[i][j];
  for (int k = 0; k < 10; k++){       // 経由する頂点
    for (int i = 0; i < 10; i++) {    // 始点
      for (int j = 0; j < 10; j++) {  // 終点
        c[i][j] = min(c[i][j], c[i][k] + c[k][j]);
      }
    }
  }
  ll ans = 0;
  rep(i,h)rep(j,w){
    if(a[i][j]!=-1)ans += c[a[i][j]][1];
  }
  cout << ans << endl;
}


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

typedef long long ll;
typedef long double ld;
typedef vector<vector<int>> Graph;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
#define pi 3.14159265359
#define inf 2147483647
#define INF 9223372036854775807
#define mod 1000000007
#define mod2 998244353

int main() {
    int N; cin >> N;
    for(int i = N; i > 0; i--) {
        int n = sqrt(i);
        if(n == sqrt(i)) {
            cout << i << endl;
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 3624
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define For(i,a,b) for(int i=a;i<=b;i++)
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define sz(x) ((int)x.size())
#define MOD (ll)(INF)
#define INF 1e17
#define int ll
#define EPS (1e-6)
using namespace std;
using ll=long long;
using pii=pair<int,int>;

int gcd(int a,int b) { return b==0?a:gcd(b,a%b); }
int lcm(int a,int b) { return a/gcd(a,b)*b; }

int fpow(int b,int p)
{
	if(p==0) return 1;
	int h=fpow(b,p/2);
	if(p%2) return h*b%MOD*h%MOD;
	return h*h%MOD;
}

int32_t main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int n; cin>>n;
	cout<<fixed<<setprecision(10);
	double tmp,tot=0;
	For(i,1,n){
		cin>>tmp;
		tot+=1/tmp;
	}
	cout<<1/tot<<"\n";
	return 0;
}




























Measured memory_bytes: 256
import numpy as np

S = input()
ans = int(S[0])
ope = []

while True:
    for i in S[1:]:
        if np.random.randint(2) == 0:
            ans += int(i)
            ope.append("+")
        else:
            ans -= int(i)
            ope.append("-")

    if ans == 7:
        print(S[0]+ope[0]+S[1]+ope[1]+S[2]+ope[2]+S[3]+"=7")
        exit()
    else:
        ans = int(S[0])
        ope = []

Measured memory_bytes: 26520
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long int Q, H, S, D, N;
  cin >> Q >> H >> S >> D >> N;
  H = min(H, 2*Q);
  S = min(S, 2*H);
  D = min(D, 2*S);
  long long int total = (N/2)*D + ((N%2==1) ? S : 0);
  cout << total << "\n";
  return 0;
}

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

typedef pair<int,int> P;

int main(){
  int n, m;

  while(cin >> n >> m, n || m){
    vector<P> v;

    for(int i = 0; i < n; i++){
      int d, p;
      cin >> d >> p;
      v.push_back(P(p, d));
    }
    sort(v.begin(), v.end());

    int ans = 0;

    for(int i = v.size() - 1; i >= 0; i--){
      if(m <= 0){
        ans += v[i].first * v[i].second;
      }
      else if(m >= v[i].second){
        m -= v[i].second;
      }
      else{
        ans += v[i].first * (v[i].second - m);
        m = 0;
      }
    }

    cout << ans << endl;
  }
}

Measured memory_bytes: 1328
local mfl = math.floor
local mce, msq = math.ceil, math.sqrt
local function getprimes(x)
  local primes = {}
  local allnums = {}
  for i = 1, x do allnums[i] = true end
  for i = 2, x do
    if allnums[i] then
      table.insert(primes, i)
      local lim = x // i
      for j = 2, lim do
        allnums[j * i] = false
      end
    end
  end
  return primes
end

local function getdivisorparts(x, primes)
  local prime_num = #primes
  local tmp = {}
  local lim = mce(msq(x))
  local primepos = 1
  local dv = primes[primepos]
  while primepos <= prime_num and dv <= lim do
    if x % dv == 0 then
      local asdf = {}
      asdf.p = dv
      asdf.cnt = 1
      x = x // dv
      while x % dv == 0 do
        x = x // dv
        asdf.cnt = asdf.cnt + 1
      end
      table.insert(tmp, asdf)
      lim = mce(msq(x))
    end
    if primepos == prime_num then break end
    primepos = primepos + 1
    dv = primes[primepos]
  end
  if x ~= 1 then
    local asdf = {}
    asdf.p, asdf.cnt = x, 1
    table.insert(tmp, asdf)
  end
  return tmp
end

local function getdivisor(divisorparts)
  local t = {}
  local pat = 1
  local len = #divisorparts
  local allpat = 1
  for i = 1, len do
    allpat = allpat * (1 + divisorparts[i].cnt)
  end
  for t_i_pat = 0, allpat - 1 do
    local div = allpat
    local i_pat = t_i_pat
    local ret = 1
    for i = 1, len do
      div = div // (divisorparts[i].cnt + 1)
      local mul = i_pat // div
      i_pat = i_pat % div
      for j = 1, mul do
        ret = ret * divisorparts[i].p
      end
    end
    table.insert(t, ret)
  end
  table.sort(t)
  return t
end


local n, s = io.read("*n", "*n")
local lim = 316228

local function solve(x)
  local tn = n
  local c = 0
  while 0 < tn do
    c = c + tn % x
    tn = tn // x
  end
  return c == s
end

local found = false
for x = 2, lim - 1 do
  if solve(x) then
    found = true
    print(x)
    break
  end
end
if not found then
  if n == s then
    print(n + 1)
    found = true
  elseif s < n then
    local mul = n - s
    local primes = getprimes(lim)
    local divp = getdivisorparts(mul, primes)
    local divs = getdivisor(divp)
    for i = 1, #divs do
      local cand = divs[i]
      local a1 = mul // cand
      if a1 <= cand then
        local a0 = s - a1
        if 0 <= a0 and a0 <= cand then
          found = true
          print(cand + 1)
          break
        end
      end
    end
  end
  if not found then
    print(-1)
  end
end


Measured memory_bytes: 9080
n = int(input())

a = list(map(int, input().split()))
b = []
c = []

for i in range(n):
	b.append(-(i + 1 + a[i]))
	c.append(a[i] - i - 1)

#print(a)
#print(b)
#print(c)

counts = {}

result = 0

counts[b[0]] = 1

for i in range(1, n):
	x = c[i]

#	print(x)
	#print(counts)

	if x in counts: 
		result += counts[x]

	y = b[i]
	if y in counts:
		counts[y] += 1
	else: 
		counts[y] = 1


	


print(result)


Measured memory_bytes: 138212
from itertools import accumulate
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

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

l = [0]*101
l[A] += 1
l[B] -= 1
l[C] += 1
l[D] -= 1
l = list(accumulate(l))
print(l.count(2))


Measured memory_bytes: 3188
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>

int main(){
    int x, y;
    std::cin >> x >> y;

    std::cout << (x + y / 2) << std::endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int n;
	scanf("%d", &n);
	long long int a[100005], b[100005];
	int i;
	for (i = 0; i <= n; i++)
		scanf("%lld", &a[i]);
	for (i = 0; i < n; i++)
		scanf("%lld", &b[i]);
	long long int ans = 0;
	for (i = 0; i < n; i++)
	{
		if (a[i] <= b[i])
		{
			ans += a[i];
			b[i] -= a[i];
			if (a[i + 1] <= b[i])
			{
				ans += a[i + 1];
				a[i + 1] = 0;
			}
			else
			{
				ans += b[i];
				a[i + 1] -= b[i];
			}
		}
		else
			ans += b[i];
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 1664
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>
#include <cmath>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
//ll mod = 998244353;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main() {
    int n;
    cin >> n;
    vector<ll> x(n);
    rep(i, n) cin >> x[i];
    vector<ll> tmp = x;
    sort(tmp.begin(), tmp.end());
    ll med_l = tmp[n/2-1];
    ll med_h = tmp[n/2];
    rep(i, n) {
        if (x[i] <= med_l) {
            cout << med_h << endl;
        }
        else {
            cout << med_l << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 6380
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(),v.end()
#define INF INT_MAX;
typedef long long ll;
using namespace std;

int main(){
  int n; cin >> n;
  vector<string> word(0);
  string w1; cin >> w1;
  word.push_back(w1);
  bool ok=true;
  rep(i,n-1){
    string w2; cin >> w2;
    if(w1.back()!=w2.at(0)) ok=false;
    for(auto c:word){
      if(c==w2) ok = false;
    }

    if(ok) word.push_back(w2);
    w1 = w2;
  }
  if(ok) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> l_l;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
#define pb push_back
#define sz(x) (int)(x).size()
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
const int INF=1001001000;
const int mINF=-1001001000;
const ll LINF=1010010010010010000;
template<class T> inline bool chmin(T& a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template<class T> inline bool chmax(T& a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
//グリッド：（典型）dp,dfs,bfs,最短経路,その他
int main(){
    string s;cin>>s;
    bool f1=(s[0]==s[sz(s)-1]);
    bool f2=(sz(s)%2==1);
    if(f1^f2){
        cout<<"First"<<endl;
    }
    else cout<<"Second"<<endl;
    return 0;
}

Measured memory_bytes: 512
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    sys.setrecursionlimit(10**7)
    INF = 10**5 + 1
    MOD = 10**9 + 7
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]
    NI = lambda : int(sys.stdin.readline())
    SI = lambda : sys.stdin.readline().rstrip()

    N,M = LI()
    S = SI()
    N0 = 2 ** N.bit_length()
    st = [INF] * (2*N0)

    def update(i,x):
        i += N0-1
        st[i] = x
        while i > 0:
            i = (i-1) // 2
            st[i] = min(st[i*2+1], st[i*2+2])

    def query(l,r):
        L = l+N0; R = r+N0
        ret = INF
        while L < R:
            if L % 2:
                ret = min(ret,st[L-1])
                L += 1
            if R % 2:
                R -= 1
                ret = min(ret,st[R-1])
            L //= 2; R //= 2
        return ret

    update(0,0)

    for i in range(1,N+1):
        if S[i] == '1': continue
        else:
            if i <= M:
                update(i,1)
            else:
                x = query(i-M,i)
                update(i,x+1)
    if st[N+N0-1] >= INF:
        print(-1)
    else:
        ans = []
        f = N
        last_i = N
        s = st[N+N0-1]
        d = 1
        cnt = 0
        for i in range(N-1,-1,-1):
            cnt += 1
            if st[i+N0-1] == s-1:
                d = f - i
                last_i = i
            if cnt == M:
                ans.append(d)
                f = last_i
                s -= 1
                cnt = f - i
        if f > 0:
            ans.append(f)
        print(*reversed(ans),sep=' ')

if __name__ == '__main__':
    main()

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

const int mod = int(1e9) + 7;

int main() {
  int n;
  cin >> n;
  vector<int> c(1);
  cin >> c[0];
  for (int i = 1; i < n; i++) {
    int tmp;
    cin >> tmp;
    if (tmp != c[c.size() - 1]) c.push_back(tmp);
  }
  n = c.size();
  vector<long> cn(200010, 0);
  vector<long> dp(n, 0);
  dp[0] = 1;
  cn[c[0]] = dp[0];
  for (int i = 1; i < n; i++) {
    cn[c[i]] = dp[i] = (dp[i - 1] + cn[c[i]]) % mod;
  }
  cout << dp[n - 1];
  return 0;
}

Measured memory_bytes: 4340
function main(input) {
  const args = input.split(' ').map(n => parseInt(n, 10));
  const A = args[0],
        B = args[1],
        K = args[2];
  let cnt = 0;
  
  for (let i = 100; i >= 1; i--) {
    if (A % i === 0 && B % i === 0) {
      cnt++;
      if (cnt === K) {
        console.log(i);
        break;
      }
    }
  }
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 29584
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

int N, M;
bool E[601][601];
int kazu[601];
double kei[601], saidai[601];
double memo[601];
double dfs(int v) {
	if (memo[v] != -1) return memo[v];
	double ret = 0;
	for (int i = v + 1; i <= N; i++) if (E[v][i]) {
		double tmp = dfs(i);
		chmax(saidai[v], tmp);
		ret += tmp;
	}
	kei[v] = ret;
	return memo[v] = 1 + ret / kazu[v];
}

double K[601];
double omomi(int v) {
	if (K[v] != -1) return K[v];
	double ret = 0;
	rep1(i, v - 1) if (E[i][v]) {
		ret += omomi(i) / kazu[i];
	}
	return K[v] = ret;
}

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


	N = getint(), M = getint();
	rep1(i, M) {
		int s = getint();
		kazu[s]++;
		E[s][getint()] = 1;
	}

	rep1(i, N) memo[i] = -1;
	memo[N] = 0;

	double kotae = dfs(1);

	rep1(i, N) K[i] = -1;
	K[1] = 1;

	double saishou = 0;
	rep1(i, N) {
		if (kazu[i] > 1) {
			double are = (kei[i] - saidai[i]) / (kazu[i] - 1) - kei[i] / kazu[i];
			are *= omomi(i);
			chmin(saishou, are);
		}
	}

	printf("%.12f", kotae + saishou);

	Would you please return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    int h=0;
    cin >> n;
    for(int i=0;7*i<=n;i++){
        for(int j=0;(7*i+4*j)<=n;j++){
            if(7*i+4*j==n){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
vector<ll>a, b;
int main()
{
    ll n, m, k, x;
    scanf("%lld %lld %lld", &n, &m, &k);
    ll sum= 0;
    a.push_back(0);
    for(int i=0; i<n; i++)
    scanf("%lld", &x), a.push_back(x+sum), sum+= x;
    sum= 0;
    for(int i=0; i<m; i++)
    scanf("%lld", &x), b.push_back(x+sum), sum+= x;
    ll res= 0;
    for(int i=0; i<a.size() && a[i]<=k; i++)
    {
        ll p= i;
        x= k-a[i];
        p+= upper_bound(b.begin(), b.end(), x)-b.begin();
        res= max(res, p);
    }
    printf("%lld\n", res);
    return 0;
}


Measured memory_bytes: 7896
#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <ctime>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <memory.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <unordered_map>
#include <unordered_set>
using namespace std;
typedef long double LD;
typedef long long LL;
typedef pair<LL, LL> pll;
typedef pair<int, int> pii;
typedef vector<int> vi;
#ifdef LOCAL
#define DEBUG(x) { cerr << "# " << #x << ": " << x << endl;}
#else
#define DEBUG(x)
#endif
mt19937_64 mt(time(0));
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/






int main() {
  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  cout.precision(10); cout << fixed;
#ifdef LOCAL
  freopen("../test.txt", "r", stdin);
    // freopen("../output.txt", "w", stdout);
#endif
  LL n, d; cin >> n >> d;
  d = d * d;
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    LL a, b; cin >> a >> b;
    if (a*a+b*b <= d) cnt++;
  }
  cout << cnt << endl;






/*---------------------------------------Coding Space End------------------------------------------*/
#ifdef LOCAL
  cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s." << endl;
#endif
  return 0;
}
/* author:  txingml */
/* picture is from hamayanhamayan(CF handle) */


Measured memory_bytes: 3192
n,k = gets.split.map(&:to_i)
ans = 0.0
 
(1..n).each do |i|
  div = 1.0/n
  dob = i
  while dob < k do
    dob *= 2
    div *= 1.0/2
  end
  ans += div
end
 
puts ans

Measured memory_bytes: 1788
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String today = sc.next();
        if (today.equals("Sunny")) {
            System.out.println("Cloudy");
        } else if (today.equals("Cloudy")) {
            System.out.println("Rainy");
        } else {
            System.out.println("Sunny");
        }
    }
}

Measured memory_bytes: 21844
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
#include<stdio.h>
#include<string.h>
#include <bitset>

using namespace std;
#define int long long

#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(), (x).end()

template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return; std::cout << e <<" ";}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){std::cout<< e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class... Ts> void DEBUG(T d, Ts... e){if(DEBUG_OUT == false)return;DEBUG(d);DEBUG(e...);}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; abort();}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
//SOLVE

int take[1 << 20], at[1 << 20], dm[1 << 20];
void solve(void)
{
  int N, M;
  cin >> N >> M;
  vector<vector<int>> GRAPH(N + 1);
  vector<int> in(N + 1, 0);
  vector<int> pi(N + 1, 0);
  for (int i = 0; i < N - 1 + M; i++)
  {
    int A, B;
    cin >> A >> B;
    GRAPH[A].push_back(B);
    in[B]++;
  }
  queue<int> q;
  for (int i = 1; i <= N; i++)
  {
    if (in[i] == 0)
      q.push(i);
  }
  while (!q.empty())
  {
    int u = q.front();
    q.pop();
    for (auto &&i : GRAPH[u])
    {
      if (--in[i] == 0)
      {
        pi[i] = u;
      q.push(i);
      }

    }
  }
  for (int i = 1; i <= N; i++)
  {
    cout << pi[i] << endl;
  }
  {
    /* code */
  }

  return;
}
int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(9);
  solve();

  return 0;
}


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

int main(){
  long long D = 0, S = -1, S_cnt = 0;

  int M;
  cin >> M;
  for(int i = 0; i < M; i++){
    long long d, c;
    cin >> d >> c;
    D += c;
    S += d * c;
    S_cnt += S / 9;
    S %= 9;
  }

  cout << D - 1 + S_cnt << endl;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    String[] str = in.readLine().split(" ");
    int a = Integer.parseInt(str[0]);
    int b = Integer.parseInt(str[1]);
    int h = Integer.parseInt(str[2]);
    int m = Integer.parseInt(str[3]);
    double hour = (h*30)+(m*0.5);
    double min = m*6;
    double anglediff = Math.abs(hour-min);
    double ans = 0;
    
    double sqrt = Math.pow(a,2)+Math.pow(b,2)-2*a*b*Math.cos(Math.toRadians(anglediff));
    System.out.println(Math.sqrt(sqrt));
  }
}

Measured memory_bytes: 33036
#include <string>
#include <algorithm>
#include <vector> 
#include <math.h>
#include <iostream>
#include <cmath>
#include <random>
using namespace std;
long long mod = 1000000000 + 7;


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

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

}

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

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll llINF = 1LL << 60;
const int iINF = 1e8;

//---main---------------------------------------------
int main(){
    //main
    ll X,K,D;
    cin >> X >> K >> D;
    X = abs(X);
    ll ans;
    if(K<X/D){
        ans = X - K*D;
    }else{
        ll a,b;
        a = X/D;
        b = X%D;
        if((K-a)%2==0) ans = b;
        else ans = D-b;
    }
    
    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 3528
#include <stdio.h>

int main(void) {
	int s,n,r,i,t,y;
	while(scanf("%d",&t) , t != 0){
		y = 0;
		for(i = 1;i <= t;i++){
			scanf("%d",&r);
			if(i == 1){
				s = r;
				n = r;
			}
			else{
				if(r == n + 1){
					n = r;
				}
				else{
					if(s != n){
						if(y){
							printf(" ");
						}
						printf("%d-%d",s,n);
						s = r;
						n = r;
						y++;
					}
					else{
						if(y){
							printf(" ");
						}
						printf("%d",s);
						s = r;
						n = r;
						y++;
					}
				}
			}
		}
		if(s != n){
			if(y){
				printf(" ");
			}
			printf("%d-%d",s,n);
			s = r;
			n = r;
		}
		else{
			if(y){
				printf(" ");
			}
			printf("%d",s);
			s = r;
			n = r;
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 600
N = gets.to_i
INF = N + 1
# dp = Array.new(N+1,INF)
# dp[0] = 0
dp = (0..N).to_a
n = N
a = 1
b = 1
ans = 0
# stack = [1]
stack = []
# binding.pry
while n / (a * 9) >= 1
  stack << a *= 9
end
# p a
while n / (b * 6) >= 1
  stack << b *= 6
end
stack.sort_by!{|x|x}
# p stack
stack.size.times do |i|
  stack[i].upto(N) do |j|
    dp[j] = [dp[j], dp[j - stack[i]] + 1].min
  end
end
puts dp[N]

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

// 総数を1000000007で割った余り
const long long mod = 1e9 + 7;

using ll  = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

void printVec(vector<int>& vec) {
    for (auto& e : vec) {
        cout << e << " ";
    }
    cout << endl;
}

int func(long long n, std::string s) {
    // cout << fixed << setprecision(8);

    char color = s[0];
    ll   cnt   = 1;
    for (int i = 1; i < n; i++) {
        if (color == s[i]) continue;
        cnt++;
        color = s[i];
    }
    cout << cnt << endl;

    return 0;
}

int main() {
    long long N;
    scanf("%lld", &N);
    std::string S;
    std::cin >> S;

    func(N, S);

    return 0;
}


Measured memory_bytes: 512
from collections import deque
import copy
import sys

from math import *

def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline


def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N] =  [long(input_raw[0])]
    input_raw = read_func().strip().split()
    cards = {}
    for i in range(N):
        c = int(input_raw[i])
        if c not in cards:
            cards[c] = 1
        else:
            cards[c] += 1

    even_num = 0
    for c in cards:
        if cards[c] % 2 == 0:
            even_num += 1
    if even_num % 2 == 0:
        print len(cards)
    else:
        print len(cards) - 1



if __name__ == '__main__':
    main()


Measured memory_bytes: 22892
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,X,T;
 
  cin >> N;
  cin >> X;
  cin >> T;
  if(N%X==0){
    cout << N/X *T << endl;
  }
  else{
  cout << (N/X +1)*T << endl;
  }
}
  

Measured memory_bytes: 3616
def solve():
    import sys
    s = list(map(int, sys.stdin.read().split()))
    x, y, z = s[0] + s[4] + s[8], s[1] + s[5] + s[6], s[2] + s[3] + s[7]
    if x == y == z:
        print("Yes")
    else:
        print("No")


solve()


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

using namespace std;
using ll = long long;

int main() {
	int N;
	cin >> N;
	vector<ll> x(N);
	vector<ll> y(N);
	for (int i = 0; i < N; ++i) {
		cin >> x[i] >> y[i];
	}

	ll res = N;
	for (int i = 0; i < N; ++i) {
		for (int j = 0; j < N; ++j) {
			if (i == j) { continue; }
			ll p = x[j] - x[i];
			ll q = y[j] - y[i];
			if (p == 0 && q == 0) { continue; }

			ll cnt = 0;
			for (int k = 0; k < N; ++k) {
				bool find = false;
				for (int l = 0; l < N; ++l) {
					if (l == k) { continue; }
					if ((x[k] + p == x[l]) && (y[k] + q == y[l])) {
						find = true;
						break;
					}
				}
				if (find) { ++cnt; }
			}
			res = min(res, N - cnt);
		}
	}
	cout << res << endl;

	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
int main() {
	int a[4][13] = { { 0 },{ 0 } }, n, b[53], x;
	vector<string>s;
	string tr;
	cin >> x;
	for (int i = 0; i < x; i++) {
		cin >> tr >> n;
		if (tr == "S")a[0][n-1] = 1;
		if (tr == "H")a[1][n-1] = 1;
		if (tr == "C")a[2][n-1] = 1;
		if (tr == "D")a[3][n-1] = 1;
	}
	for (int j = 0; j < 4; j++) {
		for (int i = 0; i < 13; i++) {
			if (a[j][i] != 1) {
				if (j == 0)cout << "S " << i+1 << endl;
				if (j == 1)cout << "H " << i+1 << endl;
				if (j == 2)cout << "C " << i+1 << endl;
				if (j == 3)cout << "D " << i+1 << endl;
			}
		}
	}
}


Measured memory_bytes: 3148
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int inf = INT_MAX;
const ll INF = LLONG_MAX;
const ll MOD = 1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b, const ll mod=MOD) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b, const ll mod=MOD) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b, const ll mod=MOD) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b, const ll mod=MOD) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int a, b, c; cin >> a >> b >> c;
    cout << (a + b >= c ? "Yes":"No") << endl;

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
main(){
  int i,n,x;
  scanf("%d",&n);
  for(i=3;i<=n;i++){
    x=i;
    if(x%3==0) printf(" %d",i);
    else if(x%10==3) printf(" %d",i);
    else {
      while(x>10){
        x/=10;
        if(x%10==3){
          printf(" %d",i);
          break;
        }
      }
      continue;
    }
  }
  printf("\n");
  return 0;
}

Measured memory_bytes: 600
K = int(input())
num = list(range(1, 10))
for i in range(K):
  a = num[i]
  b = 10 * a + a % 10
  if a % 10 != 0:
    num.append(b - 1)
  num.append(b)
  if a % 10 != 9:
    num.append(b + 1)
print(num[K - 1])

Measured memory_bytes: 15768
#include<bits/stdc++.h>
#define maxn 200050

using namespace std;
int n,a[maxn],r,s;

int main()
{
    for (int i=1;i<=30000;i++) if (i%2==0||i%3==0||i%5==0) a[++r]=i;
    scanf("%d",&n);
    for (int i=1;i<=n;i++) s=(s+a[i])%30;
    for (int i=n;i>=1;i--)
    {
        for (int j=n+1;j<=n+22;j++) if ((s-a[i]+30+a[j])%30==0){
            for (int k=1;k<=n;k++) if (k!=i) printf("%d ",a[k]);
            printf("%d\n",a[j]);
            return 0;
        }
    }
}


Measured memory_bytes: 384
f=lambda:[*map(int,input().split())]
n,k=f()
p,c=f(),f()
p=[i-1 for i in p]
a=-10**9
for i in range(n):
  x,l,s,t=i,[],0,0
  while 1:
    x=p[x]
    l+=[c[x]]
    s+=c[x]
    if x==i: break
  m=len(l)
  for j in range(m):
    if j+1>k: break
    t+=l[j]
    a=max(a,t+(k-j-1)//m*s*(s>0))
print(a)

Measured memory_bytes: 83064
#include<bits/stdc++.h>
#define N 100
#define INFTY (1<<21)
#define WH 0
#define GR 1
#define BL 2
using namespace std;

vector<int> color(N),d(N),p(N);
vector<vector<int>> M(N,vector<int>(N));
int n;

int prim(){
	int u,mincost;
	for(int i=0;i<n;i++){
		color.at(i) = WH;
		d.at(i) = INFTY;
		p.at(i) = -1;
	}
	d.at(0) = 0;
	
	while(1){
		mincost = INFTY;
		u = -1;
		for(int i=0;i<n;i++){
			if(color.at(i) != BL && d.at(i) < mincost){
				mincost = d.at(i);
				u = i;
			}
		}
		if(u == -1) break;
		
		color.at(u) = BL;
		
		for(int v=0;v<n;v++){
			if(color.at(v) != BL && M.at(u).at(v) != INFTY){
				if(M.at(u).at(v) < d.at(v)){
					d.at(v) = M.at(u).at(v);
					p.at(v) = u;
					color.at(v) = GR;
				}
			}
		}
	}
	int sum=0;
	for(int i=0;i<n;i++){
		if(p.at(i) != -1) sum += M.at(i).at(p.at(i));
	}
	return sum;
}

int main(){
	cin >> n;
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			int e;
			cin >> e;
			if(e == -1) M.at(i).at(j) = INFTY;
			else M.at(i).at(j) = e;
		}
	}
	cout << prim() << endl;
}


Measured memory_bytes: 3204
program main
  implicit none
  integer(8) i, A, B, C, D, CD, ans, x1, x2, x3, y1, y2, y3

  read(*, *)A, B, C, D
  x1 = C
  x2 = D
  
  do
    if (x1 < x2) then
      x2 = x2-x1
    elseif (x1 > x2) then
      x1 = x1-x2
    else
      CD = x1
      exit
    end if
  end do
  CD = (C*D)/CD
    
  if (mod(A,C) == 0) then
    x1 = A/C
  else 
    x1 = A/C + 1
  end if
  if (mod(A,D) == 0) then
    x2 = A/D
  else 
    x2 = A/D + 1
  end if
  if (mod(A,CD) == 0) then
    x3 = A/(CD)
  else 
    x3 = A/(CD) + 1
  end if 
  
  if (mod(B,C) == 0) then
    y1 = B/C + 1
  else 
    y1 = B/C + 1
  end if
  if (mod(B,D) == 0) then
    y2 = B/D + 1
  else 
    y2 = B/D + 1
  end if
  if (mod(B,CD) == 0) then
    y3 = B/(CD) + 1
  else 
    y3 = B/(CD) + 1
  end if 

  ans = B-A+1
  ans = ans-(y1-x1)
  ans = ans-(y2-x2)
  ans = ans+(y3-x3)

  write(*,*) ans
end program main


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<stack>
#include<set>
#include<climits>
#include<cstdlib>
#include<cmath>
#include<string>

using namespace std;

#define INF 1 << 29
#define LL long long int

struct mypair{
    int a;
    int b;
    bool r;

    bool operator < (const mypair &right) const{
        return a < right.a;
    }
};

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

    int n;
    cin >> n;

    vector<mypair> a(2*n);

    for(int i = 0; i < n; i++){
        int x,y;

        cin >> x >> y;

        a[i] = mypair{x,y,true};
    }

    for(int i = n; i < 2*n; i++){
        int x,y;

        cin >> x >> y;

        a[i] = mypair{x,y,false};
    }

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

    set<mypair> st;

    int count = 0;

    for(int i = 0; i < n*2; i++){
        if(a[i].r){
            st.insert(a[i]);
        }else{
            mypair t = mypair{-1,-1,false};
            auto del = st.begin();
            for(auto it = st.begin(); it != st.end(); it++){
                if((*it).b < a[i].b && (*it).b > t.b){
                    t = *it;
                    del = it;
                }
            }
            if(t.b < 0){

            }else{
                count++;
                st.erase(del);
            }
        }
    }

    cout << count << endl;

    return 0;
}

Measured memory_bytes: 256
<?php
//$N = (int)trim(fgets(STDIN));
list($X,$N) = array_map('intval',explode(" ",trim(fgets(STDIN))));
//$S = trim(fgets(STDIN));
$p = array_map('intval',explode(" ",trim(fgets(STDIN))));

foreach($p as $v) {
  $key[$v]=1;
}

for($i=0;$i<200;$i++) {
  if (!isset($key[$X-$i])) {
    printf("%d\n",$X-$i);
    exit;
  }
  if (!isset($key[$X+$i])) {
    printf("%d\n",$X+$i);
    exit;
  }
}


Measured memory_bytes: 16184
#include "iostream"
#include "string"
#include "vector"
#include "algorithm"
#include "functional"
#include "cmath"
#include "numeric"

int main() {
    // get values from input
    int n, m;
    std::vector<int> x;

    std::cin >> n >> m;

    for (int i = 0; i < m; ++i) {
        int x_i;
        std::cin >> x_i;
        x.push_back(x_i);
    }
    // main procedure
    std::vector<int> distances_of_spot;

    std::sort(x.begin(), x.end());
    for (int i = 0; i < m - 1; i++){
        distances_of_spot.push_back(x[i + 1] - x[i]);
    }
    std::sort(distances_of_spot.begin(), distances_of_spot.end());

    int move_times = std::max(m - n, 0);
    int answer = std::accumulate(distances_of_spot.begin(), distances_of_spot.begin() + move_times, 0);

    // output
    std::cout << answer << std::endl;

    return 0;
}

Measured memory_bytes: 1400
#include<iostream>

using namespace std;

int k,s;

int main(){
  cin >> k >> s;
  int ans=0;
  for(int x=0;x<=k;x++){
    for(int y=0;y<=k;y++){
      int z=s-x-y;
      if(z>=0 && z<=k) ans++;
    }}
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3652
#include <stdio.h>
#include <math.h>

typedef struct { double x, y; } point;
int input_point(point *p){ return scanf("%lf,%lf", &p->x, &p->y); }
double len(point a, point b) { return hypot(a.x - b.x, a.y - b.y); }

int main(int argc, char const *argv[])
{
	point a, b, c;
	double S = 0;

	input_point(&a);
	input_point(&b);
	while (~input_point(&c)){
		double x = len(a, b), y = len(b, c), z = len(c, a);
		double s = (x + y + z) / 2;
		S += sqrt(s * (s - x) * (s - y) * (s - z));
		b = c;
	}
	printf("%.6f\n", S);

	return (0);
}

Measured memory_bytes: 668
{-# OPTIONS_GHC -O2 -funbox-strict-fields #-}
import qualified Data.ByteString.Char8 as BC
import           Data.Maybe            (fromJust)

main :: IO ()
main = do
  [a, b, c, x, y] <- map readInt . BC.words <$> BC.getLine
  print $ solve a b c x y

solve :: Int -> Int -> Int -> Int -> Int -> Int
solve a b c x y
  | x > y     = solve' a b c x y
  | otherwise = solve' b a c y x

solve' a b c x y
  | a > 2 * c     = 2 * c * x
  | a + b > 2 * c = a * (x - y) + 2 * c * y
  | otherwise     = a * x + b * y

readInt :: BC.ByteString -> Int
readInt = fst . fromJust . BC.readInt


Measured memory_bytes: 380
#include <bits/stdc++.h>
#define maxn 1000233
#define maxm 2000233
#define maxno 26006058
using namespace std;

// node
//int now[maxm];
int has[maxm][27]; // how many can match
int sonid[maxm][27];
int ts;

int cnt[256];
long long Ans;

void insert(const char *s, int len) {
	int id = 0;
	if(len == 1) {
		++has[id][*(s - 1) - 'a'];
		return;
	}
	while(len) {
		--s, --len;
		if(sonid[id][*s - 'a']) id = sonid[id][*s - 'a'];
		else id = sonid[id][*s - 'a'] = ++ts;
		if(len == 1) {
			++has[id][*(s - 1) - 'a'];
			break;	
		}
	}
}

void query(const char *s, int len) {
	int id = 0;
	while(len) {
		--s, --len;
		for(int i = 0; i < 26; ++i) if(cnt[i + 'a']) Ans += has[id][i];
		--cnt[*s];
		if(sonid[id][*s - 'a']) id = sonid[id][*s - 'a'];
		else break;
	}
}

string str[maxn];
int len[maxn];

int main() {
	int N;
	scanf("%d", &N);
	for(int i = 1; i <= N; ++i) cin >> str[i];
	sort(str + 1, str + N + 1, [](const string &a, const string &b){
		return a.length() < b.length();
	});
	for(int i = 1; i <= N; ++i) {
		len[i] = str[i].length();
		memset(cnt, 0, sizeof cnt);
		for(int j = 0; j < len[i]; ++j) ++cnt[str[i][j]];
		query(str[i].c_str() + len[i], len[i]);
		insert(str[i].c_str() + len[i], len[i]);
	}
	printf("%lld", Ans);
	return 0;
}

Measured memory_bytes: 190172
#include <bits/stdc++.h>
using namespace std;
typedef int int__;
#define int long long
#define pb push_back
#define pi pair<int,int>
#define vpi vector<pi>
#define vi vector<int>
#define vvi vector<vi>
#define fi first
#define se second
#define forn(i, n)for(int i=0;i<int__(n);i++) 
#define sz(a)int__(a.size())
template <class A, class B> ostream& operator << (ostream& out, const pair<A, B> &a){return out << "(" << a.first << ", " << a.second << ")";}
template<class A>ostream& operator<<(ostream& out,const vector<A>&v){out<<"[";forn(i,sz(v)){if(i)out<<", ";out<<v[i];}return out<<"]";}
const int MAX = 1e9 + 100;
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
int Mod(int x){const int mm=2019;x%=mm;if(x<0)x+=mm;return x;}
int Pow(int x,int n){if(n==0)return 1;int t=Pow(x,n/2);t=Mod(t*t);if(n&1)t=Mod(t*x);return t;}
#define watch(x) cout << #x << " : " << x << endl;
int gcd(int a,int b){if(b==0)return a;return gcd(b,a%b);}
#define all(x) x.begin(), x.end()
 

 
int__ main() {
	fast;
	string s; cin >> s;
	int n=s.size();

	map<int,int> mp;
	int ans = 0;

	mp[0] = 1;

	int r = 0;
	for(int i=n-1;i>=0;i--) {
		
		r = Mod(Pow(10,n-i-1)*(s[i]-'0') + r);

		if(s[i]!='0') ans += mp[r];

		mp[r]++;
	}

	cout << ans << endl;
}

Measured memory_bytes: 3828
#include <iostream>
#include <cstdio>
#include <cstring>

using namespace std;

const int maxn = 100;
int p[maxn][maxn];
int vis[maxn];
int edger[maxn],edgec[maxn];
int n;

void dfs(int j)
{
    for(int i = 1; i <= n; i++)
    {
        if(!vis[i] && p[j][i])
        {
            vis[i] = 1;
            dfs(i);
        }
    }
    return;
}
bool ifspecial(int i)
{
    p[edger[i]][edgec[i]] = 0;
    p[edgec[i]][edger[i]] = 0;
    memset(vis,0,sizeof vis);
    int cnt = 0;
    for(int i = 1; i <= n; ++i)
    {
        if(!vis[i])
        {
            dfs(i);
            cnt++;
        }
    }
    p[edger[i]][edgec[i]] = 1;
    p[edgec[i]][edger[i]] = 1;
    if(cnt == 1)
        return false;
    else
        return true;
}

int main()
{
#ifdef local
    freopen("in.txt","r",stdin);
#endif // local
    ios::sync_with_stdio(0),cin.tie(0);
    int m;
    cin >> n >> m;
    for(int i = 0; i < m; ++i)
    {
        int a,b;
        cin >> a >> b;
        p[a][b] = 1;
        p[b][a] = 1;
        edger[i] = a;
        edgec[i] = b;
    }

    int ans = 0;
    for(int i = 0; i < m; ++i)
        if(ifspecial(i))
           ans++;
    cout << ans;

    return 0;
}


Measured memory_bytes: 256
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

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

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

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

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

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

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

int main(void){
    int N,m;
    LL sum;
    cin>>N;
    VI A(N);
    REP(i,N){
        cin>>A[i];
        A[i]-=(i+1);
    }
    sort(A.begin(), A.end());
    m=A[A.size()/2];
    REP(i,N)sum+=abs(A[i]-m);
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 1024
N,L=map(int, input().split())
 
sum = 0
lower = 100000
for i in range(1, N+1):
    sum = sum + L + i -1
for i in range(1, N+1):
    s = abs(L + i -1)
    if s < lower:
        lower = s
        ij = i
 
print(sum - (L + ij -1))

Measured memory_bytes: 3060
#include <algorithm>
#include <iostream>
#include <map>
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
using namespace std;

#define MAX_N 100000

map<ll, int> prime_factor(ll n) {
  map<ll, int> ret;
  for (ll i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if (n != 1) ret[n] = 1;
  return ret;
}

int main(void) {
  ios::sync_with_stdio(false);
  ll A, B;
  cin >> A >> B;
  if (A > B) {
    ll tmp = A;
    A = B;
    B = tmp;
  }

  int Ans = 1;
  auto mpB = prime_factor(B);
  for (auto p : prime_factor(A)) {
    if (mpB[p.first] > 0) Ans++;
  }
  cout << Ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
using Graph=vector<vector<int>>;
typedef long long ll;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};

int main(){
    int a,b,c,d;cin>>a>>b>>c>>d;
    while(true){
        c-=b;
        if(c<=0){
            cout<<"Yes"<<endl;
            break;
        }
        a-=d;
        if(a<=0){
            cout<<"No"<<endl;
            break;
        }
    }
}

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

int main() {
	int n;

	cin >> n;

	int maxvalue = 0;
	map<string, int> m;

	for (int i = 0; i < n; ++i)
	{
		string s;
		cin >> s;
		++m[s];
		maxvalue = max(maxvalue, m[s]);
	}

	for (auto mm : m)
	{
		if (mm.second == maxvalue)
		{
			cout << mm.first << endl;
		}
	}
	

	return 0;
}


Measured memory_bytes: 25216