akhauriyash/Code-Regression huggingface dataset:
from heapq import heapify
from heapq import heappop
from heapq import heappush
n=int(input())
v=list(map(int,input().split()))
heapify(v)
ans=0
while len(v)>1:
  s=(heappop(v)+heappop(v))/2
  heappush(v,s)
print(heappop(v))

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}
void yes(){ cout << "Yes" << endl; }
void no(){ cout << "No" << endl; }
int SIZE(string s){ return (int)s.size(); }

int main(){
    cout << setprecision(16);
    ll d,n; cin >> d >> n;
    if(n == 100) n++;
    cout << n * pow(100,d) << endl;
    return 0;
}

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

const int MOD = 1000000007;
const int INF = 1e9;

int main(){
  int n;
  const int max_n = 2 * 1e5;
  int a[max_n + 1];

  cin >> n;
  for(int i = 0; i < n; i++) cin >> a[i];
  sort(a, a+n);
  reverse(a, a+n);

  long long ans = a[0];
  int now = 1;
  for(int i = 0; i < n-2; i++){
    if(i % 2 == 0 && i != 0){
      now ++;
    }
    ans += a[now];
  }
  cout << ans << endl;


  return 0;
}

Measured memory_bytes: 4340
#include <iostream>
#include <stack>
#include <map>
#include <algorithm>
#include <queue>
#include <math.h>
#include <string.h>

using namespace std;

int N, M;
long x[2000];
long y[2000];
long z[2000];
long xyz[2000];

int main(int argc, char** argv) {
    cin >> N;
    if (N < 1000)
        cout << "ABC" << endl;
    else
        cout << "ABD" << endl;
    return 0;
    for(int i=1;i<=N;i++) cin >> x[i] >> y[i] >> z[i];

    long ans = -1e9;
    for (int px=0; px<=1; px++) for (int py=0; py<=1; py++) for (int pz=0; pz<=1; pz++) {
        vector<pair<long, int>> v(N);
        for(int i=1;i<=N;i++) {
            xyz[i] = 0;
            if (px)
                xyz[i] += x[i];
            else
                xyz[i] -= x[i];
            if (py)
                xyz[i] += y[i];
            else
                xyz[i] -= y[i];
            if (pz)
                xyz[i] += z[i];
            else
                xyz[i] -= z[i];
            pair<long, int> p(xyz[i], i);
            v[i - 1] = p;
        }
        sort(v.begin(), v.end());
        long ans_ = 0;
        long x_, y_, z_;
        x_ = 0;
        y_ = 0;
        z_ = 0;
        for (int i=N; N-M<i; i--) x_ += x[v[i-1].second];
        for (int i=N; N-M<i; i--) y_ += y[v[i-1].second];
        for (int i=N; N-M<i; i--) z_ += z[v[i-1].second];
        if (px && x_ < 0) break;
        if (py && y_ < 0) break;
        if (pz && z_ < 0) break;
        for (int i=N; N-M<i; i--) ans_ += v[i-1].first;
        ans = max(ans_, ans);
    }
    cout << ans << endl;
}

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

#define ld long double
#define ll long long
#define ALL(a)  (a).begin(),(a).end()
#define spa << " " <<
ll MOD = 1e9+7;
ll INF = 1e18;
void chmin(ll &a, ll b) { if (a > b) a = b; }
void chmax(ll &a, ll b) { if (a < b) a = b; }

int main(){
  ll i, j;
  string s;
  cin >> s;
  bool judge = true;
  ll result = 0;
  for( i = 0; i < 4; i++){
    if(s[i] == '+')
      result++;
    else
      result--;
  }

  /*
  vector<ll> a(n);
  for(i = 0; i < n; i++)
    cin >> a[i];
  //for(i = 0; i < n; i++)
    
  */
  
  /*
  if(judge)
    //cout << "Yes" << endl;
    //cout << "YES" << endl;
    //cout << "Yay!" << endl;
  else
    //cout << "No" << endl;
    //cout << "NO" << endl;
    //cout << ":(" << endl;
  */
  
  cout << result << endl;

  return 0;
}

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

using ll = long long;
using ull = unsigned long long;

using namespace std;

ll findGCD(ll x, ll y, ll z)
{
    ll result = __gcd(x, y);
    result = __gcd(result, z);
    return result;
}

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

    ll N, sum = 0;
    cin>>N;

    for(ll i=1;i<=N;++i)
    {
        for(ll j=1;j<=N;++j)
        {
            for(ll k=1;k<=N;++k)
                sum += findGCD(i,j,k);
        }
    }

    cout<<sum<<'\n';

    return 0;
}


Measured memory_bytes: 3652
n,m = map(int,input().split())
d = []
for i in range(m):
    a,b = map(int,input().split())
    a,b = a-1, b-1
    d.append((a,b))
#print(d)
pa = None

def root(a):
    if pa[a] == a:
        return a
    else:
        pa[a] = root(pa[a])
        return pa[a]
def is_same(a,b):
    return root(a) == root(b)
def unite(a,b):
    aa = root(a)
    bb = root(b)
    if aa == bb:
        return
    pa[aa] = bb

ans = 0
for i in range(m):
    pa = [x for x in range(n)]
    for j,v in enumerate(d):
        #(i,j,v)
        if i == j:continue
        a,b = v
        unite(a,b)
    a,b = d[i]
    if not is_same(a,b):
        ans +=1
print(ans)

Measured memory_bytes: 44524
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(v) v.begin(),v.end()
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int INF=1e9;
const int di[] = {-1,0,1,0};
const int dj[] = {0,-1,0,1};

int main(){
  string o,e;
  cin>>o>>e;
  rep(i,o.length()){
    cout<<o[i];
    if(i<e.length()){
      cout<<e[i];
    }
  }
  cout<<endl;
  return 0;
}

Measured memory_bytes: 3600
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vll vector<ll>
#define rep(c, a, b) for(ll c=a;c<b;c++)
#define re(c, b) for(ll c=0;c<b;c++)
typedef long long int ll;
typedef long double ld;
using namespace std;

int main(int argc, char const *argv[]) {
  ll n;std::cin >> n;
  vll a(n), b(n);
  multimap<ll, ll> mp;
  re(i, n) {
    std::cin >> a[i] >> b[i];
    mp.emplace(a[i] + b[i], i);
  }
  ll A = 0, B = 0;
  while(!(mp.empty())){
    ll idx = (*(--mp.end())).second;
    A+=a[idx];mp.erase(--mp.end());
    if(mp.empty()) break;
    idx = (*(--mp.end())).second;
    B+=b[idx];mp.erase(--mp.end());
    //std::cout << A << " " << B << '\n';
  }
  std::cout << A - B << '\n';
  return 0;
}


Measured memory_bytes: 8064
#include "bits/stdc++.h"
#define LF '\n'
#define ALL(x) x.begin(), x.end()
using namespace std;
typedef int64_t i64;
typedef pair<int,int> pii;
template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;}
constexpr int INF = 0x3f3f3f3f;
template<class Itr> void dump(Itr begin, Itr end) { for (;begin != end; ++begin) clog << *begin << LF; }

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

  string a, b, c;
  cin >> a >> b >> c;

  cout << a.front() << b.front() << c.front() << LF;


  return 0;
}



Measured memory_bytes: 256
import sys
import itertools
atn = []
for i in range(5):
    atn.append(int(input()))

seq = list(itertools.permutations(atn))
ans = 10**10
for s in seq:
    tmp_ans = 0
    for i in s:
        #print(tmp_ans,(10-(tmp_ans %10)))
        div = (10-(tmp_ans %10))
        div = div if div <10 else 0
        tmp_ans += div
        #print(tmp_ans)
        tmp_ans += i
        #print(tmp_ans)
    if tmp_ans < ans:
        ans = tmp_ans
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define N 200
using namespace std;
int a[N*N][2],from[N],A[N][2],B[N][2],g[N];
bool bz[N];
void ins(int x,int y){
	static int sum=1;
	a[++sum][0]=y,a[sum][1]=g[x],g[x]=sum;
}
bool dfs(int x){
	for (int i=g[x];i;i=a[i][1])
		if (!from[a[i][0]]){
			from[a[i][0]]=x;
			return 1;
		}else{
			if (bz[a[i][0]])continue;
			bz[a[i][0]]=1;
			if (dfs(from[a[i][0]])){
				from[a[i][0]]=x;
				return 1;
			}
		}
}
int main(){
	ios::sync_with_stdio(false);
	int n;
	cin>>n;
	for (int i=1;i<=n;i++)cin>>A[i][0]>>A[i][1];
	for (int i=1;i<=n;i++)cin>>B[i][0]>>B[i][1];
	for (int i=1;i<=n;i++)
		for (int j=1;j<=n;j++)
			if (A[i][0]<B[j][0]&&A[i][1]<B[j][1])
				ins(i,j);
	int ans=0;
	for (int i=1;i<=n;i++){
		memset(bz,0,sizeof(bz));
		ans+=dfs(i);
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
//https://www.codechef.com/problems/CHEFSUBA
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<algorithm>
#include<iostream>
#include<queue>
#include<map>
#include<cmath>
#include<set>
#include<stack>
#define ll long long
#define max(x,y) (x)>(y)?(x):(y)
#define min(x,y) (x)>(y)?(y):(x)
#define cls(name,x) memset(name,x,sizeof(name))
using namespace std;
const int inf=1<<28;
const int maxn=110;
const int maxm=110;
const int maxk=100010;
const int mod=1e9+7;
const double pi=acos(-1.0);
int n,m;
char s[maxn][maxn];
int main()
{
    //freopen("in.txt","r",stdin);
    int a,b;
    while(~scanf("%d %d",&n,&m))
    {
        for(int i=0;i<n;i++)
            scanf("%s",s[i]);
        for(int i=0;i<=n+1;i++)
        {
            for(int j=0;j<=m+1;j++)
            {
                if(i==0||i==n+1||j==0||j==m+1)
                    printf("#");
                else
                    printf("%c",s[i-1][j-1]);
            }
            printf("\n");
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<string>
using namespace std;
int main()
{
	string s;
	cin >> s;
	for(int i=0;i<s.size();i++)
		if (s[i] == 'C')
		{
			for (int j = i;j<s.size() ;j++)
				if (s[j] == 'F') 
				{
					printf("Yes");
					return 0;
				}
	    }
    cout << "No";
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <complex>
#include <iomanip>
#include <cmath>
using namespace std;
const double EPS = 1e-8;
const double INF = 1e18;
const double PI = acos(-1);
typedef complex<double> P;
typedef vector<P> VP;
#define X real()
#define Y imag()

double cross(P a, P b){
    return (conj(a)*b).Y;
}
double gettriarea(P a, P b, P c){
    return abs(cross(b-a, c-a)) /2;
}

int main(){
    while(1){
        int n,m;
        cin >> n >> m;
        if(n==0) break;

        VP p(n);
        for(int i=0; i<n; i++){
            double d;
            cin >> d;
            p[i] = P(1, 0) *P(cos(d*2*PI), sin(d*2*PI));
        }
        double ans = 0;
        for(int sp=0; sp<n; sp++){
            p.push_back(p[0]);
            p.erase(p.begin());
            vector<vector<double> > dp(n+1, vector<double>(n+1, 0));
            for(int cp=2; cp<n; cp++){
                for(int cn=3; cn<=cp +1; cn++){
                    for(int lp=cn-2; lp<cp; lp++){
                        dp[cp][cn] = max(dp[cp][cn], dp[lp][cn-1] +gettriarea(p[0], p[lp], p[cp]));
                    }
                }
            }
            for(int i=0; i<n; i++){
                ans = max(ans, dp[i][m]);
            }
        }
        cout << fixed << setprecision(6);
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 3488
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cassert>
#define ll long long
using namespace std;
inline int read(){
	int re=0,flag=1;char ch=getchar();
	while(!isdigit(ch)){
		if(ch=='-') flag=-1;
		ch=getchar();
	}
	while(isdigit(ch)) re=(re<<1)+(re<<3)+ch-'0',ch=getchar();
	return re*flag;
}
int n,ch[100010];ll a[100010];
ll dp0,dp1,dp2;
int main(){
	n=read();int i;char c;
	for(i=1;i<=n;i++){
		a[i]=read();
		if(i==n) break;
		c=getchar();
		while(c!='+'&&c!='-') c=getchar();
		ch[i+1]=(c=='-');
//		cout<<"finish readin "<<i<<' '<<a[i]<<' '<<ch[i+1]<<'\n';
	}
	dp0=0;dp1=dp2=-1e15;
	for(i=1;i<=n;i++){
		if(ch[i]){
			dp0-=a[i];
			dp1+=a[i];
			dp2-=a[i];
			dp2=max(dp2,dp1);
			dp1=max(dp1,dp0);
		}
		else{
			dp0+=a[i];
			dp1-=a[i];
			dp2+=a[i];
		}
		dp1=max(dp2,dp1);
		dp0=max(dp1,dp0);
	}
	cout<<dp0<<'\n';
}

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

typedef long long ll;
typedef unsigned long long ull;

ll A[2000000], B[2000000], C[10001];

void counting_sort(ll *A, ll *B, int n, int k){
    for(int i=0;i<k;i++) C[i] = 0;
    for(int i=0;i<n;i++) C[A[i]]++;
    for(int i=1;i<k;i++) C[i]+=C[i-1];
    for(int i=n-1;i>=0;i--){
        B[C[A[i]]-1] = A[i];
        C[A[i]]--;
    }
}


int main(){
    int n;
    cin >> n;
    for(int i=0;i<n;i++) cin >> A[i];
    counting_sort(A, B, n, 10001);

    cout << B[0];
    for(int i=1;i<n;i++) cout << ' ' << B[i];
    cout << endl;    
    
    return 0;
}


Measured memory_bytes: 34416
from itertools import permutations

n,m = map(int,input().split())
graph = [[] for _ in range(n)]
for _ in range(m):
    a,b = map(int,input().split())
    graph[a-1].append(b-1)
    graph[b-1].append(a-1)

ans = 0
lsts = list(permutations(range(n)))

for lst in lsts:
    if lst[0] != 0:
        continue
    now = 0
    for l in lst[1:]:
        if not l in graph[now]:
            break
        now = l
    else:
        ans += 1
        
print(ans)

Measured memory_bytes: 8052
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <functional>
#include <limits.h>
#include <set>
#include <map>
#include <tuple>
using namespace std;

#define ll long long
#define ull unsigned long long
#define rep(i,N) for (int i=0;i<N;i++)
#define loop(i,N,M) for(int i=N;i<M;i++)
#define MAX(v) *max_element(v.begin(),v.end())
#define MIN(v) *min_element(v.begin(),v.end())
#define SORTL2S(type,v) sort(v.begin(),v.end(),greater<type>())
#define SORTS2L(type,v) sort(v.begin(),v.end())
#define SORTMF(v,func) sort(v.begin(),v.end(),func)

//変数
string S;

//解法
void solve() {

	int ans = 1000;

	for (int i = 2; i < S.size(); i++) {
		int sum = 0;
		sum += S[i] - '0';
		sum += 10 * (S[i - 1] - '0');
		sum += 100 * (S[i - 2] - '0');

		ans = min(ans, abs(sum - 753));
	}

	cout << ans;

	return;
}

int main() {
	//入力

	cin >> S;

	solve();
	cout << endl;
	return 0;
}

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

    typedef long long ll;
    typedef long double ld;
    ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
    ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }
    #define endl '\n'
    #define max3(a,b,c) max(a,max(b,c))

    const int q = 1e9+9;




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

        bool chek[100001]= {false};
        int WA[105000];
        int t=0,f=0;

        while(m--) {
            int p;
            string s;
            cin >> p >> s;
            if(chek[p]) continue;
            if(s == "AC") {
                chek[p] = true;
                t++;
                f += WA[p];
            } else if(s == "WA") {
                WA[p]++;
            }
        }

        cout<<t<<" "<<f<<endl;
        return 0;
    }
        // gotcha;


Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  string s;
  while(cin>>s){
    int r1=0,r2=0;
    char op='n';
    bool f=0;
    int p=0;
    while(p<(int)s.size()){
      while(isdigit(s[p])) r2=r2*10+(s[p++]-'0');
      if(r2>9999){
	f=1;
	break;
      }
      if(op=='n') r1=r2;
      if(op=='+') r1+=r2;
      if(op=='-') r1-=r2;
      if(op=='*') r1*=r2;
      if(r1<0||r1>9999){
	f=1;
	break;
      }
      r2=0;
      op=s[p++];
    }
    if(f) cout<<"E"<<endl;
    else cout<<r1<<endl;
  }
  return 0;
}

Measured memory_bytes: 2968
def main():
  ## IMPORT MODULE
  #import sys

  #sys.setrecursionlimit(100000)
  #input=lambda :sys.stdin.readline().rstrip()

  #f_inf=float("inf")
  #MOD=10**9+7
  
  if 'get_ipython' in globals(): 
    ## SAMPLE INPUT
    n, m = 4, 3
    H = [1, 2, 3, 4]
    graph = [[(3, 2)], [(3, 2), (4, 3)], [(1, 0), (2, 1)], [(2, 1)]]

  else:
    ##INPUT 
    n, m = map(int, input().split())
    H = list(map(int, input().split()))
   
    graph = [[] for _ in range(n)]
    for i in range(m):
      a, b = map(int, input().split())
      a -= 1
      b -= 1
      graph[a].append((H[b], b))
      graph[b].append((H[a], a))

  ## SUBMITION CODES HERE
  cnt = 0
  for i in range(n):
    graph[i].sort(reverse=True)
    if graph[i]:
      if graph[i][0][0] < H[i]:  
        cnt += 1
    else:
      cnt += 1
  print(cnt)
  
main()

Measured memory_bytes: 42252
#include<cstdio>
#include<algorithm>
#define ll long long
#define MN 500
using namespace std;
ll read_p,read_ca,read_f;
inline ll read(){
	read_p=0;read_ca=getchar();read_f=1;
	while (read_ca<'0'||read_ca>'9') read_f=read_ca=='-'?-1:read_f,read_ca=getchar();
	while (read_ca>='0'&&read_ca<='9') read_p=read_p*10+read_ca-48,read_ca=getchar();
	return read_p*read_f;
}
int T;
const ll M=1e18;
const int MOD=1e9+7;
struct na{ll x,y;}S[MN][MN];
ll n,m,F[MN],mmh,MMH;
int main(){
	T=read();
	F[0]=F[1]=1;
	for (ll i=2;(F[i]=F[i-1]+F[i-2])<=M;i++);
	S[0][0].x=S[0][0].y=1;
	for (ll i=1;F[i]<=M;i++){
		for (ll j=0;j<i;j++) S[i][j].x=S[i-1][j].x+S[i-1][j].y,S[i][j].y=S[i-1][j].x;
		S[i][i].x=F[i+2];S[i][i].y=F[i];
	}
	while(T--){
		n=read();m=read();
		if (n==1&&m==1) {printf("1 1\n");continue;}
		if (n<m) swap(n,m);
		mmh=1;
		while (F[mmh+2]<=n&&F[mmh+1]<=m) mmh++;
		printf("%lld ",mmh);mmh--;
		MMH=0;
		for (ll i=0;i<=mmh;i++){
			if (m>=S[mmh][i].x) (MMH+=(n-S[mmh][i].y)/S[mmh][i].x)%=MOD;
			if (n>=S[mmh][i].x) (MMH+=(m-S[mmh][i].y)/S[mmh][i].x)%=MOD;
		}
		printf("%lld\n",(MMH+(mmh?0:m))%MOD);
	}
}


Measured memory_bytes: 4352
import math

n = int(input())
first_pos = int(math.log10(n))
count = 0


def find(pos, found=[], permit_9=False, permit_zero=False):
    global n
    global count

    if pos < 0:
        return

    digit = 9 if permit_9 else (n // (10**pos)) % 10

    #print('%d %d %d %d %s %s' % (pos, n, digit, 10**pos, found, permit_9))

    for i in range(0, digit + 1):
        if i == 0 and permit_zero:
            find(pos - 1, found=found, permit_9=permit_9 or i < digit, permit_zero=True)
        if i == 3 or i == 5 or i == 7:
            found.append(i)
            find(pos - 1, found=found, permit_9=permit_9 or i < digit, permit_zero=False)
            if pos == 0 and set(found) == {3, 5, 7}:
                #print('== OK == %s' % found)
                count += 1
            found.pop()

#print(first_pos)
find(first_pos, found=[], permit_9=False, permit_zero=True)
print(count)


Measured memory_bytes: 3316
#include <stdio.h>


int main(int argc, char const *argv[])
{
    int a, b, c;
    
    scanf("%d %d %d", &a, &b, &c);
    
    
    if (a < b && b < c) {
        puts("Yes");
    }
    else
    {
        puts("No");
    }
    
    
    return 0;
}



Measured memory_bytes: 2044
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define pi 3.141592653589793238
#define int long long
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

map<int,int>vis[100005];
map<int,vector<int> >adj[100005];
vector<vector<pair<int,int> > >mm;

vector<int>temp;
int ind=0;
int dis[1000005];
bool flag=false;

void dfs(int ver,int col)
{
    vis[ver][col]=1;
    temp.push_back(ver);
    for(auto i:adj[ver][col])
    {
        if(!vis[i][col])
        {
            dfs(i,col);
        }
    }
}

void bfs()
{
    deque<pair<int,int> >d;
    d.push_back({0,1});
    dis[1]=0;
    while (!d.empty())
    {
        pair<int,int>p=d.front();
        d.pop_front();
        for(auto i:mm[p.second])
        {
            if(dis[i.first]>p.first+i.second)
            {
                dis[i.first]=p.first+i.second;
                if(i.second==0)
                    d.push_front({dis[i.first],i.first});
                else
                    d.push_back({dis[i.first],i.first});
            }
        }
    }    
}

signed main()
{

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

#ifndef ONLINE_JUDGE
    if(fopen("INPUT.txt","r"))
    {
    freopen ("INPUT.txt" , "r" , stdin);
    freopen ("OUTPUT.txt" , "w" , stdout);
    }
#endif  

    int n,m;
    cin>>n>>m;
    mm.resize(1000005);
    int x,y,z;
    set<pair<pair<int,int> ,int> >s;
    for(int i=0;i<m;i++)
    {
        cin>>x>>y>>z;
        if(x>y)
            swap(x,y);
        s.insert({{x,y},z});
    }
    for(auto i:s)
    {
        x=i.first.first;
        y=i.first.second;
        z=i.second;
        adj[x][z].push_back(y);
        adj[y][z].push_back(x);
        mm[x].push_back({y,1});
        mm[y].push_back({x,1});
    }
    int count=n;
    for(int i=1;i<=n;i++)
    {
        for(auto j:adj[i])
        {
            if(!vis[i][j.first])
            {
                temp.clear();
                ind=0;
                dfs(i,j.first);

                count++;

                for(auto k:temp)
                {
                    mm[count].push_back({k,0});
                    mm[k].push_back({count,1});
                }
            }
        }
    }

    fill_n(dis,1000005,1e17);

    bfs();
    if(dis[n]>=1e17)
        cout<<-1;
    else
        cout<<dis[n];
}



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

int main()
{
   ios::sync_with_stdio(0);
   cin.tie(0);
    int n; cin >> n;
    string s; cin >>  s;

    int start = 0;
    int endd = n - 1;


    int cnt = 0;
    for( ;;){
        int firstWhilte = n;
        for(int i = start; i < n; ++i){
            if(s[i] == 'W'){
                firstWhilte = i;
                break;
            }
        }

        int lastRed = -1;
        for(int i = endd; i >= 0 ; --i){
            if(s[i] == 'R'){
                lastRed = i;
                break;
            }
        }

        if(firstWhilte < lastRed){
            swap(s[firstWhilte], s[lastRed]);
            ++cnt;
        }else{
            break;
        }

        start = firstWhilte + 1;
        endd = lastRed - 1;

    }

    cout << cnt << "\n";


    return 0;
}


Measured memory_bytes: 3736
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
#define rep(i,n) for (ll i=0;i<(n);++i)
#define rep2(i,a,b) for (ll i=(a);i<(b);++i)
#define debug(x) cout << #x << '=' << x << endl
#define all(v) (v).begin(),(v).end()
const ll MOD=1e9+7;
//const ll MOD=998244353;
const ll INF=1e9;
const ll IINF=1e18;
const double EPS=1e-8;
const double pi=acos(-1);

template<class T> inline bool chmin(T &a,T b){
    if (a>b){a=b; return true;}
    return false;
}
template<class T> inline bool chmax(T &a,T b){
    if (a<b){a=b; return true;}
    return false;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,ans=0; string S; cin >> N >> S;
    rep(i,N-2){
        if (S[i]=='A'&&S[i+1]=='B'&&S[i+2]=='C') ++ans;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int power2(int n)
{
	int re = 1;
	for (int i = 0; i < n; i++){
		re *= 2;
	}
	return re;
}
int main(void)
{
	int n, m,re;
	scanf("%d%d", &n, &m);
	re = power2(m)*(1900 * m + (n - m) * 100);
	printf("%d\n", re);
	return 0;
}

Measured memory_bytes: 128
N = int(input())
H = list(map(int, input().split()))
 
flag = False
for i in range(1, N):
    if H[i-1] > H[i]:
        if H[i-1] == H[i]+1:
            if flag==False:
                H[i-1] -= 1
                flag = True
        else:
            break
        if flag==False:
            H[i-1] -= 1
    else:
        if flag==False:
            H[i-1] -= 1
        if H[i-1] != H[i]:
            flag = False

if H == sorted(H):
    print('Yes')
else:
    print('No')

Measured memory_bytes: 14396
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define MOD 1000000007

ll findpow(ll a,ll b){
    ll cnt=0,i,j;
    while(a>1){
        a=a/b;
        cnt++;
    }
    return cnt;
}

int main(){
    ll i,j,k,sum=0,n,flag=1;
    string a,b,c;
    cin>>a>>b>>c;
    i=0;j=0;k=0;
    flag=1;
    while(1){
        if(flag==1){
            if(a[i]=='a'){
                i++;
                flag=1;
            }
            else if(a[i]=='b'){
                i++;
                flag=2;
            }
            else if(a[i]=='c'){
                i++;
                flag=3;
            }
        }
        else if(flag==2){
            if(b[j]=='a'){
              //  i++;
              j++;
                flag=1;
            }
            else if(b[j]=='b'){
                j++;
                flag=2;
            }
            else if(b[j]=='c'){
                j++;
                flag=3;
            }
        }
        else if(flag==3){
            if(c[k]=='a'){
               // i++;
               k++;
                flag=1;
            }
            else if(c[k]=='b'){
                k++;
                flag=2;
            }
            else if(c[k]=='c'){
                k++;
                flag=3;
            }
        }
        if(i==a.size()&&flag==1){
            cout<<"A"<<endl;
            break;
        }
        else if(j==b.size()&&flag==2){
            cout<<"B"<<endl;
            break;
        }
        else if(k==c.size()&&flag==3){
            cout<<"C"<<endl;
            break;
        }
    }
    
	return 0;
}

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

int main(){
    double w, h;
    cin >> w >> h;
    int x, y;
    cin >> x >> y;

    int t = 0;
    if((w == x*2) && (h == y*2)){
        t = 1;
    }
    double ans = w * h / 2;
    printf("%lf %d\n", ans, t);
}

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

ll gcd(ll x,ll y) {return y ? gcd(y,x%y) : x;} 
ll lcm(ll x,ll y) {return x/gcd(x,y)*y;}

int main(){
    int n;
    string s;
    cin >> n >> s;
    ll ans=0;
    vector<char> a={'B','G','R'};
    do{
        vector<ll> b(3,0);
        for(int i=0;i<n;i++){
            if(s[i]==a[0]) b[0]++;
            if(s[i]==a[1]) b[1]+=b[0];
            if(s[i]==a[2]) b[2]+=b[1];
        }
        ans+=b[2];
        for(int i=1;i<=(n-1)/2;i++){
            for(int j=0;j<n-2*i;j++){
                if(s[j]==a[0]&&s[j+i]==a[1]&&s[j+i+i]==a[2]) ans--;
            }
        }
    }while(next_permutation(a.begin(),a.end()));
    
    cout << ans << endl;
    return 0;
}











Measured memory_bytes: 3644
#include<bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define lli long long int
#define ulli unsigned long long int
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define pf pop_front()
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define loopl(i,a,b) for(lli i=a;i<b;i++) 
#define loop(i,a,b) for(int i=a;i<b;i++)
#define all(v) v.begin(), v.end()
#define mod 1000000007
#define mod2 1000000006
#define inf 100000000000000000
#define lld long double
#define pll pair<long long int,long long int>
#define pii pair<int,int>
#define vll vector<lli>
#define vii vector<int>
#define is indexed_set
#define eps 0.000001
#define endl '\n'
#define mo 998244353
#define pi 3.141592653589793
 
using namespace std ;
 
typedef tree<pair<pll,lli>,null_type,less<pair<pll,lli>>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set;
 
#define N 100005
 
int main() 
{
/////////////////////////////////////
    
    fastio;
 
/////////////////////////////////////  
   
    lli n,m;
    cin>>n>>m;

    bool a[n+1]={0};
    lli cnt3[n+1]={0};
    loopl(i,0,m)
    {
    	lli p;
    	string s;
    	cin>>p;
    	cin>>s;

    	if(a[p] == 0)
    	{
    		if(s=="WA") cnt3[p]++;
    		else a[p]=1;
    	}
    }

    lli cnt2=0,cnt=0;
    loopl(i,1,n+1)
    {
    	if(a[i]) 
    	{
    		cnt2++;
    		cnt+=cnt3[i];
    	}
    }

    cout<<cnt2<<" "<<cnt;
	
}

        
 


Measured memory_bytes: 1152
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-15
#define mp(a1,a2) make_pair(a1,a2)
typedef long long ll;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
int dp[2001][2001];
int sum[2][4001][2001]={{{0}}};
int main(){
	int N;
	char c[2001];
	int a[4001];
	int pos[2][2001];
	vpint siro,kuro;
	scan(N);
	rep(i,N*2){
		string S;
		scan(S);scan(a[i]);a[i]--;
		c[i]=S[0];
		int iro;
		if(c[i]=='W') iro=0;
		else iro=1;
		pos[iro][a[i]]=i;
		sum[iro][i][a[i]]++;
	}
	rep(iro,2){
		rep(i,N*2){
			for(int j=N-1;j>=1;j--){
				sum[iro][i][j-1]+=sum[iro][i][j];
			}
		}
		rep(i,N*2-1){
			rep(j,N){
				sum[iro][i+1][j]+=sum[iro][i][j];
			}
		}
	}
	rep(i,N+1) rep(j,N+1) dp[i][j]=INF;
	dp[0][0]=0;
	rep(i,N+1){
		rep(j,N+1){
			if(i<N){
				int p=pos[0][i];
				dp[i+1][j]=min(dp[i+1][j],dp[i][j]+sum[0][p][i+1]+sum[1][p][j]);
			}
			if(j<N){
				int p=pos[1][j];
				dp[i][j+1]=min(dp[i][j+1],dp[i][j]+sum[0][p][i]+sum[1][p][j+1]);
			}
		}
	}
	prin(dp[N][N]);
	return 0;
}


Measured memory_bytes: 78464
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1e18;
const ll MOD = 1e9 + 7;


int main(){
    int n, k;
    cin >> n >> k;
    vector<ll> v(n);
    rep(i, n) cin >> v[i];

    ll ans = INF;
    for(int bit=0; bit<(1<<n); bit++){
        if(__builtin_popcount(bit) < k) continue;
        ll maxv = 0;
        ll sum = 0;
        rep(i, n){
            if(((bit>>i) & 1) && v[i] <= maxv){
                sum += (maxv - v[i] + 1);
                maxv++;
            }
            else chmax(maxv, v[i]);
        }
        chmin(ans, sum);
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
import sys
import copy
import  math
import bisect
from collections import *
from operator import itemgetter

from fractions import gcd
def lcm(x, y):
    return (x * y) // gcd(x, y)

stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

n = ni()
li = [ni() for _ in range(n)]
ans = li[0]
for i in range(1, n):
    ans = lcm(ans, li[i])
print(ans)

Measured memory_bytes: 5144
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const long long INF = 1e15;

#include <math.h>
#define PI 3.14159265358979323846264338327950L

int mxN = 50000000;
vector<int> cnt(mxN + 1);

int main() {
    string ss;
    cin >> ss;
    int f = stoi(ss.substr(0, 2)), s = stoi(ss.substr(2));
    if (ss.substr(2) == "00" && ss.substr(0, 2) == "00") {
        cout << "NA";
        return 0;
    }
    if (ss.substr(0, 2) == "00") {
        if (s <= 12) {
            cout << "YYMM";
            return 0;
        }
        else {
            cout << "NA";
            return 0;
        }
    }
    if(ss.substr(2) == "00") {
        if (f <= 12) {
            cout << "MMYY";
            return 0;
        }
        else {
            cout << "NA";
            return 0;
        }
    }
    
    if (f > 12 && s > 12) {
        cout << "NA";
        return 0;
    }
    if (f <= 12 && s <= 12) {
        cout << "AMBIGUOUS";
        return 0;
    }
    if (f <= 12) {
        cout << "MMYY";
        return 0;
    }
    if (s <= 12) {
        cout << "YYMM";
        return 0;
    }
    cout << "NA";


    return 0;
}

Measured memory_bytes: 198352
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<stdio.h>
#include<cmath>
#include<stack>
#include<set>
#include<map>
#include<stdio.h>
#include<functional>
#include<queue>

using ll = long long;

using namespace std;

ll mod = 1000000007;

ll n_pow(ll a, ll n) {
	if (n == 0)return 1;
	ll t = n_pow(a, n / 2);
	t *= t;
	t %= mod;
	if (n % 2 == 1)t *= a;
	return t % mod;
}

const int INF = 1001001001;
//const ll INF = 1e18;

int dx[] = { 1,0,-1,0 };
int dy[] = { 0,1,0,-1 };

ll cal_gcd(ll a, ll b) {
	ll m = max(a, b);
	ll n = min(a, b);
	while (m%n != 0) {
		ll b = m % n;
		m = n;
		n = b;
	}
	return n;
}


int main() {
	string s, t;
	cin >> s >> t;
	bool ok = true;
	if (t.size() != s.size() + 1)ok = false;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] != t[i])ok = false;
	}
	if (ok)cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 3632
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

a, b = [0], [0]
for i in range(N):
    a.append(a[i] + A[i])
for j in range(M):
    b.append(b[j] + B[j])
j = M
ans = []
for i in range(N + 1):
    if a[i] > K:
        break
    while b[j] > K - a[i]:
        j -= 1
    ans.append(i + j)
ans_max = max(ans)
print(ans_max)

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

#define in cin
#define out cout

#define REP(i,n) for(int i=0; i<n; i++)
#define REP2(i,s,e) for(int i=s; i<e; i++)
#define REPE(i,s,e) for(int i=s; i<=e; i++)
#define REPR(i,s,e) for(int i=s; i>=e; i--)

#define all(v) v.begin(), v.end()
#define pb push_back

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

#define x first
#define y second
#define intINF 2147483647
#define llINF 9223372036854775807LL
#define MOD 1000000007

int main()
{

    int n, k; scanf("%d%d", &n, &k);
    if(k == 1 || k == 2*n-1)
    {
        out << "No\n";
        return 0;
    }
    out << "Yes\n";

    int p = (n-k+2*n-1)%(2*n-1);
    vector<int> v(2*n-1);
    REP(i, 2*n-1)
    {
        v[(p+i)%(2*n-1)] = i+1;
    }
    for(int w : v) printf("%d\n", w);

    return 0;
}


Measured memory_bytes: 2304
#include<iostream>
using namespace std;
int n,m,f[200010],a[200010],b[200010],z[200010],d;
int g(int s){
	return f[s]==s?s:f[s]=g(f[s]);
}
void o(int x,int y){
	int p=g(x),q=g(y);
	if(p==q) return;
	f[q]=p;
	z[p]+=z[q];
}
int main(){
	cin>>n>>m;
	for(int i=1;i<=n;i++) f[i]=i,z[i]=1;
	for(int i=1;i<=m;i++){
		cin>>a[i]>>b[i];
		o(a[i],b[i]);
	}
	for(int i=1;i<=n;i++) if(g(i)==i)
	d=max(d,z[i]);
	cout<<d;
}

Measured memory_bytes: 6836
from collections import deque

H, W = map(int, input().split())
S = [["#" for _ in range(W+2)]]
white = 0
for h in range(H):
    s = ["#"] + list(input()) + ["#"]
    white += s.count(".")
    S.append(s)
S.append(["#" for _ in range(W+2)])

S[1][1] = 0
start = (1, 1)
goal = (H, W)
ans = -1
stack = deque()
stack.append(start)
move = [(1, 0), (-1, 0), (0, 1), (0, -1)]
while stack:
    x, y = stack.pop()
    if (x, y) == goal:
        ans = white - S[x][y] - 1
        print(ans)
        exit()
    for dx, dy in move:
        nx, ny = x + dx, y + dy
        if S[nx][ny] != ".":
            continue
        stack.appendleft((nx, ny))
        S[nx][ny] = S[x][y] + 1
print(ans)

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define pb push_back
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)
#define mod (ll)(1e9+7)
#define int ll

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}


signed main() {
  int n, a, b, x[100001];
  int ans = 0;
  cin >> n >> a >> b;

  rep(i, 0, n) cin >> x[i];

  rep(i, 1, n) {
    if((x[i] - x[i - 1]) * a > b) ans += b;
    else ans += (x[i] - x[i - 1]) * a;
  }

  cout << ans << endl;
}


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

using namespace std;

int main(){
    int  n;cin>>n;
    int a=0,un=0;
    for(int i=0;i<n;++i){
        string s;cin>>s;
        if(s[0]=='A')++a;
        else{
            if(a>un)++un;
            else{
                cout<<"NO"<<endl;
                return 0;
            }
        }
    }
    if(a==un)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    return 0;
}

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

int main(){
    int64_t N, A, B, X, Y,ans;
    cin >> N >> A>> B;
  
    X = N/(A+B);
    Y = N%(A+B);

    if(Y>A){
        ans=A*X+A;
    }
    else{
        ans = A*X+Y;
    }


    cout<< ans <<endl;
}

Measured memory_bytes: 384
//shara's here
//SPEEEEEEEEEED IS KEEEEEEEEEEY
#include <bits/stdc++.h>
using namespace std;
typedef int q;
typedef double w;
typedef string s;
typedef long long ll;
typedef long double ld;
#if defined(ONLINE_JUDGE)
#include "E:\shara\debug.hpp"
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
#define speed ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
bool validm(ll k){
     if(k>=1&&k<=12)return true;
     else return false;
}
int main(){
    speed;
    bool Vm1=0,Vm2=0;
    ll x;
    cin>>x;
    ll m=x%100;
    x/=100;
    ll y=x;
    Vm1=validm(m);
    Vm2=validm(y);
    if(Vm1&&Vm2){cout<<"AMBIGUOUS"<<endl;}
    else if(Vm1&&!Vm2)cout<<"YYMM"<<endl;
    else if(!Vm1&&Vm2)cout<<"MMYY"<<endl;
    else cout<<"NA"<<endl;
return 0;}
/*
███████████████████████████████████████████████████
███████████████████████████████████████████████████
██████████████████████████████████▀████████████████
██████████████████████████████████░▀███████████████
██████████████████████████████▌███░░░▀▀████████████
██▀████████████████████▐██████░▐██░░░░░░▀▀█████████
██░████████████████████▐█████▌░██▌▄░░░░▄▄░▄████▀███
█▌░███████████████████▀░█████░░░█░░░▄████░░███▀▐███
█▌░▐██████████████████░░████▌░░░▀░░▀███▀▀░▐███▄████
██░▀██████████████▌▐█▐▄▄████▌░░░░░░░░░░░░░▌████████
███░███████████████▀░▄▄██▀█▐░░░░░░░░░░░░░░▐████████
███▄░██████████████▄░░░░░░▀▀▀░░░░░░░░░░░░░█▐███████
████▄░██████████████████▄▄▄▄▄▄▐▄░░░░░░░░░░░████████
█████▄█████████████████▀▀▀▀▀▀░░░░░░░░░░░░░░████████
████████████████████████▄░░░░░░░░░░░░░░░▄░░████████
██████████████████████████▄▄▄░░░░░░░░░▄█░▄█████████
████████████████████████████████▄░░░░██▄███▀░░▀████
█████████████████████████████▀█████▄███▀▀▀░░▄▄░████
████████████████████████████▀░░▀░░▀▀░░░░▄▄▄██▀░░▀▀█
███████████████████████████▌░░░░░░░░░░░███████░░░▄█
███████████████▄░▀████████▀░░░░░░▀░░░░███████▌░░░██
███▄▄████████████▄░▀██████▄░░░░░█░░░░████████░░░▀▀
░▀█████████████████▄░▀█████░░░░██░░░░▀██████░░░░░▄█
▐█▄▀█████████████████▄░▀████░░░██▌░░░▐████▀░░░░▄███
▐███▄▀▀█████████████████▄░▀▀░░░░▀██▌▄█▀▀░░░▄▄██████
▀▀▀▀▀░░░▀▀▀▀▀░░░▀▀▀▀▀▀▀▀▀▀▀░░░░░░░▀▀░░░░░░▀▀▀▀▀▀▀▀▀
*/

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

using namespace std;

int main()
{
	int n;
	cin >> n;
	set<int> s;
	while(n--)
	{
		int x;
		scanf("%d", &x);
		s.insert(x);
	}	
	cout << s.size() << endl;
	return 0;
} 

Measured memory_bytes: 256
#include <bits//stdc++.h>
using namespace std;
int main(void){
    int a,b,c,i,j;
    cin>>a>>b;
    if(a>12)
    cout<<b<<endl;
    else if(a>5)
    cout<<b/2<<endl;
    else
    cout<<"0"<<endl;
}


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

int main() {
#ifndef ONLINE_JUDGE
   freopen("inp.txt", "r", stdin);      freopen("outp.txt", "w", stdout);
#endif
   ios::sync_with_stdio(false);   cin.tie(NULL);   cout.tie(NULL);

   int n;
   cin >> n;
   vector <int> a(n);
   for (auto &i : a) {
      cin >> i;
   }
   sort(a.rbegin(), a.rend());

   ll ans = a[0];
   for (int i = 1; i < n / 2; i++)
      ans += 2 * a[i];
   if (n % 2)
      ans += a[n / 2];

   cout << ans << '\n';

   return 0;
}

Measured memory_bytes: 3992
#include<stdio.h>

#define NUM 1000000

int main(void){
    int s;
    scanf("%d",&s);
    int a[NUM];
    a[0]=s;
    
    for(int i = 1; i <= NUM; i++){
        if(a[i-1]%2){
            a[i]=3*a[i-1]+1;
        }else{
            a[i]=a[i-1]/2;
        }
        
        for(int j = 0; j < i; j++)
        {
            if(a[i]==a[j]){
                printf("%d",i+1);
                return 0;
            }
        }
        
    }
    

    return 0;
}

Measured memory_bytes: 128
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int h = nextInt(scanner);
        int w = nextInt(scanner);
        int k = nextInt(scanner);

        char[][] c = new char[h][w];



        for (int i = 0; i < h; i++) {
            String row = scanner.next();
            int ccount = 0;
            for (char cc: row.toCharArray()) {
                c[i][ccount] = cc;
                ccount++;
            }
        }

        int sum = h + w;
        List<Integer> x = new ArrayList<>();
        List<Integer> y = new ArrayList<>();

        int count = 0;

        for (int i = 0; i < (Math.pow(2, sum)); i++){
            x.clear();
            y.clear();
            int black = 0;
            char[][] strings = new char[h][w];
            for (int j = 0; j < h; j++) {
                if (w >= 0) System.arraycopy(c[j], 0, strings[j], 0, w);
            }
            for (int j = 0; j < sum; j++) {
                if ((1 & i >> j) == 1) {
                    if (j < h) {
                        x.add(j);
                    }else {
                        y.add(j - h);
                    }
                }
            }
            if (!x.isEmpty()) {
                for (int xx :x) {
                    for (int l = 0; l < w; l++) {
                        strings[xx][l] = 'R';
                    }
                }
            }
            if (!y.isEmpty()) {
                for (int yy: y) {

                        for (int l = 0; l < h; l++) {
                            strings[l][yy] = 'R';
                        }

                }
            }
            for (int l = 0; l < h; l++) {
                for (int m = 0; m < w; m++) {
                    if (strings[l][m] == '#') {
                        black++;
                    }
                }
            }
            if (black == k) {
                count++;
            }
        }
        System.out.println(count);
    }


    private static int nextInt(Scanner scanner) {
        return Integer.parseInt(scanner.next());
    }

    private static long nextLong(Scanner scanner) {
        return Long.parseLong(scanner.next());
    }

    private static float nextFloat(Scanner scanner) {
        return Float.parseFloat(scanner.next());
    }

    private static double nextDouble(Scanner scanner) {
        return Double.parseDouble(scanner.next());
    }


}





Measured memory_bytes: 39200
//include
//------------------------------------------
#include <bits/stdc++.h>
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;}
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
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)
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const long long INF = 1000000007;
//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;
// chmax chmin
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; }

int main(void){
    ll A,B;
    cin >> A >> B;
    
    for(ll i=1; i<B+1; i++){
        if(A*i % B == 0){
            cout << A*i << endl;
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007
#define EPS 1e-10
#define MAX_N 20000
#define MAX_M 16

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;
typedef pair<P, char> PC;

int n, m, k;
V vi;

int main(){
	cin >> n;
	FOR(i, 1, 2 * n + 1)vi.push_back(i);
	cin >> m;
	REP(i, m){
		V s, t;
		cin >> k;
		if (k != 0){
			REP(j, k)s.push_back(vi[j]);
			FOR(j, k, 2 * n)t.push_back(vi[j]);
			vi.clear();
			REP(j, t.size())vi.push_back(t[j]);
			REP(j, s.size())vi.push_back(s[j]);
		}
		else{
			REP(j, n)s.push_back(vi[j]);
			FOR(j, n, 2 * n)t.push_back(vi[j]);
			vi.clear();
			REP(j, n){
				vi.push_back(s[j]);
				vi.push_back(t[j]);
			}
		}
	}
	REP(i, vi.size())cout << vi[i] << endl;
}

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

using namespace std;

int dp[10001];

int main(void){

  int N,W;
  cin >> N >> W;

  vector<int>v(N),w(N);

  for(int i=0;i<N;i++)
    cin >> v[i] >> w[i];

  fill(dp,dp+10001,0);

  for(int i=0;i<N;i++)
    for(int j=W;j>=0;j--)
      if(j+w[i]<=W)dp[j+w[i]]=max(dp[j+w[i]],dp[j]+v[i]);

  int ans=0;
  for(int j=0;j<=W;j++)
    ans = max(ans, dp[j]);

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

Measured memory_bytes: 1240
#include <bits/stdc++.h>
using namespace std;
int main () {
    int N;
    cin >> N;
    vector<int> v;
    vector<pair<double, double>> m(N);
    for (int i = 0; i < N; i++) {
        v.push_back(i);
        cin >> m[i].first >> m[i].second;
    }
    double ans = 0;
    do {
        double res = 0;
        for (int i = 1; i < N; i++) {
            int a = v[i-1], b = v[i];
            res += sqrt(pow(m[a].first-m[b].first, 2) + pow(m[a].second-m[b].second, 2));
        }
        for (int i = 2; i <= N; i++) {
            res /= i;
        }
        ans += res;
    } while (next_permutation(v.begin(), v.end()));
    printf("%.10lf\n", ans);
}

Measured memory_bytes: 256
let split str delim =
  let rec doit s acc =
    match
      try Some (String.index s delim)
      with _ -> None
    with
    | None -> s :: acc
    | Some i ->
        let s1 = String.sub s 0 i in
        let s2 = String.sub s (i + 1) (String.length s - String.length s1 - 1) in
        doit s2 (s1 :: acc)
  in
  List.rev (doit str [])

let () =
  let l = read_line () in
  match List.map int_of_string (split l ' ') with
  | [] | [_] | _::_::[] | _::_::_::[] | _::_::_::_::[] -> exit 1
  | w :: h :: x :: y :: r :: _ ->
      let str = if (x - r >= 0) && (x + r <= w) && (y - r >= 0) && (y + r <= h) then "Yes"
                else "No" in
      Printf.printf "%s\n" str

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

#define newline '\n'
#define IOS ios_base::sync_with_stdio(false); cin.tie(0)
using ll = long long;
using ull = unsigned long long;

int main() {
    IOS;

    int k;
    string s;
    cin >> k >> s;

    int len = s.size();
    if (len <= k) {
        cout << s << newline;
    } else {
        cout << s.substr(0, k) << "..." << newline;
    }

    return 0;
}

Measured memory_bytes: 3620