akhauriyash/Code-Regression huggingface dataset:
require 'pp'

# 空白区切の入力値を数値の配列で返却する
def gets_i_list()
  gets.chomp.split(" ").map(&:to_i)
end

# https://qiita.com/jkr_2255/items/3c9bc8273da818a39810
def combi(n,k)
  k=n-k if 2*k > n
  return 1 if k == 0
  ((n-k+1)..n).reduce(&:*)/((1..k).reduce(&:*))
end

N, A, B = gets_i_list
size = B - A + 1

if A > B
  puts 0
elsif N == 1
  puts 0 if A != B
  puts 1 if A == B
else
  # min = A * (N - 1) + B
  # max = A + B * (N - 1)
  # puts max - min + 1
  puts (B - A) * (N - 2) + 1
end

# if nums.empty?
#   puts 0
# elsif nums.size > N
#   puts 0
# elsif N == 1
#   puts 1
# elsif N == 2 && nums.size == 2
#   puts 1
# else
#   min = A * (N - 1) + B
#   max = A + B * (N - 1)
#   puts max - min + 1
# end


Measured memory_bytes: 2044
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

int main()
{
	int n;
	cin >> n;
	vector<string> S(n);
	for (auto &S_i : S) cin >> S_i;

	string ans = "";
	for (char c = 'a'; c <= 'z'; ++c) {
		int num = 99999;
		for (const auto &s : S) {
			num = min<int>(num, count(s.begin(), s.end(), c));
		}
		ans.insert(ans.end(), num, c);
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

int c[3][3];

int main(int argc, char* argv) {

        for (int i = 0; i < 3; i++) {
                for (int j = 0; j < 3; j++) {
                        scanf("%d", &c[i][j]);
                }
        }

        const int a1 = 0;
        const int b1 = c[0][0] - a1;
        const int b2 = c[0][1] - a1;
        const int b3 = c[0][2] - a1;

        // start search
        const int a2t = c[1][0] - b1;
        const int a3t = c[2][0] - b1;
        if ( (a2t == (c[1][1] - b2)) && (a2t == (c[1][2] - b3))
                && (a3t == (c[2][1] - b2)) && (a3t == (c[2][2] - b3))) {
                printf("Yes\n");
                exit(0);
        }

        printf("No\n");
        return 0;
}


Measured memory_bytes: 128
def main():
    M, D = map(int, input().split())
    ans = 0

    for d in range(22, D + 1):
        d1 = d % 10
        d10 = d // 10

        if d1 < 2 or d10 < 2:
            continue

        if 4 <= d10 * d1 <= M:
            ans += 1

    print(ans)


if __name__ == "__main__":
    main()


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

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef pair<ii, int> ri3;
#define mp make_pair
#define pb push_back
#define fi first
#define sc second
#define SZ(x) (int)(x).size()
#define ALL(x) begin(x), end(x) 
#define REP(i, n) for (int i = 0; i < n; ++i) 
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define RFOR(i, a, b) for (int i = a; i >= b; --i)

int main() {
    //freopen("in.txt", "r", stdin);
    ios::sync_with_stdio(false);
    cin.tie(0);

    int N; string S; cin >> N >> S;
    unordered_set<string> st;
    for (char c : S) {
        string x = ""; x += c;
        vector<string> vv;
        for (auto d : st) if (d.length() < 3) vv.push_back(d+c);
        for (auto d : vv) st.insert(d);
        st.insert(x);
    }
    int ans = 0;
    for (auto d : st) if (d.length() == 3) ++ans;
    cout << ans;
}



Measured memory_bytes: 384
N,K=list(map(int,input().split()))
per=[1/N]*N
count=0
for i in range(0,min(K-1,N)):
    per[i]=i+1
for i in range(0,min(K-1,N)):
    while True:
        count+=1
        per[i]*=2
        if per[i]>=K:
            per[i]=(1/N)*((1/2)**count)
            count=0
            break
print(sum(per))

Measured memory_bytes: 3828
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using boost::multiprecision::cpp_int;
using namespace std;

#if __has_include("print.hpp")
  #include "print.hpp"
#endif

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MOD 1000000007

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 ll;
typedef pair<ll, ll> p;


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n, m;
  cin >> n >> m;

  ll maxv = 1;
  if(n == 1){
    cout << m << endl;
    return 0;
  }
  for (ll i = 2; ; ++i) {
    ll tmp = (n-1) * i;
    ll rem = m - tmp;
    if(rem < i) break;
    if(rem % i == 0) chmax(maxv, i);
  }
  cout << maxv << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string.h>
#include <stdlib.h>
#include <iomanip>
#include <limits>
using namespace std;

int N;
int x[10], y[10];

double dist(int i, int j){
    double dx = x[i] - x[j];
    double dy = y[i] - y[j];
    return pow(dx*dx + dy*dy, 0.5);
}

void solve(){

    cin >> N;
    for(int i = 1; i <= N; i++) cin >> x[i] >> y[i];

    double sum = 0.;
    vector<int> v(N);

    for(int i = 0 ; i < N ; i++) v[i] = i + 1;

    do{
        for(int i = 0 ; i < N - 1 ; i++) sum += dist(v[i], v[i+1]);
    } while( next_permutation(v.begin(), v.end()) );

    int Factorial = 1;
    for(int i = 2 ; i <= N ; i++) Factorial *= i;

    cout << fixed << setprecision(10) << sum/Factorial << endl;
    // cout << sum/Factorial << endl;
    return;

}

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

Measured memory_bytes: 384
n, m = gets.split.map &:to_i
g = Array.new(n) {[]} #隣接リストのグラフ
m.times do
  u, v = gets.split.map(&:to_i).map(&:pred)
  g[u].push(v)
end
s, t = gets.split.map(&:to_i).map(&:pred)

dist = Array.new(n) {Array.new(3)} # nilで初期化
dist[s][0] = 0
q = [[s, 0]]
while q.size > 0
  u, v = q.shift
  nl = (v + 1) % 3
  g[u].each do |e|
    unless dist[e][nl]
      dist[e][nl] = dist[u][v] + 1
      q.push([e, nl])
    end
  end
end
ans = dist[t][0] || -3
puts ans / 3

Measured memory_bytes: 15996
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int N=sc.nextInt();
        int Y=sc.nextInt();
        int x=-1;
        int y=-1;
        int z=-1;
        Out:
        for(int i=0;i<=N;i++){
            for(int j=0;j<=N-i;j++){
                int k=N-i-j;
                if((10000*i+5000*j+1000*k) == Y){
                    x=i;
                    y=j;
                    z=k;
                    break Out;
                }
            }
        }
        System.out.println(x+" "+y+" "+z);
    }
}

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

H = list(map(int, input().split()))

# print(N, H)

counter = 0
answer = []
for i in range(N):
    try:
        if H[i] >= H[i + 1]:
            counter += 1
        else:
            answer.append(counter)
            counter = 0
    except:
        pass
answer.append(counter)

print(max(answer))

Measured memory_bytes: 15020
#include <bits/stdc++.h>
 
using namespace std;
typedef long long int lli;
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef pair <lli,lli> pii;
#define ff first
#define ss second
#define MOD 1000000007
#define pb push_back
 
int main(){
	fast;
	string s;
	cin>>s;
	string ans="Yes";
	if(s.size()%2 ==0){
	for(int i=0; i<s.size(); i+=2){
	    if(s[i]=='h' && s[i+1]=='i') continue;
	    else{
	        ans="No";
	        break;
	    }
	}}
	else ans="No";
	cout<<ans<<"\n";
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){

int a, b;

scanf("%d%d",&a,&b);

int ans=0;

if(a>=b){
    ans=ans+a;
    a--;

}else{
    ans=ans+b;
    b--;
}

if(a>=b){
    ans=ans+a;
    a--;

}else{
    ans=ans+b;
    b--;
}

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


return 0;

}

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

#define ll long long
#define debug(x) cerr << fixed << #x << " is " << x << endl;

const int MAX = 1000;
const int MOD = 1000000007;
vector<int> primes;

int E(int n, int p)
{
	int sum = 0;
	for(int i = p; n / i != 0; i *= p)
		sum += n / i;
	return sum;
}

void crivo()
{
	bitset<MAX+1> sieve;
	sieve.set();
	for(int i = 2; i < MAX; i++)
	{
		if(sieve[i])
		{
			primes.push_back(i);
			for(int j = 2*i; j < MAX; j += i)
				sieve[j] = 0;
		}
	}
}


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

	crivo();
	int n, ans = 1;
	cin >> n;
	for(auto i : primes)
	{
		if(i > n)
			break;
		ans = (ll) ans * (E(n, i) + 1) % MOD;
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#ifndef LOCAL
#pragma GCC optimize ("O3")
#endif
#include <bits/stdc++.h>
using namespace std;
#define sim template < class c
#define ris return * this
#define mor > muu & operator << (
#define R22(r) sim > typename \
  enable_if<1 r sizeof dud<c>(0), muu&>::type operator<<(c g) {
sim > struct rge { c b, e; };
sim > rge<c> range(c h, c n) { return {h, n}; }
sim > auto dud(c* r) -> decltype(cerr << *r);
sim > char dud(...);
struct muu {
#ifdef LOCAL
stringstream a;
~muu() { cerr << a.str() << endl; }
R22(<) a << boolalpha << g; ris; }
R22(==) ris << range(begin(g), end(g)); }
sim, class b mor pair < b, c > r) { ris << "(" << r.first << ", " << r.second << ")"; }
sim mor rge<c> u) {
  a << "[";
  for (c i = u.b; i != u.e; ++i)
    *this << ", " + 2 * (i == u.b) << *i;
  ris << "]";
}
#else
sim mor const c&) { ris; }
#endif
muu & operator()() { ris; }
};
#define imie(r...) "[" #r ": " << (r) << "] "
#define imask(r...) "[" #r ": " << bitset<8 * sizeof(r)>(r) << "] "
#define arr(a, i) "[" #a imie(i) ": " << a[i] << "] "
#define arr2(a, i, j) "[" #a imie(i) imie(j) ": " << a[i][j] << "] "
#define debug (muu() << __FUNCTION__ << "#" << __LINE__ << ": ")

const int N = 1e5 + 7;
int n, k;
int a[107];
int dp[N];

int main() {
    scanf("%d %d", &n, &k);
    for (int i = 1; i <= n; ++i) scanf("%d", a + i);
    dp[0] = 0;
    for (int i = 1; i <= k; ++i) {
        for (int j = 1; j <= n; ++j) if (i >= a[j] && !dp[i - a[j]]) dp[i] = 1;
    }
    
    if (dp[k]) printf("First\n");
    else printf("Second\n");
    return 0;
}


Measured memory_bytes: 640
readline = open(0).readline
writelines = open(1, 'w').writelines

Q = int(readline())
root = [None, None, None]
cursor = root[1] = [root, None, None]
def insert(x):
    global cursor
    cursor[0][1] = cursor[0] = cursor = [cursor[0], cursor, x]
def move(d):
    global cursor
    if d > 0:
        for _ in range(d):
            cursor = cursor[1]
    else:
        for _ in range(-d):
            cursor = cursor[0]
def erase():
    global cursor
    cursor[1][0] = cursor[0]
    cursor[0][1] = cursor = cursor[1]


C = [insert, move, erase].__getitem__
for q in range(Q):
    t, *a = map(int, readline().split())
    C(t)(*a)
root = root[1]
ans = []
while root[1]:
    ans.append("%d\n" % root[2])
    root = root[1]
writelines(ans)



Measured memory_bytes: 80948
#include <iostream>
using namespace std;
int main(void){
  int N;
  cin >> N;
  while(N >= 1000){
    N = N - 1000;
  }
  if(N == 0)
    cout << N << endl;
  else{
    N = 1000 - N;
    cout << N << endl;
  }
  return 0;
}

Measured memory_bytes: 3188
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace _0258
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                int n = RInt();
                if (n == 0) break;

                int[] vs = RArInt();
                List<int>[] cand = new List<int>[vs.Length];
                for (int i = 0; i < cand.Length; i++) cand[i] = new List<int>();

                for (int i = 0; i < vs.Length; i++)
                {
                    for (int j = 0; j < vs.Length; j++)
                    {
                        if (i != j) cand[i].Add(vs[j]);
                    }
                }

                for (int i = 0; i < cand.Length; i++)
                {
                    int diff = cand[i].Take(cand[i].Count() - 1).Select((x, idx) => cand[i][idx + 1] - cand[i][idx]).Distinct().Count();
                    if (diff == 1)
                    {
                        Console.WriteLine(vs[i]);
                        break;
                    }
                }
            }
        }
        static string RSt() { return Console.ReadLine(); }
        static int RInt() { return int.Parse(Console.ReadLine().Trim()); }
        static long RLong() { return long.Parse(Console.ReadLine().Trim()); }
        static double RDouble() { return double.Parse(Console.ReadLine()); }
        static string[] RArSt(char sep = ' ') { return Console.ReadLine().Trim().Split(sep); }
        static int[] RArInt(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => int.Parse(e)); }
        static long[] RArLong(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => long.Parse(e)); }
        static double[] RArDouble(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => double.Parse(e)); }
        static string WAr<T>(IEnumerable<T> array, string sep = " ") { return string.Join(sep, array.Select(x => x.ToString()).ToArray()); }
    }
}



Measured memory_bytes: 22728
n = int(input())
s = input()
t = input()
cou = 0
for i in range(n):
  s1 = s[i:]
  t1 = t[:n-i]
#  print(s1,t1)
  if s1==t1:
    print(2*n-(n-i))
    exit()
else:
  print(2*n)


Measured memory_bytes: 9048
import java.util.*;
 
public class Main {
	
    public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	int N = sc.nextInt();
    	int K = sc.nextInt();
    	int[] hi = new int[N];
    	for (int i = 0; i < N; i++) {
    		hi[i] = sc.nextInt();
    	}
    	Arrays.sort(hi);
    	int high = hi[K-1] - hi[0];
    	int min = high;
    	for (int i = K; i < N; i++) {
    		high = hi[i] - hi[i-K+1];
    		if (high < min) {
    			min = high;
    		}
    	}
    	System.out.println(min);
    }
}

Measured memory_bytes: 50816
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define repr(i,x,n) for(int i=x; i<(n); i++)
#define ALL(x) (x).begin(),(x).end()
#define INF 1e9
typedef long long ll;
using VI = vector<int>;
using VB = vector<bool>;
using VS = vector<string>;
using graph = vector<vector<int>>;

int main()
{
int x; cin>>x;
    cout<<10-x/200<<endl;
    return 0;
}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N,Q,l,r,count=0;string S;cin>>N>>Q>>S;
  vector<int> a(N);
  for(int i=0;i<N-1;i++){
    if(S.at(i)=='A' && S.at(i+1)=='C')count++;
    a.at(i)=count;
  }
  for(int i=0;i<Q;i++){
    cin>>l>>r;
    if(l<2)cout<<a.at(r-2)<<endl;
    else cout<<a.at(r-2)-a.at(l-2)<<endl;
  }
}

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

int N,M;
int a,b;
int V[100010] = {0};

int main(){
	cin >> N >> M;
	for(int i=0;i<M;i++){
		cin >> a >> b;
		V[a]++;
		V[b]++;
	}
	bool judge = true;
	for(int i=1;i<=N;i++){
		if(V[i]%2!=0) judge = false;
	}
	if(judge) cout << "YES" << endl;
	else cout << "NO" << endl;
}

Measured memory_bytes: 640
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <math.h>
#include <climits>
#include <algorithm>
#include <functional>
#include <vector>
#include <queue>
#include <map> 
#include <set>
#include <string>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
const ll MD = 1000000007;

/* sample input

*/

int main()
{
	int h, w,d;
	cin >> h >> w >> d;

	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {

			int posx, posy;
			int x = i + j;
			int y = -j + i + w;
			posx = x/d % 2;
			posy = y/d % 2;

			char color[2][2];
			color[0][0] = 'R';
			color[0][1] = 'Y';
			color[1][0] = 'G';
			color[1][1] = 'B';

			cout << color[posx][posy];

			if (j == w - 1) {
				cout << endl;
			}
		}
	}

	return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define pi 3.141592653589793
using namespace std;
double a,b,h,c;
int main(){
	cin>>a>>b>>h;
	c=h*2.0/(b*a);
	if(c<a){
		printf("%.12lf",atan(b/c)*180/pi);
		return 0;
	}else{
		double d=(h*2.0-a*a*b)/(a*a);
		b-=d;
		printf("%.12lf",atan(b/a)*180/pi);
		return 0;
	}
	return 0;
}

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

using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int x, n;
    int min = std::numeric_limits<int>::max();
    int max = std::numeric_limits<int>::min();
    long long sum = 0;
    cin>>n;
    for(int i=0; i<n; i++) {
        cin>>x;
        min = std::min(min, x);
        max = std::max(max, x);
        sum+=x;
    }
    cout<<min<<' '<<max<<' '<<sum<<'\n';
    return 0;
}

Measured memory_bytes: 1196
#include<stdio.h>

int convert(char *s)
{
	int n=10000000;
	int i,num=0;
	for(i=0;i<8;i++)
	{
		num+=(int)(*(s+i)-'0')*n;
		n/=10;
	}
	return num;
}

void sort(char *data,int muki)
{
	int i,j;
	char tmp;

	for(i=0;i<7;i++)
	{
		for(j=i+1;j>0;j--)
		{
			if(muki==1)
			{
				if(*(data+j)<*(data+j-1))
				{
					tmp=*(data+j);
					*(data+j)=*(data+j-1);
					*(data+j-1)=tmp;
				}
			}
			else if(muki==-1)
			{
				if(*(data+j)>*(data+j-1))
				{
					tmp=*(data+j);
					*(data+j)=*(data+j-1);
					*(data+j-1)=tmp;
				}
			}
		}
	}
}

int main()
{
	char str[9];
	int max,min,diff,n,i;

	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%s",str);
		sort(str,-1);
		max=convert(str);
		sort(str,1);
		min=convert(str);
		diff=max-min;
		printf("%d\n",diff);
	}
	return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<stdlib.h>

using namespace std;


int main() {
	int N, K, C;
	string S;
	cin >> N >> K >> C;
	cin >> S;
	vector<int>front, back;
	for (int i = 0; i < N; i++) {
		if (front.size() == K)break;
		if (S[i] == 'o') {
			front.push_back(i);
			i += C;
		}
	}
	for (int i = N - 1; i >= 0; i--) {
		if (back.size() == K)break;
		if (S[i] == 'o') {
			back.push_back(i);
			i -= C;
		}
	}
	int MAX = min(front.size(), back.size());
	if (MAX <= K) {
		for (int i = 0; i < MAX; i++) {
			if (front[i] == back[back.size()-i-1]) {
				cout << front[i] + 1 << endl;
			}
		}
	}
	return 0;
}

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

using namespace std;

int n,m,d;
int fa[55];
long long dp[51][125500],val[55],sz[55];
long long pre[55],pre2[55];
int id[55];

bool cmp(int a,int b)
{
	return sz[a] * val[b] > sz[b] * val[a];
}

int main()
{
	scanf("%d%d%d",&n,&m,&d);
	scanf("%lld",&val[1]); sz[1] = 1;
	for(int i = 2;i <= n; ++ i)
		scanf("%lld%d",&val[i],&fa[i]),sz[i] = 1;
	for(int i = n;i >= 2; -- i)
		sz[fa[i]] += sz[i],val[fa[i]] += val[i];
	memset(dp,0x3f3f3f3f,sizeof(dp));
	dp[0][0] = 0;
	int lim = min(d,n);
	for(int i = 1;i <= n; ++ i)
	{
		id[i] = i;
		for(int j = 0;j <= (i - 1) * lim * n; ++ j)
			if(dp[i - 1][j] <= m)
			{
				for(int k = 0;k <= lim; ++ k)
				{
					dp[i][j + k * sz[i]] = min(dp[i][j + k * sz[i]],dp[i - 1][j] + val[i] * k);
					if(dp[i][j + k * sz[i]] > m) break;
				}
			}
	}
	sort(id + 1,id + 1 + n,cmp);
	for(int i = 1;i <= n; ++ i)
	{
		if(pre[i - 1] >= m)
		{
			pre[i] = pre[i - 1] + 1;
			continue;
		}
		int fuck = id[i];
		int tmp = fuck == 1 ? 1e9 : d - lim;
		if(val[fuck] >= m && tmp)
			pre[i] = m;
		else
			pre[i] = pre[i - 1] + tmp * val[fuck],
			pre2[i] = pre2[i - 1] + tmp * sz[fuck];
	}
	long long ans = 0;
	for(int i = 0;i <= n * n * lim; ++ i)
		if(dp[n][i] <= m)
		{
			long long fuck = m - dp[n][i];
			int pos = upper_bound(pre + 1,pre + 1 + n,fuck) - pre - 1;
			ans = max(ans,i + pre2[pos] + sz[id[pos + 1]] * ((fuck - pre[pos]) / val[id[pos + 1]]));
		}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 50304
// WeirdBugsButOkay

#include <bits/stdc++.h>

#define ll long long
#define ld long double
#define pii pair <int, int>
#define pll pair <ll, ll>
#define mp make_pair
#define pb push_back
#define ff first
#define ss second

using namespace std;

ll n, m, q;
vector <ll> a, b, c, d;
ll ans;
vector <ll> cur;

void solve(ll i)
{
    if(i == n)
    {
        //for(auto j : cur)
            //cout << j << " ";
        //cout << endl;
        ll tans = 0;
        for(ll i = 0; i < q; i++)
            if(cur[b[i] - 1] - cur[a[i] - 1] == c[i])
                tans += d[i];
        ans = max(ans, tans);
    }
    else
    {
        for(ll j = cur.back(); j <= m; j++)
        {
            cur.pb(j);
            solve(i + 1);
        }
    }
    cur.pop_back();
}

void solve()
{
    cin >> n >> m >> q;
    a.resize(q);
    b.resize(q);
    c.resize(q);
    d.resize(q);
    for(ll i = 0; i < q; i++)
        cin >> a[i] >> b[i] >> c[i] >> d[i];
    for(ll i = 1; i <= m; i++)
    {
        cur.pb(i);
        solve(1);
    }
    cout << ans << endl;
}

int main()
{
    ios_base :: sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int q = 1;
    //cin >> q;
    for(int i = 1; i <= q; i++)
    {
    	solve();
    }
    return 0;
}

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

int main(){
    int h;
    cin >> h;
    vector<int> heap(h + 1);
    for (int i = 1; i <= h; i++)
        cin >> heap[i];
    for (int i = 1; i <= h; i++){
        cout << "node " << i << ": key = ";
        cout << heap[i] << ", ";
        if (i / 2)
            cout << "parent key = " << heap[i / 2] << ", ";
        if (i * 2 <= h)
            cout << "left key = " << heap[i * 2] << ", ";
        if (i * 2 + 1 <= h)
            cout << "right key = " << heap[i * 2 + 1] << ", ";
        cout << endl;
    }   
}


Measured memory_bytes: 3084
#include <stdio.h>

int main()
{
  int n,T;
  int c,t;
  int ans=10000;
  
  scanf("%d%d",&n,&T);
  for(int i=0;i<n;++i){
    scanf("%d%d",&c,&t);
    if(t<=T&&c<ans){
      ans=c;
    }
  }
  
  if(ans==10000)printf("TLE");
  else printf("%d",ans);
  
  return 0;
}

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


uint64_t N;
uint64_t mindist = UINT64_MAX;
int main() {
  ios::sync_with_stdio(false);
  cin >> N;
  for(uint64_t i = 1; i <= sqrt(N); ++i) {
    if((N % i) == 0 && (i + N/i -2) < mindist) {
      mindist = i + N/i -2;
    }
  }
  cout << mindist;


  return 0;
}


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

start = 0
cnt = 0
for i in range(1, N+1):
  try:
    start = a.index(i, start)
  except:
    break
  else:
    cnt += 1

if cnt == 0:
  print(-1)
else:
  print(N - cnt)

Measured memory_bytes: 77516
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    ll n;cin>>n;
    long double T,A;cin>>T>>A;
    long double diff = 1e18;
    ll idx=-1;
    for(ll i=0;i<n;i++){
        ll val;cin>>val;
        long double cur = T - val*0.006;
        if(abs(cur-A) < diff ) diff=abs(cur-A),idx=i;
    }
    cout<<idx+1;
}


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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;


const ll LongINF=1e13+7;
const int INF=1e9+7;
const int dx[]={0,1,0,-1};
const int dy[]={1,0,-1,0};

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;}
template <class T, class Y>T GCD(T a, Y b){if(a<b){int c=a;a=b;b=c;}if (a % b == 0){return b;}return GCD(b, a % b);}
void clear(queue<pair<int, int>> &q){queue<pair<int, int>> empty;swap(q, empty);} //queueの中身の型は適時変更を忘れない

#define REP(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define rv reverse
#define ALL(a) (a).begin(),(a).end()


int main(){
    ll N,i=1;
    cin>>N;
    while(true){
        if(i*i<=N&&N<(i+1)*(i+1)){
            cout<<i*i<<endl;
            break;
        }
        i++;
    }
    return 0;
}

//a=97,z=122

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
int main(){
  ll N;
  cin>>N;
  vector<ll>d(N);
  for(ll i=0;i<N;i++)cin>>d[i];
  sort(d.begin(),d.end());
  cout<<d[N/2]-d[N/2-1]<<endl;
}

Measured memory_bytes: 4028
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
#include <vector>
#include <cstdlib>
#include <map>
#include <queue>
#include <deque>
#include <algorithm>
#include <stack>
#include <functional>
#include <sstream>
#define rep(i,j,n) for(i=j;i<(n);i++)
#define rrep(i,j,n) for(i=j;i>(n);i--)
typedef long long int lli;
#define N 1000000007
#define M 998244353

using namespace std;

int main(){
    lli n,a,b,x,cost=0;
    vector<lli> vec;
    lli i,j;
    cin>>n>>a>>b;
    rep(i,0,n){
        cin>>x;
        vec.push_back(x);
        if(i>0){
            cost+=min((vec[i]-vec[i-1])*a,b);
        }
    }
    cout<<cost<<endl;
}


Measured memory_bytes: 1528
using System;
using System.IO;
using System.Linq;

class Solve{
    static void Main(string[] args){
        var arr = Console.ReadLine().Split();
        var M = int.Parse(arr[2]);
        var a = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
        var b = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
        var answer = a.Min() + b.Min();
        for (int i = 0; i < M; i++){
            var xyc = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
            var disctTgt = a[xyc[0] - 1] + b[xyc[1] - 1] - xyc[2];
            answer = disctTgt < answer ? disctTgt : answer;}
        var writer = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
        Console.SetOut(writer);
        Console.WriteLine(answer);
        Console.Out.Flush();}}

Measured memory_bytes: 53332
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <deque>
#include <list>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>

using namespace std;


#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int (i)=(n); (i)>=(0); (i)--)
#define SIZE(x) ((int)(x).size())
#define GCD(a, b) int gcd(int a,int b){return b?gcd(b,a%b):a;}
#define QP(a, b) int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define all(v) (v).begin(),(v).end()


template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
template<typename A, size_t N, typename T>
void FILL(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

typedef vector<int, int> vint;
typedef pair<int,int> pint;
typedef vector<pint>vpint;
typedef long long ll;

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1LL << 60;
const ll MOD = 1000000007LL;


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b; cin >> a >> b;
    if(a > 8 || b > 8) cout << ":(";
    else cout << "Yay!";
    cout << 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++)

void printVector(vector<auto> v)
{
    int n = v.size();
    rep(i, n)
    {
        cout << v[i] << " ";
    }
    cout << endl;
}

int N;
vector<vector<int>> edge;

vector<int> CalculateCost(int s)
{
    int INF = INT32_MAX;
    vector<int> cost(N, INF);

    cost[s] = 0;
    queue<int> pos_queue;
    pos_queue.push(s);

    while (pos_queue.size())
    {
        int pos = pos_queue.front();
        pos_queue.pop();
        rep(i, edge[pos].size())
        {
            int next = edge[pos][i];
            if (cost[next] == INF)
            {
                cost[next] = cost[pos] + 1;
                pos_queue.push(next);
            }
        }
    }
    return cost;
}

int main()
{
    int u, v;
    cin >> N >> u >> v;
    u--;
    v--;
    edge.resize(N);
    rep(i, N - 1)
    {
        int A, B;
        cin >> A >> B;
        A--;
        B--;
        edge[A].push_back(B);
        edge[B].push_back(A);
    }
    vector<int> costT = CalculateCost(u);
    vector<int> costA = CalculateCost(v);
    vector<int> cost(N);

    int ans = 0;
    rep(i, N)
    {
        cost[i] = costA[i] - costT[i];
        if (cost[i] > 0)
            ans = max(ans, costA[i]);
    }
    cout << ans - 1 << endl;

    return 0;
}

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

int main(){
    int N, K;
    cin >> N >> K;
    vector<int> A(N);
    while(K--){
        int sz;
        cin >> sz;
        while(sz--){
            int a;
            cin >> a;
            A[a-1]++;
        }
    }
    int ans = 0;
    for(int a : A) if(a == 0) ans++;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3628
# set building
b_num = 4
f_num = 3
r_num = 10
building = [[[0 for i in range(r_num)] for j in range(f_num)] for k in range(b_num)]

# input
n = int(input())
for _ in range(n):
    b,f,r,v = map(int, input().split())
    building[b-1][f-1][r-1] += v

# output
for b_tmp in range(b_num):
    for f_tmp in range(f_num):
        for r_tmp in range(r_num):
            print(' '+str(building[b_tmp][f_tmp][r_tmp]), end='')
        print('')
    if b_tmp < b_num-1:
        print('#'*20)


Measured memory_bytes: 5628
#include <bits/stdc++.h>
using namespace std;
#define rep(i,ini,n) for(int i=ini;i<n;i++)
#define _rep(i,ini,n) for(int i=ini;i>=n;i--)
#define ToEnd(a) a.begin(),a.end()
uint64_t MOD=1000000007;

int main(){
    int N,K;
    cin>>N>>K;
    
    uint64_t ans=0;
    rep(n,0,N){
        int x; cin>>x;
        ans+=min(x,abs(K-x))*2;
    }

    cout<<ans<<endl;
}

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

using ll=long long;
#define int ll

#define FOR(i,a,b) for(int i=int(a);i<int(b);i++)
#define REP(i,b) FOR(i,0,b)
#define MP make_pair
#define PB push_back
#define ALL(x) x.begin(),x.end()
#define REACH cerr<<"reached line "<<__LINE__<<endl
#define DMP(x) cerr<<"line "<<__LINE__<<" "<<#x<<":"<<x<<endl
#define ZERO(x) memset(x,0,sizeof(x))

using pi=pair<int,int>;
using vi=vector<int>;
using ld=long double;

template<class T,class U>
ostream& operator<<(ostream& os,const pair<T,U>& p){
	os<<"("<<p.first<<","<<p.second<<")";
	return os;
}

template<class T>
ostream& operator <<(ostream& os,const vector<T>& v){
	os<<"[";
	REP(i,(int)v.size()){
		if(i)os<<",";
		os<<v[i];
	}
	os<<"]";
	return os;
}

int read(){
	int i;
	scanf("%lld",&i);
	return i;
}

void printSpace(){
	printf(" ");
}

void printEoln(){
	printf("\n");
}

void print(int x,int suc=1){
	printf("%lld",x);
	if(suc==1)
		printEoln();
	if(suc==2)
		printSpace();
}

string readString(){
	static char buf[3341919];
	scanf("%s",buf);
	return string(buf);
}

char* readCharArray(){
	static char buf[3341919];
	static int bufUsed=0;
	char* ret=buf+bufUsed;
	scanf("%s",ret);
	bufUsed+=strlen(ret)+1;
	return ret;
}

template<class T,class U>
void chmax(T& a,U b){
	if(a<b)
		a=b;
}

template<class T,class U>
void chmin(T& a,U b){
	if(a>b)
		a=b;
}

template<class T>
T Sq(const T& t){
	return t*t;
}

const int inf=LLONG_MAX/3;

signed main(){
	int n=read(),a=read(),b=read();
	if(n==1){
		if(a==b)cout<<1<<endl;
		else cout<<0<<endl;
	}else{
		if(a<=b)cout<<(n-2)*(b-a)+1<<endl;
		else cout<<0<<endl;
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
using namespace std;

void output_array(vector<int> &v)
{
  for (int i = 0; i < v.size(); i++)
    cout << (i ? " " : "") << v[i];
  cout << "\n";
}

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

  double sqrt_num = sqrt(num);
  for (int i = 3; i <= sqrt_num; i += 2)
  {
    if (num % i == 0)
      return false;
  }

  return true;
}

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

  int n;
  cin >> n;

  int res = 0;
  int x;
  for (int i = 0; i < n; i++)
  {
    cin >> x;
    if (is_prime(x))
      res++;
  }

  cout << res << "\n";

  return 0;
}



Measured memory_bytes: 3136
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ll long long
#define lld long double
#ifdef DEBUG
#define line() cout << "[" << __LINE__ << "] ";
#define dump(i) cout << #i ": " << i << " ";
#define dumpl(i) cout << #i ": " << i << endl;
#else
#define line(i)
#define dump(i)
#define dumpl(i)
#endif
using namespace std;

int main(int argc, char const *argv[])
{
    string s;
    cin >> s;
    string ans = "";
    string now = "";

    rep(i, s.size())
    {
        if (s[i] == 'A' || s[i] == 'T' || s[i] == 'C' || s[i] == 'G')
        {
            now += s[i];
        }
        else
        {
            if (now.size() > ans.size())
            {
                ans = now;
            }
            now = "";
        }
    }
    if (now.size() > ans.size())
    {
        ans = now;
    }
    cout << ans.size() << endl;
    return 0;
}


Measured memory_bytes: 256
n,m,c = map(int,input().split())
b = list(map(int,input().split()))
A = [list(map(int,input().split())) for _ in range(n)]
ans = 0
for a in A:
  check = c
  for i,j in zip(a,b):
    check += i*j
  ans += (check > 0)
print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=(ll)1e9+7;


int main(){
    int N; cin>>N;

    vector<string> S(N);
    map<string,ll> mp;
    
    for (int i = 0; i < N; ++i) {
        cin>>S[i];
        sort(S[i].begin(),S[i].end());
        mp[S[i]]++;
    }

    ll ans=0ll;

    for (auto itr=mp.begin();itr!=mp.end();++itr) {
        ll val=itr->second;
        ans+=val*(val-1)/2;
    }

    cout<<ans<<endl;

    return 0;
}

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

using ll = long long int;

const int MAX = (int)(1e5 + 5);
const ll INF = (ll)(1e10 + 5);

const int MAX_H = (int)(1e2 + 5);
const int MAX_W = (int)(1e1 + 5);
const ll MOD = (ll)(1e9 + 7);

int h, w, k;

ll dp[MAX_H][MAX_W];
ll mv[MAX_W][3];
int retain = 0, ls = 1, rs = 2;
bool arr[MAX_W];

ll ans;

bool check() {
  for (int l = 1; l <= w - 1; ++l) {
    if (arr[l] && arr[l + 1]) {
      return false;
    }
  }

  return true;
}

int main(void) {
  // Here your code !
  scanf("%d %d %d", &h, &w, &k);

  arr[0] = false;  // guard

  for (int k = 0; k < 1 << (w - 1); ++k) {
    for (int l = 0; l < w - 1; ++l) {
      arr[l + 1] = (k >> l & 1) ? true : false;
    }

    if (!check()) continue;  // in-valid pattern

    for (int j = 1; j <= w; ++j) {
      if (arr[j]) {
        mv[j][rs] += 1;
      } else if (arr[j - 1]) {
        mv[j][ls] += 1;
      } else {
        mv[j][retain] += 1;
      }
    }
  }

  dp[0][1] = 1LL;

  for (int i = 0; i < h; ++i) {
    for (int j = 1; j <= w; ++j) {
      dp[i + 1][j] += dp[i][j] * mv[j][retain];
      dp[i + 1][j + 1] += dp[i][j] * mv[j][rs];
      dp[i + 1][j - 1] += dp[i][j] * mv[j][ls];

      dp[i + 1][j] %= MOD;
      dp[i + 1][j + 1] %= MOD;
      dp[i + 1][j - 1] %= MOD;
    }
  }

  ans = dp[h][k];

  printf("%lld\n", ans);

  return 0;
}


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

int x[10],y[10];

double dist(int i, int j) {
  double dx = x[i] - x[j];
  double dy = y[i] - y[j];
  return pow(dx*dx+dy*dy,0.5);
}

int main() {
  int n; cin >> n;
  for (int i = 1; i <= n; i++) cin >> x[i] >> y[i];
  std::vector<int> v(n);
  rep(i,n) v[i] = i + 1;
  double sum = 0.0;
  do {
    rep(i,n-1) sum += dist(v[i], v[i+1]);
  } while (next_permutation(v.begin(), v.end()));

  int f = 1;
  for (int i = 2; i <= n; i++) f *= i;
  cout << fixed << setprecision(10) << sum / f << endl;
}


Measured memory_bytes: 4132
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < (b); i++)
#define rrep(i, a, b) for (int i = a; i >= (b); i--)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
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;
}
void hr() {
   cerr << "--------------" << endl;
}
const int INF = 1001001001;
const int MOD = 1000000007;
// const int MOD = 998244353;

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

   int n, m;
   cin >> n >> m;
   vector<int> h(n);
   rep(i, 0, n) cin >> h[i];
   vector<int> ner(n, 0);
   rep(i, 0, m) {
      int a, b;
      cin >> a >> b;
      a--, b--;
      ner[a] = max(h[b], ner[a]);
      ner[b] = max(h[a], ner[b]);
   }
   int ans = 0;
   rep(i, 0, n) {
      if (h[i] > ner[i]) ans++;
   }
   cout << ans << endl;
   return 0;
}

Measured memory_bytes: 3976
////////////////////////////////////////////
///                                      ///
///         Template ver. 1 rapel        ///
/// Fear is Temporary, Regret is Forever ///
///          Must Try and Get AC         ///
///                                      ///
////////////////////////////////////////////
#include <stdio.h>
#include <iostream>
#include <sstream>
#include <iomanip>

#include <algorithm>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <utility>

#include <math.h>
#include <complex>

#include <assert.h>
#include <time.h>
//#include <chrono>
//#include <random>

#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <bitset>

#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define PF push_front
#define POB pop_back
#define POF pop_front
#define endl '\n'
using namespace std;

typedef long long LL;
typedef unsigned long long ULL;

void desperate_optimization(int precision){
  	ios_base::sync_with_stdio(false);
  	cin.tie(0);
  	cout.tie(0);
  	cout.setf(ios::fixed);
  	cout.setf(ios::showpoint);
  	cout.precision(precision);
}

void hora(int tc) {
	int n;
	string s;
	cin>>s;
	n = s.size();
	if(s[0] == '0' || s[n - 1] == '1') {
		cout<<-1<<endl;
		return ;
	}
	for(int i = 0;i < n - 1;i++) {
		if(s[i] != s[n - 2 - i]) {
			cout<<-1<<endl;
			return ;
		}
	}
	cout<<1<<" "<<2<<endl;
	int root = 2;
	for(int i = 2;i < n;i++) {
		cout<<root<<" "<<i + 1<<endl;
		if(s[i - 1] == '1') root = i + 1;
	}
}

int main(){
	desperate_optimization(10);
	int ntc = 1;
	//cin>>ntc;
	for(int tc = 1;tc <= ntc;tc++) hora(tc);
	return 0;
}



Measured memory_bytes: 1616
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (int)(k); i < (int)(n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int MOD = 1000000007;
const int INF = MOD + 1;
const ld EPS = 1e-12;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }

/*--------------------template--------------------*/

int main()
{
	cin.sync_with_stdio(false); cout << fixed << setprecision(10);
	string s;
	cin >> s;
	bool a = false, b = false;
	REP(i, s.size())
	{
		if (s[i] == 'C') a = true;
		if (a && s[i] == 'F') b = true;
	}
	cout << (b ? "Yes" : "No") << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int n;
pair < int, int > a[(1<<20)];
int main () {
    cin >> n;
    for ( int i = 0 ; i < n ; i ++ ) {
        cin >> a[i].first;
        a[i].second = i;
    }
    sort( a, a+n );

    int cnt = 0;
    for ( int i = 0 ; i < n ; i ++ ) {
        if ( i%2 != a[i].second%2 ) { cnt ++; }
    }
    cout << cnt/2 << "\n";
    return 0;
}


Measured memory_bytes: 1152
#include<stdio.h>
main(){
  int n,a,x=100000;
  scanf("%d",&n);
  for(;n>0;n--){
    a=x*0.05;
    x=x+a+999;
    x/=1000;
    x*=1000;
  }
  printf("%d\n",x);
  return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define SZ(x) ((int)(x).size())
#define debug(x) cerr << #x << ": " << x << '\n'
#define INF 999999999
typedef long long int Int;
typedef pair<int,int> P;
using ll = long long;
using VI = vector<int>;
const int MAX = 210;
int N,M,R;
Int dist[MAX][MAX];

int main(){
    cin >> N >> M >> R;
    vector<int> vr;
    rep(i,R){
        int r;cin >> r;r--;
        vr.push_back(r);
    }
    for(int i=0;i<MAX;i++){
        for(int j=0;j<210;j++) dist[i][j] = INF;
        dist[i][i] = 0;
    }
    
    for(int i=0;i<M;i++){
        int a,b,c;cin >> a >> b >> c;
        --a,--b;
        dist[a][b] = c;
        dist[b][a] = c;
    }
    for(int k=0;k<N;k++){
        for(int i=0;i<N;i++){
            for(int j=0;j<N;j++){
                dist[i][j] = min(dist[i][j],dist[i][k]+dist[k][j]);
            }
        }
    }

    Int res = INF;
    sort(vr.begin(),vr.end());
    do{
        Int tmp = 0;
        for(int i=0;i<vr.size()-1;i++) tmp += dist[vr[i]][vr[i+1]];
        res = min(res,tmp);
    }while(next_permutation(vr.begin(),vr.end()));
    cout << res << endl;
}

Measured memory_bytes: 640
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<algorithm>
#include<vector>
#include<string.h>
#include<math.h>
#include<map>
#include<iomanip>
#include<queue>

using namespace std;

const long long mod = 1e9 + 7;
int dp[100100];

int main(){

	cin.tie(0);
	ios::sync_with_stdio(false);
	
	//cout << fixed << setprecision(1) << endl;
	
	memset(dp,0,sizeof(dp));
	
	int n , m;
	cin >> n >> m;
	vector<int> ng(m);
	
	for(int i = 0; i < m; i++){
		cin >> ng[i];
		dp[ng[i]] = -1;
	}
	
	for(int i = n; i >= 0; i--){
		if(i == n){
			dp[i] = 1;
		}
		if(dp[i] == -1)continue;
		if(dp[i + 1] != -1){
			dp[i] += dp[i + 1];
			dp[i] %= mod;
		}
		if(dp[i + 2] != -1){
			dp[i] += dp[i + 2];
			dp[i] %= mod;
		}
	}
	cout << dp[0] << endl;
		
	return 0;
}
 

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

int main(){
  int n;
  cin >> n;
  vector<double> p(n);
  rep(i, n) cin >> p[i];
  vector<vector<double>> dp(n + 1, vector<double>(n + 1));
  dp[0][0] = 1;
  rep(i, n) {
    rep(j, n) {
      dp[i + 1][j] += (1 - p[i]) * dp[i][j];
      dp[i + 1][j + 1] += p[i] * dp[i][j];
    }
  }
  double ans = 0;
  for (int i = (n+1)/2; i <= n; ++i) {
    ans += dp[n][i];
  }
  printf("%.10f\n", ans);
}

Measured memory_bytes: 70656
/*
      author : nishi5451
      created: 11.08.2020 20:34:47
*/

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


int main(){
    int a,b;
    cin >> a >> b;
    if(a<=8 && b<=8) cout << "Yay!" << endl;
    else cout << ":(" << endl;
    return 0;
}

Measured memory_bytes: 3644
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = int64_t;
#define rep(i, j, n) for (int i = j; i < (int)n; ++i)

int main() {
  int n;
  cin >> n;
  vector<ll> h(n);
  rep(i, 0, n) cin >> h[i];
  reverse(h.begin(), h.end());
  rep(i, 0, n - 1) {
    if (h[i] < h[i + 1]) {
      --h[i + 1];
      if (h[i] < h[i + 1]) {
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;

  return 0;
}


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

int ctoi(char c) {
    switch (c) {
        case '0': return 0;
        case '1': return 1;
        case '2': return 2;
        case '3': return 3;
        case '4': return 4;
        case '5': return 5;
        case '6': return 6;
        case '7': return 7;
        case '8': return 8;
        case '9': return 9;
        default: return 0;
    }
}
int main()
{
    string N;
    cin >> N;
    int SN = 0;
    int S = stoi(N);
    for (int i = 0; i < N.size(); i++)
    {
        int a = ctoi(N[i]);
        SN += a;
    }
    if (S % SN == 0)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<functional>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<cstdio>
using namespace std;
using ll = long long;
int main(){
  int n;
  cin >> n;
  int ans = 0;
  for(int i = 0; i < n; i++) {
    int tmp;
    cin >> tmp;
    while(tmp%2 != 1){
      ans++;
      tmp /= 2;
    }
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

#define M 1000000
#define L 14

char H[M][L]; /* Hash Table */

int getChar(char ch){
  if ( ch == 'A') return 1;
  else if ( ch == 'C') return 2;
  else if ( ch == 'G') return 3;
  else if ( ch == 'T') return 4;
}

/* convert a string into an integer value */
long long getKey(char str[]){
  long long sum = 0, p = 1, i;
  for ( i = 0; i < strlen(str); i++ ){
    sum += p*(getChar(str[i]));
    p *= 5;
  }
  return sum;
}

int h1(int key){ return key % M ;/* your task */ }
int h2(int key){ return 1+(key%(M-1));/* your task */ }

int find(char str[]){
  long long i=0,key,ori;

  key=getKey(str);
  while(1){
    ori=(h1(key)+i*h2(key))%M;
    if(strcmp(H[ori],str)==0) return 1;
    else if(strlen(H[ori])==0) return 0;
    i++;
  }
return 0;
}

int insert(char str[]){
  long long key,i=0,ori;

  key=getKey(str);
  while(1){
    ori=(h1(key)+i*h2(key))%M;
    if(strcmp(H[ori],str)==0) return 1;
    else if(strlen(H[ori])==0){
    strcpy(H[ori],str);
    return 0;
    }
    i++;
  }
  return 0;
}

int main(){
    int i, n, h;
    char str[L], com[9];
    for ( i = 0; i < M; i++ ) H[i][0] = '\0';

    scanf("%d", &n);

    for ( i = 0; i < n; i++ ){
        scanf("%s %s", com, str);

        if ( com[0] == 'i' ){
            insert(str);
        } else {
            if (find(str)){
                printf("yes\n");
            } else {
                printf("no\n");
            }
        }
    }

    return 0;
}




Measured memory_bytes: 15456
/*input
10 4
40 10 20 70 80 10 20 70 80 60
*/
 
#include <unordered_map>
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <climits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <stdint.h>
 
using namespace std;
 
/*******  All Required define Pre-Processors and typedef Constants *******/
#define ar array
#define scd(t) scanf("%d",&t)
#define scld(t) scanf("%ld",&t)
#define sclld(t) scanf("%lld",&t)
#define scc(t) scanf("%c",&t)
#define scs(t) scanf("%s",t)
#define scf(t) scanf("%f",&t)
#define sclf(t) scanf("%lf",&t)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define tests int r; cin >> r; while(r--)
#define MP make_pair
#define PI acos(-1)
typedef pair<long long, long long> PII;
typedef pair<double, double> PDD;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef map<int,int> MPII;
typedef set<int> SETI;
typedef multiset<int> MSETI;
typedef long int int32;
typedef unsigned long int uint32;
typedef long long int int64;
typedef unsigned long long int  uint64;
#define godspeed ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(0);
 
#define M(x) ((x)%(1000000007))
 
 int64 fact(int n) {
   int64 count = 1;
   for(int64 i = 1;i<=n;i++){
   		count = M(count * i);
   }
   return count;
}
 
 
 
int main() {
	godspeed;
	int n,k;
	cin>>n>>k;
	int arr[n];
	rep(i,n){
		int a;
		cin>>a;
		arr[i] = a;
	}
	int dp[n];
	dp[0] = 0;
	dp[1] = abs(arr[1]-arr[0]);
	for(int i = 2;i<n;i++){
		int mi = dp[i-1] + abs(arr[i-1]-arr[i]);
		for(int j = 1; j<=k;j++){
			if(i-j>=0){
				mi = min(mi, dp[i-j] + abs(arr[i-j]-arr[i]));
			}
		}
		dp[i] = mi;
	}
	cout<<dp[n-1]<<endl;
}

Measured memory_bytes: 4424