akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<numeric>
#include<map>
#include<queue>
#include<set>
#include<cstdio>
using namespace std;

int main(){
    int N,a[200010],b[200010];cin>>N;
    for(int i=1;i<=N;i++)cin>>a[i];
    int i=N,M=0;
    set<int> S;
    while(i>=1){
        int k=2*i,sum=0;
        while(k<=N){
            sum=(sum+b[k])%2;
            k+=i;
        }
        b[i]=(a[i]-sum+2)%2;
        if(b[i]==1){
            M++;
            S.insert(i);
        }
        i--;
    }
    cout<<M<<endl;
    for(auto itr=S.begin();itr!=S.end();itr++)
        cout<<*itr<<" "<<endl;
    
    return 0;

}

Measured memory_bytes: 8576
#include<queue>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define LL long long
using namespace std;

int N,K,X,Y=9999,A[106];

int main()
{
	scanf("%d%d",&N,&K);
	for(int i=1,j=1;i<=N;i++)
	{
		A[j++]++;
		if(j==K+1) j=1;
	}
	
	for(int i=1;i<=K;i++)
	{
		X=max(X,A[i]);
		Y=min(Y,A[i]);
	} 
	printf("%d",X-Y);
} 

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using i64 = long long;

int main() {
    i64 a, b, c, d;
    std::cin >> a >> b >> c >> d;
    std::cout << std::max({
        a * c,
        b * c,
        a * d,
        b * d,
    }) << std::endl;

    return 0;
}


Measured memory_bytes: 3628
#include<iostream>

using namespace std;

typedef long long llint;

const int MAXN = 10005;

llint n, x, y;
llint a[MAXN], b[MAXN];

int main () {
	cin >> n;
	for (int i=0; i<n; i++) {
		cin >> a[i];
		x-=a[i];
	}
	for (int i=0; i<n; i++) {
		cin >> b[i];
		x+=b[i];
	}
	y=x;
	for (int i=0; i<n; i++) {
		if (a[i]%2!=b[i]%2) {
			b[i]++;
			y--;
		}
		if (a[i]>b[i]) y-=a[i]-b[i]; else x-=(b[i]-a[i])/2;
	}
	if (x>=0 && y>=0 && 2*x==y) cout << "Yes"; else cout << "No";
	return 0;
}

Measured memory_bytes: 384
#include<stdio.h>
#define Max 10000

int main()
{
  int i,j,h,n,q,S[Max],T[Max];

  scanf("%d",&n);
  for(i=0;i<n;i++)
    scanf("%d",&S[i]);
  scanf("%d",&q);
  for(i=0;i<q;i++)
    scanf("%d",&T[i]);
 
  h=0;
  for(i=0;i<q;i++)
    {
      S[n]=T[i];
      for(j=0;j<=n;j++)
	{
	  if(j==n) break;
	  else if(S[j]==T[i]){
	    h++;
	    break;
	  }
	}
    }
  printf("%d\n",h);
  return 0;
}

Measured memory_bytes: 644
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int main() {
    string s;
    cin >> s;
    cout << s.substr(0,5) << " " << s.substr(6,7) << " " << s.substr(14) << endl;

    return 0;
}

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

int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

  string s;
  cin>>s;
  bool f=false;
  if(s[0]==s[1]&&s[1]==s[2]){
    f=true;
  }else if (s[1]==s[2]&&s[2]==s[3]){
    f=true;
  }

  if(f){
    puts("Yes");
  }else{
    puts("No");

  }

  return 0;
}


Measured memory_bytes: 256
n = int(input())
cnt = 0
c = [[0 for _ in range(10)] for _ in range(10)]
for k in range(1, n + 1):
    a, b = int(str(k)[0]), int(str(k)[-1])
    c[a][b] += 1
for i in range(0, 10):
    for j in range(0, 10):
        cnt += c[i][j] * c[j][i]
print(cnt)

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


int main()
{    
    
    int N,X,Y;
    cin >> N >> X >> Y;

    int ans[N-1]={0};
    
    int L;
    for  (int  i = 1; i < N; ++i) {
        for  (int  j = i+1; j < N+1; ++j) {
            L=j-i;
            
            if (i <= X && j >= Y){
                L=j-Y+X-i+1;
            }

            if (i >= X && j <= Y){
                if (L>Y-j+i-X+1){
                    L=Y-j+i-X+1;
                }
            }

            if (i < X && j < Y && j > X){
                if (L>Y-j+X-i+1){
                    L=Y-j+X-i+1;
                }
            }

            if (i > X && i < Y && j > Y){
                if (L>j-Y+i-X+1){
                    L=j-Y+i-X+1;
                }
            }


            ans[L-1]+=1;
        }
    }
    

    for  (int  i = 0; i < N-1; ++i) {
        cout << ans[i] << endl;
    }
    return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define PI 3.14159265359

int main() {
    ll n,m,x,c[20],a[20][20],mm=900000000;
    bool flag = true;
    cin >> n >> m >> x;
    for(int i=0;i<n;i++){
        cin >> c[i];
        for(int j=0;j<m;j++){
            cin >> a[i][j];
        }
    }
    for(int bit = 0;bit < (1<<n);bit++){
        flag=true;
        ll hogev[m]={0},hogem=0;
        for(int i=0;i<n;i++){
            if(bit & (1<<i)){
                hogem += c[i];
                for(int j=0;j<m;j++){
                    hogev[j]+=a[i][j];
                }
            }
        }
        for(int j=0;j<m;j++){
            if(hogev[j] < x)flag=false;
        }
        if(flag){
            if(mm>hogem) mm = hogem;
        }
    }
    if(mm != 900000000)cout << mm << endl;
    else cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 3628
#include<cstdio>
#include<cstring>
using namespace std;
int n,ans;
char s[5005];
unsigned long long hash[5005],power[5005];
inline bool check(int len){
	for(register int i=0;i<=n-(len<<1)+1;i++){
		for(register int j=i+len;j<=n-len+1;j++){
			if((hash[i+len]-hash[i]*power[len])==(hash[j+len]-hash[j]*power[len])){
				return true;
			}
		}
	}
	return false;
}
void Binary(int l,int r){
	if(l>r)return;
	int mid=(l+r)>>1;
	if(check(mid)){
		ans=mid;
		Binary(mid+1,r);
	}else Binary(l,mid-1);
}
int main(){
	scanf("%d\n",&n);
	scanf("%s",s+1);
	power[0]=1;
	for(register int i=1;i<=5004;i++)power[i]=(power[i-1]*233);
	for(register int i=1;i<=n;i++)hash[i]=(hash[i-1]*233+s[i]-'a'+1);
	Binary(0,n);
	printf("%d\n",ans);
}

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

using namespace std;

int main(){
	
	int n;
	cin>>n;
	int arr[300000];
	for(int i=0;i<n;i++){
		cin>>arr[i];
	}
	
	sort(arr,arr+n);
	for(int i=0;i<n;i++){
		
		if(arr[i]==arr[i+1]){
			cout<<"NO";
			return 0;
		}
	}
	cout<<"YES";
	
	return 0;
}

Measured memory_bytes: 1024
import java.util.*;

public class Main {

	static final int r = 2019;

	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		sc.close();
		long ans = 0;
		int n = s.length();
		long mod[] = new long[r];
		int t[] = new int[n + 1];
		int m = 1;
		for(int i = n - 1; i >= 0; --i){
			int tmp = t[i + 1] + m * (int)(s.charAt(i) - '0');
			tmp %= r;
			t[i] = tmp;
			if(tmp == 0)ans++;
			ans += mod[tmp];
			mod[tmp]++;
			m *= 10;
			m %= r;
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 40948
n, m, x = list(map(int, input().split()))
a = [list(map(int, input().split())) for _ in range(1)][0]

cost1 = 0
for i in range(x, n+1):
    if i in a:
        cost1 += 1
    
cost2 = 0
for i in range(x):
    i = x-i
    if i in a:
        cost2 += 1
print(min(cost1, cost2))


Measured memory_bytes: 3064
#include<stdio.h>

void swap(unsigned long *a,unsigned long *b){
unsigned long temp;
temp=(*a);
(*a)=(*b);
(*b)=temp;

return;
}


unsigned long getGCM(unsigned long x,unsigned long y){
unsigned long a,b;

 if(x%y==0)return y;
 else{
  b=x%y;
  a=getGCM(y,b);
 }

}



unsigned long getLCM(unsigned long x,unsigned long y){
unsigned long gcm;
unsigned long lcm;
if(x<y)swap(&x,&y);
gcm=getGCM(x,y);

lcm=x*y/gcm;

return lcm;
}


unsigned long main(){
unsigned long n,i,j;
unsigned long A[10];


scanf("%d",&n);
for(i=0;i<n;i++)scanf("%ld",&A[i]);

for(i=n-1;i>0;i--){
 for(j=0;j<i;j++){
   A[j]=getLCM(A[j],A[j+1]);

 }

}
 
printf("%ld\n",A[0]);

return 0;
}


Measured memory_bytes: 2044
#include <iostream>
#include <map>
#include <vector>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <climits>
#include <stack>
#include <queue>
#include <set>
#include <cctype>
#include <bitset>
#include <type_traits>

#include <list>
using namespace std;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define YES(j) cout << (j ? "YES" : "NO") << endl;
#define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
#define yes(j) std::cout << (j ? "yes" : "no") << endl;

int main(void)
{
    int n;
    cin >> n;
    vector<long long> a;
    REP(i, n)
    {
        long long tmp;
        cin >> tmp;
        a.push_back(tmp);
    }

    //a[0]--;
    long long maxv = a[0];
    for (int i = 1; i < n; i++)
    {
        if (a[i] < a[i - 1])
        {
            if (maxv - a[i] > 1)
            {
                Yes(0);
                return 0;
            }
        }
        maxv = max(maxv, a[i]);
    }
    Yes(1);
}

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

int main() {
	int N;
	double ans;

	cin >> N;

	if (N % 2 == 0) {
		ans = 1.00000 / 2;
	}
	else if (N == 1) {
		ans = 1;
	}
	else {
		ans = (double)(N / 2 + 1) / N;
	}

	cout << ans;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        int a = sc.nextInt();
        int b = sc.nextInt();

        if (a + b >= 10) {
            System.out.println("error");
        } else {
            System.out.println(a + b);
        }

    }

}

Measured memory_bytes: 20948
N = int(input())
S = input()
r = []
g = []
b = []
for idx, i in enumerate(S, 1):
    if i == 'R':
        r.append(idx)
    elif i == 'G':
        g.append(idx)
    else:
        b.append(idx)

b = set(b)
cnt = len(b) * len(r) * len(g)
for i in r:
    original = i
    for j in g:
        i = original
        if i > j:
            i, j = j, i
        d = j - i
        if j + d in b:
            cnt -= 1
        if i - d in b:
            cnt -= 1
        if d % 2 == 0 and (i + j) // 2 in b:
            cnt -= 1
print(cnt)


Measured memory_bytes: 9316
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
 
int main() {
  int a, b;
  cin >> a >> b;
  int ans = 0;
  if (a > 9 || b > 9) ans = -1;
  else ans = a*b;
  
  cout << ans << endl;
  return 0;
}

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

template <typename T>
class weighted_quick_find {
	vector<pair<int, T>> data;
	vector<vector<int>> all;
public:
	weighted_quick_find(int n) : data(n), all(n, vector<int>(1)) {
		for (int i = 0; i < n; i++) {
			data[i].first = i;
			all[i][0] = i;
		}
	}
	void unite(int a, int b, T d) {
		if (same(a, b)) return;
		d += data[a].second - data[b].second;
		a = data[a].first;
		b = data[b].first;
		if (all[a].size() < all[b].size()) swap(a, b), d = -d;
		for (auto& id : all[b]) {
			data[id] = { a, data[id].second + d };
		}
		all[a].insert(all[a].end(), all[b].begin(), all[b].end());
	}
	bool same(int a, int b) const {
		return data[a].first == data[b].first;
	}
	T dist(int a, int b) const {
		return data[b].second - data[a].second;
	}
};

int main()
{
	ios::sync_with_stdio(false), cin.tie(0);
	int n, q;
	cin >> n >> q;
	weighted_quick_find<int> wqf(n);
	while (q--) {
		int com, x, y;
		cin >> com >> x >> y;
		if (com == 0) {
			int z;
			cin >> z;
			wqf.unite(x, y, z);
		}
		else if (wqf.same(x, y)) {
			printf("%d\n", wqf.dist(x, y));
		}
		else {
			puts("?");
		}
	}
	return 0;
}



Measured memory_bytes: 10276
n,k=map(int,input().split())
v=[int(i) for i in input().split()]
r=min(n,k)
ans=0
for a in range(r+1):
    for b in range(r-a+1):
        if b>=1:
            q=v[:a]+v[-b:]
        else:
            q=v[:a]
        t=k-a-b
        m=0
        for i in sorted(q):
            if i<0 and t>0:
                m+=abs(i)
                t-=1
        ans=max(ans,m+sum(q))
print(ans)
        

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

string reverse(string s)
{
    reverse(begin(s), end(s));
    return s;
}

bool all_zero(const string& s)
{
    for (const char c : s)
        if (c != '0')
            return false;
    return true;
}

// You have a list of pairs (a_i, b_i).
// Minimize A + B, subject to the constraint that
// for each i, either a_i <= A or b_i <= B
int f(vector<pair<int, int>> costs)
{
    if (costs.empty()) return 0;

    sort(begin(costs), end(costs));
    int x = costs.back().first, y = 0, result = x+y;
    while (!costs.empty())
    {
        y = max(y, costs.back().second);
        costs.pop_back();
        x = costs.empty() ? 0 : costs.back().first;
        result = min(result, x+y);
    }
    return result;
}

int solve(const string& A, const string& B)
{
    if (all_zero(B))
        return all_zero(A) ? 0 : -1;

    const int N = int(A.length());

    vector<int> r(N), l(N);
    for (int i = 0; i < N; i++)
    {
        for (r[i] = 0; B[(i+r[i])%N] != '1'; r[i]++) ;
        for (l[i] = 0; B[(i-l[i]+N)%N] != '1'; l[i]++) ;
    }

    int result = numeric_limits<int>::max();
    for (int shift = 0; shift < N; shift++)
    {
        int mismatches = 0;
        for (int i = 0; i < N; i++)
            mismatches += A[i] != B[(i+shift)%N];

        vector<pair<int, int>> costs;
        for (int i = 0; i < N; i++)
            if (A[i] != B[(i+shift)%N] && r[i] > shift)
                costs.push_back({l[i], r[i]-shift});

        result = min(result, shift + 2*f(costs) + mismatches);
    }
    return result;
}

int main()
{
    string A, B;
    cin >> A >> B;
    cout << min(solve(A, B), solve(reverse(A), reverse(B))) << endl;
}


Measured memory_bytes: 256
#include <memory.h>

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>

using namespace std;

#define mod 1000000007

int main() {
	int n;
	cin >> n;
	if (n == 3) {
		cout << "Yes" << endl;
		for (int i = 1; i < 2 * n; i++) {
			cout << i << " " << i + 1 << endl;
		}
		return 0;
	}
	int tmp = 0;
	while ((1 << tmp) < n) tmp++;
	if ((1 << tmp) == n) {
		cout << "No" << endl;
		return 0;
	}
	tmp--;
	cout << "Yes" << endl;
	tmp = (1 << tmp) - 1;
	// 頂点番号1~tmpを並べてつなげる
	for (int i = 1; i < tmp; i++) {
		cout << i << " " << i + 1 << endl;
	}
	// 頂点n + 1とtmpをつなげる
	cout << tmp << " " << n + 1 << endl;
	// 頂点n + 1 ~ n + tmpを並べてつなげる
	for (int i = 2; i <= tmp; i++) {
		cout << n + i - 1 << " " << n + i << endl;
	}
	if (n == tmp) {
		return 0;
	}
	// 頂点tmp + 1、tmp + 2を頂点1につなげる
	cout << 1 << " " << tmp + 1 << endl;
	cout << 1 << " " << tmp + 2 << endl;
	// 頂点tmp + 1 + nをtmp + 2に、tmp + 2 + nをtmp + 1につなげる
	cout << tmp + 1 << " " << tmp + 2 + n << endl;
	cout << tmp + 2 << " " << tmp + 1 + n << endl;
	int tmpp = 0;
	for (int i = 2; i <= tmp; i += 2) {
		tmpp ^= (i ^ (i - 1));
		// cout << tmpp << endl;
		if (((tmp + 1) ^ tmpp) <= n) {
			cout << tmp + 1 << " " << ((tmp + 1) ^ tmpp) << endl;
			cout << i << " " << ((tmp + 1) ^ tmpp) + n << endl;
		}
		if (((tmp + 2) ^ tmpp) <= n) {
			cout << tmp + 2 << " " << ((tmp + 2) ^ tmpp) << endl;
			cout << i << " " << ((tmp + 2) ^ tmpp) + n << endl;
		}
	}
}

Measured memory_bytes: 2688
def upper_square(A: int, B: int) -> int:
    """C**2 < A*B を満たす最大の C を求めます。
    """
    l, r = min(A, B), max(A, B)
    while r - l > 1:
        m = (l + r) // 2
        if m * m < A * B:
            l = m
        else:
            r = m
    return l


def query(A: int, B: int) -> int:
    A, B = min(A, B), max(A, B)
    if A == B:
        # (1, 2A-1), ..., (A-1, A+1), (A+1, A-1), ..., (2A-1, 1)
        # が最大。
        return 2 * A - 2
    if B == A + 1:
        # (1, 2A), ..., (A-1, A+2), (A+2, A-1), ..., (2A, 1)
        # が最大。
        return 2 * A - 2

    # C = A
    # while (C + 1) ** 2 < A * B:
    #     C += 1
    C = upper_square(A, B)

    if A * B <= C * (C + 1):
        # (1, A+B−1), ..., (A−1, B+1), (A+1, 2C−A−1), ..., (C, C), ..., (2C−1, 1)
        # が最大。
        return 2 * C - 2

    # (1, A+B−1), ..., (A−1, B+1), (A+1, 2C−A), ..., (C, C+1), (C+1, C), ...,(2C, 1)
    # が最大。
    return 2*C - 1


def worst_case(Q: int, queries: list) -> list:
    return [query(A, B) for A, B in queries]


if __name__ == "__main__":
    Q = int(input())
    queries = [tuple(map(int, input().split())) for _ in range(Q)]
    ans = worst_case(Q, queries)
    for a in ans:
        print(a)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1LL << 60;
 
int main()
{
    int N;
    cin >> N;
    vector<int> A(N);
    double sum = 0;
    double kari = 0;
    double ans = 0;
    for (int i = 0; i < N; i++)
    {
        cin >> A[i];
        kari = 1.0 / A[i];
        sum += kari;
 
    }
    ans = 1.0 / sum;
    cout << fixed << ans << setprecision(16) << endl;
}

Measured memory_bytes: 256
// ABC119
// A - Still TBD
#include<bits/stdc++.h>

using namespace std;

int main(){
    string s;
    cin >> s;
    if(s[5]=='0' && s[6]<'5') cout << "Heisei" << endl;
    else cout << "TBD" << endl;
    return 0;
}


Measured memory_bytes: 256
n=gets.to_i
l=(n-1).times.map{gets.split.map(&:to_i)}
ans=[]
(n-1).times{ |i|
  ci,si,fi=l[i]
  e=ci+si
  (i+1).upto(n-2){ |j|
    cj,sj,fj=l[j]
    x=e%fj>0 ? e+fj-e%fj: e
    e=[x,sj].max
    e+=cj
  }
  ans << e
}
ans << 0
puts ans


Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define VL vector<ll>
#define VS vector<string>
#define VB vector<bool>
#define VP vector<pair<ll,ll>>
#define VVL vector<vector<ll>>
#define VVP vector<vector<pair<ll,ll>>>
#define PL pair<ll,ll>
#define ALL(v) (v).begin(), (v).end()

int main() {
    ll N;
    cin>>N;
    vector<long double> A(N);
    long double rsum=0;
    rep(i,0,N){
      cin>>A[i];
      rsum+=1/A[i];
    }
    long double ans=1/rsum;
    cout<<fixed<<setprecision(15)<<ans<<endl;
    return 0;
}

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

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

  int answerk=-1, answerfk=-1, answertk=-1;

  int a = Y/1000;

  if (a == N) {
    answerk = N;
    answerfk = 0;
    answertk = 0;
  }

  int b = a - N;

  for(int j=b/4; j>=0; j--) {
    if((b-4*j) % 9 == 0 && (b-4*j)/9 >= 0 && (b-4*j)/9 <= N-j) {
      answerfk = j;
      answertk = (b-4*j) / 9;
      answerk = N-j-answertk;
    }
  }
  cout << answertk << " " << answerfk << " " << answerk << endl;
  return 0;
}
  



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using V = vector<int>;
using VV = vector<vector<int>>;
using VVV = vector<vector<vector<int>>>;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using VVVL = vector<vector<vector<ll>>>;
using pq = priority_queue<int>;
template<class T>
using P = pair<T, T>;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define REP(i,k,n) for(int i=(k);i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define output(x,y) cout << fixed << setprecision(y) << x << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
int under = (1 << 31);
int upper = under - 1;
ll UNDER = (1LL << 63);
ll UPPER = UNDER - 1;
const int MOD = 1e9 + 7;
const long double pi = 3.141592653589793;
int main() {
	int n;
	cin >> n;
	string s;
	cin >> s;
	V Blacks(n + 1, 0);
	rep(i, n) {
		if (s[i] == '.') Blacks[0]++;
	}
	rep1(i, n) {
		int I = i - 1;
		Blacks[i] = Blacks[i - 1];
		if (s[I] == '.') Blacks[i]--;
		else Blacks[i]++;
	}
	cout << *min_element(all(Blacks)) << endl;
	return 0;
}

Measured memory_bytes: 1412
<?php
$a = trim(fgets(STDIN));
$b = trim(fgets(STDIN));

$n = explode(' ', $a);
$h = explode(' ', $b);

sort($h);

$ans =0;
for ($i = 0; $i < $n[0] - $n[1]; $i++) {
    $ans += (int)$h[$i];
}

echo $ans;

Measured memory_bytes: 23200
#include<iostream>
#include<iomanip>
#include<cassert>
#include<stdexcept>
#include<utility>
#include<functional>
#include<numeric>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<array>
#include<stack>
#include<queue>
#include<deque>
#include<vector>
#include<complex>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<string>
#include<bitset>
#include<memory>
using namespace std;
using ll=long long;

int main(){
    int n,k,s,t;
    cin>>n>>k>>s>>t;
    vector<int> a(n);
    for(int i=0;i<n;i++) cin>>a[i];
    vector<int> flag(18);
    for(int i=0;i<18;i++){
        int sb = (s>>i)&1;
        int tb = (t>>i)&1;
        if(sb==1 && tb==0){
            cout<<0<<endl;
            return 0;
        }
        if(sb==1){
            vector<int> a2;
            for(int j=0;j<n;j++){
                if((a[j]>>i)&1){
                    a2.push_back(a[j]);
                }
            }
            a=a2;
        }
        else if(tb==0){
            vector<int> a2;
            for(int j=0;j<n;j++){
                if(!((a[j]>>i)&1)){
                    a2.push_back(a[j]);
                }
            }
            a=a2;
        }
        else{
            flag[i] = true;
        }
        n = a.size();
    }

    
    vector<vector<ll>> comb(60,vector<ll>(60,1));
    for(int i=2;i<60;i++){
        for(int j=1;j<i;j++){
            comb[i][j] = comb[i-1][j-1]+comb[i-1][j];
        }
    }
    
    vector<vector<ll>> comb_sum(60,vector<ll>(60,1));
    for(int i=2;i<60;i++){
        for(int j=1;j<=i;j++){
            comb_sum[i][j]=comb_sum[i][j-1]+comb[i][j];
        }
    }
    
    

    auto choose=[&](ll x){
        if(x<k) return (1LL<<x)-1;
        else return comb_sum[x][k]-1;
    };

    // cerr<<comb_sum[3][3]<<endl;

    ll ans = 0;

    vector<int> num(n);
    for(int bit=0;bit<(1<<18);bit++){
        bool brk=false;
        for(int i=0;i<18;i++){
            if(((bit>>i)&1) && !flag[i]){
                brk=true;
            }
        }
        if(brk) continue;

        fill(num.begin(),num.end(),0);
        for(int i=0;i<18;i++){
            if(!((bit>>i)&1)) continue;
            for(int j=0;j<n;j++){
                num[j]+=(((a[j]>>i)&1)<<i);
            }
        }
        map<int,int> mp;
        for(int i=0;i<n;i++){
            mp[num[i]]++;
        }
        

        int cnt = 0;
        for(int i=0;i<18;i++){
            if((bit>>i)&1) cnt++;
        }

        int sign = (cnt%2 ? -1 : 1);
        ll piyo = 0;
        // cerr<<"#"<<bit<<endl;
        for(auto& e:mp){
            // cerr<<e.second<<" ";
            piyo+=choose(e.second);
        }
        // cerr<<endl;
        // cerr<<bit<<" "<<piyo<<endl;
        ans+=sign*piyo;
    }
    cout<<ans<<endl;
    
    return 0;
}


Measured memory_bytes: 3672
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
#define era(t) t.erase(unique(be(t)),t.end())
#define doublecout(a) cout<<fixed<<setprecision(12)<<a<<endl;
typedef long long ll;
using namespace std;
const ll mod=1000000007,mod9=1000000009;
template <class T>inline T lcm(T a,T b){return (a*b/__gcd(a,b));}
bool solve(string s){
    if(s=="kyoto"||s=="tokyo")return true;
    else return false;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,m,a,b,ans=0;
    cin>>n>>m;
    vector<pair<int,int> > v;
    for(int i=0;i<m;i++){
        cin>>a>>b;
        v.pb(make_pair(b,a));
    }
    sort(be(v));
    for(int i=0;i<m;){
        int maki=v[i].first;
        ans++;
        while(i<m&&maki>v[i].second){
            i++;
        }
    }
    cout << ans<<endl;
    return 0;
}



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

int comp(const void* a, const void* b)
{ return *(int*)a > *(int*)b ; }

int findNumberOfTriangles(int arr[], int n)
{

    qsort(arr, n, sizeof( arr[0] ), comp);


    int count = 0;

    for (int i = 0; i < n - 2; ++i)
    {

        int k = i + 2;


        for (int j = i + 1; j < n; ++j)
        {

            while (k < n && arr[i] + arr[j] > arr[k])
            ++k;


            if(k > j)
            count += k - j - 1;
        }
    }

    return count;
}

int main()
{
    int i,j,k,n,m,p,q;
    cin>>n;
    int arr[n];
    for(i=0;i<n;i++)
    {
        cin>>arr[i];
    }
    int size = sizeof( arr ) / sizeof( arr[0] );

    cout<<findNumberOfTriangles( arr, size )<<endl;

    return 0;
}


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

using namespace std;

int main(void){
    int x, y, z;
    cin >> x >> y >> z;
    int n = x / (y+z);
    if(x % (y+z) >= z) cout << n << endl;
    else cout << n-1 << endl;
    return 0;
}

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

using namespace std;

using ll = long long;

int pay(const int b, int m) {
    if (m < b) return 0;
    int p = b;
    while (b * p <= m) p *= b;
    return p;
}

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

    int n;
    cin >> n;

    int ans = n;
    for (int i = 0; i <= n; ++i) {
        int res = i, cnt = 0, m6, m9;

        while ((m6 = pay(6, res)) != 0) {
            ++cnt;
            res -= m6;
        }

        res = n - (i - res);
        while ((m9 = pay(9, res)) != 0) {
            ++cnt;
            res -= m9;
        }

        ans = min(ans, cnt + res);
    }

    cout << ans << endl;


    return 0;
}


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

int m,nmin,nmax,ans,gap;
int a[201];
int main(){
	while(1){
		cin >>m >>nmin >>nmax;
		if(!(m||nmin||nmax))break;
		for(int i=0;i<m;i++){
			cin >>a[i];
		}
		gap=0;
		for(int i=nmin;i<=nmax;i++){
			if(a[i-1]-a[i]>=gap){
				ans=i;
				gap=a[i-1]-a[i];
			}

		}
	//for(int i=0;i<m;i++){
	//	cout << a[i]<<" ";
	//}
		cout << ans<<endl;
	}
	
}

Measured memory_bytes: 3088
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i ++)
using namespace std;
using ll = long long;
using PL = pair<ll,ll>;
using P = pair<int,int>;
constexpr int INF = 1000000000;
constexpr long long HINF = 1000000000000000;
constexpr long long MOD = 1000000007;// = 998244353;
constexpr double EPS = 1e-4;
constexpr double PI = 3.14159265358979;

int main() {
    int a,b; cin >> a >> b;
    int ans = (a + b + 1)/2;
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 3556
/*
 * main.c
 *
 *  Created on: 2019/12/29
 *      Author: family
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define MAX(a,b) (a > b ? a : b)
#define MIN(a,b) (a > b ? b : a)
typedef long long int ll;

int main()
{
	char S[101] = {0}, T[101] = {0};
	scanf("%s %s", S, T);
	printf("%s%s\n", T, S);
    return 0;
}


Measured memory_bytes: 128
main(n,a,b,t,i,f){
    scanf("%d",&n);
    while(n--){
        a=b=-100;
        for(i=f=0;i<10;i++){
            scanf("%d",&t);
            if(a<t)          a=t;
            else if(b<t) b=t;
            else    f=1;
        }
        puts(f?"NO":"YES");
    }
    exit(0);
}

Measured memory_bytes: 580
#include<bits/stdc++.h>
#define mt make_tuple
#define mp make_pair
#define pu push_back
#define INF 1000000001
#define MOD 1000000007
#define ll long long int
#define ld long double
#define vi vector<int>
#define vll vector<long long int>
#define fi first
#define se second
#define pr(v) { for(int i=0;i<v.size();i++) { v[i]==INF? cout<<"INF " : cout<<v[i]<<" "; } cout<<endl;}
#define t1(x)                cerr<<#x<<" : "<<x<<endl
#define t2(x, y)             cerr<<#x<<" : "<<x<<" "<<#y<<" : "<<y<<endl
#define t3(x, y, z)          cerr<<#x<<" : " <<x<<" "<<#y<<" : "<<y<<" "<<#z<<" : "<<z<<endl
#define t4(a,b,c,d)          cerr<<#a<<" : "<<a<<" "<<#b<<" : "<<b<<" "<<#c<<" : "<<c<<" "<<#d<<" : "<<d<<endl
#define t5(a,b,c,d,e)          cerr<<#a<<" : "<<a<<" "<<#b<<" : "<<b<<" "<<#c<<" : "<<c<<" "<<#d<<" : "<<d<<" "<<#e<<" : "<<e<<endl
#define t6(a,b,c,d,e,f)          cerr<<#a<<" : "<<a<<" "<<#b<<" : "<<b<<" "<<#c<<" : "<<c<<" "<<#d<<" : "<<d<<" "<<#e<<" : "<<e<<" "<<#f<<" : "<<f<<endl
#define GET_MACRO(_1,_2,_3,_4,_5,_6,NAME,...) NAME
#define t(...) GET_MACRO(__VA_ARGS__,t6,t5, t4, t3, t2, t1)(__VA_ARGS__)
#define _ cerr<<"here"<<endl;
#define __ {ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);}


using namespace std;

int main()
{
  __;
  string s,t;
  cin>>s>>t;
  s = "$"+s;
  t = "$"+t;
  int n = s.size(),m = t.size();
  vector<vector<int> > dp(n,vector<int>(m));
  vector<vector<int> > keep(n,vector<int>(m));
  dp[0][0] = s[0]==t[0];
  if(dp[0][0]) keep[0][0] = 3;
  for(int i=0;i<n;i++)
  {
    for(int j=0;j<m;j++)
    {
      if(i==0 && j==0) continue;
      else if(i==0)
      {
        dp[i][j] = dp[i][j-1];
        keep[i][j] = 1;
      }
      else if(j==0)
      {
        dp[i][j] = dp[i-1][j];
        keep[i][j] = 2;
      }
      else
      {
        int a = s[i]==t[j];
        int max1 = -1;
        if(dp[i-1][j-1] + a > dp[i-1][j]) {max1 = dp[i-1][j-1]+a; keep[i][j] = 3;}
        else {max1 = dp[i-1][j]; keep[i][j] = 2;}
        if(dp[i][j-1] > max1) {max1 = dp[i][j-1]; keep[i][j] = 1;}
        dp[i][j] = max1;
      }
    }
  }

  int i = n-1, j = m-1;
  string k;
  while(i>=0 && j>=0)
  {
    if(i==0 && j==0) break;
    int a = keep[i][j];
    if(a==3)
    {
      k+=s[i];
      i = i-1;
      j = j-1;
    }
    else if(a==2)
    {
      i = i-1;
    }
    else
    {
      j = j-1;
    }
  } 
  // cout<<dp[n-1][m-1]<<endl;
  reverse(k.begin(),k.end());
  cout<<k<<endl;
  // for(int i=0;i<n;i++) {for(int j=0;j<m;j++) cout<<dp[i][j]<<" "; cout<<endl;}
  // for(int i=0;i<n;i++) {for(int j=0;j<m;j++) cout<<keep[i][j]<<" "; cout<<endl;}
  return 0;
}



Measured memory_bytes: 72064
#include <bits/stdc++.h>
 
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pii;
typedef tuple<ll, ll, ll> ti;
 
#define REP(a,b,c) for(ll a=(b);a<(c);a++)
#define PER(a,b,c) for(ll a=(b);a>=(c);a--)
 
ll ii(){ ll x; cin >> x; return x; }
string is(){ string x; cin >> x; return x; }
void oi(ll x){ cout << x; }
void od(ld x){ cout << fixed << setprecision(10) << x; }
void os(string x){ cout << x; }
void oie(ll x){ cout << x << endl; }
void ode(ld x){ cout << fixed << setprecision(10) << x << endl; }
void ose(string x){ cout << x << endl; }
void oe(){ cout << endl; }
 
int main(){
    ld r;
    cin >> r;
    ode(2*r*M_PI);
 
    return 0;
}

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

void solve(){
	string str;
	cin>> str;
	for(int i = 0; i < str.size(); i++){
		cout << 'x';
	}
	cout << "\n";
	
}

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

}

Measured memory_bytes: 3564
import java.io.UnsupportedEncodingException;
import java.util.*;

public class Main {

	public static void main(String[] args) throws UnsupportedEncodingException {

		Scanner sc = new Scanner(System.in);

		int ans = 0;

		int a = sc.nextInt();
		int b = sc.nextInt();

		if (a <= b) {
			ans = a;
		} else {
			ans = a - 1;
		}

		System.out.println(ans);
		sc.close();
	}
}


Measured memory_bytes: 22996
#include<bits/stdc++.h>
#define V vector
#define VI vector<int>
#define VVI vector<vector<int>>
#define REP(i,n) for(int i=0;i<(n);i++)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define MOD 1000000007
#define INF 1e9
#define F first
#define S second
#define All(x) (x).begin(),(x).end()
using namespace std;
const double PI = acos(-1);
typedef long long ll;

template <class T>
class SegTree{
    int n; //葉の数(要素数)
    vector<T> data; //データ格納用
    T def; //初期値で単位元
    function<T(T,T)> operation; //区間クエリ使用
    function<T(T,T)> update; //点更新で使用

    //区間[a,b)の総和
    T _query(int a,int b,int k,int l,int r){
        if(r<=a||b<=l)return def; //範囲外だから
        if(a<=l&&r<=b)
            return data[k]; //a,l,r,bで完全に含まれる
        else {
            T c1=_query(a,b,2*k+1,l,(l+r)/2); //左の子
            T c2=_query(a,b,2*k+2,(l+r)/2,r); //右の子
            return operation(c1,c2);
        }
    }

  public:
    // _n:必要サイズ, _def:初期値かつ単位元, _operation:クエリ関数,
    // _update:更新関数
    SegTree(size_t _n,T _def,function<T(T,T)> _operation,function<T(T,T)> _update)
        :  def(_def),operation(_operation),update(_update){
            n=1;
            while(n<_n){
                n*=2;
            }
            data=vector<T>(2*n-1,def);
    }

    // 場所i(0-indexed)の値をxで更新
    void change(int i,T x){
        i+=n-1;
        data[i]=update(data[i],x);
        while(i>0){
            i=(i-1)/2;
            data[i]=operation(data[i*2+1],data[i*2+2]);
        }
    }

    //[a,b)の区間クエリを実行
    T query(int a,int b){
        return _query(a,b,0,0,n);
    }

    T operator[](int i){
        return data[i+n-1];
    }
};

int main(void){
  int N,Q;
  cin>>N>>Q;
  SegTree<ll> st(N,(1ll<<31)-1,
                 [](ll a,ll b){return min(a,b);},
                 [](ll a,ll b){return b;});
  
  REP(i,Q){
    int c,x,y;
    cin>>c>>x>>y;
    if(c==0)st.change(x,y);
    else cout<<st.query(x,y+1)<<endl;
  }

  return 0;
}


Measured memory_bytes: 4976
import java.util.*;

public class Main {             
    
  public static void main(String[] args) {
   
    Scanner sc = new Scanner(System.in);                                              
    
    int N = sc.nextInt();
    
    int A = sc.nextInt();
    
    System.out.println(N*N - A);                    
    
  }  
}



Measured memory_bytes: 21844
import Foundation

#if swift(>=4.0)
extension String {
    func split(by separator: String) -> [String] {
        return self.components(separatedBy: separator)
    }
    func toArray() -> [String] {
        return self.map{String($0)}
    }
}
func exponentiate(_ lhs: Int, _ rhs: Int) -> Int {
    return (0..<rhs).reduce(1){i,_ in i*lhs}
}
#else
extension String {
    func split(by separator: String) -> [String] {
        return self.componentsSeparatedByString(separator)
    }
    var count: Int {
        return self.characters.count
    }
    func toArray() -> [String] {
        return self.characters.map{String($0)}
    }
    func uppercased() -> String {
        return self.uppercaseString
    }
    func lowercased() -> String {
        return self.lowercaseString
    }
}
//extension Array where Element == String {
//    func joined(separator separator: String) -> String {
//        return self.joinWithSeparator(separator)
//    }
//}
extension Array where Element: Comparable {
    func max() -> Element {
        return self.maxElement()!
    }
    func min() -> Element {
        return self.minElement()!
    }
    func sorted() -> Array {
        return self.sort()
    }
    func reversed() -> Array {
        return self.reverse()
    }
    mutating func sort() {
        self.sortInPlace()
    }
}
extension Array {
    init(repeating: Element, count: Int) {
        self.init(count: count, repeatedValue: repeating)
    }
}
func stride<T: Strideable>(from start: T, to end: T, by stride: T.Stride) -> StrideTo<T> {
    return start.stride(to: end, by: stride)
}
func exponentiate(lhs: Int, _ rhs: Int) -> Int {
    return (0..<rhs).reduce(1){i,_ in i*lhs}
}
#endif
func readInt() -> Int? {
    return Int(readLine()!)
}
func readStringSplit(by separator: String) -> [String] {
    return readLine()!.split(by: separator)
}
func readIntSplit(by separator: String) -> [Int] {
    return readLine()!.split(by: separator).map{Int($0)!}
}

/*************** テストスペース ***************/

//var min, min2, count: Int!
//for i in 1...10 {
//    let x = Int(readLine()!)!
//    if i == 1 {
//        min = x
//        count = 1
//    } else if x < min {
//        min2 = min
//        min = x
//        count = 1
//    } else if x == min && count == 1 {
//        min2 = x
//        count = 2
//    }
//}
//print(min2)

/*************** メインプログラム ***************/

let input = readLine()!
let N = Int(input)!
let sum = input.toArray().reduce(0){$0+Int($1)!}
print(N % sum == 0 ? "Yes" : "No")


Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
	public static void main(String[] args){

		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int n = sc.nextInt();
		int k = sc.nextInt();
		String s = sc.next();



		//int[] a = new int[n];
		int[] b = new int[n-1];

		char before = s.charAt(0);
		for(int i =0 ; i<n-1;i++) {
			if(s.charAt(i+1)==before) {
				b[i]=0;
			}else {
				if(before=='L') {
					b[i]=-1;
				}else {
					b[i]=1;
				}
			}
			 before = s.charAt(i+1);
		}



		long sum = 0;
		int negative =0;
		int positive =0;

		for(int i =0;i<n-1;i++) {
			if(b[i]==-1)negative++;
			if(b[i]==1)positive++;
			if(b[i]==0)sum++;
		}

		int couple=Math.min(negative, positive);
		int isolate =0;
		if(negative!=positive)isolate =1;


		for(int i=0;i<k;i++) {
			if(couple>0) {
				sum=sum+2;
				couple--;
			}else {
				if(isolate>0) {
					sum++;
					isolate--;
				}
			}

		}



		System.out.println(sum);
	}
}
/*
class City{
	int order;
	int prefecture;
	int year;
	int number;
	City(int order,int prefecture, int year){
		this.order = order;
		this.prefecture = prefecture;
		this.year = year;
	}
}
*/

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

int is_adjacent(vector<vector<char>>canvas,int x, int y,int row ,int col){
    if(x-1>=0)
        if(canvas[x-1][y] == '#')
            return 0;
    if(y+1<col)
        if(canvas[x][y+1] == '#')
            return 0;
    if(x+1<row)
        if(canvas[x+1][y] =='#')
            return 0;
    if(y-1>=0)
        if(canvas[x][y-1] == '#')
            return 0;
    return 1;
}
int main(){
    int row,col;
    cin>>row>>col;
    vector<vector<char>>canvas(row);
    for(int i = 0 ; i < row ; ++i){
        vector<char>temp_char;
        for(int j = 0 ; j < col ; ++j){
            char temp;
            cin>>temp;
            temp_char.push_back(temp);
        }
        canvas[i] = temp_char;
    }
    int result = 0;
    for(int i = 0 ; i<row ; ++i){
        for(int j = 0 ; j < col ; ++j){
            if(canvas[i][j] == '#')
                result += is_adjacent(canvas,i,j,row,col);
        }
    }
    if(result==0)
        cout<<"Yes";
    else
        cout<<"No";
}


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

vector<pair<string, int>> decode(string &s) {
    vector<pair<string, int>> res;
    int p = 0;
    while (p < s.size()) {
        if (isdigit(s[p])) {
            int num = 0;
            while (p < s.size() && isdigit(s[p])) num = num * 10 + s[p++] - '0';
            res.emplace_back("", num);
        }
        if (isalpha(s[p])) {
            string str = "";
            while (p < s.size() && isalpha(s[p])) str += s[p++];
            res.emplace_back(str, 0);
        }
    }
    return res;
}

int main() {
    int n; cin >> n;
    string s0; cin >> s0;
    auto p0 = decode(s0);
    while (n--) {
        string s; cin >> s;
        auto p = decode(s);
        cout << (p >= p0 ? "+" : "-") << endl;
    }
    return 0;
}


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

int main() {
  int N,K;
  cin >> N>>K;
  long ans;
  if(K%2!=0){    
    ans=((long)N/K)*((long)N/K)*((long)N/K);
  }
  else{
    ans=((long)N/K)*((long)N/K)*(N/K)+((long)2*N/K-N/K)*((long)2*N/K-N/K)*((long)2*N/K-N/K);
  }
   cout<<ans<<endl;
}

Measured memory_bytes: 256
arr = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
n = int(input())
print(arr[n-1])


Measured memory_bytes: 2940
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import math
import itertools

# NO, PAY-PAY
#import numpy as np
#import statistics
#from statistics import mean, median,variance,stdev

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
 
def main():
    N,M,R = inputMap()
    r = inputList()
    A = [[100000000000000000 for _ in range(N)] for _ in range(N)]
    
    for _ in range(M):
        a,b,c = inputList()
        A[a-1][b-1] = c
        A[b-1][a-1] = c
    
    for i in range(N):
        A[i][i] = 0
        
    A = warshall_floyd(A, N)
        
    ans = -1
    visi = list(itertools.permutations(r))
    for sp in visi:
        tmp = 0
        for i, val in enumerate(sp):
            if i == 0:
                continue
            tmp += A[sp[i-1]-1][sp[i]-1]
            
        if ans == -1 or ans > tmp:
            ans = tmp
            
    print(ans)
        
def warshall_floyd(d, n):
	#d[i][j]: iからjへの最短距離
	for k in range(n):
		for i in range(n):
			for j in range(n):
				d[i][j] = min(d[i][j], d[i][k] + d[k][j])
	return d
		
            	
if __name__ == "__main__":
	main()


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

ll next(ll a, ll b){
	if(b == -1) return a;
	else return min(a, b);
}

int main(void){
	int n, m;
	cin >> n >> m;
	vector<int> a(m), b(m);
	vector<int>c(m, 0);
	vector<int> imp(n+1,0);
	for(int i = 0; i < m; ++i){
		cin >> a[i] >> b[i];
		for(int j = 0; j < b[i]; ++j){
			int tmp;
			cin >> tmp;
			tmp--;
			c[i] |= (1<<tmp);
			imp[tmp] = 1;
		}
	}
	for(int i = 0; i < n; ++i){
		if(imp[i] == 0){
			cout << -1 << endl;
			return 0;
		}
	}
	vector<vector<int>> dp(n+2, vector<int> (1<<n, -1));
	dp[0][0] = 0;
	int cnt = 1e9;
	for(int i = 0; i < n; ++i){
		for(int j = 0; j < m; ++j){
			for(int bit = 0; bit < (1<<n); ++bit){
				if(dp[i][bit] == -1) continue;
				dp[i+1][c[j]|bit] = next(a[j]+dp[i][bit], dp[i+1][c[j]|bit]);
				if((c[j]|bit)+1 == (1<<n)){
					cnt = min(cnt, dp[i+1][c[j]|bit]);
					// cout << cnt << endl;
				}
			}	
		}
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n;
char a[101];
bool jud;
int main(){
	scanf("%s",a);
	int len=strlen(a);
	for(int i = 1;i<len;i++){
		if(a[i]!='9') jud=1;
	}
	if(jud){
		cout<<(a[0]-'0')+9*(len-1)-1<<endl;
		return 0;
	}
	cout<<(a[0]-'0')+9*(len-1)<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

#define rep(i,n) for(int i=0;i<n;i++)
#define deb(n) cout << #n<<' '<<n<<endl

using namespace std;

char field[100][100];
const int dx[4] = { 1,0,-1,0 };
const int dy[4] = { 0,1,0,-1 };

int main() {
    int H, W;
    cin >> H >> W;
    rep(i,W) {
        rep(j,H) {
            cin >> field[i][j];
        }
    }
    bool fflag = false;
    rep(x,W) {
        rep(y, H) {
            if (field[x][y] == '#') {
                rep(a, 4) {
                    int nx = x + dx[a];
                    int ny = y + dy[a];
                    if (0 <= nx&&nx < W && 0 <= ny&&ny < H && field[nx][ny] == '#') {
                        break;
                    }
                    if (a == 3) {
                        fflag = true;
                        goto end;
                    }
                }
            }
        }
    }
end:
    if (fflag) cout << "No" << endl;
    else cout << "Yes" << endl;
}

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

i = abs(b - a) #東側の塔が西から何番目か

hb = (i + 1) * (i // 2) if i % 2 == 0 else (i + 1) * (i // 2) + (i + 1) // 2
print(hb - b)

Measured memory_bytes: 2940
S = input()
L = len(S)
if L%2 == 0:
    for i in range(L-2,0,-2):
        if S[:i//2] == S[i//2:i]:
            ans = i
            break
else:
    for i in range(L-1,0,-2):
        if S[:i//2] == S[i//2:i]:
            ans = i
            break
print(i)

Measured memory_bytes: 2940
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#include <set>
#include <bitset>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <cassert>
#include <ctime>
#define rep(i,m,n) for(i=m;i<=(int)n;i++)
#define mod 1000000007
#define inf 0x3f3f3f3f
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ll long long
#define pi acos(-1.0)
#define pii pair<int,int>
#define ls rt<<1
#define rs rt<<1|1
#define sys system("pause")
const int maxn=2e5+10;
const int N=1e2+10;
using namespace std;
ll gcd(ll p,ll q){return q==0?p:gcd(q,p%q);}
ll qpow(ll p,ll q){ll f=1;while(q){if(q&1)f=f*p%mod;p=p*p%mod;q>>=1;}return f;}
int n,m,k,t,a[maxn];
int main()
{
    int i,j;
    scanf("%d",&n);
    rep(i,1,n)scanf("%d",&a[i]);
    for(i=n;i>=1;i-=2)printf("%d ",a[i]);
    i++;
    if(i<=0)i+=2;
    for(;i<=n;i+=2)printf("%d ",a[i]);
    return 0;
}


Measured memory_bytes: 2944
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

long P = 10^^9 + 7;

void main()
{
    auto nk = readln.split.to!(int[]);
    auto N = nk[0];
    auto K = nk[1];

    auto as = readln.split.to!(int[]);

    long[][] DP;
    DP.length = N;
    foreach_reverse (i, ref dp; DP) {
        dp.length = K+1;
        long[] cs;
        if (i+1 != N) {
            cs.length = K+1;
            cs[0] = DP[i+1][0];
            foreach (k; 1..K+1) cs[k] = (DP[i+1][k] + cs[k-1]); 
        }
        foreach (j; 0..K+1) {
            DP[i][j] = i+1 == N ? (j <= as[i] ? 1 : 0) : (j <= as[i] ? cs[j] : cs[j] - cs[j - as[i] - 1]) % P;
        }
    }

    writeln(DP[0][K]);
}

Measured memory_bytes: 97404
#include<stdio.h>

typedef struct{
	char mark;                     //?§??????????
	int num;
}card;

void swap(card *a,card *b);                    //????????????????????£?¨?	
void bubble(int N,card *B);
void select(int N,card *S);
void printer(int N,card *P,card *P2);

int main(void)
{
	int i,j,n;
	card c[36],c2[36];

	scanf("%d",&n);                              
	for(i = 0;i < n;i++){
		scanf(" %c%d",&c[i].mark,&c[i].num);
	}

	for(i = 0;i < n;i++){   //copy
		c2[i] = c[i];
	}

	bubble(n,c);
	select(n,c2);
	printer(n,c,c2);
	return 0;
}

void swap(card *a,card *b)        //??????????????¢??°
{
	card temp;
	temp = *a;
	*a = *b;
	*b = temp;
	return;
}

void bubble(int N,card *B)          //????????????????????????????????????
{
	int j = 0;
	int flag = 1;
	int i = 0;

	while(flag){
		flag = 0;
		for(j = N - 1;j > i;j--){
			if(B[j].num < B[j - 1].num)swap(&B[j],&B[j - 1]);
			flag = 1;
		}
		i++;
	}
	return;
}

void select(int N,card *S)
{
	int i,j,minj;

	for(i = 0;i < N;i++){
		minj = i;
		for(j = i;j < N;j++){
			if(S[j].num < S[minj].num){
				minj = j;
			}
		}
		swap(&S[i],&S[minj]);
	}
	return;
}

void printer(int N,card *P,card *P2)                        //????????¢??°
{
	int i;

	for(i = 0;i < N;i++){
		if(i != 0)printf(" ");
		printf("%c%d",P[i].mark,P[i].num);
	}
	printf("\n");
	printf("Stable\n");

	for(i = 0; i < N;i++){
		if(i != 0)printf(" ");
		printf("%c%d",P2[i].mark,P2[i].num);
	}
	printf("\n");
	
	int count = 0;
	for(i = 0;i < N;i++){
		if(P[i].mark == P2[i].mark){
			count++;
		}
	}
	if(count == N){
		printf("Stable\n");
	}else{
		printf("Not stable\n");
	}
}          

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

char incrementChar(char x){
    return static_cast<char>(x + 1);
}

int weekToInt(string x){
    int num;
    if(x == "SUN"){
        num = 1;
    }else if(x == "MON"){
        num = 2;
    }else if(x == "TUE"){
        num = 3;
    }else if(x == "WED"){
        num = 4;
    }else if(x == "THU"){
        num = 5;
    }else if(x == "FRI"){
        num = 6;
    }else if(x == "SAT"){
        num = 7;
    }else{
        num = 0;
    }

    return num;
}

int main(){
    string S;
    cin >> S;

    if(S == "Sunny"){
        cout << "Cloudy" << endl;
    }else if(S =="Cloudy"){
        cout << "Rainy" << endl;
    }else{
        cout << "Sunny" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
	"regexp"
)

func main() {
	var line string
	fmt.Scan(&line)
	keyence := "keyence"
	for i := 0; i < len(keyence) + 1; i++ {
		reg := ""
		if i != 0 {
			reg = "^" + reg
		}
		reg = reg + keyence[:i] + ".*" + keyence[i:]
		if i != len(keyence) {
			reg = reg + "$"
		}
		b, _ := regexp.Match(reg, []byte(line))
		if b {
			fmt.Println("YES")
			return
		}
	}
	fmt.Println("NO")
}

Measured memory_bytes: 768