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

using namespace std;

mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
typedef long long ll;
typedef long double ld;

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  map<pair<int, int>, int> cnt;
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    ld x;
    cin >> x;
    x *= 1e9;
    ll y = x;
    ld d1 = fabs(y - x), d2 = fabs(y + 1 - x);
    if (d2 < d1) {
      y++;
    }
    int c2 = 0, c5 = 0;
    while (y % 2 == 0) {
      c2++;
      y /= 2;
    }
    while (y % 5 == 0) {
      c5++;
      y /= 5;
    }
    cnt[{c2, c5}]++;
  }
  ll sol = 0;
  for (auto &it1 : cnt) {
    for (auto &it2 : cnt) {
      if (it1 == it2) {
        if (it1.first.first + it2.first.first >= 18 && it1.first.second + it2.first.second >= 18) {
          sol += (ll) it1.second * (it1.second - 1) / 2;
        }
        break;
      }
      if (it1.first.first + it2.first.first >= 18 && it1.first.second + it2.first.second >= 18) {
        sol += (ll) it1.second * it2.second;
      }
    }
  }
  cout << sol << "\n";
  return 0;
}


Measured memory_bytes: 3732
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;
public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int a=sc.nextInt();
		String b=sc.next();
		int max =0;
		for(int i=1;i<a;i++) {
		Set<String> hasha = new HashSet<String>();
		Set<String> hashb = new HashSet<String>();
		String c=b.substring(0, i);
		for(int j=0;j<c.length();j++) {
		hasha.add(c.substring(j, j+1));
		}
		String d=b.substring(i);
		for(int j=0;j<d.length();j++) {
			hashb.add(d.substring(j, j+1));
			}
		hasha.retainAll(hashb);

		if(max<hasha.size()) {
			max=hasha.size();
		}
	}
System.out.println(max);

}

}

Measured memory_bytes: 25044
#include <bits/stdc++.h>
using namespace std;
typedef int64_t int64;
typedef uint32_t uint;
typedef uint64_t uint64;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    vector<int> vA(3);
    for(uint i=0; i<3; ++i){ cin>>vA[i]; }
    sort(vA.begin(), vA.end());
    
    int64 sum=0ll;
    for(uint i=1; i<3; ++i){
        sum += vA[i] - vA[i-1];
    }
    cout << sum << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<queue>
#include<vector>
#include<algorithm>
#include<cstring>
#include<functional>

using namespace std;
typedef pair<int,int> P;
struct edge{
	int t,c;
};

int n,m,k;
vector<edge> G[100001];
int dist[100001];
int ff[100001],tt[100001],cc[100001];

int main(void){
	scanf("%d%d%d",&n,&m,&k);
	for(int i=0;i<m;i++){
		int f,t;
		edge e;
		scanf("%d%d%d",&f,&t,&e.c);
		ff[i]=f;
		tt[i]=t;
		cc[i]=e.c;
		e.t=t;
		G[f].push_back(e);
		e.t=f;
		G[t].push_back(e);
	}
	priority_queue<P,vector<P>,greater<P> > que;
	for(int i=0;i<k;i++){
		int t;
		scanf("%d",&t);
		que.push(P(0,t));
	}
	for(int i=0;i<=n;i++)dist[i]=100000000;
	while(que.size()){
		P p=que.top();
		que.pop();
		int v=p.second;
		int c=p.first;
		if(dist[v]<c)continue;
		dist[v]=c;
		for(int i=0;i<G[v].size();i++){
			edge e=G[v][i];
			if(dist[e.t]>c+e.c){
				dist[e.t]=c+e.c;
				que.push(P(c+e.c,e.t));
			}
		}
	}
	int res=0;
	for(int i=0;i<m;i++){
		int f=ff[i],t=tt[i],c=cc[i];
		if(dist[f]==dist[t])res=max(res,dist[f]+(c+1)/2);
		else{
			int mins=min(dist[f],dist[t]);
			int maxs=max(dist[f],dist[t]);
			c-=maxs-mins;
			if(c<=0)res=max(res,maxs);
			else{
				res=max(res,maxs+(c+1)/2);
			}
		}
	}
	printf("%d\n",res);
	return 0;
}

Measured memory_bytes: 7664
#include<iostream>
using namespace std;
int main()
{
    // スペース区切りの整数の入力
    int a,b,c;
    cin >> a >> b >> c;
  
    int left = c-(a-b);
    if(left<0){
      cout << 0 << endl;
    }else{
      cout << left << endl;
    }
    
    
  	
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n); for (int i=0; i<(n); i++)//第一引数の変数をカウンタ変数としてn回回す
//repはカウンタ変数が1ずつ増える場合にしか使えない
using veci = vector<int>;
using vecd = vector<double>;
using vecs = vector<string>;
int main(){//受け取った数列を昇順にソートして、その分だけ順に減らしていき、その都度ansを1増やす
  int n, x;
  cin >> n >> x;
  veci a(n)
  rep(i, n){
    cin >> a.at(i);
  }
  int ans = 0;
  sort(a.begin(), a.end());
  rep(i, n){
    if (i == n-1 && x != a.at(i)){
      break;
    }
    if (x >= a.at(i)){
      x -= a.at(i);
      ans += 1;
    }
    else{
      break;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define REP(i,st,ed) for(register int i=st,i##end=ed;i<=i##end;++i)
#define DREP(i,st,ed) for(register int i=st,i##end=ed;i>=i##end;--i)
typedef long long ll;
template<typename T>inline bool chkmin(T &x,T y){return (y<x)?(x=y,1):0;}
template<typename T>inline bool chkmax(T &x,T y){return (y>x)?(x=y,1):0;}
inline int read(){
	int x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c>'9' || c<'0'));
	if(c=='-') f=-1,c=getchar();
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1)+(x<<3)+(c^'0');
	return x*f;
}
inline ll readll(){
	ll x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c>'9' || c<'0'));
	if(c=='-') f=-1,c=getchar();
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1ll)+(x<<3ll)+(c^'0');
	return x*f;
}
const int maxn=2e5+10;
int a[maxn];
ll sum1[maxn],sum2[maxn],sum;
int main(){
	int n=read(),m=read();
	REP(i,1,n) a[i]=read();
	REP(i,2,n){
		if(a[i]==a[i-1]) continue;
		if(a[i]>a[i-1]){
			sum1[a[i-1]+2]++,sum1[a[i]+1]--;
			sum2[a[i]+1]-=a[i]-a[i-1]-1;
			sum+=a[i]-a[i-1];
		}
		else{
			a[i]+=m;
			sum1[a[i-1]+2]++,sum1[a[i]+1]--;
			sum2[a[i]+1]-=a[i]-a[i-1]-1;
			sum+=a[i]-a[i-1];
			a[i]-=m;
		}
	}
	ll ans=0;
	REP(i,1,2*m){
		sum1[i]+=sum1[i-1];
		sum2[i]+=sum1[i]+sum2[i-1];
	}
	REP(i,1,m) chkmax(ans,sum2[i]+sum2[i+m]);
	printf("%lld\n",sum-ans);
	return 0;
}


Measured memory_bytes: 3712
#include<iostream>
#include<functional>
#include<utility>
#include<cmath>
#include<iomanip>
#include<algorithm>
#include<string>
#include<vector>

using namespace std;
const auto MOD = 1000000007;
const int INF = 1e9;
const long long LINF = 1e18;
#define rep(i,n) for(int i = 0; i < (n);i++)
typedef pair<int, int> PII;
typedef pair<long, long> PLL;
typedef vector<int> VI;
typedef vector<long long> VLL;


int n, m,a,b,c;
string s,t;

int main() {
	long long re;
	cin >> re;
	cout << re * (re - 1) / 2<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>//solved by *ALIKHAN*
#define ll long long
#define ld long double
#define pb push_back
#define sz(x) (int)x.size()
#define F first
#define S second
#define ppb pop_back
#define mp make_pair
#define all(n) n.begin(), n.end()
#define timefaster ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;

const int N = (int)2e5 + 123;
const int mod = (int)1e9 + 7;
const int INF = (ll)1e18;

int main(){
	ll n;
	cin >> n;
	string s;
	cin >> s;
	if(n%2==1){
		cout << "No";
		return 0;
	}
	for(ll i = 0;i < sz(s) / 2; i++){
		if(s[i] != s[n/2 + i]){
			cout << "No";
			return 0;
		}
	}
	cout << "Yes";
}
// Aksay sila


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int s;
    cin >> s;
    int a,b;
    a = s/100;
    b = s%100;
    // AMBIGUOUS
    if(0 < a && a < 13 && 0 < b && b < 13){
        cout << "AMBIGUOUS" << endl;
    // YYMM
    }else if(0 < b && b < 13){
        cout << "YYMM" << endl;
    // MMYY
    }else if(0 < a && a < 13){
        cout << "MMYY" << endl;
    }else{
        cout << "NA" << endl;
    }
    // cout << a << b << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
int p[100];
int g[100][100];
int main(){
	int a,b;
	scanf("%d%d",&a,&b);
	for(int i=0;i<b;i++){
		int c;scanf("%d",&c);
		for(int j=0;j<c;j++){
			int d;scanf("%d",&d);d--;
			p[d]=i;
		}
	}
	int e;scanf("%d",&e);
	for(int j=0;j<e;j++){
		int x,y;scanf("%d%d",&x,&y);x--;y--;
		g[x][y]=g[y][x]=1;
	}
	int ret=0;
	for(int i=0;i<a;i++){
		bool ok=false;
		for(int j=0;j<a;j++){
			if(p[i]==p[j]&&g[i][j])ok=true;
		}
		if(ok)ret++;
	}
	printf("%d\n",ret);
}

Measured memory_bytes: 1048
#include <bits/stdc++.h>
#define ll long long
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end))) // rep(i, 1, 5) --> {1,2,3,4} // rep(i, 5, 1) --> {4,3,2,1} // rep(it, end(v), begin(v)) --> *it

using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<string> v(n);
    rep(i, 0, n)
        cin >> v[i];
    vector<map<char, int>> vmp(n);
    rep(i, 0, n)
        rep(j, 'a', 'z' + 1)
            vmp[i][j] = 0;
    rep(i, 0, n)
        rep(j, 0, v[i].size())
            vmp[i][v[i][j]]++;
    map<char, int> mp;
    rep(i, 'a', 'z' + 1)
        mp[i] = INT_MAX;
    rep(i, 0, n)
        for (auto x:vmp[i])
            mp[x.first] = min(mp[x.first], x.second);
    string res = "";
    for (auto x:mp)
        if (x.second != 0)
            res += string(x.second, x.first);
    cout << res;
    return 0;
}

Measured memory_bytes: 256
S = input()
N = len(S)
left_R = [0] * N
right_L = [N-1] * N

for i, s in enumerate(S[1:], 1):
  left_R[i] = i if s == 'R' else left_R[i-1]

for i, s in enumerate(S[N-2::-1], 1):
  i = N-1-i
  right_L[i] = i if s == 'L' else right_L[i+1]

answer = [0] * N
for i, (s, R, L) in enumerate(zip(S, left_R, right_L)):
  if s == 'L':
    j = left_R[i]
    if (i+j) & 1:
      j += 1
  else:
    j = right_L[i]
    if (i+j) & 1:
      j -= 1
  answer[j] += 1
print(' '.join(map(str, answer)))
  

Measured memory_bytes: 15396
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define fsp(x) fixed << setprecision(x)
#define xout cerr
const ll inf = LLONG_MAX;
const long double pi = acosl(-1);
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	//const ll p = 1e9 + 7;
	//const ll p = 998244353;

	string s;
	cin >> s;
	cout << s.substr(0, 3) << endl;
}


Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
   int n,m;
   cin>>n>>m;
   int a[n];
   int sum=0;
   
   for(int i=0;i<n;i++)
   {
       cin>>a[i];
       sum+=a[i];
   }
   int req;
   
   req=sum/(4*m);
   if(sum%(4*m)!=0) req=req+1;
   
 
   bool flag=false;
   ll count=0;
   for(int i=0;i<n;i++)
   {
       if(a[i]>=req)
       count++;
       
      
 
   }
  if(count>=m)
  cout<<"Yes";
  else cout<<"No";
 
}


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

using namespace std;

#ifdef DGC
#include "debug.h"
#else
#define debug(...) 9715
#endif
typedef long long ll;
typedef long double ld;
typedef complex<ld> point;
#define F first
#define S second



int main()
{
	#ifdef DGC
		//freopen("a.in", "r", stdin);
		//freopen("b.out", "w", stdout);
	#endif

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

	int n;
	cin >> n;
	vector<pair<int, ll>> a(n);
	for (auto &i : a) cin >> i.F >> i.S;

	ll ans = 0;
	vector<int> r;
	while (!a.empty())
	{
		int d; ll c;
		tie(d, c) = a.back();
		a.pop_back();

		if (c&1) r.push_back(d), --c;
		while (c > 0)
		{
			int nd = 2*d;
			ans += c / 2;
			if (nd > 9)
			{
				nd = nd%10 + nd/10;
				ans += c / 2;
			}

			c /= 2;
			d = nd;
			if (c&1) r.push_back(d), --c;
		}
	}

	while (r.size() > 1)
	{
		int x = r.back();
		r.pop_back();
		int y = r.back();
		r.pop_back();

		++ans;
		int d = x+y;
		if (d > 9) r.push_back(d/10);
		r.push_back(d%10);
	}

	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 21096
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
using namespace std;
using ll = long long;

int main(int argc, const char * argv[]) {
    string s;
    cin >> s;
    int cnt = 0;
    for (int i = 0; i < s.size(); i++) {
        if (s[i] == '+') {
            cnt++;
        }else{
            cnt--;
        }
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 256
a,b,c,x,y = map(int,input().split())
print( min( max(x,y)*2*c , x*a+y*b , max(2*c*min(x,y)+(x-min(x,y))*a, 2*c*min(x,y)+(y-min(x,y))*b)  ) )




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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()

typedef long long lint;

using namespace std;

int main(){
  int n;
  cin>>n;
  int m[n][26];
  REP(i,n)REP(j,26)m[i][j]=0;
  REP(i,n){
    string S;
    cin>>S;
    for(char c:S){
      m[i][c-'a']++;
    }
  }
  int ma[26];
  REP(c,26){
    int min=9999;
    REP(i,n){
      if(m[i][c]<min)min=m[i][c];
    }
    ma[c]=min;
  }
  REP(c,26){
    REP(i,ma[c])cout<<char(c+'a');
  }
  cout<<endl;
  return 0;
}


Measured memory_bytes: 256
import kotlin.math.*

fun str() = readLine()!!
fun int() = readLine()!!.toInt()

fun main() {
	val n = int()
	val blue = Array(n) {str()}
	val m = int()
	val red = Array(m) {str()}

	var r = 0
	for(i in 0 until n-1) {
		var count = 1
		for(j in i+1 until n)
			if(blue[i]==blue[j]) ++count
		for(j in 0 until m)
			if(blue[i]==red[j]) --count
		r = max(r,count)
	}

	println(r)
}


Measured memory_bytes: 36036
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <cstring>
#include <numeric>
#include <cstdlib>
#include <cmath>
using namespace std;

typedef long long ll;

#define INF 10e18 // 4倍しても(4回足しても)long longを溢れない
#define rep(i,n) for(int i=0; i<n; i++)
#define rep_r(i,n,m) for(int i=m; i<n; i++)
#define END cout << endl
#define MOD 1000000007
#define pb push_back
#define sorti(x) sort(x.begin(), x.end())
#define sortd(x) sort(x.begin(), x.end(), std::greater<int>())

struct edge { ll to, cost; };

vector<vector<ll> > G;
vector<ll> memo;

ll dp(ll i) {
  if (memo[i] != -1) return memo[i];
  ll res = 0;
  for (auto v : G[i]) res = max(res, dp(v) + 1);
  return memo[i] = res;
}

int main() {
  int n,m;
  cin >> n >> m;
  vector<ll> x(m), y(m);
  rep(i,m) {
    cin >> x[i] >> y[i];
  }
  
  G.resize(n+1);
  rep(i,m) G[x[i]].pb(y[i]);

  memo.resize(n+1, -1);
  ll ans = 0;
  rep_r(i,n+1,1) ans = max(dp(i), ans);

  cout << ans << endl;
}


Measured memory_bytes: 10112
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
#define pb emplace_back
using namespace std;

namespace Header_Template {
  typedef long long li;
  template<class T>inline void read(T &x) {
    x = 0;
    T tmp = 1;
    char c = getchar();
    while ((c < '0' || c > '9') && c != '-') c = getchar();
    if (c == '-') tmp = -1, c = getchar();
    while (c >= '0' && c <= '9')
      x = (x << 1) + (x << 3) + c - '0', c = getchar();
    x *= tmp;
  }
  template<class T>inline void Max(T &x, T y) {
    if (y > x) x = y;
  }
  template<class T>inline void Min(T &x, T y) {
    if (y < x) x = y;
  }
}
using namespace Header_Template;

namespace Dinic {
  const int N = 500, M = 100010;
  const li inf = 1e18 + 10;
  int n, sum, S, T;
  int cur[N], level[N];
  
  struct Edge {
    int des;
    li flow;
    int e;
  } edge[M];

  vector<int> g[N];

  void Init(int x, int y, int z) {
    n = x;
    S = y, T = z;
    for (int i = 0; i < n; ++i) g[i].clear();
    sum = 0;
  }

  inline void Addedge(int x, int y, li f) {
    ++sum;
    edge[sum] = (Edge){y, f, sum + 1};
    g[x].pb(sum);
    ++sum;
    edge[sum] = (Edge){x, 0, sum - 1};
    g[y].pb(sum);
  }

  bool Bfs(void) {
    fill(level, level + n, -1);
    queue<int> q;
    while (!q.empty()) q.pop();
    level[S] = 1;
    q.push(S);
    while (!q.empty()) {
      int x = q.front();
      q.pop();
      if (x == T) return 1;
      for (int i = 0; i < (int)g[x].size(); ++i) {
	int num = g[x][i];
	int y = edge[num].des;
	if (level[y] == -1 && edge[num].flow)
	  level[y] = level[x] + 1, q.push(y);
      }
    }
    return 0;
  }

  li Dfs(int x, li f) {
    if (x == T || f == 0) return f;
    li tmp, cnt = 0;
    for (int &i = cur[x]; i < (int)g[x].size(); ++i) {
      int num = g[x][i];
      int y = edge[num].des;
      if (edge[num].flow && level[y] == level[x] + 1) {
	tmp = Dfs(y, min(f - cnt, edge[num].flow));
	edge[num].flow -= tmp;
	edge[edge[num].e].flow += tmp;
	cnt += tmp;
	if (cnt == f) return cnt;
      }
    }
    if (!cnt) level[x] = -1;
    return cnt;
  }

  li Solve(void) {
    li ans = 0;
    while (Bfs()) {
      fill(cur, cur + n, 0);
      ans += Dfs(S, inf);
    }
    return ans;
  }
}

const int maxn = 200;
pair<int, int> a[maxn], b[maxn];
int n;

int main(void) {
  read(n);
  for (int i = 1; i <= n; ++i)
    read(a[i].first), read(a[i].second);
  for (int i = 1; i <= n; ++i)
    read(b[i].first), read(b[i].second);
  Dinic::Init(n + n + 2, 0, n + n + 1);
  for (int i = 1; i <= n; ++i)
    Dinic::Addedge(0, i, 1);
  for (int i = 1; i <= n; ++i)
    Dinic::Addedge(i + n, n + n + 1, 1);
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= n; ++j)
      if (a[i].first < b[j].first && a[i].second < b[j].second)
        Dinic::Addedge(i, j + n, 1);
  printf("%lld\n", Dinic::Solve());
  
  return 0;
}


Measured memory_bytes: 512
from sys import exit

a,b,c,x,y = map(int,input().split())

if a+b<2*c:
    print(x*a+y*b)
    exit()

ans = 0
if x>y:
    a,b = b,a
    x,y = y,x

ans = 2*c*x
ans += min(2*c*(y-x), b*(y-x))
print(ans)


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

using namespace std;

typedef long long ll;
typedef long double ld;

bool visited[200005];
vector <int> graf[2000005];

ll sa, sb, br;

void dfs(int v){
    visited[v] = 1;
    if(v <= 100000) sa++;
    else sb++;
    for(auto c : graf[v]){
        br++;
        if(visited[c]) continue;
        dfs(c);
    }
}

ll res;

int main(){
    ios_base::sync_with_stdio(false);
	cout.precision(10);
	cout << fixed;

    int n;
    cin >> n;
    for(int i=1; i<=n; i++){
        int a, b;
        cin >> a >> b;
        graf[a].push_back(b+100000);
        graf[b+100000].push_back(a);
    }
    for(int i=1; i<=200000; i++){
        if(!visited[i]){
            sa = 0;
            sb = 0;
            br = 0;
            dfs(i);
            br /= 2;
            res += sa*sb-br;
        }
    }
    cout << res;
    return 0;
}


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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int N;
int A[111111],B[111111],C[111111];
vint G[111111];
int sz[111111];
int dep[111111];
void dfs(int v,int p,int d){
    dep[v]=d;
    sz[v]=1;
    for(auto u:G[v]){
        if(u==p)continue;
        dfs(u,v,d+1);
        sz[v]+=sz[u];
    }
}

vint cs;
void dfs2(int v,int p){
    int ma=0;
    for(auto u:G[v]){
        if(u==p)continue;
        dfs2(u,v);
        chmax(ma,sz[u]);
    }
    chmax(ma,N-sz[v]);
    if(ma*2<=N){
        cs.pb(v);
    }
}

signed main(){
    cin>>N;
    rep(i,N-1){
        cin>>A[i]>>B[i]>>C[i];
        A[i]--;B[i]--;
        G[A[i]].pb(B[i]);G[B[i]].pb(A[i]);
    }

    dfs(0,-1,0);
    dfs2(0,-1);

    int ans=0;
    rep(i,N-1){
        if(dep[A[i]]<dep[B[i]])swap(A[i],B[i]);
        int sa=sz[A[i]];
        int sb=N-sa;
        ans+=min(sa,sb)*2*C[i];
    }

    if(cs.size()==1){
        int mi=LLONG_MAX;
        rep(i,N-1){
            if(A[i]==cs[0]||B[i]==cs[0])chmin(mi,C[i]);
        }
        ans-=mi;
    }
    else{
        if(dep[cs[0]]<dep[cs[1]])swap(cs[0],cs[1]);
        rep(i,N-1){
            if(A[i]==cs[0]&&B[i]==cs[1])ans-=C[i];
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 15488
#include<stdio.h>

int main(void) {
  int Y,M,D;
  scanf("%d/%d/%d", &Y,&M,&D);

  if(M <= 4 && D <= 30) {
    printf("Heisei\n");
  } else {
    printf("TBD\n");
  }
  return 0;
}



Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> mp;
ll inf =  1e9;


int main(){
 ll n,m;
 ll a,b,c;
 string s,t;
 cin>>s;
 if( s == "ABC" ){
  cout<<"ARC"<<endl;
 }else{
  cout<<"ABC"<<endl;
 }
    return 0;
}


Measured memory_bytes: 3628
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
 
using namespace std;
 
using ll = long long int;
 
int result[310][310] = {};
 
int main(void) {
 
	string s;
	cin >> s;
 
	for (int i = 0; i < s.size(); i += 2) {
		cout << s[i];
	}
	cout << endl;
 
	return 0;
}

Measured memory_bytes: 512
#include<stdio.h>
#include<math.h>
int main(void){
  int n,*a,i,j,tmp,min=2147483647;
  scanf("%d",&n);
  a=(int)malloc(sizeof(int)*n);
  for(i=0;i<n;i++)scanf("%d",&a[i]);
  for(i=0;i<n;i++)a[i]-=100;
  for(i=-100;i<=100;i++){
    for(j=0,tmp=0;j<n;j++)tmp+=pow(a[j],2);
    if(tmp<min)min=tmp;
    for(j=0;j<n;j++)a[j]++;
  }
  printf("%d",min);
  return 0;
}

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

// Function Macros:
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define all(v) (v).begin(), (v).end()
#define setpre(n) cout << fixed << setprecision(n)

// Type / Class / Struct Definitions:
using namespace std;

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

// Constants:
const int INF = (1ll << 30) - 1;  // approx 1.07e9
const ll INFLL = 1ll << 60;       // approx 1.15e18
const int MOD = 1e9 + 7;          // 998244353
const long double EPS = 1.0e-14;

// Global Variables:

// Prototype Declarations:
int gcd(int, int);
template <class T>
inline bool chmin(T&, T);
template <class T>
inline bool chmax(T&, T);

// ================ Main Loop ================
int main() {
    int n;
    cin >> n;
    ll ans = 0;
    for(int i = 1; i <= n; i++) {
        if(i % 3 == 0 || i % 5 == 0) {
            continue;
        } else {
            ans += i;
        }
    }
    cout << ans << endl;
    return 0;
}
// ===========================================

// Functions:
int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}

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;
}


Measured memory_bytes: 3624
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <limits>
#include <climits>
#include <utility>
#include <algorithm>
#include <numeric>

using namespace std;

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

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

    int pow = (1 << (S.size()-1));

    ll ans = 0;

    for (int i = 0; i < pow; ++i) {
        int s = 0;

        for (int j = 0; j < S.size()-1; ++j) {
            if (i & (1 << j)) {
                ll add = stoll(S.substr(s, j - s + 1));
                ans += add;
                s = j + 1;
            }
        }

        ll add = stoll(S.substr(s));
        ans += add;
    }

    cout << ans << endl;

    return 0;
}


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

using namespace std;

#define rep(i, n) for (long i = 0; i < n; ++i)
#define repp(i, a, b) for (long i = a; i < b; ++i)
#define vint vector<int>

int main() {
	int X;
	cin >> X;
	repp(i, -500, 500){
		repp(j, -500, 500){
			if(i*i*i*i*i - j*j*j*j*j == X){
				cout << i << ' ' << j << endl;
				return 0;
			}
		}
	}
}

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

int main(){
    long long N,L;
    cin >> N >> L;
    long long goukei = 0;
    long long sa = 1e9;
    for(int i = 1; i <= N; i++) {
        long long X = i+L-1;
        goukei+=X;
        if(abs(sa) > abs(X)) sa = X;
    }
    cout << goukei-sa << endl;
    return 0;
}


Measured memory_bytes: 256
// ABC_084_D

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

#define forn(i, n) for(int i = 0; i < (int)n; ++i)

bool is_prime(int n){
	if(n < 2) return false;
	else{
  	for(int i = 2; i * i <= n; ++i) if(n % i == 0) return false;
  }

  return true;
}


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

	vector<int> l(q), r(q);
	forn(i, q) cin >> l[i] >> r[i];
	forn(i, q) ++r[i];

	// prime number?
	const int MAX = 100000;
	vector<int> vec(MAX, 0);

	for(int i = 1; i < MAX; i+=2) {
		if(i % 2 == 0) continue;
  	if(is_prime(i) && (is_prime((i + 1)/2))) {
  		vec[i] = 1;
  		//cout << vec[i] << " ";
  	}
  	else continue;
  }

  // sum
  vector<int> sum(MAX+1, 0);
  forn(i, MAX) sum[i+1] = sum[i] + vec[i];

  // query
  forn(i, q) cout << sum[r[i]] - sum[l[i]] << "\n";

  return 0;

} 

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

int main() {
  int N, K, S;
  cin >> N >> K;
  S = 1;
  for (int i = 0; i < N; i++){
    if (S * 2 > S + K)
      S = S + K;
    else
      S = S * 2;
  }
  cout << S << endl;

}

Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int X = sc.nextInt();
        int Y = sc.nextInt();
        boolean judge = false;
        for(int i = 0; i <= X; i++){
          if(2*i+4*(X-i) == Y){
            judge = true;
            break;
          }
        }
        if(judge == false)
          System.out.println("No");
        else
          System.out.println("Yes");
    }
}


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

using namespace std;


const long long int limit = 20000000LL;


class combination {
public:

//Nの最大値がわかれば代入する
	combination( long long int combinationThreshold = 1e7 ) {
		( *this ).combinationThreshold = combinationThreshold + 2;
	}

	//a^p % mod
	long long int powmod( long long int A, long long int P, long long int M = LLONG_MAX ) {
		long long int ans = 1;
		long long int mul = A;
		for( ; P > 0; P >>= 1, mul = ( mul*mul ) % M ) {
			if( ( P & 1 ) == 1 ) ans = ( ans*mul ) % M;
		}
		return ans;
	}

	//nCk mod m
	long long int cb( long long int N, long long int K, long long int M = LLONG_MAX ) {
		if( N < combinationThreshold ) {// 事前計算O(N)、答えるのはO(1)
			if( inv.size() == 0 ) {
				inv = vector<long long int>( combinationThreshold );
				inv[1] = 1;
				for( long long int i = 2; i < combinationThreshold; i++ ) {
					inv[i] = M - ( M / i )*inv[M%i] % M;
				}
				fact = vector<long long int>( combinationThreshold );
				fact[0] = 1;
				revFact = vector<long long int>
					( combinationThreshold );
				revFact[0] = 1;
				for( long long int i = 1; i < combinationThreshold; i++ ) {
					fact[i] = ( fact[i - 1] * i ) % M;
					revFact[i] = ( revFact[i - 1] * inv[i] ) % M;
				}
			}
			return ( ( ( fact[N] * revFact[K] ) % M )*revFact[N - K] ) % M;
		} else {
			return cbOnce( N, K, M );
		}
	}

	//一回だけなら最速 O(K + log(M))
	long long int cbOnce( long long int N, long long int K, long long int M = LLONG_MAX ) {
		if( K > N / 2 ) return cb( N, N - K, M );
		long long int ans = 1;
		long long int div = 1;
		for( long long int i = 0; i < K; i++ ) {
			ans *= N - i;
			ans %= M;
			div *= i + 1;
			div %= M;
		}
		ans *= powmod( div, M - 2, M );
		return ans%M;
	}

private:
	vector<vector<long long int>>C;//3000以下の答え
	vector<long long int>fact;//階乗
	vector<long long int>revFact;//階乗の逆元
	vector<long long int>inv;//mod pでの逆元

	long long int combinationThreshold;//Nの最大値がわかれば入れる。
};





int main() {
	long long int N, M, mod = 1000000007LL;
	cin >> N >> M;
	if( abs( N - M ) > 1 ) {
		cout << 0 << endl;
		return 0;
	}
	combination cb;
	long long int ans = 0;
	if( N == M ) {
		long long int x = 1;
		for( long long int i = 1; i <= N; i++ ) {
			x *= i;
			x %= mod;
		}
		ans = x*x * 2 % mod;
	} else {
		if( N < M ) {
			swap( N, M );
		}
		ans = 1;
		for( size_t i = 1; i <= N; i++ ) {
			if( i != N ) {
				ans *= i;
				ans %= mod;
			}
			ans *= i;
			ans %= mod;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
//
// Created by Myabu on 2020/01/18.
//

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <utility>
#include <math.h>
#include <stack>
#include <queue>
#include <cstdio>
#include <numeric>
#include <iomanip>

using namespace std;


int main(void){
    int N;
    double ans = 0;

    cin>>N;

    for (int i = 0; i < N; ++i) {
        double X;
        string U;
        cin>>X>>U;

        if(U == "JPY"){
            ans += X;
        }else{
            ans += X * 380000;
        }
    }

    std::cout<<std::fixed<<std::setprecision(8);
    cout<<ans<<endl;



    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int A,B,ans=0; cin >> A >> B;
  if(A>B) ans += 2*A -1;
  else if(A<B) ans += 2*B -1;
  else if(A==B) ans += 2*A;
  
  cout << ans << endl;
}

Measured memory_bytes: 3580
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#define repp(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define repm(i,a,b) for(int i=(int)a;i>(int)b;--i)
using ll=long long;
static const ll mod = 1e9 + 7;
static const ll INF = 1LL << 50;
using namespace std;


//素因数分解
template<typename T>
map<T, T>prime_fact(T n) {
	map<T, T>mp;
	for (unsigned long long i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			n /= i;
			mp[i]++;
		}
	}
	if (n != 1) {//sqrt(n)を超えた素数を処理(あっても1つ)
		mp[n]++;
	}
	return mp;
}
int main() {
	ll n;
	cin >> n;
	cout << n << ":";
	for (auto x : prime_fact<ll>(n)) {
		for (int i = 0; i < x.second; ++i) {
			cout << " ";
			cout << x.first;
		}
	}
	cout << endl;
}


Measured memory_bytes: 3104
n = int(input())
a = list(map(int,input().split()))
x = []
y = []

s = 0
for i in a:
    s += i
    x.append(s)
s = 0
for i in a[::-1]:
    s += i
    y.append(s)
x = x[:-1]
y = y[:-1][::-1]

res = float('inf')
for (i,j) in zip(x,y):
    res = min(res, abs(i-j))
print(res)


Measured memory_bytes: 31708
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,x,y) for(int i=(int)x; i<(int)y; ++i)
int main(){
  int H, W, h, w;
  cin >> H >> W >> h >> w;
  if(H%h==0 && W%w==0){
    printf("No\n");
  }else{
    printf("Yes\n");
    FOR(i,0,H){
      FOR(j,0,W){
        if(i%h==h-1 && j%w==w-1) printf("-999999 ");
        else if(i%h==0 && j%w==0) printf("999998 ");
        else printf("0 ");
      }
      printf("\n");
    }
  }
  return 0;
}


Measured memory_bytes: 2048
#include<bits/stdc++.h>
using namespace std;
long long keta(long long x){
  int y=0;
  while(x!=0){
    y++;
    x/=10;
  }
  return y;
}

int main(){
  long long n;
  cin >> n;
  long long ans=11;
  for(int i=1; i<=sqrt(n);i++){
    if(n%i==0){
      ans=min(ans,keta(n/i));
    }
  }
  cout << ans << endl;
}

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

int main() {
  int A,B,remaind;
  cin >> A >> B;
  int N = B-A+1;
  int reverse = 0;
  int sum = 0;
  for (int i=0; i<N; i++) {
    int tmp = A;
    while (tmp !=0) {
      remaind = tmp % 10;
      reverse = reverse*10 + remaind;
      tmp /= 10; 
    }
  	if (reverse == A) {
    	sum++;
  	}
   A++;
   reverse=0;
  }
  cout << sum << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
 
int main(){
  int a, b, c;
  vector<int> ans;
 
  cin >> a >> b >> c;
  ans.push_back(a+b);
  ans.push_back(a+c);
  ans.push_back(b+c);
 
  sort(ans.begin(), ans.end());
 
  cout << ans[0] << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int data[45];
int fib(int n){
  if(data[n]) return data[n];
  if(n==0||n==1) return data[n]=1;
  return data[n]=fib(n-1)+fib(n-2);
}
int main(){
  int n; cin>>n;
  cout<<fib(n)<<endl;
  return 0;
}



Measured memory_bytes: 3116
//khodaya khodet komak kon
#include <bits/stdc++.h>

#define F first
#define S second
#define pb push_back
#define all(x) x.begin(), x.end()
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")


using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

const int N = 200000 + 10;
const ll MOD = 1000000000 + 7;
const ll INF = 1000000010;
const ll LOG = 25;

int n, Grundy[N];
vi G[N];

void DFS(int v, int p = 0){
	for (auto u:G[v]){
		if (u == p) continue;
		DFS(u, v);
		Grundy[v] ^= (1 + Grundy[u]);
	}
}

int32_t main(){
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n;
	for (int i = 1; i <= n - 1; i++){
		int v, u;
		cin >> v >> u;
		G[v].pb(u), G[u].pb(v);
	}
	DFS(1);
	cout << (Grundy[1] == 0?"Bob":"Alice");










	return 0;
}


Measured memory_bytes: 19544
#include <bits/stdc++.h>
#include <iostream>
#include <map>
#include <vector>
#include <cmath>
#include <ios>
#include <iomanip>
#include <algorithm>
//#include <windows.h>
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP2(i, m, n) for (int i = (m); i < (int)(n); ++i)
#define REPR(i, n) for (int i = (n)-1; i >= 0; --i)
#define REPR2(i, m, n) for (int i = (n)-1; i >= (m); --i)
#define REPx(x, a) for(auto x : a)
#define ALL(a) a.begin(), a.end()
#define SORT(a) sort(ALL(a))
#define SORTR(a) sort(ALL(a), greater<int>())
#define REVERSE(a) reverse(ALL(a))
#define bit_search(bit, n) REP(bit, 1<<(n))
#define bit_check(bit, i) ((bit>>(i)) & 1)
#define setpre(n) fixed << setprecision((n))
#define UNIQUE(a) do {SORT(a); (a).erase(unique(ALL(a)), (a).end());} while(0)
#define MAX(a) *max_element(ALL(a))
#define MIN(a) *min_element(ALL(a))
#define bisect_left(a, x) lower_bound(ALL(a), (x)) - a.begin()
#define bisect_right(a, x) upper_bound(ALL(a), (x)) - a.begin()
#define INPUT(a) REP(i, a.size()) cin >> a[i];
#define INPUTP(a) REP(i, a.size()) cin >> a[i].first >> a[i].second;
#define OUTPUT_PERMUTATION(n) do{VI v(n); iota(ALL(v), 1); do{REPx(x, v) cout << x << " "; ENDL} while(next_permutation(ALL(v)));} while(0);
#define MAKE_PERMUTATION(n, PER) do{VVI a(fact(n), VI(n)); int idx = 0; VI v(n); iota(ALL(v), 1); do{REP(roop, n) a[idx][roop] = v[roop]; idx++;} while(next_permutation(ALL(v))); PER = a;} while(0); // int fact(), VVI PERを宣言しておく
#define ENDL cout << endl;
using namespace std;
using LL = long long;
using ULL = unsigned long long;
using LD = long double;
using PII = pair<int, int>;
using VPII = vector<PII>;
using PLL = pair<LL, LL>;
using VPLL = vector<PLL>;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VC = vector<char>;
using VVC = vector<VC>;
using VS = vector<string>;
using VVS = vector<VS>;
using VB = vector<bool>;
using VVB = vector<VB>;
using VD = vector<double>;
const int INF = 2e9;
const LL MOD = 1e9 + 7;

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

void END(){cout << 1 << endl; exit(0);}

bool check(string a, string t)
{
  bool res = true;
  int s = a.size();
  REP(i, s)
  {
    if (a[i] == '?') continue;
    else if (a[i] != t[i])
    {
      res = false;
      break;
    }
  }
  return res;
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s, t;
  cin >> s >> t;
  REPR(i, s.size()-t.size()+1)
  {
    string a = "";
    REP2(j, i, i+t.size()) a += s[j];
    if (check(a, t))
    {
      int idx = 0;
      REP(j, s.size())
      {
        if (i <= j && j < i+t.size()) cout << t[idx++];
        else
        {
          if (s[j] == '?') cout << 'a';
          else cout << s[j];
        }
      }
      ENDL
      return 0;
    }
  }
  cout << "UNRESTORABLE" << endl;

  return 0;
}

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

using namespace std;

int main() {
  int n;
  cin >> n;
  string s, t;
  cin >> s >> t;
  for(int i = 0;i < n;i++) {
    cout << s[i] << t[i];
  }
}


Measured memory_bytes: 3576
#include<iostream>
using namespace std;
int main(){
  int N,K,H[100000],x=0;
  cin>>N>>K;
  for(int i=0;i<N;i++){
    cin>>H[i];
    if(H[i]>=K)
    x++;
  }
  cout<<x<<endl;
  return 0;
}


Measured memory_bytes: 640
#include<stdio.h>
#include<string.h>
int main()
{
	int n;
	scanf("%d", &n);
	char s[10004];
	scanf("%s", s);
	int l = strlen(s);
	int i;
	for (i = 0; i < l; i++)
		printf("%c", (s[i] - 'A' + n) % 26 + 'A');
	printf("\n");
	return 0;
}

Measured memory_bytes: 128
from sys import stdin
input = stdin.readline
N, M = map(int, input().split())
ac = [False] * N
wa = [0] * N
wa_cnt = 0
for i in range(M):
  p, s = input().split()
  p = int(p) - 1
  if ac[p] is False and s == "AC":
    wa_cnt += wa[p]
    ac[p] = True
  elif s == "WA":
    wa[p] += 1
print(ac.count(True), wa_cnt)

Measured memory_bytes: 4596
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_B main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LONG_MAX/2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
// functions

#endif


int main_B() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N; cin >> N;
    vi P(N); REP(i, N) cin >> P[i];

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

    int ans = P[N-1]/2;
    REP(i, N - 1) ans += P[i];

    cout << ans << endl;

    return 0;
}

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


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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 MX = 1000000000000000000;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i,n){
        cin >> a[i];
        if(a[i] == 0){
            cout << 0 << endl;
            return 0;
        }
    }
    ll ans = 1;
    rep(i,n){
        if((MX+1)/ans < a[i]){
            cout << -1 << endl;
            return 0;
        }
        ans *= a[i];
    }
    if(ans > MX) ans = -1;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3996
arg = gets

if arg == nil then
  exit
end

a,b = arg.split(" ").map(&:to_i)

ans = 0

for i in (0..1) do
  if a > b then
    ans = ans + a
    a = a - 1
  else
    ans = ans + b
    b = b - 1
  end
end

puts ans


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

using namespace std;

int main ()
{
    int n;
    int i;
    int a;
    double sum;
    
    cin >>n;
    for(i=0;i<n;i++)
    {
        cin >> a;
        sum+=1.0/a;
    }

    cout << 1.0/sum << endl;

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main()
{
    char s[101];
    int check = 0;

    scanf("%s", s);

    int i;
    for(i = 1; s[i]; i += 2){
        if(s[i] == 'R'){
            check = 1;
            break;
        }
    }

    for(i = 0; s[i]; i += 2){
        if(s[i] == 'L'){
            check = 1;
            break;
        }
    }

    if(check == 1){
        printf("No");
    }
    else{
        printf("Yes");
    }

    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <math.h>
#include <cstdio>

using namespace std;

int fugo(double r) {
	return r < 0 ? -1 : 1;
}
double Abs(double r) {
	return r < 0 ? -r : r;
}

int main() {
	char s[1000];
	while (1) {
		string str;
		if ( !getline(cin, str) ) break;

		for (int i = 0; i < str.size(); ++i)
			s[i] = str[i];
		s[str.size()] = '\0';

		double a, b, c, d, e, f;
		sscanf(s, "%lf%lf%lf%lf%lf%lf", &a, &b, &c, &d, &e, &f);

		double A = a * e - b * d;
		double x = (c * e - b * f) / A;
		double y = (a * f - c * d) / A;

		x = fugo(x) * (int)(Abs(x) * 10000 + 5) / 10 / 1000.0;
		y = fugo(y) * (int)(Abs(y) * 10000 + 5) / 10 / 1000.0;

		printf("%.3f %.3f\n", x, y);
	}
}

Measured memory_bytes: 1296
#include <stdio.h>
int main()
{
    int x, y;
    for(int i = 0; i < 3000; i++){
        scanf("%d %d",&x,&y);
        if (x == 0 && y == 0){
            break;
        }
        else if (x >= y) {
            printf("%d %d\n",y, x);
        } else {
            printf("%d %d\n",x ,y);
        }
    }
    return 0;
}


Measured memory_bytes: 2704
#include <iostream>
#include <vector>

using namespace std;

#define debug(x) cout << #x << "==" << x << endl;

const int inf = 100000000;

typedef long long ll;

int main() {
  ios::sync_with_stdio(false);

  int N;
  cin >> N;

  // dp[i][x] := 0;
  // dp[i][x] := dp[i-1][]

  int pos = 0;
  int i = 0;
  while(pos < N) {
    pos += i;
    i++;
  }
  i--;
  cout << i << "\n";

  return 0;
}


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

int main() {
    int W,H,x,y,r;
    cin >>W>>H>>x>>y>>r;
    if (x+r<=W&&x-r>=0&&y+r<=H&&y-r>=0) {
          cout << "Yes" << endl;

     } else{cout<< "No"<<endl;
     }
   return 0;
    }


Measured memory_bytes: 3092
n = int(input())
s = input()

num = [0 for _ in range(n)]

num[0] = s[1:].count("E")
for i in range(1,n):
    num[i] = num[i-1] + int(s[i-1]=="W") - int(s[i]=="E")

print(min(num))

Measured memory_bytes: 15520
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.regex.Pattern;

public class Main {
    public void solve(BufferedReader stdin, PrintWriter stdout) throws NumberFormatException, IOException {
        int[] first = toIntArray(stdin.readLine());
        int n = first[0]; // 宝箱の個数
        int m = first[1]; // 鍵の個数
        int[] a = new int[m]; // 鍵の値段
        int[] c = new int[m]; // 開けることができる宝箱をbitで表現したもの
        for (int i = 0; i < m; i++) {
            a[i] = toIntArray(stdin.readLine())[0]; // 鍵の値段
            for (int j : toIntArray(stdin.readLine())) {
                c[i] = c[i] | (1 << (j - 1));
            }
        }


        // dp[どこまで鍵を見たか][開けた宝箱(bit)] = コストの最小値
        int max = Arrays.stream(a).sum() + 1;
        int[][] dp = new int[m + 1][1 << n];
        for (int[] raw : dp) {
            Arrays.fill(raw, max);
        }
        dp[0][0] = 0;

        for (int i = 0; i < m; i++) {
            for (int j = 0; j < 1 << n; j++) {
                dp[i + 1][j] = Math.min(dp[i + 1][j], dp[i][j]);
                dp[i + 1][j | c[i]] = Math.min(dp[i + 1][j | c[i]], dp[i][j] + a[i]);
            }
        }

        int ans = dp[m][(1 << n) - 1];
        if (ans == max) {
            stdout.println(-1);
        } else {
            stdout.println(ans);
        }
    }

    private Pattern space = Pattern.compile(" ");

    private int[] toIntArray(String line) {
        return space.splitAsStream(line).mapToInt(Integer::parseInt).toArray();
    }

    public static void main(String[] args) throws NumberFormatException, IOException {
        BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter stdout = new PrintWriter(System.out, false);
        new Main().solve(stdin, stdout);
        stdout.flush();
    }
}

Measured memory_bytes: 53116
/*#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define int long long
#define rep(i,a,b) for(int i=a;i<b;i++)
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define mod 1000000007
//int max(int a, int b, int c){ if(a>b){if(a>c) return a; else return c;}else{if(b>c)return b;else return c;}}
int power(int a,int b){int res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
int32_t main()
{
	IOS;
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
	int n;
	cin>>n;
	int ans=0;
	while(n>=500)
	{
		n-=500;
		ans+=1000;
	}
	while(n>=5)
	{
		n-=5;
		ans+=5;
	}
	cout<<ans;
	return 0;
}*/
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,k;
	cin>>k>>n;
	int a[n];
	for(int i=0;i<n;i++)
		cin>>a[i];
	int temp=a[1]-a[0];
	for(int i=0;i<n-1;i++)
	{
		temp=max(temp,a[i+1]-a[i]);
	}
	temp=max(temp,k-(a[n-1]-a[0]));
	cout<<k-temp;

	return 0;
}

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

int S[1000], top;

int pop() {
	top--;
	return S[top + 1];
}

void push(int x) {
	++top;
	S[top] = x;
}

int main() {
	int a, b;
	top = 0;
	char s[256];
	
	while (cin >> s) {
		if (s[0] == '+') {
			a = pop();
			b = pop();
			push(a + b);
		}
		else if (s[0] == '-') {
			a = pop();
			b = pop();
			push(b - a);
		}
		else if (s[0] == '*') {
			a = pop();
			b = pop();
			push(a*b);
		}
		else {
			push(atoi(s));
		}
	}

	int c = pop();
	cout << c << endl;



}


Measured memory_bytes: 3108
#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>
using namespace std;
typedef long long ll;

int main(void) {
    ll n, a[100010], s[100010];
    cin >> n;
    for (int i = 0; i < n; i++) cin >> a[i];
    sort(a, a + n);
    a[n] = 0;
    for (int i = 0; i < n; i++) {
        if (i == 0) s[i] = a[i];
        else s[i] = s[i - 1] + a[i];
    }
    
    int ans = 0;
    for (int i = 0; i < n; i++) {
        if (s[i] * 2 >= a[i + 1]) ans++;
        else ans = 0;
    }
    cout << ans << endl;
}

Measured memory_bytes: 1792
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)

	x, y := next(), next()

	switch {
	case x < y: fmt.Println("<")
	case x > y: fmt.Println(">")
	default: fmt.Println("=")
	}
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define ll long long
#define ls id << 1
#define rs id << 1 | 1
#define mem(array, value, size, type) memset(array, value, ((size) + 5) * sizeof(type))
#define memarray(array, value) memset(array, value, sizeof(array))
#define pb(x) push_back(x)
#define st(x) (1LL << (x))
#define pii pair<int, int>
#define mp(a, b) make_pair((a), (b))
#define Flush fflush(stdout)
using namespace std;
const int N = 500050;
const int inf = 0x3f3f3f3f;
const ll llinf = 0x3f3f3f3f3f3f;
const ll mod = 998244353LL;
clock_t TIME_START, TIME_END;
void program_end()
{
#ifdef ONLINE
    printf("\nTime used: %.6lf(s)\n", ((double)TIME_END - TIME_START) / CLOCKS_PER_SEC);
    system("pause");
#endif
}
int n;
struct camels
{
    int k;
    ll l, r;
} a[N];
ll ans;
vector<pair<int,ll>> L, R;
priority_queue<ll, vector<ll>, greater<ll>> q;

void solve()
{
    ans = 0;
    L.clear(), R.clear();
    cin >> n;
    for (int i = 1; i <= n; ++i)
        scanf("%d%lld%lld", &a[i].k, &a[i].l, &a[i].r);
    for (int i = 1; i <= n; ++i)
    {
        if (a[i].l == a[i].r)
            ans += a[i].l;
        else if (a[i].l > a[i].r)
            ans += a[i].r, L.push_back(mp(a[i].k, a[i].l - a[i].r));
        else
            ans += a[i].l, R.push_back(mp(n - a[i].k, a[i].r - a[i].l));
    }
    sort(L.begin(), L.end()), sort(R.begin(), R.end());
    priority_queue<ll, vector<ll>, greater<ll>> q;
    for (auto i : L)
    {
        ans += i.second;
        q.push(i.second);
        while (q.size() > i.first)
            ans -= q.top(), q.pop();
    }
    priority_queue<ll, vector<ll>, greater<ll>> qq;
    for (auto i : R)
    {
        ans += i.second;
        qq.push(i.second);
        while (qq.size() > i.first)
            ans -= qq.top(), qq.pop();
    }
    cout << ans << '\n';
}

int main()
{
    TIME_START = clock();
    int Test = 1;
    cin >> Test;
    while (Test--)
        solve();
    TIME_END = clock();
    program_end();
    return 0;
}

Measured memory_bytes: 13740