akhauriyash/Code-Regression huggingface dataset:
/* written by : vipin kumar */
#include<iostream>
#include<set>
#include<map>
#include<unordered_set>
#include<cmath>
#include<algorithm>
using namespace std;
#include<vector>
#define int long long int
#define mod 1000000007
int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int value[100001]={0};
	int i,j,k;
	for(i=1;i<=100;i++)
	{
		for(j=1;j<=100;j++)
		{
			for(k=1;k<=100;k++)
			{
				int here=i*i+j*j+k*k+i*j+j*k+i*k;
				value[here]++;
			}
		}
	}
	int n;
	cin>>n;
	for(j=1;j<=n;j++)
	   cout<<value[j]<<endl;
}



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

int H,W,D,ans=0;
char t[101][101];
int a[101][101];
int b[101][101];

int main(){
  cin>>H>>W>>D;
  for(int i=1;i<=H;i++){
    for(int j=1;j<=W;j++){
      cin>>t[i][j];
      if(t[i][j]=='#')continue;
      a[i][j]=a[i-1][j]+1;
      b[i][j]=b[i][j-1]+1;
      if(a[i][j]>=D)ans++;
      if(b[i][j]>=D)ans++;
    }
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3192
#include <iostream>
#include<iomanip>
#include<algorithm>
#include<cmath>
using namespace std;

int main() {

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

	if (d == 0) {
		cout << setprecision(10) << (1.0 / n)*(m - 1) << endl;
	}
	else {
		cout << setprecision(10) << ((2.0*(n - d)) / pow(n, 2))*(m - 1) << endl;
	}
  
	return 0;
}


Measured memory_bytes: 256
use std::io::prelude::*;
use std::str::FromStr;
pub struct Scanner<R: Read>(R);
impl<R: Read> Scanner<R> {
    pub fn new(reader: R) -> Self {
        Self(reader)
    }
    pub fn read<T: FromStr>(&mut self) -> T {
        let token = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| (b as char).is_whitespace())
            .take_while(|&b| !(b as char).is_whitespace())
            .collect::<Vec<u8>>();
        unsafe { std::str::from_utf8_unchecked(token.as_slice()) }
            .parse()
            .ok()
            .expect("Can't parse it.")
    }
    pub fn vec<T: FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}
fn main() {
    let (stdin, stdout) = (std::io::stdin(), std::io::stdout());
    let mut sc = Scanner::new(stdin.lock());
    let mut out = std::io::BufWriter::new(stdout.lock());
    solve(&mut sc, &mut out);
    out.flush().ok().unwrap();
}
fn solve(sc: &mut Scanner<std::io::StdinLock>, out: &mut std::io::BufWriter<std::io::StdoutLock>) {
    let n = sc.read();

    println!(
        "{}",
        (0..n)
            .map(|_| sc.read::<u32>().trailing_zeros())
            .min()
            .unwrap()
    );
}


Measured memory_bytes: 2168
#include <iostream> 
#include <math.h>
#include <string>
#include <string.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <stdlib.h>
#include <deque>  
#include <iomanip>

using namespace std;

#define ll long long
#define INF 1e9
#define MOD 1e9 + 7
#define rep(i, n) for(int i = 0; i < n; i++)
#define loop(i, a, n) for(int i = a; i < n; i++)
#define all(in) in.begin(), in.end()

int main(){
    int n;
    int ans = 0;
    cin >> n;
    vector<int> p(n);
    rep(i, n) cin >> p[i];
    rep(i, n - 2){
        if(p[i+ 1] != min(min(p[i], p[i + 2]), p[i + 1]) && p[i + 1] != max(p[i], max(p[i + 1], p[i + 2 ]))){
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if(a < b){ a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if(a > b){ a = b; return 1; } return 0; }
int main()
{
  int n,m; cin >> n >> m;
  vector<int> k(m);
  vector<vector<int>> s(m);
  rep(i,m) {
    cin >> k[i];
    s[i].resize(k[i]);
    rep(j,k[i]) {
      cin >> s[i][j];
      s[i][j]--;
    }
  }
  vector<int> p(m);
  rep(i,m) cin >> p[i];

  int res = 0;
  rep(mask,(1 << n)) {
    bool f = true;
    rep(j,m) {
      int cnt = 0;
      rep(l,k[j]) {
	if((mask >> s[j][l]) & 1) cnt++;
      }
      if(cnt % 2 != p[j]) f = false;
    }
    if(f) res++;
  }
  cout << res << "\n";
  
  return 0;
}


Measured memory_bytes: 3612
d[1<<27],i,a,b;main(c){for(memset(d+1,9,1<<28);i--?:(c=getchar(d[b]=fmin(d[b],++a))-10)?a=d[b^=1<<c-87],i=25:0;)a=fmin(a,d[b^1<<i]);printf("%d",a);}

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

int main(void) {
	
	char x[1001] = { 0 };

	while (1) {
		
		int sum = 0;
		scanf("%s", x);
		if (x[0] == '0')
			break;

		for (int i = 0; i < strlen(x); i++) {
			sum += x[i] - '0';
		}

		printf("%d\n", sum);
			
	}

	return 0;
}




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


int main(){
    int n,q;
    int S[10000],T[500];
    cin >> n;
    for (int i = 0; i < n ; ++i) {
        cin >> S[i];
    }
    cin >> q;
    for (int i = 0; i < q ; ++i) {
        cin >> T[i];
    }

    int count = 0;
    for (int i = 0; i < q ; ++i) {
        for (int j = 0; j < n ; j++) {
            if(T[i] == S[j]) {
                count++;
                break;
            }
        }
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 1200
#include<cstdio>
#define rep(i, a, b) for (register int i=(a); i<=(b); ++i)
#define per(i, a, b) for (register int i=(a); i>=(b); --i)
using namespace std;
const int N=3005, P=998244353;
inline void Add(int &x, int y){x=x+y>=P?x+y-P:x+y;}
inline void sub(int &x, int y){x=x-y<0?x-y+P:x-y;}
inline int add(int x, int y){return x+y>=P?x+y-P:x+y;}
inline int mul(int x, int y){return 1ll*x*y-1ll*x*y/P*P;}
int C[N][N];

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

int calc(int n, int x)
{
	int ans=0;
	if (n<<1<x || (x&1)) ans=1;
	rep(i, n, 2*n-1)
	{
		if (i<x) Add(ans, C[n][i-n]);
		else 
		{
			if (!((i-x)%2)) continue;
			int cnt=(i-x+1)>>1;
			if (cnt<<1>=n) continue;
			int a=n-(cnt<<1), b=i-(cnt<<2);
			if (a<=b && a<<1>=b) Add(ans, C[a][b-a]);
		}
	}
	return ans;
}

int main()
{
	int n=read(), x=read();
	rep(i, 0, n)
	{
		C[i][0]=1;
		rep(j, 1, i) C[i][j]=add(C[i-1][j], C[i-1][j-1]);
	}
	int ans=0;
	rep(i, 0, n) Add(ans, mul(C[n][i], calc(n-i, x)));
	printf("%d\n", ans);
	return 0;
}


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

int main() {
  int K,S,res; cin >> K >> S;
  for(int x=0; x <= K; ++x) {
    for(int y=0; y <= K; ++y) {
      if (0<=S-x-y && S-x-y<=K) ++res;
    }
  }
  cout << res << endl;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <map>
#include <list>
using namespace std;
typedef long long ll;
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define mp make_pair
#define pb push_back
#define pf push_front
const int INF = 1e9;
const ll LINF = 1e18;
const int MOD = 1e9+7;

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

	char S[N];
	for (int i = 0; i < N; i++) cin >> S[i];

	list<char> ls;
	for (int i = 0; i < N; i++) {
		ls.pb(S[i]);
	}

	int cnt = 0;
	for (int i = 0; i < N; i++) {
		// stringは参照型のため、"=="で比較はできない（ポインタ,アドレスが同じかの比較になる？）
		if (S[i] == '(') cnt++;
		else {
			if (cnt == 0) ls.pf('(');
			else cnt--;
		}
	}

	while (cnt > 0) {
		ls.pb(')');
		cnt--;
	}

	for_each(ls.cbegin(), ls.cend(), [](char c) {
		cout << c;
	});

	cout << endl;
    return 0;
}


Measured memory_bytes: 256
import java.text.DecimalFormat;
import java.util.stream.LongStream;
import java.util.stream.IntStream;
import java.io.*;
import java.util.*;

public class Main {

    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        PrintWriter out = new PrintWriter(System.out);

        AtCoder problem = new AtCoder(sc);
        problem.solve(out);

        out.flush();
    }

}

class AtCoder {

    final String s;

    AtCoder(FastScanner sc) {
        s = sc.next();
    }

    void solve(PrintWriter out) {
        out.println(s.matches("[aeiou]") ? "vowel" : "consonant");
    }

}

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 long nextLong() {
        if (!hasNext()) {
            throw new NoSuchElementException();
        }
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }

    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) {
            throw new NumberFormatException();
        }
        return (int) nl;
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }
}


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

using namespace std;

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define MOD 1000000007
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 1
#define mp(a,b) make_pair(a,b)

lli flag[100100];
lli p[100100];

int main()
{
	lli n,m;

	cin>>n>>m;

	REP(i,0,100100)flag[i]=0;

	//lli p=0;
	lli ac=0;
	
	REP(i,0,m){
		lli pi;
		string s;
		cin>>pi>>s;
		pi--;

		if(s=="AC"){
			if(flag[pi]==0){
				flag[pi]=1;
				ac++;
			}
		}
		else{
			if(flag[pi]==0){
				p[pi]++;
			}
		}
	}
	lli pSum = 0;
	REP(i,0,n){
		if(flag[i])pSum += p[i];
	}
	cout<<ac<<" "<<pSum<<endl;

	return 0;
}

Measured memory_bytes: 1792
//
#include <vector>
#include <set>
#include <map>
#include <array>
#include <iostream>
#include <cstdio>
#include <cstdint>
#include <algorithm>
#include <numeric>
#include <bitset>
#include <iomanip>
//
using ll = long long;
using namespace std;
#define rep(i,n) for(ll i=0;i<(n);++i)
#define outD(fpv) cout << setprecision(20) << fpv << endl;
inline void yes(bool cond) { cond ? puts("Yes") : puts("No"); }
inline void YES(bool cond) { cond ? puts("YES") : puts("NO"); }
template<typename Type> inline void chmin(Type& a, Type b) { if (a > b) a = b; }
template<typename Type> inline void chmax(Type& a, Type b) { if (a < b) a = b; }
template<typename Arr, typename Type> inline void fill(Arr& arr, Type v) { std::fill(arr.begin(), arr.end(), v); }
template<typename Type> inline void sort(Type& arr) { std::sort(arr.begin(), arr.end()); }
template<typename Type> inline Type nth(vector<Type>& arr, size_t pos) { std::nth_element(arr.begin(), arr.begin() + pos, arr.end()); return arr[pos]; }
template<typename Type> inline void unique(Type& arr) { sort(arr); arr.erase(unique(arr.begin(), arr.end()), arr.end()); }
constexpr ll INF_I = std::numeric_limits<ll>::max();
constexpr ll BIGP = 1000000007L;
constexpr double INF_F = std::numeric_limits<float>::infinity();
constexpr double PI = 3.14159265358979323846L;
//
int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    //
    ll A, B, C, D;
    cin >> A >> B >> C >> D;
    const auto f = [C, D](ll x)
    {
        ll E = lcm(C, D);
        ll c = x / C;
        ll d = x / D;
        ll e = x / E;
        return x - c - d + e;
    };
    cout << f(B) - f(A - 1);
    //
    return 0;
}

Measured memory_bytes: 3620
h_l = gets.split(" ")
h_l.map!{|i|i.to_i}
i = 0
h_l[0].times do |time|
  i += gets.chomp.count("#")
end
if i == h_l.inject(0){|sum,i| sum += i} -1
  puts "Possible"
else 
  puts "Impossible"
end

Measured memory_bytes: 1788
#include <string>
#include<bits/stdc++.h>
using namespace std;
 
int main(void){
  string S, front="", back="";
  int Q, D, F;
  char C;
  cin >> S;
  cin >> Q;
  bool rev = false;
  
  for(int i=0; i<Q; i++){
    cin >> D;
    if(D==1){
      rev = !rev;
    }else if(D==2){
      cin >> F >> C;
      if(rev){
        if(F==1){
          back = back+C;
        }else if(F==2){
          front = front+C;
        }
      }else if(!rev){
        if(F==1){
          front = front+C;
        }else if(F==2){
          back = back+C;
        }
      }
    }
      
  }
  reverse(front.begin(),front.end());
  S = front + S + back;
  if(rev)reverse(S.begin(), S.end());

  cout << S;
  return 0;
}

Measured memory_bytes: 1620
S = gets.chomp
T = gets.chomp
sn = S.size
tn = T.size

def match(a, b)
  return false if a.size!=b.size
  (0...a.size).all? {|i| a[i]==b[i] or a[i]=='?' }
end

res = []
for i in 0...(sn-tn+1)
  if match(S[i, tn], T)
    s = S.dup
    s[i, tn] = T
    res << s.gsub('?', 'a')
  end
end
if res.size>0
  puts res.min
else
  puts 'UNRESTORABLE'
end




Measured memory_bytes: 1788
package main

import (
  "fmt"
)

func dijkstra(E *[][]int, s int) (D []int) {
  N := len((*E))
  D = make([]int, N)
  for i := 0; i < N; i++ {
    if i != s {
      D[i] = -1
    }
  }
  Q := []int{s}
  var v int
  for i := 0; i < N; i++ {
    v = Q[i]
    for _, adj := range (*E)[v] {
      if D[adj] >= 0 {
        continue
      }
      D[adj] = D[v] + 1
      Q = append(Q, adj)
    }
  }
  return
}

func max(A *[]int) (i, a int) {
  i = 0
  a = (*A)[0]
  for _i, _a := range (*A) {
    if _a > a {
      a = _a
      i = _i
    }
  }
  return
}

func main() {
  var N int
  fmt.Scan(&N)
  E := make([][]int, N)
  for i := range E {
    E[i] = make([]int, 0)
  }
  var a, b int
  for i := 0; i < N - 1; i++ {
    fmt.Scan(&a, &b)
    E[a - 1] = append(E[a - 1], b - 1)
    E[b - 1] = append(E[b - 1], a - 1)
  }
  D0 := dijkstra(&E, 0)
  s, _ := max(&D0)
  D1 := dijkstra(&E, s)
  _, L := max(&D1)
  if L % 3 != 1 {
    fmt.Println("First")
  } else {
    fmt.Println("Second")
  }
}

Measured memory_bytes: 31616
import sys
rr = lambda: sys.stdin.readline().strip()
ri = lambda: int(rr())
rs = lambda: [int(_) for _ in rr().split()]

R, G, B, N = rs()

cnt = 0
for r in range(N//R + 1):
    for g in range(N//G + 1):
        if (N - (r*R + g*G))%B == 0 and (N - (r*R + g*G)) >= 0:
            cnt += 1

print(cnt)

Measured memory_bytes: 40556
import java.util.Scanner;

public class Main {
	static boolean[][] nodes;
	static int cnt = 0;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		String s = sc.next();
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < s.length(); i++) {
			char c = s.charAt(i);
			switch (c) {
			case '0':
				sb.append('0');
				break;
			case '1':
				sb.append('1');
				break;
			case 'B':
				if (sb.length() != 0) {
					sb.deleteCharAt(sb.length() - 1);
				}
				break;
			default:
				break;
			}
		}
		System.out.println(sb);
		sc.close();
	}

}


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



int main(){
    int n;
    cin>>n;
    ll m;
    cin>>m;
    ll a[100005];
    for(int i=0;i<n;i++){
        cin>>a[i];
        a[i]%=m;
    }
    
    
    map<ll,int> mod;
    ll sum[100005];
    sum[0]=0;
    mod[0]=1;
    for(int i=0;i<n;i++){
        sum[i+1]=a[i]+sum[i];
        sum[i+1]%=m;
        mod[sum[i+1]]++;
    }
   
    ll ans=0;
    ll b;
    for(auto i : mod){
        b=i.second;
        b*=i.second-1;
        b/=2;
        ans+=b;
    }
    
    cout<<ans<<endl;
    return 0;
}



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

int a,b,c,len;

int main()
{
	scanf("%d%d",&a,&b);
	c=b;
	while(c>0)
	{
		c/=10;
		len++;
	}
	a=a*pow(10,len)+b;
	if(sqrt(a)==floor(sqrt(a)))printf("Yes");
	else printf("No");
}

Measured memory_bytes: 256
#include<cstdio>
#include<vector>
#include<cstring>
#include<algorithm>
using namespace std;
const int MAX_V=10000+5;
const int INF=1<<30;
int pre[MAX_V];
int cost[MAX_V][MAX_V];//cost[u][v]表示边e=(u,v)的权值（不存在这条边时设为INF）
bool visited[MAX_V][MAX_V];
int d[MAX_V];//顶点s出发的最短距离
bool used[MAX_V];//已经使用过的图
int V,E;//顶点数，边数
//求从起点s出发到各个顶点的最短距离
void dijkstra(int s)
{
    fill(d+1,d+V+1,INF);
    fill(used+1,used+V+1,false);
    fill(pre+1,pre+V+1,-1);
    d[s]=0;
    while(true)
    {
        int v=-1;
        //从尚未使用过的顶点中选择一个距离最小的顶点
        for(int u=1; u<=V; u++)
        {
            if(!used[u]&&(v==-1||d[u]<d[v]))
                v=u;
        }
        if(v==-1)
            break;
        used[v]=true;
        for(int u=1; u<=V; u++)
        {
            if(d[u]>d[v]+cost[v][u])
            {
                d[u]=d[v]+cost[v][u];
                pre[u]=v;
            }
        }
    }
}
vector<int> get_path(int t)
{
    vector<int>path;
    for(; t!=-1; t=pre[t])
        path.push_back(t);
    reverse(path.begin(),path.end());
    return path;
}
int main()
{
    scanf("%d%d",&V,&E);
    int a,b,c;
    for(int i=1;i<=V;i++)
    {
        for(int j=1;j<=V;j++)
            cost[i][j]=INF;
    }
    for(int i=0;i<E;i++)
    {
        scanf("%d%d%d",&a,&b,&c);
        cost[a][b]=cost[b][a]=c;
    }
    memset(visited,false,sizeof(visited));
    int ans=E;
    for(int i=1;i<=V;i++)
    {
        dijkstra(i);
        for(int j=1;j<=V;j++)
        {
            if(i==j)
                continue;
            vector<int>v=get_path(j);
            for(int i=0;i<v.size()-1;i++)
            {
                int a=v[i];
                int b=v[i+1];
                if(!visited[v[i]][v[i+1]]&&!visited[v[i+1]][v[i]])
                {
                    visited[v[i]][v[i+1]]=visited[v[i+1]][v[i]]=true;
                    ans--;
                }
            }
        }
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 102656
#include <bits/stdc++.h>
#define  rep(i,n) for(li i=0;i<(n);i++)
#define  red(i,n) for(li i=(n)-1;i>=0;i--)
#define  all(a)   begin(a),end(a)
#define  pb(a)    push_back(a) 
using namespace std;
using li = long long;
using ul = unsigned long long;
using vi = vector<li>;
using vs = vector<string>;
inline ul gcd(ul a,ul b) { return b?gcd(b,a%b):a; }


int main()
{
    int n,a,b,ans=0;
    cin>>n;
    rep(i,n) cin>>a>>b,ans+=b-a+1;
    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))
A = [x - i - 1 for i,x in enumerate(A)]
A .sort()
ans = 0
b = 0

if len(A) % 2 == 0:
    b = A[int(len(A)/2)]
else:
    b = A[int((len(A) -1)/2)]

for j in A:
    ans += abs(j-b)

print(ans)


Measured memory_bytes: 26180
#include <bits/stdc++.h> 
#define rep(i, n) for(long long i = 0; i < (long long)(n); i++)
#define all(x) (x).begin(),(x).end()
#define _GLIBCXX_DEBUG
typedef long long ll;
using namespace std;
int main(){
  int n;
  cin>>n;
  int b[n-1];
  rep(i,n-1){cin>>b[i];}
  int k=0;
  k+=b[0]+b[n-2];
  for(int i=1;i<n-1;i++){k+=min(b[i],b[i-1]);}
  cout<<k<<endl;
}


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

int main() {
    int N;
    cin>>N;
    vector<long> A(N);
    for(int i=0;i<N;++i){
        cin>>A[i];
    }
    sort(A.begin(), A.end());
    long mini = A[0], maxi = A[N-1];
    vector<long> minarr, pluarr;
    for(int i=1;i<N-1;++i){
        if(A[i]>=0){
            pluarr.push_back(A[i]);
            mini -= A[i];
        }
        else {
            minarr.push_back(A[i]);
            maxi -= A[i];
        }
    }
    cout<<maxi - mini<<endl;
    maxi = A[N-1];
    mini = A[0];
    for(int i=0;i<minarr.size();++i){
        cout<<maxi<<" "<<minarr[i]<<endl;
        maxi -= minarr[i];
    }
    for(int i=0;i<pluarr.size();++i){
        cout<<mini<<" "<<pluarr[i]<<endl;
        mini -= pluarr[i];
    }
    cout<<maxi<<" "<<mini<<endl;
}


Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define sz(x) int(x.size())
#define pb push_back
#define eb emplace_back
using ll=long long;
using P = pair<int,int>;
using LP=pair<ll,int>;
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
const ll MOD=1000000007,MOD2=998244353;



int main() {
    int a,b,c,d,e,k;
    cin>>a>>b>>c>>d>>e>>k;
    if(abs(e-a)<=k){cout<<"Yay!"<<endl;}
    else{cout<<":("<<endl;}
}

Measured memory_bytes: 3636
S = input()
K = int(input())
a = []
ans = 0
count = 0
for i in range(len(S)-1):
    if S[i] == S[i+1] :
        count += 1
    else:
        if count!=0:
            ans += (count+1)//2
            a.append(count+1)
            count = 0
if count !=0:
    ans += (count+1)//2 
ans = ans*K
a.append(0)
if len(S) == 1:
    ans = K//2
else:    
    
    if (count+1)%2==1 and a[0]%2 == 1 and S[0]== S[1] and S[0] == S[len(S)-1]:
    
        ans+=K-1
    if S[0]!= S[1] and (count+1)%2 ==1 and  S[0] == S[len(S)-1]:
        ans+=K-1
    if count+1 == len(S):
        if len(S)%2==1:
            ans = (len(S)*K)//2
 
print(ans)

Measured memory_bytes: 3064
from collections import deque
N,M = list(map(int, input().split()))

E = {}
for i in range(N):
  E[i] = set()
  
for i in range(M):
  a,b = list(map(int, input().split()))
  a,b = a-1, b-1
  E[a].add(b)
  E[b].add(a)
  
visited = [False] * N
will_search = [False] * N
q = deque()
q.append(0)
ans = [0] * N
while len(q) >0:
  now = q.popleft()
  visited[now] = True
  for x in E[now]:
    if visited[x] or will_search[x]:
      continue
    will_search[x] = True
    ans[x] = now
    q.append(x)
    
if len(ans) < N:
  print('No')
else:
  print('Yes')
  for a in ans[1:]:
    print(a+1)

Measured memory_bytes: 72708
import math
S = input()

def check(S):
    if S == S[::-1]:
        N = len(S)
        end = math.floor(((N-1)/2))
        s2 = S[:end]
        if s2 == s2[::-1]:
            start = math.floor((N+3)/2)
            s3 = S[start-1:N]
            if s3 == s3[::-1]:
                return "Yes"
    return "No"

print(check(S))

Measured memory_bytes: 3064
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,a,b) for(int i =(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
#define REPm(i,n) for(int i=(n)-1;i>=0;i--)
#define REP1(i,n) for(int i=1;i<=(n);i++)
typedef long long ll;
#define MAX_N 100
int a[101];
int main(){
    int K,T;
    cin >> K >> T;
    int m = 0;
    REP(i,T){
        cin >> a[i];
        if(a[i] > m) m = a[i];
    }
    cout << max(0,2*m-K-1)<< endl;
    return 0;
}


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

using namespace std;
using ll = long long;
using ld = long double;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define reps(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
const ll mod = 1e9 + 7;
const int INF = 1e9;

int main() {
	cin.sync_with_stdio(false);
	int N;
	cin >> N;
	int A[2][100], B[2][100] = {};
	rep(i, N)cin >> A[0][i];
	rep(i, N)cin >> A[1][i];
	int sum1 = 0, sum2 = 0;
	rep(i, N) {
		sum1 += A[0][i];
		sum2 += A[1][i];
	}
	int ans = 0, suma = 0;
	rep(i, N) {
		suma += A[0][i];
		ans = max(ans, suma + sum2);
		sum2 -= A[1][i];
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n)    for(long long i = 0; i < (n) ; ++i)
#define orep(i,n)   for(long long i = 1; i <= (n); ++i)   // one rep
#define drep(i,n)   for(long long i = (n)-1; i >= 0; --i) // down rep
#define srep(i,s,t) for(long long i = (s); i < (t); ++i)  // set rep
#define rng(x)  (x).begin(),(x).end()

  // range
#define rrng(a) (a).rbegin(),(a).rend() // reverse range
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define ru(x,y) (((x)+(y)-1)/(y)) // round up
#define fi first
#define se second
#define eb emplace_back
#define fcout cout << fixed << setprecision(15)


using namespace std;
using ll  = long long;
using P   = pair<int,int>;
using vi  = vector<int>;
using vvi = vector<vi>;
using vp  = vector<P>;
using vl  = vector<ll>;

template<typename T> void Yes(T flag) {
  cout << (flag ? "Yes" : "No") << endl;
}

template<typename T> void pv(vector<T> vec) {
  cout << "[";
  for(auto& v : vec) { cout << v << ","; }
  cout << "]" << endl;
}

template<>
void pv(vector<P> vec) {
  cout << "[";
  for(auto& v : vec) {
    cout << "<" << v.fi << ","<< v.se << ">" << ",";
  }
  cout << "]" << endl;
}

template<typename T> void pv2(vector<vector<T>> vec) {
  for(auto& v : vec) pv(v);
}

int dp[105][10005];
int main() {
  int n,lw;
  cin >> n >> lw;
  vi v(n,0);
  vi w(n,0);
  rep(i,n) {
    cin >> v.at(i) >> w.at(i);
  }
  rep(i,n) rep(j,lw+1) {
     dp[i+1][j] = max(dp[i][j],dp[i+1][j]);
     if(j+w.at(i)>lw) continue;
      dp[i+1][j+w.at(i)] = max(dp[i][j+w.at(i)],dp[i][j]+v.at(i));
  }
  cout << dp[n][lw] << endl;

  return 0;
}



Measured memory_bytes: 7032
#include <bits/stdc++.h>
using namespace std;
#define _MACRO(_1, _2, _3, NAME, ...) NAME
#define _repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define _rep(i,n) _repl(i,0,n)
#define rep(...) _MACRO(__VA_ARGS__, _repl, _rep)(__VA_ARGS__)
#define pb push_back
#define all(x) begin(x),end(x)
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#ifdef LOCAL
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cerr<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cerr<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream &o, const pair<T,U> &p){o<<"("<<p.first<<","<<p.second<<")";return o;}
template<class T> ostream& operator<<(ostream &o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}
#else
#define dbg(...) {}
#endif

bool isprime(int x){
  for(int i=2; i*2 <= x; i++) {
    if(x%i==0) return false;
  }
  return true;
}

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

  if(n <= 3) {
    cout << 0 << endl;
    return 0;
  }

  vector<int> p(101,0);
  vector<bool> isp(101,0);
  vector<int> primes;
  primes.pb(2);
  isp[1] = false;
  isp[2] = true;
  rep(i,3,101) {
    isp[i] = isprime(i);
    if(isp[i]) primes.pb(i);
  }

  rep(i,2,n+1){
    int x = i;
    for(auto pr : primes){
      while(x % pr == 0){
        p[pr]++;
        x /= pr;
      }
    }
  }
dbg(p);

  int ans = 0;
  rep(i,100) if(p[i]>=2){
    rep(j,100) rep(k,j+1,100) if(i!=j && i!=k && p[j]>=4 && p[k]>=4) ans++;
    rep(j,100) if(i!=j && p[j]>=24) ans++;
  }
  rep(i,100) rep(j,100) if(i!=j && p[i]>=4 && p[j]>=14) ans++;
  rep(i,100) if(p[i]>=74) ans++;

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep2(i, l, r) for (int i = (l); i < (r); i++)
#define ALL(x) (x).begin(), (x).end()     //昇順
#define RALL(x) (x).rbegin(), (x).rend()  // 降順
const long long mod = 1e9 + 7;
typedef long long ll;
typedef priority_queue<int> PQ;
typedef vector<long long> VL;
typedef vector<bool> VB;
typedef vector<int> VI;  // VI a(n);
typedef vector<double> VD;
typedef vector<string> VS;
typedef vector<char> VC;
typedef vector<VS> VSS;
typedef vector<VC> VCC;
typedef vector<VI> VII;  // VII a(n,vector<int>(m)) n * m
typedef vector<VL> VLL;
typedef pair<int, int> PII;
typedef map<int, int> MP;  // MP a;
typedef vector<pair<ll, ll>> PS;

template <class T, class U> bool chmax(T &a, U b) { if (a <= b) {a = b; return 1;} return 0; }
template <class T, class U>  bool chmin(T &a, U b) { if (a > b) { a = b; return 1; } return 0; }
template <typename T>  ostream &operator<<(ostream &os, vector<T> &v) { os << "{"; rep(i, (int)v.size()) { os << v[i] << (i < v.size() - 1 ? ", " : ""); } os << "}"; return os; }

// g++ -std=c++11 prac.cpp
// operator << (cout,a);
// chmin(min,a)

int main() {
    ll x=0,y=0,z=0,n,m,ans=0,sum=0,k,h,w,Max=-1,Min=1e9+1;
    bool ok = true;
    string s,t;
    cin >> n >> k;
    VII a(k,vector<int>(k));
    VI d(k);
    VI b(n);
    rep(i,k){
        cin >> d[i];
        rep(j,d[i]){
            cin >> x;x--;
            b[x]++;
        }
    }
    rep(i,n){
        if(b[i]==0)
            ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3672
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
namespace AtCoder
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static long Mod = (long)1e9 + 7;
        static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            var NK = Sarray();
            var N = NK[0];
            var K = NK[1];
            var S = ReadLine();
            var ans = 0L;
            var hanNum = 0L;
            for (var i = 0; i < N - 1; ++i)
            {
                if (S[i] == S[i + 1])
                    ++ans;
                else
                    ++hanNum;
            }
            var kanou = hanNum / 2;
            var hosei = K * 2;
            if (kanou < K) ++hosei;
            WriteLine(Min(N - 1, ans + hosei));
            //Out.Flush();
        }
    }
}

Measured memory_bytes: 13536
object Main {
  def main(args:Array[String]) = {
      import scala.io.StdIn.readLine
    /* 文字列を読み込み、空白で分割して配列にし、Int型にする */
    val in = readLine().toInt
    
    val h = in/3600
    val m = (in - h*3600)/60
    val s = in%60
    
    println(h+":"+m+":"+s)
  }
}


Measured memory_bytes: 43664
#include<stdio.h>
int main()
{
    int A,B,m;
    scanf("%d%d",&A,&B);

    if(A>9||B>9)
    {
        m=-1;
        printf("%d",m);
    }
    else{
    m=A*B;
    printf("%d",m);
    }
    return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
#include <stdbool.h>


#define Niii 8
#define freeqqq -1
#define not_freewww 1

void inter(void);
void board(void);
void recursive(int );

int row[Niii],col[Niii],dpos[2*Niii-1],dneg[2*Niii-1];

bool X[Niii][Niii];



int main()
{
  inter();

  for(int i=0;i<Niii;i++){
    for(int j=0;j<Niii;j++){
      X[i][j]=false;

    }
  }

  int k;
  scanf("%d",&k);
  for(int i=0;i<k;i++){
    int r,c;
    scanf("%d%d",&r,&c);
    X[r][c]=true;
  }

  recursive(0);
  return 0;
}



void inter(){
  int i;
  for(i=0;i<Niii;i++){
    row[i]=freeqqq;
    col[i]=freeqqq;
  }
  for(i=0;i<2*Niii-1;i++){
    dpos[i]=freeqqq;
    dneg[i]=freeqqq;
  }
}


void board(){
  int i,j;
  for(i=0;i<Niii;i++){
    for(j=0;j<Niii;j++){
      if(X[i][j]){
	if(row[i]!=j)return;
      }
    }
  }
  for(i=0;i<Niii;i++){
    for(j=0;j<Niii;j++){
      if(row[i]==j){
	printf("Q");
      }
      else{
	printf(".");
      }
    }
    printf("\n");
  }
}


void recursive(int i){
  if(i==Niii){
    board();return;
  }
  for(int j=0;j<Niii;j++){
    if(not_freewww==col[j] || not_freewww==dpos[i+j] || not_freewww==dneg[i-j+Niii-1])continue;
    row[i]=j;
    col[j]=not_freewww;
    dpos[i+j]=not_freewww;
    dneg[i-j+Niii-1]=not_freewww;
    recursive(i+1);
    row[i]=col[j]=dpos[i+j]=dneg[i-j+Niii-1]=freeqqq;
  }
}



Measured memory_bytes: 2084
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef double D;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef long double ld;

#define rd(x) scanf("%d",&x)
#define rd2(x,y) scanf("%d %d",&x,&y)
#define rd3(x,y,z) scanf("%d %d %d",&x,&y,&z)
#define rl(x) scanf("%lld",&x)
#define rl2(x,y) scanf("%lld %lld",&x,&y)
#define rl3(x,y,z) scanf("%lld %lld %lld",&x,&y,&z)
#define wd(x) printf("%d" ,x)
#define wd2(x,y) printf("%d %d",x,y)
#define wl(x) printf("%lld",x)
#define wl2(x,y) printf("%lld %lld",x,y)
#define PC(x) putchar(x)
#define GC() getchar()
#define NL printf("\n")
#define SP printf(" ")
 
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a,value) memset(a, value, sizeof(a))

#define F first
#define S second
#define MP make_pair
#define PB push_back

#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)
#define fr(i,s,e) for(int i=s;i<e;i++)
#define frl(i,s,e) for(ll i=s;i<e;i++)
#define frr(i,s,e) for(int i=s-1;i>=e;i--)
#define frv(i,a) for(int i = 0;i<(int)a.size();i++)
#define frvr(i,a) for(int i = a.size()-1;i>=0;i--)
#define tr(i,a) for(typeof(a.begin()) i = a.begin(); i != a.end();i++)

#define inf 10000000000000
#define mod 1000000007
#define maxn 100009
#define maxr 100009

void solve()
{
	ll n;
	rl(n);
	VL arr(n);
	map<ll,ll> mp;
	ll sec=0,last=0;
	fr(i,0,n)
	{
		rl(arr[i]);
		mp[arr[i]]+=1;
	}

	for(auto i:mp)
	{
		sec=last;
		last=i.F;
	}
	fr(i,0,n)
	{
		if(arr[i]!=last)
		{
			wl(last);
		}
		else
		{
			if(mp[last]==1)
				wl(sec);
			else
				wl(last);
		}
		NL;
	}
	return;
}
int main(){
	//sstd::ios::sync_with_stdio(false); cin.tie(NULL);
	solve();	
	return 0;
}

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

#define task "A"
#define ALL(v) (v).begin(), (v).end()
#define rep(i, l, r) for (int i = (l); i <= (r); ++i)
#define Rep(i, r, l) for (int i = (r); i >= (l); --i)
#define pb push_back
#define F first
#define S second

using ll = long long;
using ld = long double;
using ull = unsigned long long;

using namespace std;

typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ll> vl;

// Variables
int a,b;
//
// Function

//

int main()
{
	//freopen(task".in","r",stdin);
	//freopen(task".out","w",stdout);
	ios_base::sync_with_stdio(false);cin.tie(nullptr);
	cin >> a >> b;
	a+=b;
	if (a&1)
    {
        cout << "IMPOSSIBLE";
    } else cout << a/2;
}


Measured memory_bytes: 256
/*
       This sky
       Is lonely and grey
       But every night I feel your gravity waves
       And the world is cold
       But it's beautiful
       I wish you were here now
       I miss your soul
       But you lost your light
       When the darkness called
       I still stand here waiting
       The last to fall
       The last to fall
       The last to fall
       The last to fall
                            */
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
template <typename X> ostream& operator << (ostream& x,const vector<X>& v){for(ll i=0;i<v.size();++i) x<<v[i]<<" ";return x;}
template <typename X> ostream& operator << (ostream& x,const set<X>& v){for(auto it:v) x<<it<<" ";return x;}
template <typename X, typename Y> ostream& operator << (ostream& x, const pair<X,Y>& v) {x<<v.ff<<" "<<v.ss;return x;}
template <typename T, typename S> ostream& operator << (ostream& os, const unordered_map<T, S>& v) { for (auto it : v) os << it.first << "=>" << it.second << endl; return os; }
struct pair_hash {inline std::size_t operator()(const std::pair<ll, ll> & v) const {return v.first*31+v.second;}};
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC targett("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL)
#define pb push_back
#define fr first
#define sc second
#define tra(it,m) for(auto it=m.begin();it!=m.end();++it)
#define dbg(x) cout<<#x<<" = "<<x<<'\n';
#define fri(i,s,n) for(ll i=s;i<n;i++)
#define mod 1000000007
#define mod2 998244353
#define vct2 vector<vector<ll>>
#define vct vector<ll>
#define pll pair<ll,ll>
#define rz(n) resize(n)
#define all(v) v.begin(),v.end()
#define mkp make_pair
#define arrin(a,n) for(ll i = 0; i < n ; i++){cin>>a[i];}
#define arrout(a,n) for(ll i = 0;i < n; i++){cout<<a[i]<<" ";}
#define ex(s) cout<<s<<endl,exit(0);
#define inf 4e18
#define five 100005;
#define six 1000005;
#define printclock cerr<<"Time"<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
//_______________________________________________________________________________________
int main()
{
       int n,k;
       cin>>n>>k;
       int a[n];
       arrin(a,n);
       sort(a,a+n);
       int ans = 0;
       fri(i,0,k){
              ans += a[i];
       }
       cout<<ans;
}


Measured memory_bytes: 3636
#include<cstdio>
#define ll long long
using namespace std;
int n,m;
long long ans;
int main(){
	scanf("%d%d",&n,&m);
	if(n==1){
		if(m==1) printf("1\n");
		else printf("%d\n",m-2);
		return 0;
	}else if(m==1){
		printf("%d\n",n-2);
		return 0;
	}else{
		ans=(ll)(n-2)*(m-2);
		printf("%lld\n",ans);
	}
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#define REP(i, n) for (int i = 0; i < (n); i++)

using namespace std;

int main() {
  int A[5];
  int K;
  REP(i, 5) cin >> A[i];
  cin >> K;
  puts(A[4] - A[0] <= K ? "Yay!" : ":(");
}



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

int main(){
    int n,m;    cin>>n>>m;
    long long a=0;
    
    long long b=0;

    long long ans=0;

    for(int i=0;i<n;i++){
        int x;  cin>>x;
        a+=x;
    }
    for(int i=0;i<m;i++){
        int x;  cin>>x;
        b+=x;
    }

    ans=a*b;

    cout<<ans<<endl;

    return 0;
}



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

int main() {
  long long int a,b,k;
  cin >> a >> b >> k;
  if(a >= k) {
    cout << a-k << " " << b << endl;
  }
  else if(b >= k-a) {
    cout << "0 " << b-k+a << endl;
  }
  else {
    cout << "0 0" << endl;
  }
  return 0;
}

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

typedef long double lf;

int fa[15];
void init() {
    for(int i = 0; i < 15; i++) fa[i] = i;
}
int find(int u) {
    if(fa[u] == u) return u;
    else return fa[u] = find(fa[u]);
}
void mrg(int u, int v) {
    u = find(u);
    v = find(v);
    if(u == v) return;
    fa[v] = u;
}

struct Edge {
    int u, v;
    lf w;
    bool operator <(const Edge &i) const {
        return w < i.w;
    }
};

int N;
int X[15], Y[15], A[15];
lf sum[1 << 15], mst[1 << 15];
int cnt[1 << 15];

lf need;

int cc[1 << 15];
int dp(int mask) {
    int &ret = cc[mask];
    if(ret != -1) return ret;
    if(mask == 0) return ret = 1;

    for(int i = mask; i; i = mask & (i - 1)) {
        if(sum[i] >= need * cnt[i] + mst[i]) {
            if(dp(mask ^ i)) return ret = 1;
        }
    }
    return ret = 0;
}

bool check(lf x) {
    need = x;
    memset(cc, -1, sizeof(cc));
    return dp((1 << N) - 1);
}

lf dist(int a, int b) {
    int dx = X[a] - X[b];
    int dy = Y[a] - Y[b];
    return sqrt(1LL * dx * dx + 1LL * dy * dy);
}

int main() {
    for(int i = 1; i < (1 << 15); i++) for(int j = 0; j < 15; j++) if(i & (1 << j)) cnt[i]++;

    scanf("%d", &N);

    for(int i = 0; i < N; i++) {
        scanf("%d %d %d", &X[i], &Y[i], &A[i]);
    }

    for(int mask = 1; mask < (1 << N); mask++) {

        vector<int> V;
        for(int i = 0; i < N; i++) if(mask & (1 << i)) {
            V.push_back(i);
            sum[mask] += A[i];
        }

        vector<Edge> E;
        for(int i = 0; i < V.size(); i++) {
            for(int j = i + 1; j < V.size(); j++) {
                E.push_back({ i, j, dist(V[i], V[j]) });
            }
        }

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

        init();
        for(int i = 0; i < E.size(); i++) {
            int u = E[i].u;
            int v = E[i].v;
            lf w = E[i].w;

            if(find(u) == find(v)) continue;
            mrg(u, v);
            mst[mask] += w;
        }
    }

    lf s = 0, e = 1e9;
    for(int n = 0; n < 60; n++) {
        lf m = (s + e) / 2;

        if(check(m)) s = m;
        else e = m;
    }

    cout << fixed;
    cout.precision(20);
    cout << s;
}


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

int main() {
  int N, M, R; cin >> N >> M >> R;
  long D[N][N];
  for (int i = 0; i < N; i++) for (int j = 0; j < N; j++) D[i][j] = (1L<<60);
  for (int i = 0; i < N; i++) D[i][i] = 0;
  int r[R]; for (int i = 0; i < R; i++) {cin >> r[i]; r[i]--;}
  for (int i =0 ; i < M; i++) {
    int a, b, c; cin >>a>>b>>c;a--;b--;
    D[a][b] = D[b][a] = c;
  }
  for (int k = 0; k < N; k++)
    for (int i =0;i<N;i++)
      for (int j=0;j<N;j++)
        D[i][j] = min(D[i][j], D[i][k] + D[k][j]);
  int perm[R]; for (int i = 0; i < R; i++) perm[i] = i;
  long min_sum = (1L<<60);
  do {
    long sum = 0;
    for (int i = 0; i < R-1; i++) sum += D[r[perm[i]]][r[perm[i+1]]];
    min_sum = min(min_sum, sum);
  } while (next_permutation(perm, perm+R));
  cout<<min_sum<<endl;
}

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

int main() {
    int n;
    cin >> n;
    int ans1 = 0, ans2 = 0, mn = 105;
    rep(i, n) {
        int s;
        cin >> s;
        if (s % 10 == 0)
            ans1 += s;

        else {
            ans2 += s;
            mn = min(mn, s);
        }
    }
    if (ans2 == 0) {
        cout << 0 << endl;
    } else if (ans2 % 10 == 0)
        cout << ans1 + ans2 - mn << endl;
    else
        cout << ans1 + ans2 << endl;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;
//import java.util.stream.*;;
//import java.math.*;

public class Main {

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

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
        Scanner sc = new Scanner(System.in);
        int n, k, x, y;
        int i = 0;
        long sum = 0;
        n = sc.nextInt();
        k = sc.nextInt();
        x = sc.nextInt();
        y = sc.nextInt();
        while (i++ < n) {
            if (i <= k) {
                sum += x;
            } else {
                sum += y;
            }
        }
        System.out.println(sum);
        bw.flush();
    }
}


Measured memory_bytes: 21716
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    S = readline().strip()
    T = readline().strip()
    
    ans = 0
    for s, t in zip(S, T):
        if s == t:
            ans += 1
            
    print(ans)
    return


if __name__ == '__main__':
    main()


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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    while(true){
        cin >> s;
        if(s == "#") break;
        int s_len = s.size(), n_violate = 0, dir = 0;
        for(int i = 0; i < s_len - 1; ++i){
            int sa = (s[i] - '0' + 2) % 3;
            int sb = (s[i + 1] - '0' + 2) % 3;
            if(dir == 0){
                if(sa < sb){
                    dir = -1;
                }
                if(sa > sb){
                    dir = 1;
                }
            }else{
                dir *= -1;
                if(dir == 1 && sa < sb){
                    ++n_violate;
                    dir *= -1;
                }else if(dir == -1 && sa > sb){
                    ++n_violate;
                    dir *= -1;
                }
            }

        }
        printf("%d\n", n_violate);
        s.clear();
    }
    return 0;
}

Measured memory_bytes: 1356
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <algorithm>    // std::copy
#include <iterator>     // std::back_inserter
#include <set>
using namespace std;
 
int main(){
    int A,B;
    cin >> A >> B;

    if(abs( (A + B) % 2 ) != 0){
        cout << "IMPOSSIBLE" << endl;
    } 
    else{
        cout << (A + B) / 2 << endl;
    }
}

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

using namespace std;

#define all(x) begin(x), end(x)

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

constexpr int MAXN = 200005;
vi tree[MAXN];
ll dp[MAXN];

void dfs(int u, int p) {
    for (int v : tree[u]) {
        if (v == p) continue;

        dp[v] += dp[u];
        dfs(v, u);
    }
}

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

    int n, q;
    cin >> n >> q;
    for (int i = 1; i < n; ++i) {
        int u, v;
        cin >> u >> v;
        --u; --v;
        tree[u].push_back(v);
        tree[v].push_back(u);
    }

    while (q-- > 0) {
        int u, x;
        cin >> u >> x;
        --u;
        dp[u] += x;
    }

    dfs(0, -1);

    for (int i = 0; i < n; ++i) {
        cout << dp[i] << ' ';
    }
    
    return 0;
}


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

int main(){
  string s;
  int k;
  set<string> sub;
  cin>>s >>k;
  
  for(int i=0;i<s.size();i++){
    for(int j=1;j<=k;j++){
      sub.insert(s.substr(i, j));
    }
  }
  
  auto itr = sub.begin();
  for(int i=0;i<k-1;i++)itr++;
  cout<<*itr<<endl;
  return 0;
}

Measured memory_bytes: 1664
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <bits/stdc++.h>
#include<queue>
#include <numeric>
using namespace std;
 
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
 
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
 template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
 
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
 
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define fore(i,a) for(auto &i:a)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
 
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
 



int main(){
    int n,m;
    cin >> n >> m;
    vector<PII> p(m);
    REP(i,m) cin >> p[i].first >> p[i].second;
    REP(x,1000){
        int keta=1;
        int nx=x/10;
        vector<int> d(1,x%10);
        while(nx){
            keta++;
            d.push_back(nx%10);
            nx/=10;
        }
    if(keta!=n) continue;
    bool ok = true;
    reverse(d.begin(),d.end());
    REP(i,m){
        if(d[p[i].first-1] != p[i].second)ok=false;
    }
    if(ok){
        cout << x << endl;
        return 0;
    }
    }
    cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 256