akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
const int MAXN=212345;
int e[MAXN],d[MAXN];
long long v[MAXN];
int main()
{
    int n;
    scanf("%d",&n);
    v[0]=-1;v[n+1]=-1;
    e[0]=0;d[n+1]=n+1;
    for(int i=1;i<=n;i++)scanf("%lld",&v[i]);
    for(int i=1;i<=n;i++)
    {
        int k=i-1;
        while(v[k]>v[i])k=e[k];
        e[i]=k;
    }
    for(int i=n;i>0;i--)
    {
        int k=i+1;
        while(v[k]>v[i])k=d[k];
        d[i]=k;
    }
    long long resp=0;
    for(int i=1;i<=n;i++)
    {
        long long a1=i-e[i],a2=d[i]-i;
        //printf("%lld %lld\n",a1,a2);
        resp+=a1*a2*v[i];
    }
    printf("%lld\n",resp);
    return 0;
}


Measured memory_bytes: 3328
// AtCoder Beginner Contest 120 - Problem C: Unification (https://atcoder.jp/contests/abc120/tasks/abc120_c)
#include <bits/stdc++.h>

using namespace std;

int solve(const string& s)
{
    int ones = 0, zeroes = 0;

    for (const auto c : s)
    {
        ones += (c == '1' ? 1 : 0);
        zeroes += (c == '0' ? 1 : 0);
    }

    auto ans = min(ones, zeroes) * 2;

    return ans;
}

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

    string s;
    cin >> s;

    auto ans = solve(s);

    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 512
package main

import (
	"fmt"
	"math"
)

func main() {
	var x int
	fmt.Scan(&x)

	sqrt := int(math.Sqrt(float64(x)))

	ans := 1
	for i := 2; i <= sqrt; i++ {
		for j := 1; j < 10; j++ {
			tmp := pow(i, j)
			if tmp > x {
				break
			}
			ans = max(ans, tmp)
		}
	}
	fmt.Println(ans)
}

func max(x, y int) int {
	return int(math.Max(float64(x), float64(y)))
}

func pow(x, y int) int {
	return int(math.Pow(float64(x), float64(y)))
}


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

int main(){
    long long N;
    cin >> N;
    int M;
    int ans = 11;
    int pre;
    int a, b;
    M = sqrt(N) + 100;
    for(int i=1; i < M; i++){
        if(N % i == 0){
            a = log10(i) + 1;
            b = log10(N / i) + 1;
            pre = max(a, b);
            ans = min(ans,pre);
        }
    }
    cout << ans << endl;
}

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

// nice things
#define len(x) ((sizeof(x)/sizeof(0[x])) / ((size_t)(!(sizeof(x) % sizeof(0[x])))))
#define help(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); _help(_it, args); }
void _help(istream_iterator<string> it) {}
template<typename T, typename... Args>
void _help(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " is " << a << "\n";
	_help(++it, args...);
}

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

    int N;
    cin >> N;
    
    cout << (N-1)/2;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<utility>
#include<algorithm>
#include<cstdio>
#include<iomanip>
#include<queue>
#include<stack>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)

using namespace std;

ll GCD (ll a, ll b) {
    if (a < b) {
        swap(a, b);
    }

    ll r = a % b;
    while (r != 0) {
        a = b;
        b = r;
        r = a % b;
    }

    return b;
}

ll LCM (ll a, ll b) {
    ll g = GCD (a, b);
    return a * b / g;
}

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

    ll N;
    cin >> N;
    vector<pair<ll, ll>> task;
    Rep (i, N) {
        ll a, b;
        cin >> a >> b;
        task.push_back(make_pair(b, a));
    }

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

    ll now = 0;
    bool ans = true;
    Rep (i, N) {
        now += task[i].second;
        if (now > task[i].first) {
            ans = false;
            break;
        }
    }

    if (ans) cout << "Yes\n";
    else cout << "No\n";

}

Measured memory_bytes: 6384
implicit none
integer(8) :: i,l
character :: s*105
logical :: c,f
read*,s
c = .false.
f = .false.
l = len(trim(s))
do i = 1,l
	if(s(i:i)=='C')then
		c = .true.
	else if(s(i:i)=='F' .and. c)then
		f = .true.
	endif
enddo
if(c .and. f)then
	write(*,'(a)')'Yes'
else
	write(*,'(a)')'No'
endif
end

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <deque>
using ll = long long;
int MOD = 1e9 + 7;
using namespace std;
ll GCD(ll x, ll y)
{
    if (y == 0)
    {
        return x;
    }
    else
    {
        return GCD(y, x % y);
    }
}
ll LCM(ll x, ll y)
{
    return x / GCD(x, y) * y;
}
struct UnionFind
{
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

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

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

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

    bool same(int x, int y)
    { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};
int main()
{
    ll n, k;
    cin >> n >> k;
    vector<pair<int,int>> vec(n);
    for (int i = 0; i < n;i++){
        ll x,y;
        cin>>x>>y;
        vec[i]=make_pair(x,y);
    }
    sort(vec.begin(),vec.end());
    for(int i=0;i<n;i++){
        k-=vec[i].second;
        if(k<=0){
            cout<<vec[i].first<<endl;
            return 0;
        }
    }
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr long long INFL = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;


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

    int N;
    cin >> N;
    int x[N],y[N];
    rep(i,N) cin >> x[i] >> y[i];

    int A[N];
    rep(i,N) A[i]=i;
    double sum=0;
    int co=0;
    do {
        for(int i=1;i<N;i++){
            sum+=pow(pow(x[A[i]]-x[A[i-1]],2)+pow(y[A[i]]-y[A[i-1]],2),0.5);
        }
        co++;

    }while (next_permutation(A, A+N));
    double ans=sum/co;
    cout << fixed << setprecision(14);
    cout << ans << endl;

}


Measured memory_bytes: 512
n = input()

if(n[len(n)-1] == "2" or n[len(n)-1] == "4" or n[len(n)-1] == "5" or n[len(n)-1] == "7" or n[len(n)-1] == "9"):
  print("hon")
elif(n[len(n)-1] == "0" or n[len(n)-1] == "1" or n[len(n)-1] == "6" or n[len(n)-1] == "8"):
  print("pon")
elif(n[len(n)-1] == "3"):
  print("bon")
 


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

#define ll long long

#define pii pair < int, int >
#define pll pair < ll, ll >

#define vi vector < int >
#define vs vector < string >

#define pb push_back

using namespace std;

const int N = 1e5 + 50;

int a[N], b[N];
bool vis[N];

int main()
{
    int x, y;

    cin >> x >> y;

    if(y % 2 == 0 && y / 2 == x){
        cout << "Yes" << endl;
        return 0;
    }

    if(y % 4 == 0 && y / 4 == x){
        cout << "Yes" << endl;
        return 0;
    }

    for(int i = 1; i <= x; i++){
        int tmp = (i * 2) + ((x - i) * 4);

        if(tmp == y){
            cout << "Yes" << endl;
            return 0;
        }
    }

    cout << "No" << endl;

    return 0;
}


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

int a[100010];
int cnt[100010];

int main() {
	long long n, q, b, c, s = 0;

    ios::sync_with_stdio(false);
    cin.tie(0);

	cin >> n;

	for(long long i = 0; i < n; i++) {
		cin >> a[i];
		cnt[a[i]]++;
		s += a[i];
	}

	cin >> q;
	while(q--) {	//q operations
		cin >> b >> c;
		long long tmp = cnt[b]*(b-c);
		s = s - tmp;
		cnt[c] += cnt[b];
		cnt[b] = 0;

		cout << s << endl;
	}

	return 0;
}


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

X, Y, Z = map(int, input().split())

for i in range(1, 1000001):
    if (Y + Z) * i + Z > X:
        # 座り切れなくなった所で、ひとつ前の値を出力
        print(i - 1)
        exit()

Measured memory_bytes: 2940
S = input()

N = len(S)
L = [0] * N

s = S[0]
cnt = 1
for i in range(1, N):
  if S[i] == s:
    cnt += 1
  else:
    if S[i] == "L":
      re = i - 1
      L[re] = cnt // 2 + cnt % 2
      L[re + 1] = cnt // 2
    else:
      L[re] += cnt // 2
      L[re + 1] += cnt // 2 + cnt % 2
    cnt = 1
    s = S[i]
L[re] += cnt // 2
L[re + 1] += cnt // 2 + cnt % 2

print(" ".join(list(map(str, L))))

Measured memory_bytes: 10484
#include<iostream>
using namespace std;
int main()
{
	int n;	cin>>n;
	bool OK=true;
	for(int i=1;i<=n;i++)
	{
		int x;	cin>>x;
		if(x%2==0&&(x%3!=0&&x%5!=0))
			OK=false;
	}
	if(OK)
		cout<<"APPROVED"<<endl;
	else 
		cout<<"DENIED"<<endl;
}

Measured memory_bytes: 256
// clang-format off
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979;
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
bool odd(const int &n) { return n & 1; }
bool even(const int &n) { return ~n & 1; }
template<typename T> int len(const T &v) { return v.size(); }
template<typename T = int> T in() { T x; cin >> x; return x; }
template<typename T = int> T in(T &&x) { T z(forward<T>(x)); cin >> z; return z; }
template<typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &x : v) is >> x; return is; }
template<typename A, typename B> istream &operator>>(istream &is, pair<A, B> &p) { return is >> p.first >> p.second; }
template<typename T> ostream &operator<<(ostream &os, const vector<vector<T>> &v) { int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "" : "\n"); return os; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "" : " "); return os; }
template<typename A, typename B> ostream &operator<<(ostream &os, const pair<A, B> &p) { return os << p.first << ' ' << p.second; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
// clang-format on

main() {
  int h, w;
  cin >> h >> w;
  auto a = vectors(h, w, 0LL);
  cin >> a;
  int ans = INF;
  rep(i, h) rep(j, w) {
    int s = 0;
    rep(k, h) rep(l, w) s += min(abs(i - k), abs(j - l)) * a[k][l];
    cmin(ans, s);
  }
  cout << ans << endl;
}



Measured memory_bytes: 3144
/*
By Tianyi Chen. All rights reserved.
Date: 2016-08-13
*/
#include<bits/stdc++.h>
using namespace std;
int n,a[100],s,ans=INT_MAX;
int main() {
 scanf("%d",&n);for(int i=0;i<n;++i)scanf("%d",a+i);
 for(int t=-100;t<=100;++t) {
  s=0;
  for(int i=0;i<n;++i)s+=(t-a[i])*(t-a[i]);
  ans=min(ans,s);
 }
 printf("%d\n",ans);
}

Measured memory_bytes: 256
N = int(input())

def dfs(s): # 文字列 s で始まる七五三数の個数
  if int(s) > N:
    return 0
  ret = 1 if all(s.count(c) > 0 for c in '753') else 0 # s 自体が七五三数なら +1
  for c in '753':
    ret += dfs(s + c)
  return ret

print(dfs('0')) # 本当は dfs('') と書きたいが 4 行目でのエラーを防ぐため仕方なく

Measured memory_bytes: 55004
//#define _GLIBCXX_DEBUG

#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
const int INF= 1e9+5;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>>vvi;

int main(){
  string a,b;
  cin>>a>>b;
  int A=a.size(), B=b.size();
  if(A>B)cout<<"GREATER"<<endl;
  else if(A<B)cout<<"LESS"<<endl;
  else{
    bool equal=true;
    for(int i=0;i<A;i++){
      if(a[i]!=b[i])equal=false;
    }
    if(equal){
      cout<<"EQUAL"<<endl;
      return 0;
    }
    bool a_big=false;
    for(int i=0;i<A;i++){
      if(a[i]<b[i]){
        a_big=false;
        break;
      }
      if(a[i]>b[i]){
        a_big=true;
        break;
      }
    }
    if(a_big)cout<<"GREATER"<<endl;
    else cout<<"LESS"<<endl;
  }
}
  

Measured memory_bytes: 256
N = int(input())
A = tuple(map(int, input().split()))
S = [0]
for a in reversed(A):
    S.append(S[-1] + a)
S.reverse()

lst = [0] * (N + 2)
lst[0] = 1
for i, a in enumerate(A):
    if lst[i] < a:
        print(-1)
        break
    lst[i + 1] = min((lst[i] - a) * 2, S[i + 1])
else:
    print(sum(lst))


Measured memory_bytes: 22148
import itertools
n,m,q=map(int, input().split())
abcd = [list(map(int, input().split())) for i in range(q)]
l = [i+1 for i in range(m)]
ans = 0
for v in itertools.combinations_with_replacement(l, n):
    point = 0
    for j in range(len(abcd)):
        if v[abcd[j][1]-1] - v[abcd[j][0]-1] == abcd[j][2]:
            point += abcd[j][3]
    if ans < point:
        ans = point
print(ans)

Measured memory_bytes: 9204
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	N := ReadInt()
	a := make([]int, N)
	b := make([]int, N)
	for i := 0; i < N; i++ {
		a[i], b[i] = ReadInt(), ReadInt()
	}
	for i := 0; i < N-2; i++ {
		if a[i] == b[i] && a[i+1] == b[i+1] && a[i+2] == b[i+2] {
			fmt.Println("Yes")
			return
		}
	}
	fmt.Println("No")
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }
func ReadInts(n int) (a []int) {
	for i := 0; i < n; i++ {
		a = append(a, ReadInt())
	}
	return
}


Measured memory_bytes: 1844
#include <cstdio>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <string>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <cmath>
#include <iomanip>
#include <list>
#include <tuple>
#include <bitset>
#include <ciso646>
#include <cassert>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;
typedef vector<ll> vec;

inline bool check(ll x, ll y, ll xMax, ll yMax) { return x >= 0 && y >= 0 && xMax > x && yMax > y; }
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(); }
template<class T> inline T sqr(T x) { return x*x; }
template<class T> inline T mypow(T x, ll n) { T res = 1; while (n > 0) { if (n & 1)res = res * x;	x = x * x;	n >>= 1; }return res; }
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

#define For(i,a,b)	for(ll (i) = (a);i < (b);(i)++)
#define rep(i,n)	For(i,0,n)
#define rFor(i,a,b)	for(ll (i) = (a-1);i >= (b);(i)--)
#define rrep(i,n)	rFor(i,n,0)
#define each(i,n)	for(auto &i : n)
#define clr(a)		memset((a), 0 ,sizeof(a))
#define mclr(a)		memset((a), -1 ,sizeof(a))
#define all(a)		(a).begin(),(a).end()
#define sz(a)		(sizeof(a))
#define tostr(a)	tostring(a)
#define dump(val) 	cerr << #val " = " << val << endl;
#define Fill(a,v)	fill((int*)a,(int*)(a+(sz(a)/sz(*(a)))),v)

const ll dx[8] = { 1, 0, -1, 0, 1, 1, -1, -1 }, dy[8] = { 0, -1, 0, 1, -1, 1, -1, 1 };

const ll mod = 1e9 + 7;
const ll INF = 1e17 + 9;

#define int ll
#define double ld


set<int> solve(int n) {
	set<int> ret;
	int sum = 0;
	for (int i = 1; i <= n; i++) {
		ret.insert(i);
		sum += i;
		if (sum >= n)break;
	}
	if (ret.count(sum - n)) {
		ret.erase(sum - n);
	}
	return ret;
}

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

	int N;
	cin >> N;

	auto ans = solve(N);

	each(i, ans) {
		cout << i << endl;
	}

	return 0;
}

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

using namespace std;

int main() {
    string s;
    cin >> s;
    string hitachi = "";
    for (int i = 1; i <= 5; i++) {
        hitachi += "hi";
        if (hitachi == s) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
#include<iterator>
#include<list>
using namespace std;
typedef  long long int lint;
//typedef pair<int, int> IP;
typedef pair<lint, lint> LLP;
typedef pair<char, char>CP;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define llower(v,hoge) *lower_bound(v.begin(), v.end(), hoge)
#define lupper(v,hoge) *upper_bound(v.begin(), v.end(), hoge)
#define mp make_pair
#define P pair<int,int>

int main() {
	int INF = 100000000;
	int V;
	cin >> V;
	vector<vector<P>>G(V);
	rep(i, V) {
		int v, k;
		cin >> v >> k;
		rep(j, k) {
			int tmpv, tmpc;
			cin >> tmpv >> tmpc;
			G[i].push_back(mp(tmpv, tmpc));
		}
	}
	int start = 0;//スタート位置
	vector<int>dist(V, INF);//startからの距離を入れる配列。INF(未訪問)で初期化
	dist[start] = 0;
	priority_queue<P, vector<P>, greater<P>>que;//少ない値を優先するプライオリティキューを宣言
	que.push(mp(dist[start], start));

	while (!que.empty()) {
		P p = que.top();
		int v = p.second;
		que.pop();
		if (dist[v] < p.first)continue;
		for (int i = 0; i < G[v].size(); i++) {
			P e = G[v][i];
			int u = e.first, cst = e.second;
			if (dist[u] > dist[v] + cst) {
				dist[u] = dist[v] + cst;
				que.push(mp(dist[u], u));
			}
		}
	}
	rep(i, V) {
		cout << i << ' ' << dist[i] << endl;
	}
}


Measured memory_bytes: 7828
# 5で割って1余る素数だけで構成する
# すると任意の5つの組の和は5で割り切れるため、合成数となる
def sieve(n):
    is_prime = [True for _ in range(n+1)]
    is_prime[0] = False
    for i in range(2, n+1):
        if is_prime[i-1]:
            j = 2 * i
            while j <= n:
                is_prime[j-1] = False
                j += i
    table = [ i for i in range(1, n+1) if is_prime[i-1]]
    return is_prime, table

ps = sieve(55555)[1]
N = int(input())
cands = []
for p in ps:
  if p%5 == 1:
    cands.append(p)
    if len(cands) == N:
      break

print(*cands)

Measured memory_bytes: 3736
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<ll,ll> P;
#define pb push_back
#define mp make_pair
#define fr(i,n) for(int i=0;i<n;i++)
#define Fr(i,n) for(int i=0;i++<n;)
#define ifr(i,n) for(int i=n-1;i>=0;i--)
#define iFr(i,n) for(int i=n;i>0;i--)

const ll INF=1e17;
int main(){
  ll n,m,r,x[10],a,b,c,d[220][220],dp[1<<8][8];
  cin>>n>>m>>r;
  fr(i,r) cin>>x[i];
  Fr(i,n) Fr(j,n) d[i][j]=INF;
  fr(i,m){
    cin>>a>>b>>c;
    d[a][b]=c;
    d[b][a]=c;
  }
  Fr(k,n) Fr(i,n) Fr(j,n) d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
  fr(i,1<<r){
    fr(j,r){
      if(1-((i>>j)&1)) continue;
      if(i==(1<<j)){
        dp[i][j]=0;
        continue;
      }
      dp[i][j]=INF;
      fr(k,r){
        if(1-((i>>k)&1)) continue;
        if(k==j) continue;
        dp[i][j]=min(dp[i][j],dp[i-(1<<j)][k]+d[x[j]][x[k]]);
      }
    }
  }
  ll ans=INF;
  fr(i,r) ans=min(ans,dp[(1<<r)-1][i]);
  cout<<ans<<endl;
}

Measured memory_bytes: 640
/************************************************************
	> File Name: d.cpp
	> Author: TSwiftie
	> Mail: 2224273204@qq.com 
	> Created Time: Sun 19 Jan 2020 08:28:03 PM CST
************************************************************/

#pragma GCC optimize(2)
#include <bits/stdc++.h>
#include <ext/rope>
#define lowbit(x) (x&-x)
#define lc (o<<1)
#define rc (o<<1|1)
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int INF = 0x3f3f3f3f;
const int MAXN = 15;
const int MAXM = 2e5+5;
const int MOD = 1e9+7;
const int dir[4][2] = {1,0,-1,0,0,1,0,-1};
const double PI = acos(-1.0);
const double EXP = 1e-8;
int f[MAXN][MAXN];
int main(void){
	IOS;
	int n;
	cin >> n;
	for(int i = 1;i <= n;i++){
		int tmp = i;
		while(tmp%10!=tmp)
			tmp/=10;
		f[tmp][i%10]++;
	}
	ll ans = 0;
	for(int i = 1;i <= 10;i++)
		for(int j = 1;j <= 10;j++)
			ans += f[i][j]*f[j][i];
	cout << ans << endl;
	return 0;
}

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



int main() 
{
  vector<string> key(0);
  std::map<std::string,int> S;
  int N;
  cin >> N;
  string s;
  int criteria=0;
  rep(i, N)
  {
  cin >> s;
    int a = S[s];
   S[s]=a+1;
    if(a+1==1){
    key.push_back(s);
    }
    if(a+1>criteria)
      criteria=a+1;
  }
  sort(ALL(key));
  rep(i, S.size())
  {
    if(S[key[i]]==criteria)
      cout << key[i] << endl;
  }

}

Measured memory_bytes: 26736
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int mod = 1e9+7;
int s[2005], t[2005];
LL dp[2005][2005];
int main(){
    int n, m;
    scanf("%d%d", &n, &m);
    for(int i=1;i<=n;i++) scanf("%d", &s[i]);   
    for(int i=1;i<=m;i++) scanf("%d", &t[i]);
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            if(s[i] == t[j]) dp[i][j] = (dp[i][j] + dp[i-1][j-1] + 1)%mod;
            dp[i][j] = (dp[i][j] + dp[i-1][j] + dp[i][j-1] - dp[i-1][j-1] + mod)%mod;
        }
    }
    printf("%d\n", (dp[n][m]+1)%mod);
}

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

using namespace std;
using llong = long long;
using P = pair<llong, llong>;

#define BE(x) x.begin(), x.end()

const llong inf = llong(1e18)+7;
const llong mod = 1e9+7;

int main(){
	int n,a,b;
	cin >> n >> a >> b;

	cout << min(b,a*n) << endl;

	return 0;
}

Measured memory_bytes: 256
using System;
class aoj{
	static void Main(){
		int a=int.Parse(Console.ReadLine());
		string []b=Console.ReadLine().Split(' ');
		int []c=new int[a];
		for(int i=0;i<a;i++){
			c[i]=int.Parse(b[i]);
		}
		Array.Reverse(c);
		Console.Write(c[0]);
		for(int i=1;i<a;i++){
			Console.Write(" "+c[i]);
		}
		Console.WriteLine();
	}
}

Measured memory_bytes: 9132
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=(ll)(1e9+7);
ll run();
int main() {
#ifdef home
    freopen("i", "r", stdin);
    freopen("d", "w", stderr);
#endif
    cout.precision(15);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    run();
    return 0;
}
const ll inf = (1e8+5);
void max_self(ll &a, ll b) {
    a = max(a, b);
}
void min_self(ll &a, ll b) {
    a = min(a, b);
}
void mul(ll &a, ll b) {
    a = (a * b) % mod;
}
void add_self(ll &a, ll b){
    a+=b;
    if(a>=mod)
        a-=mod;
}
ll gcd(ll a, ll b){
    return b?gcd(b,a%b):a;
}


ll run() {
    int H,W,h,w;
    cin>>H>>W>>h>>w;
    cout<<(H*W-(h*W+w*H-h*w));


}


















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

int main(){
	int a[5];
	int b[4];
	while(true){
		b[1] = 0;
		b[2] = 0;
		b[3] = 0;
		for(int i=0; i<5; i++){
			cin >> a[i];
			if(!a[0])
				return 0;
			b[a[i]]++;
		}
		if(b[1] == 5 || b[2] == 5 || b[3] == 5 || (b[1] && b[2] && b[3]))
			for(int i=0; i<5; i++)
				cout << 3 << endl;
		else if(!b[1])
			for(int i=0; i<5; i++){
				if(a[i] == 2)
					cout << 1 << endl;
				else
					cout << 2 << endl;
			}
		else if(!b[2])
			for(int i=0; i<5; i++){
				if(a[i] == 3)
					cout << 1 << endl;
				else
					cout << 2 << endl;
			}
		else
			for(int i=0; i<5; i++){
				if(a[i] == 1)
					cout << 1 << endl;
				else
					cout << 2 << endl;
			}
	}
}

Measured memory_bytes: 0
import math
from collections import deque
N, K = map(int, input().split())
A = list(map(int, input().split()))
S = sum(A)
cut = []
for k in range(N):
  cut.append(K*A[k]//S)

length = []
for k in range(N):
  length.append([A[k] / (cut[k]+1), k])

length.sort(key = lambda x: x[0], reverse=True)

def nibun_insert(lis, item):
  end = len(lis)
  start = 0
  now = (end+start)//2
  while end > start+1:
    if lis[now][0] > item[0]:
      start = 0 + now
      now = (now + end)//2
    else:
      end = 0 + now
      now = (now + start)//2
  lis.insert(now+1, item)
  return lis

C = sum(cut)
res = K - C
length = length[:res+1]
length = deque(length)
for _ in range(res):
  a = length.popleft()
  cut[a[1]] += 1
  a[0] = a[0]*cut[a[1]]/(cut[a[1]]+1)
  if a[0] <= length[-1][0]:
    continue
  elif a[0] >= length[0][0]:
    length.appendleft(a)
  else:
    length = nibun_insert(length, a)
  length.pop()

print(math.ceil(length.popleft()[0]))

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

// int/long:		-2,147,483,648 - 2,147,483,648 (-2^31 <= int < 2^31)
// long/long long:	-9,223,372,036,854,775,808 - 9,223,372,036,854,775,807 (-2^63 <= long < 2^63)

#define	INF (1<<29)
//536,870,912

// lower_bound(A.begin(), A.end(), N)
// upper_bound(...

// A.erase(unique(A.begin(), A.end()), A.end())

// bit: &/and, |/or, ^/xor, ~/not

// getline(cin, String)

// Graph
// Warshall-Floyd: Distance between each node, N^3
// Dijkstra: Distance from the start node, N^2
// DFS(Depth-First Search)

#define	MOD 1000000007

int	main() {
	int N;
	cin >>N;
	vector<int> A(N+1, 0);
	int MA=0;
	int MI=0;
	int MAI=-1;
	int MII=-1;
	for (int i=1; i<=N; i++) {
		cin >>A.at(i);
		if (MA<A.at(i)) {
			MAI=i;
			MA=A.at(i);
		}
		if (MI>A.at(i)) {
			MII=i;
			MI=A.at(i);
		}
	}
	vector<vector<int>> B;
	if (-1==MII) {
		for (int i=1; i<N; i++) {
			B.push_back({i, i+1});
		}
	} else if (-1==MAI) {
		for (int i=N; i>1; i--) {
			B.push_back({i, i-1});
		}
	} else if (abs(MA)>=abs(MI)) {
		for (int i=1; i<=N; i++)
			if (A.at(i)<0)
				B.push_back({MAI, i});
		for (int i=1; i<N; i++) {
			B.push_back({i, i+1});
		}
	} else if (abs(MA)<abs(MI)) {
		for (int i=1; i<=N; i++)
			if (A.at(i)>0)
				B.push_back({MII, i});
		for (int i=N; i>1; i--) {
			B.push_back({i, i-1});
		}
	}
	cout <<B.size() <<endl;
	for (int i=0; i<B.size(); i++)
		cout <<B.at(i).at(0) <<' ' <<B.at(i).at(1) <<endl;
	/*
	for (int i=0; i<B.size(); i++)
		A.at(B.at(i).at(1)) +=A.at(B.at(i).at(0));
	for (int i=1; i<=N; i++)
		cout <<A.at(i) <<endl;
	*/
	return 0;
}



Measured memory_bytes: 256
//ProblemC

#define USE_STDIO

#ifdef _MYPC
#include "mypc.h"
#endif // _MYPC

#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <list>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
#include <memory>
#include <cstdio>
#include <cstring>

using namespace std;

//ProblemC

static const string V = "Vacant";
static const string M = "Male";
static const string F = "Female";

constexpr int Q = 20;

class Solve {
private:
	int n;
	void solve() {
		cin >> n;
		string ans;

		cout << 0 << endl;
		cin >> ans;

		int l = 0, r = n;
		char lc = ans[0];
		if (lc == V[0]) return;

		for (int i = 1; i < Q; i++) {
			int mid = (l + r) / 2;
			cout << mid << endl;
			cin >> ans;

			if (ans[0] == V[0]) return;

			if (ans[0] == lc && (mid - l) % 2 != 0
				|| ans[0] != lc && (mid - l) % 2 == 0) {
				r = mid;
			}
			else {
				l = mid;
				lc = ans[0];
			}
		}
	}

public:
	Solve() { solve(); }
};

int main(int argc, char* argv[]) {
	unique_ptr<Solve> solve = make_unique<Solve>();
	return 0;
}


Measured memory_bytes: 852
#include<iostream>
#include<vector>
#include<cstdio>
#include<climits>

using namespace std;
int const inf=INT_MAX;
int gcd(int a,int b){
  int tmp;
  while(a!=0){
  if(a<b){
    tmp=a;
    a=b;
    b=tmp;
  }
  a=a%b;
  } 
  return b;
}
class Seg_Tree{
    private:
    int n;
    vector<int> node;
    public:
    int process(int left,int right){
        if(left==inf)return right;
        if(right==inf)return left;
        int ans=gcd(left,right);
        return ans;
    }
    Seg_Tree(vector<int> v){
        int num=1;
        int size=v.size();
        while(num<size){
            num*=2;
        }
        n=num;
        node.resize(2*num-1,inf);
        for(int i=0;i<size;i++)node[i+num-1]=v[i];
        for(int i=n-2;i>=0;i--)node[i]=process(node[i*2+1],node[i*2+2]);
    }
    void update(int x,int val){
        x+=(n-1);
        node[x]=val;
        while(x>0){
            x=(x-1)/2;
            node[x]=process(node[x*2+1],node[x*2+2]);
        }
    }
    int out(int a,int b,int k=0,int l=0,int r=-1){
        if(r<0)r=n;
        if(a>=r||b<=l)return inf;
        if(a<=l&&b>=r)return node[k];
        int vl=out(a,b,k*2+1,l,(l+r)/2);
        int vr=out(a,b,k*2+2,(l+r)/2,r);
        return process(vl,vr);
    }
};

int main(){
    int n;
    cin>>n;
    vector<int> num(n);
    for(int i=0;i<n;i++)cin>>num[i];
    Seg_Tree tree(num);
    int max=tree.out(1,n);
    if(max<tree.out(0,n-1))max=tree.out(0,n-1);
    for(int i=1;i<n-1;i++){
        int tmpl=tree.out(0,i);
        int tmpr=tree.out(i+1,n);
        int tmp=gcd(tmpl,tmpr);
        if(tmp>max)max=tmp;
    }
    cout<<max<<endl;
    return 0;
}

Measured memory_bytes: 2048
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();
		scan.close();

		if(1<=a && a<=100){
			if(1<=b && b<=100){
				System.out.println(a*b+" "+(a+b)*2);
			}
		}

	}

}

Measured memory_bytes: 26096
import sys
input = sys.stdin.buffer.readline

n, k = map(int, input().split())
s, p, r = map(int, input().split())
t = input().rstrip().decode("utf-8")

cnt = 0
for i in range(k):
    f = 0
    pre = ""
    for j in range(i, n, k):
        if pre != t[j] or f == 1:
            cnt += eval(t[j])
            f = 0
        else:
            f = 1
        pre = t[j]
print(cnt)

Measured memory_bytes: 3316
#include<stdio.h>
int main(void)
{
	int a,b;
	scanf("%d",&a);
	scanf("%d",&b);
	if(a==1){
		a=a+13;
	}
	if(b==1){
		b=b+13;
	}
	if(a==b){
		printf("Draw\n");
	}
	else{
		if(a>b){
			printf("Alice\n");
		}
		if(a<b){
			printf("Bob\n");
		}
	}
	return 0;
}


Measured memory_bytes: 128
import java.awt.Point
import java.util.*

fun main(args:Array<String>) {
    val (h,w) = readLine()!!.split(" ").map { it.toInt() }
    val map = (1..h).map { readLine()!! }
    val step = (1..h).map { (1..w).map { MapState( h*w+1, null) }.toMutableList() }
    step[0][0] = MapState(0, null)
    val queue = LinkedList<Pos>()
    queue.push(Pos(0,0))
    while (queue.isNotEmpty()) {
        val current = queue.pop()
        for(i in (Math.max(0, current.r - 1)..Math.min(h-1, current.r + 1))) {
            for(j in Math.max(0, current.c -1)..Math.min(w-1, current.c + 1)) {
                if(i == current.r && j == current.c) {
                    continue
                }
                if(i != current.r && j != current.c) {
                    continue
                }
                if(map[i][j] == '#') {
                    continue
                }
                if(step[i][j].step <= step[current.r][current.c].step + 1) {
                    continue
                }
                step[i][j] = MapState(step[current.r][current.c].step + 1, current)
                queue.push(Pos(i,j))
            }
        }
    }
    if(step.last().last().step == h*w+1) {
        println(-1)
        return
    }
    val flag = (1..h).map { (1..w).map { false }.toMutableList() }
    queue.push(Pos(h-1,w-1))
    while (queue.isNotEmpty()) {
        val current = queue.pop()
        flag[current.r][current.c] = true
        step[current.r][current.c].from?.let { queue.push(it) }
    }
    var ans = 0
    for(i in (0 until h)) {
        for(j in (0 until w)) {
            if(map[i][j] == '#') {
                continue
            }
            if(flag[i][j]) {
                continue
            }
            ans++
        }
    }
    println(ans)

}

class MapState(val step:Int, val from:Pos?)
class Pos(val r:Int, val c:Int)


Measured memory_bytes: 48688
import java.awt.*;
import java.awt.geom.*;
import java.io.*;

import java.util.*;
class Main {


	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int S = sc.nextInt();
		int h = S / 3600;
		S -= h * 3600;
		int m = S / 60;
		S -= m * 60;
		System.out.println(h + ":" + m + ":" + S);
	}
}

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

#define fer( a , b , c ) for( register int a = b ; a <= c ; a ++ )
#define der( a , b , c ) for( register int a = b ; a >= c ; a -- )

  using namespace std ;

inline int read(){
	int sum = 0 , f = 1 ;
	char ch = getchar() ;
	while( ch < '0' || ch > '9' ){
		if( ch == '-' ){
			f = -1 ;
		}
		ch = getchar() ;
	}
	while( ch >= '0' && ch <= '9' ){
		sum = ( sum << 1 ) + ( sum << 3 ) + ( ch ^ 48 ) ;
		ch = getchar() ;
	}
	return sum * f ;
}

int x ; 

signed main(){
	cin >> x ;
	if( x == 0 ){
		cout << "1" ;
	}
	else{
		cout << "0" ;
	}
	return 0 ;
}



Measured memory_bytes: 3532
#include <bits/stdc++.h>
#define pt(sth) cout << sth << "\n"
#define chmax(a, b) {if(a<b) a=b;}
#define chmin(a, b) {if(a>b) a=b;}
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
static const ll INF=1e18;
static const ll MAX=101010;
static const ll MOD=1e9+7;
static const ll LOGN=55;

map<ll, ll> mp;
void divisor(ll n) {
  for(ll i=1; i*i<=n; i++) {
    if(n%i==0) {
      mp[i]++;
      mp[n/i]++;
    }
  }
}

int main(void) {
  ll N, M;
  cin >> N >> M;
  
  divisor(M);
  
  ll ans=0;
  for(auto it=mp.begin(); it!=mp.end(); it++) {
    if(M/it->first>=N) ans=it->first;
  }
  
  pt(ans);
}






Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <stdio.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <sstream>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort(ALL(x))
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

const int lim = 100100;
// using edge = struct{int to; int col;};
VI G[lim];
int d[2][lim], id;

void dfs(int c, int p = -1){
  // if(~p) d[id][c] = d[id][p] + 1;
  d[id][c] = d[id][p] + 1;
  for(auto &to : G[c]){
    if(to != p) dfs(to, c);
  }
}

signed main(){
  int n; cin>>n;
  rep(i,n-1){
    int a,b; cin>>a>>b; a--; b--;
    // G[a].PB({b,-1}); G[b].PB({a,-1});
    G[a].PB(b); G[b].PB(a);
  }
  id = 0; dfs(0);
  id = 1; dfs(n-1);

  int ans = 0;
  rep(i,n){
    if(d[0][i] <= d[1][i]) ans++;
    else ans--;
  }
  if(ans>0) cout << "Fennec" << endl;
  else cout << "Snuke" << endl;

  return 0;
}


Measured memory_bytes: 11264
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

const mod = 1000000007

// 1MB
const ioBufferSize = 1 * 1024 * 1024

var sc = func() *bufio.Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Buffer(make([]byte, ioBufferSize), ioBufferSize)
	sc.Split(bufio.ScanWords)
	return sc
}()

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	n := nextInt()
	a := make([]int, n)

	for i := 0; i < n; i++ {
		a[i] = nextInt()
	}

	c := 0
	for {
		for i := 0; i < n; i++ {
			if a[i]%2 == 1 {
				fmt.Println(c)
				return
			}
			a[i] /= 2
		}
		c++
	}
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin >> s;
    map<char, int> mmp;
    for(int i = 0; i < 3; ++i)
        mmp[s[i]]++;
    if(mmp['A'] == 2 || mmp['B'] == 2) puts("Yes");
    else puts("No");

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <vector>
#include <cstring>
#include <algorithm> // sort
#include <map> // sort

#define REP(i, n) for (long long i = 0; i < (n); i++) 
typedef long long ll;
static const ll MOD = 10007;
using namespace std;

int main(){
    int N,M;
    cin >> N >> M;
    string a[N],b[M];
    for(int i = 0; i < N; ++i)cin >> a[i];
    for(int i = 0; i < M; ++i)cin >> b[i];
    string res = "No";

    //BがAに含まれているか
    //各点からはじめて、完全一致をみるしかない気がする
    //N<=50だから可能

    for(int i = 0; i < N; ++i)
    {
        if(i + M > N)break;
        for(int j = 0; j < N; ++j)
        {
            //幅が足りなかったらbreak;
            if(j + M > N)break;
            bool flg = true;
            //開始位置(i,j)
            //終了位置は、(i + M-1, j + M-1)となるはず
            for(int y = i; y < i + M; ++y)
            {
                for(int x = j; x < j + M; ++x)
                {
                    if(a[y][x] != b[y - i][x - j])
                    {
                        flg = false;
                        break;
                    }
                }
            }
            if(flg)
            {
                res = "Yes";
                cout << res << endl;
                return 0;
            }
        }
    }
    cout << res << endl;
    return 0;    
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep_inv(i, n, m) for(int i = (int)(n); i > (int)(m); i--)
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vl>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;

int main(){
  ll N, A;
  cin >> N >> A;
  vl x(N);
  rep(i, N){
    cin >> x[i];
  }

  vector<vector<vector<ll> > > dp(50, vvl(51, vl(2501, 0)));
  ll sum = 0;
  dp[0][0][0] = 1;
  dp[0][1][x[0]] = 1;
  
  rep(i, N - 1){
    sum += x[i];
    
    rep(j, i + 2){
      rep(k, sum + 1){
		dp[i + 1][j + 1][k + x[i + 1]] += dp[i][j][k];
		dp[i + 1][j][k] += dp[i][j][k];
      }
    }
  }

  ll ans = 0;

  rep2(i, 1, N + 1){
    ans += dp[N-1][i][i * A];
  }

  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 51200
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(int i=0;i<N;++i)
typedef long long int LL;

int main()
{
	LL N;
	in >> N;
	std::vector<long double>a(N);
	rep(i, N) in >> a[i];

	long double ans = 0;
	std::sort(a.begin(), a.end());
	rep(i, N)
	{
		for (int j = i + 1; j < N; ++j)
		{
			long double m = a[j] - a[i], u1 = 0, u2 = 0;
			for (int k = N - 1; k >= 0; --k)
			{
				if (k != i && k != j)
				{
					if (u1 == 0) u1 = a[k];
					else if (u2 == 0)
					{
						u2 = a[k];
						break;
					}
				}
			}
			ans = std::max(ans, (u1 + u2) / m);
		}
	}

	out << std::fixed << std::setprecision(6);
	out << ans << std::endl;
}


Measured memory_bytes: 3288
#include<bits/stdc++.h>
using namespace std;
const int N=200002;
#define int long long
struct node{
	int x,y,w;
	bool operator<(node a)const{return w<a.w;}
}e[N<<3];
int cnt,i,fa[N],n,q,d[N],a,b,c,ans,rx,ry,j;
int find(int x) {return x == fa[x] ? x : fa[x]=find(fa[x]);}
signed main() {
	scanf("%lld%lld",&n,&q);
	memset(d,63,sizeof(d));
	for (i=1;i<= q;++i) {
		scanf("%lld%lld%lld",&a,&b,&c);
		e[++cnt]={a,b,c};
		d[a]=min(d[a],c+1);
		d[b]=min(d[b],c+2);
	}
	for (j=0;j<2;j++)
		for (i=0;i<n;++i)d[i]=min(d[i],d[(i-1+n)%n]+2);
	for (i=0;i<=n;++i) e[++cnt]={i,(i+1)%n,d[i]};
	sort(e+1,e+1+cnt);
	for (i=1;i<n;++i) fa[i]=i;
	for (i=1;i<=cnt;++i){
		rx=find(e[i].x),ry=find(e[i].y);
		if(rx!=ry) fa[rx]=ry,ans+=e[i].w;
	}
	printf("%lld",ans);
}

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

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int n; cin >> n;
	vector<double> x(n),y(n);
	for(int i=0;i<n;i++){
		cin >> x[i];
	}
	double sum=0;
	for(int i=0;i<n;i++){
		cin >> y[i];
		sum+=abs(x[i]-y[i]);
	}
	printf("%.8f\n",sum);
	sum=0;
	for(int i=0;i<n;i++){
		sum+=(x[i]-y[i])*(x[i]-y[i]);
	}
	printf("%.8f\n",sqrt(sum));
	sum=0;
	for(int i=0;i<n;i++){
		sum+=(abs(x[i]-y[i]))*(x[i]-y[i])*(x[i]-y[i]);
	}
	printf("%.8f\n",pow(sum,1.0/3.0));
	double ma=0;
	for(int i=0;i<n;i++){
		ma=max(ma,abs(x[i]-y[i]));
	}
	printf("%.8f\n",ma );
}


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

int main(void){
	char str[11], *p, *q;
	int s,i,count=0;

	cin >> str;
	s = strlen(str)/2;
	
	if(strlen(str)%2 && (str[s] == '(' || str[s] == ')')) count ++;
//	cout <<s;
	p = str;
	q = str+strlen(str)-1;
	for(;p<q; p++,q--){
		if((*p == 'i' && *q == 'i') ||
		   (*p == 'w' && *q == 'w') ||
		   (*p == '(' && *q == ')') ||
		   (*p == ')' && *q == '(')) continue;
		 count++;
	}
	
	cout << count << endl;
}

Measured memory_bytes: 0
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int map[][] = new int[2][N];
        for(int i = 0; i < 2; i++){
            for(int j = 0; j < N; j++){
                map[i][j] = sc.nextInt();
            }
        }
        
        int max = 0;
        for(int i = 0; i < N; i++){
            int down = 0, sum = 0;
            for(int j = 0; j < N-1; j++){
                if(i == j)
                    down = 1;
                sum += map[down][j+1-down];
            }
            max = sum > max ? sum : max;
        }
        max += map[0][0] + map[1][N-1];
        
        System.out.println(max);
    }
    
}

Measured memory_bytes: 21844
using System;

namespace B
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var input = Console.ReadLine().Split(' ');

            var ans = 0;
            for (var i = 1; i <= n; i++)
            {
                var a = int.Parse(input[i - 1]);

                if (i % 2 != 0 && a % 2 != 0)
                {
                    ans++;
                }
            }
            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 17860
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <deque>
#include <stack>
#include <map>
const int MOD = 1e9+7;
const int MOOD = 998244353;
#define PI 3.14159265359
typedef long long ll;
using namespace std;

ll dp[3000][3001];


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

	dp[0][0] = 2;	
	dp[0][a[0]] = 1;

	for (int i = 1; i < n; i++){
		for (int j = 0; j <= s; j++){
			if (dp[i-1][j] != 0){
				if (j + a[i] <= s){
					dp[i][j+a[i]] += dp[i-1][j];
					dp[i][j+a[i]] %= MOOD;
				}
				dp[i][j] += dp[i-1][j]*2;
				dp[i][j] %= MOOD;
			}
		}
	}
	cout << dp[n-1][s] << endl;
	return 0;
}

Measured memory_bytes: 73908
def factorial(n, mod):
    fac = [0] * (n + 1)
    inv = [0] * (n + 1)
    fac[0], inv[0] = 1, 1
    for i in range(1, n + 1):
        fac[i] = fac[i-1] * i % mod
        inv[i] = inverse(fac[i], mod)
    return fac, inv

def inverse(a, mod):
    a %= mod # 除数が正なら正になる
    p = mod
    x, y = 0, 1
    while a > 0:
        n = p // a
        p, a = a, p % a, 
        x, y = y, x - n * y
    return x % mod # 除数が正なら正になる

mod = 1000000007
n, k = map(int, input().split())
        
nodes = [[] for _ in range(n)]

branch_n = [0] * n
for i in range(n-1):
    a, b = map(lambda x : int(x) - 1, input().split())
    nodes[a].append(b)
    nodes[b].append(a)

if len(nodes[0]) >= k:
    print(0)
    quit()
stack = nodes[0][:]
visited = {0}
fac, inv = factorial(k, mod)
ans = fac[k] * inv[k-len(nodes[0])-1] % mod
while stack:
    i = stack.pop()
    visited.add(i)
    m = len(nodes[i])
    if m >= k:
        print(0)
        quit()
    ans = ans * fac[k-2] % mod * inv[k-1-m] % mod
    for j in nodes[i]:
        if not j in visited:
            stack.append(j)
print(ans)

Measured memory_bytes: 117092
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline int rd_int(void){
  int x;
  rd(x);
  return x;
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(const char c[]){
  int i=0;
  for(i=0;c[i]!='\0';i++){
    putchar_unlocked(c[i]);
  }
}
int main(){
  int Lj4PdHRW;
  int res = 0;
  int KL2GvlyY = rd_int();
  for(Lj4PdHRW=(0);Lj4PdHRW<(KL2GvlyY);Lj4PdHRW++){
    if(rd_int()%2){
      res ^= 1;
    }
  }
  if(res){
    wt_L("NO");
    wt_L('\n');
  }
  else{
    wt_L("YES");
    wt_L('\n');
  }
  return 0;
}
// cLay varsion 20191125-1

// --- original code ---
// {
//   int res = 0;
//   REP(rd_int()) if(rd_int()%2) res ^= 1;
//   wt(if[res, "NO", "YES"]);
// }


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

int main() {
  long long x;
  cin >> x;
  long long ans = x/11 * 2;
  int r = x%11;
  if(r>6) ans += 2;
  else if(r>0)ans += 1;
  
  
  cout << ans << endl;
}


Measured memory_bytes: 256
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define ll long long
#define INF 1000000000000000000
#define INT_MAX 2147483647

#include <iostream>
#include <vector>
#include <cmath>
#include <numeric>

using namespace std;

int main(){
    vector<ll> d(5);
    vector<ll> p(5);
    ll ans;
    ll N;

    cin >> N;
    REP(i,5){
        cin >> d[i];
    }
    SORT(d);
    if(d[0]>N){
        cout << "5" <<endl;
    }else{
        if(N%d[0]==0){
            cout << N/d[0]+4 << endl;
        }else{
            cout << N/d[0]+5 << endl;
        }
    }
    return 0;   
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(300000)

YES = "YES"  # type: str
NO = "NO"  # type: str

def solve(A: str, B: str, C: str):
    ret = NO
    if A[-1] == B[0] and B[-1] == C[0]:
        ret = YES
    print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = next(tokens)  # type: str
    B = next(tokens)  # type: str
    C = next(tokens)  # type: str
    solve(A, B, C)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064