akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,p,ans=1;
    ll g[1000000]={0};
    cin>>n>>p;
    if(n>=63){
        cout << 1<<endl;
        return 0;
    }
    ll a = 2;
    while (p >= a * a) {
        if (p % a == 0) {
            g[a]++;
            p /= a;
        } else {
            a++;
        }
    }
    if(p!=1 && n==1){
        ans*=p;
    }
    else{
        if(p<1000000){
            g[p]++;
        }
    }
    for(int i=2;i<999999;i++){
        if(g[i]!=0){
            ans*=pow(i,(g[i]/n));
        }
    }
    cout << ans<<endl;

    return 0;
}


Measured memory_bytes: 8064
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
using namespace std;
#pragma warning (disable: 4996)

string S;
int maxn = 0, cnt = 0;

int main() {
	cin >> S;
	for (int i = 0; i < S.size(); i++) {
		if (S[i] == 'R') cnt++;
		else cnt = 0;
		maxn = max(maxn, cnt);
	}
	cout << maxn << endl;
	return 0;
}

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

int ceiling_div(int a, int b){ // ceiling(a/b)= floor((a+b-1)/b)
  return (a+b-1)/b;
}

int main(){
  int N,D,A;
  cin >> N >> D >> A;

  vector<pair<int, int>> data(N);
  for(int i=0; i<N; i++){
    int x,h;
    cin >> x >> h;
    data.at(i)= make_pair(x,h);
  }
  sort(data.begin(), data.end());

  vector<int> ngh_id(N);
  int left= N-1;
  for(int right= N-1; right >= 0; right--){
    while(left > 0 && data.at(right).first- data.at(left-1).first <= 2*D){
      left--;
    }
    ngh_id.at(right)= left;

    if(right==left) left--;
  }

  vector<int> damage(N);
  int64_t ans= 0;
  for(int i=0; i<N; i++){
    int hp_edge= data.at(i).second-(damage.at(i)- damage.at(ngh_id.at(i)) );
    if( hp_edge>0 ){
      int n_diff= ceiling_div(hp_edge, A);
      ans+= n_diff;
      if(i<N-1) damage.at(i+1)= damage.at(i)+ A*n_diff;
    }
    else if(i<N-1){
      damage.at(i+1)= damage.at(i);
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 3328
n = gets.to_i
max = 0
arr = gets.chomp.split(' ').map(&:to_i)
arr.each do |num|
  i = 0
  while true
    if num % (2 ** (i+1)) != 0
      max += i
      break
    end
    i += 1
  end
end
puts max

Measured memory_bytes: 14764
#include <bits/stdc++.h>
 
using namespace std;
 
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(a) a.begin(), a.end()
#define rep(i, st, n) for (int i = (st); i < (n); ++i)
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef long double ld;
 
template <typename T1, typename T2> bool chkmin(T1 &x, T2 y) { return y < x ? (x = y, true) : false; }
template <typename T1, typename T2> bool chkmax(T1 &x, T2 y) { return y > x ? (x = y, true) : false; }

signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
#ifdef DEBUG
    freopen("in", "r", stdin);
#endif
    
    int n, m, a, b;
    cin >> n >> m >> a >> b;
    for (int i = 0; i < n; ++i)
    {
        int x = (i < b ? 0 : 1);
        for (int j = 0; j < m; ++j)
        {
            int y = (j < a ? 0 : 1);
            cout << (x ^ y);
        }
        cout << '\n';
    }

    return 0;
}

Measured memory_bytes: 1280
// Last Change: 05/02/2020 21:55:01.
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

int main() {
  ll A, B, N;
  cin >> A >> B >> N;

  ll x = min(N, B - 1);
  cout << (A * x) / B << endl;
}


Measured memory_bytes: 3192
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;

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

    vector<vector<int> > a(3, vector<int>(n));
    for(int i=0; i<3; ++i){
        for(int j=0; j<n; ++j)
            cin >> a[i][j];
        sort(a[i].begin(), a[i].end());
    }

    int i = 0;
    int k = 0;
    long long ans = 0;
    for(int j=0; j<n; ++j){
        while(i < n && a[0][i] < a[1][j])
            ++ i;
        while(k < n && a[2][k] <= a[1][j])
            ++ k;
        ans += i * (long long)(n - k);
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define lp(i,a,n) for(int i=a;i<=n;++i)
#define lpd(i,a,n) for(int i=a;i>=n;--i)
#define mem(a,b) memset(a,b,sizeof a)
#define all(v) v.begin(),v.end()
#define println(a) cout <<(a) <<endl
#define sz(x) ((int)(x).size())
#define readi(x) scanf("%d",&x)
#define read2i(x,y) scanf("%d%d",&x,&y)
#define read3i(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define mod 1000000007
#define eps 1e-8
#define infi 1000000000
#define infll 1000000000000000000ll
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef set<int> si;
typedef map<int,int> mii;

const int N = 2002;
int n,a[N],sum;
bitset<N*N> dp[2];

int main(){
    readi(n);
    lp(i,1,n) readi(a[i]), sum += a[i];

    lp(i,1,n){
        dp[i&1] = dp[(i-1)&1];
        dp[i&1][a[i]] = 1;
        dp[i&1] |= dp[(i-1)&1] << a[i];
    }

    sum = (sum + 1) / 2;
    while(!dp[n&1][sum]) ++sum;
    cout <<sum;
}

/*
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
*/


Measured memory_bytes: 2176
n = int(input())
l = [list(map(int, input().split())) for _ in range(n)]
ans = True
for i in l:
    t, x, y = i[0], i[1], i[2]
    if x+y > t or (x+y)%2 != t%2:
        ans = False
 
print("Yes") if ans else print("No")

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

int abs(int x) {
    return max(x, -x);
}

int main() {
  int64_t N, M;
  cin >> N >> M;
  vector<vector<int64_t>> va(N, vector<int64_t> (2));
  vector<vector<int64_t>> vb(M, vector<int64_t> (2));
  for (int64_t i = 0; i < N; i++) {
    int64_t a, b;
    cin >>a >> b;
    va.at(i).at(0) = a;
    va.at(i).at(1) = b;
  }
  for (int64_t i = 0; i < M; i++) {
    int64_t a, b;
    cin >>a >> b;
    vb.at(i).at(0) = a;
    vb.at(i).at(1) = b;
  }
 
  vector<int64_t> ans(N);
 for (int64_t i = 0LL; i < N; i++) {
   int64_t d = 400000000LL;
   for (int64_t j = 0LL; j < M; j++) {
     if (abs(va.at(i).at(0) - vb.at(j).at(0)) + abs(va.at(i).at(1)-vb.at(j).at(1)) < d) {
       d=(abs(va.at(i).at(0) - vb.at(j).at(0)) + abs(va.at(i).at(1)-vb.at(j).at(1)));
       ans.at(i) = j+1;
     }
   }
 }
  for (int64_t i = 0; i < N; i++) {
    cout << ans.at(i) << endl;
  }
}

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

int main(){
  int n;
  cin>>n;
  printf("%s%d","ABC",n);
  // printf("%d", n);
  return 0;
}

// prinf("表示形式（形式、行間、エスケープ記号、）"、読んだ順に実行、’,’で区別)


Measured memory_bytes: 256
N, M = [int(nm) for nm in input().split()]
S = []
for m in range(M):
  KS = [int(ks) for ks in input().split()]
  S.append(KS[1:])
P = [int(p) for p in input().split()]
ans = 0
for n in range(2**N):
  on_off = str(format(n, "b"))
  if len(on_off)<N:
    on_off = "0"*(N-len(on_off)) + on_off
  on_light = 0
  for m in range(M):
    nm_of_light = 0
    for sm in range(len(S[m])):
      nm_of_light += int(on_off[S[m][sm]-1])
    if nm_of_light % 2 == P[m]:
      on_light += 1
  if on_light == M:
    ans += 1
print(ans)

Measured memory_bytes: 3188
S = gets.chomp

def cnt(s, t)
  s.split(//).zip(t.split(//)).count{|a, b| a != b}
end

l = S.length
puts [cnt('10'*(l/2) + (l.even? ? '' : '1'), S), cnt('01'*(l/2) + (l.even? ? '' : '0'), S)].min

Measured memory_bytes: 30084
from collections import deque

N = int(input())
idxs = [deque() for i in range(26)]
def ctoi(c):
    return ord(c) - ord('a')

cs = []
for i in range(N):
    c = input()[0]
    cs.append(c)
    ci = ctoi(c)
    idxs[ci].append(i)

dp = [i for i in range(N)]
dp[0] = 0
for i in range(N):
    c = cs[i]
    ci = ctoi(c)
    if i > 0:
        dp[i] = min(dp[i],dp[i-1]+1)

    if len(idxs[ci]) < 2: continue
    idxs[ci].popleft()
    pi = idxs[ci][0]
    dp[pi] = dp[i]
    #print(dp)

print(dp[-1] + 1)


Measured memory_bytes: 14752
a = int(input())
b = list(map(int, input().split()))
c = 0
d = 0
e = []
for i in range(a):
    if b[i] < 0:
        c -= 1
    d += abs(b[i])
    e.append(abs(b[i]))
if c % 2 == 0:
    print(d)
else:
    print(d - min(e) * 2)


Measured memory_bytes: 14284
#include <bits/stdc++.h>
using namespace std;
int n, m, q;
string a[2];
set<int> s[2];
void go(int x, int y) {
	int p0 = *s[0].lower_bound(x);
	int p1 = *s[1].lower_bound(x);
	int p = min(p0, p1);
	if (x + q - y < p) {
		s[0].insert(x + q - y);
		s[1].insert(x + q - y);
		return;
	}
	int v = p;
	int t = p == p1;
	s[t ^ 1].insert(v);
	while (s[t].find(v) != s[t].end()) {
		s[t].erase(v);
		v++;
	}
	if (s[t ^ 1].find(v) != s[t ^ 1].end()) {
		s[t ^ 1].erase(v);
		go(v, y + p - x);
	} else {
		s[t].insert(v);
	}
}
int main() {
	ios::sync_with_stdio(false);
	cin >> n >> m >> q >> a[0] >> a[1];
	reverse(a[0].begin(), a[0].end());
	reverse(a[1].begin(), a[1].end());
	while (a[0].size() < m) {
		a[0].push_back('0');
	}
	while (a[1].size() < n) {
		a[1].push_back('0');
	}
	s[0].insert(1e9);
	s[1].insert(1e9);
	for (int i = max(n, m) - 1; i >= 0; i--) {
		if (a[0][i] == '1' && a[1][i] == '0') {
			s[0].insert(i);
		}
		if (a[0][i] == '0' && a[1][i] == '1') {
			s[1].insert(i);
		}
		if (a[0][i] == '1' && a[1][i] == '1') {
			go(i, 0);
		}
	}
	s[0].insert(-1);
	s[1].insert(-1);
	for (int i = 0; i < 2; i++) {
		auto it = --s[i].end();
		for (int j = *--it; j >= 0; j--) {
			if (j == *it) {
				it--;
				printf("1");
			} else {
				printf("0");
			}
		}
		printf("\n");
	}
	return 0;
}
//Strange

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

int a,b,c,x;
int sum;

int main()
{
	cin>>a>>b>>c>>x;
	
	for(int i=0;i<=a;i++)
		for(int j=0;j<=b;j++)
			for(int k=0;k<=c;k++)
				if(!(500*i+100*j+50*k-x)) sum++;
				
	cout<<sum<<endl;
	
	return 0;
}

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

int main(){

	ios_base::sync_with_stdio(0);
	cout.tie(0);
	cin.tie(0);

	int n,m;
	cin>>n>>m;

	string s[2] = {"AC","WA"};
	int ac=0 , wa=0;

	int idx[105005];
	int widx[105005];

	memset(idx,0,sizeof idx);
	memset(widx,0,sizeof widx);

	for(int i=0 ; i<m ; ++i){
		int id;
		string j;

		cin>>id>>j;
		if( j == s[0] )
			idx[id] = 1;
		else if( !idx[id] )
			widx[id]++;
	}

	for(int i=0 ; i<105005 ; ++i){
		if(idx[i]){
			ac++;
			wa += widx[i];
		}
	}

	cout<<ac<<" "<<wa;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}
using ll = long long;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define endl "\n"
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
constexpr int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    for(auto c : s) {
        if(c == '7') {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 3612
dic = {}
N = int(input())
pre = input()
dic[pre] = 0
flag = True
for i in range(N-1):
    s = input()
    if list(pre)[len(pre)-1]!=list(s)[0]:
        flag=False

    if s in dic:
        flag=False
    else:
        dic[s]=0

    pre = s

print("Yes" if flag else "No")

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

using namespace std;

#define int long long

signed main()
{
	int M;
	cin >> M;
	for (int t = 0; t < M; t++)
	{
		set<string> latte;
		string S;
		cin >> S;
		for (int i = 1; i < S.size(); i++)
		{
			string a = S.substr(0, i);
			for (int j = 0; j < 2; j++, reverse(a.begin(), a.end()))
			{
				string b = S.substr(i);
				for (int k = 0; k < 2; k++, reverse(b.begin(), b.end()))
				{
					latte.insert(a + b);
					latte.insert(b + a);
				}
			}
		}
		printf("%d\n", latte.size());
	}
	return 0;
}

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

public class Main{
    public static void main(String[] args) throws IOException{
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        String line = reader.readLine();
        double r = Double.parseDouble(line);
        double area = r*r*Math.PI;
        double d = 2*Math.PI*r;
        System.out.printf("%f %f\n",area,d);
    }
}


Measured memory_bytes: 24644
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        int[] A = new int[s.length()];
        for (int i = 0; i < A.length; i++) A[i] = s.charAt(i)-'0';
        System.out.println(helper(A));
        sc.close();
    }

    public static int helper(int[] A) {
        int res = 0, count = 0;
        for (int i = 0; i < A.length; i++) {
            if (i % 2 == 0) {
                if (A[i] != 0) res++;
                if (A[i] != 1) count++;
            } else {
                if (A[i] != 1) res++;
                if (A[i] != 0) count++;
            }
        }
        return Math.min(res, count);
    }
}

Measured memory_bytes: 28940
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import collections
import sys
input = sys.stdin.readline


def main():
    n = int(input())
    s = list()
    for i in range(n):
        s.append(str(input()).replace('\n', ''))

    c = dict(collections.Counter(s))
    max_count = max(c.values())
    ans = list()
    for k, v in c.items():
        if v == max_count:
            ans.append(k)

    for i in sorted(ans):
        print(i)


if __name__ == '__main__':
    main()


Measured memory_bytes: 41712
#include <cstdio>
#include <iostream>
using namespace std;
int main()
{
	int n;
	cin >> n;
	double ans;
	for (int i=1;i<=n;i++)
	{
		int x;
		cin >> x; 
		ans+=1.0/x;
	}
	cout << 1.0/ans;
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N = 205;
const int maxS = 40005;
long long f[2][2*maxS],n,m,a[N];
const int MOD =1e9+7;
void init()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
}
void nhap()
{
    cin >> n >> m;
    for (int i=1; i<=n; i++) {
        cin >> a[i];
        a[i] -= m;
    }
}
void xuli()
{
    memset(f,0,sizeof(f));
    f[0][maxS] = 1;
    for (int i = 1; i<=n; i++) {
        for (int j = 0; j<2*maxS; j++) {
             f[1][j+a[i]] = f[0][j+a[i]] + f[0][j];
        }
        for (int j = 0; j<2*maxS; j++) {
            f[0][j] = f[1][j];
            f[1][j] = 0;
        }
    }
    cout << f[0][maxS] - 1  << '\n';
}
int main()
{
    init();
        nhap();
        xuli();

}


Measured memory_bytes: 1536
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
long S(long n)
{
	long ans=0;
	while(n)ans+=n%10,n/=10;
	return ans;
}
vector<pair<long,long> >a;
vector<long>ans;
main()
{
	for(long i=0;i<16;i++)
	{
		for(long j=1;j<1000;j++)
		{
			long now=j;
			for(long l=0;l<i;l++)now=now*10+9;
			a.push_back(make_pair(now,S(now)));
		}
	}
	sort(a.begin(),a.end());
	a.erase(unique(a.begin(),a.end()),a.end());
	long A=-1,B;
	for(int i=a.size();i--;)
	{
		if(A<0||B*a[i].second>=A*a[i].first)
		{
			A=a[i].second;
			B=a[i].first;
			ans.push_back(a[i].first);
		}
	}
	reverse(ans.begin(),ans.end());
	ans.erase(unique(ans.begin(),ans.end()),ans.end());
	int k;cin>>k;
	for(int i=0;i<k;i++)cout<<ans[i]<<endl;
}


Measured memory_bytes: 640
#pragma GCC optimize(2)
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, int> pdd;

const ll mod = 23333333333333333;
const int N = 1e2 + 10, M = 1e5 + 10;
const ll INF = 5e17;
const int inf = 0x3f3f3f3f;
const double eps = 1e-4;

#define pi acos(-1)
#define mk make_pair

int a[N], b[N], c[N], d[N];
int arr[N];
int n, m, q;
int cnt;
int ans;

void dfs(int pos, int last)
{
    if (pos == n)
    {
        cnt++;
        int sum = 0;
        for (int i = 1; i <= q; i++)
        {
            if (arr[b[i]] && arr[a[i]])
            {
                if (arr[b[i]] - arr[a[i]] == c[i])
                    sum += d[i];
            }
        }
        ans = max(ans, sum);
        return;
    }
    for (int i = last; i <= m; i++)
    {
        arr[pos + 1] = i;
        dfs(pos + 1, i);
        arr[pos + 1] = 0;
    }
}

int main()
{
    cin >> n >> m >> q;
    for (int i = 1; i <= q; i++)
    {
        scanf("%d%d%d%d", &a[i], &b[i], &c[i], &d[i]);
    }
    for (int i = 1; i <= n; i++)
    {
        arr[1] = i;
        dfs(1, i);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3716
import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def v(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 6)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")
al = "abcdefghijklmnopqrstuvwxyz"
AL = al.upper()

n,*a=map(int,open(0));print(sum(a)-max(a)//2)


Measured memory_bytes: 10504
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <string>
#include <stack> // s.top()
#include <bitset>
#include <queue> // s.front()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define print(x) cout<<(x)<<endl
#define INF10 1001001001 
#define INF5 100000
#define EPS 1e-10

int N;

ll GCD(ll a, ll b) {
	if (b == 0)return a;
	else return GCD(b, a%b);
}


int main() {
	cin >> N;
	ll ans = 1;
	ll tmp;
	for (int i = 0; i < N; i++) {
		ll T; cin >> T;
		tmp = ans / GCD(T, ans);
		ans = tmp * T;
	}
	cout << ans << endl;





	return 0;
}


Measured memory_bytes: 256
n = int(input())
s = []
for _ in range(n):
    s.append(input())
m = int(input())
t = []
for _ in range(m):
    t.append(input())

v = 0
ss = set(s)
for x in ss:
    tmp = s.count(x) - t.count(x)
    if tmp > v:
        v = tmp

print(v)


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

using ll = long long;
#define ALL(c) (c).begin(), (c).end()
const int MOD = 1000000007;

int main() {
    string s;
    cin >> s;
    deque<char> q;
    for (const char c : s) {
        if (c == 'B') {
            if (q.size() != 0) {
                q.pop_back();
            }
        } else {
            q.push_back(c);
        }
    }
    while (!q.empty()) {
        cout << q.front();
        q.pop_front();
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fo(i,a,b) for(int i=(a);i<=(b);++i)
#define rv(i,a,b) for(int i=(a);i>=(b);--i)
#define P pair<int,int>
#define all(x) x.begin(),x.end()
#define SZ(x) ((int)x.size())
using namespace std;
typedef long long LL;
const int M = 1200000;
const int inf = 0x3f3f3f3f;
int n,m,k;
int a[20][2];
int cal(int t[]){
	int ret=0;
	fo(i,0,n-1){
		fo(j,0,i-1){
			if(t[j]>t[i])
				++ret;
		}
	}
	return ret;
}
int main() {
	cin>>n;
	int ans=inf;
	fo(i,0,n-1)
		cin>>a[i][0];
	fo(i,0,n-1)
		cin>>a[i][1];
	int al=(1<<n)-1;
	fo(i,0,al){
		vector<P> v[2];
		fo(j,0,n-1){
			int to=((i>>j)&1);
			v[to^(j&1)].push_back({a[j][to],j});
		}
		if(SZ(v[1])!=n/2 || SZ(v[0])!=(n+1)/2) continue;
		if(!v[0].empty())
			sort(all(v[0]));
		if(!v[1].empty())
			sort(all(v[1]));
		int tar[20];
		int pre=-inf;
		bool bk=0;
		fo(j,0,n-1){
			P cur=v[j&1][j>>1];
			if(cur.first<pre) {
				bk=1;
				break;
			}
			pre=cur.first;
			tar[j]=cur.second;
		}
		if(bk) continue;
		ans=min(ans,cal(tar));
	}
	if(ans==inf) cout<<-1<<endl;
	else cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-12;

//int N, M, K, T, H, W, L, R;
long long int N, M, K, T, H, W, L, R;



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

	cin >> N >> M >> K;
	vector<long long int>v(K);
	for (auto &i : v)cin >> i;
	long long int mi = v[0];
	for (int i = 1; i < K; i++) {
		v[i] += v[i - 1];
		mi = min(mi, v[i]);
	}
	if (N + mi > M&&v.back() >= 0) {
		cout << -1 << endl;
		return 0;
	}
	long long int ans = 1;
	while (1) {
		if (N + mi > M) {
			ans += K;
			N += v.back();
		}
		else {
			for (auto i : v) {
				if (N + i > M)ans++;
				else {
					cout << ans << endl;
					return 0;
				}
			}
		}
	}
}


Measured memory_bytes: 3620
import sys
input = sys.stdin.readline
from collections import deque
ANS = 0
SUM = 0
def dfs(arr, l):
    global SUM, ANS
    if l == N:
        for i in range(Q):
            if arr[A[i][1]-1]-arr[A[i][0]-1] == A[i][2]:
                SUM += A[i][3]
            ANS = max(SUM, ANS)
        SUM = 0
        return
    else:
        for i in range(arr[l-1], M+1):
            arr.append(i)
            l = len(arr)
            dfs(arr,l)
            arr.pop()

    return ANS

if __name__ == '__main__':
    N, M ,Q = map(int, input().split())
    A = [list(map(int, input().split())) for i in range(Q)]
    for i in range(M):
        pANS = ANS
        ARR = deque([i+1])
        dfs(ARR,1)
        ANS = max(pANS, ANS)
    print(ANS)

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

#define endl '\n'
#define ll long long
#define LSB __builtin_ctzll
#define sc(a) scanf("%d",&a)
#define MSB 63-__builtin_clzll
#define scl(a) scanf("%lld",&a)
#define BITS __builtin_popcountll
#define mem(a , v)  memset(a , v , sizeof(a))
#define fastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

const int MOD = 1e9+7;
const int MAX = 1e5+55;
const int INF = 1e9+77;
const ll INFINF = 1e18+1e17;
const double PI = acos(-1.0);
vector<int> months = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

ll power(ll x,ll y){
         if(y==0)
         return 1;
         ll s=power(x,y/2);
         s*=s;
         if(y&1)
         s*=x;
         return s;
}

string s1;
string s2;
string ans;
int n1;
int n2;


int dp[3001][3001];

int solve(int i,int j){
    if(i==n1){
        return 0;
    }
    if(j==n2){
        return 0;
    }

    int &res=dp[i][j];
    if(res!=-1){
        return res;
    }

    res=0;
    if(s1[i]==s2[j]){
        res+=solve(i+1,j+1)+1;
    }
    else{
        res=max(    solve(i+1,j)  ,   solve(i,j+1)   );
    }

    return res;

}


void build(int i,int j){
    if(i==n1){
        return;
    }
    if(j==n2){
        return;
    }


    if(s1[i]==s2[j]){
        ans+=s1[i];
        build(i+1,j+1);
    }
    else{
        if(solve(i+1,j)>=solve(i,j+1)){
            build(i+1,j);
        }
        else{
            build(i,j+1);
        }
    }

    return;

}



int main(){

ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

//freopen("input.txt" , "r" , stdin);
//freopen("output.txt" , "w" , stdout);



     cin>>s1>>s2;
     n1=s1.size();
     n2=s2.size();

     mem(dp,-1);
     int cur=solve(0,0);
     ans="";
     build(0,0);
     cout<<ans;








     return 0;

}


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

void solve() 
{
	int x,i=0;while(cin>>x){
		i++;
		if(x==0){
			cout<<i<<endl;return;
		}
	}
}

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

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
using P = pair<int,int>;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

int main(){
    string s, t;
    cin >> s >> t;
    map<char, vector<ll>> mp;
    ll sn = s.size(), tn = t.size();
    s += s;
    rep(i, s.size()){
        mp[s[i]].push_back(i);
    }
    rep(i, tn){
        if (mp.find(t[i]) == mp.end()){
            cout << -1 << endl;
            return 0;        
        }
    }

    int left = 0;
    ll ans = 0;
    while(left < tn){
        ll a = -1;
        while(left < tn){
            char c = t[left];
            auto itr = upper_bound(mp[c].begin(), mp[c].end(), a);
            if (*itr >= sn) break;
            else{
                a = *itr;
                left++;
            }
        }
        if (left == tn) ans += a + 1LL;
        else ans += sn;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5796
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb(in,tmp) in.push_back(tmp)
#define all(in) in.begin(),in.end()
#define PI acos(-1)
using namespace std;
int main(){
  map<int,map<string,int> >in;
  int n;
  cin>>n;
  rep(i,n){
    int tmp;
    string tmp1;
    cin>>tmp1>>tmp;
    in[tmp1.size()][tmp1]+=tmp;
  }
  map<int,map<string,int> >::iterator ite=in.begin();
  for(;ite!=in.end();ite++){
    map<string,int>::iterator it=in[ite->first].begin();
    for(;it!=in[ite->first].end();it++)
      cout<<it->first<<" "<<it->second<<endl;
  }
}

Measured memory_bytes: 1228
#include <iostream>
#include <vector>
using namespace std;
int main(void){
    // Your code here!
    int n,k,x,y,ans=0;
    cin>>n>>k>>x>>y;
    for(int i =0;i<n;i++){
        if(i < k){
            ans+=x;
        }else{
            ans+=y;
        }
    }
    cout << ans;
}


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

typedef long double LD;
typedef long long ll;
typedef map<int,int> mii;
typedef pair<int,int> pii;
typedef vector<pii> vpii;

#define pb              push_back
#define mp              make_pair
#define F               first
#define S               second
#define mod             1000000007
#define INF             2147483647
#define Endl            "\n"
#define FasterIO        ios_base::sync_with_stdio(0);cin.tie(0); cout.tie(0) ;
#define precision(a)    cout << fixed << setprecision(a)
#define bug(a,b)        cout<<a<<"\t"<<b<<"\n";
#define Case(a,b)       cout<<"Case "<<a<<": "<<b<<"\n";
#define reset(a,b)      memset(a,b,sizeof(a));
#define srt(a)      sort(a.begin(),a.end());

const int MAXN = 1000005;
const int SQRTN = 1003;
const int LOGN = 22;
const double PI=acos(-1);
const int sz=1e5+9;

int strtoint(string str){
    stringstream ss(str);
    int x = 0;
    ss >> x ;
    return x ;
}
string intostr(int x){
    stringstream ss;
    ss << x;
    string str = ss.str();
    return str;
}
void rem(string &s, const string &c) {
	auto pos = s.find(c);
	if (pos == string::npos) {
		cout << -1 << endl;
		exit(0);
	}
	s.erase(0, pos + 1);
}
void println (int n){
    cout<<n<<"\n";
}
void printvec(vector <int> &a){
    for (int i=0;i<a.size();i++){
        cout<<a[i]<<" ";
    }
    cout<<"\n";
}

void printgraph(vector <int> g[],int e){
    for (int i=0;i<e;i++){
        cout<<i<<" --> ";
        for (int j=0;j<g[i].size();j++){
            cout<<g[i][j]<<" ";
        }
        cout<<"\n";
    }
}

void printmap (map <int,int> &mymap){
    for (auto itr = mymap.begin(); itr != mymap.end(); ++itr) {
        cout << '\t' << itr->first
             << '\t' << itr->second << '\n';
    }
    cout << "\n";
}

int a[100005][4], dp[100005][4];
int N;

int rec(int pos, int type){

    if(pos>N) return 0;

    if(dp[pos][type]!=-1) return dp[pos][type];

    int ret = -1;
    for(int i=1; i<=3; i++)
        if(i!=type)
            ret = max (ret, rec(pos+1,i) + a[pos+1][i]);

    return dp[pos][type] = ret;
}


void solve(){
    memset(dp,-1,sizeof(dp));
    int i,j;
    cin>>N;
    for(i=1; i<=N; i++)
        for(j=1; j<=3; j++)
            cin>>a[i][j];


   cout<< rec(0,0) << "\n";

    //printvec(v);
}


int main(){
    //FasterIO;

    solve();
    return 0;
}

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

typedef long long ll;
ll mod=1e9+7;

ll modpow(ll a,ll b){
  ll ans=1;
  a%=mod;
  while(b){
    if(b&1) ans=ans*a%mod;
    a=a*a%mod;
    b>>=1;
  }
  return ans;
}

ll dp[100000][101];
ll sum[100000][101];

int main(){
  ll n,k;
  cin >> n >> k;
  ll t=sqrt(n);
  for(ll i=1;i<=t;i++) dp[i][1]=1;
  ll now=t+1;
  ll s=n/t-1;
  for(ll i=s;i>=1;i--){
    dp[now][1]=n/i-n/(i+1);
    now++;
  }
  for(ll i=2;i<=k;i++){
    for(ll j=1;j<now;j++){
      sum[j][i-1]=(sum[j-1][i-1]+dp[j][i-1])%mod;
    }
    for(ll j=1;j<now;j++){
      dp[j][i]=(sum[now-j][i-1]*dp[j][1])%mod;
    }
  }
  ll ans=0;
  for(ll i=1;i<now;i++){
    ans=(ans+dp[i][k])%mod;
  }
  cout << ans << endl;
}

Measured memory_bytes: 102656
#include <string.h>

#include <algorithm>
#include <cmath>
#include <cstdlib>  // abs() for integer
#include <iostream>

using namespace std;

int main(void) {
    int N, D;
    int X[200000], Y[200000];

    cin >> N >> D;
    for (int i = 0; i < N; i++) cin >> X[i] >> Y[i];

    int cnt = 0;
    for (int i = 0; i < N; i++) {
        long long dist_2 = (long long) X[i] * X[i] + (long long) Y[i] * Y[i];
        //cout << dist_2 << endl;

        if (dist_2 <= (long long)D * D) {
            cnt++;
        }
    }

    cout << cnt << endl;

    // cout<<template<<endl;
    return 0;
}

Measured memory_bytes: 5136
#include<bits/stdc++.h>
using namespace std;
int a[1005];
int main(){
	int n;
	cin>>n;
	int tmp,f1=0;
	for(int i=0;i<n;i++){
		cin>>tmp;
		if(tmp%2==0){
			if(tmp%3==0||tmp%5==0)continue;
			else{
				f1=1;
				break;
			}
		}
	}
	if(f1)cout<<"DENIED";
	else cout<<"APPROVED";
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstring>
#include <cstdio>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map> //pair is also included in this library
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

#define REP(i, s, n) for(int i = (int)(s); i < (int)(n); i++)
#define fst first
#define snd second
#define MP make_pair //incase c++11 or later is not available

using namespace std;

typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

//prefer define statement
//for reason that const int ver. of INF will raise a silly warning (unused variable)
#define INF (INT_MAX/3)
#define LIM_INF (INT_MAX)
//const int INF = INT_MAX/3;
#define PI = 3.14159265358979323846
/*------------------------------------------------------------------------------*/

int main(){
  int N, M, K;

  cin >> N >> M >> K;

  bool ans = false;
  
  REP(i, 0, N+1){
    int c = 0;
    c += i * M;
    REP(j, 0, M+1){
      int d = j * (N - 2 * i);
      int e = c + d;
      if(e == K){
        ans = true;
        break;
      }
    }

    if(ans){
      break;
    }
  }

  if(ans){
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector>
#include <numeric>
#define PI 3.14159265358979323846
#define MAXINF 1e18L
#define MININF -1e18L
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define SORT(v) sort(ALL(v))
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define pb push_back
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
typedef long long ll;
typedef pair<int, int> intint;

int main(void)
{
    int a;
    cin >> a;
    if(a == 1) {
        pr("Hello World");
    }
    else{
        int A,B;
        cin >> A >> B;
        pr(A+B);
    }
}

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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)
#define rrep(i, n) for(int i = ((int)n - 1); i >= 0; --i)

using ll = long long;
using ld = long double;

const ll INF = 1e18;
const int Inf = 1e9;
const double EPS = 1e-9;
const ll MOD = 1e9 + 7;
const ll MAX = 1e7;

ll fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++) {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

ll COM(int n, int k) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
	int x, y;
	cin >> x >> y;
	if ((x + y) % 3 != 0) {
	  cout << 0 << endl;
	  return 0;
	}
	int t = (x + y) / 3;
	x -= t, y -= t;
	COMinit();
	cout << COM(x + y, x) << endl;
    
    return 0;
}



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

using namespace std;

int color[8];
int dobby;

int main()
{
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    
    int n; cin >> n;
    for (int i = 0; i < n; ++i)
    {
        int x; cin >> x;
        
        if (x < 400)
            color[0] = 1;
        if (x > 399 && x < 800)
            color[1] = 1;
        if (x > 799 && x < 1200)
            color[2] = 1;
        if (x > 1199 && x < 1600)
            color[3] = 1;
        if (x > 1599 && x < 2000)
            color[4] = 1;
        if (x > 1999 && x < 2400)
            color[5] = 1;
        if (x > 2399 && x < 2800)
            color[6] = 1;
        if (x > 2799 && x < 3200)
            color[7] = 1;
        if (x > 3199)
            ++dobby;
    }
    
    int collect = 0;
    
    for (int j = 0; j < 8; ++j)
        if (color[j])
            ++collect;
    
    cout << max(1, collect) << " " << collect + dobby;
}

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

using namespace std;

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

    vector<int> b(n + 1, 1000000000);
    for (int i = 1; i <= n - 1; i++) {
        cin >> b[i];
    }

    int res = 0;
    for (int i = 1; i <= n; i++) {
        res += min(b[i - 1], b[i]);
    }

    cout << res << endl;
}


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

using namespace std;

#define _39_days ""

typedef long long ll;

const int N = 1e5 + 5;

int n, m, cnt[N], is[N], ans;

int main() {
    cin >> n >> m;
    for (int i = 1; i <= n; ++i) {
        cnt[i] = 1;
    }
    is[1] = 1;
    for (int i = 1; i <= m; ++i) {
        int x, y;
        cin >> x >> y;
        cnt[x]--;
        cnt[y]++;
        if (is[x])
            is[y] = 1;
        if (!cnt[x])
            is[x] = 0;
    }
    for (int i = 1; i <= n; ++i) {
        if (is[i])
            ++ans;
    }
    cout << ans;
}


Measured memory_bytes: 1024
#include <stdio.h>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef vector<vector<int>> v2int;
typedef vector<ll> vll;
typedef vector<vector<ll>> v2ll;
typedef list<int> liint;
typedef pair<int, int> pint;
const int INF = int(2e9);
const ll LINF = ll(2e9) * ll(2e9);
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b) { a > b ? : a = b; }
template<class T, class C> void chmin(T& a, C b) { a < b ? : a = b; }



int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll N;
    ll A, B;
    cin >> N >> A >> B;
    auto C = A + B;

    ll ans = A *( N / C);
    ans += min(A, N% C);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int main (void)
{
  int n,d,a[11],r;
  cin>>r>>d>>a[0];
  for(int i=1;i<=10;i++)
  {
    a[i]=a[i-1]*r-d;
    cout<<a[i]<<endl;
    
  }
  
  return 0;
}

Measured memory_bytes: 3552
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define dup(x,y) (((x)+(y)-1)/(y))
#define v(T) vector<T>
#define vv(T) v(v(T))
#define diup(v,a,k) distance((v).begin(),(k)+upper_bound((v).begin(),(v).end(),(a)))
#define dilo(v,a,k) distance((v).begin(),(k)+lower_bound((v).begin(),(v).end(),(a)))
using ll = int64_t;
using ull = uint64_t;
using uint = uint32_t;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,v.size())i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,v.size())s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(v.size())o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
//---------------------------------------------------------------
#define fastio cin.tie(nullptr); std::ios::sync_with_stdio(false);
#define myio ifstream iofi; if(argc>1){iofi.open(argv[1]); std::cin.rdbuf(iofi.rdbuf());}
#define myloopset int loop = 1; if(argc>2) loop =stoi(argv[2]); rep(i,loop)
//--------------------------------------------------------------
template <class T> T chmin(T &a,T b){if(a>b){a=b; return 1;}else return 0;}
template <class T> T chmax(T &a,T b){if(a<b){a=b; return 1;}else return 0;}
struct Edge{
  int from;
  int to;
  ll cost;
  Edge(int from,int to,ll cost){
    this->from = from; 
    this->to   = to; 
    this->cost = cost; 
  }
};
void Main(){
  int n,m,R;
  cin>>n>>m>>R;
  vi r(R);
  cin>>r;
  rep(i,R) r[i]--;
  vvi d(n,vi(n,INF));
  rep(i,m){
    int a,b,c;
    cin>>a>>b>>c;
    a--;b--;
    d[a][b] = c;
    d[b][a] = c;
  }
  rep(k,n){
    rep(i,n){
      rep(j,n){
        chmin(d[i][j] , d[i][k] + d[k][j] );
      }
    }
  }
  sort(rng(r));
  int ans=INF;
  do{
    int sum=0;
    rep(i,R-1){
      sum += d[r[i]][r[i+1]];
    }
    chmin(ans,sum);
  }while(next_permutation(rng(r)));
  cout<<ans<<endl;
} int main(int argc,char** argv)
{fastio; myio; myloopset Main();}


Measured memory_bytes: 384
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.NoSuchElementException;
import java.util.Random;

class Main {
	public static void main(String[] args) {
		new Main().run();
	}
	
	void run() {
		FastScanner sc=new FastScanner();
		PrintWriter pw=new PrintWriter(System.out);
		char[] s=sc.next().toCharArray();
		int ans=0;
		for(char c:s) {
			if(c=='+')++ans;
			else --ans;
		}
		pw.println(ans);
		pw.close();
	}

	
	static void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}

}


class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public int nextInt() {
    	return Integer.parseInt(next());
    }
    
    public long nextLong() {
    	return Long.parseLong(next());
    }
}

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

int main(){
  int x,y;
  cin >>x>>y;
  for(int i=0;i<=x;i++){
    if(2*i+4*(x-i)==y){
      cout <<"Yes"<<endl;
      return 0;
    }
  }
  cout <<"No"<<endl;
  return 0;
}

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

int main() {
	int N;
  	cin >> N;
  	int K, U;
    int min = 512;
  
		for (int i = 0; i < N; i++) {
          int A;
          cin >> A;
          U = 2;
          K = 0;
          
          if (A%2 == 1) {
            min = 0;
            break;
          }
          
          while (A%U == 0) {
              K++;
              U *= 2;
          }
          
          if (K <= min) min = K;
        }
  
  cout << min << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <string>
#include <cmath>
#include <string>
#include <algorithm>
#include <iostream>
#include <map>
#include <vector>
using namespace std;
#define rep(i, a, n) for (int i=a;i<n;++i)
#define per(i, a, n) for (int i=n-1; i>=a;--i)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()

// D - Five, Five Everywhere

std::vector<int> MakePrime(int n) {
  std::vector<int> prime;
  prime.emplace_back(2);
  for (int i = 3; i <= n; i += 2) {
    bool a = false;
    for (int j = 3; j <= std::sqrt(i); j += 2) {
      if (i%j == 0) {
        a = true;
      }
    }
    if (a == false) {
      prime.emplace_back(i);
    }
  }
  return prime;
}

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

    vector<int> prime = MakePrime(55555);
    vector<int> ans;
    int ret = N;
    int i=0;
    while(ret>0){
        if(prime[i]%5 == 1){
            ans.push_back(prime[i]);
            --ret;
        }
        ++i;
    }
    rep(i, 0, ans.size()){
        cout << ans[i] << " ";
    }
    return 0;
}




Measured memory_bytes: 256
from collections import Counter
from functools import reduce
from operator import xor
n = int(input())
a = Counter(map(int , input().split()))

if n % 3 == 0:
    if len(a) == 3:
        if 0 == reduce(xor, a) and all(v == n // 3 for v in a.values()):
            print("Yes")
        else:
            print("No")
    elif len(a) == 2:
        if 0 in a and a[0] == n // 3:
            print("Yes")
        else:
            print("No")
    else:
        if 0 in a:
            print("Yes")
        else:
            print("No")
else:
    if len(a) == 1 and 0 in a:
        print("Yes")
    else:
        print("No")

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

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    
    String line = br.readLine();
    int front = Integer.parseInt(line.substring(0, 2));
    int rear = Integer.parseInt(line.substring(2, 4));
    
    String result = "NA";
    
    if(front>=1 && front<=12 && rear>=1 && rear<=12){
      result = "AMBIGUOUS";
    }else if (rear>=1 && rear<=12){
      result = "YYMM";
    }else if(front>=1 && front<=12){
      result = "MMYY";
    }
    
    System.out.println(result);
  }
}


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

using namespace std;

string S;

int main(void) {

	cin >> S;

	int N = S.size();

	if (N % 2 == 1) { cout << "No" << endl; return 0; }
	else {
		for (int i = 0; i < N; i += 2) {
			if (S[i] == 'h' && S[i + 1] == 'i') {}
			else { cout << "No" << endl; return 0; }
		}
	}

	cout << "Yes" << endl;
	return 0;
}

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

int main(){
	int i,n,bp,tp,bc,tc[100],input,maxc,tmpc,cc;
	cin >> n >> bp >> tp >> bc;
	for(i = 0;i < n;i++){
		cin >> input;
		tc[i] = input;
	}
	sort(tc,tc+n,greater<int>());
	maxc = bc / bp;
	tmpc = bc;
	for(i = 0;i < n;i++){
		tmpc += tc[i];
		cc = tmpc / (bp + (tp * (i + 1)));
		if(cc > maxc) maxc = cc;
	}
	cout << maxc << endl;
	return 0;
}

Measured memory_bytes: 0
n = int(input())
red = []
blue = []
for _ in range(n):
    a, b = map(int, input().split())
    red.append([a, b])
for _ in range(n):
    c, d = map(int, input().split())
    blue.append([c, d])
blue.sort()
red.sort(key=lambda x: x[1], reverse=True)
ans = 0
for b in blue:
    for i, r in enumerate(red):
        if (r[0] < b[0]) & (r[1] < b[1]):
            ans += 1
            red.pop(i)
            break
print(ans)

Measured memory_bytes: 3064